@esso0428/pi-subagents 0.17.16 → 0.17.18

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 (359) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/ROADMAP.md +87 -0
  3. package/docs/post-0.17.6-agents-roster-viewer-spec.md +42 -0
  4. package/docs/post-0.17.6-durable-history-spec.md +41 -0
  5. package/docs/post-0.17.6-feature-specs.md +50 -0
  6. package/docs/post-0.17.6-nested-agents-spec.md +38 -0
  7. package/docs/post-0.17.6-recovery-shutdown-spec.md +46 -0
  8. package/docs/post-0.17.6-ui-latency-baseline-spec.md +46 -0
  9. package/docs/post-0.17.6-workflow-rpc-lifecycle-spec.md +54 -0
  10. package/package.json +1 -1
  11. package/src/agent-history.ts +2 -54
  12. package/src/agent-manager.ts +406 -1288
  13. package/src/agent-runner.ts +27 -251
  14. package/src/agent-types.ts +32 -188
  15. package/src/cross-extension-rpc.ts +20 -96
  16. package/src/custom-agents.ts +13 -170
  17. package/src/index.ts +480 -1920
  18. package/src/invocation-config.ts +3 -118
  19. package/src/model-resolver.ts +0 -18
  20. package/src/output-file.ts +6 -61
  21. package/src/prompts.ts +2 -45
  22. package/src/schedule.ts +14 -35
  23. package/src/settings.ts +2 -301
  24. package/src/status-note.ts +1 -66
  25. package/src/types.ts +10 -177
  26. package/src/ui/agent-widget.ts +57 -278
  27. package/src/ui/conversation-blocks.ts +0 -6
  28. package/src/ui/conversation-timeline.ts +25 -139
  29. package/src/ui/conversation-viewer.ts +48 -212
  30. package/src/ui/schedule-menu.ts +8 -9
  31. package/src/usage.ts +2 -109
  32. package/src/worktree.ts +55 -69
  33. package/dist/abortable.d.ts +0 -13
  34. package/dist/abortable.d.ts.map +0 -1
  35. package/dist/abortable.js +0 -43
  36. package/dist/abortable.js.map +0 -1
  37. package/dist/agent-color.d.ts +0 -36
  38. package/dist/agent-color.d.ts.map +0 -1
  39. package/dist/agent-color.js +0 -124
  40. package/dist/agent-color.js.map +0 -1
  41. package/dist/agent-file-toggle.d.ts +0 -126
  42. package/dist/agent-file-toggle.d.ts.map +0 -1
  43. package/dist/agent-file-toggle.js +0 -259
  44. package/dist/agent-file-toggle.js.map +0 -1
  45. package/dist/agent-history-list.d.ts +0 -19
  46. package/dist/agent-history-list.d.ts.map +0 -1
  47. package/dist/agent-history-list.js +0 -69
  48. package/dist/agent-history-list.js.map +0 -1
  49. package/dist/agent-history.d.ts +0 -35
  50. package/dist/agent-history.d.ts.map +0 -1
  51. package/dist/agent-history.js +0 -188
  52. package/dist/agent-history.js.map +0 -1
  53. package/dist/agent-manager.d.ts +0 -503
  54. package/dist/agent-manager.d.ts.map +0 -1
  55. package/dist/agent-manager.js +0 -1572
  56. package/dist/agent-manager.js.map +0 -1
  57. package/dist/agent-recovery.d.ts +0 -37
  58. package/dist/agent-recovery.d.ts.map +0 -1
  59. package/dist/agent-recovery.js +0 -171
  60. package/dist/agent-recovery.js.map +0 -1
  61. package/dist/agent-runner.d.ts +0 -303
  62. package/dist/agent-runner.d.ts.map +0 -1
  63. package/dist/agent-runner.js +0 -1003
  64. package/dist/agent-runner.js.map +0 -1
  65. package/dist/agent-types.d.ts +0 -120
  66. package/dist/agent-types.d.ts.map +0 -1
  67. package/dist/agent-types.js +0 -301
  68. package/dist/agent-types.js.map +0 -1
  69. package/dist/child-context.d.ts +0 -3
  70. package/dist/child-context.d.ts.map +0 -1
  71. package/dist/child-context.js +0 -13
  72. package/dist/child-context.js.map +0 -1
  73. package/dist/context.d.ts +0 -13
  74. package/dist/context.d.ts.map +0 -1
  75. package/dist/context.js +0 -57
  76. package/dist/context.js.map +0 -1
  77. package/dist/cross-extension-rpc.d.ts +0 -67
  78. package/dist/cross-extension-rpc.d.ts.map +0 -1
  79. package/dist/cross-extension-rpc.js +0 -139
  80. package/dist/cross-extension-rpc.js.map +0 -1
  81. package/dist/custom-agents.d.ts +0 -55
  82. package/dist/custom-agents.d.ts.map +0 -1
  83. package/dist/custom-agents.js +0 -309
  84. package/dist/custom-agents.js.map +0 -1
  85. package/dist/default-agents.d.ts +0 -8
  86. package/dist/default-agents.d.ts.map +0 -1
  87. package/dist/default-agents.js +0 -123
  88. package/dist/default-agents.js.map +0 -1
  89. package/dist/enabled-models.d.ts +0 -50
  90. package/dist/enabled-models.d.ts.map +0 -1
  91. package/dist/enabled-models.js +0 -146
  92. package/dist/enabled-models.js.map +0 -1
  93. package/dist/env.d.ts +0 -7
  94. package/dist/env.d.ts.map +0 -1
  95. package/dist/env.js +0 -29
  96. package/dist/env.js.map +0 -1
  97. package/dist/group-join.d.ts +0 -33
  98. package/dist/group-join.d.ts.map +0 -1
  99. package/dist/group-join.js +0 -117
  100. package/dist/group-join.js.map +0 -1
  101. package/dist/index.d.ts +0 -51
  102. package/dist/index.d.ts.map +0 -1
  103. package/dist/index.js +0 -3687
  104. package/dist/index.js.map +0 -1
  105. package/dist/invocation-config.d.ts +0 -108
  106. package/dist/invocation-config.d.ts.map +0 -1
  107. package/dist/invocation-config.js +0 -84
  108. package/dist/invocation-config.js.map +0 -1
  109. package/dist/memory.d.ts +0 -54
  110. package/dist/memory.d.ts.map +0 -1
  111. package/dist/memory.js +0 -166
  112. package/dist/memory.js.map +0 -1
  113. package/dist/mention-clone.d.ts +0 -88
  114. package/dist/mention-clone.d.ts.map +0 -1
  115. package/dist/mention-clone.js +0 -154
  116. package/dist/mention-clone.js.map +0 -1
  117. package/dist/mention.d.ts +0 -82
  118. package/dist/mention.d.ts.map +0 -1
  119. package/dist/mention.js +0 -132
  120. package/dist/mention.js.map +0 -1
  121. package/dist/model-resolver.d.ts +0 -37
  122. package/dist/model-resolver.d.ts.map +0 -1
  123. package/dist/model-resolver.js +0 -96
  124. package/dist/model-resolver.js.map +0 -1
  125. package/dist/model-scope.d.ts +0 -50
  126. package/dist/model-scope.d.ts.map +0 -1
  127. package/dist/model-scope.js +0 -49
  128. package/dist/model-scope.js.map +0 -1
  129. package/dist/nested-tools.d.ts +0 -57
  130. package/dist/nested-tools.d.ts.map +0 -1
  131. package/dist/nested-tools.js +0 -301
  132. package/dist/nested-tools.js.map +0 -1
  133. package/dist/nico-overrides.d.ts +0 -54
  134. package/dist/nico-overrides.d.ts.map +0 -1
  135. package/dist/nico-overrides.js +0 -170
  136. package/dist/nico-overrides.js.map +0 -1
  137. package/dist/output-file.d.ts +0 -44
  138. package/dist/output-file.d.ts.map +0 -1
  139. package/dist/output-file.js +0 -156
  140. package/dist/output-file.js.map +0 -1
  141. package/dist/prompts.d.ts +0 -56
  142. package/dist/prompts.d.ts.map +0 -1
  143. package/dist/prompts.js +0 -92
  144. package/dist/prompts.js.map +0 -1
  145. package/dist/schedule-store.d.ts +0 -39
  146. package/dist/schedule-store.d.ts.map +0 -1
  147. package/dist/schedule-store.js +0 -156
  148. package/dist/schedule-store.js.map +0 -1
  149. package/dist/schedule.d.ts +0 -110
  150. package/dist/schedule.d.ts.map +0 -1
  151. package/dist/schedule.js +0 -360
  152. package/dist/schedule.js.map +0 -1
  153. package/dist/settings.d.ts +0 -354
  154. package/dist/settings.d.ts.map +0 -1
  155. package/dist/settings.js +0 -247
  156. package/dist/settings.js.map +0 -1
  157. package/dist/skill-loader.d.ts +0 -25
  158. package/dist/skill-loader.d.ts.map +0 -1
  159. package/dist/skill-loader.js +0 -94
  160. package/dist/skill-loader.js.map +0 -1
  161. package/dist/status-note.d.ts +0 -62
  162. package/dist/status-note.d.ts.map +0 -1
  163. package/dist/status-note.js +0 -86
  164. package/dist/status-note.js.map +0 -1
  165. package/dist/structured-output.d.ts +0 -62
  166. package/dist/structured-output.d.ts.map +0 -1
  167. package/dist/structured-output.js +0 -113
  168. package/dist/structured-output.js.map +0 -1
  169. package/dist/types.d.ts +0 -372
  170. package/dist/types.d.ts.map +0 -1
  171. package/dist/types.js +0 -6
  172. package/dist/types.js.map +0 -1
  173. package/dist/ui/agent-mention.d.ts +0 -83
  174. package/dist/ui/agent-mention.d.ts.map +0 -1
  175. package/dist/ui/agent-mention.js +0 -188
  176. package/dist/ui/agent-mention.js.map +0 -1
  177. package/dist/ui/agent-widget.d.ts +0 -241
  178. package/dist/ui/agent-widget.d.ts.map +0 -1
  179. package/dist/ui/agent-widget.js +0 -992
  180. package/dist/ui/agent-widget.js.map +0 -1
  181. package/dist/ui/ccstyle/diff/ansi-utils.d.ts +0 -11
  182. package/dist/ui/ccstyle/diff/ansi-utils.d.ts.map +0 -1
  183. package/dist/ui/ccstyle/diff/ansi-utils.js +0 -145
  184. package/dist/ui/ccstyle/diff/ansi-utils.js.map +0 -1
  185. package/dist/ui/ccstyle/diff/diff-presentation.d.ts +0 -12
  186. package/dist/ui/ccstyle/diff/diff-presentation.d.ts.map +0 -1
  187. package/dist/ui/ccstyle/diff/diff-presentation.js +0 -48
  188. package/dist/ui/ccstyle/diff/diff-presentation.js.map +0 -1
  189. package/dist/ui/ccstyle/diff/diff-renderer.d.ts +0 -46
  190. package/dist/ui/ccstyle/diff/diff-renderer.d.ts.map +0 -1
  191. package/dist/ui/ccstyle/diff/diff-renderer.js +0 -2049
  192. package/dist/ui/ccstyle/diff/diff-renderer.js.map +0 -1
  193. package/dist/ui/ccstyle/diff/line-width-safety.d.ts +0 -12
  194. package/dist/ui/ccstyle/diff/line-width-safety.d.ts.map +0 -1
  195. package/dist/ui/ccstyle/diff/line-width-safety.js +0 -58
  196. package/dist/ui/ccstyle/diff/line-width-safety.js.map +0 -1
  197. package/dist/ui/ccstyle/diff/render-utils.d.ts +0 -6
  198. package/dist/ui/ccstyle/diff/render-utils.d.ts.map +0 -1
  199. package/dist/ui/ccstyle/diff/render-utils.js +0 -25
  200. package/dist/ui/ccstyle/diff/render-utils.js.map +0 -1
  201. package/dist/ui/ccstyle/diff/shiki-highlight.d.ts +0 -19
  202. package/dist/ui/ccstyle/diff/shiki-highlight.d.ts.map +0 -1
  203. package/dist/ui/ccstyle/diff/shiki-highlight.js +0 -85
  204. package/dist/ui/ccstyle/diff/shiki-highlight.js.map +0 -1
  205. package/dist/ui/ccstyle/diff/types.d.ts +0 -22
  206. package/dist/ui/ccstyle/diff/types.d.ts.map +0 -1
  207. package/dist/ui/ccstyle/diff/types.js +0 -10
  208. package/dist/ui/ccstyle/diff/types.js.map +0 -1
  209. package/dist/ui/ccstyle/diff/write-display-utils.d.ts +0 -2
  210. package/dist/ui/ccstyle/diff/write-display-utils.d.ts.map +0 -1
  211. package/dist/ui/ccstyle/diff/write-display-utils.js +0 -12
  212. package/dist/ui/ccstyle/diff/write-display-utils.js.map +0 -1
  213. package/dist/ui/ccstyle/tool-renderer.d.ts +0 -17
  214. package/dist/ui/ccstyle/tool-renderer.d.ts.map +0 -1
  215. package/dist/ui/ccstyle/tool-renderer.js +0 -74
  216. package/dist/ui/ccstyle/tool-renderer.js.map +0 -1
  217. package/dist/ui/ccstyle/tool-result.d.ts +0 -44
  218. package/dist/ui/ccstyle/tool-result.d.ts.map +0 -1
  219. package/dist/ui/ccstyle/tool-result.js +0 -423
  220. package/dist/ui/ccstyle/tool-result.js.map +0 -1
  221. package/dist/ui/conversation-blocks.d.ts +0 -46
  222. package/dist/ui/conversation-blocks.d.ts.map +0 -1
  223. package/dist/ui/conversation-blocks.js +0 -313
  224. package/dist/ui/conversation-blocks.js.map +0 -1
  225. package/dist/ui/conversation-nvim.d.ts +0 -8
  226. package/dist/ui/conversation-nvim.d.ts.map +0 -1
  227. package/dist/ui/conversation-nvim.js +0 -117
  228. package/dist/ui/conversation-nvim.js.map +0 -1
  229. package/dist/ui/conversation-role.d.ts +0 -13
  230. package/dist/ui/conversation-role.d.ts.map +0 -1
  231. package/dist/ui/conversation-role.js +0 -39
  232. package/dist/ui/conversation-role.js.map +0 -1
  233. package/dist/ui/conversation-search.d.ts +0 -39
  234. package/dist/ui/conversation-search.d.ts.map +0 -1
  235. package/dist/ui/conversation-search.js +0 -124
  236. package/dist/ui/conversation-search.js.map +0 -1
  237. package/dist/ui/conversation-timeline.d.ts +0 -102
  238. package/dist/ui/conversation-timeline.d.ts.map +0 -1
  239. package/dist/ui/conversation-timeline.js +0 -555
  240. package/dist/ui/conversation-timeline.js.map +0 -1
  241. package/dist/ui/conversation-viewer.d.ts +0 -138
  242. package/dist/ui/conversation-viewer.d.ts.map +0 -1
  243. package/dist/ui/conversation-viewer.js +0 -1175
  244. package/dist/ui/conversation-viewer.js.map +0 -1
  245. package/dist/ui/schedule-menu.d.ts +0 -17
  246. package/dist/ui/schedule-menu.d.ts.map +0 -1
  247. package/dist/ui/schedule-menu.js +0 -95
  248. package/dist/ui/schedule-menu.js.map +0 -1
  249. package/dist/ui/select-item.d.ts +0 -28
  250. package/dist/ui/select-item.d.ts.map +0 -1
  251. package/dist/ui/select-item.js +0 -35
  252. package/dist/ui/select-item.js.map +0 -1
  253. package/dist/ui/viewer-keys.d.ts +0 -21
  254. package/dist/ui/viewer-keys.d.ts.map +0 -1
  255. package/dist/ui/viewer-keys.js +0 -18
  256. package/dist/ui/viewer-keys.js.map +0 -1
  257. package/dist/ui/workflow-card.d.ts +0 -176
  258. package/dist/ui/workflow-card.d.ts.map +0 -1
  259. package/dist/ui/workflow-card.js +0 -333
  260. package/dist/ui/workflow-card.js.map +0 -1
  261. package/dist/ui/workflow-dialog.d.ts +0 -306
  262. package/dist/ui/workflow-dialog.d.ts.map +0 -1
  263. package/dist/ui/workflow-dialog.js +0 -844
  264. package/dist/ui/workflow-dialog.js.map +0 -1
  265. package/dist/ui/workflow-menu.d.ts +0 -42
  266. package/dist/ui/workflow-menu.d.ts.map +0 -1
  267. package/dist/ui/workflow-menu.js +0 -127
  268. package/dist/ui/workflow-menu.js.map +0 -1
  269. package/dist/usage.d.ts +0 -136
  270. package/dist/usage.d.ts.map +0 -1
  271. package/dist/usage.js +0 -121
  272. package/dist/usage.js.map +0 -1
  273. package/dist/workflow/collisions.d.ts +0 -96
  274. package/dist/workflow/collisions.d.ts.map +0 -1
  275. package/dist/workflow/collisions.js +0 -89
  276. package/dist/workflow/collisions.js.map +0 -1
  277. package/dist/workflow/entry.d.ts +0 -33
  278. package/dist/workflow/entry.d.ts.map +0 -1
  279. package/dist/workflow/entry.js +0 -30
  280. package/dist/workflow/entry.js.map +0 -1
  281. package/dist/workflow/host.d.ts +0 -63
  282. package/dist/workflow/host.d.ts.map +0 -1
  283. package/dist/workflow/host.js +0 -363
  284. package/dist/workflow/host.js.map +0 -1
  285. package/dist/workflow/journal.d.ts +0 -98
  286. package/dist/workflow/journal.d.ts.map +0 -1
  287. package/dist/workflow/journal.js +0 -121
  288. package/dist/workflow/journal.js.map +0 -1
  289. package/dist/workflow/json-schema.d.ts +0 -52
  290. package/dist/workflow/json-schema.d.ts.map +0 -1
  291. package/dist/workflow/json-schema.js +0 -112
  292. package/dist/workflow/json-schema.js.map +0 -1
  293. package/dist/workflow/meta.d.ts +0 -68
  294. package/dist/workflow/meta.d.ts.map +0 -1
  295. package/dist/workflow/meta.js +0 -318
  296. package/dist/workflow/meta.js.map +0 -1
  297. package/dist/workflow/progress.d.ts +0 -225
  298. package/dist/workflow/progress.d.ts.map +0 -1
  299. package/dist/workflow/progress.js +0 -362
  300. package/dist/workflow/progress.js.map +0 -1
  301. package/dist/workflow/runtime.d.ts +0 -335
  302. package/dist/workflow/runtime.d.ts.map +0 -1
  303. package/dist/workflow/runtime.js +0 -831
  304. package/dist/workflow/runtime.js.map +0 -1
  305. package/dist/workflow/saved.d.ts +0 -91
  306. package/dist/workflow/saved.d.ts.map +0 -1
  307. package/dist/workflow/saved.js +0 -204
  308. package/dist/workflow/saved.js.map +0 -1
  309. package/dist/workflow/task.d.ts +0 -137
  310. package/dist/workflow/task.d.ts.map +0 -1
  311. package/dist/workflow/task.js +0 -208
  312. package/dist/workflow/task.js.map +0 -1
  313. package/dist/workflow/tool-description.d.ts +0 -39
  314. package/dist/workflow/tool-description.d.ts.map +0 -1
  315. package/dist/workflow/tool-description.js +0 -200
  316. package/dist/workflow/tool-description.js.map +0 -1
  317. package/dist/workflow/worker-source.d.ts +0 -48
  318. package/dist/workflow/worker-source.d.ts.map +0 -1
  319. package/dist/workflow/worker-source.js +0 -779
  320. package/dist/workflow/worker-source.js.map +0 -1
  321. package/dist/worktree.d.ts +0 -53
  322. package/dist/worktree.d.ts.map +0 -1
  323. package/dist/worktree.js +0 -165
  324. package/dist/worktree.js.map +0 -1
  325. package/dist/write-execution.d.ts +0 -42
  326. package/dist/write-execution.d.ts.map +0 -1
  327. package/dist/write-execution.js +0 -138
  328. package/dist/write-execution.js.map +0 -1
  329. package/dist/xml.d.ts +0 -11
  330. package/dist/xml.d.ts.map +0 -1
  331. package/dist/xml.js +0 -13
  332. package/dist/xml.js.map +0 -1
  333. package/src/abortable.ts +0 -43
  334. package/src/agent-color.ts +0 -161
  335. package/src/agent-file-toggle.ts +0 -269
  336. package/src/child-context.ts +0 -15
  337. package/src/mention-clone.ts +0 -196
  338. package/src/mention.ts +0 -141
  339. package/src/model-scope.ts +0 -70
  340. package/src/nested-tools.ts +0 -424
  341. package/src/structured-output.ts +0 -130
  342. package/src/ui/agent-mention.ts +0 -216
  343. package/src/ui/select-item.ts +0 -45
  344. package/src/ui/workflow-card.ts +0 -470
  345. package/src/ui/workflow-dialog.ts +0 -1115
  346. package/src/ui/workflow-menu.ts +0 -166
  347. package/src/workflow/collisions.ts +0 -123
  348. package/src/workflow/entry.ts +0 -47
  349. package/src/workflow/host.ts +0 -403
  350. package/src/workflow/journal.ts +0 -164
  351. package/src/workflow/json-schema.ts +0 -128
  352. package/src/workflow/meta.ts +0 -325
  353. package/src/workflow/progress.ts +0 -550
  354. package/src/workflow/runtime.ts +0 -1219
  355. package/src/workflow/saved.ts +0 -217
  356. package/src/workflow/task.ts +0 -302
  357. package/src/workflow/tool-description.ts +0 -200
  358. package/src/workflow/worker-source.ts +0 -781
  359. package/src/xml.ts +0 -13
