synapsexcoder 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.opencode/opencode.jsonc +102 -0
- package/README.md +353 -0
- package/dist/agents/agent-config-manager.d.ts +58 -0
- package/dist/agents/agent-config-manager.d.ts.map +1 -0
- package/dist/agents/agent-config-manager.js +313 -0
- package/dist/agents/agent-config-manager.js.map +1 -0
- package/dist/agents/base-agents.d.ts +352 -0
- package/dist/agents/base-agents.d.ts.map +1 -0
- package/dist/agents/base-agents.js +3961 -0
- package/dist/agents/base-agents.js.map +1 -0
- package/dist/agents/gated-subagent.d.ts +126 -0
- package/dist/agents/gated-subagent.d.ts.map +1 -0
- package/dist/agents/gated-subagent.js +591 -0
- package/dist/agents/gated-subagent.js.map +1 -0
- package/dist/agents/gated-subagents.d.ts +130 -0
- package/dist/agents/gated-subagents.d.ts.map +1 -0
- package/dist/agents/gated-subagents.js +2014 -0
- package/dist/agents/gated-subagents.js.map +1 -0
- package/dist/agents/internal-gatekeeper.d.ts +167 -0
- package/dist/agents/internal-gatekeeper.d.ts.map +1 -0
- package/dist/agents/internal-gatekeeper.js +1130 -0
- package/dist/agents/internal-gatekeeper.js.map +1 -0
- package/dist/agents/verification-agent.d.ts +86 -0
- package/dist/agents/verification-agent.d.ts.map +1 -0
- package/dist/agents/verification-agent.js +211 -0
- package/dist/agents/verification-agent.js.map +1 -0
- package/dist/analytics/analytics-types.d.ts +113 -0
- package/dist/analytics/analytics-types.d.ts.map +1 -0
- package/dist/analytics/analytics-types.js +8 -0
- package/dist/analytics/analytics-types.js.map +1 -0
- package/dist/analytics/dashboard-generator.d.ts +35 -0
- package/dist/analytics/dashboard-generator.d.ts.map +1 -0
- package/dist/analytics/dashboard-generator.js +365 -0
- package/dist/analytics/dashboard-generator.js.map +1 -0
- package/dist/analytics/index.d.ts +12 -0
- package/dist/analytics/index.d.ts.map +1 -0
- package/dist/analytics/index.js +12 -0
- package/dist/analytics/index.js.map +1 -0
- package/dist/analytics/metrics-aggregator.d.ts +88 -0
- package/dist/analytics/metrics-aggregator.d.ts.map +1 -0
- package/dist/analytics/metrics-aggregator.js +280 -0
- package/dist/analytics/metrics-aggregator.js.map +1 -0
- package/dist/cli/index.d.ts +36 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +2677 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/normalize_patch.d.ts +3 -0
- package/dist/cli/normalize_patch.d.ts.map +1 -0
- package/dist/cli/normalize_patch.js +34 -0
- package/dist/cli/normalize_patch.js.map +1 -0
- package/dist/commands/command-processor.d.ts +58 -0
- package/dist/commands/command-processor.d.ts.map +1 -0
- package/dist/commands/command-processor.js +796 -0
- package/dist/commands/command-processor.js.map +1 -0
- package/dist/config/compliance-checker.d.ts +93 -0
- package/dist/config/compliance-checker.d.ts.map +1 -0
- package/dist/config/compliance-checker.js +424 -0
- package/dist/config/compliance-checker.js.map +1 -0
- package/dist/config/enterprise-config.d.ts +173 -0
- package/dist/config/enterprise-config.d.ts.map +1 -0
- package/dist/config/enterprise-config.js +190 -0
- package/dist/config/enterprise-config.js.map +1 -0
- package/dist/config/index.d.ts +13 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +11 -0
- package/dist/config/index.js.map +1 -0
- package/dist/context/context-system.d.ts +97 -0
- package/dist/context/context-system.d.ts.map +1 -0
- package/dist/context/context-system.js +880 -0
- package/dist/context/context-system.js.map +1 -0
- package/dist/context/store.d.ts +123 -0
- package/dist/context/store.d.ts.map +1 -0
- package/dist/context/store.js +281 -0
- package/dist/context/store.js.map +1 -0
- package/dist/dasp/dasp-controller.d.ts +83 -0
- package/dist/dasp/dasp-controller.d.ts.map +1 -0
- package/dist/dasp/dasp-controller.js +190 -0
- package/dist/dasp/dasp-controller.js.map +1 -0
- package/dist/dasp/feedback-adapter.d.ts +56 -0
- package/dist/dasp/feedback-adapter.d.ts.map +1 -0
- package/dist/dasp/feedback-adapter.js +158 -0
- package/dist/dasp/feedback-adapter.js.map +1 -0
- package/dist/dasp/index.d.ts +14 -0
- package/dist/dasp/index.d.ts.map +1 -0
- package/dist/dasp/index.js +10 -0
- package/dist/dasp/index.js.map +1 -0
- package/dist/dasp/prompt-templates.d.ts +38 -0
- package/dist/dasp/prompt-templates.d.ts.map +1 -0
- package/dist/dasp/prompt-templates.js +406 -0
- package/dist/dasp/prompt-templates.js.map +1 -0
- package/dist/dasp/vault-rag-provider.d.ts +51 -0
- package/dist/dasp/vault-rag-provider.d.ts.map +1 -0
- package/dist/dasp/vault-rag-provider.js +125 -0
- package/dist/dasp/vault-rag-provider.js.map +1 -0
- package/dist/distribution/cli-distribution.d.ts +68 -0
- package/dist/distribution/cli-distribution.d.ts.map +1 -0
- package/dist/distribution/cli-distribution.js +941 -0
- package/dist/distribution/cli-distribution.js.map +1 -0
- package/dist/docs/doc-generator.d.ts +78 -0
- package/dist/docs/doc-generator.d.ts.map +1 -0
- package/dist/docs/doc-generator.js +297 -0
- package/dist/docs/doc-generator.js.map +1 -0
- package/dist/docs/index.d.ts +13 -0
- package/dist/docs/index.d.ts.map +1 -0
- package/dist/docs/index.js +11 -0
- package/dist/docs/index.js.map +1 -0
- package/dist/docs/site-builder.d.ts +58 -0
- package/dist/docs/site-builder.d.ts.map +1 -0
- package/dist/docs/site-builder.js +229 -0
- package/dist/docs/site-builder.js.map +1 -0
- package/dist/ecosystem/adapters/claude-adapter.d.ts +29 -0
- package/dist/ecosystem/adapters/claude-adapter.d.ts.map +1 -0
- package/dist/ecosystem/adapters/claude-adapter.js +116 -0
- package/dist/ecosystem/adapters/claude-adapter.js.map +1 -0
- package/dist/ecosystem/adapters/cursor-adapter.d.ts +27 -0
- package/dist/ecosystem/adapters/cursor-adapter.d.ts.map +1 -0
- package/dist/ecosystem/adapters/cursor-adapter.js +93 -0
- package/dist/ecosystem/adapters/cursor-adapter.js.map +1 -0
- package/dist/ecosystem/adapters/v0-adapter.d.ts +30 -0
- package/dist/ecosystem/adapters/v0-adapter.d.ts.map +1 -0
- package/dist/ecosystem/adapters/v0-adapter.js +112 -0
- package/dist/ecosystem/adapters/v0-adapter.js.map +1 -0
- package/dist/ecosystem/ecosystem-router.d.ts +80 -0
- package/dist/ecosystem/ecosystem-router.d.ts.map +1 -0
- package/dist/ecosystem/ecosystem-router.js +241 -0
- package/dist/ecosystem/ecosystem-router.js.map +1 -0
- package/dist/ecosystem/ecosystem-types.d.ts +94 -0
- package/dist/ecosystem/ecosystem-types.d.ts.map +1 -0
- package/dist/ecosystem/ecosystem-types.js +27 -0
- package/dist/ecosystem/ecosystem-types.js.map +1 -0
- package/dist/ecosystem/index.d.ts +10 -0
- package/dist/ecosystem/index.d.ts.map +1 -0
- package/dist/ecosystem/index.js +9 -0
- package/dist/ecosystem/index.js.map +1 -0
- package/dist/integration/agentic-integration.d.ts +73 -0
- package/dist/integration/agentic-integration.d.ts.map +1 -0
- package/dist/integration/agentic-integration.js +253 -0
- package/dist/integration/agentic-integration.js.map +1 -0
- package/dist/integration/background-agents-integration.d.ts +54 -0
- package/dist/integration/background-agents-integration.d.ts.map +1 -0
- package/dist/integration/background-agents-integration.js +225 -0
- package/dist/integration/background-agents-integration.js.map +1 -0
- package/dist/integration/dcp-integration.d.ts +81 -0
- package/dist/integration/dcp-integration.d.ts.map +1 -0
- package/dist/integration/dcp-integration.js +189 -0
- package/dist/integration/dcp-integration.js.map +1 -0
- package/dist/integration/firecrawl-integration.d.ts +61 -0
- package/dist/integration/firecrawl-integration.d.ts.map +1 -0
- package/dist/integration/firecrawl-integration.js +246 -0
- package/dist/integration/firecrawl-integration.js.map +1 -0
- package/dist/integration/index.d.ts +40 -0
- package/dist/integration/index.d.ts.map +1 -0
- package/dist/integration/index.js +43 -0
- package/dist/integration/index.js.map +1 -0
- package/dist/integration/integration-hub.d.ts +43 -0
- package/dist/integration/integration-hub.d.ts.map +1 -0
- package/dist/integration/integration-hub.js +507 -0
- package/dist/integration/integration-hub.js.map +1 -0
- package/dist/integration/integration-loader.d.ts +42 -0
- package/dist/integration/integration-loader.d.ts.map +1 -0
- package/dist/integration/integration-loader.js +240 -0
- package/dist/integration/integration-loader.js.map +1 -0
- package/dist/integration/md-table-formatter-integration.d.ts +41 -0
- package/dist/integration/md-table-formatter-integration.d.ts.map +1 -0
- package/dist/integration/md-table-formatter-integration.js +183 -0
- package/dist/integration/md-table-formatter-integration.js.map +1 -0
- package/dist/integration/native/agentic/agentic-engine.d.ts +52 -0
- package/dist/integration/native/agentic/agentic-engine.d.ts.map +1 -0
- package/dist/integration/native/agentic/agentic-engine.js +267 -0
- package/dist/integration/native/agentic/agentic-engine.js.map +1 -0
- package/dist/integration/native/background/background-engine.d.ts +62 -0
- package/dist/integration/native/background/background-engine.d.ts.map +1 -0
- package/dist/integration/native/background/background-engine.js +167 -0
- package/dist/integration/native/background/background-engine.js.map +1 -0
- package/dist/integration/native/dcp/dcp-engine.d.ts +55 -0
- package/dist/integration/native/dcp/dcp-engine.d.ts.map +1 -0
- package/dist/integration/native/dcp/dcp-engine.js +168 -0
- package/dist/integration/native/dcp/dcp-engine.js.map +1 -0
- package/dist/integration/native/firecrawl/firecrawl-engine.d.ts +66 -0
- package/dist/integration/native/firecrawl/firecrawl-engine.d.ts.map +1 -0
- package/dist/integration/native/firecrawl/firecrawl-engine.js +221 -0
- package/dist/integration/native/firecrawl/firecrawl-engine.js.map +1 -0
- package/dist/integration/native/formatter/formatter-engine.d.ts +47 -0
- package/dist/integration/native/formatter/formatter-engine.d.ts.map +1 -0
- package/dist/integration/native/formatter/formatter-engine.js +130 -0
- package/dist/integration/native/formatter/formatter-engine.js.map +1 -0
- package/dist/integration/native/index.d.ts +41 -0
- package/dist/integration/native/index.d.ts.map +1 -0
- package/dist/integration/native/index.js +80 -0
- package/dist/integration/native/index.js.map +1 -0
- package/dist/integration/native/orchestration/orchestration-engine.d.ts +62 -0
- package/dist/integration/native/orchestration/orchestration-engine.d.ts.map +1 -0
- package/dist/integration/native/orchestration/orchestration-engine.js +177 -0
- package/dist/integration/native/orchestration/orchestration-engine.js.map +1 -0
- package/dist/integration/native/pty/pty-engine.d.ts +45 -0
- package/dist/integration/native/pty/pty-engine.d.ts.map +1 -0
- package/dist/integration/native/pty/pty-engine.js +103 -0
- package/dist/integration/native/pty/pty-engine.js.map +1 -0
- package/dist/integration/native/shell-strategy.d.ts +60 -0
- package/dist/integration/native/shell-strategy.d.ts.map +1 -0
- package/dist/integration/native/shell-strategy.js +131 -0
- package/dist/integration/native/shell-strategy.js.map +1 -0
- package/dist/integration/native/skillful/skillful-engine.d.ts +53 -0
- package/dist/integration/native/skillful/skillful-engine.d.ts.map +1 -0
- package/dist/integration/native/skillful/skillful-engine.js +127 -0
- package/dist/integration/native/skillful/skillful-engine.js.map +1 -0
- package/dist/integration/native/subtask2/subtask2-engine.d.ts +50 -0
- package/dist/integration/native/subtask2/subtask2-engine.d.ts.map +1 -0
- package/dist/integration/native/subtask2/subtask2-engine.js +158 -0
- package/dist/integration/native/subtask2/subtask2-engine.js.map +1 -0
- package/dist/integration/native/supermemory/supermemory-engine.d.ts +63 -0
- package/dist/integration/native/supermemory/supermemory-engine.d.ts.map +1 -0
- package/dist/integration/native/supermemory/supermemory-engine.js +127 -0
- package/dist/integration/native/supermemory/supermemory-engine.js.map +1 -0
- package/dist/integration/native/workspace/workspace-engine.d.ts +75 -0
- package/dist/integration/native/workspace/workspace-engine.d.ts.map +1 -0
- package/dist/integration/native/workspace/workspace-engine.js +216 -0
- package/dist/integration/native/workspace/workspace-engine.js.map +1 -0
- package/dist/integration/oh-my-opencode-integration.d.ts +59 -0
- package/dist/integration/oh-my-opencode-integration.d.ts.map +1 -0
- package/dist/integration/oh-my-opencode-integration.js +180 -0
- package/dist/integration/oh-my-opencode-integration.js.map +1 -0
- package/dist/integration/openagents-control-integration.d.ts +81 -0
- package/dist/integration/openagents-control-integration.d.ts.map +1 -0
- package/dist/integration/openagents-control-integration.js +273 -0
- package/dist/integration/openagents-control-integration.js.map +1 -0
- package/dist/integration/pty-integration.d.ts +64 -0
- package/dist/integration/pty-integration.d.ts.map +1 -0
- package/dist/integration/pty-integration.js +180 -0
- package/dist/integration/pty-integration.js.map +1 -0
- package/dist/integration/shell-strategy-integration.d.ts +26 -0
- package/dist/integration/shell-strategy-integration.d.ts.map +1 -0
- package/dist/integration/shell-strategy-integration.js +110 -0
- package/dist/integration/shell-strategy-integration.js.map +1 -0
- package/dist/integration/skillful-integration.d.ts +74 -0
- package/dist/integration/skillful-integration.d.ts.map +1 -0
- package/dist/integration/skillful-integration.js +317 -0
- package/dist/integration/skillful-integration.js.map +1 -0
- package/dist/integration/subtask2-integration.d.ts +71 -0
- package/dist/integration/subtask2-integration.d.ts.map +1 -0
- package/dist/integration/subtask2-integration.js +240 -0
- package/dist/integration/subtask2-integration.js.map +1 -0
- package/dist/integration/supermemory-integration.d.ts +82 -0
- package/dist/integration/supermemory-integration.d.ts.map +1 -0
- package/dist/integration/supermemory-integration.js +252 -0
- package/dist/integration/supermemory-integration.js.map +1 -0
- package/dist/integration/types.d.ts +218 -0
- package/dist/integration/types.d.ts.map +1 -0
- package/dist/integration/types.js +5 -0
- package/dist/integration/types.js.map +1 -0
- package/dist/integration/workspace-integration.d.ts +46 -0
- package/dist/integration/workspace-integration.d.ts.map +1 -0
- package/dist/integration/workspace-integration.js +181 -0
- package/dist/integration/workspace-integration.js.map +1 -0
- package/dist/knowledge-vault/deepwiki-sync.d.ts +99 -0
- package/dist/knowledge-vault/deepwiki-sync.d.ts.map +1 -0
- package/dist/knowledge-vault/deepwiki-sync.js +381 -0
- package/dist/knowledge-vault/deepwiki-sync.js.map +1 -0
- package/dist/knowledge-vault/index.d.ts +11 -0
- package/dist/knowledge-vault/index.d.ts.map +1 -0
- package/dist/knowledge-vault/index.js +8 -0
- package/dist/knowledge-vault/index.js.map +1 -0
- package/dist/knowledge-vault/knowledge-vault.d.ts +38 -0
- package/dist/knowledge-vault/knowledge-vault.d.ts.map +1 -0
- package/dist/knowledge-vault/knowledge-vault.js +284 -0
- package/dist/knowledge-vault/knowledge-vault.js.map +1 -0
- package/dist/knowledge-vault/opencode-doc-ingest.d.ts +23 -0
- package/dist/knowledge-vault/opencode-doc-ingest.d.ts.map +1 -0
- package/dist/knowledge-vault/opencode-doc-ingest.js +48 -0
- package/dist/knowledge-vault/opencode-doc-ingest.js.map +1 -0
- package/dist/knowledge-vault/types.d.ts +61 -0
- package/dist/knowledge-vault/types.d.ts.map +1 -0
- package/dist/knowledge-vault/types.js +5 -0
- package/dist/knowledge-vault/types.js.map +1 -0
- package/dist/knowledge-vault/vault-config.d.ts +12 -0
- package/dist/knowledge-vault/vault-config.d.ts.map +1 -0
- package/dist/knowledge-vault/vault-config.js +24 -0
- package/dist/knowledge-vault/vault-config.js.map +1 -0
- package/dist/mcp/index.d.ts +28 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +29 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/mcp-manager.d.ts +181 -0
- package/dist/mcp/mcp-manager.d.ts.map +1 -0
- package/dist/mcp/mcp-manager.js +621 -0
- package/dist/mcp/mcp-manager.js.map +1 -0
- package/dist/mcp/mcp-types.d.ts +199 -0
- package/dist/mcp/mcp-types.d.ts.map +1 -0
- package/dist/mcp/mcp-types.js +152 -0
- package/dist/mcp/mcp-types.js.map +1 -0
- package/dist/mcp/servers/mcp-server-bridge.d.ts +64 -0
- package/dist/mcp/servers/mcp-server-bridge.d.ts.map +1 -0
- package/dist/mcp/servers/mcp-server-bridge.js +189 -0
- package/dist/mcp/servers/mcp-server-bridge.js.map +1 -0
- package/dist/messages/message-bus.d.ts +148 -0
- package/dist/messages/message-bus.d.ts.map +1 -0
- package/dist/messages/message-bus.js +432 -0
- package/dist/messages/message-bus.js.map +1 -0
- package/dist/modes/custom-mode-registry.d.ts +121 -0
- package/dist/modes/custom-mode-registry.d.ts.map +1 -0
- package/dist/modes/custom-mode-registry.js +306 -0
- package/dist/modes/custom-mode-registry.js.map +1 -0
- package/dist/modes/index.d.ts +10 -0
- package/dist/modes/index.d.ts.map +1 -0
- package/dist/modes/index.js +8 -0
- package/dist/modes/index.js.map +1 -0
- package/dist/modes/mode-designer.d.ts +89 -0
- package/dist/modes/mode-designer.d.ts.map +1 -0
- package/dist/modes/mode-designer.js +485 -0
- package/dist/modes/mode-designer.js.map +1 -0
- package/dist/modes/mode-manager.d.ts +27 -0
- package/dist/modes/mode-manager.d.ts.map +1 -0
- package/dist/modes/mode-manager.js +68 -0
- package/dist/modes/mode-manager.js.map +1 -0
- package/dist/modes/synapse-modes.d.ts +26 -0
- package/dist/modes/synapse-modes.d.ts.map +1 -0
- package/dist/modes/synapse-modes.js +69 -0
- package/dist/modes/synapse-modes.js.map +1 -0
- package/dist/opencode/agent-delegate.d.ts +3 -0
- package/dist/opencode/agent-delegate.d.ts.map +1 -0
- package/dist/opencode/agent-delegate.js +3 -0
- package/dist/opencode/agent-delegate.js.map +1 -0
- package/dist/opencode/tool-bridge.d.ts +3 -0
- package/dist/opencode/tool-bridge.d.ts.map +1 -0
- package/dist/opencode/tool-bridge.js +3 -0
- package/dist/opencode/tool-bridge.js.map +1 -0
- package/dist/optimization/token-optimizer-v2.d.ts +18 -0
- package/dist/optimization/token-optimizer-v2.d.ts.map +1 -0
- package/dist/optimization/token-optimizer-v2.js +23 -0
- package/dist/optimization/token-optimizer-v2.js.map +1 -0
- package/dist/optimization/token-optimizer.d.ts +90 -0
- package/dist/optimization/token-optimizer.d.ts.map +1 -0
- package/dist/optimization/token-optimizer.js +399 -0
- package/dist/optimization/token-optimizer.js.map +1 -0
- package/dist/parallel/agent-farm.d.ts +123 -0
- package/dist/parallel/agent-farm.d.ts.map +1 -0
- package/dist/parallel/agent-farm.js +501 -0
- package/dist/parallel/agent-farm.js.map +1 -0
- package/dist/parallel/farm-scheduler.d.ts +115 -0
- package/dist/parallel/farm-scheduler.d.ts.map +1 -0
- package/dist/parallel/farm-scheduler.js +356 -0
- package/dist/parallel/farm-scheduler.js.map +1 -0
- package/dist/parallel/farm-types.d.ts +104 -0
- package/dist/parallel/farm-types.d.ts.map +1 -0
- package/dist/parallel/farm-types.js +9 -0
- package/dist/parallel/farm-types.js.map +1 -0
- package/dist/parallel/farm-worker.d.ts +62 -0
- package/dist/parallel/farm-worker.d.ts.map +1 -0
- package/dist/parallel/farm-worker.js +268 -0
- package/dist/parallel/farm-worker.js.map +1 -0
- package/dist/parallel/index.d.ts +14 -0
- package/dist/parallel/index.d.ts.map +1 -0
- package/dist/parallel/index.js +14 -0
- package/dist/parallel/index.js.map +1 -0
- package/dist/plugin/native-tools.d.ts +8 -0
- package/dist/plugin/native-tools.d.ts.map +1 -0
- package/dist/plugin/native-tools.js +147 -0
- package/dist/plugin/native-tools.js.map +1 -0
- package/dist/plugin/opencode-plugin.d.ts +32 -0
- package/dist/plugin/opencode-plugin.d.ts.map +1 -0
- package/dist/plugin/opencode-plugin.js +119 -0
- package/dist/plugin/opencode-plugin.js.map +1 -0
- package/dist/plugins/plugin-system.d.ts +108 -0
- package/dist/plugins/plugin-system.d.ts.map +1 -0
- package/dist/plugins/plugin-system.js +707 -0
- package/dist/plugins/plugin-system.js.map +1 -0
- package/dist/profiler/cpu-profiler.d.ts +53 -0
- package/dist/profiler/cpu-profiler.d.ts.map +1 -0
- package/dist/profiler/cpu-profiler.js +233 -0
- package/dist/profiler/cpu-profiler.js.map +1 -0
- package/dist/profiler/index.d.ts +36 -0
- package/dist/profiler/index.d.ts.map +1 -0
- package/dist/profiler/index.js +122 -0
- package/dist/profiler/index.js.map +1 -0
- package/dist/profiler/memory-profiler.d.ts +45 -0
- package/dist/profiler/memory-profiler.d.ts.map +1 -0
- package/dist/profiler/memory-profiler.js +211 -0
- package/dist/profiler/memory-profiler.js.map +1 -0
- package/dist/profiler/profiler-types.d.ts +234 -0
- package/dist/profiler/profiler-types.d.ts.map +1 -0
- package/dist/profiler/profiler-types.js +89 -0
- package/dist/profiler/profiler-types.js.map +1 -0
- package/dist/profiler/query-profiler.d.ts +48 -0
- package/dist/profiler/query-profiler.d.ts.map +1 -0
- package/dist/profiler/query-profiler.js +210 -0
- package/dist/profiler/query-profiler.js.map +1 -0
- package/dist/profiler/report-generator.d.ts +17 -0
- package/dist/profiler/report-generator.d.ts.map +1 -0
- package/dist/profiler/report-generator.js +329 -0
- package/dist/profiler/report-generator.js.map +1 -0
- package/dist/sdk/api.d.ts +85 -0
- package/dist/sdk/api.d.ts.map +1 -0
- package/dist/sdk/api.js +155 -0
- package/dist/sdk/api.js.map +1 -0
- package/dist/sdk/hooks.d.ts +58 -0
- package/dist/sdk/hooks.d.ts.map +1 -0
- package/dist/sdk/hooks.js +115 -0
- package/dist/sdk/hooks.js.map +1 -0
- package/dist/sdk/index.d.ts +17 -0
- package/dist/sdk/index.d.ts.map +1 -0
- package/dist/sdk/index.js +14 -0
- package/dist/sdk/index.js.map +1 -0
- package/dist/sdk/plugin-base.d.ts +198 -0
- package/dist/sdk/plugin-base.d.ts.map +1 -0
- package/dist/sdk/plugin-base.js +227 -0
- package/dist/sdk/plugin-base.js.map +1 -0
- package/dist/security/audit-rules.d.ts +12 -0
- package/dist/security/audit-rules.d.ts.map +1 -0
- package/dist/security/audit-rules.js +214 -0
- package/dist/security/audit-rules.js.map +1 -0
- package/dist/security/index.d.ts +13 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +13 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/sarif-exporter.d.ts +36 -0
- package/dist/security/sarif-exporter.d.ts.map +1 -0
- package/dist/security/sarif-exporter.js +216 -0
- package/dist/security/sarif-exporter.js.map +1 -0
- package/dist/security/security-auditor.d.ts +30 -0
- package/dist/security/security-auditor.d.ts.map +1 -0
- package/dist/security/security-auditor.js +295 -0
- package/dist/security/security-auditor.js.map +1 -0
- package/dist/security/security-types.d.ts +132 -0
- package/dist/security/security-types.d.ts.map +1 -0
- package/dist/security/security-types.js +7 -0
- package/dist/security/security-types.js.map +1 -0
- package/dist/synapsexcoder/agent-delegate.d.ts +128 -0
- package/dist/synapsexcoder/agent-delegate.d.ts.map +1 -0
- package/dist/synapsexcoder/agent-delegate.js +837 -0
- package/dist/synapsexcoder/agent-delegate.js.map +1 -0
- package/dist/synapsexcoder/agent-mailbox.d.ts +26 -0
- package/dist/synapsexcoder/agent-mailbox.d.ts.map +1 -0
- package/dist/synapsexcoder/agent-mailbox.js +64 -0
- package/dist/synapsexcoder/agent-mailbox.js.map +1 -0
- package/dist/synapsexcoder/ast-grep/ast-grep-api.d.ts +62 -0
- package/dist/synapsexcoder/ast-grep/ast-grep-api.d.ts.map +1 -0
- package/dist/synapsexcoder/ast-grep/ast-grep-api.js +223 -0
- package/dist/synapsexcoder/ast-grep/ast-grep-api.js.map +1 -0
- package/dist/synapsexcoder/cited-search.d.ts +32 -0
- package/dist/synapsexcoder/cited-search.d.ts.map +1 -0
- package/dist/synapsexcoder/cited-search.js +141 -0
- package/dist/synapsexcoder/cited-search.js.map +1 -0
- package/dist/synapsexcoder/credential-store.d.ts +42 -0
- package/dist/synapsexcoder/credential-store.d.ts.map +1 -0
- package/dist/synapsexcoder/credential-store.js +165 -0
- package/dist/synapsexcoder/credential-store.js.map +1 -0
- package/dist/synapsexcoder/devcontainer-awareness.d.ts +35 -0
- package/dist/synapsexcoder/devcontainer-awareness.d.ts.map +1 -0
- package/dist/synapsexcoder/devcontainer-awareness.js +133 -0
- package/dist/synapsexcoder/devcontainer-awareness.js.map +1 -0
- package/dist/synapsexcoder/execution-loops/helix-loop.d.ts +31 -0
- package/dist/synapsexcoder/execution-loops/helix-loop.d.ts.map +1 -0
- package/dist/synapsexcoder/execution-loops/helix-loop.js +93 -0
- package/dist/synapsexcoder/execution-loops/helix-loop.js.map +1 -0
- package/dist/synapsexcoder/execution-loops/ralp-loop.d.ts +28 -0
- package/dist/synapsexcoder/execution-loops/ralp-loop.d.ts.map +1 -0
- package/dist/synapsexcoder/execution-loops/ralp-loop.js +77 -0
- package/dist/synapsexcoder/execution-loops/ralp-loop.js.map +1 -0
- package/dist/synapsexcoder/feature-names.d.ts +27 -0
- package/dist/synapsexcoder/feature-names.d.ts.map +1 -0
- package/dist/synapsexcoder/feature-names.js +40 -0
- package/dist/synapsexcoder/feature-names.js.map +1 -0
- package/dist/synapsexcoder/index.d.ts +39 -0
- package/dist/synapsexcoder/index.d.ts.map +1 -0
- package/dist/synapsexcoder/index.js +23 -0
- package/dist/synapsexcoder/index.js.map +1 -0
- package/dist/synapsexcoder/knowledge-provider.d.ts +44 -0
- package/dist/synapsexcoder/knowledge-provider.d.ts.map +1 -0
- package/dist/synapsexcoder/knowledge-provider.js +107 -0
- package/dist/synapsexcoder/knowledge-provider.js.map +1 -0
- package/dist/synapsexcoder/lsp/lsp-layer.d.ts +51 -0
- package/dist/synapsexcoder/lsp/lsp-layer.d.ts.map +1 -0
- package/dist/synapsexcoder/lsp/lsp-layer.js +302 -0
- package/dist/synapsexcoder/lsp/lsp-layer.js.map +1 -0
- package/dist/synapsexcoder/migration/opencode-config-migrator.d.ts +37 -0
- package/dist/synapsexcoder/migration/opencode-config-migrator.d.ts.map +1 -0
- package/dist/synapsexcoder/migration/opencode-config-migrator.js +100 -0
- package/dist/synapsexcoder/migration/opencode-config-migrator.js.map +1 -0
- package/dist/synapsexcoder/runtime-environment.d.ts +35 -0
- package/dist/synapsexcoder/runtime-environment.d.ts.map +1 -0
- package/dist/synapsexcoder/runtime-environment.js +108 -0
- package/dist/synapsexcoder/runtime-environment.js.map +1 -0
- package/dist/synapsexcoder/secret-guard.d.ts +18 -0
- package/dist/synapsexcoder/secret-guard.d.ts.map +1 -0
- package/dist/synapsexcoder/secret-guard.js +69 -0
- package/dist/synapsexcoder/secret-guard.js.map +1 -0
- package/dist/synapsexcoder/self-prompt-engine.d.ts +15 -0
- package/dist/synapsexcoder/self-prompt-engine.d.ts.map +1 -0
- package/dist/synapsexcoder/self-prompt-engine.js +11 -0
- package/dist/synapsexcoder/self-prompt-engine.js.map +1 -0
- package/dist/synapsexcoder/session-observability.d.ts +44 -0
- package/dist/synapsexcoder/session-observability.d.ts.map +1 -0
- package/dist/synapsexcoder/session-observability.js +115 -0
- package/dist/synapsexcoder/session-observability.js.map +1 -0
- package/dist/synapsexcoder/specialist-agents.d.ts +38 -0
- package/dist/synapsexcoder/specialist-agents.d.ts.map +1 -0
- package/dist/synapsexcoder/specialist-agents.js +192 -0
- package/dist/synapsexcoder/specialist-agents.js.map +1 -0
- package/dist/synapsexcoder/swarm/kanban-board.d.ts +34 -0
- package/dist/synapsexcoder/swarm/kanban-board.d.ts.map +1 -0
- package/dist/synapsexcoder/swarm/kanban-board.js +85 -0
- package/dist/synapsexcoder/swarm/kanban-board.js.map +1 -0
- package/dist/synapsexcoder/swarm/swarm-mailbox.d.ts +38 -0
- package/dist/synapsexcoder/swarm/swarm-mailbox.d.ts.map +1 -0
- package/dist/synapsexcoder/swarm/swarm-mailbox.js +93 -0
- package/dist/synapsexcoder/swarm/swarm-mailbox.js.map +1 -0
- package/dist/synapsexcoder/tool-bridge.d.ts +277 -0
- package/dist/synapsexcoder/tool-bridge.d.ts.map +1 -0
- package/dist/synapsexcoder/tool-bridge.js +1356 -0
- package/dist/synapsexcoder/tool-bridge.js.map +1 -0
- package/dist/synapsexcoder/tool-routing.d.ts +28 -0
- package/dist/synapsexcoder/tool-routing.d.ts.map +1 -0
- package/dist/synapsexcoder/tool-routing.js +79 -0
- package/dist/synapsexcoder/tool-routing.js.map +1 -0
- package/dist/synapsexcoder/type-injector.d.ts +26 -0
- package/dist/synapsexcoder/type-injector.d.ts.map +1 -0
- package/dist/synapsexcoder/type-injector.js +124 -0
- package/dist/synapsexcoder/type-injector.js.map +1 -0
- package/dist/synapsexcoder/utils/fuzzy-match.d.ts +25 -0
- package/dist/synapsexcoder/utils/fuzzy-match.d.ts.map +1 -0
- package/dist/synapsexcoder/utils/fuzzy-match.js +83 -0
- package/dist/synapsexcoder/utils/fuzzy-match.js.map +1 -0
- package/dist/synapsexcoder/vault-crawl.d.ts +29 -0
- package/dist/synapsexcoder/vault-crawl.d.ts.map +1 -0
- package/dist/synapsexcoder/vault-crawl.js +103 -0
- package/dist/synapsexcoder/vault-crawl.js.map +1 -0
- package/dist/synapsexcoder/verified-apply.d.ts +39 -0
- package/dist/synapsexcoder/verified-apply.d.ts.map +1 -0
- package/dist/synapsexcoder/verified-apply.js +81 -0
- package/dist/synapsexcoder/verified-apply.js.map +1 -0
- package/dist/synapsexcoder/verified-context-editing.d.ts +34 -0
- package/dist/synapsexcoder/verified-context-editing.d.ts.map +1 -0
- package/dist/synapsexcoder/verified-context-editing.js +80 -0
- package/dist/synapsexcoder/verified-context-editing.js.map +1 -0
- package/dist/synapsexcoder/worker-pool.d.ts +47 -0
- package/dist/synapsexcoder/worker-pool.d.ts.map +1 -0
- package/dist/synapsexcoder/worker-pool.js +120 -0
- package/dist/synapsexcoder/worker-pool.js.map +1 -0
- package/dist/synapsexcoder/workspace-intelligence.d.ts +35 -0
- package/dist/synapsexcoder/workspace-intelligence.d.ts.map +1 -0
- package/dist/synapsexcoder/workspace-intelligence.js +126 -0
- package/dist/synapsexcoder/workspace-intelligence.js.map +1 -0
- package/dist/synapsexcoder/worktree-manager.d.ts +31 -0
- package/dist/synapsexcoder/worktree-manager.d.ts.map +1 -0
- package/dist/synapsexcoder/worktree-manager.js +100 -0
- package/dist/synapsexcoder/worktree-manager.js.map +1 -0
- package/dist/team/index.d.ts +17 -0
- package/dist/team/index.d.ts.map +1 -0
- package/dist/team/index.js +13 -0
- package/dist/team/index.js.map +1 -0
- package/dist/team/team-audit.d.ts +120 -0
- package/dist/team/team-audit.d.ts.map +1 -0
- package/dist/team/team-audit.js +357 -0
- package/dist/team/team-audit.js.map +1 -0
- package/dist/team/team-collaboration.d.ts +150 -0
- package/dist/team/team-collaboration.d.ts.map +1 -0
- package/dist/team/team-collaboration.js +495 -0
- package/dist/team/team-collaboration.js.map +1 -0
- package/dist/team/team-rbac.d.ts +84 -0
- package/dist/team/team-rbac.d.ts.map +1 -0
- package/dist/team/team-rbac.js +259 -0
- package/dist/team/team-rbac.js.map +1 -0
- package/dist/team/team-session-manager.d.ts +100 -0
- package/dist/team/team-session-manager.d.ts.map +1 -0
- package/dist/team/team-session-manager.js +255 -0
- package/dist/team/team-session-manager.js.map +1 -0
- package/dist/thoughts/thoughts-manager.d.ts +52 -0
- package/dist/thoughts/thoughts-manager.d.ts.map +1 -0
- package/dist/thoughts/thoughts-manager.js +271 -0
- package/dist/thoughts/thoughts-manager.js.map +1 -0
- package/dist/tools/api-validator/index.d.ts +97 -0
- package/dist/tools/api-validator/index.d.ts.map +1 -0
- package/dist/tools/api-validator/index.js +312 -0
- package/dist/tools/api-validator/index.js.map +1 -0
- package/dist/tools/code-archaeology/index.d.ts +193 -0
- package/dist/tools/code-archaeology/index.d.ts.map +1 -0
- package/dist/tools/code-archaeology/index.js +468 -0
- package/dist/tools/code-archaeology/index.js.map +1 -0
- package/dist/tools/codebase-search/index.d.ts +126 -0
- package/dist/tools/codebase-search/index.d.ts.map +1 -0
- package/dist/tools/codebase-search/index.js +437 -0
- package/dist/tools/codebase-search/index.js.map +1 -0
- package/dist/tools/context/index.d.ts +162 -0
- package/dist/tools/context/index.d.ts.map +1 -0
- package/dist/tools/context/index.js +332 -0
- package/dist/tools/context/index.js.map +1 -0
- package/dist/tools/deepwiki/analyzer.d.ts +167 -0
- package/dist/tools/deepwiki/analyzer.d.ts.map +1 -0
- package/dist/tools/deepwiki/analyzer.js +925 -0
- package/dist/tools/deepwiki/analyzer.js.map +1 -0
- package/dist/tools/deepwiki/extractor.d.ts +151 -0
- package/dist/tools/deepwiki/extractor.d.ts.map +1 -0
- package/dist/tools/deepwiki/extractor.js +923 -0
- package/dist/tools/deepwiki/extractor.js.map +1 -0
- package/dist/tools/deepwiki/generator.d.ts +89 -0
- package/dist/tools/deepwiki/generator.d.ts.map +1 -0
- package/dist/tools/deepwiki/generator.js +638 -0
- package/dist/tools/deepwiki/generator.js.map +1 -0
- package/dist/tools/deepwiki/index.d.ts +96 -0
- package/dist/tools/deepwiki/index.d.ts.map +1 -0
- package/dist/tools/deepwiki/index.js +282 -0
- package/dist/tools/deepwiki/index.js.map +1 -0
- package/dist/tools/deepwiki/types.d.ts +370 -0
- package/dist/tools/deepwiki/types.d.ts.map +1 -0
- package/dist/tools/deepwiki/types.js +21 -0
- package/dist/tools/deepwiki/types.js.map +1 -0
- package/dist/tools/dependency-mapper/index.d.ts +212 -0
- package/dist/tools/dependency-mapper/index.d.ts.map +1 -0
- package/dist/tools/dependency-mapper/index.js +592 -0
- package/dist/tools/dependency-mapper/index.js.map +1 -0
- package/dist/tools/memory/index.d.ts +120 -0
- package/dist/tools/memory/index.d.ts.map +1 -0
- package/dist/tools/memory/index.js +275 -0
- package/dist/tools/memory/index.js.map +1 -0
- package/dist/tools/normalize_patch.d.ts +3 -0
- package/dist/tools/normalize_patch.d.ts.map +1 -0
- package/dist/tools/normalize_patch.js +22 -0
- package/dist/tools/normalize_patch.js.map +1 -0
- package/dist/tools/pattern-detector/index.d.ts +105 -0
- package/dist/tools/pattern-detector/index.d.ts.map +1 -0
- package/dist/tools/pattern-detector/index.js +526 -0
- package/dist/tools/pattern-detector/index.js.map +1 -0
- package/dist/tools/performance-profiler/index.d.ts +50 -0
- package/dist/tools/performance-profiler/index.d.ts.map +1 -0
- package/dist/tools/performance-profiler/index.js +164 -0
- package/dist/tools/performance-profiler/index.js.map +1 -0
- package/dist/tools/refactoring-engine/index.d.ts +63 -0
- package/dist/tools/refactoring-engine/index.d.ts.map +1 -0
- package/dist/tools/refactoring-engine/index.js +270 -0
- package/dist/tools/refactoring-engine/index.js.map +1 -0
- package/dist/tools/registry.d.ts +36 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +499 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/test-generator/index.d.ts +152 -0
- package/dist/tools/test-generator/index.d.ts.map +1 -0
- package/dist/tools/test-generator/index.js +448 -0
- package/dist/tools/test-generator/index.js.map +1 -0
- package/dist/types/index.d.ts +565 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +7 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/path-validator.d.ts +94 -0
- package/dist/utils/path-validator.d.ts.map +1 -0
- package/dist/utils/path-validator.js +192 -0
- package/dist/utils/path-validator.js.map +1 -0
- package/dist/utils/secure-exec.d.ts +92 -0
- package/dist/utils/secure-exec.d.ts.map +1 -0
- package/dist/utils/secure-exec.js +230 -0
- package/dist/utils/secure-exec.js.map +1 -0
- package/dist/verification/claim-parser.d.ts +37 -0
- package/dist/verification/claim-parser.d.ts.map +1 -0
- package/dist/verification/claim-parser.js +231 -0
- package/dist/verification/claim-parser.js.map +1 -0
- package/dist/verification/cross-reference-engine.d.ts +55 -0
- package/dist/verification/cross-reference-engine.d.ts.map +1 -0
- package/dist/verification/cross-reference-engine.js +149 -0
- package/dist/verification/cross-reference-engine.js.map +1 -0
- package/dist/verification/discrepancy-tracker.d.ts +73 -0
- package/dist/verification/discrepancy-tracker.d.ts.map +1 -0
- package/dist/verification/discrepancy-tracker.js +196 -0
- package/dist/verification/discrepancy-tracker.js.map +1 -0
- package/dist/verification/feature-reconciler.d.ts +90 -0
- package/dist/verification/feature-reconciler.d.ts.map +1 -0
- package/dist/verification/feature-reconciler.js +264 -0
- package/dist/verification/feature-reconciler.js.map +1 -0
- package/dist/verification/index.d.ts +16 -0
- package/dist/verification/index.d.ts.map +1 -0
- package/dist/verification/index.js +19 -0
- package/dist/verification/index.js.map +1 -0
- package/dist/verification/integration-verifier.d.ts +66 -0
- package/dist/verification/integration-verifier.d.ts.map +1 -0
- package/dist/verification/integration-verifier.js +210 -0
- package/dist/verification/integration-verifier.js.map +1 -0
- package/dist/verification/recursive-audit-loop.d.ts +56 -0
- package/dist/verification/recursive-audit-loop.d.ts.map +1 -0
- package/dist/verification/recursive-audit-loop.js +136 -0
- package/dist/verification/recursive-audit-loop.js.map +1 -0
- package/dist/verification/runtime-verifier.d.ts +37 -0
- package/dist/verification/runtime-verifier.d.ts.map +1 -0
- package/dist/verification/runtime-verifier.js +221 -0
- package/dist/verification/runtime-verifier.js.map +1 -0
- package/dist/verification/types.d.ts +88 -0
- package/dist/verification/types.d.ts.map +1 -0
- package/dist/verification/types.js +5 -0
- package/dist/verification/types.js.map +1 -0
- package/dist/verification/verification-engine.d.ts +48 -0
- package/dist/verification/verification-engine.d.ts.map +1 -0
- package/dist/verification/verification-engine.js +203 -0
- package/dist/verification/verification-engine.js.map +1 -0
- package/opencode-agents/synapse-analyzer.md +64 -0
- package/opencode-agents/synapse-debugger.md +43 -0
- package/opencode-agents/synapse-diff-validator.md +42 -0
- package/opencode-agents/synapse-gatekeeper.md +273 -0
- package/opencode-agents/synapse-master.md +167 -0
- package/opencode-agents/synapse-planner.md +55 -0
- package/opencode-agents/synapse-researcher.md +61 -0
- package/opencode-agents/synapse-reviewer.md +64 -0
- package/opencode-agents/synapse-rewriter.md +62 -0
- package/opencode-agents/synapse-strategist.md +50 -0
- package/opencode-agents/synapse-test-runner.md +43 -0
- package/opencode-agents/synapse-ui-designer.md +61 -0
- package/opencode-agents/synapse-verifier.md +544 -0
- package/package.json +108 -0
- package/src/plugin/opencode-plugin.ts +141 -0
|
@@ -0,0 +1,1130 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* Internal Gatekeeper - Subagent Self-Review System
|
|
4
|
+
*
|
|
5
|
+
* Each subagent has its own internal gatekeeper that reviews work
|
|
6
|
+
* before returning to the Master Agent. Implements the APPROVE/DECLINE
|
|
7
|
+
* decision loop with retry capability.
|
|
8
|
+
*/
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// Error Indicators — patterns that signal broken/invalid output
|
|
11
|
+
// ============================================================================
|
|
12
|
+
const ERROR_INDICATORS = [
|
|
13
|
+
/\bundefined\b/i,
|
|
14
|
+
/\bnull\b(?!\s*[=!<>])/i, // "null" as a standalone value, not a comparison
|
|
15
|
+
/\bNaN\b/,
|
|
16
|
+
/stack\s*trace/i,
|
|
17
|
+
/\bat\s+\S+\s+\(/i, // stack trace lines like "at Module._compile ("
|
|
18
|
+
/Error:\s+/,
|
|
19
|
+
/TypeError:\s+/,
|
|
20
|
+
/ReferenceError:\s+/,
|
|
21
|
+
/SyntaxError:\s+/,
|
|
22
|
+
/ENOENT/,
|
|
23
|
+
/EACCES/,
|
|
24
|
+
/EPERM/,
|
|
25
|
+
/Cannot read propert/i,
|
|
26
|
+
/is not a function/i,
|
|
27
|
+
/is not defined/i,
|
|
28
|
+
/Unexpected token/i,
|
|
29
|
+
/FATAL/i,
|
|
30
|
+
/PANIC/i,
|
|
31
|
+
];
|
|
32
|
+
// ============================================================================
|
|
33
|
+
// Internal Gatekeeper
|
|
34
|
+
// ============================================================================
|
|
35
|
+
export class InternalGatekeeper {
|
|
36
|
+
agentType;
|
|
37
|
+
toolBridge;
|
|
38
|
+
config;
|
|
39
|
+
retryHistory = [];
|
|
40
|
+
constructor(agentType, toolBridge, config) {
|
|
41
|
+
this.agentType = agentType;
|
|
42
|
+
this.toolBridge = toolBridge;
|
|
43
|
+
this.config = {
|
|
44
|
+
maxRetries: config?.maxRetries ?? 3,
|
|
45
|
+
strictMode: config?.strictMode ?? false,
|
|
46
|
+
autoApproveThreshold: config?.autoApproveThreshold ?? 0.8,
|
|
47
|
+
model: config?.model,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Review subagent work and return APPROVE or DECLINE decision.
|
|
52
|
+
* Implements retry loop: DECLINE -> TRASH & RESTART -> Re-review
|
|
53
|
+
*/
|
|
54
|
+
async review(work) {
|
|
55
|
+
const attempt = this.retryHistory.length + 1;
|
|
56
|
+
console.log(`🔒 [${this.agentType}] Internal Gatekeeper: Review attempt ${attempt}/${this.config.maxRetries + 1}`);
|
|
57
|
+
// Perform review using AI
|
|
58
|
+
const reviewResult = await this.performReview(work);
|
|
59
|
+
const result = {
|
|
60
|
+
approved: reviewResult.decision === "approve",
|
|
61
|
+
decision: reviewResult.decision,
|
|
62
|
+
confidence: reviewResult.confidence,
|
|
63
|
+
issues: reviewResult.issues,
|
|
64
|
+
suggestions: reviewResult.suggestions,
|
|
65
|
+
reasoning: reviewResult.reasoning,
|
|
66
|
+
retryCount: attempt - 1,
|
|
67
|
+
};
|
|
68
|
+
// Record in history
|
|
69
|
+
this.retryHistory.push({
|
|
70
|
+
attempt,
|
|
71
|
+
decision: reviewResult.decision,
|
|
72
|
+
issues: reviewResult.issues,
|
|
73
|
+
timestamp: Date.now(),
|
|
74
|
+
});
|
|
75
|
+
// Log decision
|
|
76
|
+
if (reviewResult.decision === "approve") {
|
|
77
|
+
console.log(`✅ [${this.agentType}] Internal Gatekeeper: APPROVED (confidence: ${(reviewResult.confidence * 100).toFixed(1)}%)`);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
console.log(`❌ [${this.agentType}] Internal Gatekeeper: DECLINED (issues: ${reviewResult.issues.length})`);
|
|
81
|
+
if (reviewResult.issues.length > 0) {
|
|
82
|
+
console.log(` Issues:`);
|
|
83
|
+
reviewResult.issues.forEach((issue, idx) => {
|
|
84
|
+
console.log(` ${idx + 1}. [${issue.severity}] ${issue.description}`);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Perform the actual review using AI
|
|
92
|
+
*/
|
|
93
|
+
async performReview(work) {
|
|
94
|
+
const criteria = this.getReviewCriteria();
|
|
95
|
+
const outputStr = this.formatOutput(work.output);
|
|
96
|
+
const prompt = `You are an Internal Gatekeeper for a subagent (${this.agentType}) in a multi-agent coding system.
|
|
97
|
+
|
|
98
|
+
Your job is to review the work produced by the subagent BEFORE it returns to the Master Agent.
|
|
99
|
+
You must APPROVE if the work meets quality standards, or DECLINE if it needs revision.
|
|
100
|
+
|
|
101
|
+
## SUBAGENT TYPE: ${this.agentType}
|
|
102
|
+
|
|
103
|
+
## WORK OUTPUT TO REVIEW:
|
|
104
|
+
${outputStr}
|
|
105
|
+
|
|
106
|
+
## REVIEW CRITERIA FOR ${this.agentType.toUpperCase()}:
|
|
107
|
+
${criteria}
|
|
108
|
+
|
|
109
|
+
## CONTEXT:
|
|
110
|
+
- Task: ${work.task.prompt.substring(0, 500)}
|
|
111
|
+
- Files: ${work.task.context.files.map((f) => f.path).join(", ")}
|
|
112
|
+
|
|
113
|
+
Respond with ONLY a JSON object (no other text):
|
|
114
|
+
{
|
|
115
|
+
"decision": "approve" | "decline",
|
|
116
|
+
"confidence": 0.0-1.0,
|
|
117
|
+
"reasoning": "Brief explanation",
|
|
118
|
+
"issues": [
|
|
119
|
+
{
|
|
120
|
+
"id": "issue-N",
|
|
121
|
+
"severity": "critical" | "high" | "medium" | "low",
|
|
122
|
+
"category": "correctness | completeness | code_quality | security | performance",
|
|
123
|
+
"description": "Issue description",
|
|
124
|
+
"evidence": "Evidence from the work",
|
|
125
|
+
"remediation": "How to fix"
|
|
126
|
+
}
|
|
127
|
+
],
|
|
128
|
+
"suggestions": [
|
|
129
|
+
{
|
|
130
|
+
"id": "suggest-N",
|
|
131
|
+
"priority": "must" | "should" | "could",
|
|
132
|
+
"category": "...",
|
|
133
|
+
"description": "Suggestion",
|
|
134
|
+
"rationale": "Why this helps"
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
}`;
|
|
138
|
+
try {
|
|
139
|
+
// Use the configured model or fall back to grok-code-fast-1
|
|
140
|
+
const modelToUse = this.config.model || "github-copilot/grok-code-fast-1";
|
|
141
|
+
const toolResult = await this.toolBridge.callModel(prompt, {
|
|
142
|
+
model: modelToUse,
|
|
143
|
+
});
|
|
144
|
+
const response = toolResult?.success
|
|
145
|
+
? toolResult.output
|
|
146
|
+
: null;
|
|
147
|
+
if (!response) {
|
|
148
|
+
// Model returned no response — fall back to local code analysis
|
|
149
|
+
console.warn(`⚠️ [${this.agentType}] Model returned no response, running local analysis fallback`);
|
|
150
|
+
return this.performLocalAnalysisFallback(work, "model_no_response");
|
|
151
|
+
}
|
|
152
|
+
return this.parseReviewResponse(response);
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
// Model call threw — fall back to local code analysis (NEVER auto-approve)
|
|
156
|
+
console.warn(`⚠️ [${this.agentType}] Model call failed: ${error}, running local analysis fallback`);
|
|
157
|
+
return this.performLocalAnalysisFallback(work, `model_error: ${String(error)}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Get review criteria based on agent type
|
|
162
|
+
*/
|
|
163
|
+
getReviewCriteria() {
|
|
164
|
+
const criteriaMap = {
|
|
165
|
+
planner: `
|
|
166
|
+
- COMPLETENESS: Are all required steps included?
|
|
167
|
+
- LOGICAL FLOW: Are steps in correct order?
|
|
168
|
+
- DEPENDENCIES: Are dependencies properly identified?
|
|
169
|
+
- RISK ASSESSMENT: Are potential risks identified?
|
|
170
|
+
- Does the plan address the task requirements?`,
|
|
171
|
+
analyzer: `
|
|
172
|
+
- ACCURACY: Are identified issues correct?
|
|
173
|
+
- COMPLETENESS: Are all issues found?
|
|
174
|
+
- FALSE POSITIVES: Are there any false positives?
|
|
175
|
+
- SEVERITY: Are severity levels appropriate?
|
|
176
|
+
- Does it cover syntax, logic, security, performance?`,
|
|
177
|
+
reviewer: `
|
|
178
|
+
- REASONING: Is the reasoning sound?
|
|
179
|
+
- COMPLETENESS: Are all aspects reviewed?
|
|
180
|
+
- ACCURACY: Are conclusions correct?
|
|
181
|
+
- ALTERNATIVES: Are alternatives considered?
|
|
182
|
+
- Does it provide actionable feedback?`,
|
|
183
|
+
rewriter: `
|
|
184
|
+
- SYNTAX: Is the code syntactically correct?
|
|
185
|
+
- REGRESSIONS: Are there potential regressions?
|
|
186
|
+
- SAFETY: Are changes safe to apply?
|
|
187
|
+
- COMPLETENESS: Are all required changes made?
|
|
188
|
+
- Does it properly fix the identified issues?`,
|
|
189
|
+
ui_designer: `
|
|
190
|
+
- VALIDITY: Is the design valid?
|
|
191
|
+
- ACCESSIBILITY: Are accessibility issues addressed?
|
|
192
|
+
- RESPONSIVENESS: Is it responsive?
|
|
193
|
+
- QUALITY: Is the visual design good?
|
|
194
|
+
- Does it match the UI requirements?`,
|
|
195
|
+
researcher: `
|
|
196
|
+
- RELIABILITY: Are sources reliable?
|
|
197
|
+
- RELEVANCE: Is information relevant?
|
|
198
|
+
- COMPLETENESS: Is research thorough?
|
|
199
|
+
- CITATIONS: Are sources cited?
|
|
200
|
+
- Does it answer the research question?`,
|
|
201
|
+
gatekeeper: `
|
|
202
|
+
- FAIRNESS: Is the review fair?
|
|
203
|
+
- THOROUGHNESS: Is the review thorough?
|
|
204
|
+
- ACCURACY: Are decisions accurate?`,
|
|
205
|
+
master: `
|
|
206
|
+
- ORCHESTRATION: Is coordination effective?`,
|
|
207
|
+
};
|
|
208
|
+
return criteriaMap[this.agentType] || criteriaMap.analyzer;
|
|
209
|
+
}
|
|
210
|
+
// ==========================================================================
|
|
211
|
+
// Local Analysis Fallback — replaces dangerous auto-approve
|
|
212
|
+
// ==========================================================================
|
|
213
|
+
/**
|
|
214
|
+
* Perform local rule-based analysis when model call fails.
|
|
215
|
+
* This is the CRITICAL safety net — it uses structural validation and
|
|
216
|
+
* quality heuristics to make a conservative decision without AI.
|
|
217
|
+
*
|
|
218
|
+
* Design principle: when in doubt, DECLINE rather than approve.
|
|
219
|
+
*/
|
|
220
|
+
performLocalAnalysisFallback(work, failureReason) {
|
|
221
|
+
const outputStr = this.formatOutput(work.output);
|
|
222
|
+
const structural = this.validateStructure(work, outputStr);
|
|
223
|
+
const quality = this.evaluateQualityHeuristics(work, outputStr);
|
|
224
|
+
// Build detailed check breakdown for transparency
|
|
225
|
+
const structuralSummary = structural.checks
|
|
226
|
+
.map((c) => ` ${c.passed ? "✅" : "❌"} ${c.name}: ${c.detail}`)
|
|
227
|
+
.join("\n");
|
|
228
|
+
const qualitySummary = quality.checks
|
|
229
|
+
.map((c) => ` ${c.passed ? "✅" : "❌"} ${c.name} (w=${c.weight}): ${c.detail}`)
|
|
230
|
+
.join("\n");
|
|
231
|
+
const checkBreakdown = `[Local Analysis Fallback — ${failureReason}]\nStructural (valid=${structural.valid}):\n${structuralSummary}\nQuality (score=${(quality.score * 100).toFixed(1)}%):\n${qualitySummary}`;
|
|
232
|
+
console.log(`🔍 [${this.agentType}] Local analysis fallback:\n${checkBreakdown}`);
|
|
233
|
+
// Decision logic — conservative approach
|
|
234
|
+
const issues = [];
|
|
235
|
+
const suggestions = [];
|
|
236
|
+
let decision;
|
|
237
|
+
let confidence;
|
|
238
|
+
let reasoning;
|
|
239
|
+
// Always note that this is a fallback review
|
|
240
|
+
suggestions.push({
|
|
241
|
+
id: "suggest-fallback-rerun",
|
|
242
|
+
priority: "should",
|
|
243
|
+
category: "correctness",
|
|
244
|
+
description: "This review was performed via local heuristics due to model failure. Re-run with model verification when available.",
|
|
245
|
+
rationale: `Model was unavailable: ${failureReason}`,
|
|
246
|
+
});
|
|
247
|
+
// Collect issues from failed structural checks
|
|
248
|
+
for (const check of structural.checks) {
|
|
249
|
+
if (!check.passed) {
|
|
250
|
+
issues.push({
|
|
251
|
+
id: `struct-${check.name.replace(/\s+/g, "-").toLowerCase()}`,
|
|
252
|
+
severity: "high",
|
|
253
|
+
category: "correctness",
|
|
254
|
+
description: `Structural validation failed: ${check.name}`,
|
|
255
|
+
evidence: check.detail,
|
|
256
|
+
remediation: `Fix the structural issue: ${check.detail}`,
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
// Collect issues from failed quality checks
|
|
261
|
+
for (const check of quality.checks) {
|
|
262
|
+
if (!check.passed) {
|
|
263
|
+
issues.push({
|
|
264
|
+
id: `quality-${check.name.replace(/\s+/g, "-").toLowerCase()}`,
|
|
265
|
+
severity: check.weight >= 0.2 ? "medium" : "low",
|
|
266
|
+
category: "code_quality",
|
|
267
|
+
description: `Quality heuristic failed: ${check.name}`,
|
|
268
|
+
evidence: check.detail,
|
|
269
|
+
remediation: `Improve quality: ${check.detail}`,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (!structural.valid) {
|
|
274
|
+
// Structural validation FAILED — always DECLINE
|
|
275
|
+
decision = "decline";
|
|
276
|
+
confidence = Math.max(0.5, 1.0 - quality.score);
|
|
277
|
+
reasoning = `DECLINED (local fallback): Structural validation failed. ${issues.length} issue(s) found. Quality score: ${(quality.score * 100).toFixed(1)}%. Failure reason: ${failureReason}`;
|
|
278
|
+
}
|
|
279
|
+
else if (quality.score < 0.4) {
|
|
280
|
+
// Quality score below 40% — DECLINE
|
|
281
|
+
decision = "decline";
|
|
282
|
+
confidence = Math.max(0.4, 1.0 - quality.score);
|
|
283
|
+
reasoning = `DECLINED (local fallback): Quality score too low (${(quality.score * 100).toFixed(1)}% < 40% threshold). ${issues.length} issue(s) found. Failure reason: ${failureReason}`;
|
|
284
|
+
}
|
|
285
|
+
else if (quality.score < 0.7) {
|
|
286
|
+
// Quality score 40-70% — DECLINE with request for changes
|
|
287
|
+
// We lean conservative: this range means "not confident enough to approve"
|
|
288
|
+
decision = "decline";
|
|
289
|
+
confidence = 0.5;
|
|
290
|
+
reasoning = `DECLINED (local fallback): Quality score in uncertain range (${(quality.score * 100).toFixed(1)}%, needs ≥70% for approval). ${issues.length} issue(s) found. Failure reason: ${failureReason}`;
|
|
291
|
+
suggestions.push({
|
|
292
|
+
id: "suggest-improve-quality",
|
|
293
|
+
priority: "must",
|
|
294
|
+
category: "completeness",
|
|
295
|
+
description: `Quality score is ${(quality.score * 100).toFixed(1)}%. Improve the output to exceed 70% threshold for approval.`,
|
|
296
|
+
rationale: "Without model verification, only high-quality outputs are approved.",
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
// Structural valid AND quality > 70% — APPROVE with capped confidence
|
|
301
|
+
// Cap at 0.85 since we have no model verification
|
|
302
|
+
decision = "approve";
|
|
303
|
+
confidence = Math.min(0.85, quality.score * 0.8);
|
|
304
|
+
reasoning = `APPROVED (local fallback): Structural validation passed. Quality score: ${(quality.score * 100).toFixed(1)}%. Confidence capped at ${(confidence * 100).toFixed(1)}% (no model verification). Failure reason: ${failureReason}`;
|
|
305
|
+
}
|
|
306
|
+
return { decision, confidence, issues, suggestions, reasoning };
|
|
307
|
+
}
|
|
308
|
+
// ==========================================================================
|
|
309
|
+
// Structural Validation — checks basic correctness of output shape
|
|
310
|
+
// ==========================================================================
|
|
311
|
+
/**
|
|
312
|
+
* Validate the structural integrity of work output.
|
|
313
|
+
* Checks: non-empty, parseable, expected shape for agent type, no error indicators.
|
|
314
|
+
*/
|
|
315
|
+
validateStructure(work, outputStr) {
|
|
316
|
+
const checks = [];
|
|
317
|
+
// Check 1: Output exists and is non-null
|
|
318
|
+
const outputExists = work.output != null;
|
|
319
|
+
checks.push({
|
|
320
|
+
name: "Output exists",
|
|
321
|
+
passed: outputExists,
|
|
322
|
+
detail: outputExists
|
|
323
|
+
? "Output is non-null"
|
|
324
|
+
: "Output is null or undefined",
|
|
325
|
+
});
|
|
326
|
+
if (!outputExists) {
|
|
327
|
+
return { valid: false, checks };
|
|
328
|
+
}
|
|
329
|
+
// Check 2: Output is non-empty
|
|
330
|
+
const trimmed = outputStr.trim();
|
|
331
|
+
const nonEmpty = trimmed.length > 0;
|
|
332
|
+
checks.push({
|
|
333
|
+
name: "Non-empty output",
|
|
334
|
+
passed: nonEmpty,
|
|
335
|
+
detail: nonEmpty
|
|
336
|
+
? `Output has ${trimmed.length} characters`
|
|
337
|
+
: "Output is empty or whitespace-only",
|
|
338
|
+
});
|
|
339
|
+
if (!nonEmpty) {
|
|
340
|
+
return { valid: false, checks };
|
|
341
|
+
}
|
|
342
|
+
// Check 3: Minimum length (not trivially short)
|
|
343
|
+
const minLength = this.getMinimumLengthForAgent(work.agentType);
|
|
344
|
+
const meetsMinLength = trimmed.length >= minLength;
|
|
345
|
+
checks.push({
|
|
346
|
+
name: "Minimum length",
|
|
347
|
+
passed: meetsMinLength,
|
|
348
|
+
detail: meetsMinLength
|
|
349
|
+
? `Output length ${trimmed.length} ≥ minimum ${minLength}`
|
|
350
|
+
: `Output length ${trimmed.length} < minimum ${minLength} for ${work.agentType}`,
|
|
351
|
+
});
|
|
352
|
+
// Check 4: Parseable as JSON/structured data (if output is an object or looks like JSON)
|
|
353
|
+
let parseableCheck = true;
|
|
354
|
+
if (typeof work.output === "string") {
|
|
355
|
+
const looksLikeJson = trimmed.startsWith("{") || trimmed.startsWith("[");
|
|
356
|
+
if (looksLikeJson) {
|
|
357
|
+
try {
|
|
358
|
+
JSON.parse(trimmed);
|
|
359
|
+
checks.push({
|
|
360
|
+
name: "JSON parseable",
|
|
361
|
+
passed: true,
|
|
362
|
+
detail: "Output parses as valid JSON",
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
catch {
|
|
366
|
+
parseableCheck = false;
|
|
367
|
+
checks.push({
|
|
368
|
+
name: "JSON parseable",
|
|
369
|
+
passed: false,
|
|
370
|
+
detail: "Output looks like JSON but fails to parse",
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
checks.push({
|
|
376
|
+
name: "JSON parseable",
|
|
377
|
+
passed: true,
|
|
378
|
+
detail: "Output is not JSON-shaped (string content), skipping parse check",
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
else if (typeof work.output === "object") {
|
|
383
|
+
// Object output — verify it can round-trip through JSON
|
|
384
|
+
try {
|
|
385
|
+
JSON.stringify(work.output);
|
|
386
|
+
checks.push({
|
|
387
|
+
name: "JSON parseable",
|
|
388
|
+
passed: true,
|
|
389
|
+
detail: "Object output serializes to valid JSON",
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
catch {
|
|
393
|
+
parseableCheck = false;
|
|
394
|
+
checks.push({
|
|
395
|
+
name: "JSON parseable",
|
|
396
|
+
passed: false,
|
|
397
|
+
detail: "Object output cannot be serialized to JSON",
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
checks.push({
|
|
403
|
+
name: "JSON parseable",
|
|
404
|
+
passed: true,
|
|
405
|
+
detail: `Output type is ${typeof work.output}, parse check not applicable`,
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
// Check 5: Expected structure for agent type
|
|
409
|
+
const structureResult = this.checkExpectedStructure(work, outputStr);
|
|
410
|
+
checks.push(structureResult);
|
|
411
|
+
// Check 6: No error indicators in output
|
|
412
|
+
const errorIndicators = this.detectErrorIndicators(outputStr);
|
|
413
|
+
const noErrors = errorIndicators.length === 0;
|
|
414
|
+
checks.push({
|
|
415
|
+
name: "No error indicators",
|
|
416
|
+
passed: noErrors,
|
|
417
|
+
detail: noErrors
|
|
418
|
+
? "No error patterns detected"
|
|
419
|
+
: `Found error indicators: ${errorIndicators.join(", ")}`,
|
|
420
|
+
});
|
|
421
|
+
// Valid only if all critical checks pass (exists, non-empty, min-length, parseable, no errors)
|
|
422
|
+
const valid = outputExists && nonEmpty && meetsMinLength && parseableCheck && noErrors;
|
|
423
|
+
return { valid, checks };
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Get minimum output length based on agent type.
|
|
427
|
+
* Different agents produce different amounts of output.
|
|
428
|
+
*/
|
|
429
|
+
getMinimumLengthForAgent(agentType) {
|
|
430
|
+
const minimums = {
|
|
431
|
+
planner: 100, // Plans need steps, dependencies
|
|
432
|
+
analyzer: 80, // Analysis needs findings
|
|
433
|
+
reviewer: 80, // Reviews need assessments
|
|
434
|
+
rewriter: 50, // Rewrites can be small targeted fixes
|
|
435
|
+
ui_designer: 100, // UI output needs structure
|
|
436
|
+
researcher: 100, // Research needs findings, sources
|
|
437
|
+
gatekeeper: 50, // Gatekeeper output can be concise
|
|
438
|
+
master: 30, // Master coordination can be terse
|
|
439
|
+
};
|
|
440
|
+
return minimums[agentType] ?? 50;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Check if output has the expected structure for the given agent type.
|
|
444
|
+
* Each agent type has characteristic patterns in its output.
|
|
445
|
+
*/
|
|
446
|
+
checkExpectedStructure(work, outputStr) {
|
|
447
|
+
// Agent-type-specific structural expectations
|
|
448
|
+
const expectations = {
|
|
449
|
+
planner: {
|
|
450
|
+
patterns: [
|
|
451
|
+
/(?:step|phase|stage)\s*\d/i,
|
|
452
|
+
/(?:depend|prerequisite|requires|before|after)/i,
|
|
453
|
+
/(?:goal|objective|target|outcome)/i,
|
|
454
|
+
/(?:estimate|timeline|duration|time)/i,
|
|
455
|
+
/(?:\d+[\.\)]\s|\-\s|\*\s)/m, // numbered/bulleted lists
|
|
456
|
+
],
|
|
457
|
+
minMatches: 2,
|
|
458
|
+
description: "Planner output should have steps/phases, dependencies, and goals",
|
|
459
|
+
},
|
|
460
|
+
analyzer: {
|
|
461
|
+
patterns: [
|
|
462
|
+
/(?:issue|problem|finding|defect|bug|vulnerability)/i,
|
|
463
|
+
/(?:severity|critical|high|medium|low|priority)/i,
|
|
464
|
+
/(?:file|line|location|at\s)/i,
|
|
465
|
+
/(?:recommend|suggest|fix|remediat)/i,
|
|
466
|
+
],
|
|
467
|
+
minMatches: 2,
|
|
468
|
+
description: "Analyzer output should have issues with severity and recommendations",
|
|
469
|
+
},
|
|
470
|
+
reviewer: {
|
|
471
|
+
patterns: [
|
|
472
|
+
/(?:review|assess|evaluat|examin)/i,
|
|
473
|
+
/(?:quality|correct|complet|accura)/i,
|
|
474
|
+
/(?:approved?|decline|accept|reject|pass|fail)/i,
|
|
475
|
+
/(?:feedback|comment|note|observation)/i,
|
|
476
|
+
],
|
|
477
|
+
minMatches: 2,
|
|
478
|
+
description: "Reviewer output should have assessments, quality judgments, and feedback",
|
|
479
|
+
},
|
|
480
|
+
rewriter: {
|
|
481
|
+
patterns: [
|
|
482
|
+
/(?:function|class|const|let|var|import|export|def |return)/i,
|
|
483
|
+
/(?:\{[\s\S]*\}|\([\s\S]*\))/,
|
|
484
|
+
/(?:fix|change|modif|updat|refactor)/i,
|
|
485
|
+
],
|
|
486
|
+
minMatches: 1,
|
|
487
|
+
description: "Rewriter output should contain code with functions/classes and change indicators",
|
|
488
|
+
},
|
|
489
|
+
ui_designer: {
|
|
490
|
+
patterns: [
|
|
491
|
+
/(?:component|layout|design|view|page|screen)/i,
|
|
492
|
+
/(?:style|css|class|tailwind|color|theme)/i,
|
|
493
|
+
/(?:<\w+[\s>]|jsx|tsx|html|svg)/i,
|
|
494
|
+
/(?:responsive|mobile|desktop|tablet|breakpoint)/i,
|
|
495
|
+
],
|
|
496
|
+
minMatches: 2,
|
|
497
|
+
description: "UI designer output should have component/layout structure and styling",
|
|
498
|
+
},
|
|
499
|
+
researcher: {
|
|
500
|
+
patterns: [
|
|
501
|
+
/(?:source|reference|citation|link|url|http)/i,
|
|
502
|
+
/(?:finding|result|discover|evidence|data)/i,
|
|
503
|
+
/(?:conclusion|summary|overview)/i,
|
|
504
|
+
/(?:relevant|related|similar|comparison)/i,
|
|
505
|
+
],
|
|
506
|
+
minMatches: 2,
|
|
507
|
+
description: "Researcher output should have sources, findings, and conclusions",
|
|
508
|
+
},
|
|
509
|
+
gatekeeper: {
|
|
510
|
+
patterns: [
|
|
511
|
+
/(?:approve|decline|decision|verdict)/i,
|
|
512
|
+
/(?:issue|concern|problem)/i,
|
|
513
|
+
/(?:confidence|score|rating)/i,
|
|
514
|
+
],
|
|
515
|
+
minMatches: 1,
|
|
516
|
+
description: "Gatekeeper output should have a decision and confidence score",
|
|
517
|
+
},
|
|
518
|
+
master: {
|
|
519
|
+
patterns: [
|
|
520
|
+
/(?:dispatch|coordinate|assign|delegate|route)/i,
|
|
521
|
+
/(?:agent|subagent|task)/i,
|
|
522
|
+
],
|
|
523
|
+
minMatches: 1,
|
|
524
|
+
description: "Master output should have coordination and agent dispatch info",
|
|
525
|
+
},
|
|
526
|
+
};
|
|
527
|
+
const expectation = expectations[work.agentType] ?? expectations.analyzer;
|
|
528
|
+
const matches = expectation.patterns.filter((p) => p.test(outputStr));
|
|
529
|
+
const passed = matches.length >= expectation.minMatches;
|
|
530
|
+
return {
|
|
531
|
+
name: `Expected structure (${work.agentType})`,
|
|
532
|
+
passed,
|
|
533
|
+
detail: passed
|
|
534
|
+
? `Matched ${matches.length}/${expectation.patterns.length} expected patterns (need ≥${expectation.minMatches})`
|
|
535
|
+
: `Only matched ${matches.length}/${expectation.patterns.length} patterns (need ≥${expectation.minMatches}). ${expectation.description}`,
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Detect error indicators in output text.
|
|
540
|
+
* Returns a list of matched error pattern descriptions.
|
|
541
|
+
*/
|
|
542
|
+
detectErrorIndicators(outputStr) {
|
|
543
|
+
const found = [];
|
|
544
|
+
for (const pattern of ERROR_INDICATORS) {
|
|
545
|
+
if (pattern.test(outputStr)) {
|
|
546
|
+
found.push(pattern.source);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return found;
|
|
550
|
+
}
|
|
551
|
+
// ==========================================================================
|
|
552
|
+
// Quality Heuristics — rule-based scoring per agent type
|
|
553
|
+
// ==========================================================================
|
|
554
|
+
/**
|
|
555
|
+
* Evaluate quality heuristics based on agent type.
|
|
556
|
+
* Returns a weighted score between 0.0-1.0 with detailed check breakdown.
|
|
557
|
+
*/
|
|
558
|
+
evaluateQualityHeuristics(work, outputStr) {
|
|
559
|
+
// Run common checks first, then agent-specific checks
|
|
560
|
+
const commonChecks = this.runCommonQualityChecks(outputStr);
|
|
561
|
+
const agentChecks = this.runAgentSpecificQualityChecks(work, outputStr);
|
|
562
|
+
const allChecks = [...commonChecks, ...agentChecks];
|
|
563
|
+
// Calculate weighted score
|
|
564
|
+
const totalWeight = allChecks.reduce((sum, c) => sum + c.weight, 0);
|
|
565
|
+
const earnedWeight = allChecks
|
|
566
|
+
.filter((c) => c.passed)
|
|
567
|
+
.reduce((sum, c) => sum + c.weight, 0);
|
|
568
|
+
const score = totalWeight > 0 ? earnedWeight / totalWeight : 0;
|
|
569
|
+
return { score, checks: allChecks };
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Common quality checks applicable to all agent types.
|
|
573
|
+
*/
|
|
574
|
+
runCommonQualityChecks(outputStr) {
|
|
575
|
+
const checks = [];
|
|
576
|
+
const trimmed = outputStr.trim();
|
|
577
|
+
// Check: Reasonable length (not suspiciously short)
|
|
578
|
+
const reasonableLength = trimmed.length >= 50;
|
|
579
|
+
checks.push({
|
|
580
|
+
name: "Reasonable length",
|
|
581
|
+
passed: reasonableLength,
|
|
582
|
+
weight: 0.15,
|
|
583
|
+
detail: reasonableLength
|
|
584
|
+
? `Length ${trimmed.length} chars is reasonable`
|
|
585
|
+
: `Length ${trimmed.length} chars is suspiciously short`,
|
|
586
|
+
});
|
|
587
|
+
// Check: Has substantive content (not just boilerplate/filler)
|
|
588
|
+
const fillerPatterns = /^(ok|done|completed|finished|success|no issues?|looks good|lgtm)\s*\.?$/im;
|
|
589
|
+
const notJustFiller = !fillerPatterns.test(trimmed);
|
|
590
|
+
checks.push({
|
|
591
|
+
name: "Substantive content",
|
|
592
|
+
passed: notJustFiller,
|
|
593
|
+
weight: 0.2,
|
|
594
|
+
detail: notJustFiller
|
|
595
|
+
? "Output contains substantive content"
|
|
596
|
+
: "Output appears to be only filler/boilerplate text",
|
|
597
|
+
});
|
|
598
|
+
// Check: No excessive repetition (same line repeated many times)
|
|
599
|
+
const lines = trimmed.split("\n").filter((l) => l.trim().length > 0);
|
|
600
|
+
const uniqueLines = new Set(lines.map((l) => l.trim()));
|
|
601
|
+
const repetitionRatio = lines.length > 0 ? uniqueLines.size / lines.length : 1;
|
|
602
|
+
const notExcessivelyRepetitive = repetitionRatio > 0.3;
|
|
603
|
+
checks.push({
|
|
604
|
+
name: "No excessive repetition",
|
|
605
|
+
passed: notExcessivelyRepetitive,
|
|
606
|
+
weight: 0.1,
|
|
607
|
+
detail: notExcessivelyRepetitive
|
|
608
|
+
? `Repetition ratio: ${(repetitionRatio * 100).toFixed(0)}% unique lines`
|
|
609
|
+
: `Too repetitive: only ${(repetitionRatio * 100).toFixed(0)}% unique lines`,
|
|
610
|
+
});
|
|
611
|
+
// Check: No placeholder markers left
|
|
612
|
+
const placeholderPattern = /\[(?:TODO|PLACEHOLDER|INSERT|FILL|TBD)\]|\.{3,}(?:\s*$)/im;
|
|
613
|
+
const noPlaceholders = !placeholderPattern.test(trimmed);
|
|
614
|
+
checks.push({
|
|
615
|
+
name: "No placeholders",
|
|
616
|
+
passed: noPlaceholders,
|
|
617
|
+
weight: 0.15,
|
|
618
|
+
detail: noPlaceholders
|
|
619
|
+
? "No placeholder markers detected"
|
|
620
|
+
: "Found placeholder markers (TODO, INSERT, TBD, etc.) in output",
|
|
621
|
+
});
|
|
622
|
+
return checks;
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Agent-type-specific quality checks.
|
|
626
|
+
* Each agent type has unique expectations for what constitutes quality output.
|
|
627
|
+
*/
|
|
628
|
+
runAgentSpecificQualityChecks(work, outputStr) {
|
|
629
|
+
switch (work.agentType) {
|
|
630
|
+
case "planner":
|
|
631
|
+
return this.checkPlannerQuality(outputStr);
|
|
632
|
+
case "analyzer":
|
|
633
|
+
return this.checkAnalyzerQuality(outputStr);
|
|
634
|
+
case "reviewer":
|
|
635
|
+
return this.checkReviewerQuality(outputStr);
|
|
636
|
+
case "rewriter":
|
|
637
|
+
return this.checkRewriterQuality(work, outputStr);
|
|
638
|
+
case "ui_designer":
|
|
639
|
+
return this.checkUIDesignerQuality(outputStr);
|
|
640
|
+
case "researcher":
|
|
641
|
+
return this.checkResearcherQuality(outputStr);
|
|
642
|
+
default:
|
|
643
|
+
return this.checkGenericQuality(outputStr);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* Planner output: should have numbered steps, dependencies, clear structure.
|
|
648
|
+
*/
|
|
649
|
+
checkPlannerQuality(outputStr) {
|
|
650
|
+
const checks = [];
|
|
651
|
+
// Has numbered/ordered steps
|
|
652
|
+
const stepPattern = /(?:\d+[\.\)]\s|\bstep\s+\d+)/gi;
|
|
653
|
+
const stepMatches = outputStr.match(stepPattern);
|
|
654
|
+
const hasSteps = (stepMatches?.length ?? 0) >= 2;
|
|
655
|
+
checks.push({
|
|
656
|
+
name: "Has ordered steps",
|
|
657
|
+
passed: hasSteps,
|
|
658
|
+
weight: 0.15,
|
|
659
|
+
detail: hasSteps
|
|
660
|
+
? `Found ${stepMatches?.length ?? 0} ordered steps`
|
|
661
|
+
: "Missing ordered steps (need at least 2)",
|
|
662
|
+
});
|
|
663
|
+
// Mentions dependencies or ordering
|
|
664
|
+
const hasDeps = /(?:depend|prerequisite|requires|before|after|block)/i.test(outputStr);
|
|
665
|
+
checks.push({
|
|
666
|
+
name: "Mentions dependencies",
|
|
667
|
+
passed: hasDeps,
|
|
668
|
+
weight: 0.1,
|
|
669
|
+
detail: hasDeps
|
|
670
|
+
? "Dependencies/ordering mentioned"
|
|
671
|
+
: "No dependency or ordering mentions found",
|
|
672
|
+
});
|
|
673
|
+
// Has sections or structured formatting
|
|
674
|
+
const hasSections = /(?:#{1,3}\s|\*\*[^*]+\*\*|={3,}|-{3,})/m.test(outputStr);
|
|
675
|
+
checks.push({
|
|
676
|
+
name: "Structured formatting",
|
|
677
|
+
passed: hasSections,
|
|
678
|
+
weight: 0.05,
|
|
679
|
+
detail: hasSections
|
|
680
|
+
? "Output has structured sections"
|
|
681
|
+
: "Output lacks clear section structure",
|
|
682
|
+
});
|
|
683
|
+
// Addresses the task (references files from context if any)
|
|
684
|
+
const hasSpecifics = /(?:file|component|module|service|api|endpoint)/i.test(outputStr);
|
|
685
|
+
checks.push({
|
|
686
|
+
name: "Task-specific content",
|
|
687
|
+
passed: hasSpecifics,
|
|
688
|
+
weight: 0.1,
|
|
689
|
+
detail: hasSpecifics
|
|
690
|
+
? "References specific files/components"
|
|
691
|
+
: "Lacks specific file/component references",
|
|
692
|
+
});
|
|
693
|
+
return checks;
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Analyzer output: should have issues with severity and structured findings.
|
|
697
|
+
*/
|
|
698
|
+
checkAnalyzerQuality(outputStr) {
|
|
699
|
+
const checks = [];
|
|
700
|
+
// Has severity indicators
|
|
701
|
+
const hasSeverity = /(?:critical|high|medium|low|severity|priority|warning|info)/i.test(outputStr);
|
|
702
|
+
checks.push({
|
|
703
|
+
name: "Has severity levels",
|
|
704
|
+
passed: hasSeverity,
|
|
705
|
+
weight: 0.15,
|
|
706
|
+
detail: hasSeverity
|
|
707
|
+
? "Severity levels present"
|
|
708
|
+
: "Missing severity level indicators",
|
|
709
|
+
});
|
|
710
|
+
// Has structured findings (not just prose)
|
|
711
|
+
const hasFindings = /(?:issue|finding|problem|defect|bug|vulnerability|violation)/i.test(outputStr);
|
|
712
|
+
checks.push({
|
|
713
|
+
name: "Has structured findings",
|
|
714
|
+
passed: hasFindings,
|
|
715
|
+
weight: 0.15,
|
|
716
|
+
detail: hasFindings
|
|
717
|
+
? "Structured findings present"
|
|
718
|
+
: "Missing structured findings/issues",
|
|
719
|
+
});
|
|
720
|
+
// Has remediation/recommendations
|
|
721
|
+
const hasRemediation = /(?:recommend|suggest|fix|remediat|resolution|solution)/i.test(outputStr);
|
|
722
|
+
checks.push({
|
|
723
|
+
name: "Has remediation advice",
|
|
724
|
+
passed: hasRemediation,
|
|
725
|
+
weight: 0.1,
|
|
726
|
+
detail: hasRemediation
|
|
727
|
+
? "Remediation advice present"
|
|
728
|
+
: "Missing remediation/fix recommendations",
|
|
729
|
+
});
|
|
730
|
+
return checks;
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* Reviewer output: should have quality assessment and actionable feedback.
|
|
734
|
+
*/
|
|
735
|
+
checkReviewerQuality(outputStr) {
|
|
736
|
+
const checks = [];
|
|
737
|
+
// Has an explicit decision/assessment
|
|
738
|
+
const hasDecision = /(?:approved?|decline|accept|reject|pass|fail|verdict|recommend)/i.test(outputStr);
|
|
739
|
+
checks.push({
|
|
740
|
+
name: "Has explicit decision",
|
|
741
|
+
passed: hasDecision,
|
|
742
|
+
weight: 0.15,
|
|
743
|
+
detail: hasDecision
|
|
744
|
+
? "Contains an explicit review decision"
|
|
745
|
+
: "Missing explicit approve/decline decision",
|
|
746
|
+
});
|
|
747
|
+
// Has reasoning/justification
|
|
748
|
+
const hasReasoning = /(?:because|reason|rationale|since|due to|given that|therefore)/i.test(outputStr);
|
|
749
|
+
checks.push({
|
|
750
|
+
name: "Has reasoning",
|
|
751
|
+
passed: hasReasoning,
|
|
752
|
+
weight: 0.1,
|
|
753
|
+
detail: hasReasoning
|
|
754
|
+
? "Reasoning/justification provided"
|
|
755
|
+
: "Missing reasoning for the decision",
|
|
756
|
+
});
|
|
757
|
+
// Has actionable feedback
|
|
758
|
+
const hasFeedback = /(?:should|could|consider|improve|change|add|remove|ensure)/i.test(outputStr);
|
|
759
|
+
checks.push({
|
|
760
|
+
name: "Has actionable feedback",
|
|
761
|
+
passed: hasFeedback,
|
|
762
|
+
weight: 0.15,
|
|
763
|
+
detail: hasFeedback
|
|
764
|
+
? "Actionable feedback present"
|
|
765
|
+
: "Missing actionable improvement suggestions",
|
|
766
|
+
});
|
|
767
|
+
return checks;
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Rewriter output: should contain code that differs from input, with balanced syntax.
|
|
771
|
+
*/
|
|
772
|
+
checkRewriterQuality(work, outputStr) {
|
|
773
|
+
const checks = [];
|
|
774
|
+
// Has actual code content
|
|
775
|
+
const codePatterns = /(?:function|class|const|let|var|import|export|def |return|if\s*\(|for\s*\(|while\s*\()/i;
|
|
776
|
+
const hasCode = codePatterns.test(outputStr);
|
|
777
|
+
checks.push({
|
|
778
|
+
name: "Contains code",
|
|
779
|
+
passed: hasCode,
|
|
780
|
+
weight: 0.2,
|
|
781
|
+
detail: hasCode
|
|
782
|
+
? "Code content detected"
|
|
783
|
+
: "No recognizable code patterns found",
|
|
784
|
+
});
|
|
785
|
+
// Check balanced braces/brackets/parens
|
|
786
|
+
const balanced = this.checkBalancedDelimiters(outputStr);
|
|
787
|
+
checks.push({
|
|
788
|
+
name: "Balanced delimiters",
|
|
789
|
+
passed: balanced.balanced,
|
|
790
|
+
weight: 0.15,
|
|
791
|
+
detail: balanced.balanced
|
|
792
|
+
? "All braces, brackets, and parens are balanced"
|
|
793
|
+
: `Unbalanced delimiters: ${balanced.detail}`,
|
|
794
|
+
});
|
|
795
|
+
// Output differs from input (not a no-op)
|
|
796
|
+
const inputStr = this.formatOutput(work.task.prompt);
|
|
797
|
+
const isDifferent = outputStr.trim() !== inputStr.trim() &&
|
|
798
|
+
!outputStr.includes("no changes needed");
|
|
799
|
+
checks.push({
|
|
800
|
+
name: "Output differs from input",
|
|
801
|
+
passed: isDifferent,
|
|
802
|
+
weight: 0.05,
|
|
803
|
+
detail: isDifferent
|
|
804
|
+
? "Output contains modifications"
|
|
805
|
+
: "Output appears identical to input or explicitly states no changes",
|
|
806
|
+
});
|
|
807
|
+
return checks;
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* UI designer output: should have component structure, styling, and accessibility mentions.
|
|
811
|
+
*/
|
|
812
|
+
checkUIDesignerQuality(outputStr) {
|
|
813
|
+
const checks = [];
|
|
814
|
+
// Has component/layout structure
|
|
815
|
+
const hasStructure = /(?:<\w+|component|layout|container|wrapper|grid|flex|section)/i.test(outputStr);
|
|
816
|
+
checks.push({
|
|
817
|
+
name: "Has component structure",
|
|
818
|
+
passed: hasStructure,
|
|
819
|
+
weight: 0.15,
|
|
820
|
+
detail: hasStructure
|
|
821
|
+
? "Component/layout structure detected"
|
|
822
|
+
: "Missing component or layout structure",
|
|
823
|
+
});
|
|
824
|
+
// Has styling references
|
|
825
|
+
const hasStyling = /(?:style|css|class|className|tailwind|color|bg-|text-|p-|m-|w-|h-)/i.test(outputStr);
|
|
826
|
+
checks.push({
|
|
827
|
+
name: "Has styling",
|
|
828
|
+
passed: hasStyling,
|
|
829
|
+
weight: 0.1,
|
|
830
|
+
detail: hasStyling
|
|
831
|
+
? "Styling references found"
|
|
832
|
+
: "Missing styling/CSS references",
|
|
833
|
+
});
|
|
834
|
+
// Mentions accessibility
|
|
835
|
+
const hasA11y = /(?:aria-|role=|alt=|accessib|wcag|screen.?reader|semantic)/i.test(outputStr);
|
|
836
|
+
checks.push({
|
|
837
|
+
name: "Accessibility awareness",
|
|
838
|
+
passed: hasA11y,
|
|
839
|
+
weight: 0.1,
|
|
840
|
+
detail: hasA11y
|
|
841
|
+
? "Accessibility considerations present"
|
|
842
|
+
: "No accessibility mentions (aria, role, alt, etc.)",
|
|
843
|
+
});
|
|
844
|
+
// Has responsive design mentions
|
|
845
|
+
const hasResponsive = /(?:responsive|mobile|desktop|tablet|breakpoint|media|sm:|md:|lg:|xl:)/i.test(outputStr);
|
|
846
|
+
checks.push({
|
|
847
|
+
name: "Responsive design",
|
|
848
|
+
passed: hasResponsive,
|
|
849
|
+
weight: 0.05,
|
|
850
|
+
detail: hasResponsive
|
|
851
|
+
? "Responsive design considerations present"
|
|
852
|
+
: "No responsive design mentions",
|
|
853
|
+
});
|
|
854
|
+
return checks;
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* Researcher output: should have sources, findings, and evidence.
|
|
858
|
+
*/
|
|
859
|
+
checkResearcherQuality(outputStr) {
|
|
860
|
+
const checks = [];
|
|
861
|
+
// Has source references
|
|
862
|
+
const hasSources = /(?:source|reference|citation|http|url|link|according to|per )/i.test(outputStr);
|
|
863
|
+
checks.push({
|
|
864
|
+
name: "Has source references",
|
|
865
|
+
passed: hasSources,
|
|
866
|
+
weight: 0.15,
|
|
867
|
+
detail: hasSources
|
|
868
|
+
? "Source references found"
|
|
869
|
+
: "Missing source references or citations",
|
|
870
|
+
});
|
|
871
|
+
// Has key findings
|
|
872
|
+
const hasFindings = /(?:finding|result|discover|evidence|data|conclusion|insight)/i.test(outputStr);
|
|
873
|
+
checks.push({
|
|
874
|
+
name: "Has key findings",
|
|
875
|
+
passed: hasFindings,
|
|
876
|
+
weight: 0.15,
|
|
877
|
+
detail: hasFindings
|
|
878
|
+
? "Key findings present"
|
|
879
|
+
: "Missing key findings or evidence",
|
|
880
|
+
});
|
|
881
|
+
// Has summary or conclusion
|
|
882
|
+
const hasSummary = /(?:summary|conclusion|overview|in summary|to summarize|key takeaway)/i.test(outputStr);
|
|
883
|
+
checks.push({
|
|
884
|
+
name: "Has summary/conclusion",
|
|
885
|
+
passed: hasSummary,
|
|
886
|
+
weight: 0.1,
|
|
887
|
+
detail: hasSummary
|
|
888
|
+
? "Summary/conclusion present"
|
|
889
|
+
: "Missing summary or concluding section",
|
|
890
|
+
});
|
|
891
|
+
return checks;
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* Generic quality checks for agent types without specific heuristics.
|
|
895
|
+
*/
|
|
896
|
+
checkGenericQuality(outputStr) {
|
|
897
|
+
const checks = [];
|
|
898
|
+
const hasStructure = /(?:#{1,3}\s|\*\*[^*]+\*\*|\d+[\.\)]\s|\-\s\S)/m.test(outputStr);
|
|
899
|
+
checks.push({
|
|
900
|
+
name: "Has structure",
|
|
901
|
+
passed: hasStructure,
|
|
902
|
+
weight: 0.2,
|
|
903
|
+
detail: hasStructure
|
|
904
|
+
? "Output has recognizable structure"
|
|
905
|
+
: "Output lacks clear structure (headings, lists, etc.)",
|
|
906
|
+
});
|
|
907
|
+
const hasDetail = outputStr.length >= 100;
|
|
908
|
+
checks.push({
|
|
909
|
+
name: "Has sufficient detail",
|
|
910
|
+
passed: hasDetail,
|
|
911
|
+
weight: 0.2,
|
|
912
|
+
detail: hasDetail
|
|
913
|
+
? `Output has ${outputStr.length} characters of detail`
|
|
914
|
+
: `Output is too brief (${outputStr.length} chars)`,
|
|
915
|
+
});
|
|
916
|
+
return checks;
|
|
917
|
+
}
|
|
918
|
+
/**
|
|
919
|
+
* Check if delimiters ({}, [], ()) are balanced in the output.
|
|
920
|
+
* Important for code output — unbalanced delimiters usually mean broken code.
|
|
921
|
+
*/
|
|
922
|
+
checkBalancedDelimiters(text) {
|
|
923
|
+
// Strip string literals and comments to avoid false positives
|
|
924
|
+
const stripped = text
|
|
925
|
+
.replace(/\/\/.*$/gm, "") // single-line comments
|
|
926
|
+
.replace(/\/\*[\s\S]*?\*\//g, "") // multi-line comments
|
|
927
|
+
.replace(/#.*$/gm, "") // Python-style comments
|
|
928
|
+
.replace(/"(?:[^"\\]|\\.)*"/g, '""') // double-quoted strings
|
|
929
|
+
.replace(/'(?:[^'\\]|\\.)*'/g, "''") // single-quoted strings
|
|
930
|
+
.replace(/`(?:[^`\\]|\\.)*`/g, "``"); // template literals
|
|
931
|
+
let braces = 0;
|
|
932
|
+
let brackets = 0;
|
|
933
|
+
let parens = 0;
|
|
934
|
+
for (const ch of stripped) {
|
|
935
|
+
if (ch === "{")
|
|
936
|
+
braces++;
|
|
937
|
+
else if (ch === "}")
|
|
938
|
+
braces--;
|
|
939
|
+
else if (ch === "[")
|
|
940
|
+
brackets++;
|
|
941
|
+
else if (ch === "]")
|
|
942
|
+
brackets--;
|
|
943
|
+
else if (ch === "(")
|
|
944
|
+
parens++;
|
|
945
|
+
else if (ch === ")")
|
|
946
|
+
parens--;
|
|
947
|
+
// Early exit: if any counter goes negative, we have a closing without opening
|
|
948
|
+
if (braces < 0 || brackets < 0 || parens < 0) {
|
|
949
|
+
const problems = [];
|
|
950
|
+
if (braces < 0)
|
|
951
|
+
problems.push("extra closing }");
|
|
952
|
+
if (brackets < 0)
|
|
953
|
+
problems.push("extra closing ]");
|
|
954
|
+
if (parens < 0)
|
|
955
|
+
problems.push("extra closing )");
|
|
956
|
+
return { balanced: false, detail: problems.join(", ") };
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
if (braces === 0 && brackets === 0 && parens === 0) {
|
|
960
|
+
return { balanced: true, detail: "All delimiters balanced" };
|
|
961
|
+
}
|
|
962
|
+
const problems = [];
|
|
963
|
+
if (braces !== 0)
|
|
964
|
+
problems.push(`braces off by ${braces > 0 ? "+" : ""}${braces}`);
|
|
965
|
+
if (brackets !== 0)
|
|
966
|
+
problems.push(`brackets off by ${brackets > 0 ? "+" : ""}${brackets}`);
|
|
967
|
+
if (parens !== 0)
|
|
968
|
+
problems.push(`parens off by ${parens > 0 ? "+" : ""}${parens}`);
|
|
969
|
+
return { balanced: false, detail: problems.join(", ") };
|
|
970
|
+
}
|
|
971
|
+
// ==========================================================================
|
|
972
|
+
// Output Formatting
|
|
973
|
+
// ==========================================================================
|
|
974
|
+
/**
|
|
975
|
+
* Format output for review
|
|
976
|
+
*/
|
|
977
|
+
formatOutput(output) {
|
|
978
|
+
if (!output)
|
|
979
|
+
return "No output provided";
|
|
980
|
+
if (typeof output === "string") {
|
|
981
|
+
return output.substring(0, 6000);
|
|
982
|
+
}
|
|
983
|
+
try {
|
|
984
|
+
const jsonStr = JSON.stringify(output, null, 2);
|
|
985
|
+
return jsonStr.substring(0, 6000);
|
|
986
|
+
}
|
|
987
|
+
catch {
|
|
988
|
+
return String(output).substring(0, 6000);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* Parse the review response
|
|
993
|
+
*/
|
|
994
|
+
parseReviewResponse(response) {
|
|
995
|
+
try {
|
|
996
|
+
// Try to extract JSON from response
|
|
997
|
+
const jsonMatch = response.match(/\{[\s\S]*\}/);
|
|
998
|
+
if (!jsonMatch) {
|
|
999
|
+
return this.analyzeTextDecision(response);
|
|
1000
|
+
}
|
|
1001
|
+
const parsed = JSON.parse(jsonMatch[0]);
|
|
1002
|
+
// Determine decision
|
|
1003
|
+
let decision = "approve";
|
|
1004
|
+
if (parsed.decision) {
|
|
1005
|
+
if (parsed.decision === "decline") {
|
|
1006
|
+
decision = "decline";
|
|
1007
|
+
}
|
|
1008
|
+
else if (parsed.decision === "approve") {
|
|
1009
|
+
decision = "approve";
|
|
1010
|
+
}
|
|
1011
|
+
else {
|
|
1012
|
+
// Handle other decisions like "request_revision"
|
|
1013
|
+
decision =
|
|
1014
|
+
parsed.decision === "request_revision" ? "decline" : "approve";
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
// Check for critical issues that should trigger decline
|
|
1018
|
+
const criticalIssues = (parsed.issues || []).filter((i) => i.severity === "critical");
|
|
1019
|
+
const highIssues = (parsed.issues || []).filter((i) => i.severity === "high");
|
|
1020
|
+
const mustHaveSuggestions = (parsed.suggestions || []).filter((s) => s.priority === "must");
|
|
1021
|
+
// Override decision based on issue severity
|
|
1022
|
+
if (criticalIssues.length > 0) {
|
|
1023
|
+
decision = "decline";
|
|
1024
|
+
}
|
|
1025
|
+
else if (highIssues.length > 0 && this.config.strictMode) {
|
|
1026
|
+
decision = "decline";
|
|
1027
|
+
}
|
|
1028
|
+
else if (mustHaveSuggestions.length > 0) {
|
|
1029
|
+
decision = "decline";
|
|
1030
|
+
}
|
|
1031
|
+
// Calculate confidence
|
|
1032
|
+
let confidence = parsed.confidence ?? 0.7;
|
|
1033
|
+
confidence -= parsed.issues?.length * 0.05 || 0;
|
|
1034
|
+
confidence = Math.max(0, Math.min(1, confidence));
|
|
1035
|
+
return {
|
|
1036
|
+
decision,
|
|
1037
|
+
confidence,
|
|
1038
|
+
reasoning: parsed.reasoning || "Review completed",
|
|
1039
|
+
issues: (parsed.issues || []).map((issue, idx) => ({
|
|
1040
|
+
id: issue.id || `issue-${idx}`,
|
|
1041
|
+
severity: issue.severity || "medium",
|
|
1042
|
+
category: issue.category || "code_quality",
|
|
1043
|
+
description: issue.description || "Issue identified",
|
|
1044
|
+
evidence: issue.evidence || "",
|
|
1045
|
+
remediation: issue.remediation || "",
|
|
1046
|
+
})),
|
|
1047
|
+
suggestions: (parsed.suggestions || []).map((sug, idx) => ({
|
|
1048
|
+
id: sug.id || `suggest-${idx}`,
|
|
1049
|
+
priority: sug.priority || "should",
|
|
1050
|
+
category: sug.category || "code_quality",
|
|
1051
|
+
description: sug.description || "Suggestion",
|
|
1052
|
+
rationale: sug.rationale || "",
|
|
1053
|
+
})),
|
|
1054
|
+
};
|
|
1055
|
+
}
|
|
1056
|
+
catch {
|
|
1057
|
+
return this.analyzeTextDecision(response);
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Analyze text response when JSON parsing fails
|
|
1062
|
+
*/
|
|
1063
|
+
analyzeTextDecision(response) {
|
|
1064
|
+
const lower = response.toLowerCase();
|
|
1065
|
+
// Check for negative indicators
|
|
1066
|
+
const hasCritical = lower.includes("critical");
|
|
1067
|
+
const hasHigh = lower.includes("high severity");
|
|
1068
|
+
const hasMajor = lower.includes("major issue");
|
|
1069
|
+
const needsWork = lower.includes("needs work") || lower.includes("should fix");
|
|
1070
|
+
let decision = "approve";
|
|
1071
|
+
if (hasCritical || hasHigh || hasMajor || needsWork) {
|
|
1072
|
+
decision = "decline";
|
|
1073
|
+
}
|
|
1074
|
+
return {
|
|
1075
|
+
decision,
|
|
1076
|
+
confidence: decision === "approve" ? 0.6 : 0.4,
|
|
1077
|
+
reasoning: response.substring(0, 300),
|
|
1078
|
+
issues: decision === "decline"
|
|
1079
|
+
? [
|
|
1080
|
+
{
|
|
1081
|
+
id: "text-issue-1",
|
|
1082
|
+
severity: "medium",
|
|
1083
|
+
category: "code_quality",
|
|
1084
|
+
description: "Issue detected from text analysis",
|
|
1085
|
+
evidence: response.substring(0, 200),
|
|
1086
|
+
remediation: "Review and fix the identified issues",
|
|
1087
|
+
},
|
|
1088
|
+
]
|
|
1089
|
+
: [],
|
|
1090
|
+
suggestions: [],
|
|
1091
|
+
};
|
|
1092
|
+
}
|
|
1093
|
+
/**
|
|
1094
|
+
* Check if max retries exceeded
|
|
1095
|
+
*/
|
|
1096
|
+
hasExceededMaxRetries() {
|
|
1097
|
+
return this.retryHistory.length >= this.config.maxRetries;
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* Get current retry count
|
|
1101
|
+
*/
|
|
1102
|
+
getRetryCount() {
|
|
1103
|
+
return this.retryHistory.length;
|
|
1104
|
+
}
|
|
1105
|
+
/**
|
|
1106
|
+
* Get retry history
|
|
1107
|
+
*/
|
|
1108
|
+
getRetryHistory() {
|
|
1109
|
+
return [...this.retryHistory];
|
|
1110
|
+
}
|
|
1111
|
+
/**
|
|
1112
|
+
* Reset history for new task
|
|
1113
|
+
*/
|
|
1114
|
+
reset() {
|
|
1115
|
+
this.retryHistory = [];
|
|
1116
|
+
}
|
|
1117
|
+
/**
|
|
1118
|
+
* Get config
|
|
1119
|
+
*/
|
|
1120
|
+
getConfig() {
|
|
1121
|
+
return { ...this.config };
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
// ============================================================================
|
|
1125
|
+
// Factory
|
|
1126
|
+
// ============================================================================
|
|
1127
|
+
export function createInternalGatekeeper(agentType, toolBridge, config) {
|
|
1128
|
+
return new InternalGatekeeper(agentType, toolBridge, config);
|
|
1129
|
+
}
|
|
1130
|
+
//# sourceMappingURL=internal-gatekeeper.js.map
|