@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 +82 -180
- package/lib/kb-proposals.js +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,164 +1,91 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nzpr/kb
|
|
2
2
|
|
|
3
|
-
`@nzpr/kb` is a
|
|
3
|
+
`@nzpr/kb` is a CLI for a curated knowledge base.
|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
##
|
|
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
|
-
|
|
45
|
-
Return the current knowledge inventory in a machine-friendly form.
|
|
14
|
+
Use `@nzpr/kb` to do five things:
|
|
46
15
|
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
##
|
|
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
|
-
|
|
24
|
+
The public surface is the `kb` CLI.
|
|
63
25
|
|
|
64
26
|
```bash
|
|
65
|
-
|
|
66
|
-
kb --
|
|
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
|
-
|
|
37
|
+
## Install
|
|
70
38
|
|
|
71
39
|
```bash
|
|
72
|
-
npm install
|
|
73
|
-
npm link
|
|
40
|
+
npm install -g @nzpr/kb
|
|
74
41
|
```
|
|
75
42
|
|
|
76
|
-
|
|
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
|
-
|
|
97
|
-
kb init-repo --dir /path/to/knowledge-repo
|
|
98
|
-
```
|
|
45
|
+
## Minimal Usage
|
|
99
46
|
|
|
100
|
-
|
|
47
|
+
### 1. Initialize a Knowledge Repo
|
|
101
48
|
|
|
102
49
|
```bash
|
|
103
50
|
kb init-repo --interactive
|
|
104
51
|
```
|
|
105
52
|
|
|
106
|
-
|
|
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
|
-
|
|
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
|
-
|
|
61
|
+
kb create \
|
|
62
|
+
--title "Example Rule" \
|
|
63
|
+
--text "Write the exact knowledge text here."
|
|
64
|
+
```
|
|
135
65
|
|
|
136
|
-
|
|
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
|
-
|
|
68
|
+
### 3. Approve Knowledge
|
|
142
69
|
|
|
143
|
-
|
|
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
|
-
|
|
72
|
+
That triggers automation which:
|
|
150
73
|
|
|
151
|
-
|
|
74
|
+
1. writes the Markdown document
|
|
75
|
+
2. opens a PR
|
|
76
|
+
3. lets merge trigger publish
|
|
152
77
|
|
|
153
|
-
|
|
78
|
+
### 4. Publish Knowledge
|
|
154
79
|
|
|
155
|
-
|
|
80
|
+
Publishing reads local docs and writes them to the database.
|
|
156
81
|
|
|
157
82
|
```bash
|
|
158
|
-
export KB_DATABASE_URL=postgresql://
|
|
83
|
+
export KB_DATABASE_URL=postgresql://USER:PASSWORD@HOST:5432/DB
|
|
84
|
+
|
|
85
|
+
kb publish --docs-root ./docs
|
|
159
86
|
```
|
|
160
87
|
|
|
161
|
-
|
|
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
|
-
|
|
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://
|
|
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
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
-
|
|
208
|
-
|
|
209
|
-
## npm Release
|
|
109
|
+
## Standard Workflow
|
|
210
110
|
|
|
211
|
-
The
|
|
111
|
+
The intended flow is:
|
|
212
112
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
##
|
|
121
|
+
## Repo Bootstrap
|
|
220
122
|
|
|
221
|
-
|
|
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://
|
|
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`.
|
package/lib/kb-proposals.js
CHANGED
|
@@ -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
|
}
|