@akagilnc/pi-workflow-roles 0.1.5368 → 0.1.5375

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 (165) hide show
  1. package/dist/acp-host/production-host.js +719 -776
  2. package/dist/activation-ledger-git.js +2 -2
  3. package/dist/activation-ledger-topology.js +1 -7
  4. package/dist/analyst-entry.js +4 -8
  5. package/dist/analyst-gate-cycles-read.js +3 -11
  6. package/dist/analyst-index.js +3 -9
  7. package/dist/analyst-ledger.js +1 -11
  8. package/dist/analyst-metric-families/acceptance-success-rework.js +1 -3
  9. package/dist/analyst-metric-families/round-timeline.js +1 -3
  10. package/dist/analyst-page.js +2 -2
  11. package/dist/archivist-record-topology.js +2 -2
  12. package/dist/audit-escalation.js +2 -1
  13. package/dist/auditor-soul.js +2 -1
  14. package/dist/collector-config.js +6 -8
  15. package/dist/compliance-transport.js +2 -1
  16. package/dist/countersign-contracts.js +2 -1
  17. package/dist/diarist-contracts.js +3 -2
  18. package/dist/doctor-contracts.js +1 -3
  19. package/dist/doctor-evidence.js +7 -8
  20. package/dist/dossier-resolution.js +1 -3
  21. package/dist/engine-detour-usage.js +1 -3
  22. package/dist/gatekeeper-role.js +2 -9
  23. package/dist/gleaner-left-contracts.js +2 -1
  24. package/dist/headless-host/description.js +14 -17
  25. package/dist/headless-host/production-host.js +721 -780
  26. package/dist/host-session-record.js +3 -2
  27. package/dist/inspector-contracts.js +2 -1
  28. package/dist/ledger-session-read.js +1 -3
  29. package/dist/merger-contracts.js +9 -9
  30. package/dist/migrate-book-topology.js +348 -314
  31. package/dist/navigator-attendance.js +9 -11
  32. package/dist/navigator-invocation-identity.js +3 -2
  33. package/dist/navigator-public-session.js +3 -5
  34. package/dist/navigator-session-contracts.js +8 -10
  35. package/dist/navigator-work-base.js +5 -8
  36. package/dist/notary-contracts.js +3 -5
  37. package/dist/package-contracts/auditor-output.js +1 -3
  38. package/dist/package-contracts/fixer-packet.js +3 -6
  39. package/dist/package-contracts/gatekeeper-output.js +1 -3
  40. package/dist/package-contracts/navigator-output.js +8 -8
  41. package/dist/package-contracts/terminating-infrastructure.js +5 -9
  42. package/dist/package-contracts/terminating-tools.js +4 -3
  43. package/dist/public-cli/analyst-run.js +3 -2
  44. package/dist/public-cli/auto-resume.js +3 -8
  45. package/dist/public-cli/cli.js +9 -8
  46. package/dist/public-cli/config.js +8 -11
  47. package/dist/public-cli/countersign-run.js +1 -3
  48. package/dist/public-cli/host-providers.js +7 -14
  49. package/dist/public-cli/instruction-seat-run.js +4 -3
  50. package/dist/public-cli/invocation.js +9 -8
  51. package/dist/public-cli/main.js +1531 -1567
  52. package/dist/public-cli/post-admission.js +4 -3
  53. package/dist/public-cli/run-lifecycle.js +14 -26
  54. package/dist/public-cli/settlement.js +10 -26
  55. package/dist/public-role-summons.js +3 -2
  56. package/dist/receipt-delivery-policy.js +1 -3
  57. package/dist/role-run-placement.js +3 -5
  58. package/dist/role-run-relocation.js +12 -19
  59. package/dist/run-terminal-artifacts.js +1 -11
  60. package/dist/run-ticket-number.js +2 -4
  61. package/dist/session-assistant-usage.js +2 -1
  62. package/dist/session-dialogue.js +1 -14
  63. package/dist/sitian-reader.js +2 -4
  64. package/dist/submission-correctable-error.js +2 -1
  65. package/dist/submission-errors.js +2 -1
  66. package/dist/submission-gate.js +2 -1
  67. package/dist/submission-ledger.js +4 -5
  68. package/dist/ticket-provenance-contracts.js +1 -3
  69. package/dist/ticket-provenance.js +2 -1
  70. package/dist/typed-provider-http.js +4 -7
  71. package/dist/unknown-value.js +28 -0
  72. package/dist/user-dialogue-stdin.js +2 -1
  73. package/package.json +1 -1
  74. package/src/acp-host/role-turn-host.ts +4 -2
  75. package/src/activation-ledger-git.ts +3 -2
  76. package/src/activation-ledger-topology.ts +4 -12
  77. package/src/analyst-entry.ts +3 -11
  78. package/src/analyst-gate-cycles-read.ts +3 -15
  79. package/src/analyst-index.ts +3 -13
  80. package/src/analyst-ledger.ts +2 -16
  81. package/src/analyst-metric-families/acceptance-success-rework.ts +2 -4
  82. package/src/analyst-metric-families/round-timeline.ts +2 -4
  83. package/src/analyst-page.ts +2 -2
  84. package/src/archivist-record-topology.ts +2 -2
  85. package/src/audit-escalation.ts +2 -1
  86. package/src/auditor-soul.ts +3 -1
  87. package/src/book-topology-migration-placement.ts +5 -16
  88. package/src/book-topology-migrators-t11.ts +16 -15
  89. package/src/book-topology-mixed-volume-migrators.ts +3 -6
  90. package/src/book-topology-record-class-migrators.ts +7 -10
  91. package/src/book-topology-runs-migrator.ts +4 -3
  92. package/src/collector-config.ts +7 -9
  93. package/src/compliance-transport.ts +2 -1
  94. package/src/countersign-contracts.ts +2 -1
  95. package/src/diarist-contracts.ts +3 -2
  96. package/src/doctor-contracts.ts +3 -1
  97. package/src/doctor-evidence.ts +8 -7
  98. package/src/doctor-role.ts +4 -2
  99. package/src/dossier-resolution.ts +2 -4
  100. package/src/engine-detour-tool.ts +0 -2
  101. package/src/engine-detour-usage.ts +2 -4
  102. package/src/external-host-turn-loop.ts +3 -1
  103. package/src/factory-board.ts +1 -8
  104. package/src/gatekeeper-role.ts +2 -10
  105. package/src/gleaner-left-contracts.ts +3 -1
  106. package/src/headless-host/description.ts +15 -18
  107. package/src/headless-host/role-turn-host.ts +10 -9
  108. package/src/host-session-record.ts +4 -2
  109. package/src/inspector-contracts.ts +2 -1
  110. package/src/ledger-session-read.ts +2 -5
  111. package/src/merger-contracts.ts +10 -9
  112. package/src/navigator-attendance.ts +10 -12
  113. package/src/navigator-invocation-identity.ts +3 -2
  114. package/src/navigator-public-session.ts +4 -6
  115. package/src/navigator-session-contracts.ts +8 -11
  116. package/src/navigator-work-base.ts +5 -8
  117. package/src/navigator-work-context.ts +2 -1
  118. package/src/notary-contracts.ts +4 -6
  119. package/src/oauth-keepalive.ts +5 -18
  120. package/src/package-contracts/auditor-output.ts +2 -4
  121. package/src/package-contracts/fixer-packet.ts +4 -6
  122. package/src/package-contracts/gatekeeper-output.ts +2 -4
  123. package/src/package-contracts/judge-output.ts +0 -1
  124. package/src/package-contracts/navigator-output.ts +8 -8
  125. package/src/package-contracts/terminating-infrastructure.ts +6 -20
  126. package/src/package-contracts/terminating-tools.ts +8 -12
  127. package/src/pi/adapter.ts +0 -1
  128. package/src/pi/role-turn-host.ts +0 -1
  129. package/src/public-cli/analyst-run.ts +4 -2
  130. package/src/public-cli/auto-resume.ts +4 -11
  131. package/src/public-cli/cli.ts +10 -10
  132. package/src/public-cli/config.ts +8 -27
  133. package/src/public-cli/countersign-run.ts +2 -4
  134. package/src/public-cli/host-providers.ts +10 -27
  135. package/src/public-cli/instruction-seat-run.ts +5 -3
  136. package/src/public-cli/invocation.ts +11 -10
  137. package/src/public-cli/post-admission.ts +5 -3
  138. package/src/public-cli/run-lifecycle.ts +20 -41
  139. package/src/public-cli/settlement.ts +11 -33
  140. package/src/public-role-summons.ts +4 -3
  141. package/src/receipt-delivery-policy.ts +1 -4
  142. package/src/reviewer-role.ts +0 -1
  143. package/src/role-envelope.ts +5 -3
  144. package/src/role-run-placement.ts +4 -10
  145. package/src/role-run-relocation.ts +13 -23
  146. package/src/role-runtime.ts +9 -15
  147. package/src/run-terminal-artifacts.ts +2 -16
  148. package/src/run-ticket-number.ts +4 -10
  149. package/src/session-assistant-usage.ts +3 -1
  150. package/src/session-dialogue.ts +1 -4
  151. package/src/session-identity.ts +0 -1
  152. package/src/sitian-reader.ts +2 -4
  153. package/src/submission-correctable-error.ts +3 -1
  154. package/src/submission-errors.ts +2 -1
  155. package/src/submission-gate.ts +3 -1
  156. package/src/submission-ledger.ts +5 -6
  157. package/src/ticket-provenance-contracts.ts +1 -4
  158. package/src/ticket-provenance.ts +3 -1
  159. package/src/ticket-snapshot.ts +2 -4
  160. package/src/ticket-trajectory.ts +1 -8
  161. package/src/typed-provider-http.ts +5 -15
  162. package/src/unknown-value.ts +34 -0
  163. package/src/user-dialogue-stdin.ts +3 -1
  164. package/src/worker-role.ts +2 -5
  165. package/src/worker-submission-gates.ts +5 -7
@@ -136,6 +136,30 @@ var init_collector_output = __esm({
136
136
  }
137
137
  });
138
138
 
139
+ // src/unknown-value.ts
140
+ import { Guard } from "typebox/guard";
141
+ function isRecord(value) {
142
+ return Guard.IsObjectNotArray(value);
143
+ }
144
+ function errnoCode(error) {
145
+ return error !== null && typeof error === "object" && "code" in error && typeof error.code === "string" ? error.code : void 0;
146
+ }
147
+ function errorText(error) {
148
+ return error instanceof Error ? error.message : String(error);
149
+ }
150
+ function isEnoent(error) {
151
+ return error instanceof Error && errnoCode(error) === "ENOENT";
152
+ }
153
+ function isMissingPathError(error) {
154
+ const code = errnoCode(error);
155
+ return error instanceof Error && (code === "ENOENT" || code === "ENOTDIR");
156
+ }
157
+ var init_unknown_value = __esm({
158
+ "src/unknown-value.ts"() {
159
+ "use strict";
160
+ }
161
+ });
162
+
139
163
  // src/package-contracts/terminating-infrastructure.ts
140
164
  import { Type } from "typebox";
