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.
Files changed (118) hide show
  1. package/README.md +9 -4
  2. package/dist/cli/adapters/claude-code.d.ts +8 -4
  3. package/dist/cli/adapters/claude-code.d.ts.map +1 -1
  4. package/dist/cli/adapters/claude-code.js +13 -7
  5. package/dist/cli/adapters/claude-code.js.map +1 -1
  6. package/dist/cli/adapters/codex.d.ts +19 -6
  7. package/dist/cli/adapters/codex.d.ts.map +1 -1
  8. package/dist/cli/adapters/codex.js +24 -7
  9. package/dist/cli/adapters/codex.js.map +1 -1
  10. package/dist/cli/adapters/single-file-base.d.ts +15 -1
  11. package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
  12. package/dist/cli/adapters/single-file-base.js +46 -21
  13. package/dist/cli/adapters/single-file-base.js.map +1 -1
  14. package/dist/cli/adapters/vscode.d.ts +11 -1
  15. package/dist/cli/adapters/vscode.d.ts.map +1 -1
  16. package/dist/cli/adapters/vscode.js +48 -8
  17. package/dist/cli/adapters/vscode.js.map +1 -1
  18. package/dist/cli/codex-target.test.d.ts +2 -0
  19. package/dist/cli/codex-target.test.d.ts.map +1 -0
  20. package/dist/cli/codex-target.test.js +154 -0
  21. package/dist/cli/codex-target.test.js.map +1 -0
  22. package/dist/cli/command-namespace.d.ts +91 -0
  23. package/dist/cli/command-namespace.d.ts.map +1 -0
  24. package/dist/cli/command-namespace.js +218 -0
  25. package/dist/cli/command-namespace.js.map +1 -0
  26. package/dist/cli/command-namespace.test.d.ts +2 -0
  27. package/dist/cli/command-namespace.test.d.ts.map +1 -0
  28. package/dist/cli/command-namespace.test.js +356 -0
  29. package/dist/cli/command-namespace.test.js.map +1 -0
  30. package/dist/cli/copy.d.ts +1 -1
  31. package/dist/cli/copy.d.ts.map +1 -1
  32. package/dist/cli/copy.js +3 -2
  33. package/dist/cli/copy.js.map +1 -1
  34. package/dist/cli/doctor.d.ts.map +1 -1
  35. package/dist/cli/doctor.js +2 -1
  36. package/dist/cli/doctor.js.map +1 -1
  37. package/dist/cli/doctor.test.js +2 -2
  38. package/dist/cli/doctor.test.js.map +1 -1
  39. package/dist/cli/explain.d.ts.map +1 -1
  40. package/dist/cli/explain.js +13 -1
  41. package/dist/cli/explain.js.map +1 -1
  42. package/dist/cli/github-report.js +1 -1
  43. package/dist/cli/github-report.js.map +1 -1
  44. package/dist/cli/init.d.ts.map +1 -1
  45. package/dist/cli/init.js +45 -10
  46. package/dist/cli/init.js.map +1 -1
  47. package/dist/cli/init.test.js +31 -14
  48. package/dist/cli/init.test.js.map +1 -1
  49. package/dist/cli/managed-paths.d.ts +18 -1
  50. package/dist/cli/managed-paths.d.ts.map +1 -1
  51. package/dist/cli/managed-paths.js +74 -2
  52. package/dist/cli/managed-paths.js.map +1 -1
  53. package/dist/cli/manifest.d.ts.map +1 -1
  54. package/dist/cli/manifest.js +2 -0
  55. package/dist/cli/manifest.js.map +1 -1
  56. package/dist/cli/mcp-audit.d.ts.map +1 -1
  57. package/dist/cli/mcp-audit.js +7 -3
  58. package/dist/cli/mcp-audit.js.map +1 -1
  59. package/dist/cli/mcp-file.d.ts +37 -0
  60. package/dist/cli/mcp-file.d.ts.map +1 -0
  61. package/dist/cli/mcp-file.js +291 -0
  62. package/dist/cli/mcp-file.js.map +1 -0
  63. package/dist/cli/mcp-file.test.d.ts +2 -0
  64. package/dist/cli/mcp-file.test.d.ts.map +1 -0
  65. package/dist/cli/mcp-file.test.js +121 -0
  66. package/dist/cli/mcp-file.test.js.map +1 -0
  67. package/dist/cli/mcp.d.ts +15 -0
  68. package/dist/cli/mcp.d.ts.map +1 -1
  69. package/dist/cli/mcp.js +123 -56
  70. package/dist/cli/mcp.js.map +1 -1
  71. package/dist/cli/remove.d.ts.map +1 -1
  72. package/dist/cli/remove.js +45 -8
  73. package/dist/cli/remove.js.map +1 -1
  74. package/dist/cli/sync-check.d.ts.map +1 -1
  75. package/dist/cli/sync-check.js +26 -7
  76. package/dist/cli/sync-check.js.map +1 -1
  77. package/dist/cli/sync-check.test.js +2 -2
  78. package/dist/cli/sync-check.test.js.map +1 -1
  79. package/dist/cli/types.d.ts +37 -2
  80. package/dist/cli/types.d.ts.map +1 -1
  81. package/dist/cli/types.js +3 -0
  82. package/dist/cli/types.js.map +1 -1
  83. package/dist/cli/unreadable-report.d.ts +7 -0
  84. package/dist/cli/unreadable-report.d.ts.map +1 -1
  85. package/dist/cli/unreadable-report.js +14 -0
  86. package/dist/cli/unreadable-report.js.map +1 -1
  87. package/dist/cli/update.d.ts.map +1 -1
  88. package/dist/cli/update.js +69 -5
  89. package/dist/cli/update.js.map +1 -1
  90. package/package.json +3 -2
  91. package/src/cli/adapters/claude-code.ts +13 -7
  92. package/src/cli/adapters/codex.ts +25 -7
  93. package/src/cli/adapters/single-file-base.ts +66 -26
  94. package/src/cli/adapters/vscode.ts +51 -10
  95. package/src/cli/codex-target.test.ts +178 -0
  96. package/src/cli/command-namespace.test.ts +417 -0
  97. package/src/cli/command-namespace.ts +222 -0
  98. package/src/cli/copy.ts +6 -2
  99. package/src/cli/doctor.test.ts +2 -2
  100. package/src/cli/doctor.ts +3 -2
  101. package/src/cli/explain.ts +13 -1
  102. package/src/cli/github-report.ts +1 -1
  103. package/src/cli/init.test.ts +31 -14
  104. package/src/cli/init.ts +48 -11
  105. package/src/cli/managed-paths.ts +75 -3
  106. package/src/cli/manifest.ts +2 -0
  107. package/src/cli/mcp-audit.ts +7 -3
  108. package/src/cli/mcp-file.test.ts +138 -0
  109. package/src/cli/mcp-file.ts +302 -0
  110. package/src/cli/mcp.ts +130 -60
  111. package/src/cli/remove.ts +40 -8
  112. package/src/cli/sync-check.test.ts +2 -2
  113. package/src/cli/sync-check.ts +23 -6
  114. package/src/cli/types.ts +37 -2
  115. package/src/cli/unreadable-report.ts +14 -0
  116. package/src/cli/update.ts +73 -5
  117. package/src/dashboard/node_modules/.vite/deps/_metadata.json +6 -6
  118. package/src/orchestrator/prompts/bootstrap-customizations.prompt.md +4 -4
