opencastle 1.3.0 → 1.3.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 (112) hide show
  1. package/README.md +90 -125
  2. package/bin/cli.mjs +12 -1
  3. package/dist/cli/adapters/claude-code.d.ts +5 -3
  4. package/dist/cli/adapters/claude-code.d.ts.map +1 -1
  5. package/dist/cli/adapters/claude-code.js +7 -3
  6. package/dist/cli/adapters/claude-code.js.map +1 -1
  7. package/dist/cli/adapters/single-file-base.d.ts +18 -0
  8. package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
  9. package/dist/cli/adapters/single-file-base.js +29 -4
  10. package/dist/cli/adapters/single-file-base.js.map +1 -1
  11. package/dist/cli/agent-plugin.test.js +12 -0
  12. package/dist/cli/agent-plugin.test.js.map +1 -1
  13. package/dist/cli/bootstrap.d.ts.map +1 -1
  14. package/dist/cli/bootstrap.js +20 -0
  15. package/dist/cli/bootstrap.js.map +1 -1
  16. package/dist/cli/ci.d.ts.map +1 -1
  17. package/dist/cli/ci.js +6 -4
  18. package/dist/cli/ci.js.map +1 -1
  19. package/dist/cli/command-namespace.test.js +33 -0
  20. package/dist/cli/command-namespace.test.js.map +1 -1
  21. package/dist/cli/convoy-cmd.d.ts.map +1 -1
  22. package/dist/cli/convoy-cmd.js +2 -1
  23. package/dist/cli/convoy-cmd.js.map +1 -1
  24. package/dist/cli/dispatcher.test.js +6 -0
  25. package/dist/cli/dispatcher.test.js.map +1 -1
  26. package/dist/cli/docs-accuracy.test.js +33 -8
  27. package/dist/cli/docs-accuracy.test.js.map +1 -1
  28. package/dist/cli/doctor.d.ts.map +1 -1
  29. package/dist/cli/doctor.js +9 -6
  30. package/dist/cli/doctor.js.map +1 -1
  31. package/dist/cli/init-own-files.test.d.ts +2 -0
  32. package/dist/cli/init-own-files.test.d.ts.map +1 -0
  33. package/dist/cli/init-own-files.test.js +133 -0
  34. package/dist/cli/init-own-files.test.js.map +1 -0
  35. package/dist/cli/init.d.ts.map +1 -1
  36. package/dist/cli/init.js +106 -7
  37. package/dist/cli/init.js.map +1 -1
  38. package/dist/cli/init.test.js +5 -4
  39. package/dist/cli/init.test.js.map +1 -1
  40. package/dist/cli/layers.d.ts.map +1 -1
  41. package/dist/cli/layers.js +13 -4
  42. package/dist/cli/layers.js.map +1 -1
  43. package/dist/cli/lesson.d.ts.map +1 -1
  44. package/dist/cli/lesson.js +6 -5
  45. package/dist/cli/lesson.js.map +1 -1
  46. package/dist/cli/prompt.d.ts.map +1 -1
  47. package/dist/cli/prompt.js +9 -7
  48. package/dist/cli/prompt.js.map +1 -1
  49. package/dist/cli/prompt.test.js +20 -2
  50. package/dist/cli/prompt.test.js.map +1 -1
  51. package/dist/cli/remove.d.ts.map +1 -1
  52. package/dist/cli/remove.js +3 -1
  53. package/dist/cli/remove.js.map +1 -1
  54. package/dist/cli/review.d.ts.map +1 -1
  55. package/dist/cli/review.js +7 -1
  56. package/dist/cli/review.js.map +1 -1
  57. package/dist/cli/sync-check.d.ts.map +1 -1
  58. package/dist/cli/sync-check.js +12 -3
  59. package/dist/cli/sync-check.js.map +1 -1
  60. package/dist/cli/sync.d.ts.map +1 -1
  61. package/dist/cli/sync.js +3 -2
  62. package/dist/cli/sync.js.map +1 -1
  63. package/dist/cli/update.d.ts.map +1 -1
  64. package/dist/cli/update.js +4 -3
  65. package/dist/cli/update.js.map +1 -1
  66. package/dist/cli/website-plugins.test.js +51 -2
  67. package/dist/cli/website-plugins.test.js.map +1 -1
  68. package/dist/orchestrator/plugins/coolify/config.d.ts.map +1 -1
  69. package/dist/orchestrator/plugins/coolify/config.js +13 -0
  70. package/dist/orchestrator/plugins/coolify/config.js.map +1 -1
  71. package/dist/orchestrator/plugins/sentry/config.d.ts.map +1 -1
  72. package/dist/orchestrator/plugins/sentry/config.js +13 -0
  73. package/dist/orchestrator/plugins/sentry/config.js.map +1 -1
  74. package/package.json +1 -1
  75. package/src/cli/adapters/claude-code.ts +7 -3
  76. package/src/cli/adapters/single-file-base.ts +47 -4
  77. package/src/cli/agent-plugin.test.ts +14 -0
  78. package/src/cli/bootstrap.ts +23 -0
  79. package/src/cli/ci.ts +6 -4
  80. package/src/cli/command-namespace.test.ts +35 -0
  81. package/src/cli/convoy/TELEMETRY.md +64 -62
  82. package/src/cli/convoy-cmd.ts +2 -1
  83. package/src/cli/dispatcher.test.ts +7 -0
  84. package/src/cli/docs-accuracy.test.ts +34 -7
  85. package/src/cli/doctor.ts +9 -6
  86. package/src/cli/init-own-files.test.ts +156 -0
  87. package/src/cli/init.test.ts +5 -4
  88. package/src/cli/init.ts +104 -7
  89. package/src/cli/layers.ts +13 -4
  90. package/src/cli/lesson.ts +6 -5
  91. package/src/cli/prompt.test.ts +21 -2
  92. package/src/cli/prompt.ts +11 -7
  93. package/src/cli/remove.ts +3 -0
  94. package/src/cli/review.ts +7 -1
  95. package/src/cli/sync-check.ts +12 -3
  96. package/src/cli/sync.ts +3 -2
  97. package/src/cli/update.ts +4 -3
  98. package/src/cli/website-plugins.test.ts +55 -5
  99. package/src/dashboard/node_modules/.vite/deps/_metadata.json +6 -6
  100. package/src/orchestrator/agents/team-lead.agent.md +2 -2
  101. package/src/orchestrator/customizations/README.md +58 -13
  102. package/src/orchestrator/customizations/logs/README.md +23 -18
  103. package/src/orchestrator/instructions/general.instructions.md +1 -1
  104. package/src/orchestrator/plugins/coolify/config.ts +13 -0
  105. package/src/orchestrator/plugins/sentry/config.ts +13 -0
  106. package/src/orchestrator/prompts/bootstrap-customizations.prompt.md +44 -49
  107. package/src/orchestrator/prompts/brainstorm.prompt.md +2 -2
  108. package/src/orchestrator/prompts/bug-fix.prompt.md +5 -4
  109. package/src/orchestrator/prompts/create-skill.prompt.md +29 -39
  110. package/src/orchestrator/prompts/generate-convoy.prompt.md +1 -1
  111. package/src/orchestrator/prompts/generate-prd.prompt.md +1 -1
  112. package/src/orchestrator/prompts/implement-feature.prompt.md +7 -6
