+ Maximum time to wait for shell integration to initialize before executing commands. For
+ users with long shell startup times, this value may need to be increased if you see "Shell
+ Integration Unavailable" errors in the terminal.
+
void
setSoundEnabled: (value: boolean) => void
setSoundVolume: (value: number) => void
+ terminalShellIntegrationTimeout?: number
+ setTerminalShellIntegrationTimeout: (value: number) => void
setDiffEnabled: (value: boolean) => void
setEnableCheckpoints: (value: boolean) => void
setBrowserViewportSize: (value: string) => void
@@ -124,6 +126,7 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
browserViewportSize: "900x600",
screenshotQuality: 75,
terminalOutputLineLimit: 500,
+ terminalShellIntegrationTimeout: 4000,
mcpEnabled: true,
enableMcpServerCreation: true,
alwaysApproveResubmit: false,
@@ -265,6 +268,8 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
setScreenshotQuality: (value) => setState((prevState) => ({ ...prevState, screenshotQuality: value })),
setTerminalOutputLineLimit: (value) =>
setState((prevState) => ({ ...prevState, terminalOutputLineLimit: value })),
+ setTerminalShellIntegrationTimeout: (value) =>
+ setState((prevState) => ({ ...prevState, terminalShellIntegrationTimeout: value })),
setMcpEnabled: (value) => setState((prevState) => ({ ...prevState, mcpEnabled: value })),
setEnableMcpServerCreation: (value) =>
setState((prevState) => ({ ...prevState, enableMcpServerCreation: value })),
From e403771c4e955c7324ef37b01697862bfc11cdb5 Mon Sep 17 00:00:00 2001
From: Eric Wheeler
Date: Sun, 16 Mar 2025 14:53:36 -0700
Subject: [PATCH 4/7] critical fix: race condition that prevents command
completion
Terminal running state is now managed in TerminalRegistry instead of Terminal to prevent race between stream close and shell completion.
While this race may not trigger on current VSCode versions, newer releases with additional terminal fixes may expose the issue. This proactively prevents "Shell execution end event received, but process is not running" errors.
Signed-off-by: Eric Wheeler
---
src/integrations/terminal/Terminal.ts | 6 +++---
src/integrations/terminal/TerminalProcess.ts | 5 +----
src/integrations/terminal/TerminalRegistry.ts | 2 ++
3 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/src/integrations/terminal/Terminal.ts b/src/integrations/terminal/Terminal.ts
index 553eda5b123..d0cc660a6ad 100644
--- a/src/integrations/terminal/Terminal.ts
+++ b/src/integrations/terminal/Terminal.ts
@@ -67,12 +67,10 @@ export class Terminal {
}
this.streamClosed = false
- this.running = true
this.process.emit("stream_available", stream)
} else {
// Stream is being closed
this.streamClosed = true
- this.running = false
}
}
@@ -81,7 +79,6 @@ export class Terminal {
* @param exitDetails The exit details of the shell execution
*/
public shellExecutionComplete(exitDetails: ExitCodeDetails): void {
- this.running = false
this.busy = false
if (this.process) {
@@ -155,6 +152,9 @@ export class Terminal {
}
public runCommand(command: string): TerminalProcessResultPromise {
+ // We set busy before the command is running because the terminal may be waiting
+ // on terminal integration, and we must prevent another instance from selecting
+ // the terminal for use during that time.
this.busy = true
// Create process immediately
diff --git a/src/integrations/terminal/TerminalProcess.ts b/src/integrations/terminal/TerminalProcess.ts
index 6b562a08cf1..21d65577151 100644
--- a/src/integrations/terminal/TerminalProcess.ts
+++ b/src/integrations/terminal/TerminalProcess.ts
@@ -306,10 +306,7 @@ export class TerminalProcess extends EventEmitter {
"",
)
- // Ensure terminal is marked as not busy
- if (this.terminalInfo) {
- this.terminalInfo.busy = false
- }
+ this.terminalInfo.busy = false
// Emit continue event to allow execution to proceed
this.emit("continue")
diff --git a/src/integrations/terminal/TerminalRegistry.ts b/src/integrations/terminal/TerminalRegistry.ts
index aacb3260d03..dcf1af76d4d 100644
--- a/src/integrations/terminal/TerminalRegistry.ts
+++ b/src/integrations/terminal/TerminalRegistry.ts
@@ -32,6 +32,7 @@ export class TerminalRegistry {
})
if (terminalInfo) {
+ terminalInfo.running = true
terminalInfo.setActiveStream(stream)
} else {
console.error(
@@ -90,6 +91,7 @@ export class TerminalRegistry {
// Signal completion to any waiting processes
if (terminalInfo) {
+ terminalInfo.running = false
terminalInfo.shellExecutionComplete(exitDetails)
}
},
From 2c2eec924b2d614d2568ec5c2582a4eea11847e6 Mon Sep 17 00:00:00 2001
From: Eric Wheeler
Date: Sun, 16 Mar 2025 16:45:00 -0700
Subject: [PATCH 5/7] fix: improve command execution path reporting
Enhance clarity of command execution context and error reporting:
- Check to see if the directory changed because of the command
- Clarify execution path message
- Add explicit message when command exits with non-zero code
Signed-off-by: Eric Wheeler
---
src/core/Cline.ts | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/core/Cline.ts b/src/core/Cline.ts
index 8b5afe98063..cbe796f7856 100644
--- a/src/core/Cline.ts
+++ b/src/core/Cline.ts
@@ -1022,7 +1022,7 @@ export class Cline extends EventEmitter {
),
]
} else if (completed) {
- let exitStatus: string
+ let exitStatus: string = ""
if (exitDetails !== undefined) {
if (exitDetails.signal) {
exitStatus = `Process terminated by signal ${exitDetails.signal} (${exitDetails.signalName})`
@@ -1033,13 +1033,22 @@ export class Cline extends EventEmitter {
result += ""
exitStatus = `Exit code: `
} else {
- exitStatus = `Exit code: ${exitDetails.exitCode}`
+ if (exitDetails.exitCode !== 0) {
+ exitStatus += "Command execution was not successful, inspect the cause and adjust as needed.\n"
+ }
+ exitStatus += `Exit code: ${exitDetails.exitCode}`
}
} else {
result += ""
exitStatus = `Exit code: `
}
- const workingDirInfo = workingDir ? ` from '${workingDir.toPosix()}'` : ""
+
+ let workingDirInfo: string = workingDir ? ` within working directory '${workingDir.toPosix()}'` : ""
+ const newWorkingDir = terminalInfo.getCurrentWorkingDirectory()
+
+ if (newWorkingDir !== workingDir) {
+ workingDirInfo += `; command changed working directory for this terminal to '${newWorkingDir.toPosix()} so be aware that future commands will be executed from this directory`
+ }
const outputInfo = `\nOutput:\n${result}`
return [
From de5157afefade563ea8c408d704ddacacf76e583 Mon Sep 17 00:00:00 2001
From: Eric Wheeler
Date: Sun, 16 Mar 2025 17:13:23 -0700
Subject: [PATCH 6/7] system instructions: clarify terminal directory
operations
Clear guidance for the AI system on:
- Working directory constraints
- Path handling requirements
- Tool vs terminal directory behavior
Signed-off-by: Eric Wheeler
---
src/core/prompts/sections/rules.ts | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/core/prompts/sections/rules.ts b/src/core/prompts/sections/rules.ts
index 86e554a157e..a68017970ca 100644
--- a/src/core/prompts/sections/rules.ts
+++ b/src/core/prompts/sections/rules.ts
@@ -64,7 +64,8 @@ export function getRulesSection(
RULES
-- Your current working directory is: ${cwd.toPosix()}
+- The project base directory is: ${cwd.toPosix()}
+- All all file paths must be relative to this directory. However, commands may change directories in terminals, so respect working directory specified by the response to .
- You cannot \`cd\` into a different directory to complete a task. You are stuck operating from '${cwd.toPosix()}', so be sure to pass in the correct 'path' parameter when using tools that require a path.
- Do not use the ~ character or $HOME to refer to the home directory.
- Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory '${cwd.toPosix()}', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '${cwd.toPosix()}'). For example, if you needed to run \`npm install\` in a project outside of '${cwd.toPosix()}', you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`.
From 7ff67c7205e14ae45940fcb94729845dda899299 Mon Sep 17 00:00:00 2001
From: Eric Wheeler
Date: Sun, 16 Mar 2025 17:44:04 -0700
Subject: [PATCH 7/7] test: update snapshots for system prompt working
directory instructions
Signed-off-by: Eric Wheeler
---
.../__snapshots__/system.test.ts.snap | 45 ++++++++++++-------
1 file changed, 30 insertions(+), 15 deletions(-)
diff --git a/src/core/prompts/__tests__/__snapshots__/system.test.ts.snap b/src/core/prompts/__tests__/__snapshots__/system.test.ts.snap
index 0202ebcef7d..8ca2780b6c5 100644
--- a/src/core/prompts/__tests__/__snapshots__/system.test.ts.snap
+++ b/src/core/prompts/__tests__/__snapshots__/system.test.ts.snap
@@ -270,7 +270,8 @@ MODES
RULES
-- Your current working directory is: /test/path
+- The project base directory is: /test/path
+- All all file paths must be relative to this directory. However, commands may change directories in terminals, so respect working directory specified by the response to .
- You cannot \`cd\` into a different directory to complete a task. You are stuck operating from '/test/path', so be sure to pass in the correct 'path' parameter when using tools that require a path.
- Do not use the ~ character or $HOME to refer to the home directory.
- Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory '/test/path', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '/test/path'). For example, if you needed to run \`npm install\` in a project outside of '/test/path', you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`.
@@ -689,7 +690,8 @@ MODES
RULES
-- Your current working directory is: /test/path
+- The project base directory is: /test/path
+- All all file paths must be relative to this directory. However, commands may change directories in terminals, so respect working directory specified by the response to .
- You cannot \`cd\` into a different directory to complete a task. You are stuck operating from '/test/path', so be sure to pass in the correct 'path' parameter when using tools that require a path.
- Do not use the ~ character or $HOME to refer to the home directory.
- Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory '/test/path', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '/test/path'). For example, if you needed to run \`npm install\` in a project outside of '/test/path', you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`.
@@ -1077,7 +1079,8 @@ MODES
RULES
-- Your current working directory is: /test/path
+- The project base directory is: /test/path
+- All all file paths must be relative to this directory. However, commands may change directories in terminals, so respect working directory specified by the response to .
- You cannot \`cd\` into a different directory to complete a task. You are stuck operating from '/test/path', so be sure to pass in the correct 'path' parameter when using tools that require a path.
- Do not use the ~ character or $HOME to refer to the home directory.
- Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory '/test/path', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '/test/path'). For example, if you needed to run \`npm install\` in a project outside of '/test/path', you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`.
@@ -1414,7 +1417,8 @@ MODES
RULES
-- Your current working directory is: /test/path
+- The project base directory is: /test/path
+- All all file paths must be relative to this directory. However, commands may change directories in terminals, so respect working directory specified by the response to .
- You cannot \`cd\` into a different directory to complete a task. You are stuck operating from '/test/path', so be sure to pass in the correct 'path' parameter when using tools that require a path.
- Do not use the ~ character or $HOME to refer to the home directory.
- Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory '/test/path', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '/test/path'). For example, if you needed to run \`npm install\` in a project outside of '/test/path', you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`.
@@ -1748,7 +1752,8 @@ MODES
RULES
-- Your current working directory is: /test/path
+- The project base directory is: /test/path
+- All all file paths must be relative to this directory. However, commands may change directories in terminals, so respect working directory specified by the response to .
- You cannot \`cd\` into a different directory to complete a task. You are stuck operating from '/test/path', so be sure to pass in the correct 'path' parameter when using tools that require a path.
- Do not use the ~ character or $HOME to refer to the home directory.
- Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory '/test/path', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '/test/path'). For example, if you needed to run \`npm install\` in a project outside of '/test/path', you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`.
@@ -2082,7 +2087,8 @@ MODES
RULES
-- Your current working directory is: /test/path
+- The project base directory is: /test/path
+- All all file paths must be relative to this directory. However, commands may change directories in terminals, so respect working directory specified by the response to .
- You cannot \`cd\` into a different directory to complete a task. You are stuck operating from '/test/path', so be sure to pass in the correct 'path' parameter when using tools that require a path.
- Do not use the ~ character or $HOME to refer to the home directory.
- Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory '/test/path', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '/test/path'). For example, if you needed to run \`npm install\` in a project outside of '/test/path', you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`.
@@ -2464,7 +2470,8 @@ MODES
RULES
-- Your current working directory is: /test/path
+- The project base directory is: /test/path
+- All all file paths must be relative to this directory. However, commands may change directories in terminals, so respect working directory specified by the response to .
- You cannot \`cd\` into a different directory to complete a task. You are stuck operating from '/test/path', so be sure to pass in the correct 'path' parameter when using tools that require a path.
- Do not use the ~ character or $HOME to refer to the home directory.
- Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory '/test/path', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '/test/path'). For example, if you needed to run \`npm install\` in a project outside of '/test/path', you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`.
@@ -3212,7 +3219,8 @@ MODES
RULES
-- Your current working directory is: /test/path
+- The project base directory is: /test/path
+- All all file paths must be relative to this directory. However, commands may change directories in terminals, so respect working directory specified by the response to .
- You cannot \`cd\` into a different directory to complete a task. You are stuck operating from '/test/path', so be sure to pass in the correct 'path' parameter when using tools that require a path.
- Do not use the ~ character or $HOME to refer to the home directory.
- Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory '/test/path', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '/test/path'). For example, if you needed to run \`npm install\` in a project outside of '/test/path', you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`.
@@ -3594,7 +3602,8 @@ MODES
RULES
-- Your current working directory is: /test/path
+- The project base directory is: /test/path
+- All all file paths must be relative to this directory. However, commands may change directories in terminals, so respect working directory specified by the response to .
- You cannot \`cd\` into a different directory to complete a task. You are stuck operating from '/test/path', so be sure to pass in the correct 'path' parameter when using tools that require a path.
- Do not use the ~ character or $HOME to refer to the home directory.
- Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory '/test/path', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '/test/path'). For example, if you needed to run \`npm install\` in a project outside of '/test/path', you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`.
@@ -3989,7 +3998,8 @@ MODES
RULES
-- Your current working directory is: /test/path
+- The project base directory is: /test/path
+- All all file paths must be relative to this directory. However, commands may change directories in terminals, so respect working directory specified by the response to .
- You cannot \`cd\` into a different directory to complete a task. You are stuck operating from '/test/path', so be sure to pass in the correct 'path' parameter when using tools that require a path.
- Do not use the ~ character or $HOME to refer to the home directory.
- Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory '/test/path', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '/test/path'). For example, if you needed to run \`npm install\` in a project outside of '/test/path', you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`.
@@ -4325,7 +4335,8 @@ MODES
RULES
-- Your current working directory is: /test/path
+- The project base directory is: /test/path
+- All all file paths must be relative to this directory. However, commands may change directories in terminals, so respect working directory specified by the response to .
- You cannot \`cd\` into a different directory to complete a task. You are stuck operating from '/test/path', so be sure to pass in the correct 'path' parameter when using tools that require a path.
- Do not use the ~ character or $HOME to refer to the home directory.
- Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory '/test/path', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '/test/path'). For example, if you needed to run \`npm install\` in a project outside of '/test/path', you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`.
@@ -4845,7 +4856,8 @@ MODES
RULES
-- Your current working directory is: /test/path
+- The project base directory is: /test/path
+- All all file paths must be relative to this directory. However, commands may change directories in terminals, so respect working directory specified by the response to .
- You cannot \`cd\` into a different directory to complete a task. You are stuck operating from '/test/path', so be sure to pass in the correct 'path' parameter when using tools that require a path.
- Do not use the ~ character or $HOME to refer to the home directory.
- Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory '/test/path', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '/test/path'). For example, if you needed to run \`npm install\` in a project outside of '/test/path', you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`.
@@ -5257,7 +5269,8 @@ MODES
RULES
-- Your current working directory is: /test/path
+- The project base directory is: /test/path
+- All all file paths must be relative to this directory. However, commands may change directories in terminals, so respect working directory specified by the response to .
- You cannot \`cd\` into a different directory to complete a task. You are stuck operating from '/test/path', so be sure to pass in the correct 'path' parameter when using tools that require a path.
- Do not use the ~ character or $HOME to refer to the home directory.
- Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory '/test/path', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '/test/path'). For example, if you needed to run \`npm install\` in a project outside of '/test/path', you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`.
@@ -5545,7 +5558,8 @@ MODES
RULES
-- Your current working directory is: /test/path
+- The project base directory is: /test/path
+- All all file paths must be relative to this directory. However, commands may change directories in terminals, so respect working directory specified by the response to .
- You cannot \`cd\` into a different directory to complete a task. You are stuck operating from '/test/path', so be sure to pass in the correct 'path' parameter when using tools that require a path.
- Do not use the ~ character or $HOME to refer to the home directory.
- Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory '/test/path', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '/test/path'). For example, if you needed to run \`npm install\` in a project outside of '/test/path', you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`.
@@ -6410,7 +6424,8 @@ MODES
RULES
-- Your current working directory is: /test/path
+- The project base directory is: /test/path
+- All all file paths must be relative to this directory. However, commands may change directories in terminals, so respect working directory specified by the response to .
- You cannot \`cd\` into a different directory to complete a task. You are stuck operating from '/test/path', so be sure to pass in the correct 'path' parameter when using tools that require a path.
- Do not use the ~ character or $HOME to refer to the home directory.
- Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory '/test/path', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '/test/path'). For example, if you needed to run \`npm install\` in a project outside of '/test/path', you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`.