@gotgenes/pi-subagents 1.0.0 → 1.0.2

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 (61) hide show
  1. package/AGENTS.md +4 -82
  2. package/CHANGELOG.md +29 -0
  3. package/README.md +18 -4
  4. package/docs/architecture/architecture.md +391 -0
  5. package/docs/decisions/0001-deferred-patches.md +13 -14
  6. package/docs/plans/0051-update-adr-0001-hard-fork.md +74 -0
  7. package/package.json +12 -17
  8. package/.markdownlint-cli2.yaml +0 -19
  9. package/.release-please-manifest.json +0 -3
  10. package/dist/agent-manager.d.ts +0 -108
  11. package/dist/agent-manager.js +0 -390
  12. package/dist/agent-runner.d.ts +0 -93
  13. package/dist/agent-runner.js +0 -428
  14. package/dist/agent-types.d.ts +0 -48
  15. package/dist/agent-types.js +0 -136
  16. package/dist/context.d.ts +0 -12
  17. package/dist/context.js +0 -56
  18. package/dist/cross-extension-rpc.d.ts +0 -46
  19. package/dist/cross-extension-rpc.js +0 -54
  20. package/dist/custom-agents.d.ts +0 -14
  21. package/dist/custom-agents.js +0 -127
  22. package/dist/default-agents.d.ts +0 -7
  23. package/dist/default-agents.js +0 -119
  24. package/dist/env.d.ts +0 -6
  25. package/dist/env.js +0 -28
  26. package/dist/group-join.d.ts +0 -32
  27. package/dist/group-join.js +0 -116
  28. package/dist/index.d.ts +0 -13
  29. package/dist/index.js +0 -1731
  30. package/dist/invocation-config.d.ts +0 -22
  31. package/dist/invocation-config.js +0 -15
  32. package/dist/memory.d.ts +0 -49
  33. package/dist/memory.js +0 -151
  34. package/dist/model-resolver.d.ts +0 -19
  35. package/dist/model-resolver.js +0 -62
  36. package/dist/output-file.d.ts +0 -24
  37. package/dist/output-file.js +0 -86
  38. package/dist/prompts.d.ts +0 -29
  39. package/dist/prompts.js +0 -72
  40. package/dist/schedule-store.d.ts +0 -36
  41. package/dist/schedule-store.js +0 -144
  42. package/dist/schedule.d.ts +0 -109
  43. package/dist/schedule.js +0 -338
  44. package/dist/settings.d.ts +0 -66
  45. package/dist/settings.js +0 -130
  46. package/dist/skill-loader.d.ts +0 -24
  47. package/dist/skill-loader.js +0 -93
  48. package/dist/types.d.ts +0 -164
  49. package/dist/types.js +0 -5
  50. package/dist/ui/agent-widget.d.ts +0 -134
  51. package/dist/ui/agent-widget.js +0 -451
  52. package/dist/ui/conversation-viewer.d.ts +0 -35
  53. package/dist/ui/conversation-viewer.js +0 -252
  54. package/dist/ui/schedule-menu.d.ts +0 -16
  55. package/dist/ui/schedule-menu.js +0 -95
  56. package/dist/usage.d.ts +0 -50
  57. package/dist/usage.js +0 -49
  58. package/dist/worktree.d.ts +0 -36
  59. package/dist/worktree.js +0 -139
  60. package/prek.toml +0 -24
  61. package/release-please-config.json +0 -22
