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
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The namespace every command OpenCastle compiles is invoked under.
|
|
6
|
+
*
|
|
7
|
+
* `/bug-fix` was a name anyone could want: a teammate's own command, another
|
|
8
|
+
* tool's, a skill. Compiled commands now live under one prefix, `/oc:bug-fix`,
|
|
9
|
+
* and in the directories commands live in OpenCastle owns that namespace and
|
|
10
|
+
* nothing beside it — so a command someone writes by hand is never overwritten,
|
|
11
|
+
* swept, removed, or reported as drift.
|
|
12
|
+
*
|
|
13
|
+
* The prefix is a namespace, not a mark of origin. A team's own prompt in a
|
|
14
|
+
* baseline or in `.opencastle/prompts/` compiles to `/oc:<name>` as well: it is
|
|
15
|
+
* shared, reviewed config that `sync` rewrites, which is what the prefix tells
|
|
16
|
+
* the person typing it.
|
|
17
|
+
*/
|
|
18
|
+
export const COMMAND_NAMESPACE = 'oc'
|
|
19
|
+
|
|
20
|
+
/** What a person types after the slash: `oc:bug-fix`. */
|
|
21
|
+
export function commandName(name: string): string {
|
|
22
|
+
return `${COMMAND_NAMESPACE}:${name}`
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Claude Code names a command after its path under `.claude/commands/`, with
|
|
27
|
+
* each directory becoming a `:` segment — `oc/bug-fix.md` is `/oc:bug-fix`. A
|
|
28
|
+
* directory, not a colon in the file name, because Windows cannot check out a
|
|
29
|
+
* file whose name contains one.
|
|
30
|
+
*/
|
|
31
|
+
export const CLAUDE_COMMANDS_DIR = `commands/${COMMAND_NAMESPACE}`
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* VS Code reads prompt files from the top of `.github/prompts/` only, so the
|
|
35
|
+
* namespace goes in the file name, and the command name — `name:` in the
|
|
36
|
+
* frontmatter, which VS Code prefers to the file name — carries the colon.
|
|
37
|
+
*/
|
|
38
|
+
export function vscodePromptFile(fileName: string): string {
|
|
39
|
+
return `${COMMAND_NAMESPACE}.${fileName}`
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Give a prompt file the namespaced command name, in its frontmatter.
|
|
44
|
+
*
|
|
45
|
+
* Any `name:` the source declared is replaced rather than prefixed: Claude Code
|
|
46
|
+
* ignores the field and names commands after the file, so honouring it here
|
|
47
|
+
* would give one prompt two different names in two assistants.
|
|
48
|
+
*/
|
|
49
|
+
export function withCommandName(content: string, name: string): string {
|
|
50
|
+
const line = `name: '${commandName(name)}'`
|
|
51
|
+
// The file's own line endings, so a CRLF checkout of a team's prompt is not
|
|
52
|
+
// rewritten into mixed endings.
|
|
53
|
+
const eol = content.includes('\r\n') ? '\r\n' : '\n'
|
|
54
|
+
const lines = content.split(/\r?\n/)
|
|
55
|
+
if (lines[0]?.trim() === '---') {
|
|
56
|
+
const close = lines.findIndex((l, i) => i > 0 && l.trim() === '---')
|
|
57
|
+
if (close > 0) {
|
|
58
|
+
// The declared name and, for a block scalar (`name: >`), the indented
|
|
59
|
+
// lines that continue it — left behind, they would break the YAML and
|
|
60
|
+
// take `description` and `agent` down with it.
|
|
61
|
+
const kept: string[] = []
|
|
62
|
+
let inName = false
|
|
63
|
+
for (const l of lines.slice(1, close)) {
|
|
64
|
+
if (/^name\s*:/.test(l)) {
|
|
65
|
+
inName = true
|
|
66
|
+
continue
|
|
67
|
+
}
|
|
68
|
+
if (inName && /^[ \t]/.test(l)) continue
|
|
69
|
+
inName = false
|
|
70
|
+
kept.push(l)
|
|
71
|
+
}
|
|
72
|
+
return ['---', line, ...kept, ...lines.slice(close)].join(eol)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return `---${eol}${line}${eol}---${eol}${eol}${content}`
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Does this file say a release of ours wrote it?
|
|
80
|
+
*
|
|
81
|
+
* Every prompt and workflow OpenCastle has shipped since 0.2 opens with
|
|
82
|
+
* `<!-- ⚠️ This file is managed by OpenCastle. … -->`. Only inside an HTML
|
|
83
|
+
* comment, and only near the top: the same words in a person's own sentence
|
|
84
|
+
* are theirs, which is the distinction `managed-block.ts` learned for root
|
|
85
|
+
* files.
|
|
86
|
+
*/
|
|
87
|
+
export function carriesOurBanner(content: string): boolean {
|
|
88
|
+
const lines = content
|
|
89
|
+
.replace(/^/, '')
|
|
90
|
+
.split(/\r?\n/)
|
|
91
|
+
.map((l) => l.trim())
|
|
92
|
+
.filter((l) => l !== '')
|
|
93
|
+
.slice(0, 12)
|
|
94
|
+
return lines.some((l) => l.startsWith('<!--') && l.includes('This file is managed by OpenCastle'))
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Every prompt and workflow a release before the namespace shipped — read
|
|
99
|
+
* from all 103 release tags, 0.1.0 to 1.0.0. A closed list: those releases are
|
|
100
|
+
* done.
|
|
101
|
+
*
|
|
102
|
+
* The banner alone is not enough to call a file theirs. Namespaced output
|
|
103
|
+
* carries it too, so a person who copies `oc/bug-fix.md` to `our-bug-fix.md`
|
|
104
|
+
* and edits it would see their copy deleted on the next sync. A legacy file is
|
|
105
|
+
* one of these names *and* carries the banner.
|
|
106
|
+
*/
|
|
107
|
+
const LEGACY_PROMPTS = [
|
|
108
|
+
'assess-complexity', 'bootstrap-customizations', 'brainstorm', 'bug-fix', 'create-skill',
|
|
109
|
+
'fix-convoy', 'fix-prd', 'generate-convoy', 'generate-prd', 'generate-task-spec',
|
|
110
|
+
'implement-feature', 'metrics-report', 'quick-refinement', 'resolve-pr-comments',
|
|
111
|
+
'validate-convoy', 'validate-prd',
|
|
112
|
+
]
|
|
113
|
+
const LEGACY_WORKFLOWS = [
|
|
114
|
+
'README', 'bug-fix', 'data-pipeline', 'database-migration', 'feature-implementation',
|
|
115
|
+
'performance-optimization', 'refactoring', 'schema-changes', 'security-audit',
|
|
116
|
+
'shared-delivery-phase',
|
|
117
|
+
]
|
|
118
|
+
|
|
119
|
+
/** File names a release before the namespace wrote at the top of `.claude/commands/`. */
|
|
120
|
+
const LEGACY_CLAUDE_NAMES = new Set([
|
|
121
|
+
...LEGACY_PROMPTS.map((n) => `${n}.md`),
|
|
122
|
+
...LEGACY_WORKFLOWS.map((n) => `workflow-${n}.md`),
|
|
123
|
+
])
|
|
124
|
+
|
|
125
|
+
/** File names a release before the namespace wrote in `.github/prompts/`. */
|
|
126
|
+
const LEGACY_VSCODE_NAMES = new Set(LEGACY_PROMPTS.map((n) => `${n}.prompt.md`))
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Was this project last compiled by a release before the namespace?
|
|
130
|
+
*
|
|
131
|
+
* Legacy output is looked for only then — during the sync that upgrades it,
|
|
132
|
+
* or over an install whose manifest is gone. Afterwards the old names are free
|
|
133
|
+
* again: a team that copies `oc/bug-fix.md` back to `bug-fix.md` because it
|
|
134
|
+
* prefers the short name keeps its copy, banner and all.
|
|
135
|
+
*
|
|
136
|
+
* Read from a mark in the manifest, not from its version. 1.0.0 shipped
|
|
137
|
+
* without the namespace, and which number the namespaced release gets depends
|
|
138
|
+
* on what else merges first — a version cut-off guessed here would miss every
|
|
139
|
+
* project compiled in between, and leave a stale `/bug-fix` beside
|
|
140
|
+
* `/oc:bug-fix` in each of them.
|
|
141
|
+
*/
|
|
142
|
+
export function compiledBeforeNamespace(projectRoot: string): boolean {
|
|
143
|
+
for (const rel of ['.opencastle/manifest.json', '.opencastle.json']) {
|
|
144
|
+
const abs = resolve(projectRoot, rel)
|
|
145
|
+
if (!existsSync(abs)) continue
|
|
146
|
+
try {
|
|
147
|
+
const manifest = JSON.parse(readFileSync(abs, 'utf8')) as { commandNamespace?: unknown }
|
|
148
|
+
return manifest.commandNamespace !== COMMAND_NAMESPACE
|
|
149
|
+
} catch {
|
|
150
|
+
return true
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return true
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Does the file at `abs` carry our banner? An unreadable file is not ours to delete. */
|
|
157
|
+
function bannerAt(abs: string): boolean {
|
|
158
|
+
try {
|
|
159
|
+
return carriesOurBanner(readFileSync(abs, 'utf8'))
|
|
160
|
+
} catch {
|
|
161
|
+
return false
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Commands a release before the namespace compiled into the top of
|
|
167
|
+
* `.claude/commands/`.
|
|
168
|
+
*
|
|
169
|
+
* Those releases wrote `bug-fix.md` and `workflow-bug-fix.md` there and swept
|
|
170
|
+
* the whole directory on every sync. Now commands go under `oc/`, and nothing
|
|
171
|
+
* the rest — so the old files would linger as a second, stale `/bug-fix` beside
|
|
172
|
+
* `/oc:bug-fix`. One of their names with our banner is theirs; anything else in
|
|
173
|
+
* the directory is a person's, and is left alone.
|
|
174
|
+
*
|
|
175
|
+
* Paths are relative to the project root, with forward slashes.
|
|
176
|
+
*/
|
|
177
|
+
export function legacyClaudeCommands(projectRoot: string, dotDir = '.claude'): string[] {
|
|
178
|
+
const dir = resolve(projectRoot, dotDir, 'commands')
|
|
179
|
+
if (!existsSync(dir) || !compiledBeforeNamespace(projectRoot)) return []
|
|
180
|
+
let entries
|
|
181
|
+
try {
|
|
182
|
+
entries = readdirSync(dir, { withFileTypes: true })
|
|
183
|
+
} catch {
|
|
184
|
+
return []
|
|
185
|
+
}
|
|
186
|
+
return entries
|
|
187
|
+
.filter((e) => e.isFile() && LEGACY_CLAUDE_NAMES.has(e.name) && bannerAt(resolve(dir, e.name)))
|
|
188
|
+
.map((e) => `${dotDir}/commands/${e.name}`)
|
|
189
|
+
.sort()
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Is this file in `.github/prompts/` one OpenCastle wrote?
|
|
194
|
+
*
|
|
195
|
+
* VS Code reads prompts only from the top of that directory, so OpenCastle's
|
|
196
|
+
* and a person's share it. Ours are the `oc.` files, plus the un-namespaced
|
|
197
|
+
* ones a release before the namespace wrote — which `sync` replaces. Everything else is
|
|
198
|
+
* theirs: never swept, never reported as drift, never removed.
|
|
199
|
+
*/
|
|
200
|
+
export function isOurVscodePrompt(fileName: string, abs: string, projectRoot: string): boolean {
|
|
201
|
+
if (fileName.startsWith(`${COMMAND_NAMESPACE}.`)) return true
|
|
202
|
+
return LEGACY_VSCODE_NAMES.has(fileName) && compiledBeforeNamespace(projectRoot) && bannerAt(abs)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Prompt files a release before the namespace wrote in `.github/prompts/`,
|
|
207
|
+
* present now — `bug-fix.prompt.md`, written today as `oc.bug-fix.prompt.md`.
|
|
208
|
+
*/
|
|
209
|
+
export function legacyVscodePrompts(projectRoot: string): string[] {
|
|
210
|
+
const dir = resolve(projectRoot, '.github', 'prompts')
|
|
211
|
+
if (!existsSync(dir) || !compiledBeforeNamespace(projectRoot)) return []
|
|
212
|
+
let entries
|
|
213
|
+
try {
|
|
214
|
+
entries = readdirSync(dir, { withFileTypes: true })
|
|
215
|
+
} catch {
|
|
216
|
+
return []
|
|
217
|
+
}
|
|
218
|
+
return entries
|
|
219
|
+
.filter((e) => e.isFile() && LEGACY_VSCODE_NAMES.has(e.name) && bannerAt(resolve(dir, e.name)))
|
|
220
|
+
.map((e) => `.github/prompts/${e.name}`)
|
|
221
|
+
.sort()
|
|
222
|
+
}
|
package/src/cli/copy.ts
CHANGED
|
@@ -66,7 +66,7 @@ async function sameText(
|
|
|
66
66
|
export async function copyDir(
|
|
67
67
|
src: string,
|
|
68
68
|
dest: string,
|
|
69
|
-
{ overwrite = false, filter, transform }: CopyDirOptions = {}
|
|
69
|
+
{ overwrite = false, filter, transform, rename }: CopyDirOptions = {}
|
|
70
70
|
): Promise<CopyResults> {
|
|
71
71
|
const entries = await readdir(src, { withFileTypes: true });
|
|
72
72
|
await mkdir(dest, { recursive: true });
|
|
@@ -75,7 +75,10 @@ export async function copyDir(
|
|
|
75
75
|
|
|
76
76
|
for (const entry of entries) {
|
|
77
77
|
const srcPath = resolve(src, entry.name);
|
|
78
|
-
const destPath = resolve(
|
|
78
|
+
const destPath = resolve(
|
|
79
|
+
dest,
|
|
80
|
+
rename && !entry.isDirectory() ? rename(entry.name) : entry.name,
|
|
81
|
+
);
|
|
79
82
|
|
|
80
83
|
if (filter && !filter(entry.name, srcPath)) continue;
|
|
81
84
|
|
|
@@ -84,6 +87,7 @@ export async function copyDir(
|
|
|
84
87
|
overwrite,
|
|
85
88
|
filter,
|
|
86
89
|
transform,
|
|
90
|
+
rename,
|
|
87
91
|
});
|
|
88
92
|
mergeCopyResults(results, sub);
|
|
89
93
|
} else {
|
package/src/cli/doctor.test.ts
CHANGED
|
@@ -205,8 +205,8 @@ describe('claude-code adapter getDoctorChecks', () => {
|
|
|
205
205
|
expect(checks.find((c) => c.path === 'CLAUDE.md')?.type).toBe('file')
|
|
206
206
|
expect(checks.find((c) => c.path === '.claude/agents/')).toBeDefined()
|
|
207
207
|
expect(checks.find((c) => c.path === '.claude/skills/')).toBeDefined()
|
|
208
|
-
// claude-code: prompts and workflows share
|
|
209
|
-
expect(checks.find((c) => c.path === '.claude/commands/')).toBeDefined()
|
|
208
|
+
// claude-code: prompts and workflows share the namespaced commands dir
|
|
209
|
+
expect(checks.find((c) => c.path === '.claude/commands/oc/')).toBeDefined()
|
|
210
210
|
expect(checks.find((c) => c.label === 'Commands directory')).toBeDefined()
|
|
211
211
|
})
|
|
212
212
|
})
|
package/src/cli/explain.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { IDE_ADAPTERS } from './adapters/index.js'
|
|
|
8
8
|
import { PLUGINS } from '../orchestrator/plugins/index.js'
|
|
9
9
|
import { c } from './prompt.js'
|
|
10
10
|
import { IDE_LABELS, type CliContext, type IdeChoice } from './types.js'
|
|
11
|
+
import { COMMAND_NAMESPACE } from './command-namespace.js'
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* `opencastle explain`: what a new teammate's assistant is given here, and
|
|
@@ -122,13 +123,24 @@ function render(report: ExplainReport, all: boolean): void {
|
|
|
122
123
|
if (lock.policy?.contextBudget) out(` ${c.dim(`budget: ${lock.policy.contextBudget} tokens`)}`)
|
|
123
124
|
out('')
|
|
124
125
|
|
|
126
|
+
// Where a prompt is a command someone types, and under which name.
|
|
127
|
+
const hasClaude = report.targets.some((t) => t.id === 'claude-code')
|
|
128
|
+
const typedIn = [
|
|
129
|
+
...(hasClaude ? ['Claude Code'] : []),
|
|
130
|
+
...(report.targets.some((t) => t.id === 'vscode') ? ['Copilot'] : []),
|
|
131
|
+
]
|
|
125
132
|
for (const kind of ['skills', 'agents', 'prompts', 'workflows'] as const) {
|
|
126
133
|
const items = ofKind(kind)
|
|
127
134
|
if (items.length === 0) continue
|
|
128
135
|
const team = items.filter(([, i]) => i.from !== 'opencastle' && !i.from.startsWith('plugin:'))
|
|
129
136
|
const integrations = items.filter(([, i]) => i.from.startsWith('plugin:'))
|
|
130
137
|
const core = items.filter(([, i]) => i.from === 'opencastle')
|
|
131
|
-
const title = {
|
|
138
|
+
const title = {
|
|
139
|
+
skills: 'Skills — loaded when a task matches the description',
|
|
140
|
+
agents: 'Agents — personas to delegate to',
|
|
141
|
+
prompts: typedIn.length > 0 ? `Commands — /${COMMAND_NAMESPACE}:<name> in ${typedIn.join(' and ')}` : 'Prompts',
|
|
142
|
+
workflows: hasClaude ? `Workflows — /${COMMAND_NAMESPACE}:workflow-<name> in Claude Code` : 'Workflows',
|
|
143
|
+
}[kind]
|
|
132
144
|
out(` ${c.bold(title)} ${c.dim(`(${items.length})`)}`)
|
|
133
145
|
for (const [ref, item] of [...team, ...integrations, ...(all ? core : [])]) {
|
|
134
146
|
const name = ref.slice(kind.length + 1)
|
package/src/cli/github-report.ts
CHANGED
|
@@ -54,7 +54,7 @@ function explain(d: Drift): string {
|
|
|
54
54
|
case 'missing':
|
|
55
55
|
return `${where} should exist but does not. Run \`opencastle sync\` and commit the result; generated config is committed like a lockfile.`
|
|
56
56
|
case 'extra':
|
|
57
|
-
return `${where} sits in generated output but no source produces it, so the next \`opencastle sync\` deletes it.`
|
|
57
|
+
return `${where} ${d.detail ? `was ${d.detail}` : 'sits in generated output but no source produces it'}, so the next \`opencastle sync\` deletes it.`
|
|
58
58
|
case 'outdated':
|
|
59
59
|
return `${where}: ${d.detail ?? 'an MCP server entry sync would change'}. Run \`opencastle sync\` and commit — it touches only entries OpenCastle wrote and nobody edited.`
|
|
60
60
|
case 'unreducible':
|
package/src/cli/init.test.ts
CHANGED
|
@@ -834,24 +834,28 @@ describe('Claude Code adapter install', () => {
|
|
|
834
834
|
expect(mcpConfig).not.toHaveProperty('servers')
|
|
835
835
|
})
|
|
836
836
|
|
|
837
|
-
it('creates prompts in .claude/commands/', async () => {
|
|
837
|
+
it('creates prompts in .claude/commands/oc/, the oc: namespace', async () => {
|
|
838
838
|
const adapter = await IDE_ADAPTERS['claude-code']()
|
|
839
839
|
await adapter.install(PKG_ROOT, tempDir, STACK_EMPTY, EMPTY_REPO_INFO)
|
|
840
840
|
|
|
841
|
-
const commandsDir = join(tempDir, '.claude', 'commands')
|
|
841
|
+
const commandsDir = join(tempDir, '.claude', 'commands', 'oc')
|
|
842
842
|
expect(existsSync(commandsDir)).toBe(true)
|
|
843
843
|
const commands = await readdir(commandsDir)
|
|
844
844
|
// Should have prompt files
|
|
845
845
|
expect(commands.length).toBeGreaterThan(0)
|
|
846
|
+
expect(commands).toContain('bug-fix.md')
|
|
846
847
|
// All should be .md files
|
|
847
848
|
expect(commands.every((f) => f.endsWith('.md'))).toBe(true)
|
|
849
|
+
// Nothing outside the namespace: the rest of the directory is the user's.
|
|
850
|
+
const top = await readdir(join(tempDir, '.claude', 'commands'))
|
|
851
|
+
expect(top).toEqual(['oc'])
|
|
848
852
|
})
|
|
849
853
|
|
|
850
854
|
it('creates workflows as commands with workflow- prefix', async () => {
|
|
851
855
|
const adapter = await IDE_ADAPTERS['claude-code']()
|
|
852
856
|
await adapter.install(PKG_ROOT, tempDir, STACK_EMPTY, EMPTY_REPO_INFO)
|
|
853
857
|
|
|
854
|
-
const commandsDir = join(tempDir, '.claude', 'commands')
|
|
858
|
+
const commandsDir = join(tempDir, '.claude', 'commands', 'oc')
|
|
855
859
|
const commands = await readdir(commandsDir)
|
|
856
860
|
// Workflow files should have the "workflow-" prefix
|
|
857
861
|
const workflows = commands.filter((f) => f.startsWith('workflow-'))
|
|
@@ -866,7 +870,8 @@ describe('Claude Code adapter install', () => {
|
|
|
866
870
|
expect(paths.framework).not.toContain('CLAUDE.md')
|
|
867
871
|
expect(paths.framework).toContain('.claude/agents/')
|
|
868
872
|
expect(paths.framework).toContain('.claude/skills/')
|
|
869
|
-
expect(paths.framework).toContain('.claude/commands/')
|
|
873
|
+
expect(paths.framework).toContain('.claude/commands/oc/')
|
|
874
|
+
expect(paths.framework).not.toContain('.claude/commands/')
|
|
870
875
|
|
|
871
876
|
expect(paths.customizable).toContain('.opencastle/')
|
|
872
877
|
expect(paths.customizable).toContain('.mcp.json')
|
package/src/cli/init.ts
CHANGED
|
@@ -12,14 +12,15 @@ import type { PluginConfig } from '../orchestrator/plugins/types.js'
|
|
|
12
12
|
import { detectRepoInfo, mergeStackIntoRepoInfo, formatRepoInfo, buildDetectedToolsSet, detectCurrentIde, detectAssistantConfigs } from './detect.js'
|
|
13
13
|
import { IDE_ADAPTERS } from './adapters/index.js'
|
|
14
14
|
import { IDE_LABELS } from './types.js'
|
|
15
|
-
import type { CliContext, CopyResults, IdeChoice, TechTool, TeamTool, StackConfig } from './types.js'
|
|
15
|
+
import type { CliContext, CopyResults, IdeAdapter, IdeChoice, TechTool, TeamTool, StackConfig } from './types.js'
|
|
16
16
|
import { bootstrapCustomizations } from './bootstrap.js'
|
|
17
17
|
import { stripManagedBlock, stripManagedBlockFromFile } from './managed-block.js'
|
|
18
|
-
import { resolveManagedPaths, declaredManagedPaths } from './managed-paths.js'
|
|
18
|
+
import { resolveManagedPaths, declaredManagedPaths, ownerOf, removeOwnedFiles } from './managed-paths.js'
|
|
19
19
|
import { noteUnreadable } from './unreadable-report.js'
|
|
20
20
|
import { resolveSources, materialize, hasErrors, formatIssues, requiredEnvVars } from './layers.js'
|
|
21
21
|
import { buildLock, writeLock, priorTeam } from './lock.js'
|
|
22
22
|
import { parseVersion, compareVersions } from './version-range.js'
|
|
23
|
+
import { COMMAND_NAMESPACE } from './command-namespace.js'
|
|
23
24
|
|
|
24
25
|
const INIT_HELP = `
|
|
25
26
|
opencastle init [options]
|
|
@@ -381,10 +382,21 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
|
|
|
381
382
|
const previous = await resolveManagedPaths({ ...existing, ide: dropped[0], ides: dropped })
|
|
382
383
|
const keeping = await declaredManagedPaths(ides as string[])
|
|
383
384
|
const kept = new Set([...keeping.framework, ...(keeping.merged ?? [])])
|
|
384
|
-
|
|
385
|
+
// And what a release before the `oc:` namespace left outside them.
|
|
386
|
+
const droppedAdapters: IdeAdapter[] = []
|
|
387
|
+
for (const id of dropped) {
|
|
388
|
+
const load = IDE_ADAPTERS[id]
|
|
389
|
+
if (load) droppedAdapters.push(await load())
|
|
390
|
+
}
|
|
391
|
+
const legacy = droppedAdapters.flatMap((a) => a.getLegacyOutputs?.(projectRoot) ?? [])
|
|
392
|
+
for (const p of [...previous.framework, ...legacy]) {
|
|
385
393
|
if (kept.has(p)) continue
|
|
386
394
|
const fullPath = resolve(projectRoot, p)
|
|
387
|
-
|
|
395
|
+
// A directory the target shares with the user loses only its own files.
|
|
396
|
+
const owns = ownerOf(droppedAdapters, p, projectRoot)
|
|
397
|
+
if (owns) {
|
|
398
|
+
removeOwnedFiles(projectRoot, p, owns)
|
|
399
|
+
} else if (p.endsWith('/')) {
|
|
388
400
|
await removeDirIfExists(fullPath)
|
|
389
401
|
} else if (existsSync(fullPath)) {
|
|
390
402
|
await unlink(fullPath)
|
|
@@ -480,9 +492,22 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
|
|
|
480
492
|
}
|
|
481
493
|
}
|
|
482
494
|
|
|
483
|
-
// If all files were skipped (orphaned install — no manifest but files exist)
|
|
484
|
-
|
|
485
|
-
|
|
495
|
+
// If all files were skipped (orphaned install — no manifest but files exist).
|
|
496
|
+
//
|
|
497
|
+
// Or if a release before the `oc:` namespace left its commands here. The
|
|
498
|
+
// namespaced files are new, so they count as created and "all skipped" no
|
|
499
|
+
// longer holds for any install that old — its stale `/bug-fix` stayed beside
|
|
500
|
+
// `/oc:bug-fix` and its agent bodies were never refreshed.
|
|
501
|
+
const previousOutput: string[] = []
|
|
502
|
+
if (!isReinit) {
|
|
503
|
+
for (const ide of ides) {
|
|
504
|
+
previousOutput.push(...((await IDE_ADAPTERS[ide]()).getLegacyOutputs?.(projectRoot) ?? []))
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
if (((totalCreated === 0 && totalSkipped > 0) || previousOutput.length > 0) && !isReinit) {
|
|
508
|
+
console.log(
|
|
509
|
+
` ${c.yellow('⚠')} Found ${totalSkipped + previousOutput.length} existing files from a previous installation.`,
|
|
510
|
+
)
|
|
486
511
|
// `--yes` is documented as "accept the detected setup without asking", and
|
|
487
512
|
// this was the one question it did not cover. On a TTY it still asked.
|
|
488
513
|
// `refuse`, because the default here overwrites. A piped run that ran out of
|
|
@@ -828,6 +853,17 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
|
|
|
828
853
|
` ${step}. Set the environment variable${envVars.length > 1 ? 's' : ''} listed above (in .env or your shell)`
|
|
829
854
|
)
|
|
830
855
|
}
|
|
856
|
+
// The commands are namespaced, and a name nobody tells you is a name nobody
|
|
857
|
+
// types. Only where `/oc:` is a slash command.
|
|
858
|
+
const withCommands = ides.filter((id) => id === 'claude-code' || id === 'vscode')
|
|
859
|
+
if (withCommands.length > 0) {
|
|
860
|
+
step++
|
|
861
|
+
const where = withCommands.map((id) => (id === 'vscode' ? 'Copilot Chat' : 'Claude Code')).join(' or ')
|
|
862
|
+
console.log(
|
|
863
|
+
` ${step}. Type ${c.cyan(`/${COMMAND_NAMESPACE}:`)} in ${where} for OpenCastle's commands — ` +
|
|
864
|
+
`${c.cyan(`/${COMMAND_NAMESPACE}:bootstrap-customizations`)} first on an existing codebase`,
|
|
865
|
+
)
|
|
866
|
+
}
|
|
831
867
|
step++
|
|
832
868
|
console.log(` ${step}. Commit the .opencastle/ folder to your repository`)
|
|
833
869
|
|
package/src/cli/managed-paths.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs'
|
|
1
|
+
import { existsSync, readdirSync, rmdirSync, rmSync, statSync } from 'node:fs'
|
|
2
2
|
import { resolve } from 'node:path'
|
|
3
3
|
import { IDE_ADAPTERS } from './adapters/index.js'
|
|
4
|
-
import type { ManagedPaths, Manifest } from './types.js'
|
|
4
|
+
import type { IdeAdapter, ManagedPaths, Manifest } from './types.js'
|
|
5
|
+
import { CLAUDE_COMMANDS_DIR } from './command-namespace.js'
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* What the manifest *should* say, given what the adapters declare today.
|
|
@@ -36,6 +37,20 @@ export const ROOT_INSTRUCTION_FILES = [
|
|
|
36
37
|
'.github/copilot-instructions.md',
|
|
37
38
|
] as const
|
|
38
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Framework paths a release recorded that today's compiler has narrowed.
|
|
42
|
+
*
|
|
43
|
+
* Before the `oc:` namespace the whole of `.claude/commands/` was generated, and manifests
|
|
44
|
+
* recorded it. Commands now live under `.claude/commands/oc/`, and the rest of
|
|
45
|
+
* the directory is the user's — so a stored `.claude/commands/` must not stay
|
|
46
|
+
* in `framework`, where `remove` and a dropped target's cleanup would delete
|
|
47
|
+
* every command a person wrote there. What those releases left at the top is
|
|
48
|
+
* found by its banner instead (`getLegacyOutputs`).
|
|
49
|
+
*/
|
|
50
|
+
const SUPERSEDED_FRAMEWORK: Record<string, string> = {
|
|
51
|
+
'.claude/commands/': `.claude/${CLAUDE_COMMANDS_DIR}/`,
|
|
52
|
+
}
|
|
53
|
+
|
|
39
54
|
function unique(values: string[]): string[] {
|
|
40
55
|
return [...new Set(values)]
|
|
41
56
|
}
|
|
@@ -78,7 +93,7 @@ export async function resolveManagedPaths(manifest: Manifest): Promise<Required<
|
|
|
78
93
|
|
|
79
94
|
return {
|
|
80
95
|
framework: unique([
|
|
81
|
-
...(stored?.framework ?? []),
|
|
96
|
+
...(stored?.framework ?? []).map((p) => SUPERSEDED_FRAMEWORK[p] ?? p),
|
|
82
97
|
...declared.framework,
|
|
83
98
|
]).filter((p) => !isMerged(p)),
|
|
84
99
|
customizable: unique([
|
|
@@ -95,6 +110,61 @@ export async function resolveManagedPaths(manifest: Manifest): Promise<Required<
|
|
|
95
110
|
}
|
|
96
111
|
}
|
|
97
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Which files in a framework directory the given targets wrote, when one of
|
|
115
|
+
* them shares that directory with the user — `undefined` when the directory is
|
|
116
|
+
* wholly generated and can be removed whole.
|
|
117
|
+
*/
|
|
118
|
+
export function ownerOf(
|
|
119
|
+
adapters: IdeAdapter[],
|
|
120
|
+
dir: string,
|
|
121
|
+
projectRoot: string,
|
|
122
|
+
): ((_rel: string) => boolean) | undefined {
|
|
123
|
+
const sharing = adapters.filter((a) => a.ownsFile && a.getSharedDirs?.().includes(dir))
|
|
124
|
+
if (sharing.length === 0) return undefined
|
|
125
|
+
return (rel) => sharing.every((a) => a.ownsFile!(rel, projectRoot))
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Delete the files at the top of a shared directory that `owns` claims, and the
|
|
130
|
+
* directory itself if that empties it — never anything of the user's.
|
|
131
|
+
*
|
|
132
|
+
* Only the top level: the one shared directory, `.github/prompts/`, is read
|
|
133
|
+
* there and nowhere deeper, so nothing below it is ours, and walking into a
|
|
134
|
+
* person's subfolders could only delete their empty ones or stop at one it
|
|
135
|
+
* cannot read. A path that is not a readable directory is left for a person.
|
|
136
|
+
* Returns how many files went.
|
|
137
|
+
*/
|
|
138
|
+
export function removeOwnedFiles(projectRoot: string, dir: string, owns: (_rel: string) => boolean): number {
|
|
139
|
+
const root = resolve(projectRoot, dir)
|
|
140
|
+
const prefix = dir.endsWith('/') ? dir : `${dir}/`
|
|
141
|
+
let entries
|
|
142
|
+
try {
|
|
143
|
+
if (!statSync(root).isDirectory()) return 0
|
|
144
|
+
entries = readdirSync(root, { withFileTypes: true })
|
|
145
|
+
} catch {
|
|
146
|
+
return 0
|
|
147
|
+
}
|
|
148
|
+
let removed = 0
|
|
149
|
+
for (const entry of entries) {
|
|
150
|
+
if (entry.isDirectory() || !owns(`${prefix}${entry.name}`)) continue
|
|
151
|
+
try {
|
|
152
|
+
// `rmSync` rather than `unlinkSync`: on Windows it gets past a read-only
|
|
153
|
+
// file, which `unlink` fails on with EPERM.
|
|
154
|
+
rmSync(resolve(root, entry.name), { force: true })
|
|
155
|
+
removed++
|
|
156
|
+
} catch {
|
|
157
|
+
// Left for a person; one stubborn file must not stop the uninstall.
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
try {
|
|
161
|
+
if (readdirSync(root).length === 0) rmdirSync(root)
|
|
162
|
+
} catch {
|
|
163
|
+
// As above.
|
|
164
|
+
}
|
|
165
|
+
return removed
|
|
166
|
+
}
|
|
167
|
+
|
|
98
168
|
/**
|
|
99
169
|
* Files an install is not complete without.
|
|
100
170
|
*
|
package/src/cli/manifest.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { resolve, dirname, relative } from 'node:path';
|
|
|
3
3
|
import { existsSync, readdirSync } from 'node:fs';
|
|
4
4
|
import type { Manifest } from './types.js';
|
|
5
5
|
import { UnreadableConfigError } from './types.js';
|
|
6
|
+
import { COMMAND_NAMESPACE } from './command-namespace.js';
|
|
6
7
|
|
|
7
8
|
const MANIFEST_FILE = '.opencastle/manifest.json';
|
|
8
9
|
|
|
@@ -91,5 +92,6 @@ export function createManifest(version: string, ide: string, ides?: string[]): M
|
|
|
91
92
|
ides: ides ?? [ide],
|
|
92
93
|
installedAt: new Date().toISOString(),
|
|
93
94
|
updatedAt: new Date().toISOString(),
|
|
95
|
+
commandNamespace: COMMAND_NAMESPACE,
|
|
94
96
|
};
|
|
95
97
|
}
|
package/src/cli/remove.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { removeDirIfExists } from './copy.js'
|
|
|
6
6
|
import { removeGitignoreBlock, predictGitignoreStrip, LOCAL_DIRS } from './gitignore.js'
|
|
7
7
|
import { confirm, select, closePrompts, c } from './prompt.js'
|
|
8
8
|
import { stripManagedBlockFromFile, predictStripFile } from './managed-block.js'
|
|
9
|
-
import { resolveManagedPaths } from './managed-paths.js'
|
|
9
|
+
import { resolveManagedPaths, ownerOf, removeOwnedFiles } from './managed-paths.js'
|
|
10
10
|
import { stripManagedMcpServers, getMcpConfigRelPath, willKeepSomethingAfterStrip } from './mcp.js'
|
|
11
11
|
import { priorTeam } from './lock.js'
|
|
12
12
|
import { IDE_ADAPTERS } from './adapters/index.js'
|
|
@@ -216,7 +216,18 @@ export default async function remove({ args }: CliContext): Promise<void> {
|
|
|
216
216
|
// An install from before this field existed records nothing, and absence means
|
|
217
217
|
// "unknown" — which is treated as "not ours to delete".
|
|
218
218
|
const createdConfigs = new Set(manifest.createdConfigs ?? [])
|
|
219
|
-
|
|
219
|
+
// Commands a release before the namespace left at the top of `.claude/commands/`,
|
|
220
|
+
// outside today's framework directories — found by the banner they carry, so
|
|
221
|
+
// a command the user wrote there is not among them.
|
|
222
|
+
const legacyOutputs: string[] = []
|
|
223
|
+
const adapters = await Promise.all(ides.map((ide) => IDE_ADAPTERS[ide]()))
|
|
224
|
+
for (const adapter of adapters) {
|
|
225
|
+
legacyOutputs.push(...(adapter.getLegacyOutputs?.(projectRoot) ?? []))
|
|
226
|
+
}
|
|
227
|
+
const frameworkPaths = [
|
|
228
|
+
...managed.framework.filter((p) => !mcpPaths.has(p)),
|
|
229
|
+
...legacyOutputs.filter((p) => !managed.framework.includes(p)),
|
|
230
|
+
]
|
|
220
231
|
// `.opencastle/` is handled explicitly below, so drop it here — listing it in
|
|
221
232
|
// both places printed it twice and counted it twice in "Removed N path(s)".
|
|
222
233
|
const customizablePaths = managed.customizable.filter(
|
|
@@ -236,7 +247,9 @@ export default async function remove({ args }: CliContext): Promise<void> {
|
|
|
236
247
|
} else {
|
|
237
248
|
console.log(` ${c.bold('Deleted')}\n`)
|
|
238
249
|
for (const p of [...frameworkPaths, ...customizablePaths]) {
|
|
239
|
-
|
|
250
|
+
// A directory shared with the user — `.github/prompts/` — loses only ours.
|
|
251
|
+
const shared = ownerOf(adapters, p, projectRoot) ? c.dim(' — only the files OpenCastle wrote') : ''
|
|
252
|
+
console.log(` ${c.red('-')} ${c.dim(p)}${shared}`)
|
|
240
253
|
}
|
|
241
254
|
// Named plainly: this is the one path in the list that holds writing of the
|
|
242
255
|
// user's own, and the command spends the rest of its effort preserving
|
|
@@ -317,7 +330,10 @@ export default async function remove({ args }: CliContext): Promise<void> {
|
|
|
317
330
|
// Only if it was there. The manifest still lists paths for a target that
|
|
318
331
|
// has since been dropped, so the count claimed to have removed
|
|
319
332
|
// directories that had not existed for releases.
|
|
320
|
-
|
|
333
|
+
const owns = ownerOf(adapters, p, projectRoot)
|
|
334
|
+
if (owns) {
|
|
335
|
+
if (removeOwnedFiles(projectRoot, p, owns) > 0) removed++
|
|
336
|
+
} else if (existsSync(resolve(projectRoot, p))) {
|
|
321
337
|
await removeDirIfExists(resolve(projectRoot, p))
|
|
322
338
|
removed++
|
|
323
339
|
}
|
package/src/cli/sync-check.ts
CHANGED
|
@@ -164,6 +164,7 @@ function comparePath(
|
|
|
164
164
|
projectRoot: string,
|
|
165
165
|
ide: string,
|
|
166
166
|
drift: Drift[],
|
|
167
|
+
owns?: (_rel: string) => boolean,
|
|
167
168
|
): number {
|
|
168
169
|
const fresh = resolve(freshRoot, managedPath)
|
|
169
170
|
const actual = resolve(projectRoot, managedPath)
|
|
@@ -208,7 +209,11 @@ function comparePath(
|
|
|
208
209
|
const expected = new Set(generated)
|
|
209
210
|
for (const rel of filesUnder(actual)) {
|
|
210
211
|
if (expected.has(rel)) continue
|
|
211
|
-
|
|
212
|
+
const shown = `${managedPath.replace(/\/$/, '')}/${rel}`
|
|
213
|
+
// A file the target shares the directory with someone over — their own
|
|
214
|
+
// prompt beside ours in `.github/prompts/` — is not drift.
|
|
215
|
+
if (owns && !owns(shown)) continue
|
|
216
|
+
drift.push({ ide, path: shown, kind: 'extra' })
|
|
212
217
|
}
|
|
213
218
|
return checked
|
|
214
219
|
}
|
|
@@ -347,7 +352,18 @@ async function compareProject(
|
|
|
347
352
|
// most likely to be edited by hand, would be the only thing never checked.
|
|
348
353
|
const managed = adapter.getManagedPaths()
|
|
349
354
|
for (const managedPath of [...managed.framework, ...(managed.merged ?? [])]) {
|
|
350
|
-
checked += comparePath(managedPath, scratch, projectRoot, ide, drift
|
|
355
|
+
checked += comparePath(managedPath, scratch, projectRoot, ide, drift, adapter.ownsFile
|
|
356
|
+
? (rel) => adapter.ownsFile!(rel, projectRoot)
|
|
357
|
+
: undefined)
|
|
358
|
+
}
|
|
359
|
+
// Output an earlier release left where this one no longer writes — a
|
|
360
|
+
// stale `/bug-fix` beside `/oc:bug-fix`. The next sync removes it.
|
|
361
|
+
for (const rel of adapter.getLegacyOutputs?.(projectRoot) ?? []) {
|
|
362
|
+
const detail = 'written by a release before the oc: namespace'
|
|
363
|
+
// A legacy prompt inside a compared directory is already reported.
|
|
364
|
+
const seen = drift.find((d) => d.ide === ide && d.path === rel)
|
|
365
|
+
if (seen) seen.detail = detail
|
|
366
|
+
else drift.push({ ide, path: rel, kind: 'extra', detail })
|
|
351
367
|
}
|
|
352
368
|
} finally {
|
|
353
369
|
rmSync(scratch, { recursive: true, force: true })
|
|
@@ -712,7 +728,7 @@ function render(report: CheckReport): void {
|
|
|
712
728
|
}
|
|
713
729
|
if (extra.length > 0) {
|
|
714
730
|
console.log(` ${c.bold('Not produced by any source')} ${c.dim('(removed on the next sync)')}`)
|
|
715
|
-
for (const d of extra) console.log(` ${c.red('+')} ${d.path} ${c.dim(`(${d.ide})`)}`)
|
|
731
|
+
for (const d of extra) console.log(` ${c.red('+')} ${d.path} ${c.dim(`(${d.ide}${d.detail ? ` — ${d.detail}` : ''})`)}`)
|
|
716
732
|
console.log('')
|
|
717
733
|
}
|
|
718
734
|
|