@@ -1,30 +1,48 @@
1
+ import { existsSync } from 'node:fs'
2
+ import { resolve } from 'node:path'
1
3
  import { createSingleFileAdapter } from './single-file-base.js'
2
4
 
3
5
  /**
4
6
  * Codex CLI adapter.
5
7
  *
6
- * Generates AGENTS.md (root instructions) and .codex/ structure.
8
+ * Generates AGENTS.md (root instructions), the cross-assistant skills
9
+ * directory, and .codex/ structure.
7
10
  *
8
11
  * copilot-instructions.md -> AGENTS.md (combined with instructions/)
9
- * skills/<name>/SKILL.md -> .codex/skills/<name>/SKILL.md (+ sibling resources, frontmatter preserved)
12
+ * skills/<name>/SKILL.md -> .agents/skills/<name>/SKILL.md (+ sibling resources, frontmatter preserved)
10
13
  * agents/*.agent.md -> .codex/agents/<name>.md
11
14
  * agent-workflows/*.md -> .codex/workflows/<name>.md
12
15
  * prompts/*.prompt.md -> .codex/prompts/<name>.md
13
- * customizations/ -> .codex/customizations/ (scaffolded once)
14
- * mcp.json -> .codex/mcp.json (mcpServers format)
16
+ * MCP servers -> .codex/config.toml ([mcp_servers.<name>] tables)
17
+ *
18
+ * Codex reads a repository's skills only from `.agents/skills/` and its
19
+ * project MCP servers only from `.codex/config.toml`, in a project the user has
20
+ * trusted. Releases before this one wrote `.codex/skills/` and `.codex/mcp.json`,
21
+ * neither of which Codex reads; `sync` removes the first and takes our servers
22
+ * back out of the second.
23
+ *
24
+ * `.agents/skills/` is also where the Antigravity adapter writes skills. Both
25
+ * compile the same skills from the same source, so with both selected each
26
+ * one's output is the other's, and neither sweep removes anything of the other.
15
27
  */
