GeezerVison is showing github.com — sqlite again (#10597) · cbarber/opencode@6d95f0d
File treeExpand file treeCollapse file tree Open diff view settings app/src/context/global-sync 20260127222353_familiar_lady_ursula 20260211171708_add_project_commands 20260213144116_wakeful_the_professor
Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .opencode/command/commit.md -3Lines changed: 0 additions & 3 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| 16 | 16 |
| 17 | 17 | For anything in the packages/web use the docs: prefix. | 18 | 18 |
| 19 | | -For anything in the packages/app use the ignore: prefix. | 20 | | - | 21 | 19 | prefer to explain WHY something was done from an end user perspective instead of | 22 | 20 | WHAT was done. | 23 | 21 |
| 24 | 22 | do not do generic messages like "improved agent experience" be very specific | 25 | 23 | about what user facing changes were made | 26 | 24 |
| 27 | | -if there are changes do a git pull --rebase | 28 | 25 | if there are conflicts DO NOT FIX THEM. notify me and I will fix them | 29 | 26 |
| 30 | 27 | ## GIT DIFF | |
Collapse file Copy file name to clipboardExpand all lines: AGENTS.md +1Lines changed: 1 addition & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -110,3 +110,4 @@ const table = sqliteTable("session", { | 110 | 110 |
| 111 | 111 | - Avoid mocks as much as possible | 112 | 112 | - Test actual implementation, do not duplicate logic into tests | | 113 | +- Tests cannot run from repo root (guard: `do-not-run-tests-from-root`); run from package dirs like `packages/opencode`. |
Collapse file Copy file name to clipboardExpand all lines: bun.lock +308-243Lines changed: 308 additions & 243 deletions Collapse file Copy file name to clipboardExpand all lines: package.json +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 40 | 40 | "@tailwindcss/vite": "4.1.11", | 41 | 41 | "diff": "8.0.2", | 42 | 42 | "dompurify": "3.3.1", | | 43 | + "drizzle-kit": "1.0.0-beta.12-a5629fb", | | 44 | + "drizzle-orm": "1.0.0-beta.12-a5629fb", | 43 | 45 | "ai": "5.0.124", | 44 | 46 | "hono": "4.10.7", | 45 | 47 | "hono-openapi": "1.1.2", | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/context/global-sync/event-reducer.ts +18Lines changed: 18 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -231,6 +231,24 @@ export function applyDirectoryEvent(input: { | 231 | 231 | } | 232 | 232 | break | 233 | 233 | } | | 234 | + case "message.part.delta": { | | 235 | + const props = event.properties as { messageID: string; partID: string; field: string; delta: string } | | 236 | + const parts = input.store.part[props.messageID] | | 237 | + if (!parts) break | | 238 | + const result = Binary.search(parts, props.partID, (p) => p.id) | | 239 | + if (!result.found) break | | 240 | + input.setStore( | | 241 | + "part", | | 242 | + props.messageID, | | 243 | + produce((draft) => { | | 244 | + const part = draft[result.index] | | 245 | + const field = props.field as keyof typeof part | | 246 | + const existing = part[field] as string | undefined | | 247 | + ;(part[field] as string) = (existing ?? "") + props.delta | | 248 | + }), | | 249 | + ) | | 250 | + break | | 251 | + } | 234 | 252 | case "vcs.branch.updated": { | 235 | 253 | const props = event.properties as { branch: string } | 236 | 254 | if (input.store.vcs?.branch === props.branch) break | |
Collapse file Copy file name to clipboardExpand all lines: packages/console/core/package.json +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 12 | 12 | "@opencode-ai/console-resource": "workspace:*", | 13 | 13 | "@planetscale/database": "1.19.0", | 14 | 14 | "aws4fetch": "1.0.20", | 15 | | - "drizzle-orm": "0.41.0", | | 15 | + "drizzle-orm": "catalog:", | 16 | 16 | "postgres": "3.4.7", | 17 | 17 | "stripe": "18.0.0", | 18 | 18 | "ulid": "catalog:", | | 44 | 44 | "@tsconfig/node22": "22.0.2", | 45 | 45 | "@types/bun": "1.3.0", | 46 | 46 | "@types/node": "catalog:", | 47 | | - "drizzle-kit": "0.30.5", | | 47 | + "drizzle-kit": "catalog:", | 48 | 48 | "mysql2": "3.14.4", | 49 | 49 | "typescript": "catalog:", | 50 | 50 | "@typescript/native-preview": "catalog:" | |
Collapse file Copy file name to clipboardExpand all lines: packages/console/core/src/drizzle/index.ts +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,7 +4,6 @@ export * from "drizzle-orm" | 4 | 4 | import { Client } from "@planetscale/database" | 5 | 5 |
| 6 | 6 | import { MySqlTransaction, type MySqlTransactionConfig } from "drizzle-orm/mysql-core" | 7 | | -import type { ExtractTablesWithRelations } from "drizzle-orm" | 8 | 7 | import type { PlanetScalePreparedQueryHKT, PlanetscaleQueryResultHKT } from "drizzle-orm/planetscale-serverless" | 9 | 8 | import { Context } from "../context" | 10 | 9 | import { memo } from "../util/memo" | @@ -14,7 +13,7 @@ export namespace Database { | 14 | 13 | PlanetscaleQueryResultHKT, | 15 | 14 | PlanetScalePreparedQueryHKT, | 16 | 15 | Record<string, never>, | 17 | | - ExtractTablesWithRelations<Record<string, never>> | | 16 | + any | 18 | 17 | > | 19 | 18 |
| 20 | 19 | const client = memo(() => { | @@ -23,7 +22,7 @@ export namespace Database { | 23 | 22 | username: Resource.Database.username, | 24 | 23 | password: Resource.Database.password, | 25 | 24 | }) | 26 | | - const db = drizzle(result, {}) | | 25 | + const db = drizzle({ client: result }) | 27 | 26 | return db | 28 | 27 | }) | 29 | 28 |
| |
Collapse file Copy file name to clipboard +8-25Lines changed: 8 additions & 25 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -# opencode agent guidelines | | 1 | +# opencode database guide | 2 | 2 |
| 3 | | -## Build/Test Commands | | 3 | +## Database | 4 | 4 |
| 5 | | -- **Install**: `bun install` | 6 | | -- **Run**: `bun run --conditions=browser ./src/index.ts` | 7 | | -- **Typecheck**: `bun run typecheck` (npm run typecheck) | 8 | | -- **Test**: `bun test` (runs all tests) | 9 | | -- **Single test**: `bun test test/tool/tool.test.ts` (specific test file) | 10 | | - | 11 | | -## Code Style | 12 | | - | 13 | | -- **Runtime**: Bun with TypeScript ESM modules | 14 | | -- **Imports**: Use relative imports for local modules, named imports preferred | 15 | | -- **Types**: Zod schemas for validation, TypeScript interfaces for structure | 16 | | -- **Naming**: camelCase for variables/functions, PascalCase for classes/namespaces | 17 | | -- **Error handling**: Use Result patterns, avoid throwing exceptions in tools | 18 | | -- **File structure**: Namespace-based organization (e.g., `Tool.define()`, `Session.create()`) | 19 | | - | 20 | | -## Architecture | 21 | | - | 22 | | -- **Tools**: Implement `Tool.Info` interface with `execute()` method | 23 | | -- **Context**: Pass `sessionID` in tool context, use `App.provide()` for DI | 24 | | -- **Validation**: All inputs validated with Zod schemas | 25 | | -- **Logging**: Use `Log.create({ service: "name" })` pattern | 26 | | -- **Storage**: Use `Storage` namespace for persistence | 27 | | -- **API Client**: The TypeScript TUI (built with SolidJS + OpenTUI) communicates with the OpenCode server using `@opencode-ai/sdk`. When adding/modifying server endpoints in `packages/opencode/src/server/server.ts`, run `./script/generate.ts` to regenerate the SDK and related files. | | 5 | +- **Schema**: Drizzle schema lives in `src/**/*.sql.ts`. | | 6 | +- **Naming**: tables and columns use snake*case; join columns are `<entity>_id`; indexes are `<table>*<column>\_idx`. | | 7 | +- **Migrations**: generated by Drizzle Kit using `drizzle.config.ts` (schema: `./src/**/*.sql.ts`, output: `./migration`). | | 8 | +- **Command**: `bun run db generate --name <slug>`. | | 9 | +- **Output**: creates `migration/<timestamp>_<slug>/migration.sql` and `snapshot.json`. | | 10 | +- **Tests**: migration tests should read the per-folder layout (no `_journal.json`). |
Collapse file Copy file name to clipboard +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { defineConfig } from "drizzle-kit" | | 2 | + | | 3 | +export default defineConfig({ | | 4 | + dialect: "sqlite", | | 5 | + schema: "./src/**/*.sql.ts", | | 6 | + out: "./migration", | | 7 | + dbCredentials: { | | 8 | + url: "/home/thdxr/.local/share/opencode/opencode.db", | | 9 | + }, | | 10 | +}) |
Collapse file Copy file name to clipboard +90Lines changed: 90 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +CREATE TABLE `project` ( | | 2 | + `id` text PRIMARY KEY, | | 3 | + `worktree` text NOT NULL, | | 4 | + `vcs` text, | | 5 | + `name` text, | | 6 | + `icon_url` text, | | 7 | + `icon_color` text, | | 8 | + `time_created` integer NOT NULL, | | 9 | + `time_updated` integer NOT NULL, | | 10 | + `time_initialized` integer, | | 11 | + `sandboxes` text NOT NULL | | 12 | +); | | 13 | +--> statement-breakpoint | | 14 | +CREATE TABLE `message` ( | | 15 | + `id` text PRIMARY KEY, | | 16 | + `session_id` text NOT NULL, | | 17 | + `time_created` integer NOT NULL, | | 18 | + `time_updated` integer NOT NULL, | | 19 | + `data` text NOT NULL, | | 20 | + CONSTRAINT `fk_message_session_id_session_id_fk` FOREIGN KEY (`session_id`) REFERENCES `session`(`id`) ON DELETE CASCADE | | 21 | +); | | 22 | +--> statement-breakpoint | | 23 | +CREATE TABLE `part` ( | | 24 | + `id` text PRIMARY KEY, | | 25 | + `message_id` text NOT NULL, | | 26 | + `session_id` text NOT NULL, | | 27 | + `time_created` integer NOT NULL, | | 28 | + `time_updated` integer NOT NULL, | | 29 | + `data` text NOT NULL, | | 30 | + CONSTRAINT `fk_part_message_id_message_id_fk` FOREIGN KEY (`message_id`) REFERENCES `message`(`id`) ON DELETE CASCADE | | 31 | +); | | 32 | +--> statement-breakpoint | | 33 | +CREATE TABLE `permission` ( | | 34 | + `project_id` text PRIMARY KEY, | | 35 | + `time_created` integer NOT NULL, | | 36 | + `time_updated` integer NOT NULL, | | 37 | + `data` text NOT NULL, | | 38 | + CONSTRAINT `fk_permission_project_id_project_id_fk` FOREIGN KEY (`project_id`) REFERENCES `project`(`id`) ON DELETE CASCADE | | 39 | +); | | 40 | +--> statement-breakpoint | | 41 | +CREATE TABLE `session` ( | | 42 | + `id` text PRIMARY KEY, | | 43 | + `project_id` text NOT NULL, | | 44 | + `parent_id` text, | | 45 | + `slug` text NOT NULL, | | 46 | + `directory` text NOT NULL, | | 47 | + `title` text NOT NULL, | | 48 | + `version` text NOT NULL, | | 49 | + `share_url` text, | | 50 | + `summary_additions` integer, | | 51 | + `summary_deletions` integer, | | 52 | + `summary_files` integer, | | 53 | + `summary_diffs` text, | | 54 | + `revert` text, | | 55 | + `permission` text, | | 56 | + `time_created` integer NOT NULL, | | 57 | + `time_updated` integer NOT NULL, | | 58 | + `time_compacting` integer, | | 59 | + `time_archived` integer, | | 60 | + CONSTRAINT `fk_session_project_id_project_id_fk` FOREIGN KEY (`project_id`) REFERENCES `project`(`id`) ON DELETE CASCADE | | 61 | +); | | 62 | +--> statement-breakpoint | | 63 | +CREATE TABLE `todo` ( | | 64 | + `session_id` text NOT NULL, | | 65 | + `content` text NOT NULL, | | 66 | + `status` text NOT NULL, | | 67 | + `priority` text NOT NULL, | | 68 | + `position` integer NOT NULL, | | 69 | + `time_created` integer NOT NULL, | | 70 | + `time_updated` integer NOT NULL, | | 71 | + CONSTRAINT `todo_pk` PRIMARY KEY(`session_id`, `position`), | | 72 | + CONSTRAINT `fk_todo_session_id_session_id_fk` FOREIGN KEY (`session_id`) REFERENCES `session`(`id`) ON DELETE CASCADE | | 73 | +); | | 74 | +--> statement-breakpoint | | 75 | +CREATE TABLE `session_share` ( | | 76 | + `session_id` text PRIMARY KEY, | | 77 | + `id` text NOT NULL, | | 78 | + `secret` text NOT NULL, | | 79 | + `url` text NOT NULL, | | 80 | + `time_created` integer NOT NULL, | | 81 | + `time_updated` integer NOT NULL, | | 82 | + CONSTRAINT `fk_session_share_session_id_session_id_fk` FOREIGN KEY (`session_id`) REFERENCES `session`(`id`) ON DELETE CASCADE | | 83 | +); | | 84 | +--> statement-breakpoint | | 85 | +CREATE INDEX `message_session_idx` ON `message` (`session_id`);--> statement-breakpoint | | 86 | +CREATE INDEX `part_message_idx` ON `part` (`message_id`);--> statement-breakpoint | | 87 | +CREATE INDEX `part_session_idx` ON `part` (`session_id`);--> statement-breakpoint | | 88 | +CREATE INDEX `session_project_idx` ON `session` (`project_id`);--> statement-breakpoint | | 89 | +CREATE INDEX `session_parent_idx` ON `session` (`parent_id`);--> statement-breakpoint | | 90 | +CREATE INDEX `todo_session_idx` ON `todo` (`session_id`); |
|