@raybase/create 0.0.1 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/THIRD_PARTY_NOTICES.md +38 -0
- package/assets/apple-touch-icons/0.png +0 -0
- package/assets/apple-touch-icons/1.png +0 -0
- package/assets/apple-touch-icons/2.png +0 -0
- package/assets/apple-touch-icons/3.png +0 -0
- package/assets/apple-touch-icons/4.png +0 -0
- package/assets/apple-touch-icons/5.png +0 -0
- package/assets/apple-touch-icons/6.png +0 -0
- package/assets/apple-touch-icons/7.png +0 -0
- package/assets/apple-touch-icons/8.png +0 -0
- package/assets/apple-touch-icons/9.png +0 -0
- package/assets/apple-touch-icons/A.png +0 -0
- package/assets/apple-touch-icons/B.png +0 -0
- package/assets/apple-touch-icons/C.png +0 -0
- package/assets/apple-touch-icons/D.png +0 -0
- package/assets/apple-touch-icons/E.png +0 -0
- package/assets/apple-touch-icons/F.png +0 -0
- package/assets/apple-touch-icons/G.png +0 -0
- package/assets/apple-touch-icons/H.png +0 -0
- package/assets/apple-touch-icons/I.png +0 -0
- package/assets/apple-touch-icons/J.png +0 -0
- package/assets/apple-touch-icons/K.png +0 -0
- package/assets/apple-touch-icons/L.png +0 -0
- package/assets/apple-touch-icons/M.png +0 -0
- package/assets/apple-touch-icons/N.png +0 -0
- package/assets/apple-touch-icons/O.png +0 -0
- package/assets/apple-touch-icons/P.png +0 -0
- package/assets/apple-touch-icons/Q.png +0 -0
- package/assets/apple-touch-icons/R.png +0 -0
- package/assets/apple-touch-icons/S.png +0 -0
- package/assets/apple-touch-icons/T.png +0 -0
- package/assets/apple-touch-icons/U.png +0 -0
- package/assets/apple-touch-icons/V.png +0 -0
- package/assets/apple-touch-icons/W.png +0 -0
- package/assets/apple-touch-icons/X.png +0 -0
- package/assets/apple-touch-icons/Y.png +0 -0
- package/assets/apple-touch-icons/Z.png +0 -0
- package/assets/apple-touch-icons/default.png +0 -0
- package/dist/.source-hash +1 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2351 -0
- package/dist/index.js.map +1 -0
- package/dist/raybase-package-ranges.d.ts +11 -0
- package/dist/raybase-package-ranges.d.ts.map +1 -0
- package/dist/raybase-package-ranges.js +11 -0
- package/dist/raybase-package-ranges.js.map +1 -0
- package/dist/source-fetch.d.ts +91 -0
- package/dist/source-fetch.d.ts.map +1 -0
- package/dist/source-fetch.js +325 -0
- package/dist/source-fetch.js.map +1 -0
- package/dist/source-hash.d.ts +2 -0
- package/dist/source-hash.d.ts.map +1 -0
- package/dist/source-hash.js +23 -0
- package/dist/source-hash.js.map +1 -0
- package/dist/starter-description.d.ts +44 -0
- package/dist/starter-description.d.ts.map +1 -0
- package/dist/starter-description.js +273 -0
- package/dist/starter-description.js.map +1 -0
- package/dist/starter-source.d.ts +43 -0
- package/dist/starter-source.d.ts.map +1 -0
- package/dist/starter-source.js +156 -0
- package/dist/starter-source.js.map +1 -0
- package/dist/store-app-apply.d.ts +27 -0
- package/dist/store-app-apply.d.ts.map +1 -0
- package/dist/store-app-apply.js +100 -0
- package/dist/store-app-apply.js.map +1 -0
- package/dist/store-app-manifest.d.ts +86 -0
- package/dist/store-app-manifest.d.ts.map +1 -0
- package/dist/store-app-manifest.js +110 -0
- package/dist/store-app-manifest.js.map +1 -0
- package/dist/store-app-registry.d.ts +30 -0
- package/dist/store-app-registry.d.ts.map +1 -0
- package/dist/store-app-registry.js +232 -0
- package/dist/store-app-registry.js.map +1 -0
- package/models/recommended.json +42 -0
- package/modules/api/templates/react-router/app/api/operations.ts +8 -0
- package/modules/api/templates/tanstack-start/src/api/operations.ts +15 -0
- package/modules/docs/templates/astro-emdash/content/docs/getting-started.mdx +13 -0
- package/modules/docs/templates/astro-emdash/content/docs/index.mdx +13 -0
- package/modules/docs/templates/astro-emdash/content/docs/mcp.mdx +11 -0
- package/modules/docs/templates/astro-emdash/content/docs/meta.json +4 -0
- package/modules/docs/templates/astro-emdash/site/content/docs/getting-started.mdx +12 -0
- package/modules/docs/templates/astro-emdash/site/content/docs/index.mdx +12 -0
- package/modules/docs/templates/astro-emdash/site/content/docs/mcp.mdx +10 -0
- package/modules/docs/templates/astro-emdash/site/content/docs/meta.json +4 -0
- package/modules/docs/templates/astro-emdash/site/source.config.ts +10 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/docs-assets.ts +1 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/docs-client.tsx +22 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/docs-data.ts +24 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/docs-handler.tsx +105 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/docs-layout.tsx +56 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/docs-mdx.tsx +79 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/docs-page-actions.tsx +146 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/docs-page.tsx +70 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/llm-text.ts +61 -0
- package/modules/docs/templates/astro-emdash/site/src/docs/source.ts +7 -0
- package/modules/docs/templates/astro-emdash/site/src/pages/docs/[...slug].ts +6 -0
- package/modules/docs/templates/astro-emdash/site/src/pages/docs/api/markdown.ts +4 -0
- package/modules/docs/templates/astro-emdash/site/src/pages/docs/api/search.ts +4 -0
- package/modules/docs/templates/astro-emdash/site/src/pages/llms.txt.ts +8 -0
- package/modules/docs/templates/astro-emdash/site/src/styles-docs.css +3 -0
- package/modules/docs/templates/astro-emdash/source.config.ts +10 -0
- package/modules/docs/templates/astro-emdash/src/docs/docs-assets.ts +1 -0
- package/modules/docs/templates/astro-emdash/src/docs/docs-client.tsx +22 -0
- package/modules/docs/templates/astro-emdash/src/docs/docs-data.ts +24 -0
- package/modules/docs/templates/astro-emdash/src/docs/docs-handler.tsx +105 -0
- package/modules/docs/templates/astro-emdash/src/docs/docs-layout.tsx +56 -0
- package/modules/docs/templates/astro-emdash/src/docs/docs-mdx.tsx +79 -0
- package/modules/docs/templates/astro-emdash/src/docs/docs-page-actions.tsx +146 -0
- package/modules/docs/templates/astro-emdash/src/docs/docs-page.tsx +70 -0
- package/modules/docs/templates/astro-emdash/src/docs/llm-text.ts +61 -0
- package/modules/docs/templates/astro-emdash/src/docs/source.ts +7 -0
- package/modules/docs/templates/astro-emdash/src/routes/docs/$.tsx +22 -0
- package/modules/docs/templates/astro-emdash/src/routes/docs/api/markdown.ts +12 -0
- package/modules/docs/templates/astro-emdash/src/routes/docs/api/search.ts +12 -0
- package/modules/docs/templates/astro-emdash/src/routes/docs.index.tsx +22 -0
- package/modules/docs/templates/astro-emdash/src/routes/docs.tsx +22 -0
- package/modules/docs/templates/astro-emdash/src/styles-docs.css +3 -0
- package/modules/docs/templates/react-router/app/components/mdx.tsx +79 -0
- package/modules/docs/templates/react-router/app/lib/layout.shared.tsx +54 -0
- package/modules/docs/templates/react-router/app/lib/source.ts +7 -0
- package/modules/docs/templates/react-router/app/routes/docs.$.tsx +49 -0
- package/modules/docs/templates/react-router/app/routes/docs.api.search.ts +10 -0
- package/modules/docs/templates/react-router/app/routes/docs.tsx +13 -0
- package/modules/docs/templates/react-router/content/docs/getting-started.mdx +8 -0
- package/modules/docs/templates/react-router/content/docs/index.mdx +8 -0
- package/modules/docs/templates/react-router/content/docs/mcp.mdx +121 -0
- package/modules/docs/templates/react-router/content/docs/meta.json +4 -0
- package/modules/docs/templates/react-router/source.config.ts +5 -0
- package/modules/docs/templates/tanstack-start/content/docs/getting-started.mdx +10 -0
- package/modules/docs/templates/tanstack-start/content/docs/index.mdx +8 -0
- package/modules/docs/templates/tanstack-start/content/docs/mcp.mdx +121 -0
- package/modules/docs/templates/tanstack-start/content/docs/meta.json +4 -0
- package/modules/docs/templates/tanstack-start/source.config.ts +10 -0
- package/modules/docs/templates/tanstack-start/src/docs/docs-assets.ts +1 -0
- package/modules/docs/templates/tanstack-start/src/docs/docs-client.tsx +22 -0
- package/modules/docs/templates/tanstack-start/src/docs/docs-data.ts +24 -0
- package/modules/docs/templates/tanstack-start/src/docs/docs-handler.tsx +105 -0
- package/modules/docs/templates/tanstack-start/src/docs/docs-layout.tsx +56 -0
- package/modules/docs/templates/tanstack-start/src/docs/docs-mdx.tsx +79 -0
- package/modules/docs/templates/tanstack-start/src/docs/docs-page-actions.tsx +146 -0
- package/modules/docs/templates/tanstack-start/src/docs/docs-page.tsx +70 -0
- package/modules/docs/templates/tanstack-start/src/docs/llm-text.ts +61 -0
- package/modules/docs/templates/tanstack-start/src/docs/source.ts +7 -0
- package/modules/docs/templates/tanstack-start/src/routes/docs/$.tsx +22 -0
- package/modules/docs/templates/tanstack-start/src/routes/docs/api/markdown.ts +12 -0
- package/modules/docs/templates/tanstack-start/src/routes/docs/api/search.ts +12 -0
- package/modules/docs/templates/tanstack-start/src/routes/docs.index.tsx +22 -0
- package/modules/docs/templates/tanstack-start/src/routes/docs.tsx +22 -0
- package/modules/docs/templates/tanstack-start/src/styles-docs.css +3 -0
- package/modules/guide/templates/astro-emdash/content/guide/capability-map.md +17 -0
- package/modules/guide/templates/astro-emdash/src/components/guide-widget.tsx +41 -0
- package/modules/guide/templates/astro-emdash/src/guide/actions.ts +8 -0
- package/modules/guide/templates/astro-emdash/src/guide/config.ts +21 -0
- package/modules/guide/templates/astro-emdash/src/guide/corpus.gen.ts +4 -0
- package/modules/guide/templates/astro-emdash/src/guide/corpus.manifest.json +72 -0
- package/modules/guide/templates/astro-emdash/src/guide/corpus.ts +4 -0
- package/modules/guide/templates/astro-emdash/src/guide/resources.json +4 -0
- package/modules/guide/templates/react-router/app/components/guide-widget.tsx +29 -0
- package/modules/guide/templates/react-router/app/guide/actions.ts +3 -0
- package/modules/guide/templates/react-router/app/guide/config.ts +21 -0
- package/modules/guide/templates/react-router/app/guide/corpus.gen.ts +4 -0
- package/modules/guide/templates/react-router/app/guide/corpus.manifest.json +22 -0
- package/modules/guide/templates/react-router/app/guide/corpus.ts +4 -0
- package/modules/guide/templates/react-router/app/guide/resources.json +4 -0
- package/modules/guide/templates/react-router/content/guide/capability-map.md +13 -0
- package/modules/guide/templates/tanstack-start/content/guide/capability-map.md +17 -0
- package/modules/guide/templates/tanstack-start/src/components/guide-widget.tsx +41 -0
- package/modules/guide/templates/tanstack-start/src/guide/actions.ts +17 -0
- package/modules/guide/templates/tanstack-start/src/guide/config.ts +21 -0
- package/modules/guide/templates/tanstack-start/src/guide/corpus.gen.ts +4 -0
- package/modules/guide/templates/tanstack-start/src/guide/corpus.manifest.json +22 -0
- package/modules/guide/templates/tanstack-start/src/guide/corpus.ts +4 -0
- package/modules/guide/templates/tanstack-start/src/guide/resources.json +4 -0
- package/modules/openai-subscription/templates/astro-emdash/.agents/skills/raybase-openai-subscription/SKILL.md +57 -0
- package/modules/openai-subscription/templates/astro-emdash/.agents/skills/raybase-openai-subscription/references/compatibility-and-testing.md +129 -0
- package/modules/openai-subscription/templates/astro-emdash/.agents/skills/raybase-openai-subscription/references/module-contract.md +133 -0
- package/modules/openai-subscription/templates/astro-emdash/.agents/skills/raybase-openai-subscription/references/structured-outputs.md +159 -0
- package/modules/openai-subscription/templates/astro-emdash/src/openai-subscription.ts +11 -0
- package/modules/openai-subscription/templates/react-router/.agents/skills/raybase-openai-subscription/SKILL.md +57 -0
- package/modules/openai-subscription/templates/react-router/.agents/skills/raybase-openai-subscription/references/compatibility-and-testing.md +129 -0
- package/modules/openai-subscription/templates/react-router/.agents/skills/raybase-openai-subscription/references/module-contract.md +133 -0
- package/modules/openai-subscription/templates/react-router/.agents/skills/raybase-openai-subscription/references/structured-outputs.md +159 -0
- package/modules/openai-subscription/templates/react-router/app/openai-subscription.ts +11 -0
- package/modules/openai-subscription/templates/tanstack-start/.agents/skills/raybase-openai-subscription/SKILL.md +57 -0
- package/modules/openai-subscription/templates/tanstack-start/.agents/skills/raybase-openai-subscription/references/compatibility-and-testing.md +129 -0
- package/modules/openai-subscription/templates/tanstack-start/.agents/skills/raybase-openai-subscription/references/module-contract.md +133 -0
- package/modules/openai-subscription/templates/tanstack-start/.agents/skills/raybase-openai-subscription/references/structured-outputs.md +159 -0
- package/modules/openai-subscription/templates/tanstack-start/src/openai-subscription.ts +11 -0
- package/package.json +34 -8
- package/skills/README.md +122 -0
- package/skills/raybase-actions/SKILL.md +223 -0
- package/skills/raybase-actions/references/action-patterns.md +190 -0
- package/skills/raybase-actions/references/adapting-actions.md +93 -0
- package/skills/raybase-actions/references/testing-actions.md +48 -0
- package/skills/raybase-agent-debugging/SKILL.md +230 -0
- package/skills/raybase-ai/SKILL.md +1310 -0
- package/skills/raybase-api/SKILL.md +45 -0
- package/skills/raybase-astro-emdash/SKILL.md +143 -0
- package/skills/raybase-astro-emdash-content-model/SKILL.md +217 -0
- package/skills/raybase-astro-emdash-content-model/references/LICENSE-emdash +9 -0
- package/skills/raybase-astro-emdash-content-model/references/emdash-collections.md +265 -0
- package/skills/raybase-astro-emdash-design/LICENSE-impeccable +60 -0
- package/skills/raybase-astro-emdash-design/SKILL.md +170 -0
- package/skills/raybase-astro-emdash-design/reference/color.md +91 -0
- package/skills/raybase-astro-emdash-design/reference/copy.md +73 -0
- package/skills/raybase-astro-emdash-design/reference/direction.md +115 -0
- package/skills/raybase-astro-emdash-design/reference/imagery.md +84 -0
- package/skills/raybase-astro-emdash-design/reference/layout.md +69 -0
- package/skills/raybase-astro-emdash-design/reference/motion.md +75 -0
- package/skills/raybase-astro-emdash-design/reference/polish.md +75 -0
- package/skills/raybase-astro-emdash-design/reference/typography.md +72 -0
- package/skills/raybase-astro-emdash-galley/SKILL.md +265 -0
- package/skills/raybase-astro-emdash-migration/SKILL.md +218 -0
- package/skills/raybase-astro-emdash-migration/references/inventory-and-conversion.md +242 -0
- package/skills/raybase-astro-emdash-security-review/SKILL.md +68 -0
- package/skills/raybase-astro-emdash-theme-selection/SKILL.md +216 -0
- package/skills/raybase-auth/SKILL.md +358 -0
- package/skills/raybase-background-jobs/SKILL.md +774 -0
- package/skills/raybase-building/SKILL.md +409 -0
- package/skills/raybase-building/references/interview-and-spec.md +87 -0
- package/skills/raybase-building/references/planning-docs.md +26 -0
- package/skills/raybase-building/references/schema-and-config.md +70 -0
- package/skills/raybase-changing-a-live-app/SKILL.md +119 -0
- package/skills/raybase-data-and-policies/SKILL.md +377 -0
- package/skills/raybase-deploy/SKILL.md +136 -0
- package/skills/raybase-docs-writing/SKILL.md +119 -0
- package/skills/raybase-guide/SKILL.md +235 -0
- package/skills/raybase-mcp/SKILL.md +309 -0
- package/skills/raybase-mcp/agents/openai.yaml +4 -0
- package/skills/raybase-notifications/SKILL.md +138 -0
- package/skills/raybase-pro-migration/SKILL.md +28 -0
- package/skills/raybase-react-router/SKILL.md +241 -0
- package/skills/raybase-react-router-design/LICENSE-impeccable +60 -0
- package/skills/raybase-react-router-design/SKILL.md +135 -0
- package/skills/raybase-react-router-design/reference/color.md +87 -0
- package/skills/raybase-react-router-design/reference/copy.md +83 -0
- package/skills/raybase-react-router-design/reference/delight.md +48 -0
- package/skills/raybase-react-router-design/reference/interaction.md +91 -0
- package/skills/raybase-react-router-design/reference/layout.md +82 -0
- package/skills/raybase-react-router-design/reference/motion.md +86 -0
- package/skills/raybase-react-router-design/reference/polish.md +79 -0
- package/skills/raybase-react-router-design/reference/typography.md +71 -0
- package/skills/raybase-react-router-security-review/LICENSE +22 -0
- package/skills/raybase-react-router-security-review/SKILL.md +190 -0
- package/skills/raybase-react-router-security-review/agents/openai.yaml +4 -0
- package/skills/raybase-react-router-security-review/references/api-security.md +519 -0
- package/skills/raybase-react-router-security-review/references/authentication.md +353 -0
- package/skills/raybase-react-router-security-review/references/authorization.md +372 -0
- package/skills/raybase-react-router-security-review/references/business-logic.md +443 -0
- package/skills/raybase-react-router-security-review/references/cryptography.md +329 -0
- package/skills/raybase-react-router-security-review/references/csrf.md +398 -0
- package/skills/raybase-react-router-security-review/references/data-protection.md +378 -0
- package/skills/raybase-react-router-security-review/references/deserialization.md +410 -0
- package/skills/raybase-react-router-security-review/references/error-handling.md +436 -0
- package/skills/raybase-react-router-security-review/references/file-security.md +457 -0
- package/skills/raybase-react-router-security-review/references/injection.md +259 -0
- package/skills/raybase-react-router-security-review/references/logging.md +433 -0
- package/skills/raybase-react-router-security-review/references/misconfiguration.md +435 -0
- package/skills/raybase-react-router-security-review/references/modern-threats.md +475 -0
- package/skills/raybase-react-router-security-review/references/raybase-react-router-security.md +235 -0
- package/skills/raybase-react-router-security-review/references/ssrf.md +413 -0
- package/skills/raybase-react-router-security-review/references/supply-chain.md +405 -0
- package/skills/raybase-react-router-security-review/references/xss.md +336 -0
- package/skills/raybase-realtime/SKILL.md +158 -0
- package/skills/raybase-realtime/agents/openai.yaml +4 -0
- package/skills/raybase-schema/SKILL.md +209 -0
- package/skills/raybase-search/SKILL.md +137 -0
- package/skills/raybase-search/agents/openai.yaml +4 -0
- package/skills/raybase-settings/SKILL.md +139 -0
- package/skills/raybase-settings/agents/openai.yaml +4 -0
- package/skills/raybase-tanstack-start/SKILL.md +166 -0
- package/skills/raybase-tanstack-start-design/LICENSE-impeccable +60 -0
- package/skills/raybase-tanstack-start-design/SKILL.md +140 -0
- package/skills/raybase-tanstack-start-design/reference/color.md +80 -0
- package/skills/raybase-tanstack-start-design/reference/copy.md +83 -0
- package/skills/raybase-tanstack-start-design/reference/delight.md +48 -0
- package/skills/raybase-tanstack-start-design/reference/interaction.md +91 -0
- package/skills/raybase-tanstack-start-design/reference/layout.md +82 -0
- package/skills/raybase-tanstack-start-design/reference/motion.md +86 -0
- package/skills/raybase-tanstack-start-design/reference/polish.md +79 -0
- package/skills/raybase-tanstack-start-design/reference/typography.md +71 -0
- package/skills/raybase-tanstack-start-security-review/LICENSE +22 -0
- package/skills/raybase-tanstack-start-security-review/SKILL.md +194 -0
- package/skills/raybase-tanstack-start-security-review/agents/openai.yaml +4 -0
- package/skills/raybase-tanstack-start-security-review/references/api-security.md +519 -0
- package/skills/raybase-tanstack-start-security-review/references/authentication.md +353 -0
- package/skills/raybase-tanstack-start-security-review/references/authorization.md +372 -0
- package/skills/raybase-tanstack-start-security-review/references/business-logic.md +443 -0
- package/skills/raybase-tanstack-start-security-review/references/cryptography.md +329 -0
- package/skills/raybase-tanstack-start-security-review/references/csrf.md +398 -0
- package/skills/raybase-tanstack-start-security-review/references/data-protection.md +378 -0
- package/skills/raybase-tanstack-start-security-review/references/deserialization.md +410 -0
- package/skills/raybase-tanstack-start-security-review/references/error-handling.md +436 -0
- package/skills/raybase-tanstack-start-security-review/references/file-security.md +457 -0
- package/skills/raybase-tanstack-start-security-review/references/injection.md +259 -0
- package/skills/raybase-tanstack-start-security-review/references/logging.md +433 -0
- package/skills/raybase-tanstack-start-security-review/references/misconfiguration.md +435 -0
- package/skills/raybase-tanstack-start-security-review/references/modern-threats.md +475 -0
- package/skills/raybase-tanstack-start-security-review/references/raybase-tanstack-security.md +208 -0
- package/skills/raybase-tanstack-start-security-review/references/ssrf.md +413 -0
- package/skills/raybase-tanstack-start-security-review/references/supply-chain.md +405 -0
- package/skills/raybase-tanstack-start-security-review/references/xss.md +336 -0
- package/skills-manifest.json +41 -0
- package/templates/astro-emdash/.dev.vars.example +7 -0
- package/templates/astro-emdash/AGENTS.md +122 -0
- package/templates/astro-emdash/DESIGN.md +90 -0
- package/templates/astro-emdash/components.json +21 -0
- package/templates/astro-emdash/content/docs/getting-started.mdx +20 -0
- package/templates/astro-emdash/content/docs/index.mdx +13 -0
- package/templates/astro-emdash/content/docs/mcp.mdx +11 -0
- package/templates/astro-emdash/content/docs/meta.json +4 -0
- package/templates/astro-emdash/content/docs/site-templates.mdx +62 -0
- package/templates/astro-emdash/dev/CODEBASE-MAP.md +46 -0
- package/templates/astro-emdash/dev/SPEC-OVERVIEW.md +15 -0
- package/templates/astro-emdash/dev/SPEC.md +84 -0
- package/templates/astro-emdash/dev/features/archive/.gitkeep +1 -0
- package/templates/astro-emdash/docs/theme-previews/base.svg +24 -0
- package/templates/astro-emdash/docs/theme-previews/steel.svg +24 -0
- package/templates/astro-emdash/docs/theme-previews/zen.svg +24 -0
- package/templates/astro-emdash/docs/themes.md +106 -0
- package/templates/astro-emdash/drizzle.config.ts +5 -0
- package/templates/astro-emdash/gitignore +11 -0
- package/templates/astro-emdash/migrations/app/meta/_journal.json +5 -0
- package/templates/astro-emdash/package.json +79 -0
- package/templates/astro-emdash/pnpm-workspace.yaml +71 -0
- package/templates/astro-emdash/public/_headers +4 -0
- package/templates/astro-emdash/site/astro.config.mjs +120 -0
- package/templates/astro-emdash/site/demo/README.md +72 -0
- package/templates/astro-emdash/site/demo/content/collection.json +43 -0
- package/templates/astro-emdash/site/demo/content/entries.json +120 -0
- package/templates/astro-emdash/site/demo/templates/demo-article-card/manifest.json +51 -0
- package/templates/astro-emdash/site/demo/templates/demo-article-card/sample-content.json +5 -0
- package/templates/astro-emdash/site/demo/templates/demo-article-card/template.liquid +48 -0
- package/templates/astro-emdash/site/demo/templates/demo-article-page/host.json +9 -0
- package/templates/astro-emdash/site/demo/templates/demo-article-page/manifest.json +38 -0
- package/templates/astro-emdash/site/demo/templates/demo-article-page/sample-content.json +34 -0
- package/templates/astro-emdash/site/demo/templates/demo-article-page/template.liquid +84 -0
- package/templates/astro-emdash/site/demo/templates/demo-articles-index/manifest.json +64 -0
- package/templates/astro-emdash/site/demo/templates/demo-articles-index/page.json +7 -0
- package/templates/astro-emdash/site/demo/templates/demo-articles-index/sample-content.json +24 -0
- package/templates/astro-emdash/site/demo/templates/demo-articles-index/template.liquid +100 -0
- package/templates/astro-emdash/site/demo/templates/demo-menu-nav/manifest.json +51 -0
- package/templates/astro-emdash/site/demo/templates/demo-menu-nav/sample-content.json +5 -0
- package/templates/astro-emdash/site/demo/templates/demo-menu-nav/template.liquid +70 -0
- package/templates/astro-emdash/site/gitignore +1 -0
- package/templates/astro-emdash/site/package.json +56 -0
- package/templates/astro-emdash/site/scripts/apply-site-templates.mjs +560 -0
- package/templates/astro-emdash/site/scripts/galley-demo.mjs +298 -0
- package/templates/astro-emdash/site/scripts/seed-galley-starter.mjs +360 -0
- package/templates/astro-emdash/site/scripts/site-origin.mjs +45 -0
- package/templates/astro-emdash/site/seed/seed.json +154 -0
- package/templates/astro-emdash/site/seed/templates/.gitkeep +1 -0
- package/templates/astro-emdash/site/src/components/RaybaseSignedInMenu.astro +163 -0
- package/templates/astro-emdash/site/src/components/blocks/RaybaseActionIsland.astro +41 -0
- package/templates/astro-emdash/site/src/content-door/raybase-routes.ts +738 -0
- package/templates/astro-emdash/site/src/content-door/resolve-page.ts +142 -0
- package/templates/astro-emdash/site/src/content-door/seed.ts +85 -0
- package/templates/astro-emdash/site/src/env.d.ts +12 -0
- package/templates/astro-emdash/site/src/layouts/SiteLayout.astro +68 -0
- package/templates/astro-emdash/site/src/lib/palettes.gen.ts +7 -0
- package/templates/astro-emdash/site/src/lib/site-motion.ts +169 -0
- package/templates/astro-emdash/site/src/lib/site-shell.ts +294 -0
- package/templates/astro-emdash/site/src/live.config.ts +8 -0
- package/templates/astro-emdash/site/src/middleware.ts +20 -0
- package/templates/astro-emdash/site/src/pages/[...slug].astro +113 -0
- package/templates/astro-emdash/site/src/pages/_raybase/handoff/consume.ts +6 -0
- package/templates/astro-emdash/site/src/pages/_raybase/islands/action.ts +8 -0
- package/templates/astro-emdash/site/src/pages/_raybase/sign-out/index.ts +6 -0
- package/templates/astro-emdash/site/src/styles/palette-fonts.gen.css +1 -0
- package/templates/astro-emdash/site/src/styles/palettes.gen.css +3 -0
- package/templates/astro-emdash/site/src/styles.css +607 -0
- package/templates/astro-emdash/site/tsconfig.json +12 -0
- package/templates/astro-emdash/site/wrangler.jsonc +34 -0
- package/templates/astro-emdash/source.config.ts +10 -0
- package/templates/astro-emdash/src/actions.ts +58 -0
- package/templates/astro-emdash/src/ai/agents.ts +20 -0
- package/templates/astro-emdash/src/ai/retrieval.ts +36 -0
- package/templates/astro-emdash/src/auth-door.ts +18 -0
- package/templates/astro-emdash/src/client.tsx +25 -0
- package/templates/astro-emdash/src/components/.gitkeep +1 -0
- package/templates/astro-emdash/src/components/account-menu.tsx +91 -0
- package/templates/astro-emdash/src/components/auth-shell.tsx +69 -0
- package/templates/astro-emdash/src/components/mode-toggle.tsx +32 -0
- package/templates/astro-emdash/src/components/search-command-palette.tsx +107 -0
- package/templates/astro-emdash/src/components/setup-token-page.tsx +196 -0
- package/templates/astro-emdash/src/components/ui/avatar.tsx +107 -0
- package/templates/astro-emdash/src/components/ui/badge.tsx +52 -0
- package/templates/astro-emdash/src/components/ui/button.tsx +69 -0
- package/templates/astro-emdash/src/components/ui/checkbox.tsx +29 -0
- package/templates/astro-emdash/src/components/ui/dialog.tsx +158 -0
- package/templates/astro-emdash/src/components/ui/dropdown-menu.tsx +303 -0
- package/templates/astro-emdash/src/components/ui/input.tsx +20 -0
- package/templates/astro-emdash/src/components/ui/label.tsx +20 -0
- package/templates/astro-emdash/src/components/ui/scroll-area.tsx +53 -0
- package/templates/astro-emdash/src/components/ui/select.tsx +215 -0
- package/templates/astro-emdash/src/components/ui/separator.tsx +23 -0
- package/templates/astro-emdash/src/components/ui/sheet.tsx +138 -0
- package/templates/astro-emdash/src/components/ui/sidebar.tsx +728 -0
- package/templates/astro-emdash/src/components/ui/skeleton.tsx +13 -0
- package/templates/astro-emdash/src/components/ui/textarea.tsx +18 -0
- package/templates/astro-emdash/src/components/ui/tooltip.tsx +66 -0
- package/templates/astro-emdash/src/db/migrations.gen.ts +6 -0
- package/templates/astro-emdash/src/db/schema.ts +6 -0
- package/templates/astro-emdash/src/db/seed.ts +16 -0
- package/templates/astro-emdash/src/db/storage.ts +32 -0
- package/templates/astro-emdash/src/docs/docs-assets.ts +1 -0
- package/templates/astro-emdash/src/docs/docs-client.tsx +22 -0
- package/templates/astro-emdash/src/docs/docs-data.ts +24 -0
- package/templates/astro-emdash/src/docs/docs-handler.tsx +105 -0
- package/templates/astro-emdash/src/docs/docs-layout.tsx +56 -0
- package/templates/astro-emdash/src/docs/docs-mdx.tsx +79 -0
- package/templates/astro-emdash/src/docs/docs-page-actions.tsx +146 -0
- package/templates/astro-emdash/src/docs/docs-page.tsx +70 -0
- package/templates/astro-emdash/src/docs/llm-text.ts +61 -0
- package/templates/astro-emdash/src/docs/source.ts +7 -0
- package/templates/astro-emdash/src/guide/corpus.gen.ts +4 -0
- package/templates/astro-emdash/src/guide/corpus.manifest.json +72 -0
- package/templates/astro-emdash/src/hooks/use-mobile.ts +19 -0
- package/templates/astro-emdash/src/jobs.example.ts +48 -0
- package/templates/astro-emdash/src/lib/account.ts +12 -0
- package/templates/astro-emdash/src/lib/auth-client.ts +181 -0
- package/templates/astro-emdash/src/lib/utils.ts +6 -0
- package/templates/astro-emdash/src/mcp-app.ts +57 -0
- package/templates/astro-emdash/src/notifications.example.ts +37 -0
- package/templates/astro-emdash/src/raybase.auth.ts +70 -0
- package/templates/astro-emdash/src/raybase.config.ts +49 -0
- package/templates/astro-emdash/src/raybase.server.ts +56 -0
- package/templates/astro-emdash/src/realtime.example.ts +18 -0
- package/templates/astro-emdash/src/router.tsx +19 -0
- package/templates/astro-emdash/src/routes/__root.tsx +56 -0
- package/templates/astro-emdash/src/routes/_app/admin.tsx +13 -0
- package/templates/astro-emdash/src/routes/_app/forgot-password.tsx +97 -0
- package/templates/astro-emdash/src/routes/_app/index.tsx +169 -0
- package/templates/astro-emdash/src/routes/_app/invite.$token.tsx +11 -0
- package/templates/astro-emdash/src/routes/_app/login.tsx +193 -0
- package/templates/astro-emdash/src/routes/_app/profile.tsx +98 -0
- package/templates/astro-emdash/src/routes/_app/reset-password.$token.tsx +15 -0
- package/templates/astro-emdash/src/routes/_app/reset-password.tsx +115 -0
- package/templates/astro-emdash/src/routes/_app/setup.$token.tsx +11 -0
- package/templates/astro-emdash/src/routes/_app/signup.tsx +141 -0
- package/templates/astro-emdash/src/routes/_app/verify-email.$token.tsx +15 -0
- package/templates/astro-emdash/src/routes/_app/verify-email.tsx +154 -0
- package/templates/astro-emdash/src/routes/_app.tsx +33 -0
- package/templates/astro-emdash/src/routes/admin/$.ts +20 -0
- package/templates/astro-emdash/src/routes/api/$.ts +19 -0
- package/templates/astro-emdash/src/routes/docs/$.tsx +22 -0
- package/templates/astro-emdash/src/routes/docs/api/markdown.ts +12 -0
- package/templates/astro-emdash/src/routes/docs/api/search.ts +12 -0
- package/templates/astro-emdash/src/routes/docs.index.tsx +22 -0
- package/templates/astro-emdash/src/routes/docs.tsx +22 -0
- package/templates/astro-emdash/src/search.ts +6 -0
- package/templates/astro-emdash/src/settings.ts +12 -0
- package/templates/astro-emdash/src/styles-docs.css +3 -0
- package/templates/astro-emdash/src/styles.css +101 -0
- package/templates/astro-emdash/src/themes/base.css +76 -0
- package/templates/astro-emdash/src/themes/carbon.css +76 -0
- package/templates/astro-emdash/src/themes/fonts.css +25 -0
- package/templates/astro-emdash/src/themes/sage.css +76 -0
- package/templates/astro-emdash/src/themes/sand.css +76 -0
- package/templates/astro-emdash/src/themes/slate.css +81 -0
- package/templates/astro-emdash/src/themes/ultra.css +76 -0
- package/templates/astro-emdash/src/themes/zen.css +76 -0
- package/templates/astro-emdash/src/worker-entry.ts +31 -0
- package/templates/astro-emdash/tests/raybase-patterns.test.ts +29 -0
- package/templates/astro-emdash/tsconfig.json +36 -0
- package/templates/astro-emdash/vite.config.ts +130 -0
- package/templates/astro-emdash/vitest.config.ts +8 -0
- package/templates/astro-emdash/wrangler.jsonc +112 -0
- package/templates/react-router/.dev.vars.example +5 -0
- package/templates/react-router/.editorconfig +15 -0
- package/templates/react-router/AGENTS.md +54 -0
- package/templates/react-router/README.md +52 -0
- package/templates/react-router/app/app.css +44 -0
- package/templates/react-router/app/components/mdx.tsx +79 -0
- package/templates/react-router/app/components/ui/button.tsx +45 -0
- package/templates/react-router/app/components/ui/card.tsx +87 -0
- package/templates/react-router/app/components/ui/separator.tsx +22 -0
- package/templates/react-router/app/db/migrations.gen.ts +6 -0
- package/templates/react-router/app/db/schema.ts +56 -0
- package/templates/react-router/app/db/seed.ts +14 -0
- package/templates/react-router/app/entry.server.tsx +41 -0
- package/templates/react-router/app/globals.d.ts +1 -0
- package/templates/react-router/app/lib/layout.shared.tsx +52 -0
- package/templates/react-router/app/lib/source.ts +7 -0
- package/templates/react-router/app/lib/utils.ts +6 -0
- package/templates/react-router/app/raybase.server.ts +65 -0
- package/templates/react-router/app/root.tsx +23 -0
- package/templates/react-router/app/routes/_index.tsx +53 -0
- package/templates/react-router/app/routes/docs.$.tsx +49 -0
- package/templates/react-router/app/routes/docs.api.search.ts +10 -0
- package/templates/react-router/app/routes/docs.tsx +13 -0
- package/templates/react-router/app/routes.ts +3 -0
- package/templates/react-router/components.json +22 -0
- package/templates/react-router/content/docs/getting-started.mdx +15 -0
- package/templates/react-router/content/docs/index.mdx +8 -0
- package/templates/react-router/content/docs/mcp.mdx +121 -0
- package/templates/react-router/content/docs/meta.json +4 -0
- package/templates/react-router/dev/CODEBASE-MAP.md +48 -0
- package/templates/react-router/dev/SPEC-OVERVIEW.md +35 -0
- package/templates/react-router/dev/SPEC.md +93 -0
- package/templates/react-router/dev/features/archive/.gitkeep +1 -0
- package/templates/react-router/drizzle.config.ts +5 -0
- package/templates/react-router/env.d.ts +53 -0
- package/templates/react-router/gitignore +23 -0
- package/templates/react-router/migrations/app/meta/_journal.json +1 -0
- package/templates/react-router/package.json +70 -0
- package/templates/react-router/public/_headers +4 -0
- package/templates/react-router/public/favicon.ico +0 -0
- package/templates/react-router/react-router.config.ts +9 -0
- package/templates/react-router/source.config.ts +5 -0
- package/templates/react-router/tests/raybase-patterns.test.ts +23 -0
- package/templates/react-router/tsconfig.json +27 -0
- package/templates/react-router/vite.config.ts +59 -0
- package/templates/react-router/vitest.config.ts +8 -0
- package/templates/react-router/workers/app.ts +40 -0
- package/templates/react-router/wrangler.jsonc +111 -0
- package/templates/tanstack-start/.dev.vars.example +5 -0
- package/templates/tanstack-start/AGENTS.md +95 -0
- package/templates/tanstack-start/DESIGN.md +65 -0
- package/templates/tanstack-start/components.json +21 -0
- package/templates/tanstack-start/content/docs/getting-started.mdx +65 -0
- package/templates/tanstack-start/content/docs/index.mdx +10 -0
- package/templates/tanstack-start/content/docs/mcp.mdx +122 -0
- package/templates/tanstack-start/content/docs/meta.json +4 -0
- package/templates/tanstack-start/dev/CODEBASE-MAP.md +84 -0
- package/templates/tanstack-start/dev/SPEC-OVERVIEW.md +46 -0
- package/templates/tanstack-start/dev/SPEC.md +213 -0
- package/templates/tanstack-start/dev/features/archive/.gitkeep +1 -0
- package/templates/tanstack-start/docs/theme-previews/base.svg +24 -0
- package/templates/tanstack-start/docs/theme-previews/steel.svg +24 -0
- package/templates/tanstack-start/docs/theme-previews/zen.svg +24 -0
- package/templates/tanstack-start/docs/themes.md +116 -0
- package/templates/tanstack-start/drizzle.config.ts +5 -0
- package/templates/tanstack-start/gitignore +11 -0
- package/templates/tanstack-start/migrations/app/0000_low_karen_page.sql +26 -0
- package/templates/tanstack-start/migrations/app/meta/0000_snapshot.json +196 -0
- package/templates/tanstack-start/migrations/app/meta/_journal.json +13 -0
- package/templates/tanstack-start/package.json +77 -0
- package/templates/tanstack-start/public/_headers +8 -0
- package/templates/tanstack-start/public/icons/app-icon-maskable.svg +1 -0
- package/templates/tanstack-start/public/icons/app-icon.svg +1 -0
- package/templates/tanstack-start/public/icons/apple-touch-icon.png +0 -0
- package/templates/tanstack-start/public/manifest.webmanifest +14 -0
- package/templates/tanstack-start/public/raybase-push-sw.js +32 -0
- package/templates/tanstack-start/source.config.ts +10 -0
- package/templates/tanstack-start/src/actions.ts +560 -0
- package/templates/tanstack-start/src/ai/agents.ts +78 -0
- package/templates/tanstack-start/src/ai/retrieval.ts +36 -0
- package/templates/tanstack-start/src/auth-door.ts +18 -0
- package/templates/tanstack-start/src/client.tsx +25 -0
- package/templates/tanstack-start/src/components/.gitkeep +1 -0
- package/templates/tanstack-start/src/components/account-menu.tsx +127 -0
- package/templates/tanstack-start/src/components/auth-shell.tsx +69 -0
- package/templates/tanstack-start/src/components/install-app.tsx +35 -0
- package/templates/tanstack-start/src/components/mode-toggle.tsx +32 -0
- package/templates/tanstack-start/src/components/search-command-palette.tsx +107 -0
- package/templates/tanstack-start/src/components/setup-token-page.tsx +197 -0
- package/templates/tanstack-start/src/components/ui/avatar.tsx +107 -0
- package/templates/tanstack-start/src/components/ui/badge.tsx +52 -0
- package/templates/tanstack-start/src/components/ui/button.tsx +69 -0
- package/templates/tanstack-start/src/components/ui/checkbox.tsx +29 -0
- package/templates/tanstack-start/src/components/ui/dialog.tsx +158 -0
- package/templates/tanstack-start/src/components/ui/dropdown-menu.tsx +303 -0
- package/templates/tanstack-start/src/components/ui/input.tsx +20 -0
- package/templates/tanstack-start/src/components/ui/label.tsx +20 -0
- package/templates/tanstack-start/src/components/ui/scroll-area.tsx +53 -0
- package/templates/tanstack-start/src/components/ui/select.tsx +215 -0
- package/templates/tanstack-start/src/components/ui/separator.tsx +23 -0
- package/templates/tanstack-start/src/components/ui/sheet.tsx +138 -0
- package/templates/tanstack-start/src/components/ui/sidebar.tsx +728 -0
- package/templates/tanstack-start/src/components/ui/skeleton.tsx +13 -0
- package/templates/tanstack-start/src/components/ui/textarea.tsx +18 -0
- package/templates/tanstack-start/src/components/ui/tooltip.tsx +66 -0
- package/templates/tanstack-start/src/db/migrations.gen.ts +6 -0
- package/templates/tanstack-start/src/db/schema.ts +90 -0
- package/templates/tanstack-start/src/db/seed.ts +106 -0
- package/templates/tanstack-start/src/db/storage.ts +32 -0
- package/templates/tanstack-start/src/docs/docs-assets.ts +1 -0
- package/templates/tanstack-start/src/docs/docs-client.tsx +22 -0
- package/templates/tanstack-start/src/docs/docs-data.ts +24 -0
- package/templates/tanstack-start/src/docs/docs-handler.tsx +105 -0
- package/templates/tanstack-start/src/docs/docs-layout.tsx +56 -0
- package/templates/tanstack-start/src/docs/docs-mdx.tsx +79 -0
- package/templates/tanstack-start/src/docs/docs-page-actions.tsx +146 -0
- package/templates/tanstack-start/src/docs/docs-page.tsx +70 -0
- package/templates/tanstack-start/src/docs/llm-text.ts +61 -0
- package/templates/tanstack-start/src/docs/source.ts +7 -0
- package/templates/tanstack-start/src/hooks/use-mobile.ts +19 -0
- package/templates/tanstack-start/src/hooks/use-pwa-install.ts +77 -0
- package/templates/tanstack-start/src/jobs.example.ts +56 -0
- package/templates/tanstack-start/src/lib/account.ts +13 -0
- package/templates/tanstack-start/src/lib/auth-client.ts +187 -0
- package/templates/tanstack-start/src/lib/push-client.ts +98 -0
- package/templates/tanstack-start/src/lib/utils.ts +6 -0
- package/templates/tanstack-start/src/mcp-app.ts +74 -0
- package/templates/tanstack-start/src/notifications.example.ts +37 -0
- package/templates/tanstack-start/src/raybase.auth.ts +86 -0
- package/templates/tanstack-start/src/raybase.config.ts +86 -0
- package/templates/tanstack-start/src/raybase.server.ts +155 -0
- package/templates/tanstack-start/src/realtime.example.ts +46 -0
- package/templates/tanstack-start/src/router.tsx +19 -0
- package/templates/tanstack-start/src/routes/__root.tsx +73 -0
- package/templates/tanstack-start/src/routes/_app/admin.tsx +13 -0
- package/templates/tanstack-start/src/routes/_app/forgot-password.tsx +97 -0
- package/templates/tanstack-start/src/routes/_app/index.tsx +1316 -0
- package/templates/tanstack-start/src/routes/_app/invite.$token.tsx +11 -0
- package/templates/tanstack-start/src/routes/_app/login.tsx +193 -0
- package/templates/tanstack-start/src/routes/_app/profile.tsx +98 -0
- package/templates/tanstack-start/src/routes/_app/reset-password.$token.tsx +16 -0
- package/templates/tanstack-start/src/routes/_app/reset-password.tsx +115 -0
- package/templates/tanstack-start/src/routes/_app/setup.$token.tsx +11 -0
- package/templates/tanstack-start/src/routes/_app/signup.tsx +141 -0
- package/templates/tanstack-start/src/routes/_app/verify-email.$token.tsx +15 -0
- package/templates/tanstack-start/src/routes/_app/verify-email.tsx +154 -0
- package/templates/tanstack-start/src/routes/_app.tsx +33 -0
- package/templates/tanstack-start/src/routes/admin/$.ts +20 -0
- package/templates/tanstack-start/src/routes/api/$.ts +19 -0
- package/templates/tanstack-start/src/routes/docs/$.tsx +22 -0
- package/templates/tanstack-start/src/routes/docs/api/markdown.ts +12 -0
- package/templates/tanstack-start/src/routes/docs/api/search.ts +12 -0
- package/templates/tanstack-start/src/routes/docs.index.tsx +22 -0
- package/templates/tanstack-start/src/routes/docs.tsx +22 -0
- package/templates/tanstack-start/src/search.ts +26 -0
- package/templates/tanstack-start/src/settings.ts +12 -0
- package/templates/tanstack-start/src/styles-docs.css +3 -0
- package/templates/tanstack-start/src/styles.css +73 -0
- package/templates/tanstack-start/src/themes/base.css +76 -0
- package/templates/tanstack-start/src/themes/carbon.css +76 -0
- package/templates/tanstack-start/src/themes/fonts.css +18 -0
- package/templates/tanstack-start/src/themes/sage.css +76 -0
- package/templates/tanstack-start/src/themes/sand.css +76 -0
- package/templates/tanstack-start/src/themes/slate.css +76 -0
- package/templates/tanstack-start/src/themes/ultra.css +76 -0
- package/templates/tanstack-start/src/themes/zen.css +76 -0
- package/templates/tanstack-start/src/worker-entry.ts +30 -0
- package/templates/tanstack-start/tests/raybase-patterns.test.ts +247 -0
- package/templates/tanstack-start/tsconfig.json +33 -0
- package/templates/tanstack-start/vite.config.ts +132 -0
- package/templates/tanstack-start/vitest.config.ts +8 -0
- package/templates/tanstack-start/wrangler.jsonc +112 -0
- package/README.md +0 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,2351 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { createHash, generateKeyPairSync, randomBytes } from "node:crypto";
|
|
4
|
+
import { cpSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, readlinkSync, renameSync, rmSync, statSync, symlinkSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { Command } from "commander";
|
|
8
|
+
import { applyEdits, modify, parse } from "jsonc-parser";
|
|
9
|
+
import { applyStoreAppOverlay, assertSafeProjectFiles } from "./store-app-apply.js";
|
|
10
|
+
import { resolveStoreApp } from "./store-app-registry.js";
|
|
11
|
+
import { RAYBASE_PACKAGE_RANGES } from "./raybase-package-ranges.js";
|
|
12
|
+
import { hashSourceTree } from "./source-hash.js";
|
|
13
|
+
import { STARTER_DESCRIPTION_FILE, starterRangeProblem } from "./starter-description.js";
|
|
14
|
+
import { STARTER_TREE_SKIP, resolveStarterSource } from "./starter-source.js";
|
|
15
|
+
export { MAX_SOURCE_BYTES, assertSafeSourcePath, directoryIntegrity, downloadGithubRepo, extractArchive, fetchSourceBuffer, materializeDirectFiles, parseGithubSource, rejectSymlinks, sha256Hex, sha256SourceIntegrity, siblingHref, splitSourceRef, validateDirectFileManifest } from "./source-fetch.js";
|
|
16
|
+
export { STARTER_DESCRIPTION_FILE, STARTER_FRAMEWORKS, StarterDescriptionError, readStarterDescription, satisfiesSemverRange, starterRangeProblem, validateStarterDescription } from "./starter-description.js";
|
|
17
|
+
export { parseStarterSource, resolveStarterSource } from "./starter-source.js";
|
|
18
|
+
const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
19
|
+
const FRAMEWORKS = ["tanstack-start", "react-router", "astro-emdash"];
|
|
20
|
+
const DEFAULT_FRAMEWORK = "tanstack-start";
|
|
21
|
+
const FRAMEWORK_HELP = `Frameworks (each has a built-in starter):
|
|
22
|
+
tanstack-start Pick for secure internal apps, dashboards, approval tools, and CRUD workflows. This is the default.
|
|
23
|
+
react-router Pick for a React Router app with Raybase sign-in, admin, and data in the same worker.
|
|
24
|
+
astro-emdash Pick for a public Astro + EmDash content site governed by a Raybase spine.`;
|
|
25
|
+
// Where each framework's built-in starter lives in the raybase repo (local
|
|
26
|
+
// mode) vs the published package (bundled by scripts/prepare-create-raybase.mjs into templates/<name>).
|
|
27
|
+
const FRAMEWORK_SOURCE_DIRS = {
|
|
28
|
+
"tanstack-start": "templates/tanstack-start",
|
|
29
|
+
"react-router": "templates/react-router",
|
|
30
|
+
"astro-emdash": "templates/astro-emdash"
|
|
31
|
+
};
|
|
32
|
+
const SKILLS_MANIFEST = loadSkillsManifest();
|
|
33
|
+
const BASE_SKILLS = SKILLS_MANIFEST.base;
|
|
34
|
+
const FRAMEWORK_SKILLS = Object.fromEntries(FRAMEWORKS.map((framework) => [framework, [...BASE_SKILLS, ...(SKILLS_MANIFEST.frameworks[framework] ?? [])]]));
|
|
35
|
+
function loadSkillsManifest() {
|
|
36
|
+
const file = join(packageRoot, "skills-manifest.json");
|
|
37
|
+
const parsed = JSON.parse(readFileSync(file, "utf8"));
|
|
38
|
+
const isNameList = (value) => Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
39
|
+
// Only base is required. A framework with no skills of its own may be left
|
|
40
|
+
// out; a key that names no framework is a typo and is refused.
|
|
41
|
+
const frameworks = parsed.frameworks ?? {};
|
|
42
|
+
const frameworksValid = typeof frameworks === "object" &&
|
|
43
|
+
!Array.isArray(frameworks) &&
|
|
44
|
+
Object.entries(frameworks).every(([framework, skills]) => FRAMEWORKS.includes(framework) && isNameList(skills));
|
|
45
|
+
if (parsed.schemaVersion !== 1 || !isNameList(parsed.base) || !frameworksValid) {
|
|
46
|
+
throw new Error(`Invalid skills manifest at ${file}: expected schemaVersion 1, a base skill array, and optional skill arrays keyed by framework (${FRAMEWORKS.join(", ")}).`);
|
|
47
|
+
}
|
|
48
|
+
return { ...parsed, frameworks };
|
|
49
|
+
}
|
|
50
|
+
const DOCS_SKILL = "raybase-docs-writing";
|
|
51
|
+
const GUIDE_SKILL = "raybase-guide";
|
|
52
|
+
const API_SKILL = "raybase-api";
|
|
53
|
+
// Skills provenance lock. Stamped by every install/sync so `raybase doctor`
|
|
54
|
+
// can compare what was installed against the CLI's bundled snapshot, and so
|
|
55
|
+
// sync can prune skills it installed without touching user-authored ones.
|
|
56
|
+
// Declared before program.parse below: the create command runs during module
|
|
57
|
+
// evaluation, so later top-level consts would still be in their TDZ.
|
|
58
|
+
const SKILLS_LOCK_FILE = ".raybase/skills.json";
|
|
59
|
+
// Where a project created with --starter records what it was created from:
|
|
60
|
+
// the source as given, the GitHub commit or the integrity it resolved to, and
|
|
61
|
+
// the skills the starter brought. Same footing as .raybase/kits.json.
|
|
62
|
+
const STARTER_LOCK_FILE = ".raybase/starter.json";
|
|
63
|
+
// The Raybase version a starter's `raybase` range is checked against at
|
|
64
|
+
// create time. create-raybase and the raybase CLI release together.
|
|
65
|
+
const CREATE_RAYBASE_VERSION = JSON.parse(readFileSync(join(packageRoot, "package.json"), "utf8")).version;
|
|
66
|
+
const FIRST_PARTY_MODULES = ["docs", "guide", "api"];
|
|
67
|
+
const noKeptFiles = new Set();
|
|
68
|
+
const DEFAULT_MODULES = ["docs", "guide"];
|
|
69
|
+
const ASTRO_EMDASH_SITE_DOCS_FILES = [
|
|
70
|
+
"site/source.config.ts",
|
|
71
|
+
"site/content/docs/index.mdx",
|
|
72
|
+
"site/content/docs/getting-started.mdx",
|
|
73
|
+
"site/content/docs/mcp.mdx",
|
|
74
|
+
"site/content/docs/meta.json",
|
|
75
|
+
"site/src/docs/docs-assets.ts",
|
|
76
|
+
"site/src/docs/docs-client.tsx",
|
|
77
|
+
"site/src/docs/docs-data.ts",
|
|
78
|
+
"site/src/docs/docs-handler.tsx",
|
|
79
|
+
"site/src/docs/docs-layout.tsx",
|
|
80
|
+
"site/src/docs/docs-mdx.tsx",
|
|
81
|
+
"site/src/docs/docs-page-actions.tsx",
|
|
82
|
+
"site/src/docs/docs-page.tsx",
|
|
83
|
+
"site/src/docs/llm-text.ts",
|
|
84
|
+
"site/src/docs/source.ts",
|
|
85
|
+
"site/src/pages/docs/[...slug].ts",
|
|
86
|
+
"site/src/pages/docs/api/markdown.ts",
|
|
87
|
+
"site/src/pages/docs/api/search.ts",
|
|
88
|
+
"site/src/pages/llms.txt.ts",
|
|
89
|
+
"site/src/styles-docs.css"
|
|
90
|
+
];
|
|
91
|
+
const MODULE_FILES = {
|
|
92
|
+
docs: {
|
|
93
|
+
"tanstack-start": [
|
|
94
|
+
"source.config.ts",
|
|
95
|
+
"content/docs/index.mdx",
|
|
96
|
+
"content/docs/getting-started.mdx",
|
|
97
|
+
"content/docs/mcp.mdx",
|
|
98
|
+
"content/docs/meta.json",
|
|
99
|
+
"src/docs/docs-assets.ts",
|
|
100
|
+
"src/docs/docs-client.tsx",
|
|
101
|
+
"src/docs/docs-data.ts",
|
|
102
|
+
"src/docs/docs-handler.tsx",
|
|
103
|
+
"src/docs/docs-layout.tsx",
|
|
104
|
+
"src/docs/docs-mdx.tsx",
|
|
105
|
+
"src/docs/docs-page-actions.tsx",
|
|
106
|
+
"src/docs/docs-page.tsx",
|
|
107
|
+
"src/docs/llm-text.ts",
|
|
108
|
+
"src/docs/source.ts",
|
|
109
|
+
"src/styles-docs.css",
|
|
110
|
+
"src/routes/docs.index.tsx",
|
|
111
|
+
"src/routes/docs.tsx",
|
|
112
|
+
"src/routes/docs/$.tsx",
|
|
113
|
+
"src/routes/docs/api/markdown.ts",
|
|
114
|
+
"src/routes/docs/api/search.ts"
|
|
115
|
+
],
|
|
116
|
+
"react-router": [
|
|
117
|
+
"source.config.ts",
|
|
118
|
+
"content/docs/index.mdx",
|
|
119
|
+
"content/docs/getting-started.mdx",
|
|
120
|
+
"content/docs/mcp.mdx",
|
|
121
|
+
"content/docs/meta.json",
|
|
122
|
+
"app/components/mdx.tsx",
|
|
123
|
+
"app/lib/source.ts",
|
|
124
|
+
"app/lib/layout.shared.tsx",
|
|
125
|
+
"app/routes/docs.tsx",
|
|
126
|
+
"app/routes/docs.$.tsx",
|
|
127
|
+
"app/routes/docs.api.search.ts"
|
|
128
|
+
],
|
|
129
|
+
"astro-emdash": [
|
|
130
|
+
"source.config.ts",
|
|
131
|
+
"content/docs/index.mdx",
|
|
132
|
+
"content/docs/getting-started.mdx",
|
|
133
|
+
"content/docs/mcp.mdx",
|
|
134
|
+
"content/docs/meta.json",
|
|
135
|
+
"src/docs/docs-assets.ts",
|
|
136
|
+
"src/docs/docs-client.tsx",
|
|
137
|
+
"src/docs/docs-data.ts",
|
|
138
|
+
"src/docs/docs-handler.tsx",
|
|
139
|
+
"src/docs/docs-layout.tsx",
|
|
140
|
+
"src/docs/docs-mdx.tsx",
|
|
141
|
+
"src/docs/docs-page-actions.tsx",
|
|
142
|
+
"src/docs/docs-page.tsx",
|
|
143
|
+
"src/docs/llm-text.ts",
|
|
144
|
+
"src/docs/source.ts",
|
|
145
|
+
"src/styles-docs.css",
|
|
146
|
+
"src/routes/docs.index.tsx",
|
|
147
|
+
"src/routes/docs.tsx",
|
|
148
|
+
"src/routes/docs/$.tsx",
|
|
149
|
+
"src/routes/docs/api/markdown.ts",
|
|
150
|
+
"src/routes/docs/api/search.ts"
|
|
151
|
+
]
|
|
152
|
+
},
|
|
153
|
+
guide: {
|
|
154
|
+
"tanstack-start": [
|
|
155
|
+
"src/components/guide-widget.tsx",
|
|
156
|
+
"src/guide/actions.ts",
|
|
157
|
+
"src/guide/config.ts",
|
|
158
|
+
"src/guide/corpus.ts",
|
|
159
|
+
"src/guide/corpus.gen.ts",
|
|
160
|
+
"src/guide/corpus.manifest.json",
|
|
161
|
+
"src/guide/resources.json",
|
|
162
|
+
"content/guide/capability-map.md"
|
|
163
|
+
],
|
|
164
|
+
"react-router": [
|
|
165
|
+
"app/components/guide-widget.tsx",
|
|
166
|
+
"app/guide/actions.ts",
|
|
167
|
+
"app/guide/config.ts",
|
|
168
|
+
"app/guide/corpus.ts",
|
|
169
|
+
"app/guide/corpus.gen.ts",
|
|
170
|
+
"app/guide/corpus.manifest.json",
|
|
171
|
+
"app/guide/resources.json",
|
|
172
|
+
"content/guide/capability-map.md"
|
|
173
|
+
],
|
|
174
|
+
"astro-emdash": [
|
|
175
|
+
"src/components/guide-widget.tsx",
|
|
176
|
+
"src/guide/actions.ts",
|
|
177
|
+
"src/guide/config.ts",
|
|
178
|
+
"src/guide/corpus.ts",
|
|
179
|
+
"src/guide/corpus.gen.ts",
|
|
180
|
+
"src/guide/corpus.manifest.json",
|
|
181
|
+
"src/guide/resources.json",
|
|
182
|
+
"content/guide/capability-map.md"
|
|
183
|
+
]
|
|
184
|
+
},
|
|
185
|
+
api: {
|
|
186
|
+
"tanstack-start": ["src/api/operations.ts"],
|
|
187
|
+
"react-router": ["app/api/operations.ts"],
|
|
188
|
+
"astro-emdash": ["src/api/operations.ts"]
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
const MODULE_PACKAGES = {
|
|
192
|
+
docs: "@raybase/docs",
|
|
193
|
+
guide: "@raybase/guide",
|
|
194
|
+
api: "@raybase/api"
|
|
195
|
+
};
|
|
196
|
+
const MODULE_SKILLS = {
|
|
197
|
+
docs: [DOCS_SKILL],
|
|
198
|
+
guide: [GUIDE_SKILL],
|
|
199
|
+
api: [API_SKILL]
|
|
200
|
+
};
|
|
201
|
+
const MODULE_COMMANDS = {
|
|
202
|
+
docs: [],
|
|
203
|
+
guide: ["guide enable", "guide disable", "guide index", "guide status"],
|
|
204
|
+
api: []
|
|
205
|
+
};
|
|
206
|
+
const GUIDE_DEPENDENCIES = {
|
|
207
|
+
"@assistant-ui/react": "^0.11.29",
|
|
208
|
+
"@raybase/agent-ui": RAYBASE_PACKAGE_RANGES["@raybase/agent-ui"],
|
|
209
|
+
"@raybase/guide": RAYBASE_PACKAGE_RANGES["@raybase/guide"],
|
|
210
|
+
"lucide-react": "^1.18.0"
|
|
211
|
+
};
|
|
212
|
+
function moduleFileMode(id, template, path) {
|
|
213
|
+
if (id === "docs") {
|
|
214
|
+
if (path.startsWith("content/docs/") || path.startsWith("site/content/docs/"))
|
|
215
|
+
return "editable";
|
|
216
|
+
return "copy";
|
|
217
|
+
}
|
|
218
|
+
if (id === "guide") {
|
|
219
|
+
const guideRoot = template === "react-router" ? "app/guide" : "src/guide";
|
|
220
|
+
if (path === `${guideRoot}/actions.ts` || path === `${guideRoot}/resources.json` || path === `${guideRoot}/config.ts` || path === "content/guide/capability-map.md")
|
|
221
|
+
return "editable";
|
|
222
|
+
if (path === `${guideRoot}/corpus.manifest.json`)
|
|
223
|
+
return "generated";
|
|
224
|
+
return "copy";
|
|
225
|
+
}
|
|
226
|
+
return "copy";
|
|
227
|
+
}
|
|
228
|
+
const DEFAULT_AI_CONFIG_BLOCK = ` ai: {
|
|
229
|
+
enabled: true,
|
|
230
|
+
defaults: {
|
|
231
|
+
model: "@cf/zai-org/glm-4.7-flash",
|
|
232
|
+
embeddingModel: "@cf/baai/bge-base-en-v1.5",
|
|
233
|
+
maxInputChars: 20000,
|
|
234
|
+
maxOutputTokens: 1200
|
|
235
|
+
},
|
|
236
|
+
limits: {
|
|
237
|
+
// Daily spend caps are opt-in and unlimited when unset. Set them only if
|
|
238
|
+
// your inference lane bills per token and you want a hard ceiling:
|
|
239
|
+
// perUserDailyRequests: 50,
|
|
240
|
+
// perUserDailyOutputTokens: 25000,
|
|
241
|
+
// perAppDailyRequests: 500,
|
|
242
|
+
perPublicDailyRequests: 200,
|
|
243
|
+
perPublicDailyOutputTokens: 60000,
|
|
244
|
+
maxToolCallsPerTurn: 6,
|
|
245
|
+
maxLoopStepsPerTurn: 8,
|
|
246
|
+
maxConversationMessages: 40
|
|
247
|
+
}
|
|
248
|
+
},`;
|
|
249
|
+
const AI_CONFIG_PLACEHOLDER = ` // To enable user-facing AI chat features, run \`raybase ai enable\`.
|
|
250
|
+
// ai: {
|
|
251
|
+
// enabled: true
|
|
252
|
+
// }`;
|
|
253
|
+
// Local working state that must never be copied out of a repo checkout
|
|
254
|
+
// (untracked installs, dev caches, personal credentials). Mirrored in
|
|
255
|
+
// scripts/prepare-create-raybase.mjs for the published bundle.
|
|
256
|
+
const FRAMEWORK_EXCLUDES = new Set([
|
|
257
|
+
"node_modules",
|
|
258
|
+
"package-lock.json",
|
|
259
|
+
".source",
|
|
260
|
+
".wrangler",
|
|
261
|
+
".react-router",
|
|
262
|
+
".cache",
|
|
263
|
+
".raybase",
|
|
264
|
+
"build",
|
|
265
|
+
"dist",
|
|
266
|
+
".env",
|
|
267
|
+
".dev.vars",
|
|
268
|
+
".DS_Store",
|
|
269
|
+
"pnpm-lock.yaml"
|
|
270
|
+
]);
|
|
271
|
+
const CANONICAL_SPEC_PATH = "dev/SPEC.md";
|
|
272
|
+
const PLANNING_STUB_DEV_FILES = new Set([".DS_Store", "SPEC.md", "SPEC-OVERVIEW.md"]);
|
|
273
|
+
const PLANNING_DOC_PATHS = ["dev/SPEC.md", "dev/SPEC-OVERVIEW.md"];
|
|
274
|
+
const RECOMMENDED_MODELS_URL = "https://raybase.dev/models/recommended.json";
|
|
275
|
+
const FALLBACK_RECOMMENDED_GUIDE_MODEL = "@cf/zai-org/glm-4.7-flash";
|
|
276
|
+
const program = new Command();
|
|
277
|
+
program
|
|
278
|
+
.name("create-raybase")
|
|
279
|
+
.argument("[directory]", "Project directory")
|
|
280
|
+
.option("--name <name>", "App display name")
|
|
281
|
+
.option("--framework <framework>", `Framework, created from its built-in starter: ${FRAMEWORKS.join(" | ")} (default ${DEFAULT_FRAMEWORK})`)
|
|
282
|
+
.option("--starter <source>", `Create from a starter outside Raybase: a folder, a GitHub repository (github:<owner>/<repo>[/<path>][#ref]) or a web address serving its file-manifest.json. The starter describes itself in ${STARTER_DESCRIPTION_FILE}`)
|
|
283
|
+
.option("--from <store-app>", "Verified Raybase Store app id")
|
|
284
|
+
.option("--store-registry <source>", "Store registry URL. Defaults to the hosted Raybase Store registry.")
|
|
285
|
+
.option("--offline", "Skip network checks; only valid when creating from a built-in starter or a starter folder")
|
|
286
|
+
.option("--local-packages <repoRoot>", "Resolve the built-in starters, skills, and @raybase packages from a local raybase repo checkout (or set RAYBASE_LOCAL)")
|
|
287
|
+
.option("--registry <origin>", "A registry other than the public npm registry that serves @raybase packages, written to the project's .npmrc with its read token taken from REGISTRY_READ_TOKEN")
|
|
288
|
+
.option("--skip-install", "Do not install dependencies")
|
|
289
|
+
.option("--skip-git", "Do not initialize git")
|
|
290
|
+
.option("--without <module>", "Skip a default first-party module (docs | guide)", collect, [])
|
|
291
|
+
.option("--with <module>", "Add an optional first-party module while keeping defaults (api)", collect, [])
|
|
292
|
+
.option("--only <module>", "Install only the listed first-party module(s); may repeat", collect, [])
|
|
293
|
+
.option("--bare", "Install no first-party modules")
|
|
294
|
+
.option("--refresh-skills", "Only refresh Raybase skills in the current project")
|
|
295
|
+
.option("--json", "Print machine-readable output")
|
|
296
|
+
.addHelpText("after", `\n${FRAMEWORK_HELP}`)
|
|
297
|
+
.action(async (directory, options) => {
|
|
298
|
+
try {
|
|
299
|
+
await createRaybaseProject(directory === undefined ? undefined : String(directory), options);
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
302
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
303
|
+
process.exit(1);
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
307
|
+
program.parse(process.argv);
|
|
308
|
+
}
|
|
309
|
+
export async function createRaybaseProject(directory, options) {
|
|
310
|
+
const cwd = process.cwd();
|
|
311
|
+
if (options.starter && options.from) {
|
|
312
|
+
throw new Error("--starter and --from cannot be combined: a Store app is built on a framework's built-in starter.");
|
|
313
|
+
}
|
|
314
|
+
if (options.starter && options.refreshSkills)
|
|
315
|
+
throw new Error("--starter creates a project; --refresh-skills refreshes the current one. Pass one of them.");
|
|
316
|
+
const storeApp = options.from && !options.refreshSkills ? await resolveStoreApp(options.from, { registry: options.storeRegistry, offline: Boolean(options.offline) }) : null;
|
|
317
|
+
let starter = null;
|
|
318
|
+
try {
|
|
319
|
+
if (options.starter) {
|
|
320
|
+
starter = await resolveStarterSource(options.starter, { cwd, offline: Boolean(options.offline) });
|
|
321
|
+
const declared = starter.description.framework;
|
|
322
|
+
if (options.framework !== undefined && options.framework !== declared) {
|
|
323
|
+
throw new Error(`The starter "${starter.description.name}" is built on the ${declared} framework (its ${STARTER_DESCRIPTION_FILE}), but --framework ${options.framework} was passed. Drop --framework, or pass --framework ${declared}.`);
|
|
324
|
+
}
|
|
325
|
+
const rangeProblem = starterRangeProblem(starter.description, CREATE_RAYBASE_VERSION);
|
|
326
|
+
if (rangeProblem) {
|
|
327
|
+
throw new Error(`${rangeProblem} Use a version of the starter made for Raybase ${CREATE_RAYBASE_VERSION}, or a create-raybase inside the starter's range.`);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if (storeApp && options.framework && options.framework !== DEFAULT_FRAMEWORK && options.framework !== storeApp.manifest.baseFramework) {
|
|
331
|
+
throw new Error(`Store app ${storeApp.id} is built on the ${storeApp.manifest.baseFramework} framework; do not pass --framework with --from.`);
|
|
332
|
+
}
|
|
333
|
+
if (storeApp && (options.bare || options.without?.length || options.with?.length || options.only?.length)) {
|
|
334
|
+
throw new Error("--bare, --without, --with, and --only are not supported with whole-app Store apps in v1.");
|
|
335
|
+
}
|
|
336
|
+
const projectDirectory = directory ?? storeApp?.id ?? "raybase-app";
|
|
337
|
+
const projectDir = options.refreshSkills ? cwd : resolve(cwd, projectDirectory);
|
|
338
|
+
// basename (not the raw argument) so scaffolding in place (".") names the
|
|
339
|
+
// project after the folder the user already made for it.
|
|
340
|
+
const projectName = basename(projectDir);
|
|
341
|
+
const appName = options.name ?? storeApp?.manifest.install.appNameSuggestion ?? humanize(projectName);
|
|
342
|
+
// Same derivation as the letter-mark favicon in the template's __root.tsx.
|
|
343
|
+
const appInitial = appName.trim().charAt(0).toUpperCase().replace(/[^A-Z0-9]/, "") || "A";
|
|
344
|
+
const localRoot = resolveLocalRoot(options.localPackages ?? process.env.RAYBASE_LOCAL) ?? sourceCheckoutRoot();
|
|
345
|
+
const template = options.refreshSkills
|
|
346
|
+
? detectFramework(projectDir)
|
|
347
|
+
: starter?.description.framework ?? storeApp?.manifest.baseFramework ?? parseFramework(options.framework);
|
|
348
|
+
// The tree the project is copied from: the starter, or the framework's built-in starter.
|
|
349
|
+
const sourceDir = starter ? starter.root : options.refreshSkills ? null : frameworkSourceDir(template, localRoot);
|
|
350
|
+
const selectedModules = options.refreshSkills ? detectInstalledModules(projectDir) : storeApp ? modulesForStoreApp(storeApp) : resolveSelectedModules(options);
|
|
351
|
+
const docsEnabled = selectedModules.has("docs");
|
|
352
|
+
const guideEnabled = selectedModules.has("guide");
|
|
353
|
+
const apiEnabled = selectedModules.has("api");
|
|
354
|
+
const guideAiModel = guideEnabled && !options.refreshSkills
|
|
355
|
+
? await resolveRecommendedGuideAiModel({ offline: Boolean(options.offline), localRoot })
|
|
356
|
+
: null;
|
|
357
|
+
assertNode();
|
|
358
|
+
assertFreshLocalBuild(localRoot);
|
|
359
|
+
if (sourceDir)
|
|
360
|
+
assertStarterNode(sourceDir, starter?.description.name ?? template);
|
|
361
|
+
if (!options.skipInstall && !options.offline)
|
|
362
|
+
await checkNetwork();
|
|
363
|
+
if (!options.refreshSkills) {
|
|
364
|
+
// Pre-created workspace folders commonly hold agent skills the user wired
|
|
365
|
+
// up, .git, local env/scratch files, a playground BUILD-LOG.md, or a dev/
|
|
366
|
+
// planning dir already — treat those as empty rather than forcing a
|
|
367
|
+
// nested scaffold.
|
|
368
|
+
const scaffoldSafeEntries = new Set([".agents", ".claude", ".git", ".DS_Store", ".env", "tmp", "BUILD-LOG.md"]);
|
|
369
|
+
const blockingEntries = existsSync(projectDir)
|
|
370
|
+
? readdirSync(projectDir).filter((entry) => !scaffoldSafeEntries.has(entry) && !(entry === "dev" && isScaffoldSafeDevDir(projectDir, sourceDir)))
|
|
371
|
+
: [];
|
|
372
|
+
if (blockingEntries.length > 0) {
|
|
373
|
+
throw new Error(`${projectDir} already exists and is not empty (found: ${blockingEntries.slice(0, 5).join(", ")}).`);
|
|
374
|
+
}
|
|
375
|
+
const preservedPlanningDocs = readPlanningDocs(projectDir);
|
|
376
|
+
mkdirSync(projectDir, { recursive: true });
|
|
377
|
+
if (starter) {
|
|
378
|
+
copyStarterTree(starter, projectDir);
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
cpSync(sourceDir, projectDir, {
|
|
382
|
+
recursive: true,
|
|
383
|
+
filter: (source) => !FRAMEWORK_EXCLUDES.has(source.split("/").pop() ?? "")
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
restoreGitignores(projectDir);
|
|
387
|
+
if (starter?.description.spec)
|
|
388
|
+
writeStarterSpec(starter, projectDir);
|
|
389
|
+
replacePlaceholders(projectDir, {
|
|
390
|
+
__APP_NAME__: appName,
|
|
391
|
+
__APP_INITIAL__: appInitial,
|
|
392
|
+
__PACKAGE_NAME__: slugify(projectName)
|
|
393
|
+
});
|
|
394
|
+
restorePlanningDocs(projectDir, preservedPlanningDocs);
|
|
395
|
+
normalizeRaybaseDeps(projectDir, localRoot);
|
|
396
|
+
const docsPlacement = resolveDocsPlacement(projectDir, template, docsEnabled);
|
|
397
|
+
// Module files the starter supplies itself are kept, not laid over.
|
|
398
|
+
const keptModuleFiles = new Set(starter?.description.moduleFiles ?? []);
|
|
399
|
+
for (const file of keptModuleFiles) {
|
|
400
|
+
if (!existsSync(join(projectDir, file)))
|
|
401
|
+
throw new Error(`The starter "${starter.description.name}" lists ${file} in moduleFiles (its ${STARTER_DESCRIPTION_FILE}) but does not contain it.`);
|
|
402
|
+
}
|
|
403
|
+
configureDocs(projectDir, template, docsEnabled, docsPlacement, localRoot, keptModuleFiles);
|
|
404
|
+
configureGuide(projectDir, template, guideEnabled, docsEnabled, localRoot, keptModuleFiles);
|
|
405
|
+
configureApi(projectDir, template, apiEnabled, localRoot, keptModuleFiles);
|
|
406
|
+
if (guideAiModel)
|
|
407
|
+
configureAiDefaultModel(projectDir, template, guideAiModel);
|
|
408
|
+
if (storeApp) {
|
|
409
|
+
applyStoreAppOverlay(projectDir, storeApp, localRoot);
|
|
410
|
+
ensureAgentInstructions(projectDir, template, docsEnabled, guideEnabled, apiEnabled);
|
|
411
|
+
assertSafeProjectFiles(projectDir);
|
|
412
|
+
replacePlaceholders(projectDir, {
|
|
413
|
+
__APP_NAME__: appName,
|
|
414
|
+
__APP_INITIAL__: appInitial,
|
|
415
|
+
__PACKAGE_NAME__: slugify(projectName)
|
|
416
|
+
});
|
|
417
|
+
restorePlanningDocs(projectDir, preservedPlanningDocs);
|
|
418
|
+
normalizeRaybaseDeps(projectDir, localRoot);
|
|
419
|
+
if (guideAiModel)
|
|
420
|
+
configureAiDefaultModel(projectDir, template, guideAiModel);
|
|
421
|
+
}
|
|
422
|
+
applyAppleTouchIcon(projectDir, appInitial);
|
|
423
|
+
ensureDevVars(projectDir, template, guideEnabled, apiEnabled);
|
|
424
|
+
if (starter)
|
|
425
|
+
appendStarterDevVars(projectDir, starter.description);
|
|
426
|
+
recordScaffoldedModules(projectDir, template, selectedModules, docsPlacement, keptModuleFiles);
|
|
427
|
+
}
|
|
428
|
+
const appId = ensureAppId(projectDir);
|
|
429
|
+
installSkills(projectDir, template, localRoot, docsEnabled, guideEnabled, apiEnabled);
|
|
430
|
+
const starterSkills = starter ? installStarterSkills(projectDir, starter) : {};
|
|
431
|
+
ensureAgentInstructions(projectDir, template, docsEnabled, guideEnabled, apiEnabled);
|
|
432
|
+
if (starter?.description.agentInstructions) {
|
|
433
|
+
mergeStarterAgentInstructions(projectDir, starter, { __APP_NAME__: appName, __APP_INITIAL__: appInitial, __PACKAGE_NAME__: slugify(projectName) });
|
|
434
|
+
}
|
|
435
|
+
ensureSpec(projectDir, appName, template);
|
|
436
|
+
if (starter)
|
|
437
|
+
writeStarterLock(projectDir, starter, starterSkills);
|
|
438
|
+
// Published @raybase packages are served by a private registry, not npm; a
|
|
439
|
+
// scaffold without this mapping cannot install its own dependencies.
|
|
440
|
+
// Raybase's packages are on the public npm registry, which needs no .npmrc.
|
|
441
|
+
if (!options.refreshSkills && !localRoot && options.registry)
|
|
442
|
+
writeRegistryNpmrc(projectDir, options.registry);
|
|
443
|
+
if (!options.refreshSkills && !options.skipInstall) {
|
|
444
|
+
const install = installCommand(projectDir);
|
|
445
|
+
run(install.command, install.args, projectDir);
|
|
446
|
+
}
|
|
447
|
+
if (!options.refreshSkills && !options.skipGit) {
|
|
448
|
+
initGit(projectDir);
|
|
449
|
+
}
|
|
450
|
+
const result = {
|
|
451
|
+
ok: true,
|
|
452
|
+
projectDir,
|
|
453
|
+
appName,
|
|
454
|
+
appId,
|
|
455
|
+
framework: template,
|
|
456
|
+
storeApp: storeApp
|
|
457
|
+
? {
|
|
458
|
+
id: storeApp.manifest.id,
|
|
459
|
+
version: storeApp.manifest.version,
|
|
460
|
+
provenance: join(projectDir, ".raybase/store-app.json")
|
|
461
|
+
}
|
|
462
|
+
: undefined,
|
|
463
|
+
starter: starter
|
|
464
|
+
? {
|
|
465
|
+
name: starter.description.name,
|
|
466
|
+
source: starter.source.type,
|
|
467
|
+
resolvedRef: starter.source.resolvedRef ?? undefined,
|
|
468
|
+
integrity: starter.source.integrity,
|
|
469
|
+
provenance: join(projectDir, STARTER_LOCK_FILE)
|
|
470
|
+
}
|
|
471
|
+
: undefined,
|
|
472
|
+
docs: docsEnabled,
|
|
473
|
+
guide: guideEnabled,
|
|
474
|
+
api: apiEnabled,
|
|
475
|
+
localPackages: localRoot ?? undefined,
|
|
476
|
+
next: withStarterNextSteps(nextSteps(projectDir, template, docsEnabled, guideEnabled, apiEnabled, storeApp), starter)
|
|
477
|
+
};
|
|
478
|
+
if (options.json) {
|
|
479
|
+
console.log(JSON.stringify(result, null, 2));
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
console.log("RAYBASE_NEXT_STEPS_START");
|
|
483
|
+
console.log(JSON.stringify(result, null, 2));
|
|
484
|
+
console.log("RAYBASE_NEXT_STEPS_END");
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
finally {
|
|
488
|
+
storeApp?.cleanup();
|
|
489
|
+
starter?.cleanup();
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
// Same mapping as Pro's scaffolder (create-raybase-pro): the scope points at
|
|
493
|
+
// the registry and the read token comes from the environment, never the file.
|
|
494
|
+
function writeRegistryNpmrc(projectDir, origin) {
|
|
495
|
+
const registry = new URL(origin);
|
|
496
|
+
const file = join(projectDir, ".npmrc");
|
|
497
|
+
const existing = existsSync(file) ? readFileSync(file, "utf8") : "";
|
|
498
|
+
if (/^@raybase:registry=/m.test(existing))
|
|
499
|
+
return;
|
|
500
|
+
const lines = [`@raybase:registry=${registry.origin}/`, `//${registry.host}/:_authToken=\${REGISTRY_READ_TOKEN}`];
|
|
501
|
+
writeFileSync(file, `${existing}${existing && !existing.endsWith("\n") ? "\n" : ""}${lines.join("\n")}\n`);
|
|
502
|
+
}
|
|
503
|
+
// The published bundle carries each .gitignore as `gitignore`, because npm
|
|
504
|
+
// never packs .gitignore (scripts/prepare-create-raybase.mjs). Without the
|
|
505
|
+
// rename, the scaffold's first commit would take .dev.vars and .env.
|
|
506
|
+
function restoreGitignores(directory) {
|
|
507
|
+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
508
|
+
if (entry.name === "node_modules")
|
|
509
|
+
continue;
|
|
510
|
+
const path = join(directory, entry.name);
|
|
511
|
+
if (entry.isDirectory())
|
|
512
|
+
restoreGitignores(path);
|
|
513
|
+
else if (entry.name === "gitignore" && !existsSync(join(directory, ".gitignore")))
|
|
514
|
+
renameSync(path, join(directory, ".gitignore"));
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
function collect(value, previous) {
|
|
518
|
+
return [...previous, value];
|
|
519
|
+
}
|
|
520
|
+
function parseFramework(value) {
|
|
521
|
+
const framework = value ?? DEFAULT_FRAMEWORK;
|
|
522
|
+
if (!FRAMEWORKS.includes(framework)) {
|
|
523
|
+
throw new Error(`Unknown framework "${framework}". Valid frameworks: ${FRAMEWORKS.join(", ")}.`);
|
|
524
|
+
}
|
|
525
|
+
return framework;
|
|
526
|
+
}
|
|
527
|
+
function detectFramework(projectDir) {
|
|
528
|
+
const file = join(projectDir, "package.json");
|
|
529
|
+
if (!existsSync(file))
|
|
530
|
+
throw new Error(`No package.json in ${projectDir}. Run --refresh-skills from a Raybase project root.`);
|
|
531
|
+
let declared;
|
|
532
|
+
try {
|
|
533
|
+
declared = JSON.parse(readFileSync(file, "utf8")).raybase?.framework;
|
|
534
|
+
}
|
|
535
|
+
catch (error) {
|
|
536
|
+
throw new Error(`package.json in ${projectDir} could not be parsed: ${error instanceof Error ? error.message : String(error)}`);
|
|
537
|
+
}
|
|
538
|
+
if (declared === undefined || declared === null || declared === "") {
|
|
539
|
+
throw new Error(`package.json has no raybase.framework. Set it to one of: ${FRAMEWORKS.join(", ")}.`);
|
|
540
|
+
}
|
|
541
|
+
if (!FRAMEWORKS.includes(declared)) {
|
|
542
|
+
throw new Error(`package.json raybase.framework is ${JSON.stringify(declared)}, which is not a Raybase framework. Use one of: ${FRAMEWORKS.join(", ")}.`);
|
|
543
|
+
}
|
|
544
|
+
return declared;
|
|
545
|
+
}
|
|
546
|
+
function detectInstalledModules(projectDir) {
|
|
547
|
+
const lockFile = join(projectDir, ".raybase/modules.json");
|
|
548
|
+
if (existsSync(lockFile)) {
|
|
549
|
+
const parsed = JSON.parse(readFileSync(lockFile, "utf8"));
|
|
550
|
+
if (Number(parsed.schemaVersion) > 1)
|
|
551
|
+
throw new Error(".raybase/modules.json schemaVersion is newer than this create-raybase. Upgrade @raybase/create.");
|
|
552
|
+
if (parsed.schemaVersion !== 1 || !parsed.modules || typeof parsed.modules !== "object") {
|
|
553
|
+
throw new Error(".raybase/modules.json is not a valid Raybase Modules lock file.");
|
|
554
|
+
}
|
|
555
|
+
return new Set(FIRST_PARTY_MODULES.filter((module) => parsed.modules?.[module]?.enabled === true));
|
|
556
|
+
}
|
|
557
|
+
const file = join(projectDir, "package.json");
|
|
558
|
+
if (!existsSync(file))
|
|
559
|
+
return new Set(DEFAULT_MODULES);
|
|
560
|
+
try {
|
|
561
|
+
const parsed = JSON.parse(readFileSync(file, "utf8"));
|
|
562
|
+
const modules = parsed.raybase?.modules;
|
|
563
|
+
if (!modules)
|
|
564
|
+
return new Set(DEFAULT_MODULES);
|
|
565
|
+
return new Set(FIRST_PARTY_MODULES.filter((module) => modules[module]?.enabled === true));
|
|
566
|
+
}
|
|
567
|
+
catch {
|
|
568
|
+
return new Set(DEFAULT_MODULES);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
function resolveSelectedModules(options) {
|
|
572
|
+
const without = options.without ?? [];
|
|
573
|
+
const withModules = options.with ?? [];
|
|
574
|
+
const only = options.only ?? [];
|
|
575
|
+
if (options.bare && (without.length || withModules.length || only.length)) {
|
|
576
|
+
throw new Error("--bare cannot be combined with --without, --with, or --only. Use --bare by itself for a platform-only app.");
|
|
577
|
+
}
|
|
578
|
+
if (only.length && (without.length || withModules.length))
|
|
579
|
+
throw new Error("--only cannot be combined with --without or --with.");
|
|
580
|
+
const unknown = [...without, ...withModules, ...only].filter((module) => !FIRST_PARTY_MODULES.includes(module));
|
|
581
|
+
if (unknown.length)
|
|
582
|
+
throw new Error(`Unknown module "${unknown[0]}". Available first-party modules: ${FIRST_PARTY_MODULES.join(", ")}.`);
|
|
583
|
+
if (options.bare)
|
|
584
|
+
return new Set();
|
|
585
|
+
if (only.length)
|
|
586
|
+
return new Set(only);
|
|
587
|
+
const selected = new Set(DEFAULT_MODULES);
|
|
588
|
+
for (const module of without)
|
|
589
|
+
selected.delete(module);
|
|
590
|
+
for (const module of withModules)
|
|
591
|
+
selected.add(module);
|
|
592
|
+
return selected;
|
|
593
|
+
}
|
|
594
|
+
function modulesForStoreApp(storeApp) {
|
|
595
|
+
const modules = new Set();
|
|
596
|
+
if (storeApp.manifest.modules?.docs?.enabled === true)
|
|
597
|
+
modules.add("docs");
|
|
598
|
+
if (storeApp.manifest.modules?.guide?.enabled === true)
|
|
599
|
+
modules.add("guide");
|
|
600
|
+
if (storeApp.manifest.modules?.api?.enabled === true)
|
|
601
|
+
modules.add("api");
|
|
602
|
+
return modules;
|
|
603
|
+
}
|
|
604
|
+
function resolveDocsPlacement(projectDir, template, docsEnabled) {
|
|
605
|
+
if (!docsEnabled)
|
|
606
|
+
return "spine";
|
|
607
|
+
if (template !== "astro-emdash")
|
|
608
|
+
return "spine";
|
|
609
|
+
const spec = readSpecPublicDocumentation(projectDir);
|
|
610
|
+
return spec.documentation === "public docs on the public site" && spec.docsExposure === "public" ? "site" : "spine";
|
|
611
|
+
}
|
|
612
|
+
function readSpecPublicDocumentation(projectDir) {
|
|
613
|
+
const file = join(projectDir, CANONICAL_SPEC_PATH);
|
|
614
|
+
if (!existsSync(file))
|
|
615
|
+
return {};
|
|
616
|
+
const source = readFileSync(file, "utf8");
|
|
617
|
+
return {
|
|
618
|
+
publicSurface: specLine(source, "Public surface"),
|
|
619
|
+
documentation: specLine(source, "Documentation"),
|
|
620
|
+
docsExposure: specLine(source, "Docs exposure")
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
function specLine(source, label) {
|
|
624
|
+
const match = source.match(new RegExp(`^${escapeRegExp(label)}:\\s*(.+?)\\s*$`, "mi"));
|
|
625
|
+
return match?.[1]?.trim();
|
|
626
|
+
}
|
|
627
|
+
function frameworkSourceDir(template, localRoot) {
|
|
628
|
+
if (localRoot) {
|
|
629
|
+
const source = join(localRoot, FRAMEWORK_SOURCE_DIRS[template]);
|
|
630
|
+
if (!existsSync(source))
|
|
631
|
+
throw new Error(`Built-in starter ${source} not found in the local raybase repo.`);
|
|
632
|
+
return source;
|
|
633
|
+
}
|
|
634
|
+
const bundled = join(packageRoot, "templates", template);
|
|
635
|
+
if (existsSync(bundled))
|
|
636
|
+
return bundled;
|
|
637
|
+
throw new Error(`Bundled starter for "${template}" is missing. Reinstall create-raybase or pass --local-packages.`);
|
|
638
|
+
}
|
|
639
|
+
// iOS home-screen icons must be PNG, so the letter can't be substituted into
|
|
640
|
+
// them like the SVG icons. Instead a pre-baked tile matching the app initial
|
|
641
|
+
// (assets/apple-touch-icons, regenerated by scripts/bake-apple-touch-icons.mjs)
|
|
642
|
+
// replaces the template's stock placeholder.
|
|
643
|
+
function applyAppleTouchIcon(projectDir, appInitial) {
|
|
644
|
+
const target = join(projectDir, "public/icons/apple-touch-icon.png");
|
|
645
|
+
if (!existsSync(target))
|
|
646
|
+
return;
|
|
647
|
+
const tiles = join(packageRoot, "assets/apple-touch-icons");
|
|
648
|
+
const tile = join(tiles, `${appInitial}.png`);
|
|
649
|
+
const stockTile = join(tiles, "default.png");
|
|
650
|
+
if (!existsSync(tile) || !existsSync(stockTile))
|
|
651
|
+
return;
|
|
652
|
+
// A store-app overlay may ship branded icons; only replace the stock tile.
|
|
653
|
+
if (!readFileSync(target).equals(readFileSync(stockTile)))
|
|
654
|
+
return;
|
|
655
|
+
cpSync(tile, target);
|
|
656
|
+
}
|
|
657
|
+
// A pre-existing dev/ planning dir is scaffold-safe when merging the template
|
|
658
|
+
// into it cannot clobber anything: entries colliding with the built-in starter's
|
|
659
|
+
// dev/ payload block the scaffold, except the SPEC docs that
|
|
660
|
+
// readPlanningDocs/restorePlanningDocs round-trip.
|
|
661
|
+
function isScaffoldSafeDevDir(projectDir, sourceDir) {
|
|
662
|
+
const devDir = join(projectDir, "dev");
|
|
663
|
+
if (!existsSync(devDir) || !statSync(devDir).isDirectory())
|
|
664
|
+
return false;
|
|
665
|
+
const templateDevDir = join(sourceDir, "dev");
|
|
666
|
+
const templateEntries = new Set(existsSync(templateDevDir) ? readdirSync(templateDevDir) : []);
|
|
667
|
+
for (const preserved of PLANNING_STUB_DEV_FILES)
|
|
668
|
+
templateEntries.delete(preserved);
|
|
669
|
+
return readdirSync(devDir).every((entry) => !templateEntries.has(entry));
|
|
670
|
+
}
|
|
671
|
+
function readPlanningDocs(projectDir) {
|
|
672
|
+
const docs = new Map();
|
|
673
|
+
for (const relativePath of PLANNING_DOC_PATHS) {
|
|
674
|
+
const file = join(projectDir, relativePath);
|
|
675
|
+
if (existsSync(file) && statSync(file).isFile()) {
|
|
676
|
+
docs.set(relativePath, readFileSync(file, "utf8"));
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
return docs;
|
|
680
|
+
}
|
|
681
|
+
function restorePlanningDocs(projectDir, docs) {
|
|
682
|
+
for (const [relativePath, contents] of docs) {
|
|
683
|
+
const file = join(projectDir, relativePath);
|
|
684
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
685
|
+
writeFileSync(file, contents);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
function resolveLocalRoot(value) {
|
|
689
|
+
if (!value)
|
|
690
|
+
return null;
|
|
691
|
+
const root = resolve(value);
|
|
692
|
+
assertLocalRoot(root, "--local-packages");
|
|
693
|
+
return root;
|
|
694
|
+
}
|
|
695
|
+
function sourceCheckoutRoot() {
|
|
696
|
+
const root = resolve(packageRoot, "../..");
|
|
697
|
+
if (!existsSync(join(root, "packages/create-raybase/src/index.ts")))
|
|
698
|
+
return null;
|
|
699
|
+
for (const source of Object.values(FRAMEWORK_SOURCE_DIRS)) {
|
|
700
|
+
if (!existsSync(join(root, source)))
|
|
701
|
+
return null;
|
|
702
|
+
}
|
|
703
|
+
try {
|
|
704
|
+
assertLocalRoot(root, "auto-detected source checkout");
|
|
705
|
+
}
|
|
706
|
+
catch {
|
|
707
|
+
return null;
|
|
708
|
+
}
|
|
709
|
+
return root;
|
|
710
|
+
}
|
|
711
|
+
function assertLocalRoot(root, label) {
|
|
712
|
+
for (const probe of [
|
|
713
|
+
"packages/core/package.json",
|
|
714
|
+
"packages/docs/package.json",
|
|
715
|
+
"packages/guide/package.json",
|
|
716
|
+
"packages/api/package.json",
|
|
717
|
+
"packages/agent-ui/package.json",
|
|
718
|
+
"packages/cli/package.json",
|
|
719
|
+
"skills/raybase-building"
|
|
720
|
+
]) {
|
|
721
|
+
if (!existsSync(join(root, probe))) {
|
|
722
|
+
throw new Error(`${label}: ${root} does not look like a raybase repo checkout (missing ${probe}).`);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
// link: deps resolve their own dependencies through the repo's install.
|
|
726
|
+
if (!existsSync(join(root, "node_modules"))) {
|
|
727
|
+
throw new Error(`${label}: run \`pnpm install\` in ${root} first (linked packages resolve their dependencies through the repo's node_modules).`);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
// In local mode the built-in starters and skills are read straight from the repo, so
|
|
731
|
+
// they cannot go stale — but the running dist/index.js can. Fail loudly when
|
|
732
|
+
// the repo source no longer matches the build being executed. The comparison
|
|
733
|
+
// is content-based: the build stamps a source-tree signature into
|
|
734
|
+
// dist/.source-hash, because git operations from concurrent checkouts refresh
|
|
735
|
+
// src mtimes without changing content, so an mtime guard false-positives
|
|
736
|
+
// right after a clean build.
|
|
737
|
+
function assertFreshLocalBuild(localRoot) {
|
|
738
|
+
if (!localRoot || process.env.RAYBASE_LOCAL_ALLOW_STALE === "1")
|
|
739
|
+
return;
|
|
740
|
+
const distFile = fileURLToPath(import.meta.url);
|
|
741
|
+
const srcDir = join(localRoot, "packages/create-raybase/src");
|
|
742
|
+
if (!distFile.startsWith(localRoot) || !existsSync(srcDir))
|
|
743
|
+
return;
|
|
744
|
+
const stampFile = join(dirname(distFile), ".source-hash");
|
|
745
|
+
if (existsSync(stampFile)) {
|
|
746
|
+
if (readFileSync(stampFile, "utf8").trim() !== hashSourceTree(srcDir)) {
|
|
747
|
+
throw new Error("create-raybase source differs from the build you are running. Run `pnpm build` in the raybase repo first (or set RAYBASE_LOCAL_ALLOW_STALE=1).");
|
|
748
|
+
}
|
|
749
|
+
return;
|
|
750
|
+
}
|
|
751
|
+
// Builds that predate stamping (or a bare tsc run): mtimes are all we have.
|
|
752
|
+
const srcFile = join(srcDir, "index.ts");
|
|
753
|
+
if (existsSync(srcFile) && statSync(srcFile).mtimeMs > statSync(distFile).mtimeMs) {
|
|
754
|
+
throw new Error("create-raybase source is newer than the build you are running. Run `pnpm build` in the raybase repo first (or set RAYBASE_LOCAL_ALLOW_STALE=1).");
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
// Built-in starters may carry repo-relative file: deps (so in-place starter
|
|
758
|
+
// development inside the raybase repo keeps working). Scaffolded projects get
|
|
759
|
+
// them normalized: absolute link: paths in local mode, published semver
|
|
760
|
+
// otherwise, so dependency installation works wherever the project lives.
|
|
761
|
+
// link:, not file:, for local mode — pnpm copies file: deps into its store,
|
|
762
|
+
// which both freezes core edits out of the project and tries to resolve the
|
|
763
|
+
// cli's `@raybase/core@workspace:*` outside a workspace (install error).
|
|
764
|
+
// link: symlinks into the repo, whose own node_modules satisfies everything.
|
|
765
|
+
function normalizeRaybaseDeps(projectDir, localRoot) {
|
|
766
|
+
normalizePackageRaybaseDeps(join(projectDir, "package.json"), localRoot);
|
|
767
|
+
const sitePackage = join(projectDir, "site", "package.json");
|
|
768
|
+
if (existsSync(sitePackage))
|
|
769
|
+
normalizePackageRaybaseDeps(sitePackage, localRoot);
|
|
770
|
+
}
|
|
771
|
+
function normalizePackageRaybaseDeps(file, localRoot) {
|
|
772
|
+
const parsed = JSON.parse(readFileSync(file, "utf8"));
|
|
773
|
+
const sources = localRoot
|
|
774
|
+
? {
|
|
775
|
+
"@raybase/agent-ui": `link:${join(localRoot, "packages/agent-ui")}`,
|
|
776
|
+
"@raybase/core": `link:${join(localRoot, "packages/core")}`,
|
|
777
|
+
"@raybase/emdash": `link:${join(localRoot, "packages/emdash")}`,
|
|
778
|
+
"@raybase/galley": localGalleyPackageRange(localRoot),
|
|
779
|
+
"@raybase/docs": `link:${join(localRoot, "packages/docs")}`,
|
|
780
|
+
"@raybase/guide": `link:${join(localRoot, "packages/guide")}`,
|
|
781
|
+
"@raybase/api": `link:${join(localRoot, "packages/api")}`,
|
|
782
|
+
"@raybase/cli": `link:${join(localRoot, "packages/cli")}`
|
|
783
|
+
}
|
|
784
|
+
: {
|
|
785
|
+
...RAYBASE_PACKAGE_RANGES
|
|
786
|
+
};
|
|
787
|
+
let changed = false;
|
|
788
|
+
for (const section of ["dependencies", "devDependencies"]) {
|
|
789
|
+
const deps = parsed[section];
|
|
790
|
+
if (!deps)
|
|
791
|
+
continue;
|
|
792
|
+
for (const [name, source] of Object.entries(sources)) {
|
|
793
|
+
if (deps[name] && deps[name] !== source) {
|
|
794
|
+
deps[name] = source;
|
|
795
|
+
changed = true;
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
if (changed)
|
|
800
|
+
writeFileSync(file, `${JSON.stringify(parsed, null, 2)}\n`);
|
|
801
|
+
}
|
|
802
|
+
// Local workerd reads .dev.vars, which FRAMEWORK_EXCLUDES keeps out of the
|
|
803
|
+
// copy (a starter developer's working file may hold real credentials) — so
|
|
804
|
+
// scaffolds get a fresh one with local-mode defaults. Without it the worker
|
|
805
|
+
// inherits production values from wrangler vars (no local persona, and
|
|
806
|
+
// /admin 500s on the missing auth secret).
|
|
807
|
+
function defaultLocalAiMode(template, guideEnabled) {
|
|
808
|
+
return template === "tanstack-start" && guideEnabled ? "live" : "disabled";
|
|
809
|
+
}
|
|
810
|
+
function localAuthSecret() {
|
|
811
|
+
return randomBytes(32).toString("base64url");
|
|
812
|
+
}
|
|
813
|
+
function localBackupSecret() {
|
|
814
|
+
return randomBytes(32).toString("base64url");
|
|
815
|
+
}
|
|
816
|
+
function localApiKeySecret() {
|
|
817
|
+
return randomBytes(32).toString("hex");
|
|
818
|
+
}
|
|
819
|
+
function localHandoffPrivateJwk() {
|
|
820
|
+
const { privateKey } = generateKeyPairSync("ec", { namedCurve: "P-256" });
|
|
821
|
+
const jwk = privateKey.export({ format: "jwk" });
|
|
822
|
+
jwk.alg = "ES256";
|
|
823
|
+
jwk.use = "sig";
|
|
824
|
+
jwk.kid = `raybase-handoff-${createHash("sha256").update(JSON.stringify({ crv: jwk.crv, kty: jwk.kty, x: jwk.x, y: jwk.y })).digest("hex").slice(0, 16)}`;
|
|
825
|
+
return JSON.stringify(jwk);
|
|
826
|
+
}
|
|
827
|
+
function ensureDevVars(projectDir, template, guideEnabled, apiEnabled) {
|
|
828
|
+
const file = join(projectDir, ".dev.vars");
|
|
829
|
+
if (existsSync(file))
|
|
830
|
+
return;
|
|
831
|
+
const aiMode = defaultLocalAiMode(template, guideEnabled);
|
|
832
|
+
const authSecret = localAuthSecret();
|
|
833
|
+
const backupSecret = localBackupSecret();
|
|
834
|
+
const apiSecretLine = apiEnabled ? `RAYBASE_API_KEY_SECRET=${localApiKeySecret()}\n` : "";
|
|
835
|
+
mkdirSync(join(projectDir, ".raybase"), { recursive: true });
|
|
836
|
+
writeFileSync(join(projectDir, ".raybase/backups-key-current"), `${backupSecret}\n`, { mode: 0o600 });
|
|
837
|
+
writeFileSync(join(projectDir, ".raybase/backups-key-retained"), "", { mode: 0o600 });
|
|
838
|
+
if (template === "astro-emdash") {
|
|
839
|
+
const handoffJwk = localHandoffPrivateJwk();
|
|
840
|
+
mkdirSync(join(projectDir, ".raybase"), { recursive: true });
|
|
841
|
+
writeFileSync(join(projectDir, ".raybase/handoff-private-jwk"), `${handoffJwk}\n`, { mode: 0o600 });
|
|
842
|
+
writeFileSync(file, `RAYBASE_ENV=local
|
|
843
|
+
BETTER_AUTH_SECRET=${authSecret}
|
|
844
|
+
BETTER_AUTH_URL=http://localhost:3000
|
|
845
|
+
RAYBASE_BACKUPS_KEY=${backupSecret}
|
|
846
|
+
RAYBASE_HANDOFF_PRIVATE_JWK=${handoffJwk}
|
|
847
|
+
RAYBASE_SITE_ORIGIN=http://127.0.0.1:4321
|
|
848
|
+
RAYBASE_AI_MODE=${aiMode}
|
|
849
|
+
RAYBASE_AI_GATEWAY_ID=
|
|
850
|
+
RAYBASE_AI_GATEWAY_CACHE=
|
|
851
|
+
RAYBASE_AI_GATEWAY_AUTH=
|
|
852
|
+
RAYBASE_AI_MOCK_RESPONSE=
|
|
853
|
+
${apiSecretLine}
|
|
854
|
+
`);
|
|
855
|
+
return;
|
|
856
|
+
}
|
|
857
|
+
writeFileSync(file, `RAYBASE_ENV=local
|
|
858
|
+
BETTER_AUTH_SECRET=${authSecret}
|
|
859
|
+
BETTER_AUTH_URL=http://localhost:3000
|
|
860
|
+
RAYBASE_BACKUPS_KEY=${backupSecret}
|
|
861
|
+
RAYBASE_AI_MODE=${aiMode}
|
|
862
|
+
RAYBASE_AI_GATEWAY_ID=
|
|
863
|
+
RAYBASE_AI_GATEWAY_CACHE=
|
|
864
|
+
RAYBASE_AI_GATEWAY_AUTH=
|
|
865
|
+
RAYBASE_AI_MOCK_RESPONSE=
|
|
866
|
+
${apiSecretLine}
|
|
867
|
+
`);
|
|
868
|
+
}
|
|
869
|
+
function assertNode() {
|
|
870
|
+
const major = Number(process.versions.node.split(".")[0]);
|
|
871
|
+
if (major < 20)
|
|
872
|
+
throw new Error("Raybase requires Node.js 20 or newer.");
|
|
873
|
+
}
|
|
874
|
+
function assertStarterNode(sourceDir, label) {
|
|
875
|
+
const packageFile = join(sourceDir, "package.json");
|
|
876
|
+
if (!existsSync(packageFile))
|
|
877
|
+
return;
|
|
878
|
+
let nodeRange;
|
|
879
|
+
try {
|
|
880
|
+
const parsed = JSON.parse(readFileSync(packageFile, "utf8"));
|
|
881
|
+
if (typeof parsed.engines?.node === "string")
|
|
882
|
+
nodeRange = parsed.engines.node.trim();
|
|
883
|
+
}
|
|
884
|
+
catch {
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
887
|
+
if (!nodeRange || satisfiesNodeRange(process.versions.node, nodeRange))
|
|
888
|
+
return;
|
|
889
|
+
throw new Error(`The ${label} starter requires Node.js ${nodeRange}, but this process is running Node.js v${process.versions.node}. ` +
|
|
890
|
+
"Switch Node versions before running create-raybase, then retry.");
|
|
891
|
+
}
|
|
892
|
+
function satisfiesNodeRange(version, range) {
|
|
893
|
+
return range.split("||").some((alternative) => {
|
|
894
|
+
const comparators = alternative.trim().split(/\s+/).filter(Boolean);
|
|
895
|
+
if (comparators.length === 0)
|
|
896
|
+
return true;
|
|
897
|
+
return comparators.every((comparator) => satisfiesComparator(version, comparator));
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
function satisfiesComparator(version, comparator) {
|
|
901
|
+
if (comparator === "*" || comparator.toLowerCase() === "x")
|
|
902
|
+
return true;
|
|
903
|
+
const match = comparator.match(/^(>=|>|<=|<|=)?\s*v?(\d+)(?:\.(\d+))?(?:\.(\d+))?$/);
|
|
904
|
+
// The preflight supports the simple comparator ranges used by Raybase's
|
|
905
|
+
// built-in starters. Unknown npm range syntax fails open so pnpm remains the source
|
|
906
|
+
// of truth instead of create-raybase blocking a valid install.
|
|
907
|
+
if (!match)
|
|
908
|
+
return true;
|
|
909
|
+
const [, operator = "=", major, minor = "0", patch = "0"] = match;
|
|
910
|
+
const comparison = compareVersions(version, `${major}.${minor}.${patch}`);
|
|
911
|
+
switch (operator) {
|
|
912
|
+
case ">":
|
|
913
|
+
return comparison > 0;
|
|
914
|
+
case ">=":
|
|
915
|
+
return comparison >= 0;
|
|
916
|
+
case "<":
|
|
917
|
+
return comparison < 0;
|
|
918
|
+
case "<=":
|
|
919
|
+
return comparison <= 0;
|
|
920
|
+
case "=":
|
|
921
|
+
return comparison === 0;
|
|
922
|
+
default:
|
|
923
|
+
return comparison === 0;
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
function compareVersions(left, right) {
|
|
927
|
+
const leftParts = parseVersion(left);
|
|
928
|
+
const rightParts = parseVersion(right);
|
|
929
|
+
for (let index = 0; index < 3; index += 1) {
|
|
930
|
+
const diff = leftParts[index] - rightParts[index];
|
|
931
|
+
if (diff !== 0)
|
|
932
|
+
return diff > 0 ? 1 : -1;
|
|
933
|
+
}
|
|
934
|
+
return 0;
|
|
935
|
+
}
|
|
936
|
+
function parseVersion(value) {
|
|
937
|
+
const match = value.match(/^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?/);
|
|
938
|
+
if (!match)
|
|
939
|
+
return [0, 0, 0];
|
|
940
|
+
return [Number(match[1]), Number(match[2] ?? 0), Number(match[3] ?? 0)];
|
|
941
|
+
}
|
|
942
|
+
async function checkNetwork() {
|
|
943
|
+
const controller = new AbortController();
|
|
944
|
+
const timeout = setTimeout(() => controller.abort(), 6000);
|
|
945
|
+
try {
|
|
946
|
+
const response = await fetch("https://registry.npmjs.org/create-raybase", {
|
|
947
|
+
method: "HEAD",
|
|
948
|
+
signal: controller.signal
|
|
949
|
+
});
|
|
950
|
+
if (!response.ok && response.status !== 404)
|
|
951
|
+
throw new Error(`npm registry returned ${response.status}`);
|
|
952
|
+
}
|
|
953
|
+
catch (error) {
|
|
954
|
+
throw new Error(`Network check failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
955
|
+
}
|
|
956
|
+
finally {
|
|
957
|
+
clearTimeout(timeout);
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
function installSkills(projectDir, template, localRoot, docsEnabled, guideEnabled, apiEnabled) {
|
|
961
|
+
applySkillsSync(projectDir, { framework: template, localRoot, docsEnabled, guideEnabled, apiEnabled });
|
|
962
|
+
}
|
|
963
|
+
// Refresh the installed .agents/skills set in place for the project's framework
|
|
964
|
+
// and enabled modules — first-party `raybase skills sync`. Overwrites local
|
|
965
|
+
// skill edits (reported) and prunes previously stamped skills that left the
|
|
966
|
+
// expected set.
|
|
967
|
+
export function syncProjectSkills(projectDir, options = {}) {
|
|
968
|
+
const framework = detectFramework(projectDir);
|
|
969
|
+
const modules = detectInstalledModules(projectDir);
|
|
970
|
+
const localRoot = options.localRoot !== undefined ? options.localRoot : resolveLocalRoot(process.env.RAYBASE_LOCAL) ?? sourceCheckoutRoot();
|
|
971
|
+
return applySkillsSync(projectDir, {
|
|
972
|
+
framework,
|
|
973
|
+
localRoot,
|
|
974
|
+
docsEnabled: modules.has("docs"),
|
|
975
|
+
guideEnabled: modules.has("guide"),
|
|
976
|
+
apiEnabled: modules.has("api"),
|
|
977
|
+
dryRun: Boolean(options.dryRun)
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
// Staleness check for `raybase doctor`: never throws, never writes. Compares
|
|
981
|
+
// the stamped install hashes (or, unstamped, the installed trees) against the
|
|
982
|
+
// bundled skill snapshot. `checked: false` means there is nothing reliable to
|
|
983
|
+
// compare — no installed skills, no resolvable snapshot, or unreadable state.
|
|
984
|
+
export function checkProjectSkills(projectDir) {
|
|
985
|
+
try {
|
|
986
|
+
if (!isDirectoryLike(join(projectDir, ".agents", "skills")))
|
|
987
|
+
return { checked: false };
|
|
988
|
+
const framework = detectFramework(projectDir);
|
|
989
|
+
const modules = detectInstalledModules(projectDir);
|
|
990
|
+
const localRoot = resolveLocalRoot(process.env.RAYBASE_LOCAL) ?? sourceCheckoutRoot();
|
|
991
|
+
const expected = skillsForFramework(framework, modules.has("docs"), modules.has("guide"), modules.has("api"));
|
|
992
|
+
const prior = readSkillsLock(projectDir);
|
|
993
|
+
const missing = [];
|
|
994
|
+
const stale = [];
|
|
995
|
+
for (const bundle of expected) {
|
|
996
|
+
const source = skillSource(bundle, localRoot);
|
|
997
|
+
if (!isDirectoryLike(source))
|
|
998
|
+
return { checked: false };
|
|
999
|
+
const target = join(projectDir, ".agents", "skills", bundle);
|
|
1000
|
+
if (!isDirectoryLike(target)) {
|
|
1001
|
+
missing.push(bundle);
|
|
1002
|
+
continue;
|
|
1003
|
+
}
|
|
1004
|
+
// With a stamp, local edits are respected: only an upstream move of the
|
|
1005
|
+
// bundled skill counts as stale. Without one, compare trees directly.
|
|
1006
|
+
const baseline = prior?.skills[bundle]?.sha256 ?? hashSkillTree(target);
|
|
1007
|
+
if (baseline !== hashSkillTree(source))
|
|
1008
|
+
stale.push(bundle);
|
|
1009
|
+
}
|
|
1010
|
+
const removable = Object.keys(prior?.skills ?? {}).filter((bundle) => !expected.includes(bundle) && pathEntryExists(join(projectDir, ".agents", "skills", bundle)));
|
|
1011
|
+
return { checked: true, framework, stamped: prior !== null, missing, stale, removable };
|
|
1012
|
+
}
|
|
1013
|
+
catch {
|
|
1014
|
+
return { checked: false };
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
function applySkillsSync(projectDir, input) {
|
|
1018
|
+
const dryRun = Boolean(input.dryRun);
|
|
1019
|
+
const expected = skillsForFramework(input.framework, input.docsEnabled, input.guideEnabled, input.apiEnabled);
|
|
1020
|
+
const prior = readSkillsLock(projectDir);
|
|
1021
|
+
const report = {
|
|
1022
|
+
ok: true,
|
|
1023
|
+
dryRun,
|
|
1024
|
+
framework: input.framework,
|
|
1025
|
+
modules: { api: input.apiEnabled, docs: input.docsEnabled, guide: input.guideEnabled },
|
|
1026
|
+
added: [],
|
|
1027
|
+
updated: [],
|
|
1028
|
+
removed: [],
|
|
1029
|
+
unchanged: [],
|
|
1030
|
+
localEditsOverwritten: [],
|
|
1031
|
+
lockFile: SKILLS_LOCK_FILE
|
|
1032
|
+
};
|
|
1033
|
+
const lock = {
|
|
1034
|
+
schemaVersion: 1,
|
|
1035
|
+
framework: input.framework,
|
|
1036
|
+
modules: report.modules,
|
|
1037
|
+
skills: {},
|
|
1038
|
+
syncedAt: new Date().toISOString()
|
|
1039
|
+
};
|
|
1040
|
+
for (const bundle of expected) {
|
|
1041
|
+
const source = skillSource(bundle, input.localRoot);
|
|
1042
|
+
if (!existsSync(source)) {
|
|
1043
|
+
throw new Error(`Skills bundle ${bundle} not found at ${source}. Re-run pnpm prepare:create in the raybase repo.`);
|
|
1044
|
+
}
|
|
1045
|
+
const sourceHash = hashSkillTree(source);
|
|
1046
|
+
const target = join(projectDir, ".agents", "skills", bundle);
|
|
1047
|
+
const installedHash = isDirectoryLike(target) ? hashSkillTree(target) : null;
|
|
1048
|
+
if (installedHash === null) {
|
|
1049
|
+
report.added.push(bundle);
|
|
1050
|
+
}
|
|
1051
|
+
else if (installedHash === sourceHash) {
|
|
1052
|
+
report.unchanged.push(bundle);
|
|
1053
|
+
}
|
|
1054
|
+
else {
|
|
1055
|
+
report.updated.push(bundle);
|
|
1056
|
+
const stamped = prior?.skills[bundle]?.sha256;
|
|
1057
|
+
if (stamped && stamped !== installedHash)
|
|
1058
|
+
report.localEditsOverwritten.push(bundle);
|
|
1059
|
+
}
|
|
1060
|
+
lock.skills[bundle] = { sha256: sourceHash };
|
|
1061
|
+
if (dryRun)
|
|
1062
|
+
continue;
|
|
1063
|
+
if (installedHash !== sourceHash) {
|
|
1064
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
1065
|
+
// Remove-then-copy so files deleted upstream do not linger in the app.
|
|
1066
|
+
rmSync(target, { recursive: true, force: true });
|
|
1067
|
+
cpSync(source, target, { recursive: true });
|
|
1068
|
+
}
|
|
1069
|
+
ensureDirectorySymlink(join(projectDir, ".claude", "skills", bundle), target);
|
|
1070
|
+
}
|
|
1071
|
+
// Prune only what a previous install stamped: user-authored skills in
|
|
1072
|
+
// .agents/skills are invisible to the lock and stay untouched.
|
|
1073
|
+
for (const bundle of Object.keys(prior?.skills ?? {})) {
|
|
1074
|
+
if (expected.includes(bundle))
|
|
1075
|
+
continue;
|
|
1076
|
+
const target = join(projectDir, ".agents", "skills", bundle);
|
|
1077
|
+
if (!pathEntryExists(target))
|
|
1078
|
+
continue;
|
|
1079
|
+
report.removed.push(bundle);
|
|
1080
|
+
if (dryRun)
|
|
1081
|
+
continue;
|
|
1082
|
+
rmSync(target, { recursive: true, force: true });
|
|
1083
|
+
const link = join(projectDir, ".claude", "skills", bundle);
|
|
1084
|
+
if (pathEntryExists(link))
|
|
1085
|
+
rmSync(link, { recursive: true, force: true });
|
|
1086
|
+
}
|
|
1087
|
+
if (!dryRun)
|
|
1088
|
+
writeSkillsLock(projectDir, lock);
|
|
1089
|
+
return report;
|
|
1090
|
+
}
|
|
1091
|
+
function readSkillsLock(projectDir) {
|
|
1092
|
+
const file = join(projectDir, SKILLS_LOCK_FILE);
|
|
1093
|
+
if (!existsSync(file))
|
|
1094
|
+
return null;
|
|
1095
|
+
const parsed = JSON.parse(readFileSync(file, "utf8"));
|
|
1096
|
+
if (Number(parsed.schemaVersion) > 1)
|
|
1097
|
+
throw new Error(`${SKILLS_LOCK_FILE} schemaVersion is newer than this create-raybase. Upgrade create-raybase.`);
|
|
1098
|
+
if (parsed.schemaVersion !== 1 || !parsed.skills || typeof parsed.skills !== "object") {
|
|
1099
|
+
throw new Error(`${SKILLS_LOCK_FILE} is not a valid Raybase skills lock file.`);
|
|
1100
|
+
}
|
|
1101
|
+
return parsed;
|
|
1102
|
+
}
|
|
1103
|
+
function writeSkillsLock(projectDir, lock) {
|
|
1104
|
+
const file = join(projectDir, SKILLS_LOCK_FILE);
|
|
1105
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
1106
|
+
writeFileSync(file, stableJson(lock));
|
|
1107
|
+
}
|
|
1108
|
+
// Deterministic tree hash: sorted POSIX-relative paths + file contents.
|
|
1109
|
+
function hashSkillTree(dir) {
|
|
1110
|
+
const hash = createHash("sha256");
|
|
1111
|
+
const files = walk(dir)
|
|
1112
|
+
.map((file) => relative(dir, file).split(sep).join("/"))
|
|
1113
|
+
.sort();
|
|
1114
|
+
for (const file of files) {
|
|
1115
|
+
hash.update(file);
|
|
1116
|
+
hash.update("\0");
|
|
1117
|
+
hash.update(readFileSync(join(dir, ...file.split("/"))));
|
|
1118
|
+
hash.update("\0");
|
|
1119
|
+
}
|
|
1120
|
+
return hash.digest("hex");
|
|
1121
|
+
}
|
|
1122
|
+
function isDirectoryLike(path) {
|
|
1123
|
+
try {
|
|
1124
|
+
return statSync(path).isDirectory();
|
|
1125
|
+
}
|
|
1126
|
+
catch {
|
|
1127
|
+
return false;
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
function skillsForFramework(template, docsEnabled, guideEnabled, apiEnabled) {
|
|
1131
|
+
return [
|
|
1132
|
+
...FRAMEWORK_SKILLS[template],
|
|
1133
|
+
...(docsEnabled ? [DOCS_SKILL] : []),
|
|
1134
|
+
...(guideEnabled ? [GUIDE_SKILL] : []),
|
|
1135
|
+
...(apiEnabled ? [API_SKILL] : [])
|
|
1136
|
+
];
|
|
1137
|
+
}
|
|
1138
|
+
function skillSource(bundle, localRoot) {
|
|
1139
|
+
if (bundle === API_SKILL && localRoot)
|
|
1140
|
+
return join(localRoot, "packages/api/skills", bundle);
|
|
1141
|
+
return localRoot ? join(localRoot, "skills", bundle) : join(packageRoot, "skills", bundle);
|
|
1142
|
+
}
|
|
1143
|
+
function ensureDirectorySymlink(link, target) {
|
|
1144
|
+
if (pathEntryExists(link)) {
|
|
1145
|
+
const stat = lstatSync(link);
|
|
1146
|
+
if (stat.isSymbolicLink() && resolve(dirname(link), readlinkSync(link)) === target)
|
|
1147
|
+
return;
|
|
1148
|
+
rmSync(link, { recursive: true, force: true });
|
|
1149
|
+
}
|
|
1150
|
+
mkdirSync(dirname(link), { recursive: true });
|
|
1151
|
+
symlinkSync(relativeLinkTarget(link, target), link, "dir");
|
|
1152
|
+
}
|
|
1153
|
+
function ensureFileSymlink(link, target, replaceExistingFile) {
|
|
1154
|
+
if (pathEntryExists(link)) {
|
|
1155
|
+
const stat = lstatSync(link);
|
|
1156
|
+
if (stat.isSymbolicLink()) {
|
|
1157
|
+
if (resolve(dirname(link), readlinkSync(link)) === target)
|
|
1158
|
+
return;
|
|
1159
|
+
rmSync(link, { recursive: true, force: true });
|
|
1160
|
+
mkdirSync(dirname(link), { recursive: true });
|
|
1161
|
+
symlinkSync(relativeLinkTarget(link, target), link, "file");
|
|
1162
|
+
return;
|
|
1163
|
+
}
|
|
1164
|
+
const canReplaceFile = !stat.isDirectory() && (replaceExistingFile || readFileSync(link, "utf8") === readFileSync(target, "utf8"));
|
|
1165
|
+
if (!canReplaceFile)
|
|
1166
|
+
return;
|
|
1167
|
+
rmSync(link, { recursive: true, force: true });
|
|
1168
|
+
}
|
|
1169
|
+
mkdirSync(dirname(link), { recursive: true });
|
|
1170
|
+
symlinkSync(relativeLinkTarget(link, target), link, "file");
|
|
1171
|
+
}
|
|
1172
|
+
function relativeLinkTarget(link, target) {
|
|
1173
|
+
return relative(dirname(link), target).split(sep).join("/");
|
|
1174
|
+
}
|
|
1175
|
+
function pathEntryExists(path) {
|
|
1176
|
+
try {
|
|
1177
|
+
lstatSync(path);
|
|
1178
|
+
return true;
|
|
1179
|
+
}
|
|
1180
|
+
catch (error) {
|
|
1181
|
+
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT")
|
|
1182
|
+
return false;
|
|
1183
|
+
throw error;
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
function ensureAgentInstructions(projectDir, template, docsEnabled, guideEnabled, apiEnabled) {
|
|
1187
|
+
const agentsFile = join(projectDir, "AGENTS.md");
|
|
1188
|
+
const claudeFile = join(projectDir, "CLAUDE.md");
|
|
1189
|
+
const docsPlacement = docsEnabled ? currentDocsPlacement(projectDir) : "spine";
|
|
1190
|
+
const block = defaultAgentBlock(template, docsEnabled, guideEnabled, apiEnabled, docsPlacement);
|
|
1191
|
+
const createdFromClaude = !existsSync(agentsFile) && pathEntryExists(claudeFile) && !lstatSync(claudeFile).isSymbolicLink();
|
|
1192
|
+
if (!existsSync(agentsFile)) {
|
|
1193
|
+
writeFileSync(agentsFile, createdFromClaude ? readFileSync(claudeFile, "utf8") : block);
|
|
1194
|
+
}
|
|
1195
|
+
const existing = readFileSync(agentsFile, "utf8");
|
|
1196
|
+
if (!existing.includes("Raybase conventions")) {
|
|
1197
|
+
writeFileSync(agentsFile, `${existing.trim()}\n\n${block}`);
|
|
1198
|
+
}
|
|
1199
|
+
ensureFileSymlink(claudeFile, agentsFile, createdFromClaude);
|
|
1200
|
+
}
|
|
1201
|
+
function defaultAgentBlock(template, docsEnabled, guideEnabled, apiEnabled, docsPlacement) {
|
|
1202
|
+
const docsPath = template === "astro-emdash" && docsPlacement === "site" ? "site/content/docs" : "content/docs";
|
|
1203
|
+
const sourceRoot = template === "react-router" ? "app" : "src";
|
|
1204
|
+
const docsLine = docsEnabled ? `- /docs lives in ${docsPath}; use .agents/skills/raybase-docs-writing/SKILL.md before changing docs.\n` : "";
|
|
1205
|
+
const guideLine = guideEnabled
|
|
1206
|
+
? `- Guide is enabled; use .agents/skills/raybase-guide/SKILL.md before changing ${sourceRoot}/guide or app workflows. Keep Guide context current, and expose only intentional workflows through narrow Guide actions.\n`
|
|
1207
|
+
: "";
|
|
1208
|
+
const apiLine = apiEnabled ? "- API is enabled; use .agents/skills/raybase-api/SKILL.md before exposing external HTTP operations.\n" : "";
|
|
1209
|
+
const frameworkLine = template === "react-router"
|
|
1210
|
+
? "Routes are React Router file routes in app/routes; Raybase owns /login, /setup, /invite, /admin, /api and /mcp ahead of the router (workers/app.ts)."
|
|
1211
|
+
: "For TanStack Start route/layout/framework work, read .agents/skills/raybase-tanstack-start/SKILL.md.";
|
|
1212
|
+
return `# Raybase conventions
|
|
1213
|
+
|
|
1214
|
+
Use the raybase-* skills in .agents/skills before changing this app. ${frameworkLine} Claude Code compatibility links live in .claude/skills.
|
|
1215
|
+
|
|
1216
|
+
Commands:
|
|
1217
|
+
- raybase dev
|
|
1218
|
+
- raybase doctor
|
|
1219
|
+
- raybase migrate
|
|
1220
|
+
- raybase deploy
|
|
1221
|
+
- raybase backup
|
|
1222
|
+
- raybase invite --owner
|
|
1223
|
+
|
|
1224
|
+
${docsLine}${guideLine}${apiLine}
|
|
1225
|
+
Access:
|
|
1226
|
+
- \`dev/SPEC.md\` must contain \`Signup mode\`, \`Cloudflare email capability\`, \`Auth email features\`, \`Invite delivery\`, and \`Password recovery\` lines before implementation.
|
|
1227
|
+
- Default to \`Signup mode: invite-only\`, \`Cloudflare email capability: free-compatible\`, \`Auth email features: none\`, \`Invite delivery: admin-shared links\`, and \`Password recovery: admin-assisted\`.
|
|
1228
|
+
- Public signup is controlled by \`appConfig.auth.signupMode\`, not \`auth.publicRoutes\`. Use \`"public"\` for provider and password signup, or \`"provider-only"\` for provider signup with the password door closed.
|
|
1229
|
+
- Both public signup modes create normal \`user\` users only; Raybase \`/admin\` remains invite/operator-only. Password sign-in stays available to existing accounts in every mode.
|
|
1230
|
+
- Password-based public signup, password reset, emailed invites, welcome email, and magic links require owner-confirmed Workers Paid plus Cloudflare Email Sending/domain onboarding and \`Cloudflare email capability: transactional-email\`. Provider-only signup needs no auth email because the provider verifies the email.
|
|
1231
|
+
- Cloudflare verified destination addresses are only for operator/admin notifications or intentional test sends; do not treat them as user verification, password reset, invite email, magic-link auth, or public signup.
|
|
1232
|
+
|
|
1233
|
+
Living planning docs:
|
|
1234
|
+
- Write \`dev/SPEC.md\` and \`dev/SPEC-OVERVIEW.md\` together before asking for approval; capture why the app exists and what success looks like when that is not already clear. Present the overview inline in the approval message and link \`dev/SPEC.md\` as the full spec.
|
|
1235
|
+
- Read \`dev/SPEC.md\`, \`dev/SPEC-OVERVIEW.md\`, and \`dev/CODEBASE-MAP.md\` before substantial product or architecture work.
|
|
1236
|
+
- Update them when the product story, business value, or architecture changes; skip churn for tiny fixes.
|
|
1237
|
+
- Use \`dev/features/<feature-slug>/\` for temporary feature proposals, then archive implemented proposals under \`dev/features/archive/\` after folding durable facts into the canonical planning docs.
|
|
1238
|
+
|
|
1239
|
+
Prohibitions:
|
|
1240
|
+
- Do not add custom auth.
|
|
1241
|
+
- Do not import or use unsafeDb.
|
|
1242
|
+
- Do not deploy without raybase doctor passing.
|
|
1243
|
+
- Do not change schema outside ${sourceRoot}/db/schema.ts plus raybase migrate.
|
|
1244
|
+
`;
|
|
1245
|
+
}
|
|
1246
|
+
function ensureSpec(projectDir, appName, template) {
|
|
1247
|
+
const file = join(projectDir, CANONICAL_SPEC_PATH);
|
|
1248
|
+
if (existsSync(file))
|
|
1249
|
+
return;
|
|
1250
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
1251
|
+
if (template === "astro-emdash") {
|
|
1252
|
+
writeFileSync(file, `# ${appName} Spec
|
|
1253
|
+
|
|
1254
|
+
Status: Draft placeholder - not approved for implementation.
|
|
1255
|
+
|
|
1256
|
+
This file is the owner-facing source of truth for the Raybase + Astro/EmDash content site the agent will build. Replace this placeholder with an approved plain-language spec before changing content collections, Galley templates, public pages, Raybase Actions, jobs, docs, Guide, MCP, or deployment wiring.
|
|
1257
|
+
|
|
1258
|
+
## Content Site Purpose And Audience
|
|
1259
|
+
|
|
1260
|
+
TBD
|
|
1261
|
+
|
|
1262
|
+
Describe who reads the public site, what the site must communicate or publish, and what success looks like.
|
|
1263
|
+
|
|
1264
|
+
## Access
|
|
1265
|
+
|
|
1266
|
+
Signup mode: invite-only
|
|
1267
|
+
Cloudflare email capability: free-compatible
|
|
1268
|
+
Auth email features: none
|
|
1269
|
+
Invite delivery: admin-shared links
|
|
1270
|
+
Password recovery: admin-assisted
|
|
1271
|
+
|
|
1272
|
+
Default: only invited users can sign in. For provider and password signup, use
|
|
1273
|
+
\`Signup mode: public self-signup\` with \`auth.signupMode: "public"\`. For provider
|
|
1274
|
+
signup with the password door closed, use \`Signup mode: provider-only
|
|
1275
|
+
self-signup\` with \`auth.signupMode: "provider-only"\`. Both public modes create
|
|
1276
|
+
normal \`user\` users only; password sign-in stays available to existing accounts,
|
|
1277
|
+
and Raybase \`/admin\` remains invite/operator-only.
|
|
1278
|
+
|
|
1279
|
+
Raybase spine access is invite-only by default. EmDash admin access is reached through a Raybase-minted handoff token and an HttpOnly content-worker cookie that expires with it. Public visitors can read published content only.
|
|
1280
|
+
|
|
1281
|
+
## Public Surface / Documentation
|
|
1282
|
+
|
|
1283
|
+
Public surface: public Astro/EmDash site
|
|
1284
|
+
Documentation: docs inside the app
|
|
1285
|
+
Docs exposure: public
|
|
1286
|
+
|
|
1287
|
+
Docs are public by default. With docs placement \`spine\` the spine serves
|
|
1288
|
+
\`/docs\` and \`/docs/api/search\` to signed-out visitors; with \`Documentation:
|
|
1289
|
+
public docs on the public site\` they move to the public Astro site.
|
|
1290
|
+
\`Docs exposure: signed-in only\` is a choice for \`spine\` placement; write it
|
|
1291
|
+
here only together with the sign-in check the raybase-astro-emdash skill
|
|
1292
|
+
describes.
|
|
1293
|
+
|
|
1294
|
+
## Content Ownership
|
|
1295
|
+
|
|
1296
|
+
EmDash owns content editing, schema builder, media, drafts, and publishing in its own content D1 database and media R2 bucket. Raybase owns identity, admin/operator surfaces, audit, agents, deploy orchestration, and declared public Raybase Actions.
|
|
1297
|
+
|
|
1298
|
+
## Pages, Galley Templates, And Media
|
|
1299
|
+
|
|
1300
|
+
TBD
|
|
1301
|
+
|
|
1302
|
+
List the public pages and expected runtime-authored Galley templates. Ordinary public sections should use Galley templates and \`pages.content\` Portable Text blocks rather than new Astro source components.
|
|
1303
|
+
|
|
1304
|
+
## Raybase Server Islands
|
|
1305
|
+
|
|
1306
|
+
TBD
|
|
1307
|
+
|
|
1308
|
+
List any public Raybase-powered islands. Each island must call an allowlisted public Raybase Action with output validation; content data must never supply arbitrary URLs.
|
|
1309
|
+
|
|
1310
|
+
## Open Questions
|
|
1311
|
+
|
|
1312
|
+
- What audience, content model, Galley templates, media needs, and public Raybase islands should replace this placeholder?
|
|
1313
|
+
`);
|
|
1314
|
+
return;
|
|
1315
|
+
}
|
|
1316
|
+
writeFileSync(file, `# ${appName} Spec
|
|
1317
|
+
|
|
1318
|
+
Status: Draft placeholder - not approved for implementation.
|
|
1319
|
+
|
|
1320
|
+
This file is the owner-facing source of truth for the app the agent will build. Replace this placeholder with an approved plain-language spec that explains why the app exists and what value it should produce before writing app-specific schema, policies, screens, docs, jobs, notifications, MCP tools, or Store app customizations. Write dev/SPEC-OVERVIEW.md from the same app facts at the same time, paste that overview into the approval message, and link dev/SPEC.md as the full spec.
|
|
1321
|
+
|
|
1322
|
+
## Purpose And Business Value
|
|
1323
|
+
|
|
1324
|
+
TBD
|
|
1325
|
+
|
|
1326
|
+
Describe the problem this app solves, why that problem matters to the owner and
|
|
1327
|
+
users, and what success should look like.
|
|
1328
|
+
|
|
1329
|
+
Security default: this is an internal app. Only invited users can sign in, and uninvited visitors see a login wall.
|
|
1330
|
+
|
|
1331
|
+
## Access
|
|
1332
|
+
|
|
1333
|
+
Signup mode: invite-only
|
|
1334
|
+
Cloudflare email capability: free-compatible
|
|
1335
|
+
Auth email features: none
|
|
1336
|
+
Invite delivery: admin-shared links
|
|
1337
|
+
Password recovery: admin-assisted
|
|
1338
|
+
|
|
1339
|
+
Default: only invited users can sign in. For provider and password signup, use
|
|
1340
|
+
\`Signup mode: public self-signup\` with \`auth.signupMode: "public"\`. For
|
|
1341
|
+
provider signup with the password door closed, use \`Signup mode: provider-only
|
|
1342
|
+
self-signup\` with \`auth.signupMode: "provider-only"\`. Both public modes
|
|
1343
|
+
create normal \`user\` users only; password sign-in stays available to existing
|
|
1344
|
+
accounts, and Raybase \`/admin\` remains invite/operator-only.
|
|
1345
|
+
|
|
1346
|
+
The default Cloudflare email capability is Free-compatible: Raybase generates
|
|
1347
|
+
single-use setup and invite links, but admins copy and share invite links
|
|
1348
|
+
manually. There is no self-service password reset, magic-link/passwordless
|
|
1349
|
+
auth, public-signup email verification, invite email, welcome email, or other
|
|
1350
|
+
auth email to arbitrary recipients.
|
|
1351
|
+
|
|
1352
|
+
Use \`Cloudflare email capability: transactional-email\` only after the owner
|
|
1353
|
+
has confirmed Workers Paid plus Cloudflare Email Sending/domain onboarding.
|
|
1354
|
+
Then list only approved \`Auth email features\` from \`password-reset\`,
|
|
1355
|
+
\`invite-email\`, \`welcome-email\`, \`public-signup-email-verification\`, and
|
|
1356
|
+
\`magic-link\`, and align \`Invite delivery\` and \`Password recovery\` with
|
|
1357
|
+
the app config. Cloudflare verified destination addresses may be used for
|
|
1358
|
+
operator/admin notifications or intentional test sends only; they are not a
|
|
1359
|
+
Raybase auth mode for end-user verification, reset, invites, or magic links.
|
|
1360
|
+
|
|
1361
|
+
## Public Surface / Documentation
|
|
1362
|
+
|
|
1363
|
+
Public surface: none
|
|
1364
|
+
Documentation: in-app docs
|
|
1365
|
+
Docs exposure: public
|
|
1366
|
+
|
|
1367
|
+
Docs are public by default: \`/docs\` and \`/docs/api/search\` answer signed-out
|
|
1368
|
+
visitors. \`Docs exposure: signed-in only\` is a choice; write it here only
|
|
1369
|
+
together with the sign-in check on the docs routes that the framework skill
|
|
1370
|
+
describes.
|
|
1371
|
+
|
|
1372
|
+
## What The App Does
|
|
1373
|
+
|
|
1374
|
+
TBD
|
|
1375
|
+
|
|
1376
|
+
## Users And Roles
|
|
1377
|
+
|
|
1378
|
+
TBD
|
|
1379
|
+
|
|
1380
|
+
Use business role names such as manager, approver, or operations. Operator access to /admin is separate from app roles.
|
|
1381
|
+
|
|
1382
|
+
## Data Model
|
|
1383
|
+
|
|
1384
|
+
TBD
|
|
1385
|
+
|
|
1386
|
+
## Permissions
|
|
1387
|
+
|
|
1388
|
+
TBD
|
|
1389
|
+
|
|
1390
|
+
Describe who can read, create, update, and delete each kind of record. Every app table must have explicit read, create, update, and delete policies.
|
|
1391
|
+
|
|
1392
|
+
## Workflows
|
|
1393
|
+
|
|
1394
|
+
TBD
|
|
1395
|
+
|
|
1396
|
+
Describe the important business workflows, approvals, state changes, imports, exports, reminders, and reports the app must support.
|
|
1397
|
+
|
|
1398
|
+
## Integrations, Files, AI, And MCP
|
|
1399
|
+
|
|
1400
|
+
TBD
|
|
1401
|
+
|
|
1402
|
+
Name any external systems, uploads, generated files, AI/Guide behavior, search, notifications, jobs, or MCP tools the app needs.
|
|
1403
|
+
|
|
1404
|
+
## Open Questions
|
|
1405
|
+
|
|
1406
|
+
- What owner-approved purpose, business value, users, data, permissions, and workflows should replace this placeholder?
|
|
1407
|
+
|
|
1408
|
+
Agents must stop here until the owner has approved a real spec. Do not infer business value, roles, data, permissions, workflows, Store app fit, docs, jobs, notifications, or MCP tools from this placeholder.
|
|
1409
|
+
`);
|
|
1410
|
+
}
|
|
1411
|
+
function nextSteps(projectDir, template, docsEnabled, guideEnabled, apiEnabled, storeApp) {
|
|
1412
|
+
const storeSteps = storeApp
|
|
1413
|
+
? [
|
|
1414
|
+
`Store app ${storeApp.manifest.id}@${storeApp.manifest.version} was installed.`,
|
|
1415
|
+
".raybase/store-app.json records Store provenance.",
|
|
1416
|
+
"Store dev/SPEC.md is a canonical baseline; confirm it is approved as-is or record approved access/signup/email-capability deltas before customization."
|
|
1417
|
+
]
|
|
1418
|
+
: [];
|
|
1419
|
+
if (template === "astro-emdash") {
|
|
1420
|
+
const docsPlacement = currentDocsPlacement(projectDir);
|
|
1421
|
+
const docsPath = docsPlacement === "site" ? "site/content/docs" : "content/docs";
|
|
1422
|
+
const docsStep = docsPlacement === "site"
|
|
1423
|
+
? "Docs live at /docs on the public Astro/EmDash site; follow .agents/skills/raybase-docs-writing/SKILL.md before changing site/content/docs."
|
|
1424
|
+
: "Docs live at /docs on the spine; follow .agents/skills/raybase-docs-writing/SKILL.md before changing content/docs.";
|
|
1425
|
+
const guideKnowledge = docsEnabled ? `${docsPath}, content/guide, and site content docs` : "content/guide and site content docs";
|
|
1426
|
+
return [
|
|
1427
|
+
"cd " + projectDir,
|
|
1428
|
+
...storeSteps,
|
|
1429
|
+
...(storeApp
|
|
1430
|
+
? []
|
|
1431
|
+
: [
|
|
1432
|
+
"Replace dev/SPEC.md and dev/SPEC-OVERVIEW.md together: interview the owner, fill in content site audience / Raybase spine access / EmDash D1-R2 ownership / page and Galley template model / Server Island policy, paste the overview into the approval message, link dev/SPEC.md as the full spec, and get approval before content-site changes."
|
|
1433
|
+
]),
|
|
1434
|
+
"Follow .agents/skills/raybase-astro-emdash/SKILL.md before changing site/",
|
|
1435
|
+
...(docsEnabled ? [docsStep] : []),
|
|
1436
|
+
...(guideEnabled
|
|
1437
|
+
? [`Guide is enabled on the Raybase spine; keep ${guideKnowledge} current, document what Guide can do, add narrow Guide actions for intended workflows, then run raybase guide index after knowledge changes.`]
|
|
1438
|
+
: []),
|
|
1439
|
+
...(apiEnabled ? ["API is enabled at /api/v1 on the spine; set deployed RAYBASE_API_KEY_SECRET and manage keys from /admin/api."] : []),
|
|
1440
|
+
"After the first raybase deploy, copy the printed content site URL into src/raybase.config.ts appConfig.handoff.resources[].origin before production handoff.",
|
|
1441
|
+
"raybase dev (starts the Raybase spine on :3000 and the Astro/EmDash site on :4321, or the next free port when :4321 is taken)"
|
|
1442
|
+
];
|
|
1443
|
+
}
|
|
1444
|
+
const guideKnowledge = docsEnabled ? "content/docs and content/guide" : "content/guide";
|
|
1445
|
+
return [
|
|
1446
|
+
"cd " + projectDir,
|
|
1447
|
+
...storeSteps,
|
|
1448
|
+
...(storeApp
|
|
1449
|
+
? []
|
|
1450
|
+
: [
|
|
1451
|
+
"Replace dev/SPEC.md and dev/SPEC-OVERVIEW.md together: interview the owner, fill in access/signup mode / Cloudflare email capability / auth email features / purpose and business value / users / data / permissions / workflows, paste the overview into the approval message, link dev/SPEC.md as the full spec, and get approval before schema or screens."
|
|
1452
|
+
]),
|
|
1453
|
+
template === "react-router"
|
|
1454
|
+
? "Follow .agents/skills/raybase-building/SKILL.md; app routes live in app/routes and read the signed-in user with currentUser() from app/raybase.server.ts"
|
|
1455
|
+
: "Follow .agents/skills/raybase-building/SKILL.md and .agents/skills/raybase-tanstack-start/SKILL.md",
|
|
1456
|
+
...(docsEnabled ? ["Docs live at /docs; follow .agents/skills/raybase-docs-writing/SKILL.md before changing content/docs."] : []),
|
|
1457
|
+
...(guideEnabled
|
|
1458
|
+
? [`Guide is enabled; keep ${guideKnowledge} current, document what Guide can do, add narrow Guide actions for intended workflows, then run raybase guide index after knowledge changes.`]
|
|
1459
|
+
: []),
|
|
1460
|
+
...(apiEnabled ? ["API is enabled at /api/v1; set deployed RAYBASE_API_KEY_SECRET and manage keys from /admin/api."] : []),
|
|
1461
|
+
"raybase dev"
|
|
1462
|
+
];
|
|
1463
|
+
}
|
|
1464
|
+
function configureDocs(projectDir, template, enabled, placement, localRoot, keep = noKeptFiles) {
|
|
1465
|
+
const packageFile = join(projectDir, "package.json");
|
|
1466
|
+
const parsed = JSON.parse(readFileSync(packageFile, "utf8"));
|
|
1467
|
+
parsed.raybase = {
|
|
1468
|
+
...(parsed.raybase ?? {}),
|
|
1469
|
+
framework: template,
|
|
1470
|
+
modules: {
|
|
1471
|
+
...(parsed.raybase?.modules ?? {}),
|
|
1472
|
+
docs: { enabled, package: "@raybase/docs", placement }
|
|
1473
|
+
}
|
|
1474
|
+
};
|
|
1475
|
+
if (!enabled || placement === "site") {
|
|
1476
|
+
parsed.dependencies = parsed.dependencies ?? {};
|
|
1477
|
+
parsed.devDependencies = parsed.devDependencies ?? {};
|
|
1478
|
+
delete parsed.dependencies?.["@raybase/docs"];
|
|
1479
|
+
if (enabled)
|
|
1480
|
+
parsed.dependencies["@raybase/docs"] = localRaybasePackageRange("@raybase/docs", RAYBASE_PACKAGE_RANGES["@raybase/docs"], localRoot);
|
|
1481
|
+
// lucide-react stays: base app components (src/components/ui, _app routes) import it outside docs.
|
|
1482
|
+
for (const name of ["fumadocs-core", "fumadocs-ui"])
|
|
1483
|
+
delete parsed.dependencies?.[name];
|
|
1484
|
+
for (const name of ["fumadocs-mdx", "@types/mdx"])
|
|
1485
|
+
delete parsed.devDependencies?.[name];
|
|
1486
|
+
}
|
|
1487
|
+
writeFileSync(packageFile, `${JSON.stringify(parsed, null, 2)}\n`);
|
|
1488
|
+
if (!enabled) {
|
|
1489
|
+
pruneDocsFiles(projectDir, template);
|
|
1490
|
+
}
|
|
1491
|
+
else if (placement === "site") {
|
|
1492
|
+
pruneDocsFiles(projectDir, template, { keepServerModule: true });
|
|
1493
|
+
copySiteDocsTemplate(projectDir, template, localRoot, keep);
|
|
1494
|
+
configureSiteDocsPackage(projectDir);
|
|
1495
|
+
patchSiteDocsAstroConfig(projectDir, true);
|
|
1496
|
+
ensureSiteSourceIgnored(projectDir);
|
|
1497
|
+
patchDocsServerModule(projectDir, template, placement);
|
|
1498
|
+
}
|
|
1499
|
+
else {
|
|
1500
|
+
patchDocsServerModule(projectDir, template, placement);
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
function configureGuide(projectDir, template, enabled, docsEnabled, localRoot, keep = noKeptFiles) {
|
|
1504
|
+
const packageFile = join(projectDir, "package.json");
|
|
1505
|
+
const parsed = JSON.parse(readFileSync(packageFile, "utf8"));
|
|
1506
|
+
parsed.raybase = {
|
|
1507
|
+
...(parsed.raybase ?? {}),
|
|
1508
|
+
modules: {
|
|
1509
|
+
...(parsed.raybase?.modules ?? {}),
|
|
1510
|
+
guide: { enabled, package: "@raybase/guide" }
|
|
1511
|
+
}
|
|
1512
|
+
};
|
|
1513
|
+
parsed.dependencies = parsed.dependencies ?? {};
|
|
1514
|
+
if (enabled) {
|
|
1515
|
+
for (const [name, range] of Object.entries(GUIDE_DEPENDENCIES)) {
|
|
1516
|
+
parsed.dependencies[name] = localRaybasePackageRange(name, range, localRoot);
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
else {
|
|
1520
|
+
delete parsed.dependencies["@assistant-ui/react"];
|
|
1521
|
+
delete parsed.dependencies["@raybase/agent-ui"];
|
|
1522
|
+
delete parsed.dependencies["@raybase/guide"];
|
|
1523
|
+
}
|
|
1524
|
+
writeFileSync(packageFile, `${JSON.stringify(parsed, null, 2)}\n`);
|
|
1525
|
+
if (enabled) {
|
|
1526
|
+
copyGuideTemplate(projectDir, template, localRoot, keep);
|
|
1527
|
+
patchGuideServerModule(projectDir, template, true);
|
|
1528
|
+
patchGuideWidget(projectDir, template, true);
|
|
1529
|
+
patchGuideCss(projectDir, template, true);
|
|
1530
|
+
enableTemplateAi(projectDir, template);
|
|
1531
|
+
if (!docsEnabled)
|
|
1532
|
+
disableGuideDocsSurface(projectDir, template);
|
|
1533
|
+
}
|
|
1534
|
+
else {
|
|
1535
|
+
disableTemplateAi(projectDir, template);
|
|
1536
|
+
patchGuideCss(projectDir, template, false);
|
|
1537
|
+
pruneGuideFiles(projectDir, template);
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
function copySiteDocsTemplate(projectDir, template, localRoot, keep = noKeptFiles) {
|
|
1541
|
+
if (template !== "astro-emdash")
|
|
1542
|
+
return;
|
|
1543
|
+
const sourceRoot = localRoot ? join(localRoot, "packages/docs/templates/astro-emdash") : join(packageRoot, "modules/docs/templates/astro-emdash");
|
|
1544
|
+
const fallbackRoot = join(packageRoot, "templates/astro-emdash");
|
|
1545
|
+
const root = existsSync(sourceRoot) ? sourceRoot : fallbackRoot;
|
|
1546
|
+
for (const rel of ASTRO_EMDASH_SITE_DOCS_FILES) {
|
|
1547
|
+
if (keep.has(rel))
|
|
1548
|
+
continue;
|
|
1549
|
+
const source = join(root, rel);
|
|
1550
|
+
const target = join(projectDir, rel);
|
|
1551
|
+
if (!existsSync(source))
|
|
1552
|
+
throw new Error(`Docs module template file ${rel} is missing at ${source}.`);
|
|
1553
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
1554
|
+
cpSync(source, target);
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
function configureSiteDocsPackage(projectDir) {
|
|
1558
|
+
const file = join(projectDir, "site/package.json");
|
|
1559
|
+
if (!existsSync(file))
|
|
1560
|
+
return;
|
|
1561
|
+
const parsed = JSON.parse(readFileSync(file, "utf8"));
|
|
1562
|
+
parsed.dependencies = {
|
|
1563
|
+
...(parsed.dependencies ?? {}),
|
|
1564
|
+
"fumadocs-core": "16.10.3",
|
|
1565
|
+
"fumadocs-ui": "16.10.3",
|
|
1566
|
+
"lucide-react": "1.18.0"
|
|
1567
|
+
};
|
|
1568
|
+
parsed.devDependencies = {
|
|
1569
|
+
...(parsed.devDependencies ?? {}),
|
|
1570
|
+
"fumadocs-mdx": "15.0.12",
|
|
1571
|
+
"@types/mdx": "^2.0.14"
|
|
1572
|
+
};
|
|
1573
|
+
writeFileSync(file, `${JSON.stringify(parsed, null, 2)}\n`);
|
|
1574
|
+
}
|
|
1575
|
+
function patchSiteDocsAstroConfig(projectDir, enabled) {
|
|
1576
|
+
const file = join(projectDir, "site/astro.config.mjs");
|
|
1577
|
+
if (!existsSync(file))
|
|
1578
|
+
return;
|
|
1579
|
+
let source = readFileSync(file, "utf8");
|
|
1580
|
+
if (enabled) {
|
|
1581
|
+
if (!source.includes('from "fumadocs-mdx/vite"'))
|
|
1582
|
+
source = ensureImportLine(source, 'import mdx from "fumadocs-mdx/vite";\n');
|
|
1583
|
+
if (!/\bmdx\(\)/.test(source))
|
|
1584
|
+
source = source.replace(/vite:\s*\{\s*/, (match) => `${match}plugins: [mdx()],\n `);
|
|
1585
|
+
}
|
|
1586
|
+
else {
|
|
1587
|
+
source = source.replace(/^import mdx from "fumadocs-mdx\/vite";\n/m, "").replace(/\s*plugins:\s*\[\s*mdx\(\)\s*\],?\n/m, "");
|
|
1588
|
+
}
|
|
1589
|
+
writeFileSync(file, source);
|
|
1590
|
+
}
|
|
1591
|
+
function ensureSiteSourceIgnored(projectDir) {
|
|
1592
|
+
const file = join(projectDir, "site/.gitignore");
|
|
1593
|
+
const source = existsSync(file) ? readFileSync(file, "utf8") : "";
|
|
1594
|
+
if (/(^|\n)\.source\/?(\n|$)/.test(source))
|
|
1595
|
+
return;
|
|
1596
|
+
writeFileSync(file, `${source.replace(/\s*$/, "")}\n.source/\n`);
|
|
1597
|
+
}
|
|
1598
|
+
function patchDocsServerModule(projectDir, template, placement) {
|
|
1599
|
+
const file = join(projectDir, template === "react-router" ? "app/raybase.server.ts" : "src/raybase.server.ts");
|
|
1600
|
+
if (!existsSync(file))
|
|
1601
|
+
return;
|
|
1602
|
+
let source = readFileSync(file, "utf8");
|
|
1603
|
+
source = ensureExactImport(source, "@raybase/docs", "docsModule");
|
|
1604
|
+
const guideEnabled = exactImportPattern("@raybase/guide", "guideModule").test(source);
|
|
1605
|
+
const apiEnabled = exactImportPattern("./api/operations", "api").test(source);
|
|
1606
|
+
source = replaceNamedRegion(source, "raybase:modules", renderModulesRegion({ template, docs: true, guide: guideEnabled, api: apiEnabled, docsPlacement: placement }));
|
|
1607
|
+
source = ensureRaybaseEnvImport(source);
|
|
1608
|
+
writeFileSync(file, source);
|
|
1609
|
+
}
|
|
1610
|
+
function localRaybasePackageRange(name, range, localRoot) {
|
|
1611
|
+
if (!localRoot || !name.startsWith("@raybase/"))
|
|
1612
|
+
return range;
|
|
1613
|
+
if (name === "@raybase/galley")
|
|
1614
|
+
return localGalleyPackageRange(localRoot);
|
|
1615
|
+
return `link:${join(localRoot, "packages", name.split("/")[1] ?? "")}`;
|
|
1616
|
+
}
|
|
1617
|
+
function localGalleyPackageRange(localRoot) {
|
|
1618
|
+
if (!localRoot)
|
|
1619
|
+
return RAYBASE_PACKAGE_RANGES["@raybase/galley"];
|
|
1620
|
+
for (const candidate of [
|
|
1621
|
+
resolve(localRoot, "../galley"),
|
|
1622
|
+
resolve(localRoot, "../../galley"),
|
|
1623
|
+
resolve(localRoot, "../../../galley")
|
|
1624
|
+
]) {
|
|
1625
|
+
if (existsSync(join(candidate, "package.json")))
|
|
1626
|
+
return `link:${candidate}`;
|
|
1627
|
+
}
|
|
1628
|
+
return RAYBASE_PACKAGE_RANGES["@raybase/galley"];
|
|
1629
|
+
}
|
|
1630
|
+
function copyGuideTemplate(projectDir, template, localRoot, keep = noKeptFiles) {
|
|
1631
|
+
const sourceRoot = guideTemplateRoot(template, localRoot);
|
|
1632
|
+
for (const rel of MODULE_FILES.guide[template]) {
|
|
1633
|
+
if (keep.has(rel))
|
|
1634
|
+
continue;
|
|
1635
|
+
const source = join(sourceRoot, rel);
|
|
1636
|
+
const target = join(projectDir, rel);
|
|
1637
|
+
if (!existsSync(source))
|
|
1638
|
+
throw new Error(`Guide module template file ${rel} is missing at ${source}.`);
|
|
1639
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
1640
|
+
cpSync(source, target);
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
function guideTemplateRoot(template, localRoot) {
|
|
1644
|
+
if (localRoot)
|
|
1645
|
+
return join(localRoot, "packages/guide/templates", template);
|
|
1646
|
+
const bundled = join(packageRoot, "modules/guide/templates", template);
|
|
1647
|
+
if (existsSync(bundled))
|
|
1648
|
+
return bundled;
|
|
1649
|
+
return join(packageRoot, "templates", template);
|
|
1650
|
+
}
|
|
1651
|
+
function configureApi(projectDir, template, enabled, localRoot, keep = noKeptFiles) {
|
|
1652
|
+
const packageFile = join(projectDir, "package.json");
|
|
1653
|
+
const parsed = JSON.parse(readFileSync(packageFile, "utf8"));
|
|
1654
|
+
parsed.raybase = {
|
|
1655
|
+
...(parsed.raybase ?? {}),
|
|
1656
|
+
modules: {
|
|
1657
|
+
...(parsed.raybase?.modules ?? {}),
|
|
1658
|
+
api: { enabled, package: "@raybase/api" }
|
|
1659
|
+
}
|
|
1660
|
+
};
|
|
1661
|
+
parsed.dependencies = parsed.dependencies ?? {};
|
|
1662
|
+
if (enabled) {
|
|
1663
|
+
parsed.dependencies["@raybase/api"] = localRoot ? `link:${join(localRoot, "packages/api")}` : RAYBASE_PACKAGE_RANGES["@raybase/api"];
|
|
1664
|
+
copyApiTemplate(projectDir, template, localRoot, keep);
|
|
1665
|
+
patchApiServerModule(projectDir, template, true);
|
|
1666
|
+
}
|
|
1667
|
+
else {
|
|
1668
|
+
delete parsed.dependencies["@raybase/api"];
|
|
1669
|
+
pruneApiFiles(projectDir, template);
|
|
1670
|
+
patchApiServerModule(projectDir, template, false);
|
|
1671
|
+
}
|
|
1672
|
+
writeFileSync(packageFile, `${JSON.stringify(parsed, null, 2)}\n`);
|
|
1673
|
+
}
|
|
1674
|
+
function copyApiTemplate(projectDir, template, localRoot, keep = noKeptFiles) {
|
|
1675
|
+
const sourceRoot = apiTemplateRoot(template, localRoot);
|
|
1676
|
+
for (const rel of MODULE_FILES.api[template]) {
|
|
1677
|
+
if (keep.has(rel))
|
|
1678
|
+
continue;
|
|
1679
|
+
const source = join(sourceRoot, rel);
|
|
1680
|
+
const target = join(projectDir, rel);
|
|
1681
|
+
if (!existsSync(source))
|
|
1682
|
+
throw new Error(`API module template file ${rel} is missing at ${source}.`);
|
|
1683
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
1684
|
+
cpSync(source, target);
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
function apiTemplateRoot(template, localRoot) {
|
|
1688
|
+
if (localRoot)
|
|
1689
|
+
return join(localRoot, "packages/api/templates", template);
|
|
1690
|
+
const bundled = join(packageRoot, "modules/api/templates", template);
|
|
1691
|
+
if (existsSync(bundled))
|
|
1692
|
+
return bundled;
|
|
1693
|
+
return join(packageRoot, "templates", template);
|
|
1694
|
+
}
|
|
1695
|
+
function pruneApiFiles(projectDir, template) {
|
|
1696
|
+
for (const rel of MODULE_FILES.api[template])
|
|
1697
|
+
rmSync(join(projectDir, rel), { recursive: true, force: true });
|
|
1698
|
+
}
|
|
1699
|
+
function patchApiServerModule(projectDir, template, enabled) {
|
|
1700
|
+
const file = join(projectDir, template === "react-router" ? "app/raybase.server.ts" : "src/raybase.server.ts");
|
|
1701
|
+
if (!existsSync(file))
|
|
1702
|
+
return;
|
|
1703
|
+
let source = readFileSync(file, "utf8");
|
|
1704
|
+
if (enabled)
|
|
1705
|
+
source = ensureExactImport(source, "./api/operations", "api");
|
|
1706
|
+
else
|
|
1707
|
+
source = source.replace(exactImportPattern("./api/operations", "api"), "");
|
|
1708
|
+
const docsEnabled = exactImportPattern("@raybase/docs", "docsModule").test(source);
|
|
1709
|
+
const guideEnabled = exactImportPattern("@raybase/guide", "guideModule").test(source);
|
|
1710
|
+
source = replaceNamedRegion(source, "raybase:modules", renderModulesRegion({ template, docs: docsEnabled, guide: guideEnabled, api: enabled, docsPlacement: currentDocsPlacement(projectDir) }));
|
|
1711
|
+
if (docsEnabled || guideEnabled)
|
|
1712
|
+
source = ensureRaybaseEnvImport(source);
|
|
1713
|
+
writeFileSync(file, source);
|
|
1714
|
+
}
|
|
1715
|
+
function recordScaffoldedModules(projectDir, template, selectedModules, docsPlacement, keep = noKeptFiles) {
|
|
1716
|
+
const packageJson = JSON.parse(readFileSync(join(projectDir, "package.json"), "utf8"));
|
|
1717
|
+
const sitePackageJson = docsPlacement === "site" && existsSync(join(projectDir, "site/package.json"))
|
|
1718
|
+
? JSON.parse(readFileSync(join(projectDir, "site/package.json"), "utf8"))
|
|
1719
|
+
: {};
|
|
1720
|
+
const now = new Date().toISOString();
|
|
1721
|
+
const modules = {};
|
|
1722
|
+
for (const id of selectedModules) {
|
|
1723
|
+
const moduleFiles = id === "docs" && template === "astro-emdash" && docsPlacement === "site" ? [...ASTRO_EMDASH_SITE_DOCS_FILES] : MODULE_FILES[id][template];
|
|
1724
|
+
const files = moduleFiles
|
|
1725
|
+
.filter((file) => existsSync(join(projectDir, file)))
|
|
1726
|
+
.map((file) => {
|
|
1727
|
+
const sha = sha256File(join(projectDir, file));
|
|
1728
|
+
return {
|
|
1729
|
+
installedSha256: sha,
|
|
1730
|
+
// A file the starter supplies in place of the module's is the app's own.
|
|
1731
|
+
mode: keep.has(file) ? "editable" : moduleFileMode(id, template, file),
|
|
1732
|
+
path: file,
|
|
1733
|
+
sourceSha256: sha
|
|
1734
|
+
};
|
|
1735
|
+
});
|
|
1736
|
+
const dependencySource = id === "docs" && docsPlacement === "site" ? { ...(packageJson.dependencies ?? {}), ...(sitePackageJson.dependencies ?? {}) } : packageJson.dependencies;
|
|
1737
|
+
const devDependencySource = id === "docs" && docsPlacement === "site" ? { ...(packageJson.devDependencies ?? {}), ...(sitePackageJson.devDependencies ?? {}) } : packageJson.devDependencies;
|
|
1738
|
+
modules[id] = {
|
|
1739
|
+
commands: MODULE_COMMANDS[id],
|
|
1740
|
+
dependencies: moduleDependencyRecord(dependencySource, id),
|
|
1741
|
+
devDependencies: moduleDependencyRecord(devDependencySource, id),
|
|
1742
|
+
doctorHooks: [id],
|
|
1743
|
+
enabled: true,
|
|
1744
|
+
files,
|
|
1745
|
+
id,
|
|
1746
|
+
...(id === "docs" ? { placement: docsPlacement } : {}),
|
|
1747
|
+
installedAt: now,
|
|
1748
|
+
nextSteps: id === "guide"
|
|
1749
|
+
? [
|
|
1750
|
+
`Keep ${docsPlacement === "site" ? "site/content/docs" : "content/docs"} and content/guide current with what the app does and what Guide can do.`,
|
|
1751
|
+
"Add narrow Guide actions for intended user workflows, then run raybase guide index after knowledge changes.",
|
|
1752
|
+
"Run raybase doctor."
|
|
1753
|
+
]
|
|
1754
|
+
: ["Commit .raybase/modules.json with the app.", "Run raybase doctor."],
|
|
1755
|
+
packageName: MODULE_PACKAGES[id],
|
|
1756
|
+
skills: MODULE_SKILLS[id],
|
|
1757
|
+
template,
|
|
1758
|
+
updatedAt: now,
|
|
1759
|
+
version: "0.1.0"
|
|
1760
|
+
};
|
|
1761
|
+
}
|
|
1762
|
+
const file = join(projectDir, ".raybase/modules.json");
|
|
1763
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
1764
|
+
writeFileSync(file, stableJson({ schemaVersion: 1, updatedAt: now, modules }));
|
|
1765
|
+
}
|
|
1766
|
+
function moduleDependencyRecord(dependencies, id) {
|
|
1767
|
+
const names = id === "docs"
|
|
1768
|
+
? ["@raybase/docs", "fumadocs-core", "fumadocs-ui", "lucide-react", "fumadocs-mdx", "@types/mdx"]
|
|
1769
|
+
: id === "guide"
|
|
1770
|
+
? ["@assistant-ui/react", "@raybase/agent-ui", "@raybase/guide", "lucide-react"]
|
|
1771
|
+
: ["@raybase/api"];
|
|
1772
|
+
return Object.fromEntries(names.flatMap((name) => (dependencies?.[name] ? [[name, dependencies[name]]] : [])));
|
|
1773
|
+
}
|
|
1774
|
+
function enableTemplateAi(projectDir, template) {
|
|
1775
|
+
const file = join(projectDir, "wrangler.jsonc");
|
|
1776
|
+
const source = readFileSync(file, "utf8");
|
|
1777
|
+
const parsed = parse(source);
|
|
1778
|
+
if (!parsed.ai) {
|
|
1779
|
+
writeFileSync(file, editJsoncValue(source, ["ai"], { binding: "AI" }));
|
|
1780
|
+
}
|
|
1781
|
+
if (template === "tanstack-start") {
|
|
1782
|
+
const latest = readFileSync(file, "utf8");
|
|
1783
|
+
writeFileSync(file, removeLocalAiPlaceholder(editJsoncValue(latest, ["env", "local-dev", "ai"], { binding: "AI", remote: true })));
|
|
1784
|
+
}
|
|
1785
|
+
enableTemplateAiConfig(projectDir, template);
|
|
1786
|
+
}
|
|
1787
|
+
function enableTemplateAiConfig(projectDir, template) {
|
|
1788
|
+
const file = join(projectDir, template === "react-router" ? "app/db/schema.ts" : "src/raybase.config.ts");
|
|
1789
|
+
if (!existsSync(file))
|
|
1790
|
+
return;
|
|
1791
|
+
const source = readFileSync(file, "utf8");
|
|
1792
|
+
if (/^\s*ai\s*:/m.test(source))
|
|
1793
|
+
return;
|
|
1794
|
+
// Keeps the Gateway and BYOK hints in the template's comment above the block.
|
|
1795
|
+
let next = source.replace(/\n\s*\/\/ To enable user-facing AI (?:chat )?features, run `raybase ai enable`\.\n([\s\S]*?)[ \t]*\/\/ ai: \{[\s\S]*?\n\s*\/\/ \}\n?/m, (_match, hints) => `\n${hints}${DEFAULT_AI_CONFIG_BLOCK}\n`);
|
|
1796
|
+
if (next === source && template === "react-router") {
|
|
1797
|
+
next = source.replace(/realtime:\s*\{\s*enabled:\s*true\s*\}/, (match) => `${match},\n${DEFAULT_AI_CONFIG_BLOCK}`);
|
|
1798
|
+
}
|
|
1799
|
+
if (next === source) {
|
|
1800
|
+
next = source.replace(/\n\}\s+satisfies\s+RaybaseConfig;/, `,\n${DEFAULT_AI_CONFIG_BLOCK}\n} satisfies RaybaseConfig;`);
|
|
1801
|
+
}
|
|
1802
|
+
if (next !== source)
|
|
1803
|
+
writeFileSync(file, next);
|
|
1804
|
+
}
|
|
1805
|
+
function configureAiDefaultModel(projectDir, template, model) {
|
|
1806
|
+
const file = join(projectDir, template === "react-router" ? "app/db/schema.ts" : "src/raybase.config.ts");
|
|
1807
|
+
if (!existsSync(file))
|
|
1808
|
+
return;
|
|
1809
|
+
const source = readFileSync(file, "utf8");
|
|
1810
|
+
const escaped = JSON.stringify(model);
|
|
1811
|
+
const existingModelPattern = /(\n\s*defaults:\s*\{\n)(\s*)model:\s*"[^"]*",/m;
|
|
1812
|
+
let next = source.replace(existingModelPattern, `$1$2model: ${escaped},`);
|
|
1813
|
+
if (!existingModelPattern.test(source)) {
|
|
1814
|
+
next = source.replace(/(\n\s*defaults:\s*\{\n)/m, `$1 model: ${escaped},\n`);
|
|
1815
|
+
}
|
|
1816
|
+
if (next !== source)
|
|
1817
|
+
writeFileSync(file, next);
|
|
1818
|
+
}
|
|
1819
|
+
async function resolveRecommendedGuideAiModel(input) {
|
|
1820
|
+
if (!input.offline) {
|
|
1821
|
+
const remote = await fetchRecommendedGuideAiModel().catch(() => null);
|
|
1822
|
+
if (remote)
|
|
1823
|
+
return remote;
|
|
1824
|
+
}
|
|
1825
|
+
return bundledRecommendedGuideAiModel(input.localRoot) ?? FALLBACK_RECOMMENDED_GUIDE_MODEL;
|
|
1826
|
+
}
|
|
1827
|
+
async function fetchRecommendedGuideAiModel() {
|
|
1828
|
+
const response = await fetch(RECOMMENDED_MODELS_URL, { headers: { accept: "application/json" } });
|
|
1829
|
+
if (!response.ok)
|
|
1830
|
+
return null;
|
|
1831
|
+
return recommendedGuideAiModelFromManifest(await response.json());
|
|
1832
|
+
}
|
|
1833
|
+
function bundledRecommendedGuideAiModel(localRoot) {
|
|
1834
|
+
const candidates = [
|
|
1835
|
+
localRoot ? join(localRoot, "apps/landing/models/recommended.json") : null,
|
|
1836
|
+
join(packageRoot, "models/recommended.json")
|
|
1837
|
+
].filter((candidate) => Boolean(candidate));
|
|
1838
|
+
for (const candidate of candidates) {
|
|
1839
|
+
if (!existsSync(candidate))
|
|
1840
|
+
continue;
|
|
1841
|
+
const model = recommendedGuideAiModelFromManifest(JSON.parse(readFileSync(candidate, "utf8")));
|
|
1842
|
+
if (model)
|
|
1843
|
+
return model;
|
|
1844
|
+
}
|
|
1845
|
+
return null;
|
|
1846
|
+
}
|
|
1847
|
+
function recommendedGuideAiModelFromManifest(value) {
|
|
1848
|
+
if (!value || typeof value !== "object")
|
|
1849
|
+
return null;
|
|
1850
|
+
const manifest = value;
|
|
1851
|
+
if (manifest.schemaVersion !== 1)
|
|
1852
|
+
return null;
|
|
1853
|
+
const model = manifest.defaults?.guide?.model ?? manifest.defaults?.chat?.model;
|
|
1854
|
+
return typeof model === "string" && model.trim() ? model.trim() : null;
|
|
1855
|
+
}
|
|
1856
|
+
function disableTemplateAi(projectDir, template) {
|
|
1857
|
+
const wranglerFile = join(projectDir, "wrangler.jsonc");
|
|
1858
|
+
replaceInFile(wranglerFile, [
|
|
1859
|
+
[/,\n\s*"ai":\s*\{\n\s*"binding":\s*"AI"\n\s*\}/m, ""],
|
|
1860
|
+
[/\n\s*"ai":\s*\{\n\s*"binding":\s*"AI"\n\s*\},/m, "\n"]
|
|
1861
|
+
]);
|
|
1862
|
+
if (template === "tanstack-start") {
|
|
1863
|
+
const latest = readFileSync(wranglerFile, "utf8");
|
|
1864
|
+
writeFileSync(wranglerFile, editJsoncValue(latest, ["env", "local-dev", "ai"], undefined));
|
|
1865
|
+
}
|
|
1866
|
+
const configFile = join(projectDir, template === "react-router" ? "app/db/schema.ts" : "src/raybase.config.ts");
|
|
1867
|
+
replaceInFile(configFile, [
|
|
1868
|
+
[/\n\s*ai:\s*\{\n\s*enabled:\s*true,[\s\S]*?\n\s*maxConversationMessages:\s*40\n\s*\}\n\s*\},?/m, ""]
|
|
1869
|
+
]);
|
|
1870
|
+
if (existsSync(configFile)) {
|
|
1871
|
+
const source = readFileSync(configFile, "utf8");
|
|
1872
|
+
if (!/To enable user-facing AI (?:chat )?features/.test(source)) {
|
|
1873
|
+
const next = source.replace(/\n\s*\/\/ To add app-specific user-facing agents, define them in src\/ai\/agents\.ts and pass\n\s*\/\/ agents to createRaybaseApp in src\/raybase\.server\.ts\./m, `\n${AI_CONFIG_PLACEHOLDER}`);
|
|
1874
|
+
if (next !== source)
|
|
1875
|
+
writeFileSync(configFile, next);
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
function pruneDocsFiles(projectDir, template, options = {}) {
|
|
1880
|
+
const files = template === "react-router"
|
|
1881
|
+
? [
|
|
1882
|
+
"source.config.ts",
|
|
1883
|
+
"content",
|
|
1884
|
+
"app/components/mdx.tsx",
|
|
1885
|
+
"app/lib/source.ts",
|
|
1886
|
+
"app/lib/layout.shared.tsx",
|
|
1887
|
+
"app/routes/docs.tsx",
|
|
1888
|
+
"app/routes/docs.$.tsx",
|
|
1889
|
+
"app/routes/docs.api.search.ts"
|
|
1890
|
+
]
|
|
1891
|
+
: [
|
|
1892
|
+
"source.config.ts",
|
|
1893
|
+
"content",
|
|
1894
|
+
"src/components/docs-page-actions.tsx",
|
|
1895
|
+
"src/components/mdx.tsx",
|
|
1896
|
+
"src/lib/docs-server.ts",
|
|
1897
|
+
"src/lib/llm-text.ts",
|
|
1898
|
+
"src/lib/source.ts",
|
|
1899
|
+
"src/lib/layout.shared.tsx",
|
|
1900
|
+
"src/docs",
|
|
1901
|
+
"src/styles-docs.css",
|
|
1902
|
+
"src/routes/docs.index.tsx",
|
|
1903
|
+
"src/routes/docs.tsx",
|
|
1904
|
+
"src/routes/docs"
|
|
1905
|
+
];
|
|
1906
|
+
for (const file of files)
|
|
1907
|
+
rmSync(join(projectDir, file), { recursive: true, force: true });
|
|
1908
|
+
if (!options.keepServerModule)
|
|
1909
|
+
removeServerModule(projectDir, template, "docs");
|
|
1910
|
+
replaceInFile(join(projectDir, template === "react-router" ? "app/db/schema.ts" : "src/raybase.config.ts"), [
|
|
1911
|
+
[/\n\s*docs:\s*\{[\s\S]*?\n\s*\},/m, ""]
|
|
1912
|
+
]);
|
|
1913
|
+
replaceInFile(join(projectDir, template === "react-router" ? "app/app.css" : "src/styles.css"), [
|
|
1914
|
+
[/^\/\* Keep after app Tailwind integrations so Fumadocs layout utilities win the cascade in Vite dev\. \*\/\n/m, ""],
|
|
1915
|
+
[/^@import "fumadocs-ui\/style\.css";\n/m, ""],
|
|
1916
|
+
[/^@import "fumadocs-ui\/css\/neutral\.css";\n/m, ""],
|
|
1917
|
+
[/^@import "fumadocs-ui\/css\/preset\.css";\n/m, ""]
|
|
1918
|
+
]);
|
|
1919
|
+
if (template === "tanstack-start") {
|
|
1920
|
+
replaceInFile(join(projectDir, "src/routes/__root.tsx"), [
|
|
1921
|
+
[/^import \{ RootProvider \} from "fumadocs-ui\/provider\/tanstack";\n/m, ""],
|
|
1922
|
+
[
|
|
1923
|
+
/ <RootProvider search=\{\{ options: \{ api: "\/docs\/api\/search" \} \}\}>\n \{devServerSsr \? <LoadingShell \/> : <Outlet \/>\}\n <\/RootProvider>/m,
|
|
1924
|
+
" {devServerSsr ? <LoadingShell /> : <Outlet />}"
|
|
1925
|
+
]
|
|
1926
|
+
]);
|
|
1927
|
+
}
|
|
1928
|
+
replaceInFile(join(projectDir, "vite.config.ts"), [
|
|
1929
|
+
[/^import mdx from "fumadocs-mdx\/vite";\n/m, ""],
|
|
1930
|
+
[/\bmdx\(\),\s*/g, ""]
|
|
1931
|
+
]);
|
|
1932
|
+
replaceInFile(join(projectDir, "AGENTS.md"), [
|
|
1933
|
+
[/^- `?\/docs`? lives in `?content\/docs`?; use `?\.(?:agents|claude)\/skills\/raybase-docs-writing\/SKILL\.md`? before changing docs\.\n/m, ""],
|
|
1934
|
+
[/^- Fumadocs is served by the app at `?\/docs`?; search is served at `?\/docs\/api\/search`?\.\n/m, ""],
|
|
1935
|
+
[/^- `?\/docs`? is a public, non-embedded React Router docs site outside `?\/app`?; search is served at `?\/docs\/api\/search`?, not `?\/api\/search`?\.\n/m, ""]
|
|
1936
|
+
]);
|
|
1937
|
+
replaceInFile(join(projectDir, template === "react-router" ? "app/routes/_index.tsx" : "src/routes/_app/index.tsx"), [
|
|
1938
|
+
[/\n\s*<a className="[^"]*" href="\/docs" data-raybase-docs-nav>\n\s*Docs\n\s*<\/a>/m, ""]
|
|
1939
|
+
]);
|
|
1940
|
+
}
|
|
1941
|
+
function pruneGuideFiles(projectDir, template) {
|
|
1942
|
+
const files = template === "react-router"
|
|
1943
|
+
? ["app/components/guide-widget.tsx", "app/guide"]
|
|
1944
|
+
: ["src/components/guide-widget.tsx", "src/guide"];
|
|
1945
|
+
for (const file of files)
|
|
1946
|
+
rmSync(join(projectDir, file), { recursive: true, force: true });
|
|
1947
|
+
patchGuideServerModule(projectDir, template, false);
|
|
1948
|
+
patchGuideWidget(projectDir, template, false);
|
|
1949
|
+
}
|
|
1950
|
+
function disableGuideDocsSurface(projectDir, template) {
|
|
1951
|
+
const file = join(projectDir, template === "react-router" ? "app/guide/config.ts" : "src/guide/config.ts");
|
|
1952
|
+
replaceInFile(file, [
|
|
1953
|
+
[/docs: \{ enabled: true, audience: "signed-in" \}/, 'docs: { enabled: false, audience: "signed-in" }']
|
|
1954
|
+
]);
|
|
1955
|
+
}
|
|
1956
|
+
function patchGuideServerModule(projectDir, template, enabled) {
|
|
1957
|
+
const file = join(projectDir, template === "react-router" ? "app/raybase.server.ts" : "src/raybase.server.ts");
|
|
1958
|
+
if (!existsSync(file))
|
|
1959
|
+
return;
|
|
1960
|
+
let source = readFileSync(file, "utf8");
|
|
1961
|
+
if (enabled) {
|
|
1962
|
+
source = ensureExactImport(source, "@raybase/guide", "guideModule");
|
|
1963
|
+
source = ensureExactImport(source, "./guide/actions", "guideActions");
|
|
1964
|
+
source = ensureExactImport(source, "./guide/config", "guideConfig");
|
|
1965
|
+
source = ensureExactImport(source, "./guide/corpus", "guideCorpus");
|
|
1966
|
+
}
|
|
1967
|
+
else {
|
|
1968
|
+
source = source
|
|
1969
|
+
.replace(exactImportPattern("@raybase/guide", "guideModule"), "")
|
|
1970
|
+
.replace(exactImportPattern("./guide/actions", "guideActions"), "")
|
|
1971
|
+
.replace(exactImportPattern("./guide/config", "guideConfig"), "")
|
|
1972
|
+
.replace(exactImportPattern("./guide/corpus", "guideCorpus"), "");
|
|
1973
|
+
}
|
|
1974
|
+
const docsEnabled = exactImportPattern("@raybase/docs", "docsModule").test(source);
|
|
1975
|
+
const apiEnabled = exactImportPattern("./api/operations", "api").test(source);
|
|
1976
|
+
source = replaceNamedRegion(source, "raybase:modules", renderModulesRegion({ template, docs: docsEnabled, guide: enabled, api: apiEnabled, docsPlacement: currentDocsPlacement(projectDir) }));
|
|
1977
|
+
if (docsEnabled || enabled)
|
|
1978
|
+
source = ensureRaybaseEnvImport(source);
|
|
1979
|
+
writeFileSync(file, source);
|
|
1980
|
+
}
|
|
1981
|
+
function patchGuideWidget(projectDir, template, enabled) {
|
|
1982
|
+
const file = join(projectDir, template === "react-router" ? "app/root.tsx" : "src/routes/__root.tsx");
|
|
1983
|
+
if (!existsSync(file))
|
|
1984
|
+
return;
|
|
1985
|
+
let source = readFileSync(file, "utf8");
|
|
1986
|
+
const importLine = template === "react-router" ? 'import { GuideWidget } from "./components/guide-widget";\n' : 'import { GuideWidget } from "../components/guide-widget";\n';
|
|
1987
|
+
const renderLine = template === "react-router" ? "<GuideWidget />" : "{devServerSsr ? null : <GuideWidget />}";
|
|
1988
|
+
if (enabled) {
|
|
1989
|
+
source = ensureImportLine(source, importLine);
|
|
1990
|
+
source = replaceNamedRegion(source, "raybase:guide-widget", renderLine);
|
|
1991
|
+
}
|
|
1992
|
+
else {
|
|
1993
|
+
source = source.replace(importLine, "");
|
|
1994
|
+
source = replaceNamedRegion(source, "raybase:guide-widget", "");
|
|
1995
|
+
}
|
|
1996
|
+
writeFileSync(file, source);
|
|
1997
|
+
}
|
|
1998
|
+
function patchGuideCss(projectDir, template, enabled) {
|
|
1999
|
+
const file = join(projectDir, template === "react-router" ? "app/app.css" : "src/styles.css");
|
|
2000
|
+
if (!existsSync(file))
|
|
2001
|
+
return;
|
|
2002
|
+
let source = readFileSync(file, "utf8");
|
|
2003
|
+
const line = '@source "../node_modules/@raybase/agent-ui/dist";\n';
|
|
2004
|
+
if (enabled) {
|
|
2005
|
+
if (!source.includes(line))
|
|
2006
|
+
source = source.replace(/^@import "tailwindcss";\n/m, `@import "tailwindcss";\n${line}`);
|
|
2007
|
+
}
|
|
2008
|
+
else {
|
|
2009
|
+
source = source.replace(line, "");
|
|
2010
|
+
}
|
|
2011
|
+
writeFileSync(file, source);
|
|
2012
|
+
}
|
|
2013
|
+
function removeServerModule(projectDir, template, module) {
|
|
2014
|
+
const file = join(projectDir, template === "react-router" ? "app/raybase.server.ts" : "src/raybase.server.ts");
|
|
2015
|
+
if (!existsSync(file))
|
|
2016
|
+
return;
|
|
2017
|
+
let source = readFileSync(file, "utf8");
|
|
2018
|
+
const docsEnabled = module === "docs" ? false : exactImportPattern("@raybase/docs", "docsModule").test(source);
|
|
2019
|
+
const guideEnabled = module === "guide" ? false : exactImportPattern("@raybase/guide", "guideModule").test(source);
|
|
2020
|
+
const apiEnabled = module === "api" ? false : exactImportPattern("./api/operations", "api").test(source);
|
|
2021
|
+
if (module === "docs") {
|
|
2022
|
+
source = source.replace(exactImportPattern("@raybase/docs", "docsModule"), "");
|
|
2023
|
+
}
|
|
2024
|
+
else if (module === "guide") {
|
|
2025
|
+
source = source
|
|
2026
|
+
.replace(exactImportPattern("@raybase/guide", "guideModule"), "")
|
|
2027
|
+
.replace(exactImportPattern("./guide/actions", "guideActions"), "")
|
|
2028
|
+
.replace(exactImportPattern("./guide/config", "guideConfig"), "")
|
|
2029
|
+
.replace(exactImportPattern("./guide/corpus", "guideCorpus"), "");
|
|
2030
|
+
}
|
|
2031
|
+
else {
|
|
2032
|
+
source = source.replace(exactImportPattern("./api/operations", "api"), "");
|
|
2033
|
+
}
|
|
2034
|
+
source = replaceNamedRegion(source, "raybase:modules", renderModulesRegion({ template, docs: docsEnabled, guide: guideEnabled, api: apiEnabled, docsPlacement: currentDocsPlacement(projectDir) }));
|
|
2035
|
+
if (docsEnabled || guideEnabled)
|
|
2036
|
+
source = ensureRaybaseEnvImport(source);
|
|
2037
|
+
writeFileSync(file, source);
|
|
2038
|
+
}
|
|
2039
|
+
function replaceInFile(file, replacements) {
|
|
2040
|
+
if (!existsSync(file))
|
|
2041
|
+
return;
|
|
2042
|
+
const source = readFileSync(file, "utf8");
|
|
2043
|
+
let next = source;
|
|
2044
|
+
for (const [pattern, replacement] of replacements)
|
|
2045
|
+
next = next.replace(pattern, replacement);
|
|
2046
|
+
if (next !== source)
|
|
2047
|
+
writeFileSync(file, next);
|
|
2048
|
+
}
|
|
2049
|
+
function currentDocsPlacement(projectDir) {
|
|
2050
|
+
try {
|
|
2051
|
+
const parsed = JSON.parse(readFileSync(join(projectDir, "package.json"), "utf8"));
|
|
2052
|
+
return parsed.raybase?.modules?.docs?.placement === "site" ? "site" : "spine";
|
|
2053
|
+
}
|
|
2054
|
+
catch {
|
|
2055
|
+
return "spine";
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
function editJsoncValue(source, path, value) {
|
|
2059
|
+
return applyEdits(source, modify(source, path, value, { formattingOptions: { insertSpaces: true, tabSize: 2 } }));
|
|
2060
|
+
}
|
|
2061
|
+
function removeLocalAiPlaceholder(source) {
|
|
2062
|
+
return source.replace(/\n\s*\/\/ Live local Workers AI uses a remote binding and Wrangler login\.\n\s*\/\/ Add with `raybase ai enable --dev --mode live`:\n\s*\/\/ "ai": \{\n\s*\/\/ "binding": "AI",\n\s*\/\/ "remote": true\n\s*\/\/ \},/m, "");
|
|
2063
|
+
}
|
|
2064
|
+
// The React Router starter's createRaybaseApp is typed by its worker Env
|
|
2065
|
+
// (env.d.ts, which workers/app.ts passes through), so its modules are too.
|
|
2066
|
+
function moduleEnvType(template) {
|
|
2067
|
+
return template === "react-router" ? "Env" : "RaybaseEnv";
|
|
2068
|
+
}
|
|
2069
|
+
function renderModulesRegion(input) {
|
|
2070
|
+
const env = moduleEnvType(input.template);
|
|
2071
|
+
const docsModuleCall = input.docs && input.docsPlacement === "site" ? ` docsModule<${env}>({ placement: "site", audience: "public" })` : ` docsModule<${env}>()`;
|
|
2072
|
+
const entries = [
|
|
2073
|
+
input.docs ? docsModuleCall : null,
|
|
2074
|
+
input.guide ? ` guideModule<${env}>({ config: guideConfig, corpus: guideCorpus, actions: guideActions })` : null,
|
|
2075
|
+
input.api ? " api" : null
|
|
2076
|
+
].filter(Boolean);
|
|
2077
|
+
return entries.length ? `modules: [\n${entries.join(",\n")}\n],` : "modules: [],";
|
|
2078
|
+
}
|
|
2079
|
+
function replaceNamedRegion(source, name, body) {
|
|
2080
|
+
const start = `${name}:start`;
|
|
2081
|
+
const end = `${name}:end`;
|
|
2082
|
+
const startMatches = indexesOf(source, start);
|
|
2083
|
+
const endMatches = indexesOf(source, end);
|
|
2084
|
+
if (startMatches.length !== 1 || endMatches.length !== 1 || endMatches[0] < startMatches[0]) {
|
|
2085
|
+
throw new Error(`Expected exactly one ordered ${name} anchor region.`);
|
|
2086
|
+
}
|
|
2087
|
+
const startLineEnd = source.indexOf("\n", startMatches[0]);
|
|
2088
|
+
const endLineStart = source.lastIndexOf("\n", endMatches[0]);
|
|
2089
|
+
if (startLineEnd === -1 || endLineStart === -1 || endLineStart < startLineEnd) {
|
|
2090
|
+
throw new Error(`Malformed ${name} anchor region.`);
|
|
2091
|
+
}
|
|
2092
|
+
const linePrefix = source.slice(source.lastIndexOf("\n", startMatches[0]) + 1, startMatches[0]);
|
|
2093
|
+
const indent = /^\s*/.exec(linePrefix)?.[0] ?? "";
|
|
2094
|
+
const replacement = body.trim()
|
|
2095
|
+
? `\n${indent}${body.trim().replace(/\n/g, `\n${indent}`)}\n${indent}`
|
|
2096
|
+
: `\n${indent}`;
|
|
2097
|
+
return `${source.slice(0, startLineEnd)}${replacement}${source.slice(endLineStart)}`;
|
|
2098
|
+
}
|
|
2099
|
+
function indexesOf(source, needle) {
|
|
2100
|
+
const indexes = [];
|
|
2101
|
+
let index = source.indexOf(needle);
|
|
2102
|
+
while (index !== -1) {
|
|
2103
|
+
indexes.push(index);
|
|
2104
|
+
index = source.indexOf(needle, index + needle.length);
|
|
2105
|
+
}
|
|
2106
|
+
return indexes;
|
|
2107
|
+
}
|
|
2108
|
+
function exactImportPattern(moduleSpecifier, binding) {
|
|
2109
|
+
return new RegExp(`^import \\{ ${escapeRegExp(binding)} \\} from "${escapeRegExp(moduleSpecifier)}";\\n`, "m");
|
|
2110
|
+
}
|
|
2111
|
+
function ensureExactImport(source, moduleSpecifier, binding) {
|
|
2112
|
+
if (exactImportPattern(moduleSpecifier, binding).test(source))
|
|
2113
|
+
return source;
|
|
2114
|
+
const matches = [...source.matchAll(/^import .*\n/gm)];
|
|
2115
|
+
const line = `import { ${binding} } from "${moduleSpecifier}";\n`;
|
|
2116
|
+
const last = matches.at(-1);
|
|
2117
|
+
if (!last?.index && last?.index !== 0)
|
|
2118
|
+
return `${line}${source}`;
|
|
2119
|
+
return `${source.slice(0, last.index + last[0].length)}${line}${source.slice(last.index + last[0].length)}`;
|
|
2120
|
+
}
|
|
2121
|
+
function ensureImportLine(source, line) {
|
|
2122
|
+
if (source.includes(line))
|
|
2123
|
+
return source;
|
|
2124
|
+
const matches = [...source.matchAll(/^import .*\n/gm)];
|
|
2125
|
+
const last = matches.at(-1);
|
|
2126
|
+
if (!last?.index && last?.index !== 0)
|
|
2127
|
+
return `${line}${source}`;
|
|
2128
|
+
return `${source.slice(0, last.index + last[0].length)}${line}${source.slice(last.index + last[0].length)}`;
|
|
2129
|
+
}
|
|
2130
|
+
function ensureRaybaseEnvImport(source) {
|
|
2131
|
+
if (/^import\s+(?:type\s+)?\{[^}]*\bRaybaseEnv\b[^}]*\}\s+from "@raybase\/core\/worker";\n/m.test(source))
|
|
2132
|
+
return source;
|
|
2133
|
+
return ensureImportLine(source, 'import type { RaybaseEnv } from "@raybase/core/worker";\n');
|
|
2134
|
+
}
|
|
2135
|
+
function escapeRegExp(value) {
|
|
2136
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2137
|
+
}
|
|
2138
|
+
function replacePlaceholders(root, replacements) {
|
|
2139
|
+
for (const file of walk(root)) {
|
|
2140
|
+
if (statSync(file).isDirectory())
|
|
2141
|
+
continue;
|
|
2142
|
+
const source = readFileSync(file, "utf8");
|
|
2143
|
+
let next = source;
|
|
2144
|
+
for (const [key, value] of Object.entries(replacements)) {
|
|
2145
|
+
next = next.split(key).join(value);
|
|
2146
|
+
}
|
|
2147
|
+
if (next !== source)
|
|
2148
|
+
writeFileSync(file, next);
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
function initGit(projectDir) {
|
|
2152
|
+
const git = spawnSync("git", ["--version"], { encoding: "utf8" });
|
|
2153
|
+
if (git.status !== 0)
|
|
2154
|
+
return;
|
|
2155
|
+
run("git", ["init"], projectDir);
|
|
2156
|
+
run("git", ["add", "."], projectDir);
|
|
2157
|
+
const commit = spawnSync("git", ["commit", "-m", "Initial Raybase app"], {
|
|
2158
|
+
cwd: projectDir,
|
|
2159
|
+
stdio: "ignore"
|
|
2160
|
+
});
|
|
2161
|
+
if (commit.status !== 0) {
|
|
2162
|
+
console.log("Git initialized. Initial commit skipped because git user identity is not configured.");
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
2165
|
+
function run(command, args, cwd) {
|
|
2166
|
+
const result = spawnSync(command, args, { cwd, stdio: "inherit" });
|
|
2167
|
+
if (result.status !== 0)
|
|
2168
|
+
throw new Error(`${command} ${args.join(" ")} failed.`);
|
|
2169
|
+
}
|
|
2170
|
+
function installCommand(projectDir) {
|
|
2171
|
+
if (existsSync(join(projectDir, "package-lock.json")))
|
|
2172
|
+
return { command: "npm", args: ["install"] };
|
|
2173
|
+
return { command: "pnpm", args: ["install"] };
|
|
2174
|
+
}
|
|
2175
|
+
function walk(root) {
|
|
2176
|
+
const files = [];
|
|
2177
|
+
for (const item of readdirSync(root)) {
|
|
2178
|
+
const path = join(root, item);
|
|
2179
|
+
const stat = statSync(path);
|
|
2180
|
+
if (stat.isDirectory())
|
|
2181
|
+
files.push(...walk(path));
|
|
2182
|
+
else
|
|
2183
|
+
files.push(path);
|
|
2184
|
+
}
|
|
2185
|
+
return files;
|
|
2186
|
+
}
|
|
2187
|
+
function sha256File(file) {
|
|
2188
|
+
return createHash("sha256").update(readFileSync(file)).digest("hex");
|
|
2189
|
+
}
|
|
2190
|
+
function stableJson(value) {
|
|
2191
|
+
return `${JSON.stringify(sortJson(value), null, 2)}\n`;
|
|
2192
|
+
}
|
|
2193
|
+
function sortJson(value) {
|
|
2194
|
+
if (Array.isArray(value))
|
|
2195
|
+
return value.map(sortJson);
|
|
2196
|
+
if (!value || typeof value !== "object")
|
|
2197
|
+
return value;
|
|
2198
|
+
return Object.fromEntries(Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, val]) => [key, sortJson(val)]));
|
|
2199
|
+
}
|
|
2200
|
+
// --- starters from outside Raybase -----------------------------------------
|
|
2201
|
+
// raybase.starter.json is the starter's own description; see
|
|
2202
|
+
// ./starter-description.ts. The files it names as inputs (agent
|
|
2203
|
+
// instructions, the SPEC template, skill folders) are consumed here and not
|
|
2204
|
+
// copied into the project; raybase.starter.json itself stays at the root.
|
|
2205
|
+
function starterInputPaths(description) {
|
|
2206
|
+
return [description.agentInstructions, description.spec, ...(description.skills ?? [])]
|
|
2207
|
+
.filter((path) => Boolean(path))
|
|
2208
|
+
.map((path) => path.replace(/^\.\//, "").replace(/\/+$/, ""));
|
|
2209
|
+
}
|
|
2210
|
+
function copyStarterTree(starter, projectDir) {
|
|
2211
|
+
const inputs = new Set(starterInputPaths(starter.description));
|
|
2212
|
+
cpSync(starter.root, projectDir, {
|
|
2213
|
+
recursive: true,
|
|
2214
|
+
filter: (source) => {
|
|
2215
|
+
const rel = relative(starter.root, source).split(sep).join("/");
|
|
2216
|
+
if (!rel)
|
|
2217
|
+
return true;
|
|
2218
|
+
const name = rel.split("/").pop() ?? "";
|
|
2219
|
+
if (FRAMEWORK_EXCLUDES.has(name) || STARTER_TREE_SKIP.has(name))
|
|
2220
|
+
return false;
|
|
2221
|
+
// A web starter is materialized beside its own file-manifest.json.
|
|
2222
|
+
if (rel === "file-manifest.json" && starter.source.type === "web")
|
|
2223
|
+
return false;
|
|
2224
|
+
return !inputs.has(rel);
|
|
2225
|
+
}
|
|
2226
|
+
});
|
|
2227
|
+
// cpSync creates the folders that held only inputs; drop them when empty.
|
|
2228
|
+
for (const input of inputs) {
|
|
2229
|
+
let dir = dirname(join(projectDir, input));
|
|
2230
|
+
while (dir.startsWith(`${projectDir}${sep}`) && existsSync(dir) && readdirSync(dir).length === 0) {
|
|
2231
|
+
rmSync(dir, { recursive: true, force: true });
|
|
2232
|
+
dir = dirname(dir);
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
}
|
|
2236
|
+
function writeStarterSpec(starter, projectDir) {
|
|
2237
|
+
const target = join(projectDir, CANONICAL_SPEC_PATH);
|
|
2238
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
2239
|
+
// Placeholders (__APP_NAME__ …) are replaced with the rest of the tree.
|
|
2240
|
+
cpSync(join(starter.root, starter.description.spec), target);
|
|
2241
|
+
}
|
|
2242
|
+
function appendStarterDevVars(projectDir, description) {
|
|
2243
|
+
const entries = Object.entries(description.devVars ?? {});
|
|
2244
|
+
if (!entries.length)
|
|
2245
|
+
return;
|
|
2246
|
+
const file = join(projectDir, ".dev.vars");
|
|
2247
|
+
const existing = existsSync(file) ? readFileSync(file, "utf8") : "";
|
|
2248
|
+
const present = new Set(existing.split(/\r?\n/).map((line) => line.match(/^\s*([A-Z][A-Z0-9_]*)\s*=/)?.[1]).filter(Boolean));
|
|
2249
|
+
const lines = entries.filter(([name]) => !present.has(name)).map(([name, value]) => `${name}=${value}`);
|
|
2250
|
+
if (!lines.length)
|
|
2251
|
+
return;
|
|
2252
|
+
const body = existing.replace(/\s*$/, "");
|
|
2253
|
+
writeFileSync(file, `${body}${body ? "\n" : ""}# From the starter ${JSON.stringify(description.name)} (${STARTER_DESCRIPTION_FILE} devVars)\n${lines.join("\n")}\n`);
|
|
2254
|
+
}
|
|
2255
|
+
// A starter's skills install beside Raybase's: .agents/skills/<folder name>
|
|
2256
|
+
// plus the .claude/skills link. They are not stamped in .raybase/skills.json,
|
|
2257
|
+
// so `raybase skills sync` and --refresh-skills neither prune them nor count
|
|
2258
|
+
// them as drift; .raybase/starter.json records them instead.
|
|
2259
|
+
function installStarterSkills(projectDir, starter) {
|
|
2260
|
+
const installed = {};
|
|
2261
|
+
for (const entry of starter.description.skills ?? []) {
|
|
2262
|
+
const path = entry.replace(/^\.\//, "").replace(/\/+$/, "");
|
|
2263
|
+
const name = path.split("/").pop();
|
|
2264
|
+
const source = join(starter.root, path);
|
|
2265
|
+
const target = join(projectDir, ".agents", "skills", name);
|
|
2266
|
+
if (resolve(source) !== resolve(target)) {
|
|
2267
|
+
rmSync(target, { recursive: true, force: true });
|
|
2268
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
2269
|
+
cpSync(source, target, { recursive: true });
|
|
2270
|
+
}
|
|
2271
|
+
ensureDirectorySymlink(join(projectDir, ".claude", "skills", name), target);
|
|
2272
|
+
installed[name] = { path, sha256: hashSkillTree(target) };
|
|
2273
|
+
}
|
|
2274
|
+
return installed;
|
|
2275
|
+
}
|
|
2276
|
+
function mergeStarterAgentInstructions(projectDir, starter, replacements) {
|
|
2277
|
+
const agentsFile = join(projectDir, "AGENTS.md");
|
|
2278
|
+
const marker = `<!-- ${STARTER_DESCRIPTION_FILE} agentInstructions -->`;
|
|
2279
|
+
const existing = existsSync(agentsFile) ? readFileSync(agentsFile, "utf8") : "";
|
|
2280
|
+
if (existing.includes(marker))
|
|
2281
|
+
return;
|
|
2282
|
+
let block = readFileSync(join(starter.root, starter.description.agentInstructions), "utf8").trim();
|
|
2283
|
+
for (const [key, value] of Object.entries(replacements))
|
|
2284
|
+
block = block.split(key).join(value);
|
|
2285
|
+
writeFileSync(agentsFile, `${existing.trim()}\n\n${marker}\n${block}\n`);
|
|
2286
|
+
}
|
|
2287
|
+
function writeStarterLock(projectDir, starter, skills) {
|
|
2288
|
+
const file = join(projectDir, STARTER_LOCK_FILE);
|
|
2289
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
2290
|
+
writeFileSync(file, stableJson({
|
|
2291
|
+
schemaVersion: 1,
|
|
2292
|
+
name: starter.description.name,
|
|
2293
|
+
framework: starter.description.framework,
|
|
2294
|
+
raybase: starter.description.raybase,
|
|
2295
|
+
source: starter.source,
|
|
2296
|
+
skills,
|
|
2297
|
+
createdAt: new Date().toISOString(),
|
|
2298
|
+
createdWith: { "@raybase/create": CREATE_RAYBASE_VERSION }
|
|
2299
|
+
}));
|
|
2300
|
+
}
|
|
2301
|
+
// The starter's own steps go before the final "raybase dev".
|
|
2302
|
+
function withStarterNextSteps(steps, starter) {
|
|
2303
|
+
const extra = starter?.description.nextSteps ?? [];
|
|
2304
|
+
if (!extra.length)
|
|
2305
|
+
return steps;
|
|
2306
|
+
const last = steps.at(-1);
|
|
2307
|
+
return last?.startsWith("raybase dev") ? [...steps.slice(0, -1), ...extra, last] : [...steps, ...extra];
|
|
2308
|
+
}
|
|
2309
|
+
// Every project gets a short random app id at scaffold time, stored in
|
|
2310
|
+
// package.json under raybase.appId and stamped onto the deployed worker as a
|
|
2311
|
+
// var by `raybase deploy`. It is the app's durable identity: deploy uses it to
|
|
2312
|
+
// tell "my previous deployment" apart from "an unrelated worker that happens
|
|
2313
|
+
// to share the directory-derived name". Existing ids are always preserved —
|
|
2314
|
+
// the id must stay stable across re-scaffolds and skill refreshes.
|
|
2315
|
+
function ensureAppId(projectDir) {
|
|
2316
|
+
const file = join(projectDir, "package.json");
|
|
2317
|
+
if (!existsSync(file))
|
|
2318
|
+
return null;
|
|
2319
|
+
const parsed = JSON.parse(readFileSync(file, "utf8"));
|
|
2320
|
+
const existing = parsed.raybase?.appId;
|
|
2321
|
+
if (existing)
|
|
2322
|
+
return existing;
|
|
2323
|
+
const appId = generateAppId();
|
|
2324
|
+
parsed.raybase = { ...(parsed.raybase ?? {}), appId };
|
|
2325
|
+
writeFileSync(file, `${JSON.stringify(parsed, null, 2)}\n`);
|
|
2326
|
+
return appId;
|
|
2327
|
+
}
|
|
2328
|
+
function generateAppId() {
|
|
2329
|
+
// Hostname-safe and unambiguous (no 0/o, 1/l/i): the id may end up in a
|
|
2330
|
+
// workers.dev label if deploy ever needs it in a name.
|
|
2331
|
+
const alphabet = "abcdefghjkmnpqrstuvwxyz23456789";
|
|
2332
|
+
const bytes = randomBytes(6);
|
|
2333
|
+
let id = "";
|
|
2334
|
+
for (const byte of bytes)
|
|
2335
|
+
id += alphabet[byte % alphabet.length];
|
|
2336
|
+
return id;
|
|
2337
|
+
}
|
|
2338
|
+
function humanize(value) {
|
|
2339
|
+
return value
|
|
2340
|
+
.split(/[\/_-]/)
|
|
2341
|
+
.filter(Boolean)
|
|
2342
|
+
.map((part) => part[0]?.toUpperCase() + part.slice(1))
|
|
2343
|
+
.join(" ") || "Raybase App";
|
|
2344
|
+
}
|
|
2345
|
+
function slugify(value) {
|
|
2346
|
+
return value
|
|
2347
|
+
.toLowerCase()
|
|
2348
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
2349
|
+
.replace(/^-|-$/g, "") || "raybase-app";
|
|
2350
|
+
}
|
|
2351
|
+
//# sourceMappingURL=index.js.map
|