daedalus-cli 0.4.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.
Files changed (144) hide show
  1. package/Daedalus.bat +18 -0
  2. package/LICENSE +21 -0
  3. package/README.md +254 -0
  4. package/dist/agents/agent.d.ts +10 -0
  5. package/dist/agents/agent.d.ts.map +1 -0
  6. package/dist/agents/agent.js +3 -0
  7. package/dist/agents/agent.js.map +1 -0
  8. package/dist/agents/orchestrator.d.ts +18 -0
  9. package/dist/agents/orchestrator.d.ts.map +1 -0
  10. package/dist/agents/orchestrator.js +171 -0
  11. package/dist/agents/orchestrator.js.map +1 -0
  12. package/dist/agents/roles.d.ts +14 -0
  13. package/dist/agents/roles.d.ts.map +1 -0
  14. package/dist/agents/roles.js +126 -0
  15. package/dist/agents/roles.js.map +1 -0
  16. package/dist/config/index.d.ts +485 -0
  17. package/dist/config/index.d.ts.map +1 -0
  18. package/dist/config/index.js +237 -0
  19. package/dist/config/index.js.map +1 -0
  20. package/dist/highlight.d.ts +4 -0
  21. package/dist/highlight.d.ts.map +1 -0
  22. package/dist/highlight.js +42 -0
  23. package/dist/highlight.js.map +1 -0
  24. package/dist/index.d.ts +3 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +1386 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/indexing/fts.d.ts +40 -0
  29. package/dist/indexing/fts.d.ts.map +1 -0
  30. package/dist/indexing/fts.js +121 -0
  31. package/dist/indexing/fts.js.map +1 -0
  32. package/dist/indexing/indexer.d.ts +22 -0
  33. package/dist/indexing/indexer.d.ts.map +1 -0
  34. package/dist/indexing/indexer.js +518 -0
  35. package/dist/indexing/indexer.js.map +1 -0
  36. package/dist/onboarding/wizard.d.ts +2 -0
  37. package/dist/onboarding/wizard.d.ts.map +1 -0
  38. package/dist/onboarding/wizard.js +231 -0
  39. package/dist/onboarding/wizard.js.map +1 -0
  40. package/dist/router/health.d.ts +6 -0
  41. package/dist/router/health.d.ts.map +1 -0
  42. package/dist/router/health.js +74 -0
  43. package/dist/router/health.js.map +1 -0
  44. package/dist/router/index.d.ts +33 -0
  45. package/dist/router/index.d.ts.map +1 -0
  46. package/dist/router/index.js +214 -0
  47. package/dist/router/index.js.map +1 -0
  48. package/dist/router/rate-limiter.d.ts +7 -0
  49. package/dist/router/rate-limiter.d.ts.map +1 -0
  50. package/dist/router/rate-limiter.js +36 -0
  51. package/dist/router/rate-limiter.js.map +1 -0
  52. package/dist/router/types.d.ts +81 -0
  53. package/dist/router/types.d.ts.map +1 -0
  54. package/dist/router/types.js +3 -0
  55. package/dist/router/types.js.map +1 -0
  56. package/dist/session/jsonl.d.ts +20 -0
  57. package/dist/session/jsonl.d.ts.map +1 -0
  58. package/dist/session/jsonl.js +61 -0
  59. package/dist/session/jsonl.js.map +1 -0
  60. package/dist/session/manager.d.ts +42 -0
  61. package/dist/session/manager.d.ts.map +1 -0
  62. package/dist/session/manager.js +184 -0
  63. package/dist/session/manager.js.map +1 -0
  64. package/dist/session/memory.d.ts +23 -0
  65. package/dist/session/memory.d.ts.map +1 -0
  66. package/dist/session/memory.js +88 -0
  67. package/dist/session/memory.js.map +1 -0
  68. package/dist/session/sqlite.d.ts +59 -0
  69. package/dist/session/sqlite.d.ts.map +1 -0
  70. package/dist/session/sqlite.js +174 -0
  71. package/dist/session/sqlite.js.map +1 -0
  72. package/dist/tools/builtin/delegation.d.ts +17 -0
  73. package/dist/tools/builtin/delegation.d.ts.map +1 -0
  74. package/dist/tools/builtin/delegation.js +85 -0
  75. package/dist/tools/builtin/delegation.js.map +1 -0
  76. package/dist/tools/builtin/diff-ui.d.ts +21 -0
  77. package/dist/tools/builtin/diff-ui.d.ts.map +1 -0
  78. package/dist/tools/builtin/diff-ui.js +211 -0
  79. package/dist/tools/builtin/diff-ui.js.map +1 -0
  80. package/dist/tools/builtin/files.d.ts +29 -0
  81. package/dist/tools/builtin/files.d.ts.map +1 -0
  82. package/dist/tools/builtin/files.js +286 -0
  83. package/dist/tools/builtin/files.js.map +1 -0
  84. package/dist/tools/builtin/git.d.ts +7 -0
  85. package/dist/tools/builtin/git.d.ts.map +1 -0
  86. package/dist/tools/builtin/git.js +11 -0
  87. package/dist/tools/builtin/git.js.map +1 -0
  88. package/dist/tools/builtin/indexing.d.ts +22 -0
  89. package/dist/tools/builtin/indexing.d.ts.map +1 -0
  90. package/dist/tools/builtin/indexing.js +159 -0
  91. package/dist/tools/builtin/indexing.js.map +1 -0
  92. package/dist/tools/builtin/project-config.d.ts +17 -0
  93. package/dist/tools/builtin/project-config.d.ts.map +1 -0
  94. package/dist/tools/builtin/project-config.js +66 -0
  95. package/dist/tools/builtin/project-config.js.map +1 -0
  96. package/dist/tools/builtin/terminal.d.ts +7 -0
  97. package/dist/tools/builtin/terminal.d.ts.map +1 -0
  98. package/dist/tools/builtin/terminal.js +99 -0
  99. package/dist/tools/builtin/terminal.js.map +1 -0
  100. package/dist/tools/builtin/todo.d.ts +20 -0
  101. package/dist/tools/builtin/todo.d.ts.map +1 -0
  102. package/dist/tools/builtin/todo.js +36 -0
  103. package/dist/tools/builtin/todo.js.map +1 -0
  104. package/dist/tools/builtin/web.d.ts +10 -0
  105. package/dist/tools/builtin/web.d.ts.map +1 -0
  106. package/dist/tools/builtin/web.js +67 -0
  107. package/dist/tools/builtin/web.js.map +1 -0
  108. package/dist/tools/daedalus-spinner.d.ts +29 -0
  109. package/dist/tools/daedalus-spinner.d.ts.map +1 -0
  110. package/dist/tools/daedalus-spinner.js +77 -0
  111. package/dist/tools/daedalus-spinner.js.map +1 -0
  112. package/dist/tools/definitions.d.ts +5 -0
  113. package/dist/tools/definitions.d.ts.map +1 -0
  114. package/dist/tools/definitions.js +296 -0
  115. package/dist/tools/definitions.js.map +1 -0
  116. package/dist/tools/executor.d.ts +4 -0
  117. package/dist/tools/executor.d.ts.map +1 -0
  118. package/dist/tools/executor.js +86 -0
  119. package/dist/tools/executor.js.map +1 -0
  120. package/dist/tools/mcp/http.d.ts +23 -0
  121. package/dist/tools/mcp/http.d.ts.map +1 -0
  122. package/dist/tools/mcp/http.js +200 -0
  123. package/dist/tools/mcp/http.js.map +1 -0
  124. package/dist/tools/mcp/registry.d.ts +16 -0
  125. package/dist/tools/mcp/registry.d.ts.map +1 -0
  126. package/dist/tools/mcp/registry.js +92 -0
  127. package/dist/tools/mcp/registry.js.map +1 -0
  128. package/dist/tools/mcp/stdio.d.ts +26 -0
  129. package/dist/tools/mcp/stdio.d.ts.map +1 -0
  130. package/dist/tools/mcp/stdio.js +157 -0
  131. package/dist/tools/mcp/stdio.js.map +1 -0
  132. package/dist/tools/mcp/tool-executor.d.ts +3 -0
  133. package/dist/tools/mcp/tool-executor.d.ts.map +1 -0
  134. package/dist/tools/mcp/tool-executor.js +23 -0
  135. package/dist/tools/mcp/tool-executor.js.map +1 -0
  136. package/dist/tools/mcp/types.d.ts +26 -0
  137. package/dist/tools/mcp/types.d.ts.map +1 -0
  138. package/dist/tools/mcp/types.js +3 -0
  139. package/dist/tools/mcp/types.js.map +1 -0
  140. package/dist/types.d.ts +58 -0
  141. package/dist/types.d.ts.map +1 -0
  142. package/dist/types.js +3 -0
  143. package/dist/types.js.map +1 -0
  144. package/package.json +63 -0
