agjan 0.0.20 → 0.0.22

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.
Files changed (59) hide show
  1. package/README.md +2 -1
  2. package/dist/adapters/claude-code.js +9 -3
  3. package/dist/auto.js +4 -0
  4. package/dist/baseline.js +11 -8
  5. package/dist/commands/check.js +65 -13
  6. package/dist/commands/gates.js +9 -1
  7. package/dist/commands/lint.js +16 -5
  8. package/dist/commands/new.js +4 -3
  9. package/dist/commands/setup.js +91 -81
  10. package/dist/config.js +24 -0
  11. package/dist/fix.js +13 -10
  12. package/dist/git.js +57 -9
  13. package/dist/launcher.js +9 -3
  14. package/dist/progress-view.js +35 -23
  15. package/dist/progress.js +103 -38
  16. package/dist/qa.js +18 -9
  17. package/dist/review-policy.js +12 -4
  18. package/dist/review.js +82 -35
  19. package/dist/schema.js +85 -0
  20. package/dist/scope.js +12 -4
  21. package/dist/tests-map.js +17 -11
  22. package/docs/guide.md +46 -7
  23. package/kit/domains/btp/domain.json +2 -2
  24. package/kit/hooks/guard.mjs +53 -9
  25. package/kit/skills/agjan-ask/SKILL.md +69 -0
  26. package/kit/skills/agjan-ask/references/sources.md +45 -0
  27. package/kit/skills/agjan-design/SKILL.md +13 -0
  28. package/kit/skills/agjan-fix/SKILL.md +1 -1
  29. package/kit/skills/agjan-spec/SKILL.md +7 -1
  30. package/kit/skills/agjan-spec/references/elicitation.md +135 -0
  31. package/kit/skills/btp-architect/SKILL.md +8 -3
  32. package/kit/skills/btp-architect/references/deployment.md +43 -0
  33. package/kit/skills/btp-architect/references/security.md +59 -4
  34. package/kit/skills/cap-developer/SKILL.md +20 -8
  35. package/kit/skills/cap-developer/references/agents.md +90 -0
  36. package/kit/skills/cap-developer/references/handlers.md +88 -9
  37. package/kit/skills/cap-developer/references/modeling.md +41 -0
  38. package/kit/skills/cap-developer/references/project-setup.md +57 -7
  39. package/kit/skills/cap-developer/references/services.md +172 -7
  40. package/kit/skills/cap-developer/references/testing.md +79 -6
  41. package/kit/skills/cap-developer/references/typescript.md +8 -7
  42. package/kit/skills/cap-developer/references/validation-security.md +74 -2
  43. package/kit/skills/fiori-developer/SKILL.md +22 -2
  44. package/kit/skills/fiori-developer/references/accessibility.md +65 -0
  45. package/kit/skills/fiori-developer/references/app-setup.md +10 -3
  46. package/kit/skills/fiori-developer/references/elements-cookbook.md +71 -0
  47. package/kit/skills/fiori-developer/references/elements.md +82 -9
  48. package/kit/skills/fiori-developer/references/freestyle-ts.md +27 -0
  49. package/kit/skills/fiori-developer/references/testing.md +5 -0
  50. package/kit/skills/fiori-developer/references/ui5-basics.md +34 -1
  51. package/kit/skills/qa-tester/SKILL.md +11 -4
  52. package/kit/skills/qa-tester/references/techniques.md +123 -0
  53. package/kit/skills/solution-reviewer/SKILL.md +10 -0
  54. package/kit/skills/solution-reviewer/references/defects.md +154 -0
  55. package/kit/templates/agents-block.md +3 -2
  56. package/kit/templates/agjan-ci.yml +3 -0
  57. package/package.json +1 -1
  58. package/schemas/config.schema.json +1 -1
  59. package/schemas/reviews.schema.json +1 -1
