grok-wr1now 1.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/LICENSE +21 -0
- package/README.md +223 -0
- package/dist/accuracy/hallucination-reducer.d.ts +28 -0
- package/dist/accuracy/hallucination-reducer.js +59 -0
- package/dist/agents/dispatcher.d.ts +70 -0
- package/dist/agents/dispatcher.js +212 -0
- package/dist/agents/focused-subagent.d.ts +19 -0
- package/dist/agents/focused-subagent.js +85 -0
- package/dist/agents/index.d.ts +3 -0
- package/dist/agents/index.js +2 -0
- package/dist/analysis/hallucination-reducer.d.ts +28 -0
- package/dist/analysis/hallucination-reducer.js +62 -0
- package/dist/architect/mode.d.ts +8 -0
- package/dist/architect/mode.js +17 -0
- package/dist/architect/models.d.ts +14 -0
- package/dist/architect/models.js +22 -0
- package/dist/architecture/decision.d.ts +2 -0
- package/dist/architecture/decision.js +6 -0
- package/dist/autodream/dream.d.ts +22 -0
- package/dist/autodream/dream.js +1 -0
- package/dist/autodream/executor.d.ts +13 -0
- package/dist/autodream/executor.js +38 -0
- package/dist/autopilot-pro/agent/full-mode.d.ts +14 -0
- package/dist/autopilot-pro/agent/full-mode.js +43 -0
- package/dist/autopilot-pro/implementation.d.ts +57 -0
- package/dist/autopilot-pro/implementation.js +242 -0
- package/dist/autopilot-pro/index.d.ts +12 -0
- package/dist/autopilot-pro/index.js +6 -0
- package/dist/autopilot-pro/intelligence.d.ts +66 -0
- package/dist/autopilot-pro/intelligence.js +334 -0
- package/dist/autopilot-pro/obsidian-sync.d.ts +48 -0
- package/dist/autopilot-pro/obsidian-sync.js +260 -0
- package/dist/autopilot-pro/pilot-loop.d.ts +133 -0
- package/dist/autopilot-pro/pilot-loop.js +691 -0
- package/dist/autopilot-pro/strategy.d.ts +45 -0
- package/dist/autopilot-pro/strategy.js +317 -0
- package/dist/autopilot-pro/tools/extended-tools.d.ts +31 -0
- package/dist/autopilot-pro/tools/extended-tools.js +53 -0
- package/dist/autopilot-pro/validation.d.ts +33 -0
- package/dist/autopilot-pro/validation.js +192 -0
- package/dist/autoresearch/benchmark-runner.d.ts +23 -0
- package/dist/autoresearch/benchmark-runner.js +223 -0
- package/dist/autoresearch/benchmark.d.ts +67 -0
- package/dist/autoresearch/benchmark.js +122 -0
- package/dist/autoresearch/competitor-architecture.d.ts +21 -0
- package/dist/autoresearch/competitor-architecture.js +162 -0
- package/dist/autoresearch/competitor-fetcher.d.ts +39 -0
- package/dist/autoresearch/competitor-fetcher.js +234 -0
- package/dist/autoresearch/competitor-researcher.d.ts +9 -0
- package/dist/autoresearch/competitor-researcher.js +202 -0
- package/dist/autoresearch/competitor-trajectory.d.ts +40 -0
- package/dist/autoresearch/competitor-trajectory.js +174 -0
- package/dist/autoresearch/competitors.d.ts +26 -0
- package/dist/autoresearch/competitors.js +111 -0
- package/dist/autoresearch/experiment-loop.d.ts +79 -0
- package/dist/autoresearch/experiment-loop.js +283 -0
- package/dist/autoresearch/index.d.ts +32 -0
- package/dist/autoresearch/index.js +16 -0
- package/dist/autoresearch/isolation.d.ts +25 -0
- package/dist/autoresearch/isolation.js +74 -0
- package/dist/autoresearch/l1-loop.d.ts +59 -0
- package/dist/autoresearch/l1-loop.js +112 -0
- package/dist/autoresearch/l1.d.ts +104 -0
- package/dist/autoresearch/l1.js +419 -0
- package/dist/autoresearch/l2.d.ts +75 -0
- package/dist/autoresearch/l2.js +238 -0
- package/dist/autoresearch/l3.d.ts +59 -0
- package/dist/autoresearch/l3.js +194 -0
- package/dist/autoresearch/meta-agent.d.ts +85 -0
- package/dist/autoresearch/meta-agent.js +309 -0
- package/dist/autoresearch/objectives.d.ts +16 -0
- package/dist/autoresearch/objectives.js +101 -0
- package/dist/autoresearch/oversight-feedback.d.ts +58 -0
- package/dist/autoresearch/oversight-feedback.js +116 -0
- package/dist/autoresearch/runtime-bridge.d.ts +136 -0
- package/dist/autoresearch/runtime-bridge.js +447 -0
- package/dist/autoresearch/trace.d.ts +26 -0
- package/dist/autoresearch/trace.js +166 -0
- package/dist/benchmark/cases.d.ts +7 -0
- package/dist/benchmark/cases.js +22 -0
- package/dist/benchmark/evaluator.d.ts +1 -0
- package/dist/benchmark/evaluator.js +9 -0
- package/dist/benchmark/suite.d.ts +3 -0
- package/dist/benchmark/suite.js +24 -0
- package/dist/benchmark/swe-bench-enhancer.d.ts +9 -0
- package/dist/benchmark/swe-bench-enhancer.js +72 -0
- package/dist/benchmark/swe-bench-runner.d.ts +4 -0
- package/dist/benchmark/swe-bench-runner.js +20 -0
- package/dist/benchmark/swe.d.ts +2 -0
- package/dist/benchmark/swe.js +17 -0
- package/dist/cli/architect-cmd.d.ts +13 -0
- package/dist/cli/architect-cmd.js +59 -0
- package/dist/cli/ask-cmd.d.ts +19 -0
- package/dist/cli/ask-cmd.js +34 -0
- package/dist/cli/auto-implement-cmd.d.ts +7 -0
- package/dist/cli/auto-implement-cmd.js +54 -0
- package/dist/cli/autocomplete.d.ts +10 -0
- package/dist/cli/autocomplete.js +210 -0
- package/dist/cli/autopilot.d.ts +68 -0
- package/dist/cli/autopilot.js +293 -0
- package/dist/cli/autoresearch-cmd.d.ts +7 -0
- package/dist/cli/autoresearch-cmd.js +206 -0
- package/dist/cli/benchmark-cmd.d.ts +51 -0
- package/dist/cli/benchmark-cmd.js +229 -0
- package/dist/cli/clean-cmd.d.ts +20 -0
- package/dist/cli/clean-cmd.js +109 -0
- package/dist/cli/config-cmd.d.ts +36 -0
- package/dist/cli/config-cmd.js +201 -0
- package/dist/cli/daemon-cmd.d.ts +10 -0
- package/dist/cli/daemon-cmd.js +131 -0
- package/dist/cli/dashboard.d.ts +50 -0
- package/dist/cli/dashboard.js +237 -0
- package/dist/cli/decisions-cmd.d.ts +22 -0
- package/dist/cli/decisions-cmd.js +117 -0
- package/dist/cli/doctor-cmd.d.ts +15 -0
- package/dist/cli/doctor-cmd.js +217 -0
- package/dist/cli/env-cmd.d.ts +35 -0
- package/dist/cli/env-cmd.js +75 -0
- package/dist/cli/eval-cmd.d.ts +25 -0
- package/dist/cli/eval-cmd.js +108 -0
- package/dist/cli/explain-cmd.d.ts +28 -0
- package/dist/cli/explain-cmd.js +74 -0
- package/dist/cli/export-cmd.d.ts +17 -0
- package/dist/cli/export-cmd.js +141 -0
- package/dist/cli/git-ai.d.ts +29 -0
- package/dist/cli/git-ai.js +137 -0
- package/dist/cli/health.d.ts +42 -0
- package/dist/cli/health.js +159 -0
- package/dist/cli/history-cmd.d.ts +17 -0
- package/dist/cli/history-cmd.js +60 -0
- package/dist/cli/init.d.ts +18 -0
- package/dist/cli/init.js +130 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +1826 -0
- package/dist/cli/mcp-cmd.d.ts +10 -0
- package/dist/cli/mcp-cmd.js +64 -0
- package/dist/cli/migrate-cmd.d.ts +29 -0
- package/dist/cli/migrate-cmd.js +138 -0
- package/dist/cli/model-picker.d.ts +22 -0
- package/dist/cli/model-picker.js +107 -0
- package/dist/cli/pilot-pro-cmd.d.ts +9 -0
- package/dist/cli/pilot-pro-cmd.js +214 -0
- package/dist/cli/ping-cmd.d.ts +1 -0
- package/dist/cli/ping-cmd.js +3 -0
- package/dist/cli/plan-view.d.ts +17 -0
- package/dist/cli/plan-view.js +111 -0
- package/dist/cli/plugin-cmd.d.ts +31 -0
- package/dist/cli/plugin-cmd.js +124 -0
- package/dist/cli/refactor-cmd.d.ts +20 -0
- package/dist/cli/refactor-cmd.js +50 -0
- package/dist/cli/repl.d.ts +10 -0
- package/dist/cli/repl.js +2735 -0
- package/dist/cli/run-cmd.d.ts +40 -0
- package/dist/cli/run-cmd.js +238 -0
- package/dist/cli/safe-input.d.ts +5 -0
- package/dist/cli/safe-input.js +49 -0
- package/dist/cli/schedule-cmd.d.ts +34 -0
- package/dist/cli/schedule-cmd.js +152 -0
- package/dist/cli/search-cmd.d.ts +32 -0
- package/dist/cli/search-cmd.js +135 -0
- package/dist/cli/session-presets.d.ts +24 -0
- package/dist/cli/session-presets.js +183 -0
- package/dist/cli/stats.d.ts +33 -0
- package/dist/cli/stats.js +120 -0
- package/dist/cli/subcommands.d.ts +64 -0
- package/dist/cli/subcommands.js +334 -0
- package/dist/cli/terminal-cmd.d.ts +18 -0
- package/dist/cli/terminal-cmd.js +71 -0
- package/dist/cli/todo-cmd.d.ts +17 -0
- package/dist/cli/todo-cmd.js +80 -0
- package/dist/cli/watch-cmd.d.ts +19 -0
- package/dist/cli/watch-cmd.js +71 -0
- package/dist/core/anthropic-provider.d.ts +29 -0
- package/dist/core/anthropic-provider.js +205 -0
- package/dist/core/config-validator.d.ts +23 -0
- package/dist/core/config-validator.js +83 -0
- package/dist/core/conversation-runtime.d.ts +42 -0
- package/dist/core/conversation-runtime.js +127 -0
- package/dist/core/daemon.d.ts +69 -0
- package/dist/core/daemon.js +321 -0
- package/dist/core/error-recovery.d.ts +68 -0
- package/dist/core/error-recovery.js +185 -0
- package/dist/core/execution-mode.d.ts +86 -0
- package/dist/core/execution-mode.js +234 -0
- package/dist/core/health-monitor.d.ts +59 -0
- package/dist/core/health-monitor.js +139 -0
- package/dist/core/index.d.ts +42 -0
- package/dist/core/index.js +21 -0
- package/dist/core/logger.d.ts +34 -0
- package/dist/core/logger.js +71 -0
- package/dist/core/mcp-server.d.ts +72 -0
- package/dist/core/mcp-server.js +505 -0
- package/dist/core/openai-provider.d.ts +37 -0
- package/dist/core/openai-provider.js +216 -0
- package/dist/core/persistence.d.ts +96 -0
- package/dist/core/persistence.js +162 -0
- package/dist/core/provider-config.d.ts +57 -0
- package/dist/core/provider-config.js +115 -0
- package/dist/core/rate-limiter.d.ts +28 -0
- package/dist/core/rate-limiter.js +72 -0
- package/dist/core/request-metadata.d.ts +22 -0
- package/dist/core/request-metadata.js +51 -0
- package/dist/core/runtime.d.ts +66 -0
- package/dist/core/runtime.js +472 -0
- package/dist/core/session-restore.d.ts +52 -0
- package/dist/core/session-restore.js +129 -0
- package/dist/core/session.d.ts +73 -0
- package/dist/core/session.js +132 -0
- package/dist/core/workspace.d.ts +45 -0
- package/dist/core/workspace.js +120 -0
- package/dist/core/xai-embeddings.d.ts +32 -0
- package/dist/core/xai-embeddings.js +106 -0
- package/dist/core/xai-provider.d.ts +27 -0
- package/dist/core/xai-provider.js +214 -0
- package/dist/core/xai-streaming.d.ts +22 -0
- package/dist/core/xai-streaming.js +172 -0
- package/dist/daemon/context-monitor.d.ts +13 -0
- package/dist/daemon/context-monitor.js +37 -0
- package/dist/daemon/kairos-daemon.d.ts +11 -0
- package/dist/daemon/kairos-daemon.js +52 -0
- package/dist/daemon/kairos.d.ts +11 -0
- package/dist/daemon/kairos.js +34 -0
- package/dist/daemon/monitor.d.ts +10 -0
- package/dist/daemon/monitor.js +31 -0
- package/dist/execution/autodream-executor.d.ts +17 -0
- package/dist/execution/autodream-executor.js +31 -0
- package/dist/execution/autodream.d.ts +11 -0
- package/dist/execution/autodream.js +34 -0
- package/dist/execution/multi-step-runner.d.ts +11 -0
- package/dist/execution/multi-step-runner.js +64 -0
- package/dist/governance/agent-registry.d.ts +7 -0
- package/dist/governance/agent-registry.js +12 -0
- package/dist/governance/layer.d.ts +29 -0
- package/dist/governance/layer.js +40 -0
- package/dist/governance/multi-agent-governor.d.ts +28 -0
- package/dist/governance/multi-agent-governor.js +49 -0
- package/dist/governance/multi-agent.d.ts +15 -0
- package/dist/governance/multi-agent.js +32 -0
- package/dist/governance/policy.d.ts +26 -0
- package/dist/governance/policy.js +23 -0
- package/dist/hallucination/reducer.d.ts +14 -0
- package/dist/hallucination/reducer.js +36 -0
- package/dist/history/appender.d.ts +1 -0
- package/dist/history/appender.js +9 -0
- package/dist/history/reader.d.ts +1 -0
- package/dist/history/reader.js +12 -0
- package/dist/ide/extension.d.ts +11 -0
- package/dist/ide/extension.js +43 -0
- package/dist/ide/ide-extension.d.ts +13 -0
- package/dist/ide/ide-extension.js +35 -0
- package/dist/ide/ide-integration.d.ts +24 -0
- package/dist/ide/ide-integration.js +55 -0
- package/dist/ide/integration.d.ts +16 -0
- package/dist/ide/integration.js +36 -0
- package/dist/ide/native-bridge.d.ts +8 -0
- package/dist/ide/native-bridge.js +20 -0
- package/dist/ide/plugin.d.ts +1 -0
- package/dist/ide/plugin.js +80 -0
- package/dist/ide/vscode-extension.d.ts +3 -0
- package/dist/ide/vscode-extension.js +17 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +11 -0
- package/dist/kairos/context.d.ts +6 -0
- package/dist/kairos/context.js +17 -0
- package/dist/kairos/daemon.d.ts +10 -0
- package/dist/kairos/daemon.js +39 -0
- package/dist/kairos/monitor.d.ts +5 -0
- package/dist/kairos/monitor.js +11 -0
- package/dist/memory/claude-md-memory.d.ts +7 -0
- package/dist/memory/claude-md-memory.js +21 -0
- package/dist/memory/claude.d.ts +5 -0
- package/dist/memory/claude.js +18 -0
- package/dist/memory/conversation-persistence.d.ts +54 -0
- package/dist/memory/conversation-persistence.js +89 -0
- package/dist/memory/conversation.d.ts +98 -0
- package/dist/memory/conversation.js +242 -0
- package/dist/memory/distiller.d.ts +71 -0
- package/dist/memory/distiller.js +180 -0
- package/dist/memory/embedding-repository.d.ts +80 -0
- package/dist/memory/embedding-repository.js +321 -0
- package/dist/memory/hierarchical-indexer.d.ts +72 -0
- package/dist/memory/hierarchical-indexer.js +321 -0
- package/dist/memory/index.d.ts +15 -0
- package/dist/memory/index.js +9 -0
- package/dist/memory/repository.d.ts +59 -0
- package/dist/memory/repository.js +226 -0
- package/dist/memory/semantic-search.d.ts +65 -0
- package/dist/memory/semantic-search.js +164 -0
- package/dist/memory/sqlite-store.d.ts +72 -0
- package/dist/memory/sqlite-store.js +345 -0
- package/dist/memory/summarizer.d.ts +49 -0
- package/dist/memory/summarizer.js +141 -0
- package/dist/meta/agent.d.ts +27 -0
- package/dist/meta/agent.js +51 -0
- package/dist/model/adapter.d.ts +90 -0
- package/dist/model/adapter.js +162 -0
- package/dist/model/contracts/autoresearch.d.ts +68 -0
- package/dist/model/contracts/autoresearch.js +1 -0
- package/dist/model/contracts/common.d.ts +39 -0
- package/dist/model/contracts/common.js +6 -0
- package/dist/model/contracts/index.d.ts +9 -0
- package/dist/model/contracts/index.js +9 -0
- package/dist/model/contracts/memory.d.ts +51 -0
- package/dist/model/contracts/memory.js +1 -0
- package/dist/model/contracts/plan.d.ts +22 -0
- package/dist/model/contracts/plan.js +1 -0
- package/dist/model/contracts/policy.d.ts +54 -0
- package/dist/model/contracts/policy.js +1 -0
- package/dist/model/contracts/provider.d.ts +108 -0
- package/dist/model/contracts/provider.js +1 -0
- package/dist/model/contracts/runtime.d.ts +45 -0
- package/dist/model/contracts/runtime.js +1 -0
- package/dist/model/contracts/tool.d.ts +45 -0
- package/dist/model/contracts/tool.js +1 -0
- package/dist/model/contracts/worker.d.ts +35 -0
- package/dist/model/contracts/worker.js +1 -0
- package/dist/model/index.d.ts +13 -0
- package/dist/model/index.js +8 -0
- package/dist/model/policy.d.ts +80 -0
- package/dist/model/policy.js +360 -0
- package/dist/model/registry.d.ts +40 -0
- package/dist/model/registry.js +100 -0
- package/dist/model/router.d.ts +31 -0
- package/dist/model/router.js +235 -0
- package/dist/model/streaming.d.ts +58 -0
- package/dist/model/streaming.js +212 -0
- package/dist/model/task-router.d.ts +50 -0
- package/dist/model/task-router.js +133 -0
- package/dist/modes/architect-mode.d.ts +13 -0
- package/dist/modes/architect-mode.js +31 -0
- package/dist/orchestrator/architect.d.ts +36 -0
- package/dist/orchestrator/architect.js +65 -0
- package/dist/orchestrator/auto-context.d.ts +20 -0
- package/dist/orchestrator/auto-context.js +88 -0
- package/dist/orchestrator/clarification.d.ts +12 -0
- package/dist/orchestrator/clarification.js +41 -0
- package/dist/orchestrator/conflict-resolver.d.ts +80 -0
- package/dist/orchestrator/conflict-resolver.js +274 -0
- package/dist/orchestrator/coordinator.d.ts +42 -0
- package/dist/orchestrator/coordinator.js +183 -0
- package/dist/orchestrator/evaluator.d.ts +12 -0
- package/dist/orchestrator/evaluator.js +25 -0
- package/dist/orchestrator/executor.d.ts +26 -0
- package/dist/orchestrator/executor.js +343 -0
- package/dist/orchestrator/index.d.ts +26 -0
- package/dist/orchestrator/index.js +15 -0
- package/dist/orchestrator/interfaces.d.ts +51 -0
- package/dist/orchestrator/interfaces.js +1 -0
- package/dist/orchestrator/model-planner.d.ts +17 -0
- package/dist/orchestrator/model-planner.js +140 -0
- package/dist/orchestrator/oversight-persistence.d.ts +37 -0
- package/dist/orchestrator/oversight-persistence.js +60 -0
- package/dist/orchestrator/oversight.d.ts +97 -0
- package/dist/orchestrator/oversight.js +321 -0
- package/dist/orchestrator/parallel-executor.d.ts +33 -0
- package/dist/orchestrator/parallel-executor.js +61 -0
- package/dist/orchestrator/planner.d.ts +14 -0
- package/dist/orchestrator/planner.js +48 -0
- package/dist/orchestrator/preflight.d.ts +128 -0
- package/dist/orchestrator/preflight.js +410 -0
- package/dist/orchestrator/streaming-executor.d.ts +35 -0
- package/dist/orchestrator/streaming-executor.js +151 -0
- package/dist/orchestrator/tool-call-loop.d.ts +56 -0
- package/dist/orchestrator/tool-call-loop.js +223 -0
- package/dist/orchestrator/tool-schema-bridge.d.ts +51 -0
- package/dist/orchestrator/tool-schema-bridge.js +87 -0
- package/dist/oversight/collector.d.ts +14 -0
- package/dist/oversight/collector.js +19 -0
- package/dist/planning/autonomous-planner.d.ts +14 -0
- package/dist/planning/autonomous-planner.js +41 -0
- package/dist/planning/ultraplan-scheduler.d.ts +16 -0
- package/dist/planning/ultraplan-scheduler.js +37 -0
- package/dist/planning/ultraplan-session.d.ts +9 -0
- package/dist/planning/ultraplan-session.js +40 -0
- package/dist/planning/ultraplan.d.ts +14 -0
- package/dist/planning/ultraplan.js +57 -0
- package/dist/runtime/focused.d.ts +5 -0
- package/dist/runtime/focused.js +12 -0
- package/dist/safety/enforcer.d.ts +63 -0
- package/dist/safety/enforcer.js +153 -0
- package/dist/safety/index.d.ts +2 -0
- package/dist/safety/index.js +1 -0
- package/dist/subagent/dispatcher.d.ts +29 -0
- package/dist/subagent/dispatcher.js +14 -0
- package/dist/telemetry/bus.d.ts +112 -0
- package/dist/telemetry/bus.js +209 -0
- package/dist/telemetry/decision-log-store.d.ts +30 -0
- package/dist/telemetry/decision-log-store.js +101 -0
- package/dist/telemetry/error-monitor.d.ts +47 -0
- package/dist/telemetry/error-monitor.js +122 -0
- package/dist/telemetry/index.d.ts +4 -0
- package/dist/telemetry/index.js +2 -0
- package/dist/terminals/index.d.ts +6 -0
- package/dist/terminals/index.js +3 -0
- package/dist/terminals/mirrored-worker.d.ts +125 -0
- package/dist/terminals/mirrored-worker.js +236 -0
- package/dist/terminals/persistence.d.ts +29 -0
- package/dist/terminals/persistence.js +46 -0
- package/dist/terminals/shared-memory.d.ts +98 -0
- package/dist/terminals/shared-memory.js +177 -0
- package/dist/thinking/extended-thinker.d.ts +11 -0
- package/dist/thinking/extended-thinker.js +26 -0
- package/dist/thinking/extended.d.ts +10 -0
- package/dist/thinking/extended.js +28 -0
- package/dist/tools/approval.d.ts +21 -0
- package/dist/tools/approval.js +57 -0
- package/dist/tools/builtin/archive-extract.d.ts +6 -0
- package/dist/tools/builtin/archive-extract.js +126 -0
- package/dist/tools/builtin/checksum.d.ts +6 -0
- package/dist/tools/builtin/checksum.js +89 -0
- package/dist/tools/builtin/command-executor.d.ts +17 -0
- package/dist/tools/builtin/command-executor.js +57 -0
- package/dist/tools/builtin/dependency-check.d.ts +6 -0
- package/dist/tools/builtin/dependency-check.js +161 -0
- package/dist/tools/builtin/docker-manage.d.ts +6 -0
- package/dist/tools/builtin/docker-manage.js +110 -0
- package/dist/tools/builtin/echo-text.d.ts +6 -0
- package/dist/tools/builtin/echo-text.js +57 -0
- package/dist/tools/builtin/edit-file.d.ts +6 -0
- package/dist/tools/builtin/edit-file.js +190 -0
- package/dist/tools/builtin/env-inspector.d.ts +6 -0
- package/dist/tools/builtin/env-inspector.js +127 -0
- package/dist/tools/builtin/git-checkout.d.ts +6 -0
- package/dist/tools/builtin/git-checkout.js +94 -0
- package/dist/tools/builtin/git-commit.d.ts +6 -0
- package/dist/tools/builtin/git-commit.js +129 -0
- package/dist/tools/builtin/git-diff.d.ts +6 -0
- package/dist/tools/builtin/git-diff.js +136 -0
- package/dist/tools/builtin/git-log.d.ts +6 -0
- package/dist/tools/builtin/git-log.js +112 -0
- package/dist/tools/builtin/git-status.d.ts +6 -0
- package/dist/tools/builtin/git-status.js +103 -0
- package/dist/tools/builtin/glob-find.d.ts +6 -0
- package/dist/tools/builtin/glob-find.js +103 -0
- package/dist/tools/builtin/grep-search.d.ts +6 -0
- package/dist/tools/builtin/grep-search.js +148 -0
- package/dist/tools/builtin/http-request.d.ts +6 -0
- package/dist/tools/builtin/http-request.js +180 -0
- package/dist/tools/builtin/index.d.ts +29 -0
- package/dist/tools/builtin/index.js +30 -0
- package/dist/tools/builtin/kubernetes-manage.d.ts +6 -0
- package/dist/tools/builtin/kubernetes-manage.js +121 -0
- package/dist/tools/builtin/lint-check.d.ts +6 -0
- package/dist/tools/builtin/lint-check.js +145 -0
- package/dist/tools/builtin/list-directory.d.ts +6 -0
- package/dist/tools/builtin/list-directory.js +156 -0
- package/dist/tools/builtin/npm-manage.d.ts +6 -0
- package/dist/tools/builtin/npm-manage.js +130 -0
- package/dist/tools/builtin/patch-apply.d.ts +6 -0
- package/dist/tools/builtin/patch-apply.js +152 -0
- package/dist/tools/builtin/port-scanner.d.ts +6 -0
- package/dist/tools/builtin/port-scanner.js +113 -0
- package/dist/tools/builtin/process-list.d.ts +6 -0
- package/dist/tools/builtin/process-list.js +110 -0
- package/dist/tools/builtin/read-file.d.ts +6 -0
- package/dist/tools/builtin/read-file.js +110 -0
- package/dist/tools/builtin/repo-map.d.ts +16 -0
- package/dist/tools/builtin/repo-map.js +211 -0
- package/dist/tools/builtin/run-command.d.ts +6 -0
- package/dist/tools/builtin/run-command.js +113 -0
- package/dist/tools/builtin/terraform-manage.d.ts +6 -0
- package/dist/tools/builtin/terraform-manage.js +116 -0
- package/dist/tools/builtin/test-runner.d.ts +6 -0
- package/dist/tools/builtin/test-runner.js +159 -0
- package/dist/tools/builtin/tree-view.d.ts +6 -0
- package/dist/tools/builtin/tree-view.js +128 -0
- package/dist/tools/builtin/web-fetch.d.ts +6 -0
- package/dist/tools/builtin/web-fetch.js +184 -0
- package/dist/tools/builtin/web-search.d.ts +6 -0
- package/dist/tools/builtin/web-search.js +119 -0
- package/dist/tools/builtin/write-file.d.ts +6 -0
- package/dist/tools/builtin/write-file.js +125 -0
- package/dist/tools/chain.d.ts +40 -0
- package/dist/tools/chain.js +63 -0
- package/dist/tools/execution-stream.d.ts +36 -0
- package/dist/tools/execution-stream.js +93 -0
- package/dist/tools/index.d.ts +26 -0
- package/dist/tools/index.js +20 -0
- package/dist/tools/interactive-approval.d.ts +24 -0
- package/dist/tools/interactive-approval.js +109 -0
- package/dist/tools/output-validator.d.ts +20 -0
- package/dist/tools/output-validator.js +35 -0
- package/dist/tools/plugin.d.ts +71 -0
- package/dist/tools/plugin.js +165 -0
- package/dist/tools/project-loader.d.ts +13 -0
- package/dist/tools/project-loader.js +179 -0
- package/dist/tools/registry.d.ts +95 -0
- package/dist/tools/registry.js +291 -0
- package/dist/tools/schema-validator.d.ts +27 -0
- package/dist/tools/schema-validator.js +222 -0
- package/dist/ultraplan/planner.d.ts +6 -0
- package/dist/ultraplan/planner.js +21 -0
- package/dist/ultraplan/session.d.ts +8 -0
- package/dist/ultraplan/session.js +19 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wr1now
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
# grok-cli
|
|
2
|
+
|
|
3
|
+
Agentic AI coding CLI powered by xAI/Grok — orchestration, memory, tools, and autonomous execution.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
**Prerequisites:** Node.js 20+, git
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
git clone https://github.com/wr1now/grok-cli.git
|
|
11
|
+
cd grok-cli
|
|
12
|
+
bash setup.sh
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The setup script installs dependencies, builds, runs tests, and tells you next steps.
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
export XAI_API_KEY="your-key-here" # get a key at https://console.x.ai
|
|
19
|
+
|
|
20
|
+
# Interactive REPL (recommended)
|
|
21
|
+
./grok -i
|
|
22
|
+
|
|
23
|
+
# Direct execution
|
|
24
|
+
./grok "explain this codebase"
|
|
25
|
+
|
|
26
|
+
# Full pipeline (preflight → oversight → execution)
|
|
27
|
+
./grok run "build a REST API"
|
|
28
|
+
|
|
29
|
+
# Autonomous mode
|
|
30
|
+
./grok run "refactor the auth module" --mode autonomous
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Global Install (optional)
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm link
|
|
37
|
+
grok "your goal here"
|
|
38
|
+
grok -i
|
|
39
|
+
grok run "goal" --mode auto
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Execution Modes
|
|
43
|
+
|
|
44
|
+
| Mode | Flag | Preflight | Oversight | Tools | Interaction |
|
|
45
|
+
|---|---|---|---|---|---|
|
|
46
|
+
| **Normal** | `--mode normal` | interactive | full | approval required | interactive |
|
|
47
|
+
| **Fast** | `--mode fast` | skip | skip | safe auto-approved | minimal |
|
|
48
|
+
| **Plan** | `--mode plan` | full | full | no execution | review only |
|
|
49
|
+
| **Autonomous** | `--mode auto` | auto-answer | auto-proceed | non-destructive auto | result only |
|
|
50
|
+
|
|
51
|
+
## Commands
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# Execution
|
|
55
|
+
grok "goal" # Direct execution
|
|
56
|
+
grok run "goal" # Preflight → Oversight → Execute
|
|
57
|
+
grok ask "question" # Quick answer, no tools
|
|
58
|
+
grok architect "goal" # Two-phase reasoning pipeline
|
|
59
|
+
grok autopilot "goal" # Agree on plan, execute uninterrupted
|
|
60
|
+
|
|
61
|
+
# AI-Powered
|
|
62
|
+
grok explain <file>[:<lines>] # AI code explanation
|
|
63
|
+
grok refactor <file> # AI refactoring suggestions
|
|
64
|
+
grok diff # AI diff summary + commit suggestion
|
|
65
|
+
grok commit # AI-generated commit message
|
|
66
|
+
grok pr # AI-generated PR description
|
|
67
|
+
|
|
68
|
+
# Project
|
|
69
|
+
grok init # Create .grok/ directory
|
|
70
|
+
grok config # View/edit project config
|
|
71
|
+
grok dashboard # Architecture + progress overview
|
|
72
|
+
grok scan # Project structure analysis
|
|
73
|
+
grok workspace # Multi-project workspace
|
|
74
|
+
|
|
75
|
+
# Development
|
|
76
|
+
grok test # Run tests
|
|
77
|
+
grok lint # Typecheck
|
|
78
|
+
grok deps # Dependency analysis
|
|
79
|
+
grok git # Git summary
|
|
80
|
+
grok security # Secret/env scanning
|
|
81
|
+
grok search "query" # Full-text code search
|
|
82
|
+
grok todo # Find TODOs in codebase
|
|
83
|
+
grok benchmark [N] # Provider latency benchmark
|
|
84
|
+
|
|
85
|
+
# Operations
|
|
86
|
+
grok health # Provider + system health
|
|
87
|
+
grok stats # Telemetry dashboard
|
|
88
|
+
grok doctor # Comprehensive diagnostic
|
|
89
|
+
grok eval # Execution metrics analysis
|
|
90
|
+
grok history # Execution timeline
|
|
91
|
+
grok export <target> # Export data (report/decisions/memory/config)
|
|
92
|
+
grok clean # Remove stale .grok/ data
|
|
93
|
+
grok env # Full environment info
|
|
94
|
+
grok migrate # Version migration check
|
|
95
|
+
grok plugin # Plugin management
|
|
96
|
+
grok trajectory # Competitor analysis
|
|
97
|
+
grok autoresearch start # Karpathy optimization loop
|
|
98
|
+
grok daemon start # Background file watcher
|
|
99
|
+
grok schedule list # Manage scheduled jobs
|
|
100
|
+
grok version # Version info
|
|
101
|
+
|
|
102
|
+
# Interactive
|
|
103
|
+
grok -i # REPL with session presets, slash commands, streaming
|
|
104
|
+
grok --resume-session-id <id> "goal" # Resume a persisted batch/stream session
|
|
105
|
+
grok --help # Show all commands and flags
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Architecture
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
User Goal
|
|
112
|
+
│
|
|
113
|
+
▼
|
|
114
|
+
┌──────────────────────────────────────┐
|
|
115
|
+
│ PREFLIGHT │
|
|
116
|
+
│ Clarify → Competitive Analysis → │
|
|
117
|
+
│ Enhanced Strategy │
|
|
118
|
+
└──────────────────────────────────────┘
|
|
119
|
+
│
|
|
120
|
+
▼
|
|
121
|
+
┌──────────────────────────────────────┐
|
|
122
|
+
│ OVERSIGHT (metacognition) │
|
|
123
|
+
│ Coherence → Blind Spots → Reframe │
|
|
124
|
+
│ Verdict: proceed / adjust / abort │
|
|
125
|
+
└──────────────────────────────────────┘
|
|
126
|
+
│
|
|
127
|
+
▼
|
|
128
|
+
┌──────────────────────────────────────┐
|
|
129
|
+
│ EXECUTION │
|
|
130
|
+
│ Route → Plan → Tool Loop → Evaluate│
|
|
131
|
+
└──────────────────────────────────────┘
|
|
132
|
+
│
|
|
133
|
+
▼
|
|
134
|
+
Memory + Decision Log + Telemetry
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Built-in Tools
|
|
138
|
+
|
|
139
|
+
| Tool | Tier | Description |
|
|
140
|
+
|---|---|---|
|
|
141
|
+
| `echo_text` | safe_read | Echo text back |
|
|
142
|
+
| `read_file` | safe_read | Read file contents (byte-limited) |
|
|
143
|
+
| `write_file` | safe_write | Write or append to file |
|
|
144
|
+
| `edit_file` | safe_write | Search-and-replace editing |
|
|
145
|
+
| `list_directory` | safe_read | List directory contents |
|
|
146
|
+
| `run_command` | shell | Shell command execution |
|
|
147
|
+
| `git_status` | safe_read | Git status |
|
|
148
|
+
| `git_diff` | safe_read | Git diff |
|
|
149
|
+
| `git_log` | safe_read | Git log |
|
|
150
|
+
| `git_commit` | safe_write | Stage and commit |
|
|
151
|
+
| `git_checkout` | safe_write | Branch switching |
|
|
152
|
+
| `repo_map` | safe_read | Project structure map |
|
|
153
|
+
| `grep_search` | safe_read | Regex content search |
|
|
154
|
+
| `glob_find` | safe_read | File pattern matching |
|
|
155
|
+
| `web_fetch` | network | HTTP client (SSRF-protected) |
|
|
156
|
+
| `http_request` | network | Full HTTP requests (SSRF-protected) |
|
|
157
|
+
| `web_search` | network | Web search |
|
|
158
|
+
| `env_inspector` | safe_read | Environment variables (secrets redacted) |
|
|
159
|
+
| `test_runner` | shell | Run test suites |
|
|
160
|
+
| `lint_check` | shell | Run linters |
|
|
161
|
+
|
|
162
|
+
See `grok health` for the full list of registered tools.
|
|
163
|
+
|
|
164
|
+
## `.grok/` Directory
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
.grok/
|
|
168
|
+
├── config/ # project.json, providers.json
|
|
169
|
+
├── sessions/ # Session state
|
|
170
|
+
├── conversations/ # Multi-turn history
|
|
171
|
+
├── memory/ # Scoped records (session/project/semantic)
|
|
172
|
+
├── policies/ # Policy bundles
|
|
173
|
+
├── decision-logs/ # Audit trail
|
|
174
|
+
├── oversight/ # Preflight + oversight results
|
|
175
|
+
└── tools/ # Project tool definitions (.json)
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Project-scoped durability is automatic when `projectRoot` is available:
|
|
179
|
+
|
|
180
|
+
- Memory uses the built-in SQLite-backed store when supported, with JSON fallback otherwise
|
|
181
|
+
- Decision logs persist to `.grok/decision-logs/`
|
|
182
|
+
- `grok history`, `grok eval`, and `grok export` read persisted artifacts directly and do not require API auth
|
|
183
|
+
- `--resume-session-id` restores both session metadata and persisted conversation context
|
|
184
|
+
- REPL `/save`, normal exit, and `Ctrl+C` suspension all persist session state and conversation history
|
|
185
|
+
|
|
186
|
+
## Environment Variables
|
|
187
|
+
|
|
188
|
+
| Variable | Description |
|
|
189
|
+
|---|---|
|
|
190
|
+
| `XAI_API_KEY` | xAI/Grok API key (primary) |
|
|
191
|
+
| `XAI_OAUTH_BEARER` | OAuth bearer (alternative) |
|
|
192
|
+
| `XAI_MODEL` | Override default model (e.g. `grok-3-mini`) |
|
|
193
|
+
| `ANTHROPIC_API_KEY` | Anthropic adapter (optional) |
|
|
194
|
+
| `OPENAI_API_KEY` | OpenAI adapter (optional) |
|
|
195
|
+
|
|
196
|
+
## Development
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
npm run build # Compile TypeScript
|
|
200
|
+
npm run typecheck # Type check only
|
|
201
|
+
npm run test # Build + run all tests
|
|
202
|
+
npm run clean # Remove dist/
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Experimental Features
|
|
206
|
+
|
|
207
|
+
These are functional but not yet production-hardened:
|
|
208
|
+
|
|
209
|
+
- `grok pilot-pro "goal"` — Full autonomous mega-loop (intel → strategy → build → validate)
|
|
210
|
+
- `grok mcp start` — Expose tools via MCP server
|
|
211
|
+
- Pilot Pro preset in REPL (`/preset pilot_pro`)
|
|
212
|
+
|
|
213
|
+
## Security
|
|
214
|
+
|
|
215
|
+
- All tool execution goes through an approval gate with configurable risk tiers
|
|
216
|
+
- Destructive operations always require explicit user approval
|
|
217
|
+
- Network tools block localhost, RFC 1918, link-local, and cloud metadata endpoints (SSRF protection)
|
|
218
|
+
- Environment inspector redacts secrets by default
|
|
219
|
+
- Dangerous execution modes require typing "yes" to confirm
|
|
220
|
+
|
|
221
|
+
## License
|
|
222
|
+
|
|
223
|
+
MIT
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { JsonObject } from "../model/contracts/common.js";
|
|
2
|
+
import type { MetaAgentResponse } from "../autopilot-pro/meta-agent.js";
|
|
3
|
+
export declare class HallucinationReducer {
|
|
4
|
+
private readonly accuracyThreshold;
|
|
5
|
+
/**
|
|
6
|
+
* Validates a MetaAgent response for hallucinations by scoring trace metrics and cross-referencing with competitive data.
|
|
7
|
+
* @param response The response from MetaAgent to validate.
|
|
8
|
+
* @param context Additional context for validation (e.g., query details).
|
|
9
|
+
* @returns True if the response is deemed factual and low-hallucination, false otherwise.
|
|
10
|
+
*/
|
|
11
|
+
validateResponse(response: MetaAgentResponse, context: JsonObject): Promise<boolean>;
|
|
12
|
+
/**
|
|
13
|
+
* Cross-references the response content with competitor data to ensure factual consistency.
|
|
14
|
+
* @param response The MetaAgent response.
|
|
15
|
+
* @param competitors Analyzed competitor data.
|
|
16
|
+
* @param recommendations Competitive recommendations.
|
|
17
|
+
* @returns True if the response is consistent with facts.
|
|
18
|
+
*/
|
|
19
|
+
private crossReferenceFactualAccuracy;
|
|
20
|
+
/**
|
|
21
|
+
* Checks if a specific claim is factual based on competitor data.
|
|
22
|
+
* @param claim The claim to verify.
|
|
23
|
+
* @param competitors Competitor analysis data.
|
|
24
|
+
* @param recommendations Recommendations list.
|
|
25
|
+
* @returns True if the claim is supported by data.
|
|
26
|
+
*/
|
|
27
|
+
private isClaimFactual;
|
|
28
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { getCompetitiveRecommendations, analyzeCompetitors, } from "../autoresearch/competitors.js";
|
|
2
|
+
import { scoreTraceMetrics } from "../trace/trace-metrics.js"; // Assuming scoreTraceMetrics is defined elsewhere
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Hallucination Reducer — reduces hallucinations by validating MetaAgent responses
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
export class HallucinationReducer {
|
|
7
|
+
accuracyThreshold = 0.8; // Configurable threshold for factual accuracy
|
|
8
|
+
/**
|
|
9
|
+
* Validates a MetaAgent response for hallucinations by scoring trace metrics and cross-referencing with competitive data.
|
|
10
|
+
* @param response The response from MetaAgent to validate.
|
|
11
|
+
* @param context Additional context for validation (e.g., query details).
|
|
12
|
+
* @returns True if the response is deemed factual and low-hallucination, false otherwise.
|
|
13
|
+
*/
|
|
14
|
+
async validateResponse(response, context) {
|
|
15
|
+
// Step 1: Score the trace metrics for reliability
|
|
16
|
+
const traceScore = await scoreTraceMetrics(response.trace);
|
|
17
|
+
if (traceScore < this.accuracyThreshold) {
|
|
18
|
+
return false; // Response is likely hallucinated based on trace
|
|
19
|
+
}
|
|
20
|
+
// Step 2: Cross-reference with competitor analysis for factual accuracy
|
|
21
|
+
const competitors = await analyzeCompetitors(context);
|
|
22
|
+
const recommendations = getCompetitiveRecommendations(context);
|
|
23
|
+
// Check if the response aligns with known competitive facts
|
|
24
|
+
return this.crossReferenceFactualAccuracy(response, competitors, recommendations);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Cross-references the response content with competitor data to ensure factual consistency.
|
|
28
|
+
* @param response The MetaAgent response.
|
|
29
|
+
* @param competitors Analyzed competitor data.
|
|
30
|
+
* @param recommendations Competitive recommendations.
|
|
31
|
+
* @returns True if the response is consistent with facts.
|
|
32
|
+
*/
|
|
33
|
+
crossReferenceFactualAccuracy(response, competitors, // Assuming competitors is an array of competitor objects
|
|
34
|
+
recommendations) {
|
|
35
|
+
// Extract key facts or claims from the response (simplified: assume response has a 'claims' array)
|
|
36
|
+
const claims = response.claims || [];
|
|
37
|
+
// Verify each claim against competitors and recommendations
|
|
38
|
+
for (const claim of claims) {
|
|
39
|
+
if (!this.isClaimFactual(claim, competitors, recommendations)) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Checks if a specific claim is factual based on competitor data.
|
|
47
|
+
* @param claim The claim to verify.
|
|
48
|
+
* @param competitors Competitor analysis data.
|
|
49
|
+
* @param recommendations Recommendations list.
|
|
50
|
+
* @returns True if the claim is supported by data.
|
|
51
|
+
*/
|
|
52
|
+
isClaimFactual(claim, competitors, recommendations) {
|
|
53
|
+
// Simplified logic: Check if claim matches any competitor feature or recommendation
|
|
54
|
+
// In a real implementation, this could use NLP or keyword matching
|
|
55
|
+
const lowerClaim = claim.toLowerCase();
|
|
56
|
+
return (competitors.some(comp => comp.features.some((feat) => feat.toLowerCase().includes(lowerClaim))) ||
|
|
57
|
+
recommendations.some(rec => rec.toLowerCase().includes(lowerClaim)));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { Identifier, ISO8601Timestamp, JsonObject, Result, StructuredError } from "../model/contracts/common.js";
|
|
2
|
+
import type { WorkerBudget, WorkerClass, WorkerContract, WorkerResult, WorkerRole } from "../model/contracts/worker.js";
|
|
3
|
+
import type { DelegationPolicy } from "../model/contracts/policy.js";
|
|
4
|
+
import type { SemanticContextPack } from "../model/contracts/memory.js";
|
|
5
|
+
export type DispatchErrorCode = "worker_class_not_enabled" | "parallel_limit_exceeded" | "budget_exceeded" | "invalid_worker_contract" | "worker_execution_failed" | "worker_timeout" | "human_approval_required" | "context_pack_missing";
|
|
6
|
+
export interface DispatchError extends StructuredError {
|
|
7
|
+
readonly subsystem: "subagent-runtime";
|
|
8
|
+
readonly code: DispatchErrorCode;
|
|
9
|
+
readonly workerClass?: WorkerClass;
|
|
10
|
+
readonly actorId?: Identifier;
|
|
11
|
+
}
|
|
12
|
+
export type DispatchEventKind = "dispatch_requested" | "dispatch_approved" | "dispatch_denied" | "worker_started" | "worker_completed" | "worker_failed" | "worker_timeout" | "parallel_limit_checked";
|
|
13
|
+
export interface DispatchEvent {
|
|
14
|
+
readonly kind: DispatchEventKind;
|
|
15
|
+
readonly timestamp: ISO8601Timestamp;
|
|
16
|
+
readonly actorId?: Identifier;
|
|
17
|
+
readonly workerClass?: WorkerClass;
|
|
18
|
+
readonly detail: JsonObject;
|
|
19
|
+
}
|
|
20
|
+
export interface DispatchEventSink {
|
|
21
|
+
emit(event: DispatchEvent): void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Each worker type (focused subagent, mirrored terminal) provides a runtime.
|
|
25
|
+
* The dispatcher calls this after policy validation passes.
|
|
26
|
+
* Worker runtimes are responsible for their own execution lifecycle,
|
|
27
|
+
* including model calls and tool usage within their budget.
|
|
28
|
+
*/
|
|
29
|
+
export interface WorkerRuntime {
|
|
30
|
+
execute(contract: WorkerContract): Promise<WorkerResult>;
|
|
31
|
+
}
|
|
32
|
+
export interface WorkerApprovalRequest {
|
|
33
|
+
readonly actorId: Identifier;
|
|
34
|
+
readonly workerClass: WorkerClass;
|
|
35
|
+
readonly role: WorkerRole;
|
|
36
|
+
readonly objective: string;
|
|
37
|
+
readonly budget: WorkerBudget;
|
|
38
|
+
}
|
|
39
|
+
export interface WorkerApprovalResponse {
|
|
40
|
+
readonly actorId: Identifier;
|
|
41
|
+
readonly approved: boolean;
|
|
42
|
+
readonly decidedBy: Identifier;
|
|
43
|
+
readonly decidedAt: ISO8601Timestamp;
|
|
44
|
+
readonly rationale?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface WorkerApprovalGate {
|
|
47
|
+
requestApproval(request: WorkerApprovalRequest): Promise<WorkerApprovalResponse>;
|
|
48
|
+
}
|
|
49
|
+
export interface SubagentDispatcher {
|
|
50
|
+
dispatch(contract: WorkerContract, policy: DelegationPolicy, contextPack?: SemanticContextPack): Promise<Result<WorkerResult, DispatchError>>;
|
|
51
|
+
activeWorkerCount(workerClass?: WorkerClass): number;
|
|
52
|
+
}
|
|
53
|
+
export declare class DefaultSubagentDispatcher implements SubagentDispatcher {
|
|
54
|
+
private readonly runtimes;
|
|
55
|
+
private readonly activeWorkers;
|
|
56
|
+
private readonly approvalGate;
|
|
57
|
+
private readonly sink;
|
|
58
|
+
constructor(approvalGate: WorkerApprovalGate, sink?: DispatchEventSink);
|
|
59
|
+
/**
|
|
60
|
+
* Register a runtime for a worker class.
|
|
61
|
+
* V1 typically registers only focused_subagent.
|
|
62
|
+
*/
|
|
63
|
+
registerRuntime(workerClass: WorkerClass, runtime: WorkerRuntime): void;
|
|
64
|
+
dispatch(contract: WorkerContract, policy: DelegationPolicy, contextPack?: SemanticContextPack): Promise<Result<WorkerResult, DispatchError>>;
|
|
65
|
+
activeWorkerCount(workerClass?: WorkerClass): number;
|
|
66
|
+
private checkParallelLimits;
|
|
67
|
+
private requestHumanApproval;
|
|
68
|
+
private executeWithTimeout;
|
|
69
|
+
private buildError;
|
|
70
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { Ok, Err } from "../model/contracts/common.js";
|
|
2
|
+
const NOOP_DISPATCH_SINK = { emit: () => { } };
|
|
3
|
+
export class DefaultSubagentDispatcher {
|
|
4
|
+
runtimes = new Map();
|
|
5
|
+
activeWorkers = new Map();
|
|
6
|
+
approvalGate;
|
|
7
|
+
sink;
|
|
8
|
+
constructor(approvalGate, sink) {
|
|
9
|
+
this.approvalGate = approvalGate;
|
|
10
|
+
this.sink = sink ?? NOOP_DISPATCH_SINK;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Register a runtime for a worker class.
|
|
14
|
+
* V1 typically registers only focused_subagent.
|
|
15
|
+
*/
|
|
16
|
+
registerRuntime(workerClass, runtime) {
|
|
17
|
+
this.runtimes.set(workerClass, runtime);
|
|
18
|
+
}
|
|
19
|
+
async dispatch(contract, policy, contextPack) {
|
|
20
|
+
const now = new Date().toISOString();
|
|
21
|
+
this.sink.emit({
|
|
22
|
+
kind: "dispatch_requested",
|
|
23
|
+
timestamp: now,
|
|
24
|
+
actorId: contract.actorId,
|
|
25
|
+
workerClass: contract.workerClass,
|
|
26
|
+
detail: {
|
|
27
|
+
role: contract.role,
|
|
28
|
+
objective: contract.objective,
|
|
29
|
+
hasContextPack: !!contextPack,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
// 1. Validate worker contract.
|
|
33
|
+
if (!contract.actorId || !contract.objective) {
|
|
34
|
+
return Err(this.buildError("invalid_worker_contract", "Worker contract missing required fields (actorId or objective)", now, contract.workerClass, contract.actorId));
|
|
35
|
+
}
|
|
36
|
+
// 2. Worker class enabled check (Law 10).
|
|
37
|
+
if (!policy.enabledWorkerClasses.includes(contract.workerClass)) {
|
|
38
|
+
this.sink.emit({
|
|
39
|
+
kind: "dispatch_denied",
|
|
40
|
+
timestamp: now,
|
|
41
|
+
actorId: contract.actorId,
|
|
42
|
+
workerClass: contract.workerClass,
|
|
43
|
+
detail: {
|
|
44
|
+
reason: "worker_class_not_enabled",
|
|
45
|
+
enabledClasses: policy.enabledWorkerClasses,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
return Err(this.buildError("worker_class_not_enabled", `Worker class '${contract.workerClass}' is not enabled in delegation policy`, now, contract.workerClass, contract.actorId));
|
|
49
|
+
}
|
|
50
|
+
// 3. Parallel limit check.
|
|
51
|
+
const parallelCheck = this.checkParallelLimits(contract.workerClass, policy, now);
|
|
52
|
+
if (!parallelCheck.ok)
|
|
53
|
+
return parallelCheck;
|
|
54
|
+
// 4. Context pack required for focused subagents (Law 10: only necessary context).
|
|
55
|
+
if (contract.workerClass === "focused_subagent" && !contextPack) {
|
|
56
|
+
return Err(this.buildError("context_pack_missing", "Focused subagents require a semantic context pack (Law 10: Delegation Discipline)", now, contract.workerClass, contract.actorId));
|
|
57
|
+
}
|
|
58
|
+
// 5. Human approval for mirrored workers (Law 20).
|
|
59
|
+
if (contract.workerClass === "mirrored_terminal_worker" &&
|
|
60
|
+
policy.requireHumanApprovalForMirroredWorkers) {
|
|
61
|
+
const approvalResult = await this.requestHumanApproval(contract, now);
|
|
62
|
+
if (!approvalResult.ok)
|
|
63
|
+
return approvalResult;
|
|
64
|
+
}
|
|
65
|
+
// 6. Resolve runtime.
|
|
66
|
+
const runtime = this.runtimes.get(contract.workerClass);
|
|
67
|
+
if (!runtime) {
|
|
68
|
+
return Err(this.buildError("invalid_worker_contract", `No runtime registered for worker class '${contract.workerClass}'`, now, contract.workerClass, contract.actorId));
|
|
69
|
+
}
|
|
70
|
+
// 7. Inject context pack into worker memory profile if provided.
|
|
71
|
+
const enrichedContract = contextPack
|
|
72
|
+
? {
|
|
73
|
+
...contract,
|
|
74
|
+
memoryProfile: {
|
|
75
|
+
...contract.memoryProfile,
|
|
76
|
+
contextPack,
|
|
77
|
+
},
|
|
78
|
+
}
|
|
79
|
+
: contract;
|
|
80
|
+
// 8. Execute.
|
|
81
|
+
this.activeWorkers.set(contract.actorId, contract.workerClass);
|
|
82
|
+
this.sink.emit({
|
|
83
|
+
kind: "worker_started",
|
|
84
|
+
timestamp: new Date().toISOString(),
|
|
85
|
+
actorId: contract.actorId,
|
|
86
|
+
workerClass: contract.workerClass,
|
|
87
|
+
detail: {
|
|
88
|
+
role: contract.role,
|
|
89
|
+
budgetMaxTokens: contract.budget.maxTokens ?? null,
|
|
90
|
+
budgetMaxToolCalls: contract.budget.maxToolCalls ?? null,
|
|
91
|
+
budgetMaxRuntimeMs: contract.budget.maxRuntimeMs ?? null,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
try {
|
|
95
|
+
const result = await this.executeWithTimeout(runtime, enrichedContract);
|
|
96
|
+
this.activeWorkers.delete(contract.actorId);
|
|
97
|
+
const eventKind = result.ok ? "worker_completed" : "worker_failed";
|
|
98
|
+
this.sink.emit({
|
|
99
|
+
kind: eventKind,
|
|
100
|
+
timestamp: new Date().toISOString(),
|
|
101
|
+
actorId: contract.actorId,
|
|
102
|
+
workerClass: contract.workerClass,
|
|
103
|
+
detail: {
|
|
104
|
+
ok: result.ok,
|
|
105
|
+
summary: result.summary,
|
|
106
|
+
producedArtifacts: (result.producedArtifacts?.length ?? 0),
|
|
107
|
+
escalatedMemoryWrites: (result.escalatedMemoryWrites?.length ?? 0),
|
|
108
|
+
openQuestions: (result.openQuestions?.length ?? 0),
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
return Ok(result);
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
this.activeWorkers.delete(contract.actorId);
|
|
115
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
116
|
+
this.sink.emit({
|
|
117
|
+
kind: "worker_failed",
|
|
118
|
+
timestamp: new Date().toISOString(),
|
|
119
|
+
actorId: contract.actorId,
|
|
120
|
+
workerClass: contract.workerClass,
|
|
121
|
+
detail: { error: message },
|
|
122
|
+
});
|
|
123
|
+
return Err(this.buildError("worker_execution_failed", `Worker '${contract.actorId}' failed: ${message}`, new Date().toISOString(), contract.workerClass, contract.actorId));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
activeWorkerCount(workerClass) {
|
|
127
|
+
if (workerClass === undefined)
|
|
128
|
+
return this.activeWorkers.size;
|
|
129
|
+
let count = 0;
|
|
130
|
+
for (const wc of this.activeWorkers.values()) {
|
|
131
|
+
if (wc === workerClass)
|
|
132
|
+
count++;
|
|
133
|
+
}
|
|
134
|
+
return count;
|
|
135
|
+
}
|
|
136
|
+
// ---- private ----
|
|
137
|
+
checkParallelLimits(workerClass, policy, now) {
|
|
138
|
+
this.sink.emit({
|
|
139
|
+
kind: "parallel_limit_checked",
|
|
140
|
+
timestamp: now,
|
|
141
|
+
workerClass,
|
|
142
|
+
detail: {
|
|
143
|
+
currentActive: this.activeWorkerCount(workerClass),
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
if (workerClass === "focused_subagent") {
|
|
147
|
+
const limit = policy.maxParallelFocusedSubagents;
|
|
148
|
+
if (limit !== undefined && this.activeWorkerCount("focused_subagent") >= limit) {
|
|
149
|
+
return Err(this.buildError("parallel_limit_exceeded", `Focused subagent parallel limit (${limit}) reached`, now, workerClass));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (workerClass === "mirrored_terminal_worker") {
|
|
153
|
+
const limit = policy.maxParallelMirroredWorkers;
|
|
154
|
+
if (limit !== undefined && this.activeWorkerCount("mirrored_terminal_worker") >= limit) {
|
|
155
|
+
return Err(this.buildError("parallel_limit_exceeded", `Mirrored worker parallel limit (${limit}) reached`, now, workerClass));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return Ok(undefined);
|
|
159
|
+
}
|
|
160
|
+
async requestHumanApproval(contract, now) {
|
|
161
|
+
const response = await this.approvalGate.requestApproval({
|
|
162
|
+
actorId: contract.actorId,
|
|
163
|
+
workerClass: contract.workerClass,
|
|
164
|
+
role: contract.role,
|
|
165
|
+
objective: contract.objective,
|
|
166
|
+
budget: contract.budget,
|
|
167
|
+
});
|
|
168
|
+
if (!response.approved) {
|
|
169
|
+
this.sink.emit({
|
|
170
|
+
kind: "dispatch_denied",
|
|
171
|
+
timestamp: response.decidedAt,
|
|
172
|
+
actorId: contract.actorId,
|
|
173
|
+
workerClass: contract.workerClass,
|
|
174
|
+
detail: {
|
|
175
|
+
reason: "human_approval_denied",
|
|
176
|
+
decidedBy: response.decidedBy,
|
|
177
|
+
rationale: response.rationale ?? null,
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
return Err(this.buildError("human_approval_required", `Mirrored worker dispatch denied by ${response.decidedBy}`, response.decidedAt, contract.workerClass, contract.actorId));
|
|
181
|
+
}
|
|
182
|
+
this.sink.emit({
|
|
183
|
+
kind: "dispatch_approved",
|
|
184
|
+
timestamp: response.decidedAt,
|
|
185
|
+
actorId: contract.actorId,
|
|
186
|
+
workerClass: contract.workerClass,
|
|
187
|
+
detail: { decidedBy: response.decidedBy },
|
|
188
|
+
});
|
|
189
|
+
return Ok(undefined);
|
|
190
|
+
}
|
|
191
|
+
async executeWithTimeout(runtime, contract) {
|
|
192
|
+
const timeoutMs = contract.budget.maxRuntimeMs ?? 120_000;
|
|
193
|
+
return new Promise((resolve, reject) => {
|
|
194
|
+
const timer = setTimeout(() => {
|
|
195
|
+
reject(new Error(`Worker execution timed out after ${timeoutMs}ms`));
|
|
196
|
+
}, timeoutMs);
|
|
197
|
+
runtime
|
|
198
|
+
.execute(contract)
|
|
199
|
+
.then((result) => {
|
|
200
|
+
clearTimeout(timer);
|
|
201
|
+
resolve(result);
|
|
202
|
+
})
|
|
203
|
+
.catch((err) => {
|
|
204
|
+
clearTimeout(timer);
|
|
205
|
+
reject(err);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
buildError(code, message, timestamp, workerClass, actorId) {
|
|
210
|
+
return { code, message, subsystem: "subagent-runtime", timestamp, workerClass, actorId };
|
|
211
|
+
}
|
|
212
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { WorkerContract, WorkerResult } from "../model/contracts/worker.js";
|
|
2
|
+
import type { WorkerRuntime } from "./dispatcher.js";
|
|
3
|
+
/**
|
|
4
|
+
* Delegate that provides actual LLM execution capability.
|
|
5
|
+
* When set, the subagent calls the LLM with its objective and context pack.
|
|
6
|
+
* When absent, the subagent returns a "prepared" result (plan-only mode).
|
|
7
|
+
*/
|
|
8
|
+
export interface FocusedSubagentDelegate {
|
|
9
|
+
executeGoal(objective: string, contextSummary: string, actorId: string): Promise<{
|
|
10
|
+
ok: boolean;
|
|
11
|
+
content: string;
|
|
12
|
+
latencyMs: number;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
export declare class FocusedSubagentRuntime implements WorkerRuntime {
|
|
16
|
+
private readonly delegate?;
|
|
17
|
+
constructor(delegate?: FocusedSubagentDelegate);
|
|
18
|
+
execute(contract: WorkerContract): Promise<WorkerResult>;
|
|
19
|
+
}
|