@@ -0,0 +1,156 @@
1
+ /**
2
+ * What `init` says about files that were there before it.
3
+ *
4
+ * A target is often detected because of a file of the user's in its own rules
5
+ * directory — `.cursor/rules/team.mdc` is what makes Cursor a target — and that
6
+ * directory is generated, so the next `sync` removes the file. `init` used to
7
+ * say nothing, and the first anyone heard of it was `sync` naming a file it had
8
+ * just deleted. The same accounting is what makes "Left N existing files
9
+ * untouched" mean files that were there: a fresh seven-target install said 205,
10
+ * every one of them written a moment earlier by the target before.
11
+ */
12
+ import { describe, it, expect, beforeEach, afterEach } from 'vitest'
13
+ import { execFileSync } from 'node:child_process'
14
+ import { mkdtempSync, mkdirSync, rmSync, writeFileSync, readFileSync, existsSync } from 'node:fs'
15
+ import { tmpdir } from 'node:os'
16
+ import { join, resolve } from 'node:path'
17
+
18
+ const repoRoot = resolve(import.meta.dirname, '..', '..')
19
+ const cli = join(repoRoot, 'bin', 'cli.mjs')
20
+
21
+ // `bin/cli.mjs` loads the command modules from `dist/`. CI builds before
22
+ // `npm test`, so nothing here is skipped there.
23
+ const cliBuilt = existsSync(join(repoRoot, 'dist', 'cli', 'init.js'))
24
+
25
+ describe.skipIf(!cliBuilt)('init and the files already there', () => {
26
+ let projectRoot: string
27
+ let home: string
28
+
29
+ const run = (...args: string[]): string =>
30
+ execFileSync('node', [cli, ...args], {
31
+ cwd: projectRoot,
32
+ encoding: 'utf8',
33
+ stdio: ['ignore', 'pipe', 'pipe'],
34
+ // A scratch home, so nothing of the person running the tests is read, and
35
+ // plain text to assert on.
36
+ env: { ...process.env, HOME: home, CLAUDE_CONFIG_DIR: join(home, '.claude'), CODEX_HOME: join(home, '.codex'), NO_COLOR: '1' },
37
+ })
38
+
39
+ beforeEach(() => {
40
+ projectRoot = mkdtempSync(join(tmpdir(), 'oc-own-files-'))
41
+ home = mkdtempSync(join(tmpdir(), 'oc-own-files-home-'))
42
+ execFileSync('git', ['init', '-q'], { cwd: projectRoot })
43
+ })
44
+
45
+ afterEach(() => {
46
+ rmSync(projectRoot, { recursive: true, force: true })
47
+ rmSync(home, { recursive: true, force: true })
48
+ })
49
+
50
+ it('names a rule of yours in a generated directory, and leaves it in place', () => {
51
+ mkdirSync(join(projectRoot, '.cursor', 'rules'), { recursive: true })
52
+ writeFileSync(join(projectRoot, '.cursor', 'rules', 'team.mdc'), '---\nalwaysApply: true\n---\nUse tabs.\n')
53
+
54
+ const out = run('init', '--yes')
55
+
56
+ expect(out).toContain('1 file of yours is in a directory OpenCastle generates')
57
+ expect(out).toContain('.cursor/rules/team.mdc')
58
+ expect(out).toContain('The next sync removes it')
59
+ expect(readFileSync(join(projectRoot, '.cursor', 'rules', 'team.mdc'), 'utf8')).toContain('Use tabs.')
60
+ })
61
+
62
+ it('says nothing of the kind when there is nothing of yours there', () => {
63
+ writeFileSync(join(projectRoot, 'CLAUDE.md'), '# House rules\n')
64
+ expect(run('init', '--yes')).not.toContain('of yours')
65
+ })
66
+
67
+ it('counts nothing as left alone on a fresh install for several targets that share a directory', () => {
68
+ // Cursor, Windsurf and OpenCode all write `.agents/skills/`.
69
+ writeFileSync(join(projectRoot, '.cursorrules'), 'rules\n')
70
+ writeFileSync(join(projectRoot, '.windsurfrules'), 'rules\n')
71
+ writeFileSync(join(projectRoot, 'opencode.json'), '{}\n')
72
+
73
+ const out = run('init', '--yes')
74
+
75
+ expect(out).not.toMatch(/Left \d+ existing files? untouched/)
76
+ const manifest = JSON.parse(readFileSync(join(projectRoot, '.opencastle', 'manifest.json'), 'utf8'))
77
+ const customizable: string[] = manifest.managedPaths.customizable
78
+ expect(customizable.filter((p) => p === '.opencastle/')).toHaveLength(1)
79
+ expect(new Set(manifest.managedPaths.framework).size).toBe(manifest.managedPaths.framework.length)
80
+ })
81
+
82
+ it('leaves out the notes for a database and a CMS the project does not use', () => {
83
+ writeFileSync(join(projectRoot, 'CLAUDE.md'), '# House rules\n')
84
+ run('init', '--yes')
85
+ expect(existsSync(join(projectRoot, '.opencastle', 'stack', 'supabase-config.md'))).toBe(false)
86
+ expect(existsSync(join(projectRoot, '.opencastle', 'stack', 'sanity-config.md'))).toBe(false)
87
+ })
88
+
89
+ it('writes the MCP config of an assistant a second init adds', () => {
90
+ // Recompiling the new target instead of installing it left it with no
91
+ // servers, and every check said all was well.
92
+ writeFileSync(join(projectRoot, 'CLAUDE.md'), '# House rules\n')
93
+ run('init', '--yes')
94
+ writeFileSync(join(projectRoot, '.cursorrules'), 'rules\n')
95
+ run('init', '--yes')
96
+ expect(existsSync(join(projectRoot, '.cursor', 'mcp.json'))).toBe(true)
97
+ })
98
+
99
+ it('does not put back, on a second init, the templates the first one pruned', () => {
100
+ writeFileSync(join(projectRoot, 'CLAUDE.md'), '# House rules\n')
101
+ run('init', '--yes')
102
+ const stack = join(projectRoot, '.opencastle', 'stack')
103
+ for (const name of ['cms-config.md', 'database-config.md', 'sanity-config.md', 'supabase-config.md']) {
104
+ expect(existsSync(join(stack, name)), name).toBe(false)
105
+ }
106
+ run('init', '--yes')
107
+ for (const name of ['cms-config.md', 'database-config.md', 'sanity-config.md', 'supabase-config.md']) {
108
+ expect(existsSync(join(stack, name)), `${name} after a second init`).toBe(false)
109
+ }
110
+ })
111
+
112
+ it('keeps the notes for the one it does use', () => {
113
+ writeFileSync(join(projectRoot, 'CLAUDE.md'), '# House rules\n')
114
+ writeFileSync(join(projectRoot, 'package.json'), JSON.stringify({ name: 'x', dependencies: { '@supabase/supabase-js': '2.0.0' } }))
115
+ run('init', '--yes')
116
+ expect(existsSync(join(projectRoot, '.opencastle', 'stack', 'supabase-config.md'))).toBe(true)
117
+ expect(existsSync(join(projectRoot, '.opencastle', 'stack', 'sanity-config.md'))).toBe(false)
118
+ })
119
+ })
120
+
121
+ describe.skipIf(!cliBuilt)('sync --check on a lessons index that is behind', () => {
122
+ let projectRoot: string
123
+ let home: string
124
+
125
+ beforeEach(() => {
126
+ projectRoot = mkdtempSync(join(tmpdir(), 'oc-lessons-check-'))
127
+ home = mkdtempSync(join(tmpdir(), 'oc-lessons-check-home-'))
128
+ execFileSync('git', ['init', '-q'], { cwd: projectRoot })
129
+ })
130
+
131
+ afterEach(() => {
132
+ rmSync(projectRoot, { recursive: true, force: true })
133
+ rmSync(home, { recursive: true, force: true })
134
+ })
135
+
136
+ it('files it under the sources that changed, not under MCP servers', () => {
137
+ const env = { ...process.env, HOME: home, CLAUDE_CONFIG_DIR: join(home, '.claude'), CODEX_HOME: join(home, '.codex'), NO_COLOR: '1' }
138
+ writeFileSync(join(projectRoot, 'CLAUDE.md'), '# House rules\n')
139
+ execFileSync('node', [cli, 'init', '--yes'], { cwd: projectRoot, env, stdio: 'ignore' })
140
+ // A lesson that arrived in a merge, with the index not yet rebuilt.
141
+ mkdirSync(join(projectRoot, '.opencastle', 'lessons'), { recursive: true })
142
+ writeFileSync(
143
+ join(projectRoot, '.opencastle', 'lessons', '2026-10-03-quote-shell-variables.md'),
144
+ '---\nid: "2026-10-03-quote-shell-variables"\ntitle: "Quote shell variables"\ncategory: "terminal"\nseverity: "medium"\nadded: "2026-10-03"\n---\n\n**Problem:** Unquoted variables break on spaces.\n',
145
+ )
146
+ let out = ''
147
+ try {
148
+ execFileSync('node', [cli, 'sync', '--check'], { cwd: projectRoot, env, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] })
149
+ } catch (err) {
150
+ out = String((err as { stdout?: string }).stdout ?? '')
151
+ }
152
+ expect(out).toContain('.opencastle/LESSONS-LEARNED.md')
153
+ expect(out).toContain('Sources changed since the last sync')
154
+ expect(out).not.toContain('MCP servers sync would change')
155
+ })
156
+ })
@@ -801,7 +801,7 @@ describe('Claude Code adapter install', () => {
801
801
  expect(content).not.toContain('**supabase-database**')
802
802
  })
