@cydm/pie 4.12.2 → 4.13.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.
Files changed (23) hide show
  1. package/dist/builtin/extensions/ask-user/index.js +1 -1
  2. package/dist/builtin/extensions/cron/index.js +177 -28
  3. package/dist/builtin/extensions/im-forward/index.js +472 -53
  4. package/dist/builtin/extensions/memory/index.js +8 -8
  5. package/dist/builtin/extensions/pie-proc/index.js +7 -7
  6. package/dist/builtin/extensions/plan-mode/index.js +1 -1
  7. package/dist/builtin/extensions/subagent/index.js +5 -5
  8. package/dist/builtin/extensions/todo/index.js +1 -1
  9. package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-bridge.js +1 -1
  10. package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-runtime.js +1 -1
  11. package/dist/builtin/skills/chrome-devtools-axi/{chunk-NL3FSRAW.js → chunk-D2OVVTF6.js} +32 -4
  12. package/dist/builtin/skills/chrome-devtools-axi/{cli-QAJYAXI4.js → cli-DJ36OIQ4.js} +1 -1
  13. package/dist/chunks/{chunk-QSXBPTOA.js → chunk-3CJLYX5J.js} +4 -4
  14. package/dist/chunks/{chunk-W37NAT3N.js → chunk-5MCIBDAM.js} +5 -5
  15. package/dist/chunks/{chunk-WTBLV6F5.js → chunk-5PCLBIOO.js} +23 -9
  16. package/dist/chunks/{chunk-KW46ND3S.js → chunk-AKC7NMP4.js} +126 -15
  17. package/dist/chunks/{chunk-26ILLZKQ.js → chunk-NOSNHMA2.js} +1 -1
  18. package/dist/chunks/{host-image-fallback-NXY36VO2.js → host-image-fallback-MZK633DK.js} +1 -1
  19. package/dist/chunks/{memory-git-C3S276QJ.js → memory-git-Q3UBYOJ4.js} +2 -2
  20. package/dist/chunks/{read-file-understanding-ZCBNCQHG.js → read-file-understanding-KCJMSOS7.js} +3 -3
  21. package/dist/chunks/{src-7CU7OTQS.js → src-QI47K3W3.js} +1 -1
  22. package/dist/cli.js +48 -48
  23. package/package.json +2 -2
@@ -3,10 +3,15 @@ import {
3
3
  distillWorkerLogPath,
4
4
  readDistillWorkerLog,
5
5
  spawnDistillWorker
6
- } from "../../../chunks/chunk-WTBLV6F5.js";
6
+ } from "../../../chunks/chunk-5PCLBIOO.js";
7
7
  import {
8
8
  commitCuratedMemoryBestEffort
9
- } from "../../../chunks/chunk-26ILLZKQ.js";
9
+ } from "../../../chunks/chunk-NOSNHMA2.js";
10
+ import {
11
+ getConfigDir,
12
+ getSessionsDir,
13
+ getSettingsPath
14
+ } from "../../../chunks/chunk-CBDQJMUI.js";
10
15
  import {
11
16
  DEFAULT_MEMORY_INJECTION_BUDGET,
12
17
  MemoryStore,
@@ -19,16 +24,11 @@ import {
19
24
  saveAttestedEntry,
20
25
  searchMemory,
21
26
  todayKey
22
- } from "../../../chunks/chunk-KW46ND3S.js";
27
+ } from "../../../chunks/chunk-AKC7NMP4.js";
23
28
  import {
24
29
  FileSessionStore
25
30
  } from "../../../chunks/chunk-SXBX2P5R.js";
26
31
  import "../../../chunks/chunk-BQWHLYYZ.js";
27
- import {
28
- getConfigDir,
29
- getSessionsDir,
30
- getSettingsPath
31
- } from "../../../chunks/chunk-CBDQJMUI.js";
32
32
  import "../../../chunks/chunk-G2K4GY6N.js";
