agjan 0.0.9 → 0.0.10
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/docs/guide.md +8 -6
- package/package.json +1 -1
- package/src/cli.mjs +4 -1
- package/src/commands/setup.mjs +37 -41
- package/src/copilot-mcp.mjs +56 -0
package/docs/guide.md
CHANGED
|
@@ -48,11 +48,13 @@ Then:
|
|
|
48
48
|
|
|
49
49
|
1. Open the project in Claude Code once and **trust the folder**: the reviewer's tools
|
|
50
50
|
load only in a trusted folder. Allow the project MCP servers when asked (`cap`, `ui5`,
|
|
51
|
-
`fiori`: documentation tools for the role skills).
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
`fiori`: documentation tools for the role skills). GitHub Copilot CLI loads a
|
|
52
|
+
project's `.mcp.json` only in folders it remembers as trusted, so with the Copilot
|
|
53
|
+
host `init` asks to add these servers to your Copilot user configuration
|
|
54
|
+
(`copilot mcp add`); they then load in every Copilot session (`/mcp` lists them under
|
|
55
|
+
the user servers). A server with the same name that is already there is left as it
|
|
56
|
+
is. `npx agjan doctor` reports one you removed; `npx agjan sync --copilot-mcp` adds it
|
|
57
|
+
again.
|
|
56
58
|
2. Later, when a team shares the repository on GitHub, consider
|
|
57
59
|
[protecting the main branch](#protecting-the-main-branch-on-github-optional)
|
|
58
60
|
(optional).
|
|
@@ -338,7 +340,7 @@ Commit the result in a pull request of its own: CI reports it as a policy change
|
|
|
338
340
|
|
|
339
341
|
| Symptom | Cause and fix |
|
|
340
342
|
|---|---|
|
|
341
|
-
| Copilot shows only `github-mcp-server`, not `cap`, `ui5`, `fiori` |
|
|
343
|
+
| Copilot shows only `github-mcp-server`, not `cap`, `ui5`, `fiori` | They are not in Copilot's user configuration (`doctor`: copilot mcp), and Copilot ignores `.mcp.json` in folders it does not remember as trusted. Run `npx agjan sync --copilot-mcp`, then restart `copilot`. `/add-dir` does not help: it only allows file access. |
|
|
342
344
|
| The reviewer has no `review_context` tool | Claude Code: the folder is not trusted yet (`doctor` says so); open it once and accept. Copilot CLI: trust the folder when asked. |
|
|
343
345
|
| `approve` says it needs a human at an interactive terminal | It was run without a terminal, for example by an agent. Run it yourself in a terminal. |
|
|
344
346
|
| `approve` refuses: the review did not see the current files | Something changed after the last review; let the agent ask for the review again. |
|
package/package.json
CHANGED
package/src/cli.mjs
CHANGED
|
@@ -54,8 +54,11 @@ Usage: agjan <command> [options]
|
|
|
54
54
|
Setup (human):
|
|
55
55
|
init [--domains btp] [--hosts claude-code,copilot] [--base <ref>]
|
|
56
56
|
[--no-hook] [--no-ci] [--prepare] [--agent-allow | --no-agent-allow]
|
|
57
|
+
[--copilot-mcp | --no-copilot-mcp]
|
|
57
58
|
set up agjan in this repository
|
|
58
|
-
sync [--force]
|
|
59
|
+
sync [--force] [--copilot-mcp]
|
|
60
|
+
regenerate managed files (skills, agents, blocks, settings);
|
|
61
|
+
--copilot-mcp adds missing MCP servers to Copilot
|
|
59
62
|
hook install install the pre-commit hook
|
|
60
63
|
doctor check the environment and the project setup
|
|
61
64
|
|
package/src/commands/setup.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { spawnSync } from 'node:child_process';
|
|
2
|
-
import { existsSync, mkdirSync, readFileSync,
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
|
-
import {
|
|
4
|
+
import { join } from 'node:path';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
import { parseArgs } from 'node:util';
|
|
7
7
|
import { CONFIG_FILE, MODEL_TIERS, RECOMMENDED_ALLOW, SESSION_MODEL, agentModel, loadConfig, loadDomain } from '../config.mjs';
|
|
@@ -15,6 +15,8 @@ import { GUARD } from '../adapters/copilot.mjs';
|
|
|
15
15
|
import { git, mergeBase, resolveBase } from '../git.mjs';
|
|
16
16
|
import { AgjanError, UsageError } from '../errors.mjs';
|
|
17
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';
|
|
18
20
|
|
|
19
21
|
const CI_FILE = '.github/workflows/agjan.yml';
|
|
20
22
|
const CI_TEMPLATE = new URL('../../kit/templates/agjan-ci.yml', import.meta.url);
|
|
@@ -106,7 +108,7 @@ function nextSteps(ctx, hosts, firstCommit) {
|
|
|
106
108
|
steps.push("Open this folder once in Claude Code and trust it: the reviewer's agjan tools load only in trusted folders.");
|
|
107
109
|
}
|
|
108
110
|
if (hosts.includes('copilot')) {
|
|
109
|
-
steps.push(`Start ${s.cyan('copilot')} in this folder and
|
|
111
|
+
steps.push(`Start ${s.cyan('copilot')} in this folder and trust it. Without agent.allow_edits, answer the first file edit prompt with "don't ask again for file operations", or start ${s.cyan('copilot --allow-tool write')}.`);
|
|
110
112
|
}
|
|
111
113
|
steps.push(`Run: ${s.cyan('npx agjan doctor')}`);
|
|
112
114
|
return ['', s.bold('Next steps:'), ...steps.map((text, i) => ` ${i + 1}. ${text}`)];
|
|
@@ -131,6 +133,8 @@ export async function init(ctx, argv) {
|
|
|
131
133
|
'no-agent-allow': { type: 'boolean' },
|
|
132
134
|
'agent-allow-edits': { type: 'boolean' },
|
|
133
135
|
'no-agent-allow-edits': { type: 'boolean' },
|
|
136
|
+
'copilot-mcp': { type: 'boolean' },
|
|
137
|
+
'no-copilot-mcp': { type: 'boolean' },
|
|
134
138
|
},
|
|
135
139
|
});
|
|
136
140
|
const root = ctx.root;
|
|
@@ -154,6 +158,12 @@ export async function init(ctx, argv) {
|
|
|
154
158
|
ask(ctx, `Let agents run these commands without a prompt: ${RECOMMENDED_ALLOW.join(', ')}?\n(agjan approve, accept and reject stay blocked; change agent.allow in ${CONFIG_FILE} later.)`, { defaultYes: true }) ?? false;
|
|
155
159
|
const allowEdits = flag('agent-allow-edits', 'no-agent-allow-edits') ??
|
|
156
160
|
ask(ctx, 'Let agents change files in this project without a prompt?\n(agjan records and policy files excluded; agjan checks the scope of every change.)', { defaultYes: true }) ?? false;
|
|
161
|
+
// Copilot loads the project's .mcp.json only in folders it remembers as trusted; its
|
|
162
|
+
// user configuration loads everywhere (decision 72).
|
|
163
|
+
const areas = Object.fromEntries(domains.flatMap((d) => Object.keys(loadDomain(d).areas).flatMap((a) => [[a, {}], [`${d}:${a}`, {}]])));
|
|
164
|
+
const servers = Object.keys(mcpServers({ areas }).servers);
|
|
165
|
+
const copilotMcp = hosts.includes('copilot') && servers.length > 0 && (flag('copilot-mcp', 'no-copilot-mcp') ??
|
|
166
|
+
ask(ctx, `Add the documentation MCP servers ${servers.join(', ')} to your Copilot configuration (copilot mcp add)?\n(Copilot loads a project's .mcp.json only in folders it remembers as trusted; these then load in every Copilot session.)`, { defaultYes: true }) ?? false);
|
|
157
167
|
|
|
158
168
|
const config = {
|
|
159
169
|
$schema: './node_modules/agjan/schemas/config.schema.json',
|
|
@@ -172,6 +182,7 @@ export async function init(ctx, argv) {
|
|
|
172
182
|
const setting = (on, text) => ` ${pad(on ? tone(s, 'created') : s.gray('none'), on ? 'created' : 'none', 14)} ${text}`;
|
|
173
183
|
ctx.out(setting(agentAllow, `agent.allow${agentAllow ? ` (${RECOMMENDED_ALLOW.length} commands)` : ''}`));
|
|
174
184
|
ctx.out(setting(allowEdits, `agent.allow_edits${allowEdits ? ' (file changes without a prompt)' : ''}`));
|
|
185
|
+
if (copilotMcp) addToCopilot(ctx, loadConfig(root));
|
|
175
186
|
|
|
176
187
|
if (!values['no-hook']) {
|
|
177
188
|
const hook = installHook(root);
|
|
@@ -210,13 +221,28 @@ function addPrepare(root) {
|
|
|
210
221
|
return `added "prepare": "${command}"`;
|
|
211
222
|
}
|
|
212
223
|
|
|
213
|
-
/**
|
|
224
|
+
/**
|
|
225
|
+
* Adds the documentation MCP servers to Copilot's user configuration and reports each:
|
|
226
|
+
* added, already there (left as it is), or failed with the command to run by hand.
|
|
227
|
+
*/
|
|
228
|
+
function addToCopilot(ctx, config) {
|
|
229
|
+
const s = ctx.style;
|
|
230
|
+
const { servers } = mcpServers(config);
|
|
231
|
+
for (const r of addCopilotServers(servers)) {
|
|
232
|
+
const action = r.state === 'added' ? 'created' : r.state === 'exists' ? 'unchanged' : 'failed';
|
|
233
|
+
ctx.out(` ${pad(tone(s, action), action, 14)} copilot mcp ${r.name}: ${r.detail}`);
|
|
234
|
+
if (r.state === 'failed') ctx.out(` ${' '.repeat(14)} add it yourself: ${s.cyan(addCommand(r.name, servers[r.name]).join(' '))}`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** agjan sync [--force] [--copilot-mcp]: regenerate managed files; edited ones are kept unless --force. */
|
|
214
239
|
export function sync(ctx, argv) {
|
|
215
|
-
const { values } = parseArgs({ args: argv, options: { force: { type: 'boolean' } } });
|
|
240
|
+
const { values } = parseArgs({ args: argv, options: { force: { type: 'boolean' }, 'copilot-mcp': { type: 'boolean' } } });
|
|
216
241
|
if (!existsSync(join(ctx.root, CONFIG_FILE))) throw new AgjanError(`no ${CONFIG_FILE}; run 'agjan init' first`);
|
|
217
242
|
ctx.out(`${ctx.style.bold('agjan sync')}:`);
|
|
218
243
|
const results = doSync(ctx, { force: values.force });
|
|
219
244
|
printResults(ctx, results);
|
|
245
|
+
if (values['copilot-mcp']) addToCopilot(ctx, ctx.config);
|
|
220
246
|
return results.some((r) => r.action.startsWith('kept')) ? 1 : 0;
|
|
221
247
|
}
|
|
222
248
|
|
|
@@ -259,39 +285,6 @@ function claudeTrust(root) {
|
|
|
259
285
|
return data.projects[root]?.hasTrustDialogAccepted === true ? 'trusted' : 'not trusted';
|
|
260
286
|
}
|
|
261
287
|
|
|
262
|
-
/**
|
|
263
|
-
* Whether Copilot CLI trusts the project folder: the folder or a parent is in
|
|
264
|
-
* `trustedFolders` of its config.json or settings.json (in COPILOT_HOME, default
|
|
265
|
-
* ~/.copilot; read-only). Only a remembered folder loads the workspace's .mcp.json.
|
|
266
|
-
*/
|
|
267
|
-
export function copilotTrust(root, dir = process.env.COPILOT_HOME || join(homedir(), '.copilot')) {
|
|
268
|
-
const files = ['config.json', 'settings.json'].map((f) => join(dir, f)).filter((f) => existsSync(f));
|
|
269
|
-
if (!files.length) return 'unknown';
|
|
270
|
-
const folders = files.flatMap((f) => {
|
|
271
|
-
try {
|
|
272
|
-
// Copilot writes comment lines at the top of its config file.
|
|
273
|
-
const list = JSON.parse(readFileSync(f, 'utf8').replace(/^\s*\/\/.*$/gm, '')).trustedFolders;
|
|
274
|
-
return Array.isArray(list) ? list.filter((x) => typeof x === 'string') : [];
|
|
275
|
-
} catch {
|
|
276
|
-
return [];
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
const fold = process.platform === 'darwin' || process.platform === 'win32' ? (p) => p.toLowerCase() : (p) => p;
|
|
280
|
-
const real = (p) => {
|
|
281
|
-
try {
|
|
282
|
-
return fold(realpathSync(p));
|
|
283
|
-
} catch {
|
|
284
|
-
return fold(resolve(p));
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
const here = real(root);
|
|
288
|
-
const inside = (folder) => {
|
|
289
|
-
const rel = relative(real(folder), here);
|
|
290
|
-
return rel === '' || (!rel.startsWith('..') && !isAbsolute(rel));
|
|
291
|
-
};
|
|
292
|
-
return folders.some(inside) ? 'trusted' : 'not trusted';
|
|
293
|
-
}
|
|
294
|
-
|
|
295
288
|
/** agjan doctor: checks the environment and the project setup; exit 1 on any failure. */
|
|
296
289
|
export function doctor(ctx) {
|
|
297
290
|
for (const line of mark(ctx.style, ctx.kit, 'doctor: environment and project setup')) ctx.out(line);
|
|
@@ -356,9 +349,12 @@ export function doctor(ctx) {
|
|
|
356
349
|
const guard = probeGuard(root);
|
|
357
350
|
if (guard) warn('copilot guard', guard);
|
|
358
351
|
else ok('copilot guard', 'denies agjan approve in a test payload');
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
|
|
352
|
+
const names = Object.keys(mcpServers(config).servers);
|
|
353
|
+
const known = names.length ? copilotServers() : {};
|
|
354
|
+
const missing = names.filter((name) => !known?.[name]);
|
|
355
|
+
if (!known) warn('copilot mcp', 'copilot is not on PATH; its MCP servers were not checked');
|
|
356
|
+
else if (missing.length) warn('copilot mcp', `${missing.join(', ')} not in Copilot's configuration (removed?); add: npx agjan sync --copilot-mcp`);
|
|
357
|
+
else if (names.length) ok('copilot mcp', `${names.join(', ')} in Copilot's configuration`);
|
|
362
358
|
}
|
|
363
359
|
if (config.hosts.includes('claude-code')) {
|
|
364
360
|
const trust = claudeTrust(root);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Copilot CLI loads a project's .mcp.json only in folders it remembers as trusted, so
|
|
5
|
+
* `init` also adds the documentation servers to Copilot's user configuration with
|
|
6
|
+
* `copilot mcp add` (design decision 72). Servers there load in every folder. agjan
|
|
7
|
+
* never removes or changes a server in that configuration: one that exists is reported
|
|
8
|
+
* and left as it is.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Runs the copilot command; AGJAN_COPILOT names a Node script that replaces it (tests). */
|
|
12
|
+
function copilot(args) {
|
|
13
|
+
const options = { encoding: 'utf8', timeout: 60_000 };
|
|
14
|
+
const fake = process.env.AGJAN_COPILOT;
|
|
15
|
+
if (fake) return spawnSync(process.execPath, [fake, ...args], options);
|
|
16
|
+
return spawnSync('copilot', args, { ...options, shell: process.platform === 'win32' });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The command line that adds one server, for messages and for doing it by hand. */
|
|
20
|
+
export function addCommand(name, server) {
|
|
21
|
+
const env = Object.entries(server.env ?? {}).flatMap(([k, v]) => ['--env', `${k}=${v}`]);
|
|
22
|
+
return ['copilot', 'mcp', 'add', ...env, name, '--', server.command, ...(server.args ?? [])];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The servers Copilot knows (user, workspace, plugin; not its built-in ones), as
|
|
27
|
+
* { name: { source, command, args } }, or null when copilot cannot be run.
|
|
28
|
+
*/
|
|
29
|
+
export function copilotServers() {
|
|
30
|
+
const run = copilot(['mcp', 'list', '--json']);
|
|
31
|
+
if (run.error || run.status !== 0) return null;
|
|
32
|
+
try {
|
|
33
|
+
const list = JSON.parse(run.stdout).mcpServers ?? {};
|
|
34
|
+
return Object.fromEntries(Object.entries(list).filter(([, s]) => s.source !== 'builtin'));
|
|
35
|
+
} catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Adds each server that Copilot does not know yet. Returns one result per server:
|
|
42
|
+
* `added`, `exists` (left as it is), or `failed` with the reason.
|
|
43
|
+
*/
|
|
44
|
+
export function addCopilotServers(servers) {
|
|
45
|
+
const known = copilotServers();
|
|
46
|
+
if (!known) return Object.keys(servers).map((name) => ({ name, state: 'failed', detail: 'copilot is not on PATH' }));
|
|
47
|
+
return Object.entries(servers).map(([name, server]) => {
|
|
48
|
+
if (known[name]) return { name, state: 'exists', detail: `already in Copilot's ${known[name].source} configuration; left as it is` };
|
|
49
|
+
const run = copilot(addCommand(name, server).slice(1));
|
|
50
|
+
const output = `${run.stdout ?? ''}${run.stderr ?? ''}`.trim();
|
|
51
|
+
if (run.error || run.status !== 0 || /^Error:/m.test(output)) {
|
|
52
|
+
return { name, state: 'failed', detail: (output.split('\n').find((l) => l.startsWith('Error:')) ?? output.split('\n')[0] ?? `exit code ${run.status}`).trim() };
|
|
53
|
+
}
|
|
54
|
+
return { name, state: 'added', detail: "Copilot's user configuration" };
|
|
55
|
+
});
|
|
56
|
+
}
|