@ngockhoale/ckit 0.2.6 → 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 (126) 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/config.js +4 -2
  5. package/dist/src/team/engine.d.ts +10 -0
  6. package/dist/src/team/engine.js +118 -10
  7. package/dist/src/team/journal.d.ts +2 -0
  8. package/dist/src/team/journal.js +28 -3
  9. package/dist/src/team/runners.d.ts +4 -0
  10. package/dist/src/team/runners.js +16 -2
  11. package/dist/src/team/types.d.ts +6 -0
  12. package/dist/src/tui/team/model.js +2 -0
  13. package/gui/app.css +178 -18
  14. package/gui/app.js +318 -115
  15. package/gui/assets/ckit-oriental-avatar-pack/README.md +5 -0
  16. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-architect-01.png +0 -0
  17. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-architect-02.png +0 -0
  18. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-architect-03.png +0 -0
  19. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-architect-04.png +0 -0
  20. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-architect-05.png +0 -0
  21. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-architect-06.png +0 -0
  22. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-architect-07.png +0 -0
  23. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-architect-08.png +0 -0
  24. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-architect-09.png +0 -0
  25. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-data-ai-01.png +0 -0
  26. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-data-ai-02.png +0 -0
  27. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-data-ai-03.png +0 -0
  28. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-data-ai-04.png +0 -0
  29. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-data-ai-05.png +0 -0
  30. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-data-ai-06.png +0 -0
  31. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-data-ai-07.png +0 -0
  32. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-data-ai-08.png +0 -0
  33. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-data-ai-09.png +0 -0
  34. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-developer-01.png +0 -0
  35. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-developer-02.png +0 -0
  36. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-developer-03.png +0 -0
  37. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-developer-04.png +0 -0
  38. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-developer-05.png +0 -0
  39. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-developer-06.png +0 -0
  40. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-developer-07.png +0 -0
  41. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-developer-08.png +0 -0
  42. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-developer-09.png +0 -0
  43. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-devops-01.png +0 -0
  44. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-devops-02.png +0 -0
  45. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-devops-03.png +0 -0
  46. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-devops-04.png +0 -0
  47. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-devops-05.png +0 -0
  48. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-devops-06.png +0 -0
  49. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-devops-07.png +0 -0
  50. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-devops-08.png +0 -0
  51. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-devops-09.png +0 -0
  52. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-pm-01.png +0 -0
  53. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-pm-02.png +0 -0
  54. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-pm-03.png +0 -0
  55. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-pm-04.png +0 -0
  56. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-pm-05.png +0 -0
  57. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-pm-06.png +0 -0
  58. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-pm-07.png +0 -0
  59. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-pm-08.png +0 -0
  60. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-pm-09.png +0 -0
  61. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-qa-01.png +0 -0
  62. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-qa-02.png +0 -0
  63. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-qa-03.png +0 -0
  64. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-qa-04.png +0 -0
  65. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-qa-05.png +0 -0
  66. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-qa-06.png +0 -0
  67. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-qa-07.png +0 -0
  68. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-qa-08.png +0 -0
  69. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-qa-09.png +0 -0
  70. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-security-01.png +0 -0
  71. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-security-02.png +0 -0
  72. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-security-03.png +0 -0
  73. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-security-04.png +0 -0
  74. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-security-05.png +0 -0
  75. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-security-06.png +0 -0
  76. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-security-07.png +0 -0
  77. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-security-08.png +0 -0
  78. package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-security-09.png +0 -0
  79. package/gui/assets/ckit-oriental-avatar-pack/manifest.json +447 -0
  80. package/gui/comic/assets/backgrounds/command-center.svg +1 -0
  81. package/gui/comic/assets/backgrounds/developer-workshop.svg +1 -0
  82. package/gui/comic/assets/backgrounds/handoff-corridor.svg +1 -0
  83. package/gui/comic/assets/backgrounds/incident-room.svg +1 -0
  84. package/gui/comic/assets/backgrounds/mission-overview.svg +1 -0
  85. package/gui/comic/assets/backgrounds/quality-lab.svg +1 -0
  86. package/gui/comic/assets/backgrounds/reporting-hall.svg +1 -0
  87. package/gui/comic/assets/backgrounds/research-library.svg +1 -0
  88. package/gui/comic/assets/backgrounds/review-chamber.svg +1 -0
  89. package/gui/comic/assets/backgrounds/strategy-room.svg +1 -0
  90. package/gui/comic/assets/effects/check-burst.svg +1 -0
  91. package/gui/comic/assets/effects/focus-lines.svg +1 -0
  92. package/gui/comic/assets/effects/glow.svg +1 -0
  93. package/gui/comic/assets/effects/particles.svg +1 -0
  94. package/gui/comic/assets/effects/speed-lines.svg +1 -0
  95. package/gui/comic/assets/effects/warning-flash.svg +1 -0
  96. package/gui/comic/assets/frame/episode-banner.svg +1 -0
  97. package/gui/comic/assets/frame/panel-corner.svg +1 -0
  98. package/gui/comic/assets/props/approval-seal.svg +1 -0
  99. package/gui/comic/assets/props/bug-warning.svg +1 -0
  100. package/gui/comic/assets/props/capsule.svg +1 -0
  101. package/gui/comic/assets/props/checklist.svg +1 -0
  102. package/gui/comic/assets/props/code-display.svg +1 -0
  103. package/gui/comic/assets/props/document.svg +1 -0
  104. package/gui/comic/assets/props/files.svg +1 -0
  105. package/gui/comic/assets/props/folder.svg +1 -0
  106. package/gui/comic/assets/props/magnifier.svg +1 -0
  107. package/gui/comic/assets/props/package.svg +1 -0
  108. package/gui/comic/assets/props/rejection-mark.svg +1 -0
  109. package/gui/comic/assets/props/report.svg +1 -0
  110. package/gui/comic/assets/props/scroll.svg +1 -0
  111. package/gui/comic/assets/props/shield.svg +1 -0
  112. package/gui/comic/assets/props/tablet.svg +1 -0
  113. package/gui/comic/assets/props/workstation.svg +1 -0
  114. package/gui/comic/comic.css +130 -0
  115. package/gui/comic/contact-sheet.html +15 -0
  116. package/gui/comic/contact-sheet.js +41 -0
  117. package/gui/comic/engine.js +366 -0
  118. package/gui/comic/manifests/backgrounds.json +216 -0
  119. package/gui/comic/manifests/characters.json +96 -0
  120. package/gui/comic/manifests/effects.json +96 -0
  121. package/gui/comic/manifests/props.json +246 -0
  122. package/gui/comic/manifests/scenes.json +205 -0
  123. package/gui/comic/render.js +594 -0
  124. package/gui/index.html +30 -14
  125. package/gui/network.js +253 -254
  126. package/package.json +2 -1
