hungry-ghost-hive 0.3.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 +111 -0
- package/README.md +352 -0
- package/dist/agents/base-agent.d.ts +63 -0
- package/dist/agents/base-agent.d.ts.map +1 -0
- package/dist/agents/base-agent.js +189 -0
- package/dist/agents/base-agent.js.map +1 -0
- package/dist/agents/index.d.ts +7 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +7 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/intermediate.d.ts +15 -0
- package/dist/agents/intermediate.d.ts.map +1 -0
- package/dist/agents/intermediate.js +142 -0
- package/dist/agents/intermediate.js.map +1 -0
- package/dist/agents/junior.d.ts +15 -0
- package/dist/agents/junior.d.ts.map +1 -0
- package/dist/agents/junior.js +147 -0
- package/dist/agents/junior.js.map +1 -0
- package/dist/agents/qa.d.ts +23 -0
- package/dist/agents/qa.d.ts.map +1 -0
- package/dist/agents/qa.js +238 -0
- package/dist/agents/qa.js.map +1 -0
- package/dist/agents/senior.d.ts +18 -0
- package/dist/agents/senior.d.ts.map +1 -0
- package/dist/agents/senior.js +267 -0
- package/dist/agents/senior.js.map +1 -0
- package/dist/agents/tech-lead.d.ts +17 -0
- package/dist/agents/tech-lead.d.ts.map +1 -0
- package/dist/agents/tech-lead.js +274 -0
- package/dist/agents/tech-lead.js.map +1 -0
- package/dist/cli/commands/add-repo.d.ts +3 -0
- package/dist/cli/commands/add-repo.d.ts.map +1 -0
- package/dist/cli/commands/add-repo.js +84 -0
- package/dist/cli/commands/add-repo.js.map +1 -0
- package/dist/cli/commands/agents.d.ts +3 -0
- package/dist/cli/commands/agents.d.ts.map +1 -0
- package/dist/cli/commands/agents.js +214 -0
- package/dist/cli/commands/agents.js.map +1 -0
- package/dist/cli/commands/assign.d.ts +3 -0
- package/dist/cli/commands/assign.d.ts.map +1 -0
- package/dist/cli/commands/assign.js +81 -0
- package/dist/cli/commands/assign.js.map +1 -0
- package/dist/cli/commands/config.d.ts +3 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/config.js +118 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/escalations.d.ts +3 -0
- package/dist/cli/commands/escalations.d.ts.map +1 -0
- package/dist/cli/commands/escalations.js +157 -0
- package/dist/cli/commands/escalations.js.map +1 -0
- package/dist/cli/commands/index.d.ts +17 -0
- package/dist/cli/commands/index.d.ts.map +1 -0
- package/dist/cli/commands/index.js +17 -0
- package/dist/cli/commands/index.js.map +1 -0
- package/dist/cli/commands/init.d.ts +3 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +59 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/manager.d.ts +3 -0
- package/dist/cli/commands/manager.d.ts.map +1 -0
- package/dist/cli/commands/manager.js +775 -0
- package/dist/cli/commands/manager.js.map +1 -0
- package/dist/cli/commands/manager.test.d.ts +2 -0
- package/dist/cli/commands/manager.test.d.ts.map +1 -0
- package/dist/cli/commands/manager.test.js +45 -0
- package/dist/cli/commands/manager.test.js.map +1 -0
- package/dist/cli/commands/msg.d.ts +3 -0
- package/dist/cli/commands/msg.d.ts.map +1 -0
- package/dist/cli/commands/msg.js +190 -0
- package/dist/cli/commands/msg.js.map +1 -0
- package/dist/cli/commands/my-stories.d.ts +3 -0
- package/dist/cli/commands/my-stories.d.ts.map +1 -0
- package/dist/cli/commands/my-stories.js +174 -0
- package/dist/cli/commands/my-stories.js.map +1 -0
- package/dist/cli/commands/nuke.d.ts +3 -0
- package/dist/cli/commands/nuke.d.ts.map +1 -0
- package/dist/cli/commands/nuke.js +189 -0
- package/dist/cli/commands/nuke.js.map +1 -0
- package/dist/cli/commands/pr.d.ts +3 -0
- package/dist/cli/commands/pr.d.ts.map +1 -0
- package/dist/cli/commands/pr.js +488 -0
- package/dist/cli/commands/pr.js.map +1 -0
- package/dist/cli/commands/req.d.ts +3 -0
- package/dist/cli/commands/req.d.ts.map +1 -0
- package/dist/cli/commands/req.js +212 -0
- package/dist/cli/commands/req.js.map +1 -0
- package/dist/cli/commands/resume.d.ts +3 -0
- package/dist/cli/commands/resume.d.ts.map +1 -0
- package/dist/cli/commands/resume.js +114 -0
- package/dist/cli/commands/resume.js.map +1 -0
- package/dist/cli/commands/status.d.ts +3 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/status.js +259 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/stories.d.ts +3 -0
- package/dist/cli/commands/stories.d.ts.map +1 -0
- package/dist/cli/commands/stories.js +111 -0
- package/dist/cli/commands/stories.js.map +1 -0
- package/dist/cli/commands/teams.d.ts +3 -0
- package/dist/cli/commands/teams.d.ts.map +1 -0
- package/dist/cli/commands/teams.js +137 -0
- package/dist/cli/commands/teams.js.map +1 -0
- package/dist/cli/dashboard/index.d.ts +5 -0
- package/dist/cli/dashboard/index.d.ts.map +1 -0
- package/dist/cli/dashboard/index.js +128 -0
- package/dist/cli/dashboard/index.js.map +1 -0
- package/dist/cli/dashboard/panels/activity.d.ts +5 -0
- package/dist/cli/dashboard/panels/activity.d.ts.map +1 -0
- package/dist/cli/dashboard/panels/activity.js +64 -0
- package/dist/cli/dashboard/panels/activity.js.map +1 -0
- package/dist/cli/dashboard/panels/agents.d.ts +5 -0
- package/dist/cli/dashboard/panels/agents.d.ts.map +1 -0
- package/dist/cli/dashboard/panels/agents.js +196 -0
- package/dist/cli/dashboard/panels/agents.js.map +1 -0
- package/dist/cli/dashboard/panels/escalations.d.ts +5 -0
- package/dist/cli/dashboard/panels/escalations.d.ts.map +1 -0
- package/dist/cli/dashboard/panels/escalations.js +93 -0
- package/dist/cli/dashboard/panels/escalations.js.map +1 -0
- package/dist/cli/dashboard/panels/merge-queue.d.ts +5 -0
- package/dist/cli/dashboard/panels/merge-queue.d.ts.map +1 -0
- package/dist/cli/dashboard/panels/merge-queue.js +57 -0
- package/dist/cli/dashboard/panels/merge-queue.js.map +1 -0
- package/dist/cli/dashboard/panels/pipeline.d.ts +5 -0
- package/dist/cli/dashboard/panels/pipeline.d.ts.map +1 -0
- package/dist/cli/dashboard/panels/pipeline.js +54 -0
- package/dist/cli/dashboard/panels/pipeline.js.map +1 -0
- package/dist/cli/dashboard/panels/stories.d.ts +5 -0
- package/dist/cli/dashboard/panels/stories.d.ts.map +1 -0
- package/dist/cli/dashboard/panels/stories.js +79 -0
- package/dist/cli/dashboard/panels/stories.js.map +1 -0
- package/dist/cli-runtimes/claude.d.ts +8 -0
- package/dist/cli-runtimes/claude.d.ts.map +1 -0
- package/dist/cli-runtimes/claude.js +27 -0
- package/dist/cli-runtimes/claude.js.map +1 -0
- package/dist/cli-runtimes/codex.d.ts +8 -0
- package/dist/cli-runtimes/codex.d.ts.map +1 -0
- package/dist/cli-runtimes/codex.js +27 -0
- package/dist/cli-runtimes/codex.js.map +1 -0
- package/dist/cli-runtimes/gemini.d.ts +8 -0
- package/dist/cli-runtimes/gemini.d.ts.map +1 -0
- package/dist/cli-runtimes/gemini.js +29 -0
- package/dist/cli-runtimes/gemini.js.map +1 -0
- package/dist/cli-runtimes/index.d.ts +25 -0
- package/dist/cli-runtimes/index.d.ts.map +1 -0
- package/dist/cli-runtimes/index.js +48 -0
- package/dist/cli-runtimes/index.js.map +1 -0
- package/dist/cli-runtimes/index.test.d.ts +2 -0
- package/dist/cli-runtimes/index.test.d.ts.map +1 -0
- package/dist/cli-runtimes/index.test.js +216 -0
- package/dist/cli-runtimes/index.test.js.map +1 -0
- package/dist/cli-runtimes/types.d.ts +27 -0
- package/dist/cli-runtimes/types.d.ts.map +1 -0
- package/dist/cli-runtimes/types.js +2 -0
- package/dist/cli-runtimes/types.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +3 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/loader.d.ts +11 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +72 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/schema.d.ts +660 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +217 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/config/schema.test.d.ts +2 -0
- package/dist/config/schema.test.d.ts.map +1 -0
- package/dist/config/schema.test.js +123 -0
- package/dist/config/schema.test.js.map +1 -0
- package/dist/context-files/generator.d.ts +32 -0
- package/dist/context-files/generator.d.ts.map +1 -0
- package/dist/context-files/generator.js +120 -0
- package/dist/context-files/generator.js.map +1 -0
- package/dist/context-files/index.d.ts +38 -0
- package/dist/context-files/index.d.ts.map +1 -0
- package/dist/context-files/index.js +76 -0
- package/dist/context-files/index.js.map +1 -0
- package/dist/context-files/index.test.d.ts +2 -0
- package/dist/context-files/index.test.d.ts.map +1 -0
- package/dist/context-files/index.test.js +265 -0
- package/dist/context-files/index.test.js.map +1 -0
- package/dist/context-files/templates.d.ts +19 -0
- package/dist/context-files/templates.d.ts.map +1 -0
- package/dist/context-files/templates.js +266 -0
- package/dist/context-files/templates.js.map +1 -0
- package/dist/db/client.d.ts +95 -0
- package/dist/db/client.d.ts.map +1 -0
- package/dist/db/client.js +343 -0
- package/dist/db/client.js.map +1 -0
- package/dist/db/lock.d.ts +25 -0
- package/dist/db/lock.d.ts.map +1 -0
- package/dist/db/lock.js +56 -0
- package/dist/db/lock.js.map +1 -0
- package/dist/db/lock.test.d.ts +2 -0
- package/dist/db/lock.test.d.ts.map +1 -0
- package/dist/db/lock.test.js +73 -0
- package/dist/db/lock.test.js.map +1 -0
- package/dist/db/queries/agents.d.ts +31 -0
- package/dist/db/queries/agents.d.ts.map +1 -0
- package/dist/db/queries/agents.js +76 -0
- package/dist/db/queries/agents.js.map +1 -0
- package/dist/db/queries/escalations.d.ts +29 -0
- package/dist/db/queries/escalations.d.ts.map +1 -0
- package/dist/db/queries/escalations.js +105 -0
- package/dist/db/queries/escalations.js.map +1 -0
- package/dist/db/queries/heartbeat.d.ts +20 -0
- package/dist/db/queries/heartbeat.d.ts.map +1 -0
- package/dist/db/queries/heartbeat.js +61 -0
- package/dist/db/queries/heartbeat.js.map +1 -0
- package/dist/db/queries/index.d.ts +8 -0
- package/dist/db/queries/index.d.ts.map +1 -0
- package/dist/db/queries/index.js +8 -0
- package/dist/db/queries/index.js.map +1 -0
- package/dist/db/queries/logs.d.ts +21 -0
- package/dist/db/queries/logs.d.ts.map +1 -0
- package/dist/db/queries/logs.js +72 -0
- package/dist/db/queries/logs.js.map +1 -0
- package/dist/db/queries/messages.d.ts +17 -0
- package/dist/db/queries/messages.d.ts.map +1 -0
- package/dist/db/queries/messages.js +22 -0
- package/dist/db/queries/messages.js.map +1 -0
- package/dist/db/queries/pull-requests.d.ts +33 -0
- package/dist/db/queries/pull-requests.d.ts.map +1 -0
- package/dist/db/queries/pull-requests.js +130 -0
- package/dist/db/queries/pull-requests.js.map +1 -0
- package/dist/db/queries/requirements.d.ts +22 -0
- package/dist/db/queries/requirements.d.ts.map +1 -0
- package/dist/db/queries/requirements.js +53 -0
- package/dist/db/queries/requirements.js.map +1 -0
- package/dist/db/queries/stories.d.ts +42 -0
- package/dist/db/queries/stories.d.ts.map +1 -0
- package/dist/db/queries/stories.js +163 -0
- package/dist/db/queries/stories.js.map +1 -0
- package/dist/db/queries/teams.d.ts +14 -0
- package/dist/db/queries/teams.d.ts.map +1 -0
- package/dist/db/queries/teams.js +24 -0
- package/dist/db/queries/teams.js.map +1 -0
- package/dist/git/branches.d.ts +52 -0
- package/dist/git/branches.d.ts.map +1 -0
- package/dist/git/branches.js +133 -0
- package/dist/git/branches.js.map +1 -0
- package/dist/git/github.d.ts +75 -0
- package/dist/git/github.d.ts.map +1 -0
- package/dist/git/github.js +162 -0
- package/dist/git/github.js.map +1 -0
- package/dist/git/index.d.ts +4 -0
- package/dist/git/index.d.ts.map +1 -0
- package/dist/git/index.js +4 -0
- package/dist/git/index.js.map +1 -0
- package/dist/git/submodules.d.ts +47 -0
- package/dist/git/submodules.d.ts.map +1 -0
- package/dist/git/submodules.js +115 -0
- package/dist/git/submodules.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +62 -0
- package/dist/index.js.map +1 -0
- package/dist/llm/anthropic.d.ts +18 -0
- package/dist/llm/anthropic.d.ts.map +1 -0
- package/dist/llm/anthropic.js +111 -0
- package/dist/llm/anthropic.js.map +1 -0
- package/dist/llm/index.d.ts +6 -0
- package/dist/llm/index.d.ts.map +1 -0
- package/dist/llm/index.js +24 -0
- package/dist/llm/index.js.map +1 -0
- package/dist/llm/openai.d.ts +18 -0
- package/dist/llm/openai.d.ts.map +1 -0
- package/dist/llm/openai.js +103 -0
- package/dist/llm/openai.js.map +1 -0
- package/dist/llm/provider.d.ts +38 -0
- package/dist/llm/provider.d.ts.map +1 -0
- package/dist/llm/provider.js +17 -0
- package/dist/llm/provider.js.map +1 -0
- package/dist/orchestrator/index.d.ts +4 -0
- package/dist/orchestrator/index.d.ts.map +1 -0
- package/dist/orchestrator/index.js +4 -0
- package/dist/orchestrator/index.js.map +1 -0
- package/dist/orchestrator/scaler.d.ts +42 -0
- package/dist/orchestrator/scaler.d.ts.map +1 -0
- package/dist/orchestrator/scaler.js +154 -0
- package/dist/orchestrator/scaler.js.map +1 -0
- package/dist/orchestrator/scheduler.d.ts +90 -0
- package/dist/orchestrator/scheduler.d.ts.map +1 -0
- package/dist/orchestrator/scheduler.js +1003 -0
- package/dist/orchestrator/scheduler.js.map +1 -0
- package/dist/orchestrator/scheduler.test.d.ts +2 -0
- package/dist/orchestrator/scheduler.test.d.ts.map +1 -0
- package/dist/orchestrator/scheduler.test.js +242 -0
- package/dist/orchestrator/scheduler.test.js.map +1 -0
- package/dist/orchestrator/workflow.d.ts +18 -0
- package/dist/orchestrator/workflow.d.ts.map +1 -0
- package/dist/orchestrator/workflow.js +106 -0
- package/dist/orchestrator/workflow.js.map +1 -0
- package/dist/state-detectors/claude.d.ts +33 -0
- package/dist/state-detectors/claude.d.ts.map +1 -0
- package/dist/state-detectors/claude.js +237 -0
- package/dist/state-detectors/claude.js.map +1 -0
- package/dist/state-detectors/claude.test.d.ts +2 -0
- package/dist/state-detectors/claude.test.d.ts.map +1 -0
- package/dist/state-detectors/claude.test.js +127 -0
- package/dist/state-detectors/claude.test.js.map +1 -0
- package/dist/state-detectors/codex.d.ts +34 -0
- package/dist/state-detectors/codex.d.ts.map +1 -0
- package/dist/state-detectors/codex.js +233 -0
- package/dist/state-detectors/codex.js.map +1 -0
- package/dist/state-detectors/codex.test.d.ts +2 -0
- package/dist/state-detectors/codex.test.d.ts.map +1 -0
- package/dist/state-detectors/codex.test.js +85 -0
- package/dist/state-detectors/codex.test.js.map +1 -0
- package/dist/state-detectors/factory.d.ts +22 -0
- package/dist/state-detectors/factory.d.ts.map +1 -0
- package/dist/state-detectors/factory.js +37 -0
- package/dist/state-detectors/factory.js.map +1 -0
- package/dist/state-detectors/factory.test.d.ts +2 -0
- package/dist/state-detectors/factory.test.d.ts.map +1 -0
- package/dist/state-detectors/factory.test.js +44 -0
- package/dist/state-detectors/factory.test.js.map +1 -0
- package/dist/state-detectors/gemini.d.ts +34 -0
- package/dist/state-detectors/gemini.d.ts.map +1 -0
- package/dist/state-detectors/gemini.js +236 -0
- package/dist/state-detectors/gemini.js.map +1 -0
- package/dist/state-detectors/gemini.test.d.ts +2 -0
- package/dist/state-detectors/gemini.test.d.ts.map +1 -0
- package/dist/state-detectors/gemini.test.js +93 -0
- package/dist/state-detectors/gemini.test.js.map +1 -0
- package/dist/state-detectors/index.d.ts +20 -0
- package/dist/state-detectors/index.d.ts.map +1 -0
- package/dist/state-detectors/index.js +21 -0
- package/dist/state-detectors/index.js.map +1 -0
- package/dist/state-detectors/types.d.ts +67 -0
- package/dist/state-detectors/types.d.ts.map +1 -0
- package/dist/state-detectors/types.js +28 -0
- package/dist/state-detectors/types.js.map +1 -0
- package/dist/tmux/index.d.ts +2 -0
- package/dist/tmux/index.d.ts.map +1 -0
- package/dist/tmux/index.js +2 -0
- package/dist/tmux/index.js.map +1 -0
- package/dist/tmux/manager.d.ts +45 -0
- package/dist/tmux/manager.d.ts.map +1 -0
- package/dist/tmux/manager.js +252 -0
- package/dist/tmux/manager.js.map +1 -0
- package/dist/utils/claude-code-state.d.ts +46 -0
- package/dist/utils/claude-code-state.d.ts.map +1 -0
- package/dist/utils/claude-code-state.js +252 -0
- package/dist/utils/claude-code-state.js.map +1 -0
- package/dist/utils/cli-builder.d.ts +19 -0
- package/dist/utils/cli-builder.d.ts.map +1 -0
- package/dist/utils/cli-builder.js +58 -0
- package/dist/utils/cli-builder.js.map +1 -0
- package/dist/utils/cli-commands.d.ts +27 -0
- package/dist/utils/cli-commands.d.ts.map +1 -0
- package/dist/utils/cli-commands.js +69 -0
- package/dist/utils/cli-commands.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +13 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +77 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/paths.d.ts +17 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +33 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/utils/timeout.d.ts +25 -0
- package/dist/utils/timeout.d.ts.map +1 -0
- package/dist/utils/timeout.js +57 -0
- package/dist/utils/timeout.js.map +1 -0
- package/package.json +78 -0
- package/src/agents/base-agent.ts +255 -0
- package/src/agents/index.ts +6 -0
- package/src/agents/intermediate.ts +161 -0
- package/src/agents/junior.ts +166 -0
- package/src/agents/qa.ts +272 -0
- package/src/agents/senior.ts +307 -0
- package/src/agents/tech-lead.ts +324 -0
- package/src/cli/commands/add-repo.ts +89 -0
- package/src/cli/commands/agents.ts +247 -0
- package/src/cli/commands/assign.ts +86 -0
- package/src/cli/commands/config.ts +121 -0
- package/src/cli/commands/escalations.ts +179 -0
- package/src/cli/commands/index.ts +16 -0
- package/src/cli/commands/init.ts +66 -0
- package/src/cli/commands/manager.test.ts +52 -0
- package/src/cli/commands/manager.ts +916 -0
- package/src/cli/commands/msg.ts +232 -0
- package/src/cli/commands/my-stories.ts +198 -0
- package/src/cli/commands/nuke.ts +223 -0
- package/src/cli/commands/pr.ts +559 -0
- package/src/cli/commands/req.ts +231 -0
- package/src/cli/commands/resume.ts +129 -0
- package/src/cli/commands/status.ts +284 -0
- package/src/cli/commands/stories.ts +131 -0
- package/src/cli/commands/teams.ts +158 -0
- package/src/cli/dashboard/index.ts +141 -0
- package/src/cli/dashboard/panels/activity.ts +77 -0
- package/src/cli/dashboard/panels/agents.ts +244 -0
- package/src/cli/dashboard/panels/escalations.ts +109 -0
- package/src/cli/dashboard/panels/merge-queue.ts +65 -0
- package/src/cli/dashboard/panels/pipeline.ts +65 -0
- package/src/cli/dashboard/panels/stories.ts +87 -0
- package/src/cli-runtimes/claude.ts +31 -0
- package/src/cli-runtimes/codex.ts +31 -0
- package/src/cli-runtimes/gemini.ts +33 -0
- package/src/cli-runtimes/index.test.ts +261 -0
- package/src/cli-runtimes/index.ts +52 -0
- package/src/cli-runtimes/types.ts +30 -0
- package/src/config/index.ts +2 -0
- package/src/config/loader.ts +89 -0
- package/src/config/schema.test.ts +135 -0
- package/src/config/schema.ts +238 -0
- package/src/context-files/generator.ts +132 -0
- package/src/context-files/index.test.ts +323 -0
- package/src/context-files/index.ts +102 -0
- package/src/context-files/templates.ts +279 -0
- package/src/db/client.ts +475 -0
- package/src/db/lock.test.ts +93 -0
- package/src/db/lock.ts +74 -0
- package/src/db/migrations/001-initial.sql +121 -0
- package/src/db/migrations/005-add-agent-heartbeat.sql +4 -0
- package/src/db/queries/agents.ts +113 -0
- package/src/db/queries/escalations.ts +140 -0
- package/src/db/queries/heartbeat.ts +92 -0
- package/src/db/queries/index.ts +7 -0
- package/src/db/queries/logs.ts +136 -0
- package/src/db/queries/messages.ts +38 -0
- package/src/db/queries/pull-requests.ts +170 -0
- package/src/db/queries/requirements.ts +81 -0
- package/src/db/queries/stories.ts +223 -0
- package/src/db/queries/teams.ts +39 -0
- package/src/git/branches.ts +186 -0
- package/src/git/github.ts +247 -0
- package/src/git/index.ts +3 -0
- package/src/git/submodules.ts +141 -0
- package/src/index.ts +93 -0
- package/src/llm/anthropic.ts +134 -0
- package/src/llm/index.ts +26 -0
- package/src/llm/openai.ts +125 -0
- package/src/llm/provider.ts +60 -0
- package/src/orchestrator/index.ts +3 -0
- package/src/orchestrator/scaler.ts +201 -0
- package/src/orchestrator/scheduler.test.ts +288 -0
- package/src/orchestrator/scheduler.ts +1130 -0
- package/src/orchestrator/workflow.ts +137 -0
- package/src/state-detectors/claude.test.ts +149 -0
- package/src/state-detectors/claude.ts +256 -0
- package/src/state-detectors/codex.test.ts +100 -0
- package/src/state-detectors/codex.ts +252 -0
- package/src/state-detectors/factory.test.ts +51 -0
- package/src/state-detectors/factory.ts +40 -0
- package/src/state-detectors/gemini.test.ts +110 -0
- package/src/state-detectors/gemini.ts +255 -0
- package/src/state-detectors/index.ts +25 -0
- package/src/state-detectors/types.ts +80 -0
- package/src/tmux/index.ts +1 -0
- package/src/tmux/manager.ts +310 -0
- package/src/types/sql.js.d.ts +34 -0
- package/src/utils/claude-code-state.ts +281 -0
- package/src/utils/cli-builder.ts +78 -0
- package/src/utils/cli-commands.ts +84 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/logger.ts +93 -0
- package/src/utils/paths.ts +49 -0
- package/src/utils/timeout.ts +84 -0
- package/tsconfig.json +25 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { execa } from 'execa';
|
|
2
|
+
|
|
3
|
+
export interface PRCreateOptions {
|
|
4
|
+
title: string;
|
|
5
|
+
body: string;
|
|
6
|
+
baseBranch: string;
|
|
7
|
+
headBranch: string;
|
|
8
|
+
draft?: boolean;
|
|
9
|
+
labels?: string[];
|
|
10
|
+
assignees?: string[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface PRInfo {
|
|
14
|
+
number: number;
|
|
15
|
+
url: string;
|
|
16
|
+
title: string;
|
|
17
|
+
state: 'open' | 'closed' | 'merged';
|
|
18
|
+
headBranch: string;
|
|
19
|
+
baseBranch: string;
|
|
20
|
+
additions: number;
|
|
21
|
+
deletions: number;
|
|
22
|
+
changedFiles: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface PRReview {
|
|
26
|
+
state: 'APPROVED' | 'CHANGES_REQUESTED' | 'COMMENTED' | 'PENDING';
|
|
27
|
+
body: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Check if gh CLI is available and authenticated
|
|
32
|
+
*/
|
|
33
|
+
export async function isGitHubCLIAvailable(): Promise<boolean> {
|
|
34
|
+
try {
|
|
35
|
+
await execa('gh', ['auth', 'status']);
|
|
36
|
+
return true;
|
|
37
|
+
} catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Create a pull request
|
|
44
|
+
*/
|
|
45
|
+
export async function createPullRequest(
|
|
46
|
+
workDir: string,
|
|
47
|
+
options: PRCreateOptions
|
|
48
|
+
): Promise<{ number: number; url: string }> {
|
|
49
|
+
const args = [
|
|
50
|
+
'pr', 'create',
|
|
51
|
+
'--title', options.title,
|
|
52
|
+
'--body', options.body,
|
|
53
|
+
'--base', options.baseBranch,
|
|
54
|
+
'--head', options.headBranch,
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
if (options.draft) {
|
|
58
|
+
args.push('--draft');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (options.labels && options.labels.length > 0) {
|
|
62
|
+
args.push('--label', options.labels.join(','));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (options.assignees && options.assignees.length > 0) {
|
|
66
|
+
args.push('--assignee', options.assignees.join(','));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const { stdout } = await execa('gh', args, { cwd: workDir });
|
|
70
|
+
const url = stdout.trim();
|
|
71
|
+
|
|
72
|
+
// Extract PR number from URL
|
|
73
|
+
const numberMatch = url.match(/\/pull\/(\d+)/);
|
|
74
|
+
const number = numberMatch ? parseInt(numberMatch[1], 10) : 0;
|
|
75
|
+
|
|
76
|
+
return { number, url };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get pull request information
|
|
81
|
+
*/
|
|
82
|
+
export async function getPullRequest(workDir: string, prNumber: number): Promise<PRInfo> {
|
|
83
|
+
const { stdout } = await execa('gh', [
|
|
84
|
+
'pr', 'view', prNumber.toString(),
|
|
85
|
+
'--json', 'number,url,title,state,headRefName,baseRefName,additions,deletions,changedFiles',
|
|
86
|
+
], { cwd: workDir });
|
|
87
|
+
|
|
88
|
+
const data = JSON.parse(stdout);
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
number: data.number,
|
|
92
|
+
url: data.url,
|
|
93
|
+
title: data.title,
|
|
94
|
+
state: data.state.toLowerCase() as PRInfo['state'],
|
|
95
|
+
headBranch: data.headRefName,
|
|
96
|
+
baseBranch: data.baseRefName,
|
|
97
|
+
additions: data.additions,
|
|
98
|
+
deletions: data.deletions,
|
|
99
|
+
changedFiles: data.changedFiles,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* List open pull requests
|
|
105
|
+
*/
|
|
106
|
+
export async function listPullRequests(workDir: string, state: 'open' | 'closed' | 'all' = 'open'): Promise<PRInfo[]> {
|
|
107
|
+
const { stdout } = await execa('gh', [
|
|
108
|
+
'pr', 'list',
|
|
109
|
+
'--state', state,
|
|
110
|
+
'--json', 'number,url,title,state,headRefName,baseRefName,additions,deletions,changedFiles',
|
|
111
|
+
], { cwd: workDir });
|
|
112
|
+
|
|
113
|
+
const data = JSON.parse(stdout) as Array<{
|
|
114
|
+
number: number;
|
|
115
|
+
url: string;
|
|
116
|
+
title: string;
|
|
117
|
+
state: string;
|
|
118
|
+
headRefName: string;
|
|
119
|
+
baseRefName: string;
|
|
120
|
+
additions: number;
|
|
121
|
+
deletions: number;
|
|
122
|
+
changedFiles: number;
|
|
123
|
+
}>;
|
|
124
|
+
|
|
125
|
+
return data.map(pr => ({
|
|
126
|
+
number: pr.number,
|
|
127
|
+
url: pr.url,
|
|
128
|
+
title: pr.title,
|
|
129
|
+
state: pr.state.toLowerCase() as PRInfo['state'],
|
|
130
|
+
headBranch: pr.headRefName,
|
|
131
|
+
baseBranch: pr.baseRefName,
|
|
132
|
+
additions: pr.additions,
|
|
133
|
+
deletions: pr.deletions,
|
|
134
|
+
changedFiles: pr.changedFiles,
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Add a comment to a pull request
|
|
140
|
+
*/
|
|
141
|
+
export async function commentOnPullRequest(
|
|
142
|
+
workDir: string,
|
|
143
|
+
prNumber: number,
|
|
144
|
+
body: string
|
|
145
|
+
): Promise<void> {
|
|
146
|
+
await execa('gh', [
|
|
147
|
+
'pr', 'comment', prNumber.toString(),
|
|
148
|
+
'--body', body,
|
|
149
|
+
], { cwd: workDir });
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Submit a review on a pull request
|
|
154
|
+
*/
|
|
155
|
+
export async function reviewPullRequest(
|
|
156
|
+
workDir: string,
|
|
157
|
+
prNumber: number,
|
|
158
|
+
review: PRReview
|
|
159
|
+
): Promise<void> {
|
|
160
|
+
const args = [
|
|
161
|
+
'pr', 'review', prNumber.toString(),
|
|
162
|
+
];
|
|
163
|
+
|
|
164
|
+
switch (review.state) {
|
|
165
|
+
case 'APPROVED':
|
|
166
|
+
args.push('--approve');
|
|
167
|
+
break;
|
|
168
|
+
case 'CHANGES_REQUESTED':
|
|
169
|
+
args.push('--request-changes');
|
|
170
|
+
break;
|
|
171
|
+
case 'COMMENTED':
|
|
172
|
+
args.push('--comment');
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (review.body) {
|
|
177
|
+
args.push('--body', review.body);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
await execa('gh', args, { cwd: workDir });
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Merge a pull request
|
|
185
|
+
*/
|
|
186
|
+
export async function mergePullRequest(
|
|
187
|
+
workDir: string,
|
|
188
|
+
prNumber: number,
|
|
189
|
+
options: {
|
|
190
|
+
method?: 'merge' | 'squash' | 'rebase';
|
|
191
|
+
deleteAfterMerge?: boolean;
|
|
192
|
+
} = {}
|
|
193
|
+
): Promise<void> {
|
|
194
|
+
const args = ['pr', 'merge', prNumber.toString(), '--auto'];
|
|
195
|
+
|
|
196
|
+
switch (options.method) {
|
|
197
|
+
case 'squash':
|
|
198
|
+
args.push('--squash');
|
|
199
|
+
break;
|
|
200
|
+
case 'rebase':
|
|
201
|
+
args.push('--rebase');
|
|
202
|
+
break;
|
|
203
|
+
default:
|
|
204
|
+
args.push('--merge');
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (options.deleteAfterMerge !== false) {
|
|
208
|
+
args.push('--delete-branch');
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
await execa('gh', args, { cwd: workDir });
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Close a pull request
|
|
216
|
+
*/
|
|
217
|
+
export async function closePullRequest(workDir: string, prNumber: number): Promise<void> {
|
|
218
|
+
await execa('gh', ['pr', 'close', prNumber.toString()], { cwd: workDir });
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Get PR diff
|
|
223
|
+
*/
|
|
224
|
+
export async function getPullRequestDiff(workDir: string, prNumber: number): Promise<string> {
|
|
225
|
+
const { stdout } = await execa('gh', [
|
|
226
|
+
'pr', 'diff', prNumber.toString(),
|
|
227
|
+
], { cwd: workDir });
|
|
228
|
+
|
|
229
|
+
return stdout;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Get PR reviews
|
|
234
|
+
*/
|
|
235
|
+
export async function getPullRequestReviews(workDir: string, prNumber: number): Promise<Array<{
|
|
236
|
+
author: string;
|
|
237
|
+
state: string;
|
|
238
|
+
body: string;
|
|
239
|
+
}>> {
|
|
240
|
+
const { stdout } = await execa('gh', [
|
|
241
|
+
'pr', 'view', prNumber.toString(),
|
|
242
|
+
'--json', 'reviews',
|
|
243
|
+
], { cwd: workDir });
|
|
244
|
+
|
|
245
|
+
const data = JSON.parse(stdout);
|
|
246
|
+
return data.reviews || [];
|
|
247
|
+
}
|
package/src/git/index.ts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { execa } from 'execa';
|
|
2
|
+
import { existsSync } from 'fs';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
|
|
5
|
+
export interface SubmoduleInfo {
|
|
6
|
+
path: string;
|
|
7
|
+
url: string;
|
|
8
|
+
branch?: string;
|
|
9
|
+
commit: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Add a git submodule
|
|
14
|
+
*/
|
|
15
|
+
export async function addSubmodule(
|
|
16
|
+
rootDir: string,
|
|
17
|
+
url: string,
|
|
18
|
+
path: string,
|
|
19
|
+
branch: string = 'main'
|
|
20
|
+
): Promise<void> {
|
|
21
|
+
const fullPath = join(rootDir, path);
|
|
22
|
+
|
|
23
|
+
if (existsSync(fullPath)) {
|
|
24
|
+
throw new Error(`Path already exists: ${fullPath}`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
await execa('git', ['submodule', 'add', '-b', branch, url, path], {
|
|
28
|
+
cwd: rootDir,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Initialize submodules
|
|
34
|
+
*/
|
|
35
|
+
export async function initSubmodules(rootDir: string): Promise<void> {
|
|
36
|
+
await execa('git', ['submodule', 'init'], { cwd: rootDir });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Update submodules
|
|
41
|
+
*/
|
|
42
|
+
export async function updateSubmodules(rootDir: string, recursive: boolean = true): Promise<void> {
|
|
43
|
+
const args = ['submodule', 'update'];
|
|
44
|
+
if (recursive) {
|
|
45
|
+
args.push('--recursive');
|
|
46
|
+
}
|
|
47
|
+
await execa('git', args, { cwd: rootDir });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Initialize and update submodules
|
|
52
|
+
*/
|
|
53
|
+
export async function initAndUpdateSubmodules(rootDir: string): Promise<void> {
|
|
54
|
+
await execa('git', ['submodule', 'update', '--init', '--recursive'], {
|
|
55
|
+
cwd: rootDir,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Remove a submodule
|
|
61
|
+
*/
|
|
62
|
+
export async function removeSubmodule(rootDir: string, path: string): Promise<void> {
|
|
63
|
+
// Deinitialize the submodule
|
|
64
|
+
await execa('git', ['submodule', 'deinit', '-f', path], { cwd: rootDir });
|
|
65
|
+
|
|
66
|
+
// Remove from .git/modules
|
|
67
|
+
await execa('git', ['rm', '-f', path], { cwd: rootDir });
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* List all submodules
|
|
72
|
+
*/
|
|
73
|
+
export async function listSubmodules(rootDir: string): Promise<SubmoduleInfo[]> {
|
|
74
|
+
try {
|
|
75
|
+
const { stdout } = await execa('git', ['submodule', 'status'], {
|
|
76
|
+
cwd: rootDir,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
if (!stdout.trim()) {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const submodules: SubmoduleInfo[] = [];
|
|
84
|
+
|
|
85
|
+
for (const line of stdout.split('\n')) {
|
|
86
|
+
const match = line.match(/^[\s+-]?([a-f0-9]+)\s+(\S+)(?:\s+\((.+)\))?/);
|
|
87
|
+
if (match) {
|
|
88
|
+
const [, commit, path, branch] = match;
|
|
89
|
+
submodules.push({
|
|
90
|
+
path,
|
|
91
|
+
url: await getSubmoduleUrl(rootDir, path),
|
|
92
|
+
branch: branch?.replace('heads/', ''),
|
|
93
|
+
commit,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return submodules;
|
|
99
|
+
} catch {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Get the URL of a submodule
|
|
106
|
+
*/
|
|
107
|
+
export async function getSubmoduleUrl(rootDir: string, path: string): Promise<string> {
|
|
108
|
+
try {
|
|
109
|
+
const { stdout } = await execa('git', [
|
|
110
|
+
'config', '--file', '.gitmodules',
|
|
111
|
+
`submodule.${path}.url`,
|
|
112
|
+
], { cwd: rootDir });
|
|
113
|
+
return stdout.trim();
|
|
114
|
+
} catch {
|
|
115
|
+
return '';
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Check if a path is a submodule
|
|
121
|
+
*/
|
|
122
|
+
export async function isSubmodule(rootDir: string, path: string): Promise<boolean> {
|
|
123
|
+
const submodules = await listSubmodules(rootDir);
|
|
124
|
+
return submodules.some(s => s.path === path);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Sync submodule URLs
|
|
129
|
+
*/
|
|
130
|
+
export async function syncSubmodules(rootDir: string): Promise<void> {
|
|
131
|
+
await execa('git', ['submodule', 'sync'], { cwd: rootDir });
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Fetch updates for all submodules
|
|
136
|
+
*/
|
|
137
|
+
export async function fetchSubmodules(rootDir: string): Promise<void> {
|
|
138
|
+
await execa('git', ['submodule', 'foreach', 'git', 'fetch'], {
|
|
139
|
+
cwd: rootDir,
|
|
140
|
+
});
|
|
141
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import { spawnSync } from 'child_process';
|
|
6
|
+
import {
|
|
7
|
+
initCommand,
|
|
8
|
+
configCommand,
|
|
9
|
+
addRepoCommand,
|
|
10
|
+
teamsCommand,
|
|
11
|
+
reqCommand,
|
|
12
|
+
statusCommand,
|
|
13
|
+
agentsCommand,
|
|
14
|
+
storiesCommand,
|
|
15
|
+
escalationsCommand,
|
|
16
|
+
resumeCommand,
|
|
17
|
+
assignCommand,
|
|
18
|
+
nukeCommand,
|
|
19
|
+
msgCommand,
|
|
20
|
+
myStoriesCommand,
|
|
21
|
+
prCommand,
|
|
22
|
+
managerCommand,
|
|
23
|
+
} from './cli/commands/index.js';
|
|
24
|
+
|
|
25
|
+
const program = new Command();
|
|
26
|
+
|
|
27
|
+
program
|
|
28
|
+
.name('hive')
|
|
29
|
+
.description('AI Agent Orchestrator - Manage agile software development teams of AI agents')
|
|
30
|
+
.version('0.1.0');
|
|
31
|
+
|
|
32
|
+
// Core commands
|
|
33
|
+
program.addCommand(initCommand);
|
|
34
|
+
program.addCommand(configCommand);
|
|
35
|
+
|
|
36
|
+
// Repository and team management
|
|
37
|
+
program.addCommand(addRepoCommand);
|
|
38
|
+
program.addCommand(teamsCommand);
|
|
39
|
+
|
|
40
|
+
// Requirement and workflow
|
|
41
|
+
program.addCommand(reqCommand);
|
|
42
|
+
program.addCommand(statusCommand);
|
|
43
|
+
program.addCommand(resumeCommand);
|
|
44
|
+
program.addCommand(assignCommand);
|
|
45
|
+
|
|
46
|
+
// Entity management
|
|
47
|
+
program.addCommand(agentsCommand);
|
|
48
|
+
program.addCommand(storiesCommand);
|
|
49
|
+
program.addCommand(escalationsCommand);
|
|
50
|
+
|
|
51
|
+
// Destructive operations
|
|
52
|
+
program.addCommand(nukeCommand);
|
|
53
|
+
|
|
54
|
+
// Communication
|
|
55
|
+
program.addCommand(msgCommand);
|
|
56
|
+
|
|
57
|
+
// Agent workflow
|
|
58
|
+
program.addCommand(myStoriesCommand);
|
|
59
|
+
|
|
60
|
+
// PR and merge queue
|
|
61
|
+
program.addCommand(prCommand);
|
|
62
|
+
|
|
63
|
+
// Manager (micromanager daemon)
|
|
64
|
+
program.addCommand(managerCommand);
|
|
65
|
+
|
|
66
|
+
// Dashboard command
|
|
67
|
+
program
|
|
68
|
+
.command('dashboard')
|
|
69
|
+
.description('Open TUI dashboard')
|
|
70
|
+
.option('-r, --refresh <ms>', 'Refresh interval in milliseconds', '5000')
|
|
71
|
+
.action(async (options: { refresh: string }) => {
|
|
72
|
+
try {
|
|
73
|
+
// Ensure higher Node heap specifically for the dashboard by re-spawning with --max-old-space-size if not already set
|
|
74
|
+
const hasHeapFlag = process.execArgv.some(arg => arg.startsWith('--max-old-space-size'));
|
|
75
|
+
const desiredMb = parseInt(process.env.HIVE_DASHBOARD_HEAP_MB || '4096', 10);
|
|
76
|
+
|
|
77
|
+
if (!hasHeapFlag) {
|
|
78
|
+
const args = [`--max-old-space-size=${desiredMb}`, process.argv[1], 'dashboard', '--refresh', String(options.refresh)];
|
|
79
|
+
const result = spawnSync(process.execPath, args, { stdio: 'inherit', env: process.env });
|
|
80
|
+
process.exit(result.status === null ? 1 : result.status);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const { startDashboard } = await import('./cli/dashboard/index.js');
|
|
84
|
+
startDashboard({ refreshInterval: parseInt(options.refresh, 10) });
|
|
85
|
+
} catch (err) {
|
|
86
|
+
console.error(chalk.red('Failed to start dashboard:'), err);
|
|
87
|
+
console.log(chalk.gray('Make sure blessed is installed: npm install blessed'));
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Parse and run
|
|
93
|
+
program.parse();
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
2
|
+
import type { LLMProvider, Message, CompletionOptions, CompletionResult } from './provider.js';
|
|
3
|
+
import { withTimeout } from '../utils/timeout.js';
|
|
4
|
+
|
|
5
|
+
export class AnthropicProvider implements LLMProvider {
|
|
6
|
+
name = 'anthropic';
|
|
7
|
+
private client: Anthropic;
|
|
8
|
+
private model: string;
|
|
9
|
+
private defaultMaxTokens: number;
|
|
10
|
+
private defaultTemperature: number;
|
|
11
|
+
|
|
12
|
+
constructor(options: {
|
|
13
|
+
apiKey?: string;
|
|
14
|
+
model?: string;
|
|
15
|
+
maxTokens?: number;
|
|
16
|
+
temperature?: number;
|
|
17
|
+
} = {}) {
|
|
18
|
+
this.client = new Anthropic({
|
|
19
|
+
apiKey: options.apiKey || process.env.ANTHROPIC_API_KEY,
|
|
20
|
+
});
|
|
21
|
+
this.model = options.model || 'claude-sonnet-4-20250514';
|
|
22
|
+
this.defaultMaxTokens = options.maxTokens || 8000;
|
|
23
|
+
this.defaultTemperature = options.temperature ?? 0.5;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async complete(messages: Message[], options?: CompletionOptions): Promise<CompletionResult> {
|
|
27
|
+
// Extract system message if present
|
|
28
|
+
const systemMessage = messages.find(m => m.role === 'system');
|
|
29
|
+
const conversationMessages = messages.filter(m => m.role !== 'system');
|
|
30
|
+
|
|
31
|
+
const apiCall = async () => {
|
|
32
|
+
const response = await this.client.messages.create({
|
|
33
|
+
model: this.model,
|
|
34
|
+
max_tokens: options?.maxTokens ?? this.defaultMaxTokens,
|
|
35
|
+
temperature: options?.temperature ?? this.defaultTemperature,
|
|
36
|
+
system: systemMessage?.content,
|
|
37
|
+
messages: conversationMessages.map(m => ({
|
|
38
|
+
role: m.role as 'user' | 'assistant',
|
|
39
|
+
content: m.content,
|
|
40
|
+
})),
|
|
41
|
+
stop_sequences: options?.stopSequences,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const content = response.content[0];
|
|
45
|
+
const textContent = content.type === 'text' ? content.text : '';
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
content: textContent,
|
|
49
|
+
stopReason: this.mapStopReason(response.stop_reason),
|
|
50
|
+
usage: {
|
|
51
|
+
inputTokens: response.usage.input_tokens,
|
|
52
|
+
outputTokens: response.usage.output_tokens,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// Apply timeout if specified
|
|
58
|
+
if (options?.timeoutMs) {
|
|
59
|
+
return withTimeout(
|
|
60
|
+
apiCall(),
|
|
61
|
+
options.timeoutMs,
|
|
62
|
+
`Anthropic API call timed out after ${options.timeoutMs}ms`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return apiCall();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async *streamComplete(messages: Message[], options?: CompletionOptions): AsyncIterable<string> {
|
|
70
|
+
const systemMessage = messages.find(m => m.role === 'system');
|
|
71
|
+
const conversationMessages = messages.filter(m => m.role !== 'system');
|
|
72
|
+
// Capture instance properties to avoid 'this' binding issues in generator
|
|
73
|
+
const client = this.client;
|
|
74
|
+
const model = this.model;
|
|
75
|
+
const defaultMaxTokens = this.defaultMaxTokens;
|
|
76
|
+
const defaultTemperature = this.defaultTemperature;
|
|
77
|
+
|
|
78
|
+
const streamGenerator = async function* () {
|
|
79
|
+
const stream = client.messages.stream({
|
|
80
|
+
model: model,
|
|
81
|
+
max_tokens: options?.maxTokens ?? defaultMaxTokens,
|
|
82
|
+
temperature: options?.temperature ?? defaultTemperature,
|
|
83
|
+
system: systemMessage?.content,
|
|
84
|
+
messages: conversationMessages.map(m => ({
|
|
85
|
+
role: m.role as 'user' | 'assistant',
|
|
86
|
+
content: m.content,
|
|
87
|
+
})),
|
|
88
|
+
stop_sequences: options?.stopSequences,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
for await (const event of stream) {
|
|
92
|
+
if (event.type === 'content_block_delta' && event.delta.type === 'text_delta') {
|
|
93
|
+
yield event.delta.text;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// Apply timeout if specified
|
|
99
|
+
if (options?.timeoutMs) {
|
|
100
|
+
const timeoutPromise = new Promise<never>((_, reject) => {
|
|
101
|
+
setTimeout(() => {
|
|
102
|
+
reject(new Error(`Anthropic streaming API call timed out after ${options.timeoutMs}ms`));
|
|
103
|
+
}, options.timeoutMs);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const generator = streamGenerator();
|
|
107
|
+
|
|
108
|
+
while (true) {
|
|
109
|
+
const result = await Promise.race([
|
|
110
|
+
generator.next(),
|
|
111
|
+
timeoutPromise
|
|
112
|
+
]);
|
|
113
|
+
|
|
114
|
+
if (result.done) break;
|
|
115
|
+
yield result.value;
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
yield* streamGenerator();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
private mapStopReason(reason: string | null): CompletionResult['stopReason'] {
|
|
123
|
+
switch (reason) {
|
|
124
|
+
case 'end_turn':
|
|
125
|
+
return 'end_turn';
|
|
126
|
+
case 'max_tokens':
|
|
127
|
+
return 'max_tokens';
|
|
128
|
+
case 'stop_sequence':
|
|
129
|
+
return 'stop_sequence';
|
|
130
|
+
default:
|
|
131
|
+
return 'error';
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
package/src/llm/index.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { LLMProvider, ProviderConfig } from './provider.js';
|
|
2
|
+
import { AnthropicProvider } from './anthropic.js';
|
|
3
|
+
import { OpenAIProvider } from './openai.js';
|
|
4
|
+
|
|
5
|
+
export * from './provider.js';
|
|
6
|
+
export { AnthropicProvider } from './anthropic.js';
|
|
7
|
+
export { OpenAIProvider } from './openai.js';
|
|
8
|
+
|
|
9
|
+
export function createProvider(config: ProviderConfig): LLMProvider {
|
|
10
|
+
switch (config.provider) {
|
|
11
|
+
case 'anthropic':
|
|
12
|
+
return new AnthropicProvider({
|
|
13
|
+
model: config.model,
|
|
14
|
+
maxTokens: config.maxTokens,
|
|
15
|
+
temperature: config.temperature,
|
|
16
|
+
});
|
|
17
|
+
case 'openai':
|
|
18
|
+
return new OpenAIProvider({
|
|
19
|
+
model: config.model,
|
|
20
|
+
maxTokens: config.maxTokens,
|
|
21
|
+
temperature: config.temperature,
|
|
22
|
+
});
|
|
23
|
+
default:
|
|
24
|
+
throw new Error(`Unknown provider: ${config.provider}`);
|
|
25
|
+
}
|
|
26
|
+
}
|