@cydm/pie 4.14.0 → 4.14.1

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.
Files changed (30) hide show
  1. package/dist/builtin/extensions/ask-user/index.js +4 -4
  2. package/dist/builtin/extensions/cron/index.js +70 -17
  3. package/dist/builtin/extensions/im-forward/index.js +8 -8
  4. package/dist/builtin/extensions/memory/index.js +6 -6
  5. package/dist/builtin/extensions/pie-proc/README.md +12 -3
  6. package/dist/builtin/extensions/pie-proc/index.js +88 -45
  7. package/dist/builtin/extensions/plan-mode/index.js +4 -4
  8. package/dist/builtin/extensions/subagent/index.js +5 -5
  9. package/dist/builtin/extensions/todo/index.js +4 -4
  10. package/dist/chunks/{chunk-BOQIGMGQ.js → chunk-2WLKAMOH.js} +3 -3
  11. package/dist/chunks/{chunk-IK2FR2YF.js → chunk-DJ4LO7PQ.js} +1 -1
  12. package/dist/chunks/{chunk-MCR4JYI6.js → chunk-IM7DLPPY.js} +74 -8
  13. package/dist/chunks/{chunk-FD3KBPDR.js → chunk-IQDVL34H.js} +7 -7
  14. package/dist/chunks/{chunk-JKO42HZW.js → chunk-OQCKDEEE.js} +1 -1
  15. package/dist/chunks/{chunk-26KRUYZH.js → chunk-SAXKBFX3.js} +1 -1
  16. package/dist/chunks/{chunk-JJH77AUU.js → chunk-SYZR74QO.js} +4 -4
  17. package/dist/chunks/{chunk-KGWKRO7Z.js → chunk-TNRZEQD5.js} +2 -2
  18. package/dist/chunks/{chunk-UYDS75SI.js → chunk-TTSQWGAT.js} +2 -1
  19. package/dist/chunks/{chunk-EZZTMDWZ.js → chunk-X3ZVZB2R.js} +435 -17
  20. package/dist/chunks/{host-image-fallback-LPHB5CTL.js → host-image-fallback-AEKY2LSZ.js} +1 -1
  21. package/dist/chunks/{memory-git-ZJN6SPIU.js → memory-git-G56IXFWU.js} +5 -5
  22. package/dist/chunks/{model-registry-GLBIUOJR.js → model-registry-4LM2I6FR.js} +2 -2
  23. package/dist/chunks/{read-file-understanding-DFJPTTSB.js → read-file-understanding-GTNZHAK5.js} +5 -5
  24. package/dist/chunks/{src-KZ7YID3I.js → src-3YJ4UVEC.js} +3 -3
  25. package/dist/chunks/{src-ALHMJZ5R.js → src-APNP4M4N.js} +2 -2
  26. package/dist/chunks/{src-LEXKDSFV.js → src-T6AUO53N.js} +4 -4
  27. package/dist/chunks/{src-76Q33OY5.js → src-TNUD7EDH.js} +1 -1
  28. package/dist/chunks/{test-stream-OVGDTXOY.js → test-stream-EF2DHEHV.js} +1 -1
  29. package/dist/cli.js +16 -16
  30. package/package.json +1 -1
@@ -1,10 +1,10 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  createAskUserCapability
4
- } from "../../../chunks/chunk-EZZTMDWZ.js";
5
- import "../../../chunks/chunk-JJH77AUU.js";
6
- import "../../../chunks/chunk-26KRUYZH.js";
7
- import "../../../chunks/chunk-MCR4JYI6.js";
4
+ } from "../../../chunks/chunk-X3ZVZB2R.js";
5
+ import "../../../chunks/chunk-SYZR74QO.js";
6
+ import "../../../chunks/chunk-SAXKBFX3.js";
7
+ import "../../../chunks/chunk-IM7DLPPY.js";
8
8
  import "../../../chunks/chunk-XXGYUYXI.js";
9
9
  import "../../../chunks/chunk-LZQXQOPJ.js";
10
10
 
@@ -127,20 +127,27 @@ function sweepStaleOwners(state, dir, opts = {}) {
127
127
  if (dead) {
128
128
  reaped.push({ key, sessionId: row.sessionId, reason: `pid ${parsed.pid} provably dead` });
129
129
  delete state.owners[key];
130
+ try {
131
+ fs.rmSync(liveness, { force: true });
132
+ } catch {
133
+ }
130
134
  }
131
135
  } catch {
132
136
  }
133
137
  }
134
138
  return reaped;
135
139
  }
