@akagilnc/pi-workflow-roles 0.1.3280 → 0.1.3353

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +5 -5
  2. package/README.zh-CN.md +5 -5
  3. package/dist/audit-escalation.js +31 -4
  4. package/dist/gatekeeper-role.js +25 -4
  5. package/dist/grok/production-host.js +1167 -862
  6. package/dist/inspector-contracts.js +5 -2
  7. package/dist/notary-contracts.js +16 -5
  8. package/dist/packaged-role-registry.js +0 -7
  9. package/dist/public-cli/main.js +867 -757
  10. package/package.json +1 -1
  11. package/src/audit-escalation.ts +52 -8
  12. package/src/collector-ledger.ts +309 -74
  13. package/src/collector-receipt.ts +0 -1
  14. package/src/collector-role.ts +21 -14
  15. package/src/diarist-mechanical.ts +16 -5
  16. package/src/gatekeeper-role.ts +33 -4
  17. package/src/grok/role-envelope.ts +68 -52
  18. package/src/inspector-contracts.ts +6 -3
  19. package/src/inspector-role.ts +5 -2
  20. package/src/notary-contracts.ts +20 -5
  21. package/src/notary-role.ts +2 -2
  22. package/src/packaged-role-registry.ts +0 -12
  23. package/src/public-cli/cli.ts +50 -125
  24. package/src/public-cli/coder-run.ts +5 -19
  25. package/src/public-cli/collector-run.ts +65 -21
  26. package/src/public-cli/countersign-run.ts +14 -40
  27. package/src/public-cli/doctor-run.ts +50 -6
  28. package/src/public-cli/fixer-run.ts +5 -19
  29. package/src/public-cli/gleaner-left-run.ts +14 -40
  30. package/src/public-cli/inspector-run.ts +51 -7
  31. package/src/public-cli/instruction-seat-run.ts +27 -0
  32. package/src/public-cli/judge-run.ts +11 -36
  33. package/src/public-cli/merger-run.ts +5 -19
  34. package/src/public-cli/notary-run.ts +54 -5
  35. package/src/public-cli/option-definitions.ts +3 -3
  36. package/src/public-cli/post-admission.ts +76 -0
  37. package/src/public-cli/reviewer-run.ts +5 -19
  38. package/src/public-cli/run-lifecycle.ts +342 -107
  39. package/src/public-cli/settlement.ts +134 -71
  40. package/src/role-runtime.ts +18 -1
  41. package/src/submission-ledger.ts +55 -5
@@ -14878,6 +14878,9 @@ function projectLawfulNotaryOutput(value) {
14878
14878
  if (!Array.isArray(clone.findings)) clone.findings = asStringArray2(clone.findings);
14879
14879
  return clone;
14880
14880
  }
14881
+ if (status === "escalate") {
14882
+ return structuredClone(value);
14883
+ }
14881
14884
  return void 0;
14882
14885
  }
14883
14886
  function validateRecordedNotaryOutput(value) {
@@ -14897,6 +14900,10 @@ function notaryDecisiveFacts(output) {
14897
14900
  if (status === "bounce") {
14898
14901
  facts.disposition = "rewrite";
14899
14902
  }
14903
+ if (status === "escalate") {
14904
+ const reason = output.reason;
14905
+ if (reason !== void 0) facts.reason = reason;
14906
+ }
14900
14907
  return facts;
14901
14908
  }
14902
14909
  var NOTARY_OUTPUT_TOOL_NAME, NOTARY_FIXED_KICKOFF, notaryOutputSchema;
@@ -14912,11 +14919,14 @@ var init_notary_contracts = __esm({
14912
14919
  openToolObject(
14913
14920
  typebox_exports.Object({
14914
14921
  status: typebox_exports.Unknown({
14915
- description: "pass | bounce \u2014 \u5F62\u72B6\u6307\u5F15\uFF0C\u975E schema \u95F8"
14922
+ description: "pass | bounce | escalate \u2014 \u5F62\u72B6\u6307\u5F15\uFF0C\u975E schema \u95F8"
14916
14923
  }),
14917
14924
  findings: typebox_exports.Unknown({
14918
- description: "string[] findings\uFF0C\u968F pass \u6216 bounce \u7559\u5B58"
14919
- })
14925
+ description: "string[] findings\uFF0C\u968F pass\u3001bounce \u6216 escalate \u7559\u5B58"
14926
+ }),
14927
+ reason: typebox_exports.Optional(typebox_exports.Unknown({
14928
+ description: "status \u4E3A escalate \u65F6\u7684\u4E0A\u5448\u7406\u7531"
14929
+ }))
14920
14930
  })
14921
14931
  )
14922
14932
  );
@@ -14991,7 +15001,7 @@ function validateRecordedInspectorOutput(value) {
14991
15001
  } catch {
14992
15002
  throw new Error("Inspector output has no execution discriminator");
14993
15003
  }
