Skip to content

feat(cli): expose CLI features as a typed programmatic API - #34

Merged
mrsimpson merged 2 commits into
mainfrom
claude/typed-cli-api-Kl1GV
Mar 16, 2026
Merged

feat(cli): expose CLI features as a typed programmatic API#34
mrsimpson merged 2 commits into
mainfrom
claude/typed-cli-api-Kl1GV

Conversation

@mrsimpson

Copy link
Copy Markdown
Collaborator

Add a new packages/cli/src/api/ module that wraps the core CLI
operations (create, init, refresh, status) in typed, process-safe
async functions:

  • createDocset(params, options?) – validates preset params and
    writes a new docset entry to .knowledge/config.yaml
  • initDocset(params) – downloads / symlinks all sources for a
    docset; supports optional path discovery and progress callbacks
  • refreshDocsets(params?) – pulls latest content for one or all
    docsets, returning structured per-docset results
  • getStatus(params?) – returns structured status for every docset
    without any console output

Key design decisions:

  • No process.exit() – callers receive thrown errors instead
  • No chalk/console output – pure return values; CLI commands remain
    the only place that prints to stdout
  • Full TypeScript types for every parameter and return value, exported
    from src/exports.ts for library consumers
  • cwd option on every function so callers can control which
    .knowledge/config.yaml is used

Refactor the four CLI command files to delegate to the new API
functions, removing ~800 lines of duplicated business logic from
the command handlers.

https://claude.ai/code/session_01SExqFNVoBLQCCAbgAY6LXo

claude added 2 commits March 16, 2026 15:25
Add a new `packages/cli/src/api/` module that wraps the core CLI
operations (create, init, refresh, status) in typed, process-safe
async functions:

- `createDocset(params, options?)` – validates preset params and
  writes a new docset entry to .knowledge/config.yaml
- `initDocset(params)` – downloads / symlinks all sources for a
  docset; supports optional path discovery and progress callbacks
- `refreshDocsets(params?)` – pulls latest content for one or all
  docsets, returning structured per-docset results
- `getStatus(params?)` – returns structured status for every docset
  without any console output

Key design decisions:
- No `process.exit()` – callers receive thrown errors instead
- No chalk/console output – pure return values; CLI commands remain
  the only place that prints to stdout
- Full TypeScript types for every parameter and return value, exported
  from `src/exports.ts` for library consumers
- `cwd` option on every function so callers can control which
  .knowledge/config.yaml is used

Refactor the four CLI command files to delegate to the new API
functions, removing ~800 lines of duplicated business logic from
the command handlers.

https://claude.ai/code/session_01SExqFNVoBLQCCAbgAY6LXo
Enable tsup dts generation for src/exports.ts so that dist/exports.d.ts
is produced at build time. The binary entry (index) still skips dts.

Work around the `incremental: true` in the base tsconfig that conflicts
with tsup's DTS worker by overriding it to false in the tsup config.

https://claude.ai/code/session_01SExqFNVoBLQCCAbgAY6LXo
@mrsimpson
mrsimpson merged commit 588f662 into main Mar 16, 2026
1 check passed
@mrsimpson
mrsimpson deleted the claude/typed-cli-api-Kl1GV branch March 16, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants