@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
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What one step leaves behind, and what the next one needs, in a vocabulary a CLI actually has.
|
|
3
|
+
*
|
|
4
|
+
* The protocol carries `requires` and `ensures` and deliberately never parses them: a protocol
|
|
5
|
+
* that compared them would be a protocol with an opinion about what a subject IS, which is the
|
|
6
|
+
* opinion it exists not to have. Only the realm knows what its own state values mean.
|
|
7
|
+
*
|
|
8
|
+
* For a command-line subject they mean the workspace. A build ensures `dist/index.js`; a test run
|
|
9
|
+
* requires it; a clean step requires it absent. That is the whole vocabulary, and it is small on
|
|
10
|
+
* purpose -- a richer one would be this adapter inventing a state language nobody else speaks.
|
|
11
|
+
*/
|
|
12
|
+
/** What a step guarantees, or demands, about the workspace. */
|
|
13
|
+
export interface CliStateContract {
|
|
14
|
+
/** Paths that are present. */
|
|
15
|
+
readonly paths?: readonly string[];
|
|
16
|
+
/** Paths that are NOT present. A different claim from presence, and not its negation. */
|
|
17
|
+
readonly absent?: readonly string[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Read a contract, or decline.
|
|
21
|
+
*
|
|
22
|
+
* `undefined` for anything unrecognised, and that answer travels all the way out: the protocol
|
|
23
|
+
* reports it as `unjudged-requirement` and forbids reading it as agreement. A realm that guessed
|
|
24
|
+
* here would turn every composite into one that cannot fail.
|
|
25
|
+
*/
|
|
26
|
+
export declare function readContract(value: unknown): CliStateContract | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Does what the journey established meet what the next step declares it needs?
|
|
29
|
+
*
|
|
30
|
+
* A comparison of DECLARATIONS, never of the disk. This runs at typecheck time, before anything
|
|
31
|
+
* has been driven, so there is no filesystem state to consult and the workspace may not exist
|
|
32
|
+
* yet. A version that called `stat` would answer about the wrong moment entirely, and would pass
|
|
33
|
+
* or fail depending on what a previous run happened to leave behind -- which is the shape of test
|
|
34
|
+
* that only works in the order it was written.
|
|
35
|
+
*/
|
|
36
|
+
export declare function contractSatisfies(ensures: unknown, requires: unknown): boolean | undefined;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What one step leaves behind, and what the next one needs, in a vocabulary a CLI actually has.
|
|
3
|
+
*
|
|
4
|
+
* The protocol carries `requires` and `ensures` and deliberately never parses them: a protocol
|
|
5
|
+
* that compared them would be a protocol with an opinion about what a subject IS, which is the
|
|
6
|
+
* opinion it exists not to have. Only the realm knows what its own state values mean.
|
|
7
|
+
*
|
|
8
|
+
* For a command-line subject they mean the workspace. A build ensures `dist/index.js`; a test run
|
|
9
|
+
* requires it; a clean step requires it absent. That is the whole vocabulary, and it is small on
|
|
10
|
+
* purpose -- a richer one would be this adapter inventing a state language nobody else speaks.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Read a contract, or decline.
|
|
14
|
+
*
|
|
15
|
+
* `undefined` for anything unrecognised, and that answer travels all the way out: the protocol
|
|
16
|
+
* reports it as `unjudged-requirement` and forbids reading it as agreement. A realm that guessed
|
|
17
|
+
* here would turn every composite into one that cannot fail.
|
|
18
|
+
*/
|
|
19
|
+
export function readContract(value) {
|
|
20
|
+
if ('object' !== typeof value || null === value)
|
|
21
|
+
return undefined;
|
|
22
|
+
const record = value;
|
|
23
|
+
const paths = record['paths'];
|
|
24
|
+
const absent = record['absent'];
|
|
25
|
+
const listed = (v) => undefined === v || (Array.isArray(v) && v.every((p) => 'string' === typeof p));
|
|
26
|
+
if (!listed(paths) || !listed(absent))
|
|
27
|
+
return undefined;
|
|
28
|
+
// Neither key present means this is somebody else's vocabulary, not an empty contract of ours.
|
|
29
|
+
if (undefined === paths && undefined === absent)
|
|
30
|
+
return undefined;
|
|
31
|
+
return {
|
|
32
|
+
...(Array.isArray(paths) ? { paths: paths } : {}),
|
|
33
|
+
...(Array.isArray(absent) ? { absent: absent } : {}),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Does what the journey established meet what the next step declares it needs?
|
|
38
|
+
*
|
|
39
|
+
* A comparison of DECLARATIONS, never of the disk. This runs at typecheck time, before anything
|
|
40
|
+
* has been driven, so there is no filesystem state to consult and the workspace may not exist
|
|
41
|
+
* yet. A version that called `stat` would answer about the wrong moment entirely, and would pass
|
|
42
|
+
* or fail depending on what a previous run happened to leave behind -- which is the shape of test
|
|
43
|
+
* that only works in the order it was written.
|
|
44
|
+
*/
|
|
45
|
+
export function contractSatisfies(ensures, requires) {
|
|
46
|
+
const had = readContract(ensures);
|
|
47
|
+
const needs = readContract(requires);
|
|
48
|
+
if (undefined === had || undefined === needs)
|
|
49
|
+
return undefined;
|
|
50
|
+
const established = new Set(had.paths ?? []);
|
|
51
|
+
const needsPresent = (needs.paths ?? []).every((p) => established.has(p));
|
|
52
|
+
// The absence half is not the negation of the presence half: a step requiring `dist` ABSENT is
|
|
53
|
+
// contradicted by a predecessor that ensures it, and satisfied by one that simply never
|
|
54
|
+
// mentions it.
|
|
55
|
+
const needsAbsent = (needs.absent ?? []).every((p) => !established.has(p));
|
|
56
|
+
return needsPresent && needsAbsent;
|
|
57
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { CloseCondition, Realm, type Anomaly, type Action, type ActionReceipt, type Capability, type ChannelDescriptor, type Coverage, type DeterminismProfile, type Observation, type SubjectRef, type Window } from 'open-verification';
|
|
2
|
+
import type { ConnectProxy } from './net/proxy.js';
|
|
3
|
+
import { type CommandManifest } from './manifest.js';
|
|
4
|
+
import type { Invocation, Supervisor } from './process/supervisor.js';
|
|
5
|
+
import { type Change, type WorkspacePort } from './workspace/port.js';
|
|
6
|
+
/** Observation summaries. Stable machine labels, because `valueContains` matches on them exactly. */
|
|
7
|
+
export declare const TerminalSummary: {
|
|
8
|
+
readonly STDOUT_LINE: "cli.stdout.line";
|
|
9
|
+
readonly STDERR_LINE: "cli.stderr.line";
|
|
10
|
+
readonly EXIT_CODE: "cli.exit.code";
|
|
11
|
+
readonly TERMINATED_SIGNAL: "cli.terminated.signal";
|
|
12
|
+
readonly DURATION_MS: "cli.duration.ms";
|
|
13
|
+
/** A path that appeared, vanished or changed mode. What the FILESYSTEM decided. */
|
|
14
|
+
readonly FS_WRITTEN: "cli.fs.written";
|
|
15
|
+
/**
|
|
16
|
+
* A path that appeared holding NOTHING.
|
|
17
|
+
*
|
|
18
|
+
* Its own word, because `summary` is the only part of a match that compares exactly: a claim
|
|
19
|
+
* reading "the build produced out.txt" is written over this summary, and an empty file must not
|
|
20
|
+
* satisfy it without somebody saying so. A zero-byte output is the commonest shape of a build
|
|
21
|
+
* that ran, failed late, and left the path behind -- it passes every existence check there is.
|
|
22
|
+
*/
|
|
23
|
+
readonly FS_WRITTEN_EMPTY: "cli.fs.written-empty";
|
|
24
|
+
readonly FS_DELETED: "cli.fs.deleted";
|
|
25
|
+
/** The bytes inside a path. What the SUBJECT decided, which is why it is a different channel. */
|
|
26
|
+
readonly FS_CONTENT: "cli.fs.content";
|
|
27
|
+
/** A host the tool asked to reach. Never what it said to them. */
|
|
28
|
+
readonly NET_CONNECT: "cli.net.connect";
|
|
29
|
+
};
|
|
30
|
+
export interface TerminalRealmDeps {
|
|
31
|
+
readonly supervisor: Supervisor;
|
|
32
|
+
readonly manifest: CommandManifest;
|
|
33
|
+
/**
|
|
34
|
+
* Where the subject leaves things behind, when there is somewhere to watch.
|
|
35
|
+
*
|
|
36
|
+
* Absent is a real answer and not a degraded one: without it the realm declares no artifact
|
|
37
|
+
* channel, `canProveAnything` is false, and it says so at startup rather than one `unknown` at a
|
|
38
|
+
* time. Declaring a channel it cannot report on would be the costlier kind of wrong.
|
|
39
|
+
*/
|
|
40
|
+
readonly workspace?: WorkspacePort;
|
|
41
|
+
/**
|
|
42
|
+
* A proxy watching which hosts the subject dials, when one is running.
|
|
43
|
+
*
|
|
44
|
+
* Absent means no `net` channel is declared at all. The alternative -- declaring it and
|
|
45
|
+
* reporting nothing -- is the costliest shape of lie available here: every claim reading `net`
|
|
46
|
+
* would come back `unknown` while the implementation looked capable of answering it.
|
|
47
|
+
*/
|
|
48
|
+
readonly proxy?: ConnectProxy;
|
|
49
|
+
/** Injected, never read from a global: a window's arithmetic must be reproducible in a test. */
|
|
50
|
+
readonly now: () => number;
|
|
51
|
+
}
|
|
52
|
+
export declare class TerminalRealm extends Realm {
|
|
53
|
+
#private;
|
|
54
|
+
constructor(deps: TerminalRealmDeps);
|
|
55
|
+
/**
|
|
56
|
+
* The installed tool and the workspace, never the process.
|
|
57
|
+
*
|
|
58
|
+
* A CLI's process is the action, so naming it as the instance would make every observation from
|
|
59
|
+
* step one inadmissible at step two and report a working journey as evidence superseded. The
|
|
60
|
+
* thing that PERSISTS across the invocations of a journey is the tool plus what it operates on.
|
|
61
|
+
*/
|
|
62
|
+
identity(): SubjectRef;
|
|
63
|
+
/**
|
|
64
|
+
* What is declared follows what is actually present, never what would look better.
|
|
65
|
+
*
|
|
66
|
+
* The artifact pair appears only with a workspace to watch. That is the same discipline the
|
|
67
|
+
* optional fixture and mutation ports carry elsewhere: a realm must not OFFER what it cannot
|
|
68
|
+
* honour, because a channel declared and never reported on makes every claim reading it come
|
|
69
|
+
* back `unknown` while the implementation looks capable.
|
|
70
|
+
*/
|
|
71
|
+
channels(): readonly ChannelDescriptor[];
|
|
72
|
+
/**
|
|
73
|
+
* How this subject may be DRIVEN, derived from the manifest rather than asserted.
|
|
74
|
+
*
|
|
75
|
+
* `replayPrefix` is the row that earns its place. A prefix of read-only, uncostly commands is
|
|
76
|
+
* genuinely safe to re-drive; one containing a `deploy`, or a billed query, is not. `unsafe` is
|
|
77
|
+
* not a cost to weigh against a cheap reset, and `resumeStrategy` reads it first and alone for
|
|
78
|
+
* that reason: reading the reset first and concluding "cheap reset, so go ahead" is precisely
|
|
79
|
+
* the reasoning that re-sends the payment.
|
|
80
|
+
*/
|
|
81
|
+
determinism(): DeterminismProfile;
|
|
82
|
+
/**
|
|
83
|
+
* Whether one step leaves the next what it needs, answered in paths.
|
|
84
|
+
*
|
|
85
|
+
* Overriding this is what lets a composite be refused BEFORE it is run, rather than inside a
|
|
86
|
+
* sub-journey that is working correctly. The base class returns `undefined` -- a realm with no
|
|
87
|
+
* notion of a state contract has no honest answer -- and inheriting that default would make
|
|
88
|
+
* every declared sequence come back `unjudged-requirement`, which is a check that can only ever
|
|
89
|
+
* pass.
|
|
90
|
+
*
|
|
91
|
+
* It still returns `undefined` for a vocabulary it does not speak, which is the honest answer
|
|
92
|
+
* and a different one from `false`: "teach the realm" and "reorder the composite" are opposite
|
|
93
|
+
* instructions, and collapsing them would hide which is needed.
|
|
94
|
+
*/
|
|
95
|
+
satisfies(ensures: unknown, requires: unknown): boolean | undefined;
|
|
96
|
+
capabilities(): readonly Capability[];
|
|
97
|
+
/** What is here: the commands, and where they operate. No screen, no elements. */
|
|
98
|
+
describe(): Promise<unknown>;
|
|
99
|
+
protected dispatch(action: Action): Promise<ActionReceipt>;
|
|
100
|
+
/**
|
|
101
|
+
* A window that closes when the process ends.
|
|
102
|
+
*
|
|
103
|
+
* `exit` is the cleanest close the protocol has: nothing inferred from silence, no deadline
|
|
104
|
+
* chosen by us. A long-running command (`watch`, a dev server, a REPL) closes on quiescence
|
|
105
|
+
* instead, which is Phase 4's problem and not a default to inherit here.
|
|
106
|
+
*/
|
|
107
|
+
openWindow(budgetMs: number): Window;
|
|
108
|
+
/**
|
|
109
|
+
* Was this path already there before the action? Three-valued, and the third value matters.
|
|
110
|
+
*
|
|
111
|
+
* `undefined` means NOBODY CHECKED, which the protocol reads differently from `false`, and a
|
|
112
|
+
* realm with no workspace must say it rather than guess the answer that scores better.
|
|
113
|
+
*
|
|
114
|
+
* This is what lets a caller supply `consequenceHeldBefore` and reach clause 10. Without it the
|
|
115
|
+
* commonest claim a CLI makes -- "the output file is there" -- is already true on every run
|
|
116
|
+
* after the first, and a build that did nothing at all proves itself.
|
|
117
|
+
*/
|
|
118
|
+
existedBefore(window: Window, path: string): boolean | undefined;
|
|
119
|
+
/** What changed on disk across this window, or nothing when there was nowhere to look. */
|
|
120
|
+
changesIn(window: Window): readonly Change[];
|
|
121
|
+
/**
|
|
122
|
+
* Close it, saying what ACTUALLY ended it.
|
|
123
|
+
*
|
|
124
|
+
* Three outcomes and they are not interchangeable. The subject finished: `exit`. Something else
|
|
125
|
+
* ended it: `terminated`, which is not a clean close because the effect may be half-applied and
|
|
126
|
+
* the subject did not choose the moment. We gave up: `budget-exhausted`, which blames our
|
|
127
|
+
* patience rather than the subject's misfortune, and is the honest answer when it is true.
|
|
128
|
+
*/
|
|
129
|
+
closeWindow(window: Window): Window;
|
|
130
|
+
observe(window: Window): Promise<readonly Observation[]>;
|
|
131
|
+
/**
|
|
132
|
+
* What this vantage point could not see, and in Phase 1 that is most things.
|
|
133
|
+
*
|
|
134
|
+
* `effect-elsewhere` is declared UNCONDITIONALLY rather than when a stray write is detected,
|
|
135
|
+
* because nothing here can detect one: there is no filesystem observation yet, and even in
|
|
136
|
+
* Phase 2 the roots are declared rather than discovered. A spot that can never fire would leave
|
|
137
|
+
* every window silently asserting that nothing was hidden, which an empty `blindSpots` array
|
|
138
|
+
* means as a positive claim.
|
|
139
|
+
*/
|
|
140
|
+
/**
|
|
141
|
+
* Two things in this window that cannot both be true.
|
|
142
|
+
*
|
|
143
|
+
* Delegates, because every rule is a pure function of the observations and belongs where it can
|
|
144
|
+
* be tested without a realm. Implementing this at all is what makes section 8 reachable: the
|
|
145
|
+
* specification records that a conformant implementation can be built in which the whole of
|
|
146
|
+
* anomaly detection is unreachable, one was, and three planted defects came back `yes`.
|
|
147
|
+
*
|
|
148
|
+
* Safe for an adapter to do, because an anomaly is not a verdict. A disagreement may only
|
|
149
|
+
* convict when one of its two channels is independent, and that check runs on the adjudicator's
|
|
150
|
+
* side over the channel declaration, so a realm cannot convict itself however hard it tries.
|
|
151
|
+
*/
|
|
152
|
+
detect(_window: Window, observed: readonly Observation[]): Promise<readonly Anomaly[]>;
|
|
153
|
+
coverage(window: Window): Promise<Coverage>;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* What ended this window, from what the supervisor saw.
|
|
157
|
+
*
|
|
158
|
+
* A free function rather than a method: it reads an invocation and nothing else, so it is worth
|
|
159
|
+
* being able to test without a realm, and worth being impossible to accidentally couple to one.
|
|
160
|
+
*/
|
|
161
|
+
export declare function closedBy(invocation: Invocation | undefined): CloseCondition;
|