@esso0428/pi-subagents 0.17.5 → 0.17.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (263) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/CONTRIBUTING.md +4 -0
  3. package/README.md +1 -1
  4. package/dist/abortable.d.ts +13 -0
  5. package/dist/abortable.d.ts.map +1 -0
  6. package/dist/abortable.js +43 -0
  7. package/dist/abortable.js.map +1 -0
  8. package/dist/agent-color.d.ts +36 -0
  9. package/dist/agent-color.d.ts.map +1 -0
  10. package/dist/agent-color.js +124 -0
  11. package/dist/agent-color.js.map +1 -0
  12. package/dist/agent-file-toggle.d.ts +126 -0
  13. package/dist/agent-file-toggle.d.ts.map +1 -0
  14. package/dist/agent-file-toggle.js +259 -0
  15. package/dist/agent-file-toggle.js.map +1 -0
  16. package/dist/agent-history.d.ts +4 -0
  17. package/dist/agent-history.d.ts.map +1 -1
  18. package/dist/agent-history.js +47 -1
  19. package/dist/agent-history.js.map +1 -1
  20. package/dist/agent-manager.d.ts +370 -56
  21. package/dist/agent-manager.d.ts.map +1 -1
  22. package/dist/agent-manager.js +1123 -409
  23. package/dist/agent-manager.js.map +1 -1
  24. package/dist/agent-runner.d.ts +100 -10
  25. package/dist/agent-runner.d.ts.map +1 -1
  26. package/dist/agent-runner.js +166 -21
  27. package/dist/agent-runner.js.map +1 -1
  28. package/dist/agent-types.d.ts +57 -5
  29. package/dist/agent-types.d.ts.map +1 -1
  30. package/dist/agent-types.js +164 -32
  31. package/dist/agent-types.js.map +1 -1
  32. package/dist/child-context.d.ts +3 -0
  33. package/dist/child-context.d.ts.map +1 -0
  34. package/dist/child-context.js +13 -0
  35. package/dist/child-context.js.map +1 -0
  36. package/dist/cross-extension-rpc.d.ts +23 -3
  37. package/dist/cross-extension-rpc.d.ts.map +1 -1
  38. package/dist/cross-extension-rpc.js +79 -17
  39. package/dist/cross-extension-rpc.js.map +1 -1
  40. package/dist/custom-agents.d.ts +38 -1
  41. package/dist/custom-agents.d.ts.map +1 -1
  42. package/dist/custom-agents.js +164 -12
  43. package/dist/custom-agents.js.map +1 -1
  44. package/dist/index.d.ts +34 -0
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +1908 -495
  47. package/dist/index.js.map +1 -1
  48. package/dist/invocation-config.d.ts +87 -2
  49. package/dist/invocation-config.d.ts.map +1 -1
  50. package/dist/invocation-config.js +71 -3
  51. package/dist/invocation-config.js.map +1 -1
  52. package/dist/mention-clone.d.ts +88 -0
  53. package/dist/mention-clone.d.ts.map +1 -0
  54. package/dist/mention-clone.js +154 -0
  55. package/dist/mention-clone.js.map +1 -0
  56. package/dist/mention.d.ts +82 -0
  57. package/dist/mention.d.ts.map +1 -0
  58. package/dist/mention.js +132 -0
  59. package/dist/mention.js.map +1 -0
  60. package/dist/model-resolver.d.ts +17 -0
  61. package/dist/model-resolver.d.ts.map +1 -1
  62. package/dist/model-resolver.js +15 -0
  63. package/dist/model-resolver.js.map +1 -1
  64. package/dist/model-scope.d.ts +50 -0
  65. package/dist/model-scope.d.ts.map +1 -0
  66. package/dist/model-scope.js +49 -0
  67. package/dist/model-scope.js.map +1 -0
  68. package/dist/nested-tools.d.ts +57 -0
  69. package/dist/nested-tools.d.ts.map +1 -0
  70. package/dist/nested-tools.js +301 -0
  71. package/dist/nested-tools.js.map +1 -0
  72. package/dist/output-file.d.ts +22 -3
  73. package/dist/output-file.d.ts.map +1 -1
  74. package/dist/output-file.js +58 -7
  75. package/dist/output-file.js.map +1 -1
  76. package/dist/prompts.d.ts +23 -0
  77. package/dist/prompts.d.ts.map +1 -1
  78. package/dist/prompts.js +20 -2
  79. package/dist/prompts.js.map +1 -1
  80. package/dist/schedule.d.ts.map +1 -1
  81. package/dist/schedule.js +36 -15
  82. package/dist/schedule.js.map +1 -1
  83. package/dist/settings.d.ts +228 -2
  84. package/dist/settings.d.ts.map +1 -1
  85. package/dist/settings.js +94 -0
  86. package/dist/settings.js.map +1 -1
  87. package/dist/status-note.d.ts +49 -1
  88. package/dist/status-note.d.ts.map +1 -1
  89. package/dist/status-note.js +62 -1
  90. package/dist/status-note.js.map +1 -1
  91. package/dist/structured-output.d.ts +62 -0
  92. package/dist/structured-output.d.ts.map +1 -0
  93. package/dist/structured-output.js +113 -0
  94. package/dist/structured-output.js.map +1 -0
  95. package/dist/types.d.ts +176 -10
  96. package/dist/types.d.ts.map +1 -1
  97. package/dist/ui/agent-mention.d.ts +83 -0
  98. package/dist/ui/agent-mention.d.ts.map +1 -0
  99. package/dist/ui/agent-mention.js +188 -0
  100. package/dist/ui/agent-mention.js.map +1 -0
  101. package/dist/ui/agent-widget.d.ts +96 -75
  102. package/dist/ui/agent-widget.d.ts.map +1 -1
  103. package/dist/ui/agent-widget.js +397 -420
  104. package/dist/ui/agent-widget.js.map +1 -1
  105. package/dist/ui/conversation-blocks.d.ts.map +1 -1
  106. package/dist/ui/conversation-blocks.js +6 -0
  107. package/dist/ui/conversation-blocks.js.map +1 -1
  108. package/dist/ui/conversation-timeline.d.ts +10 -2
  109. package/dist/ui/conversation-timeline.d.ts.map +1 -1
  110. package/dist/ui/conversation-timeline.js +130 -23
  111. package/dist/ui/conversation-timeline.js.map +1 -1
  112. package/dist/ui/conversation-viewer.d.ts +20 -5
  113. package/dist/ui/conversation-viewer.d.ts.map +1 -1
  114. package/dist/ui/conversation-viewer.js +274 -73
  115. package/dist/ui/conversation-viewer.js.map +1 -1
  116. package/dist/ui/fleet-list.d.ts +198 -0
  117. package/dist/ui/fleet-list.d.ts.map +1 -0
  118. package/dist/ui/fleet-list.js +487 -0
  119. package/dist/ui/fleet-list.js.map +1 -0
  120. package/dist/ui/schedule-menu.d.ts.map +1 -1
  121. package/dist/ui/schedule-menu.js +6 -7
  122. package/dist/ui/schedule-menu.js.map +1 -1
  123. package/dist/ui/select-item.d.ts +28 -0
  124. package/dist/ui/select-item.d.ts.map +1 -0
  125. package/dist/ui/select-item.js +35 -0
  126. package/dist/ui/select-item.js.map +1 -0
  127. package/dist/ui/workflow-card.d.ts +176 -0
  128. package/dist/ui/workflow-card.d.ts.map +1 -0
  129. package/dist/ui/workflow-card.js +333 -0
  130. package/dist/ui/workflow-card.js.map +1 -0
  131. package/dist/ui/workflow-dialog.d.ts +306 -0
  132. package/dist/ui/workflow-dialog.d.ts.map +1 -0
  133. package/dist/ui/workflow-dialog.js +844 -0
  134. package/dist/ui/workflow-dialog.js.map +1 -0
  135. package/dist/ui/workflow-menu.d.ts +61 -0
  136. package/dist/ui/workflow-menu.d.ts.map +1 -0
  137. package/dist/ui/workflow-menu.js +148 -0
  138. package/dist/ui/workflow-menu.js.map +1 -0
  139. package/dist/usage.d.ts +86 -1
  140. package/dist/usage.d.ts.map +1 -1
  141. package/dist/usage.js +72 -1
  142. package/dist/usage.js.map +1 -1
  143. package/dist/workflow/collisions.d.ts +96 -0
  144. package/dist/workflow/collisions.d.ts.map +1 -0
  145. package/dist/workflow/collisions.js +89 -0
  146. package/dist/workflow/collisions.js.map +1 -0
  147. package/dist/workflow/entry.d.ts +33 -0
  148. package/dist/workflow/entry.d.ts.map +1 -0
  149. package/dist/workflow/entry.js +30 -0
  150. package/dist/workflow/entry.js.map +1 -0
  151. package/dist/workflow/host.d.ts +63 -0
  152. package/dist/workflow/host.d.ts.map +1 -0
  153. package/dist/workflow/host.js +363 -0
  154. package/dist/workflow/host.js.map +1 -0
  155. package/dist/workflow/journal.d.ts +98 -0
  156. package/dist/workflow/journal.d.ts.map +1 -0
  157. package/dist/workflow/journal.js +121 -0
  158. package/dist/workflow/journal.js.map +1 -0
  159. package/dist/workflow/json-schema.d.ts +52 -0
  160. package/dist/workflow/json-schema.d.ts.map +1 -0
  161. package/dist/workflow/json-schema.js +112 -0
  162. package/dist/workflow/json-schema.js.map +1 -0
  163. package/dist/workflow/meta.d.ts +68 -0
  164. package/dist/workflow/meta.d.ts.map +1 -0
  165. package/dist/workflow/meta.js +318 -0
  166. package/dist/workflow/meta.js.map +1 -0
  167. package/dist/workflow/progress.d.ts +225 -0
  168. package/dist/workflow/progress.d.ts.map +1 -0
  169. package/dist/workflow/progress.js +362 -0
  170. package/dist/workflow/progress.js.map +1 -0
  171. package/dist/workflow/runtime.d.ts +335 -0
  172. package/dist/workflow/runtime.d.ts.map +1 -0
  173. package/dist/workflow/runtime.js +831 -0
  174. package/dist/workflow/runtime.js.map +1 -0
  175. package/dist/workflow/saved.d.ts +91 -0
  176. package/dist/workflow/saved.d.ts.map +1 -0
  177. package/dist/workflow/saved.js +204 -0
  178. package/dist/workflow/saved.js.map +1 -0
  179. package/dist/workflow/task.d.ts +137 -0
  180. package/dist/workflow/task.d.ts.map +1 -0
  181. package/dist/workflow/task.js +208 -0
  182. package/dist/workflow/task.js.map +1 -0
  183. package/dist/workflow/tool-description.d.ts +39 -0
  184. package/dist/workflow/tool-description.d.ts.map +1 -0
  185. package/dist/workflow/tool-description.js +200 -0
  186. package/dist/workflow/tool-description.js.map +1 -0
  187. package/dist/workflow/worker-source.d.ts +48 -0
  188. package/dist/workflow/worker-source.d.ts.map +1 -0
  189. package/dist/workflow/worker-source.js +779 -0
  190. package/dist/workflow/worker-source.js.map +1 -0
  191. package/dist/worktree.d.ts +10 -3
  192. package/dist/worktree.d.ts.map +1 -1
  193. package/dist/worktree.js +58 -54
  194. package/dist/worktree.js.map +1 -1
  195. package/dist/xml.d.ts +11 -0
  196. package/dist/xml.d.ts.map +1 -0
  197. package/dist/xml.js +13 -0
  198. package/dist/xml.js.map +1 -0
  199. package/docs/rpc.md +183 -0
  200. package/docs/superpowers/plans/2026-09-30-conversation-viewer-scrollbar.md +216 -0
  201. package/docs/superpowers/plans/2026-09-30-upstream-event-workflow-partial-history.md +195 -0
  202. package/docs/superpowers/specs/2026-09-30-conversation-viewer-scrollbar-design.md +82 -0
  203. package/docs/superpowers/specs/2026-09-30-upstream-event-workflow-partial-history-design.md +49 -0
  204. package/docs/workflows.md +437 -0
  205. package/examples/agent-tool-description.md +7 -7
  206. package/examples/workflows/compose.js +51 -0
  207. package/examples/workflows/fan-out-audit.js +47 -0
  208. package/examples/workflows/gated-fix.js +60 -0
  209. package/examples/workflows/lib/count-child.js +27 -0
  210. package/examples/workflows/review-panel.js +63 -0
  211. package/examples/workflows/structured-findings.js +78 -0
  212. package/package.json +1 -1
  213. package/src/abortable.ts +43 -0
  214. package/src/agent-color.ts +161 -0
  215. package/src/agent-file-toggle.ts +269 -0
  216. package/src/agent-history.ts +54 -2
  217. package/src/agent-manager.ts +1263 -402
  218. package/src/agent-runner.ts +251 -27
  219. package/src/agent-types.ts +188 -32
  220. package/src/child-context.ts +15 -0
  221. package/src/cross-extension-rpc.ts +96 -20
  222. package/src/custom-agents.ts +170 -13
  223. package/src/index.ts +2024 -537
  224. package/src/invocation-config.ts +118 -3
  225. package/src/mention-clone.ts +196 -0
  226. package/src/mention.ts +141 -0
  227. package/src/model-resolver.ts +18 -0
  228. package/src/model-scope.ts +70 -0
  229. package/src/nested-tools.ts +424 -0
  230. package/src/output-file.ts +61 -6
  231. package/src/prompts.ts +45 -2
  232. package/src/schedule.ts +35 -14
  233. package/src/settings.ts +312 -2
  234. package/src/status-note.ts +66 -1
  235. package/src/structured-output.ts +130 -0
  236. package/src/types.ts +177 -10
  237. package/src/ui/agent-mention.ts +216 -0
  238. package/src/ui/agent-widget.ts +389 -441
  239. package/src/ui/conversation-blocks.ts +6 -0
  240. package/src/ui/conversation-timeline.ts +139 -25
  241. package/src/ui/conversation-viewer.ts +284 -69
  242. package/src/ui/fleet-list.ts +558 -0
  243. package/src/ui/schedule-menu.ts +9 -8
  244. package/src/ui/select-item.ts +45 -0
  245. package/src/ui/workflow-card.ts +470 -0
  246. package/src/ui/workflow-dialog.ts +1115 -0
  247. package/src/ui/workflow-menu.ts +193 -0
  248. package/src/usage.ts +109 -2
  249. package/src/workflow/collisions.ts +123 -0
  250. package/src/workflow/entry.ts +47 -0
  251. package/src/workflow/host.ts +403 -0
  252. package/src/workflow/journal.ts +164 -0
  253. package/src/workflow/json-schema.ts +128 -0
  254. package/src/workflow/meta.ts +325 -0
  255. package/src/workflow/progress.ts +550 -0
  256. package/src/workflow/runtime.ts +1219 -0
  257. package/src/workflow/saved.ts +217 -0
  258. package/src/workflow/task.ts +302 -0
  259. package/src/workflow/tool-description.ts +200 -0
  260. package/src/workflow/worker-source.ts +781 -0
  261. package/src/worktree.ts +69 -55
  262. package/src/xml.ts +13 -0
  263. package/vitest.config.ts +0 -18
