@maheidem/pi-delegate 0.10.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 CHANGED
@@ -1,5 +1,12 @@
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
+
3
10
  ## [0.10.0]
4
11
 
5
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.
@@ -35,13 +35,14 @@ import type {
35
35
  SessionEntryLike,
36
36
  BackgroundRunHandle,
37
37
  ChildLiveState,
38
+ ChildConfig,
38
39
  ResolvedChildConfig,
39
40
  RunState,
40
41
  RunTerminalState,
41
42
  } from "./types.ts";
42
43
  import { FeedRing, type FeedEvent } from "./transcript-feed.ts";
43
44
  import { decodeTranscriptRecord, isTerminalRunState } from "./types.ts";
44
- import { applyProjectOverlay, clampConfigField, formatDuration, normalizeConfig, parseDuration, projectConfigPath, resolveChildConfig, 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";
45
46
  import { EMPTY_USAGE } from "./types.ts";
46
47
  import { isRoleName, resolveRole, rolePromptExists, DELEGATE_ROLES } from "./roles.ts";
47
48
  import type { DelegateRole } from "./types.ts";
@@ -175,6 +176,73 @@ export class DelegateApplicationImpl implements DelegateApplication {
175
176
  }
176
177
  }
177
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
+
178
246
  /**
179
247
  * R22: the configured default execution mode for delegations without
180
248
  * an explicit override (absent `background` parameter / no flag).
@@ -530,6 +530,7 @@ export function saveProjectConfig(projectRoot: string, fields: Partial<DelegateC
530
530
  }
531
531
  }
532
532
  const known = new Set<string>(Object.keys(DEFAULT_DELEGATE_CONFIG));
533
+ known.add("child");
533
534
  for (const [key, value] of Object.entries(fields)) {
534
535
  if (known.has(key)) existing[key] = value;
535
536
  }
@@ -1511,6 +1511,17 @@ export default function delegateExtension(pi: ExtensionAPI) {
1511
1511
  { key: "info:retention", label: "Retention", value: `${c.maxRuns} runs · ${c.maxRunAgeDays}d`, kind: "info" },
1512
1512
  ];
1513
1513
  };
1514
+ const buildChildRows = (): PanelRow[] => {
1515
+ const child = app.projectChildConfig(projectRoot);
1516
+ const effectiveTrust = child?.trustProject ?? ctx.isProjectTrusted();
1517
+ return [
1518
+ { key: "cfg:child:model", label: "Child model", value: child?.model ?? "(inherited)", rawValue: child?.model ?? "", kind: "input", inputHint: "provider/model e.g. local-mac/Qwen3.8-27B — blank clears" },
1519
+ { key: "cfg:child:thinking", label: "Child thinking", value: child?.thinking ?? "(inherited)", rawValue: child?.thinking ?? "", kind: "input", inputHint: "e.g. minimal / high — blank clears" },
1520
+ { key: "cfg:child:tools", label: "Child tools", value: child?.tools ? (child.tools.length ? child.tools.join(", ") : "(none - handoff only)") : "(role ceiling)", rawValue: child?.tools ? child.tools.join(", ") : "", kind: "input", inputHint: "comma-separated allowlist — blank = role ceiling" },
1521
+ { key: "child-context-toggle", label: "Child context", value: child?.context ?? "standard", kind: "action" },
1522
+ { key: "child-trust-toggle", label: "Child project trust", value: child?.trustProject === undefined ? `(parent: ${effectiveTrust ? "approved" : "declined"})` : (child.trustProject ? "approved" : "declined"), kind: "action" },
1523
+ ];
1524
+ };
1514
1525
  try {
1515
1526
  await ctx.ui.custom(
1516
1527
  (tui, theme, keybindings, done) =>
@@ -1520,13 +1531,15 @@ export default function delegateExtension(pi: ExtensionAPI) {
1520
1531
  initialKey: "cfg:user:queueLimit",
1521
1532
  snapshot: () => ({
1522
1533
  title: "Advanced configuration",
1523
- summaryLines: ["User-wide · ~/.pi/agent/delegate/config.json", "Esc or any action returns to Delegation"],
1524
- sections: [{ title: "Knobs", rows: buildRows() }],
1534
+ summaryLines: ["User-wide: ~/.pi/agent/delegate/config.json · Child: project overlay (.pi/delegate/config.json)", "Esc or any action returns to Delegation"],
1535
+ sections: [{ title: "Knobs", rows: buildRows() }, { title: "Child — project scope (.pi/delegate/config.json)", rows: buildChildRows() }],
1525
1536
  }),
1526
1537
  apply: (key: string, raw: string): string | null => {
1527
1538
  const m = /^cfg:user:([A-Za-z0-9]+)$/.exec(key);
1528
- if (!m) return `Unknown setting '${key}'.`;
1529
- return app.patchConfig(m[1]!, raw);
1539
+ if (m) return app.patchConfig(m[1]!, raw);
1540
+ const cm = /^cfg:child:(model|thinking|tools)$/.exec(key);
1541
+ if (cm) return app.patchProjectChildConfig(projectRoot, cm[1]!, raw);
1542
+ return `Unknown setting '${key}'.`;
1530
1543
  },
1531
1544
  activate: (key): PanelActionResult => {
1532
1545
  // R22: the execution-default toggle cycles background ⇄ foreground
@@ -1542,6 +1555,19 @@ export default function delegateExtension(pi: ExtensionAPI) {
1542
1555
  const err = app.patchProgressReportsEnabled(next);
1543
1556
  return err ? { kind: "error", message: err } : { kind: "updated", message: `Progress reports: ${next ? "on" : "off"}` };
1544
1557
  }
1558
+ if (key === "child-context-toggle") {
1559
+ const current = app.projectChildConfig(projectRoot)?.context ?? "standard";
1560
+ const next = current === "standard" ? "minimal" : "standard";
1561
+ const err = app.patchProjectChildConfig(projectRoot, "context", next);
1562
+ return err ? { kind: "error", message: err } : { kind: "updated", message: `Child context: ${next}` };
1563
+ }
1564
+ if (key === "child-trust-toggle") {
1565
+ const projectTrust = app.projectChildConfig(projectRoot)?.trustProject;
1566
+ const current = projectTrust ?? ctx.isProjectTrusted();
1567
+ const next = !current;
1568
+ const err = app.patchProjectChildConfig(projectRoot, "trustProject", String(next));
1569
+ return err ? { kind: "error", message: err } : { kind: "updated", message: `Child trust: ${next ? "approved" : "declined"}` };
1570
+ }
1545
1571
  return { kind: "close", action: "advanced-done" };
1546
1572
  },
1547
1573
  requestRender: () => tui.requestRender(),
@@ -1646,6 +1672,18 @@ export default function delegateExtension(pi: ExtensionAPI) {
1646
1672
  ],
1647
1673
  });
1648
1674
 
1675
+ const child = projectRoot ? app.projectChildConfig(projectRoot) : undefined;
1676
+ sections.push({
1677
+ title: "Child (project pins)",
1678
+ rows: [
1679
+ { key: "child-model", label: "Model", value: child?.model ?? "(inherited)", kind: "info" },
1680
+ { key: "child-thinking", label: "Thinking", value: child?.thinking ?? "(inherited)", kind: "info" },
1681
+ { key: "child-tools", label: "Tools", value: child?.tools ? (child.tools.length ? child.tools.join(", ") : "(none — handoff only)") : "(role ceiling)", kind: "info" },
1682
+ { key: "child-context", label: "Context", value: child?.context ?? "standard", kind: "info" },
1683
+ { key: "child-trust", label: "Trust", value: child?.trustProject === undefined ? "(parent)" : child.trustProject ? "approved" : "declined", kind: "info" },
1684
+ ],
1685
+ });
1686
+
1649
1687
  sections.push({
1650
1688
  title: "Timeouts (base)",
1651
1689
  rows: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maheidem/pi-delegate",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "type": "module",
5
5
  "description": "Foreground isolated delegation and strict coordinator mode for the Pi coding agent.",
6
6
  "license": "MIT",