crewforth 3.2.0-rc.2 → 3.2.0-rc.3
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 +100 -3
- package/README.md +2 -0
- package/VERSION +1 -1
- package/adopt.sh +10 -1
- package/bin/cli.js +3 -2
- package/kit/CLAUDE.md +3 -3
- package/kit/agents/crew-review-agent.md +2 -0
- package/kit/eval/doctor.sh +13 -2
- package/kit/eval/gate-report.sh +2 -0
- package/kit/eval/lib/crew-map/narrative.mjs +42 -8
- package/kit/eval/lib/crew-map/project.mjs +3 -2
- package/kit/eval/lib/crew-map/rules/tech.json +35 -0
- package/kit/eval/lib/crew-map/scan.mjs +56 -4
- package/kit/eval/lib/crew-map/stacks.mjs +114 -8
- package/kit/eval/lib/crew-map/surface.mjs +62 -1
- package/kit/eval/lib/gate-log.sh +52 -0
- package/kit/eval/lib/json-string.awk +27 -0
- package/kit/eval/lib/preset.sh +109 -0
- package/kit/eval/lib/presets/default.json +7 -0
- package/kit/eval/lib/presets/solo.json +7 -0
- package/kit/eval/lib/presets/strict.json +11 -0
- package/kit/eval/lib/preview.sh +150 -0
- package/kit/eval/lib/review-bench/bench.mjs +273 -0
- package/kit/eval/lib/review-prepass/prepass.mjs +203 -0
- package/kit/eval/lib/review-prepass/prepass.sh +23 -0
- package/kit/eval/lib/settings-json.awk +4 -0
- package/kit/eval/lib/statusline.sh +1 -1
- package/kit/eval/lib/verify-cmd.sh +17 -0
- package/kit/eval/review-bench.sh +26 -0
- package/kit/eval/smoke-test.sh +142 -20
- package/kit/hooks/board-sync.sh +2 -23
- package/kit/hooks/guard-agent-model.sh +32 -23
- package/kit/hooks/guard-bash.sh +36 -21
- package/kit/hooks/guard-write.sh +3 -7
- package/kit/hooks/precompact-snapshot.sh +75 -0
- package/kit/hooks/session-rehydrate.sh +25 -2
- package/kit/settings.json +12 -0
- package/kit/skills/crew-code-review/SKILL.md +16 -0
- package/kit/skills/crew-map/SKILL.md +16 -5
- package/kit/skills/crew-review/SKILL.md +2 -1
- package/kit/studio/README.md +21 -10
- package/kit/studio/server/index.js +74 -22
- package/kit/studio/server/lib/graph.js +9 -1
- package/kit/studio/server/lib/kit-telemetry.js +30 -5
- package/kit/studio/server/lib/lan.js +87 -0
- package/kit/studio/server/lib/redact.js +60 -0
- package/kit/studio/server/lib/remote.js +104 -18
- package/kit/studio/server/lib/session.js +1 -1
- package/kit/studio/server/lib/terminal.js +51 -13
- package/kit/studio/server/lib/transcript.js +32 -0
- package/kit/studio/web/app.js +69 -7
- package/kit/studio/web/canvas.js +14 -2
- package/kit/studio/web/chat.js +32 -7
- package/kit/studio/web/graph-plan.js +3 -2
- package/kit/studio/web/map-plan.js +72 -3
- package/kit/studio/web/map.js +103 -10
- package/kit/studio/web/qr.js +200 -0
- package/kit/studio/web/style.css +34 -0
- package/kit/studio/web/tokens.css +6 -0
- package/package.json +1 -1
- package/start.sh +14 -1
package/kit/studio/web/canvas.js
CHANGED
|
@@ -717,7 +717,10 @@ export class Canvas {
|
|
|
717
717
|
// ran out of the card.
|
|
718
718
|
p.bg = mk('div', 'cv-sub cv-indent cv-bg');
|
|
719
719
|
p.bg.hidden = true;
|
|
720
|
-
|
|
720
|
+
// Agent calls the model gate refused, which started no agent: a line of their own, the gate's words on hover.
|
|
721
|
+
p.refused = mk('div', 'cv-sub cv-indent cv-refused');
|
|
722
|
+
p.refused.hidden = true;
|
|
723
|
+
el.append(row, p.name, p.sub, p.bg, p.refused);
|
|
721
724
|
} else if (it.kind === 'group') {
|
|
722
725
|
el.classList.add('cv-group');
|
|
723
726
|
p.tile = mk('span', 'cv-tile');
|
|
@@ -837,12 +840,21 @@ export class Canvas {
|
|
|
837
840
|
p.name.title = p.name.textContent;
|
|
838
841
|
const bits = [`${n.turns ?? 0} ${n.turns === 1 ? 'turn' : 'turns'}`];
|
|
839
842
|
if (n.tokens != null) bits.push(`${fmtTokens(n.tokens)} ctx`);
|
|
843
|
+
if (n.context?.toolShare != null) bits.push(`${n.context.toolShare}% tool output`);
|
|
840
844
|
p.sub.textContent = bits.join(' · ');
|
|
841
|
-
|
|
845
|
+
// The share is of the text since the last compaction, in characters; the compactions are the transcript's own.
|
|
846
|
+
const lc = n.context?.lastCompact;
|
|
847
|
+
p.sub.title = [p.sub.textContent,
|
|
848
|
+
n.context?.toolShare != null ? `${n.context.toolShare}% of the text in context since the last compaction is tool output (characters, not tokens)` : null,
|
|
849
|
+
n.context?.compactions ? `compacted ${n.context.compactions}×${lc?.before != null ? `, last ${lc.trigger ?? ''} ${fmtTokens(lc.before)} → ${fmtTokens(lc.after)}` : ''}` : null].filter(Boolean).join('\n');
|
|
842
850
|
// What the session has running that is not an agent: commands sent to the background.
|
|
843
851
|
p.bg.hidden = !bg;
|
|
844
852
|
p.bg.textContent = bg ? `${bg} in background` : '';
|
|
845
853
|
p.bg.title = bg ? n.backgroundNow.map((c) => `In the background: ${c.toolName}${c.detail ? ` · ${c.detail}` : ''}`).join('\n') : '';
|
|
854
|
+
const refused = n.refusedCalls ?? [];
|
|
855
|
+
p.refused.hidden = !refused.length;
|
|
856
|
+
p.refused.textContent = refused.length ? `${refused.length} refused by the model gate` : '';
|
|
857
|
+
p.refused.title = refused.map((r) => `${r.agent ?? 'an agent'}${r.model ? ` (${r.model})` : ''}: ${r.text}`).join('\n');
|
|
846
858
|
el.title = 'Click to inspect this session';
|
|
847
859
|
el.setAttribute('aria-label', `Session, ${st?.word ?? 'state not measured'}, ${p.name.textContent}, ${p.sub.textContent}`);
|
|
848
860
|
}
|
package/kit/studio/web/chat.js
CHANGED
|
@@ -208,6 +208,7 @@ class Pane {
|
|
|
208
208
|
this.note(`History not read: ${e.message}`, 'bad');
|
|
209
209
|
return;
|
|
210
210
|
}
|
|
211
|
+
if (conv?.transcriptsHidden) { this.note('Transcripts are hidden on this link', 'muted'); return; }
|
|
211
212
|
if (conv?.measured === false) { this.note(`History not measured — ${conv.reason}`, 'bad'); return; }
|
|
212
213
|
|
|
213
214
|
const frag = document.createDocumentFragment();
|
|
@@ -559,9 +560,12 @@ class Pane {
|
|
|
559
560
|
cont.type = 'button';
|
|
560
561
|
cont.addEventListener('click', () => this.hooks.onContinue?.(this, cont));
|
|
561
562
|
const contRow = el('div', 'chat-ro-row');
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
563
|
+
// Said before the press, from the server's own check (the one Continue here acts on): the same session, or a copy.
|
|
564
|
+
// Until the server answers, and if it cannot: the sentence true of both outcomes.
|
|
565
|
+
const FALLBACK = 'Continues it in Studio. If it is still open somewhere else, Studio starts a copy instead: '
|
|
566
|
+
+ 'the original does not see this, and messages here never reach your terminal.';
|
|
567
|
+
const contText = el('span', 'sub', FALLBACK);
|
|
568
|
+
contRow.append(cont, contText);
|
|
565
569
|
|
|
566
570
|
const term = el('button', 'btn sm', 'Open in terminal');
|
|
567
571
|
term.type = 'button';
|
|
@@ -572,13 +576,34 @@ class Pane {
|
|
|
572
576
|
const termRow = el('div', 'chat-ro-row');
|
|
573
577
|
termRow.append(term, termText);
|
|
574
578
|
|
|
575
|
-
|
|
579
|
+
// Back to the desktop app: the command, to copy and run where the app is.
|
|
580
|
+
const deskLine = el('code', 'chat-ro-cmd');
|
|
581
|
+
const deskCopy = el('button', 'btn sm', 'Copy');
|
|
582
|
+
deskCopy.type = 'button';
|
|
583
|
+
deskCopy.addEventListener('click', () => { if (deskLine.dataset.cmd) navigator.clipboard?.writeText(deskLine.dataset.cmd).then(() => { deskCopy.textContent = 'Copied'; }, () => {}); });
|
|
584
|
+
const deskText = el('span', 'sub');
|
|
585
|
+
deskText.append('Open it in the desktop app again: ', deskLine);
|
|
586
|
+
const deskRow = el('div', 'chat-ro-row');
|
|
587
|
+
deskRow.append(deskCopy, deskText);
|
|
576
588
|
|
|
577
|
-
|
|
589
|
+
this.roEl.replaceChildren(lead, contRow, termRow, deskRow);
|
|
590
|
+
|
|
591
|
+
// The commands are the server's, read before anything runs. One that could not be worked out is said so.
|
|
578
592
|
fetch(this.api(`/api/session/${encodeURIComponent(this.id)}/terminal`), { cache: 'no-store' })
|
|
579
593
|
.then((r) => r.json())
|
|
580
|
-
.then((r) => {
|
|
581
|
-
|
|
594
|
+
.then((r) => {
|
|
595
|
+
line.textContent = r?.plan?.line ?? 'not measured — no working directory or session id recorded';
|
|
596
|
+
// On Windows the command is a PowerShell line (no one line works in cmd and PowerShell 5.1 both): say so.
|
|
597
|
+
deskLine.textContent = r?.desktop?.line ?? 'not measured — no working directory or session id recorded';
|
|
598
|
+
if (r?.desktop?.line) deskLine.dataset.cmd = r.desktop.line; else deskCopy.disabled = true;
|
|
599
|
+
if (r?.desktop?.shell === 'PowerShell') deskText.append(' (in PowerShell)');
|
|
600
|
+
contText.textContent = r?.continueAs === 'same'
|
|
601
|
+
? 'Continues this same session in Studio: its id and history stay, and the desktop app or a terminal that opens it later sees what you add here. Nothing else has it open now.'
|
|
602
|
+
: r?.continueAs === 'copy'
|
|
603
|
+
? 'It is open somewhere else right now, so Studio starts a copy: the original does not see this, and messages here never reach your terminal or the desktop app.'
|
|
604
|
+
: FALLBACK;
|
|
605
|
+
})
|
|
606
|
+
.catch((e) => { line.textContent = `not read — ${e.message}`; deskLine.textContent = `not read — ${e.message}`; deskCopy.disabled = true; });
|
|
582
607
|
}
|
|
583
608
|
|
|
584
609
|
paintState() {
|
|
@@ -276,8 +276,9 @@ export function tallestFor(paneHeight) {
|
|
|
276
276
|
return Math.max(AUTO.tallest, fits);
|
|
277
277
|
}
|
|
278
278
|
|
|
279
|
-
/** A session's card: one line taller
|
|
280
|
-
export const sessionHeight = (n) => SIZE.session.h + (n?.backgroundNow?.length ? SIZE.session.line : 0)
|
|
279
|
+
/** A session's card: one line taller for commands running in the background, one for refused agent calls. */
|
|
280
|
+
export const sessionHeight = (n) => SIZE.session.h + (n?.backgroundNow?.length ? SIZE.session.line : 0)
|
|
281
|
+
+ (n?.refusedCalls?.length ? SIZE.session.line : 0);
|
|
281
282
|
|
|
282
283
|
/* ----------------------------------------------------------------- plan --- */
|
|
283
284
|
|
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
// What the Map view draws, worked out from a crew map. No page in it.
|
|
2
2
|
//
|
|
3
3
|
// The map is Crewforth's (server/lib/crew-map.js reads it). This file puts each node in a band, says which lines
|
|
4
|
-
// a selection lights, orders the findings and words them. It invents no layer: a module
|
|
5
|
-
//
|
|
4
|
+
// a selection lights, orders the findings and words them. It invents no layer: a module's layer is the one /crew-map
|
|
5
|
+
// wrote for it (citing the lines it rests on); without one, its band is what the scan shows of it, and a module whose
|
|
6
|
+
// place the scan does not show goes to "Unplaced". A finding the scanner hides by default stays hidden until asked.
|
|
6
7
|
|
|
8
|
+
// The layers /crew-map may write (eval/lib/crew-map/narrative.mjs LAYERS), set between the bands the scan alone
|
|
9
|
+
// gives, so a map with no layer is drawn in the same order as before.
|
|
10
|
+
export const LAYER_KEYS = ['ui', 'api', 'service', 'data', 'infra', 'tool', 'library'];
|
|
7
11
|
export const BANDS = [
|
|
12
|
+
['ui', 'UI'],
|
|
8
13
|
['clients', 'Clients'],
|
|
14
|
+
['api', 'API'],
|
|
9
15
|
['entry', 'Entry points'],
|
|
16
|
+
['service', 'Service'],
|
|
10
17
|
['core', 'Core'],
|
|
18
|
+
['data', 'Data'],
|
|
11
19
|
['infra', 'Infrastructure'],
|
|
20
|
+
['library', 'Library'],
|
|
21
|
+
['tool', 'Tools'],
|
|
12
22
|
['external', 'External'],
|
|
13
23
|
['unplaced', 'Unplaced'],
|
|
14
24
|
];
|
|
@@ -37,8 +47,10 @@ export function findingModules(f, modules) {
|
|
|
37
47
|
* one that only calls endpoints → Clients
|
|
38
48
|
* one another module of this project references → Core · one with an entry point and nothing above → Entry points
|
|
39
49
|
* anything else → Unplaced, so a guess is never drawn as a fact.
|
|
50
|
+
* A module /crew-map gave a layer goes to that layer's band first.
|
|
40
51
|
*/
|
|
41
52
|
export function bandOf(node, doc) {
|
|
53
|
+
if (node.kind === 'module' && LAYER_KEYS.includes(node.narrative?.layer)) return node.narrative.layer;
|
|
42
54
|
if (node.kind === 'external') return 'external';
|
|
43
55
|
if (node.kind === 'service') return 'infra';
|
|
44
56
|
if (node.kind === 'client') return 'clients';
|
|
@@ -201,6 +213,52 @@ export function cardSub(node, doc) {
|
|
|
201
213
|
return [tech || node.stack, provided ? `${provided} ${provided === 1 ? 'endpoint' : 'endpoints'}` : null].filter(Boolean).join(' · ');
|
|
202
214
|
}
|
|
203
215
|
|
|
216
|
+
/**
|
|
217
|
+
* What a module's card says, as the Map draws it: a kind line (its domain, else its stack, and how many endpoints it
|
|
218
|
+
* provides), up to three of what it is built with, and the outside services it calls, folded into one line under it.
|
|
219
|
+
*/
|
|
220
|
+
export const CARD_CHIPS = 3;
|
|
221
|
+
export function cardOf(node, doc) {
|
|
222
|
+
const provided = (doc.provides?.endpoints ?? []).filter((e) => e.module === node.id).length;
|
|
223
|
+
const kind = [node.narrative?.domain ?? node.stack ?? null, provided ? `${provided} ${provided === 1 ? 'endpoint' : 'endpoints'}` : null].filter(Boolean).join(' · ');
|
|
224
|
+
const tech = (node.tech ?? []).map((t) => t.replace(/@.*$/, ''));
|
|
225
|
+
return { kind, chips: tech.slice(0, CARD_CHIPS), more: Math.max(0, tech.length - CARD_CHIPS), outside: outsideOf(node, doc) };
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** The outside services a module calls, by name, in the order they are named: what its card folds under it. */
|
|
229
|
+
export function outsideOf(node, doc) {
|
|
230
|
+
const byId = new Map((doc.nodes ?? []).map((n) => [n.id, n]));
|
|
231
|
+
const names = [];
|
|
232
|
+
for (const e of doc.edges ?? []) {
|
|
233
|
+
if (e.from !== node.id) continue;
|
|
234
|
+
const to = byId.get(e.to);
|
|
235
|
+
if (to?.kind !== 'external') continue;
|
|
236
|
+
const name = to.label && to.label !== 'unknown' ? to.label : (to.hosts ?? [])[0] ?? to.id.replace(/^ext:[^:]+:/, '');
|
|
237
|
+
if (!names.includes(name)) names.push(name);
|
|
238
|
+
}
|
|
239
|
+
return names.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** The tour /crew-map wrote, the stops whose node is on this map, each with the node's name. */
|
|
243
|
+
export function tourOf(doc) {
|
|
244
|
+
const byId = new Map((doc.nodes ?? []).map((n) => [n.id, n]));
|
|
245
|
+
return (Array.isArray(doc.tour) ? doc.tour : []).filter((s) => s && byId.has(s.node) && typeof s.text === 'string')
|
|
246
|
+
.map((s) => ({ node: s.node, name: byId.get(s.node).name ?? byId.get(s.node).label ?? s.node, text: s.text, cites: (s.cites ?? []).filter((c) => typeof c === 'string') }));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* The nodes a search names: by name, folder, what they are built with, their domain, the folders inside them and
|
|
251
|
+
* what their README says. Case does not matter; an empty search names none.
|
|
252
|
+
*/
|
|
253
|
+
export function searchOf(query, nodes) {
|
|
254
|
+
const q = String(query ?? '').trim().toLowerCase();
|
|
255
|
+
if (!q) return new Set();
|
|
256
|
+
const hay = (n) => [n.name, n.label, n.path, n.stack, ...(n.tech ?? []), ...(n.hosts ?? []), n.narrative?.domain, n.narrative?.layer,
|
|
257
|
+
...(n.structure?.folders ?? []).map((f) => f.folder), ...(n.about?.evidence ?? []).map((e) => e.text)]
|
|
258
|
+
.filter((x) => typeof x === 'string').join('\n').toLowerCase();
|
|
259
|
+
return new Set(nodes.filter((n) => hay(n).includes(q)).map((n) => n.id));
|
|
260
|
+
}
|
|
261
|
+
|
|
204
262
|
/** The summary pills: what the map holds, and how many findings the list shows. */
|
|
205
263
|
export function summaryOf(doc, findings) {
|
|
206
264
|
const n = (k) => (doc.nodes ?? []).filter((x) => x.kind === k).length;
|
|
@@ -247,6 +305,16 @@ export function inspectOf(node, doc, edges, findings) {
|
|
|
247
305
|
narrative: typeof node.narrative?.text === 'string' ? node.narrative.text : null,
|
|
248
306
|
narrativeCites: Array.isArray(node.narrative?.cites) ? node.narrative.cites.filter((c) => typeof c === 'string') : [],
|
|
249
307
|
narrativeNote: 'Not written yet: this map holds no description of the module, only what its files show.',
|
|
308
|
+
// /crew-map's layer and domain, when it wrote them; the band is the layer's (bandOf).
|
|
309
|
+
layer: LAYER_KEYS.includes(node.narrative?.layer) ? (BANDS.find(([k]) => k === node.narrative.layer)?.[1] ?? null) : null,
|
|
310
|
+
domain: typeof node.narrative?.domain === 'string' ? node.narrative.domain : null,
|
|
311
|
+
// What is inside it: the entry point the scan found, its folders with how many source files each holds, tests apart.
|
|
312
|
+
inside: node.kind === 'module' ? {
|
|
313
|
+
entry: node.entryPoint?.evidence?.[0] ? `${node.entryPoint.evidence[0].file}:${node.entryPoint.evidence[0].line}` : (node.entryPoint?.file ?? null),
|
|
314
|
+
folders: (node.structure?.folders ?? []).map((f) => ({ folder: f.folder, files: f.files })),
|
|
315
|
+
other: node.structure?.otherFiles ?? 0,
|
|
316
|
+
tests: node.structure?.testFiles ?? 0,
|
|
317
|
+
} : null,
|
|
250
318
|
connectsTo: out,
|
|
251
319
|
connections: { out, in: into },
|
|
252
320
|
byKind: Object.entries(byKind).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)),
|
|
@@ -274,7 +342,8 @@ export function emptyNote(data) {
|
|
|
274
342
|
return null;
|
|
275
343
|
}
|
|
276
344
|
|
|
277
|
-
|
|
345
|
+
// A module card holds its name and kind, a row of what it is built with, and the line of outside services under it.
|
|
346
|
+
export const CARD = { module: [280, 104], service: [280, 104], client: [280, 104], group: [280, 104], external: [104, 52] };
|
|
278
347
|
const GAP_X = 24;
|
|
279
348
|
const GAP_Y = 20;
|
|
280
349
|
const LEFT = 140; // the band's label sits in this column
|
package/kit/studio/web/map.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
// The Map view: the project as Crewforth's crew map shows it.
|
|
2
2
|
//
|
|
3
|
-
// Bands from the
|
|
4
|
-
//
|
|
3
|
+
// Bands from the layers /crew-map wrote (UI, API, Service, Data, Infrastructure, …), or from what the scan shows
|
|
4
|
+
// where it wrote none, on a pane that pans and zooms like the graph's (the shared viewport.js). A module's card
|
|
5
|
+
// carries what it is built with and folds the outside services it calls into one line under it; a search dims the
|
|
6
|
+
// cards it does not name, and the tour /crew-map wrote steps through the map one stop at a time. Lines are solid where a file proves them, dotted where they are inferred, dashed with their
|
|
5
7
|
// own mark where the model proposed them. A card can be placed by hand and stays placed for that project; modules
|
|
6
8
|
// that share a folder can be folded into one card. Under the pane, the findings; beside it, the inspector. On a
|
|
7
9
|
// phone the pane gives way to the findings and a list of the modules. It reads the map the server sends and writes
|
|
8
10
|
// nothing; what leaves the page is copied text: a finding as a task, or a file:line.
|
|
9
11
|
import {
|
|
10
12
|
nodesOf, edgesOf, edgeKey, litEdges, findingsOf, findingCounts, cardSub, summaryOf, sourceOf, inspectOf, taskOf,
|
|
11
|
-
emptyNote, layoutOf, pathOf, chipsOf,
|
|
13
|
+
emptyNote, layoutOf, pathOf, chipsOf, inferredOnly, groupsOf, foldView, placed, BANDS, cardOf, tourOf, searchOf, resourceWord,
|
|
12
14
|
} from './map-plan.js';
|
|
13
15
|
import { Viewport, draggable, swallowClick } from './viewport.js';
|
|
14
16
|
|
|
@@ -30,6 +32,8 @@ const BAND_ORDER = Object.fromEntries(BANDS.map(([k], i) => [k, i]));
|
|
|
30
32
|
const BAND_WORD = Object.fromEntries(BANDS);
|
|
31
33
|
|
|
32
34
|
const LAYERS = [['modules', 'Modules'], ['external', 'External'], ['endpoints', 'Endpoints'], ['findings', 'Findings']];
|
|
35
|
+
// How a line between two modules is named on the map.
|
|
36
|
+
const EDGE_WORD = { references: 'uses', calls: 'calls', builds: 'builds' };
|
|
33
37
|
|
|
34
38
|
export class MapView {
|
|
35
39
|
/**
|
|
@@ -51,6 +55,8 @@ export class MapView {
|
|
|
51
55
|
this.groupOf = {};
|
|
52
56
|
this.lay = null;
|
|
53
57
|
this.fitted = false;
|
|
58
|
+
this.query = '';
|
|
59
|
+
this.tourAt = -1; // the stop shown, or -1 when the tour is off
|
|
54
60
|
this.root.classList.add('mp');
|
|
55
61
|
this.#build();
|
|
56
62
|
}
|
|
@@ -61,8 +67,11 @@ export class MapView {
|
|
|
61
67
|
this.pane = mk('div', 'mp-canvas-pane');
|
|
62
68
|
this.layer = mk('div', 'mp-canvas');
|
|
63
69
|
this.pane.append(this.layer);
|
|
70
|
+
this.tourBox = mk('div', 'mp-tour');
|
|
71
|
+
this.tourBox.hidden = true;
|
|
72
|
+
this.pane.append(this.tourBox);
|
|
64
73
|
this.vp = new Viewport(this.pane, this.layer, {
|
|
65
|
-
skip: (t) => Boolean(t.closest?.('.mp-card') || t.closest?.('.mp-group-fold')),
|
|
74
|
+
skip: (t) => Boolean(t.closest?.('.mp-card') || t.closest?.('.mp-group-fold') || t.closest?.('.mp-tour')),
|
|
66
75
|
onApply: () => this.hooks.onZoom?.(this.vp.view.k),
|
|
67
76
|
});
|
|
68
77
|
this.below = mk('div', 'mp-below');
|
|
@@ -90,7 +99,7 @@ export class MapView {
|
|
|
90
99
|
|
|
91
100
|
setData(data) {
|
|
92
101
|
if (data?.cwd !== this.data?.cwd) {
|
|
93
|
-
this.selected = null; this.tab = 'overview'; this.fitted = false; this.layWidth = null;
|
|
102
|
+
this.selected = null; this.tab = 'overview'; this.fitted = false; this.layWidth = null; this.query = ''; this.tourAt = -1;
|
|
94
103
|
this.#restore(data?.cwd);
|
|
95
104
|
}
|
|
96
105
|
this.data = data;
|
|
@@ -109,6 +118,7 @@ export class MapView {
|
|
|
109
118
|
/** Esc closes the legend first, then lets the selection go. Returns whether it had something to close. */
|
|
110
119
|
escape() {
|
|
111
120
|
if (this.legendOpen) { this.legendOpen = false; this.render(); return true; }
|
|
121
|
+
if (this.tourAt >= 0) { this.tourAt = -1; this.render(); return true; }
|
|
112
122
|
if (!this.selected) return false;
|
|
113
123
|
this.selected = null; this.render(); return true;
|
|
114
124
|
}
|
|
@@ -133,6 +143,14 @@ export class MapView {
|
|
|
133
143
|
return true;
|
|
134
144
|
}
|
|
135
145
|
|
|
146
|
+
/** Step the tour to a stop (clamped), selecting its node and bringing it to the middle; -1 ends it. */
|
|
147
|
+
tour(at) {
|
|
148
|
+
const stops = this.data?.doc ? tourOf(this.data.doc) : [];
|
|
149
|
+
if (at < 0 || !stops.length) { this.tourAt = -1; this.render(); return; }
|
|
150
|
+
this.tourAt = Math.min(at, stops.length - 1);
|
|
151
|
+
this.select(stops[this.tourAt].node, { reveal: true });
|
|
152
|
+
}
|
|
153
|
+
|
|
136
154
|
toggleGroup(id) {
|
|
137
155
|
if (this.folded.has(id)) this.folded.delete(id); else this.folded.add(id);
|
|
138
156
|
this.#persist();
|
|
@@ -155,7 +173,8 @@ export class MapView {
|
|
|
155
173
|
const counts = this.layers.findings ? findingCounts(findings.shown) : {};
|
|
156
174
|
const allEdges = edgesOf(doc, d.compare);
|
|
157
175
|
const all = nodesOf(doc, d.compare);
|
|
158
|
-
|
|
176
|
+
// An outside service is not a card: it is named on the line under the cards of the modules that call it.
|
|
177
|
+
let nodes = all.filter((n) => n.kind !== 'external' && this.layers.modules);
|
|
159
178
|
const groups = groupsOf(nodes);
|
|
160
179
|
this.groupOf = {};
|
|
161
180
|
for (const g of Object.values(groups)) for (const m of g.members) if (this.folded.has(g.id)) this.groupOf[m] = g.id;
|
|
@@ -179,6 +198,7 @@ export class MapView {
|
|
|
179
198
|
const lay = this.lay;
|
|
180
199
|
const shownSel = this.selected ? (lay.pos[this.selected] ? this.selected : this.groupOf[this.selected] ?? null) : null;
|
|
181
200
|
const lit = litEdges(edges, shownSel);
|
|
201
|
+
const found = searchOf(this.query, nodes);
|
|
182
202
|
|
|
183
203
|
this.top.replaceChildren(this.#head(doc, findings), this.#toolbar(d), this.#source(d));
|
|
184
204
|
|
|
@@ -220,6 +240,7 @@ export class MapView {
|
|
|
220
240
|
if (shownSel) path.dataset.lit = String(lit.has(edgeKey(e)));
|
|
221
241
|
lines.append(path);
|
|
222
242
|
const tags = [];
|
|
243
|
+
if (EDGE_WORD[e.kind] && !e.calls) tags.push(mk('span', 'mp-badge', EDGE_WORD[e.kind]));
|
|
223
244
|
if (e.line === 'model') { const m = mk('span', 'mp-pill', 'model'); m.dataset.tone = 'model'; m.title = 'Proposed by the model, not shown by a file'; tags.push(m); }
|
|
224
245
|
if (e.calls) {
|
|
225
246
|
tags.push(mk('span', 'mp-pill', `${e.calls} ${e.calls === 1 ? 'call' : 'calls'}`));
|
|
@@ -233,10 +254,15 @@ export class MapView {
|
|
|
233
254
|
}
|
|
234
255
|
}
|
|
235
256
|
parts.push(lines, ...labels);
|
|
236
|
-
for (const n of nodes)
|
|
257
|
+
for (const n of nodes) {
|
|
258
|
+
const card = this.#card(n, doc, lay.pos[n.id], counts[n.id] ?? 0, chips[n.id], edges, shownSel);
|
|
259
|
+
if (this.query.trim()) card.dataset.match = String(found.has(n.id));
|
|
260
|
+
parts.push(card);
|
|
261
|
+
}
|
|
237
262
|
this.layer.replaceChildren(...parts);
|
|
238
263
|
if (!this.fitted) { this.fitted = true; this.fit(); } else this.vp.apply();
|
|
239
264
|
|
|
265
|
+
this.#tourBox(doc);
|
|
240
266
|
this.below.replaceChildren(...(this.layers.findings ? [this.#findings(findings)] : []));
|
|
241
267
|
this.#modList(all, counts);
|
|
242
268
|
const picked = this.selected ? all.find((n) => n.id === this.selected) ?? null : null;
|
|
@@ -261,6 +287,26 @@ export class MapView {
|
|
|
261
287
|
bar.append(b);
|
|
262
288
|
}
|
|
263
289
|
bar.append(mk('span', 'row-fill'));
|
|
290
|
+
const search = mk('input', 'mp-search');
|
|
291
|
+
search.type = 'search';
|
|
292
|
+
search.placeholder = 'Search files and modules';
|
|
293
|
+
search.setAttribute('aria-label', 'Search files and modules');
|
|
294
|
+
search.value = this.query;
|
|
295
|
+
search.addEventListener('input', () => { this.query = search.value; this.render(); this.top.querySelector('.mp-search')?.focus(); });
|
|
296
|
+
search.addEventListener('keydown', (e) => {
|
|
297
|
+
if (e.key !== 'Enter') return;
|
|
298
|
+
const first = [...searchOf(this.query, nodesOf(d.doc, d.compare))][0];
|
|
299
|
+
if (first) this.select(first, { reveal: true });
|
|
300
|
+
});
|
|
301
|
+
bar.append(search);
|
|
302
|
+
if (tourOf(d.doc).length) {
|
|
303
|
+
const t = mk('button', 'mp-tog', 'Tour');
|
|
304
|
+
t.type = 'button';
|
|
305
|
+
t.setAttribute('aria-pressed', String(this.tourAt >= 0));
|
|
306
|
+
t.title = 'The stops /crew-map wrote for someone new to the project, in order';
|
|
307
|
+
t.addEventListener('click', () => this.tour(this.tourAt >= 0 ? -1 : 0));
|
|
308
|
+
bar.append(t);
|
|
309
|
+
}
|
|
264
310
|
const pick = mk('select', 'mp-compare');
|
|
265
311
|
pick.setAttribute('aria-label', 'Compare with');
|
|
266
312
|
const none = mk('option', null, d.others?.length ? 'Compare with…' : 'Compare with: no other project has a map');
|
|
@@ -322,10 +368,29 @@ export class MapView {
|
|
|
322
368
|
if (!card.title) card.title = (n.hosts ?? []).join(', ');
|
|
323
369
|
} else {
|
|
324
370
|
const top = mk('span', 'mp-row');
|
|
325
|
-
|
|
371
|
+
const name = mk('span', 'mp-name', n.name ?? n.id);
|
|
372
|
+
name.title = n.name ?? n.id;
|
|
373
|
+
top.append(name);
|
|
326
374
|
if (count) { const f = mk('span', 'mp-fb', String(count)); f.title = `${count} ${count === 1 ? 'finding' : 'findings'}`; top.append(f); }
|
|
327
|
-
|
|
328
|
-
card.append(top, mk('span', 'sub',
|
|
375
|
+
top.append(mk('span', 'row-fill'));
|
|
376
|
+
if (n.kind === 'group') { card.append(top, mk('span', 'sub', `${n.members.length} modules · click to open`)); }
|
|
377
|
+
else if (n.kind !== 'module') { card.append(top, mk('span', 'sub', cardSub(n, doc))); }
|
|
378
|
+
else {
|
|
379
|
+
const c = cardOf(n, doc);
|
|
380
|
+
if (c.kind) top.append(mk('span', 'mp-kind', c.kind));
|
|
381
|
+
card.append(top);
|
|
382
|
+
if (c.chips.length) {
|
|
383
|
+
const row = mk('span', 'mp-chips');
|
|
384
|
+
for (const t of c.chips) row.append(mk('span', 'mp-chip', t));
|
|
385
|
+
if (c.more) { const m = mk('span', 'mp-chip', `+${c.more}`); m.title = (n.tech ?? []).slice(3).map((t) => t.replace(/@.*$/, '')).join(', '); row.append(m); }
|
|
386
|
+
card.append(row);
|
|
387
|
+
}
|
|
388
|
+
if (this.layers.external) {
|
|
389
|
+
const fold = mk('span', `mp-fold${c.outside.length ? '' : ' none'}`, c.outside.length ? `▸ ${c.outside.join(' · ')}` : 'no outside calls');
|
|
390
|
+
if (c.outside.length) fold.title = c.outside.join('\n');
|
|
391
|
+
card.append(fold);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
329
394
|
if (chips?.length) { const c = mk('span', 'mp-chips'); for (const t of chips) c.append(mk('span', 'mp-chip', t)); card.append(c); }
|
|
330
395
|
}
|
|
331
396
|
draggable(card, {
|
|
@@ -402,6 +467,12 @@ export class MapView {
|
|
|
402
467
|
close.addEventListener('click', () => this.select(null));
|
|
403
468
|
top.append(mk('span', 'mp-name', v.title), mk('span', 'row-fill'), close);
|
|
404
469
|
parts.push(top);
|
|
470
|
+
if (v.layer || v.domain) {
|
|
471
|
+
const pills = mk('div', 'mp-row');
|
|
472
|
+
if (v.layer) pills.append(mk('span', 'mp-pill', `Layer · ${v.layer}`));
|
|
473
|
+
if (v.domain) pills.append(mk('span', 'mp-pill', `Domain · ${v.domain}`));
|
|
474
|
+
parts.push(pills);
|
|
475
|
+
}
|
|
405
476
|
if (v.path) parts.push(mk('code', 'sub', v.path));
|
|
406
477
|
if (v.chips.length) { const c = mk('div', 'mp-chips'); for (const t of v.chips) c.append(mk('span', 'mp-chip', t)); parts.push(c); }
|
|
407
478
|
const tabs = mk('nav', 'mp-tabs');
|
|
@@ -417,6 +488,13 @@ export class MapView {
|
|
|
417
488
|
if (this.tab === 'overview') {
|
|
418
489
|
sec.append(mk('span', 'lbl', 'What it is for'), mk('p', v.narrative ? null : 'sub', v.narrative ?? v.narrativeNote));
|
|
419
490
|
if (v.narrative && v.narrativeCites.length) sec.append(mk('p', 'sub mp-cites', `From ${v.narrativeCites.join(', ')}`));
|
|
491
|
+
if (v.inside && (v.inside.entry || v.inside.folders.length)) {
|
|
492
|
+
sec.append(mk('span', 'lbl', 'Inside'));
|
|
493
|
+
if (v.inside.entry) { const r = mk('div', 'mp-conn mp-inside'); r.append(this.#cite(v.inside.entry), mk('span', 'mp-ev', 'entry point')); sec.append(r); }
|
|
494
|
+
for (const f of v.inside.folders) { const r = mk('div', 'mp-conn mp-inside'); r.append(mk('span', 'mp-file', `${f.folder === '.' ? '(root)' : `${f.folder}/`}`), mk('span', 'mp-ev', `${f.files} ${f.files === 1 ? 'file' : 'files'}`)); sec.append(r); }
|
|
495
|
+
if (v.inside.other) sec.append(mk('p', 'sub', `${v.inside.other} more files in other folders`));
|
|
496
|
+
if (v.inside.tests) sec.append(mk('p', 'sub', `${v.inside.tests} test ${v.inside.tests === 1 ? 'file' : 'files'}`));
|
|
497
|
+
}
|
|
420
498
|
sec.append(mk('span', 'lbl', 'Connects to'));
|
|
421
499
|
if (!v.connectsTo.length) sec.append(mk('p', 'sub', 'Nothing on this map.'));
|
|
422
500
|
for (const c of v.connectsTo) sec.append(this.#conn(c));
|
|
@@ -459,6 +537,21 @@ export class MapView {
|
|
|
459
537
|
this.side.replaceChildren(...parts);
|
|
460
538
|
}
|
|
461
539
|
|
|
540
|
+
/** The tour's stop, over the bottom of the pane: which of how many, what to look at, and the way on. */
|
|
541
|
+
#tourBox(doc) {
|
|
542
|
+
const stops = tourOf(doc);
|
|
543
|
+
if (this.tourAt < 0 || !stops.length) { this.tourBox.hidden = true; return; }
|
|
544
|
+
const s = stops[Math.min(this.tourAt, stops.length - 1)];
|
|
545
|
+
const head = mk('div', 'mp-row');
|
|
546
|
+
head.append(mk('span', 'lbl', `Tour · ${this.tourAt + 1} of ${stops.length}`), mk('span', 'mp-name', s.name), mk('span', 'row-fill'));
|
|
547
|
+
const nav = (label, at, off) => { const b = mk('button', 'btn sm ghost', label); b.type = 'button'; b.disabled = off; b.addEventListener('click', () => this.tour(at)); return b; };
|
|
548
|
+
head.append(nav('Back', this.tourAt - 1, this.tourAt === 0), nav(this.tourAt === stops.length - 1 ? 'Done' : 'Next', this.tourAt === stops.length - 1 ? -1 : this.tourAt + 1, false));
|
|
549
|
+
const body = [head, mk('p', null, s.text)];
|
|
550
|
+
if (s.cites.length) body.push(mk('p', 'sub mp-cites', `From ${s.cites.join(', ')}`));
|
|
551
|
+
this.tourBox.replaceChildren(...body);
|
|
552
|
+
this.tourBox.hidden = false;
|
|
553
|
+
}
|
|
554
|
+
|
|
462
555
|
/** A file:line the viewer can copy. */
|
|
463
556
|
#cite(text) {
|
|
464
557
|
const b = mk('button', 'mp-ev mp-cite', text);
|