codemod 2.0.0-alpha.2 → 2.0.0-alpha.4
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/README.md +1 -2
- package/package.json +14 -16
- package/register.d.mts +2 -11
- package/register.mjs +53 -46
- package/runtime/addon.d.mts +119 -0
- package/runtime/addon.mjs +36 -40
- package/runtime/ast-grep.d.mts +20 -0
- package/runtime/ast-grep.mjs +50 -61
- package/runtime/context.d.mts +25 -0
- package/runtime/context.mjs +10 -64
- package/runtime/hooks.d.mts +2 -0
- package/runtime/hooks.mjs +4 -6
- package/runtime/host.d.mts +81 -81
- package/runtime/host.mjs +428 -326
- package/runtime/llm.d.mts +2 -0
- package/runtime/llm.mjs +1 -7
- package/runtime/modules.d.mts +3 -0
- package/runtime/modules.mjs +7 -10
- package/runtime/orchestrator-version.d.mts +2 -0
- package/runtime/orchestrator-version.mjs +3 -0
- package/runtime/orchestrator.d.mts +261 -0
- package/runtime/orchestrator.mjs +823 -608
- package/runtime/runtime.d.mts +15 -0
- package/runtime/runtime.mjs +18 -26
- package/runtime/workflow.d.mts +24 -0
- package/runtime/workflow.mjs +42 -121
- package/testing/index.d.mts +107 -155
- package/testing/index.mjs +552 -545
- package/types/index.d.ts +0 -1
- package/types/langs/package.json +3 -0
- package/types/modules/ast-grep.d.ts +22 -1
- package/types/modules/workflow.d.ts +386 -231
- package/vite.d.mts +4 -21
- package/vite.mjs +23 -17
- package/runtime/metrics.mjs +0 -45
- package/types/metrics.d.ts +0 -5
- package/types/modules/metrics.d.ts +0 -107
package/runtime/llm.mjs
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
// `codemod/llm` is not available when Node.js runs the workflow yet.
|
|
2
|
-
|
|
3
2
|
export function generate() {
|
|
4
|
-
|
|
5
|
-
new Error(
|
|
6
|
-
"codemod/llm is not available when Node.js runs the workflow; run it with the codemod CLI",
|
|
7
|
-
),
|
|
8
|
-
);
|
|
3
|
+
return Promise.reject(new Error("codemod/llm is not available when Node.js runs the workflow; run it with the codemod CLI"));
|
|
9
4
|
}
|
|
10
|
-
|
|
11
5
|
export default generate;
|
package/runtime/modules.mjs
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
// The older `codemod:*` spelling of the codemod modules, and this package's
|
|
2
2
|
// Node.js implementations they resolve to. `codemod/workflow` and the rest
|
|
3
3
|
// need no mapping: they are this package's own exports.
|
|
4
|
-
|
|
4
|
+
// Paths of the built files, next to the built form of this one.
|
|
5
5
|
const MODULES = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"codemod:llm": "./llm.mjs",
|
|
6
|
+
"codemod:workflow": "./workflow.mjs",
|
|
7
|
+
"codemod:ast-grep": "./ast-grep.mjs",
|
|
8
|
+
"codemod:runtime": "./runtime.mjs",
|
|
9
|
+
"codemod:llm": "./llm.mjs",
|
|
11
10
|
};
|
|
12
|
-
|
|
13
11
|
export const CODEMOD_MODULES = Object.keys(MODULES);
|
|
14
|
-
|
|
15
12
|
/** The URL an older `codemod:*` specifier resolves to, or undefined. */
|
|
16
13
|
export function resolveCodemodModule(specifier) {
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
const path = MODULES[specifier];
|
|
15
|
+
return path ? new URL(path, import.meta.url).href : undefined;
|
|
19
16
|
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/** A JSON value: what steps record and tasks are described in. */
|
|
2
|
+
export type Json = null | boolean | number | string | Json[] | {
|
|
3
|
+
[key: string]: Json;
|
|
4
|
+
};
|
|
5
|
+
/** `"partial"`: the step finished, but some of its files failed. */
|
|
6
|
+
export type StepStatus = "succeeded" | "partial" | "failed" | "canceled" | "awaiting-approval" | "waiting";
|
|
7
|
+
/**
|
|
8
|
+
* One step as the run store keeps it: `StepRecord` in
|
|
9
|
+
* `crates/state/src/run_store.rs`, which reads and writes this JSON.
|
|
10
|
+
*/
|
|
11
|
+
export interface StepRecord {
|
|
12
|
+
/** The step's place in the run's list of steps; it keeps it across resumes. */
|
|
13
|
+
position: number;
|
|
14
|
+
label: string;
|
|
15
|
+
/** Canonical form of the step's label and task: what makes it this step. */
|
|
16
|
+
key: string;
|
|
17
|
+
status: StepStatus;
|
|
18
|
+
result?: Json;
|
|
19
|
+
error?: string | null;
|
|
20
|
+
/** When a successful step finished, in milliseconds since the epoch. */
|
|
21
|
+
finishedAt?: number | null;
|
|
22
|
+
/** The order in which the run's steps finished. */
|
|
23
|
+
seq?: number | null;
|
|
24
|
+
/** The step did not run: a test gave its result. */
|
|
25
|
+
given?: boolean;
|
|
26
|
+
/** When a `sleep` or `waitForEvent` step began to wait. */
|
|
27
|
+
since?: number | null;
|
|
28
|
+
/** How many times the step ran, when retries made that more than once. */
|
|
29
|
+
attempts?: number | null;
|
|
30
|
+
}
|
|
31
|
+
/** What a step is asked to do, as the host receives it: JSON with a `kind`. */
|
|
32
|
+
export type TaskContent = {
|
|
33
|
+
kind: string;
|
|
34
|
+
} & Record<string, unknown>;
|
|
35
|
+
/** A function given to a host that runs callbacks in place. */
|
|
36
|
+
export type Callback = (...args: any[]) => unknown;
|
|
37
|
+
/** `host.start(request)`: `HostRequest` in `crates/workflow/src/run.rs`. */
|
|
38
|
+
export interface StartRequest {
|
|
39
|
+
position: number;
|
|
40
|
+
label: string;
|
|
41
|
+
task: TaskContent;
|
|
42
|
+
/** The step's function, on hosts that run callbacks in place. */
|
|
43
|
+
fn?: Callback;
|
|
44
|
+
/** How long the task may run, from the step's `timeout`. */
|
|
45
|
+
timeoutMs?: number;
|
|
46
|
+
/** When the step began to wait (`sleep`, `waitForEvent`). */
|
|
47
|
+
since?: number;
|
|
48
|
+
}
|
|
49
|
+
/** What a task resolves to: `TaskOutcome` in `crates/workflow/src/tasks/mod.rs`. */
|
|
50
|
+
export interface Outcome {
|
|
51
|
+
result?: Json;
|
|
52
|
+
/** Set when some of the task's files failed: how many, as a message. */
|
|
53
|
+
partial?: string;
|
|
54
|
+
}
|
|
55
|
+
/** `host.event(event)`: `HostEvent` in `crates/workflow/src/run.rs`. */
|
|
56
|
+
export type StepEvent = {
|
|
57
|
+
type: "stepStarted" | "stepReplayed";
|
|
58
|
+
position: number;
|
|
59
|
+
label: string;
|
|
60
|
+
} | {
|
|
61
|
+
type: "stepRetrying";
|
|
62
|
+
position: number;
|
|
63
|
+
label: string;
|
|
64
|
+
/** The attempt that failed, counting from 1. */
|
|
65
|
+
attempt: number;
|
|
66
|
+
attempts: number;
|
|
67
|
+
error: string;
|
|
68
|
+
};
|
|
69
|
+
/** How a test runs a workflow; steps are matched by label. */
|
|
70
|
+
export interface TestPlan {
|
|
71
|
+
/** Stop after this step. */
|
|
72
|
+
until?: string;
|
|
73
|
+
/** Results for steps that should not run. */
|
|
74
|
+
given?: Record<string, Json>;
|
|
75
|
+
}
|
|
76
|
+
/** What runs the orchestrator: the engine's QuickJS context, or Node.js. */
|
|
77
|
+
export interface Host {
|
|
78
|
+
/** Steps recorded by earlier executions of the run. */
|
|
79
|
+
history(): StepRecord[];
|
|
80
|
+
/** Persist one step's outcome; `ms` is how long it took. */
|
|
81
|
+
record(entry: StepRecord, ms: number): void;
|
|
82
|
+
event(event: StepEvent): void;
|
|
83
|
+
/** Whether a step about to start must not, because the run was asked to stop. */
|
|
84
|
+
canceled(): boolean;
|
|
85
|
+
/** Run a task. Rejects with `{ name, message }`. */
|
|
86
|
+
start(request: StartRequest): Promise<Outcome>;
|
|
87
|
+
/** Evaluate a workflow.yaml `${{ }}` expression. */
|
|
88
|
+
evaluate(kind: string, expression: string, scope: unknown): unknown;
|
|
89
|
+
/** The real time, for step records. */
|
|
90
|
+
now(): number;
|
|
91
|
+
/** Move the body's clock forward. */
|
|
92
|
+
advanceClock(ms: number): void;
|
|
93
|
+
/** `{ until?, given? }` when the run is a test. */
|
|
94
|
+
testPlan(): TestPlan | null;
|
|
95
|
+
/** The test's `until` step has started. */
|
|
96
|
+
stop(): void;
|
|
97
|
+
/** A replayed step waits for `replayNext()`. */
|
|
98
|
+
wake?(): void;
|
|
99
|
+
/**
|
|
100
|
+
* Identifies a callback given as a function. Hosts without it need the
|
|
101
|
+
* build to extract callbacks.
|
|
102
|
+
*/
|
|
103
|
+
callbackId?(fn: Callback): string;
|
|
104
|
+
}
|
|
105
|
+
export declare class StepError extends Error {
|
|
106
|
+
readonly label: string;
|
|
107
|
+
constructor(label: string, cause: unknown);
|
|
108
|
+
}
|
|
109
|
+
export declare class CanceledError extends Error {
|
|
110
|
+
constructor(message?: string);
|
|
111
|
+
}
|
|
112
|
+
export declare class AwaitingApprovalError extends Error {
|
|
113
|
+
constructor(message?: string);
|
|
114
|
+
}
|
|
115
|
+
declare const TASK: unique symbol;
|
|
116
|
+
/** The files a `forEachFile` step visits, as the engine receives it. */
|
|
117
|
+
export interface Selector {
|
|
118
|
+
include: string[];
|
|
119
|
+
exclude: string[];
|
|
120
|
+
language?: string;
|
|
121
|
+
containing?: string;
|
|
122
|
+
concurrency?: number;
|
|
123
|
+
}
|
|
124
|
+
/** A callback the build extracted, or one given as a function. */
|
|
125
|
+
export interface Extracted {
|
|
126
|
+
id: string;
|
|
127
|
+
/** The outside values an extracted callback uses, read when its step is called. */
|
|
128
|
+
captures?: () => Json;
|
|
129
|
+
fn?: Callback;
|
|
130
|
+
}
|
|
131
|
+
/** What the build puts in place of an extracted callback. */
|
|
132
|
+
export interface CallbackReference {
|
|
133
|
+
__flowCallback: string;
|
|
134
|
+
captures: () => Json;
|
|
135
|
+
}
|
|
136
|
+
export interface ForEachFileTask {
|
|
137
|
+
readonly [TASK]: "forEachFile";
|
|
138
|
+
readonly selector: Selector;
|
|
139
|
+
readonly callback: Extracted;
|
|
140
|
+
}
|
|
141
|
+
export interface HostTask {
|
|
142
|
+
readonly [TASK]: "host";
|
|
143
|
+
readonly content: TaskContent;
|
|
144
|
+
/** `jssg(path, { reduce, initial })`: folds each file's data into one result. */
|
|
145
|
+
readonly reducer?: Reducer;
|
|
146
|
+
}
|
|
147
|
+
export interface Reducer {
|
|
148
|
+
callback: Extracted;
|
|
149
|
+
initial: Json;
|
|
150
|
+
}
|
|
151
|
+
export interface DependencyGraphTask {
|
|
152
|
+
readonly [TASK]: "dependencyGraph";
|
|
153
|
+
readonly lockfiles: string[] | undefined;
|
|
154
|
+
readonly callback: Extracted;
|
|
155
|
+
}
|
|
156
|
+
export type Task = ForEachFileTask | DependencyGraphTask | HostTask;
|
|
157
|
+
/** A length of time: milliseconds, or a string such as "30s" or "10m". */
|
|
158
|
+
export type Duration = number | string;
|
|
159
|
+
/** `step(..., options)`: how to run a step. */
|
|
160
|
+
export interface StepOptions {
|
|
161
|
+
retries?: number;
|
|
162
|
+
retryDelay?: Duration;
|
|
163
|
+
timeout?: Duration;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The task builders (`forEachFile`, `shell`, `jssg`, ...). They only describe
|
|
167
|
+
* work, so they need no run. `options.callbackId(fn)` lets callbacks be given
|
|
168
|
+
* as functions, for hosts that run them in place.
|
|
169
|
+
*/
|
|
170
|
+
export declare function createTasks(options?: Pick<Host, "callbackId">): {
|
|
171
|
+
callbackOf: (value: unknown) => Extracted | null;
|
|
172
|
+
__callback: (id: string, captures: () => Json) => CallbackReference;
|
|
173
|
+
forEachFile: (selector: unknown, callback?: unknown) => ForEachFileTask | HostTask;
|
|
174
|
+
dependencyGraph: (options: unknown, callback: unknown) => DependencyGraphTask;
|
|
175
|
+
shell: (command: unknown, ...rest: unknown[]) => HostTask | ShellTag;
|
|
176
|
+
jssg: (path: string, options?: object) => HostTask;
|
|
177
|
+
astGrep: (path: string, options?: object) => HostTask;
|
|
178
|
+
shard: (options: object) => HostTask;
|
|
179
|
+
codemod: (source: string, options?: object) => HostTask;
|
|
180
|
+
agent: (prompt: string, options?: object) => HostTask;
|
|
181
|
+
installSkill: (options: object) => HostTask;
|
|
182
|
+
approval: (message: string) => HostTask;
|
|
183
|
+
sleep: (duration: Duration) => HostTask;
|
|
184
|
+
waitForEvent: (name: string, options?: {
|
|
185
|
+
timeout?: Duration;
|
|
186
|
+
}) => HostTask;
|
|
187
|
+
branch: (name: string) => HostTask;
|
|
188
|
+
commit: (message: string, options?: object) => HostTask;
|
|
189
|
+
pullRequest: (options: object) => HostTask;
|
|
190
|
+
};
|
|
191
|
+
/** A duration in milliseconds, from a number of them or a string such as "30s". */
|
|
192
|
+
export declare function milliseconds(value: unknown, what: string): number;
|
|
193
|
+
/** A duration in its largest whole unit, as the engine words it. */
|
|
194
|
+
export declare function describeDuration(ms: number): string;
|
|
195
|
+
/** What `createRuntime` returns: `codemod/workflow` for one run, and what its host drives. */
|
|
196
|
+
export type Runtime = ReturnType<typeof createRuntime>;
|
|
197
|
+
/** A tag made by `shell(options)`. */
|
|
198
|
+
type ShellTag = (strings: TemplateStringsArray, ...values: unknown[]) => HostTask;
|
|
199
|
+
export declare function createRuntime(host: Host): {
|
|
200
|
+
__evaluate: (kind: string, expression: string, scope: unknown) => unknown;
|
|
201
|
+
step: (...args: unknown[]) => Promise<Json>;
|
|
202
|
+
sleep: (duration: Duration) => Promise<Json>;
|
|
203
|
+
waitForEvent: (name: string, options?: {
|
|
204
|
+
timeout?: Duration;
|
|
205
|
+
}) => Promise<Json>;
|
|
206
|
+
replayNext: () => boolean;
|
|
207
|
+
close: () => void;
|
|
208
|
+
isClosed: () => boolean;
|
|
209
|
+
__callback: (id: string, captures: () => Json) => CallbackReference;
|
|
210
|
+
forEachFile: (selector: unknown, callback?: unknown) => ForEachFileTask | HostTask;
|
|
211
|
+
dependencyGraph: (options: unknown, callback: unknown) => DependencyGraphTask;
|
|
212
|
+
shell: (command: unknown, ...rest: unknown[]) => HostTask | ShellTag;
|
|
213
|
+
jssg: (path: string, options?: object) => HostTask;
|
|
214
|
+
astGrep: (path: string, options?: object) => HostTask;
|
|
215
|
+
shard: (options: object) => HostTask;
|
|
216
|
+
codemod: (source: string, options?: object) => HostTask;
|
|
217
|
+
agent: (prompt: string, options?: object) => HostTask;
|
|
218
|
+
installSkill: (options: object) => HostTask;
|
|
219
|
+
approval: (message: string) => HostTask;
|
|
220
|
+
branch: (name: string) => HostTask;
|
|
221
|
+
commit: (message: string, options?: object) => HostTask;
|
|
222
|
+
pullRequest: (options: object) => HostTask;
|
|
223
|
+
};
|
|
224
|
+
/** Freeze a JSON value, all the way down. */
|
|
225
|
+
export declare function freeze<T>(value: T): T;
|
|
226
|
+
/**
|
|
227
|
+
* An error as a step's failure says it. Changing a captured value or a step
|
|
228
|
+
* result fails as a TypeError that does not say why; the hint does.
|
|
229
|
+
*/
|
|
230
|
+
export declare function describeError(error: unknown): string;
|
|
231
|
+
/** What a `forEachFile` callback did to its file. */
|
|
232
|
+
export type FileEffect = {
|
|
233
|
+
op: "write";
|
|
234
|
+
text: string;
|
|
235
|
+
} | {
|
|
236
|
+
op: "rename";
|
|
237
|
+
to: string;
|
|
238
|
+
} | {
|
|
239
|
+
op: "delete";
|
|
240
|
+
};
|
|
241
|
+
/** The `file` a `forEachFile` callback gets. */
|
|
242
|
+
export interface WorkflowFile {
|
|
243
|
+
readonly path: string;
|
|
244
|
+
readonly text: string;
|
|
245
|
+
readonly language: string | undefined;
|
|
246
|
+
write(text: string): void;
|
|
247
|
+
rename(to: string): void;
|
|
248
|
+
delete(): void;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* The `file` a `forEachFile` callback gets, and the effects it records on it.
|
|
252
|
+
* After `close()`, when the callback has finished, the file takes no more.
|
|
253
|
+
*/
|
|
254
|
+
export declare function fileHandle(path: string, text: string, language?: string): {
|
|
255
|
+
file: WorkflowFile;
|
|
256
|
+
effects: FileEffect[];
|
|
257
|
+
close(): void;
|
|
258
|
+
};
|
|
259
|
+
/** Throw a TypeError naming the first part of `value` that is not JSON. */
|
|
260
|
+
export declare function checkJson(value: unknown, path: string, seen?: Set<object>): asserts value is Json;
|
|
261
|
+
export {};
|