@akagilnc/pi-workflow-roles 0.1.2383 → 0.1.2397

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.
@@ -14384,13 +14384,6 @@ function validateNotaryOutput(value) {
14384
14384
  throw new Error("Notary output has no recognized execution discriminator");
14385
14385
  }
14386
14386
  const status = seatFallbackBaseStatus(statusRaw);
14387
- if (status === "incomplete") {
14388
- const reason = value.reason;
14389
- if (typeof reason !== "string" || reason.trim() === "") {
14390
- throw new Error("Notary incomplete requires a non-empty reason");
14391
- }
14392
- return structuredClone(value);
14393
- }
14394
14387
  if (status === "bounce") {
14395
14388
  const clone = structuredClone(value);
14396
14389
  if (clone.disposition === void 0) clone.disposition = "rewrite";
@@ -14417,9 +14410,6 @@ function notaryDecisiveFacts(output) {
14417
14410
  if (status === "bounce") {
14418
14411
  facts.disposition = "rewrite";
14419
14412
  }
14420
- if (status === "incomplete") {
14421
- facts.reason = output.reason;
14422
- }
14423
14413
  return facts;
14424
14414
  }
14425
14415
  var NOTARY_OUTPUT_TOOL_NAME, NOTARY_FIXED_KICKOFF, notaryOutputSchema;
@@ -14434,13 +14424,10 @@ var init_notary_contracts = __esm({
14434
14424
  notaryOutputSchema = openToolObject(
14435
14425
  typebox_exports.Object({
14436
14426
  status: typebox_exports.Unknown({
14437
- description: "pass | bounce | incomplete \u2014 guidance, not a schema gate."
14427
+ description: "pass | bounce \u2014 guidance, not a schema gate."
14438
14428
  }),
14439
14429
  findings: typebox_exports.Unknown({
14440
14430
  description: "string[] findings retained with pass or bounce."
14441
- }),
14442
- reason: typebox_exports.Unknown({
14443
- description: "Why the notary decision is incomplete."
14444
14431
  })
14445
14432
  })
14446
14433
  );
@@ -15444,7 +15431,7 @@ function validateAcceptedDetails(toolName, details) {
15444
15431
  [COLLECTOR_OUTPUT_TOOL]: [],
15445
15432
  [DOCTOR_OUTPUT_TOOL_NAME]: ["completed", "refused"],
15446
15433
  [MERGER_OUTPUT_TOOL_NAME]: ["completed", "escalate"],
15447
- [NOTARY_OUTPUT_TOOL_NAME]: ["pass", "bounce", "incomplete"]
15434
+ [NOTARY_OUTPUT_TOOL_NAME]: ["pass", "bounce"]
15448
15435
  };
15449
15436
  const collectorDiscriminator = toolName === COLLECTOR_OUTPUT_TOOL && Array.isArray(candidate?.groups);
15450
15437
  const baseDiscriminator = typeof discriminator === "string" ? seatFallbackBaseStatus(discriminator) : discriminator;
@@ -19893,9 +19880,6 @@ var init_command_renderer = __esm({
19893
19880
  function encodeTerminalField(value) {
19894
19881
  return JSON.stringify(value);
19895
19882
  }
19896
- function jsonSafeComplianceCandidate(value) {
19897
- return value === void 0 ? JSON_SAFE_UNDEFINED_ARGUMENT : value;
19898
- }
19899
19883
  function isLawfulTypedTerminalOutcome(outcome) {
19900
19884
  return outcome.kind === "accepted" || outcome.kind === "audit_escalation" || outcome.kind === "no_receipt";
19901
19885
  }
@@ -19919,31 +19903,6 @@ function buildResidualIncompleteTerminalOutcome(input) {
19919
19903
  }
19920
19904
  };
19921
19905
  }
19922
- function buildAuditIncompleteTerminalOutcome(input) {
19923
- const roleCandidate = jsonSafeComplianceCandidate(input.roleCandidate);
19924
- const audit = {
19925
- ...input.audit,
19926
- candidate: jsonSafeComplianceCandidate(input.audit.candidate)
19927
- };
19928
- return {
19929
- kind: "audit_incomplete",
19930
- role: input.role,
19931
- status: "audit-incomplete",
19932
- decision: "no-usable-decision",
19933
- roleCandidate,
19934
- audit,
19935
- acceptedReceipt: false,
19936
- decisiveFacts: {
19937
- decision: "no-usable-decision",
19938
- roleCandidate,
19939
- auditCandidate: audit.candidate,
19940
- auditObservation: audit.observation,
19941
- observationKind: audit.observation.kind,
19942
- observationType: audit.observation.kind === "non-object-arguments" ? audit.observation.type : audit.observation.kind === "object-status-unreadable" ? audit.observation.status : audit.observation.kind === "missing-subject" ? audit.observation.subject : audit.observation.kind,
19943
- acceptedReceipt: false
19944
- }
19945
- };
19946
- }
19947
19906
  function redactExactRunId(text, runId) {
19948
19907
  if (runId.length === 0) return text;
19949
19908
  if (!text.includes(runId)) return text;
@@ -20026,15 +19985,11 @@ function formatTerminalResult(result2) {
20026
19985
  return `${lines.join("\n")}
20027
19986
  `;
20028
19987
  }
20029
- var JSON_SAFE_UNDEFINED_ARGUMENT, REDACTED_RUN_ID_TOKEN;
19988
+ var REDACTED_RUN_ID_TOKEN;
20030
19989
  var init_terminal = __esm({
20031
19990
  "src/public-cli/terminal.ts"() {
20032
19991
  "use strict";
20033
19992
  init_command_renderer();
20034
- JSON_SAFE_UNDEFINED_ARGUMENT = Object.freeze({
20035
- kind: "json-safe-sentinel",
20036
- type: "undefined"
20037
- });
20038
19993
  REDACTED_RUN_ID_TOKEN = "[run-id]";
20039
19994
  }
20040
19995
  });
@@ -20155,8 +20110,8 @@ function extractSessionToolIntervals(rows) {
20155
20110
  if (resultTimestamp === void 0 || resultTimestamp.length === 0) {
20156
20111
  throw new Error(`toolResult ${message.toolCallId} missing timestamp`);
20157
20112
  }
20158
- const open5 = openById.get(message.toolCallId);
20159
- if (open5 === void 0) {
20113
+ const open4 = openById.get(message.toolCallId);
20114
+ if (open4 === void 0) {
20160
20115
  const toolName = typeof message.toolName === "string" && message.toolName.length > 0 ? message.toolName : "unknown";
20161
20116
  order.push({
20162
20117
  toolCallId: message.toolCallId,
@@ -20166,10 +20121,10 @@ function extractSessionToolIntervals(rows) {
20166
20121
  });
20167
20122
  continue;
20168
20123
  }
20169
- if (open5.endedAt !== void 0) {
20124
+ if (open4.endedAt !== void 0) {
20170
20125
  throw new Error(`duplicate toolResult for toolCallId ${message.toolCallId}`);
20171
20126
  }
20172
- open5.endedAt = resultTimestamp;
20127
+ open4.endedAt = resultTimestamp;
20173
20128
  }
20174
20129
  }
20175
20130
  return order.map((interval) => {
@@ -20293,7 +20248,6 @@ async function classifyAuditorVolume(filePath) {
20293
20248
  const findings = asStringFindings(call.args?.findings);
20294
20249
  const findingsCount = findings.length;
20295
20250
  if (DISPATCH_TOOLS.has(call.toolName)) {
20296
- if (status === "incomplete") return void 0;
20297
20251
  if (status !== "dispatch") {
20298
20252
  throw new Error(
20299
20253
  `accepted dispatch receipt has non-dispatch status ${JSON.stringify(status)} in ${filePath}`
@@ -20415,16 +20369,10 @@ var init_session_opening_materials = __esm({
20415
20369
  });
20416
20370
 
20417
20371
  // src/auditor-soul.ts
20418
- var AUDITOR_SOUL_ROLES;
20419
20372
  var init_auditor_soul = __esm({
20420
20373
  "src/auditor-soul.ts"() {
20421
20374
  "use strict";
20422
20375
  init_session_opening_materials();
20423
- AUDITOR_SOUL_ROLES = [
20424
- "judge",
20425
- "reviewer",
20426
- "doctor"
20427
- ];
20428
20376
  }
20429
20377
  });
20430
20378
 
@@ -20519,21 +20467,44 @@ function readListField(value) {
20519
20467
  return Array.isArray(value) ? value : value === void 0 ? [] : [value];
20520
20468
  }
20521
20469
  function readComplianceCandidate(arguments_, usage) {
20522
- if (typeof arguments_ !== "object" || arguments_ === null || Array.isArray(arguments_)) return { status: "audit-incomplete", observation: { kind: "non-object-arguments", type: arguments_ === null ? "null" : Array.isArray(arguments_) ? "array" : typeof arguments_ }, candidate: arguments_, ...usage === void 0 ? {} : { usage } };
20470
+ if (typeof arguments_ !== "object" || arguments_ === null || Array.isArray(arguments_)) {
20471
+ throw new ComplianceCandidateUnreadableError(
20472
+ { kind: "non-object-arguments", type: arguments_ === null ? "null" : Array.isArray(arguments_) ? "array" : typeof arguments_ },
20473
+ arguments_,
20474
+ usage
20475
+ );
20476
+ }
20523
20477
  const args = arguments_;
20524
20478
  const status = args.status;
20525
20479
  if (status === "pass") return { status, ...usage === void 0 ? {} : { usage } };
20526
20480
  if (status === "revise") return { status, violations: readListField(args.violations), ...usage === void 0 ? {} : { usage } };
20527
20481
  if (status === "escalate") return { status, ...Object.hasOwn(args, "conflicts") ? { conflicts: args.conflicts } : {}, ...Object.hasOwn(args, "decisionGate") ? { decisionGate: args.decisionGate } : {}, ...usage === void 0 ? {} : { usage } };
20528
- return { status: "audit-incomplete", observation: { kind: "object-status-unreadable", status: status === void 0 ? "missing" : "unknown" }, candidate: arguments_, ...usage === void 0 ? {} : { usage } };
20482
+ throw new ComplianceCandidateUnreadableError(
20483
+ { kind: "object-status-unreadable", status: status === void 0 ? "missing" : "unknown" },
20484
+ arguments_,
20485
+ usage
20486
+ );
20529
20487
  }
20530
- var nonblank2, decisionGateSchema, complianceDecisionSchema, COMPLIANCE_RESPONSE_ENTRY_TYPE, AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE, AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE;
20488
+ var ComplianceCandidateUnreadableError, nonblank2, decisionGateSchema, complianceDecisionSchema, COMPLIANCE_RESPONSE_ENTRY_TYPE, AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE, AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE;
20531
20489
  var init_compliance_transport = __esm({
20532
20490
  "src/compliance-transport.ts"() {
20533
20491
  "use strict";
20534
20492
  init_build();
20535
20493
  init_evidence_child_executor();
20536
20494
  init_auditor_dossier_tool();
20495
+ ComplianceCandidateUnreadableError = class extends Error {
20496
+ observation;
20497
+ candidate;
20498
+ usage;
20499
+ constructor(observation, candidate, usage) {
20500
+ const detail = observation.kind === "non-object-arguments" ? `${observation.kind}:${observation.type}` : observation.kind === "object-status-unreadable" ? `${observation.kind}:${observation.status}` : observation.kind === "missing-subject" ? `${observation.kind}:${observation.subject}` : observation.kind;
20501
+ super(`Compliance candidate unreadable: ${detail}`);
20502
+ this.name = "ComplianceCandidateUnreadableError";
20503
+ this.observation = observation;
20504
+ this.candidate = candidate;
20505
+ if (usage !== void 0) this.usage = usage;
20506
+ }
20507
+ };
20537
20508
  nonblank2 = typebox_exports.String({ minLength: 1, pattern: "\\S" });
20538
20509
  decisionGateSchema = typebox_exports.Object({ question: nonblank2, options: typebox_exports.Array(nonblank2, { minItems: 1 }) }, { additionalProperties: false });
20539
20510
  complianceDecisionSchema = typebox_exports.Object({ status: typebox_exports.Unknown({ description: "Auditor decision status." }), violations: typebox_exports.Array(nonblank2, { description: "Observed compliance violations." }), conflicts: typebox_exports.Array(nonblank2, { description: "Unresolved authority or execution conflicts." }), decisionGate: typebox_exports.Union([decisionGateSchema, typebox_exports.Null()], { description: "Escalation question and available options." }) }, { additionalProperties: true, required: [] });
@@ -20663,11 +20634,16 @@ var init_work_subject_identity = __esm({
20663
20634
  });
20664
20635
 
20665
20636
  // src/navigator-invocation-identity.ts
20666
- function isNavigatorInfrastructureFailureFact(value) {
20637
+ function buildNavigatorInfrastructureFailureFact() {
20638
+ return {
20639
+ kind: NAVIGATOR_INFRASTRUCTURE_FAILURE_KIND,
20640
+ source: "shared-role-lifecycle",
20641
+ reasonCode: "host_failure"
20642
+ };
20643
+ }
20644
+ function hasNavigatorInfrastructureFailureBase(value) {
20667
20645
  if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
20668
20646
  const record4 = value;
20669
- const keys = Object.keys(record4);
20670
- if (keys.length !== NAVIGATOR_INFRASTRUCTURE_FAILURE_KEYS.length) return false;
20671
20647
  for (const key of NAVIGATOR_INFRASTRUCTURE_FAILURE_KEYS) {
20672
20648
  if (!Object.hasOwn(record4, key)) return false;
20673
20649
  }
@@ -20698,7 +20674,8 @@ function parseInvocationMarkerIdentity(data) {
20698
20674
  function classifyPackagedRoleTerminalResult(message) {
20699
20675
  if (typeof message.toolName !== "string") return { kind: "nonterminal" };
20700
20676
  if (!PACKAGED_ROLE_OUTPUT_TOOLS.has(message.toolName)) return { kind: "nonterminal" };
20701
- const infraFact = isNavigatorInfrastructureFailureFact(message.details) ? message.details : void 0;
20677
+ const hasInfraBase = hasNavigatorInfrastructureFailureBase(message.details);
20678
+ const infraFact = hasInfraBase ? buildNavigatorInfrastructureFailureFact() : void 0;
20702
20679
  if (message.isError === true) {
20703
20680
  if (infraFact === void 0) return { kind: "nonterminal" };
20704
20681
  return { kind: "infrastructure", fact: infraFact };
@@ -20805,8 +20782,7 @@ var init_navigator_invocation_identity = __esm({
20805
20782
 
20806
20783
  // src/public-cli/settlement.ts
20807
20784
  import { randomUUID } from "node:crypto";
20808
- import { constants as fsConstants } from "node:fs";
20809
- import { appendFile, lstat as lstat4, mkdir as mkdir3, open as open2, readFile as readFile10, readdir as readdir4, writeFile as writeFile5 } from "node:fs/promises";
20785
+ import { appendFile, readFile as readFile10, readdir as readdir4, writeFile as writeFile5 } from "node:fs/promises";
20810
20786
  import { dirname as dirname7, join as join13 } from "node:path";
20811
20787
  function isChildDiagnosticFloodLine(line2) {
20812
20788
  if (/^at\s+/.test(line2)) return true;
@@ -21110,7 +21086,7 @@ async function readBoundEvidenceChildKnownFailure(sessionFile) {
21110
21086
  }
21111
21087
  return void 0;
21112
21088
  }
21113
- async function readBoundAuditorKnownFailure(sessionFile) {
21089
+ async function loadBoundAuditorVolumes(sessionFile) {
21114
21090
  let parentEntries;
21115
21091
  try {
21116
21092
  parentEntries = await readBoundSessionEntries(sessionFile);
@@ -21147,7 +21123,7 @@ async function readBoundAuditorKnownFailure(sessionFile) {
21147
21123
  if (isMissingPathError2(error)) return void 0;
21148
21124
  throw sessionReadFailure(error, "failed to read bound auditor session directory");
21149
21125
  }
21150
- const validAuditorFiles = [];
21126
+ const valid = [];
21151
21127
  for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
21152
21128
  let entries;
21153
21129
  try {
@@ -21162,9 +21138,17 @@ async function readBoundAuditorKnownFailure(sessionFile) {
21162
21138
  const attemptEntryId = typeof bindingParent?.attemptEntryId === "string" ? bindingParent.attemptEntryId : void 0;
21163
21139
  const attemptEntryIndex = attemptEntryId === void 0 ? -1 : parentEntries.findIndex((entry) => entry.id === attemptEntryId);
21164
21140
  if (bindingParent?.sessionId !== parentId || bindingParent.sessionFile !== sessionFile || attemptEntryIndex < latestParentUserIndex) continue;
21165
- validAuditorFiles.push({ file, entries, ...attemptEntryId === void 0 ? {} : { attemptEntryId } });
21141
+ valid.push({
21142
+ entries,
21143
+ parentId,
21144
+ sessionFile,
21145
+ ...attemptEntryId === void 0 ? {} : { attemptEntryId }
21146
+ });
21166
21147
  }
21167
- for (const { entries, attemptEntryId } of validAuditorFiles) {
21148
+ return valid;
21149
+ }
21150
+ function complianceFailureFromAuditorVolumes(volumes) {
21151
+ for (const { entries, attemptEntryId, parentId, sessionFile } of volumes) {
21168
21152
  const stop = extractSessionProviderStop(entries);
21169
21153
  if (stop === void 0) continue;
21170
21154
  for (let i = entries.length - 1; i >= 0; i -= 1) {
@@ -21185,7 +21169,10 @@ async function readBoundAuditorKnownFailure(sessionFile) {
21185
21169
  };
21186
21170
  }
21187
21171
  }
21188
- for (const { entries } of validAuditorFiles) {
21172
+ return void 0;
21173
+ }
21174
+ function providerStopFallbackFromAuditorVolumes(volumes) {
21175
+ for (const { entries } of volumes) {
21189
21176
  const stop = extractSessionProviderStop(entries);
21190
21177
  if (stop === void 0) continue;
21191
21178
  const primary = knownFailureFromProviderStop(stop);
@@ -21199,6 +21186,16 @@ async function readBoundAuditorKnownFailure(sessionFile) {
21199
21186
  }
21200
21187
  return void 0;
21201
21188
  }
21189
+ async function readBoundAuditorComplianceFailure(sessionFile) {
21190
+ const volumes = await loadBoundAuditorVolumes(sessionFile);
21191
+ if (volumes === void 0) return void 0;
21192
+ return complianceFailureFromAuditorVolumes(volumes);
21193
+ }
21194
+ async function readBoundAuditorProviderStopFallback(sessionFile) {
21195
+ const volumes = await loadBoundAuditorVolumes(sessionFile);
21196
+ if (volumes === void 0) return void 0;
21197
+ return providerStopFallbackFromAuditorVolumes(volumes);
21198
+ }
21202
21199
  function typedFailedTerminatingToolKnownFailure(entries) {
21203
21200
  let attemptStart = 0;
21204
21201
  for (let i = entries.length - 1; i >= 0; i -= 1) {
@@ -21217,11 +21214,12 @@ function typedFailedTerminatingToolKnownFailure(entries) {
21217
21214
  if (boundRoleToolCallForResult(attemptEntries, i, message, message.toolName) === void 0) continue;
21218
21215
  const textPart = Array.isArray(message.content) ? message.content.find((part) => isRecord8(part) && part.type === "text" && typeof part.text === "string") : void 0;
21219
21216
  const diagnostic = isRecord8(textPart) ? textPart.text : void 0;
21217
+ const details = isRecord8(message.details) ? message.details : classification.fact;
21220
21218
  return {
21221
21219
  cause: "output",
21222
21220
  identity: { name: message.toolName, code: message.toolCallId },
21223
21221
  ...typeof diagnostic === "string" && diagnostic.trim() !== "" ? { diagnostic } : {},
21224
- details: classification.fact
21222
+ details
21225
21223
  };
21226
21224
  }
21227
21225
  return void 0;
@@ -21249,8 +21247,8 @@ async function resolveAuditedRunnerFailureResolution(input) {
21249
21247
  }
21250
21248
  }
21251
21249
  try {
21252
- const auditorFailure = await readBoundAuditorKnownFailure(input.sessionFile);
21253
- if (auditorFailure !== void 0) return resolutionOf(auditorFailure);
21250
+ const auditorCompliance = await readBoundAuditorComplianceFailure(input.sessionFile);
21251
+ if (auditorCompliance !== void 0) return resolutionOf(auditorCompliance);
21254
21252
  } catch (error) {
21255
21253
  const failure = sessionReadFailure(error, "failed to recover bound auditor failure");
21256
21254
  return resolutionOf({
@@ -21274,6 +21272,17 @@ async function resolveAuditedRunnerFailureResolution(input) {
21274
21272
  });
21275
21273
  }
21276
21274
  }
21275
+ try {
21276
+ const auditorStop = await readBoundAuditorProviderStopFallback(input.sessionFile);
21277
+ if (auditorStop !== void 0) return resolutionOf(auditorStop);
21278
+ } catch (error) {
21279
+ const failure = sessionReadFailure(error, "failed to recover bound auditor provider stop");
21280
+ return resolutionOf({
21281
+ cause: "session",
21282
+ identity: thrownIdentity(failure),
21283
+ diagnostic: failure.message || failure.name
21284
+ });
21285
+ }
21277
21286
  try {
21278
21287
  const evidenceChildFailure = await readBoundEvidenceChildKnownFailure(input.sessionFile);
21279
21288
  if (evidenceChildFailure !== void 0) return resolutionOf(evidenceChildFailure);
@@ -21679,29 +21688,6 @@ function assertCollectorReceiptMatchesAdmitted(receipt, admitted) {
21679
21688
  );
21680
21689
  }
21681
21690
  }
21682
- function isComplianceAuditIncomplete(value) {
21683
- if (!isRecord8(value) || value.status !== "audit-incomplete") return false;
21684
- const observation = value.observation;
21685
- if (!isRecord8(observation)) return false;
21686
- if (observation.kind === "missing-dossier") return true;
21687
- if (observation.kind === "missing-subject") {
21688
- return typeof observation.subject === "string" && observation.subject.length > 0;
21689
- }
21690
- if (observation.kind === "object-status-unreadable") {
21691
- return observation.status === "missing" || observation.status === "unknown";
21692
- }
21693
- return observation.kind === "non-object-arguments" && [
21694
- "null",
21695
- "array",
21696
- "undefined",
21697
- "string",
21698
- "number",
21699
- "boolean",
21700
- "bigint",
21701
- "symbol",
21702
- "function"
21703
- ].includes(observation.type);
21704
- }
21705
21691
  function auditToolNameForRole(role) {
21706
21692
  switch (role) {
21707
21693
  case "judge":
@@ -21712,16 +21698,6 @@ function auditToolNameForRole(role) {
21712
21698
  return DOCTOR_AUDIT_TOOL_NAME;
21713
21699
  }
21714
21700
  }
21715
- function outputToolNameForAuditedRole(role) {
21716
- switch (role) {
21717
- case "judge":
21718
- return JUDGE_OUTPUT_TOOL_NAME;
21719
- case "reviewer":
21720
- return REVIEWER_OUTPUT_TOOL_NAME;
21721
- case "doctor":
21722
- return DOCTOR_OUTPUT_TOOL_NAME;
21723
- }
21724
- }
21725
21701
  function boundRoleToolCallForResult(entries, resultIndex, message, outputToolName) {
21726
21702
  const callId = message.toolCallId;
21727
21703
  if (typeof callId !== "string" || callId.trim() === "") return void 0;
@@ -21816,10 +21792,6 @@ function isUnboundAuditEscalationFace(details) {
21816
21792
  const kind = safelyRead(details, "kind");
21817
21793
  return kind.readable && kind.value === "audit_escalation";
21818
21794
  }
21819
- function auditIncompleteFromCandidate(candidate) {
21820
- const decision = readComplianceCandidate(candidate);
21821
- return decision.status === "audit-incomplete" ? decision : void 0;
21822
- }
21823
21795
  function boundRetainedAuditResponse(entries, callIndex, resultIndex, auditToolName) {
21824
21796
  const matches = [];
21825
21797
  for (let index = callIndex + 1; index < resultIndex; index += 1) {
@@ -21838,92 +21810,6 @@ function boundRetainedAuditResponse(entries, callIndex, resultIndex, auditToolNa
21838
21810
  }
21839
21811
  return matches.length === 1 ? matches[0] : void 0;
21840
21812
  }
21841
- function extractComplianceAuditIncompleteRoleOutcome(entries, role, outputToolName) {
21842
- if (outputToolName !== outputToolNameForAuditedRole(role)) return void 0;
21843
- const auditToolName = auditToolNameForRole(role);
21844
- for (let index = entries.length - 1; index >= 0; index -= 1) {
21845
- const message = entries[index]?.message;
21846
- if (entries[index]?.type !== "message" || message?.role !== "toolResult" || message.toolName !== outputToolName || message.isError === true || !isComplianceAuditIncomplete(message.details)) {
21847
- continue;
21848
- }
21849
- const roleCall = boundRoleToolCallForResult(
21850
- entries,
21851
- index,
21852
- message,
21853
- outputToolName
21854
- );
21855
- if (roleCall === void 0) continue;
21856
- const details = message.details;
21857
- if (details.observation.kind === "missing-dossier" || details.observation.kind === "missing-subject") {
21858
- return {
21859
- outcome: buildAuditIncompleteTerminalOutcome({
21860
- role,
21861
- roleCandidate: roleCall.candidate,
21862
- audit: details
21863
- })
21864
- };
21865
- }
21866
- const retained = boundRetainedAuditResponse(
21867
- entries,
21868
- roleCall.callIndex,
21869
- index,
21870
- auditToolName
21871
- );
21872
- if (retained === void 0) continue;
21873
- const audit = auditIncompleteFromCandidate(retained.candidate);
21874
- if (audit === void 0) continue;
21875
- return {
21876
- outcome: buildAuditIncompleteTerminalOutcome({
21877
- role,
21878
- roleCandidate: roleCall.candidate,
21879
- audit
21880
- })
21881
- };
21882
- }
21883
- return void 0;
21884
- }
21885
- function auditArtifactPublicationError(message, code) {
21886
- const error = new Error(message);
21887
- error.name = "ArtifactPublicationError";
21888
- error.code = code;
21889
- return error;
21890
- }
21891
- async function ensureAuditEvidenceDirectory(runDirectory) {
21892
- const artifactsDir = join13(runDirectory, "artifacts");
21893
- const runStat = await lstat4(runDirectory);
21894
- if (runStat.isSymbolicLink() || !runStat.isDirectory()) {
21895
- throw auditArtifactPublicationError(
21896
- "audit evidence run directory is not a real directory",
21897
- "ELOOP"
21898
- );
21899
- }
21900
- try {
21901
- const existing = await lstat4(artifactsDir);
21902
- if (existing.isSymbolicLink()) {
21903
- throw auditArtifactPublicationError(
21904
- "audit evidence artifacts directory is a symlink",
21905
- "ELOOP"
21906
- );
21907
- }
21908
- if (!existing.isDirectory()) {
21909
- throw auditArtifactPublicationError(
21910
- "audit evidence artifacts path is not a directory",
21911
- "EEXIST"
21912
- );
21913
- }
21914
- } catch (error) {
21915
- if (!isMissingPathError2(error)) throw error;
21916
- await mkdir3(artifactsDir, { recursive: true });
21917
- const created = await lstat4(artifactsDir);
21918
- if (created.isSymbolicLink() || !created.isDirectory()) {
21919
- throw auditArtifactPublicationError(
21920
- "audit evidence artifacts directory is not a real directory",
21921
- "ELOOP"
21922
- );
21923
- }
21924
- }
21925
- return artifactsDir;
21926
- }
21927
21813
  async function appendRunAttemptHistory(admitted, outcome) {
21928
21814
  const entries = await readBoundSessionEntries(admitted.sessionFile);
21929
21815
  let parentId = null;
@@ -21952,119 +21838,6 @@ async function appendRunAttemptHistory(admitted, outcome) {
21952
21838
  `;
21953
21839
  await appendFile(admitted.sessionFile, line2, "utf8");
21954
21840
  }
21955
- async function publishComplianceAuditIncompleteEvidence(admitted, outcome) {
21956
- await appendRunAttemptHistory(admitted, outcome);
21957
- if (typeof fsConstants.O_NOFOLLOW !== "number" || typeof fsConstants.O_NONBLOCK !== "number") {
21958
- throw auditArtifactPublicationError(
21959
- "audit evidence publication requires O_NOFOLLOW|O_NONBLOCK open-flag support (anti-symlink/anti-planted protection must not be silently dropped); refusing to publish",
21960
- "ENOSYS"
21961
- );
21962
- }
21963
- const artifactsDir = await ensureAuditEvidenceDirectory(admitted.runDirectory);
21964
- const evidencePath = join13(artifactsDir, "audit-incomplete.json");
21965
- let existing;
21966
- try {
21967
- existing = await lstat4(evidencePath);
21968
- } catch (error) {
21969
- if (!isMissingPathError2(error)) throw error;
21970
- }
21971
- if (existing?.isSymbolicLink()) {
21972
- throw auditArtifactPublicationError(
21973
- "audit evidence destination is a symlink",
21974
- "ELOOP"
21975
- );
21976
- }
21977
- if (existing && !existing.isFile()) {
21978
- throw auditArtifactPublicationError(
21979
- "audit evidence destination is not a regular file",
21980
- "EEXIST"
21981
- );
21982
- }
21983
- const handle = await open2(
21984
- evidencePath,
21985
- fsConstants.O_WRONLY | fsConstants.O_CREAT | fsConstants.O_TRUNC | fsConstants.O_NOFOLLOW | fsConstants.O_NONBLOCK,
21986
- 384
21987
- );
21988
- try {
21989
- if (!(await handle.stat()).isFile()) {
21990
- throw auditArtifactPublicationError(
21991
- "audit evidence destination is not a regular file",
21992
- "EEXIST"
21993
- );
21994
- }
21995
- await handle.writeFile(`${JSON.stringify(outcome, null, 2)}
21996
- `, "utf8");
21997
- await handle.sync();
21998
- } finally {
21999
- await handle.close();
22000
- }
22001
- return { kind: "evidence", path: evidencePath };
22002
- }
22003
- function auditPublicationFailureTerminal(admitted, entries, outcome, error) {
22004
- const attempt = publicationAttemptFromError(
22005
- join13(admitted.runDirectory, "artifacts", "audit-incomplete.json"),
22006
- error
22007
- );
22008
- const diagnostic = `audit-incomplete evidence publication failed: ${attempt.diagnostic}`;
22009
- const decisiveFacts = {
22010
- ...outcome.decisiveFacts,
22011
- cause: "unrecognized",
22012
- diagnostic,
22013
- publicationFailure: attempt
22014
- };
22015
- if (attempt.identity?.name !== void 0) decisiveFacts.errorName = attempt.identity.name;
22016
- if (attempt.identity?.code !== void 0) decisiveFacts.errorCode = attempt.identity.code;
22017
- const auditResidual = {
22018
- roleCandidate: outcome.roleCandidate,
22019
- audit: outcome.audit,
22020
- acceptedReceipt: false
22021
- };
22022
- return {
22023
- roleOutcome: {
22024
- kind: "failure",
22025
- role: admitted.role,
22026
- cause: "unrecognized",
22027
- diagnostic,
22028
- decisiveFacts,
22029
- auditResidual
22030
- },
22031
- navigator: extractNavigatorFact(entries),
22032
- artifacts: [],
22033
- runId: admitted.runId
22034
- };
22035
- }
22036
- async function trySettleComplianceAuditIncompleteTerminalResult(admitted) {
22037
- if (!AUDITOR_SOUL_ROLES.includes(admitted.role)) {
22038
- return void 0;
22039
- }
22040
- const outputToolName = admitted.role === "judge" ? JUDGE_OUTPUT_TOOL_NAME : admitted.role === "reviewer" ? REVIEWER_OUTPUT_TOOL_NAME : DOCTOR_OUTPUT_TOOL_NAME;
22041
- const entries = await readLawfulSettlementEntries(admitted);
22042
- if (entries === void 0) return void 0;
22043
- const extracted = extractComplianceAuditIncompleteRoleOutcome(
22044
- entries,
22045
- admitted.role,
22046
- outputToolName
22047
- );
22048
- if (extracted === void 0) return void 0;
22049
- let evidence;
22050
- try {
22051
- evidence = await publishComplianceAuditIncompleteEvidence(
22052
- admitted,
22053
- extracted.outcome
22054
- );
22055
- } catch (error) {
22056
- return auditPublicationFailureTerminal(admitted, entries, extracted.outcome, error);
22057
- }
22058
- return withOptionalMenxiaProjection(
22059
- {
22060
- roleOutcome: extracted.outcome,
22061
- navigator: extractNavigatorFact(entries),
22062
- artifacts: [evidence],
22063
- runId: admitted.runId
22064
- },
22065
- admitted.sessionDirectory
22066
- );
22067
- }
22068
21841
  function extractJudgeRoleOutcome(entries) {
22069
21842
  if (!isReceiptSettlementBindingClear(entries)) return void 0;
22070
21843
  for (let i = entries.length - 1; i >= 0; i -= 1) {
@@ -22196,6 +21969,8 @@ async function extractMenxiaFactFromSessionDirectory(sessionDirectory) {
22196
21969
  return projectTerminalMenxiaFact(rounds);
22197
21970
  }
22198
21971
  async function withOptionalMenxiaProjection(base, sessionDirectory) {
21972
+ const secondaryEvidence = base.roleOutcome.kind === "failure" ? base.roleOutcome.decisiveFacts.secondaryEvidence : void 0;
21973
+ if (isRecord8(secondaryEvidence) && secondaryEvidence.kind === "role_infrastructure_failure" && (secondaryEvidence.stage === "gatekeeper" || secondaryEvidence.stage === "inspector" || secondaryEvidence.stage === "notary")) return base;
22199
21974
  const menxia = await extractMenxiaFactFromSessionDirectory(sessionDirectory);
22200
21975
  return menxia === void 0 ? base : { ...base, menxia };
22201
21976
  }
@@ -22909,16 +22684,11 @@ async function settleLawfulNotaryTerminalResult(admitted) {
22909
22684
  NOTARY_OUTPUT_TOOL_NAME
22910
22685
  );
22911
22686
  if (residual === void 0) continue;
22912
- return {
22913
- roleOutcome: buildResidualIncompleteTerminalOutcome({
22914
- role: "notary",
22915
- candidate: residual.candidate,
22916
- diagnostic: residual.diagnostic
22917
- }),
22918
- navigator: extractNavigatorFact(entries),
22919
- artifacts: [],
22920
- runId: admitted.runId
22921
- };
22687
+ return settleFailureTerminalResult(admitted, {
22688
+ cause: "output",
22689
+ diagnostic: residual.diagnostic,
22690
+ details: { candidate: residual.candidate, acceptedReceipt: false }
22691
+ });
22922
22692
  }
22923
22693
  return void 0;
22924
22694
  }
@@ -23640,9 +23410,9 @@ var init_settlement = __esm({
23640
23410
  });
23641
23411
 
23642
23412
  // src/public-cli/auto-resume.ts
23643
- import { constants as fsConstants2 } from "node:fs";
23413
+ import { constants as fsConstants } from "node:fs";
23644
23414
  import { randomUUID as randomUUID2 } from "node:crypto";
23645
- import { appendFile as appendFile2, lstat as lstat5, mkdir as mkdir4, open as open3, readFile as readFile11 } from "node:fs/promises";
23415
+ import { appendFile as appendFile2, lstat as lstat5, mkdir as mkdir4, open as open2, readFile as readFile11 } from "node:fs/promises";
23646
23416
  import { join as join14 } from "node:path";
23647
23417
  function presentTerminal(terminal, io) {
23648
23418
  if (terminal.roleOutcome.kind === "failure" || terminal.roleOutcome.kind === "no_receipt") {
@@ -23760,10 +23530,10 @@ async function retainDispatchError(admitted, attempt, error) {
23760
23530
  2
23761
23531
  )}
23762
23532
  `;
23763
- const noFollowFlag = typeof fsConstants2.O_NOFOLLOW === "number" ? fsConstants2.O_NOFOLLOW : 0;
23764
- const handle = await open3(
23533
+ const noFollowFlag = typeof fsConstants.O_NOFOLLOW === "number" ? fsConstants.O_NOFOLLOW : 0;
23534
+ const handle = await open2(
23765
23535
  filePath,
23766
- fsConstants2.O_WRONLY | fsConstants2.O_CREAT | fsConstants2.O_EXCL | noFollowFlag,
23536
+ fsConstants.O_WRONLY | fsConstants.O_CREAT | fsConstants.O_EXCL | noFollowFlag,
23767
23537
  384
23768
23538
  );
23769
23539
  try {
@@ -24826,8 +24596,7 @@ async function runPublicDoctor(argv, env, io, parseDoctorArgv2) {
24826
24596
  extraArgs,
24827
24597
  adapters: {
24828
24598
  trySettle: trySettleDoctorTerminalResult,
24829
- shouldPresentSettled: (terminal) => isLawfulTypedTerminalOutcome(terminal.roleOutcome),
24830
- trySettleSecondary: trySettleComplianceAuditIncompleteTerminalResult
24599
+ shouldPresentSettled: (terminal) => isLawfulTypedTerminalOutcome(terminal.roleOutcome)
24831
24600
  },
24832
24601
  ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
24833
24602
  });
@@ -25055,20 +24824,6 @@ async function dispatchAdmittedFixer(input) {
25055
24824
  terminal: lawful
25056
24825
  };
25057
24826
  }
25058
- const auditIncomplete = await trySettleComplianceAuditIncompleteTerminalResult(admitted);
25059
- if (auditIncomplete !== void 0) {
25060
- await markRunTerminal(admitted.runDirectory).catch(() => void 0);
25061
- if (auditIncomplete.roleOutcome.kind === "failure") {
25062
- presentFailureTerminal(auditIncomplete, io);
25063
- } else {
25064
- io.stdout(formatTerminalResult(auditIncomplete));
25065
- }
25066
- return {
25067
- exitCode: exitCodeForTerminalOutcome(auditIncomplete.roleOutcome),
25068
- admitted,
25069
- terminal: auditIncomplete
25070
- };
25071
- }
25072
24827
  const credentialFailure = postRunMissingCredentialFailure(
25073
24828
  result2,
25074
24829
  env.model,
@@ -25299,7 +25054,7 @@ async function runPublicNotary(argv, env, io, parseNotaryArgv2) {
25299
25054
  extraArgs,
25300
25055
  adapters: {
25301
25056
  trySettle: trySettleNotaryTerminalResult,
25302
- // Accepted receipts and residual incomplete share one present path.
25057
+ // Accepted receipts and failure terminals both present via shared path.
25303
25058
  shouldPresentSettled: () => true
25304
25059
  },
25305
25060
  ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
@@ -25497,20 +25252,6 @@ async function dispatchAdmittedJudge(input) {
25497
25252
  terminal: lawful
25498
25253
  };
25499
25254
  }
25500
- const auditIncomplete = await trySettleComplianceAuditIncompleteTerminalResult(admitted);
25501
- if (auditIncomplete !== void 0) {
25502
- await markRunTerminal(admitted.runDirectory).catch(() => void 0);
25503
- if (auditIncomplete.roleOutcome.kind === "failure") {
25504
- presentFailureTerminal(auditIncomplete, io);
25505
- } else {
25506
- io.stdout(formatTerminalResult(auditIncomplete));
25507
- }
25508
- return {
25509
- exitCode: exitCodeForTerminalOutcome(auditIncomplete.roleOutcome),
25510
- admitted,
25511
- terminal: auditIncomplete
25512
- };
25513
- }
25514
25255
  const infrastructureFailure = await readEngineDetourInfrastructureFailure(
25515
25256
  admitted.sessionFile
25516
25257
  );
@@ -26316,20 +26057,6 @@ async function dispatchAdmittedReviewer(input) {
26316
26057
  terminal: lawful
26317
26058
  };
26318
26059
  }
26319
- const auditIncomplete = await trySettleComplianceAuditIncompleteTerminalResult(admitted);
26320
- if (auditIncomplete !== void 0) {
26321
- await markRunTerminal(admitted.runDirectory).catch(() => void 0);
26322
- if (auditIncomplete.roleOutcome.kind === "failure") {
26323
- presentFailureTerminal(auditIncomplete, io);
26324
- } else {
26325
- io.stdout(formatTerminalResult(auditIncomplete));
26326
- }
26327
- return {
26328
- exitCode: exitCodeForTerminalOutcome(auditIncomplete.roleOutcome),
26329
- admitted,
26330
- terminal: auditIncomplete
26331
- };
26332
- }
26333
26060
  const infrastructureFailure = await readEngineDetourInfrastructureFailure(
26334
26061
  admitted.sessionFile
26335
26062
  );
@@ -26564,7 +26291,7 @@ var init_atomic_write = __esm({
26564
26291
  });
26565
26292
 
26566
26293
  // src/analyst-index.ts
26567
- import { open as open4, readFile as readFile12, unlink as unlink4 } from "node:fs/promises";
26294
+ import { open as open3, readFile as readFile12, unlink as unlink4 } from "node:fs/promises";
26568
26295
  import { dirname as dirname9, join as join23 } from "node:path";
26569
26296
  function sleep(ms) {
26570
26297
  return new Promise((resolve9) => {
@@ -26579,7 +26306,7 @@ async function withAnalystLibraryIndexLock(ledgerHome, fn) {
26579
26306
  const startedAt = Date.now();
26580
26307
  while (true) {
26581
26308
  try {
26582
- const handle = await open4(lockPath, "wx");
26309
+ const handle = await open3(lockPath, "wx");
26583
26310
  try {
26584
26311
  await handle.writeFile(`${process.pid}
26585
26312
  `, "utf8");