opencastle 1.0.0 → 1.1.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/README.md +9 -4
- package/dist/cli/adapters/claude-code.d.ts +8 -4
- package/dist/cli/adapters/claude-code.d.ts.map +1 -1
- package/dist/cli/adapters/claude-code.js +13 -7
- package/dist/cli/adapters/claude-code.js.map +1 -1
- package/dist/cli/adapters/codex.d.ts +19 -6
- package/dist/cli/adapters/codex.d.ts.map +1 -1
- package/dist/cli/adapters/codex.js +24 -7
- package/dist/cli/adapters/codex.js.map +1 -1
- package/dist/cli/adapters/single-file-base.d.ts +15 -1
- package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
- package/dist/cli/adapters/single-file-base.js +46 -21
- 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/codex-target.test.d.ts +2 -0
- package/dist/cli/codex-target.test.d.ts.map +1 -0
- package/dist/cli/codex-target.test.js +154 -0
- package/dist/cli/codex-target.test.js.map +1 -0
- package/dist/cli/command-namespace.d.ts +91 -0
- package/dist/cli/command-namespace.d.ts.map +1 -0
- package/dist/cli/command-namespace.js +218 -0
- package/dist/cli/command-namespace.js.map +1 -0
- package/dist/cli/command-namespace.test.d.ts +2 -0
- package/dist/cli/command-namespace.test.d.ts.map +1 -0
- package/dist/cli/command-namespace.test.js +356 -0
- package/dist/cli/command-namespace.test.js.map +1 -0
- package/dist/cli/copy.d.ts +1 -1
- package/dist/cli/copy.d.ts.map +1 -1
- package/dist/cli/copy.js +3 -2
- package/dist/cli/copy.js.map +1 -1
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +2 -1
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/doctor.test.js +2 -2
- package/dist/cli/doctor.test.js.map +1 -1
- package/dist/cli/explain.d.ts.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 +45 -10
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/init.test.js +31 -14
- 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 +74 -2
- package/dist/cli/managed-paths.js.map +1 -1
- package/dist/cli/manifest.d.ts.map +1 -1
- package/dist/cli/manifest.js +2 -0
- package/dist/cli/manifest.js.map +1 -1
- package/dist/cli/mcp-audit.d.ts.map +1 -1
- package/dist/cli/mcp-audit.js +7 -3
- package/dist/cli/mcp-audit.js.map +1 -1
- package/dist/cli/mcp-file.d.ts +37 -0
- package/dist/cli/mcp-file.d.ts.map +1 -0
- package/dist/cli/mcp-file.js +291 -0
- package/dist/cli/mcp-file.js.map +1 -0
- package/dist/cli/mcp-file.test.d.ts +2 -0
- package/dist/cli/mcp-file.test.d.ts.map +1 -0
- package/dist/cli/mcp-file.test.js +121 -0
- package/dist/cli/mcp-file.test.js.map +1 -0
- package/dist/cli/mcp.d.ts +15 -0
- package/dist/cli/mcp.d.ts.map +1 -1
- package/dist/cli/mcp.js +123 -56
- package/dist/cli/mcp.js.map +1 -1
- package/dist/cli/remove.d.ts.map +1 -1
- package/dist/cli/remove.js +45 -8
- package/dist/cli/remove.js.map +1 -1
- package/dist/cli/sync-check.d.ts.map +1 -1
- package/dist/cli/sync-check.js +26 -7
- package/dist/cli/sync-check.js.map +1 -1
- package/dist/cli/sync-check.test.js +2 -2
- package/dist/cli/sync-check.test.js.map +1 -1
- package/dist/cli/types.d.ts +37 -2
- package/dist/cli/types.d.ts.map +1 -1
- package/dist/cli/types.js +3 -0
- package/dist/cli/types.js.map +1 -1
- package/dist/cli/unreadable-report.d.ts +7 -0
- package/dist/cli/unreadable-report.d.ts.map +1 -1
- package/dist/cli/unreadable-report.js +14 -0
- package/dist/cli/unreadable-report.js.map +1 -1
- package/dist/cli/update.d.ts.map +1 -1
- package/dist/cli/update.js +69 -5
- package/dist/cli/update.js.map +1 -1
- package/package.json +3 -2
- package/src/cli/adapters/claude-code.ts +13 -7
- package/src/cli/adapters/codex.ts +25 -7
- package/src/cli/adapters/single-file-base.ts +66 -26
- package/src/cli/adapters/vscode.ts +51 -10
- package/src/cli/codex-target.test.ts +178 -0
- package/src/cli/command-namespace.test.ts +417 -0
- package/src/cli/command-namespace.ts +222 -0
- package/src/cli/copy.ts +6 -2
- package/src/cli/doctor.test.ts +2 -2
- package/src/cli/doctor.ts +3 -2
- package/src/cli/explain.ts +13 -1
- package/src/cli/github-report.ts +1 -1
- package/src/cli/init.test.ts +31 -14
- package/src/cli/init.ts +48 -11
- package/src/cli/managed-paths.ts +75 -3
- package/src/cli/manifest.ts +2 -0
- package/src/cli/mcp-audit.ts +7 -3
- package/src/cli/mcp-file.test.ts +138 -0
- package/src/cli/mcp-file.ts +302 -0
- package/src/cli/mcp.ts +130 -60
- package/src/cli/remove.ts +40 -8
- package/src/cli/sync-check.test.ts +2 -2
- package/src/cli/sync-check.ts +23 -6
- package/src/cli/types.ts +37 -2
- package/src/cli/unreadable-report.ts +14 -0
- package/src/cli/update.ts +73 -5
- 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';
|
|
@@ -6,6 +6,7 @@ import { mergeCopyResults, copyDir } from '../copy.js';
|
|
|
6
6
|
import { scaffoldMcpConfigInto } from '../mcp.js';
|
|
7
7
|
import { getAgentTransform } from '../stack-config.js';
|
|
8
8
|
import { withSource } from '../layers.js';
|
|
9
|
+
import { isOurVscodePrompt, legacyVscodePrompts, vscodePromptFile, withCommandName } from '../command-namespace.js';
|
|
9
10
|
/**
|
|
10
11
|
* VS Code / GitHub Copilot adapter.
|
|
11
12
|
*
|
|
@@ -16,7 +17,7 @@ import { withSource } from '../layers.js';
|
|
|
16
17
|
* instructions/ → .github/instructions/
|
|
17
18
|
* skills/ → .github/skills/
|
|
18
19
|
* agent-workflows/ → .github/agent-workflows/
|
|
19
|
-
* prompts
|
|
20
|
+
* prompts/<name>.prompt.md → .github/prompts/oc.<name>.prompt.md (/oc:<name>)
|
|
20
21
|
* customizations/ → .opencastle/ (scaffolded once)
|
|
21
22
|
*/
|
|
22
23
|
export const IDE_ID = 'vscode';
|
|
@@ -40,6 +41,18 @@ function copyRulesFor(dir, stack) {
|
|
|
40
41
|
if (dir === 'agents') {
|
|
41
42
|
return { transform: stack ? getAgentTransform(stack) : undefined };
|
|
42
43
|
}
|
|
44
|
+
if (dir === 'prompts') {
|
|
45
|
+
// The `oc:` namespace. VS Code reads prompt files from the top of
|
|
46
|
+
// `.github/prompts/` only, so it goes in the file name as `oc.` and in the
|
|
47
|
+
// command name — the frontmatter `name`, which VS Code prefers — as `oc:`.
|
|
48
|
+
const PROMPT = '.prompt.md';
|
|
49
|
+
return {
|
|
50
|
+
rename: (name) => (name.endsWith(PROMPT) ? vscodePromptFile(name) : name),
|
|
51
|
+
transform: (content, srcPath) => srcPath.endsWith(PROMPT)
|
|
52
|
+
? withCommandName(content, basename(srcPath).slice(0, -PROMPT.length))
|
|
53
|
+
: content,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
43
56
|
if (dir === 'agent-workflows') {
|
|
44
57
|
// The directory's own README documents the templates for contributors; it is
|
|
45
58
|
// not one of them, and no other adapter installs it.
|
|
@@ -105,8 +118,7 @@ async function installFrom(src, projectRoot, stack, repoInfo) {
|
|
|
105
118
|
if (!existsSync(srcDir))
|
|
106
119
|
continue;
|
|
107
120
|
const destDir = resolve(destRoot, dir);
|
|
108
|
-
const
|
|
109
|
-
const sub = await copyDir(srcDir, destDir, { filter, transform });
|
|
121
|
+
const sub = await copyDir(srcDir, destDir, copyRulesFor(dir, stack));
|
|
110
122
|
mergeCopyResults(results, sub);
|
|
111
123
|
}
|
|
112
124
|
// MCP server config → .vscode/mcp.json (scaffold once)
|
|
@@ -133,8 +145,13 @@ async function updateFrom(src, projectRoot, stack) {
|
|
|
133
145
|
const beforeSweep = new Map();
|
|
134
146
|
for (const dir of FRAMEWORK_DIRS) {
|
|
135
147
|
const abs = resolve(destRoot, dir);
|
|
136
|
-
for (const rel of filesUnderDir(abs))
|
|
137
|
-
|
|
148
|
+
for (const rel of filesUnderDir(abs)) {
|
|
149
|
+
const shown = `.github/${dir}/${rel}`;
|
|
150
|
+
// A prompt someone wrote beside ours is theirs to keep.
|
|
151
|
+
if (!ownsFile(shown, projectRoot))
|
|
152
|
+
continue;
|
|
153
|
+
beforeSweep.set(resolve(abs, rel), shown);
|
|
154
|
+
}
|
|
138
155
|
}
|
|
139
156
|
// Recompile over the existing tree, then sweep — not the other way round.
|
|
140
157
|
//
|
|
@@ -149,8 +166,7 @@ async function updateFrom(src, projectRoot, stack) {
|
|
|
149
166
|
if (!existsSync(srcDir))
|
|
150
167
|
continue;
|
|
151
168
|
const destDir = resolve(destRoot, dir);
|
|
152
|
-
const
|
|
153
|
-
const sub = await copyDir(srcDir, destDir, { overwrite: true, filter, transform });
|
|
169
|
+
const sub = await copyDir(srcDir, destDir, { overwrite: true, ...copyRulesFor(dir, stack) });
|
|
154
170
|
mergeCopyResults(results, sub);
|
|
155
171
|
for (const abs of sub.visited ?? [])
|
|
156
172
|
visited.add(abs);
|
|
@@ -169,6 +185,30 @@ async function updateFrom(src, projectRoot, stack) {
|
|
|
169
185
|
}
|
|
170
186
|
return results;
|
|
171
187
|
}
|
|
188
|
+
const PROMPTS_DIR = '.github/prompts/';
|
|
189
|
+
/**
|
|
190
|
+
* `.github/prompts/` is shared: VS Code reads prompt files only at its top, so
|
|
191
|
+
* OpenCastle's `oc.` files and a person's own sit side by side. Every other
|
|
192
|
+
* framework directory is wholly generated.
|
|
193
|
+
*/
|
|
194
|
+
export function ownsFile(rel, projectRoot) {
|
|
195
|
+
const norm = rel.replace(/\\/g, '/');
|
|
196
|
+
if (!norm.startsWith(PROMPTS_DIR))
|
|
197
|
+
return true;
|
|
198
|
+
const name = norm.slice(PROMPTS_DIR.length);
|
|
199
|
+
// VS Code reads nothing deeper, and OpenCastle writes nothing deeper.
|
|
200
|
+
if (name.includes('/'))
|
|
201
|
+
return false;
|
|
202
|
+
return isOurVscodePrompt(name, resolve(projectRoot, norm), projectRoot);
|
|
203
|
+
}
|
|
204
|
+
/** The one framework directory this target shares with the user. */
|
|
205
|
+
export function getSharedDirs() {
|
|
206
|
+
return [PROMPTS_DIR];
|
|
207
|
+
}
|
|
208
|
+
/** The un-namespaced prompts an earlier release wrote. `update`'s sweep removes them. */
|
|
209
|
+
export function getLegacyOutputs(projectRoot) {
|
|
210
|
+
return legacyVscodePrompts(projectRoot);
|
|
211
|
+
}
|
|
172
212
|
export function getManagedPaths() {
|
|
173
213
|
return {
|
|
174
214
|
framework: FRAMEWORK_DIRS.map((d) => `.github/${d}/`),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vscode.js","sourceRoot":"","sources":["../../../src/cli/adapters/vscode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"vscode.js","sourceRoot":"","sources":["../../../src/cli/adapters/vscode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAA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GAAG,GAAa,EAAE,CAAA;IACxB,MAAM,IAAI,GAAG,CAAC,GAAW,EAAE,MAAc,EAAQ,EAAE;QACjD,KAAK,MAAM,KAAK,IAAI,WAAW,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;YAC9D,IAAI,KAAK,CAAC,WAAW,EAAE;gBAAE,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,GAAG,KAAK,CAAC,IAAI,GAAG,CAAC,CAAA;;gBAC7E,GAAG,CAAC,IAAI,CAAC,GAAG,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;QACzC,CAAC;IACH,CAAC,CAAA;IACD,IAAI,UAAU,CAAC,IAAI,CAAC;QAAE,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;IACpC,OAAO,GAAG,CAAA;AACZ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex-target.test.d.ts","sourceRoot":"","sources":["../../src/cli/codex-target.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codex CLI, driven through the built CLI the way a project meets it.
|
|
3
|
+
*
|
|
4
|
+
* Codex reads a repository's skills only from `.agents/skills/` and its MCP
|
|
5
|
+
* servers only from `.codex/config.toml`. Every release up to 1.0.0 wrote
|
|
6
|
+
* `.codex/skills/` and `.codex/mcp.json` instead, so a Codex user got the root
|
|
7
|
+
* AGENTS.md and nothing else — and every check reported the install healthy,
|
|
8
|
+
* because each compared the project against the same wrong paths.
|
|
9
|
+
*/
|
|
10
|
+
import { execFileSync } from 'node:child_process';
|
|
11
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
12
|
+
import { tmpdir } from 'node:os';
|
|
13
|
+
import { dirname, join, resolve } from 'node:path';
|
|
14
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
15
|
+
import { parse as parseToml } from 'smol-toml';
|
|
16
|
+
import { teamEntryFor } from './mcp.js';
|
|
17
|
+
const pkgRoot = resolve(import.meta.dirname, '..', '..');
|
|
18
|
+
const cli = join(pkgRoot, 'bin', 'cli.mjs');
|
|
19
|
+
const built = existsSync(join(pkgRoot, 'dist', 'cli', 'init.js'));
|
|
20
|
+
const USERS_CONFIG = `# Codex settings, written by hand
|
|
21
|
+
model = "gpt-5-codex"
|
|
22
|
+
approval_policy = "on-request"
|
|
23
|
+
|
|
24
|
+
[mcp_servers.mine]
|
|
25
|
+
command = "my-own-server"
|
|
26
|
+
`;
|
|
27
|
+
function write(root, files) {
|
|
28
|
+
for (const [rel, text] of Object.entries(files)) {
|
|
29
|
+
mkdirSync(dirname(join(root, rel)), { recursive: true });
|
|
30
|
+
writeFileSync(join(root, rel), text);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function run(project, ...args) {
|
|
34
|
+
return execFileSync('node', [cli, ...args], { cwd: project, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
|
|
35
|
+
}
|
|
36
|
+
function servers(project) {
|
|
37
|
+
const text = readFileSync(join(project, '.codex/config.toml'), 'utf8');
|
|
38
|
+
return (parseToml(text).mcp_servers ?? {});
|
|
39
|
+
}
|
|
40
|
+
describe("a team server in Codex's own fields", () => {
|
|
41
|
+
it('sends a bearer token, and a header that is one variable, from the environment', () => {
|
|
42
|
+
const { entry } = teamEntryFor('acme-docs', {
|
|
43
|
+
type: 'http',
|
|
44
|
+
url: 'https://docs.acme.example/mcp',
|
|
45
|
+
headers: { Authorization: 'Bearer ${ACME_DOCS_TOKEN}', 'X-Tenant': '${ACME_TENANT}', 'X-Client': 'opencastle' },
|
|
46
|
+
}, 'codex');
|
|
47
|
+
expect(entry).toEqual({
|
|
48
|
+
url: 'https://docs.acme.example/mcp',
|
|
49
|
+
bearer_token_env_var: 'ACME_DOCS_TOKEN',
|
|
50
|
+
env_http_headers: { 'X-Tenant': 'ACME_TENANT' },
|
|
51
|
+
http_headers: { 'X-Client': 'opencastle' },
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
it('forwards a variable the server reads under its own name, and keeps literal values', () => {
|
|
55
|
+
const { entry } = teamEntryFor('acme-flags', { command: 'npx', args: ['-y', '@acme/flags-mcp@1.2.3'], env: { FLAGS_TOKEN: '${FLAGS_TOKEN}', MODE: 'ci' } }, 'codex');
|
|
56
|
+
expect(entry).toEqual({
|
|
57
|
+
command: 'npx',
|
|
58
|
+
args: ['-y', '@acme/flags-mcp@1.2.3'],
|
|
59
|
+
env: { MODE: 'ci' },
|
|
60
|
+
env_vars: ['FLAGS_TOKEN'],
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
it('leaves a reference it cannot express as written, for doctor to name', () => {
|
|
64
|
+
const { entry } = teamEntryFor('x', { command: 'srv', env: { API_KEY: '${OTHER_NAME}' } }, 'codex');
|
|
65
|
+
expect(entry).toEqual({ command: 'srv', env: { API_KEY: '${OTHER_NAME}' } });
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
describe.skipIf(!built)('Codex CLI as a target', () => {
|
|
69
|
+
let project;
|
|
70
|
+
beforeEach(() => {
|
|
71
|
+
project = mkdtempSync(join(tmpdir(), 'oc-codex-target-'));
|
|
72
|
+
execFileSync('git', ['init', '-q'], { cwd: project });
|
|
73
|
+
// A project that uses Supabase, so the stack carries a remote server, and
|
|
74
|
+
// a Codex setup of the user's own that every write must leave alone.
|
|
75
|
+
write(project, {
|
|
76
|
+
'package.json': JSON.stringify({ name: 'app', dependencies: { '@supabase/supabase-js': '^2.0.0' } }),
|
|
77
|
+
'.codex/config.toml': USERS_CONFIG,
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
afterEach(() => rmSync(project, { recursive: true, force: true }));
|
|
81
|
+
it('installs skills and servers where Codex reads them, after the user’s own settings', () => {
|
|
82
|
+
run(project, 'init', '--yes');
|
|
83
|
+
expect(existsSync(join(project, '.agents/skills/testing-workflow/SKILL.md'))).toBe(true);
|
|
84
|
+
expect(existsSync(join(project, '.codex/skills'))).toBe(false);
|
|
85
|
+
expect(existsSync(join(project, '.codex/mcp.json'))).toBe(false);
|
|
86
|
+
const text = readFileSync(join(project, '.codex/config.toml'), 'utf8');
|
|
87
|
+
expect(text.startsWith(USERS_CONFIG)).toBe(true);
|
|
88
|
+
expect(servers(project).Supabase).toEqual({ url: 'https://mcp.supabase.com/mcp' });
|
|
89
|
+
expect(servers(project).mine).toEqual({ command: 'my-own-server' });
|
|
90
|
+
run(project, 'sync', '--check');
|
|
91
|
+
});
|
|
92
|
+
it('the sync that upgrades a 1.0.0 install moves skills and servers, and keeps what is the user’s', () => {
|
|
93
|
+
run(project, 'init', '--yes');
|
|
94
|
+
// Back to how 1.0.0 left it: skills under `.codex/skills/`, servers in a
|
|
95
|
+
// `.codex/mcp.json` it created, and a manifest that recorded both.
|
|
96
|
+
rmSync(join(project, '.agents'), { recursive: true, force: true });
|
|
97
|
+
write(project, {
|
|
98
|
+
'.codex/config.toml': USERS_CONFIG,
|
|
99
|
+
'.codex/skills/testing-workflow/SKILL.md': '---\nname: testing-workflow\ndescription: old\n---\nold\n',
|
|
100
|
+
'.codex/mcp.json': JSON.stringify({ mcpServers: { Supabase: { url: 'https://mcp.supabase.com/mcp' } } }, null, 2) + '\n',
|
|
101
|
+
});
|
|
102
|
+
const path = join(project, '.opencastle/manifest.json');
|
|
103
|
+
const manifest = JSON.parse(readFileSync(path, 'utf8'));
|
|
104
|
+
manifest.version = '1.0.0';
|
|
105
|
+
manifest.createdConfigs = ['.codex/mcp.json'];
|
|
106
|
+
manifest.managedPaths = {
|
|
107
|
+
framework: ['.codex/agents/', '.codex/skills/', '.codex/prompts/', '.codex/workflows/'],
|
|
108
|
+
customizable: ['.opencastle/', '.codex/mcp.json'],
|
|
109
|
+
merged: ['AGENTS.md'],
|
|
110
|
+
};
|
|
111
|
+
writeFileSync(path, JSON.stringify(manifest, null, 2));
|
|
112
|
+
const out = run(project, 'sync', '--yes');
|
|
113
|
+
expect(out).toContain('Removed .codex/mcp.json');
|
|
114
|
+
expect(existsSync(join(project, '.codex/skills'))).toBe(false);
|
|
115
|
+
expect(existsSync(join(project, '.codex/mcp.json'))).toBe(false);
|
|
116
|
+
expect(readFileSync(join(project, '.agents/skills/testing-workflow/SKILL.md'), 'utf8')).not.toContain('description: old');
|
|
117
|
+
expect(readFileSync(join(project, '.codex/config.toml'), 'utf8').startsWith(USERS_CONFIG)).toBe(true);
|
|
118
|
+
expect(servers(project).Supabase).toBeDefined();
|
|
119
|
+
const after = JSON.parse(readFileSync(path, 'utf8'));
|
|
120
|
+
expect(after.createdConfigs ?? []).not.toContain('.codex/mcp.json');
|
|
121
|
+
expect(after.managedPaths?.framework).toContain('.agents/skills/');
|
|
122
|
+
expect(after.managedPaths?.framework).not.toContain('.codex/skills/');
|
|
123
|
+
run(project, 'sync', '--check');
|
|
124
|
+
});
|
|
125
|
+
it('keeps servers a person added to the old .codex/mcp.json, and says where they belong', () => {
|
|
126
|
+
run(project, 'init', '--yes');
|
|
127
|
+
write(project, {
|
|
128
|
+
'.codex/mcp.json': JSON.stringify({ mcpServers: { Supabase: { url: 'https://mcp.supabase.com/mcp' }, theirs: { command: 'x' } } }),
|
|
129
|
+
});
|
|
130
|
+
const out = run(project, 'sync', '--yes', '--force');
|
|
131
|
+
expect(out).toContain("Took OpenCastle's servers out of .codex/mcp.json");
|
|
132
|
+
expect(out).toContain('.codex/config.toml');
|
|
133
|
+
const left = JSON.parse(readFileSync(join(project, '.codex/mcp.json'), 'utf8'));
|
|
134
|
+
expect(Object.keys(left.mcpServers)).toEqual(['theirs']);
|
|
135
|
+
});
|
|
136
|
+
it('shares .agents/skills/ with Antigravity without either sweep removing the other’s files', () => {
|
|
137
|
+
write(project, { 'GEMINI.md': '# Gemini\n' });
|
|
138
|
+
run(project, 'init', '--yes');
|
|
139
|
+
const manifest = JSON.parse(readFileSync(join(project, '.opencastle/manifest.json'), 'utf8'));
|
|
140
|
+
expect(manifest.ides).toEqual(expect.arrayContaining(['codex', 'antigravity']));
|
|
141
|
+
const skills = readdirSync(join(project, '.agents/skills')).sort();
|
|
142
|
+
expect(skills).toContain('testing-workflow');
|
|
143
|
+
run(project, 'sync', '--yes', '--force');
|
|
144
|
+
expect(readdirSync(join(project, '.agents/skills')).sort()).toEqual(skills);
|
|
145
|
+
run(project, 'sync', '--check');
|
|
146
|
+
});
|
|
147
|
+
it('remove --all takes our servers out of config.toml and leaves the user’s setup', () => {
|
|
148
|
+
run(project, 'init', '--yes');
|
|
149
|
+
run(project, 'remove', '--all', '--yes');
|
|
150
|
+
expect(readFileSync(join(project, '.codex/config.toml'), 'utf8')).toBe(USERS_CONFIG);
|
|
151
|
+
expect(existsSync(join(project, '.agents/skills'))).toBe(false);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
//# sourceMappingURL=codex-target.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex-target.test.js","sourceRoot":"","sources":["../../src/cli/codex-target.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC9G,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AACpE,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,WAAW,CAAA;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,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AC7B,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;QACxC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,oBAAoB,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;QACpF,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACjE,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The namespace every command OpenCastle compiles is invoked under.
|
|
3
|
+
*
|
|
4
|
+
* `/bug-fix` was a name anyone could want: a teammate's own command, another
|
|
5
|
+
* tool's, a skill. Compiled commands now live under one prefix, `/oc:bug-fix`,
|
|
6
|
+
* and in the directories commands live in OpenCastle owns that namespace and
|
|
7
|
+
* nothing beside it — so a command someone writes by hand is never overwritten,
|
|
8
|
+
* swept, removed, or reported as drift.
|
|
9
|
+
*
|
|
10
|
+
* The prefix is a namespace, not a mark of origin. A team's own prompt in a
|
|
11
|
+
* baseline or in `.opencastle/prompts/` compiles to `/oc:<name>` as well: it is
|
|
12
|
+
* shared, reviewed config that `sync` rewrites, which is what the prefix tells
|
|
13
|
+
* the person typing it.
|
|
14
|
+
*/
|
|
15
|
+
export declare const COMMAND_NAMESPACE = "oc";
|
|
16
|
+
/** What a person types after the slash: `oc:bug-fix`. */
|
|
17
|
+
export declare function commandName(name: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Claude Code names a command after its path under `.claude/commands/`, with
|
|
20
|
+
* each directory becoming a `:` segment — `oc/bug-fix.md` is `/oc:bug-fix`. A
|
|
21
|
+
* directory, not a colon in the file name, because Windows cannot check out a
|
|
22
|
+
* file whose name contains one.
|
|
23
|
+
*/
|
|
24
|
+
export declare const CLAUDE_COMMANDS_DIR = "commands/oc";
|
|
25
|
+
/**
|
|
26
|
+
* VS Code reads prompt files from the top of `.github/prompts/` only, so the
|
|
27
|
+
* namespace goes in the file name, and the command name — `name:` in the
|
|
28
|
+
* frontmatter, which VS Code prefers to the file name — carries the colon.
|
|
29
|
+
*/
|
|
30
|
+
export declare function vscodePromptFile(fileName: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Give a prompt file the namespaced command name, in its frontmatter.
|
|
33
|
+
*
|
|
34
|
+
* Any `name:` the source declared is replaced rather than prefixed: Claude Code
|
|
35
|
+
* ignores the field and names commands after the file, so honouring it here
|
|
36
|
+
* would give one prompt two different names in two assistants.
|
|
37
|
+
*/
|
|
38
|
+
export declare function withCommandName(content: string, name: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Does this file say a release of ours wrote it?
|
|
41
|
+
*
|
|
42
|
+
* Every prompt and workflow OpenCastle has shipped since 0.2 opens with
|
|
43
|
+
* `<!-- ⚠️ This file is managed by OpenCastle. … -->`. Only inside an HTML
|
|
44
|
+
* comment, and only near the top: the same words in a person's own sentence
|
|
45
|
+
* are theirs, which is the distinction `managed-block.ts` learned for root
|
|
46
|
+
* files.
|
|
47
|
+
*/
|
|
48
|
+
export declare function carriesOurBanner(content: string): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Was this project last compiled by a release before the namespace?
|
|
51
|
+
*
|
|
52
|
+
* Legacy output is looked for only then — during the sync that upgrades it,
|
|
53
|
+
* or over an install whose manifest is gone. Afterwards the old names are free
|
|
54
|
+
* again: a team that copies `oc/bug-fix.md` back to `bug-fix.md` because it
|
|
55
|
+
* prefers the short name keeps its copy, banner and all.
|
|
56
|
+
*
|
|
57
|
+
* Read from a mark in the manifest, not from its version. 1.0.0 shipped
|
|
58
|
+
* without the namespace, and which number the namespaced release gets depends
|
|
59
|
+
* on what else merges first — a version cut-off guessed here would miss every
|
|
60
|
+
* project compiled in between, and leave a stale `/bug-fix` beside
|
|
61
|
+
* `/oc:bug-fix` in each of them.
|
|
62
|
+
*/
|
|
63
|
+
export declare function compiledBeforeNamespace(projectRoot: string): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Commands a release before the namespace compiled into the top of
|
|
66
|
+
* `.claude/commands/`.
|
|
67
|
+
*
|
|
68
|
+
* Those releases wrote `bug-fix.md` and `workflow-bug-fix.md` there and swept
|
|
69
|
+
* the whole directory on every sync. Now commands go under `oc/`, and nothing
|
|
70
|
+
* the rest — so the old files would linger as a second, stale `/bug-fix` beside
|
|
71
|
+
* `/oc:bug-fix`. One of their names with our banner is theirs; anything else in
|
|
72
|
+
* the directory is a person's, and is left alone.
|
|
73
|
+
*
|
|
74
|
+
* Paths are relative to the project root, with forward slashes.
|
|
75
|
+
*/
|
|
76
|
+
export declare function legacyClaudeCommands(projectRoot: string, dotDir?: string): string[];
|
|
77
|
+
/**
|
|
78
|
+
* Is this file in `.github/prompts/` one OpenCastle wrote?
|
|
79
|
+
*
|
|
80
|
+
* VS Code reads prompts only from the top of that directory, so OpenCastle's
|
|
81
|
+
* and a person's share it. Ours are the `oc.` files, plus the un-namespaced
|
|
82
|
+
* ones a release before the namespace wrote — which `sync` replaces. Everything else is
|
|
83
|
+
* theirs: never swept, never reported as drift, never removed.
|
|
84
|
+
*/
|
|
85
|
+
export declare function isOurVscodePrompt(fileName: string, abs: string, projectRoot: string): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Prompt files a release before the namespace wrote in `.github/prompts/`,
|
|
88
|
+
* present now — `bug-fix.prompt.md`, written today as `oc.bug-fix.prompt.md`.
|
|
89
|
+
*/
|
|
90
|
+
export declare function legacyVscodePrompts(projectRoot: string): string[];
|
|
91
|
+
//# sourceMappingURL=command-namespace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-namespace.d.ts","sourceRoot":"","sources":["../../src/cli/command-namespace.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,iBAAiB,OAAO,CAAA;AAErC,yDAAyD;AACzD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,gBAAkC,CAAA;AAElE;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CA2BrE;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAQzD;AAiCD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAYpE;AAWD;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,SAAY,GAAG,MAAM,EAAE,CAatF;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAG7F;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,CAajE"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* The namespace every command OpenCastle compiles is invoked under.
|
|
5
|
+
*
|
|
6
|
+
* `/bug-fix` was a name anyone could want: a teammate's own command, another
|
|
7
|
+
* tool's, a skill. Compiled commands now live under one prefix, `/oc:bug-fix`,
|
|
8
|
+
* and in the directories commands live in OpenCastle owns that namespace and
|
|
9
|
+
* nothing beside it — so a command someone writes by hand is never overwritten,
|
|
10
|
+
* swept, removed, or reported as drift.
|
|
11
|
+
*
|
|
12
|
+
* The prefix is a namespace, not a mark of origin. A team's own prompt in a
|
|
13
|
+
* baseline or in `.opencastle/prompts/` compiles to `/oc:<name>` as well: it is
|
|
14
|
+
* shared, reviewed config that `sync` rewrites, which is what the prefix tells
|
|
15
|
+
* the person typing it.
|
|
16
|
+
*/
|
|
17
|
+
export const COMMAND_NAMESPACE = 'oc';
|
|
18
|
+
/** What a person types after the slash: `oc:bug-fix`. */
|
|
19
|
+
export function commandName(name) {
|
|
20
|
+
return `${COMMAND_NAMESPACE}:${name}`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Claude Code names a command after its path under `.claude/commands/`, with
|
|
24
|
+
* each directory becoming a `:` segment — `oc/bug-fix.md` is `/oc:bug-fix`. A
|
|
25
|
+
* directory, not a colon in the file name, because Windows cannot check out a
|
|
26
|
+
* file whose name contains one.
|
|
27
|
+
*/
|
|
28
|
+
export const CLAUDE_COMMANDS_DIR = `commands/${COMMAND_NAMESPACE}`;
|
|
29
|
+
/**
|
|
30
|
+
* VS Code reads prompt files from the top of `.github/prompts/` only, so the
|
|
31
|
+
* namespace goes in the file name, and the command name — `name:` in the
|
|
32
|
+
* frontmatter, which VS Code prefers to the file name — carries the colon.
|
|
33
|
+
*/
|
|
34
|
+
export function vscodePromptFile(fileName) {
|
|
35
|
+
return `${COMMAND_NAMESPACE}.${fileName}`;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Give a prompt file the namespaced command name, in its frontmatter.
|
|
39
|
+
*
|
|
40
|
+
* Any `name:` the source declared is replaced rather than prefixed: Claude Code
|
|
41
|
+
* ignores the field and names commands after the file, so honouring it here
|
|
42
|
+
* would give one prompt two different names in two assistants.
|
|
43
|
+
*/
|
|
44
|
+
export function withCommandName(content, name) {
|
|
45
|
+
const line = `name: '${commandName(name)}'`;
|
|
46
|
+
// The file's own line endings, so a CRLF checkout of a team's prompt is not
|
|
47
|
+
// rewritten into mixed endings.
|
|
48
|
+
const eol = content.includes('\r\n') ? '\r\n' : '\n';
|
|
49
|
+
const lines = content.split(/\r?\n/);
|
|
50
|
+
if (lines[0]?.trim() === '---') {
|
|
51
|
+
const close = lines.findIndex((l, i) => i > 0 && l.trim() === '---');
|
|
52
|
+
if (close > 0) {
|
|
53
|
+
// The declared name and, for a block scalar (`name: >`), the indented
|
|
54
|
+
// lines that continue it — left behind, they would break the YAML and
|
|
55
|
+
// take `description` and `agent` down with it.
|
|
56
|
+
const kept = [];
|
|
57
|
+
let inName = false;
|
|
58
|
+
for (const l of lines.slice(1, close)) {
|
|
59
|
+
if (/^name\s*:/.test(l)) {
|
|
60
|
+
inName = true;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (inName && /^[ \t]/.test(l))
|
|
64
|
+
continue;
|
|
65
|
+
inName = false;
|
|
66
|
+
kept.push(l);
|
|
67
|
+
}
|
|
68
|
+
return ['---', line, ...kept, ...lines.slice(close)].join(eol);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return `---${eol}${line}${eol}---${eol}${eol}${content}`;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Does this file say a release of ours wrote it?
|
|
75
|
+
*
|
|
76
|
+
* Every prompt and workflow OpenCastle has shipped since 0.2 opens with
|
|
77
|
+
* `<!-- ⚠️ This file is managed by OpenCastle. … -->`. Only inside an HTML
|
|
78
|
+
* comment, and only near the top: the same words in a person's own sentence
|
|
79
|
+
* are theirs, which is the distinction `managed-block.ts` learned for root
|
|
80
|
+
* files.
|
|
81
|
+
*/
|
|
82
|
+
export function carriesOurBanner(content) {
|
|
83
|
+
const lines = content
|
|
84
|
+
.replace(/^/, '')
|
|
85
|
+
.split(/\r?\n/)
|
|
86
|
+
.map((l) => l.trim())
|
|
87
|
+
.filter((l) => l !== '')
|
|
88
|
+
.slice(0, 12);
|
|
89
|
+
return lines.some((l) => l.startsWith('<!--') && l.includes('This file is managed by OpenCastle'));
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Every prompt and workflow a release before the namespace shipped — read
|
|
93
|
+
* from all 103 release tags, 0.1.0 to 1.0.0. A closed list: those releases are
|
|
94
|
+
* done.
|
|
95
|
+
*
|
|
96
|
+
* The banner alone is not enough to call a file theirs. Namespaced output
|
|
97
|
+
* carries it too, so a person who copies `oc/bug-fix.md` to `our-bug-fix.md`
|
|
98
|
+
* and edits it would see their copy deleted on the next sync. A legacy file is
|
|
99
|
+
* one of these names *and* carries the banner.
|
|
100
|
+
*/
|
|
101
|
+
const LEGACY_PROMPTS = [
|
|
102
|
+
'assess-complexity', 'bootstrap-customizations', 'brainstorm', 'bug-fix', 'create-skill',
|
|
103
|
+
'fix-convoy', 'fix-prd', 'generate-convoy', 'generate-prd', 'generate-task-spec',
|
|
104
|
+
'implement-feature', 'metrics-report', 'quick-refinement', 'resolve-pr-comments',
|
|
105
|
+
'validate-convoy', 'validate-prd',
|
|
106
|
+
];
|
|
107
|
+
const LEGACY_WORKFLOWS = [
|
|
108
|
+
'README', 'bug-fix', 'data-pipeline', 'database-migration', 'feature-implementation',
|
|
109
|
+
'performance-optimization', 'refactoring', 'schema-changes', 'security-audit',
|
|
110
|
+
'shared-delivery-phase',
|
|
111
|
+
];
|
|
112
|
+
/** File names a release before the namespace wrote at the top of `.claude/commands/`. */
|
|
113
|
+
const LEGACY_CLAUDE_NAMES = new Set([
|
|
114
|
+
...LEGACY_PROMPTS.map((n) => `${n}.md`),
|
|
115
|
+
...LEGACY_WORKFLOWS.map((n) => `workflow-${n}.md`),
|
|
116
|
+
]);
|
|
117
|
+
/** File names a release before the namespace wrote in `.github/prompts/`. */
|
|
118
|
+
const LEGACY_VSCODE_NAMES = new Set(LEGACY_PROMPTS.map((n) => `${n}.prompt.md`));
|
|
119
|
+
/**
|
|
120
|
+
* Was this project last compiled by a release before the namespace?
|
|
121
|
+
*
|
|
122
|
+
* Legacy output is looked for only then — during the sync that upgrades it,
|
|
123
|
+
* or over an install whose manifest is gone. Afterwards the old names are free
|
|
124
|
+
* again: a team that copies `oc/bug-fix.md` back to `bug-fix.md` because it
|
|
125
|
+
* prefers the short name keeps its copy, banner and all.
|
|
126
|
+
*
|
|
127
|
+
* Read from a mark in the manifest, not from its version. 1.0.0 shipped
|
|
128
|
+
* without the namespace, and which number the namespaced release gets depends
|
|
129
|
+
* on what else merges first — a version cut-off guessed here would miss every
|
|
130
|
+
* project compiled in between, and leave a stale `/bug-fix` beside
|
|
131
|
+
* `/oc:bug-fix` in each of them.
|
|
132
|
+
*/
|
|
133
|
+
export function compiledBeforeNamespace(projectRoot) {
|
|
134
|
+
for (const rel of ['.opencastle/manifest.json', '.opencastle.json']) {
|
|
135
|
+
const abs = resolve(projectRoot, rel);
|
|
136
|
+
if (!existsSync(abs))
|
|
137
|
+
continue;
|
|
138
|
+
try {
|
|
139
|
+
const manifest = JSON.parse(readFileSync(abs, 'utf8'));
|
|
140
|
+
return manifest.commandNamespace !== COMMAND_NAMESPACE;
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
/** Does the file at `abs` carry our banner? An unreadable file is not ours to delete. */
|
|
149
|
+
function bannerAt(abs) {
|
|
150
|
+
try {
|
|
151
|
+
return carriesOurBanner(readFileSync(abs, 'utf8'));
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Commands a release before the namespace compiled into the top of
|
|
159
|
+
* `.claude/commands/`.
|
|
160
|
+
*
|
|
161
|
+
* Those releases wrote `bug-fix.md` and `workflow-bug-fix.md` there and swept
|
|
162
|
+
* the whole directory on every sync. Now commands go under `oc/`, and nothing
|
|
163
|
+
* the rest — so the old files would linger as a second, stale `/bug-fix` beside
|
|
164
|
+
* `/oc:bug-fix`. One of their names with our banner is theirs; anything else in
|
|
165
|
+
* the directory is a person's, and is left alone.
|
|
166
|
+
*
|
|
167
|
+
* Paths are relative to the project root, with forward slashes.
|
|
168
|
+
*/
|
|
169
|
+
export function legacyClaudeCommands(projectRoot, dotDir = '.claude') {
|
|
170
|
+
const dir = resolve(projectRoot, dotDir, 'commands');
|
|
171
|
+
if (!existsSync(dir) || !compiledBeforeNamespace(projectRoot))
|
|
172
|
+
return [];
|
|
173
|
+
let entries;
|
|
174
|
+
try {
|
|
175
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
return [];
|
|
179
|
+
}
|
|
180
|
+
return entries
|
|
181
|
+
.filter((e) => e.isFile() && LEGACY_CLAUDE_NAMES.has(e.name) && bannerAt(resolve(dir, e.name)))
|
|
182
|
+
.map((e) => `${dotDir}/commands/${e.name}`)
|
|
183
|
+
.sort();
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Is this file in `.github/prompts/` one OpenCastle wrote?
|
|
187
|
+
*
|
|
188
|
+
* VS Code reads prompts only from the top of that directory, so OpenCastle's
|
|
189
|
+
* and a person's share it. Ours are the `oc.` files, plus the un-namespaced
|
|
190
|
+
* ones a release before the namespace wrote — which `sync` replaces. Everything else is
|
|
191
|
+
* theirs: never swept, never reported as drift, never removed.
|
|
192
|
+
*/
|
|
193
|
+
export function isOurVscodePrompt(fileName, abs, projectRoot) {
|
|
194
|
+
if (fileName.startsWith(`${COMMAND_NAMESPACE}.`))
|
|
195
|
+
return true;
|
|
196
|
+
return LEGACY_VSCODE_NAMES.has(fileName) && compiledBeforeNamespace(projectRoot) && bannerAt(abs);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Prompt files a release before the namespace wrote in `.github/prompts/`,
|
|
200
|
+
* present now — `bug-fix.prompt.md`, written today as `oc.bug-fix.prompt.md`.
|
|
201
|
+
*/
|
|
202
|
+
export function legacyVscodePrompts(projectRoot) {
|
|
203
|
+
const dir = resolve(projectRoot, '.github', 'prompts');
|
|
204
|
+
if (!existsSync(dir) || !compiledBeforeNamespace(projectRoot))
|
|
205
|
+
return [];
|
|
206
|
+
let entries;
|
|
207
|
+
try {
|
|
208
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
return [];
|
|
212
|
+
}
|
|
213
|
+
return entries
|
|
214
|
+
.filter((e) => e.isFile() && LEGACY_VSCODE_NAMES.has(e.name) && bannerAt(resolve(dir, e.name)))
|
|
215
|
+
.map((e) => `.github/prompts/${e.name}`)
|
|
216
|
+
.sort();
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=command-namespace.js.map
|