@imdeadpool/guardex 8.4.0 → 8.4.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/CONTRIBUTING.md +13 -4
- package/README.md +223 -1
- package/THIRD-PARTY-NOTICES.md +29 -0
- package/bin/multiagent-safety.js +9 -12
- package/package.json +4 -2
- package/skills/gitguardex/SKILL.md +28 -0
- package/skills/pr-lens/SKILL.md +87 -0
- package/src/abide.js +534 -0
- package/src/agents/activity.js +23 -4
- package/src/agents/inspect.js +15 -6
- package/src/agents/launch.js +6 -1
- package/src/agents/process-lease.js +84 -0
- package/src/agents/sessions.js +96 -16
- package/src/agents/start.js +18 -9
- package/src/agents/status.js +35 -14
- package/src/agents/supervise.js +87 -0
- package/src/budget/index.js +6 -1
- package/src/cli/args.js +71 -77
- package/src/cli/commands/agents.js +38 -10
- package/src/cli/commands/branch.js +116 -103
- package/src/cli/commands/claude.js +604 -50
- package/src/cli/commands/codex.js +359 -0
- package/src/cli/commands/context.js +52 -0
- package/src/cli/commands/mcp.js +5 -1
- package/src/cli/commands/pr.js +138 -3
- package/src/cli/commands/review.js +3 -1
- package/src/cli/commands/setup.js +25 -0
- package/src/cli/commands/status.js +128 -60
- package/src/cli/commands/storage.js +24 -0
- package/src/cli/commands/usage.js +48 -0
- package/src/cli/commands/watch.js +157 -47
- package/src/cli/commands/worktree-copy-ignored.js +38 -0
- package/src/cli/commands/worktree-estimate.js +69 -0
- package/src/cli/commands/worktree-hooks.js +62 -0
- package/src/cli/commands/worktree-navigation.js +71 -0
- package/src/cli/commands/worktree-provision.js +92 -0
- package/src/cli/main.js +229 -110
- package/src/cli/shared/gate-flags.js +131 -0
- package/src/cli/shared/scaffolding.js +31 -3
- package/src/cli/shared-locks.js +3 -1
- package/src/cockpit/pane-actions.js +43 -7
- package/src/context.js +373 -17
- package/src/doctor/index.js +29 -35
- package/src/finish/events.js +254 -0
- package/src/finish/index.js +322 -62
- package/src/finish/post-branch-finish-cleanup.js +316 -22
- package/src/finish/preflight.js +44 -1
- package/src/finish/progress.js +36 -0
- package/src/finish/review-gate.js +317 -127
- package/src/finish/review-receipt.js +156 -0
- package/src/finish/with-claims-lock.py +29 -0
- package/src/git/index.js +179 -42
- package/src/hooks/index.js +68 -3
- package/src/mcp/collect.js +61 -5
- package/src/mcp/server.js +4 -0
- package/src/output/index.js +167 -1
- package/src/pr-lens-publish.js +93 -0
- package/src/pr-lens.js +184 -0
- package/src/pr-respond.js +860 -0
- package/src/pr-review.js +519 -159
- package/src/pr.js +73 -14
- package/src/provider-binary.js +21 -0
- package/src/review-diff-context.js +90 -0
- package/src/review-fix.js +23 -17
- package/src/scaffold/agent-worktree-prep.js +14 -12
- package/src/scaffold/dependency-store.js +234 -0
- package/src/scaffold/index.js +13 -1
- package/src/scaffold/provision-approvals.js +83 -0
- package/src/scaffold/provision-config.js +169 -40
- package/src/shared-git-state.js +11 -1
- package/src/speckit/index.js +12 -1
- package/src/storage/run-artifacts.js +185 -0
- package/src/toolchain/index.js +322 -2
- package/src/worktree-copy-ignored.js +200 -0
- package/src/worktree-hook-worker.js +29 -0
- package/src/worktree-hooks.js +333 -0
- package/src/worktree-navigation.js +248 -0
- package/src/worktree-picker.js +89 -0
- package/src/worktree-quota.js +100 -0
- package/src/worktree-start.js +100 -0
- package/templates/AGENTS.multiagent-safety.md +8 -0
- package/templates/AGENTS.multiagent-safety.min.md +3 -1
- package/templates/codex/skills/gitguardex/SKILL.md +28 -0
- package/templates/codex/skills/opensrc/SKILL.md +24 -0
- package/templates/githooks/post-merge +16 -2
- package/templates/scripts/agent-autofinish-watch.sh +17 -18
- package/templates/scripts/agent-branch-finish.sh +180 -19
- package/templates/scripts/agent-branch-merge.sh +7 -32
- package/templates/scripts/agent-branch-start.sh +202 -43
- package/templates/scripts/agent-claude-stop-finish.sh +4 -27
- package/templates/scripts/agent-file-locks.py +257 -29
- package/templates/scripts/agent-preflight.sh +3 -0
- package/templates/scripts/agent-worktree-prune.sh +975 -63
- package/templates/scripts/codex-agent.sh +55 -5
- package/templates/scripts/lib/guardex-base-branch.sh +207 -0
- package/templates/scripts/openspec/init-change-workspace.sh +10 -18
- package/templates/scripts/review-bot-watch.sh +171 -4
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
//
|
|
3
3
|
// Subcommands:
|
|
4
4
|
// gx claude install install/update .claude/settings.json, hooks, slash
|
|
5
|
-
// commands,
|
|
6
|
-
// target repo. Idempotent.
|
|
5
|
+
// commands, the gitguardex agent skill, and the abide
|
|
6
|
+
// rule hooks in the target repo. Idempotent.
|
|
7
7
|
// gx claude check diagnose Claude Code wiring (no mutations).
|
|
8
8
|
// gx claude uninstall remove gitguardex-managed Claude Code wiring.
|
|
9
9
|
// gx claude doctor alias for `check --fix`.
|
|
@@ -11,19 +11,41 @@
|
|
|
11
11
|
// This command makes a repo "Claude Code-ready" so the agent can pivot, claim
|
|
12
12
|
// files, open PRs, and follow the gitguardex contract without manual setup.
|
|
13
13
|
|
|
14
|
+
const cp = require('child_process');
|
|
14
15
|
const fs = require('fs');
|
|
15
16
|
const path = require('path');
|
|
17
|
+
const { isDeepStrictEqual } = require('util');
|
|
16
18
|
const { TOOL_NAME, SHORT_TOOL_NAME } = require('../../context');
|
|
17
|
-
const { resolveRepoRoot } = require('../../git');
|
|
19
|
+
const { gitRun, resolveRepoRoot } = require('../../git');
|
|
20
|
+
const { requireValue } = require('../args');
|
|
18
21
|
|
|
19
22
|
const SETTINGS_REL = '.claude/settings.json';
|
|
20
23
|
const HOOKS_REL = '.claude/hooks';
|
|
21
24
|
const COMMANDS_REL = '.claude/commands';
|
|
22
25
|
const SKILLS_REL = '.claude/skills';
|
|
23
|
-
// Repo-scoped MCP registration
|
|
24
|
-
//
|
|
26
|
+
// Repo-scoped MCP registration for the gx radar and CodeGraph. Opt out with
|
|
27
|
+
// --no-mcp when a repository manages its own MCP surface.
|
|
25
28
|
const MCP_REL = '.mcp.json';
|
|
26
29
|
const MCP_SERVER_KEY = SHORT_TOOL_NAME;
|
|
30
|
+
const MCP_SERVER_SPECS = {
|
|
31
|
+
[MCP_SERVER_KEY]: { command: SHORT_TOOL_NAME, args: ['mcp', 'serve'] },
|
|
32
|
+
codegraph: { type: 'stdio', command: 'codegraph', args: ['serve', '--mcp'] },
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Abide (github.com/coldteadotai/abide) compiles the repo's AGENTS.md /
|
|
36
|
+
// CLAUDE.md into a rubric and judges every edit against it from outside the
|
|
37
|
+
// agent's context window. gx installs the four hooks through the in-repo shim
|
|
38
|
+
// `.claude/hooks/abide_hook.js` (a managed hook file below), so the committed
|
|
39
|
+
// settings entry is the same on every machine; the shim finds the abide
|
|
40
|
+
// package at run time. Opt out with --no-abide. Shared runtime: src/abide.js.
|
|
41
|
+
const abide = require('../../abide');
|
|
42
|
+
const ABIDE_COMPILE_TIMEOUT_MS = 15 * 60_000;
|
|
43
|
+
const ABIDE_CALIBRATE_TIMEOUT_MS = 10 * 60_000;
|
|
44
|
+
|
|
45
|
+
const MANAGED_AGENT_SKILLS = [
|
|
46
|
+
{ name: 'gitguardex', source: ['.claude', 'skills', 'gitguardex'] },
|
|
47
|
+
{ name: 'opensrc', source: ['templates', 'codex', 'skills', 'opensrc'] },
|
|
48
|
+
];
|
|
27
49
|
|
|
28
50
|
const MANAGED_HOOK_FILES = [
|
|
29
51
|
'skill_guard.py',
|
|
@@ -35,6 +57,8 @@ const MANAGED_HOOK_FILES = [
|
|
|
35
57
|
// for live-session presence. Must ship with them or those hooks fail their
|
|
36
58
|
// import (fail-open, but then presence is silently absent on target repos).
|
|
37
59
|
'_session_presence.py',
|
|
60
|
+
// Portable launcher for abide's rule hooks; finds @coldtea/abide at run time.
|
|
61
|
+
'abide_hook.js',
|
|
38
62
|
];
|
|
39
63
|
|
|
40
64
|
const MANAGED_SLASH_COMMANDS = [
|
|
@@ -255,19 +279,24 @@ function installSlashCommands(repoRoot, { dryRun }) {
|
|
|
255
279
|
return results;
|
|
256
280
|
}
|
|
257
281
|
|
|
258
|
-
function
|
|
282
|
+
function installAgentSkills(repoRoot, { dryRun }) {
|
|
259
283
|
const packageRoot = findPackageRoot();
|
|
260
|
-
const srcDir = path.join(packageRoot, SKILLS_REL, 'gitguardex');
|
|
261
|
-
if (!fs.existsSync(srcDir)) return { status: 'source-missing' };
|
|
262
|
-
const destDir = path.join(repoRoot, SKILLS_REL, 'gitguardex');
|
|
263
|
-
if (!dryRun) fs.mkdirSync(destDir, { recursive: true });
|
|
264
284
|
const results = [];
|
|
265
|
-
for (const
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
285
|
+
for (const skill of MANAGED_AGENT_SKILLS) {
|
|
286
|
+
const srcDir = path.join(packageRoot, ...skill.source);
|
|
287
|
+
if (!fs.existsSync(srcDir)) {
|
|
288
|
+
results.push({ skill: skill.name, status: 'source-missing' });
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
const destDir = path.join(repoRoot, SKILLS_REL, skill.name);
|
|
292
|
+
if (!dryRun) fs.mkdirSync(destDir, { recursive: true });
|
|
293
|
+
for (const entry of fs.readdirSync(srcDir)) {
|
|
294
|
+
const src = path.join(srcDir, entry);
|
|
295
|
+
const dest = path.join(destDir, entry);
|
|
296
|
+
if (fs.statSync(src).isDirectory()) continue;
|
|
297
|
+
const result = copyFileIfDifferent(src, dest, { dryRun });
|
|
298
|
+
results.push({ skill: `${skill.name}/${entry}`, ...result });
|
|
299
|
+
}
|
|
271
300
|
}
|
|
272
301
|
return { status: 'ok', files: results };
|
|
273
302
|
}
|
|
@@ -346,44 +375,426 @@ function describeStatus(s) {
|
|
|
346
375
|
}
|
|
347
376
|
|
|
348
377
|
function mcpServerSpec() {
|
|
349
|
-
return
|
|
378
|
+
return MCP_SERVER_SPECS[MCP_SERVER_KEY];
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function mcpSpecsMatch(actual, desired) {
|
|
382
|
+
return isDeepStrictEqual(actual, desired);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function conflictingMcpTransportFields(actual, desired) {
|
|
386
|
+
const desiredType = desired.type || (desired.command ? 'stdio' : null);
|
|
387
|
+
const conflicts = [];
|
|
388
|
+
if (Object.prototype.hasOwnProperty.call(actual, 'type') && actual.type !== desiredType) {
|
|
389
|
+
conflicts.push('type');
|
|
390
|
+
}
|
|
391
|
+
if (desiredType === 'stdio') {
|
|
392
|
+
for (const key of ['url', 'headers']) {
|
|
393
|
+
if (Object.prototype.hasOwnProperty.call(actual, key)) conflicts.push(key);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return conflicts;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function mcpSpecCompatible(actual, desired) {
|
|
400
|
+
return Boolean(
|
|
401
|
+
actual
|
|
402
|
+
&& typeof actual === 'object'
|
|
403
|
+
&& !Array.isArray(actual)
|
|
404
|
+
&& conflictingMcpTransportFields(actual, desired).length === 0
|
|
405
|
+
&& Object.entries(desired).every(([key, value]) => isDeepStrictEqual(actual[key], value)),
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function missingManagedMcpServers(config) {
|
|
410
|
+
return Object.entries(MCP_SERVER_SPECS)
|
|
411
|
+
.filter(([key, desired]) => !mcpSpecCompatible(config?.mcpServers?.[key], desired))
|
|
412
|
+
.map(([key]) => key);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function resolveMcpStatePath(repoRoot) {
|
|
416
|
+
const result = gitRun(repoRoot, ['rev-parse', '--git-dir'], { allowFailure: true });
|
|
417
|
+
if (result.status !== 0 || !result.stdout.trim()) {
|
|
418
|
+
throw new Error(`Unable to resolve git metadata directory for ${repoRoot}`);
|
|
419
|
+
}
|
|
420
|
+
const gitDir = path.resolve(repoRoot, result.stdout.trim());
|
|
421
|
+
return path.join(gitDir, 'guardex', 'claude-mcp-state.json');
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function resolveMcpConfigLinkPath(statePath, filePath, location = 'git') {
|
|
425
|
+
if (location === 'worktree') {
|
|
426
|
+
return path.join(path.dirname(filePath), '.omx', 'state', 'claude-mcp-config-link');
|
|
427
|
+
}
|
|
428
|
+
return `${statePath}.config-link`;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function removeMcpOwnershipState(statePath, filePath) {
|
|
432
|
+
const managedPaths = [
|
|
433
|
+
statePath,
|
|
434
|
+
resolveMcpConfigLinkPath(statePath, filePath, 'git'),
|
|
435
|
+
resolveMcpConfigLinkPath(statePath, filePath, 'worktree'),
|
|
436
|
+
];
|
|
437
|
+
for (const managedPath of managedPaths) {
|
|
438
|
+
if (fs.existsSync(managedPath)) fs.unlinkSync(managedPath);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function replaceMcpConfigLink(filePath, statePath) {
|
|
443
|
+
for (const location of ['git', 'worktree']) {
|
|
444
|
+
const linkPath = resolveMcpConfigLinkPath(statePath, filePath, location);
|
|
445
|
+
const temporaryPath = `${linkPath}.tmp-${process.pid}`;
|
|
446
|
+
try {
|
|
447
|
+
fs.mkdirSync(path.dirname(linkPath), { recursive: true });
|
|
448
|
+
if (fs.existsSync(temporaryPath)) fs.unlinkSync(temporaryPath);
|
|
449
|
+
fs.linkSync(filePath, temporaryPath);
|
|
450
|
+
fs.renameSync(temporaryPath, linkPath);
|
|
451
|
+
const otherLocation = location === 'git' ? 'worktree' : 'git';
|
|
452
|
+
const otherPath = resolveMcpConfigLinkPath(statePath, filePath, otherLocation);
|
|
453
|
+
if (fs.existsSync(otherPath)) fs.unlinkSync(otherPath);
|
|
454
|
+
return location;
|
|
455
|
+
} catch {
|
|
456
|
+
if (fs.existsSync(temporaryPath)) fs.unlinkSync(temporaryPath);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return null;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function mcpStateMatchesConfig(state, filePath, statePath) {
|
|
463
|
+
const linkPath = resolveMcpConfigLinkPath(statePath, filePath, state?.configLink);
|
|
464
|
+
if (state?.version !== 2 || !['git', 'worktree'].includes(state.configLink)
|
|
465
|
+
|| !fs.existsSync(filePath) || !fs.existsSync(linkPath)) return false;
|
|
466
|
+
const configStat = fs.statSync(filePath);
|
|
467
|
+
const linkStat = fs.statSync(linkPath);
|
|
468
|
+
return Boolean(
|
|
469
|
+
configStat.dev === linkStat.dev
|
|
470
|
+
&& configStat.ino === linkStat.ino,
|
|
471
|
+
);
|
|
350
472
|
}
|
|
351
473
|
|
|
352
474
|
// Register the read-only `gx mcp` server in the target repo's .mcp.json so any
|
|
353
475
|
// agent there can call list_agents / who_owns / my_context. Merges into an
|
|
354
476
|
// existing .mcp.json without disturbing other servers; idempotent.
|
|
355
|
-
function installMcpServer(repoRoot, { dryRun }) {
|
|
477
|
+
function installMcpServer(repoRoot, { dryRun, linkConfig = replaceMcpConfigLink }) {
|
|
356
478
|
const filePath = path.join(repoRoot, MCP_REL);
|
|
479
|
+
const statePath = resolveMcpStatePath(repoRoot);
|
|
357
480
|
const fileExisted = fs.existsSync(filePath);
|
|
358
|
-
const
|
|
359
|
-
config
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
481
|
+
const originalContents = fileExisted ? fs.readFileSync(filePath) : null;
|
|
482
|
+
const config = fileExisted ? readJsonIfExists(filePath) : {};
|
|
483
|
+
if (config === null || typeof config !== 'object' || Array.isArray(config)) {
|
|
484
|
+
throw new Error(`${MCP_REL} must contain a JSON object`);
|
|
485
|
+
}
|
|
486
|
+
if (config.mcpServers == null) config.mcpServers = {};
|
|
487
|
+
else if (typeof config.mcpServers !== 'object' || Array.isArray(config.mcpServers)) {
|
|
488
|
+
throw new Error(`${MCP_REL} has a non-object mcpServers value`);
|
|
489
|
+
}
|
|
490
|
+
const existingState = readJsonIfExists(statePath);
|
|
491
|
+
const missingServers = missingManagedMcpServers(config);
|
|
492
|
+
if (missingServers.length === 0) {
|
|
493
|
+
if (!dryRun && (!existingState || !mcpStateMatchesConfig(existingState, filePath, statePath))) {
|
|
494
|
+
removeMcpOwnershipState(statePath, filePath);
|
|
495
|
+
writeJson(statePath, { version: 2, configLink: null, servers: {} }, { dryRun: false });
|
|
496
|
+
}
|
|
363
497
|
return { status: 'unchanged', dest: filePath };
|
|
364
498
|
}
|
|
365
|
-
|
|
366
|
-
config.mcpServers[
|
|
367
|
-
|
|
368
|
-
|
|
499
|
+
|
|
500
|
+
const hadManagedServer = Object.keys(MCP_SERVER_SPECS).some((key) => config.mcpServers[key]);
|
|
501
|
+
// A missing .mcp.json means any surviving ownership state is stale. Start a
|
|
502
|
+
// fresh record instead of restoring definitions from an earlier config.
|
|
503
|
+
const state = (fileExisted && existingState && mcpStateMatchesConfig(existingState, filePath, statePath)
|
|
504
|
+
? existingState
|
|
505
|
+
: null)
|
|
506
|
+
|| { version: 2, configLink: null, servers: {} };
|
|
507
|
+
state.servers = state.servers || {};
|
|
508
|
+
for (const [key, desired] of Object.entries(MCP_SERVER_SPECS)) {
|
|
509
|
+
const isLegacyGx = key === MCP_SERVER_KEY
|
|
510
|
+
&& !existingState
|
|
511
|
+
&& !state.servers[key]
|
|
512
|
+
&& mcpSpecsMatch(config.mcpServers[key], desired);
|
|
513
|
+
if (!missingServers.includes(key) && !isLegacyGx) continue;
|
|
514
|
+
const hadPrevious = !isLegacyGx && Object.prototype.hasOwnProperty.call(config.mcpServers, key);
|
|
515
|
+
state.servers[key] = {
|
|
516
|
+
hadPrevious,
|
|
517
|
+
...(hadPrevious ? { previous: deepClone(config.mcpServers[key]) } : {}),
|
|
518
|
+
};
|
|
519
|
+
if (!isLegacyGx) {
|
|
520
|
+
const current = config.mcpServers[key];
|
|
521
|
+
const compatibleFields = current && typeof current === 'object' && !Array.isArray(current)
|
|
522
|
+
? deepClone(current)
|
|
523
|
+
: {};
|
|
524
|
+
for (const field of conflictingMcpTransportFields(compatibleFields, desired)) {
|
|
525
|
+
delete compatibleFields[field];
|
|
526
|
+
}
|
|
527
|
+
config.mcpServers[key] = {
|
|
528
|
+
...compatibleFields,
|
|
529
|
+
...deepClone(desired),
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
const status = hadManagedServer ? 'updated' : fileExisted ? 'merged' : 'created';
|
|
535
|
+
if (!dryRun) {
|
|
536
|
+
writeJson(filePath, config, { dryRun: false });
|
|
537
|
+
state.version = 2;
|
|
538
|
+
const configLink = linkConfig(filePath, statePath);
|
|
539
|
+
if (configLink) {
|
|
540
|
+
state.configLink = configLink;
|
|
541
|
+
writeJson(statePath, state, { dryRun: false });
|
|
542
|
+
} else {
|
|
543
|
+
if (fileExisted) fs.writeFileSync(filePath, originalContents);
|
|
544
|
+
else fs.unlinkSync(filePath);
|
|
545
|
+
if (!existingState || !mcpStateMatchesConfig(existingState, filePath, statePath)) {
|
|
546
|
+
removeMcpOwnershipState(statePath, filePath);
|
|
547
|
+
}
|
|
548
|
+
return { status: 'ownership-unavailable', dest: filePath };
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
return { status, dest: filePath, state: statePath };
|
|
369
552
|
}
|
|
370
553
|
|
|
371
|
-
//
|
|
372
|
-
//
|
|
373
|
-
// top-level keys); otherwise prunes just the gx entry and preserves the rest.
|
|
554
|
+
// Restore the MCP values captured by installMcpServer. A server without a
|
|
555
|
+
// matching ownership record is user-owned and must never be removed.
|
|
374
556
|
function uninstallMcpServer(repoRoot, { dryRun }) {
|
|
375
557
|
const filePath = path.join(repoRoot, MCP_REL);
|
|
558
|
+
const statePath = resolveMcpStatePath(repoRoot);
|
|
376
559
|
const config = readJsonIfExists(filePath);
|
|
377
|
-
|
|
560
|
+
const state = readJsonIfExists(statePath);
|
|
561
|
+
if (!state || !state.servers) {
|
|
562
|
+
const legacyGx = config?.mcpServers?.[MCP_SERVER_KEY];
|
|
563
|
+
if (!mcpSpecsMatch(legacyGx, MCP_SERVER_SPECS[MCP_SERVER_KEY])) {
|
|
564
|
+
if (!dryRun) removeMcpOwnershipState(statePath, filePath);
|
|
565
|
+
return { status: 'absent', dest: filePath };
|
|
566
|
+
}
|
|
567
|
+
delete config.mcpServers[MCP_SERVER_KEY];
|
|
568
|
+
const removeConfig = Object.keys(config.mcpServers).length === 0 && Object.keys(config).length === 1;
|
|
569
|
+
if (!dryRun) {
|
|
570
|
+
if (removeConfig) fs.unlinkSync(filePath);
|
|
571
|
+
else writeJson(filePath, config, { dryRun: false });
|
|
572
|
+
removeMcpOwnershipState(statePath, filePath);
|
|
573
|
+
}
|
|
574
|
+
return { status: removeConfig ? 'removed' : 'pruned', dest: filePath };
|
|
575
|
+
}
|
|
576
|
+
if (!config || !config.mcpServers) {
|
|
577
|
+
if (!dryRun) removeMcpOwnershipState(statePath, filePath);
|
|
378
578
|
return { status: 'absent', dest: filePath };
|
|
379
579
|
}
|
|
380
|
-
|
|
381
|
-
|
|
580
|
+
if (!mcpStateMatchesConfig(state, filePath, statePath)) {
|
|
581
|
+
if (!dryRun) removeMcpOwnershipState(statePath, filePath);
|
|
582
|
+
return { status: 'preserved', dest: filePath };
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
let changed = false;
|
|
586
|
+
for (const [key, ownership] of Object.entries(state.servers)) {
|
|
587
|
+
const desired = MCP_SERVER_SPECS[key];
|
|
588
|
+
if (!desired) continue;
|
|
589
|
+
const previous = ownership.hadPrevious
|
|
590
|
+
&& ownership.previous
|
|
591
|
+
&& typeof ownership.previous === 'object'
|
|
592
|
+
&& !Array.isArray(ownership.previous)
|
|
593
|
+
? deepClone(ownership.previous)
|
|
594
|
+
: {};
|
|
595
|
+
for (const field of conflictingMcpTransportFields(previous, desired)) {
|
|
596
|
+
delete previous[field];
|
|
597
|
+
}
|
|
598
|
+
const installed = { ...previous, ...desired };
|
|
599
|
+
if (!mcpSpecsMatch(config.mcpServers[key], installed)) continue;
|
|
600
|
+
if (ownership.hadPrevious) {
|
|
601
|
+
config.mcpServers[key] = deepClone(ownership.previous);
|
|
602
|
+
} else {
|
|
603
|
+
delete config.mcpServers[key];
|
|
604
|
+
}
|
|
605
|
+
changed = true;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
const removeConfig = changed
|
|
609
|
+
&& Object.keys(config.mcpServers).length === 0
|
|
610
|
+
&& Object.keys(config).length === 1;
|
|
611
|
+
if (!dryRun) {
|
|
612
|
+
if (removeConfig) fs.unlinkSync(filePath);
|
|
613
|
+
else if (changed) writeJson(filePath, config, { dryRun: false });
|
|
614
|
+
removeMcpOwnershipState(statePath, filePath);
|
|
615
|
+
}
|
|
616
|
+
return { status: removeConfig ? 'removed' : changed ? 'pruned' : 'preserved', dest: filePath };
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
function abideHooksStatus(repoRoot) {
|
|
620
|
+
const settings = readJsonIfExists(path.join(repoRoot, SETTINGS_REL));
|
|
621
|
+
const entries = abide.abideHookEntries(settings);
|
|
622
|
+
const present = Object.keys(entries);
|
|
623
|
+
const shimEvents = present.filter((e) => entries[e].some((entry) => entry.shim));
|
|
624
|
+
const missingEvents = abide.ABIDE_HOOK_EVENTS.filter((e) => !shimEvents.includes(e));
|
|
625
|
+
// Entries abide's own installer wrote: an absolute path that only works on
|
|
626
|
+
// the machine that ran it. Install migrates them to the shim.
|
|
627
|
+
const legacyScripts = [...new Set(present
|
|
628
|
+
.flatMap((e) => entries[e].filter((entry) => !entry.shim).map((entry) => entry.script))
|
|
629
|
+
.filter(Boolean))];
|
|
630
|
+
const staleScripts = legacyScripts.filter((script) => !fs.existsSync(script));
|
|
631
|
+
const shimPath = path.join(repoRoot, abide.ABIDE_SHIM_REL);
|
|
632
|
+
return {
|
|
633
|
+
present,
|
|
634
|
+
shimEvents,
|
|
635
|
+
missingEvents,
|
|
636
|
+
legacyScripts,
|
|
637
|
+
staleScripts,
|
|
638
|
+
shimFileExists: fs.existsSync(shimPath),
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
function ensureAbideGitignore(repoRoot, { dryRun }) {
|
|
643
|
+
const dir = path.join(repoRoot, abide.ABIDE_DIR_REL);
|
|
644
|
+
const target = path.join(dir, '.gitignore');
|
|
645
|
+
const wanted = ['events.jsonl', 'compile-skill.md'];
|
|
646
|
+
let existing = [];
|
|
647
|
+
try {
|
|
648
|
+
existing = fs.readFileSync(target, 'utf8').split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
|
|
649
|
+
} catch (_error) {
|
|
650
|
+
existing = [];
|
|
651
|
+
}
|
|
652
|
+
const missing = wanted.filter((entry) => !existing.includes(entry));
|
|
653
|
+
if (missing.length === 0) return false;
|
|
382
654
|
if (!dryRun) {
|
|
383
|
-
|
|
384
|
-
|
|
655
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
656
|
+
fs.writeFileSync(target, `${[...existing, ...missing].join('\n')}\n`);
|
|
385
657
|
}
|
|
386
|
-
return
|
|
658
|
+
return true;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// Make sure the shim can find abide here; warm the npx cache when it cannot.
|
|
662
|
+
function ensureAbidePackage(repoRoot) {
|
|
663
|
+
const found = abide.resolveShimPackageDir(repoRoot);
|
|
664
|
+
if (found) return { packageDir: found };
|
|
665
|
+
const fetched = abide.runAbide(repoRoot, ['help']);
|
|
666
|
+
if (fetched.status === 'unavailable') {
|
|
667
|
+
return { packageDir: null, note: `neither 'abide' nor 'npx' on PATH; hooks stay silent until 'npm i -g ${abide.ABIDE_PACKAGE}'` };
|
|
668
|
+
}
|
|
669
|
+
if (fetched.status !== 'ok') {
|
|
670
|
+
return { packageDir: null, note: `could not fetch ${abide.ABIDE_PACKAGE}: ${abide.summarizeAbideOutput(fetched)}` };
|
|
671
|
+
}
|
|
672
|
+
const after = abide.resolveShimPackageDir(repoRoot);
|
|
673
|
+
return after
|
|
674
|
+
? { packageDir: after, via: fetched.via }
|
|
675
|
+
: { packageDir: null, note: `${abide.ABIDE_PACKAGE} was fetched but the shim cannot see it; set GUARDEX_ABIDE_PACKAGE_DIR` };
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
function abideSelfTest(repoRoot) {
|
|
679
|
+
const result = cp.spawnSync(process.execPath, [path.join(repoRoot, abide.ABIDE_SHIM_REL), 'session-start'], {
|
|
680
|
+
cwd: repoRoot,
|
|
681
|
+
input: '{}',
|
|
682
|
+
encoding: 'utf8',
|
|
683
|
+
timeout: 15_000,
|
|
684
|
+
});
|
|
685
|
+
return !result.error && result.status === 0;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
function installAbide(repoRoot, { dryRun, noAbide }) {
|
|
689
|
+
const settingsPath = path.join(repoRoot, SETTINGS_REL);
|
|
690
|
+
if (noAbide) return { status: 'skipped', dest: settingsPath };
|
|
691
|
+
|
|
692
|
+
const before = abideHooksStatus(repoRoot);
|
|
693
|
+
const migrate = before.legacyScripts.length > 0;
|
|
694
|
+
const wire = before.missingEvents.length > 0 || migrate;
|
|
695
|
+
const gitignoreChange = ensureAbideGitignore(repoRoot, { dryRun: true });
|
|
696
|
+
if (!wire && !gitignoreChange) {
|
|
697
|
+
// Already wired (a fresh clone of a wired repo, or a rerun): the only
|
|
698
|
+
// thing that can still be missing is the package on this machine.
|
|
699
|
+
const packageDir = abide.resolveShimPackageDir(repoRoot);
|
|
700
|
+
if (packageDir) return { status: 'unchanged', dest: settingsPath, packageDir };
|
|
701
|
+
if (dryRun) return { status: 'would-fetch', dest: settingsPath, packageDir: null };
|
|
702
|
+
const pkg = ensureAbidePackage(repoRoot);
|
|
703
|
+
return {
|
|
704
|
+
status: pkg.packageDir ? 'fetched' : 'unchanged',
|
|
705
|
+
dest: settingsPath,
|
|
706
|
+
packageDir: pkg.packageDir,
|
|
707
|
+
...(pkg.via ? { via: pkg.via } : {}),
|
|
708
|
+
...(pkg.note ? { note: pkg.note } : {}),
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
if (dryRun) return { status: migrate ? 'would-migrate' : wire ? 'would-install' : 'would-update', dest: settingsPath };
|
|
712
|
+
|
|
713
|
+
if (wire) {
|
|
714
|
+
// Drop every abide entry (upstream absolute ones included), then merge the
|
|
715
|
+
// shim entries in, so the outcome never depends on what was there.
|
|
716
|
+
uninstallAbide(repoRoot, { dryRun: false, keepShim: true });
|
|
717
|
+
const settings = readJsonIfExists(settingsPath);
|
|
718
|
+
writeJson(settingsPath, mergeSettings(settings, abide.abideSettingsTemplate()), { dryRun: false });
|
|
719
|
+
}
|
|
720
|
+
ensureAbideGitignore(repoRoot, { dryRun: false });
|
|
721
|
+
|
|
722
|
+
const pkg = ensureAbidePackage(repoRoot);
|
|
723
|
+
if (!abideSelfTest(repoRoot)) {
|
|
724
|
+
return { status: 'failed', dest: settingsPath, note: `the shim at ${abide.ABIDE_SHIM_REL} did not run cleanly` };
|
|
725
|
+
}
|
|
726
|
+
const after = abideHooksStatus(repoRoot);
|
|
727
|
+
if (after.missingEvents.length > 0 || after.legacyScripts.length > 0) {
|
|
728
|
+
return { status: 'failed', dest: settingsPath, note: `${SETTINGS_REL} still lacks shim hooks for: ${after.missingEvents.join(', ') || 'none'}; legacy entries left: ${after.legacyScripts.length}` };
|
|
729
|
+
}
|
|
730
|
+
return {
|
|
731
|
+
status: migrate ? 'migrated' : wire ? 'installed' : 'updated',
|
|
732
|
+
dest: settingsPath,
|
|
733
|
+
packageDir: pkg.packageDir,
|
|
734
|
+
...(pkg.via ? { via: pkg.via } : {}),
|
|
735
|
+
...(pkg.note ? { note: pkg.note } : {}),
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
// `abide compile` runs a headless Claude Code turn that reads the instruction
|
|
740
|
+
// files and writes .abide/rubric.json, so the first interactive session does
|
|
741
|
+
// not spend its first turn compiling.
|
|
742
|
+
function compileAbideRubric(repoRoot, { dryRun }) {
|
|
743
|
+
const rubric = abide.rubricStatus(repoRoot);
|
|
744
|
+
if (rubric.status === 'fresh') return { status: 'fresh', rules: rubric.rules };
|
|
745
|
+
if (!abide.abideKeySource(repoRoot)) return { status: 'no-key' };
|
|
746
|
+
if (dryRun) return { status: 'would-compile', reason: rubric.status };
|
|
747
|
+
const result = abide.runAbide(repoRoot, ['compile'], { stdio: 'inherit', timeoutMs: ABIDE_COMPILE_TIMEOUT_MS });
|
|
748
|
+
if (result.status !== 'ok') {
|
|
749
|
+
return { status: 'failed', note: result.status === 'unavailable' ? 'abide is not installed' : `${result.label} exited ${result.exitCode}` };
|
|
750
|
+
}
|
|
751
|
+
const after = abide.rubricStatus(repoRoot);
|
|
752
|
+
return after.status === 'fresh'
|
|
753
|
+
? { status: 'compiled', rules: after.rules }
|
|
754
|
+
: { status: 'failed', note: `rubric is ${after.status} after compile` };
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
// `abide calibrate --json` scores every model rule against recent git history
|
|
758
|
+
// and marks the ones that never decide. Costs Jev calls, so it is opt-in.
|
|
759
|
+
function calibrateAbideRules(repoRoot) {
|
|
760
|
+
const result = abide.runAbide(repoRoot, ['calibrate', '--json'], { timeoutMs: ABIDE_CALIBRATE_TIMEOUT_MS });
|
|
761
|
+
if (result.status !== 'ok') {
|
|
762
|
+
return { status: 'failed', note: result.status === 'unavailable' ? 'abide is not installed' : `${result.label} failed: ${abide.summarizeAbideOutput(result)}` };
|
|
763
|
+
}
|
|
764
|
+
const jsonLine = result.stdout.split('\n').map((l) => l.trim()).filter((l) => l.startsWith('{')).pop();
|
|
765
|
+
try {
|
|
766
|
+
const parsed = JSON.parse(jsonLine || '');
|
|
767
|
+
return {
|
|
768
|
+
status: 'ok',
|
|
769
|
+
hunks: parsed.hunks || 0,
|
|
770
|
+
weak: Array.isArray(parsed.weak) ? parsed.weak : [],
|
|
771
|
+
noisy: Array.isArray(parsed.noisy) ? parsed.noisy : [],
|
|
772
|
+
};
|
|
773
|
+
} catch (_error) {
|
|
774
|
+
return { status: 'failed', note: `${result.label} produced no JSON` };
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
// Drop only the entries abide wrote (upstream and shim); the rubric under
|
|
779
|
+
// .abide/ stays, exactly like `abide uninstall claude --project`.
|
|
780
|
+
function uninstallAbide(repoRoot, { dryRun, keepShim = false }) {
|
|
781
|
+
const settingsPath = path.join(repoRoot, SETTINGS_REL);
|
|
782
|
+
const settings = readJsonIfExists(settingsPath);
|
|
783
|
+
if (!settings || !settings.hooks) return { status: 'absent', dest: settingsPath };
|
|
784
|
+
let removed = 0;
|
|
785
|
+
for (const eventName of Object.keys(settings.hooks)) {
|
|
786
|
+
const groups = (settings.hooks[eventName] || []).map((group) => {
|
|
787
|
+
const kept = (group.hooks || []).filter((h) => !abide.isAbideHookCommand(h.command)
|
|
788
|
+
|| (keepShim && abide.isShimCommand(h.command)));
|
|
789
|
+
removed += (group.hooks || []).length - kept.length;
|
|
790
|
+
return { ...group, hooks: kept };
|
|
791
|
+
}).filter((group) => group.hooks.length > 0);
|
|
792
|
+
if (groups.length === 0) delete settings.hooks[eventName];
|
|
793
|
+
else settings.hooks[eventName] = groups;
|
|
794
|
+
}
|
|
795
|
+
if (removed === 0) return { status: 'absent', dest: settingsPath };
|
|
796
|
+
if (!dryRun) writeJson(settingsPath, settings, { dryRun: false });
|
|
797
|
+
return { status: 'pruned', dest: settingsPath, removed };
|
|
387
798
|
}
|
|
388
799
|
|
|
389
800
|
function runInstall(rawArgs) {
|
|
@@ -394,11 +805,15 @@ function runInstall(rawArgs) {
|
|
|
394
805
|
const settingsResult = installSettings(repoRoot, opts);
|
|
395
806
|
const hookResults = installHooks(repoRoot, opts);
|
|
396
807
|
const slashResults = installSlashCommands(repoRoot, opts);
|
|
397
|
-
const skillResult =
|
|
808
|
+
const skillResult = installAgentSkills(repoRoot, opts);
|
|
398
809
|
const mcpResult = opts.noMcp
|
|
399
810
|
? { status: 'skipped', dest: path.join(repoRoot, MCP_REL) }
|
|
400
811
|
: installMcpServer(repoRoot, opts);
|
|
401
812
|
const symlinkResult = ensureSpeckitMarkers(repoRoot, opts);
|
|
813
|
+
// After settings + symlink: abide merges into the settings file we just
|
|
814
|
+
// wrote and needs AGENTS.md / CLAUDE.md on disk to find any rules.
|
|
815
|
+
const abideResult = installAbide(repoRoot, opts);
|
|
816
|
+
const compileResult = opts.compile && !opts.noAbide ? compileAbideRubric(repoRoot, opts) : null;
|
|
402
817
|
|
|
403
818
|
// Summary
|
|
404
819
|
const summarize = (label, items, key) => {
|
|
@@ -413,12 +828,23 @@ function runInstall(rawArgs) {
|
|
|
413
828
|
summarize('hooks', hookResults, 'hook');
|
|
414
829
|
summarize('slash commands', slashResults, 'command');
|
|
415
830
|
if (skillResult.status === 'ok') {
|
|
416
|
-
summarize('
|
|
417
|
-
} else if (skillResult.status === 'source-missing') {
|
|
418
|
-
logWarn('gitguardex skill source missing in package; skipped.');
|
|
831
|
+
summarize('agent skills', skillResult.files, 'skill');
|
|
419
832
|
}
|
|
420
833
|
logInfo(`mcp server (${MCP_REL}): ${mcpResult.status}`);
|
|
421
834
|
logInfo(`CLAUDE.md symlink: ${symlinkResult.status}${symlinkResult.note ? ` (${symlinkResult.note})` : ''}`);
|
|
835
|
+
const abideLine = `abide rule hooks: ${abideResult.status}`
|
|
836
|
+
+ `${abideResult.packageDir ? ` (${abide.ABIDE_PACKAGE} at ${abideResult.packageDir})` : ''}`
|
|
837
|
+
+ `${abideResult.note ? ` (${abideResult.note})` : ''}`;
|
|
838
|
+
if (abideResult.status === 'failed' || abideResult.note) logWarn(abideLine);
|
|
839
|
+
else logInfo(abideLine);
|
|
840
|
+
if (compileResult) {
|
|
841
|
+
const compileLine = `abide rubric: ${compileResult.status}`
|
|
842
|
+
+ `${compileResult.rules !== undefined ? ` (${compileResult.rules} rules)` : ''}`
|
|
843
|
+
+ `${compileResult.note ? ` (${compileResult.note})` : ''}`
|
|
844
|
+
+ `${compileResult.status === 'no-key' ? ` (run 'abide login' first)` : ''}`;
|
|
845
|
+
if (compileResult.status === 'failed' || compileResult.status === 'no-key') logWarn(compileLine);
|
|
846
|
+
else logInfo(compileLine);
|
|
847
|
+
}
|
|
422
848
|
|
|
423
849
|
if (opts.json) {
|
|
424
850
|
process.stdout.write(JSON.stringify({
|
|
@@ -429,13 +855,24 @@ function runInstall(rawArgs) {
|
|
|
429
855
|
skill: skillResult,
|
|
430
856
|
mcp: mcpResult,
|
|
431
857
|
symlink: symlinkResult,
|
|
858
|
+
abide: abideResult,
|
|
859
|
+
...(compileResult ? { abideCompile: compileResult } : {}),
|
|
432
860
|
dryRun: opts.dryRun,
|
|
433
861
|
}, null, 2) + '\n');
|
|
434
862
|
return;
|
|
435
863
|
}
|
|
436
864
|
|
|
437
865
|
if (!opts.dryRun) {
|
|
438
|
-
|
|
866
|
+
if (mcpResult && mcpResult.status === 'ownership-unavailable') {
|
|
867
|
+
logWarn(
|
|
868
|
+
`MCP server registration skipped — ${MCP_REL} already exists and `
|
|
869
|
+
+ 'ownership could not be claimed (another tool owns it). '
|
|
870
|
+
+ "The rest of the wiring is in place, but MCP tools won't be available until "
|
|
871
|
+
+ `the file is free. Remove or relocate ${MCP_REL} and re-run to register.`,
|
|
872
|
+
);
|
|
873
|
+
} else {
|
|
874
|
+
logOk('Claude Code wiring is in place.');
|
|
875
|
+
}
|
|
439
876
|
logInfo(`Next: run '${SHORT_TOOL_NAME} status' to verify and '${SHORT_TOOL_NAME} pivot "<task>" "claude-<name>"' to start work.`);
|
|
440
877
|
}
|
|
441
878
|
}
|
|
@@ -502,15 +939,104 @@ function runCheck(rawArgs) {
|
|
|
502
939
|
|
|
503
940
|
// MCP registration check
|
|
504
941
|
const mcpConfig = readJsonIfExists(path.join(repoRoot, MCP_REL));
|
|
505
|
-
const
|
|
506
|
-
if (
|
|
942
|
+
const missingMcpServers = missingManagedMcpServers(mcpConfig);
|
|
943
|
+
if (missingMcpServers.length > 0) {
|
|
507
944
|
issues.push({
|
|
508
945
|
severity: 'warning',
|
|
509
946
|
kind: 'mcp-missing',
|
|
510
|
-
message: `${MCP_REL} does not register
|
|
947
|
+
message: `${MCP_REL} does not register managed MCP server(s): ${missingMcpServers.join(', ')} (run '${SHORT_TOOL_NAME} claude install', or install --no-mcp to skip).`,
|
|
511
948
|
});
|
|
512
949
|
}
|
|
513
950
|
|
|
951
|
+
// Abide check: hooks present, hook script still on this machine, key on hand.
|
|
952
|
+
if (!opts.noAbide) {
|
|
953
|
+
const hooks = abideHooksStatus(repoRoot);
|
|
954
|
+
const install = `run '${SHORT_TOOL_NAME} claude install'`;
|
|
955
|
+
if (hooks.present.length === 0) {
|
|
956
|
+
issues.push({
|
|
957
|
+
severity: 'warning',
|
|
958
|
+
kind: 'abide-missing',
|
|
959
|
+
message: `${SETTINGS_REL} has no abide rule hooks (${install}, or check --no-abide to skip).`,
|
|
960
|
+
});
|
|
961
|
+
} else if (hooks.shimEvents.length === 0 && hooks.legacyScripts.length > 0) {
|
|
962
|
+
issues.push({
|
|
963
|
+
severity: 'warning',
|
|
964
|
+
kind: 'abide-hook-legacy',
|
|
965
|
+
message: `abide hooks point at an absolute path from abide's own installer (${hooks.legacyScripts[0]}); ${install} to migrate them to the portable shim.`,
|
|
966
|
+
});
|
|
967
|
+
} else if (hooks.missingEvents.length > 0) {
|
|
968
|
+
issues.push({
|
|
969
|
+
severity: 'warning',
|
|
970
|
+
kind: 'abide-hook-missing',
|
|
971
|
+
message: `abide hook missing for: ${hooks.missingEvents.join(', ')} (${install}).`,
|
|
972
|
+
});
|
|
973
|
+
}
|
|
974
|
+
for (const script of hooks.staleScripts) {
|
|
975
|
+
issues.push({
|
|
976
|
+
severity: 'error',
|
|
977
|
+
kind: 'abide-hook-stale',
|
|
978
|
+
message: `abide hook points at ${script}, which does not exist here (${install} to migrate to the shim).`,
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
if (hooks.shimEvents.length > 0 && !hooks.shimFileExists) {
|
|
982
|
+
issues.push({
|
|
983
|
+
severity: 'error',
|
|
984
|
+
kind: 'abide-shim-missing',
|
|
985
|
+
message: `${abide.ABIDE_SHIM_REL} is referenced by hooks but missing (${install}).`,
|
|
986
|
+
});
|
|
987
|
+
}
|
|
988
|
+
const wired = hooks.shimEvents.length > 0 || hooks.legacyScripts.length > 0;
|
|
989
|
+
if (hooks.shimEvents.length > 0 && hooks.shimFileExists && !abide.resolveShimPackageDir(repoRoot)) {
|
|
990
|
+
issues.push({
|
|
991
|
+
severity: 'warning',
|
|
992
|
+
kind: 'abide-unresolved',
|
|
993
|
+
message: `${abide.ABIDE_PACKAGE} is not installed on this machine, so the hooks run silent; 'npm i -g ${abide.ABIDE_PACKAGE}' or ${install} to fetch it.`,
|
|
994
|
+
});
|
|
995
|
+
}
|
|
996
|
+
const keySource = abide.abideKeySource(repoRoot);
|
|
997
|
+
if (wired && !keySource) {
|
|
998
|
+
issues.push({
|
|
999
|
+
severity: 'warning',
|
|
1000
|
+
kind: 'abide-no-key',
|
|
1001
|
+
message: `no ${abide.ABIDE_KEY_NAMES.join(' / ')} in the environment, .env.local, .env, or ~/.abide/.env; abide hooks stay silent until 'abide login'.`,
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
if (wired && keySource) {
|
|
1005
|
+
const rubric = abide.rubricStatus(repoRoot);
|
|
1006
|
+
if (rubric.status === 'missing') {
|
|
1007
|
+
issues.push({
|
|
1008
|
+
severity: 'warning',
|
|
1009
|
+
kind: 'abide-rubric-missing',
|
|
1010
|
+
message: `${abide.ABIDE_RUBRIC_REL} not compiled yet; the next Claude session compiles it, or run '${SHORT_TOOL_NAME} claude install --compile' now.`,
|
|
1011
|
+
});
|
|
1012
|
+
} else if (rubric.status === 'invalid') {
|
|
1013
|
+
issues.push({ severity: 'error', kind: 'abide-rubric-invalid', message: `${abide.ABIDE_RUBRIC_REL} is not valid JSON.` });
|
|
1014
|
+
} else if (rubric.status === 'stale') {
|
|
1015
|
+
const what = [...rubric.changed.map((f) => `${f} changed`), ...rubric.removed.map((f) => `${f} removed`)].join(', ');
|
|
1016
|
+
issues.push({
|
|
1017
|
+
severity: 'warning',
|
|
1018
|
+
kind: 'abide-rubric-stale',
|
|
1019
|
+
message: `${abide.ABIDE_RUBRIC_REL} predates its sources (${what}); the next session recompiles it, or run '${SHORT_TOOL_NAME} claude install --compile'.`,
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
if (opts.calibrate && rubric.status === 'fresh') {
|
|
1023
|
+
const calibrated = calibrateAbideRules(repoRoot);
|
|
1024
|
+
if (calibrated.status === 'failed') {
|
|
1025
|
+
issues.push({ severity: 'warning', kind: 'abide-calibrate-failed', message: calibrated.note });
|
|
1026
|
+
} else {
|
|
1027
|
+
for (const [kind, ids] of [['weak', calibrated.weak], ['noisy', calibrated.noisy]]) {
|
|
1028
|
+
if (ids.length === 0) continue;
|
|
1029
|
+
issues.push({
|
|
1030
|
+
severity: 'warning',
|
|
1031
|
+
kind: `abide-rules-${kind}`,
|
|
1032
|
+
message: `${ids.length} rule(s) ${kind} against ${calibrated.hunks} hunks of git history: ${ids.join(', ')} ('abide tune' rewrites them).`,
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
|
|
514
1040
|
// Symlink check
|
|
515
1041
|
const symlinkResult = ensureSpeckitMarkers(repoRoot, { dryRun: true });
|
|
516
1042
|
if (symlinkResult.status === 'would-create-symlink'
|
|
@@ -594,10 +1120,15 @@ function runUninstall(rawArgs) {
|
|
|
594
1120
|
if (!opts.dryRun) writeJson(settingsPath, settings, { dryRun: false });
|
|
595
1121
|
removed.push(`${SETTINGS_REL} (managed entries pruned)`);
|
|
596
1122
|
}
|
|
597
|
-
// Remove
|
|
1123
|
+
// Remove abide's hook entries (its rubric under .abide/ stays, as abide itself leaves it)
|
|
1124
|
+
const abideRemoval = uninstallAbide(repoRoot, opts);
|
|
1125
|
+
if (abideRemoval.status === 'pruned') {
|
|
1126
|
+
removed.push(`${SETTINGS_REL} (${abideRemoval.removed} abide hook entries pruned)`);
|
|
1127
|
+
}
|
|
1128
|
+
// Remove managed MCP servers from .mcp.json (drop the file if it only held ours)
|
|
598
1129
|
const mcpRemoval = uninstallMcpServer(repoRoot, opts);
|
|
599
|
-
if (mcpRemoval.status
|
|
600
|
-
removed.push(`${MCP_REL} (${mcpRemoval.status === 'removed' ? 'removed' :
|
|
1130
|
+
if (mcpRemoval.status === 'removed' || mcpRemoval.status === 'pruned') {
|
|
1131
|
+
removed.push(`${MCP_REL} (${mcpRemoval.status === 'removed' ? 'removed' : 'managed servers pruned'})`);
|
|
601
1132
|
}
|
|
602
1133
|
|
|
603
1134
|
logOk(`Removed ${removed.length} item(s)${opts.dryRun ? ' (dry-run)' : ''}.`);
|
|
@@ -613,16 +1144,22 @@ function parseInstallArgs(rawArgs) {
|
|
|
613
1144
|
yes: false,
|
|
614
1145
|
fix: false,
|
|
615
1146
|
noMcp: false,
|
|
1147
|
+
noAbide: false,
|
|
1148
|
+
compile: false,
|
|
1149
|
+
calibrate: false,
|
|
616
1150
|
};
|
|
617
1151
|
for (let index = 0; index < rawArgs.length; index += 1) {
|
|
618
1152
|
const arg = rawArgs[index];
|
|
619
|
-
if (arg === '--target') { opts.target = rawArgs
|
|
1153
|
+
if (arg === '--target') { opts.target = requireValue(rawArgs, index, '--target'); index += 1; continue; }
|
|
620
1154
|
if (arg === '--force') { opts.force = true; continue; }
|
|
621
1155
|
if (arg === '--dry-run') { opts.dryRun = true; continue; }
|
|
622
1156
|
if (arg === '--json') { opts.json = true; continue; }
|
|
623
1157
|
if (arg === '--yes' || arg === '-y') { opts.yes = true; continue; }
|
|
624
1158
|
if (arg === '--fix') { opts.fix = true; continue; }
|
|
625
1159
|
if (arg === '--no-mcp') { opts.noMcp = true; continue; }
|
|
1160
|
+
if (arg === '--no-abide') { opts.noAbide = true; continue; }
|
|
1161
|
+
if (arg === '--compile') { opts.compile = true; continue; }
|
|
1162
|
+
if (arg === '--calibrate') { opts.calibrate = true; continue; }
|
|
626
1163
|
}
|
|
627
1164
|
return opts;
|
|
628
1165
|
}
|
|
@@ -631,7 +1168,8 @@ function printUsage() {
|
|
|
631
1168
|
console.log(`Usage: ${SHORT_TOOL_NAME} claude <subcommand> [flags]
|
|
632
1169
|
|
|
633
1170
|
Subcommands:
|
|
634
|
-
install install/update .claude/settings.json + hooks + slash commands + .mcp.json
|
|
1171
|
+
install install/update .claude/settings.json + hooks + slash commands + .mcp.json
|
|
1172
|
+
+ abide rule hooks (AGENTS.md / CLAUDE.md enforced on every edit).
|
|
635
1173
|
check diagnose Claude Code wiring (read-only by default).
|
|
636
1174
|
doctor alias: 'check --fix'.
|
|
637
1175
|
uninstall remove gitguardex-managed Claude Code wiring (--yes required).
|
|
@@ -639,7 +1177,10 @@ Subcommands:
|
|
|
639
1177
|
Flags:
|
|
640
1178
|
--target <path> Operate in a different repo directory.
|
|
641
1179
|
--force Overwrite existing managed entries instead of merging.
|
|
642
|
-
--no-mcp Skip registering
|
|
1180
|
+
--no-mcp Skip registering gx and CodeGraph MCP servers in .mcp.json.
|
|
1181
|
+
--no-abide Skip the abide rule hooks (install) / their diagnostics (check).
|
|
1182
|
+
--compile For 'install': compile .abide/rubric.json now (headless Claude turn; needs a key).
|
|
1183
|
+
--calibrate For 'check': score the rubric's rules against git history (spends Jev calls).
|
|
643
1184
|
--dry-run Report what would change without writing.
|
|
644
1185
|
--json Emit JSON output.
|
|
645
1186
|
--yes / -y Required for uninstall.
|
|
@@ -677,6 +1218,7 @@ module.exports = {
|
|
|
677
1218
|
ensureSpeckitMarkers,
|
|
678
1219
|
installHooks,
|
|
679
1220
|
installSlashCommands,
|
|
1221
|
+
installAgentSkills,
|
|
680
1222
|
installMcpServer,
|
|
681
1223
|
uninstallMcpServer,
|
|
682
1224
|
mcpServerSpec,
|
|
@@ -684,6 +1226,18 @@ module.exports = {
|
|
|
684
1226
|
MANAGED_SLASH_COMMANDS,
|
|
685
1227
|
MCP_REL,
|
|
686
1228
|
MCP_SERVER_KEY,
|
|
1229
|
+
MCP_SERVER_SPECS,
|
|
1230
|
+
missingManagedMcpServers,
|
|
1231
|
+
resolveMcpConfigLinkPath,
|
|
1232
|
+
resolveMcpStatePath,
|
|
1233
|
+
MANAGED_AGENT_SKILLS,
|
|
687
1234
|
TEMPLATE_DEFAULT_SETTINGS,
|
|
688
1235
|
EXPECTED_HOOK_MATCHERS,
|
|
1236
|
+
abideHooksStatus,
|
|
1237
|
+
installAbide,
|
|
1238
|
+
uninstallAbide,
|
|
1239
|
+
compileAbideRubric,
|
|
1240
|
+
calibrateAbideRules,
|
|
1241
|
+
ensureAbideGitignore,
|
|
1242
|
+
parseInstallArgs,
|
|
689
1243
|
};
|