@caupulican/pi-adaptative 0.84.1 → 0.85.3

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 (214) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
  3. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +14 -8
  4. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
  5. package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +14 -8
  6. package/dist/bundled-resources/runtimes/pi-shell-engine/arithmetic.py +364 -0
  7. package/dist/bundled-resources/runtimes/pi-shell-engine/context.py +2 -1
  8. package/dist/bundled-resources/runtimes/pi-shell-engine/errors.py +16 -0
  9. package/dist/bundled-resources/runtimes/pi-shell-engine/exec.py +137 -14
  10. package/dist/bundled-resources/runtimes/pi-shell-engine/nodes.py +23 -2
  11. package/dist/bundled-resources/runtimes/pi-shell-engine/parser.py +134 -6
  12. package/dist/bundled-resources/runtimes/pi-shell-engine/tokens.py +25 -2
  13. package/dist/bundled-resources/skills/deduplicate-by-evidence/SKILL.md +7 -5
  14. package/dist/bundled-resources/skills/worker-profile-writer/SKILL.md +63 -0
  15. package/dist/core/agent-session.d.ts.map +1 -1
  16. package/dist/core/agent-session.js +8 -0
  17. package/dist/core/agent-session.js.map +1 -1
  18. package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
  19. package/dist/core/autonomy/lane-tool-surface.js +4 -2
  20. package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
  21. package/dist/core/background-lane-controller.d.ts +3 -0
  22. package/dist/core/background-lane-controller.d.ts.map +1 -1
  23. package/dist/core/background-lane-controller.js +6 -0
  24. package/dist/core/background-lane-controller.js.map +1 -1
  25. package/dist/core/compaction-controller.d.ts +2 -0
  26. package/dist/core/compaction-controller.d.ts.map +1 -1
  27. package/dist/core/compaction-controller.js +35 -13
  28. package/dist/core/compaction-controller.js.map +1 -1
  29. package/dist/core/default-tool-surface.d.ts.map +1 -1
  30. package/dist/core/default-tool-surface.js +1 -0
  31. package/dist/core/default-tool-surface.js.map +1 -1
  32. package/dist/core/delegation/worker-delegation-controller.d.ts +7 -0
  33. package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
  34. package/dist/core/delegation/worker-delegation-controller.js +28 -0
  35. package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
  36. package/dist/core/delegation/worker-profile-resolver.d.ts +2 -0
  37. package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -1
  38. package/dist/core/delegation/worker-profile-resolver.js +46 -11
  39. package/dist/core/delegation/worker-profile-resolver.js.map +1 -1
  40. package/dist/core/doctor.d.ts +1 -1
  41. package/dist/core/doctor.d.ts.map +1 -1
  42. package/dist/core/doctor.js +5 -4
  43. package/dist/core/doctor.js.map +1 -1
  44. package/dist/core/failure-corpus.d.ts +26 -1
  45. package/dist/core/failure-corpus.d.ts.map +1 -1
  46. package/dist/core/failure-corpus.js +17 -0
  47. package/dist/core/failure-corpus.js.map +1 -1
  48. package/dist/core/model-capability.d.ts.map +1 -1
  49. package/dist/core/model-capability.js +1 -0
  50. package/dist/core/model-capability.js.map +1 -1
  51. package/dist/core/model-tool-protocol.d.ts +3 -2
  52. package/dist/core/model-tool-protocol.d.ts.map +1 -1
  53. package/dist/core/model-tool-protocol.js +5 -1
  54. package/dist/core/model-tool-protocol.js.map +1 -1
  55. package/dist/core/models/runtime-process.d.ts +7 -1
  56. package/dist/core/models/runtime-process.d.ts.map +1 -1
  57. package/dist/core/models/runtime-process.js +4 -2
  58. package/dist/core/models/runtime-process.js.map +1 -1
  59. package/dist/core/orchestration/lane-tool-manifests.d.ts +1 -1
  60. package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -1
  61. package/dist/core/orchestration/lane-tool-manifests.js +6 -1
  62. package/dist/core/orchestration/lane-tool-manifests.js.map +1 -1
  63. package/dist/core/orchestration/session-task-profile-store.d.ts +31 -0
  64. package/dist/core/orchestration/session-task-profile-store.d.ts.map +1 -0
  65. package/dist/core/orchestration/session-task-profile-store.js +138 -0
  66. package/dist/core/orchestration/session-task-profile-store.js.map +1 -0
  67. package/dist/core/orchestration/task-profile-writer.d.ts +58 -0
  68. package/dist/core/orchestration/task-profile-writer.d.ts.map +1 -0
  69. package/dist/core/orchestration/task-profile-writer.js +165 -0
  70. package/dist/core/orchestration/task-profile-writer.js.map +1 -0
  71. package/dist/core/process-matrix/runtime.js +43 -11
  72. package/dist/core/process-matrix/runtime.js.map +1 -1
  73. package/dist/core/resource-loader.d.ts +2 -0
  74. package/dist/core/resource-loader.d.ts.map +1 -1
  75. package/dist/core/resource-loader.js +18 -6
  76. package/dist/core/resource-loader.js.map +1 -1
  77. package/dist/core/runtime-builder.d.ts +3 -1
  78. package/dist/core/runtime-builder.d.ts.map +1 -1
  79. package/dist/core/runtime-builder.js +14 -0
  80. package/dist/core/runtime-builder.js.map +1 -1
  81. package/dist/core/security/untrusted-boundary.d.ts.map +1 -1
  82. package/dist/core/security/untrusted-boundary.js +4 -6
  83. package/dist/core/security/untrusted-boundary.js.map +1 -1
  84. package/dist/core/session-role.d.ts.map +1 -1
  85. package/dist/core/session-role.js +1 -0
  86. package/dist/core/session-role.js.map +1 -1
  87. package/dist/core/system-prompt.d.ts.map +1 -1
  88. package/dist/core/system-prompt.js +21 -23
  89. package/dist/core/system-prompt.js.map +1 -1
  90. package/dist/core/tool-capability-policy.js +1 -1
  91. package/dist/core/tool-capability-policy.js.map +1 -1
  92. package/dist/core/tool-recovery-log-records.d.ts +33 -1
  93. package/dist/core/tool-recovery-log-records.d.ts.map +1 -1
  94. package/dist/core/tool-recovery-log-records.js +59 -12
  95. package/dist/core/tool-recovery-log-records.js.map +1 -1
  96. package/dist/core/tool-recovery-logger.d.ts +12 -1
  97. package/dist/core/tool-recovery-logger.d.ts.map +1 -1
  98. package/dist/core/tool-recovery-logger.js +24 -1
  99. package/dist/core/tool-recovery-logger.js.map +1 -1
  100. package/dist/core/tool-repair-health.d.ts.map +1 -1
  101. package/dist/core/tool-repair-health.js +6 -0
  102. package/dist/core/tool-repair-health.js.map +1 -1
  103. package/dist/core/tools/bash.d.ts +3 -8
  104. package/dist/core/tools/bash.d.ts.map +1 -1
  105. package/dist/core/tools/bash.js +4 -28
  106. package/dist/core/tools/bash.js.map +1 -1
  107. package/dist/core/tools/delegate.js +4 -4
  108. package/dist/core/tools/delegate.js.map +1 -1
  109. package/dist/core/tools/edit-diff.d.ts +32 -5
  110. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  111. package/dist/core/tools/edit-diff.js +137 -69
  112. package/dist/core/tools/edit-diff.js.map +1 -1
  113. package/dist/core/tools/edit.d.ts +22 -7
  114. package/dist/core/tools/edit.d.ts.map +1 -1
  115. package/dist/core/tools/edit.js +128 -55
  116. package/dist/core/tools/edit.js.map +1 -1
  117. package/dist/core/tools/file-mutation-intent.d.ts +70 -0
  118. package/dist/core/tools/file-mutation-intent.d.ts.map +1 -0
  119. package/dist/core/tools/file-mutation-intent.js +325 -0
  120. package/dist/core/tools/file-mutation-intent.js.map +1 -0
  121. package/dist/core/tools/find.d.ts +2 -1
  122. package/dist/core/tools/find.d.ts.map +1 -1
  123. package/dist/core/tools/find.js +2 -6
  124. package/dist/core/tools/find.js.map +1 -1
  125. package/dist/core/tools/goal.d.ts.map +1 -1
  126. package/dist/core/tools/goal.js +41 -18
  127. package/dist/core/tools/goal.js.map +1 -1
  128. package/dist/core/tools/grep.d.ts +2 -1
  129. package/dist/core/tools/grep.d.ts.map +1 -1
  130. package/dist/core/tools/grep.js +2 -6
  131. package/dist/core/tools/grep.js.map +1 -1
  132. package/dist/core/tools/index.d.ts +3 -1
  133. package/dist/core/tools/index.d.ts.map +1 -1
  134. package/dist/core/tools/index.js +31 -8
  135. package/dist/core/tools/index.js.map +1 -1
  136. package/dist/core/tools/managed-search-tool.d.ts +8 -0
  137. package/dist/core/tools/managed-search-tool.d.ts.map +1 -0
  138. package/dist/core/tools/managed-search-tool.js +10 -0
  139. package/dist/core/tools/managed-search-tool.js.map +1 -0
  140. package/dist/core/tools/profile-writer.d.ts +33 -0
  141. package/dist/core/tools/profile-writer.d.ts.map +1 -0
  142. package/dist/core/tools/profile-writer.js +67 -0
  143. package/dist/core/tools/profile-writer.js.map +1 -0
  144. package/dist/core/tools/shell-command-parser.d.ts +4 -3
  145. package/dist/core/tools/shell-command-parser.d.ts.map +1 -1
  146. package/dist/core/tools/shell-command-parser.js +32 -7
  147. package/dist/core/tools/shell-command-parser.js.map +1 -1
  148. package/dist/core/tools/shell-contract-router.d.ts.map +1 -1
  149. package/dist/core/tools/shell-contract-router.js +23 -1
  150. package/dist/core/tools/shell-contract-router.js.map +1 -1
  151. package/dist/core/tools/task-steps.d.ts.map +1 -1
  152. package/dist/core/tools/task-steps.js +6 -11
  153. package/dist/core/tools/task-steps.js.map +1 -1
  154. package/dist/core/tools/tmux-dispatch.d.ts +2 -0
  155. package/dist/core/tools/tmux-dispatch.d.ts.map +1 -1
  156. package/dist/core/tools/tmux-dispatch.js +16 -2
  157. package/dist/core/tools/tmux-dispatch.js.map +1 -1
  158. package/dist/core/tools/windows-shell-engine.js +1 -1
  159. package/dist/core/tools/windows-shell-engine.js.map +1 -1
  160. package/dist/core/tools/write.d.ts +24 -7
  161. package/dist/core/tools/write.d.ts.map +1 -1
  162. package/dist/core/tools/write.js +182 -107
  163. package/dist/core/tools/write.js.map +1 -1
  164. package/dist/index.d.ts +1 -1
  165. package/dist/index.d.ts.map +1 -1
  166. package/dist/index.js +1 -1
  167. package/dist/index.js.map +1 -1
  168. package/dist/jscpd-cli.d.ts +3 -0
  169. package/dist/jscpd-cli.d.ts.map +1 -0
  170. package/dist/jscpd-cli.js +22 -0
  171. package/dist/jscpd-cli.js.map +1 -0
  172. package/dist/modes/interactive/components/profile-resource-editor.js +2 -2
  173. package/dist/modes/interactive/components/profile-resource-editor.js.map +1 -1
  174. package/dist/modes/interactive/components/tool-execution.d.ts +1 -0
  175. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  176. package/dist/modes/interactive/components/tool-execution.js +85 -3
  177. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  178. package/dist/modes/interactive/interactive-mode.js +1 -1
  179. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  180. package/dist/utils/bundled-jscpd.d.ts +20 -0
  181. package/dist/utils/bundled-jscpd.d.ts.map +1 -0
  182. package/dist/utils/bundled-jscpd.js +154 -0
  183. package/dist/utils/bundled-jscpd.js.map +1 -0
  184. package/dist/utils/paths.js +1 -1
  185. package/dist/utils/paths.js.map +1 -1
  186. package/dist/utils/shell.d.ts.map +1 -1
  187. package/dist/utils/shell.js +11 -0
  188. package/dist/utils/shell.js.map +1 -1
  189. package/dist/utils/tools-manager.d.ts +19 -2
  190. package/dist/utils/tools-manager.d.ts.map +1 -1
  191. package/dist/utils/tools-manager.js +92 -40
  192. package/dist/utils/tools-manager.js.map +1 -1
  193. package/docs/index.md +3 -0
  194. package/docs/managed-data-tools.md +15 -0
  195. package/docs/models.md +1 -1
  196. package/docs/quickstart.md +2 -2
  197. package/docs/settings.md +1 -1
  198. package/docs/tool-boundary-performance-roadmap-2026-08-02.md +166 -0
  199. package/docs/tool-repair.md +4 -4
  200. package/docs/windows.md +7 -5
  201. package/docs/worker-profiles.md +16 -0
  202. package/examples/extensions/built-in-tool-renderer.ts +12 -5
  203. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  204. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  205. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  206. package/examples/extensions/minimal-mode.ts +8 -7
  207. package/examples/extensions/prompt-customizer.ts +4 -2
  208. package/examples/extensions/sandbox/package-lock.json +2 -2
  209. package/examples/extensions/sandbox/package.json +1 -1
  210. package/examples/extensions/ssh.ts +113 -24
  211. package/examples/extensions/with-deps/package-lock.json +2 -2
  212. package/examples/extensions/with-deps/package.json +1 -1
  213. package/npm-shrinkwrap.json +112 -12
  214. package/package.json +7 -5
