pi-knowledge 0.4.6 → 0.5.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.
@@ -1,5 +1,5 @@
1
- import { existsSync, readdirSync, statSync, watch } from "node:fs";
2
- import { join } from "node:path";
1
+ import { existsSync, statSync, watch } from "node:fs";
2
+ import { createSkippedScanStats, iterateScannableFiles } from "../indexer/chunker.js";
3
3
  const watchers = new Map();
4
4
  const pollers = new Map();
5
5
  const snapshots = new Map();
@@ -15,34 +15,20 @@ function scheduleUpdate(kbId, onUpdate) {
15
15
  onUpdate(kbId);
16
16
  }, DEBOUNCE_MS));
17
17
  }
18
- function scanSnapshot(dirPath) {
18
+ function scanSnapshot(dirPath, options = {}) {
19
19
  const snapshot = new Map();
20
- function scan(dir) {
21
- let entries;
20
+ if (!existsSync(dirPath))
21
+ return snapshot;
22
+ const skipped = createSkippedScanStats();
23
+ for (const file of iterateScannableFiles(dirPath, skipped, options)) {
22
24
  try {
23
- entries = readdirSync(dir, { withFileTypes: true });
25
+ const stat = statSync(file.path);
26
+ snapshot.set(file.path, `${stat.mtimeMs}:${stat.size}`);
24
27
  }
25
28
  catch {
26
- return;
27
- }
28
- for (const entry of entries) {
29
- const fullPath = join(dir, entry.name);
30
- try {
31
- const stat = statSync(fullPath);
32
- if (entry.isDirectory()) {
33
- scan(fullPath);
34
- }
35
- else if (entry.isFile()) {
36
- snapshot.set(fullPath, `${stat.mtimeMs}:${stat.size}`);
37
- }
38
- }
39
- catch {
40
- /* file disappeared or is unreadable */
41
- }
29
+ /* file disappeared or is unreadable */
42
30
  }
43
31
  }
44
- if (existsSync(dirPath))
45
- scan(dirPath);
46
32
  return snapshot;
47
33
  }
48
34
  function snapshotsDiffer(a, b) {
@@ -54,23 +40,27 @@ function snapshotsDiffer(a, b) {
54
40
  }
55
41
  return false;
56
42
  }
57
- function startPoller(kbId, dirPath, onUpdate) {
58
- snapshots.set(kbId, scanSnapshot(dirPath));
43
+ function startPoller(kbId, dirPath, onUpdate, options = {}) {
44
+ snapshots.set(kbId, scanSnapshot(dirPath, options));
59
45
  pollers.set(kbId, setInterval(() => {
60
46
  const previous = snapshots.get(kbId) ?? new Map();
61
- const next = scanSnapshot(dirPath);
47
+ const next = scanSnapshot(dirPath, options);
62
48
  if (snapshotsDiffer(previous, next)) {
63
49
  snapshots.set(kbId, next);
64
50
  scheduleUpdate(kbId, onUpdate);
65
51
  }
66
52
  }, POLL_MS));
67
53
  }
68
- export function startWatcher(kbId, dirPath, onUpdate) {
54
+ export function startWatcher(kbId, dirPath, onUpdate, options = {}) {
69
55
  stopWatcher(kbId);
70
- startPoller(kbId, dirPath, onUpdate);
56
+ startPoller(kbId, dirPath, onUpdate, options);
71
57
  try {
72
58
  const watcher = watch(dirPath, { recursive: true }, () => {
73
- snapshots.set(kbId, scanSnapshot(dirPath));
59
+ const previous = snapshots.get(kbId) ?? new Map();
60
+ const next = scanSnapshot(dirPath, options);
61
+ if (!snapshotsDiffer(previous, next))
62
+ return;
63
+ snapshots.set(kbId, next);
74
64
  scheduleUpdate(kbId, onUpdate);
75
65
  });
76
66
  watcher.on("error", () => {
@@ -26,8 +26,8 @@ Default data storage is `~/.pi/knowledge` under Pi and `~/.omp/knowledge` under
26
26
  | `OPENAI_BASE_URL` | `https://api.openai.com/v1` | Common OpenAI-compatible API root fallback. |
27
27
  | `PI_KNOWLEDGE_EMBEDDING_MAX_CHARS` | `20000` | Final per-input API embedding safety cap for OpenAI-compatible servers with smaller context windows. This does not replace chunker bounds. |
28
28
  | `PI_KNOWLEDGE_EMBEDDING_API_FALLBACK` | unset | Set to `local` to explicitly fall back to local embeddings after API failures. Without this, API failures are surfaced. |
29
- | `PI_KNOWLEDGE_ENABLE_NATIVE_IDLE_DISPOSE` | unset | Set to `true` to opt into native ONNX idle disposal. Disabled by default for stable shutdown. |
30
- | `PI_KNOWLEDGE_EMBEDDING_IDLE_MS` | `30000` | Idle-dispose timer used only when native idle disposal is enabled. Mainly for lifecycle stress tests. |
29
+ | `PI_KNOWLEDGE_ENABLE_NATIVE_IDLE_DISPOSE` | unset | Enables idle timers for embedding/reranker run coordination. It does not guarantee immediate worker memory release; model-worker shutdown remains tied to engine/session shutdown. Disabled by default for stable shutdown. |
30
+ | `PI_KNOWLEDGE_EMBEDDING_IDLE_MS` | `30000` | Idle timer used only when native idle disposal coordination is enabled. Mainly for lifecycle stress tests. |
31
31
  | `PI_KNOWLEDGE_OFFLINE` | unset | Use with a pre-populated model cache for offline local model operation. See `docs/offline-mode.md`. |
32
32
 
33
33
  API embedding failures intentionally surface by default. Silent fallback can hide bad API keys, wrong base URLs, unsupported model names, or context-window errors and can produce a KB with a different embedding model than intended.
@@ -40,6 +40,12 @@ API embedding failures intentionally surface by default. Silent fallback can hid
40
40
  | `PI_KNOWLEDGE_AUTO_INJECT` | unset | Set to `true` to auto-search KB context before model calls. This is opt-in. |
41
41
  | `PI_KNOWLEDGE_STALE_INDEXING_MS` | built-in stale threshold | Override the stale indexing threshold used by diagnostics and `knowledge_doctor`. |
42
42
 
43
+ Search diagnostics include result provenance in both text output and structured `details`: chunk id, chunk hash, match reason, indexed timestamp, stale flag, and source mtime when the original source file is available. This provenance is stored in SQLite and derived from indexed source metadata; it does not create or modify files in the indexed project.
44
+
45
+ `knowledge_doctor` emits both human-readable issues and machine-readable actions in structured `details`. Action codes include `run_update`, `rebuild_kb`, `wait_for_indexing`, `review_skipped_scope`, `rebuild_vectors`, `check_source`, and `none`. Agents should prefer these action codes over parsing the English action text.
46
+
47
+ `knowledge_symbol_search` uses a lightweight symbol index stored in `knowledge.db`. It is rebuilt during `knowledge_add`, `knowledge_update`, and `knowledge_import`, and can find code symbols, route-like handlers, Markdown headings, config keys, and environment variables. Older file/directory/URL KBs without symbol metadata should be updated before relying on symbol lookup. Imported portable KBs and inline text KBs do not retain an active source path; rebuild their symbols by re-importing or re-adding the content.
48
+
43
49
  ## Test and Release Fixtures
44
50
 
45
51
  | Variable | Default | Purpose |
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-knowledge",
3
- "version": "0.4.6",
4
- "description": "Local-first RAG knowledge base for Pi agents with hybrid code/doc search, reranking, diagnostics, and large-project indexing",
3
+ "version": "0.5.0",
4
+ "description": "Local-first RAG knowledge base for Pi and OMP coding agents with hybrid code/doc search, reranking, diagnostics, and large-project indexing",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -24,6 +24,8 @@
24
24
  "pi-package",
25
25
  "pi",
26
26
  "pi-extension",
27
+ "omp",
28
+ "omp-sh",
27
29
  "ai-agent",
28
30
  "coding-agent",
29
31
  "knowledge-base",