@@ -1,93 +0,0 @@
1
- /**
2
- * agent-runner.ts — Core execution engine: creates sessions, runs agents, collects results.
3
- */
4
- import type { Model } from "@earendil-works/pi-ai";
5
- import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
6
- import { type AgentSession, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
7
- import type { SubagentType, ThinkingLevel } from "./types.js";
8
- /** Normalize max turns. undefined or 0 = unlimited, otherwise minimum 1. */
9
- export declare function normalizeMaxTurns(n: number | undefined): number | undefined;
10
- /** Get the default max turns value. undefined = unlimited. */
11
- export declare function getDefaultMaxTurns(): number | undefined;
12
- /** Set the default max turns value. undefined or 0 = unlimited, otherwise minimum 1. */
13
- export declare function setDefaultMaxTurns(n: number | undefined): void;
14
- /** Get the grace turns value. */
15
- export declare function getGraceTurns(): number;
16
- /** Set the grace turns value (minimum 1). */
17
- export declare function setGraceTurns(n: number): void;
18
- /** Info about a tool event in the subagent. */
19
- export interface ToolActivity {
20
- type: "start" | "end";
21
- toolName: string;
22
- }
23
- export interface RunOptions {
24
- /** ExtensionAPI instance — used for pi.exec() instead of execSync. */
25
- pi: ExtensionAPI;
26
- model?: Model<any>;
27
- maxTurns?: number;
28
- signal?: AbortSignal;
29
- isolated?: boolean;
30
- inheritContext?: boolean;
31
- thinkingLevel?: ThinkingLevel;
32
- /** Override working directory (e.g. for worktree isolation). */
33
- cwd?: string;
34
- /** Called on tool start/end with activity info. */
35
- onToolActivity?: (activity: ToolActivity) => void;
36
- /** Called on streaming text deltas from the assistant response. */
37
- onTextDelta?: (delta: string, fullText: string) => void;
38
- onSessionCreated?: (session: AgentSession) => void;
39
- /** Called at the end of each agentic turn with the cumulative count. */
40
- onTurnEnd?: (turnCount: number) => void;
41
- /**
42
- * Called once per assistant message_end with that message's usage delta.
43
- * Lets callers maintain a lifetime accumulator that survives compaction
44
- * (which replaces session.state.messages and resets stats-derived sums).
45
- */
46
- onAssistantUsage?: (usage: {
47
- input: number;
48
- output: number;
49
- cacheWrite: number;
50
- }) => void;
51
- /**
52
- * Called when the session successfully compacts. `tokensBefore` is upstream's
53
- * pre-compaction context size estimate. Aborted compactions don't fire.
54
- */
55
- onCompaction?: (info: {
56
- reason: "manual" | "threshold" | "overflow";
57
- tokensBefore: number;
58
- }) => void;
59
- }
60
- export interface RunResult {
61
- responseText: string;
62
- session: AgentSession;
63
- /** True if the agent was hard-aborted (max_turns + grace exceeded). */
64
- aborted: boolean;
65
- /** True if the agent was steered to wrap up (hit soft turn limit) but finished in time. */
66
- steered: boolean;
67
- }
68
- export declare function runAgent(ctx: ExtensionContext, type: SubagentType, prompt: string, options: RunOptions): Promise<RunResult>;
69
- /**
70
- * Send a new prompt to an existing session (resume).
71
- */
72
- export declare function resumeAgent(session: AgentSession, prompt: string, options?: {
73
- onToolActivity?: (activity: ToolActivity) => void;
74
- onAssistantUsage?: (usage: {
75
- input: number;
76
- output: number;
77
- cacheWrite: number;
78
- }) => void;
79
- onCompaction?: (info: {
80
- reason: "manual" | "threshold" | "overflow";
81
- tokensBefore: number;
82
- }) => void;
83
- signal?: AbortSignal;
84
- }): Promise<string>;
85
- /**
86
- * Send a steering message to a running subagent.
87
- * The message will interrupt the agent after its current tool execution.
88
- */
89
- export declare function steerAgent(session: AgentSession, message: string): Promise<void>;
90
- /**
91
- * Get the subagent's conversation messages as formatted text.
92
- */
93
- export declare function getAgentConversation(session: AgentSession): string;
@@ -1,428 +0,0 @@
1
- /**
2
- * agent-runner.ts — Core execution engine: creates sessions, runs agents, collects results.
3
- */
4
- import { createAgentSession, DefaultResourceLoader, getAgentDir, SessionManager, SettingsManager, } from "@earendil-works/pi-coding-agent";
5
- import { getAgentConfig, getConfig, getMemoryToolNames, getReadOnlyMemoryToolNames, getToolNamesForType, } from "./agent-types.js";
6
- import { buildParentContext, extractText } from "./context.js";
7
- import { DEFAULT_AGENTS } from "./default-agents.js";
8
- import { detectEnv } from "./env.js";
9
- import { buildMemoryBlock, buildReadOnlyMemoryBlock } from "./memory.js";
10
- import { buildAgentPrompt } from "./prompts.js";
11
- import { preloadSkills } from "./skill-loader.js";
12
- /** Names of tools registered by this extension that subagents must NOT inherit. */
13
- const EXCLUDED_TOOL_NAMES = ["Agent", "get_subagent_result", "steer_subagent"];
14
- /**
15
- * Filter the session's active tool names according to extension/denylist rules.
16
- *
17
- * Run twice — once before `bindExtensions` (filters built-in tools) and once after
18
- * (filters extension-registered tools, which only join the active set during
19
- * `bindExtensions`). Extracting this keeps the two callsites consistent and makes
20
- * the post-bind re-filter trivial.
21
- *
22
- * @param activeTools Names currently active on the session.
23
- * @param toolNames The built-in tool name allowlist for this agent type.
24
- * @param extensions Agent config `extensions` field: false | true | string[] (allowlist).
25
- * @param disallowedSet Optional denylist from agent config.
26
- */
27
- function filterActiveTools(activeTools, toolNames, extensions, disallowedSet) {
28
- if (extensions === false) {
29
- // Extensions disabled: only apply the denylist to built-in tools.
30
- if (!disallowedSet)
31
- return activeTools;
32
- return activeTools.filter((t) => !disallowedSet.has(t));
33
- }
34
- const builtinToolNameSet = new Set(toolNames);
35
- return activeTools.filter((t) => {
36
- if (EXCLUDED_TOOL_NAMES.includes(t))
37
- return false;
38
- if (disallowedSet?.has(t))
39
- return false;
40
- if (builtinToolNameSet.has(t))
41
- return true;
42
- if (Array.isArray(extensions)) {
43
- return extensions.some((ext) => t.startsWith(ext) || t.includes(ext));
44
- }
45
- return true;
46
- });
47
- }
48
- /** Default max turns. undefined = unlimited (no turn limit). */
49
- let defaultMaxTurns;
50
- /** Normalize max turns. undefined or 0 = unlimited, otherwise minimum 1. */
51
- export function normalizeMaxTurns(n) {
52
- if (n == null || n === 0)
53
- return undefined;
54
- return Math.max(1, n);
55
- }
56
- /** Get the default max turns value. undefined = unlimited. */
57
- export function getDefaultMaxTurns() {
58
- return defaultMaxTurns;
59
- }
60
- /** Set the default max turns value. undefined or 0 = unlimited, otherwise minimum 1. */
61
- export function setDefaultMaxTurns(n) {
62
- defaultMaxTurns = normalizeMaxTurns(n);
63
- }
64
- /** Additional turns allowed after the soft limit steer message. */
65
- let graceTurns = 5;
66
- /** Get the grace turns value. */
67
- export function getGraceTurns() {
68
- return graceTurns;
69
- }
70
- /** Set the grace turns value (minimum 1). */
71
- export function setGraceTurns(n) {
72
- graceTurns = Math.max(1, n);
73
- }
74
- /**
75
- * Try to find the right model for an agent type.
76
- * Priority: explicit option > config.model > parent model.
77
- */
78
- function resolveDefaultModel(parentModel, registry, configModel) {
79
- if (configModel) {
80
- const slashIdx = configModel.indexOf("/");
81
- if (slashIdx !== -1) {
82
- const provider = configModel.slice(0, slashIdx);
83
- const modelId = configModel.slice(slashIdx + 1);
84
- // Build a set of available model keys for fast lookup
85
- const available = registry.getAvailable?.();
86
- const availableKeys = available
87
- ? new Set(available.map((m) => `${m.provider}/${m.id}`))
88
- : undefined;
89
- const isAvailable = (p, id) => !availableKeys || availableKeys.has(`${p}/${id}`);
90
- const found = registry.find(provider, modelId);
91
- if (found && isAvailable(provider, modelId))
92
- return found;
93
- }
94
- }
95
- return parentModel;
96
- }
97
- /**
98
- * Subscribe to a session and collect the last assistant message text.
99
- * Returns an object with a `getText()` getter and an `unsubscribe` function.
100
- */
101
- function collectResponseText(session) {
102
- let text = "";
103
- const unsubscribe = session.subscribe((event) => {
104
- if (event.type === "message_start") {
105
- text = "";
106
- }
107
- if (event.type === "message_update" &&
108
- event.assistantMessageEvent.type === "text_delta") {
109
- text += event.assistantMessageEvent.delta;
110
- }
111
- });
112
- return { getText: () => text, unsubscribe };
113
- }
114
- /** Get the last assistant text from the completed session history. */
115
- function getLastAssistantText(session) {
116
- for (let i = session.messages.length - 1; i >= 0; i--) {
117
- const msg = session.messages[i];
118
- if (msg.role !== "assistant")
119
- continue;
120
- const text = extractText(msg.content).trim();
121
- if (text)
122
- return text;
123
- }
124
- return "";
125
- }
126
- /**
127
- * Wire an AbortSignal to abort a session.
128
- * Returns a cleanup function to remove the listener.
129
- */
130
- function forwardAbortSignal(session, signal) {
131
- if (!signal)
132
- return () => { };
133
- const onAbort = () => session.abort();
134
- signal.addEventListener("abort", onAbort, { once: true });
135
- return () => signal.removeEventListener("abort", onAbort);
136
- }
137
- export async function runAgent(ctx, type, prompt, options) {
138
- const config = getConfig(type);
139
- const agentConfig = getAgentConfig(type);
140
- // Resolve working directory: worktree override > parent cwd
141
- const effectiveCwd = options.cwd ?? ctx.cwd;
142
- const env = await detectEnv(options.pi, effectiveCwd);
143
- // Get parent system prompt for append-mode agents
144
- const parentSystemPrompt = ctx.getSystemPrompt();
145
- // Build prompt extras (memory, skill preloading)
146
- const extras = {};
147
- // Resolve extensions/skills: isolated overrides to false
148
- const extensions = options.isolated ? false : config.extensions;
149
- const skills = options.isolated ? false : config.skills;
150
- // Skill preloading: when skills is string[], preload their content into prompt
151
- if (Array.isArray(skills)) {
152
- const loaded = preloadSkills(skills, effectiveCwd);
153
- if (loaded.length > 0) {
154
- extras.skillBlocks = loaded;
155
- }
156
- }
157
- let toolNames = getToolNamesForType(type);
158
- // Persistent memory: detect write capability and branch accordingly.
159
- // Account for disallowedTools — a tool in the base set but on the denylist is not truly available.
160
- if (agentConfig?.memory) {
161
- const existingNames = new Set(toolNames);
162
- const denied = agentConfig.disallowedTools
163
- ? new Set(agentConfig.disallowedTools)
164
- : undefined;
165
- const effectivelyHas = (name) => existingNames.has(name) && !denied?.has(name);
166
- const hasWriteTools = effectivelyHas("write") || effectivelyHas("edit");
167
- if (hasWriteTools) {
168
- // Read-write memory: add any missing memory tool names (read/write/edit)
169
- const extraNames = getMemoryToolNames(existingNames);
170
- if (extraNames.length > 0)
171
- toolNames = [...toolNames, ...extraNames];
172
- extras.memoryBlock = buildMemoryBlock(agentConfig.name, agentConfig.memory, effectiveCwd);
173
- }
174
- else {
175
- // Read-only memory: only add read tool name, use read-only prompt
176
- const extraNames = getReadOnlyMemoryToolNames(existingNames);
177
- if (extraNames.length > 0)
178
- toolNames = [...toolNames, ...extraNames];
179
- extras.memoryBlock = buildReadOnlyMemoryBlock(agentConfig.name, agentConfig.memory, effectiveCwd);
180
- }
181
- }
182
- // Build system prompt from agent config
183
- let systemPrompt;
184
- if (agentConfig) {
185
- systemPrompt = buildAgentPrompt(agentConfig, effectiveCwd, env, parentSystemPrompt, extras);
186
- }
187
- else {
188
- // Unknown type fallback: spread the canonical general-purpose config (defensive —
189
- // unreachable in practice since index.ts resolves unknown types before calling runAgent).
190
- const fallback = DEFAULT_AGENTS.get("general-purpose");
191
- if (!fallback)
192
- throw new Error(`No fallback config available for unknown type "${type}"`);
193
- systemPrompt = buildAgentPrompt({ ...fallback, name: type }, effectiveCwd, env, parentSystemPrompt, extras);
194
- }
195
- // When skills is string[], we've already preloaded them into the prompt.
196
- // Still pass noSkills: true since we don't need the skill loader to load them again.
197
- const noSkills = skills === false || Array.isArray(skills);
198
- const agentDir = getAgentDir();
199
- // Load extensions/skills: true or string[] → load; false → don't.
200
- // Suppress AGENTS.md/CLAUDE.md and APPEND_SYSTEM.md — upstream's
201
- // buildSystemPrompt() re-appends both AFTER systemPromptOverride, which
202
- // would defeat prompt_mode: replace and isolated: true. Parent context, if
203
- // wanted, reaches the subagent via prompt_mode: append (parentSystemPrompt
204
- // is embedded in systemPromptOverride) or inherit_context (conversation).
205
- const loader = new DefaultResourceLoader({
206
- cwd: effectiveCwd,
207
- agentDir,
208
- noExtensions: extensions === false,
209
- noSkills,
210
- noPromptTemplates: true,
211
- noThemes: true,
212
- noContextFiles: true,
213
- systemPromptOverride: () => systemPrompt,
214
- appendSystemPromptOverride: () => [],
215
- });
216
- await loader.reload();
217
- // Resolve model: explicit option > config.model > parent model
218
- const model = options.model ??
219
- resolveDefaultModel(ctx.model, ctx.modelRegistry, agentConfig?.model);
220
- // Resolve thinking level: explicit option > agent config > undefined (inherit)
221
- const thinkingLevel = options.thinkingLevel ?? agentConfig?.thinking;
222
- const sessionOpts = {
223
- cwd: effectiveCwd,
224
- agentDir,
225
- sessionManager: SessionManager.inMemory(effectiveCwd),
226
- settingsManager: SettingsManager.create(effectiveCwd, agentDir),
227
- modelRegistry: ctx.modelRegistry,
228
- model,
229
- tools: toolNames,
230
- resourceLoader: loader,
231
- };
232
- if (thinkingLevel) {
233
- sessionOpts.thinkingLevel = thinkingLevel;
234
- }
235
- const { session } = await createAgentSession(sessionOpts);
236
- // Build disallowed tools set from agent config
237
- const disallowedSet = agentConfig?.disallowedTools
238
- ? new Set(agentConfig.disallowedTools)
239
- : undefined;
240
- // Filter active tools: remove our own tools to prevent nesting,
241
- // apply extension allowlist if specified, and apply disallowedTools denylist.
242
- // First pass — over built-in tools, before bindExtensions registers extension tools.
243
- if (extensions !== false || disallowedSet) {
244
- const filtered = filterActiveTools(session.getActiveToolNames(), toolNames, extensions, disallowedSet);
245
- session.setActiveToolsByName(filtered);
246
- }
247
- // Bind extensions so that session_start fires and extensions can initialize
248
- // (e.g. loading credentials, setting up state). Placed after tool filtering
249
- // so extension-provided skills/prompts from extendResourcesFromExtensions()
250
- // respect the active tool set. All ExtensionBindings fields are optional.
251
- await session.bindExtensions({
252
- onError: (err) => {
253
- options.onToolActivity?.({
254
- type: "end",
255
- toolName: `extension-error:${err.extensionPath}`,
256
- });
257
- },
258
- });
259
- // Patch 2 (RepOne #443): re-filter active tools after bindExtensions.
260
- // Extension-registered tools (added during bindExtensions) are not in the
261
- // session's active set when the first filter pass runs above. Without this
262
- // re-filter, the `extensions: string[]` allowlist branch never matches any
263
- // extension tools and `extensions: true` lets non-allowlisted denylist
264
- // entries slip in. Run the same filter against the post-bind active set.
265
- if (extensions !== false || disallowedSet) {
266
- const refiltered = filterActiveTools(session.getActiveToolNames(), toolNames, extensions, disallowedSet);
267
- session.setActiveToolsByName(refiltered);
268
- }
269
- options.onSessionCreated?.(session);
270
- // Track turns for graceful max_turns enforcement
271
- let turnCount = 0;
272
- const maxTurns = normalizeMaxTurns(options.maxTurns ?? agentConfig?.maxTurns ?? defaultMaxTurns);
273
- let softLimitReached = false;
274
- let aborted = false;
275
- let currentMessageText = "";
276
- const unsubTurns = session.subscribe((event) => {
277
- if (event.type === "turn_end") {
278
- turnCount++;
279
- options.onTurnEnd?.(turnCount);
280
- if (maxTurns != null) {
281
- if (!softLimitReached && turnCount >= maxTurns) {
282
- softLimitReached = true;
283
- session.steer("You have reached your turn limit. Wrap up immediately — provide your final answer now.");
284
- }
285
- else if (softLimitReached && turnCount >= maxTurns + graceTurns) {
286
- aborted = true;
287
- session.abort();
288
- }
289
- }
290
- }
291
- if (event.type === "message_start") {
292
- currentMessageText = "";
293
- }
294
- if (event.type === "message_update" &&
295
- event.assistantMessageEvent.type === "text_delta") {
296
- currentMessageText += event.assistantMessageEvent.delta;
297
- options.onTextDelta?.(event.assistantMessageEvent.delta, currentMessageText);
298
- }
299
- if (event.type === "tool_execution_start") {
300
- options.onToolActivity?.({ type: "start", toolName: event.toolName });
301
- }
302
- if (event.type === "tool_execution_end") {
303
- options.onToolActivity?.({ type: "end", toolName: event.toolName });
304
- }
305
- if (event.type === "message_end" && event.message.role === "assistant") {
306
- const u = event.message.usage;
307
- if (u)
308
- options.onAssistantUsage?.({
309
- input: u.input ?? 0,
310
- output: u.output ?? 0,
311
- cacheWrite: u.cacheWrite ?? 0,
312
- });
313
- }
314
- if (event.type === "compaction_end" && !event.aborted && event.result) {
315
- options.onCompaction?.({
316
- reason: event.reason,
317
- tokensBefore: event.result.tokensBefore,
318
- });
319
- }
320
- });
321
- const collector = collectResponseText(session);
322
- const cleanupAbort = forwardAbortSignal(session, options.signal);
323
- // Build the effective prompt: optionally prepend parent context
324
- let effectivePrompt = prompt;
325
- if (options.inheritContext) {
326
- const parentContext = buildParentContext(ctx);
327
- if (parentContext) {
328
- effectivePrompt = parentContext + prompt;
329
- }
330
- }
331
- try {
332
- await session.prompt(effectivePrompt);
333
- }
334
- finally {
335
- unsubTurns();
336
- collector.unsubscribe();
337
- cleanupAbort();
338
- }
339
- const responseText = collector.getText().trim() || getLastAssistantText(session);
340
- return { responseText, session, aborted, steered: softLimitReached };
341
- }
342
- /**
343
- * Send a new prompt to an existing session (resume).
344
- */
345
- export async function resumeAgent(session, prompt, options = {}) {
346
- const collector = collectResponseText(session);
347
- const cleanupAbort = forwardAbortSignal(session, options.signal);
348
- const unsubEvents = options.onToolActivity || options.onAssistantUsage || options.onCompaction
349
- ? session.subscribe((event) => {
350
- if (event.type === "tool_execution_start")
351
- options.onToolActivity?.({
352
- type: "start",
353
- toolName: event.toolName,
354
- });
355
- if (event.type === "tool_execution_end")
356
- options.onToolActivity?.({ type: "end", toolName: event.toolName });
357
- if (event.type === "message_end" &&
358
- event.message.role === "assistant") {
359
- const u = event.message.usage;
360
- if (u)
361
- options.onAssistantUsage?.({
362
- input: u.input ?? 0,
363
- output: u.output ?? 0,
364
- cacheWrite: u.cacheWrite ?? 0,
365
- });
366
- }
367
- if (event.type === "compaction_end" &&
368
- !event.aborted &&
369
- event.result) {
370
- options.onCompaction?.({
371
- reason: event.reason,
372
- tokensBefore: event.result.tokensBefore,
373
- });
374
- }
375
- })
376
- : () => { };
377
- try {
378
- await session.prompt(prompt);
379
- }
380
- finally {
381
- collector.unsubscribe();
382
- unsubEvents();
383
- cleanupAbort();
384
- }
385
- return collector.getText().trim() || getLastAssistantText(session);
386
- }
387
- /**
388
- * Send a steering message to a running subagent.
389
- * The message will interrupt the agent after its current tool execution.
390
- */
391
- export async function steerAgent(session, message) {
392
- await session.steer(message);
393
- }
394
- /**
395
- * Get the subagent's conversation messages as formatted text.
396
- */
397
- export function getAgentConversation(session) {
398
- const parts = [];
399
- for (const msg of session.messages) {
400
- if (msg.role === "user") {
401
- const text = typeof msg.content === "string"
402
- ? msg.content
403
- : extractText(msg.content);
404
- if (text.trim())
405
- parts.push(`[User]: ${text.trim()}`);
406
- }
407
- else if (msg.role === "assistant") {
408
- const textParts = [];
409
- const toolCalls = [];
410
- for (const c of msg.content) {
411
- if (c.type === "text" && c.text)
412
- textParts.push(c.text);
413
- else if (c.type === "toolCall")
414
- toolCalls.push(` Tool: ${c.name ?? c.toolName ?? "unknown"}`);
415
- }
416
- if (textParts.length > 0)
417
- parts.push(`[Assistant]: ${textParts.join("\n")}`);
418
- if (toolCalls.length > 0)
419
- parts.push(`[Tool Calls]:\n${toolCalls.join("\n")}`);
420
- }
421
- else if (msg.role === "toolResult") {
422
- const text = extractText(msg.content);
423
- const truncated = text.length > 200 ? text.slice(0, 200) + "..." : text;
424
- parts.push(`[Tool Result (${msg.toolName})]: ${truncated}`);
425
- }
426
- }
427
- return parts.join("\n\n");
428
- }
@@ -1,48 +0,0 @@
1
- /**
2
- * agent-types.ts — Unified agent type registry.
3
- *
4
- * Merges embedded default agents with user-defined agents from .pi/agents/*.md.
5
- * User agents override defaults with the same name. Disabled agents are kept but excluded from spawning.
6
- */
7
- import type { AgentConfig } from "./types.js";
8
- /** All known built-in tool names. */
9
- export declare const BUILTIN_TOOL_NAMES: string[];
10
- /**
11
- * Register agents into the unified registry.
12
- * Starts with DEFAULT_AGENTS, then overlays user agents (overrides defaults with same name).
13
- * Disabled agents (enabled === false) are kept in the registry but excluded from spawning.
14
- */
15
- export declare function registerAgents(userAgents: Map<string, AgentConfig>): void;
16
- /** Resolve a type name case-insensitively. Returns the canonical key or undefined. */
17
- export declare function resolveType(name: string): string | undefined;
18
- /** Get the agent config for a type (case-insensitive). */
19
- export declare function getAgentConfig(name: string): AgentConfig | undefined;
20
- /** Get all enabled type names (for spawning and tool descriptions). */
21
- export declare function getAvailableTypes(): string[];
22
- /** Get all type names including disabled (for UI listing). */
23
- export declare function getAllTypes(): string[];
24
- /** Get names of default agents currently in the registry. */
25
- export declare function getDefaultAgentNames(): string[];
26
- /** Get names of user-defined agents (non-defaults) currently in the registry. */
27
- export declare function getUserAgentNames(): string[];
28
- /** Check if a type is valid and enabled (case-insensitive). */
29
- export declare function isValidType(type: string): boolean;
30
- /**
31
- * Get memory tool names (read/write/edit) not already in the provided set.
32
- */
33
- export declare function getMemoryToolNames(existingToolNames: Set<string>): string[];
34
- /**
35
- * Get read-only memory tool names not already in the provided set.
36
- */
37
- export declare function getReadOnlyMemoryToolNames(existingToolNames: Set<string>): string[];
38
- /** Get built-in tool names for a type (case-insensitive). */
39
- export declare function getToolNamesForType(type: string): string[];
40
- /** Get config for a type (case-insensitive, returns a SubagentTypeConfig-compatible object). Falls back to general-purpose. */
41
- export declare function getConfig(type: string): {
42
- displayName: string;
43
- description: string;
44
- builtinToolNames: string[];
45
- extensions: true | string[] | false;
46
- skills: true | string[] | false;
47
- promptMode: "replace" | "append";
48
- };