@@ -0,0 +1,20 @@
1
+ export declare const JSCPD_VERSION = "5.0.14";
2
+ type ModuleRequire = ((id: string) => unknown) & {
3
+ resolve?(id: string): string;
4
+ };
5
+ export interface BundledJscpdSource {
6
+ sourcePath: string;
7
+ sourceVersion: string;
8
+ }
9
+ export interface InstallBundledJscpdBinaryOptions extends BundledJscpdSource {
10
+ managedBinDir: string;
11
+ targetPlatform: string;
12
+ probeVersion?: (path: string) => string | undefined;
13
+ }
14
+ export declare function resolveJscpdPlatformPackage(targetPlatform: string, targetArchitecture: string, libc?: "glibc" | "musl"): string | undefined;
15
+ export declare function resolveBundledJscpdSource(targetPlatform?: string, targetArchitecture?: string, requires?: readonly ModuleRequire[]): BundledJscpdSource | undefined;
16
+ export declare function probeJscpdVersion(path: string): string | undefined;
17
+ export declare function installBundledJscpdBinary(options: InstallBundledJscpdBinaryOptions): string;
18
+ export declare function ensureManagedJscpd(managedBinDir?: string): string;
19
+ export {};
20
+ //# sourceMappingURL=bundled-jscpd.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundled-jscpd.d.ts","sourceRoot":"","sources":["../../src/utils/bundled-jscpd.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,aAAa,WAAW,CAAC;AAEtC,KAAK,aAAa,GAAG,CAAC,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG;IAAE,OAAO,CAAC,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAElF,MAAM,WAAW,kBAAkB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,gCAAiC,SAAQ,kBAAkB;IAC3E,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;CACpD;AAMD,wBAAgB,2BAA2B,CAC1C,cAAc,EAAE,MAAM,EACtB,kBAAkB,EAAE,MAAM,EAC1B,IAAI,GAAE,OAAO,GAAG,MAAgB,GAC9B,MAAM,GAAG,SAAS,CAepB;AAgCD,wBAAgB,yBAAyB,CACxC,cAAc,GAAE,MAAmB,EACnC,kBAAkB,GAAE,MAAe,EACnC,QAAQ,GAAE,SAAS,aAAa,EAA0C,GACxE,kBAAkB,GAAG,SAAS,CAWhC;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAalE;AAMD,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,gCAAgC,GAAG,MAAM,CA2C3F;AAED,wBAAgB,kBAAkB,CAAC,aAAa,GAAE,MAAoB,GAAG,MAAM,CA0B9E"}
@@ -0,0 +1,154 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { chmodSync, copyFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync } from "node:fs";
3
+ import { createRequire } from "node:module";
4
+ import { arch, platform } from "node:os";
5
+ import { dirname, join } from "node:path";
6
+ import { pathToFileURL } from "node:url";
7
+ import { getBinDir } from "../config.js";
8
+ export const JSCPD_VERSION = "5.0.14";
9
+ const moduleRequire = createRequire(import.meta.url);
10
+ const executableDirRequire = createRequire(pathToFileURL(join(dirname(process.execPath), "package.json")).href);
11
+ let cachedManagedPath;
12
+ export function resolveJscpdPlatformPackage(targetPlatform, targetArchitecture, libc = "glibc") {
13
+ if (targetPlatform === "darwin" && (targetArchitecture === "arm64" || targetArchitecture === "x64")) {
14
+ return `jscpd-darwin-${targetArchitecture}`;
15
+ }
16
+ if (targetPlatform === "linux" && targetArchitecture === "x64") {
17
+ return libc === "musl" ? "jscpd-linux-x64-musl" : "jscpd-linux-x64-gnu";
18
+ }
19
+ if (targetPlatform === "linux" && targetArchitecture === "arm64" && libc === "glibc") {
20
+ return "jscpd-linux-arm64-gnu";
21
+ }
22
+ if (targetPlatform === "win32" && (targetArchitecture === "arm64" || targetArchitecture === "x64")) {
23
+ // Upstream publishes x64 only. Windows on Arm supports x64 application emulation.
24
+ return "jscpd-windows-x64-msvc";
25
+ }
26
+ return undefined;
27
+ }
28
+ function detectRuntimeLibc() {
29
+ if (platform() !== "linux")
30
+ return "glibc";
31
+ const report = process.report?.getReport();
32
+ return report?.header?.glibcVersionRuntime ? "glibc" : "musl";
33
+ }
34
+ function binaryName(targetPlatform) {
35
+ return targetPlatform === "win32" ? "jscpd.exe" : "jscpd";
36
+ }
37
+ function readSourceFromPackage(packageName, requires) {
38
+ for (const requireFrom of requires) {
39
+ try {
40
+ const packageJsonPath = requireFrom.resolve?.(`${packageName}/package.json`);
41
+ if (!packageJsonPath)
42
+ continue;
43
+ const manifest = JSON.parse(readFileSync(packageJsonPath, "utf8"));
44
+ const sourcePath = join(dirname(packageJsonPath), "bin", binaryName(platform()));
45
+ if (typeof manifest.version === "string" && existsSync(sourcePath)) {
46
+ return { sourcePath, sourceVersion: manifest.version };
47
+ }
48
+ }
49
+ catch {
50
+ // Try the next package-resolution root.
51
+ }
52
+ }
53
+ return undefined;
54
+ }
55
+ export function resolveBundledJscpdSource(targetPlatform = platform(), targetArchitecture = arch(), requires = [moduleRequire, executableDirRequire]) {
56
+ const standaloneBinary = join(dirname(process.execPath), "bundled-tools", binaryName(targetPlatform));
57
+ const standaloneVersion = join(dirname(process.execPath), "bundled-tools", "jscpd.version");
58
+ if (targetPlatform === platform() && existsSync(standaloneBinary) && existsSync(standaloneVersion)) {
59
+ return {
60
+ sourcePath: standaloneBinary,
61
+ sourceVersion: readFileSync(standaloneVersion, "utf8").trim(),
62
+ };
63
+ }
64
+ const packageName = resolveJscpdPlatformPackage(targetPlatform, targetArchitecture, detectRuntimeLibc());
65
+ return packageName ? readSourceFromPackage(packageName, requires) : undefined;
66
+ }
67
+ export function probeJscpdVersion(path) {
68
+ try {
69
+ const result = spawnSync(path, ["--version"], {
70
+ encoding: "utf8",
71
+ stdio: "pipe",
72
+ timeout: 5_000,
73
+ windowsHide: true,
74
+ });
75
+ if (result.error || result.status !== 0)
76
+ return undefined;
77
+ return `${result.stdout ?? ""}${result.stderr ?? ""}`.trim() || undefined;
78
+ }
79
+ catch {
80
+ return undefined;
81
+ }
82
+ }
83
+ function isExactVersion(output) {
84
+ return output?.split(/\s+/).includes(JSCPD_VERSION) === true;
85
+ }
86
+ export function installBundledJscpdBinary(options) {
87
+ if (options.sourceVersion !== JSCPD_VERSION) {
88
+ throw new Error(`Pi requires bundled jscpd ${JSCPD_VERSION}; found ${options.sourceVersion || "unknown"}.`);
89
+ }
90
+ const targetPath = join(options.managedBinDir, binaryName(options.targetPlatform));
91
+ const temporaryPath = join(options.managedBinDir, `.jscpd-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2, 10)}${options.targetPlatform === "win32" ? ".exe" : ""}`);
92
+ mkdirSync(options.managedBinDir, { recursive: true });
93
+ const probeVersion = options.probeVersion ?? probeJscpdVersion;
94
+ let promoted = false;
95
+ try {
96
+ copyFileSync(options.sourcePath, temporaryPath);
97
+ if (options.targetPlatform !== "win32")
98
+ chmodSync(temporaryPath, 0o755);
99
+ const version = probeVersion(temporaryPath);
100
+ if (!isExactVersion(version)) {
101
+ throw new Error(`Pi requires bundled jscpd ${JSCPD_VERSION}; installed binary reported ${version ?? "no version"}.`);
102
+ }
103
+ try {
104
+ renameSync(temporaryPath, targetPath);
105
+ promoted = true;
106
+ }
107
+ catch {
108
+ // Concurrent sessions converge on the same exact binary. Windows cannot replace an
109
+ // existing executable with rename, so accept a valid winner without deleting it.
110
+ if (existsSync(targetPath) && isExactVersion(probeVersion(targetPath))) {
111
+ rmSync(temporaryPath, { force: true });
112
+ return targetPath;
113
+ }
114
+ rmSync(targetPath, { force: true });
115
+ renameSync(temporaryPath, targetPath);
116
+ promoted = true;
117
+ }
118
+ return targetPath;
119
+ }
120
+ catch (error) {
121
+ rmSync(temporaryPath, { force: true });
122
+ if (promoted && !isExactVersion(probeVersion(targetPath)))
123
+ rmSync(targetPath, { force: true });
124
+ throw error;
125
+ }
126
+ }
127
+ export function ensureManagedJscpd(managedBinDir = getBinDir()) {
128
+ const targetPath = join(managedBinDir, binaryName(platform()));
129
+ if (cachedManagedPath?.path === targetPath) {
130
+ try {
131
+ if (statSync(cachedManagedPath.path).mtimeMs === cachedManagedPath.mtimeMs)
132
+ return cachedManagedPath.path;
133
+ }
134
+ catch {
135
+ cachedManagedPath = undefined;
136
+ }
137
+ }
138
+ if (existsSync(targetPath) && isExactVersion(probeJscpdVersion(targetPath))) {
139
+ cachedManagedPath = { path: targetPath, mtimeMs: statSync(targetPath).mtimeMs };
140
+ return targetPath;
141
+ }
142
+ const source = resolveBundledJscpdSource();
143
+ if (!source) {
144
+ throw new Error(`Bundled jscpd ${JSCPD_VERSION} is unavailable for ${platform()}/${arch()}. Reinstall Pi for this platform.`);
145
+ }
146
+ const installed = installBundledJscpdBinary({
147
+ ...source,
148
+ managedBinDir,
149
+ targetPlatform: platform(),
150
+ });
151
+ cachedManagedPath = { path: installed, mtimeMs: statSync(installed).mtimeMs };
152
+ return installed;
153
+ }
154
+ //# sourceMappingURL=bundled-jscpd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundled-jscpd.js","sourceRoot":"","sources":["../../src/utils/bundled-jscpd.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACrH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC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AC;YACR,iBAAiB,GAAG,SAAS,CAAC;QAC/B,CAAC;IACF,CAAC;IACD,IAAI,UAAU,CAAC,UAAU,CAAC,IAAI,cAAc,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;QAC7E,iBAAiB,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE,CAAC;QAChF,OAAO,UAAU,CAAC;IACnB,CAAC;IACD,MAAM,MAAM,GAAG,yBAAyB,EAAE,CAAC;IAC3C,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACd,iBAAiB,aAAa,uBAAuB,QAAQ,EAAE,IAAI,IAAI,EAAE,mCAAmC,CAC5G,CAAC;IACH,CAAC;IACD,MAAM,SAAS,GAAG,yBAAyB,CAAC;QAC3C,GAAG,MAAM;QACT,aAAa;QACb,cAAc,EAAE,QAAQ,EAAE;KAC1B,CAAC,CAAC;IACH,iBAAiB,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC;IAC9E,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["import { spawnSync } from \"node:child_process\";\nimport { chmodSync, copyFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { arch, platform } from \"node:os\";\nimport { dirname, join } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { getBinDir } from \"../config.ts\";\n\nexport const JSCPD_VERSION = \"5.0.14\";\n\ntype ModuleRequire = ((id: string) => unknown) & { resolve?(id: string): string };\n\nexport interface BundledJscpdSource {\n\tsourcePath: string;\n\tsourceVersion: string;\n}\n\nexport interface InstallBundledJscpdBinaryOptions extends BundledJscpdSource {\n\tmanagedBinDir: string;\n\ttargetPlatform: string;\n\tprobeVersion?: (path: string) => string | undefined;\n}\n\nconst moduleRequire = createRequire(import.meta.url);\nconst executableDirRequire = createRequire(pathToFileURL(join(dirname(process.execPath), \"package.json\")).href);\nlet cachedManagedPath: { path: string; mtimeMs: number } | undefined;\n\nexport function resolveJscpdPlatformPackage(\n\ttargetPlatform: string,\n\ttargetArchitecture: string,\n\tlibc: \"glibc\" | \"musl\" = \"glibc\",\n): string | undefined {\n\tif (targetPlatform === \"darwin\" && (targetArchitecture === \"arm64\" || targetArchitecture === \"x64\")) {\n\t\treturn `jscpd-darwin-${targetArchitecture}`;\n\t}\n\tif (targetPlatform === \"linux\" && targetArchitecture === \"x64\") {\n\t\treturn libc === \"musl\" ? \"jscpd-linux-x64-musl\" : \"jscpd-linux-x64-gnu\";\n\t}\n\tif (targetPlatform === \"linux\" && targetArchitecture === \"arm64\" && libc === \"glibc\") {\n\t\treturn \"jscpd-linux-arm64-gnu\";\n\t}\n\tif (targetPlatform === \"win32\" && (targetArchitecture === \"arm64\" || targetArchitecture === \"x64\")) {\n\t\t// Upstream publishes x64 only. Windows on Arm supports x64 application emulation.\n\t\treturn \"jscpd-windows-x64-msvc\";\n\t}\n\treturn undefined;\n}\n\nfunction detectRuntimeLibc(): \"glibc\" | \"musl\" {\n\tif (platform() !== \"linux\") return \"glibc\";\n\tconst report = process.report?.getReport() as { header?: { glibcVersionRuntime?: string } } | undefined;\n\treturn report?.header?.glibcVersionRuntime ? \"glibc\" : \"musl\";\n}\n\nfunction binaryName(targetPlatform: string): string {\n\treturn targetPlatform === \"win32\" ? \"jscpd.exe\" : \"jscpd\";\n}\n\nfunction readSourceFromPackage(\n\tpackageName: string,\n\trequires: readonly ModuleRequire[],\n): BundledJscpdSource | undefined {\n\tfor (const requireFrom of requires) {\n\t\ttry {\n\t\t\tconst packageJsonPath = requireFrom.resolve?.(`${packageName}/package.json`);\n\t\t\tif (!packageJsonPath) continue;\n\t\t\tconst manifest = JSON.parse(readFileSync(packageJsonPath, \"utf8\")) as { version?: unknown };\n\t\t\tconst sourcePath = join(dirname(packageJsonPath), \"bin\", binaryName(platform()));\n\t\t\tif (typeof manifest.version === \"string\" && existsSync(sourcePath)) {\n\t\t\t\treturn { sourcePath, sourceVersion: manifest.version };\n\t\t\t}\n\t\t} catch {\n\t\t\t// Try the next package-resolution root.\n\t\t}\n\t}\n\treturn undefined;\n}\n\nexport function resolveBundledJscpdSource(\n\ttargetPlatform: string = platform(),\n\ttargetArchitecture: string = arch(),\n\trequires: readonly ModuleRequire[] = [moduleRequire, executableDirRequire],\n): BundledJscpdSource | undefined {\n\tconst standaloneBinary = join(dirname(process.execPath), \"bundled-tools\", binaryName(targetPlatform));\n\tconst standaloneVersion = join(dirname(process.execPath), \"bundled-tools\", \"jscpd.version\");\n\tif (targetPlatform === platform() && existsSync(standaloneBinary) && existsSync(standaloneVersion)) {\n\t\treturn {\n\t\t\tsourcePath: standaloneBinary,\n\t\t\tsourceVersion: readFileSync(standaloneVersion, \"utf8\").trim(),\n\t\t};\n\t}\n\tconst packageName = resolveJscpdPlatformPackage(targetPlatform, targetArchitecture, detectRuntimeLibc());\n\treturn packageName ? readSourceFromPackage(packageName, requires) : undefined;\n}\n\nexport function probeJscpdVersion(path: string): string | undefined {\n\ttry {\n\t\tconst result = spawnSync(path, [\"--version\"], {\n\t\t\tencoding: \"utf8\",\n\t\t\tstdio: \"pipe\",\n\t\t\ttimeout: 5_000,\n\t\t\twindowsHide: true,\n\t\t});\n\t\tif (result.error || result.status !== 0) return undefined;\n\t\treturn `${result.stdout ?? \"\"}${result.stderr ?? \"\"}`.trim() || undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction isExactVersion(output: string | undefined): boolean {\n\treturn output?.split(/\\s+/).includes(JSCPD_VERSION) === true;\n}\n\nexport function installBundledJscpdBinary(options: InstallBundledJscpdBinaryOptions): string {\n\tif (options.sourceVersion !== JSCPD_VERSION) {\n\t\tthrow new Error(`Pi requires bundled jscpd ${JSCPD_VERSION}; found ${options.sourceVersion || \"unknown\"}.`);\n\t}\n\tconst targetPath = join(options.managedBinDir, binaryName(options.targetPlatform));\n\tconst temporaryPath = join(\n\t\toptions.managedBinDir,\n\t\t`.jscpd-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2, 10)}${\n\t\t\toptions.targetPlatform === \"win32\" ? \".exe\" : \"\"\n\t\t}`,\n\t);\n\tmkdirSync(options.managedBinDir, { recursive: true });\n\tconst probeVersion = options.probeVersion ?? probeJscpdVersion;\n\tlet promoted = false;\n\ttry {\n\t\tcopyFileSync(options.sourcePath, temporaryPath);\n\t\tif (options.targetPlatform !== \"win32\") chmodSync(temporaryPath, 0o755);\n\t\tconst version = probeVersion(temporaryPath);\n\t\tif (!isExactVersion(version)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Pi requires bundled jscpd ${JSCPD_VERSION}; installed binary reported ${version ?? \"no version\"}.`,\n\t\t\t);\n\t\t}\n\t\ttry {\n\t\t\trenameSync(temporaryPath, targetPath);\n\t\t\tpromoted = true;\n\t\t} catch {\n\t\t\t// Concurrent sessions converge on the same exact binary. Windows cannot replace an\n\t\t\t// existing executable with rename, so accept a valid winner without deleting it.\n\t\t\tif (existsSync(targetPath) && isExactVersion(probeVersion(targetPath))) {\n\t\t\t\trmSync(temporaryPath, { force: true });\n\t\t\t\treturn targetPath;\n\t\t\t}\n\t\t\trmSync(targetPath, { force: true });\n\t\t\trenameSync(temporaryPath, targetPath);\n\t\t\tpromoted = true;\n\t\t}\n\t\treturn targetPath;\n\t} catch (error) {\n\t\trmSync(temporaryPath, { force: true });\n\t\tif (promoted && !isExactVersion(probeVersion(targetPath))) rmSync(targetPath, { force: true });\n\t\tthrow error;\n\t}\n}\n\nexport function ensureManagedJscpd(managedBinDir: string = getBinDir()): string {\n\tconst targetPath = join(managedBinDir, binaryName(platform()));\n\tif (cachedManagedPath?.path === targetPath) {\n\t\ttry {\n\t\t\tif (statSync(cachedManagedPath.path).mtimeMs === cachedManagedPath.mtimeMs) return cachedManagedPath.path;\n\t\t} catch {\n\t\t\tcachedManagedPath = undefined;\n\t\t}\n\t}\n\tif (existsSync(targetPath) && isExactVersion(probeJscpdVersion(targetPath))) {\n\t\tcachedManagedPath = { path: targetPath, mtimeMs: statSync(targetPath).mtimeMs };\n\t\treturn targetPath;\n\t}\n\tconst source = resolveBundledJscpdSource();\n\tif (!source) {\n\t\tthrow new Error(\n\t\t\t`Bundled jscpd ${JSCPD_VERSION} is unavailable for ${platform()}/${arch()}. Reinstall Pi for this platform.`,\n\t\t);\n\t}\n\tconst installed = installBundledJscpdBinary({\n\t\t...source,\n\t\tmanagedBinDir,\n\t\ttargetPlatform: platform(),\n\t});\n\tcachedManagedPath = { path: installed, mtimeMs: statSync(installed).mtimeMs };\n\treturn installed;\n}\n"]}
@@ -13,7 +13,7 @@ export { normalizePath, resolvePath };
13
13
  */
