yadflow 4.10.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 +97 -0
- package/README.md +12 -3
- package/bin/commands.mjs +5 -1
- package/bin/yad.mjs +109 -15
- package/cli/agent-guard-worker.mjs +13 -0
- package/cli/agent-guard.mjs +1053 -57
- package/cli/agent-rules.mjs +34 -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 +344 -0
- package/cli/brain.mjs +810 -0
- package/cli/ci-check.mjs +3 -3
- package/cli/doctor.mjs +80 -13
- 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/hook.mjs +59 -9
- package/cli/issues-act.mjs +57 -13
- package/cli/issues-write.mjs +19 -6
- package/cli/issues.mjs +62 -23
- package/cli/lib.mjs +37 -2
- package/cli/local-page.mjs +138 -0
- package/cli/machine.mjs +1 -1
- package/cli/manifest.mjs +50 -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 +186 -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/plan.mjs +125 -0
- package/cli/platform.mjs +5 -5
- package/cli/product-index.mjs +1 -1
- package/cli/protection.mjs +32 -0
- package/cli/reconcile.mjs +8 -2
- package/cli/report.mjs +9 -3
- package/cli/reports-dir.mjs +391 -0
- package/cli/reports.mjs +65 -0
- package/cli/run-checks.mjs +5 -2
- package/cli/scan.mjs +1 -1
- package/cli/setup.mjs +30 -5
- package/cli/standup.mjs +87 -71
- 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-guide.mjs +211 -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 +59 -4
- package/cli/update-commit.mjs +101 -9
- package/cli/usage.mjs +8 -4
- package/package.json +8 -4
- package/skills/yad-architecture/SKILL.md +22 -4
- 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/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 +4 -4
- 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,391 @@
|
|
|
1
|
+
// The local reports folder (E180).
|
|
2
|
+
//
|
|
3
|
+
// A report shows the state of the work at one moment, and goes stale as soon as the work moves on. So
|
|
4
|
+
// every report yadflow writes — the standup, the usage and issues reports, the brain view page, and
|
|
5
|
+
// later the progress map and the doc sites — is saved on THIS machine only, in one folder beside the
|
|
6
|
+
// Product, and never committed or pushed unless the person asks for that themselves:
|
|
7
|
+
//
|
|
8
|
+
// acme/
|
|
9
|
+
// product/ <- the Product (its main checkout)
|
|
10
|
+
// product--EP-x/ <- a worktree of it (#115) — it saves into the same folder below
|
|
11
|
+
// product--reports/ <- the reports folder
|
|
12
|
+
// .gitignore `*`, so a folder that ends up inside a git tree is still never added
|
|
13
|
+
// index.html the catalog page: every saved report, newest first
|
|
14
|
+
// catalog.json the same list as data
|
|
15
|
+
// standup/2026-11-14-0900--standup--team--3-waiting.md
|
|
16
|
+
// usage/2026-11-01-1000--usage--team--all-time.html
|
|
17
|
+
//
|
|
18
|
+
// A file's name says what it is and what state it shows: `<date>-<time>--<kind>--<scope>--<state>.<ext>`.
|
|
19
|
+
// The date comes first, so sorting by name sorts by time. Each part is cut down to `a-z 0-9 -`, so the
|
|
20
|
+
// name is the same on every system (Windows refuses `:` and a few other characters).
|
|
21
|
+
//
|
|
22
|
+
// Where the folder is, first match wins:
|
|
23
|
+
// 1. `--out <file>` on the command — that file, exactly as before (the catalog is not touched);
|
|
24
|
+
// 2. YAD_REPORTS_DIR — a folder the person chose (for example on another disk);
|
|
25
|
+
// 3. `<main checkout>--reports`, beside the Product's main checkout. A run from a worktree, or from a
|
|
26
|
+
// code repo (yad finds the Product first), lands in the same one folder.
|
|
27
|
+
//
|
|
28
|
+
// The catalog records the Product commit each report was made at, so `yad reports list` can say which
|
|
29
|
+
// ones are stale: the Product's epics/ or .sdlc/ changed since then.
|
|
30
|
+
import fs from 'node:fs';
|
|
31
|
+
import path from 'node:path';
|
|
32
|
+
import { spawnSync } from 'node:child_process';
|
|
33
|
+
import { randomBytes } from 'node:crypto';
|
|
34
|
+
import { readJSONStrict, writeJSON } from './lib.mjs';
|
|
35
|
+
|
|
36
|
+
export const REPORTS_SUFFIX = '--reports';
|
|
37
|
+
export const CATALOG_FILE = 'catalog.json';
|
|
38
|
+
export const INDEX_FILE = 'index.html';
|
|
39
|
+
export const CATALOG_VERSION = 1;
|
|
40
|
+
export const REPORTS_ENV = 'YAD_REPORTS_DIR';
|
|
41
|
+
// A report may keep one side file beside it, `<file>.digest.json` (the progress map's item states, E181).
|
|
42
|
+
export const SIDE_SUFFIX = '.digest.json';
|
|
43
|
+
|
|
44
|
+
// The kinds of report. A kind is also its subfolder's name, so only these are accepted.
|
|
45
|
+
export const KINDS = Object.freeze({
|
|
46
|
+
'progress-map': 'Progress map',
|
|
47
|
+
'brain-view': 'Brain view',
|
|
48
|
+
usage: 'Usage report',
|
|
49
|
+
standup: 'Standup',
|
|
50
|
+
issues: 'Issues report',
|
|
51
|
+
'docs-site': 'Docs site',
|
|
52
|
+
timeline: 'Timeline',
|
|
53
|
+
defects: 'Defects report',
|
|
54
|
+
learning: 'Learning tutorial',
|
|
55
|
+
status: 'Status',
|
|
56
|
+
history: 'History',
|
|
57
|
+
claims: 'Claims',
|
|
58
|
+
doctor: 'Doctor',
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const git = (runner, cwd, args) => {
|
|
62
|
+
const r = runner('git', ['-C', cwd, ...args], { encoding: 'utf8' });
|
|
63
|
+
return { ok: r.status === 0, code: r.status, out: String(r.stdout ?? '').trim() };
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// The Product's MAIN checkout: for a worktree, the folder that holds the shared .git; else `root` itself.
|
|
67
|
+
// Only when `root` is the TOP of its checkout: a Product folder inside some other repo (a test fixture,
|
|
68
|
+
// a monorepo) keeps its reports beside itself, never beside that other repo.
|
|
69
|
+
export function mainCheckout(root, { runner = spawnSync } = {}) {
|
|
70
|
+
const top = git(runner, root, ['rev-parse', '--show-toplevel']);
|
|
71
|
+
const real = (p) => { let r; try { r = fs.realpathSync.native(p); } catch { r = path.resolve(p); } return process.platform === 'win32' ? r.toLowerCase() : r; };
|
|
72
|
+
if (!top.ok || !top.out || real(top.out) !== real(root)) return path.resolve(root);
|
|
73
|
+
const r = git(runner, root, ['rev-parse', '--path-format=absolute', '--git-common-dir']);
|
|
74
|
+
if (!r.ok || !r.out) return path.resolve(root);
|
|
75
|
+
const common = path.resolve(root, r.out);
|
|
76
|
+
// A normal checkout keeps its git data in `<checkout>/.git`; anything else (a bare repo) has no
|
|
77
|
+
// checkout to stand beside, so the folder given is used.
|
|
78
|
+
return path.basename(common) === '.git' ? path.dirname(common) : path.resolve(root);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// → { dir, via: 'env' | 'beside' }
|
|
82
|
+
export function reportsDir(root, { env = process.env, runner = spawnSync } = {}) {
|
|
83
|
+
const chosen = env[REPORTS_ENV];
|
|
84
|
+
if (chosen && String(chosen).trim()) return { dir: path.resolve(String(chosen).trim()), via: 'env' };
|
|
85
|
+
const main = mainCheckout(root, { runner });
|
|
86
|
+
return { dir: path.join(path.dirname(main), `${path.basename(main)}${REPORTS_SUFFIX}`), via: 'beside' };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// One part of a name: lower case, `a-z 0-9 -` only, no doubled or end dashes, at most `max` long.
|
|
90
|
+
export function slug(s, max = 40) {
|
|
91
|
+
const out = String(s ?? '')
|
|
92
|
+
.normalize('NFKD').replace(/[̀-ͯ]/g, '')
|
|
93
|
+
.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '')
|
|
94
|
+
.slice(0, max).replace(/-+$/g, '');
|
|
95
|
+
return out || 'none';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
99
|
+
// The local date and time, `YYYY-MM-DD-HHmm` — the person reads it in their own time.
|
|
100
|
+
export const stamp = (at) => `${at.getFullYear()}-${pad(at.getMonth() + 1)}-${pad(at.getDate())}-${pad(at.getHours())}${pad(at.getMinutes())}`;
|
|
101
|
+
|
|
102
|
+
const EXT_RE = /^[a-z0-9]{1,8}$/;
|
|
103
|
+
export function reportName({ kind, scope, state, at = new Date(), ext }) {
|
|
104
|
+
if (!Object.hasOwn(KINDS, kind)) throw new Error(`unknown report kind: ${kind}`);
|
|
105
|
+
if (!EXT_RE.test(String(ext))) throw new Error(`bad report extension: ${ext}`);
|
|
106
|
+
return `${stamp(at)}--${kind}--${slug(scope, 40)}--${slug(state, 40)}.${ext}`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Write `content` as a NEW file in `dir`: `name`, else `name-2`, `name-3`… before the extension. Each name
|
|
110
|
+
// is taken with an exclusive create (`wx`), so two runs at the same moment never write the same file.
|
|
111
|
+
function writeFresh(dir, name, content) {
|
|
112
|
+
const dot = name.lastIndexOf('.');
|
|
113
|
+
const [base, ext] = dot > 0 ? [name.slice(0, dot), name.slice(dot)] : [name, ''];
|
|
114
|
+
for (let i = 1; i < 1000; i++) {
|
|
115
|
+
const n = i === 1 ? name : `${base}-${i}${ext}`;
|
|
116
|
+
try { fs.writeFileSync(path.join(dir, n), content, { flag: 'wx' }); return n; } catch (e) { if (e.code !== 'EEXIST') throw e; }
|
|
117
|
+
}
|
|
118
|
+
throw new Error(`no free name for ${name} in ${dir}`);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Hold `catalog.lock` while the catalog is read, changed and written, so a run at the same moment never
|
|
122
|
+
// loses an entry.
|
|
123
|
+
// - The lock appears WHOLE: its `<pid> <token>` is written to a temp file first, then hard-linked to
|
|
124
|
+
// `catalog.lock` (a link fails when the lock is there), so no run ever reads a half-made, empty lock.
|
|
125
|
+
// - It is taken over only when its content is ours to judge — `<pid> <token>`, with that process no
|
|
126
|
+
// longer alive — or it is older than 5 minutes. A takeover renames the lock aside, then checks that
|
|
127
|
+
// what it moved is what it judged; a fresh lock another run made in between is linked back.
|
|
128
|
+
// - On the way out a run removes the lock only while it still holds its own token.
|
|
129
|
+
// - A lock that cannot be read (a folder, no permission) is never spun on: the deadline still ends it.
|
|
130
|
+
// The pid is this machine's: a reports folder shared with another machine or a container can see a
|
|
131
|
+
// live lock there as dead. One residual race is left (a third run locking in the instant between the
|
|
132
|
+
// rename and the link-back); it needs a crashed run and three runs in the same moment.
|
|
133
|
+
const LOCK_FILE = 'catalog.lock';
|
|
134
|
+
const LOCK_STALE_MS = 5 * 60 * 1000;
|
|
135
|
+
const LOCK_RE = /^(\d+) [0-9a-f]{16}$/;
|
|
136
|
+
const alive = (pid) => { if (!Number.isInteger(pid) || pid <= 0) return false; try { process.kill(pid, 0); return true; } catch (e) { return e.code === 'EPERM'; } };
|
|
137
|
+
function lockStale(held, age) {
|
|
138
|
+
if (age > LOCK_STALE_MS) return true;
|
|
139
|
+
const m = LOCK_RE.exec(String(held));
|
|
140
|
+
return !!m && !alive(Number(m[1]));
|
|
141
|
+
}
|
|
142
|
+
// A disk with no hard links (FAT, exFAT, some network shares) says so with one of these; there the lock is
|
|
143
|
+
// made with a plain exclusive create, which brings back the small "empty for an instant" window — a young
|
|
144
|
+
// lock yad cannot judge is waited on, never taken over, so that window costs a wait, not an entry.
|
|
145
|
+
const NO_LINKS = new Set(['EPERM', 'ENOTSUP', 'ENOSYS', 'EXDEV', 'EOPNOTSUPP']);
|
|
146
|
+
function tryLock(lock, token) {
|
|
147
|
+
const tmp = `${lock}.${randomBytes(6).toString('hex')}.new`;
|
|
148
|
+
try {
|
|
149
|
+
fs.writeFileSync(tmp, token, { flag: 'wx' });
|
|
150
|
+
fs.linkSync(tmp, lock);
|
|
151
|
+
return true;
|
|
152
|
+
} catch (e) {
|
|
153
|
+
if (e.code === 'EEXIST') return false;
|
|
154
|
+
if (!NO_LINKS.has(e.code)) throw e;
|
|
155
|
+
try { fs.writeFileSync(lock, token, { flag: 'wx' }); return true; } catch (e2) { if (e2.code === 'EEXIST') return false; throw e2; }
|
|
156
|
+
} finally { fs.rmSync(tmp, { force: true }); }
|
|
157
|
+
}
|
|
158
|
+
export function withCatalogLock(dir, fn, { waitMs = 5000 } = {}) {
|
|
159
|
+
const lock = path.join(dir, LOCK_FILE);
|
|
160
|
+
const token = `${process.pid} ${randomBytes(8).toString('hex')}`;
|
|
161
|
+
const until = Date.now() + waitMs;
|
|
162
|
+
for (;;) {
|
|
163
|
+
if (tryLock(lock, token)) break;
|
|
164
|
+
if (Date.now() > until) return { problem: `${lock} is held by another yad run that is still going`, held: true };
|
|
165
|
+
let held, age;
|
|
166
|
+
try { held = fs.readFileSync(lock, 'utf8'); age = Date.now() - fs.statSync(lock).mtimeMs; } catch (e) {
|
|
167
|
+
if (e.code === 'ENOENT') continue; // released between the two steps: try again
|
|
168
|
+
return { problem: `${lock} cannot be read (${e.code || e.message}) — remove it if no yad run is going`, held: true };
|
|
169
|
+
}
|
|
170
|
+
if (lockStale(held, age)) {
|
|
171
|
+
const aside = `${lock}.${randomBytes(6).toString('hex')}.stale`;
|
|
172
|
+
try { fs.renameSync(lock, aside); } catch { continue; } // another run moved it first
|
|
173
|
+
let moved = null; try { moved = fs.readFileSync(aside, 'utf8'); } catch { /* gone */ }
|
|
174
|
+
if (moved !== held && moved !== null) {
|
|
175
|
+
// Put the fresh lock back, exclusively: by a link, or on a disk with no hard links by writing its
|
|
176
|
+
// content again. Either fails when a newer lock is already there.
|
|
177
|
+
try { fs.linkSync(aside, lock); } catch (e) { if (NO_LINKS.has(e.code)) { try { fs.writeFileSync(lock, moved, { flag: 'wx' }); } catch { /* a newer lock is there */ } } }
|
|
178
|
+
}
|
|
179
|
+
fs.rmSync(aside, { force: true });
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 50);
|
|
183
|
+
}
|
|
184
|
+
try { return fn(); } finally {
|
|
185
|
+
try { if (fs.readFileSync(lock, 'utf8') === token) fs.rmSync(lock, { force: true }); } catch { /* already gone */ }
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Make `dir` (and its parents), refusing a path that exists and is not a plain folder.
|
|
190
|
+
function ownDir(dir) {
|
|
191
|
+
let st = null;
|
|
192
|
+
try { st = fs.lstatSync(dir); } catch { /* new */ }
|
|
193
|
+
if (st && !st.isDirectory()) return `${dir} is not a plain folder (a file or a link) — remove it, or set ${REPORTS_ENV}`;
|
|
194
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Write by a temp file and a rename, never through a link.
|
|
199
|
+
function writeNew(file, content) {
|
|
200
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
201
|
+
fs.rmSync(tmp, { force: true });
|
|
202
|
+
try {
|
|
203
|
+
fs.writeFileSync(tmp, content, { flag: 'wx' });
|
|
204
|
+
fs.renameSync(tmp, file);
|
|
205
|
+
} finally { fs.rmSync(tmp, { force: true }); }
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// The `.gitignore` that keeps the folder out of any git tree it may sit in. Written once; a person's own
|
|
209
|
+
// edit to it is left alone.
|
|
210
|
+
function ensureIgnored(dir) {
|
|
211
|
+
const f = path.join(dir, '.gitignore');
|
|
212
|
+
if (!fs.existsSync(f)) writeNew(f, '# yadflow reports — local to this machine, never committed (E180)\n*\n');
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// The catalog, or `{ problem }` when the file is there and cannot be read: it is never overwritten then.
|
|
216
|
+
export function readCatalog(dir) {
|
|
217
|
+
const file = path.join(dir, CATALOG_FILE);
|
|
218
|
+
let rec;
|
|
219
|
+
try { rec = readJSONStrict(file, null); } catch (e) { return { problem: `${file} cannot be read (${e.message.split('\n')[0]}) — fix or remove it; the catalog was not changed` }; }
|
|
220
|
+
if (rec === null) return { entries: [] };
|
|
221
|
+
if (typeof rec !== 'object' || Array.isArray(rec) || !Array.isArray(rec.entries)) return { problem: `${file} is not a reports catalog — fix or remove it; the catalog was not changed` };
|
|
222
|
+
if (rec.version !== CATALOG_VERSION) return { problem: `${file} is version ${JSON.stringify(rec.version ?? null)}, and this yadflow reads version ${CATALOG_VERSION} — the catalog was not changed` };
|
|
223
|
+
return { entries: rec.entries.filter((e) => e && typeof e.file === 'string') };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// The local date and time a report was made, as its file name spells it (`2026-11-14 09:05`).
|
|
227
|
+
const madeAt = (iso) => { const d = new Date(iso); return Number.isFinite(d.getTime()) ? stamp(d).replace(/^(\d{4}-\d{2}-\d{2})-(\d{2})(\d{2})$/, '$1 $2:$3') : '—'; };
|
|
228
|
+
const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (ch) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[ch]));
|
|
229
|
+
|
|
230
|
+
// The catalog page. Static: no script, no network; links are relative, so the folder can be moved.
|
|
231
|
+
export function renderIndex(entries) {
|
|
232
|
+
const kinds = [...new Set(entries.map((e) => e.kind))].sort((a, b) => (KINDS[a] || a).localeCompare(KINDS[b] || b));
|
|
233
|
+
const section = (k) => {
|
|
234
|
+
const rows = entries.filter((e) => e.kind === k).sort((a, b) => String(b.createdAt).localeCompare(String(a.createdAt)));
|
|
235
|
+
return `<h2>${esc(KINDS[k] || k)} <small>${rows.length}</small></h2>\n<table><tr><th>Report</th><th>Scope</th><th>State</th><th>Made (local time)</th><th>Product at</th></tr>\n${rows.map((e) =>
|
|
236
|
+
`<tr><td><a href="${esc(e.file.split('/').map(encodeURIComponent).join('/'))}">${esc(path.posix.basename(e.file))}</a>${e.anonymous ? ' <span class="tag">anonymous</span>' : ''}</td><td>${esc(e.scope)}</td><td>${esc(e.state)}</td><td>${esc(madeAt(e.createdAt))}</td><td><code>${esc(e.productSha ? e.productSha.slice(0, 10) : '—')}</code> ${esc(e.productBranch || '')}</td></tr>`).join('\n')}\n</table>`;
|
|
237
|
+
};
|
|
238
|
+
return `<!doctype html>
|
|
239
|
+
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
|
|
240
|
+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'">
|
|
241
|
+
<title>Saved reports</title>
|
|
242
|
+
<style>
|
|
243
|
+
:root{--bg:#fbfbfd;--ink:#1d2333;--muted:#667089;--line:#e3e6ee;--tag:#eef1f8;--link:#2457c5}
|
|
244
|
+
@media (prefers-color-scheme: dark){:root{--bg:#0d111c;--ink:#e6eaf4;--muted:#8d97ad;--line:#232a3b;--tag:#1b2233;--link:#8fb6ff}}
|
|
245
|
+
body{margin:0;padding:24px 16px;background:var(--bg);color:var(--ink);font:14px/1.5 system-ui,-apple-system,"Segoe UI",sans-serif}
|
|
246
|
+
main{max-width:1100px;margin:0 auto}h1{font-size:20px;margin:0 0 4px}p{color:var(--muted);margin:0 0 18px}
|
|
247
|
+
h2{font-size:15px;margin:26px 0 8px}h2 small{color:var(--muted);font-weight:500}
|
|
248
|
+
table{border-collapse:collapse;width:100%;display:block;overflow-x:auto}th,td{text-align:left;padding:6px 10px;border-top:1px solid var(--line);white-space:nowrap}
|
|
249
|
+
th{color:var(--muted);font-weight:600;font-size:12px;border-top:0}a{color:var(--link)}
|
|
250
|
+
.tag{background:var(--tag);border-radius:4px;padding:1px 6px;font-size:12px;color:var(--muted)}code{font-size:12px}
|
|
251
|
+
</style></head><body><main>
|
|
252
|
+
<h1>Saved reports</h1>
|
|
253
|
+
<p>Each report shows the state of the work when it was made. They are kept on this machine only and never committed. Run <code>yad reports list</code> to see which ones are stale.</p>
|
|
254
|
+
${entries.length ? kinds.map(section).join('\n') : '<p>No reports saved yet.</p>'}
|
|
255
|
+
</main></body></html>
|
|
256
|
+
`;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function productAt(root, runner) {
|
|
260
|
+
const sha = git(runner, root, ['rev-parse', '--verify', '--quiet', 'HEAD^{commit}']);
|
|
261
|
+
const br = git(runner, root, ['rev-parse', '--abbrev-ref', 'HEAD']);
|
|
262
|
+
return { productSha: sha.ok && /^[0-9a-f]{40,64}$/.test(sha.out) ? sha.out : null, productBranch: br.ok && br.out !== 'HEAD' ? br.out : null };
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Save one report into the folder and add it to the catalog.
|
|
266
|
+
// → { file, dir, name, warnings: [] } | { problem }
|
|
267
|
+
// The report is written even when the catalog cannot be read: the person asked for the report, and
|
|
268
|
+
// the broken catalog is named in a warning, never overwritten.
|
|
269
|
+
export function saveReport(root, { kind, scope, state, ext, content, command = null, anonymous = false, at = new Date(), env = process.env, runner = spawnSync, lockWaitMs = 5000 } = {}) {
|
|
270
|
+
const { dir } = reportsDir(root, { env, runner });
|
|
271
|
+
const sub = path.join(dir, kind);
|
|
272
|
+
// A folder that cannot be made or written (a read-only parent, say) is a refusal, never a crash.
|
|
273
|
+
const cannot = (e) => ({ problem: `cannot save the report in ${dir} (${e.code || e.message}) — set ${REPORTS_ENV} to a folder you can write, or pass --out <file>` });
|
|
274
|
+
let file, name;
|
|
275
|
+
try {
|
|
276
|
+
const problem = ownDir(dir) || ownDir(sub);
|
|
277
|
+
if (problem) return { problem };
|
|
278
|
+
ensureIgnored(dir);
|
|
279
|
+
name = writeFresh(sub, reportName({ kind, scope, state, at, ext }), content);
|
|
280
|
+
file = path.join(sub, name);
|
|
281
|
+
} catch (e) { return cannot(e); }
|
|
282
|
+
const warnings = [];
|
|
283
|
+
try {
|
|
284
|
+
const done = withCatalogLock(dir, () => {
|
|
285
|
+
const cat = readCatalog(dir);
|
|
286
|
+
if (cat.problem) return cat;
|
|
287
|
+
const entry = { file: `${kind}/${name}`, kind, scope: String(scope ?? ''), state: String(state ?? ''), createdAt: at.toISOString(), ...productAt(root, runner), anonymous: !!anonymous, command };
|
|
288
|
+
const entries = [...cat.entries, entry];
|
|
289
|
+
writeJSON(path.join(dir, CATALOG_FILE), { version: CATALOG_VERSION, entries });
|
|
290
|
+
writeNew(path.join(dir, INDEX_FILE), renderIndex(entries));
|
|
291
|
+
return {};
|
|
292
|
+
}, { waitMs: lockWaitMs });
|
|
293
|
+
if (done.problem) warnings.push(done.held ? `the report was saved at ${file}, but not added to the catalog: ${done.problem}. It is in the folder; open it by that path` : done.problem);
|
|
294
|
+
} catch (e) { warnings.push(`the report was saved, but the catalog was not updated (${e.code || e.message})`); }
|
|
295
|
+
return { file, dir, name, warnings };
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Is a report stale? → 'fresh' | 'stale' | 'unknown'. Stale: the Product's epics/ or .sdlc/ changed
|
|
299
|
+
// between the commit the report was made at and the Product's HEAD now. Changes not yet committed are
|
|
300
|
+
// not counted — the record is what is committed.
|
|
301
|
+
export function freshness(root, sha, { runner = spawnSync } = {}) {
|
|
302
|
+
if (!sha || !/^[0-9a-f]{40,64}$/.test(sha)) return 'unknown';
|
|
303
|
+
const r = git(runner, root, ['diff', '--quiet', sha, 'HEAD', '--', 'epics', '.sdlc']);
|
|
304
|
+
return r.code === 0 ? 'fresh' : r.code === 1 ? 'stale' : 'unknown';
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// Every catalog entry, newest first, with `n` (1 = newest), whether its file is still there, and its freshness.
|
|
308
|
+
export function listReports(root, { env = process.env, runner = spawnSync } = {}) {
|
|
309
|
+
const { dir, via } = reportsDir(root, { env, runner });
|
|
310
|
+
if (!fs.existsSync(dir)) return { dir, via, entries: [] };
|
|
311
|
+
const linked = linkedDir(dir);
|
|
312
|
+
if (linked) return { dir, via, problem: linked };
|
|
313
|
+
const cat = readCatalog(dir);
|
|
314
|
+
if (cat.problem) return { dir, via, problem: cat.problem };
|
|
315
|
+
const seen = new Map(); // one git run per commit, however many reports were made at it
|
|
316
|
+
const fresh = (sha) => { if (!seen.has(sha)) seen.set(sha, freshness(root, sha, { runner })); return seen.get(sha); };
|
|
317
|
+
const entries = [...cat.entries]
|
|
318
|
+
.sort((a, b) => String(b.createdAt).localeCompare(String(a.createdAt)))
|
|
319
|
+
.map((e, i) => ({ n: i + 1, ...e, present: insideDir(dir, e.file) && fs.existsSync(path.join(dir, e.file)), freshness: fresh(e.productSha) }));
|
|
320
|
+
return { dir, via, entries };
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// A catalog path must be exactly `<kind>/<file name>`, with the kind folder a plain folder (not a link)
|
|
324
|
+
// inside the real reports folder: a hand-edited `../x`, `.gitignore` or a linked kind folder is never
|
|
325
|
+
// opened or deleted.
|
|
326
|
+
const NAME_RE = /^[a-z0-9][a-z0-9-]*\.[a-z0-9]{1,8}$/;
|
|
327
|
+
function insideDir(dir, rel) {
|
|
328
|
+
if (typeof rel !== 'string') return false;
|
|
329
|
+
const parts = rel.split('/');
|
|
330
|
+
if (parts.length !== 2 || !Object.hasOwn(KINDS, parts[0]) || !NAME_RE.test(parts[1])) return false;
|
|
331
|
+
const sub = path.join(dir, parts[0]);
|
|
332
|
+
let st; try { st = fs.lstatSync(sub); } catch { return false; }
|
|
333
|
+
if (!st.isDirectory()) return false;
|
|
334
|
+
try { return fs.realpathSync(sub) === path.join(fs.realpathSync(dir), parts[0]); } catch { return false; }
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// The folder itself must be a plain folder: a link there is said, never followed for a delete.
|
|
338
|
+
function linkedDir(dir) {
|
|
339
|
+
let st; try { st = fs.lstatSync(dir); } catch { return null; }
|
|
340
|
+
return st.isDirectory() ? null : `${dir} is not a plain folder (a link or a file) — yad does not read or change it; set ${REPORTS_ENV} to a real folder`;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// The entries `prune` would remove: older than `days`, or whose file is gone.
|
|
344
|
+
// `days: null` drops only entries whose file is missing or not a report path — it deletes no file.
|
|
345
|
+
export function pruneReports(root, { days = null, apply = false, now = Date.now(), env = process.env, runner = spawnSync } = {}) {
|
|
346
|
+
const { dir } = reportsDir(root, { env, runner });
|
|
347
|
+
if (!fs.existsSync(dir)) return { dir, removed: [], kept: 0 };
|
|
348
|
+
const linked = linkedDir(dir);
|
|
349
|
+
if (linked) return { dir, problem: linked };
|
|
350
|
+
const plan = () => {
|
|
351
|
+
const cat = readCatalog(dir);
|
|
352
|
+
if (cat.problem) return { problem: cat.problem };
|
|
353
|
+
const cut = now - days * 864e5;
|
|
354
|
+
const old = (e) => { if (days === null) return false; const t = Date.parse(e.createdAt); return Number.isFinite(t) && t < cut; };
|
|
355
|
+
// The reason is decided BEFORE anything is deleted.
|
|
356
|
+
const marked = cat.entries.map((e) => ({ e, reason: !insideDir(dir, e.file) ? 'outside' : !fs.existsSync(path.join(dir, e.file)) ? 'missing' : old(e) ? 'old' : null }));
|
|
357
|
+
return { removed: marked.filter((m) => m.reason), kept: marked.filter((m) => !m.reason).map((m) => m.e) };
|
|
358
|
+
};
|
|
359
|
+
const act = () => {
|
|
360
|
+
const p = plan();
|
|
361
|
+
if (p.problem || !apply || !p.removed.length) return p;
|
|
362
|
+
for (const { e, reason } of p.removed) {
|
|
363
|
+
if (reason !== 'old') continue; // only a file proved inside the folder is deleted
|
|
364
|
+
const f = path.join(dir, e.file);
|
|
365
|
+
let st = null; try { st = fs.lstatSync(f); } catch { /* already gone */ }
|
|
366
|
+
if (st && (st.isFile() || st.isSymbolicLink())) fs.rmSync(f, { force: true });
|
|
367
|
+
// A report's own side file (the progress map's digest, E181) goes with it.
|
|
368
|
+
const side = `${f}${SIDE_SUFFIX}`;
|
|
369
|
+
let sst = null; try { sst = fs.lstatSync(side); } catch { /* none */ }
|
|
370
|
+
if (sst && (sst.isFile() || sst.isSymbolicLink())) fs.rmSync(side, { force: true });
|
|
371
|
+
}
|
|
372
|
+
writeJSON(path.join(dir, CATALOG_FILE), { version: CATALOG_VERSION, entries: p.kept });
|
|
373
|
+
writeNew(path.join(dir, INDEX_FILE), renderIndex(p.kept));
|
|
374
|
+
return p;
|
|
375
|
+
};
|
|
376
|
+
let r;
|
|
377
|
+
try { r = apply ? withCatalogLock(dir, act) : plan(); } catch (e) { return { dir, problem: `cannot change ${dir} (${e.code || e.message})` }; }
|
|
378
|
+
if (r.problem) return { dir, problem: r.problem };
|
|
379
|
+
return { dir, removed: r.removed.map(({ e, reason }) => ({ file: e.file, createdAt: e.createdAt, reason })), kept: r.kept.length };
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// A command's report: to `out` when the person named a file (exactly as before E180, no catalog), else
|
|
383
|
+
// saved into the reports folder. → { file, warnings } | { problem }
|
|
384
|
+
export function writeOrSave(root, { out = null, ...rest }) {
|
|
385
|
+
if (out) {
|
|
386
|
+
fs.mkdirSync(path.dirname(path.resolve(out)), { recursive: true });
|
|
387
|
+
fs.writeFileSync(out, rest.content);
|
|
388
|
+
return { file: out, warnings: [], own: true };
|
|
389
|
+
}
|
|
390
|
+
return saveReport(root, rest);
|
|
391
|
+
}
|
package/cli/reports.mjs
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// `yad reports list | open | prune` (E180) — the saved reports in the local reports folder.
|
|
2
|
+
// See reports-dir.mjs for where the folder is and how a file is named.
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { spawnSync } from 'node:child_process';
|
|
5
|
+
import { c, log, ok, info, warn, refuse, emitJSON, forTerminal } from './lib.mjs';
|
|
6
|
+
import { listReports, pruneReports, REPORTS_ENV } from './reports-dir.mjs';
|
|
7
|
+
import { openUrl } from './report.mjs';
|
|
8
|
+
|
|
9
|
+
export const REPORTS_USAGE = 'usage: yad reports [list] [--json] · yad reports open <n|file> · yad reports prune --older-than <days> | --missing [--apply] [--json]';
|
|
10
|
+
|
|
11
|
+
const FRESH = { fresh: 'fresh', stale: 'stale — the Product changed since', unknown: 'unknown' };
|
|
12
|
+
|
|
13
|
+
export async function runReports(root, { action = 'list', args = [], olderThan = null, missing = false, apply = false, json = false, env = process.env, runner = spawnSync, opener = openUrl } = {}) {
|
|
14
|
+
if (action === 'list') {
|
|
15
|
+
if (args.length) return refuse(`yad reports list takes no words (got: ${args.map(forTerminal).join(' ')})`, REPORTS_USAGE, { json });
|
|
16
|
+
const r = listReports(root, { env, runner });
|
|
17
|
+
if (r.problem) return refuse(r.problem, null, { json });
|
|
18
|
+
if (json) return emitJSON({ dir: r.dir, via: r.via, entries: r.entries });
|
|
19
|
+
log(c.bold('\nyad reports'));
|
|
20
|
+
info(`folder: ${forTerminal(r.dir)}${r.via === 'env' ? ` (from ${REPORTS_ENV})` : ''} — on this machine only, never committed`);
|
|
21
|
+
if (!r.entries.length) { info('no reports saved yet'); return r; }
|
|
22
|
+
for (const e of r.entries) {
|
|
23
|
+
const mark = !e.present ? c.red('missing') : e.freshness === 'stale' ? c.yellow(FRESH.stale) : e.freshness === 'fresh' ? c.green(FRESH.fresh) : c.dim(FRESH.unknown);
|
|
24
|
+
log(` ${String(e.n).padStart(3)} ${forTerminal(path.posix.basename(e.file))} ${mark}${e.anonymous ? c.dim(' · anonymous') : ''}`);
|
|
25
|
+
}
|
|
26
|
+
info('open one: yad reports open <n> · the catalog page: index.html in the folder');
|
|
27
|
+
return r;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (action === 'open') {
|
|
31
|
+
if (args.length !== 1) return refuse('name one report: its number from `yad reports list`, or its file name', REPORTS_USAGE, { json });
|
|
32
|
+
const r = listReports(root, { env, runner });
|
|
33
|
+
if (r.problem) return refuse(r.problem, null, { json });
|
|
34
|
+
const want = String(args[0]);
|
|
35
|
+
const hit = /^\d+$/.test(want) ? r.entries.find((e) => e.n === Number(want)) : r.entries.find((e) => e.file === want || path.posix.basename(e.file) === want);
|
|
36
|
+
if (!hit) return refuse(`no saved report ${forTerminal(want)}`, 'see them with: yad reports list', { json });
|
|
37
|
+
if (!hit.present) return refuse(`${forTerminal(hit.file)} is in the catalog but its file is gone`, 'drop it from the catalog with: yad reports prune --missing --apply (it deletes no report)', { json });
|
|
38
|
+
const file = path.join(r.dir, hit.file);
|
|
39
|
+
const opened = opener(file);
|
|
40
|
+
if (json) return emitJSON({ file, opened, freshness: hit.freshness });
|
|
41
|
+
if (opened) ok(`opened ${forTerminal(file)}`);
|
|
42
|
+
else info(`no browser opener was found here (open, xdg-open or explorer) — open ${forTerminal(file)} yourself`);
|
|
43
|
+
if (hit.freshness === 'stale') warn('this report is stale: the Product changed since it was made — run the command again for a current one');
|
|
44
|
+
return { file, opened };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (action === 'prune') {
|
|
48
|
+
if (args.length) return refuse(`yad reports prune takes no words (got: ${args.map(forTerminal).join(' ')})`, REPORTS_USAGE, { json });
|
|
49
|
+
if (missing && olderThan !== null) return refuse('pass --older-than <days> or --missing, not both', REPORTS_USAGE, { json });
|
|
50
|
+
const days = missing ? null : Number(olderThan);
|
|
51
|
+
if (!missing && (olderThan === null || olderThan === true || !Number.isInteger(days) || days < 0)) return refuse('say how old: --older-than <days> (a whole number, 0 or more), or --missing to drop only entries whose file is gone', REPORTS_USAGE, { json });
|
|
52
|
+
const r = pruneReports(root, { days, apply, env, runner });
|
|
53
|
+
if (r.problem) return refuse(r.problem, null, { json });
|
|
54
|
+
if (json) return emitJSON({ dir: r.dir, applied: !!apply, removed: r.removed, kept: r.kept });
|
|
55
|
+
log(c.bold(`\nyad reports prune${apply ? '' : ' (dry run)'}`));
|
|
56
|
+
if (!r.removed.length) { info(`${missing ? 'no entry is missing its file' : `nothing older than ${days} day(s)`} — ${r.kept} kept`); return r; }
|
|
57
|
+
for (const e of r.removed) log(` ${apply ? c.red('removed') : 'would remove'} ${forTerminal(e.file)}${e.reason === 'missing' ? c.dim(' (file already gone)') : e.reason === 'outside' ? c.dim(' (not a report path inside the folder — only dropped from the catalog)') : ''}`);
|
|
58
|
+
if (apply) ok(`removed ${r.removed.length}, kept ${r.kept}`);
|
|
59
|
+
else info(`nothing was deleted — add --apply to remove these ${r.removed.length}`);
|
|
60
|
+
return r;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return refuse(`unknown action: yad reports ${forTerminal(action)}`, REPORTS_USAGE, { json });
|
|
64
|
+
}
|
|
65
|
+
|
package/cli/run-checks.mjs
CHANGED
|
@@ -450,8 +450,9 @@ export async function runChecks(dir, opts = {}) {
|
|
|
450
450
|
{ name: 'pr-title', script: 'pr-title.sh', args: ['--profile', profile, title], needs: titleNeeds },
|
|
451
451
|
{ name: 'pr-template', script: 'pr-template.sh', args: ['--profile', profile, bodyFile], needs: bodyNeeds },
|
|
452
452
|
{ name: 'risk-map', script: 'risk-map-check.sh', args: [base] },
|
|
453
|
-
|
|
454
|
-
{ name: '
|
|
453
|
+
// The base, as CI passes it: a Unity project skips both, unless its base has a package.json (#496).
|
|
454
|
+
{ name: 'install-deps', script: 'install-deps.sh', args: [base], build: true },
|
|
455
|
+
{ name: 'build/test/lint', script: 'build-test-lint.sh', args: [base], build: true, after: 'install-deps' },
|
|
455
456
|
{ name: 'contract-check', script: 'contract-check.sh', args: [base] },
|
|
456
457
|
{ name: 'lineage-check', script: 'lineage-check.sh', args: [base] },
|
|
457
458
|
{ name: 'epic-open', script: 'epic-open.sh', args: [base] },
|
|
@@ -539,6 +540,8 @@ export async function runChecks(dir, opts = {}) {
|
|
|
539
540
|
} else {
|
|
540
541
|
r.exit = p.status;
|
|
541
542
|
r.status = p.status === 0 ? 'pass' : 'fail';
|
|
543
|
+
// A gate that passed by skipping says so (#496): a skipped gate is not a pass.
|
|
544
|
+
if (r.status === 'pass' && (g.name === 'install-deps' || g.name === 'build/test/lint') && /^SKIP \[(install-deps|build\/test\/lint)\]: a Unity project/m.test(r.output)) { r.status = 'skip'; r.reason = 'a Unity project: build and test it with Unity\'s own CI'; }
|
|
542
545
|
}
|
|
543
546
|
if (g.name === 'pr-title' && titleNote) info(titleNote);
|
|
544
547
|
if (g.name === 'pr-template' && platform === 'gitlab') {
|
package/cli/scan.mjs
CHANGED
|
@@ -144,7 +144,7 @@ function droppedFrom(stdout, confidential) {
|
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
// Map(title → id), across open and closed. Null if unread. GitHub assigns by number, GitLab by id.
|
|
147
|
-
function readMilestones(t, runner) {
|
|
147
|
+
export function readMilestones(t, runner) {
|
|
148
148
|
const gh = t.platform === 'github';
|
|
149
149
|
const at = gh ? `repos/${t.repo}/milestones?state=all&per_page=${PAGE}` : `projects/${encodeURIComponent(t.repo)}/milestones?per_page=${PAGE}`;
|
|
150
150
|
const map = new Map();
|
package/cli/setup.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
import { err } from './errors.mjs';
|
|
11
11
|
import { VERSION, IDE_TARGETS, IDE_AGENTS, DEFAULT_IDE_TARGETS, PROJECT_FILES, DESIGN_TOOLS, DESIGN_PRIMARY, TESTING_TOOLS, TESTING_PRIMARY, LEARNING_TOOLS, LEARNING_PRIMARY , productConfigPath } from './manifest.mjs';
|
|
12
12
|
import {
|
|
13
|
-
moduleActions, repoActions, productActions, hookActions, agentFileActions, agentGuardActions, allowListActions, captureHookActions, legacyHookScriptActions, gitHookActions, gitHookState, gitHookAdvice,
|
|
13
|
+
moduleActions, repoActions, productActions, hookActions, agentFileActions, agentGuardActions, allowListActions, captureHookActions, activityHookActions, legacyHookScriptActions, gitHookActions, gitHookState, gitHookAdvice,
|
|
14
14
|
legacyModuleActions, removedModuleActions, legacyRepoActions, legacyProductActions, withoutKeptRenames,
|
|
15
15
|
safeIdeTargetsFor, detectedIdeTargetStateFor, recordManagedWrites, canonicalIdeTargets,
|
|
16
16
|
} from './plan.mjs';
|
|
@@ -20,6 +20,8 @@ import { loadSkillBindings, stepSkills } from './epic-state.mjs';
|
|
|
20
20
|
import { offerToolbox, REPOMIX_VERSION } from './toolbox.mjs';
|
|
21
21
|
import { readAllowList } from './agent-rules.mjs';
|
|
22
22
|
import { PREAPPROVED } from './agent-guard.mjs';
|
|
23
|
+
import { repoGitUrl } from './protection.mjs';
|
|
24
|
+
import { hostFromGitUrl, plainHost } from './platform.mjs';
|
|
23
25
|
|
|
24
26
|
// Parse a comma/space separated list into a clean, deduped array of trimmed tokens.
|
|
25
27
|
export function parseList(s) {
|
|
@@ -626,15 +628,31 @@ export async function runSetup(root, opts = {}) {
|
|
|
626
628
|
// Strict read for the same reason as the reconfigure write above: a corrupt Product must abort, never
|
|
627
629
|
// fail-open to `{}` and get rewritten with everything else stripped on a plain re-run.
|
|
628
630
|
const cur = readJSONStrict(productPath, {}) || {};
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
631
|
+
// A git_url that names only a host is no repo (#513): replaced too — but only by an origin that names one
|
|
632
|
+
// on the SAME host. These settings are shared and committed: a person's own SSH alias (`gitlab-work`) or a
|
|
633
|
+
// fork on another host would send everyone, and CI, to the wrong place (#513 review 1).
|
|
634
|
+
const hostOnly = cur.platform && typeof cur.git_url === 'string' && cur.git_url.trim() && !repoGitUrl(cur.git_url);
|
|
635
|
+
const originUrl = (cur.platform && (!cur.git_url || hostOnly)) ? ((run('git', ['remote', 'get-url', 'origin'], { cwd: root }).stdout || '').trim() || null) : null;
|
|
636
|
+
// A value with no readable host (`gitlab.example.com`, no scheme) has no host to protect: any origin that
|
|
637
|
+
// names a repo replaces it (#513 review 2).
|
|
638
|
+
// Only an origin on a real host: a `file://` or local-path origin is no platform address (review 3).
|
|
639
|
+
const setHost = hostOnly ? plainHost(hostFromGitUrl(cur.git_url)) : null;
|
|
640
|
+
const originHost = originUrl ? plainHost(hostFromGitUrl(originUrl)) : null;
|
|
641
|
+
const fits = !!originUrl && !!repoGitUrl(originUrl) && !!originHost && (!setHost || originHost === setHost);
|
|
642
|
+
const backfillUrl = originUrl && (!hostOnly || fits) ? originUrl : null;
|
|
643
|
+
if (hostOnly && !backfillUrl) {
|
|
644
|
+
const why = !originUrl ? 'this clone has no origin remote'
|
|
645
|
+
: !repoGitUrl(originUrl) ? 'origin names no repo either'
|
|
646
|
+
: !originHost ? 'origin is not on a platform host'
|
|
647
|
+
: 'origin is on another host';
|
|
648
|
+
info(`the Product's git_url names no repo, and ${why} — left as it is: set git_url to the Product's full address`);
|
|
649
|
+
}
|
|
632
650
|
const mode = setupModeFields(root, cur, solo, opts);
|
|
633
651
|
const modeMoved = Object.keys(mode).some((k) => JSON.stringify(cur[k]) !== JSON.stringify(mode[k]));
|
|
634
652
|
if (modeMoved || JSON.stringify(cur.profile || {}) !== JSON.stringify({ codebase, repo_layout, team_size }) || backfillUrl) {
|
|
635
653
|
writeProductConfig(root, { ...cur, ...(backfillUrl ? { git_url: backfillUrl } : {}), ...mode, profile: { codebase, repo_layout, team_size } });
|
|
636
654
|
if (mode.mode_set) info(`mode: ${mode.mode_set.from} → ${mode.mode_set.to} (recorded as mode_set)`);
|
|
637
|
-
if (backfillUrl) info(`backfilled the Product's git_url from origin: ${backfillUrl}`);
|
|
655
|
+
if (backfillUrl) info(hostOnly ? `replaced the Product's git_url, which named no repo, with origin: ${backfillUrl}` : `backfilled the Product's git_url from origin: ${backfillUrl}`);
|
|
638
656
|
else info(`recorded profile: ${solo ? 'solo' : `team(${team_size})`}, ${codebase}, ${repo_layout}`);
|
|
639
657
|
}
|
|
640
658
|
}
|
|
@@ -859,6 +877,13 @@ export async function runSetup(root, opts = {}) {
|
|
|
859
877
|
applyActions(captureWiring, { force: true });
|
|
860
878
|
wired.push(...captureWiring);
|
|
861
879
|
}
|
|
880
|
+
// E178: the live activity record for `yad brain view --live` — only when the config says `"activity": true`.
|
|
881
|
+
const activityWiring = activityHookActions(root, ideTargets);
|
|
882
|
+
if (activityWiring.length) {
|
|
883
|
+
log(` ${c.bold('product')} ${c.dim('(activity record)')}`);
|
|
884
|
+
applyActions(activityWiring, { force: true });
|
|
885
|
+
wired.push(...activityWiring);
|
|
886
|
+
}
|
|
862
887
|
// E158: the rules block in AGENTS.md (and CLAUDE.md importing it), which an AI agent reads first. The team's
|
|
863
888
|
// own text in these files is kept; only the lines between yad's markers are written.
|
|
864
889
|
const agentFiles = agentFileActions(root, ideTargets);
|