@cydm/pie 4.0.0 → 4.2.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.
@@ -3,7 +3,7 @@ import {
3
3
  distillWorkerLogPath,
4
4
  readDistillWorkerLog,
5
5
  spawnDistillWorker
6
- } from "../../../chunks/chunk-TDKNKNPL.js";
6
+ } from "../../../chunks/chunk-PFXSA2LK.js";
7
7
  import {
8
8
  getConfigDir,
9
9
  getSettingsPath
@@ -19,8 +19,8 @@ import {
19
19
  saveAttestedEntry,
20
20
  searchMemory,
21
21
  todayKey
22
- } from "../../../chunks/chunk-FDLLNPIE.js";
23
- import "../../../chunks/chunk-WK4N5HT5.js";
22
+ } from "../../../chunks/chunk-PC6HUZAD.js";
23
+ import "../../../chunks/chunk-BK36Y35W.js";
24
24
  import "../../../chunks/chunk-NCP264ZE.js";
25
25
  import "../../../chunks/chunk-JQRZLVPY.js";
26
26
  import {
@@ -230,6 +230,7 @@ function parseStatusFile(raw) {
230
230
  if (Array.isArray(record.allowPeers) && record.allowPeers.length <= 1e3 && record.allowPeers.every((id) => typeof id === "string" && (id === "*" || isValidInstanceId(id)))) file.allowPeers = record.allowPeers;
231
231
  if (typeof record.secret === "string" && /^[a-f0-9]{64}$/.test(record.secret)) file.secret = record.secret;
232
232
  if (typeof record.sessionName === "string" && !hasControlChars(record.sessionName) && record.sessionName.length <= MAX_DISPLAY_NAME_CHARS) file.sessionName = record.sessionName;
233
+ if (typeof record.displaySessionName === "string" && !hasControlChars(record.displaySessionName) && record.displaySessionName.length <= MAX_DISPLAY_NAME_CHARS) file.displaySessionName = record.displaySessionName;
233
234
  if (typeof record.currentTool === "string" && !hasControlChars(record.currentTool) && record.currentTool.length <= 200) file.currentTool = record.currentTool;
234
235
  if (typeof record.blockedSince === "number" && Number.isSafeInteger(record.blockedSince) && record.blockedSince >= 0) file.blockedSince = record.blockedSince;
235
236
  if (typeof record.turnStartedAt === "number" && Number.isSafeInteger(record.turnStartedAt) && record.turnStartedAt >= 0) file.turnStartedAt = record.turnStartedAt;
@@ -1649,11 +1650,15 @@ var Runtime = class {
1649
1650
  });
1650
1651
  }
1651
1652
  currentStatus() {
1653
+ const liveName = this.ctx.getSessionName?.();
1654
+ if (typeof liveName === "string") this.sessionName = liveName;
1655
+ const displaySessionName = this.ctx.getSessionDisplayName?.() ?? liveName;
1652
1656
  const snapshot = this.projection.snapshot({
1653
1657
  ...this.statusBase,
1654
1658
  displayName: this.displayName,
1655
1659
  sessionId: this.sessionId,
1656
- sessionName: this.sessionName
1660
+ sessionName: this.sessionName,
1661
+ ...displaySessionName ? { displaySessionName } : {}
1657
1662
  });
1658
1663
  return { ...snapshot, allowPeers: [...this.allowPolicy.snapshot()], undeliveredInjections: this.delivery?.undeliveredInjections ?? snapshot.undeliveredInjections ?? 0 };
1659
1664
  }
@@ -2038,8 +2043,12 @@ ${body}` : ""}`;
2038
2043
  const listings = listPeers(this.discoveryDir, { selfId: this.instanceId, pruneDead: false });
2039
2044
  if (listings.length === 0) return "No pie-ipc peers discovered.";
