oira666_pi-subagent 0.5.3 → 0.5.7
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/README.md +5 -3
- package/config.ts +20 -83
- package/docs/configuration.md +46 -28
- package/extension/execution.ts +5 -3
- package/extension/expand-command.ts +31 -50
- package/extension/launch-tool.ts +22 -7
- package/extension/provider.ts +6 -1
- package/extension/resume-tool.ts +18 -5
- package/extension/schemas.ts +97 -7
- package/extension/session-start.ts +14 -0
- package/extension/state.ts +1 -1
- package/extension/tool-registration.ts +3 -2
- package/intelligence.ts +78 -0
- package/names.ts +2 -0
- package/package.json +8 -8
- package/resume.ts +10 -1
- package/runner/arguments.ts +2 -2
- package/runner/attempt.ts +3 -0
- package/runner/options.ts +5 -3
- package/runner/parallel.ts +20 -8
- package/runner/single.ts +5 -12
- package/storage/name-records.ts +2 -0
- package/types/contracts.ts +2 -0
- package/types/details.ts +1 -0
- package/types/outcomes.ts +1 -0
- package/ui/detail-lines.ts +6 -1
- package/ui/detail-model.ts +2 -0
- package/ui/detail-transcript.ts +22 -1
- package/ui/expand-view.ts +62 -0
- package/ui/pager-view.ts +3 -2
- package/ui/pager.ts +1 -1
- package/ui/tree-build.ts +6 -1
- package/runner/smart-decision.ts +0 -163
package/README.md
CHANGED
|
@@ -103,7 +103,9 @@ See [configuration](docs/configuration.md) for frontmatter, layer restrictions,
|
|
|
103
103
|
|
|
104
104
|
Collapsed results show each child's name, task, status, and most recent activity anywhere in its subtree. `Ctrl+O` expands the newest call from memory without reading historical transcripts.
|
|
105
105
|
|
|
106
|
-
`/subagent-expand <name>` opens a saved worker transcript. With no name, it opens a searchable picker. Name completion is fuzzy. Each task or resume shows its actual provider/model and thinking level from the worker's session, not the parent's settings. Missing historical metadata appears as `unknown`.
|
|
106
|
+
`/subagent-expand <name>` opens a saved worker transcript. With no name, it opens a searchable picker. Name completion is fuzzy. Each task or resume shows its actual provider/model and thinking level from the worker's session, not the parent's settings. Selected presets also appear as an intelligence label, kept separately for each run. Missing historical model/thinking metadata appears as `unknown`.
|
|
107
|
+
|
|
108
|
+
[Model presets](docs/configuration.md#caller-selected-intelligence) show labels such as `Nicolas (Junior/code-writer)` in regular tool results. One enabled preset applies automatically to all launches and resumes without exposing an `intelligence` argument. Two or more expose an optional choice; zero or disabled presets keep the existing defaults and show no intelligence label.
|
|
107
109
|
|
|
108
110
|
| Key | Action |
|
|
109
111
|
| --- | --- |
|
|
@@ -111,9 +113,9 @@ Collapsed results show each child's name, task, status, and most recent activity
|
|
|
111
113
|
| T | Current turn's tool list |
|
|
112
114
|
| Up / Down, Enter | Select and open a tool or nested child |
|
|
113
115
|
| C | Children across all turns |
|
|
114
|
-
| Esc |
|
|
116
|
+
| Esc | Back one level: tool detail, tools/children, parent subagent, then the searchable list. From the list or a directly named subagent, close. |
|
|
115
117
|
| /, n, N | Search, next match, previous match |
|
|
116
|
-
| q | Close |
|
|
118
|
+
| q | Close from any transcript view |
|
|
117
119
|
|
|
118
120
|
While workers run, steering input can be broadcast to selected names, including nested paths such as `John > Maria`. Only inputs marked as streaming `steer` open the routing prompt. Idle prompts and queued follow-ups remain with the parent.
|
|
119
121
|
|
package/config.ts
CHANGED
|
@@ -3,13 +3,14 @@ import * as fs from "node:fs";
|
|
|
3
3
|
import * as os from "node:os";
|
|
4
4
|
import * as path from "node:path";
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { intelligenceEnabled, parseIntelligencePresets, type IntelligencePreset } from "./intelligence.js";
|
|
7
7
|
|
|
8
8
|
export const PI_SUBAGENTS_CONFIG_FILE = "pi-subagents.json";
|
|
9
|
+
export const PI_SUBAGENT_CONFIG_FILE = "pi-subagent.json";
|
|
9
10
|
|
|
10
11
|
export interface PiSubagentsConfig {
|
|
11
12
|
toolPrompts: Record<string, string>;
|
|
12
|
-
|
|
13
|
+
intelligencePresets: IntelligencePreset[];
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
function readConfig(filePath: string): Record<string, unknown> {
|
|
@@ -24,81 +25,15 @@ function readConfig(filePath: string): Record<string, unknown> {
|
|
|
24
25
|
|
|
25
26
|
return parsed as Record<string, unknown>;
|
|
26
27
|
} catch {
|
|
27
|
-
//
|
|
28
|
+
// Do not expose configuration contents in parser errors.
|
|
28
29
|
console.warn(`[pi-subagent] Failed to read config "${filePath}".`);
|
|
29
30
|
return {};
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
function
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
let tempFileCounter = 0;
|
|
38
|
-
|
|
39
|
-
/** Add the explicit default without allowing a failed write to change runtime behavior. */
|
|
40
|
-
function persistSmartDecisionFallback(config: Record<string, unknown>, filePath: string): void {
|
|
41
|
-
const smartDecision = config["smart-decision"];
|
|
42
|
-
if (!isRecord(smartDecision) || Object.hasOwn(smartDecision, "fallback")) return;
|
|
43
|
-
|
|
44
|
-
smartDecision.fallback = true;
|
|
45
|
-
let tempPath: string | undefined;
|
|
46
|
-
let ownsTemp = false;
|
|
47
|
-
try {
|
|
48
|
-
// Replace the target rather than a symlink that points to it.
|
|
49
|
-
const targetPath = fs.realpathSync(filePath);
|
|
50
|
-
// Re-read immediately before writing so unrelated edits made since the initial load survive.
|
|
51
|
-
// Retrying also makes concurrent nested-worker migrations converge without clobbering one another.
|
|
52
|
-
for (let attempt = 0; attempt < 3; attempt++) {
|
|
53
|
-
const source = fs.readFileSync(targetPath, "utf8");
|
|
54
|
-
const latest = JSON.parse(source) as unknown;
|
|
55
|
-
if (!isRecord(latest)) return;
|
|
56
|
-
const latestSmartDecision = latest["smart-decision"];
|
|
57
|
-
if (!isRecord(latestSmartDecision)) return;
|
|
58
|
-
if (Object.hasOwn(latestSmartDecision, "fallback")) {
|
|
59
|
-
smartDecision.fallback = latestSmartDecision.fallback;
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
latestSmartDecision.fallback = true;
|
|
64
|
-
const mode = fs.statSync(targetPath).mode & 0o7777;
|
|
65
|
-
const candidatePath = path.join(
|
|
66
|
-
path.dirname(targetPath),
|
|
67
|
-
`.${path.basename(targetPath)}.${process.pid}.${tempFileCounter++}.tmp`,
|
|
68
|
-
);
|
|
69
|
-
const fd = fs.openSync(candidatePath, "wx", mode);
|
|
70
|
-
tempPath = candidatePath;
|
|
71
|
-
ownsTemp = true;
|
|
72
|
-
try {
|
|
73
|
-
fs.writeFileSync(fd, `${JSON.stringify(latest, null, 2)}\n`, "utf8");
|
|
74
|
-
fs.fchmodSync(fd, mode);
|
|
75
|
-
fs.fsyncSync(fd);
|
|
76
|
-
} finally {
|
|
77
|
-
fs.closeSync(fd);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (fs.readFileSync(targetPath, "utf8") !== source) {
|
|
81
|
-
fs.unlinkSync(tempPath);
|
|
82
|
-
tempPath = undefined;
|
|
83
|
-
ownsTemp = false;
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
fs.renameSync(tempPath, targetPath);
|
|
87
|
-
tempPath = undefined;
|
|
88
|
-
ownsTemp = false;
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
throw new Error("config changed during fallback migration");
|
|
92
|
-
} catch {
|
|
93
|
-
if (ownsTemp && tempPath) {
|
|
94
|
-
try {
|
|
95
|
-
fs.unlinkSync(tempPath);
|
|
96
|
-
} catch {
|
|
97
|
-
// Best-effort cleanup. Do not expose filesystem errors or configuration contents.
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
console.warn("[pi-subagent] Failed to save the default smart-decision fallback.");
|
|
101
|
-
}
|
|
34
|
+
function configAtLocation(dir: string): string {
|
|
35
|
+
const singular = path.join(dir, PI_SUBAGENT_CONFIG_FILE);
|
|
36
|
+
return fs.existsSync(singular) ? singular : path.join(dir, PI_SUBAGENTS_CONFIG_FILE);
|
|
102
37
|
}
|
|
103
38
|
|
|
104
39
|
function readToolPrompts(config: Record<string, unknown>, filePath: string): Record<string, string> {
|
|
@@ -124,11 +59,11 @@ function readToolPrompts(config: Record<string, unknown>, filePath: string): Rec
|
|
|
124
59
|
return result;
|
|
125
60
|
}
|
|
126
61
|
|
|
127
|
-
/** Find the nearest project-local
|
|
62
|
+
/** Find the nearest project-local config while walking up from cwd. */
|
|
128
63
|
export function findProjectConfig(cwd: string): string | null {
|
|
129
64
|
let dir = path.resolve(cwd);
|
|
130
65
|
while (true) {
|
|
131
|
-
const candidate = path.join(dir, ".pi"
|
|
66
|
+
const candidate = configAtLocation(path.join(dir, ".pi"));
|
|
132
67
|
if (fs.existsSync(candidate)) return candidate;
|
|
133
68
|
const parent = path.dirname(dir);
|
|
134
69
|
if (parent === dir) return null;
|
|
@@ -141,26 +76,28 @@ export function findProjectConfig(cwd: string): string | null {
|
|
|
141
76
|
* ~/.pi/pi-subagents.json
|
|
142
77
|
* $PI_CODING_AGENT_DIR/pi-subagents.json (normally ~/.pi/agent/pi-subagents.json)
|
|
143
78
|
* nearest project .pi/pi-subagents.json (trusted projects only)
|
|
79
|
+
* pi-subagent.json replaces pi-subagents.json at each location when present.
|
|
144
80
|
*/
|
|
145
81
|
export function loadPiSubagentsConfig(cwd?: string, includeProject = false): PiSubagentsConfig {
|
|
146
|
-
const paths = [
|
|
147
|
-
path.join(os.homedir(), ".pi", PI_SUBAGENTS_CONFIG_FILE),
|
|
148
|
-
path.join(getAgentDir(), PI_SUBAGENTS_CONFIG_FILE),
|
|
149
|
-
];
|
|
82
|
+
const paths = [configAtLocation(path.join(os.homedir(), ".pi")), configAtLocation(getAgentDir())];
|
|
150
83
|
if (cwd && includeProject) {
|
|
151
84
|
const projectConfig = findProjectConfig(cwd);
|
|
152
85
|
if (projectConfig) paths.push(projectConfig);
|
|
153
86
|
}
|
|
154
87
|
|
|
155
88
|
const toolPrompts: Record<string, string> = {};
|
|
156
|
-
let
|
|
89
|
+
let intelligencePresets: IntelligencePreset[] = [];
|
|
157
90
|
for (const filePath of new Set(paths)) {
|
|
158
91
|
const config = readConfig(filePath);
|
|
159
|
-
persistSmartDecisionFallback(config, filePath);
|
|
160
92
|
Object.assign(toolPrompts, readToolPrompts(config, filePath));
|
|
161
|
-
if (Object.hasOwn(config, "
|
|
162
|
-
|
|
93
|
+
if (Object.hasOwn(config, "subagents-models")) {
|
|
94
|
+
intelligencePresets = [];
|
|
95
|
+
try {
|
|
96
|
+
intelligencePresets = parseIntelligencePresets(config["subagents-models"]);
|
|
97
|
+
} catch {
|
|
98
|
+
console.warn(`[pi-subagent] Ignoring invalid subagents-models in "${filePath}".`);
|
|
99
|
+
}
|
|
163
100
|
}
|
|
164
101
|
}
|
|
165
|
-
return { toolPrompts,
|
|
102
|
+
return { toolPrompts, intelligencePresets: intelligenceEnabled(intelligencePresets) ? intelligencePresets : [] };
|
|
166
103
|
}
|
package/docs/configuration.md
CHANGED
|
@@ -37,11 +37,13 @@ At maximum depth 1, combining `first-layer: only` with `last-layer: disabled` bl
|
|
|
37
37
|
|
|
38
38
|
## Tool descriptions
|
|
39
39
|
|
|
40
|
-
Use `pi-
|
|
40
|
+
Use `pi-subagent.json` to configure model presets or replace either tool's full model-facing description. Files load in this order, with later values overriding earlier values per tool:
|
|
41
41
|
|
|
42
|
-
1. `~/.pi/pi-
|
|
43
|
-
2. `$PI_CODING_AGENT_DIR/pi-
|
|
44
|
-
3. The nearest trusted `.pi/pi-
|
|
42
|
+
1. `~/.pi/pi-subagent.json`
|
|
43
|
+
2. `$PI_CODING_AGENT_DIR/pi-subagent.json`, normally `~/.pi/agent/pi-subagent.json`
|
|
44
|
+
3. The nearest trusted `.pi/pi-subagent.json`, walking upward from the working directory
|
|
45
|
+
|
|
46
|
+
The legacy filename `pi-subagents.json` is also supported. At each location, the singular filename takes precedence over the plural filename.
|
|
45
47
|
|
|
46
48
|
```json
|
|
47
49
|
{
|
|
@@ -54,41 +56,57 @@ Use `pi-subagents.json` to replace either tool's full model-facing description.
|
|
|
54
56
|
|
|
55
57
|
Missing descriptions retain their defaults. Overrides change written guidance, not schemas, budget checks, or runtime limits. Keep instructions to estimate worker counts and avoid unnecessary delegation.
|
|
56
58
|
|
|
57
|
-
##
|
|
59
|
+
## Caller-selected intelligence
|
|
58
60
|
|
|
59
|
-
|
|
61
|
+
Define named model presets in `pi-subagent.json`. With two or more enabled presets, the calling model chooses through each task's optional `intelligence` argument. With exactly one enabled preset, both tools hide the argument and automatically use that preset for every launch and resume. With no presets, the argument is absent and existing model/thinking defaults apply. No router or separate model-selection request is used.
|
|
60
62
|
|
|
61
63
|
```json
|
|
62
64
|
{
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
{
|
|
71
|
-
"openai-codex/gpt-6-astra/high": "Frontier model for the most complicated tasks. Expensive and slow; use for difficult planning, architecture, and non-trivial problems.",
|
|
72
|
-
"openai/gpt-4.1-mini/off": "Fast, inexpensive model for small, well-defined edits and straightforward tasks."
|
|
65
|
+
"subagents-models": [
|
|
66
|
+
{
|
|
67
|
+
"junior": {
|
|
68
|
+
"model": "gpt-4.1-mini",
|
|
69
|
+
"provider": "openai",
|
|
70
|
+
"reasoning-level": "off",
|
|
71
|
+
"description": "Small, well-defined edits and lookups."
|
|
73
72
|
}
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"senior": {
|
|
76
|
+
"model": "gpt-6-astra",
|
|
77
|
+
"provider": "openai-codex",
|
|
78
|
+
"reasoning-level": "high",
|
|
79
|
+
"description": "Difficult architecture and cross-system debugging."
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Use models available in your Pi installation. Names are arbitrary, unique, non-empty strings without leading or trailing whitespace. Each array entry defines one preset. `model`, `provider`, and `reasoning-level` are required. Accepted reasoning levels are `off`, `minimal`, `low`, `medium`, `high`, `xhigh`, and `max`; support depends on the selected model and Pi version. `description` is optional. The tool schema shows each name with its description, or just its name when omitted.
|
|
87
|
+
|
|
88
|
+
```json
|
|
89
|
+
{
|
|
90
|
+
"tasks": [
|
|
91
|
+
{
|
|
92
|
+
"agent": "code-writer",
|
|
93
|
+
"task": "Fix the button label.",
|
|
94
|
+
"max_subagents_allowed": 0,
|
|
95
|
+
"intelligence": "junior"
|
|
96
|
+
}
|
|
97
|
+
]
|
|
76
98
|
}
|
|
77
99
|
```
|
|
78
100
|
|
|
79
|
-
|
|
101
|
+
With multiple presets, `resume_subagents` also accepts `intelligence` on each resume item. A selected or automatic preset overrides the parent model and agent model/thinking settings for that run. The parent's explicit `--provider` and `--api-key` are not forwarded when a preset is selected. Worker providers use their configured Pi credentials. With multiple presets, omitting `intelligence` preserves existing defaults; it does not remember a previous preset choice.
|
|
80
102
|
|
|
81
|
-
|
|
82
|
-
- `model` selects the decision model, not the worker model. `jev` maps to TypeSafe's `jev-latest`; explicit TypeSafe model IDs also work.
|
|
83
|
-
- `provider_url` is the provider base URL, defaulting to `https://api.typesafe.ai`. For a local compatible server, use `http://localhost:8765`. The extension appends `/v1/systemone`; trailing slashes are ignored. Use an HTTP or HTTPS URL without credentials, query parameters, or a fragment.
|
|
84
|
-
- `api_key` is your TypeSafe API key. Worker providers still need their own Pi credentials.
|
|
85
|
-
- `fallback` defaults to `true`. When a loaded `smart-decision` object omits it, the extension adds `"fallback": true` and saves that configuration file at runtime. Existing values, including `false`, are left untouched. Untrusted project files are never changed. If saving fails, a warning is emitted and the runtime default still applies. If selection fails, a short warning is written and the worker uses the original launch settings. Set it to `false` to return a tool error without launching the affected worker. This covers network errors, the 10-second request timeout, API errors, invalid answers, and invalid enabled configuration. Cancellation cancels the task instead of falling back.
|
|
103
|
+
Tool result rows show the selected preset, for example `Nicolas (Junior/code-writer)`. Display names capitalize only the first character; configured spelling and argument values otherwise stay unchanged. Runs without a preset show `Nicolas (code-writer)`. Durable results retain their own preset name, and the name registry retains the initial choice. `/subagent-expand` shows each task's or resume's recorded intelligence alongside its actual transcript model and thinking level. Later resumes do not relabel earlier work. Missing model or thinking metadata remains `unknown`, even when a preset name is known.
|
|
86
104
|
|
|
87
|
-
|
|
105
|
+
`PI_SUBAGENT_INTELLIGENCE=true` enables presets when they exist, which is the default. Set it to `false` or `0` to treat the configuration as having no presets: both tools hide the argument and no automatic preset applies. Unknown choices or attempts to pass a hidden argument fail before launching workers.
|
|
88
106
|
|
|
89
|
-
Configuration
|
|
107
|
+
Configuration follows the trust checks and file order above. A later `subagents-models` block replaces the entire earlier block. An empty list disables selection. Invalid blocks warn and disable selection rather than using a partial list. Nested workers load configuration using the same rules. Reload Pi after changing settings.
|
|
90
108
|
|
|
91
|
-
|
|
109
|
+
The old `smart-decision` block is ignored. Remove it and its router credentials when migrating. Configuration files are no longer modified at runtime.
|
|
92
110
|
|
|
93
111
|
## Limits and discovery
|
|
94
112
|
|
|
@@ -130,7 +148,7 @@ Normally Pi restarts through `process.execPath process.argv[1]`. No package-mana
|
|
|
130
148
|
|
|
131
149
|
## Forwarded CLI arguments
|
|
132
150
|
|
|
133
|
-
Children inherit the parent's CLI settings except arguments managed by the extension. Without
|
|
151
|
+
Children inherit the parent's CLI settings except arguments managed by the extension. Without an intelligence preset, every new launch explicitly selects the parent's active model, so `/model` changes affect subsequent launches.
|
|
134
152
|
|
|
135
153
|
Forwarded unchanged:
|
|
136
154
|
|
package/extension/execution.ts
CHANGED
|
@@ -28,6 +28,7 @@ export async function executeSingle(
|
|
|
28
28
|
topLevelBaseId: number,
|
|
29
29
|
subagentName?: string,
|
|
30
30
|
budget?: SubagentBudget,
|
|
31
|
+
intelligence?: string,
|
|
31
32
|
) {
|
|
32
33
|
if (previousResult && isFinishedResult(previousResult)) {
|
|
33
34
|
return {
|
|
@@ -65,7 +66,8 @@ export async function executeSingle(
|
|
|
65
66
|
resumeSession: resumeExistingSession,
|
|
66
67
|
initialResult: previousResult,
|
|
67
68
|
fallbackModel,
|
|
68
|
-
|
|
69
|
+
intelligence,
|
|
70
|
+
intelligencePresets: state.intelligencePresets,
|
|
69
71
|
onHandle: (handle) => {
|
|
70
72
|
activeId = topLevelBaseId;
|
|
71
73
|
state.activeSubagents.set(activeId, { agent: agentName, task, handle, name: subagentName });
|
|
@@ -106,7 +108,7 @@ export async function executeSingle(
|
|
|
106
108
|
|
|
107
109
|
export async function executeParallel(
|
|
108
110
|
state: ExtensionState,
|
|
109
|
-
tasks: Array<{ agent: string; task: string }>,
|
|
111
|
+
tasks: Array<{ agent: string; task: string; intelligence?: string }>,
|
|
110
112
|
agents: AgentConfig[],
|
|
111
113
|
defaultCwd: string,
|
|
112
114
|
signal: AbortSignal | undefined,
|
|
@@ -153,7 +155,7 @@ export async function executeParallel(
|
|
|
153
155
|
{
|
|
154
156
|
...extras,
|
|
155
157
|
namesFile: state.currentNamesFile || undefined,
|
|
156
|
-
|
|
158
|
+
intelligencePresets: state.intelligencePresets,
|
|
157
159
|
projectTrusted: state.latestSessionCtx?.cwd === defaultCwd && state.latestSessionCtx.isProjectTrusted(),
|
|
158
160
|
},
|
|
159
161
|
);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { buildSubagentDetail, findNameRecord, type SubagentDetail } from "../detail.js";
|
|
2
2
|
import { readNamesRegistry, type NamesRegistry, type SubagentNameRecord } from "../names.js";
|
|
3
|
-
import {
|
|
3
|
+
import { filterPickerItems, type PickerItem } from "../overlay.js";
|
|
4
|
+
import { SubagentExpandView } from "../ui/expand-view.js";
|
|
4
5
|
import type { SessionContext } from "./contracts.js";
|
|
5
6
|
import type { ExtensionState } from "./state.js";
|
|
6
7
|
|
|
@@ -66,63 +67,43 @@ export function registerSubagentExpandCommand(state: ExtensionState): void {
|
|
|
66
67
|
return;
|
|
67
68
|
}
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
if (!record) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
|
|
70
|
+
const record = name ? findNameRecord(registry, name) : undefined;
|
|
71
|
+
if (!record && name) {
|
|
72
|
+
const suggestions = filterPickerItems(
|
|
73
|
+
sortedRecords.map((item) => ({ name: item.name, agent: item.agent, task: item.task })),
|
|
74
|
+
name,
|
|
75
|
+
)
|
|
76
|
+
.slice(0, 10)
|
|
77
|
+
.map((item) => item.name);
|
|
78
|
+
ctx.ui.notify(
|
|
79
|
+
`Unknown subagent "${name}".${suggestions.length > 0 ? ` Did you mean: ${suggestions.join(", ")}?` : ""}`,
|
|
80
|
+
"error",
|
|
81
|
+
);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const resolveDetail = (selectedName: string): SubagentDetail | undefined => {
|
|
86
|
+
const selected = findNameRecord(registry, selectedName);
|
|
87
|
+
if (!selected) return undefined;
|
|
88
|
+
try {
|
|
89
|
+
return buildSubagentDetail(selected, { sessionDir: resolveDetailSessionDir(state, selected) });
|
|
90
|
+
} catch (err) {
|
|
78
91
|
ctx.ui.notify(
|
|
79
|
-
`
|
|
92
|
+
`Failed to read subagent session: ${err instanceof Error ? err.message : String(err)}`,
|
|
80
93
|
"error",
|
|
81
94
|
);
|
|
82
|
-
return;
|
|
95
|
+
return undefined;
|
|
83
96
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
(tui, theme, _keybindings, done: (value: string | undefined) => void) =>
|
|
88
|
-
new SubagentPicker({
|
|
89
|
-
items: sortedRecords.map((item) => ({ name: item.name, agent: item.agent, task: item.task })),
|
|
90
|
-
getRows: () => tui?.terminal?.rows ?? 30,
|
|
91
|
-
theme,
|
|
92
|
-
requestRender: () => tui?.requestRender?.(),
|
|
93
|
-
onPick: (value) => done(value),
|
|
94
|
-
}),
|
|
95
|
-
{
|
|
96
|
-
overlay: true,
|
|
97
|
-
overlayOptions: { anchor: "center", width: "80%", maxHeight: "90%", margin: 1 },
|
|
98
|
-
},
|
|
99
|
-
);
|
|
100
|
-
if (!picked) return;
|
|
101
|
-
record = findNameRecord(registry, picked);
|
|
102
|
-
if (!record) return;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
let detail: SubagentDetail;
|
|
106
|
-
try {
|
|
107
|
-
detail = buildSubagentDetail(record, { sessionDir: resolveDetailSessionDir(state, record) });
|
|
108
|
-
} catch (err) {
|
|
109
|
-
ctx.ui.notify(`Failed to read subagent session: ${err instanceof Error ? err.message : String(err)}`, "error");
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
97
|
+
};
|
|
98
|
+
const detail = record ? resolveDetail(record.name) : undefined;
|
|
99
|
+
if (record && !detail) return;
|
|
112
100
|
|
|
113
101
|
await ctx.ui.custom(
|
|
114
102
|
(tui, theme, _keybindings, done: (value: void) => void) =>
|
|
115
|
-
new
|
|
103
|
+
new SubagentExpandView({
|
|
104
|
+
items: sortedRecords.map((item) => ({ name: item.name, agent: item.agent, task: item.task })),
|
|
116
105
|
detail,
|
|
117
|
-
resolveDetail
|
|
118
|
-
const childRecord = findNameRecord(registry, childName);
|
|
119
|
-
if (!childRecord) return undefined;
|
|
120
|
-
try {
|
|
121
|
-
return buildSubagentDetail(childRecord, { sessionDir: resolveDetailSessionDir(state, childRecord) });
|
|
122
|
-
} catch {
|
|
123
|
-
return undefined;
|
|
124
|
-
}
|
|
125
|
-
},
|
|
106
|
+
resolveDetail,
|
|
126
107
|
getRows: () => tui?.terminal?.rows ?? 30,
|
|
127
108
|
theme,
|
|
128
109
|
requestRender: () => tui?.requestRender?.(),
|
package/extension/launch-tool.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { validatePreparedArguments } from "./schemas.js";
|
|
1
|
+
import { createIntelligenceSchemas, validatePreparedArguments } from "./schemas.js";
|
|
2
|
+
import { selectIntelligence } from "../intelligence.js";
|
|
2
3
|
import * as path from "node:path";
|
|
3
4
|
import { discoverAgents } from "../agents.js";
|
|
4
5
|
import {
|
|
@@ -10,7 +11,7 @@ import {
|
|
|
10
11
|
} from "../budget.js";
|
|
11
12
|
import { allocateSubagentNames } from "../names.js";
|
|
12
13
|
import { recordToolCallStart, renderCall, renderResult } from "../render.js";
|
|
13
|
-
import { getTaskBranchSize
|
|
14
|
+
import { getTaskBranchSize } from "../resume.js";
|
|
14
15
|
import { buildSubagentDetails, DEFAULT_DELEGATION_MODE, SUBAGENT_TOOL_NAME } from "../types.js";
|
|
15
16
|
import { updateLatestBroadcastTargets } from "./broadcast.js";
|
|
16
17
|
import { makeDetailsFactory } from "./details.js";
|
|
@@ -29,17 +30,25 @@ import {
|
|
|
29
30
|
import { trackProgress } from "./progress.js";
|
|
30
31
|
import { getSubagentsToolDescription } from "./prompts.js";
|
|
31
32
|
import { ensureBudget, getParentModelForSubagent, getSessionDirForTask } from "./runtime.js";
|
|
32
|
-
import {
|
|
33
|
+
import { findRecoveryPlanIndex, prepareIntelligenceArguments, prepareRecoveryArguments } from "./schemas.js";
|
|
33
34
|
import type { ExtensionState } from "./state.js";
|
|
34
35
|
|
|
35
36
|
export function registerSubagentsTool(state: ExtensionState) {
|
|
37
|
+
const parameters = createIntelligenceSchemas(state.intelligencePresets).subagents;
|
|
36
38
|
state.pi.registerTool({
|
|
37
39
|
name: SUBAGENT_TOOL_NAME,
|
|
38
40
|
label: "Subagents",
|
|
39
41
|
description: state.configuredToolPrompts[SUBAGENT_TOOL_NAME] ?? getSubagentsToolDescription(),
|
|
40
|
-
parameters
|
|
42
|
+
parameters,
|
|
41
43
|
prepareArguments(args) {
|
|
42
|
-
return validatePreparedArguments(
|
|
44
|
+
return validatePreparedArguments(
|
|
45
|
+
parameters,
|
|
46
|
+
prepareRecoveryArguments(
|
|
47
|
+
prepareIntelligenceArguments(args, "tasks"),
|
|
48
|
+
state.pendingResumePlans,
|
|
49
|
+
state.intelligencePresets,
|
|
50
|
+
),
|
|
51
|
+
);
|
|
43
52
|
},
|
|
44
53
|
|
|
45
54
|
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
@@ -67,6 +76,7 @@ export function registerSubagentsTool(state: ExtensionState) {
|
|
|
67
76
|
}
|
|
68
77
|
|
|
69
78
|
for (const [index, task] of tasks.entries()) {
|
|
79
|
+
selectIntelligence(state.intelligencePresets, task.intelligence);
|
|
70
80
|
if (!isBranchBudgetAmount(task.max_subagents_allowed)) {
|
|
71
81
|
throw new SubagentBudgetError(
|
|
72
82
|
`tasks[${index}].max_subagents_allowed is required. Use a non-negative safe integer below Number.MAX_SAFE_INTEGER, excluding the assigned agent. Use 0 for a direct worker.`,
|
|
@@ -144,7 +154,7 @@ export function registerSubagentsTool(state: ExtensionState) {
|
|
|
144
154
|
}
|
|
145
155
|
}
|
|
146
156
|
|
|
147
|
-
const resumePlanIndex = state.pendingResumePlans
|
|
157
|
+
const resumePlanIndex = findRecoveryPlanIndex(tasks, state.pendingResumePlans, state.intelligencePresets);
|
|
148
158
|
const resumePlan = resumePlanIndex >= 0 ? state.pendingResumePlans[resumePlanIndex] : null;
|
|
149
159
|
if (launchGeneration !== state.lifecycleGeneration || signal?.aborted)
|
|
150
160
|
throw new SubagentBudgetError("Launch canceled or session changed. No slots were reserved.");
|
|
@@ -203,11 +213,15 @@ export function registerSubagentsTool(state: ExtensionState) {
|
|
|
203
213
|
state.currentOwnerId,
|
|
204
214
|
pendingAllocation.map(({ task, index }) => {
|
|
205
215
|
const agentConfig = agents.find((agent) => agent.name === task.agent);
|
|
216
|
+
const preset = selectIntelligence(state.intelligencePresets, task.intelligence);
|
|
206
217
|
return {
|
|
207
218
|
agent: task.agent,
|
|
208
219
|
task: task.task,
|
|
209
220
|
budget: budgets[index],
|
|
210
|
-
model:
|
|
221
|
+
model: preset
|
|
222
|
+
? `${preset.provider}/${preset.model}`
|
|
223
|
+
: (formatModelFlag(getParentModelForSubagent(state, ctx)) ?? agentConfig?.model),
|
|
224
|
+
intelligence: preset?.name,
|
|
211
225
|
tools: agentConfig?.tools,
|
|
212
226
|
sessionDir:
|
|
213
227
|
resumePlan?.details?.results[index]?.sessionDir ??
|
|
@@ -250,6 +264,7 @@ export function registerSubagentsTool(state: ExtensionState) {
|
|
|
250
264
|
topLevelBaseId,
|
|
251
265
|
names[0],
|
|
252
266
|
budgets[0],
|
|
267
|
+
task.intelligence,
|
|
253
268
|
);
|
|
254
269
|
}
|
|
255
270
|
|
package/extension/provider.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { ResumeModel, StreamOptions, ProviderContext } from "./contracts.js
|
|
|
6
6
|
import { RESUME_MODEL_DEF, isSyntheticResumePrompt } from "./models.js";
|
|
7
7
|
import { restoreVisibleModelForResume } from "./runtime.js";
|
|
8
8
|
import type { ExtensionState } from "./state.js";
|
|
9
|
+
import { normalizeRecoveryIntelligence } from "./schemas.js";
|
|
9
10
|
|
|
10
11
|
export function mergeProviderHeaders(
|
|
11
12
|
base: Record<string, string | null> | undefined,
|
|
@@ -129,7 +130,11 @@ export function registerResumeProvider(state: ExtensionState): void {
|
|
|
129
130
|
const toolCalls = plans.map((plan, index) =>
|
|
130
131
|
fauxToolCall(
|
|
131
132
|
SUBAGENT_TOOL_NAME,
|
|
132
|
-
{
|
|
133
|
+
{
|
|
134
|
+
tasks: normalizeRecoveryIntelligence(plan.tasks, state.intelligencePresets).map((task) => ({
|
|
135
|
+
...task,
|
|
136
|
+
})),
|
|
137
|
+
},
|
|
133
138
|
{ id: `resume_subagent_${Date.now()}_${index}` },
|
|
134
139
|
),
|
|
135
140
|
);
|
package/extension/resume-tool.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { validatePreparedArguments } from "./schemas.js";
|
|
1
|
+
import { createIntelligenceSchemas, validatePreparedArguments } from "./schemas.js";
|
|
2
|
+
import { selectIntelligence } from "../intelligence.js";
|
|
2
3
|
import * as fs from "node:fs";
|
|
3
4
|
import * as path from "node:path";
|
|
4
5
|
import { discoverAgents, isAgentEnabledAtLayer, type AgentConfig } from "../agents.js";
|
|
@@ -26,11 +27,12 @@ import { formatModelFlag } from "./models.js";
|
|
|
26
27
|
import { resumableSubagentsDisabled } from "./policy.js";
|
|
27
28
|
import { trackProgress } from "./progress.js";
|
|
28
29
|
import { ensureBudget, getParentModelForSubagent } from "./runtime.js";
|
|
29
|
-
import { normalizeResumes,
|
|
30
|
+
import { normalizeResumes, prepareIntelligenceArguments } from "./schemas.js";
|
|
30
31
|
import type { ExtensionState } from "./state.js";
|
|
31
32
|
|
|
32
33
|
export function registerResumeSubagentsTool(state: ExtensionState) {
|
|
33
34
|
if (resumableSubagentsDisabled()) return;
|
|
35
|
+
const parameters = createIntelligenceSchemas(state.intelligencePresets).resumes;
|
|
34
36
|
state.pi.registerTool({
|
|
35
37
|
name: RESUME_SUBAGENTS_TOOL_NAME,
|
|
36
38
|
label: "Resume subagents",
|
|
@@ -41,9 +43,12 @@ export function registerResumeSubagentsTool(state: ExtensionState) {
|
|
|
41
43
|
"Optional max_subagents_allowed replaces the lifetime descendant cap, excluding the resumed agent. Past launches and assigned slots still count. Increases reserve extra slots from the original launcher; omitting it keeps the current allowance.",
|
|
42
44
|
"Pass { resumes: [{ subagent, task }] }. Resumes in one call run in parallel; wait between dependent tasks.",
|
|
43
45
|
].join("\n"),
|
|
44
|
-
parameters
|
|
46
|
+
parameters,
|
|
45
47
|
prepareArguments(args) {
|
|
46
|
-
return validatePreparedArguments(
|
|
48
|
+
return validatePreparedArguments(
|
|
49
|
+
parameters,
|
|
50
|
+
prepareIntelligenceArguments(prepareResumeArguments(args), "resumes"),
|
|
51
|
+
);
|
|
47
52
|
},
|
|
48
53
|
|
|
49
54
|
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
@@ -68,6 +73,8 @@ export function registerResumeSubagentsTool(state: ExtensionState) {
|
|
|
68
73
|
);
|
|
69
74
|
}
|
|
70
75
|
|
|
76
|
+
for (const resume of resumes) selectIntelligence(state.intelligencePresets, resume.intelligence);
|
|
77
|
+
|
|
71
78
|
const duplicates = resumes
|
|
72
79
|
.map((resume) => resume.name)
|
|
73
80
|
.filter((name, index, all) => all.indexOf(name) !== index);
|
|
@@ -117,6 +124,7 @@ export function registerResumeSubagentsTool(state: ExtensionState) {
|
|
|
117
124
|
tools?: string[];
|
|
118
125
|
budget: SubagentBudget;
|
|
119
126
|
max_subagents_allowed?: number;
|
|
127
|
+
intelligence?: string;
|
|
120
128
|
}> = [];
|
|
121
129
|
const hasSessionFiles = (dir: string): boolean => {
|
|
122
130
|
try {
|
|
@@ -166,6 +174,7 @@ export function registerResumeSubagentsTool(state: ExtensionState) {
|
|
|
166
174
|
budget:
|
|
167
175
|
resolution.record.budget ?? createBudget(path.join(resolution.record.sessionDir, "legacy-budget"), 0),
|
|
168
176
|
max_subagents_allowed: resume.max_subagents_allowed,
|
|
177
|
+
intelligence: resume.intelligence,
|
|
169
178
|
});
|
|
170
179
|
}
|
|
171
180
|
if (errors.length > 0) {
|
|
@@ -225,7 +234,11 @@ export function registerResumeSubagentsTool(state: ExtensionState) {
|
|
|
225
234
|
}
|
|
226
235
|
}
|
|
227
236
|
|
|
228
|
-
const tasks = targets.map((target) => ({
|
|
237
|
+
const tasks = targets.map((target) => ({
|
|
238
|
+
agent: target.agent,
|
|
239
|
+
task: target.task,
|
|
240
|
+
intelligence: target.intelligence,
|
|
241
|
+
}));
|
|
229
242
|
const topLevelBaseId = state.nextActiveSubagentId;
|
|
230
243
|
state.nextActiveSubagentId += tasks.length;
|
|
231
244
|
const trackedOnUpdate = trackProgress(state, toolCallId, topLevelBaseId, ctx, onUpdate);
|