@pellux/goodvibes-sdk 0.37.1 → 0.38.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/dist/contracts/artifacts/operator-contract.json +1 -1
- package/dist/events/communication.d.ts +21 -1
- package/dist/events/communication.d.ts.map +1 -1
- package/dist/platform/agents/message-bus-core.d.ts +7 -0
- package/dist/platform/agents/message-bus-core.d.ts.map +1 -1
- package/dist/platform/agents/message-bus-core.js +2 -1
- package/dist/platform/agents/orchestrator-runner.d.ts +37 -1
- package/dist/platform/agents/orchestrator-runner.d.ts.map +1 -1
- package/dist/platform/agents/orchestrator-runner.js +158 -7
- package/dist/platform/agents/orchestrator.d.ts +40 -0
- package/dist/platform/agents/orchestrator.d.ts.map +1 -1
- package/dist/platform/agents/orchestrator.js +29 -0
- package/dist/platform/agents/turn-knowledge-injection.d.ts +107 -0
- package/dist/platform/agents/turn-knowledge-injection.d.ts.map +1 -0
- package/dist/platform/agents/turn-knowledge-injection.js +152 -0
- package/dist/platform/agents/wrfc-controller.d.ts +23 -0
- package/dist/platform/agents/wrfc-controller.d.ts.map +1 -1
- package/dist/platform/agents/wrfc-controller.js +55 -0
- package/dist/platform/config/manager.d.ts +9 -0
- package/dist/platform/config/manager.d.ts.map +1 -1
- package/dist/platform/config/manager.js +15 -0
- package/dist/platform/control-plane/approval-broker.d.ts +1 -0
- package/dist/platform/control-plane/approval-broker.d.ts.map +1 -1
- package/dist/platform/control-plane/approval-broker.js +2 -0
- package/dist/platform/core/adaptive-planner.d.ts +50 -0
- package/dist/platform/core/adaptive-planner.d.ts.map +1 -1
- package/dist/platform/core/adaptive-planner.js +49 -0
- package/dist/platform/core/index.d.ts +1 -0
- package/dist/platform/core/index.d.ts.map +1 -1
- package/dist/platform/core/index.js +1 -0
- package/dist/platform/core/orchestrator-runtime.d.ts +11 -0
- package/dist/platform/core/orchestrator-runtime.d.ts.map +1 -1
- package/dist/platform/core/orchestrator-turn-loop.d.ts +28 -1
- package/dist/platform/core/orchestrator-turn-loop.d.ts.map +1 -1
- package/dist/platform/core/orchestrator-turn-loop.js +115 -3
- package/dist/platform/core/orchestrator.d.ts +61 -0
- package/dist/platform/core/orchestrator.d.ts.map +1 -1
- package/dist/platform/core/orchestrator.js +74 -1
- package/dist/platform/core/plan-proposal.d.ts +165 -0
- package/dist/platform/core/plan-proposal.d.ts.map +1 -0
- package/dist/platform/core/plan-proposal.js +296 -0
- package/dist/platform/knowledge/knowledge-api.d.ts +26 -0
- package/dist/platform/knowledge/knowledge-api.d.ts.map +1 -1
- package/dist/platform/knowledge/knowledge-api.js +11 -0
- package/dist/platform/orchestration/budget.d.ts +22 -0
- package/dist/platform/orchestration/budget.d.ts.map +1 -0
- package/dist/platform/orchestration/budget.js +35 -0
- package/dist/platform/orchestration/cancellation.d.ts +31 -0
- package/dist/platform/orchestration/cancellation.d.ts.map +1 -0
- package/dist/platform/orchestration/cancellation.js +25 -0
- package/dist/platform/orchestration/controller-compat.d.ts +32 -0
- package/dist/platform/orchestration/controller-compat.d.ts.map +1 -0
- package/dist/platform/orchestration/controller-compat.js +13 -0
- package/dist/platform/orchestration/dirty-guard.d.ts +32 -0
- package/dist/platform/orchestration/dirty-guard.d.ts.map +1 -0
- package/dist/platform/orchestration/dirty-guard.js +147 -0
- package/dist/platform/orchestration/engine.d.ts +57 -0
- package/dist/platform/orchestration/engine.d.ts.map +1 -0
- package/dist/platform/orchestration/engine.js +418 -0
- package/dist/platform/orchestration/index.d.ts +18 -0
- package/dist/platform/orchestration/index.d.ts.map +1 -0
- package/dist/platform/orchestration/index.js +10 -0
- package/dist/platform/orchestration/persistence.d.ts +24 -0
- package/dist/platform/orchestration/persistence.d.ts.map +1 -0
- package/dist/platform/orchestration/persistence.js +176 -0
- package/dist/platform/orchestration/phase-runner.d.ts +87 -0
- package/dist/platform/orchestration/phase-runner.d.ts.map +1 -0
- package/dist/platform/orchestration/phase-runner.js +274 -0
- package/dist/platform/orchestration/scheduler.d.ts +45 -0
- package/dist/platform/orchestration/scheduler.d.ts.map +1 -0
- package/dist/platform/orchestration/scheduler.js +57 -0
- package/dist/platform/orchestration/types.d.ts +250 -0
- package/dist/platform/orchestration/types.d.ts.map +1 -0
- package/dist/platform/orchestration/types.js +15 -0
- package/dist/platform/runtime/emitters/communication.d.ts +11 -0
- package/dist/platform/runtime/emitters/communication.d.ts.map +1 -1
- package/dist/platform/runtime/emitters/communication.js +9 -0
- package/dist/platform/runtime/feature-flags/flags.d.ts.map +1 -1
- package/dist/platform/runtime/feature-flags/flags.js +17 -0
- package/dist/platform/runtime/fleet/adapters/agent.d.ts +56 -0
- package/dist/platform/runtime/fleet/adapters/agent.d.ts.map +1 -0
- package/dist/platform/runtime/fleet/adapters/agent.js +143 -0
- package/dist/platform/runtime/fleet/adapters/automation.d.ts +30 -0
- package/dist/platform/runtime/fleet/adapters/automation.d.ts.map +1 -0
- package/dist/platform/runtime/fleet/adapters/automation.js +41 -0
- package/dist/platform/runtime/fleet/adapters/background-process.d.ts +12 -0
- package/dist/platform/runtime/fleet/adapters/background-process.d.ts.map +1 -0
- package/dist/platform/runtime/fleet/adapters/background-process.js +46 -0
- package/dist/platform/runtime/fleet/adapters/code-index.d.ts +21 -0
- package/dist/platform/runtime/fleet/adapters/code-index.d.ts.map +1 -0
- package/dist/platform/runtime/fleet/adapters/code-index.js +44 -0
- package/dist/platform/runtime/fleet/adapters/orchestration.d.ts +47 -0
- package/dist/platform/runtime/fleet/adapters/orchestration.d.ts.map +1 -0
- package/dist/platform/runtime/fleet/adapters/orchestration.js +225 -0
- package/dist/platform/runtime/fleet/adapters/schedule.d.ts +14 -0
- package/dist/platform/runtime/fleet/adapters/schedule.d.ts.map +1 -0
- package/dist/platform/runtime/fleet/adapters/schedule.js +28 -0
- package/dist/platform/runtime/fleet/adapters/trigger.d.ts +12 -0
- package/dist/platform/runtime/fleet/adapters/trigger.d.ts.map +1 -0
- package/dist/platform/runtime/fleet/adapters/trigger.js +22 -0
- package/dist/platform/runtime/fleet/adapters/watcher.d.ts +13 -0
- package/dist/platform/runtime/fleet/adapters/watcher.d.ts.map +1 -0
- package/dist/platform/runtime/fleet/adapters/watcher.js +47 -0
- package/dist/platform/runtime/fleet/adapters/workflow.d.ts +11 -0
- package/dist/platform/runtime/fleet/adapters/workflow.d.ts.map +1 -0
- package/dist/platform/runtime/fleet/adapters/workflow.js +34 -0
- package/dist/platform/runtime/fleet/adapters/wrfc.d.ts +22 -0
- package/dist/platform/runtime/fleet/adapters/wrfc.d.ts.map +1 -0
- package/dist/platform/runtime/fleet/adapters/wrfc.js +228 -0
- package/dist/platform/runtime/fleet/index.d.ts +10 -0
- package/dist/platform/runtime/fleet/index.d.ts.map +1 -0
- package/dist/platform/runtime/fleet/index.js +6 -0
- package/dist/platform/runtime/fleet/registry.d.ts +113 -0
- package/dist/platform/runtime/fleet/registry.d.ts.map +1 -0
- package/dist/platform/runtime/fleet/registry.js +630 -0
- package/dist/platform/runtime/fleet/types.d.ts +199 -0
- package/dist/platform/runtime/fleet/types.d.ts.map +1 -0
- package/dist/platform/runtime/fleet/types.js +2 -0
- package/dist/platform/runtime/runtime-knowledge-api.d.ts +1 -1
- package/dist/platform/runtime/runtime-knowledge-api.d.ts.map +1 -1
- package/dist/platform/runtime/runtime-knowledge-api.js +1 -0
- package/dist/platform/runtime/services.d.ts +46 -0
- package/dist/platform/runtime/services.d.ts.map +1 -1
- package/dist/platform/runtime/services.js +78 -0
- package/dist/platform/state/code-index-chunking.d.ts +49 -0
- package/dist/platform/state/code-index-chunking.d.ts.map +1 -0
- package/dist/platform/state/code-index-chunking.js +111 -0
- package/dist/platform/state/code-index-db.d.ts +53 -0
- package/dist/platform/state/code-index-db.d.ts.map +1 -0
- package/dist/platform/state/code-index-db.js +101 -0
- package/dist/platform/state/code-index-store.d.ts +175 -0
- package/dist/platform/state/code-index-store.d.ts.map +1 -0
- package/dist/platform/state/code-index-store.js +612 -0
- package/dist/platform/state/index.d.ts +4 -2
- package/dist/platform/state/index.d.ts.map +1 -1
- package/dist/platform/state/index.js +2 -1
- package/dist/platform/state/knowledge-injection.d.ts +23 -0
- package/dist/platform/state/knowledge-injection.d.ts.map +1 -1
- package/dist/platform/state/knowledge-injection.js +34 -19
- package/dist/platform/state/memory-vector-store.d.ts +1 -13
- package/dist/platform/state/memory-vector-store.d.ts.map +1 -1
- package/dist/platform/state/memory-vector-store.js +6 -38
- package/dist/platform/state/sqlite-vec-loader.d.ts +25 -0
- package/dist/platform/state/sqlite-vec-loader.d.ts.map +1 -0
- package/dist/platform/state/sqlite-vec-loader.js +43 -0
- package/dist/platform/tools/agent/manager.d.ts +128 -1
- package/dist/platform/tools/agent/manager.d.ts.map +1 -1
- package/dist/platform/tools/agent/manager.js +137 -1
- package/dist/platform/tools/exec/runtime.d.ts.map +1 -1
- package/dist/platform/tools/exec/runtime.js +139 -44
- package/dist/platform/tools/exec/schema.d.ts +2 -0
- package/dist/platform/tools/exec/schema.d.ts.map +1 -1
- package/dist/platform/tools/fetch/runtime.d.ts +7 -0
- package/dist/platform/tools/fetch/runtime.d.ts.map +1 -1
- package/dist/platform/tools/fetch/runtime.js +8 -6
- package/dist/platform/tools/registry.d.ts +9 -3
- package/dist/platform/tools/registry.d.ts.map +1 -1
- package/dist/platform/tools/registry.js +9 -3
- package/dist/platform/types/tools.d.ts +14 -1
- package/dist/platform/types/tools.d.ts.map +1 -1
- package/dist/platform/version.js +1 -1
- package/dist/platform/workspace/checkpoint/side-git.d.ts +20 -8
- package/dist/platform/workspace/checkpoint/side-git.d.ts.map +1 -1
- package/dist/platform/workspace/checkpoint/side-git.js +21 -11
- package/package.json +17 -9
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** SDK-owned platform module. This implementation is maintained in goodvibes-sdk. */
|
|
2
|
+
/**
|
|
3
|
+
* Code-index SQL layer — schema plus every direct table operation for
|
|
4
|
+
* CodeIndexStore's bun:sqlite database (Wave-5, W5.3 Stage A; extracted from
|
|
5
|
+
* code-index-store.ts to keep that file within the 800-line source discipline).
|
|
6
|
+
*
|
|
7
|
+
* Three tables:
|
|
8
|
+
* - `code_chunks` chunk metadata (path/lang/symbol/kind/lines/hashes)
|
|
9
|
+
* - `code_vectors` vec0 virtual table keyed by rowid
|
|
10
|
+
* - `code_index_meta` key/value build provenance — currently the embedding
|
|
11
|
+
* provider id the index was last fully built with, so search() can refuse
|
|
12
|
+
* to compare query vectors from a different provider's space against the
|
|
13
|
+
* stored vectors (see CodeIndexStore.getProviderMismatch).
|
|
14
|
+
*
|
|
15
|
+
* Every function takes the Database handle explicitly — this module holds no
|
|
16
|
+
* state and never opens/closes connections; CodeIndexStore owns the lifecycle.
|
|
17
|
+
*/
|
|
18
|
+
import type { Database } from 'bun:sqlite';
|
|
19
|
+
import type { CodeChunk } from './code-index-chunking.js';
|
|
20
|
+
export type ChunkRow = {
|
|
21
|
+
rowid: number;
|
|
22
|
+
chunk_id: string;
|
|
23
|
+
path: string;
|
|
24
|
+
lang: string;
|
|
25
|
+
symbol: string;
|
|
26
|
+
kind: string;
|
|
27
|
+
start_line: number;
|
|
28
|
+
end_line: number;
|
|
29
|
+
content_hash: string;
|
|
30
|
+
mtime: number;
|
|
31
|
+
file_hash: string;
|
|
32
|
+
};
|
|
33
|
+
export type VectorRow = {
|
|
34
|
+
rowid: number;
|
|
35
|
+
chunk_id: string;
|
|
36
|
+
distance: number;
|
|
37
|
+
};
|
|
38
|
+
/** Meta key for the embedding provider id the index was last fully built with. */
|
|
39
|
+
export declare const EMBEDDING_PROVIDER_META_KEY = "embedding_provider_id";
|
|
40
|
+
export declare const CHUNK_ROW_COLUMNS = "rowid, chunk_id, path, lang, symbol, kind, start_line, end_line, content_hash, mtime, file_hash";
|
|
41
|
+
export declare function createCodeIndexSchema(db: Database): void;
|
|
42
|
+
export declare function getCodeIndexMeta(db: Database, key: string): string | null;
|
|
43
|
+
export declare function setCodeIndexMeta(db: Database, key: string, value: string): void;
|
|
44
|
+
export declare function writeChunk(db: Database, chunk: CodeChunk, embedding: Float32Array): void;
|
|
45
|
+
export declare function deleteChunksForPath(db: Database, relPath: string): void;
|
|
46
|
+
export declare function getFileHash(db: Database, relPath: string): string | null;
|
|
47
|
+
export declare function getChunkById(db: Database, chunkId: string): CodeChunk | null;
|
|
48
|
+
export declare function countChunksForPath(db: Database, relPath: string): number;
|
|
49
|
+
export declare function countIndexedFiles(db: Database): number;
|
|
50
|
+
export declare function countIndexedChunks(db: Database): number;
|
|
51
|
+
export declare function listIndexedPaths(db: Database): string[];
|
|
52
|
+
export declare function rowToChunk(row: ChunkRow): CodeChunk;
|
|
53
|
+
//# sourceMappingURL=code-index-db.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-index-db.d.ts","sourceRoot":"","sources":["../../../src/platform/state/code-index-db.ts"],"names":[],"mappings":"AAAA,qFAAqF;AAErF;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAE1D,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,kFAAkF;AAClF,eAAO,MAAM,2BAA2B,0BAA0B,CAAC;AAEnE,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for the embedding provider id the index was last fully built with. */
|
|
4
|
+
export const EMBEDDING_PROVIDER_META_KEY = 'embedding_provider_id';
|
|
5
|
+
export const CHUNK_ROW_COLUMNS = 'rowid, chunk_id, path, lang, symbol, kind, start_line, end_line, content_hash, mtime, file_hash';
|
|
6
|
+
export function createCodeIndexSchema(db) {
|
|
7
|
+
db.run(`
|
|
8
|
+
CREATE TABLE IF NOT EXISTS code_chunks (
|
|
9
|
+
rowid INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
10
|
+
chunk_id TEXT NOT NULL UNIQUE,
|
|
11
|
+
path TEXT NOT NULL,
|
|
12
|
+
lang TEXT NOT NULL,
|
|
13
|
+
symbol TEXT NOT NULL DEFAULT '',
|
|
14
|
+
kind TEXT NOT NULL DEFAULT '',
|
|
15
|
+
start_line INTEGER NOT NULL,
|
|
16
|
+
end_line INTEGER NOT NULL,
|
|
17
|
+
content_hash TEXT NOT NULL,
|
|
18
|
+
mtime INTEGER NOT NULL,
|
|
19
|
+
file_hash TEXT NOT NULL
|
|
20
|
+
)
|
|
21
|
+
`);
|
|
22
|
+
db.run('CREATE INDEX IF NOT EXISTS code_chunks_path_idx ON code_chunks(path)');
|
|
23
|
+
db.run(`
|
|
24
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS code_vectors USING vec0(
|
|
25
|
+
embedding float[${MEMORY_VECTOR_DIMS}],
|
|
26
|
+
+chunk_id text
|
|
27
|
+
)
|
|
28
|
+
`);
|
|
29
|
+
db.run(`
|
|
30
|
+
CREATE TABLE IF NOT EXISTS code_index_meta (
|
|
31
|
+
key TEXT PRIMARY KEY,
|
|
32
|
+
value TEXT NOT NULL
|
|
33
|
+
)
|
|
34
|
+
`);
|
|
35
|
+
}
|
|
36
|
+
export function getCodeIndexMeta(db, key) {
|
|
37
|
+
const row = db.query('SELECT value FROM code_index_meta WHERE key = ? LIMIT 1').get(key);
|
|
38
|
+
return row?.value ?? null;
|
|
39
|
+
}
|
|
40
|
+
export function setCodeIndexMeta(db, key, value) {
|
|
41
|
+
db.query('INSERT INTO code_index_meta (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value').run(key, value);
|
|
42
|
+
}
|
|
43
|
+
function ensureChunkRowId(db, chunk) {
|
|
44
|
+
db.query(`INSERT OR IGNORE INTO code_chunks
|
|
45
|
+
(chunk_id, path, lang, symbol, kind, start_line, end_line, content_hash, mtime, file_hash)
|
|
46
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(chunk.chunkId, chunk.path, chunk.lang, chunk.symbol, chunk.kind, chunk.startLine, chunk.endLine, chunk.contentHash, chunk.mtimeMs, chunk.fileHash);
|
|
47
|
+
const row = db.query('SELECT rowid FROM code_chunks WHERE chunk_id = ? LIMIT 1').get(chunk.chunkId);
|
|
48
|
+
if (!row)
|
|
49
|
+
throw new Error(`Code index row id not found for ${chunk.chunkId}`);
|
|
50
|
+
return Number(row.rowid);
|
|
51
|
+
}
|
|
52
|
+
export function writeChunk(db, chunk, embedding) {
|
|
53
|
+
const rowid = ensureChunkRowId(db, chunk);
|
|
54
|
+
db.query('DELETE FROM code_vectors WHERE rowid = ?').run(rowid);
|
|
55
|
+
db.query('INSERT INTO code_vectors (rowid, embedding, chunk_id) VALUES (?, ?, ?)').run(rowid, embedding, chunk.chunkId);
|
|
56
|
+
}
|
|
57
|
+
export function deleteChunksForPath(db, relPath) {
|
|
58
|
+
const rows = db.query('SELECT rowid FROM code_chunks WHERE path = ?').all(relPath);
|
|
59
|
+
for (const row of rows) {
|
|
60
|
+
db.query('DELETE FROM code_vectors WHERE rowid = ?').run(row.rowid);
|
|
61
|
+
}
|
|
62
|
+
db.query('DELETE FROM code_chunks WHERE path = ?').run(relPath);
|
|
63
|
+
}
|
|
64
|
+
export function getFileHash(db, relPath) {
|
|
65
|
+
const row = db.query('SELECT file_hash FROM code_chunks WHERE path = ? LIMIT 1').get(relPath);
|
|
66
|
+
return row?.file_hash ?? null;
|
|
67
|
+
}
|
|
68
|
+
export function getChunkById(db, chunkId) {
|
|
69
|
+
const row = db.query(`SELECT ${CHUNK_ROW_COLUMNS} FROM code_chunks WHERE chunk_id = ? LIMIT 1`).get(chunkId);
|
|
70
|
+
return row ? rowToChunk(row) : null;
|
|
71
|
+
}
|
|
72
|
+
export function countChunksForPath(db, relPath) {
|
|
73
|
+
const row = db.query('SELECT count(*) AS count FROM code_chunks WHERE path = ?').get(relPath);
|
|
74
|
+
return Number(row?.count ?? 0);
|
|
75
|
+
}
|
|
76
|
+
export function countIndexedFiles(db) {
|
|
77
|
+
const row = db.query('SELECT count(DISTINCT path) AS count FROM code_chunks').get();
|
|
78
|
+
return Number(row?.count ?? 0);
|
|
79
|
+
}
|
|
80
|
+
export function countIndexedChunks(db) {
|
|
81
|
+
const row = db.query('SELECT count(*) AS count FROM code_chunks').get();
|
|
82
|
+
return Number(row?.count ?? 0);
|
|
83
|
+
}
|
|
84
|
+
export function listIndexedPaths(db) {
|
|
85
|
+
const rows = db.query('SELECT DISTINCT path FROM code_chunks').all();
|
|
86
|
+
return rows.map((row) => row.path);
|
|
87
|
+
}
|
|
88
|
+
export function rowToChunk(row) {
|
|
89
|
+
return {
|
|
90
|
+
chunkId: row.chunk_id,
|
|
91
|
+
path: row.path,
|
|
92
|
+
lang: row.lang,
|
|
93
|
+
symbol: row.symbol,
|
|
94
|
+
kind: row.kind,
|
|
95
|
+
startLine: Number(row.start_line),
|
|
96
|
+
endLine: Number(row.end_line),
|
|
97
|
+
contentHash: row.content_hash,
|
|
98
|
+
mtimeMs: Number(row.mtime),
|
|
99
|
+
fileHash: row.file_hash,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/** SDK-owned platform module. This implementation is maintained in goodvibes-sdk. */
|
|
2
|
+
import { MemoryEmbeddingProviderRegistry } from './memory-embeddings.js';
|
|
3
|
+
import { type CodeChunk, type CodeChunkMode } from './code-index-chunking.js';
|
|
4
|
+
export type { CodeChunk, CodeChunkMode } from './code-index-chunking.js';
|
|
5
|
+
/** Honest per-build skip/degrade counters — every excluded or fallback file is counted, never silently dropped. */
|
|
6
|
+
export interface CodeIndexSkipReport {
|
|
7
|
+
readonly tooLarge: number;
|
|
8
|
+
/** Files skipped because the per-build file-count bound (maxFiles) was already reached. */
|
|
9
|
+
readonly overFileCap: number;
|
|
10
|
+
/** Files skipped because accepting them would exceed the per-build cumulative byte budget (maxTotalBytes). */
|
|
11
|
+
readonly overTotalBytes: number;
|
|
12
|
+
readonly binary: number;
|
|
13
|
+
readonly ignoredByGitignore: number;
|
|
14
|
+
readonly readErrors: number;
|
|
15
|
+
readonly chunkedByWindow: number;
|
|
16
|
+
}
|
|
17
|
+
export interface CodeIndexBuildStats {
|
|
18
|
+
readonly filesScanned: number;
|
|
19
|
+
readonly filesIndexed: number;
|
|
20
|
+
readonly filesUnchanged: number;
|
|
21
|
+
/** Chunks embedded and written by THIS build (changed/new files only — unchanged files' pre-existing chunks are counted separately). */
|
|
22
|
+
readonly chunksIndexed: number;
|
|
23
|
+
/** Pre-existing chunks belonging to files this build found unchanged (no re-chunk, no re-embed). */
|
|
24
|
+
readonly chunksUnchanged: number;
|
|
25
|
+
readonly filesRemoved: number;
|
|
26
|
+
readonly skip: CodeIndexSkipReport;
|
|
27
|
+
readonly startedAt: number;
|
|
28
|
+
readonly completedAt: number;
|
|
29
|
+
readonly durationMs: number;
|
|
30
|
+
/** Present exactly when the build was aborted (reroot()/close() during the walk) — partial results were discarded, not recorded as lastBuild. */
|
|
31
|
+
readonly abortReason?: string | undefined;
|
|
32
|
+
}
|
|
33
|
+
export interface CodeIndexBuildProgress {
|
|
34
|
+
readonly scanned: number;
|
|
35
|
+
readonly total: number;
|
|
36
|
+
}
|
|
37
|
+
export interface CodeIndexStats {
|
|
38
|
+
readonly backend: 'sqlite-vec';
|
|
39
|
+
readonly enabled: boolean;
|
|
40
|
+
readonly available: boolean;
|
|
41
|
+
readonly path: string;
|
|
42
|
+
readonly dimensions: number;
|
|
43
|
+
readonly indexedFiles: number;
|
|
44
|
+
readonly indexedChunks: number;
|
|
45
|
+
readonly embeddingProviderId: string;
|
|
46
|
+
readonly embeddingProviderLabel: string;
|
|
47
|
+
/** False when the only active provider is the deterministic hashed one — semantic retrieval is a weak lexical-ish signal in that mode. */
|
|
48
|
+
readonly semanticRetrievalAvailable: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Present exactly when the stored vectors were embedded under a DIFFERENT
|
|
51
|
+
* provider than the current default — the vector search path is disabled
|
|
52
|
+
* (lexical fallback only) until a rebuild re-embeds. Human-readable, e.g.
|
|
53
|
+
* "embeddings built with X, current provider Y — rebuild to re-embed".
|
|
54
|
+
*/
|
|
55
|
+
readonly embeddingProviderMismatch?: string | undefined;
|
|
56
|
+
readonly building: boolean;
|
|
57
|
+
readonly lastBuild: CodeIndexBuildStats | null;
|
|
58
|
+
readonly error?: string | undefined;
|
|
59
|
+
}
|
|
60
|
+
/** A single search hit: the matched chunk plus its distance/similarity and an honest retrieval-quality label. */
|
|
61
|
+
export interface CodeContextResult {
|
|
62
|
+
readonly chunk: CodeChunk;
|
|
63
|
+
readonly distance: number;
|
|
64
|
+
readonly similarity: number;
|
|
65
|
+
/** 'lexical' when the hit did not come from a true semantic vector match: the hashed fallback provider is active, or a provider mismatch disabled the vector path. */
|
|
66
|
+
readonly label: 'semantic' | 'lexical';
|
|
67
|
+
}
|
|
68
|
+
export interface CodeIndexOptions {
|
|
69
|
+
/** Maximum number of files walked per build. Default 5000. */
|
|
70
|
+
readonly maxFiles?: number | undefined;
|
|
71
|
+
/** Files larger than this are skipped and counted as `tooLarge`. Default 512KB. */
|
|
72
|
+
readonly maxFileBytes?: number | undefined;
|
|
73
|
+
/** Cumulative byte budget for one build; once exceeded, remaining files count as `overTotalBytes`. Default 256MB. */
|
|
74
|
+
readonly maxTotalBytes?: number | undefined;
|
|
75
|
+
/** Fallback window size (lines) for unsupported/parse-failed/symbol-less files. Default 60. */
|
|
76
|
+
readonly windowLines?: number | undefined;
|
|
77
|
+
/** Overlap (lines) between consecutive fallback windows. Default 10. */
|
|
78
|
+
readonly windowOverlapLines?: number | undefined;
|
|
79
|
+
}
|
|
80
|
+
export declare class CodeIndexStore {
|
|
81
|
+
private readonly embeddingRegistry;
|
|
82
|
+
private readonly options;
|
|
83
|
+
private db;
|
|
84
|
+
private available;
|
|
85
|
+
private error;
|
|
86
|
+
private building;
|
|
87
|
+
private buildStartedAtMs;
|
|
88
|
+
private buildPromise;
|
|
89
|
+
private lastBuild;
|
|
90
|
+
private progress;
|
|
91
|
+
private readonly intelligence;
|
|
92
|
+
private intelligenceReadyPromise;
|
|
93
|
+
/**
|
|
94
|
+
* Lifecycle generation counter. Bumped by reroot() and close(); an in-flight
|
|
95
|
+
* runBuild() captures the value at start and re-checks it after EVERY await,
|
|
96
|
+
* aborting cleanly when stale so a build started against one root can never
|
|
97
|
+
* write wrong-rooted chunks into a database opened for a different root.
|
|
98
|
+
*/
|
|
99
|
+
private epoch;
|
|
100
|
+
private rootDir;
|
|
101
|
+
private dbPath;
|
|
102
|
+
constructor(rootDir: string, dbPath: string, embeddingRegistry: MemoryEmbeddingProviderRegistry, options?: CodeIndexOptions);
|
|
103
|
+
init(): void;
|
|
104
|
+
close(): void;
|
|
105
|
+
/**
|
|
106
|
+
* Re-root the store to a new working directory + db path (workspace swap).
|
|
107
|
+
* Bumps the build epoch (aborting any in-flight build at its next await),
|
|
108
|
+
* closes existing handles, reopens at the new path, and clears in-memory
|
|
109
|
+
* build state. Does NOT re-trigger a build — the caller decides when to
|
|
110
|
+
* call scheduleBuild()/buildFull() again, exactly as it decided to open the
|
|
111
|
+
* store originally.
|
|
112
|
+
*/
|
|
113
|
+
reroot(newRootDir: string, newDbPath: string): Promise<void>;
|
|
114
|
+
isBuilding(): boolean;
|
|
115
|
+
buildProgress(): CodeIndexBuildProgress | null;
|
|
116
|
+
/** Wall-clock start time of the in-flight build, or null when idle. */
|
|
117
|
+
buildStartedAt(): number | null;
|
|
118
|
+
/** True unless the only active embedding provider is the deterministic hashed fallback. */
|
|
119
|
+
hasSemanticProvider(): boolean;
|
|
120
|
+
/** Stated once, honest: why Stage-B auto-retrieval (a later wave) would be absent right now. Null when a real provider is active. */
|
|
121
|
+
describeDegradation(): string | null;
|
|
122
|
+
/**
|
|
123
|
+
* Human-readable provider-space mismatch, or null when the stored vectors
|
|
124
|
+
* were built with the current default provider (or provenance is unknown —
|
|
125
|
+
* an index that predates provenance tracking keeps its legacy behavior
|
|
126
|
+
* until the next build stamps it).
|
|
127
|
+
*/
|
|
128
|
+
getProviderMismatch(): string | null;
|
|
129
|
+
stats(): CodeIndexStats;
|
|
130
|
+
search(query: string, opts?: {
|
|
131
|
+
limit?: number;
|
|
132
|
+
}): CodeContextResult[];
|
|
133
|
+
/**
|
|
134
|
+
* Lexical fallback used when the vector path is disabled by a provider
|
|
135
|
+
* mismatch: token match over chunk symbol/path metadata (chunk text is not
|
|
136
|
+
* stored, so this is name/path matching only — labeled 'lexical', never
|
|
137
|
+
* 'semantic'). Similarity is the matched-token fraction.
|
|
138
|
+
*/
|
|
139
|
+
private searchLexical;
|
|
140
|
+
/** Fire-and-forget kickoff; concurrent/repeated calls while a build is running are no-ops. Never awaited by the caller — never blocks a turn. */
|
|
141
|
+
scheduleBuild(): void;
|
|
142
|
+
/** Full source-tree walk. Concurrent calls coalesce onto the same in-flight promise (mirrors MemoryStore.rebuildVectorIndexAsync). */
|
|
143
|
+
buildFull(): Promise<CodeIndexBuildStats>;
|
|
144
|
+
/**
|
|
145
|
+
* Reindex a single file on demand. Intended to be called from the file
|
|
146
|
+
* read/write tool paths and from an explicit reindex command — wiring
|
|
147
|
+
* those call sites is out of scope for this module (see module doc).
|
|
148
|
+
* A no-op (chunks removed) if the path is gitignored or no longer exists.
|
|
149
|
+
*/
|
|
150
|
+
reindexFile(absPath: string): Promise<{
|
|
151
|
+
indexed: boolean;
|
|
152
|
+
mode: CodeChunkMode;
|
|
153
|
+
}>;
|
|
154
|
+
private runBuild;
|
|
155
|
+
/**
|
|
156
|
+
* Compose the root .gitignore with any nested .gitignore files (each nested
|
|
157
|
+
* file's patterns apply relative to its own directory, per git semantics).
|
|
158
|
+
* Nested coverage is bounded by findNestedGitignoreFiles' cap (see module doc).
|
|
159
|
+
*/
|
|
160
|
+
private buildIgnoreMatcher;
|
|
161
|
+
/**
|
|
162
|
+
* Index one file's content. Short-circuits on an unchanged file_hash (no
|
|
163
|
+
* re-chunk, no re-embed) — the "content_hash stable across re-index of
|
|
164
|
+
* unchanged file" contract — unless forceReembed is set (provider mismatch).
|
|
165
|
+
*
|
|
166
|
+
* Epoch honesty: all of a file's chunks are embedded (every await) BEFORE
|
|
167
|
+
* any row is deleted or written, and the epoch is re-checked after each
|
|
168
|
+
* await — so a reroot() mid-file aborts with the database untouched for
|
|
169
|
+
* that file (returns null; the caller abandons the build).
|
|
170
|
+
*/
|
|
171
|
+
private indexFileContent;
|
|
172
|
+
private ensureIntelligenceReady;
|
|
173
|
+
private embedChunkAsync;
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=code-index-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-index-store.d.ts","sourceRoot":"","sources":["../../../src/platform/state/code-index-store.ts"],"names":[],"mappings":"AAAA,qFAAqF;AA4DrF,OAAO,EAEL,+BAA+B,EAEhC,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAGL,KAAK,SAAS,EACd,KAAK,aAAa,EACnB,MAAM,0BAA0B,CAAC;AA+BlC,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAMzE,mHAAmH;AACnH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,2FAA2F;IAC3F,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,8GAA8G;IAC9G,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,MAA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