block-open-source / goose

Goose is a developer agent that operates from your command line to help you do the boring stuff.
https://block-open-source.github.io/goose/
Apache License 2.0
73 stars 12 forks source link

feat: add guards to session management #101

Open lamchau opened 4 days ago

lamchau commented 4 days ago

note: the image shows both the empty session file (goose session list doesn't contain abcd.jsonl) and what the menu ux looks like for a session conflict

lifeizhou-ap commented 22 hours ago

Hi @lamchau,

Nice one!

I noticed that the session.py file is getting bigger. Just wondering whether it is better to separate some of these logics to another component or file?

lifeizhou-ap commented 22 hours ago

also I feel that with your change, we may not require session resume as user can resume the session via session start. WDYT?

lamchau commented 22 hours ago

@lifeizhou-ap maybe after we get to 500 lines or so unless you have another suggestion?

30% or so of the Session class is text strings (split lines) and docstrings - with code folding it feels digestible. i'm worried if we start to make it to abstract it requires more context switching/modification across files

lamchau commented 22 hours ago

[formatted for clarity]

@lifeizhou-ap possibly! but the challenge lies in how it's invoked in this project and internally as a subcommand and how it's used via pipx

with pipx it would still require a conflict for a resume to happen (e.g. goose session start) creates a generated session each time, so that requires the user to use <tab> to autocomplete the latest one

  1. goose session start <tab>
  2. choose session with conflict
  3. r to resume

if we keep the command xx goose session resume and goose session resume it is only 1 step - this convenience is essentially "free" and saves a few steps for the user.

anyhoo, those are my thoughts/biases - we should go with whatever flow makes the most sense. since it's a product decision, maybe anna can make the call?

lifeizhou-ap commented 5 hours ago

@lifeizhou-ap maybe after we get to 500 lines or so unless you have another suggestion?

30% or so of the Session class is text strings (split lines) and docstrings - with code folding it feels digestible. i'm worried if we start to make it to abstract it requires more context switching/modification across files

I see. Personally I prefer small files for readability and maintenance. However, I understand your concern and we can refactor in the future when it reaches the point for refactoring.

One suggestion: Maybe extract the code into a function?

# prevents cluttering the `sessions` with empty files, which
        # can be confusing when resuming a session
        if is_empty_session(self.session_file_path):
            try:
                self.session_file_path.unlink()
            except FileNotFoundError:
                pass
            except Exception as e:
                raise Exception(f"error deleting empty session file: {e}")
lifeizhou-ap commented 4 hours ago

Hey @baxen I am happy with this PR (only with a small suggestion). Would you like to review it?

lamchau commented 14 minutes ago

@lifeizhou-ap sure thing, extracted and reordered them here a1c8c82