@@ -7,9 +7,10 @@
7
7
 
8
8
  import { createCodingTools, createReadOnlyTools } from "@earendil-works/pi-coding-agent";
9
9
  import { DEFAULT_AGENTS } from "./default-agents.js";
10
- import { applyNicoOverride, applyNicoOverridesToMap, readNicoAgentOverrides } from "./nico-overrides.js";
10
+ import { applyNicoOverridesToMap, readNicoAgentOverrides } from "./nico-overrides.js";
11
11
  import type { AgentConfig } from "./types.js";
12
12
 
13
+
13
14
  /**
14
15
  * All known built-in tool names, derived from pi's own tool factories rather
15
16
  * than hardcoded so the set tracks pi-mono if it adds/renames a built-in.
@@ -34,41 +35,6 @@ export function isDefaultsDisabled(): boolean { return disableDefaults; }
34
35
  /** Set whether default agents are disabled. */
35
36
  export function setDefaultsDisabled(b: boolean): void { disableDefaults = b; }
36
37
 
37
- /** `fallbackSubagent` value that disables the fallback entirely (strict dispatch). */
38
- export const NO_FALLBACK = "none";
39
-
40
- /**
41
- * Agent type substituted when a caller-supplied `subagent_type` doesn't resolve
42
- * to exactly one enabled agent. `undefined` keeps the historical behavior
43
- * (general-purpose); `NO_FALLBACK` makes dispatch fail closed. Set from
44
- * `subagents.json` (`fallbackSubagent`).
45
- *
46
- * Module state rather than an index.ts closure because every caller-supplied
47
- * spawn path needs it — the Agent tool, the scheduler, and cross-extension RPC.
48
- */
49
- let fallbackSubagent: string | undefined;
50
-
51
- /** Get the configured fallback agent type. undefined = general-purpose. */
52
- export function getFallbackSubagent(): string | undefined { return fallbackSubagent; }
53
-
54
- /** Set the configured fallback agent type. undefined = general-purpose. */
55
- export function setFallbackSubagent(v: string | undefined): void { fallbackSubagent = v; }
56
-
57
- /**
58
- * Build a registry map: DEFAULT_AGENTS first (unless disabled via settings),
59
- * then user agents overlaid on top (same name overrides the default).
60
- * Pure — callers that must not disturb the process-wide registry (nested
61
- * delegation resolving agents from its own config root) build their own map.
62
- */
63
- export function buildAgentRegistry(userAgents: Map<string, AgentConfig>): Map<string, AgentConfig> {
64
- const registry = new Map<string, AgentConfig>();
65
- if (!disableDefaults) {
66
- for (const [name, config] of DEFAULT_AGENTS) registry.set(name, config);
67
- }
68
- for (const [name, config] of userAgents) registry.set(name, config);
69
- return registry;
70
- }
71
-
72
38
  /**
73
39
  * Register agents into the unified registry.
74
40
  * Starts with DEFAULT_AGENTS, then overlays user agents (overrides defaults with same name).
@@ -76,163 +42,39 @@ export function buildAgentRegistry(userAgents: Map<string, AgentConfig>): Map<st
76
42
  */
