codemod 1.18.7 → 2.0.0-alpha.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/README.md +57 -2
- package/codemod +17 -30
- package/package.json +78 -10
- package/register.d.mts +11 -0
- package/register.mjs +60 -0
- package/runtime/addon.mjs +59 -0
- package/runtime/ast-grep.mjs +93 -0
- package/runtime/context.mjs +77 -0
- package/runtime/hooks.mjs +9 -0
- package/runtime/host.d.mts +120 -0
- package/runtime/host.mjs +390 -0
- package/runtime/llm.mjs +11 -0
- package/runtime/metrics.mjs +45 -0
- package/runtime/modules.mjs +19 -0
- package/runtime/orchestrator.mjs +657 -0
- package/runtime/runtime.mjs +48 -0
- package/runtime/workflow.mjs +135 -0
- package/testing/index.d.mts +203 -0
- package/testing/index.mjs +638 -0
- package/types/index.d.ts +8 -0
- package/types/langs/angular.d.ts +5 -0
- package/types/langs/c.d.ts +5 -0
- package/types/langs/c_sharp.d.ts +5 -0
- package/types/langs/cpp.d.ts +5 -0
- package/types/langs/css.d.ts +5 -0
- package/types/langs/elixir.d.ts +5 -0
- package/types/langs/go.d.ts +5 -0
- package/types/langs/html.d.ts +5 -0
- package/types/langs/java.d.ts +5 -0
- package/types/langs/javascript.d.ts +5 -0
- package/types/langs/json.d.ts +5 -0
- package/types/langs/kotlin.d.ts +5 -0
- package/types/langs/php.d.ts +5 -0
- package/types/langs/python.d.ts +5 -0
- package/types/langs/ruby.d.ts +5 -0
- package/types/langs/rust.d.ts +5 -0
- package/types/langs/scala.d.ts +5 -0
- package/types/langs/toml.d.ts +5 -0
- package/types/langs/tsx.d.ts +5 -0
- package/types/langs/typescript.d.ts +5 -0
- package/types/langs/xml.d.ts +5 -0
- package/types/langs/yaml.d.ts +5 -0
- package/types/llm.d.ts +6 -0
- package/types/llrt/abort.d.ts +69 -0
- package/types/llrt/assert.d.ts +39 -0
- package/types/llrt/async_hooks.d.ts +210 -0
- package/types/llrt/buffer.d.ts +1186 -0
- package/types/llrt/child_process.d.ts +447 -0
- package/types/llrt/console.d.ts +210 -0
- package/types/llrt/crypto.d.ts +854 -0
- package/types/llrt/dgram.d.ts +381 -0
- package/types/llrt/dns.d.ts +124 -0
- package/types/llrt/dom-events.d.ts +51 -0
- package/types/llrt/events.d.ts +245 -0
- package/types/llrt/exceptions.d.ts +26 -0
- package/types/llrt/fetch.d.ts +332 -0
- package/types/llrt/fs/promises.d.ts +554 -0
- package/types/llrt/fs.d.ts +360 -0
- package/types/llrt/globals.d.ts +23 -0
- package/types/llrt/https.d.ts +27 -0
- package/types/llrt/index.d.ts +33 -0
- package/types/llrt/module.d.ts +285 -0
- package/types/llrt/navigator.d.ts +9 -0
- package/types/llrt/net.d.ts +488 -0
- package/types/llrt/os.d.ts +293 -0
- package/types/llrt/path.d.ts +150 -0
- package/types/llrt/perf_hooks.d.ts +23 -0
- package/types/llrt/process.d.ts +502 -0
- package/types/llrt/stream/web.d.ts +526 -0
- package/types/llrt/stream.d.ts +366 -0
- package/types/llrt/string_decoder.d.ts +63 -0
- package/types/llrt/timers.d.ts +72 -0
- package/types/llrt/timezone.d.ts +101 -0
- package/types/llrt/tty.d.ts +11 -0
- package/types/llrt/url.d.ts +774 -0
- package/types/llrt/util.d.ts +240 -0
- package/types/llrt/zlib.d.ts +177 -0
- package/types/main.d.ts +5 -0
- package/types/metrics.d.ts +5 -0
- package/types/modules/ast-grep.d.ts +634 -0
- package/types/modules/langs.d.ts +87 -0
- package/types/modules/llm.d.ts +23 -0
- package/types/modules/metrics.d.ts +107 -0
- package/types/modules/runtime.d.ts +66 -0
- package/types/modules/workflow.d.ts +750 -0
- package/types/runtime.d.ts +6 -0
- package/types/workflow.d.ts +5 -0
- package/vite.d.mts +24 -0
- package/vite.mjs +26 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
declare module "codemod:ast-grep/langs/angular" {
|
|
2
|
+
export { default } from "codemod/langs/angular";
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
declare module "codemod:ast-grep/langs/c" {
|
|
6
|
+
export { default } from "codemod/langs/c";
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare module "codemod:ast-grep/langs/c_sharp" {
|
|
10
|
+
export { default } from "codemod/langs/c_sharp";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare module "codemod:ast-grep/langs/cpp" {
|
|
14
|
+
export { default } from "codemod/langs/cpp";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare module "codemod:ast-grep/langs/css" {
|
|
18
|
+
export { default } from "codemod/langs/css";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare module "codemod:ast-grep/langs/elixir" {
|
|
22
|
+
export { default } from "codemod/langs/elixir";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
declare module "codemod:ast-grep/langs/go" {
|
|
26
|
+
export { default } from "codemod/langs/go";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare module "codemod:ast-grep/langs/html" {
|
|
30
|
+
export { default } from "codemod/langs/html";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
declare module "codemod:ast-grep/langs/xml" {
|
|
34
|
+
export { default } from "codemod/langs/xml";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
declare module "codemod:ast-grep/langs/json" {
|
|
38
|
+
export { default } from "codemod/langs/json";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
declare module "codemod:ast-grep/langs/java" {
|
|
42
|
+
export { default } from "codemod/langs/java";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
declare module "codemod:ast-grep/langs/javascript" {
|
|
46
|
+
export { default } from "codemod/langs/javascript";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
declare module "codemod:ast-grep/langs/kotlin" {
|
|
50
|
+
export { default } from "codemod/langs/kotlin";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
declare module "codemod:ast-grep/langs/php" {
|
|
54
|
+
export { default } from "codemod/langs/php";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
declare module "codemod:ast-grep/langs/python" {
|
|
58
|
+
export { default } from "codemod/langs/python";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
declare module "codemod:ast-grep/langs/ruby" {
|
|
62
|
+
export { default } from "codemod/langs/ruby";
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
declare module "codemod:ast-grep/langs/rust" {
|
|
66
|
+
export { default } from "codemod/langs/rust";
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
declare module "codemod:ast-grep/langs/scala" {
|
|
70
|
+
export { default } from "codemod/langs/scala";
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
declare module "codemod:ast-grep/langs/tsx" {
|
|
74
|
+
export { default } from "codemod/langs/tsx";
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
declare module "codemod:ast-grep/langs/typescript" {
|
|
78
|
+
export { default } from "codemod/langs/typescript";
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
declare module "codemod:ast-grep/langs/toml" {
|
|
82
|
+
export { default } from "codemod/langs/toml";
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
declare module "codemod:ast-grep/langs/yaml" {
|
|
86
|
+
export { default } from "codemod/langs/yaml";
|
|
87
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare module "codemod:llm" {
|
|
2
|
+
export interface LlmRequest {
|
|
3
|
+
prompt: string;
|
|
4
|
+
systemPrompt?: string;
|
|
5
|
+
outputSchema?: Record<string, unknown> | boolean;
|
|
6
|
+
maxTokens?: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface LlmResponse {
|
|
10
|
+
output: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Generate text through the engine-owned LLM client.
|
|
15
|
+
*
|
|
16
|
+
* Provider credentials and model selection come from the engine. The engine
|
|
17
|
+
* records provider-reported usage automatically; codemods never submit usage
|
|
18
|
+
* telemetry themselves. The codemod must declare the `fetch` capability.
|
|
19
|
+
*/
|
|
20
|
+
export function generate(request: LlmRequest): Promise<LlmResponse>;
|
|
21
|
+
|
|
22
|
+
export default generate;
|
|
23
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
declare module "codemod:metrics" {
|
|
2
|
+
/**
|
|
3
|
+
* Cardinality dimensions for a metric entry.
|
|
4
|
+
* Keys and values must be strings. Undefined/null values are omitted.
|
|
5
|
+
*/
|
|
6
|
+
export type Cardinality = Record<string, string | undefined | null>;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A metric entry with its cardinality dimensions and count.
|
|
10
|
+
*/
|
|
11
|
+
export interface MetricEntry {
|
|
12
|
+
cardinality: Record<string, string>;
|
|
13
|
+
count: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A metric atom for tracking counts with cardinality dimensions.
|
|
18
|
+
*
|
|
19
|
+
* MetricAtom provides a way to increment and retrieve counts for different
|
|
20
|
+
* cardinality combinations within a named metric. This is useful for tracking
|
|
21
|
+
* things like prop usage counts with multiple dimensions (e.g., propName + propValue).
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { useMetricAtom } from "codemod/metrics";
|
|
26
|
+
*
|
|
27
|
+
* const propUsage = useMetricAtom("prop-usage");
|
|
28
|
+
*
|
|
29
|
+
* export function transform(root) {
|
|
30
|
+
* root.findAll({ rule: { pattern: "$PROP={$_}" } }).forEach((match) => {
|
|
31
|
+
* propUsage.increment({
|
|
32
|
+
* propName: match.getMatch("PROP")?.text(),
|
|
33
|
+
* });
|
|
34
|
+
* });
|
|
35
|
+
* return null;
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export class MetricAtom {
|
|
40
|
+
/**
|
|
41
|
+
* The name of this metric.
|
|
42
|
+
*/
|
|
43
|
+
readonly name: string;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Increment the count for a given cardinality combination.
|
|
47
|
+
*
|
|
48
|
+
* @param cardinality - Object with dimension key-value pairs. Undefined/null values are omitted.
|
|
49
|
+
* @param amount - The amount to increment by (default: 1)
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* // Simple increment with no cardinality
|
|
54
|
+
* metric.increment();
|
|
55
|
+
*
|
|
56
|
+
* // Single dimension
|
|
57
|
+
* propUsage.increment({ propName: "title" });
|
|
58
|
+
*
|
|
59
|
+
* // Multiple dimensions
|
|
60
|
+
* propUsage.increment({ propName: "className", propValue: "container" });
|
|
61
|
+
*
|
|
62
|
+
* // With amount
|
|
63
|
+
* propUsage.increment({ propName: "title" }, 5);
|
|
64
|
+
*
|
|
65
|
+
* // Undefined values are omitted
|
|
66
|
+
* propUsage.increment({ propName: "title", propValue: undefined });
|
|
67
|
+
* // Results in cardinality: { propName: "title" }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
increment(cardinality?: Cardinality, amount?: number): void;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Get the current entries for this metric.
|
|
74
|
+
*
|
|
75
|
+
* @returns An array of entries with their cardinality and count
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* const entries = propUsage.getEntries();
|
|
80
|
+
* // [
|
|
81
|
+
* // { cardinality: { propName: "title" }, count: 10 },
|
|
82
|
+
* // { cardinality: { propName: "className", propValue: "container" }, count: 5 }
|
|
83
|
+
* // ]
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
getEntries(): MetricEntry[];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Create or retrieve a metric atom with the given name.
|
|
91
|
+
*
|
|
92
|
+
* Multiple calls with the same name will return atoms that share the same
|
|
93
|
+
* underlying data, allowing metrics to be collected across multiple files.
|
|
94
|
+
*
|
|
95
|
+
* @param name - The name of the metric (e.g., "prop-usage", "component-count")
|
|
96
|
+
* @returns A MetricAtom instance for tracking counts with cardinality
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* import { useMetricAtom } from "codemod/metrics";
|
|
101
|
+
*
|
|
102
|
+
* const propUsage = useMetricAtom("prop-usage");
|
|
103
|
+
* const componentCount = useMetricAtom("component-count");
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export function useMetricAtom(name: string): MetricAtom;
|
|
107
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
declare module "codemod:runtime" {
|
|
2
|
+
export type RuntimeMeta =
|
|
3
|
+
| string
|
|
4
|
+
| number
|
|
5
|
+
| boolean
|
|
6
|
+
| null
|
|
7
|
+
| { [key: string]: RuntimeMeta | undefined }
|
|
8
|
+
| RuntimeMeta[];
|
|
9
|
+
|
|
10
|
+
export interface RuntimeHooks {
|
|
11
|
+
/**
|
|
12
|
+
* Emit a progress event for the current execution context.
|
|
13
|
+
*
|
|
14
|
+
* Progress events are surfaced in task logs and refresh the runtime heartbeat
|
|
15
|
+
* so long-running steps can prove they are still making forward progress.
|
|
16
|
+
*/
|
|
17
|
+
progress(message: string, meta?: RuntimeMeta): void;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Emit a non-fatal warning for the current execution context.
|
|
21
|
+
*
|
|
22
|
+
* Warning events are appended to task logs but do not change task state.
|
|
23
|
+
*/
|
|
24
|
+
warn(message: string, meta?: RuntimeMeta): void;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Override the current logical execution unit for diagnostics.
|
|
28
|
+
*
|
|
29
|
+
* For file-based transforms, this is typically a relative file path. The
|
|
30
|
+
* runtime uses it to improve watchdog diagnostics and progress attribution.
|
|
31
|
+
*/
|
|
32
|
+
setCurrentUnit(unitId: string, meta?: RuntimeMeta): void;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Fail the current file or execution unit immediately.
|
|
36
|
+
*
|
|
37
|
+
* The runtime currently treats this as a terminal task failure.
|
|
38
|
+
*/
|
|
39
|
+
failFile(message: string, meta?: RuntimeMeta): never;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Fail the current step immediately.
|
|
43
|
+
*
|
|
44
|
+
* This is always terminal for the running task.
|
|
45
|
+
*/
|
|
46
|
+
failStep(message: string, meta?: RuntimeMeta): never;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Return whether the current execution has been canceled.
|
|
50
|
+
*
|
|
51
|
+
* Codemods can poll this to stop cooperatively during long-running work.
|
|
52
|
+
*/
|
|
53
|
+
isCanceled(): boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
declare const runtime: RuntimeHooks;
|
|
57
|
+
|
|
58
|
+
export default runtime;
|
|
59
|
+
|
|
60
|
+
export const progress: RuntimeHooks["progress"];
|
|
61
|
+
export const warn: RuntimeHooks["warn"];
|
|
62
|
+
export const setCurrentUnit: RuntimeHooks["setCurrentUnit"];
|
|
63
|
+
export const failFile: RuntimeHooks["failFile"];
|
|
64
|
+
export const failStep: RuntimeHooks["failStep"];
|
|
65
|
+
export const isCanceled: RuntimeHooks["isCanceled"];
|
|
66
|
+
}
|