@caupulican/pi-adaptative 0.93.4 → 0.93.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/bundled-resources/skills/n-plus-2-architecture/SKILL.md +13 -0
  3. package/dist/core/agent-session.d.ts.map +1 -1
  4. package/dist/core/agent-session.js +5 -20
  5. package/dist/core/agent-session.js.map +1 -1
  6. package/dist/core/autonomy/envelope-enforcement.d.ts +3 -1
  7. package/dist/core/autonomy/envelope-enforcement.d.ts.map +1 -1
  8. package/dist/core/autonomy/envelope-enforcement.js +23 -12
  9. package/dist/core/autonomy/envelope-enforcement.js.map +1 -1
  10. package/dist/core/autonomy/gates.d.ts.map +1 -1
  11. package/dist/core/autonomy/gates.js +24 -26
  12. package/dist/core/autonomy/gates.js.map +1 -1
  13. package/dist/core/context-gc.d.ts.map +1 -1
  14. package/dist/core/context-gc.js +128 -3
  15. package/dist/core/context-gc.js.map +1 -1
  16. package/dist/core/session-shutdown.d.ts +9 -0
  17. package/dist/core/session-shutdown.d.ts.map +1 -0
  18. package/dist/core/session-shutdown.js +44 -0
  19. package/dist/core/session-shutdown.js.map +1 -0
  20. package/dist/core/settings-manager.js.map +1 -1
  21. package/dist/core/skill-vault.d.ts +24 -16
  22. package/dist/core/skill-vault.d.ts.map +1 -1
  23. package/dist/core/skill-vault.js +159 -82
  24. package/dist/core/skill-vault.js.map +1 -1
  25. package/dist/core/system-prompt.d.ts.map +1 -1
  26. package/dist/core/system-prompt.js +7 -18
  27. package/dist/core/system-prompt.js.map +1 -1
  28. package/dist/core/tools/bash.d.ts +3 -1
  29. package/dist/core/tools/bash.d.ts.map +1 -1
  30. package/dist/core/tools/bash.js +15 -7
  31. package/dist/core/tools/bash.js.map +1 -1
  32. package/dist/core/tools/edit.d.ts.map +1 -1
  33. package/dist/core/tools/edit.js +86 -33
  34. package/dist/core/tools/edit.js.map +1 -1
  35. package/dist/core/tools/file-mutation-intent.d.ts +16 -0
  36. package/dist/core/tools/file-mutation-intent.d.ts.map +1 -1
  37. package/dist/core/tools/file-mutation-intent.js +51 -2
  38. package/dist/core/tools/file-mutation-intent.js.map +1 -1
  39. package/dist/core/tools/persistent-process-coordinator.d.ts +8 -2
  40. package/dist/core/tools/persistent-process-coordinator.d.ts.map +1 -1
  41. package/dist/core/tools/persistent-process-coordinator.js +52 -4
  42. package/dist/core/tools/persistent-process-coordinator.js.map +1 -1
  43. package/dist/core/tools/shell-execution-session.d.ts +8 -1
  44. package/dist/core/tools/shell-execution-session.d.ts.map +1 -1
  45. package/dist/core/tools/shell-execution-session.js +54 -3
  46. package/dist/core/tools/shell-execution-session.js.map +1 -1
  47. package/dist/core/tools/shell-session.d.ts +5 -2
  48. package/dist/core/tools/shell-session.d.ts.map +1 -1
  49. package/dist/core/tools/shell-session.js +112 -17
  50. package/dist/core/tools/shell-session.js.map +1 -1
  51. package/dist/core/tools/skill.d.ts +2 -1
  52. package/dist/core/tools/skill.d.ts.map +1 -1
  53. package/dist/core/tools/skill.js +26 -12
  54. package/dist/core/tools/skill.js.map +1 -1
  55. package/dist/core/tools/windows-shell-engine.d.ts +1 -1
  56. package/dist/core/tools/windows-shell-engine.d.ts.map +1 -1
  57. package/dist/core/tools/windows-shell-engine.js +6 -2
  58. package/dist/core/tools/windows-shell-engine.js.map +1 -1
  59. package/dist/index.d.ts +1 -1
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +1 -1
  62. package/dist/index.js.map +1 -1
  63. package/dist/modes/interactive/components/settings-selector.js +2 -2
  64. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  65. package/dist/utils/shell.d.ts +3 -5
  66. package/dist/utils/shell.d.ts.map +1 -1
  67. package/dist/utils/shell.js +4 -7
  68. package/dist/utils/shell.js.map +1 -1
  69. package/docs/settings.md +7 -7
  70. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  71. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  72. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  73. package/examples/extensions/sandbox/package-lock.json +2 -2
  74. package/examples/extensions/sandbox/package.json +1 -1
  75. package/examples/extensions/with-deps/package-lock.json +2 -2
  76. package/examples/extensions/with-deps/package.json +1 -1
  77. package/npm-shrinkwrap.json +12 -12
  78. package/package.json +4 -4