package/gui/network.js CHANGED
@@ -1,78 +1,73 @@
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}; }
12
- 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}; }
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}; }
10
+ var avatarResolver = null, engineResolver = null, imgCache = {};
11
+ var RM = window.matchMedia ? window.matchMedia('(prefers-reduced-motion: reduce)') : {matches: false};
12
+ function portrait(a) {
13
+ var url = a && avatarResolver ? avatarResolver(a) : null; if (!url) return null;
14
+ var im = imgCache[url];
15
+ if (!im) { im = imgCache[url] = new Image(); im.decoding = 'async'; im.src = url; im.onerror = function () { im.bad = true; }; }
16
+ return im.complete && im.naturalWidth && !im.bad ? im : null;
17
+ }
13
18
 
14
19
  function create(canvas) {
15
20
  var ctx = canvas.getContext('2d');
16
21
  var W = 0, H = 0, dpr = 1, S = 1, wide = false;
17
- var agents = [], nodes = {}, zones = {}, hub = {x: 0, y: 0, r: 44};
18
- var particles = [], sparks = [], packages = [], flashes = {}, hot = {}, ambient = [], noise = [];
19
- var stageIdx = -1, stageDone = 0, stageLoop = 1, selected = null, hover = null, onSelect = null, onFrame = null;
20
- var slow = false, grid = null, t0 = performance.now(), verdictFlash = null;
21
-
22
- function initAmbient() {
23
- 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});
24
- 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)});
25
- }
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); }
26
26
  function buildGrid() {
27
27
  grid = document.createElement('canvas'); grid.width = W * dpr; grid.height = H * dpr;
28
28
  var g = grid.getContext('2d'); g.scale(dpr, dpr);
29
- g.fillStyle = 'rgba(120,150,190,0.10)';
30
- for (var x = 12; x < W; x += 24) for (var y = 12; y < H; y += 24) g.fillRect(x, y, 1, 1);
31
- g.strokeStyle = 'rgba(80,110,150,0.06)'; g.lineWidth = 1; g.beginPath();
32
- for (var x2 = 0; x2 < W; x2 += 120) { g.moveTo(x2 + .5, 0); g.lineTo(x2 + .5, H); }
33
- 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); }
34
33
  g.stroke();
35
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);
40
+ }
36
41
  function layout() {
37
- /* wide = short/letterbox canvas: everything on one row so nothing overlaps or gets clipped */
38
42
  wide = H < 330 || W / H > 3.2;
39
- S = wide ? Math.max(.5, Math.min(W / 1150, H / 300, 1.15)) : Math.max(.55, Math.min(W / 1050, H / 600, 1.25));
40
- var zp = wide ? ZONE_WIDE : ZONE_POS, hp = wide ? HUB_WIDE : HUB_POS, old = nodes;
41
- var BUILTIN = {director: 1, ba: 1, implement: 1, qc: 1}, extraIds = [];
42
- agents.forEach(function (a) { if (!BUILTIN[a.team] && extraIds.indexOf(a.team) < 0) extraIds.push(a.team); });
43
- var teamIds = ['ba', 'implement', 'qc'].filter(function (t) { return agents.some(function (a) { return a.team === t; }); }).concat(extraIds);
44
- /* flow order (CKNet.TEAM_ORDER, set by the app) decides the placement; the default order keeps the classic layout */
45
- 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; });
46
- if (ord.length === teamIds.length) teamIds = ord;
47
- var reordered = !extraIds.length && teamIds.some(function (t, i) { return t !== classic[i]; });
48
- if (extraIds.length || reordered) {
49
- /* 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. */
50
- zp = {}; var maxN = 1;
51
- teamIds.forEach(function (t) { maxN = Math.max(maxN, Math.min(4, agents.filter(function (a) { return a.team === t; }).length)); });
52
- var zw = 2 * 1.2 * (64 + 26 * maxN);
53
- if (wide) {
54
- var slots = teamIds.length + 1; hp = [.5 / slots, .5];
55
- teamIds.forEach(function (t, i) { zp[t] = [(i + 1.5) / slots, .56]; });
56
- S = Math.max(.4, Math.min(S, W / slots / zw));
57
- } else {
58
- /* clockwise from the hub: first two teams on the upper row (left, right), the rest along the bottom row from right to left */
59
- var top = teamIds.slice(0, 2), bottom = teamIds.slice(2).reverse();
60
- top.forEach(function (t, i) { zp[t] = [top.length === 1 ? .5 : (i ? .84 : .16), .44]; });
61
- bottom.forEach(function (t, i) { zp[t] = [(i + .5) / bottom.length, .84]; });
62
- S = Math.max(.4, Math.min(S * .8, W / Math.max(bottom.length, 2) / zw));
63
- }
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};
52
+ }
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);
64
58
  }
