harnery 0.10.0 → 0.11.0

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.
@@ -0,0 +1,434 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import {
3
+ chmodSync,
4
+ existsSync,
5
+ mkdirSync,
6
+ readFileSync,
7
+ renameSync,
8
+ statSync,
9
+ unlinkSync,
10
+ writeFileSync,
11
+ } from "node:fs";
12
+ import { dirname, join } from "node:path";
13
+ import type { RepoSnapshot } from "../context/index.ts";
14
+ import type {
15
+ AcceptanceCriterion,
16
+ AcceptanceResult,
17
+ AcceptanceSummary,
18
+ HarnessEvidenceCapability,
19
+ HarnessEvidenceCoverage,
20
+ ResultDigest,
21
+ WorkflowAgentProof,
22
+ WorkflowEvidenceInput,
23
+ WorkflowEvidenceRecord,
24
+ WorkflowMeta,
25
+ WorkflowProof,
26
+ WorkflowProofUnknown,
27
+ WorkflowRepoEvidence,
28
+ WorkflowRepoSnapshot,
29
+ } from "./types.ts";
30
+ import { WORKFLOW_PROOF_SCHEMA_VERSION } from "./types.ts";
31
+
32
+ const MAX_ACCEPTANCE_CRITERIA = 50;
33
+ const MAX_EVIDENCE_RECORDS = 200;
34
+ const MAX_PACKET_BYTES = 512 * 1024;
35
+ const MAX_NAME_CHARS = 200;
36
+ const MAX_OBJECTIVE_CHARS = 2_000;
37
+ const MAX_CRITERION_CHARS = 500;
38
+ const MAX_LABEL_CHARS = 200;
39
+ const MAX_SUMMARY_CHARS = 2_000;
40
+ const MAX_REF_CHARS = 1_000;
41
+ const ACCEPTANCE_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
42
+ const RUN_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,199}$/;
43
+
44
+ export interface NormalizedWorkflowMeta {
45
+ name: string;
46
+ description?: string;
47
+ objective?: string;
48
+ acceptance: AcceptanceCriterion[];
49
+ }
50
+
51
+ export interface BuildWorkflowProofInput {
52
+ runId: string;
53
+ meta: NormalizedWorkflowMeta;
54
+ status: "succeeded" | "failed";
55
+ startedAt: string;
56
+ endedAt: string;
57
+ durationMs: number;
58
+ journalPath: string;
59
+ before: RepoSnapshot;
60
+ after: RepoSnapshot;
61
+ agents: WorkflowAgentProof[];
62
+ evidence: WorkflowEvidenceRecord[];
63
+ harnessEvidence?: Readonly<Record<string, HarnessEvidenceCapability | undefined>>;
64
+ result?: unknown;
65
+ error?: string;
66
+ }
67
+
68
+ export function normalizeWorkflowMeta(
69
+ meta: WorkflowMeta | undefined,
70
+ fallbackName: string,
71
+ ): NormalizedWorkflowMeta {
72
+ const name = boundedRequired(meta?.name ?? fallbackName, "workflow name", MAX_NAME_CHARS);
73
+ const objective = boundedOptional(meta?.objective, "workflow objective", MAX_OBJECTIVE_CHARS);
74
+ const description = boundedOptional(
75
+ meta?.description,
76
+ "workflow description",
77
+ MAX_OBJECTIVE_CHARS,
78
+ );
79
+ const acceptance = meta?.acceptance ?? [];
80
+ if (!Array.isArray(acceptance)) throw new Error("workflow acceptance must be an array");
81
+ if (acceptance.length > MAX_ACCEPTANCE_CRITERIA) {
82
+ throw new Error(`workflow acceptance exceeds ${MAX_ACCEPTANCE_CRITERIA} criteria`);
83
+ }
84
+
85
+ const seen = new Set<string>();
86
+ const normalized = acceptance.map((criterion, index) => {
87
+ if (!criterion || typeof criterion !== "object") {
88
+ throw new Error(`workflow acceptance[${index}] must be an object`);
89
+ }
90
+ const id = boundedRequired(criterion.id, `workflow acceptance[${index}].id`, 64);
91
+ if (!ACCEPTANCE_ID.test(id)) {
92
+ throw new Error(
93
+ `workflow acceptance id ${JSON.stringify(id)} must match ${ACCEPTANCE_ID.source}`,
94
+ );
95
+ }
96
+ if (seen.has(id)) throw new Error(`duplicate workflow acceptance id ${JSON.stringify(id)}`);
97
+ seen.add(id);
98
+ return {
99
+ id,
100
+ statement: boundedRequired(
101
+ criterion.statement,
102
+ `workflow acceptance[${index}].statement`,
103
+ MAX_CRITERION_CHARS,
104
+ ),
105
+ };
106
+ });
107
+ return { name, description, objective, acceptance: normalized };
108
+ }
109
+
110
+ export function createEvidenceRecord(input: {
111
+ value: WorkflowEvidenceInput;
112
+ sequence: number;
113
+ acceptanceIds: ReadonlySet<string>;
114
+ stage?: string;
115
+ recordedAt?: string;
116
+ }): WorkflowEvidenceRecord {
117
+ if (input.sequence > MAX_EVIDENCE_RECORDS) {
118
+ throw new Error(`workflow evidence exceeds ${MAX_EVIDENCE_RECORDS} records`);
119
+ }
120
+ const value = input.value;
121
+ const acceptanceIds = value.acceptanceIds ?? [];
122
+ if (!Array.isArray(acceptanceIds)) throw new Error("evidence acceptanceIds must be an array");
123
+ const uniqueAcceptanceIds = [...new Set(acceptanceIds)];
124
+ for (const id of uniqueAcceptanceIds) {
125
+ if (typeof id !== "string" || !input.acceptanceIds.has(id)) {
126
+ throw new Error(`evidence references unknown acceptance id ${JSON.stringify(id)}`);
127
+ }
128
+ }
129
+ return {
130
+ id: `e${input.sequence}`,
131
+ source: "workflow",
132
+ recorded_at: input.recordedAt ?? new Date().toISOString(),
133
+ kind: enumValue(
134
+ value.kind,
135
+ ["test", "command", "artifact", "change", "review", "observation"],
136
+ "evidence kind",
137
+ ),
138
+ status: enumValue(value.status, ["passed", "failed", "observed", "unknown"], "evidence status"),
139
+ label: boundedRequired(value.label, "evidence label", MAX_LABEL_CHARS),
140
+ summary: boundedOptional(value.summary, "evidence summary", MAX_SUMMARY_CHARS),
141
+ ref: boundedOptional(value.ref, "evidence ref", MAX_REF_CHARS),
142
+ stage: boundedOptional(input.stage, "evidence stage", MAX_LABEL_CHARS),
143
+ acceptance_ids: uniqueAcceptanceIds,
144
+ };
145
+ }
146
+
147
+ export function rollupAcceptance(
148
+ criteria: AcceptanceCriterion[],
149
+ evidence: WorkflowEvidenceRecord[],
150
+ ): { criteria: AcceptanceResult[]; summary: AcceptanceSummary } {
151
+ const results = criteria.map((criterion): AcceptanceResult => {
152
+ const attached = evidence.filter((item) => item.acceptance_ids.includes(criterion.id));
153
+ const failed = attached.filter((item) => item.status === "failed");
154
+ const passed = attached.filter((item) => item.status === "passed");
155
+ const decisive = failed.length > 0 ? failed : passed;
156
+ const status = failed.length > 0 ? "unsatisfied" : passed.length > 0 ? "satisfied" : "unknown";
157
+ return {
158
+ ...criterion,
159
+ status,
160
+ evidence_ids: attached.map((item) => item.id),
161
+ sources: [...new Set(decisive.map((item) => item.source))],
162
+ };
163
+ });
164
+ return {
165
+ criteria: results,
166
+ summary: {
167
+ satisfied: results.filter((item) => item.status === "satisfied").length,
168
+ unsatisfied: results.filter((item) => item.status === "unsatisfied").length,
169
+ unknown: results.filter((item) => item.status === "unknown").length,
170
+ total: results.length,
171
+ },
172
+ };
173
+ }
174
+
175
+ export function digestResult(value: unknown, kind?: "text" | "json"): ResultDigest {
176
+ const resolvedKind = kind ?? (typeof value === "string" ? "text" : "json");
177
+ const serialized = resolvedKind === "text" ? String(value) : (JSON.stringify(value) ?? "null");
178
+ return {
179
+ kind: resolvedKind,
180
+ sha256: createHash("sha256").update(serialized).digest("hex"),
181
+ bytes: Buffer.byteLength(serialized),
182
+ };
183
+ }
184
+
185
+ export function buildWorkflowProof(input: BuildWorkflowProofInput): WorkflowProof {
186
+ const acceptance = rollupAcceptance(input.meta.acceptance, input.evidence);
187
+ const repository = buildRepoEvidence(input.before, input.after);
188
+ const agents = input.agents.map((agent) => ({
189
+ ...agent,
190
+ label: clipped(agent.label, MAX_LABEL_CHARS),
191
+ model: clippedOptional(agent.model, MAX_LABEL_CHARS),
192
+ session_id: clippedOptional(agent.session_id, MAX_REF_CHARS),
193
+ error: clippedOptional(agent.error, MAX_SUMMARY_CHARS),
194
+ }));
195
+ const harnesses = buildHarnessCoverage(agents, input.harnessEvidence);
196
+ const unknowns = buildUnknowns(agents, harnesses, repository);
197
+ const journal = readFileSync(input.journalPath);
198
+ return {
199
+ schema_version: WORKFLOW_PROOF_SCHEMA_VERSION,
200
+ run: {
201
+ id: input.runId,
202
+ name: input.meta.name,
203
+ status: input.status,
204
+ started_at: input.startedAt,
205
+ ended_at: input.endedAt,
206
+ duration_ms: input.durationMs,
207
+ objective: input.meta.objective,
208
+ error: clippedOptional(input.error, MAX_SUMMARY_CHARS),
209
+ result: input.result === undefined ? undefined : digestResult(input.result),
210
+ },
211
+ acceptance,
212
+ agents,
213
+ evidence: input.evidence,
214
+ repository,
215
+ harnesses,
216
+ unknowns,
217
+ integrity: {
218
+ journal: {
219
+ path: "journal.jsonl",
220
+ sha256: createHash("sha256").update(journal).digest("hex"),
221
+ bytes: journal.byteLength,
222
+ },
223
+ },
224
+ };
225
+ }
226
+
227
+ export function writeWorkflowProof(path: string, proof: WorkflowProof): void {
228
+ const body = `${JSON.stringify(proof, null, 2)}\n`;
229
+ const bytes = Buffer.byteLength(body);
230
+ if (bytes > MAX_PACKET_BYTES) {
231
+ throw new Error(`workflow proof is ${bytes} bytes; limit is ${MAX_PACKET_BYTES}`);
232
+ }
233
+ mkdirSync(dirname(path), { recursive: true });
234
+ const temporary = `${path}.tmp-${process.pid}-${randomUUID()}`;
235
+ try {
236
+ writeFileSync(temporary, body, { encoding: "utf8", flag: "wx", mode: 0o600 });
237
+ renameSync(temporary, path);
238
+ chmodSync(path, 0o600);
239
+ } finally {
240
+ if (existsSync(temporary)) unlinkSync(temporary);
241
+ }
242
+ }
243
+
244
+ export function readWorkflowProof(coordRoot: string, runId: string): WorkflowProof {
245
+ if (!RUN_ID.test(runId)) throw new Error(`invalid workflow run id ${JSON.stringify(runId)}`);
246
+ const path = join(coordRoot, ".harnery", "workflows", runId, "proof.json");
247
+ if (!existsSync(path)) throw new Error(`workflow run ${runId} has no proof packet at ${path}`);
248
+ const size = statSync(path).size;
249
+ if (size > MAX_PACKET_BYTES) {
250
+ throw new Error(`workflow proof is ${size} bytes; limit is ${MAX_PACKET_BYTES}`);
251
+ }
252
+ let proof: WorkflowProof;
253
+ try {
254
+ proof = JSON.parse(readFileSync(path, "utf8")) as WorkflowProof;
255
+ } catch (error) {
256
+ throw new Error(`cannot parse workflow proof at ${path}: ${(error as Error).message}`);
257
+ }
258
+ if (proof.schema_version !== WORKFLOW_PROOF_SCHEMA_VERSION || proof.run?.id !== runId) {
259
+ throw new Error(`workflow proof at ${path} has an unsupported or mismatched schema`);
260
+ }
261
+ return proof;
262
+ }
263
+
264
+ export function renderWorkflowProof(proof: WorkflowProof): string {
265
+ const lines = [
266
+ `run ${proof.run.id} (${proof.run.name}): ${proof.run.status}`,
267
+ `duration: ${Math.round(proof.run.duration_ms / 1000)}s`,
268
+ ];
269
+ if (proof.run.objective) lines.push(`objective: ${proof.run.objective}`);
270
+ const summary = proof.acceptance.summary;
271
+ lines.push(
272
+ `acceptance: ${summary.satisfied} satisfied, ${summary.unsatisfied} unsatisfied, ${summary.unknown} unknown`,
273
+ );
274
+ for (const criterion of proof.acceptance.criteria) {
275
+ const mark =
276
+ criterion.status === "satisfied" ? "PASS" : criterion.status === "unsatisfied" ? "FAIL" : "?";
277
+ const refs = criterion.evidence_ids.length > 0 ? ` [${criterion.evidence_ids.join(", ")}]` : "";
278
+ lines.push(` ${mark} ${criterion.id}: ${criterion.statement}${refs}`);
279
+ }
280
+ lines.push(`evidence: ${proof.evidence.length} record(s); agents: ${proof.agents.length}`);
281
+ const repo = proof.repository;
282
+ const drift = repo.drift;
283
+ lines.push(
284
+ `repository: branch ${repo.before.branch ?? "unknown"} -> ${repo.after.branch ?? "unknown"}; ` +
285
+ `HEAD ${short(repo.before.head)} -> ${short(repo.after.head)}; ` +
286
+ `${drift.dirty_paths_added.length} dirty added, ${drift.dirty_paths_cleared.length} cleared`,
287
+ );
288
+ if (proof.unknowns.length > 0) {
289
+ lines.push(`unknowns: ${proof.unknowns.length}`);
290
+ for (const unknown of proof.unknowns) lines.push(` - ${unknown.message}`);
291
+ }
292
+ lines.push(`journal sha256: ${proof.integrity.journal.sha256}`);
293
+ return `${lines.join("\n")}\n`;
294
+ }
295
+
296
+ function buildRepoEvidence(beforeRaw: RepoSnapshot, afterRaw: RepoSnapshot): WorkflowRepoEvidence {
297
+ const before = normalizeRepoSnapshot(beforeRaw);
298
+ const after = normalizeRepoSnapshot(afterRaw);
299
+ const beforeDirty = new Set(before.dirty_paths);
300
+ const afterDirty = new Set(after.dirty_paths);
301
+ const retained = after.dirty_paths.filter((path) => beforeDirty.has(path));
302
+ const incomplete = Boolean(
303
+ before.dirty_paths_truncated || after.dirty_paths_truncated || retained.length > 0,
304
+ );
305
+ return {
306
+ source: "engine",
307
+ before,
308
+ after,
309
+ drift: {
310
+ branch_changed: before.branch !== after.branch,
311
+ head_changed: before.head !== after.head,
312
+ dirty_paths_added: after.dirty_paths.filter((path) => !beforeDirty.has(path)),
313
+ dirty_paths_cleared: before.dirty_paths.filter((path) => !afterDirty.has(path)),
314
+ dirty_paths_retained: retained,
315
+ incomplete,
316
+ note: incomplete
317
+ ? "Snapshots cannot prove whether retained dirty paths changed during the run, and truncated lists may omit paths."
318
+ : undefined,
319
+ },
320
+ };
321
+ }
322
+
323
+ function normalizeRepoSnapshot(snapshot: RepoSnapshot): WorkflowRepoSnapshot {
324
+ return {
325
+ cwd: snapshot.cwd,
326
+ root: snapshot.root,
327
+ branch: snapshot.branch,
328
+ head: snapshot.head,
329
+ dirty_paths: snapshot.dirty_paths,
330
+ dirty_paths_truncated: snapshot.dirty_paths_truncated,
331
+ };
332
+ }
333
+
334
+ function buildHarnessCoverage(
335
+ agents: WorkflowAgentProof[],
336
+ claims: Readonly<Record<string, HarnessEvidenceCapability | undefined>> | undefined,
337
+ ): HarnessEvidenceCoverage[] {
338
+ return [...new Set(agents.map((agent) => agent.harness))].map((harness) => {
339
+ const harnessAgents = agents.filter((agent) => agent.harness === harness);
340
+ return {
341
+ harness,
342
+ tool_evidence: claims?.[harness]?.toolEvidence ?? {
343
+ support: "unknown",
344
+ note: "No harness capability claim was supplied to this workflow run.",
345
+ },
346
+ observed: {
347
+ final_results: harnessAgents.filter((agent) => agent.result).length,
348
+ session_ids: harnessAgents.filter((agent) => agent.session_id).length,
349
+ costs: harnessAgents.filter((agent) => agent.cost_usd !== undefined).length,
350
+ },
351
+ };
352
+ });
353
+ }
354
+
355
+ function buildUnknowns(
356
+ agents: WorkflowAgentProof[],
357
+ harnesses: HarnessEvidenceCoverage[],
358
+ repository: WorkflowRepoEvidence,
359
+ ): WorkflowProofUnknown[] {
360
+ const unknowns: WorkflowProofUnknown[] = [];
361
+ for (const harness of harnesses) {
362
+ if (harness.tool_evidence.support === "unknown") {
363
+ unknowns.push({
364
+ code: "harness_capability_unregistered",
365
+ harness: harness.harness,
366
+ message: `${harness.harness}: tool-evidence capability was not registered for this run.`,
367
+ });
368
+ } else if (harness.tool_evidence.support !== "supported") {
369
+ unknowns.push({
370
+ code: "tool_evidence_unavailable",
371
+ harness: harness.harness,
372
+ message: `${harness.harness}: adapter-native tool evidence is ${harness.tool_evidence.support}.`,
373
+ });
374
+ }
375
+ }
376
+ for (const agent of agents.filter((item) => item.status !== "failed")) {
377
+ if (agent.cost_usd === undefined) {
378
+ unknowns.push({
379
+ code: "agent_cost_unreported",
380
+ harness: agent.harness,
381
+ agent_id: agent.id,
382
+ message: `${agent.id}: ${agent.harness} did not report per-run cost.`,
383
+ });
384
+ }
385
+ if (!agent.session_id) {
386
+ unknowns.push({
387
+ code: "agent_session_unreported",
388
+ harness: agent.harness,
389
+ agent_id: agent.id,
390
+ message: `${agent.id}: ${agent.harness} did not report a child session id.`,
391
+ });
392
+ }
393
+ }
394
+ if (repository.drift.incomplete) {
395
+ unknowns.push({
396
+ code: "repository_drift_incomplete",
397
+ message: repository.drift.note ?? "Repository drift is incomplete.",
398
+ });
399
+ }
400
+ return unknowns;
401
+ }
402
+
403
+ function boundedRequired(value: unknown, field: string, max: number): string {
404
+ if (typeof value !== "string" || value.trim() === "") throw new Error(`${field} is required`);
405
+ const normalized = value.trim();
406
+ if (normalized.length > max) throw new Error(`${field} exceeds ${max} characters`);
407
+ return normalized;
408
+ }
409
+
410
+ function boundedOptional(value: unknown, field: string, max: number): string | undefined {
411
+ if (value === undefined) return undefined;
412
+ if (typeof value !== "string") throw new Error(`${field} must be a string`);
413
+ const normalized = value.trim();
414
+ if (normalized === "") return undefined;
415
+ if (normalized.length > max) throw new Error(`${field} exceeds ${max} characters`);
416
+ return normalized;
417
+ }
418
+
419
+ function enumValue<T extends string>(value: unknown, values: readonly T[], field: string): T {
420
+ if (typeof value === "string" && values.includes(value as T)) return value as T;
421
+ throw new Error(`${field} must be one of: ${values.join(", ")}`);
422
+ }
423
+
424
+ function short(value: string | undefined): string {
425
+ return value ? value.slice(0, 8) : "unknown";
426
+ }
427
+
428
+ function clipped(value: string, max: number): string {
429
+ return value.length <= max ? value : `${value.slice(0, Math.max(0, max - 1))}…`;
430
+ }
431
+
432
+ function clippedOptional(value: string | undefined, max: number): string | undefined {
433
+ return value === undefined ? undefined : clipped(value, max);
434
+ }
@@ -9,6 +9,164 @@
9
9
 
