@xzzpig/pi-subagents 0.4.2 → 0.6.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.
- package/CHANGELOG.md +172 -1
- package/README.md +8 -0
- package/agents/oracle.md +3 -1
- package/agents/reviewer.md +1 -0
- package/agents/scout.md +2 -2
- package/agents/worker.md +2 -1
- package/async-retention-discovery-worker.mjs +180 -0
- package/docs/agents.md +79 -2
- package/docs/configuration.md +42 -14
- package/docs/extension-api.md +45 -2
- package/docs/models.md +2 -0
- package/docs/observability.md +41 -5
- package/docs/tool-reference.md +38 -39
- package/docs/workflows.md +173 -3
- package/package.json +13 -10
- package/prompts/council.md +48 -0
- package/skills/council-mode/SKILL.md +230 -0
- package/skills/pi-subagents/SKILL.md +8 -4
- package/skills/pi-subagents/references/constraints-and-recipes.md +13 -6
- package/skills/pi-subagents/references/execution-controls.md +40 -15
- package/skills/pi-subagents/references/management-authoring-rpc.md +3 -3
- package/skills/pi-subagents/references/multi-lane-orchestration.md +39 -0
- package/skills/pi-subagents/references/prompting-and-roles.md +4 -2
- package/src/agents/agent-management.ts +158 -357
- package/src/agents/agent-serializer.ts +4 -0
- package/src/agents/agents.ts +227 -53
- package/src/agents/builtin-names.ts +9 -0
- package/src/agents/runtime-agent-registry.ts +422 -0
- package/src/agents/skills.ts +1 -1
- package/src/api/agents.ts +7 -0
- package/src/api/external-job-provider.ts +186 -0
- package/src/api/preflight.ts +37 -9
- package/src/api/shared-types.ts +2 -0
- package/src/extension/config.ts +6 -3
- package/src/extension/context-injection.ts +118 -0
- package/src/extension/doctor.ts +15 -6
- package/src/extension/fanout-child.ts +2 -2
- package/src/extension/index.ts +224 -90
- package/src/extension/public-execution.ts +31 -2
- package/src/extension/rpc.ts +41 -1
- package/src/extension/schemas.ts +17 -37
- package/src/extension/tool-description.ts +35 -24
- package/src/inspectors/herdr/actions.ts +2 -2
- package/src/inspectors/herdr/inspector-runner.ts +2 -1
- package/src/inspectors/herdr/project-panes.ts +2 -2
- package/src/intercom/native-supervisor-channel.ts +32 -10
- package/src/missions/lifecycle.ts +6 -1
- package/src/missions/store.ts +4 -9
- package/src/missions/workflow-state.ts +2 -2
- package/src/profiles/profiles.ts +3 -1
- package/src/runs/background/active-run-index.ts +31 -8
- package/src/runs/background/async-execution.ts +70 -41
- package/src/runs/background/async-job-tracker.ts +24 -7
- package/src/runs/background/async-resume.ts +49 -16
- package/src/runs/background/async-retention.ts +886 -0
- package/src/runs/background/async-status-snapshot.ts +14 -5
- package/src/runs/background/async-status.ts +39 -53
- package/src/runs/background/auto-drain.ts +1 -0
- package/src/runs/background/chain-append.ts +3 -33
- package/src/runs/background/completion-dedupe.ts +5 -1
- package/src/runs/background/completion-replay.ts +22 -12
- package/src/runs/background/control-channel.ts +14 -68
- package/src/runs/background/fleet-view.ts +68 -19
- package/src/runs/background/index-segment.ts +59 -0
- package/src/runs/background/inspect-rpc.ts +443 -0
- package/src/runs/background/notify.ts +31 -5
- package/src/runs/background/result-files.ts +158 -90
- package/src/runs/background/result-watcher.ts +124 -20
- package/src/runs/background/resume-guidance.ts +8 -5
- package/src/runs/background/retained-children.ts +13 -3
- package/src/runs/background/run-id-query.ts +7 -0
- package/src/runs/background/run-id-resolver.ts +11 -9
- package/src/runs/background/run-status.ts +27 -18
- package/src/runs/background/scheduled-runs.ts +24 -4
- package/src/runs/background/stale-run-reconciler.ts +6 -3
- package/src/runs/background/steering.ts +11 -1
- package/src/runs/background/subagent-runner.ts +260 -144
- package/src/runs/background/subagent-wait.ts +17 -13
- package/src/runs/background/terminal-run-index.ts +138 -0
- package/src/runs/background/wait-completions.ts +21 -4
- package/src/runs/background/wait-subscriptions.ts +81 -2
- package/src/runs/background/wait-tool.ts +1 -0
- package/src/runs/foreground/async-steering-action.ts +21 -14
- package/src/runs/foreground/execution.ts +8 -2
- package/src/runs/foreground/subagent-executor.ts +816 -1593
- package/src/runs/foreground/workflow-detach-reconcile.ts +262 -0
- package/src/runs/foreground/workflow-foreground-steering.ts +6 -5
- package/src/runs/shared/acceptance.ts +48 -5
- package/src/runs/shared/chain-outputs.ts +1 -3
- package/src/runs/shared/external-job-bridge.ts +444 -0
- package/src/runs/shared/external-job-runner.ts +286 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.ts +14 -0
- package/src/runs/shared/model-exclusions.ts +242 -0
- package/src/runs/shared/model-fallback.ts +153 -40
- package/src/runs/shared/orca-progress-tabs.ts +84 -22
- package/src/runs/shared/parallel-handoff.ts +46 -4
- package/src/runs/shared/parallel-utils.ts +4 -15
- package/src/runs/shared/permissions.ts +5 -1
- package/src/runs/shared/pi-args.ts +8 -1
- package/src/runs/shared/session-lease.ts +0 -6
- package/src/runs/shared/subagent-control.ts +51 -7
- package/src/runs/shared/subagent-prompt-runtime.ts +12 -6
- package/src/runs/shared/workflow-graph.ts +1 -23
- package/src/runs/shared/worktree.ts +14 -2
- package/src/shared/atomic-json.ts +22 -2
- package/src/shared/capacity-resilient-json.ts +102 -0
- package/src/shared/completion-owner.ts +14 -0
- package/src/shared/file-system-retry.ts +49 -1
- package/src/shared/fork-context.ts +59 -1
- package/src/shared/model-info.ts +20 -0
- package/src/shared/prompt-resources.ts +0 -40
- package/src/shared/settings.ts +5 -29
- package/src/shared/types.ts +110 -26
- package/src/shared/utils.ts +8 -0
- package/src/shared/watch-strategy.ts +10 -0
- package/src/slash/slash-bridge.ts +2 -1
- package/src/slash/slash-commands.ts +47 -7
- package/src/slash/slash-live-state.ts +3 -3
- package/src/tui/fleet-status.ts +86 -1
- package/src/tui/fleet.ts +117 -16
- package/src/tui/render.ts +73 -3
- package/src/watchdog/change-signature.ts +1 -1
- package/src/watchdog/lsp-diagnostics.ts +1 -0
- package/src/workflows/chat-progress.ts +2 -2
- package/src/workflows/scripted-workflow.ts +320 -79
- package/src/workflows/workflow-receipt.ts +140 -0
- package/src/runs/foreground/chain-clarify.ts +0 -1354
- package/src/runs/foreground/chain-execution.ts +0 -1581
package/src/api/preflight.ts
CHANGED
|
@@ -2,11 +2,11 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import * as fs from "node:fs";
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { discoverAgents, discoverAgentsAll, resolveAgentName, type AgentConfig, type AgentScope, type AgentSource } from "../agents/agents.ts";
|
|
5
|
+
import { discoverAgents, discoverAgentsAll, findBlockingAgentDiagnostic, resolveAgentName, type AgentConfig, type AgentScope, type AgentSource } from "../agents/agents.ts";
|
|
6
6
|
import { resolveExecutionAgentScope } from "../agents/agent-scope.ts";
|
|
7
7
|
import { buildSkillInjection, normalizeSkillInput, resolveSkillsWithFallback } from "../agents/skills.ts";
|
|
8
8
|
import { buildAgentMemoryInjection } from "../agents/agent-memory.ts";
|
|
9
|
-
import { buildModelCandidates, resolveEffectiveSubagentModel, type AvailableModelInfo, type ParentModel } from "../runs/shared/model-fallback.ts";
|
|
9
|
+
import { buildModelCandidates, inheritsParentModel, resolveEffectiveSubagentModel, type AvailableModelInfo, type ParentModel } from "../runs/shared/model-fallback.ts";
|
|
10
10
|
import { applyThinkingSuffix, resolvePiLaunchToolPlan, type PiLaunchToolPlan } from "../runs/shared/pi-args.ts";
|
|
11
11
|
import { injectOutputPathSystemPrompt, normalizeSingleOutputOverride, resolveSingleOutputPath } from "../runs/shared/single-output.ts";
|
|
12
12
|
import { getArtifactPaths, getArtifactsDir } from "../shared/artifacts.ts";
|
|
@@ -17,6 +17,8 @@ import { appendTurnBudgetSystemPrompt } from "../runs/shared/turn-budget.ts";
|
|
|
17
17
|
import type { ResolvedTurnBudget } from "../shared/types.ts";
|
|
18
18
|
import type { ResolvedMcpDirectToolSelection } from "../runs/shared/mcp-direct-tool-allowlist.ts";
|
|
19
19
|
import { resolveStepBehavior } from "../shared/settings.ts";
|
|
20
|
+
import { canPreferForkFromSnapshot, resolveSubagentLaunchContext } from "../shared/fork-context.ts";
|
|
21
|
+
import { loadConfig } from "../extension/config.ts";
|
|
20
22
|
import { agentDefinitionDigest, AGENT_DEFINITION_PROJECTION_VERSION, launchBindingDigest } from "../shared/launch-contract.ts";
|
|
21
23
|
import { DIRS, TEMP_ROOT_DIR } from "../shared/types.ts";
|
|
22
24
|
import { processTerminalCandidatePath, processTerminalPath } from "../runs/background/process-terminal.ts";
|
|
@@ -60,6 +62,8 @@ export interface SubagentLaunchContractInput {
|
|
|
60
62
|
artifacts?: boolean;
|
|
61
63
|
artifactDir?: ArtifactDirPreference;
|
|
62
64
|
parentSessionFile?: string | null;
|
|
65
|
+
/** Current parent leaf required before an implicit `defaultContext: fork` stays `fork`. */
|
|
66
|
+
parentLeafId?: string | null;
|
|
63
67
|
sessionRoot?: string;
|
|
64
68
|
sessionDir?: string;
|
|
65
69
|
runId?: string;
|
|
@@ -194,6 +198,18 @@ function normalizeAvailableModels(models: SubagentLaunchContractInput["available
|
|
|
194
198
|
return (models ?? []).map((model) => ({ ...model, fullId: model.fullId ?? `${model.provider}/${model.id}` }));
|
|
195
199
|
}
|
|
196
200
|
|
|
201
|
+
function resolveLaunchContractContext(input: SubagentLaunchContractInput, agent: AgentConfig): "fresh" | "fork" {
|
|
202
|
+
return resolveSubagentLaunchContext({
|
|
203
|
+
explicitContext: input.context,
|
|
204
|
+
agentDefaultContext: agent.defaultContext,
|
|
205
|
+
defaultSubagentContext: loadConfig().defaultSubagentContext,
|
|
206
|
+
canUseImplicitFork: canPreferForkFromSnapshot({
|
|
207
|
+
parentSessionFile: input.parentSessionFile,
|
|
208
|
+
leafId: input.parentLeafId,
|
|
209
|
+
}),
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
197
213
|
function candidateList(inputAgent: string, selected: AgentConfig | undefined, cwd: string): SubagentLaunchContractAgentCandidate[] {
|
|
198
214
|
const all = discoverAgentsAll(cwd);
|
|
199
215
|
return [...all.builtin, ...all.package, ...all.user, ...all.project]
|
|
@@ -226,12 +242,17 @@ export async function resolveSubagentLaunchContract(input: SubagentLaunchContrac
|
|
|
226
242
|
if (input.artifactDir !== undefined && input.artifactDir !== "project" && input.artifactDir !== "session" && input.artifactDir !== "temp") {
|
|
227
243
|
return { ok: false, code: "invalid_artifact_dir", message: `Unsupported artifactDir '${String(input.artifactDir)}'; expected 'project', 'session', or 'temp'.`, diagnostics };
|
|
228
244
|
}
|
|
229
|
-
if (input.context === "fork") {
|
|
230
|
-
diagnostics.push({ code: "host_required", severity: "host-required", message: "Exact fork session branching and fork-thinking downgrade checks require Pi host session and model-registry snapshots." });
|
|
231
|
-
}
|
|
232
245
|
const scope = resolveExecutionAgentScope(input.agentScope);
|
|
233
246
|
const discovered = discoverAgents(effectiveCwd, scope);
|
|
234
247
|
const resolvedAgent = resolveAgentName(input.agent, discovered.agents);
|
|
248
|
+
const ambiguousCandidates = resolvedAgent.error
|
|
249
|
+
? discovered.agents.filter((agent) => resolveAgentName(input.agent, [agent]).agent)
|
|
250
|
+
: resolvedAgent.agent;
|
|
251
|
+
const invalidAgent = findBlockingAgentDiagnostic(input.agent, ambiguousCandidates, discovered.agentDiagnostics);
|
|
252
|
+
if (invalidAgent) {
|
|
253
|
+
const message = `Agent '${input.agent}' has invalid configuration: ${invalidAgent.error}`;
|
|
254
|
+
return { ok: false, code: "missing_agent", message, diagnostics: [{ code: "missing_agent", severity: "error", message }] };
|
|
255
|
+
}
|
|
235
256
|
if (resolvedAgent.error) {
|
|
236
257
|
return { ok: false, code: "ambiguous_agent", message: resolvedAgent.error, diagnostics };
|
|
237
258
|
}
|
|
@@ -239,6 +260,10 @@ export async function resolveSubagentLaunchContract(input: SubagentLaunchContrac
|
|
|
239
260
|
return { ok: false, code: "missing_agent", message: `Unknown agent: ${input.agent}`, diagnostics };
|
|
240
261
|
}
|
|
241
262
|
const agent = resolvedAgent.agent;
|
|
263
|
+
const context = resolveLaunchContractContext(input, agent);
|
|
264
|
+
if (context === "fork") {
|
|
265
|
+
diagnostics.push({ code: "host_required", severity: "host-required", message: "Exact fork session branching and fork-thinking downgrade checks require Pi host session and model-registry snapshots." });
|
|
266
|
+
}
|
|
242
267
|
const effectiveCapabilityCeiling = intersectSubagentCapabilityCeilings(input.capabilityCeiling, input.inheritedCapabilityCeiling);
|
|
243
268
|
const restrictionMessage = capabilityCeilingAgentRestrictionMessage(agent.name, effectiveCapabilityCeiling);
|
|
244
269
|
if (restrictionMessage) return { ok: false, code: "restricted_agent", message: restrictionMessage, diagnostics };
|
|
@@ -264,7 +289,7 @@ export async function resolveSubagentLaunchContract(input: SubagentLaunchContrac
|
|
|
264
289
|
}
|
|
265
290
|
if (resolvedSkills.missing.length > 0) diagnostics.push({ code: "missing_skill", severity: "error", message: `Missing skills: ${resolvedSkills.missing.join(", ")}` });
|
|
266
291
|
|
|
267
|
-
const externalRunner = agent.runner?.type === "external-cli";
|
|
292
|
+
const externalRunner = agent.runner?.type === "external-cli" || agent.runner?.type === "external-job";
|
|
268
293
|
const availableModels = normalizeAvailableModels(input.availableModels);
|
|
269
294
|
const preferredProvider = input.preferredProvider ?? input.parentModel?.provider;
|
|
270
295
|
const primaryModel = externalRunner
|
|
@@ -274,7 +299,10 @@ export async function resolveSubagentLaunchContract(input: SubagentLaunchContrac
|
|
|
274
299
|
const model = externalRunner ? undefined : applyThinkingSuffix(primaryModel, effectiveThinkingConfig, input.thinking !== undefined);
|
|
275
300
|
const modelCandidates = externalRunner
|
|
276
301
|
? []
|
|
277
|
-
: buildModelCandidates(primaryModel, agent.fallbackModels, availableModels, preferredProvider, {
|
|
302
|
+
: buildModelCandidates(primaryModel, agent.fallbackModels, availableModels, preferredProvider, {
|
|
303
|
+
scope: discovered.modelScope,
|
|
304
|
+
primaryModelFromParent: inheritsParentModel(input.model, agent.model, input.parentModel),
|
|
305
|
+
})
|
|
278
306
|
.map((candidate) => applyThinkingSuffix(candidate, effectiveThinkingConfig, input.thinking !== undefined) ?? candidate);
|
|
279
307
|
let toolPlan: PiLaunchToolPlan;
|
|
280
308
|
try {
|
|
@@ -339,7 +367,7 @@ export async function resolveSubagentLaunchContract(input: SubagentLaunchContrac
|
|
|
339
367
|
definitionDigest,
|
|
340
368
|
shadowedCandidates,
|
|
341
369
|
},
|
|
342
|
-
context
|
|
370
|
+
context,
|
|
343
371
|
...(model ? { model } : {}),
|
|
344
372
|
modelCandidates,
|
|
345
373
|
...(resolveEffectiveThinking(model, effectiveThinkingConfig) ? { thinking: resolveEffectiveThinking(model, effectiveThinkingConfig) } : {}),
|
|
@@ -405,7 +433,7 @@ export async function resolveSubagentLaunchContract(input: SubagentLaunchContrac
|
|
|
405
433
|
extensions: toolPlan.extensionArgs,
|
|
406
434
|
mcpDirectTools: toolPlan.effectiveMcpTools,
|
|
407
435
|
...(outputPath ? { outputPath } : {}),
|
|
408
|
-
outputMode:
|
|
436
|
+
outputMode: behavior.outputMode,
|
|
409
437
|
...(input.outputSchema ? { structuredOutputSchema: input.outputSchema } : {}),
|
|
410
438
|
}),
|
|
411
439
|
};
|
package/src/api/shared-types.ts
CHANGED
package/src/extension/config.ts
CHANGED
|
@@ -94,6 +94,9 @@ function validateMainWindowRendererConfig(value: unknown): void {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
function validateConfig(config: Record<string, unknown>): void {
|
|
97
|
+
if (config.defaultSubagentContext !== undefined && config.defaultSubagentContext !== "fresh" && config.defaultSubagentContext !== "fork") {
|
|
98
|
+
throw new Error('config.defaultSubagentContext must be "fresh" or "fork"');
|
|
99
|
+
}
|
|
97
100
|
if (config.foregroundDetachShortcut !== undefined
|
|
98
101
|
&& (typeof config.foregroundDetachShortcut !== "string" || !isValidKeyId(config.foregroundDetachShortcut))) {
|
|
99
102
|
throw new Error("config.foregroundDetachShortcut must be a valid keybinding string such as \"ctrl+b\"");
|
|
@@ -101,15 +104,15 @@ function validateConfig(config: Record<string, unknown>): void {
|
|
|
101
104
|
if (config.artifactDir !== undefined && !ARTIFACT_DIR_PREFERENCES.has(config.artifactDir as ArtifactDirPreference)) {
|
|
102
105
|
throw new Error(`config.artifactDir must be "project", "session", or "temp"`);
|
|
103
106
|
}
|
|
104
|
-
if (config.legacyChainControls !== undefined && typeof config.legacyChainControls !== "boolean") {
|
|
105
|
-
throw new Error("config.legacyChainControls must be a boolean");
|
|
106
|
-
}
|
|
107
107
|
if (config.maxActiveAsyncRunsPerSession !== undefined
|
|
108
108
|
&& (typeof config.maxActiveAsyncRunsPerSession !== "number"
|
|
109
109
|
|| !Number.isInteger(config.maxActiveAsyncRunsPerSession)
|
|
110
110
|
|| config.maxActiveAsyncRunsPerSession < 0)) {
|
|
111
111
|
throw new Error("config.maxActiveAsyncRunsPerSession must be a non-negative integer");
|
|
112
112
|
}
|
|
113
|
+
if (config.resultScanLogging !== undefined && config.resultScanLogging !== "all" && config.resultScanLogging !== "activity" && config.resultScanLogging !== "off") {
|
|
114
|
+
throw new Error('config.resultScanLogging must be "all", "activity", or "off"');
|
|
115
|
+
}
|
|
113
116
|
validateMissionStoreConfig(config.missions);
|
|
114
117
|
validateAuthorityPolicy(config.authorityPolicy);
|
|
115
118
|
validatePermissionConfig(config.permissions);
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { AgentConfig } from "../agents/agents.ts";
|
|
2
|
+
import { isAgentAllowedByCapabilityCeiling, type ResolvedSubagentCapabilityCeiling } from "../runs/shared/capability-ceiling.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Marker used to detect an already-injected block so repeated injections
|
|
6
|
+
* (forked or resumed sessions replaying chained system prompts) stay idempotent.
|
|
7
|
+
*/
|
|
8
|
+
export const SUBAGENT_INJECTION_MARKER = "<available_subagents>";
|
|
9
|
+
|
|
10
|
+
/** One compact line per advertised agent inside the injected block. */
|
|
11
|
+
export interface InjectableAgentSummary {
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ResolveInjectableAgentsInput {
|
|
17
|
+
/** Merged discovered agents across scopes (builtin, package, user, project). */
|
|
18
|
+
agents: readonly AgentConfig[];
|
|
19
|
+
/** Names (canonical or alias) listed by the `subagents.injectAgents` setting. */
|
|
20
|
+
injectAgents?: readonly string[];
|
|
21
|
+
/** Current session capability ceiling; restricted agents are never advertised. */
|
|
22
|
+
capabilityCeiling?: ResolvedSubagentCapabilityCeiling | undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ResolveInjectableAgentsResult {
|
|
26
|
+
agents: InjectableAgentSummary[];
|
|
27
|
+
/** Setting entries that matched no discovered agent, trimmed, discovery order preserved. */
|
|
28
|
+
unknownNames: string[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function normalizeDescription(description: string): string {
|
|
32
|
+
return description.replace(/\s+/g, " ").trim();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function buildNameLookup(agents: readonly AgentConfig[]): Map<string, AgentConfig> {
|
|
36
|
+
const lookup = new Map<string, AgentConfig>();
|
|
37
|
+
for (const agent of agents) {
|
|
38
|
+
if (!lookup.has(agent.name)) lookup.set(agent.name, agent);
|
|
39
|
+
for (const alias of agent.aliases ?? []) {
|
|
40
|
+
if (!lookup.has(alias)) lookup.set(alias, agent);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return lookup;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Union of settings-listed agents (`subagents.injectAgents`) and agents whose
|
|
48
|
+
* frontmatter opts in with `injectToContext: true`. Settings names resolve
|
|
49
|
+
* against canonical names and aliases; unresolved entries are reported through
|
|
50
|
+
* `unknownNames` instead of failing discovery. Disabled agents and agents
|
|
51
|
+
* restricted by the session capability ceiling are never advertised.
|
|
52
|
+
*/
|
|
53
|
+
export function resolveInjectableAgents(input: ResolveInjectableAgentsInput): ResolveInjectableAgentsResult {
|
|
54
|
+
const { agents, injectAgents, capabilityCeiling } = input;
|
|
55
|
+
const lookup = buildNameLookup(agents);
|
|
56
|
+
const selected = new Map<string, InjectableAgentSummary>();
|
|
57
|
+
const unknownNames: string[] = [];
|
|
58
|
+
|
|
59
|
+
const advertise = (agent: AgentConfig): void => {
|
|
60
|
+
if (agent.disabled === true) return;
|
|
61
|
+
if (!isAgentAllowedByCapabilityCeiling(agent.name, capabilityCeiling)) return;
|
|
62
|
+
if (selected.has(agent.name)) return;
|
|
63
|
+
selected.set(agent.name, { name: agent.name, description: normalizeDescription(agent.description) });
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
for (const rawName of injectAgents ?? []) {
|
|
67
|
+
const name = rawName.trim();
|
|
68
|
+
if (!name) continue;
|
|
69
|
+
const resolved = lookup.get(name);
|
|
70
|
+
if (!resolved) {
|
|
71
|
+
if (!unknownNames.includes(name)) unknownNames.push(name);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
advertise(resolved);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
for (const agent of agents) {
|
|
78
|
+
if (agent.injectToContext === true) advertise(agent);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
agents: Array.from(selected.values()).sort((a, b) => a.name.localeCompare(b.name)),
|
|
83
|
+
unknownNames,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Append the session-snapshot block to this turn's system prompt.
|
|
89
|
+
* Returns `undefined` when nothing should change: empty block, or a prompt
|
|
90
|
+
* that already carries the marker (forked/resumed chains replaying history).
|
|
91
|
+
*/
|
|
92
|
+
export function applyInjectionBlock(input: { systemPrompt: string; block: string }): string | undefined {
|
|
93
|
+
const { systemPrompt, block } = input;
|
|
94
|
+
if (!block) return undefined;
|
|
95
|
+
if (systemPrompt.includes(SUBAGENT_INJECTION_MARKER)) return undefined;
|
|
96
|
+
return `${systemPrompt}\n\n${block}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Render the deterministic `<available_subagents>` block appended to the parent
|
|
101
|
+
* system prompt. Pure function of its input: stable sort order and a fixed
|
|
102
|
+
* template guarantee byte-identical output across turns so provider prompt
|
|
103
|
+
* caching stays effective. Descriptions are collapsed to a single line so a
|
|
104
|
+
* multi-line frontmatter description cannot break the compact format. Returns
|
|
105
|
+
* an empty string when nothing is advertised.
|
|
106
|
+
*/
|
|
107
|
+
export function renderInjectionBlock(agents: readonly InjectableAgentSummary[]): string {
|
|
108
|
+
if (agents.length === 0) return "";
|
|
109
|
+
const lines = [
|
|
110
|
+
SUBAGENT_INJECTION_MARKER,
|
|
111
|
+
"The following pre-declared subagents are available.",
|
|
112
|
+
"Launch them with the subagent tool when a task matches their description.",
|
|
113
|
+
"",
|
|
114
|
+
...agents.map((agent) => `- ${agent.name}: ${normalizeDescription(agent.description)}`),
|
|
115
|
+
"</available_subagents>",
|
|
116
|
+
];
|
|
117
|
+
return lines.join("\n");
|
|
118
|
+
}
|
package/src/extension/doctor.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as path from "node:path";
|
|
3
3
|
import { discoverAgentsAll, type AgentSource } from "../agents/agents.ts";
|
|
4
|
+
import { mergeAgentsForScope } from "../agents/agent-selection.ts";
|
|
5
|
+
import { resolveInjectableAgents } from "./context-injection.ts";
|
|
4
6
|
import { isAsyncAvailable } from "../runs/background/async-execution.ts";
|
|
5
7
|
import { formatSpawnBudgetSummary, getSpawnBudgetSnapshot } from "../runs/shared/spawn-budget.ts";
|
|
6
8
|
import { getActiveAsyncCapacitySnapshot, resolveMaxActiveAsyncRunsPerSession } from "../runs/background/active-async-capacity.ts";
|
|
@@ -134,21 +136,28 @@ function formatSessionLines(input: DoctorReportInput): string[] {
|
|
|
134
136
|
|
|
135
137
|
function formatDiscovery(input: DoctorReportInput, deps: DoctorDeps): string[] {
|
|
136
138
|
return [
|
|
137
|
-
lineFromCheck("agents
|
|
139
|
+
lineFromCheck("agents", () => {
|
|
138
140
|
const discovered = deps.discoverAgentsAll(input.cwd);
|
|
139
141
|
const agentCounts = {
|
|
140
142
|
builtin: discovered.builtin.length,
|
|
141
143
|
package: discovered.package?.length ?? 0,
|
|
142
144
|
user: discovered.user.length,
|
|
143
145
|
project: discovered.project.length,
|
|
146
|
+
runtime: 0,
|
|
144
147
|
};
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
148
|
+
const diagnostics = discovered.agentDiagnostics ?? [];
|
|
149
|
+
const injectable = resolveInjectableAgents({
|
|
150
|
+
agents: mergeAgentsForScope("both", discovered.user, discovered.project, discovered.builtin, discovered.package),
|
|
151
|
+
injectAgents: discovered.injectAgents,
|
|
152
|
+
});
|
|
153
|
+
const snapshot = input.state.contextInjectionBlock;
|
|
149
154
|
return [
|
|
150
155
|
`- agents: total ${agentCounts.builtin + agentCounts.package + agentCounts.user + agentCounts.project} (${formatSourceCounts(agentCounts)})`,
|
|
151
|
-
|
|
156
|
+
injectable.agents.length
|
|
157
|
+
? `- context injection: ${injectable.agents.length} advertised (${injectable.agents.map((agent) => agent.name).join(", ")}); session snapshot ${snapshot ? "present" : "absent"}`
|
|
158
|
+
: "- context injection: none",
|
|
159
|
+
...(injectable.unknownNames.length ? [`- context injection unknown names (ignored): ${injectable.unknownNames.join(", ")}`] : []),
|
|
160
|
+
...diagnostics.map((diagnostic) => `- invalid agent ${diagnostic.name ?? diagnostic.filePath} (${diagnostic.source}): ${diagnostic.error}`),
|
|
152
161
|
].join("\n");
|
|
153
162
|
}),
|
|
154
163
|
lineFromCheck("skills", () => {
|
|
@@ -171,13 +171,13 @@ export default function registerFanoutChildSubagentExtension(pi: ExtensionAPI):
|
|
|
171
171
|
allowMutatingManagementActions: false,
|
|
172
172
|
});
|
|
173
173
|
|
|
174
|
-
const params = createSubagentParamsSchema(
|
|
174
|
+
const params = createSubagentParamsSchema();
|
|
175
175
|
const tool: ToolDefinition<typeof params, Details> = {
|
|
176
176
|
name: "subagent",
|
|
177
177
|
label: "Subagent",
|
|
178
178
|
description: [
|
|
179
179
|
"Delegate to subagents from child-safe fanout mode.",
|
|
180
|
-
|
|
180
|
+
"Allowed management/control actions: list, get, status, interrupt, resume, steer, doctor.",
|
|
181
181
|
"Mutating management actions (create, update, delete, eject, disable, enable, reset, grant-spawn-budget) are blocked in this mode.",
|
|
182
182
|
].join("\n"),
|
|
183
183
|
parameters: params,
|