pi-knowledge 0.2.0 → 0.2.2
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/.pi/skills/search-docs.md +23 -0
- package/CHANGELOG.md +16 -0
- package/README.md +2 -0
- package/index.ts +14 -3
- package/package.json +2 -1
- package/src/engine.ts +5 -5
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: search-docs
|
|
3
|
+
description: Search indexed knowledge bases for relevant documentation or code
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Search Knowledge Base
|
|
7
|
+
|
|
8
|
+
Search the indexed knowledge bases for: $ARGUMENTS
|
|
9
|
+
|
|
10
|
+
## Steps
|
|
11
|
+
|
|
12
|
+
1. Use `knowledge_show` to see available knowledge bases
|
|
13
|
+
2. Use `knowledge_search` with the user's query (hybrid mode by default)
|
|
14
|
+
3. If results are insufficient, try mode "deep" for cross-encoder reranking
|
|
15
|
+
4. For exact symbol lookups, use mode "fast" (BM25 only)
|
|
16
|
+
5. Present results with file paths and relevant snippets
|
|
17
|
+
|
|
18
|
+
## Tips
|
|
19
|
+
|
|
20
|
+
- Code queries: use function names, class names, or API signatures
|
|
21
|
+
- Concept queries: use natural language descriptions
|
|
22
|
+
- Filter: `file_type: "typescript"` or `file_type: "python"`
|
|
23
|
+
- No results? Check `knowledge_show` to confirm content is indexed
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.2.2] - 2026-06-15
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- AbortSignal now threads end-to-end (tool → engine → embedding loop)
|
|
7
|
+
- Cancellation actually works during long embedding operations
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- TUI custom rendering for knowledge_search (renderCall + renderResult)
|
|
11
|
+
- All DESIGN.md phases complete (30/30 checkboxes)
|
|
12
|
+
|
|
13
|
+
## [0.2.1] - 2026-06-15
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
- README lists all 9 tools (was missing export/import)
|
|
17
|
+
- npm package includes .pi/skills/ for skill distribution
|
|
18
|
+
|
|
3
19
|
## [0.2.0] - 2026-06-15
|
|
4
20
|
|
|
5
21
|
### Added
|
package/README.md
CHANGED
|
@@ -63,6 +63,8 @@ pi install ./pi-knowledge
|
|
|
63
63
|
| `knowledge_show` | List all knowledge bases with stats |
|
|
64
64
|
| `knowledge_status` | Show engine status with health diagnostics (stale, orphans, coverage) |
|
|
65
65
|
| `knowledge_clear` | Remove all knowledge bases |
|
|
66
|
+
| `knowledge_export` | Export a KB to shareable JSONL file |
|
|
67
|
+
| `knowledge_import` | Import a KB from JSONL (re-embeds content) |
|
|
66
68
|
|
|
67
69
|
## Architecture
|
|
68
70
|
|
package/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Text } from "@earendil-works/pi-tui";
|
|
2
3
|
import { Type } from "typebox";
|
|
3
4
|
import { KnowledgeEngine } from "./src/engine.ts";
|
|
4
5
|
import { getDefaultKnowledgeDir } from "./src/storage/sqlite.ts";
|
|
@@ -71,7 +72,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
71
72
|
const { source, name } = params;
|
|
72
73
|
const { kb, chunkCount } = await engine.add(source, name, (msg) => {
|
|
73
74
|
onUpdate?.({ content: [{ type: "text", text: msg }] });
|
|
74
|
-
});
|
|
75
|
+
}, _signal);
|
|
75
76
|
// Start watcher for new directory KB
|
|
76
77
|
if (WATCH_ENABLED && kb.source_path && kb.source_type === "directory") {
|
|
77
78
|
startWatcher(kb.id, kb.source_path, (kbId) => { engine.update(kbId).catch(() => {}); });
|
|
@@ -100,6 +101,15 @@ export default function (pi: ExtensionAPI) {
|
|
|
100
101
|
offset: Type.Optional(Type.Number({ description: "Pagination offset" })),
|
|
101
102
|
file_type: Type.Optional(Type.String({ description: "Filter by file type (e.g. typescript, markdown, python)" })),
|
|
102
103
|
}),
|
|
104
|
+
renderCall(args, theme) {
|
|
105
|
+
const mode = args.mode || "hybrid";
|
|
106
|
+
return new Text(`${theme.fg("accent", "Search")}: "${args.query}" ${theme.fg("muted", `(${mode})`)}`, 0, 0);
|
|
107
|
+
},
|
|
108
|
+
renderResult(result, options, theme) {
|
|
109
|
+
const text = result.content?.[0]?.text ?? "";
|
|
110
|
+
const lines = options.expanded ? text : text.split("\n").slice(0, 5).join("\n");
|
|
111
|
+
return new Text(lines, 0, 0);
|
|
112
|
+
},
|
|
103
113
|
async execute(_id, params) {
|
|
104
114
|
const { query, mode, limit, kb_id, offset, file_type } = params;
|
|
105
115
|
const filters = file_type ? { file_type } : undefined;
|
|
@@ -129,13 +139,14 @@ export default function (pi: ExtensionAPI) {
|
|
|
129
139
|
async execute(_id, params, _signal, onUpdate) {
|
|
130
140
|
const { added, removed, unchanged } = await engine.update(params.target, (msg) => {
|
|
131
141
|
onUpdate?.({ content: [{ type: "text", text: msg }] });
|
|
132
|
-
});
|
|
142
|
+
}, _signal);
|
|
133
143
|
return {
|
|
134
144
|
content: [{ type: "text", text: `Updated: +${added} added, -${removed} removed, ${unchanged} unchanged.` }],
|
|
135
145
|
};
|
|
136
146
|
},
|
|
137
147
|
});
|
|
138
148
|
|
|
149
|
+
|
|
139
150
|
pi.registerTool({
|
|
140
151
|
name: "knowledge_status",
|
|
141
152
|
label: "Knowledge Status",
|
|
@@ -215,7 +226,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
215
226
|
async execute(_id, params, _signal, onUpdate) {
|
|
216
227
|
const { kb, chunkCount } = await engine.importKB(params.input, (msg) => {
|
|
217
228
|
onUpdate?.({ content: [{ type: "text", text: msg }] });
|
|
218
|
-
});
|
|
229
|
+
}, _signal);
|
|
219
230
|
return { content: [{ type: "text", text: `Imported "${kb.name}": ${chunkCount} chunks (re-embedded)` }] };
|
|
220
231
|
},
|
|
221
232
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-knowledge",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Vector knowledge base extension for Pi — index files, hybrid search, local embeddings",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.ts",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"files": [
|
|
13
13
|
"index.ts",
|
|
14
14
|
"src/",
|
|
15
|
+
".pi/",
|
|
15
16
|
"README.md",
|
|
16
17
|
"CHANGELOG.md",
|
|
17
18
|
"LICENSE"
|
package/src/engine.ts
CHANGED
|
@@ -68,7 +68,7 @@ export class KnowledgeEngine {
|
|
|
68
68
|
this.vectorCache.delete(kbId);
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
async add(source: string, name: string, onProgress?: ProgressCallback): Promise<{ kb: KnowledgeBase; chunkCount: number }> {
|
|
71
|
+
async add(source: string, name: string, onProgress?: ProgressCallback, signal?: AbortSignal): Promise<{ kb: KnowledgeBase; chunkCount: number }> {
|
|
72
72
|
if (!this.db) throw new Error("Engine not initialized");
|
|
73
73
|
const resolvedSource = resolve(source);
|
|
74
74
|
const isUrl = source.startsWith("http://") || source.startsWith("https://");
|
|
@@ -120,7 +120,7 @@ export class KnowledgeEngine {
|
|
|
120
120
|
|
|
121
121
|
onProgress?.(`${allChunks.length} chunks, embedding...`);
|
|
122
122
|
const texts = allChunks.map((c) => c.content);
|
|
123
|
-
const vectors = await embedDocuments(texts);
|
|
123
|
+
const vectors = await embedDocuments(texts, signal);
|
|
124
124
|
|
|
125
125
|
onProgress?.(`Storing...`);
|
|
126
126
|
insertChunks(this.db, kb.id, allChunks);
|
|
@@ -141,7 +141,7 @@ export class KnowledgeEngine {
|
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
async update(nameOrId: string, onProgress?: ProgressCallback): Promise<{ added: number; removed: number; unchanged: number }> {
|
|
144
|
+
async update(nameOrId: string, onProgress?: ProgressCallback, signal?: AbortSignal): Promise<{ added: number; removed: number; unchanged: number }> {
|
|
145
145
|
if (!this.db) throw new Error("Engine not initialized");
|
|
146
146
|
const kb = getKB(this.db, nameOrId) ?? getKBByName(this.db, nameOrId);
|
|
147
147
|
if (!kb) throw new Error(`Knowledge base not found: ${nameOrId}`);
|
|
@@ -350,7 +350,7 @@ export class KnowledgeEngine {
|
|
|
350
350
|
return chunks.length;
|
|
351
351
|
}
|
|
352
352
|
|
|
353
|
-
async importKB(inputPath: string, onProgress?: ProgressCallback): Promise<{ kb: KnowledgeBase; chunkCount: number }> {
|
|
353
|
+
async importKB(inputPath: string, onProgress?: ProgressCallback, signal?: AbortSignal): Promise<{ kb: KnowledgeBase; chunkCount: number }> {
|
|
354
354
|
if (!this.db) throw new Error("Engine not initialized");
|
|
355
355
|
const { readFileSync } = await import("node:fs");
|
|
356
356
|
const lines = readFileSync(inputPath, "utf-8").trim().split("\n");
|
|
@@ -361,7 +361,7 @@ export class KnowledgeEngine {
|
|
|
361
361
|
const chunkData = lines.slice(1).map((l) => JSON.parse(l));
|
|
362
362
|
onProgress?.(`Importing ${chunkData.length} chunks, embedding...`);
|
|
363
363
|
const texts = chunkData.map((c: any) => c.content);
|
|
364
|
-
const vectors = await embedDocuments(texts);
|
|
364
|
+
const vectors = await embedDocuments(texts, signal);
|
|
365
365
|
const chunks = chunkData.map((c: any) => ({ content_hash: contentHash(c.content), content: c.content, content_tokenized: preTokenizeForFTS(c.content), file_path: c.file_path, file_type: c.file_type, start_line: c.start_line, end_line: c.end_line, metadata_json: c.metadata_json || "{}" }));
|
|
366
366
|
insertChunks(this.db, kb.id, chunks);
|
|
367
367
|
const vectorPath = join(this.knowledgeDir, "vectors", `${kb.id}.bin`);
|