@akagilnc/pi-workflow-roles 0.1.3673 → 0.1.3685

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 (42) hide show
  1. package/dist/acp-host/production-host.js +297 -166
  2. package/dist/audit-escalation.js +4 -3
  3. package/dist/diarist-contracts.js +4 -4
  4. package/dist/diarist-role.js +10 -4
  5. package/dist/diarist.js +121 -17
  6. package/dist/doctor-role.js +2 -1
  7. package/dist/gatekeeper-role.js +3 -2
  8. package/dist/judge-role.js +2 -1
  9. package/dist/package-contracts/terminating-tools.js +1 -1
  10. package/dist/public-cli/inspector-run.js +3 -13
  11. package/dist/public-cli/instruction-seat-run.js +6 -31
  12. package/dist/public-cli/invocation.js +32 -0
  13. package/dist/public-cli/judge-run.js +1 -7
  14. package/dist/public-cli/main.js +714 -728
  15. package/dist/public-cli/run-lifecycle.js +0 -28
  16. package/dist/public-cli/seat-ticket-binding.js +15 -104
  17. package/dist/readable-gate-item.js +16 -0
  18. package/dist/role-runtime.js +89 -10
  19. package/dist/submission-errors.js +4 -1
  20. package/package.json +1 -1
  21. package/resources/diarist-collect.md +10 -0
  22. package/src/audit-escalation.ts +4 -3
  23. package/src/diarist-contracts.ts +21 -9
  24. package/src/diarist-role.ts +15 -4
  25. package/src/diarist.ts +192 -22
  26. package/src/doctor-role.ts +2 -1
  27. package/src/gatekeeper-role.ts +3 -2
  28. package/src/judge-role.ts +2 -1
  29. package/src/package-contracts/terminating-tools.ts +1 -1
  30. package/src/public-cli/coder-run.ts +1 -7
  31. package/src/public-cli/countersign-run.ts +238 -86
  32. package/src/public-cli/diarist-run.ts +83 -28
  33. package/src/public-cli/fixer-run.ts +1 -7
  34. package/src/public-cli/inspector-run.ts +3 -17
  35. package/src/public-cli/instruction-seat-run.ts +6 -36
  36. package/src/public-cli/invocation.ts +52 -0
  37. package/src/public-cli/judge-run.ts +1 -7
  38. package/src/public-cli/run-lifecycle.ts +0 -31
  39. package/src/public-cli/seat-ticket-binding.ts +14 -138
  40. package/src/readable-gate-item.ts +20 -0
  41. package/src/role-runtime.ts +107 -9
  42. package/src/submission-errors.ts +4 -1
@@ -15055,7 +15055,7 @@ function validateRecordedDiaristOutput(value) {
15055
15055
  } catch {
15056
15056
  throw new Error("Diarist output has no execution discriminator");
15057
15057
  }