@@ -20,11 +20,9 @@ export declare function killTrackedDetachedChildren(): void;
20
20
  /**
21
21
  * Kill a process and all its children (cross-platform).
22
22
  *
23
- * Windows uses `spawnSync` (not `spawn`) deliberately: callers rely on this function returning
24
- * only once the tree is actually gone (e.g. before removing a directory that was the killed
25
- * process's cwd a directory Windows keeps locked until every handle into it, including a
26
- * live process's cwd handle, is released). A fire-and-forget async `taskkill` would return before
27
- * termination completed, leaving a race where the directory is still locked.
23
+ * Windows dispatches tree kill via synchronous `taskkill /F /T /PID <pid>`. Callers awaiting
24
+ * full directory/handle release must still synchronize on the child process's terminal `close`
25
+ * event to ensure Node and OS handles have completed teardown before directory removal.
28
26
  */
29
27
  export declare function killProcessTree(pid: number): void;
30
28
  //# sourceMappingURL=shell.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../src/utils/shell.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,mCAAmC,EAAE,MAAM,kCAAkC,CAAC;AAEvF,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,YAAY,CAAC;AAE1D,MAAM,WAAW,WAAW;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,EAAE,CAAC;CACf;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAAG,qBAAqB,CAE5G;AAuCD;;;;GAIG;AACH,wBAAgB,6BAA6B,IAAI,WAAW,EAAE,CAqB7D;AAkCD,sHAAsH;AACtH,wBAAgB,cAAc,CAC7B,eAAe,CAAC,EAAE,MAAM,EACxB,SAAS,GAAE,qBAAkD,GAC3D,WAAW,CAkBb;AAED,wBAAgB,WAAW,IAAI,MAAM,CAAC,UAAU,CAoB/C;AAQD,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEvD;AAED,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEzD;AAED,wBAAgB,2BAA2B,IAAI,IAAI,CAKlD;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAyBjD"}
