Repository navigation
fix(cli): keep embedded source resources and catalog --dir inside the caller's working directory - #10606
fix(cli): keep embedded source resources and catalog --dir inside the caller's working directory#10606waleedlatif1 wants to merge 1 commit into
Conversation
… caller's working directory An embedded run (Mothership's sim_cli) resolved a relative --dir against the Sim server's cwd and walked every directory up to /, each level a sandbox file read through the host's reader. Resolve --dir against the embed context's workingDirectory and stop the walk there; a --dir outside it is read alone.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Confidence Score: 4/5
[Medium impact] The changes affect embedded workflow source reads, not the wider CLI. Fix the nested parent-record read before merging so the promised directory boundary holds. Findings
SummaryResolves embedded
Reviews (1) · Last reviewed commit: "fix(cli): keep embedded source resources..." · Reviewed by Greptile |
| const named = await namedWorkspace(dir).catch(() => null) | ||
| if (named) return named | ||
| if (dirname(dir) === dir) return null | ||
| if (!walks || dir === ceiling || dirname(dir) === dir) return null |
There was a problem hiding this comment.
The new stop check does not bound reads inside namedWorkspace. With working directory /home/user and --dir /srv/workflows/key, workspaceFolderOf still reads /srv/.sim/base.json before this check runs. That adds an unwanted caller round trip and can reject the command because of a workspace recorded outside the selected directory.
Pass the boundary into the nested lookup and skip parent records outside it. Add a regression test using a workflows/<key> path.
There was a problem hiding this comment.
2 issues found across 3 files
Confidence score: 3/5
workflow-source-reads.tscan resolve a relativeworkingDirectoryagainst the Sim process cwd, letting source reads escape the caller’s intended directory. Validate that the embedded directory is absolute or constrain resolution to the intended root.dir-kind.tscan probe a workspace parent for an outside--dirshaped likeworkflows/<key>before the ceiling check. SkipworkspaceFolderOfparent probing whenwalksis false.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/sim-cli/src/commands/protocol/workflow-source-reads.ts">
<violation number="1" location="packages/sim-cli/src/commands/protocol/workflow-source-reads.ts:40">
P2: This path resolution accepts a relative `workingDirectory` and resolves it against the Sim process's cwd, allowing source reads to escape the caller's intended directory. Validate the embedded working directory as absolute and fail before resolving, matching the existing embedded file-output guard.</violation>
</file>
<file name="packages/sim-cli/src/commands/protocol/source-dir/dir-kind.ts">
<violation number="1" location="packages/sim-cli/src/commands/protocol/source-dir/dir-kind.ts:179">
P2: An outside `--dir` shaped as `workflows/<key>` can still read its workspace parent before this ceiling check runs. Avoid `workspaceFolderOf` parent probing when `walks` is false so an embedded outside-directory read remains isolated.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Turn on auto-fix | Re-trigger cubic
| const top = embedded ? (embedded.workingDirectory ?? '/') : undefined | ||
| const dir = top === undefined ? given : posix.resolve(top, given) |
There was a problem hiding this comment.
P2: This path resolution accepts a relative workingDirectory and resolves it against the Sim process's cwd, allowing source reads to escape the caller's intended directory. Validate the embedded working directory as absolute and fail before resolving, matching the existing embedded file-output guard.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/sim-cli/src/commands/protocol/workflow-source-reads.ts, line 40:
<comment>This path resolution accepts a relative `workingDirectory` and resolves it against the Sim process's cwd, allowing source reads to escape the caller's intended directory. Validate the embedded working directory as absolute and fail before resolving, matching the existing embedded file-output guard.</comment>
<file context>
@@ -29,11 +31,15 @@ function generatedLeafWithDir(
- const named = await enclosingWorkspace(dir)
+ const given = String(command.getOptionValue(DIR_FLAG))
+ const embedded = embedStore.getStore()
+ const top = embedded ? (embedded.workingDirectory ?? '/') : undefined
+ const dir = top === undefined ? given : posix.resolve(top, given)
+ const named = await enclosingWorkspace(dir, top)
</file context>
| const top = embedded ? (embedded.workingDirectory ?? '/') : undefined | |
| const dir = top === undefined ? given : posix.resolve(top, given) | |
| if (embedded?.workingDirectory !== undefined && !posix.isAbsolute(embedded.workingDirectory)) { | |
| throw new Error('The caller working directory must be absolute.') | |
| } | |
| const top = embedded ? (embedded.workingDirectory ?? '/') : undefined | |
| const dir = top === undefined ? given : posix.resolve(top, given) |
| const named = await namedWorkspace(dir).catch(() => null) | ||
| if (named) return named | ||
| if (dirname(dir) === dir) return null | ||
| if (!walks || dir === ceiling || dirname(dir) === dir) return null |
There was a problem hiding this comment.
P2: An outside --dir shaped as workflows/<key> can still read its workspace parent before this ceiling check runs. Avoid workspaceFolderOf parent probing when walks is false so an embedded outside-directory read remains isolated.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/sim-cli/src/commands/protocol/source-dir/dir-kind.ts, line 179:
<comment>An outside `--dir` shaped as `workflows/<key>` can still read its workspace parent before this ceiling check runs. Avoid `workspaceFolderOf` parent probing when `walks` is false so an embedded outside-directory read remains isolated.</comment>
<file context>
@@ -160,15 +160,23 @@ export async function recordedWorkspace(
const named = await namedWorkspace(dir).catch(() => null)
if (named) return named
- if (dirname(dir) === dir) return null
+ if (!walks || dir === ceiling || dirname(dir) === dir) return null
}
}
</file context>
Summary
sim_cli) ofworkflows source resources|catalogresolved a relative--diragainst the Sim server's cwd and walked every directory up to/. Each level was a file read through the caller's reader, which means a workbench round trip, and the reads exposed the server's directory layout.--diris now resolved against the embed context'sworkingDirectory(/when the host gives none), and the walk stops at that directory. A--diroutside it is read alone, with no walk.--dir wffrom chat now reads<workingDirectory>/wf/.sim/base.json. The directory's workspace and the conflicting-workspace refusal now apply in embedded runs, the same as in the terminal.enclosingWorkspacetakes an optionaltop. The terminal call site is unchanged.Type of Change
Testing
workflow-source-reads.test.tsrunsrunEmbeddedCliwith a recording reader. It checks that no read leaves the working directory, that--dir wfreads/home/user/wf/.sim/base.jsonand sends its workflow id, that a--dirnaming another workspace is refused, and that a--diroutside the working directory is read alone.top, and the outside-dir check) turns its test red.check:cli-docs,check:test-patterns,check:comment-hygiene,check:boundaries,check:sim-cli-bundleandcheck:test-typespass.Checklist