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,9 +1,10 @@
1
1
  import { type DiagnosticResult } from "./diagnostics/health.ts";
2
2
  import { createSkippedScanStats } from "./indexer/chunker.ts";
3
3
  import { type RankingDiagnostics } from "./search/ranking.ts";
4
- import { type KnowledgeBase } from "./storage/sqlite.ts";
4
+ import { type KnowledgeBase, type KnowledgeSymbol } from "./storage/sqlite.ts";
5
+ export type SearchMode = "auto" | "fast" | "semantic" | "hybrid" | "deep" | "adaptive" | "code" | "config" | "docs" | "errors" | "decision";
5
6
  export interface SearchOptions {
6
- mode?: "auto" | "fast" | "semantic" | "hybrid" | "deep" | "adaptive";
7
+ mode?: SearchMode;
7
8
  limit?: number;
8
9
  offset?: number;
9
10
  kb_id?: string;
@@ -23,6 +24,15 @@ export interface SearchResult {
23
24
  start_line: number;
24
25
  end_line: number;
25
26
  ranking?: RankingDiagnostics;
27
+ provenance?: {
28
+ chunk_id: string;
29
+ chunk_hash: string;
30
+ indexed_at: number;
31
+ source_mtime?: number;
32
+ stale: boolean;
33
+ match_reason: "bm25" | "vector" | "hybrid" | "rerank" | "symbol" | "adaptive";
34
+ source_chunk_ids?: string[];
35
+ };
26
36
  }
27
37
  export declare const CURRENT_EMBEDDING_MODEL = "multilingual-e5-small";
28
38
  export interface SearchResponse {
@@ -30,8 +40,8 @@ export interface SearchResponse {
30
40
  total_count: number;
31
41
  has_more: boolean;
32
42
  warnings?: string[];
33
- mode_used?: NonNullable<SearchOptions["mode"]>;
34
- retry_modes?: NonNullable<SearchOptions["mode"]>[];
43
+ mode_used?: SearchMode;
44
+ retry_modes?: SearchMode[];
35
45
  suggestions?: string[];
36
46
  }
37
47
  export type ProgressCallback = (msg: string) => void;
@@ -45,12 +55,44 @@ export interface DoctorIssue {
45
55
  kb_name?: string;
46
56
  message: string;
47
57
  action: string;
58
+ action_code?: "run_update" | "rebuild_kb" | "wait_for_indexing" | "review_skipped_scope" | "rebuild_vectors" | "check_source" | "none";
48
59
  }
49
60
  export interface DoctorReport {
50
61
  health_score: number;
51
62
  summary: string;
52
63
  issues: DoctorIssue[];
53
64
  diagnostics: DiagnosticResult[];
65
+ actions: Array<{
66
+ code: NonNullable<DoctorIssue["action_code"]>;
67
+ kb_name?: string;
68
+ target?: string;
69
+ description: string;
70
+ }>;
71
+ }
72
+ export interface SymbolSearchOptions {
73
+ kb_id?: string;
74
+ kind?: KnowledgeSymbol["kind"];
75
+ file_pattern?: string;
76
+ limit?: number;
77
+ offset?: number;
78
+ exact?: boolean;
79
+ }
80
+ export interface SymbolSearchResponse {
81
+ results: Array<{
82
+ name: string;
83
+ kind: KnowledgeSymbol["kind"];
84
+ file_path: string;
85
+ file_type: string;
86
+ kb_name: string;
87
+ start_line: number;
88
+ end_line: number;
89
+ signature?: string;
90
+ container_name?: string;
91
+ text: string;
92
+ indexed_at: number;
93
+ }>;
94
+ total_count: number;
95
+ has_more: boolean;
54
96
  }
55
97
  export interface IndexPlan {
56
98
  source_type: "file" | "directory" | "text" | "url";
@@ -62,28 +104,39 @@ export interface IndexPlan {
62
104
  export declare class KnowledgeEngine {
63
105
  private db;
64
106
  private knowledgeDir;
107
+ private activeUpdates;
108
+ private activeMutations;
109
+ private disposing;
110
+ private runExclusive;
65
111
  initialize(knowledgeDir: string): Promise<void>;
66
- plan(source: string, options?: AddOptions): IndexPlan;
112
+ private vectorPathFor;
113
+ private deleteVectorFile;
114
+ plan(source: string, options?: AddOptions, signal?: AbortSignal): IndexPlan;
67
115
  add(source: string, name: string, onProgress?: ProgressCallback, signal?: AbortSignal, options?: AddOptions): Promise<{
68
116
  kb: KnowledgeBase;
69
117
  chunkCount: number;
70
118
  }>;
119
+ private addUnlocked;
71
120
  update(nameOrId: string, onProgress?: ProgressCallback, signal?: AbortSignal): Promise<{
72
121
  added: number;
73
122
  removed: number;
74
123
  unchanged: number;
75
124
  }>;
76
- search(query: string, options?: SearchOptions): Promise<SearchResponse>;
125
+ private runUpdate;
126
+ search(query: string, options?: SearchOptions, signal?: AbortSignal): Promise<SearchResponse>;
77
127
  remove(nameOrId: string): boolean;
78
- list(): KnowledgeBase[];
128
+ list(signal?: AbortSignal): KnowledgeBase[];
79
129
  clear(): void;
80
- diagnose(): DiagnosticResult[];
81
- doctor(): DoctorReport;
82
- exportKB(nameOrId: string, outputPath: string): Promise<number>;
130
+ diagnose(signal?: AbortSignal): DiagnosticResult[];
131
+ symbolSearch(query: string, options?: SymbolSearchOptions, signal?: AbortSignal): SymbolSearchResponse;
132
+ doctor(signal?: AbortSignal): DoctorReport;
133
+ exportKB(nameOrId: string, outputPath: string, signal?: AbortSignal, onProgress?: ProgressCallback): Promise<number>;
134
+ private exportKBUnlocked;
83
135
  importKB(inputPath: string, onProgress?: ProgressCallback, signal?: AbortSignal): Promise<{
84
136
  kb: KnowledgeBase;
85
137
  chunkCount: number;
86
138
  }>;
139
+ private importKBUnlocked;
87
140
  dispose(options?: {
88
141
  disposeModels?: boolean;
89
142
  }): Promise<void>;