@maheidem/pi-delegate 0.9.0 → 0.11.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 +15 -0
- package/README.md +59 -0
- package/extensions/application.ts +136 -17
- package/extensions/config.ts +152 -5
- package/extensions/index.ts +200 -40
- package/extensions/rpc-jsonl.ts +25 -0
- package/extensions/run-store.ts +4 -0
- package/extensions/runner.ts +67 -6
- package/extensions/types.ts +55 -0
- package/extensions/ui/event-card.ts +96 -0
- package/extensions/ui/peek-view.ts +24 -2
- package/extensions/ui/running-view.ts +119 -16
- package/package.json +1 -1
- package/roles/general.md +5 -0
- package/roles/research.md +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.11.0]
|
|
4
|
+
|
|
5
|
+
- Child configuration finally visible and editable in the TUI: the Advanced configuration panel gains a "Child — project scope (.pi/delegate/config.json)" section (child model, thinking, tools; context toggle; project-trust toggle) and the dashboard gains a read-only "Child (project pins)" section (Model / Thinking / Tools / Context / Trust). Pins show `(inherited)`/`(role ceiling)`/`(parent)` when unset.
|
|
6
|
+
- Fixed a real persistence bug: `saveProjectConfig` dropped the `child` key silently (not in its known-key set), so project-level child config could never be written through the app. It is now written, with per-field merge semantics.
|
|
7
|
+
- New `application.ts` surface: `projectChildConfig(projectRoot)` getter (validated) and `patchProjectChildConfig(projectRoot, field, rawValue)` (merge-per-field; blank clears the field; validated — model/thinking ≤128 chars, tools comma-split identifier-ish, context standard|minimal, trustProject true|false).
|
|
8
|
+
- Visual evidence is now mandatory for UI changes (AGENTS.md): one screen capture of a terminal running the extension within pi per new option before acceptance. Evidence for this release lives in `.planning/evidence/capture/` (gitignored).
|
|
9
|
+
|
|
10
|
+
## [0.10.0]
|
|
11
|
+
|
|
12
|
+
- Standard project context for children: default child args no longer pass `--no-skills`/`--no-prompt-templates`/`--no-themes` (only `child.context: "minimal"` re-disables them). Children now see the same skills, prompt templates and themes as the main session.
|
|
13
|
+
- Project-level child config: `.pi/delegate/config.json` accepts a validated `child` object (`model`, `thinking`, `tools`, `trustProject`, `context`). Resolution is per-invocation > project > parent. The resolved config is persisted in the receipt (`childConfig`) and shown in `/delegate doctor`/`inspect`/`status`.
|
|
14
|
+
- Interactive TUI for every running child (foreground + background): the foreground panel accepts follow-up messages (enter), cancel (x / esc x2) and shows the child's live provider/model/effort from a cached `get_state` RPC response (fallback to the pinned display, labeled).
|
|
15
|
+
- Better parent guidance: foreground-vs-background decision table in the tool description and promptGuidelines, README, and role prompts.
|
|
16
|
+
- Every middle-of-run informational message (delegate question/note/handoff, background progress/result) renders through a shared event-card component instead of bare text.
|
|
17
|
+
|
|
3
18
|
## [0.9.0]
|
|
4
19
|
|
|
5
20
|
- Security: strict `toolCallId` allowlist in `ask.ts` (read + write paths) — path traversal refused, fails closed.
|
package/README.md
CHANGED
|
@@ -43,6 +43,28 @@ To try a local checkout without an install, run `pi -e ./extensions/index.ts` in
|
|
|
43
43
|
|
|
44
44
|
Any unrecognized first word is shorthand for `run general …`.
|
|
45
45
|
|
|
46
|
+
### Picking the execution mode (foreground vs background)
|
|
47
|
+
|
|
48
|
+
Both modes delegate the same task to the same child; the difference is only
|
|
49
|
+
how you get the result back:
|
|
50
|
+
|
|
51
|
+
- **Foreground** (`background: false`, `/delegate fg …`) — the call blocks
|
|
52
|
+
this turn until the child finishes, and the live panel accepts follow-up
|
|
53
|
+
messages (enter → steer the child; x → arm cancel). Use it when the very
|
|
54
|
+
next step depends on the result, or you want to nudge the child
|
|
55
|
+
interactively.
|
|
56
|
+
- **Background** (`background: true`, the default for the `delegate` tool
|
|
57
|
+
and `/delegate bg …`) — the call returns a runId immediately and the
|
|
58
|
+
terminal report arrives later as a message. Use it for independent
|
|
59
|
+
parallel work, long-running exploration, or work that finishes after you
|
|
60
|
+
continue.
|
|
61
|
+
|
|
62
|
+
Always pass `description` (3–6 words) for every delegation, foreground
|
|
63
|
+
included. Use `delegate_send` to correct or redirect a **live** run — never
|
|
64
|
+
`resumeFrom` for corrections; reserve `resumeFrom` for finished runs whose
|
|
65
|
+
work you want to continue in the same session. When in doubt, choose
|
|
66
|
+
background.
|
|
67
|
+
|
|
46
68
|
### Terminal UI (v0.3.0)
|
|
47
69
|
|
|
48
70
|
One centralized experience built on the `SettingsPanel` of
|
|
@@ -280,6 +302,43 @@ never free text we hope has the right shape:
|
|
|
280
302
|
apply after `/reload` in that session — the version line makes a stale
|
|
281
303
|
copy self-evident instead of indistinguishable from a regression.
|
|
282
304
|
|
|
305
|
+
### Project-wide child config (v0.9.0)
|
|
306
|
+
|
|
307
|
+
A project file `<project>/.pi/delegate/config.json` may also pin **how the
|
|
308
|
+
child is launched** — the `child` object (all keys optional):
|
|
309
|
+
|
|
310
|
+
```json
|
|
311
|
+
{
|
|
312
|
+
"child": {
|
|
313
|
+
"model": "proj/model-id",
|
|
314
|
+
"thinking": "high",
|
|
315
|
+
"tools": ["read", "grep", "bash"],
|
|
316
|
+
"trustProject": false,
|
|
317
|
+
"context": "standard"
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
Resolution order — **per-invocation > project > parent**:
|
|
323
|
+
|
|
324
|
+
- the `delegate` tool's `model` / `thinking` parameters beat everything;
|
|
325
|
+
- the project `child` block otherwise overrides the parent's current model
|
|
326
|
+
and thinking level;
|
|
327
|
+
- `tools` replaces the role's closed ceiling (the child still always gets
|
|
328
|
+
`handoff`, and `ask_parent` when the background ask channel is enabled);
|
|
329
|
+
names the parent session does not register are dropped with a diagnostic,
|
|
330
|
+
never silently enabled;
|
|
331
|
+
- `context: "minimal"` passes `--no-skills --no-prompt-templates --no-themes`
|
|
332
|
+
to the child; **the default is standard** (project skills, prompt
|
|
333
|
+
templates and themes are kept);
|
|
334
|
+
- `trustProject` overrides the parent session's approval state for the child.
|
|
335
|
+
|
|
336
|
+
The `child` block is **project-only**: the user config never carries it
|
|
337
|
+
(an attempt to put it there is diagnosed as an unknown, ignored key). A
|
|
338
|
+
corrupt project file never breaks a delegation — the user config wins and
|
|
339
|
+
corruption is diagnosed. Tool details and `/delegate doctor` show the
|
|
340
|
+
resolved shape (model source, thinking, tools, context, trust).
|
|
341
|
+
|
|
283
342
|
## Configuration
|
|
284
343
|
|
|
285
344
|
- The user config file is `<agent dir>/delegate/config.json`. The agent dir comes from `getAgentDir()` (normally `~/.pi/agent`). The code exports the path as `CONFIG_PATH` from `extensions/config.ts`.
|
|
@@ -34,12 +34,15 @@ import type {
|
|
|
34
34
|
TranscriptRecordV1,
|
|
35
35
|
SessionEntryLike,
|
|
36
36
|
BackgroundRunHandle,
|
|
37
|
+
ChildLiveState,
|
|
38
|
+
ChildConfig,
|
|
39
|
+
ResolvedChildConfig,
|
|
37
40
|
RunState,
|
|
38
41
|
RunTerminalState,
|
|
39
42
|
} from "./types.ts";
|
|
40
43
|
import { FeedRing, type FeedEvent } from "./transcript-feed.ts";
|
|
41
44
|
import { decodeTranscriptRecord, isTerminalRunState } from "./types.ts";
|
|
42
|
-
import { applyProjectOverlay, clampConfigField, formatDuration, normalizeConfig, parseDuration, projectConfigPath, resolveRunTimeouts, saveConfig, saveProjectConfig, type DelegateConfigV1 } from "./config.ts";
|
|
45
|
+
import { applyProjectOverlay, clampConfigField, formatDuration, normalizeConfig, parseDuration, projectConfigPath, resolveChildConfig, resolveRunTimeouts, saveConfig, saveProjectConfig, validateChildConfig, type DelegateConfigV1 } from "./config.ts";
|
|
43
46
|
import { EMPTY_USAGE } from "./types.ts";
|
|
44
47
|
import { isRoleName, resolveRole, rolePromptExists, DELEGATE_ROLES } from "./roles.ts";
|
|
45
48
|
import type { DelegateRole } from "./types.ts";
|
|
@@ -173,6 +176,73 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
173
176
|
}
|
|
174
177
|
}
|
|
175
178
|
|
|
179
|
+
/** The project overlay's child config (validated), or undefined when absent/invalid. */
|
|
180
|
+
projectChildConfig(projectRoot: string): ChildConfig | undefined {
|
|
181
|
+
if (!projectRoot) return undefined;
|
|
182
|
+
let raw: unknown;
|
|
183
|
+
try {
|
|
184
|
+
raw = JSON.parse(fs.readFileSync(projectConfigPath(projectRoot), "utf8"));
|
|
185
|
+
} catch {
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
|
188
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return undefined;
|
|
189
|
+
const diagnostics: string[] = [];
|
|
190
|
+
return validateChildConfig((raw as Record<string, unknown>).child, diagnostics);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Live-edit one field of the PROJECT-level child config
|
|
195
|
+
* (`<root>/.pi/delegate/config.json` → `child.*`). Merge semantics: only
|
|
196
|
+
* the given field changes. Blank input clears the field. Returns an
|
|
197
|
+
* error string or null.
|
|
198
|
+
*/
|
|
199
|
+
patchProjectChildConfig(projectRoot: string, field: string, rawValue: string): string | null {
|
|
200
|
+
if (!projectRoot) return "No project root available.";
|
|
201
|
+
const pPath = projectConfigPath(projectRoot);
|
|
202
|
+
let project: Record<string, unknown> = {};
|
|
203
|
+
try {
|
|
204
|
+
const raw = JSON.parse(fs.readFileSync(pPath, "utf8"));
|
|
205
|
+
if (raw && typeof raw === "object" && !Array.isArray(raw)) project = raw as Record<string, unknown>;
|
|
206
|
+
} catch {
|
|
207
|
+
// missing or corrupt file: start from a fresh object (saveProjectConfig
|
|
208
|
+
// preserves corrupt files as evidence before overwriting).
|
|
209
|
+
}
|
|
210
|
+
const existing = (project.child && typeof project.child === "object" && !Array.isArray(project.child) ? project.child : {}) as Record<string, unknown>;
|
|
211
|
+
const next: Record<string, unknown> = { ...existing };
|
|
212
|
+
const raw = (rawValue ?? "").trim();
|
|
213
|
+
const known = new Set(["model", "thinking", "tools", "context", "trustProject"]);
|
|
214
|
+
if (!known.has(field)) return `Unknown child setting '${field}'. Use: model, thinking, tools, context, trustProject.`;
|
|
215
|
+
if (field === "model" || field === "thinking") {
|
|
216
|
+
if (!raw) delete next[field];
|
|
217
|
+
else if (raw.length > 128) return `${field} must be ≤ 128 characters.`;
|
|
218
|
+
else next[field] = raw;
|
|
219
|
+
} else if (field === "tools") {
|
|
220
|
+
if (!raw) delete next.tools;
|
|
221
|
+
else {
|
|
222
|
+
const tools = raw.split(",").map((t) => t.trim()).filter(Boolean);
|
|
223
|
+
const bad = tools.find((t) => !/^[A-Za-z0-9_.:-]+$/.test(t));
|
|
224
|
+
if (bad) return `tools: '${bad}' is not a valid tool name (letters, numbers, . _ - : only).`;
|
|
225
|
+
next.tools = tools;
|
|
226
|
+
}
|
|
227
|
+
} else if (field === "context") {
|
|
228
|
+
if (!raw) delete next.context;
|
|
229
|
+
else if (raw === "standard" || raw === "minimal") next.context = raw;
|
|
230
|
+
else return `context must be "standard" or "minimal".`;
|
|
231
|
+
} else if (field === "trustProject") {
|
|
232
|
+
if (!raw) delete next.trustProject;
|
|
233
|
+
else if (raw === "true" || raw === "false") next.trustProject = raw === "true";
|
|
234
|
+
else return `trustProject must be "true" or "false".`;
|
|
235
|
+
}
|
|
236
|
+
if (Object.keys(next).length === 0) delete project.child;
|
|
237
|
+
else project.child = next;
|
|
238
|
+
try {
|
|
239
|
+
saveProjectConfig(projectRoot, { child: project.child as ChildConfig | undefined } as Record<string, unknown> as Partial<DelegateConfigV1>);
|
|
240
|
+
return null;
|
|
241
|
+
} catch (error) {
|
|
242
|
+
return `Save failed: ${(error as Error).message}`;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
176
246
|
/**
|
|
177
247
|
* R22: the configured default execution mode for delegations without
|
|
178
248
|
* an explicit override (absent `background` parameter / no flag).
|
|
@@ -261,6 +331,35 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
261
331
|
return { update: this.activeStream, events: this.activeRing.all(), queue: this.runQueue.length, hardMs: this.activeRun.hardMs };
|
|
262
332
|
}
|
|
263
333
|
|
|
334
|
+
/** Host/TUI hook: send get_state to the live child (best-effort, fire-and-forget). */
|
|
335
|
+
requestChildState(): void {
|
|
336
|
+
try {
|
|
337
|
+
this.activeRun?.runner.requestChildState();
|
|
338
|
+
} catch {
|
|
339
|
+
// best-effort
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** Host/TUI hook: cached live child state (get_state) of the active run. */
|
|
344
|
+
activeRunChildState(): ChildLiveState | undefined {
|
|
345
|
+
try {
|
|
346
|
+
return this.activeRun?.runner.getChildState();
|
|
347
|
+
} catch {
|
|
348
|
+
return undefined;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
activeRunId(): string | null {
|
|
353
|
+
return this.activeRun?.id ?? null;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/** Host/TUI hook: steer the live child (follow-up message). */
|
|
357
|
+
steerActiveRun(message: string): { ok: true } | { ok: false; error: string } {
|
|
358
|
+
const runner = this.activeRun?.runner;
|
|
359
|
+
if (!runner) return { ok: false, error: "no active run to steer" };
|
|
360
|
+
return runner.steer(message);
|
|
361
|
+
}
|
|
362
|
+
|
|
264
363
|
/** Advanced knobs for the dashboard's Configure-advanced screen (§ S7). */
|
|
265
364
|
panelConfig(): Pick<DelegateConfigV1, "queueLimit" | "killGraceMs" | "handoffGraceMs" | "handoffEnforceTimeoutMs" | "stuckToolTimeoutMs" | "maxTaskBytes" | "maxResultBytes" | "updateThrottleMs" | "defaultRole" | "defaultExecution" | "maxRuns" | "maxRunAgeDays" | "progressReports"> {
|
|
266
365
|
const c = this.liveConfig;
|
|
@@ -335,7 +434,7 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
335
434
|
private async startRun(request: DelegateRequest, hooks: RunHooks = {}): Promise<RunAttemptResult> {
|
|
336
435
|
const prepared = this.prepareRun(request);
|
|
337
436
|
if ("error" in prepared) return prepared.error;
|
|
338
|
-
const { opened, role, task, model, cfg, timeoutInfo, modelNote, resumeOf, sessionPath, sessionDir } = prepared;
|
|
437
|
+
const { opened, role, task, model, cfg, timeoutInfo, modelNote, resumeOf, sessionPath, sessionDir, childConfig } = prepared;
|
|
339
438
|
const agentDir = this.ports.agentDir;
|
|
340
439
|
|
|
341
440
|
// 8. Reservation NOW covers the child lifecycle.
|
|
@@ -360,11 +459,12 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
360
459
|
role,
|
|
361
460
|
task,
|
|
362
461
|
runId: opened.metadata.runId,
|
|
363
|
-
parentModel:
|
|
462
|
+
parentModel: request.parentModel ?? "",
|
|
364
463
|
thinkingLevel: request.thinkingLevel,
|
|
365
464
|
cwd: request.cwd,
|
|
366
465
|
projectTrusted: request.projectTrusted,
|
|
367
466
|
registeredTools: this.lastRegisteredTools,
|
|
467
|
+
childConfig,
|
|
368
468
|
...(resumeOf ? { resumeOf } : {}),
|
|
369
469
|
...(sessionPath ? { sessionPath } : {}),
|
|
370
470
|
...(sessionDir ? { sessionDir } : {}),
|
|
@@ -391,7 +491,7 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
391
491
|
} catch {
|
|
392
492
|
// cleanup failure is warning-only
|
|
393
493
|
}
|
|
394
|
-
return outcomeToRunResult(outcome, opened.metadata, role.name, model, request.thinkingLevel, { timeoutInfo, modelNote, ...(request.description ? { description: request.description } : {}) });
|
|
494
|
+
return outcomeToRunResult(outcome, opened.metadata, role.name, model, request.thinkingLevel, { timeoutInfo, modelNote, ...(request.description ? { description: request.description } : {}), ...(childConfig ? { childConfig } : {}) });
|
|
395
495
|
} catch (error) {
|
|
396
496
|
this.activeRun = null;
|
|
397
497
|
return errorResult(opened.metadata.runId, role.name, "E_CHILD_EXIT", `Delegation failed unexpectedly: ${(error as Error).message}`);
|
|
@@ -405,7 +505,7 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
405
505
|
runBackground(request: DelegateRequest, hooks: { onAsk?: RunHooks["onAsk"]; onProgress?: RunHooks["onProgress"] } = {}): { error: DelegateRunResult } | { handle: BackgroundRunHandle } {
|
|
406
506
|
const prepared = this.prepareRun(request);
|
|
407
507
|
if ("error" in prepared) return { error: prepared.error };
|
|
408
|
-
const { opened, role, task, model, cfg, timeoutInfo, modelNote, resumeOf, sessionPath, sessionDir } = prepared;
|
|
508
|
+
const { opened, role, task, model, cfg, timeoutInfo, modelNote, resumeOf, sessionPath, sessionDir, childConfig } = prepared;
|
|
409
509
|
const agentDir = this.ports.agentDir;
|
|
410
510
|
// R17: ask channel plumbing — answers dir + budget env for the child.
|
|
411
511
|
const askEnabled = this.liveConfig.askParent?.enabled !== false;
|
|
@@ -422,11 +522,12 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
422
522
|
role,
|
|
423
523
|
task,
|
|
424
524
|
runId: opened.metadata.runId,
|
|
425
|
-
parentModel:
|
|
525
|
+
parentModel: request.parentModel ?? "",
|
|
426
526
|
thinkingLevel: request.thinkingLevel,
|
|
427
527
|
cwd: request.cwd,
|
|
428
528
|
projectTrusted: request.projectTrusted,
|
|
429
529
|
registeredTools: this.lastRegisteredTools,
|
|
530
|
+
childConfig,
|
|
430
531
|
...(resumeOf ? { resumeOf } : {}),
|
|
431
532
|
...(sessionPath ? { sessionPath } : {}),
|
|
432
533
|
...(sessionDir ? { sessionDir } : {}),
|
|
@@ -454,7 +555,7 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
454
555
|
} catch {
|
|
455
556
|
// cleanup failure is warning-only
|
|
456
557
|
}
|
|
457
|
-
return outcomeToRunResult(outcome, opened.metadata, role.name, model, request.thinkingLevel, { timeoutInfo, modelNote });
|
|
558
|
+
return outcomeToRunResult(outcome, opened.metadata, role.name, model, request.thinkingLevel, { timeoutInfo, modelNote, ...(childConfig ? { childConfig } : {}) });
|
|
458
559
|
},
|
|
459
560
|
(error: unknown) => {
|
|
460
561
|
this.backgroundStreams.delete(opened.metadata.runId);
|
|
@@ -494,6 +595,7 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
494
595
|
resumeOf: string | undefined;
|
|
495
596
|
sessionPath: string | undefined;
|
|
496
597
|
sessionDir: string | undefined;
|
|
598
|
+
childConfig: ResolvedChildConfig;
|
|
497
599
|
} {
|
|
498
600
|
const agentDir = this.ports.agentDir;
|
|
499
601
|
// Config cascade: project .pi/delegate/config.json overlays the
|
|
@@ -504,10 +606,11 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
504
606
|
// Strip the overlay's diagnostic keys so only real config fields
|
|
505
607
|
// reach the runner (a spurious key would survive into metadata).
|
|
506
608
|
const overlay = applyProjectOverlay(this.liveConfig, request.projectRoot);
|
|
507
|
-
const { projectOverrides, projectSetKeys, projectCorrupt, ...rest } = overlay as unknown as DelegateConfigV1 & {
|
|
609
|
+
const { projectOverrides, projectSetKeys, projectCorrupt, projectDiagnostics: _pd, ...rest } = overlay as unknown as DelegateConfigV1 & {
|
|
508
610
|
projectOverrides: string[];
|
|
509
611
|
projectSetKeys: string[];
|
|
510
612
|
projectCorrupt?: string;
|
|
613
|
+
projectDiagnostics?: string[];
|
|
511
614
|
};
|
|
512
615
|
void projectSetKeys; // display-only; run resolution uses projectOverrides
|
|
513
616
|
projectSetsHard = projectOverrides.includes("hardTimeoutMs");
|
|
@@ -550,15 +653,29 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
550
653
|
return { error: errorResult("", role.name, "E_PROJECT_UNTRUSTED", "Project is not trusted; a write-capable child cannot run. Approve trust or use the research role.") };
|
|
551
654
|
}
|
|
552
655
|
|
|
553
|
-
// 5.
|
|
554
|
-
//
|
|
555
|
-
const
|
|
656
|
+
// 5. Child config resolution (R5, project-level child config):
|
|
657
|
+
// per-invocation (tool arg) > project overlay > parent's current.
|
|
658
|
+
const childConfig =
|
|
659
|
+
request.childConfig ??
|
|
660
|
+
resolveChildConfig({
|
|
661
|
+
perInvocation: request.model ? { model: request.model } : undefined,
|
|
662
|
+
projectRoot: request.projectRoot,
|
|
663
|
+
baseConfig: this.liveConfig,
|
|
664
|
+
parentModel: request.parentModel,
|
|
665
|
+
parentThinking: request.thinkingLevel,
|
|
666
|
+
registeredTools: this.lastRegisteredTools,
|
|
667
|
+
});
|
|
668
|
+
// 5b. Model resolution: the resolved child model wins; otherwise the
|
|
669
|
+
// parent's current model is inherited as before.
|
|
670
|
+
const model = childConfig.model?.trim() || "";
|
|
556
671
|
if (!model) {
|
|
557
672
|
return { error: errorResult("", role.name, "E_MODEL_UNAVAILABLE", "No parent model available to inherit. Select or configure a model, or pass an explicit child model.") };
|
|
558
673
|
}
|
|
559
|
-
const
|
|
560
|
-
|
|
561
|
-
|
|
674
|
+
const parentModel = request.parentModel?.trim() ?? "";
|
|
675
|
+
const modelNote =
|
|
676
|
+
model !== parentModel
|
|
677
|
+
? `child model pinned to ${model} (${childConfig.modelSource === "project" ? "project child config" : "tool arg"}; parent model ${parentModel || "none"} not inherited)`
|
|
678
|
+
: undefined;
|
|
562
679
|
|
|
563
680
|
// R3: resume — re-enter a prior run's durable child session.
|
|
564
681
|
let resumeOf: string | undefined;
|
|
@@ -583,7 +700,7 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
583
700
|
// 7. Open run store entry (atomic, 0700/0600).
|
|
584
701
|
let opened;
|
|
585
702
|
try {
|
|
586
|
-
opened = openRun(agentDir, { ...request, task, role: role.name });
|
|
703
|
+
opened = openRun(agentDir, { ...request, task, role: role.name, childConfig });
|
|
587
704
|
} catch (error) {
|
|
588
705
|
return { error: errorResult("", role.name, "E_STORE", `Run store could not initialize: ${(error as Error).message}`) };
|
|
589
706
|
}
|
|
@@ -599,7 +716,7 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
599
716
|
}
|
|
600
717
|
}
|
|
601
718
|
|
|
602
|
-
return { opened, role, task, model, cfg, timeoutInfo, modelNote, resumeOf, sessionPath, sessionDir };
|
|
719
|
+
return { opened, role, task, model, cfg, timeoutInfo, modelNote, resumeOf, sessionPath, sessionDir, childConfig };
|
|
603
720
|
}
|
|
604
721
|
|
|
605
722
|
/** Queued-call introspection for status views. */
|
|
@@ -956,7 +1073,7 @@ function outcomeToRunResult(
|
|
|
956
1073
|
role: RoleName,
|
|
957
1074
|
model: string,
|
|
958
1075
|
thinkingLevel?: string,
|
|
959
|
-
provenance?: { timeoutInfo?: string; modelNote?: string; description?: string },
|
|
1076
|
+
provenance?: { timeoutInfo?: string; modelNote?: string; description?: string; childConfig?: ResolvedChildConfig },
|
|
960
1077
|
): DelegateRunResult {
|
|
961
1078
|
const ok = outcome.state === "succeeded";
|
|
962
1079
|
const details: DelegateDetails = {
|
|
@@ -978,6 +1095,8 @@ function outcomeToRunResult(
|
|
|
978
1095
|
...(provenance?.timeoutInfo ? { timeoutInfo: provenance.timeoutInfo } : {}),
|
|
979
1096
|
// R22: foreground results return the validated description inline.
|
|
980
1097
|
...(provenance?.description ? { description: provenance.description } : {}),
|
|
1098
|
+
// Resolved child config (receipt copy) — inspectable in details.
|
|
1099
|
+
...(provenance?.childConfig ? { childConfig: provenance.childConfig } : {}),
|
|
981
1100
|
transcriptPath: outcome.transcriptPath,
|
|
982
1101
|
stderrPath: outcome.stderrPath,
|
|
983
1102
|
displayItems: outcome.displayItems,
|
package/extensions/config.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import * as fs from "node:fs";
|
|
7
7
|
import * as path from "node:path";
|
|
8
8
|
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
9
|
-
import type { RoleName } from "./types.ts";
|
|
9
|
+
import type { ChildConfig, RoleName, ResolvedChildConfig } from "./types.ts";
|
|
10
10
|
import { ROLE_NAMES } from "./types.ts";
|
|
11
11
|
|
|
12
12
|
export interface DelegateConfigV1 {
|
|
@@ -46,6 +46,11 @@ export interface DelegateConfigV1 {
|
|
|
46
46
|
timeoutMs: number;
|
|
47
47
|
maxPerRun: number;
|
|
48
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* Project-level child config (from the project overlay only — the user-wide
|
|
51
|
+
* file never carries this). Validated field-by-field; defaults to absent.
|
|
52
|
+
*/
|
|
53
|
+
child?: ChildConfig;
|
|
49
54
|
}
|
|
50
55
|
|
|
51
56
|
export const DEFAULT_DELEGATE_CONFIG: DelegateConfigV1 = {
|
|
@@ -249,6 +254,131 @@ function applyKnownField(config: DelegateConfigV1, key: string, value: unknown,
|
|
|
249
254
|
) as never;
|
|
250
255
|
}
|
|
251
256
|
|
|
257
|
+
/**
|
|
258
|
+
* Validate a project-overlay `child` object field-by-field. Unknown keys are
|
|
259
|
+
* diagnosed and dropped; invalid values are dropped with diagnostics; a
|
|
260
|
+
* non-object is dropped entirely (returns undefined). Never throws.
|
|
261
|
+
*/
|
|
262
|
+
export function validateChildConfig(raw: unknown, diagnostics: string[] = []): ChildConfig | undefined {
|
|
263
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
264
|
+
if (raw !== undefined && raw !== null) diagnostics.push("child: expected an object, ignored");
|
|
265
|
+
return undefined;
|
|
266
|
+
}
|
|
267
|
+
const record = raw as Record<string, unknown>;
|
|
268
|
+
const child: ChildConfig = {};
|
|
269
|
+
for (const key of Object.keys(record)) {
|
|
270
|
+
const value = record[key];
|
|
271
|
+
if (key === "model") {
|
|
272
|
+
if (typeof value === "string" && value.trim()) child.model = value.trim();
|
|
273
|
+
else diagnostics.push("child.model: expected a non-empty string, ignored");
|
|
274
|
+
} else if (key === "thinking") {
|
|
275
|
+
if (typeof value === "string" && value.trim()) child.thinking = value.trim();
|
|
276
|
+
else diagnostics.push("child.thinking: expected a non-empty string, ignored");
|
|
277
|
+
} else if (key === "tools") {
|
|
278
|
+
if (Array.isArray(value)) {
|
|
279
|
+
const tools: string[] = [];
|
|
280
|
+
let dropped = 0;
|
|
281
|
+
for (const item of value) {
|
|
282
|
+
if (typeof item === "string" && item.trim()) tools.push(item.trim());
|
|
283
|
+
else dropped += 1;
|
|
284
|
+
}
|
|
285
|
+
if (dropped > 0) diagnostics.push(`child.tools: dropped ${dropped} non-string or empty entr${dropped === 1 ? "y" : "ies"}`);
|
|
286
|
+
child.tools = tools;
|
|
287
|
+
} else {
|
|
288
|
+
diagnostics.push("child.tools: expected an array of strings, ignored");
|
|
289
|
+
}
|
|
290
|
+
} else if (key === "trustProject") {
|
|
291
|
+
if (typeof value === "boolean") child.trustProject = value;
|
|
292
|
+
else diagnostics.push("child.trustProject: expected a boolean, ignored");
|
|
293
|
+
} else if (key === "context") {
|
|
294
|
+
if (value === "standard" || value === "minimal") child.context = value;
|
|
295
|
+
else diagnostics.push("child.context: expected \"standard\" or \"minimal\", ignored");
|
|
296
|
+
} else {
|
|
297
|
+
diagnostics.push(`child.${key}: unknown nested key, ignored`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return child;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export interface ResolveChildConfigOptions {
|
|
304
|
+
/** Per-invocation values (tool args) — highest precedence. */
|
|
305
|
+
perInvocation?: { model?: string; thinking?: string };
|
|
306
|
+
/** The user-wide base config; the project overlay merges on top of it. */
|
|
307
|
+
baseConfig?: DelegateConfigV1;
|
|
308
|
+
/** Project root to read .pi/delegate/config.json from (no overlay when absent). */
|
|
309
|
+
projectRoot?: string;
|
|
310
|
+
/** Parent's current model ("provider/model-id"). */
|
|
311
|
+
parentModel: string;
|
|
312
|
+
/** Parent's thinking level. */
|
|
313
|
+
parentThinking?: string;
|
|
314
|
+
/** Registered parent tool names (unknown child.tools names are dropped with diagnostics). */
|
|
315
|
+
registeredTools?: readonly string[];
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Resolve the effective child config for one run. Resolution order:
|
|
320
|
+
* per-invocation (tool arg) > project child config > parent's current.
|
|
321
|
+
* The project overlay supplies the tools allowlist and context/trust
|
|
322
|
+
* pins; the parent layer supplies the inherited model and thinking.
|
|
323
|
+
* Unknown tool names are dropped with diagnostics, never thrown.
|
|
324
|
+
*/
|
|
325
|
+
export function resolveChildConfig(options: ResolveChildConfigOptions): ResolvedChildConfig {
|
|
326
|
+
const diagnostics: string[] = [];
|
|
327
|
+
let projectChild: ChildConfig | undefined;
|
|
328
|
+
if (options.projectRoot) {
|
|
329
|
+
const overlay = applyProjectOverlay(options.baseConfig ?? DEFAULT_DELEGATE_CONFIG, options.projectRoot);
|
|
330
|
+
projectChild = overlay.child;
|
|
331
|
+
diagnostics.push(...(overlay.projectDiagnostics ?? []));
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const perModel = typeof options.perInvocation?.model === "string" ? options.perInvocation.model.trim() : "";
|
|
335
|
+
const perThinking = typeof options.perInvocation?.thinking === "string" ? options.perInvocation.thinking.trim() : "";
|
|
336
|
+
const projectModel = projectChild?.model?.trim() ?? "";
|
|
337
|
+
const parentModel = (options.parentModel ?? "").trim();
|
|
338
|
+
|
|
339
|
+
let model: string | undefined;
|
|
340
|
+
let modelSource: "per-invocation" | "project" | "parent" | undefined;
|
|
341
|
+
if (perModel) {
|
|
342
|
+
model = perModel;
|
|
343
|
+
modelSource = "per-invocation";
|
|
344
|
+
} else if (projectModel) {
|
|
345
|
+
model = projectModel;
|
|
346
|
+
modelSource = "project";
|
|
347
|
+
} else if (parentModel) {
|
|
348
|
+
model = parentModel;
|
|
349
|
+
modelSource = "parent";
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const projectThinking = projectChild?.thinking?.trim() ?? "";
|
|
353
|
+
const thinking = perThinking || projectThinking || (options.parentThinking?.trim() || undefined);
|
|
354
|
+
|
|
355
|
+
let tools: string[] | undefined;
|
|
356
|
+
if (projectChild?.tools !== undefined) {
|
|
357
|
+
if (options.registeredTools) {
|
|
358
|
+
const registered = new Set(options.registeredTools);
|
|
359
|
+
const unknown = projectChild.tools.filter((n) => !registered.has(n));
|
|
360
|
+
if (unknown.length > 0) diagnostics.push(`child.tools: unknown tool name(s) dropped: ${unknown.join(", ")}`);
|
|
361
|
+
tools = projectChild.tools.filter((n) => registered.has(n));
|
|
362
|
+
} else {
|
|
363
|
+
tools = [...projectChild.tools];
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const trustProject = projectChild?.trustProject;
|
|
368
|
+
const context = projectChild?.context ?? "standard";
|
|
369
|
+
|
|
370
|
+
const resolved: ResolvedChildConfig = { context };
|
|
371
|
+
if (model) {
|
|
372
|
+
resolved.model = model;
|
|
373
|
+
resolved.modelSource = modelSource;
|
|
374
|
+
}
|
|
375
|
+
if (thinking) resolved.thinking = thinking;
|
|
376
|
+
if (tools !== undefined) resolved.tools = tools;
|
|
377
|
+
if (trustProject !== undefined) resolved.trustProject = trustProject;
|
|
378
|
+
if (diagnostics.length > 0) resolved.diagnostics = diagnostics;
|
|
379
|
+
return resolved;
|
|
380
|
+
}
|
|
381
|
+
|
|
252
382
|
/** The config file of this extension: `<agent dir>/delegate/config.json`. */
|
|
253
383
|
export const CONFIG_PATH = path.join(getAgentDir(), "delegate", "config.json");
|
|
254
384
|
|
|
@@ -400,6 +530,7 @@ export function saveProjectConfig(projectRoot: string, fields: Partial<DelegateC
|
|
|
400
530
|
}
|
|
401
531
|
}
|
|
402
532
|
const known = new Set<string>(Object.keys(DEFAULT_DELEGATE_CONFIG));
|
|
533
|
+
known.add("child");
|
|
403
534
|
for (const [key, value] of Object.entries(fields)) {
|
|
404
535
|
if (known.has(key)) existing[key] = value;
|
|
405
536
|
}
|
|
@@ -457,11 +588,12 @@ export function projectConfigPath(projectRoot: string): string {
|
|
|
457
588
|
export function applyProjectOverlay(
|
|
458
589
|
base: DelegateConfigV1,
|
|
459
590
|
projectRoot: string,
|
|
460
|
-
): DelegateConfigV1 & { projectOverrides: string[]; projectSetKeys: string[]; projectCorrupt?: string } {
|
|
461
|
-
const result: DelegateConfigV1 & { projectOverrides: string[]; projectSetKeys: string[]; projectCorrupt?: string } = {
|
|
591
|
+
): DelegateConfigV1 & { projectOverrides: string[]; projectSetKeys: string[]; projectCorrupt?: string; projectDiagnostics: string[] } {
|
|
592
|
+
const result: DelegateConfigV1 & { projectOverrides: string[]; projectSetKeys: string[]; projectCorrupt?: string; projectDiagnostics: string[] } = {
|
|
462
593
|
...base,
|
|
463
594
|
projectOverrides: [],
|
|
464
595
|
projectSetKeys: [],
|
|
596
|
+
projectDiagnostics: [],
|
|
465
597
|
};
|
|
466
598
|
const pPath = projectConfigPath(projectRoot);
|
|
467
599
|
let raw: unknown;
|
|
@@ -478,12 +610,25 @@ export function applyProjectOverlay(
|
|
|
478
610
|
const known = new Set<string>(Object.keys(DEFAULT_DELEGATE_CONFIG));
|
|
479
611
|
const overrides: string[] = [];
|
|
480
612
|
const setKeys: string[] = [];
|
|
613
|
+
const childDiagnostics: string[] = [];
|
|
481
614
|
for (const key of Object.keys(record)) {
|
|
482
615
|
if (key === "schemaVersion") continue;
|
|
483
616
|
if (!knownKey(key)) continue; // unknown keys in project overlay ignored
|
|
484
617
|
// File truth: present in the project file counts as set even when the
|
|
485
618
|
// normalized value equals the base value (the override list would omit it).
|
|
486
619
|
setKeys.push(key);
|
|
620
|
+
if (key === "child") {
|
|
621
|
+
// Project-level child config: validated field-by-field, merged
|
|
622
|
+
// per-field over the base (only fields present in the file replace).
|
|
623
|
+
const validated = validateChildConfig(record[key], childDiagnostics);
|
|
624
|
+
if (validated === undefined) continue; // not an object: dropped entirely
|
|
625
|
+
const merged: ChildConfig = { ...(base.child ?? {}), ...validated };
|
|
626
|
+
if (Object.keys(merged).length > 0) {
|
|
627
|
+
result.child = merged;
|
|
628
|
+
if (JSON.stringify(merged) !== JSON.stringify(base.child ?? {})) overrides.push("child");
|
|
629
|
+
}
|
|
630
|
+
continue;
|
|
631
|
+
}
|
|
487
632
|
try {
|
|
488
633
|
const probe: DelegateConfigV1 = { ...DEFAULT_DELEGATE_CONFIG };
|
|
489
634
|
applyKnownField(probe, key, record[key]);
|
|
@@ -498,11 +643,12 @@ export function applyProjectOverlay(
|
|
|
498
643
|
}
|
|
499
644
|
result.projectOverrides = overrides;
|
|
500
645
|
result.projectSetKeys = setKeys;
|
|
646
|
+
if (childDiagnostics.length > 0) result.projectDiagnostics = childDiagnostics;
|
|
501
647
|
return result;
|
|
502
648
|
}
|
|
503
649
|
|
|
504
650
|
function knownKey(key: string): boolean {
|
|
505
|
-
return (Object.keys(DEFAULT_DELEGATE_CONFIG) as string[]).includes(key);
|
|
651
|
+
return (Object.keys(DEFAULT_DELEGATE_CONFIG) as string[]).includes(key) || key === "child";
|
|
506
652
|
}
|
|
507
653
|
|
|
508
654
|
/**
|
|
@@ -519,10 +665,11 @@ export function loadConfigCascade(
|
|
|
519
665
|
return { ...base, projectOverrides: [], projectSetKeys: [] };
|
|
520
666
|
}
|
|
521
667
|
const overlay = applyProjectOverlay(base.config, projectRoot);
|
|
522
|
-
const { projectOverrides, projectSetKeys, projectCorrupt, ...rest } = overlay as unknown as DelegateConfigV1 & {
|
|
668
|
+
const { projectOverrides, projectSetKeys, projectCorrupt, projectDiagnostics, ...rest } = overlay as unknown as DelegateConfigV1 & {
|
|
523
669
|
projectOverrides: string[];
|
|
524
670
|
projectSetKeys: string[];
|
|
525
671
|
projectCorrupt?: string;
|
|
672
|
+
projectDiagnostics?: string[];
|
|
526
673
|
};
|
|
527
674
|
const config: DelegateConfigV1 = { ...(rest as unknown as DelegateConfigV1) };
|
|
528
675
|
return {
|