Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@nzpr/kb) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Team Knowledge Base CLI
@nzpr/kb is a package for managing a knowledge base that agents can read from and that humans can keep curated.
The core idea is simple:
- initialize a knowledge base
- propose knowledge
- publish approved knowledge
- search the current knowledge
- ask grounded questions against it
At the product level, a knowledge base is just a collection of documents, and each document should stay minimal:
titletext
Everything else is implementation detail.
Public API
The public surface of @nzpr/kb is the kb CLI.
kb init-repoInitialize a knowledge base workspace. Usekb init-repo --interactivefor a guided setup flow. Use--layout repo-rootwhen this repository is itself the KB.kb create --title TEXT --text TEXTPropose a new knowledge document or a substantial update.kb publishMake the current approved documents become the live knowledge base.kb search "<query>"Return the closest matching knowledge documents.kb ask "<question>"Return a grounded answer from the closest matching knowledge.kb listList the current knowledge documents.kb catalogReturn the current knowledge inventory in a machine-friendly form.kb doctorCheck whether the knowledge base is healthy and queryable.
Lifecycle
The intended workflow is:
- Initialize a knowledge base.
- Propose knowledge.
- Review and approve knowledge.
- Publish knowledge.
- Query knowledge.
Install
From npm:
npm install -g @nzpr/kb
kb --helpFrom source:
npm install
npm linkCommands
kb init-repo [--dir PATH] [--repo OWNER/REPO]kb search "<terms>"kb ask "<question>"kb listkb catalog [--json]kb create --title TEXT --text TEXT [--path RELATIVE_PATH]kb publish --docs-root PATH
Knowledge Repo Workflow
In practice, the live knowledge usually lives in a separate repository that owns:
kb/docs/- the review flow for proposed knowledge
- the publish automation
Bootstrap that repo with:
kb init-repo --dir /path/to/knowledge-repoIf you want the CLI to walk you through setup and tell you what to do next:
kb init-repo --interactiveLayout options:
--layout repo-rootputs documents indocs/--layout nested-kbputs documents inkb/docs/
For a dedicated knowledge repository, prefer --layout repo-root.
Or bootstrap and configure it in one step:
export GITHUB_TOKEN=...
kb init-repo \
--dir /path/to/knowledge-repo \
--repo owner/knowledge-repo \
--database-url postgresql://kb:kb@host:5432/kb \
--embedding-mode bge-m3-openai \
--embedding-api-url https://embeddings.example.com/v1/embeddings \
--embedding-model BAAI/bge-m3Inside that knowledge repo, the normal flow is:
- Run
kb init-repoonce to scaffold the repo. If you provide--repo,--database-url, andGITHUB_TOKEN, it also configures the target repo and preflights the database. - Open or update a knowledge proposal issue.
- Review and approve it there.
- Materialize it into the configured docs directory.
- After merge, that repo's CI runs
kb publishagainst that docs directory.
kb init-repo is safe to rerun. It reports bootstrap status for:
- local scaffold creation
- knowledge document layout selection
- database preflight and schema initialization
- GitHub repo labels, variables, and secrets
In interactive mode it also:
- asks which repo and directory you want to initialize
- asks whether to wire GitHub setup now
- asks whether to verify the database now
- collects embedding settings if you want remote embeddings
- prints the next actions after initialization
If one remote step fails, the scaffold still stays in place and the command tells you what to rerun.
Runtime
Node.js 20+ is required.
Query commands need:
export KB_DATABASE_URL=postgresql://kb:kb@localhost:5432/kbHigher-quality retrieval can use a self-hosted embeddings service:
export KB_EMBEDDING_MODE=bge-m3-openai
export KB_EMBEDDING_API_URL=https://embeddings.example.com/v1/embeddings
export KB_EMBEDDING_MODEL=BAAI/bge-m3
export KB_EMBEDDING_API_KEY=...If KB_EMBEDDING_MODE is omitted, the CLI uses local hash embeddings for development.
Publishing needs one more privileged environment variable:
export KB_GITHUB_REPO=owner/repo
export GITHUB_TOKEN=...Publishing is allowed when the provided GITHUB_TOKEN has write access to KB_GITHUB_REPO. Normal readers do not need GitHub credentials.
When kb init-repo is given --repo, it uses the same token to:
- enable issues in the target repo
- create or update the
kb-entryandkb-approvedlabels - write repository secrets and variables
- verify and initialize the target database schema if
--database-urlis provided
If you run kb init-repo without the repo or database inputs, it still scaffolds the knowledge repo and prints exactly which remote bootstrap inputs are still pending.
Quick Start
export KB_DATABASE_URL=postgresql://kb:kb@localhost:5432/kb
export KB_GITHUB_REPO=owner/repo
export GITHUB_TOKEN=...
docker compose -f docker-compose.pgvector.yml up -d
kb publish --docs-root ./docs
kb catalog --json
kb search "deployment rule"Each Markdown file is indexed as one document and one vector row. Keep documents simple: one title and one body.
Optional Split Mode
If you later want separate entities, isolated databases, or a dedicated content repo, you can use kb create with:
export KB_GITHUB_REPO=org/knowledge-content
export GITHUB_TOKEN=...That path is optional. The default assumption is that you work in one repo.
npm Release
The package is published as @nzpr/kb.
- local validation:
npm test - local package preview:
npm pack --dry-run - GitHub Actions publish: push a tag like
v0.1.0or run thenpm-publishworkflow manually - npm authentication: use npm trusted publishing with GitHub Actions OIDC, not a long-lived publish token
- required npm setup: in npm package settings, configure trusted publishing for
nzpr/kband workflow file.github/workflows/npm-publish.yml
Using From A Knowledge Repo
The knowledge-authority repo should install this package in CI and use it to sync its configured docs directory into the vector database. For a dedicated KB repo with --layout repo-root, that directory is docs/:
npm install -g @nzpr/kb
export KB_GITHUB_REPO=owner/repo
export GITHUB_TOKEN=...
kb publish --docs-root ./docsOr scaffold that repo first:
kb init-repo --dir .If you want init to configure the target repo too:
export GITHUB_TOKEN=...
export KB_REPO_AUTOMATION_TOKEN=...
kb init-repo \
--dir . \
--repo owner/knowledge-repo \
--database-url postgresql://kb:kb@host:5432/kb \
--embedding-mode bge-m3-openai \
--embedding-api-url https://embeddings.example.com/v1/embeddings \
--embedding-model BAAI/bge-m3 \
--embedding-api-key YOUR_KEY