65
- hub = {x: W * hp[0], y: H * hp[1], r: 50 * S};
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};
66
61
  zones = {}; nodes = {};
67
- teamIds.forEach(function (tid) {
68
- var list = agents.filter(function (a) { return a.team === tid; }), n = Math.max(1, list.length);
69
- var rz = (64 + 26 * Math.min(n, 4)) * S, zy = Math.max(rz + 26 * S, Math.min(H - rz - 6, H * zp[tid][1]));
70
- zones[tid] = {id: tid, x: W * zp[tid][0], y: zy, r: rz, n: list.length, color: TEAM_COLOR[tid] || '#8A9AAF'};
71
- list.forEach(function (a, i) {
72
- var ang, rad = list.length === 1 ? 0 : rz * .52, o = old[a.id];
73
- if (list.length === 2) ang = i === 0 ? Math.PI : 0; else ang = -Math.PI / 2 + i * 2 * Math.PI / list.length;
74
- 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};
75
69
  });
70
+ x += cw + M.tg;
76
71
  });
77
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}; });
78
73
  }
@@ -80,99 +75,103 @@
80
75
  var r = canvas.parentElement.getBoundingClientRect();
81
76
  dpr = Math.min(window.devicePixelRatio || 1, 2); W = Math.max(300, r.width); H = Math.max(260, r.height);
82
77
  canvas.width = W * dpr; canvas.height = H * dpr; canvas.style.width = W + 'px'; canvas.style.height = H + 'px';
83
- var saved = {}; Object.keys(nodes).forEach(function (k) { saved[k] = nodes[k].state; });
84
- layout(); Object.keys(saved).forEach(function (k) { if (nodes[k]) nodes[k].state = saved[k]; });
85
- buildGrid();
78
+ layout(); buildGrid();
86
79
  }
87
80
  function ro() { if (window.ResizeObserver) new ResizeObserver(resize).observe(canvas.parentElement); window.addEventListener('resize', resize); }
88
81
 
89
- function endpoint(id) {
90
- if (nodes[id]) return nodes[id];
91
- if (zones[id]) return zones[id];
92
- 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;
93
91
  }
94
- function teamOf(id) { if (nodes[id]) return nodes[id].agent.team; if (zones[id]) return id; return 'director'; }
95
- function burst(x, y, color, n, kind) {
96
- for (var i = 0; i < n; i++) {
97
- var a = Math.random() * 6.283, sp = rnd(30, kind === 'fail' ? 190 : 140);
98
- 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)];
99
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));
100
104
  }
101
- function addParticle(a, b, bend, color, opt) {
102
- opt = opt || {};
103
- 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};
104
111
  }
105
- function pulse(from, to, kind) {
106
- var A = endpoint(from), B = endpoint(to), ta = teamOf(from), tb = teamOf(to);
107
- var color = kind === 'fail' ? '#F05668' : kind === 'pass' ? '#4AD69A' : TEAM_COLOR[ta] || '#21D6E8';
108
- var key = [from, to].sort().join('|'); hot[key] = {until: performance.now() + 2200, c1: TEAM_COLOR[ta], c2: TEAM_COLOR[tb]};
109
- if (from === to) { burst(A.x, A.y, color, 8); return; }
110
- var intra = ta === tb && ta !== 'director' && nodes[from] && nodes[to];
111
- if (intra) {
112
- addParticle(A, B, .45, color, {speed: .9, size: 3.2});
113
- addParticle(B, A, -.45, color, {speed: .9, size: 2.2, delay: .45});
114
- burst(B.x, B.y, color, 5);
115
- } else {
116
- addParticle(A, B, .18, color, {speed: kind ? .7 : .5, size: 3.6});
117
- addParticle(A, B, .18, '#ffffff', {speed: kind ? .7 : .5, size: 1.8, delay: .08});
118
- 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}); }
119
- 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));
120
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)});
121
132
  }
122
133
  function handoff(fromTeam, toTeam, title) {
123
- var A = zones[fromTeam] || hub, B = zones[toTeam] || hub;
124
- var dur = slow ? 90 : 2.6;
125
- 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()});
126
- 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};
127
- burst(A.x, A.y, TEAM_COLOR[fromTeam] || '#fff', 26);
134
+ spawnChip(fromTeam, toTeam, title || 'Handoff', {caption: 'HANDOFF', max: 32, color: TEAM_COLOR[fromTeam] || TEAM_COLOR.director});
128
135
  }
129
136
  function verdict(v) {
130
- var q = zones.qc || hub, c = v === 'PASS' ? '#4AD69A' : '#F05668';
131
- burst(q.x, q.y, c, v === 'PASS' ? 60 : 40, v === 'PASS' ? 'pass' : 'fail');
132
- verdictFlash = {until: performance.now() + 1600, color: c, v: v};
133
- 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});
134
139
  }
135
- 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; }
136
- function setAgents(list) {
137
- 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
+ });
138
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(); }
139
172
  function setState(id, st) { if (nodes[id]) nodes[id].state = st; }