10
10
  import type { BillingMode, BillingProber } from "./billing.ts";
11
11
 
12
+ export const WORKFLOW_PROOF_SCHEMA_VERSION = 1 as const;
13
+
14
+ export type EvidenceKind = "test" | "command" | "artifact" | "change" | "review" | "observation";
15
+ export type EvidenceStatus = "passed" | "failed" | "observed" | "unknown";
16
+ export type EvidenceSource = "workflow" | "engine";
17
+ export type AcceptanceStatus = "satisfied" | "unsatisfied" | "unknown";
18
+ export type WorkflowRunStatus = "succeeded" | "failed";
19
+
20
+ export interface AcceptanceCriterion {
21
+ /** Stable identifier referenced by evidence, for example `tests-pass`. */
22
+ id: string;
23
+ statement: string;
24
+ }
25
+
26
+ export interface WorkflowEvidenceInput {
27
+ kind: EvidenceKind;
28
+ status: EvidenceStatus;
29
+ label: string;
30
+ summary?: string;
31
+ /** Inspectable local path, URL, command name, or other bounded reference. */
32
+ ref?: string;
33
+ /** Declared acceptance criteria this evidence bears on. */
34
+ acceptanceIds?: string[];
35
+ }
36
+
37
+ export interface WorkflowEvidenceRecord {
38
+ id: string;
39
+ source: EvidenceSource;
40
+ recorded_at: string;
41
+ kind: EvidenceKind;
42
+ status: EvidenceStatus;
43
+ label: string;
44
+ summary?: string;
45
+ ref?: string;
46
+ stage?: string;
47
+ acceptance_ids: string[];
48
+ }
49
+
50
+ export interface AcceptanceResult extends AcceptanceCriterion {
51
+ status: AcceptanceStatus;
52
+ evidence_ids: string[];
53
+ /** Sources behind the decisive evidence. Empty when status is unknown. */
54
+ sources: EvidenceSource[];
55
+ }
56
+
57
+ export interface AcceptanceSummary {
58
+ satisfied: number;
59
+ unsatisfied: number;
60
+ unknown: number;
61
+ total: number;
62
+ }
63
+
64
+ export interface ResultDigest {
65
+ kind: "text" | "json";
66
+ sha256: string;
67
+ bytes: number;
68
+ }
69
+
70
+ export interface WorkflowAgentProof {
71
+ id: string;
72
+ label: string;
73
+ stage?: string;
74
+ harness: HarnessName;
75
+ model?: string;
76
+ status: "succeeded" | "failed" | "cached";
77
+ attempts: number;
78
+ duration_ms: number;
79
+ cost_usd?: number;
80
+ session_id?: string;
81
+ result?: ResultDigest;
82
+ error?: string;
83
+ }
84
+
85
+ export interface WorkflowRepoSnapshot {
86
+ cwd: string;
87
+ root?: string;
88
+ branch?: string;
89
+ head?: string;
90
+ dirty_paths: string[];
91
+ dirty_paths_truncated?: boolean;
92
+ }
93
+
94
+ export interface WorkflowRepoEvidence {
95
+ source: "engine";
96
+ before: WorkflowRepoSnapshot;
97
+ after: WorkflowRepoSnapshot;
98
+ drift: {
99
+ branch_changed: boolean;
100
+ head_changed: boolean;
101
+ dirty_paths_added: string[];
102
+ dirty_paths_cleared: string[];
103
+ dirty_paths_retained: string[];
104
+ /** True when snapshots cannot prove whether every retained dirty path changed. */
105
+ incomplete: boolean;
106
+ note?: string;
107
+ };
108
+ }
109
+
110
+ export interface HarnessEvidenceCoverage {
111
+ harness: HarnessName;
112
+ tool_evidence: {
113
+ support: "supported" | "partial" | "unsupported" | "unknown";
114
+ note?: string;
115
+ };
116
+ observed: {
117
+ final_results: number;
118
+ session_ids: number;
119
+ costs: number;
120
+ };
121
+ }
122
+
123
+ export interface WorkflowProofUnknown {
124
+ code:
125
+ | "tool_evidence_unavailable"
126
+ | "harness_capability_unregistered"
127
+ | "agent_cost_unreported"
128
+ | "agent_session_unreported"
129
+ | "repository_drift_incomplete";
130
+ message: string;
131
+ harness?: HarnessName;
132
+ agent_id?: string;
133
+ }
134
+
135
+ export interface WorkflowProof {
136
+ schema_version: typeof WORKFLOW_PROOF_SCHEMA_VERSION;
137
+ run: {
138
+ id: string;
139
+ name: string;
140
+ status: WorkflowRunStatus;
141
+ started_at: string;
142
+ ended_at: string;
143
+ duration_ms: number;
144
+ objective?: string;
145
+ error?: string;
146
+ result?: ResultDigest;
147
+ };
148
+ acceptance: {
149
+ criteria: AcceptanceResult[];
150
+ summary: AcceptanceSummary;
151
+ };
152
+ agents: WorkflowAgentProof[];
153
+ evidence: WorkflowEvidenceRecord[];
154
+ repository: WorkflowRepoEvidence;
155
+ harnesses: HarnessEvidenceCoverage[];
156
+ unknowns: WorkflowProofUnknown[];
157
+ integrity: {
158
+ journal: {
159
+ path: "journal.jsonl";
160
+ sha256: string;
161
+ bytes: number;
162
+ };
163
+ };
164
+ }
165
+
166
+ export interface HarnessEvidenceCapability {
167
+ toolEvidence: HarnessEvidenceCoverage["tool_evidence"];
168
+ }
169
+
12
170
  /** JSON-schema *subset* accepted by stage gates (see validate.ts). */
