@miller-tech/uap 1.0.0 → 1.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.
Files changed (129) hide show
  1. package/dist/benchmarks/benchmark.d.ts +8 -8
  2. package/dist/benchmarks/improved-benchmark.d.ts.map +1 -1
  3. package/dist/benchmarks/improved-benchmark.js +10 -23
  4. package/dist/benchmarks/improved-benchmark.js.map +1 -1
  5. package/dist/benchmarks/model-integration.d.ts.map +1 -1
  6. package/dist/benchmarks/model-integration.js +22 -23
  7. package/dist/benchmarks/model-integration.js.map +1 -1
  8. package/dist/bin/policy.js +67 -11
  9. package/dist/bin/policy.js.map +1 -1
  10. package/dist/cli/dashboard.d.ts +2 -1
  11. package/dist/cli/dashboard.d.ts.map +1 -1
  12. package/dist/cli/dashboard.js +399 -10
  13. package/dist/cli/dashboard.js.map +1 -1
  14. package/dist/cli/model.js +12 -12
  15. package/dist/cli/model.js.map +1 -1
  16. package/dist/cli/setup-wizard.d.ts.map +1 -1
  17. package/dist/cli/setup-wizard.js +24 -0
  18. package/dist/cli/setup-wizard.js.map +1 -1
  19. package/dist/coordination/deploy-batcher.d.ts +1 -0
  20. package/dist/coordination/deploy-batcher.d.ts.map +1 -1
  21. package/dist/coordination/deploy-batcher.js +24 -25
  22. package/dist/coordination/deploy-batcher.js.map +1 -1
  23. package/dist/dashboard/data-service.d.ts +94 -0
  24. package/dist/dashboard/data-service.d.ts.map +1 -0
  25. package/dist/dashboard/data-service.js +286 -0
  26. package/dist/dashboard/data-service.js.map +1 -0
  27. package/dist/dashboard/index.d.ts +5 -0
  28. package/dist/dashboard/index.d.ts.map +1 -0
  29. package/dist/dashboard/index.js +3 -0
  30. package/dist/dashboard/index.js.map +1 -0
  31. package/dist/dashboard/server.d.ts +15 -0
  32. package/dist/dashboard/server.d.ts.map +1 -0
  33. package/dist/dashboard/server.js +158 -0
  34. package/dist/dashboard/server.js.map +1 -0
  35. package/dist/mcp-router/session-stats.d.ts +9 -0
  36. package/dist/mcp-router/session-stats.d.ts.map +1 -1
  37. package/dist/mcp-router/session-stats.js +19 -3
  38. package/dist/mcp-router/session-stats.js.map +1 -1
  39. package/dist/memory/adaptive-context.d.ts +1 -0
  40. package/dist/memory/adaptive-context.d.ts.map +1 -1
  41. package/dist/memory/adaptive-context.js +4 -0
  42. package/dist/memory/adaptive-context.js.map +1 -1
  43. package/dist/memory/embeddings.d.ts.map +1 -1
  44. package/dist/memory/embeddings.js +4 -4
  45. package/dist/memory/embeddings.js.map +1 -1
  46. package/dist/memory/model-router.d.ts +1 -1
  47. package/dist/memory/model-router.d.ts.map +1 -1
  48. package/dist/memory/model-router.js +52 -1
  49. package/dist/memory/model-router.js.map +1 -1
  50. package/dist/memory/predictive-memory.d.ts.map +1 -1
  51. package/dist/memory/predictive-memory.js +4 -3
  52. package/dist/memory/predictive-memory.js.map +1 -1
  53. package/dist/models/analytics.d.ts +93 -0
  54. package/dist/models/analytics.d.ts.map +1 -0
  55. package/dist/models/analytics.js +205 -0
  56. package/dist/models/analytics.js.map +1 -0
  57. package/dist/models/execution-profiles.d.ts +6 -0
  58. package/dist/models/execution-profiles.d.ts.map +1 -1
  59. package/dist/models/execution-profiles.js +15 -0
  60. package/dist/models/execution-profiles.js.map +1 -1
  61. package/dist/models/executor.d.ts.map +1 -1
  62. package/dist/models/executor.js +51 -17
  63. package/dist/models/executor.js.map +1 -1
  64. package/dist/models/index.d.ts +2 -0
  65. package/dist/models/index.d.ts.map +1 -1
  66. package/dist/models/index.js +2 -0
  67. package/dist/models/index.js.map +1 -1
  68. package/dist/models/router.d.ts +8 -0
  69. package/dist/models/router.d.ts.map +1 -1
  70. package/dist/models/router.js +46 -21
  71. package/dist/models/router.js.map +1 -1
  72. package/dist/models/types.d.ts +26 -0
  73. package/dist/models/types.d.ts.map +1 -1
  74. package/dist/models/types.js +43 -4
  75. package/dist/models/types.js.map +1 -1
  76. package/dist/models/unified-router.d.ts.map +1 -1
  77. package/dist/models/unified-router.js +4 -0
  78. package/dist/models/unified-router.js.map +1 -1
  79. package/dist/policies/database-manager.d.ts +1 -0
  80. package/dist/policies/database-manager.d.ts.map +1 -1
  81. package/dist/policies/database-manager.js +14 -2
  82. package/dist/policies/database-manager.js.map +1 -1
  83. package/dist/policies/enforced-tool-router.d.ts +2 -2
  84. package/dist/policies/enforced-tool-router.d.ts.map +1 -1
  85. package/dist/policies/enforced-tool-router.js +4 -4
  86. package/dist/policies/enforced-tool-router.js.map +1 -1
  87. package/dist/policies/policy-gate.d.ts +2 -2
  88. package/dist/policies/policy-gate.d.ts.map +1 -1
  89. package/dist/policies/policy-gate.js +6 -4
  90. package/dist/policies/policy-gate.js.map +1 -1
  91. package/dist/policies/policy-memory.d.ts +3 -0
  92. package/dist/policies/policy-memory.d.ts.map +1 -1
  93. package/dist/policies/policy-memory.js +11 -0
  94. package/dist/policies/policy-memory.js.map +1 -1
  95. package/dist/policies/schemas/policy.d.ts +3 -0
  96. package/dist/policies/schemas/policy.d.ts.map +1 -1
  97. package/dist/policies/schemas/policy.js +1 -0
  98. package/dist/policies/schemas/policy.js.map +1 -1
  99. package/dist/tasks/coordination.d.ts +18 -0
  100. package/dist/tasks/coordination.d.ts.map +1 -1
  101. package/dist/tasks/coordination.js +59 -1
  102. package/dist/tasks/coordination.js.map +1 -1
  103. package/dist/tasks/event-bus.d.ts +91 -0
  104. package/dist/tasks/event-bus.d.ts.map +1 -0
  105. package/dist/tasks/event-bus.js +123 -0
  106. package/dist/tasks/event-bus.js.map +1 -0
  107. package/dist/tasks/service.d.ts +5 -0
  108. package/dist/tasks/service.d.ts.map +1 -1
  109. package/dist/tasks/service.js +59 -0
  110. package/dist/tasks/service.js.map +1 -1
  111. package/dist/telemetry/session-telemetry.d.ts.map +1 -1
  112. package/dist/telemetry/session-telemetry.js +3 -0
  113. package/dist/telemetry/session-telemetry.js.map +1 -1
  114. package/dist/utils/concurrency-pool.d.ts +51 -0
  115. package/dist/utils/concurrency-pool.d.ts.map +1 -0
  116. package/dist/utils/concurrency-pool.js +80 -0
  117. package/dist/utils/concurrency-pool.js.map +1 -0
  118. package/dist/utils/system-resources.d.ts +47 -0
  119. package/dist/utils/system-resources.d.ts.map +1 -0
  120. package/dist/utils/system-resources.js +92 -0
  121. package/dist/utils/system-resources.js.map +1 -0
  122. package/docs/BENCHMARK_GAPS_AND_PLAN.md +146 -0
  123. package/docs/PARALLELISM_GAPS_AND_OPTIONS.md +422 -0
  124. package/docs/UAP_OPTIMIZATION_PLAN.md +638 -0
  125. package/docs/getting-started/INTEGRATION.md +193 -14
  126. package/docs/opencode-integration-guide.md +740 -0
  127. package/docs/opencode-integration-quickref.md +180 -0
  128. package/package.json +4 -1
  129. package/templates/hooks/session-start.sh +8 -1
