agjan 0.0.11 → 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 +62 -38
- package/kit/hooks/guard.mjs +48 -119
- package/kit/skills/agjan-build/SKILL.md +4 -2
- package/kit/skills/agjan-design/SKILL.md +6 -2
- package/kit/skills/agjan-fix/SKILL.md +8 -16
- package/kit/skills/agjan-map/SKILL.md +8 -16
- package/kit/skills/agjan-spec/SKILL.md +21 -17
- package/kit/skills/agjan-verify/SKILL.md +20 -13
- package/kit/templates/agents-block.md +3 -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/browser.mjs +0 -49
- package/src/cli.mjs +0 -165
- package/src/commands/branch.mjs +0 -95
- package/src/commands/check.mjs +0 -376
- package/src/commands/fix.mjs +0 -116
- package/src/commands/gates.mjs +0 -267
- 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 -141
- package/src/commands/setup.mjs +0 -393
- package/src/commands/status.mjs +0 -250
- package/src/commands/ui-test.mjs +0 -38
- 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 -416
- 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
package/src/commands/setup.mjs
DELETED
|
@@ -1,393 +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
|
-
import { UI_SCRIPT, hasUiTests, probeBrowser } from '../browser.mjs';
|
|
21
|
-
|
|
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
|
-
|
|
26
|
-
function list(value) {
|
|
27
|
-
return value ? value.split(',').map((v) => v.trim()).filter(Boolean) : null;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function printResults(ctx, results) {
|
|
31
|
-
const s = ctx.style;
|
|
32
|
-
for (const r of results) {
|
|
33
|
-
if (r.action === 'unchanged') continue;
|
|
34
|
-
const [word, ...rest] = r.action.split(' ');
|
|
35
|
-
ctx.out(` ${pad([tone(s, word), ...rest].join(' '), r.action, 14)} ${r.path}`);
|
|
36
|
-
}
|
|
37
|
-
const unchanged = results.filter((r) => r.action === 'unchanged').length;
|
|
38
|
-
if (unchanged) ctx.out(s.gray(` ${unchanged} file(s) unchanged`));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const ADAPTER_LEGACY_MODELS = { 'claude-code': CLAUDE_LEGACY, copilot: COPILOT_LEGACY };
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Missing `models.<host>` entries for the configured hosts, so the reviewer models are
|
|
45
|
-
* visible in agjan.config.json. New projects get "session"; a project from an earlier
|
|
46
|
-
* version gets what it used implicitly (Claude Code: sonnet and opus), so nothing changes.
|
|
47
|
-
*/
|
|
48
|
-
function missingModels(raw, hosts, { existing }) {
|
|
49
|
-
const added = {};
|
|
50
|
-
for (const host of hosts) {
|
|
51
|
-
if (raw.models?.[host]) continue;
|
|
52
|
-
const legacy = existing ? ADAPTER_LEGACY_MODELS[host] ?? {} : {};
|
|
53
|
-
added[host] = Object.fromEntries(MODEL_TIERS.map((tier) => [tier, legacy[tier] ?? SESSION_MODEL]));
|
|
54
|
-
}
|
|
55
|
-
return added;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Settings that decide what agents may do without asking, written visibly into an
|
|
60
|
-
* existing configuration that lacks them, with the behavior it had (design decision 69).
|
|
61
|
-
*/
|
|
62
|
-
function missingSettings(raw) {
|
|
63
|
-
const out = [];
|
|
64
|
-
if (raw.agent?.allow === undefined || raw.agent?.allow_edits === undefined) out.push('agent');
|
|
65
|
-
return out;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** Writes the managed files for the current configuration and updates the recorded kit version. */
|
|
69
|
-
function doSync(ctx, { force }) {
|
|
70
|
-
const config = loadConfig(ctx.root);
|
|
71
|
-
for (const host of unsupportedHosts(config)) ctx.err(`agjan: host '${host}' has no adapter in this version; skipped`);
|
|
72
|
-
const file = join(ctx.root, CONFIG_FILE);
|
|
73
|
-
const raw = readJson(file) ?? {};
|
|
74
|
-
const added = missingModels(raw, config.hosts, { existing: Boolean(raw.models) || raw.kit !== ctx.kit });
|
|
75
|
-
const visible = missingSettings(raw);
|
|
76
|
-
if (Object.keys(added).length || visible.length) {
|
|
77
|
-
const next = { ...raw, models: { ...(raw.models ?? {}), ...added } };
|
|
78
|
-
if (visible.includes('agent')) next.agent = { allow: raw.agent?.allow ?? [], allow_edits: raw.agent?.allow_edits ?? false, ...(raw.agent ?? {}) };
|
|
79
|
-
writeJson(file, next);
|
|
80
|
-
config.models = { ...(config.models ?? {}), ...added };
|
|
81
|
-
}
|
|
82
|
-
const results = applyPlan(ctx.root, buildPlan(config), { kit: ctx.kit, force });
|
|
83
|
-
for (const [host, tiers] of Object.entries(added)) {
|
|
84
|
-
results.push({ path: CONFIG_FILE, action: `models.${host}: ${MODEL_TIERS.map((t) => `${t}=${tiers[t]}`).join(', ')}` });
|
|
85
|
-
}
|
|
86
|
-
if (visible.includes('agent')) results.push({ path: CONFIG_FILE, action: 'agent: allow, allow_edits' });
|
|
87
|
-
const current = readJson(file) ?? {};
|
|
88
|
-
if (current.kit !== ctx.kit) {
|
|
89
|
-
writeJson(file, { ...current, kit: ctx.kit });
|
|
90
|
-
results.push({ path: CONFIG_FILE, action: current.kit ? `kit ${current.kit} -> ${ctx.kit}` : `kit ${ctx.kit}` });
|
|
91
|
-
}
|
|
92
|
-
return results;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/** Asks a yes/no question; null without a terminal (scripts, CI, agents). */
|
|
96
|
-
function ask(ctx, question, options) {
|
|
97
|
-
return ctx.ask(question, options);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/** The next steps after init, for the configured hosts (design decision 69). */
|
|
101
|
-
function nextSteps(ctx, hosts, firstCommit) {
|
|
102
|
-
const s = ctx.style;
|
|
103
|
-
const steps = [
|
|
104
|
-
firstCommit
|
|
105
|
-
? `Commit the setup: ${s.cyan('git add -A && git commit -m "chore: set up agjan"')}`
|
|
106
|
-
: `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"')}`,
|
|
107
|
-
];
|
|
108
|
-
if (hosts.includes('claude-code')) {
|
|
109
|
-
steps.push("Open this folder once in Claude Code and trust it: the reviewer's agjan tools load only in trusted folders.");
|
|
110
|
-
}
|
|
111
|
-
if (hosts.includes('copilot')) {
|
|
112
|
-
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')}.`);
|
|
113
|
-
}
|
|
114
|
-
steps.push(`Run: ${s.cyan('npx agjan doctor')}`);
|
|
115
|
-
return ['', s.bold('Next steps:'), ...steps.map((text, i) => ` ${i + 1}. ${text}`)];
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* agjan init [--domains btp] [--hosts claude-code] [--language en] [--base <ref>] [--no-hook] [--no-ci]
|
|
120
|
-
* [--prepare] [--agent-allow | --no-agent-allow] [--agent-allow-edits | --no-agent-allow-edits]
|
|
121
|
-
*/
|
|
122
|
-
export async function init(ctx, argv) {
|
|
123
|
-
const { values } = parseArgs({
|
|
124
|
-
args: argv,
|
|
125
|
-
options: {
|
|
126
|
-
domains: { type: 'string' },
|
|
127
|
-
hosts: { type: 'string' },
|
|
128
|
-
language: { type: 'string' },
|
|
129
|
-
base: { type: 'string' },
|
|
130
|
-
'no-hook': { type: 'boolean' },
|
|
131
|
-
'no-ci': { type: 'boolean' },
|
|
132
|
-
prepare: { type: 'boolean' },
|
|
133
|
-
'agent-allow': { type: 'boolean' },
|
|
134
|
-
'no-agent-allow': { type: 'boolean' },
|
|
135
|
-
'agent-allow-edits': { type: 'boolean' },
|
|
136
|
-
'no-agent-allow-edits': { type: 'boolean' },
|
|
137
|
-
'copilot-mcp': { type: 'boolean' },
|
|
138
|
-
'no-copilot-mcp': { type: 'boolean' },
|
|
139
|
-
},
|
|
140
|
-
});
|
|
141
|
-
const root = ctx.root;
|
|
142
|
-
if (existsSync(join(root, CONFIG_FILE))) throw new AgjanError(`${CONFIG_FILE} already exists; run 'agjan sync' to update the managed files`);
|
|
143
|
-
const domains = list(values.domains) ?? ['btp'];
|
|
144
|
-
for (const d of domains) loadDomain(d);
|
|
145
|
-
const hosts = list(values.hosts) ?? ['claude-code'];
|
|
146
|
-
for (const h of hosts) if (!ADAPTERS[h]) throw new UsageError(`host '${h}' is not supported in this version (supported: ${Object.keys(ADAPTERS).join(', ')})`);
|
|
147
|
-
|
|
148
|
-
// The mark first, then the questions (design decision 69).
|
|
149
|
-
const s = ctx.style;
|
|
150
|
-
const lines = mark(s, ctx.kit, 'setting up this repository');
|
|
151
|
-
for (const line of lines) ctx.out(line);
|
|
152
|
-
await blink(ctx, lines);
|
|
153
|
-
|
|
154
|
-
// Opt-in decisions, asked once. Enter takes the recommended answer (yes); without a
|
|
155
|
-
// terminal the safe defaults (no) apply. They are written visibly, so the team sees
|
|
156
|
-
// and can change them.
|
|
157
|
-
const flag = (yes, no) => (values[yes] ? true : values[no] ? false : null);
|
|
158
|
-
const agentAllow = flag('agent-allow', 'no-agent-allow') ??
|
|
159
|
-
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;
|
|
160
|
-
const allowEdits = flag('agent-allow-edits', 'no-agent-allow-edits') ??
|
|
161
|
-
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;
|
|
162
|
-
// Copilot loads the project's .mcp.json only in folders it remembers as trusted; its
|
|
163
|
-
// user configuration loads everywhere (decision 72).
|
|
164
|
-
const areas = Object.fromEntries(domains.flatMap((d) => Object.keys(loadDomain(d).areas).flatMap((a) => [[a, {}], [`${d}:${a}`, {}]])));
|
|
165
|
-
const servers = Object.keys(mcpServers({ areas }).servers);
|
|
166
|
-
const copilotMcp = hosts.includes('copilot') && servers.length > 0 && (flag('copilot-mcp', 'no-copilot-mcp') ??
|
|
167
|
-
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);
|
|
168
|
-
|
|
169
|
-
const config = {
|
|
170
|
-
$schema: './node_modules/agjan/schemas/config.schema.json',
|
|
171
|
-
kit: ctx.kit,
|
|
172
|
-
domains,
|
|
173
|
-
hosts,
|
|
174
|
-
language: values.language ?? 'en',
|
|
175
|
-
models: missingModels({}, hosts, { existing: false }),
|
|
176
|
-
git: { ...(values.base ? { base: values.base } : {}) },
|
|
177
|
-
agent: { allow: agentAllow ? RECOMMENDED_ALLOW : [], allow_edits: allowEdits },
|
|
178
|
-
};
|
|
179
|
-
writeJson(join(root, CONFIG_FILE), config);
|
|
180
|
-
ctx.out('', `${s.bold('agjan init')}: ${CONFIG_FILE} (domains ${domains.join(', ')}; hosts ${hosts.join(', ')})`);
|
|
181
|
-
|
|
182
|
-
printResults(ctx, doSync(ctx, { force: false }));
|
|
183
|
-
const setting = (on, text) => ` ${pad(on ? tone(s, 'created') : s.gray('none'), on ? 'created' : 'none', 14)} ${text}`;
|
|
184
|
-
ctx.out(setting(agentAllow, `agent.allow${agentAllow ? ` (${RECOMMENDED_ALLOW.length} commands)` : ''}`));
|
|
185
|
-
ctx.out(setting(allowEdits, `agent.allow_edits${allowEdits ? ' (file changes without a prompt)' : ''}`));
|
|
186
|
-
if (copilotMcp) addToCopilot(ctx, loadConfig(root));
|
|
187
|
-
|
|
188
|
-
if (!values['no-hook']) {
|
|
189
|
-
const hook = installHook(root);
|
|
190
|
-
ctx.out(` ${pad(tone(s, hook.action), hook.action, 14)} pre-commit hook`);
|
|
191
|
-
}
|
|
192
|
-
if (values.prepare) ctx.out(` package.json ${addPrepare(root)}`);
|
|
193
|
-
if (!values['no-ci']) {
|
|
194
|
-
const ci = join(root, CI_FILE);
|
|
195
|
-
if (existsSync(ci)) {
|
|
196
|
-
ctx.out(` ${pad(s.gray('unchanged'), 'unchanged', 14)} ${CI_FILE} (exists)`);
|
|
197
|
-
} else {
|
|
198
|
-
mkdirSync(join(ci, '..'), { recursive: true });
|
|
199
|
-
writeFileSync(ci, readFileSync(CI_TEMPLATE, 'utf8'));
|
|
200
|
-
ctx.out(` ${pad(tone(s, 'created'), 'created', 14)} ${CI_FILE}`);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
const pkg = readJson(join(root, 'package.json'));
|
|
205
|
-
if (!pkg?.devDependencies?.agjan && !pkg?.dependencies?.agjan) {
|
|
206
|
-
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')}`);
|
|
207
|
-
}
|
|
208
|
-
const firstCommit = git(root, ['rev-parse', '--verify', '--quiet', 'HEAD'], { allowFail: true }) === null;
|
|
209
|
-
ctx.out(...nextSteps(ctx, hosts, firstCommit));
|
|
210
|
-
return 0;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
function addPrepare(root) {
|
|
214
|
-
const file = join(root, 'package.json');
|
|
215
|
-
const pkg = readJson(file);
|
|
216
|
-
if (!pkg) return 'no package.json; prepare script not added';
|
|
217
|
-
const command = 'agjan hook install';
|
|
218
|
-
const current = pkg.scripts?.prepare;
|
|
219
|
-
if (current?.includes(command)) return 'prepare script already installs the hook';
|
|
220
|
-
if (current) return `prepare script exists; add '&& ${command}' to it yourself`;
|
|
221
|
-
writeJson(file, { ...pkg, scripts: { ...(pkg.scripts ?? {}), prepare: command } });
|
|
222
|
-
return `added "prepare": "${command}"`;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Adds the documentation MCP servers to Copilot's user configuration and reports each:
|
|
227
|
-
* added, already there (left as it is), or failed with the command to run by hand.
|
|
228
|
-
*/
|
|
229
|
-
function addToCopilot(ctx, config) {
|
|
230
|
-
const s = ctx.style;
|
|
231
|
-
const { servers } = mcpServers(config);
|
|
232
|
-
for (const r of addCopilotServers(servers)) {
|
|
233
|
-
const action = r.state === 'added' ? 'created' : r.state === 'exists' ? 'unchanged' : 'failed';
|
|
234
|
-
ctx.out(` ${pad(tone(s, action), action, 14)} copilot mcp ${r.name}: ${r.detail}`);
|
|
235
|
-
if (r.state === 'failed') ctx.out(` ${' '.repeat(14)} add it yourself: ${s.cyan(addCommand(r.name, servers[r.name]).join(' '))}`);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/** agjan sync [--force] [--copilot-mcp]: regenerate managed files; edited ones are kept unless --force. */
|
|
240
|
-
export function sync(ctx, argv) {
|
|
241
|
-
const { values } = parseArgs({ args: argv, options: { force: { type: 'boolean' }, 'copilot-mcp': { type: 'boolean' } } });
|
|
242
|
-
if (!existsSync(join(ctx.root, CONFIG_FILE))) throw new AgjanError(`no ${CONFIG_FILE}; run 'agjan init' first`);
|
|
243
|
-
ctx.out(`${ctx.style.bold('agjan sync')}:`);
|
|
244
|
-
const results = doSync(ctx, { force: values.force });
|
|
245
|
-
printResults(ctx, results);
|
|
246
|
-
if (values['copilot-mcp']) addToCopilot(ctx, ctx.config);
|
|
247
|
-
return results.some((r) => r.action.startsWith('kept')) ? 1 : 0;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/** agjan hook install */
|
|
251
|
-
export function hook(ctx, argv) {
|
|
252
|
-
if (argv[0] !== 'install' || argv.length !== 1) throw new UsageError('usage: agjan hook install');
|
|
253
|
-
const result = installHook(ctx.root);
|
|
254
|
-
ctx.out(`${ctx.style.bold('agjan hook')}: ${tone(ctx.style, result.action)} (${result.path})`);
|
|
255
|
-
return result.state === 'installed' ? 0 : 1;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/** Starts the agjan MCP server and checks that it answers initialize and lists its tools. */
|
|
259
|
-
function probeMcp(root) {
|
|
260
|
-
const input = [
|
|
261
|
-
{ jsonrpc: '2.0', id: 1, method: 'initialize', params: { protocolVersion: '2025-11-25', capabilities: {}, clientInfo: { name: 'agjan-doctor', version: '1' } } },
|
|
262
|
-
{ jsonrpc: '2.0', id: 2, method: 'tools/list' },
|
|
263
|
-
].map((m) => JSON.stringify(m)).join('\n');
|
|
264
|
-
const run = spawnSync(process.execPath, [BIN, 'mcp'], { cwd: root, input: `${input}\n`, encoding: 'utf8', timeout: 10_000 });
|
|
265
|
-
try {
|
|
266
|
-
const lines = run.stdout.trim().split('\n').map((l) => JSON.parse(l));
|
|
267
|
-
const tools = lines.find((l) => l.id === 2)?.result?.tools?.map((t) => t.name) ?? [];
|
|
268
|
-
return tools.includes('review_record') ? null : `unexpected answer: ${run.stdout.slice(0, 200)}`;
|
|
269
|
-
} catch {
|
|
270
|
-
return `did not answer: ${(run.stderr || run.error?.message || '').trim().slice(0, 200)}`;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/** Runs the Copilot guard hook the way Copilot does, with a payload it must deny. */
|
|
275
|
-
function probeGuard(root) {
|
|
276
|
-
const payload = JSON.stringify({ toolName: 'bash', toolArgs: { command: 'npx agjan approve spec' } });
|
|
277
|
-
const run = spawnSync(process.execPath, [join(root, GUARD)], { cwd: root, input: payload, encoding: 'utf8', timeout: 10_000 });
|
|
278
|
-
if (run.status !== 0) return `${GUARD} did not run (is agjan installed locally?); the hook then allows every command`;
|
|
279
|
-
return run.stdout.includes('"deny"') ? null : `unexpected answer: ${run.stdout.slice(0, 120)}`;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/** Whether Claude Code has the project folder trusted, from ~/.claude.json (read-only). */
|
|
283
|
-
function claudeTrust(root) {
|
|
284
|
-
const data = readJson(join(homedir(), '.claude.json'));
|
|
285
|
-
if (!data?.projects) return 'unknown';
|
|
286
|
-
return data.projects[root]?.hasTrustDialogAccepted === true ? 'trusted' : 'not trusted';
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/** agjan doctor: checks the environment and the project setup; exit 1 on any failure. */
|
|
290
|
-
export async function doctor(ctx) {
|
|
291
|
-
const lines = mark(ctx.style, ctx.kit, 'doctor: environment and project setup');
|
|
292
|
-
for (const line of lines) ctx.out(line);
|
|
293
|
-
await blink(ctx, lines);
|
|
294
|
-
const rows = [];
|
|
295
|
-
const ok = (what, detail = '') => rows.push(['ok', what, detail]);
|
|
296
|
-
const warn = (what, detail) => rows.push(['warn', what, detail]);
|
|
297
|
-
const fail = (what, detail) => rows.push(['fail', what, detail]);
|
|
298
|
-
|
|
299
|
-
const major = Number(process.versions.node.split('.')[0]);
|
|
300
|
-
if (major >= 22) ok('node', process.versions.node);
|
|
301
|
-
else fail('node', `${process.versions.node}; agjan needs Node 22 or later`);
|
|
302
|
-
const gitVersion = spawnSync('git', ['--version'], { encoding: 'utf8' });
|
|
303
|
-
if (gitVersion.status === 0) ok('git', gitVersion.stdout.trim().replace(/^git version /, ''));
|
|
304
|
-
else fail('git', 'not found on PATH');
|
|
305
|
-
|
|
306
|
-
let root;
|
|
307
|
-
try {
|
|
308
|
-
root = ctx.root;
|
|
309
|
-
} catch (error) {
|
|
310
|
-
fail('repository', error.message);
|
|
311
|
-
}
|
|
312
|
-
if (root) {
|
|
313
|
-
ok('agjan', ctx.kit);
|
|
314
|
-
const raw = readJson(join(root, CONFIG_FILE));
|
|
315
|
-
if (!raw) {
|
|
316
|
-
fail('configuration', `no ${CONFIG_FILE}; run: npx agjan init`);
|
|
317
|
-
} else {
|
|
318
|
-
const config = loadConfig(root);
|
|
319
|
-
ok('configuration', `domains ${config.domains.join(', ')}; hosts ${config.hosts.join(', ')}`);
|
|
320
|
-
if (raw.kit !== ctx.kit) warn('kit version', `project records ${raw.kit}, installed ${ctx.kit}; run: npx agjan sync`);
|
|
321
|
-
const local = readJson(join(root, 'node_modules', 'agjan', 'package.json'));
|
|
322
|
-
if (!local) warn('local install', 'agjan is not installed in node_modules; run: npm install --save-dev agjan');
|
|
323
|
-
else if (local.version !== ctx.kit) warn('local install', `node_modules has ${local.version}, this command is ${ctx.kit}`);
|
|
324
|
-
else ok('local install', local.version);
|
|
325
|
-
|
|
326
|
-
const base = resolveBase(root, config.git?.base);
|
|
327
|
-
const commits = git(root, ['rev-parse', '--verify', '--quiet', 'HEAD'], { allowFail: true }) !== null;
|
|
328
|
-
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');
|
|
329
|
-
else if (!base) warn('base branch', `none found; set git.base in ${CONFIG_FILE}`);
|
|
330
|
-
else if (!mergeBase(root, base)) warn('base branch', `${base} has no common history with HEAD (fetch it?)`);
|
|
331
|
-
else ok('base branch', base);
|
|
332
|
-
|
|
333
|
-
const problems = planStatus(root, buildPlan(config)).filter((i) => i.state !== 'ok');
|
|
334
|
-
if (problems.length === 0) ok('managed files', 'up to date');
|
|
335
|
-
for (const p of problems) {
|
|
336
|
-
const fix = p.state === 'modified' ? 'edited locally; agjan sync --force restores it' : 'run: npx agjan sync';
|
|
337
|
-
warn('managed file', `${p.path}: ${p.state}; ${fix}`);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
const hookState = hookStatus(root);
|
|
341
|
-
if (hookState.state === 'installed') ok('pre-commit hook', hookState.kind);
|
|
342
|
-
else warn('pre-commit hook', `${hookState.state}; run: npx agjan hook install`);
|
|
343
|
-
|
|
344
|
-
if (!existsSync(join(root, CI_FILE))) warn('ci', `${CI_FILE} is missing`);
|
|
345
|
-
else ok('ci', CI_FILE);
|
|
346
|
-
|
|
347
|
-
const mcp = probeMcp(root);
|
|
348
|
-
if (mcp) fail('agjan mcp server', mcp);
|
|
349
|
-
else ok('agjan mcp server', 'answers initialize and tools/list');
|
|
350
|
-
|
|
351
|
-
if (config.hosts.includes('copilot')) {
|
|
352
|
-
const guard = probeGuard(root);
|
|
353
|
-
if (guard) warn('copilot guard', guard);
|
|
354
|
-
else ok('copilot guard', 'denies agjan approve in a test payload');
|
|
355
|
-
const names = Object.keys(mcpServers(config).servers);
|
|
356
|
-
const known = names.length ? copilotServers() : {};
|
|
357
|
-
const missing = names.filter((name) => !known?.[name]);
|
|
358
|
-
if (!known) warn('copilot mcp', 'copilot is not on PATH; its MCP servers were not checked');
|
|
359
|
-
else if (missing.length) warn('copilot mcp', `${missing.join(', ')} not in Copilot's configuration (removed?); add: npx agjan sync --copilot-mcp`);
|
|
360
|
-
else if (names.length) ok('copilot mcp', `${names.join(', ')} in Copilot's configuration`);
|
|
361
|
-
}
|
|
362
|
-
if (config.hosts.includes('claude-code')) {
|
|
363
|
-
const trust = claudeTrust(root);
|
|
364
|
-
if (trust === 'trusted') ok('claude code trust', 'project folder trusted');
|
|
365
|
-
else warn('claude code trust', `${trust}; open the folder in Claude Code once and trust it, or the reviewer has no agjan tools`);
|
|
366
|
-
}
|
|
367
|
-
if (hasUiTests(root)) {
|
|
368
|
-
const browser = probeBrowser(root);
|
|
369
|
-
if (browser.ready) ok('ui tests', `Chromium starts; npx agjan ui-test runs npm run ${UI_SCRIPT}`);
|
|
370
|
-
else warn('ui tests', `skipped (optional): ${browser.reason}; enable: ${browser.enable}`);
|
|
371
|
-
} else if (config.areas.fiori) {
|
|
372
|
-
ok('ui tests', `none (optional: Playwright, a ${UI_SCRIPT} script; see the fiori-developer skill)`);
|
|
373
|
-
}
|
|
374
|
-
const allow = config.agent?.allow ?? [];
|
|
375
|
-
ok('agent allow list', allow.length ? `${allow.length} command(s) without a prompt: ${allow.join(', ')}` : 'none (the hosts ask for every command)');
|
|
376
|
-
ok('reviewer models', config.hosts.map((h) => `${h}: ${MODEL_TIERS.map((t) => `${t} ${agentModel(config, h, t) ?? 'session model'}`).join(', ')}`).join('; '));
|
|
377
|
-
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)');
|
|
378
|
-
ok('branches', 'agents ask you, then run npx agjan branch');
|
|
379
|
-
ok('script edits', config.agent?.script_edits === 'allow' ? 'allowed (agent.script_edits)' : 'denied by the guard: agents edit files with their edit tool');
|
|
380
|
-
const tracked = (git(root, ['ls-files', '--', 'node_modules'], { allowFail: true }) ?? '').trim();
|
|
381
|
-
if (tracked) warn('node_modules', 'is committed; remove it: git rm -r -q --cached node_modules && git commit -m "chore: stop tracking node_modules"');
|
|
382
|
-
const ignored = git(root, ['check-ignore', '-q', '.agjan/x'], { allowFail: true }) !== null;
|
|
383
|
-
if (!ignored) warn('.gitignore', '.agjan/ is not ignored; run: npx agjan sync');
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
const s = ctx.style;
|
|
388
|
-
for (const [level, what, detail] of rows) 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
|
-
}
|
package/src/commands/status.mjs
DELETED
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
import { parseArgs } from 'node:util';
|
|
2
|
-
import { FEATURES_DIR, changedFeatures, listFeatures, loadFeature, selectFeature, stillBlocked } from '../feature.mjs';
|
|
3
|
-
import { UsageError } from '../errors.mjs';
|
|
4
|
-
import { buildProgress, verifyState } from '../progress.mjs';
|
|
5
|
-
import { gateReadiness, pendingGate } from './gates.mjs';
|
|
6
|
-
import { fixRules, freshReview } from '../fix.mjs';
|
|
7
|
-
import { projectProblems } from '../baseline.mjs';
|
|
8
|
-
import { readFix } from './fix.mjs';
|
|
9
|
-
import { fixAttempts, reviewerFor, roundLimit, roundState } from '../review-policy.mjs';
|
|
10
|
-
import { blink, mark, markLine, pad, tone } from '../ui.mjs';
|
|
11
|
-
import { acTestFiles } from '../tests-map.mjs';
|
|
12
|
-
import { acResults, loadResults } from '../test-results.mjs';
|
|
13
|
-
import { runChecks } from './check.mjs';
|
|
14
|
-
import { readLog } from '../log.mjs';
|
|
15
|
-
import { optionalSteps } from '../progress-view.mjs';
|
|
16
|
-
|
|
17
|
-
/** One indented row: a label column, then the value. `next` and `blocks` stand out. */
|
|
18
|
-
function row(ctx, label, value) {
|
|
19
|
-
const s = ctx.style;
|
|
20
|
-
const styled = { next: s.bold(s.cyan(label)), blocks: s.red(label) }[label] ?? s.gray(label);
|
|
21
|
-
ctx.out(` ${pad(styled, label, 8)} ${value}`);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** The unit's heading: slug, key and stage (or kind). */
|
|
25
|
-
function heading(ctx, unit, detail) {
|
|
26
|
-
const s = ctx.style;
|
|
27
|
-
ctx.out(`${s.bold(unit.slug)} (${s.cyan(unit.key)}) ${detail}`);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** "review step X with agent Y", or the hand-over when the step used up its rounds. */
|
|
31
|
-
function reviewNext(ctx, feature, step) {
|
|
32
|
-
const state = roundState(feature, ctx.config, step);
|
|
33
|
-
if (state.exhausted) {
|
|
34
|
-
return `the ${step} review is still blocked after ${state.round} of ${state.limit} rounds: ask the user whether to run another round (yes: npx agjan review extend ${step}) or to stop and take over (fix with them, accept findings, or change the documents)`;
|
|
35
|
-
}
|
|
36
|
-
const round = state.round ? `, round ${state.next} of ${state.limit}` : '';
|
|
37
|
-
return `review step ${step} with ${reviewerFor(ctx.config, step)}${round}`;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** The review step a feature in Spec or Design needs next. */
|
|
41
|
-
function gateStep(feature) {
|
|
42
|
-
if (feature.stage === 'design') return 'design';
|
|
43
|
-
return feature.design?.parsed.mode === 'light' ? 'design:light' : 'spec';
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** The next action in Build: a due review first, then the next task, then Verify, then the PR. */
|
|
47
|
-
function nextInBuild(ctx, feature, progress) {
|
|
48
|
-
// The same rule as the progress pages: a skill runs once it logged its start (decision 70).
|
|
49
|
-
const events = readLog(feature.dir);
|
|
50
|
-
const since = feature.approvals.approvals.design?.at_utc;
|
|
51
|
-
const building = events.some((e) => e.event === 'step' && e.stage === 'build' && (!since || e.at_utc >= since));
|
|
52
|
-
const lastStage = events.filter((e) => e.event === 'step').at(-1)?.stage;
|
|
53
|
-
if (!building && (progress.next || progress.due.length)) {
|
|
54
|
-
return `a human starts the build: /agjan-build${progress.next ? ` (first task ${progress.next.id}: ${progress.next.title})` : ''}`;
|
|
55
|
-
}
|
|
56
|
-
if (progress.due.length) return reviewNext(ctx, feature, progress.due[0].step);
|
|
57
|
-
if (progress.next) return `task ${progress.next.id}: ${progress.next.title} (commit as '<KEY>-${progress.next.id}: …')`;
|
|
58
|
-
const { state, record } = verifyState(ctx.root, ctx.config, feature);
|
|
59
|
-
if (state === 'blocked') return `the verify review ${record.id} is blocked: resolve its findings, then /agjan-verify again`;
|
|
60
|
-
if (state === 'stale') return `files changed after the verify review ${record.id}: /agjan-verify again`;
|
|
61
|
-
if (state === 'current') return `${ctx.style.green('done')}: development finished and verified (${record.id}); the next steps below are optional`;
|
|
62
|
-
return lastStage === 'verify' ? 'verify is running: /agjan-verify' : 'all tasks done and reviewed: a human starts the verification: /agjan-verify';
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** "2 open, 1 blocker(s)", red when a blocker is open. */
|
|
66
|
-
function findingCount(ctx, open) {
|
|
67
|
-
const blockers = open.filter((f) => f.severity === 'blocker').length;
|
|
68
|
-
const text = `${open.length} open, ${blockers} blocker(s)`;
|
|
69
|
-
return blockers ? ctx.style.red(text) : ctx.style.yellow(text);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** A fix or a map run: its checks, its review, and the next step. */
|
|
73
|
-
function describeRecord(ctx, unit, onBase = false) {
|
|
74
|
-
if (onBase) return describeRecordOnBase(ctx, unit);
|
|
75
|
-
heading(ctx, unit, ctx.style.magenta(unit.kind));
|
|
76
|
-
const problems = unit.kind === 'fix' ? fixRules(ctx.root, ctx.config).problems : projectProblems(ctx.root, ctx.config);
|
|
77
|
-
for (const p of problems) row(ctx, 'blocks', p);
|
|
78
|
-
const review = freshReview(ctx.root, ctx.config, unit, unit.kind);
|
|
79
|
-
row(ctx, 'review', review.problem ?? `${review.record.id} ${tone(ctx.style, review.record.verdict)}, ${tone(ctx.style, 'current')}`);
|
|
80
|
-
const open = unit.findings.filter((f) => f.status === 'open');
|
|
81
|
-
if (open.length) row(ctx, 'findings', findingCount(ctx, open));
|
|
82
|
-
let next;
|
|
83
|
-
if (problems.length) next = unit.kind === 'fix' ? 'the change is not a fix: revert it and use /agjan-spec' : `complete docs/agjan/project.md`;
|
|
84
|
-
else if (review.problem) next = reviewNext(ctx, unit, unit.kind);
|
|
85
|
-
else if (unit.kind === 'fix' && readFix(unit)?.review?.tree_hash !== review.record.tree_hash) next = 'npx agjan fix record --verify "<command and result>"';
|
|
86
|
-
else next = unit.kind === 'map' ? 'npx agjan baseline refresh, commit, open a PR' : 'commit and open a PR';
|
|
87
|
-
row(ctx, 'next', next);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* A feature that did not change on this branch is already on the base branch (merged, or
|
|
92
|
-
* committed there directly): its tasks come from the whole history, and work on it
|
|
93
|
-
* continues as a new feature on a branch.
|
|
94
|
-
*/
|
|
95
|
-
function describeOnBase(ctx, feature) {
|
|
96
|
-
const s = ctx.style;
|
|
97
|
-
const progress = buildProgress(ctx.root, ctx.config, feature, { history: true });
|
|
98
|
-
const verify = feature.reviews.records.filter((r) => r.step === 'verify').at(-1);
|
|
99
|
-
const merged = progress.complete && verify && !stillBlocked(feature, verify);
|
|
100
|
-
heading(ctx, feature, merged ? `stage: ${s.green('merged')}` : `stage: ${s.magenta(feature.stage)} (on the base branch)`);
|
|
101
|
-
row(ctx, 'spec', tone(s, feature.state.spec));
|
|
102
|
-
row(ctx, 'design', `${tone(s, feature.state.design)}${feature.design?.parsed.mode ? ` (${feature.design.parsed.mode})` : ''}`);
|
|
103
|
-
const reviews = feature.reviews.records;
|
|
104
|
-
if (reviews.length) row(ctx, 'reviews', `${reviews.length}, last ${reviews.at(-1).id} ${reviews.at(-1).step}: ${tone(s, reviews.at(-1).verdict)}`);
|
|
105
|
-
for (const t of progress.tasks) {
|
|
106
|
-
row(ctx, 'task', `${tone(s, t.commit ? 'done' : 'open')} ${t.id} [${t.areaName}] ${t.title}${t.commit ? s.gray(` (${t.commit.slice(0, 7)})`) : ''}`);
|
|
107
|
-
}
|
|
108
|
-
if (!merged) row(ctx, 'next', 'continue on a feature branch, or start follow-up work as a new feature');
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/** A fix or a map run already on the base branch: merged once its last review passed. */
|
|
112
|
-
function describeRecordOnBase(ctx, unit) {
|
|
113
|
-
const s = ctx.style;
|
|
114
|
-
const last = unit.reviews.records.at(-1);
|
|
115
|
-
const merged = last && !stillBlocked(unit, last);
|
|
116
|
-
heading(ctx, unit, `${s.magenta(unit.kind)} ${merged ? `stage: ${s.green('merged')}` : '(on the base branch)'}`);
|
|
117
|
-
row(ctx, 'review', last ? `${last.id} ${tone(s, last.verdict)}` : 'none');
|
|
118
|
-
const open = unit.findings.filter((f) => f.status === 'open');
|
|
119
|
-
if (open.length) row(ctx, 'findings', findingCount(ctx, open));
|
|
120
|
-
if (!merged) row(ctx, 'next', `start follow-up work on a branch (/agjan-${unit.kind === 'fix' ? 'fix' : 'map'})`);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* The end of a feature's agent work (verified, CI check clean or not): a screen that says
|
|
125
|
-
* so unmistakably, what was met, what is open, and what the human does next (Gate 3).
|
|
126
|
-
* Colored with the agjan mark on a terminal; the same content as plain text for agents,
|
|
127
|
-
* who end /agjan-verify with it.
|
|
128
|
-
*/
|
|
129
|
-
async function completion(ctx, feature, progress) {
|
|
130
|
-
const s = ctx.style;
|
|
131
|
-
const areaNames = [...new Set(progress.tasks.map((t) => t.areaName))];
|
|
132
|
-
const automated = feature.spec.parsed.acs.filter((ac) => ac.verification !== 'manual');
|
|
133
|
-
const manual = feature.spec.parsed.acs.filter((ac) => ac.verification === 'manual');
|
|
134
|
-
const loaded = loadResults(ctx.root, ctx.config, areaNames);
|
|
135
|
-
const results = loaded.files.length ? acResults(loaded, feature.key) : null;
|
|
136
|
-
const tests = acTestFiles(ctx.root, ctx.config, areaNames, feature.key);
|
|
137
|
-
const covered = automated.filter((ac) => (results ? results.get(ac.id)?.passed && !results.get(ac.id)?.failed : tests.has(ac.id))).length;
|
|
138
|
-
const { report } = runChecks(ctx, 'ci', feature.slug);
|
|
139
|
-
const open = feature.findings.filter((f) => f.status === 'open');
|
|
140
|
-
const blockers = open.filter((f) => f.severity === 'blocker').length;
|
|
141
|
-
const ok = (text) => `${s.teal('✔')} ${text}`;
|
|
142
|
-
const bad = (text) => `${s.red('✖')} ${text}`;
|
|
143
|
-
const lines = [
|
|
144
|
-
[ok(`tasks ${progress.tasks.length}/${progress.tasks.length}`), (covered === automated.length ? ok : bad)(`ACs ${covered}/${automated.length} ${results ? 'with passing tests' : 'with tests'}`),
|
|
145
|
-
report.errors ? bad(`check --ci: ${report.errors} error(s)`) : ok('check --ci clean')].join(' '),
|
|
146
|
-
[(blockers ? bad : ok)(`reviews ${feature.reviews.records.length}, ${blockers} blocker(s) open`), open.length - blockers ? `${s.gray('●')} ${open.length - blockers} note(s) open` : ok('no open notes')].join(' '),
|
|
147
|
-
];
|
|
148
|
-
ctx.out();
|
|
149
|
-
if (s.brand) {
|
|
150
|
-
const stars = `${s.teal('✦')} ${s.violet('✦')} ${s.teal('✦')}`;
|
|
151
|
-
const logo = mark(s, ctx.kit, `${stars} ${s.bold(`${feature.key} is done`)} ${stars}`, `${feature.slug} · development finished and verified`);
|
|
152
|
-
for (const line of logo) ctx.out(line);
|
|
153
|
-
await blink(ctx, logo);
|
|
154
|
-
} else {
|
|
155
|
-
ctx.out(`✔ ${feature.key} is done: development finished and verified (${feature.slug})`);
|
|
156
|
-
}
|
|
157
|
-
for (const line of lines) ctx.out(` ${line}`);
|
|
158
|
-
ctx.out(` ${s.bold('Optional next steps:')}`);
|
|
159
|
-
const steps = optionalSteps(ctx.root, feature, { manual: manual.map((ac) => ac.id) });
|
|
160
|
-
for (const step of steps) ctx.out(` ${s.violet('▸')} ${step}`);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
async function describe(ctx, feature, onBase = false) {
|
|
164
|
-
if (feature.kind !== 'feature') return describeRecord(ctx, feature, onBase);
|
|
165
|
-
if (onBase) return describeOnBase(ctx, feature);
|
|
166
|
-
heading(ctx, feature, `stage: ${ctx.style.magenta(feature.stage)}`);
|
|
167
|
-
row(ctx, 'spec', tone(ctx.style, feature.state.spec));
|
|
168
|
-
const mode = feature.design?.parsed.mode ? ` (${feature.design.parsed.mode})` : '';
|
|
169
|
-
row(ctx, 'design', `${tone(ctx.style, feature.state.design)}${mode}`);
|
|
170
|
-
const steps = [...new Set(feature.reviews.records.map((r) => r.step))];
|
|
171
|
-
for (const step of steps) {
|
|
172
|
-
const records = feature.reviews.records.filter((r) => r.step === step);
|
|
173
|
-
const last = records[records.length - 1];
|
|
174
|
-
const { limit, extra } = roundState(feature, ctx.config, step);
|
|
175
|
-
row(ctx, 'review', `${step}: ${tone(ctx.style, last.verdict)} (round ${last.round} of ${limit}${extra ? `, ${extra} granted by the user` : ''}, ${last.id})`);
|
|
176
|
-
}
|
|
177
|
-
const open = feature.findings.filter((f) => f.status === 'open');
|
|
178
|
-
if (open.length) {
|
|
179
|
-
row(ctx, 'findings', findingCount(ctx, open));
|
|
180
|
-
}
|
|
181
|
-
for (const a of feature.amendments.filter((x) => x.status !== 'approved')) {
|
|
182
|
-
row(ctx, 'amend', `${a.id} ${tone(ctx.style, a.status)}: ${a.paths.join(', ')}`);
|
|
183
|
-
}
|
|
184
|
-
if (feature.stage === 'build') {
|
|
185
|
-
const progress = buildProgress(ctx.root, ctx.config, feature);
|
|
186
|
-
for (const t of progress.tasks) {
|
|
187
|
-
row(ctx, 'task', `${tone(ctx.style, t.commit ? 'done' : 'open')} ${t.id} [${t.areaName}] ${t.title}${t.commit ? ctx.style.gray(` (${t.commit.slice(0, 7)})`) : ''}`);
|
|
188
|
-
}
|
|
189
|
-
for (const d of progress.due) row(ctx, 'due', ctx.style.yellow(`review ${d.step} (${d.reason})`));
|
|
190
|
-
row(ctx, 'next', nextInBuild(ctx, feature, progress).replace('<KEY>', feature.key));
|
|
191
|
-
const verify = verifyState(ctx.root, ctx.config, feature);
|
|
192
|
-
if (progress.complete && progress.due.length === 0 && verify.state === 'current') await completion(ctx, feature, progress);
|
|
193
|
-
} else {
|
|
194
|
-
// Spec and Design: either the gate is ready for the human, or what blocks it.
|
|
195
|
-
const gate = pendingGate(feature);
|
|
196
|
-
const { problems } = gateReadiness(ctx, feature, gate);
|
|
197
|
-
if (problems.length === 0) {
|
|
198
|
-
row(ctx, 'next', `${ctx.style.green('ready for approval')}: a human runs '${ctx.style.bold(`npx agjan approve ${gate}`)}' in a terminal`);
|
|
199
|
-
} else {
|
|
200
|
-
for (const p of problems) row(ctx, 'blocks', p);
|
|
201
|
-
const step = gateStep(feature);
|
|
202
|
-
const state = roundState(feature, ctx.config, step);
|
|
203
|
-
if (state.exhausted) row(ctx, 'next', ctx.style.red(reviewNext(ctx, feature, step)));
|
|
204
|
-
else row(ctx, 'next', `resolve the points above, then ${reviewNext(ctx, feature, step)}; then request 'approve ${gate}'`);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* agjan status --done [--feature <slug>]: only the completion block of a verified feature,
|
|
211
|
-
* for the agent's final message (exit 1 with the next step while it is not done).
|
|
212
|
-
*/
|
|
213
|
-
async function done(ctx, slug) {
|
|
214
|
-
const feature = loadFeature(ctx.root, slug);
|
|
215
|
-
const progress = feature.kind === 'feature' && feature.stage === 'build' ? buildProgress(ctx.root, ctx.config, feature) : null;
|
|
216
|
-
if (progress?.complete && progress.due.length === 0 && verifyState(ctx.root, ctx.config, feature).state === 'current') {
|
|
217
|
-
await completion(ctx, feature, progress);
|
|
218
|
-
return 0;
|
|
219
|
-
}
|
|
220
|
-
ctx.out(`${feature.key} is not done yet: ${progress ? nextInBuild(ctx, feature, progress).replace('<KEY>', feature.key) : `stage ${feature.stage}`}`);
|
|
221
|
-
return 1;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/** agjan status [--feature <slug> | --all | --done] */
|
|
225
|
-
export async function run(ctx, argv) {
|
|
226
|
-
const { values } = parseArgs({ args: argv, options: { feature: { type: 'string' }, all: { type: 'boolean' }, done: { type: 'boolean' } } });
|
|
227
|
-
const root = ctx.root;
|
|
228
|
-
if (values.done) return done(ctx, selectFeature(root, ctx.config, values.feature));
|
|
229
|
-
let slugs;
|
|
230
|
-
if (values.feature) {
|
|
231
|
-
if (!listFeatures(root).includes(values.feature)) throw new UsageError(`no feature '${values.feature}'`);
|
|
232
|
-
slugs = [values.feature];
|
|
233
|
-
} else {
|
|
234
|
-
slugs = values.all ? listFeatures(root) : changedFeatures(root, ctx.config);
|
|
235
|
-
}
|
|
236
|
-
const c = ctx.config;
|
|
237
|
-
const branches = 'branches: ask the user, then npx agjan branch';
|
|
238
|
-
for (const line of markLine(ctx.style, ctx.kit, 'status')) ctx.out(line);
|
|
239
|
-
ctx.out(ctx.style.gray(`settings: documents in '${c.language ?? 'en'}' (headings in English); reviews up to ${roundLimit(c)} rounds; ${fixAttempts(c)} attempts for failing checks; ${branches}`));
|
|
240
|
-
if (slugs.length === 0) {
|
|
241
|
-
ctx.out(values.all ? `no features in ${FEATURES_DIR}` : 'no changed feature on this branch (agjan status --all lists every feature)');
|
|
242
|
-
return 0;
|
|
243
|
-
}
|
|
244
|
-
const changed = new Set(changedFeatures(root, ctx.config));
|
|
245
|
-
for (const [i, slug] of slugs.entries()) {
|
|
246
|
-
if (i > 0) ctx.out();
|
|
247
|
-
await describe(ctx, loadFeature(root, slug), !changed.has(slug));
|
|
248
|
-
}
|
|
249
|
-
return 0;
|
|
250
|
-
}
|