Skip to content

Commit 916713e

Browse files
committed
fest: add --debug flag
1 parent 4180504 commit 916713e

4 files changed

Lines changed: 77 additions & 7 deletions

File tree

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,40 @@ json-cli "run tests, check git diff, then git add and commit with message 'fix:
9999
json-cli "install deps, run typecheck, run tests, build, git add, commit with message 'ci: local pipeline passed', push"
100100
```
101101

102+
### Options
103+
104+
```bash
105+
json-cli
106+
# or
107+
json-cli --help
108+
```
109+
```
110+
┌ json-cli — AI-powered CLI task runner
111+
112+
│ Usage
113+
│ json-cli "<your goal>" [options]
114+
115+
│ Options
116+
│ --provider <name> AI provider: claude | openai | ollama (default: claude)
117+
│ --yes Skip confirmation prompt
118+
│ --dry-run Show plan without executing
119+
│ --debug Show system prompt and raw AI response
120+
│ --help Show this help message
121+
122+
│ Examples
123+
│ json-cli "please run tests"
124+
│ json-cli "run tests and build"
125+
│ json-cli "run tests and build" --yes
126+
│ json-cli "git add, commit with message 'fix: bug', push"
127+
│ json-cli "clone https://github.com/user/repo, install deps, run dev"
128+
│ json-cli "run tests and publish" --provider openai
129+
│ json-cli "run tests" --dry-run
130+
│ json-cli "run tests" --debug
131+
│ json-cli "run tests" --debug --dry-run
132+
133+
└ Docs: https://github.com/ekaone/json-cli
134+
```
135+
102136
---
103137

104138
## How it works

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ekaone/json-cli",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"description": "AI-powered CLI task runner with JSON command plans",
55
"keywords": ["ai", "agent", "cli", "task-runner", "llm"],
66
"author": {

src/cli.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function showHelp(): void {
1515
--provider <name> AI provider: claude | openai | ollama (default: claude)
1616
--yes Skip confirmation prompt
1717
--dry-run Show plan without executing
18+
--debug Show system prompt and raw AI response
1819
--help Show this help message`,
1920
);
2021
p.log.message(
@@ -25,7 +26,9 @@ function showHelp(): void {
2526
json-cli "git add, commit with message 'fix: bug', push"
2627
json-cli "clone https://github.com/user/repo, install deps, run dev"
2728
json-cli "run tests and publish" --provider openai
28-
json-cli "run tests" --dry-run`,
29+
json-cli "run tests" --dry-run
30+
json-cli "run tests" --debug
31+
json-cli "run tests" --debug --dry-run`,
2932
);
3033
p.outro("Docs: https://github.com/ekaone/json-cli");
3134
}
@@ -39,6 +42,7 @@ function parseArgs(): {
3942
provider: ProviderName;
4043
yes: boolean;
4144
dryRun: boolean;
45+
debug: boolean;
4246
} {
4347
const args = process.argv.slice(2);
4448

@@ -54,6 +58,7 @@ function parseArgs(): {
5458

5559
const yes = args.includes("--yes");
5660
const dryRun = args.includes("--dry-run");
61+
const debug = args.includes("--debug");
5762

5863
const prompt = args
5964
.filter(
@@ -67,7 +72,7 @@ function parseArgs(): {
6772
process.exit(0);
6873
}
6974

70-
return { prompt, provider, yes, dryRun };
75+
return { prompt, provider, yes, dryRun, debug };
7176
}
7277

7378
// ---------------------------------------------------------------------------
@@ -86,10 +91,10 @@ function formatStep(step: Step): string {
8691
// Main
8792
// ---------------------------------------------------------------------------
8893
async function main() {
89-
const { prompt, provider: providerName, yes, dryRun } = parseArgs();
94+
const { prompt, provider: providerName, yes, dryRun, debug } = parseArgs();
9095

9196
p.intro(
92-
`json-cli — powered by ${providerName}${dryRun ? " (dry run)" : ""}`,
97+
`json-cli — powered by ${providerName}${dryRun ? " (dry run)" : ""}${debug ? " (debug)" : ""}`,
9398
);
9499

95100
// Step 1: Generate plan
@@ -99,7 +104,7 @@ async function main() {
99104
let plan;
100105
try {
101106
const provider = resolveProvider(providerName);
102-
plan = await generatePlan(prompt, provider);
107+
plan = await generatePlan(prompt, provider, debug);
103108
spinner.stop("Plan ready");
104109
} catch (err) {
105110
spinner.stop("Failed to generate plan");
@@ -128,6 +133,7 @@ async function main() {
128133
if (dryRun) {
129134
p.outro("Dry run complete — no commands were executed.");
130135
setTimeout(() => process.exit(0), 50);
136+
return;
131137
}
132138

133139
// Step 5: Confirm — skip if --yes
@@ -136,6 +142,7 @@ async function main() {
136142
if (p.isCancel(confirmed) || !confirmed) {
137143
p.cancel("Aborted.");
138144
setTimeout(() => process.exit(0), 50);
145+
return;
139146
}
140147
} else {
141148
p.log.info("Skipping confirmation (--yes)");
@@ -155,6 +162,7 @@ async function main() {
155162
`❌ Failed at step ${result.failedStep?.id}: ${result.failedStep?.description}\n${result.error ?? ""}`,
156163
);
157164
setTimeout(() => process.exit(1), 50);
165+
return;
158166
}
159167
}
160168

src/planner.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,36 @@ Respond ONLY with valid JSON matching this exact shape, no markdown, no explanat
5050
export async function generatePlan(
5151
userPrompt: string,
5252
provider: AIProvider,
53+
debug: boolean = false,
5354
): Promise<Plan> {
54-
const raw = await provider.generate(userPrompt, buildSystemPrompt());
55+
const systemPrompt = buildSystemPrompt();
56+
57+
if (debug) {
58+
console.log("┌");
59+
console.log("│");
60+
console.log("● System prompt:");
61+
console.log(
62+
"│ " + systemPrompt.split("\n").slice(0, 8).join("\n│ ") + "...",
63+
);
64+
console.log("│");
65+
}
66+
67+
const raw = await provider.generate(userPrompt, systemPrompt);
68+
69+
if (debug) {
70+
console.log("● Raw AI response:");
71+
try {
72+
const parsed = JSON.parse(raw);
73+
console.log(
74+
"│ " + JSON.stringify(parsed, null, 2).split("\n").join("\n│ "),
75+
);
76+
} catch {
77+
console.log("│ " + raw);
78+
}
79+
console.log("│");
80+
console.log("◇ Plan ready");
81+
console.log("");
82+
}
5583

5684
// Strip markdown fences if any provider wraps output
5785
const cleaned = raw.replace(/```json|```/g, "").trim();

0 commit comments

Comments
 (0)