@maheidem/pi-delegate 0.9.0 → 0.10.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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.10.0]
4
+
5
+ - 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.
6
+ - 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`.
7
+ - 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).
8
+ - Better parent guidance: foreground-vs-background decision table in the tool description and promptGuidelines, README, and role prompts.
9
+ - Every middle-of-run informational message (delegate question/note/handoff, background progress/result) renders through a shared event-card component instead of bare text.
10
+
3
11
  ## [0.9.0]
4
12
 
5
13
  - 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,14 @@ import type {
34
34
  TranscriptRecordV1,
35
35
  SessionEntryLike,
36
36
  BackgroundRunHandle,
37
+ ChildLiveState,
38
+ ResolvedChildConfig,
37
39
  RunState,
38
40
  RunTerminalState,
39
41
  } from "./types.ts";
40
42
  import { FeedRing, type FeedEvent } from "./transcript-feed.ts";
41
43
  import { decodeTranscriptRecord, isTerminalRunState } from "./types.ts";
42
- import { applyProjectOverlay, clampConfigField, formatDuration, normalizeConfig, parseDuration, projectConfigPath, resolveRunTimeouts, saveConfig, saveProjectConfig, type DelegateConfigV1 } from "./config.ts";
44
+ import { applyProjectOverlay, clampConfigField, formatDuration, normalizeConfig, parseDuration, projectConfigPath, resolveChildConfig, resolveRunTimeouts, saveConfig, saveProjectConfig, type DelegateConfigV1 } from "./config.ts";
43
45
  import { EMPTY_USAGE } from "./types.ts";
44
46
  import { isRoleName, resolveRole, rolePromptExists, DELEGATE_ROLES } from "./roles.ts";
45
47
  import type { DelegateRole } from "./types.ts";
@@ -261,6 +263,35 @@ export class DelegateApplicationImpl implements DelegateApplication {
261
263
  return { update: this.activeStream, events: this.activeRing.all(), queue: this.runQueue.length, hardMs: this.activeRun.hardMs };
262
264
  }
263
265
 
266
+ /** Host/TUI hook: send get_state to the live child (best-effort, fire-and-forget). */
267
+ requestChildState(): void {
268
+ try {
269
+ this.activeRun?.runner.requestChildState();
270
+ } catch {
271
+ // best-effort
272
+ }
273
+ }
274
+
275
+ /** Host/TUI hook: cached live child state (get_state) of the active run. */
276
+ activeRunChildState(): ChildLiveState | undefined {
277
+ try {
278
+ return this.activeRun?.runner.getChildState();
279
+ } catch {
280
+ return undefined;
281
+ }
282
+ }
283
+
284
+ activeRunId(): string | null {
285
+ return this.activeRun?.id ?? null;
286
+ }
287
+
288
+ /** Host/TUI hook: steer the live child (follow-up message). */
289
+ steerActiveRun(message: string): { ok: true } | { ok: false; error: string } {
290
+ const runner = this.activeRun?.runner;
291
+ if (!runner) return { ok: false, error: "no active run to steer" };
292
+ return runner.steer(message);
293
+ }
294
+
264
295
  /** Advanced knobs for the dashboard's Configure-advanced screen (§ S7). */
265
296
  panelConfig(): Pick<DelegateConfigV1, "queueLimit" | "killGraceMs" | "handoffGraceMs" | "handoffEnforceTimeoutMs" | "stuckToolTimeoutMs" | "maxTaskBytes" | "maxResultBytes" | "updateThrottleMs" | "defaultRole" | "defaultExecution" | "maxRuns" | "maxRunAgeDays" | "progressReports"> {
266
297
  const c = this.liveConfig;
@@ -335,7 +366,7 @@ export class DelegateApplicationImpl implements DelegateApplication {
335
366
  private async startRun(request: DelegateRequest, hooks: RunHooks = {}): Promise<RunAttemptResult> {
336
367
  const prepared = this.prepareRun(request);
337
368
  if ("error" in prepared) return prepared.error;
338
- const { opened, role, task, model, cfg, timeoutInfo, modelNote, resumeOf, sessionPath, sessionDir } = prepared;
369
+ const { opened, role, task, model, cfg, timeoutInfo, modelNote, resumeOf, sessionPath, sessionDir, childConfig } = prepared;
339
370
  const agentDir = this.ports.agentDir;
340
371
 
341
372
  // 8. Reservation NOW covers the child lifecycle.
@@ -360,11 +391,12 @@ export class DelegateApplicationImpl implements DelegateApplication {
360
391
  role,
361
392
  task,
362
393
  runId: opened.metadata.runId,
363
- parentModel: model,
394
+ parentModel: request.parentModel ?? "",
364
395
  thinkingLevel: request.thinkingLevel,
365
396
  cwd: request.cwd,
366
397
  projectTrusted: request.projectTrusted,
367
398
  registeredTools: this.lastRegisteredTools,
399
+ childConfig,
368
400
  ...(resumeOf ? { resumeOf } : {}),
369
401
  ...(sessionPath ? { sessionPath } : {}),
370
402
  ...(sessionDir ? { sessionDir } : {}),
@@ -391,7 +423,7 @@ export class DelegateApplicationImpl implements DelegateApplication {
391
423
  } catch {
392
424
  // cleanup failure is warning-only
393
425
  }
394
- return outcomeToRunResult(outcome, opened.metadata, role.name, model, request.thinkingLevel, { timeoutInfo, modelNote, ...(request.description ? { description: request.description } : {}) });
426
+ return outcomeToRunResult(outcome, opened.metadata, role.name, model, request.thinkingLevel, { timeoutInfo, modelNote, ...(request.description ? { description: request.description } : {}), ...(childConfig ? { childConfig } : {}) });
395
427
  } catch (error) {
396
428
  this.activeRun = null;
397
429
  return errorResult(opened.metadata.runId, role.name, "E_CHILD_EXIT", `Delegation failed unexpectedly: ${(error as Error).message}`);
@@ -405,7 +437,7 @@ export class DelegateApplicationImpl implements DelegateApplication {
405
437
  runBackground(request: DelegateRequest, hooks: { onAsk?: RunHooks["onAsk"]; onProgress?: RunHooks["onProgress"] } = {}): { error: DelegateRunResult } | { handle: BackgroundRunHandle } {
406
438
  const prepared = this.prepareRun(request);
407
439
  if ("error" in prepared) return { error: prepared.error };
408
- const { opened, role, task, model, cfg, timeoutInfo, modelNote, resumeOf, sessionPath, sessionDir } = prepared;
440
+ const { opened, role, task, model, cfg, timeoutInfo, modelNote, resumeOf, sessionPath, sessionDir, childConfig } = prepared;
409
441
  const agentDir = this.ports.agentDir;
410
442
  // R17: ask channel plumbing — answers dir + budget env for the child.
411
443
  const askEnabled = this.liveConfig.askParent?.enabled !== false;
@@ -422,11 +454,12 @@ export class DelegateApplicationImpl implements DelegateApplication {
422
454
  role,
423
455
  task,
424
456
  runId: opened.metadata.runId,
425
- parentModel: model,
457
+ parentModel: request.parentModel ?? "",
426
458
  thinkingLevel: request.thinkingLevel,
427
459
  cwd: request.cwd,
428
460
  projectTrusted: request.projectTrusted,
429
461
  registeredTools: this.lastRegisteredTools,
462
+ childConfig,
430
463
  ...(resumeOf ? { resumeOf } : {}),
431
464
  ...(sessionPath ? { sessionPath } : {}),
432
465
  ...(sessionDir ? { sessionDir } : {}),
@@ -454,7 +487,7 @@ export class DelegateApplicationImpl implements DelegateApplication {
454
487
  } catch {
455
488
  // cleanup failure is warning-only
456
489
  }
457
- return outcomeToRunResult(outcome, opened.metadata, role.name, model, request.thinkingLevel, { timeoutInfo, modelNote });
490
+ return outcomeToRunResult(outcome, opened.metadata, role.name, model, request.thinkingLevel, { timeoutInfo, modelNote, ...(childConfig ? { childConfig } : {}) });
458
491
  },
459
492
  (error: unknown) => {
460
493
  this.backgroundStreams.delete(opened.metadata.runId);
@@ -494,6 +527,7 @@ export class DelegateApplicationImpl implements DelegateApplication {
494
527
  resumeOf: string | undefined;
495
528
  sessionPath: string | undefined;
496
529
  sessionDir: string | undefined;
530
+ childConfig: ResolvedChildConfig;
497
531
  } {
498
532
  const agentDir = this.ports.agentDir;
499
533
  // Config cascade: project .pi/delegate/config.json overlays the
@@ -504,10 +538,11 @@ export class DelegateApplicationImpl implements DelegateApplication {
504
538
  // Strip the overlay's diagnostic keys so only real config fields
505
539
  // reach the runner (a spurious key would survive into metadata).
506
540
  const overlay = applyProjectOverlay(this.liveConfig, request.projectRoot);
507
- const { projectOverrides, projectSetKeys, projectCorrupt, ...rest } = overlay as unknown as DelegateConfigV1 & {
541
+ const { projectOverrides, projectSetKeys, projectCorrupt, projectDiagnostics: _pd, ...rest } = overlay as unknown as DelegateConfigV1 & {
508
542
  projectOverrides: string[];
509
543
  projectSetKeys: string[];
510
544
  projectCorrupt?: string;
545
+ projectDiagnostics?: string[];
511
546
  };
512
547
  void projectSetKeys; // display-only; run resolution uses projectOverrides
513
548
  projectSetsHard = projectOverrides.includes("hardTimeoutMs");
@@ -550,15 +585,29 @@ export class DelegateApplicationImpl implements DelegateApplication {
550
585
  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
586
  }
552
587
 
553
- // 5. Model resolution (R5): an explicit `model` pin wins; otherwise
554
- // the parent's current model is inherited as before.
555
- const model = request.model?.trim() || request.parentModel?.trim();
588
+ // 5. Child config resolution (R5, project-level child config):
589
+ // per-invocation (tool arg) > project overlay > parent's current.
590
+ const childConfig =
591
+ request.childConfig ??
592
+ resolveChildConfig({
593
+ perInvocation: request.model ? { model: request.model } : undefined,
594
+ projectRoot: request.projectRoot,
595
+ baseConfig: this.liveConfig,
596
+ parentModel: request.parentModel,
597
+ parentThinking: request.thinkingLevel,
598
+ registeredTools: this.lastRegisteredTools,
599
+ });
600
+ // 5b. Model resolution: the resolved child model wins; otherwise the
601
+ // parent's current model is inherited as before.
602
+ const model = childConfig.model?.trim() || "";
556
603
  if (!model) {
557
604
  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
605
  }
559
- const modelNote = request.model?.trim() && request.model!.trim() !== request.parentModel?.trim()
560
- ? `child model pinned to ${request.model!.trim()} (parent model ${request.parentModel || "none"} not inherited)`
561
- : undefined;
606
+ const parentModel = request.parentModel?.trim() ?? "";
607
+ const modelNote =
608
+ model !== parentModel
609
+ ? `child model pinned to ${model} (${childConfig.modelSource === "project" ? "project child config" : "tool arg"}; parent model ${parentModel || "none"} not inherited)`
610
+ : undefined;
562
611
 
563
612
  // R3: resume — re-enter a prior run's durable child session.
564
613
  let resumeOf: string | undefined;
@@ -583,7 +632,7 @@ export class DelegateApplicationImpl implements DelegateApplication {
583
632
  // 7. Open run store entry (atomic, 0700/0600).
584
633
  let opened;
585
634
  try {
586
- opened = openRun(agentDir, { ...request, task, role: role.name });
635
+ opened = openRun(agentDir, { ...request, task, role: role.name, childConfig });
587
636
  } catch (error) {
588
637
  return { error: errorResult("", role.name, "E_STORE", `Run store could not initialize: ${(error as Error).message}`) };
589
638
  }
@@ -599,7 +648,7 @@ export class DelegateApplicationImpl implements DelegateApplication {
599
648
  }
600
649
  }
601
650
 
602
- return { opened, role, task, model, cfg, timeoutInfo, modelNote, resumeOf, sessionPath, sessionDir };
651
+ return { opened, role, task, model, cfg, timeoutInfo, modelNote, resumeOf, sessionPath, sessionDir, childConfig };
603
652
  }
604
653
 
605
654
  /** Queued-call introspection for status views. */
@@ -956,7 +1005,7 @@ function outcomeToRunResult(
956
1005
  role: RoleName,
957
1006
  model: string,
958
1007
  thinkingLevel?: string,
959
- provenance?: { timeoutInfo?: string; modelNote?: string; description?: string },
1008
+ provenance?: { timeoutInfo?: string; modelNote?: string; description?: string; childConfig?: ResolvedChildConfig },
960
1009
  ): DelegateRunResult {
961
1010
  const ok = outcome.state === "succeeded";
962
1011
  const details: DelegateDetails = {
@@ -978,6 +1027,8 @@ function outcomeToRunResult(
978
1027
  ...(provenance?.timeoutInfo ? { timeoutInfo: provenance.timeoutInfo } : {}),
979
1028
  // R22: foreground results return the validated description inline.
980
1029
  ...(provenance?.description ? { description: provenance.description } : {}),
1030
+ // Resolved child config (receipt copy) — inspectable in details.
1031
+ ...(provenance?.childConfig ? { childConfig: provenance.childConfig } : {}),
981
1032
  transcriptPath: outcome.transcriptPath,
982
1033
  stderrPath: outcome.stderrPath,
983
1034
  displayItems: outcome.displayItems,
@@ -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
 
@@ -457,11 +587,12 @@ export function projectConfigPath(projectRoot: string): string {
457
587
  export function applyProjectOverlay(
458
588
  base: DelegateConfigV1,
459
589
  projectRoot: string,
460
- ): DelegateConfigV1 & { projectOverrides: string[]; projectSetKeys: string[]; projectCorrupt?: string } {
461
- const result: DelegateConfigV1 & { projectOverrides: string[]; projectSetKeys: string[]; projectCorrupt?: string } = {
590
+ ): DelegateConfigV1 & { projectOverrides: string[]; projectSetKeys: string[]; projectCorrupt?: string; projectDiagnostics: string[] } {
591
+ const result: DelegateConfigV1 & { projectOverrides: string[]; projectSetKeys: string[]; projectCorrupt?: string; projectDiagnostics: string[] } = {
462
592
  ...base,
463
593
  projectOverrides: [],
464
594
  projectSetKeys: [],
595
+ projectDiagnostics: [],
465
596
  };
466
597
  const pPath = projectConfigPath(projectRoot);
467
598
  let raw: unknown;
@@ -478,12 +609,25 @@ export function applyProjectOverlay(
478
609
  const known = new Set<string>(Object.keys(DEFAULT_DELEGATE_CONFIG));
479
610
  const overrides: string[] = [];
480
611
  const setKeys: string[] = [];
612
+ const childDiagnostics: string[] = [];
481
613
  for (const key of Object.keys(record)) {
482
614
  if (key === "schemaVersion") continue;
483
615
  if (!knownKey(key)) continue; // unknown keys in project overlay ignored
484
616
  // File truth: present in the project file counts as set even when the
485
617
  // normalized value equals the base value (the override list would omit it).
486
618
  setKeys.push(key);
619
+ if (key === "child") {
620
+ // Project-level child config: validated field-by-field, merged
621
+ // per-field over the base (only fields present in the file replace).
622
+ const validated = validateChildConfig(record[key], childDiagnostics);
623
+ if (validated === undefined) continue; // not an object: dropped entirely
624
+ const merged: ChildConfig = { ...(base.child ?? {}), ...validated };
625
+ if (Object.keys(merged).length > 0) {
626
+ result.child = merged;
627
+ if (JSON.stringify(merged) !== JSON.stringify(base.child ?? {})) overrides.push("child");
628
+ }
629
+ continue;
630
+ }
487
631
  try {
488
632
  const probe: DelegateConfigV1 = { ...DEFAULT_DELEGATE_CONFIG };
489
633
  applyKnownField(probe, key, record[key]);
@@ -498,11 +642,12 @@ export function applyProjectOverlay(
498
642
  }
499
643
  result.projectOverrides = overrides;
500
644
  result.projectSetKeys = setKeys;
645
+ if (childDiagnostics.length > 0) result.projectDiagnostics = childDiagnostics;
501
646
  return result;
502
647
  }
503
648
 
504
649
  function knownKey(key: string): boolean {
505
- return (Object.keys(DEFAULT_DELEGATE_CONFIG) as string[]).includes(key);
650
+ return (Object.keys(DEFAULT_DELEGATE_CONFIG) as string[]).includes(key) || key === "child";
506
651
  }
507
652
 
508
653
  /**
@@ -519,10 +664,11 @@ export function loadConfigCascade(
519
664
  return { ...base, projectOverrides: [], projectSetKeys: [] };
520
665
  }
521
666
  const overlay = applyProjectOverlay(base.config, projectRoot);
522
- const { projectOverrides, projectSetKeys, projectCorrupt, ...rest } = overlay as unknown as DelegateConfigV1 & {
667
+ const { projectOverrides, projectSetKeys, projectCorrupt, projectDiagnostics, ...rest } = overlay as unknown as DelegateConfigV1 & {
523
668
  projectOverrides: string[];
524
669
  projectSetKeys: string[];
525
670
  projectCorrupt?: string;
671
+ projectDiagnostics?: string[];
526
672
  };
527
673
  const config: DelegateConfigV1 = { ...(rest as unknown as DelegateConfigV1) };
528
674
  return {