[Enh] Set the session cwd to use server root_dir instead of chat directory#108
Draft
Zsailer wants to merge 2 commits into
Draft
[Enh] Set the session cwd to use server root_dir instead of chat directory#108Zsailer wants to merge 2 commits into
Zsailer wants to merge 2 commits into
Conversation
The session cwd was set to persona.get_chat_dir() which resolves to .jupyter/chats — the directory containing the chat file. This caused Claude Code to start inside the chat storage directory rather than the user's file tree. Use persona.parent.root_dir (the Jupyter server's root directory) as the session cwd, falling back to get_chat_dir() if root_dir is not available.
Author
This is outdated now, since I've made changes to this PR and above. |
da1d902 to
97d2d43
Compare
Read cwd from YChat metadata (set by the frontend when a chat is opened) and resolve it against root_dir. Falls back to root_dir then get_chat_dir() when chat metadata has no cwd. Session creation is deferred from __init__ to the first process_message call so the Y.js metadata has time to sync from the browser.
97d2d43 to
e874687
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When you open a chat while browsing a subdirectory in JupyterLab, you'd expect the AI agent to start working in that same directory. Instead, it was starting in the server process's working directory or the chat file's parent directory. I like to centralize all my chats in to a hidden folder (e.g.
.jupyter/chat). I think a better place for the agent to start is in my current working directory (determined by the user/client's UI).This PR reads the user's file browser path from YChat metadata and uses it as the agent's session working directory. The metadata is set by the frontend when a chat is opened (see jupyterlab/jupyter-chat#420).
The cwd resolution priority is:
cwd(from the file browser) joined withroot_dirroot_diralone (when there's no chat metadata, e.g. older chats)get_chat_dir()(last resort — the chat file's parent directory)One subtlety: session creation is deferred from persona
__init__to the firstprocess_messagecall. This gives the Y.js document time to sync the metadata from the browser before the session reads it. Without this, the metadata would always be empty because the session was created before the frontend's update arrived.