@blockrun/franklin 3.32.1 → 3.34.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 (97) hide show
  1. package/README.md +23 -2
  2. package/dist/agent/approvals.d.ts +47 -0
  3. package/dist/agent/approvals.js +66 -0
  4. package/dist/agent/commands.js +230 -7
  5. package/dist/agent/compact.js +1 -1
  6. package/dist/agent/context.js +1 -1
  7. package/dist/agent/input-queue.d.ts +26 -0
  8. package/dist/agent/input-queue.js +65 -0
  9. package/dist/agent/loop.js +198 -5
  10. package/dist/agent/optimize.js +1 -1
  11. package/dist/agent/streaming-executor.d.ts +4 -0
  12. package/dist/agent/streaming-executor.js +52 -0
  13. package/dist/agent/tokens.js +2 -0
  14. package/dist/agent/tool-guard.d.ts +7 -0
  15. package/dist/agent/tool-guard.js +21 -0
  16. package/dist/agent/types.d.ts +26 -0
  17. package/dist/audit/approvals.d.ts +20 -0
  18. package/dist/audit/approvals.js +21 -0
  19. package/dist/commands/init.js +1 -1
  20. package/dist/commands/models.d.ts +11 -0
  21. package/dist/commands/models.js +157 -37
  22. package/dist/commands/start.d.ts +10 -1
  23. package/dist/commands/start.js +53 -1
  24. package/dist/events/types.d.ts +38 -1
  25. package/dist/gateway-models.d.ts +14 -2
  26. package/dist/gateway-models.js +8 -0
  27. package/dist/goal/engine.d.ts +39 -0
  28. package/dist/goal/engine.js +182 -0
  29. package/dist/goal/prompts.d.ts +16 -0
  30. package/dist/goal/prompts.js +206 -0
  31. package/dist/goal/runtime.d.ts +20 -0
  32. package/dist/goal/runtime.js +110 -0
  33. package/dist/goal/store.d.ts +22 -0
  34. package/dist/goal/store.js +79 -0
  35. package/dist/goal/types.d.ts +63 -0
  36. package/dist/goal/types.js +26 -0
  37. package/dist/hooks/loader.d.ts +19 -0
  38. package/dist/hooks/loader.js +115 -0
  39. package/dist/hooks/runner.d.ts +31 -0
  40. package/dist/hooks/runner.js +147 -0
  41. package/dist/hooks/types.d.ts +64 -0
  42. package/dist/hooks/types.js +35 -0
  43. package/dist/index.js +5 -1
  44. package/dist/learnings/extractor.js +1 -1
  45. package/dist/memory/capture.d.ts +40 -0
  46. package/dist/memory/capture.js +95 -0
  47. package/dist/memory/dream.d.ts +24 -0
  48. package/dist/memory/dream.js +147 -0
  49. package/dist/memory/indexer.d.ts +29 -0
  50. package/dist/memory/indexer.js +144 -0
  51. package/dist/memory/store.d.ts +50 -0
  52. package/dist/memory/store.js +163 -0
  53. package/dist/monitors/registry.d.ts +42 -0
  54. package/dist/monitors/registry.js +104 -0
  55. package/dist/panel/html.js +299 -0
  56. package/dist/panel/server.js +41 -0
  57. package/dist/pricing.js +4 -1
  58. package/dist/router/index.js +15 -9
  59. package/dist/router/vision.js +5 -4
  60. package/dist/scheduler/service.d.ts +24 -0
  61. package/dist/scheduler/service.js +44 -0
  62. package/dist/scheduler/store.d.ts +26 -0
  63. package/dist/scheduler/store.js +116 -0
  64. package/dist/scheduler/types.d.ts +36 -0
  65. package/dist/scheduler/types.js +31 -0
  66. package/dist/serve/agent-host.d.ts +63 -0
  67. package/dist/serve/agent-host.js +270 -0
  68. package/dist/serve/server.js +131 -2
  69. package/dist/session/live-registry.d.ts +32 -0
  70. package/dist/session/live-registry.js +83 -0
  71. package/dist/session/search.d.ts +6 -0
  72. package/dist/session/search.js +3 -3
  73. package/dist/session/storage.d.ts +6 -0
  74. package/dist/session/storage.js +6 -0
  75. package/dist/tools/goal.d.ts +7 -0
  76. package/dist/tools/goal.js +29 -0
  77. package/dist/tools/index.js +11 -0
  78. package/dist/tools/memory.js +14 -4
  79. package/dist/tools/moa.js +1 -1
  80. package/dist/tools/monitor.d.ts +11 -0
  81. package/dist/tools/monitor.js +96 -0
  82. package/dist/tools/scheduler.d.ts +12 -0
  83. package/dist/tools/scheduler.js +79 -0
  84. package/dist/tools/spend-tools.d.ts +33 -0
  85. package/dist/tools/spend-tools.js +114 -0
  86. package/dist/tools/tool-categories.js +7 -0
  87. package/dist/tools/trade-plan.d.ts +11 -0
  88. package/dist/tools/trade-plan.js +137 -0
  89. package/dist/tools/trading-execute.js +24 -0
  90. package/dist/trading/trade-plan.d.ts +75 -0
  91. package/dist/trading/trade-plan.js +290 -0
  92. package/dist/ui/app.js +54 -9
  93. package/dist/ui/model-picker.d.ts +40 -0
  94. package/dist/ui/model-picker.js +135 -25
  95. package/package.json +2 -2
  96. package/dist/agent/media-router.d.ts +0 -98
  97. package/dist/agent/media-router.js +0 -328