package/CHANGELOG.md CHANGED
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.17.7] - 2026-09-30
11
+
12
+ ### Added
13
+ - **Durable `.pi-subagents` histories now capture every spawn, tool/message turn, partial run, stop, abort, error, timeout, and shutdown path**, independently of the optional `.output` transcript switch.
14
+ - **Upstream workflow, lifecycle/RPC event handling, recovery checkpoints, and historical conversation reopening** are integrated while preserving the fork's fleet UI, scrollbar, preview, and in-place tool output behavior.
15
+
16
+ ### Fixed
17
+ - **ConversationViewer Markdown modes, cost/invocation metadata, terminal controls, truncation notices, and render-width safety** now work for live and recovered history.
18
+
19
+ ## [0.17.6] - 2026-09-30
20
+
21
+ ### Fixed
22
+ - **The main ConversationViewer now reserves a right-hand scrollbar rail and exposes an explicit `[preview]` action**, keeping transcript scrolling visible while opening the focused tool's full read-only preview without changing the conversation view's layout or focus behavior.
23
+
10
24
  ## [0.17.5] - 2026-09-30
11
25
 
12
26
  ### Fixed
package/CONTRIBUTING.md CHANGED
@@ -53,6 +53,10 @@ npm run build # tsc
53
53
  All four must pass. `npm run lint:fix` will auto-fix most style issues, and