16
28
 
17
29
  export const IDE_ID = 'codex'
18
30
 
19
- const { install, update, getManagedPaths, getDoctorChecks } = createSingleFileAdapter({
31
+ /** What releases before `.agents/skills/` wrote, relative to the project root. */
32
+ export const LEGACY_CODEX_SKILLS = '.codex/skills/'
33
+ export const LEGACY_CODEX_MCP = '.codex/mcp.json'
34
+
35
+ const { install, update, getManagedPaths, getDoctorChecks, getLegacyOutputs } = createSingleFileAdapter({
20
36
  rootFile: 'AGENTS.md',
21
37
  dotDir: '.codex',
22
- mcpConfigPath: '.codex/mcp.json',
38
+ skillsDir: '.agents/skills',
39
+ mcpConfigPath: '.codex/config.toml',
23
40
  mcpFormat: 'codex',
24
41
  promptsDir: 'prompts',
25
42
  workflowsDir: 'workflows',
26
43
  workflowPrefix: '',
27
44
  frameworkDirs: ['agents', 'skills', 'prompts', 'workflows'],
45
+ legacyOutputs: (projectRoot) => (existsSync(resolve(projectRoot, LEGACY_CODEX_SKILLS)) ? [LEGACY_CODEX_SKILLS] : []),
28
46
  })
29
47
 
30
- export { install, update, getManagedPaths, getDoctorChecks }
48
+ export { install, update, getManagedPaths, getDoctorChecks, getLegacyOutputs }
@@ -1,4 +1,4 @@
1
- import { resolve, basename, relative } from 'node:path'
1
+ import { resolve, basename, relative, sep } from 'node:path'
2
2
  import { mkdir, writeFile, readdir, readFile, rm, rename } from 'node:fs/promises'
3
3
  import { existsSync, readdirSync, realpathSync } from 'node:fs'
4
4
  import { writeManagedBlock, recordMerge } from '../managed-block.js'
@@ -31,6 +31,18 @@ export interface SingleFileAdapterConfig {
31
31
  workflowPrefix: string
32
32
  /** Framework subdirectories (under dotDir) to remove during update */
33
33
  frameworkDirs: string[]
34
+ /**
35
+ * Where skills go, relative to the project root, when the assistant does not
36
+ * read them from `<dotDir>/skills/`. Codex CLI reads a repository's skills
37
+ * only from `.agents/skills/`, the cross-assistant location; the
38
+ * `.codex/skills/` this wrote was never loaded.
39
+ */
40
+ skillsDir?: string
41
+ /**
42
+ * Output an earlier release wrote outside today's framework directories,
43
+ * present on disk now, relative to the project root. Removed on update.
44
+ */
45
+ legacyOutputs?: (_projectRoot: string) => string[]
34
46
  }
35
47
 
36
48
  /**
@@ -58,23 +70,34 @@ export interface SingleFileAdapterConfig {
58
70
  * first selected owner's directory. Both trees are still installed; the index
59
71
  * names one of them, and says so.
60
72
  */
61
- const SHARED_ROOT_OWNERS: Record<string, Array<{ ide: string; dotDir: string }>> = {
73
+ const SHARED_ROOT_OWNERS: Record<string, Array<{ ide: string; dotDir: string; skillsDir: string }>> = {
62
74
  'AGENTS.md': [
63
- { ide: 'opencode', dotDir: '.opencode' },
64
- { ide: 'codex', dotDir: '.codex' },
75
+ { ide: 'opencode', dotDir: '.opencode', skillsDir: '.opencode/skills' },
76
+ { ide: 'codex', dotDir: '.codex', skillsDir: '.agents/skills' },
65
77
  ],
66
78
  }
67
79
 
68
- /** The directory the shared root file should point at, given what is selected. */
80
+ /** Where an adapter writes skills, relative to the project root. */
81
+ function skillsDirOf(config: SingleFileAdapterConfig): string {
82
+ return config.skillsDir ?? `${config.dotDir}/skills`
83
+ }
84
+
85
+ /**
86
+ * The directories the shared root file should point at, given what is
87
+ * selected, and the other places the same content is installed.
88
+ */
69
89
  function referenceDir(config: SingleFileAdapterConfig, stack?: StackConfig): {
70
90
  dir: string
91
+ skills: string
71
92
  sharedWith: string[]
72
93
  } {
73
94
  const owners = SHARED_ROOT_OWNERS[config.rootFile] ?? []
74
95
  const selected = new Set<string>(stack?.ides ?? [])
75
96
  const present = owners.filter((o) => selected.has(o.ide))
76
- if (present.length < 2) return { dir: config.dotDir, sharedWith: [] }
77
- return { dir: present[0].dotDir, sharedWith: present.map((o) => o.dotDir) }
97
+ if (present.length < 2) return { dir: config.dotDir, skills: skillsDirOf(config), sharedWith: [] }
98
+ const [first, ...rest] = present
99
+ const elsewhere = rest.flatMap((o) => (o.skillsDir.startsWith(`${o.dotDir}/`) ? [o.dotDir] : [o.dotDir, o.skillsDir]))
100
+ return { dir: first.dotDir, skills: first.skillsDir, sharedWith: elsewhere }
78
101
  }
79
102
 
80
103
  /**
@@ -109,7 +132,9 @@ async function reconcileCase(onDisk: string, visited: Set<string>): Promise<bool
109
132
  return false
110
133
  }
111
134
 
112
- export function createSingleFileAdapter(config: SingleFileAdapterConfig): IdeAdapter {
135
+ export function createSingleFileAdapter(
136
+ config: SingleFileAdapterConfig,
137
+ ): IdeAdapter & { getLegacyOutputs(_projectRoot: string): string[] } {
113
138
  /**
114
139
  * Write one generated file and report what actually happened to it.
115
140
  *
@@ -194,18 +219,17 @@ export function createSingleFileAdapter(config: SingleFileAdapterConfig): IdeAda
194
219
  // Always built: the content goes into a managed block, so a file the user
195
220
  // already owns keeps its content and gains the generated section.
196
221
  const rootPath = resolve(projectRoot, config.rootFile)
197
- const { dir: refDir, sharedWith } = referenceDir(config, stack)
222
+ const { dir: refDir, skills: refSkills, sharedWith } = referenceDir(config, stack)
198
223
  {
199
224
  const sections: string[] = []
200
225
 
201
226
  sections.push(
202
227
  '# Project Instructions\n\n' +
203
228
  'All conventions, architecture, and project context are embedded below. ' +
204
- `Skills are in \`${refDir}/skills/\` — read them when a task matches. ` +
229
+ `Skills are in \`${refSkills}/\` — read them when a task matches. ` +
205
230
  `Agent definitions are in \`${refDir}/agents/\` — read the relevant file when adopting a persona.` +
206
- (sharedWith.length > 1
231
+ (sharedWith.length > 0
207
232
  ? `\n\nThis file is shared by more than one assistant. The same content is also installed under ${sharedWith
208
- .filter((d) => d !== refDir)
209
233
  .map((d) => `\`${d}/\``)
210
234
  .join(', ')}.`
211
235
  : '')
@@ -270,7 +294,7 @@ export function createSingleFileAdapter(config: SingleFileAdapterConfig): IdeAda
270
294
  await readdir(skillsDir, { withFileTypes: true })
271
295
  ).filter((e) => e.isDirectory())
272
296
  const skillRef = (name: string): string =>
273
- `${refDir}/skills/${name}/SKILL.md`
297
+ `${refSkills}/${name}/SKILL.md`
274
298
  // Integration skills are listed after the rest, as they always were:
275
299
  // reordering the index would change every root file on upgrade for
276
300
  // no reason anyone could see in the diff.
@@ -317,12 +341,12 @@ export function createSingleFileAdapter(config: SingleFileAdapterConfig): IdeAda
317
341
  }
318
342
  }
319
343
 
320
- // 3. Skills → dotDir/skills/<name>/SKILL.md (+ sibling resources, frontmatter preserved).
344
+ // 3. Skills → <skillsDir>/<name>/SKILL.md (+ sibling resources, frontmatter preserved).
321
345
  // Matches the SKILL.md-per-folder format used by Claude Code, OpenCode, Codex,
322
346
  // and Antigravity — agents discover skills via the description: frontmatter field.
323
347
  const skillsDir = resolve(srcRoot, 'skills')
324
348
  if (existsSync(skillsDir)) {
325
- const destSkills = resolve(dotDirPath, 'skills')
349
+ const destSkills = resolve(projectRoot, skillsDirOf(config))
326
350
  await mkdir(destSkills, { recursive: true })
327
351
  const subdirs = (
328
352
  await readdir(skillsDir, { withFileTypes: true })
@@ -409,23 +433,19 @@ export function createSingleFileAdapter(config: SingleFileAdapterConfig): IdeAda
409
433
  source?: CompileSource,
410
434
  ): Promise<CopyResults> {
411
435
  const results: CopyResults = { copied: [], skipped: [], created: [] }
412
- const dotDirPath = resolve(projectRoot, config.dotDir)
413
436
 
414
437
  // 1. Leave the root file in place. install() rewrites only the managed
415
438
  // block inside it, so deleting it here would destroy whatever the user
416
439
  // wrote around that block.
417
440
 
418
441
  // 2. Note what is there now, so step 4 can say what it removed.
419
- const sweptDirs = config.frameworkDirs
420
- .map((dir) => resolve(dotDirPath, dir))
442
+ const sweptDirs = frameworkRoots()
443
+ .map((dir) => resolve(projectRoot, dir))
421
444
  .filter((dirPath) => existsSync(dirPath))
422
445
  const before = new Map<string, string>()
423
446
  for (const dirPath of sweptDirs) {
424
447
  for (const rel of filesUnderDir(dirPath)) {
425
- before.set(
426
- resolve(dirPath, rel),
427
- `${config.dotDir}/${relative(dotDirPath, dirPath)}/${rel}`,
428
- )
448
+ before.set(resolve(dirPath, rel), `${relative(projectRoot, dirPath).split(sep).join('/')}/${rel}`)
429
449
  }
430
450
  }
431
451
 
@@ -459,6 +479,13 @@ export function createSingleFileAdapter(config: SingleFileAdapterConfig): IdeAda
459
479
  await rm(abs, { force: true })
460
480
  }
461
481
  }
482
+ // What an earlier release put where this one no longer writes — the
483
+ // un-namespaced commands at the top of `.claude/commands/`. Asked after the
484
+ // recompile, so a failure there leaves the old commands working.
485
+ for (const rel of getLegacyOutputs(projectRoot)) {
486
+ await rm(resolve(projectRoot, rel), { force: true, recursive: rel.endsWith('/') })
487
+ ;(results.deleted ??= []).push(rel)
488
+ }
462
489
  // Pass the three categories through as they came back. Folding `created`
463
490
  // into `copied` was how "Updated N framework files" stayed plausible while
464
491
  // nothing was being rewritten — the count was of files visited, not changed.
@@ -487,11 +514,24 @@ export function createSingleFileAdapter(config: SingleFileAdapterConfig): IdeAda
487
514
  return results
488
515
  }
489
516
 
490
- function getManagedPaths(): ManagedPaths {
517
+ function getLegacyOutputs(projectRoot: string): string[] {
518
+ return config.legacyOutputs?.(projectRoot) ?? []
519
+ }
520
+
521
+ /**
522
+ * Every directory this adapter generates whole, relative to the project
523
+ * root and without a trailing slash: its framework directories under
524
+ * `dotDir`, with skills wherever `skillsDir` puts them.
525
+ */
526
+ function frameworkRoots(): string[] {
491
527
  // Deduplicate dirs (e.g. promptsDir === workflowsDir for claude-code's 'commands')
492
528
  const dirs = new Set(['agents', 'skills', ...config.frameworkDirs])
529
+ return Array.from(dirs).map((d) => (d === 'skills' ? skillsDirOf(config) : `${config.dotDir}/${d}`))
530
+ }
531
+
532
+ function getManagedPaths(): ManagedPaths {
493
533
  return {
494
- framework: Array.from(dirs).map((d) => `${config.dotDir}/${d}/`),
534
+ framework: frameworkRoots().map((d) => `${d}/`),
495
535
  merged: [config.rootFile],
496
536
  customizable: ['.opencastle/', config.mcpConfigPath],
497
537
  }
@@ -501,7 +541,7 @@ export function createSingleFileAdapter(config: SingleFileAdapterConfig): IdeAda
501
541
  const checks: DoctorCheck[] = [
502
542
  { label: 'Root instructions file', path: config.rootFile, type: 'file' },
503
543
  { label: 'Agent definitions', path: `${config.dotDir}/agents/`, type: 'dir', countContents: true, countFilter: '.md' },
504
- { label: 'Skills directory', path: `${config.dotDir}/skills/`, type: 'dir', countContents: true },
544
+ { label: 'Skills directory', path: `${skillsDirOf(config)}/`, type: 'dir', countContents: true },
505
545
  ]
506
546
  if (config.promptsDir === config.workflowsDir) {
507
547
  checks.push({ label: 'Commands directory', path: `${config.dotDir}/${config.promptsDir}/`, type: 'dir', countContents: true })
@@ -512,7 +552,7 @@ export function createSingleFileAdapter(config: SingleFileAdapterConfig): IdeAda
512
552
  return checks
513
553
  }
514
554
 
515
- return { install, update, getManagedPaths, getDoctorChecks }
555
+ return { install, update, getManagedPaths, getDoctorChecks, getLegacyOutputs }
516
556
  }
517
557
 
518
558
  /** Every file under a directory, relative to it. */
@@ -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/ → .github/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
- ): { filter?: (_name: string, _srcPath: string) => boolean; transform?: CopyDirOptions['transform'] } {
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 { filter, transform } = copyRulesFor(dir, stack)
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)) beforeSweep.set(resolve(abs, rel), `.github/${dir}/${rel}`)
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 { filter, transform } = copyRulesFor(dir, stack)
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,178 @@
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 type { Manifest } from './types.js'
17
+ import { teamEntryFor } from './mcp.js'
18
+
19
+ const pkgRoot = resolve(import.meta.dirname, '..', '..')
20
+ const cli = join(pkgRoot, 'bin', 'cli.mjs')
21
+ const built = existsSync(join(pkgRoot, 'dist', 'cli', 'init.js'))
22
+
23
+ const USERS_CONFIG = `# Codex settings, written by hand
24
+ model = "gpt-5-codex"
25
+ approval_policy = "on-request"
26
+
27
+ [mcp_servers.mine]
28
+ command = "my-own-server"
29
+ `
30
+
31
+ function write(root: string, files: Record<string, string>): void {
32
+ for (const [rel, text] of Object.entries(files)) {
33
+ mkdirSync(dirname(join(root, rel)), { recursive: true })
34
+ writeFileSync(join(root, rel), text)
35
+ }
36
+ }
37
+
38
+ function run(project: string, ...args: string[]): string {
39
+ return execFileSync('node', [cli, ...args], { cwd: project, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] })
40
+ }
41
+
42
+ function servers(project: string): Record<string, Record<string, unknown>> {
43
+ const text = readFileSync(join(project, '.codex/config.toml'), 'utf8')
44
+ return ((parseToml(text) as { mcp_servers?: Record<string, Record<string, unknown>> }).mcp_servers ?? {})
45
+ }
46
+
47
+ describe("a team server in Codex's own fields", () => {
48
+ it('sends a bearer token, and a header that is one variable, from the environment', () => {
49
+ const { entry } = teamEntryFor(
50
+ 'acme-docs',
51
+ {
52
+ type: 'http',
53
+ url: 'https://docs.acme.example/mcp',
54
+ headers: { Authorization: 'Bearer ${ACME_DOCS_TOKEN}', 'X-Tenant': '${ACME_TENANT}', 'X-Client': 'opencastle' },
55
+ },
56
+ 'codex',
57
+ )
58
+ expect(entry).toEqual({
59
+ url: 'https://docs.acme.example/mcp',
60
+ bearer_token_env_var: 'ACME_DOCS_TOKEN',
61
+ env_http_headers: { 'X-Tenant': 'ACME_TENANT' },
62
+ http_headers: { 'X-Client': 'opencastle' },
63
+ })
64
+ })
65
+
66
+ it('forwards a variable the server reads under its own name, and keeps literal values', () => {
67
+ const { entry } = teamEntryFor(
68
+ 'acme-flags',
69
+ { command: 'npx', args: ['-y', '@acme/flags-mcp@1.2.3'], env: { FLAGS_TOKEN: '${FLAGS_TOKEN}', MODE: 'ci' } },
70
+ 'codex',
71
+ )
72
+ expect(entry).toEqual({
73
+ command: 'npx',
74
+ args: ['-y', '@acme/flags-mcp@1.2.3'],
75
+ env: { MODE: 'ci' },
76
+ env_vars: ['FLAGS_TOKEN'],
77
+ })
78
+ })
79
+
80
+ it('leaves a reference it cannot express as written, for doctor to name', () => {
81
+ const { entry } = teamEntryFor('x', { command: 'srv', env: { API_KEY: '${OTHER_NAME}' } }, 'codex')
82
+ expect(entry).toEqual({ command: 'srv', env: { API_KEY: '${OTHER_NAME}' } })
83
+ })
84
+ })
85
+
86
+ describe.skipIf(!built)('Codex CLI as a target', () => {
87
+ let project: string
88
+ beforeEach(() => {
89
+ project = mkdtempSync(join(tmpdir(), 'oc-codex-target-'))
90
+ execFileSync('git', ['init', '-q'], { cwd: project })
91
+ // A project that uses Supabase, so the stack carries a remote server, and
92
+ // a Codex setup of the user's own that every write must leave alone.
93
+ write(project, {
94
+ 'package.json': JSON.stringify({ name: 'app', dependencies: { '@supabase/supabase-js': '^2.0.0' } }),
95
+ '.codex/config.toml': USERS_CONFIG,
96
+ })
97
+ })
98
+ afterEach(() => rmSync(project, { recursive: true, force: true }))
99
+
100
+ it('installs skills and servers where Codex reads them, after the user’s own settings', () => {
101
+ run(project, 'init', '--yes')
102
+ expect(existsSync(join(project, '.agents/skills/testing-workflow/SKILL.md'))).toBe(true)
103
+ expect(existsSync(join(project, '.codex/skills'))).toBe(false)
104
+ expect(existsSync(join(project, '.codex/mcp.json'))).toBe(false)
105
+ const text = readFileSync(join(project, '.codex/config.toml'), 'utf8')
106
+ expect(text.startsWith(USERS_CONFIG)).toBe(true)
107
+ expect(servers(project).Supabase).toEqual({ url: 'https://mcp.supabase.com/mcp' })
108
+ expect(servers(project).mine).toEqual({ command: 'my-own-server' })
109
+ run(project, 'sync', '--check')
110
+ })
111
+
112
+ it('the sync that upgrades a 1.0.0 install moves skills and servers, and keeps what is the user’s', () => {
113
+ run(project, 'init', '--yes')
114
+ // Back to how 1.0.0 left it: skills under `.codex/skills/`, servers in a
115
+ // `.codex/mcp.json` it created, and a manifest that recorded both.
116
+ rmSync(join(project, '.agents'), { recursive: true, force: true })
117
+ write(project, {
118
+ '.codex/config.toml': USERS_CONFIG,
119
+ '.codex/skills/testing-workflow/SKILL.md': '---\nname: testing-workflow\ndescription: old\n---\nold\n',
120
+ '.codex/mcp.json': JSON.stringify({ mcpServers: { Supabase: { url: 'https://mcp.supabase.com/mcp' } } }, null, 2) + '\n',
121
+ })
122
+ const path = join(project, '.opencastle/manifest.json')
123
+ const manifest = JSON.parse(readFileSync(path, 'utf8')) as Manifest
124
+ manifest.version = '1.0.0'
125
+ manifest.createdConfigs = ['.codex/mcp.json']
126
+ manifest.managedPaths = {
127
+ framework: ['.codex/agents/', '.codex/skills/', '.codex/prompts/', '.codex/workflows/'],
128
+ customizable: ['.opencastle/', '.codex/mcp.json'],
129
+ merged: ['AGENTS.md'],
130
+ }
131
+ writeFileSync(path, JSON.stringify(manifest, null, 2))
132
+
133
+ const out = run(project, 'sync', '--yes')
134
+ expect(out).toContain('Removed .codex/mcp.json')
135
+ expect(existsSync(join(project, '.codex/skills'))).toBe(false)
136
+ expect(existsSync(join(project, '.codex/mcp.json'))).toBe(false)
137
+ expect(readFileSync(join(project, '.agents/skills/testing-workflow/SKILL.md'), 'utf8')).not.toContain('description: old')
138
+ expect(readFileSync(join(project, '.codex/config.toml'), 'utf8').startsWith(USERS_CONFIG)).toBe(true)
139
+ expect(servers(project).Supabase).toBeDefined()
140
+
141
+ const after = JSON.parse(readFileSync(path, 'utf8')) as Manifest
142
+ expect(after.createdConfigs ?? []).not.toContain('.codex/mcp.json')
143
+ expect(after.managedPaths?.framework).toContain('.agents/skills/')
144
+ expect(after.managedPaths?.framework).not.toContain('.codex/skills/')
145
+ run(project, 'sync', '--check')
146
+ })
147
+
148
+ it('keeps servers a person added to the old .codex/mcp.json, and says where they belong', () => {
149
+ run(project, 'init', '--yes')
150
+ write(project, {
151
+ '.codex/mcp.json': JSON.stringify({ mcpServers: { Supabase: { url: 'https://mcp.supabase.com/mcp' }, theirs: { command: 'x' } } }),
152
+ })
153
+ const out = run(project, 'sync', '--yes', '--force')
154
+ expect(out).toContain("Took OpenCastle's servers out of .codex/mcp.json")
155
+ expect(out).toContain('.codex/config.toml')
156
+ const left = JSON.parse(readFileSync(join(project, '.codex/mcp.json'), 'utf8')) as { mcpServers: object }
157
+ expect(Object.keys(left.mcpServers)).toEqual(['theirs'])
158
+ })
159
+
160
+ it('shares .agents/skills/ with Antigravity without either sweep removing the other’s files', () => {
161
+ write(project, { 'GEMINI.md': '# Gemini\n' })
162
+ run(project, 'init', '--yes')
163
+ const manifest = JSON.parse(readFileSync(join(project, '.opencastle/manifest.json'), 'utf8')) as Manifest
164
+ expect(manifest.ides).toEqual(expect.arrayContaining(['codex', 'antigravity']))
165
+ const skills = readdirSync(join(project, '.agents/skills')).sort()
166
+ expect(skills).toContain('testing-workflow')
167
+ run(project, 'sync', '--yes', '--force')
168
+ expect(readdirSync(join(project, '.agents/skills')).sort()).toEqual(skills)
169
+ run(project, 'sync', '--check')
170
+ })
171
+
172
+ it('remove --all takes our servers out of config.toml and leaves the user’s setup', () => {
173
+ run(project, 'init', '--yes')
174
+ run(project, 'remove', '--all', '--yes')
175
+ expect(readFileSync(join(project, '.codex/config.toml'), 'utf8')).toBe(USERS_CONFIG)
176
+ expect(existsSync(join(project, '.agents/skills'))).toBe(false)
177
+ })
178
+ })