@ekaone/json-cli 0.1.3 → 0.1.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/dist/cli.cjs +21 -7
- package/dist/index.cjs +13 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +13 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -29,18 +29,21 @@ var p = __toESM(require("@clack/prompts"), 1);
|
|
|
29
29
|
// src/providers/claude.ts
|
|
30
30
|
var import_sdk = __toESM(require("@anthropic-ai/sdk"), 1);
|
|
31
31
|
function createClaudeProvider(apiKey) {
|
|
32
|
-
const client = new import_sdk.default({
|
|
32
|
+
const client = new import_sdk.default({
|
|
33
|
+
apiKey: apiKey ?? process.env.ANTHROPIC_API_KEY
|
|
34
|
+
});
|
|
33
35
|
return {
|
|
34
36
|
name: "claude",
|
|
35
37
|
async generate(userPrompt, systemPrompt) {
|
|
36
38
|
const message = await client.messages.create({
|
|
37
|
-
model: "claude-
|
|
39
|
+
model: "claude-sonnet-4-6",
|
|
38
40
|
max_tokens: 1024,
|
|
39
41
|
system: systemPrompt,
|
|
40
42
|
messages: [{ role: "user", content: userPrompt }]
|
|
41
43
|
});
|
|
42
44
|
const block = message.content[0];
|
|
43
|
-
if (block.type !== "text")
|
|
45
|
+
if (block.type !== "text")
|
|
46
|
+
throw new Error("Unexpected response type from Claude");
|
|
44
47
|
return block.text;
|
|
45
48
|
}
|
|
46
49
|
};
|
|
@@ -140,7 +143,7 @@ var StepSchema = import_zod.z.object({
|
|
|
140
143
|
command: import_zod.z.string(),
|
|
141
144
|
args: import_zod.z.array(import_zod.z.string()).default([]),
|
|
142
145
|
description: import_zod.z.string(),
|
|
143
|
-
cwd: import_zod.z.string().optional()
|
|
146
|
+
cwd: import_zod.z.string().nullable().optional()
|
|
144
147
|
// optional working directory override
|
|
145
148
|
});
|
|
146
149
|
var PlanSchema = import_zod.z.object({
|
|
@@ -183,6 +186,7 @@ Rules:
|
|
|
183
186
|
- Each step must have a clear, short description
|
|
184
187
|
- NEVER generate a "cd" step \u2014 each step runs in a separate process so "cd" has no effect
|
|
185
188
|
- If subsequent steps need to run inside a cloned directory, set the "cwd" field instead
|
|
189
|
+
- For commands that take a message or value argument (like git commit -m), always keep the full message as a single array element, e.g. args: ["-m", "Update changes"] never args: ["-m", "Update", "changes"]
|
|
186
190
|
|
|
187
191
|
Respond ONLY with valid JSON matching this exact shape, no markdown, no explanation:
|
|
188
192
|
{
|
|
@@ -190,10 +194,19 @@ Respond ONLY with valid JSON matching this exact shape, no markdown, no explanat
|
|
|
190
194
|
"steps": [
|
|
191
195
|
{
|
|
192
196
|
"id": 1,
|
|
197
|
+
"type": "git",
|
|
198
|
+
"command": "commit",
|
|
199
|
+
"args": ["-m", "Update changes"],
|
|
200
|
+
"description": "Commit staged changes",
|
|
201
|
+
"cwd": null
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
"id": 2,
|
|
193
205
|
"type": "pnpm",
|
|
194
206
|
"command": "run",
|
|
195
|
-
"args": ["dev"],
|
|
196
|
-
"description": "Start dev server"
|
|
207
|
+
"args": ["dev", "--port", "3000"],
|
|
208
|
+
"description": "Start dev server",
|
|
209
|
+
"cwd": "my-repo"
|
|
197
210
|
}
|
|
198
211
|
]
|
|
199
212
|
}`;
|
|
@@ -311,7 +324,8 @@ function parseArgs() {
|
|
|
311
324
|
return { prompt, provider, yes, dryRun };
|
|
312
325
|
}
|
|
313
326
|
function formatStep(step) {
|
|
314
|
-
const
|
|
327
|
+
const formatArg = (arg) => arg.includes(" ") ? `"${arg}"` : arg;
|
|
328
|
+
const cmd = step.type === "shell" ? `${step.command} ${step.args.map(formatArg).join(" ")}` : `${step.type} ${step.command} ${step.args.map(formatArg).join(" ")}`.trim();
|
|
315
329
|
return `${cmd.padEnd(35)} \u2192 ${step.description}`;
|
|
316
330
|
}
|
|
317
331
|
async function main() {
|
package/dist/index.cjs
CHANGED
|
@@ -55,7 +55,7 @@ var StepSchema = import_zod.z.object({
|
|
|
55
55
|
command: import_zod.z.string(),
|
|
56
56
|
args: import_zod.z.array(import_zod.z.string()).default([]),
|
|
57
57
|
description: import_zod.z.string(),
|
|
58
|
-
cwd: import_zod.z.string().optional()
|
|
58
|
+
cwd: import_zod.z.string().nullable().optional()
|
|
59
59
|
// optional working directory override
|
|
60
60
|
});
|
|
61
61
|
var PlanSchema = import_zod.z.object({
|
|
@@ -98,6 +98,7 @@ Rules:
|
|
|
98
98
|
- Each step must have a clear, short description
|
|
99
99
|
- NEVER generate a "cd" step \u2014 each step runs in a separate process so "cd" has no effect
|
|
100
100
|
- If subsequent steps need to run inside a cloned directory, set the "cwd" field instead
|
|
101
|
+
- For commands that take a message or value argument (like git commit -m), always keep the full message as a single array element, e.g. args: ["-m", "Update changes"] never args: ["-m", "Update", "changes"]
|
|
101
102
|
|
|
102
103
|
Respond ONLY with valid JSON matching this exact shape, no markdown, no explanation:
|
|
103
104
|
{
|
|
@@ -105,10 +106,19 @@ Respond ONLY with valid JSON matching this exact shape, no markdown, no explanat
|
|
|
105
106
|
"steps": [
|
|
106
107
|
{
|
|
107
108
|
"id": 1,
|
|
109
|
+
"type": "git",
|
|
110
|
+
"command": "commit",
|
|
111
|
+
"args": ["-m", "Update changes"],
|
|
112
|
+
"description": "Commit staged changes",
|
|
113
|
+
"cwd": null
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"id": 2,
|
|
108
117
|
"type": "pnpm",
|
|
109
118
|
"command": "run",
|
|
110
|
-
"args": ["dev"],
|
|
111
|
-
"description": "Start dev server"
|
|
119
|
+
"args": ["dev", "--port", "3000"],
|
|
120
|
+
"description": "Start dev server",
|
|
121
|
+
"cwd": "my-repo"
|
|
112
122
|
}
|
|
113
123
|
]
|
|
114
124
|
}`;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/catalog.ts","../src/planner.ts","../src/runner.ts"],"sourcesContent":["/**\n * @file index.ts\n * @description Core entry point for @ekaone/json-cli.\n * @author Eka Prasetia\n * @website https://prasetia.me\n * @license MIT\n */\n\nexport { generatePlan } from \"./planner.js\";\nexport { runPlan } from \"./runner.js\";\nexport type { Plan, Step } from \"./catalog.js\";\nexport type { AIProvider } from \"./providers/types.js\";\n","import { z } from \"zod\";\n\n// ---------------------------------------------------------------------------\n// Allowed commands per type — the whitelist that prevents hallucination\n// ---------------------------------------------------------------------------\nexport const CATALOG = {\n npm: [\"install\", \"run\", \"build\", \"test\", \"publish\", \"ci\"],\n pnpm: [\"install\", \"run\", \"build\", \"test\", \"publish\", \"add\", \"remove\"],\n yarn: [\"install\", \"run\", \"build\", \"test\", \"publish\", \"add\", \"remove\"],\n bun: [\"install\", \"run\", \"build\", \"test\", \"publish\", \"add\", \"remove\"],\n git: [\n \"init\",\n \"add\",\n \"commit\",\n \"push\",\n \"pull\",\n \"clone\",\n \"status\",\n \"log\",\n \"branch\",\n \"checkout\",\n \"merge\",\n \"stash\",\n ],\n shell: [\"any\"], // escape hatch — always requires extra confirmation\n} as const;\n\nexport type CommandType = keyof typeof CATALOG;\n\n// ---------------------------------------------------------------------------\n// Zod schemas — Layer 2 defense against hallucinated output\n// ---------------------------------------------------------------------------\nexport const StepSchema = z.object({\n id: z.number(),\n type: z.enum([\"npm\", \"pnpm\", \"yarn\", \"bun\", \"git\", \"shell\"]),\n command: z.string(),\n args: z.array(z.string()).default([]),\n description: z.string(),\n cwd: z.string().optional(), // optional working directory override\n});\n\nexport const PlanSchema = z.object({\n goal: z.string(),\n steps: z.array(StepSchema).min(1).max(10),\n});\n\nexport type Step = z.infer<typeof StepSchema>;\nexport type Plan = z.infer<typeof PlanSchema>;\n\n// ---------------------------------------------------------------------------\n// Catalog validation — Layer 3: check command is in whitelist\n// ---------------------------------------------------------------------------\nexport function validateStep(step: Step): { valid: boolean; reason?: string } {\n const allowed = CATALOG[step.type];\n\n // shell type is always allowed but flagged for extra confirmation\n if (step.type === \"shell\") {\n return { valid: true };\n }\n\n if (!allowed.includes(step.command as never)) {\n return {\n valid: false,\n reason: `\"${step.command}\" is not an allowed command for type \"${step.type}\". Allowed: ${allowed.join(\", \")}`,\n };\n }\n\n return { valid: true };\n}\n\n// ---------------------------------------------------------------------------\n// Build the catalog string injected into AI system prompt\n// ---------------------------------------------------------------------------\nexport function buildCatalogPrompt(): string {\n const lines = Object.entries(CATALOG).map(([type, commands]) => {\n const list =\n commands[0] === \"any\"\n ? \"any shell command (use sparingly)\"\n : commands.join(\", \");\n return ` - ${type}: [${list}]`;\n });\n\n return `Allowed command types and commands:\\n${lines.join(\"\\n\")}`;\n}\n","import { buildCatalogPrompt, PlanSchema, validateStep } from \"./catalog.js\";\nimport type { AIProvider } from \"./providers/types.js\";\nimport type { Plan } from \"./catalog.js\";\n\n// ---------------------------------------------------------------------------\n// System prompt — constrains AI to only produce catalog-valid JSON\n// ---------------------------------------------------------------------------\nfunction buildSystemPrompt(): string {\n return `You are a CLI task planner. Given a user's goal, generate a JSON execution plan.\n\n${buildCatalogPrompt()}\n\nRules:\n- ONLY use command types and commands listed above\n- Prefer pnpm over npm unless the user specifies otherwise\n- Use \"shell\" type only when no other type fits\n- Keep steps minimal — don't add unnecessary steps\n- Each step must have a clear, short description\n- NEVER generate a \"cd\" step — each step runs in a separate process so \"cd\" has no effect\n- If subsequent steps need to run inside a cloned directory, set the \"cwd\" field instead\n\nRespond ONLY with valid JSON matching this exact shape, no markdown, no explanation:\n{\n \"goal\": \"string describing the overall goal\",\n \"steps\": [\n {\n \"id\": 1,\n \"type\": \"pnpm\",\n \"command\": \"run\",\n \"args\": [\"dev\"],\n \"description\": \"Start dev server\"\n }\n ]\n}`;\n}\n\n// ---------------------------------------------------------------------------\n// Main planner function\n// ---------------------------------------------------------------------------\nexport async function generatePlan(\n userPrompt: string,\n provider: AIProvider,\n): Promise<Plan> {\n const raw = await provider.generate(userPrompt, buildSystemPrompt());\n\n // Strip markdown fences if any provider wraps output\n const cleaned = raw.replace(/```json|```/g, \"\").trim();\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(cleaned);\n } catch {\n throw new Error(`AI returned invalid JSON:\\n${cleaned}`);\n }\n\n // Layer 2: Zod shape validation\n const result = PlanSchema.safeParse(parsed);\n if (!result.success) {\n const issues = result.error.issues\n .map((i) => ` - ${i.path.join(\".\")}: ${i.message}`)\n .join(\"\\n\");\n throw new Error(`Plan failed schema validation:\\n${issues}`);\n }\n\n // Layer 3: Catalog whitelist validation\n for (const step of result.data.steps) {\n const check = validateStep(step);\n if (!check.valid) {\n throw new Error(\n `Step ${step.id} failed catalog validation: ${check.reason}`,\n );\n }\n }\n\n return result.data;\n}\n","import { execa } from \"execa\";\nimport type { Plan, Step } from \"./catalog.js\";\n\n// ---------------------------------------------------------------------------\n// Build the actual shell command from a Step\n// ---------------------------------------------------------------------------\nfunction resolveCommand(step: Step): { bin: string; args: string[] } {\n if (step.type === \"shell\") {\n // shell: command is the binary, args are the args\n return { bin: step.command, args: step.args };\n }\n\n // For npm/pnpm/yarn/bun/git: binary is the type, command + args follow\n return { bin: step.type, args: [step.command, ...step.args] };\n}\n\n// ---------------------------------------------------------------------------\n// Run a single step, streaming stdout/stderr live\n// ---------------------------------------------------------------------------\nexport async function runStep(\n step: Step,\n): Promise<{ success: boolean; error?: string }> {\n const { bin, args } = resolveCommand(step);\n\n try {\n await execa(bin, args, {\n cwd: step.cwd ?? process.cwd(),\n stdout: \"inherit\", // stream directly to terminal\n stderr: \"inherit\",\n });\n return { success: true };\n } catch (err: any) {\n const parts = [\n `Command: ${bin} ${args.join(\" \")}`,\n err?.exitCode ? `Exit code: ${err.exitCode}` : null,\n err?.stderr ? `Reason: ${err.stderr.trim()}` : null,\n !err?.stderr ? (err?.message ?? String(err)) : null,\n ]\n .filter(Boolean)\n .join(\"\\n \");\n\n return { success: false, error: parts };\n }\n}\n\n// ---------------------------------------------------------------------------\n// Run the full plan, stopping on first failure\n// ---------------------------------------------------------------------------\nexport async function runPlan(\n plan: Plan,\n onStep: (step: Step, index: number, total: number) => void,\n): Promise<{ success: boolean; failedStep?: Step; error?: string }> {\n const total = plan.steps.length;\n\n for (let i = 0; i < total; i++) {\n const step = plan.steps[i];\n onStep(step, i, total);\n\n const result = await runStep(step);\n\n if (!result.success) {\n return { success: false, failedStep: step, error: result.error };\n }\n }\n\n return { success: true };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAkB;AAKX,IAAM,UAAU;AAAA,EACrB,KAAK,CAAC,WAAW,OAAO,SAAS,QAAQ,WAAW,IAAI;AAAA,EACxD,MAAM,CAAC,WAAW,OAAO,SAAS,QAAQ,WAAW,OAAO,QAAQ;AAAA,EACpE,MAAM,CAAC,WAAW,OAAO,SAAS,QAAQ,WAAW,OAAO,QAAQ;AAAA,EACpE,KAAK,CAAC,WAAW,OAAO,SAAS,QAAQ,WAAW,OAAO,QAAQ;AAAA,EACnE,KAAK;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,OAAO,CAAC,KAAK;AAAA;AACf;AAOO,IAAM,aAAa,aAAE,OAAO;AAAA,EACjC,IAAI,aAAE,OAAO;AAAA,EACb,MAAM,aAAE,KAAK,CAAC,OAAO,QAAQ,QAAQ,OAAO,OAAO,OAAO,CAAC;AAAA,EAC3D,SAAS,aAAE,OAAO;AAAA,EAClB,MAAM,aAAE,MAAM,aAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC;AAAA,EACpC,aAAa,aAAE,OAAO;AAAA,EACtB,KAAK,aAAE,OAAO,EAAE,SAAS;AAAA;AAC3B,CAAC;AAEM,IAAM,aAAa,aAAE,OAAO;AAAA,E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AK,WAAW,OAAO,GAAG,IAAK;AAAA,IACjD,EACG,OAAO,OAAO,EACd,KAAK,OAAO;AAEf,WAAO,EAAE,SAAS,OAAO,OAAO,MAAM;AAAA,EACxC;AACF;AAKA,eAAsB,QACpB,MACA,QACkE;AAClE,QAAM,QAAQ,KAAK,MAAM;AAEzB,WAAS,IAAI,GAAG,IAAI,OAAO,KAAK;AAC9B,UAAM,OAAO,KAAK,MAAM,CAAC;AACzB,WAAO,MAAM,GAAG,KAAK;AAErB,UAAM,SAAS,MAAM,QAAQ,IAAI;AAEjC,QAAI,CAAC,OAAO,SAAS;AACnB,aAAO,EAAE,SAAS,OAAO,YAAY,MAAM,OAAO,OAAO,MAAM;AAAA,IACjE;AAAA,EACF;AAEA,SAAO,EAAE,SAAS,KAAK;AACzB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/catalog.ts","../src/planner.ts","../src/runner.ts"],"sourcesContent":["/**\n * @file index.ts\n * @description Core entry point for @ekaone/json-cli.\n * @author Eka Prasetia\n * @website https://prasetia.me\n * @license MIT\n */\n\nexport { generatePlan } from \"./planner.js\";\nexport { runPlan } from \"./runner.js\";\nexport type { Plan, Step } from \"./catalog.js\";\nexport type { AIProvider } from \"./providers/types.js\";\n","import { z } from \"zod\";\n\n// ---------------------------------------------------------------------------\n// Allowed commands per type — the whitelist that prevents hallucination\n// ---------------------------------------------------------------------------\nexport const CATALOG = {\n npm: [\"install\", \"run\", \"build\", \"test\", \"publish\", \"ci\"],\n pnpm: [\"install\", \"run\", \"build\", \"test\", \"publish\", \"add\", \"remove\"],\n yarn: [\"install\", \"run\", \"build\", \"test\", \"publish\", \"add\", \"remove\"],\n bun: [\"install\", \"run\", \"build\", \"test\", \"publish\", \"add\", \"remove\"],\n git: [\n \"init\",\n \"add\",\n \"commit\",\n \"push\",\n \"pull\",\n \"clone\",\n \"status\",\n \"log\",\n \"branch\",\n \"checkout\",\n \"merge\",\n \"stash\",\n ],\n shell: [\"any\"], // escape hatch — always requires extra confirmation\n} as const;\n\nexport type CommandType = keyof typeof CATALOG;\n\n// ---------------------------------------------------------------------------\n// Zod schemas — Layer 2 defense against hallucinated output\n// ---------------------------------------------------------------------------\nexport const StepSchema = z.object({\n id: z.number(),\n type: z.enum([\"npm\", \"pnpm\", \"yarn\", \"bun\", \"git\", \"shell\"]),\n command: z.string(),\n args: z.array(z.string()).default([]),\n description: z.string(),\n cwd: z.string().nullable().optional(), // optional working directory override\n});\n\nexport const PlanSchema = z.object({\n goal: z.string(),\n steps: z.array(StepSchema).min(1).max(10),\n});\n\nexport type Step = z.infer<typeof StepSchema>;\nexport type Plan = z.infer<typeof PlanSchema>;\n\n// ---------------------------------------------------------------------------\n// Catalog validation — Layer 3: check command is in whitelist\n// ---------------------------------------------------------------------------\nexport function validateStep(step: Step): { valid: boolean; reason?: string } {\n const allowed = CATALOG[step.type];\n\n // shell type is always allowed but flagged for extra confirmation\n if (step.type === \"shell\") {\n return { valid: true };\n }\n\n if (!allowed.includes(step.command as never)) {\n return {\n valid: false,\n reason: `\"${step.command}\" is not an allowed command for type \"${step.type}\". Allowed: ${allowed.join(\", \")}`,\n };\n }\n\n return { valid: true };\n}\n\n// ---------------------------------------------------------------------------\n// Build the catalog string injected into AI system prompt\n// ---------------------------------------------------------------------------\nexport function buildCatalogPrompt(): string {\n const lines = Object.entries(CATALOG).map(([type, commands]) => {\n const list =\n commands[0] === \"any\"\n ? \"any shell command (use sparingly)\"\n : commands.join(\", \");\n return ` - ${type}: [${list}]`;\n });\n\n return `Allowed command types and commands:\\n${lines.join(\"\\n\")}`;\n}\n","import { buildCatalogPrompt, PlanSchema, validateStep } from \"./catalog.js\";\nimport type { AIProvider } from \"./providers/types.js\";\nimport type { Plan } from \"./catalog.js\";\n\n// ---------------------------------------------------------------------------\n// System prompt — constrains AI to only produce catalog-valid JSON\n// ---------------------------------------------------------------------------\nfunction buildSystemPrompt(): string {\n return `You are a CLI task planner. Given a user's goal, generate a JSON execution plan.\n\n${buildCatalogPrompt()}\n\nRules:\n- ONLY use command types and commands listed above\n- Prefer pnpm over npm unless the user specifies otherwise\n- Use \"shell\" type only when no other type fits\n- Keep steps minimal — don't add unnecessary steps\n- Each step must have a clear, short description\n- NEVER generate a \"cd\" step — each step runs in a separate process so \"cd\" has no effect\n- If subsequent steps need to run inside a cloned directory, set the \"cwd\" field instead\n- For commands that take a message or value argument (like git commit -m), always keep the full message as a single array element, e.g. args: [\"-m\", \"Update changes\"] never args: [\"-m\", \"Update\", \"changes\"]\n\nRespond ONLY with valid JSON matching this exact shape, no markdown, no explanation:\n{\n \"goal\": \"string describing the overall goal\",\n \"steps\": [\n {\n \"id\": 1,\n \"type\": \"git\",\n \"command\": \"commit\",\n \"args\": [\"-m\", \"Update changes\"],\n \"description\": \"Commit staged changes\",\n \"cwd\": null\n },\n {\n \"id\": 2,\n \"type\": \"pnpm\",\n \"command\": \"run\",\n \"args\": [\"dev\", \"--port\", \"3000\"],\n \"description\": \"Start dev server\",\n \"cwd\": \"my-repo\"\n }\n ]\n}`;\n}\n\n// ---------------------------------------------------------------------------\n// Main planner function\n// ---------------------------------------------------------------------------\nexport async function generatePlan(\n userPrompt: string,\n provider: AIProvider,\n): Promise<Plan> {\n const raw = await provider.generate(userPrompt, buildSystemPrompt());\n\n // Strip markdown fences if any provider wraps output\n const cleaned = raw.replace(/```json|```/g, \"\").trim();\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(cleaned);\n } catch {\n throw new Error(`AI returned invalid JSON:\\n${cleaned}`);\n }\n\n // Layer 2: Zod shape validation\n const result = PlanSchema.safeParse(parsed);\n if (!result.success) {\n const issues = result.error.issues\n .map((i) => ` - ${i.path.join(\".\")}: ${i.message}`)\n .join(\"\\n\");\n throw new Error(`Plan failed schema validation:\\n${issues}`);\n }\n\n // Layer 3: Catalog whitelist validation\n for (const step of result.data.steps) {\n const check = validateStep(step);\n if (!check.valid) {\n throw new Error(\n `Step ${step.id} failed catalog validation: ${check.reason}`,\n );\n }\n }\n\n return result.data;\n}\n","import { execa } from \"execa\";\nimport type { Plan, Step } from \"./catalog.js\";\n\n// ---------------------------------------------------------------------------\n// Build the actual shell command from a Step\n// ---------------------------------------------------------------------------\nfunction resolveCommand(step: Step): { bin: string; args: string[] } {\n if (step.type === \"shell\") {\n // shell: command is the binary, args are the args\n return { bin: step.command, args: step.args };\n }\n\n // For npm/pnpm/yarn/bun/git: binary is the type, command + args follow\n return { bin: step.type, args: [step.command, ...step.args] };\n}\n\n// ---------------------------------------------------------------------------\n// Run a single step, streaming stdout/stderr live\n// ---------------------------------------------------------------------------\nexport async function runStep(\n step: Step,\n): Promise<{ success: boolean; error?: string }> {\n const { bin, args } = resolveCommand(step);\n\n try {\n await execa(bin, args, {\n cwd: step.cwd ?? process.cwd(),\n stdout: \"inherit\", // stream directly to terminal\n stderr: \"inherit\",\n });\n return { success: true };\n } catch (err: any) {\n const parts = [\n `Command: ${bin} ${args.join(\" \")}`,\n err?.exitCode ? `Exit code: ${err.exitCode}` : null,\n err?.stderr ? `Reason: ${err.stderr.trim()}` : null,\n !err?.stderr ? (err?.message ?? String(err)) : null,\n ]\n .filter(Boolean)\n .join(\"\\n \");\n\n return { success: false, error: parts };\n }\n}\n\n// ---------------------------------------------------------------------------\n// Run the full plan, stopping on first failure\n// ---------------------------------------------------------------------------\nexport async function runPlan(\n plan: Plan,\n onStep: (step: Step, index: number, total: number) => void,\n): Promise<{ success: boolean; failedStep?: Step; error?: string }> {\n const total = plan.steps.length;\n\n for (let i = 0; i < total; i++) {\n const step = plan.steps[i];\n onStep(step, i, total);\n\n const result = await runStep(step);\n\n if (!result.success) {\n return { success: false, failedStep: step, error: result.error };\n }\n }\n\n return { success: true };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAkB;AAKX,IAAM,UAAU;AAAA,EACrB,KAAK,CAAC,WAAW,OAAO,SAAS,QAAQ,WAAW,IAAI;AAAA,EACxD,MAAM,CAA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AY,MAAM,OAAO,OAAO,MAAM;AAAA,IACjE;AAAA,EACF;AAEA,SAAO,EAAE,SAAS,KAAK;AACzB;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -18,7 +18,7 @@ declare const StepSchema: z.ZodObject<{
|
|
|
18
18
|
command: z.ZodString;
|
|
19
19
|
args: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
20
20
|
description: z.ZodString;
|
|
21
|
-
cwd: z.ZodOptional<z.ZodString
|
|
21
|
+
cwd: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
22
22
|
}, z.core.$strip>;
|
|
23
23
|
declare const PlanSchema: z.ZodObject<{
|
|
24
24
|
goal: z.ZodString;
|
|
@@ -35,7 +35,7 @@ declare const PlanSchema: z.ZodObject<{
|
|
|
35
35
|
command: z.ZodString;
|
|
36
36
|
args: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
37
37
|
description: z.ZodString;
|
|
38
|
-
cwd: z.ZodOptional<z.ZodString
|
|
38
|
+
cwd: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
39
39
|
}, z.core.$strip>>;
|
|
40
40
|
}, z.core.$strip>;
|
|
41
41
|
type Step = z.infer<typeof StepSchema>;
|
package/dist/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ declare const StepSchema: z.ZodObject<{
|
|
|
18
18
|
command: z.ZodString;
|
|
19
19
|
args: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
20
20
|
description: z.ZodString;
|
|
21
|
-
cwd: z.ZodOptional<z.ZodString
|
|
21
|
+
cwd: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
22
22
|
}, z.core.$strip>;
|
|
23
23
|
declare const PlanSchema: z.ZodObject<{
|
|
24
24
|
goal: z.ZodString;
|
|
@@ -35,7 +35,7 @@ declare const PlanSchema: z.ZodObject<{
|
|
|
35
35
|
command: z.ZodString;
|
|
36
36
|
args: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
37
37
|
description: z.ZodString;
|
|
38
|
-
cwd: z.ZodOptional<z.ZodString
|
|
38
|
+
cwd: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
39
39
|
}, z.core.$strip>>;
|
|
40
40
|
}, z.core.$strip>;
|
|
41
41
|
type Step = z.infer<typeof StepSchema>;
|
package/dist/index.js
CHANGED
|
@@ -28,7 +28,7 @@ var StepSchema = z.object({
|
|
|
28
28
|
command: z.string(),
|
|
29
29
|
args: z.array(z.string()).default([]),
|
|
30
30
|
description: z.string(),
|
|
31
|
-
cwd: z.string().optional()
|
|
31
|
+
cwd: z.string().nullable().optional()
|
|
32
32
|
// optional working directory override
|
|
33
33
|
});
|
|
34
34
|
var PlanSchema = z.object({
|
|
@@ -71,6 +71,7 @@ Rules:
|
|
|
71
71
|
- Each step must have a clear, short description
|
|
72
72
|
- NEVER generate a "cd" step \u2014 each step runs in a separate process so "cd" has no effect
|
|
73
73
|
- If subsequent steps need to run inside a cloned directory, set the "cwd" field instead
|
|
74
|
+
- For commands that take a message or value argument (like git commit -m), always keep the full message as a single array element, e.g. args: ["-m", "Update changes"] never args: ["-m", "Update", "changes"]
|
|
74
75
|
|
|
75
76
|
Respond ONLY with valid JSON matching this exact shape, no markdown, no explanation:
|
|
76
77
|
{
|
|
@@ -78,10 +79,19 @@ Respond ONLY with valid JSON matching this exact shape, no markdown, no explanat
|
|
|
78
79
|
"steps": [
|
|
79
80
|
{
|
|
80
81
|
"id": 1,
|
|
82
|
+
"type": "git",
|
|
83
|
+
"command": "commit",
|
|
84
|
+
"args": ["-m", "Update changes"],
|
|
85
|
+
"description": "Commit staged changes",
|
|
86
|
+
"cwd": null
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"id": 2,
|
|
81
90
|
"type": "pnpm",
|
|
82
91
|
"command": "run",
|
|
83
|
-
"args": ["dev"],
|
|
84
|
-
"description": "Start dev server"
|
|
92
|
+
"args": ["dev", "--port", "3000"],
|
|
93
|
+
"description": "Start dev server",
|
|
94
|
+
"cwd": "my-repo"
|
|
85
95
|
}
|
|
86
96
|
]
|
|
87
97
|
}`;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/catalog.ts","../src/planner.ts","../src/runner.ts"],"sourcesContent":["import { z } from \"zod\";\n\n// ---------------------------------------------------------------------------\n// Allowed commands per type — the whitelist that prevents hallucination\n// ---------------------------------------------------------------------------\nexport const CATALOG = {\n npm: [\"install\", \"run\", \"build\", \"test\", \"publish\", \"ci\"],\n pnpm: [\"install\", \"run\", \"build\", \"test\", \"publish\", \"add\", \"remove\"],\n yarn: [\"install\", \"run\", \"build\", \"test\", \"publish\", \"add\", \"remove\"],\n bun: [\"install\", \"run\", \"build\", \"test\", \"publish\", \"add\", \"remove\"],\n git: [\n \"init\",\n \"add\",\n \"commit\",\n \"push\",\n \"pull\",\n \"clone\",\n \"status\",\n \"log\",\n \"branch\",\n \"checkout\",\n \"merge\",\n \"stash\",\n ],\n shell: [\"any\"], // escape hatch — always requires extra confirmation\n} as const;\n\nexport type CommandType = keyof typeof CATALOG;\n\n// ---------------------------------------------------------------------------\n// Zod schemas — Layer 2 defense against hallucinated output\n// ---------------------------------------------------------------------------\nexport const StepSchema = z.object({\n id: z.number(),\n type: z.enum([\"npm\", \"pnpm\", \"yarn\", \"bun\", \"git\", \"shell\"]),\n command: z.string(),\n args: z.array(z.string()).default([]),\n description: z.string(),\n cwd: z.string().optional(), // optional working directory override\n});\n\nexport const PlanSchema = z.object({\n goal: z.string(),\n steps: z.array(StepSchema).min(1).max(10),\n});\n\nexport type Step = z.infer<typeof StepSchema>;\nexport type Plan = z.infer<typeof PlanSchema>;\n\n// ---------------------------------------------------------------------------\n// Catalog validation — Layer 3: check command is in whitelist\n// ---------------------------------------------------------------------------\nexport function validateStep(step: Step): { valid: boolean; reason?: string } {\n const allowed = CATALOG[step.type];\n\n // shell type is always allowed but flagged for extra confirmation\n if (step.type === \"shell\") {\n return { valid: true };\n }\n\n if (!allowed.includes(step.command as never)) {\n return {\n valid: false,\n reason: `\"${step.command}\" is not an allowed command for type \"${step.type}\". Allowed: ${allowed.join(\", \")}`,\n };\n }\n\n return { valid: true };\n}\n\n// ---------------------------------------------------------------------------\n// Build the catalog string injected into AI system prompt\n// ---------------------------------------------------------------------------\nexport function buildCatalogPrompt(): string {\n const lines = Object.entries(CATALOG).map(([type, commands]) => {\n const list =\n commands[0] === \"any\"\n ? \"any shell command (use sparingly)\"\n : commands.join(\", \");\n return ` - ${type}: [${list}]`;\n });\n\n return `Allowed command types and commands:\\n${lines.join(\"\\n\")}`;\n}\n","import { buildCatalogPrompt, PlanSchema, validateStep } from \"./catalog.js\";\nimport type { AIProvider } from \"./providers/types.js\";\nimport type { Plan } from \"./catalog.js\";\n\n// ---------------------------------------------------------------------------\n// System prompt — constrains AI to only produce catalog-valid JSON\n// ---------------------------------------------------------------------------\nfunction buildSystemPrompt(): string {\n return `You are a CLI task planner. Given a user's goal, generate a JSON execution plan.\n\n${buildCatalogPrompt()}\n\nRules:\n- ONLY use command types and commands listed above\n- Prefer pnpm over npm unless the user specifies otherwise\n- Use \"shell\" type only when no other type fits\n- Keep steps minimal — don't add unnecessary steps\n- Each step must have a clear, short description\n- NEVER generate a \"cd\" step — each step runs in a separate process so \"cd\" has no effect\n- If subsequent steps need to run inside a cloned directory, set the \"cwd\" field instead\n\nRespond ONLY with valid JSON matching this exact shape, no markdown, no explanation:\n{\n \"goal\": \"string describing the overall goal\",\n \"steps\": [\n {\n \"id\": 1,\n \"type\": \"pnpm\",\n \"command\": \"run\",\n \"args\": [\"dev\"],\n \"description\": \"Start dev server\"\n }\n ]\n}`;\n}\n\n// ---------------------------------------------------------------------------\n// Main planner function\n// ---------------------------------------------------------------------------\nexport async function generatePlan(\n userPrompt: string,\n provider: AIProvider,\n): Promise<Plan> {\n const raw = await provider.generate(userPrompt, buildSystemPrompt());\n\n // Strip markdown fences if any provider wraps output\n const cleaned = raw.replace(/```json|```/g, \"\").trim();\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(cleaned);\n } catch {\n throw new Error(`AI returned invalid JSON:\\n${cleaned}`);\n }\n\n // Layer 2: Zod shape validation\n const result = PlanSchema.safeParse(parsed);\n if (!result.success) {\n const issues = result.error.issues\n .map((i) => ` - ${i.path.join(\".\")}: ${i.message}`)\n .join(\"\\n\");\n throw new Error(`Plan failed schema validation:\\n${issues}`);\n }\n\n // Layer 3: Catalog whitelist validation\n for (const step of result.data.steps) {\n const check = validateStep(step);\n if (!check.valid) {\n throw new Error(\n `Step ${step.id} failed catalog validation: ${check.reason}`,\n );\n }\n }\n\n return result.data;\n}\n","import { execa } from \"execa\";\nimport type { Plan, Step } from \"./catalog.js\";\n\n// ---------------------------------------------------------------------------\n// Build the actual shell command from a Step\n// ---------------------------------------------------------------------------\nfunction resolveCommand(step: Step): { bin: string; args: string[] } {\n if (step.type === \"shell\") {\n // shell: command is the binary, args are the args\n return { bin: step.command, args: step.args };\n }\n\n // For npm/pnpm/yarn/bun/git: binary is the type, command + args follow\n return { bin: step.type, args: [step.command, ...step.args] };\n}\n\n// ---------------------------------------------------------------------------\n// Run a single step, streaming stdout/stderr live\n// ---------------------------------------------------------------------------\nexport async function runStep(\n step: Step,\n): Promise<{ success: boolean; error?: string }> {\n const { bin, args } = resolveCommand(step);\n\n try {\n await execa(bin, args, {\n cwd: step.cwd ?? process.cwd(),\n stdout: \"inherit\", // stream directly to terminal\n stderr: \"inherit\",\n });\n return { success: true };\n } catch (err: any) {\n const parts = [\n `Command: ${bin} ${args.join(\" \")}`,\n err?.exitCode ? `Exit code: ${err.exitCode}` : null,\n err?.stderr ? `Reason: ${err.stderr.trim()}` : null,\n !err?.stderr ? (err?.message ?? String(err)) : null,\n ]\n .filter(Boolean)\n .join(\"\\n \");\n\n return { success: false, error: parts };\n }\n}\n\n// ---------------------------------------------------------------------------\n// Run the full plan, stopping on first failure\n// ---------------------------------------------------------------------------\nexport async function runPlan(\n plan: Plan,\n onStep: (step: Step, index: number, total: number) => void,\n): Promise<{ success: boolean; failedStep?: Step; error?: string }> {\n const total = plan.steps.length;\n\n for (let i = 0; i < total; i++) {\n const step = plan.steps[i];\n onStep(step, i, total);\n\n const result = await runStep(step);\n\n if (!result.success) {\n return { success: false, failedStep: step, error: result.error };\n }\n }\n\n return { success: true };\n}\n"],"mappings":";AAAA,SAAS,SAAS;AAKX,IAAM,UAAU;AAAA,EACrB,KAAK,CAAC,WAAW,OAAO,SAAS,QAAQ,WAAW,IAAI;AAAA,EACxD,MAAM,CAAC,WAAW,OAAO,SAAS,QAAQ,WAAW,OAAO,QAAQ;AAAA,EACpE,MAAM,CAAC,WAAW,OAAO,SAAS,QAAQ,WAAW,OAAO,QAAQ;AAAA,EACpE,KAAK,CAAC,WAAW,OAAO,SAAS,QAAQ,WAAW,OAAO,QAAQ;AAAA,EACnE,KAAK;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,OAAO,CAAC,KAAK;AAAA;AACf;AAOO,IAAM,aAAa,EAAE,OAAO;AAAA,EACjC,IAAI,EAAE,OAAO;AAAA,EACb,MAAM,EAAE,KAAK,CAAC,OAAO,QAAQ,QAAQ,OAAO,OAAO,OAAO,CAAC;AAAA,EAC3D,SAAS,EAAE,OAAO;AAAA,EAClB,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC;AAAA,EACpC,aAAa,EAAE,OAAO;AAAA,EACtB,KAAK,EAAE,OAAO,EAAE,SAAS;AAAA;AAC3B,CAAC;AAEM,IAAM,aAAa,EAAE,OAAO;AAAA,EACjC,MAAM,EAAE,OAAO;AAAA,EACf,OAAO,EAAE,MAAM,UAAU,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE;AAC1C,CAAC;AAQM,SAAS,aAAa,MAAiD;AAC5E,QAAM,UAAU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pB,MACA,QACkE;AAClE,QAAM,QAAQ,KAAK,MAAM;AAEzB,WAAS,IAAI,GAAG,IAAI,OAAO,KAAK;AAC9B,UAAM,OAAO,KAAK,MAAM,CAAC;AACzB,WAAO,MAAM,GAAG,KAAK;AAErB,UAAM,SAAS,MAAM,QAAQ,IAAI;AAEjC,QAAI,CAAC,OAAO,SAAS;AACnB,aAAO,EAAE,SAAS,OAAO,YAAY,MAAM,OAAO,OAAO,MAAM;AAAA,IACjE;AAAA,EACF;AAEA,SAAO,EAAE,SAAS,KAAK;AACzB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/catalog.ts","../src/planner.ts","../src/runner.ts"],"sourcesContent":["import { z } from \"zod\";\n\n// ---------------------------------------------------------------------------\n// Allowed commands per type — the whitelist that prevents hallucination\n// ---------------------------------------------------------------------------\nexport const CATALOG = {\n npm: [\"install\", \"run\", \"build\", \"test\", \"publish\", \"ci\"],\n pnpm: [\"install\", \"run\", \"build\", \"test\", \"publish\", \"add\", \"remove\"],\n yarn: [\"install\", \"run\", \"build\", \"test\", \"publish\", \"add\", \"remove\"],\n bun: [\"install\", \"run\", \"build\", \"test\", \"publish\", \"add\", \"remove\"],\n git: [\n \"init\",\n \"add\",\n \"commit\",\n \"push\",\n \"pull\",\n \"clone\",\n \"status\",\n \"log\",\n \"branch\",\n \"checkout\",\n \"merge\",\n \"stash\",\n ],\n shell: [\"any\"], // escape hatch — always requires extra confirmation\n} as const;\n\nexport type CommandType = keyof typeof CATALOG;\n\n// ---------------------------------------------------------------------------\n// Zod schemas — Layer 2 defense against hallucinated output\n// ---------------------------------------------------------------------------\nexport const StepSchema = z.object({\n id: z.number(),\n type: z.enum([\"npm\", \"pnpm\", \"yarn\", \"bun\", \"git\", \"shell\"]),\n command: z.string(),\n args: z.array(z.string()).default([]),\n description: z.string(),\n cwd: z.string().nullable().optional(), // optional working directory override\n});\n\nexport const PlanSchema = z.object({\n goal: z.string(),\n steps: z.array(StepSchema).min(1).max(10),\n});\n\nexport type Step = z.infer<typeof StepSchema>;\nexport type Plan = z.infer<typeof PlanSchema>;\n\n// ---------------------------------------------------------------------------\n// Catalog validation — Layer 3: check command is in whitelist\n// ---------------------------------------------------------------------------\nexport function validateStep(step: Step): { valid: boolean; reason?: string } {\n const allowed = CATALOG[step.type];\n\n // shell type is always allowed but flagged for extra confirmation\n if (step.type === \"shell\") {\n return { valid: true };\n }\n\n if (!allowed.includes(step.command as never)) {\n return {\n valid: false,\n reason: `\"${step.command}\" is not an allowed command for type \"${step.type}\". Allowed: ${allowed.join(\", \")}`,\n };\n }\n\n return { valid: true };\n}\n\n// ---------------------------------------------------------------------------\n// Build the catalog string injected into AI system prompt\n// ---------------------------------------------------------------------------\nexport function buildCatalogPrompt(): string {\n const lines = Object.entries(CATALOG).map(([type, commands]) => {\n const list =\n commands[0] === \"any\"\n ? \"any shell command (use sparingly)\"\n : commands.join(\", \");\n return ` - ${type}: [${list}]`;\n });\n\n return `Allowed command types and commands:\\n${lines.join(\"\\n\")}`;\n}\n","import { buildCatalogPrompt, PlanSchema, validateStep } from \"./catalog.js\";\nimport type { AIProvider } from \"./providers/types.js\";\nimport type { Plan } from \"./catalog.js\";\n\n// ---------------------------------------------------------------------------\n// System prompt — constrains AI to only produce catalog-valid JSON\n// ---------------------------------------------------------------------------\nfunction buildSystemPrompt(): string {\n return `You are a CLI task planner. Given a user's goal, generate a JSON execution plan.\n\n${buildCatalogPrompt()}\n\nRules:\n- ONLY use command types and commands listed above\n- Prefer pnpm over npm unless the user specifies otherwise\n- Use \"shell\" type only when no other type fits\n- Keep steps minimal — don't add unnecessary steps\n- Each step must have a clear, short description\n- NEVER generate a \"cd\" step — each step runs in a separate process so \"cd\" has no effect\n- If subsequent steps need to run inside a cloned directory, set the \"cwd\" field instead\n- For commands that take a message or value argument (like git commit -m), always keep the full message as a single array element, e.g. args: [\"-m\", \"Update changes\"] never args: [\"-m\", \"Update\", \"changes\"]\n\nRespond ONLY with valid JSON matching this exact shape, no markdown, no explanation:\n{\n \"goal\": \"string describing the overall goal\",\n \"steps\": [\n {\n \"id\": 1,\n \"type\": \"git\",\n \"command\": \"commit\",\n \"args\": [\"-m\", \"Update changes\"],\n \"description\": \"Commit staged changes\",\n \"cwd\": null\n },\n {\n \"id\": 2,\n \"type\": \"pnpm\",\n \"command\": \"run\",\n \"args\": [\"dev\", \"--port\", \"3000\"],\n \"description\": \"Start dev server\",\n \"cwd\": \"my-repo\"\n }\n ]\n}`;\n}\n\n// ---------------------------------------------------------------------------\n// Main planner function\n// ---------------------------------------------------------------------------\nexport async function generatePlan(\n userPrompt: string,\n provider: AIProvider,\n): Promise<Plan> {\n const raw = await provider.generate(userPrompt, buildSystemPrompt());\n\n // Strip markdown fences if any provider wraps output\n const cleaned = raw.replace(/```json|```/g, \"\").trim();\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(cleaned);\n } catch {\n throw new Error(`AI returned invalid JSON:\\n${cleaned}`);\n }\n\n // Layer 2: Zod shape validation\n const result = PlanSchema.safeParse(parsed);\n if (!result.success) {\n const issues = result.error.issues\n .map((i) => ` - ${i.path.join(\".\")}: ${i.message}`)\n .join(\"\\n\");\n throw new Error(`Plan failed schema validation:\\n${issues}`);\n }\n\n // Layer 3: Catalog whitelist validation\n for (const step of result.data.steps) {\n const check = validateStep(step);\n if (!check.valid) {\n throw new Error(\n `Step ${step.id} failed catalog validation: ${check.reason}`,\n );\n }\n }\n\n return result.data;\n}\n","import { execa } from \"execa\";\nimport type { Plan, Step } from \"./catalog.js\";\n\n// ---------------------------------------------------------------------------\n// Build the actual shell command from a Step\n// ---------------------------------------------------------------------------\nfunction resolveCommand(step: Step): { bin: string; args: string[] } {\n if (step.type === \"shell\") {\n // shell: command is the binary, args are the args\n return { bin: step.command, args: step.args };\n }\n\n // For npm/pnpm/yarn/bun/git: binary is the type, command + args follow\n return { bin: step.type, args: [step.command, ...step.args] };\n}\n\n// ---------------------------------------------------------------------------\n// Run a single step, streaming stdout/stderr live\n// ---------------------------------------------------------------------------\nexport async function runStep(\n step: Step,\n): Promise<{ success: boolean; error?: string }> {\n const { bin, args } = resolveCommand(step);\n\n try {\n await execa(bin, args, {\n cwd: step.cwd ?? process.cwd(),\n stdout: \"inherit\", // stream directly to terminal\n stderr: \"inherit\",\n });\n return { success: true };\n } catch (err: any) {\n const parts = [\n `Command: ${bin} ${args.join(\" \")}`,\n err?.exitCode ? `Exit code: ${err.exitCode}` : null,\n err?.stderr ? `Reason: ${err.stderr.trim()}` : null,\n !err?.stderr ? (err?.message ?? String(err)) : null,\n ]\n .filter(Boolean)\n .join(\"\\n \");\n\n return { success: false, error: parts };\n }\n}\n\n// ---------------------------------------------------------------------------\n// Run the full plan, stopping on first failure\n// ---------------------------------------------------------------------------\nexport async function runPlan(\n plan: Plan,\n onStep: (step: Step, index: number, total: number) => void,\n): Promise<{ success: boolean; failedStep?: Step; error?: string }> {\n const total = plan.steps.length;\n\n for (let i = 0; i < total; i++) {\n const step = plan.steps[i];\n onStep(step, i, total);\n\n const result = await runStep(step);\n\n if (!result.success) {\n return { success: false, failedStep: step, error: result.error };\n }\n }\n\n return { success: true };\n}\n"],"mappings":";AAAA,SAAS,SAAS;AAKX,IAAM,UAAU;AAAA,EACrB,KAAK,CAAC,WAAW,OAAO,SAAS,QAAQ,WAAW,IAAI;AAAA,EACxD,MAAM,CAAC,WAAW,OAAO,SAAS,QAAQ,WAAW,OAAO,QAAQ;AAAA,EACpE,MAAM,CAAC,WAAW,OAAO,SAAS,QAAQ,WAAW,OAAO,QAAQ;AAAA,EACpE,KAAK,CAAC,WAAW,OAAO,SAAS,QAAQ,WAAW,OAAO,QAAQ;AAAA,EACnE,KAAK;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,OAAO,CAAC,KAAK;AAAA;AACf;AAOO,IAAM,aAAa,EAAE,OAAO;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