Skip to content

Commit d903d99

Browse files
committed
fix: Auto-map ls/dir based on platform
1 parent eba8c5c commit d903d99

4 files changed

Lines changed: 51 additions & 4 deletions

File tree

README.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ json-cli --help
117117
118118
Options
119119
--provider <name> AI provider: claude | openai | ollama (default: claude)
120+
--catalogs <list> Force specific catalogs: package,git,docker,fs,shell (comma-separated)
120121
--yes Skip confirmation prompt
121122
--dry-run Show plan without executing
122123
--debug Show system prompt and raw AI response
@@ -136,6 +137,8 @@ json-cli --help
136137
json-cli "run tests" --dry-run
137138
json-cli "run tests" --debug
138139
json-cli "run tests" --debug --dry-run
140+
json-cli "deploy to prod" --catalogs docker
141+
json-cli "list files in E:" --catalogs fs
139142
json-cli --resume
140143
json-cli --history
141144
@@ -144,6 +147,40 @@ json-cli --help
144147

145148
---
146149

150+
## Catalogs (Command Whitelists)
151+
152+
json-cli automatically detects which catalogs to use based on your project structure:
153+
154+
| Catalog | Auto-detected when | Commands |
155+
|---------|-------------------|----------|
156+
| `package` | `package.json` exists | npm, pnpm, yarn, bun |
157+
| `git` | `.git/` folder exists | git init, add, commit, push, pull... |
158+
| `docker` | `Dockerfile` or `docker-compose.yml` exists | docker build, run, compose... |
159+
| `fs` | Always included | mkdir, rm, cp, mv, touch, cat, ls, dir |
160+
| `shell` | Always included | Any command (escape hatch) |
161+
162+
### Force specific catalogs
163+
164+
Use `--catalogs` to override auto-detection:
165+
166+
```bash
167+
# Only use docker commands, even in a Node.js project
168+
json-cli "deploy to prod" --catalogs docker
169+
170+
# Only filesystem commands
171+
json-cli "list files in E:" --catalogs fs
172+
173+
# Multiple catalogs (comma-separated)
174+
json-cli "build and deploy" --catalogs package,docker
175+
```
176+
177+
This is useful when you want to:
178+
- Exclude certain tools from the plan
179+
- Ensure only specific command types are used
180+
- Override auto-detection in CI/CD pipelines
181+
182+
---
183+
147184
## How it works
148185

149186
```
@@ -177,7 +214,8 @@ Runner ← executes step by step, streams output live
177214
| `yarn` | install, run, build, test, publish, add, remove, why, upgrade |
178215
| `bun` | install, run, build, test, publish, add, remove, x, update |
179216
| `git` | init, add, commit, push, pull, clone, status, log, branch, checkout, merge, diff, stash |
180-
| `fs` | mkdir, touch, cp, mv, ls `(coming soon)` |
217+
| `docker`| build, run, compose, push, pull, exec, logs, ps, stop, start, rm, rmi |
218+
| `fs` | mkdir, rm, cp, mv, touch, cat, ls, dir |
181219
| `shell` | any *(escape hatch — always requires extra confirmation)* |
182220

183221
> **Note:** Flags and arguments are unrestricted, `--port 5000`, `-m "message"`, `--force` etc. are all passed freely. Only the command itself is whitelisted.

src/catalogs/fs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { CatalogModule } from "./base.js";
22

33
export const fsCatalog: CatalogModule = {
44
name: "fs",
5-
commands: ["mkdir", "rm", "cp", "mv", "touch", "cat", "ls"],
5+
commands: ["mkdir", "rm", "cp", "mv", "touch", "cat", "ls", "dir"],
66
detectors: [],
77
typeEnum: ["fs"],
88
buildPrompt() {

src/cli.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function showHelp(): void {
2323
p.log.message(
2424
`Options
2525
--provider <name> AI provider: claude | openai | ollama (default: claude)
26-
--catalogs <list> Force specific catalogs: package,git,docker,fs (comma-separated)
26+
--catalogs <list> Force specific catalogs: package,git,docker,fs,shell (comma-separated)
2727
--yes Skip confirmation prompt
2828
--dry-run Show plan without executing
2929
--debug Show system prompt and raw AI response
@@ -44,6 +44,8 @@ function showHelp(): void {
4444
json-cli "run tests" --dry-run
4545
json-cli "run tests" --debug
4646
json-cli "run tests" --debug --dry-run
47+
json-cli "deploy to prod" --catalogs docker
48+
json-cli "list files in E:" --catalogs fs
4749
json-cli --resume
4850
json-cli --history`,
4951
);

src/runner.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { execa } from "execa";
2+
import { platform } from "os";
23
import type { Plan, Step } from "./catalogs/index.js";
34

45
// ---------------------------------------------------------------------------
@@ -9,7 +10,13 @@ function resolveCommand(step: Step): { bin: string; args: string[] } {
910
case "shell":
1011
return { bin: step.command, args: step.args };
1112
case "fs":
12-
// Filesystem commands need special handling
13+
// Auto-map ls/dir based on platform for better cross-platform UX
14+
if (step.command === "ls" && platform() === "win32") {
15+
return { bin: "dir", args: step.args };
16+
}
17+
if (step.command === "dir" && platform() !== "win32") {
18+
return { bin: "ls", args: step.args };
19+
}
1320
return { bin: step.command, args: step.args };
1421
case "docker":
1522
return { bin: "docker", args: [step.command, ...step.args] };

0 commit comments

Comments
 (0)