15058
- if (status === "completed") {
15058
+ if (status === "completed" || status === "escalate") {
15059
15059
  return value;
15060
15060
  }
15061
15061
  throw new Error("Diarist output has no execution discriminator");
@@ -15068,7 +15068,7 @@ var init_diarist_contracts = __esm({
15068
15068
  DIARIST_SOURCES_FLAG = {
15069
15069
  name: "ak-diarist-sources",
15070
15070
  definition: {
15071
- description: "Frozen per-ticket source catalog the diarist selects from",
15071
+ description: "Frozen source catalog the diarist selects from (may be unbound until LLM asserts ticketNumber)",
15072
15072
  type: "string"
15073
15073
  }
15074
15074
  };
@@ -16687,6 +16687,13 @@ var init_run_ticket_number = __esm({
16687
16687
  }
16688
16688
  });
16689
16689
 
16690
+ // src/readable-gate-item.ts
16691
+ var init_readable_gate_item = __esm({
16692
+ "src/readable-gate-item.ts"() {
16693
+ "use strict";
16694
+ }
16695
+ });
16696
+
16690
16697
  // src/audit-escalation.ts
16691
16698
  function isAuditEscalationResult(value) {
16692
16699
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
@@ -16698,6 +16705,7 @@ var AUDIT_ESCALATION_KIND;
16698
16705
  var init_audit_escalation = __esm({
16699
16706
  "src/audit-escalation.ts"() {
16700
16707
  "use strict";
16708
+ init_readable_gate_item();
16701
16709
  AUDIT_ESCALATION_KIND = "audit_escalation";
16702
16710
  }
16703
16711
  });
@@ -16706,6 +16714,7 @@ var init_audit_escalation = __esm({
16706
16714
  var init_submission_errors = __esm({
16707
16715
  "src/submission-errors.ts"() {
16708
16716
  "use strict";
16717
+ init_readable_gate_item();
16709
16718
  }
16710
16719
  });
16711
16720
 
@@ -16762,7 +16771,7 @@ function validateAcceptedDetails(toolName, details) {
16762
16771
  [GATEKEEPER_OUTPUT_TOOL_NAME]: ["dispatch", "pass"],
16763
16772
  [NAVIGATOR_OUTPUT_TOOL_NAME]: ["advice"],
16764
16773
  [AUDITOR_OUTPUT_TOOL_NAME]: ["pass", "bounce", "escalate"],
16765
- [DIARIST_OUTPUT_TOOL_NAME]: ["completed"]
16774
+ [DIARIST_OUTPUT_TOOL_NAME]: ["completed", "escalate"]
16766
16775
  };
16767
16776
  const collectorDiscriminator = toolName === COLLECTOR_OUTPUT_TOOL && Array.isArray(candidate?.groups);
16768
16777
  const baseDiscriminator = discriminator;
@@ -17816,27 +17825,6 @@ async function findLatestRunIdForSeatTicket(input) {
17816
17825
  }
17817
17826
  return best;
17818
17827
  }
17819
- async function collectBookRunTicketNumbers(input) {
17820
- const ledgerHome = resolveActivationLedgerHome(input.home);
17821
- const runsDir = join11(
17822
- activationBookDirectory(ledgerHome, input.bookKey),
17823
- "runs"
17824
- );
17825
- let entries;
17826
- try {
17827
- entries = await readdir2(runsDir);
17828
- } catch (error) {
17829
- if (errorCodeOf2(error) === "ENOENT") return /* @__PURE__ */ new Set();
17830
- throw error;
17831
- }
17832
- const known = /* @__PURE__ */ new Set();
17833
- for (const entry of entries) {
17834
- if (!entry.includes("@")) continue;
17835
- const ticketNumber = await readRunTicketNumber(join11(runsDir, entry));
17836
- if (ticketNumber !== void 0) known.add(ticketNumber);
17837
- }
17838
- return known;
17839
- }
17840
17828
  function parsePersistedTicketIdentity(record4) {
17841
17829
  const correlationId = typeof record4.correlationId === "string" && record4.correlationId.trim() !== "" ? record4.correlationId : void 0;
17842
17830
  const ticketNumber = typeof record4.ticketNumber === "number" && Number.isSafeInteger(record4.ticketNumber) && record4.ticketNumber >= 1 ? record4.ticketNumber : void 0;
@@ -21911,493 +21899,84 @@ var init_method_skill = __esm({
21911
21899
  }
21912
21900
  });
21913
21901
 
21914
- // src/ticket-provenance-contracts.ts
21915
- function isRecord10(value) {
21916
- return typeof value === "object" && value !== null && !Array.isArray(value);
21917
- }
21918
- function projectTicketProvenanceDiagnostic(value) {
21919
- if (!isRecord10(value)) return void 0;
21920
- if (value.recordClass !== TICKET_PROVENANCE_RECORD_CLASS_DIAGNOSTIC) {
21921
- return void 0;
21922
- }
21923
- if (typeof value.diagnosticKind !== "string" || !DIAGNOSTIC_KINDS.has(value.diagnosticKind)) {
21924
- return void 0;
21925
- }
21926
- if (typeof value.cause !== "string" || value.cause.length === 0) {
21927
- return void 0;
21928
- }
21929
- if (typeof value.recordedAt !== "string" || value.recordedAt.length === 0) {
21930
- return void 0;
21931
- }
21932
- return {
21933
- recordClass: TICKET_PROVENANCE_RECORD_CLASS_DIAGNOSTIC,
21934
- diagnosticKind: value.diagnosticKind,
21935
- cause: value.cause,
21936
- recordedAt: value.recordedAt,
21937
- ...typeof value.reason === "string" ? { reason: value.reason } : {}
21938
- };
21939
- }
21940
- function projectTicketProvenanceEntry(value) {
21941
- if (!isRecord10(value)) return void 0;
21942
- if (value.recordClass === TICKET_PROVENANCE_RECORD_CLASS_DIAGNOSTIC) {
21943
- return void 0;
21944
- }
21945
- if (!isRecord10(value.basis)) return void 0;
21946
- if (typeof value.basis.method !== "string" || !BASIS_METHODS.has(value.basis.method)) {
21947
- return void 0;
21948
- }
21949
- if (typeof value.sourceKind !== "string" || !SOURCE_KINDS.has(value.sourceKind)) {
21950
- return void 0;
21951
- }
21952
- if (!isRecord10(value.sourceRef)) return void 0;
21953
- if (typeof value.transcript !== "string" || value.transcript.length === 0) {
21954
- return void 0;
21955
- }
21956
- if (typeof value.timestamp !== "string" || value.timestamp.length === 0) {
21957
- return void 0;
21958
- }
21959
- const basis = {
21960
- method: value.basis.method,
21961
- ...Array.isArray(value.basis.anchors) ? {
21962
- anchors: value.basis.anchors.filter(
21963
- (item) => typeof item === "string"
21964
- )
21965
- } : {},
21966
- ...typeof value.basis.note === "string" ? { note: value.basis.note } : {}
21967
- };
21968
- const sourceRef = {
21969
- ...typeof value.sourceRef.sessionFile === "string" ? { sessionFile: value.sourceRef.sessionFile } : {},
21970
- ...typeof value.sourceRef.entryId === "string" || typeof value.sourceRef.entryId === "number" ? { entryId: value.sourceRef.entryId } : {},
21971
- ...typeof value.sourceRef.path === "string" ? { path: value.sourceRef.path } : {},
21972
- ...typeof value.sourceRef.url === "string" ? { url: value.sourceRef.url } : {}
21973
- };
21974
- return {
21975
- basis,
21976
- sourceKind: value.sourceKind,
21977
- sourceRef,
21978
- transcript: value.transcript,
21979
- timestamp: value.timestamp
21980
- };
21902
+ // src/auditor-dossier-tool.ts
21903
+ import { dirname as dirname8, join as join15, resolve as resolve8 } from "node:path";
21904
+ function gateSubmissionCandidatePath(runDirectory) {
21905
+ return join15(runDirectory, "artifacts", GATE_SUBMISSION_CANDIDATE_FILE);
21981
21906
  }
21982
- var TICKET_PROVENANCE_KIND, TICKET_PROVENANCE_HUMAN_VIEW, TICKET_PROVENANCE_OFFERED_WATERMARK, TICKET_PROVENANCE_RECORD_CLASS_DIAGNOSTIC, SOURCE_KINDS, BASIS_METHODS, DIAGNOSTIC_KINDS;
21983
- var init_ticket_provenance_contracts = __esm({
21984
- "src/ticket-provenance-contracts.ts"() {
21907
+ var GATE_SUBMISSION_CANDIDATE_FILE;
21908
+ var init_auditor_dossier_tool = __esm({
21909
+ "src/auditor-dossier-tool.ts"() {
21985
21910
  "use strict";
21986
- TICKET_PROVENANCE_KIND = "ticket-provenance";
21987
- TICKET_PROVENANCE_HUMAN_VIEW = "\u8D77\u5C45\u5F55.md";
21988
- TICKET_PROVENANCE_OFFERED_WATERMARK = "offered-identities.jsonl";
21989
- TICKET_PROVENANCE_RECORD_CLASS_DIAGNOSTIC = "diagnostic";
21990
- SOURCE_KINDS = /* @__PURE__ */ new Set([
21991
- "cc-session",
21992
- "issue-body-comment",
21993
- "adr-decision-key",
21994
- "ticket-decree-block"
21995
- ]);
21996
- BASIS_METHODS = /* @__PURE__ */ new Set(["llm-semantic"]);
21997
- DIAGNOSTIC_KINDS = /* @__PURE__ */ new Set([
21998
- "collector-failed",
21999
- "issue-source-failed",
22000
- "quote-verify-failed"
22001
- ]);
21911
+ init_build();
21912
+ GATE_SUBMISSION_CANDIDATE_FILE = "gate-submission-candidate.json";
22002
21913
  }
22003
21914
  });
22004
21915
 
22005
- // src/ticket-provenance.ts
22006
- import { createHash as createHash5 } from "node:crypto";
22007
- import { appendFileSync as appendFileSync2, existsSync as existsSync6, mkdirSync as mkdirSync3, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "node:fs";
22008
- import { join as join15 } from "node:path";
22009
- function ticketProvenanceSubject(ticketNumber) {
22010
- if (!Number.isSafeInteger(ticketNumber) || ticketNumber < 1) {
22011
- throw new Error(`ticket-provenance subject requires a positive ticket number, got ${String(ticketNumber)}`);
21916
+ // src/compliance-transport.ts
21917
+ var nonblank2, decisionGateSchema, complianceDecisionSchema, AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE, AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE;
21918
+ var init_compliance_transport = __esm({
21919
+ "src/compliance-transport.ts"() {
21920
+ "use strict";
21921
+ init_build();
21922
+ init_auditor_dossier_tool();
21923
+ nonblank2 = typebox_exports.String({ minLength: 1, pattern: "\\S" });
21924
+ decisionGateSchema = typebox_exports.Object({ question: nonblank2, options: typebox_exports.Array(nonblank2, { minItems: 1 }) }, { additionalProperties: false });
21925
+ complianceDecisionSchema = typebox_exports.Object({ status: typebox_exports.Unknown({ description: "pass | bounce | escalate \u2014 \u5F62\u72B6\u6307\u5F15\uFF0C\u975E schema \u95F8" }), violations: typebox_exports.Array(nonblank2, { description: "\u89C2\u5BDF\u5230\u7684\u5408\u89C4\u8FDD\u89C4" }), conflicts: typebox_exports.Array(nonblank2, { description: "\u672A\u51B3\u6743\u5A01\u6216\u6267\u884C\u51B2\u7A81" }), decisionGate: typebox_exports.Union([decisionGateSchema, typebox_exports.Null()], { description: "\u5347\u7EA7\u95EE\u9898\u4E0E\u53EF\u9009\u9009\u9879" }) }, { additionalProperties: true, required: [] });
21926
+ AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE = "ak_auditor_parent_attempt_binding";
21927
+ AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE = "ak_auditor_compliance_failure";
22012
21928
  }
22013
- return String(ticketNumber);
22014
- }
22015
- function ticketProvenanceEntryIdentity(input) {
22016
- const ref = input.sourceRef;
22017
- const refKey = [
22018
- ref.sessionFile ?? "",
22019
- ref.entryId === void 0 ? "" : String(ref.entryId),
22020
- ref.path ?? "",
22021
- ref.url ?? ""
22022
- ].join("");
22023
- const material = [
22024
- String(input.ticketNumber),
22025
- input.sourceKind,
22026
- refKey,
22027
- input.transcript
22028
- ].join("\0");
22029
- return createHash5("sha256").update(material, "utf8").digest("hex");
22030
- }
22031
- function resolveTicketProvenanceVolume(ticketNumber, cwd, home) {
22032
- const path = resolveSitianRecordPath({
22033
- level: "event",
22034
- kind: TICKET_PROVENANCE_KIND,
22035
- subject: ticketProvenanceSubject(ticketNumber),
22036
- cwd,
22037
- ...home === void 0 ? {} : { home }
22038
- });
22039
- return {
22040
- recordFile: path.recordFile,
22041
- volumeDir: path.sessionDir,
22042
- humanViewFile: join15(path.sessionDir, TICKET_PROVENANCE_HUMAN_VIEW),
22043
- offeredWatermarkFile: join15(path.sessionDir, TICKET_PROVENANCE_OFFERED_WATERMARK)
22044
- };
21929
+ });
21930
+
21931
+ // src/ledger-session-read.ts
21932
+ import { readFile as readFile11 } from "node:fs/promises";
21933
+ function isRecord10(value) {
21934
+ return typeof value === "object" && value !== null && !Array.isArray(value);
22045
21935
  }
22046
- function readOfferedIdentities(ticketNumber, cwd, home) {
22047
- const { offeredWatermarkFile } = resolveTicketProvenanceVolume(ticketNumber, cwd, home);
22048
- if (!existsSync6(offeredWatermarkFile)) return /* @__PURE__ */ new Set();
22049
- let text;
22050
- try {
22051
- text = readFileSync2(offeredWatermarkFile, "utf8");
22052
- } catch (error) {
22053
- throw new TicketProvenanceWatermarkError(
22054
- "unreadable",
22055
- `ticket-provenance offered watermark unreadable (${offeredWatermarkFile})`,
22056
- { cause: error }
22057
- );
22058
- }
22059
- const seen = /* @__PURE__ */ new Set();
21936
+ async function readLedgerSessionJsonl(path) {
21937
+ const text = await readFile11(path, "utf8");
22060
21938
  const lines = text.split("\n");
21939
+ const rows = [];
22061
21940
  for (let index = 0; index < lines.length; index += 1) {
22062
- const trimmed = lines[index].trim();
22063
- if (!trimmed) continue;
22064
- let parsed;
21941
+ const line2 = lines[index];
21942
+ if (!line2.trim()) continue;
21943
+ let row;
22065
21944
  try {
22066
- parsed = JSON.parse(trimmed);
21945
+ row = JSON.parse(line2);
22067
21946
  } catch (error) {
22068
- throw new TicketProvenanceWatermarkError(
22069
- "malformed-json",
22070
- `ticket-provenance offered watermark malformed JSON at line ${index + 1} (${offeredWatermarkFile})`,
22071
- { cause: error }
22072
- );
21947
+ if (!(error instanceof SyntaxError)) throw error;
21948
+ const completedByTerminator = index < lines.length - 1;
21949
+ if (completedByTerminator) {
21950
+ throw new LedgerSessionJsonlError(
21951
+ `malformed JSONL record in ${path} at line ${index + 1}: ${error.message}`,
21952
+ { path, line: index + 1, prefixRows: rows }
21953
+ );
21954
+ }
21955
+ break;
22073
21956
  }
22074
- if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed) || typeof parsed.identity !== "string" || parsed.identity.length === 0) {
22075
- throw new TicketProvenanceWatermarkError(
22076
- "bad-shape",
22077
- `ticket-provenance offered watermark bad shape at line ${index + 1} (${offeredWatermarkFile})`
21957
+ if (!isRecord10(row)) {
21958
+ const kind = row === null ? "null" : Array.isArray(row) ? "array" : typeof row;
21959
+ throw new LedgerSessionJsonlError(
21960
+ `complete non-object JSONL record in ${path} at line ${index + 1}: expected object, got ${kind}`,
21961
+ { path, line: index + 1, prefixRows: rows }
22078
21962
  );
22079
21963
  }
22080
- seen.add(parsed.identity);
22081
- }
22082
- return seen;
22083
- }
22084
- async function readTicketProvenance(ticketNumber, cwd, home) {
22085
- const { recordFile } = resolveTicketProvenanceVolume(ticketNumber, cwd, home);
22086
- const { records: records2 } = await readSitianRecords(recordFile);
22087
- const entries = [];
22088
- const diagnostics = [];
22089
- let skipped = 0;
22090
- for (const record4 of records2) {
22091
- if (record4.kind !== TICKET_PROVENANCE_KIND) {
22092
- skipped += 1;
22093
- continue;
22094
- }
22095
- const diagnostic = projectTicketProvenanceDiagnostic(record4.payload);
22096
- if (diagnostic !== void 0) {
22097
- diagnostics.push(diagnostic);
22098
- continue;
22099
- }
22100
- const entry = projectTicketProvenanceEntry(record4.payload);
22101
- if (entry === void 0) {
22102
- skipped += 1;
22103
- continue;
22104
- }
22105
- entries.push(entry);
21964
+ rows.push(row);
22106
21965
  }
22107
- return { entries, diagnostics, records: records2, recordFile, skipped };
21966
+ return rows;
22108
21967
  }
22109
- function markdownFenceFor(text) {
22110
- let longest = 0;
22111
- const runs = text.match(/`+/g);
22112
- if (runs !== null) {
22113
- for (const run of runs) {
22114
- if (run.length > longest) longest = run.length;
22115
- }
21968
+ function extractSessionTimestampSpan(rows) {
21969
+ let startedAt;
21970
+ let endedAt;
21971
+ for (const row of rows) {
21972
+ if (typeof row.timestamp !== "string" || !row.timestamp) continue;
21973
+ if (startedAt === void 0) startedAt = row.timestamp;
21974
+ endedAt = row.timestamp;
22116
21975
  }
22117
- return "`".repeat(Math.max(3, longest + 1));
22118
- }
22119
- function renderTicketProvenanceMarkdown(input) {
22120
- const lines = [
22121
- `# \u8D77\u5C45\u5F55 \xB7 #${input.ticketNumber}`,
22122
- "",
22123
- `\u6761\u76EE\u6570\uFF1A${input.entries.length}`,
22124
- ""
22125
- ];
22126
- let index = 0;
22127
- for (const entry of input.entries) {
22128
- index += 1;
22129
- lines.push(`## ${index}. ${entry.sourceKind} \xB7 ${entry.timestamp}`);
22130
- lines.push("");
22131
- lines.push(`- basis.method: \`${entry.basis.method}\``);
22132
- if (entry.basis.anchors !== void 0 && entry.basis.anchors.length > 0) {
22133
- lines.push(`- anchors: ${entry.basis.anchors.map((a) => `\`${a}\``).join(", ")}`);
22134
- }
22135
- if (entry.basis.note !== void 0) {
22136
- lines.push(`- note: ${entry.basis.note}`);
22137
- }
22138
- const refParts = [];
22139
- if (entry.sourceRef.sessionFile !== void 0) {
22140
- refParts.push(`sessionFile=${entry.sourceRef.sessionFile}`);
22141
- }
22142
- if (entry.sourceRef.entryId !== void 0) {
22143
- refParts.push(`entryId=${String(entry.sourceRef.entryId)}`);
22144
- }
22145
- if (entry.sourceRef.path !== void 0) {
22146
- refParts.push(`path=${entry.sourceRef.path}`);
22147
- }
22148
- if (entry.sourceRef.url !== void 0) {
22149
- refParts.push(`url=${entry.sourceRef.url}`);
22150
- }
22151
- if (refParts.length > 0) {
22152
- lines.push(`- sourceRef: ${refParts.join(" \xB7 ")}`);
22153
- }
22154
- lines.push("");
22155
- const fence = markdownFenceFor(entry.transcript);
22156
- lines.push(fence);
22157
- lines.push(entry.transcript);
22158
- lines.push(fence);
22159
- lines.push("");
22160
- }
22161
- return lines.join("\n");
22162
- }
22163
- function ensureTicketProvenanceVolume(ticketNumber, cwd, home) {
22164
- const volume = resolveTicketProvenanceVolume(ticketNumber, cwd, home);
22165
- mkdirSync3(volume.volumeDir, { recursive: true });
22166
- appendFileSync2(volume.recordFile, "", "utf8");
22167
- return volume;
22168
- }
22169
- function appendTicketProvenanceDiagnostic(input) {
22170
- const subject = ticketProvenanceSubject(input.ticketNumber);
22171
- const identityParts = input.diagnostic.diagnosticKind === "quote-verify-failed" ? [
22172
- subject,
22173
- input.diagnostic.recordClass,
22174
- input.diagnostic.diagnosticKind,
22175
- input.diagnostic.cause,
22176
- input.diagnostic.reason ?? ""
22177
- ] : [
22178
- subject,
22179
- input.diagnostic.recordClass,
22180
- input.diagnostic.diagnosticKind,
22181
- input.diagnostic.recordedAt,
22182
- input.diagnostic.cause,
22183
- input.diagnostic.reason ?? ""
22184
- ];
22185
- const identity = createHash5("sha256").update(identityParts.join("\0"), "utf8").digest("hex");
22186
- return sitianReport({
22187
- level: "event",
22188
- kind: TICKET_PROVENANCE_KIND,
22189
- identity,
22190
- subject,
22191
- cwd: input.cwd,
22192
- ...input.home === void 0 ? {} : { home: input.home },
22193
- host: input.host ?? "diarist",
22194
- source: input.source ?? "diarist-diagnostic",
22195
- payload: input.diagnostic
22196
- });
22197
- }
22198
- function appendIssueSourceFailureDiagnostic(input) {
22199
- const recordedAt = input.recordedAt ?? (/* @__PURE__ */ new Date()).toISOString();
22200
- return appendTicketProvenanceDiagnostic({
22201
- ticketNumber: input.ticketNumber,
22202
- cwd: input.cwd,
22203
- ...input.home === void 0 ? {} : { home: input.home },
22204
- source: "diarist-issue-source",
22205
- diagnostic: {
22206
- recordClass: TICKET_PROVENANCE_RECORD_CLASS_DIAGNOSTIC,
22207
- diagnosticKind: "issue-source-failed",
22208
- cause: input.cause,
22209
- recordedAt,
22210
- reason: input.reason
22211
- }
22212
- });
22213
- }
22214
- function writeTicketProvenanceHumanView(input) {
22215
- const volume = ensureTicketProvenanceVolume(input.ticketNumber, input.cwd, input.home);
22216
- const md = renderTicketProvenanceMarkdown({
22217
- ticketNumber: input.ticketNumber,
22218
- entries: input.entries
22219
- });
22220
- writeFileSync2(volume.humanViewFile, md, "utf8");
22221
- return volume.humanViewFile;
22222
- }
22223
- var TicketProvenanceWatermarkError;
22224
- var init_ticket_provenance = __esm({
22225
- "src/ticket-provenance.ts"() {
22226
- "use strict";
22227
- init_sitian_facade();
22228
- init_ticket_provenance_contracts();
22229
- TicketProvenanceWatermarkError = class extends Error {
22230
- code = "ticket-provenance-watermark";
22231
- reason;
22232
- constructor(reason, message, options) {
22233
- super(message, options);
22234
- this.name = "TicketProvenanceWatermarkError";
22235
- this.reason = reason;
22236
- }
22237
- };
22238
- }
22239
- });
22240
-
22241
- // src/public-cli/seat-ticket-binding.ts
22242
- import { existsSync as existsSync7 } from "node:fs";
22243
- function instructionTicketTokens(instruction) {
22244
- const tokens = [];
22245
- const seen = /* @__PURE__ */ new Set();
22246
- for (const match of instruction.matchAll(/#([1-9]\d*)/g)) {
22247
- const parsed = Number(match[1]);
22248
- if (!Number.isSafeInteger(parsed)) continue;
22249
- if (seen.has(parsed)) continue;
22250
- seen.add(parsed);
22251
- tokens.push(parsed);
22252
- }
22253
- return tokens;
22254
- }
22255
- async function resolveKnownTicketNumber(input) {
22256
- const tokens = instructionTicketTokens(input.instruction);
22257
- if (tokens.length === 0) return void 0;
22258
- const target = tokens[0];
22259
- const volume = resolveTicketProvenanceVolume(
22260
- target,
22261
- input.projectRoot,
22262
- input.home
22263
- );
22264
- if (existsSync7(volume.volumeDir)) return target;
22265
- const runTickets = await readBookRunTickets(input);
22266
- return runTickets.has(target) ? target : void 0;
22267
- }
22268
- async function resolveDiaristSummonsTicketNumber(input) {
22269
- const tokens = instructionTicketTokens(input.instruction);
22270
- return tokens[0];
22271
- }
22272
- async function readBookRunTickets(input) {
22273
- let bookKey;
22274
- try {
22275
- bookKey = input.bookKey ?? resolveBookKeyFromGit(input.projectRoot);
22276
- } catch (error) {
22277
- if (error instanceof ActivationGitRepositoryRequiredError) return /* @__PURE__ */ new Set();
22278
- throw error;
22279
- }
22280
- return await collectBookRunTicketNumbers({ home: input.home, bookKey });
22281
- }
22282
- async function bindReusedTicketNumber(admitted, ticketNumber) {
22283
- if (ticketNumber === void 0) return;
22284
- if (admitted.ticketNumber !== void 0) return;
22285
- await bindAdmittedTicketNumber(admitted, ticketNumber);
22286
- }
22287
- async function resolveSeatTicketBinding(admitted, env) {
22288
- if (admitted.ticketNumber !== void 0) return admitted.ticketNumber;
22289
- const ticketNumber = await resolveKnownTicketNumber({
22290
- instruction: admitted.instruction,
22291
- projectRoot: admitted.projectRoot,
22292
- home: env.home,
22293
- bookKey: admitted.bookKey
22294
- });
22295
- await bindReusedTicketNumber(admitted, ticketNumber);
22296
- return ticketNumber;
22297
- }
22298
- async function tryResumeSameTicketSeatRun(input) {
22299
- if (input.freshSummons === true) return void 0;
22300
- if (input.parentRunPath === void 0 && input.ticketNumber === void 0) {
22301
- return void 0;
22302
- }
22303
- const previousRunId = await findLatestRunIdForSeatTicket({
22304
- home: input.home,
22305
- bookKey: resolveBookKeyFromGit(input.projectRoot),
22306
- role: input.role,
22307
- ...input.parentRunPath === void 0 ? {} : { parentRunPath: input.parentRunPath },
22308
- ...input.ticketNumber === void 0 ? {} : { ticketNumber: input.ticketNumber }
22309
- });
22310
- if (previousRunId === void 0) return void 0;
22311
- return await input.resume(previousRunId, input.summons);
22312
- }
22313
- var init_seat_ticket_binding = __esm({
22314
- "src/public-cli/seat-ticket-binding.ts"() {
22315
- "use strict";
22316
- init_activation_ledger_git();
22317
- init_ticket_provenance();
22318
- init_invocation();
22319
- init_run_lifecycle();
22320
- }
22321
- });
22322
-
22323
- // src/auditor-dossier-tool.ts
22324
- import { dirname as dirname8, join as join16, resolve as resolve8 } from "node:path";
22325
- function gateSubmissionCandidatePath(runDirectory) {
22326
- return join16(runDirectory, "artifacts", GATE_SUBMISSION_CANDIDATE_FILE);
22327
- }
22328
- var GATE_SUBMISSION_CANDIDATE_FILE;
22329
- var init_auditor_dossier_tool = __esm({
22330
- "src/auditor-dossier-tool.ts"() {
22331
- "use strict";
22332
- init_build();
22333
- GATE_SUBMISSION_CANDIDATE_FILE = "gate-submission-candidate.json";
22334
- }
22335
- });
22336
-
22337
- // src/compliance-transport.ts
22338
- var nonblank2, decisionGateSchema, complianceDecisionSchema, AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE, AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE;
22339
- var init_compliance_transport = __esm({
22340
- "src/compliance-transport.ts"() {
22341
- "use strict";
22342
- init_build();
22343
- init_auditor_dossier_tool();
22344
- nonblank2 = typebox_exports.String({ minLength: 1, pattern: "\\S" });
22345
- decisionGateSchema = typebox_exports.Object({ question: nonblank2, options: typebox_exports.Array(nonblank2, { minItems: 1 }) }, { additionalProperties: false });
22346
- complianceDecisionSchema = typebox_exports.Object({ status: typebox_exports.Unknown({ description: "pass | bounce | escalate \u2014 \u5F62\u72B6\u6307\u5F15\uFF0C\u975E schema \u95F8" }), violations: typebox_exports.Array(nonblank2, { description: "\u89C2\u5BDF\u5230\u7684\u5408\u89C4\u8FDD\u89C4" }), conflicts: typebox_exports.Array(nonblank2, { description: "\u672A\u51B3\u6743\u5A01\u6216\u6267\u884C\u51B2\u7A81" }), decisionGate: typebox_exports.Union([decisionGateSchema, typebox_exports.Null()], { description: "\u5347\u7EA7\u95EE\u9898\u4E0E\u53EF\u9009\u9009\u9879" }) }, { additionalProperties: true, required: [] });
22347
- AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE = "ak_auditor_parent_attempt_binding";
22348
- AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE = "ak_auditor_compliance_failure";
22349
- }
22350
- });
22351
-
22352
- // src/ledger-session-read.ts
22353
- import { readFile as readFile11 } from "node:fs/promises";
22354
- function isRecord11(value) {
22355
- return typeof value === "object" && value !== null && !Array.isArray(value);
22356
- }
22357
- async function readLedgerSessionJsonl(path) {
22358
- const text = await readFile11(path, "utf8");
22359
- const lines = text.split("\n");
22360
- const rows = [];
22361
- for (let index = 0; index < lines.length; index += 1) {
22362
- const line2 = lines[index];
22363
- if (!line2.trim()) continue;
22364
- let row;
22365
- try {
22366
- row = JSON.parse(line2);
22367
- } catch (error) {
22368
- if (!(error instanceof SyntaxError)) throw error;
22369
- const completedByTerminator = index < lines.length - 1;
22370
- if (completedByTerminator) {
22371
- throw new LedgerSessionJsonlError(
22372
- `malformed JSONL record in ${path} at line ${index + 1}: ${error.message}`,
22373
- { path, line: index + 1, prefixRows: rows }
22374
- );
22375
- }
22376
- break;
22377
- }
22378
- if (!isRecord11(row)) {
22379
- const kind = row === null ? "null" : Array.isArray(row) ? "array" : typeof row;
22380
- throw new LedgerSessionJsonlError(
22381
- `complete non-object JSONL record in ${path} at line ${index + 1}: expected object, got ${kind}`,
22382
- { path, line: index + 1, prefixRows: rows }
22383
- );
22384
- }
22385
- rows.push(row);
22386
- }
22387
- return rows;
22388
- }
22389
- function extractSessionTimestampSpan(rows) {
22390
- let startedAt;
22391
- let endedAt;
22392
- for (const row of rows) {
22393
- if (typeof row.timestamp !== "string" || !row.timestamp) continue;
22394
- if (startedAt === void 0) startedAt = row.timestamp;
22395
- endedAt = row.timestamp;
22396
- }
22397
- return {
22398
- ...startedAt !== void 0 ? { startedAt } : {},
22399
- ...endedAt !== void 0 ? { endedAt } : {}
22400
- };
21976
+ return {
21977
+ ...startedAt !== void 0 ? { startedAt } : {},
21978
+ ...endedAt !== void 0 ? { endedAt } : {}
21979
+ };
22401
21980
  }
22402
21981
  function extractSessionModelSequence(rows) {
22403
21982
  const seen = /* @__PURE__ */ new Set();
@@ -22412,7 +21991,7 @@ function extractSessionModelSequence(rows) {
22412
21991
  if (row.type === "model_change" && typeof row.modelId === "string") {
22413
21992
  push(row.modelId);
22414
21993
  }
22415
- const message = isRecord11(row.message) ? row.message : void 0;
21994
+ const message = isRecord10(row.message) ? row.message : void 0;
22416
21995
  if (message?.role === "assistant" && typeof message.model === "string") {
22417
21996
  push(message.model);
22418
21997
  }
@@ -22428,11 +22007,11 @@ function extractSessionToolIntervals(rows) {
22428
22007
  const openById = /* @__PURE__ */ new Map();
22429
22008
  for (const row of rows) {
22430
22009
  const rowTimestamp = typeof row.timestamp === "string" ? row.timestamp : void 0;
22431
- const message = isRecord11(row.message) ? row.message : void 0;
22010
+ const message = isRecord10(row.message) ? row.message : void 0;
22432
22011
  if (message?.role === "assistant" && Array.isArray(message.content)) {
22433
22012
  const callTimestamp = typeof message.timestamp === "string" && message.timestamp ? message.timestamp : rowTimestamp;
22434
22013
  for (const part of message.content) {
22435
- if (!isRecord11(part) || part.type !== "toolCall") continue;
22014
+ if (!isRecord10(part) || part.type !== "toolCall") continue;
22436
22015
  if (typeof part.id !== "string" || part.id.length === 0) {
22437
22016
  throw new Error("toolCall frame missing string id");
22438
22017
  }
@@ -22445,7 +22024,7 @@ function extractSessionToolIntervals(rows) {
22445
22024
  if (openById.has(part.id)) {
22446
22025
  throw new Error(`duplicate toolCall id ${part.id}`);
22447
22026
  }
22448
- const args = isRecord11(part.arguments) ? part.arguments : void 0;
22027
+ const args = isRecord10(part.arguments) ? part.arguments : void 0;
22449
22028
  const command = part.name === "bash" && args !== void 0 && typeof args.command === "string" ? bashCommandFirstLine(args.command) : void 0;
22450
22029
  const interval = {
22451
22030
  toolCallId: part.id,
@@ -22530,8 +22109,8 @@ var init_ledger_session_read = __esm({
22530
22109
 
22531
22110
  // src/analyst-gate-cycles-read.ts
22532
22111
  import { readdir as readdir3 } from "node:fs/promises";
22533
- import { join as join17 } from "node:path";
22534
- function isRecord12(value) {
22112
+ import { join as join16 } from "node:path";
22113
+ function isRecord11(value) {
22535
22114
  return typeof value === "object" && value !== null && !Array.isArray(value);
22536
22115
  }
22537
22116
  function isParentAttemptBindingRow(row) {
@@ -22562,7 +22141,7 @@ function isGateTerminatingToolName(toolName) {
22562
22141
  function acceptedGateReceiptIds(rows) {
22563
22142
  const accepted = /* @__PURE__ */ new Set();
22564
22143
  for (const row of rows) {
22565
- const message = isRecord12(row.message) ? row.message : void 0;
22144
+ const message = isRecord11(row.message) ? row.message : void 0;
22566
22145
  if (message?.role !== "toolResult") continue;
22567
22146
  if (typeof message.toolCallId !== "string" || message.toolCallId.length === 0) continue;
22568
22147
  if (message.isError === false) accepted.add(message.toolCallId);
@@ -22601,7 +22180,7 @@ function nearestAttemptBindingBefore(rows, beforeIndex) {
22601
22180
  for (let i = beforeIndex - 1; i >= 0; i -= 1) {
22602
22181
  const row = rows[i];
22603
22182
  if (!isParentAttemptBindingRow(row)) continue;
22604
- if (!isRecord12(row.data) || !isRecord12(row.data.parent)) continue;
22183
+ if (!isRecord11(row.data) || !isRecord11(row.data.parent)) continue;
22605
22184
  const id = row.data.parent.attemptEntryId;
22606
22185
  const sessionFile = row.data.parent.sessionFile;
22607
22186
  return {
@@ -22616,10 +22195,10 @@ function extractAllAcceptedGateToolCalls(rows) {
22616
22195
  const out = [];
22617
22196
  for (let rowIndex = 0; rowIndex < rows.length; rowIndex += 1) {
22618
22197
  const row = rows[rowIndex];
22619
- const message = isRecord12(row.message) ? row.message : void 0;
22198
+ const message = isRecord11(row.message) ? row.message : void 0;
22620
22199
  if (message?.role !== "assistant" || !Array.isArray(message.content)) continue;
22621
22200
  for (const part of message.content) {
22622
- if (!isRecord12(part) || part.type !== "toolCall") continue;
22201
+ if (!isRecord11(part) || part.type !== "toolCall") continue;
22623
22202
  if (typeof part.id !== "string" || part.id.length === 0) continue;
22624
22203
  if (typeof part.name !== "string" || part.name.length === 0) continue;
22625
22204
  if (!isGateTerminatingToolName(part.name)) continue;
@@ -22627,7 +22206,7 @@ function extractAllAcceptedGateToolCalls(rows) {
22627
22206
  const binding = nearestAttemptBindingBefore(rows, rowIndex);
22628
22207
  out.push({
22629
22208
  toolName: part.name,
22630
- args: isRecord12(part.arguments) ? part.arguments : void 0,
22209
+ args: isRecord11(part.arguments) ? part.arguments : void 0,
22631
22210
  accepted: true,
22632
22211
  rowIndex,
22633
22212
  ...binding
@@ -22767,7 +22346,7 @@ async function resolveOfficerSessionFromPointerFile(pointerPath) {
22767
22346
  { cause: error }
22768
22347
  );
22769
22348
  }
22770
- if (!isRecord12(raw) || raw.kind !== "direct-officer-run-pointer" || raw.version !== 1) {
22349
+ if (!isRecord11(raw) || raw.kind !== "direct-officer-run-pointer" || raw.version !== 1) {
22771
22350
  throw new Error(`direct officer run pointer has unknown shape in ${pointerPath}`);
22772
22351
  }
22773
22352
  const sessionFile = raw.sessionFile;
@@ -22791,7 +22370,7 @@ async function readAnalystGateCyclesFromAuditorRoles(auditorRolesDirectory, opti
22791
22370
  throw error;
22792
22371
  }
22793
22372
  for (const name of names) {
22794
- const path = join17(directory, name);
22373
+ const path = join16(directory, name);
22795
22374
  const sessionPath = name.endsWith(".pointer.json") ? await resolveOfficerSessionFromPointerFile(path) : path;
22796
22375
  if (sessionPath === void 0) continue;
22797
22376
  const classified = await classifyAuditorVolume(sessionPath);
@@ -22841,6 +22420,7 @@ var init_gatekeeper_role = __esm({
22841
22420
  "use strict";
22842
22421
  init_auditor_dossier_tool();
22843
22422
  init_submission_errors();
22423
+ init_readable_gate_item();
22844
22424
  init_inspector_contracts();
22845
22425
  init_gatekeeper_output();
22846
22426
  init_shape_unreadable_failure();
@@ -22851,21 +22431,21 @@ var init_gatekeeper_role = __esm({
22851
22431
 
22852
22432
  // src/run-terminal-artifacts.ts
22853
22433
  import { readdir as readdir4, readFile as readFile12 } from "node:fs/promises";
22854
- import { basename as basename6, dirname as dirname9, join as join18 } from "node:path";
22434
+ import { basename as basename6, dirname as dirname9, join as join17 } from "node:path";
22855
22435
  function isMissingPathError2(error) {
22856
22436
  return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
22857
22437
  }
22858
22438
  function errorText2(error) {
22859
22439
  return error instanceof Error ? error.message : String(error);
22860
22440
  }
22861
- function isRecord13(value) {
22441
+ function isRecord12(value) {
22862
22442
  return typeof value === "object" && value !== null && !Array.isArray(value);
22863
22443
  }
22864
22444
  function readUsableTerminalArtifactBody(body) {
22865
22445
  if (body === null) {
22866
22446
  return { ok: false, reason: "terminal artifact JSON value is null" };
22867
22447
  }
22868
- if (!isRecord13(body)) {
22448
+ if (!isRecord12(body)) {
22869
22449
  return {
22870
22450
  ok: false,
22871
22451
  reason: `terminal artifact JSON value is not a typed object (${Array.isArray(body) ? "array" : typeof body})`
@@ -22926,7 +22506,7 @@ async function listUniqueErrorFallbackPaths(directories) {
22926
22506
  }
22927
22507
  for (const name of names.sort((a, b) => a.localeCompare(b))) {
22928
22508
  if (!UNIQUE_ERROR_FALLBACK_NAME.test(name)) continue;
22929
- found.push(join18(dir, name));
22509
+ found.push(join17(dir, name));
22930
22510
  }
22931
22511
  }
22932
22512
  return found;
@@ -22942,14 +22522,14 @@ function presentUniqueFallbackBoundToRun(body, expectedRunId) {
22942
22522
  return typeof body.runId === "string" && body.runId === expectedRunId;
22943
22523
  }
22944
22524
  async function readRunTerminalArtifact(runDirectory) {
22945
- const artifactsDir = join18(runDirectory, "artifacts");
22525
+ const artifactsDir = join17(runDirectory, "artifacts");
22946
22526
  for (const file of RUN_TERMINAL_ARTIFACT_FILES) {
22947
- const path = join18(artifactsDir, file);
22527
+ const path = join17(artifactsDir, file);
22948
22528
  const read3 = await readTerminalArtifactAtPath(path, file);
22949
22529
  if (read3 !== void 0) return read3;
22950
22530
  }
22951
22531
  for (const relative3 of RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS) {
22952
- const path = join18(runDirectory, relative3);
22532
+ const path = join17(runDirectory, relative3);
22953
22533
  const read3 = await readTerminalArtifactAtPath(path, "error.json");
22954
22534
  if (read3 !== void 0) return read3;
22955
22535
  }
@@ -23088,14 +22668,14 @@ var init_submission_ledger = __esm({
23088
22668
  });
23089
22669
 
23090
22670
  // src/session-opening-materials.ts
23091
- import { existsSync as existsSync8 } from "node:fs";
22671
+ import { existsSync as existsSync6 } from "node:fs";
23092
22672
  import { readFile as readFile13 } from "node:fs/promises";
23093
- import { dirname as dirname10, join as join19 } from "node:path";
22673
+ import { dirname as dirname10, join as join18 } from "node:path";
23094
22674
  import { fileURLToPath, pathToFileURL as pathToFileURL2 } from "node:url";
23095
22675
  function resolvePackageRootDir(moduleUrl = import.meta.url) {
23096
22676
  let dir = dirname10(fileURLToPath(moduleUrl));
23097
22677
  for (let i = 0; i < 8; i += 1) {
23098
- if (existsSync8(join19(dir, "package.json")) && existsSync8(join19(dir, "souls"))) {
22678
+ if (existsSync6(join18(dir, "package.json")) && existsSync6(join18(dir, "souls"))) {
23099
22679
  return dir;
23100
22680
  }
23101
22681
  const parent = dirname10(dir);
@@ -23421,12 +23001,12 @@ var init_reviewer_dispatch = __esm({
23421
23001
 
23422
23002
  // src/public-cli/reviewer-dispatch-rejection.ts
23423
23003
  import { readFile as readFile14, unlink as unlink3 } from "node:fs/promises";
23424
- import { join as join20 } from "node:path";
23004
+ import { join as join19 } from "node:path";
23425
23005
  function isReviewerPreflightViolation(value) {
23426
23006
  return typeof value === "string" && REVIEWER_PREFLIGHT_VIOLATIONS.includes(value);
23427
23007
  }
23428
23008
  function reviewerDispatchRejectionPath(runDirectory) {
23429
- return join20(runDirectory, REVIEWER_DISPATCH_REJECTION_FILE);
23009
+ return join19(runDirectory, REVIEWER_DISPATCH_REJECTION_FILE);
23430
23010
  }
23431
23011
  async function clearReviewerDispatchRejection(runDirectory) {
23432
23012
  try {
@@ -23487,7 +23067,7 @@ var init_collector_evidence = __esm({
23487
23067
 
23488
23068
  // src/collector-github.ts
23489
23069
  import { spawn as spawn2 } from "node:child_process";
23490
- function isRecord14(value) {
23070
+ function isRecord13(value) {
23491
23071
  return typeof value === "object" && value !== null && !Array.isArray(value);
23492
23072
  }
23493
23073
  function requireString(value, label) {
@@ -23528,25 +23108,25 @@ function commentFailureCause(error) {
23528
23108
  };
23529
23109
  }
23530
23110
  function requireUserLogin(raw) {
23531
- if (!isRecord14(raw) || typeof raw["login"] !== "string") {
23111
+ if (!isRecord13(raw) || typeof raw["login"] !== "string") {
23532
23112
  throw new Error("GitHub payload missing user.login");
23533
23113
  }
23534
23114
  return raw["login"];
23535
23115
  }
23536
23116
  function optionalUserLogin(raw) {
23537
23117
  if (raw === null) return null;
23538
- if (!isRecord14(raw) || typeof raw["login"] !== "string") {
23118
+ if (!isRecord13(raw) || typeof raw["login"] !== "string") {
23539
23119
  throw new Error("GitHub payload missing user.login");
23540
23120
  }
23541
23121
  return raw["login"];
23542
23122
  }
23543
23123
  function machineIdentity(raw) {
23544
23124
  const user = raw["user"];
23545
- if (!isRecord14(user) || typeof user["type"] !== "string" || typeof user["id"] !== "number") {
23125
+ if (!isRecord13(user) || typeof user["type"] !== "string" || typeof user["id"] !== "number") {
23546
23126
  return null;
23547
23127
  }
23548
23128
  const app = raw["performed_via_github_app"];
23549
- const appId = isRecord14(app) && typeof app["id"] === "number" ? app["id"] : void 0;
23129
+ const appId = isRecord13(app) && typeof app["id"] === "number" ? app["id"] : void 0;
23550
23130
  return {
23551
23131
  userType: user["type"],
23552
23132
  userId: user["id"],
@@ -23554,9 +23134,9 @@ function machineIdentity(raw) {
23554
23134
  };
23555
23135
  }
23556
23136
  function normalizePullRequest(raw) {
23557
- if (!isRecord14(raw)) throw new Error("GitHub pull request payload must be an object");
23137
+ if (!isRecord13(raw)) throw new Error("GitHub pull request payload must be an object");
23558
23138
  const head = raw["head"];
23559
- if (!isRecord14(head) || typeof head["sha"] !== "string" || head["sha"].length === 0) {
23139
+ if (!isRecord13(head) || typeof head["sha"] !== "string" || head["sha"].length === 0) {
23560
23140
  throw new Error("GitHub pull request payload missing head.sha");
23561
23141
  }
23562
23142
  const number = requireNumber(raw["number"], "number");
@@ -23572,7 +23152,7 @@ function normalizePullRequest(raw) {
23572
23152
  };
23573
23153
  }
23574
23154
  function normalizePullRequestReaction(raw) {
23575
- if (!isRecord14(raw)) throw new Error("GitHub reaction payload must be an object");
23155
+ if (!isRecord13(raw)) throw new Error("GitHub reaction payload must be an object");
23576
23156
  return {
23577
23157
  id: requireNumber(raw["id"], "reaction.id"),
23578
23158
  userLogin: optionalUserLogin(raw["user"]),
@@ -23583,7 +23163,7 @@ function normalizePullRequestReaction(raw) {
23583
23163
  };
23584
23164
  }
23585
23165
  function normalizeReview(raw) {
23586
- if (!isRecord14(raw)) throw new Error("GitHub review payload must be an object");
23166
+ if (!isRecord13(raw)) throw new Error("GitHub review payload must be an object");
23587
23167
  return {
23588
23168
  id: requireNumber(raw["id"], "review.id"),
23589
23169
  ...typeof raw["node_id"] === "string" ? { nodeId: raw["node_id"] } : {},
@@ -23598,7 +23178,7 @@ function normalizeReview(raw) {
23598
23178
  };
23599
23179
  }
23600
23180
  function normalizeIssueComment(raw) {
23601
- if (!isRecord14(raw)) throw new Error("GitHub issue comment payload must be an object");
23181
+ if (!isRecord13(raw)) throw new Error("GitHub issue comment payload must be an object");
23602
23182
  return {
23603
23183
  id: requireNumber(raw["id"], "comment.id"),
23604
23184
  userLogin: optionalUserLogin(raw["user"]),
@@ -23611,7 +23191,7 @@ function normalizeIssueComment(raw) {
23611
23191
  };
23612
23192
  }
23613
23193
  function normalizeReviewComment(raw) {
23614
- if (!isRecord14(raw)) throw new Error("GitHub review comment payload must be an object");
23194
+ if (!isRecord13(raw)) throw new Error("GitHub review comment payload must be an object");
23615
23195
  return {
23616
23196
  id: requireNumber(raw["id"], "review_comment.id"),
23617
23197
  pullRequestReviewId: typeof raw["pull_request_review_id"] === "number" ? raw["pull_request_review_id"] : null,
@@ -23920,11 +23500,11 @@ function createGhCollectorGitHubTransport(runner = createGhApiRunner()) {
23920
23500
  if (input.signal?.aborted) {
23921
23501
  throw error;
23922
23502
  }
23923
- if (isRecord14(error) && error["ambiguousGhFailure"] === true) {
23503
+ if (isRecord13(error) && error["ambiguousGhFailure"] === true) {
23924
23504
  const cause = commentFailureCause(error);
23925
23505
  return { kind: "ambiguous_loss", diagnostics: cause.message, cause };
23926
23506
  }
23927
- if (isRecord14(error) && error["name"] === "AbortError") {
23507
+ if (isRecord13(error) && error["name"] === "AbortError") {
23928
23508
  throw error;
23929
23509
  }
23930
23510
  throw error;
@@ -24100,11 +23680,11 @@ var init_navigator_invocation_identity = __esm({
24100
23680
  });
24101
23681
 
24102
23682
  // src/receipt-delivery-policy.ts
24103
- function isRecord15(value) {
23683
+ function isRecord14(value) {
24104
23684
  return typeof value === "object" && value !== null && !Array.isArray(value);
24105
23685
  }
24106
23686
  function parseNoReceiptLifecycleFacts(input) {
24107
- if (!isRecord15(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) => isRecord15(item) && typeof item.reason === "string")) {
23687
+ if (!isRecord14(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) => isRecord14(item) && typeof item.reason === "string")) {
24108
23688
  throw new TypeError("malformed no-receipt lifecycle facts");
24109
23689
  }
24110
23690
  return {
@@ -24290,7 +23870,7 @@ var init_terminal = __esm({
24290
23870
  // src/public-cli/settlement.ts
24291
23871
  import { randomUUID as randomUUID3 } from "node:crypto";
24292
23872
  import { appendFile as appendFile2, readFile as readFile15, readdir as readdir5, writeFile as writeFile5 } from "node:fs/promises";
24293
- import { dirname as dirname11, join as join21 } from "node:path";
23873
+ import { dirname as dirname11, join as join20 } from "node:path";
24294
23874
  function sealedLedgerHome(admitted) {
24295
23875
  return homeFromRunDirectory(admitted.runDirectory);
24296
23876
  }
@@ -24670,7 +24250,7 @@ async function readSitianRetainedAuditorProviderStop(sessionFile) {
24670
24250
  const { records: records2 } = await readSitianRecords(recordFile);
24671
24251
  for (let i = records2.length - 1; i >= 0; i -= 1) {
24672
24252
  const payload = records2[i]?.payload;
24673
- if (!isRecord16(payload) || !isRecord16(payload.response)) continue;
24253
+ if (!isRecord15(payload) || !isRecord15(payload.response)) continue;
24674
24254
  if (typeof payload.type === "string") continue;
24675
24255
  const stop = sessionProviderStopFromAssistant(payload.response);
24676
24256
  if (stop !== void 0) return stop;
@@ -24691,7 +24271,7 @@ async function readSessionProviderStop(sessionFile) {
24691
24271
  }
24692
24272
  }
24693
24273
  async function readBoundEvidenceChildKnownFailure(sessionFile) {
24694
- const childDirectory = join21(dirname11(sessionFile), "evidence-children");
24274
+ const childDirectory = join20(dirname11(sessionFile), "evidence-children");
24695
24275
  let names;
24696
24276
  try {
24697
24277
  names = await readdir5(childDirectory);
@@ -24702,12 +24282,12 @@ async function readBoundEvidenceChildKnownFailure(sessionFile) {
24702
24282
  for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
24703
24283
  let entries;
24704
24284
  try {
24705
- entries = await readBoundSessionEntries(join21(childDirectory, file));
24285
+ entries = await readBoundSessionEntries(join20(childDirectory, file));
24706
24286
  } catch (error) {
24707
24287
  throw sessionReadFailure(error, "failed to read discovered evidence-child session");
24708
24288
  }
24709
24289
  const header = entries.find((entry) => entry.type === "session");
24710
- if (!isRecord16(header) || header.parentSession !== sessionFile) continue;
24290
+ if (!isRecord15(header) || header.parentSession !== sessionFile) continue;
24711
24291
  const stop = extractSessionProviderStop(entries);
24712
24292
  if (stop === void 0) continue;
24713
24293
  const primary = knownFailureFromProviderStop(stop);
@@ -24739,12 +24319,12 @@ async function loadBoundAuditorVolumes(sessionFile) {
24739
24319
  return firstLine === RESUME_ENVELOPE;
24740
24320
  };
24741
24321
  const isResumeEnvelope = (msg) => {
24742
- if (!isRecord16(msg) || msg.role !== "user") return false;
24322
+ if (!isRecord15(msg) || msg.role !== "user") return false;
24743
24323
  const text = typeof msg.text === "string" ? msg.text : typeof msg.content === "string" ? msg.content : void 0;
24744
24324
  if (isResumeEnvelopeBytes(text)) return true;
24745
24325
  const content = msg.content;
24746
24326
  if (Array.isArray(content)) {
24747
- return content.some((p) => isRecord16(p) && (isResumeEnvelopeBytes(p.text) || isResumeEnvelopeBytes(p.content)));
24327
+ return content.some((p) => isRecord15(p) && (isResumeEnvelopeBytes(p.text) || isResumeEnvelopeBytes(p.content)));
24748
24328
  }
24749
24329
  return false;
24750
24330
  };
@@ -24756,7 +24336,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
24756
24336
  latestParentUserIndex = i;
24757
24337
  break;
24758
24338
  }
24759
- const childDirectories = [join21(dirname11(sessionFile), "auditor-roles")];
24339
+ const childDirectories = [join20(dirname11(sessionFile), "auditor-roles")];
24760
24340
  const valid = [];
24761
24341
  let sawAnyDirectory = false;
24762
24342
  for (const childDirectory of childDirectories) {
@@ -24771,12 +24351,12 @@ async function loadBoundAuditorVolumes(sessionFile) {
24771
24351
  for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
24772
24352
  let entries;
24773
24353
  try {
24774
- entries = await readBoundSessionEntries(join21(childDirectory, file));
24354
+ entries = await readBoundSessionEntries(join20(childDirectory, file));
24775
24355
  } catch (error) {
24776
24356
  throw sessionReadFailure(error, "failed to read discovered auditor session");
24777
24357
  }
24778
24358
  const header = entries.find((entry) => entry.type === "session");
24779
- if (!isRecord16(header)) continue;
24359
+ if (!isRecord15(header)) continue;
24780
24360
  const bindingIndexes = [];
24781
24361
  for (let i = 0; i < entries.length; i += 1) {
24782
24362
  const entry = entries[i];
@@ -24790,7 +24370,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
24790
24370
  end: idx + 1 < bindingIndexes.length ? bindingIndexes[idx + 1] : entries.length
24791
24371
  })) : [{ entry: void 0, start: 0, end: entries.length }];
24792
24372
  for (const { entry: bindingEntry, start, end } of bindingPasses) {
24793
- const bindingParent = bindingEntry !== void 0 && isRecord16(bindingEntry.data) && isRecord16(bindingEntry.data.parent) ? bindingEntry.data.parent : void 0;
24373
+ const bindingParent = bindingEntry !== void 0 && isRecord15(bindingEntry.data) && isRecord15(bindingEntry.data.parent) ? bindingEntry.data.parent : void 0;
24794
24374
  const attemptEntryId = typeof bindingParent?.attemptEntryId === "string" ? bindingParent.attemptEntryId : void 0;
24795
24375
  const attemptEntryIndex = attemptEntryId === void 0 ? -1 : parentEntries.findIndex((entry) => entry.id === attemptEntryId);
24796
24376
  const boundSessionFile = typeof bindingParent?.sessionFile === "string" ? bindingParent.sessionFile : typeof header.parentSession === "string" ? header.parentSession : void 0;
@@ -24817,11 +24397,11 @@ function complianceFailureFromAuditorVolumes(volumes) {
24817
24397
  if (stop === void 0) continue;
24818
24398
  for (let i = entries.length - 1; i >= 0; i -= 1) {
24819
24399
  const entry = entries[i];
24820
- if (entry?.type !== "custom" || entry.customType !== AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE || !isRecord16(entry.data)) continue;
24821
- const parent = isRecord16(entry.data.parent) ? entry.data.parent : void 0;
24822
- const failure = isRecord16(entry.data.failure) ? entry.data.failure : void 0;
24400
+ if (entry?.type !== "custom" || entry.customType !== AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE || !isRecord15(entry.data)) continue;
24401
+ const parent = isRecord15(entry.data.parent) ? entry.data.parent : void 0;
24402
+ const failure = isRecord15(entry.data.failure) ? entry.data.failure : void 0;
24823
24403
  if (parent?.sessionId !== parentId || parent.sessionFile !== sessionFile || parent.attemptEntryId !== attemptEntryId || failure?.cause !== "provider" && failure?.cause !== "unrecognized") continue;
24824
- const identity = isRecord16(failure.identity) ? failure.identity : void 0;
24404
+ const identity = isRecord15(failure.identity) ? failure.identity : void 0;
24825
24405
  return {
24826
24406
  cause: failure.cause === "provider" ? "provider" : "unrecognized",
24827
24407
  ...identity === void 0 ? {} : { identity: {
@@ -24829,7 +24409,7 @@ function complianceFailureFromAuditorVolumes(volumes) {
24829
24409
  ...typeof identity.code === "string" || typeof identity.code === "number" ? { code: identity.code } : {}
24830
24410
  } },
24831
24411
  ...typeof failure.diagnostic === "string" ? { diagnostic: failure.diagnostic } : {},
24832
- ...isRecord16(failure.details) ? { details: failure.details } : {}
24412
+ ...isRecord15(failure.details) ? { details: failure.details } : {}
24833
24413
  };
24834
24414
  }
24835
24415
  }
@@ -24876,9 +24456,9 @@ function typedFailedTerminatingToolKnownFailure(entries) {
24876
24456
  if (classification.kind !== "infrastructure") continue;
24877
24457
  if (typeof message.toolCallId !== "string" || typeof message.toolName !== "string") continue;
24878
24458
  if (boundRoleToolCallForResult(attemptEntries, i, message, message.toolName) === void 0) continue;
24879
- const textPart = Array.isArray(message.content) ? message.content.find((part) => isRecord16(part) && part.type === "text" && typeof part.text === "string") : void 0;
24880
- const diagnostic = isRecord16(textPart) ? textPart.text : void 0;
24881
- const details = isRecord16(message.details) ? message.details : classification.fact;
24459
+ const textPart = Array.isArray(message.content) ? message.content.find((part) => isRecord15(part) && part.type === "text" && typeof part.text === "string") : void 0;
24460
+ const diagnostic = isRecord15(textPart) ? textPart.text : void 0;
24461
+ const details = isRecord15(message.details) ? message.details : classification.fact;
24882
24462
  return {
24883
24463
  cause: "activation",
24884
24464
  identity: { name: message.toolName, code: message.toolCallId },
@@ -25036,7 +24616,7 @@ function controlledFailureInputFromResolution(resolution) {
25036
24616
  } : {}
25037
24617
  };
25038
24618
  }
25039
- function isRecord16(value) {
24619
+ function isRecord15(value) {
25040
24620
  return typeof value === "object" && value !== null && !Array.isArray(value);
25041
24621
  }
25042
24622
  function safelyRead(object, key) {
@@ -25160,7 +24740,7 @@ function boundRoleToolCallForResult(entries, resultIndex, message, outputToolNam
25160
24740
  const candidateMessage = entries[index]?.message;
25161
24741
  if (candidateMessage?.role === "assistant" && Array.isArray(candidateMessage.content)) {
25162
24742
  for (const part of candidateMessage.content) {
25163
- if (!isRecord16(part) || part.type !== "toolCall" || part.id !== callId) {
24743
+ if (!isRecord15(part) || part.type !== "toolCall" || part.id !== callId) {
25164
24744
  continue;
25165
24745
  }
25166
24746
  if (part.name !== outputToolName) return void 0;
@@ -25232,7 +24812,7 @@ function parseNavigatorAttendanceDetails(details) {
25232
24812
  const advisoryDiagnostic = typeof details.routePlaybookReadFailure === "string" ? { advisoryDiagnostic: details.routePlaybookReadFailure } : {};
25233
24813
  if (disposition === "recommendation") {
25234
24814
  const next = details.next;
25235
- if (!isRecord16(next) || typeof next.role !== "string") {
24815
+ if (!isRecord15(next) || typeof next.role !== "string") {
25236
24816
  return {
25237
24817
  disposition: "unavailable",
25238
24818
  source: "unknown",
@@ -25240,7 +24820,7 @@ function parseNavigatorAttendanceDetails(details) {
25240
24820
  };
25241
24821
  }
25242
24822
  const reason = typeof details.reason === "string" ? details.reason : "";
25243
- const route = Array.isArray(details.route) ? details.route.filter(isRecord16).map((target) => ({
24823
+ const route = Array.isArray(details.route) ? details.route.filter(isRecord15).map((target) => ({
25244
24824
  role: String(target.role),
25245
24825
  phase: navigatorPhaseValue(target.phase)
25246
24826
  })) : void 0;
@@ -25303,8 +24883,8 @@ function projectTerminalGateFact(rounds) {
25303
24883
  };
25304
24884
  }
25305
24885
  async function extractGateFactFromSessionDirectory(sessionDirectory, options = {}) {
25306
- const directories = [join21(sessionDirectory, "auditor-roles")];
25307
- const parentSessionFile = options.parentSessionFile ?? join21(sessionDirectory, "session.jsonl");
24886
+ const directories = [join20(sessionDirectory, "auditor-roles")];
24887
+ const parentSessionFile = options.parentSessionFile ?? join20(sessionDirectory, "session.jsonl");
25308
24888
  const rounds = await readAnalystGateCyclesFromAuditorRoles(directories, {
25309
24889
  parentSessionFile
25310
24890
  });
@@ -25312,7 +24892,7 @@ async function extractGateFactFromSessionDirectory(sessionDirectory, options = {
25312
24892
  }
25313
24893
  async function withOptionalGateProjection(base, sessionDirectory, gateContext = {}) {
25314
24894
  const secondaryEvidence = base.roleOutcome.kind === "failure" ? base.roleOutcome.decisiveFacts.secondaryEvidence : void 0;
25315
- if (isRecord16(secondaryEvidence) && secondaryEvidence.kind === "role_infrastructure_failure" && (secondaryEvidence.stage === "gatekeeper" || secondaryEvidence.stage === "inspector" || secondaryEvidence.stage === "notary")) return base;
24895
+ if (isRecord15(secondaryEvidence) && secondaryEvidence.kind === "role_infrastructure_failure" && (secondaryEvidence.stage === "gatekeeper" || secondaryEvidence.stage === "inspector" || secondaryEvidence.stage === "notary")) return base;
25316
24896
  const gate = await extractGateFactFromSessionDirectory(sessionDirectory, gateContext);
25317
24897
  return gate === void 0 ? base : { ...base, gate };
25318
24898
  }
@@ -25352,7 +24932,7 @@ function extractNavigatorFact(entries) {
25352
24932
  const entry = entries[i];
25353
24933
  if (entry?.type === "custom_message" && entry.customType === "ak-navigator-attendance") {
25354
24934
  const details = entry.message?.details ?? entry.details;
25355
- if (!isRecord16(details)) {
24935
+ if (!isRecord15(details)) {
25356
24936
  return {
25357
24937
  disposition: "unavailable",
25358
24938
  source: "unknown",
@@ -25402,8 +24982,8 @@ async function extractNavigatorFactFromAdmittedSession(sessionFile) {
25402
24982
  async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
25403
24983
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
25404
24984
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
25405
- const reportPath = join21(artifactsDir, "report.json");
25406
- const evidencePath = join21(artifactsDir, "evidence.json");
24985
+ const reportPath = join20(artifactsDir, "report.json");
24986
+ const evidencePath = join20(artifactsDir, "evidence.json");
25407
24987
  await writeFile5(
25408
24988
  reportPath,
25409
24989
  `${JSON.stringify(
@@ -25447,8 +25027,8 @@ async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
25447
25027
  async function publishCoderArtifacts(admitted, roleOutcome, coordinates, options = {}) {
25448
25028
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
25449
25029
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
25450
- const reportPath = join21(artifactsDir, "report.json");
25451
- const evidencePath = join21(artifactsDir, "evidence.json");
25030
+ const reportPath = join20(artifactsDir, "report.json");
25031
+ const evidencePath = join20(artifactsDir, "evidence.json");
25452
25032
  await writeFile5(
25453
25033
  reportPath,
25454
25034
  `${JSON.stringify(
@@ -25599,8 +25179,8 @@ function extractFixerMethodInvocations(entries, options) {
25599
25179
  async function publishFixerArtifacts(admitted, roleOutcome, coordinates, options) {
25600
25180
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
25601
25181
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
25602
- const reportPath = join21(artifactsDir, "report.json");
25603
- const evidencePath = join21(artifactsDir, "evidence.json");
25182
+ const reportPath = join20(artifactsDir, "report.json");
25183
+ const evidencePath = join20(artifactsDir, "evidence.json");
25604
25184
  await writeFile5(
25605
25185
  reportPath,
25606
25186
  `${JSON.stringify(
@@ -25690,8 +25270,8 @@ async function settleLawfulFixerTerminalResult(admitted, authority, options) {
25690
25270
  async function publishCollectorArtifacts(admitted, roleOutcome, coordinates, options = {}) {
25691
25271
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
25692
25272
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
25693
- const reportPath = join21(artifactsDir, "report.json");
25694
- const evidencePath = join21(artifactsDir, "evidence.json");
25273
+ const reportPath = join20(artifactsDir, "report.json");
25274
+ const evidencePath = join20(artifactsDir, "evidence.json");
25695
25275
  await writeFile5(
25696
25276
  reportPath,
25697
25277
  `${JSON.stringify(
@@ -25750,7 +25330,7 @@ async function settleLawfulCollectorTerminalResult(admitted, authority) {
25750
25330
  const residual = boundErroredToolCandidate(entries, index, message, COLLECTOR_WAIT_TOOL);
25751
25331
  if (residual === void 0) continue;
25752
25332
  const candidate = residual.candidate;
25753
- const duration = isRecord16(candidate) ? candidate.durationMs : void 0;
25333
+ const duration = isRecord15(candidate) ? candidate.durationMs : void 0;
25754
25334
  if (Number.isSafeInteger(duration) && duration >= 1 && duration <= 9e5) {
25755
25335
  continue;
25756
25336
  }
@@ -25798,8 +25378,8 @@ async function trySettleCollectorTerminalResult(admitted, authority) {
25798
25378
  async function publishDoctorArtifacts(admitted, roleOutcome, coordinates, options = {}) {
25799
25379
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
25800
25380
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
25801
- const reportPath = join21(artifactsDir, "report.json");
25802
- const evidencePath = join21(artifactsDir, "evidence.json");
25381
+ const reportPath = join20(artifactsDir, "report.json");
25382
+ const evidencePath = join20(artifactsDir, "evidence.json");
25803
25383
  await writeFile5(
25804
25384
  reportPath,
25805
25385
  `${JSON.stringify(
@@ -25940,7 +25520,7 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
25940
25520
  spec.toolName
25941
25521
  );
25942
25522
  if (residual !== void 0) {
25943
- const details = isRecord16(residual.candidate) ? residual.candidate : { candidate: residual.candidate };
25523
+ const details = isRecord15(residual.candidate) ? residual.candidate : { candidate: residual.candidate };
25944
25524
  return settleFailureTerminalResult(admitted, {
25945
25525
  cause: "output",
25946
25526
  diagnostic: residual.diagnostic,
@@ -26059,8 +25639,8 @@ function extractReviewerMethodInvocations(entries, options) {
26059
25639
  async function publishReviewerArtifacts(admitted, roleOutcome, coordinates, options) {
26060
25640
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
26061
25641
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
26062
- const reportPath = join21(artifactsDir, "report.json");
26063
- const evidencePath = join21(artifactsDir, "evidence.json");
25642
+ const reportPath = join20(artifactsDir, "report.json");
25643
+ const evidencePath = join20(artifactsDir, "evidence.json");
26064
25644
  await writeFile5(
26065
25645
  reportPath,
26066
25646
  `${JSON.stringify(
@@ -26174,8 +25754,8 @@ function extractMergerMethodInvocations(entries, options) {
26174
25754
  async function publishMergerArtifacts(admitted, roleOutcome, coordinates, options) {
26175
25755
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
26176
25756
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
26177
- const reportPath = join21(artifactsDir, "report.json");
26178
- const evidencePath = join21(artifactsDir, "evidence.json");
25757
+ const reportPath = join20(artifactsDir, "report.json");
25758
+ const evidencePath = join20(artifactsDir, "evidence.json");
26179
25759
  await writeFile5(
26180
25760
  reportPath,
26181
25761
  `${JSON.stringify(
@@ -26242,7 +25822,7 @@ async function settleLawfulMergerTerminalResult(admitted, authority, options) {
26242
25822
  if (message?.role !== "toolResult") continue;
26243
25823
  const residual = boundErroredToolCandidate(entries, index, message, MERGER_OUTPUT_TOOL_NAME);
26244
25824
  if (residual === void 0) continue;
26245
- const attemptId = isRecord16(residual.candidate) ? safelyRead(residual.candidate, "attemptId") : { readable: true, value: void 0 };
25825
+ const attemptId = isRecord15(residual.candidate) ? safelyRead(residual.candidate, "attemptId") : { readable: true, value: void 0 };
26246
25826
  if (!attemptId.readable || attemptId.value !== admitted.runId) continue;
26247
25827
  return {
26248
25828
  roleOutcome: buildResidualIncompleteTerminalOutcome({
@@ -26320,7 +25900,7 @@ function uniqueFailureFallbackDirs(runDirectory, baseDir) {
26320
25900
  return dirs;
26321
25901
  }
26322
25902
  async function resolveFailureArtifactsBase(runDirectory) {
26323
- const artifactsDir = join21(runDirectory, "artifacts");
25903
+ const artifactsDir = join20(runDirectory, "artifacts");
26324
25904
  try {
26325
25905
  await ensureRunArtifactsDir(runDirectory);
26326
25906
  return { baseDir: artifactsDir };
@@ -26336,7 +25916,7 @@ async function writeFailureJsonRetainingCause(preferredCandidates, uniqueFallbac
26336
25916
  const candidates = [
26337
25917
  ...preferredCandidates,
26338
25918
  // One unique name per fallback dir — collisions on fixed names cannot exhaust this.
26339
- ...uniqueFallbackDirs.map((dir) => join21(dir, `${stem}.${randomUUID3()}.json`))
25919
+ ...uniqueFallbackDirs.map((dir) => join20(dir, `${stem}.${randomUUID3()}.json`))
26340
25920
  ];
26341
25921
  for (let i = 0; i < candidates.length; i += 1) {
26342
25922
  const path = candidates[i];
@@ -26381,26 +25961,26 @@ async function publishFailureArtifacts(admitted, failure, authority) {
26381
25961
  } catch (error) {
26382
25962
  priorIssues.push(publicationAttemptFromError(sessionFile, error));
26383
25963
  }
26384
- const underArtifacts = baseDir === join21(admitted.runDirectory, "artifacts");
25964
+ const underArtifacts = baseDir === join20(admitted.runDirectory, "artifacts");
26385
25965
  const uniqueFallbackDirs = uniqueFailureFallbackDirs(
26386
25966
  admitted.runDirectory,
26387
25967
  baseDir
26388
25968
  );
26389
25969
  const errorCandidates = underArtifacts ? [
26390
- join21(baseDir, "error.json"),
26391
- join21(baseDir, "error.settlement.json"),
26392
- join21(admitted.runDirectory, "error.settlement.json")
25970
+ join20(baseDir, "error.json"),
25971
+ join20(baseDir, "error.settlement.json"),
25972
+ join20(admitted.runDirectory, "error.settlement.json")
26393
25973
  ] : [
26394
- join21(baseDir, "error.settlement.json"),
26395
- join21(baseDir, "error.json")
25974
+ join20(baseDir, "error.settlement.json"),
25975
+ join20(baseDir, "error.json")
26396
25976
  ];
26397
25977
  const evidenceCandidates = underArtifacts ? [
26398
- join21(baseDir, "evidence.json"),
26399
- join21(baseDir, "evidence.settlement.json"),
26400
- join21(admitted.runDirectory, "evidence.settlement.json")
25978
+ join20(baseDir, "evidence.json"),
25979
+ join20(baseDir, "evidence.settlement.json"),
25980
+ join20(admitted.runDirectory, "evidence.settlement.json")
26401
25981
  ] : [
26402
- join21(baseDir, "evidence.settlement.json"),
26403
- join21(baseDir, "evidence.json")
25982
+ join20(baseDir, "evidence.settlement.json"),
25983
+ join20(baseDir, "evidence.json")
26404
25984
  ];
26405
25985
  const errorPayloadBase = {
26406
25986
  kind: "error",
@@ -26666,9 +26246,336 @@ function projectRoleTurnRequest(admitted, roleDetails, options) {
26666
26246
  ...options.timeoutMs === void 0 ? {} : { timeoutMs: options.timeoutMs }
26667
26247
  };
26668
26248
  }
26669
- var init_turn_request = __esm({
26670
- "src/public-cli/turn-request.ts"() {
26249
+ var init_turn_request = __esm({
26250
+ "src/public-cli/turn-request.ts"() {
26251
+ "use strict";
26252
+ }
26253
+ });
26254
+
26255
+ // src/ticket-provenance-contracts.ts
26256
+ function isRecord16(value) {
26257
+ return typeof value === "object" && value !== null && !Array.isArray(value);
26258
+ }
26259
+ function projectTicketProvenanceDiagnostic(value) {
26260
+ if (!isRecord16(value)) return void 0;
26261
+ if (value.recordClass !== TICKET_PROVENANCE_RECORD_CLASS_DIAGNOSTIC) {
26262
+ return void 0;
26263
+ }
26264
+ if (typeof value.diagnosticKind !== "string" || !DIAGNOSTIC_KINDS.has(value.diagnosticKind)) {
26265
+ return void 0;
26266
+ }
26267
+ if (typeof value.cause !== "string" || value.cause.length === 0) {
26268
+ return void 0;
26269
+ }
26270
+ if (typeof value.recordedAt !== "string" || value.recordedAt.length === 0) {
26271
+ return void 0;
26272
+ }
26273
+ return {
26274
+ recordClass: TICKET_PROVENANCE_RECORD_CLASS_DIAGNOSTIC,
26275
+ diagnosticKind: value.diagnosticKind,
26276
+ cause: value.cause,
26277
+ recordedAt: value.recordedAt,
26278
+ ...typeof value.reason === "string" ? { reason: value.reason } : {}
26279
+ };
26280
+ }
26281
+ function projectTicketProvenanceEntry(value) {
26282
+ if (!isRecord16(value)) return void 0;
26283
+ if (value.recordClass === TICKET_PROVENANCE_RECORD_CLASS_DIAGNOSTIC) {
26284
+ return void 0;
26285
+ }
26286
+ if (!isRecord16(value.basis)) return void 0;
26287
+ if (typeof value.basis.method !== "string" || !BASIS_METHODS.has(value.basis.method)) {
26288
+ return void 0;
26289
+ }
26290
+ if (typeof value.sourceKind !== "string" || !SOURCE_KINDS.has(value.sourceKind)) {
26291
+ return void 0;
26292
+ }
26293
+ if (!isRecord16(value.sourceRef)) return void 0;
26294
+ if (typeof value.transcript !== "string" || value.transcript.length === 0) {
26295
+ return void 0;
26296
+ }
26297
+ if (typeof value.timestamp !== "string" || value.timestamp.length === 0) {
26298
+ return void 0;
26299
+ }
26300
+ const basis = {
26301
+ method: value.basis.method,
26302
+ ...Array.isArray(value.basis.anchors) ? {
26303
+ anchors: value.basis.anchors.filter(
26304
+ (item) => typeof item === "string"
26305
+ )
26306
+ } : {},
26307
+ ...typeof value.basis.note === "string" ? { note: value.basis.note } : {}
26308
+ };
26309
+ const sourceRef = {
26310
+ ...typeof value.sourceRef.sessionFile === "string" ? { sessionFile: value.sourceRef.sessionFile } : {},
26311
+ ...typeof value.sourceRef.entryId === "string" || typeof value.sourceRef.entryId === "number" ? { entryId: value.sourceRef.entryId } : {},
26312
+ ...typeof value.sourceRef.path === "string" ? { path: value.sourceRef.path } : {},
26313
+ ...typeof value.sourceRef.url === "string" ? { url: value.sourceRef.url } : {}
26314
+ };
26315
+ return {
26316
+ basis,
26317
+ sourceKind: value.sourceKind,
26318
+ sourceRef,
26319
+ transcript: value.transcript,
26320
+ timestamp: value.timestamp
26321
+ };
26322
+ }
26323
+ var TICKET_PROVENANCE_KIND, TICKET_PROVENANCE_HUMAN_VIEW, TICKET_PROVENANCE_OFFERED_WATERMARK, TICKET_PROVENANCE_RECORD_CLASS_DIAGNOSTIC, SOURCE_KINDS, BASIS_METHODS, DIAGNOSTIC_KINDS;
26324
+ var init_ticket_provenance_contracts = __esm({
26325
+ "src/ticket-provenance-contracts.ts"() {
26326
+ "use strict";
26327
+ TICKET_PROVENANCE_KIND = "ticket-provenance";
26328
+ TICKET_PROVENANCE_HUMAN_VIEW = "\u8D77\u5C45\u5F55.md";
26329
+ TICKET_PROVENANCE_OFFERED_WATERMARK = "offered-identities.jsonl";
26330
+ TICKET_PROVENANCE_RECORD_CLASS_DIAGNOSTIC = "diagnostic";
26331
+ SOURCE_KINDS = /* @__PURE__ */ new Set([
26332
+ "cc-session",
26333
+ "issue-body-comment",
26334
+ "adr-decision-key",
26335
+ "ticket-decree-block"
26336
+ ]);
26337
+ BASIS_METHODS = /* @__PURE__ */ new Set(["llm-semantic"]);
26338
+ DIAGNOSTIC_KINDS = /* @__PURE__ */ new Set([
26339
+ "collector-failed",
26340
+ "issue-source-failed",
26341
+ "quote-verify-failed"
26342
+ ]);
26343
+ }
26344
+ });
26345
+
26346
+ // src/ticket-provenance.ts
26347
+ import { createHash as createHash5 } from "node:crypto";
26348
+ import { appendFileSync as appendFileSync2, existsSync as existsSync7, mkdirSync as mkdirSync3, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "node:fs";
26349
+ import { join as join21 } from "node:path";
26350
+ function ticketProvenanceSubject(ticketNumber) {
26351
+ if (!Number.isSafeInteger(ticketNumber) || ticketNumber < 1) {
26352
+ throw new Error(`ticket-provenance subject requires a positive ticket number, got ${String(ticketNumber)}`);
26353
+ }
26354
+ return String(ticketNumber);
26355
+ }
26356
+ function ticketProvenanceEntryIdentity(input) {
26357
+ const ref = input.sourceRef;
26358
+ const refKey = [
26359
+ ref.sessionFile ?? "",
26360
+ ref.entryId === void 0 ? "" : String(ref.entryId),
26361
+ ref.path ?? "",
26362
+ ref.url ?? ""
26363
+ ].join("");
26364
+ const material = [
26365
+ String(input.ticketNumber),
26366
+ input.sourceKind,
26367
+ refKey,
26368
+ input.transcript
26369
+ ].join("\0");
26370
+ return createHash5("sha256").update(material, "utf8").digest("hex");
26371
+ }
26372
+ function resolveTicketProvenanceVolume(ticketNumber, cwd, home) {
26373
+ const path = resolveSitianRecordPath({
26374
+ level: "event",
26375
+ kind: TICKET_PROVENANCE_KIND,
26376
+ subject: ticketProvenanceSubject(ticketNumber),
26377
+ cwd,
26378
+ ...home === void 0 ? {} : { home }
26379
+ });
26380
+ return {
26381
+ recordFile: path.recordFile,
26382
+ volumeDir: path.sessionDir,
26383
+ humanViewFile: join21(path.sessionDir, TICKET_PROVENANCE_HUMAN_VIEW),
26384
+ offeredWatermarkFile: join21(path.sessionDir, TICKET_PROVENANCE_OFFERED_WATERMARK)
26385
+ };
26386
+ }
26387
+ function readOfferedIdentities(ticketNumber, cwd, home) {
26388
+ const { offeredWatermarkFile } = resolveTicketProvenanceVolume(ticketNumber, cwd, home);
26389
+ if (!existsSync7(offeredWatermarkFile)) return /* @__PURE__ */ new Set();
26390
+ let text;
26391
+ try {
26392
+ text = readFileSync2(offeredWatermarkFile, "utf8");
26393
+ } catch (error) {
26394
+ throw new TicketProvenanceWatermarkError(
26395
+ "unreadable",
26396
+ `ticket-provenance offered watermark unreadable (${offeredWatermarkFile})`,
26397
+ { cause: error }
26398
+ );
26399
+ }
26400
+ const seen = /* @__PURE__ */ new Set();
26401
+ const lines = text.split("\n");
26402
+ for (let index = 0; index < lines.length; index += 1) {
26403
+ const trimmed = lines[index].trim();
26404
+ if (!trimmed) continue;
26405
+ let parsed;
26406
+ try {
26407
+ parsed = JSON.parse(trimmed);
26408
+ } catch (error) {
26409
+ throw new TicketProvenanceWatermarkError(
26410
+ "malformed-json",
26411
+ `ticket-provenance offered watermark malformed JSON at line ${index + 1} (${offeredWatermarkFile})`,
26412
+ { cause: error }
26413
+ );
26414
+ }
26415
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed) || typeof parsed.identity !== "string" || parsed.identity.length === 0) {
26416
+ throw new TicketProvenanceWatermarkError(
26417
+ "bad-shape",
26418
+ `ticket-provenance offered watermark bad shape at line ${index + 1} (${offeredWatermarkFile})`
26419
+ );
26420
+ }
26421
+ seen.add(parsed.identity);
26422
+ }
26423
+ return seen;
26424
+ }
26425
+ async function readTicketProvenance(ticketNumber, cwd, home) {
26426
+ const { recordFile } = resolveTicketProvenanceVolume(ticketNumber, cwd, home);
26427
+ const { records: records2 } = await readSitianRecords(recordFile);
26428
+ const entries = [];
26429
+ const diagnostics = [];
26430
+ let skipped = 0;
26431
+ for (const record4 of records2) {
26432
+ if (record4.kind !== TICKET_PROVENANCE_KIND) {
26433
+ skipped += 1;
26434
+ continue;
26435
+ }
26436
+ const diagnostic = projectTicketProvenanceDiagnostic(record4.payload);
26437
+ if (diagnostic !== void 0) {
26438
+ diagnostics.push(diagnostic);
26439
+ continue;
26440
+ }
26441
+ const entry = projectTicketProvenanceEntry(record4.payload);
26442
+ if (entry === void 0) {
26443
+ skipped += 1;
26444
+ continue;
26445
+ }
26446
+ entries.push(entry);
26447
+ }
26448
+ return { entries, diagnostics, records: records2, recordFile, skipped };
26449
+ }
26450
+ function markdownFenceFor(text) {
26451
+ let longest = 0;
26452
+ const runs = text.match(/`+/g);
26453
+ if (runs !== null) {
26454
+ for (const run of runs) {
26455
+ if (run.length > longest) longest = run.length;
26456
+ }
26457
+ }
26458
+ return "`".repeat(Math.max(3, longest + 1));
26459
+ }
26460
+ function renderTicketProvenanceMarkdown(input) {
26461
+ const lines = [
26462
+ `# \u8D77\u5C45\u5F55 \xB7 #${input.ticketNumber}`,
26463
+ "",
26464
+ `\u6761\u76EE\u6570\uFF1A${input.entries.length}`,
26465
+ ""
26466
+ ];
26467
+ let index = 0;
26468
+ for (const entry of input.entries) {
26469
+ index += 1;
26470
+ lines.push(`## ${index}. ${entry.sourceKind} \xB7 ${entry.timestamp}`);
26471
+ lines.push("");
26472
+ lines.push(`- basis.method: \`${entry.basis.method}\``);
26473
+ if (entry.basis.anchors !== void 0 && entry.basis.anchors.length > 0) {
26474
+ lines.push(`- anchors: ${entry.basis.anchors.map((a) => `\`${a}\``).join(", ")}`);
26475
+ }
26476
+ if (entry.basis.note !== void 0) {
26477
+ lines.push(`- note: ${entry.basis.note}`);
26478
+ }
26479
+ const refParts = [];
26480
+ if (entry.sourceRef.sessionFile !== void 0) {
26481
+ refParts.push(`sessionFile=${entry.sourceRef.sessionFile}`);
26482
+ }
26483
+ if (entry.sourceRef.entryId !== void 0) {
26484
+ refParts.push(`entryId=${String(entry.sourceRef.entryId)}`);
26485
+ }
26486
+ if (entry.sourceRef.path !== void 0) {
26487
+ refParts.push(`path=${entry.sourceRef.path}`);
26488
+ }
26489
+ if (entry.sourceRef.url !== void 0) {
26490
+ refParts.push(`url=${entry.sourceRef.url}`);
26491
+ }
26492
+ if (refParts.length > 0) {
26493
+ lines.push(`- sourceRef: ${refParts.join(" \xB7 ")}`);
26494
+ }
26495
+ lines.push("");
26496
+ const fence = markdownFenceFor(entry.transcript);
26497
+ lines.push(fence);
26498
+ lines.push(entry.transcript);
26499
+ lines.push(fence);
26500
+ lines.push("");
26501
+ }
26502
+ return lines.join("\n");
26503
+ }
26504
+ function ensureTicketProvenanceVolume(ticketNumber, cwd, home) {
26505
+ const volume = resolveTicketProvenanceVolume(ticketNumber, cwd, home);
26506
+ mkdirSync3(volume.volumeDir, { recursive: true });
26507
+ appendFileSync2(volume.recordFile, "", "utf8");
26508
+ return volume;
26509
+ }
26510
+ function appendTicketProvenanceDiagnostic(input) {
26511
+ const subject = ticketProvenanceSubject(input.ticketNumber);
26512
+ const identityParts = input.diagnostic.diagnosticKind === "quote-verify-failed" ? [
26513
+ subject,
26514
+ input.diagnostic.recordClass,
26515
+ input.diagnostic.diagnosticKind,
26516
+ input.diagnostic.cause,
26517
+ input.diagnostic.reason ?? ""
26518
+ ] : [
26519
+ subject,
26520
+ input.diagnostic.recordClass,
26521
+ input.diagnostic.diagnosticKind,
26522
+ input.diagnostic.recordedAt,
26523
+ input.diagnostic.cause,
26524
+ input.diagnostic.reason ?? ""
26525
+ ];
26526
+ const identity = createHash5("sha256").update(identityParts.join("\0"), "utf8").digest("hex");
26527
+ return sitianReport({
26528
+ level: "event",
26529
+ kind: TICKET_PROVENANCE_KIND,
26530
+ identity,
26531
+ subject,
26532
+ cwd: input.cwd,
26533
+ ...input.home === void 0 ? {} : { home: input.home },
26534
+ host: input.host ?? "diarist",
26535
+ source: input.source ?? "diarist-diagnostic",
26536
+ payload: input.diagnostic
26537
+ });
26538
+ }
26539
+ function appendIssueSourceFailureDiagnostic(input) {
26540
+ const recordedAt = input.recordedAt ?? (/* @__PURE__ */ new Date()).toISOString();
26541
+ return appendTicketProvenanceDiagnostic({
26542
+ ticketNumber: input.ticketNumber,
26543
+ cwd: input.cwd,
26544
+ ...input.home === void 0 ? {} : { home: input.home },
26545
+ source: "diarist-issue-source",
26546
+ diagnostic: {
26547
+ recordClass: TICKET_PROVENANCE_RECORD_CLASS_DIAGNOSTIC,
26548
+ diagnosticKind: "issue-source-failed",
26549
+ cause: input.cause,
26550
+ recordedAt,
26551
+ reason: input.reason
26552
+ }
26553
+ });
26554
+ }
26555
+ function writeTicketProvenanceHumanView(input) {
26556
+ const volume = ensureTicketProvenanceVolume(input.ticketNumber, input.cwd, input.home);
26557
+ const md = renderTicketProvenanceMarkdown({
26558
+ ticketNumber: input.ticketNumber,
26559
+ entries: input.entries
26560
+ });
26561
+ writeFileSync2(volume.humanViewFile, md, "utf8");
26562
+ return volume.humanViewFile;
26563
+ }
26564
+ var TicketProvenanceWatermarkError;
26565
+ var init_ticket_provenance = __esm({
26566
+ "src/ticket-provenance.ts"() {
26671
26567
  "use strict";
26568
+ init_sitian_facade();
26569
+ init_ticket_provenance_contracts();
26570
+ TicketProvenanceWatermarkError = class extends Error {
26571
+ code = "ticket-provenance-watermark";
26572
+ reason;
26573
+ constructor(reason, message, options) {
26574
+ super(message, options);
26575
+ this.name = "TicketProvenanceWatermarkError";
26576
+ this.reason = reason;
26577
+ }
26578
+ };
26672
26579
  }
26673
26580
  });
26674
26581
 
@@ -27854,12 +27761,7 @@ async function runPublicCoder(argv, env, io, parseCoderArgv2) {
27854
27761
  })
27855
27762
  }
27856
27763
  }),
27857
- adapters: {
27858
- ...coderAdapters(methodProvenance),
27859
- beforeDispatch: async (admittedSeat) => {
27860
- await resolveSeatTicketBinding(admittedSeat, env);
27861
- }
27862
- },
27764
+ adapters: coderAdapters(methodProvenance),
27863
27765
  ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
27864
27766
  });
27865
27767
  }
@@ -27919,7 +27821,6 @@ var init_coder_run = __esm({
27919
27821
  init_method_skill();
27920
27822
  init_cli_errors();
27921
27823
  init_invocation();
27922
- init_seat_ticket_binding();
27923
27824
  init_run_lifecycle();
27924
27825
  init_settlement();
27925
27826
  init_turn_request();
@@ -27927,6 +27828,30 @@ var init_coder_run = __esm({
27927
27828
  }
27928
27829
  });
27929
27830
 
27831
+ // src/public-cli/seat-ticket-binding.ts
27832
+ async function tryResumeSameTicketSeatRun(input) {
27833
+ if (input.freshSummons === true) return void 0;
27834
+ if (input.parentRunPath === void 0 && input.ticketNumber === void 0) {
27835
+ return void 0;
27836
+ }
27837
+ const previousRunId = await findLatestRunIdForSeatTicket({
27838
+ home: input.home,
27839
+ bookKey: resolveBookKeyFromGit(input.projectRoot),
27840
+ role: input.role,
27841
+ ...input.parentRunPath === void 0 ? {} : { parentRunPath: input.parentRunPath },
27842
+ ...input.ticketNumber === void 0 ? {} : { ticketNumber: input.ticketNumber }
27843
+ });
27844
+ if (previousRunId === void 0) return void 0;
27845
+ return await input.resume(previousRunId, input.summons);
27846
+ }
27847
+ var init_seat_ticket_binding = __esm({
27848
+ "src/public-cli/seat-ticket-binding.ts"() {
27849
+ "use strict";
27850
+ init_activation_ledger_git();
27851
+ init_run_lifecycle();
27852
+ }
27853
+ });
27854
+
27930
27855
  // src/public-cli/instruction-seat-run.ts
27931
27856
  function buildInstructionSeatTurnRequest(admitted, options) {
27932
27857
  return projectRoleTurnRequest(
@@ -28048,7 +27973,6 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv2) {
28048
27973
  let auditorSubject;
28049
27974
  let auditorSourceRun;
28050
27975
  let auditorSourceTicket;
28051
- let reusedTicketNumber;
28052
27976
  const projectRoot = parsed.project ?? env.cwd;
28053
27977
  if (role === "auditor") {
28054
27978
  if (parsed.subject !== "judge" && parsed.subject !== "doctor") {
@@ -28083,12 +28007,6 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv2) {
28083
28007
  );
28084
28008
  return { exitCode: 2 };
28085
28009
  }
28086
- } else {
28087
- reusedTicketNumber = await resolveKnownTicketNumber({
28088
- instruction: parsed.instruction,
28089
- projectRoot,
28090
- home: env.home
28091
- });
28092
28010
  }
28093
28011
  const summons = {
28094
28012
  instruction: parsed.instruction,
@@ -28114,21 +28032,6 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv2) {
28114
28032
  })
28115
28033
  });
28116
28034
  if (resumed !== void 0) return resumed;
28117
- } else if (reusedTicketNumber !== void 0) {
28118
- const resumed = await tryResumeSameTicketSeatRun({
28119
- home: env.home,
28120
- projectRoot,
28121
- role,
28122
- ticketNumber: reusedTicketNumber,
28123
- freshSummons: env.freshSummons,
28124
- summons,
28125
- resume: (runId, materials) => runPublicInstructionSeatResume(
28126
- { runId, ...materials === void 0 ? {} : { summons: materials } },
28127
- env,
28128
- io
28129
- )
28130
- });
28131
- if (resumed !== void 0) return resumed;
28132
28035
  }
28133
28036
  let admitted;
28134
28037
  try {
@@ -28186,8 +28089,6 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv2) {
28186
28089
  beforeDispatch: async (admittedSeat) => {
28187
28090
  if (auditorSourceTicket !== void 0) {
28188
28091
  await bindAdmittedTicketNumber(admittedSeat, auditorSourceTicket);
28189
- } else {
28190
- await bindReusedTicketNumber(admittedSeat, reusedTicketNumber);
28191
28092
  }
28192
28093
  }
28193
28094
  }),
@@ -28320,7 +28221,7 @@ var init_collector_run = __esm({
28320
28221
 
28321
28222
  // src/diarist-mechanical.ts
28322
28223
  import { createHash as createHash6 } from "node:crypto";
28323
- import { existsSync as existsSync9, readdirSync as readdirSync2, readFileSync as readFileSync3, realpathSync as realpathSync3, statSync as statSync2 } from "node:fs";
28224
+ import { existsSync as existsSync8, readdirSync as readdirSync2, readFileSync as readFileSync3, realpathSync as realpathSync3, statSync as statSync2 } from "node:fs";
28324
28225
  import { basename as basename7, join as join25, resolve as resolve10 } from "node:path";
28325
28226
  import { homedir } from "node:os";
28326
28227
  function extractCornerQuotes(text, minLength = DEFAULT_QUOTE_MIN) {
@@ -28402,7 +28303,7 @@ function isNotificationRow(type, text) {
28402
28303
  }
28403
28304
  function readCcSessionBlocks(options) {
28404
28305
  const root = options.projectsRoot ?? join25(homedir(), ".claude", "projects");
28405
- if (!existsSync9(root)) return [];
28306
+ if (!existsSync8(root)) return [];
28406
28307
  const blocks = [];
28407
28308
  const dirs = /* @__PURE__ */ new Set();
28408
28309
  for (const cwd of options.cwds) {
@@ -28411,10 +28312,10 @@ function readCcSessionBlocks(options) {
28411
28312
  for (const cwd of options.cwds) {
28412
28313
  if (cwd.includes("projects")) continue;
28413
28314
  const direct = join25(root, cwd);
28414
- if (existsSync9(direct)) dirs.add(direct);
28315
+ if (existsSync8(direct)) dirs.add(direct);
28415
28316
  }
28416
28317
  for (const dir of dirs) {
28417
- if (!existsSync9(dir)) continue;
28318
+ if (!existsSync8(dir)) continue;
28418
28319
  let dirStat;
28419
28320
  try {
28420
28321
  dirStat = statSync2(dir);
@@ -28539,7 +28440,7 @@ function readAdrDecisionKeyBlocks(input) {
28539
28440
  const adrRootAbs = resolve10(cwdAbs, DIARIST_ADR_ROOT_REL);
28540
28441
  let adrRootReal;
28541
28442
  try {
28542
- adrRootReal = existsSync9(adrRootAbs) ? realpathSync3(adrRootAbs) : resolve10(realpathSync3(cwdAbs), DIARIST_ADR_ROOT_REL);
28443
+ adrRootReal = existsSync8(adrRootAbs) ? realpathSync3(adrRootAbs) : resolve10(realpathSync3(cwdAbs), DIARIST_ADR_ROOT_REL);
28543
28444
  } catch (error) {
28544
28445
  throw new DiaristSourceReadError(
28545
28446
  "adr-unreadable",
@@ -28565,7 +28466,7 @@ function readAdrDecisionKeyBlocks(input) {
28565
28466
  `diarist referenced ADR escapes docs/adr (${rel})`
28566
28467
  );
28567
28468
  }
28568
- if (!existsSync9(abs)) {
28469
+ if (!existsSync8(abs)) {
28569
28470
  throw new DiaristSourceReadError(
28570
28471
  "adr-missing",
28571
28472
  abs,
@@ -28797,22 +28698,28 @@ function loadSourceBlocks(input) {
28797
28698
  return blocks;
28798
28699
  }
28799
28700
  async function prepareDiaristSourceCatalog(input) {
28800
- ensureTicketProvenanceVolume(input.ticketNumber, input.cwd, input.home);
28801
- const volume = await readTicketProvenance(input.ticketNumber, input.cwd, input.home);
28802
- writeTicketProvenanceHumanView({
28803
- ticketNumber: input.ticketNumber,
28804
- cwd: input.cwd,
28805
- ...input.home === void 0 ? {} : { home: input.home },
28806
- entries: volume.entries
28807
- });
28701
+ const known = input.ticketNumber;
28702
+ if (known !== void 0) {
28703
+ ensureTicketProvenanceVolume(known, input.cwd, input.home);
28704
+ const volume = await readTicketProvenance(known, input.cwd, input.home);
28705
+ writeTicketProvenanceHumanView({
28706
+ ticketNumber: known,
28707
+ cwd: input.cwd,
28708
+ ...input.home === void 0 ? {} : { home: input.home },
28709
+ entries: volume.entries
28710
+ });
28711
+ }
28808
28712
  const rawBlocks = loadSourceBlocks(input);
28809
28713
  const safeguarded = mechanicalSafeguardPipeline(rawBlocks);
28810
- const seen = await loadSeenEntryIdentities(input.ticketNumber, input.cwd, input.home);
28714
+ const seen = known === void 0 ? /* @__PURE__ */ new Set() : await loadSeenEntryIdentities(known, input.cwd, input.home);
28811
28715
  const fresh = safeguarded.filter(
28812
- (block) => !seen.has(blockEntryIdentity(input.ticketNumber, block))
28716
+ (block) => known === void 0 || !seen.has(blockEntryIdentity(known, block))
28813
28717
  );
28814
28718
  return {
28815
- ticketNumber: input.ticketNumber,
28719
+ ...known === void 0 ? {} : { ticketNumber: known },
28720
+ instruction: input.instruction,
28721
+ runDirectory: input.runDirectory,
28722
+ projectRoot: input.projectRoot,
28816
28723
  cwd: input.cwd,
28817
28724
  ...input.home === void 0 ? {} : { home: input.home },
28818
28725
  candidates: fresh.map((block, candidateIndex) => ({ ...block, candidateIndex }))
@@ -28850,7 +28757,7 @@ __export(diarist_run_exports, {
28850
28757
  runPublicDiarist: () => runPublicDiarist,
28851
28758
  runPublicDiaristResume: () => runPublicDiaristResume
28852
28759
  });
28853
- import { existsSync as existsSync10 } from "node:fs";
28760
+ import { existsSync as existsSync9 } from "node:fs";
28854
28761
  import { writeFile as writeFile7 } from "node:fs/promises";
28855
28762
  import { join as join26 } from "node:path";
28856
28763
  function withDiaristCatalogPath(prompt, sourcesPath) {
@@ -28877,22 +28784,24 @@ function buildDiaristTurnRequest(admitted, options, sourcesPath) {
28877
28784
  );
28878
28785
  }
28879
28786
  async function freezeDiaristSourceCatalog(admitted, env) {
28880
- if (admitted.ticketNumber === void 0) return void 0;
28881
28787
  const path = join26(admitted.runDirectory, DIARIST_SOURCE_CATALOG_FILE);
28882
- if (existsSync10(path)) {
28788
+ if (existsSync9(path)) {
28883
28789
  const identity = await readRoleRunIdentity(admitted.runDirectory);
28884
28790
  if (identity !== void 0 && identity.state !== "terminal") return path;
28885
28791
  }
28886
- const issueFace = await loadDiaristIssueFace({
28792
+ const issueFace = admitted.ticketNumber === void 0 ? void 0 : await loadDiaristIssueFace({
28887
28793
  ticketNumber: admitted.ticketNumber,
28888
28794
  projectRoot: admitted.projectRoot,
28889
28795
  home: env.home
28890
28796
  });
28891
28797
  const catalog = await prepareDiaristSourceCatalog({
28892
- ticketNumber: admitted.ticketNumber,
28798
+ ...admitted.ticketNumber === void 0 ? {} : { ticketNumber: admitted.ticketNumber },
28799
+ instruction: admitted.instruction,
28800
+ runDirectory: admitted.runDirectory,
28801
+ projectRoot: admitted.projectRoot,
28893
28802
  cwd: admitted.projectRoot,
28894
28803
  home: env.home,
28895
- issueFace,
28804
+ ...issueFace === void 0 ? {} : { issueFace },
28896
28805
  sessionCwds: [admitted.projectRoot, env.cwd]
28897
28806
  });
28898
28807
  await writeFile7(path, serializeDiaristSourceCatalog(catalog), "utf8");
@@ -28917,12 +28826,8 @@ async function runPublicDiarist(argv, env, io, parseDiaristArgv2) {
28917
28826
  throw error;
28918
28827
  }
28919
28828
  const projectRoot = parsed.project ?? env.cwd;
28920
- const reusedTicketNumber = await resolveDiaristSummonsTicketNumber({
28921
- instruction: parsed.instruction,
28922
- projectRoot,
28923
- home: env.home
28924
- });
28925
- if (reusedTicketNumber !== void 0) {
28829
+ const handoffTicket = env.boundTicketNumber;
28830
+ if (typeof handoffTicket === "number" && Number.isSafeInteger(handoffTicket) && handoffTicket >= 1) {
28926
28831
  const summons = {
28927
28832
  instruction: parsed.instruction,
28928
28833
  instructionEmpty: parsed.instruction.trim() === "",
@@ -28932,7 +28837,7 @@ async function runPublicDiarist(argv, env, io, parseDiaristArgv2) {
28932
28837
  home: env.home,
28933
28838
  projectRoot,
28934
28839
  role: "diarist",
28935
- ticketNumber: reusedTicketNumber,
28840
+ ticketNumber: handoffTicket,
28936
28841
  freshSummons: env.freshSummons,
28937
28842
  summons,
28938
28843
  resume: (runId, materials) => runPublicDiaristResume(
@@ -28964,6 +28869,9 @@ async function runPublicDiarist(argv, env, io, parseDiaristArgv2) {
28964
28869
  throw error;
28965
28870
  }
28966
28871
  await markRunAdmitted(admitted, env.principalAuthority);
28872
+ if (typeof handoffTicket === "number" && Number.isSafeInteger(handoffTicket) && handoffTicket >= 1) {
28873
+ await bindAdmittedTicketNumber(admitted, handoffTicket);
28874
+ }
28967
28875
  const turnProjection = {
28968
28876
  packageRoot: env.packageRoot,
28969
28877
  home: env.home,
@@ -28991,7 +28899,6 @@ async function runPublicDiarist(argv, env, io, parseDiaristArgv2) {
28991
28899
  request: turnRequest,
28992
28900
  adapters: diaristAdapters({
28993
28901
  beforeDispatch: async (admittedSeat) => {
28994
- await bindReusedTicketNumber(admittedSeat, reusedTicketNumber);
28995
28902
  const sourcesPath = await freezeDiaristSourceCatalog(admittedSeat, env);
28996
28903
  Object.assign(
28997
28904
  turnRequest,
@@ -29000,6 +28907,21 @@ async function runPublicDiarist(argv, env, io, parseDiaristArgv2) {
29000
28907
  }
29001
28908
  }),
29002
28909
  ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
28910
+ }).then(async (result2) => {
28911
+ if (admitted.ticketNumber === void 0 && result2.admitted !== void 0) {
28912
+ const roleOutcome = result2.terminal?.roleOutcome;
28913
+ if (roleOutcome !== void 0 && roleOutcome.kind === "accepted" && roleOutcome.status !== "escalate") {
28914
+ const facts = roleOutcome.decisiveFacts;
28915
+ const raw = typeof facts.ticketNumber === "number" ? facts.ticketNumber : typeof facts.sitian?.ticketNumber === "number" ? facts.sitian.ticketNumber : void 0;
28916
+ if (typeof raw === "number" && Number.isSafeInteger(raw) && raw >= 1) {
28917
+ admitted.ticketNumber = raw;
28918
+ if (result2.admitted.ticketNumber === void 0) {
28919
+ result2.admitted.ticketNumber = raw;
28920
+ }
28921
+ }
28922
+ }
28923
+ }
28924
+ return result2;
29003
28925
  });
29004
28926
  }
29005
28927
  async function runPublicDiaristResume(request, env, io) {
@@ -29037,9 +28959,9 @@ var init_diarist_run = __esm({
29037
28959
  init_engine_material();
29038
28960
  init_cli_errors();
29039
28961
  init_invocation();
29040
- init_seat_ticket_binding();
29041
28962
  init_post_admission();
29042
28963
  init_run_lifecycle();
28964
+ init_seat_ticket_binding();
29043
28965
  init_settlement();
29044
28966
  init_turn_request();
29045
28967
  DIARIST_SOURCE_CATALOG_FILE = "diarist-sources.json";
@@ -29060,12 +28982,7 @@ function buildCountersignTurnRequest(admitted, options) {
29060
28982
  options
29061
28983
  );
29062
28984
  }
29063
- async function runCountersignCourtDiaristStation(admitted, env, io) {
29064
- if (admitted.ticketNumber === void 0) return;
29065
- if (env.runCourtDiaristStation !== void 0) {
29066
- await env.runCourtDiaristStation(admitted);
29067
- return;
29068
- }
28985
+ async function invokeCourtDiarist(input, env, io) {
29069
28986
  const quietIo = {
29070
28987
  stdout() {
29071
28988
  },
@@ -29075,11 +28992,7 @@ async function runCountersignCourtDiaristStation(admitted, env, io) {
29075
28992
  };
29076
28993
  const { runPublicDiarist: runPublicDiarist2 } = await Promise.resolve().then(() => (init_diarist_run(), diarist_run_exports));
29077
28994
  const result2 = await runPublicDiarist2(
29078
- [
29079
- "--project",
29080
- admitted.projectRoot,
29081
- `\u6574\u7406 #${admitted.ticketNumber} \u7684\u672C\u6848\u4F9D\u636E\u3002`
29082
- ],
28995
+ ["--project", input.projectRoot, input.instruction],
29083
28996
  {
29084
28997
  home: env.home,
29085
28998
  agentDir: env.agentDir,
@@ -29094,17 +29007,60 @@ async function runCountersignCourtDiaristStation(admitted, env, io) {
29094
29007
  ...env.timeoutMs === void 0 ? {} : { timeoutMs: env.timeoutMs },
29095
29008
  ...env.credentials === void 0 ? {} : { credentials: env.credentials },
29096
29009
  ...env.correlationId === void 0 ? {} : { correlationId: env.correlationId },
29097
- ...env.signal === void 0 ? {} : { signal: env.signal }
29010
+ ...env.signal === void 0 ? {} : { signal: env.signal },
29011
+ // Typed handoff only — never derived from summons prose.
29012
+ ...input.boundTicketNumber === void 0 ? {} : { boundTicketNumber: input.boundTicketNumber }
29098
29013
  },
29099
29014
  quietIo,
29100
29015
  parseDiaristArgv
29101
29016
  );
29017
+ const roleOutcome = result2.terminal?.roleOutcome;
29018
+ if (roleOutcome !== void 0 && roleOutcome.kind !== "failure") {
29019
+ if (roleOutcome.status === "escalate") {
29020
+ const reason = typeof roleOutcome.decisiveFacts.reason === "string" ? roleOutcome.decisiveFacts.reason : "diarist escalated without reason";
29021
+ return { identity: { kind: "escalate", reason } };
29022
+ }
29023
+ }
29102
29024
  if (result2.exitCode !== 0) {
29103
- const detail = result2.terminal?.roleOutcome.kind === "failure" ? ` (roleOutcome=failure)` : "";
29025
+ const diagnostic = roleOutcome?.kind === "failure" ? roleOutcome.diagnostic : `exit ${result2.exitCode}`;
29026
+ return {
29027
+ identity: { kind: "unbound" },
29028
+ failedWithoutEscalate: {
29029
+ diagnostic: `court diarist station failed for ${input.failureLabel}: ${diagnostic}`
29030
+ }
29031
+ };
29032
+ }
29033
+ const asserted = result2.admitted?.ticketNumber;
29034
+ if (typeof asserted === "number" && Number.isSafeInteger(asserted) && asserted >= 1) {
29035
+ return { identity: { kind: "ticket", ticketNumber: asserted } };
29036
+ }
29037
+ return { identity: { kind: "unbound" } };
29038
+ }
29039
+ async function runCountersignCourtDiaristStation(admitted, env, io) {
29040
+ if (env.runCourtDiaristStation !== void 0) {
29041
+ await env.runCourtDiaristStation(admitted);
29042
+ return;
29043
+ }
29044
+ if (admitted.ticketNumber === void 0) return;
29045
+ const outcome = await invokeCourtDiarist(
29046
+ {
29047
+ instruction: `\u6574\u7406 #${admitted.ticketNumber} \u7684\u672C\u6848\u4F9D\u636E\u3002`,
29048
+ projectRoot: admitted.projectRoot,
29049
+ failureLabel: `ticket #${admitted.ticketNumber}`,
29050
+ // Refresh holds a typed key — hand it off so freeze loads issue face.
29051
+ boundTicketNumber: admitted.ticketNumber
29052
+ },
29053
+ env,
29054
+ io
29055
+ );
29056
+ if (outcome.identity.kind === "escalate") {
29104
29057
  throw new Error(
29105
- `court diarist station failed for ticket #${admitted.ticketNumber}: exit ${result2.exitCode}${detail}`
29058
+ `court diarist station escalated (cannot identify court target): ${outcome.identity.reason}`
29106
29059
  );
29107
29060
  }
29061
+ if (outcome.failedWithoutEscalate !== void 0) {
29062
+ throw new Error(outcome.failedWithoutEscalate.diagnostic);
29063
+ }
29108
29064
  }
29109
29065
  async function runPublicCountersign(argv, env, io, parseCountersignArgv2) {
29110
29066
  let parsed;
@@ -29117,33 +29073,6 @@ async function runPublicCountersign(argv, env, io, parseCountersignArgv2) {
29117
29073
  }
29118
29074
  throw error;
29119
29075
  }
29120
- const projectRoot = parsed.project ?? env.cwd;
29121
- const reusedTicketNumber = await resolveKnownTicketNumber({
29122
- instruction: parsed.instruction,
29123
- projectRoot,
29124
- home: env.home
29125
- });
29126
- if (reusedTicketNumber !== void 0) {
29127
- const summons = {
29128
- instruction: parsed.instruction,
29129
- instructionEmpty: parsed.instruction.trim() === "",
29130
- attachmentPaths: parsed.attachmentPaths
29131
- };
29132
- const resumed = await tryResumeSameTicketSeatRun({
29133
- home: env.home,
29134
- projectRoot,
29135
- role: "countersign",
29136
- ticketNumber: reusedTicketNumber,
29137
- freshSummons: env.freshSummons,
29138
- summons,
29139
- resume: (runId, materials) => runPublicCountersignResume(
29140
- { runId, ...materials === void 0 ? {} : { summons: materials } },
29141
- env,
29142
- io
29143
- )
29144
- });
29145
- if (resumed !== void 0) return resumed;
29146
- }
29147
29076
  let admitted;
29148
29077
  try {
29149
29078
  admitted = await admitCountersignInvocation({
@@ -29165,6 +29094,80 @@ async function runPublicCountersign(argv, env, io, parseCountersignArgv2) {
29165
29094
  throw error;
29166
29095
  }
29167
29096
  await markRunAdmitted(admitted, env.principalAuthority);
29097
+ let typedTicket;
29098
+ let identityDiaristRan = false;
29099
+ if (env.runCourtDiaristStation === void 0) {
29100
+ const outcome = await invokeCourtDiarist(
29101
+ {
29102
+ instruction: parsed.instruction,
29103
+ projectRoot: admitted.projectRoot,
29104
+ failureLabel: "unbound summons"
29105
+ },
29106
+ env,
29107
+ io
29108
+ );
29109
+ identityDiaristRan = true;
29110
+ if (outcome.identity.kind === "escalate") {
29111
+ return await presentControlledFailure2(
29112
+ admitted,
29113
+ {
29114
+ timedOut: false,
29115
+ code: null,
29116
+ stderr: "",
29117
+ thrown: new Error(
29118
+ `court diarist station escalated (cannot identify court target): ${outcome.identity.reason}`
29119
+ )
29120
+ },
29121
+ countersignAdapters(),
29122
+ env.principalAuthority,
29123
+ io
29124
+ );
29125
+ }
29126
+ if (outcome.failedWithoutEscalate !== void 0) {
29127
+ return await presentControlledFailure2(
29128
+ admitted,
29129
+ {
29130
+ timedOut: false,
29131
+ code: null,
29132
+ stderr: "",
29133
+ thrown: new Error(outcome.failedWithoutEscalate.diagnostic)
29134
+ },
29135
+ countersignAdapters(),
29136
+ env.principalAuthority,
29137
+ io
29138
+ );
29139
+ }
29140
+ if (outcome.identity.kind === "ticket") {
29141
+ typedTicket = outcome.identity.ticketNumber;
29142
+ const summons = {
29143
+ instruction: parsed.instruction,
29144
+ instructionEmpty: parsed.instruction.trim() === "",
29145
+ attachmentPaths: parsed.attachmentPaths
29146
+ };
29147
+ const resumed = await tryResumeSameTicketSeatRun({
29148
+ home: env.home,
29149
+ projectRoot: admitted.projectRoot,
29150
+ role: "countersign",
29151
+ ticketNumber: typedTicket,
29152
+ freshSummons: env.freshSummons,
29153
+ summons,
29154
+ resume: async (runId, materials) => {
29155
+ await markRunTerminal(admitted.runDirectory);
29156
+ return await runPublicCountersignResume(
29157
+ {
29158
+ runId,
29159
+ ...materials === void 0 ? {} : { summons: materials }
29160
+ },
29161
+ env,
29162
+ io
29163
+ );
29164
+ }
29165
+ });
29166
+ if (resumed !== void 0) {
29167
+ return resumed;
29168
+ }
29169
+ }
29170
+ }
29168
29171
  const turnProjection = {
29169
29172
  packageRoot: env.packageRoot,
29170
29173
  home: env.home,
@@ -29192,12 +29195,16 @@ async function runPublicCountersign(argv, env, io, parseCountersignArgv2) {
29192
29195
  request: turnRequest,
29193
29196
  adapters: countersignAdapters({
29194
29197
  beforeDispatch: async (admittedSeat) => {
29195
- await bindReusedTicketNumber(admittedSeat, reusedTicketNumber);
29198
+ if (!identityDiaristRan) {
29199
+ await runCountersignCourtDiaristStation(admittedSeat, env, io);
29200
+ } else if (typedTicket !== void 0) {
29201
+ await bindAdmittedTicketNumber(admittedSeat, typedTicket);
29202
+ await runCountersignCourtDiaristStation(admittedSeat, env, io);
29203
+ }
29196
29204
  Object.assign(
29197
29205
  turnRequest,
29198
29206
  buildCountersignTurnRequest(admittedSeat, turnProjection)
29199
29207
  );
29200
- await runCountersignCourtDiaristStation(admittedSeat, env, io);
29201
29208
  }
29202
29209
  }),
29203
29210
  ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
@@ -29250,9 +29257,9 @@ var init_countersign_run = __esm({
29250
29257
  init_engine_material();
29251
29258
  init_cli_errors();
29252
29259
  init_invocation();
29253
- init_seat_ticket_binding();
29254
29260
  init_post_admission();
29255
29261
  init_run_lifecycle();
29262
+ init_seat_ticket_binding();
29256
29263
  init_settlement();
29257
29264
  init_turn_request();
29258
29265
  }
@@ -29570,12 +29577,7 @@ async function runPublicFixer(argv, env, io, parseFixerArgv2) {
29570
29577
  })
29571
29578
  }
29572
29579
  }),
29573
- adapters: {
29574
- ...fixerAdapters(env.packageRoot, methodMaterial),
29575
- beforeDispatch: async (admittedSeat) => {
29576
- await resolveSeatTicketBinding(admittedSeat, env);
29577
- }
29578
- },
29580
+ adapters: fixerAdapters(env.packageRoot, methodMaterial),
29579
29581
  ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
29580
29582
  });
29581
29583
  }
@@ -29628,7 +29630,6 @@ var init_fixer_run = __esm({
29628
29630
  init_method_skill();
29629
29631
  init_cli_errors();
29630
29632
  init_invocation();
29631
- init_seat_ticket_binding();
29632
29633
  init_run_lifecycle();
29633
29634
  init_settlement();
29634
29635
  init_turn_request();
@@ -29637,7 +29638,7 @@ var init_fixer_run = __esm({
29637
29638
  });
29638
29639
 
29639
29640
  // src/public-cli/notary-run.ts
29640
- import { existsSync as existsSync11 } from "node:fs";
29641
+ import { existsSync as existsSync10 } from "node:fs";
29641
29642
  function buildNotaryTurnRequest(admitted, options) {
29642
29643
  return projectRoleTurnRequest(
29643
29644
  admitted,
@@ -29786,7 +29787,7 @@ async function runPublicNotaryResume(request, env, io) {
29786
29787
  env
29787
29788
  );
29788
29789
  const candidatePath = gateSubmissionCandidatePath(admitted.sourceRunPath);
29789
- const prompt = existsSync11(candidatePath) ? appendResumeMaterialReread(projection.continuation.prompt, candidatePath) : projection.continuation.prompt;
29790
+ const prompt = existsSync10(candidatePath) ? appendResumeMaterialReread(projection.continuation.prompt, candidatePath) : projection.continuation.prompt;
29790
29791
  return buildNotaryTurnRequest(admitted, {
29791
29792
  ...projection,
29792
29793
  continuation: { kind: "resume", prompt }
@@ -29836,11 +29837,6 @@ async function runPublicInspector(argv, env, io, parseInspectorArgv2) {
29836
29837
  throw error;
29837
29838
  }
29838
29839
  const projectRoot = parsed.project ?? env.cwd;
29839
- const reusedTicketNumber = await resolveKnownTicketNumber({
29840
- instruction: parsed.instruction,
29841
- projectRoot,
29842
- home: env.home
29843
- });
29844
29840
  const parentRunPath = parentRunPathFromGatePointerInstruction(parsed.instruction);
29845
29841
  if (parentRunPath !== void 0) {
29846
29842
  const summons = {
@@ -29906,11 +29902,7 @@ async function runPublicInspector(argv, env, io, parseInspectorArgv2) {
29906
29902
  env,
29907
29903
  io,
29908
29904
  request: turnRequest,
29909
- adapters: inspectorAdapters({
29910
- beforeDispatch: async (admittedSeat) => {
29911
- await bindReusedTicketNumber(admittedSeat, reusedTicketNumber);
29912
- }
29913
- }),
29905
+ adapters: inspectorAdapters(),
29914
29906
  ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
29915
29907
  });
29916
29908
  }
@@ -30042,12 +30034,7 @@ async function runPublicJudge(argv, env, io, parseJudgeArgv2) {
30042
30034
  })
30043
30035
  }
30044
30036
  }),
30045
- adapters: {
30046
- ...judgeAdapters(),
30047
- beforeDispatch: async (admittedSeat) => {
30048
- await resolveSeatTicketBinding(admittedSeat, env);
30049
- }
30050
- },
30037
+ adapters: judgeAdapters(),
30051
30038
  ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
30052
30039
  });
30053
30040
  }
@@ -30071,7 +30058,6 @@ var init_judge_run = __esm({
30071
30058
  init_engine_material();
30072
30059
  init_cli_errors();
30073
30060
  init_invocation();
30074
- init_seat_ticket_binding();
30075
30061
  init_run_lifecycle();
30076
30062
  init_settlement();
30077
30063
  init_turn_request();
@@ -33761,7 +33747,7 @@ var init_cli = __esm({
33761
33747
  });
33762
33748
 
33763
33749
  // src/public-cli/main.ts
33764
- import { existsSync as existsSync12 } from "node:fs";
33750
+ import { existsSync as existsSync11 } from "node:fs";
33765
33751
  import { dirname as dirname16, join as join33 } from "node:path";
33766
33752
  import { fileURLToPath as fileURLToPath2 } from "node:url";
33767
33753
 
@@ -33852,7 +33838,7 @@ function linkPackage(packageRoot2, name, targetDir) {
33852
33838
  var here = dirname16(fileURLToPath2(import.meta.url));
33853
33839
  function resolvePackageRoot(binDir) {
33854
33840
  const canonical = join33(binDir, "..", "..");
33855
- if (existsSync12(join33(canonical, "package.json"))) {
33841
+ if (existsSync11(join33(canonical, "package.json"))) {
33856
33842
  return canonical;
33857
33843
  }
33858
33844
  return binDir;