opencastle 1.6.4 → 1.7.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 (76) hide show
  1. package/dist/cli/baseline.d.ts.map +1 -1
  2. package/dist/cli/baseline.js +8 -0
  3. package/dist/cli/baseline.js.map +1 -1
  4. package/dist/cli/bootstrap.d.ts.map +1 -1
  5. package/dist/cli/bootstrap.js +31 -9
  6. package/dist/cli/bootstrap.js.map +1 -1
  7. package/dist/cli/bootstrap.test.js +10 -0
  8. package/dist/cli/bootstrap.test.js.map +1 -1
  9. package/dist/cli/detect.d.ts.map +1 -1
  10. package/dist/cli/detect.js +32 -0
  11. package/dist/cli/detect.js.map +1 -1
  12. package/dist/cli/detect.test.js +23 -0
  13. package/dist/cli/detect.test.js.map +1 -1
  14. package/dist/cli/init.d.ts.map +1 -1
  15. package/dist/cli/init.js +10 -5
  16. package/dist/cli/init.js.map +1 -1
  17. package/dist/cli/layers.d.ts.map +1 -1
  18. package/dist/cli/layers.js +21 -1
  19. package/dist/cli/layers.js.map +1 -1
  20. package/dist/cli/layers.test.js +17 -0
  21. package/dist/cli/layers.test.js.map +1 -1
  22. package/dist/cli/manifest.d.ts +9 -0
  23. package/dist/cli/manifest.d.ts.map +1 -1
  24. package/dist/cli/manifest.js +12 -0
  25. package/dist/cli/manifest.js.map +1 -1
  26. package/dist/cli/project-facts-lang.d.ts +36 -0
  27. package/dist/cli/project-facts-lang.d.ts.map +1 -0
  28. package/dist/cli/project-facts-lang.js +323 -0
  29. package/dist/cli/project-facts-lang.js.map +1 -0
  30. package/dist/cli/project-facts.d.ts +5 -0
  31. package/dist/cli/project-facts.d.ts.map +1 -1
  32. package/dist/cli/project-facts.js +28 -11
  33. package/dist/cli/project-facts.js.map +1 -1
  34. package/dist/cli/project-facts.test.js +70 -0
  35. package/dist/cli/project-facts.test.js.map +1 -1
  36. package/dist/cli/promote-command.test.js +7 -0
  37. package/dist/cli/promote-command.test.js.map +1 -1
  38. package/dist/cli/promote.d.ts +7 -1
  39. package/dist/cli/promote.d.ts.map +1 -1
  40. package/dist/cli/promote.js +16 -2
  41. package/dist/cli/promote.js.map +1 -1
  42. package/dist/cli/stack-config-update.test.js +21 -1
  43. package/dist/cli/stack-config-update.test.js.map +1 -1
  44. package/dist/cli/stack-config.d.ts +20 -0
  45. package/dist/cli/stack-config.d.ts.map +1 -1
  46. package/dist/cli/stack-config.js +36 -0
  47. package/dist/cli/stack-config.js.map +1 -1
  48. package/dist/cli/team-commands.test.js +25 -0
  49. package/dist/cli/team-commands.test.js.map +1 -1
  50. package/dist/cli/team-config.d.ts +7 -2
  51. package/dist/cli/team-config.d.ts.map +1 -1
  52. package/dist/cli/team-config.js +8 -3
  53. package/dist/cli/team-config.js.map +1 -1
  54. package/dist/cli/update.d.ts.map +1 -1
  55. package/dist/cli/update.js +13 -16
  56. package/dist/cli/update.js.map +1 -1
  57. package/package.json +1 -1
  58. package/src/cli/baseline.ts +10 -0
  59. package/src/cli/bootstrap.test.ts +11 -0
  60. package/src/cli/bootstrap.ts +31 -9
  61. package/src/cli/detect.test.ts +27 -0
  62. package/src/cli/detect.ts +29 -0
  63. package/src/cli/init.ts +10 -5
  64. package/src/cli/layers.test.ts +20 -0
  65. package/src/cli/layers.ts +20 -1
  66. package/src/cli/manifest.ts +13 -0
  67. package/src/cli/project-facts-lang.ts +338 -0
  68. package/src/cli/project-facts.test.ts +75 -0
  69. package/src/cli/project-facts.ts +31 -11
  70. package/src/cli/promote-command.test.ts +8 -0
  71. package/src/cli/promote.ts +16 -2
  72. package/src/cli/stack-config-update.test.ts +25 -1
  73. package/src/cli/stack-config.ts +36 -0
  74. package/src/cli/team-commands.test.ts +28 -0
  75. package/src/cli/team-config.ts +10 -3
  76. package/src/cli/update.ts +15 -18
