Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
it's unfortunate to have to pass filename and filepath. can these be merged? I thought filename was absolute? should we force it? Another option is to call the /files api which gives you the root iirc |
It's a bit tricky, we started passing the relative paths instead of absolute path for filename (where possible). #7722 Not sure if I want to touch this. The other option, I think we could use files_details endpoint from |
|
@Light2Dark got it, this is just for home mode? maybe we could just make those absolute URLs. @dmadisetti do you see any issue with that? that does help with consistency, but maybe folks used "home mode" in order to avoid absolute paths. separately, right now for Agents we use |
manzt
left a comment
There was a problem hiding this comment.
Similar comment to @mscolnick. Is trying to think if there is a way we can require/use one attribute instead of two that could get out of sync.
|
I think I like the idea of |
There was a problem hiding this comment.
Pull request overview
This PR ensures the frontend agent receives a correct working directory (cwd) derived from the backend’s absolute notebook filepath, preventing path-resolution errors when notebooks are mounted from outside the current directory.
Changes:
- Add
cwdto the server-generated mount config (derived fromfilepath) and thread it into the notebook/static templates. - Introduce a
cwdAtomon the frontend, parsecwdat mount-time, and use it to initialize agent sessions / compute absolute notebook paths for agent resources. - Update template tests and export HTML snapshots to include the new
cwdfield.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
marimo/_server/templates/templates.py |
Adds cwd to mount config and derives it from filepath for notebook pages. |
frontend/src/mount.tsx |
Extends mount options schema to accept cwd and stores it in state. |
frontend/src/core/saving/file-state.ts |
Adds cwdAtom to store the notebook working directory. |
frontend/src/components/chat/acp/agent-panel.tsx |
Uses cwdAtom to set agent session cwd and build an absolute filename for agent resources. |
tests/_server/templates/test_templates.py |
Adds assertions for cwd and a new filepath-driven test case. |
tests/_server/templates/snapshots/export1.txt |
Snapshot update to include "cwd": "" in mount config. |
tests/_server/templates/snapshots/export2.txt |
Snapshot update to include "cwd": "" in mount config. |
tests/_server/templates/snapshots/export3.txt |
Snapshot update to include "cwd": "" in mount config. |
tests/_server/templates/snapshots/export4.txt |
Snapshot update to include "cwd": "" in mount config. |
tests/_server/templates/snapshots/export5.txt |
Snapshot update to include "cwd": "" in mount config. |
tests/_server/templates/snapshots/export6.txt |
Snapshot update to include "cwd": "" in mount config. |
Comments suppressed due to low confidence (3)
marimo/_server/templates/templates.py:71
cwdis derived fromfilepath(an absolute server-side path) and embedded intowindow.__MARIMO_MOUNT_CONFIG__, which is sent to the browser. This can unintentionally disclose server filesystem layout (especially whenfilenameis made relative for directory mode). Consider limiting exposure (e.g., only includecwdwhen running in a trusted/local mode or when the agent feature is enabled), or pass a server-resolvable identifier instead of an absolute path and have the backend resolve paths for agent operations.
options: dict[str, Any] = {
"filename": filename or "",
"cwd": cwd or "",
"mode": mode,
"version": version or get_version(),
"server_token": str(server_token),
"user_config": user_config,
tests/_server/templates/test_templates.py:101
- This assertion is not portable on Windows: the rendered JSON will escape backslashes (e.g.,
C:\\...), sof'"cwd": "{expected_cwd}"'won’t match. Consider asserting againstjson.dumps(expected_cwd)(or parsing the mount config JSON and comparing thecwdfield) so the test is robust across path separators/escaping.
)
assert self.filename.name in result
assert f'"cwd": "{expected_cwd}"' in result
_assert_no_leftover_replacements(result)
frontend/src/mount.tsx:153
- The schema/docs say
cwdis an absolute working directory, but the backend currently emits an empty string when unknown. Consider normalizing""tonullin the schema/transform (or updating the doc comment to explicitly state it may be empty/unknown) to avoid downstream code treating an empty string as a valid absolute path.
/**
* absolute working directory of the notebook
*/
cwd: z.string().nullish().default(null),
/**
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
dmadisetti
left a comment
There was a problem hiding this comment.
No issues passing the data, assuming our permissions work
|
The windows failure might be real (file path issues) |
|
I pushed a fix but not showing up here. I think its a test issue, it's escaping \ with \ so shows up as |
📝 Summary
Previously, the agent would not know the absolute filepath, this led to errors when an agent is instantiated outside of the current directory. This fix ensures current working directory is passed from the backend on-mount, and subsequently passed to the agent.
🔍 Description of Changes
📋 Checklist