agent-kb 0.1.0
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/LICENSE +19 -0
- package/README.md +139 -0
- package/dist/api/index.d.ts +756 -0
- package/dist/api/index.js +8 -0
- package/dist/chunk-I77A4URT.js +5963 -0
- package/dist/cli/index.d.ts +84 -0
- package/dist/cli/index.js +1022 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2026 Walid Darrai <darraiwalid@gmail.com>
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
This software and its source code are proprietary and confidential.
|
|
5
|
+
|
|
6
|
+
No license, right, or permission is granted to any person or entity to use,
|
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, reproduce, or create
|
|
8
|
+
derivative works of this software, in whole or in part, by any means, without
|
|
9
|
+
the prior express written permission of the copyright holder.
|
|
10
|
+
|
|
11
|
+
Unauthorized use, copying, distribution, or disclosure of this software, or any
|
|
12
|
+
portion of it, is strictly prohibited.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
16
|
+
FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT
|
|
17
|
+
HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
18
|
+
OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE
|
|
19
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# Agent KB
|
|
2
|
+
|
|
3
|
+
A local-first, project-scoped knowledge base engine for AI agents. Agent KB lives in a hidden `.agent-kb/` folder inside your project, stores entities and relationships as human-readable files (YAML/JSON), and exposes them via a reviewable change-set workflow: agents **propose** changes, humans (or CI) **accept** or **reject** them. The engine offers structured queries, relationship tracing, FTS search, and task-specific context packs — accessible over a CLI or an in-process API.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Node.js >= 20
|
|
8
|
+
|
|
9
|
+
## Install / Quickstart
|
|
10
|
+
|
|
11
|
+
No install needed for one-off use — just run via `npx`:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx agent-kb init
|
|
15
|
+
npx agent-kb context TASK-001
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
For repeated use in a project, install locally:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install agent-kb
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Typical flow
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# 1. Initialise a KB in the current project
|
|
28
|
+
npx agent-kb init
|
|
29
|
+
|
|
30
|
+
# 2. Check KB health and pending change sets
|
|
31
|
+
npx agent-kb status
|
|
32
|
+
|
|
33
|
+
# 3. Propose a change set from a JSON file (create/update/link ops)
|
|
34
|
+
npx agent-kb propose change-set.json
|
|
35
|
+
|
|
36
|
+
# 4. Review what is pending
|
|
37
|
+
npx agent-kb changesets
|
|
38
|
+
|
|
39
|
+
# 5. Accept or reject a change set by its ID
|
|
40
|
+
npx agent-kb accept CS-001
|
|
41
|
+
npx agent-kb reject CS-002 --reason "duplicate"
|
|
42
|
+
|
|
43
|
+
# 6. Query the KB
|
|
44
|
+
npx agent-kb get TASK-001
|
|
45
|
+
npx agent-kb find Task
|
|
46
|
+
npx agent-kb related TASK-001
|
|
47
|
+
npx agent-kb trace TASK-001
|
|
48
|
+
npx agent-kb why TASK-001 --in-context FEAT-001
|
|
49
|
+
npx agent-kb search "authentication flow"
|
|
50
|
+
|
|
51
|
+
# 7. Get a task-specific context pack
|
|
52
|
+
npx agent-kb context TASK-001
|
|
53
|
+
|
|
54
|
+
# 8. Scan the project for untracked files and validate a change set or entity
|
|
55
|
+
npx agent-kb scan
|
|
56
|
+
npx agent-kb validate CS-001
|
|
57
|
+
|
|
58
|
+
# 9. Docs and housekeeping
|
|
59
|
+
npx agent-kb docs generate
|
|
60
|
+
npx agent-kb verify
|
|
61
|
+
npx agent-kb reindex
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
> **Not yet implemented in V1** — these commands are registered and parse correctly but return a `FEATURE_DISABLED` error envelope; do not use them in production flows: `snapshot create`, `export --format json`, `schema apply <file>`.
|
|
65
|
+
|
|
66
|
+
Full command reference: `npx agent-kb --help` or `npx agent-kb <command> --help`.
|
|
67
|
+
|
|
68
|
+
Available commands: `init`, `status`, `reindex`, `migrate`, `get <id>`, `find <type>`, `related <id>`, `trace <id>`, `why <id>`, `search <text>`, `context <id>`, `propose <file>`, `validate <idOrFile>`, `accept <id>`, `reject <id>`, `scan`, `verify`, `docs generate`, `changesets`, `schema apply <file>`, `snapshot create`, `export`.
|
|
69
|
+
|
|
70
|
+
## Embedding (in-process API)
|
|
71
|
+
|
|
72
|
+
Use the `agent-kb/api` entry point to call the engine directly from Node.js — no subprocess, no network:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { openKb } from 'agent-kb/api';
|
|
76
|
+
|
|
77
|
+
const kb = openKb({ root: process.cwd() });
|
|
78
|
+
|
|
79
|
+
// Get a task-specific context pack
|
|
80
|
+
const res = kb.context({ id: 'TASK-001' });
|
|
81
|
+
if (res.ok) {
|
|
82
|
+
// res.data: ContextPack
|
|
83
|
+
console.log(res.data);
|
|
84
|
+
} else {
|
|
85
|
+
// res.error: KbErrorBody (code + message)
|
|
86
|
+
console.error(res.error);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Always release the SQLite handle when done
|
|
90
|
+
kb.close();
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Every engine method returns an `Envelope`: `{ ok: true, data: T }` on success or `{ ok: false, error: KbErrorBody }` on failure — it never throws across the API boundary.
|
|
94
|
+
|
|
95
|
+
The `openKb` function accepts `{ root, clock?, lock?, embeddingProvider? }`. If `.agent-kb/` does not exist yet, the returned engine allows only `init()`; all other methods return a `NOT_FOUND` envelope until you call `init()` and re-open.
|
|
96
|
+
|
|
97
|
+
## Transports
|
|
98
|
+
|
|
99
|
+
| Transport | How to use |
|
|
100
|
+
|-----------|-----------|
|
|
101
|
+
| **CLI** | `npx agent-kb <command>` — the `agent-kb` bin ships in `dist/cli/index.js` |
|
|
102
|
+
| **In-process API** | `import { openKb } from 'agent-kb/api'` — same engine, zero overhead |
|
|
103
|
+
| **MCP server** | `npx agent-kb mcp` launches the MCP server over **stdio**. Opt-in and config-gated: it requires `mcp.enabled: true` in `.agent-kb/config.yml` (off by default), otherwise it exits with a `FEATURE_DISABLED` error. Stdio is the only transport (no HTTP/SSE). `createMcpServer` remains internal — it is **not** re-exported from `agent-kb/api`; the CLI bundles it into `dist/cli/index.js`. |
|
|
104
|
+
|
|
105
|
+
## Vector search
|
|
106
|
+
|
|
107
|
+
Off by default. Set `search.vector_enabled: true` in `.agent-kb/config.yml` to enable it, and set `search.embedding_provider: 'ollama'` with the `nomic-embed-text` model pulled (`ollama pull nomic-embed-text`). After enabling on an existing KB, run `npx agent-kb reindex` to backfill existing entities into the vector index.
|
|
108
|
+
|
|
109
|
+
### Search modes
|
|
110
|
+
|
|
111
|
+
| Mode | What it matches | When to use |
|
|
112
|
+
|------|----------------|-------------|
|
|
113
|
+
| `fts` (default) | Porter-stemmed keyword tokens in `search_fields` | Exact / fuzzy keyword lookup |
|
|
114
|
+
| `semantic` | Meaning similarity via vector embeddings (cosine) | Paraphrase or concept queries — finds what FTS misses |
|
|
115
|
+
| `hybrid` | RRF fusion of FTS + vector rankings | Best of both — surface both keyword and meaning matches |
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
# keyword match (default)
|
|
119
|
+
npx agent-kb search "authentication"
|
|
120
|
+
|
|
121
|
+
# meaning match — finds "Verifying user credentials" even without the word "login"
|
|
122
|
+
npx agent-kb search "login" --mode semantic
|
|
123
|
+
|
|
124
|
+
# fused ranking (Reciprocal Rank Fusion)
|
|
125
|
+
npx agent-kb search "login" --mode hybrid
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Error surfaces
|
|
129
|
+
|
|
130
|
+
- **`FEATURE_DISABLED`** — `semantic` mode returns this error when `search.vector_enabled` is `false` or no embedding provider is configured. `hybrid` degrades gracefully to FTS-only (no error).
|
|
131
|
+
- **`VECTOR_INDEX_FAILED`** — returned by `accept` when the vector-index update fails in the post-commit write-path hook (e.g. the embedding backend errors or is unreachable). Canonical data and FTS are consistent; the vector index is stale until `reindex` is run.
|
|
132
|
+
|
|
133
|
+
## Project documents
|
|
134
|
+
|
|
135
|
+
For contributors and deeper understanding:
|
|
136
|
+
|
|
137
|
+
- `agent-kb-product-spec.md` — external contracts (file formats, JSON ops, error codes, acceptance criteria)
|
|
138
|
+
- `agent-kb-technical-design.md` — internal engineering design (module decomposition, engine API, core types, storage internals, key flows)
|
|
139
|
+
- `TICKETS.md` — index of the 28 implementation tickets: build-order groups, execution order, critical path
|