agjan 0.0.10 → 0.0.12
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/README.md +2 -2
- package/bin/agjan.mjs +9 -2
- package/dist/adapters/claude-code.js +105 -0
- package/dist/adapters/copilot.js +80 -0
- package/dist/auto.js +24 -0
- package/dist/baseline.js +66 -0
- package/dist/browser.js +46 -0
- package/dist/cli.js +164 -0
- package/dist/commands/branch.js +71 -0
- package/dist/commands/check.js +420 -0
- package/dist/commands/fix.js +122 -0
- package/dist/commands/gates.js +462 -0
- package/dist/commands/lint.js +76 -0
- package/dist/commands/log.js +72 -0
- package/dist/commands/map.js +47 -0
- package/dist/commands/new.js +65 -0
- package/dist/commands/pr-summary.js +168 -0
- package/dist/commands/progress.js +42 -0
- package/dist/commands/report.js +105 -0
- package/dist/commands/review.js +146 -0
- package/dist/commands/setup.js +393 -0
- package/dist/commands/status.js +303 -0
- package/dist/commands/ui-test.js +39 -0
- package/dist/config.js +110 -0
- package/dist/context.js +56 -0
- package/dist/copilot-mcp.js +56 -0
- package/dist/documents.js +207 -0
- package/dist/errors.js +15 -0
- package/dist/feature.js +221 -0
- package/dist/fix.js +117 -0
- package/dist/git.js +88 -0
- package/{src/hash.mjs → dist/hash.js} +11 -14
- package/dist/hook.js +47 -0
- package/dist/json-file.js +26 -0
- package/dist/log.js +50 -0
- package/dist/managed.js +182 -0
- package/dist/mcp-config.js +76 -0
- package/dist/mcp.js +142 -0
- package/dist/plan.js +40 -0
- package/dist/progress-view.js +494 -0
- package/dist/progress.js +106 -0
- package/{src/review-policy.mjs → dist/review-policy.js} +39 -47
- package/dist/review.js +435 -0
- package/dist/scope.js +30 -0
- package/dist/terminal.js +127 -0
- package/dist/test-results.js +101 -0
- package/dist/tests-map.js +29 -0
- package/dist/types.js +5 -0
- package/dist/ui.js +136 -0
- package/dist/usage.js +116 -0
- package/dist/validate.js +46 -0
- package/docs/guide.md +98 -37
- package/kit/domains/btp/domain.json +4 -4
- package/kit/hooks/guard.mjs +48 -119
- package/kit/skills/agjan-build/SKILL.md +14 -8
- package/kit/skills/agjan-design/SKILL.md +42 -6
- package/kit/skills/agjan-fix/SKILL.md +9 -10
- package/kit/skills/agjan-map/SKILL.md +9 -10
- package/kit/skills/agjan-spec/SKILL.md +22 -11
- package/kit/skills/agjan-verify/SKILL.md +46 -19
- package/kit/skills/cap-developer/SKILL.md +10 -2
- package/kit/skills/cap-developer/references/handlers.md +11 -9
- package/kit/skills/cap-developer/references/project-setup.md +21 -8
- package/kit/skills/cap-developer/references/testing.md +38 -14
- package/kit/skills/cap-developer/references/typescript.md +143 -0
- package/kit/skills/cap-developer/references/validation-security.md +26 -8
- package/kit/skills/fiori-developer/SKILL.md +20 -5
- package/kit/skills/fiori-developer/references/app-setup.md +91 -16
- package/kit/skills/fiori-developer/references/elements.md +19 -5
- package/kit/skills/fiori-developer/references/freestyle-ts.md +5 -1
- package/kit/skills/fiori-developer/references/testing.md +109 -15
- package/kit/templates/agents-block.md +7 -3
- package/package.json +11 -3
- package/schemas/approvals.schema.json +23 -2
- package/schemas/config.schema.json +0 -5
- package/schemas/log.schema.json +1 -1
- package/src/adapters/claude-code.mjs +0 -121
- package/src/adapters/copilot.mjs +0 -89
- package/src/baseline.mjs +0 -66
- package/src/cli.mjs +0 -155
- package/src/commands/branch.mjs +0 -60
- package/src/commands/check.mjs +0 -365
- package/src/commands/fix.mjs +0 -116
- package/src/commands/gates.mjs +0 -264
- package/src/commands/lint.mjs +0 -74
- package/src/commands/log.mjs +0 -60
- package/src/commands/map.mjs +0 -47
- package/src/commands/new.mjs +0 -53
- package/src/commands/pr-summary.mjs +0 -137
- package/src/commands/progress.mjs +0 -40
- package/src/commands/report.mjs +0 -115
- package/src/commands/review.mjs +0 -76
- package/src/commands/setup.mjs +0 -383
- package/src/commands/status.mjs +0 -248
- package/src/config.mjs +0 -122
- package/src/context.mjs +0 -67
- package/src/copilot-mcp.mjs +0 -56
- package/src/documents.mjs +0 -188
- package/src/errors.mjs +0 -16
- package/src/feature.mjs +0 -225
- package/src/fix.mjs +0 -108
- package/src/git.mjs +0 -83
- package/src/hook.mjs +0 -48
- package/src/json-file.mjs +0 -24
- package/src/log.mjs +0 -51
- package/src/managed.mjs +0 -178
- package/src/mcp-config.mjs +0 -83
- package/src/mcp.mjs +0 -147
- package/src/plan.mjs +0 -45
- package/src/progress-view.mjs +0 -466
- package/src/progress.mjs +0 -85
- package/src/review.mjs +0 -413
- package/src/scope.mjs +0 -30
- package/src/terminal.mjs +0 -118
- package/src/test-results.mjs +0 -111
- package/src/tests-map.mjs +0 -29
- package/src/ui.mjs +0 -136
- package/src/usage.mjs +0 -118
- 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
|
-
}
|
package/src/commands/report.mjs
DELETED
|
@@ -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
|
-
}
|
package/src/commands/review.mjs
DELETED
|
@@ -1,76 +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 { roundState } from '../review-policy.mjs';
|
|
7
|
-
import { 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 | extend: dispatches to the subcommand. */
|
|
23
|
-
export function run(ctx, argv) {
|
|
24
|
-
return argv[0] === 'extend' ? extend(ctx, argv.slice(1)) : show(ctx, argv);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* agjan review extend <step> [--feature <slug>]: one more correction round for a step
|
|
29
|
-
* that is still blocked at its round limit (design 7.4). The agent runs it only after
|
|
30
|
-
* the user said yes to another round; status, the report and the PR summary show it.
|
|
31
|
-
*/
|
|
32
|
-
export function extend(ctx, argv) {
|
|
33
|
-
const { values, positionals } = parseArgs({ args: argv, options: { feature: { type: 'string' } }, allowPositionals: true });
|
|
34
|
-
if (positionals.length !== 1) throw new UsageError('usage: agjan review extend <step> [--feature <slug>]');
|
|
35
|
-
const step = positionals[0];
|
|
36
|
-
const feature = loadFeature(ctx.root, selectFeature(ctx.root, ctx.config, values.feature));
|
|
37
|
-
const state = roundState(feature, ctx.config, step);
|
|
38
|
-
if (!state.exhausted) {
|
|
39
|
-
const why = state.last ? `round ${state.round} of ${state.limit}, ${state.last.verdict}` : 'no review yet';
|
|
40
|
-
throw new AgjanError(`the ${step} review has not used up its rounds (${why}); another round needs no extension`);
|
|
41
|
-
}
|
|
42
|
-
appendLog(feature.dir, ctx.now(), 'round-granted', { step, round: state.limit + 1 });
|
|
43
|
-
ctx.out(`${ctx.style.green('granted')} round ${state.limit + 1} for ${ctx.style.bold(step)}: fix the blockers, then ask for the review again`);
|
|
44
|
-
return 0;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* agjan review show [--step <step>] [--feature <slug>]: read-only. Without --step it lists
|
|
49
|
-
* the review records; with --step it prints the context a reviewer would get.
|
|
50
|
-
* There is deliberately no CLI command that records a review.
|
|
51
|
-
*/
|
|
52
|
-
export function show(ctx, argv) {
|
|
53
|
-
const { values, positionals } = parseArgs({
|
|
54
|
-
args: argv,
|
|
55
|
-
options: { step: { type: 'string' }, feature: { type: 'string' } },
|
|
56
|
-
allowPositionals: true,
|
|
57
|
-
});
|
|
58
|
-
if (positionals[0] !== 'show' || positionals.length !== 1) throw new UsageError('usage: agjan review show [--step <step>] [--feature <slug>] | agjan review extend <step>');
|
|
59
|
-
const feature = loadFeature(ctx.root, selectFeature(ctx.root, ctx.config, values.feature));
|
|
60
|
-
if (values.step) {
|
|
61
|
-
ctx.out(buildContextText(ctx.root, ctx.config, feature, parseStep(values.step, feature, ctx.config)));
|
|
62
|
-
return 0;
|
|
63
|
-
}
|
|
64
|
-
if (feature.reviews.records.length === 0) {
|
|
65
|
-
ctx.out(`no reviews recorded for ${feature.slug}`);
|
|
66
|
-
return 0;
|
|
67
|
-
}
|
|
68
|
-
const status = new Map(feature.findings.map((f) => [f.id, f.status]));
|
|
69
|
-
for (const r of feature.reviews.records) {
|
|
70
|
-
const st = ctx.style;
|
|
71
|
-
const meta = st.gray(`(${r.at_utc}, ${r.reviewer?.host ?? '?'}, isolation ${r.reviewer?.isolation ?? '?'})`);
|
|
72
|
-
ctx.out(`${st.bold(r.id)} ${r.step} round ${r.round}: ${tone(st, r.verdict)} ${meta}`);
|
|
73
|
-
for (const f of r.findings ?? []) ctx.out(` ${st.cyan(f.id)} [${tone(st, f.severity)}] ${tone(st, status.get(f.id))}: ${f.issue}`);
|
|
74
|
-
}
|
|
75
|
-
return 0;
|
|
76
|
-
}
|
package/src/commands/setup.mjs
DELETED
|
@@ -1,383 +0,0 @@
|
|
|
1
|
-
import { spawnSync } from 'node:child_process';
|
|
2
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { homedir } from 'node:os';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
import { fileURLToPath } from 'node:url';
|
|
6
|
-
import { parseArgs } from 'node:util';
|
|
7
|
-
import { CONFIG_FILE, MODEL_TIERS, RECOMMENDED_ALLOW, SESSION_MODEL, agentModel, loadConfig, loadDomain } from '../config.mjs';
|
|
8
|
-
import { LEGACY_MODELS as CLAUDE_LEGACY } from '../adapters/claude-code.mjs';
|
|
9
|
-
import { LEGACY_MODELS as COPILOT_LEGACY } from '../adapters/copilot.mjs';
|
|
10
|
-
import { readJson, writeJson } from '../json-file.mjs';
|
|
11
|
-
import { applyPlan, planStatus } from '../managed.mjs';
|
|
12
|
-
import { ADAPTERS, buildPlan, unsupportedHosts } from '../plan.mjs';
|
|
13
|
-
import { hookStatus, installHook } from '../hook.mjs';
|
|
14
|
-
import { GUARD } from '../adapters/copilot.mjs';
|
|
15
|
-
import { git, mergeBase, resolveBase } from '../git.mjs';
|
|
16
|
-
import { AgjanError, UsageError } from '../errors.mjs';
|
|
17
|
-
import { blink, mark, pad, tone, verdictColor } from '../ui.mjs';
|
|
18
|
-
import { mcpServers } from '../mcp-config.mjs';
|
|
19
|
-
import { addCommand, addCopilotServers, copilotServers } from '../copilot-mcp.mjs';
|
|
20
|
-
|
|
21
|
-
const CI_FILE = '.github/workflows/agjan.yml';
|
|
22
|
-
const CI_TEMPLATE = new URL('../../kit/templates/agjan-ci.yml', import.meta.url);
|
|
23
|
-
const BIN = fileURLToPath(new URL('../../bin/agjan.mjs', import.meta.url));
|
|
24
|
-
|
|
25
|
-
function list(value) {
|
|
26
|
-
return value ? value.split(',').map((v) => v.trim()).filter(Boolean) : null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function printResults(ctx, results) {
|
|
30
|
-
const s = ctx.style;
|
|
31
|
-
for (const r of results) {
|
|
32
|
-
if (r.action === 'unchanged') continue;
|
|
33
|
-
const [word, ...rest] = r.action.split(' ');
|
|
34
|
-
ctx.out(` ${pad([tone(s, word), ...rest].join(' '), r.action, 14)} ${r.path}`);
|
|
35
|
-
}
|
|
36
|
-
const unchanged = results.filter((r) => r.action === 'unchanged').length;
|
|
37
|
-
if (unchanged) ctx.out(s.gray(` ${unchanged} file(s) unchanged`));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const ADAPTER_LEGACY_MODELS = { 'claude-code': CLAUDE_LEGACY, copilot: COPILOT_LEGACY };
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Missing `models.<host>` entries for the configured hosts, so the reviewer models are
|
|
44
|
-
* visible in agjan.config.json. New projects get "session"; a project from an earlier
|
|
45
|
-
* version gets what it used implicitly (Claude Code: sonnet and opus), so nothing changes.
|
|
46
|
-
*/
|
|
47
|
-
function missingModels(raw, hosts, { existing }) {
|
|
48
|
-
const added = {};
|
|
49
|
-
for (const host of hosts) {
|
|
50
|
-
if (raw.models?.[host]) continue;
|
|
51
|
-
const legacy = existing ? ADAPTER_LEGACY_MODELS[host] ?? {} : {};
|
|
52
|
-
added[host] = Object.fromEntries(MODEL_TIERS.map((tier) => [tier, legacy[tier] ?? SESSION_MODEL]));
|
|
53
|
-
}
|
|
54
|
-
return added;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Settings that decide what agents may do without asking, written visibly into an
|
|
59
|
-
* existing configuration that lacks them, with the behavior it had (design decision 69).
|
|
60
|
-
*/
|
|
61
|
-
function missingSettings(raw) {
|
|
62
|
-
const out = [];
|
|
63
|
-
if (raw.agent?.allow === undefined || raw.agent?.allow_edits === undefined) out.push('agent');
|
|
64
|
-
return out;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** Writes the managed files for the current configuration and updates the recorded kit version. */
|
|
68
|
-
function doSync(ctx, { force }) {
|
|
69
|
-
const config = loadConfig(ctx.root);
|
|
70
|
-
for (const host of unsupportedHosts(config)) ctx.err(`agjan: host '${host}' has no adapter in this version; skipped`);
|
|
71
|
-
const file = join(ctx.root, CONFIG_FILE);
|
|
72
|
-
const raw = readJson(file) ?? {};
|
|
73
|
-
const added = missingModels(raw, config.hosts, { existing: Boolean(raw.models) || raw.kit !== ctx.kit });
|
|
74
|
-
const visible = missingSettings(raw);
|
|
75
|
-
if (Object.keys(added).length || visible.length) {
|
|
76
|
-
const next = { ...raw, models: { ...(raw.models ?? {}), ...added } };
|
|
77
|
-
if (visible.includes('agent')) next.agent = { allow: raw.agent?.allow ?? [], allow_edits: raw.agent?.allow_edits ?? false, ...(raw.agent ?? {}) };
|
|
78
|
-
writeJson(file, next);
|
|
79
|
-
config.models = { ...(config.models ?? {}), ...added };
|
|
80
|
-
}
|
|
81
|
-
const results = applyPlan(ctx.root, buildPlan(config), { kit: ctx.kit, force });
|
|
82
|
-
for (const [host, tiers] of Object.entries(added)) {
|
|
83
|
-
results.push({ path: CONFIG_FILE, action: `models.${host}: ${MODEL_TIERS.map((t) => `${t}=${tiers[t]}`).join(', ')}` });
|
|
84
|
-
}
|
|
85
|
-
if (visible.includes('agent')) results.push({ path: CONFIG_FILE, action: 'agent: allow, allow_edits' });
|
|
86
|
-
const current = readJson(file) ?? {};
|
|
87
|
-
if (current.kit !== ctx.kit) {
|
|
88
|
-
writeJson(file, { ...current, kit: ctx.kit });
|
|
89
|
-
results.push({ path: CONFIG_FILE, action: current.kit ? `kit ${current.kit} -> ${ctx.kit}` : `kit ${ctx.kit}` });
|
|
90
|
-
}
|
|
91
|
-
return results;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** Asks a yes/no question; null without a terminal (scripts, CI, agents). */
|
|
95
|
-
function ask(ctx, question, options) {
|
|
96
|
-
return ctx.ask(question, options);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/** The next steps after init, for the configured hosts (design decision 69). */
|
|
100
|
-
function nextSteps(ctx, hosts, firstCommit) {
|
|
101
|
-
const s = ctx.style;
|
|
102
|
-
const steps = [
|
|
103
|
-
firstCommit
|
|
104
|
-
? `Commit the setup: ${s.cyan('git add -A && git commit -m "chore: set up agjan"')}`
|
|
105
|
-
: `Commit the setup on a branch of its own and merge it with a PR: ${s.cyan('git add -A && git commit -m "chore: set up agjan"')}`,
|
|
106
|
-
];
|
|
107
|
-
if (hosts.includes('claude-code')) {
|
|
108
|
-
steps.push("Open this folder once in Claude Code and trust it: the reviewer's agjan tools load only in trusted folders.");
|
|
109
|
-
}
|
|
110
|
-
if (hosts.includes('copilot')) {
|
|
111
|
-
steps.push(`Start ${s.cyan('copilot')} in this folder and trust it. Without agent.allow_edits, answer the first file edit prompt with "don't ask again for file operations", or start ${s.cyan('copilot --allow-tool write')}.`);
|
|
112
|
-
}
|
|
113
|
-
steps.push(`Run: ${s.cyan('npx agjan doctor')}`);
|
|
114
|
-
return ['', s.bold('Next steps:'), ...steps.map((text, i) => ` ${i + 1}. ${text}`)];
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* agjan init [--domains btp] [--hosts claude-code] [--language en] [--base <ref>] [--no-hook] [--no-ci]
|
|
119
|
-
* [--prepare] [--agent-allow | --no-agent-allow] [--agent-allow-edits | --no-agent-allow-edits]
|
|
120
|
-
*/
|
|
121
|
-
export async function init(ctx, argv) {
|
|
122
|
-
const { values } = parseArgs({
|
|
123
|
-
args: argv,
|
|
124
|
-
options: {
|
|
125
|
-
domains: { type: 'string' },
|
|
126
|
-
hosts: { type: 'string' },
|
|
127
|
-
language: { type: 'string' },
|
|
128
|
-
base: { type: 'string' },
|
|
129
|
-
'no-hook': { type: 'boolean' },
|
|
130
|
-
'no-ci': { type: 'boolean' },
|
|
131
|
-
prepare: { type: 'boolean' },
|
|
132
|
-
'agent-allow': { type: 'boolean' },
|
|
133
|
-
'no-agent-allow': { type: 'boolean' },
|
|
134
|
-
'agent-allow-edits': { type: 'boolean' },
|
|
135
|
-
'no-agent-allow-edits': { type: 'boolean' },
|
|
136
|
-
'copilot-mcp': { type: 'boolean' },
|
|
137
|
-
'no-copilot-mcp': { type: 'boolean' },
|
|
138
|
-
},
|
|
139
|
-
});
|
|
140
|
-
const root = ctx.root;
|
|
141
|
-
if (existsSync(join(root, CONFIG_FILE))) throw new AgjanError(`${CONFIG_FILE} already exists; run 'agjan sync' to update the managed files`);
|
|
142
|
-
const domains = list(values.domains) ?? ['btp'];
|
|
143
|
-
for (const d of domains) loadDomain(d);
|
|
144
|
-
const hosts = list(values.hosts) ?? ['claude-code'];
|
|
145
|
-
for (const h of hosts) if (!ADAPTERS[h]) throw new UsageError(`host '${h}' is not supported in this version (supported: ${Object.keys(ADAPTERS).join(', ')})`);
|
|
146
|
-
|
|
147
|
-
// The mark first, then the questions (design decision 69).
|
|
148
|
-
const s = ctx.style;
|
|
149
|
-
const lines = mark(s, ctx.kit, 'setting up this repository');
|
|
150
|
-
for (const line of lines) ctx.out(line);
|
|
151
|
-
await blink(ctx, lines);
|
|
152
|
-
|
|
153
|
-
// Opt-in decisions, asked once. Enter takes the recommended answer (yes); without a
|
|
154
|
-
// terminal the safe defaults (no) apply. They are written visibly, so the team sees
|
|
155
|
-
// and can change them.
|
|
156
|
-
const flag = (yes, no) => (values[yes] ? true : values[no] ? false : null);
|
|
157
|
-
const agentAllow = flag('agent-allow', 'no-agent-allow') ??
|
|
158
|
-
ask(ctx, `Let agents run these commands without a prompt: ${RECOMMENDED_ALLOW.join(', ')}?\n(agjan approve, accept and reject stay blocked; change agent.allow in ${CONFIG_FILE} later.)`, { defaultYes: true }) ?? false;
|
|
159
|
-
const allowEdits = flag('agent-allow-edits', 'no-agent-allow-edits') ??
|
|
160
|
-
ask(ctx, 'Let agents change files in this project without a prompt?\n(agjan records and policy files excluded; agjan checks the scope of every change.)', { defaultYes: true }) ?? false;
|
|
161
|
-
// Copilot loads the project's .mcp.json only in folders it remembers as trusted; its
|
|
162
|
-
// user configuration loads everywhere (decision 72).
|
|
163
|
-
const areas = Object.fromEntries(domains.flatMap((d) => Object.keys(loadDomain(d).areas).flatMap((a) => [[a, {}], [`${d}:${a}`, {}]])));
|
|
164
|
-
const servers = Object.keys(mcpServers({ areas }).servers);
|
|
165
|
-
const copilotMcp = hosts.includes('copilot') && servers.length > 0 && (flag('copilot-mcp', 'no-copilot-mcp') ??
|
|
166
|
-
ask(ctx, `Add the documentation MCP servers ${servers.join(', ')} to your Copilot configuration (copilot mcp add)?\n(Copilot loads a project's .mcp.json only in folders it remembers as trusted; these then load in every Copilot session.)`, { defaultYes: true }) ?? false);
|
|
167
|
-
|
|
168
|
-
const config = {
|
|
169
|
-
$schema: './node_modules/agjan/schemas/config.schema.json',
|
|
170
|
-
kit: ctx.kit,
|
|
171
|
-
domains,
|
|
172
|
-
hosts,
|
|
173
|
-
language: values.language ?? 'en',
|
|
174
|
-
models: missingModels({}, hosts, { existing: false }),
|
|
175
|
-
git: { ...(values.base ? { base: values.base } : {}) },
|
|
176
|
-
agent: { allow: agentAllow ? RECOMMENDED_ALLOW : [], allow_edits: allowEdits },
|
|
177
|
-
};
|
|
178
|
-
writeJson(join(root, CONFIG_FILE), config);
|
|
179
|
-
ctx.out('', `${s.bold('agjan init')}: ${CONFIG_FILE} (domains ${domains.join(', ')}; hosts ${hosts.join(', ')})`);
|
|
180
|
-
|
|
181
|
-
printResults(ctx, doSync(ctx, { force: false }));
|
|
182
|
-
const setting = (on, text) => ` ${pad(on ? tone(s, 'created') : s.gray('none'), on ? 'created' : 'none', 14)} ${text}`;
|
|
183
|
-
ctx.out(setting(agentAllow, `agent.allow${agentAllow ? ` (${RECOMMENDED_ALLOW.length} commands)` : ''}`));
|
|
184
|
-
ctx.out(setting(allowEdits, `agent.allow_edits${allowEdits ? ' (file changes without a prompt)' : ''}`));
|
|
185
|
-
if (copilotMcp) addToCopilot(ctx, loadConfig(root));
|
|
186
|
-
|
|
187
|
-
if (!values['no-hook']) {
|
|
188
|
-
const hook = installHook(root);
|
|
189
|
-
ctx.out(` ${pad(tone(s, hook.action), hook.action, 14)} pre-commit hook`);
|
|
190
|
-
}
|
|
191
|
-
if (values.prepare) ctx.out(` package.json ${addPrepare(root)}`);
|
|
192
|
-
if (!values['no-ci']) {
|
|
193
|
-
const ci = join(root, CI_FILE);
|
|
194
|
-
if (existsSync(ci)) {
|
|
195
|
-
ctx.out(` ${pad(s.gray('unchanged'), 'unchanged', 14)} ${CI_FILE} (exists)`);
|
|
196
|
-
} else {
|
|
197
|
-
mkdirSync(join(ci, '..'), { recursive: true });
|
|
198
|
-
writeFileSync(ci, readFileSync(CI_TEMPLATE, 'utf8'));
|
|
199
|
-
ctx.out(` ${pad(tone(s, 'created'), 'created', 14)} ${CI_FILE}`);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const pkg = readJson(join(root, 'package.json'));
|
|
204
|
-
if (!pkg?.devDependencies?.agjan && !pkg?.dependencies?.agjan) {
|
|
205
|
-
ctx.out('', s.yellow('Pin agjan in this project so every developer and CI use the same version:'), ` ${s.cyan('npm install --save-dev agjan')}`);
|
|
206
|
-
}
|
|
207
|
-
const firstCommit = git(root, ['rev-parse', '--verify', '--quiet', 'HEAD'], { allowFail: true }) === null;
|
|
208
|
-
ctx.out(...nextSteps(ctx, hosts, firstCommit));
|
|
209
|
-
return 0;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function addPrepare(root) {
|
|
213
|
-
const file = join(root, 'package.json');
|
|
214
|
-
const pkg = readJson(file);
|
|
215
|
-
if (!pkg) return 'no package.json; prepare script not added';
|
|
216
|
-
const command = 'agjan hook install';
|
|
217
|
-
const current = pkg.scripts?.prepare;
|
|
218
|
-
if (current?.includes(command)) return 'prepare script already installs the hook';
|
|
219
|
-
if (current) return `prepare script exists; add '&& ${command}' to it yourself`;
|
|
220
|
-
writeJson(file, { ...pkg, scripts: { ...(pkg.scripts ?? {}), prepare: command } });
|
|
221
|
-
return `added "prepare": "${command}"`;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Adds the documentation MCP servers to Copilot's user configuration and reports each:
|
|
226
|
-
* added, already there (left as it is), or failed with the command to run by hand.
|
|
227
|
-
*/
|
|
228
|
-
function addToCopilot(ctx, config) {
|
|
229
|
-
const s = ctx.style;
|
|
230
|
-
const { servers } = mcpServers(config);
|
|
231
|
-
for (const r of addCopilotServers(servers)) {
|
|
232
|
-
const action = r.state === 'added' ? 'created' : r.state === 'exists' ? 'unchanged' : 'failed';
|
|
233
|
-
ctx.out(` ${pad(tone(s, action), action, 14)} copilot mcp ${r.name}: ${r.detail}`);
|
|
234
|
-
if (r.state === 'failed') ctx.out(` ${' '.repeat(14)} add it yourself: ${s.cyan(addCommand(r.name, servers[r.name]).join(' '))}`);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/** agjan sync [--force] [--copilot-mcp]: regenerate managed files; edited ones are kept unless --force. */
|
|
239
|
-
export function sync(ctx, argv) {
|
|
240
|
-
const { values } = parseArgs({ args: argv, options: { force: { type: 'boolean' }, 'copilot-mcp': { type: 'boolean' } } });
|
|
241
|
-
if (!existsSync(join(ctx.root, CONFIG_FILE))) throw new AgjanError(`no ${CONFIG_FILE}; run 'agjan init' first`);
|
|
242
|
-
ctx.out(`${ctx.style.bold('agjan sync')}:`);
|
|
243
|
-
const results = doSync(ctx, { force: values.force });
|
|
244
|
-
printResults(ctx, results);
|
|
245
|
-
if (values['copilot-mcp']) addToCopilot(ctx, ctx.config);
|
|
246
|
-
return results.some((r) => r.action.startsWith('kept')) ? 1 : 0;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/** agjan hook install */
|
|
250
|
-
export function hook(ctx, argv) {
|
|
251
|
-
if (argv[0] !== 'install' || argv.length !== 1) throw new UsageError('usage: agjan hook install');
|
|
252
|
-
const result = installHook(ctx.root);
|
|
253
|
-
ctx.out(`${ctx.style.bold('agjan hook')}: ${tone(ctx.style, result.action)} (${result.path})`);
|
|
254
|
-
return result.state === 'installed' ? 0 : 1;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
/** Starts the agjan MCP server and checks that it answers initialize and lists its tools. */
|
|
258
|
-
function probeMcp(root) {
|
|
259
|
-
const input = [
|
|
260
|
-
{ jsonrpc: '2.0', id: 1, method: 'initialize', params: { protocolVersion: '2025-11-25', capabilities: {}, clientInfo: { name: 'agjan-doctor', version: '1' } } },
|
|
261
|
-
{ jsonrpc: '2.0', id: 2, method: 'tools/list' },
|
|
262
|
-
].map((m) => JSON.stringify(m)).join('\n');
|
|
263
|
-
const run = spawnSync(process.execPath, [BIN, 'mcp'], { cwd: root, input: `${input}\n`, encoding: 'utf8', timeout: 10_000 });
|
|
264
|
-
try {
|
|
265
|
-
const lines = run.stdout.trim().split('\n').map((l) => JSON.parse(l));
|
|
266
|
-
const tools = lines.find((l) => l.id === 2)?.result?.tools?.map((t) => t.name) ?? [];
|
|
267
|
-
return tools.includes('review_record') ? null : `unexpected answer: ${run.stdout.slice(0, 200)}`;
|
|
268
|
-
} catch {
|
|
269
|
-
return `did not answer: ${(run.stderr || run.error?.message || '').trim().slice(0, 200)}`;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/** Runs the Copilot guard hook the way Copilot does, with a payload it must deny. */
|
|
274
|
-
function probeGuard(root) {
|
|
275
|
-
const payload = JSON.stringify({ toolName: 'bash', toolArgs: { command: 'npx agjan approve spec' } });
|
|
276
|
-
const run = spawnSync(process.execPath, [join(root, GUARD)], { cwd: root, input: payload, encoding: 'utf8', timeout: 10_000 });
|
|
277
|
-
if (run.status !== 0) return `${GUARD} did not run (is agjan installed locally?); the hook then allows every command`;
|
|
278
|
-
return run.stdout.includes('"deny"') ? null : `unexpected answer: ${run.stdout.slice(0, 120)}`;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/** Whether Claude Code has the project folder trusted, from ~/.claude.json (read-only). */
|
|
282
|
-
function claudeTrust(root) {
|
|
283
|
-
const data = readJson(join(homedir(), '.claude.json'));
|
|
284
|
-
if (!data?.projects) return 'unknown';
|
|
285
|
-
return data.projects[root]?.hasTrustDialogAccepted === true ? 'trusted' : 'not trusted';
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
/** agjan doctor: checks the environment and the project setup; exit 1 on any failure. */
|
|
289
|
-
export function doctor(ctx) {
|
|
290
|
-
for (const line of mark(ctx.style, ctx.kit, 'doctor: environment and project setup')) ctx.out(line);
|
|
291
|
-
const rows = [];
|
|
292
|
-
const ok = (what, detail = '') => rows.push(['ok', what, detail]);
|
|
293
|
-
const warn = (what, detail) => rows.push(['warn', what, detail]);
|
|
294
|
-
const fail = (what, detail) => rows.push(['fail', what, detail]);
|
|
295
|
-
|
|
296
|
-
const major = Number(process.versions.node.split('.')[0]);
|
|
297
|
-
if (major >= 22) ok('node', process.versions.node);
|
|
298
|
-
else fail('node', `${process.versions.node}; agjan needs Node 22 or later`);
|
|
299
|
-
const gitVersion = spawnSync('git', ['--version'], { encoding: 'utf8' });
|
|
300
|
-
if (gitVersion.status === 0) ok('git', gitVersion.stdout.trim().replace(/^git version /, ''));
|
|
301
|
-
else fail('git', 'not found on PATH');
|
|
302
|
-
|
|
303
|
-
let root;
|
|
304
|
-
try {
|
|
305
|
-
root = ctx.root;
|
|
306
|
-
} catch (error) {
|
|
307
|
-
fail('repository', error.message);
|
|
308
|
-
}
|
|
309
|
-
if (root) {
|
|
310
|
-
ok('agjan', ctx.kit);
|
|
311
|
-
const raw = readJson(join(root, CONFIG_FILE));
|
|
312
|
-
if (!raw) {
|
|
313
|
-
fail('configuration', `no ${CONFIG_FILE}; run: npx agjan init`);
|
|
314
|
-
} else {
|
|
315
|
-
const config = loadConfig(root);
|
|
316
|
-
ok('configuration', `domains ${config.domains.join(', ')}; hosts ${config.hosts.join(', ')}`);
|
|
317
|
-
if (raw.kit !== ctx.kit) warn('kit version', `project records ${raw.kit}, installed ${ctx.kit}; run: npx agjan sync`);
|
|
318
|
-
const local = readJson(join(root, 'node_modules', 'agjan', 'package.json'));
|
|
319
|
-
if (!local) warn('local install', 'agjan is not installed in node_modules; run: npm install --save-dev agjan');
|
|
320
|
-
else if (local.version !== ctx.kit) warn('local install', `node_modules has ${local.version}, this command is ${ctx.kit}`);
|
|
321
|
-
else ok('local install', local.version);
|
|
322
|
-
|
|
323
|
-
const base = resolveBase(root, config.git?.base);
|
|
324
|
-
const commits = git(root, ['rev-parse', '--verify', '--quiet', 'HEAD'], { allowFail: true }) !== null;
|
|
325
|
-
if (!commits) warn('base branch', 'no commits yet: commit the setup first (git add -A && git commit -m "chore: set up agjan"); main exists after that');
|
|
326
|
-
else if (!base) warn('base branch', `none found; set git.base in ${CONFIG_FILE}`);
|
|
327
|
-
else if (!mergeBase(root, base)) warn('base branch', `${base} has no common history with HEAD (fetch it?)`);
|
|
328
|
-
else ok('base branch', base);
|
|
329
|
-
|
|
330
|
-
const problems = planStatus(root, buildPlan(config)).filter((i) => i.state !== 'ok');
|
|
331
|
-
if (problems.length === 0) ok('managed files', 'up to date');
|
|
332
|
-
for (const p of problems) {
|
|
333
|
-
const fix = p.state === 'modified' ? 'edited locally; agjan sync --force restores it' : 'run: npx agjan sync';
|
|
334
|
-
warn('managed file', `${p.path}: ${p.state}; ${fix}`);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
const hookState = hookStatus(root);
|
|
338
|
-
if (hookState.state === 'installed') ok('pre-commit hook', hookState.kind);
|
|
339
|
-
else warn('pre-commit hook', `${hookState.state}; run: npx agjan hook install`);
|
|
340
|
-
|
|
341
|
-
if (!existsSync(join(root, CI_FILE))) warn('ci', `${CI_FILE} is missing`);
|
|
342
|
-
else ok('ci', CI_FILE);
|
|
343
|
-
|
|
344
|
-
const mcp = probeMcp(root);
|
|
345
|
-
if (mcp) fail('agjan mcp server', mcp);
|
|
346
|
-
else ok('agjan mcp server', 'answers initialize and tools/list');
|
|
347
|
-
|
|
348
|
-
if (config.hosts.includes('copilot')) {
|
|
349
|
-
const guard = probeGuard(root);
|
|
350
|
-
if (guard) warn('copilot guard', guard);
|
|
351
|
-
else ok('copilot guard', 'denies agjan approve in a test payload');
|
|
352
|
-
const names = Object.keys(mcpServers(config).servers);
|
|
353
|
-
const known = names.length ? copilotServers() : {};
|
|
354
|
-
const missing = names.filter((name) => !known?.[name]);
|
|
355
|
-
if (!known) warn('copilot mcp', 'copilot is not on PATH; its MCP servers were not checked');
|
|
356
|
-
else if (missing.length) warn('copilot mcp', `${missing.join(', ')} not in Copilot's configuration (removed?); add: npx agjan sync --copilot-mcp`);
|
|
357
|
-
else if (names.length) ok('copilot mcp', `${names.join(', ')} in Copilot's configuration`);
|
|
358
|
-
}
|
|
359
|
-
if (config.hosts.includes('claude-code')) {
|
|
360
|
-
const trust = claudeTrust(root);
|
|
361
|
-
if (trust === 'trusted') ok('claude code trust', 'project folder trusted');
|
|
362
|
-
else warn('claude code trust', `${trust}; open the folder in Claude Code once and trust it, or the reviewer has no agjan tools`);
|
|
363
|
-
}
|
|
364
|
-
const allow = config.agent?.allow ?? [];
|
|
365
|
-
ok('agent allow list', allow.length ? `${allow.length} command(s) without a prompt: ${allow.join(', ')}` : 'none (the hosts ask for every command)');
|
|
366
|
-
ok('reviewer models', config.hosts.map((h) => `${h}: ${MODEL_TIERS.map((t) => `${t} ${agentModel(config, h, t) ?? 'session model'}`).join(', ')}`).join('; '));
|
|
367
|
-
ok('file edits', config.agent?.allow_edits === true ? 'without a prompt inside the project (agjan records denied, policy files ask)' : 'the host asks for every file change (agent.allow_edits)');
|
|
368
|
-
ok('branches', 'agents ask you, then run npx agjan branch');
|
|
369
|
-
ok('script edits', config.agent?.script_edits === 'allow' ? 'allowed (agent.script_edits)' : 'denied by the guard: agents edit files with their edit tool');
|
|
370
|
-
const tracked = (git(root, ['ls-files', '--', 'node_modules'], { allowFail: true }) ?? '').trim();
|
|
371
|
-
if (tracked) warn('node_modules', 'is committed; remove it: git rm -r -q --cached node_modules && git commit -m "chore: stop tracking node_modules"');
|
|
372
|
-
const ignored = git(root, ['check-ignore', '-q', '.agjan/x'], { allowFail: true }) !== null;
|
|
373
|
-
if (!ignored) warn('.gitignore', '.agjan/ is not ignored; run: npx agjan sync');
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
const s = ctx.style;
|
|
378
|
-
for (const [level, what, detail] of rows) ctx.out(`${pad(tone(s, level), level, 4)} ${pad(s.bold(what), what, 18)} ${detail}`);
|
|
379
|
-
const failed = rows.filter((r) => r[0] === 'fail').length;
|
|
380
|
-
const warned = rows.filter((r) => r[0] === 'warn').length;
|
|
381
|
-
ctx.out(`${s.bold('agjan doctor')}: ${verdictColor(s, failed, warned)(`${failed} failure(s), ${warned} warning(s)`)}`);
|
|
382
|
-
return failed ? 1 : 0;
|
|
383
|
-
}
|