77
43
  export function registerAgents(userAgents: Map<string, AgentConfig>): void {
78
44
  agents.clear();
79
- for (const [name, config] of buildAgentRegistry(userAgents)) {
80
- agents.set(name, config);
81
- }
82
- const { overrides, defaultModel } = readNicoAgentOverrides(process.cwd());
45
+
46
+ // Start with defaults (unless disabled via settings)
83
47
  if (!disableDefaults) {
84
- applyNicoOverridesToMap(agents, overrides, defaultModel);
85
- } else {
86
- // Disabling built-ins must also prevent JSON-only built-ins from being
87
- // synthesized; explicit user agents remain eligible for their overrides.
88
- for (const [name, config] of agents) {
89
- const override = overrides[name];
90
- if (override) agents.set(name, applyNicoOverride(config, override, defaultModel));
48
+ for (const [name, config] of DEFAULT_AGENTS) {
49
+ agents.set(name, config);
91
50
  }
92
51
  }
93
- }
94
52
 
95
- /** Case-insensitive key resolution within a registry. */
96
- function resolveKeyIn(registry: Map<string, AgentConfig>, name: string): string | undefined {
97
- if (registry.has(name)) return name;
98
- const lower = name.toLowerCase();
99
- for (const key of registry.keys()) {
100
- if (key.toLowerCase() === lower) return key;
53
+ // Overlay user agents (overrides defaults with same name)
54
+ for (const [name, config] of userAgents) {
55
+ agents.set(name, config);
101
56
  }
102
- return undefined;
103
- }
104
-
105
- /** Case-insensitive key resolution. */
106
- function resolveKey(name: string): string | undefined {
107
- return resolveKeyIn(agents, name);
108
- }
109
-
110
- /** Resolve a type name case-insensitively in a registry. Returns the canonical key or undefined. */
111
- export function resolveTypeIn(registry: Map<string, AgentConfig>, name: string): string | undefined {
112
- return resolveKeyIn(registry, name);
113
- }
114
-
115
- /** Get the agent config for a type (case-insensitive) from a registry. */
116
- export function getAgentConfigIn(registry: Map<string, AgentConfig>, name: string): AgentConfig | undefined {
117
- const key = resolveKeyIn(registry, name);
118
- return key ? registry.get(key) : undefined;
119
- }
120
-
121
- /** Check if a type is valid and enabled (case-insensitive) in a registry. */
122
- export function isValidTypeIn(registry: Map<string, AgentConfig>, type: string): boolean {
123
- const key = resolveKeyIn(registry, type);
124
- if (!key) return false;
125
- return registry.get(key)?.enabled !== false;
126
- }
127
-
128
- /** Get all enabled type names in a registry (for spawning and tool descriptions). */
129
- export function getAvailableTypesIn(registry: Map<string, AgentConfig>): string[] {
130
- return [...registry.entries()]
131
- .filter(([_, config]) => config.enabled !== false)
132
- .map(([name]) => name);
133
57
  }
134
58
 
135
59
  /**
136
- * Case-insensitive resolution that refuses to guess. An exact match always wins;
137
- * otherwise the name must match exactly one key. Two agents differing only in
138
- * case are reachable (`loadCustomAgents` keys by filename across three
139
- * directories), and picking whichever came first would silently dispatch a
140
- * different agent, model and tool policy than the caller meant.
60
+ * Apply npm:pi-subagents-style JSON overrides to the current agent registry.
61
+ * Reads from ~/.pi/agent/settings.json and .pi/settings.json and applies
62
+ * them as the highest-priority layer. Auto-registers agents that don't
63
+ * exist in the registry yet.
141
64
  */
142
- function resolveUnambiguousKeyIn(registry: Map<string, AgentConfig>, name: string): string | undefined {
143
- if (registry.has(name)) return name;
144
- const lower = name.toLowerCase();
145
- const matches = [...registry.keys()].filter(key => key.toLowerCase() === lower);
146
- return matches.length === 1 ? matches[0] : undefined;
147
- }
148
-
149
- /**
150
- * The canonical key for a caller-supplied name that identifies exactly one
151
- * ENABLED agent, or undefined. Strict by construction: no fallback, no guessing
152
- * between case-variants. Nested delegation resolves with this directly, since
153
- * "unknown types are rejected rather than falling back" is its own contract.
154
- */
155
- export function resolveEnabledTypeIn(
156
- registry: Map<string, AgentConfig>,
157
- requested: unknown,
158
- ): string | undefined {
159
- const raw = typeof requested === "string" ? requested.trim() : "";
160
- if (!raw) return undefined;
161
- const key = resolveUnambiguousKeyIn(registry, raw);
162
- return key !== undefined && registry.get(key)?.enabled !== false ? key : undefined;
65
+ export function applyNicoOverrides(): void {
66
+ const { overrides, defaultModel } = readNicoAgentOverrides(process.cwd());
67
+ applyNicoOverridesToMap(agents, overrides, defaultModel);
163
68
  }
164
69
 
165
- /** Outcome of resolving a caller-supplied `subagent_type` into a spawnable type. */
166
- export type SpawnTypeResolution =
167
- /** Spawn this type. `fellBackFrom` is set when it isn't what the caller asked for. */
168
- | { ok: true; type: string; fellBackFrom?: string }
169
- /** Refuse the spawn and return this message to the caller. */
170
- | { ok: false; message: string };
171
-
172
- /**
173
- * Resolve a caller-supplied agent type against a registry, applying the
174
- * `fallbackSubagent` policy. The single decision point for every caller-supplied
175
- * spawn — the Agent tool, the scheduler, cross-extension RPC, and the nested
176
- * tools — so a type that fails here never reaches `runAgent`, where `getConfig`
177
- * would silently substitute general-purpose.
178
- *
179
- * Unknown, disabled, and case-ambiguous names are all treated the same way:
180
- * the caller named something that doesn't identify exactly one enabled agent.
181
- *
182
- * Pure over `registry` — callers that need fresh agent files reload before
183
- * calling (the Agent tool already does, per spawn). Reloading here would mean
184
- * importing custom-agents.ts, which imports this module.
185
- */
186
- export function resolveSpawnTypeIn(
187
- registry: Map<string, AgentConfig>,
188
- requested: unknown,
189
- ): SpawnTypeResolution {
190
- const raw = typeof requested === "string" ? requested.trim() : "";
191
- const available = () => getAvailableTypesIn(registry).join(", ") || "(none)";
192
-
193
- const key = resolveEnabledTypeIn(registry, raw);
194
- if (key !== undefined) return { ok: true, type: key };
195
-
196
- // A missing type follows the same policy as a wrong one rather than always
197
- // erroring: before this setting existed an empty type fell back like any
198
- // other unresolvable name, and only opting in should change that.
199
- const reason = raw ? `Unknown or disabled agent type: "${raw}".` : "No agent type given.";
200
-
201
- // Trimmed like `requested`: a padded value set programmatically would
202
- // otherwise be reported as a missing agent.
203
- const configured = typeof fallbackSubagent === "string" ? fallbackSubagent.trim() : undefined;
204
-
205
- if (configured !== undefined && configured.toLowerCase() === NO_FALLBACK) {
206
- return { ok: false, message: `${reason} Available: ${available()}.` };
207
- }
208
-
209
- if (configured !== undefined) {
210
- // An explicitly configured fallback that is itself unusable is a
211
- // misconfiguration, not a second chance to guess — say so rather than
212
- // quietly dropping to general-purpose.
213
- const fallbackKey = resolveUnambiguousKeyIn(registry, configured);
214
- if (fallbackKey === undefined || registry.get(fallbackKey)?.enabled === false) {
215
- return {
216
- ok: false,
217
- message:
218
- `${reason} The configured fallbackSubagent "${configured}" is itself ` +
219
- `unknown or disabled. Available: ${available()}.`,
220
- };
221
- }
222
- return { ok: true, type: fallbackKey, fellBackFrom: raw };
70
+ /** Case-insensitive key resolution. */
71
+ function resolveKey(name: string): string | undefined {
72
+ if (agents.has(name)) return name;
73
+ const lower = name.toLowerCase();
74
+ for (const key of agents.keys()) {
75
+ if (key.toLowerCase() === lower) return key;
223
76
  }
224
-
225
- // Unset: historical behavior, deliberately unchanged. #183 asks for the
226
- // fallback to remain the default, so the pre-existing hole it leaves — an
227
- // unregistered general-purpose resolving to `getConfig`'s all-tools hardcoded
228
- // tier — is what `fallbackSubagent: none` is for, not something to close
229
- // under everyone silently.
230
- return { ok: true, type: "general-purpose", fellBackFrom: raw };
231
- }
232
-
233
- /** Resolve a caller-supplied agent type against the process-wide registry. */
234
- export function resolveSpawnType(requested: unknown): SpawnTypeResolution {
235
- return resolveSpawnTypeIn(agents, requested);
77
+ return undefined;
236
78
  }
237
79
 
238
80
  /** Resolve a type name case-insensitively. Returns the canonical key or undefined. */
@@ -242,12 +84,15 @@ export function resolveType(name: string): string | undefined {
242
84
 
243
85
  /** Get the agent config for a type (case-insensitive). */
244
86
  export function getAgentConfig(name: string): AgentConfig | undefined {
245
- return getAgentConfigIn(agents, name);
87
+ const key = resolveKey(name);
88
+ return key ? agents.get(key) : undefined;
246
89
  }
247
90
 
248
91
  /** Get all enabled type names (for spawning and tool descriptions). */
249
92
  export function getAvailableTypes(): string[] {
250
- return getAvailableTypesIn(agents);
93
+ return [...agents.entries()]
94
+ .filter(([_, config]) => config.enabled !== false)
95
+ .map(([name]) => name);
251
96
  }
252
97
 
253
98
  /** Get all type names including disabled (for UI listing). */
@@ -265,13 +110,15 @@ export function getDefaultAgentNames(): string[] {
265
110
  /** Get names of user-defined agents (non-defaults) currently in the registry. */
266
111
  export function getUserAgentNames(): string[] {
267
112
  return [...agents.entries()]
268
- .filter(([_, config]) => config.isDefault !== true && !config.description.startsWith("Auto-registered from npm:pi-subagents JSON settings"))
113
+ .filter(([_, config]) => config.isDefault !== true)
269
114
  .map(([name]) => name);
270
115
  }
271
116
 
272
117
  /** Check if a type is valid and enabled (case-insensitive). */
273
118
  export function isValidType(type: string): boolean {
274
- return isValidTypeIn(agents, type);
119
+ const key = resolveKey(type);
120
+ if (!key) return false;
121
+ return agents.get(key)?.enabled !== false;
275
122
  }
276
123
 
277
124
  /** Tool names required for memory management. */
@@ -307,7 +154,6 @@ export function getToolNamesForType(type: string): string[] {
307
154
  /** Get config for a type (case-insensitive, returns a SubagentTypeConfig-compatible object). Falls back to general-purpose. */
308
155
  export function getConfig(type: string): {
309
156
  displayName: string;
310
- color?: string;
311
157
  description: string;
312
158
  builtinToolNames: string[];
313
159
  extensions: true | string[] | false;
@@ -320,7 +166,6 @@ export function getConfig(type: string): {
320
166
  if (config && config.enabled !== false) {
321
167
  return {
322
168
  displayName: config.displayName ?? config.name,
323
- color: config.color,
324
169
  description: config.description,
325
170
  builtinToolNames: config.builtinToolNames ?? BUILTIN_TOOL_NAMES,
326
171
  extensions: config.extensions,
@@ -335,7 +180,6 @@ export function getConfig(type: string): {
335
180
  if (gp && gp.enabled !== false) {
336
181
  return {
337
182
  displayName: gp.displayName ?? gp.name,
338
- color: gp.color,
339
183
  description: gp.description,
340
184
  builtinToolNames: gp.builtinToolNames ?? BUILTIN_TOOL_NAMES,
341
185
  extensions: gp.extensions,
@@ -1,22 +1,15 @@
1
1
  /**
2
2
  * Cross-extension RPC handlers for the subagents extension.
3
3
  *
4
- * Exposes ping, spawn, stop, and consume RPCs over the pi.events event bus,
4
+ * Exposes ping, spawn, and stop RPCs over the pi.events event bus,
5
5
  * using per-request scoped reply channels.
6
6
  *
7
7
  * Reply envelope follows pi-mono convention:
8
8
  * success → { success: true, data?: T }
9
9
  * error → { success: false, error: string }
10
- *
11
- * @see docs/rpc.md — the caller-facing integration reference: spawn options
12
- * (including the fields spawnTopLevel strips), every error string, the
13
- * completion-notification race, and what protocol version 2 does not promise.
14
10
  */
15
11
 
16
- import { isTopLevelAgent } from "./agent-manager.js";
17
12
  import { type ModelRegistry, resolveModel } from "./model-resolver.js";
18
- import { checkModelScope } from "./model-scope.js";
19
- import type { AgentRecord } from "./types.js";
20
13
 
21
14
  /** Minimal event bus interface needed by the RPC handlers. */
22
15
  export interface EventBus {
@@ -32,24 +25,10 @@ export type RpcReply<T = void> =
32
25
  /** RPC protocol version — bumped when the envelope or method contracts change. */
33
26
  export const PROTOCOL_VERSION = 2;
34
27
 
35
- /** Minimal AgentManager interface needed by the spawn/stop/consume RPCs. */
28
+ /** Minimal AgentManager interface needed by the spawn/stop RPCs. */
36
29
  export interface SpawnCapable {
37
30
  spawn(pi: unknown, ctx: unknown, type: string, prompt: string, options: any): string;
38
- /** Resolves once the spawned agent is running; rejects on a startup failure. */
39
- awaitStartup(id: string): Promise<void>;
40
31
  abort(id: string): boolean;
41
- /**
42
- * The record behind an id, for the stop handler's ownership check. Narrowed
43
- * to the two fields `isTopLevelAgent` reads, so the RPC layer keeps its
44
- * deliberately shallow view of the manager.
45
- */
46
- getRecord(id: string): Pick<AgentRecord, "parentAgentId" | "workflowId"> | undefined;
47
- /**
48
- * Mark a settled agent's result as read by the caller, suppressing the
49
- * completion notification — what `get_subagent_result` does when it returns
50
- * one. False when there is no such agent, or it has not settled yet.
51
- */
52
- consumeResult(id: string): boolean;
53
32
  }
54
33
 
55
34
  export interface RpcDeps {
@@ -63,7 +42,6 @@ export interface RpcHandle {
63
42
  unsubPing: () => void;
64
43
  unsubSpawn: () => void;
65
44
  unsubStop: () => void;
66
- unsubConsume: () => void;
67
45
  }
68
46
 
69
47
  /**
@@ -91,7 +69,7 @@ function handleRpc<P extends { requestId: string }>(
91
69
  }
92
70
 
93
71
  /**
94
- * Register ping, spawn, stop, and consume RPC handlers on the event bus.
72
+ * Register ping, spawn, and stop RPC handlers on the event bus.
95
73
  * Returns unsub functions for cleanup.
96
74
  */
97
75
  export function registerRpcHandlers(deps: RpcDeps): RpcHandle {
@@ -102,7 +80,7 @@ export function registerRpcHandlers(deps: RpcDeps): RpcHandle {
102
80
  });
103
81
 
104
82
  const unsubSpawn = handleRpc<{ requestId: string; type: string; prompt: string; options?: any }>(
105
- events, "subagents:rpc:spawn", async ({ type, prompt, options }) => {
83
+ events, "subagents:rpc:spawn", ({ type, prompt, options }) => {
106
84
  const ctx = getCtx();
107
85
  if (!ctx) throw new Error("No active session");
108
86
 
@@ -113,86 +91,32 @@ export function registerRpcHandlers(deps: RpcDeps): RpcHandle {
113
91
  // agent's auth lookup doesn't crash with "No API key found for
114
92
  // undefined".
115
93
  let normalizedOptions = options ?? {};
116
- // `!= null` on purpose: a JSON-forwarding caller can serialize an unset
117
- // field as null, and the runner reads `options.model ?? default`, so null
118
- // means "inherit" — not an override to resolve or scope-check.
119
- const override = normalizedOptions.model;
120
- if (override != null) {
121
- const { modelRegistry, cwd } = ctx as { modelRegistry?: ModelRegistry; cwd?: string };
122
- // Names the override the same way in both messages below; an object
123
- // override would otherwise interpolate as "[object Object]".
124
- const label = typeof override === "string" ? override : `${override.provider}/${override.id}`;
125
- if (!modelRegistry) {
126
- throw new Error(`Model override "${label}" provided but ctx.modelRegistry is unavailable`);
94
+ if (typeof normalizedOptions.model === "string") {
95
+ const registry = (ctx as { modelRegistry?: ModelRegistry }).modelRegistry;
96
+ if (!registry) {
97
+ throw new Error(
98
+ `Model override "${normalizedOptions.model}" provided but ctx.modelRegistry is unavailable`,
99
+ );
127
100
  }
128
- let model = override;
129
- if (typeof override === "string") {
130
- const resolved = resolveModel(override, modelRegistry);
131
- if (typeof resolved === "string") {
132
- // resolveModel returns a human-readable error string when the
133
- // input doesn't match any available model. Surface it instead of
134
- // silently falling back so the caller sees the auth/typo issue.
135
- throw new Error(resolved);
136
- }
137
- model = resolved;
138
- normalizedOptions = { ...normalizedOptions, model: resolved };
101
+ const resolved = resolveModel(normalizedOptions.model, registry);
102
+ if (typeof resolved === "string") {
103
+ // resolveModel returns a human-readable error string when the
104
+ // input doesn't match any available model. Surface it instead of
105
+ // silently falling back so the caller sees the auth/typo issue.
106
+ throw new Error(resolved);
139
107
  }
140
-
141
- // A model on the RPC payload is an orchestrator-level choice, exactly
142
- // like Agent({ model }) — so it gets the Agent tool's hard error, never
143
- // the frontmatter warn (#240). The check reads the RESOLVED model:
144
- // resolveModel is fuzzy, so a bare "sonnet" can land on a provider the
145
- // caller never named. Frontmatter-pinned and parent-inherited models are
146
- // resolved later, in agent-runner, and keep warn-and-proceed.
147
- const verdict = checkModelScope({
148
- model,
149
- cwd: cwd ?? process.cwd(),
150
- modelRegistry,
151
- callerSupplied: true,
152
- agentLabel: type,
153
- modelInput: label,
154
- });
155
- if (verdict.kind === "error") throw new Error(verdict.message);
108
+ normalizedOptions = { ...normalizedOptions, model: resolved };
156
109
  }
157
110
 
158
- const id = manager.spawn(pi, ctx, type, prompt, normalizedOptions);
159
- // With isolation: "worktree" the agent starts asynchronously — wait for
160
- // it, so a strict-isolation failure is still an error envelope rather
161
- // than an id for an agent that never ran.
162
- await manager.awaitStartup(id);
163
- return { id };
111
+ return { id: manager.spawn(pi, ctx, type, prompt, normalizedOptions) };
164
112
  },
165
113
  );
166
114
 
167
115
  const unsubStop = handleRpc<{ requestId: string; agentId: string }>(
168
116
  events, "subagents:rpc:stop", ({ agentId }) => {
169
- const record = manager.getRecord(agentId);
170
- if (!record) throw new Error("Agent not found");
171
- // Only the session's own agents are this RPC's to stop. A nested child or
172
- // a workflow's agent is owned by something that is *waiting on it*, and
173
- // aborting it out from under that owner turns another extension's stop
174
- // into a failed step here. Defence in depth rather than a live hole: no
175
- // RPC hands out agent ids, so a caller has no ordinary way to name one it
176
- // does not own — but the guard is cheap and the id may leak some other
177
- // way. Same refuse-what-we-should-not-touch stance as `consume` below.
178
- if (!isTopLevelAgent(record)) throw new Error("Agent is owned by another agent or workflow");
179
- // Not "not found" — the lookup above already proved it exists. `abort`
180
- // returns false only for a record that is neither running nor queued,
181
- // which is an agent that has already finished.
182
- if (!manager.abort(agentId)) throw new Error("Agent is not running");
183
- },
184
- );
185
-
186
- // A caller that has already shown the model an agent's result — pi-tasks'
187
- // TaskOutput is the one in practice — says so here, so the completion
188
- // notification for that same result is not delivered on top of it and does
189
- // not cost the parent a turn. Deliberately outside the ping version
190
- // handshake: an extension built against protocol v2 simply never calls it.
191
- const unsubConsume = handleRpc<{ requestId: string; agentId: string }>(
192
- events, "subagents:rpc:consume", ({ agentId }) => {
193
- if (!manager.consumeResult(agentId)) throw new Error("Agent not found or still running");
117
+ if (!manager.abort(agentId)) throw new Error("Agent not found");
194
118
  },
195
119
  );
196
120
 
197
- return { unsubPing, unsubSpawn, unsubStop, unsubConsume };
121
+ return { unsubPing, unsubSpawn, unsubStop };
198
122
  }