@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.
@@ -3522,7 +3522,7 @@ function validateDoctorSubmissionShape(value) {
3522
3522
  function validateDoctorOutput(value, _patient, _store) {
3523
3523
  return validateDoctorSubmissionShape(value);
3524
3524
  }
3525
- 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;
3525
+ 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;
3526
3526
  var init_doctor_contracts = __esm({
3527
3527
  "src/doctor-contracts.ts"() {
3528
3528
  "use strict";
@@ -3532,7 +3532,6 @@ var init_doctor_contracts = __esm({
3532
3532
  DOCTOR_EVIDENCE_TOOL_NAME = "ak_doctor_evidence";
3533
3533
  DOCTOR_OUTPUT_TOOL_NAME = "ak_doctor_output";
3534
3534
  DOCTOR_AUDIT_TOOL_NAME = "ak_doctor_audit_decision";
3535
- DOCTOR_ACCEPTED_AUDIT_NO_RECEIPT_TEXT = "\u592A\u533B\u7F72\u56DE\u6267\u5DF2\u63A5\u53D7\uFF1B\u5BA1\u8BA1\u65E0\u56DE\u6267";
3536
3535
  DOCTOR_OUTPUT_TOOL_DESCRIPTION = "\u63D0\u4EA4\u552F\u4E00\u7EC8\u5C40\u5355\u6848\u8BC1\u8BCD\uFF1Bcompleted \u5141\u8BB8\u7A7A findings\u3002";
3537
3536
  DOCTOR_TARGET_KINDS = ["law", "gate", "template", "station", "seat"];
3538
3537
  nonblank = Type8.Optional(Type8.String());
@@ -4003,15 +4002,13 @@ var secretariat_contracts_exports = {};
4003
4002
  __export(secretariat_contracts_exports, {
4004
4003
  SECRETARIAT_COUNTERSIGN_TERMINAL_FACT_KEY: () => SECRETARIAT_COUNTERSIGN_TERMINAL_FACT_KEY,
4005
4004
  SECRETARIAT_GATE_OFFICER_ENTRY_TYPE: () => SECRETARIAT_GATE_OFFICER_ENTRY_TYPE,
4006
- SECRETARIAT_OUTPUT_TOOL_NAME: () => SECRETARIAT_OUTPUT_TOOL_NAME,
4007
- SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME: () => SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME
4005
+ SECRETARIAT_OUTPUT_TOOL_NAME: () => SECRETARIAT_OUTPUT_TOOL_NAME
4008
4006
  });
4009
- var SECRETARIAT_OUTPUT_TOOL_NAME, SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME, SECRETARIAT_GATE_OFFICER_ENTRY_TYPE, SECRETARIAT_COUNTERSIGN_TERMINAL_FACT_KEY;
4007
+ var SECRETARIAT_OUTPUT_TOOL_NAME, SECRETARIAT_GATE_OFFICER_ENTRY_TYPE, SECRETARIAT_COUNTERSIGN_TERMINAL_FACT_KEY;
4010
4008
  var init_secretariat_contracts = __esm({
4011
4009
  "src/secretariat-contracts.ts"() {
4012
4010
  "use strict";
4013
4011
  SECRETARIAT_OUTPUT_TOOL_NAME = "ak_secretariat_output";
4014
- SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME = "ak_secretariat_summon_countersign";
4015
4012
  SECRETARIAT_GATE_OFFICER_ENTRY_TYPE = "ak-secretariat-gate-officer";
4016
4013
  SECRETARIAT_COUNTERSIGN_TERMINAL_FACT_KEY = "countersignTerminal";
4017
4014
  }
@@ -4059,7 +4056,6 @@ __export(packaged_role_registry_exports, {
4059
4056
  packagedRebindSourceOnResume: () => packagedRebindSourceOnResume,
4060
4057
  packagedResumeSourcePath: () => packagedResumeSourcePath,
4061
4058
  packagedRoleAcceptedOutputTool: () => packagedRoleAcceptedOutputTool,
4062
- packagedRoleAcceptedText: () => packagedRoleAcceptedText,
4063
4059
  packagedRoleActivationFlags: () => packagedRoleActivationFlags,
4064
4060
  packagedRoleInputFlag: () => packagedRoleInputFlag,
4065
4061
  packagedRoleMetadata: () => packagedRoleMetadata,
@@ -4107,13 +4103,6 @@ function packagedRolePhaseFlag(role) {
4107
4103
  function packagedRoleOutputTool(role) {
4108
4104
  return packagedRoleMetadata(role)?.outputTool;
4109
4105
  }
4110
- function packagedRoleAcceptedText(role) {
4111
- const record4 = packagedRoleMetadata(role);
4112
- if (record4 === void 0) {
4113
- throw new Error(`Unsupported workflow role: ${String(role)}`);
4114
- }
4115
- return record4.acceptedText;
4116
- }
4117
4106
  function packagedMethodLoadFailureCause(role) {
4118
4107
  const record4 = packagedRoleMetadata(role);
4119
4108
  if (record4 === void 0 || !("methodLoadFailureCause" in record4)) return void 0;
@@ -4286,7 +4275,6 @@ var init_packaged_role_registry = __esm({
4286
4275
  auditTool: JUDGE_AUDIT_TOOL_NAME,
4287
4276
  settlement: "sealed",
4288
4277
  runnerFailure: "engine-detour-known-first",
4289
- acceptedText: "\u5927\u7406\u5BFA\u56DE\u6267\u5DF2\u63A5\u53D7",
4290
4278
  /** Factory board: court until another station has started, then marshal. */
4291
4279
  boardPlacement: "judge-history",
4292
4280
  /** Navigator subject is the public admitted instruction when the run is bound. */
@@ -4325,7 +4313,6 @@ var init_packaged_role_registry = __esm({
4325
4313
  ],
4326
4314
  method: "observed"
4327
4315
  },
4328
- acceptedText: "\u4FEE\u5185\u53F8\u56DE\u6267\u5DF2\u63A5\u53D7",
4329
4316
  boardPlacement: "marshal",
4330
4317
  activationFlags: [
4331
4318
  { field: "packetPath", flag: "ak-fix-packet", binds: "input" },
@@ -4364,7 +4351,6 @@ var init_packaged_role_registry = __esm({
4364
4351
  ],
4365
4352
  method: "optional"
4366
4353
  },
4367
- acceptedText: "\u5C06\u4F5C\u76D1\u56DE\u6267\u5DF2\u63A5\u53D7",
4368
4354
  activationFlags: [
4369
4355
  { field: "taskPath", flag: "ak-coder-task", binds: "input" },
4370
4356
  { field: "phase", flag: "ak-coder-phase", binds: "phase" }
@@ -4410,7 +4396,6 @@ var init_packaged_role_registry = __esm({
4410
4396
  /** Frozen base/lens/authority become the initial prompt; instruction follows. */
4411
4397
  transportPrompt: "skill-args",
4412
4398
  runnerFailure: "engine-detour-record-first",
4413
- acceptedText: "\u5FA1\u53F2\u53F0\u56DE\u6267\u5DF2\u63A5\u53D7",
4414
4399
  boardPlacement: "marshal",
4415
4400
  activationFlags: [
4416
4401
  { field: "baseRevision", flag: "ak-review-base" },
@@ -4452,7 +4437,6 @@ var init_packaged_role_registry = __esm({
4452
4437
  { key: "manifestDigest" }
4453
4438
  ]
4454
4439
  },
4455
- acceptedText: "\u901A\u8FDB\u53F8\u56DE\u6267\u5DF2\u63A5\u53D7",
4456
4440
  boardPlacement: "collector",
4457
4441
  /** Taishi acceptance is a typed groups array, not a status leaf. */
4458
4442
  analystTerminal: "groups",
@@ -4486,7 +4470,6 @@ var init_packaged_role_registry = __esm({
4486
4470
  ],
4487
4471
  doctorReportFacts: true
4488
4472
  },
4489
- acceptedText: "\u592A\u533B\u7F72\u56DE\u6267\u5DF2\u63A5\u53D7",
4490
4473
  /** Navigator subject is the doctor case, not the case-path file bytes. */
4491
4474
  navigatorSubject: "case",
4492
4475
  activationFlags: [
@@ -4522,7 +4505,6 @@ var init_packaged_role_registry = __esm({
4522
4505
  ],
4523
4506
  method: "observed"
4524
4507
  },
4525
- acceptedText: "\u5408\u5E76\u56DE\u6267\u5DF2\u63A5\u53D7",
4526
4508
  activationFlags: [
4527
4509
  { field: "inputPath", from: "mergerInputPath", flag: "ak-merger-input", binds: "input" }
4528
4510
  ],
@@ -4555,7 +4537,6 @@ var init_packaged_role_registry = __esm({
4555
4537
  /** Court reask replaces the initial prompt. Otherwise the fixed kickoff. */
4556
4538
  reaskPrompt: true,
4557
4539
  transportPrompt: "fixed-kickoff",
4558
- acceptedText: "\u7B26\u5B9D\u90CE\u56DE\u6267\u5DF2\u63A5\u53D7",
4559
4540
  gateStageLabel: "\u7B26\u5B9D\u90CE",
4560
4541
  /** Gate summon binds --source-run and keeps dialogue off the argv. */
4561
4542
  gateSummon: "source-run",
@@ -4580,7 +4561,6 @@ var init_packaged_role_registry = __esm({
4580
4561
  phases: [null],
4581
4562
  outputTool: COUNTERSIGN_OUTPUT_TOOL_NAME,
4582
4563
  settlement: "accepted",
4583
- acceptedText: "\u7ED9\u4E8B\u4E2D\u56DE\u6267\u5DF2\u63A5\u53D7",
4584
4564
  gateStageLabel: "\u7ED9\u4E8B\u4E2D",
4585
4565
  /** Gate queue reads countersignStatus, not the shared three-state status. */
4586
4566
  gateDecision: "countersign-status",
@@ -4606,7 +4586,6 @@ var init_packaged_role_registry = __esm({
4606
4586
  settlement: "accepted",
4607
4587
  /** Project the durable 给事中 officer entry onto the shared accepted-tool settlement. */
4608
4588
  projectCountersignTerminal: true,
4609
- acceptedText: "\u4E2D\u4E66\u7701\u56DE\u6267\u5DF2\u63A5\u53D7",
4610
4589
  activationFlags: [
4611
4590
  { field: "ticketNumber" }
4612
4591
  ],
@@ -4636,7 +4615,6 @@ var init_packaged_role_registry = __esm({
4636
4615
  settlement: "accepted",
4637
4616
  /** Bound comparison base is the initial prompt; instruction follows. */
4638
4617
  transportPrompt: "baseline",
4639
- acceptedText: "\u5DE6\u62FE\u9057\u56DE\u6267\u5DF2\u63A5\u53D7",
4640
4618
  activationFlags: [
4641
4619
  { field: "baseRevision", flag: "ak-gleaner-left-base" }
4642
4620
  ],
@@ -4667,7 +4645,6 @@ var init_packaged_role_registry = __esm({
4667
4645
  settlement: "accepted",
4668
4646
  /** Court reask replaces the initial prompt. */
4669
4647
  reaskPrompt: true,
4670
- acceptedText: "\u53F0\u9662\u56DE\u6267\u5DF2\u63A5\u53D7",
4671
4648
  gateStageLabel: "\u53F0\u9662",
4672
4649
  activationFlags: [
4673
4650
  {
@@ -4699,7 +4676,6 @@ var init_packaged_role_registry = __esm({
4699
4676
  outputTool: GATEKEEPER_OUTPUT_TOOL_NAME,
4700
4677
  settlement: "accepted",
4701
4678
  runnerFailure: "engine-detour-record-first",
4702
- acceptedText: "\u95E8\u4E0B\u7701\u51B3\u8BAE\u5DF2\u53D7\u7406",
4703
4679
  activationStage: "load-and-install",
4704
4680
  // Province materials; officers reuse their own public records below.
4705
4681
  sessionMaterials: ["CLAUDE.md", "souls/gatekeeper.md", "souls/quality-law.md", "souls/gate-output-guide.md"]
@@ -4715,7 +4691,6 @@ var init_packaged_role_registry = __esm({
4715
4691
  outputTool: NAVIGATOR_OUTPUT_TOOL_NAME,
4716
4692
  settlement: "accepted",
4717
4693
  runnerFailure: "engine-detour-record-first",
4718
- acceptedText: "\u6E38\u5955\u4F7F\u5EFA\u8BAE\u5DF2\u53D7\u7406",
4719
4694
  activationStage: "load-and-install",
4720
4695
  sessionMaterials: ["CLAUDE.md", "souls/navigator.md"]
4721
4696
  },
@@ -4739,7 +4714,6 @@ var init_packaged_role_registry = __esm({
4739
4714
  /** Court reask replaces the initial prompt. */
4740
4715
  reaskPrompt: true,
4741
4716
  runnerFailure: "engine-detour-record-first",
4742
- acceptedText: "\u5BA1\u5211\u9662\u56DE\u6267\u5DF2\u63A5\u53D7",
4743
4717
  gateStageLabel: "\u5BA1\u5211\u9662",
4744
4718
  /** Gate summon binds --subject judge and --source-run. */
4745
4719
  gateSummon: "subject-source",
@@ -4758,7 +4732,6 @@ var init_packaged_role_registry = __esm({
4758
4732
  phases: [null],
4759
4733
  outputTool: DIARIST_OUTPUT_TOOL_NAME,
4760
4734
  settlement: "accepted",
4761
- acceptedText: "\u8D77\u5C45\u90CE\u56DE\u6267\u5DF2\u63A5\u53D7",
4762
4735
  activationStage: "load-and-install",
4763
4736
  sessionMaterials: [
4764
4737
  "CLAUDE.md",
@@ -5065,7 +5038,7 @@ function projectOfficerTerminal(officer, summoned) {
5065
5038
  status: "escalate",
5066
5039
  officer,
5067
5040
  // This-court receipt only (#879) — historical rows remain on terminal.submissions.
5068
- receipt: thisCourt.length > 0 ? thisCourt[thisCourt.length - 1] : retainedReceipt(outcome)
5041
+ receipt: outcome.decisiveFacts !== void 0 && Object.hasOwn(outcome.decisiveFacts, "auditEscalationReceipt") ? outcome.decisiveFacts.auditEscalationReceipt : thisCourt.length > 0 ? thisCourt[thisCourt.length - 1] : retainedReceipt(outcome)
5069
5042
  },
5070
5043
  summoned
5071
5044
  );
@@ -6298,8 +6271,8 @@ function formatTerminalResult(result) {
6298
6271
  `diagnostic ${encodeTerminalField(result.roleOutcome.diagnostic)}`
6299
6272
  );
6300
6273
  }
6301
- if (result.roleOutcome.kind === "failure" || result.roleOutcome.kind === "no_receipt") {
6302
- const facts = result.roleOutcome.decisiveFacts;
6274
+ if (result.roleOutcome.kind === "failure" || result.roleOutcome.kind === "no_receipt" || result.roleOutcome.kind === "audit_escalation") {
6275
+ const facts = result.roleOutcome.decisiveFacts ?? {};
6303
6276
  for (const [key, value] of Object.entries(facts)) {
6304
6277
  if (value === void 0) continue;
6305
6278
  const rendered = typeof value === "string" ? value : JSON.stringify(value);
@@ -6443,15 +6416,7 @@ async function projectAuditorTerminal(summoned) {
6443
6416
  if (rows.length === 0) {
6444
6417
  return readComplianceCandidate({}, usage);
6445
6418
  }
6446
- const decision = readComplianceCandidate(rows[rows.length - 1], usage);
6447
- if (rows.length === 1) return decision;
6448
- if (decision.status === "pass" || decision.status === "bounce" || decision.status === "escalate") {
6449
- return { ...decision, receipt: rows };
6450
- }
6451
- if (decision.status === "received") {
6452
- return { ...decision, reply: rows };
6453
- }
6454
- return decision;
6419
+ return readComplianceCandidate(rows[rows.length - 1], usage);
6455
6420
  }
6456
6421
  return {
6457
6422
  status: "received",
@@ -6465,6 +6430,7 @@ async function runComplianceAudit(options) {
6465
6430
  throw new Error("Compliance audit requires a parent run directory pointer");
6466
6431
  }
6467
6432
  const subject = options.subject;
6433
+ const submission = options.submission === void 0 ? void 0 : readableGateItem(options.submission);
6468
6434
  const summon = options.summonAuditor ?? (async (auditSubject, sourceRunDirectory, auditSignal, reask2) => {
6469
6435
  const { summonPublicRole: summonPublicRole2 } = await Promise.resolve().then(() => (init_public_role_summons(), public_role_summons_exports));
6470
6436
  const { homeFromRunDirectory: homeFromRunDirectory2 } = await Promise.resolve().then(() => (init_activation_ledger_topology(), activation_ledger_topology_exports));
@@ -6481,12 +6447,13 @@ async function runComplianceAudit(options) {
6481
6447
  cwd: options.context.cwd ?? process.cwd(),
6482
6448
  home,
6483
6449
  ...auditSignal === void 0 ? {} : { signal: auditSignal },
6484
- ...reask2 === void 0 ? {} : { reviewReask: reask2 }
6450
+ ...reask2 === void 0 ? {} : { reviewReask: reask2 },
6451
+ ...submission === void 0 ? {} : { gateReviewInstruction: submission }
6485
6452
  });
6486
6453
  });
6487
6454
  let reask;
6488
6455
  for (; ; ) {
6489
- const summoned = await summon(subject, runDirectory, options.signal, reask);
6456
+ const summoned = await summon(subject, runDirectory, options.signal, reask, submission);
6490
6457
  const decision = await projectAuditorTerminal(summoned);
6491
6458
  if (decision.status === "received") {
6492
6459
  reask = OFFICER_CONCLUSION_REASK;
@@ -6502,6 +6469,7 @@ var init_compliance_transport = __esm({
6502
6469
  init_auditor_dossier_tool();
6503
6470
  init_gatekeeper_role();
6504
6471
  init_terminal();
6472
+ init_readable_gate_item();
6505
6473
  AUDITOR_DOSSIER_PROMPT = "\u5377\u5B97\u6307\u9488\uFF1A";
6506
6474
  AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE = "ak_auditor_parent_attempt_binding";
6507
6475
  AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE = "ak_auditor_compliance_failure";
@@ -13525,12 +13493,16 @@ __export(audit_escalation_exports, {
13525
13493
  disposeComplianceDecision: () => disposeComplianceDecision,
13526
13494
  isAuditEscalationProjection: () => isAuditEscalationProjection,
13527
13495
  isAuditEscalationResult: () => isAuditEscalationResult,
13528
- projectAuditEscalation: () => projectAuditEscalation
13496
+ projectAuditEscalation: () => projectAuditEscalation,
13497
+ projectGatekeeperEscalation: () => projectGatekeeperEscalation
13529
13498
  });
13530
13499
  function buildAuditEscalationResult(decision, deliveredOutput) {
13531
13500
  const auditOwned = {
13532
13501
  kind: AUDIT_ESCALATION_KIND
13533
13502
  };
13503
+ if (Object.hasOwn(decision, "receipt")) {
13504
+ auditOwned.receipt = decision.receipt;
13505
+ }
13534
13506
  if (Object.hasOwn(decision, "conflicts")) {
13535
13507
  auditOwned.conflicts = decision.conflicts;
13536
13508
  }
@@ -13560,14 +13532,23 @@ function isAuditEscalationProjection(value) {
13560
13532
  }
13561
13533
  function projectAuditEscalation(decision, deliveredOutput) {
13562
13534
  const details = buildAuditEscalationResult(decision, deliveredOutput);
13563
- const original = deliveredOutput !== void 0 ? deliveredOutput : decision;
13564
13535
  return {
13565
- content: [{ type: "text", text: readableGateItem(original) }],
13536
+ content: [],
13566
13537
  details,
13567
13538
  terminate: true,
13568
13539
  ...decision.usage === void 0 ? {} : { usage: decision.usage }
13569
13540
  };
13570
13541
  }
13542
+ function projectGatekeeperEscalation(result, deliveredOutput) {
13543
+ const receipt = result.receipt;
13544
+ const record4 = receipt !== null && typeof receipt === "object" && !Array.isArray(receipt) ? receipt : void 0;
13545
+ return projectAuditEscalation({
13546
+ status: "escalate",
13547
+ officer: result.officer,
13548
+ conflicts: receipt,
13549
+ ...record4 !== void 0 && Object.hasOwn(record4, "decisionGate") ? { decisionGate: record4.decisionGate } : {}
13550
+ }, deliveredOutput);
13551
+ }
13571
13552
  function isAuditEscalationResult(value) {
13572
13553
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
13573
13554
  return false;
@@ -13616,7 +13597,6 @@ var AUDIT_ESCALATION_KIND, AUDIT_ESCALATION_LIVE_REGISTRY;
13616
13597
  var init_audit_escalation = __esm({
13617
13598
  "src/audit-escalation.ts"() {
13618
13599
  "use strict";
13619
- init_readable_gate_item();
13620
13600
  init_submission_errors();
13621
13601
  AUDIT_ESCALATION_KIND = "audit_escalation";
13622
13602
  AUDIT_ESCALATION_LIVE_REGISTRY = /* @__PURE__ */ new WeakSet();
@@ -13731,6 +13711,8 @@ function rowFromPayload(kind, payload, accepted, roleFallback) {
13731
13711
  ...role === void 0 ? {} : { role },
13732
13712
  kind,
13733
13713
  accepted,
13714
+ ...Object.hasOwn(payload, "auditReceipt") ? { auditReceipt: payload.auditReceipt } : {},
13715
+ ...Object.hasOwn(payload, "auditOfficer") ? { auditOfficer: payload.auditOfficer } : {},
13734
13716
  ...typeof payload.toolCallId === "string" && payload.toolCallId.length > 0 ? { toolCallId: payload.toolCallId } : {}
13735
13717
  };
13736
13718
  }
@@ -13995,6 +13977,7 @@ function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (er
13995
13977
  }
13996
13978
  }
13997
13979
  if (isAuditEscalationProjection(result.details) || isAuditEscalationProjection(params)) {
13980
+ const audit = isAuditEscalationProjection(result.details) && typeof result.details.audit === "object" && result.details.audit !== null ? result.details.audit : void 0;
13998
13981
  const closed2 = {
13999
13982
  role,
14000
13983
  kind: "audit_escalation",
@@ -14006,7 +13989,9 @@ function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (er
14006
13989
  toolCallId,
14007
13990
  outcome: "audit-escalation",
14008
13991
  role,
14009
- accepted: params
13992
+ accepted: params,
13993
+ ...audit !== void 0 && (Object.hasOwn(audit, "receipt") || Object.hasOwn(audit, "conflicts")) ? { auditReceipt: Object.hasOwn(audit, "receipt") ? audit.receipt : audit.conflicts } : {},
13994
+ ...audit !== void 0 && Object.hasOwn(audit, "officer") ? { auditOfficer: audit.officer } : {}
14010
13995
  });
14011
13996
  await projectClosure(closed2, context);
14012
13997
  return result;
@@ -15122,7 +15107,17 @@ function roleOutcomeFromRows(role, rows) {
15122
15107
  if (terminal.length === 0) return void 0;
15123
15108
  const payloads = mine.map((row) => row.accepted);
15124
15109
  if (terminal.some((row) => row.kind === "audit-escalation")) {
15125
- return { kind: "audit_escalation", role, status: "audit_escalation", payloads };
15110
+ const audited = terminal.slice().reverse().find((row) => row.kind === "audit-escalation" && Object.hasOwn(row, "auditReceipt"));
15111
+ return {
15112
+ kind: "audit_escalation",
15113
+ role,
15114
+ status: "audit_escalation",
15115
+ payloads,
15116
+ ...audited === void 0 ? {} : { decisiveFacts: {
15117
+ auditEscalationReceipt: audited.auditReceipt,
15118
+ ...Object.hasOwn(audited, "auditOfficer") ? { auditEscalationOfficer: audited.auditOfficer } : {}
15119
+ } }
15120
+ };
15126
15121
  }
15127
15122
  return { kind: "accepted", role, payloads };
15128
15123
  }
@@ -23282,7 +23277,7 @@ async function requireGatekeeperPass(options) {
23282
23277
  });
23283
23278
  options.hostActions.failInfrastructure(failure2, options.context, options.toolCallId);
23284
23279
  }
23285
- if (gatekeeper.status === "escalate" && options.subject.kind === "secretariat_verdict") {
23280
+ if (gatekeeper.status === "escalate") {
23286
23281
  throw new GatekeeperDecisionError(gatekeeper);
23287
23282
  }
23288
23283
  options.hostActions.bindSubmissionNonPass(options.toolCallId, gatekeeper);
@@ -23407,6 +23402,7 @@ async function installWorkspaceMethodSkills(cwd, packageRoot) {
23407
23402
  init_packaged_role_registry();
23408
23403
 
23409
23404
  // src/role-runtime.ts
23405
+ init_readable_gate_item();
23410
23406
  init_host_contracts();
23411
23407
  init_sitian_facade();
23412
23408
  init_submission_ledger();
@@ -23835,8 +23831,6 @@ function registerEngineDetourTool(roleHost, hostActions) {
23835
23831
  }
23836
23832
 
23837
23833
  // src/role-runtime.ts
23838
- init_readable_gate_item();
23839
- init_run_terminal_artifacts();
23840
23834
  init_receipt_delivery_policy();
23841
23835
 
23842
23836
  // src/collector-role.ts
@@ -24059,7 +24053,6 @@ function isNotFound(error) {
24059
24053
 
24060
24054
  // src/collector-role.ts
24061
24055
  init_collector_ledger();
24062
- init_packaged_role_registry();
24063
24056
  init_submission_correctable_error();
24064
24057
  init_collector_identity();
24065
24058
  init_collector_identity();
@@ -24539,10 +24532,7 @@ function createCollectorRoleRuntime(pi, dependencies, hostActions) {
24539
24532
  activation.ledger.beginOperational(COLLECTOR_OUTPUT_TOOL, toolCallId);
24540
24533
  activation.ledger.recordOutputCandidate();
24541
24534
  return {
24542
- content: [{
24543
- type: "text",
24544
- text: packagedRoleAcceptedText("collector")
24545
- }],
24535
+ content: [],
24546
24536
  details: params,
24547
24537
  terminate: true
24548
24538
  };
@@ -24565,7 +24555,7 @@ init_audit_escalation();
24565
24555
  init_compliance_transport();
24566
24556
  init_submission_errors();
24567
24557
  init_dossier_resolution();
24568
- init_packaged_role_registry();
24558
+ init_readable_gate_item();
24569
24559
  init_doctor_contracts();
24570
24560
  init_sitian_facade();
24571
24561
  var DOCTOR_CASE_FLAG = { name: "ak-doctor-case", definition: { description: "Retained .ak-roles/books/<book>/<n>/runs directory", type: "string" } };
@@ -24620,22 +24610,22 @@ function createDoctorRoleRuntime(pi, dependencies, host) {
24620
24610
  }
24621
24611
  let audit;
24622
24612
  try {
24623
- audit = await dependencies.auditCompliance(signal === void 0 ? { context: ctx } : { context: ctx, signal });
24613
+ audit = await dependencies.auditCompliance(signal === void 0 ? { context: ctx, submission: testimony } : { context: ctx, signal, submission: testimony });
24624
24614
  } catch (error) {
24625
24615
  host.failInfrastructure(error, ctx, id);
24626
24616
  }
24627
24617
  const acceptedDetails = testimony;
24628
- return disposeComplianceDecision(audit, { pass: (usage) => ({ content: [{ type: "text", text: packagedRoleAcceptedText("doctor") }], details: acceptedDetails, terminate: true, ...usage === void 0 ? {} : { usage } }), noReceipt: (auditNoReceipt, usageProjection) => {
24618
+ 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) => {
24629
24619
  try {
24630
24620
  appendCandidate(ctx, { version: 1, testimony, cost: active2.patient.cost, auditNoReceipt, readRecord: active2.store.readRecord(), patientIdentity: active2.patient.identity });
24631
24621
  } catch (error) {
24632
24622
  host.failInfrastructure(error, ctx, id);
24633
24623
  }
24634
- return { content: [{ type: "text", text: DOCTOR_ACCEPTED_AUDIT_NO_RECEIPT_TEXT }], details: acceptedDetails, terminate: true, ...usageProjection };
24624
+ return { content: [], details: acceptedDetails, terminate: true, ...usageProjection };
24635
24625
  }, received: () => {
24636
24626
  throw new Error("\u5BA1\u5211\u9662\u975E\u4E09\u6001\u5E94\u4EA4 runComplianceAudit \u91CD\u95EE\u8BF4\u8BDD\u8005");
24637
24627
  }, bounce: (violations) => {
24638
- throw new GatekeeperDecisionError({ status: "bounce", officer: "auditor", receipt: violations });
24628
+ throw new GatekeeperDecisionError({ status: "bounce", officer: "auditor", receipt: audit.status === "bounce" ? audit.receipt ?? violations : violations });
24639
24629
  }, escalate: (result) => result, transportFailure: (facts) => {
24640
24630
  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);
24641
24631
  } }, acceptedDetails);
@@ -24664,7 +24654,6 @@ ${JSON.stringify(catalog)}
24664
24654
  }
24665
24655
 
24666
24656
  // src/notary-role.ts
24667
- init_packaged_role_registry();
24668
24657
  init_notary_contracts();
24669
24658
  function readNotaryTicketFlag(flag) {
24670
24659
  if (flag === void 0) return void 0;
@@ -24743,7 +24732,7 @@ function createNotaryRoleRuntime(pi, dependencies, host) {
24743
24732
  throw new Error("\u7B26\u5B9D\u90CE\u672A\u6FC0\u6D3B");
24744
24733
  }
24745
24734
  return {
24746
- content: [{ type: "text", text: packagedRoleAcceptedText("notary") }],
24735
+ content: [],
24747
24736
  details: parameters,
24748
24737
  terminate: true
24749
24738
  };
@@ -24974,7 +24963,6 @@ var DIARIST_TOOL_SPEC = {
24974
24963
  // src/secretariat-role.ts
24975
24964
  init_terminating_infrastructure();
24976
24965
  init_secretariat_contracts();
24977
- init_run_terminal_artifacts();
24978
24966
  init_secretariat_contracts();
24979
24967
  import { Type as Type21 } from "typebox";
24980
24968
  var secretariatVerdictSchema = withTerminatingOutputDeclarations(
@@ -25002,17 +24990,6 @@ var secretariatVerdictSchema = withTerminatingOutputDeclarations(
25002
24990
  )
25003
24991
  );
25004
24992
  secretariatVerdictSchema.required = [];
25005
- var secretariatSummonCountersignSchema = Type21.Object(
25006
- {
25007
- instruction: Type21.Optional(
25008
- Type21.String({
25009
- description: "\u4F20\u53EC\u6563\u6587\uFF1B\u7968\u53F7\u5199\u5728\u5176\u4E2D\u3002\u7A7A\u5219\u6CBF\u7528\u672C\u5C40\u6307\u4EE4\u3002"
25010
- })
25011
- )
25012
- },
25013
- { additionalProperties: true }
25014
- );
25015
- secretariatSummonCountersignSchema.required = [];
25016
24993
  var SECRETARIAT_OUTPUT_TOOL_SPEC = {
25017
24994
  name: SECRETARIAT_OUTPUT_TOOL_NAME,
25018
24995
  label: "\u4E2D\u4E66\u7701\u8F93\u51FA",
@@ -25020,68 +24997,6 @@ var SECRETARIAT_OUTPUT_TOOL_SPEC = {
25020
24997
  promptSnippet: "\u4E2D\u4E66\u7701\u7EC8\u5C40\u56DE\u6267",
25021
24998
  parameters: secretariatVerdictSchema
25022
24999
  };
25023
- var SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_SPEC = {
25024
- name: SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME,
25025
- label: "\u4F20\u53EC\u7ED9\u4E8B\u4E2D",
25026
- 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",
25027
- promptSnippet: "\u4F20\u53EC\u7ED9\u4E8B\u4E2D",
25028
- parameters: secretariatSummonCountersignSchema
25029
- };
25030
- function latestObjectPayload(payloads) {
25031
- if (payloads === void 0 || payloads.length === 0) return void 0;
25032
- const latest = payloads[payloads.length - 1];
25033
- if (latest === null || typeof latest !== "object" || Array.isArray(latest)) {
25034
- return void 0;
25035
- }
25036
- return latest;
25037
- }
25038
- function projectSecretariatSummonResult(summoned) {
25039
- const terminal = summoned.terminal;
25040
- const roleOutcome = terminal?.roleOutcome;
25041
- const runDirectory = summoned.runDirectory;
25042
- const runId = typeof runDirectory === "string" && runDirectory.trim() !== "" ? runIdFromRunDirectory(runDirectory) : void 0;
25043
- const base = {
25044
- exitCode: summoned.exitCode,
25045
- ...runId === void 0 ? {} : { runId },
25046
- ...runDirectory === void 0 ? {} : { runDirectory },
25047
- ...summoned.stderr === void 0 || summoned.stderr === "" ? {} : { stderr: summoned.stderr }
25048
- };
25049
- if (roleOutcome === void 0) {
25050
- return { ...base, outcomeKind: "no_terminal" };
25051
- }
25052
- if (roleOutcome.kind === "accepted" || roleOutcome.kind === "audit_escalation") {
25053
- const payloads = Array.isArray(roleOutcome.payloads) ? roleOutcome.payloads : void 0;
25054
- const latest = latestObjectPayload(payloads);
25055
- const countersignStatus = latest !== void 0 && typeof latest.countersignStatus === "string" ? latest.countersignStatus : void 0;
25056
- return {
25057
- ...base,
25058
- outcomeKind: roleOutcome.kind,
25059
- // audit_escalation carries typed status; accepted may carry fixture/compat status.
25060
- ..."status" in roleOutcome && typeof roleOutcome.status === "string" && roleOutcome.status.length > 0 ? { status: roleOutcome.status } : {},
25061
- ...countersignStatus === void 0 ? {} : { countersignStatus },
25062
- ...latest === void 0 ? {} : { receipt: latest },
25063
- ...payloads === void 0 ? {} : { payloads },
25064
- ...roleOutcome.decisiveFacts === void 0 ? {} : { decisiveFacts: roleOutcome.decisiveFacts }
25065
- };
25066
- }
25067
- if (roleOutcome.kind === "failure") {
25068
- const submissions = Array.isArray(terminal?.submissions) ? terminal.submissions : void 0;
25069
- return {
25070
- ...base,
25071
- outcomeKind: "failure",
25072
- diagnostic: roleOutcome.diagnostic,
25073
- ...roleOutcome.cause === void 0 ? {} : { cause: roleOutcome.cause },
25074
- ...roleOutcome.decisiveFacts === void 0 ? {} : { decisiveFacts: roleOutcome.decisiveFacts },
25075
- ...submissions === void 0 || submissions.length === 0 ? {} : { submissions }
25076
- };
25077
- }
25078
- return {
25079
- ...base,
25080
- outcomeKind: roleOutcome.kind,
25081
- ..."status" in roleOutcome && typeof roleOutcome.status === "string" && roleOutcome.status.length > 0 ? { status: roleOutcome.status } : {},
25082
- ..."decisiveFacts" in roleOutcome && roleOutcome.decisiveFacts !== void 0 ? { decisiveFacts: roleOutcome.decisiveFacts } : {}
25083
- };
25084
- }
25085
25000
 
25086
25001
  // src/role-runtime.ts
25087
25002
  init_secretariat_contracts();
@@ -26101,7 +26016,8 @@ init_audit_escalation();
26101
26016
  // src/judge-role.ts
26102
26017
  init_terminating_infrastructure();
26103
26018
  init_submission_errors();
26104
- init_packaged_role_registry();
26019
+ init_audit_escalation();
26020
+ init_readable_gate_item();
26105
26021
  init_judge_output();
26106
26022
  import { Type as Type24 } from "typebox";
26107
26023
  var JUDGE_QUEUE_STATUSES = /* @__PURE__ */ new Set(["converged", "continue", "escalate"]);
@@ -26165,35 +26081,45 @@ function createJudgeRoleRuntime(pi, dependencies, hostActions) {
26165
26081
  if (rawStatus === "escalate") {
26166
26082
  const verdict2 = validateVerdict(parameters);
26167
26083
  return {
26168
- content: [{ type: "text", text: packagedRoleAcceptedText("judge") }],
26084
+ content: [],
26169
26085
  details: verdict2,
26170
26086
  terminate: true
26171
26087
  };
26172
26088
  }
26173
26089
  const verdict = validateVerdict(parameters);
26174
- await pi.requireGatekeeperPass({
26175
- context: ctx,
26176
- subject: { kind: "judge_draft" },
26177
- ...signal === void 0 ? {} : { signal },
26178
- hostActions,
26179
- toolCallId,
26180
- // #879: this-turn typed payload — identity-bound at submit site.
26181
- submission: parameters
26182
- });
26183
- await pi.requireGatekeeperPass({
26184
- context: ctx,
26185
- subject: { kind: "judge_compliance" },
26186
- ...signal === void 0 ? {} : { signal },
26187
- hostActions,
26188
- toolCallId,
26189
- // #879: same parent payload for 审刑院; not recovered from session latest.
26190
- submission: parameters
26191
- });
26192
- return {
26193
- content: [{ type: "text", text: packagedRoleAcceptedText("judge") }],
26194
- details: verdict,
26195
- terminate: true
26196
- };
26090
+ let draftPass;
26091
+ try {
26092
+ const obtainedDraftPass = await pi.requireGatekeeperPass({
26093
+ context: ctx,
26094
+ subject: { kind: "judge_draft" },
26095
+ ...signal === void 0 ? {} : { signal },
26096
+ hostActions,
26097
+ toolCallId,
26098
+ // #879: this-turn typed payload — identity-bound at submit site.
26099
+ submission: parameters
26100
+ });
26101
+ draftPass = obtainedDraftPass || void 0;
26102
+ if (draftPass !== void 0) hostActions.bindPriorGatePass(toolCallId, draftPass.receipt);
26103
+ const compliancePass = await pi.requireGatekeeperPass({
26104
+ context: ctx,
26105
+ subject: { kind: "judge_compliance" },
26106
+ ...signal === void 0 ? {} : { signal },
26107
+ hostActions,
26108
+ toolCallId,
26109
+ // #879: same parent payload for 审刑院; not recovered from session latest.
26110
+ submission: parameters
26111
+ });
26112
+ return {
26113
+ content: [draftPass, compliancePass].filter((pass) => pass !== void 0).map((pass) => ({ type: "text", text: readableGateItem(pass.receipt) })),
26114
+ details: verdict,
26115
+ terminate: true
26116
+ };
26117
+ } catch (error) {
26118
+ if (error instanceof GatekeeperDecisionError && error.result.status === "escalate") {
26119
+ return projectGatekeeperEscalation(error.result, verdict);
26120
+ }
26121
+ throw error;
26122
+ }
26197
26123
  }
26198
26124
  });
26199
26125
  pi.on("before_agent_start", (event) => {
@@ -26214,7 +26140,6 @@ ${soul}
26214
26140
  // src/reviewer-role.ts
26215
26141
  init_open_tool_schema();
26216
26142
  init_terminating_infrastructure();
26217
- init_packaged_role_registry();
26218
26143
  init_reviewer_output();
26219
26144
  import { Type as Type25 } from "typebox";
26220
26145
  var reviewerAmendmentsSchema = Type25.Object({
@@ -26267,7 +26192,7 @@ function createReviewerRoleRuntime(pi, dependencies, _hostActions) {
26267
26192
  async execute(_id, parameters) {
26268
26193
  if (!soul || !binding) throw new Error("\u5FA1\u53F2\u53F0\u8F93\u5165\u672A\u88C5\u8F7D");
26269
26194
  return {
26270
- content: [{ type: "text", text: packagedRoleAcceptedText("reviewer") }],
26195
+ content: [],
26271
26196
  details: parameters,
26272
26197
  terminate: true
26273
26198
  };
@@ -26290,7 +26215,9 @@ function createReviewerRoleRuntime(pi, dependencies, _hostActions) {
26290
26215
  init_open_tool_schema();
26291
26216
  init_terminating_infrastructure();
26292
26217
  init_submission_correctable_error();
26293
- init_packaged_role_registry();
26218
+ init_readable_gate_item();
26219
+ init_audit_escalation();
26220
+ init_submission_errors();
26294
26221
  init_worker_output();
26295
26222
  init_fixer_output();
26296
26223
  init_fixer_packet();
@@ -26700,8 +26627,9 @@ function createFixerRoleRuntime(pi, dependencies, hostActions) {
26700
26627
  ctx,
26701
26628
  toolCallId
26702
26629
  );
26703
- if (WORKER_DONE_STATUSES.has(workerStatusOf(output))) {
26704
- await pi.requireGatekeeperPass({
26630
+ let pass;
26631
+ try {
26632
+ pass = WORKER_DONE_STATUSES.has(workerStatusOf(output)) ? await pi.requireGatekeeperPass({
26705
26633
  context: ctx,
26706
26634
  subject: { kind: "worker_completion" },
26707
26635
  ..._signal === void 0 ? {} : { signal: _signal },
@@ -26709,11 +26637,16 @@ function createFixerRoleRuntime(pi, dependencies, hostActions) {
26709
26637
  toolCallId,
26710
26638
  // #879: this-turn typed payload — identity-bound at submit site.
26711
26639
  submission: output
26712
- });
26640
+ }) : void 0;
26641
+ } catch (error) {
26642
+ if (error instanceof GatekeeperDecisionError && error.result.status === "escalate") {
26643
+ return projectGatekeeperEscalation(error.result, output);
26644
+ }
26645
+ throw error;
26713
26646
  }
26714
26647
  const acceptedDetails = output;
26715
26648
  return {
26716
- content: [{ type: "text", text: packagedRoleAcceptedText("fixer") }],
26649
+ content: pass === void 0 ? [] : [{ type: "text", text: readableGateItem(pass.receipt) }],
26717
26650
  details: acceptedDetails,
26718
26651
  terminate: true
26719
26652
  };
@@ -26838,8 +26771,9 @@ function createCoderRoleRuntime(pi, dependencies, hostActions) {
26838
26771
  ctx2,
26839
26772
  toolCallId
26840
26773
  );
26841
- if (WORKER_DONE_STATUSES.has(workerStatusOf(output))) {
26842
- await pi.requireGatekeeperPass({
26774
+ let pass;
26775
+ try {
26776
+ pass = WORKER_DONE_STATUSES.has(workerStatusOf(output)) ? await pi.requireGatekeeperPass({
26843
26777
  context: ctx2,
26844
26778
  subject: { kind: "worker_completion" },
26845
26779
  ..._signal === void 0 ? {} : { signal: _signal },
@@ -26847,11 +26781,16 @@ function createCoderRoleRuntime(pi, dependencies, hostActions) {
26847
26781
  toolCallId,
26848
26782
  // #879: this-turn typed payload — identity-bound at submit site.
26849
26783
  submission: output
26850
- });
26784
+ }) : void 0;
26785
+ } catch (error) {
26786
+ if (error instanceof GatekeeperDecisionError && error.result.status === "escalate") {
26787
+ return projectGatekeeperEscalation(error.result, output);
26788
+ }
26789
+ throw error;
26851
26790
  }
26852
26791
  const acceptedDetails = output;
26853
26792
  return {
26854
- content: [{ type: "text", text: packagedRoleAcceptedText("coder") }],
26793
+ content: pass === void 0 ? [] : [{ type: "text", text: readableGateItem(pass.receipt) }],
26855
26794
  details: acceptedDetails,
26856
26795
  terminate: true
26857
26796
  };
@@ -26910,7 +26849,6 @@ init_doctor_contracts();
26910
26849
  init_merger_contracts();
26911
26850
 
26912
26851
  // src/merger-role.ts
26913
- init_packaged_role_registry();
26914
26852
  init_merger_contracts();
26915
26853
  init_exact_utf8();
26916
26854
  var MERGER_INPUT_FLAG = { name: "ak-merger-input", definition: { description: "Path to Merger assignment materials JSON", type: "string" } };
@@ -26939,7 +26877,7 @@ function createMergerRoleRuntime(pi, dependencies) {
26939
26877
  parameters: mergerOutputSchema,
26940
26878
  async execute(_id, params, _signal, _update, _ctx) {
26941
26879
  if (!activation) throw new Error("\u6821\u4E66\u90CE\u672A\u6FC0\u6D3B");
26942
- return { content: [{ type: "text", text: packagedRoleAcceptedText("merger") }], details: params, terminate: true };
26880
+ return { content: [], details: params, terminate: true };
26943
26881
  }
26944
26882
  });
26945
26883
  pi.on("before_agent_start", (event) => {
@@ -26991,6 +26929,7 @@ function createPiDoctorAuditor() {
26991
26929
  return runComplianceAudit({
26992
26930
  subject: "doctor",
26993
26931
  context: options.context,
26932
+ submission: options.submission,
26994
26933
  ...auditorRunDirectory(options.context) === void 0 ? {} : { runDirectory: auditorRunDirectory(options.context) },
26995
26934
  ...options.signal === void 0 ? {} : { signal: options.signal },
26996
26935
  ...options.summonAuditor === void 0 ? {} : { summonAuditor: options.summonAuditor }
@@ -27253,9 +27192,13 @@ function createFiledOfficerRuntime(roleHost, spec, dependencies) {
27253
27192
  async execute(toolCallId, parameters, signal, _onUpdate, ctx) {
27254
27193
  if (soul === void 0) throw new Error(`${spec.role} \u804C\u5206\u672A\u88C5\u8F7D`);
27255
27194
  const projected = spec.beforeAccept === void 0 ? void 0 : await spec.beforeAccept({ toolCallId, parameters, signal, ctx });
27195
+ if (isAuditEscalationProjection(projected)) {
27196
+ return { content: [], details: projected, terminate: true };
27197
+ }
27198
+ const pass = spec.relayGatePass === true && projected !== null && typeof projected === "object" && "officer" in projected && "receipt" in projected ? projected : void 0;
27256
27199
  return {
27257
- content: [{ type: "text", text: packagedRoleAcceptedText(spec.role) }],
27258
- details: projected === void 0 ? parameters : projected,
27200
+ content: pass === void 0 || pass.receipt === void 0 ? [] : [{ type: "text", text: readableGateItem(pass.receipt) }],
27201
+ details: pass === void 0 ? projected === void 0 ? parameters : projected : parameters,
27259
27202
  terminate: true
27260
27203
  };
27261
27204
  }
@@ -27445,18 +27388,12 @@ ${error.message}`
27445
27388
  }
27446
27389
  var COUNTERSIGN_QUEUE_STATUSES = /* @__PURE__ */ new Set(["converged", "continue", "escalate"]);
27447
27390
  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";
27448
- var SECRETARIAT_SUBMISSION_GATE_HOSTS = /* @__PURE__ */ new Set(["codex", "claude", "grok-build"]);
27449
27391
  var SECRETARIAT_QUEUE_STATUSES = /* @__PURE__ */ new Set(["converged", "escalate"]);
27450
27392
  var SECRETARIAT_STATUS_REASK = "secretariatStatus \u4E0D\u662F converged\u3001escalate \u4E4B\u4E00\u3002\u8BF7\u91CD\u65B0\u4EA4\u5377\uFF0Cstatus \u5199\u660E\u5176\u4E00\u3002";
27451
27393
  function createSecretariatRoleRuntime(roleHost, dependencies, hostActions) {
27452
- let parentInstruction = "";
27453
27394
  const beforeAccept = hostActions !== void 0 ? async ({ toolCallId, parameters, signal, ctx }) => {
27454
- const host = typeof ctx.host === "string" && ctx.host.trim() !== "" ? ctx.host.trim() : void 0;
27455
- if (host === void 0 || !SECRETARIAT_SUBMISSION_GATE_HOSTS.has(host)) {
27456
- return void 0;
27457
- }
27458
27395
  if (roleHost.requireGatekeeperPass === void 0) {
27459
- const error = new Error(`host ${host} cannot mount the secretariat submission gate`);
27396
+ const error = new Error("host cannot mount the secretariat submission gate");
27460
27397
  error.name = "InfrastructureFailure";
27461
27398
  return hostActions.failInfrastructure(error, ctx, toolCallId);
27462
27399
  }
@@ -27489,7 +27426,7 @@ function createSecretariatRoleRuntime(roleHost, dependencies, hostActions) {
27489
27426
  ...runId === void 0 ? {} : { runId }
27490
27427
  });
27491
27428
  }
27492
- return void 0;
27429
+ return pass;
27493
27430
  } catch (error) {
27494
27431
  if (error instanceof GatekeeperDecisionError && error.result.status === "escalate") {
27495
27432
  const receipt = error.result.receipt;
@@ -27520,80 +27457,17 @@ function createSecretariatRoleRuntime(roleHost, dependencies, hostActions) {
27520
27457
  roleHost,
27521
27458
  {
27522
27459
  role: "secretariat",
27460
+ relayGatePass: true,
27523
27461
  tool: SECRETARIAT_OUTPUT_TOOL_SPEC,
27524
27462
  soulTag: "secretariat",
27525
27463
  ...beforeAccept === void 0 ? {} : { beforeAccept }
27526
27464
  },
27527
27465
  dependencies
27528
27466
  );
27529
- let summonRegistered = false;
27530
27467
  return {
27531
27468
  async activate() {
27532
27469
  await base.activate();
27533
- if (!summonRegistered) {
27534
- summonRegistered = true;
27535
- roleHost.on("before_agent_start", (event) => {
27536
- if (typeof event.prompt === "string" && event.prompt.trim() !== "") {
27537
- parentInstruction = event.prompt;
27538
- }
27539
- });
27540
- roleHost.registerTool({
27541
- name: SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME,
27542
- label: SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_SPEC.label,
27543
- description: SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_SPEC.description,
27544
- promptSnippet: SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_SPEC.promptSnippet,
27545
- parameters: SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_SPEC.parameters,
27546
- async execute(_toolCallId, parameters, signal, _onUpdate, ctx) {
27547
- const fromArgs = typeof parameters?.instruction === "string" ? parameters.instruction.trim() : "";
27548
- const instruction = fromArgs !== "" ? fromArgs : parentInstruction.trim();
27549
- const correlationId = (() => {
27550
- const runDirectory = runDirectoryFromHostContext(ctx);
27551
- if (runDirectory === void 0) return void 0;
27552
- return runIdFromRunDirectory(runDirectory);
27553
- })();
27554
- const summon = dependencies.summonCountersign;
27555
- const summoned = summon === void 0 ? await (async () => {
27556
- const coordinates = readRoleRunCoordinates(ctx, "secretariat summons");
27557
- const { summonPublicRole: summonPublicRole2 } = await Promise.resolve().then(() => (init_public_role_summons(), public_role_summons_exports));
27558
- const { readBoardTicketNumber: readBoardTicketNumber2 } = await Promise.resolve().then(() => (init_run_ticket_number(), run_ticket_number_exports));
27559
- const parentTicket = await readBoardTicketNumber2(coordinates.runDirectory);
27560
- return summonPublicRole2({
27561
- role: "countersign",
27562
- argv: ["--project", coordinates.projectRoot, "--", instruction],
27563
- cwd: coordinates.projectRoot,
27564
- home: coordinates.home,
27565
- parentRunPath: coordinates.runDirectory,
27566
- ...parentTicket === void 0 ? {} : { boundTicketNumber: parentTicket },
27567
- ...signal === void 0 ? {} : { signal },
27568
- ...correlationId === void 0 ? {} : { correlationId },
27569
- ...dependencies.packageRoot === void 0 ? {} : { packageRoot: dependencies.packageRoot },
27570
- ...dependencies.hostAdapters === void 0 ? {} : { hostAdapters: dependencies.hostAdapters }
27571
- });
27572
- })() : await summon({
27573
- instruction,
27574
- cwd: ctx.cwd,
27575
- ...signal === void 0 ? {} : { signal },
27576
- ...correlationId === void 0 ? {} : { correlationId },
27577
- ...dependencies.home === void 0 ? {} : { home: dependencies.home },
27578
- ...dependencies.packageRoot === void 0 ? {} : { packageRoot: dependencies.packageRoot }
27579
- });
27580
- const details = projectSecretariatSummonResult(summoned);
27581
- return {
27582
- content: [
27583
- {
27584
- type: "text",
27585
- text: readableGateItem(details)
27586
- }
27587
- ],
27588
- details
27589
- };
27590
- }
27591
- });
27592
- }
27593
- const packageRequired = [
27594
- SECRETARIAT_OUTPUT_TOOL_NAME,
27595
- SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME
27596
- ];
27470
+ const packageRequired = [SECRETARIAT_OUTPUT_TOOL_NAME];
27597
27471
  const all = roleHost.getAllTools().map((tool) => tool.name);
27598
27472
  for (const name of packageRequired) {
27599
27473
  if (all.filter((item) => item === name).length !== 1) {
@@ -27631,20 +27505,29 @@ function createCountersignRoleRuntime(roleHost, dependencies, hostActions) {
27631
27505
  error.name = "InfrastructureFailure";
27632
27506
  return hostActions.failInfrastructure(error, ctx, toolCallId);
27633
27507
  }
27634
- await roleHost.requireGatekeeperPass({
27635
- context: ctx,
27636
- subject: { kind: "countersign_verdict" },
27637
- ...signal === void 0 ? {} : { signal },
27638
- hostActions,
27639
- toolCallId,
27640
- // #879: this-turn typed payload — identity-bound at submit site.
27641
- submission: parameters
27642
- });
27508
+ try {
27509
+ return await roleHost.requireGatekeeperPass({
27510
+ context: ctx,
27511
+ subject: { kind: "countersign_verdict" },
27512
+ ...signal === void 0 ? {} : { signal },
27513
+ hostActions,
27514
+ toolCallId,
27515
+ // #879: this-turn typed payload — identity-bound at submit site.
27516
+ submission: parameters
27517
+ });
27518
+ } catch (error) {
27519
+ if (error instanceof GatekeeperDecisionError && error.result.status === "escalate") {
27520
+ const { buildAuditEscalationResult: buildAuditEscalationResult2 } = await Promise.resolve().then(() => (init_audit_escalation(), audit_escalation_exports));
27521
+ return buildAuditEscalationResult2({ status: "escalate", officer: "notary", conflicts: error.result.receipt }, parameters);
27522
+ }
27523
+ throw error;
27524
+ }
27643
27525
  } : void 0;
27644
27526
  return createFiledOfficerRuntime(
27645
27527
  roleHost,
27646
27528
  {
27647
27529
  role: "countersign",
27530
+ relayGatePass: true,
27648
27531
  tool: COUNTERSIGN_TOOL_SPEC,
27649
27532
  soulTag: "countersign",
27650
27533
  ...beforeAccept === void 0 ? {} : { beforeAccept }
@@ -27715,6 +27598,7 @@ function createRoleRuntimeExtension(dependencies) {
27715
27598
  let navigatorCwd;
27716
27599
  const pendingInfrastructureFailures = /* @__PURE__ */ new Map();
27717
27600
  const pendingSubmissionNonPassByToolCallId = /* @__PURE__ */ new Map();
27601
+ const pendingPriorGatePassByToolCallId = /* @__PURE__ */ new Map();
27718
27602
  let engineDetourRegistered = false;
27719
27603
  let receiptDelivery = createReceiptDeliveryPolicy();
27720
27604
  let noReceiptRecorded = false;
@@ -27909,6 +27793,9 @@ function createRoleRuntimeExtension(dependencies) {
27909
27793
  return { readingMaterial: caseDossier };
27910
27794
  });
27911
27795
  roleHost.on("tool_result", async (event) => {
27796
+ const priorGatePass = pendingPriorGatePassByToolCallId.get(event.toolCallId);
27797
+ pendingPriorGatePassByToolCallId.delete(event.toolCallId);
27798
+ const priorPassContent = priorGatePass !== void 0 && event.isError ? [{ type: "text", text: readableGateItem(priorGatePass) }, ...event.content ?? []] : void 0;
27912
27799
  const role = selectedRole;
27913
27800
  if (role === void 0) return;
27914
27801
  if (activeCollector !== void 0 && selectedRole === roleHost.getFlag(ROLE_FLAG.name)) {
@@ -27930,13 +27817,14 @@ function createRoleRuntimeExtension(dependencies) {
27930
27817
  const settlement = isRoleInfrastructureFailure || outputClassification?.kind === "infrastructure" ? publicNavigatorSettlement(role, navigatorPhase(roleHost, role), classified) : void 0;
27931
27818
  await settleNavigatorProjection(settlement);
27932
27819
  if (infrastructureDetails !== void 0) {
27933
- return { isError: true };
27820
+ return { isError: true, ...priorPassContent === void 0 ? {} : { content: priorPassContent } };
27934
27821
  }
27935
27822
  const submissionNonPass = pendingSubmissionNonPassByToolCallId.get(event.toolCallId);
27936
27823
  if (submissionNonPass !== void 0) {
27937
27824
  pendingSubmissionNonPassByToolCallId.delete(event.toolCallId);
27938
- return { details: submissionNonPass, isError: true };
27825
+ return { details: submissionNonPass, isError: true, ...priorPassContent === void 0 ? {} : { content: priorPassContent } };
27939
27826
  }
27827
+ if (priorPassContent !== void 0) return { content: priorPassContent, isError: true };
27940
27828
  });
27941
27829
  roleHost.on("agent_end", async (event, ctx) => {
27942
27830
  const lastMessage = event.messages.at(-1);
@@ -28072,6 +27960,7 @@ function createRoleRuntimeExtension(dependencies) {
28072
27960
  disposeNavigatorAttendanceNonBlocking(attendanceToDispose);
28073
27961
  pendingInfrastructureFailures.clear();
28074
27962
  pendingSubmissionNonPassByToolCallId.clear();
27963
+ pendingPriorGatePassByToolCallId.clear();
28075
27964
  observationFace.reset();
28076
27965
  });
28077
27966
  const hostActions = {
@@ -28083,6 +27972,9 @@ function createRoleRuntimeExtension(dependencies) {
28083
27972
  },
28084
27973
  bindSubmissionNonPass(toolCallId, result) {
28085
27974
  pendingSubmissionNonPassByToolCallId.set(toolCallId, result);
27975
+ },
27976
+ bindPriorGatePass(toolCallId, receipt) {
27977
+ pendingPriorGatePassByToolCallId.set(toolCallId, receipt);
28086
27978
  }
28087
27979
  };
28088
27980
  const requireRoleSoul = (role) => dependencies.loadRoleSoul(role);
@@ -28184,9 +28076,7 @@ function createRoleRuntimeExtension(dependencies) {
28184
28076
  }
28185
28077
  );
28186
28078
  const secretariat = createSecretariatRoleRuntime(roleHost, {
28187
- loadSoul: () => requireRoleSoul("secretariat"),
28188
- ...dependencies.packageRoot === void 0 ? {} : { packageRoot: dependencies.packageRoot },
28189
- ...dependencies.hostAdapters === void 0 ? {} : { hostAdapters: dependencies.hostAdapters }
28079
+ loadSoul: () => requireRoleSoul("secretariat")
28190
28080
  }, hostActions);
28191
28081
  const merger = createMergerRoleRuntime(roleHost, {
28192
28082
  loadSoul: () => requireRoleSoul("merger"),
@@ -28377,6 +28267,7 @@ function createRoleRuntimeExtension(dependencies) {
28377
28267
  pendingNavigatorSettlement = void 0;
28378
28268
  pendingInfrastructureFailures.clear();
28379
28269
  pendingSubmissionNonPassByToolCallId.clear();
28270
+ pendingPriorGatePassByToolCallId.clear();
28380
28271
  navigatorWorkContext = void 0;
28381
28272
  envelopeHost.startKeepalive(ctx);
28382
28273
  const rawRole = roleHost.getFlag(ROLE_FLAG.name);