14
14
  export function canonicalizePath(path) {
15
15
  try {
16
- return realpathSync(path);
16
+ return realpathSync.native(path);
17
17
  }
18
18
  catch {
19
19
  return path;
@@ -1 +1 @@
1
- {"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/utils/paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,aAAa,EAAyB,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACpG,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,qGAAqG;AACrG,+FAA+F;AAC/F,OAAO,EAAE,aAAa,EAAyB,WAAW,EAAE,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC5C,IAAI,CAAC;QACJ,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,IAAI,CAAC;IACb,CAAC;AACF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,KA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AAC,QAAQ,CAAC,WAAW,EAAE,YAAY,CAAC,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1F,OAAO,eAAe,CAAC,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC;AAC5F,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,IAAY;IACtD,MAAM,KAAK,GACV,OAAO,CAAC,QAAQ,KAAK,QAAQ;QAC5B,CAAC,CAAC,CAAC,qBAAqB,EAAE,iCAAiC,CAAC;QAC5D,CAAC,CAAC,OAAO,CAAC,QAAQ,KAAK,OAAO;YAC7B,CAAC,CAAC,CAAC,0BAA0B,CAAC;YAC9B,CAAC,CAAC,EAAE,CAAC;IAER,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACnC,gBAAgB,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE;gBAClD,QAAQ,EAAE,OAAO;gBACjB,KAAK,EAAE,QAAQ;gBACf,OAAO,EAAE,KAAK;aACd,CAAC,CAAC;QACJ,CAAC;aAAM,CAAC;YACP,gBAAgB,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE;gBAC3D,QAAQ,EAAE,OAAO;gBACjB,KAAK,EAAE,QAAQ;gBACf,OAAO,EAAE,KAAK;aACd,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import { realpathSync } from \"node:fs\";\nimport { isAbsolute, relative, sep } from \"node:path\";\nimport { normalizePath, type PathInputOptions, resolvePath } from \"@caupulican/pi-agent-core/paths\";\nimport { spawnProcessSync } from \"./child-process.ts\";\n\n// normalizePath/resolvePath (and PathInputOptions) are promoted into the kernel's pure paths module.\n// Re-export them so existing coding-agent consumers keep importing from this module unchanged.\nexport { normalizePath, type PathInputOptions, resolvePath };\n\n/**\n * Resolve a path to its canonical (real) form, following symlinks.\n * Falls back to the raw path if resolution fails (e.g. the target does\n * not exist yet), so that callers never crash on missing filesystem\n * entries.\n */\nexport function canonicalizePath(path: string): string {\n\ttry {\n\t\treturn realpathSync(path);\n\t} catch {\n\t\treturn path;\n\t}\n}\n\n/**\n * Returns true if the value is NOT a package source (npm:, git:, etc.)\n * or a remote URL protocol. Bare names, relative paths, and file: URLs\n * are considered local.\n */\nexport function isLocalPath(value: string): boolean {\n\tconst trimmed = value.trim();\n\t// Known non-local prefixes. file: URLs are local paths and are intentionally resolved by resolvePath().\n\tif (\n\t\ttrimmed.startsWith(\"npm:\") ||\n\t\ttrimmed.startsWith(\"git:\") ||\n\t\ttrimmed.startsWith(\"github:\") ||\n\t\ttrimmed.startsWith(\"http:\") ||\n\t\ttrimmed.startsWith(\"https:\") ||\n\t\ttrimmed.startsWith(\"ssh:\")\n\t) {\n\t\treturn false;\n\t}\n\treturn true;\n}\n\nexport function getCwdRelativePath(filePath: string, cwd: string): string | undefined {\n\tconst resolvedCwd = resolvePath(cwd);\n\tconst resolvedPath = resolvePath(filePath, resolvedCwd);\n\tconst relativePath = relative(resolvedCwd, resolvedPath);\n\tconst isInsideCwd =\n\t\trelativePath === \"\" ||\n\t\t(relativePath !== \"..\" && !relativePath.startsWith(`..${sep}`) && !isAbsolute(relativePath));\n\n\treturn isInsideCwd ? relativePath || \".\" : undefined;\n}\n\nexport function formatPathRelativeToCwdOrAbsolute(filePath: string, cwd: string): string {\n\tconst absolutePath = resolvePath(filePath, cwd);\n\tconst resolvedCwd = resolvePath(cwd);\n\tconst absoluteDisplay = absolutePath.split(sep).join(\"/\");\n\tconst relativeDisplay = (relative(resolvedCwd, absolutePath) || \".\").split(sep).join(\"/\");\n\treturn relativeDisplay.length < absoluteDisplay.length ? relativeDisplay : absoluteDisplay;\n}\n\nexport function markPathIgnoredByCloudSync(path: string): void {\n\tconst attrs =\n\t\tprocess.platform === \"darwin\"\n\t\t\t? [\"com.dropbox.ignored\", \"com.apple.fileprovider.ignore#P\"]\n\t\t\t: process.platform === \"linux\"\n\t\t\t\t? [\"user.com.dropbox.ignored\"]\n\t\t\t\t: [];\n\n\tfor (const attr of attrs) {\n\t\tif (process.platform === \"darwin\") {\n\t\t\tspawnProcessSync(\"xattr\", [\"-w\", attr, \"1\", path], {\n\t\t\t\tencoding: \"utf-8\",\n\t\t\t\tstdio: \"ignore\",\n\t\t\t\ttimeout: 2_000,\n\t\t\t});\n\t\t} else {\n\t\t\tspawnProcessSync(\"setfattr\", [\"-n\", attr, \"-v\", \"1\", path], {\n\t\t\t\tencoding: \"utf-8\",\n\t\t\t\tstdio: \"ignore\",\n\t\t\t\ttimeout: 2_000,\n\t\t\t});\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/utils/paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,aAAa,EAAyB,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACpG,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,qGAAqG;AACrG,+FAA+F;AAC/F,OAAO,EAAE,aAAa,EAAyB,WAAW,EAAE,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC5C,IAAI,CAAC;QACJ,OAAO,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,IAAI,CAAC;IACb,CAAC;AACF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,KAAa;IACxC,MAAM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AC,WAAW,EAAE,YAAY,CAAC,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1F,OAAO,eAAe,CAAC,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC;AAC5F,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,IAAY;IACtD,MAAM,KAAK,GACV,OAAO,CAAC,QAAQ,KAAK,QAAQ;QAC5B,CAAC,CAAC,CAAC,qBAAqB,EAAE,iCAAiC,CAAC;QAC5D,CAAC,CAAC,OAAO,CAAC,QAAQ,KAAK,OAAO;YAC7B,CAAC,CAAC,CAAC,0BAA0B,CAAC;YAC9B,CAAC,CAAC,EAAE,CAAC;IAER,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACnC,gBAAgB,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE;gBAClD,QAAQ,EAAE,OAAO;gBACjB,KAAK,EAAE,QAAQ;gBACf,OAAO,EAAE,KAAK;aACd,CAAC,CAAC;QACJ,CAAC;aAAM,CAAC;YACP,gBAAgB,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE;gBAC3D,QAAQ,EAAE,OAAO;gBACjB,KAAK,EAAE,QAAQ;gBACf,OAAO,EAAE,KAAK;aACd,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import { realpathSync } from \"node:fs\";\nimport { isAbsolute, relative, sep } from \"node:path\";\nimport { normalizePath, type PathInputOptions, resolvePath } from \"@caupulican/pi-agent-core/paths\";\nimport { spawnProcessSync } from \"./child-process.ts\";\n\n// normalizePath/resolvePath (and PathInputOptions) are promoted into the kernel's pure paths module.\n// Re-export them so existing coding-agent consumers keep importing from this module unchanged.\nexport { normalizePath, type PathInputOptions, resolvePath };\n\n/**\n * Resolve a path to its canonical (real) form, following symlinks.\n * Falls back to the raw path if resolution fails (e.g. the target does\n * not exist yet), so that callers never crash on missing filesystem\n * entries.\n */\nexport function canonicalizePath(path: string): string {\n\ttry {\n\t\treturn realpathSync.native(path);\n\t} catch {\n\t\treturn path;\n\t}\n}\n\n/**\n * Returns true if the value is NOT a package source (npm:, git:, etc.)\n * or a remote URL protocol. Bare names, relative paths, and file: URLs\n * are considered local.\n */\nexport function isLocalPath(value: string): boolean {\n\tconst trimmed = value.trim();\n\t// Known non-local prefixes. file: URLs are local paths and are intentionally resolved by resolvePath().\n\tif (\n\t\ttrimmed.startsWith(\"npm:\") ||\n\t\ttrimmed.startsWith(\"git:\") ||\n\t\ttrimmed.startsWith(\"github:\") ||\n\t\ttrimmed.startsWith(\"http:\") ||\n\t\ttrimmed.startsWith(\"https:\") ||\n\t\ttrimmed.startsWith(\"ssh:\")\n\t) {\n\t\treturn false;\n\t}\n\treturn true;\n}\n\nexport function getCwdRelativePath(filePath: string, cwd: string): string | undefined {\n\tconst resolvedCwd = resolvePath(cwd);\n\tconst resolvedPath = resolvePath(filePath, resolvedCwd);\n\tconst relativePath = relative(resolvedCwd, resolvedPath);\n\tconst isInsideCwd =\n\t\trelativePath === \"\" ||\n\t\t(relativePath !== \"..\" && !relativePath.startsWith(`..${sep}`) && !isAbsolute(relativePath));\n\n\treturn isInsideCwd ? relativePath || \".\" : undefined;\n}\n\nexport function formatPathRelativeToCwdOrAbsolute(filePath: string, cwd: string): string {\n\tconst absolutePath = resolvePath(filePath, cwd);\n\tconst resolvedCwd = resolvePath(cwd);\n\tconst absoluteDisplay = absolutePath.split(sep).join(\"/\");\n\tconst relativeDisplay = (relative(resolvedCwd, absolutePath) || \".\").split(sep).join(\"/\");\n\treturn relativeDisplay.length < absoluteDisplay.length ? relativeDisplay : absoluteDisplay;\n}\n\nexport function markPathIgnoredByCloudSync(path: string): void {\n\tconst attrs =\n\t\tprocess.platform === \"darwin\"\n\t\t\t? [\"com.dropbox.ignored\", \"com.apple.fileprovider.ignore#P\"]\n\t\t\t: process.platform === \"linux\"\n\t\t\t\t? [\"user.com.dropbox.ignored\"]\n\t\t\t\t: [];\n\n\tfor (const attr of attrs) {\n\t\tif (process.platform === \"darwin\") {\n\t\t\tspawnProcessSync(\"xattr\", [\"-w\", attr, \"1\", path], {\n\t\t\t\tencoding: \"utf-8\",\n\t\t\t\tstdio: \"ignore\",\n\t\t\t\ttimeout: 2_000,\n\t\t\t});\n\t\t} else {\n\t\t\tspawnProcessSync(\"setfattr\", [\"-n\", attr, \"-v\", \"1\", path], {\n\t\t\t\tencoding: \"utf-8\",\n\t\t\t\tstdio: \"ignore\",\n\t\t\t\ttimeout: 2_000,\n\t\t\t});\n\t\t}\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../src/utils/shell.ts"],"names":[],"mappings":"AAMA,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,eAAO,MAAM,sBAAsB,8EAA8E,CAAC;AAIlH,wBAAgB,wBAAwB,CAAC,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAAG,qBAAqB,CAE5G;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE/D;AAoFD,sHAAsH;AACtH,wBAAgB,cAAc,CAC7B,eAAe,CAAC,EAAE,MAAM,EACxB,SAAS,GAAE,qBAAkD,GAC3D,WAAW,CAeb;AAED,wBAAgB,WAAW,IAAI,MAAM,CAAC,UAAU,CAY/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":"AAOA,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,eAAO,MAAM,sBAAsB,8EAA8E,CAAC;AAIlH,wBAAgB,wBAAwB,CAAC,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAAG,qBAAqB,CAE5G;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE/D;AAqFD,sHAAsH;AACtH,wBAAgB,cAAc,CAC7B,eAAe,CAAC,EAAE,MAAM,EACxB,SAAS,GAAE,qBAAkD,GAC3D,WAAW,CAeb;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"}
@@ -2,6 +2,7 @@ import { existsSync } from "node:fs";
2
2
  import { delimiter } from "node:path";
3
3
  import { spawnSync } from "child_process";
4
4
  import { getBinDir } from "../config.js";
5
+ import { ensureManagedJscpd } from "./bundled-jscpd.js";
5
6
  import { normalizePath } from "./paths.js";
6
7
  export const POWERSHELL_UTF8_PREFIX = "try { [Console]::OutputEncoding=[System.Text.Encoding]::UTF8 } catch {}\n";
7
8
  const POWERSHELL_ARGS = ["-NoLogo", "-NoProfile", "-NonInteractive", "-Command"];
@@ -92,6 +93,7 @@ function getBashConfig() {
92
93
  // boot on Windows) and is a process-lifetime invariant, so successful resolutions are cached.
93
94
  // Failures are not cached: the user can install a shell and retry without restarting.
94
95
  const resolvedPlatformShellConfigs = new Map();
96
+ let managedJscpdProvisionAttempted = false;
95
97
  /** Resolve the requested shell. Runtime callers omit shellName to select PowerShell on Windows and Bash elsewhere. */
96
98
  export function getShellConfig(customShellPath, shellName = getPlatformShellToolName()) {
97
99
  if (customShellPath) {
@@ -111,6 +113,15 @@ export function getShellConfig(customShellPath, shellName = getPlatformShellTool
111
113
  return { shell: resolved.shell, args: [...resolved.args] };
112
114
  }
113
115
  export function getShellEnv() {
116
+ if (!managedJscpdProvisionAttempted) {
117
+ managedJscpdProvisionAttempted = true;
118
+ try {
119
+ ensureManagedJscpd();
120
+ }
121
+ catch {
122
+ // The jscpd wrapper and doctor surface the exact packaging failure. Shell startup stays usable.
123
+ }
124
+ }
114
125
  const binDir = getBinDir();
115
126
  const pathKey = Object.keys(process.env).find((key) => key.toLowerCase() === "path") ?? "PATH";
116
127
  const currentPath = process.env[pathKey] ?? "";
@@ -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,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAS3C,MAAM,CAAC,MAAM,sBAAsB,GAAG,2EAA2E,CAAC;AAElH,MAAM,eAAe,GAAG,CAAC,SAAS,EAAE,YAAY,EAAE,iBAAi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J,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 { delimiter } from \"node:path\";\nimport { spawnSync } from \"child_process\";\nimport { getBinDir } from \"../config.ts\";\nimport { normalizePath } from \"./paths.ts\";\n\nexport type PlatformShellToolName = \"bash\" | \"powershell\";\n\nexport interface ShellConfig {\n\tshell: string;\n\targs: string[];\n}\n\nexport const POWERSHELL_UTF8_PREFIX = \"try { [Console]::OutputEncoding=[System.Text.Encoding]::UTF8 } catch {}\\n\";\n\nconst POWERSHELL_ARGS = [\"-NoLogo\", \"-NoProfile\", \"-NonInteractive\", \"-Command\"];\n\nexport function getPlatformShellToolName(platform: NodeJS.Platform = process.platform): PlatformShellToolName {\n\treturn platform === \"win32\" ? \"powershell\" : \"bash\";\n}\n\nexport function prefixPowerShellCommand(command: string): string {\n\treturn command.trimStart().startsWith(POWERSHELL_UTF8_PREFIX) ? command : `${POWERSHELL_UTF8_PREFIX}${command}`;\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, \"Write-Output ok\"], {\n\t\t\t\tencoding: \"utf-8\",\n\t\t\t\ttimeout: 5_000,\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 getPowerShellConfig(): ShellConfig {\n\tconst pwshOnPath = findExecutableOnPath(process.platform === \"win32\" ? \"pwsh.exe\" : \"pwsh\");\n\tif (pwshOnPath && isPowerShellExecutableAvailable(pwshOnPath)) {\n\t\treturn { shell: pwshOnPath, args: [...POWERSHELL_ARGS] };\n\t}\n\n\tconst knownPaths: string[] = [];\n\tconst programFiles = process.env.ProgramFiles;\n\tif (programFiles) knownPaths.push(`${programFiles}\\\\PowerShell\\\\7\\\\pwsh.exe`);\n\tconst systemRoot = process.env.SystemRoot;\n\tif (systemRoot) knownPaths.push(`${systemRoot}\\\\System32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe`);\n\tfor (const path of knownPaths) {\n\t\tif (existsSync(path) && isPowerShellExecutableAvailable(path)) {\n\t\t\treturn { shell: path, args: [...POWERSHELL_ARGS] };\n\t\t}\n\t}\n\n\tconst windowsPowerShellOnPath = findExecutableOnPath(\"powershell.exe\");\n\tif (windowsPowerShellOnPath && isPowerShellExecutableAvailable(windowsPowerShellOnPath)) {\n\t\treturn { shell: windowsPowerShellOnPath, args: [...POWERSHELL_ARGS] };\n\t}\n\tthrow new Error(\n\t\t\"No PowerShell executable found. Install PowerShell 7 (pwsh), restore Windows PowerShell, or set shellPath in settings.json.\",\n\t);\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>();\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 (!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\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,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,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;AAS3C,MAAM,CAAC,MAAM,sBAAsB,GAAG,2EAA2E,CAAC;AAElH,MAAM,eAAe,GAAG,CAAC,SAAS,EAAE,YAAY,EAAE,iBAAiB,EAAE,UAAU,CAAC,CAAC;AAEjF,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,MAAM,UAAU,uBAAuB,CAAC,OAAe;IACtD,OAAO,OAAO,CAAC,SAAS,EAAE,CAAC,UAAU,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC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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 { 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\";\n\nexport type PlatformShellToolName = \"bash\" | \"powershell\";\n\nexport interface ShellConfig {\n\tshell: string;\n\targs: string[];\n}\n\nexport const POWERSHELL_UTF8_PREFIX = \"try { [Console]::OutputEncoding=[System.Text.Encoding]::UTF8 } catch {}\\n\";\n\nconst POWERSHELL_ARGS = [\"-NoLogo\", \"-NoProfile\", \"-NonInteractive\", \"-Command\"];\n\nexport function getPlatformShellToolName(platform: NodeJS.Platform = process.platform): PlatformShellToolName {\n\treturn platform === \"win32\" ? \"powershell\" : \"bash\";\n}\n\nexport function prefixPowerShellCommand(command: string): string {\n\treturn command.trimStart().startsWith(POWERSHELL_UTF8_PREFIX) ? command : `${POWERSHELL_UTF8_PREFIX}${command}`;\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, \"Write-Output ok\"], {\n\t\t\t\tencoding: \"utf-8\",\n\t\t\t\ttimeout: 5_000,\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 getPowerShellConfig(): ShellConfig {\n\tconst pwshOnPath = findExecutableOnPath(process.platform === \"win32\" ? \"pwsh.exe\" : \"pwsh\");\n\tif (pwshOnPath && isPowerShellExecutableAvailable(pwshOnPath)) {\n\t\treturn { shell: pwshOnPath, args: [...POWERSHELL_ARGS] };\n\t}\n\n\tconst knownPaths: string[] = [];\n\tconst programFiles = process.env.ProgramFiles;\n\tif (programFiles) knownPaths.push(`${programFiles}\\\\PowerShell\\\\7\\\\pwsh.exe`);\n\tconst systemRoot = process.env.SystemRoot;\n\tif (systemRoot) knownPaths.push(`${systemRoot}\\\\System32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe`);\n\tfor (const path of knownPaths) {\n\t\tif (existsSync(path) && isPowerShellExecutableAvailable(path)) {\n\t\t\treturn { shell: path, args: [...POWERSHELL_ARGS] };\n\t\t}\n\t}\n\n\tconst windowsPowerShellOnPath = findExecutableOnPath(\"powershell.exe\");\n\tif (windowsPowerShellOnPath && isPowerShellExecutableAvailable(windowsPowerShellOnPath)) {\n\t\treturn { shell: windowsPowerShellOnPath, args: [...POWERSHELL_ARGS] };\n\t}\n\tthrow new Error(\n\t\t\"No PowerShell executable found. Install PowerShell 7 (pwsh), restore Windows PowerShell, or set shellPath in settings.json.\",\n\t);\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 (!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,3 +1,4 @@
1
+ export declare const FD_VERSION = "10.4.2";
1
2
  export declare const RG_VERSION = "15.2.0";
2
3
  export declare const JQ_VERSION = "1.8.2";
3
4
  export declare const UV_VERSION = "0.11.28";
@@ -12,11 +13,25 @@ interface ToolConfig {
12
13
  tagPrefix: string;
13
14
  getAssetName: (version: string, plat: string, architecture: string) => string | null;
14
15
  downloadKind?: "archive" | "binary";
15
- pinnedVersion?: string;
16
+ pinnedVersion: string;
17
+ getPinnedVersion?: (plat: string, architecture: string) => string | undefined;
16
18
  sha256ByAsset?: Readonly<Record<string, string>>;
17
19
  }
18
- declare const TOOLS: Record<"fd" | "jq" | "rg" | "uv", ToolConfig>;
20
+ declare const TOOLS: Record<"fd" | "jq" | "jscpd" | "rg" | "uv", ToolConfig>;
19
21
  export type ManagedToolName = keyof typeof TOOLS;
22
+ export type ManagedToolProvisionFailureCode = "offline" | "unsupported_platform" | "installation_failed" | "not_found_after_install" | "unknown_tool";
23
+ export type ManagedToolResolution = {
24
+ status: "available";
25
+ path: string;
26
+ } | {
27
+ status: "unavailable";
28
+ failureCode: ManagedToolProvisionFailureCode;
29
+ message: string;
30
+ };
31
+ export type ManagedToolResolver = (tool: ManagedToolName, silent?: boolean) => Promise<ManagedToolResolution>;
32
+ export declare function formatManagedToolProvisioningFailure(tool: ManagedToolName, resolution: Extract<ManagedToolResolution, {
33
+ status: "unavailable";
34
+ }>): string;
20
35
  export interface PinnedToolAsset {
21
36
  version: string;
22
37
  assetName: string;
@@ -116,6 +131,8 @@ export declare function computeIsFffInstallCoolingDown(outcome: FffInstallOutcom
116
131
  export declare function ensureFffNodePackage(silent?: boolean, forceManagedInstall?: boolean,
117
132
  /** Override the "is it already available" resolution candidates, for tests. See loadAvailableFffNodePackage's doc. */
118
133
  requires?: readonly ModuleRequire[]): Promise<unknown | undefined>;
134
+ /** Ensure a tool is available while retaining the exact bounded provisioning outcome for callers. */
135
+ export declare function ensureToolWithDiagnostics(tool: ManagedToolName, silent?: boolean): Promise<ManagedToolResolution>;
119
136
  export declare function ensureTool(tool: ManagedToolName, silent?: boolean): Promise<string | undefined>;
120
137
  export {};
121
138
  //# sourceMappingURL=tools-manager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tools-manager.d.ts","sourceRoot":"","sources":["../../src/utils/tools-manager.ts"],"names":[],"mappings":"AAmCA,eAAO,MAAM,UAAU,WAAW,CAAC;AACnC,eAAO,MAAM,UAAU,UAAU,CAAC;AAClC,eAAO,MAAM,UAAU,YAAY,CAAC;AAIpC,KAAK,aAAa,GAAG,CAAC,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG;IAAE,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,CAAA;CAAE,CAAC;AAWtF,UAAU,UAAU;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,CAAC,O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