@akagilnc/pi-workflow-roles 0.1.4956 → 0.1.4980

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.
@@ -2856,7 +2856,7 @@ function validateDoctorSubmissionShape(value) {
2856
2856
  function validateDoctorOutput(value, _patient, _store) {
2857
2857
  return validateDoctorSubmissionShape(value);
2858
2858
  }
2859
- var DOCTOR_EVIDENCE_TOOL_NAME, DOCTOR_OUTPUT_TOOL_NAME, DOCTOR_AUDIT_TOOL_NAME, DOCTOR_ACCEPTED_AUDIT_NO_RECEIPT_TEXT, DOCTOR_OUTPUT_TOOL_DESCRIPTION, DOCTOR_TARGET_KINDS, nonblank, evidenceIds, guardrail, lastRealBite, assetKinds, findingBody, finding, caseIdentity, DOCTOR_STATUS_DESCRIPTION, doctorSubmissionVariants, doctorSubmissionSchema, doctorEvidenceReadSchema, DoctorEvidenceStore;
2859
+ var DOCTOR_EVIDENCE_TOOL_NAME, DOCTOR_OUTPUT_TOOL_NAME, DOCTOR_AUDIT_TOOL_NAME, DOCTOR_OUTPUT_TOOL_DESCRIPTION, DOCTOR_TARGET_KINDS, nonblank, evidenceIds, guardrail, lastRealBite, assetKinds, findingBody, finding, caseIdentity, DOCTOR_STATUS_DESCRIPTION, doctorSubmissionVariants, doctorSubmissionSchema, doctorEvidenceReadSchema, DoctorEvidenceStore;
2860
2860
  var init_doctor_contracts = __esm({
2861
2861
  "src/doctor-contracts.ts"() {
2862
2862
  "use strict";
@@ -2866,7 +2866,6 @@ var init_doctor_contracts = __esm({
2866
2866
  DOCTOR_EVIDENCE_TOOL_NAME = "ak_doctor_evidence";
2867
2867
  DOCTOR_OUTPUT_TOOL_NAME = "ak_doctor_output";
2868
2868
  DOCTOR_AUDIT_TOOL_NAME = "ak_doctor_audit_decision";
2869
- DOCTOR_ACCEPTED_AUDIT_NO_RECEIPT_TEXT = "\u592A\u533B\u7F72\u56DE\u6267\u5DF2\u63A5\u53D7\uFF1B\u5BA1\u8BA1\u65E0\u56DE\u6267";
2870
2869
  DOCTOR_OUTPUT_TOOL_DESCRIPTION = "\u63D0\u4EA4\u552F\u4E00\u7EC8\u5C40\u5355\u6848\u8BC1\u8BCD\uFF1Bcompleted \u5141\u8BB8\u7A7A findings\u3002";
2871
2870
  DOCTOR_TARGET_KINDS = ["law", "gate", "template", "station", "seat"];
2872
2871
  nonblank = Type8.Optional(Type8.String());
@@ -3337,15 +3336,13 @@ var secretariat_contracts_exports = {};
3337
3336
  __export(secretariat_contracts_exports, {
3338
3337
  SECRETARIAT_COUNTERSIGN_TERMINAL_FACT_KEY: () => SECRETARIAT_COUNTERSIGN_TERMINAL_FACT_KEY,
3339
3338
  SECRETARIAT_GATE_OFFICER_ENTRY_TYPE: () => SECRETARIAT_GATE_OFFICER_ENTRY_TYPE,
3340
- SECRETARIAT_OUTPUT_TOOL_NAME: () => SECRETARIAT_OUTPUT_TOOL_NAME,
3341
- SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME: () => SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME
3339
+ SECRETARIAT_OUTPUT_TOOL_NAME: () => SECRETARIAT_OUTPUT_TOOL_NAME
3342
3340
  });
3343
- var SECRETARIAT_OUTPUT_TOOL_NAME, SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME, SECRETARIAT_GATE_OFFICER_ENTRY_TYPE, SECRETARIAT_COUNTERSIGN_TERMINAL_FACT_KEY;
3341
+ var SECRETARIAT_OUTPUT_TOOL_NAME, SECRETARIAT_GATE_OFFICER_ENTRY_TYPE, SECRETARIAT_COUNTERSIGN_TERMINAL_FACT_KEY;
3344
3342
  var init_secretariat_contracts = __esm({
3345
3343
  "src/secretariat-contracts.ts"() {
3346
3344
  "use strict";
3347
3345
  SECRETARIAT_OUTPUT_TOOL_NAME = "ak_secretariat_output";
3348
- SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME = "ak_secretariat_summon_countersign";
3349
3346
  SECRETARIAT_GATE_OFFICER_ENTRY_TYPE = "ak-secretariat-gate-officer";
3350
3347
  SECRETARIAT_COUNTERSIGN_TERMINAL_FACT_KEY = "countersignTerminal";
3351
3348
  }
@@ -3393,7 +3390,6 @@ __export(packaged_role_registry_exports, {
3393
3390
  packagedRebindSourceOnResume: () => packagedRebindSourceOnResume,
3394
3391
  packagedResumeSourcePath: () => packagedResumeSourcePath,
3395
3392
  packagedRoleAcceptedOutputTool: () => packagedRoleAcceptedOutputTool,
3396
- packagedRoleAcceptedText: () => packagedRoleAcceptedText,
3397
3393
  packagedRoleActivationFlags: () => packagedRoleActivationFlags,
3398
3394
  packagedRoleInputFlag: () => packagedRoleInputFlag,
3399
3395
  packagedRoleMetadata: () => packagedRoleMetadata,
@@ -3441,13 +3437,6 @@ function packagedRolePhaseFlag(role) {
3441
3437
  function packagedRoleOutputTool(role) {
3442
3438
  return packagedRoleMetadata(role)?.outputTool;
3443
3439
  }
3444
- function packagedRoleAcceptedText(role) {
3445
- const record4 = packagedRoleMetadata(role);
3446
- if (record4 === void 0) {
3447
- throw new Error(`Unsupported workflow role: ${String(role)}`);
3448
- }
3449
- return record4.acceptedText;
3450
- }
3451
3440
  function packagedMethodLoadFailureCause(role) {
3452
3441
  const record4 = packagedRoleMetadata(role);
3453
3442
  if (record4 === void 0 || !("methodLoadFailureCause" in record4)) return void 0;
@@ -3620,7 +3609,6 @@ var init_packaged_role_registry = __esm({
3620
3609
  auditTool: JUDGE_AUDIT_TOOL_NAME,
3621
3610
  settlement: "sealed",
3622
3611
  runnerFailure: "engine-detour-known-first",
3623
- acceptedText: "\u5927\u7406\u5BFA\u56DE\u6267\u5DF2\u63A5\u53D7",
3624
3612
  /** Factory board: court until another station has started, then marshal. */
3625
3613
  boardPlacement: "judge-history",
3626
3614
  /** Navigator subject is the public admitted instruction when the run is bound. */
@@ -3659,7 +3647,6 @@ var init_packaged_role_registry = __esm({
3659
3647
  ],
3660
3648
  method: "observed"
3661
3649
  },
3662
- acceptedText: "\u4FEE\u5185\u53F8\u56DE\u6267\u5DF2\u63A5\u53D7",
3663
3650
  boardPlacement: "marshal",
3664
3651
  activationFlags: [
3665
3652
  { field: "packetPath", flag: "ak-fix-packet", binds: "input" },
@@ -3698,7 +3685,6 @@ var init_packaged_role_registry = __esm({
3698
3685
  ],
3699
3686
  method: "optional"
3700
3687
  },
3701
- acceptedText: "\u5C06\u4F5C\u76D1\u56DE\u6267\u5DF2\u63A5\u53D7",
3702
3688
  activationFlags: [
3703
3689
  { field: "taskPath", flag: "ak-coder-task", binds: "input" },
3704
3690
  { field: "phase", flag: "ak-coder-phase", binds: "phase" }
@@ -3744,7 +3730,6 @@ var init_packaged_role_registry = __esm({
3744
3730
  /** Frozen base/lens/authority become the initial prompt; instruction follows. */
3745
3731
  transportPrompt: "skill-args",
3746
3732
  runnerFailure: "engine-detour-record-first",
3747
- acceptedText: "\u5FA1\u53F2\u53F0\u56DE\u6267\u5DF2\u63A5\u53D7",
3748
3733
  boardPlacement: "marshal",
3749
3734
  activationFlags: [
3750
3735
  { field: "baseRevision", flag: "ak-review-base" },
@@ -3786,7 +3771,6 @@ var init_packaged_role_registry = __esm({
3786
3771
  { key: "manifestDigest" }
3787
3772
  ]
3788
3773
  },
3789
- acceptedText: "\u901A\u8FDB\u53F8\u56DE\u6267\u5DF2\u63A5\u53D7",
3790
3774
  boardPlacement: "collector",
3791
3775
  /** Taishi acceptance is a typed groups array, not a status leaf. */
3792
3776
  analystTerminal: "groups",
@@ -3820,7 +3804,6 @@ var init_packaged_role_registry = __esm({
3820
3804
  ],
3821
3805
  doctorReportFacts: true
3822
3806
  },
3823
- acceptedText: "\u592A\u533B\u7F72\u56DE\u6267\u5DF2\u63A5\u53D7",
3824
3807
  /** Navigator subject is the doctor case, not the case-path file bytes. */
3825
3808
  navigatorSubject: "case",
3826
3809
  activationFlags: [
@@ -3856,7 +3839,6 @@ var init_packaged_role_registry = __esm({
3856
3839
  ],
3857
3840
  method: "observed"
3858
3841
  },
3859
- acceptedText: "\u5408\u5E76\u56DE\u6267\u5DF2\u63A5\u53D7",
3860
3842
  activationFlags: [
3861
3843
  { field: "inputPath", from: "mergerInputPath", flag: "ak-merger-input", binds: "input" }
3862
3844
  ],
@@ -3889,7 +3871,6 @@ var init_packaged_role_registry = __esm({
3889
3871
  /** Court reask replaces the initial prompt. Otherwise the fixed kickoff. */
3890
3872
  reaskPrompt: true,
3891
3873
  transportPrompt: "fixed-kickoff",
3892
- acceptedText: "\u7B26\u5B9D\u90CE\u56DE\u6267\u5DF2\u63A5\u53D7",
3893
3874
  gateStageLabel: "\u7B26\u5B9D\u90CE",
3894
3875
  /** Gate summon binds --source-run and keeps dialogue off the argv. */
3895
3876
  gateSummon: "source-run",
@@ -3914,7 +3895,6 @@ var init_packaged_role_registry = __esm({
3914
3895
  phases: [null],
3915
3896
  outputTool: COUNTERSIGN_OUTPUT_TOOL_NAME,
3916
3897
  settlement: "accepted",
3917
- acceptedText: "\u7ED9\u4E8B\u4E2D\u56DE\u6267\u5DF2\u63A5\u53D7",
3918
3898
  gateStageLabel: "\u7ED9\u4E8B\u4E2D",
3919
3899
  /** Gate queue reads countersignStatus, not the shared three-state status. */
3920
3900
  gateDecision: "countersign-status",
@@ -3940,7 +3920,6 @@ var init_packaged_role_registry = __esm({
3940
3920
  settlement: "accepted",
3941
3921
  /** Project the durable 给事中 officer entry onto the shared accepted-tool settlement. */
3942
3922
  projectCountersignTerminal: true,
3943
- acceptedText: "\u4E2D\u4E66\u7701\u56DE\u6267\u5DF2\u63A5\u53D7",
3944
3923
  activationFlags: [
3945
3924
  { field: "ticketNumber" }
3946
3925
  ],
@@ -3970,7 +3949,6 @@ var init_packaged_role_registry = __esm({
3970
3949
  settlement: "accepted",
3971
3950
  /** Bound comparison base is the initial prompt; instruction follows. */
3972
3951
  transportPrompt: "baseline",
3973
- acceptedText: "\u5DE6\u62FE\u9057\u56DE\u6267\u5DF2\u63A5\u53D7",
3974
3952
  activationFlags: [
3975
3953
  { field: "baseRevision", flag: "ak-gleaner-left-base" }
3976
3954
  ],
@@ -4001,7 +3979,6 @@ var init_packaged_role_registry = __esm({
4001
3979
  settlement: "accepted",
4002
3980
  /** Court reask replaces the initial prompt. */
4003
3981
  reaskPrompt: true,
4004
- acceptedText: "\u53F0\u9662\u56DE\u6267\u5DF2\u63A5\u53D7",
4005
3982
  gateStageLabel: "\u53F0\u9662",
4006
3983
  activationFlags: [
4007
3984
  {
@@ -4033,7 +4010,6 @@ var init_packaged_role_registry = __esm({
4033
4010
  outputTool: GATEKEEPER_OUTPUT_TOOL_NAME,
4034
4011
  settlement: "accepted",
4035
4012
  runnerFailure: "engine-detour-record-first",
4036
- acceptedText: "\u95E8\u4E0B\u7701\u51B3\u8BAE\u5DF2\u53D7\u7406",
4037
4013
  activationStage: "load-and-install",
4038
4014
  // Province materials; officers reuse their own public records below.
4039
4015
  sessionMaterials: ["CLAUDE.md", "souls/gatekeeper.md", "souls/quality-law.md", "souls/gate-output-guide.md"]
@@ -4049,7 +4025,6 @@ var init_packaged_role_registry = __esm({
4049
4025
  outputTool: NAVIGATOR_OUTPUT_TOOL_NAME,
4050
4026
  settlement: "accepted",
4051
4027
  runnerFailure: "engine-detour-record-first",
4052
- acceptedText: "\u6E38\u5955\u4F7F\u5EFA\u8BAE\u5DF2\u53D7\u7406",
4053
4028
  activationStage: "load-and-install",
4054
4029
  sessionMaterials: ["CLAUDE.md", "souls/navigator.md"]
4055
4030
  },
@@ -4073,7 +4048,6 @@ var init_packaged_role_registry = __esm({
4073
4048
  /** Court reask replaces the initial prompt. */
4074
4049
  reaskPrompt: true,
4075
4050
  runnerFailure: "engine-detour-record-first",
4076
- acceptedText: "\u5BA1\u5211\u9662\u56DE\u6267\u5DF2\u63A5\u53D7",
4077
4051
  gateStageLabel: "\u5BA1\u5211\u9662",
4078
4052
  /** Gate summon binds --subject judge and --source-run. */
4079
4053
  gateSummon: "subject-source",
@@ -4092,7 +4066,6 @@ var init_packaged_role_registry = __esm({
4092
4066
  phases: [null],
4093
4067
  outputTool: DIARIST_OUTPUT_TOOL_NAME,
4094
4068
  settlement: "accepted",
4095
- acceptedText: "\u8D77\u5C45\u90CE\u56DE\u6267\u5DF2\u63A5\u53D7",
4096
4069
  activationStage: "load-and-install",
4097
4070
  sessionMaterials: [
4098
4071
  "CLAUDE.md",
@@ -4399,7 +4372,7 @@ function projectOfficerTerminal(officer, summoned) {
4399
4372
  status: "escalate",
4400
4373
  officer,
4401
4374
  // This-court receipt only (#879) — historical rows remain on terminal.submissions.
4402
- receipt: thisCourt.length > 0 ? thisCourt[thisCourt.length - 1] : retainedReceipt(outcome)
4375
+ receipt: outcome.decisiveFacts !== void 0 && Object.hasOwn(outcome.decisiveFacts, "auditEscalationReceipt") ? outcome.decisiveFacts.auditEscalationReceipt : thisCourt.length > 0 ? thisCourt[thisCourt.length - 1] : retainedReceipt(outcome)
4403
4376
  },
4404
4377
  summoned
4405
4378
  );
@@ -4521,8 +4494,8 @@ function formatTerminalResult(result) {
4521
4494
  `diagnostic ${encodeTerminalField(result.roleOutcome.diagnostic)}`
4522
4495
  );
4523
4496
  }
4524
- if (result.roleOutcome.kind === "failure" || result.roleOutcome.kind === "no_receipt") {
4525
- const facts = result.roleOutcome.decisiveFacts;
4497
+ if (result.roleOutcome.kind === "failure" || result.roleOutcome.kind === "no_receipt" || result.roleOutcome.kind === "audit_escalation") {
4498
+ const facts = result.roleOutcome.decisiveFacts ?? {};
4526
4499
  for (const [key, value] of Object.entries(facts)) {
4527
4500
  if (value === void 0) continue;
4528
4501
  const rendered = typeof value === "string" ? value : JSON.stringify(value);
@@ -12982,12 +12955,16 @@ __export(audit_escalation_exports, {
12982
12955
  disposeComplianceDecision: () => disposeComplianceDecision,
12983
12956
  isAuditEscalationProjection: () => isAuditEscalationProjection,
12984
12957
  isAuditEscalationResult: () => isAuditEscalationResult,
12985
- projectAuditEscalation: () => projectAuditEscalation
12958
+ projectAuditEscalation: () => projectAuditEscalation,
12959
+ projectGatekeeperEscalation: () => projectGatekeeperEscalation
12986
12960
  });
12987
12961
  function buildAuditEscalationResult(decision, deliveredOutput) {
12988
12962
  const auditOwned = {
12989
12963
  kind: AUDIT_ESCALATION_KIND
12990
12964
  };
12965
+ if (Object.hasOwn(decision, "receipt")) {
12966
+ auditOwned.receipt = decision.receipt;
12967
+ }
12991
12968
  if (Object.hasOwn(decision, "conflicts")) {
12992
12969
  auditOwned.conflicts = decision.conflicts;
12993
12970
  }
@@ -13017,14 +12994,23 @@ function isAuditEscalationProjection(value) {
13017
12994
  }
13018
12995
  function projectAuditEscalation(decision, deliveredOutput) {
13019
12996
  const details = buildAuditEscalationResult(decision, deliveredOutput);
13020
- const original = deliveredOutput !== void 0 ? deliveredOutput : decision;
13021
12997
  return {
13022
- content: [{ type: "text", text: readableGateItem(original) }],
12998
+ content: [],
13023
12999
  details,
13024
13000
  terminate: true,
13025
13001
  ...decision.usage === void 0 ? {} : { usage: decision.usage }
13026
13002
  };
13027
13003
  }
13004
+ function projectGatekeeperEscalation(result, deliveredOutput) {
13005
+ const receipt = result.receipt;
13006
+ const record4 = receipt !== null && typeof receipt === "object" && !Array.isArray(receipt) ? receipt : void 0;
13007
+ return projectAuditEscalation({
13008
+ status: "escalate",
13009
+ officer: result.officer,
13010
+ conflicts: receipt,
13011
+ ...record4 !== void 0 && Object.hasOwn(record4, "decisionGate") ? { decisionGate: record4.decisionGate } : {}
13012
+ }, deliveredOutput);
13013
+ }
13028
13014
  function isAuditEscalationResult(value) {
13029
13015
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
13030
13016
  return false;
@@ -13073,7 +13059,6 @@ var AUDIT_ESCALATION_KIND, AUDIT_ESCALATION_LIVE_REGISTRY;
13073
13059
  var init_audit_escalation = __esm({
13074
13060
  "src/audit-escalation.ts"() {
13075
13061
  "use strict";
13076
- init_readable_gate_item();
13077
13062
  init_submission_errors();
13078
13063
  AUDIT_ESCALATION_KIND = "audit_escalation";
13079
13064
  AUDIT_ESCALATION_LIVE_REGISTRY = /* @__PURE__ */ new WeakSet();
@@ -13188,6 +13173,8 @@ function rowFromPayload(kind, payload, accepted, roleFallback) {
13188
13173
  ...role === void 0 ? {} : { role },
13189
13174
  kind,
13190
13175
  accepted,
13176
+ ...Object.hasOwn(payload, "auditReceipt") ? { auditReceipt: payload.auditReceipt } : {},
13177
+ ...Object.hasOwn(payload, "auditOfficer") ? { auditOfficer: payload.auditOfficer } : {},
13191
13178
  ...typeof payload.toolCallId === "string" && payload.toolCallId.length > 0 ? { toolCallId: payload.toolCallId } : {}
13192
13179
  };
13193
13180
  }
@@ -13452,6 +13439,7 @@ function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (er
13452
13439
  }
13453
13440
  }
13454
13441
  if (isAuditEscalationProjection(result.details) || isAuditEscalationProjection(params)) {
13442
+ const audit = isAuditEscalationProjection(result.details) && typeof result.details.audit === "object" && result.details.audit !== null ? result.details.audit : void 0;
13455
13443
  const closed2 = {
13456
13444
  role,
13457
13445
  kind: "audit_escalation",
@@ -13463,7 +13451,9 @@ function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (er
13463
13451
  toolCallId,
13464
13452
  outcome: "audit-escalation",
13465
13453
  role,
13466
- accepted: params
13454
+ accepted: params,
13455
+ ...audit !== void 0 && (Object.hasOwn(audit, "receipt") || Object.hasOwn(audit, "conflicts")) ? { auditReceipt: Object.hasOwn(audit, "receipt") ? audit.receipt : audit.conflicts } : {},
13456
+ ...audit !== void 0 && Object.hasOwn(audit, "officer") ? { auditOfficer: audit.officer } : {}
13467
13457
  });
13468
13458
  await projectClosure(closed2, context);
13469
13459
  return result;
@@ -14579,7 +14569,17 @@ function roleOutcomeFromRows(role, rows) {
14579
14569
  if (terminal.length === 0) return void 0;
14580
14570
  const payloads = mine.map((row) => row.accepted);
14581
14571
  if (terminal.some((row) => row.kind === "audit-escalation")) {
14582
- return { kind: "audit_escalation", role, status: "audit_escalation", payloads };
14572
+ const audited = terminal.slice().reverse().find((row) => row.kind === "audit-escalation" && Object.hasOwn(row, "auditReceipt"));
14573
+ return {
14574
+ kind: "audit_escalation",
14575
+ role,
14576
+ status: "audit_escalation",
14577
+ payloads,
14578
+ ...audited === void 0 ? {} : { decisiveFacts: {
14579
+ auditEscalationReceipt: audited.auditReceipt,
14580
+ ...Object.hasOwn(audited, "auditOfficer") ? { auditEscalationOfficer: audited.auditOfficer } : {}
14581
+ } }
14582
+ };
14583
14583
  }
14584
14584
  return { kind: "accepted", role, payloads };
14585
14585
  }
@@ -22715,15 +22715,7 @@ async function projectAuditorTerminal(summoned) {
22715
22715
  if (rows.length === 0) {
22716
22716
  return readComplianceCandidate({}, usage);
22717
22717
  }
22718
- const decision = readComplianceCandidate(rows[rows.length - 1], usage);
22719
- if (rows.length === 1) return decision;
22720
- if (decision.status === "pass" || decision.status === "bounce" || decision.status === "escalate") {
22721
- return { ...decision, receipt: rows };
22722
- }
22723
- if (decision.status === "received") {
22724
- return { ...decision, reply: rows };
22725
- }
22726
- return decision;
22718
+ return readComplianceCandidate(rows[rows.length - 1], usage);
22727
22719
  }
22728
22720
  return {
22729
22721
  status: "received",
@@ -22737,6 +22729,7 @@ async function runComplianceAudit(options) {
22737
22729
  throw new Error("Compliance audit requires a parent run directory pointer");
22738
22730
  }
22739
22731
  const subject = options.subject;
22732
+ const submission = options.submission === void 0 ? void 0 : readableGateItem(options.submission);
22740
22733
  const summon = options.summonAuditor ?? (async (auditSubject, sourceRunDirectory, auditSignal, reask2) => {
22741
22734
  const { summonPublicRole: summonPublicRole2 } = await Promise.resolve().then(() => (init_public_role_summons(), public_role_summons_exports));
22742
22735
  const { homeFromRunDirectory: homeFromRunDirectory2 } = await Promise.resolve().then(() => (init_activation_ledger_topology(), activation_ledger_topology_exports));
@@ -22753,12 +22746,13 @@ async function runComplianceAudit(options) {
22753
22746
  cwd: options.context.cwd ?? process.cwd(),
22754
22747
  home,
22755
22748
  ...auditSignal === void 0 ? {} : { signal: auditSignal },
22756
- ...reask2 === void 0 ? {} : { reviewReask: reask2 }
22749
+ ...reask2 === void 0 ? {} : { reviewReask: reask2 },
22750
+ ...submission === void 0 ? {} : { gateReviewInstruction: submission }
22757
22751
  });
22758
22752
  });
22759
22753
  let reask;
22760
22754
  for (; ; ) {
22761
- const summoned = await summon(subject, runDirectory, options.signal, reask);
22755
+ const summoned = await summon(subject, runDirectory, options.signal, reask, submission);
22762
22756
  const decision = await projectAuditorTerminal(summoned);
22763
22757
  if (decision.status === "received") {
22764
22758
  reask = OFFICER_CONCLUSION_REASK;
@@ -22774,6 +22768,7 @@ var init_compliance_transport = __esm({
22774
22768
  init_auditor_dossier_tool();
22775
22769
  init_gatekeeper_role();
22776
22770
  init_terminal();
22771
+ init_readable_gate_item();
22777
22772
  AUDITOR_DOSSIER_PROMPT = "\u5377\u5B97\u6307\u9488\uFF1A";
22778
22773
  AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE = "ak_auditor_parent_attempt_binding";
22779
22774
  AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE = "ak_auditor_compliance_failure";
@@ -23209,6 +23204,7 @@ function createPiDoctorAuditor() {
23209
23204
  return runComplianceAudit({
23210
23205
  subject: "doctor",
23211
23206
  context: options.context,
23207
+ submission: options.submission,
23212
23208
  ...auditorRunDirectory(options.context) === void 0 ? {} : { runDirectory: auditorRunDirectory(options.context) },
23213
23209
  ...options.signal === void 0 ? {} : { signal: options.signal },
23214
23210
  ...options.summonAuditor === void 0 ? {} : { summonAuditor: options.summonAuditor }
@@ -24326,6 +24322,7 @@ async function loadPackagedCanonicalSkillBinding(packageRoot, name) {
24326
24322
  }
24327
24323
 
24328
24324
  // src/role-runtime.ts
24325
+ init_readable_gate_item();
24329
24326
  init_host_contracts();
24330
24327
  init_sitian_facade();
24331
24328
  init_submission_ledger();
@@ -24754,8 +24751,6 @@ function registerEngineDetourTool(roleHost, hostActions) {
24754
24751
  }
24755
24752
 
24756
24753
  // src/role-runtime.ts
24757
- init_readable_gate_item();
24758
- init_run_terminal_artifacts();
24759
24754
  init_receipt_delivery_policy();
24760
24755
 
24761
24756
  // src/collector-role.ts
@@ -24978,7 +24973,6 @@ function isNotFound(error) {
24978
24973
 
24979
24974
  // src/collector-role.ts
24980
24975
  init_collector_ledger();
24981
- init_packaged_role_registry();
24982
24976
  init_submission_correctable_error();
24983
24977
  init_collector_identity();
24984
24978
  init_collector_identity();
@@ -25458,10 +25452,7 @@ function createCollectorRoleRuntime(pi, dependencies, hostActions) {
25458
25452
  activation.ledger.beginOperational(COLLECTOR_OUTPUT_TOOL, toolCallId);
25459
25453
  activation.ledger.recordOutputCandidate();
25460
25454
  return {
25461
- content: [{
25462
- type: "text",
25463
- text: packagedRoleAcceptedText("collector")
25464
- }],
25455
+ content: [],
25465
25456
  details: params,
25466
25457
  terminate: true
25467
25458
  };
@@ -25484,7 +25475,7 @@ init_audit_escalation();
25484
25475
  init_compliance_transport();
25485
25476
  init_submission_errors();
25486
25477
  init_dossier_resolution();
25487
- init_packaged_role_registry();
25478
+ init_readable_gate_item();
25488
25479
  init_doctor_contracts();
25489
25480
  init_sitian_facade();
25490
25481
  var DOCTOR_CASE_FLAG = { name: "ak-doctor-case", definition: { description: "Retained .ak-roles/books/<book>/<n>/runs directory", type: "string" } };
@@ -25539,22 +25530,22 @@ function createDoctorRoleRuntime(pi, dependencies, host) {
25539
25530
  }
25540
25531
  let audit;
25541
25532
  try {
25542
- audit = await dependencies.auditCompliance(signal === void 0 ? { context: ctx } : { context: ctx, signal });
25533
+ audit = await dependencies.auditCompliance(signal === void 0 ? { context: ctx, submission: testimony } : { context: ctx, signal, submission: testimony });
25543
25534
  } catch (error) {
25544
25535
  host.failInfrastructure(error, ctx, id);
25545
25536
  }
25546
25537
  const acceptedDetails = testimony;
25547
- return disposeComplianceDecision(audit, { pass: (usage) => ({ content: [{ type: "text", text: packagedRoleAcceptedText("doctor") }], details: acceptedDetails, terminate: true, ...usage === void 0 ? {} : { usage } }), noReceipt: (auditNoReceipt, usageProjection) => {
25538
+ return disposeComplianceDecision(audit, { pass: (usage) => ({ content: audit.status === "pass" && audit.receipt !== void 0 ? [{ type: "text", text: readableGateItem(audit.receipt) }] : [], details: acceptedDetails, terminate: true, ...usage === void 0 ? {} : { usage } }), noReceipt: (auditNoReceipt, usageProjection) => {
25548
25539
  try {
25549
25540
  appendCandidate(ctx, { version: 1, testimony, cost: active2.patient.cost, auditNoReceipt, readRecord: active2.store.readRecord(), patientIdentity: active2.patient.identity });
25550
25541
  } catch (error) {
25551
25542
  host.failInfrastructure(error, ctx, id);
25552
25543
  }
25553
- return { content: [{ type: "text", text: DOCTOR_ACCEPTED_AUDIT_NO_RECEIPT_TEXT }], details: acceptedDetails, terminate: true, ...usageProjection };
25544
+ return { content: [], details: acceptedDetails, terminate: true, ...usageProjection };
25554
25545
  }, received: () => {
25555
25546
  throw new Error("\u5BA1\u5211\u9662\u975E\u4E09\u6001\u5E94\u4EA4 runComplianceAudit \u91CD\u95EE\u8BF4\u8BDD\u8005");
25556
25547
  }, bounce: (violations) => {
25557
- throw new GatekeeperDecisionError({ status: "bounce", officer: "auditor", receipt: violations });
25548
+ throw new GatekeeperDecisionError({ status: "bounce", officer: "auditor", receipt: audit.status === "bounce" ? audit.receipt ?? violations : violations });
25558
25549
  }, escalate: (result) => result, transportFailure: (facts) => {
25559
25550
  host.failInfrastructure(Object.assign(new Error(facts.diagnostic), { name: "ComplianceTransportFailure", ...facts.submissions === void 0 && facts.terminal === void 0 ? {} : { submission: facts.submissions ?? facts.terminal } }), ctx, id);
25560
25551
  } }, acceptedDetails);
@@ -25583,7 +25574,6 @@ ${JSON.stringify(catalog)}
25583
25574
  }
25584
25575
 
25585
25576
  // src/notary-role.ts
25586
- init_packaged_role_registry();
25587
25577
  init_notary_contracts();
25588
25578
  function readNotaryTicketFlag(flag) {
25589
25579
  if (flag === void 0) return void 0;
@@ -25662,7 +25652,7 @@ function createNotaryRoleRuntime(pi, dependencies, host) {
25662
25652
  throw new Error("\u7B26\u5B9D\u90CE\u672A\u6FC0\u6D3B");
25663
25653
  }
25664
25654
  return {
25665
- content: [{ type: "text", text: packagedRoleAcceptedText("notary") }],
25655
+ content: [],
25666
25656
  details: parameters,
25667
25657
  terminate: true
25668
25658
  };
@@ -25893,7 +25883,6 @@ var DIARIST_TOOL_SPEC = {
25893
25883
  // src/secretariat-role.ts
25894
25884
  init_terminating_infrastructure();
25895
25885
  init_secretariat_contracts();
25896
- init_run_terminal_artifacts();
25897
25886
  init_secretariat_contracts();
25898
25887
  import { Type as Type23 } from "typebox";
25899
25888
  var secretariatVerdictSchema = withTerminatingOutputDeclarations(
@@ -25921,17 +25910,6 @@ var secretariatVerdictSchema = withTerminatingOutputDeclarations(
25921
25910
  )
25922
25911
  );
25923
25912
  secretariatVerdictSchema.required = [];
25924
- var secretariatSummonCountersignSchema = Type23.Object(
25925
- {
25926
- instruction: Type23.Optional(
25927
- Type23.String({
25928
- description: "\u4F20\u53EC\u6563\u6587\uFF1B\u7968\u53F7\u5199\u5728\u5176\u4E2D\u3002\u7A7A\u5219\u6CBF\u7528\u672C\u5C40\u6307\u4EE4\u3002"
25929
- })
25930
- )
25931
- },
25932
- { additionalProperties: true }
25933
- );
25934
- secretariatSummonCountersignSchema.required = [];
25935
25913
  var SECRETARIAT_OUTPUT_TOOL_SPEC = {
25936
25914
  name: SECRETARIAT_OUTPUT_TOOL_NAME,
25937
25915
  label: "\u4E2D\u4E66\u7701\u8F93\u51FA",
@@ -25939,68 +25917,6 @@ var SECRETARIAT_OUTPUT_TOOL_SPEC = {
25939
25917
  promptSnippet: "\u4E2D\u4E66\u7701\u7EC8\u5C40\u56DE\u6267",
25940
25918
  parameters: secretariatVerdictSchema
25941
25919
  };
25942
- var SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_SPEC = {
25943
- name: SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME,
25944
- label: "\u4F20\u53EC\u7ED9\u4E8B\u4E2D",
25945
- description: "\u7ECF\u5171\u4EAB\u6267\u884C\u63A5\u7F1D\u4F20\u53EC\u7ED9\u4E8B\u4E2D\u5BA1\u7968\uFF1B\u5C01\u9A73\u540E\u7EED\u540C\u4E00 run \u518D\u9001\u3002",
25946
- promptSnippet: "\u4F20\u53EC\u7ED9\u4E8B\u4E2D",
25947
- parameters: secretariatSummonCountersignSchema
25948
- };
25949
- function latestObjectPayload(payloads) {
25950
- if (payloads === void 0 || payloads.length === 0) return void 0;
25951
- const latest = payloads[payloads.length - 1];
25952
- if (latest === null || typeof latest !== "object" || Array.isArray(latest)) {
25953
- return void 0;
25954
- }
25955
- return latest;
25956
- }
25957
- function projectSecretariatSummonResult(summoned) {
25958
- const terminal = summoned.terminal;
25959
- const roleOutcome = terminal?.roleOutcome;
25960
- const runDirectory = summoned.runDirectory;
25961
- const runId = typeof runDirectory === "string" && runDirectory.trim() !== "" ? runIdFromRunDirectory(runDirectory) : void 0;
25962
- const base = {
25963
- exitCode: summoned.exitCode,
25964
- ...runId === void 0 ? {} : { runId },
25965
- ...runDirectory === void 0 ? {} : { runDirectory },
25966
- ...summoned.stderr === void 0 || summoned.stderr === "" ? {} : { stderr: summoned.stderr }
25967
- };
25968
- if (roleOutcome === void 0) {
25969
- return { ...base, outcomeKind: "no_terminal" };
25970
- }
25971
- if (roleOutcome.kind === "accepted" || roleOutcome.kind === "audit_escalation") {
25972
- const payloads = Array.isArray(roleOutcome.payloads) ? roleOutcome.payloads : void 0;
25973
- const latest = latestObjectPayload(payloads);
25974
- const countersignStatus = latest !== void 0 && typeof latest.countersignStatus === "string" ? latest.countersignStatus : void 0;
25975
- return {
25976
- ...base,
25977
- outcomeKind: roleOutcome.kind,
25978
- // audit_escalation carries typed status; accepted may carry fixture/compat status.
25979
- ..."status" in roleOutcome && typeof roleOutcome.status === "string" && roleOutcome.status.length > 0 ? { status: roleOutcome.status } : {},
25980
- ...countersignStatus === void 0 ? {} : { countersignStatus },
25981
- ...latest === void 0 ? {} : { receipt: latest },
25982
- ...payloads === void 0 ? {} : { payloads },
25983
- ...roleOutcome.decisiveFacts === void 0 ? {} : { decisiveFacts: roleOutcome.decisiveFacts }
25984
- };
25985
- }
25986
- if (roleOutcome.kind === "failure") {
25987
- const submissions = Array.isArray(terminal?.submissions) ? terminal.submissions : void 0;
25988
- return {
25989
- ...base,
25990
- outcomeKind: "failure",
25991
- diagnostic: roleOutcome.diagnostic,
25992
- ...roleOutcome.cause === void 0 ? {} : { cause: roleOutcome.cause },
25993
- ...roleOutcome.decisiveFacts === void 0 ? {} : { decisiveFacts: roleOutcome.decisiveFacts },
25994
- ...submissions === void 0 || submissions.length === 0 ? {} : { submissions }
25995
- };
25996
- }
25997
- return {
25998
- ...base,
25999
- outcomeKind: roleOutcome.kind,
26000
- ..."status" in roleOutcome && typeof roleOutcome.status === "string" && roleOutcome.status.length > 0 ? { status: roleOutcome.status } : {},
26001
- ..."decisiveFacts" in roleOutcome && roleOutcome.decisiveFacts !== void 0 ? { decisiveFacts: roleOutcome.decisiveFacts } : {}
26002
- };
26003
- }
26004
25920
 
26005
25921
  // src/role-runtime.ts
26006
25922
  init_secretariat_contracts();
@@ -26058,7 +25974,8 @@ init_audit_escalation();
26058
25974
  // src/judge-role.ts
26059
25975
  init_terminating_infrastructure();
26060
25976
  init_submission_errors();
26061
- init_packaged_role_registry();
25977
+ init_audit_escalation();
25978
+ init_readable_gate_item();
26062
25979
  init_judge_output();
26063
25980
  import { Type as Type24 } from "typebox";
26064
25981
  var JUDGE_QUEUE_STATUSES = /* @__PURE__ */ new Set(["converged", "continue", "escalate"]);
@@ -26122,35 +26039,45 @@ function createJudgeRoleRuntime(pi, dependencies, hostActions) {
26122
26039
  if (rawStatus === "escalate") {
26123
26040
  const verdict2 = validateVerdict(parameters);
26124
26041
  return {
26125
- content: [{ type: "text", text: packagedRoleAcceptedText("judge") }],
26042
+ content: [],
26126
26043
  details: verdict2,
26127
26044
  terminate: true
26128
26045
  };
26129
26046
  }
26130
26047
  const verdict = validateVerdict(parameters);
26131
- await pi.requireGatekeeperPass({
26132
- context: ctx,
26133
- subject: { kind: "judge_draft" },
26134
- ...signal === void 0 ? {} : { signal },
26135
- hostActions,
26136
- toolCallId,
26137
- // #879: this-turn typed payload — identity-bound at submit site.
26138
- submission: parameters
26139
- });
26140
- await pi.requireGatekeeperPass({
26141
- context: ctx,
26142
- subject: { kind: "judge_compliance" },
26143
- ...signal === void 0 ? {} : { signal },
26144
- hostActions,
26145
- toolCallId,
26146
- // #879: same parent payload for 审刑院; not recovered from session latest.
26147
- submission: parameters
26148
- });
26149
- return {
26150
- content: [{ type: "text", text: packagedRoleAcceptedText("judge") }],
26151
- details: verdict,
26152
- terminate: true
26153
- };
26048
+ let draftPass;
26049
+ try {
26050
+ const obtainedDraftPass = await pi.requireGatekeeperPass({
26051
+ context: ctx,
26052
+ subject: { kind: "judge_draft" },
26053
+ ...signal === void 0 ? {} : { signal },
26054
+ hostActions,
26055
+ toolCallId,
26056
+ // #879: this-turn typed payload — identity-bound at submit site.
26057
+ submission: parameters
26058
+ });
26059
+ draftPass = obtainedDraftPass || void 0;
26060
+ if (draftPass !== void 0) hostActions.bindPriorGatePass(toolCallId, draftPass.receipt);
26061
+ const compliancePass = await pi.requireGatekeeperPass({
26062
+ context: ctx,
26063
+ subject: { kind: "judge_compliance" },
26064
+ ...signal === void 0 ? {} : { signal },
26065
+ hostActions,
26066
+ toolCallId,
26067
+ // #879: same parent payload for 审刑院; not recovered from session latest.
26068
+ submission: parameters
26069
+ });
26070
+ return {
26071
+ content: [draftPass, compliancePass].filter((pass) => pass !== void 0).map((pass) => ({ type: "text", text: readableGateItem(pass.receipt) })),
26072
+ details: verdict,
26073
+ terminate: true
26074
+ };
26075
+ } catch (error) {
26076
+ if (error instanceof GatekeeperDecisionError && error.result.status === "escalate") {
26077
+ return projectGatekeeperEscalation(error.result, verdict);
26078
+ }
26079
+ throw error;
26080
+ }
26154
26081
  }
26155
26082
  });
26156
26083
  pi.on("before_agent_start", (event) => {
@@ -26171,7 +26098,6 @@ ${soul}
26171
26098
  // src/reviewer-role.ts
26172
26099
  init_open_tool_schema();
26173
26100
  init_terminating_infrastructure();
26174
- init_packaged_role_registry();
26175
26101
  init_reviewer_output();
26176
26102
  import { Type as Type25 } from "typebox";
26177
26103
  var reviewerAmendmentsSchema = Type25.Object({
@@ -26224,7 +26150,7 @@ function createReviewerRoleRuntime(pi, dependencies, _hostActions) {
26224
26150
  async execute(_id, parameters) {
26225
26151
  if (!soul || !binding) throw new Error("\u5FA1\u53F2\u53F0\u8F93\u5165\u672A\u88C5\u8F7D");
26226
26152
  return {
26227
- content: [{ type: "text", text: packagedRoleAcceptedText("reviewer") }],
26153
+ content: [],
26228
26154
  details: parameters,
26229
26155
  terminate: true
26230
26156
  };
@@ -26247,7 +26173,9 @@ function createReviewerRoleRuntime(pi, dependencies, _hostActions) {
26247
26173
  init_open_tool_schema();
26248
26174
  init_terminating_infrastructure();
26249
26175
  init_submission_correctable_error();
26250
- init_packaged_role_registry();
26176
+ init_readable_gate_item();
26177
+ init_audit_escalation();
26178
+ init_submission_errors();
26251
26179
  init_worker_output();
26252
26180
  init_fixer_output();
26253
26181
  init_fixer_packet();
@@ -26657,8 +26585,9 @@ function createFixerRoleRuntime(pi, dependencies, hostActions) {
26657
26585
  ctx,
26658
26586
  toolCallId
26659
26587
  );
26660
- if (WORKER_DONE_STATUSES.has(workerStatusOf(output))) {
26661
- await pi.requireGatekeeperPass({
26588
+ let pass;
26589
+ try {
26590
+ pass = WORKER_DONE_STATUSES.has(workerStatusOf(output)) ? await pi.requireGatekeeperPass({
26662
26591
  context: ctx,
26663
26592
  subject: { kind: "worker_completion" },
26664
26593
  ..._signal === void 0 ? {} : { signal: _signal },
@@ -26666,11 +26595,16 @@ function createFixerRoleRuntime(pi, dependencies, hostActions) {
26666
26595
  toolCallId,
26667
26596
  // #879: this-turn typed payload — identity-bound at submit site.
26668
26597
  submission: output
26669
- });
26598
+ }) : void 0;
26599
+ } catch (error) {
26600
+ if (error instanceof GatekeeperDecisionError && error.result.status === "escalate") {
26601
+ return projectGatekeeperEscalation(error.result, output);
26602
+ }
26603
+ throw error;
26670
26604
  }
26671
26605
  const acceptedDetails = output;
26672
26606
  return {
26673
- content: [{ type: "text", text: packagedRoleAcceptedText("fixer") }],
26607
+ content: pass === void 0 ? [] : [{ type: "text", text: readableGateItem(pass.receipt) }],
26674
26608
  details: acceptedDetails,
26675
26609
  terminate: true
26676
26610
  };
@@ -26795,8 +26729,9 @@ function createCoderRoleRuntime(pi, dependencies, hostActions) {
26795
26729
  ctx2,
26796
26730
  toolCallId
26797
26731
  );
26798
- if (WORKER_DONE_STATUSES.has(workerStatusOf(output))) {
26799
- await pi.requireGatekeeperPass({
26732
+ let pass;
26733
+ try {
26734
+ pass = WORKER_DONE_STATUSES.has(workerStatusOf(output)) ? await pi.requireGatekeeperPass({
26800
26735
  context: ctx2,
26801
26736
  subject: { kind: "worker_completion" },
26802
26737
  ..._signal === void 0 ? {} : { signal: _signal },
@@ -26804,11 +26739,16 @@ function createCoderRoleRuntime(pi, dependencies, hostActions) {
26804
26739
  toolCallId,
26805
26740
  // #879: this-turn typed payload — identity-bound at submit site.
26806
26741
  submission: output
26807
- });
26742
+ }) : void 0;
26743
+ } catch (error) {
26744
+ if (error instanceof GatekeeperDecisionError && error.result.status === "escalate") {
26745
+ return projectGatekeeperEscalation(error.result, output);
26746
+ }
26747
+ throw error;
26808
26748
  }
26809
26749
  const acceptedDetails = output;
26810
26750
  return {
26811
- content: [{ type: "text", text: packagedRoleAcceptedText("coder") }],
26751
+ content: pass === void 0 ? [] : [{ type: "text", text: readableGateItem(pass.receipt) }],
26812
26752
  details: acceptedDetails,
26813
26753
  terminate: true
26814
26754
  };
@@ -26867,7 +26807,6 @@ init_doctor_contracts();
26867
26807
  init_merger_contracts();
26868
26808
 
26869
26809
  // src/merger-role.ts
26870
- init_packaged_role_registry();
26871
26810
  init_merger_contracts();
26872
26811
  init_exact_utf8();
26873
26812
  var MERGER_INPUT_FLAG = { name: "ak-merger-input", definition: { description: "Path to Merger assignment materials JSON", type: "string" } };
@@ -26896,7 +26835,7 @@ function createMergerRoleRuntime(pi, dependencies) {
26896
26835
  parameters: mergerOutputSchema,
26897
26836
  async execute(_id, params, _signal, _update, _ctx) {
26898
26837
  if (!activation) throw new Error("\u6821\u4E66\u90CE\u672A\u6FC0\u6D3B");
26899
- return { content: [{ type: "text", text: packagedRoleAcceptedText("merger") }], details: params, terminate: true };
26838
+ return { content: [], details: params, terminate: true };
26900
26839
  }
26901
26840
  });
26902
26841
  pi.on("before_agent_start", (event) => {
@@ -27187,9 +27126,13 @@ function createFiledOfficerRuntime(roleHost, spec, dependencies) {
27187
27126
  async execute(toolCallId, parameters, signal, _onUpdate, ctx) {
27188
27127
  if (soul === void 0) throw new Error(`${spec.role} \u804C\u5206\u672A\u88C5\u8F7D`);
27189
27128
  const projected = spec.beforeAccept === void 0 ? void 0 : await spec.beforeAccept({ toolCallId, parameters, signal, ctx });
27129
+ if (isAuditEscalationProjection(projected)) {
27130
+ return { content: [], details: projected, terminate: true };
27131
+ }
27132
+ const pass = spec.relayGatePass === true && projected !== null && typeof projected === "object" && "officer" in projected && "receipt" in projected ? projected : void 0;
27190
27133
  return {
27191
- content: [{ type: "text", text: packagedRoleAcceptedText(spec.role) }],
27192
- details: projected === void 0 ? parameters : projected,
27134
+ content: pass === void 0 || pass.receipt === void 0 ? [] : [{ type: "text", text: readableGateItem(pass.receipt) }],
27135
+ details: pass === void 0 ? projected === void 0 ? parameters : projected : parameters,
27193
27136
  terminate: true
27194
27137
  };
27195
27138
  }
@@ -27379,18 +27322,12 @@ ${error.message}`
27379
27322
  }
27380
27323
  var COUNTERSIGN_QUEUE_STATUSES = /* @__PURE__ */ new Set(["converged", "continue", "escalate"]);
27381
27324
  var COUNTERSIGN_STATUS_REASK = "countersignStatus \u4E0D\u662F converged\u3001continue\u3001escalate \u4E09\u6001\u4E4B\u4E00\u3002\u8BF7\u91CD\u65B0\u4EA4\u5377\uFF0Cstatus \u5199\u660E\u5176\u4E00\u3002";
27382
- var SECRETARIAT_SUBMISSION_GATE_HOSTS = /* @__PURE__ */ new Set(["codex", "claude", "grok-build"]);
27383
27325
  var SECRETARIAT_QUEUE_STATUSES = /* @__PURE__ */ new Set(["converged", "escalate"]);
27384
27326
  var SECRETARIAT_STATUS_REASK = "secretariatStatus \u4E0D\u662F converged\u3001escalate \u4E4B\u4E00\u3002\u8BF7\u91CD\u65B0\u4EA4\u5377\uFF0Cstatus \u5199\u660E\u5176\u4E00\u3002";
27385
27327
  function createSecretariatRoleRuntime(roleHost, dependencies, hostActions) {
27386
- let parentInstruction = "";
27387
27328
  const beforeAccept = hostActions !== void 0 ? async ({ toolCallId, parameters, signal, ctx }) => {
27388
- const host = typeof ctx.host === "string" && ctx.host.trim() !== "" ? ctx.host.trim() : void 0;
27389
- if (host === void 0 || !SECRETARIAT_SUBMISSION_GATE_HOSTS.has(host)) {
27390
- return void 0;
27391
- }
27392
27329
  if (roleHost.requireGatekeeperPass === void 0) {
27393
- const error = new Error(`host ${host} cannot mount the secretariat submission gate`);
27330
+ const error = new Error("host cannot mount the secretariat submission gate");
27394
27331
  error.name = "InfrastructureFailure";
27395
27332
  return hostActions.failInfrastructure(error, ctx, toolCallId);
27396
27333
  }
@@ -27423,7 +27360,7 @@ function createSecretariatRoleRuntime(roleHost, dependencies, hostActions) {
27423
27360
  ...runId === void 0 ? {} : { runId }
27424
27361
  });
27425
27362
  }
27426
- return void 0;
27363
+ return pass;
27427
27364
  } catch (error) {
27428
27365
  if (error instanceof GatekeeperDecisionError && error.result.status === "escalate") {
27429
27366
  const receipt = error.result.receipt;
@@ -27454,80 +27391,17 @@ function createSecretariatRoleRuntime(roleHost, dependencies, hostActions) {
27454
27391
  roleHost,
27455
27392
  {
27456
27393
  role: "secretariat",
27394
+ relayGatePass: true,
27457
27395
  tool: SECRETARIAT_OUTPUT_TOOL_SPEC,
27458
27396
  soulTag: "secretariat",
27459
27397
  ...beforeAccept === void 0 ? {} : { beforeAccept }
27460
27398
  },
27461
27399
  dependencies
27462
27400
  );
27463
- let summonRegistered = false;
27464
27401
  return {
27465
27402
  async activate() {
27466
27403
  await base.activate();
27467
- if (!summonRegistered) {
27468
- summonRegistered = true;
27469
- roleHost.on("before_agent_start", (event) => {
27470
- if (typeof event.prompt === "string" && event.prompt.trim() !== "") {
27471
- parentInstruction = event.prompt;
27472
- }
27473
- });
27474
- roleHost.registerTool({
27475
- name: SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME,
27476
- label: SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_SPEC.label,
27477
- description: SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_SPEC.description,
27478
- promptSnippet: SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_SPEC.promptSnippet,
27479
- parameters: SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_SPEC.parameters,
27480
- async execute(_toolCallId, parameters, signal, _onUpdate, ctx) {
27481
- const fromArgs = typeof parameters?.instruction === "string" ? parameters.instruction.trim() : "";
27482
- const instruction = fromArgs !== "" ? fromArgs : parentInstruction.trim();
27483
- const correlationId = (() => {
27484
- const runDirectory = runDirectoryFromHostContext(ctx);
27485
- if (runDirectory === void 0) return void 0;
27486
- return runIdFromRunDirectory(runDirectory);
27487
- })();
27488
- const summon = dependencies.summonCountersign;
27489
- const summoned = summon === void 0 ? await (async () => {
27490
- const coordinates = readRoleRunCoordinates(ctx, "secretariat summons");
27491
- const { summonPublicRole: summonPublicRole2 } = await Promise.resolve().then(() => (init_public_role_summons(), public_role_summons_exports));
27492
- const { readBoardTicketNumber: readBoardTicketNumber2 } = await Promise.resolve().then(() => (init_run_ticket_number(), run_ticket_number_exports));
27493
- const parentTicket = await readBoardTicketNumber2(coordinates.runDirectory);
27494
- return summonPublicRole2({
27495
- role: "countersign",
27496
- argv: ["--project", coordinates.projectRoot, "--", instruction],
27497
- cwd: coordinates.projectRoot,
27498
- home: coordinates.home,
27499
- parentRunPath: coordinates.runDirectory,
27500
- ...parentTicket === void 0 ? {} : { boundTicketNumber: parentTicket },
27501
- ...signal === void 0 ? {} : { signal },
27502
- ...correlationId === void 0 ? {} : { correlationId },
27503
- ...dependencies.packageRoot === void 0 ? {} : { packageRoot: dependencies.packageRoot },
27504
- ...dependencies.hostAdapters === void 0 ? {} : { hostAdapters: dependencies.hostAdapters }
27505
- });
27506
- })() : await summon({
27507
- instruction,
27508
- cwd: ctx.cwd,
27509
- ...signal === void 0 ? {} : { signal },
27510
- ...correlationId === void 0 ? {} : { correlationId },
27511
- ...dependencies.home === void 0 ? {} : { home: dependencies.home },
27512
- ...dependencies.packageRoot === void 0 ? {} : { packageRoot: dependencies.packageRoot }
27513
- });
27514
- const details = projectSecretariatSummonResult(summoned);
27515
- return {
27516
- content: [
27517
- {
27518
- type: "text",
27519
- text: readableGateItem(details)
27520
- }
27521
- ],
27522
- details
27523
- };
27524
- }
27525
- });
27526
- }
27527
- const packageRequired = [
27528
- SECRETARIAT_OUTPUT_TOOL_NAME,
27529
- SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME
27530
- ];
27404
+ const packageRequired = [SECRETARIAT_OUTPUT_TOOL_NAME];
27531
27405
  const all = roleHost.getAllTools().map((tool) => tool.name);
27532
27406
  for (const name of packageRequired) {
27533
27407
  if (all.filter((item) => item === name).length !== 1) {
@@ -27565,20 +27439,29 @@ function createCountersignRoleRuntime(roleHost, dependencies, hostActions) {
27565
27439
  error.name = "InfrastructureFailure";
27566
27440
  return hostActions.failInfrastructure(error, ctx, toolCallId);
27567
27441
  }
27568
- await roleHost.requireGatekeeperPass({
27569
- context: ctx,
27570
- subject: { kind: "countersign_verdict" },
27571
- ...signal === void 0 ? {} : { signal },
27572
- hostActions,
27573
- toolCallId,
27574
- // #879: this-turn typed payload — identity-bound at submit site.
27575
- submission: parameters
27576
- });
27442
+ try {
27443
+ return await roleHost.requireGatekeeperPass({
27444
+ context: ctx,
27445
+ subject: { kind: "countersign_verdict" },
27446
+ ...signal === void 0 ? {} : { signal },
27447
+ hostActions,
27448
+ toolCallId,
27449
+ // #879: this-turn typed payload — identity-bound at submit site.
27450
+ submission: parameters
27451
+ });
27452
+ } catch (error) {
27453
+ if (error instanceof GatekeeperDecisionError && error.result.status === "escalate") {
27454
+ const { buildAuditEscalationResult: buildAuditEscalationResult2 } = await Promise.resolve().then(() => (init_audit_escalation(), audit_escalation_exports));
27455
+ return buildAuditEscalationResult2({ status: "escalate", officer: "notary", conflicts: error.result.receipt }, parameters);
27456
+ }
27457
+ throw error;
27458
+ }
27577
27459
  } : void 0;
27578
27460
  return createFiledOfficerRuntime(
27579
27461
  roleHost,
27580
27462
  {
27581
27463
  role: "countersign",
27464
+ relayGatePass: true,
27582
27465
  tool: COUNTERSIGN_TOOL_SPEC,
27583
27466
  soulTag: "countersign",
27584
27467
  ...beforeAccept === void 0 ? {} : { beforeAccept }
@@ -27649,6 +27532,7 @@ function createRoleRuntimeExtension(dependencies) {
27649
27532
  let navigatorCwd;
27650
27533
  const pendingInfrastructureFailures = /* @__PURE__ */ new Map();
27651
27534
  const pendingSubmissionNonPassByToolCallId = /* @__PURE__ */ new Map();
27535
+ const pendingPriorGatePassByToolCallId = /* @__PURE__ */ new Map();
27652
27536
  let engineDetourRegistered = false;
27653
27537
  let receiptDelivery = createReceiptDeliveryPolicy();
27654
27538
  let noReceiptRecorded = false;
@@ -27843,6 +27727,9 @@ function createRoleRuntimeExtension(dependencies) {
27843
27727
  return { readingMaterial: caseDossier };
27844
27728
  });
27845
27729
  roleHost.on("tool_result", async (event) => {
27730
+ const priorGatePass = pendingPriorGatePassByToolCallId.get(event.toolCallId);
27731
+ pendingPriorGatePassByToolCallId.delete(event.toolCallId);
27732
+ const priorPassContent = priorGatePass !== void 0 && event.isError ? [{ type: "text", text: readableGateItem(priorGatePass) }, ...event.content ?? []] : void 0;
27846
27733
  const role = selectedRole;
27847
27734
  if (role === void 0) return;
27848
27735
  if (activeCollector !== void 0 && selectedRole === roleHost.getFlag(ROLE_FLAG.name)) {
@@ -27864,13 +27751,14 @@ function createRoleRuntimeExtension(dependencies) {
27864
27751
  const settlement = isRoleInfrastructureFailure || outputClassification?.kind === "infrastructure" ? publicNavigatorSettlement(role, navigatorPhase(roleHost, role), classified) : void 0;
27865
27752
  await settleNavigatorProjection(settlement);
27866
27753
  if (infrastructureDetails !== void 0) {
27867
- return { isError: true };
27754
+ return { isError: true, ...priorPassContent === void 0 ? {} : { content: priorPassContent } };
27868
27755
  }
27869
27756
  const submissionNonPass = pendingSubmissionNonPassByToolCallId.get(event.toolCallId);
27870
27757
  if (submissionNonPass !== void 0) {
27871
27758
  pendingSubmissionNonPassByToolCallId.delete(event.toolCallId);
27872
- return { details: submissionNonPass, isError: true };
27759
+ return { details: submissionNonPass, isError: true, ...priorPassContent === void 0 ? {} : { content: priorPassContent } };
27873
27760
  }
27761
+ if (priorPassContent !== void 0) return { content: priorPassContent, isError: true };
27874
27762
  });
27875
27763
  roleHost.on("agent_end", async (event, ctx) => {
27876
27764
  const lastMessage = event.messages.at(-1);
@@ -28006,6 +27894,7 @@ function createRoleRuntimeExtension(dependencies) {
28006
27894
  disposeNavigatorAttendanceNonBlocking(attendanceToDispose);
28007
27895
  pendingInfrastructureFailures.clear();
28008
27896
  pendingSubmissionNonPassByToolCallId.clear();
27897
+ pendingPriorGatePassByToolCallId.clear();
28009
27898
  observationFace.reset();
28010
27899
  });
28011
27900
  const hostActions = {
@@ -28017,6 +27906,9 @@ function createRoleRuntimeExtension(dependencies) {
28017
27906
  },
28018
27907
  bindSubmissionNonPass(toolCallId, result) {
28019
27908
  pendingSubmissionNonPassByToolCallId.set(toolCallId, result);
27909
+ },
27910
+ bindPriorGatePass(toolCallId, receipt) {
27911
+ pendingPriorGatePassByToolCallId.set(toolCallId, receipt);
28020
27912
  }
28021
27913
  };
28022
27914
  const requireRoleSoul = (role) => dependencies.loadRoleSoul(role);
@@ -28118,9 +28010,7 @@ function createRoleRuntimeExtension(dependencies) {
28118
28010
  }
28119
28011
  );
28120
28012
  const secretariat = createSecretariatRoleRuntime(roleHost, {
28121
- loadSoul: () => requireRoleSoul("secretariat"),
28122
- ...dependencies.packageRoot === void 0 ? {} : { packageRoot: dependencies.packageRoot },
28123
- ...dependencies.hostAdapters === void 0 ? {} : { hostAdapters: dependencies.hostAdapters }
28013
+ loadSoul: () => requireRoleSoul("secretariat")
28124
28014
  }, hostActions);
28125
28015
  const merger = createMergerRoleRuntime(roleHost, {
28126
28016
  loadSoul: () => requireRoleSoul("merger"),
@@ -28311,6 +28201,7 @@ function createRoleRuntimeExtension(dependencies) {
28311
28201
  pendingNavigatorSettlement = void 0;
28312
28202
  pendingInfrastructureFailures.clear();
28313
28203
  pendingSubmissionNonPassByToolCallId.clear();
28204
+ pendingPriorGatePassByToolCallId.clear();
28314
28205
  navigatorWorkContext = void 0;
28315
28206
  envelopeHost.startKeepalive(ctx);
28316
28207
  const rawRole = roleHost.getFlag(ROLE_FLAG.name);
@@ -28602,7 +28493,7 @@ async function requireGatekeeperPass(options) {
28602
28493
  });
28603
28494
  options.hostActions.failInfrastructure(failure2, options.context, options.toolCallId);
28604
28495
  }
28605
- if (gatekeeper.status === "escalate" && options.subject.kind === "secretariat_verdict") {
28496
+ if (gatekeeper.status === "escalate") {
28606
28497
  throw new GatekeeperDecisionError(gatekeeper);
28607
28498
  }
28608
28499
  options.hostActions.bindSubmissionNonPass(options.toolCallId, gatekeeper);