Skip to content

fix: run custom generator commands in the generator cwd and clean their output - #486

Closed
aaaxingiiiiiii wants to merge 1 commit into
microsoft:mainfrom
aaaxingiiiiiii:fix/custom-generator-cwd
Closed

aaaxingiiiiiii wants to merge 1 commit into
microsoft:mainfrom
aaaxingiiiiiii:fix/custom-generator-cwd

Conversation

@aaaxingiiiiiii

Copy link
Copy Markdown

Summary

Custom generators receive executeShellCommand and call it themselves. This change fixes two problems with how those calls run.

Working directory. When a custom generator did not pass a cwd, its command ran in the inshellisense process directory rather than the terminal's current directory. After the user cds elsewhere in the wrapped shell, these generators query the wrong directory.

Output. The generators received raw output, including the trailing newline and any CRLF. Specs written for Fig depend on cleaned output. For example, npm's workspaces generator runs npm prefix and then reads `${stdout}/package.json`. The trailing newline ends up inside that path, so npm run -w <Tab> never lists workspaces.

Fig handles both cases:

  • When a request has no working directory, figterm uses the shell's current directory (working_directory() in crates/figterm/src/message.rs).
  • executeCommand cleans the output: CRLF becomes LF, and leading and trailing newlines are removed (cleanOutput in packages/api-bindings-wrappers/src/executeCommand.ts). Both files are in aws/amazon-q-developer-cli-autocomplete.

This change does the same for the executeShellCommand passed to custom generators. Script generators are unchanged; they already receive cwd and use stdout.trim().

Test plan

  • Added three tests to src/tests/runtime/generator.test.ts: default cwd, explicit cwd is kept, and output cleaning. Without the fix, the default-cwd and output-cleaning tests fail.
  • npm run build and npm run lint pass.
  • The other runtime tests pass, except brewInstallMullvad, which also fails on unmodified main on my machine because the local Homebrew prints no casks.
  • Ran the real spec end to end: npm run -w in a project with workspaces now lists them.

🤖 Generated with Claude Code

…ir output

Custom generators receive executeShellCommand and call it themselves.
When they did not pass a cwd, the command ran in the inshellisense
process directory instead of the terminal's current directory, and the
raw output (with trailing newlines and CRLF) was returned. Specs written
for Fig rely on both: npm's workspaces generator runs `npm prefix` and
reads `${stdout}/package.json`, which failed.

Fig runs commands without a working directory in the shell's current
directory, and cleans the output (CRLF to LF, strip leading and trailing
newlines). Do the same for the executeShellCommand passed to custom
generators. Script generators are unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@aaaxingiiiiiii
aaaxingiiiiiii deleted the fix/custom-generator-cwd branch October 15, 2026 06:37
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