54
54
  `npm run test:e2e` runs the end-to-end suite if your change touches that surface.
55
55
 
56
+ If your change touches a render path or the spawn path, `npm run bench` prints
57
+ absolute timings and `npm run bench:ab -- master` compares them against master.
58
+ Neither is required to pass; both are opt-in, and neither runs in CI.
59
+
56
60
  Other guidelines:
57
61
 
58
62
  - Keep PRs focused — one logical change per PR. Unrelated refactors make review
package/README.md CHANGED
@@ -15,7 +15,7 @@ https://github.com/user-attachments/assets/8685261b-9338-4fea-8dfe-1c590d5df543
15
15
  - **Claude Code look & feel** — same tool names, calling conventions, and UI patterns (`Agent`, `get_subagent_result`, `steer_subagent`) — feels native
16
16
  - **Parallel background agents** — spawn multiple agents that run concurrently with automatic queuing (configurable concurrency limit, default 4) and smart group join (consolidated notifications)
17
17
  - **Agents panel UI** — persistent above-editor widget with animated spinners, live tool activity, token counts, colored status icons, and one focus-gated navigator. It shows every agent by default; press `↓` at an empty prompt to activate the panel, `↑`/`↓` to select, `Enter` to open a live or read-only history viewer, and `Esc` to return. Long rosters reserve a right-hand track/thumb scrollbar and show `↑ N more` or `↓ N more` at the clipped edge. Configure via `/agents → Settings → Widget`: `all`, `background`, or `off`
