@xzzpig/pi-subagents 0.7.0 → 0.9.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 +456 -4
- package/README.md +3 -3
- package/agents/claude-code-writer.md +15 -0
- package/agents/claude-code.md +15 -0
- package/agents/codex-exec-writer.md +15 -0
- package/agents/codex-exec.md +15 -0
- package/agents/cursor-agent-writer.md +14 -0
- package/agents/cursor-agent.md +14 -0
- package/agents/reviewer.md +13 -3
- package/agents/scout.md +1 -1
- package/docs/agents.md +154 -42
- package/docs/configuration.md +85 -26
- package/docs/extension-api.md +81 -16
- package/docs/missions.md +2 -0
- package/docs/models.md +75 -11
- package/docs/observability.md +34 -21
- package/docs/tool-reference.md +142 -18
- package/docs/watchdog.md +92 -114
- package/docs/workflows.md +148 -4
- package/index.ts +10 -1
- package/install.mjs +1 -1
- package/package.json +7 -6
- package/prompts/council.md +19 -7
- package/prompts/parallel-review.md +5 -1
- package/prompts/review-loop.md +11 -7
- package/skills/council-mode/SKILL.md +44 -215
- package/skills/council-mode/references/pass-contracts.md +150 -0
- package/skills/pi-subagents/SKILL.md +90 -32
- package/skills/pi-subagents/references/constraints-and-recipes.md +34 -223
- package/skills/pi-subagents/references/execution-controls.md +104 -19
- package/skills/pi-subagents/references/management-authoring-rpc.md +5 -5
- package/skills/pi-subagents/references/multi-lane-orchestration.md +16 -4
- package/skills/pi-subagents/references/prompting-and-roles.md +71 -36
- package/skills/pi-subagents/references/review-and-validation.md +73 -0
- package/src/agents/agent-management.ts +471 -114
- package/src/agents/agent-refinements.ts +4 -4
- package/src/agents/agent-serializer.ts +16 -4
- package/src/agents/agents.ts +1076 -351
- package/src/agents/builtin-names.ts +6 -0
- package/src/agents/runtime-agent-events.ts +70 -0
- package/src/agents/runtime-agent-registry.ts +31 -20
- package/src/api/agents.ts +10 -5
- package/src/api/background-work.ts +12 -3
- package/src/api/capability-ceiling.ts +0 -1
- package/src/api/{pi-args.ts → child-tool-plan.ts} +1 -1
- package/src/api/delegation.ts +0 -7
- package/src/api/external-job-provider.ts +10 -1
- package/src/api/external-runs.ts +67 -4
- package/src/api/preflight.ts +97 -34
- package/src/api/project-panes.ts +2 -0
- package/src/api/shared-types.ts +6 -0
- package/src/extension/config.ts +90 -0
- package/src/extension/doctor.ts +15 -13
- package/src/extension/fanout-child.ts +17 -16
- package/src/extension/index.ts +139 -41
- package/src/extension/public-execution.ts +113 -22
- package/src/extension/rpc.ts +182 -13
- package/src/extension/schemas.ts +63 -21
- package/src/extension/tool-description.ts +48 -23
- package/src/extension/tool-result.ts +19 -0
- package/src/inspectors/herdr/actions.ts +2 -1
- package/src/inspectors/herdr/client.ts +3 -3
- package/src/inspectors/herdr/focus.ts +55 -0
- package/src/inspectors/herdr/inspector-runner.ts +21 -23
- package/src/inspectors/herdr/project-panes.ts +228 -44
- package/src/inspectors/herdr/session-roots-codec.ts +42 -0
- package/src/integrations/herdr-status.ts +75 -5
- package/src/intercom/native-supervisor-channel.ts +138 -60
- package/src/intercom/result-intercom.ts +2 -0
- package/src/intercom/supervisor-ui.ts +243 -0
- package/src/profiles/profiles.ts +5 -6
- package/src/runs/background/active-async-capacity.ts +103 -18
- package/src/runs/background/async-execution.ts +492 -125
- package/src/runs/background/async-job-tracker.ts +127 -28
- package/src/runs/background/async-resume.ts +67 -29
- package/src/runs/background/async-retention.ts +21 -4
- package/src/runs/background/async-status-snapshot.ts +23 -261
- package/src/runs/background/async-status.ts +199 -14
- package/src/runs/background/auto-drain.ts +1 -1
- package/src/runs/background/chain-append.ts +8 -3
- package/src/runs/background/chain-root-attachment.ts +79 -8
- package/src/runs/background/control-channel.ts +101 -214
- package/src/runs/background/fleet-view.ts +38 -22
- package/src/runs/background/inspect-rpc.ts +8 -8
- package/src/runs/background/notify.ts +295 -8
- package/src/runs/background/process-terminal.ts +16 -0
- package/src/runs/background/result-delivery-ownership.ts +45 -0
- package/src/runs/background/result-files.ts +28 -14
- package/src/runs/background/result-watcher.ts +43 -19
- package/src/runs/background/resume-guidance.ts +2 -2
- package/src/runs/background/retained-children.ts +1 -1
- package/src/runs/background/run-child-session.ts +613 -0
- package/src/runs/background/run-status.ts +99 -18
- package/src/runs/background/runner-aliases.ts +125 -0
- package/src/runs/background/runner-child-sessions.ts +31 -0
- package/src/runs/background/scheduled-runs.ts +174 -18
- package/src/runs/background/stale-run-reconciler.ts +13 -4
- package/src/runs/background/steering.ts +8 -15
- package/src/runs/background/subagent-runner.ts +959 -1159
- package/src/runs/background/subagent-wait.ts +86 -31
- package/src/runs/background/terminal-run-index.ts +1 -1
- package/src/runs/background/wait-completions.ts +45 -2
- package/src/runs/background/wait-config.ts +23 -9
- package/src/runs/background/wait-tool.ts +27 -19
- package/src/runs/foreground/async-steering-action.ts +3 -19
- package/src/runs/foreground/async-stop-action.ts +23 -2
- package/src/runs/foreground/execution.ts +585 -481
- package/src/runs/foreground/foreground-control.ts +13 -0
- package/src/runs/foreground/foreground-history.ts +26 -3
- package/src/runs/foreground/subagent-executor.ts +1549 -410
- package/src/runs/foreground/workflow-detach-reconcile.ts +141 -104
- package/src/runs/foreground/workflow-foreground-steering.ts +24 -98
- package/src/runs/shared/abort-recovery.ts +119 -0
- package/src/runs/shared/acceptance.ts +147 -39
- package/src/runs/shared/agent-contract.ts +1 -1
- package/src/runs/shared/async-status-projection.ts +565 -0
- package/src/runs/shared/background-process-options.ts +9 -0
- package/src/runs/shared/capability-ceiling.ts +2 -2
- package/src/runs/shared/child-hooks.ts +25 -0
- package/src/runs/shared/child-identity.ts +62 -0
- package/src/runs/shared/child-launch-plan.ts +151 -0
- package/src/runs/shared/child-launch.ts +314 -0
- package/src/runs/shared/child-lifecycle.ts +25 -0
- package/src/runs/shared/child-runtime-config.ts +126 -0
- package/src/runs/shared/child-session.ts +342 -0
- package/src/runs/shared/child-tool-plan.ts +540 -0
- package/src/runs/shared/claude-code-adapter.ts +133 -0
- package/src/runs/shared/codex-exec-adapter.ts +129 -0
- package/src/runs/shared/completion-evidence.ts +89 -0
- package/src/runs/shared/completion-guard.ts +57 -6
- package/src/runs/shared/cursor-agent-adapter.ts +114 -0
- package/src/runs/shared/dynamic-fanout.ts +4 -4
- package/src/runs/shared/extension-bindings.ts +78 -0
- package/src/runs/shared/external-cli-contract.ts +167 -0
- package/src/runs/shared/external-cli-preflight.ts +138 -0
- package/src/runs/shared/external-cli-runner.ts +349 -54
- package/src/runs/shared/external-job-bridge.ts +53 -37
- package/src/runs/shared/external-job-runner.ts +126 -23
- package/src/runs/shared/fast-mode-extension.ts +10 -0
- package/src/runs/shared/host-step-status.ts +231 -0
- package/src/runs/shared/lane-metadata.ts +126 -0
- package/src/runs/shared/launch-cwd.ts +16 -0
- package/src/runs/shared/long-running-guard.ts +2 -1
- package/src/runs/shared/mcp-config-sources.ts +422 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.ts +222 -158
- package/src/runs/shared/mcp-direct-tool-grant.ts +194 -0
- package/src/runs/shared/model-exclusions.ts +141 -10
- package/src/runs/shared/model-fallback.ts +187 -33
- package/src/runs/shared/model-scope.ts +106 -39
- package/src/runs/shared/mutation-evidence.ts +199 -0
- package/src/runs/shared/nested-events.ts +38 -48
- package/src/runs/shared/nested-path.ts +0 -14
- package/src/runs/shared/nested-render.ts +9 -5
- package/src/runs/shared/orca-progress-tabs.ts +83 -16
- package/src/runs/shared/parallel-handoff.ts +423 -7
- package/src/runs/shared/parallel-utils.ts +28 -5
- package/src/runs/shared/permissions.ts +1 -14
- package/src/runs/shared/pi-spawn.ts +69 -35
- package/src/runs/shared/process-signal.ts +16 -0
- package/src/runs/shared/run-fanout-budget.ts +0 -13
- package/src/runs/shared/run-history.ts +21 -1
- package/src/runs/shared/runtime-acknowledged-extensions.ts +0 -27
- package/src/runs/shared/single-output.ts +89 -22
- package/src/runs/shared/structured-output.ts +61 -7
- package/src/runs/shared/subagent-control.ts +6 -2
- package/src/runs/shared/subagent-prompt-runtime.ts +216 -360
- package/src/runs/shared/task-intent.ts +21 -7
- package/src/runs/shared/tool-availability.ts +18 -64
- package/src/runs/shared/tool-budget.ts +0 -14
- package/src/runs/shared/tool-timeout.ts +1 -1
- package/src/runs/shared/workflow-graph.ts +16 -0
- package/src/runs/shared/worktree-cleanup-plan.ts +866 -0
- package/src/runs/shared/worktree.ts +571 -62
- package/src/shared/atomic-json.ts +3 -1
- package/src/shared/child-session-name.ts +46 -0
- package/src/shared/extension-context.ts +24 -0
- package/src/shared/fork-context.ts +21 -12
- package/src/shared/fork-session-cwd.ts +27 -0
- package/src/shared/formatters.ts +18 -3
- package/src/shared/jsonl-writer.ts +11 -0
- package/src/shared/launch-contract.ts +20 -6
- package/src/shared/pruned-fork.ts +450 -0
- package/src/shared/session-file-trust.ts +19 -0
- package/src/shared/session-tokens.ts +14 -3
- package/src/shared/settings.ts +21 -102
- package/src/shared/shortcuts.ts +17 -0
- package/src/shared/thinking-ceiling.ts +46 -0
- package/src/shared/types.ts +644 -75
- package/src/shared/utils.ts +60 -93
- package/src/shared/workflow-child-permit.ts +207 -0
- package/src/slash/delegation-adapters.ts +1 -9
- package/src/slash/delegation-request.ts +0 -4
- package/src/slash/prompt-template-bridge.ts +37 -1
- package/src/slash/slash-bridge.ts +1 -2
- package/src/slash/slash-commands.ts +383 -116
- package/src/slash/slash-live-state.ts +22 -11
- package/src/slash/subagents-admin.ts +29 -12
- package/src/tui/fleet-native-transcript.ts +4 -0
- package/src/tui/fleet-status.ts +278 -90
- package/src/tui/fleet-transcript.ts +11 -5
- package/src/tui/fleet.ts +54 -28
- package/src/tui/render-helpers.ts +31 -0
- package/src/tui/render.ts +1433 -166
- package/src/watchdog/change-signature.ts +40 -1
- package/src/watchdog/child-status.ts +54 -34
- package/src/watchdog/diff-tool.ts +77 -0
- package/src/watchdog/emission-guard.ts +5 -3
- package/src/watchdog/guidance.ts +20 -0
- package/src/watchdog/permission-arbiter.ts +59 -52
- package/src/watchdog/register-child.ts +28 -25
- package/src/watchdog/register-main.ts +10 -9
- package/src/watchdog/render.ts +4 -5
- package/src/watchdog/review.ts +15 -4
- package/src/watchdog/rules.ts +70 -0
- package/src/watchdog/runtime.ts +75 -92
- package/src/watchdog/scope.ts +0 -11
- package/src/watchdog/settings.ts +48 -104
- package/src/watchdog/turn-delta.ts +1 -1
- package/src/watchdog/types.ts +18 -32
- package/src/watchdog/warning-format.ts +0 -1
- package/src/workflows/chat-progress.ts +7 -3
- package/src/workflows/host-command.ts +235 -0
- package/src/workflows/scripted-workflow.ts +1142 -69
- package/src/workflows/workflow-checklist.ts +439 -0
- package/src/workflows/workflow-child-summary.ts +121 -0
- package/src/workflows/workflow-preflight.ts +297 -0
- package/src/workflows/workflow-receipt.ts +232 -6
- package/src/workflows/workflow-resources.ts +150 -0
- package/src/workflows/workflow-settlement.ts +246 -0
- package/src/runs/shared/child-protocol.ts +0 -401
- package/src/runs/shared/pi-args.ts +0 -858
- package/src/runs/shared/subagent-startup-retry.ts +0 -116
- package/src/runs/shared/turn-budget.ts +0 -98
- package/src/shared/post-exit-stdio-guard.ts +0 -85
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
type AgentDiscoveryDiagnostic,
|
|
8
8
|
type AgentScope,
|
|
9
9
|
type AgentSource,
|
|
10
|
-
BUILTIN_AGENT_NAMES,
|
|
11
10
|
defaultInheritProjectContext,
|
|
12
11
|
defaultInheritSkills,
|
|
13
12
|
defaultSystemPromptMode,
|
|
@@ -29,16 +28,19 @@ import {
|
|
|
29
28
|
buildProactiveSkillSubagentRecommendationLines,
|
|
30
29
|
} from "./proactive-skills.ts";
|
|
31
30
|
import { parseFrontmatter, parseFrontmatterList } from "./frontmatter.ts";
|
|
32
|
-
import { resolvePiLaunchToolPlan } from "../runs/shared/
|
|
33
|
-
import { toModelInfo } from "../shared/model-info.ts";
|
|
31
|
+
import { resolvePiLaunchToolPlan } from "../runs/shared/child-tool-plan.ts";
|
|
32
|
+
import { resolveEffectiveThinking, toModelInfo } from "../shared/model-info.ts";
|
|
34
33
|
import { resolveSubagentModelOverride, type ParentModel } from "../runs/shared/model-fallback.ts";
|
|
35
34
|
import { validateToolBudgetConfig } from "../runs/shared/tool-budget.ts";
|
|
36
|
-
import { resolveTurnBudgetConfig } from "../runs/shared/turn-budget.ts";
|
|
37
35
|
import { validateAcceptanceInput } from "../runs/shared/acceptance.ts";
|
|
38
|
-
import
|
|
36
|
+
import { CODE_OWNED_EXTERNAL_CLI_ADAPTER_LABEL, isCodeOwnedExternalCliAdapterId, resolveExternalCliRunnerStatus, validateCodeOwnedProfileRunner } from "../runs/shared/external-cli-contract.ts";
|
|
37
|
+
import { resolveExternalCliBinaryAvailability, type ExternalCliBinaryAvailability } from "../runs/shared/external-cli-preflight.ts";
|
|
38
|
+
import type { AcceptanceInput, AgentCapabilitiesSnapshot, AgentCapabilityRow, Details, ExtensionConfig, ToolBudgetConfig } from "../shared/types.ts";
|
|
39
39
|
import { getProjectConfigDir } from "../shared/utils.ts";
|
|
40
|
+
import { previewDisplayText } from "../shared/display-text.ts";
|
|
40
41
|
import { capabilityCeilingAgentRestrictionSources, isAgentAllowedByCapabilityCeiling, resolveCurrentSubagentCapabilityCeiling } from "../runs/shared/capability-ceiling.ts";
|
|
41
|
-
import {
|
|
42
|
+
import { mergeRuntimeAgents, type RuntimeAgentOwner } from "./runtime-agent-registry.ts";
|
|
43
|
+
import { listExternalJobProviders } from "../api/external-job-provider.ts";
|
|
42
44
|
|
|
43
45
|
export const AGENT_MANAGEMENT_API_VERSION = 1 as const;
|
|
44
46
|
|
|
@@ -102,29 +104,44 @@ interface ManagementParams {
|
|
|
102
104
|
action?: string;
|
|
103
105
|
agent?: string;
|
|
104
106
|
agentScope?: unknown;
|
|
107
|
+
capabilities?: unknown;
|
|
105
108
|
config?: unknown;
|
|
106
109
|
}
|
|
107
110
|
|
|
108
|
-
function result(text: string, isError = false): AgentToolResult<Details> {
|
|
109
|
-
return { content: [{ type: "text", text }], isError, details: { mode: "management", results: [] } };
|
|
111
|
+
function result(text: string, isError = false, details?: Partial<Details>): AgentToolResult<Details> {
|
|
112
|
+
return { content: [{ type: "text", text }], isError, details: { mode: "management", results: [], ...details } };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function jsonDetails<T>(value: T): T {
|
|
116
|
+
return JSON.parse(JSON.stringify(value)) as T;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function presentDetails<T extends Record<string, unknown>>(value: T): T | undefined {
|
|
120
|
+
const cleaned = jsonDetails(value);
|
|
121
|
+
return Object.keys(cleaned).length > 0 ? cleaned : undefined;
|
|
110
122
|
}
|
|
111
123
|
|
|
112
124
|
function parseCsv(value: string): string[] {
|
|
113
125
|
return [...new Set(value.split(",").map((v) => v.trim()).filter(Boolean))];
|
|
114
126
|
}
|
|
115
127
|
|
|
116
|
-
|
|
128
|
+
type ConfigObjectResult =
|
|
129
|
+
| { status: "ok"; value: Record<string, unknown> }
|
|
130
|
+
| { status: "missing" }
|
|
131
|
+
| { status: "error"; message: string };
|
|
132
|
+
|
|
133
|
+
function configObject(config: unknown): ConfigObjectResult {
|
|
117
134
|
let val = config;
|
|
118
135
|
if (typeof val === "string") {
|
|
119
136
|
try {
|
|
120
137
|
val = JSON.parse(val);
|
|
121
138
|
} catch (error) {
|
|
122
139
|
const message = error instanceof Error ? error.message : String(error);
|
|
123
|
-
return { error: `config must be valid JSON: ${message}` };
|
|
140
|
+
return { status: "error", message: `config must be valid JSON: ${message}` };
|
|
124
141
|
}
|
|
125
142
|
}
|
|
126
|
-
if (!val || typeof val !== "object" || Array.isArray(val)) return {};
|
|
127
|
-
return { value: val as Record<string, unknown> };
|
|
143
|
+
if (!val || typeof val !== "object" || Array.isArray(val)) return { status: "missing" };
|
|
144
|
+
return { status: "ok", value: val as Record<string, unknown> };
|
|
128
145
|
}
|
|
129
146
|
|
|
130
147
|
function hasKey(obj: Record<string, unknown>, key: string): boolean {
|
|
@@ -168,18 +185,39 @@ function allAgents(d: { builtin: AgentConfig[]; package: AgentConfig[]; user: Ag
|
|
|
168
185
|
return [...d.builtin, ...d.package, ...d.user, ...d.project];
|
|
169
186
|
}
|
|
170
187
|
|
|
171
|
-
function
|
|
172
|
-
|
|
188
|
+
function effectiveAgentsForScope(
|
|
189
|
+
scope: AgentScope,
|
|
190
|
+
d: { builtin: AgentConfig[]; package: AgentConfig[]; user: AgentConfig[]; project: AgentConfig[] },
|
|
191
|
+
runtimeAgentOwner?: RuntimeAgentOwner,
|
|
192
|
+
): AgentConfig[] {
|
|
193
|
+
let agents = mergeAgentsForScope(scope, d.user, d.project, d.builtin, d.package);
|
|
194
|
+
if (runtimeAgentOwner) {
|
|
195
|
+
agents = mergeRuntimeAgents(runtimeAgentOwner, { agents }, allAgents(d)).agents;
|
|
196
|
+
}
|
|
197
|
+
return agents;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function availableAgentNamesFromDiscovery(
|
|
201
|
+
d: { builtin: AgentConfig[]; package: AgentConfig[]; user: AgentConfig[]; project: AgentConfig[] },
|
|
202
|
+
runtimeAgentOwner?: RuntimeAgentOwner,
|
|
203
|
+
): string[] {
|
|
204
|
+
const agents = runtimeAgentOwner ? effectiveAgentsForScope("both", d, runtimeAgentOwner) : allAgents(d);
|
|
205
|
+
return [...new Set(agents.map((agent) => agent.name))].sort((a, b) => a.localeCompare(b));
|
|
173
206
|
}
|
|
174
207
|
|
|
175
208
|
function availableAgentNames(cwd: string): string[] {
|
|
176
209
|
return availableAgentNamesFromDiscovery(discoverAgentsAll(cwd));
|
|
177
210
|
}
|
|
178
211
|
|
|
179
|
-
function findAgentsInDiscovery(
|
|
212
|
+
function findAgentsInDiscovery(
|
|
213
|
+
name: string,
|
|
214
|
+
d: { builtin: AgentConfig[]; package: AgentConfig[]; user: AgentConfig[]; project: AgentConfig[] },
|
|
215
|
+
scope: AgentScope = "both",
|
|
216
|
+
runtimeAgentOwner?: RuntimeAgentOwner,
|
|
217
|
+
): AgentConfig[] {
|
|
180
218
|
const raw = name.trim();
|
|
181
219
|
const sanitized = sanitizeName(raw);
|
|
182
|
-
const scoped =
|
|
220
|
+
const scoped = effectiveAgentsForScope(scope, d, runtimeAgentOwner);
|
|
183
221
|
let resolved = resolveAgentName(raw, scoped);
|
|
184
222
|
if (!resolved.agent && !resolved.error && sanitized !== raw) resolved = resolveAgentName(sanitized, scoped);
|
|
185
223
|
if (resolved.agent) return scoped.filter((agent) => agent.name === resolved.agent!.name).sort((a, b) => a.source.localeCompare(b.source));
|
|
@@ -232,7 +270,8 @@ function isMutableSource(source: AgentSource): source is ManagementScope {
|
|
|
232
270
|
function modelWarning(ctx: ManagementContext, model: string | undefined): string | undefined {
|
|
233
271
|
if (!model) return undefined;
|
|
234
272
|
const found = ctx.modelRegistry.getAvailable().some((m) => `${m.provider}/${m.id}` === model || m.id === model);
|
|
235
|
-
|
|
273
|
+
if (found) return undefined;
|
|
274
|
+
return `Warning: model '${model}' is not in the current model registry. Run subagent({ action: "models" }) to list valid provider/id selectors, then use the exact provider/id form (bare ids resolve only when unique).`;
|
|
236
275
|
}
|
|
237
276
|
|
|
238
277
|
function fallbackModelsWarning(ctx: ManagementContext, fallbackModels: string[] | undefined): string | undefined {
|
|
@@ -268,14 +307,29 @@ function withDeclaredExtensionPaths(config: AgentConfig, filePath: string): Agen
|
|
|
268
307
|
export function editableAgentConfig(agent: AgentConfig): AgentConfig {
|
|
269
308
|
const { extensions: _extensions, ...withoutExtensions } = agent;
|
|
270
309
|
const base = agent.override?.base;
|
|
310
|
+
const description = base?.description ?? agent.description;
|
|
311
|
+
const frontmatterFields = agent.source === "builtin" || agent.source === "runtime" ? undefined : readAgentFrontmatterFields(agent.filePath);
|
|
312
|
+
const hasDeclaredField = (...fields: string[]) => frontmatterFields === undefined || fields.some((field) => frontmatterFields.has(field));
|
|
313
|
+
const withoutSettingsDefaults = (config: AgentConfig): AgentConfig => {
|
|
314
|
+
if (!frontmatterFields) return config;
|
|
315
|
+
const next = { ...config };
|
|
316
|
+
if (!hasDeclaredField("model")) delete next.model;
|
|
317
|
+
if (!hasDeclaredField("thinking")) delete next.thinking;
|
|
318
|
+
return next;
|
|
319
|
+
};
|
|
271
320
|
const {
|
|
272
321
|
override: _override,
|
|
322
|
+
description: _description,
|
|
323
|
+
output: _output,
|
|
273
324
|
outputMode: _outputMode,
|
|
325
|
+
defaultReads: _defaultReads,
|
|
274
326
|
model: _model,
|
|
275
327
|
fallbackModels: _fallbackModels,
|
|
328
|
+
fast: _fast,
|
|
276
329
|
thinking: _thinking,
|
|
277
330
|
systemPromptMode: _systemPromptMode,
|
|
278
331
|
inheritProjectContext: _inheritProjectContext,
|
|
332
|
+
inheritGlobalContext: _inheritGlobalContext,
|
|
279
333
|
inheritSkills: _inheritSkills,
|
|
280
334
|
defaultContext: _defaultContext,
|
|
281
335
|
acceptanceRole: _acceptanceRole,
|
|
@@ -284,26 +338,35 @@ export function editableAgentConfig(agent: AgentConfig): AgentConfig {
|
|
|
284
338
|
skills: _skills,
|
|
285
339
|
skillPath: _skillPath,
|
|
286
340
|
tools: _tools,
|
|
341
|
+
excludeTools: _excludeTools,
|
|
287
342
|
mcpDirectTools: _mcpDirectTools,
|
|
343
|
+
allowNestedSubagents: _allowNestedSubagents,
|
|
288
344
|
subagentOnlyExtensions: _subagentOnlyExtensions,
|
|
345
|
+
mutationTools: _mutationTools,
|
|
289
346
|
completionGuard: _completionGuard,
|
|
347
|
+
toolBudget: _toolBudget,
|
|
290
348
|
...editable
|
|
291
349
|
} = withoutExtensions;
|
|
292
350
|
if (!base) {
|
|
293
|
-
return withDeclaredExtensionPaths({
|
|
351
|
+
return withDeclaredExtensionPaths(withoutSettingsDefaults({
|
|
294
352
|
...withoutExtensions,
|
|
295
353
|
...(agent.extensionsFromDefault ? {} : agent.extensions !== undefined ? { extensions: [...agent.extensions] } : {}),
|
|
296
|
-
}, agent.filePath);
|
|
354
|
+
}), agent.filePath);
|
|
297
355
|
}
|
|
298
356
|
|
|
299
357
|
return withDeclaredExtensionPaths({
|
|
300
358
|
...editable,
|
|
359
|
+
description,
|
|
360
|
+
...(base.output !== undefined ? { output: base.output } : {}),
|
|
301
361
|
...(base.outputMode !== undefined ? { outputMode: base.outputMode } : {}),
|
|
302
|
-
...(base.
|
|
362
|
+
...(base.defaultReads !== undefined ? { defaultReads: [...base.defaultReads] } : {}),
|
|
363
|
+
...(base.model !== undefined && hasDeclaredField("model") ? { model: base.model } : {}),
|
|
303
364
|
...(base.fallbackModels !== undefined ? { fallbackModels: [...base.fallbackModels] } : {}),
|
|
304
|
-
...(base.
|
|
365
|
+
...(base.fast !== undefined ? { fast: base.fast } : {}),
|
|
366
|
+
...(base.thinking !== undefined && hasDeclaredField("thinking") ? { thinking: base.thinking } : {}),
|
|
305
367
|
systemPromptMode: base.systemPromptMode,
|
|
306
368
|
inheritProjectContext: base.inheritProjectContext,
|
|
369
|
+
inheritGlobalContext: base.inheritGlobalContext,
|
|
307
370
|
inheritSkills: base.inheritSkills,
|
|
308
371
|
...(base.defaultContext !== undefined ? { defaultContext: base.defaultContext } : {}),
|
|
309
372
|
...(base.acceptanceRole !== undefined ? { acceptanceRole: base.acceptanceRole } : {}),
|
|
@@ -312,10 +375,14 @@ export function editableAgentConfig(agent: AgentConfig): AgentConfig {
|
|
|
312
375
|
...(base.skills !== undefined ? { skills: [...base.skills] } : {}),
|
|
313
376
|
...(base.skillPath !== undefined ? { skillPath: [...base.skillPath] } : {}),
|
|
314
377
|
...(base.tools !== undefined ? { tools: [...base.tools] } : {}),
|
|
378
|
+
...(base.excludeTools !== undefined ? { excludeTools: [...base.excludeTools] } : {}),
|
|
315
379
|
...(base.mcpDirectTools !== undefined ? { mcpDirectTools: [...base.mcpDirectTools] } : {}),
|
|
380
|
+
...(base.allowNestedSubagents !== undefined ? { allowNestedSubagents: base.allowNestedSubagents } : {}),
|
|
316
381
|
...(base.extensions !== undefined ? { extensions: [...base.extensions] } : {}),
|
|
317
382
|
...(base.subagentOnlyExtensions !== undefined ? { subagentOnlyExtensions: [...base.subagentOnlyExtensions] } : {}),
|
|
383
|
+
...(base.mutationTools !== undefined ? { mutationTools: [...base.mutationTools] } : {}),
|
|
318
384
|
...(base.completionGuard !== undefined ? { completionGuard: base.completionGuard } : {}),
|
|
385
|
+
...(base.toolBudget !== undefined ? { toolBudget: base.toolBudget } : {}),
|
|
319
386
|
}, agent.filePath);
|
|
320
387
|
}
|
|
321
388
|
|
|
@@ -343,10 +410,12 @@ export function preservedAgentFrontmatterFields(agent: AgentConfig, cfg: Record<
|
|
|
343
410
|
if (hasKey(cfg, "model")) changed("model");
|
|
344
411
|
if (hasKey(cfg, "fallbackModels")) changed("fallbackModels");
|
|
345
412
|
if (hasKey(cfg, "tools")) changed("tools");
|
|
413
|
+
if (hasKey(cfg, "excludeTools")) changed("excludeTools");
|
|
346
414
|
if (hasKey(cfg, "skills")) changed("skill", "skills");
|
|
347
415
|
if (hasKey(cfg, "skillPath")) changed("skillPath");
|
|
348
416
|
if (hasKey(cfg, "extensions")) changed("extensions");
|
|
349
417
|
if (hasKey(cfg, "subagentOnlyExtensions")) changed("subagentOnlyExtensions");
|
|
418
|
+
if (hasKey(cfg, "mutationTools")) changed("mutationTools");
|
|
350
419
|
if (hasKey(cfg, "thinking")) {
|
|
351
420
|
changed("thinking");
|
|
352
421
|
if (cfg.thinking === "off") fields.add("thinking");
|
|
@@ -359,6 +428,10 @@ export function preservedAgentFrontmatterFields(agent: AgentConfig, cfg: Record<
|
|
|
359
428
|
changed("inheritProjectContext");
|
|
360
429
|
fields.add("inheritProjectContext");
|
|
361
430
|
}
|
|
431
|
+
if (hasKey(cfg, "inheritGlobalContext")) {
|
|
432
|
+
changed("inheritGlobalContext");
|
|
433
|
+
fields.add("inheritGlobalContext");
|
|
434
|
+
}
|
|
362
435
|
if (hasKey(cfg, "inheritSkills")) {
|
|
363
436
|
changed("inheritSkills");
|
|
364
437
|
fields.add("inheritSkills");
|
|
@@ -366,7 +439,6 @@ export function preservedAgentFrontmatterFields(agent: AgentConfig, cfg: Record<
|
|
|
366
439
|
if (hasKey(cfg, "defaultContext")) changed("defaultContext");
|
|
367
440
|
if (hasKey(cfg, "async")) changed("async");
|
|
368
441
|
if (hasKey(cfg, "timeoutMs")) changed("timeoutMs");
|
|
369
|
-
if (hasKey(cfg, "turnBudget")) changed("turnBudget");
|
|
370
442
|
if (hasKey(cfg, "acceptance")) changed("acceptance");
|
|
371
443
|
if (hasKey(cfg, "acceptanceRole")) changed("acceptanceRole");
|
|
372
444
|
if (hasKey(cfg, "output")) changed("output");
|
|
@@ -423,15 +495,17 @@ function applyAgentConfig(target: AgentConfig, cfg: Record<string, unknown>): st
|
|
|
423
495
|
if (runner.type === "pi" && Object.keys(runner).every((key) => key === "type")) target.runner = { type: "pi" };
|
|
424
496
|
else if (runner.type === "external-cli" && typeof runner.command === "string" && runner.command.trim()
|
|
425
497
|
&& (runner.args === undefined || (Array.isArray(runner.args) && runner.args.every((arg) => typeof arg === "string")))
|
|
498
|
+
&& (runner.adapter === undefined || isCodeOwnedExternalCliAdapterId(runner.adapter))
|
|
499
|
+
&& (runner.adapter === undefined || runner.args === undefined || runner.args.length === 0)
|
|
426
500
|
&& (runner.promptDelivery === undefined || runner.promptDelivery === "stdin")
|
|
427
|
-
&& Object.keys(runner).every((key) => ["type", "command", "args", "promptDelivery"].includes(key))) {
|
|
501
|
+
&& Object.keys(runner).every((key) => ["type", "adapter", "command", "args", "promptDelivery"].includes(key))) {
|
|
428
502
|
const runnerArgs = Array.isArray(runner.args) ? runner.args.filter((arg): arg is string => typeof arg === "string") : undefined;
|
|
429
|
-
target.runner = { type: "external-cli", command: runner.command.trim(), ...(runnerArgs?.length ? { args: runnerArgs } : {}), ...(runner.promptDelivery ? { promptDelivery: "stdin" } : {}) };
|
|
503
|
+
target.runner = { type: "external-cli", ...(isCodeOwnedExternalCliAdapterId(runner.adapter) ? { adapter: runner.adapter } : {}), command: runner.command.trim(), ...(runnerArgs?.length ? { args: runnerArgs } : {}), ...(runner.promptDelivery ? { promptDelivery: "stdin" } : {}) };
|
|
430
504
|
} else if (runner.type === "external-job" && typeof runner.provider === "string" && runner.provider.trim() === runner.provider && runner.provider
|
|
431
505
|
&& (runner.options === undefined || (runner.options && typeof runner.options === "object" && !Array.isArray(runner.options) && isJsonSerializable(runner.options)))
|
|
432
506
|
&& Object.keys(runner).every((key) => ["type", "provider", "options"].includes(key))) {
|
|
433
507
|
target.runner = { type: "external-job", provider: runner.provider, ...(runner.options ? { options: runner.options as Record<string, unknown> } : {}) };
|
|
434
|
-
} else return
|
|
508
|
+
} else return `config.runner must be { type: 'pi' }, { type: 'external-cli', adapter?: ${CODE_OWNED_EXTERNAL_CLI_ADAPTER_LABEL}, command: string, args?: string[], promptDelivery?: 'stdin' }, or { type: 'external-job', provider: string, options?: object }.`;
|
|
435
509
|
} else return "config.runner must be an object, false, or empty string when provided.";
|
|
436
510
|
}
|
|
437
511
|
if (hasKey(cfg, "model")) {
|
|
@@ -467,6 +541,18 @@ function applyAgentConfig(target: AgentConfig, cfg: Record<string, unknown>): st
|
|
|
467
541
|
else delete target.mcpDirectTools;
|
|
468
542
|
} else return "config.tools must be a comma-separated string or false when provided.";
|
|
469
543
|
}
|
|
544
|
+
if (hasKey(cfg, "excludeTools")) {
|
|
545
|
+
if (cfg.excludeTools === false || cfg.excludeTools === "") delete target.excludeTools;
|
|
546
|
+
else if (typeof cfg.excludeTools === "string") {
|
|
547
|
+
const excludeTools = parseCsv(cfg.excludeTools);
|
|
548
|
+
if (excludeTools.length) target.excludeTools = [...new Set(excludeTools)];
|
|
549
|
+
else delete target.excludeTools;
|
|
550
|
+
} else if (Array.isArray(cfg.excludeTools) && cfg.excludeTools.every((entry) => typeof entry === "string")) {
|
|
551
|
+
const excludeTools = [...new Set(cfg.excludeTools.map((entry) => entry.trim()).filter(Boolean))];
|
|
552
|
+
if (excludeTools.length) target.excludeTools = excludeTools;
|
|
553
|
+
else delete target.excludeTools;
|
|
554
|
+
} else return "config.excludeTools must be a comma-separated string, string array, or false when provided.";
|
|
555
|
+
}
|
|
470
556
|
if (hasKey(cfg, "skills")) {
|
|
471
557
|
if (cfg.skills === false || cfg.skills === "") delete target.skills;
|
|
472
558
|
else if (typeof cfg.skills === "string") {
|
|
@@ -499,6 +585,12 @@ function applyAgentConfig(target: AgentConfig, cfg: Record<string, unknown>): st
|
|
|
499
585
|
else if (typeof cfg.subagentOnlyExtensions === "string") target.subagentOnlyExtensions = parseCsv(cfg.subagentOnlyExtensions);
|
|
500
586
|
else return "config.subagentOnlyExtensions must be a comma-separated string, empty string, or false when provided.";
|
|
501
587
|
}
|
|
588
|
+
if (hasKey(cfg, "mutationTools")) {
|
|
589
|
+
if (cfg.mutationTools === false) delete target.mutationTools;
|
|
590
|
+
else if (cfg.mutationTools === "") target.mutationTools = [];
|
|
591
|
+
else if (typeof cfg.mutationTools === "string") target.mutationTools = parseCsv(cfg.mutationTools);
|
|
592
|
+
else return "config.mutationTools must be a comma-separated string, empty string, or false when provided.";
|
|
593
|
+
}
|
|
502
594
|
if (hasKey(cfg, "thinking")) {
|
|
503
595
|
if (cfg.thinking === false || cfg.thinking === "") delete target.thinking;
|
|
504
596
|
else if (typeof cfg.thinking === "string") {
|
|
@@ -515,6 +607,10 @@ function applyAgentConfig(target: AgentConfig, cfg: Record<string, unknown>): st
|
|
|
515
607
|
if (typeof cfg.inheritProjectContext !== "boolean") return "config.inheritProjectContext must be a boolean when provided.";
|
|
516
608
|
target.inheritProjectContext = cfg.inheritProjectContext;
|
|
517
609
|
}
|
|
610
|
+
if (hasKey(cfg, "inheritGlobalContext")) {
|
|
611
|
+
if (typeof cfg.inheritGlobalContext !== "boolean") return "config.inheritGlobalContext must be a boolean when provided.";
|
|
612
|
+
target.inheritGlobalContext = cfg.inheritGlobalContext;
|
|
613
|
+
}
|
|
518
614
|
if (hasKey(cfg, "inheritSkills")) {
|
|
519
615
|
if (typeof cfg.inheritSkills !== "boolean") return "config.inheritSkills must be a boolean when provided.";
|
|
520
616
|
target.inheritSkills = cfg.inheritSkills;
|
|
@@ -534,15 +630,6 @@ function applyAgentConfig(target: AgentConfig, cfg: Record<string, unknown>): st
|
|
|
534
630
|
else if (typeof cfg.timeoutMs === "number" && Number.isInteger(cfg.timeoutMs) && cfg.timeoutMs > 0) target.defaultTimeoutMs = cfg.timeoutMs;
|
|
535
631
|
else return "config.timeoutMs must be a positive integer or false when provided.";
|
|
536
632
|
}
|
|
537
|
-
if (hasKey(cfg, "turnBudget")) {
|
|
538
|
-
if (cfg.turnBudget === false || cfg.turnBudget === "") delete target.defaultTurnBudget;
|
|
539
|
-
else {
|
|
540
|
-
const resolved = resolveTurnBudgetConfig(cfg.turnBudget, "config.turnBudget");
|
|
541
|
-
if (resolved.error) return resolved.error;
|
|
542
|
-
if (resolved.turnBudget !== undefined) target.defaultTurnBudget = resolved.turnBudget;
|
|
543
|
-
else delete target.defaultTurnBudget;
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
633
|
if (hasKey(cfg, "acceptance")) {
|
|
547
634
|
if (cfg.acceptance === "") delete target.defaultAcceptance;
|
|
548
635
|
else {
|
|
@@ -598,11 +685,13 @@ function applyAgentConfig(target: AgentConfig, cfg: Record<string, unknown>): st
|
|
|
598
685
|
if (target.runner?.type === "external-cli" || target.runner?.type === "external-job") {
|
|
599
686
|
const unsupported = [
|
|
600
687
|
target.tools?.length || target.mcpDirectTools?.length ? "tools" : undefined,
|
|
688
|
+
target.excludeTools?.length ? "excludeTools" : undefined,
|
|
601
689
|
target.model ? "model" : undefined,
|
|
602
690
|
target.fallbackModels?.length ? "fallbackModels" : undefined,
|
|
603
691
|
target.thinking ? "thinking" : undefined,
|
|
604
692
|
target.extensions?.length ? "extensions" : undefined,
|
|
605
693
|
target.subagentOnlyExtensions?.length ? "subagentOnlyExtensions" : undefined,
|
|
694
|
+
target.mutationTools?.length ? "mutationTools" : undefined,
|
|
606
695
|
target.skills?.length || target.skillPath?.length ? "skills" : undefined,
|
|
607
696
|
target.maxSubagentDepth !== undefined ? "maxSubagentDepth" : undefined,
|
|
608
697
|
target.completionGuard !== undefined ? "completionGuard" : undefined,
|
|
@@ -646,9 +735,229 @@ function renamePath(currentPath: string, newName: string, scope: ManagementScope
|
|
|
646
735
|
return { filePath };
|
|
647
736
|
}
|
|
648
737
|
|
|
738
|
+
function packageSourceLabel(agent: AgentConfig): string {
|
|
739
|
+
if (!agent.packageSourceName) return agent.source;
|
|
740
|
+
return agent.packageSourceVersion ? `${agent.packageSourceName}@${agent.packageSourceVersion}` : agent.packageSourceName;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
type ExternalJobProviderStatus =
|
|
744
|
+
| { ok: true; names: Set<string> }
|
|
745
|
+
| { ok: false; error: string };
|
|
746
|
+
|
|
747
|
+
function errorMessage(error: unknown): string {
|
|
748
|
+
return error instanceof Error ? error.message : String(error);
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
function registeredExternalJobProviderStatus(): ExternalJobProviderStatus {
|
|
752
|
+
try {
|
|
753
|
+
return { ok: true, names: new Set(listExternalJobProviders().map((provider) => provider.name)) };
|
|
754
|
+
} catch (error) {
|
|
755
|
+
return { ok: false, error: errorMessage(error) };
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
function externalJobProviderSuffix(provider: string, names: Set<string> | undefined): string {
|
|
760
|
+
if (!names) return "?";
|
|
761
|
+
return names.has(provider) ? "✓" : "missing";
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
type ExternalCliAvailabilityByCommand = ReadonlyMap<string, ExternalCliBinaryAvailability>;
|
|
765
|
+
|
|
766
|
+
function externalCliAvailabilityForAgents(agents: readonly AgentConfig[]): ExternalCliAvailabilityByCommand {
|
|
767
|
+
const availability = new Map<string, ExternalCliBinaryAvailability>();
|
|
768
|
+
for (const agent of agents) {
|
|
769
|
+
const runner = agent.runner;
|
|
770
|
+
if (runner?.type === "external-cli" && !availability.has(runner.command)) {
|
|
771
|
+
availability.set(runner.command, resolveExternalCliBinaryAvailability(runner.command, process.env));
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
return availability;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
function runnerListBadge(agent: AgentConfig, providerNames: Set<string> | undefined, externalCliAvailability?: ExternalCliAvailabilityByCommand): string | undefined {
|
|
778
|
+
if (agent.runner?.type === "external-job") return `external-job:${agent.runner.provider} ${externalJobProviderSuffix(agent.runner.provider, providerNames)}`;
|
|
779
|
+
if (agent.runner?.type === "external-cli") {
|
|
780
|
+
const availability = externalCliAvailability?.get(agent.runner.command);
|
|
781
|
+
if (!availability) return "external-cli";
|
|
782
|
+
return `external-cli:${agent.runner.command} ${availability.available ? "✓" : "missing"}`;
|
|
783
|
+
}
|
|
784
|
+
return undefined;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
function agentListMetadata(agent: AgentConfig, providerNames: Set<string> | undefined, externalCliAvailability?: ExternalCliAvailabilityByCommand): string {
|
|
788
|
+
const source = agent.source === "package" ? packageSourceLabel(agent) : agent.source;
|
|
789
|
+
return [
|
|
790
|
+
source,
|
|
791
|
+
runnerListBadge(agent, providerNames, externalCliAvailability),
|
|
792
|
+
agent.defaultContext ? `context: ${agent.defaultContext}` : undefined,
|
|
793
|
+
agent.aliases?.length ? `aliases: ${agent.aliases.join(", ")}` : undefined,
|
|
794
|
+
].filter((part): part is string => Boolean(part)).join(", ");
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
function formatAgentListLine(agent: AgentConfig, providerNames: Set<string> | undefined): string {
|
|
798
|
+
return `- ${agent.name} (${agentListMetadata(agent, providerNames)}): ${agent.description}`;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
function formatAgentCapabilitiesLine(agent: AgentConfig, providerNames: Set<string> | undefined, externalCliAvailability?: ExternalCliAvailabilityByCommand): string {
|
|
802
|
+
const declaredTools = [
|
|
803
|
+
...(agent.tools ?? []),
|
|
804
|
+
...(agent.mcpDirectTools ?? []).map((tool) => `mcp:${tool}`),
|
|
805
|
+
];
|
|
806
|
+
let tools = "none";
|
|
807
|
+
if (agent.tools === undefined && agent.mcpDirectTools === undefined) {
|
|
808
|
+
tools = "default/ambient";
|
|
809
|
+
} else if (declaredTools.length > 0) {
|
|
810
|
+
tools = declaredTools.join(", ");
|
|
811
|
+
}
|
|
812
|
+
if (agent.excludeTools?.length) tools = `${tools}; excludes: ${agent.excludeTools.join(", ")}`;
|
|
813
|
+
let model = "inherits current session";
|
|
814
|
+
if (agent.model !== undefined) {
|
|
815
|
+
model = agent.model;
|
|
816
|
+
if (agent.modelProvider && !agent.model.includes("/")) model = `${agent.modelProvider}/${agent.model}`;
|
|
817
|
+
}
|
|
818
|
+
const thinking = agent.thinking === false ? "off" : agent.thinking ?? "default";
|
|
819
|
+
return `- ${agent.name} (${agentListMetadata(agent, providerNames, externalCliAvailability)}): Description: ${previewDisplayText(agent.description, 240)}; Tools: ${tools}; Model: ${model}; Thinking: ${thinking}`;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
const EXTERNAL_JOB_CAPABILITIES = { stop: false, steer: false, resume: false, structuredOutput: false, toolEvents: false } as const;
|
|
823
|
+
const PI_AGENT_RUNNER = { type: "pi" } as const;
|
|
824
|
+
|
|
825
|
+
function listOrEmpty<T>(values: T[] | undefined): T[] {
|
|
826
|
+
return values ?? [];
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
function agentCapabilityRunner(agent: AgentConfig, providerNames: Set<string> | undefined, externalCliAvailability: ExternalCliAvailabilityByCommand): AgentCapabilityRow["runner"] {
|
|
830
|
+
const runner = agent.runner;
|
|
831
|
+
if (!runner || runner.type === "pi") return PI_AGENT_RUNNER;
|
|
832
|
+
if (runner.type === "external-cli") {
|
|
833
|
+
const availability = externalCliAvailability.get(runner.command)!;
|
|
834
|
+
return {
|
|
835
|
+
type: "external-cli",
|
|
836
|
+
adapter: runner.adapter,
|
|
837
|
+
command: runner.command,
|
|
838
|
+
...availability,
|
|
839
|
+
capabilities: resolveExternalCliRunnerStatus(runner).capabilities,
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
return { type: "external-job", provider: runner.provider, available: providerNames?.has(runner.provider), capabilities: EXTERNAL_JOB_CAPABILITIES };
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
function agentCapabilityTools(agent: AgentConfig): AgentCapabilityRow["tools"] {
|
|
846
|
+
return {
|
|
847
|
+
ambient: agent.tools === undefined && agent.mcpDirectTools === undefined,
|
|
848
|
+
names: listOrEmpty(agent.tools),
|
|
849
|
+
...(agent.excludeTools !== undefined ? { excludeTools: [...agent.excludeTools] } : {}),
|
|
850
|
+
mcpDirectTools: listOrEmpty(agent.mcpDirectTools),
|
|
851
|
+
mutationTools: agent.mutationTools,
|
|
852
|
+
};
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
function agentCapabilityRow(agent: AgentConfig, options: { executable: boolean; providerNames?: Set<string>; externalCliAvailability: ExternalCliAvailabilityByCommand; restrictionSources?: string[] }): AgentCapabilityRow {
|
|
856
|
+
return {
|
|
857
|
+
name: agent.name,
|
|
858
|
+
description: previewDisplayText(agent.description, 1000),
|
|
859
|
+
source: agent.source,
|
|
860
|
+
executable: options.executable,
|
|
861
|
+
restrictionSources: options.executable ? undefined : options.restrictionSources ?? [],
|
|
862
|
+
aliases: agent.aliases ? [...agent.aliases] : undefined,
|
|
863
|
+
runner: agentCapabilityRunner(agent, options.providerNames, options.externalCliAvailability),
|
|
864
|
+
tools: agentCapabilityTools(agent),
|
|
865
|
+
model: presentDetails({ value: agent.model, fallbackModels: agent.fallbackModels, thinking: agent.thinking }),
|
|
866
|
+
execution: presentDetails({ defaultAsync: agent.defaultAsync, timeoutMs: agent.defaultTimeoutMs }),
|
|
867
|
+
output: presentDetails({ path: agent.output, mode: agent.outputMode }),
|
|
868
|
+
extensions: presentDetails({ names: agent.extensions, subagentOnly: agent.subagentOnlyExtensions, skills: agent.skills }),
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
function agentCapabilitiesSnapshot(input: { agents: AgentConfig[]; restrictedAgents: AgentConfig[]; providerNames?: Set<string>; externalCliAvailability: ExternalCliAvailabilityByCommand; restrictedSources?: string[] }): AgentCapabilitiesSnapshot {
|
|
873
|
+
return {
|
|
874
|
+
agents: [
|
|
875
|
+
...input.agents.map((agent) => agentCapabilityRow(agent, { executable: true, providerNames: input.providerNames, externalCliAvailability: input.externalCliAvailability })),
|
|
876
|
+
...input.restrictedAgents.map((agent) => agentCapabilityRow(agent, { executable: false, providerNames: input.providerNames, externalCliAvailability: input.externalCliAvailability, restrictionSources: input.restrictedSources })),
|
|
877
|
+
],
|
|
878
|
+
restrictedCount: input.restrictedAgents.length,
|
|
879
|
+
...(input.restrictedSources?.length ? { capabilityCeilingSources: [...input.restrictedSources] } : {}),
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
function providerNames(status: ExternalJobProviderStatus): Set<string> | undefined {
|
|
884
|
+
return status.ok ? status.names : undefined;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
function appendRestrictedAgentLines(input: { lines: string[]; agents: AgentConfig[]; sources?: string[]; providerNames?: Set<string>; formatLine: (agent: AgentConfig, providerNames: Set<string> | undefined) => string }): void {
|
|
888
|
+
if (input.agents.length === 0) return;
|
|
889
|
+
input.lines.push(
|
|
890
|
+
"",
|
|
891
|
+
`Restricted agents (not executable in this session${input.sources?.length ? `; capability ceiling: ${input.sources.join(", ")}` : ""}):`,
|
|
892
|
+
...input.agents.map((agent) => input.formatLine(agent, input.providerNames)),
|
|
893
|
+
);
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
function appendExternalJobRegistryLine(lines: string[], agents: AgentConfig[], status: ExternalJobProviderStatus): void {
|
|
897
|
+
if (status.ok || !agents.some((agent) => agent.runner?.type === "external-job")) return;
|
|
898
|
+
lines.push("", `External-job provider registry unavailable: ${status.error}`);
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
function appendAgentDiagnosticLines(lines: string[], diagnostics: AgentDiscoveryDiagnostic[] | undefined): void {
|
|
902
|
+
if (!diagnostics?.length) return;
|
|
903
|
+
lines.push(
|
|
904
|
+
"",
|
|
905
|
+
"Invalid agent definitions:",
|
|
906
|
+
...diagnostics.map((diagnostic) => `- ${diagnostic.name ?? diagnostic.filePath} (${diagnostic.source}): ${diagnostic.error}`),
|
|
907
|
+
);
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
function agentCapabilityDetails(input: { capabilityMode: boolean; agents: AgentConfig[]; restrictedAgents: AgentConfig[]; providerNames?: Set<string>; externalCliAvailability: ExternalCliAvailabilityByCommand; restrictedSources?: string[] }): Partial<Details> | undefined {
|
|
911
|
+
if (!input.capabilityMode) return undefined;
|
|
912
|
+
return {
|
|
913
|
+
agentCapabilities: jsonDetails(agentCapabilitiesSnapshot({
|
|
914
|
+
agents: input.agents,
|
|
915
|
+
restrictedAgents: input.restrictedAgents,
|
|
916
|
+
providerNames: input.providerNames,
|
|
917
|
+
externalCliAvailability: input.externalCliAvailability,
|
|
918
|
+
restrictedSources: input.restrictedSources,
|
|
919
|
+
})),
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
function formatAgentListSections(
|
|
924
|
+
agents: AgentConfig[],
|
|
925
|
+
providerNames: Set<string> | undefined,
|
|
926
|
+
formatLine: (agent: AgentConfig, providerNames: Set<string> | undefined) => string = formatAgentListLine,
|
|
927
|
+
): string[] {
|
|
928
|
+
if (agents.length === 0) return ["- (none)"];
|
|
929
|
+
const sections: Array<[AgentSource, string]> = [
|
|
930
|
+
["package", "Package agents"],
|
|
931
|
+
["user", "User agents"],
|
|
932
|
+
["project", "Project agents"],
|
|
933
|
+
["runtime", "Runtime agents"],
|
|
934
|
+
["builtin", "Builtin agents"],
|
|
935
|
+
];
|
|
936
|
+
const lines: string[] = [];
|
|
937
|
+
for (const [source, label] of sections) {
|
|
938
|
+
const matches = agents.filter((agent) => agent.source === source);
|
|
939
|
+
if (matches.length === 0) continue;
|
|
940
|
+
if (lines.length > 0) lines.push("");
|
|
941
|
+
lines.push(label, ...matches.map((agent) => formatLine(agent, providerNames)));
|
|
942
|
+
}
|
|
943
|
+
return lines;
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
function formatRunnerDetail(agent: AgentConfig, providerNames: Set<string> | undefined): string | undefined {
|
|
947
|
+
if (!agent.runner) return undefined;
|
|
948
|
+
if (agent.runner.type === "external-job") return `Runner: external-job via ${agent.runner.provider} ${externalJobProviderSuffix(agent.runner.provider, providerNames)}`;
|
|
949
|
+
if (agent.runner.type === "external-cli") return `Runner: external-cli ${agent.runner.command}`;
|
|
950
|
+
return `Runner: ${JSON.stringify(agent.runner)}`;
|
|
951
|
+
}
|
|
952
|
+
|
|
649
953
|
function formatAgentDetail(agent: AgentConfig): string {
|
|
650
954
|
const tools = [...(agent.tools ?? []), ...(agent.mcpDirectTools ?? []).map((t) => `mcp:${t}`)];
|
|
955
|
+
const providerStatus = registeredExternalJobProviderStatus();
|
|
651
956
|
const lines: string[] = [`Agent: ${agent.name} (${agent.source})`, `Path: ${agent.filePath}`, `Description: ${agent.description}`];
|
|
957
|
+
if (agent.source === "package" && agent.packageSourceName) {
|
|
958
|
+
lines.push(`Source package: ${packageSourceLabel(agent)}`);
|
|
959
|
+
if (agent.packageSourceRoot) lines.push(`Package root: ${agent.packageSourceRoot}`);
|
|
960
|
+
}
|
|
652
961
|
if (agent.packageName) {
|
|
653
962
|
lines.push(`Local name: ${frontmatterNameForConfig(agent)}`);
|
|
654
963
|
lines.push(`Package: ${agent.packageName}`);
|
|
@@ -657,21 +966,28 @@ function formatAgentDetail(agent: AgentConfig): string {
|
|
|
657
966
|
if (agent.model) lines.push(`Model: ${agent.model}`);
|
|
658
967
|
if (agent.fallbackModels?.length) lines.push(`Fallback models: ${agent.fallbackModels.join(", ")}`);
|
|
659
968
|
if (tools.length) lines.push(`Tools: ${tools.join(", ")}`);
|
|
969
|
+
if (agent.excludeTools?.length) lines.push(`Excluded tools: ${agent.excludeTools.join(", ")}`);
|
|
660
970
|
if (agent.skills?.length) lines.push(`Skills: ${agent.skills.join(", ")}`);
|
|
661
971
|
if (agent.skillPath?.length) lines.push(`Skill paths: ${agent.skillPath.join(", ")}`);
|
|
662
972
|
lines.push(`System prompt mode: ${agent.systemPromptMode}`);
|
|
663
|
-
|
|
973
|
+
const runnerDetail = formatRunnerDetail(agent, providerStatus.ok ? providerStatus.names : undefined);
|
|
974
|
+
if (runnerDetail) {
|
|
975
|
+
lines.push(runnerDetail);
|
|
976
|
+
if (agent.runner?.type === "external-job" && !providerStatus.ok) lines.push(`External-job provider registry unavailable: ${providerStatus.error}`);
|
|
977
|
+
if (agent.runner?.type === "external-job" && agent.runner.options) lines.push(`Runner options: ${JSON.stringify(agent.runner.options)}`);
|
|
978
|
+
}
|
|
664
979
|
lines.push(`Inherit project context: ${agent.inheritProjectContext ? "true" : "false"}`);
|
|
980
|
+
lines.push(`Inherit global context: ${agent.inheritGlobalContext ? "true" : "false"}`);
|
|
665
981
|
lines.push(`Inherit skills: ${agent.inheritSkills ? "true" : "false"}`);
|
|
666
982
|
if (agent.defaultContext) lines.push(`Default context: ${agent.defaultContext}`);
|
|
667
983
|
if (agent.defaultAsync !== undefined) lines.push(`Async: ${agent.defaultAsync ? "true" : "false"}`);
|
|
668
984
|
if (agent.defaultTimeoutMs !== undefined) lines.push(`Timeout: ${agent.defaultTimeoutMs}ms`);
|
|
669
|
-
if (agent.defaultTurnBudget) lines.push(`Turn budget: ${JSON.stringify(agent.defaultTurnBudget)}`);
|
|
670
985
|
if (agent.defaultAcceptance !== undefined) lines.push(`Acceptance: ${typeof agent.defaultAcceptance === "object" ? JSON.stringify(agent.defaultAcceptance) : String(agent.defaultAcceptance)}`);
|
|
671
986
|
if (agent.acceptanceRole) lines.push(`Acceptance role: ${agent.acceptanceRole}`);
|
|
672
987
|
if (agent.source === "builtin") lines.push(`Disabled: ${agent.disabled ? "true" : "false"}`);
|
|
673
988
|
if (agent.extensions !== undefined) lines.push(`Extensions: ${agent.extensions.length ? agent.extensions.join(", ") : "(none)"}`);
|
|
674
989
|
if (agent.subagentOnlyExtensions !== undefined) lines.push(`Subagent-only extensions: ${agent.subagentOnlyExtensions.length ? agent.subagentOnlyExtensions.join(", ") : "(none)"}`);
|
|
990
|
+
if (agent.mutationTools !== undefined) lines.push(`Mutation tools: ${agent.mutationTools.length ? agent.mutationTools.join(", ") : "(none)"}`);
|
|
675
991
|
if (agent.thinking) lines.push(`Thinking: ${agent.thinking}`);
|
|
676
992
|
if (agent.output) lines.push(`Output: ${agent.output}`);
|
|
677
993
|
if (agent.outputMode) lines.push(`Output mode: ${agent.outputMode}`);
|
|
@@ -687,17 +1003,8 @@ function formatAgentDetail(agent: AgentConfig): string {
|
|
|
687
1003
|
|
|
688
1004
|
export function handleList(params: ManagementParams, ctx: ManagementContext): AgentToolResult<Details> {
|
|
689
1005
|
const scope = normalizeListScope(params.agentScope) ?? "both";
|
|
690
|
-
const d = discoverAgentsAll(ctx.cwd);
|
|
691
|
-
let scopedAgents =
|
|
692
|
-
if (ctx.runtimeAgentOwner && listRuntimeAgentConfigs(ctx.runtimeAgentOwner).length > 0) {
|
|
693
|
-
const configuredAgents: AgentConfig[] = [
|
|
694
|
-
...d.builtin,
|
|
695
|
-
...d.package,
|
|
696
|
-
...d.user,
|
|
697
|
-
...d.project,
|
|
698
|
-
];
|
|
699
|
-
scopedAgents = mergeRuntimeAgents(ctx.runtimeAgentOwner, { agents: scopedAgents }, configuredAgents).agents;
|
|
700
|
-
}
|
|
1006
|
+
const d = discoverAgentsAll(ctx.cwd, ctx.model?.provider);
|
|
1007
|
+
let scopedAgents = effectiveAgentsForScope(scope, d, ctx.runtimeAgentOwner);
|
|
701
1008
|
scopedAgents = scopedAgents
|
|
702
1009
|
.sort((a, b) => a.name.localeCompare(b.name));
|
|
703
1010
|
const capabilityCeiling = resolveCurrentSubagentCapabilityCeiling(ctx.currentSessionId);
|
|
@@ -710,24 +1017,29 @@ export function handleList(params: ManagementParams, ctx: ManagementContext): Ag
|
|
|
710
1017
|
...(ctx.config?.proactiveSkillSubagents !== undefined ? { config: ctx.config.proactiveSkillSubagents } : {}),
|
|
711
1018
|
discoverAvailableSkills: () => discoverAvailableSkills(ctx.cwd),
|
|
712
1019
|
});
|
|
1020
|
+
const providerStatus = registeredExternalJobProviderStatus();
|
|
1021
|
+
const providerNameSet = providerNames(providerStatus);
|
|
1022
|
+
const capabilityMode = params.capabilities === true;
|
|
1023
|
+
const externalCliAvailability = capabilityMode ? externalCliAvailabilityForAgents([...agents, ...restrictedAgents]) : undefined;
|
|
1024
|
+
const formatLine = capabilityMode
|
|
1025
|
+
? (agent: AgentConfig, names: Set<string> | undefined) => formatAgentCapabilitiesLine(agent, names, externalCliAvailability)
|
|
1026
|
+
: formatAgentListLine;
|
|
713
1027
|
const lines = [
|
|
714
|
-
"Executable agents:",
|
|
715
|
-
...(agents
|
|
716
|
-
? agents.map((a) => `- ${a.name} (${a.source}${a.defaultContext ? `, context: ${a.defaultContext}` : ""}${a.aliases?.length ? `, aliases: ${a.aliases.join(", ")}` : ""}): ${a.description}`)
|
|
717
|
-
: ["- (none)"]),
|
|
718
|
-
...(restrictedAgents.length ? [
|
|
719
|
-
"",
|
|
720
|
-
`Restricted agents (not executable in this session${restrictedSources?.length ? `; capability ceiling: ${restrictedSources.join(", ")}` : ""}):`,
|
|
721
|
-
...restrictedAgents.map((a) => `- ${a.name} (${a.source}${a.aliases?.length ? `, aliases: ${a.aliases.join(", ")}` : ""}): ${a.description}`),
|
|
722
|
-
] : []),
|
|
723
|
-
...(d.agentDiagnostics?.length ? [
|
|
724
|
-
"",
|
|
725
|
-
"Invalid agent definitions:",
|
|
726
|
-
...d.agentDiagnostics.map((diagnostic) => `- ${diagnostic.name ?? diagnostic.filePath} (${diagnostic.source}): ${diagnostic.error}`),
|
|
727
|
-
] : []),
|
|
728
|
-
...(proactiveSuggestions.length ? ["", ...proactiveSuggestions] : []),
|
|
1028
|
+
capabilityMode ? "Executable agents (capabilities):" : "Executable agents:",
|
|
1029
|
+
...formatAgentListSections(agents, providerNameSet, formatLine),
|
|
729
1030
|
];
|
|
730
|
-
|
|
1031
|
+
appendRestrictedAgentLines({ lines, agents: restrictedAgents, sources: restrictedSources, providerNames: providerNameSet, formatLine });
|
|
1032
|
+
appendExternalJobRegistryLine(lines, [...agents, ...restrictedAgents], providerStatus);
|
|
1033
|
+
appendAgentDiagnosticLines(lines, d.agentDiagnostics);
|
|
1034
|
+
if (proactiveSuggestions.length) lines.push("", ...proactiveSuggestions);
|
|
1035
|
+
return result(lines.join("\n"), false, agentCapabilityDetails({
|
|
1036
|
+
capabilityMode,
|
|
1037
|
+
agents,
|
|
1038
|
+
restrictedAgents,
|
|
1039
|
+
providerNames: providerNameSet,
|
|
1040
|
+
externalCliAvailability: externalCliAvailability ?? new Map(),
|
|
1041
|
+
restrictedSources,
|
|
1042
|
+
}));
|
|
731
1043
|
}
|
|
732
1044
|
|
|
733
1045
|
function formatModelSource(agent: AgentConfig, currentModel: ParentModel | undefined): string {
|
|
@@ -737,77 +1049,117 @@ function formatModelSource(agent: AgentConfig, currentModel: ParentModel | undef
|
|
|
737
1049
|
if (agent.modelSource?.type === "subagents.defaultModel" && agent.model === agent.modelSource.model) {
|
|
738
1050
|
return `${agent.modelSource.scope} defaultModel`;
|
|
739
1051
|
}
|
|
740
|
-
if (agent.model) return
|
|
1052
|
+
if (agent.model) return `${agent.source} agent config`;
|
|
741
1053
|
if (currentModel) return "inherits current session model";
|
|
742
1054
|
return "inherit requested, but no current session model is available";
|
|
743
1055
|
}
|
|
744
1056
|
|
|
745
1057
|
function handleModels(params: ManagementParams, ctx: ManagementContext): AgentToolResult<Details> {
|
|
746
1058
|
const requestedAgent = params.agent?.trim();
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
}
|
|
1059
|
+
const scope = normalizeListScope(params.agentScope);
|
|
1060
|
+
if (!scope) return result("agentScope must be 'user', 'project', or 'both' for models.", true);
|
|
750
1061
|
|
|
751
|
-
const discovered = discoverAgentsAll(ctx.cwd);
|
|
752
|
-
const
|
|
1062
|
+
const discovered = discoverAgentsAll(ctx.cwd, ctx.model?.provider);
|
|
1063
|
+
const effectiveAgents = effectiveAgentsForScope(scope, discovered, ctx.runtimeAgentOwner)
|
|
1064
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
753
1065
|
const availableModels = ctx.modelRegistry.getAvailable().map(toModelInfo);
|
|
754
1066
|
const currentModel = ctx.model ? { provider: ctx.model.provider, id: ctx.model.id } : undefined;
|
|
755
1067
|
const preferredProvider = ctx.model?.provider;
|
|
756
|
-
const
|
|
1068
|
+
const capabilityCeiling = resolveCurrentSubagentCapabilityCeiling(ctx.currentSessionId);
|
|
757
1069
|
|
|
1070
|
+
let selectedAgents = effectiveAgents;
|
|
758
1071
|
if (requestedAgent) {
|
|
759
|
-
const
|
|
760
|
-
|
|
761
|
-
const
|
|
762
|
-
const
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
`
|
|
769
|
-
];
|
|
770
|
-
if (agent.override) {
|
|
771
|
-
lines.push("Override file:");
|
|
772
|
-
lines.push(` ${agent.override.path}`);
|
|
773
|
-
}
|
|
774
|
-
if (agent.model && resolvedModel && agent.model !== resolvedModel) {
|
|
775
|
-
lines.push("Requested model setting:");
|
|
776
|
-
lines.push(` ${agent.model}`);
|
|
1072
|
+
const matches = findAgentsInDiscovery(requestedAgent, discovered, scope, ctx.runtimeAgentOwner);
|
|
1073
|
+
const diagnostics = diagnosticsForScope(discovered.agentDiagnostics, scope);
|
|
1074
|
+
const normalizedName = sanitizeName(requestedAgent);
|
|
1075
|
+
const diagnostic = findBlockingAgentDiagnostic(requestedAgent, matches, diagnostics)
|
|
1076
|
+
?? (normalizedName !== requestedAgent ? findBlockingAgentDiagnostic(normalizedName, matches, diagnostics) : undefined);
|
|
1077
|
+
if (diagnostic) return result(`Agent '${params.agent}' has invalid configuration: ${diagnostic.error}`, true);
|
|
1078
|
+
const distinctNames = [...new Set(matches.map((agent) => agent.name))];
|
|
1079
|
+
if (distinctNames.length > 1) return result(`Ambiguous agent alias or name '${params.agent}': ${distinctNames.sort((a, b) => a.localeCompare(b)).join(", ")}`, true);
|
|
1080
|
+
if (!matches.length) {
|
|
1081
|
+
return result(`Agent '${params.agent}' not found. Available: ${availableAgentNamesFromDiscovery(discovered, ctx.runtimeAgentOwner).join(", ") || "none"}.`, true);
|
|
777
1082
|
}
|
|
778
|
-
|
|
779
|
-
lines.push("Current session model:");
|
|
780
|
-
lines.push(` ${currentModel ? `${currentModel.provider}/${currentModel.id}` : "(unavailable)"}`);
|
|
781
|
-
return result(lines.join("\n"));
|
|
1083
|
+
selectedAgents = [matches[0]!];
|
|
782
1084
|
}
|
|
783
1085
|
|
|
784
1086
|
const lines = [
|
|
785
|
-
"
|
|
786
|
-
"",
|
|
787
|
-
"Current session model:",
|
|
788
|
-
` ${currentModel ? `${currentModel.provider}/${currentModel.id}` : "(unavailable)"}`,
|
|
1087
|
+
requestedAgent ? "Subagent model" : "Subagent models",
|
|
789
1088
|
"",
|
|
1089
|
+
...(requestedAgent ? [] : [
|
|
1090
|
+
"Current session model:",
|
|
1091
|
+
` ${currentModel ? `${currentModel.provider}/${currentModel.id}` : "(unavailable)"}`,
|
|
1092
|
+
"",
|
|
1093
|
+
]),
|
|
790
1094
|
];
|
|
791
1095
|
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
1096
|
+
const modelEntries = selectedAgents.flatMap((agent) => requestedAgent
|
|
1097
|
+
? [{ agent, name: requestedAgent }]
|
|
1098
|
+
: [{ agent, name: agent.name }, ...(agent.aliases ?? []).map((name) => ({ agent, name }))]);
|
|
1099
|
+
for (const { agent, name } of modelEntries) {
|
|
1100
|
+
const resolvedModel = resolveSubagentModelOverride(agent.model, currentModel, availableModels, agent.modelProvider ?? preferredProvider);
|
|
1101
|
+
const effectiveThinking = resolveEffectiveThinking(resolvedModel, agent.thinking)
|
|
1102
|
+
?? (agent.thinking === false ? "off" : undefined);
|
|
1103
|
+
const source = `${formatModelSource(agent, currentModel)}${agent.disabled ? "; disabled" : ""}${isAgentAllowedByCapabilityCeiling(agent.name, capabilityCeiling) ? "" : "; restricted"}`;
|
|
1104
|
+
if (requestedAgent) {
|
|
1105
|
+
lines.push(`Agent: ${requestedAgent}`);
|
|
1106
|
+
lines.push("Effective model:");
|
|
1107
|
+
lines.push(` ${resolvedModel ?? "(unresolved)"}`);
|
|
1108
|
+
lines.push(`Source: ${source}`);
|
|
1109
|
+
lines.push(`Thinking: ${effectiveThinking ?? "default"}`);
|
|
1110
|
+
if (agent.fallbackModels?.length) {
|
|
1111
|
+
lines.push("Fallback models:");
|
|
1112
|
+
for (const fallback of agent.fallbackModels) {
|
|
1113
|
+
lines.push(` ${resolveSubagentModelOverride(fallback, currentModel, availableModels, agent.modelProvider ?? preferredProvider) ?? fallback}`);
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
if (agent.override) {
|
|
1117
|
+
lines.push("Override file:");
|
|
1118
|
+
lines.push(` ${agent.override.path}`);
|
|
1119
|
+
}
|
|
1120
|
+
if (agent.model && resolvedModel && agent.model !== resolvedModel) {
|
|
1121
|
+
lines.push("Requested model setting:");
|
|
1122
|
+
lines.push(` ${agent.model}`);
|
|
1123
|
+
}
|
|
1124
|
+
if (agent.disabled) lines.push("Disabled: true");
|
|
1125
|
+
if (!isAgentAllowedByCapabilityCeiling(agent.name, capabilityCeiling)) lines.push("Restricted: true");
|
|
1126
|
+
lines.push("Current session model:");
|
|
1127
|
+
lines.push(` ${currentModel ? `${currentModel.provider}/${currentModel.id}` : "(unavailable)"}`);
|
|
1128
|
+
break;
|
|
801
1129
|
}
|
|
802
|
-
const resolvedModel = resolveSubagentModelOverride(agent.model, currentModel, availableModels, preferredProvider);
|
|
803
|
-
const source = `${formatModelSource(agent, currentModel)}${agent.disabled ? "; disabled" : ""}`;
|
|
804
1130
|
lines.push(name);
|
|
805
1131
|
lines.push(" model:");
|
|
806
1132
|
lines.push(` ${resolvedModel ?? "(unresolved)"}`);
|
|
807
1133
|
lines.push(` source: ${source}`);
|
|
1134
|
+
lines.push(` thinking: ${effectiveThinking ?? "default"}`);
|
|
1135
|
+
if (agent.fallbackModels?.length) {
|
|
1136
|
+
lines.push(" fallback models:");
|
|
1137
|
+
for (const fallback of agent.fallbackModels) {
|
|
1138
|
+
lines.push(` ${resolveSubagentModelOverride(fallback, currentModel, availableModels, agent.modelProvider ?? preferredProvider) ?? fallback}`);
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
if (agent.override) {
|
|
1142
|
+
lines.push(" override file:");
|
|
1143
|
+
lines.push(` ${agent.override.path}`);
|
|
1144
|
+
}
|
|
1145
|
+
if (agent.model && resolvedModel && agent.model !== resolvedModel) {
|
|
1146
|
+
lines.push(" requested model setting:");
|
|
1147
|
+
lines.push(` ${agent.model}`);
|
|
1148
|
+
}
|
|
808
1149
|
lines.push("");
|
|
809
1150
|
}
|
|
810
1151
|
|
|
1152
|
+
const availableFullIds = availableModels.map((m) => m.fullId).sort();
|
|
1153
|
+
if (!requestedAgent && availableFullIds.length > 0) {
|
|
1154
|
+
lines.push("Available models in this session's registry (copy an exact provider/id when passing model):");
|
|
1155
|
+
lines.push("");
|
|
1156
|
+
const shown = availableFullIds.slice(0, 80);
|
|
1157
|
+
for (const fullId of shown) lines.push(` ${fullId}`);
|
|
1158
|
+
if (availableFullIds.length > shown.length) lines.push(` ... and ${availableFullIds.length - shown.length} more`);
|
|
1159
|
+
lines.push("");
|
|
1160
|
+
lines.push("Use an exact provider/id from this list when you pass model; bare ids resolve only when unique in the registry.");
|
|
1161
|
+
}
|
|
1162
|
+
if (!requestedAgent) appendAgentDiagnosticLines(lines, diagnosticsForScope(discovered.agentDiagnostics, scope));
|
|
811
1163
|
return result(lines.join("\n"));
|
|
812
1164
|
}
|
|
813
1165
|
|
|
@@ -815,7 +1167,7 @@ function handleGet(params: ManagementParams, ctx: ManagementContext): AgentToolR
|
|
|
815
1167
|
if (!params.agent) return result("Specify 'agent' for get.", true);
|
|
816
1168
|
const scope = normalizeListScope(params.agentScope);
|
|
817
1169
|
if (!scope) return result("agentScope must be 'user', 'project', or 'both' for get.", true);
|
|
818
|
-
const discovered = discoverAgentsAll(ctx.cwd);
|
|
1170
|
+
const discovered = discoverAgentsAll(ctx.cwd, ctx.model?.provider);
|
|
819
1171
|
const matches = findAgentsInDiscovery(params.agent, discovered, scope);
|
|
820
1172
|
const diagnostics = diagnosticsForScope(discovered.agentDiagnostics, scope);
|
|
821
1173
|
const rawName = params.agent.trim();
|
|
@@ -833,9 +1185,9 @@ function handleGet(params: ManagementParams, ctx: ManagementContext): AgentToolR
|
|
|
833
1185
|
|
|
834
1186
|
export function handleCreate(params: ManagementParams, ctx: ManagementContext): AgentToolResult<Details> {
|
|
835
1187
|
const parsedConfig = configObject(params.config);
|
|
836
|
-
if (parsedConfig.error) return result(parsedConfig.
|
|
1188
|
+
if (parsedConfig.status === "error") return result(parsedConfig.message, true);
|
|
1189
|
+
if (parsedConfig.status === "missing") return result("config required for create.", true);
|
|
837
1190
|
const cfg = parsedConfig.value;
|
|
838
|
-
if (!cfg) return result("config required for create.", true);
|
|
839
1191
|
if (typeof cfg.name !== "string" || !cfg.name.trim()) return result("config.name is required and must be a non-empty string.", true);
|
|
840
1192
|
if (typeof cfg.description !== "string" || !cfg.description.trim()) return result("config.description is required and must be a non-empty string.", true);
|
|
841
1193
|
const name = sanitizeName(cfg.name);
|
|
@@ -845,7 +1197,7 @@ export function handleCreate(params: ManagementParams, ctx: ManagementContext):
|
|
|
845
1197
|
const runtimeName = buildRuntimeName(name, parsedPackage.packageName);
|
|
846
1198
|
const scopeRaw = cfg.scope ?? "user";
|
|
847
1199
|
if (scopeRaw !== "user" && scopeRaw !== "project") return result("config.scope must be 'user' or 'project'.", true);
|
|
848
|
-
const scope = scopeRaw
|
|
1200
|
+
const scope = scopeRaw;
|
|
849
1201
|
if (hasKey(cfg, "steps")) return result("Durable chain definitions were removed; use workflowScript or /prompt-workflow for repeatable workflows.", true);
|
|
850
1202
|
const d = discoverAgentsAll(ctx.cwd);
|
|
851
1203
|
const projectConfigDir = getProjectConfigDir(ctx.cwd);
|
|
@@ -866,10 +1218,13 @@ export function handleCreate(params: ManagementParams, ctx: ManagementContext):
|
|
|
866
1218
|
systemPrompt: "",
|
|
867
1219
|
systemPromptMode: defaultSystemPromptMode(name),
|
|
868
1220
|
inheritProjectContext: defaultInheritProjectContext(name),
|
|
1221
|
+
inheritGlobalContext: false,
|
|
869
1222
|
inheritSkills: defaultInheritSkills(),
|
|
870
1223
|
};
|
|
871
1224
|
const applyError = applyAgentConfig(agent, cfg);
|
|
872
1225
|
if (applyError) return result(applyError, true);
|
|
1226
|
+
const profileError = validateCodeOwnedProfileRunner(agent);
|
|
1227
|
+
if (profileError) return result(profileError, true);
|
|
873
1228
|
const mw = modelWarning(ctx, agent.model);
|
|
874
1229
|
if (mw) warnings.push(mw);
|
|
875
1230
|
const fmw = fallbackModelsWarning(ctx, agent.fallbackModels);
|
|
@@ -883,9 +1238,9 @@ export function handleCreate(params: ManagementParams, ctx: ManagementContext):
|
|
|
883
1238
|
export function handleUpdate(params: ManagementParams, ctx: ManagementContext): AgentToolResult<Details> {
|
|
884
1239
|
if (!params.agent) return result("Specify 'agent' for update.", true);
|
|
885
1240
|
const parsedConfig = configObject(params.config);
|
|
886
|
-
if (parsedConfig.error) return result(parsedConfig.
|
|
1241
|
+
if (parsedConfig.status === "error") return result(parsedConfig.message, true);
|
|
1242
|
+
if (parsedConfig.status === "missing") return result("config required for update.", true);
|
|
887
1243
|
const cfg = parsedConfig.value;
|
|
888
|
-
if (!cfg) return result("config required for update.", true);
|
|
889
1244
|
if (hasKey(cfg, "steps")) return result("Durable chain definitions were removed; use workflowScript or /prompt-workflow for repeatable workflows.", true);
|
|
890
1245
|
const warnings: string[] = [];
|
|
891
1246
|
const scopeHint = asDisambiguationScope(params.agentScope);
|
|
@@ -921,6 +1276,8 @@ export function handleUpdate(params: ManagementParams, ctx: ManagementContext):
|
|
|
921
1276
|
if (newPackageName !== undefined) updated.packageName = newPackageName;
|
|
922
1277
|
else delete updated.packageName;
|
|
923
1278
|
updated.name = buildRuntimeName(newLocalName, newPackageName);
|
|
1279
|
+
const profileError = validateCodeOwnedProfileRunner(updated);
|
|
1280
|
+
if (profileError) return result(profileError, true);
|
|
924
1281
|
if (hasKey(cfg, "description")) updated.description = (cfg.description as string).trim();
|
|
925
1282
|
if (hasKey(cfg, "model")) {
|
|
926
1283
|
const mw = modelWarning(ctx, updated.model);
|
|
@@ -1334,7 +1691,7 @@ function handleReset(params: ManagementParams, ctx: ManagementContext): AgentToo
|
|
|
1334
1691
|
}
|
|
1335
1692
|
|
|
1336
1693
|
export function handleManagementAction(action: string, params: ManagementParams, ctx: ManagementContext): AgentToolResult<Details> {
|
|
1337
|
-
switch (action
|
|
1694
|
+
switch (action) {
|
|
1338
1695
|
case "list": return handleList(params, ctx);
|
|
1339
1696
|
case "get": return handleGet(params, ctx);
|
|
1340
1697
|
case "models": return handleModels(params, ctx);
|