diff --git a/.strray/state/state.json b/.strray/state/state.json index 840bc4d53..6a4933d8f 100644 --- a/.strray/state/state.json +++ b/.strray/state/state.json @@ -1,17 +1,465 @@ { - "votingHistory": [], - "metrics": { - "totalVotes": 0, - "successfulVotes": 0, - "failedVotes": 0, - "averageConfidence": 0, - "strategyUsage": { - "majority_vote": 0, - "consensus": 0, - "expert_priority": 0 - }, - "agentParticipation": {}, - "averageVoterTurnout": 0 + "coordination:main_coordinator": { + "strRayOrchestrator": { + "taskQueue": {}, + "activeTasks": {}, + "totalProcessed": 0, + "config": { + "maxConcurrentTasks": 3, + "taskTimeout": 10000, + "conflictResolutionStrategy": "majority_vote" + }, + "kernel": { + "config": { + "enabled": true, + "confidenceThreshold": 0.75, + "maxPatternsPerAnalysis": 10, + "enableLearning": true, + "autoPrevention": true + }, + "patterns": {}, + "assumptions": {}, + "cascades": {} + } + }, + "enhancedOrchestrator": { + "state": { + "activeAgents": {}, + "pendingSpawns": [], + "completedAgents": {}, + "failedAgents": {}, + "agentDependencies": {}, + "monitoringEnabled": true, + "cleanupInterval": 30000, + "isMainOrchestrator": true + }, + "stateManager": { + "store": {}, + "persistencePath": "/Users/blaze/dev/stringray/.strray/state/state.json", + "persistenceEnabled": true, + "writeQueue": {}, + "initialized": true, + "earlyOperationsQueue": [] + }, + "complexityAnalyzer": { + "thresholds": { + "simple": 15, + "moderate": 25, + "complex": 50, + "enterprise": 75 + }, + "operationWeights": { + "create": 1, + "modify": 1.2, + "refactor": 1.8, + "analyze": 1.5, + "debug": 2, + "test": 1.3 + }, + "riskMultipliers": { + "low": 0.8, + "medium": 1, + "high": 1.3, + "critical": 1.6 + }, + "calibrationHistory": [] + }, + "agentDelegator": { + "complexityAnalyzer": { + "thresholds": { + "simple": 15, + "moderate": 25, + "complex": 50, + "enterprise": 75 + }, + "operationWeights": { + "create": 1, + "modify": 1.2, + "refactor": 1.8, + "analyze": 1.5, + "debug": 2, + "test": 1.3 + }, + "riskMultipliers": { + "low": 0.8, + "medium": 1, + "high": 1.3, + "critical": 1.6 + }, + "calibrationHistory": [] + }, + "stateManager": { + "store": {}, + "persistencePath": "/Users/blaze/dev/stringray/.strray/state/state.json", + "persistenceEnabled": true, + "writeQueue": {}, + "initialized": true, + "earlyOperationsQueue": [] + }, + "configLoader": { + "configPath": "/Users/blaze/dev/stringray/.strray/config.json", + "cachedConfig": null, + "cacheExpiry": 30000, + "lastLoadTime": 0 + }, + "kernel": { + "config": { + "enabled": true, + "confidenceThreshold": 0.75, + "maxPatternsPerAnalysis": 10, + "enableLearning": true, + "autoPrevention": true + }, + "patterns": {}, + "assumptions": {}, + "cascades": {} + }, + "agentMetrics": { + "stateManager": { + "store": {}, + "persistencePath": "/Users/blaze/dev/stringray/.strray/state/state.json", + "persistenceEnabled": true, + "writeQueue": {}, + "initialized": true, + "earlyOperationsQueue": [] + }, + "retentionConfig": { + "maxEntries": 10000, + "maxAgeMs": 2592000000, + "enableAutoCleanup": true, + "cleanupIntervalMs": 3600000 + }, + "initialized": false + } + }, + "executionContext": { + "isExecutingAsSubagent": false, + "currentAgentId": null, + "spawnStack": [] + }, + "cleanupTimer": null + }, + "agentDelegator": { + "complexityAnalyzer": { + "thresholds": { + "simple": 15, + "moderate": 25, + "complex": 50, + "enterprise": 75 + }, + "operationWeights": { + "create": 1, + "modify": 1.2, + "refactor": 1.8, + "analyze": 1.5, + "debug": 2, + "test": 1.3 + }, + "riskMultipliers": { + "low": 0.8, + "medium": 1, + "high": 1.3, + "critical": 1.6 + }, + "calibrationHistory": [] + }, + "stateManager": { + "store": {}, + "persistencePath": "/Users/blaze/dev/stringray/.strray/state/state.json", + "persistenceEnabled": true, + "writeQueue": {}, + "initialized": true, + "earlyOperationsQueue": [] + }, + "configLoader": { + "configPath": "/Users/blaze/dev/stringray/.strray/config.json", + "cachedConfig": null, + "cacheExpiry": 30000, + "lastLoadTime": 0 + }, + "kernel": { + "config": { + "enabled": true, + "confidenceThreshold": 0.75, + "maxPatternsPerAnalysis": 10, + "enableLearning": true, + "autoPrevention": true + }, + "patterns": {}, + "assumptions": {}, + "cascades": {} + }, + "agentMetrics": { + "stateManager": { + "store": {}, + "persistencePath": "/Users/blaze/dev/stringray/.strray/state/state.json", + "persistenceEnabled": true, + "writeQueue": {}, + "initialized": true, + "earlyOperationsQueue": [] + }, + "retentionConfig": { + "maxEntries": 10000, + "maxAgeMs": 2592000000, + "enableAutoCleanup": true, + "cleanupIntervalMs": 3600000 + }, + "initialized": false + } + }, + "stateManager": { + "store": {}, + "persistencePath": "/Users/blaze/dev/stringray/.strray/state/state.json", + "persistenceEnabled": true, + "writeQueue": {}, + "initialized": true, + "earlyOperationsQueue": [] + }, + "complexityAnalyzer": { + "thresholds": { + "simple": 15, + "moderate": 25, + "complex": 50, + "enterprise": 75 + }, + "operationWeights": { + "create": 1, + "modify": 1.2, + "refactor": 1.8, + "analyze": 1.5, + "debug": 2, + "test": 1.3 + }, + "riskMultipliers": { + "low": 0.8, + "medium": 1, + "high": 1.3, + "critical": 1.6 + }, + "calibrationHistory": [] + }, + "coordinationMetrics": { + "totalWorkflows": 0, + "successfulWorkflows": 0, + "failedWorkflows": 0, + "averageDuration": 0, + "agentUtilization": {}, + "coordinationEfficiency": 0 + } + }, + "coordination:strray_orchestrator": { + "taskQueue": {}, + "activeTasks": {}, + "totalProcessed": 0, + "config": { + "maxConcurrentTasks": 3, + "taskTimeout": 10000, + "conflictResolutionStrategy": "majority_vote" + }, + "kernel": { + "config": { + "enabled": true, + "confidenceThreshold": 0.75, + "maxPatternsPerAnalysis": 10, + "enableLearning": true, + "autoPrevention": true + }, + "patterns": {}, + "assumptions": {}, + "cascades": {} + } + }, + "coordination:enhanced_orchestrator": { + "state": { + "activeAgents": {}, + "pendingSpawns": [], + "completedAgents": {}, + "failedAgents": {}, + "agentDependencies": {}, + "monitoringEnabled": true, + "cleanupInterval": 30000, + "isMainOrchestrator": true + }, + "stateManager": { + "store": {}, + "persistencePath": "/Users/blaze/dev/stringray/.strray/state/state.json", + "persistenceEnabled": true, + "writeQueue": {}, + "initialized": true, + "earlyOperationsQueue": [] + }, + "complexityAnalyzer": { + "thresholds": { + "simple": 15, + "moderate": 25, + "complex": 50, + "enterprise": 75 + }, + "operationWeights": { + "create": 1, + "modify": 1.2, + "refactor": 1.8, + "analyze": 1.5, + "debug": 2, + "test": 1.3 + }, + "riskMultipliers": { + "low": 0.8, + "medium": 1, + "high": 1.3, + "critical": 1.6 + }, + "calibrationHistory": [] + }, + "agentDelegator": { + "complexityAnalyzer": { + "thresholds": { + "simple": 15, + "moderate": 25, + "complex": 50, + "enterprise": 75 + }, + "operationWeights": { + "create": 1, + "modify": 1.2, + "refactor": 1.8, + "analyze": 1.5, + "debug": 2, + "test": 1.3 + }, + "riskMultipliers": { + "low": 0.8, + "medium": 1, + "high": 1.3, + "critical": 1.6 + }, + "calibrationHistory": [] + }, + "stateManager": { + "store": {}, + "persistencePath": "/Users/blaze/dev/stringray/.strray/state/state.json", + "persistenceEnabled": true, + "writeQueue": {}, + "initialized": true, + "earlyOperationsQueue": [] + }, + "configLoader": { + "configPath": "/Users/blaze/dev/stringray/.strray/config.json", + "cachedConfig": null, + "cacheExpiry": 30000, + "lastLoadTime": 0 + }, + "kernel": { + "config": { + "enabled": true, + "confidenceThreshold": 0.75, + "maxPatternsPerAnalysis": 10, + "enableLearning": true, + "autoPrevention": true + }, + "patterns": {}, + "assumptions": {}, + "cascades": {} + }, + "agentMetrics": { + "stateManager": { + "store": {}, + "persistencePath": "/Users/blaze/dev/stringray/.strray/state/state.json", + "persistenceEnabled": true, + "writeQueue": {}, + "initialized": true, + "earlyOperationsQueue": [] + }, + "retentionConfig": { + "maxEntries": 10000, + "maxAgeMs": 2592000000, + "enableAutoCleanup": true, + "cleanupIntervalMs": 3600000 + }, + "initialized": false + } + }, + "executionContext": { + "isExecutingAsSubagent": false, + "currentAgentId": null, + "spawnStack": [] + }, + "cleanupTimer": null + }, + "coordination:agent_delegator": { + "complexityAnalyzer": { + "thresholds": { + "simple": 15, + "moderate": 25, + "complex": 50, + "enterprise": 75 + }, + "operationWeights": { + "create": 1, + "modify": 1.2, + "refactor": 1.8, + "analyze": 1.5, + "debug": 2, + "test": 1.3 + }, + "riskMultipliers": { + "low": 0.8, + "medium": 1, + "high": 1.3, + "critical": 1.6 + }, + "calibrationHistory": [] + }, + "stateManager": { + "store": {}, + "persistencePath": "/Users/blaze/dev/stringray/.strray/state/state.json", + "persistenceEnabled": true, + "writeQueue": {}, + "initialized": true, + "earlyOperationsQueue": [] + }, + "configLoader": { + "configPath": "/Users/blaze/dev/stringray/.strray/config.json", + "cachedConfig": null, + "cacheExpiry": 30000, + "lastLoadTime": 0 + }, + "kernel": { + "config": { + "enabled": true, + "confidenceThreshold": 0.75, + "maxPatternsPerAnalysis": 10, + "enableLearning": true, + "autoPrevention": true + }, + "patterns": {}, + "assumptions": {}, + "cascades": {} + }, + "agentMetrics": { + "stateManager": { + "store": {}, + "persistencePath": "/Users/blaze/dev/stringray/.strray/state/state.json", + "persistenceEnabled": true, + "writeQueue": {}, + "initialized": true, + "earlyOperationsQueue": [] + }, + "retentionConfig": { + "maxEntries": 10000, + "maxAgeMs": 2592000000, + "enableAutoCleanup": true, + "cleanupIntervalMs": 3600000 + }, + "initialized": false + } }, - "exportedAt": "2026-05-15T14:18:59.026Z" + "coordination:metrics": { + "totalWorkflows": 0, + "successfulWorkflows": 0, + "failedWorkflows": 0, + "averageDuration": 0, + "agentUtilization": {}, + "coordinationEfficiency": 0 + } } \ No newline at end of file diff --git a/src/inference/inference-cycle.ts b/src/inference/inference-cycle.ts index 9887d52c0..e78645220 100644 --- a/src/inference/inference-cycle.ts +++ b/src/inference/inference-cycle.ts @@ -804,11 +804,32 @@ Respond with EXACTLY one of: codify: ["code-review", "security-audit", "researcher"], }; + // Pre-warm the three real MCP servers so the first real calls are fast + const govServers = ["code-review", "security-audit", "researcher"]; + console.error(`[LIVE] Pre-warming real MCP servers: ${govServers.join(", ")}`); + await Promise.all( + govServers.map(async (srv) => { + try { + await mcpClientManager.callServerTool(srv, "analyze_proposal", { + proposalTitle: "warmup", + proposalDescription: "warmup", + evidence: [], + proposalType: "fix", + }); + console.error(`[LIVE] ✓ ${srv} ready`); + } catch { + console.error(`[LIVE] (warmup for ${srv} will happen on first real call)`); + } + }) + ); + for (const proposal of proposals) { + console.error(`[LIVE] Governing proposal: ${proposal.title}`); const agents = GOVERNANCE_AGENTS[proposal.type] ?? ["code-review", "security-audit"]; - const skillVotes: any[] = []; - for (const agent of agents) { + const callPromises = agents.map(async (agent) => { + const t0 = Date.now(); + console.error(`[LIVE] → real call to ${agent} ...`); try { const skillResult = await mcpClientManager.callServerTool(agent, "analyze_proposal", { proposalTitle: proposal.title, @@ -816,6 +837,7 @@ Respond with EXACTLY one of: evidence: proposal.evidence, proposalType: proposal.type, }); + const dur = Date.now() - t0; let structured = ""; const contents = (skillResult as any)?.content || []; @@ -831,21 +853,27 @@ Respond with EXACTLY one of: if (m) structured = m[0].trim(); } - skillVotes.push({ + console.error(`[LIVE] ← ${agent} done in ${dur}ms → ${structured ? structured.split('\n')[0] : 'no structured vote'}`); + + return { agent, toolUsed: "analyze_proposal", rawResponse: structured || JSON.stringify(skillResult), structuredVote: structured || null, - }); + }; } catch (err) { - skillVotes.push({ + const dur = Date.now() - t0; + console.error(`[LIVE] ← ERROR from ${agent} after ${dur}ms: ${err}`); + return { agent, toolUsed: "analyze_proposal", rawResponse: `error: ${err}`, structuredVote: null, - }); + }; } - } + }); + + const skillVotes = await Promise.all(callPromises); const approves = skillVotes.filter((v: any) => v.structuredVote && v.structuredVote.includes("DECISION: approve")).length; const rejects = skillVotes.filter((v: any) => v.structuredVote && v.structuredVote.includes("DECISION: reject")).length; diff --git a/src/mcps/knowledge-skills/code-review.server.ts b/src/mcps/knowledge-skills/code-review.server.ts index 475366735..fffe372b7 100644 --- a/src/mcps/knowledge-skills/code-review.server.ts +++ b/src/mcps/knowledge-skills/code-review.server.ts @@ -492,44 +492,7 @@ class StringRayCodeReviewServer { return languageMap[extension] || "unknown"; } - /** - * Governance-oriented proposal analysis from a code quality perspective. - */ - private async analyzeProposal(args: any) { - const { proposalTitle = "", proposalDescription = "", evidence = [], proposalType = "" } = args; - const text = `${proposalTitle} ${proposalDescription} ${evidence.join(" ")}`.toLowerCase(); - - let decision: "approve" | "reject" | "abstain" = "approve"; - let confidence = 0.82; - let reasoning = "The proposal appears reasonable from a code quality and maintainability perspective."; - - if (text.includes("extract method")) { - decision = "approve"; - confidence = 0.93; - reasoning = "Extract Method is a well-established refactoring pattern that improves readability and reduces cognitive load when applied consistently."; - } else if (text.includes("test coverage")) { - decision = "approve"; - confidence = 0.90; - reasoning = "Expanding automated test coverage generally improves long-term code health and reduces regression risk."; - } else if (text.includes("increase timeout") && text.includes("flaky")) { - decision = "reject"; - confidence = 0.72; - reasoning = "Repeatedly increasing timeouts to mask flaky tests is an anti-pattern that hides underlying race conditions or timing issues."; - } - - if (proposalType === "fix" && text.includes("timeout")) { - confidence = Math.max(0.68, confidence - 0.08); - } - - return { - content: [ - { - type: "text", - text: `DECISION: ${decision}\nCONFIDENCE: ${confidence.toFixed(2)}\nREASONING: ${reasoning}`, - }, - ], - }; - } + private analyzeCode( content: string,