opencastle 1.4.3 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/dist/cli/adapters/claude-code.d.ts.map +1 -1
  2. package/dist/cli/adapters/claude-code.js +1 -0
  3. package/dist/cli/adapters/claude-code.js.map +1 -1
  4. package/dist/cli/adapters/single-file-base.d.ts +8 -0
  5. package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
  6. package/dist/cli/adapters/single-file-base.js +48 -22
  7. package/dist/cli/adapters/single-file-base.js.map +1 -1
  8. package/dist/cli/bootstrap-on-init.test.js +16 -5
  9. package/dist/cli/bootstrap-on-init.test.js.map +1 -1
  10. package/dist/cli/bootstrap.d.ts +17 -0
  11. package/dist/cli/bootstrap.d.ts.map +1 -1
  12. package/dist/cli/bootstrap.js +284 -312
  13. package/dist/cli/bootstrap.js.map +1 -1
  14. package/dist/cli/bootstrap.test.js +22 -16
  15. package/dist/cli/bootstrap.test.js.map +1 -1
  16. package/dist/cli/command-namespace.test.js +17 -0
  17. package/dist/cli/command-namespace.test.js.map +1 -1
  18. package/dist/cli/convoy/engine.d.ts +12 -0
  19. package/dist/cli/convoy/engine.d.ts.map +1 -1
  20. package/dist/cli/convoy/engine.git.test.js +55 -0
  21. package/dist/cli/convoy/engine.git.test.js.map +1 -1
  22. package/dist/cli/convoy/engine.js +47 -3
  23. package/dist/cli/convoy/engine.js.map +1 -1
  24. package/dist/cli/convoy/findings.d.ts +35 -0
  25. package/dist/cli/convoy/findings.d.ts.map +1 -0
  26. package/dist/cli/convoy/findings.js +100 -0
  27. package/dist/cli/convoy/findings.js.map +1 -0
  28. package/dist/cli/convoy/findings.test.d.ts +2 -0
  29. package/dist/cli/convoy/findings.test.d.ts.map +1 -0
  30. package/dist/cli/convoy/findings.test.js +75 -0
  31. package/dist/cli/convoy/findings.test.js.map +1 -0
  32. package/dist/cli/convoy/isolation.d.ts.map +1 -1
  33. package/dist/cli/convoy/isolation.js +2 -1
  34. package/dist/cli/convoy/isolation.js.map +1 -1
  35. package/dist/cli/convoy/worktree.d.ts +5 -0
  36. package/dist/cli/convoy/worktree.d.ts.map +1 -1
  37. package/dist/cli/convoy/worktree.js +12 -0
  38. package/dist/cli/convoy/worktree.js.map +1 -1
  39. package/dist/cli/detect.d.ts +4 -0
  40. package/dist/cli/detect.d.ts.map +1 -1
  41. package/dist/cli/detect.js +1 -1
  42. package/dist/cli/detect.js.map +1 -1
  43. package/dist/cli/docs-accuracy.test.js +34 -0
  44. package/dist/cli/docs-accuracy.test.js.map +1 -1
  45. package/dist/cli/doctor.d.ts +11 -0
  46. package/dist/cli/doctor.d.ts.map +1 -1
  47. package/dist/cli/doctor.js +74 -10
  48. package/dist/cli/doctor.js.map +1 -1
  49. package/dist/cli/doctor.test.js +82 -1
  50. package/dist/cli/doctor.test.js.map +1 -1
  51. package/dist/cli/init.d.ts.map +1 -1
  52. package/dist/cli/init.js +58 -53
  53. package/dist/cli/init.js.map +1 -1
  54. package/dist/cli/init.test.js +32 -28
  55. package/dist/cli/init.test.js.map +1 -1
  56. package/dist/cli/layers.d.ts +20 -0
  57. package/dist/cli/layers.d.ts.map +1 -1
  58. package/dist/cli/layers.js +53 -1
  59. package/dist/cli/layers.js.map +1 -1
  60. package/dist/cli/layers.test.js +67 -1
  61. package/dist/cli/layers.test.js.map +1 -1
  62. package/dist/cli/lessons.d.ts +10 -0
  63. package/dist/cli/lessons.d.ts.map +1 -1
  64. package/dist/cli/lessons.js +26 -1
  65. package/dist/cli/lessons.js.map +1 -1
  66. package/dist/cli/lessons.test.js +38 -1
  67. package/dist/cli/lessons.test.js.map +1 -1
  68. package/dist/cli/log.d.ts +2 -2
  69. package/dist/cli/log.d.ts.map +1 -1
  70. package/dist/cli/log.js +1 -1
  71. package/dist/cli/log.js.map +1 -1
  72. package/dist/cli/log.test.js +1 -1
  73. package/dist/cli/log.test.js.map +1 -1
  74. package/dist/cli/managed-paths.d.ts +1 -1
  75. package/dist/cli/managed-paths.d.ts.map +1 -1
  76. package/dist/cli/managed-paths.js +0 -1
  77. package/dist/cli/managed-paths.js.map +1 -1
  78. package/dist/cli/plan.test.js +10 -8
  79. package/dist/cli/plan.test.js.map +1 -1
  80. package/dist/cli/project-facts.d.ts +103 -0
  81. package/dist/cli/project-facts.d.ts.map +1 -0
  82. package/dist/cli/project-facts.js +577 -0
  83. package/dist/cli/project-facts.js.map +1 -0
  84. package/dist/cli/project-facts.test.d.ts +2 -0
  85. package/dist/cli/project-facts.test.d.ts.map +1 -0
  86. package/dist/cli/project-facts.test.js +209 -0
  87. package/dist/cli/project-facts.test.js.map +1 -0
  88. package/dist/cli/stack-config.js +1 -1
  89. package/dist/cli/stack-config.js.map +1 -1
  90. package/dist/cli/sync-check.test.js +14 -2
  91. package/dist/cli/sync-check.test.js.map +1 -1
  92. package/dist/orchestrator/plugins/notion/config.d.ts.map +1 -1
  93. package/dist/orchestrator/plugins/notion/config.js +21 -17
  94. package/dist/orchestrator/plugins/notion/config.js.map +1 -1
  95. package/package.json +1 -1
  96. package/src/cli/adapters/claude-code.ts +1 -0
  97. package/src/cli/adapters/single-file-base.ts +63 -31
  98. package/src/cli/bootstrap-on-init.test.ts +17 -5
  99. package/src/cli/bootstrap.test.ts +22 -16
  100. package/src/cli/bootstrap.ts +361 -373
  101. package/src/cli/command-namespace.test.ts +17 -0
  102. package/src/cli/convoy/engine.git.test.ts +59 -0
  103. package/src/cli/convoy/engine.ts +53 -2
  104. package/src/cli/convoy/findings.test.ts +86 -0
  105. package/src/cli/convoy/findings.ts +129 -0
  106. package/src/cli/convoy/isolation.ts +2 -1
  107. package/src/cli/convoy/worktree.ts +12 -0
  108. package/src/cli/detect.ts +1 -1
  109. package/src/cli/docs-accuracy.test.ts +42 -0
  110. package/src/cli/doctor.test.ts +101 -1
  111. package/src/cli/doctor.ts +77 -11
  112. package/src/cli/init.test.ts +31 -27
  113. package/src/cli/init.ts +62 -57
  114. package/src/cli/layers.test.ts +72 -1
  115. package/src/cli/layers.ts +52 -1
  116. package/src/cli/lessons.test.ts +48 -0
  117. package/src/cli/lessons.ts +27 -1
  118. package/src/cli/log.test.ts +1 -1
  119. package/src/cli/log.ts +2 -2
  120. package/src/cli/managed-paths.ts +0 -1
  121. package/src/cli/plan.test.ts +10 -8
  122. package/src/cli/project-facts.test.ts +228 -0
  123. package/src/cli/project-facts.ts +647 -0
  124. package/src/cli/stack-config.ts +1 -1
  125. package/src/cli/sync-check.test.ts +16 -2
  126. package/src/orchestrator/agent-workflows/data-pipeline.md +2 -2
  127. package/src/orchestrator/agent-workflows/feature-implementation.md +2 -2
  128. package/src/orchestrator/agent-workflows/schema-changes.md +1 -1
  129. package/src/orchestrator/agents/team-lead.agent.md +6 -6
  130. package/src/orchestrator/agents/testing-expert.agent.md +2 -2
  131. package/src/orchestrator/customizations/LESSONS-LEARNED.md +1 -1
  132. package/src/orchestrator/customizations/README.md +27 -84
  133. package/src/orchestrator/instructions/ai-optimization.instructions.md +6 -23
  134. package/src/orchestrator/instructions/general.instructions.md +22 -95
  135. package/src/orchestrator/plugins/astro/skills/astro-framework/SKILL.md +1 -3
  136. package/src/orchestrator/plugins/chrome-devtools/skills/browser-testing/SKILL.md +3 -5
  137. package/src/orchestrator/plugins/cloudflare/skills/cloudflare-platform/SKILL.md +2 -2
  138. package/src/orchestrator/plugins/contentful/skills/contentful-cms/SKILL.md +1 -1
  139. package/src/orchestrator/plugins/convex/skills/convex-database/SKILL.md +1 -3
  140. package/src/orchestrator/plugins/coolify/skills/coolify-deployment/SKILL.md +1 -1
  141. package/src/orchestrator/plugins/cypress/skills/cypress-testing/SKILL.md +1 -1
  142. package/src/orchestrator/plugins/drizzle/skills/drizzle-orm/SKILL.md +1 -1
  143. package/src/orchestrator/plugins/expo/skills/expo-development/SKILL.md +2 -2
  144. package/src/orchestrator/plugins/figma/skills/figma-design/SKILL.md +1 -3
  145. package/src/orchestrator/plugins/hetzner/skills/hetzner-cloud/SKILL.md +1 -1
  146. package/src/orchestrator/plugins/jira/skills/jira-management/SKILL.md +1 -3
  147. package/src/orchestrator/plugins/linear/skills/linear-task-management/SKILL.md +1 -3
  148. package/src/orchestrator/plugins/netlify/skills/netlify-deployment/SKILL.md +2 -2
  149. package/src/orchestrator/plugins/nextjs/skills/nextjs-framework/SKILL.md +13 -6
  150. package/src/orchestrator/plugins/notion/config.ts +21 -17
  151. package/src/orchestrator/plugins/notion/skills/notion-knowledge-management/SKILL.md +8 -16
  152. package/src/orchestrator/plugins/nx/skills/nx-workspace/SKILL.md +2 -4
  153. package/src/orchestrator/plugins/playwright/skills/playwright-testing/SKILL.md +1 -3
  154. package/src/orchestrator/plugins/prisma/skills/prisma-database/SKILL.md +1 -3
  155. package/src/orchestrator/plugins/resend/skills/resend-email/SKILL.md +2 -2
  156. package/src/orchestrator/plugins/sanity/skills/sanity-cms/SKILL.md +1 -3
  157. package/src/orchestrator/plugins/sentry/skills/sentry-monitoring/SKILL.md +1 -1
  158. package/src/orchestrator/plugins/slack/skills/slack-notifications/SKILL.md +1 -3
  159. package/src/orchestrator/plugins/strapi/skills/strapi-cms/SKILL.md +1 -3
  160. package/src/orchestrator/plugins/stripe/skills/stripe-payments/SKILL.md +4 -4
  161. package/src/orchestrator/plugins/supabase/skills/supabase-database/SKILL.md +3 -5
  162. package/src/orchestrator/plugins/teams/skills/teams-notifications/SKILL.md +1 -3
  163. package/src/orchestrator/plugins/trello/skills/trello-task-management/SKILL.md +1 -1
  164. package/src/orchestrator/plugins/turborepo/skills/turborepo-monorepo/SKILL.md +15 -88
  165. package/src/orchestrator/plugins/vercel/skills/vercel-deployment/SKILL.md +2 -2
  166. package/src/orchestrator/plugins/vitest/skills/vitest-testing/SKILL.md +17 -150
  167. package/src/orchestrator/prompts/assess-complexity.prompt.md +1 -0
  168. package/src/orchestrator/prompts/bootstrap-customizations.prompt.md +38 -238
  169. package/src/orchestrator/prompts/brainstorm.prompt.md +1 -1
  170. package/src/orchestrator/prompts/create-skill.prompt.md +13 -67
  171. package/src/orchestrator/prompts/fix-convoy.prompt.md +1 -0
  172. package/src/orchestrator/prompts/fix-prd.prompt.md +1 -0
  173. package/src/orchestrator/prompts/generate-prd.prompt.md +1 -0
  174. package/src/orchestrator/prompts/implement-feature.prompt.md +6 -6
  175. package/src/orchestrator/prompts/resolve-pr-comments.prompt.md +2 -2
  176. package/src/orchestrator/prompts/validate-convoy.prompt.md +1 -0
  177. package/src/orchestrator/prompts/validate-prd.prompt.md +1 -0
  178. package/src/orchestrator/skills/accessibility-standards/REFERENCE.md +17 -12
  179. package/src/orchestrator/skills/accessibility-standards/SKILL.md +1 -1
  180. package/src/orchestrator/skills/agent-hooks/HOOKS-REFERENCE.md +3 -5
  181. package/src/orchestrator/skills/agent-hooks/SKILL.md +8 -6
  182. package/src/orchestrator/skills/agent-memory/KNOWLEDGE-GRAPH.md +1 -1
  183. package/src/orchestrator/skills/agent-memory/SKILL.md +7 -16
  184. package/src/orchestrator/skills/api-patterns/SKILL.md +1 -1
  185. package/src/orchestrator/skills/code-commenting/SKILL.md +1 -1
  186. package/src/orchestrator/skills/context-map/REFERENCE.md +0 -2
  187. package/src/orchestrator/skills/context-map/SKILL.md +2 -2
  188. package/src/orchestrator/skills/data-engineering/REFERENCE.md +3 -9
  189. package/src/orchestrator/skills/data-engineering/SKILL.md +9 -16
  190. package/src/orchestrator/skills/decomposition/SKILL.md +1 -1
  191. package/src/orchestrator/skills/deployment-infrastructure/SKILL.md +4 -4
  192. package/src/orchestrator/skills/documentation-standards/SKILL.md +5 -3
  193. package/src/orchestrator/skills/fast-review/REFERENCE.md +0 -2
  194. package/src/orchestrator/skills/fast-review/SKILL.md +5 -5
  195. package/src/orchestrator/skills/frontend-design/REFERENCE.md +6 -28
  196. package/src/orchestrator/skills/frontend-design/SKILL.md +19 -9
  197. package/src/orchestrator/skills/git-workflow/SKILL.md +1 -1
  198. package/src/orchestrator/skills/memory-merger/SKILL.md +13 -15
  199. package/src/orchestrator/skills/observability-logging/SKILL.md +2 -2
  200. package/src/orchestrator/skills/orchestration-protocols/REFERENCE.md +5 -9
  201. package/src/orchestrator/skills/orchestration-protocols/SKILL.md +6 -6
  202. package/src/orchestrator/skills/panel-majority-vote/REFERENCE.md +1 -5
  203. package/src/orchestrator/skills/panel-majority-vote/SKILL.md +1 -1
  204. package/src/orchestrator/skills/panel-majority-vote/panel-report.template.md +0 -2
  205. package/src/orchestrator/skills/performance-optimization/SKILL.md +2 -2
  206. package/src/orchestrator/skills/project-consistency/SKILL.md +2 -2
  207. package/src/orchestrator/skills/project-consistency/TEMPLATES.md +0 -4
  208. package/src/orchestrator/skills/react-development/SKILL.md +3 -3
  209. package/src/orchestrator/skills/security-hardening/SKILL.md +5 -5
  210. package/src/orchestrator/skills/self-improvement/LESSON-CATEGORIES.md +0 -2
  211. package/src/orchestrator/skills/self-improvement/SKILL.md +1 -1
  212. package/src/orchestrator/skills/seo-patterns/SKILL.md +1 -1
  213. package/src/orchestrator/skills/session-checkpoints/CHECKPOINT-TEMPLATE.md +0 -2
  214. package/src/orchestrator/skills/session-checkpoints/SKILL.md +1 -1
  215. package/src/orchestrator/skills/team-lead-reference/SKILL.md +3 -3
  216. package/src/orchestrator/skills/technical-writing/SKILL.md +8 -13
  217. package/src/orchestrator/skills/testing-workflow/SKILL.md +6 -6
  218. package/src/orchestrator/skills/typescript-best-practices/SKILL.md +1 -1
  219. package/src/orchestrator/skills/unslop/SKILL.md +1 -1
  220. package/src/orchestrator/skills/validation-gates/REFERENCE.md +6 -31
  221. package/src/orchestrator/skills/validation-gates/SKILL.md +12 -26
  222. package/src/orchestrator/skills/writing-for-agents/SKILL.md +2 -2
  223. package/src/orchestrator/customizations/AGENT-EXPERTISE.md +0 -325
  224. package/src/orchestrator/customizations/AGENT-FAILURES.md +0 -69
  225. package/src/orchestrator/customizations/AGENT-PERFORMANCE.md +0 -55
  226. package/src/orchestrator/customizations/DISPUTES.md +0 -162
  227. package/src/orchestrator/customizations/KNOWLEDGE-GRAPH.md +0 -10
  228. package/src/orchestrator/customizations/agents/skill-matrix.md +0 -111
  229. package/src/orchestrator/customizations/logs/events.ndjson +0 -0
  230. package/src/orchestrator/customizations/project/decisions.md +0 -31
  231. package/src/orchestrator/customizations/project/docs-structure.md +0 -34
  232. package/src/orchestrator/customizations/project/roadmap.md +0 -24
  233. package/src/orchestrator/skills/documentation-standards/WRITING-GUIDE.md +0 -39
  234. package/src/orchestrator/skills/frontend-design/COMPONENTS.md +0 -113
  235. /package/src/orchestrator/{customizations/logs/README.md → skills/observability-logging/LOG-SCHEMA.md} +0 -0
