@akagilnc/pi-workflow-roles 0.1.3932 → 0.1.3975

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/CLAUDE.md +1 -1
  2. package/dist/acp-host/production-host.js +2389 -6018
  3. package/dist/analyst-gate-cycles-read.js +15 -19
  4. package/dist/audit-escalation.js +16 -46
  5. package/dist/auditor-dossier-tool.js +7 -62
  6. package/dist/collector-identity.js +0 -157
  7. package/dist/collector-ledger.js +2 -42
  8. package/dist/compliance-transport.js +40 -14
  9. package/dist/diarist-contracts.js +2 -40
  10. package/dist/doctor-contracts.js +39 -108
  11. package/dist/doctor-evidence.js +1 -5
  12. package/dist/engine-detour-tool.js +1 -1
  13. package/dist/gatekeeper-role.js +49 -38
  14. package/dist/headless-host/production-host.js +4814 -8450
  15. package/dist/host-contracts.js +0 -5
  16. package/dist/merger-contracts.js +4 -6
  17. package/dist/navigator-attendance.js +30 -52
  18. package/dist/navigator-invocation-identity.js +0 -1
  19. package/dist/navigator-public-session.js +2 -1
  20. package/dist/notary-contracts.js +4 -10
  21. package/dist/package-contracts/auditor-output.js +5 -23
  22. package/dist/package-contracts/fixer-output.js +25 -49
  23. package/dist/package-contracts/gatekeeper-output.js +3 -13
  24. package/dist/package-contracts/navigator-output.js +4 -7
  25. package/dist/package-contracts/reviewer-output.js +1 -95
  26. package/dist/package-contracts/terminating-tools.js +33 -144
  27. package/dist/package-contracts/worker-output.js +1 -3
  28. package/dist/public-cli/auto-resume.js +30 -68
  29. package/dist/public-cli/case-dossier-delivery.js +5 -17
  30. package/dist/public-cli/diarist-run.js +9 -4
  31. package/dist/public-cli/inspector-run.js +2 -8
  32. package/dist/public-cli/instruction-seat-run.js +3 -7
  33. package/dist/public-cli/invocation.js +5 -2
  34. package/dist/public-cli/main.js +6068 -6964
  35. package/dist/public-cli/notary-run.js +1 -8
  36. package/dist/public-cli/post-admission.js +314 -113
  37. package/dist/public-cli/run-lifecycle.js +14 -38
  38. package/dist/public-cli/settlement.js +209 -390
  39. package/dist/public-cli/terminal.js +51 -45
  40. package/dist/public-role-summons.js +1 -12
  41. package/dist/reviewer-dispatch.js +12 -258
  42. package/dist/submission-correctable-error.js +0 -12
  43. package/dist/submission-errors.js +6 -1
  44. package/dist/submission-ledger.js +125 -168
  45. package/dist/ticket-provenance-contracts.js +2 -49
  46. package/dist/ticket-provenance.js +82 -31
  47. package/extensions/role-runtime.ts +1 -6
  48. package/package.json +1 -1
  49. package/resources/836-deleted-machine-instruction-inventory.md +18 -0
  50. package/src/acp-host/role-turn-host.ts +8 -3
  51. package/src/analyst-gate-cycles-read.ts +17 -29
  52. package/src/audit-escalation.ts +20 -50
  53. package/src/auditor-dossier-tool.ts +5 -103
  54. package/src/canonical-skill-binding.ts +3 -2
  55. package/src/collector-identity.ts +0 -179
  56. package/src/collector-ledger.ts +3 -46
  57. package/src/collector-role.ts +32 -61
  58. package/src/collector-tool-schemas.ts +20 -14
  59. package/src/compliance-transport.ts +55 -17
  60. package/src/countersign-role.ts +17 -8
  61. package/src/diarist-contracts.ts +3 -36
  62. package/src/diarist-role.ts +13 -7
  63. package/src/diarist.ts +4 -16
  64. package/src/doctor-contracts.ts +73 -94
  65. package/src/doctor-evidence.ts +1 -1
  66. package/src/doctor-role.ts +3 -3
  67. package/src/engine-detour-tool.ts +4 -1
  68. package/src/external-host-turn-loop.ts +9 -3
  69. package/src/gatekeeper-pass-envelope.ts +7 -12
  70. package/src/gatekeeper-role.ts +56 -50
  71. package/src/gleaner-left-role.ts +4 -2
  72. package/src/headless-host/role-turn-host.ts +4 -5
  73. package/src/host-contracts.ts +3 -8
  74. package/src/judge-role.ts +19 -13
  75. package/src/merger-contracts.ts +10 -6
  76. package/src/merger-role.ts +1 -5
  77. package/src/navigator-attendance.ts +37 -74
  78. package/src/navigator-invocation-identity.ts +0 -6
  79. package/src/navigator-public-session.ts +2 -1
  80. package/src/notary-contracts.ts +7 -10
  81. package/src/package-contracts/auditor-output.ts +4 -21
  82. package/src/package-contracts/fixer-output.ts +34 -52
  83. package/src/package-contracts/gatekeeper-output.ts +5 -22
  84. package/src/package-contracts/navigator-output.ts +7 -7
  85. package/src/package-contracts/reviewer-output.ts +2 -150
  86. package/src/package-contracts/terminating-tools.ts +32 -147
  87. package/src/package-contracts/worker-output.ts +0 -1
  88. package/src/pi/adapter.ts +3 -8
  89. package/src/public-cli/auto-resume.ts +41 -94
  90. package/src/public-cli/case-dossier-delivery.ts +5 -15
  91. package/src/public-cli/countersign-run.ts +14 -6
  92. package/src/public-cli/diarist-run.ts +11 -9
  93. package/src/public-cli/inspector-run.ts +2 -18
  94. package/src/public-cli/instruction-seat-run.ts +3 -17
  95. package/src/public-cli/invocation.ts +5 -2
  96. package/src/public-cli/merger-run.ts +1 -1
  97. package/src/public-cli/notary-run.ts +1 -18
  98. package/src/public-cli/post-admission.ts +385 -115
  99. package/src/public-cli/run-lifecycle.ts +13 -44
  100. package/src/public-cli/settlement.ts +314 -562
  101. package/src/public-cli/terminal.ts +66 -72
  102. package/src/public-role-summons.ts +5 -30
  103. package/src/reviewer-dispatch.ts +29 -331
  104. package/src/reviewer-role.ts +16 -83
  105. package/src/role-envelope.ts +16 -24
  106. package/src/role-runtime-dependencies.ts +1 -6
  107. package/src/role-runtime.ts +65 -201
  108. package/src/submission-correctable-error.ts +0 -14
  109. package/src/submission-errors.ts +6 -1
  110. package/src/submission-ledger.ts +187 -187
  111. package/src/ticket-provenance-contracts.ts +4 -60
  112. package/src/ticket-provenance.ts +98 -32
  113. package/src/worker-role.ts +35 -36
  114. package/dist/activation-ledger-session.js +0 -105
  115. package/dist/activation-ledger.js +0 -139
  116. package/dist/activation-trace.js +0 -33
  117. package/dist/atomic-write.js +0 -23
  118. package/dist/auditor-role.js +0 -12
  119. package/dist/canonical-skill-binding.js +0 -61
  120. package/dist/collector-handbook.js +0 -142
  121. package/dist/collector-receipt.js +0 -107
  122. package/dist/collector-role.js +0 -566
  123. package/dist/collector-tool-schemas.js +0 -107
  124. package/dist/countersign-role.js +0 -28
  125. package/dist/diarist-role.js +0 -44
  126. package/dist/diarist.js +0 -66
  127. package/dist/doctor-role.js +0 -75
  128. package/dist/fixer-bash-seatbelt.js +0 -13
  129. package/dist/gatekeeper-pass-envelope.js +0 -77
  130. package/dist/gleaner-left-role.js +0 -26
  131. package/dist/inspector-role.js +0 -29
  132. package/dist/judge-role.js +0 -104
  133. package/dist/merger-role.js +0 -55
  134. package/dist/navigator-role.js +0 -12
  135. package/dist/notary-role.js +0 -134
  136. package/dist/oauth-keepalive.js +0 -158
  137. package/dist/pi/adapter.js +0 -223
  138. package/dist/reviewer-agent.js +0 -122
  139. package/dist/reviewer-child-executor.js +0 -194
  140. package/dist/reviewer-construction.js +0 -103
  141. package/dist/reviewer-execution-ledger.js +0 -166
  142. package/dist/reviewer-failure-diagnostic.js +0 -17
  143. package/dist/reviewer-role.js +0 -159
  144. package/dist/reviewer-scope-prompt.js +0 -21
  145. package/dist/reviewer-settlement.js +0 -66
  146. package/dist/reviewer-workspace.js +0 -132
  147. package/dist/role-runtime.js +0 -1604
  148. package/dist/stderr-jsonl.js +0 -26
  149. package/dist/tool-execution-observation.js +0 -141
  150. package/dist/worker-role.js +0 -345
  151. package/dist/worker-submission-gates.js +0 -305
  152. package/src/collector-receipt.ts +0 -140
  153. package/src/diagnostic-tail.ts +0 -18
  154. package/src/reviewer-agent.ts +0 -135
  155. package/src/reviewer-child-executor.ts +0 -252
  156. package/src/reviewer-construction.ts +0 -195
  157. package/src/reviewer-execution-ledger.ts +0 -212
  158. package/src/reviewer-failure-diagnostic.ts +0 -18
  159. package/src/reviewer-scope-prompt.ts +0 -24
  160. package/src/reviewer-settlement.ts +0 -74
  161. package/src/reviewer-workspace.ts +0 -105
  162. package/src/shape-unreadable-failure.ts +0 -49