140
173
  function setStep(id, prog) { if (nodes[id]) nodes[id].prog = prog; }
141
- function reset() { subs = {}; particles = []; packages = []; sparks = []; hot = {}; stageIdx = -1; stageDone = 0; Object.keys(nodes).forEach(function (k) { nodes[k].state = 'idle'; nodes[k].prog = null; }); }
142
-
143
- /* ---------- drawing ---------- */
144
- function drawThread(a, b, bend, color1, color2, alpha, width) {
145
- var c = ctrl(a, b, bend);
146
- ctx.beginPath(); ctx.moveTo(a.x, a.y); ctx.quadraticCurveTo(c.x, c.y, b.x, b.y);
147
- 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; }
148
- else ctx.strokeStyle = 'rgba(110,135,170,' + alpha + ')';
149
- ctx.lineWidth = width || 1; ctx.stroke();
150
- }
151
- function drawZone(z, tms) {
152
- var f = flashes[z.id] ? Math.max(0, flashes[z.id] - tms) / 1200 : 0;
153
- var active = agents.some(function (a) { return a.team === z.id && nodes[a.id] && nodes[a.id].state === 'thinking'; });
154
- var br = active ? .55 + .25 * Math.sin(tms / 400) : .22;
155
- ctx.save();
156
- var g = ctx.createRadialGradient(z.x, z.y, z.r * .2, z.x, z.y, z.r * 1.15);
157
- g.addColorStop(0, hexA(z.color, .10 + (active ? .06 : 0) + f * .15)); g.addColorStop(1, hexA(z.color, 0));
158
- ctx.fillStyle = g; ctx.beginPath(); ctx.arc(z.x, z.y, z.r * 1.15, 0, 6.283); ctx.fill();
159
- /* hex boundary */
160
- ctx.beginPath();
161
- 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); }
162
- ctx.closePath(); ctx.fillStyle = hexA(z.color, .045 + f * .12); ctx.fill();
163
- ctx.setLineDash([7, 5]); ctx.lineDashOffset = -tms / 90; ctx.lineWidth = 1.4; ctx.strokeStyle = hexA(z.color, br + f * .4);
164
- if (active) { ctx.shadowColor = z.color; ctx.shadowBlur = 14; }
165
- ctx.stroke(); ctx.setLineDash([]); ctx.shadowBlur = 0;
166
- /* corner ticks + label */
167
- ctx.font = '600 ' + Math.round(11 * Math.max(.9, S)) + 'px ui-monospace,Menlo,monospace'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
168
- var label = TEAM_LABEL[z.id], ly = z.y - z.r * .98 - 12 * S, tw = ctx.measureText(label).width + 24;
169
- ctx.fillStyle = 'rgba(8,13,22,.92)'; roundRect(z.x - tw / 2, ly - 11, tw, 22, 11); ctx.fill();
170
- ctx.strokeStyle = hexA(z.color, .75); ctx.lineWidth = 1; ctx.stroke();
171
- ctx.fillStyle = z.color; ctx.shadowColor = z.color; ctx.shadowBlur = active ? 10 : 0;
172
- ctx.beginPath(); ctx.arc(z.x - tw / 2 + 11, ly, 3, 0, 6.283); ctx.fill(); ctx.shadowBlur = 0;
173
- ctx.fillStyle = '#E6EEFA'; ctx.fillText(label, z.x + 5, ly + .5);
174
- ctx.restore();
175
- }
174
+ function reset() { subs = {}; chips = []; stageIdx = -1; stageDone = 0; Object.keys(nodes).forEach(function (k) { nodes[k].state = 'idle'; nodes[k].prog = null; }); }
176
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(); }
177
176
  function drawHub(tms) {
178
177
  var x = hub.x, y = hub.y, r = hub.r, c = TEAM_COLOR.director;
@@ -196,7 +195,7 @@
196
195
  }
197
196
  ctx.globalCompositeOperation = 'source-over';
198
197
  /* stage ring */