package/README.md CHANGED
@@ -79,7 +79,8 @@ npx agjan approve spec design
79
79
  ```
80
80
 
81
81
  Continue with `/agjan-build` and `/agjan-verify`. Small changes: `/agjan-fix`. An
82
- existing application: `/agjan-map` once.
82
+ existing application: `/agjan-map` once. A general question about CAP, Fiori or BTP:
83
+ `/agjan-ask`.
83
84
 
84
85
  ## Documentation
85
86
 
@@ -15,9 +15,15 @@ const REVIEWERS = [
15
15
  { name: 'agjan-reviewer-deep', tier: 'deep' },
16
16
  ];
17
17
  const HUMAN_ONLY = ['approve', 'accept', 'reject', 'auto', 'models set'];
18
- /** Every way an agent's shell might start agjan. Indirect forms are stopped by the terminal check. */
19
- const LAUNCHERS = ['agjan', 'npx agjan', 'npx --no-install agjan', 'npx -y agjan', 'npm exec agjan', 'npm exec -- agjan'];
20
- export const DENY_RULES = HUMAN_ONLY.flatMap((cmd) => LAUNCHERS.map((l) => `Bash(${l} ${cmd}:*)`));
18
+ /** The agjan MCP server: Claude Code starts it for the reviewer and QA agents, never the main agent's shell. */
19
+ const AGENTS_ONLY = ['mcp'];
20
+ /**
21
+ * The usual ways an agent's shell starts agjan, the launcher's `--yes` / `-y` included. Rules
22
+ * match a prefix, so other forms (`npx agjan@<version>`, wrappers) are left to the guard hook,
23
+ * and without a terminal to the confirmation.
24
+ */
25
+ const LAUNCHERS = ['agjan', 'npx agjan', 'npx --no-install agjan', 'npx -y agjan', 'npm exec agjan', 'npm exec -- agjan', 'agjan --yes', 'agjan -y', 'npx agjan --yes', 'npx agjan -y'];
26
+ export const DENY_RULES = [...HUMAN_ONLY, ...AGENTS_ONLY].flatMap((cmd) => LAUNCHERS.map((l) => `Bash(${l} ${cmd}:*)`));
21
27
  /**
22
28
  * The guard as a PreToolUse hook. It also catches wrapped forms the prefix deny rules miss
23
29
  * (`sh -c "agjan approve …"`). If it cannot start (agjan not installed), Claude Code
package/dist/auto.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { existsSync, mkdirSync, rmSync } from 'node:fs';
2
2
  import { dirname, join } from 'node:path';
3
+ import { git } from './git.js';
3
4
  import { readJson, writeJson } from './json-file.js';
4
5
  /**
5
6
  * The personal auto mode default (decision 79): a git-ignored file in this checkout,
@@ -9,6 +10,9 @@ import { readJson, writeJson } from './json-file.js';
9
10
  */
10
11
  export const AUTO_DEFAULT_FILE = '.agjan/auto.json';
11
12
  export function readAutoDefault(root) {
13
+ // A committed file is not a person's default: it would apply to everyone (check reports it).
14
+ if (git(root, ['ls-files', '--', AUTO_DEFAULT_FILE], { allowFail: true })?.trim())
15
+ return null;
12
16
  const data = readJson(join(root, AUTO_DEFAULT_FILE));
13
17
  return data && typeof data.by === 'string' && typeof data.at_utc === 'string' ? { by: data.by, at_utc: data.at_utc } : null;
14
18
  }
package/dist/baseline.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { existsSync, mkdirSync, readFileSync } from 'node:fs';
2
2
  import { dirname, join } from 'node:path';
3
- import { createHash } from 'node:crypto';
4
- import { git } from './git.js';
3
+ import { contentIds, git } from './git.js';
5
4
  import { readJson, writeJson } from './json-file.js';
6
5
  import { headings } from './documents.js';
7
6
  import { matcher } from './scope.js';
@@ -26,15 +25,19 @@ export function projectProblems(root, config) {
26
25
  const present = new Set(headings(readFileSync(file, 'utf8')));
27
26
  return projectHeadings(config).filter((h) => !present.has(h)).map((h) => `${PROJECT_MD}: missing heading '## ${h}'`);
28
27
  }
29
- function fileHash(root, file) {
30
- return `sha256:${createHash('sha256').update(readFileSync(join(root, file))).digest('hex')}`;
31
- }
28
+ /**
29
+ * The watched files and their content as git stores it (`contentIds`): the same in a CRLF
30
+ * checkout and in CI, so a baseline refreshed on Windows is current in CI.
31
+ */
32
32
  export function watchedHashes(root, config) {
33
33
  const isWatched = matcher(config.watched ?? []);
34
+ const files = repoFiles(root).filter(isWatched).sort();
35
+ const ids = contentIds(root, files);
34
36
  const out = {};
35
- for (const file of repoFiles(root).filter(isWatched).sort()) {
36
- if (existsSync(join(root, file)))
37
- out[file] = fileHash(root, file);
37
+ for (const file of files) {
38
+ const id = ids.get(file);
39
+ if (id)
40
+ out[file] = id;
38
41
  }
39
42
  return out;
40
43
  }
@@ -1,9 +1,12 @@
1
- import { readFileSync, statSync } from 'node:fs';
1
+ import { existsSync, readFileSync, statSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { parseArgs } from 'node:util';
4
- import { git, changedFiles, mergeBase, resolveBase } from '../git.js';
5
- import { CONFIG_FILE, resolveArea } from '../config.js';
6
- import { FEATURES_DIR, changedFeatures, listFeatures, loadFeature } from '../feature.js';
4
+ import { git, changedFiles, mergeBase, paths, resolveBase } from '../git.js';
5
+ import { CONFIG_FILE, ciSettingsAt, resolveArea } from '../config.js';
6
+ import { APPROVALS_FILE, FEATURES_DIR, REVIEWS_FILE, changedFeatures, listFeatures, loadFeature } from '../feature.js';
7
+ import { loadSchema, validate } from '../schema.js';
8
+ import { REVIEW_MD, renderReviewMd } from '../review.js';
9
+ import { hashText } from '../hash.js';
7
10
  import { documentProblems, designProblems } from '../validate.js';
8
11
  import { allowedPatterns, matcher } from '../scope.js';
9
12
  import { acTestFiles } from '../tests-map.js';
@@ -111,8 +114,31 @@ function checkMap(report, root, config, run, level) {
111
114
  }
112
115
  return run;
113
116
  }
117
+ /** review.md is rendered from reviews.json (design 8.5); a hand edit, or an older agjan, leaves it behind. */
118
+ function checkReviewMd(report, unit) {
119
+ if (!unit.reviews.records.length)
120
+ return;
121
+ const file = join(unit.dir, REVIEW_MD);
122
+ const text = existsSync(file) ? readFileSync(file, 'utf8') : null;
123
+ if (text === null || hashText(text) !== hashText(renderReviewMd(unit))) {
124
+ report.warn(unit.slug, `${REVIEW_MD} does not match ${REVIEWS_FILE}; run: npx agjan progress`);
125
+ }
126
+ }
127
+ /**
128
+ * The unit's records against their schemas (design 9.2, also in the pre-commit hook): agjan
129
+ * writes them, so a problem means a hand edit or a damaged merge.
130
+ */
131
+ function checkRecords(report, unit) {
132
+ for (const [file, schema, data] of [[APPROVALS_FILE, 'approvals', unit.approvals], [REVIEWS_FILE, 'reviews', unit.reviews]]) {
133
+ for (const problem of validate(loadSchema(schema), data).slice(0, 5))
134
+ report.error(unit.slug, `${file}: ${problem}`);
135
+ }
136
+ }
114
137
  function checkFeature(report, root, config, slug, level) {
115
138
  const feature = loadFeature(root, slug);
139
+ checkRecords(report, feature);
140
+ if (level !== 'staged')
141
+ checkReviewMd(report, feature);
116
142
  if (feature.kind === 'fix')
117
143
  return checkFix(report, root, config, feature, level);
118
144
  if (feature.kind === 'map')
@@ -238,8 +264,8 @@ function checkResults(report, root, config, feature, areaNames, ci) {
238
264
  if (newest > oldest)
239
265
  report.warn(scope, 'test results are older than the latest change; run the tests again');
240
266
  }
241
- /** Changed files outside every Build feature's approved scope (design 6.5). */
242
- function checkScope(report, features, config, files, level) {
267
+ /** Changed files outside every Build feature's approved scope (design 6.5). `ci` decides uncovered changes. */
268
+ function checkScope(report, features, config, files, level, ci) {
243
269
  const docs = `${FEATURES_DIR}/`;
244
270
  // .agjan/ is local scratch (git-ignored by init); never part of a change.
245
271
  const outside = files.filter((f) => !f.startsWith(docs) && !f.startsWith('.agjan/'));
@@ -262,7 +288,7 @@ function checkScope(report, features, config, files, level) {
262
288
  // CI decides whether that is allowed; fixes get their own record in milestone 0.3.
263
289
  if (level === 'ci' && outside.length > 0) {
264
290
  const message = `${outside.length} changed file(s) are not covered by any feature`;
265
- if (config.ci.untracked_changes === 'warn')
291
+ if (ci.untracked_changes === 'warn')
266
292
  report.warn('scope', message);
267
293
  else
268
294
  report.error('scope', message);
@@ -287,6 +313,19 @@ function checkScope(report, features, config, files, level) {
287
313
  report.error('scope', `${file} is outside the approved task paths; revert it or propose an amendment (agjan amend)`);
288
314
  }
289
315
  }
316
+ /**
317
+ * `.agjan/` holds what belongs to one checkout (the auto mode default, review contexts,
318
+ * progress pages); init git-ignores it, and the scope check and the review hashes skip it.
319
+ * A file there that git tracks (committed or staged anyway) would be shared: a committed
320
+ * auto mode default would switch auto mode on for everyone's new features (decision 79).
321
+ */
322
+ function checkLocalFolder(report, root) {
323
+ const tracked = paths(git(root, ['ls-files', '-z', '--', '.agjan']));
324
+ if (!tracked.length)
325
+ return;
326
+ const shown = tracked.slice(0, 3).join(', ') + (tracked.length > 3 ? `, … (${tracked.length - 3} more)` : '');
327
+ report.error('scope', `${shown}: .agjan/ is local to each checkout and must not be committed; run: git rm -r --cached .agjan (npx agjan sync restores its .gitignore entry)`);
328
+ }
290
329
  /**
291
330
  * What agjan a manifest pins: the version range in package.json, or the resolved
292
331
  * version, source and integrity in package-lock.json. Unparsable text pins "unknown".
@@ -305,10 +344,10 @@ function agjanPin(file, text) {
305
344
  }
306
345
  }
307
346
  /**
308
- * Policy changes relative to the merge-base: reported, and failing only when configured.
347
+ * Policy changes relative to the merge-base: reported, and failing only when `ci` says so.
309
348
  * Returns the messages so the PR summary can list them.
310
349
  */
311
- function checkPolicy(report, root, config, files, base) {
350
+ function checkPolicy(report, root, ci, files, base) {
312
351
  const isPolicy = matcher(POLICY_PATTERNS);
313
352
  const from = mergeBase(root, base);
314
353
  const messages = [];
@@ -328,7 +367,7 @@ function checkPolicy(report, root, config, files, base) {
328
367
  }
329
368
  const message = `policy change: ${file}`;
330
369
  messages.push(message);
331
- if (config.ci.policy_changes === 'fail')
370
+ if (ci.policy_changes === 'fail')
332
371
  report.error('policy', message);
333
372
  else
334
373
  report.warn('policy', message);
@@ -388,11 +427,24 @@ export function runChecks(ctx, level, explicitFeature) {
388
427
  throw new UsageError(`no feature '${explicitFeature}'`);
389
428
  // Every feature changed on the branch, also with --staged: scope is judged against
390
429
  // the whole branch's approved tasks, while only staged files are checked.
391
- const slugs = explicitFeature ? [explicitFeature] : changedFeatures(root, config);
430
+ const changed = changedFeatures(root, config);
431
+ const slugs = explicitFeature ? [explicitFeature] : changed;
392
432
  const features = slugs.map((slug) => checkFeature(report, root, config, slug, level));
433
+ // With one feature named (approve verify does), the other units of the branch still own
434
+ // their files: scope is the branch's.
435
+ const others = changed.filter((slug) => !slugs.includes(slug)).map((slug) => loadFeature(root, slug));
393
436
  const files = changedFiles(root, base, { staged: level === 'staged' });
394
- checkScope(report, features, config, files, level);
395
- const policy = level === 'ci' ? checkPolicy(report, root, config, files, base) : [];
437
+ // In CI the settings that judge the change come from the base branch: a pull request
438
+ // cannot lower them in the same change (design 9.3).
439
+ const from = level === 'ci' ? mergeBase(root, base) : null;
440
+ const ci = (from && ciSettingsAt(root, from)) || config.ci;
441
+ for (const key of ['policy_changes', 'untracked_changes']) {
442
+ if (ci[key] !== config.ci[key])
443
+ report.warn('policy', `this change sets ci.${key} to ${config.ci[key]}; until it is merged, the check uses the base branch's ${ci[key]}`);
444
+ }
445
+ checkScope(report, [...features, ...others], config, files, level, ci);
446
+ checkLocalFolder(report, root);
447
+ const policy = level === 'ci' ? checkPolicy(report, root, ci, files, base) : [];
396
448
  if (level !== 'staged') {
397
449
  checkManaged(report, ctx);
398
450
  // The baseline describes the application; changes to watched files make it stale.
@@ -513,11 +513,19 @@ export async function reject(ctx, argv) {
513
513
  throw new UsageError('usage: agjan reject spec|design --reason "<why>" [--feature <slug>] [--no-commit]');
514
514
  }
515
515
  const feature = loadFeature(ctx.root, selectFeature(ctx.root, ctx.config, values.feature));
516
+ if (feature.kind !== 'feature')
517
+ throw new AgjanError(`reject is for the spec and design of a feature; ${feature.slug} is a ${feature.kind}`);
518
+ const what = gate === 'spec' ? 'spec.md' : 'the design (design.md and tasks.md)';
519
+ const state = feature.state[gate];
520
+ // A rejection sends back what waits for approval; it does not withdraw an approval.
521
+ if (state === 'approved') {
522
+ throw new AgjanError(`${what} is approved and unchanged since; reject is for one that waits for approval. To change it, ask the agent for the revision (${gate === 'spec' ? '/agjan-spec' : '/agjan-design, "Revising an approved design"'}): the approval then goes stale and the gate runs again.`);
523
+ }
516
524
  if (!(await confirmGate(ctx, feature, `reject ${gate}`, [`reason ${values.reason}`])))
517
525
  return 1;
518
526
  feature.approvals.rejections.push({ gate, reason: values.reason, at_utc: ctx.now(), by: ctx.email() });
519
527
  save(ctx, feature, 'rejected', { gate });
520
- ctx.out(`recorded rejection of ${gate} for ${feature.slug}; the document stays draft`);
528
+ ctx.out(`recorded rejection of ${gate} for ${feature.slug}; ${what} is not approved (${state})`);
521
529
  await commitRecord(ctx, feature, values, `${feature.key}: reject ${gate}`);
522
530
  return 0;
523
531
  }
