yadflow 4.10.0 → 4.12.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 +152 -0
- package/README.md +14 -3
- package/bin/commands.mjs +7 -1
- package/bin/yad.mjs +163 -16
- package/cli/agent-guard-worker.mjs +13 -0
- package/cli/agent-guard.mjs +1053 -57
- package/cli/agent-rules.mjs +59 -3
- 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 +345 -0
- package/cli/brain.mjs +810 -0
- package/cli/brand-cmd.mjs +326 -0
- package/cli/brand.mjs +327 -0
- package/cli/ci-check.mjs +3 -3
- package/cli/doctor.mjs +145 -14
- package/cli/epic-state.mjs +93 -1
- package/cli/epic.mjs +15 -3
- package/cli/errors.mjs +2 -1
- package/cli/find-product.mjs +69 -15
- 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 +26 -3
- package/cli/hook.mjs +59 -9
- package/cli/issues-act.mjs +57 -13
- package/cli/issues-write.mjs +19 -6
- package/cli/issues.mjs +69 -24
- package/cli/lib.mjs +37 -2
- package/cli/local-page.mjs +138 -0
- package/cli/local-setup-record.mjs +71 -0
- package/cli/local-setup-steps.mjs +186 -0
- package/cli/local-setup.mjs +611 -0
- package/cli/machine.mjs +1 -1
- package/cli/manifest.mjs +55 -0
- 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 +190 -0
- package/cli/map.mjs +637 -0
- package/cli/members.mjs +9 -15
- package/cli/next.mjs +1 -1
- package/cli/openpr.mjs +2 -2
- package/cli/plain-text.mjs +22 -0
- package/cli/plan.mjs +310 -36
- package/cli/platform.mjs +5 -5
- package/cli/product-index.mjs +1 -1
- package/cli/protection.mjs +32 -0
- package/cli/reconcile.mjs +61 -13
- package/cli/report.mjs +9 -3
- package/cli/reports-dir.mjs +393 -0
- package/cli/reports.mjs +65 -0
- package/cli/run-checks.mjs +5 -2
- package/cli/scan.mjs +4 -6
- package/cli/secret-text.mjs +66 -0
- package/cli/setup.mjs +54 -8
- package/cli/standup.mjs +94 -72
- package/cli/status.mjs +6 -5
- package/cli/test-agents-file.mjs +614 -8
- 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-brand.mjs +558 -0
- package/cli/test-guide.mjs +438 -0
- package/cli/test-local-setup.mjs +1188 -0
- package/cli/test-machine.mjs +59 -0
- package/cli/test-map.mjs +615 -0
- package/cli/test-reports.mjs +382 -0
- package/cli/test-run-checks.mjs +4 -0
- package/cli/test-worktree.mjs +24 -3
- package/cli/toolbox-connect.mjs +21 -6
- package/cli/toolbox.mjs +74 -5
- package/cli/update-commit.mjs +118 -9
- package/cli/usage.mjs +17 -7
- package/cli/workspace.mjs +11 -2
- package/package.json +8 -4
- package/skills/sdlc/module-help.csv +1 -0
- package/skills/yad-architecture/SKILL.md +22 -4
- package/skills/yad-brand/SKILL.md +69 -0
- package/skills/yad-change/SKILL.md +3 -1
- package/skills/yad-change/references/triage.md +2 -0
- package/skills/yad-checks/SKILL.md +2 -0
- package/skills/yad-checks/references/check-gates.md +8 -5
- 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/package-manager.sh +42 -0
- package/skills/yad-checks/templates/github/yad-checks.yml +3 -2
- package/skills/yad-checks/templates/gitlab/yad-checks.gitlab-ci.yml +3 -2
- package/skills/yad-checks/templates/hooks/local-setup-notice.mjs +96 -0
- package/skills/yad-checks/templates/hooks/yad-activity.mjs +238 -0
- package/skills/yad-connect-repos/SKILL.md +14 -0
- 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 +3 -0
- package/skills/yad-epic/references/state-schema.md +35 -1
- package/skills/yad-guide/SKILL.md +10 -7
- package/skills/yad-implement/SKILL.md +76 -15
- package/skills/yad-issues/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 +8 -4
- package/skills/yad-spec/SKILL.md +19 -0
- package/skills/yad-stories/SKILL.md +22 -4
- package/skills/yad-stories/references/story-schema.md +1 -1
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--bg: #f8fafc;
|
|
3
|
+
--panel: #ffffff;
|
|
4
|
+
--text: #0f172a;
|
|
5
|
+
--muted: #64748b;
|
|
6
|
+
--line: #e2e8f0;
|
|
7
|
+
--accent: #2563eb;
|
|
8
|
+
--warn-bg: #fef3c7;
|
|
9
|
+
--warn-text: #78350f;
|
|
10
|
+
--chip: #f1f5f9;
|
|
11
|
+
color-scheme: light;
|
|
12
|
+
}
|
|
13
|
+
@media (prefers-color-scheme: dark) {
|
|
14
|
+
:root {
|
|
15
|
+
--bg: #0b1120;
|
|
16
|
+
--panel: #111827;
|
|
17
|
+
--text: #e5e7eb;
|
|
18
|
+
--muted: #94a3b8;
|
|
19
|
+
--line: #1f2937;
|
|
20
|
+
--accent: #60a5fa;
|
|
21
|
+
--warn-bg: #422006;
|
|
22
|
+
--warn-text: #fde68a;
|
|
23
|
+
--chip: #1f2937;
|
|
24
|
+
color-scheme: dark;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
* { box-sizing: border-box; }
|
|
28
|
+
html, body { height: 100%; margin: 0; }
|
|
29
|
+
body {
|
|
30
|
+
background: var(--bg);
|
|
31
|
+
color: var(--text);
|
|
32
|
+
font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
|
33
|
+
display: flex;
|
|
34
|
+
flex-direction: column;
|
|
35
|
+
}
|
|
36
|
+
h1 { font-size: 17px; margin: 0; }
|
|
37
|
+
h2 { margin: 0; }
|
|
38
|
+
.muted { color: var(--muted); margin: 0; }
|
|
39
|
+
.small { font-size: 12px; }
|
|
40
|
+
.top {
|
|
41
|
+
display: flex;
|
|
42
|
+
flex-wrap: wrap;
|
|
43
|
+
gap: 8px 24px;
|
|
44
|
+
align-items: center;
|
|
45
|
+
padding: 10px 16px;
|
|
46
|
+
border-bottom: 1px solid var(--line);
|
|
47
|
+
background: var(--panel);
|
|
48
|
+
}
|
|
49
|
+
.banner { margin: 0; padding: 6px 10px; border-radius: 6px; font-size: 13px; }
|
|
50
|
+
.warn { background: var(--warn-bg); color: var(--warn-text); }
|
|
51
|
+
.layout {
|
|
52
|
+
flex: 1;
|
|
53
|
+
min-height: 0;
|
|
54
|
+
display: grid;
|
|
55
|
+
grid-template-columns: 260px 1fr 320px;
|
|
56
|
+
}
|
|
57
|
+
.controls, .details {
|
|
58
|
+
background: var(--panel);
|
|
59
|
+
overflow-y: auto;
|
|
60
|
+
padding: 12px 16px;
|
|
61
|
+
}
|
|
62
|
+
.controls { border-right: 1px solid var(--line); }
|
|
63
|
+
.details { border-left: 1px solid var(--line); }
|
|
64
|
+
.controls section { margin-bottom: 18px; }
|
|
65
|
+
.label {
|
|
66
|
+
display: block;
|
|
67
|
+
font-size: 11px;
|
|
68
|
+
font-weight: 600;
|
|
69
|
+
letter-spacing: .04em;
|
|
70
|
+
text-transform: uppercase;
|
|
71
|
+
color: var(--muted);
|
|
72
|
+
margin: 10px 0 4px;
|
|
73
|
+
}
|
|
74
|
+
input[type="search"], select {
|
|
75
|
+
width: 100%;
|
|
76
|
+
padding: 6px 8px;
|
|
77
|
+
border: 1px solid var(--line);
|
|
78
|
+
border-radius: 6px;
|
|
79
|
+
background: var(--bg);
|
|
80
|
+
color: var(--text);
|
|
81
|
+
font: inherit;
|
|
82
|
+
}
|
|
83
|
+
.check { display: flex; gap: 8px; align-items: flex-start; margin: 4px 0; }
|
|
84
|
+
.button {
|
|
85
|
+
margin-top: 10px;
|
|
86
|
+
padding: 6px 10px;
|
|
87
|
+
border: 1px solid var(--line);
|
|
88
|
+
border-radius: 6px;
|
|
89
|
+
background: var(--chip);
|
|
90
|
+
color: var(--text);
|
|
91
|
+
font: inherit;
|
|
92
|
+
cursor: pointer;
|
|
93
|
+
}
|
|
94
|
+
.button:hover { border-color: var(--accent); }
|
|
95
|
+
.results, .legend, .links { list-style: none; margin: 6px 0 0; padding: 0; }
|
|
96
|
+
.results li button, .links li button {
|
|
97
|
+
all: unset;
|
|
98
|
+
display: block;
|
|
99
|
+
width: 100%;
|
|
100
|
+
padding: 4px 6px;
|
|
101
|
+
border-radius: 4px;
|
|
102
|
+
cursor: pointer;
|
|
103
|
+
overflow-wrap: anywhere;
|
|
104
|
+
}
|
|
105
|
+
.results li button:hover, .links li button:hover,
|
|
106
|
+
.results li button:focus-visible, .links li button:focus-visible { background: var(--chip); outline: 1px solid var(--accent); }
|
|
107
|
+
.legend li { display: flex; gap: 8px; align-items: center; margin: 3px 0; }
|
|
108
|
+
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
|
|
109
|
+
.stage { position: relative; min-width: 0; }
|
|
110
|
+
.graph { position: absolute; inset: 0; }
|
|
111
|
+
.notice {
|
|
112
|
+
position: absolute;
|
|
113
|
+
top: 16px;
|
|
114
|
+
left: 50%;
|
|
115
|
+
transform: translateX(-50%);
|
|
116
|
+
max-width: min(520px, 90%);
|
|
117
|
+
padding: 10px 14px;
|
|
118
|
+
border-radius: 8px;
|
|
119
|
+
background: var(--panel);
|
|
120
|
+
border: 1px solid var(--line);
|
|
121
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, .12);
|
|
122
|
+
}
|
|
123
|
+
.chip {
|
|
124
|
+
display: inline-block;
|
|
125
|
+
padding: 1px 8px;
|
|
126
|
+
border-radius: 999px;
|
|
127
|
+
background: var(--chip);
|
|
128
|
+
font-size: 12px;
|
|
129
|
+
}
|
|
130
|
+
.details h2 { font-size: 16px; overflow-wrap: anywhere; margin: 4px 0 6px; }
|
|
131
|
+
.details dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 10px 0; }
|
|
132
|
+
.details dt { color: var(--muted); }
|
|
133
|
+
.details dd { margin: 0; overflow-wrap: anywhere; }
|
|
134
|
+
.details h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 14px 0 4px; }
|
|
135
|
+
.rel { color: var(--muted); font-size: 12px; }
|
|
136
|
+
.inferred { font-style: italic; }
|
|
137
|
+
@media (max-width: 900px) {
|
|
138
|
+
.layout { grid-template-columns: 1fr; grid-template-rows: auto 60vh auto; }
|
|
139
|
+
.controls { border-right: 0; border-bottom: 1px solid var(--line); }
|
|
140
|
+
.details { border-left: 0; border-top: 1px solid var(--line); }
|
|
141
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
// E179 — two focused questions over the project brain (E176), for an agent planning or editing:
|
|
2
|
+
// fileAbout(brain, target) — one file: who declares it, what it defines, which files use it or it uses, its
|
|
3
|
+
// ships, the contract surfaces that reach it;
|
|
4
|
+
// storyAbout(brain, id) — one story: its epic, repos, tasks with their declared files and ships, surfaces.
|
|
5
|
+
// Both are pure: they read the brain object (`.sdlc/brain/graph.json`) and never the disk, so a test needs no
|
|
6
|
+
// Graphify. Every list is cut at `limit`, and `more` says how many were left out.
|
|
7
|
+
|
|
8
|
+
const RANK = { EXTRACTED: 3, INFERRED: 2, AMBIGUOUS: 1 };
|
|
9
|
+
|
|
10
|
+
// The edges of the brain, indexed both ways once per question.
|
|
11
|
+
function indexOf(brain) {
|
|
12
|
+
const byId = new Map(brain.nodes.map((n) => [n.id, n]));
|
|
13
|
+
const out = new Map();
|
|
14
|
+
const into = new Map();
|
|
15
|
+
for (const e of brain.edges) {
|
|
16
|
+
if (!byId.has(e.source) || !byId.has(e.target)) continue;
|
|
17
|
+
if (!out.has(e.source)) out.set(e.source, []);
|
|
18
|
+
out.get(e.source).push(e);
|
|
19
|
+
if (!into.has(e.target)) into.set(e.target, []);
|
|
20
|
+
into.get(e.target).push(e);
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
byId,
|
|
24
|
+
out: (id, rel) => (out.get(id) || []).filter((e) => !rel || e.relation === rel),
|
|
25
|
+
into: (id, rel) => (into.get(id) || []).filter((e) => !rel || e.relation === rel),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const cut = (list, limit) => ({ items: list.slice(0, limit), more: Math.max(0, list.length - limit) });
|
|
30
|
+
const filePath = (n) => n.id.slice(`file:${n.repo}:`.length);
|
|
31
|
+
const brief = (n) => (n ? { id: n.id, label: n.label } : null);
|
|
32
|
+
|
|
33
|
+
// A task's own short id (`T01`) from its node id `task:<story>:<repo>:<Tnn>`.
|
|
34
|
+
const taskShort = (id) => id.slice(id.lastIndexOf(':') + 1);
|
|
35
|
+
|
|
36
|
+
// The file nodes `target` names: `<repo>/<path>` when the first word is a repo the brain holds, and a bare
|
|
37
|
+
// `<path>` matched in every repo. Both readings are taken, so a repo named like a folder cannot hide a file.
|
|
38
|
+
// With `repo`, `target` is a path in that repo only (review 1: `--repo` must settle an ambiguity, never add one).
|
|
39
|
+
export function fileCandidates(brain, target, { repo = null } = {}) {
|
|
40
|
+
const t = String(target).trim().replace(/\\/g, '/').replace(/^(?:\.\/)+/, '');
|
|
41
|
+
const files = brain.nodes.filter((n) => n.kind === 'file' && typeof n.repo === 'string');
|
|
42
|
+
if (repo !== null) return files.filter((n) => n.repo === repo && filePath(n) === t);
|
|
43
|
+
const found = new Map();
|
|
44
|
+
const slash = t.indexOf('/');
|
|
45
|
+
if (slash > 0) {
|
|
46
|
+
const id = `file:${t.slice(0, slash)}:${t.slice(slash + 1)}`;
|
|
47
|
+
const n = files.find((x) => x.id === id);
|
|
48
|
+
if (n) found.set(n.id, n);
|
|
49
|
+
}
|
|
50
|
+
for (const n of files) if (filePath(n) === t) found.set(n.id, n);
|
|
51
|
+
return [...found.values()].sort((a, b) => a.id.localeCompare(b.id));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// The "did you mean" list for a file the brain does not hold: files with the same name in any folder, then the
|
|
55
|
+
// files in the folder named (a typo in the name).
|
|
56
|
+
export function fileSuggestions(brain, target, max = 5) {
|
|
57
|
+
const t = String(target).trim().replace(/\\/g, '/').replace(/^(?:\.\/)+/, '').toLowerCase();
|
|
58
|
+
const cutAt = t.lastIndexOf('/');
|
|
59
|
+
const name = t.slice(cutAt + 1);
|
|
60
|
+
const folder = cutAt > 0 ? t.slice(0, cutAt) : null;
|
|
61
|
+
if (!name) return [];
|
|
62
|
+
const all = brain.nodes.filter((n) => n.kind === 'file' && typeof n.repo === 'string').map((n) => `${n.repo}/${filePath(n)}`);
|
|
63
|
+
const sameName = all.filter((f) => f.toLowerCase().endsWith(`/${name}`));
|
|
64
|
+
const sameFolder = folder ? all.filter((f) => f.toLowerCase().startsWith(`${folder}/`) && !f.slice(folder.length + 1).includes('/')) : [];
|
|
65
|
+
return [...new Set([...sameName.sort(), ...sameFolder.sort()])].slice(0, max);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// `{ found: 'none' | 'many' | 'one', candidates?, about? }`.
|
|
69
|
+
export function fileAbout(brain, target, { limit = 25, repo: inRepo = null } = {}) {
|
|
70
|
+
const candidates = fileCandidates(brain, target, { repo: inRepo });
|
|
71
|
+
if (!candidates.length) return { found: 'none', suggestions: fileSuggestions(brain, inRepo !== null ? `${inRepo}/${target}` : target) };
|
|
72
|
+
if (candidates.length > 1) return { found: 'many', candidates: candidates.map((n) => `${n.repo}/${filePath(n)}`) };
|
|
73
|
+
const f = candidates[0];
|
|
74
|
+
const ix = indexOf(brain);
|
|
75
|
+
const repo = f.repo;
|
|
76
|
+
const here = filePath(f);
|
|
77
|
+
|
|
78
|
+
// Who declares it: task → story → epic.
|
|
79
|
+
const declaredBy = ix.into(f.id, 'declares-file').map((e) => {
|
|
80
|
+
const task = ix.byId.get(e.source);
|
|
81
|
+
const storyEdge = ix.into(task.id, 'has-task')[0];
|
|
82
|
+
const story = storyEdge ? ix.byId.get(storyEdge.source) : null;
|
|
83
|
+
const epicEdge = story ? ix.into(story.id, 'has-story')[0] : null;
|
|
84
|
+
return { task: { id: task.id, short: taskShort(task.id), label: task.label }, story: brief(story), epic: brief(epicEdge ? ix.byId.get(epicEdge.source) : null), repo: task.repo ?? repo };
|
|
85
|
+
}).sort((a, b) => a.task.id.localeCompare(b.task.id));
|
|
86
|
+
|
|
87
|
+
// What it defines, in file order where Graphify gave a line.
|
|
88
|
+
const line = (n) => { const m = /^L(\d+)/.exec(String(n.at ?? '')); return m ? Number(m[1]) : Infinity; };
|
|
89
|
+
const symbols = ix.out(f.id, 'defines').map((e) => ix.byId.get(e.target)).filter((n) => n.kind === 'code');
|
|
90
|
+
const defines = [...symbols].sort((a, b) => line(a) - line(b) || a.id.localeCompare(b.id))
|
|
91
|
+
.map((n) => ({ id: n.id, label: n.label, ...(n.at ? { at: n.at } : {}) }));
|
|
92
|
+
const mine = new Set(symbols.map((n) => n.id));
|
|
93
|
+
|
|
94
|
+
// Other files joined to this one by the code's own edges (calls, imports, …), one row per file: the
|
|
95
|
+
// relations seen, the strongest confidence, how many edges. An edge inside the file is not a use.
|
|
96
|
+
const joined = (edges, otherEnd) => {
|
|
97
|
+
const rows = new Map();
|
|
98
|
+
for (const e of edges) {
|
|
99
|
+
const other = ix.byId.get(otherEnd(e));
|
|
100
|
+
if (!other || other.kind !== 'code' || typeof other.file !== 'string') continue;
|
|
101
|
+
if (other.repo === repo && other.file === here) continue;
|
|
102
|
+
const key = `${other.repo}/${other.file}`;
|
|
103
|
+
const row = rows.get(key) || { file: key, repo: other.repo, path: other.file, relations: [], confidence: 'AMBIGUOUS', edges: 0 };
|
|
104
|
+
if (!row.relations.includes(e.relation)) row.relations.push(e.relation);
|
|
105
|
+
if ((RANK[e.confidence] || 0) > (RANK[row.confidence] || 0)) row.confidence = e.confidence;
|
|
106
|
+
row.edges += 1;
|
|
107
|
+
rows.set(key, row);
|
|
108
|
+
}
|
|
109
|
+
return [...rows.values()].map((r) => ({ ...r, relations: r.relations.sort() }))
|
|
110
|
+
.sort((a, b) => b.edges - a.edges || a.file.localeCompare(b.file));
|
|
111
|
+
};
|
|
112
|
+
const usedBy = joined([...mine].flatMap((id) => ix.into(id).filter((e) => e.relation !== 'defines')), (e) => e.source);
|
|
113
|
+
const uses = joined([...mine].flatMap((id) => ix.out(id)), (e) => e.target);
|
|
114
|
+
|
|
115
|
+
// The ships of the tasks that declare it.
|
|
116
|
+
const ships = new Map();
|
|
117
|
+
for (const d of declaredBy) {
|
|
118
|
+
for (const e of ix.out(d.task.id, 'shipped-as')) {
|
|
119
|
+
const s = ix.byId.get(e.target);
|
|
120
|
+
ships.set(s.id, { id: s.id, label: s.label, ...(s.pr ? { pr: s.pr } : {}), ...(s.date ? { date: s.date } : {}) });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// The contract surfaces that reach it: by its path (code-map), or by one of its symbols (name, handler).
|
|
125
|
+
const surfaces = new Map();
|
|
126
|
+
const surfaceEdge = (e) => {
|
|
127
|
+
const s = ix.byId.get(e.source);
|
|
128
|
+
if (s?.kind === 'surface') surfaces.set(s.id, { id: s.id, label: s.label, via: [...new Set([...(surfaces.get(s.id)?.via || []), e.relation])].sort() });
|
|
129
|
+
};
|
|
130
|
+
ix.into(f.id, 'mapped-to').forEach(surfaceEdge);
|
|
131
|
+
for (const id of mine) for (const e of ix.into(id)) if (e.relation === 'named-as' || e.relation === 'handled-by') surfaceEdge(e);
|
|
132
|
+
|
|
133
|
+
const lists = {
|
|
134
|
+
declaredBy: cut(declaredBy, limit),
|
|
135
|
+
defines: cut(defines, limit),
|
|
136
|
+
usedBy: cut(usedBy, limit),
|
|
137
|
+
uses: cut(uses, limit),
|
|
138
|
+
shippedIn: cut([...ships.values()].sort((a, b) => a.id.localeCompare(b.id)), limit),
|
|
139
|
+
surfaces: cut([...surfaces.values()].sort((a, b) => a.id.localeCompare(b.id)), limit),
|
|
140
|
+
};
|
|
141
|
+
return {
|
|
142
|
+
found: 'one',
|
|
143
|
+
about: {
|
|
144
|
+
file: { id: f.id, repo, path: here, ...(f.missing ? { missing: true } : {}) },
|
|
145
|
+
...Object.fromEntries(Object.entries(lists).map(([k, v]) => [k, v.items])),
|
|
146
|
+
more: Object.fromEntries(Object.entries(lists).filter(([, v]) => v.more).map(([k, v]) => [k, v.more])),
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// The story nodes whose id holds the text: the "did you mean" list for a story the brain does not hold.
|
|
152
|
+
export function storySuggestions(brain, id, max = 5) {
|
|
153
|
+
const t = String(id).trim().toLowerCase();
|
|
154
|
+
if (!t) return [];
|
|
155
|
+
return brain.nodes.filter((n) => n.kind === 'story' && n.id.slice('story:'.length).toLowerCase().includes(t))
|
|
156
|
+
.map((n) => n.id.slice('story:'.length)).sort().slice(0, max);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// `{ found: 'none', suggestions } | { found: 'one', about }`. A story's files are the files its tasks declare
|
|
160
|
+
// in the repos cloned here: a repo not cloned has no tasks in the brain, and `reposWithoutTasks` names it.
|
|
161
|
+
export function storyAbout(brain, id, { limit = 50 } = {}) {
|
|
162
|
+
const sid = `story:${String(id).trim()}`;
|
|
163
|
+
const ix = indexOf(brain);
|
|
164
|
+
const story = ix.byId.get(sid);
|
|
165
|
+
if (!story || story.kind !== 'story') return { found: 'none', suggestions: storySuggestions(brain, id) };
|
|
166
|
+
const epicEdge = ix.into(sid, 'has-story')[0];
|
|
167
|
+
const repos = ix.out(sid, 'builds-in').map((e) => ix.byId.get(e.target).label).sort();
|
|
168
|
+
const shipOf = (s) => ({ id: s.id, label: s.label, ...(s.pr ? { pr: s.pr } : {}), ...(s.date ? { date: s.date } : {}) });
|
|
169
|
+
const tasks = ix.out(sid, 'has-task').map((e) => ix.byId.get(e.target)).sort((a, b) => a.id.localeCompare(b.id)).map((t) => ({
|
|
170
|
+
id: t.id,
|
|
171
|
+
short: taskShort(t.id),
|
|
172
|
+
label: t.label,
|
|
173
|
+
repo: t.repo ?? null,
|
|
174
|
+
files: ix.out(t.id, 'declares-file').map((x) => ix.byId.get(x.target))
|
|
175
|
+
.map((n) => ({ repo: n.repo, path: filePath(n), ...(n.missing ? { missing: true } : {}) }))
|
|
176
|
+
.sort((a, b) => a.path.localeCompare(b.path)),
|
|
177
|
+
shipped: ix.out(t.id, 'shipped-as').map((x) => shipOf(ix.byId.get(x.target))),
|
|
178
|
+
}));
|
|
179
|
+
const files = new Map();
|
|
180
|
+
for (const t of tasks) {
|
|
181
|
+
for (const f of t.files) {
|
|
182
|
+
const key = `${f.repo}/${f.path}`;
|
|
183
|
+
const row = files.get(key) || { file: key, repo: f.repo, path: f.path, ...(f.missing ? { missing: true } : {}), tasks: [] };
|
|
184
|
+
row.tasks.push(t.short);
|
|
185
|
+
files.set(key, row);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
const withTasks = new Set(tasks.map((t) => t.repo));
|
|
189
|
+
const shownTasks = cut(tasks, limit);
|
|
190
|
+
const shownFiles = cut([...files.values()].sort((a, b) => a.file.localeCompare(b.file)), limit);
|
|
191
|
+
return {
|
|
192
|
+
found: 'one',
|
|
193
|
+
about: {
|
|
194
|
+
story: { id: sid.slice('story:'.length), ...(story.status ? { status: story.status } : {}), ...(story.summary ? { summary: story.summary } : {}) },
|
|
195
|
+
epic: epicEdge ? brief(ix.byId.get(epicEdge.source)) : null,
|
|
196
|
+
repos,
|
|
197
|
+
reposWithoutTasks: repos.filter((r) => !withTasks.has(r)),
|
|
198
|
+
tasks: shownTasks.items,
|
|
199
|
+
files: shownFiles.items,
|
|
200
|
+
// Ships recorded on the story itself (a ship whose task has no node here).
|
|
201
|
+
shipped: ix.out(sid, 'shipped-as').map((x) => shipOf(ix.byId.get(x.target))),
|
|
202
|
+
surfaces: ix.out(sid, 'touches-surface').map((x) => ix.byId.get(x.target).label).sort(),
|
|
203
|
+
more: Object.fromEntries([['tasks', shownTasks.more], ['files', shownFiles.more]].filter(([, v]) => v)),
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
// The live activity record, read back for `yad brain view --live` (E178).
|
|
2
|
+
//
|
|
3
|
+
// The hook (skills/yad-checks/templates/hooks/yad-activity.mjs) appends one line per agent tool call to each
|
|
4
|
+
// repo's `<git common dir>/yad-activity.jsonl`: the Product's, and each cloned code repo's. This module finds
|
|
5
|
+
// those files, reads them (a backlog for replay, then each new line as it lands, through a rotation), and
|
|
6
|
+
// MATCHES each event to the brain's nodes — here, in Node, where the unit suite reaches it; the page only
|
|
7
|
+
// draws what it is sent.
|
|
8
|
+
//
|
|
9
|
+
// A line is DATA from a file anything on the machine can write: it is read field by field against the
|
|
10
|
+
// hook's own shape, and anything else in it is dropped.
|
|
11
|
+
|
|
12
|
+
import fs from 'node:fs';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import { StringDecoder } from 'node:string_decoder';
|
|
15
|
+
import { run } from './lib.mjs';
|
|
16
|
+
import { brainRepos } from './brain.mjs';
|
|
17
|
+
import { readRegistry } from './workspace.mjs';
|
|
18
|
+
|
|
19
|
+
export const LOG_NAME = 'yad-activity.jsonl';
|
|
20
|
+
export const OLD_LOG_NAME = 'yad-activity.1.jsonl';
|
|
21
|
+
export const KEEP_DAYS = 14;
|
|
22
|
+
export const BACKLOG_LIMIT = 20000;
|
|
23
|
+
const OPS = new Set(['read', 'search', 'edit', 'run']);
|
|
24
|
+
const posix = (p) => String(p).replace(/\\/g, '/').replace(/^\.\//, '');
|
|
25
|
+
|
|
26
|
+
// ---- where the records are -----------------------------------------------------------------------
|
|
27
|
+
|
|
28
|
+
// Does the repo above `dir` track anything under it? One file is the answer: a big folder's full list
|
|
29
|
+
// overflows the small buffer, and that is a yes (E178 review 3). Shared with yad doctor.
|
|
30
|
+
export function tracksHere(dir, runner = run) {
|
|
31
|
+
const r = runner('git', ['-C', dir, 'ls-files', '-z', '--', '.'], { maxBuffer: 4096 });
|
|
32
|
+
return !!r.stdout && (r.ok || r.error?.code === 'ENOBUFS');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// The folder git keeps a repo's shared data in, or null. A folder with no `.git` of its own counts only when
|
|
36
|
+
// the repo above it tracks files under it — the hook's own rule, so both look in the same place.
|
|
37
|
+
function commonDir(dir, runner) {
|
|
38
|
+
if (!fs.existsSync(path.join(dir, '.git')) && !tracksHere(dir, runner)) return null;
|
|
39
|
+
const r = runner('git', ['-C', dir, 'rev-parse', '--path-format=absolute', '--git-common-dir']);
|
|
40
|
+
return r.ok && r.stdout && path.isAbsolute(r.stdout) ? r.stdout : null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// One source per repo that has a git folder: the Product (repo null) and each code repo cloned here. `prefix`
|
|
44
|
+
// is a code repo's folder inside the Product, for a Product session that edits it from there.
|
|
45
|
+
export function activitySources(root, { runner = run } = {}) {
|
|
46
|
+
const out = [];
|
|
47
|
+
const productDir = commonDir(root, runner);
|
|
48
|
+
const { registry } = readRegistry(root);
|
|
49
|
+
const { usable } = brainRepos(root, registry);
|
|
50
|
+
const prefixes = [];
|
|
51
|
+
for (const r of usable) {
|
|
52
|
+
const rel = posix(path.relative(root, r.target));
|
|
53
|
+
if (rel && !rel.startsWith('..') && !path.isAbsolute(rel)) prefixes.push({ repo: r.name, prefix: `${rel}/` });
|
|
54
|
+
}
|
|
55
|
+
if (productDir) out.push({ repo: null, dir: productDir, prefixes });
|
|
56
|
+
for (const r of usable) {
|
|
57
|
+
const d = commonDir(r.target, runner);
|
|
58
|
+
if (d && d !== productDir) out.push({ repo: r.name, dir: d, prefixes: [] });
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ---- reading lines -------------------------------------------------------------------------------
|
|
64
|
+
|
|
65
|
+
// One record from one line, in the hook's shape, or null. Nothing beyond the hook's fields is kept.
|
|
66
|
+
export function parseRecord(line) {
|
|
67
|
+
let r;
|
|
68
|
+
try { r = JSON.parse(line); } catch { return null; }
|
|
69
|
+
if (!r || typeof r !== 'object' || Array.isArray(r) || r.v !== 1 || !OPS.has(r.op)) return null;
|
|
70
|
+
const t = Date.parse(r.ts);
|
|
71
|
+
if (!Number.isFinite(t)) return null;
|
|
72
|
+
const paths = Array.isArray(r.paths) ? r.paths.filter((p) => typeof p === 'string' && p && p.length <= 1024 && !p.startsWith('/') && !p.split('/').includes('..')).slice(0, 20) : [];
|
|
73
|
+
return {
|
|
74
|
+
t,
|
|
75
|
+
op: r.op,
|
|
76
|
+
s: typeof r.s === 'string' && /^[0-9a-f]{12}$/.test(r.s) ? r.s : null,
|
|
77
|
+
h: r.h === 'cursor' ? 'cursor' : 'claude',
|
|
78
|
+
tool: typeof r.tool === 'string' ? r.tool.slice(0, 40) : null,
|
|
79
|
+
paths,
|
|
80
|
+
...(typeof r.yad === 'string' && /^[a-z][a-z-]*( [a-z][a-z-]*)?$/.test(r.yad) ? { yad: r.yad } : {}),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// A log is read only when it is a PLAIN FILE: a link could point the reader at any file, and a FIFO would
|
|
85
|
+
// block it for ever (E178 review 1). The size is read from the open file itself.
|
|
86
|
+
const MAX_READ = 8 * 1024 * 1024;
|
|
87
|
+
const MAX_PART = 64 * 1024;
|
|
88
|
+
function openPlain(file) {
|
|
89
|
+
try { if (!fs.lstatSync(file).isFile()) return null; } catch { return null; }
|
|
90
|
+
let fd;
|
|
91
|
+
try {
|
|
92
|
+
fd = fs.openSync(file, 'r');
|
|
93
|
+
const st = fs.fstatSync(fd);
|
|
94
|
+
if (!st.isFile()) { fs.closeSync(fd); return null; }
|
|
95
|
+
return { fd, st };
|
|
96
|
+
} catch { if (fd !== undefined) fs.closeSync(fd); return null; }
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// The last MAX_READ bytes of a plain file, from its first whole line; '' for anything else.
|
|
100
|
+
// With `upTo` ({ ino, offset } of the live reader), the file is read only up to there — and not at all when it
|
|
101
|
+
// is not the file the reader stands in (rotated in between, or made since): the reader sends all of it.
|
|
102
|
+
function readTail(file, upTo = null) {
|
|
103
|
+
const o = openPlain(file);
|
|
104
|
+
if (!o) return '';
|
|
105
|
+
try {
|
|
106
|
+
if (upTo !== null && upTo.ino && upTo.ino !== o.st.ino) return '';
|
|
107
|
+
const end = upTo === null ? o.st.size : Math.min(o.st.size, upTo.offset);
|
|
108
|
+
const from = Math.max(0, end - MAX_READ);
|
|
109
|
+
const buf = Buffer.alloc(end - from);
|
|
110
|
+
const got = fs.readSync(o.fd, buf, 0, buf.length, from);
|
|
111
|
+
const text = buf.subarray(0, got).toString('utf8');
|
|
112
|
+
return from === 0 ? text : text.slice(text.indexOf('\n') + 1);
|
|
113
|
+
} catch { return ''; } finally { fs.closeSync(o.fd); }
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// The recent past, for replay: every source's old and current file, newest KEEP_DAYS, oldest first, at most
|
|
117
|
+
// `limit` events (the newest ones).
|
|
118
|
+
// Is the old file the one the live reader stood in? Only when file numbers can be trusted: a file system that
|
|
119
|
+
// gives every file 0 (FAT, exFAT, some network shares) or the same number to two files (a 64-bit NTFS id past
|
|
120
|
+
// what a JavaScript number holds) cannot tell — then the old file is read whole (E178 review 5).
|
|
121
|
+
const oldIs = (src, at) => {
|
|
122
|
+
if (!at || !at.ino) return false;
|
|
123
|
+
try {
|
|
124
|
+
const old = fs.lstatSync(path.join(src.dir, OLD_LOG_NAME)).ino;
|
|
125
|
+
let cur = null;
|
|
126
|
+
try { cur = fs.lstatSync(path.join(src.dir, LOG_NAME)).ino; } catch { /* no current file */ }
|
|
127
|
+
return old === at.ino && old !== cur;
|
|
128
|
+
} catch { return false; }
|
|
129
|
+
};
|
|
130
|
+
// `upTo(src)` gives where the live reader of a source stands ({ ino, offset }): the current file is read only
|
|
131
|
+
// up to there, so a line is in the backlog or sent live — not both, save in two rare races that repeat a line
|
|
132
|
+
// rather than lose one: a rotation between this read's two files, and one on a file system whose file numbers
|
|
133
|
+
// are all 0 (E178 reviews 3, 5).
|
|
134
|
+
export function readBacklog(sources, { now = Date.now(), days = KEEP_DAYS, limit = BACKLOG_LIMIT, upTo = () => null } = {}) {
|
|
135
|
+
const since = now - days * 86400000;
|
|
136
|
+
const all = [];
|
|
137
|
+
for (const src of sources) {
|
|
138
|
+
// The CURRENT file first: a rotation between the two reads then repeats a line (it is in both) rather than
|
|
139
|
+
// losing one (in neither) (E178 review 5).
|
|
140
|
+
for (const name of [LOG_NAME, OLD_LOG_NAME]) {
|
|
141
|
+
// The current file stops at the reader. The OLD file does too when it is the one the reader stood in
|
|
142
|
+
// (rotated since): its tail is the reader's to send at its next look (E178 review 4).
|
|
143
|
+
const at = upTo(src);
|
|
144
|
+
const cut = at === null ? null : name === LOG_NAME ? at : (oldIs(src, at) ? at : null);
|
|
145
|
+
for (const line of readTail(path.join(src.dir, name), cut).split('\n')) {
|
|
146
|
+
const r = line ? parseRecord(line) : null;
|
|
147
|
+
if (r && r.t >= since && r.t <= now + 60000) all.push({ src, r });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
all.sort((a, b) => a.r.t - b.r.t);
|
|
152
|
+
return all.slice(-limit);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Follow one source's current file: `onRecord(src, record)` for each whole new line. It starts at the end
|
|
156
|
+
// (the backlog has the rest). ITS LIMIT: a rotation is caught only while the renamed file is the one last read
|
|
157
|
+
// and at most 4 MB behind; rotated twice between two looks (half a second apart, 5 MB a file), or looked at in
|
|
158
|
+
// the instant between the rename and the next write, the old file's unread tail is not sent live — it is still
|
|
159
|
+
// in the backlog of the next page that opens (E178 review 2). On a file system that numbers every file 0 (FAT,
|
|
160
|
+
// exFAT) a rotation is not seen at all: the old file's unread tail is not sent live (the next page's backlog
|
|
161
|
+
// has it), and the new file is read from where the old one stood until it outgrows it. At a rotation it first reads what the old file gained since the last look (now
|
|
162
|
+
// renamed aside), then starts the new file at 0. Bytes are decoded as a stream, so a character split across
|
|
163
|
+
// two reads arrives whole; a part line longer than MAX_PART (no newline ever comes) is dropped. Returns
|
|
164
|
+
// { stop, pump, position }.
|
|
165
|
+
export function follow(src, onRecord, { interval = 500, watch = fs.watchFile, unwatch = fs.unwatchFile } = {}) {
|
|
166
|
+
const file = path.join(src.dir, LOG_NAME);
|
|
167
|
+
let offset = 0;
|
|
168
|
+
let ino = null;
|
|
169
|
+
let rest = '';
|
|
170
|
+
let decoder = new StringDecoder('utf8');
|
|
171
|
+
const first = openPlain(file);
|
|
172
|
+
if (first) { offset = first.st.size; ino = first.st.ino; fs.closeSync(first.fd); }
|
|
173
|
+
const take = (text) => {
|
|
174
|
+
const lines = (rest + text).split('\n');
|
|
175
|
+
rest = lines.pop();
|
|
176
|
+
if (rest.length > MAX_PART) rest = '';
|
|
177
|
+
for (const line of lines) { const r = line ? parseRecord(line) : null; if (r) onRecord(src, r); }
|
|
178
|
+
};
|
|
179
|
+
// Read `o` from `offset` to its end, at most 4 MB a tick.
|
|
180
|
+
const drain = (o) => {
|
|
181
|
+
const len = Math.min(o.st.size - offset, 4 * 1024 * 1024);
|
|
182
|
+
if (len <= 0) return;
|
|
183
|
+
const buf = Buffer.alloc(len);
|
|
184
|
+
const got = fs.readSync(o.fd, buf, 0, len, offset);
|
|
185
|
+
offset += got;
|
|
186
|
+
take(decoder.write(buf.subarray(0, got)));
|
|
187
|
+
};
|
|
188
|
+
const pump = () => {
|
|
189
|
+
const o = openPlain(file);
|
|
190
|
+
if (!o) { offset = 0; ino = null; rest = ''; decoder = new StringDecoder('utf8'); return; }
|
|
191
|
+
try {
|
|
192
|
+
if (ino !== null && o.st.ino !== ino) {
|
|
193
|
+
// Rotated: the old file is the renamed one when its inode is the one we were reading.
|
|
194
|
+
const old = openPlain(path.join(src.dir, OLD_LOG_NAME));
|
|
195
|
+
if (old) { try { if (old.st.ino === ino) drain(old); } catch { /* lost, as a rotation may lose a line */ } finally { fs.closeSync(old.fd); } }
|
|
196
|
+
offset = 0; rest = ''; decoder = new StringDecoder('utf8');
|
|
197
|
+
} else if (o.st.size < offset) { offset = 0; rest = ''; decoder = new StringDecoder('utf8'); }
|
|
198
|
+
ino = o.st.ino;
|
|
199
|
+
drain(o);
|
|
200
|
+
} catch { /* read again on the next tick */ } finally { fs.closeSync(o.fd); }
|
|
201
|
+
};
|
|
202
|
+
watch(file, { interval, persistent: false }, pump);
|
|
203
|
+
// Where this reader stands: the backlog of a page that opens now stops here.
|
|
204
|
+
const position = () => (ino === null ? { ino: -1, offset: 0 } : { ino, offset: offset - Buffer.byteLength(rest) });
|
|
205
|
+
return { stop: () => unwatch(file, pump), pump, position };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// ---- matching events to the brain ----------------------------------------------------------------
|
|
209
|
+
|
|
210
|
+
// What the matcher needs from the view model: each file node by repo and path, the code a file defines, and
|
|
211
|
+
// each Product work file's node.
|
|
212
|
+
export function activityIndex(model) {
|
|
213
|
+
const byId = new Map(model.nodes.map((n, i) => [n.id, i]));
|
|
214
|
+
// Each repo's file nodes by path, for a search of a folder.
|
|
215
|
+
const files = new Map();
|
|
216
|
+
model.nodes.forEach((n, i) => {
|
|
217
|
+
const m = /^file:([^:]+):(.+)$/.exec(n.id);
|
|
218
|
+
if (!m) return;
|
|
219
|
+
if (!files.has(m[1])) files.set(m[1], []);
|
|
220
|
+
files.get(m[1]).push([m[2], i]);
|
|
221
|
+
});
|
|
222
|
+
const defines = new Map();
|
|
223
|
+
for (const e of model.edges) {
|
|
224
|
+
if (e.relation !== 'defines') continue;
|
|
225
|
+
if (!defines.has(e.s)) defines.set(e.s, []);
|
|
226
|
+
defines.get(e.s).push(e.t);
|
|
227
|
+
}
|
|
228
|
+
return { byId, defines, files };
|
|
229
|
+
}
|
|
230
|
+
export const AREA_LIMIT = 24;
|
|
231
|
+
|
|
232
|
+
// The brain's nodes for one Product path: a story file is its story, a contract its contract, anything else
|
|
233
|
+
// under an epic's folder the epic.
|
|
234
|
+
function productNode(index, p) {
|
|
235
|
+
const m = /^epics\/([^/]+)\/(.*)$/.exec(p);
|
|
236
|
+
if (!m) return null;
|
|
237
|
+
const [, epic, inner] = m;
|
|
238
|
+
const story = /^stories\/([^/]+)\.md$/.exec(inner);
|
|
239
|
+
if (story && index.byId.has(`story:${story[1]}`)) return index.byId.get(`story:${story[1]}`);
|
|
240
|
+
if (inner === 'contract.md' && index.byId.has(`contract:${epic}`)) return index.byId.get(`contract:${epic}`);
|
|
241
|
+
return index.byId.get(`epic:${epic}`) ?? null;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// One event, as the page draws it: { t, op, s, h, tool, yad?, repo, hits: [{ path, node, code: [indexes] }],
|
|
245
|
+
// areas: [{ path, nodes: [indexes] }], outside: [path] }. `node` is the file (or work item) the comet flies to;
|
|
246
|
+
// `code` is what that file defines (at most 8), lit with it. A FOLDER (a search's scope) is an area: the files
|
|
247
|
+
// under it, at most AREA_LIMIT, lit softly; a path that is neither is outside the brain.
|
|
248
|
+
export function matchEvent(index, src, r) {
|
|
249
|
+
const hits = [];
|
|
250
|
+
const areas = [];
|
|
251
|
+
const outside = [];
|
|
252
|
+
for (const raw of r.paths) {
|
|
253
|
+
let repo = src.repo;
|
|
254
|
+
let p = raw;
|
|
255
|
+
if (repo === null) {
|
|
256
|
+
const pre = src.prefixes.find((x) => raw.startsWith(x.prefix));
|
|
257
|
+
if (pre) { repo = pre.repo; p = raw.slice(pre.prefix.length); }
|
|
258
|
+
}
|
|
259
|
+
const node = repo === null ? productNode(index, p) : index.byId.get(`file:${repo}:${p}`) ?? null;
|
|
260
|
+
const shown = repo === null ? p : `${repo}/${p}`;
|
|
261
|
+
if (node === null) {
|
|
262
|
+
const under = repo === null ? [] : (index.files.get(repo) || []).filter(([f]) => f.startsWith(`${p.replace(/\/$/, '')}/`)).map(([, i]) => i);
|
|
263
|
+
if (under.length) areas.push({ path: shown, nodes: under.slice(0, AREA_LIMIT) });
|
|
264
|
+
else outside.push(shown);
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
hits.push({ path: shown, node, code: (index.defines.get(node) || []).slice(0, 8) });
|
|
268
|
+
}
|
|
269
|
+
return { t: r.t, op: r.op, s: r.s, h: r.h, tool: r.tool, ...(r.yad ? { yad: r.yad } : {}), repo: src.repo, hits, areas, outside };
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// ---- the plan --------------------------------------------------------------------------------------
|
|
273
|
+
|
|
274
|
+
// Each task and the files it declares, for Plan vs reality: [{ task, story, files: [indexes] }], from the
|
|
275
|
+
// `has-task` and `declares-file` edges.
|
|
276
|
+
export function planOf(model) {
|
|
277
|
+
const storyOf = new Map();
|
|
278
|
+
const files = new Map();
|
|
279
|
+
for (const e of model.edges) {
|
|
280
|
+
if (e.relation === 'has-task') storyOf.set(e.t, e.s);
|
|
281
|
+
if (e.relation === 'declares-file') { if (!files.has(e.s)) files.set(e.s, []); files.get(e.s).push(e.t); }
|
|
282
|
+
}
|
|
283
|
+
return model.nodes.map((n, i) => [n, i]).filter(([n]) => n.kind === 'task')
|
|
284
|
+
.map(([, i]) => ({ task: i, story: storyOf.has(i) ? storyOf.get(i) : null, files: files.get(i) || [] }));
|
|
285
|
+
}
|