Skip to content

fix(cli): keep embedded source resources and catalog --dir inside the caller's working directory - #10606

Open
waleedlatif1 wants to merge 1 commit into
stagingfrom
fix/cli-embedded-source-reads-dir
Open

waleedlatif1 wants to merge 1 commit into
stagingfrom
fix/cli-embedded-source-reads-dir

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • An embedded run (Mothership's sim_cli) of workflows source resources|catalog resolved a relative --dir against 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.
  • --dir is now resolved against the embed context's workingDirectory (/ when the host gives none), and the walk stops at that directory. A --dir outside it is read alone, with no walk.
  • Because of this, a relative --dir wf from 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.
  • enclosingWorkspace takes an optional top. The terminal call site is unchanged.

Type of Change

  • Bug fix

Testing

  • New workflow-source-reads.test.ts runs runEmbeddedCli with a recording reader. It checks that no read leaves the working directory, that --dir wf reads /home/user/wf/.sim/base.json and sends its workflow id, that a --dir naming another workspace is refused, and that a --dir outside the working directory is read alone.
  • All five tests fail on the pre-fix files. Reverting each guard on its own (the stop at top, and the outside-dir check) turns its test red.
  • sim-cli type-check and the full suite (1366 tests) pass. check:cli-docs, check:test-patterns, check:comment-hygiene, check:boundaries, check:sim-cli-bundle and check:test-types pass.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added

… 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.
@vercel

vercel Bot commented Dec 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Dec 1, 2026 10:06pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5RetriggerView in Greptile

[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

  1. P1 Parent records still get read ▶

Summary

Resolves embedded resources and catalog paths against the caller's working directory.

  • Embedded source commands resolve --dir from caller context.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Parent records still get read

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.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2 issues found across 3 files

Confidence score: 3/5

  • workflow-source-reads.ts can resolve a relative workingDirectory against 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.ts can probe a workspace parent for an outside --dir shaped like workflows/<key> before the ceiling check. Skip workspaceFolderOf parent probing when walks is 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

Comment on lines +40 to +41
const top = embedded ? (embedded.workingDirectory ?? '/') : undefined
const dir = top === undefined ? given : posix.resolve(top, given)

@cubic-dev-ai cubic-dev-ai Bot Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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>
Suggested change
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)
Fix with cubic

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

@cubic-dev-ai cubic-dev-ai Bot Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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>
Fix with cubic

This branch was previously deployed

1 inactive deployment
Preview — 52f8a1dd Deployed Dec 1, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant