agjan 0.0.19 → 0.0.21
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/dist/adapters/claude-code.js +9 -3
- package/dist/auto.js +4 -0
- package/dist/baseline.js +11 -8
- package/dist/cli.js +8 -0
- package/dist/commands/check.js +65 -13
- package/dist/commands/gates.js +9 -1
- package/dist/commands/lint.js +16 -5
- package/dist/commands/log.js +1 -1
- package/dist/commands/new.js +4 -3
- package/dist/commands/setup.js +91 -81
- package/dist/commands/skill.js +22 -0
- package/dist/commands/summary.js +37 -0
- package/dist/config.js +24 -0
- package/dist/fix.js +13 -10
- package/dist/git.js +57 -9
- package/dist/launcher.js +9 -3
- package/dist/progress-view.js +36 -23
- package/dist/progress.js +103 -38
- package/dist/qa.js +10 -5
- package/dist/review-policy.js +4 -1
- package/dist/review.js +82 -35
- package/dist/schema.js +85 -0
- package/dist/scope.js +12 -4
- package/dist/story.js +110 -0
- package/dist/tests-map.js +17 -11
- package/docs/guide.md +52 -7
- package/kit/domains/btp/domain.json +2 -2
- package/kit/hooks/guard.mjs +53 -9
- package/kit/skills/agjan-build/SKILL.md +19 -7
- package/kit/skills/agjan-design/SKILL.md +20 -1
- package/kit/skills/agjan-fix/SKILL.md +1 -1
- package/kit/skills/agjan-spec/SKILL.md +9 -3
- package/kit/skills/agjan-spec/references/elicitation.md +135 -0
- package/kit/skills/agjan-verify/SKILL.md +9 -1
- package/kit/skills/btp-architect/SKILL.md +7 -2
- package/kit/skills/btp-architect/references/deployment.md +43 -0
- package/kit/skills/btp-architect/references/security.md +59 -4
- package/kit/skills/cap-developer/SKILL.md +19 -7
- package/kit/skills/cap-developer/references/agents.md +90 -0
- package/kit/skills/cap-developer/references/handlers.md +88 -9
- package/kit/skills/cap-developer/references/modeling.md +41 -0
- package/kit/skills/cap-developer/references/project-setup.md +57 -7
- package/kit/skills/cap-developer/references/services.md +172 -7
- package/kit/skills/cap-developer/references/testing.md +79 -6
- package/kit/skills/cap-developer/references/typescript.md +8 -7
- package/kit/skills/cap-developer/references/validation-security.md +74 -2
- package/kit/skills/fiori-developer/SKILL.md +21 -1
- package/kit/skills/fiori-developer/references/accessibility.md +65 -0
- package/kit/skills/fiori-developer/references/app-setup.md +10 -3
- package/kit/skills/fiori-developer/references/elements-cookbook.md +71 -0
- package/kit/skills/fiori-developer/references/elements.md +82 -9
- package/kit/skills/fiori-developer/references/freestyle-ts.md +27 -0
- package/kit/skills/fiori-developer/references/testing.md +5 -0
- package/kit/skills/fiori-developer/references/ui5-basics.md +34 -1
- package/kit/skills/qa-tester/SKILL.md +11 -4
- package/kit/skills/qa-tester/references/techniques.md +123 -0
- package/kit/skills/solution-reviewer/SKILL.md +10 -0
- package/kit/skills/solution-reviewer/references/defects.md +154 -0
- package/kit/templates/agents-block.md +1 -1
- package/kit/templates/agjan-ci.yml +3 -0
- package/package.json +1 -1
- package/schemas/config.schema.json +1 -1
- package/schemas/reviews.schema.json +1 -1
package/dist/fix.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import { git, mergeBase, resolveBase } from './git.js';
|
|
3
|
+
import { git, mergeBase, paths, resolveBase } from './git.js';
|
|
4
4
|
import { FEATURES_DIR, latestReview, stillBlocked } from './feature.js';
|
|
5
5
|
import { treeHash } from './review.js';
|
|
6
6
|
import { matcher } from './scope.js';
|
|
@@ -53,21 +53,23 @@ export function fixRules(root, config) {
|
|
|
53
53
|
const newAllowed = matcher(fix.new_file_paths ?? Object.values(config.tests ?? {}).flat());
|
|
54
54
|
const protectedPaths = [...(fix.protected ?? []), ...(config.risk_paths ?? []), ...doNotTouch(root)];
|
|
55
55
|
const isProtected = matcher(protectedPaths);
|
|
56
|
+
// -z: NUL-separated and unquoted paths (`A\0path\0`, `added\tdeleted\tpath\0`).
|
|
56
57
|
const added = new Set();
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (status === 'A')
|
|
60
|
-
added.add(
|
|
58
|
+
const status = paths(git(root, ['diff', '--name-status', '--no-renames', '-z', from], { allowFail: true }));
|
|
59
|
+
for (let i = 0; i + 1 < status.length; i += 2) {
|
|
60
|
+
if (status[i] === 'A')
|
|
61
|
+
added.add(status[i + 1]);
|
|
61
62
|
}
|
|
62
63
|
const files = [];
|
|
63
|
-
for (const line of (git(root, ['diff', '--numstat', '--no-renames', from], { allowFail: true })
|
|
64
|
-
const [a, d,
|
|
64
|
+
for (const line of paths(git(root, ['diff', '--numstat', '--no-renames', '-z', from], { allowFail: true }))) {
|
|
65
|
+
const [a, d, ...name] = line.split('\t');
|
|
66
|
+
const file = name.join('\t');
|
|
65
67
|
if (own(file))
|
|
66
68
|
continue;
|
|
67
69
|
// Binary files show '-': they count as one changed line each way, never as zero.
|
|
68
70
|
files.push({ path: file, added: a === '-' ? 1 : Number(a), deleted: d === '-' ? 1 : Number(d), isNew: added.has(file) });
|
|
69
71
|
}
|
|
70
|
-
for (const file of git(root, ['ls-files', '--others', '--exclude-standard'
|
|
72
|
+
for (const file of paths(git(root, ['ls-files', '--others', '--exclude-standard', '-z']))) {
|
|
71
73
|
if (own(file))
|
|
72
74
|
continue;
|
|
73
75
|
files.push({ path: file, added: lineCount(root, file), deleted: 0, isNew: true });
|
|
@@ -104,13 +106,14 @@ export function fixRules(root, config) {
|
|
|
104
106
|
* The latest review of a fix or map run, if it passed and saw exactly the current
|
|
105
107
|
* change; otherwise the reason why not.
|
|
106
108
|
*/
|
|
107
|
-
export function freshReview(root, config, unit, step) {
|
|
109
|
+
export function freshReview(root, config, unit, step, memo) {
|
|
108
110
|
const record = latestReview(unit.reviews, [step]);
|
|
109
111
|
if (!record)
|
|
110
112
|
return { problem: `no ${step} review recorded` };
|
|
111
113
|
if (stillBlocked(unit, record))
|
|
112
114
|
return { record, problem: `the latest ${step} review ${record.id} is blocked` };
|
|
113
|
-
|
|
115
|
+
const tree = memo ? (memo.tree ??= treeHash(root, config)) : treeHash(root, config);
|
|
116
|
+
if (record.tree_hash !== tree) {
|
|
114
117
|
return { record, problem: `the latest ${step} review ${record.id} is stale: files changed after it` };
|
|
115
118
|
}
|
|
116
119
|
return { record };
|
package/dist/git.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { lstatSync, readlinkSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
2
4
|
import { AgjanError } from './errors.js';
|
|
3
|
-
|
|
5
|
+
/**
|
|
6
|
+
* The most output git may return. Node's default (1 MiB) is easily passed by a diff with a
|
|
7
|
+
* lockfile or by the history of a long-lived repository, and the command then fails.
|
|
8
|
+
*/
|
|
9
|
+
const MAX_OUTPUT = 512 * 1024 * 1024;
|
|
10
|
+
export function git(cwd, args, { allowFail = false, input } = {}) {
|
|
4
11
|
try {
|
|
5
|
-
return execFileSync('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
|
|
12
|
+
return execFileSync('git', args, { cwd, encoding: 'utf8', input, stdio: [input === undefined ? 'ignore' : 'pipe', 'pipe', 'pipe'], maxBuffer: MAX_OUTPUT });
|
|
6
13
|
}
|
|
7
14
|
catch (error) {
|
|
8
15
|
if (allowFail)
|
|
@@ -51,8 +58,13 @@ export function mergeBase(root, base) {
|
|
|
51
58
|
return null;
|
|
52
59
|
return git(root, ['merge-base', 'HEAD', base], { allowFail: true })?.trim() || null;
|
|
53
60
|
}
|
|
54
|
-
|
|
55
|
-
|
|
61
|
+
/**
|
|
62
|
+
* The paths git lists with `-z`: separated by NUL and never quoted. Without `-z` git quotes a
|
|
63
|
+
* path with non-ASCII characters, tabs or quotes ("srv/\303\274bersicht.js"), and such a path
|
|
64
|
+
* would not match a pattern or name a file.
|
|
65
|
+
*/
|
|
66
|
+
export function paths(out) {
|
|
67
|
+
return out ? out.split('\0').filter(Boolean) : [];
|
|
56
68
|
}
|
|
57
69
|
/**
|
|
58
70
|
* Files the operating system writes on its own (macOS Finder, Windows Explorer). They are
|
|
@@ -67,22 +79,58 @@ const osFile = (path) => OS_FILES.has(path.slice(path.lastIndexOf('/') + 1));
|
|
|
67
79
|
*/
|
|
68
80
|
export function changedFiles(root, base, { staged = false } = {}) {
|
|
69
81
|
if (staged)
|
|
70
|
-
return
|
|
82
|
+
return paths(git(root, ['diff', '--cached', '--name-only', '--no-renames', '-z'])).filter((f) => !osFile(f));
|
|
71
83
|
const from = mergeBase(root, base);
|
|
72
84
|
const files = new Set();
|
|
73
85
|
if (from) {
|
|
74
|
-
for (const f of
|
|
86
|
+
for (const f of paths(git(root, ['diff', '--name-only', '--no-renames', '-z', from])))
|
|
75
87
|
files.add(f);
|
|
76
88
|
}
|
|
77
89
|
else if (git(root, ['rev-parse', '--verify', '--quiet', 'HEAD'], { allowFail: true })) {
|
|
78
|
-
for (const f of
|
|
90
|
+
for (const f of paths(git(root, ['diff', '--name-only', '--no-renames', '-z', 'HEAD'])))
|
|
79
91
|
files.add(f);
|
|
80
92
|
}
|
|
81
93
|
else {
|
|
82
|
-
for (const f of
|
|
94
|
+
for (const f of paths(git(root, ['diff', '--cached', '--name-only', '--no-renames', '-z'])))
|
|
83
95
|
files.add(f);
|
|
84
96
|
}
|
|
85
|
-
for (const f of
|
|
97
|
+
for (const f of paths(git(root, ['ls-files', '--others', '--exclude-standard', '-z'])))
|
|
86
98
|
files.add(f);
|
|
87
99
|
return [...files].filter((f) => !osFile(f)).sort();
|
|
88
100
|
}
|
|
101
|
+
/** Paths per `git hash-object` call: short enough for any command line, Windows included. */
|
|
102
|
+
const HASH_BATCH = 200;
|
|
103
|
+
/**
|
|
104
|
+
* What each path holds now, as git would store it: the blob id after git's clean filters
|
|
105
|
+
* (line endings from `core.autocrlf` or `.gitattributes`, LFS and other filters), so a CRLF
|
|
106
|
+
* checkout on Windows and an LF checkout in CI give the same id for the same commit. A
|
|
107
|
+
* symbolic link is the blob of its target, as git stores it (Windows checks such a link out
|
|
108
|
+
* as a file holding the target); a folder (an untracked link to one, a nested repository)
|
|
109
|
+
* is only named. Paths that do not exist (deleted) are not in the map. Paths are relative
|
|
110
|
+
* to `root`, POSIX.
|
|
111
|
+
*/
|
|
112
|
+
export function contentIds(root, paths) {
|
|
113
|
+
const ids = new Map();
|
|
114
|
+
const files = [];
|
|
115
|
+
for (const path of paths) {
|
|
116
|
+
let stat;
|
|
117
|
+
try {
|
|
118
|
+
stat = lstatSync(join(root, path));
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (stat.isSymbolicLink())
|
|
124
|
+
ids.set(path, `blob:${git(root, ['hash-object', '--stdin'], { input: readlinkSync(join(root, path)) }).trim()}`);
|
|
125
|
+
else if (stat.isFile())
|
|
126
|
+
files.push(path);
|
|
127
|
+
else
|
|
128
|
+
ids.set(path, stat.isDirectory() ? '(folder)' : '(not a regular file)');
|
|
129
|
+
}
|
|
130
|
+
for (let i = 0; i < files.length; i += HASH_BATCH) {
|
|
131
|
+
const batch = files.slice(i, i + HASH_BATCH);
|
|
132
|
+
const out = git(root, ['hash-object', '--', ...batch]).split('\n').filter(Boolean);
|
|
133
|
+
batch.forEach((path, j) => ids.set(path, `blob:${out[j]}`));
|
|
134
|
+
}
|
|
135
|
+
return ids;
|
|
136
|
+
}
|
package/dist/launcher.js
CHANGED
|
@@ -11,6 +11,12 @@ import { askOnTerminal } from './terminal.js';
|
|
|
11
11
|
const GLOBAL_COMMANDS = new Set(['init', 'help', '--help', '-h', 'version', '--version', '-v']);
|
|
12
12
|
/** Set for the process the launcher starts, so that it never delegates again. */
|
|
13
13
|
const DELEGATED = 'AGJAN_DELEGATED';
|
|
14
|
+
/**
|
|
15
|
+
* `AGJAN_LAUNCHER=0` turns the launcher off: the agjan that was started runs the command
|
|
16
|
+
* itself. The CI workflow sets it, so `npx agjan@<version pinned on the base branch>` checks
|
|
17
|
+
* the pull request, not a version the pull request pins (design 4.1).
|
|
18
|
+
*/
|
|
19
|
+
export const LAUNCHER = 'AGJAN_LAUNCHER';
|
|
14
20
|
const OWN_PACKAGE = realpathSync(fileURLToPath(new URL('..', import.meta.url)));
|
|
15
21
|
/** The nearest folder up from `dir` with an agjan.config.json; null outside an agjan project. */
|
|
16
22
|
export function findProject(dir) {
|
|
@@ -38,13 +44,13 @@ function defaultDelegate(bin, args, env) {
|
|
|
38
44
|
* command runs in the agjan version the project pins (node_modules), so a project is
|
|
39
45
|
* never driven by whichever version happens to be installed globally. When the pinned
|
|
40
46
|
* version is not installed (a fresh clone), it is installed first, after asking
|
|
41
|
-
* (`--yes` as the first argument skips the question). Outside an agjan project,
|
|
42
|
-
*
|
|
47
|
+
* (`--yes` as the first argument skips the question). Outside an agjan project, in the
|
|
48
|
+
* project's own agjan, and with `AGJAN_LAUNCHER=0`, the command runs here.
|
|
43
49
|
*/
|
|
44
50
|
export async function launch(args, { cwd = process.cwd(), env = process.env, stderr = process.stderr, ask = askOnTerminal, install = installDependencies, delegate = defaultDelegate, } = {}) {
|
|
45
51
|
const yes = args[0] === '--yes' || args[0] === '-y';
|
|
46
52
|
const rest = yes ? args.slice(1) : args;
|
|
47
|
-
if (rest[0] === undefined || GLOBAL_COMMANDS.has(rest[0]) || env[DELEGATED])
|
|
53
|
+
if (rest[0] === undefined || GLOBAL_COMMANDS.has(rest[0]) || env[DELEGATED] || env[LAUNCHER] === '0')
|
|
48
54
|
return { run: rest };
|
|
49
55
|
const root = findProject(cwd);
|
|
50
56
|
if (!root)
|
package/dist/progress-view.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { readJson } from './json-file.js';
|
|
4
4
|
import { agentModel, loadConfig } from './config.js';
|
|
5
|
-
import { FEATURES_DIR, changedFeatures, listFeatures, loadFeature, stillBlocked } from './feature.js';
|
|
5
|
+
import { APPROVALS_FILE, FEATURES_DIR, changedFeatures, listFeatures, loadFeature, stillBlocked } from './feature.js';
|
|
6
6
|
import { readLog } from './log.js';
|
|
7
|
-
import { acceptanceState, buildProgress, verifyState } from './progress.js';
|
|
7
|
+
import { acceptanceState, buildProgress, headHistory, prefetchFiles, repoMemo, verifyState } from './progress.js';
|
|
8
8
|
import { reviewerFor, roundLimit } from './review-policy.js';
|
|
9
9
|
import { acTestFiles } from './tests-map.js';
|
|
10
10
|
import { acResults, loadResults } from './test-results.js';
|
|
11
11
|
import { freshReview } from './fix.js';
|
|
12
12
|
import { spans } from './commands/report.js';
|
|
13
|
+
import { REVIEW_MD, renderReviewMd } from './review.js';
|
|
13
14
|
/**
|
|
14
15
|
* Progress pages (design decision 66): what happened in each unit (feature, fix, map run),
|
|
15
|
-
* who worked on it, how the review loops went, and whose turn it is. agjan regenerates them
|
|
16
|
-
* after every event it records:
|
|
16
|
+
* who worked on it, how the review loops went, and whose turn it is. agjan regenerates them,
|
|
17
|
+
* and the unit's review.md, after every event it records:
|
|
17
18
|
* - docs/agjan/<unit>/progress.md: committed with the unit, visible in the pull request;
|
|
18
19
|
* - .agjan/progress.md and .agjan/progress.html: the project overview, local (not
|
|
19
20
|
* committed, so parallel branches do not conflict). The HTML is self-contained.
|
|
@@ -45,15 +46,11 @@ function readFileSyncSafe(file) {
|
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
/** Commits of the unit anywhere in the history: subjects starting with `<KEY>:` or `<KEY>-T<n>:`. */
|
|
48
|
-
function unitCommits(root, key) {
|
|
49
|
-
const log = git(root, ['log', '--format=%h%x09%cI%x09%s', 'HEAD'], { allowFail: true }) ?? '';
|
|
49
|
+
function unitCommits(root, key, memo) {
|
|
50
50
|
const pattern = new RegExp(`^${key}(-T[1-9][0-9]*)?:`);
|
|
51
|
-
return
|
|
52
|
-
.
|
|
53
|
-
.
|
|
54
|
-
.map((line) => line.split('\t'))
|
|
55
|
-
.filter(([, , subject]) => pattern.test(subject ?? ''))
|
|
56
|
-
.map(([sha, at, subject]) => ({ sha, at: iso(Date.parse(at)), subject }))
|
|
51
|
+
return headHistory(root, memo)
|
|
52
|
+
.filter((c) => pattern.test(c.subject))
|
|
53
|
+
.map((c) => ({ sha: c.short, at: iso(Date.parse(c.at)), subject: c.subject }))
|
|
57
54
|
.reverse();
|
|
58
55
|
}
|
|
59
56
|
/** Stage track and whose turn it is. */
|
|
@@ -92,10 +89,11 @@ function stageOf(ctx, unit, onBase, extra) {
|
|
|
92
89
|
// In Build a feature always has its tasks and a verify state.
|
|
93
90
|
const progress = extra.progress;
|
|
94
91
|
const verify = extra.verify;
|
|
95
|
-
|
|
96
|
-
const verified = progress.complete && progress.due.length === 0 && verify.state === 'current';
|
|
92
|
+
// Before the due reviews, which a merged feature does not need (they cost git calls).
|
|
97
93
|
if (onBase && progress.complete && verify.record && !stillBlocked(unit, verify.record))
|
|
98
94
|
return { names, at: 5, turn: 'merged', now: 'merged' };
|
|
95
|
+
const pending = unit.amendments.filter((a) => a.status === 'pending');
|
|
96
|
+
const verified = progress.complete && progress.due.length === 0 && verify.state === 'current';
|
|
99
97
|
if (verified) {
|
|
100
98
|
if (acceptanceState(ctx.root, ctx.config, unit, verify).state === 'accepted')
|
|
101
99
|
return { names, at: 5, turn: 'done', now: 'implemented, verified and accepted' };
|
|
@@ -139,17 +137,20 @@ export function finalSteps(root, unit, { manual = [], accepted = false } = {}) {
|
|
|
139
137
|
optional: [pr],
|
|
140
138
|
};
|
|
141
139
|
}
|
|
142
|
-
/**
|
|
143
|
-
|
|
140
|
+
/**
|
|
141
|
+
* The data of one unit for the progress pages. `memo` shares git's answers between the units
|
|
142
|
+
* of one run (projectModels); a single call makes its own.
|
|
143
|
+
*/
|
|
144
|
+
export function unitModel(ctx, slug, { onBase = false, now = Date.now(), memo = repoMemo() } = {}) {
|
|
144
145
|
const unit = loadFeature(ctx.root, slug);
|
|
145
146
|
const config = ctx.config;
|
|
146
147
|
const events = readLog(unit.dir);
|
|
147
148
|
const isFeature = unit.kind === 'feature';
|
|
148
|
-
const progress = isFeature && unit.tasks ? buildProgress(ctx.root, config, unit, { history: onBase }) : null;
|
|
149
|
-
const verify = isFeature ? verifyState(ctx.root, config, unit) : null;
|
|
150
|
-
const review = !isFeature ? freshReview(ctx.root, config, unit, unit.kind) : null;
|
|
149
|
+
const progress = isFeature && unit.tasks ? buildProgress(ctx.root, config, unit, { history: onBase, memo }) : null;
|
|
150
|
+
const verify = isFeature ? verifyState(ctx.root, config, unit, memo) : null;
|
|
151
|
+
const review = !isFeature ? freshReview(ctx.root, config, unit, unit.kind, memo) : null;
|
|
151
152
|
const stage = waitingFor(events, stageOf(ctx, unit, onBase, { progress, verify, review }));
|
|
152
|
-
const commits = unitCommits(ctx.root, unit.key);
|
|
153
|
+
const commits = unitCommits(ctx.root, unit.key, memo);
|
|
153
154
|
const times = [...events.map((e) => Date.parse(e.at_utc)), ...commits.map((c) => Date.parse(c.at))].filter(Number.isFinite);
|
|
154
155
|
const start = times.length ? Math.min(...times) : now;
|
|
155
156
|
const last = times.length ? Math.max(...times) : now;
|
|
@@ -205,7 +206,7 @@ export function unitModel(ctx, slug, { onBase = false, now = Date.now() } = {})
|
|
|
205
206
|
const automated = unit.spec.parsed.acs.filter((ac) => ac.verification !== 'manual');
|
|
206
207
|
const loaded = loadResults(ctx.root, config, areaNames);
|
|
207
208
|
const results = loaded.files.length ? acResults(loaded, unit.key) : null;
|
|
208
|
-
const tests = acTestFiles(ctx.root, config, areaNames, unit.key);
|
|
209
|
+
const tests = acTestFiles(ctx.root, config, areaNames, unit.key, memo);
|
|
209
210
|
acs = {
|
|
210
211
|
total: unit.spec.parsed.acs.length,
|
|
211
212
|
automated: automated.length,
|
|
@@ -269,6 +270,7 @@ export function unitModel(ctx, slug, { onBase = false, now = Date.now() } = {})
|
|
|
269
270
|
now: stage.now,
|
|
270
271
|
optional: stage.turn === 'done' ? finalSteps(ctx.root, unit, { accepted: true }).optional : [],
|
|
271
272
|
start: iso(start),
|
|
273
|
+
created: unit.approvals.feature.created_at_utc,
|
|
272
274
|
end: iso(end),
|
|
273
275
|
last: iso(last),
|
|
274
276
|
host,
|
|
@@ -299,10 +301,17 @@ export function unitModel(ctx, slug, { onBase = false, now = Date.now() } = {})
|
|
|
299
301
|
export function projectModels(ctx, { now = Date.now() } = {}) {
|
|
300
302
|
const changed = new Set(changedFeatures(ctx.root, ctx.config));
|
|
301
303
|
const all = listFeatures(ctx.root);
|
|
304
|
+
// One history and one batch of commit file lists for all units, not one git call per unit.
|
|
305
|
+
const memo = repoMemo();
|
|
306
|
+
const keys = all.map((slug) => readJson(join(ctx.root, FEATURES_DIR, slug, APPROVALS_FILE))?.feature?.key).filter((key) => typeof key === 'string');
|
|
307
|
+
if (keys.length) {
|
|
308
|
+
const task = new RegExp(`^(?:${keys.join('|')})-T[1-9][0-9]*:`);
|
|
309
|
+
prefetchFiles(ctx.root, headHistory(ctx.root, memo).filter((c) => task.test(c.subject)).map((c) => c.sha), memo);
|
|
310
|
+
}
|
|
302
311
|
const models = [];
|
|
303
312
|
for (const slug of all) {
|
|
304
313
|
try {
|
|
305
|
-
models.push(unitModel(ctx, slug, { onBase: !changed.has(slug), now }));
|
|
314
|
+
models.push(unitModel(ctx, slug, { onBase: !changed.has(slug), now, memo }));
|
|
306
315
|
}
|
|
307
316
|
catch {
|
|
308
317
|
// A damaged unit must not stop the pages; check reports it.
|
|
@@ -463,6 +472,10 @@ export function writeProgress(ctx, { only = null, now = Date.now() } = {}) {
|
|
|
463
472
|
continue;
|
|
464
473
|
const file = join(ctx.root, FEATURES_DIR, m.slug, PROGRESS_MD);
|
|
465
474
|
writeFileSync(file, unitMarkdown(m, { generatedAt }));
|
|
475
|
+
// review.md shows each finding's status, which accepting a finding changes too.
|
|
476
|
+
const unit = loadFeature(ctx.root, m.slug);
|
|
477
|
+
if (unit.reviews.records.length)
|
|
478
|
+
writeFileSync(join(unit.dir, REVIEW_MD), renderReviewMd(unit));
|
|
466
479
|
}
|
|
467
480
|
const dir = join(ctx.root, LOCAL_DIR);
|
|
468
481
|
if (!existsSync(dir))
|
package/dist/progress.js
CHANGED
|
@@ -1,8 +1,38 @@
|
|
|
1
|
-
import { git, mergeBase, resolveBase } from './git.js';
|
|
1
|
+
import { git, mergeBase, paths, resolveBase } from './git.js';
|
|
2
2
|
import { resolveArea } from './config.js';
|
|
3
3
|
import { matcher } from './scope.js';
|
|
4
4
|
import { latestReview, stillBlocked } from './feature.js';
|
|
5
|
-
import {
|
|
5
|
+
import { isRecord, treeHash } from './review.js';
|
|
6
|
+
export function repoMemo() {
|
|
7
|
+
return { files: new Map(), ancestry: new Map(), texts: new Map() };
|
|
8
|
+
}
|
|
9
|
+
/** The history of HEAD, newest first (once per memo). */
|
|
10
|
+
export function headHistory(root, memo) {
|
|
11
|
+
if (memo?.history)
|
|
12
|
+
return memo.history;
|
|
13
|
+
const out = git(root, ['log', '--format=%H%x09%h%x09%cI%x09%s', 'HEAD'], { allowFail: true }) ?? '';
|
|
14
|
+
const history = out.split('\n').filter(Boolean).map((line) => {
|
|
15
|
+
const [sha, short, at, ...subject] = line.split('\t');
|
|
16
|
+
return { sha, short, at, subject: subject.join('\t') };
|
|
17
|
+
});
|
|
18
|
+
if (memo)
|
|
19
|
+
memo.history = history;
|
|
20
|
+
return history;
|
|
21
|
+
}
|
|
22
|
+
/** Loads the files of many commits with one git call (`git show` in batches), into the memo. */
|
|
23
|
+
export function prefetchFiles(root, shas, memo) {
|
|
24
|
+
const wanted = [...new Set(shas)].filter((sha) => !memo.files.has(sha));
|
|
25
|
+
for (let i = 0; i < wanted.length; i += 200) {
|
|
26
|
+
const out = git(root, ['show', '--name-only', '-z', '--format=%x01%H', ...wanted.slice(i, i + 200)], { allowFail: true });
|
|
27
|
+
if (out === null)
|
|
28
|
+
return; // filesOf asks commit by commit
|
|
29
|
+
// Each commit: \x01<sha>\0, then its files, NUL-separated, the first after a newline.
|
|
30
|
+
for (const chunk of out.split('\x01').filter(Boolean)) {
|
|
31
|
+
const [sha, ...names] = chunk.split('\0');
|
|
32
|
+
memo.files.set(sha, names.map((n, j) => (j === 0 ? n.replace(/^\n/, '') : n)).filter(Boolean));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
6
36
|
/**
|
|
7
37
|
* Build progress, derived from commits (design 8.3): a task is done when a commit on
|
|
8
38
|
* the branch has a subject starting with `<KEY>-<task id>:`, for example `ORDF-T1: …`.
|
|
@@ -10,37 +40,57 @@ import { scriptOwned, treeHash } from './review.js';
|
|
|
10
40
|
* A commit that changes only agjan's records (reviews, log, progress) is not task work:
|
|
11
41
|
* it never makes a review due, as the reviews' tree hash does not see it either.
|
|
12
42
|
*/
|
|
13
|
-
export function taskCommits(root, config, feature, { history = false } = {}) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
43
|
+
export function taskCommits(root, config, feature, { history = false, memo } = {}) {
|
|
44
|
+
let commits;
|
|
45
|
+
if (history) {
|
|
46
|
+
commits = headHistory(root, memo);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
const from = mergeBase(root, resolveBase(root, config.git?.base));
|
|
50
|
+
const log = git(root, ['log', '--format=%H%x09%s', from ? `${from}..HEAD` : 'HEAD'], { allowFail: true }) ?? '';
|
|
51
|
+
commits = log.split('\n').filter(Boolean).map((line) => {
|
|
52
|
+
const [sha, ...subject] = line.split('\t');
|
|
53
|
+
return { sha, subject: subject.join('\t') };
|
|
54
|
+
});
|
|
55
|
+
}
|
|
17
56
|
const done = new Map();
|
|
18
57
|
const prefix = new RegExp(`^${feature.key}-(T[1-9][0-9]*):`);
|
|
19
|
-
const records = scriptOwned(feature.slug);
|
|
20
58
|
// git log lists newest first; keep the newest commit of each task.
|
|
21
|
-
for (const
|
|
22
|
-
const
|
|
23
|
-
const match = prefix.exec(subject ?? '');
|
|
59
|
+
for (const { sha, subject } of commits) {
|
|
60
|
+
const match = prefix.exec(subject);
|
|
24
61
|
if (!match || done.has(match[1]))
|
|
25
62
|
continue;
|
|
26
|
-
const files = filesOf(root, sha);
|
|
27
|
-
if (files.length && files.every((f) =>
|
|
63
|
+
const files = filesOf(root, sha, memo);
|
|
64
|
+
if (files.length && files.every((f) => isRecord(f) || f.startsWith('.agjan/')))
|
|
28
65
|
continue;
|
|
29
66
|
done.set(match[1], sha);
|
|
30
67
|
}
|
|
31
68
|
return done;
|
|
32
69
|
}
|
|
33
|
-
function filesOf(root, sha) {
|
|
34
|
-
|
|
70
|
+
function filesOf(root, sha, memo) {
|
|
71
|
+
const known = memo?.files.get(sha);
|
|
72
|
+
if (known)
|
|
73
|
+
return known;
|
|
74
|
+
const files = paths(git(root, ['show', '--name-only', '--format=', '-z', sha]));
|
|
75
|
+
memo?.files.set(sha, files);
|
|
76
|
+
return files;
|
|
35
77
|
}
|
|
36
|
-
function isAncestor(root, ancestor, descendant) {
|
|
78
|
+
function isAncestor(root, ancestor, descendant, memo) {
|
|
37
79
|
if (!ancestor || !descendant)
|
|
38
80
|
return false;
|
|
39
|
-
|
|
81
|
+
if (ancestor === descendant)
|
|
82
|
+
return true;
|
|
83
|
+
const key = `${ancestor}..${descendant}`;
|
|
84
|
+
const known = memo?.ancestry.get(key);
|
|
85
|
+
if (known !== undefined)
|
|
86
|
+
return known;
|
|
87
|
+
const answer = git(root, ['merge-base', '--is-ancestor', ancestor, descendant], { allowFail: true }) !== null;
|
|
88
|
+
memo?.ancestry.set(key, answer);
|
|
89
|
+
return answer;
|
|
40
90
|
}
|
|
41
91
|
/** A passing review of `step` that saw the given commit (its head contains the commit). */
|
|
42
|
-
function reviewedSince(root, feature, step, sha) {
|
|
43
|
-
return feature.reviews.records.some((r) => r.step === step && !stillBlocked(feature, r) && isAncestor(root, sha, r.head_commit));
|
|
92
|
+
function reviewedSince(root, feature, step, sha, memo) {
|
|
93
|
+
return feature.reviews.records.some((r) => r.step === step && !stillBlocked(feature, r) && isAncestor(root, sha, r.head_commit, memo));
|
|
44
94
|
}
|
|
45
95
|
/**
|
|
46
96
|
* Tasks with their state, the next task, and the build reviews that are due
|
|
@@ -48,46 +98,61 @@ function reviewedSince(root, feature, step, sha) {
|
|
|
48
98
|
* always per task for tasks whose commit touched a risk path.
|
|
49
99
|
*/
|
|
50
100
|
export function buildProgress(root, config, feature, options = {}) {
|
|
101
|
+
const { memo } = options;
|
|
51
102
|
const tasks = feature.tasks?.parsed.tasks ?? [];
|
|
52
103
|
const done = taskCommits(root, config, feature, options);
|
|
53
|
-
const isRisk = matcher(config.risk_paths ?? []);
|
|
54
104
|
const list = tasks.map((t) => ({
|
|
55
105
|
...t,
|
|
56
106
|
areaName: resolveArea(config, t.area ?? '')?.name ?? t.area,
|
|
57
107
|
commit: done.get(t.id) ?? null,
|
|
58
108
|
}));
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
109
|
+
const dueReviews = () => {
|
|
110
|
+
const isRisk = matcher(config.risk_paths ?? []);
|
|
111
|
+
const due = [];
|
|
112
|
+
const perTask = config.review?.build === 'task';
|
|
113
|
+
for (const task of list.filter((t) => t.commit)) {
|
|
114
|
+
const risky = filesOf(root, task.commit, memo).some(isRisk);
|
|
115
|
+
if ((perTask || risky) && !reviewedSince(root, feature, `build:${task.id}`, task.commit, memo)) {
|
|
116
|
+
due.push({ step: `build:${task.id}`, reason: risky ? 'touches a risk path' : 'review per task' });
|
|
117
|
+
}
|
|
65
118
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
119
|
+
if (!perTask) {
|
|
120
|
+
for (const area of [...new Set(list.map((t) => t.areaName))]) {
|
|
121
|
+
const areaTasks = list.filter((t) => t.areaName === area);
|
|
122
|
+
if (areaTasks.some((t) => !t.commit))
|
|
123
|
+
continue;
|
|
124
|
+
const last = areaTasks.map((t) => t.commit).find((sha) => areaTasks.every((o) => isAncestor(root, o.commit, sha, memo)));
|
|
125
|
+
if (!reviewedSince(root, feature, `build:${area}`, last, memo))
|
|
126
|
+
due.push({ step: `build:${area}`, reason: 'all tasks of the area are done' });
|
|
127
|
+
}
|
|
75
128
|
}
|
|
76
|
-
|
|
129
|
+
return due;
|
|
130
|
+
};
|
|
77
131
|
const next = list.find((t) => !t.commit) ?? null;
|
|
78
|
-
|
|
132
|
+
let due;
|
|
133
|
+
return {
|
|
134
|
+
tasks: list,
|
|
135
|
+
next,
|
|
136
|
+
complete: list.length > 0 && !next,
|
|
137
|
+
// Worked out when asked: a merged feature on the base branch never needs it.
|
|
138
|
+
get due() {
|
|
139
|
+
due ??= dueReviews();
|
|
140
|
+
return due;
|
|
141
|
+
},
|
|
142
|
+
};
|
|
79
143
|
}
|
|
80
144
|
/**
|
|
81
145
|
* The final verify review (design 8.4): `none`, `blocked`, `stale` (files changed after
|
|
82
146
|
* it) or `current`. Shared by `check --ci` and `status`.
|
|
83
147
|
*/
|
|
84
|
-
export function verifyState(root, config, feature) {
|
|
148
|
+
export function verifyState(root, config, feature, memo) {
|
|
85
149
|
const record = latestReview(feature.reviews, ['verify']);
|
|
86
150
|
if (!record)
|
|
87
151
|
return { state: 'none', record: null };
|
|
88
152
|
if (stillBlocked(feature, record))
|
|
89
153
|
return { state: 'blocked', record };
|
|
90
|
-
|
|
154
|
+
const tree = memo ? (memo.tree ??= treeHash(root, config)) : treeHash(root, config);
|
|
155
|
+
if (record.tree_hash !== tree)
|
|
91
156
|
return { state: 'stale', record };
|
|
92
157
|
return { state: 'current', record };
|
|
93
158
|
}
|
package/dist/qa.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import { existsSync,
|
|
2
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
+
import { contentIds } from './git.js';
|
|
4
5
|
import { latestReview, stillBlocked } from './feature.js';
|
|
5
6
|
/**
|
|
6
7
|
* The QA step (design decision 81): in Verify, the QA agent (`agjan-qa`, the qa-tester
|
|
@@ -38,12 +39,16 @@ function filesUnder(root, dir) {
|
|
|
38
39
|
export function qaTestFiles(root, slug) {
|
|
39
40
|
return qaDirs(slug).flatMap((dir) => filesUnder(root, dir)).sort();
|
|
40
41
|
}
|
|
41
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* Hash of the feature's QA tests as they are now: a change after QA makes it stale. The
|
|
44
|
+
* content as git stores it, so a CRLF checkout and CI agree (`contentIds`).
|
|
45
|
+
*/
|
|
42
46
|
export function qaTestsHash(root, slug) {
|
|
47
|
+
const files = qaTestFiles(root, slug);
|
|
48
|
+
const ids = contentIds(root, files);
|
|
43
49
|
const hash = createHash('sha256');
|
|
44
|
-
for (const file of
|
|
45
|
-
hash.update(file).update('\0').update(
|
|
46
|
-
}
|
|
50
|
+
for (const file of files)
|
|
51
|
+
hash.update(file).update('\0').update(ids.get(file) ?? 'deleted').update('\0');
|
|
47
52
|
return `sha256:${hash.digest('hex')}`;
|
|
48
53
|
}
|
|
49
54
|
/**
|
package/dist/review-policy.js
CHANGED
|
@@ -69,7 +69,10 @@ export function roundState(feature, config, step) {
|
|
|
69
69
|
const extra = extraRounds(feature, step);
|
|
70
70
|
const limit = roundLimit(config) + extra;
|
|
71
71
|
const round = last?.round ?? 0;
|
|
72
|
-
|
|
72
|
+
// Exhausted: still blocked, and the next round would pass the limit; a loop that an approval
|
|
73
|
+
// or a passing verify review closed starts again at round 1 (nextRound).
|
|
74
|
+
const next = nextRound(feature, step);
|
|
75
|
+
return { last, round, next, limit, extra, exhausted: stillBlocked(feature, last) && next > limit };
|
|
73
76
|
}
|
|
74
77
|
/**
|
|
75
78
|
* Rounds the user granted beyond the limit in the current correction loop of `step`
|