package/src/cli/log.ts CHANGED
@@ -13,7 +13,7 @@ import type { CliContext } from './types.js'
13
13
  * `--type session` with no fields, `--outcome banana`, a value-less `--model`
14
14
  * stored as `true`, `--task 007` stored as the number 7, `--agnet`, and a
15
15
  * caller-supplied `--timestamp yesterday`. Each record type is now checked
16
- * against the schema in `customizations/logs/README.md`, field by field, and a
16
+ * against the schema in `skills/observability-logging/LOG-SCHEMA.md`, field by field, and a
17
17
  * record that does not match is refused with every reason at once.
18
18
  */
19
19
 
@@ -34,7 +34,7 @@ const attempt: Field = { kind: 'count', required: true, min: 1 }
34
34
 
35
35
  const OUTCOMES = ['success', 'partial', 'failed'] as const
36
36
 
37
- /** The record schemas, as `customizations/logs/README.md` documents them. `log.test.ts` holds the two together. */
37
+ /** The record schemas, as `skills/observability-logging/LOG-SCHEMA.md` documents them. `log.test.ts` holds the two together. */
38
38
  export const LOG_RECORDS: Record<string, Record<string, Field>> = {
39
39
  session: {
40
40
  agent: req('text'),
@@ -179,7 +179,6 @@ export function removeOwnedFiles(projectRoot: string, dir: string, owns: (_rel:
179
179
  */
180
180
  export const REQUIRED_CUSTOMIZATIONS = [
181
181
  'agents/skill-matrix.json',
182
- 'agents/skill-matrix.md',
183
182
  'agents/agent-registry.md',
184
183
  ] as const
185
184
 
@@ -30,21 +30,23 @@ describe('fillTemplate', () => {
30
30
  })
31
31
  })
32
32
 
33
+ // `pipeline`: only the CLI runs it. generate-convoy is the exception, as the
34
+ // Team Lead also plans in the editor by its rules.
33
35
  const PLANNER = {
34
- 'generate-prd': { output: 'prd', context: false },
35
- 'validate-prd': { output: 'validation', context: false },
36
- 'fix-prd': { output: 'prd', context: true },
37
- 'assess-complexity': { output: 'json', context: true },
38
- 'generate-convoy': { output: 'json', context: true },
39
- 'validate-convoy': { output: 'validation', context: false },
40
- 'fix-convoy': { output: 'json', context: true },
36
+ 'generate-prd': { output: 'prd', context: false, pipeline: true },
37
+ 'validate-prd': { output: 'validation', context: false, pipeline: true },
38
+ 'fix-prd': { output: 'prd', context: true, pipeline: true },
39
+ 'assess-complexity': { output: 'json', context: true, pipeline: true },
40
+ 'generate-convoy': { output: 'json', context: true, pipeline: false },
41
+ 'validate-convoy': { output: 'validation', context: false, pipeline: true },
42
+ 'fix-convoy': { output: 'json', context: true, pipeline: true },
41
43
  } as const
42
44
 
43
45
  describe('the planner templates', () => {
44
46
  it.each(Object.entries(PLANNER))('%s keeps its frontmatter and fills each input once', (name, expected) => {
45
47
  const text = readFileSync(templatePath(pkgRoot, name), 'utf8')
46
48
  const fm = parseFrontmatter(text)
47
- expect(Object.keys(fm).sort()).toEqual(['agent', 'description', 'output'])
49
+ expect(Object.keys(fm).sort()).toEqual(['agent', 'description', 'output', ...(expected.pipeline ? ['pipeline'] : [])])
48
50
  expect(fm.output).toBe(expected.output)
49
51
 
50
52
  // Exactly one slot per input, and no other mention that a fill could reach.
@@ -0,0 +1,228 @@
1
+ import { describe, it, expect, afterEach } from 'vitest'
2
+ import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'node:fs'
3
+ import { tmpdir } from 'node:os'
4
+ import { dirname, join } from 'node:path'
5
+ import { readProjectFacts } from './project-facts.js'
6
+
7
+ /**
8
+ * The facts `init` writes into `.opencastle/`, read from small project trees
9
+ * shaped like the real ones they stand for.
10
+ */
11
+
12
+ let root = ''
13
+
14
+ function project(files: Record<string, string>): string {
15
+ root = mkdtempSync(join(tmpdir(), 'oc-facts-'))
16
+ for (const [path, text] of Object.entries(files)) {
17
+ mkdirSync(dirname(join(root, path)), { recursive: true })
18
+ writeFileSync(join(root, path), text)
19
+ }
20
+ return root
21
+ }
22
+
23
+ afterEach(() => {
24
+ if (root) rmSync(root, { recursive: true, force: true })
25
+ root = ''
26
+ })
27
+
28
+ const pkg = (body: object): string => JSON.stringify(body)
29
+
30
+ describe('routes', () => {
31
+ it('reads Next.js App Router pages and route handlers, without groups, slots or private folders', async () => {
32
+ const r = project({
33
+ 'package.json': pkg({ dependencies: { next: '^15.1.0' } }),
34
+ 'app/page.tsx': '',
35
+ 'app/(marketing)/pricing/page.tsx': '',
36
+ 'app/blog/[slug]/page.mdx': '',
37
+ 'app/@modal/login/page.tsx': '',
38
+ 'app/_components/card/page.tsx': '',
39
+ 'app/api/posts/route.ts': 'export async function GET() {}\nexport const POST = handler',
40
+ 'pages/api/legacy.ts': 'export default function handler() {}',
41
+ })
42
+ const facts = await readProjectFacts(r, { frameworks: ['next'] })
43
+ expect(facts.pages).toEqual([{ root: 'app/', routes: ['/', '/blog/[slug]', '/login', '/pricing'] }])
44
+ expect(facts.api).toEqual([
45
+ { route: '/api/legacy', methods: [], file: 'pages/api/legacy.ts' },
46
+ { route: '/api/posts', methods: ['GET', 'POST'], file: 'app/api/posts/route.ts' },
47
+ ])
48
+ expect(facts.stack).toEqual([{ layer: 'Framework', name: 'Next.js', version: '15.1.0' }])
49
+ expect(facts.devPort).toBe(3000)
50
+ })
51
+
52
+ it('leaves out Astro files whose path has a part starting with an underscore', async () => {
53
+ const r = project({
54
+ 'package.json': pkg({ dependencies: { astro: '5.0.0' } }),
55
+ 'src/pages/index.astro': '',
56
+ 'src/pages/posts/[slug].astro': '',
57
+ 'src/pages/posts/_components/Card.astro': '',
58
+ 'src/pages/_utils/group.ts': 'export function group() {}',
59
+ 'src/pages/rss.xml.ts': 'export const GET = () => new Response()',
60
+ })
61
+ const facts = await readProjectFacts(r, { frameworks: ['astro'] })
62
+ expect(facts.pages[0].routes).toEqual(['/', '/posts/[slug]'])
63
+ expect(facts.api.map((a) => [a.route, a.methods])).toEqual([['/rss.xml', ['GET']]])
64
+ })
65
+
66
+ it('reads SvelteKit pages and server routes', async () => {
67
+ const r = project({
68
+ 'package.json': pkg({}),
69
+ 'src/routes/+page.svelte': '',
70
+ 'src/routes/about/+page.svelte': '',
71
+ 'src/routes/api/items/+server.ts': 'export async function GET() {}\nexport async function DELETE() {}',
72
+ })
73
+ const facts = await readProjectFacts(r, { frameworks: ['sveltekit'] })
74
+ expect(facts.pages[0]).toEqual({ root: 'src/routes/', routes: ['/', '/about'] })
75
+ expect(facts.api).toEqual([{ route: '/api/items', methods: ['GET', 'DELETE'], file: 'src/routes/api/items/+server.ts' }])
76
+ })
77
+
78
+ it('finds routes in each app of a monorepo', async () => {
79
+ const r = project({
80
+ 'package.json': pkg({ name: 'mono' }),
81
+ 'apps/web/package.json': pkg({ name: '@x/web', dependencies: { next: '15.0.0' } }),
82
+ 'apps/web/src/app/page.tsx': '',
83
+ 'apps/web/src/app/settings/page.tsx': '',
84
+ })
85
+ const facts = await readProjectFacts(r, { frameworks: ['next'] })
86
+ expect(facts.pages).toEqual([{ root: 'apps/web/src/app/', routes: ['/', '/settings'] }])
87
+ expect(facts.workspaces).toEqual([{ path: 'apps/web/', name: '@x/web', purpose: 'Next.js app' }])
88
+ })
89
+
90
+ it('reads Express-style routes when there are no route files', async () => {
91
+ const r = project({
92
+ 'package.json': pkg({ dependencies: { express: '4.19.0' } }),
93
+ 'src/server.js': "app.get('/health', h)\napp.post('/notes', h)\nrouter.delete('/notes/:id', h)",
94
+ })
95
+ const facts = await readProjectFacts(r, { frameworks: ['express'] })
96
+ expect(facts.api.map((a) => `${a.methods.join(',')} ${a.route}`)).toEqual(['GET /health', 'POST /notes', 'DELETE /notes/:id'])
97
+ })
98
+ })
99
+
100
+ describe('data', () => {
101
+ it('lists Prisma models and its migrations', async () => {
102
+ const r = project({
103
+ 'package.json': pkg({ dependencies: { '@prisma/client': '^5.2.0' } }),
104
+ 'prisma/schema.prisma': 'model User {\n id Int @id\n}\n\nmodel Post {\n id Int @id\n}\nenum Role { A }\n',
105
+ 'prisma/migrations/20240101_init/migration.sql': '',
106
+ 'prisma/migrations/20240202_posts/migration.sql': '',
107
+ 'lib/db.ts': "import { PrismaClient } from '@prisma/client'",
108
+ 'app/page.tsx': "import type { User } from '@prisma/client'",
109
+ })
110
+ const facts = await readProjectFacts(r, { databases: ['prisma'] })
111
+ expect(facts.models).toEqual({ source: 'prisma/schema.prisma', names: ['User', 'Post'] })
112
+ expect(facts.migrations).toEqual({ dir: 'prisma/migrations/', count: 2, latest: ['20240101_init', '20240202_posts'] })
113
+ // The file that sets the client up comes before the pages that use it.
114
+ expect(facts.importers.prisma[0]).toBe('lib/db.ts')
115
+ })
116
+
117
+ it('lists Drizzle tables from every schema file', async () => {
118
+ const r = project({
119
+ 'package.json': pkg({}),
120
+ 'packages/db/src/schema.ts': 'export const Post = pgTable("post", {})',
121
+ 'packages/db/src/auth-schema.ts': 'export const user = pgTable("user", {})\nexport const session = pgTable("session", {})',
122
+ })
123
+ const facts = await readProjectFacts(r, { databases: ['drizzle'] })
124
+ expect(facts.models?.names.sort()).toEqual(['post', 'session', 'user'])
125
+ })
126
+
127
+ it('lists Supabase tables from its migrations', async () => {
128
+ const r = project({
129
+ 'package.json': pkg({}),
130
+ 'supabase/migrations/20240101000000_init.sql': 'create table public.profiles (id uuid);\nCREATE TABLE IF NOT EXISTS "orders" ();',
131
+ })
132
+ const facts = await readProjectFacts(r, { databases: ['supabase'] })
133
+ expect(facts.models).toEqual({ source: 'supabase/migrations/', names: ['profiles', 'orders'] })
134
+ })
135
+ })
136
+
137
+ describe('everything else', () => {
138
+ it('takes variable names from the example file and never reads .env', async () => {
139
+ const r = project({
140
+ 'package.json': pkg({}),
141
+ '.env': 'SECRET_ONLY_IN_ENV=hunter2\n',
142
+ '.env.example': 'DATABASE_URL=\nexport STRIPE_KEY=sk_test\n# COMMENTED=1\n',
143
+ })
144
+ const facts = await readProjectFacts(r, {})
145
+ expect(facts.envVars).toEqual({ source: '.env.example', names: ['DATABASE_URL', 'STRIPE_KEY'] })
146
+ expect(JSON.stringify(facts)).not.toContain('SECRET_ONLY_IN_ENV')
147
+ expect(JSON.stringify(facts)).not.toContain('hunter2')
148
+ })
149
+
150
+ it('reads Tailwind breakpoints, but not the container sizes', async () => {
151
+ const r = project({
152
+ 'package.json': pkg({}),
153
+ 'tailwind.config.js': 'module.exports = { theme: { container: { screens: { "2xl": "1400px" } }, extend: { screens: { "3xl": "1920px" } } } }',
154
+ })
155
+ const facts = await readProjectFacts(r, { styling: ['tailwind'] })
156
+ const values = Object.fromEntries(facts.breakpoints!.values)
157
+ expect(values['2xl']).toBe('1536px')
158
+ expect(values['3xl']).toBe('1920px')
159
+ })
160
+
161
+ it('resolves pnpm catalog versions from a workspace package', async () => {
162
+ const r = project({
163
+ 'package.json': pkg({ name: 'mono' }),
164
+ 'pnpm-workspace.yaml': 'packages:\n - apps/*\ncatalog:\n next: ^16.0.1\n "@prisma/client": 6.1.0\n',
165
+ 'apps/web/package.json': pkg({ dependencies: { next: 'catalog:', '@prisma/client': 'catalog:' } }),
166
+ })
167
+ const facts = await readProjectFacts(r, { frameworks: ['next'], databases: ['prisma'] })
168
+ expect(facts.stack).toEqual([
169
+ { layer: 'Framework', name: 'Next.js', version: '16.0.1' },
170
+ { layer: 'Database', name: 'Prisma', version: '6.1.0' },
171
+ ])
172
+ })
173
+
174
+ it('describes the project from the README introduction only', async () => {
175
+ const intro = project({
176
+ 'package.json': pkg({ name: 'x' }),
177
+ 'README.md': '# X\n\n[![ci](https://x/badge.svg)](https://x)\n\nX turns [notes](https://n) into tasks.\n\n## Install\n\nRun this:\n',
178
+ })
179
+ expect((await readProjectFacts(intro, {})).description).toBe('X turns notes into tasks.')
180
+ rmSync(intro, { recursive: true, force: true })
181
+
182
+ const howTo = project({
183
+ 'package.json': pkg({ name: 'y' }),
184
+ 'README.md': '# Y\n\nThere are two ways to start:\n\n## Setup\n\nY is great.\n',
185
+ })
186
+ expect((await readProjectFacts(howTo, {})).description).toBeUndefined()
187
+ })
188
+
189
+ it('takes a port from the dev script before the framework default', async () => {
190
+ const r = project({ 'package.json': pkg({ scripts: { dev: 'next dev -p 4000' } }) })
191
+ expect((await readProjectFacts(r, { frameworks: ['next'] })).devPort).toBe(4000)
192
+ })
193
+
194
+ it('reads what CI runs, the Node version and the coverage the tests require', async () => {
195
+ const r = project({
196
+ 'package.json': pkg({ engines: { node: '>=20' }, devDependencies: { vitest: '2.0.0' } }),
197
+ '.github/workflows/ci.yml': [
198
+ 'jobs:',
199
+ ' test:',
200
+ ' steps:',
201
+ ' - run: pnpm install --frozen-lockfile',
202
+ ' - run: pnpm lint',
203
+ ' - name: Test',
204
+ ' run: |',
205
+ ' pnpm test --coverage',
206
+ ' echo done',
207
+ ].join('\n'),
208
+ 'vitest.config.ts': 'export default { test: { coverage: { thresholds: { lines: 80, branches: 70 } } } }',
209
+ })
210
+ const facts = await readProjectFacts(r, { packageManager: 'pnpm' })
211
+ expect(facts.ciCommands).toEqual(['pnpm lint', 'pnpm test --coverage'])
212
+ expect(facts.nodeVersion).toBe('>=20')
213
+ expect(facts.coverage).toEqual(['lines 80', 'branches 70'])
214
+ })
215
+
216
+ it('names test frameworks from package.json only, and finds the test files', async () => {
217
+ const r = project({
218
+ 'package.json': pkg({ devDependencies: { vitest: '^2.0.0' } }),
219
+ 'vitest.config.ts': '',
220
+ 'src/a.test.ts': '',
221
+ 'e2e/login.spec.ts': '',
222
+ })
223
+ const facts = await readProjectFacts(r, { testing: ['vitest', 'chrome-devtools'] })
224
+ expect(facts.testFrameworks).toEqual(['Vitest'])
225
+ expect(facts.testConfigs).toEqual(['vitest.config.ts'])
226
+ expect(facts.testFiles.sort()).toEqual(['e2e/login.spec.ts', 'src/a.test.ts'])
227
+ })
228
+ })