@@ -2,12 +2,23 @@ import { spawnSync } from 'node:child_process';
2
2
  import { existsSync } from 'node:fs';
3
3
  import { join } from 'node:path';
4
4
  import { parseArgs } from 'node:util';
5
- import { changedFiles, git, resolveBase } from '../git.js';
5
+ import { changedFiles, git, paths, resolveBase } from '../git.js';
6
6
  import { matcher } from '../scope.js';
7
7
  import { UsageError } from '../errors.js';
8
8
  import { overrideBase } from './check.js';
9
- /** Quotes a path for the shell (sh and cmd both accept double quotes). */
10
- const quote = (path) => (/^[\w./@-]+$/.test(path) ? path : `"${path.replace(/"/g, '\\"')}"`);
9
+ /**
10
+ * Quotes a path for the shell that runs the linter. POSIX sh takes everything inside single
11
+ * quotes literally (`$(…)` and backticks too, which double quotes still run); a single quote
12
+ * is closed, escaped and reopened. cmd.exe takes double quotes literally for everything but
13
+ * `%VAR%`, and a Windows file name cannot contain a double quote.
14
+ */
15
+ export function shellQuote(path, platform = process.platform) {
16
+ if (/^[\w./@-]+$/.test(path))
17
+ return path;
18
+ if (platform === 'win32')
19
+ return `"${path}"`;
20
+ return `'${path.replace(/'/g, "'\\''")}'`;
21
+ }
11
22
  /**
12
23
  * The folders an area's linter runs in, with the files to lint in each (paths relative to
13
24
  * the folder). `lint.in` names the folders (for example `app/*`), `lint.files` the files
@@ -46,7 +57,7 @@ export function run(ctx, argv) {
46
57
  }
47
58
  const root = ctx.root;
48
59
  const files = values.all
49
- ? (git(root, ['ls-files', '--cached', '--others', '--exclude-standard']) ?? '').split('\n').filter(Boolean)
60
+ ? paths(git(root, ['ls-files', '--cached', '--others', '--exclude-standard', '-z']))
50
61
  : changedFiles(root, resolveBase(root, ctx.config.git?.base));
51
62
  const present = files.filter((f) => existsSync(join(root, f)));
52
63
  let failed = 0;
@@ -54,7 +65,7 @@ export function run(ctx, argv) {
54
65
  for (const [area, lint] of linters) {
55
66
  for (const [folder, inside] of lintTargets(present, lint)) {
56
67
  ran += 1;
57
- const command = values.all ? lint.command : `${lint.command} ${inside.map(quote).join(' ')}`;
68
+ const command = values.all ? lint.command : `${lint.command} ${inside.map((f) => shellQuote(f)).join(' ')}`;
58
69
  ctx.out(`${s.bold(`lint ${area}`)} ${folder}: ${s.gray(values.all ? lint.command : `${lint.command} (${inside.length} file(s))`)}`);
59
70
  const result = spawnSync(command, { cwd: join(root, folder), shell: true, encoding: 'utf8', timeout: 600_000, maxBuffer: 64 * 1024 * 1024 });
60
71
  const output = `${result.stdout ?? ''}${result.stderr ?? ''}`.trim();
@@ -2,7 +2,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { parseArgs } from 'node:util';
4
4
  import { writeJson } from '../json-file.js';
5
- import { APPROVALS_FILE, FEATURES_DIR, KEY, SLUG, emptyApprovals, featureDir, listFeatures, loadFeature, selectFeature } from '../feature.js';
5
+ import { APPROVALS_FILE, CONTAINERS, FEATURES_DIR, KEY, SLUG, emptyApprovals, featureDir, listFeatures, loadFeature, selectFeature } from '../feature.js';
6
6
  import { AgjanError, UsageError } from '../errors.js';
7
7
  import { readAutoDefault } from '../auto.js';
8
8
  import { appendLog } from '../log.js';
@@ -35,8 +35,9 @@ export function run(ctx, argv) {
35
35
  throw new UsageError('usage: agjan new <slug> --key <KEY>');
36
36
  if (!SLUG.test(slug))
37
37
  throw new UsageError(`slug '${slug}' must be lowercase letters, digits and '-', at most 48 characters`);
38
- if (slug === 'fixes')
39
- throw new UsageError("'fixes' is reserved");
38
+ // The record folders of fixes and map runs (decision 57): a feature there would be invisible.
39
+ if (CONTAINERS[slug])
40
+ throw new UsageError(`'${slug}' is reserved for the ${CONTAINERS[slug]} records (${FEATURES_DIR}/${slug}/)`);
40
41
  const key = values.key;
41
42
  if (!KEY.test(key))
42
43
  throw new UsageError(`key '${key}' must be 2 to 6 uppercase letters or digits, starting with a letter`);
@@ -562,92 +562,102 @@ export async function doctor(ctx) {
562
562
  fail('configuration', `no ${CONFIG_FILE}; run: npx agjan init`);
563
563
  }
564
564
  else {
565
- const config = loadConfig(root);
566
- ok('configuration', `domains ${config.domains.join(', ')}; hosts ${config.hosts.join(', ')}`);
567
- if (raw.kit !== ctx.kit)
568
- warn('kit version', `project records ${raw.kit}, installed ${ctx.kit}; run: npx agjan sync`);
569
- const local = readJson(join(root, 'node_modules', 'agjan', 'package.json'));
570
- if (!local)
571
- warn('local install', 'agjan is not installed in node_modules; run: npm install');
572
- else if (local.version !== ctx.kit)
573
- warn('local install', `node_modules has ${local.version}, this command is ${ctx.kit}`);
574
- else
575
- ok('local install', local.version);
576
- const base = resolveBase(root, config.git?.base);
577
- const commits = git(root, ['rev-parse', '--verify', '--quiet', 'HEAD'], { allowFail: true }) !== null;
578
- if (!commits)
579
- warn('base branch', 'no commits yet: commit the setup first (git add -A && git commit -m "chore: set up agjan"); main exists after that');
580
- else if (!base)
581
- warn('base branch', `none found; set git.base in ${CONFIG_FILE}`);
582
- else if (!mergeBase(root, base))
583
- warn('base branch', `${base} has no common history with HEAD (fetch it?)`);
584
- else
585
- ok('base branch', base);
586
- const problems = planStatus(root, buildPlan(config)).filter((i) => i.state !== 'ok');
587
- if (problems.length === 0)
588
- ok('managed files', 'up to date');
589
- for (const p of problems) {
590
- const fix = p.state === 'modified' ? 'edited locally; agjan sync --force restores it' : 'run: npx agjan sync';
591
- warn('managed file', `${p.path}: ${p.state}; ${fix}`);
565
+ let config = null;
566
+ try {
567
+ config = loadConfig(root);
592
568
  }
593
- const hookState = hookStatus(root);
594
- if (hookState.state === 'installed')
595
- ok('pre-commit hook', hookState.kind);
596
- else
597
- warn('pre-commit hook', `${hookState.state}; run: npx agjan hook install`);
598
- if (!existsSync(join(root, CI_FILE)))
599
- warn('ci', `${CI_FILE} is missing`);
600
- else
601
- ok('ci', CI_FILE);
602
- const mcp = probeMcp(root);
603
- if (mcp)
604
- fail('agjan mcp server', mcp);
605
- else
606
- ok('agjan mcp server', 'answers initialize and tools/list');
607
- if (config.hosts.includes('copilot')) {
608
- const guard = probeGuard(root);
609
- if (guard)
610
- warn('copilot guard', guard);
611
- else
612
- ok('copilot guard', 'denies agjan approve in a test payload');
613
- const names = Object.keys(mcpServers(config).servers);
614
- const known = names.length ? copilotServers() : {};
615
- const missing = names.filter((name) => !known?.[name]);
616
- if (!known)
617
- warn('copilot mcp', 'copilot is not on PATH; its MCP servers were not checked');
618
- else if (missing.length)
619
- warn('copilot mcp', `${missing.join(', ')} not in Copilot's configuration (removed?); add: npx agjan sync --copilot-mcp`);
620
- else if (names.length)
621
- ok('copilot mcp', `${names.join(', ')} in Copilot's configuration`);
569
+ catch (error) {
570
+ if (!(error instanceof AgjanError))
571
+ throw error;
572
+ fail('configuration', error.message.replace(/\n\s*/g, ' '));
622
573
  }