18
- - **Conversation viewer** — select any agent in `/agents` to open a live-scrolling overlay of its full conversation (auto-follows new content, scroll up to pause). Steer a running agent inline by pressing `e` to open a Pi-native composer, typing, then `Enter` to send (`Esc` or an empty submit returns); the follow-up appears as a muted/gray USER message and redirects the agent after its current tool. `Alt+Up` (`a-up`/`alt+up`) recalls submitted follow-up drafts. Read-only tool previews replace the viewer in place, use the larger viewport with the same right-hand track/thumb scrollbar and top/bottom hidden-line affordances, and return with `Esc`, `q`, or the close control. Stop a still-running agent by pressing `x` (then `x` again to confirm) — both work for background agents too
18
+ - **Conversation viewer** — select any agent in `/agents` to open a live-scrolling overlay of its full conversation (auto-follows new content, scroll up to pause). The main viewer reserves a right-hand scrollbar rail for the transcript and exposes a `[preview]` header action for the focused tool. Steer a running agent inline by pressing `e` to open a Pi-native composer, typing, then `Enter` to send (`Esc` or an empty submit returns); the follow-up appears as a muted/gray USER message and redirects the agent after its current tool. `Alt+Up` (`a-up`/`alt+up`) recalls submitted follow-up drafts. Read-only tool previews replace the viewer in place, use the larger viewport with the same right-hand track/thumb scrollbar and top/bottom hidden-line affordances, and return with `Esc`, `q`, or the close control. Stop a still-running agent by pressing `x` (then `x` again to confirm) — both work for background agents too
19
19
  - **Custom agent types** — define agents in `.pi/agents/<name>.md` or `.agents/agents/<name>.md` (project) or globally, with YAML frontmatter: custom system prompts, model selection, thinking levels, tool restrictions
20
20
  - **Mid-run steering** — inject messages into running agents to redirect their work without restarting
21
21
  - **Session resume** — pick up where an agent left off, preserving full conversation context
