Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.
JavaScript agent-collaborationagent-harnessagent-orchestrationagent-teamagent-workflowai-assistantai-automationai-employeeai-productivityai-teamai-workflowautonomous-agentsclaude-code-guiclaude-coworkdesktop-agentlocal-firstmulti-agentmulti-agent-systemself-evolving-agentstask-automation
Read both 'text' and 'content' message shapes in chat search indexer; bump schema to force rebuild
wytf1d908b85170
diff --git a/src/main/features/search/index.ts b/src/main/features/search/index.tsindex 5da78889..6d910896 100644--- a/src/main/features/search/index.ts+++ b/src/main/features/search/index.ts@@ -223,7 +223,7 @@ export async function searchChats(userId: string, query: string): Promise<Searchconv_title: titles[String(doc.cid)] || t('chat.default_title'),role: doc.role,time: doc.time,- snippet: _makeSnippet(msg && typeof msg.content === 'string' ? msg.content : '', q),+ snippet: _makeSnippet(indexer.readMsgText(msg as any), q),score,};});diff --git a/src/main/features/search/indexer.ts b/src/main/features/search/indexer.tsindex 93135cae..4d48bc0a 100644--- a/src/main/features/search/indexer.ts+++ b/src/main/features/search/indexer.ts@@ -55,10 +55,28 @@ interface ChatFileInfo {size: number;}+// Persisted chat message can take two shapes:+// - **Legacy single-actor**: `{ role, content, time }` (pre-bus refactor;+// still on disk in older conversations).+// - **Group chat (current)**: `{ id, ts, from, to, mentions, text, ... }`+// — the `GroupMessage` shape persisted by `features/group_chat/visibility.ts`+// since the bus rewrite. Field names differ (`text` ↔ `content`,+// `from` ↔ `role`, `ts` ↔ `time`).+//+// `_msgText` / `_msgRole` / `_msgTime` read whichever pair is present so the+// index covers both old and new conversations. Without this fallback the+// new-format jsonl reads `content === undefined` → `_reindexChatFile`+// skips every message → user reports "conversation messages can't be+// searched" (only old conversations would still surface).interface ChatMessage {+ // Legacy fieldsrole?: string;time?: string;content?: unknown;+ // Group-chat fields (current persistence format)+ from?: string;+ ts?: string;+ text?: unknown;}// ── In-memory state ──────────────────────────────────────────────────────@@ -187,9 +205,28 @@ async function _readJsonl(file: string): Promise<ChatMessage[]> {}function _msgText(msg: ChatMessage | null | undefined): string {- return (msg && typeof msg.content === 'string') ? msg.content : '';+ if (!msg) return '';+ // Group-chat shape (current) wins when present; legacy `content` is the+ // fallback for older jsonl that predates the bus refactor.+ if (typeof msg.text === 'string') return msg.text;+ if (typeof msg.content === 'string') return msg.content;+ return '';}+function _msgRole(msg: ChatMessage | null | undefined): string {+ if (!msg) return '';+ return msg.from || msg.role || '';+}++function _msgTime(msg: ChatMessage | null | undefined): string {+ if (!msg) return '';+ return msg.ts || msg.time || '';+}++// Exported so `search/index.ts::searchChats` can use the same field-shape+// fallback when extracting the snippet from the live jsonl record.+export { _msgText as readMsgText };+// ── Contexts (shared knowledge base) ─────────────────────────────────────// Content is NOT indexed — only the relPath (directory segments + filename)// is tokenized. Full-text content lookup goes through the vector KB@@ -323,7 +360,7 @@ async function _reindexChatFile(if (!text) return;const doc: Doc = {fileKey, kind: 'chat', msg_index: i, cid: fileKey,- role: m.role || '', time: m.time || '', len: text.length,+ role: _msgRole(m), time: _msgTime(m), len: text.length,};_putDoc(idx, _docId('chat', fileKey, i), doc, text);});@@ -375,7 +412,7 @@ async function _upsertChatMessageDoc(const entry = await _getEntry(idxPath, 'chat');const doc: Doc = {fileKey, kind: 'chat', msg_index: msgIndex, cid: fileKey,- role: msg.role || '', time: msg.time || '', len: text.length,+ role: _msgRole(msg), time: _msgTime(msg), len: text.length,};_putDoc(entry.idx, _docId('chat', fileKey, msgIndex), doc, text);if (st) entry.idx.files[fileKey] = { mtime: st.mtimeMs, size: st.size };diff --git a/src/main/features/search/storage.ts b/src/main/features/search/storage.tsindex fad4127c..ce32a336 100644--- a/src/main/features/search/storage.ts+++ b/src/main/features/search/storage.ts@@ -27,7 +27,14 @@ const fsp = fs.promises;// relPath (directory + filename) only; content lookup goes through the// vector KB. Bumping the version forces old body-tokenized indexes to// rebuild on next reconcile.-export const SCHEMA_VERSION = 3;+// v4 fixes the chat indexer's silent skip on group-chat jsonl — `_msgText`+// only read the legacy `content` field, missing the current `text` field+// (and `from`/`ts` for role/time). Indexes built by v3 against post-bus+// jsonl have empty docs (every message skipped); bumping forces a rebuild+// so existing users get their chat history searchable again on next launch+// (the alternative — leaving v3 — would only fix newly-modified jsonl files+// because reconcile keys off mtime+size, not schema correctness).+export const SCHEMA_VERSION = 4;export type IndexKind = 'context' | 'chat';diff --git a/test/main/features/search/index.test.ts b/test/main/features/search/index.test.tsindex 8eed1704..52d60fe7 100644--- a/test/main/features/search/index.test.ts+++ b/test/main/features/search/index.test.ts@@ -120,6 +120,28 @@ describe('search › searchContexts', () => {});});+describe('search › searchChats — group-chat shape end-to-end', () => {+ it('finds a query token in current group-chat jsonl shape and returns a snippet', async () => {+ // Pin the bug-fix path: bus refactor changed `<cid>.jsonl` from+ // `{role, content, time}` to `{id, ts, from, to, mentions, text}`.+ // `searchChats` must (a) read text via `text` field for snippet, and+ // (b) `searchAll` with scope=chat must surface the result.+ writeChat('u1', 'cgroup', [+ { id: 'm0', ts: '2026-01-01T00:00:00Z', from: 'user', to: ['commander'], mentions: [], text: 'discussing pangolin habitat' },+ ]);+ const s = await loadSearch();+ const ix = await import('../../../../src/main/features/search/indexer');+ await ix.reconcileChatsIndex('u1');+ const results = await s.searchChats('u1', 'pangolin');+ expect(results.length).toBeGreaterThan(0);+ expect(results[0].cid).toBe('cgroup');+ expect(results[0].role).toBe('user');+ // Snippet must include the matched token (proves `text` field is being+ // read, not the absent `content`).+ expect(results[0].snippet).toMatch(/pangolin/);+ });+});+describe('search › searchChats', () => {it('fills conv_title from _index.json when present', async () => {writeChat('u1', 'c1', [{ role: 'user', content: 'widget question', time: 't' }]);diff --git a/test/main/features/search/indexer.test.ts b/test/main/features/search/indexer.test.tsindex 6df60965..a5642cde 100644--- a/test/main/features/search/indexer.test.ts+++ b/test/main/features/search/indexer.test.ts@@ -188,6 +188,93 @@ describe('search/indexer › indexChatMessage (hot path)', () => {});});+// Persistence shape changed during the bus refactor: legacy `<cid>.jsonl`+// stored `{ role, content, time }`; current group-chat jsonl stores+// `{ id, ts, from, to, mentions, text, ... }` (GroupMessage). The chat+// indexer must read both — without the fallback, every post-refactor+// conversation gets `_msgText() === ''` and is silently skipped, surfacing+// to the user as "conversation messages can't be searched". This describe+// pins both shapes so the fallback in `_msgText` / `_msgRole` / `_msgTime`+// can't regress unnoticed.+describe('search/indexer › chat message shapes (legacy + group-chat)', () => {+ it('reconcileChatsIndex indexes group-chat shape (`{from, ts, text, ...}`)', async () => {+ writeChat('u1', 'c1', [+ { id: 'm0', ts: '2026-01-01T00:00:00Z', from: 'user', to: ['commander'], mentions: [], text: 'pangolin sighting' },+ { id: 'm1', ts: '2026-01-01T00:00:01Z', from: 'commander', to: ['user'], text: 'noted' },+ ]);+ const ix = await loadIndexer();+ await ix.reconcileChatsIndex('u1');+ const paths = await import('../../../../src/main/paths');+ const entry = await ix.getEntry(paths.userChatsIndexPath('u1'), 'chat');+ // Both messages indexed — `from` becomes role, `ts` becomes time, `text` is the body.+ expect(entry.idx.docs['chat:c1:0']).toMatchObject({ role: 'user', time: '2026-01-01T00:00:00Z' });+ expect(entry.idx.docs['chat:c1:1']).toMatchObject({ role: 'commander', time: '2026-01-01T00:00:01Z' });+ // Body tokens reachable via the postings list.+ expect(entry.idx.postings['pangolin']).toBeDefined();+ expect(entry.idx.postings['noted']).toBeDefined();+ });++ it('indexChatMessage hot-path accepts group-chat shape', async () => {+ const ix = await loadIndexer();+ ix.indexChatMessage('u1', 'c1', 0, {+ from: 'user', ts: 't', text: 'fresh group message',+ } as any);+ await new Promise((resolve) => setTimeout(resolve, 20));+ const paths = await import('../../../../src/main/paths');+ const entry = await ix.getEntry(paths.userChatsIndexPath('u1'), 'chat');+ expect(entry.idx.docs['chat:c1:0']).toMatchObject({ role: 'user', time: 't' });+ expect(entry.idx.postings['fresh']).toBeDefined();+ });++ it('legacy shape still works (regression guard for `{role, content, time}`)', async () => {+ // Old conversations written before the bus refactor stay searchable.+ writeChat('u1', 'c2', [+ { role: 'user', content: 'legacy alpha', time: 't1' },+ { role: 'assistant', content: 'legacy beta', time: 't2' },+ ]);+ const ix = await loadIndexer();+ await ix.reconcileChatsIndex('u1');+ const paths = await import('../../../../src/main/paths');+ const entry = await ix.getEntry(paths.userChatsIndexPath('u1'), 'chat');+ expect(entry.idx.docs['chat:c2:0']).toMatchObject({ role: 'user', time: 't1' });+ expect(entry.idx.postings['legacy']).toBeDefined();+ });+});++describe('search/indexer › on-disk schema bump triggers rebuild', () => {+ it('stale-version idx (e.g. v3 chat idx built by the broken `_msgText`) is discarded on load and reconcile rebuilds from jsonl', async () => {+ // Simulate the field-state that's actually on every existing user's+ // disk after the bus refactor: idx file written by an earlier schema+ // version, with `files` claiming the jsonl was already indexed but+ // `docs` empty (since the old `_msgText` returned '' for group-chat+ // shape and `_reindexChatFile` skipped every message).+ writeChat('u1', 'cstale', [+ { id: 'm0', ts: 't', from: 'user', to: ['commander'], text: 'searchable token zebrafish' },+ ]);+ const paths = await import('../../../../src/main/paths');+ const idxPath = paths.userChatsIndexPath('u1');+ const stalePayload = {+ version: 3, // <— old version+ kind: 'chat',+ files: { cstale: { mtime: 0, size: 0 } }, // claims indexed+ docs: {}, // but no docs (bug state)+ postings: {},+ };+ fs.mkdirSync(path.dirname(idxPath), { recursive: true });+ fs.writeFileSync(idxPath, JSON.stringify(stalePayload));++ const ix = await loadIndexer();+ await ix.reconcileChatsIndex('u1');++ const entry = await ix.getEntry(idxPath, 'chat');+ // Stale index discarded by `loadIndex` (version mismatch → emptyIndex),+ // reconcile then sees no known files → re-walks the jsonl from scratch+ // → group-chat shape now correctly tokenized.+ expect(entry.idx.docs['chat:cstale:0']).toBeDefined();+ expect(entry.idx.postings['zebrafish']).toBeDefined();+ });+});+describe('search/indexer › dropChatConversation', () => {it('removes every doc under the conversation id', async () => {writeChat('u1', 'c1', [