@@ -148,6 +148,42 @@ export function getIncludedPluginIds(stack: StackConfig): Set<string> {
148
148
  return new Set([...stack.techTools, ...stack.teamTools]);
149
149
  }
150
150
 
151
+ /** Frameworks of Python and Go that render pages, not only an API. */
152
+ const RENDERS_PAGES = ['django', 'flask']
153
+
154
+ /**
155
+ * A Python or Go project with no JavaScript in it, and no framework that
156
+ * renders pages: an API service, a CLI, a worker. It has no use for TypeScript
157
+ * or web-interface rules, and nothing for a browser to test.
158
+ */
159
+ export function servesNoWebInterface(repoInfo?: RepoInfo): boolean {
160
+ const language = repoInfo?.language
161
+ if (language !== 'python' && language !== 'go') return false
162
+ if (repoInfo?.packageManager || repoInfo?.styling?.length) return false
163
+ return !(repoInfo?.frameworks ?? []).some((f) => RENDERS_PAGES.includes(f))
164
+ }
165
+
166
+ /**
167
+ * Core skills to leave out for what the project is. A FastAPI service was
168
+ * given TypeScript, React, SEO and frontend-design rules on its first day; a
169
+ * Django or Flask app, which renders pages, keeps the web ones.
170
+ */
171
+ export function getExcludedCoreSkills(repoInfo?: RepoInfo): Set<string> {
172
+ const language = repoInfo?.language
173
+ if ((language !== 'python' && language !== 'go') || repoInfo?.packageManager) return new Set()
174
+ const web = servesNoWebInterface(repoInfo) ? ['frontend-design', 'accessibility-standards', 'seo-patterns'] : []
175
+ return new Set(['typescript-best-practices', ...web])
176
+ }
177
+
178
+ /**
179
+ * Whether an integration starts selected. Chrome DevTools is preselected for
180
+ * browser checks, which a project with no web interface cannot use.
181
+ */
182
+ export function isPreselected(plugin: { preselected?: boolean; subCategory?: string }, repoInfo?: RepoInfo): boolean {
183
+ if (!plugin.preselected) return false
184
+ return !(plugin.subCategory === 'e2e-testing' && servesNoWebInterface(repoInfo))
185
+ }
186
+
151
187
  /**
152
188
  * Agents to EXCLUDE — content-engineer if no CMS, data-engineer if no DB.
153
189
  */
@@ -172,6 +172,25 @@ describe.skipIf(!built)('a repository extending a baseline', () => {
172
172
  expect(init.out).toContain('in your shell — .env is committed here')
173
173
  })
174
174
 