@@ -18,6 +18,7 @@ import {
18
18
  type NavigatorSessionFactory,
19
19
  } from "./navigator-session-contracts.ts";
20
20
  import type { NoReceiptLifecycleFacts } from "./receipt-delivery-policy.ts";
21
+ import { lastRolePayloadRecord } from "./public-cli/terminal.ts";
21
22
 
22
23
  /**
23
24
  * Classify public-navigator failure terminal from structured decisiveFacts only
@@ -146,7 +147,7 @@ export function createNativeNavigatorSessionFactory(): NavigatorSessionFactory {
146
147
  // Not a shape-unusable judgment on the navigator reply (#757).
147
148
  return;
148
149
  }
149
- const candidates = outcome.decisiveFacts.candidates;
150
+ const candidates = lastRolePayloadRecord(outcome.payloads ?? [])?.candidates;
150
151
  if (!Array.isArray(candidates)) {
151
152
  // Accepted reply without candidates array — no advice, no judgment.
152
153
  return;
@@ -73,12 +73,10 @@ function isRecord(value: unknown): value is Record<string, unknown> {
73
73
  * no findings array rewrite). Recognition only for recording/settlement callers.
74
74
  */
75
75
  export function projectLawfulNotaryOutput(value: unknown): NotaryOutput | undefined {
76
- if (!isRecord(value)) return undefined;
77
- const status = typeof value.status === "string" ? value.status : undefined;
78
- if (status === "bounce" || status === "pass" || status === "escalate") {
79
- return value as NotaryOutput;
80
- }
81
- return undefined;
76
+ // #836: no field drop
77
+ return (typeof value === "object" && value !== null && !Array.isArray(value))
78
+ ? (value as NotaryOutput)
79
+ : undefined;
82
80
  }
