Your team of AI agents, on your Mac, Windows or Linux. Agents that talk in channels, write code, review each other and use your tools, on the Claude Code, Codex, OpenCode or Pi you already have. Anything that touches the real world waits for your yes.
TypeScript agent-teamagentic-aiai-agentsai-assistantclaude-codecodexcursorelectrongrokgrok-bot-alternativelinuxlocal-firstmacosmcpmulti-agentopenclaw-alternativeopencodewindows
Let the wiki read a reply that started early and ended late (#178)
Diasff8323a07467
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 572e784..5f31645 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,10 @@ What changed in each version of Tucano. The format follows [Keep a Changelog](ht- **Long skill recipes are kept whole.** A recipe over 20,000 characters was refused when written or proposed, cut when linked from Claude Code or Codex, and left out of an imported team. Now 10,000 characters is a recommendation: past it, Tucano says by how much and keeps the whole recipe, up to a million characters.+### Fixed++- **The wiki no longer misses a long reply.** A reply that started before another and ended well after it never reached the wiki, because the wiki's curator had already read past where it started. It now goes by when each reply ended, the same order the conversation shows.+## [0.2.16] - 2026-11-07> **Em português:**diff --git a/src/core/db.ts b/src/core/db.tsindex 8c04504..59ce738 100644--- a/src/core/db.ts+++ b/src/core/db.ts@@ -992,6 +992,11 @@ export class Db {return (this.db.prepare('SELECT * FROM messages WHERE conversation_id = ? AND at > ? ORDER BY at').all(conversationId, at) as Row[]).map((r) => this.toMessage(r))}+ // What was said after `at`: a reply counts from when it ended (saidAt), so one that started before `at` is still here.+ messagesSaidAfter(conversationId: string, at: number): Message[] {+ return (this.db.prepare(`SELECT * FROM messages WHERE conversation_id = ? AND COALESCE(json_extract(run, '$.endedAt'), at) > ? ORDER BY at`).all(conversationId, at) as Row[]).map((r) => this.toMessage(r))+ }+// What the window opens with: each conversation's latest `n` messages outside threads, the threads// still going wherever they started, and every routine's request with its reply (Routines draws what// ran), each with all its replies. `since`: per conversation with older ones left, from when it's whole.diff --git a/src/core/wiki-curator.ts b/src/core/wiki-curator.tsindex 6da6496..933f9b2 100644--- a/src/core/wiki-curator.ts+++ b/src/core/wiki-curator.ts@@ -6,7 +6,7 @@// with Undo. A message can also be kept on purpose ("Keep in the wiki"), and "guarda isso"// said in the conversation makes the curator keep it.import { L } from '../shared/lang'-import type { Agent, Message, Person, Settings, WikiChange, WikiOp } from '../shared/types'+import { asSaid, saidAt, type Agent, type Message, type Person, type Settings, type WikiChange, type WikiOp } from '../shared/types'import { cleanTitle, ftsQuery } from './wiki'import type { Wiki } from './wiki'@@ -18,7 +18,7 @@ const DOC_PART = 30_000 // a long document is read in parts this size, one afterexport interface CuratorDeps {wiki: Wiki- db: { conversation(id: string): { id: string; kind: string; name: string; wikiCapture?: boolean; owner?: string } | undefined; messagesAfter(conversationId: string, at: number): Message[]; message(id: string): Message | undefined; saveMessage(m: Message): void; agents(): Agent[]; ownerId?(): string; people?(opts: { removed?: boolean }): Person[]; teamMode?(): boolean }+ db: { conversation(id: string): { id: string; kind: string; name: string; wikiCapture?: boolean; owner?: string } | undefined; messagesAfter(conversationId: string, at: number): Message[]; messagesSaidAfter(conversationId: string, at: number): Message[]; message(id: string): Message | undefined; saveMessage(m: Message): void; agents(): Agent[]; ownerId?(): string; people?(opts: { removed?: boolean }): Person[]; teamMode?(): boolean }settings: () => Settingsllm: (system: string, prompt: string) => Promise<string> // a cheap model, chosen inside; throws when none is readyemitMessage: (m: Message) => void@@ -155,7 +155,7 @@ export class WikiCurator {return this.deps.db.agents().find((a) => a.id === agentId)?.name ?? L('Agente', 'Agent')}private excerpt(messages: Message[]): string {- return messages.map((m) => `**${this.name(m)}** (${new Date(m.at).toLocaleString('pt-BR', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit' })}): ${m.text.trim()}`).join('\n\n')+ return messages.map((m) => `**${this.name(m)}** (${new Date(saidAt(m)).toLocaleString('pt-BR', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit' })}): ${m.text.trim()}`).join('\n\n')}private async doRead(conversationId: string): Promise<void> {@@ -168,14 +168,16 @@ export class WikiCurator {const since = wiki.mark(conversationId)// what was already kept on purpose ("Keep in the wiki") isn't read a second timeconst kept = wiki.readMessages(conversationId)- const all = db.messagesAfter(conversationId, since).filter((m) => (m.author.kind === 'person' || m.author.kind === 'agent') && m.text.trim() && m.run?.status !== 'working')+ // In the order things were said, and the mark goes by that too: a reply still at work when the+ // conversation was last read comes after what was read then, however early it started.+ const all = asSaid(db.messagesSaidAfter(conversationId, since)).filter((m) => (m.author.kind === 'person' || m.author.kind === 'agent') && m.text.trim() && m.run?.status !== 'working')const fresh = all.filter((m) => !kept.has(m.id))- if (!fresh.length) return all.length ? wiki.setMark(conversationId, all.at(-1)!.at) : undefined+ if (!fresh.length) return all.length ? wiki.setMark(conversationId, saidAt(all.at(-1)!)) : undefinedconst stretch = fresh.slice(-MAX_MESSAGES)const last = stretch.at(-1)!- if (stretch.reduce((n, m) => n + m.text.length, 0) < MIN_CHARS) return wiki.setMark(conversationId, last.at)+ if (stretch.reduce((n, m) => n + m.text.length, 0) < MIN_CHARS) return wiki.setMark(conversationId, saidAt(last))await this.curate({ messages: stretch, kind: 'conversation', conversationId, force: false })- wiki.setMark(conversationId, last.at)+ wiki.setMark(conversationId, saidAt(last))}// A message kept on purpose: with the one it answers, if it's a reply (in a thread, my last message there).diff --git a/test/team-round3.test.ts b/test/team-round3.test.tsindex bbe001d..dc53144 100644--- a/test/team-round3.test.ts+++ b/test/team-round3.test.ts@@ -47,7 +47,7 @@ describe('E. a source removed while the curator reads it', () => {const curatorOver = (w: Wiki, llm: () => Promise<string>, conversations: Record<string, { id: string; kind: string; name: string }> = {}): WikiCurator =>new WikiCurator({wiki: w,- db: { conversation: (id) => conversations[id], messagesAfter: () => [], message: () => undefined, saveMessage: () => {}, agents: () => [] },+ db: { conversation: (id) => conversations[id], messagesAfter: () => [], messagesSaidAfter: () => [], message: () => undefined, saveMessage: () => {}, agents: () => [] },settings: () => ({ workspaceName: 'Ana', wikiEdits: 'auto' }) as Settings,llm,emitMessage: () => {}@@ -72,7 +72,7 @@ describe('E. a source removed while the curator reads it', () => {const convs: Record<string, { id: string; kind: string; name: string }> = { dm: { id: 'dm', kind: 'dm', name: 'x' } }const c = new WikiCurator({wiki: w,- db: { conversation: (id) => convs[id], messagesAfter: () => [], message: (id) => (id === 'm1' ? { id: 'm1', conversationId: 'dm', author: { kind: 'person', id: 'p' }, text: 'O salário da Ana é 12000.', at: 1 } : undefined), saveMessage: () => {}, agents: () => [] },+ db: { conversation: (id) => convs[id], messagesAfter: () => [], messagesSaidAfter: () => [], message: (id) => (id === 'm1' ? { id: 'm1', conversationId: 'dm', author: { kind: 'person', id: 'p' }, text: 'O salário da Ana é 12000.', at: 1 } : undefined), saveMessage: () => {}, agents: () => [] },settings: () => ({ workspaceName: 'Ana', wikiEdits: 'auto' }) as Settings,llm: async () => {delete convs['dm']diff --git a/test/team-round4.test.ts b/test/team-round4.test.tsindex 910fc05..6aff2f9 100644--- a/test/team-round4.test.ts+++ b/test/team-round4.test.ts@@ -59,7 +59,7 @@ describe('A. a team from its first invite (before anyone joins)', () => {const curator = (): WikiCurator =>new WikiCurator({wiki,- db: { conversation: (id) => db.conversation(id), messagesAfter: (id) => (id === 'dm-ana' ? said : []), message: () => undefined, saveMessage: () => {}, agents: () => [], ownerId: () => db.ownerId(), people: (o) => db.people(o), teamMode: () => db.teamMode() },+ db: { conversation: (id) => db.conversation(id), messagesAfter: (id) => (id === 'dm-ana' ? said : []), messagesSaidAfter: (id) => (id === 'dm-ana' ? said : []), message: () => undefined, saveMessage: () => {}, agents: () => [], ownerId: () => db.ownerId(), people: (o) => db.people(o), teamMode: () => db.teamMode() },settings: () => settings,llm: async () => (asked++, JSON.stringify({ worth: false, reason: '', source_title: '', changes: [] })),emitMessage: () => {}diff --git a/test/wiki-curator.test.ts b/test/wiki-curator.test.tsindex 15e5c99..2636d8c 100644--- a/test/wiki-curator.test.ts+++ b/test/wiki-curator.test.ts@@ -1,8 +1,12 @@import { mkdtempSync } from 'node:fs'import { tmpdir } from 'node:os'import { join } from 'node:path'-import { describe, expect, it } from 'vitest'-import type { Agent, Message, Settings } from '../src/shared/types'+import { describe, expect, it, vi } from 'vitest'+import { saidAt, type Agent, type EngineId, type Message, type Settings } from '../src/shared/types'+import { Db } from '../src/core/db'+import { fakeEngine } from '../src/core/engines/fake'+import type { Engine, EngineEvent, Turn } from '../src/core/engines/types'+import { Runner } from '../src/core/runs'import { applyOp, Wiki } from '../src/core/wiki'import { curatorSystem, parseCuration, WikiCurator } from '../src/core/wiki-curator'@@ -70,6 +74,7 @@ describe('the curator', () => {db: {conversation: (id) => ({ id, kind: 'dm', name: 'lia', ...(off.has(id) ? { wikiCapture: false } : {}) }),messagesAfter: (_c, at) => messages.filter((m) => m.at > at),+ messagesSaidAfter: (_c, at) => messages.filter((m) => saidAt(m) > at),message: (id) => messages.find((m) => m.id === id),saveMessage: (m) => messages.splice(messages.findIndex((x) => x.id === m.id), 1, m),agents: () => agents@@ -239,6 +244,131 @@ describe('the curator', () => {})})+describe('the curator and replies that overlap', () => {+ const ready = { installed: true, loggedIn: true }+ const LIA = `LIA-${'x'.repeat(200)}` // one word each, so the fake engine says it at once+ const THEO = `THEO-${'y'.repeat(200)}`+ const agent = (id: string): Agent => ({ id, name: id, handle: id, role: '', color: 'sky', instructions: '', modelId: 'sonnet', effort: 'low', limit: 1_000_000, used: 0, grants: {}, memory: 'auto', computer: false, archived: false })+ const settings = { workspaceName: 'Edu', context: '', engines: { claude: ready, codex: ready, opencode: ready, pi: ready, gemini: ready, cursor: ready, grok: ready }, routerModel: 'haiku', memoryModel: 'haiku', memoryLearning: 'approve', defaultLimit: 1000, approvalTtlHours: 24, theme: 'system', language: 'pt' } as Settings++ // Real Db, Wiki and Runner. Lia works until `end()`; Theo is done at once.+ function world(theoSays = THEO) {+ const db = new Db(join(mkdtempSync(join(tmpdir(), 'tucano-wiki-')), 'test.db'))+ db.saveAgent(agent('lia'))+ db.saveAgent(agent('theo'))+ db.createConversation({ id: 'c', kind: 'channel', name: 'geral', members: ['lia', 'theo'] })+ const w = fresh()+ const calls: string[] = []+ const curator = new WikiCurator({ wiki: w, db, settings: () => settings, emitMessage: () => {}, llm: async (_s, prompt) => (calls.push(prompt), JSON.stringify({ guardar: false, mudancas: [] })) })+ let release = (): void => {}+ const held = new Promise<void>((r) => (release = r))+ const isLia = (t: Turn): boolean => t.system.startsWith('Você é lia')+ const quick = fakeEngine('claude', { delayMs: 1, reply: (t) => (isLia(t) ? LIA : theoSays) })+ const claude: Engine = {+ ...quick,+ async *run(t: Turn): AsyncIterable<EngineEvent> {+ if (isLia(t)) await held+ yield* quick.run(t)+ }+ }+ const engines: Record<EngineId, Engine> = { claude, codex: fakeEngine('codex'), opencode: fakeEngine('opencode'), pi: fakeEngine('pi'), gemini: fakeEngine('gemini'), cursor: fakeEngine('cursor'), grok: fakeEngine('grok') }+ const runner = new Runner({ db, engines, settings: async () => settings, emit: () => {}, workDir: mkdtempSync(join(tmpdir(), 'tucano-wiki-')) })+ const by = (who: string): Message | undefined => db.messages().find((m) => m.author.kind === 'agent' && m.author.id === who)+ // Lia is asked first and is at work when Theo is asked and answers: two messages, since agents called in one may take turns.+ const overlap = async (): Promise<void> => {+ await runner.send('c', '@lia bom dia')+ await vi.waitFor(() => expect(by('lia')?.run?.status).toBe('working'))+ await runner.send('c', '@theo bom dia')+ await vi.waitFor(() => expect(by('theo')?.run?.status).toBe('done'))+ }+ const end = async (): Promise<void> => {+ release()+ await runner.idle()+ }+ return { db, w, curator, calls, by, overlap, end }+ }+ const message = (id: string, at: number, run?: Message['run']): Message => ({ id, conversationId: 'c', author: run ? { kind: 'agent', id: 'lia' } : { kind: 'person', id: 'p1' }, text: `${id} ${'z'.repeat(200)}`, at, ...(run ? { run } : {}) })++ it('reads a reply that started first and ended last, once it ends, and nothing twice', async () => {+ const { db, w, curator, calls, by, overlap, end } = world()+ await overlap()++ await curator.read('c') // the conversation goes quiet while she works+ expect(calls).toHaveLength(1)+ expect(calls[0]).toContain('THEO-')+ expect(calls[0]).not.toContain('LIA-')++ await end()+ expect(by('lia')!.at).toBeLessThan(by('theo')!.at) // she did start first+ await curator.read('c')+ expect(calls).toHaveLength(2)+ expect(calls[1]).toContain('LIA-')+ expect(calls[1]).not.toContain('THEO-')+ expect(w.mark('c')).toBe(saidAt(by('lia')!))++ await curator.read('c')+ expect(calls).toHaveLength(2)+ db.close()+ })++ it("isn't thrown off by a reply too short to read", async () => {+ const { db, curator, calls, overlap, end } = world('ok')+ await overlap()+ await curator.read('c')+ expect(calls).toHaveLength(0)++ await end()+ await curator.read('c')+ expect(calls).toHaveLength(1)+ expect(calls[0]).toContain('LIA-')+ db.close()+ })++ it('reads in the order things were said', async () => {+ const { db, curator, calls, overlap, end } = world()+ await overlap()+ await end()+ await curator.read('c')+ expect(calls[0]!.indexOf('THEO-')).toBeGreaterThan(-1)+ expect(calls[0]!.indexOf('LIA-')).toBeGreaterThan(calls[0]!.indexOf('THEO-'))+ db.close()+ })++ it("doesn't let what came while a reply worked push it out of the stretch", async () => {+ const { db, curator, calls } = world()+ db.saveMessage(message('longa', 1, { status: 'done', steps: [], endedAt: 100 }))+ for (let k = 2; k <= 21; k++) db.saveMessage(message(`m${k}`, k))+ await curator.read('c')+ expect(calls[0]).toContain('longa')+ db.close()+ })++ it('reads again a reply tried again, which ends anew', async () => {+ const { db, w, curator, calls } = world()+ db.saveMessage(message('falhou', 1, { status: 'failed', steps: [], endedAt: 5 }))+ await curator.read('c')+ expect(w.mark('c')).toBe(5)+ db.saveMessage({ ...message('falhou', 1, { status: 'done', steps: [], endedAt: 9 }), text: `de novo ${'z'.repeat(200)}` })+ await curator.read('c')+ expect(calls).toHaveLength(2)+ expect(calls[1]).toContain('de novo')+ db.close()+ })++ it('finds what was said after a point: a reply by when it ended, one with no end by when it started', () => {+ const { db } = world()+ db.saveMessage(message('antes', 1))+ db.saveMessage(message('antiga', 2, { status: 'done', steps: [] })) // from before replies kept their end+ db.saveMessage(message('longa', 3, { status: 'done', steps: [], endedAt: 50 }))+ db.saveMessage(message('rapida', 10, { status: 'done', steps: [], endedAt: 11 }))+ db.saveMessage(message('ja-lida', 4, { status: 'done', steps: [], endedAt: 9 }))+ db.saveMessage(message('depois', 20))+ db.saveMessage(message('trabalhando', 21, { status: 'working', steps: [] }))+ expect(db.messagesSaidAfter('c', 10).map((m) => m.id)).toEqual(['longa', 'rapida', 'depois', 'trabalhando'])+ db.close()+ })+})+describe('the wiki in another folder', () => {it('moves to another folder with an index of its own, and comes back', () => {const root = mkdtempSync(join(tmpdir(), 'tucano-wiki-'))diff --git a/test/wiki-extract.test.ts b/test/wiki-extract.test.tsindex 57fe190..071787a 100644--- a/test/wiki-extract.test.ts+++ b/test/wiki-extract.test.ts@@ -63,7 +63,7 @@ describe('a document brought to the wiki', () => {const prompts: string[] = []const curator = new WikiCurator({wiki: w,- db: { conversation: () => undefined, messagesAfter: () => [], message: () => undefined, saveMessage: () => {}, agents: () => [] },+ db: { conversation: () => undefined, messagesAfter: () => [], messagesSaidAfter: () => [], message: () => undefined, saveMessage: () => {}, agents: () => [] },settings: () => ({ workspaceName: 'Ana' }) as Settings,llm: async (_s, prompt) => {prompts.push(prompt)@@ -83,7 +83,7 @@ describe('a document brought to the wiki', () => {expect(w.page('Cláusulas 1')!.body).toMatch(/Fontes: \[\[fontes\/.+\|Contrato Silva\]\]/)// a note: kept on purpose; a curator that fails marks the source as failed- const broken = new WikiCurator({ wiki: w, db: { conversation: () => undefined, messagesAfter: () => [], message: () => undefined, saveMessage: () => {}, agents: () => [] }, settings: () => ({}) as Settings, llm: async () => { throw new Error('sem modelo') }, emitMessage: () => {} })+ const broken = new WikiCurator({ wiki: w, db: { conversation: () => undefined, messagesAfter: () => [], messagesSaidAfter: () => [], message: () => undefined, saveMessage: () => {}, agents: () => [] }, settings: () => ({}) as Settings, llm: async () => { throw new Error('sem modelo') }, emitMessage: () => {} })const note = w.addSource({ title: 'Lembrete', text: 'O Marcos prefere WhatsApp depois das 18h.', kind: 'note', by: 'me', status: 'reading' })await broken.ingest(note.id)expect(w.source(note.id)).toMatchObject({ status: 'failed', error: 'sem modelo' })