Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/storage-rebuild-fts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@colony/storage': minor
'@imdeadpool/colony': patch
---

Add `Storage.rebuildFts()` so the CLI `reindex` command no longer
reaches through the type system to poke `better-sqlite3`. Behavior is
unchanged — `reindex` still runs the FTS5 `'rebuild'` statement — but
the public API is now typed and callers do not cast through `unknown`.
10 changes: 3 additions & 7 deletions apps/cli/src/commands/reindex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ export function registerReindexCommand(program: Command): void {
.action(async () => {
const settings = loadSettings();
const s = new Storage(join(resolveDataDir(settings.dataDir), 'data.db'));
// FTS5 rebuild pattern.
const db = (s as unknown as { db: { exec: (q: string) => void } }).db;
// Fallback to raw exec via better-sqlite3 if exposed; otherwise use public API to no-op.
try {
if (db?.exec) db.exec("INSERT INTO observations_fts(observations_fts) VALUES('rebuild');");
} catch {
// swallow — rebuild is best-effort
s.rebuildFts();
} finally {
s.close();
}
s.close();
process.stdout.write('reindex ok\n');
});
}
4 changes: 4 additions & 0 deletions packages/storage/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ export class Storage {
}));
}

rebuildFts(): void {
this.db.exec("INSERT INTO observations_fts(observations_fts) VALUES('rebuild');");
}

// --- embeddings ---

putEmbedding(observationId: number, model: string, vec: Float32Array): void {
Expand Down
20 changes: 20 additions & 0 deletions packages/storage/test/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,26 @@ describe('Storage', () => {
expect(hits[0]?.snippet).toContain('[auth]');
});

it('rebuildFts leaves FTS queryable', () => {
storage.createSession({
id: 'sfts',
ide: 'claude-code',
cwd: null,
started_at: Date.now(),
metadata: null,
});
storage.insertObservation({
session_id: 'sfts',
kind: 'note',
content: 'token bucket rate limiter',
compressed: true,
intensity: 'full',
});
expect(() => storage.rebuildFts()).not.toThrow();
const hits = storage.searchFts('bucket');
expect(hits.length).toBeGreaterThan(0);
});

it('stores and retrieves embeddings', () => {
storage.createSession({
id: 's2',
Expand Down
Loading