@ultrakit/ultrakit 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5991 -0
- package/dist/template/.opencode/.env.example +196 -0
- package/dist/template/.opencode/.template-manifest.json +718 -0
- package/dist/template/.opencode/.version +1 -0
- package/dist/template/.opencode/AGENTS.md +573 -0
- package/dist/template/.opencode/AGENT_ALIGNMENT.md +564 -0
- package/dist/template/.opencode/README.md +79 -0
- package/dist/template/.opencode/agent/build.md +447 -0
- package/dist/template/.opencode/agent/explore.md +114 -0
- package/dist/template/.opencode/agent/general.md +201 -0
- package/dist/template/.opencode/agent/painter.md +83 -0
- package/dist/template/.opencode/agent/plan.md +469 -0
- package/dist/template/.opencode/agent/review.md +235 -0
- package/dist/template/.opencode/agent/scout.md +142 -0
- package/dist/template/.opencode/agent/vision.md +169 -0
- package/dist/template/.opencode/command/compound.md +240 -0
- package/dist/template/.opencode/command/create.md +298 -0
- package/dist/template/.opencode/command/curate.md +299 -0
- package/dist/template/.opencode/command/design.md +130 -0
- package/dist/template/.opencode/command/explore.md +170 -0
- package/dist/template/.opencode/command/handoff.md +149 -0
- package/dist/template/.opencode/command/health.md +356 -0
- package/dist/template/.opencode/command/init-context.md +297 -0
- package/dist/template/.opencode/command/init-user.md +125 -0
- package/dist/template/.opencode/command/init.md +115 -0
- package/dist/template/.opencode/command/iterate.md +200 -0
- package/dist/template/.opencode/command/lfg.md +173 -0
- package/dist/template/.opencode/command/plan.md +436 -0
- package/dist/template/.opencode/command/pr.md +166 -0
- package/dist/template/.opencode/command/research.md +128 -0
- package/dist/template/.opencode/command/resume.md +78 -0
- package/dist/template/.opencode/command/review-codebase.md +135 -0
- package/dist/template/.opencode/command/ship.md +390 -0
- package/dist/template/.opencode/command/status.md +126 -0
- package/dist/template/.opencode/command/ui-review.md +111 -0
- package/dist/template/.opencode/command/ui-slop-check.md +169 -0
- package/dist/template/.opencode/command/verify.md +173 -0
- package/dist/template/.opencode/context/README.md +29 -0
- package/dist/template/.opencode/context/git-context.md +32 -0
- package/dist/template/.opencode/dcp-prompts/defaults/README.md +40 -0
- package/dist/template/.opencode/dcp-prompts/defaults/compress-message.md +42 -0
- package/dist/template/.opencode/dcp-prompts/defaults/compress-range.md +59 -0
- package/dist/template/.opencode/dcp-prompts/defaults/context-limit-nudge.md +15 -0
- package/dist/template/.opencode/dcp-prompts/defaults/iteration-nudge.md +3 -0
- package/dist/template/.opencode/dcp-prompts/defaults/system.md +31 -0
- package/dist/template/.opencode/dcp-prompts/defaults/turn-nudge.md +7 -0
- package/dist/template/.opencode/dcp-prompts/overrides/compress-message.md +71 -0
- package/dist/template/.opencode/dcp.jsonc +115 -0
- package/dist/template/.opencode/memory/README.md +89 -0
- package/dist/template/.opencode/memory/_templates/design.md +59 -0
- package/dist/template/.opencode/memory/_templates/prd.md +203 -0
- package/dist/template/.opencode/memory/_templates/project.md +58 -0
- package/dist/template/.opencode/memory/_templates/proposal.md +38 -0
- package/dist/template/.opencode/memory/_templates/roadmap.md +93 -0
- package/dist/template/.opencode/memory/_templates/state.md +89 -0
- package/dist/template/.opencode/memory/_templates/tasks.md +198 -0
- package/dist/template/.opencode/memory/_templates/tech-stack.md +85 -0
- package/dist/template/.opencode/memory/_templates/user.md +26 -0
- package/dist/template/.opencode/memory/project/gotchas.md +67 -0
- package/dist/template/.opencode/memory/project/project.md +92 -0
- package/dist/template/.opencode/memory/project/roadmap.md +142 -0
- package/dist/template/.opencode/memory/project/state.md +84 -0
- package/dist/template/.opencode/memory/project/tech-stack.md +53 -0
- package/dist/template/.opencode/memory/project/user.md +45 -0
- package/dist/template/.opencode/memory/research/benchmark-framework.md +162 -0
- package/dist/template/.opencode/memory/research/ccpm-analysis.md +334 -0
- package/dist/template/.opencode/memory/research/context-management-analysis.md +685 -0
- package/dist/template/.opencode/memory/research/effectiveness-audit.md +213 -0
- package/dist/template/.opencode/memory/research/opencode-mcp-bug-report.md +129 -0
- package/dist/template/.opencode/memory/research/openspec-analysis.md +226 -0
- package/dist/template/.opencode/memory/session-context.md +40 -0
- package/dist/template/.opencode/opencode.json +1148 -0
- package/dist/template/.opencode/opencodex-fast.jsonc +3 -0
- package/dist/template/.opencode/package.json +21 -0
- package/dist/template/.opencode/plugin/README.md +81 -0
- package/dist/template/.opencode/plugin/copilot-auth.ts +1285 -0
- package/dist/template/.opencode/plugin/lib/capture.ts +177 -0
- package/dist/template/.opencode/plugin/lib/compact.ts +194 -0
- package/dist/template/.opencode/plugin/lib/compile.ts +253 -0
- package/dist/template/.opencode/plugin/lib/context.ts +198 -0
- package/dist/template/.opencode/plugin/lib/curator.ts +234 -0
- package/dist/template/.opencode/plugin/lib/db/graph.ts +253 -0
- package/dist/template/.opencode/plugin/lib/db/maintenance.ts +312 -0
- package/dist/template/.opencode/plugin/lib/db/observations.ts +304 -0
- package/dist/template/.opencode/plugin/lib/db/pipeline.ts +520 -0
- package/dist/template/.opencode/plugin/lib/db/schema.ts +687 -0
- package/dist/template/.opencode/plugin/lib/db/types.ts +284 -0
- package/dist/template/.opencode/plugin/lib/distill.ts +376 -0
- package/dist/template/.opencode/plugin/lib/index-generator.ts +170 -0
- package/dist/template/.opencode/plugin/lib/inject.ts +126 -0
- package/dist/template/.opencode/plugin/lib/lint.ts +359 -0
- package/dist/template/.opencode/plugin/lib/memory-admin-tools.ts +277 -0
- package/dist/template/.opencode/plugin/lib/memory-db.ts +100 -0
- package/dist/template/.opencode/plugin/lib/memory-helpers.ts +141 -0
- package/dist/template/.opencode/plugin/lib/memory-hooks.ts +399 -0
- package/dist/template/.opencode/plugin/lib/memory-tools.ts +535 -0
- package/dist/template/.opencode/plugin/lib/notify.ts +89 -0
- package/dist/template/.opencode/plugin/lib/operation-log.ts +110 -0
- package/dist/template/.opencode/plugin/lib/validate.ts +243 -0
- package/dist/template/.opencode/plugin/memory.ts +90 -0
- package/dist/template/.opencode/plugin/package.json +7 -0
- package/dist/template/.opencode/plugin/prompt-leverage.ts +191 -0
- package/dist/template/.opencode/plugin/rtk.ts +43 -0
- package/dist/template/.opencode/plugin/sdk/copilot/chat/convert-to-openai-compatible-chat-messages.ts +172 -0
- package/dist/template/.opencode/plugin/sdk/copilot/chat/get-response-metadata.ts +15 -0
- package/dist/template/.opencode/plugin/sdk/copilot/chat/map-openai-compatible-finish-reason.ts +19 -0
- package/dist/template/.opencode/plugin/sdk/copilot/chat/openai-compatible-api-types.ts +72 -0
- package/dist/template/.opencode/plugin/sdk/copilot/chat/openai-compatible-chat-language-model.ts +835 -0
- package/dist/template/.opencode/plugin/sdk/copilot/chat/openai-compatible-chat-options.ts +30 -0
- package/dist/template/.opencode/plugin/sdk/copilot/chat/openai-compatible-metadata-extractor.ts +48 -0
- package/dist/template/.opencode/plugin/sdk/copilot/chat/openai-compatible-prepare-tools.ts +92 -0
- package/dist/template/.opencode/plugin/sdk/copilot/copilot-provider.ts +101 -0
- package/dist/template/.opencode/plugin/sdk/copilot/index.ts +5 -0
- package/dist/template/.opencode/plugin/sdk/copilot/openai-compatible-error.ts +30 -0
- package/dist/template/.opencode/plugin/sdk/copilot/responses/convert-to-openai-responses-input.ts +335 -0
- package/dist/template/.opencode/plugin/sdk/copilot/responses/map-openai-responses-finish-reason.ts +22 -0
- package/dist/template/.opencode/plugin/sdk/copilot/responses/openai-config.ts +18 -0
- package/dist/template/.opencode/plugin/sdk/copilot/responses/openai-error.ts +22 -0
- package/dist/template/.opencode/plugin/sdk/copilot/responses/openai-responses-api-types.ts +214 -0
- package/dist/template/.opencode/plugin/sdk/copilot/responses/openai-responses-language-model.ts +1770 -0
- package/dist/template/.opencode/plugin/sdk/copilot/responses/openai-responses-prepare-tools.ts +173 -0
- package/dist/template/.opencode/plugin/sdk/copilot/responses/openai-responses-settings.ts +1 -0
- package/dist/template/.opencode/plugin/sdk/copilot/responses/tool/code-interpreter.ts +87 -0
- package/dist/template/.opencode/plugin/sdk/copilot/responses/tool/file-search.ts +127 -0
- package/dist/template/.opencode/plugin/sdk/copilot/responses/tool/image-generation.ts +114 -0
- package/dist/template/.opencode/plugin/sdk/copilot/responses/tool/local-shell.ts +64 -0
- package/dist/template/.opencode/plugin/sdk/copilot/responses/tool/web-search-preview.ts +103 -0
- package/dist/template/.opencode/plugin/sdk/copilot/responses/tool/web-search.ts +102 -0
- package/dist/template/.opencode/plugin/sessions.ts +457 -0
- package/dist/template/.opencode/plugin/skill-mcp.ts +618 -0
- package/dist/template/.opencode/plugin/tsconfig.json +16 -0
- package/dist/template/.opencode/skill/accessibility-audit/SKILL.md +191 -0
- package/dist/template/.opencode/skill/agent-evals/SKILL.md +208 -0
- package/dist/template/.opencode/skill/agent-teams/SKILL.md +268 -0
- package/dist/template/.opencode/skill/anti-ai-slop/SKILL.md +76 -0
- package/dist/template/.opencode/skill/api-and-interface-design/SKILL.md +162 -0
- package/dist/template/.opencode/skill/augment-context-engine/SKILL.md +122 -0
- package/dist/template/.opencode/skill/augment-context-engine/mcp.json +6 -0
- package/dist/template/.opencode/skill/beads/SKILL.md +182 -0
- package/dist/template/.opencode/skill/beads/references/BEST_PRACTICES.md +27 -0
- package/dist/template/.opencode/skill/beads/references/BOUNDARIES.md +219 -0
- package/dist/template/.opencode/skill/beads/references/DEPENDENCIES.md +124 -0
- package/dist/template/.opencode/skill/beads/references/EXAMPLES.md +45 -0
- package/dist/template/.opencode/skill/beads/references/FILE_CLAIMING.md +101 -0
- package/dist/template/.opencode/skill/beads/references/GIT_SYNC.md +25 -0
- package/dist/template/.opencode/skill/beads/references/HIERARCHY.md +71 -0
- package/dist/template/.opencode/skill/beads/references/MULTI_AGENT.md +40 -0
- package/dist/template/.opencode/skill/beads/references/RESUMABILITY.md +177 -0
- package/dist/template/.opencode/skill/beads/references/SESSION_PROTOCOL.md +61 -0
- package/dist/template/.opencode/skill/beads/references/TASK_CREATION.md +38 -0
- package/dist/template/.opencode/skill/beads/references/TROUBLESHOOTING.md +38 -0
- package/dist/template/.opencode/skill/beads/references/WORKFLOWS.md +226 -0
- package/dist/template/.opencode/skill/brainstorming/SKILL.md +114 -0
- package/dist/template/.opencode/skill/brand-asset-protocol/SKILL.md +222 -0
- package/dist/template/.opencode/skill/chrome-devtools/SKILL.md +76 -0
- package/dist/template/.opencode/skill/chrome-devtools/mcp.json +19 -0
- package/dist/template/.opencode/skill/ci-cd-and-automation/SKILL.md +202 -0
- package/dist/template/.opencode/skill/cloudflare/SKILL.md +253 -0
- package/dist/template/.opencode/skill/cloudflare/references/agents-sdk/README.md +35 -0
- package/dist/template/.opencode/skill/cloudflare/references/agents-sdk/api.md +100 -0
- package/dist/template/.opencode/skill/cloudflare/references/agents-sdk/configuration.md +99 -0
- package/dist/template/.opencode/skill/cloudflare/references/agents-sdk/gotchas.md +59 -0
- package/dist/template/.opencode/skill/cloudflare/references/agents-sdk/patterns.md +89 -0
- package/dist/template/.opencode/skill/cloudflare/references/ai-gateway/README.md +695 -0
- package/dist/template/.opencode/skill/cloudflare/references/ai-search/README.md +14 -0
- package/dist/template/.opencode/skill/cloudflare/references/ai-search/api.md +38 -0
- package/dist/template/.opencode/skill/cloudflare/references/ai-search/configuration.md +52 -0
- package/dist/template/.opencode/skill/cloudflare/references/ai-search/gotchas.md +41 -0
- package/dist/template/.opencode/skill/cloudflare/references/ai-search/patterns.md +45 -0
- package/dist/template/.opencode/skill/cloudflare/references/analytics-engine/README.md +14 -0
- package/dist/template/.opencode/skill/cloudflare/references/analytics-engine/api.md +27 -0
- package/dist/template/.opencode/skill/cloudflare/references/analytics-engine/configuration.md +45 -0
- package/dist/template/.opencode/skill/cloudflare/references/analytics-engine/gotchas.md +3 -0
- package/dist/template/.opencode/skill/cloudflare/references/analytics-engine/patterns.md +36 -0
- package/dist/template/.opencode/skill/cloudflare/references/api/README.md +21 -0
- package/dist/template/.opencode/skill/cloudflare/references/api/api.md +31 -0
- package/dist/template/.opencode/skill/cloudflare/references/api/configuration.md +20 -0
- package/dist/template/.opencode/skill/cloudflare/references/api/gotchas.md +28 -0
- package/dist/template/.opencode/skill/cloudflare/references/api/patterns.md +47 -0
- package/dist/template/.opencode/skill/cloudflare/references/api-shield/README.md +20 -0
- package/dist/template/.opencode/skill/cloudflare/references/api-shield/api.md +78 -0
- package/dist/template/.opencode/skill/cloudflare/references/api-shield/configuration.md +128 -0
- package/dist/template/.opencode/skill/cloudflare/references/api-shield/gotchas.md +51 -0
- package/dist/template/.opencode/skill/cloudflare/references/api-shield/patterns.md +145 -0
- package/dist/template/.opencode/skill/cloudflare/references/argo-smart-routing/README.md +16 -0
- package/dist/template/.opencode/skill/cloudflare/references/argo-smart-routing/api.md +50 -0
- package/dist/template/.opencode/skill/cloudflare/references/argo-smart-routing/configuration.md +53 -0
- package/dist/template/.opencode/skill/cloudflare/references/argo-smart-routing/gotchas.md +16 -0
- package/dist/template/.opencode/skill/cloudflare/references/argo-smart-routing/patterns.md +45 -0
- package/dist/template/.opencode/skill/cloudflare/references/bindings/README.md +14 -0
- package/dist/template/.opencode/skill/cloudflare/references/bindings/api.md +3 -0
- package/dist/template/.opencode/skill/cloudflare/references/bindings/configuration.md +58 -0
- package/dist/template/.opencode/skill/cloudflare/references/bindings/gotchas.md +35 -0
- package/dist/template/.opencode/skill/cloudflare/references/bindings/patterns.md +37 -0
- package/dist/template/.opencode/skill/cloudflare/references/bot-management/README.md +71 -0
- package/dist/template/.opencode/skill/cloudflare/references/bot-management/api.md +168 -0
- package/dist/template/.opencode/skill/cloudflare/references/bot-management/configuration.md +114 -0
- package/dist/template/.opencode/skill/cloudflare/references/bot-management/gotchas.md +99 -0
- package/dist/template/.opencode/skill/cloudflare/references/bot-management/patterns.md +125 -0
- package/dist/template/.opencode/skill/cloudflare/references/browser-rendering/README.md +16 -0
- package/dist/template/.opencode/skill/cloudflare/references/browser-rendering/api.md +54 -0
- package/dist/template/.opencode/skill/cloudflare/references/browser-rendering/configuration.md +47 -0
- package/dist/template/.opencode/skill/cloudflare/references/browser-rendering/gotchas.md +29 -0
- package/dist/template/.opencode/skill/cloudflare/references/browser-rendering/patterns.md +29 -0
- package/dist/template/.opencode/skill/cloudflare/references/c3/README.md +264 -0
- package/dist/template/.opencode/skill/cloudflare/references/cache-reserve/README.md +93 -0
- package/dist/template/.opencode/skill/cloudflare/references/cache-reserve/api.md +176 -0
- package/dist/template/.opencode/skill/cloudflare/references/cache-reserve/configuration.md +164 -0
- package/dist/template/.opencode/skill/cloudflare/references/cache-reserve/gotchas.md +203 -0
- package/dist/template/.opencode/skill/cloudflare/references/cache-reserve/patterns.md +180 -0
- package/dist/template/.opencode/skill/cloudflare/references/containers/README.md +16 -0
- package/dist/template/.opencode/skill/cloudflare/references/containers/api.md +43 -0
- package/dist/template/.opencode/skill/cloudflare/references/containers/configuration.md +56 -0
- package/dist/template/.opencode/skill/cloudflare/references/containers/gotchas.md +21 -0
- package/dist/template/.opencode/skill/cloudflare/references/containers/patterns.md +40 -0
- package/dist/template/.opencode/skill/cloudflare/references/cron-triggers/README.md +85 -0
- package/dist/template/.opencode/skill/cloudflare/references/cron-triggers/api.md +198 -0
- package/dist/template/.opencode/skill/cloudflare/references/cron-triggers/configuration.md +151 -0
- package/dist/template/.opencode/skill/cloudflare/references/cron-triggers/gotchas.md +129 -0
- package/dist/template/.opencode/skill/cloudflare/references/cron-triggers/patterns.md +122 -0
- package/dist/template/.opencode/skill/cloudflare/references/d1/README.md +92 -0
- package/dist/template/.opencode/skill/cloudflare/references/d1/api.md +141 -0
- package/dist/template/.opencode/skill/cloudflare/references/d1/configuration.md +127 -0
- package/dist/template/.opencode/skill/cloudflare/references/d1/gotchas.md +70 -0
- package/dist/template/.opencode/skill/cloudflare/references/d1/patterns.md +144 -0
- package/dist/template/.opencode/skill/cloudflare/references/ddos/README.md +34 -0
- package/dist/template/.opencode/skill/cloudflare/references/ddos/api.md +136 -0
- package/dist/template/.opencode/skill/cloudflare/references/ddos/configuration.md +67 -0
- package/dist/template/.opencode/skill/cloudflare/references/ddos/gotchas.md +114 -0
- package/dist/template/.opencode/skill/cloudflare/references/ddos/patterns.md +158 -0
- package/dist/template/.opencode/skill/cloudflare/references/do-storage/README.md +62 -0
- package/dist/template/.opencode/skill/cloudflare/references/do-storage/api.md +89 -0
- package/dist/template/.opencode/skill/cloudflare/references/do-storage/configuration.md +116 -0
- package/dist/template/.opencode/skill/cloudflare/references/do-storage/gotchas.md +93 -0
- package/dist/template/.opencode/skill/cloudflare/references/do-storage/patterns.md +112 -0
- package/dist/template/.opencode/skill/cloudflare/references/durable-objects/README.md +125 -0
- package/dist/template/.opencode/skill/cloudflare/references/durable-objects/api.md +152 -0
- package/dist/template/.opencode/skill/cloudflare/references/durable-objects/configuration.md +148 -0
- package/dist/template/.opencode/skill/cloudflare/references/durable-objects/gotchas.md +158 -0
- package/dist/template/.opencode/skill/cloudflare/references/durable-objects/patterns.md +255 -0
- package/dist/template/.opencode/skill/cloudflare/references/email-routing/README.md +18 -0
- package/dist/template/.opencode/skill/cloudflare/references/email-routing/api.md +46 -0
- package/dist/template/.opencode/skill/cloudflare/references/email-routing/configuration.md +63 -0
- package/dist/template/.opencode/skill/cloudflare/references/email-routing/gotchas.md +16 -0
- package/dist/template/.opencode/skill/cloudflare/references/email-routing/patterns.md +46 -0
- package/dist/template/.opencode/skill/cloudflare/references/email-workers/README.md +598 -0
- package/dist/template/.opencode/skill/cloudflare/references/hyperdrive/README.md +62 -0
- package/dist/template/.opencode/skill/cloudflare/references/hyperdrive/api.md +137 -0
- package/dist/template/.opencode/skill/cloudflare/references/hyperdrive/configuration.md +133 -0
- package/dist/template/.opencode/skill/cloudflare/references/hyperdrive/gotchas.md +184 -0
- package/dist/template/.opencode/skill/cloudflare/references/hyperdrive/patterns.md +176 -0
- package/dist/template/.opencode/skill/cloudflare/references/images/README.md +14 -0
- package/dist/template/.opencode/skill/cloudflare/references/images/api.md +3 -0
- package/dist/template/.opencode/skill/cloudflare/references/images/configuration.md +45 -0
- package/dist/template/.opencode/skill/cloudflare/references/images/gotchas.md +23 -0
- package/dist/template/.opencode/skill/cloudflare/references/images/patterns.md +31 -0
- package/dist/template/.opencode/skill/cloudflare/references/kv/README.md +60 -0
- package/dist/template/.opencode/skill/cloudflare/references/kv/api.md +114 -0
- package/dist/template/.opencode/skill/cloudflare/references/kv/configuration.md +92 -0
- package/dist/template/.opencode/skill/cloudflare/references/kv/gotchas.md +117 -0
- package/dist/template/.opencode/skill/cloudflare/references/kv/patterns.md +139 -0
- package/dist/template/.opencode/skill/cloudflare/references/miniflare/README.md +64 -0
- package/dist/template/.opencode/skill/cloudflare/references/miniflare/api.md +144 -0
- package/dist/template/.opencode/skill/cloudflare/references/miniflare/configuration.md +203 -0
- package/dist/template/.opencode/skill/cloudflare/references/miniflare/gotchas.md +187 -0
- package/dist/template/.opencode/skill/cloudflare/references/miniflare/patterns.md +211 -0
- package/dist/template/.opencode/skill/cloudflare/references/network-interconnect/README.md +60 -0
- package/dist/template/.opencode/skill/cloudflare/references/network-interconnect/api.md +240 -0
- package/dist/template/.opencode/skill/cloudflare/references/network-interconnect/configuration.md +127 -0
- package/dist/template/.opencode/skill/cloudflare/references/network-interconnect/gotchas.md +171 -0
- package/dist/template/.opencode/skill/cloudflare/references/network-interconnect/patterns.md +171 -0
- package/dist/template/.opencode/skill/cloudflare/references/observability/README.md +18 -0
- package/dist/template/.opencode/skill/cloudflare/references/observability/api.md +51 -0
- package/dist/template/.opencode/skill/cloudflare/references/observability/configuration.md +60 -0
- package/dist/template/.opencode/skill/cloudflare/references/observability/gotchas.md +36 -0
- package/dist/template/.opencode/skill/cloudflare/references/observability/patterns.md +42 -0
- package/dist/template/.opencode/skill/cloudflare/references/pages/README.md +76 -0
- package/dist/template/.opencode/skill/cloudflare/references/pages/api.md +200 -0
- package/dist/template/.opencode/skill/cloudflare/references/pages/configuration.md +228 -0
- package/dist/template/.opencode/skill/cloudflare/references/pages/gotchas.md +161 -0
- package/dist/template/.opencode/skill/cloudflare/references/pages/patterns.md +145 -0
- package/dist/template/.opencode/skill/cloudflare/references/pages-functions/README.md +57 -0
- package/dist/template/.opencode/skill/cloudflare/references/pages-functions/api.md +201 -0
- package/dist/template/.opencode/skill/cloudflare/references/pages-functions/configuration.md +159 -0
- package/dist/template/.opencode/skill/cloudflare/references/pages-functions/gotchas.md +151 -0
- package/dist/template/.opencode/skill/cloudflare/references/pages-functions/patterns.md +190 -0
- package/dist/template/.opencode/skill/cloudflare/references/pipelines/README.md +664 -0
- package/dist/template/.opencode/skill/cloudflare/references/pulumi/README.md +107 -0
- package/dist/template/.opencode/skill/cloudflare/references/pulumi/api.md +194 -0
- package/dist/template/.opencode/skill/cloudflare/references/pulumi/configuration.md +216 -0
- package/dist/template/.opencode/skill/cloudflare/references/pulumi/gotchas.md +223 -0
- package/dist/template/.opencode/skill/cloudflare/references/pulumi/patterns.md +139 -0
- package/dist/template/.opencode/skill/cloudflare/references/queues/README.md +69 -0
- package/dist/template/.opencode/skill/cloudflare/references/queues/api.md +138 -0
- package/dist/template/.opencode/skill/cloudflare/references/queues/configuration.md +125 -0
- package/dist/template/.opencode/skill/cloudflare/references/queues/gotchas.md +112 -0
- package/dist/template/.opencode/skill/cloudflare/references/queues/patterns.md +155 -0
- package/dist/template/.opencode/skill/cloudflare/references/r2/README.md +61 -0
- package/dist/template/.opencode/skill/cloudflare/references/r2/api.md +127 -0
- package/dist/template/.opencode/skill/cloudflare/references/r2/configuration.md +76 -0
- package/dist/template/.opencode/skill/cloudflare/references/r2/gotchas.md +94 -0
- package/dist/template/.opencode/skill/cloudflare/references/r2/patterns.md +127 -0
- package/dist/template/.opencode/skill/cloudflare/references/r2-data-catalog/README.md +18 -0
- package/dist/template/.opencode/skill/cloudflare/references/r2-data-catalog/api.md +29 -0
- package/dist/template/.opencode/skill/cloudflare/references/r2-data-catalog/configuration.md +39 -0
- package/dist/template/.opencode/skill/cloudflare/references/r2-data-catalog/gotchas.md +20 -0
- package/dist/template/.opencode/skill/cloudflare/references/r2-data-catalog/patterns.md +46 -0
- package/dist/template/.opencode/skill/cloudflare/references/r2-sql/README.md +512 -0
- package/dist/template/.opencode/skill/cloudflare/references/realtime-sfu/README.md +21 -0
- package/dist/template/.opencode/skill/cloudflare/references/realtime-sfu/api.md +135 -0
- package/dist/template/.opencode/skill/cloudflare/references/realtime-sfu/configuration.md +63 -0
- package/dist/template/.opencode/skill/cloudflare/references/realtime-sfu/gotchas.md +75 -0
- package/dist/template/.opencode/skill/cloudflare/references/realtime-sfu/patterns.md +102 -0
- package/dist/template/.opencode/skill/cloudflare/references/realtimekit/README.md +81 -0
- package/dist/template/.opencode/skill/cloudflare/references/realtimekit/api.md +164 -0
- package/dist/template/.opencode/skill/cloudflare/references/realtimekit/configuration.md +147 -0
- package/dist/template/.opencode/skill/cloudflare/references/realtimekit/gotchas.md +172 -0
- package/dist/template/.opencode/skill/cloudflare/references/realtimekit/patterns.md +155 -0
- package/dist/template/.opencode/skill/cloudflare/references/sandbox/README.md +90 -0
- package/dist/template/.opencode/skill/cloudflare/references/sandbox/api.md +178 -0
- package/dist/template/.opencode/skill/cloudflare/references/sandbox/configuration.md +131 -0
- package/dist/template/.opencode/skill/cloudflare/references/sandbox/gotchas.md +156 -0
- package/dist/template/.opencode/skill/cloudflare/references/sandbox/patterns.md +203 -0
- package/dist/template/.opencode/skill/cloudflare/references/secrets-store/README.md +58 -0
- package/dist/template/.opencode/skill/cloudflare/references/secrets-store/api.md +182 -0
- package/dist/template/.opencode/skill/cloudflare/references/secrets-store/configuration.md +140 -0
- package/dist/template/.opencode/skill/cloudflare/references/secrets-store/gotchas.md +129 -0
- package/dist/template/.opencode/skill/cloudflare/references/secrets-store/patterns.md +218 -0
- package/dist/template/.opencode/skill/cloudflare/references/smart-placement/README.md +91 -0
- package/dist/template/.opencode/skill/cloudflare/references/smart-placement/api.md +139 -0
- package/dist/template/.opencode/skill/cloudflare/references/smart-placement/configuration.md +129 -0
- package/dist/template/.opencode/skill/cloudflare/references/smart-placement/gotchas.md +87 -0
- package/dist/template/.opencode/skill/cloudflare/references/smart-placement/patterns.md +135 -0
- package/dist/template/.opencode/skill/cloudflare/references/snippets/README.md +15 -0
- package/dist/template/.opencode/skill/cloudflare/references/snippets/api.md +47 -0
- package/dist/template/.opencode/skill/cloudflare/references/snippets/configuration.md +33 -0
- package/dist/template/.opencode/skill/cloudflare/references/snippets/gotchas.md +21 -0
- package/dist/template/.opencode/skill/cloudflare/references/snippets/patterns.md +34 -0
- package/dist/template/.opencode/skill/cloudflare/references/spectrum/README.md +16 -0
- package/dist/template/.opencode/skill/cloudflare/references/spectrum/api.md +24 -0
- package/dist/template/.opencode/skill/cloudflare/references/spectrum/configuration.md +43 -0
- package/dist/template/.opencode/skill/cloudflare/references/spectrum/gotchas.md +42 -0
- package/dist/template/.opencode/skill/cloudflare/references/spectrum/patterns.md +40 -0
- package/dist/template/.opencode/skill/cloudflare/references/static-assets/README.md +14 -0
- package/dist/template/.opencode/skill/cloudflare/references/static-assets/api.md +3 -0
- package/dist/template/.opencode/skill/cloudflare/references/static-assets/configuration.md +47 -0
- package/dist/template/.opencode/skill/cloudflare/references/static-assets/gotchas.md +44 -0
- package/dist/template/.opencode/skill/cloudflare/references/static-assets/patterns.md +42 -0
- package/dist/template/.opencode/skill/cloudflare/references/stream/README.md +103 -0
- package/dist/template/.opencode/skill/cloudflare/references/stream/api.md +204 -0
- package/dist/template/.opencode/skill/cloudflare/references/stream/configuration.md +127 -0
- package/dist/template/.opencode/skill/cloudflare/references/stream/gotchas.md +131 -0
- package/dist/template/.opencode/skill/cloudflare/references/stream/patterns.md +152 -0
- package/dist/template/.opencode/skill/cloudflare/references/tail-workers/README.md +640 -0
- package/dist/template/.opencode/skill/cloudflare/references/terraform/README.md +76 -0
- package/dist/template/.opencode/skill/cloudflare/references/terraform/api.md +159 -0
- package/dist/template/.opencode/skill/cloudflare/references/terraform/configuration.md +156 -0
- package/dist/template/.opencode/skill/cloudflare/references/terraform/gotchas.md +207 -0
- package/dist/template/.opencode/skill/cloudflare/references/terraform/patterns.md +135 -0
- package/dist/template/.opencode/skill/cloudflare/references/tunnel/README.md +82 -0
- package/dist/template/.opencode/skill/cloudflare/references/tunnel/api.md +105 -0
- package/dist/template/.opencode/skill/cloudflare/references/tunnel/configuration.md +113 -0
- package/dist/template/.opencode/skill/cloudflare/references/tunnel/gotchas.md +115 -0
- package/dist/template/.opencode/skill/cloudflare/references/tunnel/patterns.md +157 -0
- package/dist/template/.opencode/skill/cloudflare/references/turn/README.md +699 -0
- package/dist/template/.opencode/skill/cloudflare/references/turnstile/README.md +14 -0
- package/dist/template/.opencode/skill/cloudflare/references/turnstile/api.md +3 -0
- package/dist/template/.opencode/skill/cloudflare/references/turnstile/configuration.md +19 -0
- package/dist/template/.opencode/skill/cloudflare/references/turnstile/gotchas.md +27 -0
- package/dist/template/.opencode/skill/cloudflare/references/turnstile/patterns.md +41 -0
- package/dist/template/.opencode/skill/cloudflare/references/vectorize/README.md +682 -0
- package/dist/template/.opencode/skill/cloudflare/references/waf/README.md +14 -0
- package/dist/template/.opencode/skill/cloudflare/references/waf/api.md +3 -0
- package/dist/template/.opencode/skill/cloudflare/references/waf/configuration.md +44 -0
- package/dist/template/.opencode/skill/cloudflare/references/waf/gotchas.md +24 -0
- package/dist/template/.opencode/skill/cloudflare/references/waf/patterns.md +29 -0
- package/dist/template/.opencode/skill/cloudflare/references/web-analytics/README.md +19 -0
- package/dist/template/.opencode/skill/cloudflare/references/web-analytics/api.md +52 -0
- package/dist/template/.opencode/skill/cloudflare/references/web-analytics/configuration.md +31 -0
- package/dist/template/.opencode/skill/cloudflare/references/web-analytics/gotchas.md +28 -0
- package/dist/template/.opencode/skill/cloudflare/references/web-analytics/patterns.md +52 -0
- package/dist/template/.opencode/skill/cloudflare/references/workerd/README.md +47 -0
- package/dist/template/.opencode/skill/cloudflare/references/workerd/api.md +199 -0
- package/dist/template/.opencode/skill/cloudflare/references/workerd/configuration.md +185 -0
- package/dist/template/.opencode/skill/cloudflare/references/workerd/gotchas.md +203 -0
- package/dist/template/.opencode/skill/cloudflare/references/workerd/patterns.md +216 -0
- package/dist/template/.opencode/skill/cloudflare/references/workers/README.md +96 -0
- package/dist/template/.opencode/skill/cloudflare/references/workers/api.md +137 -0
- package/dist/template/.opencode/skill/cloudflare/references/workers/configuration.md +147 -0
- package/dist/template/.opencode/skill/cloudflare/references/workers/gotchas.md +99 -0
- package/dist/template/.opencode/skill/cloudflare/references/workers/patterns.md +149 -0
- package/dist/template/.opencode/skill/cloudflare/references/workers-ai/README.md +116 -0
- package/dist/template/.opencode/skill/cloudflare/references/workers-for-platforms/README.md +48 -0
- package/dist/template/.opencode/skill/cloudflare/references/workers-for-platforms/api.md +169 -0
- package/dist/template/.opencode/skill/cloudflare/references/workers-for-platforms/configuration.md +136 -0
- package/dist/template/.opencode/skill/cloudflare/references/workers-for-platforms/gotchas.md +130 -0
- package/dist/template/.opencode/skill/cloudflare/references/workers-for-platforms/patterns.md +170 -0
- package/dist/template/.opencode/skill/cloudflare/references/workers-playground/README.md +16 -0
- package/dist/template/.opencode/skill/cloudflare/references/workers-playground/api.md +20 -0
- package/dist/template/.opencode/skill/cloudflare/references/workers-playground/configuration.md +3 -0
- package/dist/template/.opencode/skill/cloudflare/references/workers-playground/gotchas.md +35 -0
- package/dist/template/.opencode/skill/cloudflare/references/workers-playground/patterns.md +42 -0
- package/dist/template/.opencode/skill/cloudflare/references/workers-vpc/README.md +579 -0
- package/dist/template/.opencode/skill/cloudflare/references/workflows/README.md +62 -0
- package/dist/template/.opencode/skill/cloudflare/references/workflows/api.md +125 -0
- package/dist/template/.opencode/skill/cloudflare/references/workflows/configuration.md +177 -0
- package/dist/template/.opencode/skill/cloudflare/references/workflows/gotchas.md +136 -0
- package/dist/template/.opencode/skill/cloudflare/references/workflows/patterns.md +132 -0
- package/dist/template/.opencode/skill/cloudflare/references/wrangler/README.md +90 -0
- package/dist/template/.opencode/skill/cloudflare/references/wrangler/api.md +140 -0
- package/dist/template/.opencode/skill/cloudflare/references/wrangler/configuration.md +128 -0
- package/dist/template/.opencode/skill/cloudflare/references/wrangler/gotchas.md +93 -0
- package/dist/template/.opencode/skill/cloudflare/references/wrangler/patterns.md +150 -0
- package/dist/template/.opencode/skill/cloudflare/references/zaraz/README.md +360 -0
- package/dist/template/.opencode/skill/code-search-patterns/SKILL.md +253 -0
- package/dist/template/.opencode/skill/code-simplification/SKILL.md +211 -0
- package/dist/template/.opencode/skill/condition-based-waiting/SKILL.md +135 -0
- package/dist/template/.opencode/skill/condition-based-waiting/example.ts +158 -0
- package/dist/template/.opencode/skill/context-condensation/SKILL.md +149 -0
- package/dist/template/.opencode/skill/context-engineering/SKILL.md +176 -0
- package/dist/template/.opencode/skill/context-initialization/SKILL.md +69 -0
- package/dist/template/.opencode/skill/context-management/SKILL.md +390 -0
- package/dist/template/.opencode/skill/core-data-expert/SKILL.md +93 -0
- package/dist/template/.opencode/skill/core-data-expert/references/batch-operations.md +543 -0
- package/dist/template/.opencode/skill/core-data-expert/references/cloudkit-integration.md +259 -0
- package/dist/template/.opencode/skill/core-data-expert/references/concurrency.md +522 -0
- package/dist/template/.opencode/skill/core-data-expert/references/fetch-requests.md +643 -0
- package/dist/template/.opencode/skill/core-data-expert/references/glossary.md +233 -0
- package/dist/template/.opencode/skill/core-data-expert/references/migration.md +393 -0
- package/dist/template/.opencode/skill/core-data-expert/references/model-configuration.md +597 -0
- package/dist/template/.opencode/skill/core-data-expert/references/performance.md +300 -0
- package/dist/template/.opencode/skill/core-data-expert/references/persistent-history.md +553 -0
- package/dist/template/.opencode/skill/core-data-expert/references/project-audit.md +60 -0
- package/dist/template/.opencode/skill/core-data-expert/references/saving.md +574 -0
- package/dist/template/.opencode/skill/core-data-expert/references/stack-setup.md +625 -0
- package/dist/template/.opencode/skill/core-data-expert/references/testing.md +300 -0
- package/dist/template/.opencode/skill/core-data-expert/references/threading.md +589 -0
- package/dist/template/.opencode/skill/deep-research/SKILL.md +384 -0
- package/dist/template/.opencode/skill/defense-in-depth/SKILL.md +176 -0
- package/dist/template/.opencode/skill/deprecation-and-migration/SKILL.md +189 -0
- package/dist/template/.opencode/skill/design-direction-advisor/SKILL.md +139 -0
- package/dist/template/.opencode/skill/design-system-audit/SKILL.md +153 -0
- package/dist/template/.opencode/skill/design-taste-frontend/SKILL.md +238 -0
- package/dist/template/.opencode/skill/development-lifecycle/SKILL.md +320 -0
- package/dist/template/.opencode/skill/dispatching-parallel-agents/SKILL.md +191 -0
- package/dist/template/.opencode/skill/documentation-and-adrs/SKILL.md +220 -0
- package/dist/template/.opencode/skill/executing-plans/SKILL.md +247 -0
- package/dist/template/.opencode/skill/figma/SKILL.md +224 -0
- package/dist/template/.opencode/skill/figma-go/SKILL.md +65 -0
- package/dist/template/.opencode/skill/finishing-a-development-branch/SKILL.md +357 -0
- package/dist/template/.opencode/skill/frontend-design/SKILL.md +235 -0
- package/dist/template/.opencode/skill/frontend-design/references/animation/motion-advanced.md +224 -0
- package/dist/template/.opencode/skill/frontend-design/references/animation/motion-core.md +181 -0
- package/dist/template/.opencode/skill/frontend-design/references/canvas/execution.md +90 -0
- package/dist/template/.opencode/skill/frontend-design/references/canvas/philosophy.md +94 -0
- package/dist/template/.opencode/skill/frontend-design/references/design/color-system.md +111 -0
- package/dist/template/.opencode/skill/frontend-design/references/design/interaction.md +149 -0
- package/dist/template/.opencode/skill/frontend-design/references/design/typography-rules.md +106 -0
- package/dist/template/.opencode/skill/frontend-design/references/design/ux-writing.md +99 -0
- package/dist/template/.opencode/skill/frontend-design/references/shadcn/accessibility.md +132 -0
- package/dist/template/.opencode/skill/frontend-design/references/shadcn/core-components.md +153 -0
- package/dist/template/.opencode/skill/frontend-design/references/shadcn/form-components.md +158 -0
- package/dist/template/.opencode/skill/frontend-design/references/shadcn/setup.md +69 -0
- package/dist/template/.opencode/skill/frontend-design/references/shadcn/theming.md +152 -0
- package/dist/template/.opencode/skill/frontend-design/references/tailwind/responsive.md +112 -0
- package/dist/template/.opencode/skill/frontend-design/references/tailwind/utilities-layout.md +134 -0
- package/dist/template/.opencode/skill/frontend-design/references/tailwind/utilities-styling.md +165 -0
- package/dist/template/.opencode/skill/frontend-design/references/tailwind/v4-config.md +147 -0
- package/dist/template/.opencode/skill/frontend-design/references/tailwind/v4-features.md +128 -0
- package/dist/template/.opencode/skill/full-output-enforcement/SKILL.md +62 -0
- package/dist/template/.opencode/skill/gemini-large-context/SKILL.md +216 -0
- package/dist/template/.opencode/skill/gh-address-comments/SKILL.md +29 -0
- package/dist/template/.opencode/skill/gh-address-comments/scripts/fetch_comments.py +237 -0
- package/dist/template/.opencode/skill/gh-fix-ci/SKILL.md +38 -0
- package/dist/template/.opencode/skill/gh-fix-ci/scripts/inspect_pr_checks.py +509 -0
- package/dist/template/.opencode/skill/hi-fi-prototype-html/SKILL.md +253 -0
- package/dist/template/.opencode/skill/high-end-visual-design/SKILL.md +111 -0
- package/dist/template/.opencode/skill/html-deck-export/SKILL.md +189 -0
- package/dist/template/.opencode/skill/incremental-implementation/SKILL.md +191 -0
- package/dist/template/.opencode/skill/index-knowledge/SKILL.md +413 -0
- package/dist/template/.opencode/skill/industrial-brutalist-ui/SKILL.md +105 -0
- package/dist/template/.opencode/skill/jira/SKILL.md +283 -0
- package/dist/template/.opencode/skill/jira/mcp.json +6 -0
- package/dist/template/.opencode/skill/memory-grounding/SKILL.md +68 -0
- package/dist/template/.opencode/skill/memory-system/SKILL.md +148 -0
- package/dist/template/.opencode/skill/minimalist-ui/SKILL.md +98 -0
- package/dist/template/.opencode/skill/mockup-to-code/SKILL.md +184 -0
- package/dist/template/.opencode/skill/opensrc/SKILL.md +284 -0
- package/dist/template/.opencode/skill/opensrc/references/architecture.md +176 -0
- package/dist/template/.opencode/skill/opensrc/references/cli-usage.md +176 -0
- package/dist/template/.opencode/skill/opensrc/references/registry-support.md +137 -0
- package/dist/template/.opencode/skill/pdf-extract/SKILL.md +438 -0
- package/dist/template/.opencode/skill/performance-optimization/SKILL.md +236 -0
- package/dist/template/.opencode/skill/playwright/SKILL.md +381 -0
- package/dist/template/.opencode/skill/playwright/mcp.json +16 -0
- package/dist/template/.opencode/skill/playwright/references/agent-browser-cli.md +405 -0
- package/dist/template/.opencode/skill/playwriter/SKILL.md +158 -0
- package/dist/template/.opencode/skill/polar/SKILL.md +102 -0
- package/dist/template/.opencode/skill/portless/SKILL.md +109 -0
- package/dist/template/.opencode/skill/prd/SKILL.md +146 -0
- package/dist/template/.opencode/skill/prd-task/SKILL.md +182 -0
- package/dist/template/.opencode/skill/prd-task/references/prd-schema.json +124 -0
- package/dist/template/.opencode/skill/prompt-leverage/SKILL.md +90 -0
- package/dist/template/.opencode/skill/prompt-leverage/references/framework.md +91 -0
- package/dist/template/.opencode/skill/prompt-leverage/scripts/augment_prompt.py +157 -0
- package/dist/template/.opencode/skill/react-best-practices/AGENTS.md +2410 -0
- package/dist/template/.opencode/skill/react-best-practices/README.md +123 -0
- package/dist/template/.opencode/skill/react-best-practices/SKILL.md +133 -0
- package/dist/template/.opencode/skill/react-best-practices/metadata.json +15 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/_sections.md +46 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/_template.md +28 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/advanced-event-handler-refs.md +55 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/advanced-use-latest.md +49 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/async-api-routes.md +38 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/async-defer-await.md +80 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/async-dependencies.md +36 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/async-parallel.md +28 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/async-suspense-boundaries.md +99 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/bundle-barrel-imports.md +59 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/bundle-conditional.md +31 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/bundle-defer-third-party.md +49 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/bundle-dynamic-imports.md +35 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/bundle-preload.md +50 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/client-event-listeners.md +74 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/client-localstorage-schema.md +71 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/client-passive-event-listeners.md +48 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/client-swr-dedup.md +56 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/js-batch-dom-css.md +82 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/js-cache-function-results.md +80 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/js-cache-property-access.md +28 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/js-cache-storage.md +70 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/js-combine-iterations.md +32 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/js-early-exit.md +50 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/js-hoist-regexp.md +45 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/js-index-maps.md +37 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/js-length-check-first.md +49 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/js-min-max-loop.md +82 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/js-set-map-lookups.md +24 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/js-tosorted-immutable.md +57 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/rendering-activity.md +26 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/rendering-animate-svg-wrapper.md +47 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/rendering-conditional-render.md +40 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/rendering-content-visibility.md +38 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/rendering-hoist-jsx.md +46 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/rendering-hydration-no-flicker.md +82 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/rendering-svg-precision.md +28 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/rerender-defer-reads.md +39 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/rerender-dependencies.md +45 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/rerender-derived-state.md +29 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/rerender-functional-setstate.md +74 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/rerender-lazy-state-init.md +58 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/rerender-memo.md +44 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/rerender-transitions.md +40 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/server-after-nonblocking.md +73 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/server-cache-lru.md +41 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/server-cache-react.md +76 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/server-parallel-fetching.md +83 -0
- package/dist/template/.opencode/skill/react-best-practices/rules/server-serialization.md +38 -0
- package/dist/template/.opencode/skill/receiving-code-review/SKILL.md +263 -0
- package/dist/template/.opencode/skill/reconcile/SKILL.md +183 -0
- package/dist/template/.opencode/skill/redesign-existing-projects/SKILL.md +191 -0
- package/dist/template/.opencode/skill/reflection-checkpoints/SKILL.md +183 -0
- package/dist/template/.opencode/skill/requesting-code-review/SKILL.md +443 -0
- package/dist/template/.opencode/skill/requesting-code-review/references/specialist-profiles.md +108 -0
- package/dist/template/.opencode/skill/requesting-code-review/review.md +160 -0
- package/dist/template/.opencode/skill/resend/SKILL.md +177 -0
- package/dist/template/.opencode/skill/resend/references/react-email.md +287 -0
- package/dist/template/.opencode/skill/resend/references/receive-email.md +248 -0
- package/dist/template/.opencode/skill/resend/references/send-email.md +318 -0
- package/dist/template/.opencode/skill/root-cause-tracing/SKILL.md +192 -0
- package/dist/template/.opencode/skill/root-cause-tracing/find-polluter.sh +63 -0
- package/dist/template/.opencode/skill/rtk-command-compression/SKILL.md +134 -0
- package/dist/template/.opencode/skill/screenshot/SKILL.md +48 -0
- package/dist/template/.opencode/skill/screenshot/scripts/ensure_macos_permissions.sh +54 -0
- package/dist/template/.opencode/skill/screenshot/scripts/macos_display_info.swift +22 -0
- package/dist/template/.opencode/skill/screenshot/scripts/macos_permissions.swift +40 -0
- package/dist/template/.opencode/skill/screenshot/scripts/macos_window_info.swift +126 -0
- package/dist/template/.opencode/skill/screenshot/scripts/take_screenshot.ps1 +163 -0
- package/dist/template/.opencode/skill/screenshot/scripts/take_screenshot.py +585 -0
- package/dist/template/.opencode/skill/security-and-hardening/SKILL.md +296 -0
- package/dist/template/.opencode/skill/security-threat-model/SKILL.md +36 -0
- package/dist/template/.opencode/skill/security-threat-model/references/prompt-template.md +255 -0
- package/dist/template/.opencode/skill/security-threat-model/references/security-controls-and-assets.md +32 -0
- package/dist/template/.opencode/skill/sharing-skills/SKILL.md +214 -0
- package/dist/template/.opencode/skill/skill-creator/SKILL.md +181 -0
- package/dist/template/.opencode/skill/skill-installer/SKILL.md +58 -0
- package/dist/template/.opencode/skill/skill-installer/scripts/github_utils.py +21 -0
- package/dist/template/.opencode/skill/skill-installer/scripts/install-skill-from-github.py +313 -0
- package/dist/template/.opencode/skill/skill-installer/scripts/list-skills.py +106 -0
- package/dist/template/.opencode/skill/structured-edit/SKILL.md +191 -0
- package/dist/template/.opencode/skill/subagent-driven-development/SKILL.md +237 -0
- package/dist/template/.opencode/skill/supabase/SKILL.md +130 -0
- package/dist/template/.opencode/skill/supabase/mcp.json +27 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/AGENTS.md +1490 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/SKILL.md +65 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/advanced-full-text-search.md +55 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/advanced-jsonb-indexing.md +49 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/conn-idle-timeout.md +46 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/conn-limits.md +44 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/conn-pooling.md +41 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/conn-prepared-statements.md +46 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/data-batch-inserts.md +54 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/data-n-plus-one.md +53 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/data-pagination.md +50 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/data-upsert.md +50 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/lock-advisory.md +56 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/lock-deadlock-prevention.md +68 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/lock-short-transactions.md +50 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/lock-skip-locked.md +54 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/monitor-explain-analyze.md +45 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/monitor-pg-stat-statements.md +55 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/monitor-vacuum-analyze.md +55 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/query-composite-indexes.md +44 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/query-covering-indexes.md +40 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/query-index-types.md +45 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/query-missing-indexes.md +43 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/query-partial-indexes.md +45 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/schema-data-types.md +46 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/schema-foreign-key-indexes.md +59 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/schema-lowercase-identifiers.md +55 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/schema-partitioning.md +55 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/schema-primary-keys.md +61 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/security-privileges.md +54 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/security-rls-basics.md +50 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/security-rls-performance.md +57 -0
- package/dist/template/.opencode/skill/swarm-coordination/SKILL.md +244 -0
- package/dist/template/.opencode/skill/swarm-coordination/references/architecture.md +39 -0
- package/dist/template/.opencode/skill/swarm-coordination/references/delegation-worker-protocol.md +145 -0
- package/dist/template/.opencode/skill/swarm-coordination/references/dependency-graph.md +50 -0
- package/dist/template/.opencode/skill/swarm-coordination/references/drift-check.md +90 -0
- package/dist/template/.opencode/skill/swarm-coordination/references/integration-beads.md +20 -0
- package/dist/template/.opencode/skill/swarm-coordination/references/launch-flow.md +186 -0
- package/dist/template/.opencode/skill/swarm-coordination/references/reconciler.md +172 -0
- package/dist/template/.opencode/skill/swarm-coordination/references/tier-enforcement.md +78 -0
- package/dist/template/.opencode/skill/swarm-coordination/references/tmux-integration.md +134 -0
- package/dist/template/.opencode/skill/swift-concurrency/SKILL.md +266 -0
- package/dist/template/.opencode/skill/swift-concurrency/references/actors.md +640 -0
- package/dist/template/.opencode/skill/swift-concurrency/references/async-algorithms.md +822 -0
- package/dist/template/.opencode/skill/swift-concurrency/references/async-await-basics.md +249 -0
- package/dist/template/.opencode/skill/swift-concurrency/references/async-sequences.md +670 -0
- package/dist/template/.opencode/skill/swift-concurrency/references/core-data.md +533 -0
- package/dist/template/.opencode/skill/swift-concurrency/references/glossary.md +128 -0
- package/dist/template/.opencode/skill/swift-concurrency/references/linting.md +142 -0
- package/dist/template/.opencode/skill/swift-concurrency/references/memory-management.md +542 -0
- package/dist/template/.opencode/skill/swift-concurrency/references/migration.md +1076 -0
- package/dist/template/.opencode/skill/swift-concurrency/references/performance.md +574 -0
- package/dist/template/.opencode/skill/swift-concurrency/references/sendable.md +578 -0
- package/dist/template/.opencode/skill/swift-concurrency/references/tasks.md +604 -0
- package/dist/template/.opencode/skill/swift-concurrency/references/testing.md +565 -0
- package/dist/template/.opencode/skill/swift-concurrency/references/threading.md +452 -0
- package/dist/template/.opencode/skill/swiftui-expert-skill/SKILL.md +329 -0
- package/dist/template/.opencode/skill/swiftui-expert-skill/references/animation-advanced.md +351 -0
- package/dist/template/.opencode/skill/swiftui-expert-skill/references/animation-basics.md +284 -0
- package/dist/template/.opencode/skill/swiftui-expert-skill/references/animation-transitions.md +326 -0
- package/dist/template/.opencode/skill/swiftui-expert-skill/references/image-optimization.md +286 -0
- package/dist/template/.opencode/skill/swiftui-expert-skill/references/layout-best-practices.md +312 -0
- package/dist/template/.opencode/skill/swiftui-expert-skill/references/liquid-glass.md +377 -0
- package/dist/template/.opencode/skill/swiftui-expert-skill/references/list-patterns.md +153 -0
- package/dist/template/.opencode/skill/swiftui-expert-skill/references/modern-apis.md +400 -0
- package/dist/template/.opencode/skill/swiftui-expert-skill/references/performance-patterns.md +377 -0
- package/dist/template/.opencode/skill/swiftui-expert-skill/references/scroll-patterns.md +305 -0
- package/dist/template/.opencode/skill/swiftui-expert-skill/references/sheet-navigation-patterns.md +292 -0
- package/dist/template/.opencode/skill/swiftui-expert-skill/references/state-management.md +447 -0
- package/dist/template/.opencode/skill/swiftui-expert-skill/references/text-formatting.md +285 -0
- package/dist/template/.opencode/skill/swiftui-expert-skill/references/view-structure.md +276 -0
- package/dist/template/.opencode/skill/systematic-debugging/SKILL.md +402 -0
- package/dist/template/.opencode/skill/terse-output-mode/SKILL.md +95 -0
- package/dist/template/.opencode/skill/test-driven-development/SKILL.md +403 -0
- package/dist/template/.opencode/skill/testing-anti-patterns/SKILL.md +333 -0
- package/dist/template/.opencode/skill/think-in-code/SKILL.md +136 -0
- package/dist/template/.opencode/skill/using-git-worktrees/SKILL.md +259 -0
- package/dist/template/.opencode/skill/ux-quality-gates/SKILL.md +137 -0
- package/dist/template/.opencode/skill/v0/SKILL.md +158 -0
- package/dist/template/.opencode/skill/v1-run/SKILL.md +175 -0
- package/dist/template/.opencode/skill/v1-run/mcp.json +6 -0
- package/dist/template/.opencode/skill/vercel-deploy-claimable/SKILL.md +124 -0
- package/dist/template/.opencode/skill/vercel-deploy-claimable/scripts/deploy.sh +249 -0
- package/dist/template/.opencode/skill/verification-before-completion/SKILL.md +357 -0
- package/dist/template/.opencode/skill/verification-before-completion/references/VERIFICATION_PROTOCOL.md +171 -0
- package/dist/template/.opencode/skill/verification-gates/SKILL.md +63 -0
- package/dist/template/.opencode/skill/visual-analysis/SKILL.md +154 -0
- package/dist/template/.opencode/skill/web-design-guidelines/SKILL.md +46 -0
- package/dist/template/.opencode/skill/webclaw/SKILL.md +155 -0
- package/dist/template/.opencode/skill/workspace-setup/SKILL.md +76 -0
- package/dist/template/.opencode/skill/writing-plans/SKILL.md +320 -0
- package/dist/template/.opencode/skill/writing-skills/SKILL.md +324 -0
- package/dist/template/.opencode/skill/writing-skills/anthropic-best-practices.md +1173 -0
- package/dist/template/.opencode/skill/writing-skills/graphviz-conventions.dot +172 -0
- package/dist/template/.opencode/skill/writing-skills/persuasion-principles.md +220 -0
- package/dist/template/.opencode/skill/writing-skills/references/anti-patterns.md +25 -0
- package/dist/template/.opencode/skill/writing-skills/references/claude-search-optimization.md +140 -0
- package/dist/template/.opencode/skill/writing-skills/references/discovery-workflow.md +11 -0
- package/dist/template/.opencode/skill/writing-skills/references/file-organization.md +32 -0
- package/dist/template/.opencode/skill/writing-skills/references/flowcharts-and-examples.md +57 -0
- package/dist/template/.opencode/skill/writing-skills/references/rationalization-hardening.md +75 -0
- package/dist/template/.opencode/skill/writing-skills/references/testing-methodology.md +397 -0
- package/dist/template/.opencode/skill/writing-skills/references/testing-skill-types.md +52 -0
- package/dist/template/.opencode/tool/context7.ts +191 -0
- package/dist/template/.opencode/tool/grepsearch.ts +143 -0
- package/dist/template/.opencode/tsconfig.json +21 -0
- package/dist/template/.opencode/tui.json +15 -0
- package/package.json +78 -0
|
@@ -0,0 +1,687 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database Schema & Manager
|
|
3
|
+
*
|
|
4
|
+
* Contains all SQL schema definitions, migration logic, and the
|
|
5
|
+
* singleton database connection manager.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { appendFileSync, existsSync, renameSync } from "node:fs";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { createRequire } from "node:module";
|
|
11
|
+
|
|
12
|
+
type SqlParam = string | number | bigint | null | Uint8Array;
|
|
13
|
+
type RunResult = { changes: number; lastInsertRowid: number | bigint };
|
|
14
|
+
type StatementResult = {
|
|
15
|
+
changes: number | bigint;
|
|
16
|
+
lastInsertRowid: number | bigint;
|
|
17
|
+
};
|
|
18
|
+
type StatementSyncLike = {
|
|
19
|
+
get(...params: SqlParam[]): unknown;
|
|
20
|
+
all(...params: SqlParam[]): unknown[];
|
|
21
|
+
run(...params: SqlParam[]): StatementResult;
|
|
22
|
+
};
|
|
23
|
+
type DatabaseSyncLike = {
|
|
24
|
+
prepare(sql: string): StatementSyncLike;
|
|
25
|
+
exec(sql: string): void;
|
|
26
|
+
close(): void;
|
|
27
|
+
};
|
|
28
|
+
type DatabaseSyncConstructor = new (
|
|
29
|
+
dbPath: string,
|
|
30
|
+
options?: { readOnly?: boolean; timeout?: number },
|
|
31
|
+
) => DatabaseSyncLike;
|
|
32
|
+
|
|
33
|
+
const require = createRequire(import.meta.url);
|
|
34
|
+
let DatabaseSyncCtor: DatabaseSyncConstructor | null = null;
|
|
35
|
+
|
|
36
|
+
function getDatabaseSyncConstructor(): DatabaseSyncConstructor {
|
|
37
|
+
if (!DatabaseSyncCtor) {
|
|
38
|
+
const sqlite = require("node:sqlite") as {
|
|
39
|
+
DatabaseSync: DatabaseSyncConstructor;
|
|
40
|
+
};
|
|
41
|
+
DatabaseSyncCtor = sqlite.DatabaseSync;
|
|
42
|
+
}
|
|
43
|
+
return DatabaseSyncCtor;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function normalizeParams(params: SqlParam[] | [SqlParam[]]): SqlParam[] {
|
|
47
|
+
if (params.length === 1 && Array.isArray(params[0])) {
|
|
48
|
+
return params[0];
|
|
49
|
+
}
|
|
50
|
+
return params as SqlParam[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export class Database {
|
|
54
|
+
private readonly db: DatabaseSyncLike;
|
|
55
|
+
|
|
56
|
+
constructor(
|
|
57
|
+
dbPath: string,
|
|
58
|
+
options: { create?: boolean; readonly?: boolean } = {},
|
|
59
|
+
) {
|
|
60
|
+
const DatabaseSync = getDatabaseSyncConstructor();
|
|
61
|
+
this.db = new DatabaseSync(dbPath, {
|
|
62
|
+
readOnly: options.readonly ?? false,
|
|
63
|
+
timeout: 5000,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
run(sql: string, ...params: SqlParam[] | [SqlParam[]]): RunResult {
|
|
68
|
+
const result = this.db.prepare(sql).run(...normalizeParams(params));
|
|
69
|
+
return {
|
|
70
|
+
changes: Number(result.changes),
|
|
71
|
+
lastInsertRowid: result.lastInsertRowid,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
query<Result = unknown, Params extends SqlParam[] = SqlParam[]>(sql: string) {
|
|
76
|
+
const statement = this.db.prepare(sql);
|
|
77
|
+
return {
|
|
78
|
+
get: (...params: Params | [Params]) =>
|
|
79
|
+
statement.get(
|
|
80
|
+
...normalizeParams(params as SqlParam[] | [SqlParam[]]),
|
|
81
|
+
) as Result | null,
|
|
82
|
+
all: (...params: Params | [Params]) =>
|
|
83
|
+
statement.all(
|
|
84
|
+
...normalizeParams(params as SqlParam[] | [SqlParam[]]),
|
|
85
|
+
) as Result[],
|
|
86
|
+
run: (...params: Params | [Params]): RunResult => {
|
|
87
|
+
const result = statement.run(
|
|
88
|
+
...normalizeParams(params as SqlParam[] | [SqlParam[]]),
|
|
89
|
+
);
|
|
90
|
+
return {
|
|
91
|
+
changes: Number(result.changes),
|
|
92
|
+
lastInsertRowid: result.lastInsertRowid,
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
exec(sql: string): void {
|
|
99
|
+
this.db.exec(sql);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
close(): void {
|
|
103
|
+
this.db.close();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ============================================================================
|
|
108
|
+
// Recovery Logger
|
|
109
|
+
// ============================================================================
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Log recovery messages to a file instead of stderr.
|
|
113
|
+
* Writing to stderr corrupts the TUI in OpenCode.
|
|
114
|
+
*/
|
|
115
|
+
function logRecovery(message: string): void {
|
|
116
|
+
try {
|
|
117
|
+
const logPath = path.join(process.cwd(), ".opencode/memory-recovery.log");
|
|
118
|
+
const timestamp = new Date().toISOString();
|
|
119
|
+
appendFileSync(logPath, `[${timestamp}] ${message}\n`);
|
|
120
|
+
} catch {
|
|
121
|
+
// If we can't even write a log file, silently continue
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// ============================================================================
|
|
126
|
+
// Schema v3 (v2 + navigation, entity graph, raw source, chunk type)
|
|
127
|
+
// ============================================================================
|
|
128
|
+
|
|
129
|
+
const SCHEMA_VERSION = 3;
|
|
130
|
+
|
|
131
|
+
const SCHEMA_SQL = `
|
|
132
|
+
-- Schema versioning for migrations
|
|
133
|
+
CREATE TABLE IF NOT EXISTS schema_versions (
|
|
134
|
+
id INTEGER PRIMARY KEY,
|
|
135
|
+
version INTEGER UNIQUE NOT NULL,
|
|
136
|
+
applied_at TEXT NOT NULL
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
-- Observations table (v3: added raw_source, wing, hall, room)
|
|
140
|
+
CREATE TABLE IF NOT EXISTS observations (
|
|
141
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
142
|
+
type TEXT NOT NULL CHECK(type IN ('decision','bugfix','feature','pattern','discovery','learning','warning')),
|
|
143
|
+
title TEXT NOT NULL,
|
|
144
|
+
subtitle TEXT,
|
|
145
|
+
facts TEXT,
|
|
146
|
+
narrative TEXT,
|
|
147
|
+
raw_source TEXT,
|
|
148
|
+
concepts TEXT,
|
|
149
|
+
files_read TEXT,
|
|
150
|
+
files_modified TEXT,
|
|
151
|
+
confidence TEXT CHECK(confidence IN ('high','medium','low')) DEFAULT 'high',
|
|
152
|
+
bead_id TEXT,
|
|
153
|
+
supersedes INTEGER,
|
|
154
|
+
superseded_by INTEGER,
|
|
155
|
+
valid_until TEXT,
|
|
156
|
+
markdown_file TEXT,
|
|
157
|
+
source TEXT CHECK(source IN ('manual','curator','imported')) DEFAULT 'manual',
|
|
158
|
+
wing TEXT,
|
|
159
|
+
hall TEXT CHECK(hall IS NULL OR hall IN ('facts','events','discoveries','preferences','advice')),
|
|
160
|
+
room TEXT,
|
|
161
|
+
created_at TEXT NOT NULL,
|
|
162
|
+
created_at_epoch INTEGER NOT NULL,
|
|
163
|
+
updated_at TEXT,
|
|
164
|
+
FOREIGN KEY(supersedes) REFERENCES observations(id) ON DELETE SET NULL,
|
|
165
|
+
FOREIGN KEY(superseded_by) REFERENCES observations(id) ON DELETE SET NULL
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
-- FTS5 with porter stemming (v2 upgrade)
|
|
169
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS observations_fts USING fts5(
|
|
170
|
+
title,
|
|
171
|
+
subtitle,
|
|
172
|
+
narrative,
|
|
173
|
+
facts,
|
|
174
|
+
concepts,
|
|
175
|
+
content='observations',
|
|
176
|
+
content_rowid='id',
|
|
177
|
+
tokenize='porter unicode61'
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
-- Indexes for common queries
|
|
181
|
+
CREATE INDEX IF NOT EXISTS idx_observations_type ON observations(type);
|
|
182
|
+
CREATE INDEX IF NOT EXISTS idx_observations_created ON observations(created_at_epoch DESC);
|
|
183
|
+
CREATE INDEX IF NOT EXISTS idx_observations_bead_id ON observations(bead_id);
|
|
184
|
+
CREATE INDEX IF NOT EXISTS idx_observations_superseded ON observations(superseded_by) WHERE superseded_by IS NOT NULL;
|
|
185
|
+
CREATE INDEX IF NOT EXISTS idx_observations_source ON observations(source);
|
|
186
|
+
CREATE INDEX IF NOT EXISTS idx_observations_wing ON observations(wing) WHERE wing IS NOT NULL;
|
|
187
|
+
CREATE INDEX IF NOT EXISTS idx_observations_hall ON observations(hall) WHERE hall IS NOT NULL;
|
|
188
|
+
CREATE INDEX IF NOT EXISTS idx_observations_room ON observations(room) WHERE room IS NOT NULL;
|
|
189
|
+
CREATE INDEX IF NOT EXISTS idx_observations_navigation ON observations(wing, hall, room) WHERE wing IS NOT NULL;
|
|
190
|
+
|
|
191
|
+
-- Memory files table
|
|
192
|
+
CREATE TABLE IF NOT EXISTS memory_files (
|
|
193
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
194
|
+
file_path TEXT UNIQUE NOT NULL,
|
|
195
|
+
content TEXT NOT NULL,
|
|
196
|
+
mode TEXT CHECK(mode IN ('replace', 'append')) DEFAULT 'replace',
|
|
197
|
+
created_at TEXT NOT NULL,
|
|
198
|
+
created_at_epoch INTEGER NOT NULL,
|
|
199
|
+
updated_at TEXT,
|
|
200
|
+
updated_at_epoch INTEGER
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
CREATE INDEX IF NOT EXISTS idx_memory_files_path ON memory_files(file_path);
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
-- Temporal messages table (v3: added chunk_type)
|
|
209
|
+
CREATE TABLE IF NOT EXISTS temporal_messages (
|
|
210
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
211
|
+
session_id TEXT NOT NULL,
|
|
212
|
+
message_id TEXT UNIQUE NOT NULL,
|
|
213
|
+
role TEXT NOT NULL,
|
|
214
|
+
content TEXT NOT NULL,
|
|
215
|
+
token_estimate INTEGER NOT NULL DEFAULT 0,
|
|
216
|
+
time_created INTEGER NOT NULL,
|
|
217
|
+
distillation_id INTEGER,
|
|
218
|
+
chunk_type TEXT,
|
|
219
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
220
|
+
FOREIGN KEY(distillation_id) REFERENCES distillations(id) ON DELETE SET NULL
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
CREATE INDEX IF NOT EXISTS idx_temporal_session ON temporal_messages(session_id, time_created);
|
|
224
|
+
CREATE INDEX IF NOT EXISTS idx_temporal_undistilled ON temporal_messages(session_id) WHERE distillation_id IS NULL;
|
|
225
|
+
CREATE INDEX IF NOT EXISTS idx_temporal_time ON temporal_messages(time_created DESC);
|
|
226
|
+
|
|
227
|
+
-- Distillations table (v2: compressed message summaries)
|
|
228
|
+
CREATE TABLE IF NOT EXISTS distillations (
|
|
229
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
230
|
+
session_id TEXT NOT NULL,
|
|
231
|
+
content TEXT NOT NULL,
|
|
232
|
+
terms TEXT NOT NULL DEFAULT '[]',
|
|
233
|
+
message_count INTEGER NOT NULL DEFAULT 0,
|
|
234
|
+
compression_ratio REAL NOT NULL DEFAULT 0.0,
|
|
235
|
+
time_start INTEGER NOT NULL,
|
|
236
|
+
time_end INTEGER NOT NULL,
|
|
237
|
+
time_created INTEGER NOT NULL,
|
|
238
|
+
meta_distillation_id INTEGER,
|
|
239
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
240
|
+
FOREIGN KEY(meta_distillation_id) REFERENCES distillations(id) ON DELETE SET NULL
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
CREATE INDEX IF NOT EXISTS idx_distillations_session ON distillations(session_id, time_created DESC);
|
|
244
|
+
CREATE INDEX IF NOT EXISTS idx_distillations_time ON distillations(time_created DESC);
|
|
245
|
+
|
|
246
|
+
-- Entity triples table (v3: temporal knowledge graph)
|
|
247
|
+
CREATE TABLE IF NOT EXISTS entity_triples (
|
|
248
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
249
|
+
subject TEXT NOT NULL,
|
|
250
|
+
predicate TEXT NOT NULL,
|
|
251
|
+
object TEXT NOT NULL,
|
|
252
|
+
valid_from TEXT NOT NULL,
|
|
253
|
+
valid_to TEXT,
|
|
254
|
+
confidence REAL NOT NULL DEFAULT 1.0,
|
|
255
|
+
source_observation_id INTEGER,
|
|
256
|
+
created_at TEXT NOT NULL,
|
|
257
|
+
created_at_epoch INTEGER NOT NULL,
|
|
258
|
+
FOREIGN KEY(source_observation_id) REFERENCES observations(id) ON DELETE SET NULL
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
CREATE INDEX IF NOT EXISTS idx_entity_subject ON entity_triples(subject);
|
|
262
|
+
CREATE INDEX IF NOT EXISTS idx_entity_object ON entity_triples(object);
|
|
263
|
+
CREATE INDEX IF NOT EXISTS idx_entity_predicate ON entity_triples(predicate);
|
|
264
|
+
CREATE INDEX IF NOT EXISTS idx_entity_valid ON entity_triples(valid_from, valid_to);
|
|
265
|
+
CREATE INDEX IF NOT EXISTS idx_entity_active ON entity_triples(subject, valid_to) WHERE valid_to IS NULL;
|
|
266
|
+
|
|
267
|
+
-- FTS5 for distillations (v2)
|
|
268
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS distillations_fts USING fts5(
|
|
269
|
+
content,
|
|
270
|
+
terms,
|
|
271
|
+
content='distillations',
|
|
272
|
+
content_rowid='id',
|
|
273
|
+
tokenize='porter unicode61'
|
|
274
|
+
);
|
|
275
|
+
`;
|
|
276
|
+
|
|
277
|
+
// FTS5 sync triggers
|
|
278
|
+
const FTS_TRIGGERS_SQL = `
|
|
279
|
+
-- Observations FTS sync triggers
|
|
280
|
+
CREATE TRIGGER IF NOT EXISTS observations_fts_ai AFTER INSERT ON observations BEGIN
|
|
281
|
+
INSERT INTO observations_fts(rowid, title, subtitle, narrative, facts, concepts)
|
|
282
|
+
VALUES (new.id, new.title, new.subtitle, new.narrative, new.facts, new.concepts);
|
|
283
|
+
END;
|
|
284
|
+
|
|
285
|
+
CREATE TRIGGER IF NOT EXISTS observations_fts_ad AFTER DELETE ON observations BEGIN
|
|
286
|
+
INSERT INTO observations_fts(observations_fts, rowid, title, subtitle, narrative, facts, concepts)
|
|
287
|
+
VALUES('delete', old.id, old.title, old.subtitle, old.narrative, old.facts, old.concepts);
|
|
288
|
+
END;
|
|
289
|
+
|
|
290
|
+
CREATE TRIGGER IF NOT EXISTS observations_fts_au AFTER UPDATE ON observations BEGIN
|
|
291
|
+
INSERT INTO observations_fts(observations_fts, rowid, title, subtitle, narrative, facts, concepts)
|
|
292
|
+
VALUES('delete', old.id, old.title, old.subtitle, old.narrative, old.facts, old.concepts);
|
|
293
|
+
INSERT INTO observations_fts(rowid, title, subtitle, narrative, facts, concepts)
|
|
294
|
+
VALUES (new.id, new.title, new.subtitle, new.narrative, new.facts, new.concepts);
|
|
295
|
+
END;
|
|
296
|
+
|
|
297
|
+
-- Distillations FTS sync triggers (v2)
|
|
298
|
+
CREATE TRIGGER IF NOT EXISTS distillations_fts_ai AFTER INSERT ON distillations BEGIN
|
|
299
|
+
INSERT INTO distillations_fts(rowid, content, terms)
|
|
300
|
+
VALUES (new.id, new.content, new.terms);
|
|
301
|
+
END;
|
|
302
|
+
|
|
303
|
+
CREATE TRIGGER IF NOT EXISTS distillations_fts_ad AFTER DELETE ON distillations BEGIN
|
|
304
|
+
INSERT INTO distillations_fts(distillations_fts, rowid, content, terms)
|
|
305
|
+
VALUES('delete', old.id, old.content, old.terms);
|
|
306
|
+
END;
|
|
307
|
+
|
|
308
|
+
CREATE TRIGGER IF NOT EXISTS distillations_fts_au AFTER UPDATE ON distillations BEGIN
|
|
309
|
+
INSERT INTO distillations_fts(distillations_fts, rowid, content, terms)
|
|
310
|
+
VALUES('delete', old.id, old.content, old.terms);
|
|
311
|
+
INSERT INTO distillations_fts(rowid, content, terms)
|
|
312
|
+
VALUES (new.id, new.content, new.terms);
|
|
313
|
+
END;
|
|
314
|
+
`;
|
|
315
|
+
|
|
316
|
+
// Migration from v1 to v2
|
|
317
|
+
const MIGRATION_V1_TO_V2 = `
|
|
318
|
+
-- Add source column to observations
|
|
319
|
+
ALTER TABLE observations ADD COLUMN source TEXT CHECK(source IN ('manual','curator','imported')) DEFAULT 'manual';
|
|
320
|
+
|
|
321
|
+
-- Add source index
|
|
322
|
+
CREATE INDEX IF NOT EXISTS idx_observations_source ON observations(source);
|
|
323
|
+
|
|
324
|
+
-- Create distillations table (before temporal_messages due to FK dependency)
|
|
325
|
+
CREATE TABLE IF NOT EXISTS distillations (
|
|
326
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
327
|
+
session_id TEXT NOT NULL,
|
|
328
|
+
content TEXT NOT NULL,
|
|
329
|
+
terms TEXT NOT NULL DEFAULT '[]',
|
|
330
|
+
message_count INTEGER NOT NULL DEFAULT 0,
|
|
331
|
+
compression_ratio REAL NOT NULL DEFAULT 0.0,
|
|
332
|
+
time_start INTEGER NOT NULL,
|
|
333
|
+
time_end INTEGER NOT NULL,
|
|
334
|
+
time_created INTEGER NOT NULL,
|
|
335
|
+
meta_distillation_id INTEGER,
|
|
336
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
337
|
+
FOREIGN KEY(meta_distillation_id) REFERENCES distillations(id) ON DELETE SET NULL
|
|
338
|
+
);
|
|
339
|
+
|
|
340
|
+
CREATE INDEX IF NOT EXISTS idx_distillations_session ON distillations(session_id, time_created DESC);
|
|
341
|
+
CREATE INDEX IF NOT EXISTS idx_distillations_time ON distillations(time_created DESC);
|
|
342
|
+
|
|
343
|
+
-- Create distillations FTS5
|
|
344
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS distillations_fts USING fts5(
|
|
345
|
+
content,
|
|
346
|
+
terms,
|
|
347
|
+
content='distillations',
|
|
348
|
+
content_rowid='id',
|
|
349
|
+
tokenize='porter unicode61'
|
|
350
|
+
);
|
|
351
|
+
|
|
352
|
+
-- Create temporal_messages table
|
|
353
|
+
CREATE TABLE IF NOT EXISTS temporal_messages (
|
|
354
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
355
|
+
session_id TEXT NOT NULL,
|
|
356
|
+
message_id TEXT UNIQUE NOT NULL,
|
|
357
|
+
role TEXT NOT NULL,
|
|
358
|
+
content TEXT NOT NULL,
|
|
359
|
+
token_estimate INTEGER NOT NULL DEFAULT 0,
|
|
360
|
+
time_created INTEGER NOT NULL,
|
|
361
|
+
distillation_id INTEGER,
|
|
362
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
363
|
+
FOREIGN KEY(distillation_id) REFERENCES distillations(id) ON DELETE SET NULL
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
CREATE INDEX IF NOT EXISTS idx_temporal_session ON temporal_messages(session_id, time_created);
|
|
367
|
+
CREATE INDEX IF NOT EXISTS idx_temporal_undistilled ON temporal_messages(session_id) WHERE distillation_id IS NULL;
|
|
368
|
+
CREATE INDEX IF NOT EXISTS idx_temporal_time ON temporal_messages(time_created DESC);
|
|
369
|
+
`;
|
|
370
|
+
|
|
371
|
+
// Migration from v2 to v3
|
|
372
|
+
const MIGRATION_V2_TO_V3 = `
|
|
373
|
+
-- Add raw_source column to observations
|
|
374
|
+
ALTER TABLE observations ADD COLUMN raw_source TEXT;
|
|
375
|
+
|
|
376
|
+
-- Add navigation columns to observations
|
|
377
|
+
ALTER TABLE observations ADD COLUMN wing TEXT;
|
|
378
|
+
ALTER TABLE observations ADD COLUMN hall TEXT CHECK(hall IS NULL OR hall IN ('facts','events','discoveries','preferences','advice'));
|
|
379
|
+
ALTER TABLE observations ADD COLUMN room TEXT;
|
|
380
|
+
|
|
381
|
+
-- Navigation indexes
|
|
382
|
+
CREATE INDEX IF NOT EXISTS idx_observations_wing ON observations(wing) WHERE wing IS NOT NULL;
|
|
383
|
+
CREATE INDEX IF NOT EXISTS idx_observations_hall ON observations(hall) WHERE hall IS NOT NULL;
|
|
384
|
+
CREATE INDEX IF NOT EXISTS idx_observations_room ON observations(room) WHERE room IS NOT NULL;
|
|
385
|
+
CREATE INDEX IF NOT EXISTS idx_observations_navigation ON observations(wing, hall, room) WHERE wing IS NOT NULL;
|
|
386
|
+
|
|
387
|
+
-- Add chunk_type to temporal_messages
|
|
388
|
+
ALTER TABLE temporal_messages ADD COLUMN chunk_type TEXT;
|
|
389
|
+
|
|
390
|
+
-- Entity triples table (temporal knowledge graph)
|
|
391
|
+
CREATE TABLE IF NOT EXISTS entity_triples (
|
|
392
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
393
|
+
subject TEXT NOT NULL,
|
|
394
|
+
predicate TEXT NOT NULL,
|
|
395
|
+
object TEXT NOT NULL,
|
|
396
|
+
valid_from TEXT NOT NULL,
|
|
397
|
+
valid_to TEXT,
|
|
398
|
+
confidence REAL NOT NULL DEFAULT 1.0,
|
|
399
|
+
source_observation_id INTEGER,
|
|
400
|
+
created_at TEXT NOT NULL,
|
|
401
|
+
created_at_epoch INTEGER NOT NULL,
|
|
402
|
+
FOREIGN KEY(source_observation_id) REFERENCES observations(id) ON DELETE SET NULL
|
|
403
|
+
);
|
|
404
|
+
|
|
405
|
+
CREATE INDEX IF NOT EXISTS idx_entity_subject ON entity_triples(subject);
|
|
406
|
+
CREATE INDEX IF NOT EXISTS idx_entity_object ON entity_triples(object);
|
|
407
|
+
CREATE INDEX IF NOT EXISTS idx_entity_predicate ON entity_triples(predicate);
|
|
408
|
+
CREATE INDEX IF NOT EXISTS idx_entity_valid ON entity_triples(valid_from, valid_to);
|
|
409
|
+
CREATE INDEX IF NOT EXISTS idx_entity_active ON entity_triples(subject, valid_to) WHERE valid_to IS NULL;
|
|
410
|
+
`;
|
|
411
|
+
|
|
412
|
+
// ============================================================================
|
|
413
|
+
// Database Manager
|
|
414
|
+
// ============================================================================
|
|
415
|
+
|
|
416
|
+
let dbInstance: Database | null = null;
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Get or create the memory database instance.
|
|
420
|
+
* Uses singleton pattern to reuse connection.
|
|
421
|
+
*/
|
|
422
|
+
export function getMemoryDB(): Database {
|
|
423
|
+
if (dbInstance) return dbInstance;
|
|
424
|
+
|
|
425
|
+
const dbPath = path.join(process.cwd(), ".opencode/memory.db");
|
|
426
|
+
|
|
427
|
+
try {
|
|
428
|
+
dbInstance = new Database(dbPath, { create: true });
|
|
429
|
+
} catch (err) {
|
|
430
|
+
// Database file may be corrupted — attempt recovery
|
|
431
|
+
const recovered = attemptDBRecovery(dbPath, err);
|
|
432
|
+
if (!recovered) {
|
|
433
|
+
throw new Error(
|
|
434
|
+
`Failed to open memory database: ${err instanceof Error ? err.message : String(err)}. ` +
|
|
435
|
+
`Recovery also failed. Try manually deleting ${dbPath} to start fresh.`,
|
|
436
|
+
);
|
|
437
|
+
}
|
|
438
|
+
dbInstance = recovered;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// Verify database integrity
|
|
442
|
+
try {
|
|
443
|
+
const result = dbInstance.query("PRAGMA integrity_check").get() as {
|
|
444
|
+
integrity_check: string;
|
|
445
|
+
} | null;
|
|
446
|
+
if (result && result.integrity_check !== "ok") {
|
|
447
|
+
logRecovery(
|
|
448
|
+
`[memory-db] Integrity check failed: ${result.integrity_check}`,
|
|
449
|
+
);
|
|
450
|
+
// Close bad instance and attempt recovery
|
|
451
|
+
dbInstance.close();
|
|
452
|
+
dbInstance = null;
|
|
453
|
+
const recovered = attemptDBRecovery(
|
|
454
|
+
dbPath,
|
|
455
|
+
new Error("integrity check failed"),
|
|
456
|
+
);
|
|
457
|
+
if (!recovered) {
|
|
458
|
+
throw new Error(
|
|
459
|
+
`Memory database integrity check failed and recovery failed. ` +
|
|
460
|
+
`Try manually deleting ${dbPath} to start fresh.`,
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
dbInstance = recovered;
|
|
464
|
+
}
|
|
465
|
+
} catch (err) {
|
|
466
|
+
if (err instanceof Error && err.message.includes("recovery failed")) {
|
|
467
|
+
throw err;
|
|
468
|
+
}
|
|
469
|
+
// integrity_check itself failed — try recovery
|
|
470
|
+
logRecovery(
|
|
471
|
+
`[memory-db] Integrity check query failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
472
|
+
);
|
|
473
|
+
dbInstance?.close();
|
|
474
|
+
dbInstance = null;
|
|
475
|
+
const recovered = attemptDBRecovery(dbPath, err);
|
|
476
|
+
if (!recovered) {
|
|
477
|
+
throw new Error(
|
|
478
|
+
`Memory database is corrupted and recovery failed. ` +
|
|
479
|
+
`Try manually deleting ${dbPath} to start fresh.`,
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
dbInstance = recovered;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// Enable WAL mode for better concurrency
|
|
486
|
+
dbInstance.run("PRAGMA journal_mode = WAL");
|
|
487
|
+
dbInstance.run("PRAGMA foreign_keys = ON");
|
|
488
|
+
|
|
489
|
+
// Initialize schema
|
|
490
|
+
initializeSchema(dbInstance);
|
|
491
|
+
|
|
492
|
+
return dbInstance;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Attempt to recover from a corrupted database.
|
|
497
|
+
* Strategy: WAL checkpoint first, then backup corrupt file + create fresh.
|
|
498
|
+
*/
|
|
499
|
+
function attemptDBRecovery(
|
|
500
|
+
dbPath: string,
|
|
501
|
+
originalError: unknown,
|
|
502
|
+
): Database | null {
|
|
503
|
+
logRecovery(
|
|
504
|
+
`[memory-db] Database recovery triggered: ${originalError instanceof Error ? originalError.message : String(originalError)}`,
|
|
505
|
+
);
|
|
506
|
+
|
|
507
|
+
// Step 1: Try WAL checkpoint recovery (if file exists and is openable)
|
|
508
|
+
try {
|
|
509
|
+
if (existsSync(dbPath)) {
|
|
510
|
+
let tempDB: Database | undefined;
|
|
511
|
+
try {
|
|
512
|
+
tempDB = new Database(dbPath);
|
|
513
|
+
tempDB.run("PRAGMA wal_checkpoint(TRUNCATE)");
|
|
514
|
+
tempDB.close();
|
|
515
|
+
tempDB = undefined;
|
|
516
|
+
} catch {
|
|
517
|
+
tempDB?.close();
|
|
518
|
+
throw new Error("WAL checkpoint failed");
|
|
519
|
+
}
|
|
520
|
+
// Try reopening after WAL checkpoint
|
|
521
|
+
const db = new Database(dbPath, { create: true });
|
|
522
|
+
const check = db.query("PRAGMA integrity_check").get() as {
|
|
523
|
+
integrity_check: string;
|
|
524
|
+
} | null;
|
|
525
|
+
if (check?.integrity_check === "ok") {
|
|
526
|
+
logRecovery("[memory-db] WAL checkpoint recovery succeeded.");
|
|
527
|
+
return db;
|
|
528
|
+
}
|
|
529
|
+
db.close();
|
|
530
|
+
}
|
|
531
|
+
} catch {
|
|
532
|
+
// WAL recovery failed, continue to backup + recreate
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// Step 2: Backup corrupt file and create fresh database
|
|
536
|
+
try {
|
|
537
|
+
if (existsSync(dbPath)) {
|
|
538
|
+
const backupPath = `${dbPath}.corrupt.${Date.now()}`;
|
|
539
|
+
renameSync(dbPath, backupPath);
|
|
540
|
+
logRecovery(`[memory-db] Corrupt database backed up to: ${backupPath}`);
|
|
541
|
+
|
|
542
|
+
// Also clean up WAL/SHM files
|
|
543
|
+
for (const suffix of ["-wal", "-shm"]) {
|
|
544
|
+
const walPath = dbPath + suffix;
|
|
545
|
+
if (existsSync(walPath)) {
|
|
546
|
+
renameSync(walPath, `${backupPath}${suffix}`);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
const freshDB = new Database(dbPath, { create: true });
|
|
552
|
+
logRecovery(
|
|
553
|
+
"[memory-db] Fresh database created. Previous observations are in the backup file.",
|
|
554
|
+
);
|
|
555
|
+
return freshDB;
|
|
556
|
+
} catch (backupErr) {
|
|
557
|
+
logRecovery(
|
|
558
|
+
`[memory-db] Recovery failed: ${backupErr instanceof Error ? backupErr.message : String(backupErr)}`,
|
|
559
|
+
);
|
|
560
|
+
return null;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Close the database connection (for cleanup).
|
|
566
|
+
*/
|
|
567
|
+
export function closeMemoryDB(): void {
|
|
568
|
+
if (dbInstance) {
|
|
569
|
+
dbInstance.close();
|
|
570
|
+
dbInstance = null;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* Initialize database schema with migration support.
|
|
576
|
+
*/
|
|
577
|
+
function initializeSchema(db: Database): void {
|
|
578
|
+
let currentVersion = 0;
|
|
579
|
+
|
|
580
|
+
try {
|
|
581
|
+
const versionRow = db
|
|
582
|
+
.query("SELECT MAX(version) as version FROM schema_versions")
|
|
583
|
+
.get() as {
|
|
584
|
+
version: number | null;
|
|
585
|
+
} | null;
|
|
586
|
+
currentVersion = versionRow?.version ?? 0;
|
|
587
|
+
} catch {
|
|
588
|
+
// schema_versions table doesn't exist, need full init
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
if (currentVersion >= SCHEMA_VERSION) {
|
|
592
|
+
return; // Schema is up to date
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
if (currentVersion === 0) {
|
|
596
|
+
// Fresh install — run full v3 schema
|
|
597
|
+
db.exec(SCHEMA_SQL);
|
|
598
|
+
|
|
599
|
+
// Run FTS triggers
|
|
600
|
+
try {
|
|
601
|
+
db.exec(FTS_TRIGGERS_SQL);
|
|
602
|
+
} catch {
|
|
603
|
+
// Triggers may already exist
|
|
604
|
+
}
|
|
605
|
+
} else {
|
|
606
|
+
// Run incremental migrations
|
|
607
|
+
if (currentVersion < 2) {
|
|
608
|
+
migrateV1ToV2(db);
|
|
609
|
+
}
|
|
610
|
+
if (currentVersion < 3) {
|
|
611
|
+
migrateV2ToV3(db);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// Record schema version
|
|
616
|
+
db.run(
|
|
617
|
+
"INSERT OR REPLACE INTO schema_versions (id, version, applied_at) VALUES (1, ?, ?)",
|
|
618
|
+
[SCHEMA_VERSION, new Date().toISOString()],
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* Migrate from schema v1 to v2.
|
|
624
|
+
* Adds: source column, temporal_messages, distillations, porter FTS5.
|
|
625
|
+
*/
|
|
626
|
+
function migrateV1ToV2(db: Database): void {
|
|
627
|
+
// Run structural changes (new tables, columns)
|
|
628
|
+
for (const stmt of MIGRATION_V1_TO_V2.split(";")) {
|
|
629
|
+
const trimmed = stmt.trim();
|
|
630
|
+
if (trimmed) {
|
|
631
|
+
try {
|
|
632
|
+
db.run(trimmed);
|
|
633
|
+
} catch {
|
|
634
|
+
// Statement may fail if already applied (e.g. column exists)
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
// Upgrade observations_fts to porter stemming
|
|
640
|
+
try {
|
|
641
|
+
// Drop old triggers first
|
|
642
|
+
db.run("DROP TRIGGER IF EXISTS observations_fts_ai");
|
|
643
|
+
db.run("DROP TRIGGER IF EXISTS observations_fts_ad");
|
|
644
|
+
db.run("DROP TRIGGER IF EXISTS observations_fts_au");
|
|
645
|
+
|
|
646
|
+
// Drop old FTS table
|
|
647
|
+
db.run("DROP TABLE IF EXISTS observations_fts");
|
|
648
|
+
|
|
649
|
+
// Recreate with porter tokenizer
|
|
650
|
+
db.run(`
|
|
651
|
+
CREATE VIRTUAL TABLE observations_fts USING fts5(
|
|
652
|
+
title, subtitle, narrative, facts, concepts,
|
|
653
|
+
content='observations', content_rowid='id',
|
|
654
|
+
tokenize='porter unicode61'
|
|
655
|
+
)
|
|
656
|
+
`);
|
|
657
|
+
|
|
658
|
+
// Rebuild FTS index from existing data
|
|
659
|
+
db.run("INSERT INTO observations_fts(observations_fts) VALUES('rebuild')");
|
|
660
|
+
} catch {
|
|
661
|
+
// FTS migration failed, non-fatal — search still works via LIKE fallback
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// Create new triggers (observations + distillations)
|
|
665
|
+
try {
|
|
666
|
+
db.exec(FTS_TRIGGERS_SQL);
|
|
667
|
+
} catch {
|
|
668
|
+
// Triggers may already exist
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* Migrate from schema v2 to v3.
|
|
674
|
+
* Adds: raw_source, wing/hall/room navigation, chunk_type, entity_triples table.
|
|
675
|
+
*/
|
|
676
|
+
function migrateV2ToV3(db: Database): void {
|
|
677
|
+
for (const stmt of MIGRATION_V2_TO_V3.split(";")) {
|
|
678
|
+
const trimmed = stmt.trim();
|
|
679
|
+
if (trimmed) {
|
|
680
|
+
try {
|
|
681
|
+
db.run(trimmed);
|
|
682
|
+
} catch {
|
|
683
|
+
// Statement may fail if already applied (e.g. column exists)
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
}
|