opencastle 1.0.0 → 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 +8 -3
- 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/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 +13 -3
- package/dist/cli/adapters/single-file-base.js.map +1 -1
- package/dist/cli/adapters/vscode.d.ts +11 -1
- package/dist/cli/adapters/vscode.d.ts.map +1 -1
- package/dist/cli/adapters/vscode.js +48 -8
- package/dist/cli/adapters/vscode.js.map +1 -1
- 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/doctor.test.js +2 -2
- package/dist/cli/doctor.test.js.map +1 -1
- package/dist/cli/explain.d.ts.map +1 -1
- package/dist/cli/explain.js +13 -1
- package/dist/cli/explain.js.map +1 -1
- package/dist/cli/github-report.js +1 -1
- package/dist/cli/github-report.js.map +1 -1
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +40 -6
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/init.test.js +9 -4
- package/dist/cli/init.test.js.map +1 -1
- 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/remove.d.ts.map +1 -1
- package/dist/cli/remove.js +22 -4
- package/dist/cli/remove.js.map +1 -1
- package/dist/cli/sync-check.d.ts.map +1 -1
- package/dist/cli/sync-check.js +22 -4
- package/dist/cli/sync-check.js.map +1 -1
- package/dist/cli/types.d.ts +32 -0
- 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 +14 -0
- package/dist/cli/update.js.map +1 -1
- package/package.json +2 -2
- package/src/cli/adapters/claude-code.ts +13 -7
- package/src/cli/adapters/single-file-base.ts +22 -4
- package/src/cli/adapters/vscode.ts +51 -10
- 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/doctor.test.ts +2 -2
- package/src/cli/explain.ts +13 -1
- package/src/cli/github-report.ts +1 -1
- package/src/cli/init.test.ts +9 -4
- package/src/cli/init.ts +43 -7
- package/src/cli/managed-paths.ts +73 -3
- package/src/cli/manifest.ts +2 -0
- package/src/cli/remove.ts +20 -4
- package/src/cli/sync-check.ts +19 -3
- package/src/cli/types.ts +32 -0
- package/src/cli/update.ts +12 -0
- package/src/dashboard/node_modules/.vite/deps/_metadata.json +6 -6
- package/src/orchestrator/prompts/bootstrap-customizations.prompt.md +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { resolve } from 'node:path'
|
|
1
|
+
import { basename, resolve } from 'node:path'
|
|
2
2
|
import { mkdir, readFile, unlink, rename } from 'node:fs/promises'
|
|
3
3
|
import { existsSync, readdirSync, realpathSync } from 'node:fs'
|
|
4
4
|
import { writeManagedBlock, recordMerge } from '../managed-block.js'
|
|
@@ -7,6 +7,7 @@ import { scaffoldMcpConfigInto } from '../mcp.js'
|
|
|
7
7
|
import { getAgentTransform } from '../stack-config.js'
|
|
8
8
|
import { withSource, type CompileSource } from '../layers.js'
|
|
9
9
|
import type { CopyResults, CopyDirOptions, DoctorCheck, ManagedPaths, RepoInfo, StackConfig } from '../types.js'
|
|
10
|
+
import { isOurVscodePrompt, legacyVscodePrompts, vscodePromptFile, withCommandName } from '../command-namespace.js'
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* VS Code / GitHub Copilot adapter.
|
|
@@ -18,7 +19,7 @@ import type { CopyResults, CopyDirOptions, DoctorCheck, ManagedPaths, RepoInfo,
|
|
|
18
19
|
* instructions/ → .github/instructions/
|
|
19
20
|
* skills/ → .github/skills/
|
|
20
21
|
* agent-workflows/ → .github/agent-workflows/
|
|
21
|
-
* prompts
|
|
22
|
+
* prompts/<name>.prompt.md → .github/prompts/oc.<name>.prompt.md (/oc:<name>)
|
|
22
23
|
* customizations/ → .opencastle/ (scaffolded once)
|
|
23
24
|
*/
|
|
24
25
|
|
|
@@ -44,10 +45,23 @@ const FRAMEWORK_DIRS = [
|
|
|
44
45
|
function copyRulesFor(
|
|
45
46
|
dir: string,
|
|
46
47
|
stack?: StackConfig,
|
|
47
|
-
):
|
|
48
|
+
): Pick<CopyDirOptions, 'filter' | 'transform' | 'rename'> {
|
|
48
49
|
if (dir === 'agents') {
|
|
49
50
|
return { transform: stack ? getAgentTransform(stack) : undefined }
|
|
50
51
|
}
|
|
52
|
+
if (dir === 'prompts') {
|
|
53
|
+
// The `oc:` namespace. VS Code reads prompt files from the top of
|
|
54
|
+
// `.github/prompts/` only, so it goes in the file name as `oc.` and in the
|
|
55
|
+
// command name — the frontmatter `name`, which VS Code prefers — as `oc:`.
|
|
56
|
+
const PROMPT = '.prompt.md'
|
|
57
|
+
return {
|
|
58
|
+
rename: (name) => (name.endsWith(PROMPT) ? vscodePromptFile(name) : name),
|
|
59
|
+
transform: (content, srcPath) =>
|
|
60
|
+
srcPath.endsWith(PROMPT)
|
|
61
|
+
? withCommandName(content, basename(srcPath).slice(0, -PROMPT.length))
|
|
62
|
+
: content,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
51
65
|
if (dir === 'agent-workflows') {
|
|
52
66
|
// The directory's own README documents the templates for contributors; it is
|
|
53
67
|
// not one of them, and no other adapter installs it.
|
|
@@ -126,9 +140,7 @@ async function installFrom(
|
|
|
126
140
|
if (!existsSync(srcDir)) continue
|
|
127
141
|
const destDir = resolve(destRoot, dir)
|
|
128
142
|
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
const sub = await copyDir(srcDir, destDir, { filter, transform })
|
|
143
|
+
const sub = await copyDir(srcDir, destDir, copyRulesFor(dir, stack))
|
|
132
144
|
mergeCopyResults(results, sub)
|
|
133
145
|
}
|
|
134
146
|
|
|
@@ -180,7 +192,12 @@ async function updateFrom(src: CompileSource, projectRoot: string, stack: StackC
|
|
|
180
192
|
const beforeSweep = new Map<string, string>()
|
|
181
193
|
for (const dir of FRAMEWORK_DIRS) {
|
|
182
194
|
const abs = resolve(destRoot, dir)
|
|
183
|
-
for (const rel of filesUnderDir(abs))
|
|
195
|
+
for (const rel of filesUnderDir(abs)) {
|
|
196
|
+
const shown = `.github/${dir}/${rel}`
|
|
197
|
+
// A prompt someone wrote beside ours is theirs to keep.
|
|
198
|
+
if (!ownsFile(shown, projectRoot)) continue
|
|
199
|
+
beforeSweep.set(resolve(abs, rel), shown)
|
|
200
|
+
}
|
|
184
201
|
}
|
|
185
202
|
|
|
186
203
|
// Recompile over the existing tree, then sweep — not the other way round.
|
|
@@ -196,9 +213,7 @@ async function updateFrom(src: CompileSource, projectRoot: string, stack: StackC
|
|
|
196
213
|
if (!existsSync(srcDir)) continue
|
|
197
214
|
const destDir = resolve(destRoot, dir)
|
|
198
215
|
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
const sub = await copyDir(srcDir, destDir, { overwrite: true, filter, transform })
|
|
216
|
+
const sub = await copyDir(srcDir, destDir, { overwrite: true, ...copyRulesFor(dir, stack) })
|
|
202
217
|
mergeCopyResults(results, sub)
|
|
203
218
|
for (const abs of sub.visited ?? []) visited.add(abs)
|
|
204
219
|
}
|
|
@@ -218,6 +233,32 @@ async function updateFrom(src: CompileSource, projectRoot: string, stack: StackC
|
|
|
218
233
|
return results
|
|
219
234
|
}
|
|
220
235
|
|
|
236
|
+
const PROMPTS_DIR = '.github/prompts/'
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* `.github/prompts/` is shared: VS Code reads prompt files only at its top, so
|
|
240
|
+
* OpenCastle's `oc.` files and a person's own sit side by side. Every other
|
|
241
|
+
* framework directory is wholly generated.
|
|
242
|
+
*/
|
|
243
|
+
export function ownsFile(rel: string, projectRoot: string): boolean {
|
|
244
|
+
const norm = rel.replace(/\\/g, '/')
|
|
245
|
+
if (!norm.startsWith(PROMPTS_DIR)) return true
|
|
246
|
+
const name = norm.slice(PROMPTS_DIR.length)
|
|
247
|
+
// VS Code reads nothing deeper, and OpenCastle writes nothing deeper.
|
|
248
|
+
if (name.includes('/')) return false
|
|
249
|
+
return isOurVscodePrompt(name, resolve(projectRoot, norm), projectRoot)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** The one framework directory this target shares with the user. */
|
|
253
|
+
export function getSharedDirs(): string[] {
|
|
254
|
+
return [PROMPTS_DIR]
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** The un-namespaced prompts an earlier release wrote. `update`'s sweep removes them. */
|
|
258
|
+
export function getLegacyOutputs(projectRoot: string): string[] {
|
|
259
|
+
return legacyVscodePrompts(projectRoot)
|
|
260
|
+
}
|
|
261
|
+
|
|
221
262
|
export function getManagedPaths(): ManagedPaths {
|
|
222
263
|
return {
|
|
223
264
|
framework: FRAMEWORK_DIRS.map((d) => `.github/${d}/`),
|
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compiled commands live under `oc:` — `/oc:bug-fix` — and OpenCastle owns that
|
|
3
|
+
* namespace and nothing beside it. A command someone writes by hand keeps its
|
|
4
|
+
* name, is never overwritten, never swept, and never reported as drift; what a
|
|
5
|
+
* release before the namespace left outside it is cleaned up once.
|
|
6
|
+
*/
|
|
7
|
+
import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync, existsSync, readdirSync } from 'node:fs'
|
|
8
|
+
import { tmpdir } from 'node:os'
|
|
9
|
+
import { join, resolve, dirname } from 'node:path'
|
|
10
|
+
import { execFileSync } from 'node:child_process'
|
|
11
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
12
|
+
import { IDE_ADAPTERS } from './adapters/index.js'
|
|
13
|
+
import { resolveSources, materialize } from './layers.js'
|
|
14
|
+
import { buildCheckReport } from './sync-check.js'
|
|
15
|
+
import { writeManifest, createManifest } from './manifest.js'
|
|
16
|
+
import { recordLockFor } from './lock.js'
|
|
17
|
+
import { resolveManagedPaths, ownerOf, removeOwnedFiles } from './managed-paths.js'
|
|
18
|
+
import { carriesOurBanner, commandName, legacyClaudeCommands, withCommandName } from './command-namespace.js'
|
|
19
|
+
import type { Manifest, StackConfig } from './types.js'
|
|
20
|
+
|
|
21
|
+
vi.mock('./prompt.js', async (importOriginal) => {
|
|
22
|
+
const actual = await importOriginal<typeof import('./prompt.js')>()
|
|
23
|
+
return { ...actual, confirm: vi.fn().mockResolvedValue(true), select: vi.fn().mockResolvedValue('all'), closePrompts: vi.fn() }
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
import remove from './remove.js'
|
|
27
|
+
|
|
28
|
+
const pkgRoot = resolve(import.meta.dirname, '..', '..')
|
|
29
|
+
|
|
30
|
+
const BANNER = '<!-- ⚠️ This file is managed by OpenCastle. Edits will be overwritten on update. Customize in the .opencastle/ directory instead. -->'
|
|
31
|
+
/** What a release before the namespace compiled to `.claude/commands/bug-fix.md`. */
|
|
32
|
+
const LEGACY_COMMAND = `${BANNER}\n\n# Fix Bug\n\nYou are the Team Lead.\n`
|
|
33
|
+
/** A command a person wrote. */
|
|
34
|
+
const OWN_COMMAND = '# Deploy\n\nRun our deploy script and report back.\n'
|
|
35
|
+
|
|
36
|
+
function write(root: string, files: Record<string, string>): void {
|
|
37
|
+
for (const [rel, text] of Object.entries(files)) {
|
|
38
|
+
const abs = join(root, rel)
|
|
39
|
+
mkdirSync(dirname(abs), { recursive: true })
|
|
40
|
+
writeFileSync(abs, text)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function manifestFor(ides: StackConfig['ides'], version = '1.0.0', extra: Partial<Manifest> = {}): Manifest {
|
|
45
|
+
return {
|
|
46
|
+
version,
|
|
47
|
+
ide: ides[0],
|
|
48
|
+
ides,
|
|
49
|
+
installedAt: new Date().toISOString(),
|
|
50
|
+
updatedAt: new Date().toISOString(),
|
|
51
|
+
stack: { ides, techTools: [], teamTools: [] },
|
|
52
|
+
...extra,
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
describe('the command name', () => {
|
|
57
|
+
it('is the source name under oc:', () => {
|
|
58
|
+
expect(commandName('bug-fix')).toBe('oc:bug-fix')
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('goes into the frontmatter first, keeping every other field', () => {
|
|
62
|
+
const out = withCommandName("---\ndescription: 'Fix it'\nagent: 'Team Lead (OpenCastle)'\n---\n\nBody\n", 'bug-fix')
|
|
63
|
+
expect(out).toBe("---\nname: 'oc:bug-fix'\ndescription: 'Fix it'\nagent: 'Team Lead (OpenCastle)'\n---\n\nBody\n")
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('replaces a name the source declared, so both assistants agree on it', () => {
|
|
67
|
+
const out = withCommandName("---\nname: ship\ndescription: 'Ship'\n---\nBody", 'release')
|
|
68
|
+
expect(out).toContain("name: 'oc:release'")
|
|
69
|
+
expect(out).not.toContain('name: ship')
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('drops a block-scalar name whole, so the YAML still parses', () => {
|
|
73
|
+
const out = withCommandName("---\nname: >\n ship it\n now\ndescription: 'Ship'\n---\nBody", 'release')
|
|
74
|
+
expect(out).toBe("---\nname: 'oc:release'\ndescription: 'Ship'\n---\nBody")
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('keeps CRLF endings in a prompt checked out on Windows', () => {
|
|
78
|
+
const out = withCommandName("---\r\ndescription: 'x'\r\n---\r\n\r\nBody\r\n", 'x')
|
|
79
|
+
expect(out).toBe("---\r\nname: 'oc:x'\r\ndescription: 'x'\r\n---\r\n\r\nBody\r\n")
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('adds frontmatter to a prompt that has none', () => {
|
|
83
|
+
expect(withCommandName('Just a body\n', 'plain')).toBe("---\nname: 'oc:plain'\n---\n\nJust a body\n")
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
describe('our banner', () => {
|
|
88
|
+
it('counts inside an HTML comment near the top', () => {
|
|
89
|
+
expect(carriesOurBanner(LEGACY_COMMAND)).toBe(true)
|
|
90
|
+
expect(carriesOurBanner(`${LEGACY_COMMAND}`)).toBe(true)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('does not count in a sentence a person wrote', () => {
|
|
94
|
+
expect(carriesOurBanner('# Notes\n\nThis file is managed by OpenCastle, mostly.\n')).toBe(false)
|
|
95
|
+
expect(carriesOurBanner(OWN_COMMAND)).toBe(false)
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
describe('Claude Code: /oc:<name>', () => {
|
|
100
|
+
let project: string
|
|
101
|
+
const stack: StackConfig = { ides: ['claude-code'], techTools: [], teamTools: [] }
|
|
102
|
+
|
|
103
|
+
beforeEach(() => {
|
|
104
|
+
project = mkdtempSync(join(tmpdir(), 'oc-ns-claude-'))
|
|
105
|
+
})
|
|
106
|
+
afterEach(() => {
|
|
107
|
+
rmSync(project, { recursive: true, force: true })
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it("compiles a team's own prompt into the namespace too", async () => {
|
|
111
|
+
write(project, { '.opencastle/prompts/release.prompt.md': "---\ndescription: 'Cut a release'\n---\n\nRELEASE-PROMPT\n" })
|
|
112
|
+
const src = materialize(resolveSources({ pkgRoot, projectRoot: project, stack }), pkgRoot)
|
|
113
|
+
try {
|
|
114
|
+
await (await IDE_ADAPTERS['claude-code']()).install(pkgRoot, project, stack, undefined, src)
|
|
115
|
+
} finally {
|
|
116
|
+
src.dispose()
|
|
117
|
+
}
|
|
118
|
+
expect(readFileSync(join(project, '.claude/commands/oc/release.md'), 'utf8')).toContain('RELEASE-PROMPT')
|
|
119
|
+
expect(existsSync(join(project, '.claude/commands/oc/bug-fix.md'))).toBe(true)
|
|
120
|
+
expect(existsSync(join(project, '.claude/commands/oc/workflow-bug-fix.md'))).toBe(true)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('leaves a command someone wrote alone: not swept, not overwritten, not drift', async () => {
|
|
124
|
+
write(project, { '.claude/commands/deploy.md': OWN_COMMAND, '.claude/commands/bug-fix.md': OWN_COMMAND })
|
|
125
|
+
const adapter = await IDE_ADAPTERS['claude-code']()
|
|
126
|
+
await adapter.install(pkgRoot, project, stack)
|
|
127
|
+
const swept = await adapter.update(pkgRoot, project, stack)
|
|
128
|
+
await writeManifest(project, manifestFor(['claude-code']))
|
|
129
|
+
await recordLockFor(pkgRoot, project, manifestFor(['claude-code']))
|
|
130
|
+
|
|
131
|
+
// Their `/bug-fix` and ours, `/oc:bug-fix`, side by side.
|
|
132
|
+
expect(readFileSync(join(project, '.claude/commands/deploy.md'), 'utf8')).toBe(OWN_COMMAND)
|
|
133
|
+
expect(readFileSync(join(project, '.claude/commands/bug-fix.md'), 'utf8')).toBe(OWN_COMMAND)
|
|
134
|
+
expect(readFileSync(join(project, '.claude/commands/oc/bug-fix.md'), 'utf8')).toContain('# Fix Bug')
|
|
135
|
+
expect(swept.deleted ?? []).toEqual([])
|
|
136
|
+
|
|
137
|
+
const report = await buildCheckReport(pkgRoot, project)
|
|
138
|
+
expect(report.drift).toEqual([])
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
it('removes what a release before the namespace left at the top, and keeps what a person wrote', async () => {
|
|
142
|
+
write(project, {
|
|
143
|
+
'.claude/commands/bug-fix.md': LEGACY_COMMAND,
|
|
144
|
+
'.claude/commands/workflow-bug-fix.md': `${BANNER}\n\n# Workflow: Bug Fix\n`,
|
|
145
|
+
'.claude/commands/deploy.md': OWN_COMMAND,
|
|
146
|
+
})
|
|
147
|
+
const adapter = await IDE_ADAPTERS['claude-code']()
|
|
148
|
+
await writeManifest(project, manifestFor(['claude-code'], '0.38.2'))
|
|
149
|
+
|
|
150
|
+
// Before the sync, the check names the stale commands.
|
|
151
|
+
const before = await buildCheckReport(pkgRoot, project)
|
|
152
|
+
const extra = before.drift.filter((d) => d.kind === 'extra').map((d) => d.path)
|
|
153
|
+
expect(extra).toEqual(['.claude/commands/bug-fix.md', '.claude/commands/workflow-bug-fix.md'])
|
|
154
|
+
|
|
155
|
+
const results = await adapter.update(pkgRoot, project, stack)
|
|
156
|
+
expect(results.deleted).toEqual(expect.arrayContaining(['.claude/commands/bug-fix.md', '.claude/commands/workflow-bug-fix.md']))
|
|
157
|
+
expect(readdirSync(join(project, '.claude/commands')).sort()).toEqual(['deploy.md', 'oc'])
|
|
158
|
+
expect(readFileSync(join(project, '.claude/commands/deploy.md'), 'utf8')).toBe(OWN_COMMAND)
|
|
159
|
+
expect(legacyClaudeCommands(project)).toEqual([])
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
it("keeps a person's edited copy of a namespaced command, banner and all", async () => {
|
|
163
|
+
const adapter = await IDE_ADAPTERS['claude-code']()
|
|
164
|
+
await adapter.install(pkgRoot, project, stack)
|
|
165
|
+
const ours = readFileSync(join(project, '.claude/commands/oc/bug-fix.md'), 'utf8')
|
|
166
|
+
expect(carriesOurBanner(ours)).toBe(true)
|
|
167
|
+
write(project, { '.claude/commands/our-bug-fix.md': `${ours}\nOur extra step.\n` })
|
|
168
|
+
|
|
169
|
+
const results = await adapter.update(pkgRoot, project, stack)
|
|
170
|
+
expect(results.deleted ?? []).toEqual([])
|
|
171
|
+
expect(existsSync(join(project, '.claude/commands/our-bug-fix.md'))).toBe(true)
|
|
172
|
+
expect(legacyClaudeCommands(project)).toEqual([])
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
it('cleans up after 1.0.0 too, which shipped before the namespace', async () => {
|
|
176
|
+
write(project, { '.claude/commands/bug-fix.md': LEGACY_COMMAND, '.claude/commands/deploy.md': OWN_COMMAND })
|
|
177
|
+
// As 1.0.0 wrote it: a later version than any cut-off would have guessed,
|
|
178
|
+
// and no namespace mark.
|
|
179
|
+
await writeManifest(project, manifestFor(['claude-code'], '1.0.0'))
|
|
180
|
+
expect(legacyClaudeCommands(project)).toEqual(['.claude/commands/bug-fix.md'])
|
|
181
|
+
|
|
182
|
+
await (await IDE_ADAPTERS['claude-code']()).update(pkgRoot, project, stack)
|
|
183
|
+
expect(readdirSync(join(project, '.claude/commands')).sort()).toEqual(['deploy.md', 'oc'])
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
it('a new manifest carries the namespace mark from the start', async () => {
|
|
187
|
+
expect(createManifest('9.9.9', 'claude-code').commandNamespace).toBe('oc')
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
it('frees the old names once the project is namespaced: a copy under one is kept', async () => {
|
|
191
|
+
const adapter = await IDE_ADAPTERS['claude-code']()
|
|
192
|
+
await adapter.install(pkgRoot, project, stack)
|
|
193
|
+
await writeManifest(project, manifestFor(['claude-code'], '1.0.0', { commandNamespace: 'oc' }))
|
|
194
|
+
// A team that prefers the short name copies ours back, banner and all.
|
|
195
|
+
const ours = readFileSync(join(project, '.claude/commands/oc/bug-fix.md'), 'utf8')
|
|
196
|
+
write(project, { '.claude/commands/bug-fix.md': ours })
|
|
197
|
+
|
|
198
|
+
expect(legacyClaudeCommands(project)).toEqual([])
|
|
199
|
+
const results = await adapter.update(pkgRoot, project, stack)
|
|
200
|
+
expect(results.deleted ?? []).toEqual([])
|
|
201
|
+
expect(readFileSync(join(project, '.claude/commands/bug-fix.md'), 'utf8')).toBe(ours)
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
it('narrows a stored .claude/commands/ to the namespace, so nothing else is ever deleted by it', async () => {
|
|
205
|
+
const paths = await resolveManagedPaths(
|
|
206
|
+
manifestFor(['claude-code'], '0.38.2', {
|
|
207
|
+
managedPaths: { framework: ['.claude/agents/', '.claude/skills/', '.claude/commands/'], customizable: [] },
|
|
208
|
+
}),
|
|
209
|
+
)
|
|
210
|
+
expect(paths.framework).toContain('.claude/commands/oc/')
|
|
211
|
+
expect(paths.framework).not.toContain('.claude/commands/')
|
|
212
|
+
})
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
describe('remove --all', () => {
|
|
216
|
+
let project: string
|
|
217
|
+
let cwd: ReturnType<typeof vi.spyOn>
|
|
218
|
+
beforeEach(() => {
|
|
219
|
+
project = mkdtempSync(join(tmpdir(), 'oc-ns-remove-'))
|
|
220
|
+
cwd = vi.spyOn(process, 'cwd').mockReturnValue(project)
|
|
221
|
+
vi.spyOn(console, 'log').mockImplementation(() => {})
|
|
222
|
+
})
|
|
223
|
+
afterEach(() => {
|
|
224
|
+
cwd.mockRestore()
|
|
225
|
+
vi.restoreAllMocks()
|
|
226
|
+
rmSync(project, { recursive: true, force: true })
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
it("takes OpenCastle's commands, old and new, and leaves the user's", async () => {
|
|
230
|
+
const stack: StackConfig = { ides: ['claude-code'], techTools: [], teamTools: [] }
|
|
231
|
+
await (await IDE_ADAPTERS['claude-code']()).install(pkgRoot, project, stack)
|
|
232
|
+
write(project, {
|
|
233
|
+
'.claude/commands/bug-fix.md': LEGACY_COMMAND,
|
|
234
|
+
'.claude/commands/deploy.md': OWN_COMMAND,
|
|
235
|
+
})
|
|
236
|
+
// As a release before the namespace recorded it: the whole directory.
|
|
237
|
+
await writeManifest(
|
|
238
|
+
project,
|
|
239
|
+
manifestFor(['claude-code'], '0.38.2', {
|
|
240
|
+
managedPaths: { framework: ['.claude/agents/', '.claude/skills/', '.claude/commands/'], customizable: ['.opencastle/', '.mcp.json'], merged: ['CLAUDE.md'] },
|
|
241
|
+
}),
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
await remove({ pkgRoot, args: ['--all', '--yes'] })
|
|
245
|
+
|
|
246
|
+
expect(existsSync(join(project, '.claude/commands/oc'))).toBe(false)
|
|
247
|
+
expect(existsSync(join(project, '.claude/commands/bug-fix.md'))).toBe(false)
|
|
248
|
+
expect(readFileSync(join(project, '.claude/commands/deploy.md'), 'utf8')).toBe(OWN_COMMAND)
|
|
249
|
+
})
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
describe('VS Code: /oc:<name>', () => {
|
|
253
|
+
let project: string
|
|
254
|
+
const stack: StackConfig = { ides: ['vscode'], techTools: [], teamTools: [] }
|
|
255
|
+
|
|
256
|
+
beforeEach(() => {
|
|
257
|
+
project = mkdtempSync(join(tmpdir(), 'oc-ns-vscode-'))
|
|
258
|
+
})
|
|
259
|
+
afterEach(() => {
|
|
260
|
+
rmSync(project, { recursive: true, force: true })
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
it('names each prompt oc:<name>, in a file VS Code finds at the top of .github/prompts/', async () => {
|
|
264
|
+
await (await IDE_ADAPTERS['vscode']()).install(pkgRoot, project, stack)
|
|
265
|
+
const files = readdirSync(join(project, '.github/prompts'))
|
|
266
|
+
expect(files.length).toBeGreaterThan(0)
|
|
267
|
+
expect(files.every((f) => f.startsWith('oc.') && f.endsWith('.prompt.md'))).toBe(true)
|
|
268
|
+
|
|
269
|
+
const text = readFileSync(join(project, '.github/prompts/oc.bug-fix.prompt.md'), 'utf8')
|
|
270
|
+
expect(text.split('\n').slice(0, 2)).toEqual(['---', "name: 'oc:bug-fix'"])
|
|
271
|
+
// The rest of the source's frontmatter is still there.
|
|
272
|
+
expect(text).toContain("agent: 'Team Lead (OpenCastle)'")
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
it('replaces the un-namespaced prompt files an earlier release wrote', async () => {
|
|
276
|
+
const adapter = await IDE_ADAPTERS['vscode']()
|
|
277
|
+
await adapter.install(pkgRoot, project, stack)
|
|
278
|
+
write(project, { '.github/prompts/bug-fix.prompt.md': `---\ndescription: 'old'\n---\n\n${BANNER}\n` })
|
|
279
|
+
// The project as the upgrading sync finds it: last compiled before the namespace.
|
|
280
|
+
await writeManifest(project, manifestFor(['vscode'], '0.38.2'))
|
|
281
|
+
|
|
282
|
+
// Reported once, saying why.
|
|
283
|
+
const report = await buildCheckReport(pkgRoot, project)
|
|
284
|
+
expect(report.drift.filter((d) => d.kind === 'extra')).toEqual([
|
|
285
|
+
{ ide: 'vscode', path: '.github/prompts/bug-fix.prompt.md', kind: 'extra', detail: 'written by a release before the oc: namespace' },
|
|
286
|
+
])
|
|
287
|
+
|
|
288
|
+
const results = await adapter.update(pkgRoot, project, stack)
|
|
289
|
+
expect(results.deleted).toContain('.github/prompts/bug-fix.prompt.md')
|
|
290
|
+
expect(existsSync(join(project, '.github/prompts/oc.bug-fix.prompt.md'))).toBe(true)
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
it("leaves a prompt someone wrote in .github/prompts/ alone: not swept, not drift, not removed", async () => {
|
|
294
|
+
const own = "---\ndescription: 'Deploy'\n---\n\nRun our deploy.\n"
|
|
295
|
+
write(project, {
|
|
296
|
+
'.github/prompts/deploy.prompt.md': own,
|
|
297
|
+
// Same name as one of ours before the namespace, but theirs: no banner.
|
|
298
|
+
'.github/prompts/bug-fix.prompt.md': own,
|
|
299
|
+
})
|
|
300
|
+
const adapter = await IDE_ADAPTERS['vscode']()
|
|
301
|
+
await adapter.install(pkgRoot, project, stack)
|
|
302
|
+
const results = await adapter.update(pkgRoot, project, stack)
|
|
303
|
+
expect(results.deleted ?? []).toEqual([])
|
|
304
|
+
await writeManifest(project, manifestFor(['vscode']))
|
|
305
|
+
await recordLockFor(pkgRoot, project, manifestFor(['vscode']))
|
|
306
|
+
expect((await buildCheckReport(pkgRoot, project)).drift).toEqual([])
|
|
307
|
+
|
|
308
|
+
const cwd = vi.spyOn(process, 'cwd').mockReturnValue(project)
|
|
309
|
+
const log = vi.spyOn(console, 'log').mockImplementation(() => {})
|
|
310
|
+
try {
|
|
311
|
+
await writeManifest(
|
|
312
|
+
project,
|
|
313
|
+
manifestFor(['vscode'], '1.0.0', { managedPaths: { framework: ['.github/prompts/', '.github/agents/'], customizable: [] } }),
|
|
314
|
+
)
|
|
315
|
+
await remove({ pkgRoot, args: ['--all', '--yes'] })
|
|
316
|
+
} finally {
|
|
317
|
+
cwd.mockRestore()
|
|
318
|
+
log.mockRestore()
|
|
319
|
+
}
|
|
320
|
+
expect(readFileSync(join(project, '.github/prompts/deploy.prompt.md'), 'utf8')).toBe(own)
|
|
321
|
+
expect(readFileSync(join(project, '.github/prompts/bug-fix.prompt.md'), 'utf8')).toBe(own)
|
|
322
|
+
expect(readdirSync(join(project, '.github/prompts')).sort()).toEqual(['bug-fix.prompt.md', 'deploy.prompt.md'])
|
|
323
|
+
expect(existsSync(join(project, '.github/agents'))).toBe(false)
|
|
324
|
+
})
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
const cli = join(pkgRoot, 'bin', 'cli.mjs')
|
|
328
|
+
const built = existsSync(join(pkgRoot, 'dist', 'cli', 'init.js'))
|
|
329
|
+
|
|
330
|
+
describe.skipIf(!built)('init over an install a release before the namespace left without a manifest', () => {
|
|
331
|
+
let project: string
|
|
332
|
+
beforeEach(() => {
|
|
333
|
+
project = mkdtempSync(join(tmpdir(), 'oc-ns-orphan-'))
|
|
334
|
+
execFileSync('git', ['init', '-q'], { cwd: project })
|
|
335
|
+
write(project, {
|
|
336
|
+
'CLAUDE.md': '# House rules\n',
|
|
337
|
+
'.claude/commands/bug-fix.md': LEGACY_COMMAND,
|
|
338
|
+
'.claude/commands/deploy.md': OWN_COMMAND,
|
|
339
|
+
'.claude/agents/developer.agent.md': 'an old body\n',
|
|
340
|
+
})
|
|
341
|
+
})
|
|
342
|
+
afterEach(() => rmSync(project, { recursive: true, force: true }))
|
|
343
|
+
|
|
344
|
+
it('recompiles it: the stale /bug-fix goes, old bodies are refreshed, their own command stays', () => {
|
|
345
|
+
const out = execFileSync('node', [cli, 'init', '--yes'], { cwd: project, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] })
|
|
346
|
+
expect(out).toContain('from a previous installation')
|
|
347
|
+
expect(existsSync(join(project, '.claude/commands/bug-fix.md'))).toBe(false)
|
|
348
|
+
expect(readFileSync(join(project, '.claude/commands/deploy.md'), 'utf8')).toBe(OWN_COMMAND)
|
|
349
|
+
expect(readFileSync(join(project, '.claude/agents/developer.agent.md'), 'utf8')).not.toBe('an old body\n')
|
|
350
|
+
expect(existsSync(join(project, '.claude/commands/oc/bug-fix.md'))).toBe(true)
|
|
351
|
+
const manifest = JSON.parse(readFileSync(join(project, '.opencastle/manifest.json'), 'utf8')) as Manifest
|
|
352
|
+
expect(manifest.commandNamespace).toBe('oc')
|
|
353
|
+
})
|
|
354
|
+
|
|
355
|
+
it('the sync that upgrades a 1.0.0 project removes its old commands and marks it, once', () => {
|
|
356
|
+
execFileSync('node', [cli, 'init', '--yes'], { cwd: project, stdio: 'ignore' })
|
|
357
|
+
// Back to how 1.0.0 left it: its commands at the top, its manifest unmarked.
|
|
358
|
+
write(project, { '.claude/commands/bug-fix.md': LEGACY_COMMAND })
|
|
359
|
+
const path = join(project, '.opencastle/manifest.json')
|
|
360
|
+
const manifest = JSON.parse(readFileSync(path, 'utf8')) as Manifest
|
|
361
|
+
delete manifest.commandNamespace
|
|
362
|
+
manifest.version = '1.0.0'
|
|
363
|
+
writeFileSync(path, JSON.stringify(manifest, null, 2))
|
|
364
|
+
|
|
365
|
+
execFileSync('node', [cli, 'sync', '--yes'], { cwd: project, stdio: 'ignore' })
|
|
366
|
+
expect(existsSync(join(project, '.claude/commands/bug-fix.md'))).toBe(false)
|
|
367
|
+
expect((JSON.parse(readFileSync(path, 'utf8')) as Manifest).commandNamespace).toBe('oc')
|
|
368
|
+
|
|
369
|
+
// Now the short name is theirs to use.
|
|
370
|
+
write(project, { '.claude/commands/bug-fix.md': LEGACY_COMMAND })
|
|
371
|
+
execFileSync('node', [cli, 'sync', '--yes', '--force'], { cwd: project, stdio: 'ignore' })
|
|
372
|
+
expect(existsSync(join(project, '.claude/commands/bug-fix.md'))).toBe(true)
|
|
373
|
+
})
|
|
374
|
+
})
|
|
375
|
+
|
|
376
|
+
describe('removing from the shared prompts directory', () => {
|
|
377
|
+
let project: string
|
|
378
|
+
beforeEach(() => {
|
|
379
|
+
project = mkdtempSync(join(tmpdir(), 'oc-ns-shared-'))
|
|
380
|
+
})
|
|
381
|
+
afterEach(() => {
|
|
382
|
+
rmSync(project, { recursive: true, force: true })
|
|
383
|
+
})
|
|
384
|
+
|
|
385
|
+
it("takes only our files at the top, and none of a person's subfolders", () => {
|
|
386
|
+
write(project, {
|
|
387
|
+
'.github/prompts/oc.bug-fix.prompt.md': 'ours',
|
|
388
|
+
'.github/prompts/deploy.prompt.md': 'theirs',
|
|
389
|
+
'.github/prompts/drafts/oc.idea.prompt.md': 'theirs, below the top',
|
|
390
|
+
})
|
|
391
|
+
mkdirSync(join(project, '.github/prompts/empty-folder'))
|
|
392
|
+
const owns = (rel: string): boolean => /^\.github\/prompts\/oc\.[^/]+$/.test(rel)
|
|
393
|
+
expect(removeOwnedFiles(project, '.github/prompts/', owns)).toBe(1)
|
|
394
|
+
expect(readdirSync(join(project, '.github/prompts')).sort()).toEqual(['deploy.prompt.md', 'drafts', 'empty-folder'])
|
|
395
|
+
expect(existsSync(join(project, '.github/prompts/drafts/oc.idea.prompt.md'))).toBe(true)
|
|
396
|
+
})
|
|
397
|
+
|
|
398
|
+
it('leaves a file wearing the directory name for a person, without throwing', () => {
|
|
399
|
+
write(project, { '.github/prompts': 'not a directory' })
|
|
400
|
+
expect(removeOwnedFiles(project, '.github/prompts/', () => true)).toBe(0)
|
|
401
|
+
expect(readFileSync(join(project, '.github/prompts'), 'utf8')).toBe('not a directory')
|
|
402
|
+
})
|
|
403
|
+
|
|
404
|
+
it('removes the directory when ours was all it held', () => {
|
|
405
|
+
write(project, { '.github/prompts/oc.bug-fix.prompt.md': 'ours' })
|
|
406
|
+
expect(removeOwnedFiles(project, '.github/prompts/', () => true)).toBe(1)
|
|
407
|
+
expect(existsSync(join(project, '.github/prompts'))).toBe(false)
|
|
408
|
+
})
|
|
409
|
+
|
|
410
|
+
it('treats only .github/prompts/ as shared — every other VS Code directory is removed whole', async () => {
|
|
411
|
+
const vscode = await IDE_ADAPTERS['vscode']()
|
|
412
|
+
expect(ownerOf([vscode], '.github/prompts/', project)).toBeTypeOf('function')
|
|
413
|
+
for (const dir of ['.github/agents/', '.github/instructions/', '.github/skills/', '.github/agent-workflows/']) {
|
|
414
|
+
expect(ownerOf([vscode], dir, project)).toBeUndefined()
|
|
415
|
+
}
|
|
416
|
+
})
|
|
417
|
+
})
|