@xzzpig/pi-subagents 0.7.0 → 0.8.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 +13 -4
- package/README.md +1 -1
- package/agents/reviewer.md +12 -2
- package/docs/agents.md +4 -4
- package/docs/configuration.md +6 -6
- package/docs/extension-api.md +14 -4
- package/docs/models.md +47 -6
- package/docs/observability.md +14 -3
- package/docs/tool-reference.md +21 -6
- package/docs/workflows.md +7 -1
- package/index.ts +10 -1
- package/package.json +3 -3
- package/prompts/council.md +19 -7
- package/prompts/parallel-review.md +5 -1
- package/prompts/review-loop.md +9 -5
- package/skills/council-mode/SKILL.md +50 -26
- package/skills/pi-subagents/SKILL.md +5 -1
- package/skills/pi-subagents/references/constraints-and-recipes.md +16 -1
- package/skills/pi-subagents/references/execution-controls.md +13 -4
- package/skills/pi-subagents/references/multi-lane-orchestration.md +3 -3
- package/skills/pi-subagents/references/prompting-and-roles.md +14 -7
- package/src/agents/agent-management.ts +115 -14
- package/src/agents/agent-serializer.ts +4 -2
- package/src/agents/agents.ts +226 -48
- package/src/api/external-job-provider.ts +10 -1
- package/src/api/preflight.ts +52 -19
- package/src/api/project-panes.ts +2 -0
- package/src/extension/doctor.ts +10 -0
- package/src/extension/fanout-child.ts +3 -2
- package/src/extension/index.ts +24 -4
- package/src/extension/public-execution.ts +12 -9
- package/src/extension/rpc.ts +77 -3
- package/src/extension/schemas.ts +7 -1
- package/src/extension/tool-description.ts +9 -6
- package/src/extension/tool-result.ts +19 -0
- package/src/inspectors/herdr/client.ts +3 -3
- package/src/inspectors/herdr/focus.ts +55 -0
- package/src/inspectors/herdr/project-panes.ts +228 -44
- package/src/integrations/herdr-status.ts +26 -4
- package/src/runs/background/async-execution.ts +146 -17
- package/src/runs/background/async-job-tracker.ts +33 -14
- package/src/runs/background/async-resume.ts +23 -2
- package/src/runs/background/async-retention.ts +1 -1
- package/src/runs/background/async-status.ts +10 -0
- package/src/runs/background/chain-root-attachment.ts +5 -0
- package/src/runs/background/control-channel.ts +98 -10
- package/src/runs/background/notify.ts +62 -1
- package/src/runs/background/result-watcher.ts +4 -3
- package/src/runs/background/run-status.ts +15 -1
- package/src/runs/background/stale-run-reconciler.ts +3 -0
- package/src/runs/background/subagent-runner.ts +333 -48
- package/src/runs/background/wait-completions.ts +2 -0
- package/src/runs/background/wait-tool.ts +4 -3
- package/src/runs/foreground/async-stop-action.ts +23 -2
- package/src/runs/foreground/execution.ts +148 -13
- package/src/runs/foreground/foreground-history.ts +3 -2
- package/src/runs/foreground/subagent-executor.ts +417 -50
- package/src/runs/foreground/workflow-detach-reconcile.ts +18 -6
- package/src/runs/shared/acceptance.ts +11 -5
- package/src/runs/shared/agent-contract.ts +1 -1
- package/src/runs/shared/child-identity.ts +36 -0
- package/src/runs/shared/completion-guard.ts +52 -2
- package/src/runs/shared/dynamic-fanout.ts +1 -1
- package/src/runs/shared/extension-bindings.ts +78 -0
- package/src/runs/shared/external-cli-runner.ts +2 -0
- 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/model-exclusions.ts +2 -1
- package/src/runs/shared/model-fallback.ts +48 -22
- package/src/runs/shared/model-scope.ts +106 -39
- package/src/runs/shared/mutation-evidence.ts +145 -0
- package/src/runs/shared/orca-progress-tabs.ts +71 -9
- package/src/runs/shared/parallel-utils.ts +15 -0
- package/src/runs/shared/pi-args.ts +78 -1
- package/src/runs/shared/structured-output.ts +18 -4
- package/src/runs/shared/subagent-prompt-runtime.ts +48 -15
- package/src/runs/shared/tool-availability.ts +1 -3
- package/src/shared/launch-contract.ts +12 -5
- package/src/shared/settings.ts +6 -1
- package/src/shared/thinking-ceiling.ts +52 -0
- package/src/shared/types.ts +120 -5
- package/src/tui/fleet-status.ts +66 -13
- package/src/tui/render.ts +5 -4
- package/src/watchdog/permission-arbiter.ts +59 -52
- package/src/workflows/scripted-workflow.ts +156 -12
package/src/agents/agents.ts
CHANGED
|
@@ -22,6 +22,7 @@ import { parseMemoryFrontmatter } from "./agent-memory.ts";
|
|
|
22
22
|
import { resolveTurnBudgetConfig } from "../runs/shared/turn-budget.ts";
|
|
23
23
|
import { validateAcceptanceInput } from "../runs/shared/acceptance.ts";
|
|
24
24
|
import { validatePermissionRules, type PermissionRules } from "../runs/shared/permissions.ts";
|
|
25
|
+
import { parseThinkingLevel, type ThinkingLevel } from "../shared/thinking-ceiling.ts";
|
|
25
26
|
|
|
26
27
|
export type AgentScope = "user" | "project" | "both";
|
|
27
28
|
|
|
@@ -50,9 +51,13 @@ export function defaultInheritSkills(): boolean {
|
|
|
50
51
|
|
|
51
52
|
export interface BuiltinAgentOverrideBase {
|
|
52
53
|
description?: string;
|
|
54
|
+
output?: string;
|
|
53
55
|
outputMode?: OutputMode;
|
|
56
|
+
defaultReads?: string[];
|
|
54
57
|
model?: string;
|
|
58
|
+
modelProvider?: string;
|
|
55
59
|
fallbackModels?: string[];
|
|
60
|
+
fast?: boolean;
|
|
56
61
|
thinking?: string | false;
|
|
57
62
|
systemPromptMode: SystemPromptMode;
|
|
58
63
|
inheritProjectContext: boolean;
|
|
@@ -73,9 +78,13 @@ export interface BuiltinAgentOverrideBase {
|
|
|
73
78
|
|
|
74
79
|
interface BuiltinAgentOverrideConfig {
|
|
75
80
|
description?: string;
|
|
81
|
+
output?: string | false;
|
|
76
82
|
outputMode?: OutputMode;
|
|
83
|
+
defaultReads?: string[] | false;
|
|
77
84
|
model?: string | false;
|
|
85
|
+
defaultProvider?: string | false;
|
|
78
86
|
fallbackModels?: string[] | false;
|
|
87
|
+
fast?: boolean;
|
|
79
88
|
thinking?: string | false;
|
|
80
89
|
systemPromptMode?: SystemPromptMode;
|
|
81
90
|
inheritProjectContext?: boolean;
|
|
@@ -103,6 +112,7 @@ export interface AgentModelSourceInfo {
|
|
|
103
112
|
scope: "user" | "project";
|
|
104
113
|
path: string;
|
|
105
114
|
model: string;
|
|
115
|
+
defaultProvider?: string;
|
|
106
116
|
}
|
|
107
117
|
|
|
108
118
|
export interface AgentConfig {
|
|
@@ -110,12 +120,17 @@ export interface AgentConfig {
|
|
|
110
120
|
runner?: AgentRunnerConfig;
|
|
111
121
|
localName?: string;
|
|
112
122
|
packageName?: string;
|
|
123
|
+
packageSourceName?: string;
|
|
124
|
+
packageSourceVersion?: string;
|
|
125
|
+
packageSourceRoot?: string;
|
|
113
126
|
description: string;
|
|
114
127
|
aliases?: string[];
|
|
115
128
|
tools?: string[];
|
|
116
129
|
mcpDirectTools?: string[];
|
|
117
130
|
model?: string;
|
|
131
|
+
modelProvider?: string;
|
|
118
132
|
fallbackModels?: string[];
|
|
133
|
+
fast?: boolean;
|
|
119
134
|
thinking?: string | false;
|
|
120
135
|
systemPromptMode: SystemPromptMode;
|
|
121
136
|
inheritProjectContext: boolean;
|
|
@@ -151,6 +166,7 @@ export interface AgentConfig {
|
|
|
151
166
|
extraFields?: Record<string, string>;
|
|
152
167
|
override?: BuiltinAgentOverrideInfo;
|
|
153
168
|
modelSource?: AgentModelSourceInfo;
|
|
169
|
+
maxThinking?: ThinkingLevel;
|
|
154
170
|
}
|
|
155
171
|
|
|
156
172
|
type ProjectRootResolution = "nearest" | "git-root";
|
|
@@ -158,7 +174,9 @@ type ProjectRootResolution = "nearest" | "git-root";
|
|
|
158
174
|
interface SubagentSettings {
|
|
159
175
|
overrides: Record<string, BuiltinAgentOverrideConfig>;
|
|
160
176
|
defaultModel?: string;
|
|
177
|
+
defaultProvider?: string;
|
|
161
178
|
defaultThinking?: string;
|
|
179
|
+
maxThinking?: ThinkingLevel;
|
|
162
180
|
defaultExtensions?: string[];
|
|
163
181
|
disableBuiltins?: boolean;
|
|
164
182
|
disableThinking?: boolean;
|
|
@@ -252,14 +270,22 @@ interface AgentDiscoveryResult {
|
|
|
252
270
|
projectAgentsDir: string | null;
|
|
253
271
|
modelScope?: ModelScopeConfig;
|
|
254
272
|
injectAgents?: string[];
|
|
273
|
+
maxThinking?: ThinkingLevel;
|
|
255
274
|
}
|
|
256
275
|
|
|
257
276
|
function getUserChainDir(): string {
|
|
258
277
|
return path.join(getAgentDir(), "chains");
|
|
259
278
|
}
|
|
260
279
|
|
|
280
|
+
interface PackageSubagentPath {
|
|
281
|
+
dir: string;
|
|
282
|
+
packageName?: string;
|
|
283
|
+
packageVersion?: string;
|
|
284
|
+
packageRoot: string;
|
|
285
|
+
}
|
|
286
|
+
|
|
261
287
|
interface PackageSubagentPaths {
|
|
262
|
-
agents:
|
|
288
|
+
agents: PackageSubagentPath[];
|
|
263
289
|
chains: string[];
|
|
264
290
|
}
|
|
265
291
|
|
|
@@ -406,18 +432,30 @@ function stringArray(value: unknown): string[] {
|
|
|
406
432
|
return value.filter((entry): entry is string => typeof entry === "string" && entry.trim().length > 0);
|
|
407
433
|
}
|
|
408
434
|
|
|
435
|
+
function packageMetadata(pkg: Record<string, unknown>, packageRoot: string): Omit<PackageSubagentPath, "dir"> {
|
|
436
|
+
const name = typeof pkg.name === "string" && pkg.name.trim() ? pkg.name.trim() : undefined;
|
|
437
|
+
const version = typeof pkg.version === "string" && pkg.version.trim() ? pkg.version.trim() : undefined;
|
|
438
|
+
return {
|
|
439
|
+
packageRoot,
|
|
440
|
+
...(name ? { packageName: name } : {}),
|
|
441
|
+
...(version ? { packageVersion: version } : {}),
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
|
|
409
445
|
function extractSubagentPathsFromPackageRoot(packageRoot: string): PackageSubagentPaths {
|
|
410
446
|
const packageJsonPath = path.join(packageRoot, "package.json");
|
|
411
447
|
const pkg = readJsonFileBestEffort(packageJsonPath);
|
|
412
|
-
if (!pkg) return { agents: [], chains: [] };
|
|
448
|
+
if (!pkg || typeof pkg !== "object" || Array.isArray(pkg)) return { agents: [], chains: [] };
|
|
449
|
+
const pkgRecord = pkg as Record<string, unknown>;
|
|
450
|
+
const metadata = packageMetadata(pkgRecord, packageRoot);
|
|
413
451
|
|
|
414
452
|
const roots: Record<string, unknown>[] = [];
|
|
415
|
-
const piSubagents =
|
|
453
|
+
const piSubagents = pkgRecord["pi-subagents"];
|
|
416
454
|
if (piSubagents && typeof piSubagents === "object" && !Array.isArray(piSubagents)) {
|
|
417
455
|
roots.push(piSubagents as Record<string, unknown>);
|
|
418
456
|
}
|
|
419
457
|
|
|
420
|
-
const pi =
|
|
458
|
+
const pi = pkgRecord.pi;
|
|
421
459
|
if (pi && typeof pi === "object" && !Array.isArray(pi)) {
|
|
422
460
|
const subagents = (pi as { subagents?: unknown }).subagents;
|
|
423
461
|
if (subagents && typeof subagents === "object" && !Array.isArray(subagents)) {
|
|
@@ -425,10 +463,10 @@ function extractSubagentPathsFromPackageRoot(packageRoot: string): PackageSubage
|
|
|
425
463
|
}
|
|
426
464
|
}
|
|
427
465
|
|
|
428
|
-
const agents:
|
|
466
|
+
const agents: PackageSubagentPath[] = [];
|
|
429
467
|
const chains: string[] = [];
|
|
430
468
|
for (const root of roots) {
|
|
431
|
-
for (const entry of stringArray(root.agents)) agents.push(path.resolve(packageRoot, entry));
|
|
469
|
+
for (const entry of stringArray(root.agents)) agents.push({ dir: path.resolve(packageRoot, entry), ...metadata });
|
|
432
470
|
for (const entry of stringArray(root.chains)) chains.push(path.resolve(packageRoot, entry));
|
|
433
471
|
}
|
|
434
472
|
return { agents, chains };
|
|
@@ -520,17 +558,17 @@ function collectPackageSubagentPaths(cwd: string, options: { includeUser: boolea
|
|
|
520
558
|
const seenRoots = new Set<string>();
|
|
521
559
|
const seenAgents = new Set<string>();
|
|
522
560
|
const seenChains = new Set<string>();
|
|
523
|
-
const agents:
|
|
561
|
+
const agents: PackageSubagentPath[] = [];
|
|
524
562
|
const chains: string[] = [];
|
|
525
563
|
for (const packageRoot of packageRoots) {
|
|
526
564
|
const resolvedRoot = path.resolve(packageRoot);
|
|
527
565
|
if (seenRoots.has(resolvedRoot)) continue;
|
|
528
566
|
seenRoots.add(resolvedRoot);
|
|
529
567
|
const paths = extractSubagentPathsFromPackageRoot(resolvedRoot);
|
|
530
|
-
for (const
|
|
531
|
-
if (seenAgents.has(
|
|
532
|
-
seenAgents.add(
|
|
533
|
-
agents.push(
|
|
568
|
+
for (const agentPath of paths.agents) {
|
|
569
|
+
if (seenAgents.has(agentPath.dir)) continue;
|
|
570
|
+
seenAgents.add(agentPath.dir);
|
|
571
|
+
agents.push(agentPath);
|
|
534
572
|
}
|
|
535
573
|
for (const chainDir of paths.chains) {
|
|
536
574
|
if (seenChains.has(chainDir)) continue;
|
|
@@ -614,9 +652,13 @@ function arraysEqual(a: string[] | undefined, b: string[] | undefined): boolean
|
|
|
614
652
|
function cloneOverrideBase(agent: AgentConfig): BuiltinAgentOverrideBase {
|
|
615
653
|
return {
|
|
616
654
|
description: agent.description,
|
|
655
|
+
...(agent.output !== undefined ? { output: agent.output } : {}),
|
|
617
656
|
...(agent.outputMode !== undefined ? { outputMode: agent.outputMode } : {}),
|
|
657
|
+
...(agent.defaultReads !== undefined ? { defaultReads: [...agent.defaultReads] } : {}),
|
|
618
658
|
...(agent.model !== undefined ? { model: agent.model } : {}),
|
|
659
|
+
...(agent.modelProvider !== undefined ? { modelProvider: agent.modelProvider } : {}),
|
|
619
660
|
...(agent.fallbackModels ? { fallbackModels: [...agent.fallbackModels] } : {}),
|
|
661
|
+
...(agent.fast !== undefined ? { fast: agent.fast } : {}),
|
|
620
662
|
...(agent.thinking !== undefined ? { thinking: agent.thinking } : {}),
|
|
621
663
|
systemPromptMode: agent.systemPromptMode,
|
|
622
664
|
inheritProjectContext: agent.inheritProjectContext,
|
|
@@ -639,11 +681,15 @@ function cloneOverrideBase(agent: AgentConfig): BuiltinAgentOverrideBase {
|
|
|
639
681
|
function cloneOverrideValue(override: BuiltinAgentOverrideConfig): BuiltinAgentOverrideConfig {
|
|
640
682
|
return {
|
|
641
683
|
...(override.description !== undefined ? { description: override.description } : {}),
|
|
684
|
+
...(override.output !== undefined ? { output: override.output } : {}),
|
|
642
685
|
...(override.outputMode !== undefined ? { outputMode: override.outputMode } : {}),
|
|
686
|
+
...(override.defaultReads !== undefined ? { defaultReads: override.defaultReads === false ? false : [...override.defaultReads] } : {}),
|
|
643
687
|
...(override.model !== undefined ? { model: override.model } : {}),
|
|
688
|
+
...(override.defaultProvider !== undefined ? { defaultProvider: override.defaultProvider } : {}),
|
|
644
689
|
...(override.fallbackModels !== undefined
|
|
645
690
|
? { fallbackModels: override.fallbackModels === false ? false : [...override.fallbackModels] }
|
|
646
691
|
: {}),
|
|
692
|
+
...(override.fast !== undefined ? { fast: override.fast } : {}),
|
|
647
693
|
...(override.thinking !== undefined ? { thinking: override.thinking } : {}),
|
|
648
694
|
...(override.systemPromptMode !== undefined ? { systemPromptMode: override.systemPromptMode } : {}),
|
|
649
695
|
...(override.inheritProjectContext !== undefined ? { inheritProjectContext: override.inheritProjectContext } : {}),
|
|
@@ -820,6 +866,11 @@ function parseBuiltinOverrideEntry(
|
|
|
820
866
|
}
|
|
821
867
|
}
|
|
822
868
|
|
|
869
|
+
if ("output" in input) {
|
|
870
|
+
if ((typeof input.output === "string" && input.output.trim()) || input.output === false) override.output = input.output;
|
|
871
|
+
else throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'output'; expected a non-empty string or false.`);
|
|
872
|
+
}
|
|
873
|
+
|
|
823
874
|
if ("outputMode" in input) {
|
|
824
875
|
if (input.outputMode === "inline" || input.outputMode === "file-only") {
|
|
825
876
|
override.outputMode = input.outputMode;
|
|
@@ -833,6 +884,11 @@ function parseBuiltinOverrideEntry(
|
|
|
833
884
|
else throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'model'; expected a string or false.`);
|
|
834
885
|
}
|
|
835
886
|
|
|
887
|
+
if ("fast" in input) {
|
|
888
|
+
if (typeof input.fast === "boolean") override.fast = input.fast;
|
|
889
|
+
else throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'fast'; expected a boolean.`);
|
|
890
|
+
}
|
|
891
|
+
|
|
836
892
|
if ("thinking" in input) {
|
|
837
893
|
if (typeof input.thinking === "string" || input.thinking === false) override.thinking = input.thinking;
|
|
838
894
|
else throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'thinking'; expected a string or false.`);
|
|
@@ -909,9 +965,18 @@ function parseBuiltinOverrideEntry(
|
|
|
909
965
|
else throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'systemPrompt'; expected a string.`);
|
|
910
966
|
}
|
|
911
967
|
|
|
968
|
+
const defaultReads = parseOverrideStringArrayOrFalse(input.defaultReads, { filePath, name, field: "defaultReads" });
|
|
969
|
+
if (defaultReads !== undefined) override.defaultReads = defaultReads;
|
|
970
|
+
|
|
912
971
|
const fallbackModels = parseOverrideStringArrayOrFalse(input.fallbackModels, { filePath, name, field: "fallbackModels" });
|
|
913
972
|
if (fallbackModels !== undefined) override.fallbackModels = fallbackModels;
|
|
914
973
|
|
|
974
|
+
if ("defaultProvider" in input) {
|
|
975
|
+
if (input.defaultProvider === false) override.defaultProvider = false;
|
|
976
|
+
else if (typeof input.defaultProvider === "string" && input.defaultProvider.trim()) override.defaultProvider = input.defaultProvider.trim();
|
|
977
|
+
else throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'defaultProvider'; expected a non-empty string or false.`);
|
|
978
|
+
}
|
|
979
|
+
|
|
915
980
|
const skills = parseOverrideStringArrayOrFalse(input.skills, { filePath, name, field: "skills" });
|
|
916
981
|
if (skills !== undefined) override.skills = skills;
|
|
917
982
|
|
|
@@ -958,6 +1023,14 @@ function readSubagentSettings(filePath: string | null): SubagentSettings {
|
|
|
958
1023
|
throw new Error(`Subagent settings in '${filePath}' have invalid 'defaultModel'; expected a non-empty string.`);
|
|
959
1024
|
}
|
|
960
1025
|
}
|
|
1026
|
+
let defaultProvider: string | undefined;
|
|
1027
|
+
if ("defaultProvider" in subagentsObject) {
|
|
1028
|
+
if (typeof subagentsObject.defaultProvider === "string" && subagentsObject.defaultProvider.trim()) {
|
|
1029
|
+
defaultProvider = subagentsObject.defaultProvider.trim();
|
|
1030
|
+
} else {
|
|
1031
|
+
throw new Error(`Subagent settings in '${filePath}' have invalid 'defaultProvider'; expected a non-empty string.`);
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
961
1034
|
let defaultThinking: string | undefined;
|
|
962
1035
|
if ("defaultThinking" in subagentsObject) {
|
|
963
1036
|
if (typeof subagentsObject.defaultThinking === "string" && subagentsObject.defaultThinking.trim()) {
|
|
@@ -966,6 +1039,14 @@ function readSubagentSettings(filePath: string | null): SubagentSettings {
|
|
|
966
1039
|
throw new Error(`Subagent settings in '${filePath}' have invalid 'defaultThinking'; expected a non-empty string.`);
|
|
967
1040
|
}
|
|
968
1041
|
}
|
|
1042
|
+
let maxThinking: ThinkingLevel | undefined;
|
|
1043
|
+
if ("maxThinking" in subagentsObject) {
|
|
1044
|
+
try {
|
|
1045
|
+
maxThinking = parseThinkingLevel(subagentsObject.maxThinking, `'${filePath}' subagents.maxThinking`);
|
|
1046
|
+
} catch (error) {
|
|
1047
|
+
throw new Error(`Subagent settings in '${filePath}' have invalid 'maxThinking'; expected one of off, minimal, low, medium, high, xhigh, or max.`, { cause: error instanceof Error ? error : undefined });
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
969
1050
|
let defaultExtensions: string[] | undefined;
|
|
970
1051
|
if ("defaultExtensions" in subagentsObject) {
|
|
971
1052
|
if (!Array.isArray(subagentsObject.defaultExtensions)
|
|
@@ -989,7 +1070,9 @@ function readSubagentSettings(filePath: string | null): SubagentSettings {
|
|
|
989
1070
|
const parsedSettings: SubagentSettings = {
|
|
990
1071
|
overrides: parsed,
|
|
991
1072
|
...(defaultModel !== undefined ? { defaultModel } : {}),
|
|
1073
|
+
...(defaultProvider !== undefined ? { defaultProvider } : {}),
|
|
992
1074
|
...(defaultThinking !== undefined ? { defaultThinking } : {}),
|
|
1075
|
+
...(maxThinking !== undefined ? { maxThinking } : {}),
|
|
993
1076
|
...(defaultExtensions !== undefined ? { defaultExtensions } : {}),
|
|
994
1077
|
...(disableBuiltins !== undefined ? { disableBuiltins } : {}),
|
|
995
1078
|
...(disableThinking !== undefined ? { disableThinking } : {}),
|
|
@@ -1006,25 +1089,39 @@ function readSubagentSettings(filePath: string | null): SubagentSettings {
|
|
|
1006
1089
|
return parsedSettings;
|
|
1007
1090
|
}
|
|
1008
1091
|
|
|
1092
|
+
function resolveSubagentDefaultProvider(
|
|
1093
|
+
userSettings: SubagentSettings,
|
|
1094
|
+
projectSettings: SubagentSettings,
|
|
1095
|
+
projectSettingsPath: string | null,
|
|
1096
|
+
): string | undefined {
|
|
1097
|
+
if (projectSettingsPath && projectSettings.defaultProvider !== undefined) return projectSettings.defaultProvider;
|
|
1098
|
+
return userSettings.defaultProvider;
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1009
1101
|
function resolveSubagentDefaultModel(
|
|
1010
1102
|
userSettings: SubagentSettings,
|
|
1011
1103
|
projectSettings: SubagentSettings,
|
|
1012
1104
|
userSettingsPath: string,
|
|
1013
1105
|
projectSettingsPath: string | null,
|
|
1106
|
+
defaultProvider: string | undefined,
|
|
1014
1107
|
): AgentModelSourceInfo | undefined {
|
|
1015
1108
|
if (projectSettingsPath && projectSettings.defaultModel !== undefined) {
|
|
1016
|
-
return { type: "subagents.defaultModel", scope: "project", path: projectSettingsPath, model: projectSettings.defaultModel };
|
|
1109
|
+
return { type: "subagents.defaultModel", scope: "project", path: projectSettingsPath, model: projectSettings.defaultModel, ...(defaultProvider ? { defaultProvider } : {}) };
|
|
1017
1110
|
}
|
|
1018
1111
|
return userSettings.defaultModel !== undefined
|
|
1019
|
-
? { type: "subagents.defaultModel", scope: "user", path: userSettingsPath, model: userSettings.defaultModel }
|
|
1112
|
+
? { type: "subagents.defaultModel", scope: "user", path: userSettingsPath, model: userSettings.defaultModel, ...(defaultProvider ? { defaultProvider } : {}) }
|
|
1020
1113
|
: undefined;
|
|
1021
1114
|
}
|
|
1022
1115
|
|
|
1023
|
-
function applySubagentDefaultModel(agents: AgentConfig[], defaultModel: AgentModelSourceInfo | undefined): AgentConfig[] {
|
|
1024
|
-
if (!defaultModel) return agents;
|
|
1116
|
+
function applySubagentDefaultModel(agents: AgentConfig[], defaultModel: AgentModelSourceInfo | undefined, defaultProvider: string | undefined): AgentConfig[] {
|
|
1117
|
+
if (!defaultModel && !defaultProvider) return agents;
|
|
1025
1118
|
return agents.map((agent) => {
|
|
1026
|
-
if (agent.model !== undefined) return agent;
|
|
1027
|
-
const next = {
|
|
1119
|
+
if (agent.model !== undefined && (agent.modelProvider !== undefined || !defaultProvider)) return agent;
|
|
1120
|
+
const next = {
|
|
1121
|
+
...agent,
|
|
1122
|
+
...(agent.model === undefined && defaultModel ? { model: defaultModel.model, modelSource: defaultModel } : {}),
|
|
1123
|
+
...(defaultProvider ? { modelProvider: defaultProvider } : {}),
|
|
1124
|
+
};
|
|
1028
1125
|
const frontmatterFields = agentFrontmatterFields.get(agent);
|
|
1029
1126
|
if (frontmatterFields) agentFrontmatterFields.set(next, frontmatterFields);
|
|
1030
1127
|
return next;
|
|
@@ -1051,6 +1148,20 @@ function applySubagentDefaultThinking(agents: AgentConfig[], defaultThinking: st
|
|
|
1051
1148
|
});
|
|
1052
1149
|
}
|
|
1053
1150
|
|
|
1151
|
+
function resolveSubagentMaxThinking(
|
|
1152
|
+
userSettings: SubagentSettings,
|
|
1153
|
+
projectSettings: SubagentSettings,
|
|
1154
|
+
projectSettingsPath: string | null,
|
|
1155
|
+
): ThinkingLevel | undefined {
|
|
1156
|
+
if (projectSettingsPath && projectSettings.maxThinking !== undefined) return projectSettings.maxThinking;
|
|
1157
|
+
return userSettings.maxThinking;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
function applySubagentMaxThinking(agents: AgentConfig[], maxThinking: ThinkingLevel | undefined): AgentConfig[] {
|
|
1161
|
+
if (maxThinking === undefined) return agents;
|
|
1162
|
+
return agents.map((agent) => agent.maxThinking === maxThinking ? agent : { ...agent, maxThinking });
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1054
1165
|
function resolveSubagentDefaultExtensions(
|
|
1055
1166
|
userSettings: SubagentSettings,
|
|
1056
1167
|
projectSettings: SubagentSettings,
|
|
@@ -1074,11 +1185,12 @@ function applySubagentDefaultExtensions(agents: AgentConfig[], defaultExtensions
|
|
|
1074
1185
|
function applySubagentDefaults(
|
|
1075
1186
|
agents: AgentConfig[],
|
|
1076
1187
|
defaultModel: AgentModelSourceInfo | undefined,
|
|
1188
|
+
defaultProvider: string | undefined,
|
|
1077
1189
|
defaultThinking: string | undefined,
|
|
1078
1190
|
defaultExtensions: string[] | undefined,
|
|
1079
1191
|
): AgentConfig[] {
|
|
1080
1192
|
return applySubagentDefaultExtensions(
|
|
1081
|
-
applySubagentDefaultThinking(applySubagentDefaultModel(agents, defaultModel), defaultThinking),
|
|
1193
|
+
applySubagentDefaultThinking(applySubagentDefaultModel(agents, defaultModel, defaultProvider), defaultThinking),
|
|
1082
1194
|
defaultExtensions,
|
|
1083
1195
|
);
|
|
1084
1196
|
}
|
|
@@ -1105,12 +1217,19 @@ function applyBuiltinOverride(
|
|
|
1105
1217
|
};
|
|
1106
1218
|
|
|
1107
1219
|
if (override.description !== undefined) next.description = override.description;
|
|
1220
|
+
if (override.output !== undefined) { if (override.output === false) delete next.output; else next.output = override.output; }
|
|
1108
1221
|
if (override.outputMode !== undefined) next.outputMode = override.outputMode;
|
|
1222
|
+
if (override.defaultReads !== undefined) { if (override.defaultReads === false) delete next.defaultReads; else next.defaultReads = [...override.defaultReads]; }
|
|
1109
1223
|
if (override.model !== undefined) {
|
|
1110
1224
|
if (override.model === false) delete next.model; else next.model = override.model;
|
|
1111
1225
|
delete next.modelSource;
|
|
1112
1226
|
}
|
|
1227
|
+
if (override.defaultProvider !== undefined) {
|
|
1228
|
+
if (override.defaultProvider === false) delete next.modelProvider;
|
|
1229
|
+
else next.modelProvider = override.defaultProvider;
|
|
1230
|
+
}
|
|
1113
1231
|
if (override.fallbackModels !== undefined) { if (override.fallbackModels === false) delete next.fallbackModels; else next.fallbackModels = [...override.fallbackModels]; }
|
|
1232
|
+
if (override.fast !== undefined) next.fast = override.fast;
|
|
1114
1233
|
if (override.thinking !== undefined) { if (override.thinking === false) delete next.thinking; else next.thinking = override.thinking; }
|
|
1115
1234
|
if (override.systemPromptMode !== undefined) next.systemPromptMode = override.systemPromptMode;
|
|
1116
1235
|
if (override.inheritProjectContext !== undefined) next.inheritProjectContext = override.inheritProjectContext;
|
|
@@ -1223,15 +1342,24 @@ function applyCustomAgentOverride(
|
|
|
1223
1342
|
mutable().description = override.description;
|
|
1224
1343
|
anyFilled = true;
|
|
1225
1344
|
}
|
|
1345
|
+
if (override.output !== undefined) {
|
|
1346
|
+
fill("output", ["output"], override.output === false ? undefined : override.output);
|
|
1347
|
+
}
|
|
1226
1348
|
if (override.outputMode !== undefined) {
|
|
1227
1349
|
fill("outputMode", ["outputMode"], override.outputMode);
|
|
1228
1350
|
}
|
|
1351
|
+
if (override.defaultReads !== undefined) {
|
|
1352
|
+
fill("defaultReads", ["defaultReads"], override.defaultReads === false ? undefined : [...override.defaultReads]);
|
|
1353
|
+
}
|
|
1229
1354
|
if (override.model !== undefined && !agentHasFrontmatterField(agent, "model")) {
|
|
1230
1355
|
const target = mutable();
|
|
1231
1356
|
if (override.model === false) delete target.model; else target.model = override.model;
|
|
1232
1357
|
delete target.modelSource;
|
|
1233
1358
|
anyFilled = true;
|
|
1234
1359
|
}
|
|
1360
|
+
if (override.defaultProvider !== undefined) {
|
|
1361
|
+
fill("modelProvider", ["modelProvider", "defaultProvider"], override.defaultProvider === false ? undefined : override.defaultProvider);
|
|
1362
|
+
}
|
|
1235
1363
|
if (override.fallbackModels !== undefined) {
|
|
1236
1364
|
fill(
|
|
1237
1365
|
"fallbackModels",
|
|
@@ -1239,6 +1367,9 @@ function applyCustomAgentOverride(
|
|
|
1239
1367
|
override.fallbackModels === false ? undefined : [...override.fallbackModels],
|
|
1240
1368
|
);
|
|
1241
1369
|
}
|
|
1370
|
+
if (override.fast !== undefined) {
|
|
1371
|
+
fill("fast", ["fast"], override.fast);
|
|
1372
|
+
}
|
|
1242
1373
|
if (override.thinking !== undefined) {
|
|
1243
1374
|
fill("thinking", ["thinking"], override.thinking === false ? undefined : override.thinking);
|
|
1244
1375
|
}
|
|
@@ -1257,7 +1388,8 @@ function applyCustomAgentOverride(
|
|
|
1257
1388
|
if (override.acceptanceRole !== undefined) {
|
|
1258
1389
|
fill("acceptanceRole", ["acceptanceRole"], override.acceptanceRole === false ? undefined : override.acceptanceRole);
|
|
1259
1390
|
}
|
|
1260
|
-
if (override.disabled !== undefined
|
|
1391
|
+
if (override.disabled !== undefined) {
|
|
1392
|
+
// Custom agent files cannot set `disabled`, so project overrides replace user overrides.
|
|
1261
1393
|
mutable().disabled = override.disabled;
|
|
1262
1394
|
anyFilled = true;
|
|
1263
1395
|
}
|
|
@@ -1286,7 +1418,7 @@ function applyCustomAgentOverride(
|
|
|
1286
1418
|
}
|
|
1287
1419
|
|
|
1288
1420
|
if (!anyFilled || !next) return agent;
|
|
1289
|
-
next.override = { ...meta, base: cloneOverrideBase(agent) };
|
|
1421
|
+
next.override = { ...meta, base: agent.override?.base ?? cloneOverrideBase(agent) };
|
|
1290
1422
|
const frontmatterFields = agentFrontmatterFields.get(agent);
|
|
1291
1423
|
if (frontmatterFields) agentFrontmatterFields.set(next, frontmatterFields);
|
|
1292
1424
|
return next;
|
|
@@ -1299,24 +1431,25 @@ function applyCustomAgentOverrides(
|
|
|
1299
1431
|
userSettingsPath: string,
|
|
1300
1432
|
projectSettingsPath: string | null,
|
|
1301
1433
|
): AgentConfig[] {
|
|
1434
|
+
// Apply user then project so project fields win without dropping user-only fields.
|
|
1302
1435
|
return agents.map((agent) => {
|
|
1436
|
+
const userOverride = userSettings.overrides[agent.name];
|
|
1437
|
+
const withUserOverride = userOverride
|
|
1438
|
+
? applyCustomAgentOverride(agent, userOverride, { scope: "user", path: userSettingsPath })
|
|
1439
|
+
: agent;
|
|
1440
|
+
|
|
1303
1441
|
const projectOverride = projectSettings.overrides[agent.name];
|
|
1304
1442
|
if (projectOverride && projectSettingsPath) {
|
|
1305
|
-
return applyCustomAgentOverride(
|
|
1443
|
+
return applyCustomAgentOverride(withUserOverride, projectOverride, { scope: "project", path: projectSettingsPath });
|
|
1306
1444
|
}
|
|
1307
1445
|
|
|
1308
|
-
|
|
1309
|
-
if (userOverride) {
|
|
1310
|
-
return applyCustomAgentOverride(agent, userOverride, { scope: "user", path: userSettingsPath });
|
|
1311
|
-
}
|
|
1312
|
-
|
|
1313
|
-
return agent;
|
|
1446
|
+
return withUserOverride;
|
|
1314
1447
|
});
|
|
1315
1448
|
}
|
|
1316
1449
|
|
|
1317
1450
|
export function buildBuiltinOverrideConfig(
|
|
1318
1451
|
base: BuiltinAgentOverrideBase,
|
|
1319
|
-
draft: Pick<AgentConfig, "model" | "fallbackModels" | "thinking" | "systemPromptMode" | "inheritProjectContext" | "inheritSkills" | "defaultContext" | "acceptanceRole" | "disabled" | "systemPrompt" | "skills" | "tools" | "mcpDirectTools" | "extensions" | "subagentOnlyExtensions" | "completionGuard" | "toolBudget"> & Partial<Pick<AgentConfig, "description" | "outputMode">>,
|
|
1452
|
+
draft: Pick<AgentConfig, "model" | "modelProvider" | "fallbackModels" | "fast" | "thinking" | "systemPromptMode" | "inheritProjectContext" | "inheritSkills" | "defaultContext" | "acceptanceRole" | "disabled" | "systemPrompt" | "skills" | "tools" | "mcpDirectTools" | "extensions" | "subagentOnlyExtensions" | "completionGuard" | "toolBudget"> & Partial<Pick<AgentConfig, "description" | "output" | "outputMode" | "defaultReads">>,
|
|
1320
1453
|
): BuiltinAgentOverrideConfig | undefined {
|
|
1321
1454
|
const override: BuiltinAgentOverrideConfig = {};
|
|
1322
1455
|
|
|
@@ -1324,9 +1457,13 @@ export function buildBuiltinOverrideConfig(
|
|
|
1324
1457
|
const description = draft.description.trim();
|
|
1325
1458
|
if (description && description !== base.description) override.description = description;
|
|
1326
1459
|
}
|
|
1460
|
+
if (draft.output !== base.output) override.output = draft.output ?? false;
|
|
1327
1461
|
if (draft.outputMode !== undefined && draft.outputMode !== base.outputMode) override.outputMode = draft.outputMode;
|
|
1462
|
+
if (!arraysEqual(draft.defaultReads, base.defaultReads)) override.defaultReads = draft.defaultReads ? [...draft.defaultReads] : false;
|
|
1328
1463
|
if (draft.model !== base.model) override.model = draft.model ?? false;
|
|
1464
|
+
if (draft.modelProvider !== base.modelProvider) override.defaultProvider = draft.modelProvider ?? false;
|
|
1329
1465
|
if (!arraysEqual(draft.fallbackModels, base.fallbackModels)) override.fallbackModels = draft.fallbackModels ? [...draft.fallbackModels] : false;
|
|
1466
|
+
if (draft.fast !== base.fast) override.fast = draft.fast === true;
|
|
1330
1467
|
if (draft.thinking !== base.thinking) override.thinking = draft.thinking ?? false;
|
|
1331
1468
|
if (draft.systemPromptMode !== base.systemPromptMode) override.systemPromptMode = draft.systemPromptMode;
|
|
1332
1469
|
if (draft.inheritProjectContext !== base.inheritProjectContext) override.inheritProjectContext = draft.inheritProjectContext;
|
|
@@ -1639,7 +1776,7 @@ function resolveAgentRelativeExtensionPaths(paths: string[] | undefined, agentFi
|
|
|
1639
1776
|
});
|
|
1640
1777
|
}
|
|
1641
1778
|
|
|
1642
|
-
function loadAgentsFromDefinitionFiles(files: AgentDefinitionFile[], source: AgentSource, discoveryPriority?: number): { agents: AgentConfig[]; diagnostics: AgentDiscoveryDiagnostic[] } {
|
|
1779
|
+
function loadAgentsFromDefinitionFiles(files: AgentDefinitionFile[], source: AgentSource, discoveryPriority?: number, packageSource?: Omit<PackageSubagentPath, "dir">): { agents: AgentConfig[]; diagnostics: AgentDiscoveryDiagnostic[] } {
|
|
1643
1780
|
const agents: AgentConfig[] = [];
|
|
1644
1781
|
const diagnostics: AgentDiscoveryDiagnostic[] = [];
|
|
1645
1782
|
|
|
@@ -1737,6 +1874,12 @@ function loadAgentsFromDefinitionFiles(files: AgentDefinitionFile[], source: Age
|
|
|
1737
1874
|
|
|
1738
1875
|
const extensions = resolveAgentRelativeExtensionPaths(parseFrontmatterList(frontmatter.extensions), filePath);
|
|
1739
1876
|
const subagentOnlyExtensions = resolveAgentRelativeExtensionPaths(parseFrontmatterList(frontmatter.subagentOnlyExtensions), filePath);
|
|
1877
|
+
let fast: boolean | undefined;
|
|
1878
|
+
if (frontmatter.fast !== undefined) {
|
|
1879
|
+
if (frontmatter.fast === "true") fast = true;
|
|
1880
|
+
else if (frontmatter.fast === "false") fast = false;
|
|
1881
|
+
else throw new Error(`Agent '${localName}' has invalid fast frontmatter; expected true or false.`);
|
|
1882
|
+
}
|
|
1740
1883
|
|
|
1741
1884
|
const extraFields: Record<string, string> = {};
|
|
1742
1885
|
for (const [key, value] of Object.entries(frontmatter)) {
|
|
@@ -1774,12 +1917,16 @@ function loadAgentsFromDefinitionFiles(files: AgentDefinitionFile[], source: Age
|
|
|
1774
1917
|
...(runner !== undefined ? { runner } : {}),
|
|
1775
1918
|
localName,
|
|
1776
1919
|
...(packageName !== undefined ? { packageName } : {}),
|
|
1920
|
+
...(packageSource?.packageName ? { packageSourceName: packageSource.packageName } : {}),
|
|
1921
|
+
...(packageSource?.packageVersion ? { packageSourceVersion: packageSource.packageVersion } : {}),
|
|
1922
|
+
...(packageSource?.packageRoot ? { packageSourceRoot: packageSource.packageRoot } : {}),
|
|
1777
1923
|
description: frontmatter.description,
|
|
1778
1924
|
...(aliases !== undefined ? { aliases } : {}),
|
|
1779
1925
|
...(rawTools !== undefined ? { tools } : {}),
|
|
1780
1926
|
...(mcpDirectTools.length > 0 ? { mcpDirectTools } : {}),
|
|
1781
1927
|
...(frontmatter.model !== undefined ? { model: frontmatter.model } : {}),
|
|
1782
1928
|
...(fallbackModels?.length ? { fallbackModels } : {}),
|
|
1929
|
+
...(fast !== undefined ? { fast } : {}),
|
|
1783
1930
|
...(frontmatter.thinking !== undefined ? { thinking: frontmatter.thinking === "false" ? false : frontmatter.thinking } : {}),
|
|
1784
1931
|
systemPromptMode,
|
|
1785
1932
|
inheritProjectContext,
|
|
@@ -1822,8 +1969,8 @@ function loadAgentsFromDefinitionFiles(files: AgentDefinitionFile[], source: Age
|
|
|
1822
1969
|
return { agents, diagnostics };
|
|
1823
1970
|
}
|
|
1824
1971
|
|
|
1825
|
-
function loadAgentsFromDir(dir: string, source: AgentSource, discoveryPriority?: number): { agents: AgentConfig[]; diagnostics: AgentDiscoveryDiagnostic[] } {
|
|
1826
|
-
return loadAgentsFromDefinitionFiles(readAgentDefinitionFiles(dir), source, discoveryPriority);
|
|
1972
|
+
function loadAgentsFromDir(dir: string, source: AgentSource, discoveryPriority?: number, packageSource?: Omit<PackageSubagentPath, "dir">): { agents: AgentConfig[]; diagnostics: AgentDiscoveryDiagnostic[] } {
|
|
1973
|
+
return loadAgentsFromDefinitionFiles(readAgentDefinitionFiles(dir), source, discoveryPriority, packageSource);
|
|
1827
1974
|
}
|
|
1828
1975
|
|
|
1829
1976
|
function loadChainsFromDir(dir: string, source: AgentSource): { chains: ChainConfig[]; diagnostics: ChainDiscoveryDiagnostic[] } {
|
|
@@ -1913,8 +2060,10 @@ export function discoverAgents(cwd: string, scope: AgentScope): AgentDiscoveryRe
|
|
|
1913
2060
|
const projectSettingsPath = getProjectAgentSettingsPath(cwd);
|
|
1914
2061
|
const userSettings = scope === "project" ? EMPTY_SUBAGENT_SETTINGS : readSubagentSettings(userSettingsPath);
|
|
1915
2062
|
const projectSettings = scope === "user" ? EMPTY_SUBAGENT_SETTINGS : readSubagentSettings(projectSettingsPath);
|
|
1916
|
-
const
|
|
2063
|
+
const defaultProvider = resolveSubagentDefaultProvider(userSettings, projectSettings, projectSettingsPath);
|
|
2064
|
+
const defaultModel = resolveSubagentDefaultModel(userSettings, projectSettings, userSettingsPath, projectSettingsPath, defaultProvider);
|
|
1917
2065
|
const defaultThinking = resolveSubagentDefaultThinking(userSettings, projectSettings, projectSettingsPath);
|
|
2066
|
+
const maxThinking = resolveSubagentMaxThinking(userSettings, projectSettings, projectSettingsPath);
|
|
1918
2067
|
const defaultExtensions = resolveSubagentDefaultExtensions(userSettings, projectSettings, projectSettingsPath);
|
|
1919
2068
|
const injectAgents = projectSettingsPath && projectSettings.injectAgents !== undefined
|
|
1920
2069
|
? projectSettings.injectAgents
|
|
@@ -1927,7 +2076,7 @@ export function discoverAgents(cwd: string, scope: AgentScope): AgentDiscoveryRe
|
|
|
1927
2076
|
|
|
1928
2077
|
const builtinLoaded = loadAgentsFromDefinitionFiles(BUILTIN_AGENT_DEFINITION_FILES, "builtin");
|
|
1929
2078
|
const builtinAgents = applyBuiltinOverrides(
|
|
1930
|
-
applySubagentDefaults(builtinLoaded.agents, defaultModel, defaultThinking, defaultExtensions),
|
|
2079
|
+
applySubagentDefaults(builtinLoaded.agents, defaultModel, defaultProvider, defaultThinking, defaultExtensions),
|
|
1931
2080
|
userSettings,
|
|
1932
2081
|
projectSettings,
|
|
1933
2082
|
userSettingsPath,
|
|
@@ -1937,7 +2086,7 @@ export function discoverAgents(cwd: string, scope: AgentScope): AgentDiscoveryRe
|
|
|
1937
2086
|
const userLoaded = scope === "project" ? [] : [...extraUserAgentDirs(), userDirOld, userDirNew]
|
|
1938
2087
|
.map((dir, discoveryPriority) => loadAgentsFromDir(dir, "user", discoveryPriority));
|
|
1939
2088
|
const userAgents = applyCustomAgentOverrides(
|
|
1940
|
-
applySubagentDefaults(userLoaded.flatMap((loaded) => loaded.agents), defaultModel, defaultThinking, defaultExtensions),
|
|
2089
|
+
applySubagentDefaults(userLoaded.flatMap((loaded) => loaded.agents), defaultModel, defaultProvider, defaultThinking, defaultExtensions),
|
|
1941
2090
|
userSettings,
|
|
1942
2091
|
projectSettings,
|
|
1943
2092
|
userSettingsPath,
|
|
@@ -1946,13 +2095,13 @@ export function discoverAgents(cwd: string, scope: AgentScope): AgentDiscoveryRe
|
|
|
1946
2095
|
|
|
1947
2096
|
const projectLoaded = scope === "user" ? [] : projectAgentDirs.map((dir) => loadAgentsFromDir(dir, "project", dir === projectAgentsDir ? 1 : 0));
|
|
1948
2097
|
const projectAgents = applyCustomAgentOverrides(
|
|
1949
|
-
applySubagentDefaults(projectLoaded.flatMap((loaded) => loaded.agents), defaultModel, defaultThinking, defaultExtensions),
|
|
2098
|
+
applySubagentDefaults(projectLoaded.flatMap((loaded) => loaded.agents), defaultModel, defaultProvider, defaultThinking, defaultExtensions),
|
|
1950
2099
|
userSettings,
|
|
1951
2100
|
projectSettings,
|
|
1952
2101
|
userSettingsPath,
|
|
1953
2102
|
projectSettingsPath,
|
|
1954
2103
|
);
|
|
1955
|
-
const packageLoaded = packageSubagentPaths.agents.map((
|
|
2104
|
+
const packageLoaded = packageSubagentPaths.agents.map((entry, index) => loadAgentsFromDir(entry.dir, "package", packageSubagentPaths.agents.length - index, entry));
|
|
1956
2105
|
const packageMap = new Map<string, AgentConfig>();
|
|
1957
2106
|
for (const loaded of packageLoaded) {
|
|
1958
2107
|
for (const agent of loaded.agents) {
|
|
@@ -1960,14 +2109,17 @@ export function discoverAgents(cwd: string, scope: AgentScope): AgentDiscoveryRe
|
|
|
1960
2109
|
}
|
|
1961
2110
|
}
|
|
1962
2111
|
const packageAgents = applyCustomAgentOverrides(
|
|
1963
|
-
applySubagentDefaults(Array.from(packageMap.values()), defaultModel, defaultThinking, defaultExtensions),
|
|
2112
|
+
applySubagentDefaults(Array.from(packageMap.values()), defaultModel, defaultProvider, defaultThinking, defaultExtensions),
|
|
1964
2113
|
userSettings,
|
|
1965
2114
|
projectSettings,
|
|
1966
2115
|
userSettingsPath,
|
|
1967
2116
|
projectSettingsPath,
|
|
1968
2117
|
);
|
|
1969
|
-
const agents =
|
|
1970
|
-
|
|
2118
|
+
const agents = applySubagentMaxThinking(
|
|
2119
|
+
mergeAgentsForScope(scope, userAgents, projectAgents, builtinAgents, packageAgents)
|
|
2120
|
+
.filter((agent) => agent.disabled !== true),
|
|
2121
|
+
maxThinking,
|
|
2122
|
+
);
|
|
1971
2123
|
|
|
1972
2124
|
const agentDiagnostics = [
|
|
1973
2125
|
...builtinLoaded.diagnostics,
|
|
@@ -1975,7 +2127,14 @@ export function discoverAgents(cwd: string, scope: AgentScope): AgentDiscoveryRe
|
|
|
1975
2127
|
...projectLoaded.flatMap((loaded) => loaded.diagnostics),
|
|
1976
2128
|
...packageLoaded.flatMap((loaded) => loaded.diagnostics),
|
|
1977
2129
|
];
|
|
1978
|
-
return {
|
|
2130
|
+
return {
|
|
2131
|
+
agents,
|
|
2132
|
+
agentDiagnostics,
|
|
2133
|
+
projectAgentsDir,
|
|
2134
|
+
...(modelScope !== undefined ? { modelScope } : {}),
|
|
2135
|
+
...(injectAgents?.length ? { injectAgents } : {}),
|
|
2136
|
+
...(maxThinking !== undefined ? { maxThinking } : {}),
|
|
2137
|
+
};
|
|
1979
2138
|
}
|
|
1980
2139
|
|
|
1981
2140
|
export function discoverAgentsAll(cwd: string): {
|
|
@@ -1993,6 +2152,7 @@ export function discoverAgentsAll(cwd: string): {
|
|
|
1993
2152
|
projectChainDir: string | null;
|
|
1994
2153
|
userSettingsPath: string;
|
|
1995
2154
|
projectSettingsPath: string | null;
|
|
2155
|
+
maxThinking?: ThinkingLevel;
|
|
1996
2156
|
} {
|
|
1997
2157
|
const userDirOld = path.join(getAgentDir(), "agents");
|
|
1998
2158
|
const userDirNew = path.join(os.homedir(), ".agents");
|
|
@@ -2003,8 +2163,10 @@ export function discoverAgentsAll(cwd: string): {
|
|
|
2003
2163
|
const projectSettingsPath = getProjectAgentSettingsPath(cwd);
|
|
2004
2164
|
const userSettings = readSubagentSettings(userSettingsPath);
|
|
2005
2165
|
const projectSettings = readSubagentSettings(projectSettingsPath);
|
|
2006
|
-
const
|
|
2166
|
+
const defaultProvider = resolveSubagentDefaultProvider(userSettings, projectSettings, projectSettingsPath);
|
|
2167
|
+
const defaultModel = resolveSubagentDefaultModel(userSettings, projectSettings, userSettingsPath, projectSettingsPath, defaultProvider);
|
|
2007
2168
|
const defaultThinking = resolveSubagentDefaultThinking(userSettings, projectSettings, projectSettingsPath);
|
|
2169
|
+
const maxThinking = resolveSubagentMaxThinking(userSettings, projectSettings, projectSettingsPath);
|
|
2008
2170
|
const defaultExtensions = resolveSubagentDefaultExtensions(userSettings, projectSettings, projectSettingsPath);
|
|
2009
2171
|
const injectAgents = projectSettingsPath && projectSettings.injectAgents !== undefined
|
|
2010
2172
|
? projectSettings.injectAgents
|
|
@@ -2013,7 +2175,7 @@ export function discoverAgentsAll(cwd: string): {
|
|
|
2013
2175
|
|
|
2014
2176
|
const builtinLoaded = loadAgentsFromDefinitionFiles(BUILTIN_AGENT_DEFINITION_FILES, "builtin");
|
|
2015
2177
|
const builtin = applyBuiltinOverrides(
|
|
2016
|
-
applySubagentDefaults(builtinLoaded.agents, defaultModel, defaultThinking, defaultExtensions),
|
|
2178
|
+
applySubagentDefaults(builtinLoaded.agents, defaultModel, defaultProvider, defaultThinking, defaultExtensions),
|
|
2017
2179
|
userSettings,
|
|
2018
2180
|
projectSettings,
|
|
2019
2181
|
userSettingsPath,
|
|
@@ -2022,7 +2184,7 @@ export function discoverAgentsAll(cwd: string): {
|
|
|
2022
2184
|
const userLoaded = [...extraUserAgentDirs(), userDirOld, userDirNew]
|
|
2023
2185
|
.map((dir, discoveryPriority) => loadAgentsFromDir(dir, "user", discoveryPriority));
|
|
2024
2186
|
const user = applyCustomAgentOverrides(
|
|
2025
|
-
applySubagentDefaults(userLoaded.flatMap((loaded) => loaded.agents), defaultModel, defaultThinking, defaultExtensions),
|
|
2187
|
+
applySubagentDefaults(userLoaded.flatMap((loaded) => loaded.agents), defaultModel, defaultProvider, defaultThinking, defaultExtensions),
|
|
2026
2188
|
userSettings,
|
|
2027
2189
|
projectSettings,
|
|
2028
2190
|
userSettingsPath,
|
|
@@ -2030,15 +2192,15 @@ export function discoverAgentsAll(cwd: string): {
|
|
|
2030
2192
|
);
|
|
2031
2193
|
const packageMap = new Map<string, AgentConfig>();
|
|
2032
2194
|
const packageAgentDiagnostics: AgentDiscoveryDiagnostic[] = [];
|
|
2033
|
-
for (const [index,
|
|
2034
|
-
const loaded = loadAgentsFromDir(dir, "package", packageSubagentPaths.agents.length - index);
|
|
2195
|
+
for (const [index, entry] of packageSubagentPaths.agents.entries()) {
|
|
2196
|
+
const loaded = loadAgentsFromDir(entry.dir, "package", packageSubagentPaths.agents.length - index, entry);
|
|
2035
2197
|
packageAgentDiagnostics.push(...loaded.diagnostics);
|
|
2036
2198
|
for (const agent of loaded.agents) {
|
|
2037
2199
|
if (!packageMap.has(agent.name)) packageMap.set(agent.name, agent);
|
|
2038
2200
|
}
|
|
2039
2201
|
}
|
|
2040
2202
|
const packageAgents = applyCustomAgentOverrides(
|
|
2041
|
-
applySubagentDefaults(Array.from(packageMap.values()), defaultModel, defaultThinking, defaultExtensions),
|
|
2203
|
+
applySubagentDefaults(Array.from(packageMap.values()), defaultModel, defaultProvider, defaultThinking, defaultExtensions),
|
|
2042
2204
|
userSettings,
|
|
2043
2205
|
projectSettings,
|
|
2044
2206
|
userSettingsPath,
|
|
@@ -2054,7 +2216,7 @@ export function discoverAgentsAll(cwd: string): {
|
|
|
2054
2216
|
}
|
|
2055
2217
|
}
|
|
2056
2218
|
const project = applyCustomAgentOverrides(
|
|
2057
|
-
applySubagentDefaults(Array.from(projectMap.values()), defaultModel, defaultThinking, defaultExtensions),
|
|
2219
|
+
applySubagentDefaults(Array.from(projectMap.values()), defaultModel, defaultProvider, defaultThinking, defaultExtensions),
|
|
2058
2220
|
userSettings,
|
|
2059
2221
|
projectSettings,
|
|
2060
2222
|
userSettingsPath,
|
|
@@ -2099,5 +2261,21 @@ export function discoverAgentsAll(cwd: string): {
|
|
|
2099
2261
|
|
|
2100
2262
|
const userDir = process.env.PI_CODING_AGENT_DIR ? userDirOld : fs.existsSync(userDirNew) ? userDirNew : userDirOld;
|
|
2101
2263
|
|
|
2102
|
-
return {
|
|
2264
|
+
return {
|
|
2265
|
+
builtin: applySubagentMaxThinking(builtin, maxThinking),
|
|
2266
|
+
package: applySubagentMaxThinking(packageAgents, maxThinking),
|
|
2267
|
+
user: applySubagentMaxThinking(user, maxThinking),
|
|
2268
|
+
project: applySubagentMaxThinking(project, maxThinking),
|
|
2269
|
+
agentDiagnostics,
|
|
2270
|
+
chains,
|
|
2271
|
+
chainDiagnostics,
|
|
2272
|
+
userDir,
|
|
2273
|
+
projectDir,
|
|
2274
|
+
userChainDir,
|
|
2275
|
+
projectChainDir,
|
|
2276
|
+
userSettingsPath,
|
|
2277
|
+
projectSettingsPath,
|
|
2278
|
+
...(injectAgents?.length ? { injectAgents } : {}),
|
|
2279
|
+
...(maxThinking !== undefined ? { maxThinking } : {}),
|
|
2280
|
+
};
|
|
2103
2281
|
}
|