gentle-pi 4.6.0 → 4.7.0

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 (290) hide show
  1. package/README.md +10 -11
  2. package/assets/agents/gentle-ai-explore.md +1 -0
  3. package/assets/agents/gentle-ai-verify.md +5 -2
  4. package/assets/agents/gentle-ai-worker.md +3 -0
  5. package/assets/agents/jd-fix-agent.md +1 -0
  6. package/assets/agents/jd-judge-a.md +1 -0
  7. package/assets/agents/jd-judge-b.md +1 -0
  8. package/assets/design-canvas/canvas.css +13 -1
  9. package/assets/design-canvas/canvas.js +11 -2
  10. package/assets/install-wizard/wizard.js +1 -0
  11. package/assets/migrations/agent-body-history.json +16 -1
  12. package/assets/orchestrator-delegation-reference.md +4 -4
  13. package/assets/orchestrator-delegation.md +1 -1
  14. package/assets/orchestrator-full-delegation-card.md +65 -0
  15. package/assets/orchestrator-full-delegation.md +34 -0
  16. package/assets/orchestrator-memory.md +3 -3
  17. package/assets/orchestrator-prompts.md +1 -1
  18. package/assets/orchestrator-skills.md +1 -1
  19. package/assets/orchestrator-verification.md +7 -5
  20. package/assets/orchestrator.md +3 -3
  21. package/bin/gentle-shell.mjs +164 -56
  22. package/docs/agent-status.md +61 -0
  23. package/docs/bundled-install.md +7 -5
  24. package/docs/delegated-verification.md +29 -7
  25. package/docs/gentle-agents-activity.md +14 -0
  26. package/docs/gentle-shell.md +54 -16
  27. package/docs/install-wizard.md +1 -1
  28. package/docs/permission-modes.md +9 -4
  29. package/docs/readme-reference.md +75 -30
  30. package/docs/render-cache-performance.md +11 -1
  31. package/docs/review-coordinator.md +33 -0
  32. package/docs/review-request-context.md +19 -0
  33. package/docs/review-windows-acl.md +18 -0
  34. package/docs/voice.md +6 -3
  35. package/docs/yolo-mode.md +5 -5
  36. package/extensions/ask-user-choice.ts +1 -0
  37. package/extensions/ask-user-question.ts +1 -0
  38. package/extensions/child-safety.ts +3 -0
  39. package/extensions/gentle-agent-status.ts +99 -0
  40. package/extensions/gentle-agents.ts +326 -34
  41. package/extensions/gentle-ai.ts +1496 -454
  42. package/extensions/gentle-shell.ts +293 -63
  43. package/extensions/gentle-todo.ts +18 -2
  44. package/extensions/gentle-tps.ts +48 -0
  45. package/extensions/quiet-tools.ts +38 -8
  46. package/extensions/skill-registry.ts +175 -18
  47. package/extensions/startup-banner.ts +30 -3
  48. package/lib/agent-profile-pin.ts +3 -3
  49. package/lib/agent-profiles.ts +160 -2
  50. package/lib/agent-status.ts +105 -0
  51. package/lib/agents-config.ts +46 -0
  52. package/lib/agents-history.ts +24 -5
  53. package/lib/agents-messaging.ts +47 -5
  54. package/lib/agents-runner.ts +183 -12
  55. package/lib/auto-permission-runtime.ts +1 -1
  56. package/lib/bounded-writer-admission.ts +13 -1
  57. package/lib/card-content-policy.ts +8 -6
  58. package/lib/command-palette.ts +133 -17
  59. package/lib/context-backstop.ts +14 -5
  60. package/lib/destructive-command-guard.ts +48 -4
  61. package/lib/execution-surface-guard.ts +20 -0
  62. package/lib/exploration-budget.ts +4 -2
  63. package/lib/gentle-ai-binary.ts +1 -1
  64. package/lib/gentle-design.ts +3 -0
  65. package/lib/gentle-shell-bundled.ts +6 -19
  66. package/lib/gentle-shell-launcher.ts +43 -8
  67. package/lib/herdr-activity.ts +14 -2
  68. package/lib/herdr-busy.ts +45 -0
  69. package/lib/image-attachments.ts +33 -0
  70. package/lib/image-disk-cache.ts +137 -0
  71. package/lib/inprocess-reviewer.ts +270 -140
  72. package/lib/jobs-view.ts +198 -11
  73. package/lib/model-routing-authority.ts +22 -4
  74. package/lib/native-choice-list.ts +20 -2
  75. package/lib/native-review-cli.ts +96 -19
  76. package/lib/orchestrator-mode-policy.ts +105 -0
  77. package/lib/questionnaire/questionnaire-view.ts +105 -12
  78. package/lib/rdd-mode-control.ts +32 -0
  79. package/lib/reply-language-anchor.ts +104 -0
  80. package/lib/review-blocker.ts +92 -0
  81. package/lib/review-candidate-symlink-scan.ts +136 -0
  82. package/lib/review-candidate-view-owner.ts +81 -44
  83. package/lib/review-continuation-registry.ts +99 -0
  84. package/lib/review-coordinator.ts +163 -0
  85. package/lib/review-failure-facts.ts +49 -0
  86. package/lib/review-host-relay.ts +46 -10
  87. package/lib/review-integration-v2.ts +7 -1
  88. package/lib/review-relay-phase-timing.ts +45 -0
  89. package/lib/review-start-context.ts +17 -0
  90. package/lib/session-profile-freeze.ts +4 -2
  91. package/lib/shell-bar.ts +140 -58
  92. package/lib/shell-changes.ts +2 -0
  93. package/lib/shell-panel.ts +17 -3
  94. package/lib/shell-sidebar-layout.ts +112 -40
  95. package/lib/shell-sidebar.ts +7 -0
  96. package/lib/shell-todo.ts +10 -3
  97. package/lib/verifier-admission.ts +1 -1
  98. package/lib/visual-customization-policy.ts +36 -16
  99. package/lib/visual-customize-view.ts +216 -21
  100. package/lib/visual-layout-preview.ts +9 -5
  101. package/lib/visual-profiles.ts +2 -2
  102. package/lib/windows-session-transport.ts +53 -2
  103. package/lib/yolo-session-policy.ts +40 -15
  104. package/package.json +2 -1
  105. package/runtime/gentle-ai-binary.mjs +1 -1
  106. package/runtime/gentle-shell-bundled.mjs +6 -19
  107. package/runtime/gentle-shell-launcher.mjs +42 -7
  108. package/runtime/native-review-cli.mjs +93 -16
  109. package/runtime/review-integration-v2.mjs +7 -1
  110. package/scripts/build-full-delegation-card.mjs +175 -0
  111. package/scripts/bundled-install.mjs +38 -8
  112. package/scripts/download-progress.mjs +68 -0
  113. package/scripts/gentle-ai-installer.mjs +41 -18
  114. package/scripts/gentle-ai-proxy.mjs +294 -0
  115. package/scripts/install-gentle-ai.mjs +14 -1
  116. package/scripts/installer-preflight.mjs +5 -5
  117. package/scripts/installer-runner.mjs +27 -12
  118. package/scripts/installer-server.mjs +8 -7
  119. package/scripts/render-cache-host.mjs +72 -0
  120. package/scripts/render-cache-performance-worker.mjs +5 -4
  121. package/scripts/render-cache-performance.mjs +6 -1
  122. package/scripts/run-test-suite.mjs +40 -28
  123. package/scripts/verify-package-files.mjs +12 -2
  124. package/scripts/voice-worker.cjs +32 -6
  125. package/skills/design/SKILL.md +11 -8
  126. package/skills/gentle-ai/SKILL.md +2 -2
  127. package/skills/gentle-ui-design/SKILL.md +46 -0
  128. package/skills/gentle-ui-design/references/adaptive-interfaces.md +46 -0
  129. package/skills/gentle-ui-design/references/browse-and-compare.md +62 -0
  130. package/skills/gentle-ui-design/references/composition-and-feedback.md +56 -0
  131. package/skills/gentle-ui-design/references/task-and-content.md +60 -0
  132. package/skills/skill-registry/SKILL.md +4 -2
  133. package/skills/work-unit-commits/SKILL.md +6 -7
  134. package/tests/agent-home.test.ts +28 -9
  135. package/tests/agent-profiles-workflow.test.ts +163 -0
  136. package/tests/agent-risk-escalation.test.ts +1 -1
  137. package/tests/agent-status.test.ts +143 -0
  138. package/tests/agents-config.test.ts +96 -0
  139. package/tests/agents-history.test.ts +31 -0
  140. package/tests/agents-jobs-frames.test.ts +93 -0
  141. package/tests/agents-prompt-lifecycle-runtime.test.ts +376 -0
  142. package/tests/agents-runner-drain.test.ts +193 -0
  143. package/tests/agents-runner.test.ts +178 -2
  144. package/tests/append-system-prompt-route.test.ts +4 -1
  145. package/tests/ask-user-choice.test.ts +4 -3
  146. package/tests/ask-user-question.test.ts +97 -0
  147. package/tests/auto-permission-runtime.test.ts +1 -1
  148. package/tests/autonomous-guard.test.ts +346 -10
  149. package/tests/bounded-stop-contract.test.ts +43 -3
  150. package/tests/bridge-cost.test.ts +19 -4
  151. package/tests/bundled-install.test.ts +30 -5
  152. package/tests/card-content-policy.test.ts +3 -3
  153. package/tests/chained-pr-skill.test.ts +8 -6
  154. package/tests/child-safety.test.ts +11 -0
  155. package/tests/codegraph-tools.test.ts +11 -5
  156. package/tests/command-palette.test.ts +284 -1
  157. package/tests/delegate-for-reason-contract.test.ts +3 -3
  158. package/tests/design-canvas-assets.test.ts +185 -2
  159. package/tests/destructive-command-guard.test.ts +52 -0
  160. package/tests/download-progress.test.ts +71 -0
  161. package/tests/execution-surface-guard.test.ts +55 -0
  162. package/tests/fixtures/primary-session-prompt/gentleman.golden.md +9 -5
  163. package/tests/fixtures/proxy-tls/proxy.crt +19 -0
  164. package/tests/fixtures/proxy-tls/proxy.key +28 -0
  165. package/tests/fixtures/session-profile-v1/gentle-ai-reviewer.ts +89 -0
  166. package/tests/fixtures/session-profile-v1/replay.ts +53 -6
  167. package/tests/full-delegation-closure.test.ts +131 -0
  168. package/tests/full-delegation-notices.test.ts +76 -0
  169. package/tests/generic-agent-tools.test.ts +3 -3
  170. package/tests/gentle-agent-status.test.ts +74 -0
  171. package/tests/gentle-agents-child-jobs.test.ts +237 -0
  172. package/tests/gentle-agents.test.ts +1070 -12
  173. package/tests/gentle-ai-binary.test.ts +3 -1
  174. package/tests/gentle-ai-elapsed-store.test.ts +19 -0
  175. package/tests/gentle-ai-exploration-budget.test.ts +18 -2
  176. package/tests/gentle-ai-installer.test.ts +134 -51
  177. package/tests/gentle-ai-proxy.test.ts +434 -0
  178. package/tests/gentle-ai.test.ts +113 -38
  179. package/tests/gentle-design.test.ts +21 -0
  180. package/tests/gentle-herdr-activity.test.ts +9 -6
  181. package/tests/gentle-shell-bin.test.ts +123 -0
  182. package/tests/gentle-shell-bundled.test.ts +207 -31
  183. package/tests/gentle-shell-launcher.test.ts +77 -10
  184. package/tests/gentle-shell.test.ts +899 -59
  185. package/tests/gentle-todo.test.ts +19 -2
  186. package/tests/gentle-tps.test.ts +123 -0
  187. package/tests/gentle-ui-design-skill.test.ts +59 -0
  188. package/tests/herdr-busy.test.ts +59 -0
  189. package/tests/herdr-task-summary-policy.test.ts +8 -4
  190. package/tests/image-disk-cache.test.ts +163 -0
  191. package/tests/independent-recovery-delivery.test.ts +83 -0
  192. package/tests/inprocess-reviewer.test.ts +176 -4
  193. package/tests/installer-posix-bootstrap.test.ts +1 -1
  194. package/tests/installer-preflight.test.ts +5 -4
  195. package/tests/installer-runner.test.ts +79 -44
  196. package/tests/installer-server.test.ts +14 -11
  197. package/tests/jobs-view.test.ts +260 -6
  198. package/tests/modal-mouse-boundaries.test.ts +136 -0
  199. package/tests/model-routing-authority.test.ts +178 -2
  200. package/tests/native-choice-list.test.ts +77 -2
  201. package/tests/native-review-capability-contract.test.ts +7 -1
  202. package/tests/native-review-cli.test.ts +269 -1
  203. package/tests/no-self-pause-contract.test.ts +4 -1
  204. package/tests/odd-routing-canonical-ratchet.test.ts +3 -3
  205. package/tests/orchestrator-budget.test.ts +7 -2
  206. package/tests/orchestrator-delegation-mode.test.ts +153 -0
  207. package/tests/orchestrator-mode-policy.test.ts +175 -0
  208. package/tests/orchestrator-prompt-budget.test.ts +3 -1
  209. package/tests/orchestrator-rdd-ownership.test.ts +2 -2
  210. package/tests/package-manifest.test.ts +11 -9
  211. package/tests/permission-allowlist.test.ts +202 -0
  212. package/tests/pi-update-launcher.test.ts +8 -0
  213. package/tests/pnpm-workspace-config.test.ts +58 -0
  214. package/tests/primary-session-prompt.test.ts +13 -0
  215. package/tests/profile-pin.test.ts +29 -2
  216. package/tests/profile-tier-footer.test.ts +5 -0
  217. package/tests/profiles-panel-delegation-mode.test.ts +422 -0
  218. package/tests/questionnaire-view.test.ts +115 -0
  219. package/tests/quiet-bash-runtime.test.ts +1 -1
  220. package/tests/quiet-tool-rendering.test.ts +48 -0
  221. package/tests/rdd-aware-verification-contract.test.ts +16 -11
  222. package/tests/rdd-customize.test.ts +287 -0
  223. package/tests/rdd-mode-cache.test.ts +450 -0
  224. package/tests/rdd-mode-control.test.ts +407 -0
  225. package/tests/rdd-mode-scope-regression.test.ts +137 -0
  226. package/tests/rdd-off-independent-regression.test.ts +69 -0
  227. package/tests/rdd-status-line.test.ts +18 -0
  228. package/tests/render-cache-performance.test.ts +171 -2
  229. package/tests/reply-language-anchor.test.ts +173 -0
  230. package/tests/review-agent-end-preflight.test.ts +1 -1
  231. package/tests/review-blocker.test.ts +193 -0
  232. package/tests/review-candidate-owner-retry.test.ts +1 -1
  233. package/tests/review-candidate-symlink-scan.test.ts +157 -0
  234. package/tests/review-candidate-view.test.ts +1 -1
  235. package/tests/review-candidate-windows-boundary.test.ts +131 -0
  236. package/tests/review-candidate-windows-probe.test.ts +63 -0
  237. package/tests/review-committed-restart-ack.test.ts +129 -0
  238. package/tests/review-continuation-registry.test.ts +76 -0
  239. package/tests/review-controller-native-routing.test.ts +261 -5
  240. package/tests/review-controller-workspace-root.test.ts +230 -3
  241. package/tests/review-controller.test.ts +96 -11
  242. package/tests/review-coordinator-runtime.test.ts +117 -0
  243. package/tests/review-coordinator.test.ts +195 -0
  244. package/tests/review-failure-facts.test.ts +87 -0
  245. package/tests/review-host-relay-routing.test.ts +258 -4
  246. package/tests/review-host-relay.test.ts +39 -0
  247. package/tests/review-integration-v2.test.ts +46 -3
  248. package/tests/review-json-arguments.test.ts +65 -10
  249. package/tests/review-last-event-closure.test.ts +68 -0
  250. package/tests/review-loadout-rdd-off-sdk.test.ts +65 -31
  251. package/tests/review-owner-identity.test.ts +60 -24
  252. package/tests/review-relay-phase-timing.test.ts +128 -0
  253. package/tests/review-relay-transport-agent.test.ts +12 -2
  254. package/tests/review-reviewer-evidence.test.ts +183 -0
  255. package/tests/review-risk-assessment.test.ts +74 -3
  256. package/tests/review-session-standing-permission-controller.test.ts +21 -1
  257. package/tests/review-start-context.test.ts +19 -0
  258. package/tests/review-tool-prose-budget.test.ts +121 -0
  259. package/tests/run-test-suite.test.ts +122 -1
  260. package/tests/runtime-harness.mjs +4 -1
  261. package/tests/sensitive-path-tools.test.ts +181 -5
  262. package/tests/session-profile-append-controller-pi.test.ts +60 -31
  263. package/tests/session-profile-binding.test.ts +19 -1
  264. package/tests/session-profile-disk-reader-pi.test.ts +58 -16
  265. package/tests/session-profile-v1-compat.test.ts +35 -1
  266. package/tests/shell-bar.test.ts +186 -42
  267. package/tests/shell-panel.test.ts +50 -22
  268. package/tests/shell-sidebar-fullscreen.test.ts +5 -5
  269. package/tests/shell-sidebar-layout.test.ts +294 -23
  270. package/tests/shell-sidebar-scroll-benchmark.test.ts +1 -1
  271. package/tests/shell-surface-transparent.test.ts +89 -0
  272. package/tests/shell-todo.test.ts +12 -0
  273. package/tests/skill-registry.test.ts +838 -5
  274. package/tests/startup-banner.test.ts +152 -1
  275. package/tests/startup-home-repo.test.ts +2 -0
  276. package/tests/support/review-coordinator-runtime.ts +69 -0
  277. package/tests/task-size-routing-contract.test.ts +5 -3
  278. package/tests/verifier-admission.test.ts +49 -0
  279. package/tests/verify-first-launch-contract.test.ts +78 -3
  280. package/tests/visual-customization-policy.test.ts +39 -6
  281. package/tests/visual-customize-view.test.ts +573 -9
  282. package/tests/visual-layout-preview.test.ts +15 -1
  283. package/tests/visual-profiles.test.ts +11 -0
  284. package/tests/voice-worker.test.ts +73 -2
  285. package/tests/windows-session-transport.test.ts +126 -0
  286. package/tests/work-continuity-contract.test.ts +28 -0
  287. package/tests/writer-feature-document-admission.test.ts +92 -0
  288. package/tests/yolo-customize.test.ts +27 -4
  289. package/tests/yolo-mode.test.ts +23 -18
  290. package/tests/yolo-session-policy.test.ts +270 -1
