opencastle 0.38.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -1
- package/bin/cli.mjs +20 -3
- package/dist/cli/adapters/antigravity.d.ts +1 -1
- package/dist/cli/adapters/antigravity.d.ts.map +1 -1
- package/dist/cli/adapters/claude-code.d.ts +1 -1
- package/dist/cli/adapters/claude-code.d.ts.map +1 -1
- package/dist/cli/adapters/codex.d.ts +1 -1
- package/dist/cli/adapters/codex.d.ts.map +1 -1
- package/dist/cli/adapters/cursor.d.ts +1 -1
- package/dist/cli/adapters/cursor.d.ts.map +1 -1
- package/dist/cli/adapters/opencode.d.ts +1 -1
- package/dist/cli/adapters/opencode.d.ts.map +1 -1
- package/dist/cli/adapters/rules-dir-base.d.ts +3 -2
- package/dist/cli/adapters/rules-dir-base.d.ts.map +1 -1
- package/dist/cli/adapters/rules-dir-base.js +13 -25
- package/dist/cli/adapters/rules-dir-base.js.map +1 -1
- package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
- package/dist/cli/adapters/single-file-base.js +30 -43
- package/dist/cli/adapters/single-file-base.js.map +1 -1
- package/dist/cli/adapters/vscode.d.ts +3 -2
- package/dist/cli/adapters/vscode.d.ts.map +1 -1
- package/dist/cli/adapters/vscode.js +19 -71
- package/dist/cli/adapters/vscode.js.map +1 -1
- package/dist/cli/adapters/windsurf.d.ts +1 -1
- package/dist/cli/adapters/windsurf.d.ts.map +1 -1
- package/dist/cli/baseline.d.ts +3 -0
- package/dist/cli/baseline.d.ts.map +1 -0
- package/dist/cli/baseline.js +280 -0
- package/dist/cli/baseline.js.map +1 -0
- package/dist/cli/ci.d.ts +18 -0
- package/dist/cli/ci.d.ts.map +1 -0
- package/dist/cli/ci.js +279 -0
- package/dist/cli/ci.js.map +1 -0
- package/dist/cli/dispatcher.test.js +2 -2
- package/dist/cli/dispatcher.test.js.map +1 -1
- package/dist/cli/docs-accuracy.test.js +5 -0
- package/dist/cli/docs-accuracy.test.js.map +1 -1
- package/dist/cli/doctor.d.ts +3 -3
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +66 -9
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/explain.d.ts +3 -0
- package/dist/cli/explain.d.ts.map +1 -0
- package/dist/cli/explain.js +210 -0
- package/dist/cli/explain.js.map +1 -0
- package/dist/cli/fleet.d.ts +30 -0
- package/dist/cli/fleet.d.ts.map +1 -0
- package/dist/cli/fleet.js +149 -0
- package/dist/cli/fleet.js.map +1 -0
- package/dist/cli/github-report.d.ts +49 -0
- package/dist/cli/github-report.d.ts.map +1 -0
- package/dist/cli/github-report.js +161 -0
- package/dist/cli/github-report.js.map +1 -0
- package/dist/cli/github-report.test.d.ts +2 -0
- package/dist/cli/github-report.test.d.ts.map +1 -0
- package/dist/cli/github-report.test.js +146 -0
- package/dist/cli/github-report.test.js.map +1 -0
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +135 -94
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/init.test.js +26 -25
- package/dist/cli/init.test.js.map +1 -1
- package/dist/cli/layers.d.ts +152 -0
- package/dist/cli/layers.d.ts.map +1 -0
- package/dist/cli/layers.js +932 -0
- package/dist/cli/layers.js.map +1 -0
- package/dist/cli/layers.test.d.ts +2 -0
- package/dist/cli/layers.test.d.ts.map +1 -0
- package/dist/cli/layers.test.js +483 -0
- package/dist/cli/layers.test.js.map +1 -0
- package/dist/cli/lock.d.ts +130 -0
- package/dist/cli/lock.d.ts.map +1 -0
- package/dist/cli/lock.js +320 -0
- package/dist/cli/lock.js.map +1 -0
- package/dist/cli/mcp-audit.d.ts +164 -0
- package/dist/cli/mcp-audit.d.ts.map +1 -0
- package/dist/cli/mcp-audit.js +504 -0
- package/dist/cli/mcp-audit.js.map +1 -0
- package/dist/cli/mcp-audit.test.d.ts +2 -0
- package/dist/cli/mcp-audit.test.d.ts.map +1 -0
- package/dist/cli/mcp-audit.test.js +215 -0
- package/dist/cli/mcp-audit.test.js.map +1 -0
- package/dist/cli/mcp-upgrade.test.d.ts +2 -0
- package/dist/cli/mcp-upgrade.test.d.ts.map +1 -0
- package/dist/cli/mcp-upgrade.test.js +118 -0
- package/dist/cli/mcp-upgrade.test.js.map +1 -0
- package/dist/cli/mcp.d.ts +74 -5
- package/dist/cli/mcp.d.ts.map +1 -1
- package/dist/cli/mcp.js +340 -32
- package/dist/cli/mcp.js.map +1 -1
- package/dist/cli/policy.d.ts +58 -0
- package/dist/cli/policy.d.ts.map +1 -0
- package/dist/cli/policy.js +194 -0
- package/dist/cli/policy.js.map +1 -0
- package/dist/cli/publish-workflow.test.js +55 -1
- package/dist/cli/publish-workflow.test.js.map +1 -1
- package/dist/cli/remove.d.ts.map +1 -1
- package/dist/cli/remove.js +3 -2
- package/dist/cli/remove.js.map +1 -1
- package/dist/cli/review.d.ts +25 -0
- package/dist/cli/review.d.ts.map +1 -0
- package/dist/cli/review.js +437 -0
- package/dist/cli/review.js.map +1 -0
- package/dist/cli/status.d.ts +2 -0
- package/dist/cli/status.d.ts.map +1 -1
- package/dist/cli/status.js +25 -4
- package/dist/cli/status.js.map +1 -1
- package/dist/cli/status.test.js +5 -3
- package/dist/cli/status.test.js.map +1 -1
- package/dist/cli/sync-check.d.ts +16 -1
- package/dist/cli/sync-check.d.ts.map +1 -1
- package/dist/cli/sync-check.js +219 -13
- package/dist/cli/sync-check.js.map +1 -1
- package/dist/cli/sync-check.test.js +14 -8
- package/dist/cli/sync-check.test.js.map +1 -1
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +2 -0
- package/dist/cli/sync.js.map +1 -1
- package/dist/cli/team-ci.test.d.ts +2 -0
- package/dist/cli/team-ci.test.d.ts.map +1 -0
- package/dist/cli/team-ci.test.js +169 -0
- package/dist/cli/team-ci.test.js.map +1 -0
- package/dist/cli/team-commands.test.d.ts +2 -0
- package/dist/cli/team-commands.test.d.ts.map +1 -0
- package/dist/cli/team-commands.test.js +233 -0
- package/dist/cli/team-commands.test.js.map +1 -0
- package/dist/cli/team-config.d.ts +88 -0
- package/dist/cli/team-config.d.ts.map +1 -0
- package/dist/cli/team-config.js +261 -0
- package/dist/cli/team-config.js.map +1 -0
- package/dist/cli/team-health.d.ts +49 -0
- package/dist/cli/team-health.d.ts.map +1 -0
- package/dist/cli/team-health.js +205 -0
- package/dist/cli/team-health.js.map +1 -0
- package/dist/cli/team-sources.test.d.ts +2 -0
- package/dist/cli/team-sources.test.d.ts.map +1 -0
- package/dist/cli/team-sources.test.js +542 -0
- package/dist/cli/team-sources.test.js.map +1 -0
- package/dist/cli/types.d.ts +16 -2
- package/dist/cli/types.d.ts.map +1 -1
- package/dist/cli/types.js.map +1 -1
- package/dist/cli/update.d.ts.map +1 -1
- package/dist/cli/update.js +204 -44
- package/dist/cli/update.js.map +1 -1
- package/dist/cli/version-range.d.ts +24 -0
- package/dist/cli/version-range.d.ts.map +1 -0
- package/dist/cli/version-range.js +157 -0
- package/dist/cli/version-range.js.map +1 -0
- package/dist/cli/website-plugins.test.d.ts +2 -0
- package/dist/cli/website-plugins.test.d.ts.map +1 -0
- package/dist/cli/website-plugins.test.js +34 -0
- package/dist/cli/website-plugins.test.js.map +1 -0
- package/dist/orchestrator/plugins/chrome-devtools/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/chrome-devtools/config.js +11 -1
- package/dist/orchestrator/plugins/chrome-devtools/config.js.map +1 -1
- package/dist/orchestrator/plugins/contentful/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/contentful/config.js +11 -1
- package/dist/orchestrator/plugins/contentful/config.js.map +1 -1
- package/dist/orchestrator/plugins/convex/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/convex/config.js +11 -1
- package/dist/orchestrator/plugins/convex/config.js.map +1 -1
- package/dist/orchestrator/plugins/coolify/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/coolify/config.js +14 -1
- package/dist/orchestrator/plugins/coolify/config.js.map +1 -1
- package/dist/orchestrator/plugins/figma/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/figma/config.js +24 -13
- package/dist/orchestrator/plugins/figma/config.js.map +1 -1
- package/dist/orchestrator/plugins/linear/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/linear/config.js +27 -17
- package/dist/orchestrator/plugins/linear/config.js.map +1 -1
- package/dist/orchestrator/plugins/netlify/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/netlify/config.js +23 -9
- package/dist/orchestrator/plugins/netlify/config.js.map +1 -1
- package/dist/orchestrator/plugins/nextjs/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/nextjs/config.js +11 -1
- package/dist/orchestrator/plugins/nextjs/config.js.map +1 -1
- package/dist/orchestrator/plugins/nx/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/nx/config.js +11 -1
- package/dist/orchestrator/plugins/nx/config.js.map +1 -1
- package/dist/orchestrator/plugins/pins.test.d.ts +2 -0
- package/dist/orchestrator/plugins/pins.test.d.ts.map +1 -0
- package/dist/orchestrator/plugins/pins.test.js +78 -0
- package/dist/orchestrator/plugins/pins.test.js.map +1 -0
- package/dist/orchestrator/plugins/playwright/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/playwright/config.js +11 -1
- package/dist/orchestrator/plugins/playwright/config.js.map +1 -1
- package/dist/orchestrator/plugins/prisma/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/prisma/config.js +17 -2
- package/dist/orchestrator/plugins/prisma/config.js.map +1 -1
- package/dist/orchestrator/plugins/resend/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/resend/config.js +17 -1
- package/dist/orchestrator/plugins/resend/config.js.map +1 -1
- package/dist/orchestrator/plugins/sentry/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/sentry/config.js +13 -1
- package/dist/orchestrator/plugins/sentry/config.js.map +1 -1
- package/dist/orchestrator/plugins/slack/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/slack/config.js +20 -1
- package/dist/orchestrator/plugins/slack/config.js.map +1 -1
- package/dist/orchestrator/plugins/strapi/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/strapi/config.js +11 -1
- package/dist/orchestrator/plugins/strapi/config.js.map +1 -1
- package/dist/orchestrator/plugins/trello/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/trello/config.js +21 -1
- package/dist/orchestrator/plugins/trello/config.js.map +1 -1
- package/dist/orchestrator/plugins/types.d.ts +22 -0
- package/dist/orchestrator/plugins/types.d.ts.map +1 -1
- package/package.json +3 -1
- package/src/cli/adapters/rules-dir-base.ts +23 -44
- package/src/cli/adapters/single-file-base.ts +43 -46
- package/src/cli/adapters/vscode.ts +28 -71
- package/src/cli/baseline.ts +289 -0
- package/src/cli/ci.ts +289 -0
- package/src/cli/dispatcher.test.ts +2 -2
- package/src/cli/docs-accuracy.test.ts +5 -0
- package/src/cli/doctor.ts +92 -6
- package/src/cli/explain.ts +210 -0
- package/src/cli/fleet.ts +176 -0
- package/src/cli/github-report.test.ts +158 -0
- package/src/cli/github-report.ts +179 -0
- package/src/cli/init.test.ts +27 -27
- package/src/cli/init.ts +135 -93
- package/src/cli/layers.test.ts +525 -0
- package/src/cli/layers.ts +1089 -0
- package/src/cli/lock.ts +395 -0
- package/src/cli/mcp-audit.test.ts +259 -0
- package/src/cli/mcp-audit.ts +619 -0
- package/src/cli/mcp-upgrade.test.ts +135 -0
- package/src/cli/mcp.ts +373 -34
- package/src/cli/policy.ts +207 -0
- package/src/cli/publish-workflow.test.ts +60 -1
- package/src/cli/remove.ts +8 -2
- package/src/cli/review.ts +457 -0
- package/src/cli/status.test.ts +5 -3
- package/src/cli/status.ts +29 -4
- package/src/cli/sync-check.test.ts +16 -8
- package/src/cli/sync-check.ts +245 -14
- package/src/cli/sync.ts +2 -0
- package/src/cli/team-ci.test.ts +195 -0
- package/src/cli/team-commands.test.ts +253 -0
- package/src/cli/team-config.ts +289 -0
- package/src/cli/team-health.ts +234 -0
- package/src/cli/team-sources.test.ts +578 -0
- package/src/cli/types.ts +19 -1
- package/src/cli/update.ts +217 -44
- package/src/cli/version-range.ts +150 -0
- package/src/cli/website-plugins.test.ts +41 -0
- package/src/dashboard/node_modules/.vite/deps/_metadata.json +6 -6
- package/src/orchestrator/plugins/chrome-devtools/config.ts +11 -1
- package/src/orchestrator/plugins/contentful/config.ts +11 -1
- package/src/orchestrator/plugins/convex/config.ts +11 -1
- package/src/orchestrator/plugins/coolify/config.ts +14 -1
- package/src/orchestrator/plugins/figma/SKILL.md +18 -14
- package/src/orchestrator/plugins/figma/config.ts +24 -13
- package/src/orchestrator/plugins/linear/SKILL.md +6 -14
- package/src/orchestrator/plugins/linear/config.ts +27 -17
- package/src/orchestrator/plugins/netlify/config.ts +23 -9
- package/src/orchestrator/plugins/nextjs/config.ts +11 -1
- package/src/orchestrator/plugins/nx/config.ts +11 -1
- package/src/orchestrator/plugins/pins.test.ts +80 -0
- package/src/orchestrator/plugins/playwright/config.ts +11 -1
- package/src/orchestrator/plugins/prisma/config.ts +17 -2
- package/src/orchestrator/plugins/resend/config.ts +17 -1
- package/src/orchestrator/plugins/sentry/config.ts +13 -1
- package/src/orchestrator/plugins/slack/config.ts +20 -1
- package/src/orchestrator/plugins/strapi/config.ts +11 -1
- package/src/orchestrator/plugins/trello/config.ts +21 -1
- package/src/orchestrator/plugins/types.ts +24 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
import { readManifest } from './manifest.js'
|
|
4
|
+
import { resolveStack, isEnvVarSatisfied } from './stack-config.js'
|
|
5
|
+
import { resolveSources, materialize, hasErrors, formatIssues, requiredEnvVars, refuseOlderCli } from './layers.js'
|
|
6
|
+
import { buildLock, type Lock, priorTeam } from './lock.js'
|
|
7
|
+
import { IDE_ADAPTERS } from './adapters/index.js'
|
|
8
|
+
import { PLUGINS } from '../orchestrator/plugins/index.js'
|
|
9
|
+
import { c } from './prompt.js'
|
|
10
|
+
import { IDE_LABELS, type CliContext, type IdeChoice } from './types.js'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* `opencastle explain`: what a new teammate's assistant is given here, and
|
|
14
|
+
* what they have to do for all of it to work.
|
|
15
|
+
*
|
|
16
|
+
* Onboarding onto a repository's AI setup used to mean reading generated
|
|
17
|
+
* files in whichever format your assistant uses and guessing which of them
|
|
18
|
+
* mattered. This answers it from the same resolution `sync` compiles: what is
|
|
19
|
+
* always loaded and what that costs, which skills exist and when they load,
|
|
20
|
+
* where the team's own content comes from, which MCP servers every assistant
|
|
21
|
+
* can start — and which of those still need a variable set or a sign-in.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const HELP = `
|
|
25
|
+
opencastle explain [options]
|
|
26
|
+
|
|
27
|
+
Show what every assistant in this repository is given, where each piece comes
|
|
28
|
+
from (OpenCastle, a baseline, or this project), and what you still need to
|
|
29
|
+
set up — environment variables and sign-ins for the MCP servers.
|
|
30
|
+
|
|
31
|
+
Options:
|
|
32
|
+
--all List OpenCastle's own skills and agents too, not only the team's
|
|
33
|
+
--json Machine-readable output
|
|
34
|
+
--help, -h Show this help
|
|
35
|
+
`
|
|
36
|
+
|
|
37
|
+
interface ExplainReport {
|
|
38
|
+
targets: Array<{ id: string; label: string; files: string[] }>
|
|
39
|
+
lock: Lock
|
|
40
|
+
setup: Array<{ server: string; need: string; ok: boolean; how: string }>
|
|
41
|
+
notes: string[]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function by(from: string): string {
|
|
45
|
+
if (from === 'opencastle') return 'OpenCastle'
|
|
46
|
+
if (from.startsWith('plugin:')) return `${from.slice(7)} integration`
|
|
47
|
+
return from === 'project' ? 'this project' : from
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function build(pkgRoot: string, projectRoot: string): Promise<ExplainReport> {
|
|
51
|
+
const manifest = await readManifest(projectRoot)
|
|
52
|
+
if (!manifest) throw new Error('OpenCastle is not set up here — run opencastle init')
|
|
53
|
+
refuseOlderCli(pkgRoot, manifest.version)
|
|
54
|
+
const ides = (manifest.ides?.length ? manifest.ides : [manifest.ide]).filter((i): i is string => Boolean(i) && i in IDE_ADAPTERS)
|
|
55
|
+
const stack = resolveStack({ ...manifest, ides })
|
|
56
|
+
const resolved = resolveSources({ pkgRoot, projectRoot, stack, repoInfo: manifest.repoInfo })
|
|
57
|
+
if (hasErrors(resolved)) {
|
|
58
|
+
throw new Error(`the team's sources do not resolve:\n${formatIssues(resolved.issues.filter((i) => i.level === 'error')).join('\n')}`)
|
|
59
|
+
}
|
|
60
|
+
const source = materialize(resolved, pkgRoot, ...priorTeam(projectRoot))
|
|
61
|
+
let lock: Lock
|
|
62
|
+
try {
|
|
63
|
+
lock = buildLock(source, { ides, stack, repoInfo: manifest.repoInfo })
|
|
64
|
+
} finally {
|
|
65
|
+
source.dispose()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const targets: ExplainReport['targets'] = []
|
|
69
|
+
for (const ide of ides) {
|
|
70
|
+
const adapter = await IDE_ADAPTERS[ide]()
|
|
71
|
+
const paths = adapter.getManagedPaths()
|
|
72
|
+
targets.push({
|
|
73
|
+
id: ide,
|
|
74
|
+
label: IDE_LABELS[ide as IdeChoice] ?? ide,
|
|
75
|
+
files: [...(paths.merged ?? []), ...paths.framework, ...paths.customizable.filter((p) => !p.endsWith('/'))],
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const envFile = existsSync(resolve(projectRoot, '.env')) ? readFileSync(resolve(projectRoot, '.env'), 'utf8') : ''
|
|
80
|
+
const setup: ExplainReport['setup'] = []
|
|
81
|
+
for (const req of requiredEnvVars(resolved, stack, manifest.repoInfo)) {
|
|
82
|
+
setup.push({
|
|
83
|
+
server: req.server,
|
|
84
|
+
need: req.envVar,
|
|
85
|
+
ok: isEnvVarSatisfied(req.envVar, envFile),
|
|
86
|
+
how: req.hint,
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
for (const [key, s] of Object.entries(lock.mcp)) {
|
|
90
|
+
if (s.auth === 'oauth') {
|
|
91
|
+
setup.push({ server: key, need: 'sign-in', ok: true, how: 'your assistant opens a browser to sign in the first time it starts the server' })
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const notes = resolved.issues.filter((i) => i.level === 'warning').map((i) => `${i.where}: ${i.message}`)
|
|
95
|
+
return { targets, lock, setup, notes }
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function render(report: ExplainReport, all: boolean): void {
|
|
99
|
+
const { lock } = report
|
|
100
|
+
const out = (s = ''): void => console.log(s)
|
|
101
|
+
out(`\n 🏰 ${c.bold('What the AI assistants in this repository are given')}\n`)
|
|
102
|
+
|
|
103
|
+
const layers = lock.layers.map((l) => (l.kind === 'core' ? `OpenCastle ${l.version}` : l.kind === 'project' ? 'this project' : `${l.id}${l.version ? ` ${l.version}` : ''}`))
|
|
104
|
+
out(` ${c.bold('Layers')} ${layers.join(c.dim(' → '))} ${c.dim('(later layers add to and override earlier ones)')}`)
|
|
105
|
+
out(` ${c.bold('Targets')} ${report.targets.map((t) => t.label).join(', ')}`)
|
|
106
|
+
out('')
|
|
107
|
+
|
|
108
|
+
const entries = Object.entries(lock.content)
|
|
109
|
+
const ofKind = (kind: string) => entries.filter(([ref]) => ref.startsWith(`${kind}/`))
|
|
110
|
+
const required = new Set(lock.policy?.require ?? [])
|
|
111
|
+
const tag = (ref: string, from: string, overrides?: string): string => {
|
|
112
|
+
const bits = [by(from)]
|
|
113
|
+
if (overrides) bits.push(`replaces ${by(overrides)}'s`)
|
|
114
|
+
if (required.has(ref)) bits.push('required')
|
|
115
|
+
return c.dim(`(${bits.join(', ')})`)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
out(` ${c.bold('Always loaded')} ${c.dim(`— ~${lock.context.tokens} tokens before every task: instructions ~${lock.context.instructions}, the skill and agent index ~${lock.context.index}`)}`)
|
|
119
|
+
for (const [ref, item] of ofKind('instructions')) {
|
|
120
|
+
out(` ${c.dim('•')} ${ref.slice(13)} ${c.dim(`~${item.tokens ?? 0} tokens`)} ${tag(ref, item.from, item.overrides)}`)
|
|
121
|
+
}
|
|
122
|
+
if (lock.policy?.contextBudget) out(` ${c.dim(`budget: ${lock.policy.contextBudget} tokens`)}`)
|
|
123
|
+
out('')
|
|
124
|
+
|
|
125
|
+
for (const kind of ['skills', 'agents', 'prompts', 'workflows'] as const) {
|
|
126
|
+
const items = ofKind(kind)
|
|
127
|
+
if (items.length === 0) continue
|
|
128
|
+
const team = items.filter(([, i]) => i.from !== 'opencastle' && !i.from.startsWith('plugin:'))
|
|
129
|
+
const integrations = items.filter(([, i]) => i.from.startsWith('plugin:'))
|
|
130
|
+
const core = items.filter(([, i]) => i.from === 'opencastle')
|
|
131
|
+
const title = { skills: 'Skills — loaded when a task matches the description', agents: 'Agents — personas to delegate to', prompts: 'Prompts', workflows: 'Workflows' }[kind]
|
|
132
|
+
out(` ${c.bold(title)} ${c.dim(`(${items.length})`)}`)
|
|
133
|
+
for (const [ref, item] of [...team, ...integrations, ...(all ? core : [])]) {
|
|
134
|
+
const name = ref.slice(kind.length + 1)
|
|
135
|
+
out(` ${c.dim('•')} ${c.bold(name)} ${tag(ref, item.from, item.overrides)}${item.description ? `\n ${c.dim(item.description)}` : ''}`)
|
|
136
|
+
}
|
|
137
|
+
if (!all && core.length > 0) {
|
|
138
|
+
out(` ${c.dim('•')} ${c.dim(`and ${core.length} from OpenCastle: ${core.map(([r]) => r.slice(kind.length + 1)).join(', ')}`)}`)
|
|
139
|
+
}
|
|
140
|
+
out('')
|
|
141
|
+
}
|
|
142
|
+
if (lock.excluded) {
|
|
143
|
+
out(` ${c.bold('Left out')}`)
|
|
144
|
+
for (const [ref, who] of Object.entries(lock.excluded)) out(` ${c.dim('•')} ${ref} ${c.dim(`(excluded by ${by(who)})`)}`)
|
|
145
|
+
out('')
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const servers = Object.entries(lock.mcp)
|
|
149
|
+
out(` ${c.bold('MCP servers')} ${c.dim(`— tools every assistant can start (${servers.length})`)}`)
|
|
150
|
+
for (const [key, s] of servers) {
|
|
151
|
+
const what = s.transport === 'http' ? `remote: ${s.launch}` : `runs: ${s.launch}`
|
|
152
|
+
const plugin = s.from.startsWith('plugin:') ? PLUGINS[s.from.slice(7)] : undefined
|
|
153
|
+
out(` ${c.dim('•')} ${c.bold(key)} ${c.dim(`(${by(s.from)})`)}\n ${c.dim(what)}${plugin?.officialDocs ? `\n ${c.dim(`docs: ${plugin.officialDocs}`)}` : ''}`)
|
|
154
|
+
}
|
|
155
|
+
if (lock.blocked) {
|
|
156
|
+
for (const [key, why] of Object.entries(lock.blocked)) out(` ${c.yellow('–')} ${key} ${c.dim(`not written: ${why}`)}`)
|
|
157
|
+
}
|
|
158
|
+
out('')
|
|
159
|
+
|
|
160
|
+
if (lock.policy) {
|
|
161
|
+
out(` ${c.bold("The team's policy")}`)
|
|
162
|
+
const p = lock.policy
|
|
163
|
+
// Per layer: a server must be on every list, so a union would overstate it.
|
|
164
|
+
if (p.allow) {
|
|
165
|
+
out(` ${c.dim('•')} MCP servers must be on every one of these allowlists:`)
|
|
166
|
+
for (const [who, list] of Object.entries(p.allow)) out(` ${c.dim(`${by(who)}:`)} ${list.join(', ')}`)
|
|
167
|
+
}
|
|
168
|
+
if (p.remoteHosts) {
|
|
169
|
+
out(` ${c.dim('•')} Remote servers may only reach hosts every one of these allows:`)
|
|
170
|
+
for (const [who, list] of Object.entries(p.remoteHosts)) out(` ${c.dim(`${by(who)}:`)} ${list.join(', ')}`)
|
|
171
|
+
}
|
|
172
|
+
if (p.requirePinned) out(` ${c.dim('•')} Every local server must be pinned to an exact version (${p.requirePinned})`)
|
|
173
|
+
if (p.require) out(` ${c.dim('•')} Required everywhere: ${p.require.join(', ')}`)
|
|
174
|
+
if (p.opencastle) out(` ${c.dim('•')} OpenCastle version: ${Object.values(p.opencastle).join(' and ')}`)
|
|
175
|
+
out('')
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
out(` ${c.bold('Your setup')}`)
|
|
179
|
+
if (report.setup.length === 0) out(` ${c.green('✓')} Nothing to set up — every server works without a variable or a sign-in.`)
|
|
180
|
+
for (const s of report.setup) {
|
|
181
|
+
if (s.need === 'sign-in') out(` ${c.cyan('→')} ${s.server}: ${s.how}`)
|
|
182
|
+
else out(` ${s.ok ? c.green('✓') : c.red('✗')} ${s.need} ${c.dim(`— ${s.how}${s.ok ? '' : '; set it in .env or your shell'}`)}`)
|
|
183
|
+
}
|
|
184
|
+
out('')
|
|
185
|
+
for (const t of report.targets) out(` ${c.dim(`${t.label}: ${t.files.join(', ')}`)}`)
|
|
186
|
+
if (report.notes.length > 0) {
|
|
187
|
+
out('')
|
|
188
|
+
for (const n of report.notes) out(` ${c.yellow('!')} ${c.dim(n)}`)
|
|
189
|
+
}
|
|
190
|
+
out('')
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export default async function explain({ pkgRoot, args }: CliContext): Promise<void> {
|
|
194
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
195
|
+
console.log(HELP)
|
|
196
|
+
return
|
|
197
|
+
}
|
|
198
|
+
let report: ExplainReport
|
|
199
|
+
try {
|
|
200
|
+
report = await build(pkgRoot, process.cwd())
|
|
201
|
+
} catch (err) {
|
|
202
|
+
console.error(`\n ${c.red('✗')} Cannot explain: ${(err as Error).message}\n`)
|
|
203
|
+
process.exit(1)
|
|
204
|
+
}
|
|
205
|
+
if (args.includes('--json')) {
|
|
206
|
+
console.log(JSON.stringify(report, null, 2))
|
|
207
|
+
return
|
|
208
|
+
}
|
|
209
|
+
render(report, args.includes('--all'))
|
|
210
|
+
}
|
package/src/cli/fleet.ts
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
2
|
+
import { basename, join, resolve } from 'node:path'
|
|
3
|
+
import { readLock, LOCK_REL, type Lock } from './lock.js'
|
|
4
|
+
import { parseVersion, compareVersions } from './version-range.js'
|
|
5
|
+
import { c } from './prompt.js'
|
|
6
|
+
import type { CliContext } from './types.js'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* `opencastle fleet`: many repositories, one view.
|
|
10
|
+
*
|
|
11
|
+
* A platform team that publishes a baseline needs to know where it has landed:
|
|
12
|
+
* which repositories run which version, which are behind, and whether the same
|
|
13
|
+
* MCP server runs at five different versions across the organisation. Every
|
|
14
|
+
* repository's committed lock already says all of this, so the answer is a
|
|
15
|
+
* read of files — no install, no network, no access to anyone's machine.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const HELP = `
|
|
19
|
+
opencastle fleet <dir...> [options]
|
|
20
|
+
|
|
21
|
+
Read the committed .opencastle/lock.json of each repository given and show
|
|
22
|
+
which OpenCastle and baseline versions they run, which lag behind the newest,
|
|
23
|
+
and which MCP servers run at more than one version across them.
|
|
24
|
+
|
|
25
|
+
Options:
|
|
26
|
+
--json Machine-readable output
|
|
27
|
+
--help, -h Show this help
|
|
28
|
+
|
|
29
|
+
Example: opencastle fleet ~/src/*
|
|
30
|
+
`
|
|
31
|
+
|
|
32
|
+
interface RepoRow {
|
|
33
|
+
repo: string
|
|
34
|
+
path: string
|
|
35
|
+
lock: Lock | null
|
|
36
|
+
/** A lock is there but this release cannot read it — written by a newer one, or edited. */
|
|
37
|
+
unreadable?: boolean
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface FleetReport {
|
|
41
|
+
repos: Array<{
|
|
42
|
+
repo: string
|
|
43
|
+
opencastle?: string
|
|
44
|
+
baselines: Record<string, string>
|
|
45
|
+
targets: string[]
|
|
46
|
+
mcpServers: number
|
|
47
|
+
contextTokens?: number
|
|
48
|
+
lock: boolean
|
|
49
|
+
unreadable?: boolean
|
|
50
|
+
}>
|
|
51
|
+
/** Per baseline or OpenCastle itself: version → repositories. */
|
|
52
|
+
versions: Record<string, Record<string, string[]>>
|
|
53
|
+
/** MCP servers launched at more than one version or address. */
|
|
54
|
+
spread: Record<string, Record<string, string[]>>
|
|
55
|
+
withoutLock: string[]
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function repoName(dir: string): string {
|
|
59
|
+
try {
|
|
60
|
+
const pkg = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')) as { name?: string }
|
|
61
|
+
if (pkg.name) return pkg.name
|
|
62
|
+
} catch {
|
|
63
|
+
// Not a package; the directory name will do.
|
|
64
|
+
}
|
|
65
|
+
return basename(dir)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function buildFleet(rows: RepoRow[]): FleetReport {
|
|
69
|
+
const report: FleetReport = { repos: [], versions: {}, spread: {}, withoutLock: [] }
|
|
70
|
+
const note = (bucket: Record<string, Record<string, string[]>>, key: string, value: string, repo: string): void => {
|
|
71
|
+
;((bucket[key] ??= {})[value] ??= []).push(repo)
|
|
72
|
+
}
|
|
73
|
+
for (const { repo, lock, unreadable } of rows) {
|
|
74
|
+
if (!lock) {
|
|
75
|
+
report.withoutLock.push(repo)
|
|
76
|
+
report.repos.push({ repo, baselines: {}, targets: [], mcpServers: 0, lock: false, ...(unreadable && { unreadable: true }) })
|
|
77
|
+
continue
|
|
78
|
+
}
|
|
79
|
+
const baselines: Record<string, string> = {}
|
|
80
|
+
for (const l of lock.layers) {
|
|
81
|
+
if (l.kind === 'baseline') baselines[l.id] = l.version ?? '?'
|
|
82
|
+
}
|
|
83
|
+
report.repos.push({
|
|
84
|
+
repo,
|
|
85
|
+
opencastle: lock.opencastle,
|
|
86
|
+
baselines,
|
|
87
|
+
targets: lock.targets,
|
|
88
|
+
mcpServers: Object.keys(lock.mcp).length,
|
|
89
|
+
contextTokens: lock.context?.tokens,
|
|
90
|
+
lock: true,
|
|
91
|
+
})
|
|
92
|
+
note(report.versions, 'opencastle', lock.opencastle, repo)
|
|
93
|
+
for (const [id, v] of Object.entries(baselines)) note(report.versions, id, v, repo)
|
|
94
|
+
for (const [key, s] of Object.entries(lock.mcp)) note(report.spread, key, s.launch, repo)
|
|
95
|
+
}
|
|
96
|
+
for (const key of Object.keys(report.spread)) {
|
|
97
|
+
if (Object.keys(report.spread[key]).length < 2) delete report.spread[key]
|
|
98
|
+
}
|
|
99
|
+
return report
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function newest(versions: string[]): string | undefined {
|
|
103
|
+
return [...versions].sort((a, b) => {
|
|
104
|
+
const pa = parseVersion(a)
|
|
105
|
+
const pb = parseVersion(b)
|
|
106
|
+
if (!pa || !pb) return a < b ? -1 : 1
|
|
107
|
+
return compareVersions(pa, pb)
|
|
108
|
+
}).pop()
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function render(report: FleetReport): void {
|
|
112
|
+
const out = (s = ''): void => console.log(s)
|
|
113
|
+
out(`\n 🏰 ${c.bold('Fleet')} ${c.dim(`— ${report.repos.length} repositories`)}\n`)
|
|
114
|
+
const width = Math.max(10, ...report.repos.map((r) => r.repo.length))
|
|
115
|
+
for (const r of report.repos) {
|
|
116
|
+
if (!r.lock) {
|
|
117
|
+
out(
|
|
118
|
+
` ${c.yellow('!')} ${r.repo.padEnd(width)} ${c.dim(
|
|
119
|
+
r.unreadable ? 'a lock this release cannot read — written by a newer OpenCastle, or edited by hand' : 'no lock — not synced with a release that writes one',
|
|
120
|
+
)}`,
|
|
121
|
+
)
|
|
122
|
+
continue
|
|
123
|
+
}
|
|
124
|
+
const bl = Object.entries(r.baselines).map(([id, v]) => `${id}@${v}`).join(', ')
|
|
125
|
+
out(
|
|
126
|
+
` ${c.dim('•')} ${r.repo.padEnd(width)} opencastle ${r.opencastle} ${bl || c.dim('no baseline')} ` +
|
|
127
|
+
c.dim(`${r.targets.length} target(s), ${r.mcpServers} MCP server(s), ~${r.contextTokens ?? '?'} tokens up front`),
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
out('')
|
|
131
|
+
for (const [what, byVersion] of Object.entries(report.versions)) {
|
|
132
|
+
const versions = Object.keys(byVersion)
|
|
133
|
+
const top = newest(versions)
|
|
134
|
+
const behind = versions.filter((v) => v !== top).flatMap((v) => byVersion[v])
|
|
135
|
+
const line = versions
|
|
136
|
+
.sort()
|
|
137
|
+
.map((v) => `${v} (${byVersion[v].length})`)
|
|
138
|
+
.join(', ')
|
|
139
|
+
out(` ${c.bold(what)}: ${line}${behind.length > 0 ? c.yellow(` — ${behind.length} behind ${top}: ${behind.join(', ')}`) : c.green(' — all on one version')}`)
|
|
140
|
+
}
|
|
141
|
+
const spread = Object.entries(report.spread)
|
|
142
|
+
if (spread.length > 0) {
|
|
143
|
+
out('')
|
|
144
|
+
out(` ${c.bold('MCP servers running differently across repositories')}`)
|
|
145
|
+
for (const [key, byLaunch] of spread) {
|
|
146
|
+
out(` ${c.yellow('~')} ${key}`)
|
|
147
|
+
for (const [launch, repos] of Object.entries(byLaunch)) out(` ${c.dim(`${launch} — ${repos.join(', ')}`)}`)
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
out('')
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export default async function fleet({ args }: CliContext): Promise<void> {
|
|
154
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
155
|
+
console.log(HELP)
|
|
156
|
+
return
|
|
157
|
+
}
|
|
158
|
+
const dirs = args.filter((a) => !a.startsWith('--'))
|
|
159
|
+
if (dirs.length === 0) {
|
|
160
|
+
console.log(HELP)
|
|
161
|
+
process.exit(1)
|
|
162
|
+
}
|
|
163
|
+
const rows: RepoRow[] = []
|
|
164
|
+
for (const dir of dirs) {
|
|
165
|
+
const abs = resolve(dir)
|
|
166
|
+
if (!existsSync(join(abs, '.opencastle'))) continue
|
|
167
|
+
rows.push({ repo: repoName(abs), path: abs, lock: readLock(abs), unreadable: existsSync(join(abs, LOCK_REL)) && !readLock(abs) })
|
|
168
|
+
}
|
|
169
|
+
if (rows.length === 0) {
|
|
170
|
+
console.error(`\n ${c.red('✗')} None of those directories uses OpenCastle (no .opencastle/ in any).\n`)
|
|
171
|
+
process.exit(1)
|
|
172
|
+
}
|
|
173
|
+
const report = buildFleet(rows)
|
|
174
|
+
if (args.includes('--json')) console.log(JSON.stringify(report, null, 2))
|
|
175
|
+
else render(report)
|
|
176
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
|
2
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync, existsSync } from 'node:fs'
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
import { tmpdir } from 'node:os'
|
|
5
|
+
import { escapeData, escapeProperty, annotationPath, annotations, summaryMarkdown, reportToGitHub, COMPARISON_FAILED } from './github-report.js'
|
|
6
|
+
import type { CheckReport } from './sync-check.js'
|
|
7
|
+
|
|
8
|
+
const clean: CheckReport = { installed: true, ides: ['claude-code', 'cursor'], drift: [], checked: 42 }
|
|
9
|
+
const drifted: CheckReport = {
|
|
10
|
+
installed: true,
|
|
11
|
+
ides: ['cursor'],
|
|
12
|
+
checked: 10,
|
|
13
|
+
drift: [
|
|
14
|
+
{ ide: 'cursor', path: '.cursor/rules/general.mdc', kind: 'changed' },
|
|
15
|
+
{ ide: 'cursor', path: '.cursor/rules/gone.mdc', kind: 'missing' },
|
|
16
|
+
{ ide: 'cursor', path: '.cursor/rules/stray.mdc', kind: 'extra' },
|
|
17
|
+
{ ide: 'claude-code', path: 'CLAUDE.md', kind: 'unreducible', detail: 'two start markers', fix: 'keep one pair' },
|
|
18
|
+
],
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe('escaping', () => {
|
|
22
|
+
it('encodes what the runner decodes', () => {
|
|
23
|
+
expect(escapeData('50%\nnext')).toBe('50%25%0Anext')
|
|
24
|
+
expect(escapeProperty('a:b,c')).toBe('a%3Ab%2Cc')
|
|
25
|
+
})
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
describe('annotationPath', () => {
|
|
29
|
+
it('is relative to the checkout, so a monorepo project annotates the right file', () => {
|
|
30
|
+
expect(annotationPath('CLAUDE.md', '/ws/apps/web', '/ws')).toBe('apps/web/CLAUDE.md')
|
|
31
|
+
})
|
|
32
|
+
it('falls back to the project when there is no workspace', () => {
|
|
33
|
+
expect(annotationPath('.cursor/rules/x.mdc', '/p')).toBe('.cursor/rules/x.mdc')
|
|
34
|
+
})
|
|
35
|
+
it('never climbs out of the workspace', () => {
|
|
36
|
+
expect(annotationPath('CLAUDE.md', '/elsewhere', '/ws')).toBe('CLAUDE.md')
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
describe('annotations', () => {
|
|
41
|
+
it('writes one error per drifted file, each with its own remedy', () => {
|
|
42
|
+
const lines = annotations(drifted, '/ws', '/ws')
|
|
43
|
+
expect(lines).toHaveLength(4)
|
|
44
|
+
expect(lines[0]).toMatch(/^::error file=\.cursor\/rules\/general\.mdc,title=Generated file differs from its source::/)
|
|
45
|
+
expect(lines[0]).toContain('.opencastle/')
|
|
46
|
+
// An upgrade nobody recompiled after looks the same; do not blame an edit.
|
|
47
|
+
expect(lines[0]).not.toMatch(/edited in place/i)
|
|
48
|
+
expect(lines[1]).toContain('commit the result')
|
|
49
|
+
expect(lines[2]).toContain('deletes it')
|
|
50
|
+
expect(lines[3]).toMatch(/^::error file=CLAUDE\.md,/)
|
|
51
|
+
expect(lines[3]).toContain('CLAUDE.md (claude-code): two start markers')
|
|
52
|
+
expect(lines[3]).toContain('Fix: keep one pair')
|
|
53
|
+
})
|
|
54
|
+
it('pins a project-wide file to itself', () => {
|
|
55
|
+
const report: CheckReport = {
|
|
56
|
+
...clean,
|
|
57
|
+
drift: [{ ide: 'all', path: '.gitignore', kind: 'unreducible', detail: 'cannot be read — EACCES', fix: 'fix the permissions' }],
|
|
58
|
+
}
|
|
59
|
+
const line = annotations(report, '/ws', '/ws')[0]
|
|
60
|
+
expect(line).toMatch(/^::error file=\.gitignore,/)
|
|
61
|
+
expect(line).toContain('.gitignore (all): cannot be read')
|
|
62
|
+
})
|
|
63
|
+
it('pins no file when the comparison itself failed, and still says what failed', () => {
|
|
64
|
+
const failed: CheckReport = {
|
|
65
|
+
...clean,
|
|
66
|
+
drift: [{ ide: 'all', path: 'EACCES: permission denied, scandir /p/.claude', kind: 'unreducible', detail: COMPARISON_FAILED, fix: 'fix the path named above' }],
|
|
67
|
+
}
|
|
68
|
+
const line = annotations(failed, '/ws')[0]
|
|
69
|
+
expect(line).toMatch(/^::error title=/)
|
|
70
|
+
expect(line).toContain('EACCES: permission denied')
|
|
71
|
+
expect(summaryMarkdown(failed)).toContain('The comparison could not run: EACCES')
|
|
72
|
+
expect(summaryMarkdown(failed)).not.toContain('differ')
|
|
73
|
+
})
|
|
74
|
+
it('explains an earlier MCP default', () => {
|
|
75
|
+
const report: CheckReport = {
|
|
76
|
+
...clean,
|
|
77
|
+
drift: [{ ide: 'claude-code', path: '.mcp.json', kind: 'outdated', detail: 'still an earlier OpenCastle default: Supabase', fix: 'opencastle sync' }],
|
|
78
|
+
}
|
|
79
|
+
const line = annotations(report, '/ws', '/ws')[0]
|
|
80
|
+
expect(line).toMatch(/^::error file=\.mcp\.json,title=MCP config that sync would change::/)
|
|
81
|
+
expect(line).toContain('touches only entries OpenCastle wrote and nobody edited')
|
|
82
|
+
})
|
|
83
|
+
it('says what to run when nothing is installed', () => {
|
|
84
|
+
expect(annotations({ ...clean, installed: false }, '/ws')[0]).toContain('opencastle init')
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
describe('summaryMarkdown', () => {
|
|
89
|
+
it('reports health in one line', () => {
|
|
90
|
+
expect(summaryMarkdown(clean)).toContain('42 generated files match their sources across 2 targets')
|
|
91
|
+
})
|
|
92
|
+
it('tabulates drift with a remedy per row', () => {
|
|
93
|
+
const md = summaryMarkdown(drifted)
|
|
94
|
+
expect(md).toContain('| File | Target | What happened | What to do |')
|
|
95
|
+
expect(md).toContain('`.cursor/rules/general.mdc`')
|
|
96
|
+
expect(md).toContain('Run `npx opencastle sync`')
|
|
97
|
+
})
|
|
98
|
+
it('does not call a broken MCP server a file that differs from its source', () => {
|
|
99
|
+
const report: CheckReport = {
|
|
100
|
+
...clean,
|
|
101
|
+
drift: [{ ide: 'claude-code', path: '.mcp.json', kind: 'unreducible', origin: 'mcp', detail: 'x', fix: 'y' }],
|
|
102
|
+
}
|
|
103
|
+
expect(summaryMarkdown(report)).toContain('1 MCP config has a server only a person can fix')
|
|
104
|
+
})
|
|
105
|
+
it('agrees in number', () => {
|
|
106
|
+
expect(summaryMarkdown({ ...drifted, drift: drifted.drift.slice(0, 1) })).toContain('1 file differs from its source')
|
|
107
|
+
})
|
|
108
|
+
it('keeps a pipe in a path from breaking the table', () => {
|
|
109
|
+
const md = summaryMarkdown({ ...drifted, drift: [{ ide: 'cursor', path: 'a|b.mdc', kind: 'extra' }] })
|
|
110
|
+
expect(md).toContain('a\\|b.mdc')
|
|
111
|
+
})
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
describe('reportToGitHub', () => {
|
|
115
|
+
let dir: string
|
|
116
|
+
beforeEach(() => {
|
|
117
|
+
dir = mkdtempSync(join(tmpdir(), 'gh-report-'))
|
|
118
|
+
})
|
|
119
|
+
afterEach(() => {
|
|
120
|
+
rmSync(dir, { recursive: true, force: true })
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('does nothing off GitHub Actions', () => {
|
|
124
|
+
const out: string[] = []
|
|
125
|
+
const summary = join(dir, 'summary.md')
|
|
126
|
+
reportToGitHub(drifted, dir, { env: { GITHUB_STEP_SUMMARY: summary }, write: (l) => out.push(l) })
|
|
127
|
+
expect(out).toEqual([])
|
|
128
|
+
expect(existsSync(summary)).toBe(false)
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
it('annotates and appends the summary on GitHub Actions', () => {
|
|
132
|
+
const out: string[] = []
|
|
133
|
+
const summary = join(dir, 'summary.md')
|
|
134
|
+
writeFileSync(summary, 'earlier step\n')
|
|
135
|
+
reportToGitHub(drifted, dir, {
|
|
136
|
+
env: { GITHUB_ACTIONS: 'true', GITHUB_STEP_SUMMARY: summary, GITHUB_WORKSPACE: dir },
|
|
137
|
+
write: (l) => out.push(l),
|
|
138
|
+
})
|
|
139
|
+
expect(out).toHaveLength(4)
|
|
140
|
+
const text = readFileSync(summary, 'utf8')
|
|
141
|
+
expect(text.startsWith('earlier step\n')).toBe(true)
|
|
142
|
+
expect(text).toContain('4 files differ from their sources')
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
it('keeps stdout clean for --json, and still writes the summary', () => {
|
|
146
|
+
const out: string[] = []
|
|
147
|
+
const summary = join(dir, 'summary.md')
|
|
148
|
+
reportToGitHub(clean, dir, { json: true, env: { GITHUB_ACTIONS: 'true', GITHUB_STEP_SUMMARY: summary }, write: (l) => out.push(l) })
|
|
149
|
+
expect(out).toEqual([])
|
|
150
|
+
expect(readFileSync(summary, 'utf8')).toContain('match their sources')
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
it('does not throw when the summary cannot be written', () => {
|
|
154
|
+
expect(() =>
|
|
155
|
+
reportToGitHub(clean, dir, { env: { GITHUB_ACTIONS: 'true', GITHUB_STEP_SUMMARY: join(dir, 'no', 'such', 'dir', 'x.md') }, write: () => {} }),
|
|
156
|
+
).not.toThrow()
|
|
157
|
+
})
|
|
158
|
+
})
|