2040
2045
  const lines = listings.map(({ file, health }) => {
2041
- const label = peerLabel(file.instanceId, file.displayName);
2042
- const bits = [`${label} [${health}] ${file.state}`];
2046
+ const fileRecord = file;
2047
+ const humanName = typeof fileRecord.displaySessionName === "string" && fileRecord.displaySessionName.trim() ? fileRecord.displaySessionName.trim() : void 0;
2048
+ const label = humanName ?? peerLabel(file.instanceId, file.displayName);
2049
+ const project = typeof file.cwd === "string" && file.cwd.trim() ? file.cwd.trim().split("/").filter(Boolean).pop() : void 0;
2050
+ const bits = [`${label} [${health}] ${file.state}${project ? ` \xB7 ${project}` : ""}`];
2051
+ if (this.allowPolicy.allows(file.instanceId) && typeof file.sessionName === "string" && file.sessionName.trim()) bits.push(`address=${file.sessionName.trim()}`);
2043
2052
  if (this.allowPolicy.allows(file.instanceId) && file.currentTool) bits.push(`tool=${file.currentTool}`);
2044
2053
  if (this.allowPolicy.allows(file.instanceId) && file.blockedSince !== void 0) bits.push(`blocked ${Math.max(0, Math.round((Date.now() - file.blockedSince) / 1e3))}s`);
2045
2054
  if (this.allowPolicy.allows(file.instanceId) && file.sessionId) bits.push(`session=${file.sessionId.slice(0, 8)}`);
@@ -56,6 +56,19 @@ the concierge). One-shot print hosts never own workers.
56
56
  - `killGraceMs`: force-kill escalation window after SIGTERM.
57
57
  - `defaultTtlMs`: idle TTL applied when a spawn omits `ttlMs` (0 = never).
58
58
 
59
+ **The file is re-read on every use (spawn, sweep, kill), so edits take effect
60
+ without restarting the host.** That matters on a fresh machine: the config is
61
+ usually written *after* a resident host booted, and a load-time snapshot would
62
+ make it permanently invisible. A missing or unreadable file means an empty
63
+ `allowCwd` — every spawn is refused (fail-closed) with a message that says
64
+ whether the file is missing or simply lacks the cwd, and how to write it.
65
+
66
+ `pie concierge` seeds this file on first run when it is absent, with
67
+ `allowCwd` set to the directory `pie concierge` was launched from — otherwise
68
+ a new machine can chat with the concierge but never dispatch a worker. It
69
+ never seeds `$HOME` or `/` (that is a security decision for the operator) and
70
+ never overwrites an existing file.
71
+
59
72
  ## Registry v2 & audit
60
73
 
61
74
  `~/.pie/pie-proc/` holds a LOCK-FREE compare-and-swap registry: each
@@ -180,7 +180,13 @@ function cwdAllowedOrThrow(cwd, allow) {
180
180
  } catch {
181
181
  }
182
182
  }
183
- throw new Error(`cwd "${cwd}" (canonical ${canonical}) is outside the pie-proc allowCwd roots; edit ${path.join(configDirRoot(), "pie-proc.json")}`);
183
+ const file = path.join(configDirRoot(), "pie-proc.json");
184
+ let exists = false;
185
+ try {
186
+ exists = fs.existsSync(file);
187
+ } catch {
188
+ }
189
+ throw new Error(exists ? `cwd "${cwd}" (canonical ${canonical}) is outside the pie-proc allowCwd roots in ${file}; edit that file \u2014 it is re-read on every spawn, so no host restart is needed` : `cwd "${cwd}" is outside the pie-proc allowCwd roots: there is no config yet at ${file}. Create it with {"allowCwd": ["${cwd}"]} \u2014 it is read on every spawn, so no host restart is needed`);
184
190
  }
