agjan 0.0.11 → 0.0.13

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 (114) hide show
  1. package/README.md +2 -2
  2. package/bin/agjan.mjs +9 -2
  3. package/dist/adapters/claude-code.js +136 -0
  4. package/dist/adapters/copilot.js +110 -0
  5. package/dist/auto.js +24 -0
  6. package/dist/baseline.js +66 -0
  7. package/dist/browser.js +46 -0
  8. package/dist/cli.js +170 -0
  9. package/dist/commands/branch.js +71 -0
  10. package/dist/commands/check.js +424 -0
  11. package/dist/commands/fix.js +122 -0
  12. package/dist/commands/gates.js +475 -0
  13. package/dist/commands/lint.js +76 -0
  14. package/dist/commands/log.js +74 -0
  15. package/dist/commands/map.js +47 -0
  16. package/dist/commands/models.js +90 -0
  17. package/dist/commands/new.js +65 -0
  18. package/dist/commands/pr-summary.js +176 -0
  19. package/dist/commands/progress.js +42 -0
  20. package/dist/commands/report.js +105 -0
  21. package/dist/commands/review.js +149 -0
  22. package/dist/commands/setup.js +393 -0
  23. package/dist/commands/status.js +323 -0
  24. package/dist/commands/ui-test.js +39 -0
  25. package/dist/config.js +114 -0
  26. package/dist/context.js +56 -0
  27. package/dist/copilot-mcp.js +56 -0
  28. package/dist/documents.js +207 -0
  29. package/dist/errors.js +15 -0
  30. package/dist/feature.js +221 -0
  31. package/dist/fix.js +117 -0
  32. package/dist/git.js +88 -0
  33. package/{src/hash.mjs → dist/hash.js} +11 -14
  34. package/dist/hook.js +47 -0
  35. package/dist/json-file.js +26 -0
  36. package/dist/log.js +50 -0
  37. package/dist/managed.js +182 -0
  38. package/dist/mcp-config.js +76 -0
  39. package/dist/mcp.js +187 -0
  40. package/dist/plan.js +40 -0
  41. package/dist/progress-view.js +494 -0
  42. package/dist/progress.js +106 -0
  43. package/dist/qa.js +77 -0
  44. package/dist/review-policy.js +84 -0
  45. package/dist/review.js +534 -0
  46. package/dist/scope.js +34 -0
  47. package/dist/terminal.js +127 -0
  48. package/dist/test-results.js +101 -0
  49. package/dist/tests-map.js +29 -0
  50. package/dist/types.js +5 -0
  51. package/dist/ui.js +136 -0
  52. package/dist/usage.js +116 -0
  53. package/dist/validate.js +46 -0
  54. package/docs/guide.md +80 -40
  55. package/kit/hooks/guard.mjs +48 -119
  56. package/kit/skills/agjan-build/SKILL.md +6 -2
  57. package/kit/skills/agjan-design/SKILL.md +9 -2
  58. package/kit/skills/agjan-fix/SKILL.md +8 -16
  59. package/kit/skills/agjan-map/SKILL.md +8 -16
  60. package/kit/skills/agjan-spec/SKILL.md +24 -17
  61. package/kit/skills/agjan-verify/SKILL.md +50 -16
  62. package/kit/skills/qa-tester/SKILL.md +74 -0
  63. package/kit/templates/agents-block.md +3 -3
  64. package/package.json +11 -3
  65. package/schemas/approvals.schema.json +23 -2
  66. package/schemas/config.schema.json +3 -7
  67. package/schemas/log.schema.json +1 -1
  68. package/schemas/reviews.schema.json +3 -1
  69. package/src/adapters/claude-code.mjs +0 -121
  70. package/src/adapters/copilot.mjs +0 -89
  71. package/src/baseline.mjs +0 -66
  72. package/src/browser.mjs +0 -49
  73. package/src/cli.mjs +0 -165
  74. package/src/commands/branch.mjs +0 -95
  75. package/src/commands/check.mjs +0 -376
  76. package/src/commands/fix.mjs +0 -116
  77. package/src/commands/gates.mjs +0 -267
  78. package/src/commands/lint.mjs +0 -74
  79. package/src/commands/log.mjs +0 -60
  80. package/src/commands/map.mjs +0 -47
  81. package/src/commands/new.mjs +0 -53
  82. package/src/commands/pr-summary.mjs +0 -137
  83. package/src/commands/progress.mjs +0 -40
  84. package/src/commands/report.mjs +0 -115
  85. package/src/commands/review.mjs +0 -141
  86. package/src/commands/setup.mjs +0 -393
  87. package/src/commands/status.mjs +0 -250
  88. package/src/commands/ui-test.mjs +0 -38
  89. package/src/config.mjs +0 -122
  90. package/src/context.mjs +0 -67
  91. package/src/copilot-mcp.mjs +0 -56
  92. package/src/documents.mjs +0 -188
  93. package/src/errors.mjs +0 -16
  94. package/src/feature.mjs +0 -225
  95. package/src/fix.mjs +0 -108
  96. package/src/git.mjs +0 -83
  97. package/src/hook.mjs +0 -48
  98. package/src/json-file.mjs +0 -24
  99. package/src/log.mjs +0 -51
  100. package/src/managed.mjs +0 -178
  101. package/src/mcp-config.mjs +0 -83
  102. package/src/mcp.mjs +0 -147
  103. package/src/plan.mjs +0 -45
  104. package/src/progress-view.mjs +0 -466
  105. package/src/progress.mjs +0 -85
  106. package/src/review-policy.mjs +0 -91
  107. package/src/review.mjs +0 -416
  108. package/src/scope.mjs +0 -30
  109. package/src/terminal.mjs +0 -118
  110. package/src/test-results.mjs +0 -111
  111. package/src/tests-map.mjs +0 -29
  112. package/src/ui.mjs +0 -136
  113. package/src/usage.mjs +0 -118
  114. package/src/validate.mjs +0 -41
