@nzpr/kb 0.1.12 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,164 +1,91 @@
1
- # Team Knowledge Base CLI
1
+ # @nzpr/kb
2
2
 
3
- `@nzpr/kb` is a package for managing a knowledge base that agents can read from and that humans can keep curated.
3
+ `@nzpr/kb` is a CLI for a curated knowledge base.
4
4
 
5
- The core idea is simple:
6
-
7
- - initialize a knowledge base
8
- - propose knowledge
9
- - publish approved knowledge
10
- - search the current knowledge
11
- - ask grounded questions against it
12
-
13
- At the product level, a knowledge base is just a collection of documents, and each document should stay minimal:
5
+ A knowledge base is just a set of documents:
14
6
 
15
7
  - `title`
16
8
  - `text`
17
9
 
18
10
  Everything else is implementation detail.
19
11
 
20
- ## Public API
21
-
22
- The public surface of `@nzpr/kb` is the `kb` CLI.
23
-
24
- - `kb init-repo`
25
- Initialize a knowledge base workspace.
26
- Use `kb init-repo --interactive` for a guided setup flow.
27
- Use `--layout repo-root` when this repository is itself the KB.
28
-
29
- - `kb create --title TEXT --text TEXT`
30
- Propose a new knowledge document or a substantial update.
31
-
32
- - `kb publish`
33
- Make the current approved documents become the live knowledge base.
34
-
35
- - `kb search "<query>"`
36
- Return the closest matching knowledge documents.
37
-
38
- - `kb ask "<question>"`
39
- Return a grounded answer from the closest matching knowledge.
40
-
41
- - `kb list`
42
- List the current knowledge documents.
12
+ ## Core Idea
43
13
 
44
- - `kb catalog`
45
- Return the current knowledge inventory in a machine-friendly form.
14
+ Use `@nzpr/kb` to do five things:
46
15
 
47
- - `kb doctor`
48
- Check whether the knowledge base is healthy and queryable.
16
+ 1. initialize a knowledge repo
17
+ 2. propose knowledge
18
+ 3. publish approved knowledge
19
+ 4. search knowledge
20
+ 5. answer questions from knowledge
49
21
 
50
- ## Lifecycle
51
-
52
- The intended workflow is:
53
-
54
- 1. Initialize a knowledge base.
55
- 2. Propose knowledge.
56
- 3. Review and approve knowledge.
57
- 4. Publish knowledge.
58
- 5. Query knowledge.
59
-
60
- ## Install
22
+ ## Public API
61
23
 
62
- From npm:
24
+ The public surface is the `kb` CLI.
63
25
 
64
26
  ```bash
65
- npm install -g @nzpr/kb
66
- kb --help
27
+ kb init-repo
28
+ kb create --title "..." --text "..."
29
+ kb publish --docs-root ./docs
30
+ kb search "..."
31
+ kb ask "..."
32
+ kb list
33
+ kb catalog --json
34
+ kb doctor
67
35
  ```
68
36
 
69
- From source:
37
+ ## Install
70
38
 
71
39
  ```bash
72
- npm install
73
- npm link
40
+ npm install -g @nzpr/kb
74
41
  ```
75
42
 
76
- ## Commands
77
-
78
- - `kb init-repo [--dir PATH] [--repo OWNER/REPO]`
79
- - `kb search "<terms>"`
80
- - `kb ask "<question>"`
81
- - `kb list`
82
- - `kb catalog [--json]`
83
- - `kb create --title TEXT --text TEXT [--path RELATIVE_PATH]`
84
- - `kb publish --docs-root PATH`
85
-
86
- ## Knowledge Repo Workflow
87
-
88
- In practice, the live knowledge usually lives in a separate repository that owns:
89
-
90
- - `kb/docs/`
91
- - the review flow for proposed knowledge
92
- - the publish automation
93
-
94
- Bootstrap that repo with:
43
+ Node.js 20+ is required.
95
44
 
96
- ```bash
97
- kb init-repo --dir /path/to/knowledge-repo
98
- ```
45
+ ## Minimal Usage
99
46
 
100
- If you want the CLI to walk you through setup and tell you what to do next:
47
+ ### 1. Initialize a Knowledge Repo
101
48
 
102
49
  ```bash
103
50
  kb init-repo --interactive
104
51
  ```
105
52
 