141
165
  function withTerminatingOutputDeclarations(schema) {
@@ -156,15 +180,10 @@ function withTerminatingOutputDeclarations(schema) {
156
180
  return object;
157
181
  }
158
182
  function isInfrastructureFailureDeclaration(parameters) {
159
- if (parameters === null || typeof parameters !== "object" || Array.isArray(parameters)) {
160
- return false;
161
- }
162
- const record4 = parameters;
163
- if (!Object.hasOwn(record4, INFRASTRUCTURE_FAILURE_DECLARATION_KEY)) return false;
164
- const declaration = record4[INFRASTRUCTURE_FAILURE_DECLARATION_KEY];
165
- if (declaration === null || typeof declaration !== "object" || Array.isArray(declaration)) {
166
- return false;
167
- }
183
+ if (!isRecord(parameters)) return false;
184
+ if (!Object.hasOwn(parameters, INFRASTRUCTURE_FAILURE_DECLARATION_KEY)) return false;
185
+ const declaration = parameters[INFRASTRUCTURE_FAILURE_DECLARATION_KEY];
186
+ if (!isRecord(declaration)) return false;
168
187
  const diagnostic = declaration[INFRASTRUCTURE_FAILURE_DIAGNOSTIC_KEY];
169
188
  return typeof diagnostic === "string" && diagnostic.trim().length > 0;
170
189
  }
@@ -196,6 +215,7 @@ var INFRASTRUCTURE_FAILURE_DECLARATION_KEY, INFRASTRUCTURE_FAILURE_DIAGNOSTIC_KE
196
215
  var init_terminating_infrastructure = __esm({
197
216
  "src/package-contracts/terminating-infrastructure.ts"() {
198
217
  "use strict";
218
+ init_unknown_value();
199
219
  INFRASTRUCTURE_FAILURE_DECLARATION_KEY = "infrastructureFailure";
200
220
  INFRASTRUCTURE_FAILURE_DIAGNOSTIC_KEY = "diagnostic";
201
221
  infrastructureFailureNested = Type.Object(
@@ -305,6 +325,7 @@ var init_gatekeeper_output = __esm({
305
325
  "use strict";
306
326
  init_open_tool_schema();
307
327
  init_terminating_infrastructure();
328
+ init_unknown_value();
308
329
  GATEKEEPER_OUTPUT_TOOL_NAME = "ak_gatekeeper_output";
309
330
  gatekeeperDecisionSchema = openToolObject(
310
331
  Type4.Object({
@@ -338,18 +359,17 @@ import { Type as Type5 } from "typebox";
338
359
  function projectLawfulNavigatorOutput(value) {
339
360
  if (value === void 0 || value === null) return void 0;
340
361
  if (typeof value === "string") return { prose: value };
341
- if (typeof value === "object" && !Array.isArray(value)) {
342
- const record4 = value;
343
- if (typeof record4.prose === "string") return { prose: record4.prose };
344
- if (record4.prose !== void 0 && record4.prose !== null) {
345
- return { prose: typeof record4.prose === "string" ? record4.prose : String(record4.prose) };
362
+ if (isRecord(value)) {
363
+ if (typeof value.prose === "string") return { prose: value.prose };
364
+ if (value.prose !== void 0 && value.prose !== null) {
365
+ return { prose: typeof value.prose === "string" ? value.prose : String(value.prose) };
346
366
  }
347
- const keys = Object.keys(record4);
367
+ const keys = Object.keys(value);
348
368
  if (keys.length === 0) return { prose: "" };
349
369
  try {
350
- return { prose: JSON.stringify(record4) };
370
+ return { prose: JSON.stringify(value) };
351
371
  } catch {
352
- return { prose: String(record4) };
372
+ return { prose: String(value) };
353
373
  }
354
374
  }
355
375
  return { prose: String(value) };
@@ -371,6 +391,7 @@ var NAVIGATOR_OUTPUT_TOOL_NAME, navigatorOutputSchema;
371
391
  var init_navigator_output = __esm({
372
392
  "src/package-contracts/navigator-output.ts"() {
373
393
  "use strict";
394
+ init_unknown_value();
374
395
  init_open_tool_schema();
375
396
  init_terminating_infrastructure();
376
397
  NAVIGATOR_OUTPUT_TOOL_NAME = "ak_navigator_output";
@@ -443,13 +464,9 @@ function fail(cause) {
443
464
  function parseFailure(value) {
444
465
  if (!Array.isArray(value)) fail(new Error("Fixer prerequisites must be a JSON array"));
445
466
  for (const entry of value) {
446
- if (typeof entry !== "object" || entry === null || Array.isArray(entry)) {
467
+ if (!isRecord(entry)) {
447
468
  fail(new Error("Fixer prerequisite entry must be an object with id and requirement fields"));
448
469
  }
449
- const keys = Object.keys(entry);
450
- if (keys.length !== 2 || !keys.includes("id") || !keys.includes("requirement")) {
451
- fail(new Error("Fixer prerequisite entry fields must be exactly id and requirement"));
452
- }
453
470
  if (typeof entry.id !== "string" || !new RegExp(FIXER_PREREQUISITE_ID_PATTERN).test(entry.id)) {
454
471
  fail(new Error(`Fixer prerequisite id violates pattern ${FIXER_PREREQUISITE_ID_PATTERN}`));
455
472
  }
@@ -485,11 +502,12 @@ var FIXER_PREREQUISITE_ID_PATTERN, fixerPrerequisiteSchema, fixerPrerequisitesSc
485
502
  var init_fixer_packet = __esm({
486
503
  "src/package-contracts/fixer-packet.ts"() {
487
504
  "use strict";
505
+ init_unknown_value();
488
506
  FIXER_PREREQUISITE_ID_PATTERN = "^[A-Za-z0-9][A-Za-z0-9._-]*$";
489
507
  fixerPrerequisiteSchema = Type7.Object({
490
508
  id: Type7.String({ pattern: FIXER_PREREQUISITE_ID_PATTERN }),
491
509
  requirement: Type7.String({ pattern: "\\S" })
492
- }, { additionalProperties: false });
510
+ });
493
511
  fixerPrerequisitesSchema = Type7.Array(fixerPrerequisiteSchema);
494
512
  FixerPacketValidationError = class extends Error {
495
513
  code = "AK_INVALID_FIX_PACKET";
@@ -545,6 +563,7 @@ var init_doctor_contracts = __esm({
545
563
  init_canonical_json();
546
564
  init_open_tool_schema();
547
565
  init_terminating_infrastructure();
566
+ init_unknown_value();
548
567
  DOCTOR_EVIDENCE_TOOL_NAME = "ak_doctor_evidence";
549
568
  DOCTOR_OUTPUT_TOOL_NAME = "ak_doctor_output";
550
569
  DOCTOR_AUDIT_TOOL_NAME = "ak_doctor_audit_decision";
@@ -655,35 +674,36 @@ function deepFreeze(value) {
655
674
  return value;
656
675
  }
657
676
  function readMaterial(value, label) {
658
- if (!record(value) || typeof value.bytesBase64 !== "string") fail2(`Merger ${label} material is malformed`);
677
+ if (!isRecord(value) || typeof value.bytesBase64 !== "string") fail2(`Merger ${label} material is malformed`);
659
678
  exactUtf8(Buffer.from(value.bytesBase64, "base64"), `Merger ${label} material`);
660
679
  return { bytesBase64: value.bytesBase64, sha256: typeof value.sha256 === "string" ? value.sha256 : "" };
661
680
  }
662
681
  function validateMergerInput(value) {
663
- if (!record(value) || blank(value.attemptId)) fail2("Merger input requires a non-empty attemptId for accounting");
664
- if (!record(value.materials)) fail2("Merger materials are missing");
682
+ if (!isRecord(value) || blank(value.attemptId)) fail2("Merger input requires a non-empty attemptId for accounting");
683
+ if (!isRecord(value.materials)) fail2("Merger materials are missing");
665
684
  const materials = { task: readMaterial(value.materials.task, "task"), authority: readMaterial(value.materials.authority, "authority"), targetIntent: readMaterial(value.materials.targetIntent, "targetIntent"), sourceIntent: readMaterial(value.materials.sourceIntent, "sourceIntent") };
666
- const authorizedChecks = Array.isArray(value.authorizedChecks) ? value.authorizedChecks.filter((check) => record(check)).map((c) => ({ name: asString(c.name), argv: asStringArray(c.argv).filter((a) => a.trim().length > 0) })).filter((c) => c.name.trim().length > 0 && c.argv.length > 0) : [];
685
+ const authorizedChecks = Array.isArray(value.authorizedChecks) ? value.authorizedChecks.filter((check) => isRecord(check)).map((c) => ({ name: asString(c.name), argv: asStringArray(c.argv).filter((a) => a.trim().length > 0) })).filter((c) => c.name.trim().length > 0 && c.argv.length > 0) : [];
667
686
  return deepFreeze(structuredClone({ attemptId: value.attemptId.trim(), targetObjectId: asString(value.targetObjectId), sourceObjectId: asString(value.sourceObjectId), materials, expectedConflictPaths: asStringArray(value.expectedConflictPaths), resolutionScope: asStringArray(value.resolutionScope), authorizedChecks }));
668
687
  }
669
- var materialSchema, checkSchema, mergerInputSchema, MERGER_STATUS_DESCRIPTION, mergerOutputObject, mergerOutputSchema, MERGER_OUTPUT_TOOL_NAME, record, blank, MergerInputContractError, asString, asStringArray;
688
+ var materialSchema, checkSchema, mergerInputSchema, MERGER_STATUS_DESCRIPTION, mergerOutputObject, mergerOutputSchema, MERGER_OUTPUT_TOOL_NAME, blank, MergerInputContractError, asString, asStringArray;
670
689
  var init_merger_contracts = __esm({
671
690
  "src/merger-contracts.ts"() {
672
691
  "use strict";
673
692
  init_exact_utf8();
674
693
  init_open_tool_schema();
675
694
  init_terminating_infrastructure();
676
- materialSchema = Type9.Object({ bytesBase64: Type9.String(), sha256: Type9.String() }, { additionalProperties: false });
677
- checkSchema = Type9.Object({ name: Type9.String({ minLength: 1 }), argv: Type9.Array(Type9.String({ minLength: 1 }), { minItems: 1 }) }, { additionalProperties: false });
695
+ init_unknown_value();
696
+ materialSchema = Type9.Object({ bytesBase64: Type9.String(), sha256: Type9.String() });
697
+ checkSchema = Type9.Object({ name: Type9.String({ minLength: 1 }), argv: Type9.Array(Type9.String({ minLength: 1 }), { minItems: 1 }) });
678
698
  mergerInputSchema = Type9.Object({
679
699
  attemptId: Type9.String({ minLength: 1, description: "\u5BF9\u8D26 attempt \u8EAB\u4EFD\uFF08transport\uFF09" }),
680
700
  targetObjectId: Type9.String({ description: "\u6750\u6599\uFF1Atarget parent OID\uFF1B\u53EF\u7A7A" }),
681
701
  sourceObjectId: Type9.String({ description: "\u6750\u6599\uFF1Asource parent OID\uFF1B\u53EF\u7A7A" }),
682
- materials: Type9.Object({ task: materialSchema, authority: materialSchema, targetIntent: materialSchema, sourceIntent: materialSchema }, { additionalProperties: false }),
702
+ materials: Type9.Object({ task: materialSchema, authority: materialSchema, targetIntent: materialSchema, sourceIntent: materialSchema }),
683
703
  expectedConflictPaths: Type9.Array(Type9.String(), { description: "\u6750\u6599\uFF1A\u5F53\u524D\u672A\u5408\u5E76\u8DEF\u5F84\uFF1B\u53EF\u7A7A" }),
684
704
  resolutionScope: Type9.Array(Type9.String(), { description: "\u6750\u6599\uFF1A\u89E3\u6790\u8303\u56F4\u63D0\u793A\uFF1B\u53EF\u7A7A" }),
685
705
  authorizedChecks: Type9.Array(checkSchema)
686
- }, { additionalProperties: false });
706
+ });
687
707
  MERGER_STATUS_DESCRIPTION = "completed | escalate";
688
708
  mergerOutputObject = Type9.Object({
689
709
  status: Type9.Unknown({ description: MERGER_STATUS_DESCRIPTION }),
@@ -696,7 +716,6 @@ var init_merger_contracts = __esm({
696
716
  });
697
717
  mergerOutputSchema = withTerminatingOutputDeclarations(openToolObject(mergerOutputObject));
698
718
  MERGER_OUTPUT_TOOL_NAME = "ak_merger_output";
699
- record = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
700
719
  blank = (v) => typeof v !== "string" || v.trim().length === 0;
701
720
  MergerInputContractError = class extends Error {
702
721
  constructor(message = "Merger input violates its exact contract") {
@@ -715,6 +734,7 @@ var init_notary_contracts = __esm({
715
734
  "src/notary-contracts.ts"() {
716
735
  "use strict";
717
736
  init_review_submission();
737
+ init_unknown_value();
718
738
  NOTARY_OUTPUT_TOOL_NAME = REVIEW_SUBMISSION_OUTPUT_TOOL_NAME;
719
739
  NOTARY_SOURCE_RUN_FLAG = {
720
740
  name: "ak-notary-source-run",
@@ -740,6 +760,7 @@ var init_countersign_contracts = __esm({
740
760
  "src/countersign-contracts.ts"() {
741
761
  "use strict";
742
762
  init_review_submission();
763
+ init_unknown_value();
743
764
  COUNTERSIGN_OUTPUT_TOOL_NAME = REVIEW_SUBMISSION_OUTPUT_TOOL_NAME;
744
765
  }
745
766
  });
@@ -749,6 +770,7 @@ var GLEANER_LEFT_OUTPUT_TOOL_NAME, GLEANER_LEFT_BASE_FLAG;
749
770
  var init_gleaner_left_contracts = __esm({
750
771
  "src/gleaner-left-contracts.ts"() {
751
772
  "use strict";
773
+ init_unknown_value();
752
774
  GLEANER_LEFT_OUTPUT_TOOL_NAME = "ak_gleaner_left_output";
753
775
  GLEANER_LEFT_BASE_FLAG = {
754
776
  name: "ak-gleaner-left-base",
@@ -766,6 +788,7 @@ var init_inspector_contracts = __esm({
766
788
  "src/inspector-contracts.ts"() {
767
789
  "use strict";
768
790
  init_review_submission();
791
+ init_unknown_value();
769
792
  INSPECTOR_OUTPUT_TOOL_NAME = REVIEW_SUBMISSION_OUTPUT_TOOL_NAME;
770
793
  INSPECTOR_SOURCE_RUN_FLAG = {
771
794
  name: "ak-inspector-source-run",
@@ -783,15 +806,13 @@ var init_auditor_output = __esm({
783
806
  "src/package-contracts/auditor-output.ts"() {
784
807
  "use strict";
785
808
  init_review_submission();
809
+ init_unknown_value();
786
810
  AUDITOR_OUTPUT_TOOL_NAME = REVIEW_SUBMISSION_OUTPUT_TOOL_NAME;
787
811
  auditorOutputSchema = reviewSubmissionSchema;
788
812
  }
789
813
  });
790
814
 
791
815
  // src/ticket-provenance-contracts.ts
792
- function isRecord(value) {
793
- return typeof value === "object" && value !== null && !Array.isArray(value);
794
- }
795
816
  function positiveInteger(value) {
796
817
  if (typeof value === "number" && Number.isSafeInteger(value) && value >= 1) return value;
797
818
  if (typeof value === "string" && /^[1-9][0-9]*$/.test(value)) {
@@ -832,6 +853,7 @@ var TICKET_PROVENANCE_KIND;
832
853
  var init_ticket_provenance_contracts = __esm({
833
854
  "src/ticket-provenance-contracts.ts"() {
834
855
  "use strict";
856
+ init_unknown_value();
835
857
  TICKET_PROVENANCE_KIND = "ticket-provenance";
836
858
  }
837
859
  });
@@ -849,9 +871,6 @@ __export(run_ticket_number_exports, {
849
871
  });
850
872
  import { readFile } from "node:fs/promises";
851
873
  import { join as join2 } from "node:path";
852
- function isEnoent(error) {
853
- return error instanceof Error && "code" in error && error.code === "ENOENT";
854
- }
855
874
  function isSafePositiveTicketNumber(value) {
856
875
  return typeof value === "number" && Number.isSafeInteger(value) && value >= 1;
857
876
  }
@@ -872,13 +891,13 @@ function requireSafePositiveTicketNumber(ticketNumber, context = "ticketNumber")
872
891
  }
873
892
  return ticketNumber;
874
893
  }
875
- function ticketFromRecord(record4) {
876
- return isSafePositiveTicketNumber(record4.ticketNumber) ? record4.ticketNumber : void 0;
894
+ function ticketFromRecord(record) {
895
+ return isSafePositiveTicketNumber(record.ticketNumber) ? record.ticketNumber : void 0;
877
896
  }
878
897
  async function readJsonObject(path) {
879
898
  try {
880
899
  const raw = JSON.parse(await readFile(path, "utf8"));
881
- if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
900
+ if (!isRecord(raw)) {
882
901
  return void 0;
883
902
  }
884
903
  return raw;
@@ -888,20 +907,20 @@ async function readJsonObject(path) {
888
907
  }
889
908
  }
890
909
  async function readBoardPageTicketNumber(runDirectory, page) {
891
- const record4 = await readJsonObject(join2(runDirectory, page));
892
- if (record4 === void 0) return void 0;
893
- return ticketFromRecord(record4);
910
+ const record = await readJsonObject(join2(runDirectory, page));
911
+ if (record === void 0) return void 0;
912
+ return ticketFromRecord(record);
894
913
  }
895
914
  async function readBoardTicketNumber(runDirectory) {
896
915
  return await readBoardPageTicketNumber(runDirectory, "admitted-request.json") ?? await readBoardPageTicketNumber(runDirectory, "invocation.json");
897
916
  }
898
917
  async function readMigrationDerivedTicketNumber(runDirectory) {
899
- const record4 = await readJsonObject(
918
+ const record = await readJsonObject(
900
919
  join2(runDirectory, MIGRATION_TICKET_DERIVATION_PAGE)
901
920
  );
902
- if (record4 === void 0) return void 0;
903
- if (record4.derivation !== "worktree-path-basename") return void 0;
904
- return ticketFromRecord(record4);
921
+ if (record === void 0) return void 0;
922
+ if (record.derivation !== "worktree-path-basename") return void 0;
923
+ return ticketFromRecord(record);
905
924
  }
906
925
  async function readRunTicketNumber(runDirectory) {
907
926
  return await readBoardTicketNumber(runDirectory) ?? await readMigrationDerivedTicketNumber(runDirectory);
@@ -910,6 +929,7 @@ var MIGRATION_TICKET_DERIVATION_PAGE;
910
929
  var init_run_ticket_number = __esm({
911
930
  "src/run-ticket-number.ts"() {
912
931
  "use strict";
932
+ init_unknown_value();
913
933
  MIGRATION_TICKET_DERIVATION_PAGE = "migration-ticket-derivation.json";
914
934
  }
915
935
  });
@@ -925,7 +945,7 @@ function projectDiaristTicketSessions(value) {
925
945
  if (!Array.isArray(raw)) return void 0;
926
946
  const perTicket = /* @__PURE__ */ new Map();
927
947
  for (const entry of raw) {
928
- if (entry === null || typeof entry !== "object" || Array.isArray(entry)) return void 0;
948
+ if (!isRecord(entry)) return void 0;
929
949
  const { ticketNumber, sessions: rawSessions } = entry;
930
950
  if (!isSafePositiveTicketNumber(ticketNumber)) return void 0;
931
951
  const sessions = projectTicketProvenanceSessions(rawSessions);
@@ -940,6 +960,7 @@ var init_diarist_contracts = __esm({
940
960
  "use strict";
941
961
  init_ticket_provenance_contracts();
942
962
  init_run_ticket_number();
963
+ init_unknown_value();
943
964
  DIARIST_OUTPUT_TOOL_NAME = "ak_diarist_output";
944
965
  }
945
966
  });
@@ -1012,40 +1033,40 @@ function packagedRoleMetadata(role) {
1012
1033
  }
1013
1034
  function packagedMethodSkillNames() {
1014
1035
  const names = [];
1015
- for (const record4 of PACKAGED_ROLE_REGISTRY) {
1016
- if ("methodSkills" in record4 && record4.methodSkills !== void 0) {
1017
- for (const name of record4.methodSkills) if (!names.includes(name)) names.push(name);
1036
+ for (const record of PACKAGED_ROLE_REGISTRY) {
1037
+ if ("methodSkills" in record && record.methodSkills !== void 0) {
1038
+ for (const name of record.methodSkills) if (!names.includes(name)) names.push(name);
1018
1039
  }
1019
- if ("applyMethod" in record4 && record4.applyMethod !== void 0 && !names.includes(record4.applyMethod)) {
1020
- names.push(record4.applyMethod);
1040
+ if ("applyMethod" in record && record.applyMethod !== void 0 && !names.includes(record.applyMethod)) {
1041
+ names.push(record.applyMethod);
1021
1042
  }
1022
1043
  }
1023
1044
  return names;
1024
1045
  }
1025
1046
  function isOfficerReviewSeat(role) {
1026
- const record4 = packagedRoleMetadata(role);
1027
- return record4 !== void 0 && "reviewOfficer" in record4 && record4.reviewOfficer === true;
1047
+ const record = packagedRoleMetadata(role);
1048
+ return record !== void 0 && "reviewOfficer" in record && record.reviewOfficer === true;
1028
1049
  }
1029
1050
  function packagedProvinceConfig(role) {
1030
- const record4 = packagedRoleMetadata(role);
1031
- return record4 !== void 0 && "provinceConfig" in record4 && record4.provinceConfig === true;
1051
+ const record = packagedRoleMetadata(role);
1052
+ return record !== void 0 && "provinceConfig" in record && record.provinceConfig === true;
1032
1053
  }
1033
1054
  function packagedModelParent(role) {
1034
- const record4 = packagedRoleMetadata(role);
1035
- if (record4 === void 0 || !("modelInheritsFrom" in record4)) return void 0;
1036
- return record4.modelInheritsFrom;
1055
+ const record = packagedRoleMetadata(role);
1056
+ if (record === void 0 || !("modelInheritsFrom" in record)) return void 0;
1057
+ return record.modelInheritsFrom;
1037
1058
  }
1038
1059
  function packagedRoleAcceptedOutputTool(role) {
1039
- const record4 = packagedRoleMetadata(role);
1040
- if (record4 === void 0 || !("settlement" in record4) || record4.settlement !== "accepted") {
1060
+ const record = packagedRoleMetadata(role);
1061
+ if (record === void 0 || !("settlement" in record) || record.settlement !== "accepted") {
1041
1062
  return void 0;
1042
1063
  }
1043
- return record4.outputTool;
1064
+ return record.outputTool;
1044
1065
  }
1045
1066
  function packagedRoleActivationFlags(role) {
1046
- const record4 = packagedRoleMetadata(role);
1047
- if (record4 === void 0 || !("activationFlags" in record4)) return [];
1048
- return record4.activationFlags;
1067
+ const record = packagedRoleMetadata(role);
1068
+ if (record === void 0 || !("activationFlags" in record)) return [];
1069
+ return record.activationFlags;
1049
1070
  }
1050
1071
  function packagedRoleInputFlag(role) {
1051
1072
  return packagedRoleActivationFlags(role).find((spec) => spec.binds === "input")?.flag;
@@ -1057,8 +1078,8 @@ function packagedRoleOutputTool(role) {
1057
1078
  return packagedRoleMetadata(role)?.outputTool;
1058
1079
  }
1059
1080
  function packagedBindsBoardTicket(role) {
1060
- const record4 = packagedRoleMetadata(role);
1061
- return record4?.sameParent === "board-ticket";
1081
+ const record = packagedRoleMetadata(role);
1082
+ return record?.sameParent === "board-ticket";
1062
1083
  }
1063
1084
  function packagedRebindSourceOnResume(role) {
1064
1085
  return packagedRoleMetadata(role)?.admission === "source-locator";
@@ -1067,31 +1088,31 @@ function packagedAdmitsCountersign(role) {
1067
1088
  return packagedRoleMetadata(role)?.admission === "court-materials";
1068
1089
  }
1069
1090
  function packagedBareToken(role) {
1070
- const record4 = packagedRoleMetadata(role);
1071
- if (record4 === void 0 || !("bareToken" in record4)) return void 0;
1072
- return record4.bareToken;
1091
+ const record = packagedRoleMetadata(role);
1092
+ if (record === void 0 || !("bareToken" in record)) return void 0;
1093
+ return record.bareToken;
1073
1094
  }
1074
1095
  function packagedArgvResult(role) {
1075
- const record4 = packagedRoleMetadata(role);
1076
- if (record4 !== void 0 && "argvResult" in record4) return record4.argvResult;
1096
+ const record = packagedRoleMetadata(role);
1097
+ if (record !== void 0 && "argvResult" in record) return record.argvResult;
1077
1098
  return "material";
1078
1099
  }
1079
1100
  function packagedStoresSourceRunRaw(role) {
1080
- const record4 = packagedRoleMetadata(role);
1081
- return record4 !== void 0 && "sourceRunStored" in record4 && record4.sourceRunStored === "raw";
1101
+ const record = packagedRoleMetadata(role);
1102
+ return record !== void 0 && "sourceRunStored" in record && record.sourceRunStored === "raw";
1082
1103
  }
1083
1104
  function packagedBaseIsRevision(role) {
1084
- const record4 = packagedRoleMetadata(role);
1085
- return record4 !== void 0 && "baseValue" in record4 && record4.baseValue === "revision";
1105
+ const record = packagedRoleMetadata(role);
1106
+ return record !== void 0 && "baseValue" in record && record.baseValue === "revision";
1086
1107
  }
1087
1108
  function packagedEmitsAuthorityRefs(role) {
1088
- const record4 = packagedRoleMetadata(role);
1089
- return record4 !== void 0 && "emitAuthorityRefs" in record4 && record4.emitAuthorityRefs === true;
1109
+ const record = packagedRoleMetadata(role);
1110
+ return record !== void 0 && "emitAuthorityRefs" in record && record.emitAuthorityRefs === true;
1090
1111
  }
1091
1112
  function packagedSubjectChoices(role) {
1092
- const record4 = packagedRoleMetadata(role);
1093
- if (record4 === void 0 || !("subjectChoices" in record4)) return void 0;
1094
- return record4.subjectChoices;
1113
+ const record = packagedRoleMetadata(role);
1114
+ if (record === void 0 || !("subjectChoices" in record)) return void 0;
1115
+ return record.subjectChoices;
1095
1116
  }
1096
1117
  function packagedAdmittedSubject(role, value) {
1097
1118
  const choices = packagedSubjectChoices(role);
@@ -1101,47 +1122,47 @@ function packagedAdmittedSubject(role, value) {
1101
1122
  return void 0;
1102
1123
  }
1103
1124
  function packagedAuditToolName(role) {
1104
- const record4 = packagedRoleMetadata(role);
1105
- if (record4 === void 0 || !("auditTool" in record4)) return void 0;
1106
- return record4.auditTool;
1125
+ const record = packagedRoleMetadata(role);
1126
+ if (record === void 0 || !("auditTool" in record)) return void 0;
1127
+ return record.auditTool;
1107
1128
  }
1108
1129
  function packagedSkipsGateOnInfrastructureStage(stage) {
1109
1130
  return typeof stage === "string" && PUBLIC_ROLE_RECORDS.some(
1110
- (record4) => "skipGateOnInfrastructureStage" in record4 && record4.skipGateOnInfrastructureStage === true && record4.role === stage
1131
+ (record) => "skipGateOnInfrastructureStage" in record && record.skipGateOnInfrastructureStage === true && record.role === stage
1111
1132
  );
1112
1133
  }
1113
1134
  function packagedDurableOfficerEntry(officer) {
1114
1135
  return typeof officer === "string" && PUBLIC_ROLE_RECORDS.some(
1115
- (record4) => "durableOfficerEntry" in record4 && record4.durableOfficerEntry === true && record4.role === officer
1136
+ (record) => "durableOfficerEntry" in record && record.durableOfficerEntry === true && record.role === officer
1116
1137
  );
1117
1138
  }
1118
1139
  function packagedPublicInstructionSubject(role) {
1119
1140
  return typeof role === "string" && PUBLIC_ROLE_RECORDS.some(
1120
- (record4) => "navigatorSubject" in record4 && record4.navigatorSubject === "public-instruction" && record4.role === role
1141
+ (record) => "navigatorSubject" in record && record.navigatorSubject === "public-instruction" && record.role === role
1121
1142
  );
1122
1143
  }
1123
1144
  function packagedResumeSourcePath(role) {
1124
- const record4 = packagedRoleMetadata(role);
1125
- return record4 !== void 0 && "resumeSourcePath" in record4 && record4.resumeSourcePath === true;
1145
+ const record = packagedRoleMetadata(role);
1146
+ return record !== void 0 && "resumeSourcePath" in record && record.resumeSourcePath === true;
1126
1147
  }
1127
1148
  function packagedProjectsTargetBindRejection(role) {
1128
- const record4 = packagedRoleMetadata(role);
1129
- return record4 !== void 0 && "projectTargetBindRejection" in record4 && record4.projectTargetBindRejection === true;
1149
+ const record = packagedRoleMetadata(role);
1150
+ return record !== void 0 && "projectTargetBindRejection" in record && record.projectTargetBindRejection === true;
1130
1151
  }
1131
1152
  function packagedNavigatorSubject(role) {
1132
- const record4 = packagedRoleMetadata(role);
1133
- if (record4 !== void 0 && "navigatorSubject" in record4) return record4.navigatorSubject;
1153
+ const record = packagedRoleMetadata(role);
1154
+ if (record !== void 0 && "navigatorSubject" in record) return record.navigatorSubject;
1134
1155
  return "file";
1135
1156
  }
1136
1157
  function packagedBoardPlacement(role) {
1137
- const record4 = packagedRoleMetadata(role);
1138
- if (record4 === void 0 || !("boardPlacement" in record4)) return void 0;
1139
- return record4.boardPlacement;
1158
+ const record = packagedRoleMetadata(role);
1159
+ if (record === void 0 || !("boardPlacement" in record)) return void 0;
1160
+ return record.boardPlacement;
1140
1161
  }
1141
1162
  function packagedAnalystTerminal(role) {
1142
- const record4 = packagedRoleMetadata(role);
1143
- if (record4 === void 0 || !("analystTerminal" in record4)) return void 0;
1144
- return record4.analystTerminal;
1163
+ const record = packagedRoleMetadata(role);
1164
+ if (record === void 0 || !("analystTerminal" in record)) return void 0;
1165
+ return record.analystTerminal;
1145
1166
  }
1146
1167
  function packagedRoleSessionMaterials(role) {
1147
1168
  return PUBLIC_ROLE_RECORDS.find((entry) => entry.role === role)?.sessionMaterials;
@@ -1150,13 +1171,13 @@ function isNavigatorSeat(role) {
1150
1171
  return packagedRoleOutputTool(role) === NAVIGATOR_OUTPUT_TOOL_NAME;
1151
1172
  }
1152
1173
  function packagedGateStageLabel(role) {
1153
- const record4 = packagedRoleMetadata(role);
1154
- if (record4 === void 0 || !("gateStageLabel" in record4)) return void 0;
1155
- return record4.gateStageLabel;
1174
+ const record = packagedRoleMetadata(role);
1175
+ if (record === void 0 || !("gateStageLabel" in record)) return void 0;
1176
+ return record.gateStageLabel;
1156
1177
  }
1157
1178
  function packagedGateSummon(role) {
1158
- const record4 = packagedRoleMetadata(role);
1159
- if (record4 !== void 0 && "gateSummon" in record4) return record4.gateSummon;
1179
+ const record = packagedRoleMetadata(role);
1180
+ if (record !== void 0 && "gateSummon" in record) return record.gateSummon;
1160
1181
  return "pointer";
1161
1182
  }
1162
1183
  var LEGACY_REVIEW_OUTPUT_ROLES, NOTARY_SESSION_MATERIALS, INSPECTOR_SESSION_MATERIALS, AUDITOR_PUBLIC_SESSION_MATERIALS, PUBLIC_ROLE_RECORDS, PACKAGED_ROLE_REGISTRY;
@@ -1724,7 +1745,7 @@ function unreadableDiscriminatorNotice(field, received) {
1724
1745
  return `\u8BFB\u4E0D\u51FA ${field}\uFF1A${readableGateItem(received)}`;
1725
1746
  }
1726
1747
  function receivedDiscriminator(receipt, field) {
1727
- if (receipt === null || typeof receipt !== "object" || Array.isArray(receipt)) return void 0;
1748
+ if (!isRecord(receipt)) return void 0;
1728
1749
  if (!Object.hasOwn(receipt, field)) return void 0;
1729
1750
  return receipt[field];
1730
1751
  }
@@ -1733,6 +1754,7 @@ var init_submission_errors = __esm({
1733
1754
  "src/submission-errors.ts"() {
1734
1755
  "use strict";
1735
1756
  init_readable_gate_item();
1757
+ init_unknown_value();
1736
1758
  GatekeeperDecisionError = class extends Error {
1737
1759
  result;
1738
1760
  constructor(result, message) {
@@ -1780,7 +1802,7 @@ function isCorrectableExecuteError(error) {
1780
1802
  return isCorrectableSubmissionError(error) || error instanceof GatekeeperDecisionError || error instanceof ParentQueueReaskError || error instanceof WorkerCommitReminderError || error instanceof WorkerPrefixReminderError || error instanceof WorkerUnfinishedReasonReminderError;
1781
1803
  }
1782
1804
  function projectCorrectableExecuteRejection(error) {
1783
- const diagnostic = error instanceof Error ? error.message : String(error);
1805
+ const diagnostic = errorText(error);
1784
1806
  if (error instanceof GatekeeperDecisionError) {
1785
1807
  return { diagnostic, details: { ...error.result } };
1786
1808
  }
@@ -1802,6 +1824,7 @@ var init_submission_correctable_error = __esm({
1802
1824
  "src/submission-correctable-error.ts"() {
1803
1825
  "use strict";
1804
1826
  init_submission_errors();
1827
+ init_unknown_value();
1805
1828
  correctableSubmissionErrorBrand = /* @__PURE__ */ Symbol("ak-roles.correctable-submission-error");
1806
1829
  CorrectableSubmissionError = class extends Error {
1807
1830
  [correctableSubmissionErrorBrand] = true;
@@ -1814,20 +1837,20 @@ function isTerminatingToolName(name) {
1814
1837
  return TERMINATING_TOOL_NAMES.includes(name);
1815
1838
  }
1816
1839
  function validateAcceptedDetails(_toolName, details) {
1817
- if (details !== null && typeof details === "object" && !Array.isArray(details)) {
1840
+ if (isRecord(details)) {
1818
1841
  return details;
1819
1842
  }
1820
1843
  return {};
1821
1844
  }
1822
1845
  function acceptedFacts(toolName, details) {
1823
- const record4 = details;
1846
+ const record = details;
1824
1847
  const entry = PACKAGED_ROLE_REGISTRY.find((candidate) => candidate.outputTool === toolName);
1825
1848
  const legacyRole = LEGACY_REVIEW_OUTPUT_ROLES.get(toolName);
1826
1849
  const statusKey = legacyRole === "judge" || legacyRole === "countersign" ? `${legacyRole}Status` : entry !== void 0 && "receiptStatusKey" in entry ? entry.receiptStatusKey : "status";
1827
- const status = typeof record4[statusKey] === "string" ? record4[statusKey] : void 0;
1850
+ const status = typeof record[statusKey] === "string" ? record[statusKey] : void 0;
1828
1851
  const commitKey = entry !== void 0 && "receiptCommitKey" in entry ? entry.receiptCommitKey : void 0;
1829
1852
  const commitWhen = entry !== void 0 && "receiptCommitWhen" in entry ? entry.receiptCommitWhen : void 0;
1830
- const commit = commitKey !== void 0 && status === commitWhen && typeof record4[commitKey] === "string" ? record4[commitKey] : void 0;
1853
+ const commit = commitKey !== void 0 && status === commitWhen && typeof record[commitKey] === "string" ? record[commitKey] : void 0;
1831
1854
  return {
1832
1855
  ...status === void 0 ? {} : { status },
1833
1856
  ...commit === void 0 ? {} : { commit }
@@ -1854,6 +1877,7 @@ var init_terminating_tools = __esm({
1854
1877
  init_diarist_contracts();
1855
1878
  init_secretariat_contracts();
1856
1879
  init_worker_output();
1880
+ init_unknown_value();
1857
1881
  TERMINATING_TOOL_NAMES = [.../* @__PURE__ */ new Set([
1858
1882
  ...PACKAGED_ROLE_REGISTRY.map((entry) => entry.outputTool),
1859
1883
  ...LEGACY_REVIEW_OUTPUT_ROLES.keys()
@@ -1871,9 +1895,6 @@ var init_terminating_tools = __esm({
1871
1895
  // src/doctor-evidence.ts
1872
1896
  import { readdir, readFile as readFile2, realpath, stat } from "node:fs/promises";
1873
1897
  import { dirname, relative, resolve, sep } from "node:path";
1874
- function record2(value) {
1875
- return typeof value === "object" && value !== null && !Array.isArray(value);
1876
- }
1877
1898
  async function discoverCaseFiles(root) {
1878
1899
  const found = [];
1879
1900
  async function walk(dir, depth) {
@@ -1897,9 +1918,6 @@ function accumulate(metric, value, source) {
1897
1918
  function timestamp(row) {
1898
1919
  return typeof row.timestamp === "string" && Number.isFinite(Date.parse(row.timestamp)) ? row.timestamp : void 0;
1899
1920
  }
1900
- function isMissingPathError(error) {
1901
- return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
1902
- }
1903
1921
  async function stableRunsIdentity(root) {
1904
1922
  let cursor = root;
1905
1923
  while (true) {
@@ -1920,7 +1938,7 @@ function deriveSession(content, id) {
1920
1938
  for (const line2 of content.split("\n")) if (line2.trim()) {
1921
1939
  try {
1922
1940
  const row = JSON.parse(line2);
1923
- if (!record2(row)) {
1941
+ if (!isRecord(row)) {
1924
1942
  degradationReasons.push(`non-object session row in ${id}`);
1925
1943
  break;
1926
1944
  }
@@ -1939,17 +1957,17 @@ function deriveSession(content, id) {
1939
1957
  let accepted, observedCommit, turns = 0, calls = 0, tokens = 0;
1940
1958
  const statuses = [], commits = [];
1941
1959
  for (const row of rows) {
1942
- if (row.type === "custom" && row.customType === "ak-role-submission-closure" && record2(row.data) && row.data.isError === false && typeof row.data.toolName === "string" && isTerminatingToolName(row.data.toolName)) accepted = row;
1943
- const message = record2(row.message) ? row.message : void 0;
1960
+ if (row.type === "custom" && row.customType === "ak-role-submission-closure" && isRecord(row.data) && row.data.isError === false && typeof row.data.toolName === "string" && isTerminatingToolName(row.data.toolName)) accepted = row;
1961
+ const message = isRecord(row.message) ? row.message : void 0;
1944
1962
  if (message?.role === "assistant") {
1945
- for (const part of Array.isArray(message.content) ? message.content : []) if (record2(part) && part.type === "toolCall") calls++;
1963
+ for (const part of Array.isArray(message.content) ? message.content : []) if (isRecord(part) && part.type === "toolCall") calls++;
1946
1964
  if (typeof message.responseId === "string") {
1947
1965
  turns++;
1948
- const usage = record2(message.usage) ? message.usage : void 0;
1966
+ const usage = isRecord(message.usage) ? message.usage : void 0;
1949
1967
  if (usage && typeof usage.output === "number") tokens += usage.output;
1950
1968
  }
1951
1969
  }
1952
- if (message?.role === "toolResult" && message.isError !== true && typeof message.toolName === "string" && isTerminatingToolName(message.toolName) && record2(message.details)) {
1970
+ if (message?.role === "toolResult" && message.isError !== true && typeof message.toolName === "string" && isTerminatingToolName(message.toolName) && isRecord(message.details)) {
1953
1971
  let details;
1954
1972
  try {
1955
1973
  details = validateAcceptedDetails(message.toolName, message.details);
@@ -2010,6 +2028,7 @@ var init_doctor_evidence = __esm({
2010
2028
  "use strict";
2011
2029
  init_sha256();
2012
2030
  init_terminating_tools();
2031
+ init_unknown_value();
2013
2032
  }
2014
2033
  });
2015
2034
 
@@ -2131,13 +2150,6 @@ function physicalPathIdentity(path) {
2131
2150
  function physicallyContainedIn(root, candidate) {
2132
2151
  return pathContainedIn(physicalPathIdentity(root), physicalPathIdentity(candidate));
2133
2152
  }
2134
- function errnoCode(error) {
2135
- return error !== null && typeof error === "object" && "code" in error && typeof error.code === "string" ? error.code : void 0;
2136
- }
2137
- function errorText(error) {
2138
- if (!(error instanceof Error)) return String(error);
2139
- return error.message;
2140
- }
2141
2153
  function assertPhysicalLedgerRoot(absoluteRoot) {
2142
2154
  let st;
2143
2155
  try {
@@ -2302,6 +2314,7 @@ var ActivationLedgerError;
2302
2314
  var init_activation_ledger_topology = __esm({
2303
2315
  "src/activation-ledger-topology.ts"() {
2304
2316
  "use strict";
2317
+ init_unknown_value();
2305
2318
  ActivationLedgerError = class extends Error {
2306
2319
  code = "AK_ACTIVATION_LEDGER";
2307
2320
  constructor(message, options) {
@@ -2372,21 +2385,21 @@ function buildNavigatorInfrastructureFailureFact() {
2372
2385
  }
2373
2386
  function extractInfrastructureFailureEvidence(error) {
2374
2387
  if (typeof error !== "object" || error === null) return {};
2375
- const record4 = error;
2388
+ const record = error;
2376
2389
  const evidence = {};
2377
2390
  for (const key of NAVIGATOR_INFRASTRUCTURE_FAILURE_EVIDENCE_KEYS) {
2378
- if (!Object.hasOwn(record4, key)) continue;
2379
- evidence[key] = record4[key] === void 0 ? null : record4[key];
2391
+ if (!Object.hasOwn(record, key)) continue;
2392
+ evidence[key] = record[key] === void 0 ? null : record[key];
2380
2393
  }
2381
2394
  return evidence;
2382
2395
  }
2383
2396
  function hasNavigatorInfrastructureFailureBase(value) {
2384
- if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
2385
- const record4 = value;
2397
+ if (!isRecord(value)) return false;
2398
+ const record = value;
2386
2399
  for (const key of NAVIGATOR_INFRASTRUCTURE_FAILURE_KEYS) {
2387
- if (!Object.hasOwn(record4, key)) return false;
2400
+ if (!Object.hasOwn(record, key)) return false;
2388
2401
  }
2389
- return record4.kind === NAVIGATOR_INFRASTRUCTURE_FAILURE_KIND && record4.source === "shared-role-lifecycle" && record4.reasonCode === "host_failure";
2402
+ return record.kind === NAVIGATOR_INFRASTRUCTURE_FAILURE_KIND && record.source === "shared-role-lifecycle" && record.reasonCode === "host_failure";
2390
2403
  }
2391
2404
  function mintNavigatorInvocationId() {
2392
2405
  return uuidv7();
@@ -2396,21 +2409,21 @@ function invocationPhaseFromUnknown(value) {
2396
2409
  return void 0;
2397
2410
  }
2398
2411
  function parseInvocationMarkerIdentity(data) {
2399
- if (data === null || typeof data !== "object" || Array.isArray(data)) return void 0;
2400
- const record4 = data;
2401
- const invocationId = record4.invocationId;
2412
+ if (!isRecord(data)) return void 0;
2413
+ const record = data;
2414
+ const invocationId = record.invocationId;
2402
2415
  if (typeof invocationId !== "string") return void 0;
2403
2416
  const trimmedId = invocationId.trim();
2404
2417
  if (!isUuidV7(trimmedId)) return void 0;
2405
- if (typeof record4.role !== "string" || record4.role.trim() === "") return void 0;
2406
- const phase = invocationPhaseFromUnknown(record4.phase);
2418
+ if (typeof record.role !== "string" || record.role.trim() === "") return void 0;
2419
+ const phase = invocationPhaseFromUnknown(record.phase);
2407
2420
  if (phase === void 0) return void 0;
2408
- if (typeof record4.subjectKey !== "string" || record4.subjectKey.trim() === "") return void 0;
2421
+ if (typeof record.subjectKey !== "string" || record.subjectKey.trim() === "") return void 0;
2409
2422
  return {
2410
2423
  invocationId: trimmedId,
2411
- role: record4.role,
2424
+ role: record.role,
2412
2425
  phase,
2413
- subjectKey: record4.subjectKey
2426
+ subjectKey: record.subjectKey
2414
2427
  };
2415
2428
  }
2416
2429
  function markerMatchesExpectedIdentity(marker, expected) {
@@ -2504,6 +2517,7 @@ var init_navigator_invocation_identity = __esm({
2504
2517
  "use strict";
2505
2518
  init_packaged_role_registry();
2506
2519
  init_uuidv7();
2520
+ init_unknown_value();
2507
2521
  init_work_subject_identity();
2508
2522
  NAVIGATOR_INVOCATION_ENTRY = "ak-navigator-invocation";
2509
2523
  NAVIGATOR_ROUTE_PLAYBOOK_FAILURE_ENTRY = "ak-navigator-route-playbook-failure";
@@ -2540,8 +2554,7 @@ function isConfirmedNonRepositoryStderr(stderr) {
2540
2554
  return CONFIRMED_NON_REPOSITORY_STDERR.test(stderr);
2541
2555
  }
2542
2556
  function isGitSpawnInfrastructureError(error) {
2543
- if (error === null || typeof error !== "object" || !("code" in error)) return false;
2544
- const code = error.code;
2557
+ const code = errnoCode(error);
2545
2558
  return code === "ENOENT" || code === "EACCES" || code === "EPERM";
2546
2559
  }
2547
2560
  function gitChildExitedNonzero(error) {
@@ -2584,6 +2597,7 @@ var GIT_DISCOVERY_ENV_KEYS, CONFIRMED_NON_REPOSITORY_STDERR, ActivationGitReposi
2584
2597
  var init_activation_ledger_git = __esm({
2585
2598
  "src/activation-ledger-git.ts"() {
2586
2599
  "use strict";
2600
+ init_unknown_value();
2587
2601
  GIT_DISCOVERY_ENV_KEYS = [
2588
2602
  "GIT_DIR",
2589
2603
  "GIT_COMMON_DIR",
@@ -2695,7 +2709,7 @@ function appendSitianRecord(input) {
2695
2709
  const identity = input.identity ?? randomUUID();
2696
2710
  const timestamp2 = input.timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
2697
2711
  const host = input.host ?? "pi";
2698
- const record4 = {
2712
+ const record = {
2699
2713
  level: input.level,
2700
2714
  kind: input.kind,
2701
2715
  identity,
@@ -2708,14 +2722,14 @@ function appendSitianRecord(input) {
2708
2722
  ...input.raw === void 0 ? {} : { raw: input.raw },
2709
2723
  ...input.usage === void 0 ? {} : { usage: input.usage }
2710
2724
  };
2711
- const row = `${JSON.stringify(record4)}
2725
+ const row = `${JSON.stringify(record)}
2712
2726
  `;
2713
2727
  appendFileSync(recordFile, row, "utf8");
2714
2728
  return {
2715
- identity: record4.identity,
2729
+ identity: record.identity,
2716
2730
  recordFile,
2717
- kind: record4.kind,
2718
- level: record4.level
2731
+ kind: record.kind,
2732
+ level: record.level
2719
2733
  };
2720
2734
  } catch (error) {
2721
2735
  if (error instanceof SitianInfrastructureError) throw error;
@@ -2746,9 +2760,6 @@ var init_sitian_appender = __esm({
2746
2760
  // src/sitian-reader.ts
2747
2761
  import { existsSync } from "node:fs";
2748
2762
  import { readFile as readFile3 } from "node:fs/promises";
2749
- function isRecord2(value) {
2750
- return typeof value === "object" && value !== null && !Array.isArray(value);
2751
- }
2752
2763
  async function readSitianRecords(recordFile) {
2753
2764
  if (!existsSync(recordFile)) {
2754
2765
  return { records: [], diagnostics: [] };
@@ -2762,7 +2773,7 @@ async function readSitianRecords(recordFile) {
2762
2773
  if (!line2.trim()) continue;
2763
2774
  try {
2764
2775
  const parsed = JSON.parse(line2);
2765
- if (isRecord2(parsed)) {
2776
+ if (isRecord(parsed)) {
2766
2777
  records.push(parsed);
2767
2778
  } else {
2768
2779
  const typeDesc = parsed === null ? "null" : Array.isArray(parsed) ? "array" : typeof parsed;
@@ -2778,7 +2789,7 @@ async function readSitianRecords(recordFile) {
2778
2789
  kind: "malformed",
2779
2790
  line: index + 1,
2780
2791
  raw: line2,
2781
- error: error instanceof Error ? error.message : String(error)
2792
+ error: errorText(error)
2782
2793
  });
2783
2794
  }
2784
2795
  }
@@ -2787,6 +2798,7 @@ async function readSitianRecords(recordFile) {
2787
2798
  var init_sitian_reader = __esm({
2788
2799
  "src/sitian-reader.ts"() {
2789
2800
  "use strict";
2801
+ init_unknown_value();
2790
2802
  }
2791
2803
  });
2792
2804
 
@@ -3027,9 +3039,7 @@ async function loadPublicCliConfig(home) {
3027
3039
  const raw = await readFile4(path, "utf8");
3028
3040
  return parsePublicCliConfig(JSON.parse(raw));
3029
3041
  } catch (error) {
3030
- if (error instanceof Error && "code" in error && error.code === "ENOENT") {
3031
- return { seats: {} };
3032
- }
3042
+ if (isEnoent(error)) return { seats: {} };
3033
3043
  throw error;
3034
3044
  }
3035
3045
  }
@@ -3250,35 +3260,35 @@ function serializePublicCliConfig(config) {
3250
3260
  };
3251
3261
  }
3252
3262
  function parsePublicCliConfig(value) {
3253
- if (value === null || typeof value !== "object" || Array.isArray(value)) {
3263
+ if (!isRecord(value)) {
3254
3264
  throw new Error("public CLI config must be an object");
3255
3265
  }
3256
- const record4 = value;
3266
+ const record = value;
3257
3267
  let autoResumeLimit;
3258
- if (record4.autoResumeLimit !== void 0) {
3259
- autoResumeLimit = parseAutoResumeLimit(record4.autoResumeLimit);
3268
+ if (record.autoResumeLimit !== void 0) {
3269
+ autoResumeLimit = parseAutoResumeLimit(record.autoResumeLimit);
3260
3270
  }
3261
3271
  const unknownSeats = {};
3262
- if (record4.unknownSeats !== void 0) {
3263
- if (record4.unknownSeats === null || typeof record4.unknownSeats !== "object" || Array.isArray(record4.unknownSeats)) {
3272
+ if (record.unknownSeats !== void 0) {
3273
+ if (!isRecord(record.unknownSeats)) {
3264
3274
  throw new Error("public CLI config.unknownSeats must be an object");
3265
3275
  }
3266
- Object.assign(unknownSeats, record4.unknownSeats);
3276
+ Object.assign(unknownSeats, record.unknownSeats);
3267
3277
  }
3268
3278
  const withOpaque = (seats2) => ({
3269
3279
  seats: seats2,
3270
3280
  ...autoResumeLimit === void 0 ? {} : { autoResumeLimit },
3271
3281
  ...Object.keys(unknownSeats).length === 0 ? {} : { unknownSeats }
3272
3282
  });
3273
- if (record4.seats === void 0) {
3283
+ if (record.seats === void 0) {
3274
3284
  return withOpaque({});
3275
3285
  }
3276
- if (record4.seats === null || typeof record4.seats !== "object" || Array.isArray(record4.seats)) {
3286
+ if (!isRecord(record.seats)) {
3277
3287
  throw new Error("public CLI config.seats must be an object");
3278
3288
  }
3279
3289
  const seats = {};
3280
3290
  for (const [key, raw] of Object.entries(
3281
- record4.seats
3291
+ record.seats
3282
3292
  )) {
3283
3293
  if (!isPublicConfigurableSeat(key)) {
3284
3294
  unknownSeats[key] = raw;
@@ -3289,7 +3299,7 @@ function parsePublicCliConfig(value) {
3289
3299
  return withOpaque(seats);
3290
3300
  }
3291
3301
  function parseSeatModelConfig(value, seat) {
3292
- if (value === null || typeof value !== "object" || Array.isArray(value)) {
3302
+ if (!isRecord(value)) {
3293
3303
  throw new Error(`config seat ${seat} must be an object`);
3294
3304
  }
3295
3305
  const raw = value;
@@ -3471,13 +3481,13 @@ function listRolesForDisplay(config, credentials, invocation) {
3471
3481
  return effectiveSeatConfigurations(config, credentials, invocation);
3472
3482
  }
3473
3483
  function credentialProvidersFromAuthData(data) {
3474
- if (data === null || typeof data !== "object" || Array.isArray(data)) {
3484
+ if (!isRecord(data)) {
3475
3485
  return { "openai-codex": false, xai: false };
3476
3486
  }
3477
- const record4 = data;
3487
+ const record = data;
3478
3488
  return {
3479
- "openai-codex": Object.prototype.hasOwnProperty.call(record4, "openai-codex"),
3480
- xai: Object.prototype.hasOwnProperty.call(record4, "xai")
3489
+ "openai-codex": Object.prototype.hasOwnProperty.call(record, "openai-codex"),
3490
+ xai: Object.prototype.hasOwnProperty.call(record, "xai")
3481
3491
  };
3482
3492
  }
3483
3493
  function resolvePublicAgentDir(explicit, home) {
@@ -3488,9 +3498,7 @@ async function loadCredentialProviders(agentDir) {
3488
3498
  const raw = await readFile4(join6(agentDir, "auth.json"), "utf8");
3489
3499
  return credentialProvidersFromAuthData(JSON.parse(raw));
3490
3500
  } catch (error) {
3491
- if (error instanceof Error && "code" in error && error.code === "ENOENT") {
3492
- return { "openai-codex": false, xai: false };
3493
- }
3501
+ if (isEnoent(error)) return { "openai-codex": false, xai: false };
3494
3502
  throw error;
3495
3503
  }
3496
3504
  }
@@ -3503,8 +3511,9 @@ var init_config = __esm({
3503
3511
  init_institutional_resolution();
3504
3512
  init_packaged_role_registry();
3505
3513
  init_registry();
3514
+ init_unknown_value();
3506
3515
  GATE_OFFICER_SEATS = PUBLIC_ROLE_RECORDS.flatMap(
3507
- (record4) => "provinceConfig" in record4 && record4.provinceConfig === true ? [record4.role] : []
3516
+ (record) => "provinceConfig" in record && record.provinceConfig === true ? [record.role] : []
3508
3517
  );
3509
3518
  }
3510
3519
  });
@@ -3584,9 +3593,6 @@ var init_atomic_write = __esm({
3584
3593
  // src/role-run-placement.ts
3585
3594
  import { readdir as readdir2 } from "node:fs/promises";
3586
3595
  import { join as join9 } from "node:path";
3587
- function isMissingPathError2(error) {
3588
- return error instanceof Error && "code" in error && error.code === "ENOENT";
3589
- }
3590
3596
  async function listBookRunDirectories(bookDir) {
3591
3597
  const out = [];
3592
3598
  const seen = /* @__PURE__ */ new Set();
@@ -3595,7 +3601,7 @@ async function listBookRunDirectories(bookDir) {
3595
3601
  try {
3596
3602
  entries = await readdir2(runsDir, { withFileTypes: true });
3597
3603
  } catch (error) {
3598
- if (isMissingPathError2(error)) return;
3604
+ if (isEnoent(error)) return;
3599
3605
  throw error;
3600
3606
  }
3601
3607
  for (const entry of entries) {
@@ -3611,7 +3617,7 @@ async function listBookRunDirectories(bookDir) {
3611
3617
  try {
3612
3618
  subjects = await readdir2(bookDir, { withFileTypes: true });
3613
3619
  } catch (error) {
3614
- if (isMissingPathError2(error)) return out.sort();
3620
+ if (isEnoent(error)) return out.sort();
3615
3621
  throw error;
3616
3622
  }
3617
3623
  for (const subject of subjects) {
@@ -3662,6 +3668,7 @@ var init_role_run_placement = __esm({
3662
3668
  "use strict";
3663
3669
  init_activation_ledger_topology();
3664
3670
  init_run_ticket_number();
3671
+ init_unknown_value();
3665
3672
  }
3666
3673
  });
3667
3674
 
@@ -3712,16 +3719,16 @@ var init_durable_principal = __esm({
3712
3719
  });
3713
3720
  },
3714
3721
  decode(value) {
3715
- const record4 = value;
3716
- if (record4 === null || typeof record4 !== "object") {
3722
+ const record = value;
3723
+ if (record === null || typeof record !== "object") {
3717
3724
  throw new Error("durable principal payload is missing");
3718
3725
  }
3719
- if (typeof record4.sessionDirectory !== "string" || record4.sessionDirectory.trim() === "") {
3726
+ if (typeof record.sessionDirectory !== "string" || record.sessionDirectory.trim() === "") {
3720
3727
  throw new Error("durable principal session directory is missing");
3721
3728
  }
3722
3729
  return {
3723
- sessionDirectory: record4.sessionDirectory,
3724
- sessionFile: typeof record4.sessionFile === "string" && record4.sessionFile.trim() !== "" ? record4.sessionFile : join10(record4.sessionDirectory, "session.jsonl")
3730
+ sessionDirectory: record.sessionDirectory,
3731
+ sessionFile: typeof record.sessionFile === "string" && record.sessionFile.trim() !== "" ? record.sessionFile : join10(record.sessionDirectory, "session.jsonl")
3725
3732
  };
3726
3733
  }
3727
3734
  };
@@ -3738,9 +3745,7 @@ async function clearTypedProviderHttpObservation(runDirectory) {
3738
3745
  try {
3739
3746
  await unlink(typedProviderHttpPath(runDirectory));
3740
3747
  } catch (error) {
3741
- if (error instanceof Error && "code" in error && error.code === "ENOENT") {
3742
- return;
3743
- }
3748
+ if (isEnoent(error)) return;
3744
3749
  throw error;
3745
3750
  }
3746
3751
  }
@@ -3765,34 +3770,32 @@ async function readLatestTypedProviderHttpObservation(runDirectory) {
3765
3770
  try {
3766
3771
  text = await readFile6(typedProviderHttpPath(runDirectory), "utf8");
3767
3772
  } catch (error) {
3768
- if (error instanceof Error && "code" in error && error.code === "ENOENT") {
3769
- return void 0;
3770
- }
3773
+ if (isEnoent(error)) return void 0;
3771
3774
  throw error;
3772
3775
  }
3773
3776
  const raw = JSON.parse(text);
3774
- if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
3777
+ if (!isRecord(raw)) {
3775
3778
  throw new Error("typed provider HTTP observation must be a JSON object");
3776
3779
  }
3777
- const record4 = raw;
3778
- if (typeof record4.httpStatus !== "number") {
3780
+ const record = raw;
3781
+ if (typeof record.httpStatus !== "number") {
3779
3782
  throw new Error("typed provider HTTP observation missing numeric httpStatus");
3780
3783
  }
3781
- if (typeof record4.provider !== "string" || record4.provider.trim() === "") {
3784
+ if (typeof record.provider !== "string" || record.provider.trim() === "") {
3782
3785
  throw new Error("typed provider HTTP observation missing non-empty provider");
3783
3786
  }
3784
- return { httpStatus: record4.httpStatus, provider: record4.provider };
3787
+ return { httpStatus: record.httpStatus, provider: record.provider };
3785
3788
  }
3786
3789
  var TYPED_HTTP_FILE;
3787
3790
  var init_typed_provider_http = __esm({
3788
3791
  "src/typed-provider-http.ts"() {
3789
3792
  "use strict";
3793
+ init_unknown_value();
3790
3794
  TYPED_HTTP_FILE = "typed-provider-http.json";
3791
3795
  }
3792
3796
  });
3793
3797
 
3794
3798
  // src/collector-config.ts
3795
- import { createHash as createHash2 } from "node:crypto";
3796
3799
  import { readFile as readFile7 } from "node:fs/promises";
3797
3800
  function fail3(message, cause) {
3798
3801
  throw new Error(message, cause === void 0 ? void 0 : { cause });
@@ -3822,16 +3825,13 @@ function parseCollectorPrNumber(raw) {
3822
3825
  if (!Number.isSafeInteger(value) || value < 1) fail3("Collector pull request number must be a positive safe integer");
3823
3826
  return value;
3824
3827
  }
3825
- function record3(value) {
3826
- return typeof value === "object" && value !== null && !Array.isArray(value);
3827
- }
3828
3828
  function canonicalManifest(requests) {
3829
3829
  return `${JSON.stringify({ requests: requests.map((request) => ({ id: request.id, body: request.requestBody })) })}
3830
3830
  `;
3831
3831
  }
3832
3832
  function emptyCollectorManifest() {
3833
3833
  const canonicalJson2 = canonicalManifest([]);
3834
- return { requests: [], canonicalJson: canonicalJson2, digest: createHash2("sha256").update(canonicalJson2).digest("hex") };
3834
+ return { requests: [], canonicalJson: canonicalJson2, digest: sha256Hex(canonicalJson2) };
3835
3835
  }
3836
3836
  async function loadCollectorManifest(path) {
3837
3837
  let bytes;
@@ -3846,24 +3846,26 @@ async function loadCollectorManifest(path) {
3846
3846
  } catch (error) {
3847
3847
  fail3("Collector request manifest must be UTF-8 JSON", error);
3848
3848
  }
3849
- if (!record3(parsed)) fail3("Collector request manifest must be an object");
3849
+ if (!isRecord(parsed)) fail3("Collector request manifest must be an object");
3850
3850
  const rawRequests = parsed.requests ?? [];
3851
3851
  if (!Array.isArray(rawRequests)) fail3("Collector request manifest requests must be an array");
3852
3852
  const requests = [];
3853
3853
  const ids = /* @__PURE__ */ new Set();
3854
3854
  for (const [index, item] of rawRequests.entries()) {
3855
- if (!record3(item) || typeof item.id !== "string" || item.id.length === 0 || typeof item.body !== "string" || item.body.trim() === "") fail3(`Collector request manifest requests[${index}] is invalid`);
3855
+ if (!isRecord(item) || typeof item.id !== "string" || item.id.length === 0 || typeof item.body !== "string" || item.body.trim() === "") fail3(`Collector request manifest requests[${index}] is invalid`);
3856
3856
  if (ids.has(item.id)) fail3(`Collector request manifest has duplicate request id "${item.id}"`);
3857
3857
  ids.add(item.id);
3858
3858
  requests.push({ id: item.id, requestBody: item.body });
3859
3859
  }
3860
3860
  const canonicalJson2 = canonicalManifest(requests);
3861
- return { requests, canonicalJson: canonicalJson2, digest: createHash2("sha256").update(canonicalJson2).digest("hex"), sourcePath: path };
3861
+ return { requests, canonicalJson: canonicalJson2, digest: sha256Hex(canonicalJson2), sourcePath: path };
3862
3862
  }
3863
3863
  var COLLECTOR_OWNER_PATTERN, COLLECTOR_REPO_PATTERN;
3864
3864
  var init_collector_config = __esm({
3865
3865
  "src/collector-config.ts"() {
3866
3866
  "use strict";
3867
+ init_sha256();
3868
+ init_unknown_value();
3867
3869
  COLLECTOR_OWNER_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/;
3868
3870
  COLLECTOR_REPO_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9._-]{0,98}[A-Za-z0-9])?$/;
3869
3871
  }
@@ -3932,20 +3934,11 @@ __export(run_terminal_artifacts_exports, {
3932
3934
  });
3933
3935
  import { readdir as readdir3, readFile as readFile8 } from "node:fs/promises";
3934
3936
  import { basename as basename4, dirname as dirname9, join as join13 } from "node:path";
3935
- function isMissingPathError3(error) {
3936
- return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
3937
- }
3938
- function errorText2(error) {
3939
- return error instanceof Error ? error.message : String(error);
3940
- }
3941
- function isRecord3(value) {
3942
- return typeof value === "object" && value !== null && !Array.isArray(value);
3943
- }
3944
3937
  function readUsableTerminalArtifactBody(body) {
3945
3938
  if (body === null) {
3946
3939
  return { ok: false, reason: "terminal artifact JSON value is null" };
3947
3940
  }
3948
- if (!isRecord3(body)) {
3941
+ if (!isRecord(body)) {
3949
3942
  return {
3950
3943
  ok: false,
3951
3944
  reason: `terminal artifact JSON value is not a typed object (${Array.isArray(body) ? "array" : typeof body})`
@@ -3964,12 +3957,12 @@ async function readTerminalArtifactAtPath(path, file) {
3964
3957
  try {
3965
3958
  raw = await readFile8(path, "utf8");
3966
3959
  } catch (error) {
3967
- if (isMissingPathError3(error)) return void 0;
3960
+ if (isMissingPathError(error)) return void 0;
3968
3961
  return {
3969
3962
  status: "unreadable",
3970
3963
  file,
3971
3964
  path,
3972
- reason: errorText2(error)
3965
+ reason: errorText(error)
3973
3966
  };
3974
3967
  }
3975
3968
  let parsed;
@@ -4001,7 +3994,7 @@ async function listUniqueErrorFallbackPaths(directories) {
4001
3994
  try {
4002
3995
  names = await readdir3(dir);
4003
3996
  } catch (error) {
4004
- if (isMissingPathError3(error)) continue;
3997
+ if (isMissingPathError(error)) continue;
4005
3998
  throw error;
4006
3999
  }
4007
4000
  for (const name of names.sort((a, b) => a.localeCompare(b))) {
@@ -4081,6 +4074,7 @@ var init_run_terminal_artifacts = __esm({
4081
4074
  "src/run-terminal-artifacts.ts"() {
4082
4075
  "use strict";
4083
4076
  init_role_run_placement();
4077
+ init_unknown_value();
4084
4078
  RUN_TERMINAL_ARTIFACT_FILES = [
4085
4079
  "report.json",
4086
4080
  "error.json",
@@ -4108,17 +4102,13 @@ function failureReason(error) {
4108
4102
  function retainedReceipt(decision) {
4109
4103
  return decision;
4110
4104
  }
4111
- function readRecord(value) {
4112
- if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
4113
- return value;
4114
- }
4115
4105
  function reviewQueueStatus(status) {
4116
4106
  return REVIEW_QUEUE_STATUSES.has(status) ? status : void 0;
4117
4107
  }
4118
4108
  function projectOfficerDecision(officer, decision, fallbackStatus) {
4119
4109
  const receipt = retainedReceipt(decision);
4120
- const record4 = readRecord(decision);
4121
- const status = (record4 !== void 0 && typeof record4.status === "string" ? record4.status : void 0) ?? fallbackStatus;
4110
+ const record = isRecord(decision) ? decision : void 0;
4111
+ const status = (record !== void 0 && typeof record.status === "string" ? record.status : void 0) ?? fallbackStatus;
4122
4112
  const queueStatus = typeof status === "string" ? reviewQueueStatus(status) : void 0;
4123
4113
  if (queueStatus === "converged") {
4124
4114
  return { status: "converged", officer, receipt };
@@ -4272,6 +4262,7 @@ var init_gatekeeper_role = __esm({
4272
4262
  init_review_submission();
4273
4263
  init_gatekeeper_output();
4274
4264
  init_run_terminal_artifacts();
4265
+ init_unknown_value();
4275
4266
  init_submission_errors();
4276
4267
  GATE_OFFICER_BY_SUBJECT = {
4277
4268
  worker_completion: "inspector",
@@ -4420,7 +4411,7 @@ async function readAssistantUsageFromSessionFile(sessionFile) {
4420
4411
  rows = text.trim().split("\n").filter(Boolean).map((line2) => JSON.parse(line2));
4421
4412
  } catch (error) {
4422
4413
  throw new Error(
4423
- `session usage parse failed (${sessionFile}): ${error instanceof Error ? error.message : String(error)}`,
4414
+ `session usage parse failed (${sessionFile}): ${errorText(error)}`,
4424
4415
  { cause: error }
4425
4416
  );
4426
4417
  }
@@ -4496,6 +4487,7 @@ async function usageFromPublicSummon(summoned) {
4496
4487
  var init_session_assistant_usage = __esm({
4497
4488
  "src/session-assistant-usage.ts"() {
4498
4489
  "use strict";
4490
+ init_unknown_value();
4499
4491
  }
4500
4492
  });
4501
4493
 
@@ -4667,6 +4659,7 @@ var USER_DIALOGUE_STDIN_KIND;
4667
4659
  var init_user_dialogue_stdin = __esm({
4668
4660
  "src/user-dialogue-stdin.ts"() {
4669
4661
  "use strict";
4662
+ init_unknown_value();
4670
4663
  USER_DIALOGUE_STDIN_KIND = "ak-user-dialogue";
4671
4664
  }
4672
4665
  });
@@ -4999,7 +4992,7 @@ function hermesProviderModelsCachePath(home) {
4999
4992
  return join16(home, ".hermes", "provider_models_cache.json");
5000
4993
  }
5001
4994
  function parseHostProvidersTable(value) {
5002
- if (value === null || typeof value !== "object" || Array.isArray(value)) {
4995
+ if (!isRecord(value)) {
5003
4996
  throw new Error("host-providers.json must be an object");
5004
4997
  }
5005
4998
  const out = {};
@@ -5007,13 +5000,11 @@ function parseHostProvidersTable(value) {
5007
5000
  if (host.trim() === "") {
5008
5001
  throw new Error("host-providers.json host key must be non-empty");
5009
5002
  }
5010
- if (byProvider === null || typeof byProvider !== "object" || Array.isArray(byProvider)) {
5003
+ if (!isRecord(byProvider)) {
5011
5004
  throw new Error(`host-providers.json[${host}] must be an object`);
5012
5005
  }
5013
5006
  const providers = {};
5014
- for (const [seatProvider, hostProvider] of Object.entries(
5015
- byProvider
5016
- )) {
5007
+ for (const [seatProvider, hostProvider] of Object.entries(byProvider)) {
5017
5008
  if (seatProvider.trim() === "") {
5018
5009
  throw new Error(
5019
5010
  `host-providers.json[${host}] seat-provider key must be non-empty`
@@ -5038,9 +5029,7 @@ function loadHostProvidersTable(home) {
5038
5029
  const raw = readFileSync(path, "utf8");
5039
5030
  return parseHostProvidersTable(JSON.parse(raw));
5040
5031
  } catch (error) {
5041
- if (error instanceof Error && "code" in error && error.code === "ENOENT") {
5042
- return {};
5043
- }
5032
+ if (isEnoent(error)) return {};
5044
5033
  throw error;
5045
5034
  }
5046
5035
  }
@@ -5055,20 +5044,18 @@ function listHermesProvidersForModel(home, seatModel) {
5055
5044
  try {
5056
5045
  text = readFileSync(path, "utf8");
5057
5046
  } catch (error) {
5058
- if (error instanceof Error && "code" in error && error.code === "ENOENT") {
5059
- return [];
5060
- }
5047
+ if (isEnoent(error)) return [];
5061
5048
  throw error;
5062
5049
  }
5063
5050
  const raw = JSON.parse(text);
5064
- if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
5051
+ if (!isRecord(raw)) {
5065
5052
  throw new Error(
5066
5053
  `hermes provider_models_cache.json must be an object: ${path}`
5067
5054
  );
5068
5055
  }
5069
5056
  const found = [];
5070
5057
  for (const [provider, entry] of Object.entries(raw)) {
5071
- if (entry === null || typeof entry !== "object" || Array.isArray(entry)) {
5058
+ if (!isRecord(entry)) {
5072
5059
  continue;
5073
5060
  }
5074
5061
  const models = entry.models;
@@ -5133,6 +5120,7 @@ var HostProviderResolutionError;
5133
5120
  var init_host_providers = __esm({
5134
5121
  "src/public-cli/host-providers.ts"() {
5135
5122
  "use strict";
5123
+ init_unknown_value();
5136
5124
  HostProviderResolutionError = class extends Error {
5137
5125
  host;
5138
5126
  seatProvider;
@@ -5296,9 +5284,6 @@ var init_merger_git_state = __esm({
5296
5284
 
5297
5285
  // src/ledger-session-read.ts
5298
5286
  import { readFile as readFile11 } from "node:fs/promises";
5299
- function isRecord4(value) {
5300
- return typeof value === "object" && value !== null && !Array.isArray(value);
5301
- }
5302
5287
  async function readLedgerSessionJsonlLines(path) {
5303
5288
  const text = await readFile11(path, "utf8");
5304
5289
  const lines = text.split("\n");
@@ -5321,7 +5306,7 @@ async function readLedgerSessionJsonlLines(path) {
5321
5306
  });
5322
5307
  continue;
5323
5308
  }
5324
- if (!isRecord4(row)) {
5309
+ if (!isRecord(row)) {
5325
5310
  const kind = row === null ? "null" : Array.isArray(row) ? "array" : typeof row;
5326
5311
  out.push({
5327
5312
  line: lineNumber,
@@ -5374,7 +5359,7 @@ function extractSessionModelSequence(rows) {
5374
5359
  if (row.type === "model_change" && typeof row.modelId === "string") {
5375
5360
  push(row.modelId);
5376
5361
  }
5377
- const message = isRecord4(row.message) ? row.message : void 0;
5362
+ const message = isRecord(row.message) ? row.message : void 0;
5378
5363
  if (message?.role === "assistant" && typeof message.model === "string") {
5379
5364
  push(message.model);
5380
5365
  }
@@ -5390,11 +5375,11 @@ function extractSessionToolIntervals(rows) {
5390
5375
  const openById = /* @__PURE__ */ new Map();
5391
5376
  for (const row of rows) {
5392
5377
  const rowTimestamp = typeof row.timestamp === "string" ? row.timestamp : void 0;
5393
- const message = isRecord4(row.message) ? row.message : void 0;
5378
+ const message = isRecord(row.message) ? row.message : void 0;
5394
5379
  if (message?.role === "assistant" && Array.isArray(message.content)) {
5395
5380
  const callTimestamp = typeof message.timestamp === "string" && message.timestamp ? message.timestamp : rowTimestamp;
5396
5381
  for (const part of message.content) {
5397
- if (!isRecord4(part) || part.type !== "toolCall") continue;
5382
+ if (!isRecord(part) || part.type !== "toolCall") continue;
5398
5383
  if (typeof part.id !== "string" || part.id.length === 0) {
5399
5384
  throw new Error("toolCall frame missing string id");
5400
5385
  }
@@ -5407,7 +5392,7 @@ function extractSessionToolIntervals(rows) {
5407
5392
  if (openById.has(part.id)) {
5408
5393
  throw new Error(`duplicate toolCall id ${part.id}`);
5409
5394
  }
5410
- const args = isRecord4(part.arguments) ? part.arguments : void 0;
5395
+ const args = isRecord(part.arguments) ? part.arguments : void 0;
5411
5396
  const command = part.name === "bash" && args !== void 0 && typeof args.command === "string" ? bashCommandFirstLine(args.command) : void 0;
5412
5397
  const interval = {
5413
5398
  toolCallId: part.id,
@@ -5475,6 +5460,7 @@ var LedgerSessionJsonlError;
5475
5460
  var init_ledger_session_read = __esm({
5476
5461
  "src/ledger-session-read.ts"() {
5477
5462
  "use strict";
5463
+ init_unknown_value();
5478
5464
  LedgerSessionJsonlError = class extends Error {
5479
5465
  path;
5480
5466
  line;
@@ -5491,9 +5477,6 @@ var init_ledger_session_read = __esm({
5491
5477
  });
5492
5478
 
5493
5479
  // src/session-dialogue.ts
5494
- function isRecord5(value) {
5495
- return typeof value === "object" && value !== null && !Array.isArray(value);
5496
- }
5497
5480
  function nativeEventId(row) {
5498
5481
  for (const key of ["uuid", "id"]) {
5499
5482
  const value = row[key];
@@ -5501,7 +5484,7 @@ function nativeEventId(row) {
5501
5484
  }
5502
5485
  for (const nestKey of ["message", "payload"]) {
5503
5486
  const nested = row[nestKey];
5504
- if (!isRecord5(nested)) continue;
5487
+ if (!isRecord(nested)) continue;
5505
5488
  for (const key of ["uuid", "id"]) {
5506
5489
  const value = nested[key];
5507
5490
  if (typeof value === "string" && value !== "") return value;
@@ -5514,19 +5497,19 @@ function textParts(content) {
5514
5497
  if (!Array.isArray(content)) return [];
5515
5498
  const out = [];
5516
5499
  for (const part of content) {
5517
- if (!isRecord5(part) || !SPEAKER_TEXT_PART_TYPES.has(String(part.type))) continue;
5500
+ if (!isRecord(part) || !SPEAKER_TEXT_PART_TYPES.has(String(part.type))) continue;
5518
5501
  const text = part.text;
5519
5502
  if (typeof text === "string" && text !== "") out.push(text);
5520
5503
  }
5521
5504
  return out;
5522
5505
  }
5523
5506
  function responseItemMessage(row) {
5524
- if (row.type !== "response_item" || !isRecord5(row.payload)) return void 0;
5507
+ if (row.type !== "response_item" || !isRecord(row.payload)) return void 0;
5525
5508
  if (row.payload.type !== "message") return void 0;
5526
5509
  return row.payload;
5527
5510
  }
5528
5511
  function messageBody(row) {
5529
- if (isRecord5(row.message)) return row.message;
5512
+ if (isRecord(row.message)) return row.message;
5530
5513
  return responseItemMessage(row);
5531
5514
  }
5532
5515
  function speakerOf(message) {
@@ -5536,7 +5519,7 @@ function speakerOf(message) {
5536
5519
  }
5537
5520
  function codexContentItemKinds(message) {
5538
5521
  const pass = message.internal_chat_message_metadata_passthrough;
5539
- if (!isRecord5(pass) || !Array.isArray(pass.content_item_kinds)) return void 0;
5522
+ if (!isRecord(pass) || !Array.isArray(pass.content_item_kinds)) return void 0;
5540
5523
  const kinds = [];
5541
5524
  for (const kind of pass.content_item_kinds) {
5542
5525
  if (typeof kind === "string" && kind !== "") kinds.push(kind);
@@ -5565,7 +5548,7 @@ function isFixedNonOwnerEnqueueShape(content) {
5565
5548
  return hasFixedOpenTagPrefix(content, TASK_NOTIFICATION_OPEN_TAG);
5566
5549
  }
5567
5550
  function materializationOriginKind(row) {
5568
- if (!isRecord5(row.origin)) return void 0;
5551
+ if (!isRecord(row.origin)) return void 0;
5569
5552
  const kind = row.origin.kind;
5570
5553
  return typeof kind === "string" && kind !== "" ? kind : void 0;
5571
5554
  }
@@ -5606,6 +5589,7 @@ var SPEAKER_TEXT_PART_TYPES, TASK_NOTIFICATION_OPEN_TAG;
5606
5589
  var init_session_dialogue = __esm({
5607
5590
  "src/session-dialogue.ts"() {
5608
5591
  "use strict";
5592
+ init_unknown_value();
5609
5593
  SPEAKER_TEXT_PART_TYPES = /* @__PURE__ */ new Set(["text", "input_text", "output_text"]);
5610
5594
  TASK_NOTIFICATION_OPEN_TAG = "<task-notification";
5611
5595
  }
@@ -5748,7 +5732,7 @@ async function projectSessionRanges(input) {
5748
5732
  if (error instanceof TicketProvenanceInputError) throw error;
5749
5733
  const code = errnoCode(error);
5750
5734
  if (code === "ENOENT" || code === "ENOTDIR" || code === "EISDIR") {
5751
- const detail = error instanceof Error ? error.message : String(error);
5735
+ const detail = errorText(error);
5752
5736
  throw new TicketProvenanceInputError(
5753
5737
  `session unreadable: ${input.session.path} (${detail})`,
5754
5738
  { cause: error }
@@ -5828,6 +5812,7 @@ var init_ticket_provenance = __esm({
5828
5812
  init_session_dialogue();
5829
5813
  init_sitian_facade();
5830
5814
  init_ticket_provenance_contracts();
5815
+ init_unknown_value();
5831
5816
  TicketProvenanceInputError = class extends Error {
5832
5817
  code = "ticket-provenance-input";
5833
5818
  constructor(message, options) {
@@ -7686,8 +7671,8 @@ function admissionCallerOptions(env) {
7686
7671
  };
7687
7672
  }
7688
7673
  async function admitPublicRole(role, parsed, env, override) {
7689
- const record4 = packagedRoleMetadata(role);
7690
- if (record4 === void 0) {
7674
+ const record = packagedRoleMetadata(role);
7675
+ if (record === void 0) {
7691
7676
  throw new CliUsageError(`unknown role: ${role}`);
7692
7677
  }
7693
7678
  const shared = {
@@ -7697,7 +7682,7 @@ async function admitPublicRole(role, parsed, env, override) {
7697
7682
  const instruction = parsed.instruction ?? "";
7698
7683
  const attachmentPaths = parsed.attachmentPaths ?? [];
7699
7684
  const project = parsed.project === void 0 ? {} : { project: parsed.project };
7700
- switch (record4.admission) {
7685
+ switch (record.admission) {
7701
7686
  case "instruction":
7702
7687
  return admitStandardMaterialInvocation(
7703
7688
  role,
@@ -7721,7 +7706,7 @@ async function admitPublicRole(role, parsed, env, override) {
7721
7706
  throw new CliUsageError("coder requires a nonblank task instruction");
7722
7707
  }
7723
7708
  const phase = parsed.phase ?? "apply";
7724
- if (!record4.phases.some((item) => item === phase)) {
7709
+ if (!record.phases.some((item) => item === phase)) {
7725
7710
  throw new CliUsageError("coder phase must be plan or apply");
7726
7711
  }
7727
7712
  return admitStandardMaterialInvocation("coder", {
@@ -7741,7 +7726,7 @@ async function admitPublicRole(role, parsed, env, override) {
7741
7726
  throw new CliUsageError("fixer requires a nonblank repair instruction");
7742
7727
  }
7743
7728
  const phase = parsed.phase ?? "apply";
7744
- if (!record4.phases.some((item) => item === phase)) {
7729
+ if (!record.phases.some((item) => item === phase)) {
7745
7730
  throw new CliUsageError("fixer phase must be plan or apply");
7746
7731
  }
7747
7732
  let prerequisites = Object.freeze([]);
@@ -7800,7 +7785,7 @@ async function admitPublicRole(role, parsed, env, override) {
7800
7785
  try {
7801
7786
  repository = parseCollectorRepository(parsed.repo);
7802
7787
  } catch (error) {
7803
- const detail = error instanceof Error ? error.message : String(error);
7788
+ const detail = errorText(error);
7804
7789
  throw new CliUsageError(detail, { cause: error });
7805
7790
  }
7806
7791
  } else {
@@ -7814,7 +7799,7 @@ async function admitPublicRole(role, parsed, env, override) {
7814
7799
  manifestCanonicalJson = manifest.canonicalJson;
7815
7800
  } catch (error) {
7816
7801
  throw new CliUsageError(
7817
- error instanceof Error ? error.message : String(error),
7802
+ errorText(error),
7818
7803
  { cause: error }
7819
7804
  );
7820
7805
  }
@@ -7868,7 +7853,7 @@ async function admitPublicRole(role, parsed, env, override) {
7868
7853
  });
7869
7854
  } catch (error) {
7870
7855
  if (error instanceof CliUsageError) throw error;
7871
- const detail = error instanceof Error ? error.message : String(error);
7856
+ const detail = errorText(error);
7872
7857
  throw new CliUsageError(detail, { cause: error });
7873
7858
  }
7874
7859
  if (parsed.runs === void 0) {
@@ -7886,7 +7871,7 @@ async function admitPublicRole(role, parsed, env, override) {
7886
7871
  caseRunsPath = await realpath4(caseRunsPath);
7887
7872
  } catch (error) {
7888
7873
  if (error instanceof CliUsageError) throw error;
7889
- const detail = error instanceof Error ? error.message : String(error);
7874
+ const detail = errorText(error);
7890
7875
  throw new CliUsageError(
7891
7876
  `doctor case could not be constructed from retained evidence: ${detail}`,
7892
7877
  { cause: error }
@@ -8154,8 +8139,8 @@ async function admitStandardMaterialInvocation(role, options) {
8154
8139
  }
8155
8140
  function admittedTransportPromptKind(admitted) {
8156
8141
  if (admitted.role === void 0) return "instruction";
8157
- const record4 = packagedRoleMetadata(admitted.role);
8158
- if (record4 !== void 0 && "transportPrompt" in record4) return record4.transportPrompt;
8142
+ const record = packagedRoleMetadata(admitted.role);
8143
+ if (record !== void 0 && "transportPrompt" in record) return record.transportPrompt;
8159
8144
  return "instruction";
8160
8145
  }
8161
8146
  function buildInstructionTransportPrompt(admitted, engineMaterial) {
@@ -8242,16 +8227,16 @@ async function loadAdmittedJudgeRequest(runDirectory) {
8242
8227
  const raw = JSON.parse(
8243
8228
  await readFile13(join19(runDirectory, "admitted-request.json"), "utf8")
8244
8229
  );
8245
- if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return void 0;
8246
- const record4 = raw;
8247
- if (!packagedPublicInstructionSubject(record4.role)) return void 0;
8248
- if (typeof record4.instruction !== "string") return void 0;
8249
- if (typeof record4.instructionEmpty !== "boolean") return void 0;
8250
- if (!Array.isArray(record4.attachments)) return void 0;
8230
+ if (!isRecord(raw)) return void 0;
8231
+ const record = raw;
8232
+ if (!packagedPublicInstructionSubject(record.role)) return void 0;
8233
+ if (typeof record.instruction !== "string") return void 0;
8234
+ if (typeof record.instructionEmpty !== "boolean") return void 0;
8235
+ if (!Array.isArray(record.attachments)) return void 0;
8251
8236
  return {
8252
- instruction: record4.instruction,
8253
- instructionEmpty: record4.instructionEmpty,
8254
- attachments: record4.attachments
8237
+ instruction: record.instruction,
8238
+ instructionEmpty: record.instructionEmpty,
8239
+ attachments: record.attachments
8255
8240
  };
8256
8241
  } catch {
8257
8242
  return void 0;
@@ -8269,7 +8254,7 @@ function parsePositivePrOption(raw) {
8269
8254
  try {
8270
8255
  return parseCollectorPrNumber(raw);
8271
8256
  } catch (error) {
8272
- throw new CliUsageError(error instanceof Error ? error.message : String(error), { cause: error });
8257
+ throw new CliUsageError(errorText(error), { cause: error });
8273
8258
  }
8274
8259
  }
8275
8260
  function parseRepoOption(raw) {
@@ -8309,7 +8294,7 @@ function resolveGitHubRemoteRepository(projectRoot) {
8309
8294
  try {
8310
8295
  return parseCollectorRepository(ownerRepo);
8311
8296
  } catch (error) {
8312
- const detail = error instanceof Error ? error.message : String(error);
8297
+ const detail = errorText(error);
8313
8298
  throw new CliUsageError(detail, { cause: error });
8314
8299
  }
8315
8300
  }
@@ -8356,7 +8341,7 @@ async function resolveDoctorCaseRunsPath(options) {
8356
8341
  try {
8357
8342
  real = await realpath4(resolved);
8358
8343
  } catch (error) {
8359
- const detail = error instanceof Error ? error.message : String(error);
8344
+ const detail = errorText(error);
8360
8345
  throw new CliUsageError(
8361
8346
  `doctor --runs is not a readable retained runs root: ${detail}`,
8362
8347
  { cause: error }
@@ -8642,6 +8627,7 @@ var init_invocation = __esm({
8642
8627
  init_engine_material();
8643
8628
  init_cli_errors();
8644
8629
  init_option_definitions();
8630
+ init_unknown_value();
8645
8631
  DOCTOR_ISSUE_NUMBER_PATTERN = /^[1-9]\d*$/;
8646
8632
  DOCTOR_CASE_RUNS_PATH_PATTERN = /\/\.ak-roles\/books\/[^/]+\/(?:issues\/)?([1-9]\d*)\/runs$/;
8647
8633
  ANALYST_TICKET_NUMBER_PATTERN = /^[1-9]\d*$/;
@@ -8852,18 +8838,12 @@ var init_role_seat_runtime = __esm({
8852
8838
  // src/analyst-gate-cycles-read.ts
8853
8839
  import { readdir as readdir4 } from "node:fs/promises";
8854
8840
  import { join as join22 } from "node:path";
8855
- function isRecord6(value) {
8856
- return typeof value === "object" && value !== null && !Array.isArray(value);
8857
- }
8858
8841
  function isParentAttemptBindingRow(row) {
8859
8842
  return row.type === "custom" && row.customType === AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE;
8860
8843
  }
8861
8844
  function intervalRowsForGateCall(rows, callRowIndex) {
8862
8845
  return intervalRowsAroundAnchor(rows, callRowIndex, isParentAttemptBindingRow).rows;
8863
8846
  }
8864
- function isMissingDirectoryError(error) {
8865
- return error instanceof Error && "code" in error && error.code === "ENOENT";
8866
- }
8867
8847
  function normalizeOfficerArg(raw) {
8868
8848
  if (typeof raw !== "string") return void 0;
8869
8849
  return OFFICER_ARG_ALIASES[raw.trim()];
@@ -8882,7 +8862,7 @@ function isGateTerminatingToolName(toolName) {
8882
8862
  function acceptedGateReceiptIds(rows) {
8883
8863
  const accepted = /* @__PURE__ */ new Set();
8884
8864
  for (const row of rows) {
8885
- const message = isRecord6(row.message) ? row.message : void 0;
8865
+ const message = isRecord(row.message) ? row.message : void 0;
8886
8866
  if (message?.role !== "toolResult") continue;
8887
8867
  if (typeof message.toolCallId !== "string" || message.toolCallId.length === 0) continue;
8888
8868
  if (message.isError === false) accepted.add(message.toolCallId);
@@ -8917,7 +8897,7 @@ function nearestAttemptBindingBefore(rows, beforeIndex) {
8917
8897
  for (let i = beforeIndex - 1; i >= 0; i -= 1) {
8918
8898
  const row = rows[i];
8919
8899
  if (!isParentAttemptBindingRow(row)) continue;
8920
- if (!isRecord6(row.data) || !isRecord6(row.data.parent)) continue;
8900
+ if (!isRecord(row.data) || !isRecord(row.data.parent)) continue;
8921
8901
  const id = row.data.parent.attemptEntryId;
8922
8902
  const sessionFile = row.data.parent.sessionFile;
8923
8903
  return {
@@ -8932,10 +8912,10 @@ function extractAllAcceptedGateToolCalls(rows) {
8932
8912
  const out = [];
8933
8913
  for (let rowIndex = 0; rowIndex < rows.length; rowIndex += 1) {
8934
8914
  const row = rows[rowIndex];
8935
- const message = isRecord6(row.message) ? row.message : void 0;
8915
+ const message = isRecord(row.message) ? row.message : void 0;
8936
8916
  if (message?.role !== "assistant" || !Array.isArray(message.content)) continue;
8937
8917
  for (const part of message.content) {
8938
- if (!isRecord6(part) || part.type !== "toolCall") continue;
8918
+ if (!isRecord(part) || part.type !== "toolCall") continue;
8939
8919
  if (typeof part.id !== "string" || part.id.length === 0) continue;
8940
8920
  if (typeof part.name !== "string" || part.name.length === 0) continue;
8941
8921
  if (!isGateTerminatingToolName(part.name)) continue;
@@ -8943,7 +8923,7 @@ function extractAllAcceptedGateToolCalls(rows) {
8943
8923
  const binding = nearestAttemptBindingBefore(rows, rowIndex);
8944
8924
  out.push({
8945
8925
  toolName: part.name,
8946
- args: isRecord6(part.arguments) ? part.arguments : void 0,
8926
+ args: isRecord(part.arguments) ? part.arguments : void 0,
8947
8927
  accepted: true,
8948
8928
  rowIndex,
8949
8929
  ...binding
@@ -9072,11 +9052,11 @@ async function resolveOfficerSessionFromPointerFile(pointerPath) {
9072
9052
  raw = JSON.parse(await readFile25(pointerPath, "utf8"));
9073
9053
  } catch (error) {
9074
9054
  throw new Error(
9075
- `direct officer run pointer unreadable in ${pointerPath}: ${error instanceof Error ? error.message : String(error)}`,
9055
+ `direct officer run pointer unreadable in ${pointerPath}: ${errorText(error)}`,
9076
9056
  { cause: error }
9077
9057
  );
9078
9058
  }
9079
- if (!isRecord6(raw) || raw.kind !== "direct-officer-run-pointer" || raw.version !== 1) {
9059
+ if (!isRecord(raw) || raw.kind !== "direct-officer-run-pointer" || raw.version !== 1) {
9080
9060
  throw new Error(`direct officer run pointer has unknown shape in ${pointerPath}`);
9081
9061
  }
9082
9062
  const sessionFile = raw.sessionFile;
@@ -9098,7 +9078,7 @@ async function readAnalystGateCyclesFromAuditorRoles(auditorRolesDirectory, opti
9098
9078
  (e) => e.isFile() && (e.name.endsWith(".jsonl") || e.name.endsWith(".pointer.json"))
9099
9079
  ).map((e) => e.name).sort();
9100
9080
  } catch (error) {
9101
- if (isMissingDirectoryError(error)) continue;
9081
+ if (isEnoent(error)) continue;
9102
9082
  throw error;
9103
9083
  }
9104
9084
  for (const name of names) {
@@ -9127,6 +9107,7 @@ var init_analyst_gate_cycles_read = __esm({
9127
9107
  "use strict";
9128
9108
  init_compliance_transport();
9129
9109
  init_ledger_session_read();
9110
+ init_unknown_value();
9130
9111
  DISPATCH_TOOLS = /* @__PURE__ */ new Set(["ak_menxia_output", "ak_gatekeeper_output"]);
9131
9112
  OFFICER_TOOL_TO_FACE = {
9132
9113
  ak_jishizhong_output: "inspector",
@@ -9185,7 +9166,7 @@ async function readOwnedSubmissionRecords(cwd, runId, scope = {}) {
9185
9166
  return {
9186
9167
  file,
9187
9168
  owned: records.filter(
9188
- (record4) => typeof record4.subject === "object" && record4.subject !== null && record4.subject.runId === runId
9169
+ (record) => typeof record.subject === "object" && record.subject !== null && record.subject.runId === runId
9189
9170
  )
9190
9171
  };
9191
9172
  }
@@ -9198,24 +9179,24 @@ function recordsForAttempt(owned, attemptId) {
9198
9179
  void attemptId;
9199
9180
  return owned;
9200
9181
  }
9201
- function recordAttemptId(record4) {
9202
- if (typeof record4.subject === "object" && record4.subject !== null) {
9203
- const fromSubject = record4.subject.attemptId;
9182
+ function recordAttemptId(record) {
9183
+ if (typeof record.subject === "object" && record.subject !== null) {
9184
+ const fromSubject = record.subject.attemptId;
9204
9185
  if (typeof fromSubject === "string" && fromSubject.length > 0) return fromSubject;
9205
9186
  }
9206
- if (typeof record4.payload === "object" && record4.payload !== null) {
9207
- const fromPayload = record4.payload.attemptId;
9187
+ if (typeof record.payload === "object" && record.payload !== null) {
9188
+ const fromPayload = record.payload.attemptId;
9208
9189
  if (typeof fromPayload === "string" && fromPayload.length > 0) return fromPayload;
9209
9190
  }
9210
9191
  return void 0;
9211
9192
  }
9212
9193
  async function hasFreshAttemptSubmission(cwd, runId, attemptId, homeOrScope) {
9213
9194
  const { owned } = await readOwnedSubmissionRecords(cwd, runId, resolveReadScope(homeOrScope));
9214
- return owned.some((record4) => {
9215
- if (recordAttemptId(record4) !== attemptId) return false;
9216
- if (record4.kind === "sealed") return true;
9217
- if (record4.kind === "outcome") {
9218
- const payload = record4.payload;
9195
+ return owned.some((record) => {
9196
+ if (recordAttemptId(record) !== attemptId) return false;
9197
+ if (record.kind === "sealed") return true;
9198
+ if (record.kind === "outcome") {
9199
+ const payload = record.payload;
9219
9200
  return payload?.type === "outcome" && payload.outcome === "audit-escalation";
9220
9201
  }
9221
9202
  return false;
@@ -9261,12 +9242,12 @@ function mapOwnedToSubmissionRows(owned) {
9261
9242
  const out = [];
9262
9243
  const indexByCall = /* @__PURE__ */ new Map();
9263
9244
  const roleByCall = /* @__PURE__ */ new Map();
9264
- for (const record4 of scoped) {
9265
- const payload = record4.payload;
9245
+ for (const record of scoped) {
9246
+ const payload = record.payload;
9266
9247
  if (typeof payload?.toolCallId !== "string" || payload.toolCallId.length === 0) continue;
9267
9248
  const role = recordedRole(payload);
9268
9249
  if (role !== void 0) {
9269
- roleByCall.set(submissionCallKey(recordAttemptId(record4), payload.toolCallId), role);
9250
+ roleByCall.set(submissionCallKey(recordAttemptId(record), payload.toolCallId), role);
9270
9251
  }
9271
9252
  }
9272
9253
  const take = (row, callKey) => {
@@ -9291,26 +9272,26 @@ function mapOwnedToSubmissionRows(owned) {
9291
9272
  }
9292
9273
  out.push(row);
9293
9274
  };
9294
- for (const record4 of scoped) {
9295
- const attemptId = recordAttemptId(record4);
9296
- if (record4.kind === "candidate") {
9297
- const payload2 = record4.payload;
9275
+ for (const record of scoped) {
9276
+ const attemptId = recordAttemptId(record);
9277
+ if (record.kind === "candidate") {
9278
+ const payload2 = record.payload;
9298
9279
  if (payload2?.type !== "candidate" || payload2.params === void 0) continue;
9299
9280
  const callKey2 = typeof payload2.toolCallId === "string" ? submissionCallKey(attemptId, payload2.toolCallId) : void 0;
9300
9281
  const fallback2 = callKey2 !== void 0 ? roleByCall.get(callKey2) : void 0;
9301
9282
  take(rowFromPayload("candidate", payload2, payload2.params, fallback2), callKey2);
9302
9283
  continue;
9303
9284
  }
9304
- if (record4.kind === "sealed") {
9305
- const payload2 = record4.payload;
9285
+ if (record.kind === "sealed") {
9286
+ const payload2 = record.payload;
9306
9287
  if (payload2?.type !== "sealed" || payload2.accepted === void 0) continue;
9307
9288
  const callKey2 = typeof payload2.toolCallId === "string" ? submissionCallKey(attemptId, payload2.toolCallId) : void 0;
9308
9289
  const fallback2 = callKey2 !== void 0 ? roleByCall.get(callKey2) : void 0;
9309
9290
  take(rowFromPayload("accepted", payload2, payload2.accepted, fallback2), callKey2);
9310
9291
  continue;
9311
9292
  }
9312
- if (record4.kind !== "outcome") continue;
9313
- const payload = record4.payload;
9293
+ if (record.kind !== "outcome") continue;
9294
+ const payload = record.payload;
9314
9295
  if (payload?.type !== "outcome" || payload.accepted === void 0) continue;
9315
9296
  const outcome = payload.outcome;
9316
9297
  const kind = outcome === "audit-escalation" ? "audit-escalation" : outcome === "correctable-rejection" ? "correctable-rejection" : outcome === "infrastructure" ? "infrastructure" : void 0;
@@ -9334,7 +9315,7 @@ async function readAttemptScopedSubmissionRows(cwd, runId, attemptId, home) {
9334
9315
  runId,
9335
9316
  home === void 0 ? {} : { home }
9336
9317
  );
9337
- return mapOwnedToSubmissionRows(owned.filter((record4) => recordAttemptId(record4) === attemptId));
9318
+ return mapOwnedToSubmissionRows(owned.filter((record) => recordAttemptId(record) === attemptId));
9338
9319
  }
9339
9320
  async function readRecordedSubmissions(cwd, runId, homeOrScope) {
9340
9321
  return (await readRecordedSubmissionRows(cwd, runId, homeOrScope)).map((row) => row.accepted);
@@ -9351,8 +9332,8 @@ async function restoreState(cwd, runId, scope) {
9351
9332
  }
9352
9333
  const { owned } = located;
9353
9334
  return {
9354
- sequence: owned.reduce((maximum, record4) => {
9355
- const payload = record4.payload;
9335
+ sequence: owned.reduce((maximum, record) => {
9336
+ const payload = record.payload;
9356
9337
  return payload?.type === "candidate" && typeof payload.sequence === "number" ? Math.max(maximum, payload.sequence) : maximum;
9357
9338
  }, 0)
9358
9339
  };
@@ -9467,7 +9448,7 @@ function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (er
9467
9448
  });
9468
9449
  let result;
9469
9450
  try {
9470
- const reviewEscalate = tool.name === REVIEW_SUBMISSION_OUTPUT_TOOL_NAME && infrastructureFailureDiagnostic(params) !== void 0 && params !== null && typeof params === "object" && !Array.isArray(params) && params.status === "escalate";
9451
+ const reviewEscalate = tool.name === REVIEW_SUBMISSION_OUTPUT_TOOL_NAME && infrastructureFailureDiagnostic(params) !== void 0 && isRecord(params) && params.status === "escalate";
9471
9452
  if (!reviewEscalate) {
9472
9453
  failOnInfrastructureFailureDeclaration(
9473
9454
  params,
@@ -9490,7 +9471,7 @@ function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (er
9490
9471
  toolCallId,
9491
9472
  outcome: "correctable-rejection",
9492
9473
  code: "typed-bounce",
9493
- diagnostic: error instanceof Error ? error.message : String(error),
9474
+ diagnostic: errorText(error),
9494
9475
  role,
9495
9476
  accepted: params
9496
9477
  });
@@ -9501,7 +9482,7 @@ function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (er
9501
9482
  attemptId,
9502
9483
  toolCallId,
9503
9484
  outcome: "infrastructure",
9504
- diagnostic: error instanceof Error ? error.message : String(error),
9485
+ diagnostic: errorText(error),
9505
9486
  role,
9506
9487
  accepted: params
9507
9488
  });
@@ -9539,6 +9520,7 @@ var init_submission_ledger = __esm({
9539
9520
  init_submission_correctable_error();
9540
9521
  init_terminating_infrastructure();
9541
9522
  init_review_submission();
9523
+ init_unknown_value();
9542
9524
  }
9543
9525
  });
9544
9526
 
@@ -9546,6 +9528,7 @@ var init_submission_ledger = __esm({
9546
9528
  var init_audit_escalation = __esm({
9547
9529
  "src/audit-escalation.ts"() {
9548
9530
  "use strict";
9531
+ init_unknown_value();
9549
9532
  }
9550
9533
  });
9551
9534
 
@@ -9598,7 +9581,7 @@ var init_session_opening_materials = __esm({
9598
9581
  packageRootUrl = pathToFileURL3(resolvePackageRootDir() + "/").href;
9599
9582
  MAIN_ROLE_SESSION_MATERIALS = {
9600
9583
  ...Object.fromEntries(
9601
- PUBLIC_ROLE_RECORDS.map((record4) => [record4.role, record4.sessionMaterials])
9584
+ PUBLIC_ROLE_RECORDS.map((record) => [record.role, record.sessionMaterials])
9602
9585
  )
9603
9586
  };
9604
9587
  GATEKEEPER_SESSION_MATERIALS = {
@@ -9673,17 +9656,18 @@ async function readAuditorResumeBinding(runDirectory) {
9673
9656
  if (error.code === "ENOENT") return void 0;
9674
9657
  throw error;
9675
9658
  }
9676
- if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return void 0;
9677
- const record4 = raw;
9678
- if (typeof record4.sourceRunPath !== "string" || record4.sourceRunPath.trim() === "") return void 0;
9679
- const subject = isAuditorSoulRole(record4.auditorSubject) ? record4.auditorSubject : subjectFromSourceDirectory(record4.sourceRunPath);
9659
+ if (!isRecord(raw)) return void 0;
9660
+ const record = raw;
9661
+ if (typeof record.sourceRunPath !== "string" || record.sourceRunPath.trim() === "") return void 0;
9662
+ const subject = isAuditorSoulRole(record.auditorSubject) ? record.auditorSubject : subjectFromSourceDirectory(record.sourceRunPath);
9680
9663
  if (subject === void 0) return void 0;
9681
- return { subject, sourceRunDirectory: record4.sourceRunPath };
9664
+ return { subject, sourceRunDirectory: record.sourceRunPath };
9682
9665
  }
9683
9666
  var AUDITOR_SOUL_ROLES, AK_ROLE_AUDITOR_SUBJECT_ENV, AK_ROLE_AUDITOR_SOURCE_RUN_ENV, AUDITOR_SESSION_MATERIALS;
9684
9667
  var init_auditor_soul = __esm({
9685
9668
  "src/auditor-soul.ts"() {
9686
9669
  "use strict";
9670
+ init_unknown_value();
9687
9671
  init_session_opening_materials();
9688
9672
  AUDITOR_SOUL_ROLES = [
9689
9673
  "judge",
@@ -9834,11 +9818,8 @@ function reportEngineDetourCall(input) {
9834
9818
  recordPointer: pointer
9835
9819
  };
9836
9820
  }
9837
- function isRecord7(value) {
9838
- return typeof value === "object" && value !== null && !Array.isArray(value);
9839
- }
9840
9821
  function callFactFromSitianPayload(payload, pointer) {
9841
- if (!isRecord7(payload)) return void 0;
9822
+ if (!isRecord(payload)) return void 0;
9842
9823
  if (payload.tool !== ENGINE_DETOUR_TOOL_NAME) return void 0;
9843
9824
  if (typeof payload.toolCallId !== "string" || payload.toolCallId.length === 0) {
9844
9825
  return void 0;
@@ -9854,13 +9835,13 @@ function callFactFromSitianPayload(payload, pointer) {
9854
9835
  recordPointer: pointer
9855
9836
  };
9856
9837
  }
9857
- function invocationScopeIdOfRecord(record4) {
9858
- if (isRecord7(record4.subject)) {
9859
- const fromSubject = record4.subject.invocationScopeId;
9838
+ function invocationScopeIdOfRecord(record) {
9839
+ if (isRecord(record.subject)) {
9840
+ const fromSubject = record.subject.invocationScopeId;
9860
9841
  if (typeof fromSubject === "string" && fromSubject.length > 0) return fromSubject;
9861
9842
  }
9862
- if (isRecord7(record4.payload)) {
9863
- const fromPayload = record4.payload.invocationScopeId;
9843
+ if (isRecord(record.payload)) {
9844
+ const fromPayload = record.payload.invocationScopeId;
9864
9845
  if (typeof fromPayload === "string" && fromPayload.length > 0) return fromPayload;
9865
9846
  }
9866
9847
  return void 0;
@@ -9876,21 +9857,21 @@ async function readEngineDetourToolUsage(input) {
9876
9857
  });
9877
9858
  const { records } = await readSitianRecords(recordFile);
9878
9859
  const callsByToolCallId = /* @__PURE__ */ new Map();
9879
- for (const record4 of records) {
9880
- if (record4.kind !== ENGINE_DETOUR_CALL_KIND) continue;
9881
- const boundScope = invocationScopeIdOfRecord(record4);
9860
+ for (const record of records) {
9861
+ if (record.kind !== ENGINE_DETOUR_CALL_KIND) continue;
9862
+ const boundScope = invocationScopeIdOfRecord(record);
9882
9863
  if (input.invocationScopeId !== void 0 && input.invocationScopeId.length > 0) {
9883
9864
  if (boundScope !== input.invocationScopeId) continue;
9884
9865
  } else if (boundScope !== void 0) {
9885
9866
  continue;
9886
9867
  }
9887
9868
  const pointer = {
9888
- identity: record4.identity,
9869
+ identity: record.identity,
9889
9870
  recordFile,
9890
- kind: record4.kind,
9891
- level: record4.level
9871
+ kind: record.kind,
9872
+ level: record.level
9892
9873
  };
9893
- const fact = callFactFromSitianPayload(record4.payload, pointer);
9874
+ const fact = callFactFromSitianPayload(record.payload, pointer);
9894
9875
  if (fact === void 0) continue;
9895
9876
  callsByToolCallId.set(fact.toolCallId, fact);
9896
9877
  }
@@ -9920,7 +9901,7 @@ function readInvocationRecord(runDirectory) {
9920
9901
  const raw = JSON.parse(
9921
9902
  readFileSync2(join26(runDirectory, "invocation.json"), "utf8")
9922
9903
  );
9923
- return isRecord7(raw) ? raw : void 0;
9904
+ return isRecord(raw) ? raw : void 0;
9924
9905
  } catch (error) {
9925
9906
  if (error?.code === "ENOENT") return void 0;
9926
9907
  throw error;
@@ -9933,7 +9914,7 @@ async function readInvocationEngineMounted(runDirectory) {
9933
9914
  }
9934
9915
  function withEngineDetourToolUsageFact(outcome, usage) {
9935
9916
  if (usage === void 0) return outcome;
9936
- const prior = isRecord7(outcome.decisiveFacts) ? outcome.decisiveFacts : {};
9917
+ const prior = isRecord(outcome.decisiveFacts) ? outcome.decisiveFacts : {};
9937
9918
  return {
9938
9919
  ...outcome,
9939
9920
  decisiveFacts: {
@@ -9968,6 +9949,7 @@ var init_engine_detour_usage = __esm({
9968
9949
  "use strict";
9969
9950
  init_engine_detour();
9970
9951
  init_sitian_facade();
9952
+ init_unknown_value();
9971
9953
  ENGINE_DETOUR_CALL_KIND = "engine-detour-call";
9972
9954
  ENGINE_DETOUR_TOOL_USAGE_FACT_KEY = "engineDetourToolUsage";
9973
9955
  ENGINE_DETOUR_CALL_RECORD_FILE_RELATIVE = `session/${ENGINE_DETOUR_CALL_KIND}/records.jsonl`;
@@ -10003,13 +9985,10 @@ function resolveAuditDossier(source) {
10003
9985
  }
10004
9986
  return { status: "ok", runDirectory };
10005
9987
  }
10006
- function isRecord8(value) {
10007
- return typeof value === "object" && value !== null && !Array.isArray(value);
10008
- }
10009
9988
  function readDoctorAuditSubjects(context) {
10010
9989
  const entries = context.sessionManager.getEntries?.() ?? [];
10011
9990
  for (const entry of entries) {
10012
- if (isRecord8(entry) && entry.type === "custom" && entry.customType === DOCTOR_CANDIDATE_ENTRY_TYPE) {
9991
+ if (isRecord(entry) && entry.type === "custom" && entry.customType === DOCTOR_CANDIDATE_ENTRY_TYPE) {
10013
9992
  return { status: "ok" };
10014
9993
  }
10015
9994
  }
@@ -10025,6 +10004,7 @@ var init_dossier_resolution = __esm({
10025
10004
  "src/dossier-resolution.ts"() {
10026
10005
  "use strict";
10027
10006
  init_host_contracts();
10007
+ init_unknown_value();
10028
10008
  AUDIT_RUN_DIR_ENV = "AK_ROLE_RUN_DIR";
10029
10009
  DOCTOR_CANDIDATE_ENTRY_TYPE = "ak_doctor_audit_candidate";
10030
10010
  AuditMaterialsUnavailableError = class extends Error {
@@ -10042,11 +10022,8 @@ var init_dossier_resolution = __esm({
10042
10022
  });
10043
10023
 
10044
10024
  // src/receipt-delivery-policy.ts
10045
- function isRecord9(value) {
10046
- return typeof value === "object" && value !== null && !Array.isArray(value);
10047
- }
10048
10025
  function parseNoReceiptLifecycleFacts(input) {
10049
- if (!isRecord9(input) || typeof input.terminalToolCalled !== "boolean" || input.deliveryTurns !== RECEIPT_DELIVERY_TURN_LIMIT || input.sessionCompletion !== "settled-without-accepted-receipt" || input.acceptedReceipt !== false || typeof input.runPointer !== "string" || input.runPointer.trim() === "" || typeof input.attemptPointer !== "string" || input.attemptPointer.trim() === "" || !Array.isArray(input.rejectedReceipts) || !input.rejectedReceipts.every((item) => isRecord9(item) && typeof item.reason === "string")) {
10026
+ if (!isRecord(input) || typeof input.terminalToolCalled !== "boolean" || input.deliveryTurns !== RECEIPT_DELIVERY_TURN_LIMIT || input.sessionCompletion !== "settled-without-accepted-receipt" || input.acceptedReceipt !== false || typeof input.runPointer !== "string" || input.runPointer.trim() === "" || typeof input.attemptPointer !== "string" || input.attemptPointer.trim() === "" || !Array.isArray(input.rejectedReceipts) || !input.rejectedReceipts.every((item) => isRecord(item) && typeof item.reason === "string")) {
10050
10027
  throw new TypeError("malformed no-receipt lifecycle facts");
10051
10028
  }
10052
10029
  return {
@@ -10133,6 +10110,7 @@ var RECEIPT_DELIVERY_TURN_LIMIT, NO_RECEIPT_LIFECYCLE_ENTRY_TYPE;
10133
10110
  var init_receipt_delivery_policy = __esm({
10134
10111
  "src/receipt-delivery-policy.ts"() {
10135
10112
  "use strict";
10113
+ init_unknown_value();
10136
10114
  RECEIPT_DELIVERY_TURN_LIMIT = 2;
10137
10115
  NO_RECEIPT_LIFECYCLE_ENTRY_TYPE = "ak-no-receipt-lifecycle";
10138
10116
  }
@@ -10366,7 +10344,7 @@ async function inspectJudgeSession(sessionFile) {
10366
10344
  await readFile16(sessionFile, "utf8");
10367
10345
  return { state: "present" };
10368
10346
  } catch (error) {
10369
- if (isMissingPathError4(error)) return { state: "missing" };
10347
+ if (isEnoent(error)) return { state: "missing" };
10370
10348
  return {
10371
10349
  state: "unreadable",
10372
10350
  diagnostic: error instanceof Error ? error.message || error.name : String(error)
@@ -10571,12 +10549,6 @@ function explicitInternalKnownFailureClassificationInput(failure) {
10571
10549
  ...failure.details === void 0 ? {} : { knownDetails: failure.details }
10572
10550
  };
10573
10551
  }
10574
- function isMissingPathError4(error) {
10575
- return error instanceof Error && "code" in error && error.code === "ENOENT";
10576
- }
10577
- function isAbsentFacePathError(error) {
10578
- return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
10579
- }
10580
10552
  function sessionReadFailure(error, fallbackMessage) {
10581
10553
  if (error instanceof SyntaxError) {
10582
10554
  const failed2 = new SyntaxError(
@@ -10669,7 +10641,7 @@ async function readSitianRetainedAuditorProviderStop(sessionFile) {
10669
10641
  const { records } = await readSitianRecords(recordFile);
10670
10642
  for (let i = records.length - 1; i >= 0; i -= 1) {
10671
10643
  const payload = records[i]?.payload;
10672
- if (!isRecord10(payload) || !isRecord10(payload.response)) continue;
10644
+ if (!isRecord(payload) || !isRecord(payload.response)) continue;
10673
10645
  if (typeof payload.type === "string") continue;
10674
10646
  const stop = sessionProviderStopFromAssistant(payload.response);
10675
10647
  if (stop !== void 0) return stop;
@@ -10694,7 +10666,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
10694
10666
  try {
10695
10667
  parentEntries = await readBoundSessionEntries(sessionFile);
10696
10668
  } catch (error) {
10697
- if (isMissingPathError4(error)) return void 0;
10669
+ if (isEnoent(error)) return void 0;
10698
10670
  throw sessionReadFailure(error, "failed to read parent session for auditor binding");
10699
10671
  }
10700
10672
  const parentId = parentEntries.find((entry) => entry.type === "session")?.id;
@@ -10708,7 +10680,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
10708
10680
  names = await readdir5(childDirectory);
10709
10681
  sawAnyDirectory = true;
10710
10682
  } catch (error) {
10711
- if (isMissingPathError4(error)) continue;
10683
+ if (isEnoent(error)) continue;
10712
10684
  throw sessionReadFailure(error, "failed to read bound auditor session directory");
10713
10685
  }
10714
10686
  for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
@@ -10719,7 +10691,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
10719
10691
  throw sessionReadFailure(error, "failed to read discovered auditor session");
10720
10692
  }
10721
10693
  const header = entries.find((entry) => entry.type === "session");
10722
- if (!isRecord10(header)) continue;
10694
+ if (!isRecord(header)) continue;
10723
10695
  const bindingIndexes = [];
10724
10696
  for (let i = 0; i < entries.length; i += 1) {
10725
10697
  const entry = entries[i];
@@ -10733,7 +10705,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
10733
10705
  end: idx + 1 < bindingIndexes.length ? bindingIndexes[idx + 1] : entries.length
10734
10706
  })) : [{ entry: void 0, start: 0, end: entries.length }];
10735
10707
  for (const { entry: bindingEntry, start, end } of bindingPasses) {
10736
- const bindingParent = bindingEntry !== void 0 && isRecord10(bindingEntry.data) && isRecord10(bindingEntry.data.parent) ? bindingEntry.data.parent : void 0;
10708
+ const bindingParent = bindingEntry !== void 0 && isRecord(bindingEntry.data) && isRecord(bindingEntry.data.parent) ? bindingEntry.data.parent : void 0;
10737
10709
  const attemptEntryId = typeof bindingParent?.attemptEntryId === "string" ? bindingParent.attemptEntryId : void 0;
10738
10710
  const boundSessionFile = typeof bindingParent?.sessionFile === "string" ? bindingParent.sessionFile : typeof header.parentSession === "string" ? header.parentSession : void 0;
10739
10711
  if (boundSessionFile !== sessionFile) continue;
@@ -10757,12 +10729,12 @@ function complianceFailureFromAuditorVolumes(volumes) {
10757
10729
  if (stop === void 0) continue;
10758
10730
  for (let i = entries.length - 1; i >= 0; i -= 1) {
10759
10731
  const entry = entries[i];
10760
- if (entry?.type !== "custom" || entry.customType !== AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE || !isRecord10(entry.data)) continue;
10761
- const parent = isRecord10(entry.data.parent) ? entry.data.parent : void 0;
10762
- const failure = isRecord10(entry.data.failure) ? entry.data.failure : void 0;
10732
+ if (entry?.type !== "custom" || entry.customType !== AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE || !isRecord(entry.data)) continue;
10733
+ const parent = isRecord(entry.data.parent) ? entry.data.parent : void 0;
10734
+ const failure = isRecord(entry.data.failure) ? entry.data.failure : void 0;
10763
10735
  if (parent?.sessionId !== parentId || parent.sessionFile !== sessionFile || parent.attemptEntryId !== attemptEntryId) continue;
10764
10736
  if (failure === void 0) continue;
10765
- const identity = isRecord10(failure.identity) ? failure.identity : void 0;
10737
+ const identity = isRecord(failure.identity) ? failure.identity : void 0;
10766
10738
  const typedCause = failure.cause === "provider" || failure.cause === "activation" || failure.cause === "session" || failure.cause === "output" || failure.cause === "timeout" ? failure.cause : void 0;
10767
10739
  return {
10768
10740
  ...typedCause === void 0 ? {} : { cause: typedCause },
@@ -10771,7 +10743,7 @@ function complianceFailureFromAuditorVolumes(volumes) {
10771
10743
  ...typeof identity.code === "string" || typeof identity.code === "number" ? { code: identity.code } : {}
10772
10744
  } },
10773
10745
  ...typeof failure.diagnostic === "string" ? { diagnostic: failure.diagnostic } : {},
10774
- ...isRecord10(failure.details) ? { details: failure.details } : {}
10746
+ ...isRecord(failure.details) ? { details: failure.details } : {}
10775
10747
  };
10776
10748
  }
10777
10749
  }
@@ -10818,9 +10790,9 @@ function typedFailedTerminatingToolKnownFailure(entries) {
10818
10790
  if (classification.kind !== "infrastructure") continue;
10819
10791
  if (typeof message.toolCallId !== "string" || typeof message.toolName !== "string") continue;
10820
10792
  if (boundRoleToolCallForResult(attemptEntries, i, message, message.toolName) === void 0) continue;
10821
- const textPart = Array.isArray(message.content) ? message.content.find((part) => isRecord10(part) && part.type === "text" && typeof part.text === "string") : void 0;
10822
- const diagnostic = isRecord10(textPart) ? textPart.text : void 0;
10823
- const details = isRecord10(message.details) ? message.details : classification.fact;
10793
+ const textPart = Array.isArray(message.content) ? message.content.find((part) => isRecord(part) && part.type === "text" && typeof part.text === "string") : void 0;
10794
+ const diagnostic = isRecord(textPart) ? textPart.text : void 0;
10795
+ const details = isRecord(message.details) ? message.details : classification.fact;
10824
10796
  return {
10825
10797
  cause: "activation",
10826
10798
  identity: { name: message.toolName, code: message.toolCallId },
@@ -10856,7 +10828,7 @@ async function resolveAuditedRunnerFailureResolution(input) {
10856
10828
  );
10857
10829
  if (terminatingFailure !== void 0) return resolutionOf(terminatingFailure);
10858
10830
  } catch (error) {
10859
- if (!isMissingPathError4(error)) {
10831
+ if (!isEnoent(error)) {
10860
10832
  const failure = sessionReadFailure(error, "failed to recover typed terminating-tool failure");
10861
10833
  return resolutionOf({
10862
10834
  cause: "session",
@@ -10957,15 +10929,12 @@ function controlledFailureInputFromResolution(resolution) {
10957
10929
  } : {}
10958
10930
  };
10959
10931
  }
10960
- function isRecord10(value) {
10961
- return typeof value === "object" && value !== null && !Array.isArray(value);
10962
- }
10963
10932
  function toolResultText(message) {
10964
10933
  const content = message.content;
10965
10934
  if (typeof content === "string") return content.trim();
10966
10935
  if (!Array.isArray(content)) return "";
10967
10936
  return content.map((part) => {
10968
- if (typeof part === "object" && part !== null && !Array.isArray(part) && typeof part.text === "string") {
10937
+ if (isRecord(part) && typeof part.text === "string") {
10969
10938
  return part.text;
10970
10939
  }
10971
10940
  return "";
@@ -11031,9 +11000,9 @@ function knownFailureFromControlled(failure) {
11031
11000
  };
11032
11001
  }
11033
11002
  function seatKnownFailureResolver(role) {
11034
- const record4 = packagedRoleMetadata(role);
11035
- if (record4 === void 0 || !("runnerFailure" in record4)) return void 0;
11036
- const policy = RUNNER_FAILURE_POLICY[record4.runnerFailure];
11003
+ const record = packagedRoleMetadata(role);
11004
+ if (record === void 0 || !("runnerFailure" in record)) return void 0;
11005
+ const policy = RUNNER_FAILURE_POLICY[record.runnerFailure];
11037
11006
  return async ({ result, sessionFile }) => {
11038
11007
  const infrastructureFailure = await policy.read(sessionFile);
11039
11008
  if (policy.rank === "record-first") {
@@ -11052,7 +11021,7 @@ function boundRoleToolCallForResult(entries, resultIndex, message, outputToolNam
11052
11021
  const candidateMessage = entries[index]?.message;
11053
11022
  if (candidateMessage?.role === "assistant" && Array.isArray(candidateMessage.content)) {
11054
11023
  for (const part of candidateMessage.content) {
11055
- if (!isRecord10(part) || part.type !== "toolCall" || part.id !== callId) {
11024
+ if (!isRecord(part) || part.type !== "toolCall" || part.id !== callId) {
11056
11025
  continue;
11057
11026
  }
11058
11027
  if (part.name !== outputToolName) return void 0;
@@ -11118,7 +11087,7 @@ function parseNavigatorAttendanceDetails(details) {
11118
11087
  if (typeof details.prose === "string" && details.prose.trim() !== "") {
11119
11088
  prose = details.prose;
11120
11089
  } else {
11121
- const next = isRecord10(details.next) && typeof details.next.role === "string" ? details.next.role : void 0;
11090
+ const next = isRecord(details.next) && typeof details.next.role === "string" ? details.next.role : void 0;
11122
11091
  const reason = typeof details.reason === "string" && details.reason.trim() !== "" ? details.reason : void 0;
11123
11092
  const command = typeof details.command === "string" && details.command.trim() !== "" ? details.command : void 0;
11124
11093
  if (reason !== void 0 && next !== void 0) {
@@ -11227,7 +11196,7 @@ function detourGateContext(admitted, scope) {
11227
11196
  }
11228
11197
  async function withOptionalGateProjection(base, sessionDirectory, gateContext = {}) {
11229
11198
  const secondaryEvidence = base.roleOutcome.kind === "failure" ? base.roleOutcome.decisiveFacts.secondaryEvidence : void 0;
11230
- const skipGate = isRecord10(secondaryEvidence) && secondaryEvidence.kind === "role_infrastructure_failure" && packagedSkipsGateOnInfrastructureStage(secondaryEvidence.stage);
11199
+ const skipGate = isRecord(secondaryEvidence) && secondaryEvidence.kind === "role_infrastructure_failure" && packagedSkipsGateOnInfrastructureStage(secondaryEvidence.stage);
11231
11200
  let next = base;
11232
11201
  if (!skipGate) {
11233
11202
  const gate = await extractGateFactFromSessionDirectory(sessionDirectory, gateContext);
@@ -11240,7 +11209,7 @@ function routePlaybookFailureMessage(entries) {
11240
11209
  const entry = entries[i];
11241
11210
  if (entry?.type !== "custom" || entry.customType !== NAVIGATOR_ROUTE_PLAYBOOK_FAILURE_ENTRY) continue;
11242
11211
  const data = entry.data;
11243
- if (!isRecord10(data) || typeof data.message !== "string" || data.message.trim() === "") return void 0;
11212
+ if (!isRecord(data) || typeof data.message !== "string" || data.message.trim() === "") return void 0;
11244
11213
  return data.message;
11245
11214
  }
11246
11215
  return void 0;
@@ -11263,8 +11232,8 @@ function extractNavigatorAttendanceFact(entries) {
11263
11232
  for (let i = terminal.index; i < entries.length; i += 1) {
11264
11233
  const entry = entries[i];
11265
11234
  if (entry?.type !== "custom" || entry.customType !== "ak-role-submission-closure") continue;
11266
- const details = isRecord10(entry.data) ? entry.data.navigator : void 0;
11267
- if (!isRecord10(details)) break;
11235
+ const details = isRecord(entry.data) ? entry.data.navigator : void 0;
11236
+ if (!isRecord(details)) break;
11268
11237
  return parseNavigatorAttendanceDetails(details);
11269
11238
  }
11270
11239
  return {
@@ -11278,7 +11247,7 @@ async function extractNavigatorFactFromAdmittedSession(sessionFile) {
11278
11247
  const entries = await readBoundSessionEntries(sessionFile);
11279
11248
  return extractNavigatorFact(entries);
11280
11249
  } catch (error) {
11281
- if (isMissingPathError4(error)) {
11250
+ if (isEnoent(error)) {
11282
11251
  return {
11283
11252
  disposition: "unavailable",
11284
11253
  source: "unknown",
@@ -11296,7 +11265,7 @@ async function removeFaceIfPresent(path) {
11296
11265
  try {
11297
11266
  await rm3(path, { recursive: true, force: true });
11298
11267
  } catch (error) {
11299
- if (isAbsentFacePathError(error)) return;
11268
+ if (isMissingPathError(error)) return;
11300
11269
  throw error;
11301
11270
  }
11302
11271
  }
@@ -11361,7 +11330,7 @@ async function readLawfulSettlementEntries(sessionFile) {
11361
11330
  try {
11362
11331
  return await readBoundSessionEntries(sessionFile);
11363
11332
  } catch (error) {
11364
- if (isMissingPathError4(error)) return void 0;
11333
+ if (isEnoent(error)) return void 0;
11365
11334
  throw error instanceof Error && error.knownCause === "session" ? error : sessionReadFailure(error, "session unreadable");
11366
11335
  }
11367
11336
  }
@@ -11396,7 +11365,7 @@ async function settleSealedAcceptedOrToolResidual(admitted, authority, scope, ro
11396
11365
  const residual = boundErroredToolCandidate(entries, index, message, residualToolName);
11397
11366
  if (residual === void 0) continue;
11398
11367
  const candidate = residual.candidate;
11399
- const details = isRecord10(candidate) ? candidate : { candidate };
11368
+ const details = isRecord(candidate) ? candidate : { candidate };
11400
11369
  const failed = await settleFailureTerminalResult(
11401
11370
  admitted,
11402
11371
  {
@@ -11428,26 +11397,26 @@ async function settleSealedAcceptedOrToolResidual(admitted, authority, scope, ro
11428
11397
  );
11429
11398
  }
11430
11399
  async function settleSeat(admitted, authority, scope) {
11431
- const record4 = packagedRoleMetadata(admitted.role);
11432
- if (record4 === void 0) {
11400
+ const record = packagedRoleMetadata(admitted.role);
11401
+ if (record === void 0) {
11433
11402
  throw new Error(`no settlement for ${admitted.role}`);
11434
11403
  }
11435
- if (record4.settlement === "accepted") {
11404
+ if (record.settlement === "accepted") {
11436
11405
  return trySettleAcceptedSeatTerminalResult(admitted, authority, scope);
11437
11406
  }
11438
11407
  const publish = (roleOutcome, coordinates, entries) => publishDeclaredSeatArtifacts(admitted, roleOutcome, coordinates, entries);
11439
- if (record4.settlement === "residual") {
11408
+ if (record.settlement === "residual") {
11440
11409
  return settleSealedAcceptedOrToolResidual(
11441
11410
  admitted,
11442
11411
  authority,
11443
11412
  scope,
11444
11413
  admitted.role,
11445
- record4.residualTool,
11446
- record4.residualScan,
11414
+ record.residualTool,
11415
+ record.residualScan,
11447
11416
  publish
11448
11417
  );
11449
11418
  }
11450
- const accept = "sealedAcceptedOnly" in record4 && record4.sealedAcceptedOnly === true ? (roleOutcome) => roleOutcome.role === admitted.role && roleOutcome.kind === "accepted" : void 0;
11419
+ const accept = "sealedAcceptedOnly" in record && record.sealedAcceptedOnly === true ? (roleOutcome) => roleOutcome.role === admitted.role && roleOutcome.kind === "accepted" : void 0;
11451
11420
  return settleSealedLedgerTerminal(admitted, authority, scope, publish, accept);
11452
11421
  }
11453
11422
  async function trySettleSeatTerminalResult(admitted, authority, scope) {
@@ -11471,7 +11440,7 @@ function extractDoctorCandidateFacts(entries) {
11471
11440
  continue;
11472
11441
  }
11473
11442
  const data = entry.data;
11474
- if (!isRecord10(data)) return {};
11443
+ if (!isRecord(data)) return {};
11475
11444
  return {
11476
11445
  ...data.cost === void 0 ? {} : { cost: data.cost },
11477
11446
  ...data.auditNoReceipt === void 0 ? {} : { auditNoReceipt: data.auditNoReceipt }
@@ -11480,9 +11449,9 @@ function extractDoctorCandidateFacts(entries) {
11480
11449
  return {};
11481
11450
  }
11482
11451
  function seatArtifactFace(role) {
11483
- const record4 = packagedRoleMetadata(role);
11484
- if (record4 !== void 0 && "artifactFace" in record4 && record4.artifactFace !== void 0) {
11485
- return record4.artifactFace;
11452
+ const record = packagedRoleMetadata(role);
11453
+ if (record !== void 0 && "artifactFace" in record && record.artifactFace !== void 0) {
11454
+ return record.artifactFace;
11486
11455
  }
11487
11456
  return EMPTY_ARTIFACT_FACE;
11488
11457
  }
@@ -11556,7 +11525,7 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
11556
11525
  let residual;
11557
11526
  for (let index = entries.length - 1; index >= scanStart; index -= 1) {
11558
11527
  const entry = entries[index];
11559
- if (entry?.type === "custom" && entry.customType === "ak-role-submission-closure" && isRecord10(entry.data) && entry.data.toolName === spec.toolName && classifyPackagedRoleTerminalResult(entry.data).kind === "accepted") {
11528
+ if (entry?.type === "custom" && entry.customType === "ak-role-submission-closure" && isRecord(entry.data) && entry.data.toolName === spec.toolName && classifyPackagedRoleTerminalResult(entry.data).kind === "accepted") {
11560
11529
  thisAttemptHasSeatSuccess = true;
11561
11530
  }
11562
11531
  const message = entries[index]?.message;
@@ -11596,7 +11565,7 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
11596
11565
  );
11597
11566
  }
11598
11567
  if (residual !== void 0) {
11599
- const details = isRecord10(residual.candidate) ? residual.candidate : { candidate: residual.candidate };
11568
+ const details = isRecord(residual.candidate) ? residual.candidate : { candidate: residual.candidate };
11600
11569
  const failed = await settleFailureTerminalResult(
11601
11570
  admitted,
11602
11571
  {
@@ -11620,8 +11589,8 @@ async function trySettleAcceptedSeatTerminalResult(admitted, authority, scope) {
11620
11589
  role: admitted.role,
11621
11590
  toolName
11622
11591
  }, scope);
11623
- const record4 = packagedRoleMetadata(admitted.role);
11624
- if (settled === void 0 || record4 === void 0 || !("projectCountersignTerminal" in record4) || record4.projectCountersignTerminal !== true) {
11592
+ const record = packagedRoleMetadata(admitted.role);
11593
+ if (settled === void 0 || record === void 0 || !("projectCountersignTerminal" in record) || record.projectCountersignTerminal !== true) {
11625
11594
  return settled;
11626
11595
  }
11627
11596
  return applySecretariatCountersignTerminal(admitted, authority, settled);
@@ -11634,7 +11603,7 @@ function countersignTerminalFromEntries(entries) {
11634
11603
  const entry = entries[index];
11635
11604
  if (entry?.type !== "custom") continue;
11636
11605
  if (entry.customType !== SECRETARIAT_GATE_OFFICER_ENTRY_TYPE) continue;
11637
- const data = entry.data !== null && typeof entry.data === "object" && !Array.isArray(entry.data) ? entry.data : void 0;
11606
+ const data = isRecord(entry.data) ? entry.data : void 0;
11638
11607
  if (data === void 0 || !packagedDurableOfficerEntry(data.officer)) continue;
11639
11608
  if (data.receipt === void 0) continue;
11640
11609
  const runId = typeof data.runId === "string" && data.runId.trim() !== "" ? data.runId : void 0;
@@ -11646,7 +11615,7 @@ function countersignTerminalFromEntries(entries) {
11646
11615
  return void 0;
11647
11616
  }
11648
11617
  function withCountersignTerminalFact(roleOutcome, officer) {
11649
- const prior = roleOutcome.decisiveFacts !== void 0 && isRecord10(roleOutcome.decisiveFacts) ? roleOutcome.decisiveFacts : {};
11618
+ const prior = roleOutcome.decisiveFacts !== void 0 && isRecord(roleOutcome.decisiveFacts) ? roleOutcome.decisiveFacts : {};
11650
11619
  return {
11651
11620
  ...roleOutcome,
11652
11621
  decisiveFacts: {
@@ -11659,7 +11628,7 @@ function acceptedSecretariatDefinesOfficerProjection(roleOutcome) {
11659
11628
  const payloads = roleOutcome.payloads ?? [];
11660
11629
  for (let index = payloads.length - 1; index >= 0; index -= 1) {
11661
11630
  const payload = payloads[index];
11662
- if (!isRecord10(payload)) continue;
11631
+ if (!isRecord(payload)) continue;
11663
11632
  const status = payload.secretariatStatus;
11664
11633
  if (typeof status !== "string") continue;
11665
11634
  return status === "converged";
@@ -12050,6 +12019,7 @@ var init_settlement = __esm({
12050
12019
  init_run_terminal_artifacts();
12051
12020
  init_invocation();
12052
12021
  init_terminal();
12022
+ init_unknown_value();
12053
12023
  privateFailureErrorPaths = /* @__PURE__ */ new WeakMap();
12054
12024
  NAVIGATOR_POST_ROLE_GRACE_MS = 1e4;
12055
12025
  ENGINE_DETOUR_INFRASTRUCTURE_FAILURE_SPEC = {
@@ -12218,7 +12188,7 @@ function latestQueueStatus(terminal) {
12218
12188
  if (outcome.kind === "audit_escalation") return "escalate";
12219
12189
  if (outcome.kind !== "accepted") return void 0;
12220
12190
  const latest = outcome.payloads?.[outcome.payloads.length - 1];
12221
- if (latest !== null && typeof latest === "object" && !Array.isArray(latest)) {
12191
+ if (isRecord(latest)) {
12222
12192
  const status = latest.status;
12223
12193
  if (typeof status === "string" && status.trim() !== "") return status;
12224
12194
  }
@@ -12340,6 +12310,7 @@ var init_submission_gate = __esm({
12340
12310
  init_archivist_record_pointer();
12341
12311
  init_gatekeeper_role();
12342
12312
  init_session_assistant_usage();
12313
+ init_unknown_value();
12343
12314
  }
12344
12315
  });
12345
12316
 
@@ -12521,12 +12492,12 @@ function projectRoleTurnRequest(admitted, roleDetails, options) {
12521
12492
  };
12522
12493
  }
12523
12494
  function packagedSettleSkill(admitted) {
12524
- const record4 = packagedRoleMetadata(admitted.role);
12525
- if (record4 === void 0) return void 0;
12526
- if ("applyMethod" in record4 && record4.applyMethod !== void 0) {
12527
- return "phase" in admitted && admitted.phase === "apply" ? record4.applyMethod : void 0;
12495
+ const record = packagedRoleMetadata(admitted.role);
12496
+ if (record === void 0) return void 0;
12497
+ if ("applyMethod" in record && record.applyMethod !== void 0) {
12498
+ return "phase" in admitted && admitted.phase === "apply" ? record.applyMethod : void 0;
12528
12499
  }
12529
- if ("settleMethod" in record4 && record4.settleMethod !== void 0) return record4.settleMethod;
12500
+ if ("settleMethod" in record && record.settleMethod !== void 0) return record.settleMethod;
12530
12501
  return void 0;
12531
12502
  }
12532
12503
  function readAdmittedPath2(admitted, path) {
@@ -12559,10 +12530,10 @@ function activationForAdmitted(admitted) {
12559
12530
  return activation;
12560
12531
  }
12561
12532
  function requiredMethodSkills(admitted) {
12562
- const record4 = packagedRoleMetadata(admitted.role);
12533
+ const record = packagedRoleMetadata(admitted.role);
12563
12534
  const names = [];
12564
- if (record4 !== void 0 && "methodSkills" in record4 && record4.methodSkills !== void 0) {
12565
- names.push(...record4.methodSkills);
12535
+ if (record !== void 0 && "methodSkills" in record && record.methodSkills !== void 0) {
12536
+ names.push(...record.methodSkills);
12566
12537
  }
12567
12538
  const apply = packagedSettleSkill(admitted);
12568
12539
  if (apply !== void 0 && !names.includes(apply)) names.push(apply);
@@ -12843,7 +12814,7 @@ function copyAndRecordHostDossier(options) {
12843
12814
  payload: {
12844
12815
  type: "native-session-warning",
12845
12816
  sessionId: options.sessionId,
12846
- error: error instanceof Error ? error.message : String(error)
12817
+ error: errorText(error)
12847
12818
  }
12848
12819
  });
12849
12820
  return;
@@ -12907,7 +12878,7 @@ function copyAndRecordHostDossier(options) {
12907
12878
  landingPath,
12908
12879
  ordinal,
12909
12880
  sessionId: options.sessionId,
12910
- error: lastError instanceof Error ? lastError.message : String(lastError)
12881
+ error: errorText(lastError)
12911
12882
  }
12912
12883
  });
12913
12884
  }
@@ -12917,6 +12888,7 @@ var init_host_session_record = __esm({
12917
12888
  "src/host-session-record.ts"() {
12918
12889
  "use strict";
12919
12890
  init_sitian_facade();
12891
+ init_unknown_value();
12920
12892
  HOST_SESSION_RECORD_KIND = "host-session";
12921
12893
  }
12922
12894
  });
@@ -12970,7 +12942,7 @@ async function ensureRealArtifactsDirectory(runDirectory) {
12970
12942
  throw new Error("run artifact retention: artifacts path is not a real directory");
12971
12943
  }
12972
12944
  } catch (error) {
12973
- if (!isMissingPathError5(error)) throw error;
12945
+ if (!isEnoent(error)) throw error;
12974
12946
  await mkdir4(artifactsDir, { recursive: true });
12975
12947
  const created = await lstat5(artifactsDir);
12976
12948
  if (created.isSymbolicLink() || !created.isDirectory()) {
@@ -12979,9 +12951,6 @@ async function ensureRealArtifactsDirectory(runDirectory) {
12979
12951
  }
12980
12952
  return artifactsDir;
12981
12953
  }
12982
- function isMissingPathError5(error) {
12983
- return error instanceof Error && "code" in error && error.code === "ENOENT";
12984
- }
12985
12954
  function jsonSafeReplacer() {
12986
12955
  const seen = /* @__PURE__ */ new WeakSet();
12987
12956
  return (_key, value) => {
@@ -13230,6 +13199,7 @@ var init_auto_resume = __esm({
13230
13199
  init_terminal();
13231
13200
  init_settlement();
13232
13201
  init_serialize_thrown_value();
13202
+ init_unknown_value();
13233
13203
  dummyIo = { stdout: () => {
13234
13204
  }, stderr: () => {
13235
13205
  } };
@@ -13237,7 +13207,7 @@ var init_auto_resume = __esm({
13237
13207
  name = "TurnDispatchedFailure";
13238
13208
  constructor(cause) {
13239
13209
  super(
13240
- `settlement failed after the host turn genuinely started: ${cause instanceof Error ? cause.message : String(cause)}`,
13210
+ `settlement failed after the host turn genuinely started: ${errorText(cause)}`,
13241
13211
  { cause }
13242
13212
  );
13243
13213
  }
@@ -13270,10 +13240,10 @@ function projectRelocatedTurnIdentity(request, result, admitted, relocation) {
13270
13240
  mutableRequest.runDirectory = admitted.runDirectory;
13271
13241
  mutableRequest.principal = admitted.principal;
13272
13242
  const activation = mutableRequest.activation;
13273
- if (activation !== null && typeof activation === "object" && !Array.isArray(activation)) {
13243
+ if (isRecord(activation)) {
13274
13244
  for (const field of ["taskPath", "packetPath", "prerequisitesPath", "inputPath", "requestManifestPath"]) {
13275
- const record4 = activation;
13276
- if (field in record4) record4[field] = rewrite(record4[field]);
13245
+ const record = activation;
13246
+ if (field in record) record[field] = rewrite(record[field]);
13277
13247
  }
13278
13248
  }
13279
13249
  if (result.terminal !== void 0) {
@@ -13492,7 +13462,7 @@ async function dispatchPostAdmissionTurn(input) {
13492
13462
  continue;
13493
13463
  }
13494
13464
  const payload = row.accepted;
13495
- if (payload === null || typeof payload !== "object" || Array.isArray(payload)) continue;
13465
+ if (!isRecord(payload)) continue;
13496
13466
  ticketNumber = readDeclaredTicketNumber(
13497
13467
  payload.ticketNumber
13498
13468
  );
@@ -14092,9 +14062,9 @@ async function pointExistingRunFailure(home, runId, authority, io, thrown) {
14092
14062
  }
14093
14063
  if (foundRunDirectory === void 0) return false;
14094
14064
  const runDirectory = foundRunDirectory;
14095
- let record4;
14065
+ let record;
14096
14066
  try {
14097
- record4 = await readRoleRunState(runDirectory, authority);
14067
+ record = await readRoleRunState(runDirectory, authority);
14098
14068
  } catch {
14099
14069
  await presentResumeFailurePointer(
14100
14070
  io,
@@ -14103,11 +14073,11 @@ async function pointExistingRunFailure(home, runId, authority, io, thrown) {
14103
14073
  );
14104
14074
  return true;
14105
14075
  }
14106
- if (record4 === void 0) return false;
14076
+ if (record === void 0) return false;
14107
14077
  await presentResumeFailurePointer(
14108
14078
  io,
14109
14079
  thrown,
14110
- (failure) => writeResumeDiagnosticFile(runDirectory, runId, failure, record4.role)
14080
+ (failure) => writeResumeDiagnosticFile(runDirectory, runId, failure, record.role)
14111
14081
  );
14112
14082
  return true;
14113
14083
  }
@@ -14139,7 +14109,7 @@ async function presentResumeFailurePointer(io, thrown, publish) {
14139
14109
  cause.thrownCause = formatErrorCauseDetail(thrown.cause);
14140
14110
  }
14141
14111
  presentStructuralRejection({
14142
- message: thrown instanceof Error ? thrown.message : String(thrown),
14112
+ message: errorText(thrown),
14143
14113
  cause
14144
14114
  }, io);
14145
14115
  }
@@ -14274,6 +14244,7 @@ var init_post_admission = __esm({
14274
14244
  init_settlement();
14275
14245
  init_terminal();
14276
14246
  init_auto_resume();
14247
+ init_unknown_value();
14277
14248
  POST_ADMISSION_CLEANUP_DIAGNOSTIC_ENTRY_TYPE = "ak_post_admission_cleanup_diagnostic";
14278
14249
  }
14279
14250
  });
@@ -14301,11 +14272,8 @@ var init_seat_ticket_binding = __esm({
14301
14272
  });
14302
14273
 
14303
14274
  // src/public-cli/countersign-run.ts
14304
- function isRecord11(value) {
14305
- return typeof value === "object" && value !== null && !Array.isArray(value);
14306
- }
14307
14275
  function isEscalatePayload(payload) {
14308
- if (!isRecord11(payload)) return false;
14276
+ if (!isRecord(payload)) return false;
14309
14277
  return payload.status === "escalate";
14310
14278
  }
14311
14279
  function courtDiaristPayloadRows(roleOutcome, submissions) {
@@ -14399,6 +14367,7 @@ var init_countersign_run = __esm({
14399
14367
  "src/public-cli/countersign-run.ts"() {
14400
14368
  "use strict";
14401
14369
  init_readable_gate_item();
14370
+ init_unknown_value();
14402
14371
  }
14403
14372
  });
14404
14373
 
@@ -14416,7 +14385,7 @@ function unreadablePostSubmissionStatus(admitted, terminal) {
14416
14385
  const route = POST_SUBMISSION_ROUTING[admitted.role];
14417
14386
  if (route === void 0) return void 0;
14418
14387
  const payload = terminal.roleOutcome.payloads?.at(-1);
14419
- const status = payload !== null && typeof payload === "object" && !Array.isArray(payload) ? payload.status : void 0;
14388
+ const status = isRecord(payload) ? payload.status : void 0;
14420
14389
  return typeof status === "string" && route.statuses.has(status) ? void 0 : route.reask;
14421
14390
  }
14422
14391
  async function reaskUnreadablePostSubmissionStatus(admitted, terminal, env, io) {
@@ -14429,11 +14398,11 @@ async function reaskUnreadablePostSubmissionStatus(admitted, terminal, env, io)
14429
14398
  );
14430
14399
  }
14431
14400
  function roleRecord(role) {
14432
- const record4 = packagedRoleMetadata(role);
14433
- if (record4 === void 0) {
14401
+ const record = packagedRoleMetadata(role);
14402
+ if (record === void 0) {
14434
14403
  throw new CliUsageError(`unknown role: ${role}`);
14435
14404
  }
14436
- return record4;
14405
+ return record;
14437
14406
  }
14438
14407
  function buildInstructionSeatTurnRequest(admitted, options) {
14439
14408
  return projectRoleTurnRequest(
@@ -14443,9 +14412,9 @@ function buildInstructionSeatTurnRequest(admitted, options) {
14443
14412
  );
14444
14413
  }
14445
14414
  function initialPrompt(admitted, env) {
14446
- const record4 = roleRecord(admitted.role);
14415
+ const record = roleRecord(admitted.role);
14447
14416
  const reask = env.reviewReask ?? env.gateReviewInstruction;
14448
- if (reask !== void 0 && "reaskPrompt" in record4 && record4.reaskPrompt === true) {
14417
+ if (reask !== void 0 && "reaskPrompt" in record && record.reaskPrompt === true) {
14449
14418
  return reask;
14450
14419
  }
14451
14420
  return buildInstructionTransportPrompt(
@@ -14472,8 +14441,8 @@ async function bindAndRelocateDiarist(admitted, authority, lease) {
14472
14441
  return await relocateAdmittedRunToTicket(admitted, authority, lease);
14473
14442
  }
14474
14443
  function seatAdapters(admitted, env) {
14475
- const record4 = roleRecord(admitted.role);
14476
- const present = "presentSettled" in record4 ? record4.presentSettled : "default";
14444
+ const record = roleRecord(admitted.role);
14445
+ const present = "presentSettled" in record ? record.presentSettled : "default";
14477
14446
  return {
14478
14447
  trySettle: (seat, authority, scope) => trySettlePublicSeat(seat, authority, scope),
14479
14448
  ...present === "always" ? { shouldPresentSettled: () => true } : {},
@@ -14526,7 +14495,7 @@ async function withAuditorSoulEnv(options) {
14526
14495
  }
14527
14496
  }
14528
14497
  async function dispatchAdmitted(admitted, env, io) {
14529
- const record4 = roleRecord(admitted.role);
14498
+ const record = roleRecord(admitted.role);
14530
14499
  await warnMissingMethodSkills(env.home, env.host, admitted.role, requiredMethodSkills(admitted), io.stdout);
14531
14500
  const adapters = seatAdapters(admitted, env);
14532
14501
  const held = [];
@@ -14535,7 +14504,7 @@ async function dispatchAdmitted(admitted, env, io) {
14535
14504
  if (activeEnv.correlationId !== void 0 && activeEnv.correlationId.trim() !== "") {
14536
14505
  await recordAdmittedCorrelation(admitted, activeEnv.correlationId);
14537
14506
  }
14538
- const auto = "inCallAutoResume" in record4 && record4.inCallAutoResume === true;
14507
+ const auto = "inCallAutoResume" in record && record.inCallAutoResume === true;
14539
14508
  if (auto) {
14540
14509
  return await runPostAdmissionResumable({
14541
14510
  admitted,
@@ -14749,7 +14718,7 @@ async function runCountersignBody(parsed, env, io) {
14749
14718
  }
14750
14719
  }
14751
14720
  async function runPublicInstructionSeat(argv, env, io, role, parseArgv2) {
14752
- const record4 = roleRecord(role);
14721
+ const record = roleRecord(role);
14753
14722
  let parsed;
14754
14723
  try {
14755
14724
  parsed = parseArgv2(argv);
@@ -14768,7 +14737,7 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv2) {
14768
14737
  for (const value of held) io.stdout(value);
14769
14738
  return result;
14770
14739
  }
14771
- if ("parallelLenses" in record4 && record4.parallelLenses === true) {
14740
+ if ("parallelLenses" in record && record.parallelLenses === true) {
14772
14741
  if (parsed.baseRevision === void 0) {
14773
14742
  presentStructuralRejection(new CliUsageError("reviewer requires --base"), io);
14774
14743
  return { exitCode: 2 };
@@ -14782,7 +14751,7 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv2) {
14782
14751
  let auditorSource;
14783
14752
  let auditorTicket;
14784
14753
  let resolvedNotarySource;
14785
- if (record4.sameParent === "subject-source") {
14754
+ if (record.sameParent === "subject-source") {
14786
14755
  if (parsed.subject === void 0) {
14787
14756
  presentStructuralRejection(new CliUsageError("auditor --subject requires judge|doctor"), io);
14788
14757
  return { exitCode: 2 };
@@ -14798,7 +14767,7 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv2) {
14798
14767
  auditorSource = resolved.runDirectory;
14799
14768
  auditorTicket = await readBoardTicketNumber(resolved.runDirectory);
14800
14769
  } catch (error) {
14801
- presentStructuralRejection(new CliUsageError(error instanceof Error ? error.message : String(error)), io);
14770
+ presentStructuralRejection(new CliUsageError(errorText(error)), io);
14802
14771
  return { exitCode: 2 };
14803
14772
  }
14804
14773
  if (auditorSource === void 0) return { exitCode: 2 };
@@ -14824,7 +14793,7 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv2) {
14824
14793
  });
14825
14794
  if (resumed != null) return resumed;
14826
14795
  }
14827
- if (record4.sameParent === "gate-pointer") {
14796
+ if (record.sameParent === "gate-pointer") {
14828
14797
  const parentRunPath = parentRunPathFromGatePointerInstruction(parsed.instruction ?? "");
14829
14798
  if (parentRunPath !== void 0) {
14830
14799
  const summons = {
@@ -14846,7 +14815,7 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv2) {
14846
14815
  if (resumed != null) return resumed;
14847
14816
  }
14848
14817
  }
14849
- if (record4.sameParent === "source-locator") {
14818
+ if (record.sameParent === "source-locator") {
14850
14819
  let source;
14851
14820
  try {
14852
14821
  source = await resolveNotarySourceRunLocator({
@@ -14895,7 +14864,7 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv2) {
14895
14864
  if (rejected !== void 0) return rejected;
14896
14865
  throw error;
14897
14866
  }
14898
- if (record4.sameParent === "gate-pointer") {
14867
+ if (record.sameParent === "gate-pointer") {
14899
14868
  const parentRunPath = parentRunPathFromGatePointerInstruction(parsed.instruction ?? "");
14900
14869
  if (parentRunPath !== void 0) {
14901
14870
  await persistAdmittedSourceRunPath(admitted, parentRunPath);
@@ -14903,7 +14872,7 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv2) {
14903
14872
  admitted = { ...admitted, ...sourcePatch };
14904
14873
  }
14905
14874
  }
14906
- if (record4.sameParent === "subject-source" && auditorSource !== void 0) {
14875
+ if (record.sameParent === "subject-source" && auditorSource !== void 0) {
14907
14876
  await persistAdmittedSourceRunPath(admitted, auditorSource, auditorSubject);
14908
14877
  }
14909
14878
  const runAdmitted = async () => {
@@ -14943,7 +14912,7 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv2) {
14943
14912
  }
14944
14913
  return dispatchAdmitted(admitted, env, io);
14945
14914
  };
14946
- if (record4.sameParent === "subject-source") {
14915
+ if (record.sameParent === "subject-source") {
14947
14916
  return withAuditorSoulEnv({
14948
14917
  ...auditorSubject === void 0 ? {} : { subject: auditorSubject },
14949
14918
  ...auditorSource === void 0 ? {} : { sourceRunDirectory: auditorSource },
@@ -15083,8 +15052,8 @@ async function auditSubmittedRole(turn, env, io, passedOfficer, passedReceipt, p
15083
15052
  if (admitted === void 0 || !AUDITED_ROLES.has(admitted.role) || turn.terminal?.roleOutcome.kind !== "accepted") return turn;
15084
15053
  const accepted = turn.terminal.roleOutcome.payloads?.at(-1);
15085
15054
  if (accepted === void 0) throw new Error("accepted submission has no payload");
15086
- const record4 = accepted !== null && typeof accepted === "object" && !Array.isArray(accepted) ? accepted : void 0;
15087
- const status = admitted.role === "secretariat" ? record4?.secretariatStatus : record4?.status;
15055
+ const record = isRecord(accepted) ? accepted : void 0;
15056
+ const status = admitted.role === "secretariat" ? record?.secretariatStatus : record?.status;
15088
15057
  if (admitted.role === "secretariat" && status !== "converged" && status !== "escalate") {
15089
15058
  return runPublicInstructionSeatResume(
15090
15059
  { runId: admitted.runId, message: SECRETARIAT_STATUS_REASK },
@@ -15305,6 +15274,7 @@ var init_instruction_seat_run = __esm({
15305
15274
  init_terminal();
15306
15275
  init_turn_request();
15307
15276
  init_countersign_run();
15277
+ init_unknown_value();
15308
15278
  AUDITED_ROLES = /* @__PURE__ */ new Set(["judge", "fixer", "coder", "secretariat", "countersign", "doctor"]);
15309
15279
  SECRETARIAT_STATUS_REASK = "secretariatStatus \u4E0D\u662F converged\u3001escalate \u4E4B\u4E00\u3002\u8BF7\u91CD\u65B0\u4EA4\u5377\uFF0CsecretariatStatus \u5199\u660E\u5176\u4E00\u3002";
15310
15280
  COUNTERSIGN_STATUS_REASK = "status \u4E0D\u662F converged\u3001continue\u3001escalate \u4E09\u6001\u4E4B\u4E00\u3002\u8BF7\u91CD\u65B0\u4EA4\u5377\uFF0Cstatus \u5199\u660E\u5176\u4E00\u3002";
@@ -15384,11 +15354,7 @@ var init_analyst_book_key = __esm({
15384
15354
  // src/analyst-index.ts
15385
15355
  import { open as open2, readFile as readFile18, unlink as unlink4 } from "node:fs/promises";
15386
15356
  import { dirname as dirname21, join as join34 } from "node:path";
15387
- function sleep(ms) {
15388
- return new Promise((resolve22) => {
15389
- setTimeout(resolve22, ms);
15390
- });
15391
- }
15357
+ import { setTimeout as sleep } from "node:timers/promises";
15392
15358
  async function withAnalystLibraryIndexLock(ledgerHome, fn) {
15393
15359
  const indexPath = analystLibraryIndexPath(ledgerHome);
15394
15360
  ensureRealDirectoryTree(ledgerHome, dirname21(indexPath));
@@ -15512,9 +15478,7 @@ async function readAnalystLibraryIndexPage(ledgerHome) {
15512
15478
  try {
15513
15479
  raw = await readFile18(path, "utf8");
15514
15480
  } catch (error) {
15515
- if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR")) {
15516
- return void 0;
15517
- }
15481
+ if (isMissingPathError(error)) return void 0;
15518
15482
  throw error;
15519
15483
  }
15520
15484
  const parsed = JSON.parse(raw);
@@ -15549,6 +15513,7 @@ var init_analyst_index = __esm({
15549
15513
  init_atomic_write();
15550
15514
  init_activation_ledger_topology();
15551
15515
  init_analyst_book_key();
15516
+ init_unknown_value();
15552
15517
  LIBRARY_INDEX_LOCK_NAME = ".library-index.lock";
15553
15518
  LIBRARY_INDEX_LOCK_TIMEOUT_MS = 3e4;
15554
15519
  LIBRARY_INDEX_LOCK_RETRY_MS = 15;
@@ -15716,15 +15681,6 @@ var init_analyst_cohort = __esm({
15716
15681
  // src/analyst-ledger.ts
15717
15682
  import { readdir as readdir6, readFile as readFile19 } from "node:fs/promises";
15718
15683
  import { basename as basename9, join as join35 } from "node:path";
15719
- function isMissingPathError6(error) {
15720
- return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
15721
- }
15722
- function errorText3(error) {
15723
- return error instanceof Error ? error.message : String(error);
15724
- }
15725
- function isRecord12(value) {
15726
- return typeof value === "object" && value !== null && !Array.isArray(value);
15727
- }
15728
15684
  async function readExistingRunLifecycleState(runDirectory) {
15729
15685
  return (await readRoleRunIdentity(runDirectory))?.state;
15730
15686
  }
@@ -15766,7 +15722,7 @@ async function listLedgerBookNames(booksRoot) {
15766
15722
  const entries = await readdir6(booksRoot, { withFileTypes: true });
15767
15723
  return entries.filter((e) => e.isDirectory()).map((e) => e.name).sort();
15768
15724
  } catch (error) {
15769
- if (isMissingPathError6(error)) return [];
15725
+ if (isMissingPathError(error)) return [];
15770
15726
  throw error;
15771
15727
  }
15772
15728
  }
@@ -15775,11 +15731,11 @@ async function readInvocationScopeFields(runDirectory) {
15775
15731
  try {
15776
15732
  raw = await readFile19(join35(runDirectory, "invocation.json"), "utf8");
15777
15733
  } catch (error) {
15778
- if (isMissingPathError6(error)) return void 0;
15734
+ if (isMissingPathError(error)) return void 0;
15779
15735
  throw error;
15780
15736
  }
15781
15737
  const parsed = JSON.parse(raw);
15782
- if (!isRecord12(parsed)) return void 0;
15738
+ if (!isRecord(parsed)) return void 0;
15783
15739
  if (typeof parsed.projectRoot !== "string" || parsed.projectRoot.trim() === "") {
15784
15740
  return void 0;
15785
15741
  }
@@ -15808,11 +15764,11 @@ async function resolveSessionFile(runDirectory) {
15808
15764
  try {
15809
15765
  const raw = await readFile19(join35(runDirectory, "invocation.json"), "utf8");
15810
15766
  const parsed = JSON.parse(raw);
15811
- if (isRecord12(parsed) && typeof parsed.sessionFile === "string" && parsed.sessionFile.trim() !== "") {
15767
+ if (isRecord(parsed) && typeof parsed.sessionFile === "string" && parsed.sessionFile.trim() !== "") {
15812
15768
  return parsed.sessionFile;
15813
15769
  }
15814
15770
  } catch (error) {
15815
- if (!isMissingPathError6(error)) throw error;
15771
+ if (!isMissingPathError(error)) throw error;
15816
15772
  }
15817
15773
  return join35(runDirectory, "session", "session.jsonl");
15818
15774
  }
@@ -15929,18 +15885,18 @@ async function classifyScopedRun(input) {
15929
15885
  admitAttributed(attributed.rows);
15930
15886
  } else if (attributed.kind === "attributed") {
15931
15887
  missingSources.push("session-timeline");
15932
- reasons.push(errorText3(error));
15888
+ reasons.push(errorText(error));
15933
15889
  const admitted = admitFrameSpanFromRows(attributed.rows);
15934
15890
  models = admitted.models;
15935
15891
  partialFirstFrameAt = admitted.partialFirstFrameAt;
15936
15892
  partialLastFrameAt = admitted.partialLastFrameAt;
15937
15893
  } else {
15938
15894
  missingSources.push("session-timeline");
15939
- reasons.push(errorText3(error));
15895
+ reasons.push(errorText(error));
15940
15896
  }
15941
15897
  } else {
15942
15898
  missingSources.push("session-timeline");
15943
- reasons.push(errorText3(error));
15899
+ reasons.push(errorText(error));
15944
15900
  }
15945
15901
  }
15946
15902
  if (rows !== void 0 && !missingSources.includes("session-timeline")) {
@@ -15948,7 +15904,7 @@ async function classifyScopedRun(input) {
15948
15904
  toolIntervals = extractSessionToolIntervals(rows);
15949
15905
  } catch (error) {
15950
15906
  missingSources.push("tool-association");
15951
- reasons.push(errorText3(error));
15907
+ reasons.push(errorText(error));
15952
15908
  }
15953
15909
  }
15954
15910
  let lifecycle;
@@ -15956,7 +15912,7 @@ async function classifyScopedRun(input) {
15956
15912
  lifecycle = await readExistingRunLifecycleState(input.runDirectory);
15957
15913
  } catch (error) {
15958
15914
  missingSources.push("run-state");
15959
- reasons.push(errorText3(error));
15915
+ reasons.push(errorText(error));
15960
15916
  }
15961
15917
  let ghostLeg;
15962
15918
  if (lifecycle === "admitted" || lifecycle === "running") {
@@ -15991,7 +15947,7 @@ async function classifyScopedRun(input) {
15991
15947
  }
15992
15948
  } catch (error) {
15993
15949
  missingSources.push("terminal-artifact");
15994
- reasons.push(errorText3(error));
15950
+ reasons.push(errorText(error));
15995
15951
  }
15996
15952
  if (missingSources.length > 0) {
15997
15953
  const firstFrameAt = frameSpan !== void 0 ? { status: "present", at: frameSpan.startedAt } : partialFirstFrameAt;
@@ -16028,7 +15984,7 @@ async function classifyScopedRun(input) {
16028
15984
  runId: input.runId,
16029
15985
  book: input.book,
16030
15986
  missingSources: ["auditor-roles"],
16031
- reason: errorText3(error),
15987
+ reason: errorText(error),
16032
15988
  firstFrameAt: { status: "present", at: frameSpan.startedAt },
16033
15989
  lastFrameAt: { status: "present", at: frameSpan.endedAt }
16034
15990
  },
@@ -16091,7 +16047,7 @@ async function scanAnalystIssueRuns(input) {
16091
16047
  try {
16092
16048
  runDirectories = await listBookRunDirectories(bookDir);
16093
16049
  } catch (error) {
16094
- if (isMissingPathError6(error)) continue;
16050
+ if (isMissingPathError(error)) continue;
16095
16051
  throw error;
16096
16052
  }
16097
16053
  for (const runDirectory of runDirectories) {
@@ -16151,32 +16107,30 @@ var init_analyst_ledger = __esm({
16151
16107
  init_ledger_session_read();
16152
16108
  init_run_terminal_artifacts();
16153
16109
  init_analyst_gate_cycles_read();
16110
+ init_unknown_value();
16154
16111
  LIVE_RUN_STATES = /* @__PURE__ */ new Set(["admitted", "running", "resumable"]);
16155
16112
  }
16156
16113
  });
16157
16114
 
16158
16115
  // src/analyst-metric-families/acceptance-success-rework.ts
16159
- function isRecord13(value) {
16160
- return typeof value === "object" && value !== null && !Array.isArray(value);
16161
- }
16162
16116
  function findCollectorGroups(body) {
16163
16117
  if (Array.isArray(body.groups)) return body.groups;
16164
16118
  const receipt = body.receipt;
16165
- if (isRecord13(receipt) && Array.isArray(receipt.groups)) return receipt.groups;
16119
+ if (isRecord(receipt) && Array.isArray(receipt.groups)) return receipt.groups;
16166
16120
  const outcome = body.outcome;
16167
- if (isRecord13(outcome)) {
16121
+ if (isRecord(outcome)) {
16168
16122
  const facts = outcome.decisiveFacts;
16169
- if (isRecord13(facts) && Array.isArray(facts.groups)) return facts.groups;
16123
+ if (isRecord(facts) && Array.isArray(facts.groups)) return facts.groups;
16170
16124
  }
16171
16125
  return void 0;
16172
16126
  }
16173
16127
  function extractStatus(body) {
16174
16128
  const outcome = body.outcome;
16175
- if (isRecord13(outcome) && typeof outcome.status === "string" && outcome.status.trim() !== "") {
16129
+ if (isRecord(outcome) && typeof outcome.status === "string" && outcome.status.trim() !== "") {
16176
16130
  return outcome.status;
16177
16131
  }
16178
16132
  const receipt = body.receipt;
16179
- if (isRecord13(receipt) && typeof receipt.status === "string" && receipt.status.trim() !== "") {
16133
+ if (isRecord(receipt) && typeof receipt.status === "string" && receipt.status.trim() !== "") {
16180
16134
  return receipt.status;
16181
16135
  }
16182
16136
  if (typeof body.status === "string" && body.status.trim() !== "") {
@@ -16355,6 +16309,7 @@ var init_acceptance_success_rework = __esm({
16355
16309
  init_analyst_ledger();
16356
16310
  init_analyst_median();
16357
16311
  init_packaged_role_registry();
16312
+ init_unknown_value();
16358
16313
  WORKER_ROLES = /* @__PURE__ */ new Set(["coder", "fixer"]);
16359
16314
  ACCEPTED_STATUS = {
16360
16315
  coder: /* @__PURE__ */ new Set(["completed", "refused", "partially_completed", "unfinished", "planned"]),
@@ -16673,12 +16628,9 @@ var init_leg_wall_clock = __esm({
16673
16628
  });
16674
16629
 
16675
16630
  // src/analyst-metric-families/round-timeline.ts
16676
- function isRecord14(value) {
16677
- return typeof value === "object" && value !== null && !Array.isArray(value);
16678
- }
16679
16631
  function readClassCount(body) {
16680
- if (!isRecord14(body.outcome)) return void 0;
16681
- if (!isRecord14(body.outcome.decisiveFacts)) return void 0;
16632
+ if (!isRecord(body.outcome)) return void 0;
16633
+ if (!isRecord(body.outcome.decisiveFacts)) return void 0;
16682
16634
  const classCount = body.outcome.decisiveFacts.classCount;
16683
16635
  if (typeof classCount !== "number" || !Number.isFinite(classCount)) {
16684
16636
  return void 0;
@@ -16765,6 +16717,7 @@ var init_round_timeline = __esm({
16765
16717
  "src/analyst-metric-families/round-timeline.ts"() {
16766
16718
  "use strict";
16767
16719
  init_acceptance_success_rework();
16720
+ init_unknown_value();
16768
16721
  roundTimelineFamily = {
16769
16722
  id: "round-timeline",
16770
16723
  contribute(input) {
@@ -16822,7 +16775,6 @@ var init_analyst_metric_family = __esm({
16822
16775
  });
16823
16776
 
16824
16777
  // src/analyst-page.ts
16825
- import { createHash as createHash3 } from "node:crypto";
16826
16778
  import { dirname as dirname22, join as join36 } from "node:path";
16827
16779
  function analystIssuePageKey(address) {
16828
16780
  const parts = ["book", address.bookKey];
@@ -16831,7 +16783,7 @@ function analystIssuePageKey(address) {
16831
16783
  } else if (address.scopeRootIdentity !== void 0) {
16832
16784
  parts.push("root", physicalPathIdentity(address.scopeRootIdentity));
16833
16785
  }
16834
- return createHash3("sha256").update(parts.join("\0")).digest("hex").slice(0, 32);
16786
+ return sha256Hex(parts.join("\0")).slice(0, 32);
16835
16787
  }
16836
16788
  function analystIssuePagePath(ledgerHome, address) {
16837
16789
  return join36(ledgerHome, "analyst", "issues", `${analystIssuePageKey(address)}.json`);
@@ -16954,6 +16906,7 @@ async function writeAnalystIssueMetricsPage(ledgerHome, page) {
16954
16906
  var init_analyst_page = __esm({
16955
16907
  "src/analyst-page.ts"() {
16956
16908
  "use strict";
16909
+ init_sha256();
16957
16910
  init_atomic_write();
16958
16911
  init_activation_ledger_topology();
16959
16912
  init_analyst_ledger();
@@ -17071,9 +17024,6 @@ var init_analyst_model_groups = __esm({
17071
17024
  // src/analyst-entry.ts
17072
17025
  import { readFile as readFile20 } from "node:fs/promises";
17073
17026
  import { Type as Type12 } from "typebox";
17074
- function isMissingPathError7(error) {
17075
- return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
17076
- }
17077
17027
  function cachedPageMatchesRequestedScope(page, input) {
17078
17028
  if (page.bookKey !== input.bookKey) return false;
17079
17029
  const requestedTicket = input.ticketNumber ?? input.issueNumber;
@@ -17112,7 +17062,7 @@ async function readOrComputeAnalystIssuePage(input, options) {
17112
17062
  return { mode: "issue", page, pagePath, ghostLegs: ghostScan.ghostLegs };
17113
17063
  }
17114
17064
  } catch (error) {
17115
- if (!isMissingPathError7(error)) {
17065
+ if (!isMissingPathError(error)) {
17116
17066
  throw new AnalystIssueComputeError({
17117
17067
  bookKey,
17118
17068
  projectRoot,
@@ -17204,7 +17154,7 @@ async function runAnalystModelGroupsMode(input, home) {
17204
17154
  const raw = await readFile20(pagePath, "utf8");
17205
17155
  JSON.parse(raw);
17206
17156
  } catch (error) {
17207
- if (!isMissingPathError7(error)) {
17157
+ if (!isMissingPathError(error)) {
17208
17158
  throw new AnalystIssueComputeError({ bookKey, projectRoot, cause: error });
17209
17159
  }
17210
17160
  try {
@@ -17257,6 +17207,7 @@ var init_analyst_entry = __esm({
17257
17207
  init_analyst_index();
17258
17208
  init_analyst_model_groups();
17259
17209
  init_analyst_page();
17210
+ init_unknown_value();
17260
17211
  AnalystIssueComputeError = class extends Error {
17261
17212
  code = "analyst-issue-compute-failed";
17262
17213
  bookKey;
@@ -17288,12 +17239,10 @@ var init_analyst_entry = __esm({
17288
17239
  changedLines: Type12.Optional(
17289
17240
  Type12.Number({ minimum: 0, maximum: Number.MAX_VALUE })
17290
17241
  )
17291
- },
17292
- { additionalProperties: false }
17242
+ }
17293
17243
  )
17294
17244
  )
17295
- },
17296
- { additionalProperties: false }
17245
+ }
17297
17246
  );
17298
17247
  }
17299
17248
  });
@@ -17364,7 +17313,7 @@ async function buildAnalystSweepModeInputFromAttachmentPaths(attachmentPaths) {
17364
17313
  try {
17365
17314
  text = exactUtf8(bytes, "analyst sweep attachment");
17366
17315
  } catch (error) {
17367
- const detail = error instanceof Error ? error.message : String(error);
17316
+ const detail = errorText(error);
17368
17317
  throw new CliUsageError(detail, { cause: error });
17369
17318
  }
17370
17319
  let parsed;
@@ -17454,6 +17403,7 @@ var init_analyst_run = __esm({
17454
17403
  init_analyst_entry();
17455
17404
  init_cli_errors();
17456
17405
  init_settlement();
17406
+ init_unknown_value();
17457
17407
  }
17458
17408
  });
17459
17409
 
@@ -17712,7 +17662,7 @@ function requireLegalEngineModel(model) {
17712
17662
  return assertLegalEngineModel(model);
17713
17663
  } catch (error) {
17714
17664
  throw new CliUsageError(
17715
- error instanceof Error ? error.message : String(error),
17665
+ errorText(error),
17716
17666
  { cause: error }
17717
17667
  );
17718
17668
  }
@@ -17722,7 +17672,7 @@ function requireLegalEngineName(name) {
17722
17672
  return assertLegalEngineName(name);
17723
17673
  } catch (error) {
17724
17674
  throw new CliUsageError(
17725
- error instanceof Error ? error.message : String(error),
17675
+ errorText(error),
17726
17676
  { cause: error }
17727
17677
  );
17728
17678
  }
@@ -17738,7 +17688,7 @@ function loadAndValidateConfig(home, packageRoot) {
17738
17688
  validatePublicCliConfigAxes(config, packageRoot);
17739
17689
  } catch (error) {
17740
17690
  throw new CliUsageError(
17741
- error instanceof Error ? error.message : String(error),
17691
+ errorText(error),
17742
17692
  { cause: error }
17743
17693
  );
17744
17694
  }
@@ -18000,7 +17950,7 @@ async function runConfigCommand(args, home, packageRoot, io) {
18000
17950
  try {
18001
17951
  config = setPersistentSeatHost(config, seat, unset ? void 0 : args[2]);
18002
17952
  } catch (error) {
18003
- throw new CliUsageError(error instanceof Error ? error.message : String(error), { cause: error });
17953
+ throw new CliUsageError(errorText(error), { cause: error });
18004
17954
  }
18005
17955
  await savePublicCliConfig(config, home);
18006
17956
  io.stdout(renderConfig(config, home));
@@ -18023,7 +17973,7 @@ async function runConfigCommand(args, home, packageRoot, io) {
18023
17973
  config = setPersistentSeatEngine(config, seat, name, engineModel);
18024
17974
  } catch (error) {
18025
17975
  throw new CliUsageError(
18026
- error instanceof Error ? error.message : String(error),
17976
+ errorText(error),
18027
17977
  { cause: error }
18028
17978
  );
18029
17979
  }
@@ -18044,7 +17994,7 @@ async function runConfigCommand(args, home, packageRoot, io) {
18044
17994
  config = setPersistentSeatEngine(config, seat, void 0);
18045
17995
  } catch (error) {
18046
17996
  throw new CliUsageError(
18047
- error instanceof Error ? error.message : String(error),
17997
+ errorText(error),
18048
17998
  { cause: error }
18049
17999
  );
18050
18000
  }
@@ -18067,7 +18017,7 @@ async function runConfigCommand(args, home, packageRoot, io) {
18067
18017
  config = setPersistentSeatEngineModel(config, seat, model);
18068
18018
  } catch (error) {
18069
18019
  throw new CliUsageError(
18070
- error instanceof Error ? error.message : String(error),
18020
+ errorText(error),
18071
18021
  { cause: error }
18072
18022
  );
18073
18023
  }
@@ -18088,7 +18038,7 @@ async function runConfigCommand(args, home, packageRoot, io) {
18088
18038
  config = setPersistentSeatEngineModel(config, seat, void 0);
18089
18039
  } catch (error) {
18090
18040
  throw new CliUsageError(
18091
- error instanceof Error ? error.message : String(error),
18041
+ errorText(error),
18092
18042
  { cause: error }
18093
18043
  );
18094
18044
  }
@@ -18356,6 +18306,7 @@ var init_cli = __esm({
18356
18306
  init_run_lifecycle();
18357
18307
  init_registry();
18358
18308
  init_settlement();
18309
+ init_unknown_value();
18359
18310
  init_role_turn_host();
18360
18311
  init_cli_errors();
18361
18312
  PUBLIC_ROLE_ARGV = Object.fromEntries(
@@ -18614,9 +18565,9 @@ async function summonPublicRole(options) {
18614
18565
  Promise.resolve().then(() => (init_cli(), cli_exports))
18615
18566
  ]);
18616
18567
  const { packagedRoleMetadata: packagedRoleMetadata2 } = await Promise.resolve().then(() => (init_packaged_role_registry(), packaged_role_registry_exports));
18617
- const record4 = packagedRoleMetadata2(options.role);
18568
+ const record = packagedRoleMetadata2(options.role);
18618
18569
  const parse = ((args) => PUBLIC_ROLE_ARGV2[options.role].parse(args));
18619
- const resumeRunId = record4?.summonResume === true && typeof options.resumeRunId === "string" && options.resumeRunId.trim() !== "" ? options.resumeRunId.trim() : void 0;
18570
+ const resumeRunId = record?.summonResume === true && typeof options.resumeRunId === "string" && options.resumeRunId.trim() !== "" ? options.resumeRunId.trim() : void 0;
18620
18571
  let result;
18621
18572
  if (resumeRunId !== void 0) {
18622
18573
  const instruction = options.argv[0] ?? "";
@@ -18669,7 +18620,7 @@ async function summonParallelReviewerLenses(options) {
18669
18620
  if (error instanceof AggregateError) {
18670
18621
  return [error.message, ...error.errors.map(describeFailure)].join("\n");
18671
18622
  }
18672
- return error instanceof Error ? error.message : String(error);
18623
+ return errorText(error);
18673
18624
  };
18674
18625
  const failedResult = (error) => ({
18675
18626
  exitCode: 1,
@@ -18850,7 +18801,7 @@ async function summonGateOfficer(options) {
18850
18801
  const correlationId = parentRunId;
18851
18802
  const { isSafePositiveTicketNumber: isSafePositiveTicketNumber3, readBoardTicketNumber: readBoardTicketNumber2 } = await Promise.resolve().then(() => (init_run_ticket_number(), run_ticket_number_exports));
18852
18803
  const parentTicket = await readBoardTicketNumber2(options.sourceRunDirectory);
18853
- const submittedTicket = options.submission !== null && typeof options.submission === "object" && !Array.isArray(options.submission) ? options.submission.ticketNumber : void 0;
18804
+ const submittedTicket = isRecord(options.submission) ? options.submission.ticketNumber : void 0;
18854
18805
  const courtTicket = isSafePositiveTicketNumber3(submittedTicket) ? submittedTicket : parentTicket;
18855
18806
  const instruction = options.reask ?? gateReviewInstruction ?? "";
18856
18807
  return summonPublicRole({
@@ -18872,6 +18823,7 @@ var AK_ROLE_PACKAGE_ROOT_ENV, execFileAsync3;
18872
18823
  var init_public_role_summons = __esm({
18873
18824
  "src/public-role-summons.ts"() {
18874
18825
  "use strict";
18826
+ init_unknown_value();
18875
18827
  AK_ROLE_PACKAGE_ROOT_ENV = "AK_ROLE_PACKAGE_ROOT";
18876
18828
  execFileAsync3 = promisify3(execFile3);
18877
18829
  }
@@ -18882,7 +18834,7 @@ function readListField(value) {
18882
18834
  return Array.isArray(value) ? value : value === void 0 ? [] : [value];
18883
18835
  }
18884
18836
  function tryReadComplianceCandidate(arguments_, usage) {
18885
- if (typeof arguments_ !== "object" || arguments_ === null || Array.isArray(arguments_)) {
18837
+ if (!isRecord(arguments_)) {
18886
18838
  return void 0;
18887
18839
  }
18888
18840
  const args = arguments_;
@@ -19003,6 +18955,7 @@ var init_compliance_transport = __esm({
19003
18955
  init_submission_errors();
19004
18956
  init_terminal();
19005
18957
  init_readable_gate_item();
18958
+ init_unknown_value();
19006
18959
  AUDITOR_DOSSIER_PROMPT = "\u5377\u5B97\u6307\u9488\uFF1A";
19007
18960
  AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE = "ak_auditor_parent_attempt_binding";
19008
18961
  AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE = "ak_auditor_compliance_failure";
@@ -19043,26 +18996,23 @@ function rewriteRunDirectoryPathValueAgainstRewrites(value, rewrites) {
19043
18996
  best.newRunDirectory
19044
18997
  );
19045
18998
  }
19046
- function rewriteRunDirectoryPathFields(record4, fields, oldRunDirectory, newRunDirectory) {
19047
- rewriteRunDirectoryPathFieldsAgainstRewrites(record4, fields, [
18999
+ function rewriteRunDirectoryPathFields(record, fields, oldRunDirectory, newRunDirectory) {
19000
+ rewriteRunDirectoryPathFieldsAgainstRewrites(record, fields, [
19048
19001
  { oldRunDirectory, newRunDirectory }
19049
19002
  ]);
19050
19003
  }
19051
- function rewriteRunDirectoryPathFieldsAgainstRewrites(record4, fields, rewrites) {
19004
+ function rewriteRunDirectoryPathFieldsAgainstRewrites(record, fields, rewrites) {
19052
19005
  for (const field of fields) {
19053
- if (field in record4) {
19054
- record4[field] = rewriteRunDirectoryPathValueAgainstRewrites(
19055
- record4[field],
19006
+ if (field in record) {
19007
+ record[field] = rewriteRunDirectoryPathValueAgainstRewrites(
19008
+ record[field],
19056
19009
  rewrites
19057
19010
  );
19058
19011
  }
19059
19012
  }
19060
19013
  }
19061
- function isPlainObject(value) {
19062
- return value !== null && typeof value === "object" && !Array.isArray(value);
19063
- }
19064
19014
  function rewriteSourceRunLocator(value, rewrites) {
19065
- if (!isPlainObject(value)) return;
19015
+ if (!isRecord(value)) return;
19066
19016
  rewriteRunDirectoryPathFieldsAgainstRewrites(
19067
19017
  value,
19068
19018
  SOURCE_RUN_LOCATOR_FIELDS,
@@ -19074,12 +19024,12 @@ function rewriteAdmittedRoleRunPage(page, rewrites) {
19074
19024
  rewriteSourceRunLocator(page.sourceRun, rewrites);
19075
19025
  if (Array.isArray(page.attachments)) {
19076
19026
  for (const attachment of page.attachments) {
19077
- if (isPlainObject(attachment)) {
19027
+ if (isRecord(attachment)) {
19078
19028
  rewriteRunDirectoryPathFieldsAgainstRewrites(attachment, ["frozenPath"], rewrites);
19079
19029
  }
19080
19030
  }
19081
19031
  }
19082
- if (isPlainObject(page.principal)) {
19032
+ if (isRecord(page.principal)) {
19083
19033
  rewriteRunDirectoryPathFieldsAgainstRewrites(
19084
19034
  page.principal,
19085
19035
  ["sessionDirectory", "sessionFile"],
@@ -19092,6 +19042,7 @@ var init_role_run_relocation = __esm({
19092
19042
  "src/role-run-relocation.ts"() {
19093
19043
  "use strict";
19094
19044
  init_compliance_transport();
19045
+ init_unknown_value();
19095
19046
  ADMITTED_PAGE_FIELDS = [
19096
19047
  "runDirectory",
19097
19048
  "admittedRequestPath",
@@ -19167,8 +19118,8 @@ async function readTypedHttp429Observation(runDirectory) {
19167
19118
  function renderResumeCommand(runId) {
19168
19119
  return `ak-role resume ${runId}`;
19169
19120
  }
19170
- async function writeRoleRunState(runDirectory, record4) {
19171
- const payload = { ...record4, runDirectory };
19121
+ async function writeRoleRunState(runDirectory, record) {
19122
+ const payload = { ...record, runDirectory };
19172
19123
  await writeFile8(
19173
19124
  join39(runDirectory, RUN_STATE_FILE),
19174
19125
  `${JSON.stringify(payload, null, 2)}
@@ -19177,15 +19128,15 @@ async function writeRoleRunState(runDirectory, record4) {
19177
19128
  );
19178
19129
  }
19179
19130
  function parseSameTicketSummonsMaterials(raw) {
19180
- if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return void 0;
19181
- const record4 = raw;
19182
- const instruction = typeof record4.instruction === "string" ? record4.instruction : void 0;
19183
- const instructionEmpty = typeof record4.instructionEmpty === "boolean" ? record4.instructionEmpty : void 0;
19184
- const attachmentPaths = Array.isArray(record4.attachmentPaths) ? record4.attachmentPaths.filter((p) => typeof p === "string" && p.length > 0) : void 0;
19185
- const sourceRunPath = typeof record4.sourceRunPath === "string" && record4.sourceRunPath.trim() !== "" ? record4.sourceRunPath : void 0;
19131
+ if (!isRecord(raw)) return void 0;
19132
+ const record = raw;
19133
+ const instruction = typeof record.instruction === "string" ? record.instruction : void 0;
19134
+ const instructionEmpty = typeof record.instructionEmpty === "boolean" ? record.instructionEmpty : void 0;
19135
+ const attachmentPaths = Array.isArray(record.attachmentPaths) ? record.attachmentPaths.filter((p) => typeof p === "string" && p.length > 0) : void 0;
19136
+ const sourceRunPath = typeof record.sourceRunPath === "string" && record.sourceRunPath.trim() !== "" ? record.sourceRunPath : void 0;
19186
19137
  let sourceRun;
19187
- if (record4.sourceRun !== null && typeof record4.sourceRun === "object" && !Array.isArray(record4.sourceRun)) {
19188
- const sr = record4.sourceRun;
19138
+ if (isRecord(record.sourceRun)) {
19139
+ const sr = record.sourceRun;
19189
19140
  if (typeof sr.runId === "string" && sr.runId.trim() !== "" && typeof sr.role === "string" && sr.role.trim() !== "" && typeof sr.runDirectory === "string" && sr.runDirectory.trim() !== "") {
19190
19141
  sourceRun = {
19191
19142
  runId: sr.runId,
@@ -19206,14 +19157,14 @@ function parseSameTicketSummonsMaterials(raw) {
19206
19157
  };
19207
19158
  }
19208
19159
  function parseCurrentCourtState(raw) {
19209
- if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return void 0;
19210
- const record4 = raw;
19211
- if (typeof record4.courtAttemptId !== "string" || record4.courtAttemptId.length === 0) {
19160
+ if (!isRecord(raw)) return void 0;
19161
+ const record = raw;
19162
+ if (typeof record.courtAttemptId !== "string" || record.courtAttemptId.length === 0) {
19212
19163
  return void 0;
19213
19164
  }
19214
- const summons = parseSameTicketSummonsMaterials(record4.summons);
19165
+ const summons = parseSameTicketSummonsMaterials(record.summons);
19215
19166
  return {
19216
- courtAttemptId: record4.courtAttemptId,
19167
+ courtAttemptId: record.courtAttemptId,
19217
19168
  ...summons === void 0 ? {} : { summons }
19218
19169
  };
19219
19170
  }
@@ -19228,26 +19179,26 @@ async function readRoleRunStateRaw(runDirectory) {
19228
19179
  return raw;
19229
19180
  }
19230
19181
  function parseRoleRunIdentity(raw, runDirectory) {
19231
- if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
19182
+ if (!isRecord(raw)) {
19232
19183
  throw new TypeError("Invalid run-state.json");
19233
19184
  }
19234
- const record4 = raw;
19235
- if (typeof record4.runId !== "string" || record4.runId.trim() === "") {
19185
+ const record = raw;
19186
+ if (typeof record.runId !== "string" || record.runId.trim() === "") {
19236
19187
  throw new TypeError("Invalid run-state.json");
19237
19188
  }
19238
- const role = typeof record4.role === "string" ? packagedRoleMetadata(record4.role)?.role : void 0;
19189
+ const role = typeof record.role === "string" ? packagedRoleMetadata(record.role)?.role : void 0;
19239
19190
  if (role === void 0) {
19240
19191
  throw new TypeError("Invalid run-state.json");
19241
19192
  }
19242
- if (record4.state !== "admitted" && record4.state !== "running" && record4.state !== "resumable" && record4.state !== "terminal") {
19193
+ if (record.state !== "admitted" && record.state !== "running" && record.state !== "resumable" && record.state !== "terminal") {
19243
19194
  throw new TypeError("Invalid run-state.json");
19244
19195
  }
19245
- if (typeof record4.bookKey !== "string") throw new TypeError("Invalid run-state.json");
19196
+ if (typeof record.bookKey !== "string") throw new TypeError("Invalid run-state.json");
19246
19197
  return {
19247
- runId: record4.runId,
19198
+ runId: record.runId,
19248
19199
  role,
19249
- state: record4.state,
19250
- bookKey: record4.bookKey,
19200
+ state: record.state,
19201
+ bookKey: record.bookKey,
19251
19202
  runDirectory
19252
19203
  };
19253
19204
  }
@@ -19255,40 +19206,40 @@ async function readRoleRunStateDisk(runDirectory) {
19255
19206
  const raw = await readRoleRunStateRaw(runDirectory);
19256
19207
  if (raw === void 0) return void 0;
19257
19208
  const identity = parseRoleRunIdentity(raw, runDirectory);
19258
- const record4 = raw;
19259
- if (typeof record4.projectRoot !== "string") throw new TypeError("Invalid run-state.json");
19260
- if (typeof record4.sessionDirectory !== "string") throw new TypeError("Invalid run-state.json");
19261
- if (typeof record4.admittedRequestPath !== "string") throw new TypeError("Invalid run-state.json");
19262
- const storedRunDirectory = typeof record4.runDirectory === "string" && record4.runDirectory.trim() !== "" ? record4.runDirectory : runDirectory;
19209
+ const record = raw;
19210
+ if (typeof record.projectRoot !== "string") throw new TypeError("Invalid run-state.json");
19211
+ if (typeof record.sessionDirectory !== "string") throw new TypeError("Invalid run-state.json");
19212
+ if (typeof record.admittedRequestPath !== "string") throw new TypeError("Invalid run-state.json");
19213
+ const storedRunDirectory = typeof record.runDirectory === "string" && record.runDirectory.trim() !== "" ? record.runDirectory : runDirectory;
19263
19214
  const runDir = runDirectory;
19264
19215
  const principalWire = {
19265
19216
  sessionDirectory: rewriteRunDirectoryPathValue(
19266
- record4.sessionDirectory,
19217
+ record.sessionDirectory,
19267
19218
  storedRunDirectory,
19268
19219
  runDirectory
19269
19220
  ),
19270
- ...typeof record4.sessionFile === "string" ? { sessionFile: rewriteRunDirectoryPathValue(record4.sessionFile, storedRunDirectory, runDirectory) } : {}
19221
+ ...typeof record.sessionFile === "string" ? { sessionFile: rewriteRunDirectoryPathValue(record.sessionFile, storedRunDirectory, runDirectory) } : {}
19271
19222
  };
19272
19223
  let resumable;
19273
- if (record4.resumable !== void 0 && record4.resumable !== null) {
19274
- if (typeof record4.resumable === "object" && !Array.isArray(record4.resumable)) {
19275
- const r = record4.resumable;
19224
+ if (record.resumable !== void 0 && record.resumable !== null) {
19225
+ if (isRecord(record.resumable)) {
19226
+ const r = record.resumable;
19276
19227
  if (r.httpStatus === 429 && typeof r.provider === "string" && isV1ResumableProvider(r.provider)) {
19277
19228
  resumable = { httpStatus: 429, provider: r.provider };
19278
19229
  }
19279
19230
  }
19280
19231
  }
19281
- const phase = record4.phase === "plan" || record4.phase === "apply" ? record4.phase : void 0;
19282
- const currentCourt = parseCurrentCourtState(record4.currentCourt);
19232
+ const phase = record.phase === "plan" || record.phase === "apply" ? record.phase : void 0;
19233
+ const currentCourt = parseCurrentCourtState(record.currentCourt);
19283
19234
  return {
19284
19235
  runId: identity.runId,
19285
19236
  role: identity.role,
19286
19237
  state: identity.state,
19287
19238
  bookKey: identity.bookKey,
19288
- projectRoot: record4.projectRoot,
19239
+ projectRoot: record.projectRoot,
19289
19240
  runDirectory: runDir,
19290
19241
  admittedRequestPath: rewriteRunDirectoryPathValue(
19291
- record4.admittedRequestPath,
19242
+ record.admittedRequestPath,
19292
19243
  storedRunDirectory,
19293
19244
  runDirectory
19294
19245
  ),
@@ -19354,8 +19305,8 @@ async function readRoleRunIdentity(runDirectory) {
19354
19305
  }
19355
19306
  async function markRunAdmitted(admitted, authority) {
19356
19307
  const { sessionDirectory, sessionFile } = authority.decode(admitted.principal);
19357
- const record4 = packagedRoleMetadata(admitted.role);
19358
- const workerPhase = record4 !== void 0 && "worker" in record4 && record4.worker === true && "phase" in admitted ? admitted.phase : void 0;
19308
+ const record = packagedRoleMetadata(admitted.role);
19309
+ const workerPhase = record !== void 0 && "worker" in record && record.worker === true && "phase" in admitted ? admitted.phase : void 0;
19359
19310
  await writeRoleRunState(admitted.runDirectory, {
19360
19311
  runId: admitted.runId,
19361
19312
  role: admitted.role,
@@ -19681,15 +19632,15 @@ async function readRunParentPath(runDirectory) {
19681
19632
  if (errorCodeOf(error) === "ENOENT") return void 0;
19682
19633
  throw error;
19683
19634
  }
19684
- if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
19635
+ if (!isRecord(raw)) {
19685
19636
  return void 0;
19686
19637
  }
19687
- const record4 = raw;
19688
- if (typeof record4.sourceRunPath === "string" && record4.sourceRunPath.trim() !== "") {
19689
- return record4.sourceRunPath;
19638
+ const record = raw;
19639
+ if (typeof record.sourceRunPath === "string" && record.sourceRunPath.trim() !== "") {
19640
+ return record.sourceRunPath;
19690
19641
  }
19691
- if (typeof record4.instruction === "string") {
19692
- return parentRunPathFromGatePointerInstruction(record4.instruction);
19642
+ if (typeof record.instruction === "string") {
19643
+ return parentRunPathFromGatePointerInstruction(record.instruction);
19693
19644
  }
19694
19645
  return void 0;
19695
19646
  }
@@ -19734,9 +19685,9 @@ async function findLatestRunIdForSeatTicket(input) {
19734
19685
  }
19735
19686
  return best;
19736
19687
  }
19737
- function parsePersistedTicketIdentity(record4) {
19738
- const correlationId = typeof record4.correlationId === "string" && record4.correlationId.trim() !== "" ? record4.correlationId : void 0;
19739
- const ticketNumber = isSafePositiveTicketNumber(record4.ticketNumber) ? record4.ticketNumber : void 0;
19688
+ function parsePersistedTicketIdentity(record) {
19689
+ const correlationId = typeof record.correlationId === "string" && record.correlationId.trim() !== "" ? record.correlationId : void 0;
19690
+ const ticketNumber = isSafePositiveTicketNumber(record.ticketNumber) ? record.ticketNumber : void 0;
19740
19691
  return {
19741
19692
  ...correlationId === void 0 ? {} : { correlationId },
19742
19693
  ...ticketNumber === void 0 ? {} : { ticketNumber }
@@ -19792,78 +19743,78 @@ async function loadResumableRunRecord(home, runId, authority) {
19792
19743
  const raw = JSON.parse(
19793
19744
  await readFile22(run.admittedRequestPath, "utf8")
19794
19745
  );
19795
- if (raw !== null && typeof raw === "object" && !Array.isArray(raw)) {
19796
- const record4 = raw;
19797
- const storedRunDirectory = typeof record4.runDirectory === "string" && record4.runDirectory.trim() !== "" ? record4.runDirectory : run.runDirectory;
19798
- rewriteAdmittedRoleRunPage(record4, [{
19746
+ if (isRecord(raw)) {
19747
+ const record = raw;
19748
+ const storedRunDirectory = typeof record.runDirectory === "string" && record.runDirectory.trim() !== "" ? record.runDirectory : run.runDirectory;
19749
+ rewriteAdmittedRoleRunPage(record, [{
19799
19750
  oldRunDirectory: storedRunDirectory,
19800
19751
  newRunDirectory: run.runDirectory
19801
19752
  }]);
19802
- if (typeof record4.instruction === "string") {
19803
- instruction = record4.instruction;
19753
+ if (typeof record.instruction === "string") {
19754
+ instruction = record.instruction;
19804
19755
  }
19805
- if (typeof record4.instructionEmpty === "boolean") {
19806
- instructionEmpty = record4.instructionEmpty;
19756
+ if (typeof record.instructionEmpty === "boolean") {
19757
+ instructionEmpty = record.instructionEmpty;
19807
19758
  }
19808
- if (Array.isArray(record4.attachments)) {
19809
- attachments = record4.attachments;
19759
+ if (Array.isArray(record.attachments)) {
19760
+ attachments = record.attachments;
19810
19761
  }
19811
- if (record4.phase === "plan" || record4.phase === "apply") {
19812
- phase = record4.phase;
19762
+ if (record.phase === "plan" || record.phase === "apply") {
19763
+ phase = record.phase;
19813
19764
  }
19814
- if (typeof record4.taskPath === "string" && record4.taskPath.trim() !== "") {
19815
- taskPath = record4.taskPath;
19765
+ if (typeof record.taskPath === "string" && record.taskPath.trim() !== "") {
19766
+ taskPath = record.taskPath;
19816
19767
  }
19817
- if (typeof record4.packetPath === "string" && record4.packetPath.trim() !== "") {
19818
- packetPath = record4.packetPath;
19768
+ if (typeof record.packetPath === "string" && record.packetPath.trim() !== "") {
19769
+ packetPath = record.packetPath;
19819
19770
  }
19820
- if (typeof record4.prerequisitesPath === "string" && record4.prerequisitesPath.trim() !== "") {
19821
- prerequisitesPath = record4.prerequisitesPath;
19771
+ if (typeof record.prerequisitesPath === "string" && record.prerequisitesPath.trim() !== "") {
19772
+ prerequisitesPath = record.prerequisitesPath;
19822
19773
  }
19823
- if (Array.isArray(record4.prerequisites)) {
19824
- prerequisites = record4.prerequisites;
19774
+ if (Array.isArray(record.prerequisites)) {
19775
+ prerequisites = record.prerequisites;
19825
19776
  }
19826
- if (typeof record4.baseRevision === "string" && record4.baseRevision.trim() !== "") {
19827
- baseRevision = record4.baseRevision;
19777
+ if (typeof record.baseRevision === "string" && record.baseRevision.trim() !== "") {
19778
+ baseRevision = record.baseRevision;
19828
19779
  }
19829
- if (isReviewerLens(record4.lens)) {
19830
- lens = record4.lens;
19780
+ if (isReviewerLens(record.lens)) {
19781
+ lens = record.lens;
19831
19782
  }
19832
- if (typeof record4.prNumber === "number" && Number.isSafeInteger(record4.prNumber) && record4.prNumber >= 1) {
19833
- prNumber = record4.prNumber;
19783
+ if (typeof record.prNumber === "number" && Number.isSafeInteger(record.prNumber) && record.prNumber >= 1) {
19784
+ prNumber = record.prNumber;
19834
19785
  }
19835
- if (typeof record4.repository === "string" && record4.repository.trim() !== "") {
19836
- repository = record4.repository;
19786
+ if (typeof record.repository === "string" && record.repository.trim() !== "") {
19787
+ repository = record.repository;
19837
19788
  }
19838
- if (typeof record4.repositoryDisplay === "string" && record4.repositoryDisplay.trim() !== "") {
19839
- repositoryDisplay = record4.repositoryDisplay;
19789
+ if (typeof record.repositoryDisplay === "string" && record.repositoryDisplay.trim() !== "") {
19790
+ repositoryDisplay = record.repositoryDisplay;
19840
19791
  }
19841
- if (typeof record4.requestManifestPath === "string" && record4.requestManifestPath.trim() !== "") {
19842
- requestManifestPath = record4.requestManifestPath;
19792
+ if (typeof record.requestManifestPath === "string" && record.requestManifestPath.trim() !== "") {
19793
+ requestManifestPath = record.requestManifestPath;
19843
19794
  }
19844
- if (typeof record4.manifestDigest === "string" && record4.manifestDigest.trim() !== "") {
19845
- manifestDigest = record4.manifestDigest;
19795
+ if (typeof record.manifestDigest === "string" && record.manifestDigest.trim() !== "") {
19796
+ manifestDigest = record.manifestDigest;
19846
19797
  }
19847
- if (typeof record4.waitWindowMs === "number" && Number.isSafeInteger(record4.waitWindowMs) && record4.waitWindowMs >= 1) {
19848
- waitWindowMs = record4.waitWindowMs;
19798
+ if (typeof record.waitWindowMs === "number" && Number.isSafeInteger(record.waitWindowMs) && record.waitWindowMs >= 1) {
19799
+ waitWindowMs = record.waitWindowMs;
19849
19800
  }
19850
- if (typeof record4.issueNumber === "number" && Number.isSafeInteger(record4.issueNumber) && record4.issueNumber >= 1) {
19851
- issueNumber = record4.issueNumber;
19801
+ if (typeof record.issueNumber === "number" && Number.isSafeInteger(record.issueNumber) && record.issueNumber >= 1) {
19802
+ issueNumber = record.issueNumber;
19852
19803
  }
19853
- if (typeof record4.caseRunsPath === "string" && record4.caseRunsPath.trim() !== "") {
19854
- caseRunsPath = record4.caseRunsPath;
19804
+ if (typeof record.caseRunsPath === "string" && record.caseRunsPath.trim() !== "") {
19805
+ caseRunsPath = record.caseRunsPath;
19855
19806
  }
19856
- if (record4.caseIdentity !== null && typeof record4.caseIdentity === "object" && !Array.isArray(record4.caseIdentity)) {
19857
- const ci = record4.caseIdentity;
19807
+ if (isRecord(record.caseIdentity)) {
19808
+ const ci = record.caseIdentity;
19858
19809
  if (typeof ci.issueNumber === "number" && Number.isSafeInteger(ci.issueNumber) && ci.issueNumber >= 1 && typeof ci.runsPath === "string" && ci.runsPath.trim() !== "") {
19859
19810
  caseIdentity = { issueNumber: ci.issueNumber, runsPath: ci.runsPath };
19860
19811
  }
19861
19812
  }
19862
- if (typeof record4.sourceRunPath === "string" && record4.sourceRunPath.trim() !== "") {
19863
- sourceRunPath = record4.sourceRunPath;
19813
+ if (typeof record.sourceRunPath === "string" && record.sourceRunPath.trim() !== "") {
19814
+ sourceRunPath = record.sourceRunPath;
19864
19815
  }
19865
- if (record4.sourceRun !== null && typeof record4.sourceRun === "object" && !Array.isArray(record4.sourceRun)) {
19866
- const sr = record4.sourceRun;
19816
+ if (isRecord(record.sourceRun)) {
19817
+ const sr = record.sourceRun;
19867
19818
  if (typeof sr.runId === "string" && sr.runId.trim() !== "" && typeof sr.role === "string" && sr.role.trim() !== "" && typeof sr.runDirectory === "string" && sr.runDirectory.trim() !== "") {
19868
19819
  sourceRun = {
19869
19820
  runId: sr.runId,
@@ -19872,9 +19823,9 @@ async function loadResumableRunRecord(home, runId, authority) {
19872
19823
  };
19873
19824
  }
19874
19825
  }
19875
- if (Array.isArray(record4.authorityRefs)) {
19826
+ if (Array.isArray(record.authorityRefs)) {
19876
19827
  authorityRefs = Object.freeze(
19877
- record4.authorityRefs.map((ref) => {
19828
+ record.authorityRefs.map((ref) => {
19878
19829
  if (typeof ref !== "string") {
19879
19830
  throw new CliUsageError(
19880
19831
  "role run admitted authority refs must be durable reference strings"
@@ -19884,11 +19835,11 @@ async function loadResumableRunRecord(home, runId, authority) {
19884
19835
  })
19885
19836
  );
19886
19837
  }
19887
- if (typeof record4.mergerInputPath === "string" && record4.mergerInputPath.trim() !== "") {
19888
- mergerInputPath = record4.mergerInputPath;
19838
+ if (typeof record.mergerInputPath === "string" && record.mergerInputPath.trim() !== "") {
19839
+ mergerInputPath = record.mergerInputPath;
19889
19840
  }
19890
- if (record4.derived !== null && typeof record4.derived === "object" && !Array.isArray(record4.derived)) {
19891
- const d = record4.derived;
19841
+ if (isRecord(record.derived)) {
19842
+ const d = record.derived;
19892
19843
  if (typeof d.targetObjectId === "string" && typeof d.sourceObjectId === "string" && Array.isArray(d.expectedConflictPaths) && Array.isArray(d.resolutionScope) && d.expectedConflictPaths.every((p) => typeof p === "string") && d.resolutionScope.every((p) => typeof p === "string")) {
19893
19844
  derived = {
19894
19845
  targetObjectId: d.targetObjectId,
@@ -19898,7 +19849,7 @@ async function loadResumableRunRecord(home, runId, authority) {
19898
19849
  };
19899
19850
  }
19900
19851
  }
19901
- const fromAdmitted = parsePersistedTicketIdentity(record4);
19852
+ const fromAdmitted = parsePersistedTicketIdentity(record);
19902
19853
  correlationId = fromAdmitted.correlationId;
19903
19854
  ticketNumber = fromAdmitted.ticketNumber;
19904
19855
  }
@@ -19914,7 +19865,7 @@ async function loadResumableRunRecord(home, runId, authority) {
19914
19865
  const invocationRaw = JSON.parse(
19915
19866
  await readFile22(join39(run.runDirectory, "invocation.json"), "utf8")
19916
19867
  );
19917
- if (invocationRaw !== null && typeof invocationRaw === "object" && !Array.isArray(invocationRaw)) {
19868
+ if (isRecord(invocationRaw)) {
19918
19869
  const rec = invocationRaw;
19919
19870
  if (typeof rec.provider === "string" && typeof rec.model === "string") {
19920
19871
  model = {
@@ -19933,7 +19884,7 @@ async function loadResumableRunRecord(home, runId, authority) {
19933
19884
  if (error instanceof CliUsageError) {
19934
19885
  throw error;
19935
19886
  }
19936
- if (!(error instanceof Error && "code" in error && error.code === "ENOENT")) {
19887
+ if (!isEnoent(error)) {
19937
19888
  throw new CliUsageError(
19938
19889
  `role run invocation identity is unreadable: ${runId}`,
19939
19890
  { cause: error }
@@ -20027,13 +19978,13 @@ async function loadResumablePublicRole(home, runId, authority) {
20027
19978
  function admitResumedRole(loaded) {
20028
19979
  const role = loaded.run.role;
20029
19980
  const runId = loaded.run.runId;
20030
- const record4 = packagedRoleMetadata(role);
20031
- if (record4 === void 0) {
19981
+ const record = packagedRoleMetadata(role);
19982
+ if (record === void 0) {
20032
19983
  throw new CliUsageError(`unknown role: ${role}`);
20033
19984
  }
20034
19985
  const fields = loaded.admittedFields;
20035
19986
  const base = resumedBaseAdmitted(loaded);
20036
- switch (record4.admission) {
19987
+ switch (record.admission) {
20037
19988
  case "instruction": {
20038
19989
  if (packagedResumeSourcePath(role)) {
20039
19990
  const admitted = {
@@ -20056,7 +20007,7 @@ function admitResumedRole(loaded) {
20056
20007
  return admitted;
20057
20008
  }
20058
20009
  case "worker-task": {
20059
- const phase = resumedWorkerPhase(fields.phase ?? loaded.run.phase, record4.phases, role, runId);
20010
+ const phase = resumedWorkerPhase(fields.phase ?? loaded.run.phase, record.phases, role, runId);
20060
20011
  const taskPath = fields.taskPath;
20061
20012
  if (taskPath === void 0) {
20062
20013
  throw new CliUsageError(
@@ -20078,7 +20029,7 @@ function admitResumedRole(loaded) {
20078
20029
  return admitted;
20079
20030
  }
20080
20031
  case "worker-packet": {
20081
- const phase = resumedWorkerPhase(fields.phase ?? loaded.run.phase, record4.phases, role, runId);
20032
+ const phase = resumedWorkerPhase(fields.phase ?? loaded.run.phase, record.phases, role, runId);
20082
20033
  const packetPath = fields.packetPath;
20083
20034
  if (packetPath === void 0) {
20084
20035
  throw new CliUsageError(
@@ -20183,7 +20134,7 @@ function admitResumedRole(loaded) {
20183
20134
  try {
20184
20135
  parsedRepository = parseCollectorRepository(repositoryDisplay);
20185
20136
  } catch (error) {
20186
- const detail = error instanceof Error ? error.message : String(error);
20137
+ const detail = errorText(error);
20187
20138
  throw new CliUsageError(detail, { cause: error });
20188
20139
  }
20189
20140
  if (parsedRepository.canonical !== repository) {
@@ -20258,6 +20209,7 @@ var init_run_lifecycle = __esm({
20258
20209
  init_engine_material();
20259
20210
  init_packaged_role_registry();
20260
20211
  init_invocation();
20212
+ init_unknown_value();
20261
20213
  V1_RESUMABLE_PROVIDERS = ["openai-codex", "xai"];
20262
20214
  AUTO_RESUME_LIMIT = 2;
20263
20215
  RESUME_TRANSPORT_ENVELOPE = "\u7EE7\u7EED\u3002";
@@ -20276,7 +20228,6 @@ var init_run_lifecycle = __esm({
20276
20228
  });
20277
20229
 
20278
20230
  // src/archivist-record-topology.ts
20279
- import { createHash as createHash4 } from "node:crypto";
20280
20231
  import { join as join40 } from "node:path";
20281
20232
  function resolveNavigatorWorkSubjectPlacement(input) {
20282
20233
  let ledgerHome;
@@ -20287,7 +20238,7 @@ function resolveNavigatorWorkSubjectPlacement(input) {
20287
20238
  }
20288
20239
  }
20289
20240
  ledgerHome ??= resolveActivationLedgerHome(input.home);
20290
- const digest = createHash4("sha256").update(input.subject).digest("hex").slice(0, 32);
20241
+ const digest = sha256Hex(input.subject).slice(0, 32);
20291
20242
  return {
20292
20243
  ledgerHome,
20293
20244
  sessionDir: join40(
@@ -20301,6 +20252,7 @@ var NAVIGATOR_RECORD_KIND;
20301
20252
  var init_archivist_record_topology = __esm({
20302
20253
  "src/archivist-record-topology.ts"() {
20303
20254
  "use strict";
20255
+ init_sha256();
20304
20256
  init_activation_ledger_git();
20305
20257
  init_activation_ledger_topology();
20306
20258
  NAVIGATOR_RECORD_KIND = "navigator";
@@ -20666,7 +20618,6 @@ import { readFile as readFile24 } from "node:fs/promises";
20666
20618
  init_doctor_evidence();
20667
20619
 
20668
20620
  // src/navigator-attendance.ts
20669
- import { createHash as createHash5 } from "node:crypto";
20670
20621
  init_navigator_invocation_identity();
20671
20622
  init_packaged_role_registry();
20672
20623
  init_activation_ledger_topology();
@@ -20680,6 +20631,7 @@ import { existsSync as existsSync13 } from "node:fs";
20680
20631
  import { basename as basename11 } from "node:path";
20681
20632
 
20682
20633
  // src/navigator-session-contracts.ts
20634
+ init_unknown_value();
20683
20635
  import { Type as Type10 } from "typebox";
20684
20636
  import { Value as Value2 } from "typebox/value";
20685
20637
  var NAVIGATOR_PREPARE_TOOL_NAME = "ak_navigator_prepare";
@@ -20709,12 +20661,9 @@ var NavigatorUnavailableError = class extends Error {
20709
20661
  }
20710
20662
  };
20711
20663
  function navigatorUnavailableError(source, error, cause = source) {
20712
- const message = error instanceof Error ? error.message : String(error);
20664
+ const message = errorText(error);
20713
20665
  return error instanceof NavigatorUnavailableError ? error : new NavigatorUnavailableError(source, message, cause, error);
20714
20666
  }
20715
- function exactRecord(value) {
20716
- return typeof value === "object" && value !== null && !Array.isArray(value);
20717
- }
20718
20667
  function navigatorProviderFailureFromStatus(status) {
20719
20668
  if (status === 401 || status === 403) return { source: "auth", cause: "auth" };
20720
20669
  if (status === 429) return { source: "quota", cause: "quota" };
@@ -20736,7 +20685,7 @@ function navigatorProviderFailureFromError(error) {
20736
20685
  if (cursor instanceof NavigatorUnavailableError) {
20737
20686
  return { source: cursor.unavailableSource, cause: cursor.unavailableCause };
20738
20687
  }
20739
- if (!exactRecord(cursor)) {
20688
+ if (!isRecord(cursor)) {
20740
20689
  cursor = cursor instanceof Error ? cursor.cause : void 0;
20741
20690
  continue;
20742
20691
  }
@@ -20754,13 +20703,13 @@ function navigatorProviderFailureFromError(error) {
20754
20703
  function navigatorProviderFailureFromDiagnostics(diagnostics) {
20755
20704
  if (!Array.isArray(diagnostics)) return void 0;
20756
20705
  for (const diagnostic of diagnostics) {
20757
- if (!exactRecord(diagnostic)) continue;
20706
+ if (!isRecord(diagnostic)) continue;
20758
20707
  if (diagnostic.type === "provider_transport_failure") return { source: "transport", cause: "transport" };
20759
- if (exactRecord(diagnostic.error)) {
20708
+ if (isRecord(diagnostic.error)) {
20760
20709
  const fromCode = navigatorProviderFailureFromCode(diagnostic.error.code);
20761
20710
  if (fromCode !== void 0) return fromCode;
20762
20711
  }
20763
- if (exactRecord(diagnostic.details)) {
20712
+ if (isRecord(diagnostic.details)) {
20764
20713
  const status = typeof diagnostic.details.status === "number" ? diagnostic.details.status : typeof diagnostic.details.statusCode === "number" ? diagnostic.details.statusCode : void 0;
20765
20714
  const fromStatus = navigatorProviderFailureFromStatus(status);
20766
20715
  if (fromStatus !== void 0) return fromStatus;
@@ -20870,6 +20819,7 @@ init_packaged_role_registry();
20870
20819
 
20871
20820
  // src/navigator-work-base.ts
20872
20821
  init_atomic_write();
20822
+ init_unknown_value();
20873
20823
  import { existsSync as existsSync3, realpathSync as realpathSync2 } from "node:fs";
20874
20824
  import { readFile as readFile5 } from "node:fs/promises";
20875
20825
  import { basename as basename3, dirname as dirname7, join as join8, resolve as resolve5 } from "node:path";
@@ -20903,9 +20853,7 @@ async function persistNavigatorWorkBase(sessionDir, body) {
20903
20853
  const current = await readFile5(path, "utf8");
20904
20854
  if (current === next) return path;
20905
20855
  } catch (error) {
20906
- if (!(error instanceof Error && "code" in error && error.code === "ENOENT")) {
20907
- throw error;
20908
- }
20856
+ if (!isEnoent(error)) throw error;
20909
20857
  }
20910
20858
  await writeFileAtomically(path, next);
20911
20859
  return path;
@@ -20917,9 +20865,7 @@ async function readNavigatorWorkBase(path) {
20917
20865
  try {
20918
20866
  text = await readFile5(canonical, "utf8");
20919
20867
  } catch (error) {
20920
- if (error instanceof Error && "code" in error && error.code === "ENOENT") {
20921
- return void 0;
20922
- }
20868
+ if (isEnoent(error)) return void 0;
20923
20869
  throw error;
20924
20870
  }
20925
20871
  let parsed;
@@ -20928,36 +20874,36 @@ async function readNavigatorWorkBase(path) {
20928
20874
  } catch {
20929
20875
  return void 0;
20930
20876
  }
20931
- if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return void 0;
20932
- const record4 = parsed;
20933
- if (typeof record4.subject !== "string" || typeof record4.authority !== "string") return void 0;
20934
- if (record4.authority.trim() === "") return void 0;
20935
- return { subject: record4.subject, authority: record4.authority };
20877
+ if (!isRecord(parsed)) return void 0;
20878
+ const record = parsed;
20879
+ if (typeof record.subject !== "string" || typeof record.authority !== "string") return void 0;
20880
+ if (record.authority.trim() === "") return void 0;
20881
+ return { subject: record.subject, authority: record.authority };
20936
20882
  }
20937
20883
  function jsonObjectFromPrompt(prompt) {
20938
20884
  const head = prompt.trimStart().split("\n\n", 1)[0] ?? "";
20939
20885
  if (!head.startsWith("{")) return void 0;
20940
20886
  try {
20941
20887
  const parsed = JSON.parse(head);
20942
- if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return void 0;
20888
+ if (!isRecord(parsed)) return void 0;
20943
20889
  return parsed;
20944
20890
  } catch {
20945
20891
  return void 0;
20946
20892
  }
20947
20893
  }
20948
20894
  function workContextPathFromPrompt(prompt) {
20949
- const record4 = jsonObjectFromPrompt(prompt);
20950
- const path = record4?.workContextPath;
20895
+ const record = jsonObjectFromPrompt(prompt);
20896
+ const path = record?.workContextPath;
20951
20897
  if (typeof path !== "string" || path.trim() === "") return void 0;
20952
20898
  return isNavigatorWorkContextFile(path) ? path : void 0;
20953
20899
  }
20954
20900
  function attachWorkContextPointer(text, workContextPath) {
20955
- const record4 = jsonObjectFromPrompt(text);
20956
- if (record4 === void 0) return text;
20957
- if (typeof record4.workContextPath === "string" && record4.workContextPath.trim() !== "") return text;
20901
+ const record = jsonObjectFromPrompt(text);
20902
+ if (record === void 0) return text;
20903
+ if (typeof record.workContextPath === "string" && record.workContextPath.trim() !== "") return text;
20958
20904
  const head = text.trimStart().split("\n\n", 1)[0] ?? "";
20959
20905
  const rest = text.trimStart().slice(head.length);
20960
- return `${JSON.stringify({ ...record4, workContextPath })}${rest}`;
20906
+ return `${JSON.stringify({ ...record, workContextPath })}${rest}`;
20961
20907
  }
20962
20908
  async function loadNavigatorWorkBaseSuffix(prompt) {
20963
20909
  const path = workContextPathFromPrompt(prompt);
@@ -20974,6 +20920,7 @@ ${body.authority}
20974
20920
  }
20975
20921
 
20976
20922
  // src/navigator-public-session.ts
20923
+ init_unknown_value();
20977
20924
  async function resolveNavigatorLedgerHome(context) {
20978
20925
  const { tryHomeFromAkRolesPath: tryHomeFromAkRolesPath2 } = await Promise.resolve().then(() => (init_activation_ledger_topology(), activation_ledger_topology_exports));
20979
20926
  const runDirectory = runDirectoryFromHostContext(context);
@@ -20989,9 +20936,6 @@ async function resolveNavigatorLedgerHome(context) {
20989
20936
  return void 0;
20990
20937
  }
20991
20938
  var NAVIGATOR_HOST_RUN_POINTER_ENTRY = "ak-navigator-host-run";
20992
- function exactRecord2(value) {
20993
- return typeof value === "object" && value !== null && !Array.isArray(value);
20994
- }
20995
20939
  function runIdFromNavigatorDirectory(runDirectory) {
20996
20940
  const entry = basename11(runDirectory);
20997
20941
  const suffix = "@navigator";
@@ -21002,10 +20946,10 @@ function runIdFromNavigatorDirectory(runDirectory) {
21002
20946
  function readNavigatorHostRunPointer(entries) {
21003
20947
  for (let index = entries.length - 1; index >= 0; index -= 1) {
21004
20948
  const entry = entries[index];
21005
- if (!exactRecord2(entry)) continue;
20949
+ if (!isRecord(entry)) continue;
21006
20950
  if (entry.type === "custom" && entry.customType === NAVIGATOR_HOST_RUN_POINTER_ENTRY) {
21007
20951
  const data = entry.data;
21008
- if (exactRecord2(data) && typeof data.runId === "string" && data.runId.trim() !== "") {
20952
+ if (isRecord(data) && typeof data.runId === "string" && data.runId.trim() !== "") {
21009
20953
  return data.runId.trim();
21010
20954
  }
21011
20955
  }
@@ -21185,6 +21129,8 @@ init_sitian_facade();
21185
21129
  init_work_subject_identity();
21186
21130
  init_receipt_delivery_policy();
21187
21131
  init_navigator_output();
21132
+ init_sha256();
21133
+ init_unknown_value();
21188
21134
  var NAVIGATOR_EVENT_TYPE = "ak-navigator-attendance";
21189
21135
  function resolveNavigatorAuthorityMaterial(roleInput, fileAuthority) {
21190
21136
  if (roleInput !== void 0 && roleInput.trim() !== "") return roleInput;
@@ -21199,27 +21145,24 @@ var prepareSchema = Type13.Object({
21199
21145
  }, { additionalProperties: true });
21200
21146
  var INVOCATION_ENTRY = NAVIGATOR_INVOCATION_ENTRY;
21201
21147
  var SETTLEMENT_ENTRY = "ak-navigator-settlement";
21202
- function exactRecord3(value) {
21203
- return typeof value === "object" && value !== null && !Array.isArray(value);
21204
- }
21205
21148
  function rejectedPrepareReason(entries, start) {
21206
21149
  const recent = entries.slice(start);
21207
21150
  const prepareCalls = /* @__PURE__ */ new Set();
21208
21151
  for (const entry of recent) {
21209
- if (!exactRecord3(entry) || entry.type !== "message" || !exactRecord3(entry.message) || entry.message.role !== "assistant" || !Array.isArray(entry.message.content)) continue;
21152
+ if (!isRecord(entry) || entry.type !== "message" || !isRecord(entry.message) || entry.message.role !== "assistant" || !Array.isArray(entry.message.content)) continue;
21210
21153
  for (const part of entry.message.content) {
21211
- if (exactRecord3(part) && part.type === "toolCall" && part.name === NAVIGATOR_PREPARE_TOOL_NAME && typeof part.id === "string") prepareCalls.add(part.id);
21154
+ if (isRecord(part) && part.type === "toolCall" && part.name === NAVIGATOR_PREPARE_TOOL_NAME && typeof part.id === "string") prepareCalls.add(part.id);
21212
21155
  }
21213
21156
  }
21214
21157
  let reason;
21215
21158
  for (const entry of recent) {
21216
- if (!exactRecord3(entry) || entry.type !== "message" || !exactRecord3(entry.message) || entry.message.role !== "toolResult" || entry.message.isError !== true) continue;
21159
+ if (!isRecord(entry) || entry.type !== "message" || !isRecord(entry.message) || entry.message.role !== "toolResult" || entry.message.isError !== true) continue;
21217
21160
  const callId = entry.message.toolCallId;
21218
21161
  if (entry.message.toolName !== NAVIGATOR_PREPARE_TOOL_NAME || typeof callId !== "string" || !prepareCalls.has(callId)) {
21219
21162
  return void 0;
21220
21163
  }
21221
21164
  const content = entry.message.content;
21222
- const text = Array.isArray(content) ? content.flatMap((part) => exactRecord3(part) && typeof part.text === "string" ? [part.text] : []).join("") : typeof content === "string" ? content : "";
21165
+ const text = Array.isArray(content) ? content.flatMap((part) => isRecord(part) && typeof part.text === "string" ? [part.text] : []).join("") : typeof content === "string" ? content : "";
21223
21166
  if (text.trim() !== "") reason = text.trim();
21224
21167
  }
21225
21168
  return reason;
@@ -21232,7 +21175,7 @@ function navigatorSubjectKey(subjectRoot, subject, provenance = "role_input") {
21232
21175
  if (provenance === "placeholder") return subjectRoot;
21233
21176
  const normalized = subject.trim().replace(/\s+/g, " ");
21234
21177
  if (normalized === "") return subjectRoot;
21235
- return `${subjectRoot}#${createHash5("sha256").update(normalized).digest("hex").slice(0, 32)}`;
21178
+ return `${subjectRoot}#${sha256Hex(normalized).slice(0, 32)}`;
21236
21179
  }
21237
21180
  function navigatorSubjectKeyForInput(subjectRoot, reference, cwd = process.cwd()) {
21238
21181
  if (issueRoot(subjectRoot) !== void 0 || !subjectRoot.includes("/.ak/work/")) return subjectRoot;
@@ -21454,10 +21397,10 @@ function createNavigatorAttendance(options) {
21454
21397
  return void 0;
21455
21398
  }
21456
21399
  const nativeFailure = [...activeSession.entries()].reverse().find((entry) => {
21457
- if (!exactRecord3(entry) || entry.type !== "message" || !exactRecord3(entry.message)) return false;
21400
+ if (!isRecord(entry) || entry.type !== "message" || !isRecord(entry.message)) return false;
21458
21401
  return entry.message.role === "assistant" && typeof entry.message.errorMessage === "string" && entry.message.errorMessage.trim() !== "";
21459
21402
  });
21460
- const nativeMessage = exactRecord3(nativeFailure) && exactRecord3(nativeFailure.message) ? nativeFailure.message : void 0;
21403
+ const nativeMessage = isRecord(nativeFailure) && isRecord(nativeFailure.message) ? nativeFailure.message : void 0;
21461
21404
  const errorMessage = nativeMessage !== void 0 && typeof nativeMessage.errorMessage === "string" ? nativeMessage.errorMessage : "Navigator did not submit direction advice";
21462
21405
  const providerFailure = activeSession.providerFailure?.();
21463
21406
  const source = providerFailure?.source ?? "unknown";
@@ -21632,6 +21575,7 @@ function createNavigatorAttendance(options) {
21632
21575
 
21633
21576
  // src/navigator-work-context.ts
21634
21577
  init_doctor_evidence();
21578
+ init_unknown_value();
21635
21579
  init_host_contracts();
21636
21580
  import { readFile as readFile23 } from "node:fs/promises";
21637
21581
  import { resolve as resolve18 } from "node:path";
@@ -21710,7 +21654,7 @@ async function loadNavigatorWorkContext(options) {
21710
21654
  break;
21711
21655
  }
21712
21656
  } catch (error) {
21713
- if (!(error instanceof Error && "code" in error && error.code === "ENOENT")) throw error;
21657
+ if (!isEnoent(error)) throw error;
21714
21658
  }
21715
21659
  }
21716
21660
  const authority = resolveNavigatorAuthorityMaterial(input, authorityMaterial);
@@ -21886,8 +21830,8 @@ init_session_opening_materials();
21886
21830
  // src/stderr-jsonl.ts
21887
21831
  import { writeSync } from "node:fs";
21888
21832
  var STDERR_JSONL_WRITE_RETRY_LIMIT = 100;
21889
- function writeStderrJsonlRecord(record4, write = writeSync) {
21890
- const bytes = Buffer.from(`${JSON.stringify(record4)}
21833
+ function writeStderrJsonlRecord(record, write = writeSync) {
21834
+ const bytes = Buffer.from(`${JSON.stringify(record)}
21891
21835
  `);
21892
21836
  let offset = 0;
21893
21837
  let retries = 0;
@@ -22194,6 +22138,7 @@ init_compliance_transport();
22194
22138
  init_dossier_resolution();
22195
22139
  init_doctor_contracts();
22196
22140
  init_sitian_facade();
22141
+ init_unknown_value();
22197
22142
  var DOCTOR_CASE_FLAG = { name: "ak-doctor-case", definition: { description: "Retained .ak-roles/books/<book>/<n>/runs directory", type: "string" } };
22198
22143
  function appendCandidate(ctx, data) {
22199
22144
  try {
@@ -22206,14 +22151,14 @@ function appendCandidate(ctx, data) {
22206
22151
  source: "doctor-role"
22207
22152
  });
22208
22153
  } catch (error) {
22209
- throw new ComplianceResponseRetentionError(`\u592A\u533B\u7F72\u5019\u9009\u7559\u5B58\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
22154
+ throw new ComplianceResponseRetentionError(`\u592A\u533B\u7F72\u5019\u9009\u7559\u5B58\u5931\u8D25: ${errorText(error)}`, { cause: error });
22210
22155
  }
22211
22156
  const append = ctx.sessionManager.appendCustomEntry;
22212
22157
  if (typeof append === "function") {
22213
22158
  try {
22214
22159
  append.call(ctx.sessionManager, DOCTOR_CANDIDATE_ENTRY_TYPE, data);
22215
22160
  } catch (error) {
22216
- throw new ComplianceResponseRetentionError(`\u592A\u533B\u7F72\u5019\u9009\u7559\u5B58\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
22161
+ throw new ComplianceResponseRetentionError(`\u592A\u533B\u7F72\u5019\u9009\u7559\u5B58\u5931\u8D25: ${errorText(error)}`, { cause: error });
22217
22162
  }
22218
22163
  }
22219
22164
  }
@@ -22617,6 +22562,7 @@ init_archivist_record_entry();
22617
22562
  init_sitian_facade();
22618
22563
  init_submission_errors();
22619
22564
  init_worker_submission_contracts();
22565
+ init_unknown_value();
22620
22566
  init_submission_errors();
22621
22567
  init_worker_submission_contracts();
22622
22568
  import { execFileSync as execFileSync3 } from "node:child_process";
@@ -22716,13 +22662,10 @@ function uninstallPackageWorkerHooks(cwd) {
22716
22662
  rmOwnedDir(resolve20(gitDir, HOOKS_DIR));
22717
22663
  }
22718
22664
  }
22719
- function isRecord15(value) {
22720
- return typeof value === "object" && value !== null && !Array.isArray(value);
22721
- }
22722
22665
  function containsWrittenReason(value) {
22723
22666
  if (typeof value === "string") return value.trim().length > 0;
22724
22667
  if (Array.isArray(value)) return value.some(containsWrittenReason);
22725
- if (typeof value === "object" && value !== null) {
22668
+ if (isRecord(value)) {
22726
22669
  return Object.entries(value).some(
22727
22670
  ([key, item]) => containsWrittenReason(key) || containsWrittenReason(item)
22728
22671
  );
@@ -22730,7 +22673,7 @@ function containsWrittenReason(value) {
22730
22673
  return false;
22731
22674
  }
22732
22675
  function unfinishedReasonPresent(details) {
22733
- if (typeof details !== "object" || details === null || Array.isArray(details)) return false;
22676
+ if (!isRecord(details)) return false;
22734
22677
  return containsWrittenReason(details.reason);
22735
22678
  }
22736
22679
  function readGateState(session) {
@@ -22741,7 +22684,7 @@ function readGateState(session) {
22741
22684
  if (entry.type !== "custom") continue;
22742
22685
  if (entry.customType === WORKER_COMMIT_BASELINE_ENTRY_TYPE) {
22743
22686
  const data = entry.data;
22744
- if (isRecord15(data) && (data.head === null || typeof data.head === "string")) {
22687
+ if (isRecord(data) && (data.head === null || typeof data.head === "string")) {
22745
22688
  baseline = data.head;
22746
22689
  }
22747
22690
  } else if (entry.customType === WORKER_COMMIT_REMINDER_BOUNCE_ENTRY_TYPE) {
@@ -22781,7 +22724,7 @@ function createWorkerSubmissionGate(options = {}) {
22781
22724
  let reminded = false;
22782
22725
  let prefixReminded = false;
22783
22726
  let unfinishedReasonBounces = 0;
22784
- let record4;
22727
+ let record;
22785
22728
  let sessionParent;
22786
22729
  const explicitHome = typeof options.home === "string" && options.home.length > 0 ? options.home : void 0;
22787
22730
  const head = (cwd) => {
@@ -22808,12 +22751,12 @@ function createWorkerSubmissionGate(options = {}) {
22808
22751
  uninstallPackageWorkerHooks(cwd);
22809
22752
  root = cwd;
22810
22753
  sessionParent = parent.getSessionFile();
22811
- record4 = createRecordSession({
22754
+ record = createRecordSession({
22812
22755
  cwd,
22813
22756
  kind: WORKER_SUBMISSION_GATE_RECORD_KIND,
22814
22757
  parent
22815
22758
  });
22816
- const prior = readGateState(record4);
22759
+ const prior = readGateState(record);
22817
22760
  if (prior.baseline !== void 0) {
22818
22761
  baseline = prior.baseline;
22819
22762
  reminded = prior.reminded;
@@ -22823,7 +22766,7 @@ function createWorkerSubmissionGate(options = {}) {
22823
22766
  baseline = head(cwd);
22824
22767
  reminded = false;
22825
22768
  prefixReminded = false;
22826
- record4.appendCustomEntry(WORKER_COMMIT_BASELINE_ENTRY_TYPE, {
22769
+ record.appendCustomEntry(WORKER_COMMIT_BASELINE_ENTRY_TYPE, {
22827
22770
  version: 1,
22828
22771
  head: baseline
22829
22772
  });
@@ -22845,7 +22788,7 @@ function createWorkerSubmissionGate(options = {}) {
22845
22788
  const headMoved = now !== null && (baseline === null || now !== baseline);
22846
22789
  if (!headMoved && !reminded) {
22847
22790
  reminded = true;
22848
- record4?.appendCustomEntry(WORKER_COMMIT_REMINDER_BOUNCE_ENTRY_TYPE, { version: 1 });
22791
+ record?.appendCustomEntry(WORKER_COMMIT_REMINDER_BOUNCE_ENTRY_TYPE, { version: 1 });
22849
22792
  gateSitian(root, {
22850
22793
  type: WORKER_COMMIT_REMINDER_BOUNCE_ENTRY_TYPE,
22851
22794
  version: 1
@@ -22859,7 +22802,7 @@ function createWorkerSubmissionGate(options = {}) {
22859
22802
  return;
22860
22803
  }
22861
22804
  prefixReminded = true;
22862
- record4?.appendCustomEntry(WORKER_PREFIX_REMINDER_BOUNCE_ENTRY_TYPE, { version: 1 });
22805
+ record?.appendCustomEntry(WORKER_PREFIX_REMINDER_BOUNCE_ENTRY_TYPE, { version: 1 });
22863
22806
  gateSitian(root, {
22864
22807
  type: WORKER_PREFIX_REMINDER_BOUNCE_ENTRY_TYPE,
22865
22808
  version: 1
@@ -22884,6 +22827,7 @@ function fixerBashSeatbeltDenyReason(matched) {
22884
22827
  }
22885
22828
 
22886
22829
  // src/worker-role.ts
22830
+ init_unknown_value();
22887
22831
  var CODER_STATUS_DESCRIPTION = `planned | completed | refused | partially_completed | unfinished\u3002unfinished\uFF1A\u7F3A\u524D\u7F6E\u6216\u8FDD\u5BAA\u7EA6\u675F\u81F4\u672C\u5C40\u672A\u5B8C\u6210\u3002${PARTIALLY_COMPLETED_DEFINITION}`;
22888
22832
  var coderOutputObject = Type21.Object({
22889
22833
  status: Type21.Unknown({ description: CODER_STATUS_DESCRIPTION }),
@@ -22923,11 +22867,8 @@ var FIXER_PHASES = ["plan", "apply"];
22923
22867
  function isWorkerPhase(value) {
22924
22868
  return typeof value === "string" && FIXER_PHASES.includes(value);
22925
22869
  }
22926
- function isRecord16(value) {
22927
- return typeof value === "object" && value !== null && !Array.isArray(value);
22928
- }
22929
22870
  function workerStatusOf(output) {
22930
- return isRecord16(output) && typeof output.status === "string" ? output.status : void 0;
22871
+ return isRecord(output) && typeof output.status === "string" ? output.status : void 0;
22931
22872
  }
22932
22873
  function deepFreeze2(value) {
22933
22874
  if (typeof value !== "object" || value === null || Object.isFrozen(value)) return value;
@@ -23215,6 +23156,7 @@ init_navigator_invocation_identity();
23215
23156
  init_gatekeeper_role();
23216
23157
  init_submission_errors();
23217
23158
  init_review_submission();
23159
+ init_unknown_value();
23218
23160
  init_doctor_contracts();
23219
23161
  init_doctor_evidence();
23220
23162
  init_judge_role();
@@ -23287,7 +23229,7 @@ function decodeReviewerAdmittedInputs(getFlag) {
23287
23229
  parsed = JSON.parse(rawAuthorityRefs);
23288
23230
  } catch (error) {
23289
23231
  throw new Error(
23290
- `Reviewer authority refs transport error: JSON decode failed: ${error instanceof Error ? error.message : String(error)}`
23232
+ `Reviewer authority refs transport error: JSON decode failed: ${errorText(error)}`
23291
23233
  );
23292
23234
  }
23293
23235
  if (!Array.isArray(parsed) || parsed.some((ref) => typeof ref !== "string")) {
@@ -23325,23 +23267,23 @@ function assembleReviewerParentSystemPrompt(input) {
23325
23267
  ].join("\n");
23326
23268
  }
23327
23269
  function activationStage(role, activate) {
23328
- const record4 = packagedRoleMetadata(role);
23329
- if (record4 === void 0) {
23270
+ const record = packagedRoleMetadata(role);
23271
+ if (record === void 0) {
23330
23272
  throw new Error(`Unsupported workflow role: ${String(role)}`);
23331
23273
  }
23332
23274
  return {
23333
- id: record4.activationStage,
23275
+ id: record.activationStage,
23334
23276
  run: () => activate[role]()
23335
23277
  };
23336
23278
  }
23337
- function validateActivationTraceRecord(record4) {
23338
- if (!Value4.Check(activationTraceRecordSchema, record4)) {
23279
+ function validateActivationTraceRecord(record) {
23280
+ if (!Value4.Check(activationTraceRecordSchema, record)) {
23339
23281
  throw new TypeError("Activation trace record does not match its closed contract");
23340
23282
  }
23341
- return record4;
23283
+ return record;
23342
23284
  }
23343
- async function emitActivationTrace(writeTrace, record4) {
23344
- await writeTrace(validateActivationTraceRecord(record4));
23285
+ async function emitActivationTrace(writeTrace, record) {
23286
+ await writeTrace(validateActivationTraceRecord(record));
23345
23287
  }
23346
23288
  async function executeActivationStage(role, stage, infrastructure) {
23347
23289
  try {
@@ -23361,8 +23303,8 @@ async function executeActivationStage(role, stage, infrastructure) {
23361
23303
  throw activationError;
23362
23304
  }
23363
23305
  }
23364
- function writeActivationTraceRecord(record4, write = writeSync2) {
23365
- writeStderrJsonlRecord(record4, write);
23306
+ function writeActivationTraceRecord(record, write = writeSync2) {
23307
+ writeStderrJsonlRecord(record, write);
23366
23308
  }
23367
23309
  var ActivationBarrierError = class extends Error {
23368
23310
  code = "AK_ACTIVATION_NOT_ADMITTED";
@@ -23420,7 +23362,7 @@ function publicNavigatorSettlement(role, phase, event) {
23420
23362
  if (classification.kind === "infrastructure") {
23421
23363
  return { kind: "role_infrastructure_failure", role, phase };
23422
23364
  }
23423
- const details = typeof event.details === "object" && event.details !== null && !Array.isArray(event.details) ? event.details : {};
23365
+ const details = isRecord(event.details) ? event.details : {};
23424
23366
  const status = typeof details.status === "string" ? details.status : receiptStatusFromRegistry(details);
23425
23367
  if (status !== void 0 && status === "escalate") {
23426
23368
  return { kind: "human_decision", role, phase, status };
@@ -23558,7 +23500,7 @@ function createNavigatorRoleRuntime(roleHost, dependencies) {
23558
23500
  dependencies.recordRoutePlaybookReadFailure?.(void 0);
23559
23501
  if (content.trim() !== "") parts.push(content);
23560
23502
  } catch (error) {
23561
- const message = error instanceof Error ? error.message : String(error);
23503
+ const message = errorText(error);
23562
23504
  if (message.trim() !== "") {
23563
23505
  dependencies.recordRoutePlaybookReadFailure?.(message);
23564
23506
  parts.push(message);
@@ -23651,7 +23593,7 @@ function createDiaristRoleRuntime(roleHost, dependencies) {
23651
23593
  tool: DIARIST_TOOL_SPEC,
23652
23594
  soulTag: "diarist",
23653
23595
  beforeAccept: async ({ parameters, ctx }) => {
23654
- const submitted = parameters !== null && typeof parameters === "object" && !Array.isArray(parameters) ? parameters : void 0;
23596
+ const submitted = isRecord(parameters) ? parameters : void 0;
23655
23597
  const status = submitted?.status;
23656
23598
  if (status !== "completed") return parameters;
23657
23599
  const assertion = readDiaristTicketAssertion(submitted);
@@ -23817,7 +23759,7 @@ function createRoleRuntimeExtension(dependencies) {
23817
23759
  const disposeNavigatorAttendanceNonBlocking = (attendance) => {
23818
23760
  if (attendance === void 0) return;
23819
23761
  const recordDisposeFailure = (error) => {
23820
- const diagnostic = error instanceof Error ? error.message : String(error);
23762
+ const diagnostic = errorText(error);
23821
23763
  try {
23822
23764
  sitianReport({
23823
23765
  level: "event",
@@ -23831,7 +23773,7 @@ function createRoleRuntimeExtension(dependencies) {
23831
23773
  try {
23832
23774
  envelopeHost.appendEntry?.("ak-navigator-dispose-failure", {
23833
23775
  diagnostic,
23834
- recordFailure: recordError instanceof Error ? recordError.message : String(recordError)
23776
+ recordFailure: errorText(recordError)
23835
23777
  });
23836
23778
  } catch {
23837
23779
  }
@@ -24318,9 +24260,7 @@ function createRoleRuntimeExtension(dependencies) {
24318
24260
  try {
24319
24261
  await recordTypedProviderHttpStatus(runDir, { httpStatus: status, provider });
24320
24262
  } catch (error) {
24321
- if (status >= 200 && status < 300 && error instanceof Error && "code" in error && error.code === "ENOENT") {
24322
- return;
24323
- }
24263
+ if (status >= 200 && status < 300 && isEnoent(error)) return;
24324
24264
  failInfrastructure(error, ctx);
24325
24265
  }
24326
24266
  };
@@ -24504,8 +24444,8 @@ init_auditor_soul();
24504
24444
  init_packaged_role_registry();
24505
24445
  init_session_opening_materials();
24506
24446
  function usesSubjectSoul(role) {
24507
- const record4 = packagedRoleMetadata(role);
24508
- return record4 !== void 0 && "soulSource" in record4 && record4.soulSource === "subject";
24447
+ const record = packagedRoleMetadata(role);
24448
+ return record !== void 0 && "soulSource" in record && record.soulSource === "subject";
24509
24449
  }
24510
24450
  function loadPackagedRoleReferenceMaterials(role) {
24511
24451
  return usesSubjectSoul(role) ? loadAuditorReferenceMaterialsFromSubjectInput() : loadMainRoleReferenceMaterials(role);
@@ -24556,6 +24496,7 @@ init_role_activation_flags();
24556
24496
  init_submission_correctable_error();
24557
24497
  init_navigator_invocation_identity();
24558
24498
  init_serialize_thrown_value();
24499
+ init_unknown_value();
24559
24500
  async function listen(server, path) {
24560
24501
  await new Promise((resolve22, reject) => {
24561
24502
  server.once("error", reject);
@@ -24630,7 +24571,7 @@ async function prepareRoleEnvelope(options) {
24630
24571
  try {
24631
24572
  await appendFile3(sessionFile, line2, "utf8");
24632
24573
  } catch (error) {
24633
- const diagnostic = error instanceof Error ? error.message : String(error);
24574
+ const diagnostic = errorText(error);
24634
24575
  armDurableWriteFailure?.(customType, diagnostic);
24635
24576
  }
24636
24577
  });
@@ -24736,10 +24677,10 @@ async function prepareRoleEnvelope(options) {
24736
24677
  const server = createServer((socket) => serveSocket(socket));
24737
24678
  function rememberProjectedRejection(details, toolCallId, content) {
24738
24679
  if (typeof details !== "object" || details === null) return;
24739
- const record4 = details;
24740
- if (record4.cause === "infrastructure") return;
24741
- if (record4.kind === "role_infrastructure_failure") return;
24742
- const code = typeof record4.code === "string" && record4.code.length > 0 ? record4.code : record4.status === "continue" || record4.status === "escalate" || record4.status === "no_receipt" ? record4.status : void 0;
24680
+ const record = details;
24681
+ if (record.cause === "infrastructure") return;
24682
+ if (record.kind === "role_infrastructure_failure") return;
24683
+ const code = typeof record.code === "string" && record.code.length > 0 ? record.code : record.status === "continue" || record.status === "escalate" || record.status === "no_receipt" ? record.status : void 0;
24743
24684
  if (code === void 0) return;
24744
24685
  rejection = {
24745
24686
  code,
@@ -24753,18 +24694,18 @@ async function prepareRoleEnvelope(options) {
24753
24694
  }
24754
24695
  function rememberInfrastructureFailure(details, content) {
24755
24696
  if (infrastructureRoundFailure !== void 0) return;
24756
- const record4 = typeof details === "object" && details !== null && !Array.isArray(details) ? details : void 0;
24757
- const isInfra = record4 !== void 0 && (record4.cause === "infrastructure" || record4.kind === "role_infrastructure_failure");
24697
+ const record = isRecord(details) ? details : void 0;
24698
+ const isInfra = record !== void 0 && (record.cause === "infrastructure" || record.kind === "role_infrastructure_failure");
24758
24699
  if (!isInfra) return;
24759
- const diagnostic = textDiagnostic(content) ?? (typeof record4.code === "string" && record4.code.length > 0 ? record4.code : void 0) ?? "role infrastructure failure";
24700
+ const diagnostic = textDiagnostic(content) ?? (typeof record.code === "string" && record.code.length > 0 ? record.code : void 0) ?? "role infrastructure failure";
24760
24701
  infrastructureRoundFailure = {
24761
24702
  cause: "output",
24762
24703
  identity: {
24763
24704
  name: "InfrastructureFailure",
24764
- code: typeof record4.code === "string" && record4.code.length > 0 ? record4.code : "role-infrastructure-failure"
24705
+ code: typeof record.code === "string" && record.code.length > 0 ? record.code : "role-infrastructure-failure"
24765
24706
  },
24766
24707
  diagnostic,
24767
- details: record4
24708
+ details: record
24768
24709
  };
24769
24710
  hostAbort.abort();
24770
24711
  }
@@ -24780,7 +24721,7 @@ async function prepareRoleEnvelope(options) {
24780
24721
  );
24781
24722
  };
24782
24723
  function declareRoundInfrastructureFailure(error) {
24783
- const diagnostic = error instanceof Error ? error.message : String(error);
24724
+ const diagnostic = errorText(error);
24784
24725
  const content = [{ type: "text", text: diagnostic }];
24785
24726
  const errorCode = typeof error?.code === "string" ? error.code : "ak-tool-execution-failed";
24786
24727
  const details = {
@@ -25047,8 +24988,8 @@ async function prepareRoleEnvelope(options) {
25047
24988
  let prompt = request.continuation.prompt;
25048
24989
  for (const value of inputResults) {
25049
24990
  if (typeof value !== "object" || value === null) continue;
25050
- const record4 = value;
25051
- if (record4.action === "transform" && typeof record4.text === "string") prompt = record4.text;
24991
+ const record = value;
24992
+ if (record.action === "transform" && typeof record.text === "string") prompt = record.text;
25052
24993
  }
25053
24994
  if (typeof prompt === "string" && prompt.trim() !== "") {
25054
24995
  sessionEntries.push({
@@ -25123,6 +25064,7 @@ import { writeFile as writeFile10 } from "node:fs/promises";
25123
25064
  import { dirname as dirname26, isAbsolute as isAbsolute12, join as join45, resolve as resolve21 } from "node:path";
25124
25065
 
25125
25066
  // src/external-host-turn-loop.ts
25067
+ init_unknown_value();
25126
25068
  var EXTERNAL_ROLE_TURN_ROUND_LIMIT = 8;
25127
25069
  function mergeRoleTurnAbortSignals(prepared, request) {
25128
25070
  if (request === void 0) return prepared;
@@ -25144,7 +25086,7 @@ function externalHostFailure(cause, name, code, details, diagnostic) {
25144
25086
  });
25145
25087
  }
25146
25088
  function withExternalHostCleanupFailure(outcome, cleanupError, name) {
25147
- const message = cleanupError instanceof Error ? cleanupError.message : String(cleanupError);
25089
+ const message = errorText(cleanupError);
25148
25090
  if (outcome.knownFailure === void 0) {
25149
25091
  return externalHostFailure("session", name, "dispose-failed", { cleanupError: message }, message);
25150
25092
  }
@@ -25232,6 +25174,7 @@ async function resolveBoundHostSessionId(request, identity) {
25232
25174
  init_host_session_record();
25233
25175
 
25234
25176
  // src/headless-host/description.ts
25177
+ init_unknown_value();
25235
25178
  function isClaudePrintDescription(description) {
25236
25179
  return description.protocol === "claude-print";
25237
25180
  }
@@ -25296,7 +25239,7 @@ var CODEX_JSON_VALUE_SCHEMA = Object.freeze({
25296
25239
  });
25297
25240
  function closeJsonSchemaForCodex(schema) {
25298
25241
  const closed = closeSchemaNode(schema);
25299
- const existingDefs = isPlainObject2(closed.$defs) ? closed.$defs : {};
25242
+ const existingDefs = isRecord(closed.$defs) ? closed.$defs : {};
25300
25243
  return {
25301
25244
  ...closed,
25302
25245
  $defs: {
@@ -25305,11 +25248,8 @@ function closeJsonSchemaForCodex(schema) {
25305
25248
  }
25306
25249
  };
25307
25250
  }
25308
- function isPlainObject2(value) {
25309
- return typeof value === "object" && value !== null && !Array.isArray(value);
25310
- }
25311
25251
  function isPureNullTypeSchema(value) {
25312
- if (!isPlainObject2(value)) return false;
25252
+ if (!isRecord(value)) return false;
25313
25253
  if (value.type === "null") return true;
25314
25254
  if (Array.isArray(value.type) && value.type.length > 0 && value.type.every((t) => t === "null")) {
25315
25255
  return true;
@@ -25317,7 +25257,7 @@ function isPureNullTypeSchema(value) {
25317
25257
  return false;
25318
25258
  }
25319
25259
  function stripNullFromLeafType(leaf) {
25320
- if (!isPlainObject2(leaf) || !Array.isArray(leaf.type)) return leaf;
25260
+ if (!isRecord(leaf) || !Array.isArray(leaf.type)) return leaf;
25321
25261
  const nonNull = leaf.type.filter((t) => t !== "null");
25322
25262
  if (nonNull.length === leaf.type.length) return leaf;
25323
25263
  if (nonNull.length === 0) return { ...leaf, type: "null" };
@@ -25325,7 +25265,7 @@ function stripNullFromLeafType(leaf) {
25325
25265
  return { ...leaf, type: nonNull };
25326
25266
  }
25327
25267
  function flattenUnionLeaves(schema) {
25328
- if (!isPlainObject2(schema)) return [schema];
25268
+ if (!isRecord(schema)) return [schema];
25329
25269
  if (Array.isArray(schema.anyOf)) {
25330
25270
  return schema.anyOf.flatMap(flattenUnionLeaves);
25331
25271
  }
@@ -25335,22 +25275,22 @@ function nonNullLeaves(schema) {
25335
25275
  return flattenUnionLeaves(schema).map(stripNullFromLeafType).filter((leaf) => !isPureNullTypeSchema(leaf));
25336
25276
  }
25337
25277
  function closePropertySchema(schema, optional) {
25338
- const description = isPlainObject2(schema) && typeof schema.description === "string" ? { description: schema.description } : {};
25278
+ const description = isRecord(schema) && typeof schema.description === "string" ? { description: schema.description } : {};
25339
25279
  const leaves = nonNullLeaves(schema).map(closeSchemaNode);
25340
25280
  if (leaves.length === 0) return { type: "null", ...description };
25341
25281
  if (!optional) {
25342
25282
  const closed = leaves.length === 1 ? leaves[0] : { anyOf: leaves };
25343
- if (isPlainObject2(closed) && typeof closed.$ref === "string") {
25283
+ if (isRecord(closed) && typeof closed.$ref === "string") {
25344
25284
  return { anyOf: [closed], ...description };
25345
25285
  }
25346
- return isPlainObject2(closed) ? { ...closed, ...description } : closed;
25286
+ return isRecord(closed) ? { ...closed, ...description } : closed;
25347
25287
  }
25348
25288
  return { anyOf: [...leaves, { type: "null" }], ...description };
25349
25289
  }
25350
25290
  function ensureTypedLeaf(schema) {
25351
25291
  if (schema.type !== void 0) return schema;
25352
25292
  if (typeof schema.$ref === "string") return schema;
25353
- if (isPlainObject2(schema.properties) || schema.additionalProperties !== void 0) {
25293
+ if (isRecord(schema.properties) || schema.additionalProperties !== void 0) {
25354
25294
  return { ...schema, type: "object" };
25355
25295
  }
25356
25296
  if (schema.items !== void 0) {
@@ -25376,7 +25316,7 @@ function originalRequiredNames(node) {
25376
25316
  return new Set(node.required.filter((item) => typeof item === "string"));
25377
25317
  }
25378
25318
  function closeSchemaNode(node) {
25379
- if (!isPlainObject2(node)) return node;
25319
+ if (!isRecord(node)) return node;
25380
25320
  if (typeof node.$ref === "string") return node;
25381
25321
  if (Array.isArray(node.anyOf)) {
25382
25322
  const leaves = nonNullLeaves(node).map(closeSchemaNode);
@@ -25388,12 +25328,12 @@ function closeSchemaNode(node) {
25388
25328
  if (node.items !== void 0) {
25389
25329
  out.items = closeSchemaNode(node.items);
25390
25330
  }
25391
- if (isPlainObject2(node.$defs)) {
25331
+ if (isRecord(node.$defs)) {
25392
25332
  out.$defs = Object.fromEntries(
25393
25333
  Object.entries(node.$defs).map(([key, value]) => [key, closeSchemaNode(value)])
25394
25334
  );
25395
25335
  }
25396
- const hasProperties = isPlainObject2(node.properties);
25336
+ const hasProperties = isRecord(node.properties);
25397
25337
  const isObjectType = node.type === "object" || Array.isArray(node.type) && node.type.includes("object") || hasProperties || node.additionalProperties !== void 0;
25398
25338
  if (hasProperties) {
25399
25339
  const props = node.properties;
@@ -25420,9 +25360,9 @@ function closeSchemaNode(node) {
25420
25360
  }
25421
25361
  function stringEnvironment(value) {
25422
25362
  const entries = Array.isArray(value) ? value.flatMap((item) => {
25423
- if (!isPlainObject2(item) || typeof item.name !== "string" || typeof item.value !== "string") return [];
25363
+ if (!isRecord(item) || typeof item.name !== "string" || typeof item.value !== "string") return [];
25424
25364
  return [[item.name, item.value]];
25425
- }) : isPlainObject2(value) ? Object.entries(value).filter((entry) => typeof entry[1] === "string") : [];
25365
+ }) : isRecord(value) ? Object.entries(value).filter((entry) => typeof entry[1] === "string") : [];
25426
25366
  return entries.length === 0 ? void 0 : Object.fromEntries(entries);
25427
25367
  }
25428
25368
  function codexMcpConfigArgs(mcpServers) {
@@ -25497,10 +25437,11 @@ function headlessMcpConfigDocument(mcpServers) {
25497
25437
 
25498
25438
  // src/headless-host/role-turn-host.ts
25499
25439
  init_navigator_output();
25440
+ init_unknown_value();
25500
25441
  function isHeadlessResultCandidate(value) {
25501
- if (!isPlainObject2(value)) return false;
25502
- const record4 = value;
25503
- return record4.type === void 0 || record4.type === "result" || record4.structured_output !== void 0;
25442
+ if (!isRecord(value)) return false;
25443
+ const record = value;
25444
+ return record.type === void 0 || record.type === "result" || record.structured_output !== void 0;
25504
25445
  }
25505
25446
  function parseHeadlessCliStdout(stdout) {
25506
25447
  const trimmed = stdout.trim();
@@ -25529,11 +25470,11 @@ function createCodexExecTurnObserver() {
25529
25470
  let turnCompleted = false;
25530
25471
  return {
25531
25472
  observe(value) {
25532
- if (!isPlainObject2(value)) return;
25473
+ if (!isRecord(value)) return;
25533
25474
  const type = typeof value.type === "string" ? value.type : void 0;
25534
25475
  if (type === "thread.started" && typeof value.thread_id === "string" && value.thread_id !== "") {
25535
25476
  threadId = value.thread_id;
25536
- } else if (type === "item.completed" && isPlainObject2(value.item)) {
25477
+ } else if (type === "item.completed" && isRecord(value.item)) {
25537
25478
  if (value.item.type === "agent_message" && typeof value.item.text === "string") {
25538
25479
  finalMessage = value.item.text;
25539
25480
  }
@@ -25557,7 +25498,7 @@ function createCodexExecTurnObserver() {
25557
25498
  }
25558
25499
  function formatCodexFailurePayload(payload) {
25559
25500
  if (typeof payload === "string" && payload.trim() !== "") return payload;
25560
- if (isPlainObject2(payload)) {
25501
+ if (isRecord(payload)) {
25561
25502
  if (typeof payload.message === "string" && payload.message.trim() !== "") return payload.message;
25562
25503
  try {
25563
25504
  return JSON.stringify(payload);
@@ -25585,7 +25526,7 @@ function resolveGitCommonDir(cwd) {
25585
25526
  encoding: "utf8"
25586
25527
  });
25587
25528
  } catch (error) {
25588
- const message = error instanceof Error ? error.message : String(error);
25529
+ const message = errorText(error);
25589
25530
  throw new Error(`git rev-parse --git-common-dir failed: ${message}`);
25590
25531
  }
25591
25532
  if (result.error !== void 0) {
@@ -25833,7 +25774,7 @@ function createHeadlessRoleTurnHost(config) {
25833
25774
  ...gitCommonDir === void 0 ? {} : { writableRoots: [gitCommonDir] }
25834
25775
  });
25835
25776
  } catch (error) {
25836
- const message = error instanceof Error ? error.message : String(error);
25777
+ const message = errorText(error);
25837
25778
  return {
25838
25779
  status: "terminal",
25839
25780
  result: externalHostFailure("session", "HeadlessArgvFailure", "argv-failed", { diagnostic: message }, message)
@@ -25902,7 +25843,7 @@ function createHeadlessRoleTurnHost(config) {
25902
25843
  } catch (error) {
25903
25844
  if (childExited) exitedSessionId = (codex ? codexObserver?.result().threadId : void 0) ?? sessionId;
25904
25845
  if (isHostAbortedError(error)) throw error;
25905
- const message = error instanceof Error ? error.message : String(error);
25846
+ const message = errorText(error);
25906
25847
  const observedHostFailure = codexObserver?.result().failureDiagnostic;
25907
25848
  if (observedHostFailure !== void 0) {
25908
25849
  return {
@@ -25940,7 +25881,7 @@ function createHeadlessRoleTurnHost(config) {
25940
25881
  try {
25941
25882
  await config.sessionIdentity.bind(request.principal, observation.threadId);
25942
25883
  } catch (error) {
25943
- sessionBindingDiagnostic = error instanceof Error ? error.message : String(error);
25884
+ sessionBindingDiagnostic = errorText(error);
25944
25885
  }
25945
25886
  }
25946
25887
  if (observation.failureDiagnostic !== void 0) {