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