@akagilnc/pi-workflow-roles 0.1.4659 → 0.1.4695

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.
@@ -1378,6 +1378,7 @@ __export(run_terminal_artifacts_exports, {
1378
1378
  RUN_TERMINAL_ARTIFACT_FILES: () => RUN_TERMINAL_ARTIFACT_FILES,
1379
1379
  RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS: () => RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS,
1380
1380
  isUniqueErrorFallbackName: () => isUniqueErrorFallbackName,
1381
+ listSeamOwnedUniqueErrorFacePaths: () => listSeamOwnedUniqueErrorFacePaths,
1381
1382
  readRunTerminalArtifact: () => readRunTerminalArtifact,
1382
1383
  runIdFromRunDirectory: () => runIdFromRunDirectory
1383
1384
  });
@@ -1472,30 +1473,55 @@ function presentUniqueFallbackBoundToRun(body, expectedRunId) {
1472
1473
  if (expectedRunId === void 0) return false;
1473
1474
  return typeof body.runId === "string" && body.runId === expectedRunId;
1474
1475
  }
1476
+ async function listSeamOwnedUniqueErrorFacePaths(runDirectory) {
1477
+ const artifactsDir = roleRunArtifactsDirectory(runDirectory);
1478
+ const owned = await listUniqueErrorFallbackPaths([
1479
+ artifactsDir,
1480
+ runDirectory
1481
+ ]);
1482
+ const expectedRunId = runIdFromRunDirectory(runDirectory);
1483
+ for (const path of await listUniqueErrorFallbackPaths([dirname5(runDirectory)])) {
1484
+ const read = await readTerminalArtifactAtPath(path, "error.json");
1485
+ if (read === void 0 || read.status !== "present") continue;
1486
+ if (!presentUniqueFallbackBoundToRun(read.body, expectedRunId)) continue;
1487
+ owned.push(path);
1488
+ }
1489
+ return owned;
1490
+ }
1491
+ function failureClassRank(file) {
1492
+ return file === "error.json" ? 1 : 0;
1493
+ }
1475
1494
  async function readRunTerminalArtifact(runDirectory) {
1476
1495
  const artifactsDir = roleRunArtifactsDirectory(runDirectory);
1496
+ const present = [];
1497
+ const unreadable = [];
1498
+ const consider = (read) => {
1499
+ if (read === void 0 || read.status === "absent") return;
1500
+ if (read.status === "present") {
1501
+ present.push(read);
1502
+ return;
1503
+ }
1504
+ unreadable.push(read);
1505
+ };
1477
1506
  for (const file of RUN_TERMINAL_ARTIFACT_FILES) {
1478
- const path = join8(artifactsDir, file);
1479
- const read = await readTerminalArtifactAtPath(path, file);
1480
- if (read !== void 0) return read;
1507
+ consider(await readTerminalArtifactAtPath(join8(artifactsDir, file), file));
1481
1508
  }
1482
1509
  for (const relative5 of RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS) {
1483
- const path = join8(runDirectory, relative5);
1484
- const read = await readTerminalArtifactAtPath(path, "error.json");
1485
- if (read !== void 0) return read;
1510
+ consider(
1511
+ await readTerminalArtifactAtPath(join8(runDirectory, relative5), "error.json")
1512
+ );
1486
1513
  }
1487
- for (const path of await listUniqueErrorFallbackPaths([artifactsDir, runDirectory])) {
1488
- const read = await readTerminalArtifactAtPath(path, "error.json");
1489
- if (read !== void 0) return read;
1514
+ for (const path of await listSeamOwnedUniqueErrorFacePaths(runDirectory)) {
1515
+ consider(await readTerminalArtifactAtPath(path, "error.json"));
1490
1516
  }
1491
- const expectedRunId = runIdFromRunDirectory(runDirectory);
1492
- for (const path of await listUniqueErrorFallbackPaths([dirname5(runDirectory)])) {
1493
- const read = await readTerminalArtifactAtPath(path, "error.json");
1494
- if (read === void 0) continue;
1495
- if (read.status === "present") {
1496
- if (!presentUniqueFallbackBoundToRun(read.body, expectedRunId)) continue;
1497
- return read;
1498
- }
1517
+ if (present.length > 0) {
1518
+ present.sort(
1519
+ (a, b) => failureClassRank(b.file) - failureClassRank(a.file)
1520
+ );
1521
+ return present[0];
1522
+ }
1523
+ if (unreadable.length > 0) {
1524
+ return unreadable[0];
1499
1525
  }
1500
1526
  return { status: "absent" };
1501
1527
  }
@@ -1578,14 +1604,9 @@ function thisCourtOfficerPayloads(terminal) {
1578
1604
  if (outcome !== void 0 && (outcome.kind === "accepted" || outcome.kind === "audit_escalation")) {
1579
1605
  if (outcome.payloads !== void 0 && outcome.payloads.length > 0) return outcome.payloads;
1580
1606
  }
1581
- if (outcome?.kind === "failure" && outcome.payloads !== void 0 && outcome.payloads.length > 0) {
1582
- return outcome.payloads;
1583
- }
1584
1607
  return [];
1585
1608
  }
1586
1609
  function officerFailurePayloads(terminal) {
1587
- const outcome = terminal?.roleOutcome;
1588
- if (outcome?.kind === "failure") return outcome.payloads ?? terminal?.submissions ?? [];
1589
1610
  return terminal?.submissions ?? [];
1590
1611
  }
1591
1612
  function projectOfficerPayloads(officer, payloads, fallbackStatus) {
@@ -1740,10 +1761,10 @@ __export(session_assistant_usage_exports, {
1740
1761
  });
1741
1762
  import { join as join9 } from "node:path";
1742
1763
  async function readAssistantUsageFromSessionFile(sessionFile) {
1743
- const { readFile: readFile24 } = await import("node:fs/promises");
1764
+ const { readFile: readFile25 } = await import("node:fs/promises");
1744
1765
  let text;
1745
1766
  try {
1746
- text = await readFile24(sessionFile, "utf8");
1767
+ text = await readFile25(sessionFile, "utf8");
1747
1768
  } catch (error) {
1748
1769
  if (error?.code === "ENOENT") return void 0;
1749
1770
  throw error;
@@ -3842,6 +3863,114 @@ var init_host_descriptions = __esm({
3842
3863
  }
3843
3864
  });
3844
3865
 
3866
+ // src/public-cli/terminal.ts
3867
+ function encodeTerminalField(value) {
3868
+ return JSON.stringify(value);
3869
+ }
3870
+ function isLawfulTypedTerminalOutcome(outcome) {
3871
+ return outcome.kind === "accepted" || outcome.kind === "audit_escalation" || outcome.kind === "no_receipt";
3872
+ }
3873
+ function exitCodeForTerminalOutcome(outcome) {
3874
+ return isLawfulTypedTerminalOutcome(outcome) ? 0 : 1;
3875
+ }
3876
+ function coalesceSubmissionRows(payloads, submissions) {
3877
+ if (payloads !== void 0 && payloads.length > 0) return payloads;
3878
+ if (submissions !== void 0 && submissions.length > 0) return submissions;
3879
+ return payloads ?? submissions ?? [];
3880
+ }
3881
+ function adviceNavigatorFact(input) {
3882
+ return {
3883
+ disposition: "advice",
3884
+ prose: input.prose,
3885
+ ...input.advisoryDiagnostic === void 0 ? {} : { advisoryDiagnostic: input.advisoryDiagnostic }
3886
+ };
3887
+ }
3888
+ function formatTerminalResult(result) {
3889
+ const lines = [];
3890
+ lines.push("role outcome status");
3891
+ const outcomeStatus = result.roleOutcome.kind === "failure" ? result.roleOutcome.cause ?? "" : result.roleOutcome.kind === "accepted" ? "accepted" : result.roleOutcome.status;
3892
+ lines.push(
3893
+ `${result.roleOutcome.role} ${result.roleOutcome.kind} ${encodeTerminalField(outcomeStatus)}`
3894
+ );
3895
+ if (result.roleOutcome.kind === "failure") {
3896
+ lines.push(
3897
+ `diagnostic ${encodeTerminalField(result.roleOutcome.diagnostic)}`
3898
+ );
3899
+ }
3900
+ if (result.roleOutcome.kind === "failure" || result.roleOutcome.kind === "no_receipt") {
3901
+ const facts = result.roleOutcome.decisiveFacts;
3902
+ for (const [key, value] of Object.entries(facts)) {
3903
+ if (value === void 0) continue;
3904
+ const rendered = typeof value === "string" ? value : JSON.stringify(value);
3905
+ lines.push(`fact ${encodeTerminalField(key)} ${encodeTerminalField(rendered)}`);
3906
+ }
3907
+ }
3908
+ lines.push(`navigator ${result.navigator.disposition}`);
3909
+ if (result.navigator.advisoryDiagnostic !== void 0) {
3910
+ lines.push(`navigator-advisory ${encodeTerminalField(result.navigator.advisoryDiagnostic)}`);
3911
+ }
3912
+ if (result.navigator.disposition === "advice") {
3913
+ lines.push(`prose ${encodeTerminalField(result.navigator.prose)}`);
3914
+ } else if (result.navigator.disposition === "unavailable") {
3915
+ lines.push(
3916
+ `unavailable ${result.navigator.source} ${encodeTerminalField(result.navigator.reason)}`
3917
+ );
3918
+ }
3919
+ for (const artifact of result.artifacts) {
3920
+ lines.push(`artifact ${artifact.kind} ${encodeTerminalField(artifact.path)}`);
3921
+ }
3922
+ if (result.gate !== void 0) {
3923
+ lines.push(
3924
+ `gate ${encodeTerminalField(result.gate.actualSeats.join(","))} ${result.gate.rounds.length}`
3925
+ );
3926
+ for (const round of result.gate.rounds) {
3927
+ const reason = round.dispatch.kind === "historical_dispatch" && round.dispatch.reason !== void 0 ? encodeTerminalField(round.dispatch.reason) : "";
3928
+ lines.push(
3929
+ `gate-round ${round.roundIndex} ${round.dispatch.kind} ${round.dispatch.officer} ${reason} ${round.officer.seat} ${encodeTerminalField(round.officer.status)} ${encodeTerminalField(JSON.stringify(round.officer.findings))}`
3930
+ );
3931
+ }
3932
+ }
3933
+ if (result.reviewerChildOutcomes !== void 0) {
3934
+ for (const axis of ["completeness", "correctness"]) {
3935
+ const child = result.reviewerChildOutcomes[axis];
3936
+ lines.push(`reviewer-child ${axis} ${child.exitCode}`);
3937
+ if (child.stderr !== void 0 && child.stderr !== "") {
3938
+ lines.push(`reviewer-child-diagnostic ${axis} ${encodeTerminalField(child.stderr)}`);
3939
+ }
3940
+ }
3941
+ }
3942
+ if (result.resume !== void 0) {
3943
+ lines.push(`resume ${encodeTerminalField(result.resume.command)}`);
3944
+ } else if (result.runId !== void 0) {
3945
+ lines.push(`run ${encodeTerminalField(result.runId)}`);
3946
+ }
3947
+ if (result.autoResumeCount !== void 0) {
3948
+ lines.push(`autoResumeCount ${encodeTerminalField(String(result.autoResumeCount))}`);
3949
+ }
3950
+ if (result.roleOutcome.kind === "failure") {
3951
+ const recorded = result.submissions ?? [];
3952
+ for (let i = recorded.length - 1; i >= 0; i -= 1) {
3953
+ const payload = recorded[i];
3954
+ const rendered = typeof payload === "string" ? payload : JSON.stringify(payload);
3955
+ lines.push(`recorded-submission ${encodeTerminalField(rendered)}`);
3956
+ }
3957
+ } else {
3958
+ const payloads = result.roleOutcome.kind === "accepted" || result.roleOutcome.kind === "audit_escalation" ? coalesceSubmissionRows(result.roleOutcome.payloads, result.submissions) : result.submissions ?? [];
3959
+ for (let i = payloads.length - 1; i >= 0; i -= 1) {
3960
+ const payload = payloads[i];
3961
+ const rendered = typeof payload === "string" ? payload : JSON.stringify(payload);
3962
+ lines.push(`submission ${encodeTerminalField(rendered)}`);
3963
+ }
3964
+ }
3965
+ return `${lines.join("\n")}
3966
+ `;
3967
+ }
3968
+ var init_terminal = __esm({
3969
+ "src/public-cli/terminal.ts"() {
3970
+ "use strict";
3971
+ }
3972
+ });
3973
+
3845
3974
  // src/compliance-transport.ts
3846
3975
  function readListField(value) {
3847
3976
  return Array.isArray(value) ? value : value === void 0 ? [] : [value];
@@ -3896,7 +4025,7 @@ async function projectAuditorTerminal(summoned) {
3896
4025
  };
3897
4026
  }
3898
4027
  if (outcome.kind === "failure") {
3899
- const rows = outcome.payloads ?? summoned.terminal?.submissions ?? [];
4028
+ const rows = summoned.terminal?.submissions ?? [];
3900
4029
  return {
3901
4030
  status: "transport_failure",
3902
4031
  diagnostic: outcome.diagnostic,
@@ -3906,7 +4035,10 @@ async function projectAuditorTerminal(summoned) {
3906
4035
  };
3907
4036
  }
3908
4037
  if (outcome.kind === "accepted") {
3909
- const rows = outcome.payloads ?? summoned.terminal?.submissions ?? [];
4038
+ const rows = coalesceSubmissionRows(
4039
+ outcome.payloads,
4040
+ summoned.terminal?.submissions
4041
+ );
3910
4042
  if (rows.length === 0) {
3911
4043
  return readComplianceCandidate({}, usage);
3912
4044
  }
@@ -3968,6 +4100,7 @@ var init_compliance_transport = __esm({
3968
4100
  "use strict";
3969
4101
  init_auditor_dossier_tool();
3970
4102
  init_gatekeeper_role();
4103
+ init_terminal();
3971
4104
  AUDITOR_DOSSIER_PROMPT = "\u5377\u5B97\u6307\u9488\uFF1A";
3972
4105
  AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE = "ak_auditor_parent_attempt_binding";
3973
4106
  AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE = "ak_auditor_compliance_failure";
@@ -11931,10 +12064,10 @@ function pairGateRounds(volumes) {
11931
12064
  return rounds.sort((a, b) => a.officerStartedAt.localeCompare(b.officerStartedAt)).map((round, index) => ({ ...round, roundIndex: index + 1 }));
11932
12065
  }
11933
12066
  async function resolveOfficerSessionFromPointerFile(pointerPath) {
11934
- const { readFile: readFile24 } = await import("node:fs/promises");
12067
+ const { readFile: readFile25 } = await import("node:fs/promises");
11935
12068
  let raw;
11936
12069
  try {
11937
- raw = JSON.parse(await readFile24(pointerPath, "utf8"));
12070
+ raw = JSON.parse(await readFile25(pointerPath, "utf8"));
11938
12071
  } catch (error) {
11939
12072
  throw new Error(
11940
12073
  `direct officer run pointer unreadable in ${pointerPath}: ${error instanceof Error ? error.message : String(error)}`,
@@ -14723,100 +14856,6 @@ var init_receipt_delivery_policy = __esm({
14723
14856
  }
14724
14857
  });
14725
14858
 
14726
- // src/public-cli/terminal.ts
14727
- function encodeTerminalField(value) {
14728
- return JSON.stringify(value);
14729
- }
14730
- function isLawfulTypedTerminalOutcome(outcome) {
14731
- return outcome.kind === "accepted" || outcome.kind === "audit_escalation" || outcome.kind === "no_receipt";
14732
- }
14733
- function exitCodeForTerminalOutcome(outcome) {
14734
- return isLawfulTypedTerminalOutcome(outcome) ? 0 : 1;
14735
- }
14736
- function adviceNavigatorFact(input) {
14737
- return {
14738
- disposition: "advice",
14739
- prose: input.prose,
14740
- ...input.advisoryDiagnostic === void 0 ? {} : { advisoryDiagnostic: input.advisoryDiagnostic }
14741
- };
14742
- }
14743
- function formatTerminalResult(result) {
14744
- const lines = [];
14745
- lines.push("role outcome status");
14746
- const outcomeStatus = result.roleOutcome.kind === "failure" ? result.roleOutcome.cause ?? "" : result.roleOutcome.kind === "accepted" ? "accepted" : result.roleOutcome.status;
14747
- lines.push(
14748
- `${result.roleOutcome.role} ${result.roleOutcome.kind} ${encodeTerminalField(outcomeStatus)}`
14749
- );
14750
- if (result.roleOutcome.kind === "failure") {
14751
- lines.push(
14752
- `diagnostic ${encodeTerminalField(result.roleOutcome.diagnostic)}`
14753
- );
14754
- }
14755
- if (result.roleOutcome.kind === "failure" || result.roleOutcome.kind === "no_receipt") {
14756
- const facts = result.roleOutcome.decisiveFacts;
14757
- for (const [key, value] of Object.entries(facts)) {
14758
- if (value === void 0) continue;
14759
- const rendered = typeof value === "string" ? value : JSON.stringify(value);
14760
- lines.push(`fact ${encodeTerminalField(key)} ${encodeTerminalField(rendered)}`);
14761
- }
14762
- }
14763
- lines.push(`navigator ${result.navigator.disposition}`);
14764
- if (result.navigator.advisoryDiagnostic !== void 0) {
14765
- lines.push(`navigator-advisory ${encodeTerminalField(result.navigator.advisoryDiagnostic)}`);
14766
- }
14767
- if (result.navigator.disposition === "advice") {
14768
- lines.push(`prose ${encodeTerminalField(result.navigator.prose)}`);
14769
- } else if (result.navigator.disposition === "unavailable") {
14770
- lines.push(
14771
- `unavailable ${result.navigator.source} ${encodeTerminalField(result.navigator.reason)}`
14772
- );
14773
- }
14774
- for (const artifact of result.artifacts) {
14775
- lines.push(`artifact ${artifact.kind} ${encodeTerminalField(artifact.path)}`);
14776
- }
14777
- if (result.gate !== void 0) {
14778
- lines.push(
14779
- `gate ${encodeTerminalField(result.gate.actualSeats.join(","))} ${result.gate.rounds.length}`
14780
- );
14781
- for (const round of result.gate.rounds) {
14782
- const reason = round.dispatch.kind === "historical_dispatch" && round.dispatch.reason !== void 0 ? encodeTerminalField(round.dispatch.reason) : "";
14783
- lines.push(
14784
- `gate-round ${round.roundIndex} ${round.dispatch.kind} ${round.dispatch.officer} ${reason} ${round.officer.seat} ${encodeTerminalField(round.officer.status)} ${encodeTerminalField(JSON.stringify(round.officer.findings))}`
14785
- );
14786
- }
14787
- }
14788
- if (result.reviewerChildOutcomes !== void 0) {
14789
- for (const axis of ["completeness", "correctness"]) {
14790
- const child = result.reviewerChildOutcomes[axis];
14791
- lines.push(`reviewer-child ${axis} ${child.exitCode}`);
14792
- if (child.stderr !== void 0 && child.stderr !== "") {
14793
- lines.push(`reviewer-child-diagnostic ${axis} ${encodeTerminalField(child.stderr)}`);
14794
- }
14795
- }
14796
- }
14797
- if (result.resume !== void 0) {
14798
- lines.push(`resume ${encodeTerminalField(result.resume.command)}`);
14799
- } else if (result.runId !== void 0) {
14800
- lines.push(`run ${encodeTerminalField(result.runId)}`);
14801
- }
14802
- if (result.autoResumeCount !== void 0) {
14803
- lines.push(`autoResumeCount ${encodeTerminalField(String(result.autoResumeCount))}`);
14804
- }
14805
- const payloads = result.roleOutcome.kind === "accepted" || result.roleOutcome.kind === "audit_escalation" ? result.roleOutcome.payloads ?? result.submissions ?? [] : result.roleOutcome.kind === "failure" ? result.roleOutcome.payloads ?? result.submissions ?? [] : result.submissions ?? [];
14806
- for (let i = payloads.length - 1; i >= 0; i -= 1) {
14807
- const payload = payloads[i];
14808
- const rendered = typeof payload === "string" ? payload : JSON.stringify(payload);
14809
- lines.push(`submission ${encodeTerminalField(rendered)}`);
14810
- }
14811
- return `${lines.join("\n")}
14812
- `;
14813
- }
14814
- var init_terminal = __esm({
14815
- "src/public-cli/terminal.ts"() {
14816
- "use strict";
14817
- }
14818
- });
14819
-
14820
14859
  // src/public-cli/settlement.ts
14821
14860
  var settlement_exports = {};
14822
14861
  __export(settlement_exports, {
@@ -14898,7 +14937,7 @@ __export(settlement_exports, {
14898
14937
  withSubmissions: () => withSubmissions
14899
14938
  });
14900
14939
  import { randomUUID as randomUUID4 } from "node:crypto";
14901
- import { appendFile as appendFile2, readFile as readFile16, readdir as readdir7, writeFile as writeFile7 } from "node:fs/promises";
14940
+ import { appendFile as appendFile2, readFile as readFile16, readdir as readdir7, rm as rm3, writeFile as writeFile7 } from "node:fs/promises";
14902
14941
  import { dirname as dirname14, join as join28 } from "node:path";
14903
14942
  function sealedLedgerHome(admitted) {
14904
14943
  return homeFromRunDirectory(admitted.runDirectory);
@@ -14959,7 +14998,13 @@ async function recordedSubmissionPayloads(admitted, scope) {
14959
14998
  function withSubmissions(terminal, submissions) {
14960
14999
  if (submissions.length === 0) return terminal;
14961
15000
  const roleOutcome = terminal.roleOutcome;
14962
- const withPayloads = roleOutcome.kind === "accepted" || roleOutcome.kind === "audit_escalation" ? { ...roleOutcome, payloads: (roleOutcome.payloads ?? []).length > 0 ? roleOutcome.payloads : submissions } : roleOutcome.kind === "failure" ? { ...roleOutcome, payloads: roleOutcome.payloads ?? submissions } : roleOutcome;
15001
+ if (roleOutcome.kind === "failure") {
15002
+ return { ...terminal, submissions };
15003
+ }
15004
+ const withPayloads = roleOutcome.kind === "accepted" || roleOutcome.kind === "audit_escalation" ? {
15005
+ ...roleOutcome,
15006
+ payloads: coalesceSubmissionRows(roleOutcome.payloads, submissions)
15007
+ } : roleOutcome;
14963
15008
  return { ...terminal, roleOutcome: withPayloads, submissions };
14964
15009
  }
14965
15010
  async function attachRecordedSubmissions(admitted, terminal, scope) {
@@ -14978,6 +15023,7 @@ async function settleHostEndedNoReceipt(admitted, authority, scope) {
14978
15023
  attemptPointer: `current:${admitted.runDirectory}`
14979
15024
  });
14980
15025
  const coordinates = coordinatesFromAdmitted(authority, admitted);
15026
+ await clearOppositeTerminalArtifactFace(admitted.runDirectory);
14981
15027
  return withOptionalGateProjection(
14982
15028
  {
14983
15029
  roleOutcome: {
@@ -15248,6 +15294,9 @@ function explicitInternalKnownFailureClassificationInput(failure2) {
15248
15294
  function isMissingPathError4(error) {
15249
15295
  return error instanceof Error && "code" in error && error.code === "ENOENT";
15250
15296
  }
15297
+ function isAbsentFacePathError(error) {
15298
+ return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
15299
+ }
15251
15300
  function sessionReadFailure(error, fallbackMessage) {
15252
15301
  if (error instanceof SyntaxError) {
15253
15302
  const failed2 = new SyntaxError(
@@ -16006,43 +16055,60 @@ async function extractNavigatorFactFromAdmittedSession(sessionFile) {
16006
16055
  };
16007
16056
  }
16008
16057
  }
16009
- async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
16010
- await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
16011
- const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
16058
+ async function removeFaceIfPresent(path) {
16059
+ try {
16060
+ await rm3(path, { recursive: true, force: true });
16061
+ } catch (error) {
16062
+ if (isAbsentFacePathError(error)) return;
16063
+ throw error;
16064
+ }
16065
+ }
16066
+ async function clearOppositeTerminalArtifactFace(runDirectory) {
16067
+ const artifactsDir = roleRunArtifactsDirectory(runDirectory);
16068
+ for (const file of RUN_TERMINAL_ARTIFACT_FILES) {
16069
+ await removeFaceIfPresent(join28(artifactsDir, file));
16070
+ }
16071
+ for (const relative5 of RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS) {
16072
+ await removeFaceIfPresent(join28(runDirectory, relative5));
16073
+ }
16074
+ for (const path of await listSeamOwnedUniqueErrorFacePaths(runDirectory)) {
16075
+ await removeFaceIfPresent(path);
16076
+ }
16077
+ }
16078
+ async function ensureTerminalArtifactFace(runDirectory) {
16079
+ const artifactsDir = await ensureRunArtifactsDir(runDirectory);
16080
+ await clearOppositeTerminalArtifactFace(runDirectory);
16081
+ return artifactsDir;
16082
+ }
16083
+ function acceptedArtifactAttachmentRefs(attachments) {
16084
+ return attachments.map((a) => ({
16085
+ provenancePath: a.provenancePath,
16086
+ frozenPath: a.frozenPath,
16087
+ sha256: a.sha256,
16088
+ byteLength: a.byteLength
16089
+ }));
16090
+ }
16091
+ async function publishAcceptedTerminalArtifacts(admitted, roleOutcome, coordinates, bodies) {
16092
+ await appendRunAttemptHistory(
16093
+ {
16094
+ role: admitted.role,
16095
+ runId: admitted.runId,
16096
+ sessionFile: coordinates.sessionFile
16097
+ },
16098
+ roleOutcome
16099
+ );
16100
+ const artifactsDir = await ensureTerminalArtifactFace(admitted.runDirectory);
16012
16101
  const reportPath = join28(artifactsDir, "report.json");
16013
16102
  const evidencePath = join28(artifactsDir, "evidence.json");
16014
16103
  await writeFile7(
16015
16104
  reportPath,
16016
- `${JSON.stringify(
16017
- {
16018
- role: "judge",
16019
- runId: admitted.runId,
16020
- outcome: roleOutcome
16021
- },
16022
- null,
16023
- 2
16024
- )}
16105
+ `${JSON.stringify(bodies.report, null, 2)}
16025
16106
  `,
16026
16107
  "utf8"
16027
16108
  );
16028
16109
  await writeFile7(
16029
16110
  evidencePath,
16030
- `${JSON.stringify(
16031
- {
16032
- runId: admitted.runId,
16033
- sessionDirectory: coordinates.sessionDirectory,
16034
- sessionFile: coordinates.sessionFile,
16035
- admittedRequestPath: admitted.admittedRequestPath,
16036
- attachments: admitted.attachments.map((a) => ({
16037
- provenancePath: a.provenancePath,
16038
- frozenPath: a.frozenPath,
16039
- sha256: a.sha256,
16040
- byteLength: a.byteLength
16041
- }))
16042
- },
16043
- null,
16044
- 2
16045
- )}
16111
+ `${JSON.stringify(bodies.evidence, null, 2)}
16046
16112
  `,
16047
16113
  "utf8"
16048
16114
  );
@@ -16051,55 +16117,42 @@ async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
16051
16117
  { kind: "evidence", path: evidencePath }
16052
16118
  ];
16053
16119
  }
16120
+ async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
16121
+ return publishAcceptedTerminalArtifacts(admitted, roleOutcome, coordinates, {
16122
+ report: {
16123
+ role: "judge",
16124
+ runId: admitted.runId,
16125
+ outcome: roleOutcome
16126
+ },
16127
+ evidence: {
16128
+ runId: admitted.runId,
16129
+ sessionDirectory: coordinates.sessionDirectory,
16130
+ sessionFile: coordinates.sessionFile,
16131
+ admittedRequestPath: admitted.admittedRequestPath,
16132
+ attachments: acceptedArtifactAttachmentRefs(admitted.attachments)
16133
+ }
16134
+ });
16135
+ }
16054
16136
  async function publishCoderArtifacts(admitted, roleOutcome, coordinates, options = {}) {
16055
- await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
16056
- const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
16057
- const reportPath = join28(artifactsDir, "report.json");
16058
- const evidencePath = join28(artifactsDir, "evidence.json");
16059
- await writeFile7(
16060
- reportPath,
16061
- `${JSON.stringify(
16062
- {
16063
- role: "coder",
16064
- runId: admitted.runId,
16065
- phase: admitted.phase,
16066
- outcome: roleOutcome
16067
- },
16068
- null,
16069
- 2
16070
- )}
16071
- `,
16072
- "utf8"
16073
- );
16074
- await writeFile7(
16075
- evidencePath,
16076
- `${JSON.stringify(
16077
- {
16078
- runId: admitted.runId,
16079
- role: "coder",
16080
- phase: admitted.phase,
16081
- sessionDirectory: coordinates.sessionDirectory,
16082
- sessionFile: coordinates.sessionFile,
16083
- admittedRequestPath: admitted.admittedRequestPath,
16084
- taskPath: admitted.taskPath,
16085
- attachments: admitted.attachments.map((a) => ({
16086
- provenancePath: a.provenancePath,
16087
- frozenPath: a.frozenPath,
16088
- sha256: a.sha256,
16089
- byteLength: a.byteLength
16090
- })),
16091
- ...options.methodProvenance === void 0 ? {} : { methodProvenance: options.methodProvenance }
16092
- },
16093
- null,
16094
- 2
16095
- )}
16096
- `,
16097
- "utf8"
16098
- );
16099
- return [
16100
- { kind: "report", path: reportPath },
16101
- { kind: "evidence", path: evidencePath }
16102
- ];
16137
+ return publishAcceptedTerminalArtifacts(admitted, roleOutcome, coordinates, {
16138
+ report: {
16139
+ role: "coder",
16140
+ runId: admitted.runId,
16141
+ phase: admitted.phase,
16142
+ outcome: roleOutcome
16143
+ },
16144
+ evidence: {
16145
+ runId: admitted.runId,
16146
+ role: "coder",
16147
+ phase: admitted.phase,
16148
+ sessionDirectory: coordinates.sessionDirectory,
16149
+ sessionFile: coordinates.sessionFile,
16150
+ admittedRequestPath: admitted.admittedRequestPath,
16151
+ taskPath: admitted.taskPath,
16152
+ attachments: acceptedArtifactAttachmentRefs(admitted.attachments),
16153
+ ...options.methodProvenance === void 0 ? {} : { methodProvenance: options.methodProvenance }
16154
+ }
16155
+ });
16103
16156
  }
16104
16157
  async function readLawfulSettlementEntries(sessionFile) {
16105
16158
  try {
@@ -16210,59 +16263,30 @@ function extractFixerMethodInvocations(entries, options) {
16210
16263
  return Object.freeze(observed);
16211
16264
  }
16212
16265
  async function publishFixerArtifacts(admitted, roleOutcome, coordinates, options) {
16213
- await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
16214
- const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
16215
- const reportPath = join28(artifactsDir, "report.json");
16216
- const evidencePath = join28(artifactsDir, "evidence.json");
16217
- await writeFile7(
16218
- reportPath,
16219
- `${JSON.stringify(
16220
- {
16221
- role: "fixer",
16222
- runId: admitted.runId,
16223
- phase: admitted.phase,
16224
- outcome: roleOutcome
16225
- },
16226
- null,
16227
- 2
16228
- )}
16229
- `,
16230
- "utf8"
16231
- );
16232
- await writeFile7(
16233
- evidencePath,
16234
- `${JSON.stringify(
16235
- {
16236
- runId: admitted.runId,
16237
- role: "fixer",
16238
- phase: admitted.phase,
16239
- sessionDirectory: coordinates.sessionDirectory,
16240
- sessionFile: coordinates.sessionFile,
16241
- admittedRequestPath: admitted.admittedRequestPath,
16242
- packetPath: admitted.packetPath,
16243
- ...admitted.prerequisitesPath === void 0 ? {} : { prerequisitesPath: admitted.prerequisitesPath },
16244
- prerequisites: admitted.prerequisites,
16245
- attachments: admitted.attachments.map((a) => ({
16246
- provenancePath: a.provenancePath,
16247
- frozenPath: a.frozenPath,
16248
- sha256: a.sha256,
16249
- byteLength: a.byteLength
16250
- })),
16251
- methodProvenance: options.methodProvenance,
16252
- // Optional diagnosis: availability is package-bound; invocation only when observed.
16253
- methodInvocationObserved: (options.methodInvocations ?? []).length > 0,
16254
- methodInvocations: options.methodInvocations ?? []
16255
- },
16256
- null,
16257
- 2
16258
- )}
16259
- `,
16260
- "utf8"
16261
- );
16262
- return [
16263
- { kind: "report", path: reportPath },
16264
- { kind: "evidence", path: evidencePath }
16265
- ];
16266
+ return publishAcceptedTerminalArtifacts(admitted, roleOutcome, coordinates, {
16267
+ report: {
16268
+ role: "fixer",
16269
+ runId: admitted.runId,
16270
+ phase: admitted.phase,
16271
+ outcome: roleOutcome
16272
+ },
16273
+ evidence: {
16274
+ runId: admitted.runId,
16275
+ role: "fixer",
16276
+ phase: admitted.phase,
16277
+ sessionDirectory: coordinates.sessionDirectory,
16278
+ sessionFile: coordinates.sessionFile,
16279
+ admittedRequestPath: admitted.admittedRequestPath,
16280
+ packetPath: admitted.packetPath,
16281
+ ...admitted.prerequisitesPath === void 0 ? {} : { prerequisitesPath: admitted.prerequisitesPath },
16282
+ prerequisites: admitted.prerequisites,
16283
+ attachments: acceptedArtifactAttachmentRefs(admitted.attachments),
16284
+ methodProvenance: options.methodProvenance,
16285
+ // Optional diagnosis: availability is package-bound; invocation only when observed.
16286
+ methodInvocationObserved: (options.methodInvocations ?? []).length > 0,
16287
+ methodInvocations: options.methodInvocations ?? []
16288
+ }
16289
+ });
16266
16290
  }
16267
16291
  async function settleLawfulFixerTerminalResult(admitted, authority, options, scope) {
16268
16292
  const ledgerOutcome = await closedLedgerOutcome(admitted, "fixer", scope);
@@ -16308,53 +16332,24 @@ async function settleFixerTerminalResult(admitted, authority, options, scope) {
16308
16332
  return settled;
16309
16333
  }
16310
16334
  async function publishCollectorArtifacts(admitted, roleOutcome, coordinates) {
16311
- await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
16312
- const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
16313
- const reportPath = join28(artifactsDir, "report.json");
16314
- const evidencePath = join28(artifactsDir, "evidence.json");
16315
- await writeFile7(
16316
- reportPath,
16317
- `${JSON.stringify(
16318
- {
16319
- role: "collector",
16320
- runId: admitted.runId,
16321
- outcome: roleOutcome
16322
- },
16323
- null,
16324
- 2
16325
- )}
16326
- `,
16327
- "utf8"
16328
- );
16329
- await writeFile7(
16330
- evidencePath,
16331
- `${JSON.stringify(
16332
- {
16333
- runId: admitted.runId,
16334
- role: "collector",
16335
- ...admitted.prNumber === void 0 ? {} : { prNumber: admitted.prNumber },
16336
- repository: admitted.repository.canonical,
16337
- manifestDigest: admitted.manifestDigest,
16338
- sessionDirectory: coordinates.sessionDirectory,
16339
- sessionFile: coordinates.sessionFile,
16340
- admittedRequestPath: admitted.admittedRequestPath,
16341
- attachments: admitted.attachments.map((a) => ({
16342
- provenancePath: a.provenancePath,
16343
- frozenPath: a.frozenPath,
16344
- sha256: a.sha256,
16345
- byteLength: a.byteLength
16346
- }))
16347
- },
16348
- null,
16349
- 2
16350
- )}
16351
- `,
16352
- "utf8"
16353
- );
16354
- return [
16355
- { kind: "report", path: reportPath },
16356
- { kind: "evidence", path: evidencePath }
16357
- ];
16335
+ return publishAcceptedTerminalArtifacts(admitted, roleOutcome, coordinates, {
16336
+ report: {
16337
+ role: "collector",
16338
+ runId: admitted.runId,
16339
+ outcome: roleOutcome
16340
+ },
16341
+ evidence: {
16342
+ runId: admitted.runId,
16343
+ role: "collector",
16344
+ ...admitted.prNumber === void 0 ? {} : { prNumber: admitted.prNumber },
16345
+ repository: admitted.repository.canonical,
16346
+ manifestDigest: admitted.manifestDigest,
16347
+ sessionDirectory: coordinates.sessionDirectory,
16348
+ sessionFile: coordinates.sessionFile,
16349
+ admittedRequestPath: admitted.admittedRequestPath,
16350
+ attachments: acceptedArtifactAttachmentRefs(admitted.attachments)
16351
+ }
16352
+ });
16358
16353
  }
16359
16354
  async function settleLawfulCollectorTerminalResult(admitted, authority, scope) {
16360
16355
  const coordinates = coordinatesFromAdmitted(authority, admitted);
@@ -16441,55 +16436,26 @@ function extractDoctorCandidateAuditNoReceiptFact(entries) {
16441
16436
  return void 0;
16442
16437
  }
16443
16438
  async function publishDoctorArtifacts(admitted, roleOutcome, coordinates, options = {}) {
16444
- await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
16445
- const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
16446
- const reportPath = join28(artifactsDir, "report.json");
16447
- const evidencePath = join28(artifactsDir, "evidence.json");
16448
- await writeFile7(
16449
- reportPath,
16450
- `${JSON.stringify(
16451
- {
16452
- role: "doctor",
16453
- runId: admitted.runId,
16454
- outcome: roleOutcome,
16455
- ...options.cost === void 0 ? {} : { cost: options.cost },
16456
- ...options.auditNoReceipt === void 0 ? {} : { auditNoReceipt: options.auditNoReceipt }
16457
- },
16458
- null,
16459
- 2
16460
- )}
16461
- `,
16462
- "utf8"
16463
- );
16464
- await writeFile7(
16465
- evidencePath,
16466
- `${JSON.stringify(
16467
- {
16468
- runId: admitted.runId,
16469
- role: "doctor",
16470
- issueNumber: admitted.issueNumber,
16471
- caseRunsPath: admitted.caseRunsPath,
16472
- caseIdentity: admitted.caseIdentity,
16473
- sessionDirectory: coordinates.sessionDirectory,
16474
- sessionFile: coordinates.sessionFile,
16475
- admittedRequestPath: admitted.admittedRequestPath,
16476
- attachments: admitted.attachments.map((a) => ({
16477
- provenancePath: a.provenancePath,
16478
- frozenPath: a.frozenPath,
16479
- sha256: a.sha256,
16480
- byteLength: a.byteLength
16481
- }))
16482
- },
16483
- null,
16484
- 2
16485
- )}
16486
- `,
16487
- "utf8"
16488
- );
16489
- return [
16490
- { kind: "report", path: reportPath },
16491
- { kind: "evidence", path: evidencePath }
16492
- ];
16439
+ return publishAcceptedTerminalArtifacts(admitted, roleOutcome, coordinates, {
16440
+ report: {
16441
+ role: "doctor",
16442
+ runId: admitted.runId,
16443
+ outcome: roleOutcome,
16444
+ ...options.cost === void 0 ? {} : { cost: options.cost },
16445
+ ...options.auditNoReceipt === void 0 ? {} : { auditNoReceipt: options.auditNoReceipt }
16446
+ },
16447
+ evidence: {
16448
+ runId: admitted.runId,
16449
+ role: "doctor",
16450
+ issueNumber: admitted.issueNumber,
16451
+ caseRunsPath: admitted.caseRunsPath,
16452
+ caseIdentity: admitted.caseIdentity,
16453
+ sessionDirectory: coordinates.sessionDirectory,
16454
+ sessionFile: coordinates.sessionFile,
16455
+ admittedRequestPath: admitted.admittedRequestPath,
16456
+ attachments: acceptedArtifactAttachmentRefs(admitted.attachments)
16457
+ }
16458
+ });
16493
16459
  }
16494
16460
  async function settleLawfulDoctorTerminalResult(admitted, authority, scope) {
16495
16461
  const sealed = await sealedLedgerOutcome(admitted, "doctor", scope);
@@ -16555,6 +16521,22 @@ function currentAttemptStartIndex(entries) {
16555
16521
  }
16556
16522
  return 0;
16557
16523
  }
16524
+ async function publishSeatAcceptedArtifacts(admitted, roleOutcome, coordinates) {
16525
+ return publishAcceptedTerminalArtifacts(admitted, roleOutcome, coordinates, {
16526
+ report: {
16527
+ role: admitted.role,
16528
+ runId: admitted.runId,
16529
+ outcome: roleOutcome
16530
+ },
16531
+ evidence: {
16532
+ runId: admitted.runId,
16533
+ sessionDirectory: coordinates.sessionDirectory,
16534
+ sessionFile: coordinates.sessionFile,
16535
+ admittedRequestPath: admitted.admittedRequestPath,
16536
+ attachments: acceptedArtifactAttachmentRefs(admitted.attachments)
16537
+ }
16538
+ });
16539
+ }
16558
16540
  async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec, scope) {
16559
16541
  const coordinates = coordinatesFromAdmitted(authority, admitted);
16560
16542
  const { sessionDirectory, sessionFile } = coordinates;
@@ -16585,12 +16567,17 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
16585
16567
  const roleOutcome = await closedLedgerOutcome(admitted, spec.role, scope);
16586
16568
  if (roleOutcome !== void 0 && (thisAttemptHasSeatSuccess || residual === void 0)) {
16587
16569
  const navigator = extractNavigatorFact(entries);
16570
+ const artifacts = await publishSeatAcceptedArtifacts(
16571
+ admitted,
16572
+ roleOutcome,
16573
+ coordinates
16574
+ );
16588
16575
  return withSubmissions(
16589
16576
  await withOptionalGateProjection(
16590
16577
  {
16591
16578
  roleOutcome,
16592
16579
  navigator,
16593
- artifacts: [],
16580
+ artifacts,
16594
16581
  runId: admitted.runId
16595
16582
  },
16596
16583
  sessionDirectory,
@@ -16810,58 +16797,29 @@ function extractReviewerMethodInvocations(entries, options) {
16810
16797
  return Object.freeze(observed);
16811
16798
  }
16812
16799
  async function publishReviewerArtifacts(admitted, roleOutcome, coordinates, options) {
16813
- await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
16814
- const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
16815
- const reportPath = join28(artifactsDir, "report.json");
16816
- const evidencePath = join28(artifactsDir, "evidence.json");
16817
- await writeFile7(
16818
- reportPath,
16819
- `${JSON.stringify(
16820
- {
16821
- role: "reviewer",
16822
- runId: admitted.runId,
16823
- outcome: roleOutcome
16824
- },
16825
- null,
16826
- 2
16827
- )}
16828
- `,
16829
- "utf8"
16830
- );
16831
- await writeFile7(
16832
- evidencePath,
16833
- `${JSON.stringify(
16834
- {
16835
- runId: admitted.runId,
16836
- role: "reviewer",
16837
- sessionDirectory: coordinates.sessionDirectory,
16838
- sessionFile: coordinates.sessionFile,
16839
- admittedRequestPath: admitted.admittedRequestPath,
16840
- baseRevision: admitted.baseRevision,
16841
- lens: admitted.lens,
16842
- authorityRefs: [...admitted.authorityRefs],
16843
- ...admitted.instructionEmpty ? {} : { callerProvenance: admitted.instruction },
16844
- attachments: admitted.attachments.map((a) => ({
16845
- provenancePath: a.provenancePath,
16846
- frozenPath: a.frozenPath,
16847
- sha256: a.sha256,
16848
- byteLength: a.byteLength
16849
- })),
16850
- methodProvenance: options.methodProvenance,
16851
- // Forced package method: availability is package-bound; expansion only when observed.
16852
- methodInvocationObserved: (options.methodInvocations ?? []).length > 0,
16853
- methodInvocations: options.methodInvocations ?? []
16854
- },
16855
- null,
16856
- 2
16857
- )}
16858
- `,
16859
- "utf8"
16860
- );
16861
- return [
16862
- { kind: "report", path: reportPath },
16863
- { kind: "evidence", path: evidencePath }
16864
- ];
16800
+ return publishAcceptedTerminalArtifacts(admitted, roleOutcome, coordinates, {
16801
+ report: {
16802
+ role: "reviewer",
16803
+ runId: admitted.runId,
16804
+ outcome: roleOutcome
16805
+ },
16806
+ evidence: {
16807
+ runId: admitted.runId,
16808
+ role: "reviewer",
16809
+ sessionDirectory: coordinates.sessionDirectory,
16810
+ sessionFile: coordinates.sessionFile,
16811
+ admittedRequestPath: admitted.admittedRequestPath,
16812
+ baseRevision: admitted.baseRevision,
16813
+ lens: admitted.lens,
16814
+ authorityRefs: [...admitted.authorityRefs],
16815
+ ...admitted.instructionEmpty ? {} : { callerProvenance: admitted.instruction },
16816
+ attachments: acceptedArtifactAttachmentRefs(admitted.attachments),
16817
+ methodProvenance: options.methodProvenance,
16818
+ // Forced package method: availability is package-bound; expansion only when observed.
16819
+ methodInvocationObserved: (options.methodInvocations ?? []).length > 0,
16820
+ methodInvocations: options.methodInvocations ?? []
16821
+ }
16822
+ });
16865
16823
  }
16866
16824
  async function settleLawfulReviewerTerminalResult(admitted, authority, options, scope) {
16867
16825
  const sealed = await sealedLedgerOutcome(admitted, "reviewer", scope);
@@ -16926,55 +16884,26 @@ function extractMergerMethodInvocations(entries, options) {
16926
16884
  return Object.freeze(observed);
16927
16885
  }
16928
16886
  async function publishMergerArtifacts(admitted, roleOutcome, coordinates, options) {
16929
- await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
16930
- const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
16931
- const reportPath = join28(artifactsDir, "report.json");
16932
- const evidencePath = join28(artifactsDir, "evidence.json");
16933
- await writeFile7(
16934
- reportPath,
16935
- `${JSON.stringify(
16936
- {
16937
- role: "merger",
16938
- runId: admitted.runId,
16939
- outcome: roleOutcome
16940
- },
16941
- null,
16942
- 2
16943
- )}
16944
- `,
16945
- "utf8"
16946
- );
16947
- await writeFile7(
16948
- evidencePath,
16949
- `${JSON.stringify(
16950
- {
16951
- runId: admitted.runId,
16952
- role: "merger",
16953
- sessionDirectory: coordinates.sessionDirectory,
16954
- sessionFile: coordinates.sessionFile,
16955
- admittedRequestPath: admitted.admittedRequestPath,
16956
- mergerInputPath: admitted.mergerInputPath,
16957
- derived: admitted.derived,
16958
- attachments: admitted.attachments.map((a) => ({
16959
- provenancePath: a.provenancePath,
16960
- frozenPath: a.frozenPath,
16961
- sha256: a.sha256,
16962
- byteLength: a.byteLength
16963
- })),
16964
- methodProvenance: options.methodProvenance,
16965
- methodInvocationObserved: (options.methodInvocations ?? []).length > 0,
16966
- methodInvocations: options.methodInvocations ?? []
16967
- },
16968
- null,
16969
- 2
16970
- )}
16971
- `,
16972
- "utf8"
16973
- );
16974
- return [
16975
- { kind: "report", path: reportPath },
16976
- { kind: "evidence", path: evidencePath }
16977
- ];
16887
+ return publishAcceptedTerminalArtifacts(admitted, roleOutcome, coordinates, {
16888
+ report: {
16889
+ role: "merger",
16890
+ runId: admitted.runId,
16891
+ outcome: roleOutcome
16892
+ },
16893
+ evidence: {
16894
+ runId: admitted.runId,
16895
+ role: "merger",
16896
+ sessionDirectory: coordinates.sessionDirectory,
16897
+ sessionFile: coordinates.sessionFile,
16898
+ admittedRequestPath: admitted.admittedRequestPath,
16899
+ mergerInputPath: admitted.mergerInputPath,
16900
+ derived: admitted.derived,
16901
+ attachments: acceptedArtifactAttachmentRefs(admitted.attachments),
16902
+ methodProvenance: options.methodProvenance,
16903
+ methodInvocationObserved: (options.methodInvocations ?? []).length > 0,
16904
+ methodInvocations: options.methodInvocations ?? []
16905
+ }
16906
+ });
16978
16907
  }
16979
16908
  async function settleLawfulMergerTerminalResult(admitted, authority, options, scope) {
16980
16909
  const coordinates = coordinatesFromAdmitted(authority, admitted);
@@ -17121,6 +17050,16 @@ async function publishFailureArtifacts(admitted, failure2, authority) {
17121
17050
  admitted.runDirectory
17122
17051
  );
17123
17052
  const priorIssues = baseAttempt === void 0 ? [] : [baseAttempt];
17053
+ try {
17054
+ await clearOppositeTerminalArtifactFace(admitted.runDirectory);
17055
+ } catch (error) {
17056
+ priorIssues.push(
17057
+ publicationAttemptFromError(
17058
+ roleRunArtifactsDirectory(admitted.runDirectory),
17059
+ error
17060
+ )
17061
+ );
17062
+ }
17124
17063
  try {
17125
17064
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile }, {
17126
17065
  kind: "failure",
@@ -17209,33 +17148,41 @@ async function settleFailureTerminalResult(admitted, failure2, authority, option
17209
17148
  const lifecycleEntry = entries.slice(attemptStart).reverse().find((entry) => entry.customType === NO_RECEIPT_LIFECYCLE_ENTRY_TYPE || entry.message?.customType === NO_RECEIPT_LIFECYCLE_ENTRY_TYPE);
17210
17149
  const raw = lifecycleEntry?.data ?? lifecycleEntry?.message?.details;
17211
17150
  if (raw !== void 0) {
17151
+ let facts;
17212
17152
  try {
17213
- const facts = parseNoReceiptLifecycleFacts(raw);
17214
- if (facts.runPointer === admitted.runDirectory && facts.attemptPointer === `current:${admitted.runDirectory}`) {
17215
- let decisiveFacts2 = facts;
17216
- if (admitted.role === "collector") {
17217
- const bindRejection = extractCollectorTargetBindRejection(entries.slice(attemptStart));
17218
- if (bindRejection !== void 0) {
17219
- decisiveFacts2 = {
17220
- ...facts,
17221
- targetBindRejected: true,
17222
- targetBindDiagnostic: bindRejection.diagnostic,
17223
- ...bindRejection.code === void 0 ? {} : { targetBindCode: bindRejection.code }
17224
- };
17225
- }
17153
+ facts = parseNoReceiptLifecycleFacts(raw);
17154
+ } catch {
17155
+ }
17156
+ if (facts !== void 0 && facts.runPointer === admitted.runDirectory && facts.attemptPointer === `current:${admitted.runDirectory}`) {
17157
+ let decisiveFacts2 = facts;
17158
+ if (admitted.role === "collector") {
17159
+ const bindRejection = extractCollectorTargetBindRejection(entries.slice(attemptStart));
17160
+ if (bindRejection !== void 0) {
17161
+ decisiveFacts2 = {
17162
+ ...facts,
17163
+ targetBindRejected: true,
17164
+ targetBindDiagnostic: bindRejection.diagnostic,
17165
+ ...bindRejection.code === void 0 ? {} : { targetBindCode: bindRejection.code }
17166
+ };
17226
17167
  }
17227
- return withOptionalGateProjection(
17228
- {
17229
- roleOutcome: { kind: "no_receipt", role: admitted.role, status: "no-accepted-receipt", ...facts, decisiveFacts: decisiveFacts2 },
17230
- navigator: await extractNavigatorFactFromAdmittedSession(sessionFile),
17231
- artifacts: [],
17232
- runId: admitted.runId
17233
- },
17234
- sessionDirectory,
17235
- detourGateContext(admitted, options)
17236
- );
17237
17168
  }
17238
- } catch {
17169
+ await clearOppositeTerminalArtifactFace(admitted.runDirectory);
17170
+ return withOptionalGateProjection(
17171
+ {
17172
+ roleOutcome: {
17173
+ kind: "no_receipt",
17174
+ role: admitted.role,
17175
+ status: "no-accepted-receipt",
17176
+ ...facts,
17177
+ decisiveFacts: decisiveFacts2
17178
+ },
17179
+ navigator: await extractNavigatorFactFromAdmittedSession(sessionFile),
17180
+ artifacts: [],
17181
+ runId: admitted.runId
17182
+ },
17183
+ sessionDirectory,
17184
+ detourGateContext(admitted, options)
17185
+ );
17239
17186
  }
17240
17187
  }
17241
17188
  }
@@ -17386,6 +17333,7 @@ var init_settlement = __esm({
17386
17333
  init_navigator_invocation_identity();
17387
17334
  init_receipt_delivery_policy();
17388
17335
  init_role_run_placement();
17336
+ init_run_terminal_artifacts();
17389
17337
  init_invocation();
17390
17338
  init_terminal();
17391
17339
  NAVIGATOR_POST_ROLE_GRACE_MS = 1e4;
@@ -17437,7 +17385,7 @@ var init_seat_ticket_binding = __esm({
17437
17385
  });
17438
17386
 
17439
17387
  // src/session-identity.ts
17440
- import { mkdir as mkdir3, readFile as readFile17, rename as rename2, writeFile as writeFile8 } from "node:fs/promises";
17388
+ import { mkdir as mkdir2, readFile as readFile17, rename as rename2, writeFile as writeFile8 } from "node:fs/promises";
17441
17389
  import { dirname as dirname15, join as join29 } from "node:path";
17442
17390
  function createSessionIdentityAuthority(authority, sessionBindingFile) {
17443
17391
  const bindingPath = (principal) => join29(authority.decode(principal).sessionDirectory, sessionBindingFile);
@@ -17459,7 +17407,7 @@ function createSessionIdentityAuthority(authority, sessionBindingFile) {
17459
17407
  },
17460
17408
  async bind(principal, sessionId) {
17461
17409
  const target = bindingPath(principal);
17462
- await mkdir3(dirname15(target), { recursive: true });
17410
+ await mkdir2(dirname15(target), { recursive: true });
17463
17411
  const temporary = `${target}.${process.pid}.tmp`;
17464
17412
  await writeFile8(temporary, `${JSON.stringify({ sessionId })}
17465
17413
  `, { encoding: "utf8", mode: 384 });
@@ -18184,7 +18132,7 @@ __export(case_dossier_delivery_exports, {
18184
18132
  loadCaseDossierReadingMaterial: () => loadCaseDossierReadingMaterial,
18185
18133
  projectCaseDossierPointerSection: () => projectCaseDossierPointerSection
18186
18134
  });
18187
- import { mkdtemp as mkdtemp3, readFile as readFile19, rm as rm3, writeFile as writeFile9 } from "node:fs/promises";
18135
+ import { mkdtemp as mkdtemp3, readFile as readFile19, rm as rm4, writeFile as writeFile9 } from "node:fs/promises";
18188
18136
  import { tmpdir as tmpdir3 } from "node:os";
18189
18137
  import { join as join31 } from "node:path";
18190
18138
  async function projectCaseDossierPointerSection(input) {
@@ -18224,7 +18172,7 @@ async function deliverCaseDossierAsAttachment(input) {
18224
18172
  CASE_DOSSIER_ATTACH_KEY
18225
18173
  );
18226
18174
  } finally {
18227
- await rm3(stagingDir, { recursive: true, force: true });
18175
+ await rm4(stagingDir, { recursive: true, force: true });
18228
18176
  }
18229
18177
  }
18230
18178
  async function loadCaseDossierReadingMaterial(runDirectory) {
@@ -18372,7 +18320,7 @@ var init_process_cancel = __esm({
18372
18320
  // src/public-cli/auto-resume.ts
18373
18321
  import { constants as fsConstants2 } from "node:fs";
18374
18322
  import { randomUUID as randomUUID5 } from "node:crypto";
18375
- import { lstat as lstat6, mkdir as mkdir4, open as open2 } from "node:fs/promises";
18323
+ import { lstat as lstat6, mkdir as mkdir3, open as open2 } from "node:fs/promises";
18376
18324
  import { join as join33 } from "node:path";
18377
18325
  async function persistReturnedRunState(admitted, authority, options) {
18378
18326
  if (options?.lawful === true) {
@@ -18421,7 +18369,7 @@ async function ensureRealArtifactsDirectory(runDirectory) {
18421
18369
  }
18422
18370
  } catch (error) {
18423
18371
  if (!isMissingPathError5(error)) throw error;
18424
- await mkdir4(artifactsDir, { recursive: true });
18372
+ await mkdir3(artifactsDir, { recursive: true });
18425
18373
  const created = await lstat6(artifactsDir);
18426
18374
  if (created.isSymbolicLink() || !created.isDirectory()) {
18427
18375
  throw new Error("run artifact retention: artifacts directory is not a real directory");
@@ -20879,9 +20827,39 @@ function buildCountersignTurnRequest(admitted, options) {
20879
20827
  options
20880
20828
  );
20881
20829
  }
20882
- function courtTicketNumbersFromOutcome(roleOutcome, principalTicket) {
20830
+ function isRecord14(value) {
20831
+ return typeof value === "object" && value !== null && !Array.isArray(value);
20832
+ }
20833
+ function isEscalatePayload(payload) {
20834
+ if (!isRecord14(payload)) return false;
20835
+ return payload.status === "escalate" || payload.countersignStatus === "escalate";
20836
+ }
20837
+ function courtDiaristPayloadRows(roleOutcome, submissions) {
20838
+ if (roleOutcome === void 0) return submissions ?? [];
20839
+ if (roleOutcome.kind === "accepted" || roleOutcome.kind === "audit_escalation") {
20840
+ return roleOutcome.payloads ?? [];
20841
+ }
20842
+ if (roleOutcome.kind === "failure") return submissions ?? [];
20843
+ return [];
20844
+ }
20845
+ function courtDiaristEscalateDiagnostic(roleOutcome, submissions) {
20846
+ const payloads = courtDiaristPayloadRows(roleOutcome, submissions);
20847
+ const escalatePayloads = [];
20848
+ for (const payload of payloads) {
20849
+ if (isEscalatePayload(payload)) escalatePayloads.push(payload);
20850
+ }
20851
+ if (escalatePayloads.length === 0) return "court diarist station escalated";
20852
+ if (escalatePayloads.length === 1) {
20853
+ return `court diarist station escalated: ${readableGateItem(escalatePayloads[0])}`;
20854
+ }
20855
+ return `court diarist station escalated: ${readableGateItem({
20856
+ receipts: escalatePayloads,
20857
+ currentConclusion: escalatePayloads[escalatePayloads.length - 1]
20858
+ })}`;
20859
+ }
20860
+ function courtTicketNumbersFromOutcome(roleOutcome, principalTicket, submissions) {
20883
20861
  if (roleOutcome === void 0) return void 0;
20884
- const payloads = roleOutcome.kind === "accepted" || roleOutcome.kind === "audit_escalation" || roleOutcome.kind === "failure" ? roleOutcome.payloads ?? [] : [];
20862
+ const payloads = courtDiaristPayloadRows(roleOutcome, submissions);
20885
20863
  let latest;
20886
20864
  for (const payload of payloads) {
20887
20865
  if (typeof payload !== "object" || payload === null || Array.isArray(payload)) {
@@ -20907,12 +20885,7 @@ function courtDiaristEscalated(roleOutcome) {
20907
20885
  if (roleOutcome === void 0) return false;
20908
20886
  if (roleOutcome.kind === "audit_escalation") return true;
20909
20887
  if (roleOutcome.kind !== "accepted") return false;
20910
- return (roleOutcome.payloads ?? []).some((payload) => {
20911
- if (typeof payload !== "object" || payload === null || Array.isArray(payload))
20912
- return false;
20913
- const record4 = payload;
20914
- return record4.status === "escalate" || record4.countersignStatus === "escalate";
20915
- });
20888
+ return (roleOutcome.payloads ?? []).some(isEscalatePayload);
20916
20889
  }
20917
20890
  async function invokeCourtDiarist(input, env, io) {
20918
20891
  const quietIo = {
@@ -20946,9 +20919,13 @@ async function invokeCourtDiarist(input, env, io) {
20946
20919
  ...env.hostAdapters === void 0 ? {} : { hostAdapters: env.hostAdapters }
20947
20920
  });
20948
20921
  const roleOutcome = result.terminal?.roleOutcome;
20922
+ const submissions = result.terminal?.submissions;
20949
20923
  if (courtDiaristEscalated(roleOutcome)) {
20950
20924
  return {
20951
- identity: { kind: "escalate" }
20925
+ identity: {
20926
+ kind: "escalate",
20927
+ diagnostic: courtDiaristEscalateDiagnostic(roleOutcome, submissions)
20928
+ }
20952
20929
  };
20953
20930
  }
20954
20931
  if (result.exitCode !== 0) {
@@ -20964,7 +20941,8 @@ async function invokeCourtDiarist(input, env, io) {
20964
20941
  if (isSafePositiveTicketNumber(asserted)) {
20965
20942
  const courtTicketNumbers = courtTicketNumbersFromOutcome(
20966
20943
  roleOutcome,
20967
- asserted
20944
+ asserted,
20945
+ submissions
20968
20946
  );
20969
20947
  return {
20970
20948
  identity: {
@@ -21009,9 +20987,7 @@ async function runCountersignCourtDiaristStation(admitted, env, io) {
21009
20987
  io
21010
20988
  );
21011
20989
  if (outcome.identity.kind === "escalate") {
21012
- throw new StationChildExhaustedError(
21013
- "court diarist station escalated (cannot identify court target)"
21014
- );
20990
+ throw new StationChildExhaustedError(outcome.identity.diagnostic);
21015
20991
  }
21016
20992
  if (outcome.failedWithoutEscalate !== void 0) {
21017
20993
  throw new StationChildExhaustedError(
@@ -21102,9 +21078,7 @@ async function runPublicCountersign(argv, env, io, parseCountersignArgv2) {
21102
21078
  timedOut: false,
21103
21079
  code: null,
21104
21080
  stderr: "",
21105
- thrown: new Error(
21106
- "court diarist station escalated (cannot identify court target)"
21107
- )
21081
+ thrown: new Error(outcome.identity.diagnostic)
21108
21082
  },
21109
21083
  countersignAdapters(),
21110
21084
  env.principalAuthority,
@@ -21329,6 +21303,7 @@ var init_countersign_run = __esm({
21329
21303
  init_engine_material();
21330
21304
  init_cli_errors();
21331
21305
  init_diarist_contracts();
21306
+ init_readable_gate_item();
21332
21307
  init_run_ticket_number();
21333
21308
  init_invocation();
21334
21309
  init_post_admission();
@@ -21675,7 +21650,7 @@ __export(public_role_summons_exports, {
21675
21650
  });
21676
21651
  import { execFile as execFile3 } from "node:child_process";
21677
21652
  import { existsSync as existsSync11 } from "node:fs";
21678
- import { mkdir as mkdir5, mkdtemp as mkdtemp4, realpath as realpath6, rm as rm4 } from "node:fs/promises";
21653
+ import { mkdir as mkdir4, mkdtemp as mkdtemp4, realpath as realpath6, rm as rm5 } from "node:fs/promises";
21679
21654
  import { tmpdir as tmpdir4 } from "node:os";
21680
21655
  import { join as join35, relative as relative3, sep as sep5 } from "node:path";
21681
21656
  import { promisify as promisify3 } from "node:util";
@@ -22074,7 +22049,7 @@ async function openEphemeralReviewerWorktree(options) {
22074
22049
  }
22075
22050
  }
22076
22051
  try {
22077
- await rm4(root, { recursive: true, force: true });
22052
+ await rm5(root, { recursive: true, force: true });
22078
22053
  } catch (error) {
22079
22054
  cleanupErrors.push(error);
22080
22055
  }
@@ -22092,7 +22067,7 @@ async function openEphemeralReviewerWorktree(options) {
22092
22067
  });
22093
22068
  registered = true;
22094
22069
  if (projectRelative !== "") {
22095
- await mkdir5(reviewerSandboxPath(worktreeRoot, projectRelative), { recursive: true });
22070
+ await mkdir4(reviewerSandboxPath(worktreeRoot, projectRelative), { recursive: true });
22096
22071
  }
22097
22072
  } catch (error) {
22098
22073
  await rollback(error);
@@ -22112,7 +22087,7 @@ async function openEphemeralReviewerWorktree(options) {
22112
22087
  cleanupErrors.push(error);
22113
22088
  }
22114
22089
  try {
22115
- await rm4(root, { recursive: true, force: true });
22090
+ await rm5(root, { recursive: true, force: true });
22116
22091
  } catch (error) {
22117
22092
  cleanupErrors.push(error);
22118
22093
  }
@@ -22204,7 +22179,7 @@ async function summonParallelReviewerLenses(options) {
22204
22179
  });
22205
22180
  created.add(path);
22206
22181
  if (projectRelative !== "") {
22207
- await mkdir5(reviewerSandboxPath(path, projectRelative), { recursive: true });
22182
+ await mkdir4(reviewerSandboxPath(path, projectRelative), { recursive: true });
22208
22183
  }
22209
22184
  })
22210
22185
  );
@@ -22299,7 +22274,7 @@ ${describeFailure(error)}`;
22299
22274
  );
22300
22275
  const cleanupFailures = cleanup.flatMap((result) => result.status === "rejected" ? [result.reason] : []);
22301
22276
  if (cleanupFailures.length === 0) {
22302
- const rootCleanup = await Promise.allSettled([rm4(root, { recursive: true, force: true })]);
22277
+ const rootCleanup = await Promise.allSettled([rm5(root, { recursive: true, force: true })]);
22303
22278
  cleanupFailures.push(...rootCleanup.flatMap((result) => result.status === "rejected" ? [result.reason] : []));
22304
22279
  }
22305
22280
  if (cleanupFailures.length > 0) {
@@ -22404,7 +22379,7 @@ import { randomUUID as randomUUID10 } from "node:crypto";
22404
22379
  // src/role-envelope.ts
22405
22380
  init_engine_detour();
22406
22381
  import { randomUUID as randomUUID9 } from "node:crypto";
22407
- import { appendFile as appendFile3, mkdir as mkdir7, writeFile as writeFile12 } from "node:fs/promises";
22382
+ import { appendFile as appendFile3, mkdir as mkdir6, writeFile as writeFile12 } from "node:fs/promises";
22408
22383
  import { createServer } from "node:net";
22409
22384
  import { dirname as dirname21, join as join41 } from "node:path";
22410
22385
  import { fileURLToPath as fileURLToPath2 } from "node:url";
@@ -22502,7 +22477,7 @@ async function requireGatekeeperPass(options) {
22502
22477
  }
22503
22478
 
22504
22479
  // src/host-native-method.ts
22505
- import { lstat as lstat7, mkdir as mkdir6, readlink, realpath as realpath7, symlink } from "node:fs/promises";
22480
+ import { access as access4, lstat as lstat7, mkdir as mkdir5, readdir as readdir9, readFile as readFile20, readlink, realpath as realpath7, symlink } from "node:fs/promises";
22506
22481
  import { basename as basename9, dirname as dirname18, join as join36 } from "node:path";
22507
22482
  var packagedMethodsDir = (root) => join36(root, "resources", "methods");
22508
22483
  function hostMethodSkills(methods) {
@@ -22512,25 +22487,103 @@ function hostMethodSkills(methods) {
22512
22487
  return name ? [Object.freeze({ name })] : [];
22513
22488
  }));
22514
22489
  }
22490
+ var isEnoent4 = (error) => error.code === "ENOENT";
22491
+ async function packagedMethodSkillNames(packagedMethodsRealpath) {
22492
+ const entries = await readdir9(packagedMethodsRealpath, { withFileTypes: true });
22493
+ const names = [];
22494
+ for (const entry of entries) {
22495
+ if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
22496
+ try {
22497
+ await access4(join36(packagedMethodsRealpath, entry.name, "SKILL.md"));
22498
+ } catch (error) {
22499
+ if (isEnoent4(error)) continue;
22500
+ throw error;
22501
+ }
22502
+ names.push(entry.name);
22503
+ }
22504
+ return names;
22505
+ }
22506
+ async function packagedSkillFileBytes(skillDir) {
22507
+ try {
22508
+ await access4(join36(skillDir, "SKILL.md"));
22509
+ } catch (error) {
22510
+ if (isEnoent4(error)) return void 0;
22511
+ throw error;
22512
+ }
22513
+ const files = /* @__PURE__ */ new Map();
22514
+ async function walk(dir, prefix) {
22515
+ const entries = await readdir9(dir, { withFileTypes: true });
22516
+ for (const entry of entries) {
22517
+ const rel = prefix === "" ? entry.name : `${prefix}/${entry.name}`;
22518
+ const full = join36(dir, entry.name);
22519
+ if (entry.isDirectory()) {
22520
+ await walk(full, rel);
22521
+ continue;
22522
+ }
22523
+ if (entry.isFile()) {
22524
+ files.set(rel, await readFile20(full));
22525
+ }
22526
+ }
22527
+ }
22528
+ await walk(skillDir, "");
22529
+ return files;
22530
+ }
22531
+ async function catalogPublishesPackagedSkill(catalogSkillDir, required) {
22532
+ for (const [rel, bytes] of required) {
22533
+ let other;
22534
+ try {
22535
+ other = await readFile20(join36(catalogSkillDir, rel));
22536
+ } catch (error) {
22537
+ if (isEnoent4(error)) return false;
22538
+ throw error;
22539
+ }
22540
+ if (!bytes.equals(other)) return false;
22541
+ }
22542
+ return true;
22543
+ }
22544
+ async function isCompatibleMethodCatalog(link, packagedMethodsRealpath) {
22545
+ const stat2 = await lstat7(link);
22546
+ if (!stat2.isSymbolicLink()) return false;
22547
+ let resolved;
22548
+ try {
22549
+ resolved = await realpath7(link);
22550
+ } catch (error) {
22551
+ if (isEnoent4(error)) return false;
22552
+ throw error;
22553
+ }
22554
+ if (resolved === packagedMethodsRealpath) return true;
22555
+ const names = await packagedMethodSkillNames(packagedMethodsRealpath);
22556
+ if (names.length === 0) return false;
22557
+ for (const name of names) {
22558
+ const required = await packagedSkillFileBytes(join36(packagedMethodsRealpath, name));
22559
+ if (required === void 0) return false;
22560
+ if (!await catalogPublishesPackagedSkill(join36(resolved, name), required)) return false;
22561
+ }
22562
+ return true;
22563
+ }
22515
22564
  async function installWorkspaceMethodSkills(cwd, packageRoot) {
22516
22565
  const target = await realpath7(packagedMethodsDir(packageRoot));
22517
22566
  const link = join36(cwd, ".agents", "skills");
22567
+ let present;
22518
22568
  try {
22519
- const stat2 = await lstat7(link);
22520
- if (!stat2.isSymbolicLink() || await realpath7(link) !== target) {
22521
- const detail = stat2.isSymbolicLink() ? `symlink to ${await readlink(link)}` : "non-symlink entry";
22522
- throw new Error(`workspace method catalog conflict at ${link}: ${detail}`);
22523
- }
22524
- return;
22569
+ await lstat7(link);
22570
+ present = true;
22525
22571
  } catch (error) {
22526
- if (error.code !== "ENOENT") throw error;
22572
+ if (!isEnoent4(error)) throw error;
22573
+ present = false;
22527
22574
  }
22528
- await mkdir6(dirname18(link), { recursive: true });
22575
+ if (present) {
22576
+ if (await isCompatibleMethodCatalog(link, target)) return;
22577
+ const stat2 = await lstat7(link);
22578
+ const detail = stat2.isSymbolicLink() ? `symlink to ${await readlink(link)}` : "non-symlink entry";
22579
+ throw new Error(`workspace method catalog conflict at ${link}: ${detail}`);
22580
+ }
22581
+ await mkdir5(dirname18(link), { recursive: true });
22529
22582
  try {
22530
22583
  await symlink(target, link);
22531
22584
  } catch (error) {
22532
22585
  if (error.code !== "EEXIST") throw error;
22533
- if (await realpath7(link).catch(() => "") !== target) {
22586
+ if (!await isCompatibleMethodCatalog(link, target)) {
22534
22587
  throw new Error(`workspace method catalog conflict at ${link}`);
22535
22588
  }
22536
22589
  }
@@ -22968,6 +23021,7 @@ function registerEngineDetourTool(roleHost, hostActions) {
22968
23021
  }
22969
23022
 
22970
23023
  // src/role-runtime.ts
23024
+ init_readable_gate_item();
22971
23025
  init_run_terminal_artifacts();
22972
23026
  init_receipt_delivery_policy();
22973
23027
 
@@ -22977,12 +23031,12 @@ init_collector_evidence();
22977
23031
  init_collector_github();
22978
23032
 
22979
23033
  // src/collector-handbook.ts
22980
- import { readFile as readFile20 } from "node:fs/promises";
23034
+ import { readFile as readFile21 } from "node:fs/promises";
22981
23035
  import { join as join38, sep as sep6 } from "node:path";
22982
23036
 
22983
23037
  // src/atomic-write.ts
22984
23038
  import { randomUUID as randomUUID7 } from "node:crypto";
22985
- import { rename as rename3, rm as rm5, writeFile as writeFile11 } from "node:fs/promises";
23039
+ import { rename as rename3, rm as rm6, writeFile as writeFile11 } from "node:fs/promises";
22986
23040
  import { dirname as dirname19, join as join37 } from "node:path";
22987
23041
  async function writeFileAtomically(destination, contents) {
22988
23042
  const parent = dirname19(destination);
@@ -22991,7 +23045,7 @@ async function writeFileAtomically(destination, contents) {
22991
23045
  await writeFile11(temporary, contents);
22992
23046
  await rename3(temporary, destination);
22993
23047
  } catch (error) {
22994
- await rm5(temporary, { force: true }).catch(() => void 0);
23048
+ await rm6(temporary, { force: true }).catch(() => void 0);
22995
23049
  throw error;
22996
23050
  }
22997
23051
  }
@@ -23140,7 +23194,7 @@ function createCollectorHandbookStore(input) {
23140
23194
  ensureRealDirectoryTree(input.ledgerHome, parentDir2);
23141
23195
  assertLedgerFileInsideHome(path, input.ledgerHome);
23142
23196
  try {
23143
- const body = await readFile20(path, "utf8");
23197
+ const body = await readFile21(path, "utf8");
23144
23198
  assertHandbookBudget(body, "\u6B63\u6587");
23145
23199
  return body;
23146
23200
  } catch (error) {
@@ -24215,15 +24269,14 @@ function projectSecretariatSummonResult(summoned) {
24215
24269
  };
24216
24270
  }
24217
24271
  if (roleOutcome.kind === "failure") {
24218
- const payloads = Array.isArray(roleOutcome.payloads) ? roleOutcome.payloads : void 0;
24272
+ const submissions = Array.isArray(terminal?.submissions) ? terminal.submissions : void 0;
24219
24273
  return {
24220
24274
  ...base,
24221
24275
  outcomeKind: "failure",
24222
24276
  diagnostic: roleOutcome.diagnostic,
24223
24277
  ...roleOutcome.cause === void 0 ? {} : { cause: roleOutcome.cause },
24224
24278
  ...roleOutcome.decisiveFacts === void 0 ? {} : { decisiveFacts: roleOutcome.decisiveFacts },
24225
- ...payloads === void 0 ? {} : { payloads },
24226
- ...latestObjectPayload(payloads) === void 0 ? {} : { receipt: latestObjectPayload(payloads) }
24279
+ ...submissions === void 0 || submissions.length === 0 ? {} : { submissions }
24227
24280
  };
24228
24281
  }
24229
24282
  return {
@@ -24548,7 +24601,6 @@ function createNativeNavigatorSessionFactory(deps) {
24548
24601
  let providerFailure;
24549
24602
  let noReceipt;
24550
24603
  let disposed = false;
24551
- let inFlightPrompt;
24552
24604
  let hostRunId = readNavigatorHostRunPointer(sessionManager.getEntries());
24553
24605
  const summon = deps?.summonPublicRole ?? (async (options) => {
24554
24606
  const { summonPublicRole: summonPublicRole2 } = await Promise.resolve().then(() => (init_public_role_summons(), public_role_summons_exports));
@@ -24561,85 +24613,87 @@ function createNativeNavigatorSessionFactory(deps) {
24561
24613
  }
24562
24614
  providerFailure = void 0;
24563
24615
  noReceipt = void 0;
24564
- const run = (async () => {
24565
- try {
24566
- const summonHome = await resolveNavigatorLedgerHome(context);
24567
- const resumeRunId = hostRunId;
24568
- const baseSummon = {
24569
- role: "navigator",
24570
- argv: [text],
24571
- cwd: context.cwd,
24572
- ...summonHome === void 0 ? {} : { home: summonHome }
24573
- };
24574
- const resumable = deps?.hostRunResumable ?? navigatorHostRunResumable;
24575
- let summoned;
24576
- if (resumeRunId === void 0 || summonHome === void 0) {
24577
- summoned = await summon(baseSummon);
24578
- } else if (await resumable(summonHome, resumeRunId)) {
24616
+ try {
24617
+ const summonHome = await resolveNavigatorLedgerHome(context);
24618
+ if (disposed) return;
24619
+ const resumeRunId = hostRunId;
24620
+ const baseSummon = {
24621
+ role: "navigator",
24622
+ argv: [text],
24623
+ cwd: context.cwd,
24624
+ ...summonHome === void 0 ? {} : { home: summonHome },
24625
+ ...context.signal === void 0 ? {} : { signal: context.signal }
24626
+ };
24627
+ const resumable = deps?.hostRunResumable ?? navigatorHostRunResumable;
24628
+ let summoned;
24629
+ if (resumeRunId === void 0 || summonHome === void 0) {
24630
+ if (disposed) return;
24631
+ summoned = await summon(baseSummon);
24632
+ } else {
24633
+ const canResume = await resumable(summonHome, resumeRunId);
24634
+ if (disposed) return;
24635
+ if (canResume) {
24579
24636
  summoned = await summon({ ...baseSummon, resumeRunId });
24580
24637
  } else {
24581
24638
  hostRunId = void 0;
24582
24639
  summoned = await summon(baseSummon);
24583
24640
  }
24584
- const outcome = summoned.terminal?.roleOutcome;
24585
- if (outcome === void 0) {
24586
- const detail = summoned.stderr?.trim() || `exit ${summoned.exitCode}`;
24587
- providerFailure = { source: "transport", cause: "unknown" };
24588
- throw navigatorUnavailableError(
24589
- providerFailure.source,
24590
- new Error(`Navigator public summon produced no terminal (${detail})`),
24591
- providerFailure.cause
24592
- );
24593
- }
24594
- if (outcome.kind === "failure") {
24595
- providerFailure = navigatorProviderFailureFromPublicTerminal(outcome);
24596
- throw navigatorUnavailableError(
24597
- providerFailure.source,
24598
- new Error(outcome.diagnostic),
24599
- providerFailure.cause
24600
- );
24601
- }
24602
- if (outcome.kind === "no_receipt") {
24603
- noReceipt = outcome;
24604
- return;
24605
- }
24606
- const runDirectory = summoned.runDirectory ?? (typeof summoned.admitted?.runDirectory === "string" ? summoned.admitted.runDirectory : void 0);
24607
- if (typeof runDirectory === "string" && runDirectory.trim() !== "") {
24608
- const nextRunId = runIdFromNavigatorDirectory(runDirectory);
24609
- if (nextRunId !== void 0) {
24610
- hostRunId = nextRunId;
24611
- sessionManager.appendCustomEntry(NAVIGATOR_HOST_RUN_POINTER_ENTRY, { runId: nextRunId });
24612
- }
24613
- }
24614
- if (outcome.kind !== "accepted") {
24615
- return;
24616
- }
24617
- const { navigatorProseFromUnknown: navigatorProseFromUnknown2 } = await Promise.resolve().then(() => (init_navigator_output(), navigator_output_exports));
24618
- const proseParts = [];
24619
- for (const payload of outcome.payloads ?? []) {
24620
- const prose = navigatorProseFromUnknown2(payload);
24621
- if (prose !== void 0) proseParts.push(prose);
24622
- }
24623
- if (proseParts.length === 0) return;
24624
- await tool.execute(
24625
- "navigator-public-prepare",
24626
- { prose: proseParts.join("\n\n") },
24627
- void 0,
24628
- void 0,
24629
- context
24641
+ }
24642
+ if (disposed) return;
24643
+ const outcome = summoned.terminal?.roleOutcome;
24644
+ if (outcome === void 0) {
24645
+ const detail = summoned.stderr?.trim() || `exit ${summoned.exitCode}`;
24646
+ providerFailure = { source: "transport", cause: "unknown" };
24647
+ throw navigatorUnavailableError(
24648
+ providerFailure.source,
24649
+ new Error(`Navigator public summon produced no terminal (${detail})`),
24650
+ providerFailure.cause
24630
24651
  );
24631
- } catch (error) {
24632
- if (error instanceof NavigatorUnavailableError) throw error;
24633
- const fact = navigatorProviderFailureFromError(error);
24634
- providerFailure = fact ?? { source: "transport", cause: "unknown" };
24635
- throw navigatorUnavailableError(providerFailure.source, error, providerFailure.cause);
24636
24652
  }
24637
- })();
24638
- inFlightPrompt = run;
24639
- try {
24640
- await run;
24641
- } finally {
24642
- if (inFlightPrompt === run) inFlightPrompt = void 0;
24653
+ if (outcome.kind === "failure") {
24654
+ providerFailure = navigatorProviderFailureFromPublicTerminal(outcome);
24655
+ throw navigatorUnavailableError(
24656
+ providerFailure.source,
24657
+ new Error(outcome.diagnostic),
24658
+ providerFailure.cause
24659
+ );
24660
+ }
24661
+ if (outcome.kind === "no_receipt") {
24662
+ noReceipt = outcome;
24663
+ return;
24664
+ }
24665
+ const runDirectory = summoned.runDirectory ?? (typeof summoned.admitted?.runDirectory === "string" ? summoned.admitted.runDirectory : void 0);
24666
+ if (typeof runDirectory === "string" && runDirectory.trim() !== "") {
24667
+ const nextRunId = runIdFromNavigatorDirectory(runDirectory);
24668
+ if (nextRunId !== void 0) {
24669
+ hostRunId = nextRunId;
24670
+ sessionManager.appendCustomEntry(NAVIGATOR_HOST_RUN_POINTER_ENTRY, { runId: nextRunId });
24671
+ }
24672
+ }
24673
+ if (outcome.kind !== "accepted") {
24674
+ return;
24675
+ }
24676
+ const { navigatorProseFromUnknown: navigatorProseFromUnknown2 } = await Promise.resolve().then(() => (init_navigator_output(), navigator_output_exports));
24677
+ const proseParts = [];
24678
+ for (const payload of outcome.payloads ?? []) {
24679
+ const prose = navigatorProseFromUnknown2(payload);
24680
+ if (prose !== void 0) proseParts.push(prose);
24681
+ }
24682
+ if (proseParts.length === 0) return;
24683
+ if (disposed) return;
24684
+ await tool.execute(
24685
+ "navigator-public-prepare",
24686
+ { prose: proseParts.join("\n\n") },
24687
+ void 0,
24688
+ void 0,
24689
+ context
24690
+ );
24691
+ } catch (error) {
24692
+ if (disposed) return;
24693
+ if (error instanceof NavigatorUnavailableError) throw error;
24694
+ const fact = navigatorProviderFailureFromError(error);
24695
+ providerFailure = fact ?? { source: "transport", cause: "unknown" };
24696
+ throw navigatorUnavailableError(providerFailure.source, error, providerFailure.cause);
24643
24697
  }
24644
24698
  },
24645
24699
  providerFailure: () => providerFailure,
@@ -24672,8 +24726,6 @@ function createNativeNavigatorSessionFactory(deps) {
24672
24726
  recordPointer: () => sessionManager.getSessionDir(),
24673
24727
  dispose: async () => {
24674
24728
  disposed = true;
24675
- const pending = inFlightPrompt;
24676
- if (pending !== void 0) await pending.catch(() => void 0);
24677
24729
  }
24678
24730
  };
24679
24731
  };
@@ -24785,7 +24837,14 @@ function createNavigatorAttendance(options) {
24785
24837
  let preparationFailure;
24786
24838
  let routePlaybookReadFailure;
24787
24839
  let disposed = false;
24840
+ let closing;
24841
+ const nestCancel = new AbortController();
24788
24842
  let warmedHelp;
24843
+ const sessionHostContext = () => {
24844
+ const parentSignal = options.context.signal;
24845
+ const signal = parentSignal === void 0 ? nestCancel.signal : AbortSignal.any([nestCancel.signal, parentSignal]);
24846
+ return { ...options.context, signal };
24847
+ };
24789
24848
  const loadLiveHelp = async () => {
24790
24849
  try {
24791
24850
  return await Promise.all(
@@ -24875,7 +24934,7 @@ ${text}
24875
24934
  let created;
24876
24935
  try {
24877
24936
  created = await options.createSession({
24878
- context: options.context,
24937
+ context: sessionHostContext(),
24879
24938
  subject: subjectKey,
24880
24939
  ...options.modelSettingPath === void 0 ? {} : { modelSettingPath: options.modelSettingPath },
24881
24940
  tool
@@ -25072,17 +25131,17 @@ ${helpContext}
25072
25131
  };
25073
25132
  return {
25074
25133
  setWorkContext(next) {
25075
- let closing;
25134
+ let closing2;
25076
25135
  if (next.subjectKey !== subjectKey && session !== void 0) {
25077
25136
  const previous = session;
25078
25137
  session = void 0;
25079
- closing = previous.dispose();
25138
+ closing2 = previous.dispose();
25080
25139
  }
25081
25140
  subjectKey = next.subjectKey;
25082
25141
  subject = next.subject;
25083
25142
  authority = next.authority;
25084
25143
  contextError = next.contextError;
25085
- return closing;
25144
+ return closing2;
25086
25145
  },
25087
25146
  /**
25088
25147
  * Start live-help subprocesses during activation without beginning full
@@ -25120,10 +25179,19 @@ ${helpContext}
25120
25179
  },
25121
25180
  dispose() {
25122
25181
  disposed = true;
25123
- const current = session;
25124
- session = void 0;
25182
+ if (!nestCancel.signal.aborted) {
25183
+ nestCancel.abort(navigatorUnavailableError(
25184
+ "session",
25185
+ new Error("Navigator attendance was disposed")
25186
+ ));
25187
+ }
25125
25188
  activeInvocationId = void 0;
25126
- return current?.dispose();
25189
+ if (closing === void 0) {
25190
+ const current = session;
25191
+ session = void 0;
25192
+ closing = Promise.resolve(current?.dispose()).then(() => void 0);
25193
+ }
25194
+ return closing;
25127
25195
  }
25128
25196
  };
25129
25197
  async function settleOnce(settlement) {
@@ -25535,7 +25603,7 @@ function uninstallPackageWorkerHooks(cwd) {
25535
25603
  rmOwnedDir(resolve17(gitDir, HOOKS_DIR));
25536
25604
  }
25537
25605
  }
25538
- function isRecord14(value) {
25606
+ function isRecord15(value) {
25539
25607
  return typeof value === "object" && value !== null && !Array.isArray(value);
25540
25608
  }
25541
25609
  function unfinishedReasonPresent(details) {
@@ -25551,7 +25619,7 @@ function readGateState(session) {
25551
25619
  if (entry.type !== "custom") continue;
25552
25620
  if (entry.customType === WORKER_COMMIT_BASELINE_ENTRY_TYPE) {
25553
25621
  const data = entry.data;
25554
- if (isRecord14(data) && (data.head === null || typeof data.head === "string")) {
25622
+ if (isRecord15(data) && (data.head === null || typeof data.head === "string")) {
25555
25623
  baseline = data.head;
25556
25624
  }
25557
25625
  } else if (entry.customType === WORKER_COMMIT_REMINDER_BOUNCE_ENTRY_TYPE) {
@@ -26709,10 +26777,13 @@ function createSecretariatRoleRuntime(roleHost, dependencies, hostActions) {
26709
26777
  ...dependencies.packageRoot === void 0 ? {} : { packageRoot: dependencies.packageRoot }
26710
26778
  });
26711
26779
  const details = projectSecretariatSummonResult(summoned);
26712
- const outcomeKind = typeof details.outcomeKind === "string" ? details.outcomeKind : "unknown";
26713
- const contentText = outcomeKind === "accepted" || outcomeKind === "audit_escalation" ? "\u7ED9\u4E8B\u4E2D\u56DE\u6267\u5DF2\u9001\u8FBE\u4E2D\u4E66\u7701" : outcomeKind === "failure" ? "\u7ED9\u4E8B\u4E2D\u4F20\u53EC\u5931\u8D25" : outcomeKind === "no_receipt" ? "\u7ED9\u4E8B\u4E2D\u65E0\u56DE\u6267" : "\u7ED9\u4E8B\u4E2D\u4F20\u53EC\u672A\u5F97\u7EC8\u5C40";
26714
26780
  return {
26715
- content: [{ type: "text", text: contentText }],
26781
+ content: [
26782
+ {
26783
+ type: "text",
26784
+ text: readableGateItem(details)
26785
+ }
26786
+ ],
26716
26787
  details
26717
26788
  };
26718
26789
  }
@@ -26843,6 +26914,38 @@ function createRoleRuntimeExtension(dependencies) {
26843
26914
  let noReceiptRecorded = false;
26844
26915
  let priorFetch;
26845
26916
  let fetchWrapped = false;
26917
+ const disposeNavigatorAttendanceNonBlocking = (attendance) => {
26918
+ if (attendance === void 0) return;
26919
+ const recordDisposeFailure = (error) => {
26920
+ const diagnostic = error instanceof Error ? error.message : String(error);
26921
+ try {
26922
+ sitianReport({
26923
+ level: "event",
26924
+ kind: "navigator-dispose-failure",
26925
+ cwd: navigatorCwd,
26926
+ sessionParent: navigatorSessionParent,
26927
+ payload: { diagnostic },
26928
+ source: "role-runtime"
26929
+ });
26930
+ } catch (recordError) {
26931
+ try {
26932
+ envelopeHost.appendEntry?.("ak-navigator-dispose-failure", {
26933
+ diagnostic,
26934
+ recordFailure: recordError instanceof Error ? recordError.message : String(recordError)
26935
+ });
26936
+ } catch {
26937
+ }
26938
+ }
26939
+ };
26940
+ let pending;
26941
+ try {
26942
+ pending = attendance.dispose();
26943
+ } catch (error) {
26944
+ recordDisposeFailure(error);
26945
+ return;
26946
+ }
26947
+ void Promise.resolve(pending).then(void 0, recordDisposeFailure);
26948
+ };
26846
26949
  const settleNavigatorProjection = async (settlement) => {
26847
26950
  const attendance = navigatorAttendance;
26848
26951
  if (settlement === void 0 || attendance === void 0) return;
@@ -26875,27 +26978,7 @@ function createRoleRuntimeExtension(dependencies) {
26875
26978
  };
26876
26979
  pendingNavigatorPresentation = { event, report };
26877
26980
  }
26878
- void Promise.resolve(attendance.dispose()).then(
26879
- void 0,
26880
- (error) => {
26881
- const diagnostic = error instanceof Error ? error.message : String(error);
26882
- try {
26883
- sitianReport({
26884
- level: "event",
26885
- kind: "navigator-dispose-failure",
26886
- cwd: navigatorCwd,
26887
- sessionParent: navigatorSessionParent,
26888
- payload: { diagnostic },
26889
- source: "role-runtime"
26890
- });
26891
- } catch (recordError) {
26892
- envelopeHost.appendEntry?.("ak-navigator-dispose-failure", {
26893
- diagnostic,
26894
- recordFailure: recordError instanceof Error ? recordError.message : String(recordError)
26895
- });
26896
- }
26897
- }
26898
- );
26981
+ disposeNavigatorAttendanceNonBlocking(attendance);
26899
26982
  })();
26900
26983
  pendingNavigatorSettlement = pending;
26901
26984
  await pending;
@@ -27177,9 +27260,10 @@ function createRoleRuntimeExtension(dependencies) {
27177
27260
  } catch {
27178
27261
  }
27179
27262
  }
27180
- await navigatorAttendance?.dispose();
27263
+ const attendanceToDispose = navigatorAttendance;
27181
27264
  navigatorAttendance = void 0;
27182
27265
  pendingNavigatorSettlement = void 0;
27266
+ disposeNavigatorAttendanceNonBlocking(attendanceToDispose);
27183
27267
  pendingInfrastructureFailures.clear();
27184
27268
  pendingSubmissionNonPassByToolCallId.clear();
27185
27269
  observationFace.reset();
@@ -27721,9 +27805,9 @@ async function prepareRoleEnvelope(options) {
27721
27805
  let infrastructureRoundFailure;
27722
27806
  const hostAbort = new AbortController();
27723
27807
  const runId = request.runDirectory.split("/").filter(Boolean).at(-1) ?? randomUUID9();
27724
- await mkdir7(request.runDirectory, { recursive: true });
27808
+ await mkdir6(request.runDirectory, { recursive: true });
27725
27809
  let sessionFile = options.sessionFile ?? join41(request.runDirectory, "session", "session.jsonl");
27726
- await mkdir7(dirname21(sessionFile), { recursive: true });
27810
+ await mkdir6(dirname21(sessionFile), { recursive: true });
27727
27811
  if (request.continuation.kind !== "resume") {
27728
27812
  try {
27729
27813
  await writeFile12(
@@ -28266,11 +28350,11 @@ async function prepareRoleEnvelope(options) {
28266
28350
  }
28267
28351
 
28268
28352
  // src/role-runtime-dependencies.ts
28269
- import { readFile as readFile23 } from "node:fs/promises";
28353
+ import { readFile as readFile24 } from "node:fs/promises";
28270
28354
  import { join as join42 } from "node:path";
28271
28355
 
28272
28356
  // src/canonical-skill-binding.ts
28273
- import { readFile as readFile21, realpath as realpath8 } from "node:fs/promises";
28357
+ import { readFile as readFile22, realpath as realpath8 } from "node:fs/promises";
28274
28358
  import { homedir } from "node:os";
28275
28359
  import { dirname as dirname22, resolve as resolve18 } from "node:path";
28276
28360
  import { stripFrontmatter } from "@earendil-works/pi-coding-agent";
@@ -28303,7 +28387,7 @@ async function loadCanonicalSkillBinding(name) {
28303
28387
  let raw;
28304
28388
  try {
28305
28389
  path = await realpath8(configuredPath);
28306
- raw = await readFile21(path, "utf8");
28390
+ raw = await readFile22(path, "utf8");
28307
28391
  } catch (error) {
28308
28392
  throw new CanonicalSkillUnavailableError(name, configuredPath, error);
28309
28393
  }
@@ -28342,7 +28426,7 @@ init_doctor_evidence();
28342
28426
  // src/navigator-work-context.ts
28343
28427
  init_doctor_evidence();
28344
28428
  init_host_contracts();
28345
- import { readFile as readFile22 } from "node:fs/promises";
28429
+ import { readFile as readFile23 } from "node:fs/promises";
28346
28430
  import { resolve as resolve19 } from "node:path";
28347
28431
  init_notary_source_run();
28348
28432
  init_packaged_role_registry();
@@ -28355,7 +28439,7 @@ function navigatorInputReference(getFlag, role) {
28355
28439
  }
28356
28440
  async function loadNavigatorWorkContext(options) {
28357
28441
  const reference = navigatorInputReference(options.getFlag, options.role);
28358
- const input = reference === void 0 || options.role === "doctor" || options.role === "notary" ? void 0 : await readFile22(reference, "utf8");
28442
+ const input = reference === void 0 || options.role === "doctor" || options.role === "notary" ? void 0 : await readFile23(reference, "utf8");
28359
28443
  const subjectRoot = subjectPath(reference ?? options.context.sessionManager.getSessionDir(), options.context.cwd);
28360
28444
  let subjectKey = reference === void 0 ? subjectRoot : navigatorSubjectKeyForInput(subjectRoot, reference, options.context.cwd);
28361
28445
  let subject = input ?? `work subject: ${subjectKey}`;
@@ -28412,7 +28496,7 @@ async function loadNavigatorWorkContext(options) {
28412
28496
  let authorityMaterial;
28413
28497
  for (const path of authorityFiles) {
28414
28498
  try {
28415
- const content = await readFile22(path, "utf8");
28499
+ const content = await readFile23(path, "utf8");
28416
28500
  if (content.trim() !== "") {
28417
28501
  authorityMaterial = content;
28418
28502
  break;
@@ -28481,12 +28565,12 @@ function createRoleRuntimeDependencies(packageRoot) {
28481
28565
  loadRoleReferenceMaterials: loadPackagedRoleReferenceMaterials,
28482
28566
  loadJudgeSoul: () => loadMainRoleSessionMaterials("judge"),
28483
28567
  loadFixerSoul: () => loadMainRoleSessionMaterials("fixer"),
28484
- loadFixPacket: (path) => readFile23(path, "utf8"),
28568
+ loadFixPacket: (path) => readFile24(path, "utf8"),
28485
28569
  loadCoderSoul: () => loadMainRoleSessionMaterials("coder"),
28486
- loadCoderTask: (path) => readFile23(path, "utf8"),
28570
+ loadCoderTask: (path) => readFile24(path, "utf8"),
28487
28571
  loadReviewerSoul: () => loadMainRoleSessionMaterials("reviewer"),
28488
28572
  loadCollectorSoul: () => loadMainRoleSessionMaterials("collector"),
28489
- loadCollectorHandbookSeed: () => readFile23(collectorHandbookSeedPath, "utf8"),
28573
+ loadCollectorHandbookSeed: () => readFile24(collectorHandbookSeedPath, "utf8"),
28490
28574
  createCollectorTransport: () => createGhCollectorGitHubTransport(),
28491
28575
  loadDoctorSoul: () => loadMainRoleSessionMaterials("doctor"),
28492
28576
  loadDoctorCase,
@@ -28501,7 +28585,7 @@ function createRoleRuntimeDependencies(packageRoot) {
28501
28585
  loadSecretariatSoul: () => loadMainRoleSessionMaterials("secretariat"),
28502
28586
  loadNotarySourceRun: loadNotarySourceRunLocator,
28503
28587
  loadMergerSoul: () => loadMainRoleSessionMaterials("merger"),
28504
- loadMergerInput: async (path) => JSON.parse(await readFile23(path, "utf8")),
28588
+ loadMergerInput: async (path) => JSON.parse(await readFile24(path, "utf8")),
28505
28589
  async loadCanonicalSkillBinding(name) {
28506
28590
  if (name === "tdd") {
28507
28591
  return loadPackagedCanonicalSkillBinding(packageRoot, "tdd");
@@ -28527,7 +28611,7 @@ function createRoleRuntimeDependencies(packageRoot) {
28527
28611
  authority: options.authority,
28528
28612
  invocationId: options.invocationId,
28529
28613
  loadSoul: () => loadMainRoleSessionMaterials("navigator"),
28530
- loadRoutePlaybook: () => readFile23(navigatorRoutePlaybookPath, "utf8"),
28614
+ loadRoutePlaybook: () => readFile24(navigatorRoutePlaybookPath, "utf8"),
28531
28615
  loadRoleHelp: async (role) => formatNavigatorRoleHelp(role),
28532
28616
  createSession: navigatorSessionFactory,
28533
28617
  ...options.contextError === void 0 ? {} : { contextError: options.contextError },
@@ -29106,7 +29190,7 @@ function createAcpRoleTurnHost(config) {
29106
29190
 
29107
29191
  // src/acp-host/seat-profile-soul.ts
29108
29192
  import { constants as constants2 } from "node:fs";
29109
- import { access as access4, copyFile, lstat as lstat8, mkdir as mkdir8, readlink as readlink2, symlink as symlink2, unlink as unlink3 } from "node:fs/promises";
29193
+ import { access as access5, copyFile, lstat as lstat8, mkdir as mkdir7, readlink as readlink2, symlink as symlink2, unlink as unlink4 } from "node:fs/promises";
29110
29194
  import { dirname as dirname24, join as join44, relative as relative4, resolve as resolve20 } from "node:path";
29111
29195
  function seatProfileName(spec, role) {
29112
29196
  return `${spec.namePrefix}${role}`;
@@ -29116,7 +29200,7 @@ function packageRoleSoulPath(packageRoot, role) {
29116
29200
  }
29117
29201
  async function pathExists2(path) {
29118
29202
  try {
29119
- await access4(path, constants2.F_OK);
29203
+ await access5(path, constants2.F_OK);
29120
29204
  return true;
29121
29205
  } catch {
29122
29206
  return false;
@@ -29134,14 +29218,14 @@ async function ensureSeatProfileSoul(options) {
29134
29218
  const hostRoot = dirname24(profilesRoot);
29135
29219
  const soulPath = join44(profileDir, spec.soulFileName);
29136
29220
  if (!await pathExists2(profileDir)) {
29137
- await mkdir8(profileDir, { recursive: true });
29221
+ await mkdir7(profileDir, { recursive: true });
29138
29222
  for (const name of ["auth.json", ".env", "config.yaml"]) {
29139
29223
  const source = join44(hostRoot, name);
29140
29224
  if (!await pathExists2(source)) continue;
29141
29225
  await copyFile(source, join44(profileDir, name));
29142
29226
  }
29143
29227
  } else {
29144
- await mkdir8(profileDir, { recursive: true });
29228
+ await mkdir7(profileDir, { recursive: true });
29145
29229
  }
29146
29230
  const desiredLink = relative4(profileDir, soulTarget);
29147
29231
  let current;
@@ -29157,7 +29241,7 @@ async function ensureSeatProfileSoul(options) {
29157
29241
  return profileName;
29158
29242
  }
29159
29243
  if (await pathExists2(soulPath) || current !== void 0) {
29160
- await unlink3(soulPath);
29244
+ await unlink4(soulPath);
29161
29245
  }
29162
29246
  await symlink2(desiredLink, soulPath);
29163
29247
  return profileName;