803
803
 
804
- it('strips frontmatter from agent files in .claude/agents/', async () => {
804
+ it('writes agent files in .claude/agents/ with only the frontmatter Claude Code reads', async () => {
805
805
  const adapter = await IDE_ADAPTERS['claude-code']()
806
806
  await adapter.install(PKG_ROOT, tempDir, STACK_EMPTY, EMPTY_REPO_INFO)
807
807
 
@@ -812,9 +812,10 @@ describe('Claude Code adapter install', () => {
812
812
  expect(agents).not.toContain('data-engineer.agent.md')
813
813
 
814
814
  const devAgent = await readFile(join(agentsDir, 'developer.agent.md'), 'utf8')
815
- // Should NOT start with frontmatter
816
- expect(devAgent).not.toMatch(/^---\n/)
817
- // Should contain the body content (starts with comment or heading)
815
+ // A name and a description make it a subagent; the source's VS Code fields
816
+ // (tools, tier, handoffs) are not carried over.
817
+ expect(devAgent).toMatch(/^---\nname: developer\ndescription: "[^"\n]+"\n---\n/)
818
+ expect(devAgent).not.toMatch(/^tier:/m)
818
819
  expect(devAgent).toContain('Developer')
819
820
  })
820
821
 
package/src/cli/init.ts CHANGED
@@ -11,6 +11,7 @@ import { getPluginsBySubCategory } from '../orchestrator/plugins/index.js'
11
11
  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
+ import { filesUnderDir } from './adapters/single-file-base.js'
14
15
  import { IDE_LABELS } from './types.js'
15
16
  import type { CliContext, CopyResults, IdeAdapter, IdeChoice, TechTool, TeamTool, StackConfig } from './types.js'
16
17
  import { bootstrapCustomizations } from './bootstrap.js'
@@ -423,6 +424,33 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
423
424
  }
424
425
 
425
426
  // ── Run adapters for each selected IDE ──────────────────────────
427
+ // Files already in the directories the chosen targets generate. A target is
428
+ // often detected *because* of one — `.cursor/rules/team.mdc` is what made
429
+ // Cursor a target — and the directory is the target's own, so the next `sync`
430
+ // removes it as output with no source. `init` said nothing about it; the
431
+ // first anyone heard was `sync` naming a file it had just deleted.
432
+ const inGeneratedDirs = new Set<string>()
433
+ for (const ide of ides) {
434
+ const adapter = await IDE_ADAPTERS[ide]()
435
+ for (const dir of adapter.getManagedPaths().framework) {
436
+ if (!dir.endsWith('/')) continue
437
+ for (const rel of filesUnderDir(resolve(projectRoot, dir))) {
438
+ // A prompt of yours beside ours in `.github/prompts/` stays; only what a
439
+ // target claims is at risk.
440
+ if (adapter.ownsFile && !adapter.ownsFile(`${dir}${rel}`, projectRoot)) continue
441
+ inGeneratedDirs.add(resolve(projectRoot, dir, rel))
442
+ }
443
+ }
444
+ }
445
+ const produced = new Set<string>()
446
+ const removedByReinit: string[] = []
447
+ const previousIdes = new Set<string>(existing?.ides ?? (existing?.ide ? [existing.ide] : []))
448
+ // Skipped means "was already there", and with several targets sharing
449
+ // `.agents/skills/` the second one found the first one's output: a fresh
450
+ // seven-target install reported "Left 205 existing files untouched".
451
+ const createdThisRun = new Set<string>()
452
+ const leftAlone = new Set<string>()
453
+
426
454
  let totalCreated = 0
427
455
  let totalSkipped = 0
428
456
  const skippedPaths: string[] = []
@@ -460,9 +488,14 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
460
488
  // failed the same way, and `remove --all` refused to uninstall what it had
461
489
  // just installed. Single-target installs write the root file first and so
462
490
  // throw before anything lands, which is why this only showed up with two.
491
+ // An assistant added by `init --customize` is a first install for that
492
+ // target. Recompiling it instead never wrote its MCP config — `update`
493
+ // leaves that to `sync`, and `sync` found nothing to do — so the new
494
+ // assistant ran with no servers while every check reported all clear.
495
+ const compiledBefore = isReinit && previousIdes.has(ide)
463
496
  let results: CopyResults
464
497
  try {
465
- results = isReinit
498
+ results = compiledBefore
466
499
  ? await adapter.update(pkgRoot, projectRoot, stack, combinedRepoInfo, source)
467
500
  : await adapter.install(pkgRoot, projectRoot, stack, combinedRepoInfo, source)
468
501
  } catch (err) {
@@ -470,8 +503,16 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
470
503
  continue
471
504
  }
472
505
  totalCreated += results.created.length
473
- totalSkipped += results.skipped.length
474
- skippedPaths.push(...results.skipped)
506
+ for (const p of results.skipped) {
507
+ if (createdThisRun.has(resolve(projectRoot, p))) continue
508
+ leftAlone.add(resolve(projectRoot, p))
509
+ skippedPaths.push(p)
510
+ }
511
+ for (const p of results.created) createdThisRun.add(resolve(projectRoot, p))
512
+ for (const abs of [...results.created, ...results.copied, ...results.skipped, ...(results.visited ?? [])]) {
513
+ produced.add(resolve(projectRoot, abs))
514
+ }
515
+ removedByReinit.push(...(results.deleted ?? []))
475
516
  for (const file of results.unreadable ?? []) {
476
517
  noteUnreadable(unreadable, file)
477
518
  }
@@ -484,8 +525,15 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
484
525
  tornRoots.push(...(results.tornRoots ?? []))
485
526
 
486
527
  const managed = adapter.getManagedPaths()
487
- allManagedPaths.framework.push(...managed.framework)
488
- allManagedPaths.customizable.push(...managed.customizable)
528
+ // Deduplicated like `merged` below: every target declares `.opencastle/`,
529
+ // so a four-target manifest listed it four times and the first `sync`
530
+ // rewrote the manifest to say it once.
531
+ for (const f of managed.framework) {
532
+ if (!allManagedPaths.framework.includes(f)) allManagedPaths.framework.push(f)
533
+ }
534
+ for (const f of managed.customizable) {
535
+ if (!allManagedPaths.customizable.includes(f)) allManagedPaths.customizable.push(f)
536
+ }
489
537
  // Deduplicated: opencode and codex share AGENTS.md, so a per-adapter push
490
538
  // listed it twice — "Merged into your existing …, AGENTS.md, AGENTS.md".
491
539
  for (const m of managed.merged ?? []) {
@@ -493,6 +541,8 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
493
541
  }
494
542
  }
495
543
 
544
+ totalSkipped = leftAlone.size
545
+
496
546
  // If all files were skipped (orphaned install — no manifest but files exist).
497
547
  //
498
548
  // Or if a release before the `oc:` namespace left its commands here. The
@@ -546,6 +596,10 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
546
596
  // opposite of what happened, on the one path that exists to overwrite.
547
597
  totalCreated += results.created.length + results.copied.length
548
598
  totalSkipped += results.skipped.length
599
+ for (const abs of [...results.created, ...results.copied, ...results.skipped, ...(results.visited ?? [])]) {
600
+ produced.add(resolve(projectRoot, abs))
601
+ }
602
+ removedByReinit.push(...(results.deleted ?? []))
549
603
  for (const file of results.unreadable ?? []) {
550
604
  noteUnreadable(unreadable, file)
551
605
  }
@@ -571,7 +625,15 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
571
625
  if (existsSync(custSrcDir)) {
572
626
  const custDestDir = resolve(projectRoot, '.opencastle')
573
627
  const custTransform = getCustomizationsTransform(stack)
574
- const sub = await copyDir(custSrcDir, custDestDir, { transform: custTransform })
628
+ // Over an existing `.opencastle/`, the templates bootstrap prunes or renames
629
+ // on the first run — `stack/`, the tracker config — stay as that run left
630
+ // them. Copying them again put back every one it had removed: a project
631
+ // with no CMS got `cms-config.md` and `sanity-config.md` on its second init.
632
+ const prunedOnce = (rel: string) => rel === 'stack' || rel.startsWith('stack/') || rel === 'project/tracker-config.md'
633
+ const sub = await copyDir(custSrcDir, custDestDir, {
634
+ transform: custTransform,
635
+ filter: (_name, srcPath) => !(alreadyScaffolded && prunedOnce(relative(custSrcDir, srcPath).split('\\').join('/'))),
636
+ })
575
637
  totalCreated += sub.created.length
576
638
  totalSkipped += sub.skipped.length
577
639
  }
@@ -696,6 +758,36 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
696
758
  console.log(` ${c.dim('→')} Left ${totalSkipped} existing ${noun} untouched`)
697
759
  }
698
760
 
761
+ // Re-running `init` recompiles with `sync`'s sweep, and said nothing of what
762
+ // the sweep removed; `sync` names every file.
763
+ const removed = [...new Set(removedByReinit)].filter((rel) => !existsSync(resolve(projectRoot, rel)))
764
+ if (removed.length > 0) {
765
+ console.log(`\n ${c.yellow('!')} Removed ${removed.length} file(s) no longer produced by any source:\n`)
766
+ for (const rel of removed.slice(0, 10)) console.log(` ${c.dim(rel)}`)
767
+ if (removed.length > 10) console.log(` ${c.dim(`… and ${removed.length - 10} more`)}`)
768
+ }
769
+
770
+ // Files of the user's in a directory a target now owns. Left in place, so the
771
+ // assistant keeps reading them today — but `sync` removes them, and
772
+ // `sync --check` fails on them, so say so now rather than at the deletion.
773
+ const theirs = [...inGeneratedDirs]
774
+ .filter((abs) => !produced.has(abs) && existsSync(abs))
775
+ .map((abs) => relative(projectRoot, abs).split('\\').join('/'))
776
+ if (theirs.length > 0) {
777
+ const one = theirs.length === 1
778
+ const it = one ? 'it' : 'them'
779
+ console.log(
780
+ `\n ${c.yellow('⚠')} ${theirs.length} ${one ? 'file of yours is' : 'files of yours are'} in a directory OpenCastle generates:\n`,
781
+ )
782
+ for (const rel of theirs.slice(0, 10)) console.log(` ${c.bold(rel)}`)
783
+ if (theirs.length > 10) console.log(` ${c.dim(`… and ${theirs.length - 10} more`)}`)
784
+ console.log(`\n ${c.dim(`The next sync removes ${it}; until then sync --check reports ${it}.`)}`)
785
+ console.log(
786
+ ` ${c.dim(`To keep ${it}, move ${it} into .opencastle/ (instructions/, skills/<name>/ or agents/),`)}`,
787
+ )
788
+ console.log(` ${c.dim('and the next sync compiles it for every assistant.')}`)
789
+ }
790
+
699
791
  // Name the root files that already existed and were merged rather than replaced.
700
792
  const mergedRoots: string[] = []
701
793
  for (const p of allManagedPaths.merged) {
@@ -865,8 +957,13 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
865
957
  `${c.cyan(`/${COMMAND_NAMESPACE}:bootstrap-customizations`)} first on an existing codebase`,
866
958
  )
867
959
  }
