Add AI session storage, resume, and deletion commands to Studio CLI#2767
Add AI session storage, resume, and deletion commands to Studio CLI#2767jverneaut wants to merge 28 commits intoAutomattic:trunkfrom
Conversation
|
My initial feeling here is that the PR may lack a bit of structural organization, It adds a lot of code without too much separation of concerns to the "ai.ts" command file. I think it would make sense to separate the non-command specific code to separate files (as a preparation to handle sessions in the app later) The ai-sessions.ts looks to be decent and about sessions persistence. Curious why it's not in the "ai" folder. What do you think about this assessment, does it make sense? In terms of behavior, I wonder if we should restore the "model" and the "cwd" when resuming sessions. |
|
I agree. I think we should move For On Should I go ahead with those changes? |
|
Maybe we should consider the |
|
I agree, here is what I plan to do: apps/cli
├── ai
│ ├── agent.ts
│ ├── sessions.ts
│ ├── slash-commands.ts
│ ├── system-prompt.ts
│ ├── tools.ts
│ └── ui.ts
└── commands
└── ai
├── index.ts
├── sessions.ts
└── tests
├── ai-sessions.test.ts
└── ai.test.tsThis moves the sessions logic to the |
|
That looks decent 👍 |
f2f4133 to
8cef3bb
Compare
|
@youknowriad I rebased this branch to Here is what I ended up doing: I moved the The I moved session-related internals under I also updated the session event pipeline to rely on SDK event data (notably I also implemented these updates:
|
|
The slash command /browser doesn't seem to work with session. Steps to reproduce:
|
|
Nit: Is it necessary to save sessions where nothing has happened yet?
|
|
Thanks for the review @taipeicoder!
|
edd25a6 to
ed248ae
Compare
|
Rebased the branch to work with the latest changes on trunk, most notably the commands registration in |
|
I'll take a look at the PR in a few. @taipeicoder also would appreciate a review when you have time. |
|
Thanks! We now have a conflict in In this PR, we’re introducing session persistence that saves and restores the user’s cwd (based on the original pwd), which now conflicts with that behavior. Curious to get your thoughts on how we should handle this. Would it make sense to drop cwd persistence entirely and avoid exposing it to the user? |
What do you mean? My expectations is that the way we persist the sessions is an implementation detail that the user shouldn't care about. We should be able to store the sessions in the app data folder without requiring users for permissions. |
|
@youknowriad This is not related to the session persistence layer, but to the change introduced in #2764 where the cwd is now always ~/Studio instead of being set to the user’s pwd. This PR includes a feature that saves and restores the cwd, which now conflicts with that security model. Restoring a previous cwd could point outside of ~/Studio and effectively bypass the restriction. When I mentioned “avoiding exposing it to the user”, I was referring to the TUI header for example. We currently display the cwd there, even though it’s no longer meaningful since the agent always operates within ~/Studio. |
|
Ah I see, it makes sense to avoid the switching of cwd then now indeed. Surfacing to the user is probably not that important either, although the user might ask where my sites are created. |
ed248ae to
ecbaa21
Compare
Related issues
How AI was used in this PR
Proposed Changes
session.started,session.linked,site.selected,user.message,assistant.message,tool.result,tool.progress,agent.question,turn.closed).studio ai sessionsstudio ai sessions liststudio ai sessions resume [id]studio ai sessions delete [id]studio aiusage by default.--no-session-persistenceto disable recording for a run (including resumed chats).resumeanddeleteaccept:latest<appData>/sessions/YYYY/MM/DD/<timestamp>-<uuid>.jsonllatestsemantics), loading/deleting by prefix, and directory pruning behavior.Command Help Output
studio ai sessions --helpstudio ai sessions list --helpstudio ai sessions resume --helpstudio ai sessions delete --helpTesting Instructions
npm run cli:buildENABLE_STUDIO_AI=true node apps/cli/dist/cli/main.js ai/exit.ENABLE_STUDIO_AI=true node apps/cli/dist/cli/main.js ai sessions listENABLE_STUDIO_AI=true node apps/cli/dist/cli/main.js ai sessions resume latestENABLE_STUDIO_AI=true node apps/cli/dist/cli/main.js ai sessions delete latestDeleted AI session: <id>.ENABLE_STUDIO_AI=true node apps/cli/dist/cli/main.js ai --no-session-persistence/exit.ENABLE_STUDIO_AI=true node apps/cli/dist/cli/main.js ai sessions listand confirm no new session was added for that run.npm test -- apps/cli/lib/tests/ai-sessions.test.tsnpm test -- apps/cli/commands/tests/ai.test.tsPre-merge Checklist
npm run typecheck