33
33
  import {
34
34
  Type
@@ -1,11 +1,4 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
- import {
3
- redactText
4
- } from "../../../chunks/chunk-KW46ND3S.js";
5
- import {
6
- isCompactSummaryMessage
7
- } from "../../../chunks/chunk-SXBX2P5R.js";
8
- import "../../../chunks/chunk-BQWHLYYZ.js";
9
2
  import {
10
3
  registerWorkerLifecycleBridge,
11
4
  syncInheritedWorkerModels
@@ -21,6 +14,13 @@ import {
21
14
  loadResolvedModelsConfig
22
15
  } from "../../../chunks/chunk-IZ4DYCJ7.js";
23
16
  import "../../../chunks/chunk-CBDQJMUI.js";
17
+ import {
18
+ redactText
19
+ } from "../../../chunks/chunk-AKC7NMP4.js";
20
+ import {
21
+ isCompactSummaryMessage
22
+ } from "../../../chunks/chunk-SXBX2P5R.js";
23
+ import "../../../chunks/chunk-BQWHLYYZ.js";
24
24
  import "../../../chunks/chunk-G2K4GY6N.js";
25
25
  import {
26
26
  Type
@@ -6,7 +6,7 @@ import {
6
6
  createPlanCapability,
7
7
  markCompletedPlanSteps,
8
8
  restoreExecutionState
9
- } from "../../../chunks/chunk-KW46ND3S.js";
9
+ } from "../../../chunks/chunk-AKC7NMP4.js";
10
10
  import "../../../chunks/chunk-SXBX2P5R.js";
11
11
  import "../../../chunks/chunk-BQWHLYYZ.js";
12
12
  import "../../../chunks/chunk-G2K4GY6N.js";
@@ -5,18 +5,18 @@ import {
5
5
  createCliRetryPolicy,
6
6
  formatTransportLifecycle,
7
7
  logTransportLifecycle
8
- } from "../../../chunks/chunk-W37NAT3N.js";
8
+ } from "../../../chunks/chunk-5MCIBDAM.js";
9
+ import {
10
+ getConfigDir
11
+ } from "../../../chunks/chunk-CBDQJMUI.js";
9
12
  import {
10
13
  SUBAGENT_SESSION_RECORD_VERSION,
11
14
  createPolicyEnforcedTools,
12
15
  createSharedFileSystemTools,
13
16
  createSubagentCapability
14
- } from "../../../chunks/chunk-KW46ND3S.js";
17
+ } from "../../../chunks/chunk-AKC7NMP4.js";
15
18
  import "../../../chunks/chunk-SXBX2P5R.js";
16
19
  import "../../../chunks/chunk-BQWHLYYZ.js";
17
- import {
18
- getConfigDir
19
- } from "../../../chunks/chunk-CBDQJMUI.js";
20
20
  import "../../../chunks/chunk-G2K4GY6N.js";
21
21
  import "../../../chunks/chunk-XXGYUYXI.js";
22
22
  import "../../../chunks/chunk-LZQXQOPJ.js";
@@ -8,7 +8,7 @@ import {
8
8
  executeManageTodoList,
9
9
  executionStateToTodos,
10
10
  restoreExecutionState
11
- } from "../../../chunks/chunk-KW46ND3S.js";
11
+ } from "../../../chunks/chunk-AKC7NMP4.js";
12
12
  import "../../../chunks/chunk-SXBX2P5R.js";
13
13
  import "../../../chunks/chunk-BQWHLYYZ.js";
14
14
  import "../../../chunks/chunk-G2K4GY6N.js";
@@ -30,7 +30,7 @@ import {
30
30
  resolveSessionPort,
31
31
  resolveSessionStateDir,
32
32
  terminateProfileHolders
33
- } from "./chunk-NL3FSRAW.js";
33
+ } from "./chunk-D2OVVTF6.js";
34
34
  import {
35
35
  __commonJS,
36
36
  __export,
@@ -21,6 +21,6 @@ function tryFastPath(argv, options) {
21
21
 
22
22
  // vendor/chrome-devtools-axi/bin/chrome-devtools-axi.ts
23
23
  if (!tryFastPath(process.argv.slice(2), { version: VERSION })) {
24
- const { main } = await import("./cli-QAJYAXI4.js");
24
+ const { main } = await import("./cli-DJ36OIQ4.js");
25
25
  await main(process.argv.slice(2));
26
26
  }
@@ -499,8 +499,8 @@ function tryCreateCompleteLockFile(lockFile, content) {
499
499
  }
500
500
  }
501
501
  }
