feat(cli): expose CLI features as a typed programmatic API - #34
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a new
packages/cli/src/api/module that wraps the core CLIoperations (create, init, refresh, status) in typed, process-safe
async functions:
createDocset(params, options?)– validates preset params andwrites a new docset entry to .knowledge/config.yaml
initDocset(params)– downloads / symlinks all sources for adocset; supports optional path discovery and progress callbacks
refreshDocsets(params?)– pulls latest content for one or alldocsets, returning structured per-docset results
getStatus(params?)– returns structured status for every docsetwithout any console output
Key design decisions:
process.exit()– callers receive thrown errors insteadthe only place that prints to stdout
from
src/exports.tsfor library consumerscwdoption 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