Skip to content

Commit b184d26

Browse files
committed
fix: add Rules to fixed "cd" command
1 parent 7dc0d64 commit b184d26

3 files changed

Lines changed: 118 additions & 37 deletions

File tree

README.md

Lines changed: 105 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,92 +16,164 @@ pnpm install -g @ekaone/json-cli
1616
yarn global add @ekaone/json-cli
1717
```
1818

19-
## Usage
19+
## Setup
2020

21-
```
21+
```bash
2222
export ANTHROPIC_API_KEY=your_key_here
2323
```
2424

25+
> Windows PowerShell: `$env:ANTHROPIC_API_KEY="your_key_here"`
26+
27+
---
28+
29+
## Usage
30+
31+
### Single intent
2532

2633
```bash
27-
// Single intent
2834
json-cli "please run tests"
35+
json-cli "please build"
36+
json-cli "check git status"
37+
```
38+
39+
### Multi-intent — the fun part 🔥
40+
41+
Chain multiple commands in plain English using **"then"**, **"and"**, **"after that"**:
42+
43+
```bash
44+
json-cli "run tests and then build"
2945
```
3046

3147
```bash
32-
// Multiple intents
33-
json-cli "please run tests and build"
48+
json-cli "run typecheck, test, and then check git status"
49+
```
3450

35-
OR
51+
```bash
52+
json-cli "please run dev with port 5000"
53+
```
3654

3755
```bash
38-
json-cli "heyy ... run typecheck, test and then check git status"
56+
json-cli "install deps, run tests, then build"
3957
```
4058

41-
### For local development
59+
### Full release flow in one command 🚀
4260

4361
```bash
44-
pnpm install
62+
json-cli "run tests, build, git add all, commit with message 'release v0.1.0', push, then publish"
4563
```
4664

47-
### Usage
65+
```
66+
📋 Plan (6 steps):
67+
1. pnpm test → Run test suite
68+
2. pnpm build → Build package
69+
3. git add . → Stage all changes
70+
4. git commit -m "release v0.1.0" → Commit release
71+
5. git push → Push to remote
72+
6. pnpm publish → Publish to npm
73+
74+
Proceed? › y
75+
```
76+
77+
### More crazy examples
4878

4979
```bash
50-
# Using Claude (default)
51-
pnpm dev "install deps and run tests"
80+
# Full dev startup
81+
json-cli "install deps and run dev on port 3000"
82+
83+
# Audit and fix
84+
json-cli "run npm audit, then update all deps"
5285

53-
# Using OpenAI
54-
pnpm dev "run build and publish" --provider openai
86+
# Branch and commit workflow
87+
json-cli "check git status, add all files, commit with message 'feat: add multi-intent support', then push"
5588

56-
# Using Ollama (local)
57-
pnpm dev "start dev server" --provider ollama
89+
# Test everything before shipping
90+
json-cli "run typecheck, run tests, build, then publish"
91+
92+
# Clone and install
93+
json-cli "clone https://github.com/ekaone/json-cli and then install deps"
94+
95+
# Check before commit
96+
json-cli "run tests, check git diff, then git add and commit with message 'fix: catalog types'"
97+
98+
# Full CI-like flow locally
99+
json-cli "install deps, run typecheck, run tests, build, git add, commit with message 'ci: local pipeline passed', push"
58100
```
59101

102+
---
103+
60104
## How it works
61105

62106
```
63-
User Prompt
107+
User Prompt (plain English)
64108
65109
66110
AI Provider ← Claude / OpenAI / Ollama
67-
111+
extracts ALL intents, sequences them
68112
69-
JSON Plan ← validated by Zod schema
113+
JSON Plan ← validated by Zod schema (max 10 steps)
70114
71115
72116
Catalog Check ← whitelist prevents hallucinated commands
73117
74118
75-
Confirm (y/n) ← user reviews before execution
119+
Confirm (y/n) ← review the full plan before execution
76120
77121
78-
Runner ← executes steps, streams output live
122+
Runner ← executes step by step, streams output live
123+
stops immediately on first failure
79124
```
80125

126+
---
127+
81128
## Allowed commands
82129

83-
| Type | Commands |
84-
|-------|----------|
85-
| pnpm | install, run, build, test, publish, add, remove |
86-
| npm | install, run, build, test, publish, ci |
87-
| yarn | install, run, build, test, publish, add, remove |
88-
| bun | install, run, build, test, publish, add, remove |
89-
| git | init, add, commit, push, pull, clone, status, log |
90-
| shell | any *(requires extra caution)* |
130+
| Type | Commands |
131+
|---------|----------|
132+
| `pnpm` | install, run, build, test, publish, add, remove, update, dlx, why |
133+
| `npm` | install, run, build, test, publish, ci, init, outdated, audit |
134+
| `yarn` | install, run, build, test, publish, add, remove, why, upgrade |
135+
| `bun` | install, run, build, test, publish, add, remove, x, update |
136+
| `git` | init, add, commit, push, pull, clone, status, log, branch, checkout, merge, diff, stash |
137+
| `fs` | mkdir, touch, cp, mv, ls `(coming soon)` |
138+
| `shell` | any *(escape hatch — always requires extra confirmation)* |
139+
140+
> **Note:** Flags and arguments are unrestricted — `--port 5000`, `-m "message"`, `--force` etc. are all passed freely. Only the command itself is whitelisted.
141+
142+
---
143+
144+
## AI Providers
145+
146+
```bash
147+
# Claude (default)
148+
json-cli "run tests and build"
149+
150+
# OpenAI
151+
json-cli "run tests and build" --provider openai
152+
153+
# Ollama (local, no API key needed)
154+
json-cli "run tests and build" --provider ollama
155+
```
91156

92157
## Environment variables
93158

94159
```bash
95-
ANTHROPIC_API_KEY=sk-ant-...
96-
OPENAI_API_KEY=sk-...
160+
ANTHROPIC_API_KEY=sk-ant-... # for Claude
161+
OPENAI_API_KEY=sk-... # for OpenAI
97162
```
98163

99-
## Run tests
164+
---
165+
166+
## Local development
100167

101168
```bash
169+
pnpm install
170+
pnpm dev "please run tests"
102171
pnpm test
172+
pnpm build
103173
```
104174

175+
---
176+
105177
## License
106178

107179
MIT © [Eka Prasetia](https://prasetia.me/)
@@ -112,4 +184,4 @@ MIT © [Eka Prasetia](https://prasetia.me/)
112184
- [GitHub Repository](https://github.com/ekaone/json-cli)
113185
- [Issue Tracker](https://github.com/ekaone/json-cli/issues)
114186

115-
⭐ If this library helps you, please consider giving it a star on GitHub!
187+
⭐ If this library helps you, please consider giving it a star on GitHub!

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.1",
3+
"version": "0.1.2",
44
"description": "AI-powered CLI task runner with JSON command plans",
55
"keywords": ["ai", "agent", "cli", "task-runner", "llm"],
66
"author": {

src/planner.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Rules:
1616
- Use "shell" type only when no other type fits
1717
- Keep steps minimal — don't add unnecessary steps
1818
- Each step must have a clear, short description
19+
- NEVER generate a "cd" step — each step runs in a separate process so "cd" has no effect
20+
- If subsequent steps need to run inside a cloned directory, set the "cwd" field instead
1921
2022
Respond ONLY with valid JSON matching this exact shape, no markdown, no explanation:
2123
{
@@ -35,7 +37,10 @@ Respond ONLY with valid JSON matching this exact shape, no markdown, no explanat
3537
// ---------------------------------------------------------------------------
3638
// Main planner function
3739
// ---------------------------------------------------------------------------
38-
export async function generatePlan(userPrompt: string, provider: AIProvider): Promise<Plan> {
40+
export async function generatePlan(
41+
userPrompt: string,
42+
provider: AIProvider,
43+
): Promise<Plan> {
3944
const raw = await provider.generate(userPrompt, buildSystemPrompt());
4045

4146
// Strip markdown fences if any provider wraps output
@@ -51,15 +56,19 @@ export async function generatePlan(userPrompt: string, provider: AIProvider): Pr
5156
// Layer 2: Zod shape validation
5257
const result = PlanSchema.safeParse(parsed);
5358
if (!result.success) {
54-
const issues = result.error.issues.map((i) => ` - ${i.path.join(".")}: ${i.message}`).join("\n");
59+
const issues = result.error.issues
60+
.map((i) => ` - ${i.path.join(".")}: ${i.message}`)
61+
.join("\n");
5562
throw new Error(`Plan failed schema validation:\n${issues}`);
5663
}
5764

5865
// Layer 3: Catalog whitelist validation
5966
for (const step of result.data.steps) {
6067
const check = validateStep(step);
6168
if (!check.valid) {
62-
throw new Error(`Step ${step.id} failed catalog validation: ${check.reason}`);
69+
throw new Error(
70+
`Step ${step.id} failed catalog validation: ${check.reason}`,
71+
);
6372
}
6473
}
6574

0 commit comments

Comments
 (0)