@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.
- package/CHANGELOG.md +14 -0
- package/CONTRIBUTING.md +4 -0
- package/README.md +1 -1
- package/dist/abortable.d.ts +13 -0
- package/dist/abortable.d.ts.map +1 -0
- package/dist/abortable.js +43 -0
- package/dist/abortable.js.map +1 -0
- package/dist/agent-color.d.ts +36 -0
- package/dist/agent-color.d.ts.map +1 -0
- package/dist/agent-color.js +124 -0
- package/dist/agent-color.js.map +1 -0
- package/dist/agent-file-toggle.d.ts +126 -0
- package/dist/agent-file-toggle.d.ts.map +1 -0
- package/dist/agent-file-toggle.js +259 -0
- package/dist/agent-file-toggle.js.map +1 -0
- package/dist/agent-history.d.ts +4 -0
- package/dist/agent-history.d.ts.map +1 -1
- package/dist/agent-history.js +47 -1
- package/dist/agent-history.js.map +1 -1
- package/dist/agent-manager.d.ts +370 -56
- package/dist/agent-manager.d.ts.map +1 -1
- package/dist/agent-manager.js +1123 -409
- package/dist/agent-manager.js.map +1 -1
- package/dist/agent-runner.d.ts +100 -10
- package/dist/agent-runner.d.ts.map +1 -1
- package/dist/agent-runner.js +166 -21
- package/dist/agent-runner.js.map +1 -1
- package/dist/agent-types.d.ts +57 -5
- package/dist/agent-types.d.ts.map +1 -1
- package/dist/agent-types.js +164 -32
- package/dist/agent-types.js.map +1 -1
- package/dist/child-context.d.ts +3 -0
- package/dist/child-context.d.ts.map +1 -0
- package/dist/child-context.js +13 -0
- package/dist/child-context.js.map +1 -0
- package/dist/cross-extension-rpc.d.ts +23 -3
- package/dist/cross-extension-rpc.d.ts.map +1 -1
- package/dist/cross-extension-rpc.js +79 -17
- package/dist/cross-extension-rpc.js.map +1 -1
- package/dist/custom-agents.d.ts +38 -1
- package/dist/custom-agents.d.ts.map +1 -1
- package/dist/custom-agents.js +164 -12
- package/dist/custom-agents.js.map +1 -1
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1908 -495
- package/dist/index.js.map +1 -1
- package/dist/invocation-config.d.ts +87 -2
- package/dist/invocation-config.d.ts.map +1 -1
- package/dist/invocation-config.js +71 -3
- package/dist/invocation-config.js.map +1 -1
- package/dist/mention-clone.d.ts +88 -0
- package/dist/mention-clone.d.ts.map +1 -0
- package/dist/mention-clone.js +154 -0
- package/dist/mention-clone.js.map +1 -0
- package/dist/mention.d.ts +82 -0
- package/dist/mention.d.ts.map +1 -0
- package/dist/mention.js +132 -0
- package/dist/mention.js.map +1 -0
- package/dist/model-resolver.d.ts +17 -0
- package/dist/model-resolver.d.ts.map +1 -1
- package/dist/model-resolver.js +15 -0
- package/dist/model-resolver.js.map +1 -1
- package/dist/model-scope.d.ts +50 -0
- package/dist/model-scope.d.ts.map +1 -0
- package/dist/model-scope.js +49 -0
- package/dist/model-scope.js.map +1 -0
- package/dist/nested-tools.d.ts +57 -0
- package/dist/nested-tools.d.ts.map +1 -0
- package/dist/nested-tools.js +301 -0
- package/dist/nested-tools.js.map +1 -0
- package/dist/output-file.d.ts +22 -3
- package/dist/output-file.d.ts.map +1 -1
- package/dist/output-file.js +58 -7
- package/dist/output-file.js.map +1 -1
- package/dist/prompts.d.ts +23 -0
- package/dist/prompts.d.ts.map +1 -1
- package/dist/prompts.js +20 -2
- package/dist/prompts.js.map +1 -1
- package/dist/schedule.d.ts.map +1 -1
- package/dist/schedule.js +36 -15
- package/dist/schedule.js.map +1 -1
- package/dist/settings.d.ts +228 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +94 -0
- package/dist/settings.js.map +1 -1
- package/dist/status-note.d.ts +49 -1
- package/dist/status-note.d.ts.map +1 -1
- package/dist/status-note.js +62 -1
- package/dist/status-note.js.map +1 -1
- package/dist/structured-output.d.ts +62 -0
- package/dist/structured-output.d.ts.map +1 -0
- package/dist/structured-output.js +113 -0
- package/dist/structured-output.js.map +1 -0
- package/dist/types.d.ts +176 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/agent-mention.d.ts +83 -0
- package/dist/ui/agent-mention.d.ts.map +1 -0
- package/dist/ui/agent-mention.js +188 -0
- package/dist/ui/agent-mention.js.map +1 -0
- package/dist/ui/agent-widget.d.ts +96 -75
- package/dist/ui/agent-widget.d.ts.map +1 -1
- package/dist/ui/agent-widget.js +397 -420
- package/dist/ui/agent-widget.js.map +1 -1
- package/dist/ui/conversation-blocks.d.ts.map +1 -1
- package/dist/ui/conversation-blocks.js +6 -0
- package/dist/ui/conversation-blocks.js.map +1 -1
- package/dist/ui/conversation-timeline.d.ts +10 -2
- package/dist/ui/conversation-timeline.d.ts.map +1 -1
- package/dist/ui/conversation-timeline.js +130 -23
- package/dist/ui/conversation-timeline.js.map +1 -1
- package/dist/ui/conversation-viewer.d.ts +20 -5
- package/dist/ui/conversation-viewer.d.ts.map +1 -1
- package/dist/ui/conversation-viewer.js +274 -73
- package/dist/ui/conversation-viewer.js.map +1 -1
- package/dist/ui/fleet-list.d.ts +198 -0
- package/dist/ui/fleet-list.d.ts.map +1 -0
- package/dist/ui/fleet-list.js +487 -0
- package/dist/ui/fleet-list.js.map +1 -0
- package/dist/ui/schedule-menu.d.ts.map +1 -1
- package/dist/ui/schedule-menu.js +6 -7
- package/dist/ui/schedule-menu.js.map +1 -1
- package/dist/ui/select-item.d.ts +28 -0
- package/dist/ui/select-item.d.ts.map +1 -0
- package/dist/ui/select-item.js +35 -0
- package/dist/ui/select-item.js.map +1 -0
- package/dist/ui/workflow-card.d.ts +176 -0
- package/dist/ui/workflow-card.d.ts.map +1 -0
- package/dist/ui/workflow-card.js +333 -0
- package/dist/ui/workflow-card.js.map +1 -0
- package/dist/ui/workflow-dialog.d.ts +306 -0
- package/dist/ui/workflow-dialog.d.ts.map +1 -0
- package/dist/ui/workflow-dialog.js +844 -0
- package/dist/ui/workflow-dialog.js.map +1 -0
- package/dist/ui/workflow-menu.d.ts +61 -0
- package/dist/ui/workflow-menu.d.ts.map +1 -0
- package/dist/ui/workflow-menu.js +148 -0
- package/dist/ui/workflow-menu.js.map +1 -0
- package/dist/usage.d.ts +86 -1
- package/dist/usage.d.ts.map +1 -1
- package/dist/usage.js +72 -1
- package/dist/usage.js.map +1 -1
- package/dist/workflow/collisions.d.ts +96 -0
- package/dist/workflow/collisions.d.ts.map +1 -0
- package/dist/workflow/collisions.js +89 -0
- package/dist/workflow/collisions.js.map +1 -0
- package/dist/workflow/entry.d.ts +33 -0
- package/dist/workflow/entry.d.ts.map +1 -0
- package/dist/workflow/entry.js +30 -0
- package/dist/workflow/entry.js.map +1 -0
- package/dist/workflow/host.d.ts +63 -0
- package/dist/workflow/host.d.ts.map +1 -0
- package/dist/workflow/host.js +363 -0
- package/dist/workflow/host.js.map +1 -0
- package/dist/workflow/journal.d.ts +98 -0
- package/dist/workflow/journal.d.ts.map +1 -0
- package/dist/workflow/journal.js +121 -0
- package/dist/workflow/journal.js.map +1 -0
- package/dist/workflow/json-schema.d.ts +52 -0
- package/dist/workflow/json-schema.d.ts.map +1 -0
- package/dist/workflow/json-schema.js +112 -0
- package/dist/workflow/json-schema.js.map +1 -0
- package/dist/workflow/meta.d.ts +68 -0
- package/dist/workflow/meta.d.ts.map +1 -0
- package/dist/workflow/meta.js +318 -0
- package/dist/workflow/meta.js.map +1 -0
- package/dist/workflow/progress.d.ts +225 -0
- package/dist/workflow/progress.d.ts.map +1 -0
- package/dist/workflow/progress.js +362 -0
- package/dist/workflow/progress.js.map +1 -0
- package/dist/workflow/runtime.d.ts +335 -0
- package/dist/workflow/runtime.d.ts.map +1 -0
- package/dist/workflow/runtime.js +831 -0
- package/dist/workflow/runtime.js.map +1 -0
- package/dist/workflow/saved.d.ts +91 -0
- package/dist/workflow/saved.d.ts.map +1 -0
- package/dist/workflow/saved.js +204 -0
- package/dist/workflow/saved.js.map +1 -0
- package/dist/workflow/task.d.ts +137 -0
- package/dist/workflow/task.d.ts.map +1 -0
- package/dist/workflow/task.js +208 -0
- package/dist/workflow/task.js.map +1 -0
- package/dist/workflow/tool-description.d.ts +39 -0
- package/dist/workflow/tool-description.d.ts.map +1 -0
- package/dist/workflow/tool-description.js +200 -0
- package/dist/workflow/tool-description.js.map +1 -0
- package/dist/workflow/worker-source.d.ts +48 -0
- package/dist/workflow/worker-source.d.ts.map +1 -0
- package/dist/workflow/worker-source.js +779 -0
- package/dist/workflow/worker-source.js.map +1 -0
- package/dist/worktree.d.ts +10 -3
- package/dist/worktree.d.ts.map +1 -1
- package/dist/worktree.js +58 -54
- package/dist/worktree.js.map +1 -1
- package/dist/xml.d.ts +11 -0
- package/dist/xml.d.ts.map +1 -0
- package/dist/xml.js +13 -0
- package/dist/xml.js.map +1 -0
- package/docs/rpc.md +183 -0
- package/docs/superpowers/plans/2026-09-30-conversation-viewer-scrollbar.md +216 -0
- package/docs/superpowers/plans/2026-09-30-upstream-event-workflow-partial-history.md +195 -0
- package/docs/superpowers/specs/2026-09-30-conversation-viewer-scrollbar-design.md +82 -0
- package/docs/superpowers/specs/2026-09-30-upstream-event-workflow-partial-history-design.md +49 -0
- package/docs/workflows.md +437 -0
- package/examples/agent-tool-description.md +7 -7
- package/examples/workflows/compose.js +51 -0
- package/examples/workflows/fan-out-audit.js +47 -0
- package/examples/workflows/gated-fix.js +60 -0
- package/examples/workflows/lib/count-child.js +27 -0
- package/examples/workflows/review-panel.js +63 -0
- package/examples/workflows/structured-findings.js +78 -0
- package/package.json +1 -1
- package/src/abortable.ts +43 -0
- package/src/agent-color.ts +161 -0
- package/src/agent-file-toggle.ts +269 -0
- package/src/agent-history.ts +54 -2
- package/src/agent-manager.ts +1263 -402
- package/src/agent-runner.ts +251 -27
- package/src/agent-types.ts +188 -32
- package/src/child-context.ts +15 -0
- package/src/cross-extension-rpc.ts +96 -20
- package/src/custom-agents.ts +170 -13
- package/src/index.ts +2024 -537
- package/src/invocation-config.ts +118 -3
- package/src/mention-clone.ts +196 -0
- package/src/mention.ts +141 -0
- package/src/model-resolver.ts +18 -0
- package/src/model-scope.ts +70 -0
- package/src/nested-tools.ts +424 -0
- package/src/output-file.ts +61 -6
- package/src/prompts.ts +45 -2
- package/src/schedule.ts +35 -14
- package/src/settings.ts +312 -2
- package/src/status-note.ts +66 -1
- package/src/structured-output.ts +130 -0
- package/src/types.ts +177 -10
- package/src/ui/agent-mention.ts +216 -0
- package/src/ui/agent-widget.ts +389 -441
- package/src/ui/conversation-blocks.ts +6 -0
- package/src/ui/conversation-timeline.ts +139 -25
- package/src/ui/conversation-viewer.ts +284 -69
- package/src/ui/fleet-list.ts +558 -0
- package/src/ui/schedule-menu.ts +9 -8
- package/src/ui/select-item.ts +45 -0
- package/src/ui/workflow-card.ts +470 -0
- package/src/ui/workflow-dialog.ts +1115 -0
- package/src/ui/workflow-menu.ts +193 -0
- package/src/usage.ts +109 -2
- package/src/workflow/collisions.ts +123 -0
- package/src/workflow/entry.ts +47 -0
- package/src/workflow/host.ts +403 -0
- package/src/workflow/journal.ts +164 -0
- package/src/workflow/json-schema.ts +128 -0
- package/src/workflow/meta.ts +325 -0
- package/src/workflow/progress.ts +550 -0
- package/src/workflow/runtime.ts +1219 -0
- package/src/workflow/saved.ts +217 -0
- package/src/workflow/task.ts +302 -0
- package/src/workflow/tool-description.ts +200 -0
- package/src/workflow/worker-source.ts +781 -0
- package/src/worktree.ts +69 -55
- package/src/xml.ts +13 -0
- package/vitest.config.ts +0 -18
package/dist/agent-types.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { createCodingTools, createReadOnlyTools } from "@earendil-works/pi-coding-agent";
|
|
8
8
|
import { DEFAULT_AGENTS } from "./default-agents.js";
|
|
9
|
-
import { applyNicoOverridesToMap, readNicoAgentOverrides } from "./nico-overrides.js";
|
|
9
|
+
import { applyNicoOverride, applyNicoOverridesToMap, readNicoAgentOverrides } from "./nico-overrides.js";
|
|
10
10
|
/**
|
|
11
11
|
* All known built-in tool names, derived from pi's own tool factories rather
|
|
12
12
|
* than hardcoded so the set tracks pi-mono if it adds/renames a built-in.
|
|
@@ -26,6 +26,38 @@ let disableDefaults = false;
|
|
|
26
26
|
export function isDefaultsDisabled() { return disableDefaults; }
|
|
27
27
|
/** Set whether default agents are disabled. */
|
|
28
28
|
export function setDefaultsDisabled(b) { disableDefaults = b; }
|
|
29
|
+
/** `fallbackSubagent` value that disables the fallback entirely (strict dispatch). */
|
|
30
|
+
export const NO_FALLBACK = "none";
|
|
31
|
+
/**
|
|
32
|
+
* Agent type substituted when a caller-supplied `subagent_type` doesn't resolve
|
|
33
|
+
* to exactly one enabled agent. `undefined` keeps the historical behavior
|
|
34
|
+
* (general-purpose); `NO_FALLBACK` makes dispatch fail closed. Set from
|
|
35
|
+
* `subagents.json` (`fallbackSubagent`).
|
|
36
|
+
*
|
|
37
|
+
* Module state rather than an index.ts closure because every caller-supplied
|
|
38
|
+
* spawn path needs it — the Agent tool, the scheduler, and cross-extension RPC.
|
|
39
|
+
*/
|
|
40
|
+
let fallbackSubagent;
|
|
41
|
+
/** Get the configured fallback agent type. undefined = general-purpose. */
|
|
42
|
+
export function getFallbackSubagent() { return fallbackSubagent; }
|
|
43
|
+
/** Set the configured fallback agent type. undefined = general-purpose. */
|
|
44
|
+
export function setFallbackSubagent(v) { fallbackSubagent = v; }
|
|
45
|
+
/**
|
|
46
|
+
* Build a registry map: DEFAULT_AGENTS first (unless disabled via settings),
|
|
47
|
+
* then user agents overlaid on top (same name overrides the default).
|
|
48
|
+
* Pure — callers that must not disturb the process-wide registry (nested
|
|
49
|
+
* delegation resolving agents from its own config root) build their own map.
|
|
50
|
+
*/
|
|
51
|
+
export function buildAgentRegistry(userAgents) {
|
|
52
|
+
const registry = new Map();
|
|
53
|
+
if (!disableDefaults) {
|
|
54
|
+
for (const [name, config] of DEFAULT_AGENTS)
|
|
55
|
+
registry.set(name, config);
|
|
56
|
+
}
|
|
57
|
+
for (const [name, config] of userAgents)
|
|
58
|
+
registry.set(name, config);
|
|
59
|
+
return registry;
|
|
60
|
+
}
|
|
29
61
|
/**
|
|
30
62
|
* Register agents into the unified registry.
|
|
31
63
|
* Starts with DEFAULT_AGENTS, then overlays user agents (overrides defaults with same name).
|
|
@@ -33,52 +65,153 @@ export function setDefaultsDisabled(b) { disableDefaults = b; }
|
|
|
33
65
|
*/
|
|
34
66
|
export function registerAgents(userAgents) {
|
|
35
67
|
agents.clear();
|
|
36
|
-
|
|
37
|
-
if (!disableDefaults) {
|
|
38
|
-
for (const [name, config] of DEFAULT_AGENTS) {
|
|
39
|
-
agents.set(name, config);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
// Overlay user agents (overrides defaults with same name)
|
|
43
|
-
for (const [name, config] of userAgents) {
|
|
68
|
+
for (const [name, config] of buildAgentRegistry(userAgents)) {
|
|
44
69
|
agents.set(name, config);
|
|
45
70
|
}
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Apply npm:pi-subagents-style JSON overrides to the current agent registry.
|
|
49
|
-
* Reads from ~/.pi/agent/settings.json and .pi/settings.json and applies
|
|
50
|
-
* them as the highest-priority layer. Auto-registers agents that don't
|
|
51
|
-
* exist in the registry yet.
|
|
52
|
-
*/
|
|
53
|
-
export function applyNicoOverrides() {
|
|
54
71
|
const { overrides, defaultModel } = readNicoAgentOverrides(process.cwd());
|
|
55
|
-
|
|
72
|
+
if (!disableDefaults) {
|
|
73
|
+
applyNicoOverridesToMap(agents, overrides, defaultModel);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// Disabling built-ins must also prevent JSON-only built-ins from being
|
|
77
|
+
// synthesized; explicit user agents remain eligible for their overrides.
|
|
78
|
+
for (const [name, config] of agents) {
|
|
79
|
+
const override = overrides[name];
|
|
80
|
+
if (override)
|
|
81
|
+
agents.set(name, applyNicoOverride(config, override, defaultModel));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
56
84
|
}
|
|
57
|
-
/** Case-insensitive key resolution. */
|
|
58
|
-
function
|
|
59
|
-
if (
|
|
85
|
+
/** Case-insensitive key resolution within a registry. */
|
|
86
|
+
function resolveKeyIn(registry, name) {
|
|
87
|
+
if (registry.has(name))
|
|
60
88
|
return name;
|
|
61
89
|
const lower = name.toLowerCase();
|
|
62
|
-
for (const key of
|
|
90
|
+
for (const key of registry.keys()) {
|
|
63
91
|
if (key.toLowerCase() === lower)
|
|
64
92
|
return key;
|
|
65
93
|
}
|
|
66
94
|
return undefined;
|
|
67
95
|
}
|
|
96
|
+
/** Case-insensitive key resolution. */
|
|
97
|
+
function resolveKey(name) {
|
|
98
|
+
return resolveKeyIn(agents, name);
|
|
99
|
+
}
|
|
100
|
+
/** Resolve a type name case-insensitively in a registry. Returns the canonical key or undefined. */
|
|
101
|
+
export function resolveTypeIn(registry, name) {
|
|
102
|
+
return resolveKeyIn(registry, name);
|
|
103
|
+
}
|
|
104
|
+
/** Get the agent config for a type (case-insensitive) from a registry. */
|
|
105
|
+
export function getAgentConfigIn(registry, name) {
|
|
106
|
+
const key = resolveKeyIn(registry, name);
|
|
107
|
+
return key ? registry.get(key) : undefined;
|
|
108
|
+
}
|
|
109
|
+
/** Check if a type is valid and enabled (case-insensitive) in a registry. */
|
|
110
|
+
export function isValidTypeIn(registry, type) {
|
|
111
|
+
const key = resolveKeyIn(registry, type);
|
|
112
|
+
if (!key)
|
|
113
|
+
return false;
|
|
114
|
+
return registry.get(key)?.enabled !== false;
|
|
115
|
+
}
|
|
116
|
+
/** Get all enabled type names in a registry (for spawning and tool descriptions). */
|
|
117
|
+
export function getAvailableTypesIn(registry) {
|
|
118
|
+
return [...registry.entries()]
|
|
119
|
+
.filter(([_, config]) => config.enabled !== false)
|
|
120
|
+
.map(([name]) => name);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Case-insensitive resolution that refuses to guess. An exact match always wins;
|
|
124
|
+
* otherwise the name must match exactly one key. Two agents differing only in
|
|
125
|
+
* case are reachable (`loadCustomAgents` keys by filename across three
|
|
126
|
+
* directories), and picking whichever came first would silently dispatch a
|
|
127
|
+
* different agent, model and tool policy than the caller meant.
|
|
128
|
+
*/
|
|
129
|
+
function resolveUnambiguousKeyIn(registry, name) {
|
|
130
|
+
if (registry.has(name))
|
|
131
|
+
return name;
|
|
132
|
+
const lower = name.toLowerCase();
|
|
133
|
+
const matches = [...registry.keys()].filter(key => key.toLowerCase() === lower);
|
|
134
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The canonical key for a caller-supplied name that identifies exactly one
|
|
138
|
+
* ENABLED agent, or undefined. Strict by construction: no fallback, no guessing
|
|
139
|
+
* between case-variants. Nested delegation resolves with this directly, since
|
|
140
|
+
* "unknown types are rejected rather than falling back" is its own contract.
|
|
141
|
+
*/
|
|
142
|
+
export function resolveEnabledTypeIn(registry, requested) {
|
|
143
|
+
const raw = typeof requested === "string" ? requested.trim() : "";
|
|
144
|
+
if (!raw)
|
|
145
|
+
return undefined;
|
|
146
|
+
const key = resolveUnambiguousKeyIn(registry, raw);
|
|
147
|
+
return key !== undefined && registry.get(key)?.enabled !== false ? key : undefined;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Resolve a caller-supplied agent type against a registry, applying the
|
|
151
|
+
* `fallbackSubagent` policy. The single decision point for every caller-supplied
|
|
152
|
+
* spawn — the Agent tool, the scheduler, cross-extension RPC, and the nested
|
|
153
|
+
* tools — so a type that fails here never reaches `runAgent`, where `getConfig`
|
|
154
|
+
* would silently substitute general-purpose.
|
|
155
|
+
*
|
|
156
|
+
* Unknown, disabled, and case-ambiguous names are all treated the same way:
|
|
157
|
+
* the caller named something that doesn't identify exactly one enabled agent.
|
|
158
|
+
*
|
|
159
|
+
* Pure over `registry` — callers that need fresh agent files reload before
|
|
160
|
+
* calling (the Agent tool already does, per spawn). Reloading here would mean
|
|
161
|
+
* importing custom-agents.ts, which imports this module.
|
|
162
|
+
*/
|
|
163
|
+
export function resolveSpawnTypeIn(registry, requested) {
|
|
164
|
+
const raw = typeof requested === "string" ? requested.trim() : "";
|
|
165
|
+
const available = () => getAvailableTypesIn(registry).join(", ") || "(none)";
|
|
166
|
+
const key = resolveEnabledTypeIn(registry, raw);
|
|
167
|
+
if (key !== undefined)
|
|
168
|
+
return { ok: true, type: key };
|
|
169
|
+
// A missing type follows the same policy as a wrong one rather than always
|
|
170
|
+
// erroring: before this setting existed an empty type fell back like any
|
|
171
|
+
// other unresolvable name, and only opting in should change that.
|
|
172
|
+
const reason = raw ? `Unknown or disabled agent type: "${raw}".` : "No agent type given.";
|
|
173
|
+
// Trimmed like `requested`: a padded value set programmatically would
|
|
174
|
+
// otherwise be reported as a missing agent.
|
|
175
|
+
const configured = typeof fallbackSubagent === "string" ? fallbackSubagent.trim() : undefined;
|
|
176
|
+
if (configured !== undefined && configured.toLowerCase() === NO_FALLBACK) {
|
|
177
|
+
return { ok: false, message: `${reason} Available: ${available()}.` };
|
|
178
|
+
}
|
|
179
|
+
if (configured !== undefined) {
|
|
180
|
+
// An explicitly configured fallback that is itself unusable is a
|
|
181
|
+
// misconfiguration, not a second chance to guess — say so rather than
|
|
182
|
+
// quietly dropping to general-purpose.
|
|
183
|
+
const fallbackKey = resolveUnambiguousKeyIn(registry, configured);
|
|
184
|
+
if (fallbackKey === undefined || registry.get(fallbackKey)?.enabled === false) {
|
|
185
|
+
return {
|
|
186
|
+
ok: false,
|
|
187
|
+
message: `${reason} The configured fallbackSubagent "${configured}" is itself ` +
|
|
188
|
+
`unknown or disabled. Available: ${available()}.`,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
return { ok: true, type: fallbackKey, fellBackFrom: raw };
|
|
192
|
+
}
|
|
193
|
+
// Unset: historical behavior, deliberately unchanged. #183 asks for the
|
|
194
|
+
// fallback to remain the default, so the pre-existing hole it leaves — an
|
|
195
|
+
// unregistered general-purpose resolving to `getConfig`'s all-tools hardcoded
|
|
196
|
+
// tier — is what `fallbackSubagent: none` is for, not something to close
|
|
197
|
+
// under everyone silently.
|
|
198
|
+
return { ok: true, type: "general-purpose", fellBackFrom: raw };
|
|
199
|
+
}
|
|
200
|
+
/** Resolve a caller-supplied agent type against the process-wide registry. */
|
|
201
|
+
export function resolveSpawnType(requested) {
|
|
202
|
+
return resolveSpawnTypeIn(agents, requested);
|
|
203
|
+
}
|
|
68
204
|
/** Resolve a type name case-insensitively. Returns the canonical key or undefined. */
|
|
69
205
|
export function resolveType(name) {
|
|
70
206
|
return resolveKey(name);
|
|
71
207
|
}
|
|
72
208
|
/** Get the agent config for a type (case-insensitive). */
|
|
73
209
|
export function getAgentConfig(name) {
|
|
74
|
-
|
|
75
|
-
return key ? agents.get(key) : undefined;
|
|
210
|
+
return getAgentConfigIn(agents, name);
|
|
76
211
|
}
|
|
77
212
|
/** Get all enabled type names (for spawning and tool descriptions). */
|
|
78
213
|
export function getAvailableTypes() {
|
|
79
|
-
return
|
|
80
|
-
.filter(([_, config]) => config.enabled !== false)
|
|
81
|
-
.map(([name]) => name);
|
|
214
|
+
return getAvailableTypesIn(agents);
|
|
82
215
|
}
|
|
83
216
|
/** Get all type names including disabled (for UI listing). */
|
|
84
217
|
export function getAllTypes() {
|
|
@@ -93,15 +226,12 @@ export function getDefaultAgentNames() {
|
|
|
93
226
|
/** Get names of user-defined agents (non-defaults) currently in the registry. */
|
|
94
227
|
export function getUserAgentNames() {
|
|
95
228
|
return [...agents.entries()]
|
|
96
|
-
.filter(([_, config]) => config.isDefault !== true)
|
|
229
|
+
.filter(([_, config]) => config.isDefault !== true && !config.description.startsWith("Auto-registered from npm:pi-subagents JSON settings"))
|
|
97
230
|
.map(([name]) => name);
|
|
98
231
|
}
|
|
99
232
|
/** Check if a type is valid and enabled (case-insensitive). */
|
|
100
233
|
export function isValidType(type) {
|
|
101
|
-
|
|
102
|
-
if (!key)
|
|
103
|
-
return false;
|
|
104
|
-
return agents.get(key)?.enabled !== false;
|
|
234
|
+
return isValidTypeIn(agents, type);
|
|
105
235
|
}
|
|
106
236
|
/** Tool names required for memory management. */
|
|
107
237
|
const MEMORY_TOOL_NAMES = ["read", "write", "edit"];
|
|
@@ -135,6 +265,7 @@ export function getConfig(type) {
|
|
|
135
265
|
if (config && config.enabled !== false) {
|
|
136
266
|
return {
|
|
137
267
|
displayName: config.displayName ?? config.name,
|
|
268
|
+
color: config.color,
|
|
138
269
|
description: config.description,
|
|
139
270
|
builtinToolNames: config.builtinToolNames ?? BUILTIN_TOOL_NAMES,
|
|
140
271
|
extensions: config.extensions,
|
|
@@ -148,6 +279,7 @@ export function getConfig(type) {
|
|
|
148
279
|
if (gp && gp.enabled !== false) {
|
|
149
280
|
return {
|
|
150
281
|
displayName: gp.displayName ?? gp.name,
|
|
282
|
+
color: gp.color,
|
|
151
283
|
description: gp.description,
|
|
152
284
|
builtinToolNames: gp.builtinToolNames ?? BUILTIN_TOOL_NAMES,
|
|
153
285
|
extensions: gp.extensions,
|
package/dist/agent-types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-types.js","sourceRoot":"","sources":["../src/agent-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACzF,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"agent-types.js","sourceRoot":"","sources":["../src/agent-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACzF,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAGzG;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAa;IAC1C,GAAG,IAAI,GAAG,CAAC,CAAC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":[],"mappings":"AAQA,wBAAgB,qBAAqB,IAAI,OAAO,CAE/C;AAED,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAE5E"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
/**
|
|
3
|
+
* Marks resource loading/session construction performed for a subagent. This is
|
|
4
|
+
* async-context-local so concurrent top-level extension work is unaffected.
|
|
5
|
+
*/
|
|
6
|
+
const childSessionContext = new AsyncLocalStorage();
|
|
7
|
+
export function inChildSessionContext() {
|
|
8
|
+
return childSessionContext.getStore() === true;
|
|
9
|
+
}
|
|
10
|
+
export function runInChildSessionContext(fn) {
|
|
11
|
+
return childSessionContext.run(true, fn);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=child-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"child-context.js","sourceRoot":"","sources":["../src/child-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;GAGG;AACH,MAAM,mBAAmB,GAAG,IAAI,iBAAiB,EAAW,CAAC;AAE7D,MAAM,UAAU,qBAAqB;IACnC,OAAO,mBAAmB,CAAC,QAAQ,EAAE,KAAK,IAAI,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAI,EAAoB;IAC9D,OAAO,mBAAmB,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Cross-extension RPC handlers for the subagents extension.
|
|
3
3
|
*
|
|
4
|
-
* Exposes ping, spawn, and
|
|
4
|
+
* Exposes ping, spawn, stop, and consume 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.
|
|
10
14
|
*/
|
|
15
|
+
import type { AgentRecord } from "./types.js";
|
|
11
16
|
/** Minimal event bus interface needed by the RPC handlers. */
|
|
12
17
|
export interface EventBus {
|
|
13
18
|
on(event: string, handler: (data: unknown) => void): () => void;
|
|
@@ -23,10 +28,24 @@ export type RpcReply<T = void> = {
|
|
|
23
28
|
};
|
|
24
29
|
/** RPC protocol version — bumped when the envelope or method contracts change. */
|
|
25
30
|
export declare const PROTOCOL_VERSION = 2;
|
|
26
|
-
/** Minimal AgentManager interface needed by the spawn/stop RPCs. */
|
|
31
|
+
/** Minimal AgentManager interface needed by the spawn/stop/consume RPCs. */
|
|
27
32
|
export interface SpawnCapable {
|
|
28
33
|
spawn(pi: unknown, ctx: unknown, type: string, prompt: string, options: any): string;
|
|
34
|
+
/** Resolves once the spawned agent is running; rejects on a startup failure. */
|
|
35
|
+
awaitStartup(id: string): Promise<void>;
|
|
29
36
|
abort(id: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* The record behind an id, for the stop handler's ownership check. Narrowed
|
|
39
|
+
* to the two fields `isTopLevelAgent` reads, so the RPC layer keeps its
|
|
40
|
+
* deliberately shallow view of the manager.
|
|
41
|
+
*/
|
|
42
|
+
getRecord(id: string): Pick<AgentRecord, "parentAgentId" | "workflowId"> | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Mark a settled agent's result as read by the caller, suppressing the
|
|
45
|
+
* completion notification — what `get_subagent_result` does when it returns
|
|
46
|
+
* one. False when there is no such agent, or it has not settled yet.
|
|
47
|
+
*/
|
|
48
|
+
consumeResult(id: string): boolean;
|
|
30
49
|
}
|
|
31
50
|
export interface RpcDeps {
|
|
32
51
|
events: EventBus;
|
|
@@ -38,9 +57,10 @@ export interface RpcHandle {
|
|
|
38
57
|
unsubPing: () => void;
|
|
39
58
|
unsubSpawn: () => void;
|
|
40
59
|
unsubStop: () => void;
|
|
60
|
+
unsubConsume: () => void;
|
|
41
61
|
}
|
|
42
62
|
/**
|
|
43
|
-
* Register ping, spawn, and
|
|
63
|
+
* Register ping, spawn, stop, and consume RPC handlers on the event bus.
|
|
44
64
|
* Returns unsub functions for cleanup.
|
|
45
65
|
*/
|
|
46
66
|
export declare function registerRpcHandlers(deps: RpcDeps): RpcHandle;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cross-extension-rpc.d.ts","sourceRoot":"","sources":["../src/cross-extension-rpc.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"cross-extension-rpc.d.ts","sourceRoot":"","sources":["../src/cross-extension-rpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,8DAA8D;AAC9D,MAAM,WAAW,QAAQ;IACvB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAChE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;CAC1C;AAED,gEAAgE;AAChE,MAAM,MAAM,QAAQ,CAAC,CAAC,GAAG,IAAI,IACzB;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,CAAC,EAAE,CAAC,CAAA;CAAE,GAC3B;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtC,kFAAkF;AAClF,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC,4EAA4E;AAC5E,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,MAAM,CAAC;IACrF,gFAAgF;IAChF,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3B;;;;OAIG;IACH,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC,WAAW,EAAE,eAAe,GAAG,YAAY,CAAC,GAAG,SAAS,CAAC;IACrF;;;;OAIG;IACH,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;CACpC;AAED,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,QAAQ,CAAC;IACjB,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,OAAO,GAAG,SAAS,CAAC;IAClC,OAAO,EAAE,YAAY,CAAC;CACvB;AAED,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,YAAY,EAAE,MAAM,IAAI,CAAC;CAC1B;AA0BD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,CAqG5D"}
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Cross-extension RPC handlers for the subagents extension.
|
|
3
3
|
*
|
|
4
|
-
* Exposes ping, spawn, and
|
|
4
|
+
* Exposes ping, spawn, stop, and consume 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.
|
|
10
14
|
*/
|
|
15
|
+
import { isTopLevelAgent } from "./agent-manager.js";
|
|
11
16
|
import { resolveModel } from "./model-resolver.js";
|
|
17
|
+
import { checkModelScope } from "./model-scope.js";
|
|
12
18
|
/** RPC protocol version — bumped when the envelope or method contracts change. */
|
|
13
19
|
export const PROTOCOL_VERSION = 2;
|
|
14
20
|
/**
|
|
@@ -33,7 +39,7 @@ function handleRpc(events, channel, fn) {
|
|
|
33
39
|
});
|
|
34
40
|
}
|
|
35
41
|
/**
|
|
36
|
-
* Register ping, spawn, and
|
|
42
|
+
* Register ping, spawn, stop, and consume RPC handlers on the event bus.
|
|
37
43
|
* Returns unsub functions for cleanup.
|
|
38
44
|
*/
|
|
39
45
|
export function registerRpcHandlers(deps) {
|
|
@@ -41,7 +47,7 @@ export function registerRpcHandlers(deps) {
|
|
|
41
47
|
const unsubPing = handleRpc(events, "subagents:rpc:ping", () => {
|
|
42
48
|
return { version: PROTOCOL_VERSION };
|
|
43
49
|
});
|
|
44
|
-
const unsubSpawn = handleRpc(events, "subagents:rpc:spawn", ({ type, prompt, options }) => {
|
|
50
|
+
const unsubSpawn = handleRpc(events, "subagents:rpc:spawn", async ({ type, prompt, options }) => {
|
|
45
51
|
const ctx = getCtx();
|
|
46
52
|
if (!ctx)
|
|
47
53
|
throw new Error("No active session");
|
|
@@ -52,26 +58,82 @@ export function registerRpcHandlers(deps) {
|
|
|
52
58
|
// agent's auth lookup doesn't crash with "No API key found for
|
|
53
59
|
// undefined".
|
|
54
60
|
let normalizedOptions = options ?? {};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
// `!= null` on purpose: a JSON-forwarding caller can serialize an unset
|
|
62
|
+
// field as null, and the runner reads `options.model ?? default`, so null
|
|
63
|
+
// means "inherit" — not an override to resolve or scope-check.
|
|
64
|
+
const override = normalizedOptions.model;
|
|
65
|
+
if (override != null) {
|
|
66
|
+
const { modelRegistry, cwd } = ctx;
|
|
67
|
+
// Names the override the same way in both messages below; an object
|
|
68
|
+
// override would otherwise interpolate as "[object Object]".
|
|
69
|
+
const label = typeof override === "string" ? override : `${override.provider}/${override.id}`;
|
|
70
|
+
if (!modelRegistry) {
|
|
71
|
+
throw new Error(`Model override "${label}" provided but ctx.modelRegistry is unavailable`);
|
|
59
72
|
}
|
|
60
|
-
|
|
61
|
-
if (typeof
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
73
|
+
let model = override;
|
|
74
|
+
if (typeof override === "string") {
|
|
75
|
+
const resolved = resolveModel(override, modelRegistry);
|
|
76
|
+
if (typeof resolved === "string") {
|
|
77
|
+
// resolveModel returns a human-readable error string when the
|
|
78
|
+
// input doesn't match any available model. Surface it instead of
|
|
79
|
+
// silently falling back so the caller sees the auth/typo issue.
|
|
80
|
+
throw new Error(resolved);
|
|
81
|
+
}
|
|
82
|
+
model = resolved;
|
|
83
|
+
normalizedOptions = { ...normalizedOptions, model: resolved };
|
|
66
84
|
}
|
|
67
|
-
|
|
85
|
+
// A model on the RPC payload is an orchestrator-level choice, exactly
|
|
86
|
+
// like Agent({ model }) — so it gets the Agent tool's hard error, never
|
|
87
|
+
// the frontmatter warn (#240). The check reads the RESOLVED model:
|
|
88
|
+
// resolveModel is fuzzy, so a bare "sonnet" can land on a provider the
|
|
89
|
+
// caller never named. Frontmatter-pinned and parent-inherited models are
|
|
90
|
+
// resolved later, in agent-runner, and keep warn-and-proceed.
|
|
91
|
+
const verdict = checkModelScope({
|
|
92
|
+
model,
|
|
93
|
+
cwd: cwd ?? process.cwd(),
|
|
94
|
+
modelRegistry,
|
|
95
|
+
callerSupplied: true,
|
|
96
|
+
agentLabel: type,
|
|
97
|
+
modelInput: label,
|
|
98
|
+
});
|
|
99
|
+
if (verdict.kind === "error")
|
|
100
|
+
throw new Error(verdict.message);
|
|
68
101
|
}
|
|
69
|
-
|
|
102
|
+
const id = manager.spawn(pi, ctx, type, prompt, normalizedOptions);
|
|
103
|
+
// With isolation: "worktree" the agent starts asynchronously — wait for
|
|
104
|
+
// it, so a strict-isolation failure is still an error envelope rather
|
|
105
|
+
// than an id for an agent that never ran.
|
|
106
|
+
await manager.awaitStartup(id);
|
|
107
|
+
return { id };
|
|
70
108
|
});
|
|
71
109
|
const unsubStop = handleRpc(events, "subagents:rpc:stop", ({ agentId }) => {
|
|
72
|
-
|
|
110
|
+
const record = manager.getRecord(agentId);
|
|
111
|
+
if (!record)
|
|
73
112
|
throw new Error("Agent not found");
|
|
113
|
+
// Only the session's own agents are this RPC's to stop. A nested child or
|
|
114
|
+
// a workflow's agent is owned by something that is *waiting on it*, and
|
|
115
|
+
// aborting it out from under that owner turns another extension's stop
|
|
116
|
+
// into a failed step here. Defence in depth rather than a live hole: no
|
|
117
|
+
// RPC hands out agent ids, so a caller has no ordinary way to name one it
|
|
118
|
+
// does not own — but the guard is cheap and the id may leak some other
|
|
119
|
+
// way. Same refuse-what-we-should-not-touch stance as `consume` below.
|
|
120
|
+
if (!isTopLevelAgent(record))
|
|
121
|
+
throw new Error("Agent is owned by another agent or workflow");
|
|
122
|
+
// Not "not found" — the lookup above already proved it exists. `abort`
|
|
123
|
+
// returns false only for a record that is neither running nor queued,
|
|
124
|
+
// which is an agent that has already finished.
|
|
125
|
+
if (!manager.abort(agentId))
|
|
126
|
+
throw new Error("Agent is not running");
|
|
127
|
+
});
|
|
128
|
+
// A caller that has already shown the model an agent's result — pi-tasks'
|
|
129
|
+
// TaskOutput is the one in practice — says so here, so the completion
|
|
130
|
+
// notification for that same result is not delivered on top of it and does
|
|
131
|
+
// not cost the parent a turn. Deliberately outside the ping version
|
|
132
|
+
// handshake: an extension built against protocol v2 simply never calls it.
|
|
133
|
+
const unsubConsume = handleRpc(events, "subagents:rpc:consume", ({ agentId }) => {
|
|
134
|
+
if (!manager.consumeResult(agentId))
|
|
135
|
+
throw new Error("Agent not found or still running");
|
|
74
136
|
});
|
|
75
|
-
return { unsubPing, unsubSpawn, unsubStop };
|
|
137
|
+
return { unsubPing, unsubSpawn, unsubStop, unsubConsume };
|
|
76
138
|
}
|
|
77
139
|
//# sourceMappingURL=cross-extension-rpc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cross-extension-rpc.js","sourceRoot":"","sources":["../src/cross-extension-rpc.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"cross-extension-rpc.js","sourceRoot":"","sources":["../src/cross-extension-rpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAsB,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAcnD,kFAAkF;AAClF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAoClC;;;GAGG;AACH,SAAS,SAAS,CAChB,MAAgB,EAChB,OAAe,EACf,EAA6C;IAE7C,OAAO,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,GAAY,EAAE,EAAE;QAC/C,MAAM,MAAM,GAAG,GAAQ,CAAC;QACxB,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC;YAC9B,MAAM,KAAK,GAAsC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;YACnE,IAAI,IAAI,KAAK,SAAS;gBAAE,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;YAC1C,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,UAAU,MAAM,CAAC,SAAS,EAAE,EAAE,KAAK,CAAC,CAAC;QAC7D,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,MAAM,CAAC,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/B,OAAO,EAAE,EAAE,EAAE,CAAC;IAChB,CAAC,CACF,CAAC;IAEF,MAAM,SAAS,GAAG,SAAS,CACzB,MAAM,EAAE,oBAAoB,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;QAC5C,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;QAChD,0EAA0E;QAC1E,wEAAwE;QACxE,uEAAuE;QACvE,wEAAwE;QACxE,0EAA0E;QAC1E,uEAAuE;QACvE,uEAAuE;QACvE,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QAC7F,uEAAuE;QACvE,sEAAsE;QACtE,+CAA+C;QAC/C,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IACvE,CAAC,CACF,CAAC;IAEF,0EAA0E;IAC1E,sEAAsE;IACtE,2EAA2E;IAC3E,oEAAoE;IACpE,2EAA2E;IAC3E,MAAM,YAAY,GAAG,SAAS,CAC5B,MAAM,EAAE,uBAAuB,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;QAC/C,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IAC3F,CAAC,CACF,CAAC;IAEF,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC;AAC5D,CAAC"}
|
package/dist/custom-agents.d.ts
CHANGED
|
@@ -13,6 +13,43 @@ import type { AgentConfig } from "./types.js";
|
|
|
13
13
|
* between the two project locations, .pi/agents wins — .pi stays the project
|
|
14
14
|
* authority; .agents/agents is an additional read location.
|
|
15
15
|
* Any name is allowed — names matching defaults (e.g. "Explore") override them.
|
|
16
|
+
*
|
|
17
|
+
* An agent's type comes from its frontmatter `name:`, falling back to the
|
|
18
|
+
* filename — Claude Code's rule, where "the filename doesn't have to match".
|
|
19
|
+
* Because the type is now declared rather than derived from a unique path, two
|
|
20
|
+
* files can claim the same one; the later load wins, as it always has for a
|
|
21
|
+
* filename clash, and `warnSkippedOverride` reports the substitution.
|
|
22
|
+
*/
|
|
23
|
+
export declare function loadCustomAgents(cwd: string, strict?: boolean): Map<string, AgentConfig>;
|
|
24
|
+
/**
|
|
25
|
+
* Read and parse one agent file, or warn and return undefined for the caller to
|
|
26
|
+
* skip. One bad file must not take the whole extension down with it — an
|
|
27
|
+
* unparseable `.md` used to abort activation, so pi exited before the TUI.
|
|
28
|
+
*
|
|
29
|
+
* The path is as much of the fix as the recovery: a bare YAML error ("line 2,
|
|
30
|
+
* column 14") is unactionable when agents come from three directories at once,
|
|
31
|
+
* and the only other symptom is `Unknown agent type`, which reads like a typo.
|
|
32
|
+
*
|
|
33
|
+
* Under `strict` the same failure rethrows, still naming the path, so callers
|
|
34
|
+
* that opted into failing closed stop rather than run a substituted agent.
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* Parse an agent file's frontmatter, tolerating a leading UTF-8 BOM.
|
|
38
|
+
*
|
|
39
|
+
* Editors across the Windows/CJK world write UTF-8 with a BOM by default, and
|
|
40
|
+
* pi's parser did not look past one before 0.84.3: the fence never matched, so
|
|
41
|
+
* the frontmatter came back empty and the *whole file* — YAML and all — became
|
|
42
|
+
* the body. An agent authored that way silently lost every field. `tools: none`
|
|
43
|
+
* going missing is the sharp edge: the agent registers with the default
|
|
44
|
+
* toolset rather than none, which is a wider grant than its author wrote.
|
|
45
|
+
*
|
|
46
|
+
* Stripped here rather than detected per pi version, because this is the only
|
|
47
|
+
* place agent files are read and the BOM is a file-encoding artifact, not
|
|
48
|
+
* content — normalising it at the boundary keeps one behaviour across the whole
|
|
49
|
+
* supported peer range instead of forking on what happens to be installed.
|
|
16
50
|
*/
|
|
17
|
-
export declare function
|
|
51
|
+
export declare function parseAgentFrontmatter<T extends Record<string, unknown>>(content: string): {
|
|
52
|
+
frontmatter: T;
|
|
53
|
+
body: string;
|
|
54
|
+
};
|
|
18
55
|
//# sourceMappingURL=custom-agents.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-agents.d.ts","sourceRoot":"","sources":["../src/custom-agents.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,KAAK,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"custom-agents.d.ts","sourceRoot":"","sources":["../src/custom-agents.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,KAAK,EAAE,WAAW,EAA6C,MAAM,YAAY,CAAC;AAiBzF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,UAAQ,GAAG,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAatF;AAqFD;;;;;;;;;;;GAWG;AACH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG;IAAE,WAAW,EAAE,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAE1H"}
|