@wringer/core 0.0.0 → 0.1.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.
- 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 +58 -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 +265 -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 +73 -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
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import { prepareArgs } from './prepare-args.ts';
|
|
3
|
+
import type {
|
|
4
|
+
Driver,
|
|
5
|
+
DriverCheckDefinition,
|
|
6
|
+
DriverCommand,
|
|
7
|
+
DriverCommandContext,
|
|
8
|
+
DriverCommandHelper,
|
|
9
|
+
DriverSession,
|
|
10
|
+
Fence,
|
|
11
|
+
OpenedDriver,
|
|
12
|
+
ServiceDefinition,
|
|
13
|
+
SessionParts,
|
|
14
|
+
} from './types.ts';
|
|
15
|
+
import { WringerError } from './wringer-error.ts';
|
|
16
|
+
|
|
17
|
+
export interface DriverDefinition<
|
|
18
|
+
Name extends string,
|
|
19
|
+
Options,
|
|
20
|
+
OptionsInput,
|
|
21
|
+
TargetConfig,
|
|
22
|
+
ConfigInput,
|
|
23
|
+
Client,
|
|
24
|
+
> {
|
|
25
|
+
readonly name: Name;
|
|
26
|
+
readonly options: z.ZodType<Options, OptionsInput>;
|
|
27
|
+
readonly targetConfig: z.ZodType<TargetConfig, ConfigInput>;
|
|
28
|
+
readonly services?: Readonly<Record<string, ServiceDefinition<Options, TargetConfig>>>;
|
|
29
|
+
readonly client: (session: DriverSession<Options, TargetConfig>, fence: Fence) => Client;
|
|
30
|
+
readonly commands?: (
|
|
31
|
+
command: DriverCommandHelper<Options, TargetConfig, Client>,
|
|
32
|
+
) => readonly DriverCommand<Options, TargetConfig, Client>[];
|
|
33
|
+
readonly checks?: readonly DriverCheckDefinition<Options, TargetConfig, Client>[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type DriverFactory<Name extends string, OptionsInput, ConfigInput, Client> = (
|
|
37
|
+
options: OptionsInput,
|
|
38
|
+
) => Driver<Name, Client, ConfigInput>;
|
|
39
|
+
|
|
40
|
+
// A driver package exports the factory this returns. The repo calls it once with its repo-wide
|
|
41
|
+
// options, which are parsed there. Each target's config is parsed when a run opens the driver, and
|
|
42
|
+
// every type stays inside these closures, so the registry holds drivers of any shape.
|
|
43
|
+
export function defineDriver<
|
|
44
|
+
Name extends string,
|
|
45
|
+
Options,
|
|
46
|
+
OptionsInput,
|
|
47
|
+
TargetConfig,
|
|
48
|
+
ConfigInput,
|
|
49
|
+
Client,
|
|
50
|
+
>(
|
|
51
|
+
definition: DriverDefinition<Name, Options, OptionsInput, TargetConfig, ConfigInput, Client>,
|
|
52
|
+
): DriverFactory<Name, OptionsInput, ConfigInput, Client> {
|
|
53
|
+
const commands =
|
|
54
|
+
definition.commands?.((spec) => ({
|
|
55
|
+
info: spec,
|
|
56
|
+
prepare: (raw) =>
|
|
57
|
+
prepareArgs(spec.args, raw, (args) => ({
|
|
58
|
+
decideEffect: (config: TargetConfig) =>
|
|
59
|
+
spec.decideEffect?.(args, config) ?? spec.effect ?? 'write',
|
|
60
|
+
run: (ctx: DriverCommandContext<Options, TargetConfig, Client>) => spec.run(args, ctx),
|
|
61
|
+
})),
|
|
62
|
+
})) ?? [];
|
|
63
|
+
|
|
64
|
+
const byPath = new Map(commands.map((command) => [command.info.path.join(' '), command]));
|
|
65
|
+
|
|
66
|
+
return (input) => {
|
|
67
|
+
const options = definition.options.parse(input);
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
kind: 'driver',
|
|
71
|
+
name: definition.name,
|
|
72
|
+
commands: commands.map((command) => command.info),
|
|
73
|
+
serviceNames: Object.keys(definition.services ?? {}),
|
|
74
|
+
configure: (configInput) => {
|
|
75
|
+
const parsed = definition.targetConfig.safeParse(configInput);
|
|
76
|
+
|
|
77
|
+
if (!parsed.success) {
|
|
78
|
+
return { ok: false, message: parsed.error.message };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const config = parsed.data;
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
ok: true,
|
|
85
|
+
prepared: {
|
|
86
|
+
open: (parts) => openDriver({ definition, options, config, byPath, parts }),
|
|
87
|
+
startService: (name, parts) => {
|
|
88
|
+
const service = definition.services?.[name];
|
|
89
|
+
|
|
90
|
+
if (service === undefined) {
|
|
91
|
+
return Promise.reject(
|
|
92
|
+
new WringerError('internal', {
|
|
93
|
+
message: `The ${definition.name} driver has no service ${name}.`,
|
|
94
|
+
}),
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return service.start({ ...parts, options, config });
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
interface OpenRequest<Options, TargetConfig, Client> {
|
|
108
|
+
readonly definition: {
|
|
109
|
+
readonly client: (session: DriverSession<Options, TargetConfig>, fence: Fence) => Client;
|
|
110
|
+
readonly checks?: readonly DriverCheckDefinition<Options, TargetConfig, Client>[];
|
|
111
|
+
};
|
|
112
|
+
readonly options: Options;
|
|
113
|
+
readonly config: TargetConfig;
|
|
114
|
+
readonly byPath: ReadonlyMap<string, DriverCommand<Options, TargetConfig, Client>>;
|
|
115
|
+
readonly parts: SessionParts;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function openDriver<Options, TargetConfig, Client>(
|
|
119
|
+
request: OpenRequest<Options, TargetConfig, Client>,
|
|
120
|
+
): OpenedDriver {
|
|
121
|
+
const session: DriverSession<Options, TargetConfig> = {
|
|
122
|
+
target: request.parts.target,
|
|
123
|
+
access: request.parts.access,
|
|
124
|
+
options: request.options,
|
|
125
|
+
config: request.config,
|
|
126
|
+
endpoints: request.parts.endpoints,
|
|
127
|
+
run: request.parts.run,
|
|
128
|
+
exec: request.parts.exec,
|
|
129
|
+
evidence: request.parts.evidence,
|
|
130
|
+
cursors: request.parts.cursors,
|
|
131
|
+
signal: request.parts.signal,
|
|
132
|
+
timeLeftMs: request.parts.timeLeftMs,
|
|
133
|
+
service: request.parts.service,
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const client = request.definition.client(session, request.parts.fence);
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
client,
|
|
140
|
+
checks: (request.definition.checks ?? []).map((check) => ({
|
|
141
|
+
name: check.name,
|
|
142
|
+
timeoutMs: check.timeoutMs,
|
|
143
|
+
run: (feature, emit) => check.run({ session, client, feature, emit }),
|
|
144
|
+
})),
|
|
145
|
+
prepare: (pathKey, raw) => {
|
|
146
|
+
const command = request.byPath.get(pathKey);
|
|
147
|
+
|
|
148
|
+
if (command === undefined) {
|
|
149
|
+
return { ok: false, message: `The driver has no command \`${pathKey}\`.` };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const prepared = command.prepare(raw);
|
|
153
|
+
|
|
154
|
+
return prepared.ok
|
|
155
|
+
? {
|
|
156
|
+
ok: true,
|
|
157
|
+
prepared: {
|
|
158
|
+
effect: prepared.prepared.decideEffect(request.config),
|
|
159
|
+
run: (feature, emit) => prepared.prepared.run({ session, client, feature, emit }),
|
|
160
|
+
},
|
|
161
|
+
}
|
|
162
|
+
: prepared;
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|