@akagilnc/pi-workflow-roles 0.1.3353 → 0.1.3377

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.
@@ -17301,10 +17301,6 @@ async function readTypedHttp429Observation(runDirectory) {
17301
17301
  if (!isV1ResumableProvider(observation.provider)) return void 0;
17302
17302
  return { httpStatus: 429, provider: observation.provider };
17303
17303
  }
17304
- function isV1ResumableFailure(input) {
17305
- if (input.hasLawfulTerminalResult) return false;
17306
- return input.typedHttp429 !== void 0;
17307
- }
17308
17304
  function renderResumeCommand(runId) {
17309
17305
  return `ak-role resume ${runId}`;
17310
17306
  }
@@ -21706,9 +21702,199 @@ var init_method_skill = __esm({
21706
21702
  }
21707
21703
  });
21708
21704
 
21705
+ // src/auditor-dossier-tool.ts
21706
+ var init_auditor_dossier_tool = __esm({
21707
+ "src/auditor-dossier-tool.ts"() {
21708
+ "use strict";
21709
+ init_build();
21710
+ }
21711
+ });
21712
+
21713
+ // src/engine-detour-tool.ts
21714
+ var engineDetourArgsSchema;
21715
+ var init_engine_detour_tool = __esm({
21716
+ "src/engine-detour-tool.ts"() {
21717
+ "use strict";
21718
+ init_build();
21719
+ init_engine_detour();
21720
+ engineDetourArgsSchema = typebox_exports.Object(
21721
+ {
21722
+ argv: typebox_exports.Array(typebox_exports.String({ minLength: 1 }), {
21723
+ minItems: 1,
21724
+ description: "\u9996\u9879\u4E3A PATH \u4E2D\u7684\u53EF\u6267\u884C\u6587\u4EF6\uFF0C\u5176\u4F59\u9879\u4E3A\u53C2\u6570\u3002"
21725
+ })
21726
+ },
21727
+ { additionalProperties: false }
21728
+ );
21729
+ }
21730
+ });
21731
+
21732
+ // src/session-opening-materials.ts
21733
+ import { existsSync as existsSync6 } from "node:fs";
21734
+ import { dirname as dirname8, join as join16 } from "node:path";
21735
+ import { fileURLToPath, pathToFileURL as pathToFileURL2 } from "node:url";
21736
+ function resolvePackageRootDir(moduleUrl = import.meta.url) {
21737
+ let dir = dirname8(fileURLToPath(moduleUrl));
21738
+ for (let i = 0; i < 8; i += 1) {
21739
+ if (existsSync6(join16(dir, "package.json")) && existsSync6(join16(dir, "souls"))) {
21740
+ return dir;
21741
+ }
21742
+ const parent = dirname8(dir);
21743
+ if (parent === dir) break;
21744
+ dir = parent;
21745
+ }
21746
+ return fileURLToPath(new URL("..", moduleUrl));
21747
+ }
21748
+ var packageRootUrl, MAIN_ROLE_SESSION_MATERIALS, GATEKEEPER_SESSION_MATERIALS;
21749
+ var init_session_opening_materials = __esm({
21750
+ "src/session-opening-materials.ts"() {
21751
+ "use strict";
21752
+ init_packaged_role_registry();
21753
+ packageRootUrl = pathToFileURL2(resolvePackageRootDir() + "/").href;
21754
+ MAIN_ROLE_SESSION_MATERIALS = {
21755
+ ...Object.fromEntries(
21756
+ PUBLIC_ROLE_RECORDS.map((record4) => [record4.role, record4.sessionMaterials])
21757
+ )
21758
+ };
21759
+ GATEKEEPER_SESSION_MATERIALS = {
21760
+ // #639: single authority — the public gatekeeper record owns the province list.
21761
+ gatekeeper: PUBLIC_ROLE_RECORDS.find((entry) => entry.role === "gatekeeper").sessionMaterials,
21762
+ inspector: INSPECTOR_SESSION_MATERIALS,
21763
+ notary: NOTARY_SESSION_MATERIALS
21764
+ };
21765
+ }
21766
+ });
21767
+
21768
+ // src/navigator-session-contracts.ts
21769
+ var navigatorProviderFailureSchema;
21770
+ var init_navigator_session_contracts = __esm({
21771
+ "src/navigator-session-contracts.ts"() {
21772
+ "use strict";
21773
+ init_build();
21774
+ init_value2();
21775
+ init_auditor_dossier_tool();
21776
+ init_institutional_resolution();
21777
+ navigatorProviderFailureSchema = typebox_exports.Object({
21778
+ source: typebox_exports.Union([
21779
+ typebox_exports.Literal("context"),
21780
+ typebox_exports.Literal("session"),
21781
+ typebox_exports.Literal("model"),
21782
+ typebox_exports.Literal("thinking"),
21783
+ typebox_exports.Literal("auth"),
21784
+ typebox_exports.Literal("quota"),
21785
+ typebox_exports.Literal("transport"),
21786
+ typebox_exports.Literal("unknown")
21787
+ ]),
21788
+ cause: typebox_exports.Union([
21789
+ typebox_exports.Literal("context"),
21790
+ typebox_exports.Literal("session"),
21791
+ typebox_exports.Literal("model"),
21792
+ typebox_exports.Literal("thinking"),
21793
+ typebox_exports.Literal("auth"),
21794
+ typebox_exports.Literal("quota"),
21795
+ typebox_exports.Literal("transport"),
21796
+ typebox_exports.Literal("unknown")
21797
+ ])
21798
+ }, { additionalProperties: false });
21799
+ }
21800
+ });
21801
+
21802
+ // src/receipt-delivery-policy.ts
21803
+ function isRecord9(value) {
21804
+ return typeof value === "object" && value !== null && !Array.isArray(value);
21805
+ }
21806
+ function parseNoReceiptLifecycleFacts(input) {
21807
+ if (!isRecord9(input) || typeof input.terminalToolCalled !== "boolean" || input.deliveryTurns !== RECEIPT_DELIVERY_TURN_LIMIT || input.sessionCompletion !== "settled-without-accepted-receipt" || input.acceptedReceipt !== false || typeof input.runPointer !== "string" || input.runPointer.trim() === "" || typeof input.attemptPointer !== "string" || input.attemptPointer.trim() === "" || !Array.isArray(input.rejectedReceipts) || !input.rejectedReceipts.every((item) => isRecord9(item) && typeof item.reason === "string")) {
21808
+ throw new TypeError("malformed no-receipt lifecycle facts");
21809
+ }
21810
+ return {
21811
+ terminalToolCalled: input.terminalToolCalled,
21812
+ rejectedReceipts: input.rejectedReceipts.map((item) => ({
21813
+ reason: item.reason,
21814
+ diagnosticAvailable: item.reason.trim() !== ""
21815
+ })),
21816
+ deliveryTurns: RECEIPT_DELIVERY_TURN_LIMIT,
21817
+ sessionCompletion: "settled-without-accepted-receipt",
21818
+ runPointer: input.runPointer,
21819
+ attemptPointer: input.attemptPointer,
21820
+ acceptedReceipt: false
21821
+ };
21822
+ }
21823
+ var RECEIPT_DELIVERY_TURN_LIMIT, NO_RECEIPT_LIFECYCLE_ENTRY_TYPE;
21824
+ var init_receipt_delivery_policy = __esm({
21825
+ "src/receipt-delivery-policy.ts"() {
21826
+ "use strict";
21827
+ RECEIPT_DELIVERY_TURN_LIMIT = 2;
21828
+ NO_RECEIPT_LIFECYCLE_ENTRY_TYPE = "ak-no-receipt-lifecycle";
21829
+ }
21830
+ });
21831
+
21832
+ // src/upstream-error-testimony.ts
21833
+ function isNonSuccessHttpStatus(status) {
21834
+ return typeof status === "number" && (status < 200 || status >= 300);
21835
+ }
21836
+ function hasUpstreamErrorTestimony(input) {
21837
+ if (isNonSuccessHttpStatus(input.httpStatus)) return true;
21838
+ return Array.isArray(input.diagnostics) && input.diagnostics.length > 0;
21839
+ }
21840
+ function projectConfirmedRemotePayload(input) {
21841
+ return {
21842
+ ...input.body === void 0 ? {} : { body: input.body },
21843
+ ...input.code === void 0 ? {} : { code: input.code },
21844
+ ...input.errno === void 0 ? {} : { errno: input.errno }
21845
+ };
21846
+ }
21847
+ var init_upstream_error_testimony = __esm({
21848
+ "src/upstream-error-testimony.ts"() {
21849
+ "use strict";
21850
+ }
21851
+ });
21852
+
21853
+ // src/evidence-child-executor.ts
21854
+ var init_evidence_child_executor = __esm({
21855
+ "src/evidence-child-executor.ts"() {
21856
+ "use strict";
21857
+ init_compliance_transport();
21858
+ init_auditor_dossier_tool();
21859
+ init_sitian_facade();
21860
+ init_engine_detour_tool();
21861
+ init_engine_detour();
21862
+ init_engine_material();
21863
+ init_session_opening_materials();
21864
+ init_config2();
21865
+ init_institutional_resolution();
21866
+ init_navigator_session_contracts();
21867
+ init_receipt_delivery_policy();
21868
+ init_typed_provider_http();
21869
+ init_upstream_error_testimony();
21870
+ }
21871
+ });
21872
+
21873
+ // src/compliance-transport.ts
21874
+ function createComplianceDecisionTool(name, description) {
21875
+ return { name, description, parameters: complianceDecisionSchema, async execute(_id, params) {
21876
+ return { content: [{ type: "text", text: "\u5BA1\u8BA1\u51B3\u8BAE\u5DF2\u6536" }], details: params, terminate: true };
21877
+ } };
21878
+ }
21879
+ var nonblank2, decisionGateSchema, complianceDecisionSchema, AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE, AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE;
21880
+ var init_compliance_transport = __esm({
21881
+ "src/compliance-transport.ts"() {
21882
+ "use strict";
21883
+ init_build();
21884
+ init_evidence_child_executor();
21885
+ init_auditor_dossier_tool();
21886
+ init_sitian_facade();
21887
+ nonblank2 = typebox_exports.String({ minLength: 1, pattern: "\\S" });
21888
+ decisionGateSchema = typebox_exports.Object({ question: nonblank2, options: typebox_exports.Array(nonblank2, { minItems: 1 }) }, { additionalProperties: false });
21889
+ complianceDecisionSchema = typebox_exports.Object({ status: typebox_exports.Unknown({ description: "pass | revise | escalate \u2014 \u5F62\u72B6\u6307\u5F15\uFF0C\u975E schema \u95F8" }), violations: typebox_exports.Array(nonblank2, { description: "\u89C2\u5BDF\u5230\u7684\u5408\u89C4\u8FDD\u89C4" }), conflicts: typebox_exports.Array(nonblank2, { description: "\u672A\u51B3\u6743\u5A01\u6216\u6267\u884C\u51B2\u7A81" }), decisionGate: typebox_exports.Union([decisionGateSchema, typebox_exports.Null()], { description: "\u5347\u7EA7\u95EE\u9898\u4E0E\u53EF\u9009\u9009\u9879" }) }, { additionalProperties: true, required: [] });
21890
+ AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE = "ak_auditor_parent_attempt_binding";
21891
+ AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE = "ak_auditor_compliance_failure";
21892
+ }
21893
+ });
21894
+
21709
21895
  // src/ledger-session-read.ts
