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
@@ -1,40 +0,0 @@
1
- import { spawn } from 'node:child_process';
2
- import { relative } from 'node:path';
3
- import { parseArgs } from 'node:util';
4
- import { writeProgress } from '../progress-view.mjs';
5
- import { markLine, tone } from '../ui.mjs';
6
-
7
- /** Opens a file with the system's default application; failures are reported, not thrown. */
8
- function openFile(file) {
9
- const [cmd, args] = process.platform === 'win32' ? ['cmd', ['/c', 'start', '""', file]] : [process.platform === 'darwin' ? 'open' : 'xdg-open', [file]];
10
- try {
11
- const child = spawn(cmd, args, { stdio: 'ignore', detached: true });
12
- child.on('error', () => {});
13
- child.unref();
14
- return true;
15
- } catch {
16
- return false;
17
- }
18
- }
19
-
20
- /** agjan progress [--open]: regenerates the progress pages and prints the overview. */
21
- export function run(ctx, argv) {
22
- const { values } = parseArgs({ args: argv, options: { open: { type: 'boolean' } } });
23
- const s = ctx.style;
24
- const result = writeProgress(ctx, { now: Date.parse(ctx.now()) });
25
- for (const line of markLine(s, ctx.kit, 'progress')) ctx.out(line);
26
- if (!result) {
27
- ctx.err('agjan progress: the pages could not be generated; run npx agjan check for details');
28
- return 1;
29
- }
30
- if (!result.models.length) ctx.out('no features, fixes or map runs yet');
31
- for (const m of result.models) {
32
- const turn = m.turn === 'you' ? s.violet('your turn') : m.turn === 'merged' ? tone(s, 'merged') : s.cyan('agent working');
33
- const stage = m.stages[Math.min(m.at, m.stages.length - 1)];
34
- ctx.out(`${s.bold(m.key.padEnd(6))} ${m.slug.padEnd(34)} ${stage.padEnd(15)} ${turn}${m.turn === 'merged' ? '' : s.gray(` · ${m.now}`)}`);
35
- }
36
- const html = relative(ctx.root, result.html).split('\\').join('/');
37
- ctx.out('', `${s.gray('overview')} ${html} ${s.gray('· per unit: docs/agjan/<unit>/progress.md')}`);
38
- if (values.open && !openFile(result.html)) ctx.out(`open ${html} in a browser`);
39
- return 0;
40
- }
@@ -1,115 +0,0 @@
1
- import { writeFileSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { parseArgs } from 'node:util';
4
- import { FEATURES_DIR, loadFeature, selectFeature } from '../feature.mjs';
5
- import { readLog } from '../log.mjs';
6
- import { usageBetween } from '../usage.mjs';
7
-
8
- export const REPORT_FILE = 'report.md';
9
-
10
- function minutes(ms) {
11
- if (ms < 60_000) return `${Math.round(ms / 1000)}s`;
12
- const m = Math.round(ms / 60_000);
13
- return m < 60 ? `${m}m` : `${Math.floor(m / 60)}h ${m % 60}m`;
14
- }
15
-
16
- function tokens(n) {
17
- return n >= 10_000 ? `${(n / 1000).toFixed(0)}k` : String(n);
18
- }
19
-
20
- function sum(records) {
21
- const total = { input: 0, cacheRead: 0, cacheWrite: 0, output: 0 };
22
- for (const r of records) for (const k of Object.keys(total)) total[k] += r[k];
23
- return total;
24
- }
25
-
26
- function models(records) {
27
- return [...new Set(records.map((r) => r.model))].join(', ') || '-';
28
- }
29
-
30
- /**
31
- * Spans of the feature's life from its log (design 12.1): each step runs from its
32
- * `step` event to the next `step` or `gate-requested` event; each gate wait runs from
33
- * `gate-requested` to the matching approval or rejection.
34
- */
35
- export function spans(events, end) {
36
- const out = [];
37
- const times = events.map((e) => Date.parse(e.at_utc));
38
- events.forEach((event, i) => {
39
- const at = times[i];
40
- if (event.event === 'step') {
41
- const next = events.findIndex((e, j) => j > i && ['step', 'gate-requested', 'waiting'].includes(e.event));
42
- const label = [event.stage, event.task, event.role].filter(Boolean).join(' ');
43
- out.push({ kind: 'step', label, from: at, to: next === -1 ? end : times[next] });
44
- }
45
- if (event.event === 'gate-requested') {
46
- const done = events.findIndex((e, j) => j > i && (e.event === 'approved' || e.event === 'rejected'));
47
- out.push({ kind: 'gate', label: `gate ${event.gate}`, from: at, to: done === -1 ? end : times[done], open: done === -1 });
48
- }
49
- // The agent stopped for the user: waiting until its next step.
50
- if (event.event === 'waiting') {
51
- const next = events.findIndex((e, j) => j > i && e.event === 'step');
52
- out.push({ kind: 'gate', label: 'waiting for you', from: at, to: next === -1 ? end : times[next], open: next === -1 });
53
- }
54
- });
55
- return out;
56
- }
57
-
58
- /** report.md for a feature (design 12.2). */
59
- export function buildReport(root, feature, { now = Date.now(), homes = {} } = {}) {
60
- const events = readLog(feature.dir);
61
- const lines = [`# Report: ${feature.slug} (${feature.key})`, '', `<!-- Generated by agjan report at ${new Date(now).toISOString().replace(/\.\d{3}Z$/, 'Z')}. Do not edit. -->`, ''];
62
- if (events.length === 0) return [...lines, 'No log events yet.', ''].join('\n');
63
-
64
- const start = Date.parse(events[0].at_utc);
65
- const list = spans(events, now);
66
- const usage = usageBetween(root, start, now, homes);
67
- const inSpan = (span) => usage.filter((r) => r.at >= span.from && r.at < span.to);
68
-
69
- const steps = list.filter((s) => s.kind === 'step');
70
- const gates = list.filter((s) => s.kind === 'gate');
71
- const active = steps.reduce((t, s) => t + (s.to - s.from), 0);
72
- const waiting = gates.reduce((t, s) => t + (s.to - s.from), 0);
73
- const total = sum(usage);
74
- const reviewer = usage.filter((r) => r.agent === 'subagent');
75
-
76
- lines.push('## Summary', '');
77
- lines.push(`| | |`, `|---|---|`);
78
- lines.push(`| Time window | ${events[0].at_utc} to ${new Date(now).toISOString().replace(/\.\d{3}Z$/, 'Z')} |`);
79
- lines.push(`| Active work (steps) | ${minutes(active)} |`);
80
- lines.push(`| Waiting at gates | ${minutes(waiting)}${gates.some((g) => g.open) ? ' (a gate is still open)' : ''} |`);
81
- lines.push(`| Reviews | ${feature.reviews.records.length} (${feature.reviews.records.filter((r) => r.verdict === 'blocked').length} blocked) |`);
82
- if (usage.length) {
83
- lines.push(`| Tokens: input / cache read / cache write / output | ${tokens(total.input)} / ${tokens(total.cacheRead)} / ${tokens(total.cacheWrite)} / ${tokens(total.output)} |`);
84
- lines.push(`| Share of output by reviewer agents | ${total.output ? Math.round((sum(reviewer).output / total.output) * 100) : 0}% |`);
85
- lines.push(`| Models | ${models(usage)} |`);
86
- } else {
87
- lines.push('| Tokens and models | unknown: no host session records found for this folder and time window |');
88
- }
89
- lines.push('');
90
-
91
- lines.push('## Steps and gates', '', '| Step | Start | Duration | Input | Output | Models |', '|---|---|---|---|---|---|');
92
- for (const s of list) {
93
- const r = inSpan(s);
94
- const t = sum(r);
95
- const when = new Date(s.from).toISOString().slice(11, 16);
96
- lines.push(`| ${s.label}${s.open ? ' (open)' : ''} | ${when} | ${minutes(s.to - s.from)} | ${r.length ? tokens(t.input + t.cacheRead + t.cacheWrite) : '-'} | ${r.length ? tokens(t.output) : '-'} | ${models(r)} |`);
97
- }
98
- lines.push('');
99
- lines.push(
100
- 'Durations come from `log.jsonl`. Tokens and models come from the hosts\' session records (Claude Code, GitHub Copilot CLI) for this ' +
101
- 'folder within each time span; other work in the same folder at the same time is included.',
102
- '',
103
- );
104
- return lines.join('\n');
105
- }
106
-
107
- /** agjan report [--feature <slug>]: writes docs/agjan/<slug>/report.md. */
108
- export function run(ctx, argv) {
109
- const { values } = parseArgs({ args: argv, options: { feature: { type: 'string' } } });
110
- const feature = loadFeature(ctx.root, selectFeature(ctx.root, ctx.config, values.feature));
111
- const text = buildReport(ctx.root, feature, { now: Date.parse(ctx.now()) });
112
- writeFileSync(join(feature.dir, REPORT_FILE), text);
113
- ctx.out(`wrote ${FEATURES_DIR}/${feature.slug}/${REPORT_FILE}`);
114
- return 0;
115
- }
@@ -1,141 +0,0 @@
1
- import { parseArgs } from 'node:util';
2
- import { serve } from '../mcp.mjs';
3
- import { buildContextText, parseStep } from '../review.mjs';
4
- import { loadFeature, selectFeature } from '../feature.mjs';
5
- import { appendLog } from '../log.mjs';
6
- import { reviewerFor, roundState } from '../review-policy.mjs';
7
- import { highlightMarkdown, tone } from '../ui.mjs';
8
- import { AgjanError, UsageError } from '../errors.mjs';
9
-
10
- /** agjan mcp [--host <name>] [--isolation agent|fork|none]: the agjan MCP server on stdio. */
11
- export function mcp(ctx, argv) {
12
- const { values } = parseArgs({ args: argv, options: { host: { type: 'string' }, isolation: { type: 'string' } } });
13
- const isolation = values.isolation ?? 'unknown';
14
- if (!['agent', 'shared', 'fork', 'none', 'unknown'].includes(isolation)) {
15
- throw new UsageError('--isolation must be agent, shared, fork or none');
16
- }
17
- // Resolve the repository now so a misconfigured server fails at start, not on first call.
18
- void ctx.root;
19
- return serve(ctx, { host: values.host ?? 'unknown', isolation });
20
- }
21
-
22
- /** agjan review show | report | extend: dispatches to the subcommand. */
23
- export function run(ctx, argv) {
24
- if (argv[0] === 'extend') return extend(ctx, argv.slice(1));
25
- if (argv[0] === 'report') return report(ctx, argv.slice(1));
26
- return show(ctx, argv);
27
- }
28
-
29
- const VERDICT = { pass: '✅ pass', 'pass-with-notes': '✅ pass with notes', blocked: '⛔ blocked' };
30
- const MARK = { pass: '✅', 'pass-with-notes': '✅', blocked: '⛔' };
31
- const SEVERITY = { blocker: '🔴', major: '🟠', minor: '🟡' };
32
-
33
- /** One line of an issue, at most `max` characters. */
34
- function oneLine(text, max = 140) {
35
- const line = String(text ?? '').replace(/\s+/g, ' ').trim();
36
- return line.length > max ? `${line.slice(0, max - 1)}…` : line;
37
- }
38
-
39
- /** What the writer does after this review (design 7.4), in the user's words. */
40
- function nextAfter(feature, config, record) {
41
- const state = roundState(feature, config, record.step);
42
- const status = new Map(feature.findings.map((f) => [f.id, f.status]));
43
- const open = (severity) => record.findings.filter((f) => f.severity === severity && status.get(f.id) === 'open').length;
44
- if (record.verdict === 'blocked') {
45
- if (state.exhausted) return `round limit reached (${state.round} of ${state.limit}): the agent asks you whether to run another round`;
46
- return `the agent fixes ${open('blocker')} blocker(s), then review round ${state.next} of ${state.limit}`;
47
- }
48
- const majors = open('major');
49
- if (majors) return `the agent fixes the ${majors} major finding(s) it agrees with (another round), or goes on; minor notes stay open for the PR`;
50
- return record.verdict === 'pass' ? 'the agent goes on with the next step' : 'minor notes stay open (the PR summary lists them); the agent goes on';
51
- }
52
-
53
- /**
54
- * agjan review report [--step <step>] [--feature <slug>]: the latest review round as a
55
- * short Markdown report for the user (verdict, findings by severity, the rounds of this
56
- * loop, what happens next). Agents put it into their message after every review, so the
57
- * user sees what the reviewer found; the markers are emoji, which every host shows.
58
- */
59
- export function report(ctx, argv) {
60
- const { values, positionals } = parseArgs({ args: argv, options: { step: { type: 'string' }, feature: { type: 'string' } }, allowPositionals: true });
61
- if (positionals.length) throw new UsageError('usage: agjan review report [--step <step>] [--feature <slug>]');
62
- const feature = loadFeature(ctx.root, selectFeature(ctx.root, ctx.config, values.feature));
63
- const records = feature.reviews.records.filter((r) => !values.step || r.step === values.step);
64
- const record = records.at(-1);
65
- if (!record) throw new AgjanError(`no review recorded for ${feature.slug}${values.step ? ` (step ${values.step})` : ''}`);
66
- const { limit } = roundState(feature, ctx.config, record.step);
67
- const status = new Map(feature.findings.map((f) => [f.id, f.status]));
68
- const out = [`**🔍 Review ${record.id} · ${record.step} · round ${record.round} of ${limit} · ${VERDICT[record.verdict]}**`];
69
- const isolation = record.reviewer?.isolation === 'agent' ? 'isolated' : `isolation ${record.reviewer?.isolation ?? 'unknown'}`;
70
- out.push(`- reviewer: ${reviewerFor(ctx.config, record.step)} on ${record.reviewer?.host ?? 'unknown host'}, ${isolation}`);
71
- const order = { blocker: 0, major: 1, minor: 2 };
72
- for (const f of [...record.findings].sort((a, b) => order[a.severity] - order[b.severity])) {
73
- const where = f.file ? ` · \`${f.file}${f.line ? `:${f.line}` : ''}\`` : '';
74
- const state = status.get(f.id) === 'open' ? '' : ` (${status.get(f.id)})`;
75
- out.push(`- ${SEVERITY[f.severity]} **${f.id}** ${f.severity}${state}${where} · ${oneLine(f.issue)}`);
76
- }
77
- if (!record.findings.length) out.push('- no findings');
78
- if (record.resolves?.length) out.push(`- ✅ resolved: ${record.resolves.join(', ')}`);
79
- const mine = new Set(record.findings.map((f) => f.id));
80
- const earlier = feature.findings.filter((f) => f.step === record.step && f.status === 'open' && !mine.has(f.id));
81
- if (earlier.length) out.push(`- still open from earlier rounds: ${earlier.map((f) => `${SEVERITY[f.severity]} ${f.id}`).join(', ')}`);
82
- // The rounds of this correction loop, oldest first: shows the cycles between the agents.
83
- const step = feature.reviews.records.filter((r) => r.step === record.step && r.at_utc <= record.at_utc);
84
- const start = step.findLastIndex((r) => r.round === 1);
85
- const loop = step.slice(Math.max(start, 0));
86
- if (loop.length > 1) out.push(`- rounds: ${loop.map((r) => `${r.id} ${MARK[r.verdict]}`).join(' → ')}`);
87
- out.push(`- ➜ next: ${nextAfter(feature, ctx.config, record)}`);
88
- ctx.out(highlightMarkdown(ctx.style, out.join('\n')));
89
- return 0;
90
- }
91
-
92
- /**
93
- * agjan review extend <step> [--feature <slug>]: one more correction round for a step
94
- * that is still blocked at its round limit (design 7.4). The agent runs it only after
95
- * the user said yes to another round; status, the report and the PR summary show it.
96
- */
97
- export function extend(ctx, argv) {
98
- const { values, positionals } = parseArgs({ args: argv, options: { feature: { type: 'string' } }, allowPositionals: true });
99
- if (positionals.length !== 1) throw new UsageError('usage: agjan review extend <step> [--feature <slug>]');
100
- const step = positionals[0];
101
- const feature = loadFeature(ctx.root, selectFeature(ctx.root, ctx.config, values.feature));
102
- const state = roundState(feature, ctx.config, step);
103
- if (!state.exhausted) {
104
- const why = state.last ? `round ${state.round} of ${state.limit}, ${state.last.verdict}` : 'no review yet';
105
- throw new AgjanError(`the ${step} review has not used up its rounds (${why}); another round needs no extension`);
106
- }
107
- appendLog(feature.dir, ctx.now(), 'round-granted', { step, round: state.limit + 1 });
108
- ctx.out(`${ctx.style.green('granted')} round ${state.limit + 1} for ${ctx.style.bold(step)}: fix the blockers, then ask for the review again`);
109
- return 0;
110
- }
111
-
112
- /**
113
- * agjan review show [--step <step>] [--feature <slug>]: read-only. Without --step it lists
114
- * the review records; with --step it prints the context a reviewer would get.
115
- * There is deliberately no CLI command that records a review.
116
- */
117
- export function show(ctx, argv) {
118
- const { values, positionals } = parseArgs({
119
- args: argv,
120
- options: { step: { type: 'string' }, feature: { type: 'string' } },
121
- allowPositionals: true,
122
- });
123
- if (positionals[0] !== 'show' || positionals.length !== 1) throw new UsageError('usage: agjan review show [--step <step>] [--feature <slug>] | agjan review extend <step>');
124
- const feature = loadFeature(ctx.root, selectFeature(ctx.root, ctx.config, values.feature));
125
- if (values.step) {
126
- ctx.out(buildContextText(ctx.root, ctx.config, feature, parseStep(values.step, feature, ctx.config)));
127
- return 0;
128
- }
129
- if (feature.reviews.records.length === 0) {
130
- ctx.out(`no reviews recorded for ${feature.slug}`);
131
- return 0;
132
- }
133
- const status = new Map(feature.findings.map((f) => [f.id, f.status]));
134
- for (const r of feature.reviews.records) {
135
- const st = ctx.style;
136
- const meta = st.gray(`(${r.at_utc}, ${r.reviewer?.host ?? '?'}, isolation ${r.reviewer?.isolation ?? '?'})`);
137
- ctx.out(`${st.bold(r.id)} ${r.step} round ${r.round}: ${tone(st, r.verdict)} ${meta}`);
138
- for (const f of r.findings ?? []) ctx.out(` ${st.cyan(f.id)} [${tone(st, f.severity)}] ${tone(st, status.get(f.id))}: ${f.issue}`);
139
- }
140
- return 0;
141
- }