|
| 1 | +--- |
| 2 | +id: microcli-implementation |
| 3 | +created: 2026-03-27 |
| 4 | +modified: 2026-03-27 |
| 5 | +type: plan |
| 6 | +status: active |
| 7 | +expires: 2026-04-03 |
| 8 | +--- |
| 9 | + |
| 10 | +# Plan: Build microcli |
| 11 | + |
| 12 | +## Context |
| 13 | + |
| 14 | +Create a single-file Python CLI framework (~400 lines) for AI-friendly micro CLI apps. Goals: |
| 15 | +- Single `.py` file, standard library + pyyaml |
| 16 | +- Annotated type hints for docs/args |
| 17 | +- High-level `sh()` for shell commands |
| 18 | +- `--dry-run` mode |
| 19 | +- `command.explain()` for agent workflows |
| 20 | + |
| 21 | +## Phases |
| 22 | + |
| 23 | +### Phase 1: Core Framework |
| 24 | +**Goal:** Build the command registration and argument parsing system |
| 25 | + |
| 26 | +**Deliverable:** `microcli.py` with `@m.command` decorator |
| 27 | + |
| 28 | +**Done when:** |
| 29 | +- [ ] `@m.command` decorator registers functions |
| 30 | +- [ ] Annotated type hints parsed into argparse |
| 31 | +- [ ] Module docstring used as help text |
| 32 | +- [ ] Function docstring printed before execution |
| 33 | +- [ ] `m.Flag` type marker works |
| 34 | +- [ ] `--help` works at module and command level |
| 35 | +- [ ] `--dry-run` flag works globally |
| 36 | + |
| 37 | +### Phase 2: Shell & Status |
| 38 | +**Goal:** Implement `m.sh()` and status helpers |
| 39 | + |
| 40 | +**Deliverable:** Working shell executor with Result object |
| 41 | + |
| 42 | +**Done when:** |
| 43 | +- [ ] `m.sh(cmd)` executes and returns `Result` |
| 44 | +- [ ] `Result` has: ok, failed, stdout, stderr, returncode, duration |
| 45 | +- [ ] `--dry-run` makes `sh()` print command instead of executing |
| 46 | +- [ ] `m.ok()`, `m.fail()`, `m.info()`, `m.step()`, `m.warn()` work |
| 47 | +- [ ] `m.fail()` exits with code 1 |
| 48 | + |
| 49 | +### Phase 3: Utilities |
| 50 | +**Goal:** Implement file/path utilities |
| 51 | + |
| 52 | +**Deliverable:** Core utility functions |
| 53 | + |
| 54 | +**Done when:** |
| 55 | +- [ ] `m.read(path)` returns file contents |
| 56 | +- [ ] `m.write(path, content)` writes file |
| 57 | +- [ ] `m.ls(path=".")` returns list of filenames |
| 58 | +- [ ] `m.glob(pattern)` returns list of Paths |
| 59 | +- [ ] `m.touch(path)`, `m.rm(path)`, `m.cp(src,dst)`, `m.mv(src,dst)` |
| 60 | +- [ ] `m.cd(path)` works as context manager |
| 61 | +- [ ] `m.which(cmd)` returns Path or None |
| 62 | +- [ ] `m.env(name)` returns env var or None |
| 63 | + |
| 64 | +### Phase 4: Command Explain |
| 65 | +**Goal:** Implement `command.explain()` for agent workflows |
| 66 | + |
| 67 | +**Deliverable:** Command invocation generator |
| 68 | + |
| 69 | +**Done when:** |
| 70 | +- [ ] `cmd.explain()` generates `python app.py cmd` |
| 71 | +- [ ] `cmd.explain(arg=value)` includes positional args |
| 72 | +- [ ] `cmd.explain(flag=True)` includes `--flag` |
| 73 | +- [ ] Missing required args raises TypeError |
| 74 | +- [ ] Optional args with defaults work |
| 75 | + |
| 76 | +### Phase 5: YAML Support |
| 77 | +**Goal:** Add YAML parsing utilities |
| 78 | + |
| 79 | +**Deliverable:** `m.yaml` module |
| 80 | + |
| 81 | +**Done when:** |
| 82 | +- [ ] `m.yaml.load(text)` parses YAML |
| 83 | +- [ ] `m.yaml.dump(data)` serializes to YAML |
| 84 | + |
| 85 | +## Success Criteria |
| 86 | + |
| 87 | +- [ ] Single file, ~400 lines |
| 88 | +- [ ] Works with `python app.py --help` |
| 89 | +- [ ] `m.sh()` works in both normal and dry-run modes |
| 90 | +- [ ] `cmd.explain(arg=val)` generates correct invocation |
| 91 | +- [ ] All utilities return values (not print) |
| 92 | +- [ ] Status helpers print to stdout |
| 93 | +- [ ] Annotated type hints become help text |
| 94 | + |
| 95 | +## Risks & Mitigations |
| 96 | + |
| 97 | +| Risk | Likelihood | Mitigation | |
| 98 | +|------|------------|------------| |
| 99 | +| argparse + dry-run interaction complex | Medium | Test both modes early | |
| 100 | +| Type hint parsing edge cases | Medium | Start simple, add as needed | |
| 101 | +| Single file too long | Low | Keep under 500 lines | |
| 102 | + |
| 103 | +## Related |
| 104 | + |
| 105 | +- Design: `.knowledge/notes/mode-command-tool-pattern.md` |
0 commit comments