codemod 2.0.0-alpha.1 → 2.0.0-alpha.3

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.
Files changed (102) hide show
  1. package/README.md +56 -2
  2. package/codemod +17 -30
  3. package/package.json +80 -10
  4. package/register.d.mts +2 -0
  5. package/register.mjs +67 -0
  6. package/runtime/addon.d.mts +114 -0
  7. package/runtime/addon.mjs +55 -0
  8. package/runtime/ast-grep.d.mts +20 -0
  9. package/runtime/ast-grep.mjs +82 -0
  10. package/runtime/context.d.mts +49 -0
  11. package/runtime/context.mjs +59 -0
  12. package/runtime/hooks.d.mts +2 -0
  13. package/runtime/hooks.mjs +7 -0
  14. package/runtime/host.d.mts +121 -0
  15. package/runtime/host.mjs +450 -0
  16. package/runtime/llm.d.mts +2 -0
  17. package/runtime/llm.mjs +5 -0
  18. package/runtime/metrics.d.mts +9 -0
  19. package/runtime/metrics.mjs +42 -0
  20. package/runtime/modules.d.mts +3 -0
  21. package/runtime/modules.mjs +17 -0
  22. package/runtime/orchestrator-version.d.mts +2 -0
  23. package/runtime/orchestrator-version.mjs +3 -0
  24. package/runtime/orchestrator.d.mts +261 -0
  25. package/runtime/orchestrator.mjs +879 -0
  26. package/runtime/runtime.d.mts +15 -0
  27. package/runtime/runtime.mjs +40 -0
  28. package/runtime/workflow.d.mts +19 -0
  29. package/runtime/workflow.mjs +126 -0
  30. package/testing/index.d.mts +157 -0
  31. package/testing/index.mjs +648 -0
  32. package/types/index.d.ts +8 -0
  33. package/types/langs/angular.d.ts +5 -0
  34. package/types/langs/c.d.ts +5 -0
  35. package/types/langs/c_sharp.d.ts +5 -0
  36. package/types/langs/cpp.d.ts +5 -0
  37. package/types/langs/css.d.ts +5 -0
  38. package/types/langs/elixir.d.ts +5 -0
  39. package/types/langs/go.d.ts +5 -0
  40. package/types/langs/html.d.ts +5 -0
  41. package/types/langs/java.d.ts +5 -0
  42. package/types/langs/javascript.d.ts +5 -0
  43. package/types/langs/json.d.ts +5 -0
  44. package/types/langs/kotlin.d.ts +5 -0
  45. package/types/langs/package.json +3 -0
  46. package/types/langs/php.d.ts +5 -0
  47. package/types/langs/python.d.ts +5 -0
  48. package/types/langs/ruby.d.ts +5 -0
  49. package/types/langs/rust.d.ts +5 -0
  50. package/types/langs/scala.d.ts +5 -0
  51. package/types/langs/toml.d.ts +5 -0
  52. package/types/langs/tsx.d.ts +5 -0
  53. package/types/langs/typescript.d.ts +5 -0
  54. package/types/langs/xml.d.ts +5 -0
  55. package/types/langs/yaml.d.ts +5 -0
  56. package/types/llm.d.ts +6 -0
  57. package/types/llrt/abort.d.ts +69 -0
  58. package/types/llrt/assert.d.ts +39 -0
  59. package/types/llrt/async_hooks.d.ts +210 -0
  60. package/types/llrt/buffer.d.ts +1186 -0
  61. package/types/llrt/child_process.d.ts +447 -0
  62. package/types/llrt/console.d.ts +210 -0
  63. package/types/llrt/crypto.d.ts +854 -0
  64. package/types/llrt/dgram.d.ts +381 -0
  65. package/types/llrt/dns.d.ts +124 -0
  66. package/types/llrt/dom-events.d.ts +51 -0
  67. package/types/llrt/events.d.ts +245 -0
  68. package/types/llrt/exceptions.d.ts +26 -0
  69. package/types/llrt/fetch.d.ts +332 -0
  70. package/types/llrt/fs/promises.d.ts +554 -0
  71. package/types/llrt/fs.d.ts +360 -0
  72. package/types/llrt/globals.d.ts +23 -0
  73. package/types/llrt/https.d.ts +27 -0
  74. package/types/llrt/index.d.ts +33 -0
  75. package/types/llrt/module.d.ts +285 -0
  76. package/types/llrt/navigator.d.ts +9 -0
  77. package/types/llrt/net.d.ts +488 -0
  78. package/types/llrt/os.d.ts +293 -0
  79. package/types/llrt/path.d.ts +150 -0
  80. package/types/llrt/perf_hooks.d.ts +23 -0
  81. package/types/llrt/process.d.ts +502 -0
  82. package/types/llrt/stream/web.d.ts +526 -0
  83. package/types/llrt/stream.d.ts +366 -0
  84. package/types/llrt/string_decoder.d.ts +63 -0
  85. package/types/llrt/timers.d.ts +72 -0
  86. package/types/llrt/timezone.d.ts +101 -0
  87. package/types/llrt/tty.d.ts +11 -0
  88. package/types/llrt/url.d.ts +774 -0
  89. package/types/llrt/util.d.ts +240 -0
  90. package/types/llrt/zlib.d.ts +177 -0
  91. package/types/main.d.ts +5 -0
  92. package/types/metrics.d.ts +5 -0
  93. package/types/modules/ast-grep.d.ts +634 -0
  94. package/types/modules/langs.d.ts +87 -0
  95. package/types/modules/llm.d.ts +23 -0
  96. package/types/modules/metrics.d.ts +107 -0
  97. package/types/modules/runtime.d.ts +66 -0
  98. package/types/modules/workflow.d.ts +915 -0
  99. package/types/runtime.d.ts +6 -0
  100. package/types/workflow.d.ts +5 -0
  101. package/vite.d.mts +7 -0
  102. package/vite.mjs +32 -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
+ }