@wringer/core 0.1.0 → 0.1.2
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 +1 -1
- package/README.md +71 -2
- package/dist/answer-supervisor-connection.d.ts +8 -0
- package/dist/app-machine.d.ts +76 -0
- package/dist/append-run-event.d.ts +16 -0
- package/dist/bind-drivers.d.ts +9 -0
- package/dist/build-commands.d.ts +5 -0
- package/dist/build-envelope-json-schema.d.ts +1 -0
- package/dist/build-envelope.d.ts +16 -0
- package/dist/build-launch-guard.d.ts +1 -0
- package/dist/build-manifest-write.d.ts +6 -0
- package/dist/build-promised-object-reads.d.ts +7 -0
- package/dist/build-report.d.ts +10 -0
- package/dist/build-run-handle.d.ts +2 -0
- package/dist/build-run-view.d.ts +29 -0
- package/dist/build-service-key.d.ts +1 -0
- package/dist/build-shut-down-steps.d.ts +14 -0
- package/dist/build-skip-worktree-marks.d.ts +7 -0
- package/dist/build-spawn-error.d.ts +2 -0
- package/dist/build-state-paths.d.ts +21 -0
- package/dist/build-submodule-adds.d.ts +7 -0
- package/dist/builtins/build-doctor-command.d.ts +2 -0
- package/dist/builtins/build-exec-command.d.ts +2 -0
- package/dist/builtins/build-lifecycle-commands.d.ts +3 -0
- package/dist/builtins/build-state-commands.d.ts +2 -0
- package/dist/builtins/build-use-pointers.d.ts +9 -0
- package/dist/builtins/build-verdict-commands.d.ts +2 -0
- package/dist/builtins/call-run-supervisor.d.ts +5 -0
- package/dist/builtins/pick-doctor-outcome.d.ts +13 -0
- package/dist/builtins/pick-start-action.d.ts +10 -0
- package/dist/builtins/pick-stop-plan.d.ts +14 -0
- package/dist/builtins/start-run.d.ts +22 -0
- package/dist/builtins/stop-data-schema.d.ts +6 -0
- package/dist/builtins/stop-run.d.ts +3 -0
- package/dist/call-supervisor.d.ts +10 -0
- package/dist/cap-data.d.ts +17 -0
- package/dist/collect-driver-configs.d.ts +7 -0
- package/dist/create-directory.d.ts +1 -0
- package/dist/create-evidence-writer.d.ts +13 -0
- package/dist/create-file-state.d.ts +36 -0
- package/dist/create-log-writer.d.ts +5 -0
- package/dist/create-node-repo-host.d.ts +2 -0
- package/dist/create-node-state-file-system.d.ts +10 -0
- package/dist/create-repo-state.d.ts +2 -0
- package/dist/create-socket-folder.d.ts +1 -0
- package/dist/create-wringer.d.ts +17 -0
- package/dist/decide-guard.d.ts +12 -0
- package/dist/define-driver.d.ts +13 -0
- package/dist/dispatch.d.ts +10 -0
- package/dist/envelope.d.ts +63 -0
- package/dist/error-codes.d.ts +25 -0
- package/dist/find-cancel-failure.d.ts +2 -0
- package/dist/find-colliding-service-key.d.ts +5 -0
- package/dist/find-own-value.d.ts +1 -0
- package/dist/find-remote-stop-failure.d.ts +2 -0
- package/dist/find-verdict-refusal.d.ts +3 -0
- package/dist/follow-process.d.ts +10 -0
- package/dist/get-lock-value.d.ts +2 -0
- package/dist/get-target.d.ts +2 -0
- package/dist/host.d.ts +19 -0
- package/dist/index.d.ts +60 -0
- package/dist/is-error-code.d.ts +1 -0
- package/dist/keep-cancelled-call.d.ts +1 -0
- package/dist/kill-process-group.d.ts +1 -0
- package/dist/launch-line-schema.d.ts +3 -0
- package/dist/listen-supervisor-socket.d.ts +8 -0
- package/dist/local.d.ts +2 -0
- package/dist/make-fence.d.ts +8 -0
- package/dist/make-fenced-exec.d.ts +10 -0
- package/dist/make-process-supervisor-port.d.ts +7 -0
- package/dist/open-drive.d.ts +23 -0
- package/dist/open-runless-drive.d.ts +17 -0
- package/dist/parse-launch-line.d.ts +2 -0
- package/dist/parse-patch-id.d.ts +2 -0
- package/dist/parse-report-block.d.ts +9 -0
- package/dist/parse-run-log.d.ts +2 -0
- package/dist/pick-access-refusal.d.ts +12 -0
- package/dist/pick-command-needs.d.ts +15 -0
- package/dist/pick-command-plan.d.ts +23 -0
- package/dist/pick-context-target.d.ts +7 -0
- package/dist/pick-drive-kind.d.ts +8 -0
- package/dist/pick-envelope-context.d.ts +1 -0
- package/dist/pick-envelope-payload.d.ts +12 -0
- package/dist/pick-envelope-run.d.ts +6 -0
- package/dist/pick-envelope-target.d.ts +4 -0
- package/dist/pick-late-failure-write.d.ts +13 -0
- package/dist/pick-log-refusal.d.ts +4 -0
- package/dist/pick-merge-base-failure.d.ts +2 -0
- package/dist/pick-merge-base-steps.d.ts +13 -0
- package/dist/pick-pending-cleanups.d.ts +10 -0
- package/dist/pick-submodule-refusal.d.ts +2 -0
- package/dist/pick-supervisor-operation.d.ts +16 -0
- package/dist/prepare-args.d.ts +3 -0
- package/dist/probe-process.d.ts +1 -0
- package/dist/quote-shell-word.d.ts +1 -0
- package/dist/race-deadline.d.ts +1 -0
- package/dist/read-changed-paths.d.ts +7 -0
- package/dist/read-default-base.d.ts +2 -0
- package/dist/read-fingerprint.d.ts +13 -0
- package/dist/read-head-sha.d.ts +2 -0
- package/dist/read-launch-host.d.ts +26 -0
- package/dist/read-pid-namespace.d.ts +1 -0
- package/dist/read-stream-line-batches.d.ts +2 -0
- package/dist/read-stream-lines.d.ts +2 -0
- package/dist/read-text.d.ts +1 -0
- package/dist/read-verdicts.d.ts +5 -0
- package/dist/remove-directory.d.ts +1 -0
- package/dist/remove-file.d.ts +1 -0
- package/dist/render-report-markdown.d.ts +4 -0
- package/dist/report-schema.d.ts +51 -0
- package/dist/run-events.d.ts +129 -0
- package/dist/run-git.d.ts +9 -0
- package/dist/run-process.d.ts +19 -0
- package/dist/run-supervisor-process.d.ts +2 -0
- package/dist/run-supervisor.d.ts +16 -0
- package/dist/settle-dispatch-answer.d.ts +9 -0
- package/dist/settle-envelope.d.ts +16 -0
- package/dist/ssh.d.ts +12 -0
- package/dist/start-launch.d.ts +20 -0
- package/dist/start-services.d.ts +16 -0
- package/dist/supervisor-machine.d.ts +78 -0
- package/dist/supervisor-protocol.d.ts +43 -0
- package/dist/to-wringer-error.d.ts +2 -0
- package/dist/types.d.ts +353 -0
- package/dist/wait-for-cancelled-calls.d.ts +2 -0
- package/dist/wringer-error.d.ts +12 -0
- package/dist/write-envelope-log.d.ts +11 -0
- package/dist/write-late-failure.d.ts +11 -0
- package/dist/write-new-file.d.ts +1 -0
- package/envelope.schema.json +175 -0
- package/package.json +21 -5
- package/src/answer-supervisor-connection.ts +117 -0
- package/src/app-machine.ts +174 -0
- package/src/append-run-event.ts +131 -0
- package/src/bind-drivers.ts +33 -0
- package/src/build-commands.ts +104 -0
- package/src/build-envelope-json-schema.ts +34 -0
- package/src/build-envelope.ts +40 -0
- package/src/build-launch-guard.ts +5 -0
- package/src/build-manifest-write.ts +26 -0
- package/src/build-promised-object-reads.ts +48 -0
- package/src/build-report.ts +55 -0
- package/src/build-run-handle.ts +13 -0
- package/src/build-run-view.ts +120 -0
- package/src/build-service-key.ts +4 -0
- package/src/build-shut-down-steps.ts +54 -0
- package/src/build-skip-worktree-marks.ts +36 -0
- package/src/build-spawn-error.ts +12 -0
- package/src/build-state-paths.ts +53 -0
- package/src/build-submodule-adds.ts +64 -0
- package/src/builtins/build-doctor-command.ts +163 -0
- package/src/builtins/build-exec-command.ts +41 -0
- package/src/builtins/build-lifecycle-commands.ts +115 -0
- package/src/builtins/build-state-commands.ts +152 -0
- package/src/builtins/build-use-pointers.ts +26 -0
- package/src/builtins/build-verdict-commands.ts +266 -0
- package/src/builtins/call-run-supervisor.ts +40 -0
- package/src/builtins/pick-doctor-outcome.ts +32 -0
- package/src/builtins/pick-start-action.ts +35 -0
- package/src/builtins/pick-stop-plan.ts +32 -0
- package/src/builtins/start-run.ts +281 -0
- package/src/builtins/stop-data-schema.ts +8 -0
- package/src/builtins/stop-run.ts +49 -0
- package/src/call-supervisor.ts +109 -0
- package/src/cap-data.ts +43 -0
- package/src/collect-driver-configs.ts +36 -0
- package/src/create-directory.ts +6 -0
- package/src/create-evidence-writer.ts +82 -0
- package/src/create-file-state.ts +193 -0
- package/src/create-log-writer.ts +38 -0
- package/src/create-node-repo-host.ts +20 -0
- package/src/create-node-state-file-system.ts +52 -0
- package/src/create-repo-state.ts +15 -0
- package/src/create-socket-folder.ts +24 -0
- package/src/create-wringer.ts +169 -0
- package/src/decide-guard.ts +47 -0
- package/src/define-driver.ts +165 -0
- package/src/dispatch.ts +589 -0
- package/src/envelope.ts +57 -0
- package/src/error-codes.ts +39 -0
- package/src/find-cancel-failure.ts +7 -0
- package/src/find-colliding-service-key.ts +16 -0
- package/src/find-own-value.ts +8 -0
- package/src/find-remote-stop-failure.ts +19 -0
- package/src/find-verdict-refusal.ts +26 -0
- package/src/follow-process.ts +147 -0
- package/src/get-lock-value.ts +17 -0
- package/src/get-target.ts +15 -0
- package/src/host.ts +26 -0
- package/src/index.ts +75 -0
- package/src/is-error-code.ts +3 -0
- package/src/keep-cancelled-call.ts +21 -0
- package/src/kill-process-group.ts +13 -0
- package/src/launch-line-schema.ts +6 -0
- package/src/listen-supervisor-socket.ts +75 -0
- package/src/local.ts +20 -0
- package/src/make-fence.ts +27 -0
- package/src/make-fenced-exec.ts +52 -0
- package/src/make-process-supervisor-port.ts +65 -0
- package/src/open-drive.ts +151 -0
- package/src/open-runless-drive.ts +71 -0
- package/src/parse-launch-line.ts +19 -0
- package/src/parse-patch-id.ts +8 -0
- package/src/parse-report-block.ts +39 -0
- package/src/parse-run-log.ts +34 -0
- package/src/pick-access-refusal.ts +32 -0
- package/src/pick-command-needs.ts +29 -0
- package/src/pick-command-plan.ts +51 -0
- package/src/pick-context-target.ts +22 -0
- package/src/pick-drive-kind.ts +23 -0
- package/src/pick-envelope-context.ts +10 -0
- package/src/pick-envelope-payload.ts +28 -0
- package/src/pick-envelope-run.ts +25 -0
- package/src/pick-envelope-target.ts +10 -0
- package/src/pick-late-failure-write.ts +44 -0
- package/src/pick-log-refusal.ts +18 -0
- package/src/pick-merge-base-failure.ts +15 -0
- package/src/pick-merge-base-steps.ts +37 -0
- package/src/pick-pending-cleanups.ts +23 -0
- package/src/pick-submodule-refusal.ts +46 -0
- package/src/pick-supervisor-operation.ts +52 -0
- package/src/prepare-args.ts +22 -0
- package/src/probe-process.ts +16 -0
- package/src/quote-shell-word.ts +9 -0
- package/src/race-deadline.ts +23 -0
- package/src/read-changed-paths.ts +39 -0
- package/src/read-default-base.ts +21 -0
- package/src/read-fingerprint.ts +271 -0
- package/src/read-head-sha.ts +23 -0
- package/src/read-launch-host.ts +64 -0
- package/src/read-pid-namespace.ts +18 -0
- package/src/read-stream-line-batches.ts +28 -0
- package/src/read-stream-lines.ts +11 -0
- package/src/read-text.ts +5 -0
- package/src/read-verdicts.ts +57 -0
- package/src/remove-directory.ts +6 -0
- package/src/remove-file.ts +6 -0
- package/src/render-report-markdown.ts +53 -0
- package/src/report-schema.ts +37 -0
- package/src/run-events.ts +71 -0
- package/src/run-git.ts +49 -0
- package/src/run-process.ts +168 -0
- package/src/run-supervisor-process.ts +51 -0
- package/src/run-supervisor.ts +327 -0
- package/src/settle-dispatch-answer.ts +26 -0
- package/src/settle-envelope.ts +34 -0
- package/src/ssh.ts +211 -0
- package/src/start-launch.ts +327 -0
- package/src/start-services.ts +108 -0
- package/src/supervisor-machine.ts +169 -0
- package/src/supervisor-protocol.ts +42 -0
- package/src/to-wringer-error.ts +20 -0
- package/src/types.ts +476 -0
- package/src/wait-for-cancelled-calls.ts +37 -0
- package/src/wringer-error.ts +25 -0
- package/src/write-envelope-log.ts +72 -0
- package/src/write-late-failure.ts +40 -0
- package/src/write-new-file.ts +17 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { RunView } from './build-run-view.ts';
|
|
3
|
+
import type { RunPaths } from './build-state-paths.ts';
|
|
4
|
+
import type { SupervisorCall } from './call-supervisor.ts';
|
|
5
|
+
import type { StatePort } from './create-file-state.ts';
|
|
6
|
+
import type { Evidence } from './envelope.ts';
|
|
7
|
+
import type { Access, Host } from './host.ts';
|
|
8
|
+
import type { LaunchLine } from './launch-line-schema.ts';
|
|
9
|
+
import type { FingerprintHost } from './read-fingerprint.ts';
|
|
10
|
+
import type { Endpoints, RunID } from './run-events.ts';
|
|
11
|
+
import type { ProcessResult } from './run-process.ts';
|
|
12
|
+
export type Effect = 'read' | 'write';
|
|
13
|
+
export type Emit = (event: string, data: unknown) => void;
|
|
14
|
+
export interface EvidenceWriter {
|
|
15
|
+
readonly directory: string;
|
|
16
|
+
readonly writeFile: (kind: string, name: string, content: string | Uint8Array) => Promise<Evidence>;
|
|
17
|
+
readonly addFile: (kind: string, path: string) => Promise<Evidence>;
|
|
18
|
+
}
|
|
19
|
+
export interface ExecOptions {
|
|
20
|
+
readonly stdin?: string | undefined;
|
|
21
|
+
}
|
|
22
|
+
export type RepoExec = (argv: readonly string[], options?: ExecOptions) => Promise<ProcessResult>;
|
|
23
|
+
export type DriverExec = (argv: readonly string[], effect: Effect, options?: ExecOptions) => Promise<ProcessResult>;
|
|
24
|
+
export interface ChildLog {
|
|
25
|
+
readonly path: string;
|
|
26
|
+
}
|
|
27
|
+
export interface RunHandle {
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly paths: RunPaths;
|
|
30
|
+
readonly childLog: (name: string) => ChildLog;
|
|
31
|
+
}
|
|
32
|
+
export interface DriverConfigContext {
|
|
33
|
+
readonly target: string;
|
|
34
|
+
readonly endpoints: Endpoints;
|
|
35
|
+
readonly run: RunHandle;
|
|
36
|
+
}
|
|
37
|
+
export interface ServiceCaller {
|
|
38
|
+
readonly call: (method: string, args: unknown) => Promise<unknown>;
|
|
39
|
+
}
|
|
40
|
+
export interface DriverSession<Options, TargetConfig> {
|
|
41
|
+
readonly target: string;
|
|
42
|
+
readonly access: Access;
|
|
43
|
+
readonly options: Options;
|
|
44
|
+
readonly config: TargetConfig;
|
|
45
|
+
readonly endpoints: Endpoints;
|
|
46
|
+
readonly run: RunHandle;
|
|
47
|
+
readonly exec: DriverExec;
|
|
48
|
+
readonly evidence: EvidenceWriter;
|
|
49
|
+
readonly cursors: Readonly<Record<string, number>>;
|
|
50
|
+
readonly signal: AbortSignal;
|
|
51
|
+
readonly timeLeftMs: () => number;
|
|
52
|
+
readonly service: (name: string) => ServiceCaller;
|
|
53
|
+
}
|
|
54
|
+
export interface ClientCall<Args, Result> {
|
|
55
|
+
readonly effect: (args: Args) => Effect;
|
|
56
|
+
readonly describe: (args: Args) => string;
|
|
57
|
+
readonly run: (args: Args) => Promise<Result>;
|
|
58
|
+
}
|
|
59
|
+
export type Fence = <Args, Result>(call: ClientCall<Args, Result>) => (args: Args) => Promise<Result>;
|
|
60
|
+
export interface ServiceContext<Options, TargetConfig> {
|
|
61
|
+
readonly target: string;
|
|
62
|
+
readonly access: Access;
|
|
63
|
+
readonly options: Options;
|
|
64
|
+
readonly config: TargetConfig;
|
|
65
|
+
readonly endpoints: Endpoints;
|
|
66
|
+
readonly run: RunHandle;
|
|
67
|
+
readonly host: Host;
|
|
68
|
+
readonly exec: DriverExec;
|
|
69
|
+
readonly signal: AbortSignal;
|
|
70
|
+
}
|
|
71
|
+
export type ServiceMethod = (args: unknown, signal: AbortSignal) => Promise<unknown>;
|
|
72
|
+
export interface ServiceInstance {
|
|
73
|
+
readonly methods: Readonly<Record<string, ServiceMethod>>;
|
|
74
|
+
readonly stop: () => Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
export interface ServiceDefinition<Options, TargetConfig> {
|
|
77
|
+
readonly start: (ctx: ServiceContext<Options, TargetConfig>) => Promise<ServiceInstance>;
|
|
78
|
+
}
|
|
79
|
+
export interface CommandShape<Args, Data> {
|
|
80
|
+
readonly path: readonly string[];
|
|
81
|
+
readonly summary: string;
|
|
82
|
+
readonly args: z.ZodType<Args>;
|
|
83
|
+
readonly positionals?: readonly string[] | undefined;
|
|
84
|
+
readonly data: z.ZodType<Data>;
|
|
85
|
+
readonly effect?: Effect | undefined;
|
|
86
|
+
readonly needsRun?: boolean | undefined;
|
|
87
|
+
readonly needsDoctor?: boolean | undefined;
|
|
88
|
+
readonly timeoutMs?: number | undefined;
|
|
89
|
+
}
|
|
90
|
+
export type CommandInfo = CommandShape<unknown, unknown> & {
|
|
91
|
+
readonly decideEffect?: unknown;
|
|
92
|
+
};
|
|
93
|
+
export interface DriverCommandContext<Options, TargetConfig, Client> {
|
|
94
|
+
readonly session: DriverSession<Options, TargetConfig>;
|
|
95
|
+
readonly client: Client;
|
|
96
|
+
readonly feature: string | null;
|
|
97
|
+
readonly emit: Emit;
|
|
98
|
+
}
|
|
99
|
+
export interface DriverCommandSpec<Args, Data, Options, TargetConfig, Client> extends CommandShape<Args, Data> {
|
|
100
|
+
readonly decideEffect?: ((args: Args, config: TargetConfig) => Effect) | undefined;
|
|
101
|
+
readonly run: (args: Args, ctx: DriverCommandContext<Options, TargetConfig, Client>) => Promise<Data>;
|
|
102
|
+
}
|
|
103
|
+
export type ArgsResult<Prepared> = {
|
|
104
|
+
readonly ok: true;
|
|
105
|
+
readonly prepared: Prepared;
|
|
106
|
+
} | {
|
|
107
|
+
readonly ok: false;
|
|
108
|
+
readonly message: string;
|
|
109
|
+
};
|
|
110
|
+
export interface PreparedDriverCommand<Options, TargetConfig, Client> {
|
|
111
|
+
readonly decideEffect: (config: TargetConfig) => Effect;
|
|
112
|
+
readonly run: (ctx: DriverCommandContext<Options, TargetConfig, Client>) => Promise<unknown>;
|
|
113
|
+
}
|
|
114
|
+
export interface DriverCommand<Options, TargetConfig, Client> {
|
|
115
|
+
readonly info: CommandInfo;
|
|
116
|
+
readonly prepare: (raw: unknown) => ArgsResult<PreparedDriverCommand<Options, TargetConfig, Client>>;
|
|
117
|
+
}
|
|
118
|
+
export type DriverCommandHelper<Options, TargetConfig, Client> = <Args, Data>(spec: DriverCommandSpec<Args, Data, Options, TargetConfig, Client>) => DriverCommand<Options, TargetConfig, Client>;
|
|
119
|
+
export interface DriverCheckDefinition<Options, TargetConfig, Client> {
|
|
120
|
+
readonly name: string;
|
|
121
|
+
readonly timeoutMs: number;
|
|
122
|
+
readonly run: (ctx: DriverCommandContext<Options, TargetConfig, Client>) => Promise<void>;
|
|
123
|
+
}
|
|
124
|
+
export interface SessionParts {
|
|
125
|
+
readonly target: string;
|
|
126
|
+
readonly access: Access;
|
|
127
|
+
readonly endpoints: Endpoints;
|
|
128
|
+
readonly run: RunHandle;
|
|
129
|
+
readonly exec: DriverExec;
|
|
130
|
+
readonly evidence: EvidenceWriter;
|
|
131
|
+
readonly cursors: Readonly<Record<string, number>>;
|
|
132
|
+
readonly signal: AbortSignal;
|
|
133
|
+
readonly timeLeftMs: () => number;
|
|
134
|
+
readonly fence: Fence;
|
|
135
|
+
readonly service: (name: string) => ServiceCaller;
|
|
136
|
+
}
|
|
137
|
+
export interface ServiceParts {
|
|
138
|
+
readonly target: string;
|
|
139
|
+
readonly access: Access;
|
|
140
|
+
readonly endpoints: Endpoints;
|
|
141
|
+
readonly run: RunHandle;
|
|
142
|
+
readonly host: Host;
|
|
143
|
+
readonly exec: DriverExec;
|
|
144
|
+
readonly signal: AbortSignal;
|
|
145
|
+
}
|
|
146
|
+
export interface PreparedRun {
|
|
147
|
+
readonly effect: Effect;
|
|
148
|
+
readonly run: (feature: string | null, emit: Emit) => Promise<unknown>;
|
|
149
|
+
}
|
|
150
|
+
export interface RunnableCheck {
|
|
151
|
+
readonly name: string;
|
|
152
|
+
readonly timeoutMs: number;
|
|
153
|
+
readonly run: (feature: string | null, emit: Emit) => Promise<void>;
|
|
154
|
+
}
|
|
155
|
+
export interface OpenedDriver {
|
|
156
|
+
readonly client: unknown;
|
|
157
|
+
readonly checks: readonly RunnableCheck[];
|
|
158
|
+
readonly prepare: (pathKey: string, raw: unknown) => ArgsResult<PreparedRun>;
|
|
159
|
+
}
|
|
160
|
+
export interface ConfiguredDriver {
|
|
161
|
+
readonly open: (parts: SessionParts) => OpenedDriver;
|
|
162
|
+
readonly startService: (name: string, parts: ServiceParts) => Promise<ServiceInstance>;
|
|
163
|
+
}
|
|
164
|
+
export interface DriverTypes<Client, ConfigInput> {
|
|
165
|
+
readonly client: Client;
|
|
166
|
+
readonly config: ConfigInput;
|
|
167
|
+
}
|
|
168
|
+
export interface Driver<Name extends string, Client, ConfigInput> {
|
|
169
|
+
readonly kind: 'driver';
|
|
170
|
+
readonly name: Name;
|
|
171
|
+
readonly commands: readonly CommandInfo[];
|
|
172
|
+
readonly serviceNames: readonly string[];
|
|
173
|
+
readonly configure: (input: unknown) => ArgsResult<ConfiguredDriver>;
|
|
174
|
+
readonly types?: DriverTypes<Client, ConfigInput>;
|
|
175
|
+
}
|
|
176
|
+
export type AnyDriver = Driver<string, unknown, unknown>;
|
|
177
|
+
export type AnyDrivers = readonly AnyDriver[];
|
|
178
|
+
export type DriverClients<Ds extends AnyDrivers> = {
|
|
179
|
+
readonly [D in Ds[number] as D['name']]: D extends Driver<string, infer Client, unknown> ? Client : never;
|
|
180
|
+
};
|
|
181
|
+
export type DriverConfigs<Ds extends AnyDrivers> = {
|
|
182
|
+
readonly [D in Ds[number] as D['name']]?: (ctx: DriverConfigContext) => D extends Driver<string, unknown, infer ConfigInput> ? ConfigInput : never;
|
|
183
|
+
};
|
|
184
|
+
export interface DriveContext<Ds extends AnyDrivers = AnyDrivers> {
|
|
185
|
+
readonly target: string;
|
|
186
|
+
readonly access: Access;
|
|
187
|
+
readonly feature: string | null;
|
|
188
|
+
readonly endpoints: Endpoints;
|
|
189
|
+
readonly drivers: DriverClients<Ds>;
|
|
190
|
+
readonly exec: RepoExec;
|
|
191
|
+
readonly evidence: EvidenceWriter;
|
|
192
|
+
readonly signal: AbortSignal;
|
|
193
|
+
readonly emit: Emit;
|
|
194
|
+
}
|
|
195
|
+
export interface CommandSpec<Args, Data, Ds extends AnyDrivers = AnyDrivers> extends CommandShape<Args, Data> {
|
|
196
|
+
readonly decideEffect?: ((args: Args) => Effect) | undefined;
|
|
197
|
+
readonly run: (args: Args, ctx: DriveContext<Ds>) => Promise<Data>;
|
|
198
|
+
}
|
|
199
|
+
export interface ActionDefinition<Input, Data, Ds extends AnyDrivers = AnyDrivers> {
|
|
200
|
+
readonly name: string;
|
|
201
|
+
readonly summary: string;
|
|
202
|
+
readonly effect: Effect;
|
|
203
|
+
readonly targets?: readonly string[] | undefined;
|
|
204
|
+
readonly input: z.ZodType<Input>;
|
|
205
|
+
readonly data: z.ZodType<Data>;
|
|
206
|
+
readonly timeoutMs?: number | undefined;
|
|
207
|
+
readonly run: (input: Input, ctx: DriveContext<Ds>) => Promise<Data>;
|
|
208
|
+
}
|
|
209
|
+
export interface CheckDefinition<Input, Data, Ds extends AnyDrivers = AnyDrivers> {
|
|
210
|
+
readonly name: string;
|
|
211
|
+
readonly input: z.ZodType<Input>;
|
|
212
|
+
readonly data: z.ZodType<Data>;
|
|
213
|
+
readonly timeoutMs: number;
|
|
214
|
+
readonly run: (input: Input, ctx: DriveContext<Ds>) => Promise<Data>;
|
|
215
|
+
}
|
|
216
|
+
export interface FeatureDefinition {
|
|
217
|
+
readonly name: string;
|
|
218
|
+
readonly summary: string;
|
|
219
|
+
readonly paths: readonly string[];
|
|
220
|
+
}
|
|
221
|
+
export interface UploadRequest {
|
|
222
|
+
readonly path: string;
|
|
223
|
+
readonly kind: string;
|
|
224
|
+
readonly sha256: string;
|
|
225
|
+
}
|
|
226
|
+
export interface HookHandlers {
|
|
227
|
+
readonly upload: (file: UploadRequest) => Promise<string>;
|
|
228
|
+
}
|
|
229
|
+
export interface LaunchContext {
|
|
230
|
+
readonly runDirectory: string;
|
|
231
|
+
}
|
|
232
|
+
export interface LaunchPlan {
|
|
233
|
+
readonly command: readonly string[];
|
|
234
|
+
readonly env?: Readonly<Record<string, string>> | undefined;
|
|
235
|
+
readonly cwd?: string | undefined;
|
|
236
|
+
readonly ready: (line: LaunchLine) => Endpoints | null;
|
|
237
|
+
readonly stop?: readonly string[] | undefined;
|
|
238
|
+
}
|
|
239
|
+
interface TargetBase<Ds extends AnyDrivers> {
|
|
240
|
+
readonly access: Access;
|
|
241
|
+
readonly refusalHint?: string | undefined;
|
|
242
|
+
readonly host: Host;
|
|
243
|
+
readonly drivers?: DriverConfigs<Ds> | undefined;
|
|
244
|
+
}
|
|
245
|
+
export interface EndpointsContext {
|
|
246
|
+
readonly target: string;
|
|
247
|
+
}
|
|
248
|
+
export interface LaunchTarget<Ds extends AnyDrivers> extends TargetBase<Ds> {
|
|
249
|
+
readonly mode: 'launch';
|
|
250
|
+
readonly launch: (ctx: LaunchContext) => LaunchPlan;
|
|
251
|
+
readonly endpoints?: never;
|
|
252
|
+
}
|
|
253
|
+
export interface AttachTarget<Ds extends AnyDrivers> extends TargetBase<Ds> {
|
|
254
|
+
readonly mode: 'attach';
|
|
255
|
+
readonly endpoints?: ((ctx: EndpointsContext) => Endpoints | Promise<Endpoints>) | undefined;
|
|
256
|
+
readonly launch?: never;
|
|
257
|
+
}
|
|
258
|
+
export type TargetDefinition<Ds extends AnyDrivers = AnyDrivers> = LaunchTarget<Ds> | AttachTarget<Ds>;
|
|
259
|
+
export interface Drive {
|
|
260
|
+
readonly ctx: DriveContext;
|
|
261
|
+
readonly drivers: ReadonlyMap<string, OpenedDriver>;
|
|
262
|
+
readonly evidence: readonly Evidence[];
|
|
263
|
+
}
|
|
264
|
+
export interface Deadline {
|
|
265
|
+
readonly signal: AbortSignal;
|
|
266
|
+
readonly at: number;
|
|
267
|
+
}
|
|
268
|
+
export interface BuiltinContext {
|
|
269
|
+
readonly wringer: Wringer;
|
|
270
|
+
readonly state: StatePort;
|
|
271
|
+
readonly session: Session;
|
|
272
|
+
readonly stateDir: string;
|
|
273
|
+
readonly targetName: string;
|
|
274
|
+
readonly target: TargetDefinition;
|
|
275
|
+
readonly run: RunView | undefined;
|
|
276
|
+
readonly feature: string | null;
|
|
277
|
+
readonly signal: AbortSignal;
|
|
278
|
+
readonly deadlineAt: number;
|
|
279
|
+
readonly now: () => Date;
|
|
280
|
+
readonly wait: (delayMs: number) => Promise<void>;
|
|
281
|
+
readonly emit: Emit;
|
|
282
|
+
readonly openDrive: (access: Access, deadline?: Deadline) => Drive;
|
|
283
|
+
readonly bindRun: (runID: RunID) => void;
|
|
284
|
+
readonly keepLate: (work: Promise<void>) => void;
|
|
285
|
+
}
|
|
286
|
+
export interface BuiltinCommandSpec<Args, Data> extends CommandShape<Args, Data> {
|
|
287
|
+
readonly run: (args: Args, ctx: BuiltinContext) => Promise<Data>;
|
|
288
|
+
}
|
|
289
|
+
export interface PreparedCommand<Ctx> {
|
|
290
|
+
readonly effect: Effect;
|
|
291
|
+
readonly run: (ctx: Ctx) => Promise<unknown>;
|
|
292
|
+
}
|
|
293
|
+
export type RegisteredCommand = {
|
|
294
|
+
readonly kind: 'repo';
|
|
295
|
+
readonly info: CommandInfo;
|
|
296
|
+
readonly targets: readonly string[] | undefined;
|
|
297
|
+
readonly prepare: (raw: unknown) => ArgsResult<PreparedCommand<DriveContext>>;
|
|
298
|
+
} | {
|
|
299
|
+
readonly kind: 'builtin';
|
|
300
|
+
readonly info: CommandInfo;
|
|
301
|
+
readonly prepare: (raw: unknown) => ArgsResult<PreparedCommand<BuiltinContext>>;
|
|
302
|
+
} | {
|
|
303
|
+
readonly kind: 'driver';
|
|
304
|
+
readonly info: CommandInfo;
|
|
305
|
+
readonly driver: string;
|
|
306
|
+
};
|
|
307
|
+
export interface RunnableRepoCheck {
|
|
308
|
+
readonly name: string;
|
|
309
|
+
readonly timeoutMs: number;
|
|
310
|
+
readonly run: (ctx: DriveContext) => Promise<void>;
|
|
311
|
+
}
|
|
312
|
+
export interface Wringer {
|
|
313
|
+
readonly name: string;
|
|
314
|
+
readonly stateDir: string;
|
|
315
|
+
readonly drivers: AnyDrivers;
|
|
316
|
+
readonly targets: ReadonlyMap<string, TargetDefinition>;
|
|
317
|
+
readonly commands: ReadonlyMap<string, RegisteredCommand>;
|
|
318
|
+
readonly checks: readonly RunnableRepoCheck[];
|
|
319
|
+
readonly features: readonly FeatureDefinition[];
|
|
320
|
+
readonly hooks: Partial<HookHandlers>;
|
|
321
|
+
}
|
|
322
|
+
export interface SupervisorStartRequest {
|
|
323
|
+
readonly runID: string;
|
|
324
|
+
readonly target: string;
|
|
325
|
+
}
|
|
326
|
+
export interface SupervisorPort {
|
|
327
|
+
readonly start: (request: SupervisorStartRequest) => Promise<void>;
|
|
328
|
+
readonly call: (call: SupervisorCall) => Promise<unknown>;
|
|
329
|
+
}
|
|
330
|
+
export interface OutputPort {
|
|
331
|
+
readonly writeLine: (line: string) => void;
|
|
332
|
+
}
|
|
333
|
+
export interface EvidenceFiles {
|
|
334
|
+
readonly createDirectory: (path: string) => Promise<void>;
|
|
335
|
+
readonly writeNewFile: (path: string, bytes: Uint8Array) => Promise<boolean>;
|
|
336
|
+
readonly readBytes: (path: string) => Promise<Uint8Array>;
|
|
337
|
+
}
|
|
338
|
+
export interface RepoHost extends FingerprintHost, EvidenceFiles {
|
|
339
|
+
readonly readText: (path: string) => Promise<string>;
|
|
340
|
+
}
|
|
341
|
+
export interface Session {
|
|
342
|
+
readonly root: string;
|
|
343
|
+
readonly state: StatePort;
|
|
344
|
+
readonly repoHost: RepoHost;
|
|
345
|
+
readonly target?: string | undefined;
|
|
346
|
+
readonly feature?: string | undefined;
|
|
347
|
+
readonly timeoutMs?: number | undefined;
|
|
348
|
+
readonly output: OutputPort;
|
|
349
|
+
readonly supervisor: SupervisorPort;
|
|
350
|
+
readonly now?: (() => Date) | undefined;
|
|
351
|
+
readonly wait?: ((delayMs: number) => Promise<void>) | undefined;
|
|
352
|
+
}
|
|
353
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ErrorCode } from './error-codes.ts';
|
|
2
|
+
export interface WringerErrorDetails {
|
|
3
|
+
readonly message?: string;
|
|
4
|
+
readonly hint?: string;
|
|
5
|
+
readonly data?: unknown;
|
|
6
|
+
}
|
|
7
|
+
export declare class WringerError extends Error {
|
|
8
|
+
readonly code: ErrorCode;
|
|
9
|
+
readonly hint: string | undefined;
|
|
10
|
+
readonly data: unknown;
|
|
11
|
+
constructor(code: ErrorCode, details?: WringerErrorDetails);
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RunView } from './build-run-view.ts';
|
|
2
|
+
import type { RunViewRefusal, StatePort } from './create-file-state.ts';
|
|
3
|
+
import type { Envelope } from './envelope.ts';
|
|
4
|
+
import type { WringerError } from './wringer-error.ts';
|
|
5
|
+
export interface LogRequest {
|
|
6
|
+
readonly drive: boolean;
|
|
7
|
+
readonly failure: WringerError | null;
|
|
8
|
+
readonly now: () => Date;
|
|
9
|
+
readonly refuse: RunViewRefusal | null;
|
|
10
|
+
}
|
|
11
|
+
export declare function writeEnvelopeLog(state: StatePort, run: RunView, envelope: Envelope, request: LogRequest): Promise<WringerError | null>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { StatePort } from './create-file-state.ts';
|
|
2
|
+
import type { RunID } from './run-events.ts';
|
|
3
|
+
import type { WringerError } from './wringer-error.ts';
|
|
4
|
+
export interface LateFailureRequest {
|
|
5
|
+
readonly state: StatePort;
|
|
6
|
+
readonly runID: RunID | null;
|
|
7
|
+
readonly command: string;
|
|
8
|
+
readonly answered: WringerError | null;
|
|
9
|
+
readonly now: () => Date;
|
|
10
|
+
}
|
|
11
|
+
export declare function writeLateFailure(work: Promise<unknown>, request: LateFailureRequest): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function writeNewFile(path: string, bytes: Uint8Array): Promise<boolean>;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://unpkg.com/@wringer/core/envelope.schema.json",
|
|
4
|
+
"title": "wringer envelope",
|
|
5
|
+
"$defs": {
|
|
6
|
+
"envelope": {
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"wringer": {
|
|
10
|
+
"type": "number",
|
|
11
|
+
"const": 1
|
|
12
|
+
},
|
|
13
|
+
"ok": {
|
|
14
|
+
"type": "boolean"
|
|
15
|
+
},
|
|
16
|
+
"command": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"minLength": 1
|
|
19
|
+
},
|
|
20
|
+
"target": {
|
|
21
|
+
"type": ["string", "null"]
|
|
22
|
+
},
|
|
23
|
+
"instance": {
|
|
24
|
+
"type": ["string", "null"]
|
|
25
|
+
},
|
|
26
|
+
"feature": {
|
|
27
|
+
"type": ["string", "null"]
|
|
28
|
+
},
|
|
29
|
+
"sha": {
|
|
30
|
+
"type": ["string", "null"]
|
|
31
|
+
},
|
|
32
|
+
"durationMs": {
|
|
33
|
+
"type": "integer",
|
|
34
|
+
"minimum": 0,
|
|
35
|
+
"maximum": 9007199254740991
|
|
36
|
+
},
|
|
37
|
+
"data": {},
|
|
38
|
+
"evidence": {
|
|
39
|
+
"type": "array",
|
|
40
|
+
"items": {
|
|
41
|
+
"type": "object",
|
|
42
|
+
"properties": {
|
|
43
|
+
"kind": {
|
|
44
|
+
"type": "string",
|
|
45
|
+
"minLength": 1
|
|
46
|
+
},
|
|
47
|
+
"path": {
|
|
48
|
+
"type": "string",
|
|
49
|
+
"minLength": 1
|
|
50
|
+
},
|
|
51
|
+
"sha256": {
|
|
52
|
+
"type": "string",
|
|
53
|
+
"pattern": "^[0-9a-f]{64}$"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"required": ["kind", "path", "sha256"],
|
|
57
|
+
"additionalProperties": false
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"cursors": {
|
|
61
|
+
"type": "object",
|
|
62
|
+
"propertyNames": {
|
|
63
|
+
"type": "string"
|
|
64
|
+
},
|
|
65
|
+
"additionalProperties": {
|
|
66
|
+
"type": "integer",
|
|
67
|
+
"minimum": 0,
|
|
68
|
+
"maximum": 9007199254740991
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"truncated": {
|
|
72
|
+
"type": "boolean",
|
|
73
|
+
"const": true
|
|
74
|
+
},
|
|
75
|
+
"truncatedPath": {
|
|
76
|
+
"type": "string"
|
|
77
|
+
},
|
|
78
|
+
"error": {
|
|
79
|
+
"anyOf": [
|
|
80
|
+
{
|
|
81
|
+
"type": "object",
|
|
82
|
+
"properties": {
|
|
83
|
+
"code": {
|
|
84
|
+
"type": "string",
|
|
85
|
+
"enum": [
|
|
86
|
+
"check-failed",
|
|
87
|
+
"usage",
|
|
88
|
+
"read-only",
|
|
89
|
+
"doctor-required",
|
|
90
|
+
"not-running",
|
|
91
|
+
"target-not-allowed",
|
|
92
|
+
"environment",
|
|
93
|
+
"internal",
|
|
94
|
+
"timeout"
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
"message": {
|
|
98
|
+
"type": "string"
|
|
99
|
+
},
|
|
100
|
+
"hint": {
|
|
101
|
+
"type": ["string", "null"]
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
"required": ["code", "message", "hint"],
|
|
105
|
+
"additionalProperties": false
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"type": "null"
|
|
109
|
+
}
|
|
110
|
+
]
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
"required": [
|
|
114
|
+
"wringer",
|
|
115
|
+
"ok",
|
|
116
|
+
"command",
|
|
117
|
+
"target",
|
|
118
|
+
"instance",
|
|
119
|
+
"feature",
|
|
120
|
+
"sha",
|
|
121
|
+
"durationMs",
|
|
122
|
+
"data",
|
|
123
|
+
"evidence",
|
|
124
|
+
"cursors",
|
|
125
|
+
"error"
|
|
126
|
+
],
|
|
127
|
+
"additionalProperties": false,
|
|
128
|
+
"oneOf": [
|
|
129
|
+
{
|
|
130
|
+
"type": "object",
|
|
131
|
+
"properties": {
|
|
132
|
+
"ok": {
|
|
133
|
+
"const": true
|
|
134
|
+
},
|
|
135
|
+
"error": {
|
|
136
|
+
"type": "null"
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
"type": "object",
|
|
142
|
+
"properties": {
|
|
143
|
+
"ok": {
|
|
144
|
+
"const": false
|
|
145
|
+
},
|
|
146
|
+
"error": {
|
|
147
|
+
"type": "object"
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
],
|
|
152
|
+
"dependentRequired": {
|
|
153
|
+
"truncated": ["truncatedPath"],
|
|
154
|
+
"truncatedPath": ["truncated"]
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
"streamEvent": {
|
|
158
|
+
"type": "object",
|
|
159
|
+
"properties": {
|
|
160
|
+
"wringer": {
|
|
161
|
+
"type": "number",
|
|
162
|
+
"const": 1
|
|
163
|
+
},
|
|
164
|
+
"event": {
|
|
165
|
+
"type": "string",
|
|
166
|
+
"minLength": 1
|
|
167
|
+
},
|
|
168
|
+
"data": {}
|
|
169
|
+
},
|
|
170
|
+
"required": ["wringer", "event", "data"],
|
|
171
|
+
"additionalProperties": false
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
"$ref": "#/$defs/envelope"
|
|
175
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wringer/core",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "The core of wringer: the
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "The core of wringer: the envelope, the registry, the fence, the run state and the evidence",
|
|
5
5
|
"homepage": "https://github.com/zgeoff/wringer/tree/main/packages/core#readme",
|
|
6
6
|
"bugs": "https://github.com/zgeoff/wringer/issues",
|
|
7
7
|
"license": "MIT",
|
|
@@ -13,21 +13,37 @@
|
|
|
13
13
|
"files": [
|
|
14
14
|
"src",
|
|
15
15
|
"!src/**/*.test.ts",
|
|
16
|
-
"dist"
|
|
16
|
+
"dist",
|
|
17
|
+
"envelope.schema.json",
|
|
18
|
+
"!src/test-utils"
|
|
17
19
|
],
|
|
18
20
|
"type": "module",
|
|
19
21
|
"exports": {
|
|
20
22
|
".": {
|
|
21
23
|
"types": "./dist/index.d.ts",
|
|
22
24
|
"default": "./src/index.ts"
|
|
23
|
-
}
|
|
25
|
+
},
|
|
26
|
+
"./envelope.schema.json": "./envelope.schema.json",
|
|
27
|
+
"./test-utils/*": "./src/test-utils/*"
|
|
24
28
|
},
|
|
25
29
|
"publishConfig": {
|
|
26
30
|
"access": "public"
|
|
27
31
|
},
|
|
28
32
|
"scripts": {
|
|
29
33
|
"build": "rm -rf dist && tsrs -p tsconfig.build.json",
|
|
30
|
-
"typecheck": "tsrs --noEmit"
|
|
34
|
+
"typecheck": "tsrs --noEmit",
|
|
35
|
+
"schema": "bun scripts/write-envelope-schema.ts"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@zgeoff/std": "0.4.3",
|
|
39
|
+
"ts-pattern": "5.9.2",
|
|
40
|
+
"xstate": "5.33.3",
|
|
41
|
+
"zod": "4.6.7"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@zgeoff/testing": "0.3.0",
|
|
45
|
+
"ajv": "8.20.0",
|
|
46
|
+
"tiny-invariant": "1.3.3"
|
|
31
47
|
},
|
|
32
48
|
"engines": {
|
|
33
49
|
"bun": ">=1.3"
|