🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
fix(agentbbs): page forward from sinceEnvelopeId in federation_bbs_watch (#4480)
kevin166aef93c7a8
diff --git a/v3/@claude-flow/cli/__tests__/agentbbs-watch-paging.test.ts b/v3/@claude-flow/cli/__tests__/agentbbs-watch-paging.test.tsnew file mode 100644index 0000000000..cb2ed039df--- /dev/null+++ b/v3/@claude-flow/cli/__tests__/agentbbs-watch-paging.test.ts@@ -0,0 +1,57 @@+/**+ * federation_bbs_watch paging: a watcher that resumes after sinceEnvelopeId+ * must get the envelopes right after it, so that passing the last returned id+ * walks the whole room when hasMore is set. Returning the newest `limit`+ * envelopes instead skips everything between the cursor and that window.+ */+import { describe, it, expect, beforeAll, afterAll } from 'vitest';+import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';+import { join } from 'node:path';+import { tmpdir } from 'node:os';++// The watch handler only checks that the agentbbs CLI answers `--version`;+// node does, so these tests run without the optional dependency installed.+process.env.AGENTBBS_BIN = process.execPath;++const { agentbbsTools } = await import('../src/mcp-tools/agentbbs-tools.js');++const watch = agentbbsTools.find(t => t.name === 'federation_bbs_watch')!;+const roomId = 'sales-12345678';++describe('federation_bbs_watch paging', () => {+ let dir: string;++ beforeAll(() => {+ dir = mkdtempSync(join(tmpdir(), 'bbs-watch-paging-'));+ const lines = Array.from({ length: 10 }, (_, i) => JSON.stringify({+ envelopeId: `env-${i + 1}`, roomId, seq: i + 1, msgType: 'task-result', payload: { n: i + 1 },+ }));+ writeFileSync(join(dir, `room-${roomId}.jsonl`), lines.join('\n') + '\n');+ });++ afterAll(() => { rmSync(dir, { recursive: true, force: true }); });++ it('without a cursor returns the most recent window', async () => {+ const r: any = await watch.handler({ basePath: dir, roomId, limit: 3 });+ expect(r.envelopes.map((e: any) => e.seq)).toEqual([8, 9, 10]);+ expect(r.hasMore).toBe(true);+ });++ it('after sinceEnvelopeId returns the envelopes that follow it, oldest first', async () => {+ const r: any = await watch.handler({ basePath: dir, roomId, sinceEnvelopeId: 'env-2', limit: 3 });+ expect(r.envelopes.map((e: any) => e.seq)).toEqual([3, 4, 5]);+ expect(r.hasMore).toBe(true);+ });++ it('paging with the last returned id visits every envelope once', async () => {+ const seen: number[] = [];+ let since = 'env-1';+ for (;;) {+ const r: any = await watch.handler({ basePath: dir, roomId, sinceEnvelopeId: since, limit: 4 });+ seen.push(...r.envelopes.map((e: any) => e.seq));+ if (!r.hasMore) break;+ since = r.envelopes[r.envelopes.length - 1].envelopeId;+ }+ expect(seen).toEqual([2, 3, 4, 5, 6, 7, 8, 9, 10]);+ });+});diff --git a/v3/@claude-flow/cli/src/mcp-tools/agentbbs-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/agentbbs-tools.tsindex 5453606baf..7f37157853 100644--- a/v3/@claude-flow/cli/src/mcp-tools/agentbbs-tools.ts+++ b/v3/@claude-flow/cli/src/mcp-tools/agentbbs-tools.ts@@ -480,14 +480,19 @@ export const agentbbsTools: MCPTool[] = [const all = readEnvelopes(logPath);let slice = all;+ let resuming = false;if (sinceEnvelopeId) {const idx = all.findIndex(e => e.envelopeId === sinceEnvelopeId);- slice = idx >= 0 ? all.slice(idx + 1) : all;+ resuming = idx >= 0;+ slice = resuming ? all.slice(idx + 1) : all;}// Dedup by envelopeId before applying the limit — a relay replay or a// double-append must not surface the same envelope twice to a watcher.const deduped = dedupEnvelopes(slice);- const envelopes = deduped.slice(-limit);+ // A watcher resuming after sinceEnvelopeId gets the oldest envelopes+ // first, so passing the last returned id pages through the rest when+ // hasMore is set. Without a cursor, it gets the most recent window.+ const envelopes = resuming ? deduped.slice(0, limit) : deduped.slice(-limit);return {success: true,roomId,