@timmyjl12/pi-subagents 0.0.0-stage → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. package/CHANGELOG.md +827 -0
  2. package/CONTRIBUTING.md +72 -0
  3. package/LICENSE +21 -0
  4. package/README.md +1079 -2
  5. package/SECURITY.md +97 -0
  6. package/dist/abortable.d.ts +12 -0
  7. package/dist/abortable.js +42 -0
  8. package/dist/active-agents-prompt.d.ts +18 -0
  9. package/dist/active-agents-prompt.js +34 -0
  10. package/dist/advisor-status.d.ts +16 -0
  11. package/dist/advisor-status.js +74 -0
  12. package/dist/agent-color.d.ts +35 -0
  13. package/dist/agent-color.js +123 -0
  14. package/dist/agent-file-toggle.d.ts +125 -0
  15. package/dist/agent-file-toggle.js +264 -0
  16. package/dist/agent-manager.d.ts +485 -0
  17. package/dist/agent-manager.js +1380 -0
  18. package/dist/agent-runner.d.ts +319 -0
  19. package/dist/agent-runner.js +1128 -0
  20. package/dist/agent-types.d.ts +119 -0
  21. package/dist/agent-types.js +286 -0
  22. package/dist/child-context.d.ts +15 -0
  23. package/dist/child-context.js +181 -0
  24. package/dist/child-session-shutdown.d.ts +3 -0
  25. package/dist/child-session-shutdown.js +48 -0
  26. package/dist/context.d.ts +12 -0
  27. package/dist/context.js +56 -0
  28. package/dist/cross-extension-rpc.d.ts +66 -0
  29. package/dist/cross-extension-rpc.js +138 -0
  30. package/dist/custom-agents.d.ts +54 -0
  31. package/dist/custom-agents.js +386 -0
  32. package/dist/default-agents.d.ts +7 -0
  33. package/dist/default-agents.js +125 -0
  34. package/dist/enabled-models.d.ts +49 -0
  35. package/dist/enabled-models.js +145 -0
  36. package/dist/env.d.ts +6 -0
  37. package/dist/env.js +28 -0
  38. package/dist/error-log.d.ts +58 -0
  39. package/dist/error-log.js +168 -0
  40. package/dist/group-join.d.ts +32 -0
  41. package/dist/group-join.js +116 -0
  42. package/dist/index.d.ts +52 -0
  43. package/dist/index.js +3896 -0
  44. package/dist/invocation-config.d.ts +137 -0
  45. package/dist/invocation-config.js +129 -0
  46. package/dist/memory.d.ts +53 -0
  47. package/dist/memory.js +165 -0
  48. package/dist/mention-clone.d.ts +87 -0
  49. package/dist/mention-clone.js +178 -0
  50. package/dist/mention.d.ts +81 -0
  51. package/dist/mention.js +131 -0
  52. package/dist/model-resolver.d.ts +36 -0
  53. package/dist/model-resolver.js +95 -0
  54. package/dist/model-scope.d.ts +49 -0
  55. package/dist/model-scope.js +48 -0
  56. package/dist/nested-tools.d.ts +55 -0
  57. package/dist/nested-tools.js +299 -0
  58. package/dist/output-diagnostics.d.ts +11 -0
  59. package/dist/output-diagnostics.js +64 -0
  60. package/dist/output-file.d.ts +53 -0
  61. package/dist/output-file.js +248 -0
  62. package/dist/prompts.d.ts +61 -0
  63. package/dist/prompts.js +94 -0
  64. package/dist/recovery.d.ts +56 -0
  65. package/dist/recovery.js +341 -0
  66. package/dist/schedule-store.d.ts +44 -0
  67. package/dist/schedule-store.js +210 -0
  68. package/dist/schedule.d.ts +109 -0
  69. package/dist/schedule.js +359 -0
  70. package/dist/settings.d.ts +360 -0
  71. package/dist/settings.js +251 -0
  72. package/dist/skill-loader.d.ts +24 -0
  73. package/dist/skill-loader.js +93 -0
  74. package/dist/standalone-fallback.d.ts +30 -0
  75. package/dist/standalone-fallback.js +239 -0
  76. package/dist/status-note.d.ts +61 -0
  77. package/dist/status-note.js +85 -0
  78. package/dist/structured-output.d.ts +61 -0
  79. package/dist/structured-output.js +112 -0
  80. package/dist/terminal-progress.d.ts +115 -0
  81. package/dist/terminal-progress.js +206 -0
  82. package/dist/types.d.ts +382 -0
  83. package/dist/types.js +5 -0
  84. package/dist/ui/agent-mention.d.ts +82 -0
  85. package/dist/ui/agent-mention.js +187 -0
  86. package/dist/ui/agent-widget.d.ts +235 -0
  87. package/dist/ui/agent-widget.js +652 -0
  88. package/dist/ui/conversation-viewer.d.ts +105 -0
  89. package/dist/ui/conversation-viewer.js +540 -0
  90. package/dist/ui/fleet-list.d.ts +183 -0
  91. package/dist/ui/fleet-list.js +494 -0
  92. package/dist/ui/fleet-overlay.d.ts +172 -0
  93. package/dist/ui/fleet-overlay.js +691 -0
  94. package/dist/ui/native-transcript.d.ts +33 -0
  95. package/dist/ui/native-transcript.js +230 -0
  96. package/dist/ui/schedule-menu.d.ts +16 -0
  97. package/dist/ui/schedule-menu.js +94 -0
  98. package/dist/ui/select-item.d.ts +27 -0
  99. package/dist/ui/select-item.js +34 -0
  100. package/dist/ui/tool-progress.d.ts +22 -0
  101. package/dist/ui/tool-progress.js +56 -0
  102. package/dist/ui/viewer-keys.d.ts +20 -0
  103. package/dist/ui/viewer-keys.js +17 -0
  104. package/dist/ui/workflow-card.d.ts +175 -0
  105. package/dist/ui/workflow-card.js +332 -0
  106. package/dist/ui/workflow-dialog.d.ts +305 -0
  107. package/dist/ui/workflow-dialog.js +843 -0
  108. package/dist/ui/workflow-menu.d.ts +60 -0
  109. package/dist/ui/workflow-menu.js +147 -0
  110. package/dist/usage.d.ts +135 -0
  111. package/dist/usage.js +120 -0
  112. package/dist/workflow/collisions.d.ts +95 -0
  113. package/dist/workflow/collisions.js +88 -0
  114. package/dist/workflow/entry.d.ts +32 -0
  115. package/dist/workflow/entry.js +29 -0
  116. package/dist/workflow/host.d.ts +62 -0
  117. package/dist/workflow/host.js +363 -0
  118. package/dist/workflow/journal.d.ts +97 -0
  119. package/dist/workflow/journal.js +120 -0
  120. package/dist/workflow/json-schema.d.ts +51 -0
  121. package/dist/workflow/json-schema.js +111 -0
  122. package/dist/workflow/meta.d.ts +67 -0
  123. package/dist/workflow/meta.js +317 -0
  124. package/dist/workflow/progress.d.ts +224 -0
  125. package/dist/workflow/progress.js +361 -0
  126. package/dist/workflow/runtime.d.ts +334 -0
  127. package/dist/workflow/runtime.js +830 -0
  128. package/dist/workflow/saved.d.ts +90 -0
  129. package/dist/workflow/saved.js +203 -0
  130. package/dist/workflow/task.d.ts +136 -0
  131. package/dist/workflow/task.js +207 -0
  132. package/dist/workflow/tool-description.d.ts +38 -0
  133. package/dist/workflow/tool-description.js +199 -0
  134. package/dist/workflow/worker-source.d.ts +47 -0
  135. package/dist/workflow/worker-source.js +778 -0
  136. package/dist/worktree.d.ts +52 -0
  137. package/dist/worktree.js +164 -0
  138. package/dist/xml.d.ts +10 -0
  139. package/dist/xml.js +12 -0
  140. package/docs/FORK.md +40 -0
  141. package/docs/recovery.md +62 -0
  142. package/docs/rpc.md +189 -0
  143. package/docs/workflows.md +437 -0
  144. package/examples/agent-tool-description.md +43 -0
  145. package/examples/workflows/compose.js +51 -0
  146. package/examples/workflows/fan-out-audit.js +47 -0
  147. package/examples/workflows/gated-fix.js +60 -0
  148. package/examples/workflows/lib/count-child.js +27 -0
  149. package/examples/workflows/review-panel.js +63 -0
  150. package/examples/workflows/structured-findings.js +78 -0
  151. package/package.json +75 -6
  152. package/src/abortable.ts +43 -0
  153. package/src/active-agents-prompt.ts +39 -0
  154. package/src/advisor-status.ts +74 -0
  155. package/src/agent-color.ts +161 -0
  156. package/src/agent-file-toggle.ts +273 -0
  157. package/src/agent-manager.ts +1601 -0
  158. package/src/agent-runner.ts +1372 -0
  159. package/src/agent-types.ts +345 -0
  160. package/src/child-context.ts +173 -0
  161. package/src/child-session-shutdown.ts +46 -0
  162. package/src/context.ts +58 -0
  163. package/src/cross-extension-rpc.ts +198 -0
  164. package/src/custom-agents.ts +417 -0
  165. package/src/default-agents.ts +129 -0
  166. package/src/enabled-models.ts +180 -0
  167. package/src/env.ts +33 -0
  168. package/src/error-log.ts +193 -0
  169. package/src/group-join.ts +141 -0
  170. package/src/index.ts +4218 -0
  171. package/src/invocation-config.ts +230 -0
  172. package/src/memory.ts +179 -0
  173. package/src/mention-clone.ts +221 -0
  174. package/src/mention.ts +141 -0
  175. package/src/model-resolver.ts +118 -0
  176. package/src/model-scope.ts +70 -0
  177. package/src/nested-tools.ts +422 -0
  178. package/src/output-diagnostics.ts +68 -0
  179. package/src/output-file.ts +258 -0
  180. package/src/prompts.ts +151 -0
  181. package/src/recovery.ts +320 -0
  182. package/src/schedule-store.ts +201 -0
  183. package/src/schedule.ts +386 -0
  184. package/src/settings.ts +587 -0
  185. package/src/skill-loader.ts +102 -0
  186. package/src/standalone-fallback.ts +195 -0
  187. package/src/status-note.ts +90 -0
  188. package/src/structured-output.ts +130 -0
  189. package/src/terminal-progress.ts +215 -0
  190. package/src/types.ts +394 -0
  191. package/src/ui/agent-mention.ts +216 -0
  192. package/src/ui/agent-widget.ts +732 -0
  193. package/src/ui/conversation-viewer.ts +523 -0
  194. package/src/ui/fleet-list.ts +563 -0
  195. package/src/ui/fleet-overlay.ts +847 -0
  196. package/src/ui/native-transcript.ts +220 -0
  197. package/src/ui/schedule-menu.ts +105 -0
  198. package/src/ui/select-item.ts +45 -0
  199. package/src/ui/tool-progress.ts +67 -0
  200. package/src/ui/viewer-keys.ts +39 -0
  201. package/src/ui/workflow-card.ts +470 -0
  202. package/src/ui/workflow-dialog.ts +1115 -0
  203. package/src/ui/workflow-menu.ts +193 -0
  204. package/src/usage.ts +167 -0
  205. package/src/workflow/collisions.ts +123 -0
  206. package/src/workflow/entry.ts +47 -0
  207. package/src/workflow/host.ts +404 -0
  208. package/src/workflow/journal.ts +164 -0
  209. package/src/workflow/json-schema.ts +128 -0
  210. package/src/workflow/meta.ts +325 -0
  211. package/src/workflow/progress.ts +550 -0
  212. package/src/workflow/runtime.ts +1219 -0
  213. package/src/workflow/saved.ts +217 -0
  214. package/src/workflow/task.ts +302 -0
  215. package/src/workflow/tool-description.ts +200 -0
  216. package/src/workflow/worker-source.ts +781 -0
  217. package/src/worktree.ts +205 -0
  218. package/src/xml.ts +13 -0