package/Daedalus.bat ADDED
@@ -0,0 +1,18 @@
1
+ @echo off
2
+ chcp 65001 >nul
3
+ title Daedalus - Local-First Coding CLI
4
+ color 0A
5
+
6
+ echo +------------------------------------------+
7
+ echo ^| Launching Daedalus CLI... ^|
8
+ echo +------------------------------------------+
9
+ echo.
10
+
11
+ node "%~dp0dist/index.js" %*
12
+
13
+ if errorlevel 1 (
14
+ echo.
15
+ echo [ERROR] Daedalus exited with code %errorlevel%
16
+ echo Make sure it's installed globally: npm install -g daedalus-cli
17
+ pause
18
+ )
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 bgill55_art
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,254 @@
1
+ # Daedalus
2
+
3
+ **Local-first coding CLI with an embedded model router, multi-agent orchestration, and codebase indexing.**
4
+
5
+ Daedalus is a standalone terminal-based AI coding assistant that runs entirely on your machine. It connects to local LLM servers (LM Studio, Ollama, llama.cpp, vLLM) or remote providers (OpenAI, Groq, OpenRouter, Anthropic), routes requests intelligently, and gives your AI agent access to your file system, terminal, git, web search, and codebase indexing — all from your command line.
6
+
7
+ ```text
8
+ ╭─ ⬡ You ───────────────────────────────────────────────╮
9
+ │ refactor the auth middleware to use async/await │
10
+ ╰────────────────────────────────────────────────────────╯
11
+
12
+ ╭─ ◇ Daedalus ───────────────────────────────────────────╮
13
+ │ Let me look at the current auth middleware... │
14
+ │ I'll refactor it to use async/await pattern. │
15
+ ╰────────────────────────────────────────────────────────╯ ~132t · 3.2s
16
+ ```
17
+
18
+ ---
19
+
20
+ ## Features
21
+
22
+ - **Local-first** — Works with local LLMs (LM Studio, Ollama, llama.cpp, vLLM) or remote APIs
23
+ - **Embedded model router** — Priority, round-robin, or fastest-response routing across multiple models
24
+ - **Multi-agent orchestration** — Spawns sub-agents (planner, coder, reviewer, debugger, researcher) for complex tasks
25
+ - **Codebase indexing** — FTS5-powered symbol search, definitions, and call-graph references (TS/JS, Python, Go, Rust)
26
+ - **File system tools** — Read, write, patch with interactive diff UI, search (ripgrep + native fallback)
27
+ - **Terminal access** — Cross-platform shell execution (bash/cmd) with timeout and abort
28
+ - **Git integration** — Status, diff, stage-all-and-commit, undo last patch
29
+ - **Session management** — SQLite-backed conversation history with save/load/export
30
+ - **Project memory** — Persist facts and conventions that auto-inject into every turn
31
+ - **MCP support** — Connect Model Context Protocol servers (stdio and HTTP/SSE)
32
+ - **Web tools** — DuckDuckGo search and URL fetching (no API key needed)
33
+ - **Visual chat UI** — Bordered message blocks, tab completion, syntax-highlighted code blocks
34
+ - **Configurable** — Per-project settings (test commands, auto-run), full daedalus config
35
+ - **Windows + Unix** — Full cross-platform support
36
+
37
+ ---
38
+
39
+ ## Quick Start
40
+
41
+ ### Prerequisites
42
+
43
+ - Node.js 20+
44
+ - A local LLM server (recommended) or a remote API key
45
+
46
+ ### Install
47
+
48
+ ```bash
49
+ npm install -g daedalus-cli
50
+ ```
51
+
52
+ Or run directly from source:
53
+
54
+ ```bash
55
+ git clone <repo-url>
56
+ cd daedalus
57
+ npm install
58
+ npm run build
59
+ ```
60
+
61
+ ### Launch
62
+
63
+ ```bash
64
+ daedalus
65
+ ```
66
+
67
+ On first run, Daedalus will scan for local LLM servers and guide you through setup. If none are found, it prompts you to configure a remote provider (OpenAI, Groq, OpenRouter, Anthropic, or custom).
68
+
69
+ ---
70
+
71
+ ## Usage
72
+
73
+ Once inside the REPL, type `?` or `help` for the full command reference.
74
+
75
+ ### Commands
76
+
77
+ | Command | Description |
78
+ |---------|-------------|
79
+ | `/add <file>` | Add file to active context |
80
+ | `/remove <file>` | Remove file from context |
81
+ | `/context` | Show active file context |
82
+ | `/clear` | Clear conversation history |
83
+ | `/commit [message]` | Stage all and commit changes |
84
+ | `/undo` | Revert last file patch |
85
+ | `/test [iterations]` | Run tests and auto-fix failures |
86
+ | `/index` | Index codebase for symbol search |
87
+ | `/find <query>` | Fuzzy-search indexed symbols |
88
+ | `/refs <symbol>` | Find symbol references (callers) |
89
+ | `/def <symbol>` | Get symbol definition |
90
+ | `/project` | View or set project config |
91
+ | `/session list\|load\|new\|delete` | Manage chat sessions |
92
+ | `/models` | List available models |
93
+ | `/tools` | List all tools |
94
+ | `/doctor` | Diagnose local server connections |
95
+ | `/onboard` | Re-run setup wizard |
96
+ | `/spawn <role> <task>` | Spawn a sub-agent |
97
+ | `/orchestrate <goal>` | Run multi-agent orchestration |
98
+ | `?` / `help` | Show command reference |
99
+ | `exit` / `quit` | Save and quit |
100
+
101
+ ### Tab Completion
102
+
103
+ Start typing a command and press Tab — Daedalus auto-completes it:
104
+
105
+ ```
106
+ ⬡ › /fi[TAB]
107
+ ⬡ › /find
108
+ ```
109
+
110
+ ---
111
+
112
+ ## Configuration
113
+
114
+ Daedalus stores its configuration at `~/.daedalus/config.json`. Key sections:
115
+
116
+ ```json
117
+ {
118
+ "router": {
119
+ "strategy": "priority",
120
+ "chain": [
121
+ {
122
+ "name": "local",
123
+ "endpoint": "http://localhost:1234/v1",
124
+ "model": "auto",
125
+ "enabled": true,
126
+ "priority": 1,
127
+ "maxTokens": 8192
128
+ }
129
+ ]
130
+ },
131
+ "indexing": {
132
+ "enabled": true,
133
+ "exclude": ["node_modules", "dist", ".git"]
134
+ },
135
+ "ui": {
136
+ "showTokens": true
137
+ }
138
+ }
139
+ ```
140
+
141
+ ### Router Strategies
142
+
143
+ - **`priority`** (default) — Picks the healthy model with lowest priority number
144
+ - **`round-robin`** — Cycles through healthy models evenly
145
+ - **`fastest`** — Picks the model with the lowest cached response time
146
+
147
+ ### Per-Project Config
148
+
149
+ Each project can have its own settings at `~/.daedalus/config/<project-hash>.json`:
150
+
151
+ ```json
152
+ {
153
+ "testCommand": "npm test",
154
+ "buildCommand": "npm run build",
155
+ "lintCommand": "npm run lint",
156
+ "devCommand": "npm run dev"
157
+ }
158
+ ```
159
+
160
+ Configured via `/project set <key> <value>`.
161
+
162
+ ---
163
+
164
+ ## Architecture
165
+
166
+ ```text
167
+ src/
168
+ ├── index.ts # CLI entry point, REPL, command dispatch
169
+ ├── types.ts # Shared type definitions
170
+ ├── highlight.ts # Syntax highlighting for code blocks
171
+ ├── config/ # Configuration loading, schema, discovery
172
+ │ └── index.ts
173
+ ├── router/ # Model routing engine
174
+ │ ├── index.ts # LocalRouter: routing, streaming, completion
175
+ │ ├── types.ts # Router types
176
+ │ ├── health.ts # Model health checks
177
+ │ └── rate-limiter.ts # Token-bucket rate limiter
178
+ ├── session/ # Session persistence
179
+ │ ├── manager.ts # Session orchestration
180
+ │ ├── sqlite.ts # SQLite CRUD
181
+ │ ├── memory.ts # Project facts & conventions
182
+ │ └── jsonl.ts # JSONL import/export
183
+ ├── agents/ # Multi-agent system
184
+ │ ├── agent.ts # Agent interface
185
+ │ ├── roles.ts # Role definitions (coder, reviewer, etc.)
186
+ │ └── orchestrator.ts # Orchestration engine
187
+ ├── tools/ # Tool system
188
+ │ ├── definitions.ts # 16 built-in tool definitions
189
+ │ ├── executor.ts # Tool execution engine
190
+ │ ├── daedalus-spinner.ts # Terminal spinner
191
+ │ ├── builtin/ # Built-in tool implementations
192
+ │ │ ├── files.ts # File read/write/patch/search
193
+ │ │ ├── terminal.ts # Shell execution
194
+ │ │ ├── git.ts # Git diff/status
195
+ │ │ ├── web.ts # Web search/fetch
196
+ │ │ ├── todo.ts # Task management
197
+ │ │ ├── delegation.ts # Sub-agent delegation
198
+ │ │ ├── indexing.ts # Codebase indexing tools
199
+ │ │ ├── diff-ui.ts # Interactive diff viewer
200
+ │ │ └── project-config.ts
201
+ │ └── mcp/ # MCP transport
202
+ │ ├── registry.ts # MCP server manager
203
+ │ ├── stdio.ts # stdio transport
204
+ │ ├── http.ts # HTTP/SSE transport
205
+ │ └── tool-executor.ts
206
+ ├── indexing/ # Codebase indexing
207
+ │ ├── fts.ts # FTS5 database layer
208
+ │ └── indexer.ts # File crawler & language parsers
209
+ └── onboarding/ # Setup wizard
210
+ └── wizard.ts
211
+ ```
212
+
213
+ ---
214
+
215
+ ## Development
216
+
217
+ ```bash
218
+ # Run in dev mode (hot reload)
219
+ npm run dev
220
+
221
+ # Run directly
222
+ npm start
223
+
224
+ # Build
225
+ npm run build
226
+
227
+ # Type check
228
+ npx tsc --noEmit
229
+
230
+ # Test
231
+ npm test
232
+
233
+ # Lint
234
+ npm run lint
235
+ ```
236
+
237
+ ---
238
+
239
+ ## Why Daedalus?
240
+
241
+ Daedalus is built for developers who want AI assistance without:
242
+ - Sending their code to third-party servers
243
+ - Paying per-token for every interaction
244
+ - Being locked into a single provider
245
+ - Losing their conversation history between sessions
246
+ - Having limited tool access
247
+
248
+ It's for local-first, private, customizable AI coding — with the power to grow with you.
249
+
250
+ ---
251
+
252
+ ## License
253
+
254
+ MIT
@@ -0,0 +1,10 @@
1
+ export interface Agent {
2
+ /**
3
+ * Run the agent on a given goal.
4
+ * @param goal The high-level task description.
5
+ * @param context Optional additional context (e.g., list of active files).
6
+ * @returns A string summary of what the agent accomplished.
7
+ */
8
+ run(goal: string, context?: string): Promise<string>;
9
+ }
10
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/agents/agent.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,KAAK;IACpB;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACtD"}
@@ -0,0 +1,3 @@
1
+ // Base Agent interface for Daedalus sub-agents
2
+ export {};
3
+ //# sourceMappingURL=agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/agents/agent.ts"],"names":[],"mappings":"AAAA,+CAA+C"}
@@ -0,0 +1,18 @@
1
+ import { LocalRouter } from '../router/index.js';
2
+ import { ToolContext, ChatMessage } from '../types.js';
3
+ export declare class Orchestrator {
4
+ private router;
5
+ private messages;
6
+ private toolContext;
7
+ private results;
8
+ constructor(router: LocalRouter, messages: ChatMessage[], toolContext: ToolContext);
9
+ run(goal: string): Promise<string>;
10
+ private createPlan;
11
+ private executePlan;
12
+ private parseDelegationTasks;
13
+ private delegateTask;
14
+ private runAgent;
15
+ private executeOpenAIToolCalls;
16
+ private synthesize;
17
+ }
18
+ //# sourceMappingURL=orchestrator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../../src/agents/orchestrator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAIjD,OAAO,EAAE,WAAW,EAAY,WAAW,EAAE,MAAM,aAAa,CAAC;AAgBjE,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,QAAQ,CAAgB;IAChC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,OAAO,CAAqB;gBAExB,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,WAAW,EAAE,WAAW;IAM5E,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;YAa1B,UAAU;YAiDV,WAAW;IAQzB,OAAO,CAAC,oBAAoB;YAoCd,YAAY;YAiBZ,QAAQ;YAsDR,sBAAsB;IASpC,OAAO,CAAC,UAAU;CAWnB"}
@@ -0,0 +1,171 @@
1
+ // Multi-agent orchestrator - coordinates delegation and synthesis
2
+ import { BUILTIN_TOOLS } from '../tools/definitions.js';
3
+ import { executeToolCalls } from '../tools/executor.js';
4
+ import { getAgentRole, filterToolsForRole } from './roles.js';
5
+ export class Orchestrator {
6
+ router;
7
+ messages;
8
+ toolContext;
9
+ results = [];
10
+ constructor(router, messages, toolContext) {
11
+ this.router = router;
12
+ this.messages = messages;
13
+ this.toolContext = toolContext;
14
+ }
15
+ async run(goal) {
16
+ this.results = [];
17
+ // Create initial plan
18
+ const plan = await this.createPlan(goal);
19
+ // Execute plan by delegating to agents
20
+ await this.executePlan(plan);
21
+ // Synthesize results
22
+ return this.synthesize(goal);
23
+ }
24
+ async createPlan(goal) {
25
+ const plannerRole = getAgentRole('planner');
26
+ const tools = filterToolsForRole(BUILTIN_TOOLS, 'planner');
27
+ const systemPrompt = plannerRole.systemPrompt;
28
+ const messages = [
29
+ { role: 'system', content: systemPrompt },
30
+ { role: 'user', content: `Create a plan for: ${goal}\n\nContext:\n${this.toolContext.activeFiles.size > 0 ? 'Files in context: ' + Array.from(this.toolContext.activeFiles.values()).join(', ') : 'No files in context'}` },
31
+ ];
32
+ const completion = await this.router.chat.completions.create({
33
+ model: 'auto',
34
+ messages: messages,
35
+ temperature: plannerRole.temperature ?? 0.2,
36
+ tools,
37
+ tool_choice: 'auto',
38
+ });
39
+ const assistantMessage = completion.choices[0].message;
40
+ const toolCalls = assistantMessage.tool_calls;
41
+ if (toolCalls && toolCalls.length > 0) {
42
+ // Push the assistant turn with its tool calls
43
+ messages.push(assistantMessage);
44
+ // Execute tool calls and push results back into the conversation
45
+ const results = await this.executeOpenAIToolCalls(toolCalls);
46
+ for (const result of results) {
47
+ messages.push({
48
+ role: 'tool',
49
+ content: result.content,
50
+ tool_call_id: result.toolCallId,
51
+ });
52
+ }
53
+ // Ask the planner for a final text summary now that tools have run
54
+ const followUp = await this.router.chat.completions.create({
55
+ model: 'auto',
56
+ messages,
57
+ temperature: plannerRole.temperature ?? 0.2,
58
+ tools,
59
+ tool_choice: 'none', // No more tool calls — just produce the plan text
60
+ });
61
+ return followUp.choices[0].message.content || 'No plan generated';
62
+ }
63
+ return assistantMessage.content || 'No plan generated';
64
+ }
65
+ async executePlan(plan) {
66
+ const delegationTasks = this.parseDelegationTasks(plan);
67
+ for (const task of delegationTasks) {
68
+ await this.delegateTask(task);
69
+ }
70
+ }
71
+ parseDelegationTasks(plan) {
72
+ const tasks = [];
73
+ const lines = plan.split('\n');
74
+ let currentRole = '';
75
+ let currentGoal = '';
76
+ for (const line of lines) {
77
+ const roleMatch = line.match(/(?:delegate to|have|assign to)\s+(planner|coder|reviewer|debugger|researcher)/i);
78
+ if (roleMatch) {
79
+ if (currentRole && currentGoal) {
80
+ tasks.push({ goal: currentGoal, context: '', role: currentRole });
81
+ }
82
+ currentRole = roleMatch[1].toLowerCase();
83
+ currentGoal = line.replace(roleMatch[0], '').trim();
84
+ }
85
+ else if (currentRole && line.trim()) {
86
+ currentGoal += ' ' + line.trim();
87
+ }
88
+ }
89
+ if (currentRole && currentGoal) {
90
+ tasks.push({ goal: currentGoal, context: '', role: currentRole });
91
+ }
92
+ // If no explicit delegation found, default to coder for implementation tasks
93
+ if (tasks.length === 0) {
94
+ tasks.push({
95
+ goal: plan,
96
+ context: `Files in context: ${Array.from(this.toolContext.activeFiles.values()).join(', ')}`,
97
+ role: 'coder'
98
+ });
99
+ }
100
+ return tasks;
101
+ }
102
+ async delegateTask(task) {
103
+ const role = getAgentRole(task.role);
104
+ console.log(`\n🤝 Delegating to ${role.name}: ${task.goal.slice(0, 80)}...`);
105
+ const tools = filterToolsForRole(BUILTIN_TOOLS, task.role);
106
+ const result = await this.runAgent(role, task.goal, task.context, tools);
107
+ this.results.push({
108
+ role: task.role,
109
+ goal: task.goal,
110
+ summary: result,
111
+ success: !result.includes('Error') && !result.includes('Failed'),
112
+ });
113
+ console.log(`✅ ${role.name} completed`);
114
+ }
115
+ async runAgent(role, goal, context, tools) {
116
+ const messages = [
117
+ { role: 'system', content: role.systemPrompt },
118
+ { role: 'user', content: `${context}\n\nTask: ${goal}` },
119
+ ];
120
+ let turns = 0;
121
+ const maxTurns = role.maxTurns ?? 10;
122
+ while (turns < maxTurns) {
123
+ const completion = await this.router.chat.completions.create({
124
+ model: 'auto',
125
+ messages: messages,
126
+ temperature: role.temperature ?? 0.1,
127
+ tools,
128
+ tool_choice: 'auto',
129
+ });
130
+ const message = completion.choices[0].message;
131
+ messages.push(message);
132
+ if (message.tool_calls && message.tool_calls.length > 0) {
133
+ const results = await executeToolCalls(message.tool_calls.map((tc) => ({
134
+ id: tc.id,
135
+ type: 'function',
136
+ function: { name: tc.function.name, arguments: tc.function.arguments },
137
+ })), this.toolContext);
138
+ for (const result of results) {
139
+ messages.push({
140
+ role: 'tool',
141
+ content: result.content,
142
+ tool_call_id: result.toolCallId,
143
+ });
144
+ }
145
+ turns++;
146
+ continue;
147
+ }
148
+ // No tool calls - agent is done
149
+ return message.content || 'Agent completed without response';
150
+ }
151
+ return 'Agent reached max turns';
152
+ }
153
+ async executeOpenAIToolCalls(toolCalls) {
154
+ const tc = toolCalls.map((rawTc) => ({
155
+ id: rawTc.id,
156
+ type: 'function',
157
+ function: { name: rawTc.function.name, arguments: rawTc.function.arguments },
158
+ }));
159
+ return executeToolCalls(tc, this.toolContext);
160
+ }
161
+ synthesize(goal) {
162
+ let output = `## Orchestration Complete: ${goal}\n\n`;
163
+ for (const result of this.results) {
164
+ const status = result.success ? '✅' : '❌';
165
+ output += `${status} **${result.role}**: ${result.goal.slice(0, 100)}\n`;
166
+ output += ` ${result.summary.slice(0, 200)}\n\n`;
167
+ }
168
+ return output;
169
+ }
170
+ }
171
+ //# sourceMappingURL=orchestrator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestrator.js","sourceRoot":"","sources":["../../src/agents/orchestrator.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAGlE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAa,MAAM,YAAY,CAAC;AAiBzE,MAAM,OAAO,YAAY;IACf,MAAM,CAAc;IACpB,QAAQ,CAAgB;IACxB,WAAW,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0 +1,14 @@
1
+ import type { ToolDefinition } from '../tools/definitions.js';
2
+ export interface AgentRole {
3
+ name: string;
4
+ description: string;
5
+ systemPrompt: string;
6
+ allowedTools: string[];
7
+ canDelegate: boolean;
8
+ maxTurns?: number;
9
+ temperature?: number;
10
+ }
11
+ export declare const AGENT_ROLES: Record<string, AgentRole>;
12
+ export declare function getAgentRole(name: string): AgentRole;
13
+ export declare function filterToolsForRole(tools: ToolDefinition[], roleName: string): ToolDefinition[];
14
+ //# sourceMappingURL=roles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roles.d.ts","sourceRoot":"","sources":["../../src/agents/roles.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAE9D,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAqHjD,CAAC;AAGF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAEpD;AAGD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,cAAc,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,EAAE,CAI9F"}
@@ -0,0 +1,126 @@
1
+ // Agent role definitions
2
+ export const AGENT_ROLES = {
3
+ orchestrator: {
4
+ name: 'orchestrator',
5
+ description: 'Plans, delegates, and coordinates multi-agent workflows',
6
+ systemPrompt: `You are an Orchestrator Agent. Your job is to break down complex tasks into subtasks and delegate them to specialized agents.
7
+
8
+ AVAILABLE SUB-AGENTS:
9
+ - planner: Break down vague tasks into concrete, ordered subtasks
10
+ - coder: Implement changes, write/edit files, fix bugs
11
+ - reviewer: Code review: correctness, security, style, tests
12
+ - debugger: Reproduce, isolate, fix bugs; add logging; bisect
13
+ - researcher: Web search, docs lookup, API exploration
14
+
15
+ WORKFLOW:
16
+ 1. Analyze the user's request
17
+ 2. Create a todo list with todo tool
18
+ 3. Delegate subtasks to appropriate agents using delegate_task tool
19
+ 4. Collect and synthesize results
20
+ 5. Present final outcome to user
21
+
22
+ Always use the todo tool to track progress. Delegate liberally - agents run in parallel.`,
23
+ allowedTools: ['todo', 'delegate_task', 'read_file', 'search_files', 'list_files', 'web_search'],
24
+ canDelegate: true,
25
+ temperature: 0.2,
26
+ },
27
+ planner: {
28
+ name: 'planner',
29
+ description: 'Breaks down vague tasks into concrete, ordered subtasks',
30
+ systemPrompt: `You are a Planning Agent. Your job is to analyze a task and create a clear, actionable plan.
31
+
32
+ OUTPUT: A todo list with specific, ordered subtasks. Each task should be:
33
+ - Concrete and verifiable
34
+ - Assigned to an appropriate agent (coder, reviewer, debugger, researcher)
35
+ - Sized to be completable in one agent session
36
+
37
+ Use the todo tool to create the plan. Do not implement - only plan.`,
38
+ allowedTools: ['todo', 'read_file', 'search_files', 'list_files', 'terminal', 'web_search'],
39
+ canDelegate: false,
40
+ temperature: 0.2,
41
+ },
42
+ coder: {
43
+ name: 'coder',
44
+ description: 'Implements changes, writes/edits files, fixes bugs',
45
+ systemPrompt: `You are a Coder Agent. Your job is to implement code changes based on the plan.
46
+
47
+ CAPABILITIES:
48
+ - Read and understand existing code
49
+ - Write new files and edit existing ones
50
+ - Run tests, builds, linters
51
+ - Use git for version control
52
+
53
+ GUIDELINES:
54
+ - Make minimal, focused changes
55
+ - Follow existing code style and patterns
56
+ - Write tests for new functionality
57
+ - Run tests to verify changes
58
+ - Commit with clear messages
59
+
60
+ Use tools: read_file, write_file, patch, search_files, terminal, git_diff, git_status, todo.`,
61
+ allowedTools: ['read_file', 'write_file', 'patch', 'search_files', 'list_files', 'terminal', 'git_diff', 'git_status', 'todo', 'web_search', 'fetch_url'],
62
+ canDelegate: false,
63
+ temperature: 0.1,
64
+ },
65
+ reviewer: {
66
+ name: 'reviewer',
67
+ description: 'Code review: correctness, security, style, tests',
68
+ systemPrompt: `You are a Code Reviewer Agent. Your job is to review code for quality, security, and correctness.
69
+
70
+ FOCUS AREAS:
71
+ - Correctness: Does the code do what it's supposed to?
72
+ - Security: No vulnerabilities, proper auth, input validation
73
+ - Style: Consistency with project conventions
74
+ - Tests: Adequate coverage, meaningful assertions
75
+ - Performance: No obvious bottlenecks
76
+
77
+ OUTPUT: A review summary with specific, actionable comments. Use todo tool to track review items.`,
78
+ allowedTools: ['read_file', 'search_files', 'list_files', 'terminal', 'git_diff', 'todo'],
79
+ canDelegate: false,
80
+ temperature: 0.1,
81
+ },
82
+ debugger: {
83
+ name: 'debugger',
84
+ description: 'Reproduces, isolates, and fixes bugs; adds logging; bisects',
85
+ systemPrompt: `You are a Debugger Agent. Your job is to find and fix bugs systematically.
86
+
87
+ PROCESS:
88
+ 1. Reproduce the issue (run tests, create test case)
89
+ 2. Isolate the root cause (add logging, bisect, analyze stack traces)
90
+ 3. Implement minimal fix
91
+ 4. Verify fix works and doesn't regress
92
+
93
+ TOOLS: read_file, write_file, patch, search_files, terminal, git_diff, git_status, todo.`,
94
+ allowedTools: ['read_file', 'write_file', 'patch', 'search_files', 'list_files', 'terminal', 'git_diff', 'git_status', 'todo'],
95
+ canDelegate: false,
96
+ temperature: 0.1,
97
+ },
98
+ researcher: {
99
+ name: 'researcher',
100
+ description: 'Web search, docs lookup, API exploration, unknowns',
101
+ systemPrompt: `You are a Research Agent. Your job is to gather information from external sources.
102
+
103
+ CAPABILITIES:
104
+ - Web search for technical information
105
+ - Fetch and parse documentation
106
+ - Explore APIs and libraries
107
+ - Summarize findings for other agents
108
+
109
+ OUTPUT: Concise summaries with source links. Use todo tool to track research questions.`,
110
+ allowedTools: ['web_search', 'fetch_url', 'read_file', 'search_files', 'list_files', 'todo'],
111
+ canDelegate: false,
112
+ temperature: 0.3,
113
+ },
114
+ };
115
+ // Get role by name, with fallback to coder
116
+ export function getAgentRole(name) {
117
+ return AGENT_ROLES[name] ?? AGENT_ROLES.coder;
118
+ }
119
+ // Filter tools for a specific role
120
+ export function filterToolsForRole(tools, roleName) {
121
+ const role = getAgentRole(roleName);
122
+ if (role.allowedTools.includes('*'))
123
+ return tools;
124
+ return tools.filter(t => role.allowedTools.includes(t.function.name));
125
+ }
126
+ //# sourceMappingURL=roles.js.map