agent-mockingbird 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. package/.agents/skills/btca-cli/SKILL.md +64 -0
  2. package/.agents/skills/btca-cli/agents/openai.yaml +3 -0
  3. package/.agents/skills/frontend-design/SKILL.md +42 -0
  4. package/.agents/skills/frontend-design/agents/openai.yaml +3 -0
  5. package/.env.example +36 -0
  6. package/.githooks/pre-commit +33 -0
  7. package/.github/workflows/ci.yml +309 -0
  8. package/.opencode/bun.lock +18 -0
  9. package/.opencode/package.json +5 -0
  10. package/.opencode/tools/agent_type_manager.ts +100 -0
  11. package/.opencode/tools/config_manager.ts +87 -0
  12. package/.opencode/tools/cron_manager.ts +145 -0
  13. package/.opencode/tools/memory_get.ts +43 -0
  14. package/.opencode/tools/memory_remember.ts +53 -0
  15. package/.opencode/tools/memory_search.ts +48 -0
  16. package/AGENTS.md +126 -0
  17. package/MEMORY.md +2 -0
  18. package/README.md +451 -0
  19. package/THIRD_PARTY_NOTICES.md +11 -0
  20. package/agent-mockingbird.config.example.json +135 -0
  21. package/apps/server/package.json +32 -0
  22. package/apps/server/src/backend/agents/bootstrapContext.ts +362 -0
  23. package/apps/server/src/backend/agents/openclawImport.test.ts +133 -0
  24. package/apps/server/src/backend/agents/openclawImport.ts +797 -0
  25. package/apps/server/src/backend/agents/opencodeConfig.ts +428 -0
  26. package/apps/server/src/backend/agents/service.ts +10 -0
  27. package/apps/server/src/backend/config/example-config.test.ts +20 -0
  28. package/apps/server/src/backend/config/orchestration.ts +243 -0
  29. package/apps/server/src/backend/config/policy.ts +158 -0
  30. package/apps/server/src/backend/config/schema.test.ts +15 -0
  31. package/apps/server/src/backend/config/schema.ts +391 -0
  32. package/apps/server/src/backend/config/semantic.test.ts +34 -0
  33. package/apps/server/src/backend/config/semantic.ts +149 -0
  34. package/apps/server/src/backend/config/service.test.ts +75 -0
  35. package/apps/server/src/backend/config/service.ts +207 -0
  36. package/apps/server/src/backend/config/smoke.ts +77 -0
  37. package/apps/server/src/backend/config/store.test.ts +123 -0
  38. package/apps/server/src/backend/config/store.ts +581 -0
  39. package/apps/server/src/backend/config/testFixtures.ts +5 -0
  40. package/apps/server/src/backend/config/types.ts +56 -0
  41. package/apps/server/src/backend/contracts/events.ts +320 -0
  42. package/apps/server/src/backend/contracts/runtime.ts +111 -0
  43. package/apps/server/src/backend/cron/executor.ts +435 -0
  44. package/apps/server/src/backend/cron/repository.ts +170 -0
  45. package/apps/server/src/backend/cron/service.ts +660 -0
  46. package/apps/server/src/backend/cron/storage.ts +92 -0
  47. package/apps/server/src/backend/cron/types.ts +138 -0
  48. package/apps/server/src/backend/cron/utils.ts +351 -0
  49. package/apps/server/src/backend/db/client.ts +20 -0
  50. package/apps/server/src/backend/db/migrate.ts +40 -0
  51. package/apps/server/src/backend/db/repository.ts +1762 -0
  52. package/apps/server/src/backend/db/schema.ts +113 -0
  53. package/apps/server/src/backend/db/usageDashboard.test.ts +102 -0
  54. package/apps/server/src/backend/db/wipe.ts +13 -0
  55. package/apps/server/src/backend/defaults.ts +32 -0
  56. package/apps/server/src/backend/env.ts +48 -0
  57. package/apps/server/src/backend/heartbeat/activeHours.ts +45 -0
  58. package/apps/server/src/backend/heartbeat/defaultJob.ts +88 -0
  59. package/apps/server/src/backend/heartbeat/heartbeat.test.ts +110 -0
  60. package/apps/server/src/backend/heartbeat/runtimeService.ts +190 -0
  61. package/apps/server/src/backend/heartbeat/service.ts +176 -0
  62. package/apps/server/src/backend/heartbeat/state.test.ts +63 -0
  63. package/apps/server/src/backend/heartbeat/state.ts +167 -0
  64. package/apps/server/src/backend/heartbeat/types.ts +54 -0
  65. package/apps/server/src/backend/http/boundedQueue.test.ts +49 -0
  66. package/apps/server/src/backend/http/boundedQueue.ts +92 -0
  67. package/apps/server/src/backend/http/parsers.ts +40 -0
  68. package/apps/server/src/backend/http/router.ts +61 -0
  69. package/apps/server/src/backend/http/routes/agentRoutes.ts +67 -0
  70. package/apps/server/src/backend/http/routes/backgroundRoutes.ts +203 -0
  71. package/apps/server/src/backend/http/routes/chatRoutes.ts +107 -0
  72. package/apps/server/src/backend/http/routes/configRoutes.ts +602 -0
  73. package/apps/server/src/backend/http/routes/cronRoutes.ts +221 -0
  74. package/apps/server/src/backend/http/routes/dashboardRoutes.ts +308 -0
  75. package/apps/server/src/backend/http/routes/eventRoutes.ts +7 -0
  76. package/apps/server/src/backend/http/routes/heartbeatRoutes.test.ts +41 -0
  77. package/apps/server/src/backend/http/routes/heartbeatRoutes.ts +28 -0
  78. package/apps/server/src/backend/http/routes/index.ts +101 -0
  79. package/apps/server/src/backend/http/routes/mcpRoutes.ts +213 -0
  80. package/apps/server/src/backend/http/routes/memoryRoutes.ts +154 -0
  81. package/apps/server/src/backend/http/routes/runRoutes.ts +310 -0
  82. package/apps/server/src/backend/http/routes/runtimeRoutes.ts +197 -0
  83. package/apps/server/src/backend/http/routes/skillRoutes.ts +112 -0
  84. package/apps/server/src/backend/http/routes/uiRoutes.test.ts +161 -0
  85. package/apps/server/src/backend/http/routes/uiRoutes.ts +177 -0
  86. package/apps/server/src/backend/http/routes/usageRoutes.test.ts +104 -0
  87. package/apps/server/src/backend/http/routes/usageRoutes.ts +767 -0
  88. package/apps/server/src/backend/http/schemas.ts +64 -0
  89. package/apps/server/src/backend/http/sse.ts +144 -0
  90. package/apps/server/src/backend/integration/backend-core.test.ts +2316 -0
  91. package/apps/server/src/backend/logging/logger.ts +64 -0
  92. package/apps/server/src/backend/mcp/service.ts +326 -0
  93. package/apps/server/src/backend/memory/cli.ts +170 -0
  94. package/apps/server/src/backend/memory/conceptExpansion.test.ts +28 -0
  95. package/apps/server/src/backend/memory/conceptExpansion.ts +80 -0
  96. package/apps/server/src/backend/memory/qmdPort.test.ts +54 -0
  97. package/apps/server/src/backend/memory/qmdPort.ts +61 -0
  98. package/apps/server/src/backend/memory/records.test.ts +66 -0
  99. package/apps/server/src/backend/memory/records.ts +229 -0
  100. package/apps/server/src/backend/memory/service.ts +2012 -0
  101. package/apps/server/src/backend/memory/sqliteVec.ts +58 -0
  102. package/apps/server/src/backend/memory/types.ts +104 -0
  103. package/apps/server/src/backend/opencode/agentMockingbirdPlugin.test.ts +396 -0
  104. package/apps/server/src/backend/opencode/client.ts +98 -0
  105. package/apps/server/src/backend/opencode/models.ts +41 -0
  106. package/apps/server/src/backend/opencode/systemPrompt.test.ts +146 -0
  107. package/apps/server/src/backend/opencode/systemPrompt.ts +284 -0
  108. package/apps/server/src/backend/paths.ts +57 -0
  109. package/apps/server/src/backend/prompts/service.ts +100 -0
  110. package/apps/server/src/backend/queue/queue.test.ts +189 -0
  111. package/apps/server/src/backend/queue/service.ts +177 -0
  112. package/apps/server/src/backend/queue/types.ts +39 -0
  113. package/apps/server/src/backend/run/service.ts +576 -0
  114. package/apps/server/src/backend/run/storage.ts +47 -0
  115. package/apps/server/src/backend/run/types.ts +44 -0
  116. package/apps/server/src/backend/runtime/errors.ts +61 -0
  117. package/apps/server/src/backend/runtime/index.ts +72 -0
  118. package/apps/server/src/backend/runtime/memoryPromptDedup.test.ts +153 -0
  119. package/apps/server/src/backend/runtime/memoryPromptDedup.ts +76 -0
  120. package/apps/server/src/backend/runtime/opencodeRuntime/backgroundMethods.ts +765 -0
  121. package/apps/server/src/backend/runtime/opencodeRuntime/coreMethods.ts +705 -0
  122. package/apps/server/src/backend/runtime/opencodeRuntime/eventMethods.ts +503 -0
  123. package/apps/server/src/backend/runtime/opencodeRuntime/memoryMethods.ts +462 -0
  124. package/apps/server/src/backend/runtime/opencodeRuntime/promptMethods.ts +1167 -0
  125. package/apps/server/src/backend/runtime/opencodeRuntime/shared.ts +254 -0
  126. package/apps/server/src/backend/runtime/opencodeRuntime.test.ts +2899 -0
  127. package/apps/server/src/backend/runtime/opencodeRuntime.ts +135 -0
  128. package/apps/server/src/backend/runtime/sessionScope.ts +45 -0
  129. package/apps/server/src/backend/skills/service.ts +442 -0
  130. package/apps/server/src/backend/workspace/resolve.ts +27 -0
  131. package/apps/server/src/cli/agent-mockingbird.mjs +2522 -0
  132. package/apps/server/src/cli/agent-mockingbird.test.ts +68 -0
  133. package/apps/server/src/cli/runtime-assets.mjs +269 -0
  134. package/apps/server/src/cli/runtime-assets.test.ts +52 -0
  135. package/apps/server/src/cli/runtime-layout.mjs +75 -0
  136. package/apps/server/src/cli/standaloneBuild.test.ts +19 -0
  137. package/apps/server/src/cli/standaloneBuild.ts +19 -0
  138. package/apps/server/src/cli/standaloneCronBinary.test.ts +187 -0
  139. package/apps/server/src/index.ts +178 -0
  140. package/apps/server/tsconfig.json +12 -0
  141. package/backlog.md +5 -0
  142. package/bin/agent-mockingbird +2522 -0
  143. package/bin/runtime-layout.mjs +75 -0
  144. package/build-bin.ts +34 -0
  145. package/build-cli.mjs +37 -0
  146. package/build.ts +40 -0
  147. package/bun-env.d.ts +11 -0
  148. package/bun.lock +888 -0
  149. package/bunfig.toml +2 -0
  150. package/components.json +21 -0
  151. package/config.json +130 -0
  152. package/deploy/RELEASE_INSTALL.md +112 -0
  153. package/deploy/docker-compose.yml +42 -0
  154. package/deploy/systemd/README.md +46 -0
  155. package/deploy/systemd/agent-mockingbird.service +28 -0
  156. package/deploy/systemd/opencode.service +25 -0
  157. package/docs/legacy-config-ui-reference.md +51 -0
  158. package/docs/memory-e2e-trace-2026-03-04.md +63 -0
  159. package/docs/memory-ops.md +96 -0
  160. package/docs/memory-runtime-contract.md +42 -0
  161. package/docs/memory-tuning-remote-2026-03-04.md +59 -0
  162. package/docs/opencode-rebase-workflow-plan.md +614 -0
  163. package/docs/opencode-startup-sync-plan.md +94 -0
  164. package/docs/vendor-opencode.md +41 -0
  165. package/drizzle/0000_famous_turbo.sql +49 -0
  166. package/drizzle/0001_cron_memory_aux.sql +160 -0
  167. package/drizzle/0002_runtime_session_bindings.sql +28 -0
  168. package/drizzle/0003_background_runs.sql +27 -0
  169. package/drizzle/0004_memory_open_write.sql +63 -0
  170. package/drizzle/0005_signal_channel.sql +47 -0
  171. package/drizzle/0006_usage_event_dimensions.sql +7 -0
  172. package/drizzle/meta/0000_snapshot.json +341 -0
  173. package/drizzle/meta/_journal.json +55 -0
  174. package/drizzle.config.ts +14 -0
  175. package/eslint.config.mjs +77 -0
  176. package/knip.json +18 -0
  177. package/memory/2026-03-04.md +4 -0
  178. package/opencode.lock.json +16 -0
  179. package/package.json +67 -0
  180. package/packages/agent-mockingbird-installer/README.md +31 -0
  181. package/packages/agent-mockingbird-installer/bin/agent-mockingbird-installer.mjs +44 -0
  182. package/packages/agent-mockingbird-installer/opencode.lock.json +16 -0
  183. package/packages/agent-mockingbird-installer/package.json +23 -0
  184. package/packages/contracts/package.json +19 -0
  185. package/packages/contracts/src/agentTypes.ts +122 -0
  186. package/packages/contracts/src/cron.ts +146 -0
  187. package/packages/contracts/src/dashboard.ts +378 -0
  188. package/packages/contracts/src/index.ts +3 -0
  189. package/packages/contracts/tsconfig.json +4 -0
  190. package/patches/opencode/0001-Wafflebot-OpenCode-baseline.patch +2341 -0
  191. package/patches/opencode/0002-Fix-OpenCode-web-entry-and-settings-icons.patch +104 -0
  192. package/patches/opencode/0003-fix-app-remove-duplicate-sidebar-mount.patch +32 -0
  193. package/patches/opencode/0004-Add-heartbeat-settings-and-usage-nav.patch +506 -0
  194. package/patches/opencode/0005-Use-chart-icon-for-usage-nav.patch +38 -0
  195. package/patches/opencode/0006-Modernize-cron-settings.patch +399 -0
  196. package/patches/opencode/0007-Rename-waffle-namespaces-to-mockingbird.patch +1110 -0
  197. package/patches/opencode/0008-Remove-cron-contract-section.patch +178 -0
  198. package/patches/opencode/0009-Rework-cron-tab-as-operations-console.patch +414 -0
  199. package/patches/opencode/0010-Refine-heartbeat-settings-controls.patch +208 -0
  200. package/runtime-assets/opencode-config/opencode.jsonc +25 -0
  201. package/runtime-assets/opencode-config/package.json +5 -0
  202. package/runtime-assets/opencode-config/plugins/agent-mockingbird.ts +715 -0
  203. package/runtime-assets/workspace/.agents/skills/config-auditor/SKILL.md +25 -0
  204. package/runtime-assets/workspace/.agents/skills/config-editor/SKILL.md +24 -0
  205. package/runtime-assets/workspace/.agents/skills/cron-manager/SKILL.md +57 -0
  206. package/runtime-assets/workspace/.agents/skills/memory-ops/SKILL.md +120 -0
  207. package/runtime-assets/workspace/.agents/skills/runtime-diagnose/SKILL.md +25 -0
  208. package/runtime-assets/workspace/AGENTS.md +56 -0
  209. package/runtime-assets/workspace/MEMORY.md +4 -0
  210. package/scripts/build-release-bundle.sh +66 -0
  211. package/scripts/check-ship.ts +383 -0
  212. package/scripts/dev-opencode.sh +17 -0
  213. package/scripts/dev-stack-opencode.sh +15 -0
  214. package/scripts/dev-stack.sh +61 -0
  215. package/scripts/install-systemd.sh +87 -0
  216. package/scripts/memory-e2e.sh +76 -0
  217. package/scripts/memory-trace-e2e.sh +141 -0
  218. package/scripts/migrate-opencode-env.ts +108 -0
  219. package/scripts/onboard/bootstrap.sh +32 -0
  220. package/scripts/opencode-swap.ts +78 -0
  221. package/scripts/opencode-sync.ts +715 -0
  222. package/scripts/runtime-assets-sync.mjs +83 -0
  223. package/scripts/setup-git-hooks.ts +39 -0
  224. package/tsconfig.json +45 -0
  225. package/tui.json +98 -0
  226. package/turbo.json +36 -0
  227. package/vendor/OPENCODE_VENDOR.md +13 -0
