@esso0428/pi-subagents 0.17.16 → 0.17.17
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.
- package/CHANGELOG.md +6 -0
- package/ROADMAP.md +87 -0
- package/docs/post-0.17.6-agents-roster-viewer-spec.md +42 -0
- package/docs/post-0.17.6-durable-history-spec.md +41 -0
- package/docs/post-0.17.6-feature-specs.md +50 -0
- package/docs/post-0.17.6-nested-agents-spec.md +38 -0
- package/docs/post-0.17.6-recovery-shutdown-spec.md +46 -0
- package/docs/post-0.17.6-ui-latency-baseline-spec.md +46 -0
- package/docs/post-0.17.6-workflow-rpc-lifecycle-spec.md +54 -0
- package/package.json +1 -1
- package/src/agent-history.ts +2 -54
- package/src/agent-manager.ts +406 -1288
- package/src/agent-runner.ts +27 -251
- package/src/agent-types.ts +32 -188
- package/src/cross-extension-rpc.ts +20 -96
- package/src/custom-agents.ts +13 -170
- package/src/index.ts +480 -1920
- package/src/invocation-config.ts +3 -118
- package/src/model-resolver.ts +0 -18
- package/src/output-file.ts +6 -61
- package/src/prompts.ts +2 -45
- package/src/schedule.ts +14 -35
- package/src/settings.ts +2 -301
- package/src/status-note.ts +1 -66
- package/src/types.ts +10 -177
- package/src/ui/agent-widget.ts +57 -278
- package/src/ui/conversation-blocks.ts +0 -6
- package/src/ui/conversation-timeline.ts +25 -139
- package/src/ui/conversation-viewer.ts +48 -212
- package/src/ui/schedule-menu.ts +8 -9
- package/src/usage.ts +2 -109
- package/src/worktree.ts +55 -69
- package/dist/abortable.d.ts +0 -13
- package/dist/abortable.d.ts.map +0 -1
- package/dist/abortable.js +0 -43
- package/dist/abortable.js.map +0 -1
- package/dist/agent-color.d.ts +0 -36
- package/dist/agent-color.d.ts.map +0 -1
- package/dist/agent-color.js +0 -124
- package/dist/agent-color.js.map +0 -1
- package/dist/agent-file-toggle.d.ts +0 -126
- package/dist/agent-file-toggle.d.ts.map +0 -1
- package/dist/agent-file-toggle.js +0 -259
- package/dist/agent-file-toggle.js.map +0 -1
- package/dist/agent-history-list.d.ts +0 -19
- package/dist/agent-history-list.d.ts.map +0 -1
- package/dist/agent-history-list.js +0 -69
- package/dist/agent-history-list.js.map +0 -1
- package/dist/agent-history.d.ts +0 -35
- package/dist/agent-history.d.ts.map +0 -1
- package/dist/agent-history.js +0 -188
- package/dist/agent-history.js.map +0 -1
- package/dist/agent-manager.d.ts +0 -503
- package/dist/agent-manager.d.ts.map +0 -1
- package/dist/agent-manager.js +0 -1572
- package/dist/agent-manager.js.map +0 -1
- package/dist/agent-recovery.d.ts +0 -37
- package/dist/agent-recovery.d.ts.map +0 -1
- package/dist/agent-recovery.js +0 -171
- package/dist/agent-recovery.js.map +0 -1
- package/dist/agent-runner.d.ts +0 -303
- package/dist/agent-runner.d.ts.map +0 -1
- package/dist/agent-runner.js +0 -1003
- package/dist/agent-runner.js.map +0 -1
- package/dist/agent-types.d.ts +0 -120
- package/dist/agent-types.d.ts.map +0 -1
- package/dist/agent-types.js +0 -301
- package/dist/agent-types.js.map +0 -1
- package/dist/child-context.d.ts +0 -3
- package/dist/child-context.d.ts.map +0 -1
- package/dist/child-context.js +0 -13
- package/dist/child-context.js.map +0 -1
- package/dist/context.d.ts +0 -13
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js +0 -57
- package/dist/context.js.map +0 -1
- package/dist/cross-extension-rpc.d.ts +0 -67
- package/dist/cross-extension-rpc.d.ts.map +0 -1
- package/dist/cross-extension-rpc.js +0 -139
- package/dist/cross-extension-rpc.js.map +0 -1
- package/dist/custom-agents.d.ts +0 -55
- package/dist/custom-agents.d.ts.map +0 -1
- package/dist/custom-agents.js +0 -309
- package/dist/custom-agents.js.map +0 -1
- package/dist/default-agents.d.ts +0 -8
- package/dist/default-agents.d.ts.map +0 -1
- package/dist/default-agents.js +0 -123
- package/dist/default-agents.js.map +0 -1
- package/dist/enabled-models.d.ts +0 -50
- package/dist/enabled-models.d.ts.map +0 -1
- package/dist/enabled-models.js +0 -146
- package/dist/enabled-models.js.map +0 -1
- package/dist/env.d.ts +0 -7
- package/dist/env.d.ts.map +0 -1
- package/dist/env.js +0 -29
- package/dist/env.js.map +0 -1
- package/dist/group-join.d.ts +0 -33
- package/dist/group-join.d.ts.map +0 -1
- package/dist/group-join.js +0 -117
- package/dist/group-join.js.map +0 -1
- package/dist/index.d.ts +0 -51
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -3687
- package/dist/index.js.map +0 -1
- package/dist/invocation-config.d.ts +0 -108
- package/dist/invocation-config.d.ts.map +0 -1
- package/dist/invocation-config.js +0 -84
- package/dist/invocation-config.js.map +0 -1
- package/dist/memory.d.ts +0 -54
- package/dist/memory.d.ts.map +0 -1
- package/dist/memory.js +0 -166
- package/dist/memory.js.map +0 -1
- package/dist/mention-clone.d.ts +0 -88
- package/dist/mention-clone.d.ts.map +0 -1
- package/dist/mention-clone.js +0 -154
- package/dist/mention-clone.js.map +0 -1
- package/dist/mention.d.ts +0 -82
- package/dist/mention.d.ts.map +0 -1
- package/dist/mention.js +0 -132
- package/dist/mention.js.map +0 -1
- package/dist/model-resolver.d.ts +0 -37
- package/dist/model-resolver.d.ts.map +0 -1
- package/dist/model-resolver.js +0 -96
- package/dist/model-resolver.js.map +0 -1
- package/dist/model-scope.d.ts +0 -50
- package/dist/model-scope.d.ts.map +0 -1
- package/dist/model-scope.js +0 -49
- package/dist/model-scope.js.map +0 -1
- package/dist/nested-tools.d.ts +0 -57
- package/dist/nested-tools.d.ts.map +0 -1
- package/dist/nested-tools.js +0 -301
- package/dist/nested-tools.js.map +0 -1
- package/dist/nico-overrides.d.ts +0 -54
- package/dist/nico-overrides.d.ts.map +0 -1
- package/dist/nico-overrides.js +0 -170
- package/dist/nico-overrides.js.map +0 -1
- package/dist/output-file.d.ts +0 -44
- package/dist/output-file.d.ts.map +0 -1
- package/dist/output-file.js +0 -156
- package/dist/output-file.js.map +0 -1
- package/dist/prompts.d.ts +0 -56
- package/dist/prompts.d.ts.map +0 -1
- package/dist/prompts.js +0 -92
- package/dist/prompts.js.map +0 -1
- package/dist/schedule-store.d.ts +0 -39
- package/dist/schedule-store.d.ts.map +0 -1
- package/dist/schedule-store.js +0 -156
- package/dist/schedule-store.js.map +0 -1
- package/dist/schedule.d.ts +0 -110
- package/dist/schedule.d.ts.map +0 -1
- package/dist/schedule.js +0 -360
- package/dist/schedule.js.map +0 -1
- package/dist/settings.d.ts +0 -354
- package/dist/settings.d.ts.map +0 -1
- package/dist/settings.js +0 -247
- package/dist/settings.js.map +0 -1
- package/dist/skill-loader.d.ts +0 -25
- package/dist/skill-loader.d.ts.map +0 -1
- package/dist/skill-loader.js +0 -94
- package/dist/skill-loader.js.map +0 -1
- package/dist/status-note.d.ts +0 -62
- package/dist/status-note.d.ts.map +0 -1
- package/dist/status-note.js +0 -86
- package/dist/status-note.js.map +0 -1
- package/dist/structured-output.d.ts +0 -62
- package/dist/structured-output.d.ts.map +0 -1
- package/dist/structured-output.js +0 -113
- package/dist/structured-output.js.map +0 -1
- package/dist/types.d.ts +0 -372
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -6
- package/dist/types.js.map +0 -1
- package/dist/ui/agent-mention.d.ts +0 -83
- package/dist/ui/agent-mention.d.ts.map +0 -1
- package/dist/ui/agent-mention.js +0 -188
- package/dist/ui/agent-mention.js.map +0 -1
- package/dist/ui/agent-widget.d.ts +0 -241
- package/dist/ui/agent-widget.d.ts.map +0 -1
- package/dist/ui/agent-widget.js +0 -992
- package/dist/ui/agent-widget.js.map +0 -1
- package/dist/ui/ccstyle/diff/ansi-utils.d.ts +0 -11
- package/dist/ui/ccstyle/diff/ansi-utils.d.ts.map +0 -1
- package/dist/ui/ccstyle/diff/ansi-utils.js +0 -145
- package/dist/ui/ccstyle/diff/ansi-utils.js.map +0 -1
- package/dist/ui/ccstyle/diff/diff-presentation.d.ts +0 -12
- package/dist/ui/ccstyle/diff/diff-presentation.d.ts.map +0 -1
- package/dist/ui/ccstyle/diff/diff-presentation.js +0 -48
- package/dist/ui/ccstyle/diff/diff-presentation.js.map +0 -1
- package/dist/ui/ccstyle/diff/diff-renderer.d.ts +0 -46
- package/dist/ui/ccstyle/diff/diff-renderer.d.ts.map +0 -1
- package/dist/ui/ccstyle/diff/diff-renderer.js +0 -2049
- package/dist/ui/ccstyle/diff/diff-renderer.js.map +0 -1
- package/dist/ui/ccstyle/diff/line-width-safety.d.ts +0 -12
- package/dist/ui/ccstyle/diff/line-width-safety.d.ts.map +0 -1
- package/dist/ui/ccstyle/diff/line-width-safety.js +0 -58
- package/dist/ui/ccstyle/diff/line-width-safety.js.map +0 -1
- package/dist/ui/ccstyle/diff/render-utils.d.ts +0 -6
- package/dist/ui/ccstyle/diff/render-utils.d.ts.map +0 -1
- package/dist/ui/ccstyle/diff/render-utils.js +0 -25
- package/dist/ui/ccstyle/diff/render-utils.js.map +0 -1
- package/dist/ui/ccstyle/diff/shiki-highlight.d.ts +0 -19
- package/dist/ui/ccstyle/diff/shiki-highlight.d.ts.map +0 -1
- package/dist/ui/ccstyle/diff/shiki-highlight.js +0 -85
- package/dist/ui/ccstyle/diff/shiki-highlight.js.map +0 -1
- package/dist/ui/ccstyle/diff/types.d.ts +0 -22
- package/dist/ui/ccstyle/diff/types.d.ts.map +0 -1
- package/dist/ui/ccstyle/diff/types.js +0 -10
- package/dist/ui/ccstyle/diff/types.js.map +0 -1
- package/dist/ui/ccstyle/diff/write-display-utils.d.ts +0 -2
- package/dist/ui/ccstyle/diff/write-display-utils.d.ts.map +0 -1
- package/dist/ui/ccstyle/diff/write-display-utils.js +0 -12
- package/dist/ui/ccstyle/diff/write-display-utils.js.map +0 -1
- package/dist/ui/ccstyle/tool-renderer.d.ts +0 -17
- package/dist/ui/ccstyle/tool-renderer.d.ts.map +0 -1
- package/dist/ui/ccstyle/tool-renderer.js +0 -74
- package/dist/ui/ccstyle/tool-renderer.js.map +0 -1
- package/dist/ui/ccstyle/tool-result.d.ts +0 -44
- package/dist/ui/ccstyle/tool-result.d.ts.map +0 -1
- package/dist/ui/ccstyle/tool-result.js +0 -423
- package/dist/ui/ccstyle/tool-result.js.map +0 -1
- package/dist/ui/conversation-blocks.d.ts +0 -46
- package/dist/ui/conversation-blocks.d.ts.map +0 -1
- package/dist/ui/conversation-blocks.js +0 -313
- package/dist/ui/conversation-blocks.js.map +0 -1
- package/dist/ui/conversation-nvim.d.ts +0 -8
- package/dist/ui/conversation-nvim.d.ts.map +0 -1
- package/dist/ui/conversation-nvim.js +0 -117
- package/dist/ui/conversation-nvim.js.map +0 -1
- package/dist/ui/conversation-role.d.ts +0 -13
- package/dist/ui/conversation-role.d.ts.map +0 -1
- package/dist/ui/conversation-role.js +0 -39
- package/dist/ui/conversation-role.js.map +0 -1
- package/dist/ui/conversation-search.d.ts +0 -39
- package/dist/ui/conversation-search.d.ts.map +0 -1
- package/dist/ui/conversation-search.js +0 -124
- package/dist/ui/conversation-search.js.map +0 -1
- package/dist/ui/conversation-timeline.d.ts +0 -102
- package/dist/ui/conversation-timeline.d.ts.map +0 -1
- package/dist/ui/conversation-timeline.js +0 -555
- package/dist/ui/conversation-timeline.js.map +0 -1
- package/dist/ui/conversation-viewer.d.ts +0 -138
- package/dist/ui/conversation-viewer.d.ts.map +0 -1
- package/dist/ui/conversation-viewer.js +0 -1175
- package/dist/ui/conversation-viewer.js.map +0 -1
- package/dist/ui/schedule-menu.d.ts +0 -17
- package/dist/ui/schedule-menu.d.ts.map +0 -1
- package/dist/ui/schedule-menu.js +0 -95
- package/dist/ui/schedule-menu.js.map +0 -1
- package/dist/ui/select-item.d.ts +0 -28
- package/dist/ui/select-item.d.ts.map +0 -1
- package/dist/ui/select-item.js +0 -35
- package/dist/ui/select-item.js.map +0 -1
- package/dist/ui/viewer-keys.d.ts +0 -21
- package/dist/ui/viewer-keys.d.ts.map +0 -1
- package/dist/ui/viewer-keys.js +0 -18
- package/dist/ui/viewer-keys.js.map +0 -1
- package/dist/ui/workflow-card.d.ts +0 -176
- package/dist/ui/workflow-card.d.ts.map +0 -1
- package/dist/ui/workflow-card.js +0 -333
- package/dist/ui/workflow-card.js.map +0 -1
- package/dist/ui/workflow-dialog.d.ts +0 -306
- package/dist/ui/workflow-dialog.d.ts.map +0 -1
- package/dist/ui/workflow-dialog.js +0 -844
- package/dist/ui/workflow-dialog.js.map +0 -1
- package/dist/ui/workflow-menu.d.ts +0 -42
- package/dist/ui/workflow-menu.d.ts.map +0 -1
- package/dist/ui/workflow-menu.js +0 -127
- package/dist/ui/workflow-menu.js.map +0 -1
- package/dist/usage.d.ts +0 -136
- package/dist/usage.d.ts.map +0 -1
- package/dist/usage.js +0 -121
- package/dist/usage.js.map +0 -1
- package/dist/workflow/collisions.d.ts +0 -96
- package/dist/workflow/collisions.d.ts.map +0 -1
- package/dist/workflow/collisions.js +0 -89
- package/dist/workflow/collisions.js.map +0 -1
- package/dist/workflow/entry.d.ts +0 -33
- package/dist/workflow/entry.d.ts.map +0 -1
- package/dist/workflow/entry.js +0 -30
- package/dist/workflow/entry.js.map +0 -1
- package/dist/workflow/host.d.ts +0 -63
- package/dist/workflow/host.d.ts.map +0 -1
- package/dist/workflow/host.js +0 -363
- package/dist/workflow/host.js.map +0 -1
- package/dist/workflow/journal.d.ts +0 -98
- package/dist/workflow/journal.d.ts.map +0 -1
- package/dist/workflow/journal.js +0 -121
- package/dist/workflow/journal.js.map +0 -1
- package/dist/workflow/json-schema.d.ts +0 -52
- package/dist/workflow/json-schema.d.ts.map +0 -1
- package/dist/workflow/json-schema.js +0 -112
- package/dist/workflow/json-schema.js.map +0 -1
- package/dist/workflow/meta.d.ts +0 -68
- package/dist/workflow/meta.d.ts.map +0 -1
- package/dist/workflow/meta.js +0 -318
- package/dist/workflow/meta.js.map +0 -1
- package/dist/workflow/progress.d.ts +0 -225
- package/dist/workflow/progress.d.ts.map +0 -1
- package/dist/workflow/progress.js +0 -362
- package/dist/workflow/progress.js.map +0 -1
- package/dist/workflow/runtime.d.ts +0 -335
- package/dist/workflow/runtime.d.ts.map +0 -1
- package/dist/workflow/runtime.js +0 -831
- package/dist/workflow/runtime.js.map +0 -1
- package/dist/workflow/saved.d.ts +0 -91
- package/dist/workflow/saved.d.ts.map +0 -1
- package/dist/workflow/saved.js +0 -204
- package/dist/workflow/saved.js.map +0 -1
- package/dist/workflow/task.d.ts +0 -137
- package/dist/workflow/task.d.ts.map +0 -1
- package/dist/workflow/task.js +0 -208
- package/dist/workflow/task.js.map +0 -1
- package/dist/workflow/tool-description.d.ts +0 -39
- package/dist/workflow/tool-description.d.ts.map +0 -1
- package/dist/workflow/tool-description.js +0 -200
- package/dist/workflow/tool-description.js.map +0 -1
- package/dist/workflow/worker-source.d.ts +0 -48
- package/dist/workflow/worker-source.d.ts.map +0 -1
- package/dist/workflow/worker-source.js +0 -779
- package/dist/workflow/worker-source.js.map +0 -1
- package/dist/worktree.d.ts +0 -53
- package/dist/worktree.d.ts.map +0 -1
- package/dist/worktree.js +0 -165
- package/dist/worktree.js.map +0 -1
- package/dist/write-execution.d.ts +0 -42
- package/dist/write-execution.d.ts.map +0 -1
- package/dist/write-execution.js +0 -138
- package/dist/write-execution.js.map +0 -1
- package/dist/xml.d.ts +0 -11
- package/dist/xml.d.ts.map +0 -1
- package/dist/xml.js +0 -13
- package/dist/xml.js.map +0 -1
- package/src/abortable.ts +0 -43
- package/src/agent-color.ts +0 -161
- package/src/agent-file-toggle.ts +0 -269
- package/src/child-context.ts +0 -15
- package/src/mention-clone.ts +0 -196
- package/src/mention.ts +0 -141
- package/src/model-scope.ts +0 -70
- package/src/nested-tools.ts +0 -424
- package/src/structured-output.ts +0 -130
- package/src/ui/agent-mention.ts +0 -216
- package/src/ui/select-item.ts +0 -45
- package/src/ui/workflow-card.ts +0 -470
- package/src/ui/workflow-dialog.ts +0 -1115
- package/src/ui/workflow-menu.ts +0 -166
- package/src/workflow/collisions.ts +0 -123
- package/src/workflow/entry.ts +0 -47
- package/src/workflow/host.ts +0 -403
- package/src/workflow/journal.ts +0 -164
- package/src/workflow/json-schema.ts +0 -128
- package/src/workflow/meta.ts +0 -325
- package/src/workflow/progress.ts +0 -550
- package/src/workflow/runtime.ts +0 -1219
- package/src/workflow/saved.ts +0 -217
- package/src/workflow/task.ts +0 -302
- package/src/workflow/tool-description.ts +0 -200
- package/src/workflow/worker-source.ts +0 -781
- package/src/xml.ts +0 -13
package/src/agent-types.ts
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
const { overrides, defaultModel } = readNicoAgentOverrides(process.cwd());
|
|
45
|
+
|
|
46
|
+
// Start with defaults (unless disabled via settings)
|
|
83
47
|
if (!disableDefaults) {
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
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
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
/**
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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,
|
|
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
|
|
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,
|
|
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",
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
|
|
129
|
-
if (typeof
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
121
|
+
return { unsubPing, unsubSpawn, unsubStop };
|
|
198
122
|
}
|