package/dist/qa.js ADDED
@@ -0,0 +1,77 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { existsSync, readFileSync, readdirSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import { latestReview, stillBlocked } from './feature.js';
5
+ /**
6
+ * The QA step (design decision 81): in Verify, the QA agent (`agjan-qa`, the qa-tester
7
+ * skill) writes and runs tests from the spec alone, without the design, the diff or the
8
+ * writer's tests. Its tests stay in the project as regression tests, in two folders per
9
+ * feature: service tests, and UI tests where the project's Playwright tests live.
10
+ */
11
+ export const QA_STEP = 'qa';
12
+ /** The folders a feature's QA tests live in; the only paths the QA agent writes. */
13
+ export function qaDirs(slug) {
14
+ return [`test/qa/${slug}/`, `test/ui/qa/${slug}/`];
15
+ }
16
+ /** QA runs for full-mode features unless the project turns it off (`review.qa: "off"`). */
17
+ export function qaApplies(config, feature) {
18
+ return feature.kind === 'feature' && feature.design?.parsed.mode === 'full' && config.review?.qa !== 'off';
19
+ }
20
+ function filesUnder(root, dir) {
21
+ const abs = join(root, dir);
22
+ if (!existsSync(abs))
23
+ return [];
24
+ const out = [];
25
+ const walk = (rel) => {
26
+ for (const entry of readdirSync(join(root, rel), { withFileTypes: true })) {
27
+ const path = `${rel}${entry.name}`;
28
+ if (entry.isDirectory())
29
+ walk(`${path}/`);
30
+ else if (entry.isFile())
31
+ out.push(path);
32
+ }
33
+ };
34
+ walk(dir);
35
+ return out;
36
+ }
37
+ /** The QA test files of a feature, sorted, as repository paths. */
38
+ export function qaTestFiles(root, slug) {
39
+ return qaDirs(slug).flatMap((dir) => filesUnder(root, dir)).sort();
40
+ }
41
+ /** Hash of the feature's QA tests as they are now: a change after QA makes it stale. */
42
+ export function qaTestsHash(root, slug) {
43
+ const hash = createHash('sha256');
44
+ for (const file of qaTestFiles(root, slug)) {
45
+ hash.update(file).update('\0').update(createHash('sha256').update(readFileSync(join(root, file))).digest('hex')).update('\0');
46
+ }
47
+ return `sha256:${hash.digest('hex')}`;
48
+ }
49
+ /**
50
+ * Where QA stands: `off` (light mode, or turned off), `due` (no QA round yet), `blocked`
51
+ * (its blockers are open: fix the code, then QA again), `stale` (the QA tests changed
52
+ * after the round: QA again) or `passed`. Code changes after a passing round are the
53
+ * final review's to judge, not QA's.
54
+ */
55
+ export function qaState(root, config, feature) {
56
+ if (!qaApplies(config, feature))
57
+ return { state: 'off', record: null };
58
+ const record = latestReview(feature.reviews, [QA_STEP]);
59
+ if (!record)
60
+ return { state: 'due', record: null };
61
+ if (stillBlocked(feature, record))
62
+ return { state: 'blocked', record };
63
+ if (record.qa_tests_hash !== qaTestsHash(root, feature.slug))
64
+ return { state: 'stale', record };
65
+ return { state: 'passed', record };
66
+ }
67
+ /** Why the final review and the acceptance wait for QA, or null when they need not. */
68
+ export function qaProblem(root, config, feature) {
69
+ const qa = qaState(root, config, feature);
70
+ if (qa.state === 'due')
71
+ return 'QA has not run yet: delegate step qa to agjan-qa';
72
+ if (qa.state === 'blocked')
73
+ return `the QA round ${qa.record.id} is blocked: fix the code (never the QA tests), then run QA again`;
74
+ if (qa.state === 'stale')
75
+ return `the QA tests changed after the QA round ${qa.record.id}: run QA again`;
76
+ return null;
77
+ }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Review settings from agjan.config.json (design 7.3, 7.4): which reviewer agent runs a
3
+ * step (`review.tiers`), how many correction rounds a step gets (`review.rounds`), and
4
+ * how many attempts the writer has for failing deterministic checks
5
+ * (`build.fix_attempts`). `agjan status` shows them; the skills follow `status`.
6
+ */
7
+ import { stillBlocked } from './feature.js';
8
+ import { readLog } from './log.js';
9
+ /** Default tier per kind of review step. */
10
+ export const DEFAULT_TIERS = {
11
+ spec: 'balanced',
12
+ 'design:light': 'balanced',
13
+ design: 'deep',
14
+ build: 'balanced',
15
+ verify: 'deep',
16
+ fix: 'balanced',
17
+ map: 'balanced',
18
+ qa: 'qa',
19
+ };
20
+ /** `build:cap` and `build:T2` are both of kind `build`. */
21
+ export function stepKind(step) {
22
+ return step.startsWith('build:') ? 'build' : step;
23
+ }
24
+ /** The generated reviewer agent for a step. There is no fast agent; `fast` uses the balanced one. */
25
+ export function reviewerFor(config, step) {
26
+ const kind = stepKind(step);
27
+ const tier = config.review?.tiers?.[kind] ?? DEFAULT_TIERS[kind] ?? 'balanced';
28
+ return tier === 'qa' ? 'agjan-qa' : tier === 'deep' ? 'agjan-reviewer-deep' : 'agjan-reviewer';
29
+ }
30
+ export function roundLimit(config) {
31
+ return config.review?.rounds ?? 3;
32
+ }
33
+ export function fixAttempts(config) {
34
+ return config.build?.fix_attempts ?? 3;
35
+ }
36
+ /** The gate approvals that close a correction loop of a review step. */
37
+ const CLOSING_APPROVALS = { spec: ['spec'], design: ['design'], 'design:light': ['spec', 'design'] };
38
+ /**
39
+ * The round the next review of `step` gets (design 7.4). Rounds count within one
40
+ * correction loop: a loop ends with a review without findings (`pass`), with the gate's
41
+ * approval after its last review, or, for build steps, with a passing verify review after
42
+ * it. A later change, for example after the human's Gate 3 review, starts a new loop at
43
+ * round 1.
44
+ */
45
+ export function nextRound(feature, step) {
46
+ const records = feature.reviews.records.filter((r) => r.step === step);
47
+ const approvals = (CLOSING_APPROVALS[step] ?? []).map((gate) => feature.approvals.approvals[gate]?.at_utc).filter((at) => Boolean(at));
48
+ if (step.startsWith('build:')) {
49
+ const verified = feature.reviews.records.filter((r) => r.step === 'verify' && !stillBlocked(feature, r));
50
+ approvals.push(...verified.map((r) => r.at_utc));
51
+ }
52
+ let round = 1;
53
+ for (let i = records.length - 1; i >= 0; i--) {
54
+ const r = records[i];
55
+ if (r.verdict === 'pass' || approvals.some((at) => at >= r.at_utc))
56
+ break;
57
+ round += 1;
58
+ }
59
+ return round;
60
+ }
61
+ /**
62
+ * The state of one review step: its latest round and verdict, and whether the round limit
63
+ * (with the rounds the user granted) is reached with the step still blocked (design 7.4:
64
+ * ask the user for another round, or hand over).
65
+ */
66
+ export function roundState(feature, config, step) {
67
+ const records = feature.reviews.records.filter((r) => r.step === step);
68
+ const last = records.at(-1) ?? null;
69
+ const extra = extraRounds(feature, step);
70
+ const limit = roundLimit(config) + extra;
71
+ const round = last?.round ?? 0;
72
+ return { last, round, next: nextRound(feature, step), limit, extra, exhausted: stillBlocked(feature, last) && round >= limit };
73
+ }
74
+ /**
75
+ * Rounds the user granted beyond the limit in the current correction loop of `step`
76
+ * (`agjan review extend`, design 7.4): each grant adds one round. A new loop starts at
77
+ * round 1 with the configured limit again.
78
+ */
79
+ export function extraRounds(feature, step) {
80
+ const loopStart = feature.reviews.records.filter((r) => r.step === step && r.round === 1).at(-1)?.at_utc;
81
+ if (!loopStart)
82
+ return 0;
83
+ return readLog(feature.dir).filter((e) => e.event === 'round-granted' && e.step === step && e.at_utc >= loopStart).length;
84
+ }