199
- var rr2 = r * 2.05, gap = .08, seg = 6.283 / STAGE_COUNT;
198
+ var rr2 = r * 1.42, gap = .08, seg = 6.283 / STAGE_COUNT;
200
199
  for (var s = 0; s < STAGE_COUNT; s++) {
201
200
  var a0 = -Math.PI / 2 + s * seg + gap / 2, a1 = a0 + seg - gap, col, al;
202
201
  if (stageIdx < 0) { col = '#34445B'; al = .7; }
@@ -210,28 +209,98 @@
210
209
  ctx.lineCap = 'butt';
211
210
  /* outer fine ring, rotating dashes */
212
211
  ctx.setLineDash([2, 7]); ctx.lineDashOffset = -tms / 120; ctx.strokeStyle = hexA(c, .4); ctx.lineWidth = 1;
213
- ctx.beginPath(); ctx.arc(x, y, rr2 + 9 * S, 0, 6.283); ctx.stroke(); ctx.setLineDash([]);
214
- /* core */
215
- var cg = ctx.createRadialGradient(x - r * .3, y - r * .3, 1, x, y, r * pulseK);
212
+ ctx.beginPath(); ctx.arc(x, y, rr2 + 5 * S, 0, 6.283); ctx.stroke(); ctx.setLineDash([]);
213
+ /* core: avatar portrait inside a purple energy ring */
214
+ var cr = r * .86 * pulseK, dn = nodes.director, im = dn ? portrait(dn.agent) : null;
215
+ var cg = ctx.createRadialGradient(x - r * .3, y - r * .3, 1, x, y, cr);
216
216
  cg.addColorStop(0, '#F3E6FF'); cg.addColorStop(.35, '#B98BFF'); cg.addColorStop(.8, '#7A3FD0'); cg.addColorStop(1, '#3a1d70');
217
217
  ctx.shadowColor = c; ctx.shadowBlur = 30 * pulseK; ctx.fillStyle = cg;
218
- ctx.beginPath(); ctx.arc(x, y, r * .86 * pulseK, 0, 6.283); ctx.fill(); ctx.shadowBlur = 0;
219
- ctx.strokeStyle = hexA('#F04F9B', .9); ctx.lineWidth = 2; ctx.beginPath(); ctx.arc(x, y, r * .86 * pulseK, 0, 6.283); ctx.stroke();
218
+ ctx.beginPath(); ctx.arc(x, y, cr, 0, 6.283); ctx.fill(); ctx.shadowBlur = 0;
219
+ if (im) { ctx.save(); ctx.beginPath(); ctx.arc(x, y, cr - 3, 0, 6.283); ctx.clip(); ctx.drawImage(im, x - cr + 3, y - cr + 3, (cr - 3) * 2, (cr - 3) * 2); ctx.restore(); }
220
+ ctx.strokeStyle = hexA('#F04F9B', .9); ctx.lineWidth = 2.5; ctx.beginPath(); ctx.arc(x, y, cr, 0, 6.283); ctx.stroke();
221
+ ctx.strokeStyle = hexA('#C9A6FF', .55); ctx.lineWidth = 1; ctx.beginPath(); ctx.arc(x, y, cr + 6 * S, 0, 6.283); ctx.stroke();
220
222
  /* thinking arc */
221
223
  if (anyThink) { ctx.strokeStyle = '#fff'; ctx.lineWidth = 2.5; ctx.beginPath(); var ra = tms / 300; ctx.arc(x, y, r * 1.12, ra, ra + 1.6); ctx.stroke(); }
222
- ctx.fillStyle = 'rgba(10,6,24,.9)'; ctx.font = '800 ' + Math.round(19 * S) + 'px system-ui,sans-serif'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
223
- var dlab = nodes.director ? initials(nodes.director.agent) : 'DIR'; if (dlab.length > 3) ctx.font = '800 ' + Math.round(16 * S) + 'px system-ui,sans-serif'; ctx.fillStyle = '#fff'; ctx.fillText(dlab, x, y + .5);
224
+ ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
225
+ var dlab = dn ? initials(dn.agent) : 'DIR';
226
+ if (!im) { ctx.font = '800 ' + Math.round((dlab.length > 3 ? 16 : 19) * S) + 'px system-ui,sans-serif'; ctx.fillStyle = '#fff'; ctx.fillText(dlab, x, y + .5); }
227
+ else {
228
+ /* DIR tag on the ring */
229
+ ctx.font = '800 ' + Math.round(10 * Math.max(.9, S)) + 'px ui-monospace,Menlo,monospace';
230
+ var tgw = ctx.measureText(dlab).width + 14, tgy = y + cr - 2;
231
+ ctx.fillStyle = '#2a1458'; roundRect(x - tgw / 2, tgy - 8, tgw, 16, 8); ctx.fill(); ctx.strokeStyle = '#C9A6FF'; ctx.lineWidth = 1; ctx.stroke();
232
+ ctx.fillStyle = '#fff'; ctx.fillText(dlab, x, tgy + .5);
233
+ }
234
+ if (dn) drawEngine(dn.agent, x + cr * .72, y - cr * .72, Math.max(8, 10 * S));
224
235
  if (wide) { ctx.restore(); return; } /* no room under the hub on a letterbox canvas */
225
236
  /* label */
226
237
  ctx.font = '600 ' + Math.round(11 * Math.max(.9, S)) + 'px ui-monospace,Menlo,monospace';
227
- var lab = '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;
228
239
  ctx.fillStyle = 'rgba(8,13,22,.92)'; roundRect(x - tw / 2, ly - 11, tw, 22, 11); ctx.fill();
229
240
  ctx.strokeStyle = hexA(c, .8); ctx.lineWidth = 1; ctx.stroke(); ctx.fillStyle = '#E6EEFA'; ctx.fillText(lab, x, ly + .5);
230
- if (stageLoop > 1 && stageIdx >= 1) { ctx.fillStyle = '#F3A544'; ctx.fillText('QC LOOP ' + stageLoop, x, ly + 20 * S); }
241
+ var sub = stageLoop > 1 && stageIdx >= 1 ? 'LOOP ' + stageLoop : dn && dn.state === 'thinking' ? 'Orchestrating…' : '';
242
+ if (sub) { ctx.font = '600 10.5px ui-monospace,Menlo,monospace'; ctx.fillStyle = stageLoop > 1 && stageIdx >= 1 ? '#F3A544' : '#C9A6FF'; ctx.fillText(sub, x, ly + 19); }
243
+ if (hubStats && hubStats.length) {
244
+ /* real run counters only (elapsed · messages · tokens) */
245
+ ctx.font = '600 10.5px ui-monospace,Menlo,monospace'; var gap2 = 6, ws = hubStats.map(function (t) { return ctx.measureText(t).width + 16; }), tot = ws.reduce(function (a2, b2) { return a2 + b2; }, 0) + gap2 * (ws.length - 1), cx2 = x - tot / 2, cy2 = ly + (sub ? 38 : 22);
246
+ hubStats.forEach(function (t, i) { ctx.fillStyle = 'rgba(8,13,22,.9)'; roundRect(cx2, cy2 - 9, ws[i], 18, 4); ctx.fill(); ctx.strokeStyle = 'rgba(120,140,180,.45)'; ctx.lineWidth = 1; ctx.stroke(); ctx.fillStyle = '#DCE6F5'; ctx.fillText(t, cx2 + ws[i] / 2, cy2 + .5); cx2 += ws[i] + gap2; });
247
+ }
231
248
  ctx.restore();
232
249
  }
