@reticlehq/terminal 0.0.0-stage → 3.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.
- package/LICENSE +202 -0
- package/NOTICE +12 -0
- package/README.md +15 -2
- package/bin/drive.mjs +222 -0
- package/dist/channels.d.ts +51 -0
- package/dist/channels.js +51 -0
- package/dist/detect.d.ts +8 -0
- package/dist/detect.js +176 -0
- package/dist/hud/frame.d.ts +47 -0
- package/dist/hud/frame.js +70 -0
- package/dist/hud/live.d.ts +56 -0
- package/dist/hud/live.js +92 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +19 -0
- package/dist/manifest.d.ts +60 -0
- package/dist/manifest.js +15 -0
- package/dist/net/proxy.d.ts +48 -0
- package/dist/net/proxy.js +75 -0
- package/dist/process/node-supervisor.d.ts +73 -0
- package/dist/process/node-supervisor.js +150 -0
- package/dist/process/supervisor.d.ts +103 -0
- package/dist/process/supervisor.js +13 -0
- package/dist/report.d.ts +47 -0
- package/dist/report.js +67 -0
- package/dist/run.d.ts +46 -0
- package/dist/run.js +71 -0
- package/dist/state-contract.d.ts +36 -0
- package/dist/state-contract.js +57 -0
- package/dist/terminal-realm.d.ts +161 -0
- package/dist/terminal-realm.js +647 -0
- package/dist/workspace/port.d.ts +34 -0
- package/dist/workspace/port.js +10 -0
- package/dist/workspace/snapshot.d.ts +73 -0
- package/dist/workspace/snapshot.js +145 -0
- package/package.json +54 -3
package/dist/detect.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { AnomalyKind, AnomalyTier } from 'open-verification';
|
|
2
|
+
import { TerminalChannel } from './channels.js';
|
|
3
|
+
import { TerminalSummary } from './terminal-realm.js';
|
|
4
|
+
/**
|
|
5
|
+
* Two things in one window that cannot both be true.
|
|
6
|
+
*
|
|
7
|
+
* Kept out of `TerminalRealm` because every rule here is a pure function of a window's observations:
|
|
8
|
+
* no clock, no filesystem, no process. That makes each one testable on its own, and it makes the
|
|
9
|
+
* set extensible without touching the realm, which is the open/closed shape the engine's own
|
|
10
|
+
* contradiction folds already use.
|
|
11
|
+
*
|
|
12
|
+
* ## The tier is the whole of the care
|
|
13
|
+
*
|
|
14
|
+
* Clause 3 of the adjudication order runs BEFORE the window check and before the coverage check.
|
|
15
|
+
* So an `observed`-tier anomaly convicts before `still-in-flight` or a dirty `closedBy` is ever
|
|
16
|
+
* consulted, and a tool that forks, returns, and lands its effect a second later would be
|
|
17
|
+
* convicted for behaving correctly.
|
|
18
|
+
*
|
|
19
|
+
* The rule the specification states and this file obeys: "the thing I expected had not happened
|
|
20
|
+
* yet when I stopped looking" is NOT "it did not happen". Anything derived from an absence is
|
|
21
|
+
* `absence-derived`, may downgrade a verdict to `unknown`, and may never force a `no`.
|
|
22
|
+
*
|
|
23
|
+
* Only one rule here is `observed`, and it is the one where an independent channel positively saw
|
|
24
|
+
* something: the operating system ended the process while the tool was announcing success.
|
|
25
|
+
*/
|
|
26
|
+
/** Words a tool uses when it believes it did something. Deliberately few, and deliberately dumb. */
|
|
27
|
+
const SUCCESS_WORDS = [
|
|
28
|
+
'success',
|
|
29
|
+
'succeeded',
|
|
30
|
+
'done',
|
|
31
|
+
'complete',
|
|
32
|
+
'completed',
|
|
33
|
+
'wrote',
|
|
34
|
+
'created',
|
|
35
|
+
'generated',
|
|
36
|
+
'built',
|
|
37
|
+
'updated',
|
|
38
|
+
'finished',
|
|
39
|
+
'✓',
|
|
40
|
+
'✔',
|
|
41
|
+
];
|
|
42
|
+
/**
|
|
43
|
+
* Did the tool's own output claim it did something?
|
|
44
|
+
*
|
|
45
|
+
* A HEURISTIC over prose, and it is only ever allowed to raise a suspicion -- never to decide
|
|
46
|
+
* anything on its own. That is why every rule built on it is absence-derived or needs an
|
|
47
|
+
* independent channel to agree: matching English is not evidence, and a verifier that convicted on
|
|
48
|
+
* a substring would be reading the subject's prose as though it were a fact.
|
|
49
|
+
*/
|
|
50
|
+
function claimsSuccess(observations) {
|
|
51
|
+
for (const observation of observations) {
|
|
52
|
+
if (observation.channel !== TerminalChannel.LOG)
|
|
53
|
+
continue;
|
|
54
|
+
const text = 'string' === typeof observation.value ? observation.value : '';
|
|
55
|
+
const lower = text.toLowerCase();
|
|
56
|
+
if (SUCCESS_WORDS.some((word) => lower.includes(word)))
|
|
57
|
+
return text;
|
|
58
|
+
}
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
const on = (observations, channel) => observations.filter((o) => o.channel === channel);
|
|
62
|
+
/**
|
|
63
|
+
* The tool announced success and the operating system killed it.
|
|
64
|
+
*
|
|
65
|
+
* The only OBSERVED-tier rule here, and it is entitled to convict because `x-proc` is independent:
|
|
66
|
+
* the kernel decided the ending and the tool had no say. This pairing is the entire reason the
|
|
67
|
+
* exit status is split across two channels. Merged into one, this would be two actuation-derived
|
|
68
|
+
* channels disagreeing, which `disagreementCanConvict` correctly refuses to act on -- and a real
|
|
69
|
+
* crash would be unreportable as a fault.
|
|
70
|
+
*/
|
|
71
|
+
function claimedOverKill(observations) {
|
|
72
|
+
const killed = on(observations, TerminalChannel.PROCESS).find((o) => o.summary === TerminalSummary.TERMINATED_SIGNAL);
|
|
73
|
+
if (killed === undefined)
|
|
74
|
+
return undefined;
|
|
75
|
+
const claim = claimsSuccess(observations);
|
|
76
|
+
if (claim === undefined)
|
|
77
|
+
return undefined;
|
|
78
|
+
return {
|
|
79
|
+
kind: AnomalyKind.CLAIMED_OVER_FAILURE,
|
|
80
|
+
tier: AnomalyTier.OBSERVED,
|
|
81
|
+
claim: `the tool reported: ${claim}`,
|
|
82
|
+
counter: `the operating system ended it with ${String(killed.value)}, which the tool did not choose`,
|
|
83
|
+
between: [TerminalChannel.LOG, TerminalChannel.PROCESS],
|
|
84
|
+
evidence: [killed.id],
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The tool said it wrote something and the filesystem recorded nothing.
|
|
89
|
+
*
|
|
90
|
+
* Absence-derived, not observed, and the difference is a tool that forks. A command that returns
|
|
91
|
+
* while a child is still writing has produced exactly this shape, and it is working correctly;
|
|
92
|
+
* convicting it would make every daemonising CLI permanently unprovable.
|
|
93
|
+
*/
|
|
94
|
+
function claimedWriteNeverLanded(observations) {
|
|
95
|
+
const claim = claimsSuccess(observations);
|
|
96
|
+
if (claim === undefined)
|
|
97
|
+
return undefined;
|
|
98
|
+
if (on(observations, TerminalChannel.ARTIFACT).length > 0)
|
|
99
|
+
return undefined;
|
|
100
|
+
return {
|
|
101
|
+
kind: AnomalyKind.ADVANCED_OVER_FAILURE,
|
|
102
|
+
tier: AnomalyTier.ABSENCE_DERIVED,
|
|
103
|
+
claim: `the tool reported: ${claim}`,
|
|
104
|
+
counter: 'nothing was recorded on the filesystem inside this window; the effect may be outside the ' +
|
|
105
|
+
'declared roots, in a child process, or still to land',
|
|
106
|
+
between: [TerminalChannel.LOG, TerminalChannel.ARTIFACT],
|
|
107
|
+
evidence: [],
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The action was delivered and nothing anywhere recorded anything.
|
|
112
|
+
*
|
|
113
|
+
* Absence-derived for the same reason: silence inside a window whose end WE chose is not proof
|
|
114
|
+
* that nothing happened. It is a reason to look again, which is exactly what `unknown` tells a
|
|
115
|
+
* caller to do.
|
|
116
|
+
*/
|
|
117
|
+
function noTraceAtAll(observations) {
|
|
118
|
+
if (observations.length > 0)
|
|
119
|
+
return undefined;
|
|
120
|
+
return {
|
|
121
|
+
kind: AnomalyKind.NO_EFFECT,
|
|
122
|
+
tier: AnomalyTier.ABSENCE_DERIVED,
|
|
123
|
+
claim: 'the command was dispatched',
|
|
124
|
+
counter: 'no channel recorded anything at all before the window closed',
|
|
125
|
+
between: [TerminalChannel.LOG, TerminalChannel.ARTIFACT],
|
|
126
|
+
evidence: [],
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* A host the command said it would reach, and no connection to it in the window.
|
|
131
|
+
*
|
|
132
|
+
* The rule the proxy exists for, and the one a shell can never implement: an agent with `Bash`
|
|
133
|
+
* cannot see that a command never called out. `exit 0` and a confident line of output look
|
|
134
|
+
* identical whether the request went or not.
|
|
135
|
+
*
|
|
136
|
+
* Absence-derived, like everything else built on a silence. A dial that happened after the window
|
|
137
|
+
* closed, or through a route the proxy does not sit on, produces this shape while the tool is
|
|
138
|
+
* working correctly -- so it may downgrade a verdict to `unknown` and may never force a `no`.
|
|
139
|
+
*/
|
|
140
|
+
function neverDialled(observations, expected) {
|
|
141
|
+
if (0 === expected.length)
|
|
142
|
+
return undefined;
|
|
143
|
+
const dialled = new Set(on(observations, TerminalChannel.NET).map((o) => 'object' === typeof o.value && null !== o.value
|
|
144
|
+
? String(o.value.host)
|
|
145
|
+
: ''));
|
|
146
|
+
const missed = expected.filter((host) => !dialled.has(host));
|
|
147
|
+
if (0 === missed.length)
|
|
148
|
+
return undefined;
|
|
149
|
+
return {
|
|
150
|
+
kind: 'x-never-dialled',
|
|
151
|
+
tier: AnomalyTier.ABSENCE_DERIVED,
|
|
152
|
+
claim: `the command was declared to reach ${missed.join(', ')}`,
|
|
153
|
+
counter: 'no connection to it was seen before the window closed',
|
|
154
|
+
between: [TerminalChannel.NET, TerminalChannel.LOG],
|
|
155
|
+
evidence: [],
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* The rules, as a list, so adding one is adding a function.
|
|
160
|
+
*
|
|
161
|
+
* Each takes a window's observations and returns an anomaly or nothing. None of them reads a
|
|
162
|
+
* clock, a disk or a process, which is what keeps them testable and what stops a rule quietly
|
|
163
|
+
* becoming a second observer.
|
|
164
|
+
*/
|
|
165
|
+
const RULES = [
|
|
166
|
+
claimedOverKill,
|
|
167
|
+
claimedWriteNeverLanded,
|
|
168
|
+
noTraceAtAll,
|
|
169
|
+
];
|
|
170
|
+
/** Every disagreement these rules can see in one window. */
|
|
171
|
+
export function detectAnomalies(observations, context = {}) {
|
|
172
|
+
return [
|
|
173
|
+
...RULES.map((rule) => rule(observations)),
|
|
174
|
+
neverDialled(observations, context.reaches ?? []),
|
|
175
|
+
].filter((a) => undefined !== a);
|
|
176
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Verdict } from 'open-verification';
|
|
2
|
+
import type { Change } from '../workspace/snapshot.js';
|
|
3
|
+
import type { ExitStatus } from '../process/supervisor.js';
|
|
4
|
+
/**
|
|
5
|
+
* The pane a person watches while an agent verifies its own work.
|
|
6
|
+
*
|
|
7
|
+
* The web side overlays a HUD on the page being acted upon. A command-line tool acts on a
|
|
8
|
+
* filesystem and a process, so this is the equivalent: the claim, the command, what is being
|
|
9
|
+
* watched, what has landed so far, and a verdict that is honestly absent until there is one.
|
|
10
|
+
*
|
|
11
|
+
* PURE. State in, a frame of text out — no clock, no terminal, no IO. The caller owns the screen
|
|
12
|
+
* and the ticking, which is what makes every property below testable without a terminal and what
|
|
13
|
+
* keeps the renderer from becoming a second observer of the thing it is describing.
|
|
14
|
+
*
|
|
15
|
+
* ## Two rows that are here for the same reason
|
|
16
|
+
*
|
|
17
|
+
* `EXPECT` is on screen from the first frame, before anything has happened. Watching is the ONLY
|
|
18
|
+
* moment a human can see that a claim was pre-registered — afterwards a transcript cannot show it,
|
|
19
|
+
* because an expectation amended once the result is known reads exactly like an original one.
|
|
20
|
+
*
|
|
21
|
+
* `WATCHING` names the channels. "Nothing was watching" and "it did not happen" produce identical
|
|
22
|
+
* silence, and this is the one place a person can tell them apart BEFORE the verdict lands.
|
|
23
|
+
*/
|
|
24
|
+
export type HudPhase = 'running' | 'done';
|
|
25
|
+
export interface HudState {
|
|
26
|
+
readonly expectation: string;
|
|
27
|
+
readonly command: string;
|
|
28
|
+
readonly argv: readonly string[];
|
|
29
|
+
readonly elapsedMs: number;
|
|
30
|
+
readonly phase: HudPhase;
|
|
31
|
+
readonly watching: readonly string[];
|
|
32
|
+
readonly stdout: readonly string[];
|
|
33
|
+
readonly stderr: readonly string[];
|
|
34
|
+
readonly changes: readonly Change[];
|
|
35
|
+
readonly dials: readonly {
|
|
36
|
+
host: string;
|
|
37
|
+
port: number;
|
|
38
|
+
}[];
|
|
39
|
+
readonly exit: ExitStatus | undefined;
|
|
40
|
+
readonly verdict: {
|
|
41
|
+
verdict: Verdict;
|
|
42
|
+
ground: string;
|
|
43
|
+
boughtBy: string | undefined;
|
|
44
|
+
} | undefined;
|
|
45
|
+
readonly workspaceRoot: string;
|
|
46
|
+
}
|
|
47
|
+
export declare function renderFrame(state: HudState): string;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Verdict } from 'open-verification';
|
|
2
|
+
/** How each verdict reads. `unknown` must never look like a failure to somebody scanning. */
|
|
3
|
+
const HEADLINE = {
|
|
4
|
+
[Verdict.YES]: 'yes',
|
|
5
|
+
[Verdict.NO]: 'no — CONTRADICTED',
|
|
6
|
+
[Verdict.UNKNOWN]: 'unknown — NOT PROVED',
|
|
7
|
+
[Verdict.NO_FAULT]: 'no-fault — nothing was declared',
|
|
8
|
+
};
|
|
9
|
+
const MARK = {
|
|
10
|
+
written: '+',
|
|
11
|
+
deleted: '-',
|
|
12
|
+
modified: '~',
|
|
13
|
+
'mode-changed': 'x',
|
|
14
|
+
};
|
|
15
|
+
/** Frames of a spinner, indexed by elapsed time so the caller need not hold a counter. */
|
|
16
|
+
const SPIN = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
17
|
+
/** How many lines of each stream to keep on screen. The rest is in the artifact. */
|
|
18
|
+
const TAIL = 3;
|
|
19
|
+
const relative = (path, root) => path.startsWith(root) ? `.${path.slice(root.length)}` : path;
|
|
20
|
+
function exitText(exit) {
|
|
21
|
+
if (exit === undefined)
|
|
22
|
+
return '';
|
|
23
|
+
if (exit.wasSignalled)
|
|
24
|
+
return ` killed by ${String(exit.signal)}`;
|
|
25
|
+
return ` exit ${String(exit.code)}`;
|
|
26
|
+
}
|
|
27
|
+
export function renderFrame(state) {
|
|
28
|
+
const seconds = (state.elapsedMs / 1000).toFixed(1);
|
|
29
|
+
const spinner = 'running' === state.phase ? (SPIN[Math.floor(state.elapsedMs / 80) % SPIN.length] ?? '⠋') : '·';
|
|
30
|
+
const label = 'running' === state.phase ? 'RUNNING' : 'RAN';
|
|
31
|
+
const lines = [
|
|
32
|
+
` ${spinner} ${label.padEnd(8)} ${state.command} ${state.argv.join(' ')}`.trimEnd() +
|
|
33
|
+
` ${seconds}s${exitText(state.exit)}`,
|
|
34
|
+
` EXPECT ${state.expectation}`,
|
|
35
|
+
` WATCHING ${state.watching.join(' · ')}`,
|
|
36
|
+
];
|
|
37
|
+
const tail = (rows) => rows.slice(-TAIL);
|
|
38
|
+
for (const [index, line] of tail(state.stdout).entries()) {
|
|
39
|
+
lines.push(` ${0 === index ? 'OUT ' : ' '} ${line}`);
|
|
40
|
+
}
|
|
41
|
+
for (const [index, line] of tail(state.stderr).entries()) {
|
|
42
|
+
lines.push(` ${0 === index ? 'ERR ' : ' '} ${line}`);
|
|
43
|
+
}
|
|
44
|
+
if (state.changes.length > 0) {
|
|
45
|
+
const shown = state.changes.slice(0, 6);
|
|
46
|
+
for (const [index, change] of shown.entries()) {
|
|
47
|
+
const head = 0 === index ? 'FS ' : ' ';
|
|
48
|
+
lines.push(` ${head} ${MARK[change.kind] ?? '?'} ${relative(change.path, state.workspaceRoot)}`);
|
|
49
|
+
}
|
|
50
|
+
if (state.changes.length > shown.length) {
|
|
51
|
+
lines.push(` … ${String(state.changes.length - shown.length)} more`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
for (const [index, dial] of state.dials.slice(0, 3).entries()) {
|
|
55
|
+
lines.push(` ${0 === index ? 'NET ' : ' '} ${dial.host}:${String(dial.port)}`);
|
|
56
|
+
}
|
|
57
|
+
lines.push(` ${'─'.repeat(64)}`);
|
|
58
|
+
if (state.verdict === undefined) {
|
|
59
|
+
// Never a blank where a verdict goes: a blank is read as a pass by anybody scanning.
|
|
60
|
+
lines.push(' VERDICT pending — nothing is proved until the window closes');
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const bought = state.verdict.boughtBy === undefined
|
|
64
|
+
? ''
|
|
65
|
+
: ` — bought by ${state.verdict.boughtBy}, independent, consequence grade`;
|
|
66
|
+
lines.push(` VERDICT ${HEADLINE[state.verdict.verdict]}${bought}`);
|
|
67
|
+
lines.push(` ${state.verdict.ground}`);
|
|
68
|
+
}
|
|
69
|
+
return lines.join('\n');
|
|
70
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type HudState } from './frame.js';
|
|
2
|
+
import type { Change } from '../workspace/snapshot.js';
|
|
3
|
+
import type { ExitStatus } from '../process/supervisor.js';
|
|
4
|
+
/**
|
|
5
|
+
* The screen half: hold the state, paint it, repaint in place.
|
|
6
|
+
*
|
|
7
|
+
* Split from `renderFrame` so the frame stays a pure function of state. Everything that makes a
|
|
8
|
+
* terminal a terminal -- cursor control, a repaint timer, whether there is even a TTY -- lives
|
|
9
|
+
* here, and none of it can leak into what the pane SAYS.
|
|
10
|
+
*
|
|
11
|
+
* It is a SUBSCRIBER and never a participant. It reads events, holds no opinion, and cannot change
|
|
12
|
+
* what happens: closing the pane leaves the run identical. A view that could affect the subject
|
|
13
|
+
* would be an observer contaminating its own observation, which is the confusion this project
|
|
14
|
+
* exists to refuse.
|
|
15
|
+
*/
|
|
16
|
+
/** What the pane needs to hear. Everything else about a run is the artifact's business. */
|
|
17
|
+
export type HudEvent = {
|
|
18
|
+
kind: 'started';
|
|
19
|
+
command: string;
|
|
20
|
+
argv: readonly string[];
|
|
21
|
+
watching: readonly string[];
|
|
22
|
+
} | {
|
|
23
|
+
kind: 'stdout';
|
|
24
|
+
text: string;
|
|
25
|
+
} | {
|
|
26
|
+
kind: 'stderr';
|
|
27
|
+
text: string;
|
|
28
|
+
} | {
|
|
29
|
+
kind: 'changed';
|
|
30
|
+
changes: readonly Change[];
|
|
31
|
+
} | {
|
|
32
|
+
kind: 'dialled';
|
|
33
|
+
host: string;
|
|
34
|
+
port: number;
|
|
35
|
+
} | {
|
|
36
|
+
kind: 'ended';
|
|
37
|
+
exit: ExitStatus | undefined;
|
|
38
|
+
} | {
|
|
39
|
+
kind: 'verdict';
|
|
40
|
+
verdict: HudState['verdict'];
|
|
41
|
+
};
|
|
42
|
+
export interface LiveHudInput {
|
|
43
|
+
readonly expectation: string;
|
|
44
|
+
readonly workspaceRoot: string;
|
|
45
|
+
/** Injected, so the elapsed time in a frame is reproducible in a test. */
|
|
46
|
+
readonly now: () => number;
|
|
47
|
+
/** Where to paint. Absent means nowhere, which is how a non-interactive run stays silent. */
|
|
48
|
+
readonly write?: (frame: string) => void;
|
|
49
|
+
}
|
|
50
|
+
export interface LiveHud {
|
|
51
|
+
send(event: HudEvent): void;
|
|
52
|
+
/** The current frame, for a caller that wants the text rather than the screen. */
|
|
53
|
+
frame(): string;
|
|
54
|
+
stop(): void;
|
|
55
|
+
}
|
|
56
|
+
export declare function createLiveHud(input: LiveHudInput): LiveHud;
|
package/dist/hud/live.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { renderFrame } from './frame.js';
|
|
2
|
+
/** The terminal control codes this pane uses, named so no reader has to decode them. */
|
|
3
|
+
const ESC = String.fromCharCode(27);
|
|
4
|
+
const cursorUp = (n) => `${ESC}[${String(n)}A`;
|
|
5
|
+
const clearBelow = `${ESC}[0J`;
|
|
6
|
+
/**
|
|
7
|
+
* Repaint by rewinding exactly as many lines as were painted.
|
|
8
|
+
*
|
|
9
|
+
* Not a screen clear, which throws away scrollback somebody may be reading, and not a fresh block
|
|
10
|
+
* per tick, which fills a terminal with hundreds of near-identical frames and makes the run
|
|
11
|
+
* unreadable afterwards.
|
|
12
|
+
*/
|
|
13
|
+
function repainter(write) {
|
|
14
|
+
let painted = 0;
|
|
15
|
+
return (frame) => {
|
|
16
|
+
const rewind = painted > 0 ? `${cursorUp(painted)}${clearBelow}` : '';
|
|
17
|
+
write(`${rewind}${frame}\n`);
|
|
18
|
+
painted = frame.split('\n').length + 1;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function createLiveHud(input) {
|
|
22
|
+
const startedAt = input.now();
|
|
23
|
+
let phase = 'running';
|
|
24
|
+
const state = {
|
|
25
|
+
expectation: input.expectation,
|
|
26
|
+
command: '',
|
|
27
|
+
argv: [],
|
|
28
|
+
watching: [],
|
|
29
|
+
stdout: [],
|
|
30
|
+
stderr: [],
|
|
31
|
+
changes: [],
|
|
32
|
+
dials: [],
|
|
33
|
+
exit: undefined,
|
|
34
|
+
verdict: undefined,
|
|
35
|
+
};
|
|
36
|
+
const paint = input.write === undefined ? undefined : repainter(input.write);
|
|
37
|
+
const build = () => ({
|
|
38
|
+
...state,
|
|
39
|
+
elapsedMs: input.now() - startedAt,
|
|
40
|
+
phase,
|
|
41
|
+
workspaceRoot: input.workspaceRoot,
|
|
42
|
+
});
|
|
43
|
+
/*
|
|
44
|
+
* A ticking repaint, so elapsed time and the spinner move while a slow tool is thinking.
|
|
45
|
+
* Without it the pane freezes on a tool that takes twenty seconds to say anything, which reads
|
|
46
|
+
* as a hang rather than as work. Unref'd: a view must never hold a process open.
|
|
47
|
+
*/
|
|
48
|
+
const timer = paint === undefined
|
|
49
|
+
? undefined
|
|
50
|
+
: setInterval(() => {
|
|
51
|
+
if ('running' === phase)
|
|
52
|
+
paint(renderFrame(build()));
|
|
53
|
+
}, 120);
|
|
54
|
+
timer?.unref?.();
|
|
55
|
+
return {
|
|
56
|
+
send(event) {
|
|
57
|
+
switch (event.kind) {
|
|
58
|
+
case 'started':
|
|
59
|
+
state.command = event.command;
|
|
60
|
+
state.argv = event.argv;
|
|
61
|
+
state.watching = event.watching;
|
|
62
|
+
break;
|
|
63
|
+
case 'stdout':
|
|
64
|
+
state.stdout.push(event.text);
|
|
65
|
+
break;
|
|
66
|
+
case 'stderr':
|
|
67
|
+
state.stderr.push(event.text);
|
|
68
|
+
break;
|
|
69
|
+
case 'changed':
|
|
70
|
+
state.changes = event.changes;
|
|
71
|
+
break;
|
|
72
|
+
case 'dialled':
|
|
73
|
+
state.dials.push({ host: event.host, port: event.port });
|
|
74
|
+
break;
|
|
75
|
+
case 'ended':
|
|
76
|
+
state.exit = event.exit;
|
|
77
|
+
phase = 'done';
|
|
78
|
+
break;
|
|
79
|
+
case 'verdict':
|
|
80
|
+
state.verdict = event.verdict;
|
|
81
|
+
phase = 'done';
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
paint?.(renderFrame(build()));
|
|
85
|
+
},
|
|
86
|
+
frame: () => renderFrame(build()),
|
|
87
|
+
stop() {
|
|
88
|
+
if (timer !== undefined)
|
|
89
|
+
clearInterval(timer);
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The front door.
|
|
3
|
+
*
|
|
4
|
+
* A realm for a subject that runs and exits, and the port it needs from the operating system.
|
|
5
|
+
* Nothing here spawns anything: `TerminalRealm` is given a `Supervisor` and knows the world only
|
|
6
|
+
* through it.
|
|
7
|
+
*/
|
|
8
|
+
export { TerminalRealm, TerminalSummary, closedBy } from './terminal-realm.js';
|
|
9
|
+
export type { TerminalRealmDeps } from './terminal-realm.js';
|
|
10
|
+
export { TerminalChannel } from './channels.js';
|
|
11
|
+
export { NodeSupervisor, exitStatus } from './process/node-supervisor.js';
|
|
12
|
+
export { nodeWorkspace } from './workspace/port.js';
|
|
13
|
+
export { detectAnomalies } from './detect.js';
|
|
14
|
+
export { renderReport } from './report.js';
|
|
15
|
+
export { renderFrame } from './hud/frame.js';
|
|
16
|
+
export type { HudState, HudPhase } from './hud/frame.js';
|
|
17
|
+
export { createLiveHud } from './hud/live.js';
|
|
18
|
+
export type { HudEvent, LiveHud, LiveHudInput } from './hud/live.js';
|
|
19
|
+
export { buildRun } from './run.js';
|
|
20
|
+
export type { DriveOutcome, RunInput } from './run.js';
|
|
21
|
+
export { startConnectProxy } from './net/proxy.js';
|
|
22
|
+
export type { ConnectAttempt, ConnectProxy, ConnectProxyInput } from './net/proxy.js';
|
|
23
|
+
export type { DriveRecord } from './report.js';
|
|
24
|
+
export type { WorkspacePort } from './workspace/port.js';
|
|
25
|
+
export { ChangeKind, diffSnapshots, takeSnapshot, EXCLUDED_BY_DEFAULT, } from './workspace/snapshot.js';
|
|
26
|
+
export type { Change, FileFact, Snapshot, SnapshotOptions } from './workspace/snapshot.js';
|
|
27
|
+
export type { NodeSupervisorInput } from './process/node-supervisor.js';
|
|
28
|
+
export { commandNamed } from './manifest.js';
|
|
29
|
+
export type { CliCommand, CommandManifest } from './manifest.js';
|
|
30
|
+
export type { ExitStatus, RunWatcher, Invocation, StreamLine, Supervisor, ToolIdentity, } from './process/supervisor.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The front door.
|
|
3
|
+
*
|
|
4
|
+
* A realm for a subject that runs and exits, and the port it needs from the operating system.
|
|
5
|
+
* Nothing here spawns anything: `TerminalRealm` is given a `Supervisor` and knows the world only
|
|
6
|
+
* through it.
|
|
7
|
+
*/
|
|
8
|
+
export { TerminalRealm, TerminalSummary, closedBy } from './terminal-realm.js';
|
|
9
|
+
export { TerminalChannel } from './channels.js';
|
|
10
|
+
export { NodeSupervisor, exitStatus } from './process/node-supervisor.js';
|
|
11
|
+
export { nodeWorkspace } from './workspace/port.js';
|
|
12
|
+
export { detectAnomalies } from './detect.js';
|
|
13
|
+
export { renderReport } from './report.js';
|
|
14
|
+
export { renderFrame } from './hud/frame.js';
|
|
15
|
+
export { createLiveHud } from './hud/live.js';
|
|
16
|
+
export { buildRun } from './run.js';
|
|
17
|
+
export { startConnectProxy } from './net/proxy.js';
|
|
18
|
+
export { ChangeKind, diffSnapshots, takeSnapshot, EXCLUDED_BY_DEFAULT, } from './workspace/snapshot.js';
|
|
19
|
+
export { commandNamed } from './manifest.js';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the tool under test can be asked to do, in its own words.
|
|
3
|
+
*
|
|
4
|
+
* There is no `click()` in this protocol and there is no `exec()` here, for the same reason: a
|
|
5
|
+
* capability is declared in the DOMAIN's language, not the transport's. `deploy` is a capability;
|
|
6
|
+
* running an arbitrary argv is a different and more dangerous thing, and conflating them is how a
|
|
7
|
+
* discovery pass comes to place an order.
|
|
8
|
+
*
|
|
9
|
+
* The manifest is supplied by whoever knows the tool. Nothing here is inferred from `--help`,
|
|
10
|
+
* because a guess about whether a command mutates is a guess that gets acted on.
|
|
11
|
+
*/
|
|
12
|
+
/** One thing the tool can be asked to do. */
|
|
13
|
+
export interface CliCommand {
|
|
14
|
+
/** Domain language: `build`, `deploy`. Not `exec`, and not `run-argv`. */
|
|
15
|
+
readonly name: string;
|
|
16
|
+
/** What it does, for an actor deciding whether this is the thing it wants. */
|
|
17
|
+
readonly meaning: string;
|
|
18
|
+
/**
|
|
19
|
+
* Whether performing this can change the world.
|
|
20
|
+
*
|
|
21
|
+
* Decides two different questions. A verifier that cannot tell a read from a write either
|
|
22
|
+
* refuses to explore or explores destructively. And `determinism()` reads it to decide whether
|
|
23
|
+
* a prefix may be re-driven at all.
|
|
24
|
+
*/
|
|
25
|
+
readonly mutating: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Whether running it costs money or consumes a rate limit, even when it changes nothing.
|
|
28
|
+
*
|
|
29
|
+
* Not the same question as `mutating`, and the difference was measured rather than imagined: a
|
|
30
|
+
* read-only query to an AI coding CLI mutates nothing and bills every time. `mutating` answers
|
|
31
|
+
* *may I run this for discovery*; this answers *may I replay it*.
|
|
32
|
+
*/
|
|
33
|
+
readonly costly?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Hosts this command is expected to contact, when it is expected to contact any.
|
|
36
|
+
*
|
|
37
|
+
* DECLARED, never inferred, and the difference decides whether a rule is usable at all. "The
|
|
38
|
+
* tool claimed success and dialled nothing" is a defect for `gh pr create` and the normal state
|
|
39
|
+
* of affairs for a formatter, and nothing about a process tells you which of the two you are
|
|
40
|
+
* looking at. So the manifest says, and a command that declares nothing here is never accused
|
|
41
|
+
* of failing to call out.
|
|
42
|
+
*/
|
|
43
|
+
readonly reaches?: readonly string[];
|
|
44
|
+
/** The arguments, after the tool's own executable. */
|
|
45
|
+
readonly argv: readonly string[];
|
|
46
|
+
/** Parameter shape as JSON Schema, when it takes any. */
|
|
47
|
+
readonly parameters?: unknown;
|
|
48
|
+
}
|
|
49
|
+
export interface CommandManifest {
|
|
50
|
+
/**
|
|
51
|
+
* The directory this tool operates on, and half of the subject's identity.
|
|
52
|
+
*
|
|
53
|
+
* A CLI's subject is the installed tool TOGETHER WITH the workspace, because that is what
|
|
54
|
+
* persists across the invocations of a journey. See OVP-SUBJ-3.
|
|
55
|
+
*/
|
|
56
|
+
readonly workspaceRoot: string;
|
|
57
|
+
readonly commands: readonly CliCommand[];
|
|
58
|
+
}
|
|
59
|
+
/** The command by that name, or undefined. Named so no caller re-writes the lookup. */
|
|
60
|
+
export declare function commandNamed(manifest: CommandManifest, name: string): CliCommand | undefined;
|
package/dist/manifest.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the tool under test can be asked to do, in its own words.
|
|
3
|
+
*
|
|
4
|
+
* There is no `click()` in this protocol and there is no `exec()` here, for the same reason: a
|
|
5
|
+
* capability is declared in the DOMAIN's language, not the transport's. `deploy` is a capability;
|
|
6
|
+
* running an arbitrary argv is a different and more dangerous thing, and conflating them is how a
|
|
7
|
+
* discovery pass comes to place an order.
|
|
8
|
+
*
|
|
9
|
+
* The manifest is supplied by whoever knows the tool. Nothing here is inferred from `--help`,
|
|
10
|
+
* because a guess about whether a command mutates is a guess that gets acted on.
|
|
11
|
+
*/
|
|
12
|
+
/** The command by that name, or undefined. Named so no caller re-writes the lookup. */
|
|
13
|
+
export function commandNamed(manifest, name) {
|
|
14
|
+
return manifest.commands.find((c) => c.name === name);
|
|
15
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A proxy that writes down which hosts a tool dialled, and reads nothing it sent.
|
|
3
|
+
*
|
|
4
|
+
* The one thing a shell cannot do. An agent with `Bash` can diff a filesystem and read an exit
|
|
5
|
+
* code; it has no way whatsoever to learn that a command called out, and `exited 0 and never made
|
|
6
|
+
* the request` is invisible to it.
|
|
7
|
+
*
|
|
8
|
+
* ## Why a CONNECT log and not interception
|
|
9
|
+
*
|
|
10
|
+
* Intercepting TLS would yield `net` at CONSEQUENCE grade -- status codes, response bodies, the
|
|
11
|
+
* answer the far side actually gave. It also costs a certificate authority the subject has to
|
|
12
|
+
* trust, which is a large thing to ask of somebody who wanted to check their build tool, and it
|
|
13
|
+
* puts this code in the path of every byte they send.
|
|
14
|
+
*
|
|
15
|
+
* A CONNECT log costs none of that. It is measured to work on `gh`, `vercel`, `npm`, `git` and
|
|
16
|
+
* `claude` with no flags, and it answers the question nothing else here can: *did it call out at
|
|
17
|
+
* all, and to whom?* That buys PRESENCE grade, which cannot prove a pull request exists and can
|
|
18
|
+
* convict a tool that exited 0 having never contacted the host its claim named.
|
|
19
|
+
*
|
|
20
|
+
* Consequence-grade `net` is a later question, and it should stay later: the cheap half of this
|
|
21
|
+
* is most of the value, and the expensive half asks the user for trust.
|
|
22
|
+
*/
|
|
23
|
+
/** One host a tool asked to reach. Not what it said to them. */
|
|
24
|
+
export interface ConnectAttempt {
|
|
25
|
+
readonly host: string;
|
|
26
|
+
readonly port: number;
|
|
27
|
+
readonly at: number;
|
|
28
|
+
}
|
|
29
|
+
export interface ConnectProxy {
|
|
30
|
+
readonly port: number;
|
|
31
|
+
/** Everything dialled since a moment on the injected clock. */
|
|
32
|
+
connectsSince(at: number): readonly ConnectAttempt[];
|
|
33
|
+
/**
|
|
34
|
+
* The environment a subject needs for any of this to see anything.
|
|
35
|
+
*
|
|
36
|
+
* Four variables for one value, because tools disagree about which spelling they read. A
|
|
37
|
+
* verifier that set only `HTTPS_PROXY` would observe nothing on a tool that reads
|
|
38
|
+
* `https_proxy`, while still declaring a `net` channel -- which is the shape of lie that makes
|
|
39
|
+
* an implementation look capable and report silence.
|
|
40
|
+
*/
|
|
41
|
+
env(): Readonly<Record<string, string>>;
|
|
42
|
+
stop(): Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
export interface ConnectProxyInput {
|
|
45
|
+
/** Injected, never read from a global: a window's arithmetic must be reproducible. */
|
|
46
|
+
readonly now: () => number;
|
|
47
|
+
}
|
|
48
|
+
export declare function startConnectProxy(input: ConnectProxyInput): Promise<ConnectProxy>;
|