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(claims): anchor MCP claims store to project cwd (#3210)

Daniel Peng59dd30c60e69
diff --git a/v3/@claude-flow/cli/__tests__/claims-project-cwd-3178.test.ts b/v3/@claude-flow/cli/__tests__/claims-project-cwd-3178.test.ts
new file mode 100644
index 0000000000..3a1e585fed
--- /dev/null
+++ b/v3/@claude-flow/cli/__tests__/claims-project-cwd-3178.test.ts
@@ -0,0 +1,120 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { claimsTools } from '../src/mcp-tools/claims-tools.js';
+import { ClaimService } from '../src/services/claim-service.js';
+
+describe('claims persistence uses the effective project cwd (#3178)', () => {
+ let originalCwd: string;
+ let project: string;
+ let firstCwd: string;
+ let secondCwd: string;
+
+ const call = (name: string, input: Record<string, unknown> = {}) =>
+ claimsTools.find(tool => tool.name === name)!.handler(input);
+ const claim = (issueId = '3178', claimant = 'agent:coder-1:coder') =>
+ call('claims_claim', { issueId, claimant });
+ const readStore = (root: string) =>
+ JSON.parse(readFileSync(join(root, '.claude-flow/claims/claims.json'), 'utf8'));
+
+ beforeEach(() => {
+ originalCwd = process.cwd();
+ project = mkdtempSync(join(tmpdir(), 'claims-project-cwd-'));
+ firstCwd = join(project, 'packages', 'first');
+ secondCwd = join(project, 'packages', 'second', 'src');
+ mkdirSync(firstCwd, { recursive: true });
+ mkdirSync(secondCwd, { recursive: true });
+ vi.stubEnv('CLAUDE_FLOW_CWD', project);
+ process.chdir(firstCwd);
+ });
+
+ afterEach(() => {
+ process.chdir(originalCwd);
+ vi.unstubAllEnvs();
+ rmSync(project, { recursive: true, force: true });
+ });
+
+ it('shares writes, queries, ownership checks and release across nested cwd values', async () => {
+ expect(await claim()).toMatchObject({ success: true });
+ expect(readStore(project).claims['3178']).toMatchObject({ issueId: '3178' });
+ process.chdir(secondCwd);
+ expect(await call('claims_list')).toMatchObject({ count: 1 });
+ expect(await call('claims_board')).toMatchObject({ summary: { total: 1, active: 1 } });
+ expect(await claim('3178', 'agent:coder-2:coder')).toMatchObject({ success: false });
+ expect(await call('claims_release', { issueId: '3178', claimant: 'agent:coder-2:coder' }))
+ .toMatchObject({ success: false });
+ expect(await call('claims_release', { issueId: '3178', claimant: 'agent:coder-1:coder' }))
+ .toMatchObject({ success: true });
+ process.chdir(firstCwd);
+ expect(await call('claims_list')).toMatchObject({ count: 0 });
+ expect(readStore(project).claims).toEqual({});
+ expect(existsSync(join(firstCwd, '.claude-flow'))).toBe(false);
+ expect(existsSync(join(secondCwd, '.claude-flow'))).toBe(false);
+ });
+
+ it('persists handoff and status changes in the same store', async () => {
+ expect(await claim()).toMatchObject({ success: true });
+ process.chdir(secondCwd);
+ expect(await call('claims_handoff', {
+ issueId: '3178', from: 'agent:coder-1:coder', to: 'human:alice:Alice', progress: 40,
+ })).toMatchObject({ success: true });
+ process.chdir(firstCwd);
+ expect(await call('claims_accept-handoff', { issueId: '3178', claimant: 'human:alice:Alice' }))
+ .toMatchObject({ success: true });
+ expect(await call('claims_status', { issueId: '3178', status: 'paused' }))
+ .toMatchObject({ success: true });
+ process.chdir(secondCwd);
+ expect(await call('claims_list', { status: 'paused', claimant: 'human:alice:Alice' }))
+ .toMatchObject({ count: 1 });
+ expect(readStore(project).claims['3178']).toMatchObject({ status: 'paused', progress: 40 });
+ });
+
+ it('shares stealable work and the resulting ownership change', async () => {
+ expect(await claim()).toMatchObject({ success: true });
+ expect(await call('claims_mark-stealable', { issueId: '3178', reason: 'voluntary' }))
+ .toMatchObject({ success: true });
+ process.chdir(secondCwd);
+ expect(await call('claims_stealable')).toMatchObject({ count: 1 });
+ expect(await call('claims_steal', { issueId: '3178', stealer: 'agent:coder-2:coder' }))
+ .toMatchObject({ success: true });
+ process.chdir(firstCwd);
+ expect(await call('claims_load', { agentId: 'coder-2' })).toMatchObject({ totalClaims: 1 });
+ expect(readStore(project).claims['3178'].claimant.agentId).toBe('coder-2');
+ expect(await call('claims_stealable')).toMatchObject({ count: 0 });
+ });
+
+ it('shares the current CLI/MCP store from nested directories', async () => {
+ const owner = { type: 'agent' as const, agentId: 'cli-worker', agentType: 'coder' };
+ const cli = new ClaimService(project);
+ await cli.initialize();
+ await cli.claim('cli-claim', owner);
+
+ expect(await claim('cli-claim')).toMatchObject({ success: false });
+ process.chdir(secondCwd);
+ expect(await claim('mcp-claim')).toMatchObject({ success: true });
+
+ const reopened = new ClaimService(project);
+ await reopened.initialize();
+ expect((await reopened.getAllClaims()).map(item => item.issueId).sort())
+ .toEqual(['cli-claim', 'mcp-claim']);
+ expect(existsSync(join(firstCwd, '.claude-flow'))).toBe(false);
+ expect(existsSync(join(secondCwd, '.claude-flow'))).toBe(false);
+ });
+
+ it.each([undefined, '/', process.env.HOME])('preserves cwd fallback for CLAUDE_FLOW_CWD=%s', async value => {
+ vi.stubEnv('CLAUDE_FLOW_CWD', value);
+ expect(await claim()).toMatchObject({ success: true });
+ expect(readStore(firstCwd).claims['3178']).toMatchObject({ issueId: '3178' });
+ expect(existsSync(join(project, '.claude-flow'))).toBe(false);
+ });
+
+ it('does not share claims between different effective project roots', async () => {
+ expect(await claim()).toMatchObject({ success: true });
+ vi.stubEnv('CLAUDE_FLOW_CWD', secondCwd);
+ expect(await call('claims_list')).toMatchObject({ count: 0 });
+ expect(await claim('3178', 'agent:coder-2:coder')).toMatchObject({ success: true });
+ expect(readStore(project).claims['3178'].claimant.agentId).toBe('coder-1');
+ expect(readStore(secondCwd).claims['3178'].claimant.agentId).toBe('coder-2');
+ });
+});
diff --git a/v3/@claude-flow/cli/src/mcp-tools/claims-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/claims-tools.ts
index 45bf7cec96..e766d56b68 100644
--- a/v3/@claude-flow/cli/src/mcp-tools/claims-tools.ts
+++ b/v3/@claude-flow/cli/src/mcp-tools/claims-tools.ts
@@ -7,7 +7,7 @@
* @module @claude-flow/cli/mcp-tools/claims
*/
-import type { MCPTool } from './types.js';
+import { type MCPTool, getProjectCwd } from './types.js';
import { readClaimsStore } from '../services/claims-store.js';
import { validateIdentifier, validateText } from './validate-input.js';
@@ -45,18 +45,18 @@ interface ClaimsStore {
// File-based persistence
import { existsSync, writeFileSync, mkdirSync } from 'fs';
-import { join, resolve } from 'path';
+import { resolve } from 'path';
const CLAIMS_DIR = '.claude-flow/claims';
const CLAIMS_FILE = 'claims.json';
const DEFAULT_MAX_CLAIMS = 5;
function getClaimsPath(): string {
- return resolve(join(CLAIMS_DIR, CLAIMS_FILE));
+ return resolve(getProjectCwd(), CLAIMS_DIR, CLAIMS_FILE);
}
function ensureClaimsDir(): void {
- const dir = resolve(CLAIMS_DIR);
+ const dir = resolve(getProjectCwd(), CLAIMS_DIR);
if (!existsSync(dir)) {
mkdirSync(dir, { recursive: true });
}