@@ -0,0 +1,94 @@
1
+ # OpenCode Startup Sync Plan
2
+
3
+ ## Problem
4
+
5
+ Hosted startup logs showed:
6
+
7
+ ```text
8
+ [opencode] Config sync failed: Unable to connect. Is the computer able to access the url?
9
+ ```
10
+
11
+ This happened during `agent-mockingbird` boot even though the app itself still started.
12
+
13
+ ## Diagnosis
14
+
15
+ The failure was a startup race between:
16
+
17
+ - `agent-mockingbird.service`
18
+ - `opencode.service`
19
+
20
+ `agent-mockingbird` constructed `OpencodeRuntime` during process boot, and the runtime constructor immediately kicked off OpenCode config sync. Under systemd, `After=opencode.service` only guarantees service ordering, not that OpenCode is already accepting HTTP connections on `127.0.0.1:4096`.
21
+
22
+ That meant startup could log a sync failure if Agent Mockingbird reached OpenCode before the sidecar had finished binding its port.
23
+
24
+ ## Fix
25
+
26
+ Remove eager OpenCode config sync from the `OpencodeRuntime` constructor.
27
+
28
+ Keep runtime config sync lazy so it still runs before real OpenCode operations, such as:
29
+
30
+ - health checks
31
+ - normal prompts
32
+ - background session creation
33
+ - background prompt dispatch
34
+
35
+ This preserves runtime behavior while avoiding noisy false failures during service startup.
36
+
37
+ ## Important Clarification
38
+
39
+ This change does **not** remove runtime config sync.
40
+
41
+ It only changes **when** sync happens:
42
+
43
+ - before: immediately during process construction
44
+ - after: on first actual runtime use
45
+
46
+ ## Code Change
47
+
48
+ Updated:
49
+
50
+ - `apps/server/src/backend/runtime/opencodeRuntime.ts`
51
+
52
+ Removed the constructor-triggered call that forced sync during startup.
53
+
54
+ ## Regression Coverage
55
+
56
+ Updated:
57
+
58
+ - `apps/server/src/backend/runtime/opencodeRuntime.test.ts`
59
+
60
+ Added coverage to assert that constructing the runtime does not hit OpenCode config immediately, while normal prompt flow still performs sync later.
61
+
62
+ ## Verification
63
+
64
+ Run:
65
+
66
+ ```sh
67
+ bun test apps/server/src/backend/runtime/opencodeRuntime.test.ts
68
+ ```
69
+
70
+ Expected result:
71
+
72
+ - tests pass
73
+ - runtime construction does not contact OpenCode
74
+ - prompt path still performs runtime config sync
75
+
76
+ ## Rollout
77
+
78
+ 1. Push the fix.
79
+ 2. Redeploy or update the hosted install.
80
+ 3. Restart the user services if needed.
81
+ 4. Check:
82
+
83
+ ```sh
84
+ journalctl --user -u agent-mockingbird
85
+ ```
86
+
87
+ Expected startup behavior:
88
+
89
+ - Agent Mockingbird starts cleanly
90
+ - no immediate OpenCode config sync connection error during boot
91
+
92
+ ## Follow-up
93
+
94
+ If we want stronger startup guarantees later, we can add an explicit retry/backoff around first OpenCode sync or a readiness probe for the sidecar, but that is not required for this fix.
@@ -0,0 +1,41 @@
1
+ # OpenCode Workflow
2
+
3
+ ## Layout
4
+
5
+ - `opencode.lock.json` is the source of truth for the shipped OpenCode tag, commit, package version, local paths, and patch branch name.
6
+ - `cleanroom/opencode` is a local-only pristine upstream clone managed by `bun run opencode:sync`.
7
+ - `vendor/opencode` is a generated git worktree on the Agent Mockingbird patch branch. It is editable, but it is not tracked by the main repo.
8
+ - `patches/opencode/*.patch` is the tracked serialized patch stack exported from the patch branch.
9
+
10
+ ## Commands
11
+
12
+ - `bun run opencode:sync --status`
13
+ - Show the locked version, cleanroom state, vendor worktree state, and whether the patch series matches the branch.
14
+ - `bun run opencode:sync --status --json`
15
+ - Machine-readable version of the same state.
16
+ - `bun run opencode:sync --rebuild-only`
17
+ - Recreate `vendor/opencode` from `opencode.lock.json` plus the tracked patches.
18
+ - `bun run opencode:sync --export-patches`
19
+ - Export committed OpenCode changes from the patch branch back into `patches/opencode`.
20
+ - `bun run opencode:sync --ref vX.Y.Z`
21
+ - Fetch a new upstream release tag, apply the tracked patch series, validate it, and update the lock only after success.
22
+ - `bun run opencode:sync --check`
23
+ - CI-safe validation that reproduces the generated tree from the lock and patches in temporary state.
24
+ - `bun run check:ship`
25
+ - Canonical ship gate. Bootstraps the generated vendor worktree if needed, requires a clean/exported patch state, runs `opencode:sync --check`, and compares full cleanroom vs vendor OpenCode typecheck results so upstream-only baseline failures do not fail the ship check.
26
+
27
+ ## Edit Loop
28
+
29
+ 1. Run `bun run opencode:sync --rebuild-only`.
30
+ 2. Edit files in `vendor/opencode`.
31
+ 3. Commit those changes inside the `vendor/opencode` worktree on branch `agent-mockingbird/opencode`.
32
+ 4. Run `bun run opencode:sync --export-patches`.
33
+ 5. Run `bun run check:ship`.
34
+
35
+ ## Rules
36
+
37
+ - Never edit `cleanroom/opencode` directly.
38
+ - Never hand-maintain a copied `vendor/opencode` tree.
39
+ - If `vendor/opencode` is dirty, do not run `--ref` or `--export-patches`.
40
+ - `bun run check:ship` only validates clean, exported vendor state. Dirty `vendor/opencode` is a hard failure.
41
+ - Treat `patches/opencode` as exported artifacts of the patch branch, not as the primary editing surface.
@@ -0,0 +1,49 @@
1
+ CREATE TABLE `heartbeat_events` (
2
+ `id` text PRIMARY KEY NOT NULL,
3
+ `online` integer DEFAULT true NOT NULL,
4
+ `source` text DEFAULT 'system' NOT NULL,
5
+ `created_at` integer DEFAULT (strftime('%s', 'now') * 1000) NOT NULL
6
+ );
7
+ --> statement-breakpoint
8
+ CREATE INDEX `heartbeat_events_created_idx` ON `heartbeat_events` (`created_at`);--> statement-breakpoint
9
+ CREATE TABLE `messages` (
10
+ `id` text PRIMARY KEY NOT NULL,
11
+ `session_id` text NOT NULL,
12
+ `role` text NOT NULL,
13
+ `content` text NOT NULL,
14
+ `created_at` integer DEFAULT (strftime('%s', 'now') * 1000) NOT NULL,
15
+ FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade
16
+ );
17
+ --> statement-breakpoint
18
+ CREATE INDEX `messages_session_created_idx` ON `messages` (`session_id`,`created_at`);--> statement-breakpoint
19
+ CREATE TABLE `runtime_config` (
20
+ `key` text PRIMARY KEY NOT NULL,
21
+ `value_json` text NOT NULL,
22
+ `updated_at` integer DEFAULT (strftime('%s', 'now') * 1000) NOT NULL
23
+ );
24
+ --> statement-breakpoint
25
+ CREATE TABLE `sessions` (
26
+ `id` text PRIMARY KEY NOT NULL,
27
+ `title` text NOT NULL,
28
+ `model` text NOT NULL,
29
+ `status` text DEFAULT 'idle' NOT NULL,
30
+ `message_count` integer DEFAULT 0 NOT NULL,
31
+ `created_at` integer DEFAULT (strftime('%s', 'now') * 1000) NOT NULL,
32
+ `updated_at` integer DEFAULT (strftime('%s', 'now') * 1000) NOT NULL,
33
+ `last_active_at` integer DEFAULT (strftime('%s', 'now') * 1000) NOT NULL
34
+ );
35
+ --> statement-breakpoint
36
+ CREATE INDEX `sessions_last_active_idx` ON `sessions` (`last_active_at`);--> statement-breakpoint
37
+ CREATE TABLE `usage_events` (
38
+ `id` text PRIMARY KEY NOT NULL,
39
+ `session_id` text,
40
+ `request_count_delta` integer DEFAULT 0 NOT NULL,
41
+ `input_tokens_delta` integer DEFAULT 0 NOT NULL,
42
+ `output_tokens_delta` integer DEFAULT 0 NOT NULL,
43
+ `estimated_cost_usd_delta_micros` integer DEFAULT 0 NOT NULL,
44
+ `source` text DEFAULT 'system' NOT NULL,
45
+ `created_at` integer DEFAULT (strftime('%s', 'now') * 1000) NOT NULL,
46
+ FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE set null
47
+ );
48
+ --> statement-breakpoint
49
+ CREATE INDEX `usage_events_created_idx` ON `usage_events` (`created_at`);
@@ -0,0 +1,160 @@
1
+ CREATE TABLE IF NOT EXISTS `message_memory_traces` (
2
+ `message_id` text PRIMARY KEY NOT NULL,
3
+ `session_id` text NOT NULL,
4
+ `trace_json` text NOT NULL,
5
+ `created_at` integer NOT NULL
6
+ );
7
+ --> statement-breakpoint
8
+ CREATE INDEX IF NOT EXISTS `message_memory_traces_session_idx`
9
+ ON `message_memory_traces` (`session_id`, `created_at` DESC);
10
+ --> statement-breakpoint
11
+ CREATE TABLE IF NOT EXISTS `cron_job_definitions` (
12
+ `id` text PRIMARY KEY NOT NULL,
13
+ `name` text NOT NULL,
14
+ `enabled` integer NOT NULL DEFAULT 1,
15
+ `schedule_kind` text NOT NULL CHECK (`schedule_kind` IN ('at', 'every', 'cron')),
16
+ `schedule_expr` text,
17
+ `every_ms` integer,
18
+ `at_iso` text,
19
+ `timezone` text,
20
+ `run_mode` text NOT NULL CHECK (`run_mode` IN ('background', 'conditional_agent', 'agent')),
21
+ `handler_key` text,
22
+ `agent_prompt_template` text,
23
+ `agent_model_override` text,
24
+ `max_attempts` integer NOT NULL DEFAULT 3,
25
+ `retry_backoff_ms` integer NOT NULL DEFAULT 30000,
26
+ `payload_json` text NOT NULL DEFAULT '{}',
27
+ `last_enqueued_for` integer,
28
+ `created_at` integer NOT NULL,
29
+ `updated_at` integer NOT NULL
30
+ );
31
+ --> statement-breakpoint
32
+ CREATE INDEX IF NOT EXISTS `cron_job_definitions_enabled_idx`
33
+ ON `cron_job_definitions` (`enabled`, `schedule_kind`);
34
+ --> statement-breakpoint
35
+ CREATE TABLE IF NOT EXISTS `cron_job_instances` (
36
+ `id` text PRIMARY KEY NOT NULL,
37
+ `job_definition_id` text NOT NULL REFERENCES `cron_job_definitions`(`id`) ON DELETE CASCADE,
38
+ `scheduled_for` integer NOT NULL,
39
+ `state` text NOT NULL CHECK (`state` IN ('queued', 'leased', 'running', 'completed', 'failed', 'dead')),
40
+ `attempt` integer NOT NULL DEFAULT 0,
41
+ `next_attempt_at` integer,
42
+ `lease_owner` text,
43
+ `lease_expires_at` integer,
44
+ `last_heartbeat_at` integer,
45
+ `result_summary` text,
46
+ `error_json` text,
47
+ `created_at` integer NOT NULL,
48
+ `updated_at` integer NOT NULL,
49
+ UNIQUE(`job_definition_id`, `scheduled_for`)
50
+ );
51
+ --> statement-breakpoint
52
+ CREATE INDEX IF NOT EXISTS `cron_job_instances_ready_idx`
53
+ ON `cron_job_instances` (`state`, `next_attempt_at`, `scheduled_for`);
54
+ --> statement-breakpoint
55
+ CREATE INDEX IF NOT EXISTS `cron_job_instances_job_idx`
56
+ ON `cron_job_instances` (`job_definition_id`, `created_at` DESC);
57
+ --> statement-breakpoint
58
+ CREATE TABLE IF NOT EXISTS `cron_job_steps` (
59
+ `id` text PRIMARY KEY NOT NULL,
60
+ `job_instance_id` text NOT NULL REFERENCES `cron_job_instances`(`id`) ON DELETE CASCADE,
61
+ `step_kind` text NOT NULL CHECK (`step_kind` IN ('background', 'conditional_agent', 'agent')),
62
+ `status` text NOT NULL CHECK (`status` IN ('pending', 'running', 'completed', 'failed', 'skipped')),
63
+ `input_json` text,
64
+ `output_json` text,
65
+ `error_json` text,
66
+ `started_at` integer,
67
+ `finished_at` integer,
68
+ `created_at` integer NOT NULL
69
+ );
70
+ --> statement-breakpoint
71
+ CREATE INDEX IF NOT EXISTS `cron_job_steps_instance_idx`
72
+ ON `cron_job_steps` (`job_instance_id`, `created_at` ASC);
73
+ --> statement-breakpoint
74
+ CREATE TABLE IF NOT EXISTS `memory_meta` (
75
+ `key` text PRIMARY KEY NOT NULL,
76
+ `value_json` text NOT NULL
77
+ );
78
+ --> statement-breakpoint
79
+ CREATE TABLE IF NOT EXISTS `memory_files` (
80
+ `path` text PRIMARY KEY NOT NULL,
81
+ `source` text NOT NULL DEFAULT 'memory',
82
+ `hash` text NOT NULL,
83
+ `mtime` integer NOT NULL,
84
+ `size` integer NOT NULL,
85
+ `indexed_at` integer NOT NULL
86
+ );
87
+ --> statement-breakpoint
88
+ CREATE TABLE IF NOT EXISTS `memory_chunks` (
89
+ `id` text PRIMARY KEY NOT NULL,
90
+ `path` text NOT NULL,
91
+ `source` text NOT NULL DEFAULT 'memory',
92
+ `start_line` integer NOT NULL,
93
+ `end_line` integer NOT NULL,
94
+ `hash` text NOT NULL,
95
+ `text` text NOT NULL,
96
+ `embedding_json` text,
97
+ `updated_at` integer NOT NULL
98
+ );
99
+ --> statement-breakpoint
100
+ CREATE INDEX IF NOT EXISTS `memory_chunks_path_idx` ON `memory_chunks` (`path`);
101
+ --> statement-breakpoint
102
+ CREATE INDEX IF NOT EXISTS `memory_chunks_updated_idx` ON `memory_chunks` (`updated_at`);
103
+ --> statement-breakpoint
104
+ CREATE TABLE IF NOT EXISTS `memory_embedding_cache` (
105
+ `provider` text NOT NULL,
106
+ `model` text NOT NULL,
107
+ `hash` text NOT NULL,
108
+ `embedding_json` text NOT NULL,
109
+ `dims` integer NOT NULL,
110
+ `updated_at` integer NOT NULL,
111
+ PRIMARY KEY(`provider`, `model`, `hash`)
112
+ );
113
+ --> statement-breakpoint
114
+ CREATE INDEX IF NOT EXISTS `memory_embedding_cache_updated_idx`
115
+ ON `memory_embedding_cache` (`updated_at`);
116
+ --> statement-breakpoint
117
+ CREATE TABLE IF NOT EXISTS `memory_records` (
118
+ `id` text PRIMARY KEY NOT NULL,
119
+ `path` text NOT NULL,
120
+ `type` text NOT NULL,
121
+ `source` text NOT NULL,
122
+ `content` text NOT NULL,
123
+ `entities_json` text NOT NULL,
124
+ `confidence` real NOT NULL,
125
+ `supersedes_json` text NOT NULL,
126
+ `superseded_by` text,
127
+ `recorded_at` integer NOT NULL,
128
+ `updated_at` integer NOT NULL
129
+ );
130
+ --> statement-breakpoint
131
+ CREATE INDEX IF NOT EXISTS `memory_records_path_idx` ON `memory_records` (`path`);
132
+ --> statement-breakpoint
133
+ CREATE INDEX IF NOT EXISTS `memory_records_superseded_idx` ON `memory_records` (`superseded_by`);
134
+ --> statement-breakpoint
135
+ CREATE TABLE IF NOT EXISTS `memory_write_events` (
136
+ `id` text PRIMARY KEY NOT NULL,
137
+ `status` text NOT NULL,
138
+ `reason` text NOT NULL,
139
+ `type` text NOT NULL,
140
+ `source` text NOT NULL,
141
+ `content` text NOT NULL,
142
+ `confidence` real NOT NULL,
143
+ `session_id` text,
144
+ `topic` text,
145
+ `record_id` text,
146
+ `path` text,
147
+ `created_at` integer NOT NULL
148
+ );
149
+ --> statement-breakpoint
150
+ CREATE INDEX IF NOT EXISTS `memory_write_events_created_idx`
151
+ ON `memory_write_events` (`created_at` DESC);
152
+ --> statement-breakpoint
153
+ CREATE VIRTUAL TABLE IF NOT EXISTS `memory_chunks_fts` USING fts5(
154
+ `text`,
155
+ `chunk_id` UNINDEXED,
156
+ `path` UNINDEXED,
157
+ `start_line` UNINDEXED,
158
+ `end_line` UNINDEXED,
159
+ `updated_at` UNINDEXED
160
+ );
@@ -0,0 +1,28 @@
1
+ CREATE TABLE IF NOT EXISTS `runtime_session_bindings` (
2
+ `runtime` text NOT NULL,
3
+ `session_id` text NOT NULL,
4
+ `external_session_id` text NOT NULL,
5
+ `updated_at` integer NOT NULL,
6
+ PRIMARY KEY(`runtime`, `session_id`)
7
+ );
8
+ --> statement-breakpoint
9
+ CREATE INDEX IF NOT EXISTS `runtime_session_bindings_external_idx`
10
+ ON `runtime_session_bindings` (`runtime`, `external_session_id`);
11
+ --> statement-breakpoint
12
+ CREATE INDEX IF NOT EXISTS `runtime_session_bindings_updated_idx`
13
+ ON `runtime_session_bindings` (`updated_at`);
14
+ --> statement-breakpoint
15
+ INSERT INTO `runtime_session_bindings` (`runtime`, `session_id`, `external_session_id`, `updated_at`)
16
+ SELECT
17
+ substr(j.key, 1, instr(j.key, ':') - 1) AS runtime,
18
+ substr(j.key, instr(j.key, ':') + 1) AS session_id,
19
+ CAST(j.value AS TEXT) AS external_session_id,
20
+ CAST(strftime('%s', 'now') * 1000 AS INTEGER) AS updated_at
21
+ FROM `runtime_config` rc
22
+ JOIN json_each(rc.value_json) j
23
+ WHERE rc.`key` = 'sessionBindings'
24
+ AND instr(j.key, ':') > 0
25
+ AND trim(CAST(j.value AS TEXT)) <> ''
26
+ ON CONFLICT(`runtime`, `session_id`) DO UPDATE SET
27
+ `external_session_id` = excluded.`external_session_id`,
28
+ `updated_at` = excluded.`updated_at`;
@@ -0,0 +1,27 @@
1
+ CREATE TABLE IF NOT EXISTS `background_runs` (
2
+ `id` text PRIMARY KEY NOT NULL,
3
+ `runtime` text NOT NULL,
4
+ `parent_session_id` text NOT NULL,
5
+ `parent_external_session_id` text NOT NULL,
6
+ `child_external_session_id` text NOT NULL,
7
+ `requested_by` text NOT NULL DEFAULT 'system',
8
+ `prompt` text NOT NULL DEFAULT '',
9
+ `status` text NOT NULL DEFAULT 'created',
10
+ `result_summary` text,
11
+ `error` text,
12
+ `created_at` integer NOT NULL,
13
+ `updated_at` integer NOT NULL,
14
+ `started_at` integer,
15
+ `completed_at` integer,
16
+ FOREIGN KEY (`parent_session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade,
17
+ CHECK (`status` IN ('created', 'running', 'retrying', 'idle', 'completed', 'failed', 'aborted'))
18
+ );
19
+ --> statement-breakpoint
20
+ CREATE UNIQUE INDEX IF NOT EXISTS `background_runs_child_external_idx`
21
+ ON `background_runs` (`runtime`, `child_external_session_id`);
22
+ --> statement-breakpoint
23
+ CREATE INDEX IF NOT EXISTS `background_runs_parent_created_idx`
24
+ ON `background_runs` (`parent_session_id`, `created_at` DESC);
25
+ --> statement-breakpoint
26
+ CREATE INDEX IF NOT EXISTS `background_runs_status_updated_idx`
27
+ ON `background_runs` (`status`, `updated_at` DESC);
@@ -0,0 +1,63 @@
1
+ PRAGMA foreign_keys=OFF;
2
+ --> statement-breakpoint
3
+ DROP TABLE IF EXISTS `memory_records_new`;
4
+ --> statement-breakpoint
5
+ CREATE TABLE `memory_records_new` (
6
+ `id` text PRIMARY KEY NOT NULL,
7
+ `path` text NOT NULL,
8
+ `source` text NOT NULL,
9
+ `content` text NOT NULL,
10
+ `entities_json` text NOT NULL,
11
+ `confidence` real NOT NULL,
12
+ `supersedes_json` text NOT NULL,
13
+ `superseded_by` text,
14
+ `recorded_at` integer NOT NULL,
15
+ `updated_at` integer NOT NULL
16
+ );
17
+ --> statement-breakpoint
18
+ INSERT INTO `memory_records_new` (
19
+ `id`, `path`, `source`, `content`, `entities_json`, `confidence`, `supersedes_json`, `superseded_by`, `recorded_at`, `updated_at`
20
+ )
21
+ SELECT
22
+ `id`, `path`, `source`, `content`, `entities_json`, `confidence`, `supersedes_json`, `superseded_by`, `recorded_at`, `updated_at`
23
+ FROM `memory_records`;
24
+ --> statement-breakpoint
25
+ DROP TABLE `memory_records`;
26
+ --> statement-breakpoint
27
+ ALTER TABLE `memory_records_new` RENAME TO `memory_records`;
28
+ --> statement-breakpoint
29
+ CREATE INDEX IF NOT EXISTS `memory_records_path_idx` ON `memory_records` (`path`);
30
+ --> statement-breakpoint
31
+ CREATE INDEX IF NOT EXISTS `memory_records_superseded_idx` ON `memory_records` (`superseded_by`);
32
+ --> statement-breakpoint
33
+ DROP TABLE IF EXISTS `memory_write_events_new`;
34
+ --> statement-breakpoint
35
+ CREATE TABLE `memory_write_events_new` (
36
+ `id` text PRIMARY KEY NOT NULL,
37
+ `status` text NOT NULL,
38
+ `reason` text NOT NULL,
39
+ `source` text NOT NULL,
40
+ `content` text NOT NULL,
41
+ `confidence` real NOT NULL,
42
+ `session_id` text,
43
+ `topic` text,
44
+ `record_id` text,
45
+ `path` text,
46
+ `created_at` integer NOT NULL
47
+ );
48
+ --> statement-breakpoint
49
+ INSERT INTO `memory_write_events_new` (
50
+ `id`, `status`, `reason`, `source`, `content`, `confidence`, `session_id`, `topic`, `record_id`, `path`, `created_at`
51
+ )
52
+ SELECT
53
+ `id`, `status`, `reason`, `source`, `content`, `confidence`, `session_id`, `topic`, `record_id`, `path`, `created_at`
54
+ FROM `memory_write_events`;
55
+ --> statement-breakpoint
56
+ DROP TABLE `memory_write_events`;
57
+ --> statement-breakpoint
58
+ ALTER TABLE `memory_write_events_new` RENAME TO `memory_write_events`;
59
+ --> statement-breakpoint
60
+ CREATE INDEX IF NOT EXISTS `memory_write_events_created_idx`
61
+ ON `memory_write_events` (`created_at` DESC);
62
+ --> statement-breakpoint
63
+ PRAGMA foreign_keys=ON;
@@ -0,0 +1,47 @@
1
+ CREATE TABLE `channel_conversation_bindings` (
2
+ `channel` text NOT NULL,
3
+ `conversation_key` text NOT NULL,
4
+ `session_id` text NOT NULL,
5
+ `last_target` text,
6
+ `updated_at` integer NOT NULL,
7
+ PRIMARY KEY(`channel`, `conversation_key`),
8
+ FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade
9
+ );
10
+ --> statement-breakpoint
11
+ CREATE INDEX `channel_conversation_bindings_session_idx` ON `channel_conversation_bindings` (`session_id`);
12
+ --> statement-breakpoint
13
+ CREATE INDEX `channel_conversation_bindings_updated_idx` ON `channel_conversation_bindings` (`updated_at`);
14
+ --> statement-breakpoint
15
+ CREATE TABLE `channel_pairing_requests` (
16
+ `channel` text NOT NULL,
17
+ `sender_id` text NOT NULL,
18
+ `code` text NOT NULL,
19
+ `created_at` integer NOT NULL,
20
+ `last_seen_at` integer NOT NULL,
21
+ `expires_at` integer NOT NULL,
22
+ `meta_json` text NOT NULL DEFAULT '{}',
23
+ PRIMARY KEY(`channel`, `sender_id`)
24
+ );
25
+ --> statement-breakpoint
26
+ CREATE INDEX `channel_pairing_requests_code_idx` ON `channel_pairing_requests` (`channel`, `code`);
27
+ --> statement-breakpoint
28
+ CREATE INDEX `channel_pairing_requests_expires_idx` ON `channel_pairing_requests` (`expires_at`);
29
+ --> statement-breakpoint
30
+ CREATE TABLE `channel_allowlist_entries` (
31
+ `channel` text NOT NULL,
32
+ `sender_id` text NOT NULL,
33
+ `source` text NOT NULL DEFAULT 'pairing',
34
+ `created_at` integer NOT NULL,
35
+ PRIMARY KEY(`channel`, `sender_id`)
36
+ );
37
+ --> statement-breakpoint
38
+ CREATE INDEX `channel_allowlist_entries_channel_idx` ON `channel_allowlist_entries` (`channel`, `created_at`);
39
+ --> statement-breakpoint
40
+ CREATE TABLE `channel_inbound_dedupe` (
41
+ `channel` text NOT NULL,
42
+ `event_id` text NOT NULL,
43
+ `seen_at` integer NOT NULL,
44
+ PRIMARY KEY(`channel`, `event_id`)
45
+ );
46
+ --> statement-breakpoint
47
+ CREATE INDEX `channel_inbound_dedupe_seen_idx` ON `channel_inbound_dedupe` (`seen_at`);
@@ -0,0 +1,7 @@
1
+ ALTER TABLE `usage_events` ADD `provider_id` text;
2
+ --> statement-breakpoint
3
+ ALTER TABLE `usage_events` ADD `model_id` text;
4
+ --> statement-breakpoint
5
+ CREATE INDEX `usage_events_provider_created_idx` ON `usage_events` (`provider_id`, `created_at`);
6
+ --> statement-breakpoint
7
+ CREATE INDEX `usage_events_provider_model_created_idx` ON `usage_events` (`provider_id`, `model_id`, `created_at`);