83
81
 
84
82
  /** Retain submitted Notary params as-is for the failure channel (no shape rewrite). */
@@ -96,10 +94,9 @@ export function retainNotarySubmission(value: unknown): unknown {
96
94
  * Does not gate role admission — callers must not use this to reject a submission.
97
95
  */
98
96
  export function validateRecordedNotaryOutput(value: unknown): NotaryOutput {
99
- const projected = projectLawfulNotaryOutput(value);
100
- if (projected === undefined) {
101
- throw new Error("Notary output has no recognized execution discriminator");
97
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
98
+ throw new Error("Notary output is not an object");
102
99
  }
103
- return projected;
100
+ return value as NotaryOutput;
104
101
  }
105
102
 
@@ -42,30 +42,13 @@ function isRecord(value: unknown): value is Record<string, unknown> {
42
42
  return typeof value === "object" && value !== null && !Array.isArray(value);
43
43
  }
44
44
 
45
+ /** #836: no field drop — original object is the receipt. */
45
46
  export function projectLawfulAuditorOutput(value: unknown): AuditorOutput | undefined {
46
- if (!isRecord(value)) return undefined;
47
- if (value.status === "pass") return { status: "pass" };
48
- if (value.status === "bounce") {
49
- return {
50
- status: "bounce",
51
- ...(Object.hasOwn(value, "violations") ? { violations: value.violations } : {}),
52
- };
53
- }
54
- if (value.status === "escalate") {
55
- return {
56
- status: "escalate",
57
- ...(Object.hasOwn(value, "conflicts") ? { conflicts: value.conflicts } : {}),
58
- ...(Object.hasOwn(value, "decisionGate") ? { decisionGate: value.decisionGate } : {}),
59
- };
60
- }
61
- return undefined;
47
+ return isRecord(value) ? (value as AuditorOutput) : undefined;
62
48
  }
63
49
 
64
50
  export function validateRecordedAuditorOutput(value: unknown): AuditorOutput {
65
- const projected = projectLawfulAuditorOutput(value);
66
- if (projected === undefined) {
67
- throw new Error("Auditor output has no recognized execution discriminator");
68
- }
69
- return projected;
51
+ if (!isRecord(value)) throw new Error("Auditor output is not an object");
52
+ return value as AuditorOutput;
70
53
  }
71
54
 
@@ -1,45 +1,55 @@
1
1
  import { Type, type Static } from "typebox";
2
- import { FIXER_PREREQUISITE_ID_PATTERN, type FixerInvocationInput } from "./fixer-packet.ts";
3
2
  import { openToolObjectFromUnion } from "../open-tool-schema.ts";
4
3
  import { withInfrastructureFailureDeclaration } from "./terminating-infrastructure.ts";
5
4
 
6
5
  export const FIXER_OUTPUT_TOOL_NAME = "ak_fixer_output";
7
6
  export const FIXER_ACCEPTED_TEXT = "修内司回执已接受";
8
7
 
9
- const nonblankTransportString = Type.String({ minLength: 1 });
10
- const authorityBlockerSchema = Type.Object({ cause: Type.Literal("authority_violation"), evidence: nonblankTransportString });
11
- const prerequisiteBlockerSchema = Type.Object({ cause: Type.Literal("prerequisite_unmet"), prerequisiteId: Type.String({ pattern: FIXER_PREREQUISITE_ID_PATTERN }), evidence: nonblankTransportString });
8
+ // #836 r16 class 1: these are LLM/human-read narrative content — the candidate
9
+ // row lands on the ledger as submitted (src/submission-ledger.ts:351-390) and no
10
+ // code branches on its shape. Field/type/description/Literal value stay; provider
11
+ // required/minLength/minItems is deleted. `reason` alone keeps minLength: the
12
+ // worker gate reads `reason.trim().length > 0` to pick typed-reminder-bounce vs
13
+ // accept (src/worker-submission-gates.ts:159-163,297-302).
14
+ const transportString = Type.String();
15
+ const authorityBlockerSchema = Type.Object({ cause: Type.Optional(Type.Literal("authority_violation")), evidence: Type.Optional(transportString) });
16
+ const prerequisiteBlockerSchema = Type.Object({ cause: Type.Optional(Type.Literal("prerequisite_unmet")), prerequisiteId: Type.Optional(transportString), evidence: Type.Optional(transportString) });
12
17
  const blockerSchema = Type.Union([authorityBlockerSchema, prerequisiteBlockerSchema]);
13
- const exceptionSchema = Type.Object({ where: nonblankTransportString, reason: nonblankTransportString });
18
+ const exceptionSchema = Type.Object({ where: Type.Optional(transportString), reason: Type.Optional(transportString) });
14
19
  /** ⑥ test evidence slip — require submit when diff has test changes; machine does not check existence/completeness/coverage. */
15
20
  const testEvidenceSchema = Type.Object({
16
- contract: Type.String({ minLength: 1, description: "测试改动所证明的契约" }),
17
- minimumNecessaryCost: Type.String({ minLength: 1, description: "测试改动的一行最小必要成本" }),
18
- measuredDuration: Type.String({ minLength: 1, description: "聚焦验证实测时长" }),
21
+ contract: Type.Optional(Type.String({ description: "测试改动所证明的契约" })),
22
+ minimumNecessaryCost: Type.Optional(Type.String({ description: "测试改动的一行最小必要成本" })),
23
+ measuredDuration: Type.Optional(Type.String({ description: "聚焦验证实测时长" })),
19
24
  }, { description: "测试证据条;diff 含测试改动时提交;机器不核验。" });
20
25
  const completedClassResultSchema = Type.Object({
21
- name: nonblankTransportString,
22
- disposition: Type.Literal("completed"),
23
- searchScope: nonblankTransportString,
24
- exceptions: Type.Array(exceptionSchema),
25
- commitSha: nonblankTransportString,
26
+ name: Type.Optional(transportString),
27
+ disposition: Type.Optional(Type.Literal("completed")),
28
+ searchScope: Type.Optional(transportString),
29
+ exceptions: Type.Optional(Type.Array(exceptionSchema)),
30
+ commitSha: Type.Optional(transportString),
26
31
  });
27
32
  const refusedClassResultSchema = Type.Object({
28
- name: nonblankTransportString,
29
- disposition: Type.Literal("refused"),
30
- remainingScope: nonblankTransportString,
31
- blocker: blockerSchema,
33
+ name: Type.Optional(transportString),
34
+ disposition: Type.Optional(Type.Literal("refused")),
35
+ remainingScope: Type.Optional(transportString),
36
+ blocker: Type.Optional(blockerSchema),
32
37
  });
33
38
  const classResultSchema = Type.Union([completedClassResultSchema, refusedClassResultSchema]);
34
- const completedClassResultsSchema = Type.Array(completedClassResultSchema, { minItems: 1 });
39
+ const completedClassResultsSchema = Type.Array(completedClassResultSchema);
35
40
 
41
+ // #836 (ADR 0003 Amendment): status kept open like countersignStatus
42
+ // (src/countersign-role.ts) — one shared description across every variant
43
+ // so openToolObjectFromUnion's identical-declaration collapse drops none of it.
44
+ const FIXER_STATUS_DESCRIPTION =
45
+ "planned | completed | refused | unfinished | partially_completed — 形状指引,非 schema 闸;unfinished 缺前置或违宪约束致本局未完成时可用,缺待决 owner 决定或答复属缺前置。" as const;
36
46
  const fixerOutputVariants = Type.Union([
37
- Type.Object({ status: Type.Literal("planned", { description: "planned — 形状指引,非 schema 闸" }), report: Type.String({ minLength: 1, description: "如实结果报告" }) }),
38
- Type.Object({ status: Type.Literal("refused", { description: "refused — 形状指引,非 schema 闸" }), report: Type.String({ minLength: 1, description: "如实结果报告" }), remainingScope: Type.String({ minLength: 1, description: "依法不能完成的工作范围" }), blocker: Type.Unsafe({ ...blockerSchema, description: "合法阻断完成的 blocker" }) }),
39
- Type.Object({ status: Type.Literal("unfinished", { description: "unfinished — 形状指引,非 schema 闸;缺前置或违宪约束致本局未完成时可用。缺待决 owner 决定或答复属缺前置。" }), report: Type.String({ minLength: 1, description: "如实结果报告" }), remainingScope: Type.String({ minLength: 1, description: "本局后剩余工作" }), reason: Type.Optional(Type.String({ minLength: 1, description: "阻断原因:缺前置或违宪约束。缺待决 owner 决定或答复属缺前置。" })), classResults: Type.Optional(Type.Unsafe({ ...completedClassResultsSchema, description: "本局已完成的 class 结算" })), testEvidence: Type.Optional(testEvidenceSchema) }),
40
- Type.Object({ status: Type.Literal("completed", { description: "completed — 形状指引,非 schema 闸" }), report: Type.String({ minLength: 1, description: "如实结果报告" }), classResults: Type.Array(classResultSchema, { minItems: 1, description: "已完成的 class 结算" }), testEvidence: Type.Optional(testEvidenceSchema) }),
41
- Type.Object({ status: Type.Literal("refused", { description: "refused — 形状指引,非 schema 闸" }), report: Type.String({ minLength: 1, description: "如实结果报告" }), classResults: Type.Array(classResultSchema, { minItems: 1, description: "各类拒绝结算" }) }),
42
- Type.Object({ status: Type.Literal("partially_completed", { description: "partially_completed — 形状指引,非 schema 闸" }), report: Type.String({ minLength: 1, description: "如实结果报告" }), classResults: Type.Array(classResultSchema, { minItems: 1, description: "各类完成或拒绝结算" }), testEvidence: Type.Optional(testEvidenceSchema) }),
47
+ Type.Object({ status: Type.Unknown({ description: FIXER_STATUS_DESCRIPTION }), report: Type.String({ description: "如实结果报告" }) }),
48
+ Type.Object({ status: Type.Unknown({ description: FIXER_STATUS_DESCRIPTION }), report: Type.String({ description: "如实结果报告" }), remainingScope: Type.String({ description: "依法不能完成的工作范围" }), blocker: Type.Unsafe({ ...blockerSchema, description: "合法阻断完成的 blocker" }) }),
49
+ Type.Object({ status: Type.Unknown({ description: FIXER_STATUS_DESCRIPTION }), report: Type.String({ description: "如实结果报告" }), remainingScope: Type.String({ description: "本局后剩余工作" }), reason: Type.Optional(Type.String({ minLength: 1, description: "阻断原因:缺前置或违宪约束。缺待决 owner 决定或答复属缺前置。" })), classResults: Type.Optional(Type.Unsafe({ ...completedClassResultsSchema, description: "本局已完成的 class 结算" })), testEvidence: Type.Optional(testEvidenceSchema) }),
50
+ Type.Object({ status: Type.Unknown({ description: FIXER_STATUS_DESCRIPTION }), report: Type.String({ description: "如实结果报告" }), classResults: Type.Array(classResultSchema, { description: "已完成的 class 结算" }), testEvidence: Type.Optional(testEvidenceSchema) }),
51
+ Type.Object({ status: Type.Unknown({ description: FIXER_STATUS_DESCRIPTION }), report: Type.String({ description: "如实结果报告" }), classResults: Type.Array(classResultSchema, { description: "各类拒绝结算" }) }),
52
+ Type.Object({ status: Type.Unknown({ description: FIXER_STATUS_DESCRIPTION }), report: Type.String({ description: "如实结果报告" }), classResults: Type.Array(classResultSchema, { description: "各类完成或拒绝结算" }), testEvidence: Type.Optional(testEvidenceSchema) }),
43
53
  ]);
44
54
  export const fixerOutputSchema = withInfrastructureFailureDeclaration(
45
55
  openToolObjectFromUnion(fixerOutputVariants),
@@ -54,31 +64,3 @@ export type FixerPhase = "plan" | "apply";
54
64
  export function validateFixerOutput(value: unknown, _phase?: FixerPhase): FixerOutput {
55
65
  return value as FixerOutput;
56
66
  }
57
-
58
- function safeProperty(value: unknown, property: string): unknown {
59
- if (value === null || typeof value !== "object") return undefined;
60
- try {
61
- return (value as Record<string, unknown>)[property];
62
- } catch {
63
- return undefined;
64
- }
65
- }
66
-
67
- /** Bind recognizable prerequisite blockers to the packet declaration. */
68
- export function validateFixerOutputForPacket(value: unknown, phase: FixerPhase, packet: FixerInvocationInput): FixerOutput {
69
- const output = validateFixerOutput(value, phase);
70
- const declaredIds = new Set(packet.prerequisites.map((entry) => entry.id));
71
- const topLevelBlocker = safeProperty(output, "blocker");
72
- const classResults = safeProperty(output, "classResults");
73
- const blockers = topLevelBlocker === undefined
74
- ? (Array.isArray(classResults) ? classResults.map((entry) => safeProperty(entry, "blocker")) : [])
75
- : [topLevelBlocker];
76
- for (const blocker of blockers) {
77
- if (safeProperty(blocker, "cause") !== "prerequisite_unmet") continue;
78
- const prerequisiteId = safeProperty(blocker, "prerequisiteId");
79
- if (typeof prerequisiteId === "string" && !declaredIds.has(prerequisiteId)) {
80
- throw new Error("Fixer output violates blocker.prerequisiteId declared-prerequisite constraint");
81
- }
82
- }
83
- return output;
84
- }
@@ -48,31 +48,14 @@ function asStringArray(value: unknown): readonly string[] {
48
48
  * No throw on shape — ADR 0055 / 第 0 条: already-submitted params are retained as-is;
49
49
  * public-terminal projects non-usable releases via typed failure cause.
50
50
  */
51
+ /** #836: no field drop — original object is the receipt. */
51
52
  export function projectLawfulGatekeeperOutput(value: unknown): GatekeeperDirectOutput | undefined {
52
- if (!isRecord(value)) return undefined;
53
- if (value.status === "pass") {
54
- return Array.isArray(value.findings)
55
- ? { status: "pass", findings: asStringArray(value.findings) }
56
- : { status: "pass" };
57
- }
58
- if (
59
- value.status === "dispatch" &&
60
- (value.officer === "inspector" || value.officer === "notary")
61
- ) {
62
- return { status: "dispatch", officer: value.officer };
63
- }
64
- return undefined;
53
+ return isRecord(value) ? (value as GatekeeperDirectOutput) : undefined;
65
54
  }
66
55
 
67
- /**
68
- * Settlement/recording path: only lawful recorded dispatch/pass.
69
- * Does not gate role admission — callers must not use this to reject a submission.
70
- */
56
+ /** #836: no status allowlist rejection — pass object through. */
71
57
  export function validateRecordedGatekeeperOutput(value: unknown): GatekeeperDirectOutput {
72
- const projected = projectLawfulGatekeeperOutput(value);
73
- if (projected === undefined) {
74
- throw new Error("Gatekeeper output has no recognized execution discriminator");
75
- }
76
- return projected;
58
+ if (!isRecord(value)) throw new Error("Gatekeeper output is not an object");
59
+ return value as GatekeeperDirectOutput;
77
60
  }
78
61
 
@@ -37,9 +37,10 @@ export type NavigatorAdvice = { readonly status: "advice"; readonly candidates:
37
37
  * shape is not an admission gate (ADR 0055 / 第 0 条).
38
38
  */
39
39
  export function projectLawfulNavigatorOutput(value: unknown): NavigatorAdvice | undefined {
40
- if (!isRecord(value) || !Array.isArray(value.candidates)) return undefined;
41
- if (value.status !== "advice") return undefined;
42
- return { status: "advice", candidates: value.candidates.filter(isRecord) };
40
+ // #836: no field drop
41
+ return (typeof value === "object" && value !== null && !Array.isArray(value))
42
+ ? (value as NavigatorAdvice)
43
+ : undefined;
43
44
  }
44
45
 
45
46
  /**
@@ -47,10 +48,9 @@ export function projectLawfulNavigatorOutput(value: unknown): NavigatorAdvice |
47
48
  * Does not gate role admission — callers must not use this to reject a submission.
48
49
  */
49
50
  export function validateRecordedNavigatorOutput(value: unknown): NavigatorAdvice {
50
- const projected = projectLawfulNavigatorOutput(value);
51
- if (projected === undefined) {
52
- throw new Error("Navigator output has no recognized execution discriminator");
51
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
52
+ throw new Error("Navigator output is not an object");
53
53
  }
54
- return projected;
54
+ return value as NavigatorAdvice;
55
55
  }
56
56
 
@@ -1,6 +1,4 @@
1
- /** Package-owned Reviewer intent and runtime-receipt leaves — no role registration surface. */
2
-
3
- import type { ReviewerAcceptedEvidence, ReviewerFailureClassification, ReviewerWorkspaceDisposition } from "../reviewer-execution-ledger.ts";
1
+ /** Package-owned Reviewer intent — original role payload only (#836 删 8). */
4
2
 
5
3
  export const REVIEWER_OUTPUT_TOOL_NAME = "ak_reviewer_output";
6
4
  export const REVIEWER_ACCEPTED_TEXT = "御史台回执已接受";
@@ -10,153 +8,7 @@ export type ReviewerAmendments = Readonly<Partial<Record<"standards" | "spec", s
10
8
  export type ReviewerIntent =
11
9
  | Readonly<{ status: "completed"; amendments?: ReviewerAmendments }>
12
10
  | Readonly<{ status: "refused"; diagnostic: string; amendments?: ReviewerAmendments }>;
13
- /** Child report body retained as delivered — no type/blank reshape (ADR 0031 / 0055 / #675). */
14
- export type VerbatimChildReport = Readonly<{ text: unknown }>;
15
- /** Prompt projection on the receipt face is plain text (ADR 0031). */
16
- export type ReviewerReceiptPrompt = Readonly<{ text: string }>;
17
- /** Canonical Skill content on the receipt face is plain text (ADR 0031/0032). */
18
- export type ReviewerReceiptSkillContent = Readonly<{ text: string }>;
19
- type RuntimeReviewerOutcomeCommon = Readonly<{
20
- prompt: ReviewerReceiptPrompt;
21
- workspaceDisposition: ReviewerWorkspaceDisposition;
22
- }>;
23
- export type RuntimeReviewerOutcome = RuntimeReviewerOutcomeCommon & (
24
- | Readonly<{ status: "successful"; failure?: never }>
25
- | Readonly<{ status: "failed"; failure: ReviewerFailureClassification; diagnostic: string }>
26
- );
27
- export type RuntimeReviewerAcceptedBatch = Readonly<{
28
- identity: string;
29
- legs: readonly Readonly<{ axis: "standards" | "spec"; prompt: ReviewerReceiptPrompt }>[];
30
- }>;
31
- /** Honest Spec-child disposition on the receipt face. */
32
- export type RuntimeReviewerSpecDisposition = "launched" | "skipped-missing";
33
- export type RuntimeReviewerReceiptV2 = Readonly<{
34
- version: 2;
35
- status: "completed" | "refused";
36
- diagnostic?: string;
37
- acceptedBatch?: RuntimeReviewerAcceptedBatch;
38
- /** Present on accepted batches: launched Spec child, or skipped after confirmed missing Spec. */
39
- specDisposition?: RuntimeReviewerSpecDisposition;
40
- /** Self-fetch bytes + source annotation when Spec primary path produced material (#343). */
41
- specFetchedMaterial?: ReviewerAcceptedEvidence["specFetchedMaterial"];
42
- reports: Readonly<Partial<Record<"standards" | "spec", VerbatimChildReport>>>;
43
- /** Seat-owned per-axis deltas; separate from runtime-owned child reports. */
44
- amendments?: ReviewerAmendments;
45
- outcomes: Readonly<Partial<Record<"standards" | "spec", RuntimeReviewerOutcome>>>;
46
- identities: Readonly<{
47
- canonicalSkill: ReviewerReceiptSkillContent;
48
- construction?: Readonly<{ recipe: ReviewerAcceptedEvidence["recipe"] }>;
49
- target?: ReviewerAcceptedEvidence["target"];
50
- }>;
51
- }>;
52
-
53
- function isRecord(value: unknown): value is Record<string, unknown> {
54
- return typeof value === "object" && value !== null && !Array.isArray(value);
55
- }
56
- function read(value: unknown, key: string): unknown {
57
- if (!isRecord(value)) return undefined;
58
- try { return value[key]; } catch { return undefined; }
59
- }
60
-
61
- /** Canonical per-axis string slots only — no shape reject, no prose parse (ADR 0057). */
62
- function readAmendments(output: unknown): ReviewerAmendments | undefined {
63
- const amendments = read(output, "amendments");
64
- if (!isRecord(amendments)) return undefined;
65
- const slots: Partial<Record<"standards" | "spec", string>> = {};
66
- for (const axis of ["standards", "spec"] as const) {
67
- const value = read(amendments, axis);
68
- if (typeof value === "string") slots[axis] = value;
69
- }
70
- if (slots.standards === undefined && slots.spec === undefined) return undefined;
71
- return Object.freeze(slots);
72
- }
73
11
 
74
12
  export function validateReviewerIntent(output: unknown): ReviewerIntent {
75
- const status = read(output, "status");
76
- const amendments = readAmendments(output);
77
- if (status === "completed") {
78
- return amendments === undefined ? { status } : { status, amendments };
79
- }
80
- if (status === "refused") {
81
- return amendments === undefined
82
- ? { status, diagnostic: read(output, "diagnostic") as string }
83
- : { status, diagnostic: read(output, "diagnostic") as string, amendments };
84
- }
85
- throw new Error("Reviewer output has no recognized execution intent");
86
- }
87
-
88
- /** Validate runtime-owned facts at their real identity seams (target pins + plain text). */
89
- export function validateRuntimeReviewerReceipt(output: unknown): RuntimeReviewerReceiptV2 {
90
- const status = read(output, "status");
91
- const acceptedBatch = read(output, "acceptedBatch");
92
- const identities = read(output, "identities");
93
- const construction = read(identities, "construction");
94
- const target = read(identities, "target");
95
- const reports = read(output, "reports");
96
- const outcomes = read(output, "outcomes");
97
- const legs = read(acceptedBatch, "legs");
98
-
99
- // A recognizable accepted batch must remain bound to its exact target pin.
100
- if (acceptedBatch !== undefined || construction !== undefined || target !== undefined) {
101
- if (!isRecord(acceptedBatch) || !isRecord(construction) || !isRecord(target) || !Array.isArray(legs))
102
- throw new Error("Incomplete Reviewer accepted-batch identity");
103
- const objectFormat = read(target, "objectFormat");
104
- const objectId = (value: unknown): boolean => typeof value === "string" && new RegExp(objectFormat === "sha1" ? "^[0-9a-f]{40}$" : "^[0-9a-f]{64}$").test(value);
105
- const refs = read(target, "refs");
106
- const skillText = read(read(identities, "canonicalSkill"), "text");
107
- if (typeof skillText !== "string" ||
108
- read(construction, "recipe") !== "reviewer-common-bundle-v1" ||
109
- (objectFormat !== "sha1" && objectFormat !== "sha256") || !objectId(read(target, "targetHead")) || !isRecord(refs) ||
110
- Object.values(refs).some((ref) => !isRecord(ref) || !objectId(read(ref, "objectId")) || (read(ref, "peeledCommitId") !== null && !objectId(read(ref, "peeledCommitId")))))
111
- throw new Error("Invalid Reviewer construction or target identity");
112
-
113
- const expectedAxes = legs.map((leg) => read(leg, "axis"));
114
- if (expectedAxes[0] !== "standards" || (expectedAxes.length === 2 && expectedAxes[1] !== "spec") || expectedAxes.length < 1 || expectedAxes.length > 2)
115
- throw new Error("Invalid Reviewer accepted-leg projection");
116
- if (!isRecord(outcomes) || !isRecord(reports)) throw new Error("Accepted Reviewer batch lacks outcomes or reports");
117
- const outcomeAxes = Object.keys(outcomes).filter(axis => axis === "standards" || axis === "spec");
118
- if (outcomeAxes.length !== expectedAxes.length || outcomeAxes.some((axis, index) => axis !== expectedAxes[index]))
119
- throw new Error("Reviewer outcomes must exactly cover accepted legs in canonical order");
120
-
121
- for (const [index, axisValue] of expectedAxes.entries()) {
122
- const axis = axisValue as "standards" | "spec";
123
- const outcome = read(outcomes, axis);
124
- if (!isRecord(outcome)) throw new Error("Reviewer accepted leg lacks outcome");
125
- const expectedPrompt = read(read(legs[index], "prompt"), "text");
126
- const actualPrompt = read(read(outcome, "prompt"), "text");
127
- if (expectedPrompt !== actualPrompt) throw new Error("Reviewer outcome prompt disagrees with accepted leg");
128
- const status = read(outcome, "status");
129
- const report = read(reports, axis);
130
- if (status === "successful" && report === undefined)
131
- throw new Error("Successful Reviewer outcome lacks report");
132
- if (status === "failed" && report !== undefined) throw new Error("Failed Reviewer outcome cannot bind a report");
133
- }
134
-
135
- // One read inside the existing accepted-leg consistency cycle — not a second validator.
136
- // launched ⇔ Standards+Spec; skipped-missing ⇔ Standards only.
137
- const specDisposition = read(output, "specDisposition");
138
- if (specDisposition === "launched") {
139
- if (expectedAxes.length !== 2 || expectedAxes[0] !== "standards" || expectedAxes[1] !== "spec") {
140
- throw new Error("Reviewer specDisposition launched requires Standards+Spec accepted legs");
141
- }
142
- } else if (specDisposition === "skipped-missing") {
143
- if (expectedAxes.length !== 1 || expectedAxes[0] !== "standards") {
144
- throw new Error("Reviewer specDisposition skipped-missing requires Standards-only accepted legs");
145
- }
146
- } else if (specDisposition !== undefined) {
147
- throw new Error("Invalid Reviewer specDisposition");
148
- }
149
- }
150
- return output as RuntimeReviewerReceiptV2;
151
- }
152
-
153
- /** Project thin submitted intent onto runtime enrichment without comparing runtime-owned fields. */
154
- export function projectReviewerIntentToReceipt(intentValue: unknown, receiptValue: unknown): RuntimeReviewerReceiptV2 {
155
- const intent = validateReviewerIntent(intentValue);
156
- const receipt = validateRuntimeReviewerReceipt(receiptValue);
157
- const receiptStatus = String(receipt.status);
158
- if (receiptStatus !== intent.status || (intent.status === "completed" ? receipt.diagnostic !== undefined : receipt.diagnostic !== intent.diagnostic)) {
159
- throw new Error("Reviewer intent and runtime receipt disagree");
160
- }
161
- return receipt;
13
+ return output as ReviewerIntent;
162
14
  }