@mrciphersmith/keryx 0.4.28 → 0.4.30

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 (132) hide show
  1. package/dist/cli.js +4916 -3655
  2. package/dist/core.js +91 -28
  3. package/dist/keryx-general-worker-entry.js +413 -240
  4. package/package.json +1 -1
  5. package/src/gdskills/bundled/install-manifest.json +3 -0
  6. package/src/gdskills/bundled/rules/core/api-contracts.mdc +21 -136
  7. package/src/gdskills/bundled/rules/core/async-patterns.mdc +18 -171
  8. package/src/gdskills/bundled/rules/core/clean-architecture.mdc +40 -150
  9. package/src/gdskills/bundled/rules/core/cli-interface-design.mdc +63 -194
  10. package/src/gdskills/bundled/rules/core/code-style-patterns.mdc +36 -48
  11. package/src/gdskills/bundled/rules/core/concurrency-patterns.mdc +32 -0
  12. package/src/gdskills/bundled/rules/core/database-patterns.mdc +26 -148
  13. package/src/gdskills/bundled/rules/core/error-handling.mdc +57 -109
  14. package/src/gdskills/bundled/rules/core/frontend-assistant.mdc +14 -29
  15. package/src/gdskills/bundled/rules/core/layout-rendering.mdc +51 -0
  16. package/src/gdskills/bundled/rules/core/mobx-store-template.mdc +69 -511
  17. package/src/gdskills/bundled/rules/core/nestjs-dto.mdc +18 -36
  18. package/src/gdskills/bundled/rules/core/playwright-testing.mdc +35 -308
  19. package/src/gdskills/bundled/rules/core/security-baseline.mdc +18 -140
  20. package/src/gdskills/bundled/rules/core/skill-authoring.mdc +190 -0
  21. package/src/gdskills/bundled/rules/core/skills-storage-workflow.mdc +5 -0
  22. package/src/gdskills/bundled/rules/core/solid-principles.mdc +70 -121
  23. package/src/gdskills/bundled/rules/core/storybook-guidelines.mdc +20 -22
  24. package/src/gdskills/bundled/rules/core/tdd-workflow.mdc +37 -74
  25. package/src/gdskills/bundled/rules/core/ui-anti-slop.mdc +48 -37
  26. package/src/gdskills/bundled/skills/orchestration/task-implementer/SKILL.md +2 -2
  27. package/src/gdskills/bundled/skills/quality/deprecation-path/SKILL.md +1 -1
  28. package/src/gdskills/bundled/skills/quality/tests-creator/SKILL.md +1 -1
  29. package/src/gdskills/bundled/skills/review/review-architecture/SKILL.md +25 -61
  30. package/src/gdskills/bundled/skills/review/review-backend/SKILL.md +15 -69
  31. package/src/gdskills/bundled/skills/review/review-clean-code/SKILL.md +84 -418
  32. package/src/gdskills/bundled/skills/review/review-core-boundaries/SKILL.md +2 -2
  33. package/src/gdskills/bundled/skills/review/review-degradation/SKILL.md +1 -1
  34. package/src/gdskills/bundled/skills/review/review-flow-graph/SKILL.md +1 -1
  35. package/src/gdskills/bundled/skills/review/review-frontend/SKILL.md +17 -311
  36. package/src/gdskills/bundled/skills/review/review-frontend-conventions/SKILL.md +8 -22
  37. package/src/gdskills/bundled/skills/review/review-highload/SKILL.md +84 -228
  38. package/src/gdskills/bundled/skills/review/review-layout/SKILL.md +22 -28
  39. package/src/gdskills/bundled/skills/review/review-logic/SKILL.md +9 -10
  40. package/src/gdskills/bundled/skills/review/review-performance/SKILL.md +16 -38
  41. package/src/gdskills/bundled/skills/review/review-premise/SKILL.md +1 -1
  42. package/src/gdskills/bundled/skills/review/review-regression/SKILL.md +1 -1
  43. package/src/gdskills/bundled/skills/review/review-security-code/SKILL.md +8 -8
  44. package/src/gdskills/bundled/skills/review/review-style/SKILL.md +49 -88
  45. package/src/gdskills/bundled/skills/review/review-testing-practices/SKILL.md +22 -40
  46. package/src/gdskills/bundled/skills/review/review-ui-ux/SKILL.md +42 -82
  47. package/src/gdskills/bundled/stacks/angular/rules/coding-style.mdc +15 -57
  48. package/src/gdskills/bundled/stacks/angular/rules/patterns.mdc +16 -60
  49. package/src/gdskills/bundled/stacks/angular/rules/security.mdc +11 -49
  50. package/src/gdskills/bundled/stacks/angular/rules/testing.mdc +13 -52
  51. package/src/gdskills/bundled/stacks/c-cpp/rules/coding-style.mdc +33 -57
  52. package/src/gdskills/bundled/stacks/c-cpp/rules/patterns.mdc +35 -62
  53. package/src/gdskills/bundled/stacks/c-cpp/rules/security.mdc +35 -62
  54. package/src/gdskills/bundled/stacks/c-cpp/rules/testing.mdc +34 -54
  55. package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/patterns.mdc +27 -56
  56. package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/security.mdc +51 -119
  57. package/src/gdskills/bundled/stacks/csharp-dotnet/rules/coding-style.mdc +42 -74
  58. package/src/gdskills/bundled/stacks/csharp-dotnet/rules/patterns.mdc +45 -83
  59. package/src/gdskills/bundled/stacks/csharp-dotnet/rules/security.mdc +34 -59
  60. package/src/gdskills/bundled/stacks/csharp-dotnet/rules/testing.mdc +33 -62
  61. package/src/gdskills/bundled/stacks/django/rules/coding-style.mdc +15 -56
  62. package/src/gdskills/bundled/stacks/django/rules/patterns.mdc +16 -68
  63. package/src/gdskills/bundled/stacks/django/rules/security.mdc +13 -71
  64. package/src/gdskills/bundled/stacks/django/rules/testing.mdc +16 -62
  65. package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/coding-style.mdc +30 -53
  66. package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/patterns.mdc +20 -56
  67. package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/security.mdc +52 -122
  68. package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/testing.mdc +23 -42
  69. package/src/gdskills/bundled/stacks/fastapi/rules/coding-style.mdc +13 -47
  70. package/src/gdskills/bundled/stacks/fastapi/rules/patterns.mdc +18 -81
  71. package/src/gdskills/bundled/stacks/fastapi/rules/security.mdc +13 -75
  72. package/src/gdskills/bundled/stacks/fastapi/rules/testing.mdc +14 -58
  73. package/src/gdskills/bundled/stacks/flutter-dart/rules/coding-style.mdc +36 -74
  74. package/src/gdskills/bundled/stacks/flutter-dart/rules/patterns.mdc +30 -66
  75. package/src/gdskills/bundled/stacks/flutter-dart/rules/security.mdc +33 -67
  76. package/src/gdskills/bundled/stacks/flutter-dart/rules/testing.mdc +41 -73
  77. package/src/gdskills/bundled/stacks/go/rules/coding-style.mdc +36 -57
  78. package/src/gdskills/bundled/stacks/go/rules/patterns.mdc +27 -42
  79. package/src/gdskills/bundled/stacks/go/rules/security.mdc +26 -43
  80. package/src/gdskills/bundled/stacks/go/rules/testing.mdc +23 -41
  81. package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/coding-style.mdc +21 -40
  82. package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/patterns.mdc +26 -43
  83. package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/security.mdc +25 -37
  84. package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/testing.mdc +34 -50
  85. package/src/gdskills/bundled/stacks/kotlin-android/rules/coding-style.mdc +28 -65
  86. package/src/gdskills/bundled/stacks/kotlin-android/rules/patterns.mdc +34 -78
  87. package/src/gdskills/bundled/stacks/kotlin-android/rules/security.mdc +35 -68
  88. package/src/gdskills/bundled/stacks/kotlin-android/rules/testing.mdc +34 -68
  89. package/src/gdskills/bundled/stacks/mobx/rules/coding-style.mdc +18 -64
  90. package/src/gdskills/bundled/stacks/mobx/rules/patterns.mdc +13 -66
  91. package/src/gdskills/bundled/stacks/mobx/rules/security.mdc +8 -35
  92. package/src/gdskills/bundled/stacks/mobx/rules/testing.mdc +10 -39
  93. package/src/gdskills/bundled/stacks/nestjs/rules/coding-style.mdc +32 -45
  94. package/src/gdskills/bundled/stacks/nestjs/rules/patterns.mdc +40 -60
  95. package/src/gdskills/bundled/stacks/nestjs/rules/security.mdc +30 -50
  96. package/src/gdskills/bundled/stacks/nestjs/rules/testing.mdc +27 -47
  97. package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/coding-style.mdc +14 -48
  98. package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/patterns.mdc +15 -67
  99. package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/security.mdc +12 -50
  100. package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/testing.mdc +11 -43
  101. package/src/gdskills/bundled/stacks/php-laravel/rules/coding-style.mdc +17 -58
  102. package/src/gdskills/bundled/stacks/php-laravel/rules/patterns.mdc +15 -56
  103. package/src/gdskills/bundled/stacks/php-laravel/rules/security.mdc +13 -50
  104. package/src/gdskills/bundled/stacks/php-laravel/rules/testing.mdc +14 -55
  105. package/src/gdskills/bundled/stacks/python/rules/coding-style.mdc +13 -41
  106. package/src/gdskills/bundled/stacks/python/rules/patterns.mdc +20 -61
  107. package/src/gdskills/bundled/stacks/python/rules/security.mdc +15 -57
  108. package/src/gdskills/bundled/stacks/python/rules/testing.mdc +16 -50
  109. package/src/gdskills/bundled/stacks/react/rules/coding-style.mdc +14 -40
  110. package/src/gdskills/bundled/stacks/react/rules/patterns.mdc +15 -55
  111. package/src/gdskills/bundled/stacks/react/rules/security.mdc +13 -49
  112. package/src/gdskills/bundled/stacks/react/rules/testing.mdc +10 -37
  113. package/src/gdskills/bundled/stacks/ruby-rails/rules/coding-style.mdc +15 -48
  114. package/src/gdskills/bundled/stacks/ruby-rails/rules/patterns.mdc +18 -67
  115. package/src/gdskills/bundled/stacks/ruby-rails/rules/security.mdc +11 -60
  116. package/src/gdskills/bundled/stacks/ruby-rails/rules/testing.mdc +14 -65
  117. package/src/gdskills/bundled/stacks/rust/rules/coding-style.mdc +39 -65
  118. package/src/gdskills/bundled/stacks/rust/rules/patterns.mdc +33 -60
  119. package/src/gdskills/bundled/stacks/rust/rules/security.mdc +35 -57
  120. package/src/gdskills/bundled/stacks/rust/rules/testing.mdc +29 -52
  121. package/src/gdskills/bundled/stacks/sql-db/rules/coding-style.mdc +12 -48
  122. package/src/gdskills/bundled/stacks/sql-db/rules/patterns.mdc +22 -113
  123. package/src/gdskills/bundled/stacks/sql-db/rules/security.mdc +11 -56
  124. package/src/gdskills/bundled/stacks/sql-db/rules/testing.mdc +14 -59
  125. package/src/gdskills/bundled/stacks/swift-ios/rules/coding-style.mdc +29 -65
  126. package/src/gdskills/bundled/stacks/swift-ios/rules/patterns.mdc +41 -88
  127. package/src/gdskills/bundled/stacks/swift-ios/rules/security.mdc +28 -53
  128. package/src/gdskills/bundled/stacks/swift-ios/rules/testing.mdc +32 -65
  129. package/src/gdskills/bundled/stacks/vue/rules/coding-style.mdc +17 -52
  130. package/src/gdskills/bundled/stacks/vue/rules/patterns.mdc +17 -63
  131. package/src/gdskills/bundled/stacks/vue/rules/security.mdc +11 -41
  132. package/src/gdskills/bundled/stacks/vue/rules/testing.mdc +16 -48
@@ -95,6 +95,21 @@ function appendOwnerOnlyLine(file, line) {
95
95
  chmodSync(file, 384);
96
96
  } catch {}
97
97
  }
