dual-brain 0.1.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/AGENTS.md +97 -0
- package/CLAUDE.md +147 -0
- package/LICENSE +21 -0
- package/README.md +197 -0
- package/agents/implementer.md +22 -0
- package/agents/researcher.md +25 -0
- package/agents/verifier.md +30 -0
- package/bin/dual-brain.mjs +2868 -0
- package/hooks/auto-update-wrapper.mjs +102 -0
- package/hooks/auto-update.sh +67 -0
- package/hooks/budget-balancer.mjs +679 -0
- package/hooks/control-panel.mjs +1195 -0
- package/hooks/cost-logger.mjs +286 -0
- package/hooks/cost-report.mjs +351 -0
- package/hooks/decision-ledger.mjs +299 -0
- package/hooks/dual-brain-review.mjs +404 -0
- package/hooks/dual-brain-think.mjs +393 -0
- package/hooks/enforce-tier.mjs +469 -0
- package/hooks/failure-detector.mjs +138 -0
- package/hooks/gpt-work-dispatcher.mjs +512 -0
- package/hooks/head-guard.mjs +105 -0
- package/hooks/health-check.mjs +444 -0
- package/hooks/install-git-hooks.mjs +106 -0
- package/hooks/model-registry.mjs +859 -0
- package/hooks/plan-generator.mjs +544 -0
- package/hooks/profiles.mjs +254 -0
- package/hooks/quality-gate.mjs +355 -0
- package/hooks/risk-classifier.mjs +41 -0
- package/hooks/session-report.mjs +514 -0
- package/hooks/setup-wizard.mjs +130 -0
- package/hooks/summary-checkpoint.mjs +432 -0
- package/hooks/task-classifier.mjs +328 -0
- package/hooks/test-orchestrator.mjs +1077 -0
- package/hooks/vibe-memory.mjs +463 -0
- package/hooks/vibe-router.mjs +387 -0
- package/hooks/wave-orchestrator.mjs +1397 -0
- package/install.mjs +1541 -0
- package/mcp-server/README.md +81 -0
- package/mcp-server/index.mjs +388 -0
- package/orchestrator.json +215 -0
- package/package.json +108 -0
- package/playbooks/debug.json +49 -0
- package/playbooks/refactor.json +57 -0
- package/playbooks/security-audit.json +57 -0
- package/playbooks/security.json +38 -0
- package/playbooks/test-gen.json +48 -0
- package/plugin.json +22 -0
- package/review-rules.md +17 -0
- package/shell-hook.sh +26 -0
- package/skills/go.md +22 -0
- package/skills/review.md +19 -0
- package/skills/status.md +13 -0
- package/skills/think.md +22 -0
- package/src/brief.mjs +266 -0
- package/src/decide.mjs +635 -0
- package/src/decompose.mjs +331 -0
- package/src/detect.mjs +345 -0
- package/src/dispatch.mjs +942 -0
- package/src/health.mjs +253 -0
- package/src/index.mjs +44 -0
- package/src/install-hooks.mjs +100 -0
- package/src/playbook.mjs +257 -0
- package/src/profile.mjs +990 -0
- package/src/redact.mjs +192 -0
- package/src/repo.mjs +292 -0
- package/src/session.mjs +1036 -0
- package/src/tui.mjs +197 -0
- package/src/update-check.mjs +35 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Dual-Brain Orchestrator — Codex Agent Instructions
|
|
2
|
+
|
|
3
|
+
You are a **work provider** in a dual-brain system. Claude Code is the orchestrator.
|
|
4
|
+
You are dispatched by `src/dispatch.mjs` to handle execute-tier tasks. Do not orchestrate — implement.
|
|
5
|
+
|
|
6
|
+
## Your Role
|
|
7
|
+
|
|
8
|
+
- **Tier**: Execute (`gpt-4.1` default, `o4-mini` for search, `gpt-5.4`/`gpt-5.5` for think-heavy work)
|
|
9
|
+
- **Dispatched by**: `node .claude/hooks/gpt-work-dispatcher.mjs --task "..." --tier execute`
|
|
10
|
+
- **You receive**: a scoped task, acceptance criteria, and file context
|
|
11
|
+
- **You return**: structured output (files changed, tests run, edge cases found)
|
|
12
|
+
|
|
13
|
+
You are NOT the orchestrator. Do not run `dual-brain go` or re-route tasks. Complete the work handed to you.
|
|
14
|
+
|
|
15
|
+
## Core Architecture (v6)
|
|
16
|
+
|
|
17
|
+
Four modules in `src/` form the decision pipeline:
|
|
18
|
+
|
|
19
|
+
- **`profile.mjs`** — Active profile, provider availability, subscription plan
|
|
20
|
+
- **`detect.mjs`** — Task intent, risk, complexity, tier classification
|
|
21
|
+
- **`decide.mjs`** — Provider/model/tier routing; budget pressure and dual-brain threshold
|
|
22
|
+
- **`dispatch.mjs`** — Executes decisions: Claude subagent, GPT via Codex, or dual-brain flow
|
|
23
|
+
|
|
24
|
+
## Tier System
|
|
25
|
+
|
|
26
|
+
| Tier | Model | Scope |
|
|
27
|
+
|------|-------|-------|
|
|
28
|
+
| Search | `o4-mini` | Read-only lookups, grep, explore |
|
|
29
|
+
| Execute | `gpt-4.1` | Edits, tests, git ops |
|
|
30
|
+
| Think | `gpt-5.4` / `gpt-5.5` | Architecture (usually Claude-side) |
|
|
31
|
+
|
|
32
|
+
## Structured Output Format
|
|
33
|
+
|
|
34
|
+
After completing any task, output a JSON block so the orchestrator can parse results:
|
|
35
|
+
|
|
36
|
+
```json
|
|
37
|
+
{
|
|
38
|
+
"status": "done",
|
|
39
|
+
"files_changed": ["src/foo.mjs", "src/bar.mjs"],
|
|
40
|
+
"tests_run": ["npm test -- --grep foo"],
|
|
41
|
+
"edge_cases": ["what happens when X is null"],
|
|
42
|
+
"notes": "optional freeform"
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
For search-tier tasks, include `"files_found"` and `"line_refs"` instead of `files_changed`.
|
|
47
|
+
|
|
48
|
+
## Security Rules (No Exceptions)
|
|
49
|
+
|
|
50
|
+
- **Never** write secrets, tokens, or credentials to files
|
|
51
|
+
- **Never** implement auth/credential changes without a task brief that includes dual-brain approval
|
|
52
|
+
- If the task touches auth, credentials, billing, or migrations: stop, output `"status": "needs_approval"`, and explain why
|
|
53
|
+
- Use `--sandbox` mode when available; prefer `--approval-mode suggest` for destructive operations
|
|
54
|
+
|
|
55
|
+
## Quality Gate
|
|
56
|
+
|
|
57
|
+
Before finishing a session with code changes, run:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
node .claude/hooks/session-report.mjs
|
|
61
|
+
node .claude/hooks/quality-gate.mjs
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Gate statuses: `pass` (safe to end), `issues_found` (fix first), `needs_human_review` (escalate).
|
|
65
|
+
|
|
66
|
+
## Codex CLI Flags
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
codex --approval-mode suggest # Prompt before destructive shell ops
|
|
70
|
+
codex --sandbox # Isolate filesystem writes
|
|
71
|
+
codex exec --json "..." # Programmatic output (used by dispatch.mjs)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
When invoked by dispatch.mjs, `--json` output is expected. Always emit valid JSON in the structured output block.
|
|
75
|
+
|
|
76
|
+
## Routing Rules (for context)
|
|
77
|
+
|
|
78
|
+
1. Tasks under 3 min → Claude handles directly (Codex startup overhead not worth it)
|
|
79
|
+
2. Isolated tasks over 3 min → routed here by budget-balancer
|
|
80
|
+
3. High-risk decisions → dual-brain think (Claude + GPT deliberate before you implement)
|
|
81
|
+
4. Tier priority: think > execute > search
|
|
82
|
+
|
|
83
|
+
## Risk Classification
|
|
84
|
+
|
|
85
|
+
| Risk | Examples | Action |
|
|
86
|
+
|------|----------|--------|
|
|
87
|
+
| Critical | auth, secrets, tokens | Requires dual-brain approval before you touch it |
|
|
88
|
+
| High | billing, migrations | Confirm task brief includes approval |
|
|
89
|
+
| Medium | tests, utilities | Implement, note edge cases |
|
|
90
|
+
| Low | docs, comments | Implement freely |
|
|
91
|
+
|
|
92
|
+
## Hardcoded Stops
|
|
93
|
+
|
|
94
|
+
Do not proceed if:
|
|
95
|
+
- No task brief provided (ask for one via `"status": "needs_brief"`)
|
|
96
|
+
- Task scope exceeds 5 production files with no wave plan
|
|
97
|
+
- Task involves routing/dispatcher/tier logic changes without dual-brain sign-off
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Dual-Brain Orchestrator
|
|
2
|
+
|
|
3
|
+
This project uses dual-provider orchestration. Config: `.claude/orchestrator.json`.
|
|
4
|
+
|
|
5
|
+
## Core Architecture (v7)
|
|
6
|
+
|
|
7
|
+
Four modules in `src/` form the decision pipeline:
|
|
8
|
+
|
|
9
|
+
- **`profile.mjs`** — Load active profile, provider availability, preferences, and subscription plan
|
|
10
|
+
- **`detect.mjs`** — Classify task intent, risk, complexity, and tier from prompt + file paths
|
|
11
|
+
- **`decide.mjs`** — Route to provider/model/tier; handles budget pressure and dual-brain threshold
|
|
12
|
+
- **`dispatch.mjs`** — Execute the decision: Claude subagent, GPT via Codex, or dual-brain flow
|
|
13
|
+
|
|
14
|
+
The hooks layer (`/home/runner/workspace/.claude/hooks/`) wraps these modules for Claude Code integration and is still valid.
|
|
15
|
+
|
|
16
|
+
## CLI Commands
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
dual-brain init # First-time setup
|
|
20
|
+
dual-brain go "task description" # Detect → decide → dispatch
|
|
21
|
+
dual-brain go --dry-run "..." # Show routing without executing
|
|
22
|
+
dual-brain go --files a.mjs,b.mjs "..." # Provide file context for risk classification
|
|
23
|
+
dual-brain status # Provider health, budget pressure, models
|
|
24
|
+
dual-brain remember "preference" # Save project-scoped preference
|
|
25
|
+
dual-brain forget "preference" # Remove preference by fuzzy match
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Tier Routing
|
|
29
|
+
|
|
30
|
+
- **Search** (`haiku`): Read-only lookups, grep, explore. Return: files found, line refs, confidence.
|
|
31
|
+
- **Execute** (`sonnet`): Edits, tests, git ops. Return: files changed, tests run, edge cases.
|
|
32
|
+
- **Think** (main session, Opus): Architecture, review, planning. Return: decision, alternatives, risks.
|
|
33
|
+
|
|
34
|
+
## Dual-Brain Collaboration
|
|
35
|
+
|
|
36
|
+
Dual-brain is a multi-round conversation between Claude and GPT — not a single-shot dispatch.
|
|
37
|
+
|
|
38
|
+
**Think flow** (architecture decisions):
|
|
39
|
+
1. Round 1: `node .claude/hooks/dual-brain-think.mjs --question "..."` → GPT gives independent analysis
|
|
40
|
+
2. You analyze the same question independently
|
|
41
|
+
3. Round 2: `node .claude/hooks/dual-brain-think.mjs --question "..." --round 2 --claude-says "<your analysis>"` → GPT responds with agreements, pushback, refined recommendation
|
|
42
|
+
4. You synthesize both rounds into a final decision
|
|
43
|
+
|
|
44
|
+
**Review flow** (code review):
|
|
45
|
+
1. Round 1: `node .claude/hooks/dual-brain-review.mjs` → GPT reviews the diff independently
|
|
46
|
+
2. You review the same diff independently
|
|
47
|
+
3. Round 2: `node .claude/hooks/dual-brain-review.mjs --round 2 --claude-review "<your findings>"` → GPT confirms shared findings, acknowledges misses
|
|
48
|
+
4. You synthesize into a final review verdict
|
|
49
|
+
|
|
50
|
+
## Routing Rules
|
|
51
|
+
|
|
52
|
+
1. Tasks under 3 min → Claude (Codex startup overhead not worth it)
|
|
53
|
+
2. Isolated tasks over 3 min → check balance: `node .claude/hooks/budget-balancer.mjs`
|
|
54
|
+
3. High-risk decisions → dual-brain think
|
|
55
|
+
4. When a task spans tiers: think > execute > search
|
|
56
|
+
|
|
57
|
+
## Mandatory Workload Distribution
|
|
58
|
+
|
|
59
|
+
**Claude MUST follow these rules before implementing multi-file changes:**
|
|
60
|
+
|
|
61
|
+
1. **Before starting any batch of 3+ file edits**: run `node .claude/hooks/budget-balancer.mjs` to check provider balance, then `dual-brain go --dry-run "description"` to classify tasks
|
|
62
|
+
2. **When budget-balancer recommends GPT**: dispatch via `src/dispatch.mjs` (or `node .claude/hooks/gpt-work-dispatcher.mjs --task "..." --tier execute`)
|
|
63
|
+
3. **Security/auth/credential changes**: always require dual-brain think flow before implementation
|
|
64
|
+
4. **Audit remediation batches**: plan waves with dual-brain think, dispatch execution to GPT, Claude reviews
|
|
65
|
+
5. **Claude's role in multi-task work**: define acceptance criteria, dispatch agents, review results — not solo-implement everything
|
|
66
|
+
|
|
67
|
+
**Triggers that require this workflow:** 3+ production files edited in one session · auth/credentials/tokens/secrets · changes to dispatcher, agent routing, or tier logic · audit remediation across multiple subsystems · Claude think capacity above 60% per budget-balancer.
|
|
68
|
+
|
|
69
|
+
**Failure to route is itself a bug.**
|
|
70
|
+
|
|
71
|
+
## Quality Gate
|
|
72
|
+
|
|
73
|
+
Before ending a session with code changes:
|
|
74
|
+
1. `node .claude/hooks/session-report.mjs` (allowed by head-guard for hook scripts)
|
|
75
|
+
2. `node .claude/hooks/quality-gate.mjs`
|
|
76
|
+
|
|
77
|
+
Gate statuses: `pass` (safe to end), `issues_found` (fix first), `needs_human_review` (GPT unavailable).
|
|
78
|
+
|
|
79
|
+
## Profiles
|
|
80
|
+
|
|
81
|
+
Profile persists to `.dualbrain/profile.json` (project-scoped, gitignored).
|
|
82
|
+
|
|
83
|
+
- **auto** (default): Adapts routing based on task risk, provider health, and outcomes
|
|
84
|
+
- **balanced**: Best model per tier, normal budgets, reviews at medium+ risk
|
|
85
|
+
- **cost-saver**: Prefer cheaper models, lower budgets, skip GPT for non-critical
|
|
86
|
+
- **quality-first**: Dual-brain for medium+ risk, higher budgets, stricter reviews
|
|
87
|
+
|
|
88
|
+
Switch via the interactive Profile screen in `dual-brain`, or set `bias` in `.dualbrain/profile.json`.
|
|
89
|
+
|
|
90
|
+
## Adaptive Routing (Auto Mode)
|
|
91
|
+
|
|
92
|
+
- **Risk classification**: auth/secrets→critical, billing/migrations→high, tests/utils→medium, docs→low
|
|
93
|
+
- **Failure detection**: 2+ failures on same prompt in 2 hours → auto-escalate tier or trigger dual-brain
|
|
94
|
+
- **Provider balance**: Routes to underused provider when one subscription is hot
|
|
95
|
+
- **Burst awareness**: Suppresses duplicate warnings during agent waves (3+ agents in 90s)
|
|
96
|
+
|
|
97
|
+
## Budget Balancer
|
|
98
|
+
|
|
99
|
+
`src/decide.mjs` handles routing decisions using the same token data internally. For inspection:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
node .claude/hooks/budget-balancer.mjs
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Tracks 5-hour and 7-day rolling windows against subscription limits (Claude Pro/Max, ChatGPT Plus/Pro). The higher pressure window is the binding constraint. Uses actual `input_tokens + output_tokens` from usage logs.
|
|
106
|
+
|
|
107
|
+
**Subscription tiers** (configured in `orchestrator.json` → `subscriptions.*.plan`):
|
|
108
|
+
- Claude: Pro $20, Max x5 $100, Max x20 $200
|
|
109
|
+
- ChatGPT: Plus $20, Pro $100, Pro $200
|
|
110
|
+
|
|
111
|
+
## Multi-Step Work
|
|
112
|
+
|
|
113
|
+
The wave orchestrator is available for complex multi-step tasks:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
node .claude/hooks/wave-orchestrator.mjs "fix the login bug and update the nav"
|
|
117
|
+
node .claude/hooks/wave-orchestrator.mjs --dry-run "refactor auth module"
|
|
118
|
+
node .claude/hooks/wave-orchestrator.mjs --resume <manifestId>
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
For most tasks, prefer `dual-brain go "..."` — it runs the same detect→decide→dispatch pipeline with less overhead.
|
|
122
|
+
|
|
123
|
+
## Available Tools
|
|
124
|
+
|
|
125
|
+
| Tool | Purpose |
|
|
126
|
+
|------|---------|
|
|
127
|
+
| `dual-brain go "..."` | Primary entry point: detect, decide, dispatch |
|
|
128
|
+
| `dual-brain status` | Provider health, budget, models |
|
|
129
|
+
| `node .claude/hooks/budget-balancer.mjs` | Token usage and routing recommendation |
|
|
130
|
+
| `node .claude/hooks/dual-brain-think.mjs` | Multi-round architecture decisions with GPT |
|
|
131
|
+
| `node .claude/hooks/dual-brain-review.mjs` | Multi-round code review with GPT |
|
|
132
|
+
| `node .claude/hooks/wave-orchestrator.mjs "..."` | Dependency-aware multi-wave dispatch |
|
|
133
|
+
| `node .claude/hooks/session-report.mjs` | End-of-session summary |
|
|
134
|
+
| `node .claude/hooks/quality-gate.mjs` | Gate check before ending session |
|
|
135
|
+
| `node .claude/hooks/health-check.mjs` | System health |
|
|
136
|
+
| `node .claude/hooks/test-orchestrator.mjs` | Self-tests (40 tests) |
|
|
137
|
+
| `node .claude/hooks/vibe-memory.mjs` | Persistent preferences across sessions |
|
|
138
|
+
| `dual-brain search "..."` | Search across all previous sessions |
|
|
139
|
+
|
|
140
|
+
## Cross-Session Context
|
|
141
|
+
|
|
142
|
+
When the user references past work ("we did this before", "yesterday we worked on", "remember when we", "didn't we already fix"), use the session search to find relevant context:
|
|
143
|
+
|
|
144
|
+
1. Run `dual-brain search "keyword"` to search the session index
|
|
145
|
+
2. Or use the MCP tool `dual_brain_search` if available
|
|
146
|
+
|
|
147
|
+
This surfaces previous conversations so HEAD can provide continuity across sessions without the user having to re-explain.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 1xmint
|
|
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,197 @@
|
|
|
1
|
+
# dual-brain
|
|
2
|
+
|
|
3
|
+
AI orchestration across Claude + OpenAI subscriptions — smart routing, budget awareness, and dual-brain collaboration.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g dual-brain
|
|
9
|
+
dual-brain init
|
|
10
|
+
dual-brain go "fix the login bug"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## How It Works
|
|
14
|
+
|
|
15
|
+
dual-brain detects the intent and risk of your task, picks the best model based on your subscriptions and current budget pressure, and dispatches to Claude or OpenAI. For high-risk decisions (auth, architecture, critical changes), it runs both providers in parallel and surfaces a consensus. It learns from usage patterns to improve routing over time.
|
|
16
|
+
|
|
17
|
+
**Pipeline:** `detect` → `decide` → `dispatch`
|
|
18
|
+
|
|
19
|
+
- **detect** — classifies intent (edit, refactor, debug, search, architecture…), risk (low/medium/high/critical), complexity, and effort from the task prompt and file paths
|
|
20
|
+
- **decide** — picks provider, model, and effort level based on your subscription plan, current budget pressure, and routing bias
|
|
21
|
+
- **dispatch** — runs the agent via `claude` CLI or `codex` CLI, records token usage, returns a structured result
|
|
22
|
+
|
|
23
|
+
## Commands
|
|
24
|
+
|
|
25
|
+
### `dual-brain init`
|
|
26
|
+
|
|
27
|
+
First-time setup. Three questions: which providers you have, subscription tiers, and optimization preference. The actual flow auto-detects existing auth and adapts — you may see fewer prompts if credentials are already configured.
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
Dual-Brain Orchestrator — First-time setup
|
|
31
|
+
|
|
32
|
+
Which AI subscriptions do you have?
|
|
33
|
+
(1) Claude only (2) OpenAI only (3) Both
|
|
34
|
+
> 3
|
|
35
|
+
|
|
36
|
+
Claude tier?
|
|
37
|
+
(1) $20/mo (2) $100/mo (3) $200/mo
|
|
38
|
+
> 2
|
|
39
|
+
|
|
40
|
+
Default optimization?
|
|
41
|
+
(1) Save usage (2) Balanced (3) Best quality
|
|
42
|
+
> 2
|
|
43
|
+
|
|
44
|
+
Profile saved. Providers: Claude ($100), OpenAI ($20). Mode: dual. Runtime: claude-code
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Profile is written to `.dualbrain/profile.json` in your project (or `~/.config/dual-brain/profile.json` globally).
|
|
48
|
+
|
|
49
|
+
### `dual-brain go "task"`
|
|
50
|
+
|
|
51
|
+
Detects, decides, and dispatches in one command.
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
$ dual-brain go "refactor the auth middleware to use JWT" --files src/middleware/auth.js
|
|
55
|
+
|
|
56
|
+
Moderate critical-risk security touching 1 file.
|
|
57
|
+
provider : claude
|
|
58
|
+
model : opus (high)
|
|
59
|
+
tier : think
|
|
60
|
+
dual-brain : yes
|
|
61
|
+
reason : Using opus high with dual-brain review because this security change is critical risk.
|
|
62
|
+
|
|
63
|
+
Dispatching...
|
|
64
|
+
|
|
65
|
+
Consensus: both-passed
|
|
66
|
+
Claude : Refactored auth.js to validate JWT using jsonwebtoken...
|
|
67
|
+
OpenAI : Updated middleware to verify tokens with proper expiry...
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**Options:**
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
dual-brain go "task" --dry-run # show routing decision, don't execute
|
|
74
|
+
dual-brain go "task" --files a.mjs,b.mjs # add file context for risk classification
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### `dual-brain status`
|
|
78
|
+
|
|
79
|
+
Shows provider health, budget pressure, available models, and active preferences.
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
$ dual-brain status
|
|
83
|
+
|
|
84
|
+
=== Dual-Brain Status ===
|
|
85
|
+
|
|
86
|
+
Providers:
|
|
87
|
+
Claude plan=$100 budget=23% used
|
|
88
|
+
OpenAI plan=$20 budget=5% used
|
|
89
|
+
|
|
90
|
+
Available models:
|
|
91
|
+
Claude : haiku, sonnet, opus
|
|
92
|
+
OpenAI : gpt-4.1-mini, gpt-4.1, gpt-5.2, gpt-5.4-mini, gpt-5.3-codex, gpt-5.4, gpt-5.5
|
|
93
|
+
|
|
94
|
+
Head model : sonnet
|
|
95
|
+
Mode : dual
|
|
96
|
+
Solo brain : no
|
|
97
|
+
|
|
98
|
+
Runtime:
|
|
99
|
+
claude CLI : available
|
|
100
|
+
codex CLI : available
|
|
101
|
+
detected : claude-code
|
|
102
|
+
|
|
103
|
+
Preferences: (none)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### `dual-brain remember "preference"`
|
|
107
|
+
|
|
108
|
+
Saves a project-scoped preference that influences routing decisions.
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
dual-brain remember "always use opus for security tasks"
|
|
112
|
+
dual-brain remember "prefer cost-saver mode this sprint"
|
|
113
|
+
dual-brain forget "cost-saver"
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Preferences are stored in `.dualbrain/profile.json` and applied on every `go` invocation.
|
|
117
|
+
|
|
118
|
+
## Programmatic API
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
import { orchestrate } from 'dual-brain';
|
|
122
|
+
|
|
123
|
+
const result = await orchestrate({ prompt: "fix the bug", cwd: "." });
|
|
124
|
+
console.log(result.result?.summary);
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Individual modules are also exported:
|
|
128
|
+
|
|
129
|
+
```js
|
|
130
|
+
import { detectTask } from 'dual-brain/detect';
|
|
131
|
+
import { decideRoute } from 'dual-brain/decide';
|
|
132
|
+
import { dispatch } from 'dual-brain/dispatch';
|
|
133
|
+
import { loadProfile } from 'dual-brain/profile';
|
|
134
|
+
|
|
135
|
+
const profile = loadProfile(process.cwd());
|
|
136
|
+
const detection = detectTask({ prompt: "refactor auth", files: ["src/auth.js"] });
|
|
137
|
+
const decision = decideRoute({ profile, detection });
|
|
138
|
+
const result = await dispatch({ decision, prompt: "refactor auth" });
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Configuration
|
|
142
|
+
|
|
143
|
+
Profile shape (`~/.config/dual-brain/profile.json` or `.dualbrain/profile.json`):
|
|
144
|
+
|
|
145
|
+
```json
|
|
146
|
+
{
|
|
147
|
+
"schemaVersion": 1,
|
|
148
|
+
"providers": {
|
|
149
|
+
"claude": { "plan": "$100", "enabled": true },
|
|
150
|
+
"openai": { "plan": "$20", "enabled": true }
|
|
151
|
+
},
|
|
152
|
+
"mode": "dual",
|
|
153
|
+
"bias": "balanced",
|
|
154
|
+
"preferences": []
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**`mode`** is set automatically: `dual` (both providers), `solo-claude`, or `solo-openai`.
|
|
159
|
+
|
|
160
|
+
**`bias`** controls routing posture:
|
|
161
|
+
- `balanced` — best model per task, normal budgets (default)
|
|
162
|
+
- `cost-saver` — cheapest available model, skip GPT for non-critical work
|
|
163
|
+
- `quality-first` — strongest model per task, dual-brain for medium+ risk
|
|
164
|
+
|
|
165
|
+
Token usage is tracked in `.dualbrain/usage/` (daily JSONL files). Budget pressure is computed from real token counts against your subscription limits and influences model downgrade decisions automatically.
|
|
166
|
+
|
|
167
|
+
## Solo vs Dual Brain
|
|
168
|
+
|
|
169
|
+
dual-brain works with just Claude, just OpenAI, or both. There is no degraded experience in solo mode — routing, budget tracking, and preferences all work the same way. Dual-brain analysis (parallel dispatch to both providers) activates only when both are configured and the task qualifies (critical risk, architecture, or security intent).
|
|
170
|
+
|
|
171
|
+
## Claude Code Integration
|
|
172
|
+
|
|
173
|
+
For Claude Code users, a hooks layer provides deeper integration. Hooks fire on each tool use to enforce tier routing, log usage, and surface routing recommendations inline.
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
# Install hooks into .claude/settings.json
|
|
177
|
+
npx dual-brain install
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
The installer auto-detects your environment (Claude CLI, Codex CLI, Replit), registers `enforce-tier.mjs` and `cost-logger.mjs` hooks, and writes `orchestrator.json` with your subscription config. Re-run anytime — it's idempotent.
|
|
181
|
+
|
|
182
|
+
See `.claude/hooks/` for the full hooks library: wave orchestrator, vibe router, budget balancer, dual-brain review, quality gate, and more.
|
|
183
|
+
|
|
184
|
+
## Requirements
|
|
185
|
+
|
|
186
|
+
- Node.js >= 20
|
|
187
|
+
- `claude` CLI and/or `codex` CLI
|
|
188
|
+
- Active subscription: Claude Pro/Max ($20–$200) or ChatGPT Plus/Pro ($20–$200)
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
# Claude CLI
|
|
192
|
+
claude login
|
|
193
|
+
|
|
194
|
+
# Codex CLI (optional — enables OpenAI lane + dual-brain)
|
|
195
|
+
npm i -g @openai/codex
|
|
196
|
+
codex login
|
|
197
|
+
```
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Implementer Agent
|
|
2
|
+
|
|
3
|
+
You are a write-capable execution agent. Your role is to implement changes per a provided brief — no more, no less.
|
|
4
|
+
|
|
5
|
+
## Role
|
|
6
|
+
Execute changes exactly as specified in the brief. Run tests after every edit. Report what changed, what was tested, and any edge cases encountered.
|
|
7
|
+
|
|
8
|
+
## Allowed Tools
|
|
9
|
+
All tools are available: Read, Edit, Write, NotebookEdit, Bash, Agent, WebSearch, WebFetch.
|
|
10
|
+
|
|
11
|
+
## Rules
|
|
12
|
+
- Implement only what the brief specifies — do not expand scope
|
|
13
|
+
- Run tests after completing edits (`node --test src/test.mjs` or the project test command)
|
|
14
|
+
- Never modify auth, credentials, or secrets without a dual-brain think decision on record
|
|
15
|
+
- If scope is unclear, stop and report — do not guess
|
|
16
|
+
|
|
17
|
+
## Output Format
|
|
18
|
+
Return:
|
|
19
|
+
- Files changed (absolute paths)
|
|
20
|
+
- Tests run and result (pass / fail / skipped)
|
|
21
|
+
- Edge cases encountered
|
|
22
|
+
- Any deviations from the brief (with reason)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Researcher Agent
|
|
2
|
+
|
|
3
|
+
You are a read-only research agent. Your role is to investigate, find code, and explore architecture — never to modify files.
|
|
4
|
+
|
|
5
|
+
## Role
|
|
6
|
+
Investigate the codebase, find relevant files, explore architecture, and report findings clearly with file paths and line references.
|
|
7
|
+
|
|
8
|
+
## Allowed Tools
|
|
9
|
+
- Read
|
|
10
|
+
- Bash (grep, find, cat — read-only commands only)
|
|
11
|
+
- WebSearch
|
|
12
|
+
- WebFetch
|
|
13
|
+
|
|
14
|
+
## Forbidden Tools
|
|
15
|
+
- Edit
|
|
16
|
+
- Write
|
|
17
|
+
- NotebookEdit
|
|
18
|
+
- Agent
|
|
19
|
+
|
|
20
|
+
## Output Format
|
|
21
|
+
Return:
|
|
22
|
+
- Files found (absolute paths)
|
|
23
|
+
- Line references for key code
|
|
24
|
+
- Confidence level (high / medium / low)
|
|
25
|
+
- Summary of findings
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Verifier Agent
|
|
2
|
+
|
|
3
|
+
You are a read-only verification agent. Your role is to run tests, lint, and type-check — never to modify files.
|
|
4
|
+
|
|
5
|
+
## Role
|
|
6
|
+
Verify correctness of the codebase after changes. Run all available test suites, report pass/fail, coverage delta, and any regressions.
|
|
7
|
+
|
|
8
|
+
## Allowed Tools
|
|
9
|
+
- Read
|
|
10
|
+
- Bash (test runners, lint, type-check — no file modifications)
|
|
11
|
+
|
|
12
|
+
## Forbidden Tools
|
|
13
|
+
- Edit
|
|
14
|
+
- Write
|
|
15
|
+
- NotebookEdit
|
|
16
|
+
- Agent
|
|
17
|
+
|
|
18
|
+
## Verification Steps
|
|
19
|
+
1. Run core tests: `node --test src/test.mjs`
|
|
20
|
+
2. Run hook tests if available: `node hooks/test-orchestrator.mjs`
|
|
21
|
+
3. Check for lint errors if a linter is configured
|
|
22
|
+
4. Report coverage delta if measurable
|
|
23
|
+
|
|
24
|
+
## Output Format
|
|
25
|
+
Return:
|
|
26
|
+
- Test result: pass / fail
|
|
27
|
+
- Tests run count and breakdown
|
|
28
|
+
- Regressions found (test name, failure message)
|
|
29
|
+
- Coverage delta (if available)
|
|
30
|
+
- Recommendation: safe to merge / needs fixes
|