Skip to content

fix(command): insert the /init project path verbatim - #761

Merged
Ishaan Gangwani (ishaan1124) merged 1 commit into
synthetic-sciences:mainfrom
aniruddhaadak80:fix/init-prompt-path-verbatim
Sep 28, 2026
Merged

Ishaan Gangwani (ishaan1124) merged 1 commit into
synthetic-sciences:mainfrom
aniruddhaadak80:fix/init-prompt-path-verbatim

Conversation

@aniruddhaadak80

Copy link
Copy Markdown
Contributor

What does this PR do, and why?

/init builds its prompt by splicing the project directory into a template
with a string replacement:

get template() {
  return PROMPT_INITIALIZE.replace("${path}", Instance.worktree)
}

A string replacement expands the replacement patterns inside the text it
inserts, so a directory name that legally contains $$, $& or $' produced a
corrupted prompt — and that prompt is the only thing telling the agent which
directory it is working in:

project directory what the prompt says on 3e94875c
…/openscience-init-prices$$ …at …/openscience-init-prices$: the file …
…/openscience-init-a$&b …at …/openscience-init-a${path}b: the file …
…/openscience-init-x$'y the entire rest of the prompt is pasted into the path, and the sentence repeats

$$ collapses to $, $& pastes the matched ${path} back, and $' pastes
everything after the match. The last row leaves the agent pointed at a directory
that does not exist.

A function replacement inserts the path literally, which is the same fix
applied to {file:…} config references in ba152a6.

I swept the rest of the tree for the same idiom and this is the last live
instance: the other ${…} string-pattern replacements are
tool/bash.ts (static description text and two numbers) and two
tooling/repo release helpers (fixed replacements), none of which carry user
text.

Linked issue

Fixes #760

How did you verify it?

backend/cli/test/session/command-init-template.test.ts creates a real project
directory for each of the three sequences and asserts the /init template
contains Instance.worktree — the path the runtime actually resolved, not a
hard-coded string.

On unmodified 3e94875c all three fail:

Expected to contain: "...\openscience-init-prices$$"
Received:            "Create or update the project's AGENTS.md at ...\openscience-init-prices$: the file …"

Expected to contain: "...\openscience-init-a$&b"
Received:            "Create or update the project's AGENTS.md at ...\openscience-init-a${path}b: the file …"

Commands run:

  • bun test --timeout 15000 ./test/session/command-init-template.test.ts → 3 pass
  • bun test --timeout 20000 ./test/session/command-init-template.test.ts ./test/session/command-shell.test.ts
    → 4 pass, 1 fail — the failure is
    trusted command shell interpolation uses the governed shell boundary, which
    I reproduced on unmodified main with my change stashed, so it is not from
    this diff
  • bun run --cwd backend/cli typecheck → exit 0

Pre-existing reds on this Windows checkout, not from this diff:

  • bun run format:check cannot pass here: git materializes the LF blobs as
    CRLF, so Prettier flags hundreds of untouched files, including tsconfig.json
    and turbo.json. I verified all three changed files are formatted per the
    repo config with line endings normalized.
  • bun run typecheck: backend is clean; @synsci/workspace fails because
    frontend/workspace/src/custom-elements.d.ts is a symlink (mode 120000) that
    Windows checked out as a text file containing ../../ui/src/custom-elements.d.ts,
    which TypeScript then parses as source → TS1128.

Checklist

  • bun run check is green (format, typecheck, backend + frontend/ui + SDK tests) — blocked on this Windows checkout by the CRLF and symlink artifacts described above; backend typecheck is clean and the new tests are green
  • bun run --cwd frontend/workspace build succeeds if I touched frontend/workspace or frontend/ui — not touched
  • ./tooling/repo/generate.ts was run and the tooling/sdk output committed if I changed backend/cli/src/server — not touched
  • CHANGELOG.md has an Unreleased entry if the change is user-visible
  • The matching docs page under frontend/docs/src/content/openscience/ is updated if behavior changed — no doc change needed: /init has always been documented as operating on the project directory, so this restores the documented behavior
  • Screenshots or a short video are attached for UI changes — not a UI change
  • No version bumps (package.json versions and tags are written by the release workflow)
  • install and frontend/landing/public/install are still byte-identical if I touched either — not touched

@vercel

vercel Bot commented Sep 27, 2026

Copy link
Copy Markdown

ANIRUDDHA ADAK (@aniruddhaadak80) is attempting to deploy a commit to the InkVell Team on Vercel.

A member of the Team first needs to authorize it.

The path was spliced in with a string replacement, so replacement patterns in a
directory name were expanded: `$$` became `$`, `$&` pasted the `${path}`
placeholder back, and `$'` pasted the rest of the prompt into the path. Use a
function replacement.
@ishaan1124
Ishaan Gangwani (ishaan1124) merged commit 971a8d2 into synthetic-sciences:main Sep 28, 2026
1 check failed
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.

/init corrupts the project path when the directory name contains dollar sequences

2 participants