185
191
  function safeName(name) {
186
192
  return /^[a-z0-9][a-z0-9-_]{0,47}$/i.test(name);
@@ -235,7 +241,7 @@ function pieProc(ctx) {
235
241
  if (!ctx.capabilities.longLived) {
236
242
  return;
237
243
  }
238
- const config = readConfig();
244
+ const currentConfig = () => readConfig();
239
245
  const abortedGenerations = /* @__PURE__ */ new Set();
240
246
  const observeActivity = (record) => {
241
247
  const logTime = (() => {
@@ -333,7 +339,7 @@ function pieProc(ctx) {
333
339
  changed = true;
334
340
  continue;
335
341
  }
336
- const ttl = w.kind === "resident" ? w.ttlMs ?? config.defaultTtlMs : 0;
342
+ const ttl = w.kind === "resident" ? w.ttlMs ?? currentConfig().defaultTtlMs : 0;
337
343
  if (ttl > 0 && liveness === "alive" && cutoff - Math.max(w.lastActiveAt, observeActivity(w)) > ttl) {
338
344
  try {
339
345
  process.kill(w.pid, "SIGTERM");
@@ -364,7 +370,7 @@ function pieProc(ctx) {
364
370
  if (params.kind === "oneshot" && params.task.startsWith("-")) throw new Error(`oneshot task must not start with "-" (got "${params.task.slice(0, 20)}\u2026")`);
365
371
  if (params.kind === "oneshot" && params.imForward) throw new Error("imForward applies to resident workers only");
366
372
  if (params.kind !== "resident" && params.ttlMs !== void 0) throw new Error("ttlMs applies to resident workers only");
367
- const canonicalCwd = cwdAllowedOrThrow(params.cwd, config.allowCwd);
373
+ const canonicalCwd = cwdAllowedOrThrow(params.cwd, currentConfig().allowCwd);
368
374
  const entry = cliEntry();
369
375
  if (!entry) throw new Error("cannot resolve a trusted pie entry point (refusing to spawn)");
370
376
  const generation = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
@@ -393,8 +399,8 @@ function pieProc(ctx) {
393
399
  if (sameName === w) return false;
394
400
  return w.pid === 0 || workerLiveness(w) !== "dead";
395
401
  });
396
- if (live.length >= config.maxWorkers) {
397
- return { abort: { error: new Error(`worker cap reached (${config.maxWorkers}); kill an idle worker first (pie_proc kill)`) } };
402
+ if (live.length >= currentConfig().maxWorkers) {
403
+ return { abort: { error: new Error(`worker cap reached (${currentConfig().maxWorkers}); kill an idle worker first (pie_proc kill)`) } };
398
404
  }
399
405
  const others = current.filter((w) => {
400
406
  if (sameName === w) return false;
@@ -431,6 +437,20 @@ function pieProc(ctx) {
431
437
  }
432
438
  }
433
439
  }
440
+ if (params.kind === "resident") {
441
+ const imFile = path.join(pieDir, "im-forward.json");
442
+ try {
443
+ if (fs.existsSync(imFile)) {
444
+ const existing = JSON.parse(fs.readFileSync(imFile, "utf8"));
445
+ if (existing.outboundMode === void 0) {
446
+ existing.outboundMode = "mirror";
447
+ fs.writeFileSync(imFile, JSON.stringify(existing, null, " "));
448
+ ctx.log(`pie-proc: migrated worker IM config to outboundMode=mirror (${params.name})`);
449
+ }
450
+ }
451
+ } catch {
452
+ }
453
+ }
434
454
  if (imForward) {
435
455
  const imFile = path.join(pieDir, "im-forward.json");
436
456
  if (!fs.existsSync(imFile)) {
@@ -442,6 +462,13 @@ function pieProc(ctx) {
442
462
  const doc = {
443
463
  enabled: imForward.enabled === true,
444
464
  provider,
465
+ // MULTI-AGENT IM §3 (review r1 P1-5): a spawned WORKER sharing the
466
+ // app binding must never be a second gateway. The unattended
467
+ // default would make every resident worker one (it forwards every
468
+ // settled turn — exactly the dispatch-result flood this design
469
+ // exists to kill). mirror = it speaks only where the user spoke to
470
+ // IT first; the dispatching concierge remains the single voice.
471
+ outboundMode: "mirror",
445
472
  providers: { [provider]: providerSettings }
446
473
  };
447
474
  if (typeof imForward.retryBackoffMs === "number") doc.retryBackoffMs = imForward.retryBackoffMs;
@@ -456,7 +483,12 @@ function pieProc(ctx) {
456
483
  ...process.env,
457
484
  PIE_CODING_AGENT_DIR: pieDir,
458
485
  PIE_IPC_CONFIG_DIR: inheritedIpcRoot,
459
- PIE_IPC_DISPLAY_NAME: params.kind === "resident" ? params.name : process.env.PIE_IPC_DISPLAY_NAME
486
+ PIE_IPC_DISPLAY_NAME: params.kind === "resident" ? params.name : process.env.PIE_IPC_DISPLAY_NAME,
487
+ // MULTI-AGENT IM §2 (review r1 P2-2): the dispatcher names the
488
+ // worker at spawn — the athlete never manages its own name tag.
489
+ // The child applies it as a CURATED session name (see
490
+ // json-events-mode startup), which never outranks a human rename.
491
+ PIE_PROC_CURATED_NAME: params.name
460
492
  };
461
493
  if (params.kind === "oneshot") childEnv[ONESHOT_TASK_ENV] = params.task ?? "";
462
494
  try {
@@ -546,7 +578,7 @@ function pieProc(ctx) {
546
578
  } catch {
547
579
  }
548
580
  if (!opts.force) {
549
- const deadline = Date.now() + config.killGraceMs;
581
+ const deadline = Date.now() + currentConfig().killGraceMs;
550
582
  while (Date.now() < deadline) {
551
583
  await new Promise((r) => setTimeout(r, 300));
552
584
  if (workerLiveness(target) === "dead") break;
@@ -597,7 +629,7 @@ function pieProc(ctx) {
597
629
  kind: w.kind,
598
630
  status: w.pid === 0 ? `pending (reserver ${w.reserverPid ?? "?"})` : workerLiveness(w),
599
631
  idleSeconds: Math.round((Date.now() - Math.max(w.lastActiveAt, observeActivity(w))) / 1e3),
600
- ttlMs: w.kind === "resident" ? w.ttlMs ?? config.defaultTtlMs : 0,
632
+ ttlMs: w.kind === "resident" ? w.ttlMs ?? currentConfig().defaultTtlMs : 0,
601
633
  im: Boolean(w.imForward)
602
634
  }));
603
635
  return { content: [{ type: "text", text: rows.length === 0 ? "No pie-proc workers registered." : JSON.stringify(rows, null, 2) }], details: {} };
@@ -6,8 +6,8 @@ import {
6
6
  createPlanCapability,
7
7
  markCompletedPlanSteps,
8
8
  restoreExecutionState
9
- } from "../../../chunks/chunk-FDLLNPIE.js";
10
- import "../../../chunks/chunk-WK4N5HT5.js";
9
+ } from "../../../chunks/chunk-PC6HUZAD.js";
10
+ import "../../../chunks/chunk-BK36Y35W.js";
11
11
  import "../../../chunks/chunk-NCP264ZE.js";
12
12
  import "../../../chunks/chunk-JQRZLVPY.js";
13
13
  import {
@@ -5,7 +5,7 @@ import {
5
5
  createCliRetryPolicy,
6
6
  formatTransportLifecycle,
7
7
  logTransportLifecycle
8
- } from "../../../chunks/chunk-UOZHQ73X.js";
8
+ } from "../../../chunks/chunk-J2LGVYH2.js";
9
9
  import {
10
10
  getConfigDir
11
11
  } from "../../../chunks/chunk-ILUHTKF3.js";
@@ -14,8 +14,8 @@ import {
14
14
  createPolicyEnforcedTools,
15
15
  createSharedFileSystemTools,
16
16
  createSubagentCapability
17
- } from "../../../chunks/chunk-FDLLNPIE.js";
18
- import "../../../chunks/chunk-WK4N5HT5.js";
17
+ } from "../../../chunks/chunk-PC6HUZAD.js";
18
+ import "../../../chunks/chunk-BK36Y35W.js";
19
19
  import "../../../chunks/chunk-NCP264ZE.js";
20
20
  import "../../../chunks/chunk-JQRZLVPY.js";
21
21
  import "../../../chunks/chunk-XXGYUYXI.js";
@@ -8,8 +8,8 @@ import {
8
8
  executeManageTodoList,
9
9
  executionStateToTodos,
10
10
  restoreExecutionState
11
- } from "../../../chunks/chunk-FDLLNPIE.js";
12
- import "../../../chunks/chunk-WK4N5HT5.js";
11
+ } from "../../../chunks/chunk-PC6HUZAD.js";
12
+ import "../../../chunks/chunk-BK36Y35W.js";
13
13
  import "../../../chunks/chunk-NCP264ZE.js";
14
14
  import "../../../chunks/chunk-JQRZLVPY.js";
15
15
  import "../../../chunks/chunk-XXGYUYXI.js";
@@ -3607,6 +3607,18 @@ var SessionManager = class {
3607
3607
  if (!this.sessionId) return node?.entry.label;
3608
3608
  return this.store.getEntrySummary(this.sessionId, entryId)?.label ?? node?.entry.label;
3609
3609
  }
3610
+ /** Set a CURATED name (concierge on behalf of the operator, multi-agent IM
3611
+ * design): display-authoritative and never replaced by auto-derivation,
3612
+ * but a human rename (setSessionName) outranks it. */
3613
+ setCuratedSessionName(name) {
3614
+ if (!this.metadata) {
3615
+ throw new Error("No active session");
3616
+ }
3617
+ if (this.metadata.nameSource === "manual") return;
3618
+ this.metadata.name = name;
3619
+ this.metadata.nameSource = "curated";
3620
+ this.isDirty = true;
3621
+ }
3610
3622
  /** Set a manual display name for the active session (never auto-overwritten). */
3611
3623
  setSessionName(name) {
3612
3624
  if (!this.metadata) {
@@ -3619,6 +3631,25 @@ var SessionManager = class {
3619
3631
  getSessionName() {
3620
3632
  return this.metadata?.nameSource === "manual" ? this.metadata.name : void 0;
3621
3633
  }
3634
+ /** The best name a HUMAN-FACING surface should display (multi-agent IM
3635
+ * design, 2026-11-09): manual > generated > derived. Unlike
3636
+ * getSessionName() — which is the ROUTING identity and stays
3637
+ * manual-only, because the im-forward address book treats "published
3638
+ * name" as a stable routing key — this is presentation-only: it may
3639
+ * change when a derived title is recomputed, and nothing routes on it.
3640
+ * Returns undefined when even metadata is absent; callers fall back to
3641
+ * their own id-tail labels. */
3642
+ getSessionDisplayName() {
3643
+ if (!this.metadata?.name) return void 0;
3644
+ const source = this.metadata.nameSource;
3645
+ if (source === "manual" || source === "curated" || source === "derived") {
3646
+ return this.metadata.name;
3647
+ }
3648
+ if (source === void 0 && !isAutoGeneratedSessionName(this.metadata.name)) {
3649
+ return this.metadata.name;
3650
+ }
3651
+ return void 0;
3652
+ }
3622
3653
  /**
3623
3654
  * Replace the active context with an explicit message list. Pending
3624
3655
  * entries are committed first, then the replacement messages are appended
@@ -10,10 +10,10 @@ import {
10
10
  createSharedWebSearchTool,
11
11
  defaultShellKindForPlatform,
12
12
  interpretShellExit
13
- } from "./chunk-FDLLNPIE.js";
13
+ } from "./chunk-PC6HUZAD.js";
14
14
  import {
15
15
  requestInteraction
16
- } from "./chunk-WK4N5HT5.js";
16
+ } from "./chunk-BK36Y35W.js";
17
17
  import {
18
18
  EMPTY_ASSISTANT_CONTENT_ERROR,
19
19
  OPENAI_COMPAT_PROTOCOL_ERROR_CODE,
@@ -13,7 +13,7 @@ import {
13
13
  parseEntryIdSeq,
14
14
  readAncestryPage,
15
15
  requestInteraction
16
- } from "./chunk-WK4N5HT5.js";
16
+ } from "./chunk-BK36Y35W.js";
17
17
  import {
18
18
  Agent,
19
19
  getToolCallerIdentity
@@ -174,8 +174,8 @@ async function runDistillWorkerMain(memoryRoot, date, noExit = false) {
174
174
  const { ModelRegistry } = await import("./model-registry-YA6U366L.js");
175
175
  const { AuthStorage } = await import("./auth-storage-3EGM3VTK.js");
176
176
  const { getSessionsDir } = await import("./config-74AUVDLT.js");
177
- const { FileSessionStore } = await import("./src-ZZZO4HSR.js");
178
- const { MemoryStore, runDistillation } = await import("./src-AB7PLORG.js");
177
+ const { FileSessionStore } = await import("./src-VPMIQGEW.js");
178
+ const { MemoryStore, runDistillation } = await import("./src-AQ4H43UM.js");
179
179
  const store = new MemoryStore(memoryRoot);
180
180
  ledger = store;
181
181
  const registry = new ModelRegistry(AuthStorage.create());
@@ -252,7 +252,7 @@ async function runDistillAuto(memoryRoot, days = 7) {
252
252
  } catch {
253
253
  }
254
254
  };
255
- const { MemoryStore, todayKey } = await import("./src-AB7PLORG.js");
255
+ const { MemoryStore, todayKey } = await import("./src-AQ4H43UM.js");
256
256
  const store = new MemoryStore(memoryRoot);
257
257
  const today = todayKey(Date.now());
258
258
  const dates = [];