233
250
  function initials(a) { if (a.short) return String(a.short).toUpperCase().slice(0, 4); if (a.team === 'director') return 'DIR'; var m = a.name.replace(/[^\p{L}\p{N} ·]/gu, '').split(/[ ·]+/).filter(Boolean); return ((m[0] || '?')[0] + ((m[1] || m[0] || '')[1] || (m[1] || '')[0] || '')).toUpperCase().slice(0, 2); }
234
- function cut(t, n) { return t.length > n ? t.slice(0, n - 1) + '…' : t; }
251
+ function drawEngine(a, bx, by, br) {
252
+ var e = engineResolver ? engineResolver(a) : null; if (!e) return;
253
+ ctx.save(); ctx.fillStyle = '#05070D'; ctx.beginPath(); ctx.arc(bx, by, br + 2, 0, 6.283); ctx.fill();
254
+ ctx.fillStyle = e.color; ctx.beginPath(); ctx.arc(bx, by, br, 0, 6.283); ctx.fill();
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';
256
+ ctx.fillText(e.mark, bx, by + .5); ctx.restore();
257
+ }
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();
280
+ }
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
+
235
304
  var dimTeams = null;
236
305
  function drawNode(n, tms) {
237
306
  if (n.agent.team === 'director') return;
@@ -265,12 +334,22 @@
265
334
  for (var d = 0; d < 3; d++) { var da = tms / 500 + d * 2.09; ctx.fillStyle = '#fff'; ctx.beginPath(); ctx.arc(x + Math.cos(da) * (r + 25 * S), y + Math.sin(da) * (r + 25 * S), 1.8, 0, 6.283); ctx.fill(); }
266
335
  }
267
336
  if (sel) { ctx.strokeStyle = 'rgba(255,255,255,.8)'; ctx.setLineDash([3, 3]); ctx.lineWidth = 1; ctx.beginPath(); ctx.arc(x, y, r + 15 * S, 0, 6.283); ctx.stroke(); ctx.setLineDash([]); }
337
+ var pim = portrait(n.agent);
338
+ if (pim) { ctx.save(); ctx.beginPath(); ctx.arc(x, y, r - 2.5 * S, 0, 6.283); ctx.clip(); ctx.globalAlpha = (dim ? .78 : 1) * na; ctx.drawImage(pim, x - r, y - r, r * 2, r * 2); ctx.restore(); ctx.strokeStyle = ring; ctx.lineWidth = 2.5 * S; ctx.beginPath(); ctx.arc(x, y, r - 1, 0, 6.283); ctx.stroke(); }
268
339
  var badge = initials(n.agent); ctx.fillStyle = '#F4F8FF'; ctx.font = '800 ' + Math.round(r * (badge.length > 3 ? .42 : badge.length > 2 ? .5 : .6)) + 'px system-ui,sans-serif'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
269
- ctx.shadowColor = 'rgba(0,0,0,.7)'; ctx.shadowBlur = 6; ctx.fillText(badge, x, y + 1); ctx.shadowBlur = 0;
340
+ if (!pim) { ctx.shadowColor = 'rgba(0,0,0,.7)'; ctx.shadowBlur = 6; ctx.fillText(badge, x, y + 1); ctx.shadowBlur = 0; }
341
+ else {
342
+ /* short tag under the portrait */
343
+ ctx.font = '800 ' + Math.round(Math.max(8, 9.5 * S)) + 'px ui-monospace,Menlo,monospace'; var bw = ctx.measureText(badge).width + 10, by2 = y + r - 1;
344
+ ctx.fillStyle = 'rgba(7,11,20,.95)'; roundRect(x - bw / 2, by2 - 7, bw, 14, 7); ctx.fill(); ctx.strokeStyle = hexA(c, .9); ctx.lineWidth = 1; ctx.stroke();
345
+ ctx.fillStyle = c; ctx.fillText(badge, x, by2 + .5);
346
+ }
347
+ drawEngine(n.agent, x - r * .74, y - r * .74, Math.max(7, 8.5 * S));
348
+ if (st === 'thinking' || st === 'idle') { var sx = x + r * .72, sy = y + r * .62; ctx.fillStyle = '#05070D'; ctx.beginPath(); ctx.arc(sx, sy, 5.5, 0, 6.283); ctx.fill(); ctx.fillStyle = st === 'thinking' ? '#4AD69A' : '#5B6B82'; ctx.beginPath(); ctx.arc(sx, sy, 3.6, 0, 6.283); ctx.fill(); }
270
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); }
271
350
  /* name plate: name, then engine/model, or the live step while working */
272
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);
273
- 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; };
274
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); });
275
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); });
276
355
  pw += 22; var ph = 22 + subs.length * 13 + (subs.length ? 1 : 0), px = x - pw / 2, py = y + r + 13 * S;
@@ -280,61 +359,39 @@
280
359
  if (frac) { ctx.fillStyle = c; ctx.fillRect(px + 8, py + ph - 3, (pw - 16) * frac, 2); }
281
360
  ctx.restore();
282
361
  }
