opencastle 0.38.2 → 1.1.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 +89 -4
- 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 +8 -4
- package/dist/cli/adapters/claude-code.d.ts.map +1 -1
- package/dist/cli/adapters/claude-code.js +13 -7
- package/dist/cli/adapters/claude-code.js.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 +8 -1
- package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
- package/dist/cli/adapters/single-file-base.js +43 -46
- package/dist/cli/adapters/single-file-base.js.map +1 -1
- package/dist/cli/adapters/vscode.d.ts +14 -3
- package/dist/cli/adapters/vscode.d.ts.map +1 -1
- package/dist/cli/adapters/vscode.js +63 -75
- 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/command-namespace.d.ts +91 -0
- package/dist/cli/command-namespace.d.ts.map +1 -0
- package/dist/cli/command-namespace.js +218 -0
- package/dist/cli/command-namespace.js.map +1 -0
- package/dist/cli/command-namespace.test.d.ts +2 -0
- package/dist/cli/command-namespace.test.d.ts.map +1 -0
- package/dist/cli/command-namespace.test.js +356 -0
- package/dist/cli/command-namespace.test.js.map +1 -0
- package/dist/cli/copy.d.ts +1 -1
- package/dist/cli/copy.d.ts.map +1 -1
- package/dist/cli/copy.js +3 -2
- package/dist/cli/copy.js.map +1 -1
- 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/doctor.test.js +2 -2
- package/dist/cli/doctor.test.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 +222 -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 +171 -96
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/init.test.js +35 -29
- 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/managed-paths.d.ts +18 -1
- package/dist/cli/managed-paths.d.ts.map +1 -1
- package/dist/cli/managed-paths.js +72 -2
- package/dist/cli/managed-paths.js.map +1 -1
- package/dist/cli/manifest.d.ts.map +1 -1
- package/dist/cli/manifest.js +2 -0
- package/dist/cli/manifest.js.map +1 -1
- 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 +25 -6
- 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 +241 -17
- 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 +48 -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 +218 -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 +4 -2
- package/src/cli/adapters/claude-code.ts +13 -7
- package/src/cli/adapters/rules-dir-base.ts +23 -44
- package/src/cli/adapters/single-file-base.ts +65 -50
- package/src/cli/adapters/vscode.ts +75 -77
- package/src/cli/baseline.ts +289 -0
- package/src/cli/ci.ts +289 -0
- package/src/cli/command-namespace.test.ts +417 -0
- package/src/cli/command-namespace.ts +222 -0
- package/src/cli/copy.ts +6 -2
- package/src/cli/dispatcher.test.ts +2 -2
- package/src/cli/docs-accuracy.test.ts +5 -0
- package/src/cli/doctor.test.ts +2 -2
- package/src/cli/doctor.ts +92 -6
- package/src/cli/explain.ts +222 -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 +36 -31
- package/src/cli/init.ts +174 -96
- 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/managed-paths.ts +73 -3
- package/src/cli/manifest.ts +2 -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 +28 -6
- 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 +264 -17
- 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 +51 -1
- package/src/cli/update.ts +229 -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
- package/src/orchestrator/prompts/bootstrap-customizations.prompt.md +4 -4
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The team commands, driven through the CLI the way a platform team, a new
|
|
3
|
+
* teammate and a CI job drive them — against a baseline installed where npm
|
|
4
|
+
* would install it.
|
|
5
|
+
*/
|
|
6
|
+
import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync, existsSync } from 'node:fs'
|
|
7
|
+
import { tmpdir } from 'node:os'
|
|
8
|
+
import { join, resolve, dirname } from 'node:path'
|
|
9
|
+
import { execFileSync } from 'node:child_process'
|
|
10
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
|
11
|
+
|
|
12
|
+
const repoRoot = resolve(import.meta.dirname, '..', '..')
|
|
13
|
+
const cli = join(repoRoot, 'bin', 'cli.mjs')
|
|
14
|
+
const built = existsSync(join(repoRoot, 'dist', 'cli', 'review.js'))
|
|
15
|
+
|
|
16
|
+
function run(dir: string, args: string[], env: NodeJS.ProcessEnv = {}): { code: number; out: string } {
|
|
17
|
+
const base = { ...process.env }
|
|
18
|
+
for (const k of Object.keys(base)) if (k.startsWith('GITHUB_')) delete base[k]
|
|
19
|
+
try {
|
|
20
|
+
const out = execFileSync('node', [cli, ...args], { cwd: dir, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], env: { ...base, ...env } })
|
|
21
|
+
return { code: 0, out }
|
|
22
|
+
} catch (err) {
|
|
23
|
+
const e = err as { status?: number; stdout?: string; stderr?: string }
|
|
24
|
+
return { code: e.status ?? 1, out: `${e.stdout ?? ''}${e.stderr ?? ''}` }
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function write(root: string, files: Record<string, string>): void {
|
|
29
|
+
for (const [rel, text] of Object.entries(files)) {
|
|
30
|
+
const abs = join(root, rel)
|
|
31
|
+
mkdirSync(dirname(abs), { recursive: true })
|
|
32
|
+
writeFileSync(abs, text)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function git(dir: string, ...args: string[]): void {
|
|
37
|
+
execFileSync('git', ['-c', 'user.email=t@t', '-c', 'user.name=t', ...args], { cwd: dir, stdio: 'ignore' })
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const BASELINE = 'node_modules/@acme/base'
|
|
41
|
+
|
|
42
|
+
function installBaseline(dir: string, version: string, extra: Record<string, string> = {}): void {
|
|
43
|
+
write(dir, {
|
|
44
|
+
[`${BASELINE}/package.json`]: JSON.stringify({ name: '@acme/base', version, opencastle: { baseline: 'layer' } }),
|
|
45
|
+
[`${BASELINE}/layer/config.json`]: JSON.stringify({
|
|
46
|
+
policy: { mcp: { allow: ['chrome-devtools', 'next-devtools', 'acme-*'], requirePinned: true }, require: ['skills/secure-coding'] },
|
|
47
|
+
}),
|
|
48
|
+
[`${BASELINE}/layer/skills/secure-coding/SKILL.md`]:
|
|
49
|
+
'---\nname: secure-coding\ndescription: "Our secure coding rules. Use when touching auth or user input."\n---\n\n# Secure coding\n',
|
|
50
|
+
...extra,
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
describe.skipIf(!built)('a repository extending a baseline', () => {
|
|
55
|
+
let dir: string
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
dir = mkdtempSync(join(tmpdir(), 'team-cmd-'))
|
|
58
|
+
git(dir, 'init', '-q')
|
|
59
|
+
write(dir, {
|
|
60
|
+
'package.json': JSON.stringify({ name: 'shop', scripts: { test: 'vitest' }, devDependencies: { next: '15.0.0', '@acme/base': '1.4.0' } }),
|
|
61
|
+
'.opencastle/config.json': JSON.stringify({
|
|
62
|
+
extends: ['@acme/base'],
|
|
63
|
+
mcpServers: { 'acme-db': { command: 'npx', args: ['-y', '@acme/db-mcp@2.1.0'], env: { DB_URL: '${DB_URL}' } } },
|
|
64
|
+
}),
|
|
65
|
+
})
|
|
66
|
+
installBaseline(dir, '1.4.0')
|
|
67
|
+
expect(run(dir, ['init', '--yes']).code).toBe(0)
|
|
68
|
+
})
|
|
69
|
+
afterEach(() => {
|
|
70
|
+
rmSync(dir, { recursive: true, force: true })
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it("compiles the baseline and the project's own server, writes the lock, and checks clean", () => {
|
|
74
|
+
expect(existsSync(join(dir, '.github', 'skills', 'secure-coding', 'SKILL.md'))).toBe(true)
|
|
75
|
+
expect(JSON.parse(readFileSync(join(dir, '.vscode', 'mcp.json'), 'utf8')).servers['acme-db']).toBeDefined()
|
|
76
|
+
const lock = JSON.parse(readFileSync(join(dir, '.opencastle', 'lock.json'), 'utf8'))
|
|
77
|
+
expect(lock.layers.map((l: { id: string }) => l.id)).toEqual(['opencastle', '@acme/base', 'project'])
|
|
78
|
+
expect(run(dir, ['sync', '--check']).code).toBe(0)
|
|
79
|
+
const doctor = run(dir, ['doctor'])
|
|
80
|
+
expect(doctor.out).toContain('extends @acme/base@1.4.0')
|
|
81
|
+
expect(doctor.out).toContain('Always-loaded context')
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('refuses to sync with a baseline missing, and says what to install', () => {
|
|
85
|
+
rmSync(join(dir, 'node_modules'), { recursive: true, force: true })
|
|
86
|
+
const sync = run(dir, ['sync', '--yes'])
|
|
87
|
+
expect(sync.code).toBe(1)
|
|
88
|
+
expect(sync.out).toContain('extends "@acme/base", which is not installed')
|
|
89
|
+
expect(sync.out).toContain('nothing was compiled')
|
|
90
|
+
expect(run(dir, ['sync', '--check']).code).toBe(1)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('reviews a baseline upgrade in sentences, and writes it to the job summary', () => {
|
|
94
|
+
git(dir, 'add', '-A')
|
|
95
|
+
git(dir, 'commit', '-qm', 'init')
|
|
96
|
+
installBaseline(dir, '1.5.0', {
|
|
97
|
+
[`${BASELINE}/layer/config.json`]: JSON.stringify({
|
|
98
|
+
policy: { mcp: { allow: ['chrome-devtools', 'next-devtools', 'acme-*'], requirePinned: true }, require: ['skills/secure-coding'] },
|
|
99
|
+
mcpServers: { 'acme-docs': { url: 'https://docs.acme.dev/mcp' } },
|
|
100
|
+
}),
|
|
101
|
+
})
|
|
102
|
+
const summary = join(dir, 'summary.md')
|
|
103
|
+
const review = run(dir, ['review', '--base', 'HEAD'], { GITHUB_ACTIONS: 'true', GITHUB_STEP_SUMMARY: summary })
|
|
104
|
+
expect(review.code).toBe(0)
|
|
105
|
+
expect(review.out).toContain('@acme/base 1.4.0 → 1.5.0')
|
|
106
|
+
expect(review.out).toContain('New MCP server')
|
|
107
|
+
expect(readFileSync(summary, 'utf8')).toContain('### OpenCastle — what this change does to the AI assistants')
|
|
108
|
+
// The lock has not been synced yet, and review says so.
|
|
109
|
+
expect(review.out).toContain('is not what the sources compile to')
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('explains what a new teammate needs to set up', () => {
|
|
113
|
+
const explain = run(dir, ['explain'])
|
|
114
|
+
expect(explain.code).toBe(0)
|
|
115
|
+
expect(explain.out).toContain('secure-coding')
|
|
116
|
+
expect(explain.out).toContain('DB_URL')
|
|
117
|
+
const json = JSON.parse(run(dir, ['explain', '--json']).out)
|
|
118
|
+
expect(json.setup).toContainEqual(expect.objectContaining({ server: 'acme-db', need: 'DB_URL', ok: false }))
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it('does not rewrite the manifest when a sync changes only generated content', () => {
|
|
122
|
+
const before = readFileSync(join(dir, '.opencastle', 'manifest.json'), 'utf8')
|
|
123
|
+
write(dir, { '.opencastle/skills/deploy/SKILL.md': '---\nname: deploy\ndescription: "How we deploy. Use when releasing."\n---\n\n# Deploy\n' })
|
|
124
|
+
const sync = run(dir, ['sync', '--yes'])
|
|
125
|
+
expect(sync.code).toBe(0)
|
|
126
|
+
expect(existsSync(join(dir, '.github', 'skills', 'deploy', 'SKILL.md'))).toBe(true)
|
|
127
|
+
expect(readFileSync(join(dir, '.opencastle', 'manifest.json'), 'utf8')).toBe(before)
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it('refuses to downgrade a project compiled by a newer OpenCastle — --force included', () => {
|
|
131
|
+
const path = join(dir, '.opencastle', 'manifest.json')
|
|
132
|
+
const manifest = JSON.parse(readFileSync(path, 'utf8'))
|
|
133
|
+
manifest.version = '99.0.0'
|
|
134
|
+
writeFileSync(path, JSON.stringify(manifest))
|
|
135
|
+
for (const args of [['sync', '--yes'], ['sync', '--force', '--yes']]) {
|
|
136
|
+
const sync = run(dir, args)
|
|
137
|
+
expect(sync.code).toBe(1)
|
|
138
|
+
expect(sync.out).toContain('compiled by OpenCastle 99.0.0')
|
|
139
|
+
}
|
|
140
|
+
const doctor = run(dir, ['doctor'])
|
|
141
|
+
expect(doctor.code).toBe(1)
|
|
142
|
+
expect(doctor.out).toContain('older than the 99.0.0')
|
|
143
|
+
// The check says why it compared nothing, instead of prescribing the sync that refuses.
|
|
144
|
+
const check = run(dir, ['sync', '--check'])
|
|
145
|
+
expect(check.code).toBe(1)
|
|
146
|
+
expect(check.out).toContain('older than the one that compiled the project')
|
|
147
|
+
expect(check.out).not.toContain('Fix: opencastle sync')
|
|
148
|
+
const down = run(dir, ['sync', '--allow-downgrade', '--yes'])
|
|
149
|
+
expect(down.code).toBe(0)
|
|
150
|
+
expect(down.out).toContain('Downgrading this project from OpenCastle 99.0.0')
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
it('init refuses to downgrade too', () => {
|
|
154
|
+
const path = join(dir, '.opencastle', 'manifest.json')
|
|
155
|
+
const manifest = JSON.parse(readFileSync(path, 'utf8'))
|
|
156
|
+
manifest.version = '99.0.0'
|
|
157
|
+
writeFileSync(path, JSON.stringify(manifest))
|
|
158
|
+
const init = run(dir, ['init', '--yes'])
|
|
159
|
+
expect(init.code).toBe(1)
|
|
160
|
+
expect(init.out).toContain('compiled by OpenCastle 99.0.0')
|
|
161
|
+
expect(JSON.parse(readFileSync(path, 'utf8')).version).toBe('99.0.0')
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
it('reports removing a hand-added server the project excluded', () => {
|
|
165
|
+
write(dir, {
|
|
166
|
+
'.opencastle/config.json': JSON.stringify({
|
|
167
|
+
extends: ['@acme/base'],
|
|
168
|
+
exclude: ['mcpServers/acme-db'],
|
|
169
|
+
}),
|
|
170
|
+
})
|
|
171
|
+
const vscode = JSON.parse(readFileSync(join(dir, '.vscode', 'mcp.json'), 'utf8'))
|
|
172
|
+
expect(vscode.servers['acme-db']).toBeDefined()
|
|
173
|
+
const check = run(dir, ['sync', '--check'])
|
|
174
|
+
expect(check.code).toBe(1)
|
|
175
|
+
expect(check.out).toContain('acme-db (excluded by project)')
|
|
176
|
+
const sync = run(dir, ['sync', '--yes'])
|
|
177
|
+
expect(sync.out.replace(/\x1b\[[0-9;]*m/g, '')).toMatch(/Removed \d MCP server\(s\) the team's layers retired or its policy does not allow: acme-db/)
|
|
178
|
+
expect(run(dir, ['sync', '--check']).code).toBe(0)
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
it('holds the lock back while an MCP config cannot be read, so a retired server is not forgotten', () => {
|
|
182
|
+
write(dir, { '.opencastle/config.json': JSON.stringify({ extends: ['@acme/base'] }) })
|
|
183
|
+
const lockBefore = readFileSync(join(dir, '.opencastle', 'lock.json'), 'utf8')
|
|
184
|
+
writeFileSync(join(dir, '.vscode', 'mcp.json'), '{ not json')
|
|
185
|
+
const sync = run(dir, ['sync', '--yes'])
|
|
186
|
+
expect(sync.out).toContain('Left .opencastle/lock.json as it was')
|
|
187
|
+
expect(readFileSync(join(dir, '.opencastle', 'lock.json'), 'utf8')).toBe(lockBefore)
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
it('says which integration servers the policy left out', () => {
|
|
191
|
+
const add = run(dir, ['add', 'sentry'])
|
|
192
|
+
expect(add.out.replace(/\x1b\[[0-9;]*m/g, '')).toMatch(/Left out 1 MCP server\(s\):\s+Sentry — not on the MCP allowlist of @acme\/base/)
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
it('writes the CI workflow and routes the lock to its owners', () => {
|
|
196
|
+
const ci = run(dir, ['ci', '--owners', '@acme/platform'])
|
|
197
|
+
expect(ci.code).toBe(0)
|
|
198
|
+
const workflow = readFileSync(join(dir, '.github', 'workflows', 'opencastle.yml'), 'utf8')
|
|
199
|
+
expect(workflow).toContain('sync --check')
|
|
200
|
+
expect(readFileSync(join(dir, '.github', 'CODEOWNERS'), 'utf8')).toContain('/.opencastle/lock.json @acme/platform')
|
|
201
|
+
expect(run(dir, ['ci']).code).toBe(1)
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
it('reads the fleet from committed locks', () => {
|
|
205
|
+
const fleet = JSON.parse(run(dir, ['fleet', dir, '--json']).out)
|
|
206
|
+
expect(fleet.versions['@acme/base']).toEqual({ '1.4.0': ['shop'] })
|
|
207
|
+
})
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
describe.skipIf(!built)('a baseline package', () => {
|
|
211
|
+
let dir: string
|
|
212
|
+
beforeEach(() => {
|
|
213
|
+
dir = mkdtempSync(join(tmpdir(), 'team-baseline-'))
|
|
214
|
+
})
|
|
215
|
+
afterEach(() => {
|
|
216
|
+
rmSync(dir, { recursive: true, force: true })
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
it('scaffolds one that passes its own check', () => {
|
|
220
|
+
expect(run(dir, ['baseline', 'init', 'base', '--name', '@acme/base']).code).toBe(0)
|
|
221
|
+
const pkg = JSON.parse(readFileSync(join(dir, 'base', 'package.json'), 'utf8'))
|
|
222
|
+
expect(pkg.opencastle).toEqual({ baseline: 'layer' })
|
|
223
|
+
const check = run(dir, ['baseline', 'check', 'base', '--json'])
|
|
224
|
+
expect(check.code).toBe(0)
|
|
225
|
+
const report = JSON.parse(check.out)
|
|
226
|
+
expect(report.errors).toEqual([])
|
|
227
|
+
expect(report.contributes).toMatchObject({ skills: 1, instructions: 1 })
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
it('fails one whose layer sits outside the package, as every consumer would', () => {
|
|
231
|
+
run(dir, ['baseline', 'init', 'base', '--name', '@acme/base'])
|
|
232
|
+
const path = join(dir, 'base', 'package.json')
|
|
233
|
+
const pkg = JSON.parse(readFileSync(path, 'utf8'))
|
|
234
|
+
pkg.opencastle.baseline = '../shared'
|
|
235
|
+
delete pkg.files
|
|
236
|
+
writeFileSync(path, JSON.stringify(pkg))
|
|
237
|
+
mkdirSync(join(dir, 'shared'), { recursive: true })
|
|
238
|
+
const check = run(dir, ['baseline', 'check', 'base'])
|
|
239
|
+
expect(check.code).toBe(1)
|
|
240
|
+
expect(check.out).toContain('points outside the package')
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
it('fails one that would publish empty', () => {
|
|
244
|
+
run(dir, ['baseline', 'init', 'base', '--name', '@acme/base'])
|
|
245
|
+
const path = join(dir, 'base', 'package.json')
|
|
246
|
+
const pkg = JSON.parse(readFileSync(path, 'utf8'))
|
|
247
|
+
pkg.files = ['README.md']
|
|
248
|
+
writeFileSync(path, JSON.stringify(pkg))
|
|
249
|
+
const check = run(dir, ['baseline', 'check', 'base'])
|
|
250
|
+
expect(check.code).toBe(1)
|
|
251
|
+
expect(check.out).toContain('npm publish would ship a baseline with nothing in it')
|
|
252
|
+
})
|
|
253
|
+
})
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import * as v from 'valibot'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The team's own source: `.opencastle/config.json`, and the same file at the
|
|
5
|
+
* root of every baseline it extends.
|
|
6
|
+
*
|
|
7
|
+
* Until this existed, OpenCastle compiled only its own content. A team could
|
|
8
|
+
* not write a skill, an instruction or an agent once and have every assistant
|
|
9
|
+
* receive it, which is the whole promise of a compiler — and could not share
|
|
10
|
+
* one standard across its repositories at all. A layer is a directory laid out
|
|
11
|
+
* like `.opencastle/`:
|
|
12
|
+
*
|
|
13
|
+
* config.json this file: extends, exclude, mcpServers, policy
|
|
14
|
+
* instructions/*.md always loaded, by every assistant
|
|
15
|
+
* agents/*.agent.md personas
|
|
16
|
+
* skills/<name>/SKILL.md on-demand knowledge, found by its description
|
|
17
|
+
* prompts/*.prompt.md reusable prompts / commands
|
|
18
|
+
* workflows/*.md multi-step workflow templates
|
|
19
|
+
*
|
|
20
|
+
* The project's `.opencastle/` is the top layer; `extends` puts baselines
|
|
21
|
+
* underneath it, and OpenCastle's own content sits at the bottom.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export const TEAM_CONFIG_REL = '.opencastle/config.json'
|
|
25
|
+
export const LAYER_CONFIG_FILE = 'config.json'
|
|
26
|
+
export const CONFIG_SCHEMA_URL = 'https://www.opencastle.dev/schema/config.json'
|
|
27
|
+
|
|
28
|
+
export const CONTENT_KINDS = ['instructions', 'agents', 'skills', 'prompts', 'workflows'] as const
|
|
29
|
+
export type ContentKind = (typeof CONTENT_KINDS)[number]
|
|
30
|
+
|
|
31
|
+
/** A problem found while reading or resolving team sources. */
|
|
32
|
+
export interface TeamIssue {
|
|
33
|
+
level: 'error' | 'warning'
|
|
34
|
+
/** The file or setting it is about, project-relative where possible. */
|
|
35
|
+
where: string
|
|
36
|
+
message: string
|
|
37
|
+
fix?: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/
|
|
41
|
+
export const ITEM_REF = new RegExp(`^(${CONTENT_KINDS.join('|')})/[A-Za-z0-9][A-Za-z0-9._-]*$`)
|
|
42
|
+
/** What `exclude` may name: content, or an MCP server a layer below defines. */
|
|
43
|
+
export const EXCLUDE_REF = new RegExp(`^(${[...CONTENT_KINDS, 'mcpServers'].join('|')})/[A-Za-z0-9][A-Za-z0-9._-]*$`)
|
|
44
|
+
|
|
45
|
+
const ItemRef = v.pipe(
|
|
46
|
+
v.string(),
|
|
47
|
+
v.regex(ITEM_REF, 'must name a kind and an item, e.g. "skills/seo-patterns" or "agents/content-engineer"'),
|
|
48
|
+
)
|
|
49
|
+
const ExcludeRef = v.pipe(
|
|
50
|
+
v.string(),
|
|
51
|
+
v.regex(EXCLUDE_REF, 'must name a kind and an item, e.g. "skills/seo-patterns" or "mcpServers/Slack"'),
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
const McpServer = v.strictObject({
|
|
55
|
+
type: v.optional(v.picklist(['stdio', 'http'])),
|
|
56
|
+
command: v.optional(v.pipe(v.string(), v.minLength(1))),
|
|
57
|
+
args: v.optional(v.array(v.string())),
|
|
58
|
+
url: v.optional(v.pipe(v.string(), v.regex(/^https?:\/\/\S+$/, 'must be an http(s) URL'))),
|
|
59
|
+
env: v.optional(v.record(v.string(), v.string())),
|
|
60
|
+
headers: v.optional(v.record(v.string(), v.string())),
|
|
61
|
+
description: v.optional(v.string()),
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const Policy = v.strictObject({
|
|
65
|
+
mcp: v.optional(
|
|
66
|
+
v.strictObject({
|
|
67
|
+
allow: v.optional(v.array(v.pipe(v.string(), v.minLength(1)))),
|
|
68
|
+
remoteHosts: v.optional(v.array(v.pipe(v.string(), v.minLength(1)))),
|
|
69
|
+
requirePinned: v.optional(v.boolean()),
|
|
70
|
+
}),
|
|
71
|
+
),
|
|
72
|
+
require: v.optional(v.array(ItemRef)),
|
|
73
|
+
contextBudget: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1))),
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
export const TeamConfigSchema = v.strictObject({
|
|
77
|
+
$schema: v.optional(v.string()),
|
|
78
|
+
opencastle: v.optional(v.pipe(v.string(), v.minLength(1))),
|
|
79
|
+
extends: v.optional(v.array(v.pipe(v.string(), v.minLength(1)))),
|
|
80
|
+
exclude: v.optional(v.array(ExcludeRef)),
|
|
81
|
+
mcpServers: v.optional(
|
|
82
|
+
v.record(v.pipe(v.string(), v.regex(NAME, 'server names are letters, digits, ".", "_" and "-"')), McpServer),
|
|
83
|
+
),
|
|
84
|
+
policy: v.optional(Policy),
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
export type TeamConfig = v.InferOutput<typeof TeamConfigSchema>
|
|
88
|
+
export type TeamMcpServer = NonNullable<TeamConfig['mcpServers']>[string]
|
|
89
|
+
export type TeamPolicy = NonNullable<TeamConfig['policy']>
|
|
90
|
+
|
|
91
|
+
/** Every key the schema knows, for "did you mean" on a typo. */
|
|
92
|
+
const KNOWN_KEYS = [
|
|
93
|
+
'$schema', 'opencastle', 'extends', 'exclude', 'mcpServers', 'policy',
|
|
94
|
+
'type', 'command', 'args', 'url', 'env', 'headers', 'description',
|
|
95
|
+
'mcp', 'allow', 'remoteHosts', 'requirePinned', 'require', 'contextBudget',
|
|
96
|
+
]
|
|
97
|
+
|
|
98
|
+
function distance(a: string, b: string): number {
|
|
99
|
+
const d: number[][] = Array.from({ length: a.length + 1 }, (_, i) => [i, ...Array(b.length).fill(0)])
|
|
100
|
+
for (let j = 1; j <= b.length; j++) d[0][j] = j
|
|
101
|
+
for (let i = 1; i <= a.length; i++) {
|
|
102
|
+
for (let j = 1; j <= b.length; j++) {
|
|
103
|
+
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1))
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return d[a.length][b.length]
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function suggest(key: string): string | undefined {
|
|
110
|
+
let best: string | undefined
|
|
111
|
+
let bestScore = Infinity
|
|
112
|
+
for (const k of KNOWN_KEYS) {
|
|
113
|
+
const s = distance(key.toLowerCase(), k.toLowerCase())
|
|
114
|
+
if (s < bestScore) {
|
|
115
|
+
best = k
|
|
116
|
+
bestScore = s
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return bestScore <= Math.max(2, Math.floor(key.length / 3)) ? best : undefined
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* JSON with comments and trailing commas, which is what people write in a
|
|
124
|
+
* config file their editor treats as JSONC. Rejecting a `//` comment in a file
|
|
125
|
+
* with a `$schema` line would punish exactly the teams who set it up properly.
|
|
126
|
+
*/
|
|
127
|
+
export function stripJsonc(text: string): string {
|
|
128
|
+
let out = ''
|
|
129
|
+
let i = 0
|
|
130
|
+
let inString = false
|
|
131
|
+
while (i < text.length) {
|
|
132
|
+
const ch = text[i]
|
|
133
|
+
if (inString) {
|
|
134
|
+
out += ch
|
|
135
|
+
if (ch === '\\') {
|
|
136
|
+
out += text[i + 1] ?? ''
|
|
137
|
+
i += 2
|
|
138
|
+
continue
|
|
139
|
+
}
|
|
140
|
+
if (ch === '"') inString = false
|
|
141
|
+
i++
|
|
142
|
+
continue
|
|
143
|
+
}
|
|
144
|
+
if (ch === '"') {
|
|
145
|
+
inString = true
|
|
146
|
+
out += ch
|
|
147
|
+
i++
|
|
148
|
+
continue
|
|
149
|
+
}
|
|
150
|
+
if (ch === '/' && text[i + 1] === '/') {
|
|
151
|
+
while (i < text.length && text[i] !== '\n') i++
|
|
152
|
+
continue
|
|
153
|
+
}
|
|
154
|
+
if (ch === '/' && text[i + 1] === '*') {
|
|
155
|
+
const end = text.indexOf('*/', i + 2)
|
|
156
|
+
// Newlines kept, so a JSON error's position still points at the right line.
|
|
157
|
+
const body = end === -1 ? text.slice(i) : text.slice(i, end + 2)
|
|
158
|
+
out += body.replace(/[^\n]/g, ' ')
|
|
159
|
+
i = end === -1 ? text.length : end + 2
|
|
160
|
+
continue
|
|
161
|
+
}
|
|
162
|
+
out += ch
|
|
163
|
+
i++
|
|
164
|
+
}
|
|
165
|
+
return dropTrailingCommas(out)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** A comma followed only by whitespace and a closing bracket, outside strings. */
|
|
169
|
+
function dropTrailingCommas(text: string): string {
|
|
170
|
+
let out = ''
|
|
171
|
+
let inString = false
|
|
172
|
+
for (let i = 0; i < text.length; i++) {
|
|
173
|
+
const ch = text[i]
|
|
174
|
+
if (inString) {
|
|
175
|
+
out += ch
|
|
176
|
+
if (ch === '\\') out += text[++i] ?? ''
|
|
177
|
+
else if (ch === '"') inString = false
|
|
178
|
+
continue
|
|
179
|
+
}
|
|
180
|
+
if (ch === '"') inString = true
|
|
181
|
+
if (ch === ',') {
|
|
182
|
+
let j = i + 1
|
|
183
|
+
while (j < text.length && /\s/.test(text[j])) j++
|
|
184
|
+
if (text[j] === '}' || text[j] === ']') continue
|
|
185
|
+
}
|
|
186
|
+
out += ch
|
|
187
|
+
}
|
|
188
|
+
return out
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Parse and validate one layer's config text. */
|
|
192
|
+
export function parseTeamConfig(text: string, where: string): { config: TeamConfig | null; issues: TeamIssue[] } {
|
|
193
|
+
let raw: unknown
|
|
194
|
+
try {
|
|
195
|
+
raw = JSON.parse(stripJsonc(text.replace(/^\uFEFF/, '')))
|
|
196
|
+
} catch (err) {
|
|
197
|
+
return {
|
|
198
|
+
config: null,
|
|
199
|
+
issues: [{ level: 'error', where, message: `is not valid JSON — ${(err as Error).message}`, fix: `fix the syntax in ${where}` }],
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
const result = v.safeParse(TeamConfigSchema, raw)
|
|
203
|
+
if (result.success) return { config: result.output, issues: [] }
|
|
204
|
+
|
|
205
|
+
const issues: TeamIssue[] = []
|
|
206
|
+
for (const issue of result.issues) {
|
|
207
|
+
const path = v.getDotPath(issue)
|
|
208
|
+
if (issue.type === 'strict_object' || issue.expected === 'never') {
|
|
209
|
+
// An unknown key. The default message is "Expected never", which says
|
|
210
|
+
// nothing to a person who typed `extend` instead of `extends`.
|
|
211
|
+
const key = String(issue.input === undefined ? path : (path ?? '').split('.').pop())
|
|
212
|
+
const bad = typeof issue.input === 'string' ? issue.input : key
|
|
213
|
+
const hint = suggest(bad)
|
|
214
|
+
issues.push({
|
|
215
|
+
level: 'error',
|
|
216
|
+
where,
|
|
217
|
+
message: `unknown setting "${path ?? bad}"`,
|
|
218
|
+
fix: hint ? `did you mean "${hint}"?` : `remove it, or see ${CONFIG_SCHEMA_URL}`,
|
|
219
|
+
})
|
|
220
|
+
continue
|
|
221
|
+
}
|
|
222
|
+
issues.push({ level: 'error', where, message: `${path ? `${path}: ` : ''}${issue.message}` })
|
|
223
|
+
}
|
|
224
|
+
return { config: null, issues }
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Variables an editor fills in itself. `${workspaceFolder}` is not an
|
|
229
|
+
* environment variable, and rewriting it as one — `${env:workspaceFolder}` for
|
|
230
|
+
* Cursor, a password prompt in VS Code — broke the path it named.
|
|
231
|
+
*/
|
|
232
|
+
export const EDITOR_VARIABLES = new Set([
|
|
233
|
+
'workspaceFolder',
|
|
234
|
+
'workspaceFolderBasename',
|
|
235
|
+
'workspaceRoot',
|
|
236
|
+
'userHome',
|
|
237
|
+
'pathSeparator',
|
|
238
|
+
'cwd',
|
|
239
|
+
'execPath',
|
|
240
|
+
'file',
|
|
241
|
+
'fileBasename',
|
|
242
|
+
'fileDirname',
|
|
243
|
+
'fileExtname',
|
|
244
|
+
'relativeFile',
|
|
245
|
+
'lineNumber',
|
|
246
|
+
'selectedText',
|
|
247
|
+
])
|
|
248
|
+
|
|
249
|
+
/** The environment variables a value refers to as `${NAME}`, editor variables aside. */
|
|
250
|
+
export function envNamesIn(value: string): string[] {
|
|
251
|
+
const out: string[] = []
|
|
252
|
+
for (const m of value.matchAll(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g)) {
|
|
253
|
+
if (!EDITOR_VARIABLES.has(m[1]) && !out.includes(m[1])) out.push(m[1])
|
|
254
|
+
}
|
|
255
|
+
return out
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** How a server launches: a URL means remote, a command means local. */
|
|
259
|
+
export function serverTransport(server: TeamMcpServer): 'stdio' | 'http' | null {
|
|
260
|
+
if (server.type) return server.type
|
|
261
|
+
if (server.url && !server.command) return 'http'
|
|
262
|
+
if (server.command && !server.url) return 'stdio'
|
|
263
|
+
return null
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** Shape problems a schema cannot express: exactly one of command or url. */
|
|
267
|
+
export function checkServerShape(key: string, server: TeamMcpServer, where: string): TeamIssue[] {
|
|
268
|
+
const t = serverTransport(server)
|
|
269
|
+
if (t === null) {
|
|
270
|
+
return [{
|
|
271
|
+
level: 'error',
|
|
272
|
+
where,
|
|
273
|
+
message: `mcpServers.${key} needs either "command" (a local server) or "url" (a remote one)`,
|
|
274
|
+
}]
|
|
275
|
+
}
|
|
276
|
+
if (t === 'stdio' && !server.command) {
|
|
277
|
+
return [{ level: 'error', where, message: `mcpServers.${key} is "stdio" but has no "command"` }]
|
|
278
|
+
}
|
|
279
|
+
if (t === 'http' && !server.url) {
|
|
280
|
+
return [{ level: 'error', where, message: `mcpServers.${key} is "http" but has no "url"` }]
|
|
281
|
+
}
|
|
282
|
+
if (t === 'stdio' && server.headers) {
|
|
283
|
+
return [{ level: 'error', where, message: `mcpServers.${key}: "headers" only apply to a remote ("url") server` }]
|
|
284
|
+
}
|
|
285
|
+
if (t === 'http' && (server.args || server.env)) {
|
|
286
|
+
return [{ level: 'error', where, message: `mcpServers.${key}: "args" and "env" only apply to a local ("command") server` }]
|
|
287
|
+
}
|
|
288
|
+
return []
|
|
289
|
+
}
|