fix(smartshell): avoid triple shell nesting, improve WSL path filtering, and use chunked log buffer to reduce memory usage

This commit is contained in:
2026-03-05 10:18:43 +00:00
parent f254a9e078
commit 71cc64b6d9
7 changed files with 83 additions and 38 deletions

View File

@@ -182,7 +182,7 @@ export class Smartshell {
if (!bufferExceeded) {
shellLogInstance.addToBuffer(data);
if (shellLogInstance.logStore.length > maxBuffer) {
if (shellLogInstance.logLength > maxBuffer) {
bufferExceeded = true;
shellLogInstance.logStore = Buffer.from('[Output truncated - exceeded maxBuffer]');
}
@@ -203,7 +203,7 @@ export class Smartshell {
if (!bufferExceeded) {
shellLogInstance.addToBuffer(data);
if (shellLogInstance.logStore.length > maxBuffer) {
if (shellLogInstance.logLength > maxBuffer) {
bufferExceeded = true;
shellLogInstance.logStore = Buffer.from('[Output truncated - exceeded maxBuffer]');
}
@@ -338,8 +338,12 @@ export class Smartshell {
return await this._execCommandPty(options, commandToExecute, shellLogInstance);
}
// Use the executor's shell binary directly to avoid triple shell nesting.
// Previously: Node spawn(shell:true) → /bin/sh → bash -c → command (3 layers)
// Now: Node spawn(shell:bash) → command (1 layer)
const shellBinary = this.shellEnv.executor === 'bash' ? '/bin/bash' : true;
const execChildProcess = cp.spawn(commandToExecute, [], {
shell: true,
shell: shellBinary,
cwd: process.cwd(),
env: options.env || process.env,
detached: true, // Own process group — immune to terminal SIGINT, managed by smartexit
@@ -405,7 +409,7 @@ export class Smartshell {
if (!bufferExceeded) {
shellLogInstance.addToBuffer(data);
if (shellLogInstance.logStore.length > maxBuffer) {
if (shellLogInstance.logLength > maxBuffer) {
bufferExceeded = true;
shellLogInstance.logStore = Buffer.from('[Output truncated - exceeded maxBuffer]');
}
@@ -426,7 +430,7 @@ export class Smartshell {
if (!bufferExceeded) {
shellLogInstance.addToBuffer(data);
if (shellLogInstance.logStore.length > maxBuffer) {
if (shellLogInstance.logLength > maxBuffer) {
bufferExceeded = true;
shellLogInstance.logStore = Buffer.from('[Output truncated - exceeded maxBuffer]');
}