@@ -513,6 +513,11 @@ a:hover { text-decoration:underline; }
513
513
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="7" height="7" rx="1.5"/><rect x="14" y="3" width="7" height="7" rx="1.5"/><rect x="3" y="14" width="7" height="7" rx="1.5"/><rect x="14" y="14" width="7" height="7" rx="1.5"/></svg>
514
514
  Overview
515
515
  </button>
516
+ <button class="nav-item" data-tab="agents">
517
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="5" r="2.2"/><circle cx="5" cy="19" r="2.2"/><circle cx="19" cy="19" r="2.2"/><path d="M12 7.2V12"/><path d="M12 12l-5.2 5"/><path d="M12 12l5.2 5"/></svg>
518
+ Agents
519
+ <span class="nav-badge" id="agents-nav-badge" style="display:none"></span>
520
+ </button>
516
521
  <button class="nav-item" data-tab="wallet">
517
522
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12V7H5a2 2 0 0 1 0-4h14v4"/><path d="M3 5v14a2 2 0 0 0 2 2h16v-5"/><path d="M18 12a2 2 0 0 0 0 4h4v-4z"/></svg>
518
523
  Wallet
@@ -627,6 +632,58 @@ a:hover { text-decoration:underline; }
627
632
  </div>
628
633
  </div>
629
634
 
635
+ <!-- Agents — mission control -->
636
+ <div class="tab" id="tab-agents">
637
+ <div class="content-header">
638
+ <h2>Agents</h2>
639
+ <p>Mission control — dispatch, watch, and approve your agent fleet</p>
640
+ </div>
641
+
642
+ <div id="agents-offline" class="card" style="display:none;border-color:#8a6d3b">
643
+ <h3>Agent host offline</h3>
644
+ <div class="sub">Run <code>franklin serve</code> in a terminal to dispatch and control agents from here. Sessions below are read-only.</div>
645
+ </div>
646
+
647
+ <div class="card" id="agents-dispatch-card" style="margin-bottom:12px">
648
+ <h3>Dispatch a new agent</h3>
649
+ <div style="display:flex;gap:8px;flex-wrap:wrap;align-items:center">
650
+ <input id="agents-dispatch-prompt" type="text" placeholder="e.g. monitor BTC funding rates and alert me on a flip"
651
+ style="flex:1;min-width:260px;background:transparent;border:1px solid var(--border,#333);border-radius:6px;padding:8px 10px;color:inherit" />
652
+ <input id="agents-dispatch-model" type="text" placeholder="model (optional)"
653
+ style="width:160px;background:transparent;border:1px solid var(--border,#333);border-radius:6px;padding:8px 10px;color:inherit" />
654
+ <input id="agents-dispatch-maxspend" type="number" step="0.5" min="0" placeholder="max $"
655
+ style="width:80px;background:transparent;border:1px solid var(--border,#333);border-radius:6px;padding:8px 10px;color:inherit" />
656
+ <button id="agents-dispatch-btn" class="btn">Dispatch</button>
657
+ </div>
658
+ <div class="sub" style="margin-top:6px">Every dispatch starts a NEW agent. Press Enter to batch-dispatch several.</div>
659
+ </div>
660
+
661
+ <div class="grid" style="grid-template-columns: minmax(300px, 5fr) minmax(320px, 7fr); gap:12px; align-items:start">
662
+ <div class="card">
663
+ <h3>Fleet</h3>
664
+ <div id="agents-list" class="sub">Loading…</div>
665
+ </div>
666
+ <div class="card" id="agents-peek" style="display:none">
667
+ <h3 id="agents-peek-title">Agent</h3>
668
+ <div id="agents-peek-state" class="sub"></div>
669
+ <div id="agents-approval" style="display:none;margin:10px 0;padding:10px;border:1px solid #8a6d3b;border-radius:8px">
670
+ <div id="agents-approval-title" style="font-weight:600;margin-bottom:6px"></div>
671
+ <pre id="agents-approval-desc" style="white-space:pre-wrap;font-size:12px;max-height:220px;overflow:auto"></pre>
672
+ <div id="agents-approval-options" style="display:flex;gap:8px;flex-wrap:wrap;margin-top:8px"></div>
673
+ <textarea id="agents-approval-message" placeholder="optional message (e.g. requested changes)" rows="2"
674
+ style="width:100%;margin-top:8px;background:transparent;border:1px solid var(--border,#333);border-radius:6px;padding:6px;color:inherit;display:none"></textarea>
675
+ </div>
676
+ <pre id="agents-transcript" style="white-space:pre-wrap;font-size:12px;max-height:420px;overflow:auto;background:rgba(0,0,0,0.25);border-radius:8px;padding:10px;margin-top:8px"></pre>
677
+ <div style="display:flex;gap:8px;margin-top:10px">
678
+ <input id="agents-reply-input" type="text" placeholder="reply to this agent…"
679
+ style="flex:1;background:transparent;border:1px solid var(--border,#333);border-radius:6px;padding:8px 10px;color:inherit" />
680
+ <button id="agents-reply-btn" class="btn">Send</button>
681
+ <button id="agents-cancel-btn" class="btn" style="border-color:#8a3b3b">Cancel turn</button>
682
+ </div>
683
+ </div>
684
+ </div>
685
+ </div>
686
+
630
687
  <!-- Wallet -->