960
+ // Everything, not only `.opencastle/`: the generated config is committed on
961
+ // purpose (the `.gitignore` block says so, and `doctor` checks it), and this
962
+ // line was the one place that told people to commit the sources alone.
963
+ step++
964
+ console.log(` ${step}. Commit what this wrote, .opencastle/ included — teammates get the same setup on clone`)
868
965
  step++
869
- console.log(` ${step}. Commit the .opencastle/ folder to your repository`)
966
+ console.log(` ${step}. ${c.cyan('opencastle ci')} — fail a pull request whose generated config no longer matches`)
870
967
 
871
968
  // Name the assistants not yet being compiled for — the reason to come back.
872
969
  const configured = new Set(ides)
package/src/cli/layers.ts CHANGED
@@ -327,10 +327,19 @@ export function filesUnder(root: string, within?: string[], onSkip?: (abs: strin
327
327
  return out
328
328
  }
329
329
 
330
- /** A digest of what a layer contributes: its config and its content directories. */
331
- function layerIntegrity(root: string): string {
330
+ /**
331
+ * A digest of what a layer contributes: its config and its content directories.
332
+ *
333
+ * An Agent Plugin keeps only its skills at the root; its servers are in
334
+ * `mcp.json` and everything else in `dev.opencastle/`. Hashing the root alone
335
+ * left all of that out, so an instruction edited without a version bump moved
336
+ * nothing in the lock and `review` had nothing to say about it.
337
+ */
338
+ function layerIntegrity(root: string, extensionRoot?: string): string {
332
339
  const hash = createHash('sha256')
333
- const parts = [LAYER_CONFIG_FILE, ...CONTENT_KINDS.map((k) => LAYER_DIR[k])]
340
+ const own = [LAYER_CONFIG_FILE, ...CONTENT_KINDS.map((k) => LAYER_DIR[k])]
341
+ const ext = extensionRoot ? relative(root, extensionRoot).split(sep).join('/') : null
342
+ const parts = ext ? [...own, 'plugin.json', 'mcp.json', ...own.map((p) => `${ext}/${p}`)] : own
334
343
  for (const part of parts) {
335
344
  const abs = join(root, part)
336
345
  if (!existsSync(abs)) continue
@@ -525,7 +534,7 @@ function loadExtends(
525
534
  for (const inner of plugin.config.extends ?? []) {
526
535
  loadExtends(inner, plugin.extensionRoot, plugin.configFile, [...chain, real], ctx)
527
536
  }
528
- ctx.layers.push({ id, kind: 'baseline', root, version: version ?? plugin.version, integrity: layerIntegrity(root), ...plugin })
537
+ ctx.layers.push({ id, kind: 'baseline', root, version: version ?? plugin.version, integrity: layerIntegrity(root, plugin.extensionRoot), ...plugin })
529
538
  return
530
539
  }
531
540
 
package/src/cli/lesson.ts CHANGED
@@ -60,12 +60,13 @@ const HELP = `
60
60
  --category terminal \\
61
61
  --severity medium \\
62
62
  --problem "Unquoted variables break on paths with spaces" \\
63
- --wrong 'rm -rf \\$DIR/old' \\
64
- --correct 'rm -rf "\\$DIR/old"' \\
63
+ --wrong 'rm -rf $DIR/old' \\
64
+ --correct 'rm -rf "$DIR/old"' \\
65
65
  --cite scripts/clean.sh:12
66
66
 
67
67
  opencastle lesson verify 2026-10-02-always-quote-shell-variables
68
- opencastle lesson archive LES-004 --into .opencastle/skills/git-workflow/SKILL.md
68
+ opencastle lesson archive 2026-10-02-always-quote-shell-variables \\
69
+ --into .opencastle/skills/git-workflow/SKILL.md
69
70
  `
70
71
 
71
72
  /** The `.opencastle/` this lesson belongs to: the override, or the nearest one up from here. */
@@ -219,7 +220,7 @@ async function add(dir: string, projectRoot: string, p: Parsed): Promise<void> {
219
220
 
220
221
  async function verify(dir: string, projectRoot: string, p: Parsed): Promise<void> {
221
222
  const [ref] = p.positional
222
- if (!ref) fail('verify needs the id of a lesson, e.g. opencastle lesson verify LES-004')
223
+ if (!ref) fail('verify needs the id of a lesson, e.g. opencastle lesson verify 2026-10-02-always-quote-shell-variables')
223
224
  checkCitations(projectRoot, p.cites)
224
225
  if (!p.dryRun) reindex(dir)
225
226
  const { lessons } = readLessons(dir)
@@ -240,7 +241,7 @@ async function verify(dir: string, projectRoot: string, p: Parsed): Promise<void
240
241
  async function archive(dir: string, projectRoot: string, p: Parsed): Promise<void> {
241
242
  const [ref] = p.positional
242
243
  const into = p.values.get('--into')
243
- if (!ref) fail('archive needs the id of a lesson, e.g. opencastle lesson archive LES-004 --into <file>')
244
+ if (!ref) fail('archive needs the id of a lesson, e.g. opencastle lesson archive 2026-10-02-always-quote-shell-variables --into <file>')
244
245
  if (!into) fail('archive needs --into <file>: the skill or instruction file the lesson was merged into')
245
246
  const problem = citationProblem(projectRoot, into)
246
247
  if (problem) fail(`--into: ${problem}`)
@@ -1,5 +1,5 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { computeVisibleWindow } from './prompt.js';
1
+ import { describe, it, expect, afterEach } from 'vitest';
2
+ import { computeVisibleWindow, c } from './prompt.js';
3
3
 
4
4
  describe('computeVisibleWindow', () => {
5
5
  it('returns full range when all items fit', () => {
@@ -64,3 +64,22 @@ describe('computeVisibleWindow', () => {
64
64
  expect(end).toBeGreaterThan(10);
65
65
  });
66
66
  });
67
+
68
+ describe('colours', () => {
69
+ const saved = process.env.NO_COLOR;
70
+ afterEach(() => {
71
+ if (saved === undefined) delete process.env.NO_COLOR;
72
+ else process.env.NO_COLOR = saved;
73
+ });
74
+
75
+ it('wrap text in an SGR sequence by default', () => {
76
+ delete process.env.NO_COLOR;
77
+ expect(c.green('ok')).toBe('\x1B[32mok\x1B[0m');
78
+ });
79
+
80
+ it('are left out when NO_COLOR is set (no-color.org)', () => {
81
+ process.env.NO_COLOR = '1';
82
+ expect(c.green('ok')).toBe('ok');
83
+ expect(c.bold(c.dim('x'))).toBe('x');
84
+ });
85
+ });
package/src/cli/prompt.ts CHANGED
@@ -16,15 +16,19 @@ function moveUp(n: number): string {
16
16
 
17
17
  // ── Color helpers ─────────────────────────────────────────────────
18
18
 
19
+ /** One SGR style, unless `NO_COLOR` is set (https://no-color.org). Read per call, so a test can set it. */
20
+ const sgr = (code: string) => (s: string) =>
21
+ process.env.NO_COLOR ? s : `\x1B[${code}m${s}\x1B[0m`;
22
+
19
23
  /** ANSI color helpers for CLI output. */
20
24
  export const c = {
21
- cyan: (s: string) => `\x1B[36m${s}\x1B[0m`,
22
- green: (s: string) => `\x1B[32m${s}\x1B[0m`,
23
- yellow: (s: string) => `\x1B[33m${s}\x1B[0m`,
24
- red: (s: string) => `\x1B[31m${s}\x1B[0m`,
25
- bold: (s: string) => `\x1B[1m${s}\x1B[0m`,
26
- dim: (s: string) => `\x1B[2m${s}\x1B[0m`,
27
- magenta: (s: string) => `\x1B[35m${s}\x1B[0m`,
25
+ cyan: sgr('36'),
26
+ green: sgr('32'),
27
+ yellow: sgr('33'),
28
+ red: sgr('31'),
29
+ bold: sgr('1'),
30
+ dim: sgr('2'),
31
+ magenta: sgr('35'),
28
32
  };
29
33
 
30
34
  // ── Scrollable window helper ──────────────────────────────────────
package/src/cli/remove.ts CHANGED
@@ -309,9 +309,12 @@ export default async function remove({ args }: CliContext): Promise<void> {
309
309
  }
310
310
 
311
311
  if (!assumeYes) {
312
+ // `refuse`: removing is not undone by running it again, so a piped run that
313
+ // ran out of answers aborts, as `sync` does, instead of taking the default.
312
314
  const proceed = await confirm(
313
315
  mode === 'all' ? 'Go ahead?' : 'Continue?',
314
316
  mode !== 'all',
317
+ 'refuse',
315
318
  )
316
319
  if (!proceed) {
317
320
  console.log(' Aborted.\n')
package/src/cli/review.ts CHANGED
@@ -366,7 +366,13 @@ function renderTerminal(report: ReviewReport): void {
366
366
  export function lockAtRef(projectRoot: string, ref: string): Lock | null {
367
367
  let prefix: string
368
368
  try {
369
- prefix = execFileSync('git', ['rev-parse', '--show-prefix'], { cwd: projectRoot, encoding: 'utf8' }).trim()
369
+ // Git's own "fatal: not a git repository" went to the terminal above the
370
+ // sentence below, which says the same thing in terms of this command.
371
+ prefix = execFileSync('git', ['rev-parse', '--show-prefix'], {
372
+ cwd: projectRoot,
373
+ encoding: 'utf8',
374
+ stdio: ['ignore', 'pipe', 'ignore'],
375
+ }).trim()
370
376
  } catch {
371
377
  throw new Error('this is not a git repository, so there is no base to compare with')
372
378
  }
@@ -718,7 +718,16 @@ function render(report: CheckReport): void {
718
718
  // The lock is not edited by anyone; when it differs, the sources moved and
719
719
  // nobody has synced. Filed under "edited in place" it told people they had
720
720
  // an edit to lose.
721
- const lockDrift = [...changed, ...missing].filter((d) => d.path === LOCK_REL)
721
+ //
722
+ // The lessons index is the same kind of thing: compiled from
723
+ // `.opencastle/lessons/` and stale until `sync` runs. It was filed under "MCP
724
+ // servers sync would change", which it has nothing to do with.
725
+ const lessonsIndex = `.opencastle/${LESSONS_INDEX}`
726
+ const lockDrift = [
727
+ ...[...changed, ...missing].filter((d) => d.path === LOCK_REL),
728
+ ...outdated.filter((d) => d.path === lessonsIndex),
729
+ ]
730
+ const outdatedMcp = outdated.filter((d) => d.path !== lessonsIndex)
722
731
  const changedFiles = changed.filter((d) => d.path !== LOCK_REL)
723
732
  const missingFiles = missing.filter((d) => d.path !== LOCK_REL)
724
733
  if (lockDrift.length > 0) {
@@ -742,11 +751,11 @@ function render(report: CheckReport): void {
742
751
  console.log('')
743
752
  }
744
753
 
745
- if (outdated.length > 0) {
754
+ if (outdatedMcp.length > 0) {
746
755
  console.log(
747
756
  ` ${c.bold('MCP servers sync would change')} ${c.dim('(integration defaults move forward, team servers are written as defined; entries you added or edited stay yours)')}`,
748
757
  )
749
- for (const d of outdated) {
758
+ for (const d of outdatedMcp) {
750
759
  console.log(` ${c.yellow('~')} ${d.path} ${c.dim(`(${d.ide})`)}`)
751
760
  if (d.detail) console.log(` ${c.dim(d.detail)}`)
752
761
  }
package/src/cli/sync.ts CHANGED
@@ -19,10 +19,11 @@ const SYNC_HELP = `
19
19
  Options:
20
20
  --check Report drift and exit non-zero; writes nothing (for CI)
21
21
  --dry-run Preview what would change
22
- --force Sync even when versions match
22
+ --force Recompile even when everything already matches its sources
23
23
  --allow-downgrade Recompile with this OpenCastle even though a newer one
24
24
  compiled the project
25
- --reconfigure Re-run IDE and stack selection
25
+ --reconfigure Choose the tech and team tools again (the assistants
26
+ are chosen by opencastle init)
26
27
  --yes Skip the confirmation prompt
27
28
  --json Machine-readable output (with --check)
28
29
  --help, -h Show this help
package/src/cli/update.ts CHANGED
@@ -75,7 +75,8 @@ const UPDATE_HELP = `
75
75
  --force Force update even if versions match
76
76
  --allow-downgrade Recompile with this OpenCastle even though a newer one
77
77
  compiled the project
78
- --reconfigure Re-run IDE and stack selection
78
+ --reconfigure Choose the tech and team tools again (the assistants
79
+ are chosen by opencastle init)
79
80
  --help, -h Show this help
80
81
  `
81
82
 
@@ -422,11 +423,11 @@ export default async function update({
422
423
 
423
424
  if (isVersionBump) {
424
425
  console.log(
425
- `\n 🏰 ${c.bold('OpenCastle')} ${dryRun ? 'dry-run' : 'update'}: ${c.dim(`v${manifest.version}`)} → ${c.green(`v${pkg.version}`)}\n`
426
+ `\n 🏰 ${c.bold('OpenCastle')} ${dryRun ? 'dry-run' : 'sync'}: ${c.dim(`v${manifest.version}`)} → ${c.green(`v${pkg.version}`)}\n`
426
427
  )
427
428
  } else {
428
429
  console.log(
429
- `\n 🏰 ${c.bold('OpenCastle')} ${dryRun ? 'dry-run' : 'reconfigure'} ${c.dim(`v${pkg.version}`)}\n`
430
+ `\n 🏰 ${c.bold('OpenCastle')} ${dryRun ? 'dry-run' : 'sync'} ${c.dim(`v${pkg.version}`)}\n`
430
431
  )
431
432
  }
432
433