13
171
  export interface StageSchema {
14
172
  type: "object" | "array" | "string" | "number" | "boolean";
@@ -94,11 +252,15 @@ export interface WorkflowContext {
94
252
  stage: (title: string) => void;
95
253
  /** Narrate progress (stderr + journal). */
96
254
  log: (message: string) => void;
255
+ /** Attach a bounded, sourced receipt to the run and optional acceptance criteria. */
256
+ evidence: (input: WorkflowEvidenceInput) => string;
97
257
  }
98
258
 
99
259
  export interface WorkflowMeta {
100
260
  name: string;
101
261
  description?: string;
262
+ objective?: string;
263
+ acceptance?: AcceptanceCriterion[];
102
264
  }
103
265
 
104
266
  /** Loaded script shape: `export const meta` + `export default async (ctx) => …`. */
@@ -138,6 +300,9 @@ export interface EngineOpts {
138
300
  allowApiBilling?: boolean;
139
301
  /** Billing-probe override for tests (default: the real probeBilling). */
140
302
  probeBilling?: BillingProber;
303
+ /** Capability claims used to state whether adapter-native tool evidence was
304
+ * available. Missing claims remain unknown. */
305
+ harnessEvidence?: Readonly<Record<HarnessName, HarnessEvidenceCapability | undefined>>;
141
306
  }
142
307
 
143
308
  export interface RunReport {
@@ -151,6 +316,8 @@ export interface RunReport {
151
316
  costUsd: number;
152
317
  durationMs: number;
153
318
  journalPath: string;
319
+ proofPath: string;
320
+ acceptance: AcceptanceSummary;
154
321
  /** Estimated tokens of repo instructions (CLAUDE.md/AGENTS.md at the child
155
322
  * cwd) that EVERY child cache-writes on spawn — the fixed per-child context
156
323
  * overhead a fan-out multiplies. bytes/4 heuristic; 0 when no such file. */