14994
- if (status === "pass" || status === "bounce") {
15004
+ if (status === "pass" || status === "bounce" || status === "escalate") {
14995
15005
  return value;
14996
15006
  }
14997
15007
  throw new Error("Inspector output has no execution discriminator");
@@ -15000,6 +15010,8 @@ function inspectorDecisiveFacts(output) {
15000
15010
  const facts = { status: output.status };
15001
15011
  const findings = output.findings;
15002
15012
  if (findings !== void 0) facts.findings = findings;
15013
+ const reason = output.reason;
15014
+ if (reason !== void 0) facts.reason = reason;
15003
15015
  return facts;
15004
15016
  }
15005
15017
  var INSPECTOR_OUTPUT_TOOL_NAME;
@@ -15014,7 +15026,7 @@ var init_inspector_contracts = __esm({
15014
15026
  function packagedRoleMetadata(role) {
15015
15027
  return PACKAGED_ROLE_REGISTRY.find((entry) => entry.role === role);
15016
15028
  }
15017
- var NOTARY_SESSION_MATERIALS, INSPECTOR_SESSION_MATERIALS, PUBLIC_ROLE_RECORDS, ONE_SHOT_ROLES, PACKAGED_ROLE_REGISTRY;
15029
+ var NOTARY_SESSION_MATERIALS, INSPECTOR_SESSION_MATERIALS, PUBLIC_ROLE_RECORDS, PACKAGED_ROLE_REGISTRY;
15018
15030
  var init_packaged_role_registry = __esm({
15019
15031
  "src/packaged-role-registry.ts"() {
15020
15032
  "use strict";
@@ -15197,12 +15209,6 @@ var init_packaged_role_registry = __esm({
15197
15209
  sessionMaterials: ["CLAUDE.md", "souls/navigator.md"]
15198
15210
  }
15199
15211
  ];
15200
- ONE_SHOT_ROLES = [
15201
- "collector",
15202
- "doctor",
15203
- "notary",
15204
- "inspector"
15205
- ];
15206
15212
  PACKAGED_ROLE_REGISTRY = PUBLIC_ROLE_RECORDS.map(({ sessionMaterials: _omit, ...metadata }) => metadata);
15207
15213
  }
15208
15214
  });
@@ -17715,6 +17721,16 @@ async function loadResumableRunRecord(home, runId, authority) {
17715
17721
  let derived;
17716
17722
  let correlationId;
17717
17723
  let ticketNumber;
17724
+ let prNumber;
17725
+ let repository;
17726
+ let repositoryDisplay;
17727
+ let requestManifestPath;
17728
+ let manifestDigest;
17729
+ let issueNumber;
17730
+ let caseRunsPath;
17731
+ let caseIdentity2;
17732
+ let sourceRunPath;
17733
+ let sourceRun;
17718
17734
  try {
17719
17735
  const raw = JSON.parse(
17720
17736
  await readFile8(run.admittedRequestPath, "utf8")
@@ -17748,6 +17764,46 @@ async function loadResumableRunRecord(home, runId, authority) {
17748
17764
  if (typeof record4.baseRevision === "string" && record4.baseRevision.trim() !== "") {
17749
17765
  baseRevision = record4.baseRevision;
17750
17766
  }
17767
+ if (typeof record4.prNumber === "number" && Number.isSafeInteger(record4.prNumber) && record4.prNumber >= 1) {
17768
+ prNumber = record4.prNumber;
17769
+ }
17770
+ if (typeof record4.repository === "string" && record4.repository.trim() !== "") {
17771
+ repository = record4.repository;
17772
+ }
17773
+ if (typeof record4.repositoryDisplay === "string" && record4.repositoryDisplay.trim() !== "") {
17774
+ repositoryDisplay = record4.repositoryDisplay;
17775
+ }
17776
+ if (typeof record4.requestManifestPath === "string" && record4.requestManifestPath.trim() !== "") {
17777
+ requestManifestPath = record4.requestManifestPath;
17778
+ }
17779
+ if (typeof record4.manifestDigest === "string" && record4.manifestDigest.trim() !== "") {
17780
+ manifestDigest = record4.manifestDigest;
17781
+ }
17782
+ if (typeof record4.issueNumber === "number" && Number.isSafeInteger(record4.issueNumber) && record4.issueNumber >= 1) {
17783
+ issueNumber = record4.issueNumber;
17784
+ }
17785
+ if (typeof record4.caseRunsPath === "string" && record4.caseRunsPath.trim() !== "") {
17786
+ caseRunsPath = record4.caseRunsPath;
17787
+ }
17788
+ if (record4.caseIdentity !== null && typeof record4.caseIdentity === "object" && !Array.isArray(record4.caseIdentity)) {
17789
+ const ci = record4.caseIdentity;
17790
+ if (typeof ci.issueNumber === "number" && Number.isSafeInteger(ci.issueNumber) && ci.issueNumber >= 1 && typeof ci.runsPath === "string" && ci.runsPath.trim() !== "") {
17791
+ caseIdentity2 = { issueNumber: ci.issueNumber, runsPath: ci.runsPath };
17792
+ }
17793
+ }
17794
+ if (typeof record4.sourceRunPath === "string" && record4.sourceRunPath.trim() !== "") {
17795
+ sourceRunPath = record4.sourceRunPath;
17796
+ }
17797
+ if (record4.sourceRun !== null && typeof record4.sourceRun === "object" && !Array.isArray(record4.sourceRun)) {
17798
+ const sr = record4.sourceRun;
17799
+ if (typeof sr.runId === "string" && sr.runId.trim() !== "" && typeof sr.role === "string" && sr.role.trim() !== "" && typeof sr.runDirectory === "string" && sr.runDirectory.trim() !== "") {
17800
+ sourceRun = {
17801
+ runId: sr.runId,
17802
+ role: sr.role,
17803
+ runDirectory: sr.runDirectory
17804
+ };
17805
+ }
17806
+ }
17751
17807
  if (Array.isArray(record4.authorityRefs)) {
17752
17808
  authorityRefs = Object.freeze(
17753
17809
  record4.authorityRefs.map((ref) => {
@@ -17833,19 +17889,22 @@ async function loadResumableRunRecord(home, runId, authority) {
17833
17889
  ...derived === void 0 ? {} : { derived },
17834
17890
  ...correlationId === void 0 ? {} : { correlationId },
17835
17891
  ...ticketNumber === void 0 ? {} : { ticketNumber },
17892
+ ...prNumber === void 0 ? {} : { prNumber },
17893
+ ...repository === void 0 ? {} : { repository },
17894
+ ...repositoryDisplay === void 0 ? {} : { repositoryDisplay },
17895
+ ...requestManifestPath === void 0 ? {} : { requestManifestPath },
17896
+ ...manifestDigest === void 0 ? {} : { manifestDigest },
17897
+ ...issueNumber === void 0 ? {} : { issueNumber },
17898
+ ...caseRunsPath === void 0 ? {} : { caseRunsPath },
17899
+ ...caseIdentity2 === void 0 ? {} : { caseIdentity: caseIdentity2 },
17900
+ ...sourceRunPath === void 0 ? {} : { sourceRunPath },
17901
+ ...sourceRun === void 0 ? {} : { sourceRun },
17836
17902
  ...model === void 0 ? {} : { model }
17837
17903
  }
17838
17904
  };
17839
17905
  }
17840
- async function loadResumableJudgeRun(home, runId, authority) {
17841
- const loaded = await loadResumableRunRecord(home, runId, authority);
17842
- if (loaded.run.role !== "judge") {
17843
- throw new CliUsageError(
17844
- `role run ${runId} belongs to ${loaded.run.role}, not judge`
17845
- );
17846
- }
17847
- const admitted = {
17848
- role: "judge",
17906
+ function resumedBaseAdmitted(loaded) {
17907
+ return {
17849
17908
  runId: loaded.run.runId,
17850
17909
  bookKey: loaded.run.bookKey,
17851
17910
  projectRoot: loaded.run.projectRoot,
@@ -17858,12 +17917,27 @@ async function loadResumableJudgeRun(home, runId, authority) {
17858
17917
  ...loaded.admittedFields.model === void 0 ? {} : { model: loaded.admittedFields.model },
17859
17918
  ...restoredTicketFields(loaded.admittedFields)
17860
17919
  };
17920
+ }
17921
+ function seatLoadedResult(loaded, admitted) {
17861
17922
  return {
17862
17923
  admitted,
17863
17924
  run: loaded.run,
17864
17925
  ...loaded.observation === void 0 ? {} : { observation: loaded.observation }
17865
17926
  };
17866
17927
  }
17928
+ async function loadResumableJudgeRun(home, runId, authority) {
17929
+ const loaded = await loadResumableRunRecord(home, runId, authority);
17930
+ if (loaded.run.role !== "judge") {
17931
+ throw new CliUsageError(
17932
+ `role run ${runId} belongs to ${loaded.run.role}, not judge`
17933
+ );
17934
+ }
17935
+ const admitted = {
17936
+ role: "judge",
17937
+ ...resumedBaseAdmitted(loaded)
17938
+ };
17939
+ return seatLoadedResult(loaded, admitted);
17940
+ }
17867
17941
  async function loadResumableCoderRun(home, runId, authority) {
17868
17942
  const loaded = await loadResumableRunRecord(home, runId, authority);
17869
17943
  if (loaded.run.role !== "coder") {
@@ -17891,24 +17965,11 @@ async function loadResumableCoderRun(home, runId, authority) {
17891
17965
  const admitted = {
17892
17966
  role: "coder",
17893
17967
  phase,
17894
- runId: loaded.run.runId,
17895
- bookKey: loaded.run.bookKey,
17896
- projectRoot: loaded.run.projectRoot,
17897
- instruction: loaded.admittedFields.instruction,
17968
+ ...resumedBaseAdmitted(loaded),
17898
17969
  instructionEmpty: false,
17899
- attachments: loaded.admittedFields.attachments,
17900
- runDirectory: loaded.run.runDirectory,
17901
- principal: loaded.principal,
17902
- admittedRequestPath: loaded.run.admittedRequestPath,
17903
- taskPath,
17904
- ...loaded.admittedFields.model === void 0 ? {} : { model: loaded.admittedFields.model },
17905
- ...restoredTicketFields(loaded.admittedFields)
17906
- };
17907
- return {
17908
- admitted,
17909
- run: loaded.run,
17910
- ...loaded.observation === void 0 ? {} : { observation: loaded.observation }
17970
+ taskPath
17911
17971
  };
17972
+ return seatLoadedResult(loaded, admitted);
17912
17973
  }
17913
17974
  async function loadResumableFixerRun(home, runId, authority) {
17914
17975
  const loaded = await loadResumableRunRecord(home, runId, authority);
@@ -17938,26 +17999,13 @@ async function loadResumableFixerRun(home, runId, authority) {
17938
17999
  const admitted = {
17939
18000
  role: "fixer",
17940
18001
  phase,
17941
- runId: loaded.run.runId,
17942
- bookKey: loaded.run.bookKey,
17943
- projectRoot: loaded.run.projectRoot,
17944
- instruction: loaded.admittedFields.instruction,
18002
+ ...resumedBaseAdmitted(loaded),
17945
18003
  instructionEmpty: false,
17946
- attachments: loaded.admittedFields.attachments,
17947
- runDirectory: loaded.run.runDirectory,
17948
- principal: loaded.principal,
17949
- admittedRequestPath: loaded.run.admittedRequestPath,
17950
18004
  packetPath,
17951
18005
  ...loaded.admittedFields.prerequisitesPath === void 0 ? {} : { prerequisitesPath: loaded.admittedFields.prerequisitesPath },
17952
- prerequisites,
17953
- ...loaded.admittedFields.model === void 0 ? {} : { model: loaded.admittedFields.model },
17954
- ...restoredTicketFields(loaded.admittedFields)
17955
- };
17956
- return {
17957
- admitted,
17958
- run: loaded.run,
17959
- ...loaded.observation === void 0 ? {} : { observation: loaded.observation }
18006
+ prerequisites
17960
18007
  };
18008
+ return seatLoadedResult(loaded, admitted);
17961
18009
  }
17962
18010
  async function loadResumableReviewerRun(home, runId, authority) {
17963
18011
  const loaded = await loadResumableRunRecord(home, runId, authority);
@@ -17974,25 +18022,11 @@ async function loadResumableReviewerRun(home, runId, authority) {
17974
18022
  }
17975
18023
  const admitted = {
17976
18024
  role: "reviewer",
17977
- runId: loaded.run.runId,
17978
- bookKey: loaded.run.bookKey,
17979
- projectRoot: loaded.run.projectRoot,
17980
- instruction: loaded.admittedFields.instruction,
17981
- instructionEmpty: loaded.admittedFields.instructionEmpty,
17982
- attachments: loaded.admittedFields.attachments,
17983
- runDirectory: loaded.run.runDirectory,
17984
- principal: loaded.principal,
17985
- admittedRequestPath: loaded.run.admittedRequestPath,
18025
+ ...resumedBaseAdmitted(loaded),
17986
18026
  baseRevision,
17987
- authorityRefs: Object.freeze([...loaded.admittedFields.authorityRefs ?? []]),
17988
- ...loaded.admittedFields.model === void 0 ? {} : { model: loaded.admittedFields.model },
17989
- ...restoredTicketFields(loaded.admittedFields)
17990
- };
17991
- return {
17992
- admitted,
17993
- run: loaded.run,
17994
- ...loaded.observation === void 0 ? {} : { observation: loaded.observation }
18027
+ authorityRefs: Object.freeze([...loaded.admittedFields.authorityRefs ?? []])
17995
18028
  };
18029
+ return seatLoadedResult(loaded, admitted);
17996
18030
  }
17997
18031
  async function loadResumableCountersignRun(home, runId, authority) {
17998
18032
  const loaded = await loadResumableRunRecord(home, runId, authority);
@@ -18003,23 +18037,22 @@ async function loadResumableCountersignRun(home, runId, authority) {
18003
18037
  }
18004
18038
  const admitted = {
18005
18039
  role: "countersign",
18006
- runId: loaded.run.runId,
18007
- bookKey: loaded.run.bookKey,
18008
- projectRoot: loaded.run.projectRoot,
18009
- instruction: loaded.admittedFields.instruction,
18010
- instructionEmpty: loaded.admittedFields.instructionEmpty,
18011
- attachments: loaded.admittedFields.attachments,
18012
- runDirectory: loaded.run.runDirectory,
18013
- principal: loaded.principal,
18014
- admittedRequestPath: loaded.run.admittedRequestPath,
18015
- ...loaded.admittedFields.model === void 0 ? {} : { model: loaded.admittedFields.model },
18016
- ...restoredTicketFields(loaded.admittedFields)
18040
+ ...resumedBaseAdmitted(loaded)
18017
18041
  };
18018
- return {
18019
- admitted,
18020
- run: loaded.run,
18021
- ...loaded.observation === void 0 ? {} : { observation: loaded.observation }
18042
+ return seatLoadedResult(loaded, admitted);
18043
+ }
18044
+ async function loadResumableInstructionSeatRun(home, runId, authority) {
18045
+ const loaded = await loadResumableRunRecord(home, runId, authority);
18046
+ if (loaded.run.role !== "gatekeeper" && loaded.run.role !== "navigator") {
18047
+ throw new CliUsageError(
18048
+ `role run ${runId} belongs to ${loaded.run.role}, not an instruction seat`
18049
+ );
18050
+ }
18051
+ const admitted = {
18052
+ role: loaded.run.role,
18053
+ ...resumedBaseAdmitted(loaded)
18022
18054
  };
18055
+ return seatLoadedResult(loaded, admitted);
18023
18056
  }
18024
18057
  async function loadResumableGleanerLeftRun(home, runId, authority) {
18025
18058
  const loaded = await loadResumableRunRecord(home, runId, authority);
@@ -18036,24 +18069,10 @@ async function loadResumableGleanerLeftRun(home, runId, authority) {
18036
18069
  }
18037
18070
  const admitted = {
18038
18071
  role: "gleaner-left",
18039
- runId: loaded.run.runId,
18040
- bookKey: loaded.run.bookKey,
18041
- projectRoot: loaded.run.projectRoot,
18042
- instruction: loaded.admittedFields.instruction,
18043
- instructionEmpty: loaded.admittedFields.instructionEmpty,
18044
- attachments: loaded.admittedFields.attachments,
18045
- runDirectory: loaded.run.runDirectory,
18046
- principal: loaded.principal,
18047
- admittedRequestPath: loaded.run.admittedRequestPath,
18048
- baseRevision,
18049
- ...loaded.admittedFields.model === void 0 ? {} : { model: loaded.admittedFields.model },
18050
- ...restoredTicketFields(loaded.admittedFields)
18051
- };
18052
- return {
18053
- admitted,
18054
- run: loaded.run,
18055
- ...loaded.observation === void 0 ? {} : { observation: loaded.observation }
18072
+ ...resumedBaseAdmitted(loaded),
18073
+ baseRevision
18056
18074
  };
18075
+ return seatLoadedResult(loaded, admitted);
18057
18076
  }
18058
18077
  async function loadResumableMergerRun(home, runId, authority) {
18059
18078
  const loaded = await loadResumableRunRecord(home, runId, authority);
@@ -18081,25 +18100,103 @@ async function loadResumableMergerRun(home, runId, authority) {
18081
18100
  }
18082
18101
  const admitted = {
18083
18102
  role: "merger",
18084
- runId: loaded.run.runId,
18085
- bookKey: loaded.run.bookKey,
18086
- projectRoot: loaded.run.projectRoot,
18087
- instruction: loaded.admittedFields.instruction,
18103
+ ...resumedBaseAdmitted(loaded),
18088
18104
  instructionEmpty: false,
18089
- attachments: loaded.admittedFields.attachments,
18090
- runDirectory: loaded.run.runDirectory,
18091
- principal: loaded.principal,
18092
- admittedRequestPath: loaded.run.admittedRequestPath,
18093
18105
  mergerInputPath,
18094
- derived,
18095
- ...loaded.admittedFields.model === void 0 ? {} : { model: loaded.admittedFields.model },
18096
- ...restoredTicketFields(loaded.admittedFields)
18106
+ derived
18097
18107
  };
18098
- return {
18099
- admitted,
18100
- run: loaded.run,
18101
- ...loaded.observation === void 0 ? {} : { observation: loaded.observation }
18108
+ return seatLoadedResult(loaded, admitted);
18109
+ }
18110
+ async function loadResumableCollectorRun(home, runId, authority) {
18111
+ const loaded = await loadResumableRunRecord(home, runId, authority);
18112
+ if (loaded.run.role !== "collector") {
18113
+ throw new CliUsageError(
18114
+ `role run ${runId} belongs to ${loaded.run.role}, not collector`
18115
+ );
18116
+ }
18117
+ const { prNumber, repository, repositoryDisplay, manifestDigest } = loaded.admittedFields;
18118
+ if (prNumber === void 0 || repository === void 0 || repositoryDisplay === void 0 || manifestDigest === void 0) {
18119
+ throw new CliUsageError(
18120
+ `role run admitted collector repository identity is missing: ${runId}`
18121
+ );
18122
+ }
18123
+ let parsedRepository;
18124
+ try {
18125
+ parsedRepository = parseCollectorRepository(repositoryDisplay);
18126
+ } catch (error) {
18127
+ const detail = error instanceof Error ? error.message : String(error);
18128
+ throw new CliUsageError(detail, { cause: error });
18129
+ }
18130
+ if (parsedRepository.canonical !== repository) {
18131
+ throw new CliUsageError(
18132
+ `role run admitted collector repository does not match its canonical form: ${runId}`
18133
+ );
18134
+ }
18135
+ const admitted = {
18136
+ role: "collector",
18137
+ ...resumedBaseAdmitted(loaded),
18138
+ prNumber,
18139
+ repository: parsedRepository,
18140
+ ...loaded.admittedFields.requestManifestPath === void 0 ? {} : { requestManifestPath: loaded.admittedFields.requestManifestPath },
18141
+ manifestDigest
18142
+ };
18143
+ return seatLoadedResult(loaded, admitted);
18144
+ }
18145
+ async function loadResumableDoctorRun(home, runId, authority) {
18146
+ const loaded = await loadResumableRunRecord(home, runId, authority);
18147
+ if (loaded.run.role !== "doctor") {
18148
+ throw new CliUsageError(
18149
+ `role run ${runId} belongs to ${loaded.run.role}, not doctor`
18150
+ );
18151
+ }
18152
+ const { issueNumber, caseRunsPath, caseIdentity: caseIdentity2 } = loaded.admittedFields;
18153
+ if (issueNumber === void 0 || caseRunsPath === void 0 || caseIdentity2 === void 0) {
18154
+ throw new CliUsageError(
18155
+ `role run admitted doctor case identity is missing: ${runId}`
18156
+ );
18157
+ }
18158
+ const admitted = {
18159
+ role: "doctor",
18160
+ ...resumedBaseAdmitted(loaded),
18161
+ issueNumber,
18162
+ caseRunsPath,
18163
+ caseIdentity: caseIdentity2
18164
+ };
18165
+ return seatLoadedResult(loaded, admitted);
18166
+ }
18167
+ async function loadResumableNotaryRun(home, runId, authority) {
18168
+ const loaded = await loadResumableRunRecord(home, runId, authority);
18169
+ if (loaded.run.role !== "notary") {
18170
+ throw new CliUsageError(
18171
+ `role run ${runId} belongs to ${loaded.run.role}, not notary`
18172
+ );
18173
+ }
18174
+ const { sourceRunPath, sourceRun } = loaded.admittedFields;
18175
+ if (sourceRunPath === void 0 || sourceRun === void 0) {
18176
+ throw new CliUsageError(
18177
+ `role run admitted notary source-run locator is missing: ${runId}`
18178
+ );
18179
+ }
18180
+ const admitted = {
18181
+ role: "notary",
18182
+ ...resumedBaseAdmitted(loaded),
18183
+ sourceRunPath,
18184
+ sourceRun
18185
+ };
18186
+ return seatLoadedResult(loaded, admitted);
18187
+ }
18188
+ async function loadResumableInspectorRun(home, runId, authority) {
18189
+ const loaded = await loadResumableRunRecord(home, runId, authority);
18190
+ if (loaded.run.role !== "inspector") {
18191
+ throw new CliUsageError(
18192
+ `role run ${runId} belongs to ${loaded.run.role}, not inspector`
18193
+ );
18194
+ }
18195
+ const admitted = {
18196
+ role: "inspector",
18197
+ ...resumedBaseAdmitted(loaded)
18102
18198
  };
18199
+ return seatLoadedResult(loaded, admitted);
18103
18200
  }
18104
18201
  async function peekRoleRunRole(home, runId) {
18105
18202
  const runDirectory = await findRunDirectoryById(home, runId);
@@ -18115,6 +18212,7 @@ var init_run_lifecycle = __esm({
18115
18212
  init_cli_errors();
18116
18213
  init_typed_provider_http();
18117
18214
  init_typed_provider_http();
18215
+ init_collector_config();
18118
18216
  init_engine_material();
18119
18217
  init_config2();
18120
18218
  init_invocation();
@@ -19113,7 +19211,7 @@ var init_option_definitions = __esm({
19113
19211
  },
19114
19212
  collector: {
19115
19213
  command: "collector",
19116
- summary: "Collect GitHub PR review evidence (one-shot).",
19214
+ summary: "Collect GitHub PR review evidence.",
19117
19215
  usage: ["ak-role collector --pr <number> [options] [instruction]"],
19118
19216
  examples: [
19119
19217
  "ak-role collector --pr 42 --repo owner/repository",
@@ -19122,7 +19220,7 @@ var init_option_definitions = __esm({
19122
19220
  },
19123
19221
  doctor: {
19124
19222
  command: "doctor",
19125
- summary: "Diagnose one retained case (one-shot).",
19223
+ summary: "Diagnose one retained case.",
19126
19224
  usage: ["ak-role doctor --issue <number> [options] [instruction]"],
19127
19225
  examples: [
19128
19226
  'ak-role doctor --issue 115 "Diagnose this retained case."'
@@ -19219,7 +19317,7 @@ var init_option_definitions = __esm({
19219
19317
  },
19220
19318
  resume: {
19221
19319
  command: "resume",
19222
- summary: "Resume a role run under the live seat table (model/host/engine); session principal must still exist.",
19320
+ summary: "Resume a role run under the live seat table (model/host/engine); session principal must still exist. [message] applies only to seats that accept caller instruction; Notary/\u7B26\u5B9D\u90CE must omit message and derives evidence from the existing source-run/dossier binding.",
19223
19321
  usage: ["ak-role resume <runId> [message]"],
19224
19322
  examples: [
19225
19323
  "ak-role resume 01abc\u2026",
@@ -21976,228 +22074,66 @@ var init_analyst_gate_cycles_read = __esm({
21976
22074
  }
21977
22075
  });
21978
22076
 
21979
- // src/run-terminal-artifacts.ts
21980
- import { readdir as readdir4, readFile as readFile12 } from "node:fs/promises";
21981
- import { basename as basename6, dirname as dirname8, join as join17 } from "node:path";
21982
- function isMissingPathError2(error) {
21983
- return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
21984
- }
21985
- function errorText2(error) {
21986
- return error instanceof Error ? error.message : String(error);
21987
- }
21988
- function isRecord11(value) {
21989
- return typeof value === "object" && value !== null && !Array.isArray(value);
21990
- }
21991
- function readUsableTerminalArtifactBody(body) {
21992
- if (body === null) {
21993
- return { ok: false, reason: "terminal artifact JSON value is null" };
21994
- }
21995
- if (!isRecord11(body)) {
21996
- return {
21997
- ok: false,
21998
- reason: `terminal artifact JSON value is not a typed object (${Array.isArray(body) ? "array" : typeof body})`
21999
- };
22000
- }
22001
- if (typeof body.role !== "string" || body.role.trim() === "") {
22002
- return {
22003
- ok: false,
22004
- reason: "terminal artifact missing nonblank producer-owned role field"
22005
- };
22077
+ // src/auditor-dossier-tool.ts
22078
+ var init_auditor_dossier_tool = __esm({
22079
+ "src/auditor-dossier-tool.ts"() {
22080
+ "use strict";
22081
+ init_build();
22006
22082
  }
22007
- return { ok: true, body };
22083
+ });
22084
+
22085
+ // src/compliance-transport.ts
22086
+ function createComplianceDecisionTool(name, description) {
22087
+ return { name, description, parameters: complianceDecisionSchema, async execute(_id, params) {
22088
+ return { content: [{ type: "text", text: "\u5BA1\u8BA1\u51B3\u8BAE\u5DF2\u6536" }], details: params, terminate: true };
22089
+ } };
22008
22090
  }
22009
- async function readTerminalArtifactAtPath(path, file) {
22010
- let raw;
22011
- try {
22012
- raw = await readFile12(path, "utf8");
22013
- } catch (error) {
22014
- if (isMissingPathError2(error)) return void 0;
22015
- return {
22016
- status: "unreadable",
22017
- file,
22018
- path,
22019
- reason: errorText2(error)
22020
- };
22021
- }
22022
- let parsed;
22023
- try {
22024
- parsed = JSON.parse(raw);
22025
- } catch (error) {
22026
- return {
22027
- status: "unreadable",
22028
- file,
22029
- path,
22030
- reason: error instanceof Error ? error.message : `terminal artifact JSON parse failed: ${String(error)}`
22031
- };
22032
- }
22033
- const usable = readUsableTerminalArtifactBody(parsed);
22034
- if (!usable.ok) {
22035
- return {
22036
- status: "unreadable",
22037
- file,
22038
- path,
22039
- reason: usable.reason
22040
- };
22041
- }
22042
- return { status: "present", file, path, body: usable.body };
22043
- }
22044
- async function listUniqueErrorFallbackPaths(directories) {
22045
- const found = [];
22046
- for (const dir of directories) {
22047
- let names;
22048
- try {
22049
- names = await readdir4(dir);
22050
- } catch (error) {
22051
- if (isMissingPathError2(error)) continue;
22052
- throw error;
22053
- }
22054
- for (const name of names.sort((a, b) => a.localeCompare(b))) {
22055
- if (!UNIQUE_ERROR_FALLBACK_NAME.test(name)) continue;
22056
- found.push(join17(dir, name));
22057
- }
22058
- }
22059
- return found;
22060
- }
22061
- function runIdFromRunDirectory(runDirectory) {
22062
- const name = basename6(runDirectory);
22063
- const at = name.lastIndexOf("@");
22064
- if (at <= 0 || at === name.length - 1) return void 0;
22065
- return name.slice(0, at);
22066
- }
22067
- function presentUniqueFallbackBoundToRun(body, expectedRunId) {
22068
- if (expectedRunId === void 0) return false;
22069
- return typeof body.runId === "string" && body.runId === expectedRunId;
22070
- }
22071
- async function readRunTerminalArtifact(runDirectory) {
22072
- const artifactsDir = join17(runDirectory, "artifacts");
22073
- for (const file of RUN_TERMINAL_ARTIFACT_FILES) {
22074
- const path = join17(artifactsDir, file);
22075
- const read3 = await readTerminalArtifactAtPath(path, file);
22076
- if (read3 !== void 0) return read3;
22077
- }
22078
- for (const relative3 of RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS) {
22079
- const path = join17(runDirectory, relative3);
22080
- const read3 = await readTerminalArtifactAtPath(path, "error.json");
22081
- if (read3 !== void 0) return read3;
22082
- }
22083
- for (const path of await listUniqueErrorFallbackPaths([artifactsDir, runDirectory])) {
22084
- const read3 = await readTerminalArtifactAtPath(path, "error.json");
22085
- if (read3 !== void 0) return read3;
22086
- }
22087
- const expectedRunId = runIdFromRunDirectory(runDirectory);
22088
- for (const path of await listUniqueErrorFallbackPaths([dirname8(runDirectory)])) {
22089
- const read3 = await readTerminalArtifactAtPath(path, "error.json");
22090
- if (read3 === void 0) continue;
22091
- if (read3.status === "present") {
22092
- if (!presentUniqueFallbackBoundToRun(read3.body, expectedRunId)) continue;
22093
- return read3;
22094
- }
22095
- }
22096
- return { status: "absent" };
22097
- }
22098
- var RUN_TERMINAL_ARTIFACT_FILES, RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS, UNIQUE_ERROR_FALLBACK_NAME;
22099
- var init_run_terminal_artifacts = __esm({
22100
- "src/run-terminal-artifacts.ts"() {
22091
+ var nonblank2, decisionGateSchema, complianceDecisionSchema, AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE, AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE;
22092
+ var init_compliance_transport = __esm({
22093
+ "src/compliance-transport.ts"() {
22101
22094
  "use strict";
22102
- RUN_TERMINAL_ARTIFACT_FILES = [
22103
- "report.json",
22104
- "error.json",
22105
- "audit-incomplete.json"
22106
- ];
22107
- RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS = [
22108
- "artifacts/error.settlement.json",
22109
- "error.settlement.json"
22110
- ];
22111
- UNIQUE_ERROR_FALLBACK_NAME = /^error\.[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.json$/i;
22095
+ init_build();
22096
+ init_evidence_child_executor();
22097
+ init_auditor_dossier_tool();
22098
+ init_sitian_facade();
22099
+ nonblank2 = typebox_exports.String({ minLength: 1, pattern: "\\S" });
22100
+ decisionGateSchema = typebox_exports.Object({ question: nonblank2, options: typebox_exports.Array(nonblank2, { minItems: 1 }) }, { additionalProperties: false });
22101
+ complianceDecisionSchema = typebox_exports.Object({ status: typebox_exports.Unknown({ description: "pass | revise | escalate \u2014 \u5F62\u72B6\u6307\u5F15\uFF0C\u975E schema \u95F8" }), violations: typebox_exports.Array(nonblank2, { description: "\u89C2\u5BDF\u5230\u7684\u5408\u89C4\u8FDD\u89C4" }), conflicts: typebox_exports.Array(nonblank2, { description: "\u672A\u51B3\u6743\u5A01\u6216\u6267\u884C\u51B2\u7A81" }), decisionGate: typebox_exports.Union([decisionGateSchema, typebox_exports.Null()], { description: "\u5347\u7EA7\u95EE\u9898\u4E0E\u53EF\u9009\u9009\u9879" }) }, { additionalProperties: true, required: [] });
22102
+ AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE = "ak_auditor_parent_attempt_binding";
22103
+ AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE = "ak_auditor_compliance_failure";
22112
22104
  }
22113
22105
  });
22114
22106
 
22115
- // src/submission-ledger.ts
22116
- function isAcceptedProjection(value) {
22117
- if (typeof value !== "object" || value === null) return false;
22118
- const candidate = value;
22119
- return candidate.kind === "accepted" && typeof candidate.role === "string" && typeof candidate.status === "string" && typeof candidate.decisiveFacts === "object" && candidate.decisiveFacts !== null;
22120
- }
22121
- function isAuditEscalationTerminalProjection(value) {
22122
- if (typeof value !== "object" || value === null) return false;
22123
- const candidate = value;
22124
- return candidate.kind === "audit_escalation" && typeof candidate.role === "string" && candidate.status === "audit_escalation" && typeof candidate.decisiveFacts === "object" && candidate.decisiveFacts !== null;
22125
- }
22126
- function submissionRecordFile(cwd, runId, home) {
22127
- const ledgerHome = resolveActivationLedgerHome(home);
22128
- return resolveSitianRecordPathInLedger({
22129
- level: "event",
22130
- kind: "candidate",
22131
- subject: { runId },
22132
- cwd
22133
- }, ledgerHome).recordFile;
22134
- }
22135
- async function readOwnedSubmissionRecords(cwd, runId, home) {
22136
- const file = submissionRecordFile(cwd, runId, home);
22137
- const { records: records2 } = await readSitianRecords(file);
22138
- return {
22139
- file,
22140
- owned: records2.filter((record4) => typeof record4.subject === "object" && record4.subject !== null && record4.subject.runId === runId)
22141
- };
22142
- }
22143
- async function readSealedSubmission(cwd, runId, home) {
22144
- const { owned } = await readOwnedSubmissionRecords(cwd, runId, home);
22145
- for (let index = owned.length - 1; index >= 0; index -= 1) {
22146
- const record4 = owned[index];
22147
- if (record4?.kind === "post-seal-anomaly") return void 0;
22148
- if (record4?.kind !== "sealed") continue;
22149
- const payload = record4.payload;
22150
- if (payload?.type === "sealed" && isAcceptedProjection(payload.projection)) return payload.projection;
22151
- }
22152
- return void 0;
22153
- }
22154
- async function readAuditEscalationSubmission(cwd, runId, home) {
22155
- const { owned } = await readOwnedSubmissionRecords(cwd, runId, home);
22156
- for (let index = owned.length - 1; index >= 0; index -= 1) {
22157
- const record4 = owned[index];
22158
- if (record4?.kind !== "outcome") continue;
22159
- const payload = record4.payload;
22160
- if (payload?.type !== "outcome" || payload.outcome !== "audit-escalation") continue;
22161
- if (isAuditEscalationTerminalProjection(payload.projection)) return payload.projection;
22162
- }
22163
- return void 0;
22164
- }
22165
- async function readLatestSubmissionOutcome(cwd, runId, home) {
22166
- const { owned } = await readOwnedSubmissionRecords(cwd, runId, home);
22167
- for (let index = owned.length - 1; index >= 0; index -= 1) {
22168
- const record4 = owned[index];
22169
- if (record4?.kind !== "outcome") continue;
22170
- const payload = record4.payload;
22171
- if (payload?.type === "outcome" && typeof payload.outcome === "string") {
22172
- return payload;
22173
- }
22174
- }
22175
- return void 0;
22176
- }
22177
- var init_submission_ledger = __esm({
22178
- "src/submission-ledger.ts"() {
22107
+ // src/engine-detour-tool.ts
22108
+ var engineDetourArgsSchema;
22109
+ var init_engine_detour_tool = __esm({
22110
+ "src/engine-detour-tool.ts"() {
22179
22111
  "use strict";
22180
- init_activation_ledger_topology();
22181
- init_audit_escalation();
22182
- init_terminating_tools();
22183
- init_run_terminal_artifacts();
22184
- init_sitian_facade();
22185
- init_submission_correctable_error();
22186
- init_terminating_infrastructure();
22112
+ init_build();
22113
+ init_engine_detour();
22114
+ engineDetourArgsSchema = typebox_exports.Object(
22115
+ {
22116
+ argv: typebox_exports.Array(typebox_exports.String({ minLength: 1 }), {
22117
+ minItems: 1,
22118
+ description: "\u9996\u9879\u4E3A PATH \u4E2D\u7684\u53EF\u6267\u884C\u6587\u4EF6\uFF0C\u5176\u4F59\u9879\u4E3A\u53C2\u6570\u3002"
22119
+ })
22120
+ },
22121
+ { additionalProperties: false }
22122
+ );
22187
22123
  }
22188
22124
  });
22189
22125
 
22190
22126
  // src/session-opening-materials.ts
22191
22127
  import { existsSync as existsSync6 } from "node:fs";
22192
- import { dirname as dirname9, join as join18 } from "node:path";
22128
+ import { dirname as dirname8, join as join17 } from "node:path";
22193
22129
  import { fileURLToPath, pathToFileURL as pathToFileURL2 } from "node:url";
22194
22130
  function resolvePackageRootDir(moduleUrl = import.meta.url) {
22195
- let dir = dirname9(fileURLToPath(moduleUrl));
22131
+ let dir = dirname8(fileURLToPath(moduleUrl));
22196
22132
  for (let i = 0; i < 8; i += 1) {
22197
- if (existsSync6(join18(dir, "package.json")) && existsSync6(join18(dir, "souls"))) {
22133
+ if (existsSync6(join17(dir, "package.json")) && existsSync6(join17(dir, "souls"))) {
22198
22134
  return dir;
22199
22135
  }
22200
- const parent = dirname9(dir);
22136
+ const parent = dirname8(dir);
22201
22137
  if (parent === dir) break;
22202
22138
  dir = parent;
22203
22139
  }
@@ -22223,41 +22159,6 @@ var init_session_opening_materials = __esm({
22223
22159
  }
22224
22160
  });
22225
22161
 
22226
- // src/auditor-soul.ts
22227
- var init_auditor_soul = __esm({
22228
- "src/auditor-soul.ts"() {
22229
- "use strict";
22230
- init_session_opening_materials();
22231
- }
22232
- });
22233
-
22234
- // src/auditor-dossier-tool.ts
22235
- var init_auditor_dossier_tool = __esm({
22236
- "src/auditor-dossier-tool.ts"() {
22237
- "use strict";
22238
- init_build();
22239
- }
22240
- });
22241
-
22242
- // src/engine-detour-tool.ts
22243
- var engineDetourArgsSchema;
22244
- var init_engine_detour_tool = __esm({
22245
- "src/engine-detour-tool.ts"() {
22246
- "use strict";
22247
- init_build();
22248
- init_engine_detour();
22249
- engineDetourArgsSchema = typebox_exports.Object(
22250
- {
22251
- argv: typebox_exports.Array(typebox_exports.String({ minLength: 1 }), {
22252
- minItems: 1,
22253
- description: "\u9996\u9879\u4E3A PATH \u4E2D\u7684\u53EF\u6267\u884C\u6587\u4EF6\uFF0C\u5176\u4F59\u9879\u4E3A\u53C2\u6570\u3002"
22254
- })
22255
- },
22256
- { additionalProperties: false }
22257
- );
22258
- }
22259
- });
22260
-
22261
22162
  // src/navigator-session-contracts.ts
22262
22163
  var navigatorProviderFailureSchema;
22263
22164
  var init_navigator_session_contracts = __esm({
@@ -22293,11 +22194,11 @@ var init_navigator_session_contracts = __esm({
22293
22194
  });
22294
22195
 
22295
22196
  // src/receipt-delivery-policy.ts
22296
- function isRecord12(value) {
22197
+ function isRecord11(value) {
22297
22198
  return typeof value === "object" && value !== null && !Array.isArray(value);
22298
22199
  }
22299
22200
  function parseNoReceiptLifecycleFacts(input) {
22300
- if (!isRecord12(input) || typeof input.terminalToolCalled !== "boolean" || input.deliveryTurns !== RECEIPT_DELIVERY_TURN_LIMIT || input.sessionCompletion !== "settled-without-accepted-receipt" || input.acceptedReceipt !== false || typeof input.runPointer !== "string" || input.runPointer.trim() === "" || typeof input.attemptPointer !== "string" || input.attemptPointer.trim() === "" || !Array.isArray(input.rejectedReceipts) || !input.rejectedReceipts.every((item) => isRecord12(item) && typeof item.reason === "string")) {
22201
+ if (!isRecord11(input) || typeof input.terminalToolCalled !== "boolean" || input.deliveryTurns !== RECEIPT_DELIVERY_TURN_LIMIT || input.sessionCompletion !== "settled-without-accepted-receipt" || input.acceptedReceipt !== false || typeof input.runPointer !== "string" || input.runPointer.trim() === "" || typeof input.attemptPointer !== "string" || input.attemptPointer.trim() === "" || !Array.isArray(input.rejectedReceipts) || !input.rejectedReceipts.every((item) => isRecord11(item) && typeof item.reason === "string")) {
22301
22202
  throw new TypeError("malformed no-receipt lifecycle facts");
22302
22203
  }
22303
22204
  return {
@@ -22313,75 +22214,307 @@ function parseNoReceiptLifecycleFacts(input) {
22313
22214
  acceptedReceipt: false
22314
22215
  };
22315
22216
  }
22316
- var RECEIPT_DELIVERY_TURN_LIMIT, NO_RECEIPT_LIFECYCLE_ENTRY_TYPE;
22317
- var init_receipt_delivery_policy = __esm({
22318
- "src/receipt-delivery-policy.ts"() {
22217
+ var RECEIPT_DELIVERY_TURN_LIMIT, NO_RECEIPT_LIFECYCLE_ENTRY_TYPE;
22218
+ var init_receipt_delivery_policy = __esm({
22219
+ "src/receipt-delivery-policy.ts"() {
22220
+ "use strict";
22221
+ RECEIPT_DELIVERY_TURN_LIMIT = 2;
22222
+ NO_RECEIPT_LIFECYCLE_ENTRY_TYPE = "ak-no-receipt-lifecycle";
22223
+ }
22224
+ });
22225
+
22226
+ // src/upstream-error-testimony.ts
22227
+ function isNonSuccessHttpStatus(status) {
22228
+ return typeof status === "number" && (status < 200 || status >= 300);
22229
+ }
22230
+ function hasUpstreamErrorTestimony(input) {
22231
+ if (isNonSuccessHttpStatus(input.httpStatus)) return true;
22232
+ return Array.isArray(input.diagnostics) && input.diagnostics.length > 0;
22233
+ }
22234
+ function projectConfirmedRemotePayload(input) {
22235
+ return {
22236
+ ...input.body === void 0 ? {} : { body: input.body },
22237
+ ...input.code === void 0 ? {} : { code: input.code },
22238
+ ...input.errno === void 0 ? {} : { errno: input.errno }
22239
+ };
22240
+ }
22241
+ var init_upstream_error_testimony = __esm({
22242
+ "src/upstream-error-testimony.ts"() {
22243
+ "use strict";
22244
+ }
22245
+ });
22246
+
22247
+ // src/evidence-child-executor.ts
22248
+ var init_evidence_child_executor = __esm({
22249
+ "src/evidence-child-executor.ts"() {
22250
+ "use strict";
22251
+ init_compliance_transport();
22252
+ init_auditor_dossier_tool();
22253
+ init_sitian_facade();
22254
+ init_engine_detour_tool();
22255
+ init_engine_detour();
22256
+ init_engine_material();
22257
+ init_session_opening_materials();
22258
+ init_config2();
22259
+ init_institutional_resolution();
22260
+ init_navigator_session_contracts();
22261
+ init_receipt_delivery_policy();
22262
+ init_typed_provider_http();
22263
+ init_upstream_error_testimony();
22264
+ }
22265
+ });
22266
+
22267
+ // src/gatekeeper-role.ts
22268
+ var officerDecisionSchema, MISSING_ARGUMENTS_SUBMISSION;
22269
+ var init_gatekeeper_role = __esm({
22270
+ "src/gatekeeper-role.ts"() {
22271
+ "use strict";
22272
+ init_build();
22273
+ init_evidence_child_executor();
22274
+ init_open_tool_schema();
22275
+ init_session_opening_materials();
22276
+ init_submission_errors();
22277
+ init_inspector_contracts();
22278
+ init_gatekeeper_output();
22279
+ init_submission_errors();
22280
+ officerDecisionSchema = openToolObject(typebox_exports.Object({
22281
+ status: typebox_exports.Unknown({ description: "pass | bounce | escalate \u2014 \u5F62\u72B6\u6307\u5F15\uFF0C\u975E schema \u95F8" }),
22282
+ reason: typebox_exports.Optional(typebox_exports.Unknown({ description: "status \u4E3A escalate \u65F6\u7684\u7406\u7531" })),
22283
+ findings: typebox_exports.Unknown({ description: "string[] findings\uFF0C\u968F pass\u3001bounce \u6216 escalate \u7559\u5B58" })
22284
+ }));
22285
+ MISSING_ARGUMENTS_SUBMISSION = Object.freeze({ missing: "arguments" });
22286
+ }
22287
+ });
22288
+
22289
+ // src/run-terminal-artifacts.ts
22290
+ import { readdir as readdir4, readFile as readFile12 } from "node:fs/promises";
22291
+ import { basename as basename6, dirname as dirname9, join as join18 } from "node:path";
22292
+ function isMissingPathError2(error) {
22293
+ return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
22294
+ }
22295
+ function errorText2(error) {
22296
+ return error instanceof Error ? error.message : String(error);
22297
+ }
22298
+ function isRecord12(value) {
22299
+ return typeof value === "object" && value !== null && !Array.isArray(value);
22300
+ }
22301
+ function readUsableTerminalArtifactBody(body) {
22302
+ if (body === null) {
22303
+ return { ok: false, reason: "terminal artifact JSON value is null" };
22304
+ }
22305
+ if (!isRecord12(body)) {
22306
+ return {
22307
+ ok: false,
22308
+ reason: `terminal artifact JSON value is not a typed object (${Array.isArray(body) ? "array" : typeof body})`
22309
+ };
22310
+ }
22311
+ if (typeof body.role !== "string" || body.role.trim() === "") {
22312
+ return {
22313
+ ok: false,
22314
+ reason: "terminal artifact missing nonblank producer-owned role field"
22315
+ };
22316
+ }
22317
+ return { ok: true, body };
22318
+ }
22319
+ async function readTerminalArtifactAtPath(path, file) {
22320
+ let raw;
22321
+ try {
22322
+ raw = await readFile12(path, "utf8");
22323
+ } catch (error) {
22324
+ if (isMissingPathError2(error)) return void 0;
22325
+ return {
22326
+ status: "unreadable",
22327
+ file,
22328
+ path,
22329
+ reason: errorText2(error)
22330
+ };
22331
+ }
22332
+ let parsed;
22333
+ try {
22334
+ parsed = JSON.parse(raw);
22335
+ } catch (error) {
22336
+ return {
22337
+ status: "unreadable",
22338
+ file,
22339
+ path,
22340
+ reason: error instanceof Error ? error.message : `terminal artifact JSON parse failed: ${String(error)}`
22341
+ };
22342
+ }
22343
+ const usable = readUsableTerminalArtifactBody(parsed);
22344
+ if (!usable.ok) {
22345
+ return {
22346
+ status: "unreadable",
22347
+ file,
22348
+ path,
22349
+ reason: usable.reason
22350
+ };
22351
+ }
22352
+ return { status: "present", file, path, body: usable.body };
22353
+ }
22354
+ async function listUniqueErrorFallbackPaths(directories) {
22355
+ const found = [];
22356
+ for (const dir of directories) {
22357
+ let names;
22358
+ try {
22359
+ names = await readdir4(dir);
22360
+ } catch (error) {
22361
+ if (isMissingPathError2(error)) continue;
22362
+ throw error;
22363
+ }
22364
+ for (const name of names.sort((a, b) => a.localeCompare(b))) {
22365
+ if (!UNIQUE_ERROR_FALLBACK_NAME.test(name)) continue;
22366
+ found.push(join18(dir, name));
22367
+ }
22368
+ }
22369
+ return found;
22370
+ }
22371
+ function runIdFromRunDirectory(runDirectory) {
22372
+ const name = basename6(runDirectory);
22373
+ const at = name.lastIndexOf("@");
22374
+ if (at <= 0 || at === name.length - 1) return void 0;
22375
+ return name.slice(0, at);
22376
+ }
22377
+ function presentUniqueFallbackBoundToRun(body, expectedRunId) {
22378
+ if (expectedRunId === void 0) return false;
22379
+ return typeof body.runId === "string" && body.runId === expectedRunId;
22380
+ }
22381
+ async function readRunTerminalArtifact(runDirectory) {
22382
+ const artifactsDir = join18(runDirectory, "artifacts");
22383
+ for (const file of RUN_TERMINAL_ARTIFACT_FILES) {
22384
+ const path = join18(artifactsDir, file);
22385
+ const read3 = await readTerminalArtifactAtPath(path, file);
22386
+ if (read3 !== void 0) return read3;
22387
+ }
22388
+ for (const relative3 of RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS) {
22389
+ const path = join18(runDirectory, relative3);
22390
+ const read3 = await readTerminalArtifactAtPath(path, "error.json");
22391
+ if (read3 !== void 0) return read3;
22392
+ }
22393
+ for (const path of await listUniqueErrorFallbackPaths([artifactsDir, runDirectory])) {
22394
+ const read3 = await readTerminalArtifactAtPath(path, "error.json");
22395
+ if (read3 !== void 0) return read3;
22396
+ }
22397
+ const expectedRunId = runIdFromRunDirectory(runDirectory);
22398
+ for (const path of await listUniqueErrorFallbackPaths([dirname9(runDirectory)])) {
22399
+ const read3 = await readTerminalArtifactAtPath(path, "error.json");
22400
+ if (read3 === void 0) continue;
22401
+ if (read3.status === "present") {
22402
+ if (!presentUniqueFallbackBoundToRun(read3.body, expectedRunId)) continue;
22403
+ return read3;
22404
+ }
22405
+ }
22406
+ return { status: "absent" };
22407
+ }
22408
+ var RUN_TERMINAL_ARTIFACT_FILES, RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS, UNIQUE_ERROR_FALLBACK_NAME;
22409
+ var init_run_terminal_artifacts = __esm({
22410
+ "src/run-terminal-artifacts.ts"() {
22319
22411
  "use strict";
22320
- RECEIPT_DELIVERY_TURN_LIMIT = 2;
22321
- NO_RECEIPT_LIFECYCLE_ENTRY_TYPE = "ak-no-receipt-lifecycle";
22412
+ RUN_TERMINAL_ARTIFACT_FILES = [
22413
+ "report.json",
22414
+ "error.json",
22415
+ "audit-incomplete.json"
22416
+ ];
22417
+ RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS = [
22418
+ "artifacts/error.settlement.json",
22419
+ "error.settlement.json"
22420
+ ];
22421
+ UNIQUE_ERROR_FALLBACK_NAME = /^error\.[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.json$/i;
22322
22422
  }
22323
22423
  });
22324
22424
 
22325
- // src/upstream-error-testimony.ts
22326
- function isNonSuccessHttpStatus(status) {
22327
- return typeof status === "number" && (status < 200 || status >= 300);
22425
+ // src/submission-ledger.ts
22426
+ function latestUserAttemptId(entries) {
22427
+ const ordered = [...entries];
22428
+ for (let index = ordered.length - 1; index >= 0; index -= 1) {
22429
+ const entry = ordered[index];
22430
+ if (entry?.message?.role === "user" && typeof entry.id === "string") return entry.id;
22431
+ }
22432
+ return void 0;
22328
22433
  }
22329
- function hasUpstreamErrorTestimony(input) {
22330
- if (isNonSuccessHttpStatus(input.httpStatus)) return true;
22331
- return Array.isArray(input.diagnostics) && input.diagnostics.length > 0;
22434
+ function isAcceptedProjection(value) {
22435
+ if (typeof value !== "object" || value === null) return false;
22436
+ const candidate = value;
22437
+ return candidate.kind === "accepted" && typeof candidate.role === "string" && typeof candidate.status === "string" && typeof candidate.decisiveFacts === "object" && candidate.decisiveFacts !== null;
22332
22438
  }
22333
- function projectConfirmedRemotePayload(input) {
22439
+ function isAuditEscalationTerminalProjection(value) {
22440
+ if (typeof value !== "object" || value === null) return false;
22441
+ const candidate = value;
22442
+ return candidate.kind === "audit_escalation" && typeof candidate.role === "string" && candidate.status === "audit_escalation" && typeof candidate.decisiveFacts === "object" && candidate.decisiveFacts !== null;
22443
+ }
22444
+ function submissionRecordFile(cwd, runId, home) {
22445
+ const ledgerHome = resolveActivationLedgerHome(home);
22446
+ return resolveSitianRecordPathInLedger({
22447
+ level: "event",
22448
+ kind: "candidate",
22449
+ subject: { runId },
22450
+ cwd
22451
+ }, ledgerHome).recordFile;
22452
+ }
22453
+ async function readOwnedSubmissionRecords(cwd, runId, home) {
22454
+ const file = submissionRecordFile(cwd, runId, home);
22455
+ const { records: records2 } = await readSitianRecords(file);
22334
22456
  return {
22335
- ...input.body === void 0 ? {} : { body: input.body },
22336
- ...input.code === void 0 ? {} : { code: input.code },
22337
- ...input.errno === void 0 ? {} : { errno: input.errno }
22457
+ file,
22458
+ owned: records2.filter((record4) => typeof record4.subject === "object" && record4.subject !== null && record4.subject.runId === runId)
22338
22459
  };
22339
22460
  }
22340
- var init_upstream_error_testimony = __esm({
22341
- "src/upstream-error-testimony.ts"() {
22342
- "use strict";
22461
+ async function readSealedSubmission(cwd, runId, home) {
22462
+ const { owned } = await readOwnedSubmissionRecords(cwd, runId, home);
22463
+ for (let index = owned.length - 1; index >= 0; index -= 1) {
22464
+ const record4 = owned[index];
22465
+ if (record4?.kind === "post-seal-anomaly") return void 0;
22466
+ if (record4?.kind !== "sealed") continue;
22467
+ const payload = record4.payload;
22468
+ if (payload?.type === "sealed" && isAcceptedProjection(payload.projection)) return payload.projection;
22343
22469
  }
22344
- });
22345
-
22346
- // src/evidence-child-executor.ts
22347
- var init_evidence_child_executor = __esm({
22348
- "src/evidence-child-executor.ts"() {
22470
+ return void 0;
22471
+ }
22472
+ async function readAuditEscalationSubmission(cwd, runId, home, currentAttemptId) {
22473
+ const { owned } = await readOwnedSubmissionRecords(cwd, runId, home);
22474
+ const latestAttemptId = currentAttemptId ?? owned.at(-1)?.subject?.attemptId;
22475
+ if (typeof latestAttemptId !== "string") return void 0;
22476
+ for (let index = owned.length - 1; index >= 0; index -= 1) {
22477
+ const record4 = owned[index];
22478
+ if (record4?.subject?.attemptId !== latestAttemptId) continue;
22479
+ if (record4?.kind !== "outcome") continue;
22480
+ const payload = record4.payload;
22481
+ if (payload?.type !== "outcome") continue;
22482
+ if (payload.outcome !== "audit-escalation") return void 0;
22483
+ if (isAuditEscalationTerminalProjection(payload.projection)) return payload.projection;
22484
+ }
22485
+ return void 0;
22486
+ }
22487
+ async function readLatestSubmissionOutcome(cwd, runId, home) {
22488
+ const { owned } = await readOwnedSubmissionRecords(cwd, runId, home);
22489
+ for (let index = owned.length - 1; index >= 0; index -= 1) {
22490
+ const record4 = owned[index];
22491
+ if (record4?.kind !== "outcome") continue;
22492
+ const payload = record4.payload;
22493
+ if (payload?.type === "outcome" && typeof payload.outcome === "string") {
22494
+ return payload;
22495
+ }
22496
+ }
22497
+ return void 0;
22498
+ }
22499
+ var init_submission_ledger = __esm({
22500
+ "src/submission-ledger.ts"() {
22349
22501
  "use strict";
22350
- init_compliance_transport();
22351
- init_auditor_dossier_tool();
22502
+ init_activation_ledger_topology();
22503
+ init_audit_escalation();
22504
+ init_gatekeeper_role();
22505
+ init_terminating_tools();
22506
+ init_run_terminal_artifacts();
22352
22507
  init_sitian_facade();
22353
- init_engine_detour_tool();
22354
- init_engine_detour();
22355
- init_engine_material();
22356
- init_session_opening_materials();
22357
- init_config2();
22358
- init_institutional_resolution();
22359
- init_navigator_session_contracts();
22360
- init_receipt_delivery_policy();
22361
- init_typed_provider_http();
22362
- init_upstream_error_testimony();
22508
+ init_submission_correctable_error();
22509
+ init_terminating_infrastructure();
22363
22510
  }
22364
22511
  });
22365
22512
 
22366
- // src/compliance-transport.ts
22367
- function createComplianceDecisionTool(name, description) {
22368
- return { name, description, parameters: complianceDecisionSchema, async execute(_id, params) {
22369
- return { content: [{ type: "text", text: "\u5BA1\u8BA1\u51B3\u8BAE\u5DF2\u6536" }], details: params, terminate: true };
22370
- } };
22371
- }
22372
- var nonblank2, decisionGateSchema, complianceDecisionSchema, AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE, AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE;
22373
- var init_compliance_transport = __esm({
22374
- "src/compliance-transport.ts"() {
22513
+ // src/auditor-soul.ts
22514
+ var init_auditor_soul = __esm({
22515
+ "src/auditor-soul.ts"() {
22375
22516
  "use strict";
22376
- init_build();
22377
- init_evidence_child_executor();
22378
- init_auditor_dossier_tool();
22379
- init_sitian_facade();
22380
- nonblank2 = typebox_exports.String({ minLength: 1, pattern: "\\S" });
22381
- decisionGateSchema = typebox_exports.Object({ question: nonblank2, options: typebox_exports.Array(nonblank2, { minItems: 1 }) }, { additionalProperties: false });
22382
- complianceDecisionSchema = typebox_exports.Object({ status: typebox_exports.Unknown({ description: "pass | revise | escalate \u2014 \u5F62\u72B6\u6307\u5F15\uFF0C\u975E schema \u95F8" }), violations: typebox_exports.Array(nonblank2, { description: "\u89C2\u5BDF\u5230\u7684\u5408\u89C4\u8FDD\u89C4" }), conflicts: typebox_exports.Array(nonblank2, { description: "\u672A\u51B3\u6743\u5A01\u6216\u6267\u884C\u51B2\u7A81" }), decisionGate: typebox_exports.Union([decisionGateSchema, typebox_exports.Null()], { description: "\u5347\u7EA7\u95EE\u9898\u4E0E\u53EF\u9009\u9009\u9879" }) }, { additionalProperties: true, required: [] });
22383
- AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE = "ak_auditor_parent_attempt_binding";
22384
- AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE = "ak_auditor_compliance_failure";
22517
+ init_session_opening_materials();
22385
22518
  }
22386
22519
  });
22387
22520
 
@@ -23455,15 +23588,25 @@ async function sealedLedgerOutcome(admitted) {
23455
23588
  async function hasSealedAcceptedProjection(admitted) {
23456
23589
  return await sealedLedgerOutcome(admitted) !== void 0;
23457
23590
  }
23458
- async function auditEscalationLedgerOutcome(admitted, role) {
23591
+ async function auditEscalationLedgerOutcome(admitted, role, authority) {
23592
+ let currentAttemptId;
23593
+ if (role === "coder" || role === "fixer") {
23594
+ const entries = await readBoundSessionEntries(coordinatesFromAdmitted(authority, admitted).sessionFile);
23595
+ currentAttemptId = latestUserAttemptId(entries);
23596
+ }
23459
23597
  const projection = await readAuditEscalationSubmission(
23460
23598
  admitted.projectRoot,
23461
23599
  admitted.runId,
23462
- sealedLedgerHome(admitted)
23600
+ sealedLedgerHome(admitted),
23601
+ currentAttemptId
23463
23602
  );
23464
23603
  if (projection?.role !== role) return void 0;
23465
23604
  return projection;
23466
23605
  }
23606
+ async function closedLedgerOutcome(admitted, role, authority) {
23607
+ const sealed = await sealedLedgerOutcome(admitted);
23608
+ return sealed?.role === role ? sealed : auditEscalationLedgerOutcome(admitted, role, authority);
23609
+ }
23467
23610
  function coordinatesFromAdmitted(authority, admitted) {
23468
23611
  return authority.decode(admitted.principal);
23469
23612
  }
@@ -24382,9 +24525,12 @@ function extractInfrastructureToolFailure(entries, spec) {
24382
24525
  }
24383
24526
  return void 0;
24384
24527
  }
24385
- async function readInfrastructureToolFailure(sessionFile, spec) {
24528
+ async function readInfrastructureToolFailure(sessionFile, spec, options = {}) {
24386
24529
  try {
24387
- const entries = await readBoundSessionEntries(sessionFile);
24530
+ let entries = await readBoundSessionEntries(sessionFile);
24531
+ if (options.currentAttemptOnly === true) {
24532
+ entries = entries.slice(currentAttemptStartIndex(entries));
24533
+ }
24388
24534
  return extractInfrastructureToolFailure(entries, spec);
24389
24535
  } catch {
24390
24536
  return void 0;
@@ -24393,7 +24539,10 @@ async function readInfrastructureToolFailure(sessionFile, spec) {
24393
24539
  async function readCollectorInfrastructureFailure(sessionFile) {
24394
24540
  return readInfrastructureToolFailure(
24395
24541
  sessionFile,
24396
- COLLECTOR_INFRASTRUCTURE_FAILURE_SPEC
24542
+ COLLECTOR_INFRASTRUCTURE_FAILURE_SPEC,
24543
+ // Multi-attempt resume: only a current-attempt infrastructure failure
24544
+ // may preempt the current failure cause (#633).
24545
+ { currentAttemptOnly: true }
24397
24546
  );
24398
24547
  }
24399
24548
  async function readEngineDetourInfrastructureFailure(sessionFile) {
@@ -24779,7 +24928,7 @@ async function readLawfulJudgeRoleOutcome(admitted, authority) {
24779
24928
  decisiveFacts: judgeDecisiveFacts(details, sealed.status)
24780
24929
  };
24781
24930
  }
24782
- return auditEscalationLedgerOutcome(admitted, "judge");
24931
+ return auditEscalationLedgerOutcome(admitted, "judge", authority);
24783
24932
  }
24784
24933
  async function hasLawfulJudgeTerminalResult(admitted, authority) {
24785
24934
  try {
@@ -24814,24 +24963,28 @@ async function trySettleJudgeTerminalResult(admitted, authority) {
24814
24963
  return settleLawfulJudgeTerminalResult(admitted, authority);
24815
24964
  }
24816
24965
  async function settleLawfulCoderTerminalResult(admitted, authority, options = {}) {
24817
- const sealed = await sealedLedgerOutcome(admitted);
24818
- if (sealed?.role !== "coder") return void 0;
24966
+ const ledgerOutcome = await closedLedgerOutcome(admitted, "coder", authority);
24967
+ if (ledgerOutcome === void 0) return void 0;
24968
+ let roleOutcome = ledgerOutcome;
24969
+ let output;
24970
+ if (ledgerOutcome.kind === "accepted") {
24971
+ output = validateAcceptedCoderDetails(ledgerOutcome.decisiveFacts);
24972
+ roleOutcome = {
24973
+ kind: "accepted",
24974
+ role: "coder",
24975
+ status: ledgerOutcome.status,
24976
+ decisiveFacts: coderDecisiveFacts(output)
24977
+ };
24978
+ }
24819
24979
  const coordinates = coordinatesFromAdmitted(authority, admitted);
24820
24980
  const entries = await readLawfulSettlementEntries(coordinates.sessionFile) ?? [];
24821
- const output = validateAcceptedCoderDetails(sealed.decisiveFacts);
24822
- const roleOutcome = {
24823
- kind: "accepted",
24824
- role: "coder",
24825
- status: sealed.status,
24826
- decisiveFacts: coderDecisiveFacts(output)
24827
- };
24828
24981
  const navigator = extractNavigatorFact(entries);
24829
24982
  const artifacts = await publishCoderArtifacts(
24830
24983
  admitted,
24831
24984
  roleOutcome,
24832
24985
  coordinates,
24833
24986
  {
24834
- coderOutput: output,
24987
+ ...output === void 0 ? {} : { coderOutput: output },
24835
24988
  ...options.methodProvenance === void 0 ? {} : { methodProvenance: options.methodProvenance }
24836
24989
  }
24837
24990
  );
@@ -24930,18 +25083,22 @@ async function publishFixerArtifacts(admitted, roleOutcome, coordinates, options
24930
25083
  ];
24931
25084
  }
24932
25085
  async function settleLawfulFixerTerminalResult(admitted, authority, options) {
24933
- const sealed = await sealedLedgerOutcome(admitted);
24934
- if (sealed?.role !== "fixer") return void 0;
25086
+ const ledgerOutcome = await closedLedgerOutcome(admitted, "fixer", authority);
25087
+ if (ledgerOutcome === void 0) return void 0;
25088
+ let roleOutcome = ledgerOutcome;
25089
+ let output;
25090
+ if (ledgerOutcome.kind === "accepted") {
25091
+ output = validateFixerOutput(ledgerOutcome.decisiveFacts);
25092
+ roleOutcome = {
25093
+ kind: "accepted",
25094
+ role: "fixer",
25095
+ status: ledgerOutcome.status,
25096
+ decisiveFacts: fixerDecisiveFacts(output)
25097
+ };
25098
+ }
24935
25099
  const coordinates = coordinatesFromAdmitted(authority, admitted);
24936
25100
  const { sessionDirectory, sessionFile } = coordinates;
24937
25101
  const entries = await readLawfulSettlementEntries(sessionFile) ?? [];
24938
- const output = validateFixerOutput(sealed.decisiveFacts);
24939
- const roleOutcome = {
24940
- kind: "accepted",
24941
- role: "fixer",
24942
- status: sealed.status,
24943
- decisiveFacts: fixerDecisiveFacts(output)
24944
- };
24945
25102
  const navigator = extractNavigatorFact(entries);
24946
25103
  const methodInvocations = extractFixerMethodInvocations(entries, {
24947
25104
  allowedLocations: [
@@ -24954,7 +25111,7 @@ async function settleLawfulFixerTerminalResult(admitted, authority, options) {
24954
25111
  roleOutcome,
24955
25112
  coordinates,
24956
25113
  {
24957
- fixerOutput: output,
25114
+ ...output === void 0 ? {} : { fixerOutput: output },
24958
25115
  methodProvenance: options.methodProvenance,
24959
25116
  methodInvocations
24960
25117
  }
@@ -25025,7 +25182,8 @@ async function settleLawfulCollectorTerminalResult(admitted, authority) {
25025
25182
  const entries = await readLawfulSettlementEntries(sessionFile) ?? [];
25026
25183
  const roleOutcome = await sealedLedgerOutcome(admitted);
25027
25184
  if (roleOutcome?.role !== "collector") {
25028
- for (let index = entries.length - 1; index >= 0; index -= 1) {
25185
+ const scanStart = currentAttemptStartIndex(entries);
25186
+ for (let index = entries.length - 1; index >= scanStart; index -= 1) {
25029
25187
  const message = entries[index]?.message;
25030
25188
  if (message?.role !== "toolResult") continue;
25031
25189
  const residual = boundErroredToolCandidate(entries, index, message, COLLECTOR_WAIT_TOOL);
@@ -25132,7 +25290,7 @@ async function settleLawfulDoctorTerminalResult(admitted, authority) {
25132
25290
  const { sessionDirectory, sessionFile } = coordinates;
25133
25291
  const entries = await readLawfulSettlementEntries(sessionFile) ?? [];
25134
25292
  if (sealed?.role !== "doctor") {
25135
- const escalation = await auditEscalationLedgerOutcome(admitted, "doctor");
25293
+ const escalation = await auditEscalationLedgerOutcome(admitted, "doctor", authority);
25136
25294
  if (escalation === void 0) return void 0;
25137
25295
  const artifacts2 = await publishDoctorArtifacts(admitted, escalation, coordinates);
25138
25296
  return withOptionalGateProjection(
@@ -25192,13 +25350,25 @@ function currentAttemptStartIndex(entries) {
25192
25350
  }
25193
25351
  return 0;
25194
25352
  }
25195
- async function settleLawfulOneShotAcceptedTerminalResult(admitted, authority, spec) {
25353
+ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec) {
25196
25354
  const coordinates = coordinatesFromAdmitted(authority, admitted);
25197
25355
  const { sessionDirectory, sessionFile } = coordinates;
25198
25356
  const entries = await readLawfulSettlementEntries(sessionFile) ?? [];
25199
- const roleOutcome = await sealedLedgerOutcome(admitted);
25357
+ const roleOutcome = await closedLedgerOutcome(admitted, spec.role, authority);
25358
+ if (roleOutcome?.kind === "audit_escalation") {
25359
+ const navigator2 = extractNavigatorFact(entries);
25360
+ return withOptionalGateProjection(
25361
+ {
25362
+ roleOutcome,
25363
+ navigator: navigator2,
25364
+ artifacts: [],
25365
+ runId: admitted.runId
25366
+ },
25367
+ sessionDirectory
25368
+ );
25369
+ }
25200
25370
  if (roleOutcome?.role !== spec.role) {
25201
- const scanStart = spec.residualScanCurrentAttemptOnly === true ? currentAttemptStartIndex(entries) : 0;
25371
+ const scanStart = currentAttemptStartIndex(entries);
25202
25372
  let acceptedNonUsable;
25203
25373
  for (let index = entries.length - 1; index >= scanStart; index -= 1) {
25204
25374
  const message = entries[index]?.message;
@@ -25265,10 +25435,10 @@ function tryAcceptWithValidator(validate) {
25265
25435
  };
25266
25436
  }
25267
25437
  async function settleLawfulNotaryTerminalResult(admitted, authority) {
25268
- return settleLawfulOneShotAcceptedTerminalResult(admitted, authority, {
25438
+ return settleLawfulSeatAcceptedTerminalResult(admitted, authority, {
25269
25439
  role: "notary",
25270
25440
  toolName: NOTARY_OUTPUT_TOOL_NAME,
25271
- nonUsableDiagnostic: "\u7B26\u5B9D\u90CE\u56DE\u6267\u65E0\u663E\u5F0F pass/bounce",
25441
+ nonUsableDiagnostic: "\u7B26\u5B9D\u90CE\u56DE\u6267\u65E0\u663E\u5F0F pass/bounce/escalate",
25272
25442
  tryAcceptDetails: tryAcceptWithValidator(validateRecordedNotaryOutput),
25273
25443
  projectAccepted: (sealed) => {
25274
25444
  const output = validateRecordedNotaryOutput(sealed.decisiveFacts);
@@ -25286,11 +25456,10 @@ async function trySettleNotaryTerminalResult(admitted, authority) {
25286
25456
  return settleLawfulNotaryTerminalResult(admitted, authority);
25287
25457
  }
25288
25458
  async function settleLawfulCountersignTerminalResult(admitted, authority) {
25289
- return settleLawfulOneShotAcceptedTerminalResult(admitted, authority, {
25459
+ return settleLawfulSeatAcceptedTerminalResult(admitted, authority, {
25290
25460
  role: "countersign",
25291
25461
  toolName: COUNTERSIGN_OUTPUT_TOOL_NAME,
25292
25462
  nonUsableDiagnostic: "\u7ED9\u4E8B\u4E2D\u56DE\u6267\u65E0\u663E\u5F0F \u7F72/\u5C01\u9A73/\u4E0A\u5448",
25293
- residualScanCurrentAttemptOnly: true,
25294
25463
  tryAcceptDetails: tryAcceptWithValidator(validateRecordedCountersignOutput),
25295
25464
  projectAccepted: (sealed) => {
25296
25465
  const verdict = validateRecordedCountersignOutput(sealed.decisiveFacts);
@@ -25308,11 +25477,10 @@ async function trySettleCountersignTerminalResult(admitted, authority) {
25308
25477
  return settleLawfulCountersignTerminalResult(admitted, authority);
25309
25478
  }
25310
25479
  async function settleLawfulGleanerLeftTerminalResult(admitted, authority) {
25311
- return settleLawfulOneShotAcceptedTerminalResult(admitted, authority, {
25480
+ return settleLawfulSeatAcceptedTerminalResult(admitted, authority, {
25312
25481
  role: "gleaner-left",
25313
25482
  toolName: GLEANER_LEFT_OUTPUT_TOOL_NAME,
25314
25483
  nonUsableDiagnostic: "\u5DE6\u62FE\u9057\u56DE\u6267\u65E0\u663E\u5F0F completed",
25315
- residualScanCurrentAttemptOnly: true,
25316
25484
  tryAcceptDetails: tryAcceptWithValidator(validateRecordedGleanerLeftOutput),
25317
25485
  projectAccepted: (sealed) => {
25318
25486
  const output = validateRecordedGleanerLeftOutput(sealed.decisiveFacts);
@@ -25330,10 +25498,10 @@ async function trySettleGleanerLeftTerminalResult(admitted, authority) {
25330
25498
  return settleLawfulGleanerLeftTerminalResult(admitted, authority);
25331
25499
  }
25332
25500
  async function settleLawfulInspectorTerminalResult(admitted, authority) {
25333
- return settleLawfulOneShotAcceptedTerminalResult(admitted, authority, {
25501
+ return settleLawfulSeatAcceptedTerminalResult(admitted, authority, {
25334
25502
  role: "inspector",
25335
25503
  toolName: INSPECTOR_OUTPUT_TOOL_NAME,
25336
- nonUsableDiagnostic: "\u5BDF\u9662\u56DE\u6267\u65E0\u663E\u5F0F pass/bounce",
25504
+ nonUsableDiagnostic: "\u5BDF\u9662\u56DE\u6267\u65E0\u663E\u5F0F pass/bounce/escalate",
25337
25505
  tryAcceptDetails: tryAcceptWithValidator(validateRecordedInspectorOutput),
25338
25506
  projectAccepted: (sealed) => {
25339
25507
  const output = validateRecordedInspectorOutput(sealed.decisiveFacts);
@@ -25351,7 +25519,7 @@ async function trySettleInspectorTerminalResult(admitted, authority) {
25351
25519
  return settleLawfulInspectorTerminalResult(admitted, authority);
25352
25520
  }
25353
25521
  async function settleLawfulGatekeeperTerminalResult(admitted, authority) {
25354
- return settleLawfulOneShotAcceptedTerminalResult(admitted, authority, {
25522
+ return settleLawfulSeatAcceptedTerminalResult(admitted, authority, {
25355
25523
  role: "gatekeeper",
25356
25524
  toolName: GATEKEEPER_OUTPUT_TOOL_NAME,
25357
25525
  nonUsableDiagnostic: "\u95E8\u4E0B\u7701\u51B3\u8BAE\u65E0\u663E\u5F0F dispatch/pass",
@@ -25372,7 +25540,7 @@ async function trySettleGatekeeperTerminalResult(admitted, authority) {
25372
25540
  return settleLawfulGatekeeperTerminalResult(admitted, authority);
25373
25541
  }
25374
25542
  async function settleLawfulNavigatorTerminalResult(admitted, authority) {
25375
- return settleLawfulOneShotAcceptedTerminalResult(admitted, authority, {
25543
+ return settleLawfulSeatAcceptedTerminalResult(admitted, authority, {
25376
25544
  role: "navigator",
25377
25545
  toolName: NAVIGATOR_OUTPUT_TOOL_NAME,
25378
25546
  nonUsableDiagnostic: "\u6E38\u5955\u4F7F\u56DE\u6267\u65E0\u663E\u5F0F\u8DEF\u7EBF\u5EFA\u8BAE",
@@ -26767,6 +26935,45 @@ async function dispatchPostAdmissionTurn(input) {
26767
26935
  await lease.release();
26768
26936
  }
26769
26937
  }
26938
+ function resumeTurnRequestProjectionOptions(admitted, request, env) {
26939
+ return {
26940
+ packageRoot: env.packageRoot,
26941
+ home: env.home,
26942
+ agentDir: env.agentDir,
26943
+ ...env.model === void 0 ? {} : { model: env.model },
26944
+ ...env.engine === void 0 ? {} : { engine: env.engine },
26945
+ ...env.timeoutMs === void 0 ? {} : { timeoutMs: env.timeoutMs },
26946
+ ...admitted.correlationId === void 0 && env.correlationId === void 0 ? {} : { correlationId: admitted.correlationId ?? env.correlationId },
26947
+ continuation: {
26948
+ kind: "resume",
26949
+ prompt: buildResumeContinuationPrompt({
26950
+ packageRoot: env.packageRoot,
26951
+ ...env.engine === void 0 ? {} : { engine: env.engine },
26952
+ ...request.message === void 0 ? {} : { message: request.message }
26953
+ })
26954
+ }
26955
+ };
26956
+ }
26957
+ async function runPostAdmissionSeatResume(input) {
26958
+ let loaded;
26959
+ try {
26960
+ loaded = await input.load();
26961
+ } catch (error) {
26962
+ if (error instanceof CliUsageError) {
26963
+ presentStructuralRejection(error, input.io);
26964
+ return { exitCode: 2 };
26965
+ }
26966
+ throw error;
26967
+ }
26968
+ return await runPostAdmissionManualResume({
26969
+ admitted: loaded.admitted,
26970
+ env: input.env,
26971
+ io: input.io,
26972
+ request: input.buildTurnRequest(loaded.admitted),
26973
+ adapters: input.adapters,
26974
+ ...input.effectiveEngine === void 0 ? {} : { effectiveEngine: input.effectiveEngine }
26975
+ });
26976
+ }
26770
26977
  async function runPostAdmissionOneShot(input) {
26771
26978
  const { admitted, env, io, request, adapters, effectiveEngine } = input;
26772
26979
  let lease;
@@ -26898,6 +27105,8 @@ async function runPostAdmissionManualResume(input) {
26898
27105
  var init_post_admission = __esm({
26899
27106
  "src/public-cli/post-admission.ts"() {
26900
27107
  "use strict";
27108
+ init_run_lifecycle();
27109
+ init_cli_errors();
26901
27110
  init_host_transition_prior_native();
26902
27111
  init_public_run_credentials();
26903
27112
  init_run_lifecycle();
@@ -27060,23 +27269,10 @@ async function runPublicCoderResume(request, env, io) {
27060
27269
  );
27061
27270
  }
27062
27271
  }
27063
- const turnRequest = buildCoderTurnRequest(admitted, {
27064
- packageRoot: env.packageRoot,
27065
- home: env.home,
27066
- agentDir: env.agentDir,
27067
- ...env.model === void 0 ? {} : { model: env.model },
27068
- ...env.engine === void 0 ? {} : { engine: env.engine },
27069
- ...env.timeoutMs === void 0 ? {} : { timeoutMs: env.timeoutMs },
27070
- ...admitted.correlationId === void 0 && env.correlationId === void 0 ? {} : { correlationId: admitted.correlationId ?? env.correlationId },
27071
- continuation: {
27072
- kind: "resume",
27073
- prompt: buildResumeContinuationPrompt({
27074
- packageRoot: env.packageRoot,
27075
- ...env.engine === void 0 ? {} : { engine: env.engine },
27076
- ...request.message === void 0 ? {} : { message: request.message }
27077
- })
27078
- }
27079
- });
27272
+ const turnRequest = buildCoderTurnRequest(
27273
+ admitted,
27274
+ resumeTurnRequestProjectionOptions(admitted, request, env)
27275
+ );
27080
27276
  return await runPostAdmissionManualResume({
27081
27277
  admitted,
27082
27278
  env,
@@ -27119,6 +27315,24 @@ function instructionSeatAdapters() {
27119
27315
  shouldPresentSettled: () => true
27120
27316
  };
27121
27317
  }
27318
+ async function runPublicInstructionSeatResume(request, env, io) {
27319
+ return await runPostAdmissionSeatResume({
27320
+ request,
27321
+ env,
27322
+ io,
27323
+ load: () => loadResumableInstructionSeatRun(
27324
+ env.home,
27325
+ request.runId,
27326
+ env.principalAuthority
27327
+ ),
27328
+ buildTurnRequest: (admitted) => buildInstructionSeatTurnRequest(
27329
+ admitted,
27330
+ resumeTurnRequestProjectionOptions(admitted, request, env)
27331
+ ),
27332
+ adapters: instructionSeatAdapters(),
27333
+ ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
27334
+ });
27335
+ }
27122
27336
  async function runPublicInstructionSeat(argv, env, io, role, parseArgv2) {
27123
27337
  let admitted;
27124
27338
  try {
@@ -27241,19 +27455,40 @@ async function runPublicCollector(argv, env, io, parseCollectorArgv2) {
27241
27455
  admitted,
27242
27456
  env,
27243
27457
  io,
27244
- request: turnRequest,
27245
- adapters: {
27246
- trySettle: (admitted2, authority) => trySettleCollectorTerminalResult(admitted2, authority),
27247
- shouldPresentSettled: () => true,
27248
- resolveRunnerKnownFailure: async ({ result: result2, sessionFile }) => {
27249
- const infrastructureFailure = await readCollectorInfrastructureFailure(sessionFile);
27250
- return result2.knownFailure ?? (infrastructureFailure === void 0 ? void 0 : {
27251
- cause: infrastructureFailure.cause,
27252
- diagnostic: infrastructureFailure.diagnostic,
27253
- ...infrastructureFailure.identity === void 0 ? {} : { identity: infrastructureFailure.identity }
27254
- });
27255
- }
27256
- },
27458
+ request: turnRequest,
27459
+ adapters: collectorAdapters(),
27460
+ ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
27461
+ });
27462
+ }
27463
+ function collectorAdapters() {
27464
+ return {
27465
+ trySettle: (admitted, authority) => trySettleCollectorTerminalResult(admitted, authority),
27466
+ shouldPresentSettled: () => true,
27467
+ resolveRunnerKnownFailure: async ({ result: result2, sessionFile }) => {
27468
+ const infrastructureFailure = await readCollectorInfrastructureFailure(sessionFile);
27469
+ return result2.knownFailure ?? (infrastructureFailure === void 0 ? void 0 : {
27470
+ cause: infrastructureFailure.cause,
27471
+ diagnostic: infrastructureFailure.diagnostic,
27472
+ ...infrastructureFailure.identity === void 0 ? {} : { identity: infrastructureFailure.identity }
27473
+ });
27474
+ }
27475
+ };
27476
+ }
27477
+ async function runPublicCollectorResume(request, env, io) {
27478
+ return await runPostAdmissionSeatResume({
27479
+ request,
27480
+ env,
27481
+ io,
27482
+ load: () => loadResumableCollectorRun(
27483
+ env.home,
27484
+ request.runId,
27485
+ env.principalAuthority
27486
+ ),
27487
+ buildTurnRequest: (admitted) => buildCollectorTurnRequest(
27488
+ admitted,
27489
+ resumeTurnRequestProjectionOptions(admitted, request, env)
27490
+ ),
27491
+ adapters: collectorAdapters(),
27257
27492
  ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
27258
27493
  });
27259
27494
  }
@@ -27444,8 +27679,11 @@ function readCcSessionBlocks(options) {
27444
27679
  }
27445
27680
  if (!isRecord15(parsed)) continue;
27446
27681
  const type = typeof parsed.type === "string" ? parsed.type : "";
27447
- if (type !== "user" && type !== "assistant") continue;
27448
- const transcript = messageText(parsed.message ?? parsed);
27682
+ const queuedCommand = type === "attachment" && isRecord15(parsed.attachment) && parsed.attachment.type === "queued_command" && isRecord15(parsed.attachment.origin) && parsed.attachment.origin.kind === "human" && typeof parsed.attachment.prompt === "string" ? parsed.attachment.prompt : void 0;
27683
+ if (type !== "user" && type !== "assistant" && queuedCommand === void 0) {
27684
+ continue;
27685
+ }
27686
+ const transcript = queuedCommand ?? messageText(parsed.message ?? parsed);
27449
27687
  if (transcript.trim() === "") continue;
27450
27688
  const entryId = typeof parsed.uuid === "string" ? parsed.uuid : typeof parsed.id === "string" ? parsed.id : `${basename7(sessionFile)}:${lineNo + 1}`;
27451
27689
  const timestamp2 = typeof parsed.timestamp === "string" ? parsed.timestamp : (/* @__PURE__ */ new Date(0)).toISOString();
@@ -27455,7 +27693,7 @@ function readCcSessionBlocks(options) {
27455
27693
  sourceRef: { sessionFile, entryId },
27456
27694
  transcript,
27457
27695
  timestamp: timestamp2,
27458
- isUserTurn: type === "user",
27696
+ isUserTurn: type === "user" || queuedCommand !== void 0,
27459
27697
  isNotification: notification
27460
27698
  });
27461
27699
  }
@@ -28782,43 +29020,19 @@ function countersignAdapters(options) {
28782
29020
  };
28783
29021
  }
28784
29022
  async function runPublicCountersignResume(request, env, io) {
28785
- let loaded;
28786
- try {
28787
- loaded = await loadResumableCountersignRun(
29023
+ return await runPostAdmissionSeatResume({
29024
+ request,
29025
+ env,
29026
+ io,
29027
+ load: () => loadResumableCountersignRun(
28788
29028
  env.home,
28789
29029
  request.runId,
28790
29030
  env.principalAuthority
28791
- );
28792
- } catch (error) {
28793
- if (error instanceof CliUsageError) {
28794
- presentStructuralRejection(error, io);
28795
- return { exitCode: 2 };
28796
- }
28797
- throw error;
28798
- }
28799
- const { admitted } = loaded;
28800
- const turnRequest = buildCountersignTurnRequest(admitted, {
28801
- packageRoot: env.packageRoot,
28802
- home: env.home,
28803
- agentDir: env.agentDir,
28804
- ...env.model === void 0 ? {} : { model: env.model },
28805
- ...env.engine === void 0 ? {} : { engine: env.engine },
28806
- ...env.timeoutMs === void 0 ? {} : { timeoutMs: env.timeoutMs },
28807
- ...admitted.correlationId === void 0 && env.correlationId === void 0 ? {} : { correlationId: admitted.correlationId ?? env.correlationId },
28808
- continuation: {
28809
- kind: "resume",
28810
- prompt: buildResumeContinuationPrompt({
28811
- packageRoot: env.packageRoot,
28812
- ...env.engine === void 0 ? {} : { engine: env.engine },
28813
- ...request.message === void 0 ? {} : { message: request.message }
28814
- })
28815
- }
28816
- });
28817
- return await runPostAdmissionManualResume({
28818
- admitted,
28819
- env,
28820
- io,
28821
- request: turnRequest,
29031
+ ),
29032
+ buildTurnRequest: (admitted) => buildCountersignTurnRequest(
29033
+ admitted,
29034
+ resumeTurnRequestProjectionOptions(admitted, request, env)
29035
+ ),
28822
29036
  adapters: countersignAdapters(),
28823
29037
  ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
28824
29038
  });
@@ -28999,43 +29213,19 @@ function gleanerLeftAdapters() {
28999
29213
  };
29000
29214
  }
29001
29215
  async function runPublicGleanerLeftResume(request, env, io) {
29002
- let loaded;
29003
- try {
29004
- loaded = await loadResumableGleanerLeftRun(
29216
+ return await runPostAdmissionSeatResume({
29217
+ request,
29218
+ env,
29219
+ io,
29220
+ load: () => loadResumableGleanerLeftRun(
29005
29221
  env.home,
29006
29222
  request.runId,
29007
29223
  env.principalAuthority
29008
- );
29009
- } catch (error) {
29010
- if (error instanceof CliUsageError) {
29011
- presentStructuralRejection(error, io);
29012
- return { exitCode: 2 };
29013
- }
29014
- throw error;
29015
- }
29016
- const { admitted } = loaded;
29017
- const turnRequest = buildGleanerLeftTurnRequest(admitted, {
29018
- packageRoot: env.packageRoot,
29019
- home: env.home,
29020
- agentDir: env.agentDir,
29021
- ...env.model === void 0 ? {} : { model: env.model },
29022
- ...env.engine === void 0 ? {} : { engine: env.engine },
29023
- ...env.timeoutMs === void 0 ? {} : { timeoutMs: env.timeoutMs },
29024
- ...admitted.correlationId === void 0 && env.correlationId === void 0 ? {} : { correlationId: admitted.correlationId ?? env.correlationId },
29025
- continuation: {
29026
- kind: "resume",
29027
- prompt: buildResumeContinuationPrompt({
29028
- packageRoot: env.packageRoot,
29029
- ...env.engine === void 0 ? {} : { engine: env.engine },
29030
- ...request.message === void 0 ? {} : { message: request.message }
29031
- })
29032
- }
29033
- });
29034
- return await runPostAdmissionManualResume({
29035
- admitted,
29036
- env,
29037
- io,
29038
- request: turnRequest,
29224
+ ),
29225
+ buildTurnRequest: (admitted) => buildGleanerLeftTurnRequest(
29226
+ admitted,
29227
+ resumeTurnRequestProjectionOptions(admitted, request, env)
29228
+ ),
29039
29229
  adapters: gleanerLeftAdapters(),
29040
29230
  ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
29041
29231
  });
@@ -29105,10 +29295,31 @@ async function runPublicDoctor(argv, env, io, parseDoctorArgv2) {
29105
29295
  env,
29106
29296
  io,
29107
29297
  request: turnRequest,
29108
- adapters: {
29109
- trySettle: (admitted2, authority) => trySettleDoctorTerminalResult(admitted2, authority),
29110
- shouldPresentSettled: (terminal) => isLawfulTypedTerminalOutcome(terminal.roleOutcome)
29111
- },
29298
+ adapters: doctorAdapters(),
29299
+ ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
29300
+ });
29301
+ }
29302
+ function doctorAdapters() {
29303
+ return {
29304
+ trySettle: (admitted, authority) => trySettleDoctorTerminalResult(admitted, authority),
29305
+ shouldPresentSettled: (terminal) => isLawfulTypedTerminalOutcome(terminal.roleOutcome)
29306
+ };
29307
+ }
29308
+ async function runPublicDoctorResume(request, env, io) {
29309
+ return await runPostAdmissionSeatResume({
29310
+ request,
29311
+ env,
29312
+ io,
29313
+ load: () => loadResumableDoctorRun(
29314
+ env.home,
29315
+ request.runId,
29316
+ env.principalAuthority
29317
+ ),
29318
+ buildTurnRequest: (admitted) => buildDoctorTurnRequest(
29319
+ admitted,
29320
+ resumeTurnRequestProjectionOptions(admitted, request, env)
29321
+ ),
29322
+ adapters: doctorAdapters(),
29112
29323
  ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
29113
29324
  });
29114
29325
  }
@@ -29278,23 +29489,10 @@ async function runPublicFixerResume(request, env, io) {
29278
29489
  io
29279
29490
  );
29280
29491
  }
29281
- const turnRequest = buildFixerTurnRequest(admitted, {
29282
- packageRoot: env.packageRoot,
29283
- home: env.home,
29284
- agentDir: env.agentDir,
29285
- ...env.model === void 0 ? {} : { model: env.model },
29286
- ...env.engine === void 0 ? {} : { engine: env.engine },
29287
- ...env.timeoutMs === void 0 ? {} : { timeoutMs: env.timeoutMs },
29288
- ...admitted.correlationId === void 0 && env.correlationId === void 0 ? {} : { correlationId: admitted.correlationId ?? env.correlationId },
29289
- continuation: {
29290
- kind: "resume",
29291
- prompt: buildResumeContinuationPrompt({
29292
- packageRoot: env.packageRoot,
29293
- ...env.engine === void 0 ? {} : { engine: env.engine },
29294
- ...request.message === void 0 ? {} : { message: request.message }
29295
- })
29296
- }
29297
- });
29492
+ const turnRequest = buildFixerTurnRequest(
29493
+ admitted,
29494
+ resumeTurnRequestProjectionOptions(admitted, request, env)
29495
+ );
29298
29496
  return await runPostAdmissionManualResume({
29299
29497
  admitted,
29300
29498
  env,
@@ -29374,11 +29572,39 @@ async function runPublicNotary(argv, env, io, parseNotaryArgv2) {
29374
29572
  env,
29375
29573
  io,
29376
29574
  request: turnRequest,
29377
- adapters: {
29378
- trySettle: (admitted2, authority) => trySettleNotaryTerminalResult(admitted2, authority),
29379
- // Accepted receipts and failure terminals both present via shared path.
29380
- shouldPresentSettled: () => true
29575
+ adapters: notaryAdapters(),
29576
+ ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
29577
+ });
29578
+ }
29579
+ function notaryAdapters() {
29580
+ return {
29581
+ trySettle: (admitted, authority) => trySettleNotaryTerminalResult(admitted, authority),
29582
+ // Accepted receipts and failure terminals both present via shared path.
29583
+ shouldPresentSettled: () => true
29584
+ };
29585
+ }
29586
+ async function runPublicNotaryResume(request, env, io) {
29587
+ return await runPostAdmissionSeatResume({
29588
+ request,
29589
+ env,
29590
+ io,
29591
+ load: () => {
29592
+ if (request.message !== void 0) {
29593
+ throw new CliUsageError(
29594
+ "notary rejects caller prompt/instruction; only zero caller-prompt continuation admitted"
29595
+ );
29596
+ }
29597
+ return loadResumableNotaryRun(
29598
+ env.home,
29599
+ request.runId,
29600
+ env.principalAuthority
29601
+ );
29381
29602
  },
29603
+ buildTurnRequest: (admitted) => buildNotaryTurnRequest(
29604
+ admitted,
29605
+ resumeTurnRequestProjectionOptions(admitted, request, env)
29606
+ ),
29607
+ adapters: notaryAdapters(),
29382
29608
  ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
29383
29609
  });
29384
29610
  }
@@ -29454,10 +29680,31 @@ async function runPublicInspector(argv, env, io, parseInspectorArgv2) {
29454
29680
  env,
29455
29681
  io,
29456
29682
  request: turnRequest,
29457
- adapters: {
29458
- trySettle: (admitted2, authority) => trySettleInspectorTerminalResult(admitted2, authority),
29459
- shouldPresentSettled: () => true
29460
- },
29683
+ adapters: inspectorAdapters(),
29684
+ ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
29685
+ });
29686
+ }
29687
+ function inspectorAdapters() {
29688
+ return {
29689
+ trySettle: (admitted, authority) => trySettleInspectorTerminalResult(admitted, authority),
29690
+ shouldPresentSettled: () => true
29691
+ };
29692
+ }
29693
+ async function runPublicInspectorResume(request, env, io) {
29694
+ return await runPostAdmissionSeatResume({
29695
+ request,
29696
+ env,
29697
+ io,
29698
+ load: () => loadResumableInspectorRun(
29699
+ env.home,
29700
+ request.runId,
29701
+ env.principalAuthority
29702
+ ),
29703
+ buildTurnRequest: (admitted) => buildInspectorTurnRequest(
29704
+ admitted,
29705
+ resumeTurnRequestProjectionOptions(admitted, request, env)
29706
+ ),
29707
+ adapters: inspectorAdapters(),
29461
29708
  ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
29462
29709
  });
29463
29710
  }
@@ -29559,39 +29806,15 @@ async function runPublicJudge(argv, env, io, parseJudgeArgv2) {
29559
29806
  });
29560
29807
  }
29561
29808
  async function runPublicResume(request, env, io) {
29562
- let loaded;
29563
- try {
29564
- loaded = await loadResumableJudgeRun(env.home, request.runId, env.principalAuthority);
29565
- } catch (error) {
29566
- if (error instanceof CliUsageError) {
29567
- presentStructuralRejection(error, io);
29568
- return { exitCode: 2 };
29569
- }
29570
- throw error;
29571
- }
29572
- const { admitted } = loaded;
29573
- const turnRequest = buildJudgeTurnRequest(admitted, {
29574
- packageRoot: env.packageRoot,
29575
- home: env.home,
29576
- agentDir: env.agentDir,
29577
- ...env.model === void 0 ? {} : { model: env.model },
29578
- ...env.engine === void 0 ? {} : { engine: env.engine },
29579
- ...env.timeoutMs === void 0 ? {} : { timeoutMs: env.timeoutMs },
29580
- ...admitted.correlationId === void 0 && env.correlationId === void 0 ? {} : { correlationId: admitted.correlationId ?? env.correlationId },
29581
- continuation: {
29582
- kind: "resume",
29583
- prompt: buildResumeContinuationPrompt({
29584
- packageRoot: env.packageRoot,
29585
- ...env.engine === void 0 ? {} : { engine: env.engine },
29586
- ...request.message === void 0 ? {} : { message: request.message }
29587
- })
29588
- }
29589
- });
29590
- return await runPostAdmissionManualResume({
29591
- admitted,
29809
+ return await runPostAdmissionSeatResume({
29810
+ request,
29592
29811
  env,
29593
29812
  io,
29594
- request: turnRequest,
29813
+ load: () => loadResumableJudgeRun(env.home, request.runId, env.principalAuthority),
29814
+ buildTurnRequest: (admitted) => buildJudgeTurnRequest(
29815
+ admitted,
29816
+ resumeTurnRequestProjectionOptions(admitted, request, env)
29817
+ ),
29595
29818
  adapters: judgeAdapters(),
29596
29819
  ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
29597
29820
  });
@@ -29870,23 +30093,10 @@ async function runPublicMergerResume(request, env, io) {
29870
30093
  io
29871
30094
  );
29872
30095
  }
29873
- const turnRequest = buildMergerTurnRequest(admitted, {
29874
- packageRoot: env.packageRoot,
29875
- home: env.home,
29876
- agentDir: env.agentDir,
29877
- ...env.model === void 0 ? {} : { model: env.model },
29878
- ...env.engine === void 0 ? {} : { engine: env.engine },
29879
- ...env.timeoutMs === void 0 ? {} : { timeoutMs: env.timeoutMs },
29880
- ...admitted.correlationId === void 0 && env.correlationId === void 0 ? {} : { correlationId: admitted.correlationId ?? env.correlationId },
29881
- continuation: {
29882
- kind: "resume",
29883
- prompt: buildResumeContinuationPrompt({
29884
- packageRoot: env.packageRoot,
29885
- ...env.engine === void 0 ? {} : { engine: env.engine },
29886
- ...request.message === void 0 ? {} : { message: request.message }
29887
- })
29888
- }
29889
- });
30096
+ const turnRequest = buildMergerTurnRequest(
30097
+ admitted,
30098
+ resumeTurnRequestProjectionOptions(admitted, request, env)
30099
+ );
29890
30100
  return await runPostAdmissionManualResume({
29891
30101
  admitted,
29892
30102
  env,
@@ -30070,23 +30280,10 @@ async function runPublicReviewerResume(request, env, io) {
30070
30280
  io
30071
30281
  );
30072
30282
  }
30073
- const turnRequest = buildReviewerTurnRequest(admitted, {
30074
- packageRoot: env.packageRoot,
30075
- home: env.home,
30076
- agentDir: env.agentDir,
30077
- ...env.model === void 0 ? {} : { model: env.model },
30078
- ...env.engine === void 0 ? {} : { engine: env.engine },
30079
- ...env.timeoutMs === void 0 ? {} : { timeoutMs: env.timeoutMs },
30080
- ...admitted.correlationId === void 0 && env.correlationId === void 0 ? {} : { correlationId: admitted.correlationId ?? env.correlationId },
30081
- continuation: {
30082
- kind: "resume",
30083
- prompt: buildResumeContinuationPrompt({
30084
- packageRoot: env.packageRoot,
30085
- ...env.engine === void 0 ? {} : { engine: env.engine },
30086
- ...request.message === void 0 ? {} : { message: request.message }
30087
- })
30088
- }
30089
- });
30283
+ const turnRequest = buildReviewerTurnRequest(
30284
+ admitted,
30285
+ resumeTurnRequestProjectionOptions(admitted, request, env)
30286
+ );
30090
30287
  return await runPostAdmissionManualResume({
30091
30288
  admitted,
30092
30289
  env,
@@ -32819,118 +33016,17 @@ async function runAkRole(argv, env) {
32819
33016
  const credentials = env.credentials ?? await loadCredentialProviders(agentDir);
32820
33017
  const resumeRequest = parseResumeRequest(parsed.args);
32821
33018
  const resumeRole = await peekRoleRunRole(home, resumeRequest.runId);
32822
- if (resumeRole !== void 0 && ONE_SHOT_ROLES.includes(resumeRole)) {
32823
- throw new CliUsageError(
32824
- `${resumeRole} role runs are one-shot and cannot be resumed`
32825
- );
32826
- }
32827
- const resumeSeatRole = resumeRole === "coder" ? "coder" : resumeRole === "fixer" ? "fixer" : resumeRole === "reviewer" ? "reviewer" : resumeRole === "merger" ? "merger" : resumeRole === "countersign" ? "countersign" : resumeRole === "gleaner-left" ? "gleaner-left" : "judge";
33019
+ const dispatch = resumeRole === void 0 ? RESUME_SEAT_DISPATCH.judge : RESUME_SEAT_DISPATCH[resumeRole];
32828
33020
  const seat = resolveEffectiveSeat(
32829
33021
  config,
32830
- resumeSeatRole,
33022
+ dispatch.seat,
32831
33023
  credentials,
32832
33024
  invocationFromParsed(parsed)
32833
33025
  );
32834
- if (resumeRole === "coder") {
32835
- const result3 = await runPublicCoderResume(
32836
- resumeRequest,
32837
- createRoleEnvironment(env, {
32838
- role: "coder",
32839
- home,
32840
- agentDir,
32841
- cwd,
32842
- credentials,
32843
- seat,
32844
- config
32845
- }),
32846
- io
32847
- );
32848
- return cliResultFromRoleRun(result3);
32849
- }
32850
- if (resumeRole === "fixer") {
32851
- const result3 = await runPublicFixerResume(
32852
- resumeRequest,
32853
- createRoleEnvironment(env, {
32854
- role: "fixer",
32855
- home,
32856
- agentDir,
32857
- cwd,
32858
- credentials,
32859
- seat,
32860
- config
32861
- }),
32862
- io
32863
- );
32864
- return cliResultFromRoleRun(result3);
32865
- }
32866
- if (resumeRole === "reviewer") {
32867
- const result3 = await runPublicReviewerResume(
32868
- resumeRequest,
32869
- createRoleEnvironment(env, {
32870
- role: "reviewer",
32871
- home,
32872
- agentDir,
32873
- cwd,
32874
- credentials,
32875
- seat,
32876
- config
32877
- }),
32878
- io
32879
- );
32880
- return cliResultFromRoleRun(result3);
32881
- }
32882
- if (resumeRole === "merger") {
32883
- const result3 = await runPublicMergerResume(
32884
- resumeRequest,
32885
- createRoleEnvironment(env, {
32886
- role: "merger",
32887
- home,
32888
- agentDir,
32889
- cwd,
32890
- credentials,
32891
- seat,
32892
- config
32893
- }),
32894
- io
32895
- );
32896
- return cliResultFromRoleRun(result3);
32897
- }
32898
- if (resumeRole === "countersign") {
32899
- const result3 = await runPublicCountersignResume(
32900
- resumeRequest,
32901
- createRoleEnvironment(env, {
32902
- role: "countersign",
32903
- home,
32904
- agentDir,
32905
- cwd,
32906
- credentials,
32907
- seat,
32908
- config
32909
- }),
32910
- io
32911
- );
32912
- return cliResultFromRoleRun(result3);
32913
- }
32914
- if (resumeRole === "gleaner-left") {
32915
- const result3 = await runPublicGleanerLeftResume(
32916
- resumeRequest,
32917
- createRoleEnvironment(env, {
32918
- role: "gleaner-left",
32919
- home,
32920
- agentDir,
32921
- cwd,
32922
- credentials,
32923
- seat,
32924
- config
32925
- }),
32926
- io
32927
- );
32928
- return cliResultFromRoleRun(result3);
32929
- }
32930
- const result2 = await runPublicResume(
33026
+ const result2 = await dispatch.run(
32931
33027
  resumeRequest,
32932
33028
  createRoleEnvironment(env, {
32933
- role: "judge",
33029
+ role: dispatch.seat,
32934
33030
  home,
32935
33031
  agentDir,
32936
33032
  cwd,
@@ -33239,7 +33335,7 @@ async function runAkRole(argv, env) {
33239
33335
  return { exitCode: 1 };
33240
33336
  }
33241
33337
  }
33242
- var PUBLIC_ROLE_ARGV, PUBLIC_GLOBAL_OPTIONS, HostSelectionError, THINKING_LEVELS2;
33338
+ var RESUME_SEAT_DISPATCH, PUBLIC_ROLE_ARGV, PUBLIC_GLOBAL_OPTIONS, HostSelectionError, THINKING_LEVELS2;
33243
33339
  var init_cli = __esm({
33244
33340
  "src/public-cli/cli.ts"() {
33245
33341
  "use strict";
@@ -33259,7 +33355,6 @@ var init_cli = __esm({
33259
33355
  init_collector_run();
33260
33356
  init_countersign_run();
33261
33357
  init_gleaner_left_run();
33262
- init_packaged_role_registry();
33263
33358
  init_doctor_run();
33264
33359
  init_fixer_run();
33265
33360
  init_notary_run();
@@ -33273,6 +33368,21 @@ var init_cli = __esm({
33273
33368
  init_settlement();
33274
33369
  init_role_turn_host();
33275
33370
  init_cli_errors();
33371
+ RESUME_SEAT_DISPATCH = {
33372
+ judge: { seat: "judge", run: runPublicResume },
33373
+ coder: { seat: "coder", run: runPublicCoderResume },
33374
+ fixer: { seat: "fixer", run: runPublicFixerResume },
33375
+ reviewer: { seat: "reviewer", run: runPublicReviewerResume },
33376
+ merger: { seat: "merger", run: runPublicMergerResume },
33377
+ countersign: { seat: "countersign", run: runPublicCountersignResume },
33378
+ "gleaner-left": { seat: "gleaner-left", run: runPublicGleanerLeftResume },
33379
+ collector: { seat: "collector", run: runPublicCollectorResume },
33380
+ doctor: { seat: "doctor", run: runPublicDoctorResume },
33381
+ notary: { seat: "notary", run: runPublicNotaryResume },
33382
+ inspector: { seat: "inspector", run: runPublicInspectorResume },
33383
+ gatekeeper: { seat: "gatekeeper", run: runPublicInstructionSeatResume },
33384
+ navigator: { seat: "navigator", run: runPublicInstructionSeatResume }
33385
+ };
33276
33386
  PUBLIC_ROLE_ARGV = {
33277
33387
  judge: { parse: parseJudgeArgv, options: optionsForOwner("judge") },
33278
33388
  countersign: { parse: parseCountersignArgv, options: optionsForOwner("countersign") },