283
- function drawPackage(p, tms) {
284
- 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;
285
- var pos = bez(p.a, c, p.b, k);
286
- ctx.save();
287
- ctx.globalCompositeOperation = 'lighter';
288
- 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(); }
289
- ctx.globalCompositeOperation = 'source-over';
290
- var w = 150 * Math.max(.85, S), h = 40 * Math.max(.85, S), bob = Math.sin(tms / 200) * 2;
291
- 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));
292
- 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();
293
- ctx.lineWidth = 2; ctx.strokeStyle = gx; ctx.stroke(); ctx.shadowBlur = 0;
294
- ctx.font = '18px system-ui'; ctx.textAlign = 'left'; ctx.textBaseline = 'middle'; ctx.fillStyle = '#fff'; ctx.fillText('📦', pos.x - w / 2 + 9, pos.y + 1 + bob);
295
- ctx.font = '700 10px ui-monospace,Menlo,monospace'; ctx.fillStyle = '#9FB0C6'; ctx.fillText('HANDOFF', pos.x - w / 2 + 36, pos.y - 7 + bob);
296
- 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);
297
- ctx.restore();
298
- }
299
-
300
362
 
301
- /* ---------- subagent squad ---------- */
302
- var subs = {};
363
+ /* ---------- subagent squad (fanned below the parent) ---------- */
303
364
  function spawnSub(parentId, childId, kind) {
304
365
  var pn = nodes[parentId]; if (!pn || subs[childId]) return;
305
366
  var sibs = Object.keys(subs).filter(function (k) { return subs[k].parent === parentId; }).length;
306
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};
307
- burst(pn.x, pn.y, pn.color, 10);
308
368
  }
309
369
  function subActivity(childId, text) { if (subs[childId]) subs[childId].say = {text: String(text), t0: performance.now()}; }
310
- 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(); }
311
371
  function subCount(parentId) { return Object.keys(subs).filter(function (k) { return subs[k].parent === parentId && subs[k].state === 'run'; }).length; }
312
372
  function drawSubs(now, tms) {
313
373
  Object.keys(subs).forEach(function (k) {
314
374
  var d = subs[k], pn = nodes[d.parent];
315
375
  if (!pn) { delete subs[k]; return; }
316
- 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);
317
377
  var fade = d.state === 'done' ? Math.max(0, 1 - (now - d.end) / 1800) : 1;
318
378
  if (fade <= 0) { delete subs[k]; return; }
319
- var sibs = Object.keys(subs).filter(function (q) { return subs[q].parent === d.parent; }), i = sibs.indexOf(k), n = sibs.length;
320
- 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;
321
- 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;
322
- d.x = tx; d.y = ty; var r = 9 * S * ease, col = d.ok ? pn.color : '#F05668';
323
- ctx.save(); ctx.globalAlpha = fade;
324
- ctx.setLineDash([3, 4]); ctx.lineDashOffset = -tms / 60; ctx.strokeStyle = hexA(pn.color, .7); ctx.lineWidth = 1;
325
- ctx.beginPath(); ctx.moveTo(pn.x, pn.y); ctx.lineTo(tx, ty); ctx.stroke(); ctx.setLineDash([]);
326
- 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();
327
386
  ctx.strokeStyle = col; ctx.lineWidth = 1.5; ctx.stroke(); ctx.shadowBlur = 0;
328
- 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(); }
329
- 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';
330
389
  ctx.fillText(d.state === 'done' ? (d.ok ? '✓' : '✕') : '◆', tx, ty + .5);
331
- ctx.font = '600 9px ui-monospace,Menlo,monospace'; ctx.fillStyle = '#9FB0C6';
332
- ctx.fillText(d.kind.length > 12 ? d.kind.slice(0, 11) + '…' : d.kind, tx, ty + r + 10);
333
390
  if (d.say && now - d.say.t0 < 4200 && d.state === 'run') {
334
- 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));
335
- 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;
336
- 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();
337
- 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);
338
395
  }
339
396
  ctx.restore();
340
397
  });
@@ -346,93 +403,35 @@
346
403
  requestAnimationFrame(frame);
347
404
  }
