@reticlehq/terminal 0.0.0-stage → 3.11.1

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,75 @@
1
+ import { createServer } from 'node:http';
2
+ import { connect as connectTcp } from 'node:net';
3
+ /** What an HTTPS client means by a target with no port. */
4
+ const IMPLIED_TLS_PORT = 443;
5
+ export function startConnectProxy(input) {
6
+ const seen = [];
7
+ const open = new Set();
8
+ const server = createServer((_req, res) => {
9
+ // A plain request reaching a proxy is a tool that did not use CONNECT. Refused rather than
10
+ // forwarded: this is an observer, and quietly becoming a working proxy for cleartext traffic
11
+ // would put it in the path of bytes it has no business carrying.
12
+ res.writeHead(405).end();
13
+ });
14
+ server.on('connect', (req, clientSocket, head) => {
15
+ const { host, port } = parseTarget(req.url ?? '');
16
+ seen.push({ host, port, at: input.now() });
17
+ // Tunnel the bytes through untouched. Nothing here parses, decrypts or stores them: the
18
+ // whole point of this design is that the traffic is none of our business.
19
+ const upstream = connectTcp(port, host, () => {
20
+ clientSocket.write('HTTP/1.1 200 Connection Established\r\n\r\n');
21
+ if (head.length > 0)
22
+ upstream.write(head);
23
+ upstream.pipe(clientSocket);
24
+ clientSocket.pipe(upstream);
25
+ });
26
+ open.add(clientSocket);
27
+ open.add(upstream);
28
+ const drop = () => {
29
+ open.delete(clientSocket);
30
+ open.delete(upstream);
31
+ upstream.destroy();
32
+ clientSocket.destroy();
33
+ };
34
+ // A failure to REACH the far side is still a dial, and it is already recorded above. The
35
+ // attempt is the observation; whether it succeeded is the far side's business, and reporting
36
+ // a refused connection as "never called out" would be the observer's own failure showing up
37
+ // as a fact about the subject.
38
+ upstream.on('error', drop);
39
+ clientSocket.on('error', drop);
40
+ clientSocket.on('close', drop);
41
+ });
42
+ return new Promise((resolve) => {
43
+ server.listen(0, '127.0.0.1', () => {
44
+ const address = server.address();
45
+ const port = 'object' === typeof address && null !== address ? address.port : 0;
46
+ const url = `http://127.0.0.1:${String(port)}`;
47
+ resolve({
48
+ port,
49
+ connectsSince: (at) => seen.filter((c) => c.at >= at),
50
+ env: () => ({
51
+ HTTPS_PROXY: url,
52
+ https_proxy: url,
53
+ HTTP_PROXY: url,
54
+ http_proxy: url,
55
+ }),
56
+ stop: () => new Promise((done) => {
57
+ for (const socket of open)
58
+ socket.destroy();
59
+ open.clear();
60
+ server.close(() => done());
61
+ }),
62
+ });
63
+ });
64
+ });
65
+ }
66
+ /** `host:port`, or a bare host, which an HTTPS client means as port 443. */
67
+ function parseTarget(target) {
68
+ const at = target.lastIndexOf(':');
69
+ if (-1 === at)
70
+ return { host: target, port: IMPLIED_TLS_PORT };
71
+ const port = Number(target.slice(at + 1));
72
+ if (!Number.isInteger(port))
73
+ return { host: target, port: IMPLIED_TLS_PORT };
74
+ return { host: target.slice(0, at), port };
75
+ }
@@ -0,0 +1,73 @@
1
+ import type { ExitStatus, Invocation, RunWatcher, Supervisor, ToolIdentity } from './supervisor.js';
2
+ /**
3
+ * The `Supervisor` port, over real processes.
4
+ *
5
+ * Everything in this adapter that knows an operating system exists is here, which is what lets
6
+ * `TerminalRealm` be exercised against a fake and lets this be exercised against real programs. The two
7
+ * halves are hard in opposite directions: the realm's difficulty is arranging a kill or a fork,
8
+ * and this one's difficulty IS the arranging, so faking anything here would test the fake.
9
+ *
10
+ * It reports what happened and never whether it worked. A process that exits 1 is not a failure as
11
+ * far as this class is concerned; it is a process that exited 1.
12
+ */
13
+ export interface NodeSupervisorInput {
14
+ /** The tool's own executable. Everything else comes from the manifest's argv. */
15
+ readonly executable: string;
16
+ /** Where commands run, which is also half the subject's identity. */
17
+ readonly workspaceRoot: string;
18
+ readonly tool: ToolIdentity;
19
+ /** Injected, never `Date.now()` inline: a window's arithmetic must be reproducible. */
20
+ readonly now: () => number;
21
+ /**
22
+ * The environment to run under, when it should not be inherited wholesale.
23
+ *
24
+ * Absent means the parent's. Named rather than assumed because a verifier that silently hands a
25
+ * subject its own environment is one whose results depend on who ran it.
26
+ */
27
+ readonly env?: NodeJS.ProcessEnv;
28
+ /**
29
+ * How long to keep watching AFTER the process ends, for an effect that outlives it.
30
+ *
31
+ * A tool that forks and returns has not finished when it exits: the parent is gone and a child
32
+ * is still writing. Measured while planning this, a detached child left its artifact absent at
33
+ * the moment the parent exited and present a second and a half later.
34
+ *
35
+ * Without the wait a realm sees exit 0 over an empty filesystem and reports a tool that worked
36
+ * as one that did nothing -- and clause 3 of the adjudication order runs BEFORE the coverage
37
+ * check, so an `observed`-tier anomaly would convict it before `still-in-flight` was ever
38
+ * consulted.
39
+ *
40
+ * Defaults to none, because most commands do not fork and a wait nobody needs is a tax on every
41
+ * verification. It is the manifest's business to know which ones do.
42
+ */
43
+ readonly settleMs?: number;
44
+ }
45
+ export declare class NodeSupervisor implements Supervisor {
46
+ #private;
47
+ constructor(input: NodeSupervisorInput);
48
+ toolIdentity(): ToolIdentity;
49
+ invocationsSince(at: number): readonly Invocation[];
50
+ /**
51
+ * Run one command, and stop watching when the budget ends whether or not it did.
52
+ *
53
+ * The three outcomes are kept apart deliberately, because a realm above this cannot tell them
54
+ * apart afterwards if they are merged here:
55
+ *
56
+ * the process chose to end -> an exit code, `wasSignalled: false`
57
+ * something else ended it -> a signal, and NO exit code to mistake for one
58
+ * we stopped waiting -> no exit status at all, and no `endedAt`
59
+ *
60
+ * The third is the one worth stating. Killing the process on a budget and then reporting the
61
+ * signal WE sent would make our own impatience look like the operating system's verdict on the
62
+ * subject. So the kill happens and the absence is what gets recorded.
63
+ */
64
+ run(command: string, argv: readonly string[], budgetMs: number, watcher?: RunWatcher): Promise<Invocation>;
65
+ }
66
+ /**
67
+ * Whether the process chose how it ended, or had it chosen for it.
68
+ *
69
+ * Node reports one of the two as null, which is the distinction the protocol needs and the one
70
+ * that is lost the moment they are folded into a single number. Exported for its own test: the
71
+ * mapping is small, and it is the piece a reader is most likely to doubt.
72
+ */
73
+ export declare function exitStatus(code: number | null, signal: string | null): ExitStatus;
@@ -0,0 +1,150 @@
1
+ import { spawn } from 'node:child_process';
2
+ export class NodeSupervisor {
3
+ #input;
4
+ #seen = [];
5
+ #seq = 0;
6
+ constructor(input) {
7
+ this.#input = input;
8
+ }
9
+ toolIdentity() {
10
+ return this.#input.tool;
11
+ }
12
+ invocationsSince(at) {
13
+ return this.#seen.filter((i) => i.startedAt >= at);
14
+ }
15
+ /**
16
+ * Run one command, and stop watching when the budget ends whether or not it did.
17
+ *
18
+ * The three outcomes are kept apart deliberately, because a realm above this cannot tell them
19
+ * apart afterwards if they are merged here:
20
+ *
21
+ * the process chose to end -> an exit code, `wasSignalled: false`
22
+ * something else ended it -> a signal, and NO exit code to mistake for one
23
+ * we stopped waiting -> no exit status at all, and no `endedAt`
24
+ *
25
+ * The third is the one worth stating. Killing the process on a budget and then reporting the
26
+ * signal WE sent would make our own impatience look like the operating system's verdict on the
27
+ * subject. So the kill happens and the absence is what gets recorded.
28
+ */
29
+ run(command, argv, budgetMs, watcher) {
30
+ this.#seq += 1;
31
+ const id = `i${String(this.#seq)}`;
32
+ const startedAt = this.#input.now();
33
+ return new Promise((resolve, reject) => {
34
+ const child = spawn(this.#input.executable, [...argv], {
35
+ cwd: this.#input.workspaceRoot,
36
+ ...(this.#input.env === undefined ? {} : { env: this.#input.env }),
37
+ // stdin is CLOSED, not inherited. A tool that reads it would otherwise block to the budget
38
+ // on an input that never arrives, and that hang is indistinguishable from a real one.
39
+ // Phase 4's `x-cli.stdin` opens it deliberately, for a subject that is meant to be talked to.
40
+ stdio: ['ignore', 'pipe', 'pipe'],
41
+ });
42
+ // The watcher is handed each line as it is COMPLETED, not each chunk as it arrives: a
43
+ // chunk boundary is not a line boundary, and a live view showing half a word is a view
44
+ // somebody stops trusting.
45
+ const stdout = new LineReader(watcher?.onStdout);
46
+ const stderr = new LineReader(watcher?.onStderr);
47
+ child.stdout.on('data', (chunk) => stdout.push(chunk.toString('utf8')));
48
+ child.stderr.on('data', (chunk) => stderr.push(chunk.toString('utf8')));
49
+ let settled = false;
50
+ // Read once, here, because `finish` reports it and two call sites reach `finish`.
51
+ const settleMs = this.#input.settleMs ?? 0;
52
+ const finish = (exit, endedAt, settledMs = 0) => {
53
+ if (settled)
54
+ return;
55
+ settled = true;
56
+ clearTimeout(timer);
57
+ const invocation = {
58
+ id,
59
+ command,
60
+ argv: [...argv],
61
+ startedAt,
62
+ endedAt,
63
+ exit,
64
+ stdout: stdout.lines(),
65
+ stderr: stderr.lines(),
66
+ settledMs,
67
+ };
68
+ this.#seen.push(invocation);
69
+ resolve(invocation);
70
+ };
71
+ const timer = setTimeout(() => {
72
+ // We give up, and we say nothing about how the subject ended, because it did not.
73
+ child.kill('SIGKILL');
74
+ finish(undefined, undefined);
75
+ }, budgetMs);
76
+ child.on('error', (error) => {
77
+ if (settled)
78
+ return;
79
+ settled = true;
80
+ clearTimeout(timer);
81
+ // Failing to REACH the tool is not a fact about the tool. Nothing was learned about its
82
+ // behaviour, only about our ability to start it, so this is an error rather than an
83
+ // invocation reporting a failure.
84
+ reject(error);
85
+ });
86
+ child.on('close', (code, signal) => {
87
+ const exit = exitStatus(code, signal);
88
+ const endedAt = this.#input.now();
89
+ if (settleMs <= 0) {
90
+ finish(exit, endedAt);
91
+ return;
92
+ }
93
+ // `endedAt` is when the PROCESS ended, not when we stopped watching. The window closed on
94
+ // the subject's own ending, and the extra time is ours; recording the later instant would
95
+ // put our patience into the subject's timeline.
96
+ clearTimeout(timer);
97
+ setTimeout(() => finish(exit, endedAt, settleMs), settleMs);
98
+ });
99
+ });
100
+ }
101
+ }
102
+ /**
103
+ * Whether the process chose how it ended, or had it chosen for it.
104
+ *
105
+ * Node reports one of the two as null, which is the distinction the protocol needs and the one
106
+ * that is lost the moment they are folded into a single number. Exported for its own test: the
107
+ * mapping is small, and it is the piece a reader is most likely to doubt.
108
+ */
109
+ export function exitStatus(code, signal) {
110
+ if (signal !== null) {
111
+ // No exit code, deliberately. A killed process has none, and inventing one (the shell's
112
+ // 128+n convention, say) would file a kernel decision on the channel that carries the tool's
113
+ // own self-report.
114
+ return { code: undefined, signal, wasSignalled: true };
115
+ }
116
+ return { code: code ?? undefined, signal: undefined, wasSignalled: false };
117
+ }
118
+ /**
119
+ * Bytes to lines, holding a partial line until its newline arrives.
120
+ *
121
+ * A chunk boundary is not a line boundary, so splitting each chunk on its own would report one
122
+ * line as two whenever the pipe happened to break mid-word. The sequence is per-stream and never
123
+ * merged across the two: stdout and stderr are independently buffered, and a timestamp taken when
124
+ * a line is READ says nothing about when it was written.
125
+ */
126
+ class LineReader {
127
+ #pending = '';
128
+ #lines = [];
129
+ #onLine;
130
+ constructor(onLine) {
131
+ this.#onLine = onLine;
132
+ }
133
+ push(chunk) {
134
+ const parts = (this.#pending + chunk).split('\n');
135
+ // The last part has no newline yet: it is either an unfinished line or an empty string.
136
+ this.#pending = parts.pop() ?? '';
137
+ for (const text of parts) {
138
+ this.#lines.push({ seq: this.#lines.length, text });
139
+ this.#onLine?.(text);
140
+ }
141
+ }
142
+ /** Everything seen, including a trailing line the process never terminated. */
143
+ lines() {
144
+ if ('' !== this.#pending) {
145
+ this.#lines.push({ seq: this.#lines.length, text: this.#pending });
146
+ this.#pending = '';
147
+ }
148
+ return this.#lines;
149
+ }
150
+ }
@@ -0,0 +1,103 @@
1
+ /**
2
+ * The only thing here that talks to the operating system.
3
+ *
4
+ * A PORT, not a class. `TerminalRealm` depends on this interface and never on `node:child_process`, and
5
+ * the reason is not testability alone: a realm that could only be exercised by running real
6
+ * programs would be exercised rarely, and the cases worth exercising -- a kill, a fork whose effect
7
+ * lands after exit, a process that never ends -- are the ones hardest to produce on demand.
8
+ *
9
+ * It is also where every platform difference is allowed to live. A supervisor that drives a PTY
10
+ * (Phase 4) or routes through a proxy (Phase 3) implements the same interface; the realm above it
11
+ * does not learn a second shape.
12
+ */
13
+ /** One line of output, with the order it was read on ITS OWN stream. */
14
+ export interface StreamLine {
15
+ /**
16
+ * Position within this stream, and deliberately not a global clock.
17
+ *
18
+ * stdout and stderr are two independently buffered pipes, and a timestamp taken when a line is
19
+ * READ says nothing about when it was written. A merged ordering across the two streams would be
20
+ * fiction that reads like data, so the sequence is per-stream and no interleaving is offered.
21
+ */
22
+ readonly seq: number;
23
+ readonly text: string;
24
+ }
25
+ /**
26
+ * How a process ended, with the two halves kept apart.
27
+ *
28
+ * `code` is what the tool chose. `signal` is what was imposed on it. An implementation that
29
+ * reported one number for both would have to decide which of two provenances to lie about.
30
+ */
31
+ export interface ExitStatus {
32
+ /**
33
+ * The exit code, when there was one.
34
+ *
35
+ * Kept beside `wasSignalled` rather than encoded into one number, because exit codes wrap:
36
+ * `sh -c 'exit 256'` exits 0, so a large code is not always the code that was meant, and a
37
+ * single integer cannot distinguish a wrap from a success.
38
+ */
39
+ readonly code: number | undefined;
40
+ /** The signal that ended it, when something else ended it. */
41
+ readonly signal: string | undefined;
42
+ /** Whether the ending was imposed from outside. Decides `terminated` versus `exit`. */
43
+ readonly wasSignalled: boolean;
44
+ }
45
+ /** One run of one command, as this vantage point saw it. */
46
+ export interface Invocation {
47
+ readonly id: string;
48
+ /** The manifest command's name, not its argv. */
49
+ readonly command: string;
50
+ readonly argv: readonly string[];
51
+ readonly startedAt: number;
52
+ /** Absent while the process is still running. */
53
+ readonly endedAt: number | undefined;
54
+ /** Absent while the process is still running. */
55
+ readonly exit: ExitStatus | undefined;
56
+ readonly stdout: readonly StreamLine[];
57
+ readonly stderr: readonly StreamLine[];
58
+ /**
59
+ * How long we kept watching AFTER the process ended, waiting for a deferred effect to land.
60
+ *
61
+ * Reported rather than inferred so a test can assert the settle as a CONFIGURATION fact -- zero
62
+ * when nothing asked for one -- instead of timing the call and comparing against a wall clock.
63
+ * That comparison is a statement about the machine and fails only under parallel load; this is
64
+ * the same fact with no clock in it. It is also honest output in its own right: the subject's
65
+ * timeline ends at `endedAt`, and this is the part that was ours.
66
+ */
67
+ readonly settledMs: number;
68
+ }
69
+ /** Who the tool is, and which workspace it is pointed at. Half of it each. */
70
+ export interface ToolIdentity {
71
+ readonly id: string;
72
+ readonly version: string;
73
+ /** Stable for a workspace and different for a new one. A path, a git root, a hash: its choice. */
74
+ readonly workspace: string;
75
+ /** The build or commit, when knowable. */
76
+ readonly revision?: string;
77
+ /**
78
+ * The round of source edits, reported ONLY for a tool under development.
79
+ *
80
+ * Omitted for a released build, and the omission is deliberate rather than lazy: `fixtureIsUsable`
81
+ * requires an identical epoch, so an epoch that moves on every source edit makes every captured
82
+ * fixture unusable. Absence is not zero, which the protocol already says.
83
+ */
84
+ readonly epoch?: number;
85
+ }
86
+ /**
87
+ * Somebody watching a run as it happens rather than reading it afterwards.
88
+ *
89
+ * Optional, and a SUBSCRIBER: handed lines as they arrive, able to do nothing with them but look.
90
+ * The run is identical whether or not anybody is listening, which is what keeps a live view from
91
+ * becoming an observer that changes what it observes.
92
+ */
93
+ export interface RunWatcher {
94
+ onStdout?: (line: string) => void;
95
+ onStderr?: (line: string) => void;
96
+ }
97
+ export interface Supervisor {
98
+ /** Run one command to completion, or until the budget ends it. Reports what happened, never whether it worked. */
99
+ run(command: string, argv: readonly string[], budgetMs: number, watcher?: RunWatcher): Promise<Invocation>;
100
+ /** Everything this supervisor has seen since a moment on its own clock. */
101
+ invocationsSince(at: number): readonly Invocation[];
102
+ toolIdentity(): ToolIdentity;
103
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The only thing here that talks to the operating system.
3
+ *
4
+ * A PORT, not a class. `TerminalRealm` depends on this interface and never on `node:child_process`, and
5
+ * the reason is not testability alone: a realm that could only be exercised by running real
6
+ * programs would be exercised rarely, and the cases worth exercising -- a kill, a fork whose effect
7
+ * lands after exit, a process that never ends -- are the ones hardest to produce on demand.
8
+ *
9
+ * It is also where every platform difference is allowed to live. A supervisor that drives a PTY
10
+ * (Phase 4) or routes through a proxy (Phase 3) implements the same interface; the realm above it
11
+ * does not learn a second shape.
12
+ */
13
+ export {};
@@ -0,0 +1,47 @@
1
+ import { Declaration, Verdict, type BlindSpot, type Grade } from 'open-verification';
2
+ import type { Change } from './workspace/snapshot.js';
3
+ import type { ExitStatus } from './process/supervisor.js';
4
+ /**
5
+ * What a person sees when an agent verifies its own work.
6
+ *
7
+ * The web side of this project overlays a HUD on the thing being acted upon. A command-line tool
8
+ * acts on a filesystem, so the honest overlay is a DIFF -- and that is a better artifact than the
9
+ * web ever had, because humans already read diffs all day and nobody has ever learned to read a
10
+ * DOM mutation stream.
11
+ *
12
+ * Pure and deterministic: a record in, text out, no clock and no IO. The same drive renders the
13
+ * same report, which is what makes it safe to attach to a build and to compare two of them.
14
+ *
15
+ * ## The ordering is the design
16
+ *
17
+ * `EXPECT` is rendered above `RUN`, always. It is the one property a transcript can never show
18
+ * afterwards -- an expectation amended once the result is known reads exactly like an original one
19
+ * -- so putting it first is how a reader sees that the claim was pre-registered rather than
20
+ * back-filled.
21
+ *
22
+ * The exit code is printed, and printed where it is visibly NOT the thing that decided. Every
23
+ * reader arrives believing `exit 0` means it worked, so the report shows them the thing they trust
24
+ * and names what actually paid for the verdict beside it.
25
+ */
26
+ /** One drive, as the thing a report is rendered from. */
27
+ export interface DriveRecord {
28
+ /** What was declared, before the command ran. */
29
+ readonly expectation: string;
30
+ readonly command: string;
31
+ readonly argv: readonly string[];
32
+ readonly durationMs: number;
33
+ readonly exit: ExitStatus | undefined;
34
+ readonly changes: readonly Change[];
35
+ readonly blindSpots: readonly Pick<BlindSpot, 'kind' | 'detail' | 'impeaching'>[];
36
+ readonly adjudication: {
37
+ readonly verdict: Verdict;
38
+ readonly grade?: Grade;
39
+ readonly ground: string;
40
+ readonly reasons: readonly string[];
41
+ };
42
+ readonly declaredAt: Declaration;
43
+ /** The channel that bought a `yes`. Absent when nothing did, which is itself worth showing. */
44
+ readonly boughtBy: string | undefined;
45
+ readonly workspaceRoot: string;
46
+ }
47
+ export declare function renderReport(record: DriveRecord): string;
package/dist/report.js ADDED
@@ -0,0 +1,67 @@
1
+ import { Declaration, Verdict } from 'open-verification';
2
+ /**
3
+ * How each verdict reads to a person.
4
+ *
5
+ * `unknown` is the row that matters. "I could not see" and "the tool is broken" send a reader in
6
+ * opposite directions -- one says look again with better coverage, the other says go and fix
7
+ * something -- so the word must not be a synonym for failure. NOT PROVED says what happened.
8
+ */
9
+ const HEADLINE = {
10
+ [Verdict.YES]: 'yes',
11
+ [Verdict.NO]: 'no — CONTRADICTED',
12
+ [Verdict.UNKNOWN]: 'unknown — NOT PROVED',
13
+ [Verdict.NO_FAULT]: 'no-fault — nothing was declared to prove',
14
+ };
15
+ const KIND_MARK = {
16
+ written: 'A',
17
+ deleted: 'D',
18
+ modified: 'M',
19
+ 'mode-changed': 'X',
20
+ };
21
+ /** Paths relative to the workspace, because an absolute one is noise a reader has to skip. */
22
+ function relative(path, root) {
23
+ return path.startsWith(root) ? `.${path.slice(root.length)}` : path;
24
+ }
25
+ function exitText(exit) {
26
+ if (exit === undefined)
27
+ return 'still running';
28
+ if (exit.wasSignalled)
29
+ return `killed by ${String(exit.signal)}`;
30
+ return `exit ${String(exit.code)}`;
31
+ }
32
+ export function renderReport(record) {
33
+ const lines = [];
34
+ // Always first, and never conditional on the outcome.
35
+ lines.push(` EXPECT ${record.expectation}`);
36
+ if (record.declaredAt !== Declaration.BEFORE_ACTION) {
37
+ lines.push(' ↑ declared after the action, so it can be met and never proved');
38
+ }
39
+ const seconds = (record.durationMs / 1000).toFixed(1);
40
+ lines.push(` RUN ${record.command} ${record.argv.join(' ')}`.trimEnd() +
41
+ ` ${seconds}s ${exitText(record.exit)}`);
42
+ if (0 === record.changes.length) {
43
+ lines.push(' DIFF (nothing changed under the watched roots)');
44
+ }
45
+ else {
46
+ for (const [index, change] of record.changes.entries()) {
47
+ const label = 0 === index ? ' DIFF ' : ' ';
48
+ const mark = KIND_MARK[change.kind] ?? '?';
49
+ lines.push(`${label}${mark} ${relative(change.path, record.workspaceRoot)}`);
50
+ }
51
+ }
52
+ const gaps = record.blindSpots.map((s) => s.detail);
53
+ if (gaps.length > 0) {
54
+ lines.push(` BLIND ${gaps[0] ?? ''}`);
55
+ for (const gap of gaps.slice(1))
56
+ lines.push(` ${gap}`);
57
+ }
58
+ lines.push(` ${'─'.repeat(68)}`);
59
+ const bought = record.boughtBy === undefined
60
+ ? ''
61
+ : ` — bought by ${record.boughtBy}, independent, consequence grade`;
62
+ lines.push(` VERDICT ${HEADLINE[record.adjudication.verdict]}${bought}`);
63
+ const reason = record.adjudication.reasons[0];
64
+ if (reason !== undefined)
65
+ lines.push(` ${reason}`);
66
+ return lines.join('\n');
67
+ }
package/dist/run.d.ts ADDED
@@ -0,0 +1,46 @@
1
+ import { type Action, type ActionReceipt, type Anomaly, type ChannelDescriptor, type Claim, type Coverage, type Evidence, type Grade, type VerificationRun, type Verdict, type Window } from 'open-verification';
2
+ /** One claim, driven and adjudicated. Everything a verdict needs to be re-checked. */
3
+ export interface DriveOutcome {
4
+ readonly claim: Claim;
5
+ readonly action: Action;
6
+ readonly receipt: ActionReceipt;
7
+ readonly window: Window;
8
+ readonly channels: readonly ChannelDescriptor[];
9
+ readonly evidence: readonly Evidence[];
10
+ readonly coverage: Coverage;
11
+ readonly anomalies: readonly Anomaly[];
12
+ readonly adjudication: {
13
+ readonly verdict: Verdict;
14
+ readonly grade?: Grade;
15
+ readonly ground: string;
16
+ readonly reasons: readonly string[];
17
+ };
18
+ }
19
+ export interface RunInput {
20
+ readonly id: string;
21
+ /**
22
+ * The verifier's own version, supplied rather than written down here.
23
+ *
24
+ * It was a literal, and a literal in SOURCE is outside everything that stamps a release:
25
+ * `set-version.mjs` reaches manifests, docs.json, SKILL frontmatter and the crate files, and
26
+ * nothing it has ever done touches a string inside a `.ts`. So every run this realm emitted
27
+ * would have gone on claiming the previous version, for as long as nobody looked -- the exact
28
+ * shape of the crate that sat at 0.1.0 for months while its publish step printed "nothing to
29
+ * do" and exited green.
30
+ *
31
+ * A caller reads it from the package manifest, which set-version does reach.
32
+ */
33
+ readonly verifierVersion: string;
34
+ readonly drives: readonly DriveOutcome[];
35
+ readonly startedAt: number;
36
+ readonly endedAt: number;
37
+ }
38
+ /**
39
+ * Assemble the run.
40
+ *
41
+ * Note what is NOT here: a summary field. `outcomeOf` computes the outcome from the verdicts, and
42
+ * a producer that could write its own would be able to write one its verdicts do not support.
43
+ * That is the single lie this document must not be able to tell, so the shape simply does not
44
+ * offer somewhere to tell it.
45
+ */
46
+ export declare function buildRun(input: RunInput): VerificationRun;
package/dist/run.js ADDED
@@ -0,0 +1,71 @@
1
+ import { OVP_VERSION, } from 'open-verification';
2
+ /**
3
+ * The document a human and an agent both read, and a third party can re-check.
4
+ *
5
+ * `renderReport` produces something legible; this produces something CHECKABLE. The difference is
6
+ * the whole reason both exist: a report is a thing you have to trust the producer for, and a
7
+ * `VerificationRun` is a document somebody who has never heard of us can parse, re-adjudicate and
8
+ * disagree with.
9
+ *
10
+ * It is also the artifact both views are built from. A human reading a rendered report and an
11
+ * agent reading a verdict must never be looking at different evidence, because two parties
12
+ * disagreeing about what happened is the failure this whole design is shaped to prevent.
13
+ *
14
+ * PURE, with the clock injected. The same drives assemble the same document, which is what lets
15
+ * two of them be diffed and what makes it safe to attach to a build.
16
+ */
17
+ /** Who produced these runs. A named constant, because a wire string is never a free string. */
18
+ const VERIFIER_NAME = '@reticlehq/terminal';
19
+ /**
20
+ * Assemble the run.
21
+ *
22
+ * Note what is NOT here: a summary field. `outcomeOf` computes the outcome from the verdicts, and
23
+ * a producer that could write its own would be able to write one its verdicts do not support.
24
+ * That is the single lie this document must not be able to tell, so the shape simply does not
25
+ * offer somewhere to tell it.
26
+ */
27
+ export function buildRun(input) {
28
+ const first = input.drives[0];
29
+ return {
30
+ ovp: OVP_VERSION,
31
+ id: input.id,
32
+ verifier: {
33
+ name: VERIFIER_NAME,
34
+ version: input.verifierVersion,
35
+ // No profile claimed, and that is the honest answer rather than a missing one. The
36
+ // conformance floor names `net` and `log`, and this realm's consequence-grade channel is
37
+ // the filesystem, so it reaches no profile as the table is written. Profiles score an
38
+ // implementation; they do not gate one, and a run is worth reading either way.
39
+ },
40
+ subject: first?.window.subject ?? { surface: 'x-cli', instance: 'unknown' },
41
+ channels: [...(first?.channels ?? [])],
42
+ witnesses: [],
43
+ intents: [],
44
+ claims: input.drives.map((d) => d.claim),
45
+ constraints: [],
46
+ actions: input.drives.map((d) => d.action),
47
+ receipts: input.drives.map((d) => d.receipt),
48
+ windows: input.drives.map((d) => d.window),
49
+ evidence: input.drives.flatMap((d) => [...d.evidence]),
50
+ coverage: input.drives.map((d) => d.coverage),
51
+ anomalies: input.drives.flatMap((d) => [...d.anomalies]),
52
+ verdicts: input.drives.map((d, index) => ({
53
+ id: `v${String(index + 1)}`,
54
+ claim: d.claim.id,
55
+ window: d.window.id,
56
+ verdict: d.adjudication.verdict,
57
+ // Carried, never inferred. A `yes` whose grade is absent is a green nobody can price, and
58
+ // the difference between "something was on screen" and "the subject provably did it" is
59
+ // the difference this artifact exists to keep legible.
60
+ ...(d.adjudication.grade === undefined ? {} : { grade: d.adjudication.grade }),
61
+ reasons: [...d.adjudication.reasons],
62
+ evidence: d.evidence.map((e) => e.observation.id),
63
+ anomalies: [...d.anomalies],
64
+ at: d.window.closedAt ?? d.window.openedAt,
65
+ })),
66
+ violations: [],
67
+ repairs: [],
68
+ startedAt: input.startedAt,
69
+ endedAt: input.endedAt,
70
+ };
71
+ }