140
+ var DEFAULT_MAX_AUDIT_LOG_BYTES = 2 * 1024 * 1024;
136
141
  var Store = class {
137
142
  constructor(dir, opts) {
138
143
  this.dir = dir;
139
144
  this.verifyDir = opts?.verifyDir;
145
+ this.maxAuditBytes = opts?.maxAuditBytes ?? DEFAULT_MAX_AUDIT_LOG_BYTES;
140
146
  if (opts?.createDir !== false) fs.mkdirSync(dir, { recursive: true, mode: 448 });
141
147
  }
142
148
  dir;
143
149
  verifyDir;
150
+ maxAuditBytes;
144
151
  /** Durable, append-only audit trail for operator-visible cron decisions.
145
152
  *
146
153
  * Why a file and not `ctx.log`: ctx.log only prints when PIE_VERBOSE is set
@@ -153,25 +160,62 @@ var Store = class {
153
160
  * failed audit write can never leave an unlogged change behind. A failure
154
161
  * therefore refuses the mutation (fail-closed, like the rest of the store). */
155
162
  audit(record) {
156
- this.verifyDir?.();
157
- const auditPath = path.join(this.dir, "audit.log");
158
- if (fs.existsSync(auditPath)) {
159
- const st = fs.lstatSync(auditPath);
160
- if (st.isSymbolicLink() || !st.isFile()) {
161
- throw new Error("refusing to write audit log to non-regular file");
163
+ this.withAuditLock(() => {
164
+ const auditPath = path.join(this.dir, "audit.log");
165
+ let st;
166
+ try {
167
+ st = fs.lstatSync(auditPath);
168
+ } catch (error) {
169
+ if (error?.code !== "ENOENT") throw error;
162
170
  }
163
- }
164
- const flags = fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_APPEND | (fs.constants.O_NOFOLLOW ?? 0) | (fs.constants.O_NONBLOCK ?? 0);
165
- const fd = fs.openSync(auditPath, flags, 384);
171
+ if (st) {
172
+ if (st.isSymbolicLink() || !st.isFile()) {
173
+ throw new Error("refusing to write audit log to non-regular file");
174
+ }
175
+ if (st.nlink === 1 && st.size >= this.maxAuditBytes) {
176
+ const rotatedPath = `${auditPath}.1`;
177
+ let rotStat;
178
+ try {
179
+ rotStat = fs.lstatSync(rotatedPath);
180
+ } catch (error) {
181
+ if (error?.code !== "ENOENT") throw error;
182
+ }
183
+ if (rotStat && (rotStat.isSymbolicLink() || !rotStat.isFile())) {
184
+ throw new Error("refusing to rotate audit log over non-regular file");
185
+ }
186
+ try {
187
+ fs.renameSync(auditPath, rotatedPath);
188
+ } catch (error) {
189
+ if (error?.code !== "ENOENT") throw error;
190
+ }
191
+ }
192
+ }
193
+ const flags = fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_APPEND | (fs.constants.O_NOFOLLOW ?? 0) | (fs.constants.O_NONBLOCK ?? 0);
194
+ const fd = fs.openSync(auditPath, flags, 384);
195
+ try {
196
+ const fdStat = fs.fstatSync(fd);
197
+ if (!fdStat.isFile() || fdStat.nlink !== 1) throw new Error("audit log target is not a single-link regular file");
198
+ this.verifyDir?.();
199
+ const line = `${JSON.stringify({ at: Date.now(), ...record })}
200
+ `;
201
+ fs.writeFileSync(fd, line);
202
+ } finally {
203
+ fs.closeSync(fd);
204
+ }
205
+ });
206
+ }
207
+ /** Dedicated leaf-level cross-process mutex for audit.log stat/rotate/append.
208
+ * Never acquires write.lock inside it, so both in-transaction and standalone
209
+ * audit callers serialize cleanly without deadlock risk. */
210
+ withAuditLock(fn) {
211
+ this.verifyDir?.();
212
+ const lock = path.join(this.dir, "audit.lock");
213
+ const token = this.acquireWriteLock(lock);
166
214
  try {
167
- const fdStat = fs.fstatSync(fd);
168
- if (!fdStat.isFile() || fdStat.nlink !== 1) throw new Error("audit log target is not a single-link regular file");
169
215
  this.verifyDir?.();
170
- const line = `${JSON.stringify({ at: Date.now(), ...record })}
171
- `;
172
- fs.writeFileSync(fd, line);
216
+ return fn();
173
217
  } finally {
174
- fs.closeSync(fd);
218
+ this.releaseWriteLock(lock, token);
175
219
  }
176
220
  }
177
221
  /** Serialized bytes of the state currently on disk; undefined until the
@@ -230,7 +274,7 @@ var Store = class {
230
274
  * (before the rename); it is inert — the protocol never consults it. */
231
275
  acquireWriteLock(lock) {
232
276
  const token = randomUUID();
233
- const candidate = path.join(this.dir, `write.lock.acquire.${token}`);
277
+ const candidate = path.join(this.dir, `${path.basename(lock)}.acquire.${token}`);
234
278
  const holderPath = path.join(candidate, `held.${token}`);
235
279
  let candDev;
236
280
  let candIno;
@@ -1275,6 +1319,7 @@ var delay = (ms) => new Promise((resolve3) => setTimeout(resolve3, ms));
1275
1319
  var isContention = (error) => error?.code === "EEXIST";
1276
1320
  var COORDINATOR_OWNER_FILE = "owner.json";
1277
1321
  var COORDINATOR_METADATA_GRACE_MS = 5e3;
1322
+ var STORE_OWNER_SWEEP_INTERVAL_MS = 5 * 6e4;
1278
1323
  function defaultProcessAlive(pid) {
1279
1324
  try {
1280
1325
  process.kill(pid, 0);
@@ -1329,6 +1374,7 @@ var Runtime = class {
1329
1374
  acceptedIdlePolls = 0;
1330
1375
  unreadableCoordinatorSince;
1331
1376
  coordinatorNotices = /* @__PURE__ */ new Set();
1377
+ lastOwnerSweepAt = 0;
1332
1378
  get ready() {
1333
1379
  return this.initialized && !this.stopped;
1334
1380
  }
@@ -1595,6 +1641,9 @@ var Runtime = class {
1595
1641
  state.jobs = state.jobs.filter((item) => item !== job);
1596
1642
  return;
1597
1643
  }
1644
+ if (job.state === "blocked" && job.error === error && !pending) {
1645
+ return;
1646
+ }
1598
1647
  const repeating = !("at" in job.schedule);
1599
1648
  if (!executed && repeating && !isProcessJob(job) && !job.retriedOnce) {
1600
1649
  job.retriedOnce = true;
@@ -1736,11 +1785,15 @@ Tell the user in one short message and wait for their decision. Do not resume or
1736
1785
  }
1737
1786
  }
1738
1787
  state2.owners[this.id] = { sessionId: this.sessionId, cwd: this.cwd, busy: !this.ctx.isIdle() };
1788
+ if (this.leader && (this.recovering || now - this.lastOwnerSweepAt >= STORE_OWNER_SWEEP_INTERVAL_MS)) {
1789
+ sweepStaleOwners(state2, this.store.dir, { keepKey: this.id, now });
1790
+ this.lastOwnerSweepAt = now;
1791
+ }
1739
1792
  for (const job of [...state2.jobs]) {
1740
1793
  if (isProcessJob(job)) continue;
1741
1794
  const owners = Object.entries(state2.owners).filter(([, owner]) => owner.sessionId === job.sessionId);
1742
1795
  if (this.leader && job.state === "running" && job.target === "worker" && owners.length) this.abort.abort();
1743
- if (job.enabled && owners.length > 1 && job.state !== "running") this.handleBlock(state2, job, "duplicate participating session owners; close duplicate and resume job", false);
1796
+ if (job.enabled && owners.length > 1 && job.state !== "running" && job.state !== "blocked") this.handleBlock(state2, job, "duplicate participating session owners; close duplicate and resume job", false);
1744
1797
  if (job.state === "running" && job.target === this.id && this.accepted?.id === job.id) {
1745
1798
  if (!this.accepted.consumed) {
1746
1799
  for (const message of this.ctx.getMessages?.() ?? []) this.onMessage(message);
@@ -16,7 +16,7 @@ import {
16
16
  import {
17
17
  currentWorkerLifecycleBridge,
18
18
  syncInheritedWorkerModels
19
- } from "../../../chunks/chunk-JKO42HZW.js";
19
+ } from "../../../chunks/chunk-OQCKDEEE.js";
20
20
  import {
21
21
  readProcessCommandLine
22
22
  } from "../../../chunks/chunk-7RJXKN7N.js";
@@ -29,10 +29,10 @@ import {
29
29
  readDistillWorkerLog,
30
30
  spawnDistillAutoWorker,
31
31
  spawnWikiGcWorker
32
- } from "../../../chunks/chunk-FD3KBPDR.js";
32
+ } from "../../../chunks/chunk-IQDVL34H.js";
33
33
  import {
34
34
  readCuratedMemoryGitLog
35
- } from "../../../chunks/chunk-IK2FR2YF.js";
35
+ } from "../../../chunks/chunk-DJ4LO7PQ.js";
36
36
  import {
37
37
  liveSessionHolder
38
38
  } from "../../../chunks/chunk-Q5PSWX3B.js";
@@ -43,7 +43,7 @@ import {
43
43
  } from "../../../chunks/chunk-Q4NJEPIZ.js";
44
44
  import {
45
45
  loadResolvedModelsConfig
46
- } from "../../../chunks/chunk-UYDS75SI.js";
46
+ } from "../../../chunks/chunk-TTSQWGAT.js";
47
47
  import {
48
48
  getConfigDir
49
49
  } from "../../../chunks/chunk-CBDQJMUI.js";
@@ -52,10 +52,10 @@ import {
52
52
  WikiStore,
53
53
  estimateWikiTokens,
54
54
  todayKey
55
- } from "../../../chunks/chunk-EZZTMDWZ.js";
56
- import "../../../chunks/chunk-JJH77AUU.js";
57
- import "../../../chunks/chunk-26KRUYZH.js";
58
- import "../../../chunks/chunk-MCR4JYI6.js";
55
+ } from "../../../chunks/chunk-X3ZVZB2R.js";
56
+ import "../../../chunks/chunk-SYZR74QO.js";
57
+ import "../../../chunks/chunk-SAXKBFX3.js";
58
+ import "../../../chunks/chunk-IM7DLPPY.js";
59
59
  import {
60
60
  cronActiveCount,
61
61
  cronBlockedSummary,
@@ -3,10 +3,10 @@ import {
3
3
  distillWorkerLogPath,
4
4
  readDistillWorkerLog,
5
5
  spawnDistillWorker
6
- } from "../../../chunks/chunk-FD3KBPDR.js";
6
+ } from "../../../chunks/chunk-IQDVL34H.js";
7
7
  import {
8
8
  commitCuratedMemoryBestEffort
9
- } from "../../../chunks/chunk-IK2FR2YF.js";
9
+ } from "../../../chunks/chunk-DJ4LO7PQ.js";
10
10
  import {
11
11
  getConfigDir,
12
12
  getSessionsDir,
@@ -27,12 +27,12 @@ import {
27
27
  saveAttestedEntry,
28
28
  searchMemory,
29
29
  todayKey
30
- } from "../../../chunks/chunk-EZZTMDWZ.js";
30
+ } from "../../../chunks/chunk-X3ZVZB2R.js";
31
31
  import {
32
32
  FileSessionStore
33
- } from "../../../chunks/chunk-JJH77AUU.js";
34
- import "../../../chunks/chunk-26KRUYZH.js";
35
- import "../../../chunks/chunk-MCR4JYI6.js";
33
+ } from "../../../chunks/chunk-SYZR74QO.js";
34
+ import "../../../chunks/chunk-SAXKBFX3.js";
35
+ import "../../../chunks/chunk-IM7DLPPY.js";
36
36
  import {
37
37
  Type
38
38
  } from "../../../chunks/chunk-XXGYUYXI.js";
@@ -6,8 +6,11 @@ directories, isolated agent dirs, caps, TTL sweeping, and an audit ledger.
6
6
 
7
7
  ## Host gating
8
8
 
9
- Activates on `longLived` (interactive TUI and resident json-events hosts —
10
- the manager). One-shot print hosts never own workers.
9
+ Role-pruned to the resident manager (`capabilities.unattended === true` and
10
+ `PIE_PROC_CURATED_NAME === "manager"`): both the `pie_proc` tool and the 60s
11
+ background `sweepTimer` activate only on the manager. Interactive TUI hosts,
12
+ worker processes, and one-shot print hosts never register the tool or run
13
+ background registry sweeps.
11
14
 
12
15
  ## Tool: `pie_proc`
13
16
 
@@ -85,7 +88,13 @@ fallback on Windows 11+); a probe failure is `unknown`, and unknown is
85
88
  never signalled. A v1 registry (records without generation) fails CLOSED
86
89
  with a migration error. Abandoned pending reservations are reaped only
87
90
  when their reserver process is confirmed dead (same-process aborted spawns
88
- are retried by the sweep). Every spawn/kill/TTL reap goes to the extension
91
+ are retried by the sweep). Idle-activity persistence is bounded to avoid
92
+ unbounded revision churn: `ttl === 0` resident workers never write
93
+ `lastActiveAt` bumps on log mtime changes (`pie_proc list` reads live
94
+ activity on demand), while `ttl > 0` workers throttle `lastActiveAt`
95
+ persists, maintain an in-memory high-water mark per generation, and
96
+ re-verify live activity immediately before authorizing any idle-TTL
97
+ `SIGTERM`. Every spawn/kill/TTL reap goes to the extension
89
98
  log (verbose mode / host transcript).