623
- if (config.hosts.includes('claude-code')) {
624
- const trust = claudeTrust(root);
625
- if (trust === 'trusted')
626
- ok('claude code trust', 'project folder trusted');
574
+ if (config) {
575
+ ok('configuration', `domains ${config.domains.join(', ')}; hosts ${config.hosts.join(', ')}`);
576
+ if (raw.kit !== ctx.kit)
577
+ warn('kit version', `project records ${raw.kit}, installed ${ctx.kit}; run: npx agjan sync`);
578
+ const local = readJson(join(root, 'node_modules', 'agjan', 'package.json'));
579
+ if (!local)
580
+ warn('local install', 'agjan is not installed in node_modules; run: npm install');
581
+ else if (local.version !== ctx.kit)
582
+ warn('local install', `node_modules has ${local.version}, this command is ${ctx.kit}`);
627
583
  else
628
- warn('claude code trust', `${trust}; open the folder in Claude Code once and trust it, or the reviewer has no agjan tools`);
629
- }
630
- if (hasUiTests(root)) {
631
- const browser = probeBrowser(root);
632
- if (browser.ready)
633
- ok('ui tests', `Chromium starts; npx agjan ui-test runs npm run ${UI_SCRIPT}`);
584
+ ok('local install', local.version);
585
+ const base = resolveBase(root, config.git?.base);
586
+ const commits = git(root, ['rev-parse', '--verify', '--quiet', 'HEAD'], { allowFail: true }) !== null;
587
+ if (!commits)
588
+ warn('base branch', 'no commits yet: commit the setup first (git add -A && git commit -m "chore: set up agjan"); main exists after that');
589
+ else if (!base)
590
+ warn('base branch', `none found; set git.base in ${CONFIG_FILE}`);
591
+ else if (!mergeBase(root, base))
592
+ warn('base branch', `${base} has no common history with HEAD (fetch it?)`);
634
593
  else
635
- warn('ui tests', `skipped (optional): ${browser.reason}; enable: ${browser.enable}`);
636
- }
637
- else if (config.areas.fiori) {
638
- ok('ui tests', `none (optional: Playwright, a ${UI_SCRIPT} script; see the fiori-developer skill)`);
594
+ ok('base branch', base);
595
+ const problems = planStatus(root, buildPlan(config)).filter((i) => i.state !== 'ok');
596
+ if (problems.length === 0)
597
+ ok('managed files', 'up to date');
598
+ for (const p of problems) {
599
+ const fix = p.state === 'modified' ? 'edited locally; agjan sync --force restores it' : 'run: npx agjan sync';
600
+ warn('managed file', `${p.path}: ${p.state}; ${fix}`);
601
+ }
602
+ const hookState = hookStatus(root);
603
+ if (hookState.state === 'installed')
604
+ ok('pre-commit hook', hookState.kind);
605
+ else
606
+ warn('pre-commit hook', `${hookState.state}; run: npx agjan hook install`);
607
+ if (!existsSync(join(root, CI_FILE)))
608
+ warn('ci', `${CI_FILE} is missing`);
609
+ else
610
+ ok('ci', CI_FILE);
611
+ const mcp = probeMcp(root);
612
+ if (mcp)
613
+ fail('agjan mcp server', mcp);
614
+ else
615
+ ok('agjan mcp server', 'answers initialize and tools/list');
616
+ if (config.hosts.includes('copilot')) {
617
+ const guard = probeGuard(root);
618
+ if (guard)
619
+ warn('copilot guard', guard);
620
+ else
621
+ ok('copilot guard', 'denies agjan approve in a test payload');
622
+ const names = Object.keys(mcpServers(config).servers);
623
+ const known = names.length ? copilotServers() : {};
624
+ const missing = names.filter((name) => !known?.[name]);
625
+ if (!known)
626
+ warn('copilot mcp', 'copilot is not on PATH; its MCP servers were not checked');
627
+ else if (missing.length)
628
+ warn('copilot mcp', `${missing.join(', ')} not in Copilot's configuration (removed?); add: npx agjan sync --copilot-mcp`);
629
+ else if (names.length)
630
+ ok('copilot mcp', `${names.join(', ')} in Copilot's configuration`);
631
+ }
632
+ if (config.hosts.includes('claude-code')) {
633
+ const trust = claudeTrust(root);
634
+ if (trust === 'trusted')
635
+ ok('claude code trust', 'project folder trusted');
636
+ else
637
+ warn('claude code trust', `${trust}; open the folder in Claude Code once and trust it, or the reviewer has no agjan tools`);
638
+ }
639
+ if (hasUiTests(root)) {
640
+ const browser = probeBrowser(root);
641
+ if (browser.ready)
642
+ ok('ui tests', `Chromium starts; npx agjan ui-test runs npm run ${UI_SCRIPT}`);
643
+ else
644
+ warn('ui tests', `skipped (optional): ${browser.reason}; enable: ${browser.enable}`);
645
+ }
646
+ else if (config.areas.fiori) {
647
+ ok('ui tests', `none (optional: Playwright, a ${UI_SCRIPT} script; see the fiori-developer skill)`);
648
+ }
649
+ ok('reviewer models', `${config.hosts.map((h) => `${h}: ${AGENT_TIERS.map((t) => `${t} ${agentModel(config, h, t) ?? 'session model'}`).join(', ')}`).join('; ')}${config.hosts.every((h) => !agentModel(config, h, 'deep')) ? ' (a deep reviewer on another model family than the main agent catches other things: npx agjan models set deep <model>)' : ''}`);
650
+ ok('branches', 'agents ask you, then run npx agjan branch');
651
+ const autoDefault = readAutoDefault(root);
652
+ ok('auto mode', autoDefault ? `on for new features in this checkout (since ${autoDefault.at_utc}); off: npx agjan auto off --default` : 'off: gates wait for you (npx agjan auto on --default for new features, auto on for one)');
653
+ ok('script edits', config.agent?.script_edits === 'allow' ? 'allowed (agent.script_edits)' : 'denied by the guard: agents edit files with their edit tool');
654
+ const tracked = (git(root, ['ls-files', '--', 'node_modules'], { allowFail: true }) ?? '').trim();
655
+ if (tracked)
656
+ warn('node_modules', 'is committed; remove it: git rm -r -q --cached node_modules && git commit -m "chore: stop tracking node_modules"');
657
+ const ignored = git(root, ['check-ignore', '-q', '.agjan/x'], { allowFail: true }) !== null;
658
+ if (!ignored)
659
+ warn('.gitignore', '.agjan/ is not ignored; run: npx agjan sync');
639
660
  }
640
- ok('reviewer models', `${config.hosts.map((h) => `${h}: ${AGENT_TIERS.map((t) => `${t} ${agentModel(config, h, t) ?? 'session model'}`).join(', ')}`).join('; ')}${config.hosts.every((h) => !agentModel(config, h, 'deep')) ? ' (a deep reviewer on another model family than the main agent catches other things: npx agjan models set deep <model>)' : ''}`);
641
- ok('branches', 'agents ask you, then run npx agjan branch');
642
- const autoDefault = readAutoDefault(root);
643
- ok('auto mode', autoDefault ? `on for new features in this checkout (since ${autoDefault.at_utc}); off: npx agjan auto off --default` : 'off: gates wait for you (npx agjan auto on --default for new features, auto on for one)');
644
- ok('script edits', config.agent?.script_edits === 'allow' ? 'allowed (agent.script_edits)' : 'denied by the guard: agents edit files with their edit tool');
645
- const tracked = (git(root, ['ls-files', '--', 'node_modules'], { allowFail: true }) ?? '').trim();
646
- if (tracked)
647
- warn('node_modules', 'is committed; remove it: git rm -r -q --cached node_modules && git commit -m "chore: stop tracking node_modules"');
648
- const ignored = git(root, ['check-ignore', '-q', '.agjan/x'], { allowFail: true }) !== null;
649
- if (!ignored)
650
- warn('.gitignore', '.agjan/ is not ignored; run: npx agjan sync');
651
661
  }
