The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Index Harness sessions with their folder and title (#1147)
Deecac60d1e128a
diff --git a/cli/e2e/serviceProcesses.e2e.ts b/cli/e2e/serviceProcesses.e2e.tsindex 94583c9db..93a8761fc 100644--- a/cli/e2e/serviceProcesses.e2e.ts+++ b/cli/e2e/serviceProcesses.e2e.ts@@ -50,6 +50,14 @@ function searchPids(d: IsolatedDaemon): number[] {}const finds = async (client: LocalClient, word: string, sessionId: string): Promise<boolean> =>JSON.stringify(await client.request('session_search', { query: word }, 30_000)).includes(sessionId)+/** A session's row in the index file, read as the Memories package reads it: directly and read-only. */+function indexRow(d: IsolatedDaemon, sessionId: string): Record<string, unknown> | undefined {+ const { DatabaseSync } = process.getBuiltinModule('node:sqlite') as {+ DatabaseSync: new (path: string, options: { readOnly: boolean }) => { prepare(sql: string): { get(...args: string[]): Record<string, unknown> | undefined }; close(): void }+ }+ const db = new DatabaseSync(join(d.dataDir, 'session-search.db'), { readOnly: true })+ try { return db.prepare('SELECT agent_id, title, cwd, origin FROM sessions WHERE session_id = ?').get(sessionId) } finally { db.close() }+}describe('services in their own processes', () => {let daemon: IsolatedDaemon | undefined@@ -78,6 +86,15 @@ describe('services in their own processes', () => {const word = `axolotl${engine}`await turn(client, agent.id, `about the ${word}`)await until(`search to find the ${engine} conversation`, () => finds(client, word, agent.sessionId) || null, 60_000, 1_000)+ // Its row holds the harness's folder and title, the ones the catalog joins from the harness+ // records, for what reads the file itself (the Memories package); and it is still Harness's.+ await until(`the ${engine} row to carry its folder and title`, async () => {+ const catalog = await client.request('session_search', { query: '', catalogAfter: '', limit: 100 }, 30_000)+ const entry = (catalog.hits as Array<Record<string, any>> | undefined)?.find((hit) => hit.sessionId === agent.sessionId)?.catalogEntry+ const indexed = indexRow(d, agent.sessionId)+ return entry && indexed && String(indexed.cwd).endsWith(`search-out-${engine}`) && indexed.cwd === entry.cwd+ && indexed.title && indexed.title === entry.title && indexed.agent_id === agent.id && indexed.origin === '' ? indexed : null+ }, 30_000, 1_000)}expect(d.coresStarted()).toBe(1)client.close()diff --git a/cli/src/lib/sessionSearch/indexer.spec.ts b/cli/src/lib/sessionSearch/indexer.spec.tsindex f95519eb8..6fe2645ba 100644--- a/cli/src/lib/sessionSearch/indexer.spec.ts+++ b/cli/src/lib/sessionSearch/indexer.spec.ts@@ -310,6 +310,92 @@ describe('SessionSearchIndex', () => {expect(store.counts().sessions).toBe(0)})+ it("keeps a Harness session's folder and title on its row, filled in and kept current without reading its transcript again", async () => {+ // A row indexed before Harness rows carried either: on one Mac, all 165 of them.+ const { store, index, settle, setSources, path } = setup(prompt('flash the dial firmware', 0) + answer('Flashed.', 1))+ await settle()+ expect(store.session('s1')).toMatchObject({ agentId: 'agent-1', title: '', cwd: '', origin: '' })+ const write = vi.spyOn(store, 'writeSession')+ const harness = (cwd: string, title: string): SearchSource =>+ ({ agentId: 'agent-1', sessionId: 's1', engine: 'claude', transcriptPath: path, header: 'Dial firmware · harness', changedAt: 1, harness: { cwd, title } })++ // The next sweep fills it in: the header row alone, no turn read again.+ setSources([harness('/work/dial/firmware', 'Dial firmware')])+ await settle()+ expect(store.session('s1')).toMatchObject({ agentId: 'agent-1', header: 'Dial firmware · harness', title: 'Dial firmware', cwd: '/work/dial/firmware', origin: '', turns: 1 })+ expect(write).toHaveBeenCalledTimes(1)+ expect(write.mock.calls[0][2]).toEqual([])+ await settle()+ expect(write).toHaveBeenCalledTimes(1)++ // A rename, and a folder put right, under the same header: each reaches the row.+ setSources([harness('/work/dial/firmware', 'Keyboard firmware')])+ await settle()+ expect(store.session('s1')?.title).toBe('Keyboard firmware')+ setSources([harness('/Users/me/work/dial/firmware', 'Keyboard firmware')])+ await settle()+ expect(store.session('s1')?.cwd).toBe('/Users/me/work/dial/firmware')+ expect(write.mock.calls.map((call) => call[2])).toEqual([[], [], []])++ // Still Harness's: no hit or preview of it reads as a conversation Harness did not start.+ expect(index.search('flash').hits[0]).toMatchObject({ sessionId: 's1', agentId: 'agent-1' })+ expect(index.search('flash').hits[0].external).toBeUndefined()+ expect((await index.tail('s1'))?.external).toBeUndefined()+ // A catalog entry the harness records do not cover any more (an earlier conversation) now has+ // its own title and folder, as the records give a current one, where it had the header and no folder.+ expect(index.search('', { catalogAfter: '' }).hits[0].catalogEntry).toEqual({ title: 'Keyboard firmware', cwd: '/Users/me/work/dial/firmware', origin: 'harness' })++ // A transcript read from the start writes them with its turns.+ write.mockClear()+ writeFileSync(path, prompt('tiny', 0))+ await settle()+ expect(store.session('s1')).toMatchObject({ title: 'Keyboard firmware', cwd: '/Users/me/work/dial/firmware', turns: 1 })+ expect(write.mock.calls[0][2]).toHaveLength(1)+ })++ it("keeps the folder and title of a Harness session with nothing to read, or a database's history, without reading it again", async () => {+ const store = SessionSearchStore.open(':memory:')!+ let reads = 0+ const history: LiveEvent[] = [{ type: 'user_message', payload: { content: 'draft the release notes' } }]+ let sources: SearchSource[] = []+ const set = (cwd: string, title: string) => {+ sources = [+ { agentId: 'agent-t', sessionId: 'term', engine: 'terminal', transcriptPath: null, header: 'Shell', changedAt: 1, harness: { cwd, title } },+ { agentId: 'agent-oc', sessionId: 'ses_1', engine: 'opencode', transcriptPath: null, header: 'OpenCode harness', changedAt: 100,+ readHistory: async () => { reads++; return history }, harness: { cwd, title } },+ ]+ }+ const index = new SessionSearchIndex({ store, sources: () => sources })+ cleanups.push(() => { index.stop(); store.close() })+ const settle = async () => {+ index.sweep()+ await vi.waitFor(() => { expect((index as unknown as { running: boolean }).running).toBe(false) })+ }+ set('/work/notes', 'Release notes')+ await settle()+ for (const id of ['term', 'ses_1']) expect(store.session(id)).toMatchObject({ title: 'Release notes', cwd: '/work/notes', origin: '' })+ expect(reads).toBe(1)+ const write = vi.spyOn(store, 'writeSession')+ await settle()+ expect(write).not.toHaveBeenCalled()++ set('/work/notes', 'Changelog')+ await settle()+ set('/work/release-notes', 'Changelog')+ await settle()+ for (const id of ['term', 'ses_1']) expect(store.session(id)).toMatchObject({ agentId: id === 'term' ? 'agent-t' : 'agent-oc', title: 'Changelog', cwd: '/work/release-notes', origin: '' })+ expect(write).toHaveBeenCalledTimes(4)+ expect(store.session('ses_1')?.turns).toBe(1)+ expect(reads).toBe(1)++ // Read again after a turn event, with nothing new said: a changed folder alone is still written.+ set('/work/notes', 'Changelog')+ index.touch('ses_1')+ await settle()+ expect(reads).toBe(2)+ expect(store.session('ses_1')).toMatchObject({ cwd: '/work/notes', turns: 1, lastAt: 100 })+ })+it('indexes a touched session shortly after its turn event', async () => {const { path, index, found } = setup(prompt('first ask', 0))index.touch('s1')diff --git a/cli/src/lib/sessionSearch/indexer.ts b/cli/src/lib/sessionSearch/indexer.tsindex 1c0904d80..357ca978b 100644--- a/cli/src/lib/sessionSearch/indexer.ts+++ b/cli/src/lib/sessionSearch/indexer.ts@@ -44,6 +44,13 @@ export interface SearchSource {* read from its transcript as it is indexed), else what was first asked in it.*/external?: { cwd: string; origin: string; title: string }+ /**+ * A session Harness started: its harness's folder and title (else the name the apps show for it),+ * kept on its row beside the header for what reads the index itself. The Memories package does: on+ * one Mac (2026-10-10) all 165 Harness rows had neither, so half of that person's messages had no+ * folder or title there. Cmd-P, resume and `hn` join the harness records at read time instead.+ */+ harness?: { cwd: string; title: string }}/** Claude Code's titles in a transcript: its own, and one the person gave (which wins). */@@ -69,14 +76,30 @@ function titleLine(text: string): string {return line.length > 80 ? `${line.slice(0, 79).trimEnd()}…` : line}-function headerFor(source: SearchSource, title: string): string {- return source.external ? [title, folderWords(source.external.cwd)].filter(Boolean).join(' · ') : source.header+/** What a session's row says of it beside its turns. */+type Heading = Required<Pick<IndexedSession, 'header' | 'title' | 'cwd' | 'origin'>>++/**+ * A row's heading. A conversation Harness did not start is headed by its own title and folder. A+ * Harness session keeps the header it is given and carries its harness's title and folder, never an+ * origin: an empty origin with an agent id is what marks a row as Harness's (store.ts).+ */+function headingFor(source: SearchSource, title: string): Heading {+ if (source.external) {+ const { cwd, origin } = source.external+ return { header: [title, folderWords(cwd)].filter(Boolean).join(' · '), title, cwd, origin }+ }+ return { header: source.header, title: source.harness?.title ?? '', cwd: source.harness?.cwd ?? '', origin: '' }}-function externalFields(source: SearchSource, title: string): Pick<IndexedSession, 'title' | 'cwd' | 'origin'> {- return source.external- ? { title, cwd: source.external.cwd, origin: source.external.origin }- : { title: '', cwd: '', origin: '' }+/**+ * Whether a row already holds the heading and owner a pass would give it. A title or folder that moved+ * alone rewrites it as a header does, without reading the transcript again: a rename, a folder put+ * right (lib/cwdRepair.ts), and the rows indexed before Harness rows carried either.+ */+function headed(existing: IndexedSession, heading: Heading, agentId: string): boolean {+ return existing.agentId === agentId && existing.header === heading.header && (existing.title ?? '') === heading.title+ && (existing.cwd ?? '') === heading.cwd && (existing.origin ?? '') === heading.origin}export interface SessionSearchResult {@@ -388,18 +411,17 @@ export class SessionSearchIndex {const normalize = source.transcriptPath ? lineNormalizer(source.engine, source.sessionId) : nullconst file = source.transcriptPath && normalize ? await stat(source.transcriptPath).catch(() => null) : nullconst knownTitle = source.external ? source.external.title || existing?.title || '' : ''- const header = headerFor(source, knownTitle)+ const heading = headingFor(source, knownTitle)if (!file || !source.transcriptPath || !normalize) {// Nothing to read (a terminal, a database-backed engine, a missing file): its name is still findable.- if (existing?.header === header && existing.agentId === source.agentId) return+ if (existing && headed(existing, heading, source.agentId)) returnif (this.deletedSessions.has(source.sessionId)) returnstore.writeSession({sessionId: source.sessionId, agentId: source.agentId, engine: source.engine,- path: existing?.path ?? source.transcriptPath ?? '', header,+ path: existing?.path ?? source.transcriptPath ?? '', ...heading,size: existing?.size ?? 0, mtime: existing?.mtime ?? 0,resumeOffset: existing?.resumeOffset ?? 0, resumeTurn: existing?.resumeTurn ?? 0,lastAt: existing?.lastAt ?? (source.changedAt || null), turns: 0,- ...externalFields(source, knownTitle),}, NO_TURN_DELETE, [])return}@@ -407,9 +429,9 @@ export class SessionSearchIndex {const mtime = Math.floor(file.mtimeMs)const samePath = existing?.path === pathif (samePath && existing.size === file.size && existing.mtime === mtime) {- if (existing.header !== header || existing.agentId !== source.agentId) {+ if (!headed(existing, heading, source.agentId)) {if (this.deletedSessions.has(source.sessionId)) return- store.writeSession({ ...existing, header, agentId: source.agentId, ...externalFields(source, knownTitle) }, NO_TURN_DELETE, [])+ store.writeSession({ ...existing, ...heading, agentId: source.agentId }, NO_TURN_DELETE, [])}return}@@ -437,7 +459,7 @@ export class SessionSearchIndex {: ''const session: IndexedSession = {sessionId: source.sessionId, agentId: source.agentId, engine: source.engine, path,- header: headerFor(source, title),+ ...headingFor(source, title),size: file.size, mtime,resumeOffset: open ? open.offset : end,resumeTurn: open ? open.turn : collector.next,@@ -445,7 +467,6 @@ export class SessionSearchIndex {// moved, as its engine says, before the file's own time.lastAt: lastAt ?? (resume ? existing.lastAt : null) ?? (source.external && source.changedAt ? source.changedAt : mtime),turns: 0,- ...externalFields(source, title),}// A long session's first pass writes hundreds of rows. In one transaction that held the thread for// 130 ms, so rows go in batches, each but the last saved as a pass that stopped at the next batch:@@ -477,11 +498,10 @@ export class SessionSearchIndex {private async historyPass(source: SearchSource, existing: IndexedSession | undefined, dirty: boolean): Promise<void> {const store = this.opts.storeconst stamp = source.changedAt- // A conversation Harness did not start is headed by its own title and folder, as a transcript's is.- const headed = (title: string) => ({ header: headerFor(source, title), ...externalFields(source, title) })if (existing && !dirty && existing.mtime === stamp) {- const again = source.external ? headed(existing.title ?? '') : { header: source.header }- if (existing.header !== again.header || existing.agentId !== source.agentId) {+ // A conversation Harness did not start is headed by its own title and folder, as a transcript's is.+ const again = headingFor(source, source.external ? existing.title ?? '' : '')+ if (!headed(existing, again, source.agentId)) {if (this.deletedSessions.has(source.sessionId)) returnstore.writeSession({ ...existing, ...again, agentId: source.agentId }, NO_TURN_DELETE, [])}@@ -497,11 +517,10 @@ export class SessionSearchIndex {const { closed, open } = collector.finish()const turns = open ? [...closed, open] : closedconst title = source.external ? titleLine(source.external.title || turns.find((turn) => turn.ask)?.ask || '') : ''- const head = source.external ? headed(title) : { header: source.header }+ const head = headingFor(source, title)// The size field holds the fingerprint: how much conversation there was when last read.const fingerprint = turns.reduce((sum, turn) => sum + turn.ask.length + turn.answer.length + turn.tools.length + 1, 0)- if (existing && existing.size === fingerprint && existing.mtime === stamp- && existing.header === head.header && existing.agentId === source.agentId) return+ if (existing && existing.size === fingerprint && existing.mtime === stamp && headed(existing, head, source.agentId)) returnconst changed = !existing || existing.size !== fingerprintif (this.deletedSessions.has(source.sessionId)) returnstore.writeSession({diff --git a/cli/src/lib/sessionSearch/store.ts b/cli/src/lib/sessionSearch/store.tsindex 95e09b8b7..ae891fc3d 100644--- a/cli/src/lib/sessionSearch/store.ts+++ b/cli/src/lib/sessionSearch/store.ts@@ -55,7 +55,8 @@ export interface IndexedSession {/*** A conversation Harness did not start (lib/sessionSearch/external.ts), whose `agentId` is empty:* its title (Codex's thread name, Claude's own title, else the first ask), the folder it resumes in,- * and where it ran. Empty for a Harness session.+ * and where it ran. A Harness session has its harness's title (else the name the apps show for it)+ * and folder, as they were when it was last indexed, and no origin.*/title?: stringcwd?: stringdiff --git a/cli/src/services/search.spec.ts b/cli/src/services/search.spec.tsindex c99b599b0..4e3dbae50 100644--- a/cli/src/services/search.spec.ts+++ b/cli/src/services/search.spec.ts@@ -174,11 +174,16 @@ describe('the session search service', () => {row({ agentId: 'nothing-to-read', sessionId: 's-none' }),]const { index } = setup(agents)+ // Each carries its folder and title for the index's own readers; the header is as it was.expect(index.opts.sources()).toEqual([- { agentId: 'file', sessionId: 's-file', engine: 'claude', transcriptPath: '/t/file.jsonl', header: 'name of file · Fix login · api app', changedAt: 70, readHistory: undefined },- { agentId: 'db', sessionId: 's-db', engine: 'opencode', transcriptPath: null, header: 'name of db', changedAt: 40, readHistory: reader },- { agentId: 'fresh', sessionId: 's-fresh', engine: 'claude', transcriptPath: '/t/fresh.jsonl', header: 'name of fresh', changedAt: 30, readHistory: undefined },- { agentId: 'unstamped', sessionId: 's-un', engine: 'claude', transcriptPath: '/t/un.jsonl', header: 'name of unstamped', changedAt: 0, readHistory: undefined },+ { agentId: 'file', sessionId: 's-file', engine: 'claude', transcriptPath: '/t/file.jsonl', header: 'name of file · Fix login · api app', changedAt: 70, readHistory: undefined,+ harness: { cwd: '/work/app/api', title: 'Fix login' } },+ { agentId: 'db', sessionId: 's-db', engine: 'opencode', transcriptPath: null, header: 'name of db', changedAt: 40, readHistory: reader,+ harness: { cwd: '', title: 'name of db' } },+ { agentId: 'fresh', sessionId: 's-fresh', engine: 'claude', transcriptPath: '/t/fresh.jsonl', header: 'name of fresh', changedAt: 30, readHistory: undefined,+ harness: { cwd: '', title: 'name of fresh' } },+ { agentId: 'unstamped', sessionId: 's-un', engine: 'claude', transcriptPath: '/t/un.jsonl', header: 'name of unstamped', changedAt: 0, readHistory: undefined,+ harness: { cwd: '', title: 'name of unstamped' } },])})diff --git a/cli/src/services/search.ts b/cli/src/services/search.tsindex d48dd6aee..1a50d85f6 100644--- a/cli/src/services/search.ts+++ b/cli/src/services/search.ts@@ -11,6 +11,7 @@ import { join } from 'node:path'import { createExternalSessions, type ExternalReaderOptions } from './externalSessions.js'import { externalProviders } from '../lib/sessionSearch/externals/index.js'import type { CoreApi, CorePorts, ServiceRequests } from '../core/api.js'+import type { RegisteredSession } from '../lib/registry.js'import { SessionSearchIndex, folderWords, type SearchSource } from '../lib/sessionSearch/indexer.js'import { SESSION_SEARCH_FILE, SessionSearchStore, type ExternalHit } from '../lib/sessionSearch/store.js'@@ -68,13 +69,16 @@ function openIndex(core: CoreApi, readers: ReturnType<typeof createExternalSessiconsole.warn('[search] node:sqlite is not available on this Node — session search is off')return null}+ // A harness with no title of its own goes by the name the apps show for it, in the catalog and on+ // its index row alike.+ const titleOf = (s: RegisteredSession) => s.title || core.agents.displayName(s)const index = new SessionSearchIndex({store,catalogMetadata: () => {const entries = new Map<string, ExternalHit>(readers.sessions.list().flatMap(s =>[s.sessionId, ...(s.aliases ?? [])].map(id => [id, { title: s.title, cwd: s.cwd, origin: s.origin }] as const)))for (const s of core.agents.all()) if (s.sessionId) entries.set(s.sessionId,- { title: s.title || core.agents.displayName(s), cwd: s.cwd || '', origin: 'harness' })+ { title: titleOf(s), cwd: s.cwd || '', origin: 'harness' })return entries},sources: () => {@@ -91,6 +95,9 @@ function openIndex(core: CoreApi, readers: ReturnType<typeof createExternalSessi// Conversation stamps only: the row's `touchedAt` includes discovery bookkeeping.changedAt: Math.max(s.lastTranscriptAt || 0, s.lastHookAt || 0) || s.boundAt || s.registeredAt || 0,readHistory,+ // On its row for what reads the index directly (the Memories package), which has no+ // harness records to join: a pass writes them again whenever they change.+ harness: { cwd: s.cwd || '', title: titleOf(s) },}]})// Conversations Harness did not start — any Harness agent's, earlier ones included, are not.diff --git a/store/agents/memories/test/fixtures.mjs b/store/agents/memories/test/fixtures.mjsindex 5006d7750..938f8775a 100644--- a/store/agents/memories/test/fixtures.mjs+++ b/store/agents/memories/test/fixtures.mjs@@ -15,7 +15,11 @@ function put(root, path, text) {return file}-/** The index schema the readers rely on (a subset of cli/src/lib/sessionSearch/store.ts). */+/**+ * The index schema the readers rely on (a subset of cli/src/lib/sessionSearch/store.ts). A session's+ * first turn says whose it is, as the CLI writes it: one Harness started has an `agent` id, its header+ * and no `origin`; one it did not start has no agent and says where it ran (`origin: 'terminal'`).+ */export function sessionIndex(dir, { now = Date.now(), turns = [] } = {}) {mkdirSync(dir, { recursive: true })const db = new DatabaseSync(join(dir, 'session-search.db'))@@ -34,14 +38,15 @@ export function sessionIndex(dir, { now = Date.now(), turns = [] } = {}) {const sessions = new Map()const insertTurn = db.prepare('INSERT INTO turns (session_id, turn, at, name, ask, answer) VALUES (?, ?, ?, ?, ?, ?)')for (const turn of turns) {- const session = sessions.get(turn.session) ?? { engine: turn.engine, cwd: turn.cwd ?? '', title: turn.title ?? '', count: 0, last: 0 }+ const session = sessions.get(turn.session) ?? { engine: turn.engine, cwd: turn.cwd ?? '', title: turn.title ?? '',+ agent: turn.agent ?? `agent-${turn.session}`, header: turn.header ?? '{}', origin: turn.origin ?? '', count: 0, last: 0 }insertTurn.run(turn.session, session.count, now - (turn.daysAgo ?? 0) * DAY, session.title, turn.ask ?? '', turn.answer ?? '')session.count++session.last = Math.max(session.last, now - (turn.daysAgo ?? 0) * DAY)sessions.set(turn.session, session)}- const insertSession = db.prepare("INSERT INTO sessions VALUES (?, ?, ?, '', '{}', 0, 0, 0, 0, ?, ?, ?, ?, '')")- for (const [id, session] of sessions) insertSession.run(id, `agent-${id}`, session.engine, session.last, session.count, session.title, session.cwd)+ const insertSession = db.prepare("INSERT INTO sessions VALUES (?, ?, ?, '', ?, 0, 0, 0, 0, ?, ?, ?, ?, ?)")+ for (const [id, session] of sessions) insertSession.run(id, session.agent, session.engine, session.header, session.last, session.count, session.title, session.cwd, session.origin)db.close()}diff --git a/store/agents/memories/test/sessions.test.mjs b/store/agents/memories/test/sessions.test.mjsindex 3e55d45a0..b378c28c8 100644--- a/store/agents/memories/test/sessions.test.mjs+++ b/store/agents/memories/test/sessions.test.mjs@@ -3,8 +3,9 @@ import { mkdtempSync } from 'node:fs'import { tmpdir } from 'node:os'import { join } from 'node:path'import { test } from 'node:test'-import { asks, ftsQuery, openIndex, overview, search } from '../lib/sessions.mjs'-import { DAY, makeHome } from './fixtures.mjs'+import { asks, folders, ftsQuery, openIndex, overview, search } from '../lib/sessions.mjs'+import { projectsFor } from '../lib/state.mjs'+import { DAY, makeHome, sessionIndex } from './fixtures.mjs'const now = Date.now()const { home, project } = makeHome({ now })@@ -49,3 +50,36 @@ test('search: any typed text is a safe query, one hit per conversation', () => {assert.match(hits[0].snippet, /\u0002short\u0003/)assert.equal(search(index.db, 'fridays docs', { any: true }).length, 2)})++test("Harness's own sessions are placed by their folder and named by their harness, beside the ones it did not start", async () => {+ const dir = mkdtempSync(join(tmpdir(), 'memories-harness-rows-'))+ const app = join(dir, 'code', 'my-app')+ const worktree = join(app, '.claude', 'worktrees', 'quiet-otter')+ // As the CLI indexes them: a harness's row has its agent, its header, its title and folder, and no+ // origin; one Harness did not start has no agent and says where it ran. A row indexed before Harness+ // rows carried a folder (the CLI fills it in on its next sweep) still counts, in no folder.+ sessionIndex(dir, {+ now,+ turns: [+ { session: 'h1', engine: 'claude', agent: 'agent-1', header: 'Claude · Fix login · code my-app', cwd: app, title: 'Fix login', ask: 'the login token expires early', daysAgo: 0 },+ { session: 'h1', engine: 'claude', ask: 'keep the old cookie name', daysAgo: 0 },+ { session: 'h2', engine: 'claude', agent: 'agent-2', header: 'Claude · Release · quiet-otter worktrees', cwd: worktree, title: 'Release', ask: 'tag the release', daysAgo: 1 },+ { session: 'e1', engine: 'codex', agent: '', origin: 'terminal', cwd: app, title: 'Docs pass', ask: 'write the login docs', daysAgo: 2 },+ { session: 'old', engine: 'claude', agent: 'agent-3', header: 'Claude · Old', ask: 'from before the folders', daysAgo: 3 },+ ],+ })+ const { db } = await openIndex(dir)+ assert.ok(db)+ const here = folders(db).find((folder) => folder.cwd === app)+ assert.deepEqual([here.sessions, here.asks, here.engines], [2, 3, { claude: 2, codex: 1 }])+ assert.ok(!folders(db).some((folder) => folder.cwd === ''), 'a row with no folder yet is in none')+ assert.equal(overview(db, { now }).asks, 5)+ assert.deepEqual(asks(db, { since: 0, cwd: app }).map((row) => [row.sessionId, row.title]).sort(),+ [['e1', 'Docs pass'], ['h1', 'Fix login'], ['h1', 'Fix login']])+ assert.deepEqual(search(db, 'login').map((hit) => [hit.sessionId, hit.title, hit.cwd]).sort(),+ [['e1', 'Docs pass', app], ['h1', 'Fix login', app]])+ // The project's memories, and the harness in its worktree, count together.+ const [project] = projectsFor([{ id: 'claude:x.md', project: { name: 'my-app', path: app } }], folders(db), dir)+ assert.deepEqual([project.sessions, project.asks, project.engines], [3, 4, { claude: 3, codex: 1 }])+ db.close()+})