90
99
 
91
100
  ## Design notes
@@ -2,7 +2,7 @@ import { createRequire as __createRequire } from "node:module"; const require =
2
2
  import {
3
3
  registerWorkerLifecycleBridge,
4
4
  syncInheritedWorkerModels
5
- } from "../../../chunks/chunk-JKO42HZW.js";
5
+ } from "../../../chunks/chunk-OQCKDEEE.js";
6
6
  import {
7
7
  readProcessCommandLine
8
8
  } from "../../../chunks/chunk-7RJXKN7N.js";
@@ -11,17 +11,18 @@ import {
11
11
  } from "../../../chunks/chunk-Q5PSWX3B.js";
12
12
  import "../../../chunks/chunk-Q4NJEPIZ.js";
13
13
  import {
14
- loadResolvedModelsConfig
15
- } from "../../../chunks/chunk-UYDS75SI.js";
14
+ loadResolvedModelsConfig,
15
+ normalizeModelClassRoutes
16
+ } from "../../../chunks/chunk-TTSQWGAT.js";
16
17
  import "../../../chunks/chunk-CBDQJMUI.js";
17
18
  import {
18
19
  redactText
19
- } from "../../../chunks/chunk-EZZTMDWZ.js";
20
+ } from "../../../chunks/chunk-X3ZVZB2R.js";
20
21
  import {
21
22
  isCompactSummaryMessage
22
- } from "../../../chunks/chunk-JJH77AUU.js";
23
- import "../../../chunks/chunk-26KRUYZH.js";
24
- import "../../../chunks/chunk-MCR4JYI6.js";
23
+ } from "../../../chunks/chunk-SYZR74QO.js";
24
+ import "../../../chunks/chunk-SAXKBFX3.js";
25
+ import "../../../chunks/chunk-IM7DLPPY.js";
25
26
  import {
26
27
  Type
27
28
  } from "../../../chunks/chunk-XXGYUYXI.js";
