Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 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

fix(cli): report every saved session in session_list total, not just the limited page (#4344)

kevin86a44c5d9e2b
diff --git a/v3/@claude-flow/cli/__tests__/session-list-total.test.ts b/v3/@claude-flow/cli/__tests__/session-list-total.test.ts
new file mode 100644
index 0000000000..3f88a1149e
--- /dev/null
+++ b/v3/@claude-flow/cli/__tests__/session-list-total.test.ts
@@ -0,0 +1,50 @@
+/**
+ * session_list computed `total` after applying `limit`, so `session list`
+ * printed "Showing 10 of 10 sessions" even when more sessions were saved.
+ */
+import { describe, it, expect, beforeEach, afterEach } from 'vitest';
+import { mkdtempSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { sessionTools } from '../src/mcp-tools/session-tools.js';
+
+const tool = (name: string) => {
+ const t = sessionTools.find(t => t.name === name);
+ if (!t) throw new Error(`MCP tool not registered: ${name}`);
+ return t;
+};
+
+type ListResult = { sessions: Array<{ sessionId: string }>; total: number; limit: number };
+
+describe('session_list total', () => {
+ let dir: string;
+ let prevCwd: string | undefined;
+
+ beforeEach(async () => {
+ dir = mkdtempSync(join(tmpdir(), 'ruflo-session-list-total-'));
+ prevCwd = process.env.CLAUDE_FLOW_CWD;
+ process.env.CLAUDE_FLOW_CWD = dir;
+ const save = tool('session_save').handler;
+ for (let i = 0; i < 4; i++) {
+ await save({ name: `session ${i}`, includeMemory: false, includeTasks: false, includeAgents: false });
+ }
+ });
+
+ afterEach(() => {
+ if (prevCwd === undefined) delete process.env.CLAUDE_FLOW_CWD;
+ else process.env.CLAUDE_FLOW_CWD = prevCwd;
+ rmSync(dir, { recursive: true, force: true });
+ });
+
+ it('reports every saved session in total, not just the returned page', async () => {
+ const result = await tool('session_list').handler({ limit: 2 }) as ListResult;
+ expect(result.sessions).toHaveLength(2);
+ expect(result.total).toBe(4);
+ });
+
+ it('total equals the number of sessions when under the limit', async () => {
+ const result = await tool('session_list').handler({}) as ListResult;
+ expect(result.sessions).toHaveLength(4);
+ expect(result.total).toBe(4);
+ });
+});
diff --git a/v3/@claude-flow/cli/src/mcp-tools/session-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/session-tools.ts
index abb17e32f2..b580d63c98 100644
--- a/v3/@claude-flow/cli/src/mcp-tools/session-tools.ts
+++ b/v3/@claude-flow/cli/src/mcp-tools/session-tools.ts
@@ -578,6 +578,9 @@ export const sessionTools: MCPTool[] = [
sessions.sort((a, b) => (b.stats?.totalSize ?? 0) - (a.stats?.totalSize ?? 0));
}
+ // Count every session before applying the limit so callers can tell when the list was truncated
+ const total = sessions.length;
+
// Apply limit
const limit = (input.limit as number) || 10;
sessions = sessions.slice(0, limit);
@@ -597,7 +600,7 @@ export const sessionTools: MCPTool[] = [
if ((s as Record<string, unknown>).metrics) projection.metrics = (s as Record<string, unknown>).metrics;
return projection;
}),
- total: sessions.length,
+ total,
limit,
};
},