652
662
  }
653
663
  const s = ctx.style;
package/dist/config.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { join } from 'node:path';
2
2
  import { readJson } from './json-file.js';
3
3
  import { AgjanError } from './errors.js';
4
+ import { git } from './git.js';
5
+ import { loadSchema, validate } from './schema.js';
4
6
  export const CONFIG_FILE = 'agjan.config.json';
5
7
  const KIT_DIR = new URL('../kit/', import.meta.url);
6
8
  /**
@@ -68,6 +70,11 @@ export function loadConfig(root) {
68
70
  const project = readJson(join(root, CONFIG_FILE)) ?? {};
69
71
  if (!isObject(project))
70
72
  throw new AgjanError(`${CONFIG_FILE} must contain a JSON object`);
73
+ // A typo is an error, not a silent default ("policy_changes": "error" would mean warn).
74
+ const problems = validate(loadSchema('config'), project);
75
+ if (problems.length) {
76
+ throw new AgjanError(`${CONFIG_FILE} does not match its schema (node_modules/agjan/schemas/config.schema.json):\n${problems.map((p) => ` - ${p}`).join('\n')}`);
77
+ }
71
78
  const domainIds = project.domains ?? DEFAULTS.domains;
72
79
  let config = merge(DEFAULTS, {});
73
80
  const areas = {};
@@ -108,6 +115,23 @@ export function loadConfig(root) {
108
115
  config.areas = areas;
109
116
  return config;
110
117
  }
118
+ /**
119
+ * The `ci` settings of the configuration at `commit` (the merge-base in CI): a pull request
120
+ * must not lower the settings that judge it (`policy_changes`, `untracked_changes`) in the
121
+ * same change. Null when that commit has no readable agjan.config.json (agjan is new there).
122
+ */
123
+ export function ciSettingsAt(root, commit) {
124
+ const text = git(root, ['show', `${commit}:${CONFIG_FILE}`], { allowFail: true });
125
+ if (text === null)
126
+ return null;
127
+ try {
128
+ const data = JSON.parse(text);
129
+ return isObject(data) ? merge(DEFAULTS.ci, isObject(data.ci) ? data.ci : {}) : null;
130
+ }
131
+ catch {
132
+ return null;
133
+ }
134
+ }
111
135
  /** Resolves a short or canonical area id; returns null when unknown or ambiguous. */
112
136
  export function resolveArea(config, id) {
113
137
  return config.areas[id] ?? null;
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
- for (const line of (git(root, ['diff', '--name-status', '--no-renames', from], { allowFail: true }) ?? '').split('\n')) {
58
- const [status, file] = line.split('\t');
59
- if (status === 'A')
60
- added.add(file);
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 }) ?? '').split('\n').filter(Boolean)) {
64
- const [a, d, file] = line.split('\t');
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']).split('\n').filter(Boolean)) {
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
- if (record.tree_hash !== treeHash(root, config, unit.slug)) {
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 };