348
405
  function draw(now) {
349
- var dt = Math.max(0, Math.min(.05, (now - last) / 1000)); last = now; var tms = now - t0;
406
+ last = now; var tms = RM.matches ? 0 : now - t0;
350
407
  ctx.setTransform(dpr, 0, 0, dpr, 0, 0); ctx.clearRect(0, 0, W, H);
351
408
  ctx.drawImage(grid, 0, 0, W, H);
352
- 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)');
353
- ctx.fillStyle = bg; ctx.fillRect(0, 0, W, H);
354
- /* noise threads */
355
- ctx.lineWidth = 1;
356
- noise.forEach(function (n) {
357
- var a = {x: n.a[0] * W, y: n.a[1] * H}, b = {x: n.b[0] * W, y: n.b[1] * H};
358
- drawThread(a, b, n.bend, null, null, .03 + .05 * (.5 + .5 * Math.sin(tms / 1000 * n.sp + n.ph)), 1);
359
- });
360
- /* pipeline threads between zones */
361
- var zl = zones, pairs = [['ba', 'implement'], ['implement', 'qc'], ['qc', 'ba']];
362
- pairs.forEach(function (p) { if (zl[p[0]] && zl[p[1]]) drawThread(zl[p[0]], zl[p[1]], -.14, null, null, .28, 1); });
363
- if (zl.qc && zl.implement) drawThread(zl.qc, zl.implement, .2, '#F05668', '#F3A544', .12, 1);
364
- /* hub -> agents */
365
- Object.keys(nodes).forEach(function (id) { var n = nodes[id]; if (n.agent.team !== 'director') drawThread(hub, n, .1, null, null, .22, 1); });
366
- /* intra team */
367
- Object.keys(zones).forEach(function (tid) {
368
- var ns = agents.filter(function (a) { return a.team === tid; }).map(function (a) { return nodes[a.id]; });
369
- 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);
370
- });
371
- /* hot threads */
372
- Object.keys(hot).forEach(function (k) {
373
- var h = hot[k], left = h.until - now; if (left <= 0) { delete hot[k]; return; }
374
- var al = Math.min(1, left / 700);
375
- 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; }
376
- var ids = k.split('|'), A = endpoint(ids[0]), B = endpoint(ids[1]);
377
- var intra = nodes[ids[0]] && nodes[ids[1]] && nodes[ids[0]].agent.team === nodes[ids[1]].agent.team;
378
- drawThread(A, B, intra ? .25 : .18, h.c1, h.c2, .9 * al, 2);
379
- });
380
- /* ambient */
381
- ctx.globalCompositeOperation = 'lighter';
382
- ambient.forEach(function (a) {
383
- 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;
384
- 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();
385
- });
386
- ctx.globalCompositeOperation = 'source-over';
387
- Object.keys(zones).forEach(function (k) { drawZone(zones[k], tms); });
409
+ drawConnectors(now);
410
+ Object.keys(zones).forEach(function (k) { drawTeam(zones[k], tms); });
388
411
  drawHub(tms);
389
412
  Object.keys(nodes).forEach(function (k) { drawNode(nodes[k], tms); });
390
413
  drawSubs(now, tms);
391
- /* particles */
392
- ctx.globalCompositeOperation = 'lighter';
393
- for (var i = particles.length - 1; i >= 0; i--) {
394
- var p = particles[i]; p.t += dt * p.speed; if (p.t < 0) continue;
395
- if (p.t >= 1) { particles.splice(i, 1); continue; }
396
- var c = ctrl(p.a, p.b, p.bend), pos = bez(p.a, c, p.b, p.t);
397
- p.trail.push(pos); if (p.trail.length > 14) p.trail.shift();
398
- 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(); }
399
- 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;
400
- if (p.t > .96 && p.size > 2.5) burst(pos.x, pos.y, p.color, 3);
401
- }
402
- for (var s = sparks.length - 1; s >= 0; s--) {
403
- var sp = sparks[s]; sp.age += dt; if (sp.age > sp.life) { sparks.splice(s, 1); continue; }
404
- sp.x += sp.vx * dt; sp.y += sp.vy * dt; sp.vy += sp.g * dt; sp.vx *= .985;
405
- 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();
406
- }
407
- ctx.globalCompositeOperation = 'source-over';
408
- for (var k2 = packages.length - 1; k2 >= 0; k2--) {
409
- var pk = packages[k2]; pk.t += dt;
410
- 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; }
411
- drawPackage(pk, tms);
412
- }
413
- if (verdictFlash && verdictFlash.until > now) {
414
- var al2 = (verdictFlash.until - now) / 1600, q2 = zones.qc || hub;
415
- ctx.save(); ctx.font = '800 ' + Math.round(26 * S) + 'px ui-monospace,Menlo,monospace'; ctx.textAlign = 'center'; ctx.fillStyle = hexA(verdictFlash.color, al2);
416
- ctx.shadowColor = verdictFlash.color; ctx.shadowBlur = 24; ctx.fillText(verdictFlash.v, q2.x, q2.y - q2.r * 1.4 - (1 - al2) * 18); ctx.restore();
417
- }
414
+ drawChips(now);
418
415
  if (onFrame) onFrame();
419
416
  }
420
417
  function hit(e) {
421
418
  var r = canvas.getBoundingClientRect(), x = e.clientX - r.left, y = e.clientY - r.top, best = null;
422
- 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; });
423
420
  return best;
424
421
  }
425
422
  canvas.addEventListener('mousemove', function (e) { hover = hit(e); canvas.style.cursor = hover ? 'pointer' : 'default'; });
426
423
  canvas.addEventListener('click', function (e) { var h = hit(e); if (h) { selected = h; if (onSelect) onSelect(h); } });
427
- resize(); ro(); initAmbient(); requestAnimationFrame(frame);
424
+ resize(); ro(); requestAnimationFrame(frame);
428
425
  return {
429
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,
430
427
  select: function (id) { selected = id; }, onSelect: function (f) { onSelect = f; }, onFrame: function (f) { onFrame = f; },
431
- setSlow: function (v) { slow = !!v; },
432
- 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}; },
428
+ setSlow: function (v) { slow = !!v; }, setHubStats: function (l) { hubStats = l; },
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}; },
433
430
  zonePos: function (id) { return zones[id]; },
434
- initials: initials, TEAM_COLOR: TEAM_COLOR
431
+ initials: initials, TEAM_COLOR: TEAM_COLOR,
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]; }); }
435
433
  };
436
434
  }
437
- window.CKNet = {create: create, TEAM_COLOR: TEAM_COLOR, TEAM_LABEL: TEAM_LABEL};
435
+ window.CKNet = {create: create, TEAM_COLOR: TEAM_COLOR, TEAM_LABEL: TEAM_LABEL,
436
+ setAvatarResolver: function (f) { avatarResolver = f; }, setEngineResolver: function (f) { engineResolver = f; }};
438
437
  })();