175
+ it('init run again leaves an unchanged manifest alone, timestamp and all', () => {
176
+ const path = join(dir, '.opencastle', 'manifest.json')
177
+ const before = readFileSync(path, 'utf8')
178
+ expect(run(dir, ['init', '--yes']).code).toBe(0)
179
+ expect(readFileSync(path, 'utf8')).toBe(before)
180
+ })
181
+
182
+ it('sync does not call a project healthy over a server only a person can fix', () => {
183
+ // Not on the baseline's allowlist, and added by hand: sync cannot change it.
184
+ const mcp = join(dir, '.vscode', 'mcp.json')
185
+ const config = JSON.parse(readFileSync(mcp, 'utf8'))
186
+ config.servers['my-tool'] = { command: 'npx', args: ['-y', 'my-tool-mcp@1.0.0'] }
187
+ writeFileSync(mcp, JSON.stringify(config, null, 2))
188
+ const sync = run(dir, ['sync', '--yes'])
189
+ expect(sync.code).toBe(0)
190
+ expect(sync.out).toContain('1 MCP server entry needs fixing by hand')
191
+ expect(sync.out).toContain('npx opencastle doctor')
192
+ })
193
+
175
194
  it('init refuses to downgrade too', () => {
176
195
  const path = join(dir, '.opencastle', 'manifest.json')
177
196
  const manifest = JSON.parse(readFileSync(path, 'utf8'))
@@ -258,6 +277,15 @@ describe.skipIf(!built)('a baseline package', () => {
258
277
  expect(report.contributes).toMatchObject({ skills: 1, instructions: 1 })
259
278
  })
260
279
 
280
+ it('warns when the baseline is over its own context budget before a repository adds anything', () => {
281
+ run(dir, ['baseline', 'init', 'base', '--name', '@acme/base'])
282
+ const config = join(dir, 'base', 'dev.opencastle', 'config.json')
283
+ writeFileSync(config, readFileSync(config, 'utf8').replace(/"contextBudget": \d+/, '"contextBudget": 100'))
284
+ const check = run(dir, ['baseline', 'check', 'base'])
285
+ expect(check.code).toBe(0)
286
+ expect(check.out).toMatch(/dev\.opencastle\/config\.json: policy\.contextBudget is 100 tokens, but a repository extending this baseline starts at ~\d+/)
287
+ })
288
+
261
289
  it('fails one whose layer sits outside the package, as every consumer would', () => {
262
290
  run(dir, ['baseline', 'init', 'base', '--name', '@acme/base'])
263
291
  const path = join(dir, 'base', 'package.json')
@@ -40,8 +40,15 @@ export interface TeamIssue {
40
40
 
41
41
  const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/
42
42
  export const ITEM_REF = new RegExp(`^(${CONTENT_KINDS.join('|')})/[A-Za-z0-9][A-Za-z0-9._-]*$`)
43
- /** What `exclude` may name: content, or an MCP server a layer below defines. */
44
- export const EXCLUDE_REF = new RegExp(`^(${[...CONTENT_KINDS, 'mcpServers'].join('|')})/[A-Za-z0-9][A-Za-z0-9._-]*$`)
43
+ /**
44
+ * What `exclude` may name: content, or an MCP server a layer below defines.
45
+ * Content takes `*` for any run of characters within a name — `skills/*` leaves
46
+ * out every skill from below, where a team that wanted only its own had to list
47
+ * each of them.
48
+ */
49
+ export const EXCLUDE_REF = new RegExp(
50
+ `^(?:(${CONTENT_KINDS.join('|')})/[A-Za-z0-9*][A-Za-z0-9._*-]*|mcpServers/[A-Za-z0-9][A-Za-z0-9._-]*)$`,
51
+ )
45
52
 
46
53
  const ItemRef = v.pipe(
47
54
  v.string(),
@@ -49,7 +56,7 @@ const ItemRef = v.pipe(
49
56
  )
50
57
  const ExcludeRef = v.pipe(
51
58
  v.string(),
52
- v.regex(EXCLUDE_REF, 'must name a kind and an item, e.g. "skills/seo-patterns" or "mcpServers/Slack"'),
59
+ v.regex(EXCLUDE_REF, 'must name a kind and an item, e.g. "skills/seo-patterns", "skills/*" or "mcpServers/Slack"'),
53
60
  )
54
61
 
55
62
  const McpServer = v.strictObject({
package/src/cli/update.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { isAbsolute, resolve, relative, join, dirname } from 'node:path'
2
2
  import { existsSync } from 'node:fs'
3
3
  import { readFile, mkdir, writeFile, unlink, copyFile, readdir, rm } from 'node:fs/promises'
4
- import { readManifest, writeManifest } from './manifest.js'
4
+ import { readManifest, writeManifest, manifestMeaning } from './manifest.js'
5
5
  import { multiselect, confirm, closePrompts, stdinIsExhausted, c } from './prompt.js'
6
6
  import { isLegacyStack, migrateStackConfig, IDE_LABELS } from './types.js'
7
7
  import { TECH_PLUGINS, TEAM_PLUGINS } from '../orchestrator/plugins/index.js'
@@ -11,8 +11,7 @@ import {
11
11
  updateSkillMatrixFile,
12
12
  resolveStack,
13
13
  getCustomizationsTransform,
14
- isEnvVarSatisfied,
15
- } from './stack-config.js'
14
+ isEnvVarSatisfied, isPreselected } from './stack-config.js'
16
15
  import { rebuildMcpConfig, getMcpConfigRelPath, retireLegacyMcpConfig, LEGACY_MCP_CONFIGS } from './mcp.js'
17
16
  import { updateGitignore, LOCAL_DIRS } from './gitignore.js'
18
17
  import { resolveManagedPaths, REQUIRED_CUSTOMIZATIONS } from './managed-paths.js'
@@ -51,19 +50,6 @@ function reportTeamIssues(resolved: ResolvedSources): void {
51
50
  console.error('')
52
51
  }
53
52
 
54
- /**
55
- * The manifest without the field that changes on every write.
56
- *
57
- * `updatedAt` changed on every sync, so two branches that both synced always
58
- * conflicted on the manifest — in the one file every command reads first,
59
- * where a conflict makes every command stop. Written only when something it
60
- * records has actually changed.
61
- */
62
- function manifestMeaning(m: Record<string, unknown>): string {
63
- const { updatedAt: _u, installedAt: _i, ...rest } = m
64
- return JSON.stringify(rest)
65
- }
66
-
67
53
  const UPDATE_HELP = `
68
54
  npx opencastle update [options]
69
55
 
@@ -262,6 +248,10 @@ export default async function update({
262
248
  // generated file by hand — and gating on version equality meant `sync --check`
263
249
  // could report drift while `sync` insisted everything was up to date. Compare
264
250
  // against a fresh compile instead; recompiling is idempotent and cheap.
251
+ // MCP entries only a person can fix. They do not make `sync` recompile, but
252
+ // saying everything matches over them, while `sync --check` fails on them,
253
+ // told the user the opposite of the check.
254
+ let forAPerson = 0
265
255
  const needsSync = await (async () => {
266
256
  if (manifest.version !== pkg.version || forceFlag || reconfigureFlag) return true
267
257
  // A generated config that will not parse is work outstanding, and the drift
@@ -307,6 +297,7 @@ export default async function update({
307
297
  try {
308
298
  const { buildCheckReport } = await import('./sync-check.js')
309
299
  const report = await buildCheckReport(pkgRoot, projectRoot)
300
+ forAPerson = report.drift.filter((d) => d.origin === 'mcp' && d.kind === 'unreducible').length
310
301
  // Not a broken MCP server only a person can fix: recompiling cannot clear
311
302
  // it, and doing so on every run rewrote the committed manifest for nothing.
312
303
  return report.drift.some((d) => !(d.origin === 'mcp' && d.kind === 'unreducible'))
@@ -343,6 +334,12 @@ export default async function update({
343
334
 
344
335
  if (!needsSync && !dryRun) {
345
336
  console.log(` ${c.green('✓')} Everything matches its sources (v${pkg.version}).`)
337
+ if (forAPerson > 0) {
338
+ console.log(
339
+ ` ${c.yellow('!')} ${forAPerson} MCP server entr${forAPerson === 1 ? 'y needs' : 'ies need'} fixing by hand, ` +
340
+ `which sync cannot do — ${c.cyan('npx opencastle doctor')} names ${forAPerson === 1 ? 'it' : 'them'}.`,
341
+ )
342
+ }
346
343
  // `--yes` means "do not ask me anything". This one slipped the guard, so a CI
347
344
  // runner holding stdin open would block here on an up-to-date project, and
348
345
  // `add`, which routes through sync, asked twice for one instruction.
@@ -391,7 +388,7 @@ export default async function update({
391
388
  value: p.id,
392
389
  selected: oldStack
393
390
  ? currentTech.has(p.id as TechTool)
394
- : p.preselected || detectedTools.has(p.id),
391
+ : isPreselected(p, repoInfo) || detectedTools.has(p.id),
395
392
  }))
396
393
  )
397
394
 
@@ -404,7 +401,7 @@ export default async function update({
404
401
  value: p.id,
405
402
  selected: oldStack
406
403
  ? currentTeam.has(p.id as TeamTool)
407
- : !!p.preselected,
404
+ : isPreselected(p, repoInfo),
408
405
  }))
409
406
  )
410
407