1
+ {"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../src/utils/shell.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,mCAAmC,EAAE,MAAM,kCAAkC,CAAC;AAEvF,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,YAAY,CAAC;AAE1D,MAAM,WAAW,WAAW;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,EAAE,CAAC;CACf;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAAG,qBAAqB,CAE5G;AAuCD;;;;GAIG;AACH,wBAAgB,6BAA6B,IAAI,WAAW,EAAE,CAqB7D;AAkCD,sHAAsH;AACtH,wBAAgB,cAAc,CAC7B,eAAe,CAAC,EAAE,MAAM,EACxB,SAAS,GAAE,qBAAkD,GAC3D,WAAW,CAkBb;AAED,wBAAgB,WAAW,IAAI,MAAM,CAAC,UAAU,CAoB/C;AAQD,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEvD;AAED,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEzD;AAED,wBAAgB,2BAA2B,IAAI,IAAI,CAKlD;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAwBjD"}
@@ -170,16 +170,13 @@ export function killTrackedDetachedChildren() {
170
170
  /**
171
171
  * Kill a process and all its children (cross-platform).
172
172
  *
173
- * Windows uses `spawnSync` (not `spawn`) deliberately: callers rely on this function returning
174
- * only once the tree is actually gone (e.g. before removing a directory that was the killed
175
- * process's cwd a directory Windows keeps locked until every handle into it, including a
176
- * live process's cwd handle, is released). A fire-and-forget async `taskkill` would return before
177
- * termination completed, leaving a race where the directory is still locked.
173
+ * Windows dispatches tree kill via synchronous `taskkill /F /T /PID <pid>`. Callers awaiting
174
+ * full directory/handle release must still synchronize on the child process's terminal `close`
175
+ * event to ensure Node and OS handles have completed teardown before directory removal.
178
176
  */
179
177
  export function killProcessTree(pid) {
180
178
  if (process.platform === "win32") {
181
- // Use taskkill on Windows to kill process tree; spawnSync blocks until taskkill itself
182
- // (and therefore the termination it requested) has finished.
179
+ // Use taskkill on Windows to kill process tree synchronously.
183
180
  try {
184
181
  spawnSync("taskkill", ["/F", "/T", "/PID", String(pid)], {
185
182
  stdio: "ignore",
@@ -1 +1 @@
1
- {"version":3,"file":"shell.js","sourceRoot":"","sources":["../../src/utils/shell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EACN,+BAA+B,EAC/B,kBAAkB,EAClB,eAAe,EACf,mCAAmC,GACnC,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,mCAAmC,EAAE,MAAM,kCAAkC,CAAC;AASvF,MAAM,UAAU,wBAAwB,CAAC,QAAQ,GAAoB,OAAO,CAAC,QAAQ;IACpF,OAAO,QAAQ,KAAK,OAAO,CAAC,CA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UAAU,uBAAuB,CAAC,GAAW;IAClD,wBAAwB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,2BAA2B;IAC1C,KAAK,MAAM,GAAG,IAAI,wBAAwB,EAAE,CAAC;QAC5C,eAAe,CAAC,GAAG,CAAC,CAAC;IACtB,CAAC;IACD,wBAAwB,CAAC,KAAK,EAAE,CAAC;AAClC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,GAAW;IAC1C,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QAClC,uFAAuF;QACvF,6DAA6D;QAC7D,IAAI,CAAC;YACJ,SAAS,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE;gBACxD,KAAK,EAAE,QAAQ;gBACf,WAAW,EAAE,IAAI;aACjB,CAAC,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACR,kCAAkC;QACnC,CAAC;IACF,CAAC;SAAM,CAAC;QACP,gCAAgC;QAChC,IAAI,CAAC;YACJ,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACR,iEAAiE;YACjE,IAAI,CAAC;gBACJ,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;YAC9B,CAAC;YAAC,MAAM,CAAC;gBACR,uBAAuB;YACxB,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { basename, delimiter } from \"node:path\";\nimport { spawnSync } from \"child_process\";\nimport { getBinDir } from \"../config.ts\";\nimport { ensureManagedJscpd } from \"./bundled-jscpd.ts\";\nimport { normalizePath } from \"./paths.ts\";\nimport {\n\tcreatePowerShellHostEnvironment,\n\tPOWERSHELL_7_GUARD,\n\tPOWERSHELL_ARGS,\n\tPOWERSHELL_STARTUP_PROBE_TIMEOUT_MS,\n} from \"./powershell-session-protocol.ts\";\n\nexport { POWERSHELL_STARTUP_PROBE_TIMEOUT_MS } from \"./powershell-session-protocol.ts\";\n\nexport type PlatformShellToolName = \"bash\" | \"powershell\";\n\nexport interface ShellConfig {\n\tshell: string;\n\targs: string[];\n}\n\nexport function getPlatformShellToolName(platform: NodeJS.Platform = process.platform): PlatformShellToolName {\n\treturn platform === \"win32\" ? \"powershell\" : \"bash\";\n}\n\nfunction findExecutableOnPath(executable: string): string | null {\n\tconst locator = process.platform === \"win32\" ? \"where\" : \"which\";\n\ttry {\n\t\tconst result = spawnSync(locator, [executable], {\n\t\t\tencoding: \"utf-8\",\n\t\t\ttimeout: 5_000,\n\t\t\twindowsHide: true,\n\t\t});\n\t\tif (result.status === 0 && result.stdout) {\n\t\t\tconst firstMatch = result.stdout.trim().split(/\\r?\\n/)[0];\n\t\t\tif (firstMatch && (process.platform !== \"win32\" || existsSync(firstMatch))) return firstMatch;\n\t\t}\n\t} catch {\n\t\t// Resolution falls through to known paths or the platform fallback.\n\t}\n\treturn null;\n}\n\nfunction isPowerShellExecutableAvailable(executable: string): boolean {\n\ttry {\n\t\treturn (\n\t\t\tspawnSync(executable, [...POWERSHELL_ARGS, `${POWERSHELL_7_GUARD}Write-Output ok`], {\n\t\t\t\tencoding: \"utf-8\",\n\t\t\t\tenv: createPowerShellHostEnvironment(process.env),\n\t\t\t\ttimeout: POWERSHELL_STARTUP_PROBE_TIMEOUT_MS,\n\t\t\t\twindowsHide: true,\n\t\t\t}).status === 0\n\t\t);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction isPowerShell7Executable(executable: string): boolean {\n\treturn /^pwsh(?:\\.exe)?$/iu.test(basename(executable));\n}\n\n/**\n * Ordered PowerShell candidates without launching a disposable interpreter. Persistent sessions\n * validate these candidates with their real long-lived bootstrap, so the normal path pays for one\n * PowerShell process instead of probing one process and then spawning another.\n */\nexport function getPowerShellCandidateConfigs(): ShellConfig[] {\n\tconst candidates: ShellConfig[] = [];\n\tconst seen = new Set<string>();\n\tconst addCandidate = (shell: string | null): void => {\n\t\tif (!shell || !isPowerShell7Executable(shell)) return;\n\t\tconst identity = process.platform === \"win32\" ? shell.toLowerCase() : shell;\n\t\tif (seen.has(identity)) return;\n\t\tseen.add(identity);\n\t\tcandidates.push({ shell, args: [...POWERSHELL_ARGS] });\n\t};\n\n\tconst pwshOnPath = findExecutableOnPath(process.platform === \"win32\" ? \"pwsh.exe\" : \"pwsh\");\n\taddCandidate(pwshOnPath);\n\n\tconst knownPaths: string[] = [];\n\tconst programFiles = process.env.ProgramFiles;\n\tif (programFiles) knownPaths.push(`${programFiles}\\\\PowerShell\\\\7\\\\pwsh.exe`);\n\tfor (const path of knownPaths) {\n\t\tif (existsSync(path)) addCandidate(path);\n\t}\n\treturn candidates;\n}\n\nfunction getPowerShellConfig(): ShellConfig {\n\tfor (const candidate of getPowerShellCandidateConfigs()) {\n\t\tif (isPowerShellExecutableAvailable(candidate.shell)) return candidate;\n\t}\n\tthrow new Error(\"PowerShell 7 (pwsh) was not found. Install pwsh or set shellPath to a pwsh executable.\");\n}\n\nfunction getBashConfig(): ShellConfig {\n\tif (process.platform === \"win32\") {\n\t\tconst knownPaths: string[] = [];\n\t\tconst programFiles = process.env.ProgramFiles;\n\t\tif (programFiles) knownPaths.push(`${programFiles}\\\\Git\\\\bin\\\\bash.exe`);\n\t\tconst programFilesX86 = process.env[\"ProgramFiles(x86)\"];\n\t\tif (programFilesX86) knownPaths.push(`${programFilesX86}\\\\Git\\\\bin\\\\bash.exe`);\n\t\tfor (const path of knownPaths) {\n\t\t\tif (existsSync(path)) return { shell: path, args: [\"-c\"] };\n\t\t}\n\t\tconst bashOnPath = findExecutableOnPath(\"bash.exe\");\n\t\tif (bashOnPath) return { shell: bashOnPath, args: [\"-c\"] };\n\t\tthrow new Error(\"No Bash executable found. Install Git Bash or set shellPath in settings.json.\");\n\t}\n\tif (existsSync(\"/bin/bash\")) return { shell: \"/bin/bash\", args: [\"-c\"] };\n\tconst bashOnPath = findExecutableOnPath(\"bash\");\n\treturn bashOnPath ? { shell: bashOnPath, args: [\"-c\"] } : { shell: \"sh\", args: [\"-c\"] };\n}\n\n// Platform shell resolution spawns probe processes (`where`/`which`, plus a full PowerShell\n// boot on Windows) and is a process-lifetime invariant, so successful resolutions are cached.\n// Failures are not cached: the user can install a shell and retry without restarting.\nconst resolvedPlatformShellConfigs = new Map<PlatformShellToolName, ShellConfig>();\nlet managedJscpdProvisionAttempted = false;\n\n/** Resolve the requested shell. Runtime callers omit shellName to select PowerShell on Windows and Bash elsewhere. */\nexport function getShellConfig(\n\tcustomShellPath?: string,\n\tshellName: PlatformShellToolName = getPlatformShellToolName(),\n): ShellConfig {\n\tif (customShellPath) {\n\t\tconst resolvedShellPath = normalizePath(customShellPath);\n\t\tif (shellName === \"powershell\" && !isPowerShell7Executable(resolvedShellPath)) {\n\t\t\tthrow new Error(`Custom PowerShell host must be PowerShell 7 (pwsh): ${resolvedShellPath}`);\n\t\t}\n\t\tif (!existsSync(resolvedShellPath)) throw new Error(`Custom shell path not found: ${resolvedShellPath}`);\n\t\treturn {\n\t\t\tshell: resolvedShellPath,\n\t\t\targs: shellName === \"powershell\" ? [...POWERSHELL_ARGS] : [\"-c\"],\n\t\t};\n\t}\n\tlet resolved = resolvedPlatformShellConfigs.get(shellName);\n\tif (!resolved) {\n\t\tresolved = shellName === \"powershell\" ? getPowerShellConfig() : getBashConfig();\n\t\tresolvedPlatformShellConfigs.set(shellName, resolved);\n\t}\n\treturn { shell: resolved.shell, args: [...resolved.args] };\n}\n\nexport function getShellEnv(): NodeJS.ProcessEnv {\n\tif (!managedJscpdProvisionAttempted) {\n\t\tmanagedJscpdProvisionAttempted = true;\n\t\ttry {\n\t\t\tensureManagedJscpd();\n\t\t} catch {\n\t\t\t// The jscpd wrapper and doctor surface the exact packaging failure. Shell startup stays usable.\n\t\t}\n\t}\n\tconst binDir = getBinDir();\n\tconst pathKey = Object.keys(process.env).find((key) => key.toLowerCase() === \"path\") ?? \"PATH\";\n\tconst currentPath = process.env[pathKey] ?? \"\";\n\tconst pathEntries = currentPath.split(delimiter).filter(Boolean);\n\tconst hasBinDir = pathEntries.includes(binDir);\n\tconst updatedPath = hasBinDir ? currentPath : [binDir, currentPath].filter(Boolean).join(delimiter);\n\n\treturn {\n\t\t...process.env,\n\t\t[pathKey]: updatedPath,\n\t};\n}\n\n/**\n * Detached child processes must be tracked so they can be killed on parent\n * shutdown signals (SIGHUP/SIGTERM).\n */\nconst trackedDetachedChildPids = new Set<number>();\n\nexport function trackDetachedChildPid(pid: number): void {\n\ttrackedDetachedChildPids.add(pid);\n}\n\nexport function untrackDetachedChildPid(pid: number): void {\n\ttrackedDetachedChildPids.delete(pid);\n}\n\nexport function killTrackedDetachedChildren(): void {\n\tfor (const pid of trackedDetachedChildPids) {\n\t\tkillProcessTree(pid);\n\t}\n\ttrackedDetachedChildPids.clear();\n}\n\n/**\n * Kill a process and all its children (cross-platform).\n *\n * Windows uses `spawnSync` (not `spawn`) deliberately: callers rely on this function returning\n * only once the tree is actually gone (e.g. before removing a directory that was the killed\n * process's cwd — a directory Windows keeps locked until every handle into it, including a\n * live process's cwd handle, is released). A fire-and-forget async `taskkill` would return before\n * termination completed, leaving a race where the directory is still locked.\n */\nexport function killProcessTree(pid: number): void {\n\tif (process.platform === \"win32\") {\n\t\t// Use taskkill on Windows to kill process tree; spawnSync blocks until taskkill itself\n\t\t// (and therefore the termination it requested) has finished.\n\t\ttry {\n\t\t\tspawnSync(\"taskkill\", [\"/F\", \"/T\", \"/PID\", String(pid)], {\n\t\t\t\tstdio: \"ignore\",\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t} catch {\n\t\t\t// Ignore errors if taskkill fails\n\t\t}\n\t} else {\n\t\t// Use SIGKILL on Unix/Linux/Mac\n\t\ttry {\n\t\t\tprocess.kill(-pid, \"SIGKILL\");\n\t\t} catch {\n\t\t\t// Fallback to killing just the child if process group kill fails\n\t\t\ttry {\n\t\t\t\tprocess.kill(pid, \"SIGKILL\");\n\t\t\t} catch {\n\t\t\t\t// Process already dead\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"shell.js","sourceRoot":"","sources":["../../src/utils/shell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EACN,+BAA+B,EAC/B,kBAAkB,EAClB,eAAe,EACf,mCAAmC,GACnC,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,mCAAmC,EAAE,MAAM,kCAAkC,CAAC;AASvF,MAAM,UAAU,wBAAwB,CAAC,QAAQ,GAAoB,OAAO,CAAC,QAAQ;IACpF,OAAO,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC;AACrD,CAAC;AAED,SAAS,oBAAoB,CAAC,UAAkB;IAC/C,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;IACjE,IAAI,CAAC;QACJ,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,EAAE,CAAC,UAAU,CAAC,EAAE;YAC/C,QAAQ,EAAE,OAAO;YACjB,OAAO,EAAE,KAAK;YACd,WAAW,EAAE,IAAI;SACjB,CAAC,CAAC;QACH,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YAC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AE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE;gBACxD,KAAK,EAAE,QAAQ;gBACf,WAAW,EAAE,IAAI;aACjB,CAAC,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACR,kCAAkC;QACnC,CAAC;IACF,CAAC;SAAM,CAAC;QACP,gCAAgC;QAChC,IAAI,CAAC;YACJ,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACR,iEAAiE;YACjE,IAAI,CAAC;gBACJ,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;YAC9B,CAAC;YAAC,MAAM,CAAC;gBACR,uBAAuB;YACxB,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { basename, delimiter } from \"node:path\";\nimport { spawnSync } from \"child_process\";\nimport { getBinDir } from \"../config.ts\";\nimport { ensureManagedJscpd } from \"./bundled-jscpd.ts\";\nimport { normalizePath } from \"./paths.ts\";\nimport {\n\tcreatePowerShellHostEnvironment,\n\tPOWERSHELL_7_GUARD,\n\tPOWERSHELL_ARGS,\n\tPOWERSHELL_STARTUP_PROBE_TIMEOUT_MS,\n} from \"./powershell-session-protocol.ts\";\n\nexport { POWERSHELL_STARTUP_PROBE_TIMEOUT_MS } from \"./powershell-session-protocol.ts\";\n\nexport type PlatformShellToolName = \"bash\" | \"powershell\";\n\nexport interface ShellConfig {\n\tshell: string;\n\targs: string[];\n}\n\nexport function getPlatformShellToolName(platform: NodeJS.Platform = process.platform): PlatformShellToolName {\n\treturn platform === \"win32\" ? \"powershell\" : \"bash\";\n}\n\nfunction findExecutableOnPath(executable: string): string | null {\n\tconst locator = process.platform === \"win32\" ? \"where\" : \"which\";\n\ttry {\n\t\tconst result = spawnSync(locator, [executable], {\n\t\t\tencoding: \"utf-8\",\n\t\t\ttimeout: 5_000,\n\t\t\twindowsHide: true,\n\t\t});\n\t\tif (result.status === 0 && result.stdout) {\n\t\t\tconst firstMatch = result.stdout.trim().split(/\\r?\\n/)[0];\n\t\t\tif (firstMatch && (process.platform !== \"win32\" || existsSync(firstMatch))) return firstMatch;\n\t\t}\n\t} catch {\n\t\t// Resolution falls through to known paths or the platform fallback.\n\t}\n\treturn null;\n}\n\nfunction isPowerShellExecutableAvailable(executable: string): boolean {\n\ttry {\n\t\treturn (\n\t\t\tspawnSync(executable, [...POWERSHELL_ARGS, `${POWERSHELL_7_GUARD}Write-Output ok`], {\n\t\t\t\tencoding: \"utf-8\",\n\t\t\t\tenv: createPowerShellHostEnvironment(process.env),\n\t\t\t\ttimeout: POWERSHELL_STARTUP_PROBE_TIMEOUT_MS,\n\t\t\t\twindowsHide: true,\n\t\t\t}).status === 0\n\t\t);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction isPowerShell7Executable(executable: string): boolean {\n\treturn /^pwsh(?:\\.exe)?$/iu.test(basename(executable));\n}\n\n/**\n * Ordered PowerShell candidates without launching a disposable interpreter. Persistent sessions\n * validate these candidates with their real long-lived bootstrap, so the normal path pays for one\n * PowerShell process instead of probing one process and then spawning another.\n */\nexport function getPowerShellCandidateConfigs(): ShellConfig[] {\n\tconst candidates: ShellConfig[] = [];\n\tconst seen = new Set<string>();\n\tconst addCandidate = (shell: string | null): void => {\n\t\tif (!shell || !isPowerShell7Executable(shell)) return;\n\t\tconst identity = process.platform === \"win32\" ? shell.toLowerCase() : shell;\n\t\tif (seen.has(identity)) return;\n\t\tseen.add(identity);\n\t\tcandidates.push({ shell, args: [...POWERSHELL_ARGS] });\n\t};\n\n\tconst pwshOnPath = findExecutableOnPath(process.platform === \"win32\" ? \"pwsh.exe\" : \"pwsh\");\n\taddCandidate(pwshOnPath);\n\n\tconst knownPaths: string[] = [];\n\tconst programFiles = process.env.ProgramFiles;\n\tif (programFiles) knownPaths.push(`${programFiles}\\\\PowerShell\\\\7\\\\pwsh.exe`);\n\tfor (const path of knownPaths) {\n\t\tif (existsSync(path)) addCandidate(path);\n\t}\n\treturn candidates;\n}\n\nfunction getPowerShellConfig(): ShellConfig {\n\tfor (const candidate of getPowerShellCandidateConfigs()) {\n\t\tif (isPowerShellExecutableAvailable(candidate.shell)) return candidate;\n\t}\n\tthrow new Error(\"PowerShell 7 (pwsh) was not found. Install pwsh or set shellPath to a pwsh executable.\");\n}\n\nfunction getBashConfig(): ShellConfig {\n\tif (process.platform === \"win32\") {\n\t\tconst knownPaths: string[] = [];\n\t\tconst programFiles = process.env.ProgramFiles;\n\t\tif (programFiles) knownPaths.push(`${programFiles}\\\\Git\\\\bin\\\\bash.exe`);\n\t\tconst programFilesX86 = process.env[\"ProgramFiles(x86)\"];\n\t\tif (programFilesX86) knownPaths.push(`${programFilesX86}\\\\Git\\\\bin\\\\bash.exe`);\n\t\tfor (const path of knownPaths) {\n\t\t\tif (existsSync(path)) return { shell: path, args: [\"-c\"] };\n\t\t}\n\t\tconst bashOnPath = findExecutableOnPath(\"bash.exe\");\n\t\tif (bashOnPath) return { shell: bashOnPath, args: [\"-c\"] };\n\t\tthrow new Error(\"No Bash executable found. Install Git Bash or set shellPath in settings.json.\");\n\t}\n\tif (existsSync(\"/bin/bash\")) return { shell: \"/bin/bash\", args: [\"-c\"] };\n\tconst bashOnPath = findExecutableOnPath(\"bash\");\n\treturn bashOnPath ? { shell: bashOnPath, args: [\"-c\"] } : { shell: \"sh\", args: [\"-c\"] };\n}\n\n// Platform shell resolution spawns probe processes (`where`/`which`, plus a full PowerShell\n// boot on Windows) and is a process-lifetime invariant, so successful resolutions are cached.\n// Failures are not cached: the user can install a shell and retry without restarting.\nconst resolvedPlatformShellConfigs = new Map<PlatformShellToolName, ShellConfig>();\nlet managedJscpdProvisionAttempted = false;\n\n/** Resolve the requested shell. Runtime callers omit shellName to select PowerShell on Windows and Bash elsewhere. */\nexport function getShellConfig(\n\tcustomShellPath?: string,\n\tshellName: PlatformShellToolName = getPlatformShellToolName(),\n): ShellConfig {\n\tif (customShellPath) {\n\t\tconst resolvedShellPath = normalizePath(customShellPath);\n\t\tif (shellName === \"powershell\" && !isPowerShell7Executable(resolvedShellPath)) {\n\t\t\tthrow new Error(`Custom PowerShell host must be PowerShell 7 (pwsh): ${resolvedShellPath}`);\n\t\t}\n\t\tif (!existsSync(resolvedShellPath)) throw new Error(`Custom shell path not found: ${resolvedShellPath}`);\n\t\treturn {\n\t\t\tshell: resolvedShellPath,\n\t\t\targs: shellName === \"powershell\" ? [...POWERSHELL_ARGS] : [\"-c\"],\n\t\t};\n\t}\n\tlet resolved = resolvedPlatformShellConfigs.get(shellName);\n\tif (!resolved) {\n\t\tresolved = shellName === \"powershell\" ? getPowerShellConfig() : getBashConfig();\n\t\tresolvedPlatformShellConfigs.set(shellName, resolved);\n\t}\n\treturn { shell: resolved.shell, args: [...resolved.args] };\n}\n\nexport function getShellEnv(): NodeJS.ProcessEnv {\n\tif (!managedJscpdProvisionAttempted) {\n\t\tmanagedJscpdProvisionAttempted = true;\n\t\ttry {\n\t\t\tensureManagedJscpd();\n\t\t} catch {\n\t\t\t// The jscpd wrapper and doctor surface the exact packaging failure. Shell startup stays usable.\n\t\t}\n\t}\n\tconst binDir = getBinDir();\n\tconst pathKey = Object.keys(process.env).find((key) => key.toLowerCase() === \"path\") ?? \"PATH\";\n\tconst currentPath = process.env[pathKey] ?? \"\";\n\tconst pathEntries = currentPath.split(delimiter).filter(Boolean);\n\tconst hasBinDir = pathEntries.includes(binDir);\n\tconst updatedPath = hasBinDir ? currentPath : [binDir, currentPath].filter(Boolean).join(delimiter);\n\n\treturn {\n\t\t...process.env,\n\t\t[pathKey]: updatedPath,\n\t};\n}\n\n/**\n * Detached child processes must be tracked so they can be killed on parent\n * shutdown signals (SIGHUP/SIGTERM).\n */\nconst trackedDetachedChildPids = new Set<number>();\n\nexport function trackDetachedChildPid(pid: number): void {\n\ttrackedDetachedChildPids.add(pid);\n}\n\nexport function untrackDetachedChildPid(pid: number): void {\n\ttrackedDetachedChildPids.delete(pid);\n}\n\nexport function killTrackedDetachedChildren(): void {\n\tfor (const pid of trackedDetachedChildPids) {\n\t\tkillProcessTree(pid);\n\t}\n\ttrackedDetachedChildPids.clear();\n}\n\n/**\n * Kill a process and all its children (cross-platform).\n *\n * Windows dispatches tree kill via synchronous `taskkill /F /T /PID <pid>`. Callers awaiting\n * full directory/handle release must still synchronize on the child process's terminal `close`\n * event to ensure Node and OS handles have completed teardown before directory removal.\n */\nexport function killProcessTree(pid: number): void {\n\tif (process.platform === \"win32\") {\n\t\t// Use taskkill on Windows to kill process tree synchronously.\n\t\ttry {\n\t\t\tspawnSync(\"taskkill\", [\"/F\", \"/T\", \"/PID\", String(pid)], {\n\t\t\t\tstdio: \"ignore\",\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t} catch {\n\t\t\t// Ignore errors if taskkill fails\n\t\t}\n\t} else {\n\t\t// Use SIGKILL on Unix/Linux/Mac\n\t\ttry {\n\t\t\tprocess.kill(-pid, \"SIGKILL\");\n\t\t} catch {\n\t\t\t// Fallback to killing just the child if process group kill fails\n\t\t\ttry {\n\t\t\t\tprocess.kill(pid, \"SIGKILL\");\n\t\t\t} catch {\n\t\t\t\t// Process already dead\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
package/docs/settings.md CHANGED
@@ -361,12 +361,12 @@ Context GC only rewrites the provider-bound context view. It does not delete or
361
361
  | Setting | Type | Default | Description |
362
362
  |---------|------|---------|-------------|
363
363
  | `contextGc.enabled` | boolean | `true` | Enable provider-context packing for stale bulky context |
364
- | `contextGc.preserveRecentMessages` | number | `12` | Recent messages kept verbatim |
365
- | `contextGc.minToolResultChars` | number | `2500` | Minimum stale tool-result size before packing |
366
- | `contextGc.tools` | string[] | `read`, `bash`, `python`, `powershell`, `rg`, `grep`, `context_headroom_retrieve`, `headroom_retrieve` | Tool results eligible for stale-output packing |
364
+ | `contextGc.preserveRecentMessages` | number | `24` | Recent messages kept verbatim |
365
+ | `contextGc.minToolResultChars` | number | `1200` | Minimum stale tool-result size before packing |
366
+ | `contextGc.tools` | string[] | `read`, `bash`, `python`, `powershell`, `rg`, `grep`, `find`, `run_toolkit_script`, `ls`, `skill_open`, `automata_graph_status`, `automata_graph_search`, `automata_graph_query`, `automata_graph_neighbors`, `automata_graph_path`, `automata_graph_pointer_pack`, `learning_query_memory`, `subagent`, `delegate`, `task_steps`, `pipeline`, `task_background`, `task_goal`, `run_ledger`, `context_headroom_retrieve`, `headroom_retrieve` | Tool results eligible for stale-output packing |
367
367
  | `contextGc.semanticMemory.enabled` | boolean | `true` | Pack stale Automata/Mind semantic context pages from provider context |
368
- | `contextGc.semanticMemory.preserveRecentPages` | number | `2` | Newest semantic memory pages kept verbatim |
369
- | `contextGc.semanticMemory.minChars` | number | `1200` | Minimum semantic page size before packing |
368
+ | `contextGc.semanticMemory.preserveRecentPages` | number | `1` | Newest semantic memory pages kept verbatim |
369
+ | `contextGc.semanticMemory.minChars` | number | `900` | Minimum semantic page size before packing |
370
370
  | `contextGc.semanticMemory.markers` | string[] | Automata/Mind XML-ish tags | Markers used to identify deterministic memory pages |
371
371
 
372
372
  Semantic memory packing only targets tool results and Automata/Mind custom context messages; normal user prompts are preserved even if they contain matching marker text.
@@ -375,10 +375,10 @@ Semantic memory packing only targets tool results and Automata/Mind custom conte
375
375
  {
376
376
  "contextGc": {
377
377
  "enabled": true,
378
- "preserveRecentMessages": 12,
378
+ "preserveRecentMessages": 24,
379
379
  "semanticMemory": {
380
380
  "enabled": true,
381
- "preserveRecentPages": 2
381
+ "preserveRecentPages": 1
382
382
  }
383
383
  }
384
384
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pi-extension-custom-provider",
3
- "version": "0.93.4",
3
+ "version": "0.93.7",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pi-extension-custom-provider",
9
- "version": "0.93.4",
9
+ "version": "0.93.7",
10
10
  "dependencies": {
11
11
  "@anthropic-ai/sdk": "^0.52.0"
12
12
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-extension-custom-provider-anthropic",
3
3
  "private": true,
4
- "version": "0.93.4",
4
+ "version": "0.93.7",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-extension-custom-provider-gitlab-duo",
3
3
  "private": true,
4
- "version": "0.93.4",
4
+ "version": "0.93.7",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pi-extension-sandbox",
3
- "version": "0.93.4",
3
+ "version": "0.93.7",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pi-extension-sandbox",
9
- "version": "0.93.4",
9
+ "version": "0.93.7",
10
10
  "dependencies": {
11
11
  "@anthropic-ai/sandbox-runtime": "^0.0.26"
12
12
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-extension-sandbox",
3
3
  "private": true,
4
- "version": "0.93.4",
4
+ "version": "0.93.7",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pi-extension-with-deps",
3
- "version": "0.93.4",
3
+ "version": "0.93.7",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pi-extension-with-deps",
9
- "version": "0.93.4",
9
+ "version": "0.93.7",
10
10
  "dependencies": {
11
11
  "ms": "^2.1.3"
12
12
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-extension-with-deps",
3
3
  "private": true,
4
- "version": "0.93.4",
4
+ "version": "0.93.7",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@caupulican/pi-adaptative",
3
- "version": "0.93.4",
3
+ "version": "0.93.7",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@caupulican/pi-adaptative",
9
- "version": "0.93.4",
9
+ "version": "0.93.7",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
- "@caupulican/pi-agent-core": "^0.93.4",
13
- "@caupulican/pi-ai": "^0.93.4",
14
- "@caupulican/pi-tui": "^0.93.4",
12
+ "@caupulican/pi-agent-core": "^0.93.7",
13
+ "@caupulican/pi-ai": "^0.93.7",
14
+ "@caupulican/pi-tui": "^0.93.7",
15
15
  "@silvia-odwyer/photon-node": "0.3.4",
16
16
  "chalk": "5.6.2",
17
17
  "cross-spawn": "7.0.6",
@@ -506,11 +506,11 @@
506
506
  }
507
507
  },
508
508
  "node_modules/@caupulican/pi-agent-core": {
509
- "version": "0.93.4",
510
- "resolved": "https://registry.npmjs.org/@caupulican/pi-agent-core/-/pi-agent-core-0.93.4.tgz",
509
+ "version": "0.93.7",
510
+ "resolved": "https://registry.npmjs.org/@caupulican/pi-agent-core/-/pi-agent-core-0.93.7.tgz",
511
511
  "license": "MIT",
512
512
  "dependencies": {
513
- "@caupulican/pi-ai": "^0.93.4",
513
+ "@caupulican/pi-ai": "^0.93.7",
514
514
  "ignore": "7.0.5",
515
515
  "typebox": "1.1.38",
516
516
  "yaml": "2.9.0"
@@ -520,8 +520,8 @@
520
520
  }
521
521
  },
522
522
  "node_modules/@caupulican/pi-ai": {
523
- "version": "0.93.4",
524
- "resolved": "https://registry.npmjs.org/@caupulican/pi-ai/-/pi-ai-0.93.4.tgz",
523
+ "version": "0.93.7",
524
+ "resolved": "https://registry.npmjs.org/@caupulican/pi-ai/-/pi-ai-0.93.7.tgz",
525
525
  "license": "MIT",
526
526
  "dependencies": {
527
527
  "@anthropic-ai/sdk": "0.117.1",
@@ -546,8 +546,8 @@
546
546
  }
547
547
  },
548
548
  "node_modules/@caupulican/pi-tui": {
549
- "version": "0.93.4",
550
- "resolved": "https://registry.npmjs.org/@caupulican/pi-tui/-/pi-tui-0.93.4.tgz",
549
+ "version": "0.93.7",
550
+ "resolved": "https://registry.npmjs.org/@caupulican/pi-tui/-/pi-tui-0.93.7.tgz",
551
551
  "license": "MIT",
552
552
  "dependencies": {
553
553
  "get-east-asian-width": "1.6.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caupulican/pi-adaptative",
3
- "version": "0.93.4",
3
+ "version": "0.93.7",
4
4
  "description": "Adaptive fork of Pi coding agent for self-evolving agent harness experiments",
5
5
  "type": "module",
6
6
  "piConfig": {
@@ -89,9 +89,9 @@
89
89
  "postinstall": "node scripts/postinstall-python-runtime.mjs"
90
90
  },
91
91
  "dependencies": {
92
- "@caupulican/pi-agent-core": "^0.93.4",
93
- "@caupulican/pi-ai": "^0.93.4",
94
- "@caupulican/pi-tui": "^0.93.4",
92
+ "@caupulican/pi-agent-core": "^0.93.7",
93
+ "@caupulican/pi-ai": "^0.93.7",
94
+ "@caupulican/pi-tui": "^0.93.7",
95
95
  "@silvia-odwyer/photon-node": "0.3.4",
96
96
  "chalk": "5.6.2",
97
97
  "cross-spawn": "7.0.6",