21710
21896
  import { readFile as readFile11 } from "node:fs/promises";
21711
- function isRecord9(value) {
21897
+ function isRecord10(value) {
21712
21898
  return typeof value === "object" && value !== null && !Array.isArray(value);
21713
21899
  }
21714
21900
  async function readLedgerSessionJsonl(path) {
@@ -21732,7 +21918,7 @@ async function readLedgerSessionJsonl(path) {
21732
21918
  }
21733
21919
  break;
21734
21920
  }
21735
- if (!isRecord9(row)) {
21921
+ if (!isRecord10(row)) {
21736
21922
  const kind = row === null ? "null" : Array.isArray(row) ? "array" : typeof row;
21737
21923
  throw new LedgerSessionJsonlError(
21738
21924
  `complete non-object JSONL record in ${path} at line ${index + 1}: expected object, got ${kind}`,
@@ -21769,7 +21955,7 @@ function extractSessionModelSequence(rows) {
21769
21955
  if (row.type === "model_change" && typeof row.modelId === "string") {
21770
21956
  push(row.modelId);
21771
21957
  }
21772
- const message = isRecord9(row.message) ? row.message : void 0;
21958
+ const message = isRecord10(row.message) ? row.message : void 0;
21773
21959
  if (message?.role === "assistant" && typeof message.model === "string") {
21774
21960
  push(message.model);
21775
21961
  }
@@ -21785,11 +21971,11 @@ function extractSessionToolIntervals(rows) {
21785
21971
  const openById = /* @__PURE__ */ new Map();
21786
21972
  for (const row of rows) {
21787
21973
  const rowTimestamp = typeof row.timestamp === "string" ? row.timestamp : void 0;
21788
- const message = isRecord9(row.message) ? row.message : void 0;
21974
+ const message = isRecord10(row.message) ? row.message : void 0;
21789
21975
  if (message?.role === "assistant" && Array.isArray(message.content)) {
21790
21976
  const callTimestamp = typeof message.timestamp === "string" && message.timestamp ? message.timestamp : rowTimestamp;
21791
21977
  for (const part of message.content) {
21792
- if (!isRecord9(part) || part.type !== "toolCall") continue;
21978
+ if (!isRecord10(part) || part.type !== "toolCall") continue;
21793
21979
  if (typeof part.id !== "string" || part.id.length === 0) {
21794
21980
  throw new Error("toolCall frame missing string id");
21795
21981
  }
@@ -21802,7 +21988,7 @@ function extractSessionToolIntervals(rows) {
21802
21988
  if (openById.has(part.id)) {
21803
21989
  throw new Error(`duplicate toolCall id ${part.id}`);
21804
21990
  }
21805
- const args = isRecord9(part.arguments) ? part.arguments : void 0;
21991
+ const args = isRecord10(part.arguments) ? part.arguments : void 0;
21806
21992
  const command = part.name === "bash" && args !== void 0 && typeof args.command === "string" ? bashCommandFirstLine(args.command) : void 0;
21807
21993
  const interval = {
21808
21994
  toolCallId: part.id,
@@ -21870,10 +22056,19 @@ var init_ledger_session_read = __esm({
21870
22056
 
21871
22057
  // src/analyst-gate-cycles-read.ts
21872
22058
  import { readdir as readdir3 } from "node:fs/promises";
21873
- import { join as join16 } from "node:path";
21874
- function isRecord10(value) {
22059
+ import { join as join17 } from "node:path";
22060
+ function isRecord11(value) {
21875
22061
  return typeof value === "object" && value !== null && !Array.isArray(value);
21876
22062
  }
22063
+ function extractAttemptEntryId(rows) {
22064
+ for (const row of rows) {
22065
+ if (row.type !== "custom" || row.customType !== AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE) continue;
22066
+ if (!isRecord11(row.data) || !isRecord11(row.data.parent)) continue;
22067
+ const id = row.data.parent.attemptEntryId;
22068
+ if (typeof id === "string" && id.length > 0) return id;
22069
+ }
22070
+ return void 0;
22071
+ }
21877
22072
  function isMissingDirectoryError(error) {
21878
22073
  return error instanceof Error && "code" in error && error.code === "ENOENT";
21879
22074
  }
@@ -21896,32 +22091,38 @@ function isGateTerminatingToolName(toolName) {
21896
22091
  function acceptedGateReceiptIds(rows) {
21897
22092
  const accepted = /* @__PURE__ */ new Set();
21898
22093
  for (const row of rows) {
21899
- const message = isRecord10(row.message) ? row.message : void 0;
22094
+ const message = isRecord11(row.message) ? row.message : void 0;
21900
22095
  if (message?.role !== "toolResult") continue;
21901
22096
  if (typeof message.toolCallId !== "string" || message.toolCallId.length === 0) continue;
21902
22097
  if (message.isError === false) accepted.add(message.toolCallId);
21903
22098
  }
21904
22099
  return accepted;
21905
22100
  }
21906
- function extractLastAcceptedGateToolCall(rows) {
22101
+ function extractLastGateToolCall(rows) {
21907
22102
  const acceptedIds = acceptedGateReceiptIds(rows);
21908
- let last;
22103
+ let lastAccepted;
22104
+ let lastRejected;
21909
22105
  for (const row of rows) {
21910
- const message = isRecord10(row.message) ? row.message : void 0;
22106
+ const message = isRecord11(row.message) ? row.message : void 0;
21911
22107
  if (message?.role !== "assistant" || !Array.isArray(message.content)) continue;
21912
22108
  for (const part of message.content) {
21913
- if (!isRecord10(part) || part.type !== "toolCall") continue;
22109
+ if (!isRecord11(part) || part.type !== "toolCall") continue;
21914
22110
  if (typeof part.id !== "string" || part.id.length === 0) continue;
21915
- if (!acceptedIds.has(part.id)) continue;
21916
22111
  if (typeof part.name !== "string" || part.name.length === 0) continue;
21917
22112
  if (!isGateTerminatingToolName(part.name)) continue;
21918
- last = {
22113
+ const call = {
21919
22114
  toolName: part.name,
21920
- args: isRecord10(part.arguments) ? part.arguments : void 0
22115
+ args: isRecord11(part.arguments) ? part.arguments : void 0,
22116
+ accepted: acceptedIds.has(part.id)
21921
22117
  };
22118
+ if (call.accepted) {
22119
+ lastAccepted = call;
22120
+ } else if (lastAccepted === void 0) {
22121
+ lastRejected = call;
22122
+ }
21922
22123
  }
21923
22124
  }
21924
- return last;
22125
+ return lastAccepted ?? lastRejected;
21925
22126
  }
21926
22127
  function requireAcceptedGateStatus(args, filePath) {
21927
22128
  if (args === void 0 || typeof args.status !== "string" || args.status.trim() === "") {
@@ -21953,8 +22154,12 @@ function requireAcceptedGateSpan(rows, filePath) {
21953
22154
  }
21954
22155
  async function classifyAuditorVolume(filePath) {
21955
22156
  const rows = await readLedgerSessionJsonl(filePath);
21956
- const call = extractLastAcceptedGateToolCall(rows);
22157
+ const call = extractLastGateToolCall(rows);
21957
22158
  if (call === void 0) return void 0;
22159
+ const attemptEntryId = extractAttemptEntryId(rows);
22160
+ if (!call.accepted) {
22161
+ return void 0;
22162
+ }
21958
22163
  const span = requireAcceptedGateSpan(rows, filePath);
21959
22164
  const status = requireAcceptedGateStatus(call.args, filePath);
21960
22165
  const findings = asStringFindings(call.args?.findings);
@@ -21980,7 +22185,8 @@ async function classifyAuditorVolume(filePath) {
21980
22185
  startedAt: span.startedAt,
21981
22186
  officer: officer2,
21982
22187
  status,
21983
- ...reason === void 0 ? {} : { reason }
22188
+ ...reason === void 0 ? {} : { reason },
22189
+ ...attemptEntryId === void 0 ? {} : { attemptEntryId }
21984
22190
  };
21985
22191
  }
21986
22192
  const officer = OFFICER_TOOL_TO_FACE[call.toolName];
@@ -21997,7 +22203,8 @@ async function classifyAuditorVolume(filePath) {
21997
22203
  status,
21998
22204
  findings,
21999
22205
  findingsCount,
22000
- officerWallMs: span.wallMs
22206
+ officerWallMs: span.wallMs,
22207
+ ...attemptEntryId === void 0 ? {} : { attemptEntryId }
22001
22208
  };
22002
22209
  }
22003
22210
  function pairGateRounds(volumes) {
@@ -22017,6 +22224,9 @@ function pairGateRounds(volumes) {
22017
22224
  const candidate = ordered[j];
22018
22225
  if (candidate.kind !== "officer") continue;
22019
22226
  if (candidate.officer !== vol.officer) continue;
22227
+ if (vol.attemptEntryId === void 0 || candidate.attemptEntryId === void 0 || candidate.attemptEntryId !== vol.attemptEntryId) {
22228
+ continue;
22229
+ }
22020
22230
  match = { index: j, officer: candidate };
22021
22231
  break;
22022
22232
  }
@@ -22031,11 +22241,28 @@ function pairGateRounds(volumes) {
22031
22241
  officerEndedAt: match.officer.endedAt,
22032
22242
  findings: match.officer.findings,
22033
22243
  findingsCount: match.officer.findingsCount,
22034
- dispatchStatus: vol.status,
22035
- ...vol.reason === void 0 ? {} : { dispatchReason: vol.reason }
22244
+ origin: {
22245
+ kind: "historical_dispatch",
22246
+ ...vol.reason === void 0 ? {} : { reason: vol.reason }
22247
+ }
22036
22248
  });
22037
22249
  }
22038
- return rounds;
22250
+ for (let i = 0; i < ordered.length; i += 1) {
22251
+ const vol = ordered[i];
22252
+ if (vol.kind !== "officer" || usedOfficerIdx.has(i)) continue;
22253
+ rounds.push({
22254
+ roundIndex: 0,
22255
+ officer: vol.officer,
22256
+ status: vol.status,
22257
+ officerWallMs: vol.officerWallMs,
22258
+ officerStartedAt: vol.startedAt,
22259
+ officerEndedAt: vol.endedAt,
22260
+ findings: vol.findings,
22261
+ findingsCount: vol.findingsCount,
22262
+ origin: { kind: "direct" }
22263
+ });
22264
+ }
22265
+ return rounds.sort((a, b) => a.officerStartedAt.localeCompare(b.officerStartedAt)).map((round, index) => ({ ...round, roundIndex: index + 1 }));
22039
22266
  }
22040
22267
  async function readAnalystGateCyclesFromAuditorRoles(auditorRolesDirectory) {
22041
22268
  let names;
@@ -22048,7 +22275,7 @@ async function readAnalystGateCyclesFromAuditorRoles(auditorRolesDirectory) {
22048
22275
  }
22049
22276
  const volumes = [];
22050
22277
  for (const name of names) {
22051
- const classified = await classifyAuditorVolume(join16(auditorRolesDirectory, name));
22278
+ const classified = await classifyAuditorVolume(join17(auditorRolesDirectory, name));
22052
22279
  if (classified !== void 0) volumes.push(classified);
22053
22280
  }
22054
22281
  return pairGateRounds(volumes);
@@ -22057,6 +22284,7 @@ var DISPATCH_TOOLS, OFFICER_TOOL_TO_FACE, OFFICER_ARG_ALIASES;
22057
22284
  var init_analyst_gate_cycles_read = __esm({
22058
22285
  "src/analyst-gate-cycles-read.ts"() {
22059
22286
  "use strict";
22287
+ init_compliance_transport();
22060
22288
  init_ledger_session_read();
22061
22289
  DISPATCH_TOOLS = /* @__PURE__ */ new Set(["ak_menxia_output", "ak_gatekeeper_output"]);
22062
22290
  OFFICER_TOOL_TO_FACE = {
@@ -22074,196 +22302,6 @@ var init_analyst_gate_cycles_read = __esm({
22074
22302
  }
22075
22303
  });
22076
22304
 
22077
- // src/auditor-dossier-tool.ts
22078
- var init_auditor_dossier_tool = __esm({
22079
- "src/auditor-dossier-tool.ts"() {
22080
- "use strict";
22081
- init_build();
22082
- }
22083
- });
22084
-
22085
- // src/compliance-transport.ts
22086
- function createComplianceDecisionTool(name, description) {
22087
- return { name, description, parameters: complianceDecisionSchema, async execute(_id, params) {
22088
- return { content: [{ type: "text", text: "\u5BA1\u8BA1\u51B3\u8BAE\u5DF2\u6536" }], details: params, terminate: true };
22089
- } };
22090
- }
22091
- var nonblank2, decisionGateSchema, complianceDecisionSchema, AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE, AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE;
22092
- var init_compliance_transport = __esm({
22093
- "src/compliance-transport.ts"() {
22094
- "use strict";
22095
- init_build();
22096
- init_evidence_child_executor();
22097
- init_auditor_dossier_tool();
22098
- init_sitian_facade();
22099
- nonblank2 = typebox_exports.String({ minLength: 1, pattern: "\\S" });
22100
- decisionGateSchema = typebox_exports.Object({ question: nonblank2, options: typebox_exports.Array(nonblank2, { minItems: 1 }) }, { additionalProperties: false });
22101
- complianceDecisionSchema = typebox_exports.Object({ status: typebox_exports.Unknown({ description: "pass | revise | escalate \u2014 \u5F62\u72B6\u6307\u5F15\uFF0C\u975E schema \u95F8" }), violations: typebox_exports.Array(nonblank2, { description: "\u89C2\u5BDF\u5230\u7684\u5408\u89C4\u8FDD\u89C4" }), conflicts: typebox_exports.Array(nonblank2, { description: "\u672A\u51B3\u6743\u5A01\u6216\u6267\u884C\u51B2\u7A81" }), decisionGate: typebox_exports.Union([decisionGateSchema, typebox_exports.Null()], { description: "\u5347\u7EA7\u95EE\u9898\u4E0E\u53EF\u9009\u9009\u9879" }) }, { additionalProperties: true, required: [] });
22102
- AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE = "ak_auditor_parent_attempt_binding";
22103
- AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE = "ak_auditor_compliance_failure";
22104
- }
22105
- });
22106
-
22107
- // src/engine-detour-tool.ts
22108
- var engineDetourArgsSchema;
22109
- var init_engine_detour_tool = __esm({
22110
- "src/engine-detour-tool.ts"() {
22111
- "use strict";
22112
- init_build();
22113
- init_engine_detour();
22114
- engineDetourArgsSchema = typebox_exports.Object(
22115
- {
22116
- argv: typebox_exports.Array(typebox_exports.String({ minLength: 1 }), {
22117
- minItems: 1,
22118
- description: "\u9996\u9879\u4E3A PATH \u4E2D\u7684\u53EF\u6267\u884C\u6587\u4EF6\uFF0C\u5176\u4F59\u9879\u4E3A\u53C2\u6570\u3002"
22119
- })
22120
- },
22121
- { additionalProperties: false }
22122
- );
22123
- }
22124
- });
22125
-
22126
- // src/session-opening-materials.ts
22127
- import { existsSync as existsSync6 } from "node:fs";
22128
- import { dirname as dirname8, join as join17 } from "node:path";
22129
- import { fileURLToPath, pathToFileURL as pathToFileURL2 } from "node:url";
22130
- function resolvePackageRootDir(moduleUrl = import.meta.url) {
22131
- let dir = dirname8(fileURLToPath(moduleUrl));
22132
- for (let i = 0; i < 8; i += 1) {
22133
- if (existsSync6(join17(dir, "package.json")) && existsSync6(join17(dir, "souls"))) {
22134
- return dir;
22135
- }
22136
- const parent = dirname8(dir);
22137
- if (parent === dir) break;
22138
- dir = parent;
22139
- }
22140
- return fileURLToPath(new URL("..", moduleUrl));
22141
- }
22142
- var packageRootUrl, MAIN_ROLE_SESSION_MATERIALS, GATEKEEPER_SESSION_MATERIALS;
22143
- var init_session_opening_materials = __esm({
22144
- "src/session-opening-materials.ts"() {
22145
- "use strict";
22146
- init_packaged_role_registry();
22147
- packageRootUrl = pathToFileURL2(resolvePackageRootDir() + "/").href;
22148
- MAIN_ROLE_SESSION_MATERIALS = {
22149
- ...Object.fromEntries(
22150
- PUBLIC_ROLE_RECORDS.map((record4) => [record4.role, record4.sessionMaterials])
22151
- )
22152
- };
22153
- GATEKEEPER_SESSION_MATERIALS = {
22154
- // #639: single authority — the public gatekeeper record owns the province list.
22155
- gatekeeper: PUBLIC_ROLE_RECORDS.find((entry) => entry.role === "gatekeeper").sessionMaterials,
22156
- inspector: INSPECTOR_SESSION_MATERIALS,
22157
- notary: NOTARY_SESSION_MATERIALS
22158
- };
22159
- }
22160
- });
22161
-
22162
- // src/navigator-session-contracts.ts
22163
- var navigatorProviderFailureSchema;
22164
- var init_navigator_session_contracts = __esm({
22165
- "src/navigator-session-contracts.ts"() {
22166
- "use strict";
22167
- init_build();
22168
- init_value2();
22169
- init_auditor_dossier_tool();
22170
- init_institutional_resolution();
22171
- navigatorProviderFailureSchema = typebox_exports.Object({
22172
- source: typebox_exports.Union([
22173
- typebox_exports.Literal("context"),
22174
- typebox_exports.Literal("session"),
22175
- typebox_exports.Literal("model"),
22176
- typebox_exports.Literal("thinking"),
22177
- typebox_exports.Literal("auth"),
22178
- typebox_exports.Literal("quota"),
22179
- typebox_exports.Literal("transport"),
22180
- typebox_exports.Literal("unknown")
22181
- ]),
22182
- cause: typebox_exports.Union([
22183
- typebox_exports.Literal("context"),
22184
- typebox_exports.Literal("session"),
22185
- typebox_exports.Literal("model"),
22186
- typebox_exports.Literal("thinking"),
22187
- typebox_exports.Literal("auth"),
22188
- typebox_exports.Literal("quota"),
22189
- typebox_exports.Literal("transport"),
22190
- typebox_exports.Literal("unknown")
22191
- ])
22192
- }, { additionalProperties: false });
22193
- }
22194
- });
22195
-
22196
- // src/receipt-delivery-policy.ts
22197
- function isRecord11(value) {
22198
- return typeof value === "object" && value !== null && !Array.isArray(value);
22199
- }
22200
- function parseNoReceiptLifecycleFacts(input) {
22201
- if (!isRecord11(input) || typeof input.terminalToolCalled !== "boolean" || input.deliveryTurns !== RECEIPT_DELIVERY_TURN_LIMIT || input.sessionCompletion !== "settled-without-accepted-receipt" || input.acceptedReceipt !== false || typeof input.runPointer !== "string" || input.runPointer.trim() === "" || typeof input.attemptPointer !== "string" || input.attemptPointer.trim() === "" || !Array.isArray(input.rejectedReceipts) || !input.rejectedReceipts.every((item) => isRecord11(item) && typeof item.reason === "string")) {
22202
- throw new TypeError("malformed no-receipt lifecycle facts");
22203
- }
22204
- return {
22205
- terminalToolCalled: input.terminalToolCalled,
22206
- rejectedReceipts: input.rejectedReceipts.map((item) => ({
22207
- reason: item.reason,
22208
- diagnosticAvailable: item.reason.trim() !== ""
22209
- })),
22210
- deliveryTurns: RECEIPT_DELIVERY_TURN_LIMIT,
22211
- sessionCompletion: "settled-without-accepted-receipt",
22212
- runPointer: input.runPointer,
22213
- attemptPointer: input.attemptPointer,
22214
- acceptedReceipt: false
22215
- };
22216
- }
22217
- var RECEIPT_DELIVERY_TURN_LIMIT, NO_RECEIPT_LIFECYCLE_ENTRY_TYPE;
22218
- var init_receipt_delivery_policy = __esm({
22219
- "src/receipt-delivery-policy.ts"() {
22220
- "use strict";
22221
- RECEIPT_DELIVERY_TURN_LIMIT = 2;
22222
- NO_RECEIPT_LIFECYCLE_ENTRY_TYPE = "ak-no-receipt-lifecycle";
22223
- }
22224
- });
22225
-
22226
- // src/upstream-error-testimony.ts
22227
- function isNonSuccessHttpStatus(status) {
22228
- return typeof status === "number" && (status < 200 || status >= 300);
22229
- }
22230
- function hasUpstreamErrorTestimony(input) {
22231
- if (isNonSuccessHttpStatus(input.httpStatus)) return true;
22232
- return Array.isArray(input.diagnostics) && input.diagnostics.length > 0;
22233
- }
22234
- function projectConfirmedRemotePayload(input) {
22235
- return {
22236
- ...input.body === void 0 ? {} : { body: input.body },
22237
- ...input.code === void 0 ? {} : { code: input.code },
22238
- ...input.errno === void 0 ? {} : { errno: input.errno }
22239
- };
22240
- }
22241
- var init_upstream_error_testimony = __esm({
22242
- "src/upstream-error-testimony.ts"() {
22243
- "use strict";
22244
- }
22245
- });
22246
-
22247
- // src/evidence-child-executor.ts
22248
- var init_evidence_child_executor = __esm({
22249
- "src/evidence-child-executor.ts"() {
22250
- "use strict";
22251
- init_compliance_transport();
22252
- init_auditor_dossier_tool();
22253
- init_sitian_facade();
22254
- init_engine_detour_tool();
22255
- init_engine_detour();
22256
- init_engine_material();
22257
- init_session_opening_materials();
22258
- init_config2();
22259
- init_institutional_resolution();
22260
- init_navigator_session_contracts();
22261
- init_receipt_delivery_policy();
22262
- init_typed_provider_http();
22263
- init_upstream_error_testimony();
22264
- }
22265
- });
22266
-
22267
22305
  // src/gatekeeper-role.ts
22268
22306
  var officerDecisionSchema, MISSING_ARGUMENTS_SUBMISSION;
22269
22307
  var init_gatekeeper_role = __esm({
@@ -23549,9 +23587,9 @@ function formatTerminalResult(result2) {
23549
23587
  `gate ${encodeTerminalField(result2.gate.actualSeats.join(","))} ${result2.gate.rounds.length}`
23550
23588
  );
23551
23589
  for (const round of result2.gate.rounds) {
23552
- const reason = round.dispatch.reason === void 0 ? "" : encodeTerminalField(round.dispatch.reason);
23590
+ const reason = round.dispatch.kind === "historical_dispatch" && round.dispatch.reason !== void 0 ? encodeTerminalField(round.dispatch.reason) : "";
23553
23591
  lines.push(
23554
- `gate-round ${round.roundIndex} ${round.dispatch.status} ${round.dispatch.officer} ${reason} ${round.officer.seat} ${encodeTerminalField(round.officer.status)} ${encodeTerminalField(JSON.stringify(round.officer.findings))}`
23592
+ `gate-round ${round.roundIndex} ${round.dispatch.kind} ${round.dispatch.officer} ${reason} ${round.officer.seat} ${encodeTerminalField(round.officer.status)} ${encodeTerminalField(JSON.stringify(round.officer.findings))}`
23555
23593
  );
23556
23594
  }
23557
23595
  }
@@ -24696,8 +24734,10 @@ function parseNavigatorAttendanceDetails(details) {
24696
24734
  function projectTerminalGateFact(rounds) {
24697
24735
  if (rounds.length === 0) return void 0;
24698
24736
  const seen = /* @__PURE__ */ new Set();
24699
- seen.add("gatekeeper");
24700
- for (const round of rounds) seen.add(round.officer);
24737
+ for (const round of rounds) {
24738
+ if (round.origin.kind === "historical_dispatch") seen.add("gatekeeper");
24739
+ seen.add(round.officer);
24740
+ }
24701
24741
  const actualSeats = ["gatekeeper", "inspector", "notary"].filter(
24702
24742
  (seat) => seen.has(seat)
24703
24743
  );
@@ -24705,10 +24745,10 @@ function projectTerminalGateFact(rounds) {
24705
24745
  actualSeats,
24706
24746
  rounds: rounds.map((round) => ({
24707
24747
  roundIndex: round.roundIndex,
24708
- dispatch: {
24709
- status: round.dispatchStatus,
24748
+ dispatch: round.origin.kind === "direct" ? { kind: "direct", officer: round.officer } : {
24749
+ kind: "historical_dispatch",
24710
24750
  officer: round.officer,
24711
- ...round.dispatchReason === void 0 ? {} : { reason: round.dispatchReason }
24751
+ ...round.origin.reason === void 0 ? {} : { reason: round.origin.reason }
24712
24752
  },
24713
24753
  officer: {
24714
24754
  seat: round.officer,
@@ -24930,14 +24970,6 @@ async function readLawfulJudgeRoleOutcome(admitted, authority) {
24930
24970
  }
24931
24971
  return auditEscalationLedgerOutcome(admitted, "judge", authority);
24932
24972
  }
24933
- async function hasLawfulJudgeTerminalResult(admitted, authority) {
24934
- try {
24935
- const outcome = await readLawfulJudgeRoleOutcome(admitted, authority);
24936
- return outcome !== void 0 && isLawfulTypedTerminalOutcome(outcome);
24937
- } catch {
24938
- return false;
24939
- }
24940
- }
24941
24973
  async function settleLawfulJudgeTerminalResult(admitted, authority) {
24942
24974
  const roleOutcome = await readLawfulJudgeRoleOutcome(admitted, authority);
24943
24975
  if (roleOutcome === void 0) return void 0;
@@ -25563,25 +25595,9 @@ async function trySettleNavigatorTerminalResult(admitted, authority) {
25563
25595
  async function trySettleCoderTerminalResult(admitted, authority, options = {}) {
25564
25596
  return settleLawfulCoderTerminalResult(admitted, authority, options);
25565
25597
  }
25566
- async function hasLawfulCoderTerminalResult(admitted, authority) {
25567
- try {
25568
- const outcome = await sealedLedgerOutcome(admitted);
25569
- return outcome?.role === "coder";
25570
- } catch {
25571
- return false;
25572
- }
25573
- }
25574
25598
  async function trySettleFixerTerminalResult(admitted, authority, options) {
25575
25599
  return settleLawfulFixerTerminalResult(admitted, authority, options);
25576
25600
  }
25577
- async function hasLawfulFixerTerminalResult(admitted, authority) {
25578
- try {
25579
- const outcome = await sealedLedgerOutcome(admitted);
25580
- return outcome?.role === "fixer";
25581
- } catch {
25582
- return false;
25583
- }
25584
- }
25585
25601
  function extractReviewerMethodInvocations(entries, options) {
25586
25602
  const observed = [];
25587
25603
  for (const entry of entries) {
@@ -25697,14 +25713,6 @@ async function settleLawfulReviewerTerminalResult(admitted, authority, options)
25697
25713
  async function trySettleReviewerTerminalResult(admitted, authority, options) {
25698
25714
  return settleLawfulReviewerTerminalResult(admitted, authority, options);
25699
25715
  }
25700
- async function hasLawfulReviewerTerminalResult(admitted, authority) {
25701
- try {
25702
- const outcome = await sealedLedgerOutcome(admitted);
25703
- return outcome?.role === "reviewer";
25704
- } catch {
25705
- return false;
25706
- }
25707
- }
25708
25716
  function mergerDecisiveFacts(output) {
25709
25717
  const candidate = output;
25710
25718
  const facts = {};
@@ -25862,14 +25870,6 @@ async function settleLawfulMergerTerminalResult(admitted, authority, options) {
25862
25870
  async function trySettleMergerTerminalResult(admitted, authority, options) {
25863
25871
  return settleLawfulMergerTerminalResult(admitted, authority, options);
25864
25872
  }
25865
- async function hasLawfulMergerTerminalResult(admitted, authority) {
25866
- try {
25867
- const outcome = await sealedLedgerOutcome(admitted);
25868
- return outcome?.role === "merger";
25869
- } catch {
25870
- return false;
25871
- }
25872
- }
25873
25873
  function publicationAttemptFromError(path, error) {
25874
25874
  if (error instanceof Error) {
25875
25875
  const identity = {
@@ -26764,13 +26764,9 @@ async function presentControlledFailure2(admitted, failureInput, adapters, autho
26764
26764
  });
26765
26765
  let resumable = false;
26766
26766
  const typedHttp429 = resumeObservation.typedHttp429;
26767
- if (adapters.isResumableRole === true && admitted.principal !== void 0) {
26767
+ if (admitted.principal !== void 0) {
26768
26768
  const sessionPrincipalAvailable = await authority.isAvailable(admitted.principal);
26769
- const hasLawful = adapters.hasLawfulTerminalResult !== void 0 ? await adapters.hasLawfulTerminalResult(admitted, authority) : false;
26770
- resumable = sessionPrincipalAvailable && isV1ResumableFailure({
26771
- hasLawfulTerminalResult: hasLawful,
26772
- ...typedHttp429 === void 0 ? {} : { typedHttp429 }
26773
- });
26769
+ resumable = sessionPrincipalAvailable && typedHttp429 !== void 0;
26774
26770
  }
26775
26771
  if (resumable && typedHttp429 !== void 0) {
26776
26772
  await markRunResumable(admitted.runDirectory, typedHttp429);
@@ -27138,9 +27134,7 @@ function coderAdapters(methodProvenance) {
27138
27134
  return {
27139
27135
  trySettle: (admitted, authority) => trySettleCoderTerminalResult(admitted, authority, {
27140
27136
  ...methodProvenance === void 0 ? {} : { methodProvenance }
27141
- }),
27142
- hasLawfulTerminalResult: (admitted, authority) => hasLawfulCoderTerminalResult(admitted, authority),
27143
- isResumableRole: true
27137
+ })
27144
27138
  };
27145
27139
  }
27146
27140
  async function runPublicCoder(argv, env, io, parseCoderArgv2) {
@@ -29368,9 +29362,7 @@ function fixerAdapters(packageRoot2, methodMaterial) {
29368
29362
  packageRoot2,
29369
29363
  "diagnosing-bugs"
29370
29364
  )
29371
- }),
29372
- hasLawfulTerminalResult: (admitted, authority) => hasLawfulFixerTerminalResult(admitted, authority),
29373
- isResumableRole: true
29365
+ })
29374
29366
  };
29375
29367
  }
29376
29368
  async function loadFixerMethodMaterial(packageRoot2) {
@@ -29728,8 +29720,6 @@ function buildJudgeTurnRequest(admitted, options) {
29728
29720
  function judgeAdapters() {
29729
29721
  return {
29730
29722
  trySettle: (admitted, authority) => trySettleJudgeTerminalResult(admitted, authority),
29731
- hasLawfulTerminalResult: (admitted, authority) => hasLawfulJudgeTerminalResult(admitted, authority),
29732
- isResumableRole: true,
29733
29723
  resolveRunnerKnownFailure: async ({ result: result2, sessionFile }) => {
29734
29724
  const infrastructureFailure = await readEngineDetourInfrastructureFailure(sessionFile);
29735
29725
  return result2.knownFailure ?? (infrastructureFailure === void 0 ? void 0 : {
@@ -29866,9 +29856,7 @@ function mergerAdapters(packageRoot2, methodMaterial) {
29866
29856
  "resolving-merge-conflicts"
29867
29857
  )
29868
29858
  }),
29869
- shouldPresentSettled: (t) => isLawfulTypedTerminalOutcome(t.roleOutcome) || t.roleOutcome.kind === "incomplete",
29870
- hasLawfulTerminalResult: (admitted, authority) => hasLawfulMergerTerminalResult(admitted, authority),
29871
- isResumableRole: true
29859
+ shouldPresentSettled: (t) => isLawfulTypedTerminalOutcome(t.roleOutcome) || t.roleOutcome.kind === "incomplete"
29872
29860
  };
29873
29861
  }
29874
29862
  async function loadMergerMethodMaterial(packageRoot2) {
@@ -30152,8 +30140,6 @@ function reviewerAdapters(packageRoot2, methodMaterial) {
30152
30140
  "code-review"
30153
30141
  )
30154
30142
  }),
30155
- hasLawfulTerminalResult: (admitted, authority) => hasLawfulReviewerTerminalResult(admitted, authority),
30156
- isResumableRole: true,
30157
30143
  resolveRunnerKnownFailure: async ({ result: result2, sessionFile }) => {
30158
30144
  const infrastructureFailure = await readEngineDetourInfrastructureFailure(sessionFile);
30159
30145
  return infrastructureFailure === void 0 ? result2.knownFailure : {
@@ -31543,7 +31529,8 @@ function projectRound(round) {
31543
31529
  officer: round.officer,
31544
31530
  status: round.status,
31545
31531
  officerWallMs: round.officerWallMs,
31546
- findingsCount: round.findingsCount
31532
+ findingsCount: round.findingsCount,
31533
+ origin: round.origin
31547
31534
  };
31548
31535
  }
31549
31536
  function projectLeg(facts) {