106
- Layout options:
107
-
108
- - `--layout repo-root` puts documents in `docs/`
109
- - `--layout nested-kb` puts documents in `kb/docs/`
110
-
111
- For a dedicated knowledge repository, prefer `--layout repo-root`.
53
+ For a dedicated knowledge repo, use repo-root layout so documents live in `docs/`.
112
54
 
113
- Or bootstrap and configure it in one step:
55
+ ### 2. Propose Knowledge
114
56
 
115
57
  ```bash
58
+ export KB_GITHUB_REPO=owner/repo
116
59
  export GITHUB_TOKEN=...
117
- kb init-repo \
118
- --dir /path/to/knowledge-repo \
119
- --repo owner/knowledge-repo \
120
- --database-url postgresql://kb:kb@host:5432/kb \
121
- --embedding-mode bge-m3-openai \
122
- --embedding-api-url https://embeddings.example.com/v1/embeddings \
123
- --embedding-model BAAI/bge-m3
124
- ```
125
-
126
- Inside that knowledge repo, the normal flow is:
127
-
128
- 1. Run `kb init-repo` once to scaffold the repo. If you provide `--repo`, `--database-url`, and `GITHUB_TOKEN`, it also configures the target repo and preflights the database.
129
- 2. Open or update a knowledge proposal issue.
130
- 3. Review and approve it there.
131
- 4. Materialize it into the configured docs directory.
132
- 5. After merge, that repo's CI runs `kb publish` against that docs directory.
133
60
 
134
- `kb init-repo` is safe to rerun. It reports bootstrap status for:
61
+ kb create \
62
+ --title "Example Rule" \
63
+ --text "Write the exact knowledge text here."
64
+ ```
135
65
 
136
- - local scaffold creation
137
- - knowledge document layout selection
138
- - database preflight and schema initialization
139
- - GitHub repo labels, variables, and secrets
66
+ This creates a GitHub issue proposal.
140
67
 
141
- In interactive mode it also:
68
+ ### 3. Approve Knowledge
142
69
 
143
- - asks which repo and directory you want to initialize
144
- - asks whether to wire GitHub setup now
145
- - asks whether to verify the database now
146
- - collects embedding settings if you want remote embeddings
147
- - prints the next actions after initialization
70
+ Add the `kb-approved` label to the proposal issue.
148
71
 
149
- If one remote step fails, the scaffold still stays in place and the command tells you what to rerun.
72
+ That triggers automation which:
150
73
 
151
- ## Runtime
74
+ 1. writes the Markdown document
75
+ 2. opens a PR
76
+ 3. lets merge trigger publish
152
77
 
153
- Node.js 20+ is required.
78
+ ### 4. Publish Knowledge
154
79
 
155
- Query commands need:
80
+ Publishing reads local docs and writes them to the database.
156
81
 
157
82
  ```bash
158
- export KB_DATABASE_URL=postgresql://kb:kb@localhost:5432/kb
83
+ export KB_DATABASE_URL=postgresql://USER:PASSWORD@HOST:5432/DB
84
+
85
+ kb publish --docs-root ./docs
159
86
  ```
160
87
 
161
- Higher-quality retrieval can use a self-hosted embeddings service:
88
+ Optional higher-quality embeddings:
162
89
 
163
90
  ```bash
164
91
  export KB_EMBEDDING_MODE=bge-m3-openai
@@ -167,83 +94,58 @@ export KB_EMBEDDING_MODEL=BAAI/bge-m3
167
94
  export KB_EMBEDDING_API_KEY=...
168
95
  ```
169
96
 
170
- If `KB_EMBEDDING_MODE` is omitted, the CLI uses local hash embeddings for development.
171
-
172
- Publishing uses the local docs directory and the database only. It does not need GitHub credentials.
173
-
174
- When `kb init-repo` is given `--repo`, it uses the same token to:
175
-
176
- - enable issues in the target repo
177
- - set GitHub Actions workflow permissions to write and allow Actions to create PRs
178
- - create or update the `kb-entry` and `kb-approved` labels
179
- - write repository secrets and variables
180
- - verify and initialize the target database schema if `--database-url` is provided
181
-
182
- For the GitHub setup step, that token must have repository admin access. A plain write token is not enough for Actions settings and repo secrets.
183
-
184
- 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.
185
-
186
- ## Quick Start
97
+ ### 5. Query Knowledge
187
98
 
188
99
  ```bash
