@ngockhoale/ckit 0.2.7 → 0.2.8

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 (60) hide show
  1. package/dist/src/adapters/launch/executor.d.ts +2 -0
  2. package/dist/src/adapters/launch/executor.js +12 -1
  3. package/dist/src/gui/server.js +1 -1
  4. package/dist/src/team/engine.d.ts +10 -0
  5. package/dist/src/team/engine.js +118 -10
  6. package/dist/src/team/journal.d.ts +2 -0
  7. package/dist/src/team/journal.js +28 -3
  8. package/dist/src/team/runners.d.ts +4 -0
  9. package/dist/src/team/runners.js +16 -2
  10. package/dist/src/team/types.d.ts +4 -0
  11. package/dist/src/tui/team/model.js +2 -0
  12. package/gui/app.css +1 -19
  13. package/gui/app.js +43 -53
  14. package/gui/comic/assets/backgrounds/command-center.svg +1 -0
  15. package/gui/comic/assets/backgrounds/developer-workshop.svg +1 -0
  16. package/gui/comic/assets/backgrounds/handoff-corridor.svg +1 -0
  17. package/gui/comic/assets/backgrounds/incident-room.svg +1 -0
  18. package/gui/comic/assets/backgrounds/mission-overview.svg +1 -0
  19. package/gui/comic/assets/backgrounds/quality-lab.svg +1 -0
  20. package/gui/comic/assets/backgrounds/reporting-hall.svg +1 -0
  21. package/gui/comic/assets/backgrounds/research-library.svg +1 -0
  22. package/gui/comic/assets/backgrounds/review-chamber.svg +1 -0
  23. package/gui/comic/assets/backgrounds/strategy-room.svg +1 -0
  24. package/gui/comic/assets/effects/check-burst.svg +1 -0
  25. package/gui/comic/assets/effects/focus-lines.svg +1 -0
  26. package/gui/comic/assets/effects/glow.svg +1 -0
  27. package/gui/comic/assets/effects/particles.svg +1 -0
  28. package/gui/comic/assets/effects/speed-lines.svg +1 -0
  29. package/gui/comic/assets/effects/warning-flash.svg +1 -0
  30. package/gui/comic/assets/frame/episode-banner.svg +1 -0
  31. package/gui/comic/assets/frame/panel-corner.svg +1 -0
  32. package/gui/comic/assets/props/approval-seal.svg +1 -0
  33. package/gui/comic/assets/props/bug-warning.svg +1 -0
  34. package/gui/comic/assets/props/capsule.svg +1 -0
  35. package/gui/comic/assets/props/checklist.svg +1 -0
  36. package/gui/comic/assets/props/code-display.svg +1 -0
  37. package/gui/comic/assets/props/document.svg +1 -0
  38. package/gui/comic/assets/props/files.svg +1 -0
  39. package/gui/comic/assets/props/folder.svg +1 -0
  40. package/gui/comic/assets/props/magnifier.svg +1 -0
  41. package/gui/comic/assets/props/package.svg +1 -0
  42. package/gui/comic/assets/props/rejection-mark.svg +1 -0
  43. package/gui/comic/assets/props/report.svg +1 -0
  44. package/gui/comic/assets/props/scroll.svg +1 -0
  45. package/gui/comic/assets/props/shield.svg +1 -0
  46. package/gui/comic/assets/props/tablet.svg +1 -0
  47. package/gui/comic/assets/props/workstation.svg +1 -0
  48. package/gui/comic/comic.css +130 -0
  49. package/gui/comic/contact-sheet.html +15 -0
  50. package/gui/comic/contact-sheet.js +41 -0
  51. package/gui/comic/engine.js +366 -0
  52. package/gui/comic/manifests/backgrounds.json +216 -0
  53. package/gui/comic/manifests/characters.json +96 -0
  54. package/gui/comic/manifests/effects.json +96 -0
  55. package/gui/comic/manifests/props.json +246 -0
  56. package/gui/comic/manifests/scenes.json +205 -0
  57. package/gui/comic/render.js +594 -0
  58. package/gui/index.html +2 -2
  59. package/gui/network.js +195 -284
  60. package/package.json +1 -1