502
+ var MAX_RECLAIM_GENERATIONS = 8;
502
503
  function reclaimDeadLockUnderGate(lockFile, expectedToken) {
503
- const reclaimPath = `${lockFile}.reclaim`;
504
504
  const reclaimToken = randomUUID();
505
505
  const reclaimPayload = JSON.stringify({
506
506
  pid: process.pid,
@@ -508,7 +508,26 @@ function reclaimDeadLockUnderGate(lockFile, expectedToken) {
508
508
  token: reclaimToken,
509
509
  createdAt: Date.now()
510
510
  });
511
- if (!tryCreateCompleteLockFile(reclaimPath, reclaimPayload)) {
511
+ const tokenTag = expectedToken.replace(/[^A-Za-z0-9_-]/g, "").slice(0, 16) || "dead";
512
+ const legacyPath = `${lockFile}.reclaim`;
513
+ const candidates = [
514
+ legacyPath,
515
+ ...Array.from({ length: MAX_RECLAIM_GENERATIONS }, (_, gen) => `${lockFile}.reclaim.${tokenTag}.${gen}`)
516
+ ];
517
+ let wonPath = null;
518
+ const deadPriorGates = [];
519
+ for (const gatePath of candidates) {
520
+ if (tryCreateCompleteLockFile(gatePath, reclaimPayload)) {
521
+ wonPath = gatePath;
522
+ break;
523
+ }
524
+ const existingGate = readAtomicLockRecord(gatePath);
525
+ if (!existingGate || !isLockRecordOwnerGone(existingGate)) {
526
+ return;
527
+ }
528
+ deadPriorGates.push({ path: gatePath, token: existingGate.token });
529
+ }
530
+ if (!wonPath) {
512
531
  return;
513
532
  }
514
533
  try {
@@ -519,11 +538,20 @@ function reclaimDeadLockUnderGate(lockFile, expectedToken) {
519
538
  } catch {
520
539
  }
521
540
  }
541
+ for (const prior of deadPriorGates) {
542
+ const check = readAtomicLockRecord(prior.path);
543
+ if (check && check.token === prior.token && isLockRecordOwnerGone(check)) {
544
+ try {
545
+ unlinkSync(prior.path);
546
+ } catch {
547
+ }
548
+ }
549
+ }
522
550
  } finally {
523
- const gate = readAtomicLockRecord(reclaimPath);
551
+ const gate = readAtomicLockRecord(wonPath);
524
552
  if (gate && gate.token === reclaimToken) {
525
553
  try {
526
- unlinkSync(reclaimPath);
554
+ unlinkSync(wonPath);
527
555
  } catch {
528
556
  }
529
557
  }
@@ -31,7 +31,7 @@ import {
31
31
  setSelectedPageId,
32
32
  tryAcquireAtomicLockFile,
33
33
  writeAllocatedSessionPort
34
- } from "./chunk-NL3FSRAW.js";
34
+ } from "./chunk-D2OVVTF6.js";
35
35
  import "./chunk-OJ6N23UZ.js";
36
36
 
37
37
  // ../../node_modules/chrome-devtools-axi/node_modules/@toon-format/toon/dist/index.mjs
@@ -1,11 +1,11 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
- import {
3
- createReadFileUnderstandingHandler,
4
- modalityForReadFileUnderstandingKind
5
- } from "./chunk-KW46ND3S.js";
6
2
  import {
7
3
  readImageFormat
8
4
  } from "./chunk-F7EBZTZO.js";
5
+ import {
6
+ createReadFileUnderstandingHandler,
7
+ modalityForReadFileUnderstandingKind
8
+ } from "./chunk-AKC7NMP4.js";
9
9
  import {
10
10
  getLogger
11
11
  } from "./chunk-G2K4GY6N.js";
@@ -1,4 +1,8 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import {
3
+ getBuiltinDir,
4
+ getConfigDir
5
+ } from "./chunk-CBDQJMUI.js";
2
6
  import {
3
7
  classifyShellCommand,
4
8
  createSharedWebFetchTool,
@@ -6,14 +10,10 @@ import {
6
10
  createSharedWebSearchTool,
7
11
  defaultShellKindForPlatform,
8
12
  interpretShellExit
9
- } from "./chunk-KW46ND3S.js";
13
+ } from "./chunk-AKC7NMP4.js";
10
14
  import {
11
15
  requestInteraction
12
16
  } from "./chunk-SXBX2P5R.js";
13
- import {
14
- getBuiltinDir,
15
- getConfigDir
16
- } from "./chunk-CBDQJMUI.js";
17
17
  import {
18
18
  EMPTY_ASSISTANT_CONTENT_ERROR,
19
19
  OPENAI_COMPAT_PROTOCOL_ERROR_CODE,
@@ -2,6 +2,9 @@ import { createRequire as __createRequire } from "node:module"; const require =
2
2
  import {
3
3
  getSettingsPath
4
4
  } from "./chunk-CBDQJMUI.js";
5
+ import {
6
+ createMemoryLockBackend
7
+ } from "./chunk-AKC7NMP4.js";
5
8
 
6
9
  // src/commands/memory-distill.ts
7
10
  import * as fs from "node:fs";
@@ -34,7 +37,17 @@ function spawnDistillWorker(memoryRoot, date, sessionsDir) {
34
37
  function spawnDistillAutoWorker(memoryRoot, sessionsDir) {
35
38
  return spawnDistillCli(memoryRoot, ["--auto", ...sessionsDir ? ["--sessions-dir", sessionsDir] : []]);
36
39
  }
40
+ function spawnWikiGcWorker(memoryRoot) {
41
+ return spawnMemorySubcommand(memoryRoot, ["wiki", "gc", "--memory-root", memoryRoot], "wiki gc");
42
+ }
37
43
  function spawnDistillCli(memoryRoot, modeArgs) {
44
+ return spawnMemorySubcommand(
45
+ memoryRoot,
46
+ ["distill", ...modeArgs, "--worker", "--memory-root", memoryRoot],
47
+ modeArgs.join(" ")
48
+ );
49
+ }
50
+ function spawnMemorySubcommand(memoryRoot, memoryArgs, logLabel) {
38
51
  const logPath = distillWorkerLogPath(memoryRoot);
39
52
  const entry = process.argv[1] ? path.resolve(process.argv[1]) : null;
40
53
  if (!entry) return false;
@@ -43,7 +56,7 @@ function spawnDistillCli(memoryRoot, modeArgs) {
43
56
  } catch {
44
57
  return false;
45
58
  }
46
- const args = [entry, "memory", "distill", ...modeArgs, "--worker", "--memory-root", memoryRoot];
59
+ const args = [entry, "memory", ...memoryArgs];
47
60
  let out;
48
61
  try {
49
62
  out = fs.openSync(logPath, "a");
@@ -62,7 +75,7 @@ function spawnDistillCli(memoryRoot, modeArgs) {
62
75
  });
63
76
  child.unref();
64
77
  try {
65
- fs.appendFileSync(logPath, `[${(/* @__PURE__ */ new Date()).toISOString()}] spawned worker (${modeArgs.join(" ")}) (pid ${child.pid})
78
+ fs.appendFileSync(logPath, `[${(/* @__PURE__ */ new Date()).toISOString()}] spawned worker (${logLabel}) (pid ${child.pid})
66
79
  `);
67
80
  } catch {
68
81
  }
@@ -83,7 +96,6 @@ var advisoryLockBackend = /* @__PURE__ */ (() => {
83
96
  return () => {
84
97
  if (impl) return impl;
85
98
  const koffi = require2("koffi");
86
- const { createMemoryLockBackend } = require2("@pie/shared-headless-capabilities");
87
99
  impl = createMemoryLockBackend(koffi);
88
100
  return impl;
89
101
  };
@@ -318,8 +330,8 @@ async function runDistillWorkerMain(memoryRoot, date, noExit = false, sessionsDi
318
330
  const { AuthStorage } = await import("./auth-storage-IJEJ2TGE.js");
319
331
  const { getSessionsDir } = await import("./config-4EOI5NOU.js");
320
332
  const { FileSessionStore } = await import("./src-7MZZJVOG.js");
321
- const { WikiStore, runWikiBootstrap, runWikiDream, runWikiGc } = await import("./src-7CU7OTQS.js");
322
- const { commitCuratedMemoryBestEffort } = await import("./memory-git-C3S276QJ.js");
333
+ const { WikiStore, runWikiBootstrap, runWikiDream, runWikiGc } = await import("./src-QI47K3W3.js");
334
+ const { commitCuratedMemoryBestEffort } = await import("./memory-git-Q3UBYOJ4.js");
323
335
  const wiki = new WikiStore(memoryRoot);
324
336
  wikiForError = wiki;
325
337
  if (wiki.hasDreamedDate(date)) {
@@ -357,11 +369,12 @@ async function runDistillWorkerMain(memoryRoot, date, noExit = false, sessionsDi
357
369
  });
358
370
  log(`[wiki] dream ${date}: ok=${dreamRes.ok} sessions=${dreamRes.sessionsHarvested} signals=${dreamRes.signalsAuthenticated} written=${dreamRes.written.length}${dreamRes.error ? ` error=${dreamRes.error}` : ""}`);
359
371
  let gcWrote = false;
360
- if (dreamRes.ok) {
372
+ if (wiki.exists()) {
361
373
  const meta = wiki.readMeta();
362
374
  const sevenDaysMs = 7 * 24 * 60 * 60 * 1e3;
363
- const needsGc = !meta.lastGcAt || Date.now() - meta.lastGcAt >= sevenDaysMs || wiki.listActivePages().length >= 18;
364
- if (needsGc && wiki.exists()) {
375
+ const atCapacityPressure = wiki.listActivePages().length >= 18;
376
+ const needsGc = dreamRes.ok && (!meta.lastGcAt || Date.now() - meta.lastGcAt >= sevenDaysMs) || atCapacityPressure;
377
+ if (needsGc) {
365
378
  const gcRes = await runWikiGc({ memoryRoot, balancedCall });
366
379
  log(`[wiki] weekly gc: ok=${gcRes.ok} archived=${gcRes.archivedInactive.length} compressed=${gcRes.compressedPages.length}${gcRes.error ? ` error=${gcRes.error}` : ""}`);
367
380
  gcWrote = gcRes.archivedInactive.length > 0 || gcRes.compressedPages.length > 0;
@@ -410,7 +423,7 @@ async function runDistillAuto(memoryRoot, days = 7, runner, sessionsDir) {
410
423
  } catch {
411
424
  }
412
425
  };
413
- const { WikiStore, todayKey } = await import("./src-7CU7OTQS.js");
426
+ const { WikiStore, todayKey } = await import("./src-QI47K3W3.js");
414
427
  const wiki = new WikiStore(memoryRoot);
415
428
  const today = todayKey(Date.now());
416
429
  const dates = [];
@@ -466,6 +479,7 @@ export {
466
479
  distillExitCode,
467
480
  spawnDistillWorker,
468
481
  spawnDistillAutoWorker,
482
+ spawnWikiGcWorker,
469
483
  acquireDistillLock,
470
484
  createWikiModelCall,
471
485
  isWikiDreamResultRetryable,
@@ -16627,7 +16627,30 @@ var WikiStore = class {
16627
16627
  if (!options.isBootstrap && nonIndexCount > limits.maxPagesPerDream) {
16628
16628
  violations.push(`dream update touches ${nonIndexCount} pages (max ${limits.maxPagesPerDream} per run)`);
16629
16629
  }
16630
+ const writtenRelPaths = new Set(normalized.map((u) => u.relPath));
16631
+ const plannedArchives = [];
16632
+ const seenArchive = /* @__PURE__ */ new Set();
16633
+ for (const rawSlug of options.archiveSlugs ?? []) {
16634
+ const cleaned = rawSlug.replace(/^wiki\//, "").replace(/^projects\//, "").replace(/\.md$/, "");
16635
+ if (!SLUG_RE.test(cleaned) || seenArchive.has(cleaned)) continue;
16636
+ const relPath = `projects/${cleaned}.md`;
16637
+ if (writtenRelPaths.has(relPath)) continue;
16638
+ const src = path7.join(this.wikiDir, "projects", `${cleaned}.md`);
16639
+ try {
16640
+ assertNoSymlinkUnderRoot(this.memoryRoot, src);
16641
+ if (!fs5.lstatSync(src).isFile()) continue;
16642
+ } catch {
16643
+ continue;
16644
+ }
16645
+ const content = this.readPage(relPath);
16646
+ if (content && parseWikiFrontmatter(content).pinned) continue;
16647
+ seenArchive.add(cleaned);
16648
+ plannedArchives.push({ slug: cleaned, relPath, src });
16649
+ }
16630
16650
  const activeSet = new Set(this.listActivePages());
16651
+ for (const arch of plannedArchives) {
16652
+ activeSet.delete(arch.relPath);
16653
+ }
16631
16654
  for (const u of normalized) {
16632
16655
  if (!u.relPath.startsWith("archive/")) activeSet.add(u.relPath);
16633
16656
  }
@@ -16657,7 +16680,24 @@ var WikiStore = class {
16657
16680
  return { ok: false, violations: [`staging failed: ${error instanceof Error ? error.message : String(error)}`] };
16658
16681
  }
16659
16682
  const committed = [];
16683
+ const committedArchives = [];
16660
16684
  try {
16685
+ if (plannedArchives.length > 0) {
16686
+ const archiveDir = path7.join(this.wikiDir, "archive");
16687
+ ensureSafeDir(this.memoryRoot, archiveDir);
16688
+ for (const arch of plannedArchives) {
16689
+ let dst = path7.join(archiveDir, `${arch.slug}.md`);
16690
+ for (let n = 2; fs5.existsSync(dst) && n < 100; n += 1) {
16691
+ const candidateSlug = `${arch.slug.slice(0, 44)}-${n}`;
16692
+ dst = path7.join(archiveDir, `${candidateSlug}.md`);
16693
+ }
16694
+ if (fs5.existsSync(dst)) continue;
16695
+ assertNoSymlinkUnderRoot(this.memoryRoot, arch.src);
16696
+ assertNoSymlinkUnderRoot(this.memoryRoot, dst);
16697
+ fs5.renameSync(arch.src, dst);
16698
+ committedArchives.push({ slug: arch.slug, src: arch.src, dst });
16699
+ }
16700
+ }
16661
16701
  for (const s of staged) {
16662
16702
  assertNoSymlinkUnderRoot(this.memoryRoot, s.target);
16663
16703
  fs5.renameSync(s.tmp, s.target);
@@ -16679,11 +16719,23 @@ var WikiStore = class {
16679
16719
  } catch {
16680
16720
  }
16681
16721
  }
16722
+ for (const a of committedArchives.reverse()) {
16723
+ try {
16724
+ assertNoSymlinkUnderRoot(this.memoryRoot, a.dst);
16725
+ assertNoSymlinkUnderRoot(this.memoryRoot, a.src);
16726
+ fs5.renameSync(a.dst, a.src);
16727
+ } catch {
16728
+ }
16729
+ }
16682
16730
  return { ok: false, violations: [`atomic commit failed (rolled back): ${error instanceof Error ? error.message : String(error)}`] };
16683
16731
  }
16684
16732
  const now = options.now ?? Date.now();
16685
16733
  this.writeMeta(options.isBootstrap ? { lastBootstrapAt: now } : { lastDreamAt: now });
16686
- return { ok: true, written: normalized.map((u) => u.relPath) };
16734
+ return {
16735
+ ok: true,
16736
+ written: normalized.map((u) => u.relPath),
16737
+ archived: committedArchives.map((a) => a.slug)
16738
+ };
16687
16739
  }
16688
16740
  /** Move an active project page `projects/<slug>.md` into `archive/<slug>.md`
16689
16741
  * (collision-safe: appends `-2`, `-3`, ... if archive slot already exists;
@@ -17200,7 +17252,7 @@ async function extractDreamSignalsForSession(session, call, projectHint) {
17200
17252
  }
17201
17253
  return authenticateDreamSignals(session, candidates, projectHint?.projectKey);
17202
17254
  }
17203
- async function validateOrRepairUpdates(updates, call, limits) {
17255
+ async function validateOrRepairUpdates(updates, call, limits, options = {}) {
17204
17256
  const checkAll = (batch) => {
17205
17257
  const violations = [];
17206
17258
  for (const u of batch) {
@@ -17226,10 +17278,40 @@ async function validateOrRepairUpdates(updates, call, limits) {
17226
17278
  "Pages to fix:",
17227
17279
  JSON.stringify({ updates }, null, 2)
17228
17280
  ].join("\n");
17281
+ const expectedPaths = /* @__PURE__ */ new Set();
17282
+ for (const u of updates) {
17283
+ const norm = normalizeWikiRelPath(u.path);
17284
+ if (norm) expectedPaths.add(norm);
17285
+ }
17229
17286
  try {
17230
17287
  const repairedRaw = await call(redactText(repairPrompt).text, { system: "You compress wiki markdown strictly under hard line/char budgets. Output JSON only." });
17231
17288
  const repaired = parseWikiDreamOutput(repairedRaw).updates;
17232
- const secondViolations = checkAll(repaired);
17289
+ const repairedPaths = /* @__PURE__ */ new Set();
17290
+ const pathViolations = [];
17291
+ for (const u of repaired) {
17292
+ const norm = normalizeWikiRelPath(u.path);
17293
+ if (!norm) {
17294
+ pathViolations.push(`repair returned invalid wiki path "${u.path}"`);
17295
+ continue;
17296
+ }
17297
+ if (repairedPaths.has(norm)) {
17298
+ pathViolations.push(`repair returned duplicate wiki path "${norm}"`);
17299
+ continue;
17300
+ }
17301
+ repairedPaths.add(norm);
17302
+ if (!options.allowExtraPaths && !expectedPaths.has(norm)) {
17303
+ pathViolations.push(`repair introduced unexpected wiki path "${norm}"`);
17304
+ }
17305
+ }
17306
+ for (const expected of expectedPaths) {
17307
+ if (!repairedPaths.has(expected)) {
17308
+ pathViolations.push(`repair dropped required wiki path "${expected}"`);
17309
+ }
17310
+ }
17311
+ if (updates.length > 0 && repaired.length === 0) {
17312
+ pathViolations.push("repair returned empty updates for nonempty input");
17313
+ }
17314
+ const secondViolations = [...pathViolations, ...checkAll(repaired)];
17233
17315
  if (secondViolations.length === 0) return { ok: true, updates: repaired };
17234
17316
  return { ok: false, violations: secondViolations };
17235
17317
  } catch (error) {
@@ -17363,7 +17445,7 @@ ${j.content}`).join("\n\n") || "(none)"
17363
17445
  if (filtered.length === 0) {
17364
17446
  return { ok: false, written: [], indexTokens: 0, summaries: [], error: "bootstrap returned no wiki pages" };
17365
17447
  }
17366
- const checked = await validateOrRepairUpdates(filtered, deps.balancedCall, limits);
17448
+ const checked = await validateOrRepairUpdates(filtered, deps.balancedCall, limits, { allowExtraPaths: true });
17367
17449
  if (!checked.ok) {
17368
17450
  return { ok: false, written: [], indexTokens: 0, summaries: [], violations: checked.violations, error: "bootstrap updates exceeded anti-bloat limits" };
17369
17451
  }
@@ -17667,6 +17749,7 @@ ${p.content}`).join("\n\n") || "(none yet)"
17667
17749
  }
17668
17750
  let appliedWritten = [];
17669
17751
  let summaries = [];
17752
+ const archived = [];
17670
17753
  if (filtered.length > 0) {
17671
17754
  const checked = await validateOrRepairUpdates(filtered, deps.balancedCall, limits);
17672
17755
  if (!checked.ok) {
@@ -17683,7 +17766,12 @@ ${p.content}`).join("\n\n") || "(none yet)"
17683
17766
  error: "dream updates violated anti-bloat limits"
17684
17767
  };
17685
17768
  }
17686
- const applied = wikiStore.applyWikiUpdates(checked.updates, { isBootstrap: false, limits, now });
17769
+ const applied = wikiStore.applyWikiUpdates(checked.updates, {
17770
+ isBootstrap: false,
17771
+ limits,
17772
+ now,
17773
+ archiveSlugs: archiveCandidates
17774
+ });
17687
17775
  if (!applied.ok) {
17688
17776
  return {
17689
17777
  ok: false,
@@ -17700,13 +17788,17 @@ ${p.content}`).join("\n\n") || "(none yet)"
17700
17788
  }
17701
17789
  appliedWritten = applied.written;
17702
17790
  summaries = checked.updates.map((u) => `${u.path}: ${u.summary ?? "updated"}`);
17703
- }
17704
- const archived = [];
17705
- for (const slug of archiveCandidates) {
17706
- if (wikiStore.archiveProjectPage(slug, { forcePinned: false })) {
17791
+ for (const slug of applied.archived ?? []) {
17707
17792
  archived.push(slug);
17708
17793
  summaries.push(`archived: ${slug}`);
17709
17794
  }
17795
+ } else {
17796
+ for (const slug of archiveCandidates) {
17797
+ if (wikiStore.archiveProjectPage(slug, { forcePinned: false })) {
17798
+ archived.push(slug);
17799
+ summaries.push(`archived: ${slug}`);
17800
+ }
17801
+ }
17710
17802
  }
17711
17803
  wikiStore.rebuildIndex(today, limits);
17712
17804
  persistPartialAndCompleteDates(updatesOverflowed);
@@ -17839,12 +17931,19 @@ function lookupSessionEvidence(store, input) {
17839
17931
  ...hasMore ? { nextOffset } : {}
17840
17932
  };
17841
17933
  }
17934
+ const MAX_SUMMARY_PAGES = 40;
17935
+ const SUMMARY_PAGE_SIZE = 256;
17936
+ const MAX_SUMMARY_WINDOW = MAX_SUMMARY_PAGES * SUMMARY_PAGE_SIZE;
17842
17937
  const headers = [];
17938
+ let truncatedOlder = false;
17843
17939
  const hasSummaries = typeof store.getEntrySummaries === "function";
17844
17940
  if (hasSummaries) {
17845
- let afterSeq;
17846
- for (let pages = 0; pages < 40; pages += 1) {
17847
- const page = store.getEntrySummaries(sessionId, { limit: 256, afterSeq });
17941
+ const probe = store.getEntrySummaries(sessionId, { limit: 1 });
17942
+ const total = typeof probe.total === "number" && Number.isFinite(probe.total) ? probe.total : 0;
17943
+ let afterSeq = total > MAX_SUMMARY_WINDOW ? total - MAX_SUMMARY_WINDOW : void 0;
17944
+ if (afterSeq && afterSeq > 0) truncatedOlder = true;
17945
+ for (let pages = 0; pages < MAX_SUMMARY_PAGES; pages += 1) {
17946
+ const page = store.getEntrySummaries(sessionId, { limit: SUMMARY_PAGE_SIZE, afterSeq });
17848
17947
  for (const s of page.summaries) {
17849
17948
  headers.push({ id: s.id, seq: s.seq, type: s.type, role: s.role, timestamp: s.timestamp });
17850
17949
  }
@@ -17852,8 +17951,11 @@ function lookupSessionEvidence(store, input) {
17852
17951
  afterSeq = page.summaries[page.summaries.length - 1].seq;
17853
17952
  }
17854
17953
  } else {
17954
+ const MAX_ITER_WINDOW = 4e3;
17855
17955
  let afterSeq;
17856
- for (let pages = 0; pages < 40; pages += 1) {
17956
+ let pageCount = 0;
17957
+ while (pageCount < 200) {
17958
+ pageCount += 1;
17857
17959
  const page = store.iterateEntries(sessionId, { limit: 100, afterSeq });
17858
17960
  for (let i = 0; i < page.entries.length; i += 1) {
17859
17961
  const e = page.entries[i];
@@ -17865,6 +17967,10 @@ function lookupSessionEvidence(store, input) {
17865
17967
  timestamp: e.timestamp
17866
17968
  });
17867
17969
  }
17970
+ if (headers.length > MAX_ITER_WINDOW) {
17971
+ headers.splice(0, headers.length - MAX_ITER_WINDOW);
17972
+ truncatedOlder = true;
17973
+ }
17868
17974
  if (!page.hasMore) break;
17869
17975
  afterSeq = page.lastSeq;
17870
17976
  }
@@ -17918,10 +18024,15 @@ function lookupSessionEvidence(store, input) {
17918
18024
  const limit = Math.min(Math.max(1, input.limit ?? 10), 20);
17919
18025
  const items = [];
17920
18026
  let scanned = 0;
17921
- for (let i = headers.length - 1; i >= 0 && scanned < MAX_SEARCH_SCAN && items.length < limit; i -= 1) {
18027
+ let stoppedBeforeOldest = false;
18028
+ for (let i = headers.length - 1; i >= 0; i -= 1) {
17922
18029
  const h = headers[i];
17923
18030
  if (h.type !== "message" && h.type !== "compaction") continue;
17924
18031
  if (h.type === "message" && h.role === "toolResult") continue;
18032
+ if (scanned >= MAX_SEARCH_SCAN || items.length >= limit) {
18033
+ stoppedBeforeOldest = true;
18034
+ break;
18035
+ }
17925
18036
  scanned += 1;
17926
18037
  const entry = store.readEntry(sessionId, h.id);
17927
18038
  if (!entry) continue;
@@ -17938,7 +18049,7 @@ function lookupSessionEvidence(store, input) {
17938
18049
  ...base,
17939
18050
  ok: true,
17940
18051
  items,
17941
- hasMore: headers.length > scanned && items.length === 0,
18052
+ hasMore: stoppedBeforeOldest || truncatedOlder,
17942
18053
  scanned
17943
18054
  };
17944
18055
  }
@@ -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-KW46ND3S.js";
4
+ } from "./chunk-AKC7NMP4.js";
5
5
 
6
6
  // src/commands/memory-git.ts
7
7
  import { execFileSync } from "node:child_process";
@@ -5,7 +5,7 @@ import "./chunk-LZQXQOPJ.js";
5
5
  import * as os from "node:os";
6
6
  async function describeImageViaUnderstandingChain(options) {
7
7
  try {
8
- const { understandReadFile } = await import("./read-file-understanding-ZCBNCQHG.js");
8
+ const { understandReadFile } = await import("./read-file-understanding-KCJMSOS7.js");
9
9
  const ext = options.filePath.toLowerCase().split(".").pop() ?? "";
10
10
  const mimeType = ext === "png" ? "image/png" : ext === "gif" ? "image/gif" : ext === "webp" ? "image/webp" : "image/jpeg";
11
11
  const result = await understandReadFile(
@@ -4,8 +4,8 @@ import {
4
4
  ensureMemoryGitIgnore,
5
5
  isMemoryGitInitialized,
6
6
  readCuratedMemoryGitLog
7
- } from "./chunk-26ILLZKQ.js";
8
- import "./chunk-KW46ND3S.js";
7
+ } from "./chunk-NOSNHMA2.js";
8
+ import "./chunk-AKC7NMP4.js";
9
9
  import "./chunk-SXBX2P5R.js";
10
10
  import "./chunk-BQWHLYYZ.js";
11
11
  import "./chunk-G2K4GY6N.js";
@@ -1,11 +1,11 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  understandReadFile
4
- } from "./chunk-QSXBPTOA.js";
5
- import "./chunk-KW46ND3S.js";
4
+ } from "./chunk-3CJLYX5J.js";
5
+ import "./chunk-F7EBZTZO.js";
6
+ import "./chunk-AKC7NMP4.js";
6
7
  import "./chunk-SXBX2P5R.js";
7
8
  import "./chunk-BQWHLYYZ.js";
8
- import "./chunk-F7EBZTZO.js";
9
9
  import "./chunk-G2K4GY6N.js";
10
10
  import "./chunk-XXGYUYXI.js";
11
11
  import "./chunk-LZQXQOPJ.js";
@@ -221,7 +221,7 @@ import {
221
221
  understandFileWithModel,
222
222
  validateTodos,
223
223
  validateWikiPageContent
224
- } from "./chunk-KW46ND3S.js";
224
+ } from "./chunk-AKC7NMP4.js";
225
225
  import "./chunk-SXBX2P5R.js";
226
226
  import "./chunk-BQWHLYYZ.js";
227
227
  import {