631
688
  <div class="tab" id="tab-wallet">
632
689
  <div class="content-header">
@@ -2159,6 +2216,248 @@ setInterval(() => api('wallet').then(w => {
2159
2216
  document.getElementById('sidebar-balance').textContent = usdBig(w.balance) + ' USDC';
2160
2217
  }
2161
2218
  }), 30000);
2219
+
2220
+ // ── Agents tab (mission control) ────────────────────────────────────────
2221
+ // Control plane: the serve WebSocket (ws://127.0.0.1:3737/agent), reached
2222
+ // DIRECTLY from this page — the panel's own REST stays read-only. When the
2223
+ // host is offline the tab degrades to read-only registry rows + a banner.
2224
+ (function() {
2225
+ var serveUrl = null, serveAlive = false;
2226
+ var ws = null, wsOpen = null;
2227
+ var reqSeq = 0, pending = {};
2228
+ var hosted = []; // serve-hosted agents (controllable)
2229
+ var registry = []; // /api/agents live-registry rows (incl. CLI, dead)
2230
+ var selected = null, subscribedTo = null;
2231
+ var approvals = {}; // sessionId -> latest pending approval request
2232
+ var pollTimer = null;
2233
+
2234
+ var STATE_ORDER = { 'needs-input': 0, 'working': 1, 'idle': 2, 'inactive': 3, 'completed': 4, 'failed': 5 };
2235
+ var STATE_DOT = { 'needs-input': '#e6b450', 'working': '#58c05e', 'idle': '#8a93a3', 'inactive': '#555c66', 'completed': '#4a708b', 'failed': '#c05858' };
2236
+
2237
+ function ensureWs() {
2238
+ if (ws && ws.readyState === 1) return Promise.resolve(ws);
2239
+ if (wsOpen) return wsOpen;
2240
+ if (!serveUrl) return Promise.reject(new Error('agent host offline'));
2241
+ wsOpen = new Promise(function(resolve, reject) {
2242
+ var sock = new WebSocket(serveUrl);
2243
+ sock.onopen = function() { ws = sock; wsOpen = null; resolve(sock); };
2244
+ sock.onerror = function() { wsOpen = null; reject(new Error('ws error')); };
2245
+ sock.onclose = function() { ws = null; subscribedTo = null; };
2246
+ sock.onmessage = function(evt) {
2247
+ var msg; try { msg = JSON.parse(evt.data); } catch { return; }
2248
+ if (msg.kind === 'response' || msg.kind === 'error') {
2249
+ var r = pending[msg.id];
2250
+ if (r) { delete pending[msg.id]; r(msg.kind === 'error' ? null : (msg.payload || {})); }
2251
+ } else if (msg.kind === 'agent.event' && msg.payload) {
2252
+ onAgentEvent(msg.payload.sessionId, msg.payload.ev);
2253
+ } else if (msg.kind === 'approval.request' && msg.payload) {
2254
+ approvals[msg.payload.sessionId] = msg.payload;
2255
+ if (msg.payload.sessionId === selected) renderApproval();
2256
+ refreshAgents();
2257
+ }
2258
+ };
2259
+ });
2260
+ return wsOpen;
2261
+ }
2262
+
2263
+ function wsCall(kind, payload) {
2264
+ return ensureWs().then(function(sock) {
2265
+ return new Promise(function(resolve) {
2266
+ var id = 'panel-' + (++reqSeq);
2267
+ pending[id] = resolve;
2268
+ sock.send(JSON.stringify({ id: id, kind: kind, payload: payload || {} }));
2269
+ setTimeout(function() { if (pending[id]) { delete pending[id]; resolve(null); } }, 10000);
2270
+ });
2271
+ }).catch(function() { return null; });
2272
+ }
2273
+
2274
+ function transcriptAppend(text) {
2275
+ var pre = document.getElementById('agents-transcript');
2276
+ pre.textContent += text;
2277
+ pre.scrollTop = pre.scrollHeight;
2278
+ }
2279
+
2280
+ function renderStreamEvent(ev) {
2281
+ if (!ev) return;
2282
+ if (ev.kind === 'text_delta') transcriptAppend(ev.text);
2283
+ else if (ev.kind === 'capability_start') transcriptAppend('\\n▸ ' + ev.name + (ev.preview ? ' · ' + ev.preview : '') + '\\n');
2284
+ else if (ev.kind === 'turn_done') transcriptAppend('\\n— turn ' + (ev.reason || 'done') + ' —\\n');
2285
+ }
2286
+
2287
+ function onAgentEvent(sessionId, ev) {
2288
+ if (sessionId !== selected) return;
2289
+ renderStreamEvent(ev);
2290
+ if (ev && ev.kind === 'turn_done') refreshAgents();
2291
+ }
2292
+
2293
+ function mergedAgents() {
2294
+ var bySession = {};
2295
+ registry.forEach(function(r) {
2296
+ var controllable = false;
2297
+ var state = r.state;
2298
+ if (r.host === 'cli' && state !== 'completed' && state !== 'failed') state = 'inactive';
2299
+ bySession[r.sessionId] = { sessionId: r.sessionId, label: r.label, model: r.model, state: state,
2300
+ host: r.host, controllable: controllable, costUsd: r.costUsd, updatedAt: r.updatedAt };
2301
+ });
2302
+ hosted.forEach(function(a) {
2303
+ var state = a.state;
2304
+ if (a.pendingApprovals && a.pendingApprovals.length > 0) {
2305
+ state = 'needs-input';
2306
+ approvals[a.sessionId] = approvals[a.sessionId] || a.pendingApprovals[0];
2307
+ }
2308
+ bySession[a.sessionId] = { sessionId: a.sessionId, label: a.label, model: a.model, state: state,
2309
+ host: 'serve', controllable: true, updatedAt: a.lastEventAt };
2310
+ });
2311
+ var rows = Object.keys(bySession).map(function(k) { return bySession[k]; });
2312
+ rows.sort(function(a, b) {
2313
+ var d = (STATE_ORDER[a.state] ?? 9) - (STATE_ORDER[b.state] ?? 9);
2314
+ return d !== 0 ? d : (b.updatedAt || 0) - (a.updatedAt || 0);
2315
+ });
2316
+ return rows;
2317
+ }
2318
+
2319
+ function refreshAgents() {
2320
+ var rows = mergedAgents();
2321
+ var el = document.getElementById('agents-list');
2322
+ var needsInput = rows.filter(function(r) { return r.state === 'needs-input'; }).length;
2323
+ var badge = document.getElementById('agents-nav-badge');
2324
+ if (needsInput > 0) { badge.style.display = ''; badge.textContent = String(needsInput); }
2325
+ else badge.style.display = 'none';
2326
+
2327
+ if (rows.length === 0) { el.textContent = serveAlive ? 'No agents yet — dispatch one above.' : 'No agents recorded.'; return; }
2328
+ el.innerHTML = '';
2329
+ rows.forEach(function(r) {
2330
+ var row = document.createElement('div');
2331
+ row.style.cssText = 'display:flex;align-items:center;gap:8px;padding:7px 6px;border-radius:6px;cursor:pointer'
2332
+ + (r.sessionId === selected ? ';background:rgba(255,255,255,0.06)' : '');
2333
+ var dot = document.createElement('span');
2334
+ dot.style.cssText = 'width:9px;height:9px;border-radius:50%;flex:none;background:' + (STATE_DOT[r.state] || '#666');
2335
+ var label = document.createElement('span');
2336
+ label.textContent = r.label || r.sessionId.slice(0, 8);
2337
+ label.style.cssText = 'flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:13px';
2338
+ var meta = document.createElement('span');
2339
+ meta.textContent = r.state + ' · ' + (r.model || '').split('/').pop() + (r.host === 'cli' ? ' · cli' : '');
2340
+ meta.style.cssText = 'font-size:11px;color:var(--text-dim,#889)';
2341
+ row.appendChild(dot); row.appendChild(label); row.appendChild(meta);
2342
+ row.addEventListener('click', function() { selectAgent(r); });
2343
+ el.appendChild(row);
2344
+ });
2345
+ }
2346
+
2347
+ function renderApproval() {
2348
+ var box = document.getElementById('agents-approval');
2349
+ var req = selected ? approvals[selected] : null;
2350
+ if (!req) { box.style.display = 'none'; return; }
2351
+ box.style.display = '';
2352
+ document.getElementById('agents-approval-title').textContent = req.title || req.kind;
2353
+ document.getElementById('agents-approval-desc').textContent = req.description || '';
2354
+ var opts = document.getElementById('agents-approval-options');
2355
+ var msgBox = document.getElementById('agents-approval-message');
2356
+ msgBox.style.display = '';
2357
+ opts.innerHTML = '';
2358
+ (req.options && req.options.length ? req.options : ['approve', 'deny']).forEach(function(choice, i) {
2359
+ var btn = document.createElement('button');
2360
+ btn.className = 'btn';
2361
+ btn.textContent = (i + 1) + '. ' + choice;
2362
+ btn.addEventListener('click', function() {
2363
+ wsCall('agent.permissionResponse', {
2364
+ sessionId: req.sessionId, requestId: req.requestId,
2365
+ choice: choice, message: msgBox.value.trim() || undefined,
2366
+ }).then(function() {
2367
+ delete approvals[req.sessionId];
2368
+ msgBox.value = '';
2369
+ renderApproval();
2370
+ setTimeout(loadAgents, 400);
2371
+ });
2372
+ });
2373
+ opts.appendChild(btn);
2374
+ });
2375
+ }
2376
+
2377
+ function selectAgent(row) {
2378
+ selected = row.sessionId;
2379
+ document.getElementById('agents-peek').style.display = '';
2380
+ document.getElementById('agents-peek-title').textContent = row.label || row.sessionId.slice(0, 8);
2381
+ document.getElementById('agents-peek-state').textContent =
2382
+ row.state + ' · ' + (row.model || '') + (row.controllable ? '' : ' · read-only (attach in the terminal that owns it)');
2383
+ document.getElementById('agents-transcript').textContent = '';
2384
+ var canDrive = row.controllable && serveAlive;
2385
+ document.getElementById('agents-reply-input').disabled = !canDrive;
2386
+ document.getElementById('agents-reply-btn').disabled = !canDrive;
2387
+ document.getElementById('agents-cancel-btn').disabled = !canDrive;
2388
+ renderApproval();
2389
+ refreshAgents();
2390
+ if (!canDrive) return;
2391
+ if (subscribedTo && subscribedTo !== selected) wsCall('agents.unsubscribe', { sessionId: subscribedTo });
2392
+ var sid = selected;
2393
+ wsCall('agent.output.replay', { sessionId: sid }).then(function(resp) {
2394
+ if (selected !== sid) return;
2395
+ ((resp && resp.events) || []).forEach(renderStreamEvent);
2396
+ return wsCall('agents.subscribe', { sessionId: sid }).then(function() { subscribedTo = sid; });
2397
+ });
2398
+ }
2399
+
2400
+ function loadAgents() {
2401
+ return Promise.all([api('serve-info'), api('agents')]).then(function(res) {
2402
+ var info = res[0] || {}; var reg = res[1] || {};
2403
+ serveUrl = info.url || null;
2404
+ serveAlive = !!info.alive;
2405
+ registry = reg.agents || [];
2406
+ document.getElementById('agents-offline').style.display = serveAlive ? 'none' : '';
2407
+ document.getElementById('agents-dispatch-btn').disabled = !serveAlive;
2408
+ if (!serveAlive) { hosted = []; refreshAgents(); return; }
2409
+ return wsCall('agents.list', {}).then(function(resp) {
2410
+ hosted = (resp && resp.agents) || [];
2411
+ refreshAgents();
2412
+ });
2413
+ });
2414
+ }
2415
+
2416
+ function dispatchAgent() {
2417
+ var promptEl = document.getElementById('agents-dispatch-prompt');
2418
+ var prompt = promptEl.value.trim();
2419
+ if (!prompt || !serveAlive) return;
2420
+ var model = document.getElementById('agents-dispatch-model').value.trim() || undefined;
2421
+ var maxSpend = parseFloat(document.getElementById('agents-dispatch-maxspend').value);
2422
+ promptEl.value = '';
2423
+ promptEl.focus(); // keep focus for batch dispatch
2424
+ wsCall('agents.dispatch', {
2425
+ prompt: prompt, model: model,
2426
+ maxSpendUsd: isFinite(maxSpend) && maxSpend > 0 ? maxSpend : undefined,
2427
+ }).then(loadAgents);
2428
+ }
2429
+
2430
+ document.getElementById('agents-dispatch-btn').addEventListener('click', dispatchAgent);
2431
+ document.getElementById('agents-dispatch-prompt').addEventListener('keydown', function(e) {
2432
+ if (e.key === 'Enter') dispatchAgent();
2433
+ });
2434
+ document.getElementById('agents-reply-btn').addEventListener('click', function() {
2435
+ var input = document.getElementById('agents-reply-input');
2436
+ var text = input.value.trim();
2437
+ if (!text || !selected) return;
2438
+ input.value = '';
2439
+ transcriptAppend('\\n❯ ' + text + '\\n');
2440
+ wsCall('agents.reply', { sessionId: selected, text: text }).then(function() { setTimeout(loadAgents, 300); });
2441
+ });
2442
+ document.getElementById('agents-reply-input').addEventListener('keydown', function(e) {
2443
+ if (e.key === 'Enter') document.getElementById('agents-reply-btn').click();
2444
+ });
2445
+ document.getElementById('agents-cancel-btn').addEventListener('click', function() {
2446
+ if (selected) wsCall('agents.cancel', { sessionId: selected }).then(function() { setTimeout(loadAgents, 300); });
2447
+ });
2448
+
2449
+ document.addEventListener('tab:activated', function(e) {
2450
+ if (e.detail.name !== 'agents') return;
2451
+ loadAgents();
2452
+ if (!pollTimer) pollTimer = setInterval(loadAgents, 5000);
2453
+ });
2454
+ document.addEventListener('tab:deactivated', function(e) {
2455
+ if (e.detail.name !== 'agents') return;
2456
+ if (pollTimer) { clearInterval(pollTimer); pollTimer = null; }
2457
+ });
2458
+ // Badge even before first visit.
2459
+ loadAgents();
2460
+ })();
2162
2461
  </script>
