gentle-pi 4.7.0 → 4.9.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 (617) hide show
  1. package/README.md +115 -44
  2. package/assets/agents/gentle-ai-explore.md +3 -3
  3. package/assets/agents/gentle-ai-verify.md +20 -6
  4. package/assets/agents/gentle-ai-worker.md +14 -13
  5. package/assets/agents/jd-judge-a.md +1 -3
  6. package/assets/agents/jd-judge-b.md +1 -3
  7. package/assets/agents/review-readability.md +1 -5
  8. package/assets/agents/review-reliability.md +1 -5
  9. package/assets/agents/review-resilience.md +1 -5
  10. package/assets/agents/review-risk.md +1 -5
  11. package/assets/design-canvas/canvas-api.js +45 -0
  12. package/assets/design-canvas/canvas-boards.js +476 -0
  13. package/assets/design-canvas/canvas-boot.js +219 -0
  14. package/assets/design-canvas/canvas-checks.js +491 -0
  15. package/assets/design-canvas/canvas-comments.js +315 -0
  16. package/assets/design-canvas/canvas-compare.js +159 -0
  17. package/assets/design-canvas/canvas-events.js +75 -0
  18. package/assets/design-canvas/canvas-export.js +393 -0
  19. package/assets/design-canvas/canvas-focus.js +203 -0
  20. package/assets/design-canvas/canvas-handoffs.js +150 -0
  21. package/assets/design-canvas/canvas-i18n-es.js +397 -0
  22. package/assets/design-canvas/canvas-i18n.js +108 -0
  23. package/assets/design-canvas/canvas-layout.js +526 -0
  24. package/assets/design-canvas/canvas-menu.js +219 -0
  25. package/assets/design-canvas/canvas-messages.js +86 -0
  26. package/assets/design-canvas/canvas-minimap.js +163 -0
  27. package/assets/design-canvas/canvas-parts.js +401 -0
  28. package/assets/design-canvas/canvas-popover.js +234 -0
  29. package/assets/design-canvas/canvas-rail.js +351 -0
  30. package/assets/design-canvas/canvas-sizes.js +524 -0
  31. package/assets/design-canvas/canvas-store.js +167 -0
  32. package/assets/design-canvas/canvas-theme.js +69 -0
  33. package/assets/design-canvas/canvas-tokens.js +674 -0
  34. package/assets/design-canvas/canvas-ui.js +24 -0
  35. package/assets/design-canvas/canvas-view.js +184 -0
  36. package/assets/design-canvas/canvas.css +773 -17
  37. package/assets/design-canvas/canvas.js +2 -1506
  38. package/assets/design-canvas/index.html +120 -36
  39. package/assets/design-canvas/inspector.js +574 -21
  40. package/assets/design-canvas/theme-early.js +10 -0
  41. package/assets/install-wizard/wizard.js +5 -1
  42. package/assets/migrations/agent-body-history.json +30 -0
  43. package/assets/orchestrator-delegation-reference.md +8 -14
  44. package/assets/orchestrator-delegation.md +5 -9
  45. package/assets/orchestrator-full-delegation-card.md +11 -16
  46. package/assets/orchestrator-full-delegation.md +9 -9
  47. package/assets/orchestrator-memory.md +4 -4
  48. package/assets/orchestrator-prompts.md +3 -31
  49. package/assets/orchestrator-quota-recovery.md +5 -0
  50. package/assets/orchestrator-skills.md +13 -12
  51. package/assets/orchestrator-tracking.md +13 -17
  52. package/assets/orchestrator-verification.md +12 -10
  53. package/assets/orchestrator-writer.md +13 -13
  54. package/assets/orchestrator.md +20 -24
  55. package/bin/gentle-shell.mjs +205 -10
  56. package/contracts/review-provider-contract-mirror/provider-contract.lock.json +8 -9
  57. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/manifest.json +3 -3
  58. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/orchestration/pi.md +2 -1
  59. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/routing/pi.md +16 -16
  60. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/generated/provider-capabilities.baseline.json +3 -3
  61. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/generated/provider-roles.baseline.json +1 -1
  62. package/docs/assets/brand/sponsor-banner.svg +60 -0
  63. package/docs/assets/features/gentle-tower.png +0 -0
  64. package/docs/auto-permission-answers.md +1 -1
  65. package/docs/bundled-install.md +14 -6
  66. package/docs/delegated-verification.md +23 -5
  67. package/docs/desktop-feed.md +303 -0
  68. package/docs/desktop-rpc.md +1931 -0
  69. package/docs/fast-mode.md +2 -2
  70. package/docs/gentle-agents-activity.md +26 -0
  71. package/docs/gentle-shell-desktop.md +465 -0
  72. package/docs/gentle-shell.md +102 -17
  73. package/docs/images/desktop/chat.png +0 -0
  74. package/docs/images/desktop/palette.png +0 -0
  75. package/docs/images/desktop/todo.png +0 -0
  76. package/docs/install-wizard.md +30 -21
  77. package/docs/odd-preparation-continuity.md +24 -0
  78. package/docs/permission-modes.md +9 -1
  79. package/docs/prompt-budget.md +12 -0
  80. package/docs/rdd-odd-friction-triage-2026-11-07.md +57 -0
  81. package/docs/readme-reference.md +113 -32
  82. package/docs/review-coordinator.md +29 -9
  83. package/docs/review-delivery-preflight.md +22 -0
  84. package/docs/work-continuity.md +19 -6
  85. package/extensions/ask-user-choice.ts +36 -18
  86. package/extensions/ask-user-question.ts +48 -9
  87. package/extensions/child-context.ts +21 -7
  88. package/extensions/gentle-agents.ts +436 -66
  89. package/extensions/gentle-ai.ts +809 -158
  90. package/extensions/gentle-design.ts +69 -3
  91. package/extensions/gentle-desktop-feed.ts +778 -0
  92. package/extensions/gentle-desktop-rpc.ts +276 -0
  93. package/extensions/gentle-guide.ts +3 -0
  94. package/extensions/gentle-herdr-desktop-status.ts +275 -0
  95. package/extensions/gentle-shell.ts +174 -59
  96. package/extensions/gentle-stats.ts +30 -1
  97. package/extensions/gentle-todo.ts +48 -25
  98. package/extensions/gentle-tower.ts +305 -0
  99. package/extensions/skill-registry.ts +260 -225
  100. package/herdr/RECIPE.md +157 -0
  101. package/herdr/keys.json +14 -0
  102. package/herdr/layouts/gentle-shell.json +202 -0
  103. package/herdr/mods/gentle-agents/icons/kind-herdr.svg +1 -0
  104. package/herdr/mods/gentle-agents/icons/kind-remote.svg +1 -0
  105. package/herdr/mods/gentle-agents/icons/kind-tui.svg +1 -0
  106. package/herdr/mods/gentle-agents/main.js +190 -0
  107. package/herdr/mods/gentle-agents/mod.json +1 -0
  108. package/herdr/mods/gentle-agents/snapshot.js +469 -0
  109. package/herdr/mods/gentle-agents/tokens.js +273 -0
  110. package/herdr/mods/gentle-chat/MINIMAL.md +69 -0
  111. package/herdr/mods/gentle-chat/actions.js +180 -0
  112. package/herdr/mods/gentle-chat/feed.js +321 -0
  113. package/herdr/mods/gentle-chat/icons/branch.svg +1 -0
  114. package/herdr/mods/gentle-chat/icons/chat.svg +1 -0
  115. package/herdr/mods/gentle-chat/icons/check.svg +1 -0
  116. package/herdr/mods/gentle-chat/icons/chev.svg +1 -0
  117. package/herdr/mods/gentle-chat/icons/clip.svg +1 -0
  118. package/herdr/mods/gentle-chat/icons/down.svg +1 -0
  119. package/herdr/mods/gentle-chat/icons/folder.svg +1 -0
  120. package/herdr/mods/gentle-chat/icons/kind-herdr.svg +1 -0
  121. package/herdr/mods/gentle-chat/icons/kind-remote.svg +1 -0
  122. package/herdr/mods/gentle-chat/icons/kind-tui.svg +1 -0
  123. package/herdr/mods/gentle-chat/icons/mark.svg +1 -0
  124. package/herdr/mods/gentle-chat/icons/send.svg +1 -0
  125. package/herdr/mods/gentle-chat/icons/shield.svg +1 -0
  126. package/herdr/mods/gentle-chat/icons/stop.svg +1 -0
  127. package/herdr/mods/gentle-chat/icons/term.svg +1 -0
  128. package/herdr/mods/gentle-chat/icons/user.svg +1 -0
  129. package/herdr/mods/gentle-chat/icons/x.svg +1 -0
  130. package/herdr/mods/gentle-chat/main.js +968 -0
  131. package/herdr/mods/gentle-chat/mod.json +1 -0
  132. package/herdr/mods/gentle-chat/session.js +212 -0
  133. package/herdr/mods/gentle-chat/snapshot.js +469 -0
  134. package/herdr/mods/gentle-chat/tokens.js +137 -0
  135. package/herdr/mods/gentle-chat/ui.js +883 -0
  136. package/herdr/mods/gentle-confirm/main.js +60 -0
  137. package/herdr/mods/gentle-confirm/mod.json +1 -0
  138. package/herdr/mods/gentle-inspector/actions.js +180 -0
  139. package/herdr/mods/gentle-inspector/icons/bolt.svg +1 -0
  140. package/herdr/mods/gentle-inspector/icons/bot.svg +1 -0
  141. package/herdr/mods/gentle-inspector/icons/check.svg +1 -0
  142. package/herdr/mods/gentle-inspector/icons/db.svg +1 -0
  143. package/herdr/mods/gentle-inspector/icons/diff.svg +1 -0
  144. package/herdr/mods/gentle-inspector/icons/jobs.svg +1 -0
  145. package/herdr/mods/gentle-inspector/icons/plug.svg +1 -0
  146. package/herdr/mods/gentle-inspector/icons/review.svg +1 -0
  147. package/herdr/mods/gentle-inspector/icons/stats.svg +1 -0
  148. package/herdr/mods/gentle-inspector/icons/stop.svg +1 -0
  149. package/herdr/mods/gentle-inspector/icons/todo.svg +1 -0
  150. package/herdr/mods/gentle-inspector/main.js +500 -0
  151. package/herdr/mods/gentle-inspector/mod.json +1 -0
  152. package/herdr/mods/gentle-inspector/snapshot.js +469 -0
  153. package/herdr/mods/gentle-inspector/tokens.js +273 -0
  154. package/herdr/mods/gentle-palette/actions.js +180 -0
  155. package/herdr/mods/gentle-palette/icons/bolt.svg +1 -0
  156. package/herdr/mods/gentle-palette/icons/bot.svg +1 -0
  157. package/herdr/mods/gentle-palette/icons/chat.svg +1 -0
  158. package/herdr/mods/gentle-palette/icons/check.svg +1 -0
  159. package/herdr/mods/gentle-palette/icons/cmd.svg +1 -0
  160. package/herdr/mods/gentle-palette/icons/diff.svg +1 -0
  161. package/herdr/mods/gentle-palette/icons/jobs.svg +1 -0
  162. package/herdr/mods/gentle-palette/icons/plus.svg +1 -0
  163. package/herdr/mods/gentle-palette/icons/review.svg +1 -0
  164. package/herdr/mods/gentle-palette/icons/search.svg +1 -0
  165. package/herdr/mods/gentle-palette/icons/shield.svg +1 -0
  166. package/herdr/mods/gentle-palette/icons/stats.svg +1 -0
  167. package/herdr/mods/gentle-palette/icons/stop.svg +1 -0
  168. package/herdr/mods/gentle-palette/icons/term.svg +1 -0
  169. package/herdr/mods/gentle-palette/icons/todo.svg +1 -0
  170. package/herdr/mods/gentle-palette/main.js +333 -0
  171. package/herdr/mods/gentle-palette/mod.json +1 -0
  172. package/herdr/mods/gentle-palette/snapshot.js +469 -0
  173. package/herdr/mods/gentle-palette/tokens.js +273 -0
  174. package/herdr/mods/gentle-pane/icons/chat.svg +1 -0
  175. package/herdr/mods/gentle-pane/icons/close.svg +1 -0
  176. package/herdr/mods/gentle-pane/icons/kind-herdr.svg +1 -0
  177. package/herdr/mods/gentle-pane/icons/kind-remote.svg +1 -0
  178. package/herdr/mods/gentle-pane/icons/kind-tui.svg +1 -0
  179. package/herdr/mods/gentle-pane/icons/split-down.svg +1 -0
  180. package/herdr/mods/gentle-pane/icons/split-right.svg +1 -0
  181. package/herdr/mods/gentle-pane/icons/term.svg +1 -0
  182. package/herdr/mods/gentle-pane/icons/unzoom.svg +1 -0
  183. package/herdr/mods/gentle-pane/icons/zoom.svg +1 -0
  184. package/herdr/mods/gentle-pane/main.js +91 -0
  185. package/herdr/mods/gentle-pane/mod.json +1 -0
  186. package/herdr/mods/gentle-pane/snapshot.js +469 -0
  187. package/herdr/mods/gentle-pane/tokens.js +273 -0
  188. package/herdr/mods/gentle-sidebar/actions.js +180 -0
  189. package/herdr/mods/gentle-sidebar/icons/gear.svg +1 -0
  190. package/herdr/mods/gentle-sidebar/icons/mark.svg +1 -0
  191. package/herdr/mods/gentle-sidebar/icons/refresh.svg +1 -0
  192. package/herdr/mods/gentle-sidebar/icons/server-plus.svg +1 -0
  193. package/herdr/mods/gentle-sidebar/main.js +171 -0
  194. package/herdr/mods/gentle-sidebar/mod.json +1 -0
  195. package/herdr/mods/gentle-sidebar/snapshot.js +469 -0
  196. package/herdr/mods/gentle-sidebar/tokens.js +273 -0
  197. package/herdr/mods/gentle-spaces/icons/kind-herdr.svg +1 -0
  198. package/herdr/mods/gentle-spaces/icons/kind-remote.svg +1 -0
  199. package/herdr/mods/gentle-spaces/icons/kind-tui.svg +1 -0
  200. package/herdr/mods/gentle-spaces/icons/monitor.svg +1 -0
  201. package/herdr/mods/gentle-spaces/icons/plus.svg +1 -0
  202. package/herdr/mods/gentle-spaces/icons/server.svg +1 -0
  203. package/herdr/mods/gentle-spaces/machines.js +31 -0
  204. package/herdr/mods/gentle-spaces/main.js +299 -0
  205. package/herdr/mods/gentle-spaces/mod.json +1 -0
  206. package/herdr/mods/gentle-spaces/snapshot.js +469 -0
  207. package/herdr/mods/gentle-spaces/tokens.js +273 -0
  208. package/herdr/mods/gentle-status/actions.js +180 -0
  209. package/herdr/mods/gentle-status/main.js +192 -0
  210. package/herdr/mods/gentle-status/mod.json +1 -0
  211. package/herdr/mods/gentle-status/snapshot.js +469 -0
  212. package/herdr/mods/gentle-status/tokens.js +273 -0
  213. package/herdr/mods/gentle-tabs/icons/close.svg +1 -0
  214. package/herdr/mods/gentle-tabs/icons/kind-herdr.svg +1 -0
  215. package/herdr/mods/gentle-tabs/icons/kind-remote.svg +1 -0
  216. package/herdr/mods/gentle-tabs/icons/kind-tui.svg +1 -0
  217. package/herdr/mods/gentle-tabs/icons/plus.svg +1 -0
  218. package/herdr/mods/gentle-tabs/icons/win-close.svg +1 -0
  219. package/herdr/mods/gentle-tabs/icons/win-max.svg +1 -0
  220. package/herdr/mods/gentle-tabs/icons/win-min.svg +1 -0
  221. package/herdr/mods/gentle-tabs/icons/win-restore.svg +1 -0
  222. package/herdr/mods/gentle-tabs/main.js +171 -0
  223. package/herdr/mods/gentle-tabs/mod.json +1 -0
  224. package/herdr/mods/gentle-tabs/snapshot.js +469 -0
  225. package/herdr/mods/gentle-tabs/tokens.js +273 -0
  226. package/herdr/mods/gentle-tokens/main.js +20 -0
  227. package/herdr/mods/gentle-tokens/mod.json +1 -0
  228. package/herdr/mods/gentle-tokens/snapshot.js +469 -0
  229. package/herdr/mods/gentle-tokens/tokens.js +273 -0
  230. package/herdr/preview.png +0 -0
  231. package/herdr/themes/gentle-shell-dark.json +33 -0
  232. package/herdr/themes/gentle-shell-light.json +34 -0
  233. package/lib/agent-assets.ts +30 -6
  234. package/lib/agent-tool-overlay.ts +117 -0
  235. package/lib/agents-config.ts +47 -6
  236. package/lib/agents-message-delivery.ts +17 -0
  237. package/lib/agents-messaging.ts +8 -2
  238. package/lib/agents-protocol.ts +17 -0
  239. package/lib/agents-report-cap.ts +115 -0
  240. package/lib/agents-rpc-publisher.ts +39 -12
  241. package/lib/agents-runner.ts +92 -6
  242. package/lib/agents-session-transport.ts +17 -1
  243. package/lib/auto-permission-answers.ts +2 -1
  244. package/lib/background-jobs-tools.ts +9 -4
  245. package/lib/background-jobs.ts +22 -2
  246. package/lib/bounded-writer-admission.ts +184 -31
  247. package/lib/change-diff.ts +104 -0
  248. package/lib/child-context-files.ts +21 -6
  249. package/lib/codemode-renderer.ts +1 -0
  250. package/lib/commit-slice-signal.ts +1 -1
  251. package/lib/delivery-conflict-markers.ts +349 -0
  252. package/lib/design-canvas-assets.ts +38 -0
  253. package/lib/design-canvas-server.ts +241 -23
  254. package/lib/design-comments.ts +94 -4
  255. package/lib/design-handoffs.ts +2 -1
  256. package/lib/design-layout.ts +125 -0
  257. package/lib/design-parts.ts +281 -0
  258. package/lib/design-system-tokens.ts +111 -0
  259. package/lib/desktop-agents-service.ts +315 -0
  260. package/lib/desktop-changes-service.ts +171 -0
  261. package/lib/desktop-design-service.ts +233 -0
  262. package/lib/desktop-feed-actions.ts +804 -0
  263. package/lib/desktop-feed-answers.ts +129 -0
  264. package/lib/desktop-feed-sources.ts +184 -0
  265. package/lib/desktop-feed-stats.ts +98 -0
  266. package/lib/desktop-feed-store.ts +124 -0
  267. package/lib/desktop-feed.ts +788 -0
  268. package/lib/desktop-jobs-service.ts +290 -0
  269. package/lib/desktop-review-service.ts +187 -0
  270. package/lib/desktop-rpc-agents.ts +403 -0
  271. package/lib/desktop-rpc-changes.ts +223 -0
  272. package/lib/desktop-rpc-config-watch.ts +285 -0
  273. package/lib/desktop-rpc-config.ts +885 -0
  274. package/lib/desktop-rpc-design.ts +138 -0
  275. package/lib/desktop-rpc-jobs.ts +290 -0
  276. package/lib/desktop-rpc-permissions.ts +328 -0
  277. package/lib/desktop-rpc-profiles.ts +196 -0
  278. package/lib/desktop-rpc-review.ts +180 -0
  279. package/lib/desktop-rpc-session.ts +203 -0
  280. package/lib/desktop-rpc-sessions.ts +250 -0
  281. package/lib/desktop-rpc-stats.ts +187 -0
  282. package/lib/desktop-rpc-updates.ts +143 -0
  283. package/lib/desktop-rpc-usage.ts +229 -0
  284. package/lib/desktop-rpc.ts +336 -0
  285. package/lib/desktop-session-service.ts +223 -0
  286. package/lib/desktop-sessions-service.ts +249 -0
  287. package/lib/desktop-stats-service.ts +142 -0
  288. package/lib/desktop-updates-service.ts +268 -0
  289. package/lib/desktop-usage-service.ts +310 -0
  290. package/lib/destructive-command-guard.ts +188 -13
  291. package/lib/gentle-ai-renderer.ts +13 -1
  292. package/lib/gentle-design.ts +201 -14
  293. package/lib/gentle-shell-bundled.ts +100 -9
  294. package/lib/gentle-shell-desktop.ts +1370 -0
  295. package/lib/gentle-shell-launcher.ts +45 -3
  296. package/lib/herdr-desktop-events.ts +40 -0
  297. package/lib/herdr-desktop-status.ts +229 -0
  298. package/lib/hidden-tools.ts +35 -0
  299. package/lib/inprocess-reviewer.ts +96 -12
  300. package/lib/jobs-sidebar-state.ts +5 -0
  301. package/lib/model-fallback-policy.ts +9 -0
  302. package/lib/model-routing-authority.ts +9 -0
  303. package/lib/nan-provider.ts +42 -28
  304. package/lib/native-review-cli.ts +86 -4
  305. package/lib/openai-fast-tier.ts +1 -0
  306. package/lib/orchestrator-discovery.ts +39 -2
  307. package/lib/reply-language-anchor.ts +27 -2
  308. package/lib/request-context-placement.ts +53 -0
  309. package/lib/review-candidate-view.ts +11 -1
  310. package/lib/review-continuation-registry.ts +17 -0
  311. package/lib/review-coordinator.ts +252 -8
  312. package/lib/review-delivery-preflight.ts +85 -0
  313. package/lib/review-host-relay.ts +5 -1
  314. package/lib/review-integration-v2.ts +56 -3
  315. package/lib/reviewer-stream.ts +87 -0
  316. package/lib/session-profile-freeze.ts +13 -5
  317. package/lib/shell-prompt.ts +16 -3
  318. package/lib/shell-usage.ts +10 -0
  319. package/lib/stats-collector.ts +56 -27
  320. package/lib/tower-actions.ts +100 -0
  321. package/lib/tower-hub.ts +73 -0
  322. package/lib/tower-launch.ts +111 -0
  323. package/lib/tower-open.ts +99 -0
  324. package/lib/tower-presence.ts +70 -0
  325. package/lib/tower-server.ts +234 -0
  326. package/lib/tower-snapshot.ts +298 -0
  327. package/lib/update-status.ts +238 -0
  328. package/lib/verifier-settle-reminder.ts +1 -1
  329. package/lib/vim-editor-adapter.ts +9 -2
  330. package/lib/writer-batch-admission.ts +55 -0
  331. package/lib/yolo-session-policy.ts +6 -1
  332. package/package.json +14 -5
  333. package/prompts/skill-creation.md +1 -10
  334. package/runtime/design-canvas-assets.mjs +39 -0
  335. package/runtime/gentle-shell-bundled.mjs +100 -9
  336. package/runtime/gentle-shell-desktop.mjs +1371 -0
  337. package/runtime/gentle-shell-launcher.mjs +44 -2
  338. package/runtime/native-review-cli.mjs +86 -4
  339. package/runtime/review-integration-v2.mjs +56 -3
  340. package/runtime/tower-actions.mjs +101 -0
  341. package/runtime/tower-hub.mjs +74 -0
  342. package/runtime/tower-launch.mjs +112 -0
  343. package/runtime/tower-open.mjs +100 -0
  344. package/runtime/tower-presence.mjs +71 -0
  345. package/runtime/tower-server.mjs +234 -0
  346. package/runtime/tower-snapshot.mjs +299 -0
  347. package/scripts/bootstrap.cmd +2 -2
  348. package/scripts/bootstrap.sh +41 -4
  349. package/scripts/build-full-delegation-card.mjs +5 -21
  350. package/scripts/build-runtime-modules.mjs +10 -0
  351. package/scripts/gentle-ai-installer.mjs +10 -10
  352. package/scripts/gentle-ai-proxy.mjs +1 -1
  353. package/scripts/installer-downloads.mjs +34 -8
  354. package/scripts/installer-preflight.mjs +28 -17
  355. package/scripts/installer-probes.mjs +25 -5
  356. package/scripts/installer-server.mjs +38 -9
  357. package/scripts/installer-windows.mjs +2 -2
  358. package/scripts/pi-update.mjs +166 -27
  359. package/scripts/prepare-verifier.mjs +107 -0
  360. package/scripts/update-agent-body-history.mjs +55 -8
  361. package/scripts/verify-package-files.mjs +61 -20
  362. package/skills/branch-pr/SKILL.md +16 -16
  363. package/skills/comment-writer/SKILL.md +1 -1
  364. package/skills/design/SKILL.md +6 -6
  365. package/skills/gentle-ai/SKILL.md +5 -5
  366. package/skills/judgment-day/SKILL.md +2 -2
  367. package/skills/judgment-day/references/prompts-and-formats.md +1 -1
  368. package/skills/provider-defect-report/SKILL.md +61 -0
  369. package/skills/rdd-defect-workflow/SKILL.md +6 -6
  370. package/skills/skill-improver/SKILL.md +2 -2
  371. package/skills/skill-registry/SKILL.md +11 -13
  372. package/skills/tui-design/SKILL.md +1 -1
  373. package/skills/work-unit-commits/SKILL.md +5 -5
  374. package/tests/agent-prompt-diet-contract.test.ts +101 -0
  375. package/tests/agent-tool-overlay-acceptance.test.ts +158 -0
  376. package/tests/agent-tool-overlay.test.ts +89 -0
  377. package/tests/agents-config.test.ts +10 -1
  378. package/tests/agents-message-delivery.test.ts +36 -0
  379. package/tests/agents-queries.test.ts +144 -4
  380. package/tests/agents-report-cap.test.ts +126 -0
  381. package/tests/agents-runner.test.ts +37 -1
  382. package/tests/agents-session-transport.test.ts +34 -0
  383. package/tests/always-on-prompt-verdicts-contract.test.ts +188 -0
  384. package/tests/append-system-prompt-route.test.ts +26 -7
  385. package/tests/approved-text-leftovers-contract.test.ts +136 -0
  386. package/tests/artifact-language.test.ts +1 -1
  387. package/tests/ask-user-choice.test.ts +78 -21
  388. package/tests/ask-user-question.test.ts +61 -6
  389. package/tests/audit-leftovers-contract.test.ts +51 -0
  390. package/tests/auto-permission-answers.test.ts +12 -1
  391. package/tests/background-jobs.test.ts +12 -0
  392. package/tests/bounded-stop-contract.test.ts +148 -27
  393. package/tests/branch-pr-skill.test.ts +10 -1
  394. package/tests/bundled-install.test.ts +1 -1
  395. package/tests/change-diff.test.ts +75 -0
  396. package/tests/child-context-files.test.ts +64 -8
  397. package/tests/child-skills-catalog.test.ts +56 -0
  398. package/tests/codemode-rendering.test.ts +4 -1
  399. package/tests/commit-slice-signal.test.ts +3 -2
  400. package/tests/decision-routing-contract.test.ts +390 -0
  401. package/tests/delegate-for-reason-contract.test.ts +30 -8
  402. package/tests/delegated-key-learnings-contract.test.ts +21 -28
  403. package/tests/delivery-b-rendered-surfaces.test.ts +32 -0
  404. package/tests/delivery-conflict-markers.test.ts +348 -0
  405. package/tests/design-canvas-all-sizes.test.ts +631 -0
  406. package/tests/design-canvas-allowlist.test.ts +32 -0
  407. package/tests/design-canvas-assets.test.ts +11 -878
  408. package/tests/design-canvas-boards.test.ts +77 -0
  409. package/tests/design-canvas-checks.test.ts +655 -0
  410. package/tests/design-canvas-compare.test.ts +79 -0
  411. package/tests/design-canvas-events.test.ts +59 -0
  412. package/tests/design-canvas-export.test.ts +1168 -0
  413. package/tests/design-canvas-focus.test.ts +113 -0
  414. package/tests/design-canvas-handoffs.test.ts +59 -0
  415. package/tests/design-canvas-i18n-review.test.ts +513 -0
  416. package/tests/design-canvas-i18n-views.test.ts +259 -0
  417. package/tests/design-canvas-i18n.test.ts +528 -0
  418. package/tests/design-canvas-inspector.test.ts +1004 -0
  419. package/tests/design-canvas-layout.test.ts +1222 -0
  420. package/tests/design-canvas-minimap.test.ts +413 -0
  421. package/tests/design-canvas-modules.test.ts +91 -0
  422. package/tests/design-canvas-parts.test.ts +721 -0
  423. package/tests/design-canvas-rail.test.ts +799 -0
  424. package/tests/design-canvas-server.test.ts +855 -17
  425. package/tests/design-canvas-sizes.test.ts +548 -0
  426. package/tests/design-canvas-store.test.ts +189 -0
  427. package/tests/design-canvas-theme.test.ts +198 -0
  428. package/tests/design-canvas-tokens.test.ts +965 -0
  429. package/tests/design-canvas-view.test.ts +299 -0
  430. package/tests/design-comments.test.ts +201 -1
  431. package/tests/design-handoffs.test.ts +20 -0
  432. package/tests/design-layout.test.ts +100 -0
  433. package/tests/design-parts.test.ts +260 -0
  434. package/tests/design-system-tokens.test.ts +215 -0
  435. package/tests/desktop-feed-actions-guards.test.ts +595 -0
  436. package/tests/desktop-feed-actions.test.ts +761 -0
  437. package/tests/desktop-feed-live-work.test.ts +209 -0
  438. package/tests/desktop-feed-performance.test.ts +369 -0
  439. package/tests/desktop-feed-plan-profiles.test.ts +509 -0
  440. package/tests/desktop-feed-send-prompt.test.ts +303 -0
  441. package/tests/desktop-feed-tool-summaries.test.ts +69 -0
  442. package/tests/desktop-feed.test.ts +615 -0
  443. package/tests/desktop-rpc-agents.test.ts +1319 -0
  444. package/tests/desktop-rpc-changes.test.ts +608 -0
  445. package/tests/desktop-rpc-config-watch.test.ts +1159 -0
  446. package/tests/desktop-rpc-config.test.ts +1462 -0
  447. package/tests/desktop-rpc-design.test.ts +672 -0
  448. package/tests/desktop-rpc-jobs.test.ts +1193 -0
  449. package/tests/desktop-rpc-permissions.test.ts +321 -0
  450. package/tests/desktop-rpc-profiles.test.ts +140 -0
  451. package/tests/desktop-rpc-review.test.ts +678 -0
  452. package/tests/desktop-rpc-safety.test.ts +119 -0
  453. package/tests/desktop-rpc-session.test.ts +642 -0
  454. package/tests/desktop-rpc-sessions.test.ts +647 -0
  455. package/tests/desktop-rpc-stats.test.ts +431 -0
  456. package/tests/desktop-rpc-updates.test.ts +525 -0
  457. package/tests/desktop-rpc-usage.test.ts +707 -0
  458. package/tests/desktop-rpc.test.ts +293 -0
  459. package/tests/devbinary/pi-host-relay.devtest.ts +149 -80
  460. package/tests/devbinary/review-session-consent.devtest.ts +84 -0
  461. package/tests/engram-safety.test.ts +111 -0
  462. package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.captured.json +92 -0
  463. package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.provenance.md +3 -0
  464. package/tests/fixtures/primary-session-prompt/gentleman.golden.md +30 -41
  465. package/tests/fixtures/refusal-identity.probe.mjs +139 -0
  466. package/tests/fixtures/session-profile-v1/replay.ts +4 -1
  467. package/tests/full-delegation-closure.test.ts +48 -0
  468. package/tests/gentle-agents.test.ts +848 -8
  469. package/tests/gentle-ai-binary.test.ts +1 -1
  470. package/tests/gentle-ai-child-guards.test.ts +1 -0
  471. package/tests/gentle-ai-installer.test.ts +52 -51
  472. package/tests/gentle-ai-renderer.test.ts +36 -2
  473. package/tests/gentle-ai.test.ts +195 -21
  474. package/tests/gentle-design.test.ts +365 -1
  475. package/tests/gentle-fast.test.ts +15 -0
  476. package/tests/gentle-herdr-desktop-status.test.ts +595 -0
  477. package/tests/gentle-shell-bundled.test.ts +91 -5
  478. package/tests/gentle-shell-desktop-bin.test.ts +125 -0
  479. package/tests/gentle-shell-desktop.test.ts +927 -0
  480. package/tests/gentle-shell-launcher-tower.test.ts +104 -0
  481. package/tests/gentle-shell-launcher.test.ts +1 -1
  482. package/tests/gentle-shell.test.ts +121 -87
  483. package/tests/gentle-todo.test.ts +32 -9
  484. package/tests/gentle-tower.test.ts +578 -0
  485. package/tests/herdr-desktop-status.test.ts +285 -0
  486. package/tests/hidden-tools.test.ts +188 -0
  487. package/tests/independent-recovery-delivery.test.ts +35 -9
  488. package/tests/inprocess-reviewer.test.ts +73 -0
  489. package/tests/install-wizard.test.ts +27 -1
  490. package/tests/installer-downloads.test.ts +30 -1
  491. package/tests/installer-posix-bootstrap.test.ts +114 -13
  492. package/tests/installer-preflight.test.ts +49 -1
  493. package/tests/installer-probes.test.ts +146 -0
  494. package/tests/installer-server.test.ts +203 -4
  495. package/tests/installer-windows-bootstrap.test.ts +19 -1
  496. package/tests/judgment-day-severity-admission.test.ts +46 -0
  497. package/tests/lazy-module-contradictions-contract.test.ts +181 -0
  498. package/tests/maintainer/desktop-rpc.maintest.ts +907 -0
  499. package/tests/maintainer/pi-update-source.maintest.ts +48 -18
  500. package/tests/model-fallback-policy.test.ts +26 -7
  501. package/tests/nan-provider-runtime.test.ts +17 -3
  502. package/tests/nan-provider.test.ts +111 -56
  503. package/tests/native-review-capability-contract.test.ts +19 -1
  504. package/tests/native-review-cli-nonblocking-findings.test.ts +165 -0
  505. package/tests/native-review-parity.test.ts +24 -5
  506. package/tests/native-review-refusal-identity.test.ts +25 -0
  507. package/tests/no-self-pause-contract.test.ts +33 -15
  508. package/tests/odd-integration.test.ts +11 -3
  509. package/tests/odd-routing-canonical-ratchet.test.ts +10 -0
  510. package/tests/odd-routing-contract.test.ts +99 -31
  511. package/tests/orchestrator-budget.test.ts +32 -5
  512. package/tests/orchestrator-consultation-sdk.test.ts +32 -6
  513. package/tests/orchestrator-delegation-mode.test.ts +2 -1
  514. package/tests/orchestrator-discovery.test.ts +28 -0
  515. package/tests/orchestrator-prompt-budget.test.ts +12 -2
  516. package/tests/orchestrator-prompt-diet-contract.test.ts +249 -0
  517. package/tests/orchestrator-rdd-ownership.test.ts +2 -1
  518. package/tests/orchestrator-work-search.test.ts +4 -2
  519. package/tests/package-files.test.ts +25 -1
  520. package/tests/package-manifest.test.ts +15 -14
  521. package/tests/parallel-reason-contract.test.ts +6 -3
  522. package/tests/permission-allowlist.test.ts +200 -30
  523. package/tests/persona-neutral-voseo.test.ts +4 -4
  524. package/tests/persona-reply-language.test.ts +1 -1
  525. package/tests/persona-single-channel.test.ts +13 -5
  526. package/tests/pi-routing-measured-values.test.ts +24 -0
  527. package/tests/pi-update-launcher.test.ts +17 -7
  528. package/tests/pi-update-source.test.ts +113 -6
  529. package/tests/pi-update.test.ts +294 -19
  530. package/tests/pnpm-workspace-policy.test.ts +47 -0
  531. package/tests/primary-context-files.test.ts +233 -0
  532. package/tests/primary-context-three-files.test.ts +174 -0
  533. package/tests/primary-session-prompt.test.ts +25 -0
  534. package/tests/profile-fast-tier.test.ts +66 -1
  535. package/tests/provider-defect-handoff.test.ts +124 -99
  536. package/tests/rdd-aware-verification-contract.test.ts +1 -1
  537. package/tests/rdd-status-line.test.ts +94 -1
  538. package/tests/reply-language-anchor-placement.test.ts +184 -0
  539. package/tests/reply-language-anchor.test.ts +17 -1
  540. package/tests/request-context-append-only.test.ts +218 -0
  541. package/tests/request-context-placement.test.ts +148 -0
  542. package/tests/review-agent-end-preflight.test.ts +79 -1
  543. package/tests/review-candidate-view.test.ts +65 -0
  544. package/tests/review-continuation-registry.test.ts +31 -0
  545. package/tests/review-contract-prompt.test.ts +2 -1
  546. package/tests/review-controller.test.ts +2 -1
  547. package/tests/review-coordinator-correction-gate.test.ts +105 -0
  548. package/tests/review-coordinator-findings.test.ts +206 -0
  549. package/tests/review-coordinator-nonblocking-scope.test.ts +169 -0
  550. package/tests/review-coordinator.test.ts +271 -4
  551. package/tests/review-delivery-preflight.test.ts +462 -0
  552. package/tests/review-due-compaction.test.ts +31 -0
  553. package/tests/review-due-public-boundary.test.ts +27 -0
  554. package/tests/review-integration-nonblocking-findings.test.ts +108 -0
  555. package/tests/review-json-arguments.test.ts +41 -2
  556. package/tests/review-ledger-contract.test.ts +19 -40
  557. package/tests/review-loadout-rdd-off-sdk.test.ts +30 -1
  558. package/tests/review-one-call-findings.test.ts +131 -0
  559. package/tests/review-one-call-followups.test.ts +308 -0
  560. package/tests/review-one-call-reviewer-requests.test.ts +207 -0
  561. package/tests/review-one-call.test.ts +452 -0
  562. package/tests/review-relay-transport-agent.test.ts +28 -1
  563. package/tests/review-reviewer-evidence.test.ts +41 -1
  564. package/tests/review-risk-assessment.test.ts +52 -5
  565. package/tests/review-run-statement-guidance-independent.test.ts +54 -0
  566. package/tests/review-session-standing-permission-controller.test.ts +32 -2
  567. package/tests/review-tool-prose-budget.test.ts +1 -0
  568. package/tests/reviewer-stream.test.ts +149 -0
  569. package/tests/sensitive-path-tools.test.ts +138 -4
  570. package/tests/session-profile-extension.test.ts +312 -18
  571. package/tests/session-profile-freeze.test.ts +26 -0
  572. package/tests/session-profile-v1-compat.test.ts +20 -0
  573. package/tests/shell-prompt.test.ts +17 -0
  574. package/tests/shell-usage.test.ts +59 -10
  575. package/tests/skill-collision-prefixes.test.ts +1 -0
  576. package/tests/skill-contradictions-contract.test.ts +124 -0
  577. package/tests/skill-registry-watcher.test.ts +216 -2
  578. package/tests/skill-registry.test.ts +983 -306
  579. package/tests/stats-collector.test.ts +109 -2
  580. package/tests/support/design-canvas-dom.ts +386 -0
  581. package/tests/support/review-coordinator-runtime.ts +212 -17
  582. package/tests/task-size-routing-contract.test.ts +49 -14
  583. package/tests/test-strength-contract.test.ts +2 -1
  584. package/tests/todo-request-append-only.test.ts +214 -0
  585. package/tests/tool-batching-contract.test.ts +3 -1
  586. package/tests/tower-actions.test.ts +247 -0
  587. package/tests/tower-artifacts.test.ts +114 -0
  588. package/tests/tower-open.test.ts +97 -0
  589. package/tests/tower-presence.test.ts +175 -0
  590. package/tests/tower-server.test.ts +122 -0
  591. package/tests/tower-snapshot.test.ts +236 -0
  592. package/tests/tower-web-echo.test.ts +125 -0
  593. package/tests/tower-web-hover.test.ts +251 -0
  594. package/tests/update-agent-body-history.test.ts +138 -0
  595. package/tests/verification-scoped-stop-contract.test.ts +32 -0
  596. package/tests/verification-tiers-contract.test.ts +229 -0
  597. package/tests/verifier-preparation.test.ts +229 -0
  598. package/tests/verifier-settle-reminder.test.ts +2 -2
  599. package/tests/verify-agent-contract.test.ts +20 -2
  600. package/tests/verify-first-launch-contract.test.ts +88 -12
  601. package/tests/vim-editor-adapter.test.ts +2 -2
  602. package/tests/work-continuity-contract.test.ts +136 -27
  603. package/tests/writer-admission-messages.test.ts +232 -0
  604. package/tests/writer-batch-admission.test.ts +66 -0
  605. package/tests/writer-edit-surface-scope.test.ts +52 -20
  606. package/tests/writer-feature-document-admission.test.ts +184 -0
  607. package/tests/writer-rejection-next-step.test.ts +55 -0
  608. package/tests/writer-surface-authority-contract.test.ts +158 -0
  609. package/tests/yolo-mode.test.ts +39 -0
  610. package/skills/_shared/review-ledger-contract.md +0 -106
  611. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/README.md +0 -0
  612. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/schemas/lens.schema.json +0 -0
  613. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/schemas/refuter.schema.json +0 -0
  614. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/schemas/targeted-validator.schema.json +0 -0
  615. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/vectors/lens.json +0 -0
  616. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/vectors/refuter.json +0 -0
  617. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/vectors/targeted-validator.json +0 -0
