@akagilnc/pi-workflow-roles 0.1.3671 → 0.1.3682

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.
@@ -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
  };
@@ -16762,7 +16762,7 @@ function validateAcceptedDetails(toolName, details) {
16762
16762
  [GATEKEEPER_OUTPUT_TOOL_NAME]: ["dispatch", "pass"],
16763
16763
  [NAVIGATOR_OUTPUT_TOOL_NAME]: ["advice"],
16764
16764
  [AUDITOR_OUTPUT_TOOL_NAME]: ["pass", "bounce", "escalate"],
16765
- [DIARIST_OUTPUT_TOOL_NAME]: ["completed"]
16765
+ [DIARIST_OUTPUT_TOOL_NAME]: ["completed", "escalate"]
16766
16766
  };
16767
16767
  const collectorDiscriminator = toolName === COLLECTOR_OUTPUT_TOOL && Array.isArray(candidate?.groups);
16768
16768
  const baseDiscriminator = discriminator;
@@ -17816,27 +17816,6 @@ async function findLatestRunIdForSeatTicket(input) {
17816
17816
  }
17817
17817
  return best;
17818
17818
  }
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
17819
  function parsePersistedTicketIdentity(record4) {
17841
17820
  const correlationId = typeof record4.correlationId === "string" && record4.correlationId.trim() !== "" ? record4.correlationId : void 0;
17842
17821
  const ticketNumber = typeof record4.ticketNumber === "number" && Number.isSafeInteger(record4.ticketNumber) && record4.ticketNumber >= 1 ? record4.ticketNumber : void 0;
@@ -21911,522 +21890,104 @@ var init_method_skill = __esm({
21911
21890
  }
21912
21891
  });
21913
21892
 
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
- };
21893
+ // src/auditor-dossier-tool.ts
21894
+ import { dirname as dirname8, join as join15, resolve as resolve8 } from "node:path";
21895
+ function gateSubmissionCandidatePath(runDirectory) {
21896
+ return join15(runDirectory, "artifacts", GATE_SUBMISSION_CANDIDATE_FILE);
21981
21897
  }
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"() {
21898
+ var GATE_SUBMISSION_CANDIDATE_FILE;
21899
+ var init_auditor_dossier_tool = __esm({
21900
+ "src/auditor-dossier-tool.ts"() {
21985
21901
  "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
- ]);
21902
+ init_build();
21903
+ GATE_SUBMISSION_CANDIDATE_FILE = "gate-submission-candidate.json";
22002
21904
  }
22003
21905
  });
22004
21906
 
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)}`);
21907
+ // src/compliance-transport.ts
21908
+ var nonblank2, decisionGateSchema, complianceDecisionSchema, AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE, AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE;
21909
+ var init_compliance_transport = __esm({
21910
+ "src/compliance-transport.ts"() {
21911
+ "use strict";
21912
+ init_build();
21913
+ init_auditor_dossier_tool();
21914
+ nonblank2 = typebox_exports.String({ minLength: 1, pattern: "\\S" });
21915
+ decisionGateSchema = typebox_exports.Object({ question: nonblank2, options: typebox_exports.Array(nonblank2, { minItems: 1 }) }, { additionalProperties: false });
21916
+ 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: [] });
21917
+ AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE = "ak_auditor_parent_attempt_binding";
21918
+ AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE = "ak_auditor_compliance_failure";
22012
21919
  }
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
- };
21920
+ });
21921
+
21922
+ // src/ledger-session-read.ts
21923
+ import { readFile as readFile11 } from "node:fs/promises";
21924
+ function isRecord10(value) {
21925
+ return typeof value === "object" && value !== null && !Array.isArray(value);
22045
21926
  }
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();
21927
+ async function readLedgerSessionJsonl(path) {
21928
+ const text = await readFile11(path, "utf8");
22060
21929
  const lines = text.split("\n");
21930
+ const rows = [];
22061
21931
  for (let index = 0; index < lines.length; index += 1) {
22062
- const trimmed = lines[index].trim();
22063
- if (!trimmed) continue;
22064
- let parsed;
21932
+ const line2 = lines[index];
21933
+ if (!line2.trim()) continue;
21934
+ let row;
22065
21935
  try {
22066
- parsed = JSON.parse(trimmed);
21936
+ row = JSON.parse(line2);
22067
21937
  } 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
- );
21938
+ if (!(error instanceof SyntaxError)) throw error;
21939
+ const completedByTerminator = index < lines.length - 1;
21940
+ if (completedByTerminator) {
21941
+ throw new LedgerSessionJsonlError(
21942
+ `malformed JSONL record in ${path} at line ${index + 1}: ${error.message}`,
21943
+ { path, line: index + 1, prefixRows: rows }
21944
+ );
21945
+ }
21946
+ break;
22073
21947
  }
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})`
21948
+ if (!isRecord10(row)) {
21949
+ const kind = row === null ? "null" : Array.isArray(row) ? "array" : typeof row;
21950
+ throw new LedgerSessionJsonlError(
21951
+ `complete non-object JSONL record in ${path} at line ${index + 1}: expected object, got ${kind}`,
21952
+ { path, line: index + 1, prefixRows: rows }
22078
21953
  );
22079
21954
  }
22080
- seen.add(parsed.identity);
21955
+ rows.push(row);
22081
21956
  }
22082
- return seen;
21957
+ return rows;
22083
21958
  }
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;
21959
+ function extractSessionTimestampSpan(rows) {
21960
+ let startedAt;
21961
+ let endedAt;
21962
+ for (const row of rows) {
21963
+ if (typeof row.timestamp !== "string" || !row.timestamp) continue;
21964
+ if (startedAt === void 0) startedAt = row.timestamp;
21965
+ endedAt = row.timestamp;
21966
+ }
21967
+ return {
21968
+ ...startedAt !== void 0 ? { startedAt } : {},
21969
+ ...endedAt !== void 0 ? { endedAt } : {}
21970
+ };
21971
+ }
21972
+ function extractSessionModelSequence(rows) {
21973
+ const seen = /* @__PURE__ */ new Set();
21974
+ const ordered = [];
21975
+ const push = (raw) => {
21976
+ const model = raw.trim();
21977
+ if (model === "" || seen.has(model)) return;
21978
+ seen.add(model);
21979
+ ordered.push(model);
21980
+ };
21981
+ for (const row of rows) {
21982
+ if (row.type === "model_change" && typeof row.modelId === "string") {
21983
+ push(row.modelId);
22099
21984
  }
22100
- const entry = projectTicketProvenanceEntry(record4.payload);
22101
- if (entry === void 0) {
22102
- skipped += 1;
22103
- continue;
21985
+ const message = isRecord10(row.message) ? row.message : void 0;
21986
+ if (message?.role === "assistant" && typeof message.model === "string") {
21987
+ push(message.model);
22104
21988
  }
22105
- entries.push(entry);
22106
21989
  }
22107
- return { entries, diagnostics, records: records2, recordFile, skipped };
22108
- }
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
- }
22116
- }
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 = /* @__PURE__ */ new Set();
22245
- for (const run of instruction.match(/\d+/g) ?? []) {
22246
- if (run.startsWith("0")) continue;
22247
- const parsed = Number(run);
22248
- if (!Number.isSafeInteger(parsed) || parsed < 1) continue;
22249
- tokens.add(parsed);
22250
- }
22251
- return [...tokens];
22252
- }
22253
- async function resolveKnownTicketNumber(input) {
22254
- const tokens = instructionTicketTokens(input.instruction);
22255
- if (tokens.length === 0) return void 0;
22256
- const known = [];
22257
- let runTickets;
22258
- for (const token of tokens) {
22259
- const volume = resolveTicketProvenanceVolume(
22260
- token,
22261
- input.projectRoot,
22262
- input.home
22263
- );
22264
- if (existsSync7(volume.volumeDir)) {
22265
- known.push(token);
22266
- continue;
22267
- }
22268
- if (runTickets === void 0) {
22269
- runTickets = await readBookRunTickets(input);
22270
- }
22271
- if (runTickets.has(token)) known.push(token);
22272
- }
22273
- return known.length === 1 ? known[0] : void 0;
22274
- }
22275
- async function resolveDiaristSummonsTicketNumber(input) {
22276
- const known = await resolveKnownTicketNumber(input);
22277
- if (known !== void 0) return known;
22278
- const tokens = instructionTicketTokens(input.instruction);
22279
- return tokens.length === 1 ? tokens[0] : void 0;
22280
- }
22281
- async function readBookRunTickets(input) {
22282
- let bookKey;
22283
- try {
22284
- bookKey = input.bookKey ?? resolveBookKeyFromGit(input.projectRoot);
22285
- } catch (error) {
22286
- if (error instanceof ActivationGitRepositoryRequiredError) return /* @__PURE__ */ new Set();
22287
- throw error;
22288
- }
22289
- return await collectBookRunTicketNumbers({ home: input.home, bookKey });
22290
- }
22291
- async function bindReusedTicketNumber(admitted, ticketNumber) {
22292
- if (ticketNumber === void 0) return;
22293
- if (admitted.ticketNumber !== void 0) return;
22294
- await bindAdmittedTicketNumber(admitted, ticketNumber);
22295
- }
22296
- async function resolveSeatTicketBinding(admitted, env) {
22297
- if (admitted.ticketNumber !== void 0) return admitted.ticketNumber;
22298
- const ticketNumber = await resolveKnownTicketNumber({
22299
- instruction: admitted.instruction,
22300
- projectRoot: admitted.projectRoot,
22301
- home: env.home,
22302
- bookKey: admitted.bookKey
22303
- });
22304
- await bindReusedTicketNumber(admitted, ticketNumber);
22305
- return ticketNumber;
22306
- }
22307
- async function tryResumeSameTicketSeatRun(input) {
22308
- if (input.freshSummons === true) return void 0;
22309
- if (input.parentRunPath === void 0 && input.ticketNumber === void 0) {
22310
- return void 0;
22311
- }
22312
- const previousRunId = await findLatestRunIdForSeatTicket({
22313
- home: input.home,
22314
- bookKey: resolveBookKeyFromGit(input.projectRoot),
22315
- role: input.role,
22316
- ...input.parentRunPath === void 0 ? {} : { parentRunPath: input.parentRunPath },
22317
- ...input.ticketNumber === void 0 ? {} : { ticketNumber: input.ticketNumber }
22318
- });
22319
- if (previousRunId === void 0) return void 0;
22320
- return await input.resume(previousRunId, input.summons);
22321
- }
22322
- var init_seat_ticket_binding = __esm({
22323
- "src/public-cli/seat-ticket-binding.ts"() {
22324
- "use strict";
22325
- init_activation_ledger_git();
22326
- init_ticket_provenance();
22327
- init_invocation();
22328
- init_run_lifecycle();
22329
- }
22330
- });
22331
-
22332
- // src/auditor-dossier-tool.ts
22333
- import { dirname as dirname8, join as join16, resolve as resolve8 } from "node:path";
22334
- function gateSubmissionCandidatePath(runDirectory) {
22335
- return join16(runDirectory, "artifacts", GATE_SUBMISSION_CANDIDATE_FILE);
22336
- }
22337
- var GATE_SUBMISSION_CANDIDATE_FILE;
22338
- var init_auditor_dossier_tool = __esm({
22339
- "src/auditor-dossier-tool.ts"() {
22340
- "use strict";
22341
- init_build();
22342
- GATE_SUBMISSION_CANDIDATE_FILE = "gate-submission-candidate.json";
22343
- }
22344
- });
22345
-
22346
- // src/compliance-transport.ts
22347
- var nonblank2, decisionGateSchema, complianceDecisionSchema, AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE, AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE;
22348
- var init_compliance_transport = __esm({
22349
- "src/compliance-transport.ts"() {
22350
- "use strict";
22351
- init_build();
22352
- init_auditor_dossier_tool();
22353
- nonblank2 = typebox_exports.String({ minLength: 1, pattern: "\\S" });
22354
- decisionGateSchema = typebox_exports.Object({ question: nonblank2, options: typebox_exports.Array(nonblank2, { minItems: 1 }) }, { additionalProperties: false });
22355
- 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: [] });
22356
- AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE = "ak_auditor_parent_attempt_binding";
22357
- AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE = "ak_auditor_compliance_failure";
22358
- }
22359
- });
22360
-
22361
- // src/ledger-session-read.ts
22362
- import { readFile as readFile11 } from "node:fs/promises";
22363
- function isRecord11(value) {
22364
- return typeof value === "object" && value !== null && !Array.isArray(value);
22365
- }
22366
- async function readLedgerSessionJsonl(path) {
22367
- const text = await readFile11(path, "utf8");
22368
- const lines = text.split("\n");
22369
- const rows = [];
22370
- for (let index = 0; index < lines.length; index += 1) {
22371
- const line2 = lines[index];
22372
- if (!line2.trim()) continue;
22373
- let row;
22374
- try {
22375
- row = JSON.parse(line2);
22376
- } catch (error) {
22377
- if (!(error instanceof SyntaxError)) throw error;
22378
- const completedByTerminator = index < lines.length - 1;
22379
- if (completedByTerminator) {
22380
- throw new LedgerSessionJsonlError(
22381
- `malformed JSONL record in ${path} at line ${index + 1}: ${error.message}`,
22382
- { path, line: index + 1, prefixRows: rows }
22383
- );
22384
- }
22385
- break;
22386
- }
22387
- if (!isRecord11(row)) {
22388
- const kind = row === null ? "null" : Array.isArray(row) ? "array" : typeof row;
22389
- throw new LedgerSessionJsonlError(
22390
- `complete non-object JSONL record in ${path} at line ${index + 1}: expected object, got ${kind}`,
22391
- { path, line: index + 1, prefixRows: rows }
22392
- );
22393
- }
22394
- rows.push(row);
22395
- }
22396
- return rows;
22397
- }
22398
- function extractSessionTimestampSpan(rows) {
22399
- let startedAt;
22400
- let endedAt;
22401
- for (const row of rows) {
22402
- if (typeof row.timestamp !== "string" || !row.timestamp) continue;
22403
- if (startedAt === void 0) startedAt = row.timestamp;
22404
- endedAt = row.timestamp;
22405
- }
22406
- return {
22407
- ...startedAt !== void 0 ? { startedAt } : {},
22408
- ...endedAt !== void 0 ? { endedAt } : {}
22409
- };
22410
- }
22411
- function extractSessionModelSequence(rows) {
22412
- const seen = /* @__PURE__ */ new Set();
22413
- const ordered = [];
22414
- const push = (raw) => {
22415
- const model = raw.trim();
22416
- if (model === "" || seen.has(model)) return;
22417
- seen.add(model);
22418
- ordered.push(model);
22419
- };
22420
- for (const row of rows) {
22421
- if (row.type === "model_change" && typeof row.modelId === "string") {
22422
- push(row.modelId);
22423
- }
22424
- const message = isRecord11(row.message) ? row.message : void 0;
22425
- if (message?.role === "assistant" && typeof message.model === "string") {
22426
- push(message.model);
22427
- }
22428
- }
22429
- return ordered;
21990
+ return ordered;
22430
21991
  }
