opencastle 1.13.0 → 1.13.1
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/dist/cli/adapters/rules-dir-base.d.ts.map +1 -1
- package/dist/cli/adapters/rules-dir-base.js +8 -5
- 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 +25 -4
- package/dist/cli/adapters/single-file-base.js.map +1 -1
- package/dist/cli/adapters/vscode.d.ts.map +1 -1
- package/dist/cli/adapters/vscode.js +8 -5
- package/dist/cli/adapters/vscode.js.map +1 -1
- package/dist/cli/convoy/engine.d.ts.map +1 -1
- package/dist/cli/convoy/engine.git.test.js +206 -1
- package/dist/cli/convoy/engine.git.test.js.map +1 -1
- package/dist/cli/convoy/engine.js +116 -13
- package/dist/cli/convoy/engine.js.map +1 -1
- package/dist/cli/convoy/merge.d.ts +24 -5
- package/dist/cli/convoy/merge.d.ts.map +1 -1
- package/dist/cli/convoy/merge.js +108 -10
- package/dist/cli/convoy/merge.js.map +1 -1
- package/dist/cli/convoy/merge.test.js +59 -0
- package/dist/cli/convoy/merge.test.js.map +1 -1
- package/dist/cli/convoy/worktree.d.ts +6 -1
- package/dist/cli/convoy/worktree.d.ts.map +1 -1
- package/dist/cli/convoy/worktree.js +7 -0
- package/dist/cli/convoy/worktree.js.map +1 -1
- package/dist/cli/convoy/worktree.test.js +15 -1
- package/dist/cli/convoy/worktree.test.js.map +1 -1
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +23 -3
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/foreign-skills.d.ts +23 -0
- package/dist/cli/foreign-skills.d.ts.map +1 -1
- package/dist/cli/foreign-skills.js +91 -1
- package/dist/cli/foreign-skills.js.map +1 -1
- package/dist/cli/foreign-skills.test.js +95 -2
- package/dist/cli/foreign-skills.test.js.map +1 -1
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +17 -5
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/lock.d.ts +9 -0
- package/dist/cli/lock.d.ts.map +1 -1
- package/dist/cli/lock.js +16 -0
- package/dist/cli/lock.js.map +1 -1
- package/dist/cli/mcp-audit.d.ts +6 -3
- package/dist/cli/mcp-audit.d.ts.map +1 -1
- package/dist/cli/mcp-audit.js +22 -7
- package/dist/cli/mcp-audit.js.map +1 -1
- package/dist/cli/mcp-ownership.test.d.ts +2 -0
- package/dist/cli/mcp-ownership.test.d.ts.map +1 -0
- package/dist/cli/mcp-ownership.test.js +141 -0
- package/dist/cli/mcp-ownership.test.js.map +1 -0
- package/dist/cli/mcp.d.ts +36 -5
- package/dist/cli/mcp.d.ts.map +1 -1
- package/dist/cli/mcp.js +101 -33
- package/dist/cli/mcp.js.map +1 -1
- package/dist/cli/remove.d.ts.map +1 -1
- package/dist/cli/remove.js +4 -4
- package/dist/cli/remove.js.map +1 -1
- package/dist/cli/root-files.d.ts +59 -0
- package/dist/cli/root-files.d.ts.map +1 -0
- package/dist/cli/root-files.js +133 -0
- package/dist/cli/root-files.js.map +1 -0
- package/dist/cli/root-files.test.d.ts +2 -0
- package/dist/cli/root-files.test.d.ts.map +1 -0
- package/dist/cli/root-files.test.js +152 -0
- package/dist/cli/root-files.test.js.map +1 -0
- package/dist/cli/sync-check.d.ts +1 -1
- package/dist/cli/sync-check.d.ts.map +1 -1
- package/dist/cli/sync-check.js +19 -4
- package/dist/cli/sync-check.js.map +1 -1
- package/dist/cli/team-ci.test.js +8 -1
- package/dist/cli/team-ci.test.js.map +1 -1
- package/dist/cli/unreadable-report.d.ts.map +1 -1
- package/dist/cli/unreadable-report.js +3 -0
- package/dist/cli/unreadable-report.js.map +1 -1
- package/dist/cli/update.d.ts.map +1 -1
- package/dist/cli/update.js +33 -8
- package/dist/cli/update.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/adapters/rules-dir-base.ts +6 -5
- package/src/cli/adapters/single-file-base.ts +25 -4
- package/src/cli/adapters/vscode.ts +10 -6
- package/src/cli/convoy/engine.git.test.ts +227 -1
- package/src/cli/convoy/engine.ts +112 -12
- package/src/cli/convoy/merge.test.ts +72 -0
- package/src/cli/convoy/merge.ts +128 -15
- package/src/cli/convoy/worktree.test.ts +16 -1
- package/src/cli/convoy/worktree.ts +13 -3
- package/src/cli/doctor.ts +23 -1
- package/src/cli/foreign-skills.test.ts +111 -2
- package/src/cli/foreign-skills.ts +93 -1
- package/src/cli/init.ts +15 -5
- package/src/cli/lock.ts +18 -0
- package/src/cli/mcp-audit.ts +22 -6
- package/src/cli/mcp-ownership.test.ts +167 -0
- package/src/cli/mcp.ts +104 -29
- package/src/cli/remove.ts +4 -3
- package/src/cli/root-files.test.ts +169 -0
- package/src/cli/root-files.ts +140 -0
- package/src/cli/sync-check.ts +20 -5
- package/src/cli/team-ci.test.ts +8 -1
- package/src/cli/unreadable-report.ts +3 -0
- package/src/cli/update.ts +30 -7
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A root instruction file that is a link: `CLAUDE.md -> AGENTS.md`, the usual
|
|
3
|
+
* way to keep one file for every assistant, or the other way round. With Claude Code and Codex both
|
|
4
|
+
* selected, `sync` wrote one block and then the other into the same file on
|
|
5
|
+
* every run, and `sync --check` could never pass. A committed link out of the
|
|
6
|
+
* project made `init` append to whatever it pointed at.
|
|
7
|
+
*/
|
|
8
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
|
9
|
+
import { spawnSync, execFileSync } from 'node:child_process'
|
|
10
|
+
import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
|
|
11
|
+
import { tmpdir } from 'node:os'
|
|
12
|
+
import { join, resolve } from 'node:path'
|
|
13
|
+
import { IDE_ADAPTERS } from './adapters/index.js'
|
|
14
|
+
import { ROOT_FILES, WRITER_ORDER, rootFileLink } from './root-files.js'
|
|
15
|
+
import { countManagedBlocks } from './managed-block.js'
|
|
16
|
+
import type { IdeChoice } from './types.js'
|
|
17
|
+
|
|
18
|
+
describe('each target’s root file', () => {
|
|
19
|
+
it('is the one its adapter declares', async () => {
|
|
20
|
+
for (const [ide, file] of Object.entries(ROOT_FILES)) {
|
|
21
|
+
const merged = (await IDE_ADAPTERS[ide as IdeChoice]()).getManagedPaths().merged ?? []
|
|
22
|
+
expect(merged, ide).toContain(file)
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('has its place in the order that picks who writes a file several of them are', () => {
|
|
27
|
+
expect([...new Set(Object.values(ROOT_FILES))].sort()).toEqual([...WRITER_ORDER].sort())
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
describe('rootFileLink', () => {
|
|
32
|
+
let root: string
|
|
33
|
+
beforeEach(() => {
|
|
34
|
+
root = realpathSync(mkdtempSync(join(tmpdir(), 'oc-root-link-')))
|
|
35
|
+
mkdirSync(join(root, 'repo'))
|
|
36
|
+
writeFileSync(join(root, 'repo', 'AGENTS.md'), '# notes\n')
|
|
37
|
+
writeFileSync(join(root, 'outside.md'), '# elsewhere\n')
|
|
38
|
+
})
|
|
39
|
+
afterEach(() => rmSync(root, { recursive: true, force: true }))
|
|
40
|
+
const repo = (): string => join(root, 'repo')
|
|
41
|
+
|
|
42
|
+
it('is the file’s own to write when it is not a link, or links to a file no selected target writes', () => {
|
|
43
|
+
expect(rootFileLink(repo(), join(repo(), 'AGENTS.md'), ['codex'])).toEqual({ kind: 'own' })
|
|
44
|
+
expect(rootFileLink(repo(), join(repo(), 'CLAUDE.md'), ['claude-code'])).toEqual({ kind: 'own' })
|
|
45
|
+
symlinkSync('AGENTS.md', join(repo(), 'CLAUDE.md'))
|
|
46
|
+
expect(rootFileLink(repo(), join(repo(), 'CLAUDE.md'), ['claude-code'])).toEqual({ kind: 'own' })
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('is the other target’s when it links to that target’s root file', () => {
|
|
50
|
+
symlinkSync('AGENTS.md', join(repo(), 'CLAUDE.md'))
|
|
51
|
+
expect(rootFileLink(repo(), join(repo(), 'CLAUDE.md'), ['claude-code', 'codex'])).toEqual({ kind: 'shared', file: 'AGENTS.md', ide: 'codex' })
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('is AGENTS.md’s to write when AGENTS.md is the link and CLAUDE.md the file', () => {
|
|
55
|
+
rmSync(join(repo(), 'AGENTS.md'))
|
|
56
|
+
writeFileSync(join(repo(), 'CLAUDE.md'), '# notes\n')
|
|
57
|
+
symlinkSync('CLAUDE.md', join(repo(), 'AGENTS.md'))
|
|
58
|
+
const ides = ['claude-code', 'codex']
|
|
59
|
+
expect(rootFileLink(repo(), join(repo(), 'CLAUDE.md'), ides)).toEqual({ kind: 'shared', file: 'AGENTS.md', ide: 'codex' })
|
|
60
|
+
expect(rootFileLink(repo(), join(repo(), 'AGENTS.md'), ides)).toEqual({ kind: 'own' })
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('is never a pointer’s to write into the file it points to', () => {
|
|
64
|
+
// .cursorrules says "the instructions are in CLAUDE.md": written into
|
|
65
|
+
// CLAUDE.md itself, Claude Code would read only that.
|
|
66
|
+
writeFileSync(join(repo(), 'CLAUDE.md'), '# notes\n')
|
|
67
|
+
symlinkSync('CLAUDE.md', join(repo(), '.cursorrules'))
|
|
68
|
+
const ides = ['cursor', 'claude-code']
|
|
69
|
+
expect(rootFileLink(repo(), join(repo(), 'CLAUDE.md'), ides)).toEqual({ kind: 'own' })
|
|
70
|
+
expect(rootFileLink(repo(), join(repo(), '.cursorrules'), ides)).toEqual({ kind: 'shared', file: 'CLAUDE.md', ide: 'claude-code' })
|
|
71
|
+
// GEMINI.md says the same of AGENTS.md.
|
|
72
|
+
symlinkSync('AGENTS.md', join(repo(), 'GEMINI.md'))
|
|
73
|
+
expect(rootFileLink(repo(), join(repo(), 'AGENTS.md'), ['antigravity', 'codex'])).toEqual({ kind: 'own' })
|
|
74
|
+
expect(rootFileLink(repo(), join(repo(), 'GEMINI.md'), ['antigravity', 'codex'])).toEqual({ kind: 'shared', file: 'AGENTS.md', ide: 'codex' })
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('is the other target’s when it links to a root file not written yet', () => {
|
|
78
|
+
rmSync(join(repo(), 'AGENTS.md'))
|
|
79
|
+
symlinkSync('AGENTS.md', join(repo(), 'CLAUDE.md'))
|
|
80
|
+
expect(rootFileLink(repo(), join(repo(), 'CLAUDE.md'), ['claude-code', 'codex'])).toEqual({ kind: 'shared', file: 'AGENTS.md', ide: 'codex' })
|
|
81
|
+
expect(rootFileLink(repo(), join(repo(), 'AGENTS.md'), ['claude-code', 'codex'])).toEqual({ kind: 'own' })
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('is nobody’s when it leads out of the project, dangling or not', () => {
|
|
85
|
+
symlinkSync('../outside.md', join(repo(), 'CLAUDE.md'))
|
|
86
|
+
expect(rootFileLink(repo(), join(repo(), 'CLAUDE.md'), ['claude-code']).kind).toBe('outside')
|
|
87
|
+
symlinkSync('../nowhere.md', join(repo(), 'GEMINI.md'))
|
|
88
|
+
expect(rootFileLink(repo(), join(repo(), 'GEMINI.md'), ['antigravity']).kind).toBe('outside')
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
const repoRoot = resolve(import.meta.dirname, '..', '..')
|
|
93
|
+
const cli = join(repoRoot, 'bin', 'cli.mjs')
|
|
94
|
+
const cliBuilt = existsSync(join(repoRoot, 'dist', 'cli', 'init.js'))
|
|
95
|
+
|
|
96
|
+
describe.skipIf(!cliBuilt)('CLAUDE.md as a link', () => {
|
|
97
|
+
let base: string
|
|
98
|
+
let projectRoot: string
|
|
99
|
+
const run = (...args: string[]): { status: number | null; out: string } => {
|
|
100
|
+
const r = spawnSync('node', [cli, ...args], { cwd: projectRoot, encoding: 'utf8', input: '' })
|
|
101
|
+
return { status: r.status, out: `${r.stdout}${r.stderr}` }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
beforeEach(() => {
|
|
105
|
+
base = mkdtempSync(join(tmpdir(), 'oc-root-link-cli-'))
|
|
106
|
+
projectRoot = join(base, 'repo')
|
|
107
|
+
mkdirSync(projectRoot)
|
|
108
|
+
execFileSync('git', ['init', '-q'], { cwd: projectRoot })
|
|
109
|
+
writeFileSync(join(projectRoot, 'package.json'), JSON.stringify({ name: 'demo' }))
|
|
110
|
+
})
|
|
111
|
+
afterEach(() => rmSync(base, { recursive: true, force: true }))
|
|
112
|
+
|
|
113
|
+
it('to AGENTS.md, with Claude Code and Codex: one block, and the check stays green sync after sync', () => {
|
|
114
|
+
writeFileSync(join(projectRoot, 'AGENTS.md'), '# Team notes\n\nUse pnpm.\n')
|
|
115
|
+
symlinkSync('AGENTS.md', join(projectRoot, 'CLAUDE.md'))
|
|
116
|
+
mkdirSync(join(projectRoot, '.claude'))
|
|
117
|
+
mkdirSync(join(projectRoot, '.codex'))
|
|
118
|
+
expect(run('init', '--yes').status).toBe(0)
|
|
119
|
+
expect(JSON.parse(readFileSync(join(projectRoot, '.opencastle/manifest.json'), 'utf8')).ides.sort()).toEqual(['claude-code', 'codex'])
|
|
120
|
+
|
|
121
|
+
for (let i = 0; i < 2; i++) {
|
|
122
|
+
const sync = run('sync', '--yes')
|
|
123
|
+
expect(sync.status).toBe(0)
|
|
124
|
+
expect(sync.out).toContain('Everything matches its sources')
|
|
125
|
+
}
|
|
126
|
+
expect(run('sync', '--check').status).toBe(0)
|
|
127
|
+
expect(lstatSync(join(projectRoot, 'CLAUDE.md')).isSymbolicLink()).toBe(true)
|
|
128
|
+
const text = readFileSync(join(projectRoot, 'AGENTS.md'), 'utf8')
|
|
129
|
+
expect(text.startsWith('# Team notes\n\nUse pnpm.\n')).toBe(true)
|
|
130
|
+
expect(countManagedBlocks(text)).toBe(1)
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
it('the other way, AGENTS.md to CLAUDE.md: one block, the complete one, and the check stays green', () => {
|
|
134
|
+
writeFileSync(join(projectRoot, 'CLAUDE.md'), '# Team notes\n\nUse pnpm.\n')
|
|
135
|
+
symlinkSync('CLAUDE.md', join(projectRoot, 'AGENTS.md'))
|
|
136
|
+
mkdirSync(join(projectRoot, '.claude'))
|
|
137
|
+
mkdirSync(join(projectRoot, '.codex'))
|
|
138
|
+
expect(run('init', '--yes').status).toBe(0)
|
|
139
|
+
expect(JSON.parse(readFileSync(join(projectRoot, '.opencastle/manifest.json'), 'utf8')).ides.sort()).toEqual(['claude-code', 'codex'])
|
|
140
|
+
|
|
141
|
+
for (let i = 0; i < 2; i++) {
|
|
142
|
+
const sync = run('sync', '--yes')
|
|
143
|
+
expect(sync.status).toBe(0)
|
|
144
|
+
expect(sync.out).toContain('Everything matches its sources')
|
|
145
|
+
}
|
|
146
|
+
expect(run('sync', '--check').status).toBe(0)
|
|
147
|
+
expect(lstatSync(join(projectRoot, 'AGENTS.md')).isSymbolicLink()).toBe(true)
|
|
148
|
+
const text = readFileSync(join(projectRoot, 'CLAUDE.md'), 'utf8')
|
|
149
|
+
expect(text.startsWith('# Team notes\n\nUse pnpm.\n')).toBe(true)
|
|
150
|
+
expect(countManagedBlocks(text)).toBe(1)
|
|
151
|
+
// Codex's block, with the agent and skill indexes Claude Code's leaves out.
|
|
152
|
+
expect(text).toContain('## Available Skills')
|
|
153
|
+
expect(run('doctor').status).toBe(0)
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
it('out of the project: never written, and named', () => {
|
|
157
|
+
writeFileSync(join(base, 'outside.md'), '# Shared outside\n')
|
|
158
|
+
symlinkSync('../outside.md', join(projectRoot, 'CLAUDE.md'))
|
|
159
|
+
mkdirSync(join(projectRoot, '.claude'))
|
|
160
|
+
const init = run('init', '--yes')
|
|
161
|
+
expect(init.status).toBe(0)
|
|
162
|
+
expect(init.out).toContain('Left CLAUDE.md alone — it is a link to a file outside the project')
|
|
163
|
+
expect(readFileSync(join(base, 'outside.md'), 'utf8')).toBe('# Shared outside\n')
|
|
164
|
+
expect(run('sync', '--force', '--yes').status).toBe(0)
|
|
165
|
+
expect(readFileSync(join(base, 'outside.md'), 'utf8')).toBe('# Shared outside\n')
|
|
166
|
+
expect(run('sync', '--check').status).toBe(0)
|
|
167
|
+
expect(run('doctor').out).toContain('outside the project, so sync leaves it alone')
|
|
168
|
+
})
|
|
169
|
+
})
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { lstatSync, readlinkSync, realpathSync } from 'node:fs'
|
|
2
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
3
|
+
import { writeManagedBlock, type MergeResult } from './managed-block.js'
|
|
4
|
+
import type { CopyResults, IdeChoice } from './types.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Root instruction files written through a symbolic link.
|
|
8
|
+
*
|
|
9
|
+
* `CLAUDE.md -> AGENTS.md` is a common way to keep one file for every
|
|
10
|
+
* assistant, and nothing here looked at it. With Claude Code and Codex both
|
|
11
|
+
* selected, `sync` wrote Claude Code's block through the link and then Codex's
|
|
12
|
+
* over it in the same file, every run: "Updated 2 framework files" each time,
|
|
13
|
+
* and `sync --check` failing for good, since it compiles each target apart and
|
|
14
|
+
* expected both blocks in one file. A committed link that leaves the project
|
|
15
|
+
* made `init` append to whatever it pointed at.
|
|
16
|
+
*
|
|
17
|
+
* When a link makes two selected targets' root files one file, whichever way
|
|
18
|
+
* it points, one of them writes it: the one whose block is most complete
|
|
19
|
+
* (`WRITER_ORDER`), so every assistant reading the file gets the whole of it.
|
|
20
|
+
* One that leads outside the project is not written at all.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Each target's root instruction file, as its adapter declares it among its
|
|
25
|
+
* `merged` paths. Opencode and Codex share AGENTS.md as one real file, which
|
|
26
|
+
* `SHARED_ROOT_OWNERS` already handles. `root-files.test.ts` holds this to the
|
|
27
|
+
* adapters.
|
|
28
|
+
*/
|
|
29
|
+
export const ROOT_FILES: Record<IdeChoice, string> = {
|
|
30
|
+
vscode: '.github/copilot-instructions.md',
|
|
31
|
+
cursor: '.cursorrules',
|
|
32
|
+
windsurf: '.windsurfrules',
|
|
33
|
+
'claude-code': 'CLAUDE.md',
|
|
34
|
+
opencode: 'AGENTS.md',
|
|
35
|
+
codex: 'AGENTS.md',
|
|
36
|
+
antigravity: 'GEMINI.md',
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Who writes a file that several selected targets' root files are. The full
|
|
41
|
+
* blocks first: AGENTS.md carries the instructions and the agent and skill
|
|
42
|
+
* indexes, CLAUDE.md the instructions. Then those that point to a target's
|
|
43
|
+
* rule folder. Last, those that point to another root file — GEMINI.md to
|
|
44
|
+
* AGENTS.md, .cursorrules to CLAUDE.md — which, written into the very file
|
|
45
|
+
* they name, would point to themselves.
|
|
46
|
+
*/
|
|
47
|
+
export const WRITER_ORDER: readonly string[] = [
|
|
48
|
+
'AGENTS.md',
|
|
49
|
+
'CLAUDE.md',
|
|
50
|
+
'.github/copilot-instructions.md',
|
|
51
|
+
'.windsurfrules',
|
|
52
|
+
'GEMINI.md',
|
|
53
|
+
'.cursorrules',
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
export type RootFileLink =
|
|
57
|
+
/** No other selected target's root file is the same file, or this one writes it. */
|
|
58
|
+
| { kind: 'own' }
|
|
59
|
+
/** The same file as `file`, the root file `ide` writes: that one writes it. */
|
|
60
|
+
| { kind: 'shared'; file: string; ide: IdeChoice }
|
|
61
|
+
/** A link that leads to `to`, outside the project. */
|
|
62
|
+
| { kind: 'outside'; to: string }
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The file a write to `path` lands in: through every link, to where a dangling
|
|
66
|
+
* one would create it, or `path` itself when there is nothing there yet.
|
|
67
|
+
*/
|
|
68
|
+
function landsIn(path: string): string {
|
|
69
|
+
try {
|
|
70
|
+
return realpathSync(path)
|
|
71
|
+
} catch {
|
|
72
|
+
// Not there, or a dangling link.
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
if (lstatSync(path).isSymbolicLink()) return resolve(dirname(path), readlinkSync(path))
|
|
76
|
+
} catch {
|
|
77
|
+
// Nothing there.
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
return join(realpathSync(dirname(path)), basename(path))
|
|
81
|
+
} catch {
|
|
82
|
+
return resolve(path)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** What `path` is, as a root file `ides` are compiled into. */
|
|
87
|
+
export function rootFileLink(projectRoot: string, path: string, ides: readonly string[] | undefined): RootFileLink {
|
|
88
|
+
let isLink = false
|
|
89
|
+
try {
|
|
90
|
+
isLink = lstatSync(path).isSymbolicLink()
|
|
91
|
+
} catch {
|
|
92
|
+
// Not there yet: it can still be where another target's link leads.
|
|
93
|
+
}
|
|
94
|
+
const target = landsIn(path)
|
|
95
|
+
if (isLink) {
|
|
96
|
+
let root = projectRoot
|
|
97
|
+
try {
|
|
98
|
+
root = realpathSync(projectRoot)
|
|
99
|
+
} catch {
|
|
100
|
+
// Compared as given.
|
|
101
|
+
}
|
|
102
|
+
const rel = relative(root, target)
|
|
103
|
+
if (rel === '' || rel.startsWith('..') || isAbsolute(rel)) return { kind: 'outside', to: target }
|
|
104
|
+
}
|
|
105
|
+
// The selected targets' root files that are this same file, either way the
|
|
106
|
+
// link points.
|
|
107
|
+
const same = new Map<string, IdeChoice>()
|
|
108
|
+
for (const ide of ides ?? []) {
|
|
109
|
+
const file = ROOT_FILES[ide as IdeChoice]
|
|
110
|
+
if (!file || same.has(file)) continue
|
|
111
|
+
if (landsIn(join(projectRoot, file)) === target) same.set(file, ide as IdeChoice)
|
|
112
|
+
}
|
|
113
|
+
const mine = relative(projectRoot, path).split(sep).join('/')
|
|
114
|
+
same.delete(mine)
|
|
115
|
+
if (same.size === 0) return { kind: 'own' }
|
|
116
|
+
const writer = WRITER_ORDER.find((file) => file === mine || same.has(file))
|
|
117
|
+
if (!writer || writer === mine) return { kind: 'own' }
|
|
118
|
+
return { kind: 'shared', file: writer, ide: same.get(writer)! }
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Write a target's root file block, unless the file is a link another
|
|
123
|
+
* selected target writes or that leads outside the project. Null when nothing
|
|
124
|
+
* was written; a link outside the project is named in `results.unreadable`.
|
|
125
|
+
*/
|
|
126
|
+
export async function writeRootBlock(
|
|
127
|
+
projectRoot: string,
|
|
128
|
+
path: string,
|
|
129
|
+
body: string,
|
|
130
|
+
ides: readonly string[] | undefined,
|
|
131
|
+
results: CopyResults,
|
|
132
|
+
): Promise<MergeResult | null> {
|
|
133
|
+
const link = rootFileLink(projectRoot, path, ides)
|
|
134
|
+
if (link.kind === 'shared') return null
|
|
135
|
+
if (link.kind === 'outside') {
|
|
136
|
+
;(results.unreadable ??= []).push(`${path}\u0000outside`)
|
|
137
|
+
return null
|
|
138
|
+
}
|
|
139
|
+
return writeManagedBlock(path, body)
|
|
140
|
+
}
|
package/src/cli/sync-check.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { resolveStack, getIncludedMcpServers } from './stack-config.js'
|
|
|
13
13
|
import { auditMcpConfig, describeFindingUnder, remedyFor, isFailure, type TeamAuditContext } from './mcp-audit.js'
|
|
14
14
|
import { resolveSources, materialize, hasErrors, cliVersionOf, type CompileSource } from './layers.js'
|
|
15
15
|
import { parseVersion, compareVersions } from './version-range.js'
|
|
16
|
-
import { buildLock, serializeLock, LOCK_REL, priorTeam } from './lock.js'
|
|
16
|
+
import { buildLock, serializeLock, LOCK_REL, priorTeam, priorIntegrations } from './lock.js'
|
|
17
17
|
import { PLUGINS } from '../orchestrator/plugins/index.js'
|
|
18
18
|
import { gitignoreNeedsRebuild } from './gitignore.js'
|
|
19
19
|
import {
|
|
@@ -25,7 +25,8 @@ import {
|
|
|
25
25
|
diagnoseManagedFile,
|
|
26
26
|
} from './managed-block.js'
|
|
27
27
|
import { c } from './prompt.js'
|
|
28
|
-
import { foreignSkills, skillFolders } from './foreign-skills.js'
|
|
28
|
+
import { foreignSkills, skillFolders, foreignAgents, agentFolders } from './foreign-skills.js'
|
|
29
|
+
import { rootFileLink } from './root-files.js'
|
|
29
30
|
import { reportToGitHub, COMPARISON_FAILED } from './github-report.js'
|
|
30
31
|
import type { CliContext, IdeChoice, StackConfig } from './types.js'
|
|
31
32
|
|
|
@@ -66,7 +67,7 @@ export interface Drift {
|
|
|
66
67
|
* parse, a baseline that is not installed, a policy the sources break. The
|
|
67
68
|
* comparison cannot run until it is fixed, and `sync` refuses to compile.
|
|
68
69
|
*
|
|
69
|
-
* `foreign` is a skill another tool wrote into a compiled folder, which
|
|
70
|
+
* `foreign` is a skill or agent another tool wrote into a compiled folder, which
|
|
70
71
|
* `sync` keeps by moving it into the team's sources (foreign-skills.ts).
|
|
71
72
|
*/
|
|
72
73
|
origin?: 'mcp' | 'team' | 'version' | 'memory' | 'foreign'
|
|
@@ -368,6 +369,13 @@ async function compareProject(
|
|
|
368
369
|
// most likely to be edited by hand, would be the only thing never checked.
|
|
369
370
|
const managed = adapter.getManagedPaths()
|
|
370
371
|
for (const managedPath of [...managed.framework, ...(managed.merged ?? [])]) {
|
|
372
|
+
// A root file that is a link to another selected target's root file is
|
|
373
|
+
// that target's to write and is compared there; one leading out of the
|
|
374
|
+
// project is not written at all (root-files.ts).
|
|
375
|
+
if (
|
|
376
|
+
(managed.merged ?? []).includes(managedPath) &&
|
|
377
|
+
rootFileLink(projectRoot, resolve(projectRoot, managedPath), ides).kind !== 'own'
|
|
378
|
+
) continue
|
|
371
379
|
checked += comparePath(managedPath, scratch, projectRoot, ide, drift, adapter.ownsFile
|
|
372
380
|
? (rel) => adapter.ownsFile!(rel, projectRoot)
|
|
373
381
|
: undefined)
|
|
@@ -398,6 +406,13 @@ async function compareProject(
|
|
|
398
406
|
d.detail = `added by another tool — sync moves it into .opencastle/skills/${skill.name}/`
|
|
399
407
|
}
|
|
400
408
|
}
|
|
409
|
+
for (const agent of foreignAgents(projectRoot, agentFolders(framework), new Set(resolved.items.keys()))) {
|
|
410
|
+
for (const d of drift) {
|
|
411
|
+
if (d.kind !== 'extra' || d.path !== agent.from) continue
|
|
412
|
+
d.origin = 'foreign'
|
|
413
|
+
d.detail = `added by another tool — sync moves it into .opencastle/agents/${agent.name}.agent.md`
|
|
414
|
+
}
|
|
415
|
+
}
|
|
401
416
|
}
|
|
402
417
|
|
|
403
418
|
// The lock: what every assistant is given, as `sync` would record it now.
|
|
@@ -596,7 +611,7 @@ async function compareProject(
|
|
|
596
611
|
// the two cannot disagree: `doctor` failed on a remote server Claude Code
|
|
597
612
|
// never loads while this reported every file matching its source, and CI —
|
|
598
613
|
// the one place a team would see it — stayed green.
|
|
599
|
-
const audit = auditMcpConfig(parsed, ide as IdeChoice, included, team)
|
|
614
|
+
const audit = auditMcpConfig(parsed, ide as IdeChoice, included, team, priorIntegrations(projectRoot))
|
|
600
615
|
// Everything `sync` would change in the file, in one entry: entries it
|
|
601
616
|
// moves forward, and plugin servers the stack dropped, which it deletes.
|
|
602
617
|
// Leaving the second out let `doctor` say "sync removes it" while this
|
|
@@ -792,7 +807,7 @@ function render(report: CheckReport): void {
|
|
|
792
807
|
const kept = extra.filter((d) => d.origin === 'foreign')
|
|
793
808
|
const swept = extra.filter((d) => d.origin !== 'foreign')
|
|
794
809
|
if (kept.length > 0) {
|
|
795
|
-
console.log(` ${c.bold('Skills another tool added')} ${c.dim('(the next sync keeps them: moved into .opencastle/
|
|
810
|
+
console.log(` ${c.bold('Skills and agents another tool added')} ${c.dim('(the next sync keeps them: moved into .opencastle/ and compiled for every assistant)')}`)
|
|
796
811
|
for (const d of kept) console.log(` ${c.green('+')} ${d.path} ${c.dim(`(${d.ide})`)}`)
|
|
797
812
|
console.log('')
|
|
798
813
|
}
|
package/src/cli/team-ci.test.ts
CHANGED
|
@@ -97,7 +97,14 @@ describe.skipIf(!built)('a stale MCP default is fixed by the command doctor name
|
|
|
97
97
|
})
|
|
98
98
|
|
|
99
99
|
it('a plugin server the stack dropped: doctor, CI and sync agree it goes', () => {
|
|
100
|
-
// An old Figma default in a project whose stack has no Figma.
|
|
100
|
+
// An old Figma default in a project whose stack has no Figma any more. The
|
|
101
|
+
// lock says the last compile gave the project Figma: without that it would
|
|
102
|
+
// be an entry someone added by hand under the integration's name, which is
|
|
103
|
+
// theirs (mcp-ownership.test.ts).
|
|
104
|
+
const lockPath = join(dir, '.opencastle', 'lock.json')
|
|
105
|
+
const lock = JSON.parse(readFileSync(lockPath, 'utf8'))
|
|
106
|
+
lock.mcp.Figma = { from: 'plugin:figma', transport: 'stdio', launch: 'npx -y @anthropic/figma-mcp@latest', env: ['FIGMA_ACCESS_TOKEN'] }
|
|
107
|
+
writeFileSync(lockPath, JSON.stringify(lock, null, 2) + '\n')
|
|
101
108
|
const config = JSON.parse(readFileSync(join(dir, '.mcp.json'), 'utf8'))
|
|
102
109
|
config.mcpServers.Figma = {
|
|
103
110
|
command: 'npx',
|
|
@@ -22,6 +22,9 @@
|
|
|
22
22
|
*/
|
|
23
23
|
export function whyLeftAlone(name: string, why: string | undefined): string {
|
|
24
24
|
if (why === 'unreadable') return 'it could not be read.'
|
|
25
|
+
if (why === 'outside') {
|
|
26
|
+
return 'it is a link to a file outside the project, and OpenCastle writes only inside it. Make it a file, or a link within the project.'
|
|
27
|
+
}
|
|
25
28
|
if (why === 'uneditable') {
|
|
26
29
|
return 'its MCP servers are written in a form this cannot change without rewriting yours — give each one its own [mcp_servers.<name>] table.'
|
|
27
30
|
}
|
package/src/cli/update.ts
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
updateSkillMatrixFile,
|
|
12
12
|
resolveStack,
|
|
13
13
|
getCustomizationsTransform,
|
|
14
|
-
isEnvVarSatisfied, isPreselected, envFileTextFor } from './stack-config.js'
|
|
14
|
+
isEnvVarSatisfied, isPreselected, envFileTextFor, getIncludedMcpServers } from './stack-config.js'
|
|
15
15
|
import { rebuildMcpConfig, getMcpConfigRelPath, retireLegacyMcpConfig, LEGACY_MCP_CONFIGS } from './mcp.js'
|
|
16
16
|
import { updateGitignore, LOCAL_DIRS } from './gitignore.js'
|
|
17
17
|
import { resolveManagedPaths, REQUIRED_CUSTOMIZATIONS } from './managed-paths.js'
|
|
@@ -28,8 +28,8 @@ import {
|
|
|
28
28
|
requiredEnvVars,
|
|
29
29
|
type ResolvedSources,
|
|
30
30
|
} from './layers.js'
|
|
31
|
-
import { buildLock, writeLock, readLock, LOCK_REL, priorTeam } from './lock.js'
|
|
32
|
-
import { adoptForeignSkills, foreignSkills, skillFolders } from './foreign-skills.js'
|
|
31
|
+
import { buildLock, writeLock, readLock, LOCK_REL, priorTeam, priorIntegrations } from './lock.js'
|
|
32
|
+
import { adoptForeignSkills, foreignSkills, skillFolders, adoptForeignAgents, foreignAgents, agentFolders } from './foreign-skills.js'
|
|
33
33
|
import { parseVersion, compareVersions } from './version-range.js'
|
|
34
34
|
import { COMMAND_NAMESPACE } from './command-namespace.js'
|
|
35
35
|
import { parseMcpConfigText } from './mcp-file.js'
|
|
@@ -192,6 +192,9 @@ export default async function update({
|
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
+
// Agent files kept as the team's below: the compile writes each under its
|
|
196
|
+
// `.agent.md` name, so the sweep removes the original, already copied.
|
|
197
|
+
const adoptedAgents = new Set<string>()
|
|
195
198
|
// The team's sources, checked before anything is written. A baseline that is
|
|
196
199
|
// not installed or a server the policy forbids is a compile error: better no
|
|
197
200
|
// output than output that quietly leaves the team's standard out.
|
|
@@ -241,6 +244,19 @@ export default async function update({
|
|
|
241
244
|
)
|
|
242
245
|
for (const s of foreign) console.log(` ${c.dim(`${s.from} → .opencastle/skills/${s.name}`)}`)
|
|
243
246
|
}
|
|
247
|
+
// Agents the same way: a subagent made with the assistant's own command
|
|
248
|
+
// was deleted by the sweep below, with no copy anywhere.
|
|
249
|
+
const agents = foreignAgents(projectRoot, agentFolders(framework), new Set(early.items.keys()))
|
|
250
|
+
if (agents.length > 0) {
|
|
251
|
+
const dry = args.includes('--dry-run') || args.includes('--dryRun')
|
|
252
|
+
if (!dry) adoptForeignAgents(projectRoot, agents)
|
|
253
|
+
for (const a of agents) adoptedAgents.add(a.from)
|
|
254
|
+
console.log(
|
|
255
|
+
` ${c.green('✓')} ${dry ? 'Would keep' : 'Kept'} ${agents.length} agent(s) another tool added — ` +
|
|
256
|
+
`${dry ? 'moving' : 'moved'} into .opencastle/agents/, so every assistant gets ${agents.length === 1 ? 'it' : 'them'}:`,
|
|
257
|
+
)
|
|
258
|
+
for (const a of agents) console.log(` ${c.dim(`${a.from} → .opencastle/agents/${a.name}.agent.md`)}`)
|
|
259
|
+
}
|
|
244
260
|
}
|
|
245
261
|
|
|
246
262
|
// ── Recreate the local-only directories ─────────────────────────
|
|
@@ -616,6 +632,9 @@ export default async function update({
|
|
|
616
632
|
}),
|
|
617
633
|
)
|
|
618
634
|
const createdConfigs = new Set(manifest.createdConfigs ?? [])
|
|
635
|
+
// The integration servers the last sync gave the project, read before this
|
|
636
|
+
// one writes the lock: the only ones it may take out of an MCP config.
|
|
637
|
+
const given = priorIntegrations(projectRoot)
|
|
619
638
|
// Legacy MCP configs this sync took our servers out of: deleted, or kept for
|
|
620
639
|
// what the user added to them.
|
|
621
640
|
const legacyDeleted: string[] = []
|
|
@@ -661,7 +680,7 @@ export default async function update({
|
|
|
661
680
|
for (const step of [
|
|
662
681
|
() => updateSkillMatrixFile(projectRoot, ide, newStack),
|
|
663
682
|
async () => {
|
|
664
|
-
const outcome = await rebuildMcpConfig(projectRoot, ide as IdeChoice, newStack, repoInfo, source.mcp)
|
|
683
|
+
const outcome = await rebuildMcpConfig(projectRoot, ide as IdeChoice, newStack, repoInfo, source.mcp, given)
|
|
665
684
|
for (const key of outcome.upgraded) upgradedServers.add(key)
|
|
666
685
|
for (const key of outcome.removed) removedServers.add(key)
|
|
667
686
|
for (const key of outcome.teamWritten) teamWritten.add(key)
|
|
@@ -691,6 +710,8 @@ export default async function update({
|
|
|
691
710
|
createdConfigs.has(rel),
|
|
692
711
|
[...new Set([...Object.keys(source.mcp.servers), ...priorKeys])],
|
|
693
712
|
priorInputs,
|
|
713
|
+
// And the ones this sync just wrote into the config that replaces it.
|
|
714
|
+
given && new Set([...given, ...getIncludedMcpServers(newStack, repoInfo)]),
|
|
694
715
|
)
|
|
695
716
|
if (outcome === 'deleted') {
|
|
696
717
|
legacyDeleted.push(rel)
|
|
@@ -776,7 +797,9 @@ export default async function update({
|
|
|
776
797
|
` ${c.green('+')} Created ${c.bold(String(totalCreated))} new files`
|
|
777
798
|
)
|
|
778
799
|
}
|
|
779
|
-
|
|
800
|
+
// A root file left alone for being a link out of the project says nothing
|
|
801
|
+
// about the matrix or the MCP config.
|
|
802
|
+
if (newStack && unreadable.every((u) => u.split('\u0000')[1] === 'outside')) {
|
|
780
803
|
console.log(` ${c.green('✓')} Updated skill matrix`)
|
|
781
804
|
console.log(` ${c.green('✓')} Rebuilt MCP config`)
|
|
782
805
|
}
|
|
@@ -872,7 +895,7 @@ export default async function update({
|
|
|
872
895
|
` ${c.yellow('!')} Left ${name} alone — ` +
|
|
873
896
|
whyLeftAlone(name, why),
|
|
874
897
|
)
|
|
875
|
-
console.log(` ${c.dim('Merge conflict? Fix the file and run sync again.')}`)
|
|
898
|
+
if (why !== 'outside') console.log(` ${c.dim('Merge conflict? Fix the file and run sync again.')}`)
|
|
876
899
|
}
|
|
877
900
|
if (severedRoots.length > 0) {
|
|
878
901
|
console.log(
|
|
@@ -932,7 +955,7 @@ export default async function update({
|
|
|
932
955
|
// made the warning easy to miss — and the sweep is wider on this branch than
|
|
933
956
|
// it was on main.
|
|
934
957
|
const strays = [...new Set(sweptFiles)].filter(
|
|
935
|
-
(rel) => !existsSync(resolve(projectRoot, rel)),
|
|
958
|
+
(rel) => !existsSync(resolve(projectRoot, rel)) && !adoptedAgents.has(rel),
|
|
936
959
|
)
|
|
937
960
|
if (strays.length > 0) {
|
|
938
961
|
// Deliberately not "files that were not generated": most of these *were*
|