Dashboard › opencode › Distillation
6b629450-267a-4eab-8899-f562ca167055["lore_tm_v1_Xa5FGWzZZ3VbZVfL6neaQ_rB6Tbw9h7mH1JhxWQaOFo","lore_tm_v1_Mil2pUeawed6NhH0I5HEqpx1NCZPissevU1uroZfIP0","lore_tm_v1_wZxXxkaeK-iuix7ebhOkKb-vvUxQzG2b7lLG-hKmZnA","lore_tm_v1_SHI6BfbvUEhBPhw7vSLIzWJ7VfW3pUN4qMUu__BoxRs"]
Date: Sep 14, 2026
/home/byk/Code/opencode/packages/core/script/migration.ts is a 196-line Bun migration generator/checker using packages/core/schema.json as the Drizzle snapshot, packages/core/src/database/migration for generated TypeScript migrations, packages/core/src/database/migration.gen.ts for the registry, and packages/core/src/database/schema.gen.ts for the full baseline schema./home/byk/Code/opencode/packages/core/script/migration.ts accepts --check as a boolean and --name as a string. --check runs check() and exits; otherwise it runs generate().generate() creates a temporary opencode-core-migration- directory with incremental and full outputs. For incremental generation it copies schema.json to incremental/baseline/snapshot.json, runs Drizzle with the optional --name, rejects more than one generated migration, writes a new migration to packages/core/src/database/migration/${name}.ts, rejects an already-existing target, and updates packages/core/schema.json from the generated snapshot.generate() creates a full migration named schema, regenerates /home/byk/Code/opencode/packages/core/src/database/schema.gen.ts from its SQL, and regenerates /home/byk/Code/opencode/packages/core/src/database/migration.gen.ts from sorted *.ts migration names. Its temporary directory is removed recursively with force: true in finally.check() creates a temporary opencode-core-migration-check- workspace and validates three generated artifacts: 1. no incremental migration remains, otherwise "Core schema has ungenerated database migrations. Run \bun script/migration.ts` from packages/core."; 2. schema.gen.tsexactly matches the formatted full-schema rendering, otherwise"Current database schema is stale. Run `bun script/migration.ts` from packages/core."; 3. migration.gen.tsexactly matches the formatted registry, otherwise"Database migration registry is stale. Run `bun script/migration.ts` from packages/core."`.drizzle() writes a temporary config importing packages/core/drizzle.config.ts, overrides out, and runs bun drizzle-kit generate --config ${config} with optional ["--name", name] from the packages/core working directory.generatedMigrations(directory) scans */migration.sql, extracts and sorts directory names; generatedSql(directory) requires exactly one full-schema migration and throws Expected one full schema migration, found ${generated.length}. otherwise; typescriptMigrations() scans *.ts under the migration directory, strips extensions, and sorts names.renderMigration(name, sql) emits an Effect-based default object with id: name and up(tx) satisfying DatabaseMigration.Migration; renderSchema(sql) emits the same shape without id, satisfying Omit<DatabaseMigration.Migration, "id">.renderStatements(sql) splits Drizzle SQL on "--> statement-breakpoint", trims and removes empty statements, then renders each as yield* tx.run(...). Multiline SQL is indented; tabs become two spaces; and escapeTemplate() escapes backslashes, backticks, and ${.formatTypescript(input) dynamically imports Prettierβs TypeScript and Estree plugins and formats with parser: "typescript", semi: false, and printWidth: 120. renderRegistry(names) generates concurrent dynamic imports via Promise.all([...]), maps each module to module.default, and constrains the result with satisfies DatabaseMigration.Migration[]./home/byk/Code/opencode/packages/schema/src/event.ts defines branded event IDs as strings beginning with evt_; Event.ID.create() produces "evt_" + ascending().Event.Definition includes type, a data codec, and optional durable metadata { version: number, aggregate: string }. Event.Payload includes required id, type, and data, plus optional durable payload metadata { aggregateID: string, seq: number, version: number }, optional Location.Ref, and optional Record<string, unknown> metadata.Event.define() builds an Effect Schema struct containing id, optional metadata, a literal type, optional runtime durable fields { aggregateID: Schema.String, seq: Schema.Int, version: Schema.Int }, optional location, and structured data; it annotates the schema with the event type identifier and exposes static type, data, and definition-level durable metadata when supplied.Event.inventory(...definitions) returns a frozen definitions array. Event.latest(definitions) indexes definitions by unversioned event type, selects the greater durable version when both definitions are durable and versions differ, and throws Duplicate latest event definition for ${definition.type} when distinct definitions remain ambiguous.Event.versionedType(type, version) returns ${type}.${version}. Event.durable(definitions) omits nondurable definitions, indexes durable ones by versioned type, and throws Duplicate durable event definition for ${key} for duplicate durable keys.readonlyMap() in /home/byk/Code/opencode/packages/schema/src/event.ts exposes a frozen ReadonlyMap facade implementing size, entries, forEach, get, has, keys, values, and [Symbol.iterator] over a private mutable Map./home/byk/Code/opencode/packages/schema/src/prompt.ts defines Prompt.Source with finite-number start and end offsets plus required text, annotated as "Prompt.Source".Prompt.FileAttachment has required uri and mime, with optional name, description, and source. FileAttachment.create(input) reconstructs the value through schema.make() while preserving all five fields.Prompt.AgentAttachment contains required name and optional source, annotated as "Prompt.AgentAttachment".Prompt.Prompt contains required text and optional arrays files: FileAttachment[] and agents: AgentAttachment[]. Its statics expose equivalence: Schema.toEquivalence(schema) and fromUserMessage(), which always includes text and conditionally includes files and agents only when they are not undefined.session.compact at POST /api/session/:sessionID/compact, v2.session.context for context retrieval, a boundary payload containing messageID: SessionMessage.ID and optional files: Schema.Boolean, and durable event streaming via HttpApiSchema.StreamSse({ data: SessionEvent.Durable }).