@@ -0,0 +1,13 @@
1
+ /**
2
+ * abortable.ts — race a promise against an AbortSignal without cancelling the
3
+ * underlying work.
4
+ *
5
+ * Used by the `get_subagent_result` wait paths (top-level and nested): pressing
6
+ * Esc cancels only the caller's wait; the background child keeps running and its
7
+ * result stays unconsumed. The listener is removed on every settle path so the
8
+ * signal accumulates no handlers, and a late settlement of the wrapped promise
9
+ * after an abort is absorbed as a no-op (no unhandled rejection).
10
+ */
11
+ /** Await a promise until it settles or the caller cancels, without aborting the underlying work. */
12
+ export declare function abortable<T>(promise: Promise<T>, signal?: AbortSignal): Promise<T>;
13
+ //# sourceMappingURL=abortable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abortable.d.ts","sourceRoot":"","sources":["../src/abortable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,oGAAoG;AACpG,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CA8BlF"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * abortable.ts — race a promise against an AbortSignal without cancelling the
3
+ * underlying work.
4
+ *
5
+ * Used by the `get_subagent_result` wait paths (top-level and nested): pressing
6
+ * Esc cancels only the caller's wait; the background child keeps running and its
7
+ * result stays unconsumed. The listener is removed on every settle path so the
8
+ * signal accumulates no handlers, and a late settlement of the wrapped promise
9
+ * after an abort is absorbed as a no-op (no unhandled rejection).
10
+ */
11
+ /** Await a promise until it settles or the caller cancels, without aborting the underlying work. */
12
+ export function abortable(promise, signal) {
13
+ if (!signal)
14
+ return promise;
15
+ if (signal.aborted)
16
+ return Promise.reject(signal.reason);
17
+ return new Promise((resolve, reject) => {
18
+ let settled = false;
19
+ const cleanup = () => signal.removeEventListener("abort", onAbort);
20
+ const onAbort = () => {
21
+ if (settled)
22
+ return;
23
+ settled = true;
24
+ cleanup();
25
+ reject(signal.reason);
26
+ };
27
+ signal.addEventListener("abort", onAbort, { once: true });
28
+ promise.then((value) => {
29
+ if (settled)
30
+ return;
31
+ settled = true;
32
+ cleanup();
33
+ resolve(value);
34
+ }, (error) => {
35
+ if (settled)
36
+ return;
37
+ settled = true;
38
+ cleanup();
39
+ reject(error);
40
+ });
41
+ });
42
+ }
43
+ //# sourceMappingURL=abortable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abortable.js","sourceRoot":"","sources":["../src/abortable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,oGAAoG;AACpG,MAAM,UAAU,SAAS,CAAI,OAAmB,EAAE,MAAoB;IACpE,IAAI,CAAC,MAAM;QAAE,OAAO,OAAO,CAAC;IAC5B,IAAI,MAAM,CAAC,OAAO;QAAE,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAEzD,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACxC,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACnE,MAAM,OAAO,GAAG,GAAG,EAAE;YACnB,IAAI,OAAO;gBAAE,OAAO;YACpB,OAAO,GAAG,IAAI,CAAC;YACf,OAAO,EAAE,CAAC;YACV,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACxB,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1D,OAAO,CAAC,IAAI,CACV,CAAC,KAAK,EAAE,EAAE;YACR,IAAI,OAAO;gBAAE,OAAO;YACpB,OAAO,GAAG,IAAI,CAAC;YACf,OAAO,EAAE,CAAC;YACV,OAAO,CAAC,KAAK,CAAC,CAAC;QACjB,CAAC,EACD,CAAC,KAAc,EAAE,EAAE;YACjB,IAAI,OAAO;gBAAE,OAAO;YACpB,OAAO,GAAG,IAAI,CAAC;YACf,OAAO,EAAE,CAAC;YACV,MAAM,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * agent-color.ts — Claude Code-compatible agent name badges.
3
+ *
4
+ * Claude Code renders a subagent's name as a badge: the configured color is the
5
+ * background, the text an inverse foreground. Its eight named colors are
6
+ * reproduced here, along with six-digit hex and the extra palette names Agency
7
+ * Agents uses, so those definitions render as written.
8
+ */
9
+ type ColorMode = "truecolor" | "256color";
10
+ export interface AgentNameTheme {
11
+ fg(color: string, text: string): string;
12
+ bold(text: string): string;
13
+ getColorMode?(): ColorMode;
14
+ }
15
+ export interface AgentNameStyle {
16
+ /** Existing theme foreground used when no valid agent color is configured. */
17
+ fallbackColor?: string;
18
+ /** Reapply an enclosing background after the badge instead of resetting it. */
19
+ restoreBackground?: string;
20
+ bold?: boolean;
21
+ }
22
+ /** Resolve Claude Code/Agency Agents color syntax to normalized #RRGGBB. */
23
+ export declare function resolveAgentColor(value: string | undefined): string | undefined;
24
+ /**
25
+ * Render one name as a padded background badge when `color` is valid. Claude
26
+ * Code uses one inverse color for every badge's text; black or white is picked
27
+ * by WCAG contrast here instead, so each palette entry stays readable. Invalid
28
+ * or omitted colors preserve the caller's existing theme styling.
29
+ */
30
+ export declare function renderAgentNameLabel(name: string, color: string | undefined, theme: AgentNameTheme, style?: AgentNameStyle): string;
31
+ /** Whether an agent renders as a badge — i.e. it has a valid configured color. */
32
+ export declare function hasAgentBadge(type: string | undefined): boolean;
33
+ /** Render a registered agent's display name with its configured color. */
34
+ export declare function renderAgentName(type: string | undefined, theme: AgentNameTheme, style?: AgentNameStyle): string;
35
+ export {};
36
+ //# sourceMappingURL=agent-color.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-color.d.ts","sourceRoot":"","sources":["../src/agent-color.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAsCH,KAAK,SAAS,GAAG,WAAW,GAAG,UAAU,CAAC;AAE1C,MAAM,WAAW,cAAc;IAC7B,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACxC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,YAAY,CAAC,IAAI,SAAS,CAAC;CAC5B;AAED,MAAM,WAAW,cAAc;IAC7B,8EAA8E;IAC9E,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,+EAA+E;IAC/E,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,4EAA4E;AAC5E,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAK/E;AAgDD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,KAAK,EAAE,cAAc,EACrB,KAAK,GAAE,cAAmB,GACzB,MAAM,CAkBR;AAED,kFAAkF;AAClF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAE/D;AAED,0EAA0E;AAC1E,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,KAAK,EAAE,cAAc,EACrB,KAAK,GAAE,cAAmB,GACzB,MAAM,CAIR"}
@@ -0,0 +1,124 @@
1
+ /**
2
+ * agent-color.ts — Claude Code-compatible agent name badges.
3
+ *
4
+ * Claude Code renders a subagent's name as a badge: the configured color is the
5
+ * background, the text an inverse foreground. Its eight named colors are
6
+ * reproduced here, along with six-digit hex and the extra palette names Agency
7
+ * Agents uses, so those definitions render as written.
8
+ */
9
+ import { getConfig } from "./agent-types.js";
10
+ const NAMED_AGENT_COLORS = {
11
+ // Claude Code's eight subagent colors, as its default theme renders them.
12
+ red: "#DC2626",
13
+ blue: "#6A9BCC",
14
+ green: "#16A34A",
15
+ yellow: "#CA8A04",
16
+ purple: "#827DBD",
17
+ orange: "#D97757",
18
+ pink: "#C46686",
19
+ cyan: "#0891B2",
20
+ // Agency Agents palette aliases.
21
+ amber: "#F59E0B",
22
+ teal: "#008080",
23
+ indigo: "#6366F1",
24
+ gold: "#EAB308",
25
+ "neon-green": "#10B981",
26
+ "neon-cyan": "#06B6D4",
27
+ "metallic-blue": "#3B82F6",
28
+ violet: "#8B5CF6",
29
+ rose: "#F43F5E",
30
+ lime: "#84CC16",
31
+ gray: "#6B7280",
32
+ grey: "#6B7280",
33
+ fuchsia: "#D946EF",
34
+ slate: "#64748B",
35
+ navy: "#1E3A8A",
36
+ };
37
+ const CUBE_VALUES = [0, 95, 135, 175, 215, 255];
38
+ const GRAY_VALUES = Array.from({ length: 24 }, (_, i) => 8 + i * 10);
39
+ const BLACK = { r: 0, g: 0, b: 0 };
40
+ const WHITE = { r: 255, g: 255, b: 255 };
41
+ /** Resolve Claude Code/Agency Agents color syntax to normalized #RRGGBB. */
42
+ export function resolveAgentColor(value) {
43
+ if (!value)
44
+ return undefined;
45
+ const normalized = value.trim().toLowerCase();
46
+ const resolved = NAMED_AGENT_COLORS[normalized] ?? normalized;
47
+ return /^#[0-9a-f]{6}$/i.test(resolved) ? resolved.toUpperCase() : undefined;
48
+ }
49
+ function parseHex(hex) {
50
+ return {
51
+ r: Number.parseInt(hex.slice(1, 3), 16),
52
+ g: Number.parseInt(hex.slice(3, 5), 16),
53
+ b: Number.parseInt(hex.slice(5, 7), 16),
54
+ };
55
+ }
56
+ /** Index of the entry in `values` closest to `value`. */
57
+ function nearest(values, value) {
58
+ return values.reduce((best, v, i) => (Math.abs(value - v) < Math.abs(value - values[best]) ? i : best), 0);
59
+ }
60
+ /**
61
+ * Quantize to the xterm-256 palette the way pi's own theme does, returning both
62
+ * the index to emit and the color the terminal will actually show — badge
63
+ * contrast is judged against the latter.
64
+ */
65
+ function rgbTo256({ r, g, b }) {
66
+ const [rIndex, gIndex, bIndex] = [r, g, b].map((channel) => nearest(CUBE_VALUES, channel));
67
+ const distance = ({ r: cr, g: cg, b: cb }) => 0.299 * (r - cr) ** 2 + 0.587 * (g - cg) ** 2 + 0.114 * (b - cb) ** 2;
68
+ const grayIndex = nearest(GRAY_VALUES, Math.round(0.299 * r + 0.587 * g + 0.114 * b));
69
+ const gray = { r: GRAY_VALUES[grayIndex], g: GRAY_VALUES[grayIndex], b: GRAY_VALUES[grayIndex] };
70
+ const cube = { r: CUBE_VALUES[rIndex], g: CUBE_VALUES[gIndex], b: CUBE_VALUES[bIndex] };
71
+ // Only near-neutral colors may take the gray ramp; anything else keeps its tint.
72
+ if (Math.max(r, g, b) - Math.min(r, g, b) < 10 && distance(gray) < distance(cube)) {
73
+ return { index: 232 + grayIndex, rgb: gray };
74
+ }
75
+ return { index: 16 + 36 * rIndex + 6 * gIndex + bIndex, rgb: cube };
76
+ }
77
+ function ansiColor(layer, color) {
78
+ const code = layer === "foreground" ? 38 : 48;
79
+ return typeof color === "number"
80
+ ? `\u001b[${code};5;${color}m`
81
+ : `\u001b[${code};2;${color.r};${color.g};${color.b}m`;
82
+ }
83
+ function relativeLuminance({ r, g, b }) {
84
+ const linear = (value) => {
85
+ const channel = value / 255;
86
+ return channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4;
87
+ };
88
+ return 0.2126 * linear(r) + 0.7152 * linear(g) + 0.0722 * linear(b);
89
+ }
90
+ /**
91
+ * Render one name as a padded background badge when `color` is valid. Claude
92
+ * Code uses one inverse color for every badge's text; black or white is picked
93
+ * by WCAG contrast here instead, so each palette entry stays readable. Invalid
94
+ * or omitted colors preserve the caller's existing theme styling.
95
+ */
96
+ export function renderAgentNameLabel(name, color, theme, style = {}) {
97
+ const resolved = resolveAgentColor(color);
98
+ if (!resolved) {
99
+ const text = style.bold ? theme.bold(name) : name;
100
+ return style.fallbackColor ? theme.fg(style.fallbackColor, text) : text;
101
+ }
102
+ const rgb = parseHex(resolved);
103
+ const quantized = (theme.getColorMode?.() ?? "truecolor") === "256color" ? rgbTo256(rgb) : undefined;
104
+ const shown = quantized?.rgb ?? rgb;
105
+ const contrasting = relativeLuminance(shown) > 0.179 ? BLACK : WHITE;
106
+ const label = style.bold ? theme.bold(` ${name} `) : ` ${name} `;
107
+ return ansiColor("background", quantized?.index ?? rgb)
108
+ + ansiColor("foreground", quantized ? rgbTo256(contrasting).index : contrasting)
109
+ + label
110
+ + "\u001b[39m"
111
+ + (style.restoreBackground ?? "\u001b[49m");
112
+ }
113
+ /** Whether an agent renders as a badge — i.e. it has a valid configured color. */
114
+ export function hasAgentBadge(type) {
115
+ return type !== undefined && resolveAgentColor(getConfig(type).color) !== undefined;
116
+ }
117
+ /** Render a registered agent's display name with its configured color. */
118
+ export function renderAgentName(type, theme, style = {}) {
119
+ if (!type)
120
+ return renderAgentNameLabel("Agent", undefined, theme, style);
121
+ const config = getConfig(type);
122
+ return renderAgentNameLabel(config.displayName, config.color, theme, style);
123
+ }
124
+ //# sourceMappingURL=agent-color.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-color.js","sourceRoot":"","sources":["../src/agent-color.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,MAAM,kBAAkB,GAAqC;IAC3D,0EAA0E;IAC1E,GAAG,EAAE,SAAS;IACd,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,SAAS;IAChB,MAAM,EAAE,SAAS;IAC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AAE,KAAK,CAAC,CAAC;IACzE,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IAC/B,OAAO,oBAAoB,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AAC9E,CAAC"}
@@ -0,0 +1,126 @@
1
+ /**
2
+ * agent-file-toggle.ts — Pure helpers for the `/agents` file-editing operations:
3
+ * locating an agent's .md file, toggling its `enabled:` frontmatter flag, and
4
+ * serializing an AgentConfig back to frontmatter for eject.
5
+ *
6
+ * These live outside src/index.ts so they can be tested directly: the `/agents`
7
+ * command handler is an ~890-line closure reached only through `registerCommand`,
8
+ * which every test mocks.
9
+ *
10
+ * The read side of this data (src/custom-agents.ts) parses frontmatter with a
11
+ * real YAML parser, so it honors `enabled: false` at any position in the block.
12
+ * This module must agree with it, and splits the work accordingly:
13
+ *
14
+ * - Deciding whether a file is disabled is a *read*, so it calls that same parser
15
+ * (`isDisabledContent`) instead of mirroring it. A mirror has to be right about
16
+ * YAML's boolean spellings and about pi's fence scan, and a regex was wrong
17
+ * about both.
18
+ * - *Editing* cannot go through the parser, because re-serializing a parsed
19
+ * document would reformat a file the README tells users to hand-author —
20
+ * discarding their comments, key order, and quoting. So the edits are line-wise
21
+ * and preserve everything they don't touch.
22
+ *
23
+ * That leaves removal best-effort: it recognizes a lowercase bare `false`, and
24
+ * reports `changed: false` for the spellings it cannot rewrite, so the caller
25
+ * refuses honestly rather than announcing a change it did not make.
26
+ */
27
+ import type { AgentConfig } from "./types.js";
28
+ export type AgentFileLocation = "project" | "workspace" | "personal";
29
+ export declare const projectAgentsDir: (cwd?: string) => string;
30
+ export declare const workspaceAgentsDir: (cwd?: string) => string;
31
+ export declare const personalAgentsDir: () => string;
32
+ /**
33
+ * Find the file path of a custom agent by name, in discovery-precedence order
34
+ * (project, workspace, then global). Mirrors the load-side precedence in
35
+ * src/custom-agents.ts — if the two drift, `/agents` edits a file the loader
36
+ * isn't reading.
37
+ */
38
+ export declare function findAgentFile(name: string, cwd?: string): {
39
+ path: string;
40
+ location: AgentFileLocation;
41
+ } | undefined;
42
+ /**
43
+ * Find the file behind a *loaded* agent, preferring the path the loader
44
+ * actually read (`AgentConfig.sourcePath`) over the `<type>.md` guess.
45
+ *
46
+ * An agent's type comes from its frontmatter `name:` now, so the two can
47
+ * disagree: `reviewer.md` declaring `name: code-reviewer` is loaded as
48
+ * `code-reviewer`, and probing for `code-reviewer.md` finds nothing. That is
49
+ * not a harmless miss — `/agents → Disable` would then take the no-file branch
50
+ * and write a NEW `code-reviewer.md` stub, which loses to `reviewer.md` on
51
+ * load, leaving the agent enabled while reporting success.
52
+ *
53
+ * The probe stays as the fallback: a built-in that was never ejected has no
54
+ * `sourcePath`, and a path can go stale between a load and this call.
55
+ */
56
+ export declare function locateAgentFile(name: string, sourcePath: string | undefined, cwd?: string): {
57
+ path: string;
58
+ location: AgentFileLocation;
59
+ } | undefined;
60
+ export type DisableOutcome = "disabled" | "already-disabled" | "no-frontmatter";
61
+ /**
62
+ * Does the loader consider this file disabled?
63
+ *
64
+ * Detection is a READ operation, so it asks the same parser the loader uses
65
+ * rather than mirroring it with a regex — that mirror has to be right about
66
+ * YAML's boolean spellings (`False`, `FALSE`, a trailing `# comment`, a quoted
67
+ * key) *and* about pi's fence scan, which closes the block on any line starting
68
+ * `---` and so ends it early on `----`. A throw means the file is already
69
+ * unparseable, which is what the loader sees too: it skips the agent, so there
70
+ * is no "disabled" state to report.
71
+ */
72
+ export declare function isDisabledContent(content: string): boolean;
73
+ /**
74
+ * Add `enabled: false` to a file's frontmatter.
75
+ *
76
+ * `outcome` distinguishes a real edit from a no-op so the caller can report
77
+ * honestly instead of unconditionally claiming success.
78
+ */
79
+ export declare function disableInContent(content: string): {
80
+ content: string;
81
+ outcome: DisableOutcome;
82
+ };
83
+ /**
84
+ * Remove `enabled: false` from a file's frontmatter, wherever it appears in the
85
+ * block — the loader honors the key at any position, so the two must agree or a
86
+ * hand-authored agent can be disabled and never re-enabled.
87
+ *
88
+ * `changed` is false when the key wasn't found, so the caller can avoid
89
+ * reporting "Enabled <name>" for a write that did nothing.
90
+ */
91
+ export declare function enableInContent(content: string): {
92
+ content: string;
93
+ changed: boolean;
94
+ };
95
+ /** Is this the empty stub `/agents` writes when disabling a built-in default? */
96
+ export declare function isEmptyStub(content: string): boolean;
97
+ /** The answers `/agents → Create agent → Manual` collects, before serialization. */
98
+ export interface NewAgentInput {
99
+ description: string;
100
+ /** Already-resolved `tools:` value ("none", "all", or a CSV of tool names). */
101
+ tools: string;
102
+ /** `provider/modelId`, or undefined to inherit the parent's model. */
103
+ model?: string;
104
+ /** A pi thinking level, or undefined to inherit. */
105
+ thinking?: string;
106
+ systemPrompt: string;
107
+ }
108
+ /**
109
+ * Build the .md file the create wizard writes.
110
+ *
111
+ * `description` and `model` come straight from a free-text prompt, so they are
112
+ * quoted rather than interpolated — `serializeAgentFile` above quotes the
113
+ * description for the same reason. An unquoted YAML scalar mishandles ordinary
114
+ * input in two ways, and both are silent: a colon ("Scout: find things") makes
115
+ * the file unparseable, and since #212 an unparseable agent file is *skipped*,
116
+ * so the wizard reports success for an agent that does not exist; a `#`
117
+ * ("audit #security") opens a comment and truncates the value. `model` can
118
+ * carry a colon too — pi accepts a `provider/model:thinking` suffix.
119
+ *
120
+ * `tools` and `thinking` are not quoted: both are chosen from fixed menus, and
121
+ * `tools` is a CSV that must stay a bare scalar for the loader's parser.
122
+ */
123
+ export declare function buildNewAgentFile(input: NewAgentInput): string;
124
+ /** Serialize an AgentConfig to a full .md file (frontmatter + system prompt) for eject. */
125
+ export declare function serializeAgentFile(cfg: AgentConfig): string;
126
+ //# sourceMappingURL=agent-file-toggle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-file-toggle.d.ts","sourceRoot":"","sources":["../src/agent-file-toggle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAMH,OAAO,KAAK,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