Skip to content

Commit 779c28d

Browse files
fix(web): a cd inside a here-document no longer counts as a folder the agent worked in
The body of a here-document is data, so reading a command for directory changes now stops where one begins. Co-Authored-By: Claude Fable 5.2 <[email protected]>
1 parent 7e5d570 commit 779c28d

2 files changed

Lines changed: 3 additions & 0 deletions

File tree

‎apps/web/src/workspaceBasenameLookup.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ describe("agentWorkingDirectories", () => {
145145
"abcd /work/a; echo cd /work/b; git -C /work/c status; cd /work/d",
146146
`echo "cd /work/g"; echo 'x; cd /work/h' && grep -c "cd /work/i" notes`,
147147
"echo bash -c 'cd /work/j'; cd -",
148+
"cat <<EOF > notes\ncd /work/k\nEOF",
148149
"cd /work/e\\ f && cd `pwd`/x",
149150
),
150151
).toEqual(["/work/d"]);

‎packages/client-runtime/src/workspaceBasenameLookup.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ function cdOperands(script: string): Array<string> {
162162
wordOpen = false;
163163
};
164164
for (const [token] of script.matchAll(SHELL_TOKEN)) {
165+
// A here-document's body is data, and where it ends is the shell's to say.
166+
if (!/^["'#]/.test(token) && token.includes("<<")) break;
165167
if (/^[;&|()\n]/.test(token)) endCommand();
166168
else if (/^[ \t]/.test(token) || (!wordOpen && token.startsWith("#"))) wordOpen = false;
167169
else if (wordOpen) words[words.length - 1] += token;

0 commit comments

Comments
 (0)