yadflow 4.9.0 → 4.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +184 -0
- package/README.md +15 -5
- package/bin/commands.mjs +11 -1
- package/bin/yad.mjs +203 -14
- package/cli/agent-guard-worker.mjs +13 -0
- package/cli/agent-guard.mjs +1797 -73
- package/cli/agent-rules.mjs +64 -5
- package/cli/argv-flags.mjs +2 -2
- package/cli/brain/vendor/LICENSE-graphology-library.txt +21 -0
- package/cli/brain/vendor/LICENSE-graphology.txt +21 -0
- package/cli/brain/vendor/LICENSE-sigma.txt +12 -0
- package/cli/brain/vendor/graphology-library.min.js +2 -0
- package/cli/brain/vendor/graphology.umd.min.js +2 -0
- package/cli/brain/vendor/sigma.min.js +1369 -0
- package/cli/brain/view/app.js +382 -0
- package/cli/brain/view/index.html +63 -0
- package/cli/brain/view/live.css +228 -0
- package/cli/brain/view/live.html +110 -0
- package/cli/brain/view/live.js +884 -0
- package/cli/brain/view/style.css +141 -0
- package/cli/brain-about.mjs +206 -0
- package/cli/brain-activity.mjs +285 -0
- package/cli/brain-skills.mjs +118 -0
- package/cli/brain-vendor.mjs +71 -0
- package/cli/brain-view.mjs +344 -0
- package/cli/brain.mjs +810 -0
- package/cli/ci-check.mjs +48 -4
- package/cli/codeowners-command.mjs +72 -6
- package/cli/commit.mjs +17 -3
- package/cli/docs.mjs +2 -0
- package/cli/doctor.mjs +151 -25
- package/cli/epic-state.mjs +186 -4
- package/cli/epic.mjs +26 -10
- package/cli/errors.mjs +2 -1
- package/cli/find-product.mjs +69 -15
- package/cli/fold.mjs +31 -6
- package/cli/foundation-publish.mjs +256 -0
- package/cli/gate.mjs +29 -3
- package/cli/git-read.mjs +38 -0
- package/cli/guard-stream.mjs +409 -0
- package/cli/guide.mjs +3 -1
- package/cli/hook.mjs +102 -9
- package/cli/issue-links.mjs +61 -0
- package/cli/issues-act.mjs +371 -0
- package/cli/issues-write.mjs +441 -0
- package/cli/issues.mjs +513 -0
- package/cli/lib.mjs +37 -2
- package/cli/lifecycle.mjs +7 -0
- package/cli/local-page.mjs +138 -0
- package/cli/machine.mjs +1 -1
- package/cli/manifest.mjs +59 -3
- package/cli/map/view/app.js +712 -0
- package/cli/map/view/index.html +50 -0
- package/cli/map/view/style.css +142 -0
- package/cli/map-view.mjs +186 -0
- package/cli/map.mjs +637 -0
- package/cli/members.mjs +9 -15
- package/cli/next.mjs +1 -1
- package/cli/openpr.mjs +26 -6
- package/cli/plan.mjs +127 -0
- package/cli/platform.mjs +159 -4
- package/cli/product-index.mjs +1 -1
- package/cli/protection.mjs +53 -3
- package/cli/reconcile.mjs +9 -3
- package/cli/report.mjs +9 -3
- package/cli/reports-dir.mjs +391 -0
- package/cli/reports.mjs +65 -0
- package/cli/run-checks.mjs +15 -4
- package/cli/scan.mjs +314 -0
- package/cli/setup.mjs +42 -8
- package/cli/standup.mjs +120 -78
- package/cli/status.mjs +6 -5
- package/cli/story-frames.mjs +17 -6
- package/cli/test-agents-file.mjs +985 -12
- package/cli/test-brain-activity.mjs +753 -0
- package/cli/test-brain-view.mjs +381 -0
- package/cli/test-brain.mjs +795 -0
- package/cli/test-build.mjs +25 -0
- package/cli/test-ci-check.mjs +469 -10
- package/cli/test-guide.mjs +218 -0
- package/cli/test-machine.mjs +59 -0
- package/cli/test-map.mjs +615 -0
- package/cli/test-node.mjs +15 -0
- package/cli/test-reports.mjs +382 -0
- package/cli/test-run-checks.mjs +21 -0
- package/cli/test-setup-agent.mjs +14 -0
- package/cli/test-story-frames.mjs +74 -4
- package/cli/test-worktree.mjs +24 -3
- package/cli/toolbox-connect.mjs +259 -0
- package/cli/toolbox.mjs +187 -12
- package/cli/update-commit.mjs +101 -9
- package/cli/usage.mjs +8 -4
- package/package.json +12 -4
- package/skills/sdlc/config.yaml +1 -1
- package/skills/sdlc/module-help.csv +3 -1
- package/skills/yad-analysis/SKILL.md +4 -0
- package/skills/yad-architecture/SKILL.md +22 -4
- package/skills/yad-backfill/SKILL.md +4 -0
- package/skills/yad-change/SKILL.md +7 -1
- package/skills/yad-change/references/triage.md +2 -0
- package/skills/yad-checks/SKILL.md +15 -7
- package/skills/yad-checks/references/check-gates.md +70 -35
- package/skills/yad-checks/templates/checks/build-test-lint.sh +7 -0
- package/skills/yad-checks/templates/checks/install-deps.sh +6 -0
- package/skills/yad-checks/templates/checks/member-check.mjs +3 -2
- package/skills/yad-checks/templates/checks/package-manager.sh +42 -0
- package/skills/yad-checks/templates/checks/risk-map-check.sh +2 -2
- package/skills/yad-checks/templates/checks/verified-commits.sh +3 -3
- package/skills/yad-checks/templates/github/yad-checks.yml +358 -69
- package/skills/yad-checks/templates/github/yad-pr-text.yml +118 -0
- package/skills/yad-checks/templates/github/yad-product-checks.yml +130 -54
- package/skills/yad-checks/templates/github/yad-product-pr-text.yml +131 -0
- package/skills/yad-checks/templates/github/yad-update-guard.yml +2 -1
- package/skills/yad-checks/templates/github/yad-verified-commits.yml +49 -3
- package/skills/yad-checks/templates/gitlab/yad-checks.gitlab-ci.yml +80 -20
- package/skills/yad-checks/templates/gitlab/yad-product-checks.gitlab-ci.yml +59 -9
- package/skills/yad-checks/templates/gitlab/yad-update-guard.gitlab-ci.yml +1 -0
- package/skills/yad-checks/templates/gitlab/yad-verified-commits.gitlab-ci.yml +49 -1
- package/skills/yad-checks/templates/hooks/agent-guard.mjs +44 -10
- package/skills/yad-checks/templates/hooks/ledger-guard-cursor.mjs +12 -6
- package/skills/yad-checks/templates/hooks/yad-activity.mjs +238 -0
- package/skills/yad-commit/SKILL.md +3 -1
- package/skills/yad-connect-design/SKILL.md +42 -10
- package/skills/yad-connect-design/references/design-context.md +35 -5
- package/skills/yad-connect-design/references/design-registry.md +3 -3
- package/skills/yad-connect-learning/SKILL.md +12 -2
- package/skills/yad-connect-repos/SKILL.md +18 -0
- package/skills/yad-connect-testing/SKILL.md +22 -5
- package/skills/yad-connect-testing/references/testing-context.md +1 -1
- package/skills/yad-discovery/SKILL.md +11 -0
- package/skills/yad-discovery/references/foundation-schema.md +11 -0
- package/skills/yad-docs/templates/app/package-lock.json +18 -10
- package/skills/yad-docs/templates/app/package.json +6 -1
- package/skills/yad-epic/SKILL.md +7 -0
- package/skills/yad-epic/references/state-schema.md +50 -1
- package/skills/yad-guide/SKILL.md +8 -4
- package/skills/yad-implement/SKILL.md +117 -4
- package/skills/yad-implement/references/implement-conventions.md +2 -1
- package/skills/yad-issues/SKILL.md +54 -0
- package/skills/yad-learn/SKILL.md +4 -0
- package/skills/yad-open-pr/SKILL.md +6 -0
- package/skills/yad-pr-template/SKILL.md +2 -1
- package/skills/yad-pr-template/templates/checks/pr-template.sh +8 -4
- package/skills/yad-pr-template/templates/checks/pr-title.sh +42 -6
- package/skills/yad-product-bridge/references/bridge.md +28 -0
- package/skills/yad-product-bridge/templates/github/yad-gate-sync.yml +25 -11
- package/skills/yad-product-bridge/templates/gitlab/yad-gate-sync.gitlab-ci.yml +38 -14
- package/skills/yad-run/SKILL.md +5 -0
- package/skills/yad-scan/SKILL.md +51 -0
- package/skills/yad-spec/SKILL.md +32 -2
- package/skills/yad-stories/SKILL.md +22 -4
- package/skills/yad-stories/references/story-schema.md +1 -1
- package/skills/yad-test-cases/SKILL.md +18 -2
- package/skills/yad-ui/SKILL.md +43 -8
- package/skills/yad-checks/templates/gitlab/.gitlab-ci.yml +0 -49
|
@@ -0,0 +1,884 @@
|
|
|
1
|
+
// The Observatory — `yad brain view --live` (E178).
|
|
2
|
+
//
|
|
3
|
+
// The brain is a night sky. Each thing the agent does — a file read, a search, an edit, a command — arrives
|
|
4
|
+
// as an event already matched to the brain's nodes by cli/brain-activity.mjs; this page only draws it: a comet
|
|
5
|
+
// from the last node touched to the next, a pulse where it lands, and a heat that fades, so the sky slowly
|
|
6
|
+
// shows where the agent has worked. Every name comes from files anyone can edit, so text is only ever set
|
|
7
|
+
// with textContent.
|
|
8
|
+
/* global graphology, graphologyLibrary, Sigma */
|
|
9
|
+
(function () {
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
var $ = function (id) { return document.getElementById(id); };
|
|
13
|
+
function el(tag, text, cls) {
|
|
14
|
+
var e = document.createElement(tag);
|
|
15
|
+
if (text !== undefined && text !== null) e.textContent = String(text);
|
|
16
|
+
if (cls) e.className = cls;
|
|
17
|
+
return e;
|
|
18
|
+
}
|
|
19
|
+
function clear(node) { while (node.firstChild) node.removeChild(node.firstChild); }
|
|
20
|
+
|
|
21
|
+
var OPS = {
|
|
22
|
+
read: { colour: '#38bdf8', verb: 'Reading', rgb: [56, 189, 248] },
|
|
23
|
+
search: { colour: '#fbbf24', verb: 'Searching', rgb: [251, 191, 36] },
|
|
24
|
+
edit: { colour: '#f472b6', verb: 'Editing', rgb: [244, 114, 182] },
|
|
25
|
+
run: { colour: '#a78bfa', verb: 'Running', rgb: [167, 139, 250] },
|
|
26
|
+
};
|
|
27
|
+
var OP_NAMES = ['read', 'search', 'edit', 'run'];
|
|
28
|
+
var YAD_RGB = [52, 211, 153];
|
|
29
|
+
var SKY = [10, 16, 40];
|
|
30
|
+
var HALF_LIFE = 90000; // heat halves every 90 s
|
|
31
|
+
var SESSION_GAP = 20 * 60000; // a quiet 20 min starts a new session window
|
|
32
|
+
var IDLE_AFTER = 60000;
|
|
33
|
+
var REDUCED = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
34
|
+
var SESSION_HUES = ['#38bdf8', '#f472b6', '#fbbf24', '#a78bfa', '#34d399', '#fb923c'];
|
|
35
|
+
|
|
36
|
+
// ---- colour helpers
|
|
37
|
+
function hexRgb(h) { var n = parseInt(String(h).slice(1), 16); return [(n >> 16) & 255, (n >> 8) & 255, n & 255]; }
|
|
38
|
+
function mix(a, b, k) { return [0, 1, 2].map(function (i) { return Math.round(a[i] + (b[i] - a[i]) * k); }); }
|
|
39
|
+
function rgb(c, alpha) { return alpha === undefined ? 'rgb(' + c.join(',') + ')' : 'rgba(' + c.join(',') + ',' + alpha + ')'; }
|
|
40
|
+
|
|
41
|
+
// ---- the model: inline in a replay file, or from the server
|
|
42
|
+
function key() { return new URLSearchParams(location.search).get('t') || ''; }
|
|
43
|
+
function load() {
|
|
44
|
+
var inline = document.getElementById('yad-brain-data');
|
|
45
|
+
if (inline) return Promise.resolve(JSON.parse(inline.textContent));
|
|
46
|
+
return fetch('graph.json?t=' + encodeURIComponent(key()), { cache: 'no-store' }).then(function (r) {
|
|
47
|
+
return r.json().then(function (body) {
|
|
48
|
+
if (!r.ok) throw new Error(String(body.error || 'the brain could not be read') + (body.hint ? '. ' + body.hint : ''));
|
|
49
|
+
return body;
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function start(model) {
|
|
55
|
+
var nodes = model.nodes;
|
|
56
|
+
var edges = model.edges;
|
|
57
|
+
var replayOnly = Array.isArray(model.replay);
|
|
58
|
+
|
|
59
|
+
// ---- the plan: each declared file's tasks
|
|
60
|
+
var plan = Array.isArray(model.plan) ? model.plan : [];
|
|
61
|
+
var tasksOfFile = new Map();
|
|
62
|
+
plan.forEach(function (p, i) { p.files.forEach(function (f) { if (!tasksOfFile.has(f)) tasksOfFile.set(f, []); tasksOfFile.get(f).push(i); }); });
|
|
63
|
+
|
|
64
|
+
// ---- the sky: every node when the brain is small enough, else the work and the code it names
|
|
65
|
+
var all = nodes.length <= model.warnAbove;
|
|
66
|
+
var Graph = graphology.MultiDirectedGraph || graphology;
|
|
67
|
+
var graph = new Graph();
|
|
68
|
+
var rest = nodes.map(function (n) {
|
|
69
|
+
var base = hexRgb(n.colour || '#94a3b8');
|
|
70
|
+
return n.layer === 'work' ? mix(base, SKY, 0.25) : mix(base, SKY, n.inDefault ? 0.5 : 0.7);
|
|
71
|
+
});
|
|
72
|
+
nodes.forEach(function (n, i) {
|
|
73
|
+
if (!all && !n.inDefault) return;
|
|
74
|
+
graph.addNode(String(i), { label: n.label, size: n.layer === 'work' ? n.size * 1.05 : Math.max(1.6, n.size * (n.inDefault ? 0.75 : 0.5)), color: rgb(rest[i]), x: 0, y: 0 });
|
|
75
|
+
});
|
|
76
|
+
edges.forEach(function (e, k) {
|
|
77
|
+
if (graph.hasNode(String(e.s)) && graph.hasNode(String(e.t))) {
|
|
78
|
+
graph.addEdgeWithKey(String(k), String(e.s), String(e.t), { size: 0.4, color: nodes[e.s].layer === 'work' && nodes[e.t].layer === 'work' ? '#2a3561' : '#151d3d' });
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
graphologyLibrary.layout.circular.assign(graph);
|
|
82
|
+
if (graph.order > 1) {
|
|
83
|
+
var settings = graphologyLibrary.layoutForceAtlas2.inferSettings(graph);
|
|
84
|
+
settings.barnesHutOptimize = graph.order > 800;
|
|
85
|
+
settings.scalingRatio = (settings.scalingRatio || 1) * 1.6;
|
|
86
|
+
graphologyLibrary.layoutForceAtlas2.assign(graph, { iterations: graph.order < 500 ? 320 : graph.order < 2000 ? 160 : 70, settings: settings });
|
|
87
|
+
}
|
|
88
|
+
// A node outside the drawn sky that the agent touches is placed beside a neighbour that is drawn.
|
|
89
|
+
function ensureNode(i) {
|
|
90
|
+
var k = String(i);
|
|
91
|
+
if (graph.hasNode(k)) return true;
|
|
92
|
+
var near = null;
|
|
93
|
+
edges.forEach(function (e) { if (near === null && e.t === i && graph.hasNode(String(e.s))) near = e.s; if (near === null && e.s === i && graph.hasNode(String(e.t))) near = e.t; });
|
|
94
|
+
if (near === null) return false;
|
|
95
|
+
var a = graph.getNodeAttributes(String(near));
|
|
96
|
+
graph.addNode(k, { label: nodes[i].label, size: 2.4, color: rgb(rest[i]), x: a.x + (Math.random() - 0.5) * 30, y: a.y + (Math.random() - 0.5) * 30 });
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// ---- the state of the sky at a moment, rebuilt by replaying events
|
|
101
|
+
var events = [];
|
|
102
|
+
var S;
|
|
103
|
+
var heatOn = true;
|
|
104
|
+
function freshState() {
|
|
105
|
+
return { heat: new Map(), counts: { read: 0, search: 0, edit: 0, run: 0 }, fileState: new Map(), touched: new Set(), unmapped: new Set(),
|
|
106
|
+
outsidePlan: new Map(), task: null, tentative: false, lastNode: null, trail: [], last: null, lastAt: 0, named: [] };
|
|
107
|
+
}
|
|
108
|
+
S = freshState();
|
|
109
|
+
var session = ''; // '' = every session
|
|
110
|
+
var sessionsSeen = new Map();
|
|
111
|
+
var mode = replayOnly ? 'replay' : 'live'; // 'live' | 'replay'
|
|
112
|
+
var playhead = null; // ms, while replaying
|
|
113
|
+
var playing = false;
|
|
114
|
+
var speed = 1;
|
|
115
|
+
var span = 'session';
|
|
116
|
+
|
|
117
|
+
function clock() { return mode === 'live' ? Date.now() : (playhead || 0); }
|
|
118
|
+
function heatOf(i, at) {
|
|
119
|
+
var h = S.heat.get(i);
|
|
120
|
+
if (!h) return null;
|
|
121
|
+
var k = Math.pow(0.5, Math.max(0, at - h.at) / HALF_LIFE);
|
|
122
|
+
return { read: h.read * k, search: h.search * k, edit: h.edit * k, run: h.run * k, at: h.at, total: (h.read + h.search + h.edit + h.run) * k };
|
|
123
|
+
}
|
|
124
|
+
function addHeat(i, op, w, at) {
|
|
125
|
+
var h = heatOf(i, at) || { read: 0, search: 0, edit: 0, run: 0 };
|
|
126
|
+
h[op] += w;
|
|
127
|
+
S.heat.set(i, { read: h.read, search: h.search, edit: h.edit, run: h.run, at: at });
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Apply one event to the state; with `animate`, also fly a comet to it.
|
|
131
|
+
function apply(ev, animate) {
|
|
132
|
+
if (session && ev.s !== session) return;
|
|
133
|
+
// After a quiet stretch the plan starts over: last week's task is not today's (review 2).
|
|
134
|
+
// After a quiet stretch every panel starts over — the plan, the counts, what was touched — so they all
|
|
135
|
+
// cover the same time as the timeline's "This session" (review 3). The heat has faded by then anyway.
|
|
136
|
+
if (S.lastAt && ev.t - S.lastAt > SESSION_GAP) { var heat = S.heat; S = freshState(); S.heat = heat; }
|
|
137
|
+
S.counts[ev.op] += 1;
|
|
138
|
+
S.last = ev;
|
|
139
|
+
S.lastAt = ev.t;
|
|
140
|
+
ev.hits.forEach(function (h) {
|
|
141
|
+
S.touched.add(h.path);
|
|
142
|
+
addHeat(h.node, ev.op, 1, ev.t);
|
|
143
|
+
h.code.forEach(function (c) { addHeat(c, ev.op, 0.35, ev.t); });
|
|
144
|
+
var n = nodes[h.node];
|
|
145
|
+
if (n && n.kind === 'file') {
|
|
146
|
+
var was = S.fileState.get(h.node);
|
|
147
|
+
if (ev.op === 'edit' || !was) S.fileState.set(h.node, ev.op === 'edit' ? 'edit' : 'read');
|
|
148
|
+
// THE TASK IN HAND follows EDITS only — reading around is not changing course (review 2). An edit to
|
|
149
|
+
// a file the task's own story declares moves to that file's task; an edit to a file only ANOTHER
|
|
150
|
+
// story declares is flagged as outside the plan, then followed (the agent has changed course); an
|
|
151
|
+
// edit to a file no task declares is flagged. The first edit to a declared file picks the task.
|
|
152
|
+
if (ev.op === 'edit') {
|
|
153
|
+
var tasks = tasksOfFile.get(h.node) || [];
|
|
154
|
+
var sameStory = S.task === null ? -1 : tasks.findIndex(function (t) { return plan[t].story === plan[S.task].story; });
|
|
155
|
+
// A first pick from a file several stories declare is TENTATIVE: the next edit settles the story,
|
|
156
|
+
// and moving then is not leaving the plan (review 3).
|
|
157
|
+
var settling = S.tentative && sameStory === -1 && tasks.length;
|
|
158
|
+
if (!tasks.length || (S.task !== null && sameStory === -1 && !settling)) S.outsidePlan.set(h.path, (S.outsidePlan.get(h.path) || 0) + 1);
|
|
159
|
+
// Still tentative while the file in hand belongs to several stories: only a file of ONE story
|
|
160
|
+
// settles it (review 4).
|
|
161
|
+
var stories = new Set(tasks.map(function (t) { return plan[t].story; })).size;
|
|
162
|
+
if (sameStory !== -1) { S.task = tasks[sameStory]; S.tentative = S.tentative && stories > 1; }
|
|
163
|
+
else if (tasks.length) { S.task = tasks[0]; S.tentative = stories > 1; }
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (animate) launch(S.lastNode, h.node, ev);
|
|
167
|
+
// Only the few nodes touched last carry a label, so the sky never fills with text.
|
|
168
|
+
S.named = S.named.filter(function (x) { return x !== h.node; }).concat([h.node]).slice(-4);
|
|
169
|
+
S.trail.push({ node: h.node, op: ev.op });
|
|
170
|
+
if (S.trail.length > 12) S.trail.shift();
|
|
171
|
+
S.lastNode = h.node;
|
|
172
|
+
});
|
|
173
|
+
// A searched folder: the files under it glow softly, and the strongest few pulse.
|
|
174
|
+
(ev.areas || []).forEach(function (a, ai) {
|
|
175
|
+
a.nodes.forEach(function (n, k) {
|
|
176
|
+
addHeat(n, ev.op, 0.3, ev.t);
|
|
177
|
+
if (animate && ai === 0 && k < 6 && ensureNode(n)) pulse(n, OPS[ev.op].rgb, 0.7, k * 70);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
ev.outside.forEach(function (p) {
|
|
181
|
+
S.touched.add(p);
|
|
182
|
+
S.unmapped.add(p);
|
|
183
|
+
if (ev.op === 'edit') S.outsidePlan.set(p, (S.outsidePlan.get(p) || 0) + 1);
|
|
184
|
+
});
|
|
185
|
+
// A command lands on the task in hand: the pulse shows the agent is still at work there.
|
|
186
|
+
if (!ev.hits.length && !(ev.areas && ev.areas.length) && animate) {
|
|
187
|
+
var at = S.task !== null ? plan[S.task].task : S.lastNode;
|
|
188
|
+
if (at !== null && at !== undefined) pulse(at, ev.yad ? YAD_RGB : OPS[ev.op].rgb, 1.3);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// ---- the effects layer: comets, pulses, the trail
|
|
192
|
+
var fx = $('fx');
|
|
193
|
+
var ctx = fx.getContext('2d');
|
|
194
|
+
var comets = [];
|
|
195
|
+
var pulses = [];
|
|
196
|
+
var renderer = null;
|
|
197
|
+
function launch(from, to, ev) {
|
|
198
|
+
if (!ensureNode(to)) return;
|
|
199
|
+
var colour = ev.yad ? YAD_RGB : OPS[ev.op].rgb;
|
|
200
|
+
if (REDUCED) { pulse(to, colour, 1); return; }
|
|
201
|
+
if (from !== null && from !== to && graph.hasNode(String(from))) comets.push({ from: from, to: to, colour: colour, start: performance.now(), dur: 650 });
|
|
202
|
+
pulse(to, colour, 1, from !== null && from !== to ? 520 : 0);
|
|
203
|
+
follow(to);
|
|
204
|
+
loop();
|
|
205
|
+
}
|
|
206
|
+
function pulse(node, colour, scale, delay) {
|
|
207
|
+
if (!graph.hasNode(String(node))) return;
|
|
208
|
+
pulses.push({ node: node, colour: colour, start: performance.now() + (delay || 0), dur: REDUCED ? 1 : 1200, scale: scale || 1 });
|
|
209
|
+
loop();
|
|
210
|
+
}
|
|
211
|
+
function at(node) {
|
|
212
|
+
var a = graph.getNodeAttributes(String(node));
|
|
213
|
+
return renderer.graphToViewport({ x: a.x, y: a.y });
|
|
214
|
+
}
|
|
215
|
+
function sizeFx() {
|
|
216
|
+
var r = fx.getBoundingClientRect();
|
|
217
|
+
var dpr = window.devicePixelRatio || 1;
|
|
218
|
+
fx.width = Math.max(1, Math.round(r.width * dpr));
|
|
219
|
+
fx.height = Math.max(1, Math.round(r.height * dpr));
|
|
220
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
221
|
+
}
|
|
222
|
+
function ease(x) { return 1 - Math.pow(1 - x, 3); }
|
|
223
|
+
function drawFx(now) {
|
|
224
|
+
var r = fx.getBoundingClientRect();
|
|
225
|
+
ctx.clearRect(0, 0, r.width, r.height);
|
|
226
|
+
if (!renderer) return false;
|
|
227
|
+
ctx.globalCompositeOperation = 'lighter';
|
|
228
|
+
// The trail: the last hops, faint, so the path stays readable.
|
|
229
|
+
for (var i = 1; i < S.trail.length; i++) {
|
|
230
|
+
var a = S.trail[i - 1];
|
|
231
|
+
var b = S.trail[i];
|
|
232
|
+
if (!graph.hasNode(String(a.node)) || !graph.hasNode(String(b.node)) || a.node === b.node) continue;
|
|
233
|
+
var pa = at(a.node);
|
|
234
|
+
var pb = at(b.node);
|
|
235
|
+
ctx.strokeStyle = rgb(OPS[b.op].rgb, 0.05 + 0.18 * (i / S.trail.length));
|
|
236
|
+
ctx.lineWidth = 1.2;
|
|
237
|
+
ctx.beginPath(); ctx.moveTo(pa.x, pa.y); ctx.lineTo(pb.x, pb.y); ctx.stroke();
|
|
238
|
+
}
|
|
239
|
+
var busy = false;
|
|
240
|
+
comets = comets.filter(function (c) {
|
|
241
|
+
var k = (now - c.start) / c.dur;
|
|
242
|
+
if (k >= 1) return false;
|
|
243
|
+
busy = true;
|
|
244
|
+
var p0 = at(c.from);
|
|
245
|
+
var p1 = at(c.to);
|
|
246
|
+
var head = ease(Math.max(0, k));
|
|
247
|
+
for (var j = 0; j < 24; j++) {
|
|
248
|
+
var t = head - j * 0.022;
|
|
249
|
+
if (t < 0) break;
|
|
250
|
+
var x = p0.x + (p1.x - p0.x) * t;
|
|
251
|
+
var y = p0.y + (p1.y - p0.y) * t;
|
|
252
|
+
var alpha = (1 - j / 24) * 0.55;
|
|
253
|
+
ctx.fillStyle = rgb(c.colour, alpha);
|
|
254
|
+
ctx.beginPath(); ctx.arc(x, y, Math.max(0.6, 3.2 * (1 - j / 24)), 0, Math.PI * 2); ctx.fill();
|
|
255
|
+
}
|
|
256
|
+
var hx = p0.x + (p1.x - p0.x) * head;
|
|
257
|
+
var hy = p0.y + (p1.y - p0.y) * head;
|
|
258
|
+
var g = ctx.createRadialGradient(hx, hy, 0, hx, hy, 16);
|
|
259
|
+
g.addColorStop(0, rgb([255, 255, 255], 0.95));
|
|
260
|
+
g.addColorStop(0.25, rgb(c.colour, 0.75));
|
|
261
|
+
g.addColorStop(1, rgb(c.colour, 0));
|
|
262
|
+
ctx.fillStyle = g;
|
|
263
|
+
ctx.beginPath(); ctx.arc(hx, hy, 16, 0, Math.PI * 2); ctx.fill();
|
|
264
|
+
return true;
|
|
265
|
+
});
|
|
266
|
+
pulses = pulses.filter(function (p) {
|
|
267
|
+
var k = (now - p.start) / p.dur;
|
|
268
|
+
if (k < 0) { busy = true; return true; }
|
|
269
|
+
if (k >= 1 || !graph.hasNode(String(p.node))) return false;
|
|
270
|
+
busy = true;
|
|
271
|
+
var c = at(p.node);
|
|
272
|
+
var radius = (6 + 42 * ease(k)) * p.scale;
|
|
273
|
+
ctx.strokeStyle = rgb(p.colour, 0.85 * (1 - k));
|
|
274
|
+
ctx.lineWidth = 2 * (1 - k) + 0.5;
|
|
275
|
+
ctx.beginPath(); ctx.arc(c.x, c.y, radius, 0, Math.PI * 2); ctx.stroke();
|
|
276
|
+
var g = ctx.createRadialGradient(c.x, c.y, 0, c.x, c.y, 22 * p.scale);
|
|
277
|
+
g.addColorStop(0, rgb(p.colour, 0.5 * (1 - k)));
|
|
278
|
+
g.addColorStop(1, rgb(p.colour, 0));
|
|
279
|
+
ctx.fillStyle = g;
|
|
280
|
+
ctx.beginPath(); ctx.arc(c.x, c.y, 22 * p.scale, 0, Math.PI * 2); ctx.fill();
|
|
281
|
+
return true;
|
|
282
|
+
});
|
|
283
|
+
ctx.globalCompositeOperation = 'source-over';
|
|
284
|
+
return busy;
|
|
285
|
+
}
|
|
286
|
+
// One loop for everything that moves: effects every frame, the heat's fade a few times a second, and
|
|
287
|
+
// replay. It stops when nothing moves.
|
|
288
|
+
var looping = false;
|
|
289
|
+
var lastRefresh = 0;
|
|
290
|
+
var lastFrame = 0;
|
|
291
|
+
function loop() {
|
|
292
|
+
if (looping) return;
|
|
293
|
+
looping = true;
|
|
294
|
+
lastFrame = performance.now();
|
|
295
|
+
window.requestAnimationFrame(frame);
|
|
296
|
+
}
|
|
297
|
+
function frame(now) {
|
|
298
|
+
var dt = now - lastFrame;
|
|
299
|
+
lastFrame = now;
|
|
300
|
+
if (playing && mode === 'replay') advance(dt);
|
|
301
|
+
var busy = drawFx(now);
|
|
302
|
+
var warm = heatOn && S.heat.size && clock() - S.lastAt < HALF_LIFE * 6;
|
|
303
|
+
if (renderer && (busy || warm) && now - lastRefresh > (busy ? 60 : 250)) { renderer.refresh({ skipIndexation: true }); lastRefresh = now; }
|
|
304
|
+
if (busy || playing || (warm && mode === 'live')) window.requestAnimationFrame(frame);
|
|
305
|
+
else { looping = false; if (renderer) renderer.refresh({ skipIndexation: true }); drawFx(now); }
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// ---- sigma
|
|
309
|
+
// The node a person is holding or looking at: its links are drawn bright and its neighbours named, so all its
|
|
310
|
+
// connections can be seen while it is dragged into open space.
|
|
311
|
+
var held = null;
|
|
312
|
+
var heldNear = null;
|
|
313
|
+
function hold(i) {
|
|
314
|
+
held = i;
|
|
315
|
+
heldNear = null;
|
|
316
|
+
if (i !== null) {
|
|
317
|
+
heldNear = new Set([i]);
|
|
318
|
+
// At most 60 neighbours are named, so holding a node with hundreds of links does not bury the sky in labels; every link is still lit.
|
|
319
|
+
edges.forEach(function (e) { if (heldNear.size > 60) return; if (e.s === i) heldNear.add(e.t); else if (e.t === i) heldNear.add(e.s); });
|
|
320
|
+
}
|
|
321
|
+
if (renderer) renderer.refresh({ skipIndexation: true });
|
|
322
|
+
}
|
|
323
|
+
function reducer(nodeKey, data) {
|
|
324
|
+
var i = Number(nodeKey);
|
|
325
|
+
var res = Object.assign({}, data);
|
|
326
|
+
if (!nodes[i]) return res;
|
|
327
|
+
// A held node and its neighbours are named and drawn on top, and still show their heat: the agent's work
|
|
328
|
+
// on the very nodes a person is looking at must not vanish (review).
|
|
329
|
+
var near = heldNear !== null && heldNear.has(i);
|
|
330
|
+
if (near) { res.label = nodes[i].label; res.forceLabel = true; res.zIndex = 3; if (i === held) res.highlighted = true; }
|
|
331
|
+
else if (nodes[i].layer !== 'work') res.label = '';
|
|
332
|
+
if (!heatOn) return res;
|
|
333
|
+
var h = heatOf(i, clock());
|
|
334
|
+
if (!h || h.total < 0.03) return res;
|
|
335
|
+
var hot = OP_NAMES.reduce(function (best, op) { return h[op] > h[best] ? op : best; }, 'read');
|
|
336
|
+
var k = Math.min(1, 0.3 + h.total * 0.45);
|
|
337
|
+
res.color = rgb(mix(rest[i], OPS[hot].rgb, k));
|
|
338
|
+
res.size = data.size * (1 + Math.min(1.8, h.total * 0.55));
|
|
339
|
+
res.zIndex = near ? 3 : 2;
|
|
340
|
+
if (S.named.indexOf(i) !== -1 && clock() - h.at < 20000) { res.label = nodes[i].label; res.forceLabel = true; }
|
|
341
|
+
return res;
|
|
342
|
+
}
|
|
343
|
+
function edgeReducer(edgeKey, data) {
|
|
344
|
+
var e = edges[Number(edgeKey)];
|
|
345
|
+
if (held !== null && e && (e.s === held || e.t === held)) return Object.assign({}, data, { color: 'rgba(196,210,255,0.85)', size: 1.4, zIndex: 3 });
|
|
346
|
+
if (!heatOn) return data;
|
|
347
|
+
var a = heatOf(e.s, clock());
|
|
348
|
+
var b = heatOf(e.t, clock());
|
|
349
|
+
if (!a || !b || a.total < 0.2 || b.total < 0.2) return data;
|
|
350
|
+
return Object.assign({}, data, { color: rgb(mix([21, 29, 61], [150, 170, 240], Math.min(0.75, 0.2 + (a.total + b.total) * 0.12))), size: 0.9 });
|
|
351
|
+
}
|
|
352
|
+
// Labels on a dark sky: light text, and a dark pill on hover instead of sigma's white box.
|
|
353
|
+
function drawHover(context, d, s) {
|
|
354
|
+
var size = s.labelSize;
|
|
355
|
+
context.font = s.labelWeight + ' ' + size + 'px ' + s.labelFont;
|
|
356
|
+
var w = context.measureText(d.label || '').width;
|
|
357
|
+
var x = d.x + d.size + 4;
|
|
358
|
+
var y = d.y;
|
|
359
|
+
context.fillStyle = 'rgba(10,16,36,0.92)';
|
|
360
|
+
context.strokeStyle = 'rgba(173,190,255,0.25)';
|
|
361
|
+
context.lineWidth = 1;
|
|
362
|
+
context.beginPath();
|
|
363
|
+
if (context.roundRect) context.roundRect(x - 6, y - size / 2 - 5, w + 12, size + 10, 6); else context.rect(x - 6, y - size / 2 - 5, w + 12, size + 10);
|
|
364
|
+
context.fill(); context.stroke();
|
|
365
|
+
context.fillStyle = '#e6ecff';
|
|
366
|
+
context.fillText(d.label || '', x, y + size / 3);
|
|
367
|
+
}
|
|
368
|
+
try {
|
|
369
|
+
renderer = new Sigma(graph, $('graph'), {
|
|
370
|
+
nodeReducer: reducer,
|
|
371
|
+
edgeReducer: edgeReducer,
|
|
372
|
+
zIndex: true,
|
|
373
|
+
labelColor: { color: '#c9d3f2' },
|
|
374
|
+
labelSize: 12,
|
|
375
|
+
labelWeight: '500',
|
|
376
|
+
labelFont: getComputedStyle(document.body).fontFamily,
|
|
377
|
+
labelRenderedSizeThreshold: 9,
|
|
378
|
+
defaultDrawNodeHover: drawHover,
|
|
379
|
+
stagePadding: 40,
|
|
380
|
+
});
|
|
381
|
+
} catch {
|
|
382
|
+
$('empty').hidden = false;
|
|
383
|
+
$('empty-title').textContent = 'This browser cannot draw the sky';
|
|
384
|
+
$('empty-hint').textContent = 'It needs WebGL, which is turned off here. The Now card, the plan and the timeline still work.';
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// ---- follow the agent
|
|
388
|
+
var followOn = true;
|
|
389
|
+
var lastFollow = 0;
|
|
390
|
+
var userMoving = false;
|
|
391
|
+
function follow(node) {
|
|
392
|
+
if (!followOn || !renderer || userMoving) return;
|
|
393
|
+
var t = performance.now();
|
|
394
|
+
if (t - lastFollow < 900) return;
|
|
395
|
+
lastFollow = t;
|
|
396
|
+
var d = renderer.getNodeDisplayData(String(node));
|
|
397
|
+
if (d) renderer.getCamera().animate({ x: d.x, y: d.y, ratio: Math.min(renderer.getCamera().ratio, 0.75) }, { duration: REDUCED ? 0 : 700 });
|
|
398
|
+
}
|
|
399
|
+
function setFollow(on, why) {
|
|
400
|
+
followOn = on;
|
|
401
|
+
$('t-follow').setAttribute('aria-pressed', String(on));
|
|
402
|
+
if (why) toast(why);
|
|
403
|
+
}
|
|
404
|
+
var sky = $('graph');
|
|
405
|
+
['wheel', 'mousedown', 'touchstart'].forEach(function (type) {
|
|
406
|
+
sky.addEventListener(type, function () {
|
|
407
|
+
if (followOn) setFollow(false, 'Follow paused while you look around. Press F to follow again.');
|
|
408
|
+
}, { passive: true });
|
|
409
|
+
});
|
|
410
|
+
var toastTimer = null;
|
|
411
|
+
function toast(text) {
|
|
412
|
+
var t = $('toast');
|
|
413
|
+
t.textContent = text;
|
|
414
|
+
t.hidden = false;
|
|
415
|
+
clearTimeout(toastTimer);
|
|
416
|
+
toastTimer = setTimeout(function () { t.hidden = true; }, 3200);
|
|
417
|
+
}
|
|
418
|
+
$('t-follow').addEventListener('click', function () { setFollow(!followOn); });
|
|
419
|
+
$('t-heat').addEventListener('click', function () {
|
|
420
|
+
heatOn = !heatOn;
|
|
421
|
+
this.setAttribute('aria-pressed', String(heatOn));
|
|
422
|
+
if (renderer) renderer.refresh();
|
|
423
|
+
});
|
|
424
|
+
$('t-fit').addEventListener('click', function () { if (renderer) renderer.getCamera().animate({ x: 0.5, y: 0.5, ratio: 1, angle: 0 }, { duration: 500 }); });
|
|
425
|
+
|
|
426
|
+
// ---- inspecting a node
|
|
427
|
+
if (renderer) {
|
|
428
|
+
renderer.on('clickNode', function (ev) { if (!justDragged) { hold(Number(ev.node)); inspect(Number(ev.node)); } });
|
|
429
|
+
renderer.on('clickStage', function () { if (!justDragged) { $('inspect').hidden = true; hold(null); } });
|
|
430
|
+
// Press and hold a node to drag it: its links light up and follow it, and the camera holds still until the
|
|
431
|
+
// button is let go. The node stays where it is dropped; comets fly to where it is now.
|
|
432
|
+
var dragged = null;
|
|
433
|
+
var justDragged = false;
|
|
434
|
+
renderer.on('downNode', function (ev) {
|
|
435
|
+
// The left button only: sigma never reports a right or middle button's release, so such a drag would
|
|
436
|
+
// never end.
|
|
437
|
+
var o = ev.event.original;
|
|
438
|
+
if (o && o.button !== undefined && o.button !== 0) return;
|
|
439
|
+
dragged = ev.node;
|
|
440
|
+
renderer.getContainer().style.cursor = 'grabbing';
|
|
441
|
+
justDragged = false;
|
|
442
|
+
if (!renderer.getCustomBBox()) renderer.setCustomBBox(renderer.getBBox());
|
|
443
|
+
$('inspect').hidden = true;
|
|
444
|
+
hold(Number(ev.node));
|
|
445
|
+
});
|
|
446
|
+
renderer.on('moveBody', function (ev) {
|
|
447
|
+
if (dragged === null) return;
|
|
448
|
+
// The button came up where no mouseup reached the page (the window lost focus): the drag is over.
|
|
449
|
+
if (ev.event.original.buttons === 0 && !('touches' in ev.event.original)) { drop(); return; }
|
|
450
|
+
var at = renderer.viewportToGraph(ev.event);
|
|
451
|
+
graph.mergeNodeAttributes(dragged, { x: at.x, y: at.y });
|
|
452
|
+
justDragged = true;
|
|
453
|
+
ev.preventSigmaDefault();
|
|
454
|
+
if (ev.event.original.cancelable) ev.event.original.preventDefault();
|
|
455
|
+
ev.event.original.stopPropagation();
|
|
456
|
+
});
|
|
457
|
+
var drop = function () {
|
|
458
|
+
if (dragged === null) return;
|
|
459
|
+
dragged = null;
|
|
460
|
+
renderer.getContainer().style.cursor = '';
|
|
461
|
+
// No card after a drag: it would cover the links just pulled into view. A plain click opens it.
|
|
462
|
+
// The click that follows a drag must not open or close anything.
|
|
463
|
+
setTimeout(function () { justDragged = false; }, 0);
|
|
464
|
+
};
|
|
465
|
+
renderer.on('enterNode', function () { renderer.getContainer().style.cursor = 'grab'; });
|
|
466
|
+
renderer.on('leaveNode', function () { if (dragged === null) renderer.getContainer().style.cursor = ''; });
|
|
467
|
+
renderer.on('upNode', drop);
|
|
468
|
+
renderer.on('upStage', drop);
|
|
469
|
+
renderer.getMouseCaptor().on('mouseup', drop);
|
|
470
|
+
}
|
|
471
|
+
function inspect(i) {
|
|
472
|
+
var box = $('inspect');
|
|
473
|
+
clear(box);
|
|
474
|
+
var n = nodes[i];
|
|
475
|
+
box.appendChild(el('strong', n.label));
|
|
476
|
+
if (n.file || n.kind === 'file') box.appendChild(el('div', (n.repo ? n.repo + '/' : '') + (n.file || n.label) + (n.at ? ' ' + n.at : ''), 'ipath'));
|
|
477
|
+
else box.appendChild(el('div', n.id, 'ipath'));
|
|
478
|
+
var h = S.heat.get(i);
|
|
479
|
+
var row = el('div', null, 'icounts');
|
|
480
|
+
var touches = 0;
|
|
481
|
+
events.forEach(function (ev) { if ((!session || ev.s === session) && ev.t <= clock() && ev.hits.some(function (x) { return x.node === i; })) touches += 1; });
|
|
482
|
+
row.appendChild(el('span', touches ? 'Touched ' + touches + (touches === 1 ? ' time' : ' times') + ' in this window' : 'Not touched in this window'));
|
|
483
|
+
box.appendChild(row);
|
|
484
|
+
if (!h) box.appendChild(el('div', n.kind === 'code' ? 'A code symbol Graphify found.' : 'Part of the plan.', 'quiet small'));
|
|
485
|
+
var d = renderer.getNodeDisplayData(String(i));
|
|
486
|
+
var p = d ? renderer.framedGraphToViewport({ x: d.x, y: d.y }) : { x: 40, y: 40 };
|
|
487
|
+
var r = $('graph').getBoundingClientRect();
|
|
488
|
+
box.style.left = Math.min(r.width - 330, Math.max(8, p.x + 14)) + 'px';
|
|
489
|
+
box.style.top = Math.min(r.height - 120, Math.max(8, p.y - 10)) + 'px';
|
|
490
|
+
box.hidden = false;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// ---- the panels
|
|
494
|
+
function ago(ms) {
|
|
495
|
+
var s = Math.max(0, Math.round(ms / 1000));
|
|
496
|
+
if (s < 60) return s + ' s ago';
|
|
497
|
+
var m = Math.round(s / 60);
|
|
498
|
+
if (m < 60) return m + ' min ago';
|
|
499
|
+
return Math.round(m / 60) + ' h ago';
|
|
500
|
+
}
|
|
501
|
+
function nowText(ev) {
|
|
502
|
+
if (!ev) return null;
|
|
503
|
+
var verb = OPS[ev.op].verb;
|
|
504
|
+
var target;
|
|
505
|
+
if (ev.op === 'run') target = ev.yad ? 'yad ' + ev.yad : 'a shell command';
|
|
506
|
+
else if (ev.hits.length) target = ev.hits[0].path;
|
|
507
|
+
else if (ev.areas && ev.areas.length) target = ev.areas[0].path + '/';
|
|
508
|
+
else if (ev.outside.length) target = ev.outside[0];
|
|
509
|
+
else target = ev.op === 'search' ? 'the repo' : 'a file outside the repos';
|
|
510
|
+
return { verb: verb, target: target, more: Math.max(0, ev.hits.length + (ev.areas || []).length + ev.outside.length - 1) };
|
|
511
|
+
}
|
|
512
|
+
var lastSaid = 0;
|
|
513
|
+
function paintNow() {
|
|
514
|
+
var t = nowText(S.last);
|
|
515
|
+
if (!t) {
|
|
516
|
+
$('now-op').textContent = 'Waiting';
|
|
517
|
+
$('now-op').style.color = '';
|
|
518
|
+
$('now-path').textContent = mode === 'live' ? 'for the agent\'s first move' : 'for the first event';
|
|
519
|
+
$('now-path').classList.add('is-quiet');
|
|
520
|
+
paintWhen();
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
var op = $('now-op');
|
|
524
|
+
op.textContent = t.verb;
|
|
525
|
+
op.style.color = S.last.yad ? rgb(YAD_RGB) : OPS[S.last.op].colour;
|
|
526
|
+
$('now-path').textContent = t.target + (t.more ? ' and ' + t.more + ' more' : '');
|
|
527
|
+
$('now-path').classList.remove('is-quiet');
|
|
528
|
+
paintWhen();
|
|
529
|
+
if (performance.now() - lastSaid > 2000) { $('now-say').textContent = t.verb + ' ' + t.target; lastSaid = performance.now(); }
|
|
530
|
+
}
|
|
531
|
+
function paintWhen() {
|
|
532
|
+
if (!S.last) { $('now-when').textContent = ''; return; }
|
|
533
|
+
$('now-when').textContent = mode === 'live' ? ago(Date.now() - S.last.t) : new Date(S.last.t).toLocaleTimeString();
|
|
534
|
+
}
|
|
535
|
+
function paintCounts() {
|
|
536
|
+
OP_NAMES.forEach(function (op) { $('n-' + op).textContent = String(S.counts[op]); paintSpark(op); });
|
|
537
|
+
}
|
|
538
|
+
function paintSpark(op) {
|
|
539
|
+
var c = $('sp-' + op);
|
|
540
|
+
var r = c.getBoundingClientRect();
|
|
541
|
+
var dpr = window.devicePixelRatio || 1;
|
|
542
|
+
c.width = Math.max(1, Math.round(r.width * dpr));
|
|
543
|
+
c.height = Math.max(1, Math.round(r.height * dpr));
|
|
544
|
+
var g = c.getContext('2d');
|
|
545
|
+
g.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
546
|
+
var end = clock();
|
|
547
|
+
var buckets = new Array(30).fill(0);
|
|
548
|
+
events.forEach(function (ev) {
|
|
549
|
+
if (ev.op !== op || ev.t > end || (session && ev.s !== session)) return;
|
|
550
|
+
var b = Math.floor((end - ev.t) / 20000);
|
|
551
|
+
if (b < 30) buckets[29 - b] += 1;
|
|
552
|
+
});
|
|
553
|
+
var max = Math.max(1, Math.max.apply(null, buckets));
|
|
554
|
+
var w = r.width / 30;
|
|
555
|
+
g.fillStyle = rgb(OPS[op].rgb, 0.18);
|
|
556
|
+
g.fillRect(0, r.height - 1, r.width, 1);
|
|
557
|
+
buckets.forEach(function (v, i) {
|
|
558
|
+
if (!v) return;
|
|
559
|
+
var h = Math.max(2, (v / max) * (r.height - 2));
|
|
560
|
+
g.fillStyle = rgb(OPS[op].rgb, 0.35 + 0.65 * (i / 30));
|
|
561
|
+
g.fillRect(i * w + 1, r.height - h, Math.max(1, w - 2), h);
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
function paintPlan() {
|
|
565
|
+
var box = $('plan-task');
|
|
566
|
+
clear(box);
|
|
567
|
+
if (S.task === null) {
|
|
568
|
+
box.appendChild(el('p', plan.length ? 'When the agent touches a file a task declares, that task shows here with its files.' : 'No task in this brain declares files yet. Specs with a Files line per task fill this in.', 'quiet'));
|
|
569
|
+
$('where-story').textContent = S.last ? 'Working' : 'No task yet';
|
|
570
|
+
$('where-task').textContent = '';
|
|
571
|
+
} else {
|
|
572
|
+
var p = plan[S.task];
|
|
573
|
+
var story = p.story !== null ? nodes[p.story].label : '';
|
|
574
|
+
box.appendChild(el('p', story, 'story'));
|
|
575
|
+
box.appendChild(el('p', nodes[p.task].label, 'task'));
|
|
576
|
+
var edited = p.files.filter(function (f) { return S.fileState.get(f) === 'edit'; }).length;
|
|
577
|
+
var meter = el('div', null, 'meter');
|
|
578
|
+
var fill = el('span');
|
|
579
|
+
fill.style.width = (p.files.length ? (100 * edited / p.files.length) : 0) + '%';
|
|
580
|
+
meter.appendChild(fill);
|
|
581
|
+
box.appendChild(meter);
|
|
582
|
+
box.appendChild(el('p', edited + ' of ' + p.files.length + ' declared files edited', 'meter-l'));
|
|
583
|
+
var ul = el('ul', null, 'files');
|
|
584
|
+
p.files.forEach(function (f) {
|
|
585
|
+
var st = S.fileState.get(f);
|
|
586
|
+
var li = el('li', null, st === 'edit' ? 'is-edit' : st === 'read' ? 'is-read' : 'is-none');
|
|
587
|
+
li.appendChild(el('span', st === 'edit' ? '✓' : st === 'read' ? '◐' : '○', 'st'));
|
|
588
|
+
li.appendChild(el('span', nodes[f].label));
|
|
589
|
+
li.title = st === 'edit' ? 'Edited' : st === 'read' ? 'Read, not edited yet' : 'Not touched yet';
|
|
590
|
+
ul.appendChild(li);
|
|
591
|
+
});
|
|
592
|
+
box.appendChild(ul);
|
|
593
|
+
$('where-story').textContent = story;
|
|
594
|
+
$('where-task').textContent = nodes[p.task].label;
|
|
595
|
+
}
|
|
596
|
+
var out = $('plan-out-list');
|
|
597
|
+
clear(out);
|
|
598
|
+
S.outsidePlan.forEach(function (n, p) { out.appendChild(el('li', p + (n > 1 ? ' ×' + n : ''))); });
|
|
599
|
+
$('plan-out').hidden = !S.outsidePlan.size;
|
|
600
|
+
$('touched-n').textContent = String(S.touched.size);
|
|
601
|
+
var un = $('unmapped-list');
|
|
602
|
+
clear(un);
|
|
603
|
+
S.unmapped.forEach(function (p) { un.appendChild(el('li', p)); });
|
|
604
|
+
$('unmapped-n').textContent = String(S.unmapped.size);
|
|
605
|
+
$('unmapped').hidden = !S.unmapped.size;
|
|
606
|
+
}
|
|
607
|
+
function paintMode() {
|
|
608
|
+
var dot = $('pulse');
|
|
609
|
+
var idle = mode === 'live' && (!S.last || Date.now() - S.last.t > IDLE_AFTER);
|
|
610
|
+
dot.className = 'pulse ' + (mode === 'replay' ? 'is-replay' : idle ? 'is-idle' : 'is-live');
|
|
611
|
+
$('mode').textContent = mode === 'replay' ? (replayOnly ? 'Replay' : 'Replaying') : idle ? 'Live, quiet' : 'Live';
|
|
612
|
+
$('r-live').classList.toggle('is-on', mode === 'live');
|
|
613
|
+
$('r-live').hidden = replayOnly;
|
|
614
|
+
$('r-play').textContent = playing ? 'Pause' : 'Play';
|
|
615
|
+
}
|
|
616
|
+
function paintEmpty() {
|
|
617
|
+
if (!renderer) return;
|
|
618
|
+
var none = !events.length;
|
|
619
|
+
$('empty').hidden = !none;
|
|
620
|
+
}
|
|
621
|
+
function paintAll() { paintNow(); paintCounts(); paintPlan(); paintMode(); paintEmpty(); paintRiver(); }
|
|
622
|
+
|
|
623
|
+
// ---- sessions
|
|
624
|
+
function noteSession(ev) {
|
|
625
|
+
if (!ev.s || sessionsSeen.has(ev.s)) return;
|
|
626
|
+
sessionsSeen.set(ev.s, sessionsSeen.size);
|
|
627
|
+
var o = el('option', 'Session ' + sessionsSeen.size + ' (' + (ev.h === 'cursor' ? 'Cursor' : 'Claude Code') + ', from ' + new Date(ev.t).toLocaleTimeString() + ')');
|
|
628
|
+
o.value = ev.s;
|
|
629
|
+
o.style.color = SESSION_HUES[(sessionsSeen.size - 1) % SESSION_HUES.length];
|
|
630
|
+
$('session').appendChild(o);
|
|
631
|
+
$('sessions').hidden = sessionsSeen.size < 2;
|
|
632
|
+
}
|
|
633
|
+
$('session').addEventListener('change', function () { session = this.value; rebuild(mode === 'live' ? Infinity : playhead); });
|
|
634
|
+
|
|
635
|
+
// ---- the river: the timeline
|
|
636
|
+
var river = $('river');
|
|
637
|
+
var rctx = river.getContext('2d');
|
|
638
|
+
function windowOf() {
|
|
639
|
+
var end = mode === 'live' ? Date.now() : Math.max(playhead || 0, events.length ? events[events.length - 1].t : 0);
|
|
640
|
+
if (mode === 'live') end = Date.now();
|
|
641
|
+
else if (events.length) end = Math.max(end, events[events.length - 1].t);
|
|
642
|
+
var shown = shownEvents();
|
|
643
|
+
var startT = shown.length ? shown[0].t : end - 600000;
|
|
644
|
+
if (span === 'session' && shown.length) {
|
|
645
|
+
for (var i = shown.length - 1; i > 0; i--) { if (shown[i].t - shown[i - 1].t > SESSION_GAP) { startT = shown[i].t; break; } }
|
|
646
|
+
}
|
|
647
|
+
if (end - startT < 60000) startT = end - 60000;
|
|
648
|
+
var pad = (end - startT) * 0.02;
|
|
649
|
+
return { from: startT - pad, to: end + pad };
|
|
650
|
+
}
|
|
651
|
+
function paintRiver() {
|
|
652
|
+
var r = river.getBoundingClientRect();
|
|
653
|
+
var dpr = window.devicePixelRatio || 1;
|
|
654
|
+
river.width = Math.max(1, Math.round(r.width * dpr));
|
|
655
|
+
river.height = Math.max(1, Math.round(r.height * dpr));
|
|
656
|
+
rctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
657
|
+
rctx.clearRect(0, 0, r.width, r.height);
|
|
658
|
+
var w = windowOf();
|
|
659
|
+
var lane = r.height / 4;
|
|
660
|
+
OP_NAMES.forEach(function (op, li) {
|
|
661
|
+
rctx.fillStyle = 'rgba(173,190,255,0.04)';
|
|
662
|
+
rctx.fillRect(0, li * lane + 2, r.width, lane - 4);
|
|
663
|
+
});
|
|
664
|
+
var cut = clock();
|
|
665
|
+
events.forEach(function (ev) {
|
|
666
|
+
if (ev.t < w.from || ev.t > w.to) return;
|
|
667
|
+
var x = ((ev.t - w.from) / (w.to - w.from)) * r.width;
|
|
668
|
+
var li = OP_NAMES.indexOf(ev.op);
|
|
669
|
+
var dim = (session && ev.s !== session) || ev.t > cut;
|
|
670
|
+
rctx.fillStyle = rgb(ev.yad ? YAD_RGB : OPS[ev.op].rgb, dim ? 0.18 : 0.9);
|
|
671
|
+
rctx.fillRect(Math.round(x), li * lane + 5, 2, lane - 10);
|
|
672
|
+
});
|
|
673
|
+
var px = ((cut - w.from) / (w.to - w.from)) * r.width;
|
|
674
|
+
if (px >= 0 && px <= r.width) {
|
|
675
|
+
rctx.fillStyle = mode === 'live' ? 'rgba(52,211,153,0.9)' : 'rgba(251,191,36,0.95)';
|
|
676
|
+
rctx.fillRect(Math.round(px) - 1, 0, 2, r.height);
|
|
677
|
+
}
|
|
678
|
+
$('river-from').textContent = new Date(w.from).toLocaleTimeString();
|
|
679
|
+
$('river-to').textContent = mode === 'live' ? 'now' : new Date(w.to).toLocaleTimeString();
|
|
680
|
+
}
|
|
681
|
+
function timeAt(clientX) {
|
|
682
|
+
var r = river.getBoundingClientRect();
|
|
683
|
+
var w = windowOf();
|
|
684
|
+
return w.from + Math.min(1, Math.max(0, (clientX - r.left) / r.width)) * (w.to - w.from);
|
|
685
|
+
}
|
|
686
|
+
var dragging = false;
|
|
687
|
+
river.addEventListener('pointerdown', function (e) { dragging = true; river.setPointerCapture(e.pointerId); scrubTo(timeAt(e.clientX)); });
|
|
688
|
+
river.addEventListener('pointermove', function (e) {
|
|
689
|
+
if (dragging) scrubTo(timeAt(e.clientX));
|
|
690
|
+
tip(e);
|
|
691
|
+
});
|
|
692
|
+
river.addEventListener('pointerup', function () { dragging = false; });
|
|
693
|
+
river.addEventListener('pointerleave', function () { $('river-tip').hidden = true; });
|
|
694
|
+
function tip(e) {
|
|
695
|
+
var t = timeAt(e.clientX);
|
|
696
|
+
var best = null;
|
|
697
|
+
events.forEach(function (ev) { if (!best || Math.abs(ev.t - t) < Math.abs(best.t - t)) best = ev; });
|
|
698
|
+
var box = $('river-tip');
|
|
699
|
+
var w = windowOf();
|
|
700
|
+
if (!best || Math.abs(best.t - t) > (w.to - w.from) / 60) { box.hidden = true; return; }
|
|
701
|
+
var nt = nowText(best);
|
|
702
|
+
clear(box);
|
|
703
|
+
box.appendChild(el('b', nt.verb + ' '));
|
|
704
|
+
box.appendChild(document.createTextNode(nt.target + ' ' + new Date(best.t).toLocaleTimeString()));
|
|
705
|
+
var r = river.getBoundingClientRect();
|
|
706
|
+
box.style.left = Math.min(r.width - 120, Math.max(120, e.clientX - r.left)) + 'px';
|
|
707
|
+
box.hidden = false;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
// ---- replay
|
|
711
|
+
function rebuild(until) {
|
|
712
|
+
S = freshState();
|
|
713
|
+
comets = []; pulses = [];
|
|
714
|
+
events.forEach(function (ev) { if (ev.t <= until) apply(ev, false); });
|
|
715
|
+
if (renderer) renderer.refresh();
|
|
716
|
+
paintAll();
|
|
717
|
+
loop();
|
|
718
|
+
}
|
|
719
|
+
function scrubTo(t) {
|
|
720
|
+
mode = 'replay';
|
|
721
|
+
playing = false;
|
|
722
|
+
playhead = t;
|
|
723
|
+
rebuild(t);
|
|
724
|
+
}
|
|
725
|
+
// The events this view shows: every session, or the one picked.
|
|
726
|
+
function shownEvents() { return session ? events.filter(function (ev) { return ev.s === session; }) : events; }
|
|
727
|
+
function advance(dt) {
|
|
728
|
+
var from = playhead;
|
|
729
|
+
var to = playhead + dt * speed;
|
|
730
|
+
// A quiet stretch is skipped: replay jumps to just before the next event, so it never plays dead air.
|
|
731
|
+
var next = shownEvents().find(function (ev) { return ev.t > from; });
|
|
732
|
+
if (next && next.t - from > 2500) { from = next.t - 600; to = from + dt * speed; }
|
|
733
|
+
var launched = 0;
|
|
734
|
+
events.forEach(function (ev) {
|
|
735
|
+
if (ev.t > from && ev.t <= to) { apply(ev, launched < 4); launched += 1; }
|
|
736
|
+
});
|
|
737
|
+
playhead = to;
|
|
738
|
+
if (launched) { paintNow(); paintCounts(); paintPlan(); }
|
|
739
|
+
paintRiver();
|
|
740
|
+
var shown = shownEvents();
|
|
741
|
+
var last = shown.length ? shown[shown.length - 1].t : 0;
|
|
742
|
+
if (playhead >= last) {
|
|
743
|
+
playing = false;
|
|
744
|
+
if (!replayOnly) goLive(); else paintMode();
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
function play() {
|
|
748
|
+
var shown = shownEvents();
|
|
749
|
+
if (!shown.length) return;
|
|
750
|
+
if (mode === 'live' || playhead === null || playhead >= shown[shown.length - 1].t) {
|
|
751
|
+
var w = windowOf();
|
|
752
|
+
var first = shown.find(function (ev) { return ev.t >= w.from; });
|
|
753
|
+
mode = 'replay';
|
|
754
|
+
playhead = (first ? first.t : w.from) - 400;
|
|
755
|
+
rebuild(playhead);
|
|
756
|
+
}
|
|
757
|
+
playing = !playing;
|
|
758
|
+
paintMode();
|
|
759
|
+
loop();
|
|
760
|
+
}
|
|
761
|
+
function goLive() {
|
|
762
|
+
mode = 'live';
|
|
763
|
+
playing = false;
|
|
764
|
+
playhead = null;
|
|
765
|
+
rebuild(Infinity);
|
|
766
|
+
}
|
|
767
|
+
function step(dir) {
|
|
768
|
+
var list = shownEvents();
|
|
769
|
+
if (!list.length) return;
|
|
770
|
+
var t = mode === 'live' ? Date.now() : playhead;
|
|
771
|
+
var target = null;
|
|
772
|
+
if (dir < 0) { for (var i = list.length - 1; i >= 0; i--) if (list[i].t < t - 1) { target = list[i]; break; } }
|
|
773
|
+
else { for (var j = 0; j < list.length; j++) if (list[j].t > t + 1) { target = list[j]; break; } }
|
|
774
|
+
if (!target) return;
|
|
775
|
+
mode = 'replay';
|
|
776
|
+
playing = false;
|
|
777
|
+
playhead = target.t;
|
|
778
|
+
rebuild(target.t);
|
|
779
|
+
target.hits.forEach(function (h) { pulse(h.node, OPS[target.op].rgb, 1); follow(h.node); });
|
|
780
|
+
}
|
|
781
|
+
$('r-play').addEventListener('click', play);
|
|
782
|
+
$('r-live').addEventListener('click', goLive);
|
|
783
|
+
Array.prototype.forEach.call(document.querySelectorAll('.speed'), function (b) {
|
|
784
|
+
b.addEventListener('click', function () {
|
|
785
|
+
speed = Number(b.getAttribute('data-speed'));
|
|
786
|
+
Array.prototype.forEach.call(document.querySelectorAll('.speed'), function (x) { x.setAttribute('aria-pressed', String(x === b)); });
|
|
787
|
+
});
|
|
788
|
+
});
|
|
789
|
+
Array.prototype.forEach.call(document.querySelectorAll('.span'), function (b) {
|
|
790
|
+
b.addEventListener('click', function () {
|
|
791
|
+
span = b.getAttribute('data-span');
|
|
792
|
+
Array.prototype.forEach.call(document.querySelectorAll('.span'), function (x) { x.setAttribute('aria-pressed', String(x === b)); });
|
|
793
|
+
paintRiver();
|
|
794
|
+
});
|
|
795
|
+
});
|
|
796
|
+
document.addEventListener('keydown', function (e) {
|
|
797
|
+
if (e.target && /^(INPUT|SELECT|TEXTAREA)$/.test(e.target.tagName)) return;
|
|
798
|
+
if (e.target && e.target.tagName === 'BUTTON' && (e.key === ' ' || e.key === 'Enter')) return;
|
|
799
|
+
if (e.key === ' ') { e.preventDefault(); play(); }
|
|
800
|
+
else if (e.key === 'ArrowLeft') { e.preventDefault(); step(-1); }
|
|
801
|
+
else if (e.key === 'ArrowRight') { e.preventDefault(); step(1); }
|
|
802
|
+
else if (e.key === 'f' || e.key === 'F') setFollow(!followOn, followOn ? 'Follow paused.' : 'Following the agent.');
|
|
803
|
+
else if (e.key === 'l' || e.key === 'L') { if (!replayOnly) goLive(); }
|
|
804
|
+
else if (e.key === 'h' || e.key === 'H') $('t-heat').click();
|
|
805
|
+
});
|
|
806
|
+
|
|
807
|
+
// ---- events in
|
|
808
|
+
function take(ev) {
|
|
809
|
+
noteSession(ev);
|
|
810
|
+
events.push(ev);
|
|
811
|
+
if (mode !== 'live') { paintRiver(); return; }
|
|
812
|
+
apply(ev, true);
|
|
813
|
+
paintAll();
|
|
814
|
+
}
|
|
815
|
+
function takeBacklog(list) {
|
|
816
|
+
events = list.slice().sort(function (a, b) { return a.t - b.t; });
|
|
817
|
+
events.forEach(noteSession);
|
|
818
|
+
if (mode === 'live') rebuild(Infinity); else rebuild(playhead);
|
|
819
|
+
}
|
|
820
|
+
if (replayOnly) {
|
|
821
|
+
takeBacklog(model.replay);
|
|
822
|
+
$('mode').textContent = 'Replay';
|
|
823
|
+
if (!events.length) { $('empty-title').textContent = 'Nothing was recorded'; $('empty-hint').textContent = 'This replay file holds no activity. Record some with "activity": true, then write the file again.'; }
|
|
824
|
+
else { mode = 'replay'; playhead = events[events.length - 1].t; rebuild(playhead); }
|
|
825
|
+
} else {
|
|
826
|
+
var source = new EventSource('events?t=' + encodeURIComponent(key()));
|
|
827
|
+
source.addEventListener('status', function (m) {
|
|
828
|
+
var st = JSON.parse(m.data);
|
|
829
|
+
if (!st.activity) {
|
|
830
|
+
$('empty-title').textContent = 'The activity record is off';
|
|
831
|
+
var hint = $('empty-hint');
|
|
832
|
+
clear(hint);
|
|
833
|
+
hint.appendChild(document.createTextNode('Set '));
|
|
834
|
+
hint.appendChild(el('code', '"activity": true'));
|
|
835
|
+
hint.appendChild(document.createTextNode(' in .sdlc/product.json, run '));
|
|
836
|
+
hint.appendChild(el('code', 'yad check --fix'));
|
|
837
|
+
hint.appendChild(document.createTextNode(', then start the agent.'));
|
|
838
|
+
}
|
|
839
|
+
if (st.brain && model.meta.inputs && st.brain !== model.meta.inputs) $('rebuilt').hidden = false;
|
|
840
|
+
});
|
|
841
|
+
source.addEventListener('backlog', function (m) { takeBacklog(JSON.parse(m.data)); });
|
|
842
|
+
source.addEventListener('activity', function (m) { take(JSON.parse(m.data)); });
|
|
843
|
+
source.addEventListener('rebuilt', function () { $('rebuilt').hidden = false; });
|
|
844
|
+
source.addEventListener('error', function () { $('mode').textContent = 'Reconnecting'; });
|
|
845
|
+
source.addEventListener('open', function () { paintMode(); });
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
// ---- the clock ticks the "s ago" and the idle state
|
|
849
|
+
setInterval(function () { paintWhen(); paintMode(); if (mode === 'live') { OP_NAMES.forEach(paintSpark); paintRiver(); } }, 1000);
|
|
850
|
+
window.addEventListener('resize', function () { sizeFx(); paintAll(); drawFx(performance.now()); });
|
|
851
|
+
if (renderer) renderer.on('afterRender', function () { if (!looping) drawFx(performance.now()); });
|
|
852
|
+
sizeFx();
|
|
853
|
+
paintAll();
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
// ---- the stars: drawn once, behind everything
|
|
857
|
+
function stars() {
|
|
858
|
+
var c = document.getElementById('stars');
|
|
859
|
+
var dpr = window.devicePixelRatio || 1;
|
|
860
|
+
c.width = Math.round(window.innerWidth * dpr);
|
|
861
|
+
c.height = Math.round(window.innerHeight * dpr);
|
|
862
|
+
var g = c.getContext('2d');
|
|
863
|
+
g.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
864
|
+
var seed = 7;
|
|
865
|
+
function rnd() { seed = (seed * 16807) % 2147483647; return seed / 2147483647; }
|
|
866
|
+
var count = Math.round((window.innerWidth * window.innerHeight) / 5200);
|
|
867
|
+
for (var i = 0; i < count; i++) {
|
|
868
|
+
var x = rnd() * window.innerWidth;
|
|
869
|
+
var y = rnd() * window.innerHeight;
|
|
870
|
+
var r = rnd() < 0.92 ? rnd() * 0.8 + 0.2 : rnd() * 1.4 + 0.8;
|
|
871
|
+
g.fillStyle = 'rgba(214,224,255,' + (0.15 + rnd() * 0.55) + ')';
|
|
872
|
+
g.beginPath(); g.arc(x, y, r, 0, Math.PI * 2); g.fill();
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
stars();
|
|
876
|
+
window.addEventListener('resize', stars);
|
|
877
|
+
|
|
878
|
+
load().then(start, function (err) {
|
|
879
|
+
$('mode').textContent = 'Not connected';
|
|
880
|
+
$('empty').hidden = false;
|
|
881
|
+
$('empty-title').textContent = 'The brain could not be loaded';
|
|
882
|
+
$('empty-hint').textContent = err && err.message ? err.message : String(err);
|
|
883
|
+
});
|
|
884
|
+
})();
|