@@ -0,0 +1,422 @@
1
+ # Parallelism & Dependency Notification: Gaps and Options
2
+
3
+ **Generated:** 2026-03-17
4
+
5
+ ---
6
+
7
+ ## Current State
8
+
9
+ ### What exists (DO NOT REBUILD)
10
+
11
+ | Component | File | What it does |
12
+ | ---------------------------- | ------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
13
+ | Executor parallel batching | `src/models/executor.ts:54-162` | `Promise.all` batches capped by `maxParallel` (default 3), topological level grouping |
14
+ | Deploy batcher parallelism | `src/coordination/deploy-batcher.ts:34-591` | Categorizes actions as parallel-safe vs sequential, `Promise.allSettled` with `maxParallelActions` (default 5) |
15
+ | Benchmark model parallelism | `src/benchmarks/model-integration.ts:911-944` + `improved-benchmark.ts:565-603` | Queue-based concurrency pool, `parallelModels` param (default 1) |
16
+ | Planner topological sort | `src/models/planner.ts:379-413` | Returns `string[][]` dependency levels for parallel execution |
17
+ | Task dependency DAG | `src/tasks/database.ts:71-84` + `service.ts:438-538` | `task_dependencies` table, add/remove deps, cycle detection (BFS), blocked/ready queries |
18
+ | Task coordination scoring | `src/tasks/coordination.ts:260-298` | Scores tasks: +5 no deps, +3 per task it unblocks |
19
+ | Pub/sub messaging | `src/coordination/service.ts:608-642` | SQLite-backed broadcast/send/receive on channels |
20
+ | Config schema (unused) | `src/types/config.ts:223-229` | `maxParallelDroids` (4), `maxParallelWorkflows` (3) -- declared but never consumed |
21
+ | VRAM detection | `src/bin/llama-server-optimize.ts:301-331` | nvidia-smi / sysctl, not reusable (private to llama-server) |
22
+ | CPU detection | `src/bin/llama-server-optimize.ts:614` | `os.cpus().length - 2`, not reusable (inline in llama-server) |
23
+ | Harbor N_CONCURRENT | Shell scripts | `N_CONCURRENT` env var (default 4) for Harbor `-n` flag |
24
+ | Python parallel tool calls | `tools/agents/scripts/qwen_tool_call_wrapper.py` | `parallel_tool_calls: True` in every API request |
25
+ | Unbounded memory parallelism | `src/memory/predictive-memory.ts:94-104` + `embeddings.ts:228-230` | `Promise.all` with no concurrency limit |
26
+
27
+ ### What's broken or missing
28
+
29
+ | Gap | Location | Impact |
30
+ | -------------------------------------------------- | -------------------------------------------------------------- | --------------------------------------------------------------------------- |
31
+ | **No env var override for TypeScript parallelism** | `executor.ts`, `improved-benchmark.ts`, `model-integration.ts` | Cannot tune parallelism without code changes |
32
+ | **No vCPU/resource detection shared utility** | `llama-server-optimize.ts` has it but private | Every module hardcodes defaults |
33
+ | **Config schema not wired** | `config.ts:223-229` | `maxParallelDroids`/`maxParallelWorkflows` declared but never read |
34
+ | **No dependency completion notification** | `service.ts:287-302` | `close()` marks task done but does NOT notify blocked dependents |
35
+ | **No auto-unblock on completion** | `coordination.ts:155-200` | `release()` broadcasts generic message, doesn't check newly-unblocked tasks |
36
+ | **Unbounded memory concurrency** | `predictive-memory.ts`, `embeddings.ts` | `Promise.all` on all items, can overwhelm local inference |
37
+ | **Benchmark parallelism defaults to 1** | `improved-benchmark.ts:632`, `model-integration.ts` | Sequential by default, no auto-detection |
38
+
39
+ ---
40
+
41
+ ## Option A: Minimal -- Env Overrides + Wire Config (Recommended)
42
+
43
+ **Effort:** ~2 hours | **Risk:** Low | **Impact:** High
44
+
45
+ No new abstractions. Add env var reads to existing code, wire the existing config schema, and add notification to `close()`.
46
+
47
+ ### A1. Shared resource detection utility
48
+
49
+ **New file:** `src/utils/system-resources.ts`
50
+
51
+ Extract and generalize the detection logic already in `llama-server-optimize.ts`:
52
+
53
+ ```typescript
54
+ import { cpus } from 'os';
55
+ import { execSync } from 'child_process';
56
+
57
+ export interface SystemResources {
58
+ vCPUs: number;
59
+ vramGB: number;
60
+ memoryGB: number;
61
+ }
62
+
63
+ let _cached: SystemResources | null = null;
64
+
65
+ export function detectSystemResources(): SystemResources {
66
+ if (_cached) return _cached;
67
+
68
+ const vCPUs = cpus().length;
69
+
70
+ let vramGB = 0;
71
+ try {
72
+ const out = execSync('nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits', {
73
+ encoding: 'utf-8',
74
+ timeout: 3000,
75
+ });
76
+ vramGB = Math.round(parseInt(out.trim().split('\n')[0]) / 1024);
77
+ } catch {
78
+ try {
79
+ const out = execSync('sysctl -n hw.memsize', { encoding: 'utf-8' });
80
+ vramGB = Math.min(Math.round(parseInt(out.trim()) / 1024 ** 3), 48);
81
+ } catch {
82
+ vramGB = 0;
83
+ }
84
+ }
85
+
86
+ const memoryGB = Math.round(require('os').totalmem() / 1024 ** 3);
87
+
88
+ _cached = { vCPUs, vramGB, memoryGB };
89
+ return _cached;
90
+ }
91
+
92
+ /**
93
+ * Compute safe parallelism ceiling.
94
+ * For CPU-bound: vCPUs - 2 (reserve for OS + inference).
95
+ * For IO-bound (API calls): min(vCPUs, 8).
96
+ * Env override: UAP_MAX_PARALLEL always wins.
97
+ */
98
+ export function getMaxParallel(mode: 'cpu' | 'io' = 'io'): number {
99
+ const envOverride = process.env.UAP_MAX_PARALLEL;
100
+ if (envOverride) return Math.max(1, parseInt(envOverride, 10) || 1);
101
+
102
+ const { vCPUs } = detectSystemResources();
103
+
104
+ if (mode === 'cpu') {
105
+ return Math.max(1, vCPUs - 2);
106
+ }
107
+ return Math.min(vCPUs, 8);
108
+ }
109
+ ```
110
+
111
+ ### A2. Env var overrides in existing code
112
+
113
+ **File: `src/models/executor.ts:58-65`** -- read env vars into defaults:
114
+
115
+ ```typescript
116
+ const DEFAULT_OPTIONS: ExecutorOptions = {
117
+ maxRetries: 2,
118
+ retryDelayMs: 1000,
119
+ stepTimeout: 120000,
120
+ enableFallback: true,
121
+ parallelExecution: process.env.UAP_PARALLEL !== 'false',
122
+ maxParallel: parseInt(process.env.UAP_MAX_PARALLEL || '', 10) || 3,
123
+ };
124
+ ```
125
+
126
+ **File: `src/benchmarks/improved-benchmark.ts:632`** -- auto-detect:
127
+
128
+ ```typescript
129
+ const parallelModels =
130
+ (options.parallelModels ?? parseInt(process.env.UAP_BENCHMARK_PARALLEL || '', 10)) ||
131
+ getMaxParallel('io');
132
+ ```
133
+
134
+ **File: `src/benchmarks/model-integration.ts`** -- same pattern.
135
+
136
+ **File: `src/coordination/deploy-batcher.ts:78-79`** -- same pattern:
137
+
138
+ ```typescript
139
+ parallelExecution: process.env.UAP_PARALLEL !== 'false',
140
+ maxParallelActions: parseInt(process.env.UAP_MAX_PARALLEL || '', 10) || 5,
141
+ ```
142
+
143
+ ### A3. Wire existing config schema
144
+
145
+ **File: `src/types/config.ts:223-229`** -- already declares `maxParallelDroids` and `maxParallelWorkflows`.
146
+
147
+ Wire into executor by reading config at startup:
148
+
149
+ ```typescript
150
+ // In executor.ts constructor or factory
151
+ const uapConfig = loadUAPConfig(); // existing config loader
152
+ if (uapConfig?.parallelExecution) {
153
+ this.options.parallelExecution = uapConfig.parallelExecution.enabled;
154
+ this.options.maxParallel = uapConfig.parallelExecution.maxParallelDroids;
155
+ }
156
+ ```
157
+
158
+ ### A4. Dependency completion notification
159
+
160
+ **File: `src/tasks/service.ts:287-302`** -- add unblock notification to `close()`:
161
+
162
+ ```typescript
163
+ close(id: string, reason?: string): Task | null {
164
+ const task = this.get(id);
165
+ if (!task) return null;
166
+
167
+ const now = new Date().toISOString();
168
+ const stmt = this.db.prepare(`
169
+ UPDATE tasks SET status = 'done', closed_at = ?, closed_reason = ?, updated_at = ?
170
+ WHERE id = ?
171
+ `);
172
+ stmt.run(now, reason || null, now, id);
173
+
174
+ this.recordHistory(id, 'status', task.status, 'done');
175
+ this.recordActivity(id, 'closed', reason || 'Task completed');
176
+
177
+ // --- NEW: Notify newly-unblocked dependents ---
178
+ this.notifyUnblockedDependents(id);
179
+
180
+ return this.get(id);
181
+ }
182
+
183
+ private notifyUnblockedDependents(completedTaskId: string): void {
184
+ // Find tasks that were blocked by this task
185
+ const dependents = this.db.prepare(`
186
+ SELECT from_task FROM task_dependencies
187
+ WHERE to_task = ? AND dep_type = 'blocks'
188
+ `).all(completedTaskId) as Array<{ from_task: string }>;
189
+
190
+ for (const dep of dependents) {
191
+ const dependent = this.getWithRelations(dep.from_task);
192
+ if (dependent && dependent.isReady) {
193
+ // Task is now unblocked -- record activity
194
+ this.recordActivity(dep.from_task, 'unblocked',
195
+ `Unblocked: dependency "${completedTaskId}" completed`);
196
+
197
+ // If task was in 'blocked' status, move to 'open'
198
+ const raw = this.get(dep.from_task);
199
+ if (raw && raw.status === 'blocked') {
200
+ this.db.prepare(`UPDATE tasks SET status = 'open', updated_at = ? WHERE id = ?`)
201
+ .run(new Date().toISOString(), dep.from_task);
202
+ this.recordHistory(dep.from_task, 'status', 'blocked', 'open');
203
+ }
204
+ }
205
+ }
206
+ }
207
+ ```
208
+
209
+ **File: `src/tasks/coordination.ts:155-200`** -- enhance `release()` to return unblocked tasks:
210
+
211
+ ```typescript
212
+ async release(taskId: string, reason?: string): Promise<ReleaseResult | null> {
213
+ // ... existing code ...
214
+
215
+ // Broadcast task completion
216
+ this.coordService.broadcast(this.agentId, 'coordination', {
217
+ action: 'task_completed',
218
+ resource: taskId,
219
+ data: {
220
+ title: task.title,
221
+ reason,
222
+ },
223
+ });
224
+
225
+ // --- NEW: Find and broadcast newly-unblocked tasks ---
226
+ const nowReady = this.taskService.ready().filter(t =>
227
+ t.blockedBy.length === 0 // was previously blocked, now free
228
+ );
229
+
230
+ if (nowReady.length > 0) {
231
+ this.coordService.broadcast(this.agentId, 'coordination', {
232
+ action: 'tasks_unblocked',
233
+ resource: taskId,
234
+ data: {
235
+ unblockedTasks: nowReady.map(t => ({ id: t.id, title: t.title })),
236
+ count: nowReady.length,
237
+ },
238
+ });
239
+ }
240
+
241
+ // ... rest of existing code ...
242
+
243
+ return {
244
+ task: closedTask,
245
+ completedAnnouncements: 1,
246
+ unblockedTasks: nowReady.map(t => t.id), // NEW field
247
+ };
248
+ }
249
+ ```
250
+
251
+ ### A5. Cap unbounded memory concurrency
252
+
253
+ **File: `src/memory/predictive-memory.ts:94-104`**:
254
+
255
+ ```typescript
256
+ // Before (unbounded):
257
+ const results = await Promise.all(predictions.map((p) => this.query(p)));
258
+
259
+ // After (capped):
260
+ import { getMaxParallel } from '../utils/system-resources.js';
261
+
262
+ const maxConcurrent = getMaxParallel('io');
263
+ const results: MemoryEntry[][] = [];
264
+ for (let i = 0; i < predictions.length; i += maxConcurrent) {
265
+ const batch = predictions.slice(i, i + maxConcurrent);
266
+ const batchResults = await Promise.all(batch.map((p) => this.query(p)));
267
+ results.push(...batchResults);
268
+ }
269
+ ```
270
+
271
+ ### Env Variable Summary
272
+
273
+ | Variable | Default | Scope | Override |
274
+ | ------------------------ | ------------------------ | ---------------------------------- | ---------------------------------- |
275
+ | `UAP_PARALLEL` | `true` | Global on/off | `false` to disable all parallelism |
276
+ | `UAP_MAX_PARALLEL` | auto-detected from vCPUs | Global concurrency cap | Any integer |
277
+ | `UAP_BENCHMARK_PARALLEL` | auto-detected | Benchmark model concurrency | Any integer |
278
+ | `N_CONCURRENT` | `4` | Harbor task concurrency (existing) | Any integer |
279
+
280
+ ### Precedence
281
+
282
+ ```
283
+ UAP_MAX_PARALLEL env var
284
+ → uap.config parallelExecution.maxParallelDroids
285
+ → auto-detected from os.cpus().length
286
+ → hardcoded default (3)
287
+ ```
288
+
289
+ ---
290
+
291
+ ## Option B: Concurrency Pool Utility
292
+
293
+ **Effort:** ~4 hours | **Risk:** Low | **Impact:** Medium
294
+
295
+ Everything in Option A, plus a shared concurrency pool to replace the duplicated `Promise.all` batching pattern across 5+ files.
296
+
297
+ ### B1. Shared concurrency pool
298
+
299
+ **New file:** `src/utils/concurrency-pool.ts`
300
+
301
+ ```typescript
302
+ import { getMaxParallel } from './system-resources.js';
303
+
304
+ export async function concurrentMap<T, R>(
305
+ items: T[],
306
+ fn: (item: T, index: number) => Promise<R>,
307
+ options?: { maxConcurrent?: number; mode?: 'cpu' | 'io' }
308
+ ): Promise<R[]> {
309
+ const max = options?.maxConcurrent ?? getMaxParallel(options?.mode ?? 'io');
310
+ const results: R[] = new Array(items.length);
311
+ let nextIndex = 0;
312
+
313
+ const worker = async () => {
314
+ while (nextIndex < items.length) {
315
+ const i = nextIndex++;
316
+ results[i] = await fn(items[i], i);
317
+ }
318
+ };
319
+
320
+ const workers = Array.from({ length: Math.min(max, items.length) }, () => worker());
321
+ await Promise.all(workers);
322
+ return results;
323
+ }
324
+ ```
325
+
326
+ ### B2. Replace duplicated patterns
327
+
328
+ | File | Current | Replace with |
329
+ | ------------------------------- | -------------------------------------- | ----------------------------------------------------------- |
330
+ | `executor.ts:149-153` | Manual `Promise.all` batch loop | `concurrentMap(batch, taskId => this.executeSubtask(...))` |
331
+ | `deploy-batcher.ts:582-591` | Manual `Promise.allSettled` chunk loop | `concurrentMap(actions, action => this.executeAction(...))` |
332
+ | `improved-benchmark.ts:565-603` | Queue-based pool | `concurrentMap(models, model => runBenchmarkForModel(...))` |
333
+ | `model-integration.ts:911-944` | Queue-based pool | `concurrentMap(models, model => runBenchmarkForModel(...))` |
334
+ | `predictive-memory.ts:94-104` | Unbounded `Promise.all` | `concurrentMap(predictions, p => this.query(p))` |
335
+ | `embeddings.ts:228-230` | Unbounded `Promise.all` | `concurrentMap(texts, t => this.embed(t))` |
336
+
337
+ ---
338
+
339
+ ## Option C: Full Event-Driven Dependency Resolution
340
+
341
+ **Effort:** ~8 hours | **Risk:** Medium | **Impact:** High
342
+
343
+ Everything in Options A+B, plus an event-driven system where task completion automatically triggers dependent task execution.
344
+
345
+ ### C1. TaskEventBus
346
+
347
+ **New file:** `src/tasks/event-bus.ts`
348
+
349
+ ```typescript
350
+ type TaskEvent =
351
+ | { type: 'task_completed'; taskId: string }
352
+ | { type: 'task_unblocked'; taskId: string; unblockedBy: string }
353
+ | { type: 'task_failed'; taskId: string; error: string };
354
+
355
+ type TaskEventHandler = (event: TaskEvent) => void | Promise<void>;
356
+
357
+ export class TaskEventBus {
358
+ private handlers: Map<TaskEvent['type'], TaskEventHandler[]> = new Map();
359
+
360
+ on(type: TaskEvent['type'], handler: TaskEventHandler): void {
361
+ const list = this.handlers.get(type) || [];
362
+ list.push(handler);
363
+ this.handlers.set(type, list);
364
+ }
365
+
366
+ async emit(event: TaskEvent): Promise<void> {
367
+ const handlers = this.handlers.get(event.type) || [];
368
+ await Promise.all(handlers.map((h) => h(event)));
369
+ }
370
+ }
371
+ ```
372
+
373
+ ### C2. Auto-execute unblocked tasks
374
+
375
+ Wire into `TaskCoordinator`:
376
+
377
+ ```typescript
378
+ // In coordinator constructor
379
+ this.eventBus.on('task_unblocked', async (event) => {
380
+ if (event.type !== 'task_unblocked') return;
381
+ const task = this.taskService.getWithRelations(event.taskId);
382
+ if (task && task.isReady && this.autoExecuteEnabled) {
383
+ await this.claim(event.taskId);
384
+ }
385
+ });
386
+ ```
387
+
388
+ ### C3. Executor emits completion events
389
+
390
+ Wire into `TaskExecutor.executePlan()`:
391
+
392
+ ```typescript
393
+ // After subtask completes successfully
394
+ this.eventBus.emit({ type: 'task_completed', taskId: subtaskId });
395
+ ```
396
+
397
+ ---
398
+
399
+ ## Recommendation
400
+
401
+ **Start with Option A** (env overrides + wire config + dependency notification). It addresses every gap with minimal code changes to existing files and no new abstractions. The concurrency pool (Option B) is a nice cleanup but not blocking. The event bus (Option C) is only needed if you want auto-execution of unblocked tasks.
402
+
403
+ | Option | Effort | Files changed | New files | Risk |
404
+ | ------------------- | -------- | ------------- | ------------------------------------------------ | ------ |
405
+ | **A (Recommended)** | ~2 hours | 6 existing | 1 (`system-resources.ts`) | Low |
406
+ | B | ~4 hours | 8 existing | 2 (`system-resources.ts`, `concurrency-pool.ts`) | Low |
407
+ | C | ~8 hours | 10 existing | 3 (+ `event-bus.ts`) | Medium |
408
+
409
+ ---
410
+
411
+ ## Files to Change (Option A)
412
+
413
+ | File | Change | Lines affected |
414
+ | ------------------------------------------ | -------------------------------------------------------- | -------------- |
415
+ | `src/utils/system-resources.ts` | **NEW** -- vCPU/VRAM detection + `getMaxParallel()` | ~45 lines |
416
+ | `src/models/executor.ts:58-65` | Read `UAP_PARALLEL`, `UAP_MAX_PARALLEL` env vars | 2 lines |
417
+ | `src/benchmarks/improved-benchmark.ts:632` | Read `UAP_BENCHMARK_PARALLEL`, fallback to auto-detect | 3 lines |
418
+ | `src/benchmarks/model-integration.ts` | Same as above | 3 lines |
419
+ | `src/coordination/deploy-batcher.ts:78-79` | Read env vars | 2 lines |
420
+ | `src/tasks/service.ts:287-302` | Add `notifyUnblockedDependents()` after `close()` | ~25 lines |
421
+ | `src/tasks/coordination.ts:155-200` | Broadcast `tasks_unblocked` event, return unblocked list | ~15 lines |
422
+ | `src/memory/predictive-memory.ts:94-104` | Cap concurrency with `getMaxParallel()` | 5 lines |