package/gui/network.js CHANGED
@@ -1,14 +1,12 @@
1
- /* CKit live network canvas: hub, team zones, agent nodes, threads, particles, packages. Vanilla Canvas 2D. */
1
+ /* CKit live network canvas: org-chart tree (Director -> teams -> agents), orthogonal connectors, slow readable data chips. Vanilla Canvas 2D. */
2
2
  (function () {
3
3
  'use strict';
4
- var TEAM_COLOR = {director: '#A36BFF', ba: '#21D6E8', implement: '#F3A544', qc: '#4AD69A'};
4
+ var TEAM_COLOR = {director: '#a78bfa', ba: '#22d3ee', implement: '#f59e0b', qc: '#34d399'};
5
5
  var TEAM_LABEL = {director: 'DIRECTOR', ba: 'TEAM BA', implement: 'TEAM IMPLEMENT', qc: 'TEAM QC'};
6
- var ZONE_POS = {ba: [0.16, 0.5], implement: [0.84, 0.5], qc: [0.5, 0.78]}, HUB_POS = [0.5, 0.31];
7
- var ZONE_WIDE = {ba: [0.13, 0.56], implement: [0.63, 0.56], qc: [0.87, 0.56]}, HUB_WIDE = [0.38, 0.5];
8
6
  var STAGE_COUNT = 6; /* default; the app passes the real chip count to setStage */
9
7
  function hexA(hex, a) { var n = parseInt(hex.slice(1), 16); return 'rgba(' + (n >> 16) + ',' + ((n >> 8) & 255) + ',' + (n & 255) + ',' + a + ')'; }
10
- function rnd(a, b) { return a + Math.random() * (b - a); }
11
- function bez(p0, c, p1, t) { var u = 1 - t; return {x: u * u * p0.x + 2 * u * t * c.x + t * t * p1.x, y: u * u * p0.y + 2 * u * t * c.y + t * t * p1.y}; }
8
+ function mix(hex, k) { var n = parseInt(hex.slice(1), 16); function m(c) { return Math.round(c + (255 - c) * k); } return 'rgb(' + m(n >> 16) + ',' + m((n >> 8) & 255) + ',' + m(n & 255) + ')'; }
9
+ function P(x, y) { return {x: x, y: y}; }
12
10
  var avatarResolver = null, engineResolver = null, imgCache = {};
13
11
  var RM = window.matchMedia ? window.matchMedia('(prefers-reduced-motion: reduce)') : {matches: false};
14
12
  function portrait(a) {
@@ -17,87 +15,59 @@
17
15
  if (!im) { im = imgCache[url] = new Image(); im.decoding = 'async'; im.src = url; im.onerror = function () { im.bad = true; }; }
18
16
  return im.complete && im.naturalWidth && !im.bad ? im : null;
19
17
  }
20
- function ctrl(a, b, bend) { var mx = (a.x + b.x) / 2, my = (a.y + b.y) / 2, dx = b.x - a.x, dy = b.y - a.y; return {x: mx - dy * bend, y: my + dx * bend}; }
21
18
 
22
19
  function create(canvas) {
23
20
  var ctx = canvas.getContext('2d');
24
21
  var W = 0, H = 0, dpr = 1, S = 1, wide = false;
25
- var agents = [], nodes = {}, zones = {}, hub = {x: 0, y: 0, r: 44};
26
- var particles = [], sparks = [], packages = [], flashes = {}, hot = {}, ambient = [], noise = [];
27
- var stageIdx = -1, stageDone = 0, stageLoop = 1, selected = null, hover = null, onSelect = null, onFrame = null;
28
- var hubStats = null, slow = false, grid = null, t0 = performance.now(), verdictFlash = null, labels = [], linkTitle = {};
29
- function addLabel(A, B, text, color, bend) {
30
- if (!text) return; text = String(text).replace(/\s+/g, ' ').trim(); if (!text) return;
31
- if (text.length > 22) text = text.slice(0, 21) + '…';
32
- labels.push({a: A, b: B, text: text, color: color || '#21D6E8', bend: bend || .18, until: performance.now() + 3200});
33
- if (labels.length > 6) labels.shift(); /* bounded */
34
- }
35
-
36
- function initAmbient() {
37
- ambient = []; for (var i = 0; i < 80; i++) ambient.push({x: Math.random(), y: Math.random(), vx: rnd(-.004, .004), vy: rnd(-.004, .004), r: rnd(.6, 1.8), p: Math.random() * 6});
38
- noise = []; for (var j = 0; j < 16; j++) noise.push({a: [Math.random(), Math.random()], b: [Math.random(), Math.random()], bend: rnd(-.5, .5), ph: Math.random() * 6, sp: rnd(.3, 1)});
39
- }
22
+ var agents = [], nodes = {}, zones = {}, hub = {x: 0, y: 0, r: 30}, geo = {hubB: 0, bus1: 0, bus2: 0, teamB: 0, baseY: 0, plH: 22};
23
+ var chips = [], stageIdx = -1, stageDone = 0, stageLoop = 1, selected = null, hover = null, onSelect = null, onFrame = null;
24
+ var hubStats = null, slow = false, grid = null, t0 = performance.now(), subs = {};
25
+ function PW(s) { return Math.min(150, 120 * s + 12); }
40
26
  function buildGrid() {
41
27
  grid = document.createElement('canvas'); grid.width = W * dpr; grid.height = H * dpr;
42
28
  var g = grid.getContext('2d'); g.scale(dpr, dpr);
43
- g.fillStyle = 'rgba(120,150,190,0.10)';
44
- for (var x = 12; x < W; x += 24) for (var y = 12; y < H; y += 24) g.fillRect(x, y, 1, 1);
45
- g.strokeStyle = 'rgba(80,110,150,0.06)'; g.lineWidth = 1; g.beginPath();
46
- for (var x2 = 0; x2 < W; x2 += 120) { g.moveTo(x2 + .5, 0); g.lineTo(x2 + .5, H); }
47
- for (var y2 = 0; y2 < H; y2 += 120) { g.moveTo(0, y2 + .5); g.lineTo(W, y2 + .5); }
29
+ g.fillStyle = '#080d19'; g.fillRect(0, 0, W, H);
30
+ g.strokeStyle = '#1c2639'; g.lineWidth = .6; g.beginPath();
31
+ for (var x = 0; x <= W; x += 32) { g.moveTo(x + .5, 0); g.lineTo(x + .5, H); }
32
+ for (var y = 0; y <= H; y += 32) { g.moveTo(0, y + .5); g.lineTo(W, y + .5); }
48
33
  g.stroke();
49
- /* terrain silhouette along the bottom edge (static, drawn once per resize) */
50
- var base = H, amp = Math.min(70, H * .11);
51
- [[.10, .55, 'rgba(33,214,232,0.05)'], [.05, 1, 'rgba(12,20,36,0.85)']].forEach(function (L, li) {
52
- g.beginPath(); g.moveTo(0, base);
53
- for (var tx = 0; tx <= W; tx += 8) {
54
- var k = tx / W, yv = Math.sin(k * 9 + li * 2) * .35 + Math.sin(k * 23 + li) * .18 + Math.sin(k * 3.7) * .47;
55
- g.lineTo(tx, base - amp * (L[1] * .55 + .45 * Math.abs(yv)) - (li ? 0 : amp * .25));
56
- }
57
- g.lineTo(W, base); g.closePath(); g.fillStyle = L[2]; g.fill();
58
- if (li) { g.strokeStyle = 'rgba(33,214,232,0.18)'; g.lineWidth = 1; g.stroke(); }
59
- });
34
+ }
35
+ function teamIdsNow() {
36
+ var present = {}; agents.forEach(function (a) { if (a.team !== 'director') present[a.team] = 1; });
37
+ var ord = (window.CKNet.TEAM_ORDER || []).filter(function (t, i, arr) { return present[t] && arr.indexOf(t) === i; });
38
+ var rest = ['ba', 'implement', 'qc'].concat(Object.keys(present)).filter(function (t, i, arr) { return present[t] && ord.indexOf(t) < 0 && arr.indexOf(t) === i; });
39
+ return ord.concat(rest);
60
40
  }
61
41
  function layout() {
62
- /* wide = short/letterbox canvas: everything on one row so nothing overlaps or gets clipped */
63
42
  wide = H < 330 || W / H > 3.2;
64
- S = wide ? Math.max(.5, Math.min(W / 1150, H / 300, 1.15)) : Math.max(.55, Math.min(W / 1050, H / 600, 1.25));
65
- var zp = wide ? ZONE_WIDE : ZONE_POS, hp = wide ? HUB_WIDE : HUB_POS, old = nodes;
66
- var BUILTIN = {director: 1, ba: 1, implement: 1, qc: 1}, extraIds = [];
67
- agents.forEach(function (a) { if (!BUILTIN[a.team] && extraIds.indexOf(a.team) < 0) extraIds.push(a.team); });
68
- var teamIds = ['ba', 'implement', 'qc'].filter(function (t) { return agents.some(function (a) { return a.team === t; }); }).concat(extraIds);
69
- /* flow order (CKNet.TEAM_ORDER, set by the app) decides the placement; the default order keeps the classic layout */
70
- var ord = (window.CKNet.TEAM_ORDER || []).filter(function (t) { return teamIds.indexOf(t) >= 0; }), classic = ['ba', 'implement', 'qc'].filter(function (t) { return teamIds.indexOf(t) >= 0; });
71
- if (ord.length === teamIds.length) teamIds = ord;
72
- var reordered = !extraIds.length && teamIds.some(function (t, i) { return t !== classic[i]; });
73
- if (extraIds.length || reordered) {
74
- /* extra teams: re-pack. Wide: one row after the hub. Tall: ba + implement on the upper row, the rest (qc + extras) share a bottom row. Zones shrink so nothing overlaps. */
75
- zp = {}; var maxN = 1;
76
- teamIds.forEach(function (t) { maxN = Math.max(maxN, Math.min(4, agents.filter(function (a) { return a.team === t; }).length)); });
77
- var zw = 2 * 1.2 * (64 + 26 * maxN);
78
- if (wide) {
79
- var slots = teamIds.length + 1; hp = [.5 / slots, .5];
80
- teamIds.forEach(function (t, i) { zp[t] = [(i + 1.5) / slots, .56]; });
81
- S = Math.max(.4, Math.min(S, W / slots / zw));
82
- } else {
83
- /* clockwise from the hub: first two teams on the upper row (left, right), the rest along the bottom row from right to left */
84
- var top = teamIds.slice(0, 2), bottom = teamIds.slice(2).reverse();
85
- top.forEach(function (t, i) { zp[t] = [top.length === 1 ? .5 : (i ? .84 : .16), .44]; });
86
- bottom.forEach(function (t, i) { zp[t] = [(i + .5) / bottom.length, .84]; });
87
- S = Math.max(.4, Math.min(S * .8, W / Math.max(bottom.length, 2) / zw));
88
- }
43
+ var old = nodes, tids = teamIdsNow(), lists = {};
44
+ tids.forEach(function (t) { lists[t] = agents.filter(function (a) { return a.team === t; }); });
45
+ function mk(s, zig) {
46
+ var hr = 30 * s, rr = hr * 1.42, dirY = (wide ? 8 : 52) + rr + 9 * s, hubB = wide ? dirY + rr + 9 * s : dirY + rr + 16 * s + 46;
47
+ var tr = 30 * s, teamY = hubB + 22 * s + tr, teamB = teamY + tr + 34, bus2 = teamB + 10 * s, ar = 26 * s, agentY = bus2 + 14 * s + ar;
48
+ var plH = s < .72 ? 22 : 49, zdy = zig ? 2 * ar + 13 * s + plH + 6 : 0, sp = (PW(s) + 6) * (zig ? .56 : 1), tg = 12 * s, total = -tg;
49
+ tids.forEach(function (t) { total += Math.max(lists[t].length * sp, 108) + tg; });
50
+ return {s: s, zig: zig, hr: hr, dirY: dirY, hubB: hubB, tr: tr, teamY: teamY, teamB: teamB, bus2: bus2, bus1: (hubB + teamY - tr) / 2, ar: ar, agentY: agentY, plH: plH, zdy: zdy, sp: sp, tg: tg, total: total,
51
+ fit: agentY + zdy + ar + 13 * s + plH + 16 <= H - 10 && total <= W - 24};
89
52
  }
90
- hub = {x: W * hp[0], y: H * hp[1], r: 54 * S};
53
+ var s = Math.max(.4, Math.min(W / 1050, H / 600, 1.2)), M;
54
+ for (var it = 0; it < 40; it++) {
55
+ M = mk(s, false); if (M.fit) break;
56
+ M = mk(s, true); if (M.fit || s <= .4) break;
57
+ s = Math.max(.4, s * .94);
58
+ }
59
+ S = M.s; hub = {x: W / 2, y: M.dirY, r: M.hr};
60
+ geo = {hubB: M.hubB, bus1: M.bus1, bus2: M.bus2, teamB: M.teamB, baseY: H - 12, plH: M.plH};
91
61
  zones = {}; nodes = {};
92
- teamIds.forEach(function (tid) {
93
- var list = agents.filter(function (a) { return a.team === tid; }), n = Math.max(1, list.length);
94
- var rz = (64 + 26 * Math.min(n, 4)) * S, zy = Math.max(rz + 26 * S, Math.min(H - rz - 6, H * zp[tid][1]));
95
- zones[tid] = {id: tid, x: W * zp[tid][0], y: zy, r: rz, n: list.length, color: TEAM_COLOR[tid] || '#8A9AAF'};
96
- list.forEach(function (a, i) {
97
- var ang, rad = list.length === 1 ? 0 : rz * .52, o = old[a.id];
98
- if (list.length === 2) ang = i === 0 ? Math.PI : 0; else ang = -Math.PI / 2 + i * 2 * Math.PI / list.length;
99
- nodes[a.id] = {agent: a, x: zones[tid].x + Math.cos(ang) * rad, y: zy + Math.sin(ang) * rad - 8 * S, r: 38 * S, color: TEAM_COLOR[tid] || '#8A9AAF', state: o ? o.state : 'idle', prog: o ? o.prog : null};
62
+ var x = (W - M.total) / 2, gi = 0;
63
+ tids.forEach(function (t) {
64
+ var L = lists[t], n = L.length, cw = Math.max(n * M.sp, 108), cx = x + cw / 2, col = TEAM_COLOR[t] || '#8A9AAF';
65
+ zones[t] = {id: t, x: cx, y: M.teamY, r: M.tr, n: n, color: col};
66
+ L.forEach(function (a, i) {
67
+ var o = old[a.id], ay = M.agentY + (M.zig && gi % 2 ? M.zdy : 0); gi++;
68
+ nodes[a.id] = {agent: a, x: cx + (i - (n - 1) / 2) * M.sp, y: ay, r: M.ar, color: col, state: o ? o.state : 'idle', prog: o ? o.prog : null};
100
69
  });
70
+ x += cw + M.tg;
101
71
  });
102
72
  agents.filter(function (a) { return a.team === 'director'; }).forEach(function (a) { var o = old[a.id]; nodes[a.id] = {agent: a, x: hub.x, y: hub.y, r: hub.r, color: TEAM_COLOR.director, state: o ? o.state : 'idle', prog: null}; });
103
73
  }
@@ -105,102 +75,103 @@
105
75
  var r = canvas.parentElement.getBoundingClientRect();
106
76
  dpr = Math.min(window.devicePixelRatio || 1, 2); W = Math.max(300, r.width); H = Math.max(260, r.height);
107
77
  canvas.width = W * dpr; canvas.height = H * dpr; canvas.style.width = W + 'px'; canvas.style.height = H + 'px';
108
- var saved = {}; Object.keys(nodes).forEach(function (k) { saved[k] = nodes[k].state; });
109
- layout(); Object.keys(saved).forEach(function (k) { if (nodes[k]) nodes[k].state = saved[k]; });
110
- buildGrid();
78
+ layout(); buildGrid();
111
79
  }
112
80
  function ro() { if (window.ResizeObserver) new ResizeObserver(resize).observe(canvas.parentElement); window.addEventListener('resize', resize); }
113
81
 
114
- function endpoint(id) {
115
- if (nodes[id]) return nodes[id];
116
- if (zones[id]) return zones[id];
117
- return {x: hub.x, y: hub.y, color: TEAM_COLOR.director};
82
+ /* ---------- routes (orthogonal polylines through the tree) + chips ---------- */
83
+ function isAg(id) { return nodes[id] && nodes[id].agent.team !== 'director'; }
84
+ function teamOf(id) { if (isAg(id)) return nodes[id].agent.team; if (zones[id]) return id; return 'director'; }
85
+ function colorOf(id) { return TEAM_COLOR[teamOf(id)] || '#8A9AAF'; }
86
+ function ups(id) {
87
+ var t = teamOf(id), d = P(hub.x, geo.hubB); if (!zones[t]) return [d];
88
+ var z = zones[t], up = [P(z.x, z.y - z.r), P(z.x, geo.bus1), P(d.x, geo.bus1), d];
89
+ if (isAg(id)) { var n = nodes[id]; return [P(n.x, n.y - n.r), P(n.x, geo.bus2), P(z.x, geo.bus2), P(z.x, geo.teamB)].concat(up); }
90
+ return up;
118
91
  }
119
- function teamOf(id) { if (nodes[id]) return nodes[id].agent.team; if (zones[id]) return id; return 'director'; }
120
- function burst(x, y, color, n, kind) {
121
- for (var i = 0; i < n; i++) {
122
- var a = Math.random() * 6.283, sp = rnd(30, kind === 'fail' ? 190 : 140);
123
- sparks.push({x: x, y: y, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp, life: rnd(.5, 1.1), age: 0, color: color, g: kind === 'fail' ? 160 : 0, r: rnd(1, 2.4)});
92
+ function clean(pts) { var o = []; pts.forEach(function (p) { var l = o[o.length - 1]; if (!l || Math.abs(l.x - p.x) + Math.abs(l.y - p.y) > .5) o.push(p); }); return o; }
93
+ function route(from, to) {
94
+ var ft = teamOf(from), tt = teamOf(to), a = nodes[from], b = nodes[to], z = zones[ft];
95
+ if (ft === tt && z) {
96
+ if (isAg(from) && isAg(to)) return clean([P(a.x, a.y - a.r), P(a.x, geo.bus2), P(b.x, geo.bus2), P(b.x, b.y - b.r)]);
97
+ if (isAg(to)) return clean([P(z.x, geo.teamB), P(z.x, geo.bus2), P(b.x, geo.bus2), P(b.x, b.y - b.r)]);
98
+ if (isAg(from)) return clean([P(a.x, a.y - a.r), P(a.x, geo.bus2), P(z.x, geo.bus2), P(z.x, geo.teamB)]);
99
+ return [P(z.x, z.y)];
124
100
  }
101
+ var U = ups(from), V = ups(to).reverse();
102
+ if (U.length > 1 && V.length > 1) { U.pop(); V.shift(); } /* team -> team: turn on the bus, do not detour to the Director */
103
+ return clean(U.concat(V));
125
104
  }
126
- function addParticle(a, b, bend, color, opt) {
127
- opt = opt || {};
128
- particles.push({a: a, b: b, bend: bend, t: -(opt.delay || 0), speed: opt.speed || .55, color: color, size: opt.size || 3, trail: [], back: opt.back || false, bounces: opt.bounces || 0});
105
+ function plen(pts) { var c = [0], i; for (i = 1; i < pts.length; i++) c.push(c[i - 1] + Math.hypot(pts[i].x - pts[i - 1].x, pts[i].y - pts[i - 1].y)); return c; }
106
+ function at(ch, d) {
107
+ var pts = ch.pts, c = ch.cum, i = 1; if (pts.length < 2) return {x: pts[0].x, y: pts[0].y, dx: 0, dy: 1};
108
+ d = Math.max(0, Math.min(ch.len, d)); while (i < pts.length - 1 && c[i] < d) i++;
109
+ var sg = c[i] - c[i - 1] || 1, k = (d - c[i - 1]) / sg, ax = pts[i - 1], bx = pts[i];
110
+ return {x: ax.x + (bx.x - ax.x) * k, y: ax.y + (bx.y - ax.y) * k, dx: (bx.x - ax.x) / sg, dy: (bx.y - ax.y) / sg};
129
111
  }
130
- function pulse(from, to, kind, label) {
131
- var A = endpoint(from), B = endpoint(to), ta = teamOf(from), tb = teamOf(to);
132
- if (label && from !== to) addLabel(A, B, label, kind === 'fail' ? '#F05668' : kind === 'pass' ? '#4AD69A' : TEAM_COLOR[ta], ta === tb ? .45 : .18);
133
- var color = kind === 'fail' ? '#F05668' : kind === 'pass' ? '#4AD69A' : TEAM_COLOR[ta] || '#21D6E8';
134
- var key = [from, to].sort().join('|'); hot[key] = {until: performance.now() + 2200, c1: TEAM_COLOR[ta], c2: TEAM_COLOR[tb]};
135
- if (from === to) { burst(A.x, A.y, color, 8); return; }
136
- var intra = ta === tb && ta !== 'director' && nodes[from] && nodes[to];
137
- if (intra) {
138
- addParticle(A, B, .45, color, {speed: .9, size: 3.2});
139
- addParticle(B, A, -.45, color, {speed: .9, size: 2.2, delay: .45});
140
- burst(B.x, B.y, color, 5);
141
- } else {
142
- addParticle(A, B, .18, color, {speed: kind ? .7 : .5, size: 3.6});
143
- addParticle(A, B, .18, '#ffffff', {speed: kind ? .7 : .5, size: 1.8, delay: .08});
144
- if (kind === 'fail') { for (var i = 0; i < 4; i++) addParticle(A, B, .18 + rnd(-.1, .1), '#F05668', {speed: rnd(.5, .9), size: 2, delay: i * .06}); }
145
- if (kind === 'pass') { for (var j = 0; j < 4; j++) addParticle(A, B, .18 + rnd(-.1, .1), '#4AD69A', {speed: rnd(.5, .9), size: 2, delay: j * .06}); }
112
+ function polyPath(pts, rad) {
113
+ ctx.beginPath(); ctx.moveTo(pts[0].x, pts[0].y);
114
+ for (var i = 1; i < pts.length - 1; i++) {
115
+ var a = pts[i - 1], b = pts[i], c = pts[i + 1];
116
+ ctx.arcTo(b.x, b.y, c.x, c.y, Math.min(rad, Math.hypot(b.x - a.x, b.y - a.y) / 2, Math.hypot(c.x - b.x, c.y - b.y) / 2));
146
117
  }
118
+ if (pts.length > 1) ctx.lineTo(pts[pts.length - 1].x, pts[pts.length - 1].y);
119
+ }
120
+ function cut(t, n) { return t.length > n ? t.slice(0, n - 1) + '…' : t; }
121
+ function spawnChip(from, to, label, o) {
122
+ o = o || {}; var pts = route(from, to), cum = plen(pts), len = cum[cum.length - 1], now = performance.now(), mult = slow ? 3 : 1;
123
+ var text = label ? cut(String(label).replace(/\s+/g, ' ').trim(), o.max || 28) : '';
124
+ var dur = (text ? Math.max(2.4, Math.min(7, len / 55)) : Math.max(1.4, Math.min(4, len / 90))) * mult * 1000, start = now, key = from + '>' + to;
125
+ chips.forEach(function (c) { start = Math.max(start, c.start + (c.key === key ? Math.min(1, 40 / Math.max(c.len, 1)) * c.dur * 1.8 : 1800 * mult)); }); /* queue: chips never share a bus at the same moment */
126
+ if (chips.length >= 8) chips.shift();
127
+ chips.push({pts: pts, cum: cum, len: len, text: text, cap: o.caption || '', color: o.color || colorOf(from), key: key, start: start, dur: dur, hold: 600});
128
+ }
129
+ function chipLife(c) { return RM.matches ? 3400 : 250 + c.dur + c.hold + 400; }
130
+ function pulse(from, to, kind, label) {
131
+ spawnChip(from, to, label, {color: kind === 'fail' ? '#F05668' : kind === 'pass' ? '#34d399' : colorOf(from)});
147
132
  }
148
133
  function handoff(fromTeam, toTeam, title) {
149
- var A = zones[fromTeam] || hub, B = zones[toTeam] || hub;
150
- var dur = slow ? 90 : 2.6;
151
- packages.push({a: A, b: B, t: 0, dur: dur, title: title || 'HANDOFF', color: TEAM_COLOR[fromTeam] || '#A36BFF', c2: TEAM_COLOR[toTeam] || '#21D6E8', start: performance.now()});
152
- hot[['ho', fromTeam, toTeam].join('|')] = {until: performance.now() + dur * 1000 + 1500, c1: TEAM_COLOR[fromTeam], c2: TEAM_COLOR[toTeam], thick: true, a: A, b: B};
153
- burst(A.x, A.y, TEAM_COLOR[fromTeam] || '#fff', 26);
154
- addLabel(A, B, title || 'Handoff', TEAM_COLOR[toTeam] || '#21D6E8', -.16);
155
- if (title && zones[toTeam]) linkTitle[toTeam] = String(title);
134
+ spawnChip(fromTeam, toTeam, title || 'Handoff', {caption: 'HANDOFF', max: 32, color: TEAM_COLOR[fromTeam] || TEAM_COLOR.director});
156
135
  }
157
136
  function verdict(v) {
158
- var q = zones.qc || hub, c = v === 'PASS' ? '#4AD69A' : '#F05668';
159
- burst(q.x, q.y, c, v === 'PASS' ? 60 : 40, v === 'PASS' ? 'pass' : 'fail');
160
- verdictFlash = {until: performance.now() + 1600, color: c, v: v};
161
- if (v === 'FAIL' && zones.implement) { var A = q, B = zones.implement; addParticle(A, B, .3, '#F05668', {speed: .5, size: 4}); for (var i = 0; i < 6; i++) addParticle(A, B, .3 + rnd(-.15, .15), '#F05668', {speed: rnd(.4, .8), size: 2, delay: i * .07}); }
137
+ var ids = Object.keys(zones), from = zones.qc ? 'qc' : ids[ids.length - 1] || 'director';
138
+ spawnChip(from, 'director', String(v), {color: v === 'PASS' ? '#34d399' : '#F05668', max: 12});
162
139
  }
163
- function setStage(idx, loop, count) { if (count > 0) STAGE_COUNT = count; if (idx > stageIdx) stageDone = idx; stageIdx = idx; stageLoop = loop || 1; if (idx < stageDone && idx >= 0) stageDone = idx; }
164
- function setAgents(list) {
165
- agents = list.slice(); subs = {}; layout(); particles = []; packages = []; hot = {};
140
+ function drawChipRoutes(now) {
141
+ if (RM.matches) return;
142
+ chips.forEach(function (c) {
143
+ var t = now - c.start; if (t < 0 || t > c.dur + c.hold + 300 || c.pts.length < 2) return;
144
+ var al = Math.min(1, t / 250, (c.dur + c.hold + 300 - t) / 300);
145
+ ctx.save(); ctx.globalAlpha = al * .95; ctx.setLineDash([5, 8]); ctx.lineDashOffset = -26 * ((now % 1400) / 1400); ctx.lineWidth = 2; ctx.strokeStyle = c.color; ctx.shadowColor = c.color; ctx.shadowBlur = 8;
146
+ polyPath(c.pts, 8 * S); ctx.stroke(); ctx.restore();
147
+ });
166
148
  }
149
+ function drawChips(now) {
150
+ for (var i = chips.length - 1; i >= 0; i--) {
151
+ var c = chips[i], t = now - c.start, life = chipLife(c); if (t > life) { chips.splice(i, 1); continue; } if (t < 0) continue;
152
+ var pos, al;
153
+ if (RM.matches) { pos = at(c, c.len / 2); al = Math.min(1, t / 200, (life - t) / 400); }
154
+ else { var m = Math.max(0, Math.min(1, t / c.dur)), e = m < .5 ? 2 * m * m : 1 - Math.pow(-2 * m + 2, 2) / 2; pos = at(c, c.len * e); al = Math.min(1, t / 250, (life - t) / 400); }
155
+ ctx.save(); ctx.globalAlpha = Math.max(0, al);
156
+ if (!c.text) { ctx.globalCompositeOperation = 'lighter'; ctx.shadowColor = c.color; ctx.shadowBlur = 14; ctx.fillStyle = c.color; ctx.beginPath(); ctx.arc(pos.x, pos.y, 4, 0, 6.283); ctx.fill(); ctx.fillStyle = '#fff'; ctx.beginPath(); ctx.arc(pos.x, pos.y, 1.8, 0, 6.283); ctx.fill(); ctx.restore(); continue; }
157
+ var big = !!c.cap, h = big ? 32 : 22, fs = big ? 12 : 11;
158
+ ctx.font = '600 ' + fs + 'px ui-monospace,Menlo,monospace'; var label = '› ' + c.text, tw = ctx.measureText(label).width + 20;
159
+ var px = Math.max(4, Math.min(W - tw - 4, pos.x - tw / 2)), py = pos.y - h / 2;
160
+ ctx.shadowColor = c.color; ctx.shadowBlur = 12; ctx.fillStyle = 'rgba(20,14,10,.94)'; roundRect(px, py, tw, h, 8); ctx.fill(); ctx.shadowBlur = 0;
161
+ ctx.fillStyle = hexA(c.color, .16); ctx.fill(); ctx.strokeStyle = hexA(c.color, .9); ctx.lineWidth = 1; ctx.stroke();
162
+ ctx.textAlign = 'left'; ctx.textBaseline = 'middle';
163
+ if (big) { ctx.font = '700 8px ui-monospace,Menlo,monospace'; ctx.fillStyle = hexA(c.color, .85); ctx.fillText(c.cap, px + 10, py + 8); ctx.font = '600 ' + fs + 'px ui-monospace,Menlo,monospace'; }
164
+ ctx.fillStyle = mix(c.color, .7); ctx.fillText(label, px + 10, py + (big ? 22 : h / 2 + .5));
165
+ var ex = Math.abs(pos.dx) > .5 ? tw / 2 + 8 : h / 2 + 8, dx = pos.x + pos.dx * ex, dy = pos.y + pos.dy * ex; /* glowing dot leads the chip */
166
+ ctx.globalCompositeOperation = 'lighter'; ctx.shadowColor = c.color; ctx.shadowBlur = 12; ctx.fillStyle = c.color; ctx.beginPath(); ctx.arc(dx, dy, 3.5, 0, 6.283); ctx.fill();
167
+ ctx.restore();
168
+ }
169
+ }
170
+ function setStage(idx, loop, count) { if (count > 0) STAGE_COUNT = count; if (idx > stageIdx) stageDone = idx; stageIdx = idx; stageLoop = loop || 1; if (idx < stageDone && idx >= 0) stageDone = idx; }
171
+ function setAgents(list) { agents = list.slice(); subs = {}; chips = []; layout(); }
167
172
  function setState(id, st) { if (nodes[id]) nodes[id].state = st; }
168
173
  function setStep(id, prog) { if (nodes[id]) nodes[id].prog = prog; }
169
- function reset() { subs = {}; particles = []; packages = []; sparks = []; hot = {}; labels = []; linkTitle = {}; stageIdx = -1; stageDone = 0; Object.keys(nodes).forEach(function (k) { nodes[k].state = 'idle'; nodes[k].prog = null; }); }
170
-
171
- /* ---------- drawing ---------- */
172
- function drawThread(a, b, bend, color1, color2, alpha, width) {
173
- var c = ctrl(a, b, bend);
174
- ctx.beginPath(); ctx.moveTo(a.x, a.y); ctx.quadraticCurveTo(c.x, c.y, b.x, b.y);
175
- if (color1) { var g = ctx.createLinearGradient(a.x, a.y, b.x, b.y); g.addColorStop(0, hexA(color1, alpha)); g.addColorStop(1, hexA(color2 || color1, alpha)); ctx.strokeStyle = g; }
176
- else ctx.strokeStyle = 'rgba(110,135,170,' + alpha + ')';
177
- ctx.lineWidth = width || 1; ctx.stroke();
178
- }
179
- function drawZone(z, tms) {
180
- var f = flashes[z.id] ? Math.max(0, flashes[z.id] - tms) / 1200 : 0;
181
- var active = agents.some(function (a) { return a.team === z.id && nodes[a.id] && nodes[a.id].state === 'thinking'; });
182
- var br = active ? .55 + .25 * Math.sin(tms / 400) : .22;
183
- ctx.save();
184
- var g = ctx.createRadialGradient(z.x, z.y, z.r * .2, z.x, z.y, z.r * 1.15);
185
- g.addColorStop(0, hexA(z.color, .10 + (active ? .06 : 0) + f * .15)); g.addColorStop(1, hexA(z.color, 0));
186
- ctx.fillStyle = g; ctx.beginPath(); ctx.arc(z.x, z.y, z.r * 1.15, 0, 6.283); ctx.fill();
187
- /* hex boundary */
188
- ctx.beginPath();
189
- for (var i = 0; i < 6; i++) { var an = Math.PI / 6 + i * Math.PI / 3, px = z.x + Math.cos(an) * z.r * 1.05, py = z.y + Math.sin(an) * z.r * .98; if (i) ctx.lineTo(px, py); else ctx.moveTo(px, py); }
190
- ctx.closePath(); ctx.fillStyle = hexA(z.color, .045 + f * .12); ctx.fill();
191
- ctx.setLineDash([7, 5]); ctx.lineDashOffset = -tms / 90; ctx.lineWidth = 1.4; ctx.strokeStyle = hexA(z.color, br + f * .4);
192
- if (active) { ctx.shadowColor = z.color; ctx.shadowBlur = 14; }
193
- ctx.stroke(); ctx.setLineDash([]); ctx.shadowBlur = 0;
194
- /* corner ticks + label */
195
- ctx.font = '600 ' + Math.round(11 * Math.max(.9, S)) + 'px ui-monospace,Menlo,monospace'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
196
- var label = TEAM_LABEL[z.id], ly = z.y - z.r * .98 - 12 * S, tw = ctx.measureText(label).width + 24;
197
- ctx.fillStyle = 'rgba(8,13,22,.92)'; roundRect(z.x - tw / 2, ly - 11, tw, 22, 11); ctx.fill();
198
- ctx.strokeStyle = hexA(z.color, .75); ctx.lineWidth = 1; ctx.stroke();
199
- ctx.fillStyle = z.color; ctx.shadowColor = z.color; ctx.shadowBlur = active ? 10 : 0;
200
- ctx.beginPath(); ctx.arc(z.x - tw / 2 + 11, ly, 3, 0, 6.283); ctx.fill(); ctx.shadowBlur = 0;
201
- ctx.fillStyle = '#E6EEFA'; ctx.fillText(label, z.x + 5, ly + .5);
202
- ctx.restore();
203
- }
174
+ function reset() { subs = {}; chips = []; stageIdx = -1; stageDone = 0; Object.keys(nodes).forEach(function (k) { nodes[k].state = 'idle'; nodes[k].prog = null; }); }
204
175
  function roundRect(x, y, w, h, r) { ctx.beginPath(); ctx.moveTo(x + r, y); ctx.arcTo(x + w, y, x + w, y + h, r); ctx.arcTo(x + w, y + h, x, y + h, r); ctx.arcTo(x, y + h, x, y, r); ctx.arcTo(x, y, x + w, y, r); ctx.closePath(); }
205
176
  function drawHub(tms) {
206
177
  var x = hub.x, y = hub.y, r = hub.r, c = TEAM_COLOR.director;
@@ -238,7 +209,7 @@
238
209
  ctx.lineCap = 'butt';
239
210
  /* outer fine ring, rotating dashes */
240
211
  ctx.setLineDash([2, 7]); ctx.lineDashOffset = -tms / 120; ctx.strokeStyle = hexA(c, .4); ctx.lineWidth = 1;
241
- ctx.beginPath(); ctx.arc(x, y, rr2 + 9 * S, 0, 6.283); ctx.stroke(); ctx.setLineDash([]);
212
+ ctx.beginPath(); ctx.arc(x, y, rr2 + 5 * S, 0, 6.283); ctx.stroke(); ctx.setLineDash([]);
242
213
  /* core: avatar portrait inside a purple energy ring */
243
214
  var cr = r * .86 * pulseK, dn = nodes.director, im = dn ? portrait(dn.agent) : null;
244
215
  var cg = ctx.createRadialGradient(x - r * .3, y - r * .3, 1, x, y, cr);
@@ -264,7 +235,7 @@
264
235
  if (wide) { ctx.restore(); return; } /* no room under the hub on a letterbox canvas */
265
236
  /* label */
266
237
  ctx.font = '600 ' + Math.round(11 * Math.max(.9, S)) + 'px ui-monospace,Menlo,monospace';
267
- var lab = '♛ ' + (dn ? cut(dn.agent.name, 22) : 'DIRECTOR'), tw = ctx.measureText(lab).width + 24, ly = y + rr2 + 24 * S;
238
+ var lab = '♛ ' + (dn ? cut(dn.agent.name, 22) : 'DIRECTOR'), tw = ctx.measureText(lab).width + 24, ly = y + rr2 + 14;
268
239
  ctx.fillStyle = 'rgba(8,13,22,.92)'; roundRect(x - tw / 2, ly - 11, tw, 22, 11); ctx.fill();
269
240
  ctx.strokeStyle = hexA(c, .8); ctx.lineWidth = 1; ctx.stroke(); ctx.fillStyle = '#E6EEFA'; ctx.fillText(lab, x, ly + .5);
270
241
  var sub = stageLoop > 1 && stageIdx >= 1 ? 'LOOP ' + stageLoop : dn && dn.state === 'thinking' ? 'Orchestrating…' : '';
@@ -284,17 +255,52 @@
284
255
  ctx.fillStyle = '#05070D'; ctx.font = '800 ' + Math.round(br * (e.mark.length > 1 ? .95 : 1.25)) + 'px ui-monospace,Menlo,monospace'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
285
256
  ctx.fillText(e.mark, bx, by + .5); ctx.restore();
286
257
  }
287
- function drawLabels(now) {
288
- for (var i = labels.length - 1; i >= 0; i--) {
289
- var L = labels[i], left = L.until - now; if (left <= 0) { labels.splice(i, 1); continue; }
290
- var al = Math.min(1, left / 500, (3200 - left) / 250), c = ctrl(L.a, L.b, L.bend), m = bez(L.a, c, L.b, .5);
291
- ctx.save(); ctx.globalAlpha = Math.max(0, al); ctx.font = '600 10.5px ui-monospace,Menlo,monospace'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
292
- var tw = ctx.measureText(L.text).width + 18;
293
- ctx.fillStyle = 'rgba(7,11,20,.94)'; roundRect(m.x - tw / 2, m.y - 10, tw, 20, 5); ctx.fill(); ctx.strokeStyle = hexA(L.color, .85); ctx.lineWidth = 1; ctx.stroke();
294
- ctx.fillStyle = '#E6EEFA'; ctx.fillText(L.text, m.x, m.y + .5); ctx.restore();
295
- }
258
+
259
+ function drawTeam(z, tms) {
260
+ var act = agents.some(function (a) { return a.team === z.id && nodes[a.id] && nodes[a.id].state === 'thinking'; });
261
+ var list = agents.filter(function (a) { return a.team === z.id; }), done = list.length && list.every(function (a) { return nodes[a.id] && nodes[a.id].state === 'done'; });
262
+ var x = z.x, y = z.y, r = z.r, c = z.color, na = dimTeams && dimTeams.indexOf(z.id) < 0 ? .25 : 1, pk = act ? .5 + .5 * Math.sin(tms / 320) : 0;
263
+ ctx.save(); ctx.globalAlpha = na;
264
+ var g = ctx.createRadialGradient(x, y, r * .5, x, y, r * (1.9 + pk * .3)); g.addColorStop(0, hexA(c, act ? .4 : .2)); g.addColorStop(1, hexA(c, 0));
265
+ ctx.fillStyle = g; ctx.beginPath(); ctx.arc(x, y, r * (1.9 + pk * .3), 0, 6.283); ctx.fill();
266
+ ctx.fillStyle = '#152131'; ctx.shadowColor = c; ctx.shadowBlur = act ? 22 : 10; ctx.beginPath(); ctx.arc(x, y, r, 0, 6.283); ctx.fill();
267
+ ctx.lineWidth = 2.5; ctx.strokeStyle = done ? '#34d399' : c; ctx.stroke(); ctx.shadowBlur = 0;
268
+ var lead = list.filter(function (a) { return a.lead; })[0] || list[0], im = lead ? portrait(lead) : null;
269
+ if (im) { ctx.save(); ctx.beginPath(); ctx.arc(x, y, r - 3, 0, 6.283); ctx.clip(); ctx.globalAlpha = na * .85; ctx.drawImage(im, x - r, y - r, r * 2, r * 2); ctx.restore(); }
270
+ else { var nm = (TEAM_LABEL[z.id] || z.id).replace(/^TEAM\s+/i, ''), ini = nm.slice(0, nm.length > 3 ? 2 : 3).toUpperCase(); ctx.fillStyle = mix(c, .6); ctx.font = '800 ' + Math.round(r * .62) + 'px system-ui,sans-serif'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillText(ini, x, y + 1); }
271
+ if (act) { var ra = tms / 300; ctx.strokeStyle = '#fff'; ctx.lineWidth = 2; ctx.beginPath(); ctx.arc(x, y, r + 5, ra, ra + 1.3); ctx.stroke(); }
272
+ ctx.setLineDash([2, 5]); ctx.strokeStyle = hexA(c, .6); ctx.lineWidth = 1; ctx.beginPath(); ctx.arc(x, y, r + 5, 0, 6.283); ctx.stroke(); ctx.setLineDash([]);
273
+ var bx = x + r * .74, by = y - r * .74; ctx.fillStyle = '#080d19'; ctx.beginPath(); ctx.arc(bx, by, 6, 0, 6.283); ctx.fill(); ctx.fillStyle = done ? '#34d399' : act ? '#34d399' : '#5B6B82'; ctx.beginPath(); ctx.arc(bx, by, 4, 0, 6.283); ctx.fill();
274
+ ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.font = '700 ' + Math.round(Math.max(10, 11 * S)) + 'px ui-monospace,Menlo,monospace'; ctx.fillStyle = '#e2e8f0';
275
+ var label = cut(TEAM_LABEL[z.id] || String(z.id).toUpperCase(), 18), sy = y + r + 14;
276
+ ctx.fillText(label, x, sy);
277
+ ctx.font = '600 9.5px ui-monospace,Menlo,monospace'; ctx.fillStyle = hexA(c, .95);
278
+ ctx.fillText(z.n + (z.n === 1 ? ' agent' : ' agents') + (done ? ' · ✓ done' : act ? ' · working' : ''), x, sy + 13);
279
+ ctx.restore();
296
280
  }
297
- function cut(t, n) { return t.length > n ? t.slice(0, n - 1) + '…' : t; }
281
+ function teamDim(t) { return dimTeams && dimTeams.indexOf(t) < 0 ? .25 : 1; }
282
+ function drawConnectors(now) {
283
+ var tids = Object.keys(zones), hx = hub.x, rad = 8 * S;
284
+ ctx.save(); ctx.lineWidth = 1.2; ctx.strokeStyle = 'rgba(196,140,80,.55)';
285
+ var live = {};
286
+ chips.forEach(function (c) { if (now >= c.start && now < c.start + c.dur + c.hold) live[c.key] = c; });
287
+ function seg(pts, al, t) { ctx.globalAlpha = al * (t ? teamDim(t) : 1); polyPath(pts, rad); ctx.stroke(); }
288
+ tids.forEach(function (t) {
289
+ var z = zones[t], list = agents.filter(function (a) { return a.team === t; });
290
+ seg([P(hx, geo.hubB), P(hx, geo.bus1), P(z.x, geo.bus1), P(z.x, z.y - z.r)], 1, t);
291
+ if (!list.length) return;
292
+ seg([P(z.x, geo.teamB), P(z.x, geo.bus2)], 1, t);
293
+ list.forEach(function (a) { var n = nodes[a.id]; seg([P(z.x, geo.bus2), P(n.x, geo.bus2), P(n.x, n.y - n.r)], 1, t); });
294
+ });
295
+ /* faint dashed drops + baseline (decoration) */
296
+ ctx.setLineDash([3, 5]); ctx.lineWidth = 1; ctx.strokeStyle = 'rgba(196,140,80,.18)';
297
+ var ys = []; agents.forEach(function (a) { var n = nodes[a.id]; if (!n || a.team === 'director') return; var by = n.y + n.r + 13 * S + geo.plH + 4; ctx.globalAlpha = teamDim(a.team); ctx.beginPath(); ctx.moveTo(n.x, by); ctx.lineTo(n.x, geo.baseY); ctx.stroke(); });
298
+ var xs = Object.keys(nodes).filter(function (k) { return nodes[k].agent.team !== 'director'; }).map(function (k) { return nodes[k].x; });
299
+ if (xs.length) { ctx.globalAlpha = 1; ctx.beginPath(); ctx.moveTo(Math.min.apply(null, xs), geo.baseY); ctx.lineTo(Math.max.apply(null, xs), geo.baseY); ctx.stroke(); }
300
+ ctx.restore();
301
+ drawChipRoutes(now);
302
+ }
303
+
298
304
  var dimTeams = null;
299
305
  function drawNode(n, tms) {
300
306
  if (n.agent.team === 'director') return;
@@ -343,7 +349,7 @@
343
349
  if (st === 'done' || st === 'failed') { var bx = x + r * .74, by = y - r * .74, bb = Math.max(6, 8 * S); ctx.fillStyle = '#05070D'; ctx.beginPath(); ctx.arc(bx, by, bb + 2, 0, 6.283); ctx.fill(); ctx.fillStyle = ring; ctx.beginPath(); ctx.arc(bx, by, bb, 0, 6.283); ctx.fill(); ctx.fillStyle = '#05070D'; ctx.font = '800 ' + Math.round(bb * 1.3) + 'px sans-serif'; ctx.fillText(st === 'done' ? '✓' : '!', bx, by + .5); }
344
350
  /* name plate: name, then engine/model, or the live step while working */
345
351
  var subs = S < .72 ? [] : thinking && n.prog && n.prog.label ? ['STEP ' + n.prog.step + (n.prog.total ? '/' + n.prog.total : '') + ' · ' + n.prog.label] : [n.agent.cli || '', n.agent.model || ''].filter(Boolean);
346
- var maxW = Math.max(r * 2.75, 150), fit = function (t, f) { ctx.font = f; while (t.length > 4 && ctx.measureText(t).width > maxW - 18) t = t.slice(0, -2) + '…'; return t; };
352
+ var maxW = PW(S) - 4, fit = function (t, f) { ctx.font = f; while (t.length > 4 && ctx.measureText(t).width > maxW - 18) t = t.slice(0, -2) + '…'; return t; };
347
353
  var nmTxt = fit(cut(n.agent.name, 18), '600 ' + Math.round(Math.max(10.5, 12 * S)) + 'px system-ui,sans-serif'), f1 = ctx.font, f2 = '600 9.5px ui-monospace,Menlo,monospace'; subs = subs.map(function (t) { return fit(t, f2); });
348
354
  ctx.font = f1; var pw = ctx.measureText(nmTxt).width; ctx.font = f2; subs.forEach(function (t) { pw = Math.max(pw, ctx.measureText(t).width); });
349
355
  pw += 22; var ph = 22 + subs.length * 13 + (subs.length ? 1 : 0), px = x - pw / 2, py = y + r + 13 * S;
@@ -353,61 +359,39 @@
353
359
  if (frac) { ctx.fillStyle = c; ctx.fillRect(px + 8, py + ph - 3, (pw - 16) * frac, 2); }
354
360
  ctx.restore();
355
361
  }
356
- function drawPackage(p, tms) {
357
- var c = ctrl(p.a, p.b, -.16), e = Math.min(1, p.t / p.dur), k = e < .5 ? 2 * e * e : 1 - Math.pow(-2 * e + 2, 2) / 2;
358
- var pos = bez(p.a, c, p.b, k);
359
- ctx.save();
360
- ctx.globalCompositeOperation = 'lighter';
361
- for (var i = 1; i < 14; i++) { var tp = bez(p.a, c, p.b, Math.max(0, k - i * .012)); ctx.fillStyle = hexA(p.color, .35 - i * .024); ctx.beginPath(); ctx.arc(tp.x, tp.y, 7 - i * .4, 0, 6.283); ctx.fill(); }
362
- ctx.globalCompositeOperation = 'source-over';
363
- var w = 150 * Math.max(.85, S), h = 40 * Math.max(.85, S), bob = Math.sin(tms / 200) * 2;
364
- var gx = ctx.createLinearGradient(pos.x - w / 2, 0, pos.x + w / 2, 0); gx.addColorStop(0, hexA(p.color, .95)); gx.addColorStop(1, hexA(p.c2, .95));
365
- ctx.shadowColor = p.c2; ctx.shadowBlur = 26; ctx.fillStyle = 'rgba(8,13,22,.96)'; roundRect(pos.x - w / 2, pos.y - h / 2 + bob, w, h, 9); ctx.fill();
366
- ctx.lineWidth = 2; ctx.strokeStyle = gx; ctx.stroke(); ctx.shadowBlur = 0;
367
- ctx.font = '18px system-ui'; ctx.textAlign = 'left'; ctx.textBaseline = 'middle'; ctx.fillStyle = '#fff'; ctx.strokeStyle = p.c2; ctx.lineWidth = 1.5; ctx.strokeRect(pos.x - w / 2 + 10, pos.y - 7 + bob, 14, 14); ctx.beginPath(); ctx.moveTo(pos.x - w / 2 + 10, pos.y - 2 + bob); ctx.lineTo(pos.x - w / 2 + 24, pos.y - 2 + bob); ctx.stroke();
368
- ctx.font = '700 10px ui-monospace,Menlo,monospace'; ctx.fillStyle = '#9FB0C6'; ctx.fillText('HANDOFF', pos.x - w / 2 + 36, pos.y - 7 + bob);
369
- var t = p.title.length > 17 ? p.title.slice(0, 16) + '…' : p.title; ctx.font = '600 11px system-ui,sans-serif'; ctx.fillStyle = '#EAF2FF'; ctx.fillText(t, pos.x - w / 2 + 36, pos.y + 8 + bob);
370
- ctx.restore();
371
- }
372
-
373
362
 
374
- /* ---------- subagent squad ---------- */
375
- var subs = {};
363
+ /* ---------- subagent squad (fanned below the parent) ---------- */
376
364
  function spawnSub(parentId, childId, kind) {
377
365
  var pn = nodes[parentId]; if (!pn || subs[childId]) return;
378
366
  var sibs = Object.keys(subs).filter(function (k) { return subs[k].parent === parentId; }).length;
379
367
  subs[childId] = {id: childId, parent: parentId, kind: kind || 'sub', born: performance.now(), idx: sibs, state: 'run', say: null, end: 0, ok: true, x: pn.x, y: pn.y, color: pn.color};
380
- burst(pn.x, pn.y, pn.color, 10);
381
368
  }
382
369
  function subActivity(childId, text) { if (subs[childId]) subs[childId].say = {text: String(text), t0: performance.now()}; }
383
- function finishSub(childId, ok) { var d = subs[childId]; if (!d) return; d.state = 'done'; d.ok = ok; d.end = performance.now(); burst(d.x, d.y, ok ? '#4AD69A' : '#F05668', 18); }
370
+ function finishSub(childId, ok) { var d = subs[childId]; if (!d) return; d.state = 'done'; d.ok = ok; d.end = performance.now(); }
384
371
  function subCount(parentId) { return Object.keys(subs).filter(function (k) { return subs[k].parent === parentId && subs[k].state === 'run'; }).length; }
385
372
  function drawSubs(now, tms) {
386
373
  Object.keys(subs).forEach(function (k) {
387
374
  var d = subs[k], pn = nodes[d.parent];
388
375
  if (!pn) { delete subs[k]; return; }
389
- var age = Math.max(0, (now - d.born) / 1000), pop = Math.min(1, age / .45), ease = 1 - Math.pow(1 - pop, 3);
376
+ var age = Math.max(0, (now - d.born) / 1000), ease = 1 - Math.pow(1 - Math.min(1, age / .45), 3);
390
377
  var fade = d.state === 'done' ? Math.max(0, 1 - (now - d.end) / 1800) : 1;
391
378
  if (fade <= 0) { delete subs[k]; return; }
392
- var sibs = Object.keys(subs).filter(function (q) { return subs[q].parent === d.parent; }), i = sibs.indexOf(k), n = sibs.length;
393
- var base = Math.atan2(pn.y - hub.y, pn.x - hub.x), ang = base + (i - (n - 1) / 2) * .8 + Math.sin(tms / 1500 + i) * .12;
394
- var rad = (pn.r + 70 * S) * ease, tx = pn.x + Math.cos(ang) * rad, ty = pn.y + Math.sin(ang) * rad + Math.sin(tms / 600 + i * 2) * 3;
395
- d.x = tx; d.y = ty; var r = 9 * S * ease, col = d.ok ? pn.color : '#F05668';
396
- ctx.save(); ctx.globalAlpha = fade;
397
- ctx.setLineDash([3, 4]); ctx.lineDashOffset = -tms / 60; ctx.strokeStyle = hexA(pn.color, .7); ctx.lineWidth = 1;
398
- ctx.beginPath(); ctx.moveTo(pn.x, pn.y); ctx.lineTo(tx, ty); ctx.stroke(); ctx.setLineDash([]);
399
- ctx.shadowColor = col; ctx.shadowBlur = 12; ctx.fillStyle = 'rgba(8,13,22,.96)'; ctx.beginPath(); ctx.arc(tx, ty, r, 0, 6.283); ctx.fill();
379
+ var sibs = Object.keys(subs).filter(function (q) { return subs[q].parent === d.parent; }), i = sibs.indexOf(k), n = sibs.length, r = 8 * S * ease + 1;
380
+ var plBot = pn.y + pn.r + 13 * S + geo.plH, spread = 22 * S, tx = pn.x + (i - (n - 1) / 2) * spread, ty = plBot + (12 + 14 * ease) * S + Math.sin(tms / 600 + i * 2) * 1.5;
381
+ d.x = tx; d.y = ty; var col = d.ok ? pn.color : '#F05668';
382
+ ctx.save(); ctx.globalAlpha = fade * teamDim(pn.agent.team);
383
+ ctx.setLineDash([3, 3]); ctx.lineDashOffset = -tms / 60; ctx.strokeStyle = hexA(pn.color, .7); ctx.lineWidth = 1;
384
+ ctx.beginPath(); ctx.moveTo(pn.x, plBot + 1); ctx.lineTo(pn.x, plBot + 5 * S); ctx.lineTo(tx, plBot + 5 * S); ctx.lineTo(tx, ty - r); ctx.stroke(); ctx.setLineDash([]);
385
+ ctx.shadowColor = col; ctx.shadowBlur = 10; ctx.fillStyle = '#152131'; ctx.beginPath(); ctx.arc(tx, ty, r, 0, 6.283); ctx.fill();
400
386
  ctx.strokeStyle = col; ctx.lineWidth = 1.5; ctx.stroke(); ctx.shadowBlur = 0;
401
- if (d.state === 'run') { var ra = tms / 250 + i; ctx.strokeStyle = '#fff'; ctx.lineWidth = 1.5; ctx.beginPath(); ctx.arc(tx, ty, r + 3, ra, ra + 1.2); ctx.stroke(); }
402
- ctx.fillStyle = d.state === 'done' ? col : '#EAF2FF'; ctx.font = '700 ' + Math.round(10 * S) + 'px sans-serif'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
387
+ if (d.state === 'run') { var ra = tms / 250 + i; ctx.strokeStyle = '#fff'; ctx.lineWidth = 1.2; ctx.beginPath(); ctx.arc(tx, ty, r + 2.5, ra, ra + 1.2); ctx.stroke(); }
388
+ ctx.fillStyle = d.state === 'done' ? col : '#EAF2FF'; ctx.font = '700 ' + Math.round(9 * Math.max(.8, S)) + 'px sans-serif'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
403
389
  ctx.fillText(d.state === 'done' ? (d.ok ? '✓' : '✕') : '◆', tx, ty + .5);
404
- ctx.font = '600 9px ui-monospace,Menlo,monospace'; ctx.fillStyle = '#9FB0C6';
405
- ctx.fillText(d.kind.length > 12 ? d.kind.slice(0, 11) + '…' : d.kind, tx, ty + r + 10);
406
390
  if (d.say && now - d.say.t0 < 4200 && d.state === 'run') {
407
- var txt = d.say.text.length > 44 ? d.say.text.slice(0, 43) + '…' : d.say.text, shown = txt.slice(0, Math.floor((now - d.say.t0) / 28));
408
- ctx.font = '500 10px ui-monospace,Menlo,monospace'; var tw = ctx.measureText(txt).width + 14, bx = Math.min(W - tw - 4, Math.max(4, tx - tw / 2)), by = ty - r - 26;
409
- ctx.fillStyle = 'rgba(12,18,30,.95)'; ctx.strokeStyle = hexA(pn.color, .8); ctx.lineWidth = 1; roundRect(bx, by, tw, 18, 5); ctx.fill(); ctx.stroke();
410
- ctx.fillStyle = '#E6EEFA'; ctx.textAlign = 'left'; ctx.fillText(shown, bx + 7, by + 9.5);
391
+ var txt = cut(d.say.text, 40), shown = txt.slice(0, Math.floor((now - d.say.t0) / 28));
392
+ ctx.font = '500 10px ui-monospace,Menlo,monospace'; var tw = ctx.measureText(txt).width + 14, bx = Math.min(W - tw - 4, Math.max(4, tx - tw / 2)), by = ty + r + 6;
393
+ ctx.fillStyle = 'rgba(20,14,10,.95)'; ctx.strokeStyle = hexA(pn.color, .8); ctx.lineWidth = 1; roundRect(bx, by, tw, 18, 5); ctx.fill(); ctx.stroke();
394
+ ctx.fillStyle = '#EDE3D6'; ctx.textAlign = 'left'; ctx.fillText(shown, bx + 7, by + 9.5);
411
395
  }
412
396
  ctx.restore();
413
397
  });
@@ -419,103 +403,30 @@
419
403
  requestAnimationFrame(frame);
420
404
  }
421
405
  function draw(now) {
422
- var dt = Math.max(0, Math.min(.05, (now - last) / 1000)); last = now; var tms = RM.matches ? 0 : now - t0;
423
- if (RM.matches) { particles.length = 0; sparks.length = 0; }
406
+ last = now; var tms = RM.matches ? 0 : now - t0;
424
407
  ctx.setTransform(dpr, 0, 0, dpr, 0, 0); ctx.clearRect(0, 0, W, H);
425
408
  ctx.drawImage(grid, 0, 0, W, H);
426
- var bg = ctx.createRadialGradient(hub.x, hub.y, 10, hub.x, hub.y, Math.max(W, H) * .7); bg.addColorStop(0, 'rgba(40,24,80,.28)'); bg.addColorStop(1, 'rgba(5,7,13,0)');
427
- ctx.fillStyle = bg; ctx.fillRect(0, 0, W, H);
428
- /* noise threads */
429
- ctx.lineWidth = 1;
430
- noise.forEach(function (n) {
431
- var a = {x: n.a[0] * W, y: n.a[1] * H}, b = {x: n.b[0] * W, y: n.b[1] * H};
432
- drawThread(a, b, n.bend, null, null, .03 + .05 * (.5 + .5 * Math.sin(tms / 1000 * n.sp + n.ph)), 1);
433
- });
434
- /* pipeline threads between zones */
435
- var zl = zones, pairs = [['ba', 'implement'], ['implement', 'qc'], ['qc', 'ba']];
436
- pairs.forEach(function (p) { if (zl[p[0]] && zl[p[1]]) drawThread(zl[p[0]], zl[p[1]], -.14, null, null, .28, 1); });
437
- if (zl.qc && zl.implement) drawThread(zl.qc, zl.implement, .2, '#F05668', '#F3A544', .12, 1);
438
- /* persistent Director -> team links; chip shows the latest real handoff title to that team */
439
- Object.keys(zones).forEach(function (tid) {
440
- var z = zones[tid], col = TEAM_COLOR[tid] || '#21D6E8';
441
- drawThread(hub, z, -.08, '#A36BFF', col, .5, 1.6);
442
- var t = linkTitle[tid]; if (!t) return;
443
- var m = bez(hub, ctrl(hub, z, -.08), z, .55);
444
- ctx.save(); ctx.font = '600 10px ui-monospace,Menlo,monospace'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
445
- t = cut(t, 22); var tw = ctx.measureText(t).width + 16;
446
- ctx.fillStyle = 'rgba(7,11,20,.92)'; roundRect(m.x - tw / 2, m.y - 9, tw, 18, 4); ctx.fill(); ctx.strokeStyle = hexA(col, .7); ctx.lineWidth = 1; ctx.stroke();
447
- ctx.fillStyle = '#DCE6F5'; ctx.fillText(t, m.x, m.y + .5); ctx.restore();
448
- });
449
- /* hub -> agents */
450
- Object.keys(nodes).forEach(function (id) { var n = nodes[id]; if (n.agent.team !== 'director') drawThread(hub, n, .1, null, null, .22, 1); });
451
- /* intra team */
452
- Object.keys(zones).forEach(function (tid) {
453
- var ns = agents.filter(function (a) { return a.team === tid; }).map(function (a) { return nodes[a.id]; });
454
- for (var i = 0; i < ns.length; i++) for (var j = i + 1; j < ns.length; j++) drawThread(ns[i], ns[j], .25, TEAM_COLOR[tid], TEAM_COLOR[tid], .3, 1);
455
- });
456
- /* hot threads */
457
- Object.keys(hot).forEach(function (k) {
458
- var h = hot[k], left = h.until - now; if (left <= 0) { delete hot[k]; return; }
459
- var al = Math.min(1, left / 700);
460
- if (h.thick) { drawThread(h.a, h.b, -.16, h.c1, h.c2, .35 * al, 8); drawThread(h.a, h.b, -.16, h.c1, h.c2, .95 * al, 2.5); return; }
461
- var ids = k.split('|'), A = endpoint(ids[0]), B = endpoint(ids[1]);
462
- var intra = nodes[ids[0]] && nodes[ids[1]] && nodes[ids[0]].agent.team === nodes[ids[1]].agent.team;
463
- drawThread(A, B, intra ? .25 : .18, h.c1, h.c2, .9 * al, 2);
464
- });
465
- /* ambient */
466
- ctx.globalCompositeOperation = 'lighter';
467
- ambient.forEach(function (a) {
468
- if (!RM.matches) { a.x += a.vx * dt; a.y += a.vy * dt; } if (a.x < 0) a.x = 1; if (a.x > 1) a.x = 0; if (a.y < 0) a.y = 1; if (a.y > 1) a.y = 0;
469
- ctx.fillStyle = 'rgba(150,200,255,' + (.12 + .14 * Math.sin(tms / 900 + a.p)) + ')'; ctx.beginPath(); ctx.arc(a.x * W, a.y * H, a.r, 0, 6.283); ctx.fill();
470
- });
471
- ctx.globalCompositeOperation = 'source-over';
472
- Object.keys(zones).forEach(function (k) { drawZone(zones[k], tms); });
409
+ drawConnectors(now);
410
+ Object.keys(zones).forEach(function (k) { drawTeam(zones[k], tms); });
473
411
  drawHub(tms);
474
412
  Object.keys(nodes).forEach(function (k) { drawNode(nodes[k], tms); });
475
413
  drawSubs(now, tms);
476
- /* particles */
477
- ctx.globalCompositeOperation = 'lighter';
478
- for (var i = particles.length - 1; i >= 0; i--) {
479
- var p = particles[i]; p.t += dt * p.speed; if (p.t < 0) continue;
480
- if (p.t >= 1) { particles.splice(i, 1); continue; }
481
- var c = ctrl(p.a, p.b, p.bend), pos = bez(p.a, c, p.b, p.t);
482
- p.trail.push(pos); if (p.trail.length > 14) p.trail.shift();
483
- for (var q = 0; q < p.trail.length; q++) { var f = q / p.trail.length; ctx.fillStyle = hexA(p.color, f * .5); ctx.beginPath(); ctx.arc(p.trail[q].x, p.trail[q].y, p.size * f, 0, 6.283); ctx.fill(); }
484
- ctx.shadowColor = p.color; ctx.shadowBlur = 12; ctx.fillStyle = '#fff'; ctx.beginPath(); ctx.arc(pos.x, pos.y, p.size * .7, 0, 6.283); ctx.fill(); ctx.shadowBlur = 0;
485
- if (p.t > .96 && p.size > 2.5) burst(pos.x, pos.y, p.color, 3);
486
- }
487
- for (var s = sparks.length - 1; s >= 0; s--) {
488
- var sp = sparks[s]; sp.age += dt; if (sp.age > sp.life) { sparks.splice(s, 1); continue; }
489
- sp.x += sp.vx * dt; sp.y += sp.vy * dt; sp.vy += sp.g * dt; sp.vx *= .985;
490
- ctx.fillStyle = hexA(sp.color, 1 - sp.age / sp.life); ctx.beginPath(); ctx.arc(sp.x, sp.y, sp.r, 0, 6.283); ctx.fill();
491
- }
492
- ctx.globalCompositeOperation = 'source-over';
493
- for (var k2 = packages.length - 1; k2 >= 0; k2--) {
494
- var pk = packages[k2]; pk.t += dt;
495
- if (pk.t >= pk.dur) { burst(pk.b.x, pk.b.y, pk.c2, 34); flashes[pk.b.id || 'x'] = now + 1200; packages.splice(k2, 1); continue; }
496
- drawPackage(pk, tms);
497
- }
498
- drawLabels(now);
499
- if (verdictFlash && verdictFlash.until > now) {
500
- var al2 = (verdictFlash.until - now) / 1600, q2 = zones.qc || hub;
501
- ctx.save(); ctx.font = '800 ' + Math.round(26 * S) + 'px ui-monospace,Menlo,monospace'; ctx.textAlign = 'center'; ctx.fillStyle = hexA(verdictFlash.color, al2);
502
- ctx.shadowColor = verdictFlash.color; ctx.shadowBlur = 24; ctx.fillText(verdictFlash.v, q2.x, q2.y - q2.r * 1.4 - (1 - al2) * 18); ctx.restore();
503
- }
414
+ drawChips(now);
504
415
  if (onFrame) onFrame();
505
416
  }
506
417
  function hit(e) {
507
418
  var r = canvas.getBoundingClientRect(), x = e.clientX - r.left, y = e.clientY - r.top, best = null;
508
- Object.keys(nodes).forEach(function (k) { var n = nodes[k], d = Math.hypot(n.x - x, n.y - y); if (d < Math.max(n.r + 8, 30)) best = k; });
419
+ Object.keys(nodes).forEach(function (k) { var n = nodes[k], d = Math.hypot(n.x - x, n.y - y); if (d < Math.max(n.r + 8, 24)) best = k; });
509
420
  return best;
510
421
  }
511
422
  canvas.addEventListener('mousemove', function (e) { hover = hit(e); canvas.style.cursor = hover ? 'pointer' : 'default'; });
512
423
  canvas.addEventListener('click', function (e) { var h = hit(e); if (h) { selected = h; if (onSelect) onSelect(h); } });
513
- resize(); ro(); initAmbient(); requestAnimationFrame(frame);
424
+ resize(); ro(); requestAnimationFrame(frame);
514
425
  return {
515
426
  spawnSub: spawnSub, subActivity: subActivity, finishSub: finishSub, subCount: subCount, setAgents: setAgents, setState: setState, setStep: setStep, pulse: pulse, handoff: handoff, verdict: verdict, setStage: setStage, setActiveTeams: function (l) { dimTeams = l && l.length ? l : null; }, reset: reset, resize: resize,
516
427
  select: function (id) { selected = id; }, onSelect: function (f) { onSelect = f; }, onFrame: function (f) { onFrame = f; },
517
428
  setSlow: function (v) { slow = !!v; }, setHubStats: function (l) { hubStats = l; },
518
- getNodePos: function (id) { var n = nodes[id]; if (n) return {x: n.x, y: n.y, r: n.r, w: W, h: H}; return {x: hub.x, y: hub.y, r: hub.r, w: W, h: H}; },
429
+ getNodePos: function (id) { var n = nodes[id]; if (n) return {x: n.x, y: n.y, r: n.r, w: W, h: H}; var z = zones[id]; if (z) return {x: z.x, y: z.y, r: z.r, w: W, h: H}; return {x: hub.x, y: hub.y, r: hub.r, w: W, h: H}; },
519
430
  zonePos: function (id) { return zones[id]; },
520
431
  initials: initials, TEAM_COLOR: TEAM_COLOR,
521
432
  refreshAgents: function (list) { var m = {}; list.forEach(function (a) { m[a.id] = a; }); agents = agents.map(function (a) { return m[a.id] || a; }); Object.keys(nodes).forEach(function (k) { if (m[k]) nodes[k].agent = m[k]; }); }