@@ -0,0 +1,56 @@
1
+ /**
2
+ * context.ts — Extract parent conversation context for subagent inheritance.
3
+ */
4
+ /** Extract text from a message content block array. */
5
+ export function extractText(content) {
6
+ return content
7
+ .filter((c) => c.type === "text")
8
+ .map((c) => c.text ?? "")
9
+ .join("\n");
10
+ }
11
+ /**
12
+ * Build a text representation of the parent conversation context.
13
+ * Used when inherit_context is true to give the subagent visibility
14
+ * into what has been discussed/done so far.
15
+ */
16
+ export function buildParentContext(ctx) {
17
+ const entries = ctx.sessionManager.getBranch();
18
+ if (!entries || entries.length === 0)
19
+ return "";
20
+ const parts = [];
21
+ for (const entry of entries) {
22
+ if (entry.type === "message") {
23
+ const msg = entry.message;
24
+ if (msg.role === "user") {
25
+ const text = typeof msg.content === "string"
26
+ ? msg.content
27
+ : extractText(msg.content);
28
+ if (text.trim())
29
+ parts.push(`[User]: ${text.trim()}`);
30
+ }
31
+ else if (msg.role === "assistant") {
32
+ const text = extractText(msg.content);
33
+ if (text.trim())
34
+ parts.push(`[Assistant]: ${text.trim()}`);
35
+ }
36
+ // Skip toolResult messages — too verbose for context
37
+ }
38
+ else if (entry.type === "compaction") {
39
+ // Include compaction summaries — they're already condensed
40
+ if (entry.summary) {
41
+ parts.push(`[Summary]: ${entry.summary}`);
42
+ }
43
+ }
44
+ }
45
+ if (parts.length === 0)
46
+ return "";
47
+ return `# Parent Conversation Context
48
+ The following is the conversation history from the parent session that spawned you.
49
+ Use this context to understand what has been discussed and decided so far.
50
+
51
+ ${parts.join("\n\n")}
52
+
53
+ ---
54
+ # Your Task (below)
55
+ `;
56
+ }
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Cross-extension RPC handlers for the subagents extension.
3
+ *
4
+ * Exposes ping, spawn, stop, and consume RPCs over the pi.events event bus,
5
+ * using per-request scoped reply channels.
6
+ *
7
+ * Reply envelope follows pi-mono convention:
8
+ * success → { success: true, data?: T }
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
+ */
15
+ import type { AgentRecord } from "./types.js";
16
+ /** Minimal event bus interface needed by the RPC handlers. */
17
+ export interface EventBus {
18
+ on(event: string, handler: (data: unknown) => void): () => void;
19
+ emit(event: string, data: unknown): void;
20
+ }
21
+ /** RPC reply envelope — matches pi-mono's RpcResponse shape. */
22
+ export type RpcReply<T = void> = {
23
+ success: true;
24
+ data?: T;
25
+ } | {
26
+ success: false;
27
+ error: string;
28
+ };
29
+ /** RPC protocol version — bumped when the envelope or method contracts change. */
30
+ export declare const PROTOCOL_VERSION = 2;
31
+ /** Minimal AgentManager interface needed by the spawn/stop/consume RPCs. */
32
+ export interface SpawnCapable {
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>;
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;
49
+ }
50
+ export interface RpcDeps {
51
+ events: EventBus;
52
+ pi: unknown;
53
+ getCtx: () => unknown | undefined;
54
+ manager: SpawnCapable;
55
+ }
56
+ export interface RpcHandle {
57
+ unsubPing: () => void;
58
+ unsubSpawn: () => void;
59
+ unsubStop: () => void;
60
+ unsubConsume: () => void;
61
+ }
62
+ /**
63
+ * Register ping, spawn, stop, and consume RPC handlers on the event bus.
64
+ * Returns unsub functions for cleanup.
65
+ */
66
+ export declare function registerRpcHandlers(deps: RpcDeps): RpcHandle;
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Cross-extension RPC handlers for the subagents extension.
3
+ *
4
+ * Exposes ping, spawn, stop, and consume RPCs over the pi.events event bus,
5
+ * using per-request scoped reply channels.
6
+ *
7
+ * Reply envelope follows pi-mono convention:
8
+ * success → { success: true, data?: T }
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
+ */
15
+ import { isTopLevelAgent } from "./agent-manager.js";
16
+ import { resolveModel } from "./model-resolver.js";
17
+ import { checkModelScope } from "./model-scope.js";
18
+ /** RPC protocol version — bumped when the envelope or method contracts change. */
19
+ export const PROTOCOL_VERSION = 2;
20
+ /**
21
+ * Wire a single RPC handler: listen on `channel`, run `fn(params)`,
22
+ * emit the reply envelope on `channel:reply:${requestId}`.
23
+ */
24
+ function handleRpc(events, channel, fn) {
25
+ return events.on(channel, async (raw) => {
26
+ const params = raw;
27
+ try {
28
+ const data = await fn(params);
29
+ const reply = { success: true };
30
+ if (data !== undefined)
31
+ reply.data = data;
32
+ events.emit(`${channel}:reply:${params.requestId}`, reply);
33
+ }
34
+ catch (err) {
35
+ events.emit(`${channel}:reply:${params.requestId}`, {
36
+ success: false, error: err?.message ?? String(err),
37
+ });
38
+ }
39
+ });
40
+ }
41
+ /**
42
+ * Register ping, spawn, stop, and consume RPC handlers on the event bus.
43
+ * Returns unsub functions for cleanup.
44
+ */
45
+ export function registerRpcHandlers(deps) {
46
+ const { events, pi, getCtx, manager } = deps;
47
+ const unsubPing = handleRpc(events, "subagents:rpc:ping", () => {
48
+ return { version: PROTOCOL_VERSION };
49
+ });
50
+ const unsubSpawn = handleRpc(events, "subagents:rpc:spawn", async ({ type, prompt, options }) => {
51
+ const ctx = getCtx();
52
+ if (!ctx)
53
+ throw new Error("No active session");
54
+ // Cross-extension RPC callers (e.g. pi-tasks TaskExecute) naturally
55
+ // forward serializable values, so options.model can be a string like
56
+ // "openai-codex/gpt-5.5". Resolve it to a real Model instance here
57
+ // — same pattern the scheduler path already uses — so the spawned
58
+ // agent's auth lookup doesn't crash with "No API key found for
59
+ // undefined".
60
+ let normalizedOptions = options ?? {};
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`);
72
+ }
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 };
84
+ }
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);
101
+ }
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 };
108
+ });
109
+ const unsubStop = handleRpc(events, "subagents:rpc:stop", ({ agentId }) => {
110
+ const record = manager.getRecord(agentId);
111
+ if (!record)
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");
136
+ });
137
+ return { unsubPing, unsubSpawn, unsubStop, unsubConsume };
138
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * custom-agents.ts — Load user-defined agents from project (.pi/agents/, plus the shared .agents/agents/ workspace) and global ($PI_CODING_AGENT_DIR/agents/, default ~/.pi/agent/agents/) locations.
3
+ */
4
+ import type { AgentConfig } from "./types.js";
5
+ /**
6
+ * Scan for custom agent .md files from multiple locations.
7
+ * Discovery hierarchy (higher priority wins):
8
+ * 1. Project: <cwd>/.pi/agents/*.md (authoritative — also where /agents writes)
9
+ * 2. Workspace: <cwd>/.agents/agents/*.md (shared cross-tool .agents workspace, read-only)
10
+ * 3. Global: $PI_CODING_AGENT_DIR/agents/*.md (default: ~/.pi/agent/agents/*.md)
11
+ *
12
+ * Project-level agents override global ones with the same name. On a name clash
13
+ * between the two project locations, .pi/agents wins — .pi stays the project
14
+ * authority; .agents/agents is an additional read location.
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.
50
+ */
51
+ export declare function parseAgentFrontmatter<T extends Record<string, unknown>>(content: string): {
52
+ frontmatter: T;
53
+ body: string;
54
+ };