98
+ function appendPrivateRecord(file, line) {
99
+ const fd = openSync(file, constants.O_WRONLY | constants.O_CREAT | constants.O_APPEND | constants.O_NOFOLLOW | constants.O_NONBLOCK, 384);
100
+ try {
101
+ const info = fstatSync(fd);
102
+ if (!info.isFile() || process.platform !== "win32" && (info.mode & 63) !== 0 || info.nlink !== 1) {
103
+ throw new Error("Private journal requires an owner-only regular file.");
104
+ }
105
+ const bytes = Buffer.from(`${line}
106
+ `);
107
+ if (writeSync(fd, bytes) !== bytes.length)
108
+ throw new Error("Incomplete private journal write.");
109
+ } finally {
110
+ closeSync(fd);
111
+ }
112
+ }
98
113
  function writeOwnerOnlyFileAtomic(file, body) {
99
114
  const temporary = `${file}.${process.pid}.${randomUUID()}.tmp`;
100
115
  try {
@@ -11328,33 +11343,33 @@ var init_skill_length_ceilings = __esm(() => {
11328
11343
  "quality/tests-creator": 360,
11329
11344
  "quality/ui-craft": 173,
11330
11345
  "review/code-learned-review": 283,
11331
- "review/review-architecture": 373,
11332
- "review/review-backend": 361,
11333
- "review/review-clean-code": 538,
11346
+ "review/review-architecture": 337,
11347
+ "review/review-backend": 307,
11348
+ "review/review-clean-code": 204,
11334
11349
  "review/review-core-boundaries": 158,
11335
11350
  "review/review-degradation": 191,
11336
11351
  "review/review-flow-graph": 183,
11337
- "review/review-frontend": 611,
11338
- "review/review-frontend-conventions": 206,
11339
- "review/review-highload": 472,
11352
+ "review/review-frontend": 317,
11353
+ "review/review-frontend-conventions": 192,
11354
+ "review/review-highload": 328,
11340
11355
  "review/review-jev-comments": 179,
11341
11356
  "review/review-jev-contract": 188,
11342
11357
  "review/review-jev-docs": 184,
11343
11358
  "review/review-jev-risk": 185,
11344
11359
  "review/review-jev-rules": 262,
11345
11360
  "review/review-jev-scenarios": 182,
11346
- "review/review-layout": 237,
11347
- "review/review-logic": 365,
11361
+ "review/review-layout": 231,
11362
+ "review/review-logic": 364,
11348
11363
  "review/review-orchestrator": 1565,
11349
- "review/review-performance": 354,
11364
+ "review/review-performance": 332,
11350
11365
  "review/review-pr-contract": 190,
11351
11366
  "review/review-pr-feedback": 893,
11352
11367
  "review/review-premise": 180,
11353
11368
  "review/review-regression": 212,
11354
11369
  "review/review-security-code": 358,
11355
- "review/review-style": 354,
11356
- "review/review-testing-practices": 293,
11357
- "review/review-ui-ux": 267,
11370
+ "review/review-style": 315,
11371
+ "review/review-testing-practices": 275,
11372
+ "review/review-ui-ux": 227,
11358
11373
  "review/review-verifier": 299
11359
11374
  };
11360
11375
  SKILL_LENGTH_CEILINGS = new Map(Object.entries(CEILINGS_BY_KEY));
@@ -20429,8 +20444,8 @@ var init_repomap = __esm(() => {
20429
20444
 
20430
20445
  // src/session/preservation.ts
20431
20446
  import { createHash as createHash10, randomUUID as randomUUID5 } from "crypto";
20432
- import { closeSync as closeSync4, fsyncSync, mkdirSync as mkdirSync4, openSync as openSync4, readdirSync as readdirSync5, readFileSync as readFileSync15, renameSync as renameSync4, unlinkSync as unlinkSync2, writeFileSync as writeFileSync5 } from "fs";
20433
- import path69 from "path";
20447
+ import { closeSync as closeSync4, fsyncSync, mkdirSync as mkdirSync4, openSync as openSync4, readdirSync as readdirSync5, readFileSync as readFileSync15, renameSync as renameSync5, unlinkSync as unlinkSync2, writeFileSync as writeFileSync5 } from "fs";
20448
+ import path70 from "path";
20434
20449
  function syncDir(dir) {
20435
20450
  if (process.platform === "win32")
20436
20451
  return;
@@ -20442,7 +20457,7 @@ function syncDir(dir) {
20442
20457
  }
20443
20458
  }
20444
20459
  function writePreservationFile(file, body) {
20445
- const dir = path69.dirname(file);
20460
+ const dir = path70.dirname(file);
20446
20461
  mkdirSync4(dir, { recursive: true, mode: 448 });
20447
20462
  const tmp = `${file}.${randomUUID5()}.tmp`;
20448
20463
  const fd = openSync4(tmp, "wx", 384);
@@ -20453,7 +20468,7 @@ function writePreservationFile(file, body) {
20453
20468
  closeSync4(fd);
20454
20469
  }
20455
20470
  try {
20456
- renameSync4(tmp, file);
20471
+ renameSync5(tmp, file);
20457
20472
  syncDir(dir);
20458
20473
  } catch (error) {
20459
20474
  try {
@@ -20478,21 +20493,21 @@ function commitPreservation(dir, files, beforeSelect) {
20478
20493
  throw new Error("preservation snapshot exceeds readable size limit");
20479
20494
  }
20480
20495
  const id = hash(body);
20481
- const base = path69.join(dir, "preservation");
20482
- mkdirSync4(path69.join(base, "generations"), { recursive: true, mode: 448 });
20496
+ const base = path70.join(dir, "preservation");
20497
+ mkdirSync4(path70.join(base, "generations"), { recursive: true, mode: 448 });
20483
20498
  syncDir(dir);
20484
20499
  syncDir(base);
20485
- writePreservationFile(path69.join(base, "generations", `${id}.json`), body);
20500
+ writePreservationFile(path70.join(base, "generations", `${id}.json`), body);
20486
20501
  beforeSelect?.();
20487
- writePreservationFile(path69.join(base, "CURRENT"), id);
20502
+ writePreservationFile(path70.join(base, "CURRENT"), id);
20488
20503
  return id;
20489
20504
  }
20490
20505
  function readPreservation(dir, snapshotId) {
20491
- const base = path69.join(dir, "preservation");
20506
+ const base = path70.join(dir, "preservation");
20492
20507
  let id = snapshotId;
20493
20508
  if (id === undefined) {
20494
20509
  try {
20495
- id = readFileSync15(path69.join(base, "CURRENT"), "utf8");
20510
+ id = readFileSync15(path70.join(base, "CURRENT"), "utf8");
20496
20511
  } catch (e) {
20497
20512
  if (e.code === "ENOENT")
20498
20513
  return;
@@ -20501,7 +20516,7 @@ function readPreservation(dir, snapshotId) {
20501
20516
  }
20502
20517
  if (!/^[a-f0-9]{64}$/.test(id))
20503
20518
  throw new Error("invalid preservation identity");
20504
- const read = readTranscriptFile(path69.join(base, "generations", `${id}.json`));
20519
+ const read = readTranscriptFile(path70.join(base, "generations", `${id}.json`));
20505
20520
  if (!read.ok)
20506
20521
  throw new Error(`snapshot unreadable: ${read.reason}`);
20507
20522
  if (hash(read.text) !== id)
@@ -20531,7 +20546,7 @@ function collectPreservationFiles(dir, rawSlate) {
20531
20546
  for (const name of allowed) {
20532
20547
  if (name === "slate.json")
20533
20548
  continue;
20534
- const read = readTranscriptFile(path69.join(dir, name));
20549
+ const read = readTranscriptFile(path70.join(dir, name));
20535
20550
  if (read.ok)
20536
20551
  files[name] = read.text;
20537
20552
  else if (read.reason !== "absent")
@@ -20556,17 +20571,17 @@ function queuePreservedWrapUp(dir, rawSlate) {
20556
20571
  ...files["archive.jsonl"]?.trim() ? ["Transcript retained for evidence review"] : []
20557
20572
  ]
20558
20573
  };
20559
- const outbox = path69.join(dir, "preservation", "outbox");
20560
- const target = path69.join(outbox, `${snapshot}.json`);
20574
+ const outbox = path70.join(dir, "preservation", "outbox");
20575
+ const target = path70.join(outbox, `${snapshot}.json`);
20561
20576
  mkdirSync4(outbox, { recursive: true, mode: 448 });
20562
- syncDir(path69.dirname(outbox));
20577
+ syncDir(path70.dirname(outbox));
20563
20578
  writePreservationFile(target, JSON.stringify(receipt));
20564
20579
  return receipt;
20565
20580
  }
20566
20581
  function readPendingHistory(dir) {
20567
- let read = readConfigFile(path69.join(dir, "preservation", "HISTORY"));
20582
+ let read = readConfigFile(path70.join(dir, "preservation", "HISTORY"));
20568
20583
  if (!read.ok && read.reason === "absent") {
20569
- read = readConfigFile(path69.join(dir, "preservation", "MIRRORING"));
20584
+ read = readConfigFile(path70.join(dir, "preservation", "MIRRORING"));
20570
20585
  }
20571
20586
  if (!read.ok) {
20572
20587
  if (read.reason === "absent")
@@ -20590,7 +20605,7 @@ var init_preservation = __esm(() => {
20590
20605
 
20591
20606
  // src/session/slate.ts
20592
20607
  import { mkdir as mkdir13, readFile as readFile32, readdir as readdir18, stat as stat12 } from "fs/promises";
20593
- import path70 from "path";
20608
+ import path71 from "path";
20594
20609
  import { unlinkSync as unlinkSync3 } from "fs";
20595
20610
  function isReservedNoteKey(key) {
20596
20611
  return key.toLowerCase().startsWith(ASK_ANSWER_NOTE_PREFIX);
@@ -20601,7 +20616,7 @@ function modelNotesOf(notes) {
20601
20616
  return Object.fromEntries(Object.entries(notes).filter(([key]) => !isReservedNoteKey(key)));
20602
20617
  }
20603
20618
  function slatePath(dir) {
20604
- return path70.join(dir, "slate.json");
20619
+ return path71.join(dir, "slate.json");
20605
20620
  }
20606
20621
  function slateLockPath(dir) {
20607
20622
  return `${slatePath(dir)}.lock`;
@@ -20625,14 +20640,14 @@ function workingMemoryOf(slate) {
20625
20640
  };
20626
20641
  }
20627
20642
  async function readArchivedWorkingMemory(dir) {
20628
- const archiveDir = path70.join(dir, "slate-archive");
20643
+ const archiveDir = path71.join(dir, "slate-archive");
20629
20644
  try {
20630
20645
  const names = (await readdir18(archiveDir)).filter((n) => n.endsWith(".json"));
20631
- const dated = await Promise.all(names.map(async (n) => ({ n, at: (await stat12(path70.join(archiveDir, n))).mtimeMs })));
20646
+ const dated = await Promise.all(names.map(async (n) => ({ n, at: (await stat12(path71.join(archiveDir, n))).mtimeMs })));
20632
20647
  dated.sort((a, b) => b.at - a.at || (a.n < b.n ? 1 : -1));
20633
20648
  for (const { n } of dated) {
20634
20649
  try {
20635
- const slate = JSON.parse(await readFile32(path70.join(archiveDir, n), "utf8"));
20650
+ const slate = JSON.parse(await readFile32(path71.join(archiveDir, n), "utf8"));
20636
20651
  const carry = workingMemoryOf(slate);
20637
20652
  if (carry.trail !== undefined || carry.notes !== undefined || carry.answers !== undefined)
20638
20653
  return carry;
@@ -20667,11 +20682,11 @@ async function archiveIfExistsLocked(dir, attemptId, signal) {
20667
20682
  return;
20668
20683
  throw error;
20669
20684
  }
20670
- const archiveDir = path70.join(dir, "slate-archive");
20685
+ const archiveDir = path71.join(dir, "slate-archive");
20671
20686
  await mkdir13(archiveDir, { recursive: true });
20672
20687
  signal?.throwIfAborted();
20673
20688
  queuePreservedWrapUp(dir, raw);
20674
- writePreservationFile(path70.join(archiveDir, `${attemptId}.json`), raw);
20689
+ writePreservationFile(path71.join(archiveDir, `${attemptId}.json`), raw);
20675
20690
  unlinkSync3(slatePath(dir));
20676
20691
  }
20677
20692
  async function openSlateAtomic(dir, mintAttemptId, build, signal) {
@@ -20687,7 +20702,7 @@ async function openSlateAtomic(dir, mintAttemptId, build, signal) {
20687
20702
  writePreservationFile(slatePath(dir), `${JSON.stringify(next, null, 2)}
20688
20703
  `);
20689
20704
  try {
20690
- unlinkSync3(path70.join(dir, "terminal-state.json"));
20705
+ unlinkSync3(path71.join(dir, "terminal-state.json"));
20691
20706
  } catch (error) {
20692
20707
  if (!isNotFound(error))
20693
20708
  throw error;
@@ -21089,9 +21104,9 @@ var init_validation = __esm(() => {
21089
21104
  });
21090
21105
 
21091
21106
  // src/memory/config.ts
21092
- import path80 from "path";
21107
+ import path81 from "path";
21093
21108
  function memoryConfigPath(cwd) {
21094
- return path80.join(cwd, ".metaproject", "memory.config.json");
21109
+ return path81.join(cwd, ".metaproject", "memory.config.json");
21095
21110
  }
21096
21111
  async function loadMemoryConfig(cwd) {
21097
21112
  const file = memoryConfigPath(cwd);
@@ -21169,12 +21184,12 @@ var init_config4 = __esm(() => {
21169
21184
 
21170
21185
  // src/memory/write.ts
21171
21186
  import { mkdir as mkdir18, open as open6, readFile as readFile39, rename as rename4, rm as rm7, writeFile as writeFile9 } from "fs/promises";
21172
- import path83 from "path";
21187
+ import path84 from "path";
21173
21188
  async function resolveCanonicalEntryPath(cwd, relativePath) {
21174
- const root = path83.resolve(memoryRoot(cwd));
21175
- const absolutePath = path83.resolve(root, relativePath);
21176
- const normalized = toPosix2(path83.relative(root, absolutePath));
21177
- if (!normalized || normalized.startsWith("../") || path83.isAbsolute(normalized) || !normalized.endsWith(".md")) {
21189
+ const root = path84.resolve(memoryRoot(cwd));
21190
+ const absolutePath = path84.resolve(root, relativePath);
21191
+ const normalized = toPosix2(path84.relative(root, absolutePath));
21192
+ if (!normalized || normalized.startsWith("../") || path84.isAbsolute(normalized) || !normalized.endsWith(".md")) {
21178
21193
  return null;
21179
21194
  }
21180
21195
  return { absolutePath, relativePath: normalized };
@@ -21227,9 +21242,9 @@ function validateNextEntry(relativePath, content) {
21227
21242
  return null;
21228
21243
  }
21229
21244
  async function replaceAtomically(target, content) {
21230
- const dir = path83.dirname(target);
21245
+ const dir = path84.dirname(target);
21231
21246
  await mkdir18(dir, { recursive: true });
21232
- const tmp = path83.join(dir, `.${path83.basename(target)}.keryx-tmp-${process.pid}-${Math.random().toString(16).slice(2)}`);
21247
+ const tmp = path84.join(dir, `.${path84.basename(target)}.keryx-tmp-${process.pid}-${Math.random().toString(16).slice(2)}`);
21233
21248
  try {
21234
21249
  await writeFile9(tmp, content, "utf8");
21235
21250
  const file = await open6(tmp, "r");
@@ -21258,7 +21273,7 @@ function header(content, name) {
21258
21273
  return content.match(new RegExp(`^${name}:\\s*(.+)$`, "mi"))?.[1]?.trim() ?? null;
21259
21274
  }
21260
21275
  function toPosix2(value) {
21261
- return value.split(path83.sep).join("/");
21276
+ return value.split(path84.sep).join("/");
21262
21277
  }
21263
21278
  function message(cause) {
21264
21279
  return cause instanceof Error ? cause.message : String(cause);
@@ -21370,9 +21385,9 @@ var init_evidence = __esm(() => {
21370
21385
  });
21371
21386
 
21372
21387
  // src/wiki/config.ts
21373
- import path84 from "path";
21388
+ import path85 from "path";
21374
21389
  function wikiConfigPath(cwd) {
21375
- return path84.join(cwd, ".metaproject", "wiki.config.json");
21390
+ return path85.join(cwd, ".metaproject", "wiki.config.json");
21376
21391
  }
21377
21392
  function mergeWikiConfig(parsed) {
21378
21393
  const base = DEFAULT_WIKI_CONFIG;
@@ -21450,12 +21465,12 @@ var init_config5 = __esm(() => {
21450
21465
  // src/wiki/history.ts
21451
21466
  import { createHash as createHash20, randomBytes as randomBytes4 } from "crypto";
21452
21467
  import { appendFile as appendFile3, mkdir as mkdir19, open as open7, readFile as readFile41, rm as rm8, stat as stat13, writeFile as writeFile10 } from "fs/promises";
21453
- import path85 from "path";
21468
+ import path86 from "path";
21454
21469
  function wikiRootPath(cwd) {
21455
- return path85.join(cwd, ".metaproject", "wiki");
21470
+ return path86.join(cwd, ".metaproject", "wiki");
21456
21471
  }
21457
21472
  function wikiHistoryRoot(cwd) {
21458
- return path85.join(cwd, ".metaproject", "data", "gdwiki", "history");
21473
+ return path86.join(cwd, ".metaproject", "data", "gdwiki", "history");
21459
21474
  }
21460
21475
  function newWikiRunId(now = new Date) {
21461
21476
  const stamp = now.toISOString().replace(/[-:]/g, "").replace(/\.\d+Z$/, "Z");
@@ -21476,26 +21491,26 @@ async function openWikiWriteContext(cwd, command) {
21476
21491
  return createWikiWriteContext(cwd, command, { keep: (await loadWikiConfig(cwd)).history.keep });
21477
21492
  }
21478
21493
  function wikiPageKey(cwd, absolutePath) {
21479
- const relative = path85.relative(wikiRootPath(cwd), path85.resolve(absolutePath));
21480
- if (relative === "" || relative.startsWith("..") || path85.isAbsolute(relative)) {
21494
+ const relative = path86.relative(wikiRootPath(cwd), path86.resolve(absolutePath));
21495
+ if (relative === "" || relative.startsWith("..") || path86.isAbsolute(relative)) {
21481
21496
  throw new Error(`not a wiki page: ${absolutePath}`);
21482
21497
  }
21483
21498
  return toPosix(relative);
21484
21499
  }
21485
21500
  function assertPageKey(page) {
21486
21501
  const segments = page.split("/");
21487
- if (page.length === 0 || page.includes("\\") || path85.isAbsolute(page) || segments.some((segment) => segment === "" || segment === "." || segment === "..")) {
21502
+ if (page.length === 0 || page.includes("\\") || path86.isAbsolute(page) || segments.some((segment) => segment === "" || segment === "." || segment === "..")) {
21488
21503
  throw new Error(`not a wiki page path: ${page}`);
21489
21504
  }
21490
21505
  return page;
21491
21506
  }
21492
21507
  function pageHistoryDir(cwd, page) {
21493
- return path85.join(wikiHistoryRoot(cwd), ...assertPageKey(page).replace(/\.md$/i, "").split("/"));
21508
+ return path86.join(wikiHistoryRoot(cwd), ...assertPageKey(page).replace(/\.md$/i, "").split("/"));
21494
21509
  }
21495
21510
  function versionFilePath(cwd, page, file) {
21496
21511
  const dir = pageHistoryDir(cwd, page);
21497
- const target = path85.join(dir, file);
21498
- if (!VERSION_FILE.test(file) || path85.dirname(target) !== dir) {
21512
+ const target = path86.join(dir, file);
21513
+ if (!VERSION_FILE.test(file) || path86.dirname(target) !== dir) {
21499
21514
  throw new Error(`history index names an invalid version file for ${page}: ${file}`);
21500
21515
  }
21501
21516
  return target;
@@ -21562,7 +21577,7 @@ function parsePageHistoryIndex(markdown, page) {
21562
21577
  return { page, rows };
21563
21578
  }
21564
21579
  async function readPageHistory(cwd, page) {
21565
- const indexPath = path85.join(pageHistoryDir(cwd, page), INDEX_FILE);
21580
+ const indexPath = path86.join(pageHistoryDir(cwd, page), INDEX_FILE);
21566
21581
  const raw = await readBufferOrNull(indexPath);
21567
21582
  if (raw === null)
21568
21583
  return null;
@@ -21574,8 +21589,8 @@ async function readPageHistory(cwd, page) {
21574
21589
  }
21575
21590
  async function storeVersion(cwd, page, version, at, content) {
21576
21591
  const fileName = `${versionLabel(version)}-${at.replace(/[:.]/g, "-")}.md`;
21577
- const target = path85.join(pageHistoryDir(cwd, page), fileName);
21578
- await mkdir19(path85.dirname(target), { recursive: true });
21592
+ const target = path86.join(pageHistoryDir(cwd, page), fileName);
21593
+ await mkdir19(path86.dirname(target), { recursive: true });
21579
21594
  await writeFile10(target, content);
21580
21595
  if (sha2562(await readFile41(target)) !== sha2562(content)) {
21581
21596
  throw new Error(`history: stored version does not match the page bytes: ${target}`);
@@ -21613,7 +21628,7 @@ function planPrune2(history, keep, maxRows = MAX_INDEX_ROWS) {
21613
21628
  }
21614
21629
  async function ensureHistoryRoot(cwd) {
21615
21630
  const root = wikiHistoryRoot(cwd);
21616
- const ignore = path85.join(root, ".gitignore");
21631
+ const ignore = path86.join(root, ".gitignore");
21617
21632
  if (await readBufferOrNull(ignore))
21618
21633
  return;
21619
21634
  await mkdir19(root, { recursive: true });
@@ -21643,14 +21658,14 @@ async function endsWithoutNewline(file) {
21643
21658
  }
21644
21659
  async function appendRun(cwd, entry) {
21645
21660
  const root = wikiHistoryRoot(cwd);
21646
- const file = path85.join(root, RUNS_FILE);
21661
+ const file = path86.join(root, RUNS_FILE);
21647
21662
  const lead = await endsWithoutNewline(file) ? `
21648
21663
  ` : "";
21649
21664
  await appendFile3(file, `${lead}${JSON.stringify(entry)}
21650
21665
  `, "utf8");
21651
21666
  if ((await stat13(file)).size <= MAX_RUNS_BYTES)
21652
21667
  return;
21653
- await withFileLock2(path85.join(root, ".runs.lock"), async () => {
21668
+ await withFileLock2(path86.join(root, ".runs.lock"), async () => {
21654
21669
  if ((await stat13(file)).size <= MAX_RUNS_BYTES)
21655
21670
  return;
21656
21671
  const lines = (await readFile41(file, "utf8")).split(`
@@ -21664,7 +21679,7 @@ async function mutatePage(ctx, absolutePath, next) {
21664
21679
  const page = wikiPageKey(ctx.cwd, absolutePath);
21665
21680
  const dir = pageHistoryDir(ctx.cwd, page);
21666
21681
  await ensureHistoryRoot(ctx.cwd);
21667
- return withFileLock2(path85.join(path85.dirname(dir), `.${path85.basename(dir)}.lock`), async () => {
21682
+ return withFileLock2(path86.join(path86.dirname(dir), `.${path86.basename(dir)}.lock`), async () => {
21668
21683
  const live = await readBufferOrNull(absolutePath);
21669
21684
  if (next === null ? live === null : live !== null && live.equals(next)) {
21670
21685
  return { changed: false };
@@ -21688,7 +21703,7 @@ async function mutatePage(ctx, absolutePath, next) {
21688
21703
  if (next === null) {
21689
21704
  await rm8(absolutePath, { force: true });
21690
21705
  } else {
21691
- await mkdir19(path85.dirname(absolutePath), { recursive: true });
21706
+ await mkdir19(path86.dirname(absolutePath), { recursive: true });
21692
21707
  await writeFile10(absolutePath, next);
21693
21708
  }
21694
21709
  } catch (error) {
@@ -21696,7 +21711,7 @@ async function mutatePage(ctx, absolutePath, next) {
21696
21711
  await rm8(versionFilePath(ctx.cwd, page, row.file), { force: true });
21697
21712
  throw error;
21698
21713
  }
21699
- await writeFileAtomic(path85.join(dir, INDEX_FILE), renderPageHistoryIndex(history));
21714
+ await writeFileAtomic(path86.join(dir, INDEX_FILE), renderPageHistoryIndex(history));
21700
21715
  for (const file of pruned)
21701
21716
  await rm8(versionFilePath(ctx.cwd, page, file), { force: true });
21702
21717
  return { changed: true, action };
@@ -23413,23 +23428,24 @@ var TAG_MARKERS = {
23413
23428
  "http-server": ["express", "fastify", "koa", "hono", "@nestjs/core", "@hapi/hapi"]
23414
23429
  };
23415
23430
  var DEPENDENCY_FIELDS = ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"];
23416
- async function detectProjectStack(cwd, options = {}) {
23417
- const readFile = options.readFile ?? defaultReadFile;
23418
- const manifestPath = `${cwd.replace(/\/+$/, "")}/package.json`;
23431
+ async function readManifest(manifestPath, readFile) {
23419
23432
  let raw;
23420
23433
  try {
23421
23434
  raw = await readFile(manifestPath);
23422
23435
  } catch {
23423
- return uncertainStack(`package.json not found at ${manifestPath}`);
23436
+ return { kind: "missing" };
23424
23437
  }
23425
23438
  let parsed;
23426
23439
  try {
23427
23440
  parsed = JSON.parse(raw);
23428
23441
  } catch (error) {
23429
- return uncertainStack(`package.json at ${manifestPath} did not parse as JSON: ${error instanceof Error ? error.message : String(error)}`);
23442
+ return {
23443
+ kind: "invalid",
23444
+ reason: `package.json at ${manifestPath} did not parse as JSON: ${error instanceof Error ? error.message : String(error)}`
23445
+ };
23430
23446
  }
23431
23447
  if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
23432
- return uncertainStack(`package.json at ${manifestPath} is not a JSON object`);
23448
+ return { kind: "invalid", reason: `package.json at ${manifestPath} is not a JSON object` };
23433
23449
  }
23434
23450
  const record = parsed;
23435
23451
  const names = new Set;
@@ -23441,12 +23457,68 @@ async function detectProjectStack(cwd, options = {}) {
23441
23457
  }
23442
23458
  }
23443
23459
  }
23444
- const workspaceGlobs = workspacePatterns(record);
23445
- if (workspaceGlobs.length > 0) {
23446
- return uncertainStack(`package.json at ${manifestPath} declares workspaces (${workspaceGlobs.join(", ")}); the dependencies that decide the stack live in the sub-packages, which this module does not walk`);
23460
+ return { kind: "ok", names, workspaces: workspacePatterns(record) };
23461
+ }
23462
+ async function nearestPackageManifests(root, files, readFile) {
23463
+ const nearestByDir = new Map;
23464
+ const reads = new Map;
23465
+ for (const file of files) {
23466
+ const absolute = file.startsWith("/") ? file : `${root}/${file.replace(/^(\.\/)+/, "")}`;
23467
+ if (!absolute.startsWith(`${root}/`) || absolute.split("/").includes(".."))
23468
+ continue;
23469
+ const visited = [];
23470
+ let dir = absolute.slice(0, absolute.lastIndexOf("/"));
23471
+ let nearest;
23472
+ while (dir.startsWith(`${root}/`)) {
23473
+ if (nearestByDir.has(dir)) {
23474
+ nearest = nearestByDir.get(dir);
23475
+ break;
23476
+ }
23477
+ visited.push(dir);
23478
+ const manifestPath = `${dir}/package.json`;
23479
+ const read = await readManifest(manifestPath, readFile);
23480
+ if (read.kind !== "missing") {
23481
+ reads.set(manifestPath, read);
23482
+ nearest = manifestPath;
23483
+ break;
23484
+ }
23485
+ dir = dir.slice(0, dir.lastIndexOf("/"));
23486
+ }
23487
+ for (const seen of visited)
23488
+ nearestByDir.set(seen, nearest);
23489
+ }
23490
+ return reads;
23491
+ }
23492
+ async function detectProjectStack(cwd, options = {}) {
23493
+ const readFile = options.readFile ?? defaultReadFile;
23494
+ const root = cwd.replace(/\/+$/, "");
23495
+ const manifestPath = `${root}/package.json`;
23496
+ const files = options.files ?? [];
23497
+ const rootRead = await readManifest(manifestPath, readFile);
23498
+ if (rootRead.kind === "missing") {
23499
+ return uncertainStack(`package.json not found at ${manifestPath}`);
23500
+ }
23501
+ if (rootRead.kind === "invalid") {
23502
+ return uncertainStack(rootRead.reason);
23503
+ }
23504
+ const names = new Set(rootRead.names);
23505
+ const readPaths = [manifestPath];
23506
+ const nested = files.length > 0 ? await nearestPackageManifests(root, files, readFile) : new Map;
23507
+ for (const [nestedPath, read] of [...nested.entries()].sort(([a], [b]) => a.localeCompare(b))) {
23508
+ if (read.kind === "invalid") {
23509
+ return uncertainStack(read.reason);
23510
+ }
23511
+ if (read.kind !== "ok")
23512
+ continue;
23513
+ readPaths.push(nestedPath);
23514
+ for (const name of read.names)
23515
+ names.add(name);
23516
+ }
23517
+ if (files.length === 0 && rootRead.workspaces.length > 0) {
23518
+ return uncertainStack(`package.json at ${manifestPath} declares workspaces (${rootRead.workspaces.join(", ")}); the dependencies that decide the stack live in the sub-packages, and no scope files were given to find them`);
23447
23519
  }
23448
23520
  if (names.size === 0) {
23449
- return uncertainStack(`package.json at ${manifestPath} declares no dependencies in ${DEPENDENCY_FIELDS.join("/")} \u2014 a manifest that declares nothing has not said the repository uses nothing`);
23521
+ return uncertainStack(`${readPaths.join(", ")} declare${readPaths.length === 1 ? "s" : ""} no dependencies in ${DEPENDENCY_FIELDS.join("/")} \u2014 a manifest that declares nothing has not said the repository uses nothing`);
23450
23522
  }
23451
23523
  const matched = [];
23452
23524
  const nestjsMatches = [...names].filter((name) => name.startsWith("@nestjs/")).sort();
@@ -23460,7 +23532,7 @@ async function detectProjectStack(cwd, options = {}) {
23460
23532
  return {
23461
23533
  tags,
23462
23534
  uncertain: false,
23463
- reason: `detected from ${manifestPath} (${names.size} declared dependenc${names.size === 1 ? "y" : "ies"})`,
23535
+ reason: `detected from ${readPaths.join(", ")} (${names.size} declared dependenc${names.size === 1 ? "y" : "ies"})`,
23464
23536
  matched
23465
23537
  };
23466
23538
  }
@@ -24923,7 +24995,7 @@ function lightConventionsReviewer(roster, inventory) {
24923
24995
  }
24924
24996
  async function requiredReviewers(root, mode, files, options = {}) {
24925
24997
  const inventory = await collectReviewers(root);
24926
- const stack = await detectProjectStack(root);
24998
+ const stack = await detectProjectStack(root, { files });
24927
24999
  const excluded = [];
24928
25000
  const roster = [];
24929
25001
  for (const reviewer of inventory.bundled) {
@@ -25590,7 +25662,7 @@ init_json();
25590
25662
  var SLICE_MANIFEST_COPY = "slice-manifest.json";
25591
25663
  var readJson3 = (file) => readJsonFileOr(file, undefined);
25592
25664
  var text2 = (value) => typeof value === "string" && value.trim().length > 0;
25593
- async function readManifest(packageDir) {
25665
+ async function readManifest2(packageDir) {
25594
25666
  for (const candidate of [path52.join(packageDir, "slices", "manifest.json"), path52.join(packageDir, SLICE_MANIFEST_COPY)]) {
25595
25667
  const found = await readJson3(candidate);
25596
25668
  if (found !== undefined && Array.isArray(found.slices))
@@ -25640,7 +25712,7 @@ async function computeCoverage(packageDir, options = {}) {
25640
25712
  const research = options.research ?? await readJson3(path52.join(packageDir, "research.json"));
25641
25713
  const dispatch = asRecord5(asRecord5(research)?.dispatch);
25642
25714
  const radius = await readJson3(path52.join(packageDir, "blast-radius.json"));
25643
- const manifest = await readManifest(packageDir);
25715
+ const manifest = await readManifest2(packageDir);
25644
25716
  const retry = await readJson3(path52.join(packageDir, "retry-state.json"));
25645
25717
  const scopeA = await packageScopeFiles(packageDir) ?? [];
25646
25718
  const chunkPass = hasChunkPlan(packageDir) ? await computeChunkPass(packageDir) : null;
@@ -28744,9 +28816,52 @@ init_validator();
28744
28816
  import { appendFileSync as appendFileSync2 } from "fs";
28745
28817
 
28746
28818
  // src/lib/call-diagnostics.ts
28747
- init_config_dir();
28748
28819
  import { statSync as statSync5 } from "fs";
28820
+ import path66 from "path";
28821
+
28822
+ // src/lib/diagnostics-journal.ts
28823
+ init_config_dir();
28824
+ import { lstatSync as lstatSync4, renameSync as renameSync4 } from "fs";
28749
28825
  import path65 from "path";
28826
+ function createDiagnosticsJournal(opts) {
28827
+ const name = opts.sessionId.replace(/[^A-Za-z0-9._-]/g, "_") || "session";
28828
+ const file = path65.join(keryxConfigDir(opts.configDir), "diagnostics", `${name}.events.ndjson`);
28829
+ const cap = opts.maxFileBytes ?? 1e6;
28830
+ return {
28831
+ path: () => file,
28832
+ write(row) {
28833
+ try {
28834
+ const line = JSON.stringify(row);
28835
+ if (line === undefined || Buffer.byteLength(line) + 1 > cap)
28836
+ return { ok: false, error: "ROW_TOO_LARGE" };
28837
+ ensureKeryxSubdir(["diagnostics"], opts.configDir);
28838
+ let size = 0;
28839
+ try {
28840
+ const info = lstatSync4(file);
28841
+ if (!info.isFile() || info.nlink !== 1)
28842
+ return { ok: false, error: "UNSAFE_FILE" };
28843
+ size = info.size;
28844
+ } catch (error) {
28845
+ if (error.code !== "ENOENT")
28846
+ throw error;
28847
+ }
28848
+ if (size + Buffer.byteLength(line) + 1 > cap)
28849
+ renameSync4(file, `${file}.1`);
28850
+ appendPrivateRecord(file, line);
28851
+ return { ok: true };
28852
+ } catch (error) {
28853
+ const code = error?.code;
28854
+ return { ok: false, error: typeof code === "string" && /^[A-Z0-9_]+$/.test(code) ? code : "JOURNAL_WRITE_FAILED" };
28855
+ }
28856
+ }
28857
+ };
28858
+ }
28859
+ function diagnosticMeasurements(input) {
28860
+ return Object.fromEntries(Object.entries(input).filter(([key, value]) => /^[a-zA-Z][a-zA-Z0-9]{0,39}$/.test(key) && (typeof value === "boolean" || typeof value === "number" && Number.isFinite(value))));
28861
+ }
28862
+
28863
+ // src/lib/call-diagnostics.ts
28864
+ init_config_dir();
28750
28865
  var DEFAULT_WATCH_INTERVAL_MS = 30000;
28751
28866
  var DEFAULT_STALL_MS = 10 * 60000;
28752
28867
  var DEFAULT_REPEAT_MS = 15 * 60000;
@@ -28778,6 +28893,39 @@ function createCallDiagnostics(options = {}) {
28778
28893
  let repeatMs = DEFAULT_REPEAT_MS;
28779
28894
  let lastDumpAt;
28780
28895
  let lastDumpIds = new Set;
28896
+ let journal;
28897
+ let journalFailure;
28898
+ let warnJournal;
28899
+ let warningDelivered = false;
28900
+ const persist = (kind, fields = {}) => {
28901
+ if (journal === undefined)
28902
+ return;
28903
+ const result = journal.write({ ts: new Date(now()).toISOString(), kind, ...fields });
28904
+ if (result.ok)
28905
+ return;
28906
+ journalFailure = result.error;
28907
+ if (!warningDelivered) {
28908
+ warningDelivered = true;
28909
+ try {
28910
+ warnJournal?.(result.error);
28911
+ } catch {
28912
+ journalFailure = "JOURNAL_WARNING_FAILED";
28913
+ }
28914
+ }
28915
+ };
28916
+ const persistSnapshot = () => persist("snapshot", {
28917
+ calls: [...calls.values()].map((c) => ({
28918
+ id: c.id,
28919
+ name: c.name,
28920
+ stage: c.stage,
28921
+ ageMs: now() - c.startedAt,
28922
+ stageAgeMs: now() - c.stageSince,
28923
+ stageChanges: c.stageChanges
28924
+ })),
28925
+ callsStarted: metrics.callsStarted,
28926
+ callsSettled: metrics.callsSettled,
28927
+ lastLagMs
28928
+ });
28781
28929
  const record = (label) => {
28782
28930
  ring.push(`${new Date(now()).toISOString()} ${label}`);
28783
28931
  if (ring.length > ringSize)
@@ -28865,6 +29013,7 @@ function createCallDiagnostics(options = {}) {
28865
29013
  metrics.maxLoopLagMs = lag;
28866
29014
  }
28867
29015
  lastTickAt = at;
29016
+ persistSnapshot();
28868
29017
  const suspects = [...calls.values()].filter((c) => c.watched && at - c.stageSince >= (HUMAN_STAGES.has(c.stage) ? stallMs * HUMAN_STAGE_FACTOR : stallMs));
28869
29018
  if (suspects.length === 0) {
28870
29019
  lastDumpIds = new Set;
@@ -28888,6 +29037,7 @@ function createCallDiagnostics(options = {}) {
28888
29037
  key = `${id}~${n}`;
28889
29038
  calls.set(key, { id: key, name, startedAt: at, watched: opts?.watched !== false, stage: "start", stageSince: at, stageChanges: 0 });
28890
29039
  metrics.callsStarted += 1;
29040
+ persist("call.begin", { id: key, name });
28891
29041
  return key;
28892
29042
  },
28893
29043
  stage(id, next) {
@@ -28899,6 +29049,7 @@ function createCallDiagnostics(options = {}) {
28899
29049
  call.stage = next;
28900
29050
  call.stageSince = at;
28901
29051
  call.stageChanges += 1;
29052
+ persist("call.stage", { id, stage: next });
28902
29053
  },
28903
29054
  end(id, outcome) {
28904
29055
  const call = calls.get(id);
@@ -28908,10 +29059,12 @@ function createCallDiagnostics(options = {}) {
28908
29059
  calls.delete(id);
28909
29060
  metrics.callsSettled += 1;
28910
29061
  metrics.callsByOutcome[outcome] = (metrics.callsByOutcome[outcome] ?? 0) + 1;
29062
+ persist("call.end", { id, outcome, ageMs: now() - call.startedAt });
28911
29063
  },
28912
29064
  event(kind, detail) {
28913
29065
  metrics.events[kind] = (metrics.events[kind] ?? 0) + 1;
28914
29066
  record(detail === undefined ? `event ${kind}` : `event ${kind} ${detail}`);
29067
+ persist(kind);
28915
29068
  },
28916
29069
  record,
28917
29070
  probe(name, fn) {
@@ -28925,6 +29078,9 @@ function createCallDiagnostics(options = {}) {
28925
29078
  dump,
28926
29079
  inFlight: () => [...calls.values()],
28927
29080
  dumpPath: () => file,
29081
+ journalPath: () => journal?.path(),
29082
+ journalError: () => journalFailure,
29083
+ observe: (kind, measurements) => persist(kind, diagnosticMeasurements(measurements)),
28928
29084
  tick,
28929
29085
  start(opts) {
28930
29086
  sessionId = opts.sessionId;
@@ -28932,11 +29088,19 @@ function createCallDiagnostics(options = {}) {
28932
29088
  stallMs = opts.stallMs ?? DEFAULT_STALL_MS;
28933
29089
  repeatMs = opts.repeatMs ?? DEFAULT_REPEAT_MS;
28934
29090
  const cap = opts.maxFileBytes ?? DEFAULT_MAX_FILE_BYTES;
29091
+ journal = opts.continuous ? createDiagnosticsJournal(opts) : undefined;
29092
+ journalFailure = undefined;
29093
+ warningDelivered = false;
29094
+ warnJournal = opts.onJournalError ?? ((code) => {
29095
+ process.stderr.write(`keryx: diagnostics journal unavailable (${code}).
29096
+ `);
29097
+ });
29098
+ persist("session.start", { pid: process.pid, sessionId });
28935
29099
  if (sink === undefined) {
28936
29100
  sink = (line) => {
28937
29101
  if (file === undefined) {
28938
29102
  const dir = ensureKeryxSubdir(["diagnostics"], opts.configDir);
28939
- file = path65.join(dir, `${opts.sessionId.replace(/[^A-Za-z0-9._-]/g, "_")}.ndjson`);
29103
+ file = path66.join(dir, `${opts.sessionId.replace(/[^A-Za-z0-9._-]/g, "_")}.ndjson`);
28940
29104
  }
28941
29105
  let size = 0;
28942
29106
  try {
@@ -28954,7 +29118,16 @@ function createCallDiagnostics(options = {}) {
28954
29118
  } catch {}
28955
29119
  }, intervalMs);
28956
29120
  timer.unref?.();
28957
- return () => clearInterval(timer);
29121
+ let stopped = false;
29122
+ return () => {
29123
+ if (stopped)
29124
+ return;
29125
+ stopped = true;
29126
+ clearInterval(timer);
29127
+ persistSnapshot();
29128
+ persist("session.stop");
29129
+ journal = undefined;
29130
+ };
28958
29131
  }
28959
29132
  };
28960
29133
  }
@@ -28977,7 +29150,7 @@ function tracePhase(label, env = process.env) {
28977
29150
  init_json();
28978
29151
  init_shell_syntax();
28979
29152
  import { readdir as readdir17, stat as stat11 } from "fs/promises";
28980
- import path66 from "path";
29153
+ import path67 from "path";
28981
29154
  var PR_REF = /(?:github\.com\/([\w.-]+\/[\w.-]+)\/pull\/(\d+))|^#?(\d+)$/;
28982
29155
  var REVIEW_ENDPOINT = /(?:^|\/)repos\/([^/]+\/[^/]+)\/pulls\/(\d+)\/reviews(?:\/\d+\/events)?\/?$/;
28983
29156
  var PR_REVIEW_VALUE_FLAGS = new Set(["-R", "--repo", "-b", "--body", "-F", "--body-file"]);
@@ -29056,12 +29229,12 @@ async function boundPackages(cwd) {
29056
29229
  }
29057
29230
  const found = [];
29058
29231
  for (const name of names) {
29059
- const dir = path66.join(reviewsRoot(cwd), name);
29060
- const manifest = await readJsonFileOr(path66.join(dir, "manifest.json"), undefined);
29232
+ const dir = path67.join(reviewsRoot(cwd), name);
29233
+ const manifest = await readJsonFileOr(path67.join(dir, "manifest.json"), undefined);
29061
29234
  if (manifest === undefined || !isPrBound(manifest.target))
29062
29235
  continue;
29063
29236
  const ref = parseRef(manifest.target.ref);
29064
- const info = await stat11(path66.join(dir, "manifest.json")).catch(() => {
29237
+ const info = await stat11(path67.join(dir, "manifest.json")).catch(() => {
29065
29238
  return;
29066
29239
  });
29067
29240
  found.push({ dir, id: manifest.reviewId, status: manifest.status, number: ref.number, repo: ref.repo, mtime: info?.mtimeMs ?? 0 });
@@ -29234,7 +29407,7 @@ init_command_risk();
29234
29407
  init_contained_path();
29235
29408
  import { createHash as createHash9 } from "crypto";
29236
29409
  import { closeSync as closeSync3, constants as constants6, fstatSync as fstatSync3, openSync as openSync3, readSync } from "fs";
29237
- import path67 from "path";
29410
+ import path68 from "path";
29238
29411
 
29239
29412
  // src/lib/review-path-flags.ts
29240
29413
  init_args();
@@ -29392,7 +29565,7 @@ function carriesPreload(text) {
29392
29565
  }
29393
29566
  var MAX_BUNFIG_BYTES = 256 * 1024;
29394
29567
  function readBunfig(root) {
29395
- const file = path67.join(root, "bunfig.toml");
29568
+ const file = path68.join(root, "bunfig.toml");
29396
29569
  let fd;
29397
29570
  try {
29398
29571
  fd = openSync3(file, constants6.O_RDONLY | constants6.O_NONBLOCK);
@@ -29473,10 +29646,10 @@ function movedTo(cwd, target) {
29473
29646
  if (cwd === undefined || target === "" || target.startsWith("-") || isExpandable(target))
29474
29647
  return;
29475
29648
  const cdpath = process.env.CDPATH;
29476
- if (cdpath !== undefined && cdpath !== "" && !path67.isAbsolute(target) && !target.startsWith("./") && !target.startsWith("../")) {
29649
+ if (cdpath !== undefined && cdpath !== "" && !path68.isAbsolute(target) && !target.startsWith("./") && !target.startsWith("../")) {
29477
29650
  return;
29478
29651
  }
29479
- const lexical = path67.resolve(cwd, target);
29652
+ const lexical = path68.resolve(cwd, target);
29480
29653
  return realOrResolved(lexical) === lexical ? lexical : undefined;
29481
29654
  }
29482
29655
  function areReviewPathFlagsInside(sub, args, walk) {
@@ -29511,11 +29684,11 @@ function isOutsideReadFlag(word) {
29511
29684
  return name.length >= 3 && name.startsWith("--") && GIT_OUTSIDE_READ_FLAGS.some((flag) => flag.startsWith(name));
29512
29685
  }
29513
29686
  function isOutsideRoot(projectRoot, target) {
29514
- const relative = path67.relative(projectRoot, target);
29515
- return relative === ".." || relative.startsWith(`..${path67.sep}`) || path67.isAbsolute(relative);
29687
+ const relative = path68.relative(projectRoot, target);
29688
+ return relative === ".." || relative.startsWith(`..${path68.sep}`) || path68.isAbsolute(relative);
29516
29689
  }
29517
29690
  function isEscapingOperand(word, cwd, projectRoot) {
29518
- return isOutsideRoot(projectRoot, realOrResolved(path67.resolve(cwd, word)));
29691
+ return isOutsideRoot(projectRoot, realOrResolved(path68.resolve(cwd, word)));
29519
29692
  }
29520
29693
  function isGitReadConfined(words, walk) {
29521
29694
  const cwd = walk.cwd;
@@ -29556,7 +29729,7 @@ function isTrustRoutineCommand(command, context = {}) {
29556
29729
  const segments = splitSegments(command);
29557
29730
  if (segments.length === 0 || segments.length > MAX_CHAIN_SEGMENTS)
29558
29731
  return false;
29559
- const cwd = realOrResolved(path67.resolve(context.cwd ?? process.cwd()));
29732
+ const cwd = realOrResolved(path68.resolve(context.cwd ?? process.cwd()));
29560
29733
  const walk = { projectRoot: realOrResolved(resolveProjectRoot(cwd)), cwd, untrusted: context.untrustedContent === true };
29561
29734
  return segments.every((seg) => (seg.precededBy === undefined || seg.precededBy === "&&") && !hasUnquotedMetacharacter(seg.raw) && !(isJudgedByWords(seg.words) && hasUnquotedExpansion(seg.raw)) && isRoutineSegment(seg.words, walk));
29562
29735
  }
@@ -29591,9 +29764,9 @@ function resolveQuestionAnswerer(mode) {
29591
29764
  }
29592
29765
 
29593
29766
  // src/commands/automatic-review.ts
29594
- import { existsSync as existsSync17, lstatSync as lstatSync4, realpathSync as realpathSync4 } from "fs";
29767
+ import { existsSync as existsSync17, lstatSync as lstatSync5, realpathSync as realpathSync4 } from "fs";
29595
29768
  import { mkdir as mkdir12, writeFile as writeFile7 } from "fs/promises";
29596
- import path68 from "path";
29769
+ import path69 from "path";
29597
29770
 
29598
29771
  // src/harness/tool/builtin/ask-user-tool.ts
29599
29772
  var ASK_USER_DESCRIPTION = "Ask the user an interactive multiple-choice question (Claude-style interview). " + "Use when requirements are unclear, for interview steps, or to confirm a plan. " + "Provide 2\u20136 options with short descriptions; mark at most ONE option recommended when sensible (more than one is rejected). " + "Whenever you mark an option recommended, ALWAYS set recommendationReason: one sentence on why it is the better choice. " + "Input: { question: string, options: [{ id, label, description, recommended? }], recommendationReason?: string, allow_freeform?: boolean, action?: string, irreversible?: boolean, emergency?: string }. " + "Returns the chosen option id (or freeform text if allow_freeform). " + "irreversible: true means the question decides something that cannot be undone (release, publish, deploy, delete, push, merge to a shared branch, drop, force, reset, tag a version). " + 'action names that irreversible action (e.g. action: "release"). ' + "policy: { kind, facts } optionally tags a review question with its kind (scope, budget, option_choice, partial_coverage, smaller_slice, slice_order) " + "and numeric or boolean facts about the recommended option; only the automatic answerer reads it, as numbers and flags, never as text. " + `emergency: "gate-waiver" (a gate refusal needs the operator's quote) or "reduced-reviewer-set"; the only two cases an automatic review may put to the operator.`;
@@ -29805,7 +29978,7 @@ var OPERATOR_ONLY_NAMES = new Set([foldFileName(OPERATOR_DECISIONS_FILE), foldFi
29805
29978
  var PLAIN_SEGMENT = /^[A-Za-z0-9._-]+$/;
29806
29979
  function entryExists(file) {
29807
29980
  try {
29808
- lstatSync4(file);
29981
+ lstatSync5(file);
29809
29982
  return true;
29810
29983
  } catch {
29811
29984
  return false;
@@ -29815,20 +29988,20 @@ function realTarget(target) {
29815
29988
  let existing = target;
29816
29989
  const rest = [];
29817
29990
  while (!entryExists(existing)) {
29818
- const parent = path68.dirname(existing);
29991
+ const parent = path69.dirname(existing);
29819
29992
  if (parent === existing)
29820
29993
  return target;
29821
- rest.unshift(path68.basename(existing));
29994
+ rest.unshift(path69.basename(existing));
29822
29995
  existing = parent;
29823
29996
  }
29824
29997
  try {
29825
- return path68.join(realpathSync4(existing), ...rest);
29998
+ return path69.join(realpathSync4(existing), ...rest);
29826
29999
  } catch {
29827
30000
  return "";
29828
30001
  }
29829
30002
  }
29830
30003
  function segmentsBelow(base, target) {
29831
- return path68.relative(base, target).split(/[\\/]/);
30004
+ return path69.relative(base, target).split(/[\\/]/);
29832
30005
  }
29833
30006
  function hasOnlyPlainSegments(base, target) {
29834
30007
  return segmentsBelow(base, target).every((segment) => PLAIN_SEGMENT.test(segment));
@@ -29837,7 +30010,7 @@ function touchesOperatorOnlyName(base, target) {
29837
30010
  return segmentsBelow(base, target).some((segment) => OPERATOR_ONLY_NAMES.has(foldFileName(segment)));
29838
30011
  }
29839
30012
  function escapesPackage(realDir, real) {
29840
- return !real.startsWith(`${realDir}${path68.sep}`);
30013
+ return !real.startsWith(`${realDir}${path69.sep}`);
29841
30014
  }
29842
30015
 
29843
30016
  class AutomaticReviewRun {
@@ -29875,11 +30048,11 @@ class AutomaticReviewRun {
29875
30048
  return false;
29876
30049
  }
29877
30050
  const realDir = realTarget(dir);
29878
- const isData = (file) => PACKAGE_DATA_EXTENSIONS.has(path68.extname(file).toLowerCase());
30051
+ const isData = (file) => PACKAGE_DATA_EXTENSIONS.has(path69.extname(file).toLowerCase());
29879
30052
  return targets.every((target) => {
29880
- const resolved = path68.resolve(this.cwd, target);
30053
+ const resolved = path69.resolve(this.cwd, target);
29881
30054
  const real = realTarget(resolved);
29882
- return resolved.startsWith(`${dir}${path68.sep}`) && !escapesPackage(realDir, real) && hasOnlyPlainSegments(dir, resolved) && hasOnlyPlainSegments(realDir, real) && isData(resolved) && isData(real) && !touchesOperatorOnlyName(dir, resolved) && !touchesOperatorOnlyName(realDir, real);
30055
+ return resolved.startsWith(`${dir}${path69.sep}`) && !escapesPackage(realDir, real) && hasOnlyPlainSegments(dir, resolved) && hasOnlyPlainSegments(realDir, real) && isData(resolved) && isData(real) && !touchesOperatorOnlyName(dir, resolved) && !touchesOperatorOnlyName(realDir, real);
29883
30056
  });
29884
30057
  }
29885
30058
  observe(command, result) {
@@ -29898,8 +30071,8 @@ class AutomaticReviewRun {
29898
30071
  if (id === undefined || printed === undefined) {
29899
30072
  return;
29900
30073
  }
29901
- const dir = path68.resolve(this.cwd, printed);
29902
- const metaproject = path68.join(path68.resolve(this.cwd), ".metaproject") + path68.sep;
30074
+ const dir = path69.resolve(this.cwd, printed);
30075
+ const metaproject = path69.join(path69.resolve(this.cwd), ".metaproject") + path69.sep;
29903
30076
  if (dir.startsWith(metaproject)) {
29904
30077
  this.binding = { id, dir };
29905
30078
  }
@@ -29944,13 +30117,13 @@ class AutomaticReviewRun {
29944
30117
  }
29945
30118
  summaryLine() {
29946
30119
  const { manual, automatic } = this.disclosure();
29947
- return `[automatic review] inputs: ${manual} manual, ${automatic} automatic${this.binding === undefined ? "" : ` (${path68.relative(this.cwd, path68.join(this.binding.dir, AUTOMATIC_REVIEW_DISCLOSURE_FILE))})`}`;
30120
+ return `[automatic review] inputs: ${manual} manual, ${automatic} automatic${this.binding === undefined ? "" : ` (${path69.relative(this.cwd, path69.join(this.binding.dir, AUTOMATIC_REVIEW_DISCLOSURE_FILE))})`}`;
29948
30121
  }
29949
30122
  async writeDisclosure() {
29950
30123
  if (this.binding === undefined) {
29951
30124
  return;
29952
30125
  }
29953
- const file = path68.join(this.binding.dir, AUTOMATIC_REVIEW_DISCLOSURE_FILE);
30126
+ const file = path69.join(this.binding.dir, AUTOMATIC_REVIEW_DISCLOSURE_FILE);
29954
30127
  await mkdir12(this.binding.dir, { recursive: true });
29955
30128
  await writeFile7(file, `${JSON.stringify(this.disclosure(), null, 2)}
29956
30129
  `, "utf8");
@@ -30011,27 +30184,27 @@ class AutomaticReviewRun {
30011
30184
  if (this.binding !== undefined) {
30012
30185
  return this.insidePackage(value);
30013
30186
  }
30014
- const resolved = path68.resolve(this.cwd, value);
30015
- return resolved.startsWith(reviewsRoot(path68.resolve(this.cwd)) + path68.sep);
30187
+ const resolved = path69.resolve(this.cwd, value);
30188
+ return resolved.startsWith(reviewsRoot(path69.resolve(this.cwd)) + path69.sep);
30016
30189
  }
30017
30190
  insidePackage(value) {
30018
30191
  const dir = this.binding?.dir;
30019
30192
  if (dir === undefined) {
30020
30193
  return false;
30021
30194
  }
30022
- const resolved = path68.resolve(this.cwd, value);
30023
- return resolved === dir || resolved.startsWith(`${dir}${path68.sep}`);
30195
+ const resolved = path69.resolve(this.cwd, value);
30196
+ return resolved === dir || resolved.startsWith(`${dir}${path69.sep}`);
30024
30197
  }
30025
30198
  insideCwd(value) {
30026
- const resolved = path68.resolve(this.cwd, value);
30027
- const root = path68.resolve(this.cwd);
30028
- return resolved === root || resolved.startsWith(`${root}${path68.sep}`);
30199
+ const resolved = path69.resolve(this.cwd, value);
30200
+ const root = path69.resolve(this.cwd);
30201
+ return resolved === root || resolved.startsWith(`${root}${path69.sep}`);
30029
30202
  }
30030
30203
  namesReviewPackage(value) {
30031
30204
  if (value === "" || value.startsWith("-"))
30032
30205
  return false;
30033
- const asPath = path68.resolve(this.cwd, value);
30034
- if (!/[\\/]/.test(value) && value !== "." && value !== ".." && !existsSync17(path68.join(asPath, "manifest.json")))
30206
+ const asPath = path69.resolve(this.cwd, value);
30207
+ if (!/[\\/]/.test(value) && value !== "." && value !== ".." && !existsSync17(path69.join(asPath, "manifest.json")))
30035
30208
  return true;
30036
30209
  return this.insideCwd(value) && isReviewPackageDir(asPath, this.cwd);
30037
30210
  }
@@ -30039,7 +30212,7 @@ class AutomaticReviewRun {
30039
30212
  if (this.binding === undefined) {
30040
30213
  return false;
30041
30214
  }
30042
- return ref === this.binding.id || path68.resolve(this.cwd, ref) === this.binding.dir;
30215
+ return ref === this.binding.id || path69.resolve(this.cwd, ref) === this.binding.dir;
30043
30216
  }
30044
30217
  }
30045
30218
 
@@ -31056,7 +31229,7 @@ function consolidateAnchors(removed) {
31056
31229
  // src/harness/tool/output-spill.ts
31057
31230
  import { createHash as createHash11 } from "crypto";
31058
31231
  import { chmod as chmod4, mkdir as mkdir14, open as open5 } from "fs/promises";
31059
- import path71 from "path";
31232
+ import path72 from "path";
31060
31233
  var TOOL_OUTPUT_SPILL_MAX_LINES = 2000;
31061
31234
  var TOOL_OUTPUT_SPILL_MAX_BYTES = 50 * 1024;
31062
31235
  var TOOL_OUTPUT_PREVIEW_CHARS = 16 * 1024;
@@ -31112,14 +31285,14 @@ var TOOL_OUTPUT_DIR_MODE = 448;
31112
31285
  var TOOL_OUTPUT_FILE_MODE = 384;
31113
31286
  var MAX_NAME_ATTEMPTS = 50;
31114
31287
  async function writeUniqueOutputFile(sessionDir, toolCallId, text) {
31115
- const dir = path71.join(sessionDir, TOOL_OUTPUT_DIRNAME);
31288
+ const dir = path72.join(sessionDir, TOOL_OUTPUT_DIRNAME);
31116
31289
  try {
31117
31290
  await mkdir14(dir, { recursive: true, mode: TOOL_OUTPUT_DIR_MODE });
31118
31291
  await chmod4(dir, TOOL_OUTPUT_DIR_MODE);
31119
31292
  const hash = createHash11("sha256").update(text).digest("hex").slice(0, 8);
31120
31293
  const base = `${Date.now()}-${hash}-${safeFileStem(toolCallId)}`;
31121
31294
  for (let attempt = 0;attempt < MAX_NAME_ATTEMPTS; attempt++) {
31122
- const filePath = path71.join(dir, `${base}${attempt === 0 ? "" : `-${attempt}`}.txt`);
31295
+ const filePath = path72.join(dir, `${base}${attempt === 0 ? "" : `-${attempt}`}.txt`);
31123
31296
  let handle;
31124
31297
  try {
31125
31298
  handle = await open5(filePath, "wx", TOOL_OUTPUT_FILE_MODE);
@@ -31145,11 +31318,11 @@ async function writeToolOutputFile(sessionDir, toolCallId, text) {
31145
31318
  return writeUniqueOutputFile(sessionDir, toolCallId, text);
31146
31319
  }
31147
31320
  function isInsideToolOutputDir(sessionDir, candidate) {
31148
- if (!path71.isAbsolute(candidate)) {
31321
+ if (!path72.isAbsolute(candidate)) {
31149
31322
  return false;
31150
31323
  }
31151
- const rel = path71.relative(path71.join(sessionDir, TOOL_OUTPUT_DIRNAME), path71.resolve(candidate));
31152
- return rel !== "" && rel !== ".." && !rel.startsWith(`..${path71.sep}`) && !path71.isAbsolute(rel);
31324
+ const rel = path72.relative(path72.join(sessionDir, TOOL_OUTPUT_DIRNAME), path72.resolve(candidate));
31325
+ return rel !== "" && rel !== ".." && !rel.startsWith(`..${path72.sep}`) && !path72.isAbsolute(rel);
31153
31326
  }
31154
31327
  async function spillToolOutput(text, ctx) {
31155
31328
  if (ctx.sessionDir === undefined || !exceedsSpillThreshold(text)) {
@@ -31468,15 +31641,15 @@ import {
31468
31641
  existsSync as existsSync19,
31469
31642
  mkdirSync as mkdirSync5,
31470
31643
  readdirSync as readdirSync6,
31471
- renameSync as renameSync5,
31644
+ renameSync as renameSync6,
31472
31645
  writeFileSync as writeFileSync6
31473
31646
  } from "fs";
31474
- import path73 from "path";
31647
+ import path74 from "path";
31475
31648
 
31476
31649
  // src/session/paths.ts
31477
31650
  import { existsSync as existsSync18 } from "fs";
31478
31651
  import { homedir as homedir3 } from "os";
31479
- import path72 from "path";
31652
+ import path73 from "path";
31480
31653
  function keryxDataDir(override) {
31481
31654
  if (override !== undefined && override.length > 0) {
31482
31655
  return override;
@@ -31488,22 +31661,22 @@ function keryxDataDir(override) {
31488
31661
  const home = homedir3();
31489
31662
  if (process.platform === "win32") {
31490
31663
  const appData = process.env.APPDATA;
31491
- const base = appData !== undefined && appData.length > 0 ? appData : path72.join(home, "AppData", "Roaming");
31492
- return path72.join(base, "keryx");
31664
+ const base = appData !== undefined && appData.length > 0 ? appData : path73.join(home, "AppData", "Roaming");
31665
+ return path73.join(base, "keryx");
31493
31666
  }
31494
31667
  const xdg = process.env.XDG_DATA_HOME;
31495
- const base = xdg !== undefined && xdg.length > 0 ? xdg : path72.join(home, ".local", "share");
31496
- return path72.join(base, "keryx");
31668
+ const base = xdg !== undefined && xdg.length > 0 ? xdg : path73.join(home, ".local", "share");
31669
+ return path73.join(base, "keryx");
31497
31670
  }
31498
31671
  function resolveProjectRoot2(cwd) {
31499
- const abs = path72.resolve(cwd);
31672
+ const abs = path73.resolve(cwd);
31500
31673
  let dir = abs;
31501
31674
  for (;; ) {
31502
- const gitPath = path72.join(dir, ".git");
31675
+ const gitPath = path73.join(dir, ".git");
31503
31676
  if (existsSync18(gitPath)) {
31504
31677
  return dir;
31505
31678
  }
31506
- const parent = path72.dirname(dir);
31679
+ const parent = path73.dirname(dir);
31507
31680
  if (parent === dir) {
31508
31681
  break;
31509
31682
  }
@@ -31512,12 +31685,12 @@ function resolveProjectRoot2(cwd) {
31512
31685
  return abs;
31513
31686
  }
31514
31687
  function projectKeyFromPath(projectPath) {
31515
- const abs = path72.resolve(projectPath);
31688
+ const abs = path73.resolve(projectPath);
31516
31689
  const encoded = encodeURIComponent(abs);
31517
31690
  if (encoded.length <= 200) {
31518
31691
  return encoded;
31519
31692
  }
31520
- const base = path72.basename(abs).replace(/[^a-zA-Z0-9._-]+/g, "_").slice(0, 40);
31693
+ const base = path73.basename(abs).replace(/[^a-zA-Z0-9._-]+/g, "_").slice(0, 40);
31521
31694
  let h = 0;
31522
31695
  for (let i = 0;i < abs.length; i++) {
31523
31696
  h = Math.imul(31, h) + abs.charCodeAt(i) | 0;
@@ -31527,10 +31700,10 @@ function projectKeyFromPath(projectPath) {
31527
31700
  }
31528
31701
  function projectSessionsDir(projectPath, dataDir) {
31529
31702
  const key = projectKeyFromPath(resolveProjectRoot2(projectPath));
31530
- return path72.join(keryxDataDir(dataDir), "sessions", key);
31703
+ return path73.join(keryxDataDir(dataDir), "sessions", key);
31531
31704
  }
31532
31705
  function sessionDir(projectPath, sessionId, dataDir) {
31533
- return path72.join(projectSessionsDir(projectPath, dataDir), sessionId);
31706
+ return path73.join(projectSessionsDir(projectPath, dataDir), sessionId);
31534
31707
  }
31535
31708
 
31536
31709
  // src/session/store.ts
@@ -31626,7 +31799,7 @@ function parseRemote(value) {
31626
31799
  function readSummaryFile(file) {
31627
31800
  let pending;
31628
31801
  try {
31629
- pending = readPendingHistory(path73.dirname(file));
31802
+ pending = readPendingHistory(path74.dirname(file));
31630
31803
  } catch {
31631
31804
  pending = undefined;
31632
31805
  }
@@ -31678,11 +31851,11 @@ class TranscriptUnreadableError extends Error {
31678
31851
  }
31679
31852
  }
31680
31853
  function readJsonl(file) {
31681
- const pending = readPendingHistory(path73.dirname(file));
31854
+ const pending = readPendingHistory(path74.dirname(file));
31682
31855
  if (pending === undefined && !existsSync19(file)) {
31683
31856
  return [];
31684
31857
  }
31685
- const read = pending !== undefined ? { ok: true, text: pending.files[path73.basename(file)] } : readTranscriptFile(file);
31858
+ const read = pending !== undefined ? { ok: true, text: pending.files[path74.basename(file)] } : readTranscriptFile(file);
31686
31859
  if (!read.ok) {
31687
31860
  throw new TranscriptUnreadableError(file, read.reason);
31688
31861
  }
@@ -31733,11 +31906,11 @@ function listSessions(cwd, dataDir) {
31733
31906
  if (name.startsWith(".")) {
31734
31907
  continue;
31735
31908
  }
31736
- const summary = readSummaryFile(path73.join(root, name, "summary.json"));
31909
+ const summary = readSummaryFile(path74.join(root, name, "summary.json"));
31737
31910
  if (summary === undefined) {
31738
31911
  continue;
31739
31912
  }
31740
- if (path73.resolve(summary.projectPath) !== path73.resolve(projectPath)) {
31913
+ if (path74.resolve(summary.projectPath) !== path74.resolve(projectPath)) {
31741
31914
  continue;
31742
31915
  }
31743
31916
  out.push(summary);
@@ -31770,15 +31943,15 @@ async function readSessionSlate(cwd, sessionId, dataDir) {
31770
31943
  }
31771
31944
  function loadContext(cwd, sessionId, dataDir) {
31772
31945
  const dir = sessionDir(resolveProjectRoot2(cwd), sessionId, dataDir);
31773
- const contextPath = path73.join(dir, "context.jsonl");
31946
+ const contextPath = path74.join(dir, "context.jsonl");
31774
31947
  if (readPendingHistory(dir) !== undefined || existsSync19(contextPath)) {
31775
31948
  return readJsonl(contextPath);
31776
31949
  }
31777
- return readJsonl(path73.join(dir, "transcript.jsonl"));
31950
+ return readJsonl(path74.join(dir, "transcript.jsonl"));
31778
31951
  }
31779
31952
  function loadArchive(cwd, sessionId, dataDir, onDegraded) {
31780
31953
  const dir = sessionDir(resolveProjectRoot2(cwd), sessionId, dataDir);
31781
- const archivePath = path73.join(dir, "archive.jsonl");
31954
+ const archivePath = path74.join(dir, "archive.jsonl");
31782
31955
  if (readPendingHistory(dir) !== undefined || existsSync19(archivePath)) {
31783
31956
  try {
31784
31957
  const archive = readJsonl(archivePath);
@@ -32872,13 +33045,13 @@ async function executeWaves(tasks, waves, deps) {
32872
33045
  init_fs();
32873
33046
  init_slate();
32874
33047
  import { mkdir as mkdir15, readFile as readFile33 } from "fs/promises";
32875
- import path74 from "path";
33048
+ import path75 from "path";
32876
33049
  var listeners = new Set;
32877
33050
  function clonePlan(plan) {
32878
33051
  return { revision: plan.revision, items: plan.items.map((item) => ({ ...item })) };
32879
33052
  }
32880
33053
  function executionPlanPath(dir) {
32881
- return path74.join(dir, "plan.json");
33054
+ return path75.join(dir, "plan.json");
32882
33055
  }
32883
33056
  async function readPlanFile(dir) {
32884
33057
  let raw;
@@ -33015,7 +33188,7 @@ init_fs();
33015
33188
  init_slate();
33016
33189
  import { createHash as createHash23, randomUUID as randomUUID11 } from "crypto";
33017
33190
  import { mkdir as mkdir21 } from "fs/promises";
33018
- import path88 from "path";
33191
+ import path89 from "path";
33019
33192
 
33020
33193
  // src/sac/trusted-wrap-up.ts
33021
33194
  import { createHash as createHash13, randomUUID as randomUUID6 } from "crypto";
@@ -33059,12 +33232,12 @@ function digest(value) {
33059
33232
  init_fs();
33060
33233
  import { createHash as createHash22, randomUUID as randomUUID9 } from "crypto";
33061
33234
  import { appendFile as appendFile4, mkdir as mkdir20, readdir as readdir21, readFile as readFile44 } from "fs/promises";
33062
- import path87 from "path";
33235
+ import path88 from "path";
33063
33236
 
33064
33237
  // src/sac/index.ts
33065
33238
  import { access as access2, readFile as readFile34, realpath as realpath10 } from "fs/promises";
33066
33239
  import { createHash as createHash14 } from "crypto";
33067
- import path75 from "path";
33240
+ import path76 from "path";
33068
33241
  import { fileURLToPath as fileURLToPath3 } from "url";
33069
33242
 
33070
33243
  // src/sac/workspace-reference.ts
@@ -33087,21 +33260,21 @@ var normativeSchemaFiles = {
33087
33260
  "review-decision": "review-decision.schema.json"
33088
33261
  };
33089
33262
  var normativeSchemas = new Map;
33090
- var NORMATIVE_SCHEMA_DIR = path75.join("docs", "requirements", "shared-agent-context", "schemas");
33263
+ var NORMATIVE_SCHEMA_DIR = path76.join("docs", "requirements", "shared-agent-context", "schemas");
33091
33264
  async function resolveSacNormativeSchemaPath(fileName, searchFrom = [fileURLToPath3(new URL(".", import.meta.url)), process.cwd()]) {
33092
33265
  const seen = new Set;
33093
33266
  for (const start of searchFrom) {
33094
- let dir = path75.resolve(start);
33267
+ let dir = path76.resolve(start);
33095
33268
  for (let i = 0;i < 10; i++) {
33096
33269
  if (seen.has(dir))
33097
33270
  break;
33098
33271
  seen.add(dir);
33099
- const candidate = path75.join(dir, NORMATIVE_SCHEMA_DIR, fileName);
33272
+ const candidate = path76.join(dir, NORMATIVE_SCHEMA_DIR, fileName);
33100
33273
  try {
33101
33274
  await access2(candidate);
33102
33275
  return candidate;
33103
33276
  } catch {}
33104
- const parent = path75.dirname(dir);
33277
+ const parent = path76.dirname(dir);
33105
33278
  if (parent === dir)
33106
33279
  break;
33107
33280
  dir = parent;
@@ -33763,12 +33936,12 @@ class SacReferenceError extends Error {
33763
33936
  code = "unsafe_workspace_reference";
33764
33937
  }
33765
33938
  async function resolveWorkspaceReference(input) {
33766
- if (!workspacePathPattern.test(input.uri) || path75.isAbsolute(input.uri) || /^[a-z][a-z0-9+.-]*:/i.test(input.uri) || input.uri.includes("\\"))
33939
+ if (!workspacePathPattern.test(input.uri) || path76.isAbsolute(input.uri) || /^[a-z][a-z0-9+.-]*:/i.test(input.uri) || input.uri.includes("\\"))
33767
33940
  throw new SacReferenceError("unsafe workspace reference");
33768
- const lexicalRoot = path75.resolve(input.workspaceRoot);
33941
+ const lexicalRoot = path76.resolve(input.workspaceRoot);
33769
33942
  const root = await realpath10(lexicalRoot);
33770
- const candidate = path75.resolve(lexicalRoot, input.uri.slice(2));
33771
- if (candidate !== lexicalRoot && !candidate.startsWith(`${lexicalRoot}${path75.sep}`))
33943
+ const candidate = path76.resolve(lexicalRoot, input.uri.slice(2));
33944
+ if (candidate !== lexicalRoot && !candidate.startsWith(`${lexicalRoot}${path76.sep}`))
33772
33945
  throw new SacReferenceError("workspace reference escapes root");
33773
33946
  let resolved;
33774
33947
  try {
@@ -33776,7 +33949,7 @@ async function resolveWorkspaceReference(input) {
33776
33949
  } catch {
33777
33950
  throw new SacReferenceError("workspace reference is not resolvable");
33778
33951
  }
33779
- if (resolved !== root && !resolved.startsWith(`${root}${path75.sep}`))
33952
+ if (resolved !== root && !resolved.startsWith(`${root}${path76.sep}`))
33780
33953
  throw new SacReferenceError("workspace reference escapes root after realpath");
33781
33954
  return candidate;
33782
33955
  }
@@ -33832,16 +34005,16 @@ async function evaluateStrictSacGuard(input) {
33832
34005
  init_fs();
33833
34006
  import { mkdir as mkdir16, readdir as readdir19, readFile as readFile35 } from "fs/promises";
33834
34007
  import { createHash as createHash15, randomUUID as randomUUID7 } from "crypto";
33835
- import path77 from "path";
34008
+ import path78 from "path";
33836
34009
 
33837
34010
  // src/sac/secure-resource-read.ts
33838
34011
  init_contained_read();
33839
34012
  init_descriptor_read();
33840
- import path76 from "path";
34013
+ import path77 from "path";
33841
34014
  function readWorkspaceFileNoFollow(workspaceRoot, absolutePath) {
33842
- const relativePath = path76.relative(workspaceRoot, absolutePath);
33843
- const components = relativePath.split(path76.sep);
33844
- if (!relativePath || path76.isAbsolute(relativePath) || components.some((component) => !component || component === "." || component === "..")) {
34015
+ const relativePath = path77.relative(workspaceRoot, absolutePath);
34016
+ const components = relativePath.split(path77.sep);
34017
+ if (!relativePath || path77.isAbsolute(relativePath) || components.some((component) => !component || component === "." || component === "..")) {
33845
34018
  throw new Error("safe source path is not workspace-relative");
33846
34019
  }
33847
34020
  return readDescriptorChain(workspaceRoot, absolutePath, {
@@ -33868,8 +34041,8 @@ class WorkspaceService {
33868
34041
  now;
33869
34042
  constructor(options) {
33870
34043
  this.options = options;
33871
- this.root = path77.resolve(options.workspaceRoot);
33872
- this.storageRoot = path77.resolve(options.storageRoot ?? path77.join(this.root, ".metaproject", "workspaces"));
34044
+ this.root = path78.resolve(options.workspaceRoot);
34045
+ this.storageRoot = path78.resolve(options.storageRoot ?? path78.join(this.root, ".metaproject", "workspaces"));
33873
34046
  this.now = options.now ?? (() => new Date);
33874
34047
  }
33875
34048
  async create(input) {
@@ -34195,13 +34368,13 @@ class WorkspaceService {
34195
34368
  return parsed;
34196
34369
  }
34197
34370
  workspaceDir(id) {
34198
- return path77.join(this.storageRoot, id);
34371
+ return path78.join(this.storageRoot, id);
34199
34372
  }
34200
34373
  manifestPath(id) {
34201
- return path77.join(this.workspaceDir(id), "workspace.json");
34374
+ return path78.join(this.workspaceDir(id), "workspace.json");
34202
34375
  }
34203
34376
  lockPath(id) {
34204
- return path77.join(this.storageRoot, `.${id}.lock`);
34377
+ return path78.join(this.storageRoot, `.${id}.lock`);
34205
34378
  }
34206
34379
  timestamp() {
34207
34380
  return this.now().toISOString();
@@ -34256,7 +34429,7 @@ function bindingHash(owner, intent) {
34256
34429
  // src/sac/session-wrap-up.ts
34257
34430
  import { createHash as createHash17 } from "crypto";
34258
34431
  import { mkdir as mkdir17, writeFile as writeFile8 } from "fs/promises";
34259
- import path78 from "path";
34432
+ import path79 from "path";
34260
34433
  init_wrap_up_evidence();
34261
34434
  var WRAP_UP_TTL_MS = 60 * 60 * 1000;
34262
34435
 
@@ -34272,7 +34445,7 @@ function sessionEvidenceRef(workspaceId, sessionId) {
34272
34445
  }
34273
34446
  async function resolveSessionWrapUp(input) {
34274
34447
  const now = input.now ?? (() => new Date);
34275
- const sessionId = path78.posix.basename(input.sourceRef, ".md");
34448
+ const sessionId = path79.posix.basename(input.sourceRef, ".md");
34276
34449
  const summary = findSession(input.cwd, sessionId);
34277
34450
  if (summary === undefined || input.sourceRef !== sessionEvidenceRef(input.workspaceId, summary.id)) {
34278
34451
  throw new SessionWrapUpError("session_not_found", `no session matching "${input.sourceRef}" in this project \u2014 use \`keryx sessions list\``);
@@ -34289,7 +34462,7 @@ async function resolveSessionWrapUp(input) {
34289
34462
  throw new SessionWrapUpError("session_unreadable", `session "${summary.id}" could not be read: ${cause.message}`);
34290
34463
  }
34291
34464
  const relPath = sessionEvidenceRef(input.workspaceId, summary.id).slice(2);
34292
- const evidenceDir = path78.dirname(relPath);
34465
+ const evidenceDir = path79.dirname(relPath);
34293
34466
  const slate = await readSessionSlate(input.cwd, summary.id);
34294
34467
  const diff = await gitDiff(input.cwd);
34295
34468
  const diffBody = diff.kind === "measured" ? diff.text : unmeasurableDiffBody(diff.detail);
@@ -34311,23 +34484,23 @@ async function resolveSessionWrapUp(input) {
34311
34484
  ""
34312
34485
  ].join(`
34313
34486
  `);
34314
- const wrapUpRelPath = path78.join(evidenceDir, `${summary.id}.wrap-up.md`);
34315
- const diffRelPath = path78.join(evidenceDir, `${summary.id}.diff.txt`);
34316
- const noticeRelPath = path78.join(evidenceDir, `${summary.id}.redaction.md`);
34487
+ const wrapUpRelPath = path79.join(evidenceDir, `${summary.id}.wrap-up.md`);
34488
+ const diffRelPath = path79.join(evidenceDir, `${summary.id}.diff.txt`);
34489
+ const noticeRelPath = path79.join(evidenceDir, `${summary.id}.redaction.md`);
34317
34490
  const floor = await applyEvidenceRedactionFloor(input.cwd, [
34318
- { name: path78.basename(relPath), content: markdown, path: relPath, source: "generated" },
34319
- { name: path78.basename(wrapUpRelPath), content: wrapUpMarkdown, path: wrapUpRelPath, source: "generated" },
34320
- { name: path78.basename(diffRelPath), content: diffBody, path: diffRelPath, source: "tool-output" }
34491
+ { name: path79.basename(relPath), content: markdown, path: relPath, source: "generated" },
34492
+ { name: path79.basename(wrapUpRelPath), content: wrapUpMarkdown, path: wrapUpRelPath, source: "generated" },
34493
+ { name: path79.basename(diffRelPath), content: diffBody, path: diffRelPath, source: "tool-output" }
34321
34494
  ]);
34322
34495
  if (!floor.ok)
34323
34496
  throw new SessionWrapUpError("security_denied", floor.reason);
34324
34497
  const [safeSession, safeWrapUp, safeDiff] = floor.bodies;
34325
- await mkdir17(path78.join(input.cwd, evidenceDir), { recursive: true });
34326
- await writeFile8(path78.join(input.cwd, relPath), safeSession.content, "utf8");
34327
- await writeFile8(path78.join(input.cwd, wrapUpRelPath), safeWrapUp.content, "utf8");
34328
- await writeFile8(path78.join(input.cwd, diffRelPath), safeDiff.content, "utf8");
34498
+ await mkdir17(path79.join(input.cwd, evidenceDir), { recursive: true });
34499
+ await writeFile8(path79.join(input.cwd, relPath), safeSession.content, "utf8");
34500
+ await writeFile8(path79.join(input.cwd, wrapUpRelPath), safeWrapUp.content, "utf8");
34501
+ await writeFile8(path79.join(input.cwd, diffRelPath), safeDiff.content, "utf8");
34329
34502
  if (floor.notice !== undefined)
34330
- await writeFile8(path78.join(input.cwd, noticeRelPath), floor.notice, "utf8");
34503
+ await writeFile8(path79.join(input.cwd, noticeRelPath), floor.notice, "utf8");
34331
34504
  const observedAt = now().toISOString();
34332
34505
  const evidence = [
34333
34506
  { kind: "wrap-up", uri: `./${wrapUpRelPath}`, revision: createHash17("sha256").update(safeWrapUp.content).digest("hex"), observedAt },
@@ -34350,13 +34523,13 @@ async function resolveSessionWrapUp(input) {
34350
34523
  init_fs();
34351
34524
  import { createHash as createHash18, randomBytes as randomBytes3 } from "crypto";
34352
34525
  import { readFile as readFile36 } from "fs/promises";
34353
- import path79 from "path";
34526
+ import path80 from "path";
34354
34527
  var CONFIRM_TOKEN_TTL_MS = 2 * 60000;
34355
34528
  function confirmTokenPath(cwd, workspaceId, proposalId) {
34356
- return path79.join(cwd, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.confirm-token.json`);
34529
+ return path80.join(cwd, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.confirm-token.json`);
34357
34530
  }
34358
34531
  function confirmReceiptPath(cwd, workspaceId, proposalId, idempotencyKey) {
34359
- return path79.join(cwd, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.${sha256(idempotencyKey)}.confirm-receipt.json`);
34532
+ return path80.join(cwd, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.${sha256(idempotencyKey)}.confirm-receipt.json`);
34360
34533
  }
34361
34534
  function sha256(text) {
34362
34535
  return createHash18("sha256").update(text).digest("hex");
@@ -34397,21 +34570,21 @@ init_store();
34397
34570
  init_config4();
34398
34571
  import { readFile as readFile38, readdir as readdir20 } from "fs/promises";
34399
34572
  import { randomUUID as randomUUID8 } from "crypto";
34400
- import path82 from "path";
34573
+ import path83 from "path";
34401
34574
 
34402
34575
  // src/sac/proposal-evidence.ts
34403
34576
  init_fs();
34404
34577
  import { createHash as createHash19 } from "crypto";
34405
34578
  import { readFile as readFile37, rm as rm6 } from "fs/promises";
34406
- import path81 from "path";
34579
+ import path82 from "path";
34407
34580
  function proposalPath(cwd, workspaceId, proposalId) {
34408
- return path81.join(cwd, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.json`);
34581
+ return path82.join(cwd, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.json`);
34409
34582
  }
34410
34583
  function ownerReceiptPath(cwd, owner, workspaceId, idempotencyKey) {
34411
- return path81.join(cwd, ".metaproject", "workspaces", workspaceId, `${owner}-write-receipts`, `${idempotencyKey}.json`);
34584
+ return path82.join(cwd, ".metaproject", "workspaces", workspaceId, `${owner}-write-receipts`, `${idempotencyKey}.json`);
34412
34585
  }
34413
34586
  function proposalNotePath(cwd, workspaceId, proposalId) {
34414
- return path81.join(cwd, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.note.txt`);
34587
+ return path82.join(cwd, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.note.txt`);
34415
34588
  }
34416
34589
  async function readVerifiedProposalEvidence(cwd, workspaceId, proposalId) {
34417
34590
  let proposal;
@@ -34425,7 +34598,7 @@ async function readVerifiedProposalEvidence(cwd, workspaceId, proposalId) {
34425
34598
  return { ok: false, code: "no_evidence_to_write" };
34426
34599
  let content;
34427
34600
  try {
34428
- content = await readFile37(path81.join(cwd, evidence.uri), "utf8");
34601
+ content = await readFile37(path82.join(cwd, evidence.uri), "utf8");
34429
34602
  } catch {
34430
34603
  return { ok: false, code: "evidence_file_unreadable" };
34431
34604
  }
@@ -34455,22 +34628,22 @@ function targetRelPath(targetRef) {
34455
34628
  return targetRef.replace(/^\.\//, "");
34456
34629
  }
34457
34630
  function targetAbsolutePath(cwd, targetRef) {
34458
- return path81.join(cwd, ".metaproject", targetRelPath(targetRef));
34631
+ return path82.join(cwd, ".metaproject", targetRelPath(targetRef));
34459
34632
  }
34460
34633
  function targetKey(targetRef) {
34461
34634
  return digestOf(targetRelPath(targetRef)).slice(0, 32);
34462
34635
  }
34463
34636
  function ownerTargetVersionPath(cwd, owner, workspaceId, targetRef) {
34464
- return path81.join(cwd, ".metaproject", "workspaces", workspaceId, `${owner}-target-versions`, `${targetKey(targetRef)}.json`);
34637
+ return path82.join(cwd, ".metaproject", "workspaces", workspaceId, `${owner}-target-versions`, `${targetKey(targetRef)}.json`);
34465
34638
  }
34466
34639
  function ownerTargetLockPath(cwd, owner, targetRef) {
34467
- return path81.join(cwd, ".metaproject", "data", "sac", "target-locks", owner, `${targetKey(targetRef)}.lock`);
34640
+ return path82.join(cwd, ".metaproject", "data", "sac", "target-locks", owner, `${targetKey(targetRef)}.lock`);
34468
34641
  }
34469
34642
  function ownerStagingDir(cwd, owner, workspaceId, idempotencyKey) {
34470
- return path81.join(cwd, ".metaproject", "workspaces", workspaceId, `${owner}-write-staging`, digestOf(idempotencyKey).slice(0, 32));
34643
+ return path82.join(cwd, ".metaproject", "workspaces", workspaceId, `${owner}-write-staging`, digestOf(idempotencyKey).slice(0, 32));
34471
34644
  }
34472
34645
  function ownerConflictDir(cwd, owner, workspaceId, idempotencyKey) {
34473
- return path81.join(cwd, ".metaproject", "workspaces", workspaceId, `${owner}-write-conflicts`, digestOf(idempotencyKey).slice(0, 32));
34646
+ return path82.join(cwd, ".metaproject", "workspaces", workspaceId, `${owner}-write-conflicts`, digestOf(idempotencyKey).slice(0, 32));
34474
34647
  }
34475
34648
  async function readJson7(file) {
34476
34649
  try {
@@ -34541,7 +34714,7 @@ async function applyGuardedTargetWrite(input) {
34541
34714
  staged: input.staged,
34542
34715
  stagedAt: receipt.completedAt
34543
34716
  };
34544
- await writeFileAtomic(path81.join(ownerStagingDir(cwd, owner, intent.workspaceId, intent.idempotencyKey), "plan.json"), `${JSON.stringify(staged, null, 2)}
34717
+ await writeFileAtomic(path82.join(ownerStagingDir(cwd, owner, intent.workspaceId, intent.idempotencyKey), "plan.json"), `${JSON.stringify(staged, null, 2)}
34545
34718
  `);
34546
34719
  const applied = await input.apply(input.staged);
34547
34720
  if (!applied.ok) {
@@ -34567,15 +34740,15 @@ async function recoverStagedOwnerWrite(input) {
34567
34740
  });
34568
34741
  }
34569
34742
  async function readStagedOwnerWrite(cwd, owner, workspaceId, idempotencyKey) {
34570
- return readJson7(path81.join(ownerStagingDir(cwd, owner, workspaceId, idempotencyKey), "plan.json"));
34743
+ return readJson7(path82.join(ownerStagingDir(cwd, owner, workspaceId, idempotencyKey), "plan.json"));
34571
34744
  }
34572
34745
  async function recordConflict(input) {
34573
34746
  const base = { targetRef: input.targetRef, expectedVersion: input.expectedVersion, currentVersion: input.currentVersion };
34574
34747
  if (input.proposedContent === undefined)
34575
34748
  return base;
34576
34749
  const dir = ownerConflictDir(input.cwd, input.owner, input.intent.workspaceId, input.intent.idempotencyKey);
34577
- await writeFileAtomic(path81.join(dir, "proposed"), input.proposedContent);
34578
- const diffRef = `./workspaces/${input.intent.workspaceId}/${input.owner}-write-conflicts/${path81.basename(dir)}/proposed`;
34750
+ await writeFileAtomic(path82.join(dir, "proposed"), input.proposedContent);
34751
+ const diffRef = `./workspaces/${input.intent.workspaceId}/${input.owner}-write-conflicts/${path82.basename(dir)}/proposed`;
34579
34752
  return { ...base, diffRef };
34580
34753
  }
34581
34754
 
@@ -34625,7 +34798,7 @@ async function resolveWorkspaceModule(cwd, workspaceId) {
34625
34798
  }
34626
34799
  }
34627
34800
  async function collectWikiDecisionEntries(cwd) {
34628
- const dir = path82.join(cwd, ".metaproject", "wiki", "decisions");
34801
+ const dir = path83.join(cwd, ".metaproject", "wiki", "decisions");
34629
34802
  let files;
34630
34803
  try {
34631
34804
  files = (await readdir20(dir)).filter((name) => name.endsWith(".md"));
@@ -34634,12 +34807,12 @@ async function collectWikiDecisionEntries(cwd) {
34634
34807
  }
34635
34808
  const entries = [];
34636
34809
  for (const file of files) {
34637
- const absolutePath = path82.join(dir, file);
34810
+ const absolutePath = path83.join(dir, file);
34638
34811
  try {
34639
34812
  const content = await readFile38(absolutePath, "utf8");
34640
34813
  entries.push({
34641
34814
  absolutePath,
34642
- relativePath: path82.posix.join("decisions", file),
34815
+ relativePath: path83.posix.join("decisions", file),
34643
34816
  type: extractHeaderField(content, "Type") ?? "decision",
34644
34817
  title: extractTitle(content),
34645
34818
  version: extractHeaderField(content, "Version") ?? null,
@@ -34861,7 +35034,7 @@ function createRealMemoryOwnerWriter(cwd, opts) {
34861
35034
  init_service4();
34862
35035
  init_guard2();
34863
35036
  import { readFile as readFile42 } from "fs/promises";
34864
- import path86 from "path";
35037
+ import path87 from "path";
34865
35038
  function renderWrapUpDecisionPage(input) {
34866
35039
  const note = input.note?.trim();
34867
35040
  return `# ${input.title}
@@ -34902,7 +35075,7 @@ export is the source of truth for what actually happened.
34902
35075
  `;
34903
35076
  }
34904
35077
  function wikiPageRelativePath(proposalId) {
34905
- return path86.posix.join("decisions", `sac-${proposalId}.md`);
35078
+ return path87.posix.join("decisions", `sac-${proposalId}.md`);
34906
35079
  }
34907
35080
  function createRealWikiOwnerWriter(cwd, opts) {
34908
35081
  const now = opts?.now ?? (() => new Date);
@@ -34910,7 +35083,7 @@ function createRealWikiOwnerWriter(cwd, opts) {
34910
35083
  const relativePath = staged.relativePath;
34911
35084
  const content = staged.content;
34912
35085
  const history = await openWikiWriteContext(cwd, "sac proposal accept");
34913
- await writeWikiPage(history, path86.join(cwd, ".metaproject", "wiki", relativePath), content);
35086
+ await writeWikiPage(history, path87.join(cwd, ".metaproject", "wiki", relativePath), content);
34914
35087
  return { ok: true };
34915
35088
  };
34916
35089
  return {
@@ -35059,7 +35232,7 @@ class ProposalLifecycleService {
35059
35232
  now;
35060
35233
  constructor(options) {
35061
35234
  this.options = options;
35062
- this.root = path87.resolve(options.workspaceRoot);
35235
+ this.root = path88.resolve(options.workspaceRoot);
35063
35236
  this.now = options.now ?? (() => new Date);
35064
35237
  }
35065
35238
  async create(input) {
@@ -35079,7 +35252,7 @@ class ProposalLifecycleService {
35079
35252
  if (manifest.status === "archived")
35080
35253
  throw new ProposalLifecycleError("guard_denied", "workspace is archived");
35081
35254
  const file = this.proposalPath(workspaceId, proposal.id);
35082
- await mkdir20(path87.dirname(file), { recursive: true, mode: 448 });
35255
+ await mkdir20(path88.dirname(file), { recursive: true, mode: 448 });
35083
35256
  return withFileLock2(`${file}.lock`, async () => {
35084
35257
  const consume = this.options.wrapUpAuthority.consume(input.wrapUp, { actor, workspaceId });
35085
35258
  if (consume !== "ok")
@@ -35107,7 +35280,7 @@ class ProposalLifecycleService {
35107
35280
  return this.options.workspaces.withAuthorizedActor({ actorContext: actor, workspaceId: input.workspaceId, action: "review", execute: async (manifest) => {
35108
35281
  const proposal = await this.loadProposal(input.workspaceId, input.proposalId);
35109
35282
  const ledger = this.ledgerPath(input.workspaceId);
35110
- await mkdir20(path87.dirname(ledger), { recursive: true, mode: 448 });
35283
+ await mkdir20(path88.dirname(ledger), { recursive: true, mode: 448 });
35111
35284
  return withFileLock2(`${ledger}.lock`, async () => {
35112
35285
  const records = (await this.records(ledger)).filter((record) => record.proposalId === proposal.id);
35113
35286
  const events = records.filter((record) => record.recordType === "proposal-transition");
@@ -35149,7 +35322,7 @@ class ProposalLifecycleService {
35149
35322
  } });
35150
35323
  }
35151
35324
  async listProposedProposals(workspaceId) {
35152
- const proposalsDir = path87.join(this.root, ".metaproject", "workspaces", workspaceId, "proposals");
35325
+ const proposalsDir = path88.join(this.root, ".metaproject", "workspaces", workspaceId, "proposals");
35153
35326
  let entries;
35154
35327
  try {
35155
35328
  entries = (await readdir21(proposalsDir)).filter((name) => name.endsWith(".json"));
@@ -35161,7 +35334,7 @@ class ProposalLifecycleService {
35161
35334
  const proposals = [];
35162
35335
  for (const entry of entries) {
35163
35336
  try {
35164
- const parsed = JSON.parse(await readFile44(path87.join(proposalsDir, entry), "utf8"));
35337
+ const parsed = JSON.parse(await readFile44(path88.join(proposalsDir, entry), "utf8"));
35165
35338
  if (parsed.recordType === "proposal-created")
35166
35339
  proposals.push(parsed);
35167
35340
  } catch {}
@@ -35427,31 +35600,31 @@ class ProposalLifecycleService {
35427
35600
  }
35428
35601
  }
35429
35602
  proposalPath(workspaceId, proposalId) {
35430
- return path87.join(this.root, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.json`);
35603
+ return path88.join(this.root, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.json`);
35431
35604
  }
35432
35605
  decisionRef(proposalId, key) {
35433
35606
  return `./proposals/${proposalId}.${hash2(key)}.decision.json`;
35434
35607
  }
35435
35608
  decisionPath(workspaceId, proposalId, key) {
35436
- return path87.join(this.root, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.${hash2(key)}.decision.json`);
35609
+ return path88.join(this.root, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.${hash2(key)}.decision.json`);
35437
35610
  }
35438
35611
  approvalRef(proposalId, key) {
35439
35612
  return `./proposals/${proposalId}.${hash2(key)}.approval.json`;
35440
35613
  }
35441
35614
  approvalPath(workspaceId, proposalId, key) {
35442
- return path87.join(this.root, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.${hash2(key)}.approval.json`);
35615
+ return path88.join(this.root, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.${hash2(key)}.approval.json`);
35443
35616
  }
35444
35617
  writeResultPath(workspaceId, proposalId, key) {
35445
- return path87.join(this.root, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.${hash2(key)}.write-result.json`);
35618
+ return path88.join(this.root, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.${hash2(key)}.write-result.json`);
35446
35619
  }
35447
35620
  intentRef(proposalId, key) {
35448
35621
  return `./proposals/${proposalId}.${hash2(key)}.write-intent.json`;
35449
35622
  }
35450
35623
  intentPath(workspaceId, proposalId, key) {
35451
- return path87.join(this.root, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.${hash2(key)}.write-intent.json`);
35624
+ return path88.join(this.root, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.${hash2(key)}.write-intent.json`);
35452
35625
  }
35453
35626
  attemptPath(workspaceId, proposalId, key) {
35454
- return path87.join(this.root, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.${hash2(key)}.owner-write-attempt.json`);
35627
+ return path88.join(this.root, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.${hash2(key)}.owner-write-attempt.json`);
35455
35628
  }
35456
35629
  async loadWriteResult(workspaceId, proposalId, key) {
35457
35630
  try {
@@ -35478,7 +35651,7 @@ class ProposalLifecycleService {
35478
35651
  }
35479
35652
  }
35480
35653
  ledgerPath(workspaceId) {
35481
- return path87.join(this.root, ".metaproject", "workspaces", workspaceId, "activity.jsonl");
35654
+ return path88.join(this.root, ".metaproject", "workspaces", workspaceId, "activity.jsonl");
35482
35655
  }
35483
35656
  timestamp() {
35484
35657
  return this.now().toISOString();
@@ -35707,11 +35880,11 @@ async function resolveMachineWrapUp(input) {
35707
35880
  `;
35708
35881
  const seedsJson = `${JSON.stringify(seedsForKind.map((seed) => ({ text: seed.text, source: describeSource(seed.source) })), null, 2)}
35709
35882
  `;
35710
- const evidenceRelBase = path88.posix.join(".metaproject", "workspaces", input.workspaceId, "machine-evidence");
35883
+ const evidenceRelBase = path89.posix.join(".metaproject", "workspaces", input.workspaceId, "machine-evidence");
35711
35884
  const floor = await applyEvidenceRedactionFloor(input.cwd, [
35712
- { name: `${input.kind}.diff.txt`, content: diffBody, path: path88.posix.join(evidenceRelBase, `${input.kind}.diff.txt`), source: "tool-output" },
35713
- { name: `${input.kind}.flow.json`, content: flowSnapshotJson, path: path88.posix.join(evidenceRelBase, `${input.kind}.flow.json`), source: "generated" },
35714
- { name: `${input.kind}.seeds.json`, content: seedsJson, path: path88.posix.join(evidenceRelBase, `${input.kind}.seeds.json`), source: "generated" }
35885
+ { name: `${input.kind}.diff.txt`, content: diffBody, path: path89.posix.join(evidenceRelBase, `${input.kind}.diff.txt`), source: "tool-output" },
35886
+ { name: `${input.kind}.flow.json`, content: flowSnapshotJson, path: path89.posix.join(evidenceRelBase, `${input.kind}.flow.json`), source: "generated" },
35887
+ { name: `${input.kind}.seeds.json`, content: seedsJson, path: path89.posix.join(evidenceRelBase, `${input.kind}.seeds.json`), source: "generated" }
35715
35888
  ]);
35716
35889
  if (!floor.ok)
35717
35890
  return { ok: false, code: "security_denied", detail: floor.reason };
@@ -35765,14 +35938,14 @@ ${safeSeeds.content}`;
35765
35938
  }
35766
35939
  summary = result.text.trim().length > 0 ? result.text.trim() : mechanicalSummary(summaryDiff, course);
35767
35940
  }
35768
- const evidenceDir = path88.join(input.cwd, ".metaproject", "workspaces", input.workspaceId, "machine-evidence");
35941
+ const evidenceDir = path89.join(input.cwd, ".metaproject", "workspaces", input.workspaceId, "machine-evidence");
35769
35942
  await mkdir21(evidenceDir, { recursive: true });
35770
35943
  const diffFile = `${input.kind}.${shortHash}.diff.txt`;
35771
35944
  const flowFile = `${input.kind}.${shortHash}.flow.json`;
35772
35945
  const seedsFile = `${input.kind}.${shortHash}.seeds.json`;
35773
- await writeFileAtomic(path88.join(evidenceDir, diffFile), safeDiff.content);
35774
- await writeFileAtomic(path88.join(evidenceDir, flowFile), safeFlow.content);
35775
- await writeFileAtomic(path88.join(evidenceDir, seedsFile), safeSeeds.content);
35946
+ await writeFileAtomic(path89.join(evidenceDir, diffFile), safeDiff.content);
35947
+ await writeFileAtomic(path89.join(evidenceDir, flowFile), safeFlow.content);
35948
+ await writeFileAtomic(path89.join(evidenceDir, seedsFile), safeSeeds.content);
35776
35949
  const observedAt = now().toISOString();
35777
35950
  const relBase = `./.metaproject/workspaces/${input.workspaceId}/machine-evidence`;
35778
35951
  const evidence = [
@@ -35782,7 +35955,7 @@ ${safeSeeds.content}`;
35782
35955
  ];
35783
35956
  if (floor.notice !== undefined) {
35784
35957
  const noticeFile = `${input.kind}.${shortHash}.redaction.md`;
35785
- await writeFileAtomic(path88.join(evidenceDir, noticeFile), floor.notice);
35958
+ await writeFileAtomic(path89.join(evidenceDir, noticeFile), floor.notice);
35786
35959
  evidence.push({ kind: REDACTION_NOTICE_KIND, uri: `${relBase}/${noticeFile}`, revision: sha2563(floor.notice), observedAt });
35787
35960
  }
35788
35961
  return {
@@ -35801,18 +35974,18 @@ async function writeFlooredArchiveArtifact(params) {
35801
35974
  {
35802
35975
  name: params.filename,
35803
35976
  content: params.content,
35804
- path: path88.posix.join("slate-archive", params.filename),
35977
+ path: path89.posix.join("slate-archive", params.filename),
35805
35978
  source: "generated"
35806
35979
  }
35807
35980
  ]);
35808
35981
  if (!floor.ok)
35809
35982
  return { ok: false, code: "security_denied", detail: floor.reason };
35810
35983
  const body = floor.bodies[0];
35811
- const archiveDir = path88.join(params.dir, "slate-archive");
35984
+ const archiveDir = path89.join(params.dir, "slate-archive");
35812
35985
  await mkdir21(archiveDir, { recursive: true });
35813
- await writeFileAtomic(path88.join(archiveDir, params.filename), body.content);
35986
+ await writeFileAtomic(path89.join(archiveDir, params.filename), body.content);
35814
35987
  if (floor.notice !== undefined) {
35815
- await writeFileAtomic(path88.join(archiveDir, `${params.filename}${ARCHIVE_REDACTION_NOTICE_SUFFIX}`), floor.notice);
35988
+ await writeFileAtomic(path89.join(archiveDir, `${params.filename}${ARCHIVE_REDACTION_NOTICE_SUFFIX}`), floor.notice);
35816
35989
  }
35817
35990
  return { ok: true, altered: body.altered };
35818
35991
  }
@@ -35848,9 +36021,9 @@ async function writeWrapUpOutcomeArtifact(cwd, dir, trigger, now, groups) {
35848
36021
  return;
35849
36022
  const refusalIso = now().toISOString();
35850
36023
  const refusalFilename = `${refusalIso.replace(/[:.]/g, "-")}-wrap-up-outcome.json`;
35851
- const archiveDir = path88.join(dir, "slate-archive");
36024
+ const archiveDir = path89.join(dir, "slate-archive");
35852
36025
  await mkdir21(archiveDir, { recursive: true });
35853
- await writeFileAtomic(path88.join(archiveDir, refusalFilename), `${JSON.stringify({
36026
+ await writeFileAtomic(path89.join(archiveDir, refusalFilename), `${JSON.stringify({
35854
36027
  recordType: "wrap-up-outcome",
35855
36028
  trigger,
35856
36029
  generatedAt: refusalIso,
@@ -36185,7 +36358,7 @@ init_fs();
36185
36358
  init_repomap();
36186
36359
  init_redact();
36187
36360
  init_slate();
36188
- import path89 from "path";
36361
+ import path90 from "path";
36189
36362
  var DEFAULT_TERMINAL_STATE_MAX_TOKENS = 2000;
36190
36363
  function boundedRedactedAnchorsSnapshot(anchors, maxTokens) {
36191
36364
  const fence = anchors.fence?.map((entry) => redactSensitiveText(entry));
@@ -36220,7 +36393,7 @@ function renderTerminalStateBlock(state, opts) {
36220
36393
  `);
36221
36394
  }
36222
36395
  async function writeTerminalState(dir, state) {
36223
- await writeFileAtomic(path89.join(dir, "terminal-state.json"), `${JSON.stringify(state, null, 2)}
36396
+ await writeFileAtomic(path90.join(dir, "terminal-state.json"), `${JSON.stringify(state, null, 2)}
36224
36397
  `);
36225
36398
  }
36226
36399