2163
2462
  </body>
2164
2463
  </html>`;
@@ -21,6 +21,8 @@ import { listTasks, readTaskMeta, readTaskEvents, } from '../tasks/store.js';
21
21
  import { reconcileLostTasks } from '../tasks/lost-detection.js';
22
22
  import { taskLogPath } from '../tasks/paths.js';
23
23
  import { isTerminalTaskStatus } from '../tasks/types.js';
24
+ import { readLiveAgents } from '../session/live-registry.js';
25
+ import { BLOCKRUN_DIR } from '../config.js';
24
26
  import { getHTML } from './html.js';
25
27
  const sseClients = new Set();
26
28
  function json(res, data, status = 200) {
@@ -169,6 +171,45 @@ export function createPanelServer(port) {
169
171
  }
170
172
  // ─── API ──
171
173
  try {
174
+ // Read-only agent fleet view: live registry joined with session meta.
175
+ // All agent CONTROL flows through serve's gated WebSocket — the panel's
176
+ // REST surface stays read-only by design (no new mutating routes).
177
+ if (p === '/api/agents') {
178
+ const metas = new Map(listSessions().map((m) => [m.id, m]));
179
+ const agents = readLiveAgents().map((r) => {
180
+ const meta = metas.get(r.sessionId);
181
+ return {
182
+ ...r,
183
+ costUsd: meta?.costUsd,
184
+ turnCount: meta?.turnCount,
185
+ workDir: meta?.workDir,
186
+ };
187
+ });
188
+ json(res, { agents });
189
+ return;
190
+ }
191
+ if (p === '/api/serve-info') {
192
+ // serve writes ~/.blockrun/serve-url on listen (removed on clean
193
+ // exit); a 300ms probe distinguishes a live server from a stale file.
194
+ let wsUrl = null;
195
+ try {
196
+ wsUrl = fs.readFileSync(path.join(BLOCKRUN_DIR, 'serve-url'), 'utf-8').trim() || null;
197
+ }
198
+ catch { /* serve never ran */ }
199
+ let alive = false;
200
+ const hostMatch = wsUrl?.match(/^ws:\/\/([^/]+)\//);
201
+ if (hostMatch) {
202
+ try {
203
+ await fetch(`http://${hostMatch[1]}/`, { signal: AbortSignal.timeout(300) });
204
+ alive = true; // any HTTP response (even 404) = server is up
205
+ }
206
+ catch {
207
+ alive = false;
208
+ }
209
+ }
210
+ json(res, { url: wsUrl, alive });
211
+ return;
212
+ }
172
213
  if (p === '/api/stats') {
173
214
  const summary = getStatsSummary();
174
215
  json(res, {
package/dist/pricing.js CHANGED
@@ -45,6 +45,8 @@ export const MODEL_PRICING = {
45
45
  'anthropic/claude-sonnet-4.6': { input: 3.0, output: 15.0 },
46
46
  'anthropic/claude-sonnet-4.5': { input: 3.0, output: 15.0 },
47
47
  'anthropic/claude-haiku-4.5': { input: 1.0, output: 5.0 },
48
+ // Retired 2026-07-14: the gateway 400s on the dated id (undated is canonical).
49
+ // Kept for cost lookup on sessions recorded before the switch.
48
50
  'anthropic/claude-haiku-4.5-20251001': { input: 1.0, output: 5.0 },
49
51
  // OpenAI
50
52
  'openai/gpt-5-nano': { input: 0.05, output: 0.4 },
@@ -89,7 +91,8 @@ export const MODEL_PRICING = {
89
91
  'xai/grok-3-mini': { input: 0.3, output: 0.5 },
90
92
  'xai/grok-2-vision': { input: 2.0, output: 10.0 },
91
93
  'xai/grok-3': { input: 3.0, output: 15.0 },
92
- 'xai/grok-4.3': { input: 1.5, output: 4.0 }, // public flagship 2026-06-04, OpenRouter resale
94
+ 'xai/grok-4.3': { input: 1.5, output: 4.0 }, // 1M ctx; demoted from flagship 2026-07-14
95
+ 'xai/grok-4.5': { input: 2.5, output: 9.0 }, // xAI flagship — 500K ctx (note: less than 4.3's 1M)
93
96
  'xai/grok-build-0.1': { input: 1.5, output: 3.0 }, // agentic coding, OpenRouter resale
94
97
  // DeepSeek (gateway re-aliased these to V4 Flash on 2026-05-03; price
95
98
  // dropped from $0.28/$0.42 to $0.20/$0.40, context bumped 128K→1M).
@@ -577,19 +577,25 @@ export function getFallbackChain(tier, profile = 'auto') {
577
577
  // gateway redirected it to a now-dead model, so routing to it just wasted a slot.
578
578
  // 2026-07-11: nvidia/deepseek-v4-flash removed — the gateway no longer serves
579
579
  // it (410). Free tier is now led by nvidia/qwen3-next-80b-a3b-instruct (cleanest
580
- // free instruction-follower — no thinking leak / markdown fences, verified live),
581
- // with nvidia/llama-4-maverick kept as a DIFFERENT-family fallback for resilience.
580
+ // free instruction-follower — no thinking leak / markdown fences, verified live).
581
+ // 2026-07-14: nvidia/llama-4-maverick replaced by nvidia/mistral-nemotron as the
582
+ // different-family fallback. Maverick left the gateway catalog, and the free
583
+ // pool silently substitutes for it — a live probe showed both maverick and
584
+ // qwen3-next answering as `nvidia/nemotron-3-super-120b-a12b-free`. Two chain
585
+ // entries backed by the same pooled model is fake resilience: the fallback
586
+ // couldn't rescue a turn the primary had already failed. mistral-nemotron
587
+ // verifiably serves itself, so the chain is genuinely two families again.
582
588
  const FREE_MODELS_BY_CATEGORY = {
583
- coding: ['nvidia/qwen3-next-80b-a3b-instruct', 'nvidia/llama-4-maverick'],
584
- trading: ['nvidia/qwen3-next-80b-a3b-instruct', 'nvidia/llama-4-maverick'],
585
- research: ['nvidia/qwen3-next-80b-a3b-instruct', 'nvidia/llama-4-maverick'],
586
- reasoning: ['nvidia/qwen3-next-80b-a3b-instruct', 'nvidia/llama-4-maverick'],
587
- chat: ['nvidia/qwen3-next-80b-a3b-instruct', 'nvidia/llama-4-maverick'],
588
- creative: ['nvidia/qwen3-next-80b-a3b-instruct', 'nvidia/llama-4-maverick'],
589
+ coding: ['nvidia/qwen3-next-80b-a3b-instruct', 'nvidia/mistral-nemotron'],
590
+ trading: ['nvidia/qwen3-next-80b-a3b-instruct', 'nvidia/mistral-nemotron'],
591
+ research: ['nvidia/qwen3-next-80b-a3b-instruct', 'nvidia/mistral-nemotron'],
592
+ reasoning: ['nvidia/qwen3-next-80b-a3b-instruct', 'nvidia/mistral-nemotron'],
593
+ chat: ['nvidia/qwen3-next-80b-a3b-instruct', 'nvidia/mistral-nemotron'],
594
+ creative: ['nvidia/qwen3-next-80b-a3b-instruct', 'nvidia/mistral-nemotron'],
589
595
  };
590
596
  const DEFAULT_FREE_CHAIN = [
591
597
  'nvidia/qwen3-next-80b-a3b-instruct',
592
- 'nvidia/llama-4-maverick',
598
+ 'nvidia/mistral-nemotron',
593
599
  ];
594
600
  /**
595
601
  * Pick the next free model to try given the question category and which
@@ -28,7 +28,7 @@ const VISION_MODELS = new Set([
28
28
  'anthropic/claude-sonnet-5',
29
29
  'anthropic/claude-sonnet-4.6',
30
30
  'anthropic/claude-sonnet-4.5',
31
- 'anthropic/claude-haiku-4.5-20251001',
31
+ 'anthropic/claude-haiku-4.5',
32
32
  // OpenAI — multimodal flagships + o3 (Codex 5.3 is text-only, excluded).
33
33
  // GPT-5.6 family + 5.4-mini are vision; 5.4-nano is text-only.
34
34
  'openai/gpt-5.6-sol',
@@ -54,9 +54,10 @@ const VISION_MODELS = new Set([
54
54
  // Moonshot — K2.7 (flagship) + K2.6 are multimodal (image + video input)
55
55
  'moonshot/kimi-k2.7',
56
56
  'moonshot/kimi-k2.6',
57
- // NVIDIA inference — Llama 4 Maverick + Nemotron Nano VL are multimodal;
58
- // deepseek/qwen-coder are not.
59
- 'nvidia/llama-4-maverick',
57
+ // NVIDIA inference — Nemotron Nano VL is multimodal; deepseek/qwen-coder are
58
+ // not. Llama 4 Maverick dropped 2026-07-14: it left the gateway catalog, and
59
+ // listing it here contradicted routeRequest()'s own "maverick is text-only"
60
+ // note — the free profile would route a vision turn to a text-only model.
60
61
  'nvidia/nemotron-nano-12b-v2-vl',
61
62
  ]);
62
63
  /** Does this concrete gateway model accept image input? */
@@ -0,0 +1,24 @@
1
+ /**
2
+ * In-session scheduler service. A 30s tick checks due tasks and fires them
3
+ * by enqueueing the prompt into the session's input multiplexer — firings
4
+ * always land at turn boundaries, never mid-turn.
5
+ *
6
+ * Catch-up semantics: on service start, durable tasks whose nextFireAt
7
+ * passed while no session was running fire once (a slept-through task
8
+ * fires once, not once per missed interval — see markFired).
9
+ *
10
+ * Firing when NO session is running is out of scope here: the launchd
11
+ * agent hosts the payment proxy, not an agent loop. Durable tasks simply
12
+ * wait for the next session.
13
+ */
14
+ export interface SchedulerService {
15
+ stop: () => void;
16
+ /** Immediate due-check — used by tests and session-start catch-up. */
17
+ tick: () => number;
18
+ }
19
+ export declare function startSchedulerService(opts: {
20
+ sessionId: string;
21
+ enqueue: (text: string) => void;
22
+ /** Visibility line pushed to the transcript when a task fires. */
23
+ notify?: (line: string) => void;
24
+ }): SchedulerService;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * In-session scheduler service. A 30s tick checks due tasks and fires them
3
+ * by enqueueing the prompt into the session's input multiplexer — firings
4
+ * always land at turn boundaries, never mid-turn.
5
+ *
6
+ * Catch-up semantics: on service start, durable tasks whose nextFireAt
7
+ * passed while no session was running fire once (a slept-through task
8
+ * fires once, not once per missed interval — see markFired).
9
+ *
10
+ * Firing when NO session is running is out of scope here: the launchd
11
+ * agent hosts the payment proxy, not an agent loop. Durable tasks simply
12
+ * wait for the next session.
13
+ */
14
+ import { listScheduledTasks, markFired } from './store.js';
15
+ const TICK_MS = 30_000;
16
+ export function startSchedulerService(opts) {
17
+ const fire = (task) => {
18
+ markFired(task);
19
+ opts.notify?.(`[scheduler] firing task ${task.id} (${task.firedCount + 1}× so far): ${task.prompt.slice(0, 120)}\n`);
20
+ opts.enqueue(task.prompt);
21
+ };
22
+ const tick = () => {
23
+ const now = Date.now();
24
+ let fired = 0;
25
+ for (const task of listScheduledTasks()) {
26
+ if (!task.enabled || task.nextFireAt > now)
27
+ continue;
28
+ // Non-durable tasks belong to the session that created them.
29
+ if (!task.durable && task.sessionId !== opts.sessionId)
30
+ continue;
31
+ fire(task);
32
+ fired++;
33
+ }
34
+ return fired;
35
+ };
36
+ // Session-start catch-up for durable tasks that slept through their slot.
37
+ tick();
38
+ const timer = setInterval(tick, TICK_MS);
39
+ timer.unref(); // never keep the process alive just for the scheduler
40
+ return {
41
+ stop: () => clearInterval(timer),
42
+ tick,
43
+ };
44
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Scheduler persistence — one JSON file per task under
3
+ * ~/.blockrun/scheduler/<id>.json, atomically rewritten (tmp + rename),
4
+ * mirroring the task subsystem's meta.json convention.
5
+ */
6
+ import { type ScheduledTask } from './types.js';
7
+ export declare function schedulerDir(): string;
8
+ export declare function setSchedulerSessionId(id: string): void;
9
+ export declare function getSchedulerSessionId(): string;
10
+ export declare function saveScheduledTask(task: ScheduledTask): void;
11
+ export declare function deleteScheduledTask(id: string): boolean;
12
+ /** All non-expired tasks, pruning expired files as a side effect. */
13
+ export declare function listScheduledTasks(): ScheduledTask[];
14
+ export declare function createScheduledTask(opts: {
15
+ prompt: string;
16
+ intervalSec: number;
17
+ sessionId: string;
18
+ recurring?: boolean;
19
+ durable?: boolean;
20
+ fireImmediately?: boolean;
21
+ ttlMs?: number;
22
+ }): ScheduledTask | {
23
+ error: string;
24
+ };
25
+ /** Record a firing: advance nextFireAt, or disable a one-shot. */
26
+ export declare function markFired(task: ScheduledTask): ScheduledTask;