189
- export KB_DATABASE_URL=postgresql://kb:kb@localhost:5432/kb
190
- docker compose -f docker-compose.pgvector.yml up -d
191
- kb publish --docs-root ./docs
192
- kb catalog --json
193
- kb search "deployment rule"
194
- ```
195
-
196
- Each Markdown file is indexed as one document and one vector row. Keep documents simple: one title and one body.
100
+ export KB_DATABASE_URL=postgresql://USER:PASSWORD@HOST:5432/DB
197
101
 
198
- ## Optional Split Mode
199
-
200
- If you later want separate entities, isolated databases, or a dedicated content repo, you can use `kb create` with:
201
-
202
- ```bash
203
- export KB_GITHUB_REPO=org/knowledge-content
204
- export GITHUB_TOKEN=...
102
+ kb search "deployment rule"
103
+ kb ask "How do I approve a knowledge proposal?"
104
+ kb list
105
+ kb catalog --json
106
+ kb doctor
205
107
  ```
206
108
 
207
- That path is optional. The default assumption is that you work in one repo.
208
-
209
- ## npm Release
109
+ ## Standard Workflow
210
110
 
211
- The package is published as `@nzpr/kb`.
111
+ The intended flow is:
212
112
 
213
- - local validation: `npm test`
214
- - local package preview: `npm pack --dry-run`
215
- - GitHub Actions publish: push a tag like `v0.1.0` or run the `npm-publish` workflow manually
216
- - npm authentication: use npm trusted publishing with GitHub Actions OIDC, not a long-lived publish token
217
- - required npm setup: in npm package settings, configure trusted publishing for `nzpr/kb` and workflow file `.github/workflows/npm-publish.yml`
113
+ 1. `kb init-repo`
114
+ 2. `kb create`
115
+ 3. review the issue
116
+ 4. add `kb-approved`
117
+ 5. merge the generated PR
118
+ 6. let CI run `kb publish`
119
+ 7. query with `kb search` or `kb ask`
218
120
 
219
- ## Using From A Knowledge Repo
121
+ ## Repo Bootstrap
220
122
 
221
- 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/`:
123
+ If you want `kb init-repo` to configure the target GitHub repo too:
222
124
 
223
125
  ```bash
224
- npm install -g @nzpr/kb
225
- export KB_GITHUB_REPO=owner/repo
226
126
  export GITHUB_TOKEN=...
227
- kb publish --docs-root ./docs
228
- ```
229
-
230
- Or scaffold that repo first:
231
-
232
- ```bash
233
- kb init-repo --dir .
234
- ```
235
127
 
236
- If you want init to configure the target repo too:
237
-
238
- ```bash
239
- export GITHUB_TOKEN=...
240
- export KB_REPO_AUTOMATION_TOKEN=...
241
128
  kb init-repo \
242
- --dir . \
129
+ --dir /path/to/knowledge-repo \
243
130
  --repo owner/knowledge-repo \
244
- --database-url postgresql://kb:kb@host:5432/kb \
131
+ --database-url postgresql://USER:PASSWORD@HOST:5432/DB \
245
132
  --embedding-mode bge-m3-openai \
246
133
  --embedding-api-url https://embeddings.example.com/v1/embeddings \
247
- --embedding-model BAAI/bge-m3 \
248
- --embedding-api-key YOUR_KEY
134
+ --embedding-model BAAI/bge-m3
249
135
  ```
136
+
137
+ For this setup step, the token must have repository admin access.
138
+
139
+ `kb init-repo` configures:
140
+
141
+ - issue templates
142
+ - GitHub labels
143
+ - GitHub Actions workflow permissions
144
+ - repo secrets and variables
145
+ - knowledge publish workflow
146
+
147
+ ## Notes
148
+
149
+ - Keep each document minimal: one title, one body.
150
+ - `kb publish` does not need GitHub credentials.
151
+ - The package published to npm is `@nzpr/kb`.
@@ -71,7 +71,9 @@ export function writeProposalDocument({ issueNumber, issueTitle, issueBody, docs
71
71
  "",
72
72
  `Source issue title: ${issueTitle}`,
73
73
  "",
74
- `Document path: \`${relativePath}\``
74
+ `Document path: \`${relativePath}\``,
75
+ "",
76
+ `Closes #${issueNumber}`
75
77
  ].join("\n")
76
78
  };
77
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nzpr/kb",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "Knowledge base CLI for proposing, publishing, and querying curated agent knowledge.",
5
5
  "repository": {
6
6
  "type": "git",