Repository navigation
Conversation
stripMarker only matched the marker at the start of a line, so a command whose output did not end with a newline (e.g. printf 'x') leaked the marker into the tool output and reported cwd as null. Locate the marker anywhere in its line and keep the text before it. Closes lessweb#415.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the bash tool leaking its internal working-directory marker into the command output when the command's output does not end with a newline (e.g.
printf 'x'returnedx__DEEPCODE_PWD__<token>__<cwd>andcwd: null).Closes #415
Root cause
buildShellCommandappendsprintf '%s%s\n' "<marker>" "$PWD"after the user command.stripMarkeronly recognised the marker when it started a line (startsWith(marker)). If the command's last line had no trailing\n, the marker was glued to that line, was not found, and was returned to the model as part of the output, withcwdreported asnull(so cwd tracking was lost too).Fix
In
packages/core/src/tools/bash-handler.ts,stripMarkernow finds the last occurrence of the marker anywhere in a line (lastIndexOf), reads the cwd from the text after it, and keeps the text before it as the command output. Chosen over printing a leading newline before the marker because it leaves output of ordinary commands unchanged compared to the current behaviour and needs no extra newline stripping; when the marker is on its own line the behaviour is identical to before. For unterminated output the marker's own line break is dropped, soprintf 'x'yields exactlyx.Because the marker can now be matched mid-line, the full marker must not appear in the command text itself:
printfnow receives the token as a separate argument (printf '__DEEPCODE_PWD__%s__%s\n' "<token>" "$PWD"). Otherwise a command that prints its own command line (ps,set -x) and exits before the marker is written could have that line mistaken for the marker.Differences from the diff suggested in the issue: for unterminated output this keeps exactly
partial(the issue's diff yieldspartial\n). Passing the cwd through a temp file instead of stdout was not taken, as it is out of scope for this bug.Tests
Added to
packages/core/src/tests/tool-handlers.test.ts:Bash strips the cwd marker when command output has no trailing newline(single-line and multi-line unterminated output; checks output andmetadata.cwd) - fails onmain, passes with the fix.Bash keeps trailing newline and cwd tracking for output that ends with a newline- regression guard for the unchanged path.Bash does not expose the cwd marker in the command line of the shell(skipped on Windows) - runsps -o args= -p $$; exit 3, which prints the shell's own command line and exits before the real marker; checks that the output is not truncated and that the session cwd is kept - fails without theprintfchange, passes with it.How I verified it
stripMarkerchange (noprintfchange),node --import tsx --test --test-concurrency=1 --test-name-pattern="Bash (strips|keeps|does not expose)" tool-handlers.test.tsgives 2 passed, 1 failed (the marker-in-argv test; output cut at the marker text). Onmainthe first test fails as well (outputx__DEEPCODE_PWD__...,cwd: null).npm run check(typecheck + lint + prettier): passes.npm test(all workspaces; Linux, Node 22): cli 706/706 passed, core 685 passed + 2 skipped (Windows-only) / 0 failed, vscode-ide-companion 121/121 passed.build/bundle.This PR was prepared with AI assistance (Claude Code). I have reviewed the change and the test results.