@@ -0,0 +1,968 @@
1
+ // Gentle Shell as a native chat: the centre column of design/herdr-desktop/01-inspector.html
2
+ // (T5). Shows one Gentle Shell (pi) terminal's conversation, read incrementally from its session
3
+ // JSONL, with the session header and the pending question from the session's desktop snapshot
4
+ // (docs/desktop-feed.md), and sends what you type with `hc send`. The terminal stays the real
5
+ // Gentle Shell TUI; the header's Chat | Terminal switch flips the layout stack.
6
+ // T11 (S10): any live Gentle Shell session, also one that runs outside Herdr app (the Herdr TUI,
7
+ // Ghostty, …; snapshot.js targetSession): its chat reads the exact session file its snapshot
8
+ // names; prompts and answers go through its inbox (send_prompt, answer_question via the session);
9
+ // it has no Terminal here, so the switch and ⌘J say where it runs instead.
10
+ // props: { terminal? } (else the session the window is about), and in a layout stack
11
+ // { stack, self, other } for the Chat / Terminal switch (see herdr/layouts/gentle-shell.json).
12
+ // Drawing: ui.js; colours, type and radii: tokens.js (shared with the T6 mods).
13
+ // Cost (S13, herdr/PERF.md): every redraw lays out every drawn row of the whole window, so the
14
+ // chat draws the last PAGE entries of the session's end (readTail; "Show earlier" goes back),
15
+ // wakes only for its own session file and settings files, follows the shared snapshot read
16
+ // (snapshot.js) from render instead of polling, and keeps no timer while it is hidden.
17
+
18
+ import { View, div } from "gpui-kit";
19
+ import { v_flex, TextareaState, ScrollHandle } from "gpui-base";
20
+ import { agents, props, layout, hc, run, setShared, shared, theme, watchFolder, nextCommand } from "herdr";
21
+ import { readFile } from "fs/promises";
22
+ import { sessionFileFor, readAfter, readTail, utf8 } from "./session.js";
23
+ import { FeedSource, allSessions, targetSession, machineOf, liveState } from "./snapshot.js";
24
+ import { createFeed, ingest, hideThinkingFrom } from "./feed.js";
25
+ import { palette, sans, R } from "./tokens.js";
26
+ import { header, entries, entry, lane, stateLabel, askCard, askOptions, composer, icon, PERM, ELSEWHERE } from "./ui.js";
27
+ import { sendAction, errorText, safeKeys, terminalFree, tuiCommand, showTerminal, confirm, confirmed, readSnapshot } from "./actions.js";
28
+
29
+ const PAGE = 40; // entries drawn at first; "Show earlier" adds this many
30
+ const TAIL = 300 * 1024; // a session's first paint reads its last TAIL bytes and LINES lines, up to
31
+ const LINES = 300; // TAIL_MAX bytes; each "Show earlier messages" reads as much again
32
+ const TAIL_MAX = 3 * 1024 * 1024;
33
+ const EXEC_ABOVE = 1024 * 1024; // a bigger session file is read through `sh`, only its new bytes
34
+ const LOOK_MS = 5000; // while shown: a look for a missed session switch or request (no file read)
35
+ const FILE_MS = 15000; // while shown without a folder watch: a read for missed writes
36
+ const SAFETY_MS = 60000; // while shown with one: a read for a write made before the watch began
37
+ const PLACEHOLDER = "Message Gentle Shell… / for commands";
38
+ const PLACEHOLDER_ASK = "Answer above, or message Gentle Shell… / for commands";
39
+ const ESC_MS = 1000; // the TUI's double-Esc window for stopping a turn (DOUBLE_ESC_CANCEL_WINDOW_MS)
40
+ const ESC_NOTICE = "Press Esc again to stop the agent.";
41
+ const SLASH_MAX = 50; // commands the "/" menu filters to at most
42
+ const REQUEST_MS = 10000; // a palette request older than this is ignored (shared values persist)
43
+ const NO_COMMANDS = "Open that session's terminal to run /commands.";
44
+ const KEPT = 30; // sessions whose opened rows are remembered when another session shows
45
+ const DOUBLE_MS = 300; // one ⌘O that reaches both the chat's key and the layout's key toggles once
46
+
47
+ // The composer's "/" menu: open while the draft is one "/word" (no space or line break yet).
48
+ // Names that start with the word come first, then names and descriptions that contain it.
49
+ export function slashMatches(commands, draft) {
50
+ const m = /^\/([^\s]*)$/.exec(String(draft ?? ""));
51
+ if (!m) return null;
52
+ const q = m[1].toLowerCase();
53
+ const list = Array.isArray(commands) ? commands.filter((c) => c && typeof c.name === "string") : [];
54
+ const starts = list.filter((c) => c.name.toLowerCase().startsWith(q));
55
+ const contains = q ? list.filter((c) => !starts.includes(c) && `${c.name} ${c.description ?? ""}`.toLowerCase().includes(q)) : [];
56
+ return [...starts, ...contains].slice(0, SLASH_MAX);
57
+ }
58
+
59
+ // A session started before desktop prompts refuses the kind: say what to do.
60
+ // A send_prompt refusal in words: a session from before desktop prompts, or one compacting that
61
+ // already holds a message.
62
+ const PROMPT_REFUSALS = {
63
+ unknown_kind: "This session started before desktop messages: type in its own terminal, or restart it.",
64
+ session_compacting: "A message is already waiting for compaction to finish.",
65
+ };
66
+ const promptRefusal = (r) => PROMPT_REFUSALS[r?.error?.code] ?? null;
67
+ // An apply_profile refusal in words (S12): a session from before desktop profile switching.
68
+ const PROFILE_REFUSALS = {
69
+ unknown_kind: "This session started before desktop profile switching: use /gentle:profiles in its terminal, or restart it.",
70
+ };
71
+ const questionKey = (q) => (q ? `${q.toolCallId ?? ""}|${q.openedAt ?? ""}|${q.question ?? ""}` : null);
72
+
73
+ export default class GentleChat extends View {
74
+ init(_props, cx) {
75
+ this.feed = createFeed();
76
+ this.snap = null; // the session's desktop snapshot (gentle-shell.desktop-feed/v1), or null
77
+ this.key = null; // the shown session (snapshot.js allSessions key)
78
+ this.want = null; // the session to show, picked in a host call (render, a timer)
79
+ this.address = null; // its Herdr terminal, or null when it runs elsewhere
80
+ this.cwd = null;
81
+ this.file = null;
82
+ this.dir = null;
83
+ this.pos = 0; // the byte read up to
84
+ this.start = 0; // the byte the read part begins at (S13: a long session's tail; 0 = all of it)
85
+ this.size = 0; // the file's size at the last read
86
+ this.back = 1; // how many tails are read (readTail: TAIL, LINES and TAIL_MAX times this)
87
+ this.readAt = 0;
88
+ this.watched = null;
89
+ this.loading = false;
90
+ this.again = false;
91
+ this.refreshing = false;
92
+ this.reagain = false;
93
+ this.kicked = false; // a refresh is set for the next host call (see follow)
94
+ this.looking = false; // the shown-only fallback look is set (see look)
95
+ this.requesting = false;
96
+ this.settingsDirs = new Set(); // the folders of the shown session's settings files, watched
97
+ this.real = new Map(); // cwd -> real path, for sessionFileFor
98
+ this.open = new Map(); // row id -> open, when flipped from its default (S11: per row, kept across reads)
99
+ this.hunkAt = new Map(); // diff card id -> shown hunk
100
+ this.kept = new Map(); // session file -> { open, hunkAt } of a session shown before
101
+ this.expandAll = false; // ⌘O: every row open (the TUI's ctrl+o); a click on a row still flips it
102
+ this.expandAt = 0;
103
+ this.hideThinking = true; // the session's hideThinkingBlock (read with its snapshot)
104
+ this.settingsOf = null;
105
+ this.limit = PAGE;
106
+ this.stick = true; // scroll to the newest entry after the next draw
107
+ this.error = null;
108
+ this.sending = false;
109
+ this.typing = false; // the composer has the keyboard
110
+ this.permOpen = false;
111
+ this.profOpen = false; // the profiles menu (S12), on the header's Model fact
112
+ this.profAt = null; // the profile the menu shows the agents of (hovered or picked)
113
+ this.answered = null; // { key, index, custom } once an option of the open question was picked
114
+ this.busy = null; // the desktop action in flight ("perm", "stop-<id>", "attach", …), for its pending look
115
+ this.notice = null; // one calm line under the composer after an action that has no other trace
116
+ this.draft = ""; // the composer's text, kept from its change events (Send / Stop, the "/" menu)
117
+ this.slashAt = 0; // the "/" menu's selected row
118
+ this.slashClosed = null; // the draft Esc closed the "/" menu on; it opens again once the draft changes
119
+ this.escAt = 0; // the first Esc of an Esc Esc while the agent works
120
+ this.lastRequest = 0;
121
+ this.scroll = ScrollHandle.new();
122
+ this.focus = cx.focus_handle();
123
+ this.makeInput(PLACEHOLDER);
124
+ // Enter sends, Shift+Enter is the Textarea's new line; ⌘J shows the Terminal; ⌘K opens the
125
+ // Gentle commands palette; Esc Esc stops the agent's turn (Esc first closes the "/" menu).
126
+ // While the "/" menu is open, ↑/↓ move in it and Tab completes the command.
127
+ cx.bind_keys([
128
+ { keystroke: "enter", action: "gentle_chat_send", context: "GentleChatComposer > Input" },
129
+ { keystroke: "cmd-j", action: "gentle_chat_terminal", context: "GentleChat" },
130
+ { keystroke: "cmd-k", action: "gentle_chat_palette", context: "GentleChat" },
131
+ { keystroke: "cmd-o", action: "gentle_chat_expand", context: "GentleChat" },
132
+ { keystroke: "escape", action: "gentle_chat_escape", context: "GentleChat" },
133
+ { keystroke: "escape", action: "gentle_chat_escape", context: "GentleChatComposer > Input" },
134
+ { keystroke: "up", action: "gentle_chat_slash_up", context: "GentleSlashMenu > Input" },
135
+ { keystroke: "down", action: "gentle_chat_slash_down", context: "GentleSlashMenu > Input" },
136
+ { keystroke: "tab", action: "gentle_chat_slash_complete", context: "GentleSlashMenu > Input" },
137
+ ]);
138
+ // Every live snapshot (and whether its publisher still runs): the status bar's shared read
139
+ // (snapshot.js FeedSource). A new read re-renders this view, and render follows it.
140
+ this.source = new FeedSource();
141
+ this.source.start(cx);
142
+ this.tick(cx);
143
+ this.commands(cx);
144
+ this.look(cx);
145
+ }
146
+
147
+ // From render (every shared-state or Herdr change re-renders the mods) and the fallback look:
148
+ // a refresh when the shown session, its terminal or its snapshot changed, and a palette request
149
+ // once the chat shows (a hidden stack child gets no commands). Host work runs in a timer
150
+ // callback: render may not notify, and request() sets shared state.
151
+ follow(cx) {
152
+ const want = this.pick();
153
+ if (want?.key !== this.key || (want?.terminal?.address ?? null) !== this.address
154
+ || (want?.feed?.updatedAt ?? null) !== (this.snap?.updatedAt ?? null)) {
155
+ if (!this.kicked) {
156
+ this.kicked = true;
157
+ cx.timer.after(1, (cx) => { this.kicked = false; this.tick(cx); });
158
+ }
159
+ }
160
+ if (!this.requesting && this.showing()) {
161
+ const req = shared("gentle-chat.request");
162
+ if (req && typeof req === "object" && Number.isFinite(req.at) && req.at !== this.lastRequest) {
163
+ this.requesting = true;
164
+ cx.timer.after(1, (cx) => { this.requesting = false; this.request(cx); });
165
+ }
166
+ }
167
+ }
168
+
169
+ // The fallback for a missed event, only while the chat shows (S13): a look every LOOK_MS (no
170
+ // file read), and a read every FILE_MS when the session folder has no watch (SAFETY_MS when it
171
+ // has one). It stops once the chat is hidden; render starts it again.
172
+ look(cx) {
173
+ if (this.looking) return;
174
+ this.looking = true;
175
+ try {
176
+ cx.timer.after(LOOK_MS, (cx) => {
177
+ this.looking = false;
178
+ if (!this.showing()) return;
179
+ this.follow(cx);
180
+ if (this.file && Date.now() - this.readAt >= (this.watched ? SAFETY_MS : FILE_MS)) cx.spawn(async (cx) => { await this.load(cx); });
181
+ this.look(cx);
182
+ });
183
+ } catch {
184
+ this.looking = false;
185
+ }
186
+ }
187
+
188
+ // Key commands ("<key>": "gentle-chat.<command>" in keys.json, or `herdr-app do gentle-chat.<command>`;
189
+ // herdr/keys.json binds them): chat, terminal, toggle (Chat ↔ Terminal), perm (opens the
190
+ // permission menu), profiles (opens or closes the profiles menu, S12), mode-<normal|auto|yolo|super-yolo>
191
+ // (the menu's own path: Super-YOLO asks in a dialog first), stop (the agent's turn, as Esc Esc), palette (the Gentle commands palette)
192
+ // request (a palette row: the slash command it names, see gentle-palette), and the minimal
193
+ // view's expand (⌘O: every row open ↔ the minimal view), expand-all and collapse-all (S11).
194
+ commands(cx) {
195
+ cx.spawn(async (cx) => {
196
+ for (;;) {
197
+ const c = String(await nextCommand());
198
+ try {
199
+ const mode = c.startsWith("mode-") ? c.slice(5) : null;
200
+ if (confirmed(c, cx)) { /* a confirm dialog's Confirm */ }
201
+ else if (c === "chat" || c === "terminal") this.go(c, cx);
202
+ else if (c === "toggle") this.go(this.showing() ? "terminal" : "chat", cx);
203
+ else if (c === "perm") this.permOpen = true;
204
+ else if (c === "profiles") { this.profOpen = !this.profOpen; this.profAt = null; }
205
+ else if (c === "stop") this.stop(cx);
206
+ else if (c === "palette") this.palette();
207
+ else if (c === "expand") this.expandToggle(cx);
208
+ else if (c === "expand-all" || c === "collapse-all") this.setExpandAll(c === "expand-all", cx);
209
+ else if (c === "request") this.request(cx);
210
+ else if (mode && PERM.some((m) => m.mode === mode)) this.setMode(mode, cx);
211
+ } catch (e) {
212
+ this.error = String(e?.message ?? e);
213
+ }
214
+ cx.notify();
215
+ }
216
+ });
217
+ }
218
+
219
+ // props.terminal's session, else the session the window is about (snapshot.js targetSession).
220
+ // Herdr's ambient reads belong to a host call, so this runs in render and in timers only.
221
+ pick() {
222
+ const want = props()?.terminal;
223
+ if (want) return allSessions(this.source.feeds).find((s) => s.terminal?.address === want) ?? null;
224
+ return targetSession(this.source.feeds, this.key);
225
+ }
226
+
227
+ tick(cx) {
228
+ this.want = this.pick();
229
+ this.wantFeeds = this.source.feeds;
230
+ cx.spawn(async (cx) => { await this.refreshNow(cx); });
231
+ }
232
+
233
+ // One refresh at a time; a call during one runs it again after, for the newest `want`.
234
+ async refreshNow(cx) {
235
+ if (this.refreshing) { this.reagain = true; return; }
236
+ this.refreshing = true;
237
+ try {
238
+ do {
239
+ this.reagain = false;
240
+ await this.refresh(cx);
241
+ } while (this.reagain);
242
+ } finally {
243
+ this.refreshing = false;
244
+ }
245
+ }
246
+
247
+ // A session that runs outside Herdr app: no terminal to type into or to show.
248
+ elsewhere() {
249
+ return Boolean(this.key) && !this.address;
250
+ }
251
+
252
+ // Finds the session file and snapshot of the shown session and reads what was added.
253
+ async refresh(cx) {
254
+ const s = this.want;
255
+ const key = s?.key ?? null;
256
+ const address = s?.terminal?.address ?? null;
257
+ if (key !== this.key) {
258
+ this.key = key;
259
+ this.cwd = s?.terminal?.cwd ?? s?.feed?.identity?.cwd ?? null;
260
+ this.dir = null;
261
+ this.reset(null);
262
+ this.setSnap(null);
263
+ cx.notify();
264
+ }
265
+ if (address !== this.address) { this.address = address; cx.notify(); }
266
+ if (!s) return;
267
+ // S14: a terminal on another machine. Its session file and snapshot are on that machine and the
268
+ // desktop feed reads this computer's, so nothing is read (a local file of the same folder would
269
+ // be another session): the empty state says where it runs, the Terminal shows it.
270
+ if (machineOf(address)) return;
271
+ // The snapshot names the exact session file; a terminal without one falls back to its folder.
272
+ const exact = s.feed?.identity?.sessionFile;
273
+ const where = typeof exact === "string" && exact.endsWith(".jsonl")
274
+ ? { dir: exact.slice(0, Math.max(exact.lastIndexOf("/"), exact.lastIndexOf("\\"))), file: exact, feed: s.feed }
275
+ : s.terminal ? await sessionFileFor(s.terminal, this.real, this.wantFeeds) : null;
276
+ if (this.key !== key) return;
277
+ if (this.setSnap(where?.feed ?? s.feed ?? null)) cx.notify();
278
+ if (this.settingsOf !== key) await this.readSettings(s, cx);
279
+ if (!where) return;
280
+ if (where.dir !== this.dir) { this.dir = where.dir; this.watch(where.dir, cx); }
281
+ if (where.file !== this.file) { this.reset(where.file); cx.notify(); }
282
+ // Once read, the file's writes come through its watch (S13: a snapshot change reads nothing).
283
+ if (this.file && (this.pos === 0 || this.watched !== this.dir)) await this.load(cx);
284
+ }
285
+
286
+ // The session's hideThinkingBlock (pi settings; ctrl+t in its TUI writes it): read when the
287
+ // session shows and again when one of its two settings files changes (S13: a watch on their
288
+ // folders, not a read per refresh). A missing or unreadable file reads as not set.
289
+ async readSettings(s, cx) {
290
+ this.settingsOf = s.key;
291
+ const dir = s.feed?.identity?.agentDir;
292
+ const cwd = s.feed?.identity?.cwd ?? s.terminal?.cwd ?? null;
293
+ const files = [typeof dir === "string" ? `${dir.replace(/\/+$/, "")}/settings.json` : null,
294
+ typeof cwd === "string" ? `${cwd.replace(/\/+$/, "")}/.pi/settings.json` : null];
295
+ this.settingsFiles = files;
296
+ for (const f of files) if (f) this.watchSettings(f.slice(0, f.lastIndexOf("/")), s.key, cx);
297
+ const text = async (path) => { try { return utf8(await readFile(path)); } catch { return null; } };
298
+ const hide = hideThinkingFrom(files[0] ? await text(files[0]) : null, files[1] ? await text(files[1]) : null);
299
+ if ((this.want?.key ?? null) !== s.key) return;
300
+ if (hide !== this.hideThinking) { this.hideThinking = hide; cx.notify(); }
301
+ }
302
+
303
+ // One watch per settings folder of the shown session; it ends at its next event once another
304
+ // session shows. Only a change of one of the two settings files reads them again.
305
+ watchSettings(dir, key, cx) {
306
+ if (this.settingsDirs.has(dir)) return;
307
+ this.settingsDirs.add(dir);
308
+ cx.spawn(async (cx) => {
309
+ try {
310
+ for (;;) {
311
+ const paths = await watchFolder(dir);
312
+ const files = (this.settingsFiles ?? []).filter(Boolean);
313
+ if (this.key !== key || !files.some((f) => f.startsWith(`${dir}/`))) break;
314
+ if (!Array.isArray(paths) || paths.some((p) => p === dir || files.includes(p))) {
315
+ const s = this.want;
316
+ if (s?.key === key) await this.readSettings(s, cx);
317
+ }
318
+ }
319
+ } catch {
320
+ // no such folder (a project without .pi): read when the session shows
321
+ }
322
+ this.settingsDirs.delete(dir);
323
+ });
324
+ }
325
+
326
+ // Keeps the newest snapshot; true when what it shows changed. A new or cleared question
327
+ // forgets the option picked for the old one.
328
+ setSnap(snap) {
329
+ const before = this.snap;
330
+ if (before?.updatedAt === snap?.updatedAt && before?.identity?.sessionId === snap?.identity?.sessionId) return false;
331
+ this.snap = snap;
332
+ const q = questionKey(snap?.pendingQuestion);
333
+ if (this.answered && this.answered.key !== q) this.answered = null;
334
+ if (q && q !== questionKey(before?.pendingQuestion)) this.stick = true;
335
+ // The composer draws its own placeholder (ui.js composer: one line, truncated with an
336
+ // ellipsis, centred with the clip and Send), so a question only changes its words.
337
+ this.placeholder = q ? PLACEHOLDER_ASK : PLACEHOLDER;
338
+ return true;
339
+ }
340
+
341
+ makeInput(placeholder) {
342
+ this.placeholder = placeholder;
343
+ // No native placeholder: it can neither centre nor end in an ellipsis in a narrow card. One
344
+ // row while the draft is one line (centred in the 42px field), growing with the text.
345
+ this.input = TextareaState.new({ placeholder: "", rows: 1 });
346
+ try { this.input.set_auto_grow(1, 8); } catch { /* an older host keeps one row and scrolls */ }
347
+ this.input.on("focus", (_e, cx) => { this.typing = true; cx.notify(); });
348
+ this.input.on("blur", (_e, cx) => { this.typing = false; cx.notify(); });
349
+ this.input.on("change", (_e, cx) => {
350
+ const before = this.draft;
351
+ this.draft = this.input.value();
352
+ if (this.draft !== before) { this.slashAt = 0; if (this.slashClosed !== this.draft) this.slashClosed = null; }
353
+ cx.notify();
354
+ });
355
+ }
356
+
357
+ reset(file) {
358
+ // The rows opened in a session stay open when it is read again or shown again (S11).
359
+ if (file !== this.file) {
360
+ if (this.file && (this.open.size || this.hunkAt.size)) {
361
+ this.kept.delete(this.file);
362
+ this.kept.set(this.file, { open: this.open, hunkAt: this.hunkAt });
363
+ while (this.kept.size > KEPT) this.kept.delete(this.kept.keys().next().value);
364
+ }
365
+ const back = file ? this.kept.get(file) : null;
366
+ this.open = back?.open ?? new Map();
367
+ this.hunkAt = back?.hunkAt ?? new Map();
368
+ }
369
+ this.feed = createFeed();
370
+ this.file = file;
371
+ this.pos = 0;
372
+ this.start = 0;
373
+ this.size = 0;
374
+ this.back = 1;
375
+ this.limit = PAGE;
376
+ this.stick = true;
377
+ this.error = null;
378
+ }
379
+
380
+ // Watches the session folder. With the snapshot's exact file, only a write to that file reads
381
+ // (S13: the other sessions of the folder write there too); without one (an older Gentle Shell,
382
+ // found by folder) any change looks again, since a new session file appears there.
383
+ watch(dir, cx) {
384
+ if (this.watched === dir) return;
385
+ this.watched = dir;
386
+ cx.spawn(async (cx) => {
387
+ try {
388
+ while (this.watched === dir) {
389
+ const paths = await watchFolder(dir);
390
+ if (this.watched !== dir) break;
391
+ const file = this.file;
392
+ if (!file || typeof this.snap?.identity?.sessionFile !== "string") { await this.refreshNow(cx); continue; }
393
+ const name = file.slice(file.lastIndexOf("/") + 1);
394
+ if (!Array.isArray(paths) || paths.some((p) => p === file || p === dir || String(p).endsWith(`/${name}`))) await this.load(cx);
395
+ }
396
+ } catch {
397
+ if (this.watched === dir) this.watched = null; // the fallback look reads it while shown
398
+ }
399
+ });
400
+ }
401
+
402
+ // A session with a snapshot starts from its tail (S13): the snapshot carries the header's facts
403
+ // (cost, model, name), so the history before the tail is needed only to scroll back.
404
+ useTail() {
405
+ return Boolean(this.snap);
406
+ }
407
+
408
+ // "Show earlier": the drawn entries go back PAGE more; once every read entry is drawn, one more
409
+ // tail of the file is read (the read part is rebuilt from the new start; opened rows stay).
410
+ earlier(from, cx) {
411
+ this.limit += PAGE;
412
+ this.pinned = false;
413
+ if (from <= 0 && this.start > 0 && this.file) {
414
+ this.back += 1;
415
+ this.pos = 0;
416
+ cx.spawn(async (cx) => { await this.load(cx); });
417
+ }
418
+ cx.notify();
419
+ }
420
+
421
+ // Reads only the complete lines added since `pos` (a long session: first its tail, readTail).
422
+ // The file only grows; if it shrank, start over. A big file is read through `sh`, which gives
423
+ // its size and only the new bytes; a small one is read whole and sliced (session.js).
424
+ async load(cx) {
425
+ if (this.loading) { this.again = true; return; }
426
+ this.loading = true;
427
+ const file = this.file;
428
+ try {
429
+ do {
430
+ this.again = false;
431
+ this.readAt = Date.now();
432
+ const before = this.feed.items.length;
433
+ if (this.pos === 0 && this.useTail()) {
434
+ const first = !this.feed.items.length;
435
+ const t = await readTail(file, TAIL * this.back, LINES * this.back, TAIL_MAX * this.back);
436
+ if (file !== this.file) return;
437
+ if (!t) continue;
438
+ const feed = createFeed();
439
+ ingest(feed, t.text);
440
+ this.feed = feed;
441
+ this.start = t.start;
442
+ this.pos = t.end;
443
+ this.size = t.size;
444
+ if (first) this.stick = true;
445
+ cx.notify();
446
+ continue;
447
+ }
448
+ const { text, end, more, size } = await readAfter(file, this.pos, undefined, this.size > EXEC_ABOVE);
449
+ if (file !== this.file) return;
450
+ if (Number.isFinite(size)) this.size = size;
451
+ if (text === null) {
452
+ if (this.pos > 0) { this.reset(file); this.again = true; }
453
+ continue;
454
+ }
455
+ if (text) {
456
+ ingest(this.feed, text);
457
+ this.pos = end;
458
+ if (this.feed.items.length !== before) this.stick = true;
459
+ cx.notify();
460
+ }
461
+ if (more) this.again = true;
462
+ } while (this.again);
463
+ } finally {
464
+ this.loading = false;
465
+ }
466
+ }
467
+
468
+ send(cx) {
469
+ // Enter on the "/" menu runs (or completes) the selected command.
470
+ if (this.slashMenu()) { this.slashPick(this.slashAt, false, cx); return; }
471
+ const text = this.input.value().trim();
472
+ const address = this.address;
473
+ if (!text || !this.key || this.sending) return;
474
+ if (!address && !this.snap) { this.error = "This session publishes no snapshot; it takes no messages from here."; cx.notify(); return; }
475
+ const pq = this.snap?.pendingQuestion;
476
+ // "Something else…" was picked: this text is the answer to that question.
477
+ const typedAnswer = this.answered?.custom && pq && this.answered.key === questionKey(pq) ? pq : null;
478
+ // A slash command goes to the TUI as typed; one whose result is a TUI screen (or one this
479
+ // session does not list) shows the Terminal.
480
+ if (!typedAnswer && text.startsWith("/")) {
481
+ const name = text.slice(1).split(/\s/)[0];
482
+ const known = (this.snap?.commands?.items ?? []).find((c) => c.name === name);
483
+ this.runCommand(text, known ? known.terminal !== false : true, cx);
484
+ return;
485
+ }
486
+ // An open question or prompt would take the typed text (and its Enter) as its answer.
487
+ if (!typedAnswer) {
488
+ const busy = terminalFree(this.snap);
489
+ if (busy) { this.error = busy; cx.notify(); return; }
490
+ }
491
+ this.sending = true;
492
+ this.error = null;
493
+ this.notice = null;
494
+ this.input.set_value("");
495
+ cx.notify();
496
+ cx.spawn(async (cx) => {
497
+ try {
498
+ if (typedAnswer) {
499
+ await this.pressAnswer(cx, address, typedAnswer, { text });
500
+ this.sending = false;
501
+ cx.notify();
502
+ return;
503
+ }
504
+ if (!address) {
505
+ // Outside Herdr app: the session's inbox types it into its editor (T11 send_prompt).
506
+ const r = await sendAction(cx, this.snap, "send_prompt", { text });
507
+ if (!r.ok) { this.error = promptRefusal(r) ?? errorText(r); this.input.set_value(text); }
508
+ else if (r.data?.queued && r.data?.after === "compaction") this.notice = "Queued until compaction ends";
509
+ else if (r.data?.queued) this.notice = "Queued: the agent reads it after its current step, as Enter does in the TUI.";
510
+ } else {
511
+ const r = await hc(["send", address, text]);
512
+ if (r.code !== 0) { this.error = (r.stderr || r.stdout || "hc send failed").trim(); this.input.set_value(text); }
513
+ }
514
+ } catch (e) {
515
+ this.error = String(e?.message ?? e);
516
+ this.input.set_value(text);
517
+ }
518
+ this.sending = false;
519
+ this.stick = true;
520
+ cx.notify();
521
+ });
522
+ }
523
+
524
+ // Picks option `i` of the open question (a click, or keys 1–N).
525
+ answer(i, cx) {
526
+ const pq = this.snap?.pendingQuestion;
527
+ const address = this.address;
528
+ if (!pq || !this.key || this.answered) return;
529
+ const o = askOptions(pq)[i];
530
+ if (!o) return;
531
+ this.answered = { key: questionKey(pq), index: i, custom: o.custom };
532
+ this.error = null;
533
+ cx.notify();
534
+ if (o.custom) { this.input.focus(); return; }
535
+ cx.spawn(async (cx) => { await this.pressAnswer(cx, address, pq, { option: i }); });
536
+ }
537
+
538
+ // Answers the open question like the person would in the terminal: the session first checks
539
+ // that it is still the open one (by its toolCallId) and names the keys its real list takes
540
+ // (the lists ignore digits); then those keys, and a typed answer, go to the terminal.
541
+ async pressAnswer(cx, address, pq, answer) {
542
+ try {
543
+ if (!pq.toolCallId) throw new Error(address ? "Answer it in the Terminal view." : "Answer it in that session's terminal.");
544
+ if (!address) {
545
+ // Outside Herdr app: the question's own list takes the answer (T11, answer_question via the
546
+ // session); the session checks it is still the open one, as for the keys.
547
+ const r = await sendAction(cx, this.snap, "answer_question", { toolCallId: pq.toolCallId, ...answer, via: "session" });
548
+ if (!r.ok) throw new Error(r.error?.code === "invalid_action" ? "Answer it in that session's terminal: it started before desktop answers." : errorText(r));
549
+ cx.notify();
550
+ return;
551
+ }
552
+ const r = await sendAction(cx, this.snap, "answer_question", { toolCallId: pq.toolCallId, ...answer });
553
+ if (!r.ok) {
554
+ if (r.error?.code === "answer_in_terminal") this.later(cx, () => this.toTerminal());
555
+ throw new Error(errorText(r));
556
+ }
557
+ if (!safeKeys(r.data.keys)) throw new Error("The session answered keys this view does not press.");
558
+ // The question may have closed or changed since the session answered: read it again and
559
+ // press nothing unless it is still the same one.
560
+ const still = async () => {
561
+ const fresh = await readSnapshot(this.snap);
562
+ if (questionKey(fresh?.pendingQuestion) !== questionKey(pq)) throw new Error("The question changed before the answer was sent; nothing was pressed.");
563
+ };
564
+ await still();
565
+ const k = await hc(["keys", address, ...r.data.keys]);
566
+ if (k.code !== 0) throw new Error((k.stderr || k.stdout || "hc keys failed").trim());
567
+ if (answer.text !== undefined) {
568
+ await still();
569
+ const t = await hc(["send", address, answer.text]);
570
+ if (t.code !== 0) throw new Error((t.stderr || t.stdout || "hc send failed").trim());
571
+ }
572
+ } catch (err) {
573
+ this.error = String(err?.message ?? err);
574
+ this.answered = null;
575
+ if (answer.text !== undefined && !this.input.value()) this.input.set_value(answer.text);
576
+ }
577
+ cx.notify();
578
+ }
579
+
580
+ // ---- Desktop actions (T7): the person's own authority, through the session's owners ----
581
+
582
+ toTerminal() {
583
+ if (this.elsewhere()) { this.notice = `${ELSEWHERE}.`; return; }
584
+ const { stack, other } = this.stackProps();
585
+ showTerminal(this.address, stack ?? "views", other ?? "main");
586
+ }
587
+
588
+ // Runs `fn` in a host call (a timer callback): Herdr's ambient calls (run, props, setShared)
589
+ // throw after an await in a spawned task.
590
+ later(cx, fn) {
591
+ cx.timer.after(1, () => { try { fn(); } catch (e) { this.error = String(e?.message ?? e); } });
592
+ }
593
+
594
+ // One action at a time per control; the result or refusal shows under the composer.
595
+ act(key, cx, work) {
596
+ if (this.busy) return;
597
+ this.busy = key;
598
+ this.error = null;
599
+ this.notice = null;
600
+ cx.notify();
601
+ cx.spawn(async (cx) => {
602
+ try {
603
+ const line = await work(cx);
604
+ if (line) this.error = line;
605
+ } catch (e) {
606
+ this.error = String(e?.message ?? e);
607
+ }
608
+ this.busy = null;
609
+ cx.notify();
610
+ });
611
+ }
612
+
613
+ // The TUI's own screen for this (its slash command), shown in the Terminal.
614
+ command(key, text, cx) {
615
+ if (this.elsewhere()) { this.error = NO_COMMANDS; cx.notify(); return; }
616
+ this.act(key, cx, (cx) => tuiCommand(this.address, this.snap, text, () => this.later(cx, () => this.toTerminal())));
617
+ }
618
+
619
+ // A slash command from the composer, its "/" menu or the palette: typed into the TUI like the
620
+ // person would. `terminal`: its result is a TUI screen, so the Terminal shows; otherwise the
621
+ // chat stays (a prompt template's turn, /new, /name …). The draft comes back if it failed.
622
+ runCommand(text, terminal, cx) {
623
+ if (this.busy) return;
624
+ if (this.elsewhere()) { this.promptCommand(text, cx); return; }
625
+ this.input.set_value("");
626
+ this.draft = "";
627
+ this.act("command", cx, async (cx) => {
628
+ // Herdr's ambient calls (run, props) only work inside a host call: after the await, the
629
+ // switch runs from a timer callback.
630
+ const line = await tuiCommand(this.address, this.snap, text, terminal ? () => this.later(cx, () => this.toTerminal()) : null);
631
+ if (line) { if (!this.input.value()) { this.input.set_value(text); this.draft = text; } return line; }
632
+ this.stick = true;
633
+ if (!terminal) this.notice = `${text.split(/\s/)[0]} sent to the session.`;
634
+ return null;
635
+ });
636
+ }
637
+
638
+ // Outside Herdr app (T11): a prompt template or a skill becomes the prompt it expands to, through
639
+ // the session's inbox; every other command is TUI code and stays in that session's terminal.
640
+ promptCommand(text, cx) {
641
+ const name = text.slice(1).split(/\s/)[0];
642
+ const known = (this.snap?.commands?.items ?? []).find((c) => c.name === name);
643
+ if (known?.source !== "prompt" && known?.source !== "skill") { this.error = NO_COMMANDS; cx.notify(); return; }
644
+ this.input.set_value("");
645
+ this.draft = "";
646
+ this.act("command", cx, async (cx) => {
647
+ const r = await sendAction(cx, this.snap, "send_prompt", { text });
648
+ if (!r.ok) { if (!this.input.value()) { this.input.set_value(text); this.draft = text; } return promptRefusal(r) ?? errorText(r); }
649
+ this.stick = true;
650
+ this.notice = `${text.split(/\s/)[0]} sent to the session.`;
651
+ return null;
652
+ });
653
+ }
654
+
655
+ // ---- The "/" menu (T10): the session's commands, filtered as you type ----
656
+
657
+ slashMenu() {
658
+ if (!this.typing || this.slashClosed === this.draft) return null;
659
+ const items = slashMatches(this.snap?.commands?.items, this.draft);
660
+ if (!items?.length) return null;
661
+ this.slashAt = Math.max(0, Math.min(this.slashAt, items.length - 1));
662
+ return { items, at: this.slashAt };
663
+ }
664
+
665
+ slashMove(step, cx) {
666
+ const m = this.slashMenu();
667
+ if (!m) return;
668
+ this.slashAt = (m.at + step + m.items.length) % m.items.length;
669
+ cx.notify();
670
+ }
671
+
672
+ // Tab (or a command that needs an argument) puts "/name " in the composer; Enter and a click
673
+ // run it.
674
+ slashPick(i, complete, cx) {
675
+ const c = this.slashMenu()?.items[i];
676
+ if (!c) return;
677
+ if (complete || c.args) {
678
+ this.setDraft(`/${c.name} `);
679
+ cx.notify();
680
+ return;
681
+ }
682
+ this.runCommand(`/${c.name}`, c.terminal !== false, cx);
683
+ }
684
+
685
+ // Puts `text` in the composer with the caret at its end, and the keyboard on it.
686
+ setDraft(text) {
687
+ this.input.set_value(text);
688
+ this.draft = text;
689
+ try { this.input.set_selected_range({ start: text.length, end: text.length }); } catch { /* caret stays */ }
690
+ this.input.focus();
691
+ }
692
+
693
+ // ---- Stop the agent (T10): the TUI's Esc Esc, through the session's own abort ----
694
+
695
+ working() {
696
+ const agent = this.address ? agents().find((a) => a.address === this.address) : null;
697
+ return agent?.status === "working" || this.snap?.activity?.state === "working";
698
+ }
699
+
700
+ stop(cx) {
701
+ this.escAt = 0;
702
+ this.act("stop", cx, async (cx) => {
703
+ const r = await sendAction(cx, this.snap, "abort_turn", {});
704
+ if (!r.ok) return errorText(r);
705
+ this.notice = "Stopped the agent's turn.";
706
+ return null;
707
+ });
708
+ }
709
+
710
+ // Esc: closes the "/" menu; while the agent works, a second Esc within a second stops it.
711
+ escape(cx) {
712
+ if (this.slashMenu()) { this.slashClosed = this.draft; cx.notify(); return; }
713
+ if (!this.working()) { cx.propagate(); return; }
714
+ const now = Date.now();
715
+ if (this.escAt && now - this.escAt <= ESC_MS) { this.stop(cx); return; }
716
+ this.escAt = now;
717
+ this.notice = ESC_NOTICE;
718
+ cx.notify();
719
+ cx.timer.after(ESC_MS, (cx) => {
720
+ if (this.notice === ESC_NOTICE) this.notice = null;
721
+ this.escAt = 0;
722
+ cx.notify();
723
+ });
724
+ }
725
+
726
+ // ---- The Gentle commands palette (gentle-palette) ----
727
+
728
+ palette() {
729
+ // The palette is about this chat's session, not whichever pane had the keyboard.
730
+ setShared("gentle-palette.terminal", { address: this.address, key: this.key, at: Date.now() });
731
+ run("mod.open", { name: "gentle-palette" });
732
+ }
733
+
734
+ // A palette request (gentle-palette): a permission mode, or a slash command. Consume-once: it is
735
+ // cleared when taken, and one older than REQUEST_MS is dropped. Without the session's snapshot
736
+ // yet it waits for the next render or look (follow).
737
+ request(cx) {
738
+ const req = shared("gentle-chat.request");
739
+ if (!req || typeof req !== "object" || !Number.isFinite(req.at) || req.at === this.lastRequest) return;
740
+ if (Math.abs(Date.now() - req.at) > REQUEST_MS) { setShared("gentle-chat.request", null); return; }
741
+ if (req.kind === "expand") {
742
+ this.lastRequest = req.at;
743
+ setShared("gentle-chat.request", null);
744
+ this.setExpandAll(Boolean(req.expanded), cx);
745
+ return;
746
+ }
747
+ if (!this.snap || !this.key) return;
748
+ this.lastRequest = req.at;
749
+ setShared("gentle-chat.request", null);
750
+ if (req.kind === "mode") {
751
+ if (PERM.some((m) => m.mode === req.mode)) this.setMode(req.mode, cx);
752
+ return;
753
+ }
754
+ if (req.kind === "profile") {
755
+ if (typeof req.name === "string" && req.name) this.applyProfile(req.name, cx);
756
+ return;
757
+ }
758
+ if (typeof req.text !== "string" || !req.text.startsWith("/")) return;
759
+ if (req.args) {
760
+ // It needs an argument: the chat shows with "/name " in the composer.
761
+ this.go("chat", cx);
762
+ this.setDraft(`${req.text} `);
763
+ return;
764
+ }
765
+ if (!req.terminal) this.go("chat", cx);
766
+ this.runCommand(req.text, Boolean(req.terminal), cx);
767
+ }
768
+
769
+ // The permission menu: the same owner as /gentle:mode decides. Super-YOLO asks first, with the
770
+ // TUI's own words for it.
771
+ setMode(mode, cx) {
772
+ this.permOpen = false;
773
+ cx.notify();
774
+ if (mode === this.snap?.permission?.mode) return;
775
+ const go = (cx) => this.act("perm", cx, async (cx) => {
776
+ const r = await sendAction(cx, this.snap, "set_permission_mode", { mode });
777
+ return r.ok ? null : errorText(r);
778
+ });
779
+ if (mode !== "super-yolo") return go(cx);
780
+ confirm("gentle-chat", {
781
+ title: "Switch this session to Super-YOLO?",
782
+ detail: "The agent runs ordinary and destructive shell work without asking; private paths stay blocked and consent prompts remain. Only this session changes. The session accepts it only while its agent, jobs and subagents are idle.",
783
+ }, go);
784
+ }
785
+
786
+ // S12: "Use in this session" through the session's own /gentle:profiles apply (apply_profile).
787
+ // When the owner shows a dialog (the routing it changes), the same words show here, and Confirm
788
+ // sends its token back; the owner checks it against what it would show now.
789
+ applyProfile(name, cx, confirmation = null) {
790
+ this.profOpen = false;
791
+ cx.notify();
792
+ if (!confirmation && name === this.snap?.profiles?.active) { this.notice = `"${name}" is already this session's profile.`; return; }
793
+ this.act("profile", cx, async (cx) => {
794
+ const r = await sendAction(cx, this.snap, "apply_profile", confirmation ? { name, confirmation } : { name });
795
+ if (!r.ok) return PROFILE_REFUSALS[r.error?.code] ?? errorText(r);
796
+ const d = r.data ?? {};
797
+ const said = (Array.isArray(d.notes) ? d.notes : []).map((n) => n?.text).filter(Boolean).at(-1);
798
+ if (d.status === "confirmation_required" && typeof d.confirmation?.token === "string") {
799
+ const c = d.confirmation;
800
+ this.later(cx, () => confirm("gentle-chat", {
801
+ title: c.title || `Use "${name}" in this session?`,
802
+ detail: c.message || `Routes this session's agents with the "${name}" profile.`,
803
+ height: 280,
804
+ }, (cx) => this.applyProfile(name, cx, c.token)));
805
+ return null;
806
+ }
807
+ if (d.status === "applied") { this.notice = said || `"${name}" is now this session's profile.`; return null; }
808
+ return said || `"${name}" was not applied.`;
809
+ });
810
+ }
811
+
812
+ stopAgent(id, cx) {
813
+ this.act(`stop-${id}`, cx, async (cx) => {
814
+ const r = await sendAction(cx, this.snap, "cancel_subagent", { id });
815
+ return r.ok ? null : errorText(r);
816
+ });
817
+ }
818
+
819
+ // Pastes the clipboard (an image, or files on macOS) into the session's draft, as Ctrl+V in the
820
+ // terminal does; it goes with the next message sent.
821
+ attach(cx) {
822
+ this.act("attach", cx, async () => {
823
+ const address = this.address;
824
+ if (this.elsewhere()) return "Attachments are pasted in that session's terminal.";
825
+ if (!address) return "No Gentle Shell terminal.";
826
+ const busy = terminalFree(this.snap);
827
+ if (busy) return busy;
828
+ const r = await hc(["keys", address, "ctrl+v"]);
829
+ if (r.code !== 0) return (r.stderr || r.stdout || "hc keys failed").trim();
830
+ this.notice = "Clipboard pasted into the session's draft; it goes with your next message.";
831
+ return null;
832
+ });
833
+ }
834
+
835
+ // "Open in Changes": the inspector shows its Changes tab with this file marked.
836
+ openInChanges(path, cx) {
837
+ setShared("gentle-inspector.reveal", { tab: "changes", path: String(path ?? ""), at: Date.now() });
838
+ cx.notify();
839
+ }
840
+
841
+ stackProps() {
842
+ return props() ?? {};
843
+ }
844
+
845
+ // In a layout stack: whether the chat is the shown child.
846
+ showing() {
847
+ const { stack, self } = this.stackProps();
848
+ if (!stack) return true;
849
+ const find = (node) => (node?.id === stack ? node : (node?.children ?? []).map(find).find(Boolean));
850
+ const node = find(layout());
851
+ return (node?.active ?? node?.children?.[0]?.id) === self;
852
+ }
853
+
854
+ go(which, cx) {
855
+ // A session outside Herdr app has no Terminal here: say where it runs instead.
856
+ if (which === "terminal" && this.elsewhere()) { this.notice = `${ELSEWHERE}.`; cx?.notify?.(); return; }
857
+ const { stack, self, other } = this.stackProps();
858
+ if (stack) run("layout.select", { stack, child: which === "chat" ? self : other });
859
+ }
860
+
861
+ // A row's state: its own flip, else ⌘O's "every row open", else its default (the minimal view).
862
+ isOpen(id, def) {
863
+ return this.open.has(id) ? this.open.get(id) : this.expandAll || def;
864
+ }
865
+
866
+ toggle(id, def, cx) {
867
+ this.open.set(id, !this.isOpen(id, def));
868
+ this.pinned = false; // the row stays where it was clicked
869
+ cx.notify();
870
+ }
871
+
872
+ // ⌘O, "Expand all / Collapse all": every row of every session follows, like the TUI's ctrl+o;
873
+ // the rows flipped one by one start over.
874
+ setExpandAll(on, cx) {
875
+ this.expandAll = Boolean(on);
876
+ this.open = new Map();
877
+ this.kept = new Map();
878
+ cx.notify();
879
+ }
880
+
881
+ expandToggle(cx) {
882
+ const now = Date.now();
883
+ if (now - this.expandAt < DOUBLE_MS) return;
884
+ this.expandAt = now;
885
+ this.setExpandAll(!this.expandAll, cx);
886
+ }
887
+
888
+ key(e, cx) {
889
+ if (this.typing || e.modifiers?.platform || e.modifiers?.control || e.modifiers?.alt) return;
890
+ const pq = this.snap?.pendingQuestion;
891
+ const n = Number(e.key);
892
+ if (pq && Number.isInteger(n) && n >= 1 && n <= askOptions(pq).length) { this.answer(n - 1, cx); cx.stop_propagation(); }
893
+ }
894
+
895
+ render(cx) {
896
+ try { this.follow(cx); this.look(cx); } catch { /* the fallback look keeps it fresh */ }
897
+ const p = palette(theme());
898
+ const agent = this.address ? agents().find((a) => a.address === this.address) : null;
899
+ this.agentInfo = agent;
900
+ const working = agent?.status === "working" || this.snap?.activity?.state === "working";
901
+ const list = entries(this.feed.items);
902
+ const from = Math.max(0, list.length - this.limit);
903
+ const rows = [];
904
+ if (from > 0 || this.start > 0) {
905
+ rows.push(div().flex_none().self_center().child(div().id("earlier").px(10).py(3).rounded(R.inner).text_size(12).text_color(p.muted)
906
+ .cursor_pointer().hover((s) => s.bg(p.selected))
907
+ .on_click((_e, cx) => this.earlier(from, cx))
908
+ .child(from > 0 ? `Show earlier (${from} ${from === 1 ? "message" : "messages"})` : "Show earlier messages")));
909
+ }
910
+ for (let i = from; i < list.length; i++) rows.push(lane(entry(this, p, list[i], working && i === list.length - 1)));
911
+ const pq = this.snap?.pendingQuestion;
912
+ if (pq) rows.push(lane(askCard(this, p, pq)));
913
+ else {
914
+ // S15: "Working · 2 agents" while the turn runs, "Waiting on 2 agents" once it ended while its
915
+ // background subagents or jobs still run.
916
+ const live = this.snap ? liveState(this.snap) : null;
917
+ const busy = live && (live.status === "working" || live.status === "waiting");
918
+ if (working || busy) rows.push(lane(stateLabel(p, "work", busy ? live.label : "Working")));
919
+ }
920
+ const empty = !rows.length;
921
+ // Pinned to the newest entry: new items pin it, scrolling up unpins it. scroll_to_item
922
+ // reveals a child with the least scroll, so the target is a 1px sentinel after the last row,
923
+ // asked again whenever the last row changes height (markdown settles a frame later).
924
+ if (this.stick) { this.pinned = true; this.stick = false; }
925
+ if (this.pinned && rows.length) {
926
+ this.scroll.scroll_to_item(rows.length);
927
+ const n = rows.length - 1;
928
+ rows[n] = rows[n].on_size_change((size, cx) => {
929
+ if (this.pinned && Math.abs((this.lastH ?? 0) - size.height) >= 1) { this.lastH = size.height; cx.notify(); }
930
+ });
931
+ }
932
+ rows.push(div().id("log-end").flex_none().w_full().h(1));
933
+
934
+ return v_flex().id("root").size_full().min_h(0).bg(p.background).text_color(p.text).text_size(13).line_height(1.5)
935
+ .font_family(sans()).rounded(R.window - 1)
936
+ .key_context("GentleChat").track_focus(this.focus)
937
+ .on_key_down((e, cx) => this.key(e, cx))
938
+ .on_action("gentle_chat_terminal", (_e, cx) => this.go("terminal", cx))
939
+ .on_action("gentle_chat_palette", () => this.palette())
940
+ .on_action("gentle_chat_expand", (_e, cx) => this.expandToggle(cx))
941
+ .on_action("gentle_chat_escape", (_e, cx) => this.escape(cx))
942
+ .child(header(this, p))
943
+ .child(empty ? this.empty(p) : v_flex().id("log").flex_1().min_h(0).overflow_y_scrollbar().track_scroll(this.scroll)
944
+ .pt(18).pb(7).gap(14) // .log padding-bottom 22 = gap 14 + the 1px sentinel + 7
945
+ .on_scroll_wheel((e) => { if ((e.delta?.y ?? 0) > 0) this.pinned = false; })
946
+ .on_mouse_down("left", () => this.focus.focus())
947
+ .children(rows))
948
+ .child(composer(this, p, pq));
949
+ }
950
+
951
+ // No conversation yet (the artboard has no such state): a calm block in the middle of the
952
+ // log, in the design's type: the mark in faint, a 14px semibold line, a 12.5px muted line.
953
+ empty(p) {
954
+ const machine = machineOf(this.address);
955
+ const [title, about] = machine
956
+ ? [`Runs on ${machine}`, `Herdr shows its state and its Terminal (⌘J). Its conversation and desktop feed stay on ${machine}: this window reads this computer's.`]
957
+ : !this.key
958
+ ? ["No Gentle Shell session", "Start one with + in the tab bar, or run gentle-shell in a terminal."]
959
+ : !this.file
960
+ ? ["Waiting for the first message", "This session has not written its conversation yet."]
961
+ : ["No messages yet", this.address ? "Type below to start. ⌘J shows the Terminal." : "Type below to start."];
962
+ return v_flex().id("log").flex_1().min_h(0).items_center().justify_center().gap(6).px(28).pb(40)
963
+ .on_mouse_down("left", () => this.focus.focus())
964
+ .child(icon("mark", 26).text_color(p.faint).mb(4))
965
+ .child(div().text_size(14).font_semibold().text_color(p.text).child(title))
966
+ .child(div().text_size(12.5).text_color(p.muted).text_center().child(about));
967
+ }
968
+ }