@@ -674,12 +675,10 @@ import * as fs3 from "node:fs";
674
675
  import * as path3 from "node:path";
675
676
  var SPAWN_THINKING_LEVELS = /* @__PURE__ */ new Set(["off", "minimal", "low", "medium", "high", "xhigh", "max"]);
676
677
  var MODEL_REF_RE = /^[^/\s]+\/\S+$/;
677
- function collectModelRefsFromRaw(raw) {
678
+ function collectModelRefsFromConfig(config) {
678
679
  const refs = /* @__PURE__ */ new Set();
679
- if (!raw || typeof raw !== "object") return refs;
680
- const doc = raw;
681
- if (doc.providers && typeof doc.providers === "object") {
682
- for (const [provider, cfg] of Object.entries(doc.providers)) {
680
+ if (config.profiles) {
681
+ for (const [provider, cfg] of Object.entries(config.profiles)) {
683
682
  if (!Array.isArray(cfg?.models)) continue;
684
683
  for (const m of cfg.models) {
685
684
  if (typeof m?.id === "string" && m.id.trim()) {
@@ -688,15 +687,15 @@ function collectModelRefsFromRaw(raw) {
688
687
  }
689
688
  }
690
689
  }
691
- if (doc.defaults && typeof doc.defaults === "object") {
692
- if (typeof doc.defaults.provider === "string" && typeof doc.defaults.modelId === "string") {
693
- refs.add(`${doc.defaults.provider.trim()}/${doc.defaults.modelId.trim()}`);
694
- }
695
- if (doc.defaults.modelClasses && typeof doc.defaults.modelClasses === "object") {
696
- for (const entry of Object.values(doc.defaults.modelClasses)) {
697
- const list = Array.isArray(entry) ? entry : [entry];
698
- for (const cls of list) {
699
- if (typeof cls?.provider === "string" && typeof cls?.modelId === "string") {
690
+ if (config.defaults) {
691
+ if (typeof config.defaults.provider === "string" && typeof config.defaults.modelId === "string") {
692
+ refs.add(`${config.defaults.provider.trim()}/${config.defaults.modelId.trim()}`);
693
+ }
694
+ if (config.defaults.modelClasses) {
695
+ for (const entry of Object.values(config.defaults.modelClasses)) {
696
+ for (const cls of normalizeModelClassRoutes(entry)) {
697
+ if (!cls || typeof cls !== "object") continue;
698
+ if (typeof cls.provider === "string" && typeof cls.modelId === "string") {
700
699
  refs.add(`${cls.provider.trim()}/${cls.modelId.trim()}`);
701
700
  }
702
701
  }
@@ -705,17 +704,39 @@ function collectModelRefsFromRaw(raw) {
705
704
  }
706
705
  return refs;
707
706
  }
707
+ function collectModelRefsFromMinimalFixture(raw) {
708
+ const refs = /* @__PURE__ */ new Set();
709
+ if (!raw || typeof raw !== "object") return refs;
710
+ const doc = raw;
711
+ for (const group of [doc.profiles, doc.providers]) {
712
+ if (!group || typeof group !== "object") continue;
713
+ for (const [provider, cfg] of Object.entries(group)) {
714
+ if (!Array.isArray(cfg?.models)) continue;
715
+ for (const m of cfg.models) {
716
+ if (typeof m?.id === "string" && m.id.trim()) {
717
+ refs.add(`${provider.trim()}/${m.id.trim()}`);
718
+ }
719
+ }
720
+ }
721
+ }
722
+ if (doc.defaults && typeof doc.defaults === "object") {
723
+ for (const ref of collectModelRefsFromConfig({ defaults: doc.defaults })) {
724
+ refs.add(ref);
725
+ }
726
+ }
727
+ return refs;
728
+ }
708
729
  function readKnownModelRefs(modelsPath) {
709
730
  if (!fs3.existsSync(modelsPath)) return void 0;
710
731
  try {
711
732
  const resolved = loadResolvedModelsConfig(modelsPath);
712
- const refs = collectModelRefsFromRaw(resolved.config);
733
+ const refs = collectModelRefsFromConfig(resolved.config);
713
734
  if (refs.size > 0) return refs;
714
735
  } catch {
715
736
  }
716
737
  try {
717
738
  const raw = JSON.parse(fs3.readFileSync(modelsPath, "utf8"));
718
- const refs = collectModelRefsFromRaw(raw);
739
+ const refs = collectModelRefsFromMinimalFixture(raw);
719
740
  return refs.size > 0 ? refs : void 0;
720
741
  } catch {
721
742
  return void 0;
@@ -779,12 +800,21 @@ function readModelsJsonDefault(modelsPath) {
779
800
  const known = readKnownModelRefs(modelsPath);
780
801
  if (!known || known.size === 0) return void 0;
781
802
  try {
782
- const raw = JSON.parse(fs3.readFileSync(modelsPath, "utf8"));
783
- if (typeof raw.defaults?.provider === "string" && typeof raw.defaults?.modelId === "string") {
784
- const ref = `${raw.defaults.provider.trim()}/${raw.defaults.modelId.trim()}`;
803
+ const resolved = loadResolvedModelsConfig(modelsPath);
804
+ const { provider, modelId } = resolved.config.defaults ?? {};
805
+ if (typeof provider === "string" && typeof modelId === "string") {
806
+ const ref = `${provider.trim()}/${modelId.trim()}`;
785
807
  if (MODEL_REF_RE.test(ref)) return ref;
786
808
  }
787
809
  } catch {
810
+ try {
811
+ const raw = JSON.parse(fs3.readFileSync(modelsPath, "utf8"));
812
+ if (typeof raw.defaults?.provider === "string" && typeof raw.defaults?.modelId === "string") {
813
+ const ref = `${raw.defaults.provider.trim()}/${raw.defaults.modelId.trim()}`;
814
+ if (MODEL_REF_RE.test(ref)) return ref;
815
+ }
816
+ } catch {
817
+ }
788
818
  }
789
819
  return [...known][0];
790
820
  }
@@ -1365,15 +1395,13 @@ function pieProc(ctx) {
1365
1395
  }
1366
1396
  return logTime;
1367
1397
  };
1368
- const persistActivity = (record, at) => {
1369
- try {
1370
- updateRegistry((snap) => ({
1371
- next: snap.workers.map((w) => w.generation === record.generation && at > w.lastActiveAt ? { ...w, lastActiveAt: at } : w),
1372
- result: void 0
1373
- }));
1374
- } catch {
1375
- }
1398
+ const inMemoryActivity = /* @__PURE__ */ new Map();
1399
+ const recordObservedActivity = (record) => {
1400
+ const fresh = Math.max(record.lastActiveAt, inMemoryActivity.get(record.generation) ?? 0, observeActivity(record));
1401
+ inMemoryActivity.set(record.generation, fresh);
1402
+ return fresh;
1376
1403
  };
1404
+ const activityPersistThresholdMs = (ttlMs) => Math.min(6e4, Math.floor(ttlMs / 4));
1377
1405
  const releaseReservation = (generation) => {
1378
1406
  try {
1379
1407
  updateRegistry((snap) => ({
@@ -1435,10 +1463,11 @@ function pieProc(ctx) {
1435
1463
  }
1436
1464
  }
1437
1465
  for (const w of readRegistryUncached().workers) {
1438
- const observed = Math.max(w.lastActiveAt, observeActivity(w));
1439
- if (observed > w.lastActiveAt) persistActivity(w, observed);
1466
+ recordObservedActivity(w);
1440
1467
  }
1468
+ const liveGenerations = /* @__PURE__ */ new Set();
1441
1469
  casRegistry((snap) => {
1470
+ liveGenerations.clear();
1442
1471
  const cutoff = Date.now();
1443
1472
  let changed = false;
1444
1473
  const keep = [];
@@ -1491,10 +1520,21 @@ function pieProc(ctx) {
1491
1520
  continue;
1492
1521
  }
1493
1522
  const ttl = w.kind === "resident" ? w.ttlMs ?? currentConfig().defaultTtlMs : 0;
1494
- if (ttl > 0 && liveness === "alive" && cutoff - Math.max(w.lastActiveAt, observeActivity(w)) > ttl) {
1495
- signalWorkerProcessGroup(w.pid, "SIGTERM");
1496
- ctx.log(`pie-proc: idle TTL signaled worker ${w.name} (idle > ${Math.round(ttl / 1e3)}s, identity verified)`);
1497
- keep.push({ ...w, ttlMs: 0, orphanSignaledAt: cutoff });
1523
+ let observed = Math.max(w.lastActiveAt, inMemoryActivity.get(w.generation) ?? 0);
1524
+ if (ttl > 0 && liveness === "alive" && cutoff - observed > ttl) {
1525
+ observed = recordObservedActivity(w);
1526
+ if (Date.now() - observed > ttl) {
1527
+ signalWorkerProcessGroup(w.pid, "SIGTERM");
1528
+ ctx.log(`pie-proc: idle TTL signaled worker ${w.name} (idle > ${Math.round(ttl / 1e3)}s, identity verified)`);
1529
+ keep.push({ ...w, lastActiveAt: observed, ttlMs: 0, orphanSignaledAt: cutoff });
1530
+ liveGenerations.add(w.generation);
1531
+ changed = true;
1532
+ continue;
1533
+ }
1534
+ }
1535
+ liveGenerations.add(w.generation);
1536
+ if (ttl > 0 && liveness === "alive" && observed > w.lastActiveAt && observed - w.lastActiveAt >= activityPersistThresholdMs(ttl)) {
1537
+ keep.push({ ...w, lastActiveAt: observed });
1498
1538
  changed = true;
1499
1539
  continue;
1500
1540
  }
@@ -1503,15 +1543,13 @@ function pieProc(ctx) {
1503
1543
  if (!changed) return { abort: { value: void 0 } };
1504
1544
  return { next: keep, result: void 0 };
1505
1545
  });
1546
+ for (const gen of [...inMemoryActivity.keys()]) {
1547
+ if (!liveGenerations.has(gen)) inMemoryActivity.delete(gen);
1548
+ }
1506
1549
  } catch (error) {
1507
1550
  ctx.log(`pie-proc: sweep skipped: ${error instanceof Error ? error.message : String(error)}`);
1508
1551
  }
1509
1552
  };
1510
- const sweepTimer = setInterval(sweep, 6e4);
1511
- sweepTimer.unref?.();
1512
- ctx.registerCleanup?.(() => {
1513
- clearInterval(sweepTimer);
1514
- });
1515
1553
  const spawnWorker = async (params) => {
1516
1554
  if (!safeName(params.name)) throw new Error(`invalid worker name "${params.name}" (use [a-z0-9-_], max 48)`);
1517
1555
  if (params.kind === "oneshot" && (typeof params.task !== "string" || !params.task.trim())) throw new Error("oneshot spawn requires a non-empty task");
@@ -1815,6 +1853,11 @@ function pieProc(ctx) {
1815
1853
  ctx.log("pie-proc: tool not registered (role-pruned; manager-only)");
1816
1854
  return;
1817
1855
  }
1856
+ const sweepTimer = setInterval(sweep, 6e4);
1857
+ sweepTimer.unref?.();
1858
+ ctx.registerCleanup?.(() => {
1859
+ clearInterval(sweepTimer);
1860
+ });
1818
1861
  const unregisterPanelBridge = registerPieProcPanelBridge({
1819
1862
  pieProcDir,
1820
1863
  operatorSessionsDir: resolveOperatorSessionsDir,
@@ -6,10 +6,10 @@ import {
6
6
  createPlanCapability,
7
7
  markCompletedPlanSteps,
8
8
  restoreExecutionState
9
- } from "../../../chunks/chunk-EZZTMDWZ.js";
10
- import "../../../chunks/chunk-JJH77AUU.js";
11
- import "../../../chunks/chunk-26KRUYZH.js";
12
- import "../../../chunks/chunk-MCR4JYI6.js";
9
+ } from "../../../chunks/chunk-X3ZVZB2R.js";
10
+ import "../../../chunks/chunk-SYZR74QO.js";
11
+ import "../../../chunks/chunk-SAXKBFX3.js";
12
+ import "../../../chunks/chunk-IM7DLPPY.js";
13
13
  import {
14
14
  Type
15
15
  } from "../../../chunks/chunk-XXGYUYXI.js";
@@ -5,7 +5,7 @@ import {
5
5
  createCliRetryPolicy,
6
6
  formatTransportLifecycle,
7
7
  logTransportLifecycle
8
- } from "../../../chunks/chunk-BOQIGMGQ.js";
8
+ } from "../../../chunks/chunk-2WLKAMOH.js";
9
9
  import {
10
10
  getConfigDir
11
11
  } from "../../../chunks/chunk-CBDQJMUI.js";
@@ -14,10 +14,10 @@ import {
14
14
  createPolicyEnforcedTools,
15
15
  createSharedFileSystemTools,
16
16
  createSubagentCapability
17
- } from "../../../chunks/chunk-EZZTMDWZ.js";
18
- import "../../../chunks/chunk-JJH77AUU.js";
19
- import "../../../chunks/chunk-26KRUYZH.js";
20
- import "../../../chunks/chunk-MCR4JYI6.js";
17
+ } from "../../../chunks/chunk-X3ZVZB2R.js";
18
+ import "../../../chunks/chunk-SYZR74QO.js";
19
+ import "../../../chunks/chunk-SAXKBFX3.js";
20
+ import "../../../chunks/chunk-IM7DLPPY.js";
21
21
  import "../../../chunks/chunk-XXGYUYXI.js";
22
22
  import "../../../chunks/chunk-LZQXQOPJ.js";
23
23
 
@@ -8,10 +8,10 @@ import {
8
8
  executeManageTodoList,
9
9
  executionStateToTodos,
10
10
  restoreExecutionState
11
- } from "../../../chunks/chunk-EZZTMDWZ.js";
12
- import "../../../chunks/chunk-JJH77AUU.js";
13
- import "../../../chunks/chunk-26KRUYZH.js";
14
- import "../../../chunks/chunk-MCR4JYI6.js";
11
+ } from "../../../chunks/chunk-X3ZVZB2R.js";
12
+ import "../../../chunks/chunk-SYZR74QO.js";
13
+ import "../../../chunks/chunk-SAXKBFX3.js";
14
+ import "../../../chunks/chunk-IM7DLPPY.js";
15
15
  import "../../../chunks/chunk-XXGYUYXI.js";
16
16
  import "../../../chunks/chunk-LZQXQOPJ.js";
17
17
 
@@ -10,15 +10,15 @@ import {
10
10
  createSharedWebSearchTool,
11
11
  defaultShellKindForPlatform,
12
12
  interpretShellExit
13
- } from "./chunk-EZZTMDWZ.js";
13
+ } from "./chunk-X3ZVZB2R.js";
14
14
  import {
15
15
  classifyDefaultFailure,
16
16
  isDefaultContextOverflowError,
17
17
  requestInteraction
18
- } from "./chunk-JJH77AUU.js";
18
+ } from "./chunk-SYZR74QO.js";
19
19
  import {
20
20
  getLogger
21
- } from "./chunk-MCR4JYI6.js";
21
+ } from "./chunk-IM7DLPPY.js";
22
22
  import {
23
23
  Type
24
24
  } from "./chunk-XXGYUYXI.js";
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  redactText
4
- } from "./chunk-EZZTMDWZ.js";
4
+ } from "./chunk-X3ZVZB2R.js";
5
5
 
6
6
  // src/commands/memory-git.ts
7
7
  import { execFileSync } from "node:child_process";