@@ -34,7 +34,7 @@ interface Harness {
34
34
  advance(ms: number): void;
35
35
  }
36
36
 
37
- function harness(options: { resolvePi?: RunnerDeps["resolvePi"]; failStart?: boolean; process?: RunnerDeps["process"]; pid?: number; maxConcurrency?: number; stallTimeoutMs?: number; toolStallTimeoutMs?: number; cleanupTimeoutMs?: number; answer?: Record<string, unknown>; exitOnKill?: boolean; exitOnStdinEnd?: boolean; state?: Record<string, unknown>; stateSuccess?: boolean; onNotification?: RunnerHooks["onNotification"]; onSuccessfulMutation?: RunnerHooks["onSuccessfulMutation"]; onFinish?: RunnerHooks["onFinish"]; onFallback?: RunnerHooks["onFallback"]; reject?: (command: Record<string, unknown>) => boolean; hold?: (command: Record<string, unknown>) => boolean } = {}): Harness {
37
+ function harness(options: { resolvePi?: RunnerDeps["resolvePi"]; failStart?: boolean; process?: RunnerDeps["process"]; pid?: number; maxConcurrency?: number; stallTimeoutMs?: number; toolStallTimeoutMs?: number; cleanupTimeoutMs?: number; drainTimeoutMs?: number; answer?: Record<string, unknown>; exitOnKill?: boolean; exitOnStdinEnd?: boolean; state?: Record<string, unknown>; stateSuccess?: boolean; onNotification?: RunnerHooks["onNotification"]; onSuccessfulMutation?: RunnerHooks["onSuccessfulMutation"]; onFinish?: RunnerHooks["onFinish"]; onFallback?: RunnerHooks["onFallback"]; reject?: (command: Record<string, unknown>) => boolean; hold?: (command: Record<string, unknown>) => boolean } = {}): Harness {
38
38
  const children: FakeChild[] = [];
39
39
  const timers: Harness["timers"] = [];
40
40
  const asks: Harness["asks"] = [];
@@ -75,7 +75,7 @@ function harness(options: { resolvePi?: RunnerDeps["resolvePi"]; failStart?: boo
75
75
  pi: { command: "pi", args: [] },
76
76
  };
77
77
  const store = new TaskStore();
78
- const runner = new AgentRunner(store, { maxConcurrency: options.maxConcurrency ?? 2, stallTimeoutMs: options.stallTimeoutMs ?? 10_000, toolStallTimeoutMs: options.toolStallTimeoutMs, cleanupTimeoutMs: options.cleanupTimeoutMs }, deps, {
78
+ const runner = new AgentRunner(store, { maxConcurrency: options.maxConcurrency ?? 2, stallTimeoutMs: options.stallTimeoutMs ?? 10_000, toolStallTimeoutMs: options.toolStallTimeoutMs, cleanupTimeoutMs: options.cleanupTimeoutMs, drainTimeoutMs: options.drainTimeoutMs }, deps, {
79
79
  askUser: async (taskId, ask) => {
80
80
  asks.push({ taskId, method: ask.method });
81
81
  return options.answer ?? { value: "yes" };
@@ -179,6 +179,26 @@ test("background capability admission refreshes project policy when queued work
179
179
  assert.equal(readFileSync(file, "utf8"), raw);
180
180
  });
181
181
 
182
+ for (const { tools, forwarded } of [
183
+ { tools: ["read", "bash_background"], forwarded: true },
184
+ { tools: ["read", "bash_background", "job_list", "job_stop"], forwarded: true },
185
+ { tools: ["read", "grep"], forwarded: false },
186
+ { tools: [], forwarded: false },
187
+ ]) {
188
+ test(`background capability forwards the child job marker only for a declared bash_background (${tools.join(",") || "default tools"})`, async (t) => {
189
+ const root = fs.mkdtempSync(join(tmpdir(), "child-jobs-"));
190
+ t.after(() => fs.rmSync(root, { recursive: true, force: true }));
191
+ const h = harness();
192
+ const env = { GENTLE_PI_CONFIG_HOME: join(root, "config"), GENTLE_PI_BACKGROUND_SUBAGENTS: "on" };
193
+ const task = h.runner.run(request({ cwd: root, env, agent: { ...explorer, tools } }));
194
+ await tick();
195
+ assert.equal(h.store.get(task.id)?.status, TASK_STATUS.RUNNING);
196
+ assert.equal(h.spawnOptions[0].env.GENTLE_PI_AGENTS_CHILD_JOBS, forwarded ? "1" : undefined);
197
+ h.runner.cancel(task.id);
198
+ await tick();
199
+ });
200
+ }
201
+
182
202
  const FOUR_MIN_MS = 4 * 60_000;
183
203
 
184
204
  function argumentUpdate(type: string, fields: Record<string, unknown> = {}): Record<string, unknown> {
@@ -975,6 +995,88 @@ test("runner resolves the pi command at each spawn after the entry disappears",
975
995
  assert.deepEqual(h.spawnOptions[1].args, childArguments(request()));
976
996
  });
977
997
 
998
+ test("piCommand fallback on win32 re-resolves cli.js via pi.cmd from PATH without shell (#2887)", () => {
999
+ const procWin = {
1000
+ execPath: "C:\\Program Files\\nodejs\\node.exe",
1001
+ argv: ["C:\\Program Files\\nodejs\\node.exe", "C:\\pnpm\\global\\node_modules\\@earendil-works\\pi-coding-agent\\dist\\cli.js"],
1002
+ env: { Path: "C:\\pnpm;C:\\Windows\\System32" },
1003
+ platform: "win32" as const,
1004
+ };
1005
+ const newCli = "C:\\pnpm\\global\\5\\node_modules\\@earendil-works\\pi-coding-agent\\dist\\cli.js";
1006
+ const cmdContent = `@ECHO off\r\nnode "${newCli}" %*\r\n`;
1007
+ const exists = (p: string) => p === "C:\\pnpm\\pi.cmd" || p === newCli;
1008
+ const readFile = (p: string) => (p === "C:\\pnpm\\pi.cmd" ? cmdContent : "");
1009
+
1010
+ // While original cli.js still exists, reuses it
1011
+ assert.deepEqual(piCommand(procWin, (p) => p === procWin.argv[1]), { command: procWin.execPath, args: [procWin.argv[1]] });
1012
+ // When original cli.js disappears after upgrade, resolves the new cli.js from pi.cmd on PATH
1013
+ assert.deepEqual(piCommand(procWin, exists, readFile), { command: procWin.execPath, args: [newCli] });
1014
+ });
1015
+
1016
+ test("piCommand resolves npm and pnpm cmd-shims with relative paths on win32 (#2887)", () => {
1017
+ const procWin = {
1018
+ execPath: "C:\\Program Files\\nodejs\\node.exe",
1019
+ argv: ["C:\\Program Files\\nodejs\\node.exe", "C:\\missing\\cli.js"],
1020
+ env: { PATH: "C:\\AppData\\npm" },
1021
+ platform: "win32" as const,
1022
+ };
1023
+ // npm cmd-shim style with %dp0%
1024
+ const npmShim = `@ECHO off\r\n"%_prog%" "%dp0%\\node_modules\\@earendil-works\\pi-coding-agent\\dist\\cli.js" %*\r\n`;
1025
+ const targetJs = "C:\\AppData\\npm\\node_modules\\@earendil-works\\pi-coding-agent\\dist\\cli.js";
1026
+ const exists = (p: string) => p === "C:\\AppData\\npm\\pi.cmd" || p === targetJs;
1027
+ const readFile = (p: string) => (p === "C:\\AppData\\npm\\pi.cmd" ? npmShim : "");
1028
+
1029
+ assert.deepEqual(piCommand(procWin, exists, readFile), { command: procWin.execPath, args: [targetJs] });
1030
+ });
1031
+
1032
+ test("piCommand honors GENTLE_PI_AGENTS_PI pointing to a .cmd shim by resolving its JS target (#2887)", () => {
1033
+ const procWin = {
1034
+ execPath: "C:\\Program Files\\nodejs\\node.exe",
1035
+ argv: ["C:\\Program Files\\nodejs\\node.exe", "C:\\missing\\cli.js"],
1036
+ env: { GENTLE_PI_AGENTS_PI: "C:\\custom\\pi.cmd --model gpt-5" },
1037
+ platform: "win32" as const,
1038
+ };
1039
+ const customShim = `@ECHO off\r\nnode "%~dp0pi-launcher.js" %*\r\n`;
1040
+ const targetLauncher = "C:\\custom\\pi-launcher.js";
1041
+ const exists = (p: string) => p === "C:\\custom\\pi.cmd" || p === targetLauncher;
1042
+ const readFile = (p: string) => (p === "C:\\custom\\pi.cmd" ? customShim : "");
1043
+
1044
+ assert.deepEqual(piCommand(procWin, exists, readFile), {
1045
+ command: procWin.execPath,
1046
+ args: [targetLauncher, "--model", "gpt-5"],
1047
+ });
1048
+ });
1049
+
1050
+ test("runner spawns fallback pi through Node on win32 after upgrade without shell (#2887)", async () => {
1051
+ let existsOld = true;
1052
+ const newCli = "C:\\pnpm\\dist\\cli.js";
1053
+ const procWin = {
1054
+ execPath: "C:\\Program Files\\nodejs\\node.exe",
1055
+ argv: ["C:\\Program Files\\nodejs\\node.exe", "C:\\pi\\dist\\cli.js"],
1056
+ env: { Path: "C:\\pnpm" },
1057
+ platform: "win32" as const,
1058
+ };
1059
+ const cmdContent = `@ECHO off\r\nnode "%~dp0dist\\cli.js" %*\r\n`;
1060
+ const exists = (p: string) => (existsOld && p === procWin.argv[1]) || p === "C:\\pnpm\\pi.cmd" || p === newCli;
1061
+ const readFile = (p: string) => (p === "C:\\pnpm\\pi.cmd" ? cmdContent : "");
1062
+
1063
+ const h = harness({ resolvePi: () => piCommand(procWin, exists, readFile) });
1064
+ // First run before upgrade
1065
+ h.runner.run(request({ agent: { ...explorer, instructions: "audit & verify | status %VAR%" } }));
1066
+ await tick();
1067
+ assert.equal(h.spawnOptions[0].command, procWin.execPath);
1068
+ assert.equal(h.spawnOptions[0].args[0], procWin.argv[1]);
1069
+
1070
+ // Upgrade: old cli.js disappears, piCommand re-resolves via pi.cmd
1071
+ existsOld = false;
1072
+ h.runner.run(request({ agent: { ...explorer, instructions: "audit & verify | status %VAR%" } }));
1073
+ await tick();
1074
+ assert.equal(h.spawnOptions[1].command, procWin.execPath);
1075
+ assert.equal(h.spawnOptions[1].args[0], newCli);
1076
+ // Arguments with &, |, % and spaces are preserved verbatim in argv, never joined by a shell
1077
+ assert.ok(h.spawnOptions[1].args.includes("audit & verify | status %VAR%"));
1078
+ });
1079
+
978
1080
  test("JsonLines splits on LF only, tolerates CRLF, and skips lines that are not JSON", () => {
979
1081
  const seen: unknown[] = [];
980
1082
  const lines = new JsonLines((value) => seen.push(value));
@@ -1145,6 +1247,80 @@ test("AgentRunner escalates to SIGTERM and SIGKILL if orderly cleanup exceeds cl
1145
1247
  assert.deepEqual(children[0].killed, ["SIGTERM", "SIGKILL"]);
1146
1248
  });
1147
1249
 
1250
+ test("a child that reports a running background job drains one bounded window before the orderly shutdown", async () => {
1251
+ const { store, runner, children, timers, advance } = harness({ exitOnKill: false, drainTimeoutMs: 2_000, cleanupTimeoutMs: 3_000 });
1252
+ const task = runner.run(request({ agent: { ...explorer, tools: ["read", "bash_background"] }, env: { GENTLE_PI_BACKGROUND_SUBAGENTS: "on" } }));
1253
+ await tick();
1254
+ const child = children[0];
1255
+ child.message({ id: "j1", kind: "job", message: JSON.stringify({ running: 1, pending: true }) });
1256
+ assert.deepEqual(child.sent.at(-1), { id: "j1", kind: "ack", accepted: true });
1257
+ child.emit({ type: "agent_end", messages: [{ role: "assistant", content: [{ type: "text", text: "waiting on CI" }] }] });
1258
+ child.emit({ type: "agent_settled" });
1259
+ await tick();
1260
+
1261
+ // The drain holds the orderly shutdown open; nothing has been signalled yet.
1262
+ assert.equal(store.get(task.id)?.status, TASK_STATUS.RUNNING);
1263
+ assert.equal(store.get(task.id)?.lastStep, "draining background jobs");
1264
+ assert.equal(child.child.stdin.writableEnded, false, "stdin stays open while the job drains");
1265
+ assert.deepEqual(child.killed, []);
1266
+ const drainTimer = timers.find((timer) => !timer.cancelled && timer.ms === 2_000);
1267
+ assert.ok(drainTimer, "one bounded drain window is scheduled");
1268
+
1269
+ // The bounded window expires: the ordinary orderly shutdown begins and escalates.
1270
+ advance(2_000);
1271
+ await tick();
1272
+ assert.ok(drainTimer!.cancelled);
1273
+ assert.equal(child.child.stdin.writableEnded, true, "the drain is bounded and ends by settling");
1274
+ const cleanupTimer = timers.find((timer) => !timer.cancelled && timer.ms === 3_000);
1275
+ assert.ok(cleanupTimer, "the ordinary cleanup window follows the drain");
1276
+ cleanupTimer!.fn();
1277
+ await tick();
1278
+ assert.deepEqual(child.killed, ["SIGTERM"]);
1279
+ const killTimer = timers.find((timer) => !timer.cancelled && timer.ms === 250);
1280
+ assert.ok(killTimer, "SIGKILL follows the drain like today");
1281
+ killTimer!.fn();
1282
+ await tick();
1283
+ assert.deepEqual(child.killed, ["SIGTERM", "SIGKILL"]);
1284
+ });
1285
+
1286
+ test("a child job that finishes inside the drain ends it early and only one extension is allowed", async () => {
1287
+ const { store, runner, children, timers } = harness({ exitOnKill: false, drainTimeoutMs: 2_000, cleanupTimeoutMs: 3_000 });
1288
+ const task = runner.run(request({ agent: { ...explorer, tools: ["read", "bash_background"] }, env: { GENTLE_PI_BACKGROUND_SUBAGENTS: "on" } }));
1289
+ await tick();
1290
+ const child = children[0];
1291
+ child.message({ id: "j1", kind: "job", message: JSON.stringify({ running: 1, pending: true }) });
1292
+ child.emit({ type: "agent_end", messages: [{ role: "assistant", content: [{ type: "text", text: "waiting" }] }] });
1293
+ child.emit({ type: "agent_settled" });
1294
+ await tick();
1295
+ const drainTimer = timers.find((timer) => !timer.cancelled && timer.ms === 2_000)!;
1296
+ assert.ok(drainTimer);
1297
+
1298
+ child.message({ id: "j2", kind: "job", message: JSON.stringify({ running: 0, pending: false }) });
1299
+ await tick();
1300
+ assert.ok(drainTimer.cancelled, "the drain ends early when the child reports no running jobs");
1301
+ assert.equal(child.child.stdin.writableEnded, true);
1302
+
1303
+ // A later report cannot open a second extension.
1304
+ const before = timers.filter((timer) => !timer.cancelled && timer.ms === 2_000).length;
1305
+ child.message({ id: "j3", kind: "job", message: JSON.stringify({ running: 1, pending: true }) });
1306
+ await tick();
1307
+ assert.equal(timers.filter((timer) => !timer.cancelled && timer.ms === 2_000).length, before, "no unbounded re-drain after the first extension");
1308
+ });
1309
+
1310
+ test("a job frame that is not a valid child state is refused and does not open a drain", async () => {
1311
+ const { runner, children, timers } = harness({ exitOnKill: false, drainTimeoutMs: 2_000 });
1312
+ runner.run(request({ agent: { ...explorer, tools: ["read", "bash_background"] }, env: { GENTLE_PI_BACKGROUND_SUBAGENTS: "on" } }));
1313
+ await tick();
1314
+ const child = children[0];
1315
+ child.message({ id: "j1", kind: "job", message: "not json" });
1316
+ assert.deepEqual(child.sent.at(-1), { id: "j1", kind: "ack", accepted: false, error: "invalid child job state" });
1317
+ child.emit({ type: "agent_end", messages: [{ role: "assistant", content: [{ type: "text", text: "done" }] }] });
1318
+ child.emit({ type: "agent_settled" });
1319
+ await tick();
1320
+ assert.equal(child.child.stdin.writableEnded, true, "an unparseable job report does not delay settlement");
1321
+ assert.equal(timers.filter((timer) => !timer.cancelled && timer.ms === 2_000).length, 0);
1322
+ });
1323
+
1148
1324
  test("orderly cleanup escalation retains the full exit confirmation deadline after SIGKILL (#1740)", async () => {
1149
1325
  let groupAlive = true;
1150
1326
  const { store, runner, children, timers, advance } = harness({
@@ -124,7 +124,10 @@ test("both extensions land their block in appendSystemPrompt on one shared optio
124
124
  for (const clause of [
125
125
  "necessary in-scope implementation, documentation and verification steps",
126
126
  "Never end a turn merely announcing an immediately executable authorized next step; execute it instead",
127
- "required explicit consent, a denied action, unavailable required proof, or the human's explicit stop",
127
+ "required explicit consent, a denied action, or the human's explicit stop",
128
+ "Unavailable required proof blocks completion and delivery; it does not alone prohibit specifically authorized in-scope implementation where actual native authority and other limits permit it.",
129
+ "After a setup prerequisite is repaired, the human may explicitly request one new bounded verification attempt.",
130
+ "Never bypass consent, a denial, explicit one-run or no-retry limits, terminal native outcomes, or exhausted native budgets.",
128
131
  "Do not infer permission for publishing, destructive actions, unrelated scope or native consent",
129
132
  "Report a concrete blocker and the exact decision needed",
130
133
  "launch the bounded action and end the turn when no independent in-scope work remains",
@@ -234,7 +234,7 @@ test("ask_user_choice hover preserves the keyboard-selected opaque value", async
234
234
  ui: { custom: async (factory: ChoiceCustomFactory) => {
235
235
  let completed: unknown;
236
236
  const component = factory({ requestRender() {} }, {
237
- fg: (_color, text) => `\u001b[38;5;39m${text}\u001b[39m`,
237
+ fg: (color, text) => color === "warning" ? `\u001b[33m${text}\u001b[39m` : `\u001b[38;5;39m${text}\u001b[39m`,
238
238
  bg: (_color, text) => `\u001b[48;5;236m${text}\u001b[49m`, bold: (text) => text,
239
239
  }, {}, (value) => { completionCalls++; completed = value; });
240
240
  const lines = component.render(80);
@@ -249,9 +249,10 @@ test("ask_user_choice hover preserves the keyboard-selected opaque value", async
249
249
  assert.equal(component.handleMouse?.(hover)?.render, true);
250
250
  assert.equal(completed, undefined, "hover never submits");
251
251
  const hovered = component.render(80);
252
- assert.ok(hovered[second]?.includes("\u001b[48;5;236m"), "only the second option is hovered");
252
+ assert.ok(hovered[second]?.includes("\u001b[33m"), "the second option uses the shared warning foreground");
253
+ assert.ok(!hovered[second]?.includes("\u001b[48;5;236m"), "hover does not use toolPendingBg");
253
254
  assert.ok(
254
- hovered[first]?.includes("\u001b[38;5;39m") && !hovered[first]?.includes("\u001b[48;5;236m"),
255
+ hovered[first]?.includes("\u001b[38;5;39m") && !hovered[first]?.includes("\u001b[33m"),
255
256
  "hover does not change keyboard selection",
256
257
  );
257
258
  component.handleInput("\r");
@@ -1,5 +1,7 @@
1
1
  import assert from "node:assert/strict";
2
2
  import test from "node:test";
3
+ import { Container, stripTerminalSequences, Text, TuiAltScreen, visibleWidth, type Component, type Terminal } from "@earendil-works/pi-tui";
4
+ import { createChatViewport } from "../node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/chat-viewport.js";
3
5
  import askUserQuestion, { askMultiSelect } from "../extensions/ask-user-question.ts";
4
6
  import { createGentleAiExtension } from "../extensions/gentle-ai.ts";
5
7
 
@@ -464,6 +466,101 @@ test("ask_user_question mounts through ctx.ui.custom without an overlay option",
464
466
  assert.equal(customArgCount, 1, "a dock swap passes the factory only; no overlay options");
465
467
  });
466
468
 
469
+ for (const multiSelect of [false, true]) {
470
+ test(`ask_user_question dock clears hover on its border and preserves native ${multiSelect ? "multi" : "single"}-select`, async () => {
471
+ let input: ((data: string) => void) | undefined;
472
+ const terminal: Terminal = {
473
+ start(onInput) { input = onInput; }, stop() {}, async drainInput() {}, write() {},
474
+ get columns() { return 100; }, get rows() { return 30; }, get kittyProtocolActive() { return false; },
475
+ moveBy() {}, hideCursor() {}, showCursor() {}, clearLine() {}, clearFromCursor() {}, clearScreen() {},
476
+ setTitle() {}, setProgress() {}, setProgramStatus() {},
477
+ };
478
+ const tui = new TuiAltScreen(terminal, false, undefined, { mouse: true });
479
+ const editor = new Container();
480
+ const viewport = createChatViewport({
481
+ document: new Text("Visible transcript", 0, 0),
482
+ pendingMessages: new Container(), status: new Container(), editor,
483
+ footer: new Text("Footer", 0, 0), scrollbar: "hidden",
484
+ });
485
+ tui.setLayoutRoot(viewport.root);
486
+ const hoverTheme: Theme = {
487
+ fg: (role, text) => role === "warning" ? `\x1b[33m${text}\x1b[39m` : text,
488
+ bold: (text) => text,
489
+ };
490
+ const label = "Beta: envelope/Ω";
491
+ const questions = [{
492
+ question: "Pick?", header: "Pick", options: [option("Alpha"), option(label)],
493
+ ...(multiSelect ? { multiSelect: true } : {}),
494
+ }];
495
+ const { tool, emitted } = registerQuestionTool();
496
+ const completions: unknown[] = [];
497
+ const pending = run(tool, { questions }, {
498
+ mode: "tui",
499
+ ui: { custom: (factory: CustomFactory) => new Promise((resolve) => {
500
+ const component = factory(tui, hoverTheme, {}, (value) => {
501
+ completions.push(value);
502
+ resolve(value);
503
+ }) as Component;
504
+ editor.addChild(component);
505
+ tui.setFocus(component);
506
+ }) },
507
+ });
508
+ tui.start();
509
+ tui.renderNow(true);
510
+ try {
511
+ assert.ok(input, "the fullscreen terminal receives native SGR input");
512
+ let screen = tui.getScreenLines();
513
+ const targetRow = screen.findIndex((line) => stripTerminalSequences(line).includes(label));
514
+ const tabsRow = screen.findIndex((line) => stripTerminalSequences(line).includes("[1/1]"));
515
+ const borderRow = tabsRow - 1;
516
+ assert.ok(targetRow >= 0 && borderRow >= 0, "both the option and its preceding dock border are rendered");
517
+ assert.match(stripTerminalSequences(screen[borderRow]!).trim(), /^─+$/);
518
+ const targetLine = stripTerminalSequences(screen[targetRow]!);
519
+ const targetX = visibleWidth(targetLine.slice(0, targetLine.indexOf(label))) + 1;
520
+ const expectedInitial = multiSelect ? /❯ \[ \] Alpha/ : /❯ Alpha/;
521
+ assert.match(screen.map(stripTerminalSequences).join("\n"), expectedInitial);
522
+
523
+ input(`\x1b[<35;${targetX};${targetRow + 1}M`);
524
+ tui.renderNow();
525
+ screen = tui.getScreenLines();
526
+ assert.ok(screen[targetRow]!.includes(`\x1b[33m${label}\x1b[39m`), "the option uses the warning role");
527
+ assert.match(screen.map(stripTerminalSequences).join("\n"), expectedInitial, "hover leaves keyboard selection unchanged");
528
+ if (multiSelect) assert.match(stripTerminalSequences(screen[targetRow]!), /\[ \] Beta/);
529
+ assert.deepEqual(completions, [], "hover does not answer or toggle");
530
+
531
+ input(`\x1b[<35;1;${borderRow + 1}M`);
532
+ tui.renderNow();
533
+ screen = tui.getScreenLines();
534
+ assert.ok(!screen[targetRow]!.includes("\x1b[33m"), "moving onto the non-view dock border clears hover");
535
+ assert.match(screen.map(stripTerminalSequences).join("\n"), expectedInitial);
536
+ if (multiSelect) assert.match(stripTerminalSequences(screen[targetRow]!), /\[ \] Beta/);
537
+ assert.deepEqual(completions, []);
538
+
539
+ input(`\x1b[<0;${targetX};${targetRow + 1}M`);
540
+ assert.deepEqual(completions, [], "press alone does not answer");
541
+ input(`\x1b[<0;${targetX};${targetRow + 1}m`);
542
+ if (multiSelect) {
543
+ assert.deepEqual(completions, [], "a multi-select click toggles without answering");
544
+ tui.renderNow();
545
+ screen = tui.getScreenLines();
546
+ assert.match(stripTerminalSequences(screen[targetRow]!), /\[x\] Beta/);
547
+ input("\r");
548
+ }
549
+ const result = await pending;
550
+ const answer = multiSelect
551
+ ? { questionIndex: 0, question: "Pick?", kind: "multi", answer: null, selected: [label] }
552
+ : { questionIndex: 0, question: "Pick?", kind: "option", answer: label };
553
+ assert.equal(completions.length, 1);
554
+ assert.deepEqual(result.details.answers, [answer]);
555
+ assert.equal(result.content[0]?.text, multiSelect ? `1. Pick? — selected: ${label}` : `1. Pick? — ${label}`);
556
+ assert.deepEqual(emitted, [
557
+ { channel: "gentle-pi:ask-user-question:blocked", data: { active: true } },
558
+ { channel: "gentle-pi:ask-user-question:blocked", data: { active: false } },
559
+ ]);
560
+ } finally { tui.stop(); }
561
+ });
562
+ }
563
+
467
564
  test("ask_user_question mounts exactly one active question and switches with Tab", async () => {
468
565
  const { tool } = registerQuestionTool();
469
566
  const questions = [
@@ -250,7 +250,7 @@ test("Auto fails closed on missing verdict, throws, changed arguments, mode revo
250
250
  });
251
251
 
252
252
  test("Native consent, human questions and delegation remain with their original executors", async t=>{
253
- const f=fixture(t);for(const name of ["ask_user_choice","ask_user_question","gentle_review","gentle_review_capture","subagent_run","subagent_reply"]){
253
+ const f=fixture(t);for(const name of ["ask_user_choice","ask_user_question","gentle_review","gentle_review_capture","gentle_review_capture_group","gentle_review_run","subagent_run","subagent_reply"]){
254
254
  assert.equal((await f.execute(name,{})).executions,1);
255
255
  }
256
256
  assert.equal(f.requests.length,0);