@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.
- package/CLAUDE.md +1 -1
- package/dist/acp-host/production-host.js +2389 -6018
- package/dist/analyst-gate-cycles-read.js +15 -19
- package/dist/audit-escalation.js +16 -46
- package/dist/auditor-dossier-tool.js +7 -62
- package/dist/collector-identity.js +0 -157
- package/dist/collector-ledger.js +2 -42
- package/dist/compliance-transport.js +40 -14
- package/dist/diarist-contracts.js +2 -40
- package/dist/doctor-contracts.js +39 -108
- package/dist/doctor-evidence.js +1 -5
- package/dist/engine-detour-tool.js +1 -1
- package/dist/gatekeeper-role.js +49 -38
- package/dist/headless-host/production-host.js +4814 -8450
- package/dist/host-contracts.js +0 -5
- package/dist/merger-contracts.js +4 -6
- package/dist/navigator-attendance.js +30 -52
- package/dist/navigator-invocation-identity.js +0 -1
- package/dist/navigator-public-session.js +2 -1
- package/dist/notary-contracts.js +4 -10
- package/dist/package-contracts/auditor-output.js +5 -23
- package/dist/package-contracts/fixer-output.js +25 -49
- package/dist/package-contracts/gatekeeper-output.js +3 -13
- package/dist/package-contracts/navigator-output.js +4 -7
- package/dist/package-contracts/reviewer-output.js +1 -95
- package/dist/package-contracts/terminating-tools.js +33 -144
- package/dist/package-contracts/worker-output.js +1 -3
- package/dist/public-cli/auto-resume.js +30 -68
- package/dist/public-cli/case-dossier-delivery.js +5 -17
- package/dist/public-cli/diarist-run.js +9 -4
- package/dist/public-cli/inspector-run.js +2 -8
- package/dist/public-cli/instruction-seat-run.js +3 -7
- package/dist/public-cli/invocation.js +5 -2
- package/dist/public-cli/main.js +6068 -6964
- package/dist/public-cli/notary-run.js +1 -8
- package/dist/public-cli/post-admission.js +314 -113
- package/dist/public-cli/run-lifecycle.js +14 -38
- package/dist/public-cli/settlement.js +209 -390
- package/dist/public-cli/terminal.js +51 -45
- package/dist/public-role-summons.js +1 -12
- package/dist/reviewer-dispatch.js +12 -258
- package/dist/submission-correctable-error.js +0 -12
- package/dist/submission-errors.js +6 -1
- package/dist/submission-ledger.js +125 -168
- package/dist/ticket-provenance-contracts.js +2 -49
- package/dist/ticket-provenance.js +82 -31
- package/extensions/role-runtime.ts +1 -6
- package/package.json +1 -1
- package/resources/836-deleted-machine-instruction-inventory.md +18 -0
- package/src/acp-host/role-turn-host.ts +8 -3
- package/src/analyst-gate-cycles-read.ts +17 -29
- package/src/audit-escalation.ts +20 -50
- package/src/auditor-dossier-tool.ts +5 -103
- package/src/canonical-skill-binding.ts +3 -2
- package/src/collector-identity.ts +0 -179
- package/src/collector-ledger.ts +3 -46
- package/src/collector-role.ts +32 -61
- package/src/collector-tool-schemas.ts +20 -14
- package/src/compliance-transport.ts +55 -17
- package/src/countersign-role.ts +17 -8
- package/src/diarist-contracts.ts +3 -36
- package/src/diarist-role.ts +13 -7
- package/src/diarist.ts +4 -16
- package/src/doctor-contracts.ts +73 -94
- package/src/doctor-evidence.ts +1 -1
- package/src/doctor-role.ts +3 -3
- package/src/engine-detour-tool.ts +4 -1
- package/src/external-host-turn-loop.ts +9 -3
- package/src/gatekeeper-pass-envelope.ts +7 -12
- package/src/gatekeeper-role.ts +56 -50
- package/src/gleaner-left-role.ts +4 -2
- package/src/headless-host/role-turn-host.ts +4 -5
- package/src/host-contracts.ts +3 -8
- package/src/judge-role.ts +19 -13
- package/src/merger-contracts.ts +10 -6
- package/src/merger-role.ts +1 -5
- package/src/navigator-attendance.ts +37 -74
- package/src/navigator-invocation-identity.ts +0 -6
- package/src/navigator-public-session.ts +2 -1
- package/src/notary-contracts.ts +7 -10
- package/src/package-contracts/auditor-output.ts +4 -21
- package/src/package-contracts/fixer-output.ts +34 -52
- package/src/package-contracts/gatekeeper-output.ts +5 -22
- package/src/package-contracts/navigator-output.ts +7 -7
- package/src/package-contracts/reviewer-output.ts +2 -150
- package/src/package-contracts/terminating-tools.ts +32 -147
- package/src/package-contracts/worker-output.ts +0 -1
- package/src/pi/adapter.ts +3 -8
- package/src/public-cli/auto-resume.ts +41 -94
- package/src/public-cli/case-dossier-delivery.ts +5 -15
- package/src/public-cli/countersign-run.ts +14 -6
- package/src/public-cli/diarist-run.ts +11 -9
- package/src/public-cli/inspector-run.ts +2 -18
- package/src/public-cli/instruction-seat-run.ts +3 -17
- package/src/public-cli/invocation.ts +5 -2
- package/src/public-cli/merger-run.ts +1 -1
- package/src/public-cli/notary-run.ts +1 -18
- package/src/public-cli/post-admission.ts +385 -115
- package/src/public-cli/run-lifecycle.ts +13 -44
- package/src/public-cli/settlement.ts +314 -562
- package/src/public-cli/terminal.ts +66 -72
- package/src/public-role-summons.ts +5 -30
- package/src/reviewer-dispatch.ts +29 -331
- package/src/reviewer-role.ts +16 -83
- package/src/role-envelope.ts +16 -24
- package/src/role-runtime-dependencies.ts +1 -6
- package/src/role-runtime.ts +65 -201
- package/src/submission-correctable-error.ts +0 -14
- package/src/submission-errors.ts +6 -1
- package/src/submission-ledger.ts +187 -187
- package/src/ticket-provenance-contracts.ts +4 -60
- package/src/ticket-provenance.ts +98 -32
- package/src/worker-role.ts +35 -36
- package/dist/activation-ledger-session.js +0 -105
- package/dist/activation-ledger.js +0 -139
- package/dist/activation-trace.js +0 -33
- package/dist/atomic-write.js +0 -23
- package/dist/auditor-role.js +0 -12
- package/dist/canonical-skill-binding.js +0 -61
- package/dist/collector-handbook.js +0 -142
- package/dist/collector-receipt.js +0 -107
- package/dist/collector-role.js +0 -566
- package/dist/collector-tool-schemas.js +0 -107
- package/dist/countersign-role.js +0 -28
- package/dist/diarist-role.js +0 -44
- package/dist/diarist.js +0 -66
- package/dist/doctor-role.js +0 -75
- package/dist/fixer-bash-seatbelt.js +0 -13
- package/dist/gatekeeper-pass-envelope.js +0 -77
- package/dist/gleaner-left-role.js +0 -26
- package/dist/inspector-role.js +0 -29
- package/dist/judge-role.js +0 -104
- package/dist/merger-role.js +0 -55
- package/dist/navigator-role.js +0 -12
- package/dist/notary-role.js +0 -134
- package/dist/oauth-keepalive.js +0 -158
- package/dist/pi/adapter.js +0 -223
- package/dist/reviewer-agent.js +0 -122
- package/dist/reviewer-child-executor.js +0 -194
- package/dist/reviewer-construction.js +0 -103
- package/dist/reviewer-execution-ledger.js +0 -166
- package/dist/reviewer-failure-diagnostic.js +0 -17
- package/dist/reviewer-role.js +0 -159
- package/dist/reviewer-scope-prompt.js +0 -21
- package/dist/reviewer-settlement.js +0 -66
- package/dist/reviewer-workspace.js +0 -132
- package/dist/role-runtime.js +0 -1604
- package/dist/stderr-jsonl.js +0 -26
- package/dist/tool-execution-observation.js +0 -141
- package/dist/worker-role.js +0 -345
- package/dist/worker-submission-gates.js +0 -305
- package/src/collector-receipt.ts +0 -140
- package/src/diagnostic-tail.ts +0 -18
- package/src/reviewer-agent.ts +0 -135
- package/src/reviewer-child-executor.ts +0 -252
- package/src/reviewer-construction.ts +0 -195
- package/src/reviewer-execution-ledger.ts +0 -212
- package/src/reviewer-failure-diagnostic.ts +0 -18
- package/src/reviewer-scope-prompt.ts +0 -24
- package/src/reviewer-settlement.ts +0 -74
- package/src/reviewer-workspace.ts +0 -105
- package/src/shape-unreadable-failure.ts +0 -49
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reviewer Standards/Spec axis sub-session (#744).
|
|
3
|
-
* Pi host: identity-less in-process child via shared open seam (openPiInProcessSession).
|
|
4
|
-
* Adapter keeps only: materials, engine detour, parent model, nest booking, failure projection.
|
|
5
|
-
* Scratch / abort / usage / close lifecycle stay on the shared envelope (ADR 0018).
|
|
6
|
-
* Other hosts' subagent capability is out of this ticket (principle frozen).
|
|
7
|
-
*/
|
|
8
|
-
import type { Usage } from "@earendil-works/pi-ai";
|
|
9
|
-
|
|
10
|
-
import type { HostContext, RoleTurnModelConfig } from "./host-contracts.ts";
|
|
11
|
-
import { createEngineDetourToolDefinition } from "./engine-detour-tool.ts";
|
|
12
|
-
import { resolveEngineName } from "./engine-detour.ts";
|
|
13
|
-
import {
|
|
14
|
-
appendEngineSessionMaterial,
|
|
15
|
-
engineSessionMaterialFromOptions,
|
|
16
|
-
type EngineSessionMaterial,
|
|
17
|
-
} from "./package-resources/engine-material.ts";
|
|
18
|
-
import { readPackageMaterial } from "./session-opening-materials.ts";
|
|
19
|
-
import type { AcceptedReviewerLeg } from "./reviewer-dispatch.ts";
|
|
20
|
-
import type { ReviewerPromptText } from "./reviewer-prompt-identity.ts";
|
|
21
|
-
import { hasUpstreamErrorTestimony, isNonSuccessHttpStatus } from "./upstream-error-testimony.ts";
|
|
22
|
-
|
|
23
|
-
/** Path roster only — cadence prose stays in owner material (ADR 0073). */
|
|
24
|
-
const AXIS_SUBSESSION_MATERIALS = ["souls/quality-law.md"] as const;
|
|
25
|
-
|
|
26
|
-
async function buildAxisSystemPrompt(engineMaterial?: EngineSessionMaterial): Promise<string> {
|
|
27
|
-
const materials: string[] = [];
|
|
28
|
-
for (const relativePath of AXIS_SUBSESSION_MATERIALS) {
|
|
29
|
-
materials.push(await readPackageMaterial(relativePath));
|
|
30
|
-
}
|
|
31
|
-
return appendEngineSessionMaterial(materials, engineMaterial).join("\n");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
type AxisFailureClassification = "provider" | "child" | "unknown";
|
|
35
|
-
type ClassifiedAxisError = Error & Readonly<{
|
|
36
|
-
evidenceChildFailure: AxisFailureClassification;
|
|
37
|
-
evidenceChildOriginal?: unknown;
|
|
38
|
-
}>;
|
|
39
|
-
|
|
40
|
-
function classifiedError(error: unknown, evidenceChildFailure: AxisFailureClassification): ClassifiedAxisError {
|
|
41
|
-
const diagnostic = typeof error === "object" && error !== null && typeof (error as { errorMessage?: unknown }).errorMessage === "string"
|
|
42
|
-
? (error as { errorMessage: string }).errorMessage
|
|
43
|
-
: error === undefined ? "" : String(error);
|
|
44
|
-
const wrapped = error instanceof Error
|
|
45
|
-
? error
|
|
46
|
-
: Object.assign(new Error(diagnostic, { cause: error }), { evidenceChildOriginal: error });
|
|
47
|
-
const classification = "evidenceChildFailure" in wrapped
|
|
48
|
-
? (wrapped as ClassifiedAxisError).evidenceChildFailure
|
|
49
|
-
: evidenceChildFailure;
|
|
50
|
-
return Object.assign(wrapped, { evidenceChildFailure: classification });
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** Read envelope-projected testimony on an assistant/stop node — no private walker copy. */
|
|
54
|
-
function nodeHasUpstreamTestimony(node: unknown): boolean {
|
|
55
|
-
if (typeof node !== "object" || node === null) return false;
|
|
56
|
-
const record = node as Record<string, unknown>;
|
|
57
|
-
const httpStatus = isNonSuccessHttpStatus(record.statusCode)
|
|
58
|
-
? record.statusCode
|
|
59
|
-
: isNonSuccessHttpStatus(record.status)
|
|
60
|
-
? record.status
|
|
61
|
-
: isNonSuccessHttpStatus(record.httpStatus)
|
|
62
|
-
? record.httpStatus
|
|
63
|
-
: undefined;
|
|
64
|
-
const diagnostics = Array.isArray(record.diagnostics) && record.diagnostics.length > 0
|
|
65
|
-
? record.diagnostics
|
|
66
|
-
: undefined;
|
|
67
|
-
return hasUpstreamErrorTestimony({
|
|
68
|
-
...(httpStatus === undefined ? {} : { httpStatus }),
|
|
69
|
-
...(diagnostics === undefined ? {} : { diagnostics }),
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/** Parent seat model for the axis sub-session (pre-#675 parent-effective inheritance). Pi only. */
|
|
74
|
-
async function parentSelection(context: HostContext): Promise<RoleTurnModelConfig> {
|
|
75
|
-
const { toPiContext } = await import("./pi/adapter.ts");
|
|
76
|
-
let pi;
|
|
77
|
-
try {
|
|
78
|
-
pi = toPiContext(context);
|
|
79
|
-
} catch (error) {
|
|
80
|
-
throw classifiedError(
|
|
81
|
-
new Error(
|
|
82
|
-
"Reviewer Standards/Spec sub-session requires pi host context (other hosts: subagent not in this ticket)",
|
|
83
|
-
{ cause: error },
|
|
84
|
-
),
|
|
85
|
-
"child",
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
if (pi.model === undefined) {
|
|
89
|
-
throw classifiedError(new Error("Reviewer axis sub-session requires parent model"), "child");
|
|
90
|
-
}
|
|
91
|
-
return {
|
|
92
|
-
provider: pi.model.provider,
|
|
93
|
-
model: pi.model.id,
|
|
94
|
-
...(pi.thinkingLevel === undefined ? {} : { thinking: String(pi.thinkingLevel) }),
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export type ReviewerChildExecuteOptions = Readonly<{
|
|
99
|
-
signal?: AbortSignal;
|
|
100
|
-
/** Parent directory for envelope-owned credential/config scratch. */
|
|
101
|
-
credentialScratchParent?: string;
|
|
102
|
-
/** Package root for optional engine method-material on legs (#378). */
|
|
103
|
-
packageRoot?: string;
|
|
104
|
-
/**
|
|
105
|
-
* Request-scoped RoleHost flag reader (#818).
|
|
106
|
-
* Same single gate as registerEngineDetourTool / resolveEngineName:
|
|
107
|
-
* envelope projects request.engine here; absent → pi child-env fallback.
|
|
108
|
-
* Must not read ambient process.env as the primary signal on envelope legs.
|
|
109
|
-
*/
|
|
110
|
-
getFlag?: (name: string) => boolean | string | undefined;
|
|
111
|
-
}>;
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Single conversion at the Reviewer adapter boundary: shared child classifications
|
|
115
|
-
* become Reviewer failure classifications without a second error taxonomy.
|
|
116
|
-
*/
|
|
117
|
-
export function projectSharedChildFailure(error: unknown): unknown {
|
|
118
|
-
if (typeof error === "object" && error !== null && "evidenceChildFailure" in error) {
|
|
119
|
-
const classification = (error as { evidenceChildFailure?: unknown }).evidenceChildFailure;
|
|
120
|
-
if (classification === "provider" || classification === "child" || classification === "unknown") {
|
|
121
|
-
Object.assign(error, { reviewerFailure: classification });
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return error;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function emptyUsage(): Usage {
|
|
128
|
-
return {
|
|
129
|
-
input: 0,
|
|
130
|
-
output: 0,
|
|
131
|
-
cacheRead: 0,
|
|
132
|
-
cacheWrite: 0,
|
|
133
|
-
totalTokens: 0,
|
|
134
|
-
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/** Reviewer Standards/Spec leg via pi in-process sub-session (#744). */
|
|
139
|
-
export async function executeReviewerChild(
|
|
140
|
-
workspace: string,
|
|
141
|
-
leg: AcceptedReviewerLeg,
|
|
142
|
-
context: HostContext,
|
|
143
|
-
options: ReviewerChildExecuteOptions = {},
|
|
144
|
-
): Promise<{ report: unknown; usage: Usage; prompt: ReviewerPromptText }> {
|
|
145
|
-
try {
|
|
146
|
-
if (options.signal?.aborted) {
|
|
147
|
-
throw Object.assign(new DOMException("The operation was aborted.", "AbortError"), {
|
|
148
|
-
evidenceChildFailure: "child" as const,
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
const signal = options.signal;
|
|
152
|
-
const selection = await parentSelection(context);
|
|
153
|
-
const { openPiInProcessSession } = await import("./pi/in-process-session.ts");
|
|
154
|
-
const { createRecordSession } = await import("./archivist-record-entry.ts");
|
|
155
|
-
// One gate with parent registration (#818): request flag, else pi child env.
|
|
156
|
-
const engineName = resolveEngineName(options.getFlag);
|
|
157
|
-
const engineMaterial =
|
|
158
|
-
engineName === undefined
|
|
159
|
-
? undefined
|
|
160
|
-
: options.packageRoot === undefined || options.packageRoot.trim() === ""
|
|
161
|
-
? Object.freeze({ name: engineName })
|
|
162
|
-
: engineSessionMaterialFromOptions({
|
|
163
|
-
engine: engineName,
|
|
164
|
-
packageRoot: options.packageRoot,
|
|
165
|
-
});
|
|
166
|
-
let engineDetourFailure: Error | undefined;
|
|
167
|
-
const engineDetourTool =
|
|
168
|
-
engineName === undefined
|
|
169
|
-
? undefined
|
|
170
|
-
: createEngineDetourToolDefinition({
|
|
171
|
-
engineName,
|
|
172
|
-
fail(error) {
|
|
173
|
-
engineDetourFailure ??= error instanceof Error ? error : new Error(String(error));
|
|
174
|
-
throw engineDetourFailure;
|
|
175
|
-
},
|
|
176
|
-
});
|
|
177
|
-
let opened: Awaited<ReturnType<typeof openPiInProcessSession>>;
|
|
178
|
-
try {
|
|
179
|
-
// No agentDir: envelope owns scratch via credentialScratchParent (ADR 0018).
|
|
180
|
-
opened = await openPiInProcessSession({
|
|
181
|
-
cwd: workspace,
|
|
182
|
-
selection,
|
|
183
|
-
systemPrompt: await buildAxisSystemPrompt(engineMaterial),
|
|
184
|
-
...(options.credentialScratchParent === undefined
|
|
185
|
-
? {}
|
|
186
|
-
: { credentialScratchParent: options.credentialScratchParent }),
|
|
187
|
-
...(engineDetourTool === undefined
|
|
188
|
-
? {}
|
|
189
|
-
: { customTools: [engineDetourTool] }),
|
|
190
|
-
sessionManager: createRecordSession({
|
|
191
|
-
cwd: workspace,
|
|
192
|
-
kind: "evidence-children",
|
|
193
|
-
parent: context.sessionManager,
|
|
194
|
-
}),
|
|
195
|
-
...(signal === undefined ? {} : { signal }),
|
|
196
|
-
label: "Reviewer axis sub-session",
|
|
197
|
-
});
|
|
198
|
-
} catch (error) {
|
|
199
|
-
throw classifiedError(error, "provider");
|
|
200
|
-
}
|
|
201
|
-
const { handle } = opened;
|
|
202
|
-
try {
|
|
203
|
-
const delivered = leg.prompt;
|
|
204
|
-
let turnResult;
|
|
205
|
-
try {
|
|
206
|
-
turnResult = await handle.prompt(String(delivered));
|
|
207
|
-
} catch (error) {
|
|
208
|
-
if (engineDetourFailure !== undefined) {
|
|
209
|
-
throw classifiedError(engineDetourFailure, "child");
|
|
210
|
-
}
|
|
211
|
-
throw classifiedError(error, "provider");
|
|
212
|
-
}
|
|
213
|
-
if (engineDetourFailure !== undefined) {
|
|
214
|
-
throw classifiedError(engineDetourFailure, "child");
|
|
215
|
-
}
|
|
216
|
-
if (signal?.aborted) throw new Error("Reviewer axis sub-session was cancelled");
|
|
217
|
-
const lastAssistant = turnResult.messages !== undefined
|
|
218
|
-
? [...turnResult.messages].reverse().find((message: unknown) =>
|
|
219
|
-
typeof message === "object" && message !== null && (message as { role?: unknown }).role === "assistant"
|
|
220
|
-
)
|
|
221
|
-
: undefined;
|
|
222
|
-
if (
|
|
223
|
-
turnResult.stopReason === "error" || turnResult.stopReason === "aborted"
|
|
224
|
-
|| (typeof lastAssistant === "object" && lastAssistant !== null
|
|
225
|
-
&& ((lastAssistant as { stopReason?: unknown }).stopReason === "error"
|
|
226
|
-
|| (lastAssistant as { stopReason?: unknown }).stopReason === "aborted"))
|
|
227
|
-
) {
|
|
228
|
-
const errMsg = turnResult.errorMessage
|
|
229
|
-
?? (typeof lastAssistant === "object" && lastAssistant !== null
|
|
230
|
-
? String((lastAssistant as { errorMessage?: unknown }).errorMessage ?? "")
|
|
231
|
-
: "");
|
|
232
|
-
// Envelope already attaches observed HTTP status onto error/aborted assistants.
|
|
233
|
-
const hasTestimony = nodeHasUpstreamTestimony(lastAssistant)
|
|
234
|
-
|| nodeHasUpstreamTestimony(opened.streamFailure);
|
|
235
|
-
throw classifiedError(
|
|
236
|
-
new Error(errMsg, { cause: lastAssistant }),
|
|
237
|
-
hasTestimony ? "provider" : "unknown",
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
const report = turnResult.text;
|
|
241
|
-
if (report.trim().length === 0) {
|
|
242
|
-
throw new Error("Reviewer axis sub-session returned a blank report");
|
|
243
|
-
}
|
|
244
|
-
const usage = (turnResult.usage as Usage | undefined) ?? emptyUsage();
|
|
245
|
-
return { report, usage, prompt: delivered };
|
|
246
|
-
} finally {
|
|
247
|
-
await handle.close();
|
|
248
|
-
}
|
|
249
|
-
} catch (error) {
|
|
250
|
-
throw projectSharedChildFailure(error);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import { sha256Hex } from "./sha256.ts";
|
|
2
|
-
import { reviewerScopePrompt } from "./reviewer-scope-prompt.ts";
|
|
3
|
-
import type { ReviewerPinnedTarget, ReviewerRange } from "./reviewer-pinned-git.ts";
|
|
4
|
-
import type { ReviewerPromptText } from "./reviewer-prompt-identity.ts";
|
|
5
|
-
|
|
6
|
-
export const REVIEWER_CONSTRUCTION_RECIPE = Object.freeze({
|
|
7
|
-
recipeId: "reviewer-common-bundle",
|
|
8
|
-
version: 1,
|
|
9
|
-
runtimeVersion: "1",
|
|
10
|
-
implementationSha256: sha256Hex("reviewer-common-bundle:v1:direct-text-prompts"),
|
|
11
|
-
});
|
|
12
|
-
export type ReviewerConstructionIdentity = typeof REVIEWER_CONSTRUCTION_RECIPE;
|
|
13
|
-
export type ReviewerAxis = "standards" | "spec";
|
|
14
|
-
|
|
15
|
-
export const REVIEWER_AXIS_OUTPUT_ADAPTER = Object.freeze({
|
|
16
|
-
adapterId: "reviewer-axis-output",
|
|
17
|
-
version: 1,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
/** Package-owned axis identity + neutral report-byte fact (ADR 0073: no instruction copy of soul). */
|
|
21
|
-
export function reviewerAxisMethodAdapter(axis: ReviewerAxis): string {
|
|
22
|
-
return [
|
|
23
|
-
`Axis-Output-Adapter: ${REVIEWER_AXIS_OUTPUT_ADAPTER.adapterId}@${REVIEWER_AXIS_OUTPUT_ADAPTER.version}:${axis}`,
|
|
24
|
-
"报告字节原样保留,其后无解析器/清洗器/重写/聚合腿",
|
|
25
|
-
].join("\n");
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type ConstructedReviewerLeg = Readonly<{ axis: "standards" | "spec"; prompt: ReviewerPromptText }>;
|
|
29
|
-
|
|
30
|
-
/** Ticket-number provenance for Spec self-fetch (#343). High-priority source wins. */
|
|
31
|
-
export type ReviewerTicketNumberSource =
|
|
32
|
-
| "typed-ticket-number"
|
|
33
|
-
| "branch-token"
|
|
34
|
-
| "commit-message";
|
|
35
|
-
|
|
36
|
-
export type ReviewerTicketNumberCandidate = Readonly<{
|
|
37
|
-
source: ReviewerTicketNumberSource;
|
|
38
|
-
ticketNumber: number;
|
|
39
|
-
}>;
|
|
40
|
-
|
|
41
|
-
/** One docs/adr path referenced by the fetched issue body. */
|
|
42
|
-
export type ReviewerFetchedAdr =
|
|
43
|
-
| Readonly<{ path: string; status: "present"; body: string }>
|
|
44
|
-
| Readonly<{ path: string; status: "missing" }>;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Actual Spec bytes pulled on the self-fetch primary path (fetch-then-store).
|
|
48
|
-
* Carried into Spec-child material and retained on the accepted dispatch for audit.
|
|
49
|
-
*/
|
|
50
|
-
export type ReviewerSpecFetchedMaterial = Readonly<{
|
|
51
|
-
issueRef: string;
|
|
52
|
-
owner: string;
|
|
53
|
-
repo: string;
|
|
54
|
-
ticketNumber: number;
|
|
55
|
-
adopted: ReviewerTicketNumberCandidate;
|
|
56
|
-
abandoned: readonly ReviewerTicketNumberCandidate[];
|
|
57
|
-
issueBody: string;
|
|
58
|
-
adrs: readonly ReviewerFetchedAdr[];
|
|
59
|
-
}>;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Unique discovery product for Skill step 2: durable refs Spec child can read, or confirmed missing.
|
|
63
|
-
* Optional `fetched` is present only when the self-fetch primary path produced issue bytes.
|
|
64
|
-
* Construction builds Standards/Spec solely from this product — no secondary launch decision.
|
|
65
|
-
*/
|
|
66
|
-
export type ReviewerSpecAuthorityDiscovery =
|
|
67
|
-
| Readonly<{
|
|
68
|
-
status: "available";
|
|
69
|
-
refs: readonly string[];
|
|
70
|
-
fetched?: ReviewerSpecFetchedMaterial;
|
|
71
|
-
}>
|
|
72
|
-
| Readonly<{ status: "missing" }>;
|
|
73
|
-
/** Spec-child cardinality decision recorded on the accepted dispatch. */
|
|
74
|
-
export type ReviewerSpecDisposition = "launched" | "skipped-missing";
|
|
75
|
-
export type ConstructedReviewerDispatch = Readonly<{
|
|
76
|
-
identity: string;
|
|
77
|
-
recipe: "reviewer-common-bundle-v1";
|
|
78
|
-
input: Readonly<{
|
|
79
|
-
canonicalSkill: ReviewerPromptText;
|
|
80
|
-
construction: ReviewerConstructionIdentity;
|
|
81
|
-
}>;
|
|
82
|
-
targetSnapshot: ReviewerPinnedTarget;
|
|
83
|
-
range: ReviewerRange;
|
|
84
|
-
/** Frozen durable authority references carried into Spec-axis material only. */
|
|
85
|
-
authorityRefs: readonly string[];
|
|
86
|
-
/** Honest Spec-child disposition: launched, or skipped after confirmed missing Spec. */
|
|
87
|
-
specDisposition: ReviewerSpecDisposition;
|
|
88
|
-
/** Self-fetch bytes + source annotation when primary path produced material. */
|
|
89
|
-
specFetchedMaterial?: ReviewerSpecFetchedMaterial;
|
|
90
|
-
legs: readonly ConstructedReviewerLeg[];
|
|
91
|
-
}>;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Spec-only axis material carrier for durable authority references.
|
|
95
|
-
* Exact values preserved; no prose extraction and no Standards/parent injection.
|
|
96
|
-
*/
|
|
97
|
-
export function reviewerAuthorityRefsMaterial(authorityRefs: readonly string[]): string {
|
|
98
|
-
return [
|
|
99
|
-
"权威引用:",
|
|
100
|
-
JSON.stringify(Object.freeze([...authorityRefs])),
|
|
101
|
-
].join("\n");
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Spec-only material carrier for self-fetched issue bytes + source annotation (#343).
|
|
106
|
-
* Actual issue body and referenced ADR bytes are embedded for audit (fetch-then-store).
|
|
107
|
-
* Single JSON payload keeps external issue/ADR bytes inside structured field values so they
|
|
108
|
-
* cannot forge package framing markers on the same text layer (no plain-text section protocol).
|
|
109
|
-
*/
|
|
110
|
-
export function reviewerFetchedSpecMaterial(fetched: ReviewerSpecFetchedMaterial): string {
|
|
111
|
-
return [
|
|
112
|
-
"权威取回-Spec:",
|
|
113
|
-
JSON.stringify(
|
|
114
|
-
Object.freeze({
|
|
115
|
-
source: fetched.adopted.source,
|
|
116
|
-
ticketNumber: fetched.ticketNumber,
|
|
117
|
-
issueRef: fetched.issueRef,
|
|
118
|
-
abandoned: Object.freeze([...fetched.abandoned]),
|
|
119
|
-
issueBody: fetched.issueBody,
|
|
120
|
-
adrs: Object.freeze(
|
|
121
|
-
fetched.adrs.map((adr) =>
|
|
122
|
-
adr.status === "present"
|
|
123
|
-
? Object.freeze({ path: adr.path, status: adr.status, body: adr.body })
|
|
124
|
-
: Object.freeze({ path: adr.path, status: adr.status }),
|
|
125
|
-
),
|
|
126
|
-
),
|
|
127
|
-
}),
|
|
128
|
-
),
|
|
129
|
-
].join("\n");
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/** Deterministic compiler: fixed target/range plus discovery product in, dispatch text out. */
|
|
133
|
-
export function constructReviewerDispatch(input: {
|
|
134
|
-
identity: string;
|
|
135
|
-
canonicalSkill: string;
|
|
136
|
-
target: ReviewerPinnedTarget;
|
|
137
|
-
range: ReviewerRange;
|
|
138
|
-
reviewScopeKeys?: readonly string[];
|
|
139
|
-
/** Unique discovery product (available+refs material, or missing). */
|
|
140
|
-
specAuthority: ReviewerSpecAuthorityDiscovery;
|
|
141
|
-
}): ConstructedReviewerDispatch {
|
|
142
|
-
const launchSpec = input.specAuthority.status === "available";
|
|
143
|
-
const authorityRefs = Object.freeze(
|
|
144
|
-
input.specAuthority.status === "available" ? [...input.specAuthority.refs] : [],
|
|
145
|
-
);
|
|
146
|
-
const specFetchedMaterial =
|
|
147
|
-
input.specAuthority.status === "available" && input.specAuthority.fetched !== undefined
|
|
148
|
-
? input.specAuthority.fetched
|
|
149
|
-
: undefined;
|
|
150
|
-
const specDisposition: ReviewerSpecDisposition = launchSpec ? "launched" : "skipped-missing";
|
|
151
|
-
const common = [
|
|
152
|
-
`目标:${input.range.target}`,
|
|
153
|
-
`基点:${input.range.base}`,
|
|
154
|
-
`差异命令:${input.range.diffCommand}`,
|
|
155
|
-
reviewerScopePrompt(input.reviewScopeKeys),
|
|
156
|
-
`配方:${REVIEWER_CONSTRUCTION_RECIPE.recipeId}@${REVIEWER_CONSTRUCTION_RECIPE.version}`,
|
|
157
|
-
"Canonical-Skill:",
|
|
158
|
-
input.canonicalSkill,
|
|
159
|
-
"固定范围:",
|
|
160
|
-
JSON.stringify(input.range, null, 2),
|
|
161
|
-
].join("\n");
|
|
162
|
-
const axes: readonly { axis: "standards" | "spec" }[] = launchSpec
|
|
163
|
-
? [{ axis: "standards" }, { axis: "spec" }]
|
|
164
|
-
: [{ axis: "standards" }];
|
|
165
|
-
const legs = axes.map((x) => {
|
|
166
|
-
const parts = [common, reviewerAxisMethodAdapter(x.axis)];
|
|
167
|
-
// Spec axis only — never Standards or a parent replacement Spec leg.
|
|
168
|
-
if (x.axis === "spec") {
|
|
169
|
-
if (specFetchedMaterial !== undefined) {
|
|
170
|
-
parts.push(reviewerFetchedSpecMaterial(specFetchedMaterial));
|
|
171
|
-
}
|
|
172
|
-
if (authorityRefs.length > 0) {
|
|
173
|
-
parts.push(reviewerAuthorityRefsMaterial(authorityRefs));
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return Object.freeze({
|
|
177
|
-
axis: x.axis,
|
|
178
|
-
prompt: `${parts.join("\n")}\n`,
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
return Object.freeze({
|
|
182
|
-
identity: input.identity,
|
|
183
|
-
recipe: "reviewer-common-bundle-v1",
|
|
184
|
-
input: Object.freeze({
|
|
185
|
-
canonicalSkill: input.canonicalSkill,
|
|
186
|
-
construction: REVIEWER_CONSTRUCTION_RECIPE,
|
|
187
|
-
}),
|
|
188
|
-
targetSnapshot: input.target,
|
|
189
|
-
range: input.range,
|
|
190
|
-
authorityRefs,
|
|
191
|
-
specDisposition,
|
|
192
|
-
...(specFetchedMaterial === undefined ? {} : { specFetchedMaterial }),
|
|
193
|
-
legs: Object.freeze(legs),
|
|
194
|
-
});
|
|
195
|
-
}
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import { sameReviewerPinnedTarget } from "./reviewer-git-snapshot.ts";
|
|
2
|
-
import { isReviewerPromptText, sameReviewerPromptText, type ReviewerPromptText } from "./reviewer-prompt-identity.ts";
|
|
3
|
-
import type { ReviewerDispatchRunResult } from "./reviewer-agent.ts";
|
|
4
|
-
import {
|
|
5
|
-
REVIEWER_PREFLIGHT_VIOLATIONS,
|
|
6
|
-
type ReviewerPreflightViolation,
|
|
7
|
-
type ReviewerPinnedTarget,
|
|
8
|
-
type AcceptedReviewerDispatch,
|
|
9
|
-
} from "./reviewer-dispatch.ts";
|
|
10
|
-
|
|
11
|
-
export type ReviewerUsage = Readonly<{
|
|
12
|
-
input: number; output: number; cacheRead: number; cacheWrite: number;
|
|
13
|
-
cacheWrite1h?: number; reasoning?: number; totalTokens: number;
|
|
14
|
-
cost: Readonly<{ input: number; output: number; cacheRead: number; cacheWrite: number; total: number }>;
|
|
15
|
-
}>;
|
|
16
|
-
export type ReviewerTargetSnapshot = ReviewerPinnedTarget;
|
|
17
|
-
export type ReviewerWorkspaceDisposition = "deleted" | "not-created" | Readonly<{ retained: string }>;
|
|
18
|
-
export type ReviewerFailureClassification = "cancelled" | "provider" | "snapshot" | "workspace" | "child" | "unknown";
|
|
19
|
-
|
|
20
|
-
export type ReviewerCompiledLegEvidence = AcceptedReviewerDispatch["legs"][number];
|
|
21
|
-
export type ReviewerAcceptedEvidence = Readonly<
|
|
22
|
-
Omit<AcceptedReviewerDispatch, "targetSnapshot"> & {
|
|
23
|
-
target: AcceptedReviewerDispatch["targetSnapshot"];
|
|
24
|
-
}
|
|
25
|
-
>;
|
|
26
|
-
export function projectAcceptedDispatch(dispatch: AcceptedReviewerDispatch): ReviewerEvidenceEvent {
|
|
27
|
-
return {
|
|
28
|
-
source: "reviewer-dispatch", type: "accepted", identity: dispatch.identity,
|
|
29
|
-
recipe: dispatch.recipe, input: dispatch.input, target: dispatch.targetSnapshot,
|
|
30
|
-
range: dispatch.range, authorityRefs: dispatch.authorityRefs,
|
|
31
|
-
specDisposition: dispatch.specDisposition,
|
|
32
|
-
...(dispatch.specFetchedMaterial === undefined
|
|
33
|
-
? {}
|
|
34
|
-
: { specFetchedMaterial: dispatch.specFetchedMaterial }),
|
|
35
|
-
legs: dispatch.legs,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
type ReviewerLegResultEvidenceCommon = Readonly<{
|
|
40
|
-
dispatchIdentity: string;
|
|
41
|
-
axis: "standards" | "spec";
|
|
42
|
-
prompt: ReviewerPromptText;
|
|
43
|
-
target: ReviewerPinnedTarget;
|
|
44
|
-
workspaceDisposition: ReviewerWorkspaceDisposition;
|
|
45
|
-
}>;
|
|
46
|
-
export type ReviewerLegResultEvidence = ReviewerLegResultEvidenceCommon & (
|
|
47
|
-
| Readonly<{ status: "successful"; report: unknown; usage: ReviewerUsage; failure?: never }>
|
|
48
|
-
| Readonly<{ status: "failed"; failure: ReviewerFailureClassification; diagnostic: string; report?: never; usage?: never }>
|
|
49
|
-
);
|
|
50
|
-
export type ReviewerEvidenceEvent =
|
|
51
|
-
| (Readonly<{ source: "reviewer-dispatch"; type: "rejected"; identity: string; violations: readonly ReviewerPreflightViolation[]; started: false }>)
|
|
52
|
-
| Readonly<{ source: "reviewer-dispatch"; type: "closed-attempt"; identity: string; reason: "acceptance-closed"; started: false }>
|
|
53
|
-
| (Readonly<{ source: "reviewer-dispatch"; type: "accepted" }> & ReviewerAcceptedEvidence)
|
|
54
|
-
| Readonly<{ source: "reviewer-agent"; type: "dispatch-started"; dispatchIdentity: string; cardinality: 1 | 2 }>
|
|
55
|
-
| (Readonly<{ source: "reviewer-agent"; type: "leg-settled" }> & ReviewerLegResultEvidence)
|
|
56
|
-
| Readonly<{ source: "reviewer-runtime"; type: "fatal"; diagnostics: string; cause: unknown; targetSnapshot?: ReviewerTargetSnapshot; workspaceDisposition?: ReviewerWorkspaceDisposition }>;
|
|
57
|
-
|
|
58
|
-
export type ReviewerExecutionRecord = Readonly<{
|
|
59
|
-
rejections: readonly Readonly<{ identity: string; violations: readonly ReviewerPreflightViolation[]; started: false }>[];
|
|
60
|
-
closedAttempts?: readonly Readonly<{ identity: string; reason: "acceptance-closed"; started: false }>[];
|
|
61
|
-
accepted?: ReviewerAcceptedEvidence;
|
|
62
|
-
started?: Readonly<{ dispatchIdentity: string; cardinality: 1 | 2 }>;
|
|
63
|
-
results: Readonly<Partial<Record<"standards" | "spec", ReviewerLegResultEvidence>>>;
|
|
64
|
-
}>;
|
|
65
|
-
export type ReviewerExecutionLedger = Readonly<{
|
|
66
|
-
append(event: ReviewerEvidenceEvent): void;
|
|
67
|
-
recordInfrastructureFailure<T>(error: T): T;
|
|
68
|
-
recordForAudit(status: "completed" | "refused"): ReviewerExecutionRecord;
|
|
69
|
-
}>;
|
|
70
|
-
|
|
71
|
-
export function projectReviewerDispatchOutcome(
|
|
72
|
-
ledger: ReviewerExecutionLedger,
|
|
73
|
-
dispatch: AcceptedReviewerDispatch,
|
|
74
|
-
result: ReviewerDispatchRunResult,
|
|
75
|
-
): void {
|
|
76
|
-
if (result.identity !== dispatch.identity) throw new Error("Reviewer runner identity does not match accepted dispatch");
|
|
77
|
-
if (!sameReviewerPinnedTarget(result.target, dispatch.targetSnapshot)) throw new Error("Reviewer runner target does not match accepted pinned target");
|
|
78
|
-
const expectedAxes = dispatch.legs.map(({ axis }) => axis).sort();
|
|
79
|
-
const actualAxes = Object.keys(result.legs).sort();
|
|
80
|
-
if (actualAxes.length !== expectedAxes.length || actualAxes.some((axis, index) => axis !== expectedAxes[index])) {
|
|
81
|
-
throw new Error(`Reviewer runner result axes do not match accepted dispatch: expected ${expectedAxes.join(",")}; received ${actualAxes.join(",")}`);
|
|
82
|
-
}
|
|
83
|
-
for (const leg of dispatch.legs) {
|
|
84
|
-
const actual = result.legs[leg.axis];
|
|
85
|
-
if (actual === undefined) throw new Error(`Reviewer runner omitted ${leg.axis} result`);
|
|
86
|
-
ledger.append(actual.status === "failed"
|
|
87
|
-
? { source: "reviewer-agent", type: "leg-settled", dispatchIdentity: dispatch.identity, axis: leg.axis, status: "failed", prompt: actual.prompt, target: actual.target, failure: actual.failure, diagnostic: actual.diagnostic, workspaceDisposition: actual.workspaceDisposition }
|
|
88
|
-
: { source: "reviewer-agent", type: "leg-settled", dispatchIdentity: dispatch.identity, axis: leg.axis, status: "successful", prompt: actual.prompt, target: actual.target, report: actual.report, usage: actual.usage, workspaceDisposition: actual.workspaceDisposition });
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
type FatalEvidence = { diagnostics: string; cause: unknown; targetSnapshot?: ReviewerTargetSnapshot; workspaceDisposition?: ReviewerWorkspaceDisposition };
|
|
93
|
-
|
|
94
|
-
function cloneFreeze<T>(value: T): T {
|
|
95
|
-
if (Array.isArray(value)) return Object.freeze(value.map(cloneFreeze)) as T;
|
|
96
|
-
if (typeof value === "object" && value !== null) {
|
|
97
|
-
const copy: Record<string, unknown> = {};
|
|
98
|
-
for (const [key, item] of Object.entries(value)) copy[key] = cloneFreeze(item);
|
|
99
|
-
return Object.freeze(copy) as T;
|
|
100
|
-
}
|
|
101
|
-
return value;
|
|
102
|
-
}
|
|
103
|
-
function hasExactEventShape(event: object, keys: readonly string[]): boolean {
|
|
104
|
-
const actual = Object.keys(event);
|
|
105
|
-
return actual.length === keys.length && actual.every((key) => keys.includes(key));
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function fatal(error: unknown): FatalEvidence {
|
|
109
|
-
const record = typeof error === "object" && error !== null ? error as Record<string, unknown> : undefined;
|
|
110
|
-
return cloneFreeze({
|
|
111
|
-
diagnostics: "infrastructure-failure",
|
|
112
|
-
cause: error,
|
|
113
|
-
...(record?.targetSnapshot === undefined ? {} : { targetSnapshot: record.targetSnapshot as ReviewerTargetSnapshot }),
|
|
114
|
-
...(record?.workspaceDisposition === undefined ? {} : { workspaceDisposition: record.workspaceDisposition as ReviewerWorkspaceDisposition }),
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export function createReviewerExecutionLedger(): ReviewerExecutionLedger {
|
|
119
|
-
const rejections: Array<{ identity: string; violations: readonly ReviewerPreflightViolation[]; started: false }> = [];
|
|
120
|
-
const closedAttempts: Array<{ identity: string; reason: "acceptance-closed"; started: false }> = [];
|
|
121
|
-
let accepted: ReviewerAcceptedEvidence | undefined;
|
|
122
|
-
let started: { dispatchIdentity: string; cardinality: 1 | 2 } | undefined;
|
|
123
|
-
const results: Partial<Record<"standards" | "spec", ReviewerLegResultEvidence>> = {};
|
|
124
|
-
let infrastructureFailure: FatalEvidence | undefined;
|
|
125
|
-
|
|
126
|
-
function append(raw: ReviewerEvidenceEvent): void {
|
|
127
|
-
const event = cloneFreeze(raw);
|
|
128
|
-
if (event.source === "reviewer-dispatch" && event.type === "rejected") {
|
|
129
|
-
if (!hasExactEventShape(event, ["source", "type", "identity", "violations", "started"]) || event.started !== false ||
|
|
130
|
-
event.violations.length === 0 || event.violations.some((code) => !REVIEWER_PREFLIGHT_VIOLATIONS.includes(code)))
|
|
131
|
-
throw new Error("Rejected dispatch must contain only closed bounded non-start evidence");
|
|
132
|
-
if (accepted !== undefined || started !== undefined) throw new Error("Rejection cannot follow an accepted dispatch");
|
|
133
|
-
rejections.push(cloneFreeze({ identity: event.identity, violations: event.violations, started: false }));
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
if (event.source === "reviewer-dispatch" && event.type === "closed-attempt") {
|
|
137
|
-
if (!hasExactEventShape(event, ["source", "type", "identity", "reason", "started"]) || event.reason !== "acceptance-closed" || event.started !== false)
|
|
138
|
-
throw new Error("Closed attempt must contain only immutable non-start outcome evidence");
|
|
139
|
-
if (accepted === undefined) throw new Error("Closed attempt requires a closed acceptance lifecycle");
|
|
140
|
-
closedAttempts.push(cloneFreeze({ identity: event.identity, reason: event.reason, started: false }));
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
if (event.source === "reviewer-dispatch" && event.type === "accepted") {
|
|
144
|
-
if (accepted !== undefined) throw new Error("Projection permits exactly one accepted dispatch");
|
|
145
|
-
const axes = event.legs.map((leg) => leg.axis);
|
|
146
|
-
if (axes[0] !== "standards" || (axes.length !== 1 && (axes.length !== 2 || axes[1] !== "spec")))
|
|
147
|
-
throw new Error("Accepted dispatch sibling axes disagree");
|
|
148
|
-
if (!isReviewerPromptText(event.input.canonicalSkill))
|
|
149
|
-
throw new Error("Accepted canonical Skill must be plain text");
|
|
150
|
-
for (const leg of event.legs) {
|
|
151
|
-
if (!isReviewerPromptText(leg.prompt))
|
|
152
|
-
throw new Error("Accepted compiled prompt must be plain text");
|
|
153
|
-
}
|
|
154
|
-
accepted = event;
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
if (event.source === "reviewer-runtime" && event.type === "fatal") {
|
|
158
|
-
if (infrastructureFailure === undefined) infrastructureFailure = cloneFreeze({
|
|
159
|
-
diagnostics: event.diagnostics,
|
|
160
|
-
cause: event.cause,
|
|
161
|
-
...(event.targetSnapshot === undefined ? {} : { targetSnapshot: event.targetSnapshot }),
|
|
162
|
-
...(event.workspaceDisposition === undefined ? {} : { workspaceDisposition: event.workspaceDisposition }),
|
|
163
|
-
});
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
if (event.type === "dispatch-started") {
|
|
167
|
-
if (accepted === undefined || event.dispatchIdentity !== accepted.identity) throw new Error("Start requires its accepted dispatch");
|
|
168
|
-
if (started !== undefined) throw new Error("Accepted dispatch can start exactly once");
|
|
169
|
-
if (event.cardinality !== accepted.legs.length) throw new Error("Dispatch start cardinality disagrees with acceptance");
|
|
170
|
-
started = cloneFreeze({ dispatchIdentity: event.dispatchIdentity, cardinality: event.cardinality });
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
if (accepted === undefined || started === undefined || event.dispatchIdentity !== accepted.identity)
|
|
174
|
-
throw new Error("Runner result requires its irreversible accepted dispatch start");
|
|
175
|
-
if (results[event.axis] !== undefined) throw new Error(`Reviewer ${event.axis} result can settle exactly once`);
|
|
176
|
-
const compiled = accepted.legs.find((leg) => leg.axis === event.axis);
|
|
177
|
-
if (compiled === undefined) throw new Error(`Reviewer ${event.axis} was not an accepted leg`);
|
|
178
|
-
if (!sameReviewerPromptText(event.prompt, compiled.prompt) || !isReviewerPromptText(event.prompt))
|
|
179
|
-
throw new Error("Actual runner prompt does not exactly match compiled prompt text");
|
|
180
|
-
if (!sameReviewerPinnedTarget(event.target, accepted.target)) throw new Error("Runner target does not match shared pinned target");
|
|
181
|
-
if (event.status === "successful") {
|
|
182
|
-
// Report field required; no type/blank reshape gate (ADR 0055 / #675).
|
|
183
|
-
if (event.report === undefined || event.failure !== undefined) throw new Error("Successful settlement requires a report");
|
|
184
|
-
} else if (event.failure === undefined || event.report !== undefined) {
|
|
185
|
-
throw new Error("Failed settlement requires a bounded failure classification and no report");
|
|
186
|
-
}
|
|
187
|
-
results[event.axis] = event;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function recordInfrastructureFailure<T>(error: T): T {
|
|
191
|
-
if (infrastructureFailure === undefined) {
|
|
192
|
-
const evidence = fatal(error);
|
|
193
|
-
append({ source: "reviewer-runtime", type: "fatal", ...evidence });
|
|
194
|
-
}
|
|
195
|
-
return error;
|
|
196
|
-
}
|
|
197
|
-
function recordForAudit(status: "completed" | "refused"): ReviewerExecutionRecord {
|
|
198
|
-
if (infrastructureFailure !== undefined) throw Object.assign(new Error(`Reviewer infrastructure previously failed: ${infrastructureFailure.diagnostics}`), { fatalReviewerInfrastructure: true as const });
|
|
199
|
-
if (status === "completed") {
|
|
200
|
-
if (accepted === undefined || started === undefined) throw new Error("Reviewer completed requires exactly one accepted and started dispatch");
|
|
201
|
-
const expected = accepted.legs.map((leg) => leg.axis);
|
|
202
|
-
if (expected.some((axis) => results[axis]?.status !== "successful") || Object.keys(results).length !== expected.length)
|
|
203
|
-
throw new Error(expected.length === 2 ? "Reviewer completed requires both axes settled successfully" : "Reviewer completed requires Standards settled successfully and no Spec evidence");
|
|
204
|
-
} else if (accepted !== undefined) {
|
|
205
|
-
const expected = accepted.legs.map((leg) => leg.axis);
|
|
206
|
-
if (started === undefined || expected.some((axis) => results[axis] === undefined) || Object.keys(results).length !== expected.length)
|
|
207
|
-
throw new Error("Reviewer refused after acceptance requires every expected leg terminal outcome");
|
|
208
|
-
}
|
|
209
|
-
return cloneFreeze({ rejections, closedAttempts, ...(accepted === undefined ? {} : { accepted }), ...(started === undefined ? {} : { started }), results });
|
|
210
|
-
}
|
|
211
|
-
return Object.freeze({ append, recordInfrastructureFailure, recordForAudit });
|
|
212
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { ReviewerFailureClassification } from "./reviewer-execution-ledger.ts";
|
|
2
|
-
|
|
3
|
-
export function normalizeReviewerFailureDiagnostic(error: unknown, failure: ReviewerFailureClassification): string {
|
|
4
|
-
const original = error instanceof Error && Object.hasOwn(error, "reviewerOriginal")
|
|
5
|
-
? (error as Error & { reviewerOriginal: unknown }).reviewerOriginal
|
|
6
|
-
: error;
|
|
7
|
-
const message = original instanceof Error
|
|
8
|
-
? original.message.trim()
|
|
9
|
-
: typeof original === "string"
|
|
10
|
-
? original.trim()
|
|
11
|
-
: typeof original === "object" && original !== null && typeof (original as { errorMessage?: unknown }).errorMessage === "string"
|
|
12
|
-
? (original as { errorMessage: string }).errorMessage.trim()
|
|
13
|
-
: "";
|
|
14
|
-
if (message !== "") return message;
|
|
15
|
-
return failure === "provider"
|
|
16
|
-
? "Reviewer Agent provider supplied no diagnostic details"
|
|
17
|
-
: "Reviewer Agent failed without diagnostic details";
|
|
18
|
-
}
|