Skip to content

Add functions for finding the .jupyter directory or the workspace directory #1376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jun 24, 2025

Conversation

ellisonbg
Copy link
Collaborator

@ellisonbg ellisonbg commented Jun 18, 2025

This PR introduces the find_dotjupyter_dir function, which traverses up the directory tree from a given path to find the nearest .jupyter directory.

The idea is that we want to start to use a .jupyter directory for AI related files, such as rules, personas, memory, MCP config, etc. Other AI IDEs, such as VSCode, Cursor, Cline, and Windsurf have started to do this and it seems like a well established pattern that users have grow accustomed to. The main difference for Jupyter is that we don't have a "workspace" or "project" like abstraction like these other IDEs. As such, our plan is to use the cwd of the chat file to originate the search for the .jupyter directory.

Additionally, the PR includes unit tests to verify the functionality of this new feature, ensuring it correctly identifies the .jupyter directory when present and returns None when absent.

Because this requires the user to work with hidden directories, I have also added the config to make these files visible to the user through the content manager settings. However, to see them in JupyterLab, the user will still have to modify settings. We may want to automate that as well.

@ellisonbg ellisonbg added the enhancement New feature or request label Jun 18, 2025
@ellisonbg ellisonbg marked this pull request as ready for review June 18, 2025 20:55
Copy link
Member

@dlqqq dlqqq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ellisonbg Thank you for adding unit tests for this! Left a fix for the CI below. Everything else looks great. 👍

@ellisonbg
Copy link
Collaborator Author

I think this is ready for final review, but it can't be merged until after #1379 is merged.

@krassowski
Copy link
Member

krassowski commented Jun 20, 2025

As such, our plan is to use the cwd of the chat file to originate the search for the .jupyter directory.

As a heads-up JupyterLab Desktop already uses that directory for it's config. I also proposed adopting it in JupyterLab: jupyterlab/jupyterlab#12916. Having jupyter-ai use it too makes it a stronger case.

The main difference for Jupyter is that we don't have a "workspace" or "project" like abstraction like these other IDEs

Which IMO Jupyter editors should have (again, see the linked issue).

@ellisonbg
Copy link
Collaborator Author

Thanks, I hadn't see that issue or JupyterLab Desktop's usage of it.

@ellisonbg ellisonbg changed the title Add find_dotjupyter_dir function to locate .jupyter directory Add functions for finding the .jupyter directory or the workspace directory Jun 24, 2025
@ellisonbg
Copy link
Collaborator Author

OK, I fixed the tests.

Copy link
Member

@dlqqq dlqqq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ellisonbg Thank you for working on this! Left some feedback below.

else:
stop_path = current_path.parent # Will be set to filesystem root in the loop

while current_path != current_path.parent: # Stop at root directory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition allows the loop to stop when current_path is equal to its parent, or root_dir if it is not None:

Suggested change
while current_path != current_path.parent: # Stop at root directory
# Stop after reaching `/` or `root_dir`
while current_path not in { current_path.parent, root_dir }:

This requires the previous suggestion of coercing setting root_dir: Optional[Path].

# Stop if we've reached the specified root directory
if root_dir is not None and current_path == stop_path:
break

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition can be removed entirely:

Suggested change
# Stop if we've reached the specified root directory
if root_dir is not None and current_path == stop_path:
break

This requires the previous suggestion of coercing setting root_dir: Optional[Path].

Args:
dir (str): The starting directory path
dot_dir (str): The dot directory name to search for (e.g., '.jupyter', '.git')
root_dir (Optional[str]): The root directory to stop searching at.
Copy link
Member

@dlqqq dlqqq Jun 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] I would recommend renaming root_dir to contents_root throughout this branch. The root_dir name collides with the existing concept of a root directory, referring to / or C:\\. Renaming this globally should be safe & shouldn't bring too many extra changes.

This is more of an issue in directories.py because the code there references both the root directory / and the contents root root_dir, which could be confusing to other devs.

@dlqqq dlqqq added the do-not-port Label for PRs that shouldn't be ported to another branch label Jun 24, 2025
Find the nearest dot directory by traversing up from the given directory.

Args:
dir (str): The starting directory path
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear whether this path is relative to Jupyter root? Would help to add that info to the doc.

ellisonbg and others added 12 commits June 24, 2025 14:26
This commit introduces the find_dotjupyter_dir function, which traverses up the directory tree from a given path to find the nearest .jupyter directory.

Additionally, it includes unit tests to verify the functionality of this new feature, ensuring it correctly identifies the .jupyter directory when present and returns None when absent.
ellisonbg and others added 6 commits June 24, 2025 14:26
…ry logic

The changes refactor the .jupyter directory finding functionality by:
  - Removing specific dotjupyter.py module and its tests
  - Adding new generalized directories.py utilities for finding dot directories
  - Moving .jupyter directory methods from middle of BasePersona to end for better organization
  - Adding workspace directory support alongside .jupyter directory functionality
  - Updating PersonaManager to use the new generalized directory utilities

This consolidates directory traversal logic and makes it more reusable for different directory types.
Copy link
Member

@dlqqq dlqqq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving to unblock. There are a few outstanding comments, but none are worth waiting for. Thank you Brian!

I've rebased the PR onto the latest commit on the main branch. Thanks for fixing that tiny regression on main introduced by #1379. Can merge after CI is green.

@dlqqq dlqqq merged commit f66e4d0 into jupyterlab:main Jun 24, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-port Label for PRs that shouldn't be ported to another branch enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants