🌊 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(learning): preserve zero quality and reject invalid scores
Rudy Celeklic2a8ad58e2f7
diff --git a/v3/@claude-flow/cli/__tests__/learning-quality-input.test.ts b/v3/@claude-flow/cli/__tests__/learning-quality-input.test.tsnew file mode 100644index 0000000000..2f099463e5--- /dev/null+++ b/v3/@claude-flow/cli/__tests__/learning-quality-input.test.ts@@ -0,0 +1,34 @@+import { beforeEach, describe, expect, it, vi } from 'vitest';+const feedback = vi.fn(async () => ({ success: true, controller: 'test', updated: 1 }));+const edge = vi.fn();+vi.mock('../src/memory/memory-bridge.js', () => ({ bridgeRecordFeedback: feedback, bridgeRecordCausalEdge: edge, bridgeStoreEntry: vi.fn() }));+vi.mock('../src/memory/intelligence.js', () => ({ recordTrajectory: vi.fn(async () => false) }));+vi.mock('../src/memory/graph-edge-writer.js', () => ({ insertGraphEdge: edge }));+vi.mock('../src/memory/memory-initializer.js', () => ({ storeEntry: vi.fn(async () => ({ success: true, id: 'pending' })) }));+vi.mock('../src/ruvector/trajectory-tree.js', () => ({ getTrajectoryTree: () => ({ openTrajectory() {}, appendStep() {} }) }));+const { hooksPostTask, hooksTrajectoryStart, hooksTrajectoryStep } = await import('../src/mcp-tools/hooks-tools.js');+beforeEach(() => { feedback.mockClear(); edge.mockClear(); });++describe('learning quality input', () => {+ it('preserves explicit zero task quality in feedback and causal writes', async () => {+ await hooksPostTask.handler({ taskId: 'quality-zero', quality: 0 });+ expect(feedback).toHaveBeenCalledWith(expect.objectContaining({ quality: 0 }));+ expect(edge).toHaveBeenCalledWith(expect.objectContaining({ weight: 0 }));+ });+ it('preserves zero quality in recorded trajectory steps', async () => {+ const start = await hooksTrajectoryStart.handler({ task: 'quality zero' }) as any;+ expect(await hooksTrajectoryStep.handler({ trajectoryId: start.trajectoryId, action: 'failed step', quality: 0 })).toMatchObject({ recorded: true, quality: 0 });+ });+ for (const quality of [-1, 1.1, Number.NaN, Number.POSITIVE_INFINITY, '0.5', null]) {+ it(`rejects invalid quality ${String(quality)} before writes`, async () => {+ expect(await hooksPostTask.handler({ taskId: 'invalid-quality', quality })).toMatchObject({ success: false, error: expect.any(String) });+ expect(await hooksTrajectoryStep.handler({ trajectoryId: 'trajectory', action: 'step', quality })).toMatchObject({ success: false, error: expect.any(String) });+ expect(feedback).not.toHaveBeenCalled();+ expect(edge).not.toHaveBeenCalled();+ });+ }+ it.each([[true, 0.85], [false, 0.3]])('retains the omitted-quality default for success=%s', async (success, quality) => {+ await hooksPostTask.handler({ taskId: 'default-quality', success });+ expect(feedback).toHaveBeenCalledWith(expect.objectContaining({ quality }));+ });+});diff --git a/v3/@claude-flow/cli/src/mcp-tools/hooks-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/hooks-tools.tsindex 32cf57dbc4..3a7138aaf7 100644--- a/v3/@claude-flow/cli/src/mcp-tools/hooks-tools.ts+++ b/v3/@claude-flow/cli/src/mcp-tools/hooks-tools.ts@@ -1656,7 +1656,7 @@ export const hooksPostTask: MCPTool = {taskId: { type: 'string', description: 'Task identifier' },success: { type: 'boolean', description: 'Whether task was successful' },agent: { type: 'string', description: 'Agent that completed the task' },- quality: { type: 'number', description: 'Quality score (0-1)' },+ quality: { type: 'number', minimum: 0, maximum: 1, description: 'Quality score (0-1)' },task: { type: 'string', description: 'Task description text (used for learning keyword extraction)' },duration: { type: 'number', description: 'Observed task duration in milliseconds (used by pheromone-adaptive topology)' },latencyBudgetMs: { type: 'number', description: 'Latency budget used to normalize duration (default 60000ms)' },@@ -1673,7 +1673,11 @@ export const hooksPostTask: MCPTool = {const taskId = params.taskId as string;const success = params.success !== false;const agent = params.agent as string | undefined;- const quality = (params.quality as number) || (success ? 0.85 : 0.3);+ if (params.quality !== undefined && (typeof params.quality !== 'number'+ || !Number.isFinite(params.quality) || params.quality < 0 || params.quality > 1)) {+ return { success: false, error: 'quality must be a finite number between 0 and 1' };+ }+ const quality = params.quality === undefined ? (success ? 0.85 : 0.3) : params.quality as number;const startTime = Date.now();{ const v = validateIdentifier(taskId, 'taskId'); if (!v.valid) return { success: false, error: v.error }; }@@ -3041,7 +3045,7 @@ export const hooksTrajectoryStep: MCPTool = {trajectoryId: { type: 'string', description: 'Trajectory ID' },action: { type: 'string', description: 'Action taken' },result: { type: 'string', description: 'Action result' },- quality: { type: 'number', description: 'Quality score (0-1)' },+ quality: { type: 'number', minimum: 0, maximum: 1, description: 'Quality score (0-1)' },},required: ['trajectoryId', 'action'],},@@ -3051,7 +3055,11 @@ export const hooksTrajectoryStep: MCPTool = {// the learning signal (DISTILL embeds this text).const action = scrubReasoningBlocks(params.action as string);const result = scrubReasoningBlocks((params.result as string) || 'success');- const quality = (params.quality as number) || 0.85;+ if (params.quality !== undefined && (typeof params.quality !== 'number'+ || !Number.isFinite(params.quality) || params.quality < 0 || params.quality > 1)) {+ return { success: false, error: 'quality must be a finite number between 0 and 1' };+ }+ const quality = params.quality === undefined ? 0.85 : params.quality as number;const timestamp = new Date().toISOString();const stepId = `step-${Date.now()}`;