rookery-agent 0.1.0 → 0.3.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 +467 -367
- package/docs/migration.md +88 -88
- package/docs/updates.md +112 -0
- package/package.json +13 -3
- package/packages/cli/dist/commands/config.js +2 -2
- package/packages/cli/dist/commands/doctor.d.ts.map +1 -1
- package/packages/cli/dist/commands/doctor.js +13 -9
- package/packages/cli/dist/commands/doctor.js.map +1 -1
- package/packages/cli/dist/commands/memory.js +1 -1
- package/packages/cli/dist/commands/org.d.ts +2 -2
- package/packages/cli/dist/commands/org.d.ts.map +1 -1
- package/packages/cli/dist/commands/org.js +19 -17
- package/packages/cli/dist/commands/org.js.map +1 -1
- package/packages/cli/dist/commands/serve.js +1 -1
- package/packages/cli/dist/commands/serve.js.map +1 -1
- package/packages/cli/dist/commands/shared.d.ts.map +1 -1
- package/packages/cli/dist/commands/shared.js +2 -1
- package/packages/cli/dist/commands/shared.js.map +1 -1
- package/packages/cli/dist/commands/tasks.d.ts.map +1 -1
- package/packages/cli/dist/commands/tasks.js +25 -11
- package/packages/cli/dist/commands/tasks.js.map +1 -1
- package/packages/cli/dist/commands/tools.js +1 -1
- package/packages/cli/dist/commands/tools.js.map +1 -1
- package/packages/cli/dist/index.js +13 -13
- package/packages/cli/dist/index.js.map +1 -1
- package/packages/cli/dist/repl.d.ts +12 -0
- package/packages/cli/dist/repl.d.ts.map +1 -1
- package/packages/cli/dist/repl.js +170 -16
- package/packages/cli/dist/repl.js.map +1 -1
- package/packages/cli/dist/tui/App.d.ts +7 -3
- package/packages/cli/dist/tui/App.d.ts.map +1 -1
- package/packages/cli/dist/tui/App.js +182 -16
- package/packages/cli/dist/tui/App.js.map +1 -1
- package/packages/cli/dist/tui/commands.d.ts +7 -0
- package/packages/cli/dist/tui/commands.d.ts.map +1 -1
- package/packages/cli/dist/tui/commands.js +70 -8
- package/packages/cli/dist/tui/commands.js.map +1 -1
- package/packages/cli/dist/tui/components/AssignmentsView.js +4 -4
- package/packages/cli/dist/tui/components/AssignmentsView.js.map +1 -1
- package/packages/cli/dist/tui/components/Banner.d.ts +11 -2
- package/packages/cli/dist/tui/components/Banner.d.ts.map +1 -1
- package/packages/cli/dist/tui/components/Banner.js +7 -10
- package/packages/cli/dist/tui/components/Banner.js.map +1 -1
- package/packages/cli/dist/tui/components/CodeBlock.js +2 -2
- package/packages/cli/dist/tui/components/CodeBlock.js.map +1 -1
- package/packages/cli/dist/tui/components/InputBox.d.ts.map +1 -1
- package/packages/cli/dist/tui/components/InputBox.js +4 -4
- package/packages/cli/dist/tui/components/InputBox.js.map +1 -1
- package/packages/cli/dist/tui/components/Logo.d.ts +56 -0
- package/packages/cli/dist/tui/components/Logo.d.ts.map +1 -0
- package/packages/cli/dist/tui/components/Logo.js +50 -0
- package/packages/cli/dist/tui/components/Logo.js.map +1 -0
- package/packages/cli/dist/tui/components/Markdown.js +8 -8
- package/packages/cli/dist/tui/components/Markdown.js.map +1 -1
- package/packages/cli/dist/tui/components/Message.d.ts +1 -1
- package/packages/cli/dist/tui/components/Message.d.ts.map +1 -1
- package/packages/cli/dist/tui/components/Message.js +5 -4
- package/packages/cli/dist/tui/components/Message.js.map +1 -1
- package/packages/cli/dist/tui/components/QuestionView.d.ts +29 -0
- package/packages/cli/dist/tui/components/QuestionView.d.ts.map +1 -0
- package/packages/cli/dist/tui/components/QuestionView.js +53 -0
- package/packages/cli/dist/tui/components/QuestionView.js.map +1 -0
- package/packages/cli/dist/tui/components/SlashPalette.d.ts +5 -2
- package/packages/cli/dist/tui/components/SlashPalette.d.ts.map +1 -1
- package/packages/cli/dist/tui/components/SlashPalette.js +2 -2
- package/packages/cli/dist/tui/components/SlashPalette.js.map +1 -1
- package/packages/cli/dist/tui/components/StatusLine.d.ts +0 -2
- package/packages/cli/dist/tui/components/StatusLine.d.ts.map +1 -1
- package/packages/cli/dist/tui/components/StatusLine.js +8 -5
- package/packages/cli/dist/tui/components/StatusLine.js.map +1 -1
- package/packages/cli/dist/tui/components/ToolGroup.js +2 -2
- package/packages/cli/dist/tui/components/ToolGroup.js.map +1 -1
- package/packages/cli/dist/tui/components/WatchView.d.ts +21 -0
- package/packages/cli/dist/tui/components/WatchView.d.ts.map +1 -0
- package/packages/cli/dist/tui/components/WatchView.js +36 -0
- package/packages/cli/dist/tui/components/WatchView.js.map +1 -0
- package/packages/cli/dist/tui/history.d.ts +20 -0
- package/packages/cli/dist/tui/history.d.ts.map +1 -0
- package/packages/cli/dist/tui/history.js +105 -0
- package/packages/cli/dist/tui/history.js.map +1 -0
- package/packages/cli/dist/tui/hooks/useSlash.d.ts.map +1 -1
- package/packages/cli/dist/tui/hooks/useSlash.js +3 -2
- package/packages/cli/dist/tui/hooks/useSlash.js.map +1 -1
- package/packages/cli/dist/tui/hooks/useTurn.d.ts +58 -1
- package/packages/cli/dist/tui/hooks/useTurn.d.ts.map +1 -1
- package/packages/cli/dist/tui/hooks/useTurn.js +214 -36
- package/packages/cli/dist/tui/hooks/useTurn.js.map +1 -1
- package/packages/cli/dist/tui/hooks/useWatch.d.ts +52 -0
- package/packages/cli/dist/tui/hooks/useWatch.d.ts.map +1 -0
- package/packages/cli/dist/tui/hooks/useWatch.js +145 -0
- package/packages/cli/dist/tui/hooks/useWatch.js.map +1 -0
- package/packages/cli/dist/tui/inkTheme.d.ts +19 -0
- package/packages/cli/dist/tui/inkTheme.d.ts.map +1 -0
- package/packages/cli/dist/tui/inkTheme.js +81 -0
- package/packages/cli/dist/tui/inkTheme.js.map +1 -0
- package/packages/cli/dist/tui/theme.d.ts +39 -29
- package/packages/cli/dist/tui/theme.d.ts.map +1 -1
- package/packages/cli/dist/tui/theme.js +35 -25
- package/packages/cli/dist/tui/theme.js.map +1 -1
- package/packages/cli/dist/tui/types.d.ts +56 -3
- package/packages/cli/dist/tui/types.d.ts.map +1 -1
- package/packages/cli/dist/tui/types.js +85 -0
- package/packages/cli/dist/tui/types.js.map +1 -1
- package/packages/cli/dist/ui/modelNames.d.ts +51 -0
- package/packages/cli/dist/ui/modelNames.d.ts.map +1 -0
- package/packages/cli/dist/ui/modelNames.js +134 -0
- package/packages/cli/dist/ui/modelNames.js.map +1 -0
- package/packages/cli/dist/ui/render.d.ts.map +1 -1
- package/packages/cli/dist/ui/render.js +17 -8
- package/packages/cli/dist/ui/render.js.map +1 -1
- package/packages/cli/dist/ui/speech.js +5 -0
- package/packages/cli/dist/ui/speech.js.map +1 -1
- package/packages/cli/dist/ui/theme.d.ts +33 -9
- package/packages/cli/dist/ui/theme.d.ts.map +1 -1
- package/packages/cli/dist/ui/theme.js +33 -9
- package/packages/cli/dist/ui/theme.js.map +1 -1
- package/packages/cli/package.json +1 -1
- package/packages/core/dist/agents/persona.d.ts.map +1 -1
- package/packages/core/dist/agents/persona.js +5 -2
- package/packages/core/dist/agents/persona.js.map +1 -1
- package/packages/core/dist/computer/accessibility.d.ts +78 -0
- package/packages/core/dist/computer/accessibility.d.ts.map +1 -0
- package/packages/core/dist/computer/accessibility.js +270 -0
- package/packages/core/dist/computer/accessibility.js.map +1 -0
- package/packages/core/dist/computer/assemblies.d.ts +17 -0
- package/packages/core/dist/computer/assemblies.d.ts.map +1 -0
- package/packages/core/dist/computer/assemblies.js +55 -0
- package/packages/core/dist/computer/assemblies.js.map +1 -0
- package/packages/core/dist/computer/browser-init.d.ts +9 -0
- package/packages/core/dist/computer/browser-init.d.ts.map +1 -0
- package/packages/core/dist/computer/browser-init.js +133 -0
- package/packages/core/dist/computer/browser-init.js.map +1 -0
- package/packages/core/dist/computer/cursor.d.ts +30 -0
- package/packages/core/dist/computer/cursor.d.ts.map +1 -0
- package/packages/core/dist/computer/cursor.js +30 -0
- package/packages/core/dist/computer/cursor.js.map +1 -0
- package/packages/core/dist/computer/mcp-server.js +524 -82
- package/packages/core/dist/computer/mcp-server.js.map +1 -1
- package/packages/core/dist/computer/powershell.d.ts +4 -0
- package/packages/core/dist/computer/powershell.d.ts.map +1 -1
- package/packages/core/dist/computer/powershell.js +471 -81
- package/packages/core/dist/computer/powershell.js.map +1 -1
- package/packages/core/dist/computer/screen-text.d.ts +82 -0
- package/packages/core/dist/computer/screen-text.d.ts.map +1 -0
- package/packages/core/dist/computer/screen-text.js +243 -0
- package/packages/core/dist/computer/screen-text.js.map +1 -0
- package/packages/core/dist/computer/sketch.d.ts +66 -0
- package/packages/core/dist/computer/sketch.d.ts.map +1 -0
- package/packages/core/dist/computer/sketch.js +540 -0
- package/packages/core/dist/computer/sketch.js.map +1 -0
- package/packages/core/dist/computer/tools.d.ts +8 -8
- package/packages/core/dist/computer/tools.d.ts.map +1 -1
- package/packages/core/dist/computer/tools.js +186 -31
- package/packages/core/dist/computer/tools.js.map +1 -1
- package/packages/core/dist/computer/validation.d.ts +555 -0
- package/packages/core/dist/computer/validation.d.ts.map +1 -0
- package/packages/core/dist/computer/validation.js +111 -0
- package/packages/core/dist/computer/validation.js.map +1 -0
- package/packages/core/dist/computer/windows-cursor.d.ts +14 -0
- package/packages/core/dist/computer/windows-cursor.d.ts.map +1 -0
- package/packages/core/dist/computer/windows-cursor.js +713 -0
- package/packages/core/dist/computer/windows-cursor.js.map +1 -0
- package/packages/core/dist/config.d.ts +34 -1
- package/packages/core/dist/config.d.ts.map +1 -1
- package/packages/core/dist/config.js +362 -11
- package/packages/core/dist/config.js.map +1 -1
- package/packages/core/dist/cron/scheduler.d.ts +59 -6
- package/packages/core/dist/cron/scheduler.d.ts.map +1 -1
- package/packages/core/dist/cron/scheduler.js +295 -27
- package/packages/core/dist/cron/scheduler.js.map +1 -1
- package/packages/core/dist/cron/store.d.ts +19 -1
- package/packages/core/dist/cron/store.d.ts.map +1 -1
- package/packages/core/dist/cron/store.js +36 -8
- package/packages/core/dist/cron/store.js.map +1 -1
- package/packages/core/dist/external/claude-code.d.ts +4 -0
- package/packages/core/dist/external/claude-code.d.ts.map +1 -0
- package/packages/core/dist/external/claude-code.js +111 -0
- package/packages/core/dist/external/claude-code.js.map +1 -0
- package/packages/core/dist/external/discovery.d.ts +33 -0
- package/packages/core/dist/external/discovery.d.ts.map +1 -0
- package/packages/core/dist/external/discovery.js +144 -0
- package/packages/core/dist/external/discovery.js.map +1 -0
- package/packages/core/dist/external/homes.d.ts +26 -0
- package/packages/core/dist/external/homes.d.ts.map +1 -0
- package/packages/core/dist/external/homes.js +49 -0
- package/packages/core/dist/external/homes.js.map +1 -0
- package/packages/core/dist/external/shared.d.ts +201 -0
- package/packages/core/dist/external/shared.d.ts.map +1 -0
- package/packages/core/dist/external/shared.js +308 -0
- package/packages/core/dist/external/shared.js.map +1 -0
- package/packages/core/dist/gateway/policy.d.ts +117 -2
- package/packages/core/dist/gateway/policy.d.ts.map +1 -1
- package/packages/core/dist/gateway/policy.js +286 -6
- package/packages/core/dist/gateway/policy.js.map +1 -1
- package/packages/core/dist/index.d.ts +38 -12
- package/packages/core/dist/index.d.ts.map +1 -1
- package/packages/core/dist/index.js +66 -12
- package/packages/core/dist/index.js.map +1 -1
- package/packages/core/dist/memory/db.d.ts +1 -1
- package/packages/core/dist/memory/db.d.ts.map +1 -1
- package/packages/core/dist/memory/db.js +878 -1
- package/packages/core/dist/memory/db.js.map +1 -1
- package/packages/core/dist/memory/dream/admission.d.ts +124 -0
- package/packages/core/dist/memory/dream/admission.d.ts.map +1 -0
- package/packages/core/dist/memory/dream/admission.js +116 -0
- package/packages/core/dist/memory/dream/admission.js.map +1 -0
- package/packages/core/dist/memory/dream/candidate.d.ts +152 -0
- package/packages/core/dist/memory/dream/candidate.d.ts.map +1 -0
- package/packages/core/dist/memory/dream/candidate.js +547 -0
- package/packages/core/dist/memory/dream/candidate.js.map +1 -0
- package/packages/core/dist/memory/dream/evaluate.d.ts +394 -0
- package/packages/core/dist/memory/dream/evaluate.d.ts.map +1 -0
- package/packages/core/dist/memory/dream/evaluate.js +1032 -0
- package/packages/core/dist/memory/dream/evaluate.js.map +1 -0
- package/packages/core/dist/memory/dream/frame.d.ts +61 -0
- package/packages/core/dist/memory/dream/frame.d.ts.map +1 -0
- package/packages/core/dist/memory/dream/frame.js +292 -0
- package/packages/core/dist/memory/dream/frame.js.map +1 -0
- package/packages/core/dist/memory/dream/label.d.ts +370 -0
- package/packages/core/dist/memory/dream/label.d.ts.map +1 -0
- package/packages/core/dist/memory/dream/label.js +439 -0
- package/packages/core/dist/memory/dream/label.js.map +1 -0
- package/packages/core/dist/memory/dream/measure.d.ts +114 -0
- package/packages/core/dist/memory/dream/measure.d.ts.map +1 -0
- package/packages/core/dist/memory/dream/measure.js +205 -0
- package/packages/core/dist/memory/dream/measure.js.map +1 -0
- package/packages/core/dist/memory/dream/policy.d.ts +21 -0
- package/packages/core/dist/memory/dream/policy.d.ts.map +1 -0
- package/packages/core/dist/memory/dream/policy.js +157 -0
- package/packages/core/dist/memory/dream/policy.js.map +1 -0
- package/packages/core/dist/memory/dream/probe.d.ts +202 -0
- package/packages/core/dist/memory/dream/probe.d.ts.map +1 -0
- package/packages/core/dist/memory/dream/probe.js +671 -0
- package/packages/core/dist/memory/dream/probe.js.map +1 -0
- package/packages/core/dist/memory/dream/promote.d.ts +312 -0
- package/packages/core/dist/memory/dream/promote.d.ts.map +1 -0
- package/packages/core/dist/memory/dream/promote.js +528 -0
- package/packages/core/dist/memory/dream/promote.js.map +1 -0
- package/packages/core/dist/memory/dream/score.d.ts +103 -0
- package/packages/core/dist/memory/dream/score.d.ts.map +1 -0
- package/packages/core/dist/memory/dream/score.js +334 -0
- package/packages/core/dist/memory/dream/score.js.map +1 -0
- package/packages/core/dist/memory/dream/slots.d.ts +193 -0
- package/packages/core/dist/memory/dream/slots.d.ts.map +1 -0
- package/packages/core/dist/memory/dream/slots.js +0 -0
- package/packages/core/dist/memory/dream/slots.js.map +1 -0
- package/packages/core/dist/memory/dream/trajectory.d.ts +262 -0
- package/packages/core/dist/memory/dream/trajectory.d.ts.map +1 -0
- package/packages/core/dist/memory/dream/trajectory.js +366 -0
- package/packages/core/dist/memory/dream/trajectory.js.map +1 -0
- package/packages/core/dist/memory/extractor.d.ts +7 -0
- package/packages/core/dist/memory/extractor.d.ts.map +1 -1
- package/packages/core/dist/memory/extractor.js +35 -12
- package/packages/core/dist/memory/extractor.js.map +1 -1
- package/packages/core/dist/memory/gate.d.ts +43 -7
- package/packages/core/dist/memory/gate.d.ts.map +1 -1
- package/packages/core/dist/memory/gate.js +91 -4
- package/packages/core/dist/memory/gate.js.map +1 -1
- package/packages/core/dist/memory/recall.d.ts +57 -0
- package/packages/core/dist/memory/recall.d.ts.map +1 -1
- package/packages/core/dist/memory/recall.js +60 -123
- package/packages/core/dist/memory/recall.js.map +1 -1
- package/packages/core/dist/memory/sleep.d.ts +131 -4
- package/packages/core/dist/memory/sleep.d.ts.map +1 -1
- package/packages/core/dist/memory/sleep.js +2384 -65
- package/packages/core/dist/memory/sleep.js.map +1 -1
- package/packages/core/dist/memory/store.d.ts +564 -10
- package/packages/core/dist/memory/store.d.ts.map +1 -1
- package/packages/core/dist/memory/store.js +1673 -102
- package/packages/core/dist/memory/store.js.map +1 -1
- package/packages/core/dist/org/controller.d.ts +268 -4
- package/packages/core/dist/org/controller.d.ts.map +1 -1
- package/packages/core/dist/org/controller.js +2298 -248
- package/packages/core/dist/org/controller.js.map +1 -1
- package/packages/core/dist/org/ponytail.d.ts +1 -1
- package/packages/core/dist/org/ponytail.js +1 -1
- package/packages/core/dist/org/project-mcp.d.ts +3 -3
- package/packages/core/dist/org/prompts.d.ts +44 -30
- package/packages/core/dist/org/prompts.d.ts.map +1 -1
- package/packages/core/dist/org/prompts.js +209 -92
- package/packages/core/dist/org/prompts.js.map +1 -1
- package/packages/core/dist/org/questions.d.ts +104 -0
- package/packages/core/dist/org/questions.d.ts.map +1 -0
- package/packages/core/dist/org/questions.js +136 -0
- package/packages/core/dist/org/questions.js.map +1 -0
- package/packages/core/dist/org/review.d.ts +100 -0
- package/packages/core/dist/org/review.d.ts.map +1 -0
- package/packages/core/dist/org/review.js +256 -0
- package/packages/core/dist/org/review.js.map +1 -0
- package/packages/core/dist/org/store.d.ts +311 -2
- package/packages/core/dist/org/store.d.ts.map +1 -1
- package/packages/core/dist/org/store.js +981 -13
- package/packages/core/dist/org/store.js.map +1 -1
- package/packages/core/dist/org/tools.d.ts +33 -3
- package/packages/core/dist/org/tools.d.ts.map +1 -1
- package/packages/core/dist/org/tools.js +380 -67
- package/packages/core/dist/org/tools.js.map +1 -1
- package/packages/core/dist/providers/catalogue.d.ts +1 -1
- package/packages/core/dist/providers/catalogue.d.ts.map +1 -1
- package/packages/core/dist/providers/catalogue.js +2 -2
- package/packages/core/dist/providers/catalogue.js.map +1 -1
- package/packages/core/dist/providers/claude-code.d.ts +19 -3
- package/packages/core/dist/providers/claude-code.d.ts.map +1 -1
- package/packages/core/dist/providers/claude-code.js +501 -40
- package/packages/core/dist/providers/claude-code.js.map +1 -1
- package/packages/core/dist/providers/claude-tui.d.ts +288 -0
- package/packages/core/dist/providers/claude-tui.d.ts.map +1 -0
- package/packages/core/dist/providers/claude-tui.js +1118 -0
- package/packages/core/dist/providers/claude-tui.js.map +1 -0
- package/packages/core/dist/providers/codex-auth.d.ts +15 -0
- package/packages/core/dist/providers/codex-auth.d.ts.map +1 -0
- package/packages/core/dist/providers/codex-auth.js +127 -0
- package/packages/core/dist/providers/codex-auth.js.map +1 -0
- package/packages/core/dist/providers/codex-bridge.d.ts +58 -0
- package/packages/core/dist/providers/codex-bridge.d.ts.map +1 -0
- package/packages/core/dist/providers/codex-bridge.js +375 -0
- package/packages/core/dist/providers/codex-bridge.js.map +1 -0
- package/packages/core/dist/providers/codex-translate.d.ts +75 -0
- package/packages/core/dist/providers/codex-translate.d.ts.map +1 -0
- package/packages/core/dist/providers/codex-translate.js +383 -0
- package/packages/core/dist/providers/codex-translate.js.map +1 -0
- package/packages/core/dist/providers/model-gateway.d.ts +56 -0
- package/packages/core/dist/providers/model-gateway.d.ts.map +1 -0
- package/packages/core/dist/providers/model-gateway.js +119 -0
- package/packages/core/dist/providers/model-gateway.js.map +1 -0
- package/packages/core/dist/providers/process.d.ts +3 -1
- package/packages/core/dist/providers/process.d.ts.map +1 -1
- package/packages/core/dist/providers/process.js +3 -3
- package/packages/core/dist/providers/process.js.map +1 -1
- package/packages/core/dist/providers/profiles.d.ts +11 -0
- package/packages/core/dist/providers/profiles.d.ts.map +1 -0
- package/packages/core/dist/providers/profiles.js +28 -0
- package/packages/core/dist/providers/profiles.js.map +1 -0
- package/packages/core/dist/providers/provider-catalog.d.ts +72 -0
- package/packages/core/dist/providers/provider-catalog.d.ts.map +1 -0
- package/packages/core/dist/providers/provider-catalog.js +144 -0
- package/packages/core/dist/providers/provider-catalog.js.map +1 -0
- package/packages/core/dist/providers/quota.d.ts +40 -1
- package/packages/core/dist/providers/quota.d.ts.map +1 -1
- package/packages/core/dist/providers/quota.js +288 -25
- package/packages/core/dist/providers/quota.js.map +1 -1
- package/packages/core/dist/providers/registry.d.ts +46 -3
- package/packages/core/dist/providers/registry.d.ts.map +1 -1
- package/packages/core/dist/providers/registry.js +148 -13
- package/packages/core/dist/providers/registry.js.map +1 -1
- package/packages/core/dist/providers/router.d.ts +28 -0
- package/packages/core/dist/providers/router.d.ts.map +1 -0
- package/packages/core/dist/providers/router.js +88 -0
- package/packages/core/dist/providers/router.js.map +1 -0
- package/packages/core/dist/providers/user-settings-guard.d.ts +12 -0
- package/packages/core/dist/providers/user-settings-guard.d.ts.map +1 -0
- package/packages/core/dist/providers/user-settings-guard.js +130 -0
- package/packages/core/dist/providers/user-settings-guard.js.map +1 -0
- package/packages/core/dist/runtime.d.ts +193 -7
- package/packages/core/dist/runtime.d.ts.map +1 -1
- package/packages/core/dist/runtime.js +1676 -219
- package/packages/core/dist/runtime.js.map +1 -1
- package/packages/core/dist/skills/builtin.d.ts +34 -0
- package/packages/core/dist/skills/builtin.d.ts.map +1 -0
- package/packages/core/dist/skills/builtin.js +305 -0
- package/packages/core/dist/skills/builtin.js.map +1 -0
- package/packages/core/dist/skills/shelf.d.ts +30 -0
- package/packages/core/dist/skills/shelf.d.ts.map +1 -0
- package/packages/core/dist/skills/shelf.js +159 -0
- package/packages/core/dist/skills/shelf.js.map +1 -0
- package/packages/core/dist/skills/store.d.ts +66 -4
- package/packages/core/dist/skills/store.d.ts.map +1 -1
- package/packages/core/dist/skills/store.js +105 -18
- package/packages/core/dist/skills/store.js.map +1 -1
- package/packages/core/dist/skills/suggest.d.ts +21 -0
- package/packages/core/dist/skills/suggest.d.ts.map +1 -0
- package/packages/core/dist/skills/suggest.js +150 -0
- package/packages/core/dist/skills/suggest.js.map +1 -0
- package/packages/core/dist/tools/catalog.d.ts +1 -3
- package/packages/core/dist/tools/catalog.d.ts.map +1 -1
- package/packages/core/dist/tools/catalog.js +38 -26
- package/packages/core/dist/tools/catalog.js.map +1 -1
- package/packages/core/dist/tools/hub.d.ts +136 -10
- package/packages/core/dist/tools/hub.d.ts.map +1 -1
- package/packages/core/dist/tools/hub.js +418 -24
- package/packages/core/dist/tools/hub.js.map +1 -1
- package/packages/core/dist/turns/journal.d.ts +78 -0
- package/packages/core/dist/turns/journal.d.ts.map +1 -0
- package/packages/core/dist/turns/journal.js +104 -0
- package/packages/core/dist/turns/journal.js.map +1 -0
- package/packages/core/dist/types.d.ts +1776 -12
- package/packages/core/dist/types.d.ts.map +1 -1
- package/packages/core/dist/types.js.map +1 -1
- package/packages/core/dist/util/blocks.d.ts +41 -0
- package/packages/core/dist/util/blocks.d.ts.map +1 -0
- package/packages/core/dist/util/blocks.js +175 -0
- package/packages/core/dist/util/blocks.js.map +1 -0
- package/packages/core/dist/util/queue.d.ts +12 -0
- package/packages/core/dist/util/queue.d.ts.map +1 -1
- package/packages/core/dist/util/queue.js +16 -0
- package/packages/core/dist/util/queue.js.map +1 -1
- package/packages/core/dist/util/time.d.ts +39 -0
- package/packages/core/dist/util/time.d.ts.map +1 -0
- package/packages/core/dist/util/time.js +71 -0
- package/packages/core/dist/util/time.js.map +1 -0
- package/packages/core/package.json +1 -1
- package/packages/server/dist/auth.d.ts +14 -1
- package/packages/server/dist/auth.d.ts.map +1 -1
- package/packages/server/dist/auth.js +19 -0
- package/packages/server/dist/auth.js.map +1 -1
- package/packages/server/dist/context.d.ts +35 -1
- package/packages/server/dist/context.d.ts.map +1 -1
- package/packages/server/dist/context.js +39 -10
- package/packages/server/dist/context.js.map +1 -1
- package/packages/server/dist/gateways/attachments.d.ts +32 -0
- package/packages/server/dist/gateways/attachments.d.ts.map +1 -0
- package/packages/server/dist/gateways/attachments.js +167 -0
- package/packages/server/dist/gateways/attachments.js.map +1 -0
- package/packages/server/dist/gateways/markdown.d.ts +9 -0
- package/packages/server/dist/gateways/markdown.d.ts.map +1 -0
- package/packages/server/dist/gateways/markdown.js +170 -0
- package/packages/server/dist/gateways/markdown.js.map +1 -0
- package/packages/server/dist/gateways/push.d.ts +1 -1
- package/packages/server/dist/gateways/push.d.ts.map +1 -1
- package/packages/server/dist/gateways/push.js +420 -13
- package/packages/server/dist/gateways/push.js.map +1 -1
- package/packages/server/dist/gateways/telegram-api.d.ts +70 -1
- package/packages/server/dist/gateways/telegram-api.d.ts.map +1 -1
- package/packages/server/dist/gateways/telegram-api.js +140 -1
- package/packages/server/dist/gateways/telegram-api.js.map +1 -1
- package/packages/server/dist/gateways/telegram.d.ts +181 -1
- package/packages/server/dist/gateways/telegram.d.ts.map +1 -1
- package/packages/server/dist/gateways/telegram.js +1572 -78
- package/packages/server/dist/gateways/telegram.js.map +1 -1
- package/packages/server/dist/gateways/threads.d.ts +84 -0
- package/packages/server/dist/gateways/threads.d.ts.map +1 -0
- package/packages/server/dist/gateways/threads.js +289 -0
- package/packages/server/dist/gateways/threads.js.map +1 -0
- package/packages/server/dist/index.d.ts +2 -1
- package/packages/server/dist/index.d.ts.map +1 -1
- package/packages/server/dist/index.js +2 -1
- package/packages/server/dist/index.js.map +1 -1
- package/packages/server/dist/listeners/imap.d.ts +13 -0
- package/packages/server/dist/listeners/imap.d.ts.map +1 -0
- package/packages/server/dist/listeners/imap.js +0 -0
- package/packages/server/dist/listeners/imap.js.map +1 -0
- package/packages/server/dist/listeners/registry.d.ts +18 -0
- package/packages/server/dist/listeners/registry.d.ts.map +1 -0
- package/packages/server/dist/listeners/registry.js +88 -0
- package/packages/server/dist/listeners/registry.js.map +1 -0
- package/packages/server/dist/listeners/types.d.ts +55 -0
- package/packages/server/dist/listeners/types.d.ts.map +1 -0
- package/packages/server/dist/listeners/types.js +2 -0
- package/packages/server/dist/listeners/types.js.map +1 -0
- package/packages/server/dist/main.js +15 -1
- package/packages/server/dist/main.js.map +1 -1
- package/packages/server/dist/routes/chat.d.ts +7 -3
- package/packages/server/dist/routes/chat.d.ts.map +1 -1
- package/packages/server/dist/routes/chat.js +8 -17
- package/packages/server/dist/routes/chat.js.map +1 -1
- package/packages/server/dist/routes/config.d.ts.map +1 -1
- package/packages/server/dist/routes/config.js +66 -7
- package/packages/server/dist/routes/config.js.map +1 -1
- package/packages/server/dist/routes/cron.d.ts.map +1 -1
- package/packages/server/dist/routes/cron.js +65 -8
- package/packages/server/dist/routes/cron.js.map +1 -1
- package/packages/server/dist/routes/dream.d.ts +22 -0
- package/packages/server/dist/routes/dream.d.ts.map +1 -0
- package/packages/server/dist/routes/dream.js +152 -0
- package/packages/server/dist/routes/dream.js.map +1 -0
- package/packages/server/dist/routes/hooks.d.ts +18 -0
- package/packages/server/dist/routes/hooks.d.ts.map +1 -0
- package/packages/server/dist/routes/hooks.js +62 -0
- package/packages/server/dist/routes/hooks.js.map +1 -0
- package/packages/server/dist/routes/listeners.d.ts +10 -0
- package/packages/server/dist/routes/listeners.d.ts.map +1 -0
- package/packages/server/dist/routes/listeners.js +12 -0
- package/packages/server/dist/routes/listeners.js.map +1 -0
- package/packages/server/dist/routes/memories.d.ts.map +1 -1
- package/packages/server/dist/routes/memories.js +55 -3
- package/packages/server/dist/routes/memories.js.map +1 -1
- package/packages/server/dist/routes/org.d.ts.map +1 -1
- package/packages/server/dist/routes/org.js +289 -49
- package/packages/server/dist/routes/org.js.map +1 -1
- package/packages/server/dist/routes/profile.d.ts.map +1 -1
- package/packages/server/dist/routes/profile.js +6 -3
- package/packages/server/dist/routes/profile.js.map +1 -1
- package/packages/server/dist/routes/providers.d.ts.map +1 -1
- package/packages/server/dist/routes/providers.js +66 -7
- package/packages/server/dist/routes/providers.js.map +1 -1
- package/packages/server/dist/routes/questions.d.ts +45 -0
- package/packages/server/dist/routes/questions.d.ts.map +1 -0
- package/packages/server/dist/routes/questions.js +73 -0
- package/packages/server/dist/routes/questions.js.map +1 -0
- package/packages/server/dist/routes/sessions.d.ts.map +1 -1
- package/packages/server/dist/routes/sessions.js +26 -6
- package/packages/server/dist/routes/sessions.js.map +1 -1
- package/packages/server/dist/routes/sleep.d.ts.map +1 -1
- package/packages/server/dist/routes/sleep.js +71 -2
- package/packages/server/dist/routes/sleep.js.map +1 -1
- package/packages/server/dist/routes/terminals.d.ts +25 -0
- package/packages/server/dist/routes/terminals.d.ts.map +1 -0
- package/packages/server/dist/routes/terminals.js +35 -0
- package/packages/server/dist/routes/terminals.js.map +1 -0
- package/packages/server/dist/routes/tools.d.ts.map +1 -1
- package/packages/server/dist/routes/tools.js +140 -6
- package/packages/server/dist/routes/tools.js.map +1 -1
- package/packages/server/dist/routes/updates.d.ts +10 -0
- package/packages/server/dist/routes/updates.d.ts.map +1 -0
- package/packages/server/dist/routes/updates.js +22 -0
- package/packages/server/dist/routes/updates.js.map +1 -0
- package/packages/server/dist/routes/ws.d.ts +11 -5
- package/packages/server/dist/routes/ws.d.ts.map +1 -1
- package/packages/server/dist/routes/ws.js +168 -28
- package/packages/server/dist/routes/ws.js.map +1 -1
- package/packages/server/dist/schemas.d.ts +1177 -215
- package/packages/server/dist/schemas.d.ts.map +1 -1
- package/packages/server/dist/schemas.js +317 -12
- package/packages/server/dist/schemas.js.map +1 -1
- package/packages/server/dist/server.d.ts +7 -1
- package/packages/server/dist/server.d.ts.map +1 -1
- package/packages/server/dist/server.js +210 -3
- package/packages/server/dist/server.js.map +1 -1
- package/packages/server/dist/services/stream.d.ts +94 -5
- package/packages/server/dist/services/stream.d.ts.map +1 -1
- package/packages/server/dist/services/stream.js +9 -20
- package/packages/server/dist/services/stream.js.map +1 -1
- package/packages/server/dist/services/stt.d.ts +65 -0
- package/packages/server/dist/services/stt.d.ts.map +1 -0
- package/packages/server/dist/services/stt.js +306 -0
- package/packages/server/dist/services/stt.js.map +1 -0
- package/packages/server/dist/services/turns.d.ts +54 -0
- package/packages/server/dist/services/turns.d.ts.map +1 -0
- package/packages/server/dist/services/turns.js +186 -0
- package/packages/server/dist/services/turns.js.map +1 -0
- package/packages/server/dist/services/updates.d.ts +99 -0
- package/packages/server/dist/services/updates.d.ts.map +1 -0
- package/packages/server/dist/services/updates.js +316 -0
- package/packages/server/dist/services/updates.js.map +1 -0
- package/packages/server/package.json +1 -1
- package/packages/web/dist/app-icon.svg +2 -0
- package/packages/web/dist/apple-touch-icon.png +0 -0
- package/packages/web/dist/assets/abnfDiagram-O67JEVCF-D7YyFndQ.js +1 -0
- package/packages/web/dist/assets/arc-C_Zgk2dJ.js +1 -0
- package/packages/web/dist/assets/architectureDiagram-NJMV4G6O-eI0adu1B.js +36 -0
- package/packages/web/dist/assets/blockDiagram-BEXU5L5S-WAoOFUA9.js +140 -0
- package/packages/web/dist/assets/c4Diagram-YGBWAQC7-DE8Zyhng.js +38 -0
- package/packages/web/dist/assets/channel-egZxcyUK.js +1 -0
- package/packages/web/dist/assets/chunk-2Q5K7J3B-bnqLP2XD.js +1 -0
- package/packages/web/dist/assets/chunk-3FUC2YCW-Ck1_SVe0.js +2 -0
- package/packages/web/dist/assets/chunk-5VM5RSS4-hDmC41gD.js +15 -0
- package/packages/web/dist/assets/chunk-GTNCS2PH-PoWvfCrT.js +88 -0
- package/packages/web/dist/assets/chunk-GWA4HPMP-D3V0IG43.js +1 -0
- package/packages/web/dist/assets/chunk-JWPE2WC7-BryfpHM5.js +1 -0
- package/packages/web/dist/assets/chunk-NETBCI7D-8ic1iEdT.js +1 -0
- package/packages/web/dist/assets/chunk-WEXAMYUT-nM8tmQT2.js +1 -0
- package/packages/web/dist/assets/chunk-XXDRQBXY-Do28F482.js +1 -0
- package/packages/web/dist/assets/classDiagram-v2-NBCMYWYE-Bop9oNNO.js +217 -0
- package/packages/web/dist/assets/cose-bilkent-JH36ORCC-a7f_bpnt.js +1 -0
- package/packages/web/dist/assets/cynefin-OW5HDTMX-DnArcis_.js +178 -0
- package/packages/web/dist/assets/cynefinDiagram-VND7K2PF-vEuTb1GD.js +62 -0
- package/packages/web/dist/assets/cytoscape.esm-Ix0LnXOy.js +331 -0
- package/packages/web/dist/assets/dagre-6A5THRUB-BgG4MynJ.js +4 -0
- package/packages/web/dist/assets/diagram-22UHCM2B-DRCQpafv.js +200 -0
- package/packages/web/dist/assets/diagram-3UASUU5V-BKgmAXde.js +24 -0
- package/packages/web/dist/assets/diagram-ATOU4E4O-B6Hsy36X.js +3 -0
- package/packages/web/dist/assets/diagram-CDSNMT55-JflyfyoB.js +30 -0
- package/packages/web/dist/assets/diagram-MLGK6HIB-Dd2QPJjT.js +24 -0
- package/packages/web/dist/assets/diagram-MPIPVDR6-DE5QU60x.js +41 -0
- package/packages/web/dist/assets/draco_decoder-C32yEggz.wasm +0 -0
- package/packages/web/dist/assets/draco_decoder-Z1_iN-Ht.wasm +0 -0
- package/packages/web/dist/assets/draco_decoder-fzg4nYZr.js +34 -0
- package/packages/web/dist/assets/draco_wasm_wrapper-DxJM36Ib.js +117 -0
- package/packages/web/dist/assets/draco_wasm_wrapper-fZCQGLGb.js +116 -0
- package/packages/web/dist/assets/ebnfDiagram-ZINNZB2B-D7AQ741b.js +1 -0
- package/packages/web/dist/assets/elk-276RUBZZ-CeewBVLF.js +27 -0
- package/packages/web/dist/assets/erDiagram-OPXOYQCR-mLLYkZ5c.js +99 -0
- package/packages/web/dist/assets/flowDiagram-KWPJA3E3-DtpSpsQN.js +213 -0
- package/packages/web/dist/assets/ganttDiagram-FUAMR5RP-1_lh-3ky.js +292 -0
- package/packages/web/dist/assets/gitGraphDiagram-X574FWY7-DoPXZuT5.js +106 -0
- package/packages/web/dist/assets/graph-Bn3Yngep.js +1 -0
- package/packages/web/dist/assets/index-Cw2Opmx7.js +648 -0
- package/packages/web/dist/assets/index-j0zBRCgT.css +32 -0
- package/packages/web/dist/assets/infoDiagram-VRGFBTTK-DQpRGGiD.js +2 -0
- package/packages/web/dist/assets/ishikawaDiagram-OU5B5YK6-gH5C9Q2e.js +70 -0
- package/packages/web/dist/assets/journeyDiagram-ZHPQQLJL-Bg-oeFjb.js +139 -0
- package/packages/web/dist/assets/kanban-definition-PNTS6WVX-BnpI4VH8.js +89 -0
- package/packages/web/dist/assets/katex-C5jXJg4s.js +257 -0
- package/packages/web/dist/assets/mermaid.core-BwBKxlRA.js +313 -0
- package/packages/web/dist/assets/mindmap-definition-NLK3R4M7-NBnnxEoO.js +96 -0
- package/packages/web/dist/assets/pegDiagram-GJSIUBJH-RrXXbIvO.js +1 -0
- package/packages/web/dist/assets/pieDiagram-5QR66LMP-B27q6Gso.js +39 -0
- package/packages/web/dist/assets/quadrantDiagram-O4NWA36T-DGDsdur2.js +7 -0
- package/packages/web/dist/assets/railroadDiagram-XR7U4H2S-GdjkE3mI.js +1 -0
- package/packages/web/dist/assets/requirementDiagram-PLB6GJNP-DjK0GfgO.js +84 -0
- package/packages/web/dist/assets/sankeyDiagram-IPEJSGJF-BG_AIkwF.js +40 -0
- package/packages/web/dist/assets/scene-D4LPicHk.js +4620 -0
- package/packages/web/dist/assets/sequenceDiagram-PO4LG4MO-CIQwUb4y.js +169 -0
- package/packages/web/dist/assets/sizeCapture-INFHLROL-bpIoPxdJ.js +1 -0
- package/packages/web/dist/assets/stateDiagram-v2-GCMORJYK-8hYXvPPv.js +291 -0
- package/packages/web/dist/assets/swimlanes-2SLR337P-gfflUMF9.js +1 -0
- package/packages/web/dist/assets/swimlanesDiagram-TC7HE7FX-9wdzGXU-.js +8 -0
- package/packages/web/dist/assets/timeline-definition-EJHVYXUP-PHMNoGTZ.js +120 -0
- package/packages/web/dist/assets/usecaseDiagram-POWQR4AR-B2j5iteO.js +370 -0
- package/packages/web/dist/assets/vennDiagram-UO4OBE2U-BzxtZ-_2.js +34 -0
- package/packages/web/dist/assets/wardleyDiagram-VNRHLVJA-DL7YbMpY.js +78 -0
- package/packages/web/dist/assets/xychartDiagram-PMCCYNJV-CisgP1cT.js +7 -0
- package/packages/web/dist/draco/draco_decoder.js +33 -0
- package/packages/web/dist/draco/draco_decoder.wasm +0 -0
- package/packages/web/dist/draco/draco_wasm_wrapper.js +116 -0
- package/packages/web/dist/favicon-16.png +0 -0
- package/packages/web/dist/favicon-32.png +0 -0
- package/packages/web/dist/favicon-48.png +0 -0
- package/packages/web/dist/favicon.ico +0 -0
- package/packages/web/dist/favicon.svg +1 -1
- package/packages/web/dist/icon-192.png +0 -0
- package/packages/web/dist/icon-512.png +0 -0
- package/packages/web/dist/index.html +12 -4
- package/packages/web/dist/logo-light.svg +1 -1
- package/packages/web/dist/logo-mono.svg +2 -0
- package/packages/web/dist/logo-stacked-light.svg +2 -0
- package/packages/web/dist/logo-stacked.svg +2 -0
- package/packages/web/dist/logo-white.svg +2 -0
- package/packages/web/dist/logo.svg +1 -1
- package/packages/web/dist/mark-light.svg +1 -1
- package/packages/web/dist/mark-mono.svg +2 -0
- package/packages/web/dist/mark-small-light.svg +2 -0
- package/packages/web/dist/mark-small.svg +2 -0
- package/packages/web/dist/mark-white.svg +2 -0
- package/packages/web/dist/mark.svg +1 -1
- package/packages/web/dist/models/LICENSE.txt +5 -0
- package/packages/web/dist/models/brain.glb +0 -0
- package/packages/web/dist/site.webmanifest +23 -0
- package/packages/web/dist/wordmark-light.svg +2 -0
- package/packages/web/dist/wordmark.svg +2 -0
- package/packages/web/package.json +1 -1
- package/scripts/rookery.mjs +204 -122
- package/scripts/updater.mjs +227 -0
- package/packages/cli/dist/tui/components/Wordmark.d.ts +0 -35
- package/packages/cli/dist/tui/components/Wordmark.d.ts.map +0 -1
- package/packages/cli/dist/tui/components/Wordmark.js +0 -81
- package/packages/cli/dist/tui/components/Wordmark.js.map +0 -1
- package/packages/core/dist/agents/orchestrator.d.ts +0 -24
- package/packages/core/dist/agents/orchestrator.d.ts.map +0 -1
- package/packages/core/dist/agents/orchestrator.js +0 -88
- package/packages/core/dist/agents/orchestrator.js.map +0 -1
- package/packages/core/dist/agents/roles.d.ts +0 -21
- package/packages/core/dist/agents/roles.d.ts.map +0 -1
- package/packages/core/dist/agents/roles.js +0 -81
- package/packages/core/dist/agents/roles.js.map +0 -1
- package/packages/core/dist/agents/team.d.ts +0 -105
- package/packages/core/dist/agents/team.d.ts.map +0 -1
- package/packages/core/dist/agents/team.js +0 -623
- package/packages/core/dist/agents/team.js.map +0 -1
- package/packages/core/dist/providers/codex.d.ts +0 -10
- package/packages/core/dist/providers/codex.d.ts.map +0 -1
- package/packages/core/dist/providers/codex.js +0 -375
- package/packages/core/dist/providers/codex.js.map +0 -1
- package/packages/core/dist/tools/browser.d.ts +0 -20
- package/packages/core/dist/tools/browser.d.ts.map +0 -1
- package/packages/core/dist/tools/browser.js +0 -72
- package/packages/core/dist/tools/browser.js.map +0 -1
- package/packages/server/dist/routes/agents.d.ts +0 -5
- package/packages/server/dist/routes/agents.d.ts.map +0 -1
- package/packages/server/dist/routes/agents.js +0 -6
- package/packages/server/dist/routes/agents.js.map +0 -1
- package/packages/server/dist/routes/team.d.ts +0 -11
- package/packages/server/dist/routes/team.d.ts.map +0 -1
- package/packages/server/dist/routes/team.js +0 -36
- package/packages/server/dist/routes/team.js.map +0 -1
- package/packages/web/dist/assets/3d-force-graph-BPZmoydi.js +0 -1163
- package/packages/web/dist/assets/index-IBSTzK7-.js +0 -1255
- package/packages/web/dist/assets/index-qUXUui7W.css +0 -1
- package/packages/web/dist/assets/three-spritetext-B9ZIW7c-.js +0 -4
- package/packages/web/dist/assets/three.module-cmFfBtHS.js +0 -4228
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DatabaseSync } from 'node:sqlite';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
2
3
|
import { dirname } from 'node:path';
|
|
3
4
|
import { existsSync, mkdirSync } from 'node:fs';
|
|
4
5
|
/**
|
|
@@ -6,7 +7,7 @@ import { existsSync, mkdirSync } from 'node:fs';
|
|
|
6
7
|
* That keeps Rookery free of native build steps - no node-gyp, no prebuilds,
|
|
7
8
|
* which matters a lot on Windows.
|
|
8
9
|
*/
|
|
9
|
-
export const SCHEMA_VERSION =
|
|
10
|
+
export const SCHEMA_VERSION = 27;
|
|
10
11
|
export function openDatabase(path) {
|
|
11
12
|
if (path !== ':memory:') {
|
|
12
13
|
const dir = dirname(path);
|
|
@@ -17,6 +18,21 @@ export function openDatabase(path) {
|
|
|
17
18
|
db.exec('PRAGMA journal_mode = WAL');
|
|
18
19
|
db.exec('PRAGMA foreign_keys = ON');
|
|
19
20
|
db.exec('PRAGMA synchronous = NORMAL');
|
|
21
|
+
// The CLI opens the same file in its own process, so there are really two
|
|
22
|
+
// writers. Until now that was harmless because the codebase had exactly two
|
|
23
|
+
// short transactions; the dream adds one bracket per recorded turn plus a
|
|
24
|
+
// nightly sweep, so a contended write should wait briefly instead of
|
|
25
|
+
// failing the request outright.
|
|
26
|
+
db.exec('PRAGMA busy_timeout = 5000');
|
|
27
|
+
try {
|
|
28
|
+
assertSchemaNotNewer(db);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
// Refused, not broken: release the handle synchronously so the file is
|
|
32
|
+
// not locked until garbage collection catches up with it.
|
|
33
|
+
db.close();
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
20
36
|
migrate(db);
|
|
21
37
|
return db;
|
|
22
38
|
}
|
|
@@ -24,6 +40,27 @@ function hasColumn(db, table, column) {
|
|
|
24
40
|
const rows = db.prepare('PRAGMA table_info(' + table + ')').all();
|
|
25
41
|
return rows.some((row) => row.name === column);
|
|
26
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* A file that a newer build has ever opened must not quietly continue under
|
|
45
|
+
* this one. `schema_version` is written on every open but nothing ever read
|
|
46
|
+
* it back, so an older build would keep writing `memories` rows beside dream
|
|
47
|
+
* frames recorded against a schema it does not know. Read-only on purpose:
|
|
48
|
+
* this guard never migrates and never writes, it only refuses.
|
|
49
|
+
*/
|
|
50
|
+
function assertSchemaNotNewer(db) {
|
|
51
|
+
const meta = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'meta'").get();
|
|
52
|
+
// A fresh file has no meta table yet; migrate() creates it below.
|
|
53
|
+
if (!meta)
|
|
54
|
+
return;
|
|
55
|
+
const row = db.prepare("SELECT value FROM meta WHERE key = 'schema_version'").get();
|
|
56
|
+
if (!row)
|
|
57
|
+
return;
|
|
58
|
+
const version = Number(row.value);
|
|
59
|
+
if (Number.isFinite(version) && version > SCHEMA_VERSION) {
|
|
60
|
+
throw new Error(`Database schema ${version} is newer than this build supports (${SCHEMA_VERSION}). ` +
|
|
61
|
+
'Update Rookery instead of opening the file with an older build.');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
27
64
|
function migrate(db) {
|
|
28
65
|
db.exec(`
|
|
29
66
|
CREATE TABLE IF NOT EXISTS meta (
|
|
@@ -113,6 +150,13 @@ function migrate(db) {
|
|
|
113
150
|
if (!hasColumn(db, 'memories', 'usefulness')) {
|
|
114
151
|
db.exec('ALTER TABLE memories ADD COLUMN usefulness REAL NOT NULL DEFAULT 0');
|
|
115
152
|
}
|
|
153
|
+
// Schema 11 -> 12: a memory records the words it stands on. Extraction may
|
|
154
|
+
// no longer write anything it cannot quote, and the quote is kept so the
|
|
155
|
+
// claim stays auditable long after the conversation is gone. NULL on every
|
|
156
|
+
// row that predates this, and on everything the user wrote by hand.
|
|
157
|
+
if (!hasColumn(db, 'memories', 'evidence')) {
|
|
158
|
+
db.exec('ALTER TABLE memories ADD COLUMN evidence TEXT');
|
|
159
|
+
}
|
|
116
160
|
db.exec(`
|
|
117
161
|
CREATE INDEX IF NOT EXISTS idx_memories_live
|
|
118
162
|
ON memories(owner, forgotten, importance DESC, updated_at DESC);
|
|
@@ -198,6 +242,330 @@ function migrate(db) {
|
|
|
198
242
|
if (!hasColumn(db, 'sleep_runs', 'resolved_count')) {
|
|
199
243
|
db.exec('ALTER TABLE sleep_runs ADD COLUMN resolved_count INTEGER NOT NULL DEFAULT 0');
|
|
200
244
|
}
|
|
245
|
+
// Schema 11 -> 12: the night also writes skills now, so a run says how many.
|
|
246
|
+
if (!hasColumn(db, 'sleep_runs', 'skill_count')) {
|
|
247
|
+
db.exec('ALTER TABLE sleep_runs ADD COLUMN skill_count INTEGER NOT NULL DEFAULT 0');
|
|
248
|
+
}
|
|
249
|
+
// Schema 12 -> 13: repairing a skill is counted apart from writing one.
|
|
250
|
+
if (!hasColumn(db, 'sleep_runs', 'skill_revised_count')) {
|
|
251
|
+
db.exec('ALTER TABLE sleep_runs ADD COLUMN skill_revised_count INTEGER NOT NULL DEFAULT 0');
|
|
252
|
+
}
|
|
253
|
+
// Schema 13 -> 14: the night reads the day's conversations again, so a run
|
|
254
|
+
// says how many it got through and what they yielded.
|
|
255
|
+
if (!hasColumn(db, 'sleep_runs', 'replayed_count')) {
|
|
256
|
+
db.exec('ALTER TABLE sleep_runs ADD COLUMN replayed_count INTEGER NOT NULL DEFAULT 0');
|
|
257
|
+
}
|
|
258
|
+
if (!hasColumn(db, 'sleep_runs', 'learned_count')) {
|
|
259
|
+
db.exec('ALTER TABLE sleep_runs ADD COLUMN learned_count INTEGER NOT NULL DEFAULT 0');
|
|
260
|
+
}
|
|
261
|
+
// Schema 20 -> 21: dream bookkeeping on the run - traces the nightly probe
|
|
262
|
+
// looked at.
|
|
263
|
+
if (!hasColumn(db, 'sleep_runs', 'dream_traces_seen')) {
|
|
264
|
+
db.exec('ALTER TABLE sleep_runs ADD COLUMN dream_traces_seen INTEGER NOT NULL DEFAULT 0');
|
|
265
|
+
}
|
|
266
|
+
// Schema 20 -> 21: grid placements the nightly probe scored.
|
|
267
|
+
if (!hasColumn(db, 'sleep_runs', 'dream_frames_scored')) {
|
|
268
|
+
db.exec('ALTER TABLE sleep_runs ADD COLUMN dream_frames_scored INTEGER NOT NULL DEFAULT 0');
|
|
269
|
+
}
|
|
270
|
+
// Schema 20 -> 21: model-written candidates. Its writer arrives with
|
|
271
|
+
// Phase 3; Stage 1 leaves it at 0 rather than borrowing the column for
|
|
272
|
+
// something else in between. There is deliberately no dream_promoted -
|
|
273
|
+
// nothing is promoted in Stage 1, so that counter would have no writer.
|
|
274
|
+
if (!hasColumn(db, 'sleep_runs', 'dream_candidates')) {
|
|
275
|
+
db.exec('ALTER TABLE sleep_runs ADD COLUMN dream_candidates INTEGER NOT NULL DEFAULT 0');
|
|
276
|
+
}
|
|
277
|
+
/* ------------------------------ corrections ------------------------------
|
|
278
|
+
A correction is the strongest signal the system gets. When the user says
|
|
279
|
+
"no, not like that", something written down is wrong - and until now
|
|
280
|
+
nothing captured it: the per-turn extractor sees one exchange and writes
|
|
281
|
+
facts, never "that was a correction of what you just did".
|
|
282
|
+
|
|
283
|
+
Rows sit here until a revision pass has looked at them, then they are
|
|
284
|
+
marked consumed rather than removed, so the same correction cannot drag
|
|
285
|
+
the same skill in front of the model night after night. */
|
|
286
|
+
db.exec(`
|
|
287
|
+
CREATE TABLE IF NOT EXISTS corrections (
|
|
288
|
+
id TEXT PRIMARY KEY,
|
|
289
|
+
owner TEXT NOT NULL,
|
|
290
|
+
text TEXT NOT NULL,
|
|
291
|
+
quote TEXT NOT NULL,
|
|
292
|
+
session_id TEXT,
|
|
293
|
+
created_at INTEGER NOT NULL,
|
|
294
|
+
consumed_at INTEGER
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
CREATE INDEX IF NOT EXISTS idx_corrections_open
|
|
298
|
+
ON corrections(owner, consumed_at, created_at DESC);
|
|
299
|
+
`);
|
|
300
|
+
/* ---------------------------- skill bookkeeping ----------------------------
|
|
301
|
+
A skill itself is a file on disk, editable by hand and deliberately not a
|
|
302
|
+
database row. What a database can say about it is everything a file
|
|
303
|
+
cannot: when it was opened, how the work that opened it turned out, which
|
|
304
|
+
memories it was distilled from, and what it looked like before the last
|
|
305
|
+
rewrite. Those three tables are what makes automatic improvement possible
|
|
306
|
+
at all - without them nothing can tell a skill that still holds from one
|
|
307
|
+
whose ground has moved.
|
|
308
|
+
|
|
309
|
+
Rows are keyed by skill NAME, not by a foreign key: the file may be
|
|
310
|
+
deleted from outside Rookery entirely, and an orphaned row is cheaper
|
|
311
|
+
than a constraint that cannot be honoured. */
|
|
312
|
+
db.exec(`
|
|
313
|
+
-- Every use_skill call. The join to assignments is what turns "the skill
|
|
314
|
+
-- was open" into "the run that had it open failed".
|
|
315
|
+
CREATE TABLE IF NOT EXISTS skill_uses (
|
|
316
|
+
id TEXT PRIMARY KEY,
|
|
317
|
+
skill TEXT NOT NULL,
|
|
318
|
+
owner TEXT NOT NULL,
|
|
319
|
+
assignment_id TEXT,
|
|
320
|
+
session_id TEXT,
|
|
321
|
+
created_at INTEGER NOT NULL
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
CREATE INDEX IF NOT EXISTS idx_skill_uses_skill
|
|
325
|
+
ON skill_uses(skill, created_at DESC);
|
|
326
|
+
|
|
327
|
+
-- Which memories a distilled skill stands on. When one of them is
|
|
328
|
+
-- superseded, put to sleep or edited, the skill above it is suspect.
|
|
329
|
+
CREATE TABLE IF NOT EXISTS skill_sources (
|
|
330
|
+
skill TEXT NOT NULL,
|
|
331
|
+
memory_id TEXT NOT NULL REFERENCES memories(id) ON DELETE CASCADE,
|
|
332
|
+
owner TEXT NOT NULL,
|
|
333
|
+
created_at INTEGER NOT NULL,
|
|
334
|
+
PRIMARY KEY (skill, memory_id)
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
CREATE INDEX IF NOT EXISTS idx_skill_sources_memory
|
|
338
|
+
ON skill_sources(memory_id);
|
|
339
|
+
|
|
340
|
+
-- The file as it read BEFORE an unattended write replaced it. NULL
|
|
341
|
+
-- content means the skill did not exist yet, so undoing that write means
|
|
342
|
+
-- deleting the folder rather than restoring text.
|
|
343
|
+
CREATE TABLE IF NOT EXISTS skill_versions (
|
|
344
|
+
id TEXT PRIMARY KEY,
|
|
345
|
+
skill TEXT NOT NULL,
|
|
346
|
+
content TEXT,
|
|
347
|
+
sleep_run_id TEXT,
|
|
348
|
+
created_at INTEGER NOT NULL
|
|
349
|
+
);
|
|
350
|
+
|
|
351
|
+
CREATE INDEX IF NOT EXISTS idx_skill_versions_run
|
|
352
|
+
ON skill_versions(sleep_run_id, created_at);
|
|
353
|
+
`);
|
|
354
|
+
/* -------------------------------- dream ---------------------------------
|
|
355
|
+
docs/concepts/dream-and-recursive-self-improvement.md. A trace is one
|
|
356
|
+
recall call - several calls share a turn_id - and a frame is the record
|
|
357
|
+
that makes a turn replayable: everything a candidate policy could have
|
|
358
|
+
needed, frozen at the permissive-most corner of the declared parameter
|
|
359
|
+
box. Frames are a verbatim store (the literal query, full memory
|
|
360
|
+
snapshots), which is why they carry owner and session columns of their
|
|
361
|
+
own: the delete paths must reach them without parsing the payload.
|
|
362
|
+
|
|
363
|
+
`dream_labels` is created as an empty table. Its writers arrive with
|
|
364
|
+
Phase 2; creating the shape now keeps that stage free of another schema
|
|
365
|
+
bump. `memory_touches` is append-only bookkeeping, never a label source:
|
|
366
|
+
the monotone access/usefulness counters cannot be reconstructed later if
|
|
367
|
+
the record is not kept from the start. */
|
|
368
|
+
db.exec(`
|
|
369
|
+
CREATE TABLE IF NOT EXISTS dream_traces (
|
|
370
|
+
id TEXT PRIMARY KEY,
|
|
371
|
+
turn_id TEXT NOT NULL, -- groups the calls of one turn
|
|
372
|
+
owner TEXT NOT NULL,
|
|
373
|
+
kind TEXT NOT NULL, -- turn | assignment | night
|
|
374
|
+
site TEXT NOT NULL, -- turn | extract | tool | inspect
|
|
375
|
+
pipeline TEXT NOT NULL, -- assistant | agent
|
|
376
|
+
session_id TEXT,
|
|
377
|
+
session_kind TEXT, -- chat | voice | mail | schedule
|
|
378
|
+
assignment_id TEXT,
|
|
379
|
+
sleep_run_id TEXT,
|
|
380
|
+
turn_index INTEGER NOT NULL DEFAULT 0,
|
|
381
|
+
policy_set TEXT NOT NULL, -- JSON: effective parameter set per slot
|
|
382
|
+
framed INTEGER NOT NULL DEFAULT 0,
|
|
383
|
+
holdout INTEGER NOT NULL DEFAULT 0,
|
|
384
|
+
audit INTEGER NOT NULL DEFAULT 0, -- the frozen audit set
|
|
385
|
+
degraded TEXT, -- NULL | no-tokens | fts-threw
|
|
386
|
+
started_at INTEGER NOT NULL,
|
|
387
|
+
finished_at INTEGER,
|
|
388
|
+
created_at INTEGER NOT NULL
|
|
389
|
+
);
|
|
390
|
+
CREATE INDEX IF NOT EXISTS idx_dream_traces_owner ON dream_traces(owner, started_at DESC);
|
|
391
|
+
CREATE INDEX IF NOT EXISTS idx_dream_traces_session ON dream_traces(session_id, turn_index);
|
|
392
|
+
CREATE INDEX IF NOT EXISTS idx_dream_traces_turn ON dream_traces(turn_id);
|
|
393
|
+
CREATE INDEX IF NOT EXISTS idx_dream_traces_open ON dream_traces(finished_at);
|
|
394
|
+
-- The trace sweep cuts on created_at exactly like the frame sweep does
|
|
395
|
+
-- (store.ts, sweepDreamTraces); without this index every LIMIT batch of
|
|
396
|
+
-- the nightly sweep full-scans the table.
|
|
397
|
+
CREATE INDEX IF NOT EXISTS idx_dream_traces_age ON dream_traces(created_at);
|
|
398
|
+
|
|
399
|
+
CREATE TABLE IF NOT EXISTS dream_frames (
|
|
400
|
+
trace_id TEXT NOT NULL REFERENCES dream_traces(id) ON DELETE CASCADE,
|
|
401
|
+
slot TEXT NOT NULL, -- recall
|
|
402
|
+
frame_v INTEGER NOT NULL,
|
|
403
|
+
owner TEXT NOT NULL, -- for the delete paths, without reading the payload
|
|
404
|
+
session_id TEXT, -- ditto
|
|
405
|
+
box TEXT NOT NULL, -- JSON
|
|
406
|
+
corpus_stamp_id TEXT NOT NULL, -- points at the night's document-frequency stamp in meta
|
|
407
|
+
payload TEXT NOT NULL, -- JSON: the whole frame
|
|
408
|
+
bytes INTEGER NOT NULL,
|
|
409
|
+
created_at INTEGER NOT NULL,
|
|
410
|
+
PRIMARY KEY (trace_id, slot)
|
|
411
|
+
);
|
|
412
|
+
CREATE INDEX IF NOT EXISTS idx_dream_frames_age ON dream_frames(created_at);
|
|
413
|
+
CREATE INDEX IF NOT EXISTS idx_dream_frames_owner ON dream_frames(owner, session_id);
|
|
414
|
+
|
|
415
|
+
-- turn_id is NOT NULL and sits in the primary key, so a session-scoped
|
|
416
|
+
-- label (concept 4.2a: an ambiguous quote resolves to no turn at all,
|
|
417
|
+
-- never a guess) has nowhere else to carry its locator. It goes here
|
|
418
|
+
-- instead: turn_id holds the SESSION id when scope = 'session', and only
|
|
419
|
+
-- scope = 'turn' rows (turn_id holding an actual turn id) feed DCG.
|
|
420
|
+
CREATE TABLE IF NOT EXISTS dream_labels (
|
|
421
|
+
turn_id TEXT NOT NULL,
|
|
422
|
+
target TEXT NOT NULL, -- memory id, or '*' for a per-trace weight
|
|
423
|
+
source TEXT NOT NULL, -- correction | review | merge | user
|
|
424
|
+
relevance REAL NOT NULL, -- 1 = shown relevant, 0 = shown irrelevant
|
|
425
|
+
scope TEXT NOT NULL, -- turn | session
|
|
426
|
+
evidence TEXT,
|
|
427
|
+
dead_at INTEGER, -- target removed later; the row stays
|
|
428
|
+
created_at INTEGER NOT NULL,
|
|
429
|
+
PRIMARY KEY (turn_id, target, source)
|
|
430
|
+
);
|
|
431
|
+
CREATE INDEX IF NOT EXISTS idx_dream_labels_target ON dream_labels(target);
|
|
432
|
+
|
|
433
|
+
CREATE TABLE IF NOT EXISTS memory_touches (
|
|
434
|
+
id TEXT PRIMARY KEY,
|
|
435
|
+
owner TEXT NOT NULL,
|
|
436
|
+
memory_id TEXT NOT NULL,
|
|
437
|
+
turn_id TEXT,
|
|
438
|
+
trace_id TEXT REFERENCES dream_traces(id) ON DELETE CASCADE,
|
|
439
|
+
policy_id TEXT, -- policy_versions.id, NULL until Phase 3
|
|
440
|
+
at INTEGER NOT NULL
|
|
441
|
+
);
|
|
442
|
+
CREATE INDEX IF NOT EXISTS idx_memory_touches_memory ON memory_touches(memory_id, at);
|
|
443
|
+
CREATE INDEX IF NOT EXISTS idx_memory_touches_owner ON memory_touches(owner, at);
|
|
444
|
+
CREATE INDEX IF NOT EXISTS idx_memory_touches_trace ON memory_touches(trace_id);
|
|
445
|
+
`);
|
|
446
|
+
/* --------------------------- dream, stage 2+ ----------------------------
|
|
447
|
+
Schema 23 -> 24. docs/concepts/dream-stage2plus-buildplan.md AP1;
|
|
448
|
+
verbatim column lists from dream-and-recursive-self-improvement.md 8.5
|
|
449
|
+
(policy_versions, dream_slot_state) and 8.6 (dream_evals).
|
|
450
|
+
|
|
451
|
+
dream_episodes is NOT a second verbatim store: the steps of an episode
|
|
452
|
+
already live in the turn_events journal (turns/turn_events above). This
|
|
453
|
+
table is only the index Phase 6's first-divergence judging needs over
|
|
454
|
+
that journal - one row per turn or assignment, keyed the same way. */
|
|
455
|
+
db.exec(`
|
|
456
|
+
CREATE TABLE IF NOT EXISTS policy_versions (
|
|
457
|
+
id TEXT PRIMARY KEY,
|
|
458
|
+
owner TEXT NOT NULL,
|
|
459
|
+
slot TEXT NOT NULL,
|
|
460
|
+
version INTEGER NOT NULL,
|
|
461
|
+
params TEXT NOT NULL, -- JSON, full parameter set
|
|
462
|
+
box TEXT NOT NULL, -- JSON, the box it was validated against
|
|
463
|
+
origin TEXT NOT NULL, -- default | dream | user
|
|
464
|
+
parent_id TEXT,
|
|
465
|
+
prev_active_id TEXT, -- what was active WHEN this one was promoted
|
|
466
|
+
sleep_run_id TEXT,
|
|
467
|
+
rationale TEXT,
|
|
468
|
+
replay_score REAL,
|
|
469
|
+
replay_n INTEGER,
|
|
470
|
+
baseline_score REAL,
|
|
471
|
+
audit_delta REAL, -- against the factory default, on the audit set
|
|
472
|
+
audit_ci_low REAL,
|
|
473
|
+
online_score REAL,
|
|
474
|
+
promoted_at INTEGER,
|
|
475
|
+
retired_at INTEGER,
|
|
476
|
+
created_at INTEGER NOT NULL
|
|
477
|
+
);
|
|
478
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_policy_slot_version ON policy_versions(owner, slot, version);
|
|
479
|
+
CREATE INDEX IF NOT EXISTS idx_policy_active ON policy_versions(owner, slot, promoted_at DESC);
|
|
480
|
+
|
|
481
|
+
CREATE TABLE IF NOT EXISTS dream_slot_state (
|
|
482
|
+
owner TEXT NOT NULL,
|
|
483
|
+
slot TEXT NOT NULL,
|
|
484
|
+
frozen_at INTEGER,
|
|
485
|
+
frozen_reason TEXT, -- calibration | staleness | agreement | manual
|
|
486
|
+
cooldown_until INTEGER,
|
|
487
|
+
last_promoted INTEGER,
|
|
488
|
+
PRIMARY KEY (owner, slot)
|
|
489
|
+
);
|
|
490
|
+
|
|
491
|
+
CREATE TABLE IF NOT EXISTS dream_evals (
|
|
492
|
+
id TEXT PRIMARY KEY,
|
|
493
|
+
sleep_run_id TEXT NOT NULL,
|
|
494
|
+
policy_id TEXT NOT NULL REFERENCES policy_versions(id) ON DELETE CASCADE,
|
|
495
|
+
slot TEXT NOT NULL,
|
|
496
|
+
traces INTEGER NOT NULL, -- offered
|
|
497
|
+
closed INTEGER NOT NULL, -- closed and scored
|
|
498
|
+
abstained INTEGER NOT NULL,
|
|
499
|
+
abstain_reasons TEXT NOT NULL, -- JSON histogram
|
|
500
|
+
reachable_rate REAL NOT NULL,
|
|
501
|
+
label_coverage REAL NOT NULL,
|
|
502
|
+
cost_only_share REAL NOT NULL,
|
|
503
|
+
score REAL NOT NULL,
|
|
504
|
+
baseline REAL NOT NULL,
|
|
505
|
+
delta REAL NOT NULL,
|
|
506
|
+
ci_low REAL NOT NULL, -- cluster bootstrap over sessions, 95 percent
|
|
507
|
+
ci_high REAL NOT NULL,
|
|
508
|
+
audit_delta REAL, -- against the factory default, on the audit set
|
|
509
|
+
audit_ci_low REAL,
|
|
510
|
+
delta_live REAL, -- freshness check
|
|
511
|
+
sign_agree INTEGER, -- 1 | 0 | NULL = undetermined (|delta| <= margin)
|
|
512
|
+
eval_ms INTEGER NOT NULL,
|
|
513
|
+
trace_set_hash TEXT NOT NULL,
|
|
514
|
+
evidence_digest TEXT, -- condensed rationale, no verbatim quotes
|
|
515
|
+
promoted INTEGER NOT NULL DEFAULT 0,
|
|
516
|
+
detail TEXT, -- JSON: score per label source, gaming counters
|
|
517
|
+
created_at INTEGER NOT NULL
|
|
518
|
+
);
|
|
519
|
+
CREATE INDEX IF NOT EXISTS idx_dream_evals_run ON dream_evals(sleep_run_id);
|
|
520
|
+
|
|
521
|
+
CREATE TABLE IF NOT EXISTS dream_episodes (
|
|
522
|
+
id TEXT PRIMARY KEY, -- turns.id, or assignments.id
|
|
523
|
+
owner TEXT NOT NULL,
|
|
524
|
+
kind TEXT NOT NULL, -- turn | assignment
|
|
525
|
+
session_id TEXT,
|
|
526
|
+
slot TEXT NOT NULL,
|
|
527
|
+
steps INTEGER NOT NULL,
|
|
528
|
+
outcome TEXT NOT NULL, -- success | failure | unknown
|
|
529
|
+
holdout INTEGER NOT NULL DEFAULT 0,
|
|
530
|
+
audit INTEGER NOT NULL DEFAULT 0,
|
|
531
|
+
started_at INTEGER NOT NULL,
|
|
532
|
+
finished_at INTEGER,
|
|
533
|
+
created_at INTEGER NOT NULL
|
|
534
|
+
);
|
|
535
|
+
CREATE INDEX IF NOT EXISTS idx_dream_episodes_owner ON dream_episodes(owner, created_at);
|
|
536
|
+
`);
|
|
537
|
+
// Schema 23 -> 24: a correction is only turn-locatable once it carries the
|
|
538
|
+
// turn it corrects (addCorrection took only session_id until now).
|
|
539
|
+
if (!hasColumn(db, 'corrections', 'turn_id')) {
|
|
540
|
+
db.exec('ALTER TABLE corrections ADD COLUMN turn_id TEXT');
|
|
541
|
+
}
|
|
542
|
+
// Schema 23 -> 24: label(m) needs to know whose memory it is judging and
|
|
543
|
+
// which session produced it - target alone is not enough once a label can
|
|
544
|
+
// come from outside the labelled owner's own turn.
|
|
545
|
+
if (!hasColumn(db, 'dream_labels', 'owner')) {
|
|
546
|
+
db.exec('ALTER TABLE dream_labels ADD COLUMN owner TEXT');
|
|
547
|
+
}
|
|
548
|
+
if (!hasColumn(db, 'dream_labels', 'session_id')) {
|
|
549
|
+
db.exec('ALTER TABLE dream_labels ADD COLUMN session_id TEXT');
|
|
550
|
+
}
|
|
551
|
+
// Schema 23 -> 24: locateTurn resolves a quote to the turn that carried it,
|
|
552
|
+
// and that resolution has to land somewhere a correction label can join on.
|
|
553
|
+
if (!hasColumn(db, 'messages', 'turn_id')) {
|
|
554
|
+
db.exec('ALTER TABLE messages ADD COLUMN turn_id TEXT');
|
|
555
|
+
}
|
|
556
|
+
// Schema 23 -> 24: the promotion gate and the label writers get their own
|
|
557
|
+
// counters on the run, in step with the other dream counters (8.8).
|
|
558
|
+
if (!hasColumn(db, 'sleep_runs', 'dream_promoted')) {
|
|
559
|
+
db.exec('ALTER TABLE sleep_runs ADD COLUMN dream_promoted INTEGER NOT NULL DEFAULT 0');
|
|
560
|
+
}
|
|
561
|
+
if (!hasColumn(db, 'sleep_runs', 'dream_labels_written')) {
|
|
562
|
+
db.exec('ALTER TABLE sleep_runs ADD COLUMN dream_labels_written INTEGER NOT NULL DEFAULT 0');
|
|
563
|
+
}
|
|
564
|
+
db.exec(`
|
|
565
|
+
CREATE INDEX IF NOT EXISTS idx_dream_labels_source ON dream_labels(source, created_at);
|
|
566
|
+
CREATE INDEX IF NOT EXISTS idx_corrections_turn ON corrections(turn_id);
|
|
567
|
+
CREATE INDEX IF NOT EXISTS idx_messages_turn ON messages(turn_id);
|
|
568
|
+
`);
|
|
201
569
|
// FTS index over memory content plus tags, kept in sync by triggers.
|
|
202
570
|
db.exec(`
|
|
203
571
|
CREATE VIRTUAL TABLE IF NOT EXISTS memories_fts USING fts5(
|
|
@@ -224,6 +592,13 @@ function migrate(db) {
|
|
|
224
592
|
INSERT INTO memories_fts(rowid, content, tags)
|
|
225
593
|
VALUES (new.rowid, new.content, new.tags);
|
|
226
594
|
END;
|
|
595
|
+
|
|
596
|
+
-- The dream's corpus watch reads the document frequency of a frame's
|
|
597
|
+
-- tokens from here, once per night - never inside a turn, because the
|
|
598
|
+
-- vocabulary scan walks the whole index. It lives beside the index it
|
|
599
|
+
-- reads so the two cannot drift apart.
|
|
600
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS memories_fts_v
|
|
601
|
+
USING fts5vocab(memories_fts, 'row');
|
|
227
602
|
`);
|
|
228
603
|
// The organisation: durable agents, their structure, and what they did.
|
|
229
604
|
db.exec(`
|
|
@@ -343,6 +718,40 @@ function migrate(db) {
|
|
|
343
718
|
|
|
344
719
|
CREATE INDEX IF NOT EXISTS idx_tasks_board
|
|
345
720
|
ON tasks(org_id, parent_id, status, updated_at DESC);
|
|
721
|
+
`);
|
|
722
|
+
// Schema 9 -> 10: the board gains a manual order, and a task's runs get a
|
|
723
|
+
// real history instead of a single overwritable pointer. `tasks.assignment_id`
|
|
724
|
+
// stays as "the current run" for cheap reads; `task_assignments` is the
|
|
725
|
+
// durable record that survives a rerun clobbering that pointer.
|
|
726
|
+
if (!hasColumn(db, 'tasks', 'sort_order')) {
|
|
727
|
+
db.exec('ALTER TABLE tasks ADD COLUMN sort_order INTEGER NOT NULL DEFAULT 0');
|
|
728
|
+
}
|
|
729
|
+
// Schema 21 -> 22: a run gets a name of its own. Nullable on purpose - a
|
|
730
|
+
// row written before the name existed keeps reading, and the store names
|
|
731
|
+
// it from its own first line rather than writing a guess back over it.
|
|
732
|
+
if (!hasColumn(db, 'assignments', 'title')) {
|
|
733
|
+
db.exec('ALTER TABLE assignments ADD COLUMN title TEXT');
|
|
734
|
+
}
|
|
735
|
+
// Schema 22 -> 23: an agent's mail gets a register of its own - two to
|
|
736
|
+
// four sentences on HOW this person writes, colouring the output without
|
|
737
|
+
// ever steering the work (that stays `instructions`). Nullable: a row
|
|
738
|
+
// hired before this column existed reads back with a null voice and stays
|
|
739
|
+
// silently neutral (decision E11, F5).
|
|
740
|
+
if (!hasColumn(db, 'agents', 'voice')) {
|
|
741
|
+
db.exec('ALTER TABLE agents ADD COLUMN voice TEXT');
|
|
742
|
+
}
|
|
743
|
+
db.exec(`
|
|
744
|
+
CREATE TABLE IF NOT EXISTS task_assignments (
|
|
745
|
+
task_id TEXT NOT NULL REFERENCES tasks(id) ON DELETE CASCADE,
|
|
746
|
+
assignment_id TEXT NOT NULL REFERENCES assignments(id) ON DELETE CASCADE,
|
|
747
|
+
created_at INTEGER NOT NULL,
|
|
748
|
+
PRIMARY KEY (task_id, assignment_id)
|
|
749
|
+
);
|
|
750
|
+
|
|
751
|
+
CREATE INDEX IF NOT EXISTS idx_task_assignments_assignment
|
|
752
|
+
ON task_assignments(assignment_id);
|
|
753
|
+
CREATE INDEX IF NOT EXISTS idx_task_assignments_task
|
|
754
|
+
ON task_assignments(task_id, created_at DESC);
|
|
346
755
|
`);
|
|
347
756
|
// Schedules: standing orders that fire on a cron expression, and their runs.
|
|
348
757
|
db.exec(`
|
|
@@ -396,19 +805,487 @@ function migrate(db) {
|
|
|
396
805
|
if (!hasColumn(db, 'cron_jobs', 'remaining_runs')) {
|
|
397
806
|
db.exec('ALTER TABLE cron_jobs ADD COLUMN remaining_runs INTEGER');
|
|
398
807
|
}
|
|
808
|
+
// Schema 17 -> 18: a schedule can also be fired by something that happened -
|
|
809
|
+
// a webhook call or a heartbeat listener - instead of only by the clock.
|
|
810
|
+
// `trigger_mode` decides whether the clock fires it at all; an event may
|
|
811
|
+
// fire either kind, so a clock-backed job keeps its expression as the
|
|
812
|
+
// backstop for events that never arrived. The webhook secret is its own
|
|
813
|
+
// credential per job: handing one out never hands out the server's token,
|
|
814
|
+
// and revoking one never touches another job.
|
|
815
|
+
if (!hasColumn(db, 'cron_jobs', 'trigger_mode')) {
|
|
816
|
+
db.exec("ALTER TABLE cron_jobs ADD COLUMN trigger_mode TEXT NOT NULL DEFAULT 'schedule'");
|
|
817
|
+
}
|
|
818
|
+
if (!hasColumn(db, 'cron_jobs', 'webhook_token')) {
|
|
819
|
+
db.exec('ALTER TABLE cron_jobs ADD COLUMN webhook_token TEXT');
|
|
820
|
+
}
|
|
821
|
+
if (!hasColumn(db, 'cron_jobs', 'event_cooldown_ms')) {
|
|
822
|
+
db.exec('ALTER TABLE cron_jobs ADD COLUMN event_cooldown_ms INTEGER');
|
|
823
|
+
}
|
|
824
|
+
if (!hasColumn(db, 'cron_runs', 'source')) {
|
|
825
|
+
db.exec('ALTER TABLE cron_runs ADD COLUMN source TEXT');
|
|
826
|
+
}
|
|
827
|
+
// One secret, one job. Partial, so the many jobs without a webhook do not
|
|
828
|
+
// all collide on NULL.
|
|
829
|
+
db.exec(`
|
|
830
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_cron_jobs_webhook
|
|
831
|
+
ON cron_jobs(webhook_token) WHERE webhook_token IS NOT NULL;
|
|
832
|
+
`);
|
|
399
833
|
if (!hasColumn(db, 'messages', 'tool_calls')) {
|
|
400
834
|
db.exec('ALTER TABLE messages ADD COLUMN tool_calls TEXT');
|
|
401
835
|
}
|
|
836
|
+
// Schema 15 -> 16: the ordered transcript. `tool_calls` keeps the flat
|
|
837
|
+
// compatibility view, `blocks` stores text, thinking and tools interleaved
|
|
838
|
+
// in the order they actually arrived (see `TurnBlocks`). NULL on every row
|
|
839
|
+
// that predates this; readers fall back to `content` + `toolCalls`.
|
|
840
|
+
if (!hasColumn(db, 'messages', 'blocks')) {
|
|
841
|
+
db.exec('ALTER TABLE messages ADD COLUMN blocks TEXT');
|
|
842
|
+
}
|
|
402
843
|
// Schema 8 -> 9: a project remembers whether its own `.mcp.json` was approved.
|
|
403
844
|
// Runs after the projects table exists (created above), so a fresh database
|
|
404
845
|
// gets the column from CREATE TABLE and this is a no-op for it.
|
|
405
846
|
if (!hasColumn(db, 'projects', 'mcp_trust')) {
|
|
406
847
|
db.exec('ALTER TABLE projects ADD COLUMN mcp_trust TEXT');
|
|
407
848
|
}
|
|
849
|
+
// Schema 10 -> 11: mail replaces agent_messages. To + Cc, a subject, a
|
|
850
|
+
// thread, and per-recipient read state - things one row per message
|
|
851
|
+
// (agent_messages) cannot express. agent_messages stays untouched rather
|
|
852
|
+
// than dropped; nothing reads or writes it once the org tools switch over.
|
|
853
|
+
db.exec(`
|
|
854
|
+
CREATE TABLE IF NOT EXISTS mail (
|
|
855
|
+
id TEXT PRIMARY KEY,
|
|
856
|
+
org_id TEXT NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
|
|
857
|
+
from_kind TEXT NOT NULL,
|
|
858
|
+
from_agent_id TEXT,
|
|
859
|
+
subject TEXT NOT NULL,
|
|
860
|
+
body TEXT NOT NULL,
|
|
861
|
+
thread_id TEXT NOT NULL,
|
|
862
|
+
in_reply_to TEXT,
|
|
863
|
+
depth INTEGER NOT NULL DEFAULT 0,
|
|
864
|
+
assignment_id TEXT,
|
|
865
|
+
created_at INTEGER NOT NULL
|
|
866
|
+
);
|
|
867
|
+
CREATE INDEX IF NOT EXISTS idx_mail_thread ON mail(org_id, thread_id, created_at);
|
|
868
|
+
|
|
869
|
+
CREATE TABLE IF NOT EXISTS mail_recipients (
|
|
870
|
+
id TEXT PRIMARY KEY,
|
|
871
|
+
mail_id TEXT NOT NULL REFERENCES mail(id) ON DELETE CASCADE,
|
|
872
|
+
recipient_kind TEXT NOT NULL,
|
|
873
|
+
recipient_id TEXT,
|
|
874
|
+
box TEXT NOT NULL,
|
|
875
|
+
read_at INTEGER
|
|
876
|
+
);
|
|
877
|
+
CREATE INDEX IF NOT EXISTS idx_mail_recipients_box
|
|
878
|
+
ON mail_recipients(recipient_kind, recipient_id, read_at, mail_id);
|
|
879
|
+
`);
|
|
880
|
+
migrateAgentMessagesToMail(db);
|
|
881
|
+
backfillMailSessionKind(db);
|
|
882
|
+
backfillScheduleSessionKind(db);
|
|
883
|
+
/* ------------------------- agent performance reviews -------------------------
|
|
884
|
+
docs/concepts/agent-performance-management.md. A review judges one
|
|
885
|
+
assignment against the agent's own role, never against other agents -
|
|
886
|
+
`agent_reviews` is organisation data, not a memory, so it never enters an
|
|
887
|
+
agent's own prompt. An action is the personnel record behind a review
|
|
888
|
+
trail: what actually changed about an agent, and why, so a later
|
|
889
|
+
reconfig can be judged and rolled back instead of vanishing the way
|
|
890
|
+
`updateAgent` silently overwrites `instructions` today. */
|
|
891
|
+
db.exec(`
|
|
892
|
+
CREATE TABLE IF NOT EXISTS agent_reviews (
|
|
893
|
+
id TEXT PRIMARY KEY,
|
|
894
|
+
org_id TEXT NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
|
|
895
|
+
agent_id TEXT NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
|
896
|
+
assignment_id TEXT REFERENCES assignments(id) ON DELETE CASCADE,
|
|
897
|
+
task_id TEXT,
|
|
898
|
+
source TEXT NOT NULL,
|
|
899
|
+
overall INTEGER NOT NULL,
|
|
900
|
+
quality INTEGER,
|
|
901
|
+
completeness INTEGER,
|
|
902
|
+
reliability INTEGER,
|
|
903
|
+
communication INTEGER,
|
|
904
|
+
efficiency INTEGER,
|
|
905
|
+
comment TEXT,
|
|
906
|
+
tags TEXT NOT NULL DEFAULT '[]',
|
|
907
|
+
failed_run INTEGER NOT NULL DEFAULT 0,
|
|
908
|
+
created_at INTEGER NOT NULL
|
|
909
|
+
);
|
|
910
|
+
|
|
911
|
+
CREATE INDEX IF NOT EXISTS idx_agent_reviews_agent
|
|
912
|
+
ON agent_reviews(agent_id, created_at DESC);
|
|
913
|
+
-- One effective review per source per assignment; a later user rating on
|
|
914
|
+
-- the same assignment upserts instead of stacking beside the first.
|
|
915
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_agent_reviews_once
|
|
916
|
+
ON agent_reviews(assignment_id, source);
|
|
917
|
+
|
|
918
|
+
CREATE TABLE IF NOT EXISTS agent_actions (
|
|
919
|
+
id TEXT PRIMARY KEY,
|
|
920
|
+
org_id TEXT NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
|
|
921
|
+
agent_id TEXT NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
|
922
|
+
kind TEXT NOT NULL,
|
|
923
|
+
stage INTEGER NOT NULL DEFAULT 0,
|
|
924
|
+
reason TEXT NOT NULL,
|
|
925
|
+
before_text TEXT,
|
|
926
|
+
after_text TEXT,
|
|
927
|
+
agent_note TEXT,
|
|
928
|
+
handover_text TEXT,
|
|
929
|
+
review_ids TEXT NOT NULL DEFAULT '[]',
|
|
930
|
+
decided_by TEXT NOT NULL,
|
|
931
|
+
successor_agent_id TEXT,
|
|
932
|
+
created_at INTEGER NOT NULL,
|
|
933
|
+
CHECK (kind <> 'reconfig' OR (before_text IS NOT NULL AND after_text IS NOT NULL))
|
|
934
|
+
);
|
|
935
|
+
|
|
936
|
+
CREATE INDEX IF NOT EXISTS idx_agent_actions_agent
|
|
937
|
+
ON agent_actions(agent_id, created_at DESC);
|
|
938
|
+
CREATE INDEX IF NOT EXISTS idx_agent_actions_successor
|
|
939
|
+
ON agent_actions(successor_agent_id);
|
|
940
|
+
`);
|
|
941
|
+
// Schema 14 -> 15: replacing an agent archives its memory bank instead of
|
|
942
|
+
// deleting it - archived rows stay auditable on the retired agent's page
|
|
943
|
+
// and, once the recall path is taught to filter them, out of reach for
|
|
944
|
+
// anyone else.
|
|
945
|
+
if (!hasColumn(db, 'memories', 'archived_at')) {
|
|
946
|
+
db.exec('ALTER TABLE memories ADD COLUMN archived_at INTEGER');
|
|
947
|
+
}
|
|
948
|
+
// Schema 16 -> 17: one protocol row per mail thread. `kind` is what the
|
|
949
|
+
// thread *is* - a chat, a work assignment, a run's report - and every mail
|
|
950
|
+
// in the thread inherits it, so replies cannot drift a conversation from
|
|
951
|
+
// one folder into another. `task_id` is the board side of the coupling: an
|
|
952
|
+
// assignment thread names the task it created, which is what makes a task
|
|
953
|
+
// traceable back through its mail. No FK on task_id, same reason
|
|
954
|
+
// mail.assignment_id has none - the referenced row may be cleaned up
|
|
955
|
+
// independently, and the mail trail should survive it.
|
|
956
|
+
db.exec(`
|
|
957
|
+
CREATE TABLE IF NOT EXISTS mail_threads (
|
|
958
|
+
thread_id TEXT PRIMARY KEY,
|
|
959
|
+
org_id TEXT NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
|
|
960
|
+
kind TEXT NOT NULL DEFAULT 'chat',
|
|
961
|
+
task_id TEXT,
|
|
962
|
+
archived_at INTEGER,
|
|
963
|
+
created_at INTEGER NOT NULL
|
|
964
|
+
);
|
|
965
|
+
CREATE INDEX IF NOT EXISTS idx_mail_threads_org
|
|
966
|
+
ON mail_threads(org_id, kind, archived_at);
|
|
967
|
+
CREATE INDEX IF NOT EXISTS idx_mail_threads_task
|
|
968
|
+
ON mail_threads(task_id);
|
|
969
|
+
`);
|
|
970
|
+
backfillMailThreads(db);
|
|
971
|
+
// Schema 19: the running-turn journal. Every event a conversation turn
|
|
972
|
+
// yields is a row the moment it is yielded, so any client - a reloaded
|
|
973
|
+
// tab, another browser, whoever opens the conversation next - can rebuild
|
|
974
|
+
// the turn exactly as it stood, and the live stream just continues on top.
|
|
975
|
+
// Schema 20 widens the key: an assignment run has no conversation, so a
|
|
976
|
+
// turn is owned by a session, an assignment, or both.
|
|
977
|
+
db.exec(`
|
|
978
|
+
CREATE TABLE IF NOT EXISTS turns (
|
|
979
|
+
id TEXT PRIMARY KEY,
|
|
980
|
+
session_id TEXT REFERENCES sessions(id) ON DELETE CASCADE,
|
|
981
|
+
assignment_id TEXT,
|
|
982
|
+
kind TEXT NOT NULL DEFAULT 'chat',
|
|
983
|
+
status TEXT NOT NULL DEFAULT 'running',
|
|
984
|
+
started_at INTEGER NOT NULL,
|
|
985
|
+
ended_at INTEGER
|
|
986
|
+
);
|
|
987
|
+
CREATE INDEX IF NOT EXISTS idx_turns_session
|
|
988
|
+
ON turns(session_id, started_at);
|
|
989
|
+
CREATE TABLE IF NOT EXISTS turn_events (
|
|
990
|
+
turn_id TEXT NOT NULL REFERENCES turns(id) ON DELETE CASCADE,
|
|
991
|
+
seq INTEGER NOT NULL,
|
|
992
|
+
json TEXT NOT NULL,
|
|
993
|
+
PRIMARY KEY (turn_id, seq)
|
|
994
|
+
);
|
|
995
|
+
`);
|
|
996
|
+
// Schema 19 -> 20: the session column loses its NOT NULL. A rebuild rather
|
|
997
|
+
// than two ALTERs, because SQLite cannot drop a constraint in place. Both
|
|
998
|
+
// tables move: a plain rename would leave `turn_events` pointing at the
|
|
999
|
+
// discarded name, so it is recreated beside its parent, rows first - the
|
|
1000
|
+
// journal is the record, and none of it is dropped.
|
|
1001
|
+
const turnsShape = db.prepare("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'turns'").get();
|
|
1002
|
+
if (turnsShape && !turnsShape.sql.includes('assignment_id')) {
|
|
1003
|
+
db.exec('PRAGMA foreign_keys = OFF');
|
|
1004
|
+
db.exec(`
|
|
1005
|
+
ALTER TABLE turns RENAME TO turns_v19;
|
|
1006
|
+
ALTER TABLE turn_events RENAME TO turn_events_v19;
|
|
1007
|
+
DROP INDEX IF EXISTS idx_turns_session;
|
|
1008
|
+
CREATE TABLE turns (
|
|
1009
|
+
id TEXT PRIMARY KEY,
|
|
1010
|
+
session_id TEXT REFERENCES sessions(id) ON DELETE CASCADE,
|
|
1011
|
+
assignment_id TEXT,
|
|
1012
|
+
kind TEXT NOT NULL DEFAULT 'chat',
|
|
1013
|
+
status TEXT NOT NULL DEFAULT 'running',
|
|
1014
|
+
started_at INTEGER NOT NULL,
|
|
1015
|
+
ended_at INTEGER
|
|
1016
|
+
);
|
|
1017
|
+
CREATE TABLE turn_events (
|
|
1018
|
+
turn_id TEXT NOT NULL REFERENCES turns(id) ON DELETE CASCADE,
|
|
1019
|
+
seq INTEGER NOT NULL,
|
|
1020
|
+
json TEXT NOT NULL,
|
|
1021
|
+
PRIMARY KEY (turn_id, seq)
|
|
1022
|
+
);
|
|
1023
|
+
INSERT INTO turns (id, session_id, assignment_id, kind, status, started_at, ended_at)
|
|
1024
|
+
SELECT id, session_id, NULL, kind, status, started_at, ended_at FROM turns_v19;
|
|
1025
|
+
INSERT INTO turn_events (turn_id, seq, json)
|
|
1026
|
+
SELECT turn_id, seq, json FROM turn_events_v19;
|
|
1027
|
+
DROP TABLE turn_events_v19;
|
|
1028
|
+
DROP TABLE turns_v19;
|
|
1029
|
+
CREATE INDEX idx_turns_session ON turns(session_id, started_at);
|
|
1030
|
+
CREATE INDEX idx_turns_assignment ON turns(assignment_id, started_at);
|
|
1031
|
+
`);
|
|
1032
|
+
db.exec('PRAGMA foreign_keys = ON');
|
|
1033
|
+
}
|
|
1034
|
+
// For fresh installs and rebuilt ones alike: the assignment key's index.
|
|
1035
|
+
db.exec('CREATE INDEX IF NOT EXISTS idx_turns_assignment ON turns(assignment_id, started_at);');
|
|
1036
|
+
// Whatever still claims to be running was orphaned by the process that
|
|
1037
|
+
// wrote it: this database is single-writer and just opened, so nobody is
|
|
1038
|
+
// producing those turns any more. Marked here rather than in the journal
|
|
1039
|
+
// because every open is the startup for exactly one writer. The events
|
|
1040
|
+
// stay: they are the only record of an answer that never finished.
|
|
1041
|
+
db.prepare("UPDATE turns SET status = 'interrupted', ended_at = ? WHERE status = 'running'").run(Date.now());
|
|
1042
|
+
// Schema 24 -> 25: a card says what set it going. `created_by` answers
|
|
1043
|
+
// "what kind of party made this" and cannot answer "a schedule fired" - a
|
|
1044
|
+
// schedule is not a party, it is an arrangement the user made, and adding
|
|
1045
|
+
// it to `RequesterKind` would invent a sender that mail can never have. So
|
|
1046
|
+
// the job's id sits on the card instead and `created_by` stays `user`: the
|
|
1047
|
+
// person set the schedule up, and the work is theirs. Nullable, and null
|
|
1048
|
+
// for every card made any other way (decision E1 of
|
|
1049
|
+
// docs/concepts/work-as-one-surface.md).
|
|
1050
|
+
if (!hasColumn(db, 'tasks', 'schedule_id')) {
|
|
1051
|
+
db.exec('ALTER TABLE tasks ADD COLUMN schedule_id TEXT');
|
|
1052
|
+
}
|
|
1053
|
+
// Schema 25 -> 26: the conversation a card was handed over from. A card
|
|
1054
|
+
// knew its parent task but not the chat that asked for it, so work handed
|
|
1055
|
+
// off in the background had nowhere to report back to, and the assistant's
|
|
1056
|
+
// "I will let you know" was a promise the code could not keep
|
|
1057
|
+
// (docs/concepts/delegation-report-back-and-chat-terminal.md, R1).
|
|
1058
|
+
if (!hasColumn(db, 'tasks', 'requester_session_id')) {
|
|
1059
|
+
db.exec('ALTER TABLE tasks ADD COLUMN requester_session_id TEXT');
|
|
1060
|
+
}
|
|
1061
|
+
// Schema 26 -> 27: internal mail is gone
|
|
1062
|
+
// (docs/concepts/mail-removal-notifications-and-task-activity.md). Mail was
|
|
1063
|
+
// three things at once - transport between agents, the protocol of a task,
|
|
1064
|
+
// and the channel to the user - and each gets its own home now. What
|
|
1065
|
+
// reaches the user is a notification; what happened on a card is its
|
|
1066
|
+
// activity. The mail tables stay where they are, unwritten, and their
|
|
1067
|
+
// content is copied over once below.
|
|
1068
|
+
//
|
|
1069
|
+
// No foreign keys on the references out of `notifications`: a notification
|
|
1070
|
+
// outlives the task, schedule or conversation it talks about, the same way
|
|
1071
|
+
// a mail did. `task_events` does cascade - a line of a card's protocol has
|
|
1072
|
+
// no meaning without the card.
|
|
1073
|
+
db.exec(`
|
|
1074
|
+
CREATE TABLE IF NOT EXISTS notifications (
|
|
1075
|
+
id TEXT PRIMARY KEY,
|
|
1076
|
+
org_id TEXT NOT NULL,
|
|
1077
|
+
kind TEXT NOT NULL,
|
|
1078
|
+
title TEXT NOT NULL,
|
|
1079
|
+
body TEXT NOT NULL DEFAULT '',
|
|
1080
|
+
from_kind TEXT NOT NULL DEFAULT 'system',
|
|
1081
|
+
from_agent_id TEXT,
|
|
1082
|
+
task_id TEXT,
|
|
1083
|
+
cron_job_id TEXT,
|
|
1084
|
+
cron_run_id TEXT,
|
|
1085
|
+
session_id TEXT,
|
|
1086
|
+
read_at INTEGER,
|
|
1087
|
+
archived_at INTEGER,
|
|
1088
|
+
created_at INTEGER NOT NULL
|
|
1089
|
+
);
|
|
1090
|
+
CREATE INDEX IF NOT EXISTS idx_notifications_live
|
|
1091
|
+
ON notifications(org_id, archived_at, read_at, created_at);
|
|
1092
|
+
CREATE INDEX IF NOT EXISTS idx_notifications_task
|
|
1093
|
+
ON notifications(task_id);
|
|
1094
|
+
CREATE TABLE IF NOT EXISTS task_events (
|
|
1095
|
+
id TEXT PRIMARY KEY,
|
|
1096
|
+
task_id TEXT NOT NULL REFERENCES tasks(id) ON DELETE CASCADE,
|
|
1097
|
+
at INTEGER NOT NULL,
|
|
1098
|
+
kind TEXT NOT NULL,
|
|
1099
|
+
actor_kind TEXT NOT NULL,
|
|
1100
|
+
actor_agent_id TEXT,
|
|
1101
|
+
text TEXT NOT NULL DEFAULT '',
|
|
1102
|
+
assignment_id TEXT
|
|
1103
|
+
);
|
|
1104
|
+
CREATE INDEX IF NOT EXISTS idx_task_events_task
|
|
1105
|
+
ON task_events(task_id, at);
|
|
1106
|
+
`);
|
|
1107
|
+
migrateMailToNotifications(db);
|
|
408
1108
|
db.prepare('INSERT OR REPLACE INTO meta(key, value) VALUES (?, ?)').run('schema_version', String(SCHEMA_VERSION));
|
|
409
1109
|
}
|
|
1110
|
+
/**
|
|
1111
|
+
* One thread row for every thread that already exists as mail, guarded by a
|
|
1112
|
+
* `meta` flag like the other one-time backfills. Threads whose mail ever
|
|
1113
|
+
* carried an `assignment_id` read as reports - the run answered inside them;
|
|
1114
|
+
* everything else is a chat. No historical thread was created as an
|
|
1115
|
+
* assignment (that concept arrives with this schema), so `task_id` starts
|
|
1116
|
+
* NULL everywhere.
|
|
1117
|
+
*/
|
|
1118
|
+
function backfillMailThreads(db) {
|
|
1119
|
+
const done = db.prepare("SELECT value FROM meta WHERE key = 'mail_threads_v1'").get();
|
|
1120
|
+
if (done)
|
|
1121
|
+
return;
|
|
1122
|
+
db.prepare(`INSERT OR IGNORE INTO mail_threads (thread_id, org_id, kind, task_id, archived_at, created_at)
|
|
1123
|
+
SELECT m.thread_id, m.org_id,
|
|
1124
|
+
CASE WHEN SUM(CASE WHEN m.assignment_id IS NOT NULL THEN 1 ELSE 0 END) > 0
|
|
1125
|
+
THEN 'report' ELSE 'chat' END,
|
|
1126
|
+
NULL, NULL, MIN(m.created_at)
|
|
1127
|
+
FROM mail m
|
|
1128
|
+
GROUP BY m.thread_id`).run();
|
|
1129
|
+
db.prepare("INSERT OR REPLACE INTO meta(key, value) VALUES ('mail_threads_v1', '1')").run();
|
|
1130
|
+
}
|
|
1131
|
+
/**
|
|
1132
|
+
* Files the mail transcripts that predate `kind = 'mail'` under it.
|
|
1133
|
+
*
|
|
1134
|
+
* Answering a mail addressed to the assistant has always needed a session to
|
|
1135
|
+
* run the turn in, and before the kind existed that session was written as a
|
|
1136
|
+
* plain chat - so every answered mail left a "Mail: <subject>" thread sitting
|
|
1137
|
+
* in the conversations list that nobody had opened and nobody could continue.
|
|
1138
|
+
*
|
|
1139
|
+
* The title prefix is the only marker those rows carry, so this matches on it,
|
|
1140
|
+
* narrowed to the shape `#answerMail` actually produces: no agent, still a
|
|
1141
|
+
* chat. Nothing is deleted - a row caught by mistake is one `?kind=mail` away,
|
|
1142
|
+
* and still opens by its own id.
|
|
1143
|
+
*/
|
|
1144
|
+
function backfillMailSessionKind(db) {
|
|
1145
|
+
const done = db.prepare("SELECT value FROM meta WHERE key = 'mail_session_kind_v1'").get();
|
|
1146
|
+
if (done)
|
|
1147
|
+
return;
|
|
1148
|
+
db.prepare("UPDATE sessions SET kind = 'mail' WHERE kind = 'chat' AND agent_id IS NULL AND title LIKE 'Mail: %'").run();
|
|
1149
|
+
db.prepare("INSERT OR REPLACE INTO meta(key, value) VALUES ('mail_session_kind_v1', '1')").run();
|
|
1150
|
+
}
|
|
1151
|
+
/**
|
|
1152
|
+
* Files the cron-run transcripts that predate `kind = 'schedule'` under it.
|
|
1153
|
+
*
|
|
1154
|
+
* Same story as `backfillMailSessionKind`: a scheduled run has always needed
|
|
1155
|
+
* a session to run its turn in, and before the kind existed every one of
|
|
1156
|
+
* those runs left a "Schedule: <job name>" thread sitting in the
|
|
1157
|
+
* conversations list - and because a job used to keep and reuse one session
|
|
1158
|
+
* across every firing, that single thread just kept growing. Nothing is
|
|
1159
|
+
* deleted or merged; each row just stops pretending to be a chat to come
|
|
1160
|
+
* back to.
|
|
1161
|
+
*/
|
|
1162
|
+
function backfillScheduleSessionKind(db) {
|
|
1163
|
+
const done = db.prepare("SELECT value FROM meta WHERE key = 'schedule_session_kind_v1'").get();
|
|
1164
|
+
if (done)
|
|
1165
|
+
return;
|
|
1166
|
+
db.prepare("UPDATE sessions SET kind = 'schedule' WHERE kind = 'chat' AND agent_id IS NULL AND title LIKE 'Schedule: %'").run();
|
|
1167
|
+
db.prepare("INSERT OR REPLACE INTO meta(key, value) VALUES ('schedule_session_kind_v1', '1')").run();
|
|
1168
|
+
}
|
|
1169
|
+
/**
|
|
1170
|
+
* One-time copy of every `agent_messages` row into `mail` + `mail_recipients`,
|
|
1171
|
+
* guarded by a `meta` flag so a restart never duplicates it. Reuses each
|
|
1172
|
+
* message's own id as its mail id (both are already unique, and it makes the
|
|
1173
|
+
* migration trivially idempotent to reason about even without the flag).
|
|
1174
|
+
*/
|
|
1175
|
+
function migrateAgentMessagesToMail(db) {
|
|
1176
|
+
const done = db.prepare("SELECT value FROM meta WHERE key = 'mail_migrated_v1'").get();
|
|
1177
|
+
if (done)
|
|
1178
|
+
return;
|
|
1179
|
+
const rows = db.prepare('SELECT * FROM agent_messages').all();
|
|
1180
|
+
const insertMail = db.prepare(`INSERT INTO mail (id, org_id, from_kind, from_agent_id, subject, body, thread_id, in_reply_to, depth, assignment_id, created_at)
|
|
1181
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, NULL, 0, ?, ?)`);
|
|
1182
|
+
const insertRecipient = db.prepare(`INSERT INTO mail_recipients (id, mail_id, recipient_kind, recipient_id, box, read_at)
|
|
1183
|
+
VALUES (?, ?, ?, ?, 'to', ?)`);
|
|
1184
|
+
for (const row of rows) {
|
|
1185
|
+
const id = row.id;
|
|
1186
|
+
const orgId = row.org_id;
|
|
1187
|
+
const fromAgentId = row.from_agent_id ?? null;
|
|
1188
|
+
const toAgentId = row.to_agent_id ?? null;
|
|
1189
|
+
const assignmentId = row.assignment_id ?? null;
|
|
1190
|
+
const createdAt = row.created_at;
|
|
1191
|
+
const readAt = row.read_at ?? null;
|
|
1192
|
+
const content = String(row.content ?? '');
|
|
1193
|
+
const subject = content.slice(0, 60).trim() || '(no subject)';
|
|
1194
|
+
const fromKind = fromAgentId ? 'agent' : 'assistant';
|
|
1195
|
+
const recipientKind = toAgentId ? 'agent' : 'user';
|
|
1196
|
+
insertMail.run(id, orgId, fromKind, fromAgentId, subject, content, id, assignmentId, createdAt);
|
|
1197
|
+
insertRecipient.run(randomUUID(), id, recipientKind, toAgentId, readAt);
|
|
1198
|
+
}
|
|
1199
|
+
db.prepare("INSERT OR REPLACE INTO meta(key, value) VALUES ('mail_migrated_v1', '1')").run();
|
|
1200
|
+
}
|
|
1201
|
+
/**
|
|
1202
|
+
* The one-time copy out of the retired mail tables (schema 27, section 6 of
|
|
1203
|
+
* docs/concepts/mail-removal-notifications-and-task-activity.md), guarded by
|
|
1204
|
+
* a `meta` flag like every other backfill. Nothing is deleted: the mail rows
|
|
1205
|
+
* stay exactly where they are, and both copies reuse the mail's own id, so
|
|
1206
|
+
* even without the flag a second pass could only ever skip.
|
|
1207
|
+
*
|
|
1208
|
+
* Two copies, because mail was two things:
|
|
1209
|
+
*
|
|
1210
|
+
* - Every mail the user was To or Cc on becomes a notification. Its kind
|
|
1211
|
+
* comes from what the thread was: a `report` thread is what a schedule
|
|
1212
|
+
* posted, an `assignment` thread is a card, anything else somebody writing.
|
|
1213
|
+
* One refinement the concept does not spell out: the night's promotion
|
|
1214
|
+
* notice was a mail from the user to themselves, and reads as `sleep`
|
|
1215
|
+
* rather than as an agent writing. It counts as read only when every one of
|
|
1216
|
+
* the user's copies was read; it is archived when its thread was.
|
|
1217
|
+
* - Every task with a linked thread gets that thread as its activity: the
|
|
1218
|
+
* first mail is the card's `created` line, the rest are `note`s, each by
|
|
1219
|
+
* whoever sent it.
|
|
1220
|
+
*/
|
|
1221
|
+
function migrateMailToNotifications(db) {
|
|
1222
|
+
const done = db.prepare("SELECT value FROM meta WHERE key = 'mail_to_notifications_v1'").get();
|
|
1223
|
+
if (done)
|
|
1224
|
+
return;
|
|
1225
|
+
const text = (value) => (typeof value === 'string' ? value : '');
|
|
1226
|
+
const optionalText = (value) => (typeof value === 'string' && value ? value : null);
|
|
1227
|
+
const optionalNumber = (value) => (typeof value === 'number' ? value : null);
|
|
1228
|
+
const insertNotification = db.prepare(`INSERT OR IGNORE INTO notifications
|
|
1229
|
+
(id, org_id, kind, title, body, from_kind, from_agent_id, task_id, cron_job_id, cron_run_id, session_id, read_at, archived_at, created_at)
|
|
1230
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, NULL, NULL, NULL, ?, ?, ?)`);
|
|
1231
|
+
const insertEvent = db.prepare(`INSERT OR IGNORE INTO task_events (id, task_id, at, kind, actor_kind, actor_agent_id, text, assignment_id)
|
|
1232
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`);
|
|
1233
|
+
db.exec('BEGIN');
|
|
1234
|
+
try {
|
|
1235
|
+
const toUser = db
|
|
1236
|
+
.prepare(`SELECT m.id, m.org_id, m.from_kind, m.from_agent_id, m.subject, m.body, m.created_at,
|
|
1237
|
+
mt.kind AS thread_kind, mt.task_id AS thread_task_id, mt.archived_at AS thread_archived_at,
|
|
1238
|
+
(SELECT COUNT(*) FROM mail_recipients r
|
|
1239
|
+
WHERE r.mail_id = m.id AND r.recipient_kind = 'user' AND r.read_at IS NULL) AS unread,
|
|
1240
|
+
(SELECT MAX(r.read_at) FROM mail_recipients r
|
|
1241
|
+
WHERE r.mail_id = m.id AND r.recipient_kind = 'user') AS read_at
|
|
1242
|
+
FROM mail m
|
|
1243
|
+
LEFT JOIN mail_threads mt ON mt.thread_id = m.thread_id
|
|
1244
|
+
WHERE EXISTS (SELECT 1 FROM mail_recipients r WHERE r.mail_id = m.id AND r.recipient_kind = 'user')`)
|
|
1245
|
+
.all();
|
|
1246
|
+
for (const row of toUser) {
|
|
1247
|
+
const fromKind = text(row.from_kind);
|
|
1248
|
+
const subject = text(row.subject);
|
|
1249
|
+
const kind = fromKind === 'user' && subject.startsWith('Retrieval policy ')
|
|
1250
|
+
? 'sleep'
|
|
1251
|
+
: row.thread_kind === 'report'
|
|
1252
|
+
? 'schedule'
|
|
1253
|
+
: row.thread_kind === 'assignment'
|
|
1254
|
+
? 'task'
|
|
1255
|
+
: 'agent';
|
|
1256
|
+
insertNotification.run(text(row.id), text(row.org_id), kind, subject || '(no subject)', text(row.body), fromKind === 'agent' ? 'agent' : fromKind === 'assistant' ? 'assistant' : 'system', fromKind === 'agent' ? optionalText(row.from_agent_id) : null, optionalText(row.thread_task_id), Number(row.unread ?? 0) > 0 ? null : optionalNumber(row.read_at), optionalNumber(row.thread_archived_at), optionalNumber(row.created_at) ?? Date.now());
|
|
1257
|
+
}
|
|
1258
|
+
// Only threads whose task still exists: the activity cascades with its
|
|
1259
|
+
// card, and a line for a card that is gone could not be inserted anyway.
|
|
1260
|
+
const threadMail = db
|
|
1261
|
+
.prepare(`SELECT m.id, m.from_kind, m.from_agent_id, m.body, m.created_at, m.assignment_id, mt.task_id
|
|
1262
|
+
FROM mail m
|
|
1263
|
+
JOIN mail_threads mt ON mt.thread_id = m.thread_id
|
|
1264
|
+
JOIN tasks t ON t.id = mt.task_id
|
|
1265
|
+
ORDER BY mt.task_id, m.created_at, m.rowid`)
|
|
1266
|
+
.all();
|
|
1267
|
+
let current = '';
|
|
1268
|
+
for (const row of threadMail) {
|
|
1269
|
+
const taskId = text(row.task_id);
|
|
1270
|
+
const first = taskId !== current;
|
|
1271
|
+
current = taskId;
|
|
1272
|
+
const fromKind = text(row.from_kind);
|
|
1273
|
+
insertEvent.run(text(row.id), taskId, optionalNumber(row.created_at) ?? Date.now(), first ? 'created' : 'note', fromKind === 'agent' || fromKind === 'assistant' || fromKind === 'user' ? fromKind : 'system', fromKind === 'agent' ? optionalText(row.from_agent_id) : null, text(row.body), optionalText(row.assignment_id));
|
|
1274
|
+
}
|
|
1275
|
+
db.prepare("INSERT OR REPLACE INTO meta(key, value) VALUES ('mail_to_notifications_v1', '1')").run();
|
|
1276
|
+
db.exec('COMMIT');
|
|
1277
|
+
}
|
|
1278
|
+
catch (error) {
|
|
1279
|
+
db.exec('ROLLBACK');
|
|
1280
|
+
throw error;
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
410
1283
|
/** Rebuild the FTS index. Used by the CLI after a bulk import. */
|
|
411
1284
|
export function reindex(db) {
|
|
412
1285
|
db.exec("INSERT INTO memories_fts(memories_fts) VALUES ('rebuild')");
|
|
1286
|
+
// A rebuild replaces the corpus that every recorded frame was scored
|
|
1287
|
+
// against, so the dream must treat all frames from before this moment as
|
|
1288
|
+
// invalidated instead of rediscovering the drift night after night.
|
|
1289
|
+
db.prepare("INSERT OR REPLACE INTO meta(key, value) VALUES ('dream.corpus_invalidated_at', ?)").run(String(Date.now()));
|
|
413
1290
|
}
|
|
414
1291
|
//# sourceMappingURL=db.js.map
|