22431
21992
  function bashCommandFirstLine(command) {
22432
21993
  const match = /^[^\r\n]*/.exec(command);
@@ -22437,11 +21998,11 @@ function extractSessionToolIntervals(rows) {
22437
21998
  const openById = /* @__PURE__ */ new Map();
22438
21999
  for (const row of rows) {
22439
22000
  const rowTimestamp = typeof row.timestamp === "string" ? row.timestamp : void 0;
22440
- const message = isRecord11(row.message) ? row.message : void 0;
22001
+ const message = isRecord10(row.message) ? row.message : void 0;
22441
22002
  if (message?.role === "assistant" && Array.isArray(message.content)) {
22442
22003
  const callTimestamp = typeof message.timestamp === "string" && message.timestamp ? message.timestamp : rowTimestamp;
22443
22004
  for (const part of message.content) {
22444
- if (!isRecord11(part) || part.type !== "toolCall") continue;
22005
+ if (!isRecord10(part) || part.type !== "toolCall") continue;
22445
22006
  if (typeof part.id !== "string" || part.id.length === 0) {
22446
22007
  throw new Error("toolCall frame missing string id");
22447
22008
  }
@@ -22454,7 +22015,7 @@ function extractSessionToolIntervals(rows) {
22454
22015
  if (openById.has(part.id)) {
22455
22016
  throw new Error(`duplicate toolCall id ${part.id}`);
22456
22017
  }
22457
- const args = isRecord11(part.arguments) ? part.arguments : void 0;
22018
+ const args = isRecord10(part.arguments) ? part.arguments : void 0;
22458
22019
  const command = part.name === "bash" && args !== void 0 && typeof args.command === "string" ? bashCommandFirstLine(args.command) : void 0;
22459
22020
  const interval = {
22460
22021
  toolCallId: part.id,
@@ -22539,8 +22100,8 @@ var init_ledger_session_read = __esm({
22539
22100
 
22540
22101
  // src/analyst-gate-cycles-read.ts
22541
22102
  import { readdir as readdir3 } from "node:fs/promises";
22542
- import { join as join17 } from "node:path";
22543
- function isRecord12(value) {
22103
+ import { join as join16 } from "node:path";
22104
+ function isRecord11(value) {
22544
22105
  return typeof value === "object" && value !== null && !Array.isArray(value);
22545
22106
  }
22546
22107
  function isParentAttemptBindingRow(row) {
@@ -22571,7 +22132,7 @@ function isGateTerminatingToolName(toolName) {
22571
22132
  function acceptedGateReceiptIds(rows) {
22572
22133
  const accepted = /* @__PURE__ */ new Set();
22573
22134
  for (const row of rows) {
22574
- const message = isRecord12(row.message) ? row.message : void 0;
22135
+ const message = isRecord11(row.message) ? row.message : void 0;
22575
22136
  if (message?.role !== "toolResult") continue;
22576
22137
  if (typeof message.toolCallId !== "string" || message.toolCallId.length === 0) continue;
22577
22138
  if (message.isError === false) accepted.add(message.toolCallId);
@@ -22610,7 +22171,7 @@ function nearestAttemptBindingBefore(rows, beforeIndex) {
22610
22171
  for (let i = beforeIndex - 1; i >= 0; i -= 1) {
22611
22172
  const row = rows[i];
22612
22173
  if (!isParentAttemptBindingRow(row)) continue;
22613
- if (!isRecord12(row.data) || !isRecord12(row.data.parent)) continue;
22174
+ if (!isRecord11(row.data) || !isRecord11(row.data.parent)) continue;
22614
22175
  const id = row.data.parent.attemptEntryId;
22615
22176
  const sessionFile = row.data.parent.sessionFile;
22616
22177
  return {
@@ -22625,10 +22186,10 @@ function extractAllAcceptedGateToolCalls(rows) {
22625
22186
  const out = [];
22626
22187
  for (let rowIndex = 0; rowIndex < rows.length; rowIndex += 1) {
22627
22188
  const row = rows[rowIndex];
22628
- const message = isRecord12(row.message) ? row.message : void 0;
22189
+ const message = isRecord11(row.message) ? row.message : void 0;
22629
22190
  if (message?.role !== "assistant" || !Array.isArray(message.content)) continue;
22630
22191
  for (const part of message.content) {
22631
- if (!isRecord12(part) || part.type !== "toolCall") continue;
22192
+ if (!isRecord11(part) || part.type !== "toolCall") continue;
22632
22193
  if (typeof part.id !== "string" || part.id.length === 0) continue;
22633
22194
  if (typeof part.name !== "string" || part.name.length === 0) continue;
22634
22195
  if (!isGateTerminatingToolName(part.name)) continue;
@@ -22636,7 +22197,7 @@ function extractAllAcceptedGateToolCalls(rows) {
22636
22197
  const binding = nearestAttemptBindingBefore(rows, rowIndex);
22637
22198
  out.push({
22638
22199
  toolName: part.name,
22639
- args: isRecord12(part.arguments) ? part.arguments : void 0,
22200
+ args: isRecord11(part.arguments) ? part.arguments : void 0,
22640
22201
  accepted: true,
22641
22202
  rowIndex,
22642
22203
  ...binding
@@ -22776,7 +22337,7 @@ async function resolveOfficerSessionFromPointerFile(pointerPath) {
22776
22337
  { cause: error }
22777
22338
  );
22778
22339
  }
22779
- if (!isRecord12(raw) || raw.kind !== "direct-officer-run-pointer" || raw.version !== 1) {
22340
+ if (!isRecord11(raw) || raw.kind !== "direct-officer-run-pointer" || raw.version !== 1) {
22780
22341
  throw new Error(`direct officer run pointer has unknown shape in ${pointerPath}`);
22781
22342
  }
22782
22343
  const sessionFile = raw.sessionFile;
@@ -22800,7 +22361,7 @@ async function readAnalystGateCyclesFromAuditorRoles(auditorRolesDirectory, opti
22800
22361
  throw error;
22801
22362
  }
22802
22363
  for (const name of names) {
22803
- const path = join17(directory, name);
22364
+ const path = join16(directory, name);
22804
22365
  const sessionPath = name.endsWith(".pointer.json") ? await resolveOfficerSessionFromPointerFile(path) : path;
22805
22366
  if (sessionPath === void 0) continue;
22806
22367
  const classified = await classifyAuditorVolume(sessionPath);
@@ -22860,21 +22421,21 @@ var init_gatekeeper_role = __esm({
22860
22421
 
22861
22422
  // src/run-terminal-artifacts.ts
22862
22423
  import { readdir as readdir4, readFile as readFile12 } from "node:fs/promises";
22863
- import { basename as basename6, dirname as dirname9, join as join18 } from "node:path";
22424
+ import { basename as basename6, dirname as dirname9, join as join17 } from "node:path";
22864
22425
  function isMissingPathError2(error) {
22865
22426
  return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
22866
22427
  }
22867
22428
  function errorText2(error) {
22868
22429
  return error instanceof Error ? error.message : String(error);
22869
22430
  }
22870
- function isRecord13(value) {
22431
+ function isRecord12(value) {
22871
22432
  return typeof value === "object" && value !== null && !Array.isArray(value);
22872
22433
  }
22873
22434
  function readUsableTerminalArtifactBody(body) {
22874
22435
  if (body === null) {
22875
22436
  return { ok: false, reason: "terminal artifact JSON value is null" };
22876
22437
  }
22877
- if (!isRecord13(body)) {
22438
+ if (!isRecord12(body)) {
22878
22439
  return {
22879
22440
  ok: false,
22880
22441
  reason: `terminal artifact JSON value is not a typed object (${Array.isArray(body) ? "array" : typeof body})`
@@ -22935,7 +22496,7 @@ async function listUniqueErrorFallbackPaths(directories) {
22935
22496
  }
22936
22497
  for (const name of names.sort((a, b) => a.localeCompare(b))) {
22937
22498
  if (!UNIQUE_ERROR_FALLBACK_NAME.test(name)) continue;
22938
- found.push(join18(dir, name));
22499
+ found.push(join17(dir, name));
22939
22500
  }
22940
22501
  }
22941
22502
  return found;
@@ -22951,14 +22512,14 @@ function presentUniqueFallbackBoundToRun(body, expectedRunId) {
22951
22512
  return typeof body.runId === "string" && body.runId === expectedRunId;
22952
22513
  }
22953
22514
  async function readRunTerminalArtifact(runDirectory) {
22954
- const artifactsDir = join18(runDirectory, "artifacts");
22515
+ const artifactsDir = join17(runDirectory, "artifacts");
22955
22516
  for (const file of RUN_TERMINAL_ARTIFACT_FILES) {
22956
- const path = join18(artifactsDir, file);
22517
+ const path = join17(artifactsDir, file);
22957
22518
  const read3 = await readTerminalArtifactAtPath(path, file);
22958
22519
  if (read3 !== void 0) return read3;
22959
22520
  }
22960
22521
  for (const relative3 of RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS) {
22961
- const path = join18(runDirectory, relative3);
22522
+ const path = join17(runDirectory, relative3);
22962
22523
  const read3 = await readTerminalArtifactAtPath(path, "error.json");
22963
22524
  if (read3 !== void 0) return read3;
22964
22525
  }
@@ -23097,14 +22658,14 @@ var init_submission_ledger = __esm({
23097
22658
  });
23098
22659
 
23099
22660
  // src/session-opening-materials.ts
23100
- import { existsSync as existsSync8 } from "node:fs";
22661
+ import { existsSync as existsSync6 } from "node:fs";
23101
22662
  import { readFile as readFile13 } from "node:fs/promises";
23102
- import { dirname as dirname10, join as join19 } from "node:path";
22663
+ import { dirname as dirname10, join as join18 } from "node:path";
23103
22664
  import { fileURLToPath, pathToFileURL as pathToFileURL2 } from "node:url";
23104
22665
  function resolvePackageRootDir(moduleUrl = import.meta.url) {
23105
22666
  let dir = dirname10(fileURLToPath(moduleUrl));
23106
22667
  for (let i = 0; i < 8; i += 1) {
23107
- if (existsSync8(join19(dir, "package.json")) && existsSync8(join19(dir, "souls"))) {
22668
+ if (existsSync6(join18(dir, "package.json")) && existsSync6(join18(dir, "souls"))) {
23108
22669
  return dir;
23109
22670
  }
23110
22671
  const parent = dirname10(dir);
@@ -23430,12 +22991,12 @@ var init_reviewer_dispatch = __esm({
23430
22991
 
23431
22992
  // src/public-cli/reviewer-dispatch-rejection.ts
23432
22993
  import { readFile as readFile14, unlink as unlink3 } from "node:fs/promises";
23433
- import { join as join20 } from "node:path";
22994
+ import { join as join19 } from "node:path";
23434
22995
  function isReviewerPreflightViolation(value) {
23435
22996
  return typeof value === "string" && REVIEWER_PREFLIGHT_VIOLATIONS.includes(value);
23436
22997
  }
23437
22998
  function reviewerDispatchRejectionPath(runDirectory) {
23438
- return join20(runDirectory, REVIEWER_DISPATCH_REJECTION_FILE);
22999
+ return join19(runDirectory, REVIEWER_DISPATCH_REJECTION_FILE);
23439
23000
  }
23440
23001
  async function clearReviewerDispatchRejection(runDirectory) {
23441
23002
  try {
@@ -23496,7 +23057,7 @@ var init_collector_evidence = __esm({
23496
23057
 
23497
23058
  // src/collector-github.ts
23498
23059
  import { spawn as spawn2 } from "node:child_process";
23499
- function isRecord14(value) {
23060
+ function isRecord13(value) {
23500
23061
  return typeof value === "object" && value !== null && !Array.isArray(value);
23501
23062
  }
23502
23063
  function requireString(value, label) {
@@ -23537,25 +23098,25 @@ function commentFailureCause(error) {
23537
23098
  };
23538
23099
  }
23539
23100
  function requireUserLogin(raw) {
23540
- if (!isRecord14(raw) || typeof raw["login"] !== "string") {
23101
+ if (!isRecord13(raw) || typeof raw["login"] !== "string") {
23541
23102
  throw new Error("GitHub payload missing user.login");
23542
23103
  }
23543
23104
  return raw["login"];
23544
23105
  }
23545
23106
  function optionalUserLogin(raw) {
23546
23107
  if (raw === null) return null;
23547
- if (!isRecord14(raw) || typeof raw["login"] !== "string") {
23108
+ if (!isRecord13(raw) || typeof raw["login"] !== "string") {
23548
23109
  throw new Error("GitHub payload missing user.login");
23549
23110
  }
23550
23111
  return raw["login"];
23551
23112
  }
23552
23113
  function machineIdentity(raw) {
23553
23114
  const user = raw["user"];
23554
- if (!isRecord14(user) || typeof user["type"] !== "string" || typeof user["id"] !== "number") {
23115
+ if (!isRecord13(user) || typeof user["type"] !== "string" || typeof user["id"] !== "number") {
23555
23116
  return null;
23556
23117
  }
23557
23118
  const app = raw["performed_via_github_app"];
23558
- const appId = isRecord14(app) && typeof app["id"] === "number" ? app["id"] : void 0;
23119
+ const appId = isRecord13(app) && typeof app["id"] === "number" ? app["id"] : void 0;
23559
23120
  return {
23560
23121
  userType: user["type"],
23561
23122
  userId: user["id"],
@@ -23563,9 +23124,9 @@ function machineIdentity(raw) {
23563
23124
  };
23564
23125
  }
23565
23126
  function normalizePullRequest(raw) {
23566
- if (!isRecord14(raw)) throw new Error("GitHub pull request payload must be an object");
23127
+ if (!isRecord13(raw)) throw new Error("GitHub pull request payload must be an object");
23567
23128
  const head = raw["head"];
23568
- if (!isRecord14(head) || typeof head["sha"] !== "string" || head["sha"].length === 0) {
23129
+ if (!isRecord13(head) || typeof head["sha"] !== "string" || head["sha"].length === 0) {
23569
23130
  throw new Error("GitHub pull request payload missing head.sha");
23570
23131
  }
23571
23132
  const number = requireNumber(raw["number"], "number");
@@ -23581,7 +23142,7 @@ function normalizePullRequest(raw) {
23581
23142
  };
23582
23143
  }
23583
23144
  function normalizePullRequestReaction(raw) {
23584
- if (!isRecord14(raw)) throw new Error("GitHub reaction payload must be an object");
23145
+ if (!isRecord13(raw)) throw new Error("GitHub reaction payload must be an object");
23585
23146
  return {
23586
23147
  id: requireNumber(raw["id"], "reaction.id"),
23587
23148
  userLogin: optionalUserLogin(raw["user"]),
@@ -23592,7 +23153,7 @@ function normalizePullRequestReaction(raw) {
23592
23153
  };
23593
23154
  }
23594
23155
  function normalizeReview(raw) {
23595
- if (!isRecord14(raw)) throw new Error("GitHub review payload must be an object");
23156
+ if (!isRecord13(raw)) throw new Error("GitHub review payload must be an object");
23596
23157
  return {
23597
23158
  id: requireNumber(raw["id"], "review.id"),
23598
23159
  ...typeof raw["node_id"] === "string" ? { nodeId: raw["node_id"] } : {},
@@ -23607,7 +23168,7 @@ function normalizeReview(raw) {
23607
23168
  };
23608
23169
  }
23609
23170
  function normalizeIssueComment(raw) {
23610
- if (!isRecord14(raw)) throw new Error("GitHub issue comment payload must be an object");
23171
+ if (!isRecord13(raw)) throw new Error("GitHub issue comment payload must be an object");
23611
23172
  return {
23612
23173
  id: requireNumber(raw["id"], "comment.id"),
23613
23174
  userLogin: optionalUserLogin(raw["user"]),
@@ -23620,7 +23181,7 @@ function normalizeIssueComment(raw) {
23620
23181
  };
23621
23182
  }
23622
23183
  function normalizeReviewComment(raw) {
23623
- if (!isRecord14(raw)) throw new Error("GitHub review comment payload must be an object");
23184
+ if (!isRecord13(raw)) throw new Error("GitHub review comment payload must be an object");
23624
23185
  return {
23625
23186
  id: requireNumber(raw["id"], "review_comment.id"),
23626
23187
  pullRequestReviewId: typeof raw["pull_request_review_id"] === "number" ? raw["pull_request_review_id"] : null,
@@ -23929,11 +23490,11 @@ function createGhCollectorGitHubTransport(runner = createGhApiRunner()) {
23929
23490
  if (input.signal?.aborted) {
23930
23491
  throw error;
23931
23492
  }
23932
- if (isRecord14(error) && error["ambiguousGhFailure"] === true) {
23493
+ if (isRecord13(error) && error["ambiguousGhFailure"] === true) {
23933
23494
  const cause = commentFailureCause(error);
23934
23495
  return { kind: "ambiguous_loss", diagnostics: cause.message, cause };
23935
23496
  }
23936
- if (isRecord14(error) && error["name"] === "AbortError") {
23497
+ if (isRecord13(error) && error["name"] === "AbortError") {
23937
23498
  throw error;
23938
23499
  }
23939
23500
  throw error;
@@ -24109,11 +23670,11 @@ var init_navigator_invocation_identity = __esm({
24109
23670
  });
24110
23671
 
24111
23672
  // src/receipt-delivery-policy.ts
24112
- function isRecord15(value) {
23673
+ function isRecord14(value) {
24113
23674
  return typeof value === "object" && value !== null && !Array.isArray(value);
24114
23675
  }
24115
23676
  function parseNoReceiptLifecycleFacts(input) {
24116
- 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")) {
23677
+ 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")) {
24117
23678
  throw new TypeError("malformed no-receipt lifecycle facts");
24118
23679
  }
24119
23680
  return {
@@ -24299,7 +23860,7 @@ var init_terminal = __esm({
24299
23860
  // src/public-cli/settlement.ts
24300
23861
  import { randomUUID as randomUUID3 } from "node:crypto";
24301
23862
  import { appendFile as appendFile2, readFile as readFile15, readdir as readdir5, writeFile as writeFile5 } from "node:fs/promises";
24302
- import { dirname as dirname11, join as join21 } from "node:path";
23863
+ import { dirname as dirname11, join as join20 } from "node:path";
24303
23864
  function sealedLedgerHome(admitted) {
24304
23865
  return homeFromRunDirectory(admitted.runDirectory);
24305
23866
  }
@@ -24679,7 +24240,7 @@ async function readSitianRetainedAuditorProviderStop(sessionFile) {
24679
24240
  const { records: records2 } = await readSitianRecords(recordFile);
24680
24241
  for (let i = records2.length - 1; i >= 0; i -= 1) {
24681
24242
  const payload = records2[i]?.payload;
24682
- if (!isRecord16(payload) || !isRecord16(payload.response)) continue;
24243
+ if (!isRecord15(payload) || !isRecord15(payload.response)) continue;
24683
24244
  if (typeof payload.type === "string") continue;
24684
24245
  const stop = sessionProviderStopFromAssistant(payload.response);
24685
24246
  if (stop !== void 0) return stop;
@@ -24700,7 +24261,7 @@ async function readSessionProviderStop(sessionFile) {
24700
24261
  }
24701
24262
  }
24702
24263
  async function readBoundEvidenceChildKnownFailure(sessionFile) {
24703
- const childDirectory = join21(dirname11(sessionFile), "evidence-children");
24264
+ const childDirectory = join20(dirname11(sessionFile), "evidence-children");
24704
24265
  let names;
24705
24266
  try {
24706
24267
  names = await readdir5(childDirectory);
@@ -24711,12 +24272,12 @@ async function readBoundEvidenceChildKnownFailure(sessionFile) {
24711
24272
  for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
24712
24273
  let entries;
24713
24274
  try {
24714
- entries = await readBoundSessionEntries(join21(childDirectory, file));
24275
+ entries = await readBoundSessionEntries(join20(childDirectory, file));
24715
24276
  } catch (error) {
24716
24277
  throw sessionReadFailure(error, "failed to read discovered evidence-child session");
24717
24278
  }
24718
24279
  const header = entries.find((entry) => entry.type === "session");
24719
- if (!isRecord16(header) || header.parentSession !== sessionFile) continue;
24280
+ if (!isRecord15(header) || header.parentSession !== sessionFile) continue;
24720
24281
  const stop = extractSessionProviderStop(entries);
24721
24282
  if (stop === void 0) continue;
24722
24283
  const primary = knownFailureFromProviderStop(stop);
@@ -24748,12 +24309,12 @@ async function loadBoundAuditorVolumes(sessionFile) {
24748
24309
  return firstLine === RESUME_ENVELOPE;
24749
24310
  };
24750
24311
  const isResumeEnvelope = (msg) => {
24751
- if (!isRecord16(msg) || msg.role !== "user") return false;
24312
+ if (!isRecord15(msg) || msg.role !== "user") return false;
24752
24313
  const text = typeof msg.text === "string" ? msg.text : typeof msg.content === "string" ? msg.content : void 0;
24753
24314
  if (isResumeEnvelopeBytes(text)) return true;
24754
24315
  const content = msg.content;
24755
24316
  if (Array.isArray(content)) {
24756
- return content.some((p) => isRecord16(p) && (isResumeEnvelopeBytes(p.text) || isResumeEnvelopeBytes(p.content)));
24317
+ return content.some((p) => isRecord15(p) && (isResumeEnvelopeBytes(p.text) || isResumeEnvelopeBytes(p.content)));
24757
24318
  }
24758
24319
  return false;
24759
24320
  };
@@ -24765,7 +24326,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
24765
24326
  latestParentUserIndex = i;
24766
24327
  break;
24767
24328
  }
24768
- const childDirectories = [join21(dirname11(sessionFile), "auditor-roles")];
24329
+ const childDirectories = [join20(dirname11(sessionFile), "auditor-roles")];
24769
24330
  const valid = [];
24770
24331
  let sawAnyDirectory = false;
24771
24332
  for (const childDirectory of childDirectories) {
@@ -24780,12 +24341,12 @@ async function loadBoundAuditorVolumes(sessionFile) {
24780
24341
  for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
24781
24342
  let entries;
24782
24343
  try {
24783
- entries = await readBoundSessionEntries(join21(childDirectory, file));
24344
+ entries = await readBoundSessionEntries(join20(childDirectory, file));
24784
24345
  } catch (error) {
24785
24346
  throw sessionReadFailure(error, "failed to read discovered auditor session");
24786
24347
  }
24787
24348
  const header = entries.find((entry) => entry.type === "session");
24788
- if (!isRecord16(header)) continue;
24349
+ if (!isRecord15(header)) continue;
24789
24350
  const bindingIndexes = [];
24790
24351
  for (let i = 0; i < entries.length; i += 1) {
24791
24352
  const entry = entries[i];
@@ -24799,7 +24360,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
24799
24360
  end: idx + 1 < bindingIndexes.length ? bindingIndexes[idx + 1] : entries.length
24800
24361
  })) : [{ entry: void 0, start: 0, end: entries.length }];
24801
24362
  for (const { entry: bindingEntry, start, end } of bindingPasses) {
24802
- const bindingParent = bindingEntry !== void 0 && isRecord16(bindingEntry.data) && isRecord16(bindingEntry.data.parent) ? bindingEntry.data.parent : void 0;
24363
+ const bindingParent = bindingEntry !== void 0 && isRecord15(bindingEntry.data) && isRecord15(bindingEntry.data.parent) ? bindingEntry.data.parent : void 0;
24803
24364
  const attemptEntryId = typeof bindingParent?.attemptEntryId === "string" ? bindingParent.attemptEntryId : void 0;
24804
24365
  const attemptEntryIndex = attemptEntryId === void 0 ? -1 : parentEntries.findIndex((entry) => entry.id === attemptEntryId);
24805
24366
  const boundSessionFile = typeof bindingParent?.sessionFile === "string" ? bindingParent.sessionFile : typeof header.parentSession === "string" ? header.parentSession : void 0;
@@ -24826,11 +24387,11 @@ function complianceFailureFromAuditorVolumes(volumes) {
24826
24387
  if (stop === void 0) continue;
24827
24388
  for (let i = entries.length - 1; i >= 0; i -= 1) {
24828
24389
  const entry = entries[i];
24829
- if (entry?.type !== "custom" || entry.customType !== AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE || !isRecord16(entry.data)) continue;
24830
- const parent = isRecord16(entry.data.parent) ? entry.data.parent : void 0;
24831
- const failure = isRecord16(entry.data.failure) ? entry.data.failure : void 0;
24390
+ if (entry?.type !== "custom" || entry.customType !== AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE || !isRecord15(entry.data)) continue;
24391
+ const parent = isRecord15(entry.data.parent) ? entry.data.parent : void 0;
24392
+ const failure = isRecord15(entry.data.failure) ? entry.data.failure : void 0;
24832
24393
  if (parent?.sessionId !== parentId || parent.sessionFile !== sessionFile || parent.attemptEntryId !== attemptEntryId || failure?.cause !== "provider" && failure?.cause !== "unrecognized") continue;
24833
- const identity = isRecord16(failure.identity) ? failure.identity : void 0;
24394
+ const identity = isRecord15(failure.identity) ? failure.identity : void 0;
24834
24395
  return {
24835
24396
  cause: failure.cause === "provider" ? "provider" : "unrecognized",
24836
24397
  ...identity === void 0 ? {} : { identity: {
@@ -24838,7 +24399,7 @@ function complianceFailureFromAuditorVolumes(volumes) {
24838
24399
  ...typeof identity.code === "string" || typeof identity.code === "number" ? { code: identity.code } : {}
24839
24400
  } },
24840
24401
  ...typeof failure.diagnostic === "string" ? { diagnostic: failure.diagnostic } : {},
24841
- ...isRecord16(failure.details) ? { details: failure.details } : {}
24402
+ ...isRecord15(failure.details) ? { details: failure.details } : {}
24842
24403
  };
24843
24404
  }
24844
24405
  }
@@ -24885,9 +24446,9 @@ function typedFailedTerminatingToolKnownFailure(entries) {
24885
24446
  if (classification.kind !== "infrastructure") continue;
24886
24447
  if (typeof message.toolCallId !== "string" || typeof message.toolName !== "string") continue;
24887
24448
  if (boundRoleToolCallForResult(attemptEntries, i, message, message.toolName) === void 0) continue;
24888
- const textPart = Array.isArray(message.content) ? message.content.find((part) => isRecord16(part) && part.type === "text" && typeof part.text === "string") : void 0;
24889
- const diagnostic = isRecord16(textPart) ? textPart.text : void 0;
24890
- const details = isRecord16(message.details) ? message.details : classification.fact;
24449
+ const textPart = Array.isArray(message.content) ? message.content.find((part) => isRecord15(part) && part.type === "text" && typeof part.text === "string") : void 0;
24450
+ const diagnostic = isRecord15(textPart) ? textPart.text : void 0;
24451
+ const details = isRecord15(message.details) ? message.details : classification.fact;
24891
24452
  return {
24892
24453
  cause: "activation",
24893
24454
  identity: { name: message.toolName, code: message.toolCallId },
@@ -25045,7 +24606,7 @@ function controlledFailureInputFromResolution(resolution) {
25045
24606
  } : {}
25046
24607
  };
25047
24608
  }
25048
- function isRecord16(value) {
24609
+ function isRecord15(value) {
25049
24610
  return typeof value === "object" && value !== null && !Array.isArray(value);
25050
24611
  }
25051
24612
  function safelyRead(object, key) {
@@ -25169,7 +24730,7 @@ function boundRoleToolCallForResult(entries, resultIndex, message, outputToolNam
25169
24730
  const candidateMessage = entries[index]?.message;
25170
24731
  if (candidateMessage?.role === "assistant" && Array.isArray(candidateMessage.content)) {
25171
24732
  for (const part of candidateMessage.content) {
25172
- if (!isRecord16(part) || part.type !== "toolCall" || part.id !== callId) {
24733
+ if (!isRecord15(part) || part.type !== "toolCall" || part.id !== callId) {
25173
24734
  continue;
25174
24735
  }
25175
24736
  if (part.name !== outputToolName) return void 0;
@@ -25241,7 +24802,7 @@ function parseNavigatorAttendanceDetails(details) {
25241
24802
  const advisoryDiagnostic = typeof details.routePlaybookReadFailure === "string" ? { advisoryDiagnostic: details.routePlaybookReadFailure } : {};
25242
24803
  if (disposition === "recommendation") {
25243
24804
  const next = details.next;
25244
- if (!isRecord16(next) || typeof next.role !== "string") {
24805
+ if (!isRecord15(next) || typeof next.role !== "string") {
25245
24806
  return {
25246
24807
  disposition: "unavailable",
25247
24808
  source: "unknown",
@@ -25249,7 +24810,7 @@ function parseNavigatorAttendanceDetails(details) {
25249
24810
  };
25250
24811
  }
25251
24812
  const reason = typeof details.reason === "string" ? details.reason : "";
25252
- const route = Array.isArray(details.route) ? details.route.filter(isRecord16).map((target) => ({
24813
+ const route = Array.isArray(details.route) ? details.route.filter(isRecord15).map((target) => ({
25253
24814
  role: String(target.role),
25254
24815
  phase: navigatorPhaseValue(target.phase)
25255
24816
  })) : void 0;
@@ -25312,8 +24873,8 @@ function projectTerminalGateFact(rounds) {
25312
24873
  };
25313
24874
  }
25314
24875
  async function extractGateFactFromSessionDirectory(sessionDirectory, options = {}) {
25315
- const directories = [join21(sessionDirectory, "auditor-roles")];
25316
- const parentSessionFile = options.parentSessionFile ?? join21(sessionDirectory, "session.jsonl");
24876
+ const directories = [join20(sessionDirectory, "auditor-roles")];
24877
+ const parentSessionFile = options.parentSessionFile ?? join20(sessionDirectory, "session.jsonl");
25317
24878
  const rounds = await readAnalystGateCyclesFromAuditorRoles(directories, {
25318
24879
  parentSessionFile
25319
24880
  });
@@ -25321,7 +24882,7 @@ async function extractGateFactFromSessionDirectory(sessionDirectory, options = {
25321
24882
  }
25322
24883
  async function withOptionalGateProjection(base, sessionDirectory, gateContext = {}) {
25323
24884
  const secondaryEvidence = base.roleOutcome.kind === "failure" ? base.roleOutcome.decisiveFacts.secondaryEvidence : void 0;
25324
- if (isRecord16(secondaryEvidence) && secondaryEvidence.kind === "role_infrastructure_failure" && (secondaryEvidence.stage === "gatekeeper" || secondaryEvidence.stage === "inspector" || secondaryEvidence.stage === "notary")) return base;
24885
+ if (isRecord15(secondaryEvidence) && secondaryEvidence.kind === "role_infrastructure_failure" && (secondaryEvidence.stage === "gatekeeper" || secondaryEvidence.stage === "inspector" || secondaryEvidence.stage === "notary")) return base;
25325
24886
  const gate = await extractGateFactFromSessionDirectory(sessionDirectory, gateContext);
25326
24887
  return gate === void 0 ? base : { ...base, gate };
25327
24888
  }
@@ -25361,7 +24922,7 @@ function extractNavigatorFact(entries) {
25361
24922
  const entry = entries[i];
25362
24923
  if (entry?.type === "custom_message" && entry.customType === "ak-navigator-attendance") {
25363
24924
  const details = entry.message?.details ?? entry.details;
25364
- if (!isRecord16(details)) {
24925
+ if (!isRecord15(details)) {
25365
24926
  return {
25366
24927
  disposition: "unavailable",
25367
24928
  source: "unknown",
@@ -25411,8 +24972,8 @@ async function extractNavigatorFactFromAdmittedSession(sessionFile) {
25411
24972
  async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
25412
24973
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
25413
24974
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
25414
- const reportPath = join21(artifactsDir, "report.json");
25415
- const evidencePath = join21(artifactsDir, "evidence.json");
24975
+ const reportPath = join20(artifactsDir, "report.json");
24976
+ const evidencePath = join20(artifactsDir, "evidence.json");
25416
24977
  await writeFile5(
25417
24978
  reportPath,
25418
24979
  `${JSON.stringify(
@@ -25456,8 +25017,8 @@ async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
25456
25017
  async function publishCoderArtifacts(admitted, roleOutcome, coordinates, options = {}) {
25457
25018
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
25458
25019
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
25459
- const reportPath = join21(artifactsDir, "report.json");
25460
- const evidencePath = join21(artifactsDir, "evidence.json");
25020
+ const reportPath = join20(artifactsDir, "report.json");
25021
+ const evidencePath = join20(artifactsDir, "evidence.json");
25461
25022
  await writeFile5(
25462
25023
  reportPath,
25463
25024
  `${JSON.stringify(
@@ -25608,8 +25169,8 @@ function extractFixerMethodInvocations(entries, options) {
25608
25169
  async function publishFixerArtifacts(admitted, roleOutcome, coordinates, options) {
25609
25170
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
25610
25171
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
25611
- const reportPath = join21(artifactsDir, "report.json");
25612
- const evidencePath = join21(artifactsDir, "evidence.json");
25172
+ const reportPath = join20(artifactsDir, "report.json");
25173
+ const evidencePath = join20(artifactsDir, "evidence.json");
25613
25174
  await writeFile5(
25614
25175
  reportPath,
25615
25176
  `${JSON.stringify(
@@ -25699,8 +25260,8 @@ async function settleLawfulFixerTerminalResult(admitted, authority, options) {
25699
25260
  async function publishCollectorArtifacts(admitted, roleOutcome, coordinates, options = {}) {
25700
25261
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
25701
25262
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
25702
- const reportPath = join21(artifactsDir, "report.json");
25703
- const evidencePath = join21(artifactsDir, "evidence.json");
25263
+ const reportPath = join20(artifactsDir, "report.json");
25264
+ const evidencePath = join20(artifactsDir, "evidence.json");
25704
25265
  await writeFile5(
25705
25266
  reportPath,
25706
25267
  `${JSON.stringify(
@@ -25759,7 +25320,7 @@ async function settleLawfulCollectorTerminalResult(admitted, authority) {
25759
25320
  const residual = boundErroredToolCandidate(entries, index, message, COLLECTOR_WAIT_TOOL);
25760
25321
  if (residual === void 0) continue;
25761
25322
  const candidate = residual.candidate;
25762
- const duration = isRecord16(candidate) ? candidate.durationMs : void 0;
25323
+ const duration = isRecord15(candidate) ? candidate.durationMs : void 0;
25763
25324
  if (Number.isSafeInteger(duration) && duration >= 1 && duration <= 9e5) {
25764
25325
  continue;
25765
25326
  }
@@ -25807,8 +25368,8 @@ async function trySettleCollectorTerminalResult(admitted, authority) {
25807
25368
  async function publishDoctorArtifacts(admitted, roleOutcome, coordinates, options = {}) {
25808
25369
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
25809
25370
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
25810
- const reportPath = join21(artifactsDir, "report.json");
25811
- const evidencePath = join21(artifactsDir, "evidence.json");
25371
+ const reportPath = join20(artifactsDir, "report.json");
25372
+ const evidencePath = join20(artifactsDir, "evidence.json");
25812
25373
  await writeFile5(
25813
25374
  reportPath,
25814
25375
  `${JSON.stringify(
@@ -25949,7 +25510,7 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
25949
25510
  spec.toolName
25950
25511
  );
25951
25512
  if (residual !== void 0) {
25952
- const details = isRecord16(residual.candidate) ? residual.candidate : { candidate: residual.candidate };
25513
+ const details = isRecord15(residual.candidate) ? residual.candidate : { candidate: residual.candidate };
25953
25514
  return settleFailureTerminalResult(admitted, {
25954
25515
  cause: "output",
25955
25516
  diagnostic: residual.diagnostic,
@@ -26068,8 +25629,8 @@ function extractReviewerMethodInvocations(entries, options) {
26068
25629
  async function publishReviewerArtifacts(admitted, roleOutcome, coordinates, options) {
26069
25630
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
26070
25631
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
26071
- const reportPath = join21(artifactsDir, "report.json");
26072
- const evidencePath = join21(artifactsDir, "evidence.json");
25632
+ const reportPath = join20(artifactsDir, "report.json");
25633
+ const evidencePath = join20(artifactsDir, "evidence.json");
26073
25634
  await writeFile5(
26074
25635
  reportPath,
26075
25636
  `${JSON.stringify(
@@ -26183,8 +25744,8 @@ function extractMergerMethodInvocations(entries, options) {
26183
25744
  async function publishMergerArtifacts(admitted, roleOutcome, coordinates, options) {
26184
25745
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
26185
25746
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
26186
- const reportPath = join21(artifactsDir, "report.json");
26187
- const evidencePath = join21(artifactsDir, "evidence.json");
25747
+ const reportPath = join20(artifactsDir, "report.json");
25748
+ const evidencePath = join20(artifactsDir, "evidence.json");
26188
25749
  await writeFile5(
26189
25750
  reportPath,
26190
25751
  `${JSON.stringify(
@@ -26251,7 +25812,7 @@ async function settleLawfulMergerTerminalResult(admitted, authority, options) {
26251
25812
  if (message?.role !== "toolResult") continue;
26252
25813
  const residual = boundErroredToolCandidate(entries, index, message, MERGER_OUTPUT_TOOL_NAME);
26253
25814
  if (residual === void 0) continue;
26254
- const attemptId = isRecord16(residual.candidate) ? safelyRead(residual.candidate, "attemptId") : { readable: true, value: void 0 };
25815
+ const attemptId = isRecord15(residual.candidate) ? safelyRead(residual.candidate, "attemptId") : { readable: true, value: void 0 };
26255
25816
  if (!attemptId.readable || attemptId.value !== admitted.runId) continue;
26256
25817
  return {
26257
25818
  roleOutcome: buildResidualIncompleteTerminalOutcome({
@@ -26329,7 +25890,7 @@ function uniqueFailureFallbackDirs(runDirectory, baseDir) {
26329
25890
  return dirs;
26330
25891
  }
26331
25892
  async function resolveFailureArtifactsBase(runDirectory) {
26332
- const artifactsDir = join21(runDirectory, "artifacts");
25893
+ const artifactsDir = join20(runDirectory, "artifacts");
26333
25894
  try {
26334
25895
  await ensureRunArtifactsDir(runDirectory);
26335
25896
  return { baseDir: artifactsDir };
@@ -26345,7 +25906,7 @@ async function writeFailureJsonRetainingCause(preferredCandidates, uniqueFallbac
26345
25906
  const candidates = [
26346
25907
  ...preferredCandidates,
26347
25908
  // One unique name per fallback dir — collisions on fixed names cannot exhaust this.
26348
- ...uniqueFallbackDirs.map((dir) => join21(dir, `${stem}.${randomUUID3()}.json`))
25909
+ ...uniqueFallbackDirs.map((dir) => join20(dir, `${stem}.${randomUUID3()}.json`))
26349
25910
  ];
26350
25911
  for (let i = 0; i < candidates.length; i += 1) {
26351
25912
  const path = candidates[i];
@@ -26390,26 +25951,26 @@ async function publishFailureArtifacts(admitted, failure, authority) {
26390
25951
  } catch (error) {
26391
25952
  priorIssues.push(publicationAttemptFromError(sessionFile, error));
26392
25953
  }
26393
- const underArtifacts = baseDir === join21(admitted.runDirectory, "artifacts");
25954
+ const underArtifacts = baseDir === join20(admitted.runDirectory, "artifacts");
26394
25955
  const uniqueFallbackDirs = uniqueFailureFallbackDirs(
26395
25956
  admitted.runDirectory,
26396
25957
  baseDir
26397
25958
  );
26398
25959
  const errorCandidates = underArtifacts ? [
26399
- join21(baseDir, "error.json"),
26400
- join21(baseDir, "error.settlement.json"),
26401
- join21(admitted.runDirectory, "error.settlement.json")
25960
+ join20(baseDir, "error.json"),
25961
+ join20(baseDir, "error.settlement.json"),
25962
+ join20(admitted.runDirectory, "error.settlement.json")
26402
25963
  ] : [
26403
- join21(baseDir, "error.settlement.json"),
26404
- join21(baseDir, "error.json")
25964
+ join20(baseDir, "error.settlement.json"),
25965
+ join20(baseDir, "error.json")
26405
25966
  ];
26406
25967
  const evidenceCandidates = underArtifacts ? [
26407
- join21(baseDir, "evidence.json"),
26408
- join21(baseDir, "evidence.settlement.json"),
26409
- join21(admitted.runDirectory, "evidence.settlement.json")
25968
+ join20(baseDir, "evidence.json"),
25969
+ join20(baseDir, "evidence.settlement.json"),
25970
+ join20(admitted.runDirectory, "evidence.settlement.json")
26410
25971
  ] : [
26411
- join21(baseDir, "evidence.settlement.json"),
26412
- join21(baseDir, "evidence.json")
25972
+ join20(baseDir, "evidence.settlement.json"),
25973
+ join20(baseDir, "evidence.json")
26413
25974
  ];
26414
25975
  const errorPayloadBase = {
26415
25976
  kind: "error",
@@ -26675,9 +26236,336 @@ function projectRoleTurnRequest(admitted, roleDetails, options) {
26675
26236
  ...options.timeoutMs === void 0 ? {} : { timeoutMs: options.timeoutMs }
26676
26237
  };
26677
26238
  }
26678
- var init_turn_request = __esm({
26679
- "src/public-cli/turn-request.ts"() {
26239
+ var init_turn_request = __esm({
26240
+ "src/public-cli/turn-request.ts"() {
26241
+ "use strict";
26242
+ }
26243
+ });
26244
+
26245
+ // src/ticket-provenance-contracts.ts
26246
+ function isRecord16(value) {
26247
+ return typeof value === "object" && value !== null && !Array.isArray(value);
26248
+ }
26249
+ function projectTicketProvenanceDiagnostic(value) {
26250
+ if (!isRecord16(value)) return void 0;
26251
+ if (value.recordClass !== TICKET_PROVENANCE_RECORD_CLASS_DIAGNOSTIC) {
26252
+ return void 0;
26253
+ }
26254
+ if (typeof value.diagnosticKind !== "string" || !DIAGNOSTIC_KINDS.has(value.diagnosticKind)) {
26255
+ return void 0;
26256
+ }
26257
+ if (typeof value.cause !== "string" || value.cause.length === 0) {
26258
+ return void 0;
26259
+ }
26260
+ if (typeof value.recordedAt !== "string" || value.recordedAt.length === 0) {
26261
+ return void 0;
26262
+ }
26263
+ return {
26264
+ recordClass: TICKET_PROVENANCE_RECORD_CLASS_DIAGNOSTIC,
26265
+ diagnosticKind: value.diagnosticKind,
26266
+ cause: value.cause,
26267
+ recordedAt: value.recordedAt,
26268
+ ...typeof value.reason === "string" ? { reason: value.reason } : {}
26269
+ };
26270
+ }
26271
+ function projectTicketProvenanceEntry(value) {
26272
+ if (!isRecord16(value)) return void 0;
26273
+ if (value.recordClass === TICKET_PROVENANCE_RECORD_CLASS_DIAGNOSTIC) {
26274
+ return void 0;
26275
+ }
26276
+ if (!isRecord16(value.basis)) return void 0;
26277
+ if (typeof value.basis.method !== "string" || !BASIS_METHODS.has(value.basis.method)) {
26278
+ return void 0;
26279
+ }
26280
+ if (typeof value.sourceKind !== "string" || !SOURCE_KINDS.has(value.sourceKind)) {
26281
+ return void 0;
26282
+ }
26283
+ if (!isRecord16(value.sourceRef)) return void 0;
26284
+ if (typeof value.transcript !== "string" || value.transcript.length === 0) {
26285
+ return void 0;
26286
+ }
26287
+ if (typeof value.timestamp !== "string" || value.timestamp.length === 0) {
26288
+ return void 0;
26289
+ }
26290
+ const basis = {
26291
+ method: value.basis.method,
26292
+ ...Array.isArray(value.basis.anchors) ? {
26293
+ anchors: value.basis.anchors.filter(
26294
+ (item) => typeof item === "string"
26295
+ )
26296
+ } : {},
26297
+ ...typeof value.basis.note === "string" ? { note: value.basis.note } : {}
26298
+ };
26299
+ const sourceRef = {
26300
+ ...typeof value.sourceRef.sessionFile === "string" ? { sessionFile: value.sourceRef.sessionFile } : {},
26301
+ ...typeof value.sourceRef.entryId === "string" || typeof value.sourceRef.entryId === "number" ? { entryId: value.sourceRef.entryId } : {},
26302
+ ...typeof value.sourceRef.path === "string" ? { path: value.sourceRef.path } : {},
26303
+ ...typeof value.sourceRef.url === "string" ? { url: value.sourceRef.url } : {}
26304
+ };
26305
+ return {
26306
+ basis,
26307
+ sourceKind: value.sourceKind,
26308
+ sourceRef,
26309
+ transcript: value.transcript,
26310
+ timestamp: value.timestamp
26311
+ };
26312
+ }
26313
+ var TICKET_PROVENANCE_KIND, TICKET_PROVENANCE_HUMAN_VIEW, TICKET_PROVENANCE_OFFERED_WATERMARK, TICKET_PROVENANCE_RECORD_CLASS_DIAGNOSTIC, SOURCE_KINDS, BASIS_METHODS, DIAGNOSTIC_KINDS;
26314
+ var init_ticket_provenance_contracts = __esm({
26315
+ "src/ticket-provenance-contracts.ts"() {
26316
+ "use strict";
26317
+ TICKET_PROVENANCE_KIND = "ticket-provenance";
26318
+ TICKET_PROVENANCE_HUMAN_VIEW = "\u8D77\u5C45\u5F55.md";
26319
+ TICKET_PROVENANCE_OFFERED_WATERMARK = "offered-identities.jsonl";
26320
+ TICKET_PROVENANCE_RECORD_CLASS_DIAGNOSTIC = "diagnostic";
26321
+ SOURCE_KINDS = /* @__PURE__ */ new Set([
26322
+ "cc-session",
26323
+ "issue-body-comment",
26324
+ "adr-decision-key",
26325
+ "ticket-decree-block"
26326
+ ]);
26327
+ BASIS_METHODS = /* @__PURE__ */ new Set(["llm-semantic"]);
26328
+ DIAGNOSTIC_KINDS = /* @__PURE__ */ new Set([
26329
+ "collector-failed",
26330
+ "issue-source-failed",
26331
+ "quote-verify-failed"
26332
+ ]);
26333
+ }
26334
+ });
26335
+
26336
+ // src/ticket-provenance.ts
26337
+ import { createHash as createHash5 } from "node:crypto";
26338
+ import { appendFileSync as appendFileSync2, existsSync as existsSync7, mkdirSync as mkdirSync3, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "node:fs";
26339
+ import { join as join21 } from "node:path";
26340
+ function ticketProvenanceSubject(ticketNumber) {
26341
+ if (!Number.isSafeInteger(ticketNumber) || ticketNumber < 1) {
26342
+ throw new Error(`ticket-provenance subject requires a positive ticket number, got ${String(ticketNumber)}`);
26343
+ }
26344
+ return String(ticketNumber);
26345
+ }
26346
+ function ticketProvenanceEntryIdentity(input) {
26347
+ const ref = input.sourceRef;
26348
+ const refKey = [
26349
+ ref.sessionFile ?? "",
26350
+ ref.entryId === void 0 ? "" : String(ref.entryId),
26351
+ ref.path ?? "",
26352
+ ref.url ?? ""
26353
+ ].join("");
26354
+ const material = [
26355
+ String(input.ticketNumber),
26356
+ input.sourceKind,
26357
+ refKey,
26358
+ input.transcript
26359
+ ].join("\0");
26360
+ return createHash5("sha256").update(material, "utf8").digest("hex");
26361
+ }
26362
+ function resolveTicketProvenanceVolume(ticketNumber, cwd, home) {
26363
+ const path = resolveSitianRecordPath({
26364
+ level: "event",
26365
+ kind: TICKET_PROVENANCE_KIND,
26366
+ subject: ticketProvenanceSubject(ticketNumber),
26367
+ cwd,
26368
+ ...home === void 0 ? {} : { home }
26369
+ });
26370
+ return {
26371
+ recordFile: path.recordFile,
26372
+ volumeDir: path.sessionDir,
26373
+ humanViewFile: join21(path.sessionDir, TICKET_PROVENANCE_HUMAN_VIEW),
26374
+ offeredWatermarkFile: join21(path.sessionDir, TICKET_PROVENANCE_OFFERED_WATERMARK)
26375
+ };
26376
+ }
26377
+ function readOfferedIdentities(ticketNumber, cwd, home) {
26378
+ const { offeredWatermarkFile } = resolveTicketProvenanceVolume(ticketNumber, cwd, home);
26379
+ if (!existsSync7(offeredWatermarkFile)) return /* @__PURE__ */ new Set();
26380
+ let text;
26381
+ try {
26382
+ text = readFileSync2(offeredWatermarkFile, "utf8");
26383
+ } catch (error) {
26384
+ throw new TicketProvenanceWatermarkError(
26385
+ "unreadable",
26386
+ `ticket-provenance offered watermark unreadable (${offeredWatermarkFile})`,
26387
+ { cause: error }
26388
+ );
26389
+ }
26390
+ const seen = /* @__PURE__ */ new Set();
26391
+ const lines = text.split("\n");
26392
+ for (let index = 0; index < lines.length; index += 1) {
26393
+ const trimmed = lines[index].trim();
26394
+ if (!trimmed) continue;
26395
+ let parsed;
26396
+ try {
26397
+ parsed = JSON.parse(trimmed);
26398
+ } catch (error) {
26399
+ throw new TicketProvenanceWatermarkError(
26400
+ "malformed-json",
26401
+ `ticket-provenance offered watermark malformed JSON at line ${index + 1} (${offeredWatermarkFile})`,
26402
+ { cause: error }
26403
+ );
26404
+ }
26405
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed) || typeof parsed.identity !== "string" || parsed.identity.length === 0) {
26406
+ throw new TicketProvenanceWatermarkError(
26407
+ "bad-shape",
26408
+ `ticket-provenance offered watermark bad shape at line ${index + 1} (${offeredWatermarkFile})`
26409
+ );
26410
+ }
26411
+ seen.add(parsed.identity);
26412
+ }
26413
+ return seen;
26414
+ }
26415
+ async function readTicketProvenance(ticketNumber, cwd, home) {
26416
+ const { recordFile } = resolveTicketProvenanceVolume(ticketNumber, cwd, home);
26417
+ const { records: records2 } = await readSitianRecords(recordFile);
26418
+ const entries = [];
26419
+ const diagnostics = [];
26420
+ let skipped = 0;
26421
+ for (const record4 of records2) {
26422
+ if (record4.kind !== TICKET_PROVENANCE_KIND) {
26423
+ skipped += 1;
26424
+ continue;
26425
+ }
26426
+ const diagnostic = projectTicketProvenanceDiagnostic(record4.payload);
26427
+ if (diagnostic !== void 0) {
26428
+ diagnostics.push(diagnostic);
26429
+ continue;
26430
+ }
26431
+ const entry = projectTicketProvenanceEntry(record4.payload);
26432
+ if (entry === void 0) {
26433
+ skipped += 1;
26434
+ continue;
26435
+ }
26436
+ entries.push(entry);
26437
+ }
26438
+ return { entries, diagnostics, records: records2, recordFile, skipped };
26439
+ }
26440
+ function markdownFenceFor(text) {
26441
+ let longest = 0;
26442
+ const runs = text.match(/`+/g);
26443
+ if (runs !== null) {
26444
+ for (const run of runs) {
26445
+ if (run.length > longest) longest = run.length;
26446
+ }
26447
+ }
26448
+ return "`".repeat(Math.max(3, longest + 1));
26449
+ }
26450
+ function renderTicketProvenanceMarkdown(input) {
26451
+ const lines = [
26452
+ `# \u8D77\u5C45\u5F55 \xB7 #${input.ticketNumber}`,
26453
+ "",
26454
+ `\u6761\u76EE\u6570\uFF1A${input.entries.length}`,
26455
+ ""
26456
+ ];
26457
+ let index = 0;
26458
+ for (const entry of input.entries) {
26459
+ index += 1;
26460
+ lines.push(`## ${index}. ${entry.sourceKind} \xB7 ${entry.timestamp}`);
26461
+ lines.push("");
26462
+ lines.push(`- basis.method: \`${entry.basis.method}\``);
26463
+ if (entry.basis.anchors !== void 0 && entry.basis.anchors.length > 0) {
26464
+ lines.push(`- anchors: ${entry.basis.anchors.map((a) => `\`${a}\``).join(", ")}`);
26465
+ }
26466
+ if (entry.basis.note !== void 0) {
26467
+ lines.push(`- note: ${entry.basis.note}`);
26468
+ }
26469
+ const refParts = [];
26470
+ if (entry.sourceRef.sessionFile !== void 0) {
26471
+ refParts.push(`sessionFile=${entry.sourceRef.sessionFile}`);
26472
+ }
26473
+ if (entry.sourceRef.entryId !== void 0) {
26474
+ refParts.push(`entryId=${String(entry.sourceRef.entryId)}`);
26475
+ }
26476
+ if (entry.sourceRef.path !== void 0) {
26477
+ refParts.push(`path=${entry.sourceRef.path}`);
26478
+ }
26479
+ if (entry.sourceRef.url !== void 0) {
26480
+ refParts.push(`url=${entry.sourceRef.url}`);
26481
+ }
26482
+ if (refParts.length > 0) {
26483
+ lines.push(`- sourceRef: ${refParts.join(" \xB7 ")}`);
26484
+ }
26485
+ lines.push("");
26486
+ const fence = markdownFenceFor(entry.transcript);
26487
+ lines.push(fence);
26488
+ lines.push(entry.transcript);
26489
+ lines.push(fence);
26490
+ lines.push("");
26491
+ }
26492
+ return lines.join("\n");
26493
+ }
26494
+ function ensureTicketProvenanceVolume(ticketNumber, cwd, home) {
26495
+ const volume = resolveTicketProvenanceVolume(ticketNumber, cwd, home);
26496
+ mkdirSync3(volume.volumeDir, { recursive: true });
26497
+ appendFileSync2(volume.recordFile, "", "utf8");
26498
+ return volume;
26499
+ }
26500
+ function appendTicketProvenanceDiagnostic(input) {
26501
+ const subject = ticketProvenanceSubject(input.ticketNumber);
26502
+ const identityParts = input.diagnostic.diagnosticKind === "quote-verify-failed" ? [
26503
+ subject,
26504
+ input.diagnostic.recordClass,
26505
+ input.diagnostic.diagnosticKind,
26506
+ input.diagnostic.cause,
26507
+ input.diagnostic.reason ?? ""
26508
+ ] : [
26509
+ subject,
26510
+ input.diagnostic.recordClass,
26511
+ input.diagnostic.diagnosticKind,
26512
+ input.diagnostic.recordedAt,
26513
+ input.diagnostic.cause,
26514
+ input.diagnostic.reason ?? ""
26515
+ ];
26516
+ const identity = createHash5("sha256").update(identityParts.join("\0"), "utf8").digest("hex");
26517
+ return sitianReport({
26518
+ level: "event",
26519
+ kind: TICKET_PROVENANCE_KIND,
26520
+ identity,
26521
+ subject,
26522
+ cwd: input.cwd,
26523
+ ...input.home === void 0 ? {} : { home: input.home },
26524
+ host: input.host ?? "diarist",
26525
+ source: input.source ?? "diarist-diagnostic",
26526
+ payload: input.diagnostic
26527
+ });
26528
+ }
26529
+ function appendIssueSourceFailureDiagnostic(input) {
26530
+ const recordedAt = input.recordedAt ?? (/* @__PURE__ */ new Date()).toISOString();
26531
+ return appendTicketProvenanceDiagnostic({
26532
+ ticketNumber: input.ticketNumber,
26533
+ cwd: input.cwd,
26534
+ ...input.home === void 0 ? {} : { home: input.home },
26535
+ source: "diarist-issue-source",
26536
+ diagnostic: {
26537
+ recordClass: TICKET_PROVENANCE_RECORD_CLASS_DIAGNOSTIC,
26538
+ diagnosticKind: "issue-source-failed",
26539
+ cause: input.cause,
26540
+ recordedAt,
26541
+ reason: input.reason
26542
+ }
26543
+ });
26544
+ }
26545
+ function writeTicketProvenanceHumanView(input) {
26546
+ const volume = ensureTicketProvenanceVolume(input.ticketNumber, input.cwd, input.home);
26547
+ const md = renderTicketProvenanceMarkdown({
26548
+ ticketNumber: input.ticketNumber,
26549
+ entries: input.entries
26550
+ });
26551
+ writeFileSync2(volume.humanViewFile, md, "utf8");
26552
+ return volume.humanViewFile;
26553
+ }
26554
+ var TicketProvenanceWatermarkError;
26555
+ var init_ticket_provenance = __esm({
26556
+ "src/ticket-provenance.ts"() {
26680
26557
  "use strict";
26558
+ init_sitian_facade();
26559
+ init_ticket_provenance_contracts();
26560
+ TicketProvenanceWatermarkError = class extends Error {
26561
+ code = "ticket-provenance-watermark";
26562
+ reason;
26563
+ constructor(reason, message, options) {
26564
+ super(message, options);
26565
+ this.name = "TicketProvenanceWatermarkError";
26566
+ this.reason = reason;
26567
+ }
26568
+ };
26681
26569
  }
26682
26570
  });
26683
26571
 
@@ -27863,12 +27751,7 @@ async function runPublicCoder(argv, env, io, parseCoderArgv2) {
27863
27751
  })
27864
27752
  }
27865
27753
  }),
27866
- adapters: {
27867
- ...coderAdapters(methodProvenance),
27868
- beforeDispatch: async (admittedSeat) => {
27869
- await resolveSeatTicketBinding(admittedSeat, env);
27870
- }
27871
- },
27754
+ adapters: coderAdapters(methodProvenance),
27872
27755
  ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
27873
27756
  });
27874
27757
  }
@@ -27928,7 +27811,6 @@ var init_coder_run = __esm({
27928
27811
  init_method_skill();
27929
27812
  init_cli_errors();
27930
27813
  init_invocation();
27931
- init_seat_ticket_binding();
27932
27814
  init_run_lifecycle();
27933
27815
  init_settlement();
27934
27816
  init_turn_request();
@@ -27936,6 +27818,30 @@ var init_coder_run = __esm({
27936
27818
  }
27937
27819
  });
27938
27820
 
27821
+ // src/public-cli/seat-ticket-binding.ts
27822
+ async function tryResumeSameTicketSeatRun(input) {
27823
+ if (input.freshSummons === true) return void 0;
27824
+ if (input.parentRunPath === void 0 && input.ticketNumber === void 0) {
27825
+ return void 0;
27826
+ }
27827
+ const previousRunId = await findLatestRunIdForSeatTicket({
27828
+ home: input.home,
27829
+ bookKey: resolveBookKeyFromGit(input.projectRoot),
27830
+ role: input.role,
27831
+ ...input.parentRunPath === void 0 ? {} : { parentRunPath: input.parentRunPath },
27832
+ ...input.ticketNumber === void 0 ? {} : { ticketNumber: input.ticketNumber }
27833
+ });
27834
+ if (previousRunId === void 0) return void 0;
27835
+ return await input.resume(previousRunId, input.summons);
27836
+ }
27837
+ var init_seat_ticket_binding = __esm({
27838
+ "src/public-cli/seat-ticket-binding.ts"() {
27839
+ "use strict";
27840
+ init_activation_ledger_git();
27841
+ init_run_lifecycle();
27842
+ }
27843
+ });
27844
+
27939
27845
  // src/public-cli/instruction-seat-run.ts
27940
27846
  function buildInstructionSeatTurnRequest(admitted, options) {
27941
27847
  return projectRoleTurnRequest(
@@ -28057,7 +27963,6 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv2) {
28057
27963
  let auditorSubject;
28058
27964
  let auditorSourceRun;
28059
27965
  let auditorSourceTicket;
28060
- let reusedTicketNumber;
28061
27966
  const projectRoot = parsed.project ?? env.cwd;
28062
27967
  if (role === "auditor") {
28063
27968
  if (parsed.subject !== "judge" && parsed.subject !== "doctor") {
@@ -28092,12 +27997,6 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv2) {
28092
27997
  );
28093
27998
  return { exitCode: 2 };
28094
27999
  }
28095
- } else {
28096
- reusedTicketNumber = await resolveKnownTicketNumber({
28097
- instruction: parsed.instruction,
28098
- projectRoot,
28099
- home: env.home
28100
- });
28101
28000
  }
28102
28001
  const summons = {
28103
28002
  instruction: parsed.instruction,
@@ -28123,21 +28022,6 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv2) {
28123
28022
  })
28124
28023
  });
28125
28024
  if (resumed !== void 0) return resumed;
28126
- } else if (reusedTicketNumber !== void 0) {
28127
- const resumed = await tryResumeSameTicketSeatRun({
28128
- home: env.home,
28129
- projectRoot,
28130
- role,
28131
- ticketNumber: reusedTicketNumber,
28132
- freshSummons: env.freshSummons,
28133
- summons,
28134
- resume: (runId, materials) => runPublicInstructionSeatResume(
28135
- { runId, ...materials === void 0 ? {} : { summons: materials } },
28136
- env,
28137
- io
28138
- )
28139
- });
28140
- if (resumed !== void 0) return resumed;
28141
28025
  }
28142
28026
  let admitted;
28143
28027
  try {
@@ -28195,8 +28079,6 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv2) {
28195
28079
  beforeDispatch: async (admittedSeat) => {
28196
28080
  if (auditorSourceTicket !== void 0) {
28197
28081
  await bindAdmittedTicketNumber(admittedSeat, auditorSourceTicket);
28198
- } else {
28199
- await bindReusedTicketNumber(admittedSeat, reusedTicketNumber);
28200
28082
  }
28201
28083
  }
28202
28084
  }),
@@ -28329,7 +28211,7 @@ var init_collector_run = __esm({
28329
28211
 
28330
28212
  // src/diarist-mechanical.ts
28331
28213
  import { createHash as createHash6 } from "node:crypto";
28332
- import { existsSync as existsSync9, readdirSync as readdirSync2, readFileSync as readFileSync3, realpathSync as realpathSync3, statSync as statSync2 } from "node:fs";
28214
+ import { existsSync as existsSync8, readdirSync as readdirSync2, readFileSync as readFileSync3, realpathSync as realpathSync3, statSync as statSync2 } from "node:fs";
28333
28215
  import { basename as basename7, join as join25, resolve as resolve10 } from "node:path";
28334
28216
  import { homedir } from "node:os";
28335
28217
  function extractCornerQuotes(text, minLength = DEFAULT_QUOTE_MIN) {
@@ -28411,7 +28293,7 @@ function isNotificationRow(type, text) {
28411
28293
  }
28412
28294
  function readCcSessionBlocks(options) {
28413
28295
  const root = options.projectsRoot ?? join25(homedir(), ".claude", "projects");
28414
- if (!existsSync9(root)) return [];
28296
+ if (!existsSync8(root)) return [];
28415
28297
  const blocks = [];
28416
28298
  const dirs = /* @__PURE__ */ new Set();
28417
28299
  for (const cwd of options.cwds) {
@@ -28420,10 +28302,10 @@ function readCcSessionBlocks(options) {
28420
28302
  for (const cwd of options.cwds) {
28421
28303
  if (cwd.includes("projects")) continue;
28422
28304
  const direct = join25(root, cwd);
28423
- if (existsSync9(direct)) dirs.add(direct);
28305
+ if (existsSync8(direct)) dirs.add(direct);
28424
28306
  }
28425
28307
  for (const dir of dirs) {
28426
- if (!existsSync9(dir)) continue;
28308
+ if (!existsSync8(dir)) continue;
28427
28309
  let dirStat;
28428
28310
  try {
28429
28311
  dirStat = statSync2(dir);
@@ -28548,7 +28430,7 @@ function readAdrDecisionKeyBlocks(input) {
28548
28430
  const adrRootAbs = resolve10(cwdAbs, DIARIST_ADR_ROOT_REL);
28549
28431
  let adrRootReal;
28550
28432
  try {
28551
- adrRootReal = existsSync9(adrRootAbs) ? realpathSync3(adrRootAbs) : resolve10(realpathSync3(cwdAbs), DIARIST_ADR_ROOT_REL);
28433
+ adrRootReal = existsSync8(adrRootAbs) ? realpathSync3(adrRootAbs) : resolve10(realpathSync3(cwdAbs), DIARIST_ADR_ROOT_REL);
28552
28434
  } catch (error) {
28553
28435
  throw new DiaristSourceReadError(
28554
28436
  "adr-unreadable",
@@ -28574,7 +28456,7 @@ function readAdrDecisionKeyBlocks(input) {
28574
28456
  `diarist referenced ADR escapes docs/adr (${rel})`
28575
28457
  );
28576
28458
  }
28577
- if (!existsSync9(abs)) {
28459
+ if (!existsSync8(abs)) {
28578
28460
  throw new DiaristSourceReadError(
28579
28461
  "adr-missing",
28580
28462
  abs,
@@ -28806,22 +28688,28 @@ function loadSourceBlocks(input) {
28806
28688
  return blocks;
28807
28689
  }
28808
28690
  async function prepareDiaristSourceCatalog(input) {
28809
- ensureTicketProvenanceVolume(input.ticketNumber, input.cwd, input.home);
28810
- const volume = await readTicketProvenance(input.ticketNumber, input.cwd, input.home);
28811
- writeTicketProvenanceHumanView({
28812
- ticketNumber: input.ticketNumber,
28813
- cwd: input.cwd,
28814
- ...input.home === void 0 ? {} : { home: input.home },
28815
- entries: volume.entries
28816
- });
28691
+ const known = input.ticketNumber;
28692
+ if (known !== void 0) {
28693
+ ensureTicketProvenanceVolume(known, input.cwd, input.home);
28694
+ const volume = await readTicketProvenance(known, input.cwd, input.home);
28695
+ writeTicketProvenanceHumanView({
28696
+ ticketNumber: known,
28697
+ cwd: input.cwd,
28698
+ ...input.home === void 0 ? {} : { home: input.home },
28699
+ entries: volume.entries
28700
+ });
28701
+ }
28817
28702
  const rawBlocks = loadSourceBlocks(input);
28818
28703
  const safeguarded = mechanicalSafeguardPipeline(rawBlocks);
28819
- const seen = await loadSeenEntryIdentities(input.ticketNumber, input.cwd, input.home);
28704
+ const seen = known === void 0 ? /* @__PURE__ */ new Set() : await loadSeenEntryIdentities(known, input.cwd, input.home);
28820
28705
  const fresh = safeguarded.filter(
28821
- (block) => !seen.has(blockEntryIdentity(input.ticketNumber, block))
28706
+ (block) => known === void 0 || !seen.has(blockEntryIdentity(known, block))
28822
28707
  );
28823
28708
  return {
28824
- ticketNumber: input.ticketNumber,
28709
+ ...known === void 0 ? {} : { ticketNumber: known },
28710
+ instruction: input.instruction,
28711
+ runDirectory: input.runDirectory,
28712
+ projectRoot: input.projectRoot,
28825
28713
  cwd: input.cwd,
28826
28714
  ...input.home === void 0 ? {} : { home: input.home },
28827
28715
  candidates: fresh.map((block, candidateIndex) => ({ ...block, candidateIndex }))
@@ -28859,7 +28747,7 @@ __export(diarist_run_exports, {
28859
28747
  runPublicDiarist: () => runPublicDiarist,
28860
28748
  runPublicDiaristResume: () => runPublicDiaristResume
28861
28749
  });
28862
- import { existsSync as existsSync10 } from "node:fs";
28750
+ import { existsSync as existsSync9 } from "node:fs";
28863
28751
  import { writeFile as writeFile7 } from "node:fs/promises";
28864
28752
  import { join as join26 } from "node:path";
28865
28753
  function withDiaristCatalogPath(prompt, sourcesPath) {
@@ -28886,22 +28774,24 @@ function buildDiaristTurnRequest(admitted, options, sourcesPath) {
28886
28774
  );
28887
28775
  }
28888
28776
  async function freezeDiaristSourceCatalog(admitted, env) {
28889
- if (admitted.ticketNumber === void 0) return void 0;
28890
28777
  const path = join26(admitted.runDirectory, DIARIST_SOURCE_CATALOG_FILE);
28891
- if (existsSync10(path)) {
28778
+ if (existsSync9(path)) {
28892
28779
  const identity = await readRoleRunIdentity(admitted.runDirectory);
28893
28780
  if (identity !== void 0 && identity.state !== "terminal") return path;
28894
28781
  }
28895
- const issueFace = await loadDiaristIssueFace({
28782
+ const issueFace = admitted.ticketNumber === void 0 ? void 0 : await loadDiaristIssueFace({
28896
28783
  ticketNumber: admitted.ticketNumber,
28897
28784
  projectRoot: admitted.projectRoot,
28898
28785
  home: env.home
28899
28786
  });
28900
28787
  const catalog = await prepareDiaristSourceCatalog({
28901
- ticketNumber: admitted.ticketNumber,
28788
+ ...admitted.ticketNumber === void 0 ? {} : { ticketNumber: admitted.ticketNumber },
28789
+ instruction: admitted.instruction,
28790
+ runDirectory: admitted.runDirectory,
28791
+ projectRoot: admitted.projectRoot,
28902
28792
  cwd: admitted.projectRoot,
28903
28793
  home: env.home,
28904
- issueFace,
28794
+ ...issueFace === void 0 ? {} : { issueFace },
28905
28795
  sessionCwds: [admitted.projectRoot, env.cwd]
28906
28796
  });
28907
28797
  await writeFile7(path, serializeDiaristSourceCatalog(catalog), "utf8");
@@ -28926,12 +28816,8 @@ async function runPublicDiarist(argv, env, io, parseDiaristArgv2) {
28926
28816
  throw error;
28927
28817
  }
28928
28818
  const projectRoot = parsed.project ?? env.cwd;
28929
- const reusedTicketNumber = await resolveDiaristSummonsTicketNumber({
28930
- instruction: parsed.instruction,
28931
- projectRoot,
28932
- home: env.home
28933
- });
28934
- if (reusedTicketNumber !== void 0) {
28819
+ const handoffTicket = env.boundTicketNumber;
28820
+ if (typeof handoffTicket === "number" && Number.isSafeInteger(handoffTicket) && handoffTicket >= 1) {
28935
28821
  const summons = {
28936
28822
  instruction: parsed.instruction,
28937
28823
  instructionEmpty: parsed.instruction.trim() === "",
@@ -28941,7 +28827,7 @@ async function runPublicDiarist(argv, env, io, parseDiaristArgv2) {
28941
28827
  home: env.home,
28942
28828
  projectRoot,
28943
28829
  role: "diarist",
28944
- ticketNumber: reusedTicketNumber,
28830
+ ticketNumber: handoffTicket,
28945
28831
  freshSummons: env.freshSummons,
28946
28832
  summons,
28947
28833
  resume: (runId, materials) => runPublicDiaristResume(
@@ -28973,6 +28859,9 @@ async function runPublicDiarist(argv, env, io, parseDiaristArgv2) {
28973
28859
  throw error;
28974
28860
  }
28975
28861
  await markRunAdmitted(admitted, env.principalAuthority);
28862
+ if (typeof handoffTicket === "number" && Number.isSafeInteger(handoffTicket) && handoffTicket >= 1) {
28863
+ await bindAdmittedTicketNumber(admitted, handoffTicket);
28864
+ }
28976
28865
  const turnProjection = {
28977
28866
  packageRoot: env.packageRoot,
28978
28867
  home: env.home,
@@ -29000,7 +28889,6 @@ async function runPublicDiarist(argv, env, io, parseDiaristArgv2) {
29000
28889
  request: turnRequest,
29001
28890
  adapters: diaristAdapters({
29002
28891
  beforeDispatch: async (admittedSeat) => {
29003
- await bindReusedTicketNumber(admittedSeat, reusedTicketNumber);
29004
28892
  const sourcesPath = await freezeDiaristSourceCatalog(admittedSeat, env);
29005
28893
  Object.assign(
29006
28894
  turnRequest,
@@ -29009,6 +28897,21 @@ async function runPublicDiarist(argv, env, io, parseDiaristArgv2) {
29009
28897
  }
29010
28898
  }),
29011
28899
  ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
28900
+ }).then(async (result2) => {
28901
+ if (admitted.ticketNumber === void 0 && result2.admitted !== void 0) {
28902
+ const roleOutcome = result2.terminal?.roleOutcome;
28903
+ if (roleOutcome !== void 0 && roleOutcome.kind === "accepted" && roleOutcome.status !== "escalate") {
28904
+ const facts = roleOutcome.decisiveFacts;
28905
+ const raw = typeof facts.ticketNumber === "number" ? facts.ticketNumber : typeof facts.sitian?.ticketNumber === "number" ? facts.sitian.ticketNumber : void 0;
28906
+ if (typeof raw === "number" && Number.isSafeInteger(raw) && raw >= 1) {
28907
+ admitted.ticketNumber = raw;
28908
+ if (result2.admitted.ticketNumber === void 0) {
28909
+ result2.admitted.ticketNumber = raw;
28910
+ }
28911
+ }
28912
+ }
28913
+ }
28914
+ return result2;
29012
28915
  });
29013
28916
  }
29014
28917
  async function runPublicDiaristResume(request, env, io) {
@@ -29046,9 +28949,9 @@ var init_diarist_run = __esm({
29046
28949
  init_engine_material();
29047
28950
  init_cli_errors();
29048
28951
  init_invocation();
29049
- init_seat_ticket_binding();
29050
28952
  init_post_admission();
29051
28953
  init_run_lifecycle();
28954
+ init_seat_ticket_binding();
29052
28955
  init_settlement();
29053
28956
  init_turn_request();
29054
28957
  DIARIST_SOURCE_CATALOG_FILE = "diarist-sources.json";
@@ -29069,12 +28972,7 @@ function buildCountersignTurnRequest(admitted, options) {
29069
28972
  options
29070
28973
  );
29071
28974
  }
29072
- async function runCountersignCourtDiaristStation(admitted, env, io) {
29073
- if (admitted.ticketNumber === void 0) return;
29074
- if (env.runCourtDiaristStation !== void 0) {
29075
- await env.runCourtDiaristStation(admitted);
29076
- return;
29077
- }
28975
+ async function invokeCourtDiarist(input, env, io) {
29078
28976
  const quietIo = {
29079
28977
  stdout() {
29080
28978
  },
@@ -29084,11 +28982,7 @@ async function runCountersignCourtDiaristStation(admitted, env, io) {
29084
28982
  };
29085
28983
  const { runPublicDiarist: runPublicDiarist2 } = await Promise.resolve().then(() => (init_diarist_run(), diarist_run_exports));
29086
28984
  const result2 = await runPublicDiarist2(
29087
- [
29088
- "--project",
29089
- admitted.projectRoot,
29090
- `\u6574\u7406 #${admitted.ticketNumber} \u7684\u672C\u6848\u4F9D\u636E\u3002`
29091
- ],
28985
+ ["--project", input.projectRoot, input.instruction],
29092
28986
  {
29093
28987
  home: env.home,
29094
28988
  agentDir: env.agentDir,
@@ -29103,17 +28997,60 @@ async function runCountersignCourtDiaristStation(admitted, env, io) {
29103
28997
  ...env.timeoutMs === void 0 ? {} : { timeoutMs: env.timeoutMs },
29104
28998
  ...env.credentials === void 0 ? {} : { credentials: env.credentials },
29105
28999
  ...env.correlationId === void 0 ? {} : { correlationId: env.correlationId },
29106
- ...env.signal === void 0 ? {} : { signal: env.signal }
29000
+ ...env.signal === void 0 ? {} : { signal: env.signal },
29001
+ // Typed handoff only — never derived from summons prose.
29002
+ ...input.boundTicketNumber === void 0 ? {} : { boundTicketNumber: input.boundTicketNumber }
29107
29003
  },
29108
29004
  quietIo,
29109
29005
  parseDiaristArgv
29110
29006
  );
29007
+ const roleOutcome = result2.terminal?.roleOutcome;
29008
+ if (roleOutcome !== void 0 && roleOutcome.kind !== "failure") {
29009
+ if (roleOutcome.status === "escalate") {
29010
+ const reason = typeof roleOutcome.decisiveFacts.reason === "string" ? roleOutcome.decisiveFacts.reason : "diarist escalated without reason";
29011
+ return { identity: { kind: "escalate", reason } };
29012
+ }
29013
+ }
29111
29014
  if (result2.exitCode !== 0) {
29112
- const detail = result2.terminal?.roleOutcome.kind === "failure" ? ` (roleOutcome=failure)` : "";
29015
+ const diagnostic = roleOutcome?.kind === "failure" ? roleOutcome.diagnostic : `exit ${result2.exitCode}`;
29016
+ return {
29017
+ identity: { kind: "unbound" },
29018
+ failedWithoutEscalate: {
29019
+ diagnostic: `court diarist station failed for ${input.failureLabel}: ${diagnostic}`
29020
+ }
29021
+ };
29022
+ }
29023
+ const asserted = result2.admitted?.ticketNumber;
29024
+ if (typeof asserted === "number" && Number.isSafeInteger(asserted) && asserted >= 1) {
29025
+ return { identity: { kind: "ticket", ticketNumber: asserted } };
29026
+ }
29027
+ return { identity: { kind: "unbound" } };
29028
+ }
29029
+ async function runCountersignCourtDiaristStation(admitted, env, io) {
29030
+ if (env.runCourtDiaristStation !== void 0) {
29031
+ await env.runCourtDiaristStation(admitted);
29032
+ return;
29033
+ }
29034
+ if (admitted.ticketNumber === void 0) return;
29035
+ const outcome = await invokeCourtDiarist(
29036
+ {
29037
+ instruction: `\u6574\u7406 #${admitted.ticketNumber} \u7684\u672C\u6848\u4F9D\u636E\u3002`,
29038
+ projectRoot: admitted.projectRoot,
29039
+ failureLabel: `ticket #${admitted.ticketNumber}`,
29040
+ // Refresh holds a typed key — hand it off so freeze loads issue face.
29041
+ boundTicketNumber: admitted.ticketNumber
29042
+ },
29043
+ env,
29044
+ io
29045
+ );
29046
+ if (outcome.identity.kind === "escalate") {
29113
29047
  throw new Error(
29114
- `court diarist station failed for ticket #${admitted.ticketNumber}: exit ${result2.exitCode}${detail}`
29048
+ `court diarist station escalated (cannot identify court target): ${outcome.identity.reason}`
29115
29049
  );
29116
29050
  }
29051
+ if (outcome.failedWithoutEscalate !== void 0) {
29052
+ throw new Error(outcome.failedWithoutEscalate.diagnostic);
29053
+ }
29117
29054
  }
29118
29055
  async function runPublicCountersign(argv, env, io, parseCountersignArgv2) {
29119
29056
  let parsed;
@@ -29126,33 +29063,6 @@ async function runPublicCountersign(argv, env, io, parseCountersignArgv2) {
29126
29063
  }
29127
29064
  throw error;
29128
29065
  }
29129
- const projectRoot = parsed.project ?? env.cwd;
29130
- const reusedTicketNumber = await resolveKnownTicketNumber({
29131
- instruction: parsed.instruction,
29132
- projectRoot,
29133
- home: env.home
29134
- });
29135
- if (reusedTicketNumber !== void 0) {
29136
- const summons = {
29137
- instruction: parsed.instruction,
29138
- instructionEmpty: parsed.instruction.trim() === "",
29139
- attachmentPaths: parsed.attachmentPaths
29140
- };
29141
- const resumed = await tryResumeSameTicketSeatRun({
29142
- home: env.home,
29143
- projectRoot,
29144
- role: "countersign",
29145
- ticketNumber: reusedTicketNumber,
29146
- freshSummons: env.freshSummons,
29147
- summons,
29148
- resume: (runId, materials) => runPublicCountersignResume(
29149
- { runId, ...materials === void 0 ? {} : { summons: materials } },
29150
- env,
29151
- io
29152
- )
29153
- });
29154
- if (resumed !== void 0) return resumed;
29155
- }
29156
29066
  let admitted;
29157
29067
  try {
29158
29068
  admitted = await admitCountersignInvocation({
@@ -29174,6 +29084,80 @@ async function runPublicCountersign(argv, env, io, parseCountersignArgv2) {
29174
29084
  throw error;
29175
29085
  }
29176
29086
  await markRunAdmitted(admitted, env.principalAuthority);
29087
+ let typedTicket;
29088
+ let identityDiaristRan = false;
29089
+ if (env.runCourtDiaristStation === void 0) {
29090
+ const outcome = await invokeCourtDiarist(
29091
+ {
29092
+ instruction: parsed.instruction,
29093
+ projectRoot: admitted.projectRoot,
29094
+ failureLabel: "unbound summons"
29095
+ },
29096
+ env,
29097
+ io
29098
+ );
29099
+ identityDiaristRan = true;
29100
+ if (outcome.identity.kind === "escalate") {
29101
+ return await presentControlledFailure2(
29102
+ admitted,
29103
+ {
29104
+ timedOut: false,
29105
+ code: null,
29106
+ stderr: "",
29107
+ thrown: new Error(
29108
+ `court diarist station escalated (cannot identify court target): ${outcome.identity.reason}`
29109
+ )
29110
+ },
29111
+ countersignAdapters(),
29112
+ env.principalAuthority,
29113
+ io
29114
+ );
29115
+ }
29116
+ if (outcome.failedWithoutEscalate !== void 0) {
29117
+ return await presentControlledFailure2(
29118
+ admitted,
29119
+ {
29120
+ timedOut: false,
29121
+ code: null,
29122
+ stderr: "",
29123
+ thrown: new Error(outcome.failedWithoutEscalate.diagnostic)
29124
+ },
29125
+ countersignAdapters(),
29126
+ env.principalAuthority,
29127
+ io
29128
+ );
29129
+ }
29130
+ if (outcome.identity.kind === "ticket") {
29131
+ typedTicket = outcome.identity.ticketNumber;
29132
+ const summons = {
29133
+ instruction: parsed.instruction,
29134
+ instructionEmpty: parsed.instruction.trim() === "",
29135
+ attachmentPaths: parsed.attachmentPaths
29136
+ };
29137
+ const resumed = await tryResumeSameTicketSeatRun({
29138
+ home: env.home,
29139
+ projectRoot: admitted.projectRoot,
29140
+ role: "countersign",
29141
+ ticketNumber: typedTicket,
29142
+ freshSummons: env.freshSummons,
29143
+ summons,
29144
+ resume: async (runId, materials) => {
29145
+ await markRunTerminal(admitted.runDirectory);
29146
+ return await runPublicCountersignResume(
29147
+ {
29148
+ runId,
29149
+ ...materials === void 0 ? {} : { summons: materials }
29150
+ },
29151
+ env,
29152
+ io
29153
+ );
29154
+ }
29155
+ });
29156
+ if (resumed !== void 0) {
29157
+ return resumed;
29158
+ }
29159
+ }
29160
+ }
29177
29161
  const turnProjection = {
29178
29162
  packageRoot: env.packageRoot,
29179
29163
  home: env.home,
@@ -29201,12 +29185,16 @@ async function runPublicCountersign(argv, env, io, parseCountersignArgv2) {
29201
29185
  request: turnRequest,
29202
29186
  adapters: countersignAdapters({
29203
29187
  beforeDispatch: async (admittedSeat) => {
29204
- await bindReusedTicketNumber(admittedSeat, reusedTicketNumber);
29188
+ if (!identityDiaristRan) {
29189
+ await runCountersignCourtDiaristStation(admittedSeat, env, io);
29190
+ } else if (typedTicket !== void 0) {
29191
+ await bindAdmittedTicketNumber(admittedSeat, typedTicket);
29192
+ await runCountersignCourtDiaristStation(admittedSeat, env, io);
29193
+ }
29205
29194
  Object.assign(
29206
29195
  turnRequest,
29207
29196
  buildCountersignTurnRequest(admittedSeat, turnProjection)
29208
29197
  );
29209
- await runCountersignCourtDiaristStation(admittedSeat, env, io);
29210
29198
  }
29211
29199
  }),
29212
29200
  ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
@@ -29259,9 +29247,9 @@ var init_countersign_run = __esm({
29259
29247
  init_engine_material();
29260
29248
  init_cli_errors();
29261
29249
  init_invocation();
29262
- init_seat_ticket_binding();
29263
29250
  init_post_admission();
29264
29251
  init_run_lifecycle();
29252
+ init_seat_ticket_binding();
29265
29253
  init_settlement();
29266
29254
  init_turn_request();
29267
29255
  }
@@ -29579,12 +29567,7 @@ async function runPublicFixer(argv, env, io, parseFixerArgv2) {
29579
29567
  })
29580
29568
  }
29581
29569
  }),
29582
- adapters: {
29583
- ...fixerAdapters(env.packageRoot, methodMaterial),
29584
- beforeDispatch: async (admittedSeat) => {
29585
- await resolveSeatTicketBinding(admittedSeat, env);
29586
- }
29587
- },
29570
+ adapters: fixerAdapters(env.packageRoot, methodMaterial),
29588
29571
  ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
29589
29572
  });
29590
29573
  }
@@ -29637,7 +29620,6 @@ var init_fixer_run = __esm({
29637
29620
  init_method_skill();
29638
29621
  init_cli_errors();
29639
29622
  init_invocation();
29640
- init_seat_ticket_binding();
29641
29623
  init_run_lifecycle();
29642
29624
  init_settlement();
29643
29625
  init_turn_request();
@@ -29646,7 +29628,7 @@ var init_fixer_run = __esm({
29646
29628
  });
29647
29629
 
29648
29630
  // src/public-cli/notary-run.ts
29649
- import { existsSync as existsSync11 } from "node:fs";
29631
+ import { existsSync as existsSync10 } from "node:fs";
29650
29632
  function buildNotaryTurnRequest(admitted, options) {
29651
29633
  return projectRoleTurnRequest(
29652
29634
  admitted,
@@ -29795,7 +29777,7 @@ async function runPublicNotaryResume(request, env, io) {
29795
29777
  env
29796
29778
  );
29797
29779
  const candidatePath = gateSubmissionCandidatePath(admitted.sourceRunPath);
29798
- const prompt = existsSync11(candidatePath) ? appendResumeMaterialReread(projection.continuation.prompt, candidatePath) : projection.continuation.prompt;
29780
+ const prompt = existsSync10(candidatePath) ? appendResumeMaterialReread(projection.continuation.prompt, candidatePath) : projection.continuation.prompt;
29799
29781
  return buildNotaryTurnRequest(admitted, {
29800
29782
  ...projection,
29801
29783
  continuation: { kind: "resume", prompt }
@@ -29845,11 +29827,6 @@ async function runPublicInspector(argv, env, io, parseInspectorArgv2) {
29845
29827
  throw error;
29846
29828
  }
29847
29829
  const projectRoot = parsed.project ?? env.cwd;
29848
- const reusedTicketNumber = await resolveKnownTicketNumber({
29849
- instruction: parsed.instruction,
29850
- projectRoot,
29851
- home: env.home
29852
- });
29853
29830
  const parentRunPath = parentRunPathFromGatePointerInstruction(parsed.instruction);
29854
29831
  if (parentRunPath !== void 0) {
29855
29832
  const summons = {
@@ -29915,11 +29892,7 @@ async function runPublicInspector(argv, env, io, parseInspectorArgv2) {
29915
29892
  env,
29916
29893
  io,
29917
29894
  request: turnRequest,
29918
- adapters: inspectorAdapters({
29919
- beforeDispatch: async (admittedSeat) => {
29920
- await bindReusedTicketNumber(admittedSeat, reusedTicketNumber);
29921
- }
29922
- }),
29895
+ adapters: inspectorAdapters(),
29923
29896
  ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
29924
29897
  });
29925
29898
  }
@@ -30051,12 +30024,7 @@ async function runPublicJudge(argv, env, io, parseJudgeArgv2) {
30051
30024
  })
30052
30025
  }
30053
30026
  }),
30054
- adapters: {
30055
- ...judgeAdapters(),
30056
- beforeDispatch: async (admittedSeat) => {
30057
- await resolveSeatTicketBinding(admittedSeat, env);
30058
- }
30059
- },
30027
+ adapters: judgeAdapters(),
30060
30028
  ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
30061
30029
  });
30062
30030
  }
@@ -30080,7 +30048,6 @@ var init_judge_run = __esm({
30080
30048
  init_engine_material();
30081
30049
  init_cli_errors();
30082
30050
  init_invocation();
30083
- init_seat_ticket_binding();
30084
30051
  init_run_lifecycle();
30085
30052
  init_settlement();
30086
30053
  init_turn_request();
@@ -33770,7 +33737,7 @@ var init_cli = __esm({
33770
33737
  });
33771
33738
 
33772
33739
  // src/public-cli/main.ts
33773
- import { existsSync as existsSync12 } from "node:fs";
33740
+ import { existsSync as existsSync11 } from "node:fs";
33774
33741
  import { dirname as dirname16, join as join33 } from "node:path";
33775
33742
  import { fileURLToPath as fileURLToPath2 } from "node:url";
33776
33743
 
@@ -33861,7 +33828,7 @@ function linkPackage(packageRoot2, name, targetDir) {
33861
33828
  var here = dirname16(fileURLToPath2(import.meta.url));
33862
33829
  function resolvePackageRoot(binDir) {
33863
33830
  const canonical = join33(binDir, "..", "..");
33864
- if (existsSync12(join33(canonical, "package.json"))) {
33831
+ if (existsSync11(join33(canonical, "package.json"))) {
33865
33832
  return canonical;
33866
33833
  }
33867
33834
  return binDir;