agjan 0.0.0-stage → 0.0.2
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/LICENSE +201 -0
- package/NOTICE +11 -0
- package/README.md +105 -2
- package/bin/agjan.mjs +12 -0
- package/docs/brand/agjan-icon.svg +14 -0
- package/docs/brand/agjan-logo-dark.svg +17 -0
- package/docs/brand/agjan-logo-light.svg +17 -0
- package/docs/guide.md +232 -0
- package/kit/domains/btp/domain.json +27 -0
- package/kit/hooks/guard.mjs +61 -0
- package/kit/mcp/servers.json +5 -0
- package/kit/skills/agjan-build/SKILL.md +61 -0
- package/kit/skills/agjan-design/SKILL.md +95 -0
- package/kit/skills/agjan-fix/SKILL.md +55 -0
- package/kit/skills/agjan-map/SKILL.md +51 -0
- package/kit/skills/agjan-spec/SKILL.md +111 -0
- package/kit/skills/agjan-verify/SKILL.md +60 -0
- package/kit/skills/btp-architect/SKILL.md +51 -0
- package/kit/skills/btp-architect/references/deployment.md +72 -0
- package/kit/skills/btp-architect/references/security.md +54 -0
- package/kit/skills/cap-developer/SKILL.md +49 -0
- package/kit/skills/cap-developer/references/handlers.md +47 -0
- package/kit/skills/cap-developer/references/modeling.md +52 -0
- package/kit/skills/cap-developer/references/services.md +53 -0
- package/kit/skills/cap-developer/references/testing.md +39 -0
- package/kit/skills/cap-developer/references/validation-security.md +49 -0
- package/kit/skills/fiori-developer/SKILL.md +64 -0
- package/kit/skills/fiori-developer/references/elements.md +77 -0
- package/kit/skills/fiori-developer/references/freestyle-ts.md +45 -0
- package/kit/skills/fiori-developer/references/testing.md +32 -0
- package/kit/skills/fiori-developer/references/ui5-basics.md +52 -0
- package/kit/skills/solution-reviewer/SKILL.md +51 -0
- package/kit/templates/agents-block.md +20 -0
- package/kit/templates/agjan-ci.yml +40 -0
- package/kit/templates/design.md +17 -0
- package/kit/templates/project.md +28 -0
- package/kit/templates/spec.md +33 -0
- package/kit/templates/tasks.md +13 -0
- package/package.json +50 -4
- package/schemas/approvals.schema.json +93 -0
- package/schemas/config.schema.json +79 -0
- package/schemas/log.schema.json +30 -0
- package/schemas/reviews.schema.json +68 -0
- package/schemas/tasks.schema.json +26 -0
- package/src/adapters/claude-code.mjs +115 -0
- package/src/adapters/copilot.mjs +88 -0
- package/src/baseline.mjs +66 -0
- package/src/cli.mjs +133 -0
- package/src/commands/check.mjs +363 -0
- package/src/commands/fix.mjs +116 -0
- package/src/commands/gates.mjs +264 -0
- package/src/commands/log.mjs +53 -0
- package/src/commands/map.mjs +47 -0
- package/src/commands/new.mjs +53 -0
- package/src/commands/pr-summary.mjs +134 -0
- package/src/commands/report.mjs +110 -0
- package/src/commands/review.mjs +49 -0
- package/src/commands/setup.mjs +269 -0
- package/src/commands/status.mjs +176 -0
- package/src/config.mjs +98 -0
- package/src/context.mjs +58 -0
- package/src/documents.mjs +188 -0
- package/src/errors.mjs +16 -0
- package/src/feature.mjs +214 -0
- package/src/fix.mjs +108 -0
- package/src/git.mjs +66 -0
- package/src/hash.mjs +33 -0
- package/src/hook.mjs +48 -0
- package/src/json-file.mjs +24 -0
- package/src/log.mjs +37 -0
- package/src/managed.mjs +178 -0
- package/src/mcp-config.mjs +83 -0
- package/src/mcp.mjs +142 -0
- package/src/plan.mjs +41 -0
- package/src/progress.mjs +85 -0
- package/src/review-policy.mjs +49 -0
- package/src/review.mjs +336 -0
- package/src/scope.mjs +30 -0
- package/src/terminal.mjs +98 -0
- package/src/test-results.mjs +111 -0
- package/src/tests-map.mjs +29 -0
- package/src/ui.mjs +110 -0
- package/src/usage.mjs +118 -0
- package/src/validate.mjs +41 -0
package/src/git.mjs
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { AgjanError } from './errors.mjs';
|
|
3
|
+
|
|
4
|
+
/** Runs git and returns stdout. Throws AgjanError with git's message on failure. */
|
|
5
|
+
export function git(cwd, args, { allowFail = false } = {}) {
|
|
6
|
+
try {
|
|
7
|
+
return execFileSync('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
|
|
8
|
+
} catch (error) {
|
|
9
|
+
if (allowFail) return null;
|
|
10
|
+
const detail = error.stderr?.toString().trim() || error.message;
|
|
11
|
+
throw new AgjanError(`git ${args.join(' ')} failed: ${detail}`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function repoRoot(cwd) {
|
|
16
|
+
const out = git(cwd, ['rev-parse', '--show-toplevel'], { allowFail: true });
|
|
17
|
+
if (out === null) throw new AgjanError('not inside a git repository');
|
|
18
|
+
return out.trim();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function userEmail(root) {
|
|
22
|
+
return git(root, ['config', 'user.email'], { allowFail: true })?.trim() || 'unknown';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The base branch to compare against: the configured one, else the remote's default
|
|
27
|
+
* branch, else a local main or master.
|
|
28
|
+
*/
|
|
29
|
+
export function resolveBase(root, configured) {
|
|
30
|
+
if (configured) return configured;
|
|
31
|
+
const remoteHead = git(root, ['symbolic-ref', '--quiet', '--short', 'refs/remotes/origin/HEAD'], { allowFail: true });
|
|
32
|
+
if (remoteHead) return remoteHead.trim();
|
|
33
|
+
for (const name of ['main', 'master']) {
|
|
34
|
+
if (git(root, ['rev-parse', '--verify', '--quiet', `refs/heads/${name}`], { allowFail: true })) return name;
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The merge-base commit with the base branch, or null when there is none yet. */
|
|
40
|
+
export function mergeBase(root, base) {
|
|
41
|
+
if (!base) return null;
|
|
42
|
+
return git(root, ['merge-base', 'HEAD', base], { allowFail: true })?.trim() || null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function lines(out) {
|
|
46
|
+
return out ? out.split('\n').filter(Boolean) : [];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Files changed relative to the merge-base: committed, staged, unstaged and untracked.
|
|
51
|
+
* With `staged`, only the files in the index. Paths are POSIX (git always uses '/').
|
|
52
|
+
*/
|
|
53
|
+
export function changedFiles(root, base, { staged = false } = {}) {
|
|
54
|
+
if (staged) return lines(git(root, ['diff', '--cached', '--name-only', '--no-renames']));
|
|
55
|
+
const from = mergeBase(root, base);
|
|
56
|
+
const files = new Set();
|
|
57
|
+
if (from) {
|
|
58
|
+
for (const f of lines(git(root, ['diff', '--name-only', '--no-renames', from]))) files.add(f);
|
|
59
|
+
} else if (git(root, ['rev-parse', '--verify', '--quiet', 'HEAD'], { allowFail: true })) {
|
|
60
|
+
for (const f of lines(git(root, ['diff', '--name-only', '--no-renames', 'HEAD']))) files.add(f);
|
|
61
|
+
} else {
|
|
62
|
+
for (const f of lines(git(root, ['diff', '--cached', '--name-only', '--no-renames']))) files.add(f);
|
|
63
|
+
}
|
|
64
|
+
for (const f of lines(git(root, ['ls-files', '--others', '--exclude-standard']))) files.add(f);
|
|
65
|
+
return [...files].sort();
|
|
66
|
+
}
|
package/src/hash.mjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Normalizes text before hashing so that line endings and trailing whitespace never
|
|
5
|
+
* change a hash (design 8): LF line endings, no trailing whitespace on a line, no
|
|
6
|
+
* trailing blank lines, exactly one final newline.
|
|
7
|
+
*/
|
|
8
|
+
export function normalize(text) {
|
|
9
|
+
const lines = text.replace(/\r\n?/g, '\n').split('\n').map((line) => line.replace(/[ \t]+$/, ''));
|
|
10
|
+
while (lines.length > 0 && lines[lines.length - 1] === '') lines.pop();
|
|
11
|
+
return lines.length === 0 ? '' : `${lines.join('\n')}\n`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function sha256(data) {
|
|
15
|
+
return `sha256:${createHash('sha256').update(data).digest('hex')}`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Hash of one document's content. */
|
|
19
|
+
export function hashText(text) {
|
|
20
|
+
return sha256(normalize(text));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Hash of several named documents taken together, for example the design hash over
|
|
25
|
+
* design.md and tasks.md. Names are part of the hash, so swapping contents changes it.
|
|
26
|
+
*/
|
|
27
|
+
export function hashParts(parts) {
|
|
28
|
+
const hash = createHash('sha256');
|
|
29
|
+
for (const [name, text] of parts) {
|
|
30
|
+
hash.update(name).update('\0').update(normalize(text)).update('\0');
|
|
31
|
+
}
|
|
32
|
+
return `sha256:${hash.digest('hex')}`;
|
|
33
|
+
}
|
package/src/hook.mjs
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { isAbsolute, join } from 'node:path';
|
|
3
|
+
import { git } from './git.mjs';
|
|
4
|
+
|
|
5
|
+
/** The command the hook runs; also what a husky pre-commit file must contain. */
|
|
6
|
+
export const HOOK_COMMAND = 'npx --no-install agjan check --staged';
|
|
7
|
+
const MARKER = '# agjan pre-commit hook';
|
|
8
|
+
|
|
9
|
+
const HOOK = `#!/bin/sh
|
|
10
|
+
${MARKER} (managed by agjan; reinstall with: npx agjan hook install)
|
|
11
|
+
# Fast checks on the staged change. CI runs the full check; --no-verify skips this.
|
|
12
|
+
exec ${HOOK_COMMAND}
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
/** Where the pre-commit hook lives: husky if the project uses it, else git's hooks dir. */
|
|
16
|
+
function target(root) {
|
|
17
|
+
const husky = join(root, '.husky');
|
|
18
|
+
if (existsSync(husky)) return { kind: 'husky', path: join(husky, 'pre-commit') };
|
|
19
|
+
const dir = git(root, ['rev-parse', '--git-path', 'hooks']).trim();
|
|
20
|
+
return { kind: 'git', path: join(isAbsolute(dir) ? dir : join(root, dir), 'pre-commit') };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** installed | missing | foreign (a hook agjan did not write and will not touch). */
|
|
24
|
+
export function hookStatus(root) {
|
|
25
|
+
const { kind, path } = target(root);
|
|
26
|
+
if (!existsSync(path)) return { kind, path, state: 'missing' };
|
|
27
|
+
const text = readFileSync(path, 'utf8');
|
|
28
|
+
if (text.includes(HOOK_COMMAND)) return { kind, path, state: 'installed' };
|
|
29
|
+
return { kind, path, state: kind === 'husky' ? 'missing' : 'foreign' };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Installs the hook. Never overwrites a foreign git hook; appends to husky's file. */
|
|
33
|
+
export function installHook(root) {
|
|
34
|
+
const status = hookStatus(root);
|
|
35
|
+
if (status.state === 'installed') return { ...status, action: 'unchanged' };
|
|
36
|
+
if (status.state === 'foreign') {
|
|
37
|
+
return { ...status, action: `not installed: ${status.path} exists and is not agjan's; add this line to it: ${HOOK_COMMAND}` };
|
|
38
|
+
}
|
|
39
|
+
if (status.kind === 'husky') {
|
|
40
|
+
const current = existsSync(status.path) ? readFileSync(status.path, 'utf8') : '';
|
|
41
|
+
writeFileSync(status.path, `${current.replace(/\s*$/, '')}${current.trim() ? '\n' : ''}${HOOK_COMMAND}\n`);
|
|
42
|
+
return { ...status, state: 'installed', action: 'added to husky' };
|
|
43
|
+
}
|
|
44
|
+
mkdirSync(join(status.path, '..'), { recursive: true });
|
|
45
|
+
writeFileSync(status.path, HOOK);
|
|
46
|
+
chmodSync(status.path, 0o755);
|
|
47
|
+
return { ...status, state: 'installed', action: 'installed' };
|
|
48
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync, renameSync } from 'node:fs';
|
|
2
|
+
import { AgjanError } from './errors.mjs';
|
|
3
|
+
|
|
4
|
+
export function readJson(file) {
|
|
5
|
+
let text;
|
|
6
|
+
try {
|
|
7
|
+
text = readFileSync(file, 'utf8');
|
|
8
|
+
} catch (error) {
|
|
9
|
+
if (error.code === 'ENOENT') return null;
|
|
10
|
+
throw error;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(text);
|
|
14
|
+
} catch (error) {
|
|
15
|
+
throw new AgjanError(`${file} is not valid JSON: ${error.message}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Writes JSON with stable formatting, atomically (write then rename). */
|
|
20
|
+
export function writeJson(file, value) {
|
|
21
|
+
const tmp = `${file}.tmp-${process.pid}`;
|
|
22
|
+
writeFileSync(tmp, `${JSON.stringify(value, null, 2)}\n`);
|
|
23
|
+
renameSync(tmp, file);
|
|
24
|
+
}
|
package/src/log.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { appendFileSync, readFileSync, existsSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
export const LOG_FILE = 'log.jsonl';
|
|
5
|
+
|
|
6
|
+
/** Event types (design 12.1). Script events are written by the commands themselves. */
|
|
7
|
+
export const EVENTS = [
|
|
8
|
+
'step', // a skill starts a step (from `agjan log`)
|
|
9
|
+
'gate-requested', // a skill hands a gate to the human (from `agjan log`)
|
|
10
|
+
'approved',
|
|
11
|
+
'rejected',
|
|
12
|
+
'accepted',
|
|
13
|
+
'amendment-proposed',
|
|
14
|
+
'review-recorded',
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
/** Appends one event to the feature's log.jsonl. The time is always set by the script. */
|
|
18
|
+
export function appendLog(featureDir, at, event, fields = {}) {
|
|
19
|
+
const entry = { at_utc: at, event, ...fields };
|
|
20
|
+
appendFileSync(join(featureDir, LOG_FILE), `${JSON.stringify(entry)}\n`);
|
|
21
|
+
return entry;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function readLog(featureDir) {
|
|
25
|
+
const file = join(featureDir, LOG_FILE);
|
|
26
|
+
if (!existsSync(file)) return [];
|
|
27
|
+
return readFileSync(file, 'utf8')
|
|
28
|
+
.split('\n')
|
|
29
|
+
.filter(Boolean)
|
|
30
|
+
.flatMap((line) => {
|
|
31
|
+
try {
|
|
32
|
+
return [JSON.parse(line)];
|
|
33
|
+
} catch {
|
|
34
|
+
return []; // a damaged line is skipped, not fatal: the log is observability only
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
package/src/managed.mjs
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join, relative, sep } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { hashText } from './hash.mjs';
|
|
5
|
+
import { readJson, writeJson } from './json-file.mjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Managed content (design 16.3): whole files agjan owns (kit skills, generated agents),
|
|
9
|
+
* marked blocks inside files the project owns (AGENTS.md, CLAUDE.md, .gitattributes,
|
|
10
|
+
* .gitignore), and entries merged into JSON files (.claude/settings.json).
|
|
11
|
+
*
|
|
12
|
+
* agjan.lock.json records the hash of every managed file as agjan last wrote it, so a
|
|
13
|
+
* later sync can tell "the kit changed it" from "someone edited it".
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export const LOCK_FILE = 'agjan.lock.json';
|
|
17
|
+
const KIT_SKILLS = new URL('../kit/skills/', import.meta.url);
|
|
18
|
+
|
|
19
|
+
const MARKERS = {
|
|
20
|
+
md: ['<!-- agjan:begin (managed by agjan sync; edit outside this block) -->', '<!-- agjan:end -->'],
|
|
21
|
+
hash: ['# agjan:begin (managed by agjan sync)', '# agjan:end'],
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function readText(path) {
|
|
25
|
+
return existsSync(path) ? readFileSync(path, 'utf8') : null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function toPosix(path) {
|
|
29
|
+
return path.split(sep).join('/');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** All files of the kit's skills, as { 'name/SKILL.md': content }. */
|
|
33
|
+
export function kitSkillFiles() {
|
|
34
|
+
const root = fileURLToPath(KIT_SKILLS);
|
|
35
|
+
const out = {};
|
|
36
|
+
const walk = (dir) => {
|
|
37
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
38
|
+
const path = join(dir, entry.name);
|
|
39
|
+
if (entry.isDirectory()) walk(path);
|
|
40
|
+
else out[toPosix(relative(root, path))] = readFileSync(path, 'utf8');
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
if (existsSync(root)) walk(root);
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The body of a skill file without its frontmatter. */
|
|
48
|
+
export function skillBody(text) {
|
|
49
|
+
return text.replace(/^---\r?\n[\s\S]*?\r?\n---[ \t]*\r?\n/, '').replace(/^\s+/, '');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Finds agjan's block in a text; returns [start, end] offsets of the whole block or null. */
|
|
53
|
+
function findBlock(text, style) {
|
|
54
|
+
const [begin, end] = MARKERS[style];
|
|
55
|
+
const start = text.indexOf(begin);
|
|
56
|
+
if (start === -1) return null;
|
|
57
|
+
const stop = text.indexOf(end, start);
|
|
58
|
+
if (stop === -1) return null;
|
|
59
|
+
return [start, stop + end.length];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function renderBlock(style, content) {
|
|
63
|
+
const [begin, end] = MARKERS[style];
|
|
64
|
+
return `${begin}\n${content.trimEnd()}\n${end}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Inserts or replaces agjan's block; everything outside the markers stays as it was. */
|
|
68
|
+
export function upsertBlock(text, style, content) {
|
|
69
|
+
const block = renderBlock(style, content);
|
|
70
|
+
if (text === null || text.trim() === '') return `${block}\n`;
|
|
71
|
+
const at = findBlock(text, style);
|
|
72
|
+
if (at) return text.slice(0, at[0]) + block + text.slice(at[1]);
|
|
73
|
+
return `${text.replace(/\s*$/, '')}\n\n${block}\n`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function extractBlock(text, style) {
|
|
77
|
+
if (text === null) return null;
|
|
78
|
+
const at = findBlock(text, style);
|
|
79
|
+
return at ? text.slice(at[0], at[1]) : null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function readLock(root) {
|
|
83
|
+
return readJson(join(root, LOCK_FILE)) ?? { schema: 1, kit: null, files: {} };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The state of each plan item in the working tree:
|
|
88
|
+
* ok, missing, outdated (pristine but not what this kit version generates), modified.
|
|
89
|
+
*/
|
|
90
|
+
export function planStatus(root, plan, lock = readLock(root)) {
|
|
91
|
+
return plan.map((item) => {
|
|
92
|
+
const path = join(root, item.path);
|
|
93
|
+
const current = readText(path);
|
|
94
|
+
if (item.kind === 'file') {
|
|
95
|
+
if (current === null) return { ...item, state: 'missing' };
|
|
96
|
+
const hash = hashText(current);
|
|
97
|
+
if (hash === hashText(item.content)) return { ...item, state: 'ok' };
|
|
98
|
+
return { ...item, state: lock.files[item.path] === hash ? 'outdated' : 'modified' };
|
|
99
|
+
}
|
|
100
|
+
if (item.kind === 'block') {
|
|
101
|
+
if (item.skip?.(current)) return { ...item, state: 'ok' };
|
|
102
|
+
const block = extractBlock(current, item.style);
|
|
103
|
+
if (block === null) return { ...item, state: 'missing' };
|
|
104
|
+
return { ...item, state: hashText(block) === hashText(renderBlock(item.style, item.content)) ? 'ok' : 'outdated' };
|
|
105
|
+
}
|
|
106
|
+
// json: a merge that must be present
|
|
107
|
+
let data = null;
|
|
108
|
+
try {
|
|
109
|
+
data = current === null ? null : JSON.parse(current);
|
|
110
|
+
} catch {
|
|
111
|
+
return { ...item, state: 'modified' };
|
|
112
|
+
}
|
|
113
|
+
return { ...item, state: data !== null && item.present(data) ? 'ok' : 'missing' };
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Applies the plan. Managed files someone edited are kept unless `force`; files the
|
|
119
|
+
* previous kit managed and this one does not are removed when pristine.
|
|
120
|
+
* Returns one { path, action } per touched or skipped item, and writes the lock.
|
|
121
|
+
*/
|
|
122
|
+
export function applyPlan(root, plan, { kit, force = false } = {}) {
|
|
123
|
+
const lock = readLock(root);
|
|
124
|
+
const results = [];
|
|
125
|
+
const files = {};
|
|
126
|
+
for (const item of planStatus(root, plan, lock)) {
|
|
127
|
+
const path = join(root, item.path);
|
|
128
|
+
if (item.kind === 'file') {
|
|
129
|
+
if (item.state === 'modified' && !force) {
|
|
130
|
+
results.push({ path: item.path, action: 'kept (modified locally; use --force to overwrite)' });
|
|
131
|
+
if (lock.files[item.path]) files[item.path] = lock.files[item.path];
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (item.state !== 'ok') {
|
|
135
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
136
|
+
writeFileSync(path, item.content);
|
|
137
|
+
}
|
|
138
|
+
files[item.path] = hashText(item.content);
|
|
139
|
+
results.push({ path: item.path, action: { ok: 'unchanged', missing: 'created' }[item.state] ?? 'updated' });
|
|
140
|
+
} else if (item.kind === 'block') {
|
|
141
|
+
if (item.state === 'ok') {
|
|
142
|
+
results.push({ path: item.path, action: 'unchanged' });
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const current = readText(path);
|
|
146
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
147
|
+
writeFileSync(path, upsertBlock(current, item.style, item.content));
|
|
148
|
+
results.push({ path: item.path, action: current === null ? 'created' : 'block updated' });
|
|
149
|
+
} else {
|
|
150
|
+
if (item.state === 'ok') {
|
|
151
|
+
results.push({ path: item.path, action: 'unchanged' });
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (item.state === 'modified') {
|
|
155
|
+
results.push({ path: item.path, action: 'kept (not valid JSON; fix it and run agjan sync)' });
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
const data = readJson(path) ?? {};
|
|
159
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
160
|
+
writeJson(path, item.merge(data));
|
|
161
|
+
results.push({ path: item.path, action: 'merged' });
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
for (const [old, hash] of Object.entries(lock.files)) {
|
|
165
|
+
if (files[old] || plan.some((i) => i.path === old)) continue;
|
|
166
|
+
const path = join(root, old);
|
|
167
|
+
const current = readText(path);
|
|
168
|
+
if (current !== null && hashText(current) === hash) {
|
|
169
|
+
rmSync(path);
|
|
170
|
+
results.push({ path: old, action: 'removed (no longer part of the kit)' });
|
|
171
|
+
} else if (current !== null) {
|
|
172
|
+
results.push({ path: old, action: 'kept (no longer managed; modified locally)' });
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const sorted = Object.fromEntries(Object.entries(files).sort(([a], [b]) => a.localeCompare(b)));
|
|
176
|
+
writeJson(join(root, LOCK_FILE), { schema: 1, kit, files: sorted });
|
|
177
|
+
return results;
|
|
178
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { resolveArea } from './config.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Documentation MCP servers for the role skills (design 10.1): configured in
|
|
6
|
+
* agjan.config.json under `mcp.servers`, written into the hosts' project MCP files.
|
|
7
|
+
* The agjan server itself is never written here; it lives only in the reviewer agents.
|
|
8
|
+
*
|
|
9
|
+
* Kit defaults pin exact versions (kit/mcp/servers.json, shared with the skill source
|
|
10
|
+
* check in scripts/sources.mjs): `npx -y <package>` without a version would run whatever
|
|
11
|
+
* is newest at every start.
|
|
12
|
+
*/
|
|
13
|
+
export const PINNED = JSON.parse(readFileSync(new URL('../kit/mcp/servers.json', import.meta.url), 'utf8'));
|
|
14
|
+
export const DEFAULT_SERVERS = Object.fromEntries(
|
|
15
|
+
Object.entries(PINNED).map(([name, s]) => [name, { command: 'npx', args: ['-y', `${s.package}@${s.version}`], areas: s.areas }]),
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The servers to write, and the names to remove (configured with `enabled: false`).
|
|
20
|
+
* A server is written only when one of its areas belongs to an enabled domain.
|
|
21
|
+
*/
|
|
22
|
+
export function mcpServers(config) {
|
|
23
|
+
const configured = { ...DEFAULT_SERVERS, ...(config.mcp?.servers ?? {}) };
|
|
24
|
+
const servers = {};
|
|
25
|
+
const removed = [];
|
|
26
|
+
for (const [name, server] of Object.entries(configured)) {
|
|
27
|
+
const merged = { ...(DEFAULT_SERVERS[name] ?? {}), ...server };
|
|
28
|
+
if (merged.enabled === false) {
|
|
29
|
+
removed.push(name);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (!(merged.areas ?? []).some((a) => resolveArea(config, a))) continue;
|
|
33
|
+
servers[name] = { command: merged.command, args: merged.args ?? [], ...(merged.env ? { env: merged.env } : {}) };
|
|
34
|
+
}
|
|
35
|
+
return { servers, removed };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function sameEntry(a, b) {
|
|
39
|
+
return JSON.stringify(a ?? null) === JSON.stringify(b ?? null);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A JSON-merge plan item for one MCP file; `key` is the file's server map. `fixed`
|
|
44
|
+
* entries are written as they are (the agjan server for VS Code).
|
|
45
|
+
*/
|
|
46
|
+
function mergeItem(path, key, servers, removed, shape, fixed = {}) {
|
|
47
|
+
const expected = { ...Object.fromEntries(Object.entries(servers).map(([n, s]) => [n, shape(s)])), ...fixed };
|
|
48
|
+
return {
|
|
49
|
+
kind: 'json',
|
|
50
|
+
path,
|
|
51
|
+
present: (data) =>
|
|
52
|
+
Object.entries(expected).every(([n, s]) => sameEntry(data[key]?.[n], s)) && removed.every((n) => !data[key]?.[n]),
|
|
53
|
+
merge: (data) => {
|
|
54
|
+
const map = { ...(data[key] ?? {}), ...expected };
|
|
55
|
+
for (const n of removed) delete map[n];
|
|
56
|
+
return { ...data, [key]: map };
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* VS Code ignores `mcp-servers` in agent files, so its reviewer can only reach the
|
|
63
|
+
* agjan server through the workspace configuration, which the main chat sees too
|
|
64
|
+
* (decision 55). Records made through it say `isolation: shared`.
|
|
65
|
+
*/
|
|
66
|
+
export const VSCODE_AGJAN = { type: 'stdio', command: 'npx', args: ['--no-install', 'agjan', 'mcp', '--host', 'vscode', '--isolation', 'shared'] };
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* `.mcp.json` (Claude Code, Copilot CLI) and, with the Copilot host, `.vscode/mcp.json`
|
|
70
|
+
* (VS Code). Entries agjan does not manage are kept.
|
|
71
|
+
*/
|
|
72
|
+
export function plan(config) {
|
|
73
|
+
const { servers, removed } = mcpServers(config);
|
|
74
|
+
const hosts = config.hosts ?? [];
|
|
75
|
+
const items = [];
|
|
76
|
+
if ((hosts.includes('claude-code') || hosts.includes('copilot')) && (Object.keys(servers).length || removed.length)) {
|
|
77
|
+
items.push(mergeItem('.mcp.json', 'mcpServers', servers, removed, (s) => ({ ...s })));
|
|
78
|
+
}
|
|
79
|
+
if (hosts.includes('copilot')) {
|
|
80
|
+
items.push(mergeItem('.vscode/mcp.json', 'servers', servers, removed, (s) => ({ type: 'stdio', ...s }), { agjan: VSCODE_AGJAN }));
|
|
81
|
+
}
|
|
82
|
+
return items;
|
|
83
|
+
}
|
package/src/mcp.mjs
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { createInterface } from 'node:readline';
|
|
2
|
+
import { createReviewContext, recordReview } from './review.mjs';
|
|
3
|
+
import { selectFeature } from './feature.mjs';
|
|
4
|
+
import { AgjanError } from './errors.mjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The agjan MCP server (design 7.2): a minimal MCP implementation over stdio,
|
|
8
|
+
* newline-delimited JSON-RPC 2.0. It offers the reviewer's two operations as tools, so
|
|
9
|
+
* the reviewer needs no shell and findings never pass through a command line.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const SUPPORTED_VERSIONS = ['2025-11-25', '2025-06-18', '2025-03-26', '2024-11-05'];
|
|
13
|
+
|
|
14
|
+
const FINDING_SCHEMA = {
|
|
15
|
+
type: 'object',
|
|
16
|
+
properties: {
|
|
17
|
+
severity: { type: 'string', enum: ['blocker', 'major', 'minor'] },
|
|
18
|
+
file: { type: 'string', description: 'Repository-relative POSIX path' },
|
|
19
|
+
line: { type: 'integer', minimum: 1 },
|
|
20
|
+
issue: { type: 'string' },
|
|
21
|
+
suggestion: { type: 'string' },
|
|
22
|
+
},
|
|
23
|
+
required: ['severity', 'issue'],
|
|
24
|
+
additionalProperties: false,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const TOOLS = [
|
|
28
|
+
{
|
|
29
|
+
name: 'review_context',
|
|
30
|
+
title: 'agjan: get review context',
|
|
31
|
+
description:
|
|
32
|
+
'Returns the inputs for one agjan review step and a context_id. Read only this material ' +
|
|
33
|
+
'(and files it points to) for the review. Steps: spec, design:light, design, build:<area>, ' +
|
|
34
|
+
'build:<task id>, verify.',
|
|
35
|
+
inputSchema: {
|
|
36
|
+
type: 'object',
|
|
37
|
+
properties: {
|
|
38
|
+
step: { type: 'string', description: 'spec | design:light | design | build:<area> | build:<task id> | verify' },
|
|
39
|
+
feature: { type: 'string', description: 'Feature slug; optional when exactly one feature changed on the branch' },
|
|
40
|
+
},
|
|
41
|
+
required: ['step'],
|
|
42
|
+
additionalProperties: false,
|
|
43
|
+
},
|
|
44
|
+
annotations: { readOnlyHint: true },
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'review_record',
|
|
48
|
+
title: 'agjan: record review result',
|
|
49
|
+
description:
|
|
50
|
+
'Records the result of the review for a context_id: verdict, findings and the ids of earlier ' +
|
|
51
|
+
'findings this change resolves. Refused if any file changed since review_context.',
|
|
52
|
+
inputSchema: {
|
|
53
|
+
type: 'object',
|
|
54
|
+
properties: {
|
|
55
|
+
context_id: { type: 'string' },
|
|
56
|
+
verdict: { type: 'string', enum: ['pass', 'pass-with-notes', 'blocked'] },
|
|
57
|
+
findings: { type: 'array', items: FINDING_SCHEMA, maxItems: 50 },
|
|
58
|
+
resolves: { type: 'array', items: { type: 'string' } },
|
|
59
|
+
},
|
|
60
|
+
required: ['context_id', 'verdict'],
|
|
61
|
+
additionalProperties: false,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
function text(content, isError = false) {
|
|
67
|
+
return { content: [{ type: 'text', text: content }], isError };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Handles one tools/call; tool failures are results with isError, not protocol errors. */
|
|
71
|
+
function callTool(ctx, server, name, args = {}) {
|
|
72
|
+
try {
|
|
73
|
+
if (name === 'review_context') {
|
|
74
|
+
const feature = selectFeature(ctx.root, ctx.config, args.feature);
|
|
75
|
+
const { id, text: body } = createReviewContext(ctx.root, ctx.config, { feature, step: args.step });
|
|
76
|
+
return text(`context_id: ${id}\n\n${body}`);
|
|
77
|
+
}
|
|
78
|
+
if (name === 'review_record') {
|
|
79
|
+
const record = recordReview(ctx.root, ctx.config, args, { host: server.host, isolation: server.isolation, now: ctx.now });
|
|
80
|
+
const ids = record.findings.map((f) => f.id).join(', ') || 'none';
|
|
81
|
+
return text(`recorded ${record.id} (${record.step}, round ${record.round}): ${record.verdict}; findings: ${ids}`);
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (error instanceof AgjanError) return text(error.message, true);
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Handles one JSON-RPC message; returns the response, or null for notifications. */
|
|
91
|
+
export function handleMessage(ctx, server, message) {
|
|
92
|
+
const { id, method, params } = message ?? {};
|
|
93
|
+
const isRequest = id !== undefined && id !== null;
|
|
94
|
+
const reply = (result) => (isRequest ? { jsonrpc: '2.0', id, result } : null);
|
|
95
|
+
const fail = (code, msg) => (isRequest ? { jsonrpc: '2.0', id, error: { code, message: msg } } : null);
|
|
96
|
+
|
|
97
|
+
// An invalid request always gets an answer, with id null when it has none (JSON-RPC 2.0).
|
|
98
|
+
if (message?.jsonrpc !== '2.0' || typeof method !== 'string') {
|
|
99
|
+
return { jsonrpc: '2.0', id: isRequest ? id : null, error: { code: -32600, message: 'invalid request' } };
|
|
100
|
+
}
|
|
101
|
+
switch (method) {
|
|
102
|
+
case 'initialize': {
|
|
103
|
+
const requested = params?.protocolVersion;
|
|
104
|
+
return reply({
|
|
105
|
+
protocolVersion: SUPPORTED_VERSIONS.includes(requested) ? requested : SUPPORTED_VERSIONS[0],
|
|
106
|
+
capabilities: { tools: { listChanged: false } },
|
|
107
|
+
serverInfo: { name: 'agjan', version: ctx.kit },
|
|
108
|
+
instructions: 'agjan review tools. Only the agjan reviewer agent uses them.',
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
case 'ping':
|
|
112
|
+
return reply({});
|
|
113
|
+
case 'tools/list':
|
|
114
|
+
return reply({ tools: TOOLS });
|
|
115
|
+
case 'tools/call': {
|
|
116
|
+
const result = callTool(ctx, server, params?.name, params?.arguments);
|
|
117
|
+
return result ? reply(result) : fail(-32602, `unknown tool '${params?.name}'`);
|
|
118
|
+
}
|
|
119
|
+
default:
|
|
120
|
+
if (method.startsWith('notifications/')) return null;
|
|
121
|
+
return fail(-32601, `method not found: ${method}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Runs the server until stdin closes. Logs go to stderr; stdout carries only protocol. */
|
|
126
|
+
export function serve(ctx, server, { input = process.stdin, output = process.stdout } = {}) {
|
|
127
|
+
const rl = createInterface({ input, crlfDelay: Infinity });
|
|
128
|
+
rl.on('line', (line) => {
|
|
129
|
+
if (line.trim() === '') return;
|
|
130
|
+
let response;
|
|
131
|
+
try {
|
|
132
|
+
response = handleMessage(ctx, server, JSON.parse(line));
|
|
133
|
+
} catch (error) {
|
|
134
|
+
response = error instanceof SyntaxError
|
|
135
|
+
? { jsonrpc: '2.0', id: null, error: { code: -32700, message: 'parse error' } }
|
|
136
|
+
: { jsonrpc: '2.0', id: null, error: { code: -32603, message: error.message } };
|
|
137
|
+
ctx.err(`agjan mcp: ${error.stack ?? error.message}`);
|
|
138
|
+
}
|
|
139
|
+
if (response) output.write(`${JSON.stringify(response)}\n`);
|
|
140
|
+
});
|
|
141
|
+
return new Promise((resolve) => rl.on('close', () => resolve(0)));
|
|
142
|
+
}
|
package/src/plan.mjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { kitSkillFiles } from './managed.mjs';
|
|
3
|
+
import * as claudeCode from './adapters/claude-code.mjs';
|
|
4
|
+
import * as copilot from './adapters/copilot.mjs';
|
|
5
|
+
import * as mcpConfig from './mcp-config.mjs';
|
|
6
|
+
|
|
7
|
+
export const SKILLS_DIR = '.claude/skills';
|
|
8
|
+
export const ADAPTERS = { [claudeCode.HOST]: claudeCode, [copilot.HOST]: copilot };
|
|
9
|
+
|
|
10
|
+
const AGENTS_BLOCK = readFileSync(new URL('../kit/templates/agents-block.md', import.meta.url), 'utf8');
|
|
11
|
+
|
|
12
|
+
/** CLAUDE.md already imports AGENTS.md outside agjan's block: no block needed. */
|
|
13
|
+
function importsAgents(text) {
|
|
14
|
+
return text !== null && /^@AGENTS\.md\s*$/m.test(text.replace(/<!-- agjan:begin[\s\S]*?<!-- agjan:end -->/, ''));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Everything `agjan sync` maintains for this configuration: kit skills, managed blocks,
|
|
19
|
+
* and the files of each enabled host adapter (design 4.4).
|
|
20
|
+
*/
|
|
21
|
+
export function buildPlan(config) {
|
|
22
|
+
const skills = kitSkillFiles();
|
|
23
|
+
const items = Object.entries(skills).map(([path, content]) => ({ kind: 'file', path: `${SKILLS_DIR}/${path}`, content }));
|
|
24
|
+
items.push(
|
|
25
|
+
{ kind: 'block', path: 'AGENTS.md', style: 'md', content: AGENTS_BLOCK },
|
|
26
|
+
{ kind: 'block', path: 'CLAUDE.md', style: 'md', content: '@AGENTS.md', skip: importsAgents },
|
|
27
|
+
{ kind: 'block', path: '.gitattributes', style: 'hash', content: 'docs/agjan/** text eol=lf\nagjan.lock.json text eol=lf' },
|
|
28
|
+
{ kind: 'block', path: '.gitignore', style: 'hash', content: '.agjan/' },
|
|
29
|
+
);
|
|
30
|
+
for (const host of config.hosts ?? [claudeCode.HOST]) {
|
|
31
|
+
const adapter = ADAPTERS[host];
|
|
32
|
+
if (adapter) items.push(...adapter.plan(config, skills));
|
|
33
|
+
}
|
|
34
|
+
items.push(...mcpConfig.plan(config));
|
|
35
|
+
return items;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Hosts named in the configuration that have no adapter yet. */
|
|
39
|
+
export function unsupportedHosts(config) {
|
|
40
|
+
return (config.hosts ?? []).filter((h) => !ADAPTERS[h]);
|
|
41
|
+
}
|