@serkanalgur/opencode-nexus 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Serkan Algur
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,434 @@
1
+ <div align="center">
2
+
3
+ <img src="./assets/banner.svg" alt="OpenCode Nexus" width="100%" />
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@serkanalgur/opencode-nexus?style=flat-square&color=6366f1)](https://www.npmjs.com/package/@serkanalgur/opencode-nexus)
6
+ [![license](https://img.shields.io/npm/l/@serkanalgur/opencode-nexus?style=flat-square&color=8b5cf6)](https://github.com/serkanalgur/opencode-nexus/blob/main/LICENSE)
7
+ [![opencode](https://img.shields.io/badge/OpenCode-V2-6366f1?style=flat-square)](https://opencode.ai)
8
+ [![typescript](https://img.shields.io/badge/TypeScript-5.5+-3178c6?style=flat-square)](https://www.typescriptlang.org/)
9
+
10
+ **Adaptive Multi-Agent Orchestration with Cost Intelligence**
11
+
12
+ [Installation](#installation) • [Quick Start](#quick-start) • [Features](#features) • [Architecture](#architecture) • [Configuration](#configuration) • [API Reference](#api-reference) • [Development](#development) • [Contributing](#contributing)
13
+
14
+ </div>
15
+
16
+ ---
17
+
18
+ ## What is OpenCode Nexus?
19
+
20
+ OpenCode Nexus is a next-generation agent orchestration plugin for [OpenCode V2](https://opencode.ai) that introduces **adaptive multi-agent execution** with **cost-aware routing**, **real pub/sub communication**, **self-healing capabilities**, and **shared memory** between agents.
21
+
22
+ ### Why Nexus?
23
+
24
+ | Problem | Existing Solutions | Nexus Solution |
25
+ |---------|-------------------|----------------|
26
+ | Sequential bottleneck | Agents run one-by-one | **Dynamic DAG with true parallelism** |
27
+ | No agent communication | Agents operate in isolation | **Real pub/sub with topic routing** |
28
+ | Cost blindness | Same model for all tasks | **Intelligent cost-aware model selection** |
29
+ | No self-healing | Manual restart on crash | **Auto-respawn with context transfer** |
30
+ | Memory isolation | Each agent starts fresh | **Cross-agent shared memory store** |
31
+ | Fixed architecture | 19+ predetermined agents | **Dynamic spawning based on complexity** |
32
+
33
+ ---
34
+
35
+ ## Installation
36
+
37
+ ```bash
38
+ # Using npm
39
+ npm install -g @serkanalgur/opencode-nexus
40
+
41
+ # Using bun
42
+ bun add -g @serkanalgur/opencode-nexus
43
+
44
+ # Add to OpenCode config
45
+ opencode plugin @serkanalgur/opencode-nexus --global
46
+ ```
47
+
48
+ Or manually add to `~/.config/opencode/opencode.json`:
49
+
50
+ ```json
51
+ {
52
+ "plugins": ["@serkanalgur/opencode-nexus"]
53
+ }
54
+ ```
55
+
56
+ ---
57
+
58
+ ## Quick Start
59
+
60
+ ### 1. Basic Usage
61
+
62
+ ```typescript
63
+ import { NexusOrchestrator } from '@serkanalgur/opencode-nexus'
64
+
65
+ const orchestrator = new NexusOrchestrator({
66
+ budget: { maxTotalCost: 10.00 }
67
+ })
68
+
69
+ // Execute multiple tasks in parallel
70
+ const result = await orchestrator.execute({
71
+ tasks: [
72
+ {
73
+ id: 'task-1',
74
+ name: 'Implement auth',
75
+ description: 'Add JWT authentication',
76
+ requiredRole: 'coder',
77
+ complexity: { overall: 60, factors: { fileCount: 3, codeLines: 200, dependencyDepth: 2, domainKnowledge: 40, riskLevel: 'medium' } },
78
+ dependencies: [],
79
+ files: { include: ['src/auth/**'] },
80
+ priority: 'high',
81
+ status: 'pending'
82
+ },
83
+ {
84
+ id: 'task-2',
85
+ name: 'Write tests',
86
+ description: 'Add unit tests for auth',
87
+ requiredRole: 'tester',
88
+ complexity: { overall: 30, factors: { fileCount: 2, codeLines: 150, dependencyDepth: 1, domainKnowledge: 20, riskLevel: 'low' } },
89
+ dependencies: ['task-1'],
90
+ files: { include: ['tests/auth/**'] },
91
+ priority: 'normal',
92
+ status: 'pending'
93
+ }
94
+ ]
95
+ })
96
+
97
+ console.log(`Completed in ${result.totalDuration}ms, cost: $${result.totalCost}`)
98
+ ```
99
+
100
+ ### 2. Using Slash Commands
101
+
102
+ ```
103
+ /nexus status # Show orchestrator status
104
+ /nexus agents # List active agents
105
+ /nexus costs # Show cost breakdown
106
+ /nexus pause # Pause execution
107
+ /nexus resume # Resume execution
108
+ /nexus dashboard # Open web dashboard
109
+ ```
110
+
111
+ ### 3. Agent Communication
112
+
113
+ ```typescript
114
+ // Subscribe to topics
115
+ orchestrator.publish('architecture', {
116
+ from: 'architect',
117
+ type: 'decision-made',
118
+ payload: { decision: 'Use event sourcing', rationale: '...' },
119
+ topic: 'architecture',
120
+ metadata: { priority: 'high', requiresResponse: false }
121
+ })
122
+
123
+ // Send direct message
124
+ orchestrator.send('coder-1', {
125
+ from: 'reviewer',
126
+ type: 'review-completed',
127
+ payload: { approved: true, comments: [...] },
128
+ metadata: { priority: 'normal', requiresResponse: true }
129
+ })
130
+ ```
131
+
132
+ ---
133
+
134
+ ## Features
135
+
136
+ ### Dynamic DAG Execution
137
+
138
+ Unlike static dependency graphs, Nexus builds and modifies the DAG at runtime based on task outcomes.
139
+
140
+ ```typescript
141
+ // Tasks are automatically parallelized based on dependencies
142
+ const tasks = [
143
+ { id: 'schema', dependencies: [] }, // Runs immediately
144
+ { id: 'api', dependencies: ['schema'] }, // Waits for schema
145
+ { id: 'ui', dependencies: ['api'] }, // Waits for api
146
+ { id: 'docs', dependencies: ['api'] } // Parallel with ui!
147
+ ]
148
+ ```
149
+
150
+ ### Cost-Aware Routing
151
+
152
+ Every model selection considers cost vs quality tradeoffs.
153
+
154
+ ```typescript
155
+ const orchestrator = new NexusOrchestrator({
156
+ budget: {
157
+ maxTotalCost: 10.00,
158
+ maxCostPerTask: 1.00,
159
+ alertThreshold: 0.2 // Alert at 20% remaining
160
+ }
161
+ })
162
+
163
+ // Automatically selects optimal model based on:
164
+ // - Task complexity
165
+ // - Remaining budget
166
+ // - Required quality level
167
+ ```
168
+
169
+ ### Real Pub/Sub Communication
170
+
171
+ Agents communicate through a message broker, not direct calls.
172
+
173
+ ```typescript
174
+ // Topic-based pub/sub
175
+ orchestrator.publish('auth-decisions', {
176
+ from: 'architect',
177
+ type: 'decision-made',
178
+ payload: { approach: 'JWT with refresh tokens' }
179
+ })
180
+
181
+ // Direct messaging
182
+ orchestrator.send('coder', {
183
+ from: 'reviewer',
184
+ type: 'review-requested',
185
+ payload: { file: 'src/auth.ts', focus: 'security' }
186
+ })
187
+
188
+ // Fan-out to multiple agents
189
+ orchestrator.fanOut(
190
+ { from: 'architect', type: 'context-update', payload: { ... } },
191
+ ['coder', 'reviewer', 'tester']
192
+ )
193
+ ```
194
+
195
+ ### Self-Healing
196
+
197
+ Agents automatically recover from failures.
198
+
199
+ ```typescript
200
+ const orchestrator = new NexusOrchestrator({
201
+ selfHealing: {
202
+ enabled: true,
203
+ maxRetries: 3,
204
+ retryDelay: 1000,
205
+ backoffMultiplier: 2,
206
+ contextTransfer: true // Transfer partial results to new agent
207
+ }
208
+ })
209
+ ```
210
+
211
+ ### Shared Memory
212
+
213
+ Agents share context through a structured memory store.
214
+
215
+ ```typescript
216
+ // Set memory
217
+ orchestrator.setMemory('project', 'architecture', {
218
+ pattern: 'event-sourcing',
219
+ decision: 'Use for order service'
220
+ }, 'architect')
221
+
222
+ // Get memory
223
+ const arch = orchestrator.getMemory('project', 'architecture')
224
+
225
+ // Search memory
226
+ const results = orchestrator.searchMemory('event sourcing', 'project')
227
+ ```
228
+
229
+ ### Real-Time Dashboard
230
+
231
+ Monitor your orchestrator state via web UI.
232
+
233
+ ```typescript
234
+ const orchestrator = new NexusOrchestrator({
235
+ dashboard: {
236
+ enabled: true,
237
+ port: 4747,
238
+ host: '127.0.0.1'
239
+ }
240
+ })
241
+
242
+ // Open http://localhost:4747 in browser
243
+ ```
244
+
245
+ ---
246
+
247
+ ## Architecture
248
+
249
+ ```
250
+ ┌─────────────────────────────────────────────────────────────────┐
251
+ │ NEXUS ORCHESTRATOR │
252
+ │ │
253
+ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
254
+ │ │ DAG │ │ Cost │ │ Adaptive │ │
255
+ │ │ Executor │ │ Router │ │ Spawner │ │
256
+ │ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │
257
+ │ │ │ │ │
258
+ │ ┌──────┴─────────────────┴─────────────────┴───────┐ │
259
+ │ │ AGENT LIFECYCLE MANAGER │ │
260
+ │ └──────────────────────────────────────────────────┘ │
261
+ │ │
262
+ │ ┌──────────────────────────────────────────────────┐ │
263
+ │ │ COMMUNICATION LAYER (Pub/Sub) │ │
264
+ │ └──────────────────────────────────────────────────┘ │
265
+ │ │
266
+ │ ┌──────────────────────────────────────────────────┐ │
267
+ │ │ SHARED MEMORY STORE │ │
268
+ │ └──────────────────────────────────────────────────┘ │
269
+ │ │
270
+ │ ┌──────────────────────────────────────────────────┐ │
271
+ │ │ DASHBOARD & MONITORING │ │
272
+ │ └──────────────────────────────────────────────────┘ │
273
+ └─────────────────────────────────────────────────────────────────┘
274
+ ```
275
+
276
+ ---
277
+
278
+ ## Configuration
279
+
280
+ ### Global Config
281
+
282
+ ```jsonc
283
+ // ~/.config/opencode/nexus.jsonc
284
+ {
285
+ "$schema": "https://serkanalgur.com/opencode-nexus/schema.json",
286
+
287
+ "maxConcurrency": 5,
288
+ "budget": {
289
+ "maxTotalCost": 10.00,
290
+ "maxCostPerTask": 1.00,
291
+ "alertThreshold": 0.2
292
+ },
293
+ "selfHealing": {
294
+ "enabled": true,
295
+ "maxRetries": 3,
296
+ "contextTransfer": true
297
+ },
298
+ "communication": {
299
+ "mode": "pubsub",
300
+ "persistence": true
301
+ },
302
+ "dashboard": {
303
+ "enabled": true,
304
+ "port": 4747
305
+ }
306
+ }
307
+ ```
308
+
309
+ ### Project Config
310
+
311
+ ```jsonc
312
+ // .opencode/nexus.jsonc
313
+ {
314
+ "budget": {
315
+ "maxTotalCost": 5.00
316
+ },
317
+ "agentRoles": {
318
+ "security-reviewer": {
319
+ "model": "anthropic/claude-sonnet-4-6",
320
+ "tools": ["read", "grep", "git"]
321
+ }
322
+ }
323
+ }
324
+ ```
325
+
326
+ ---
327
+
328
+ ## API Reference
329
+
330
+ ### NexusOrchestrator
331
+
332
+ ```typescript
333
+ class NexusOrchestrator {
334
+ // Core
335
+ execute(request: ExecutionRequest): Promise<ExecutionResult>
336
+ spawnAgent(config: SpawnConfig): Promise<Agent>
337
+ terminateAgent(agentId: string): Promise<void>
338
+
339
+ // Communication
340
+ publish(topic: string, message: AgentMessage): void
341
+ subscribe(topic: string, handler: Function): Unsubscribe
342
+ send(agentId: string, message: AgentMessage): void
343
+
344
+ // Memory
345
+ setMemory(scope: MemoryScope, key: string, value: unknown, author: string): void
346
+ getMemory(scope: MemoryScope, key: string): MemoryEntry | undefined
347
+ searchMemory(query: string, scope?: MemoryScope): MemoryEntry[]
348
+
349
+ // Query
350
+ getStatus(detailed?: boolean): string
351
+ listAgents(filter?: string): string
352
+ getCostReport(): string
353
+
354
+ // Control
355
+ pause(): void
356
+ resume(): void
357
+ shutdown(): void
358
+
359
+ // Events
360
+ on(event: string, handler: Function): Unsubscribe
361
+ }
362
+ ```
363
+
364
+ ### Tools
365
+
366
+ | Tool | Description | Parameters |
367
+ |------|-------------|------------|
368
+ | `nexus_status` | Get orchestrator status | `{ detailed?: boolean }` |
369
+ | `nexus_agents` | List all agents | `{ filter?: string }` |
370
+ | `nexus_costs` | Get cost report | `{}` |
371
+ | `nexus_memory_get` | Get shared memory | `{ scope: string, key: string }` |
372
+ | `nexus_memory_set` | Set shared memory | `{ scope: string, key: string, value: unknown }` |
373
+ | `nexus_send` | Send message to agent | `{ to: string, message: AgentMessage }` |
374
+
375
+ ---
376
+
377
+ ## Development
378
+
379
+ ```bash
380
+ # Clone the repo
381
+ git clone https://github.com/serkanalgur/opencode-nexus.git
382
+ cd opencode-nexus
383
+
384
+ # Install dependencies
385
+ bun install
386
+
387
+ # Build
388
+ bun run build
389
+
390
+ # Run tests
391
+ bun test
392
+
393
+ # Development mode
394
+ bun run dev
395
+ ```
396
+
397
+ ---
398
+
399
+ ## Benchmarks
400
+
401
+ | Scenario | Sequential | Swarm | Ensemble | **Nexus** |
402
+ |----------|-----------|-------|----------|-----------|
403
+ | 3 independent tasks | 300s | 120s | 100s | **60s** |
404
+ | Dependent chain (3) | 300s | 150s | 150s | **120s** |
405
+ | Mixed parallel+serial | 300s | 130s | 110s | **70s** |
406
+
407
+ | Metric | Swarm | **Nexus** |
408
+ |--------|-------|-----------|
409
+ | Tokens per task | 15,000 | **8,000** |
410
+ | Agent overhead | 19 fixed | **Dynamic 2-5** |
411
+ | Cost per session | $10 | **$4** |
412
+
413
+ ---
414
+
415
+ ## Contributing
416
+
417
+ Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.
418
+
419
+ ---
420
+
421
+ ## License
422
+
423
+ MIT License - see [LICENSE](LICENSE) for details.
424
+
425
+ ---
426
+
427
+ <div align="center">
428
+
429
+ **Built with ❤️ by [Serkan Algur](https://github.com/serkanalgur)**
430
+
431
+ [![GitHub](https://img.shields.io/badge/GitHub-serkanalgur-181717?style=flat-square&logo=github)](https://github.com/serkanalgur)
432
+ [![npm](https://img.shields.io/badge/npm-@serkanalgur-cb3837?style=flat-square&logo=npm)](https://www.npmjs.com/package/@serkanalgur)
433
+
434
+ </div>