AGENTS.md
packages/opencode/AGENTS.mdAGENTS.md
Quality
81/100
Scores the file, not the repository.Length
873 words
15 headings · 4 code blocksRepository
193k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1# opencode database guide23## Database45- **Schema**: Drizzle schema lives in `packages/core/src/**/*.sql.ts`.6- **Migrations**: database migrations live in `packages/core` and are applied by core.78## Development server910- Running `bun dev` from `packages/opencode` starts the live interactive TUI. Do not run it as a blocking foreground command when you need to inspect the result.11- Start it in `tmux` instead: `tmux new-session -d -s opencode-dev 'bun dev'`.12- Capture the current TUI output with: `tmux capture-pane -pt opencode-dev`.13- Stop the session explicitly when done: `tmux kill-session -t opencode-dev`.1415# Module shape1617Do not use `export namespace Foo { ... }` for module organization. It is not18standard ESM, it prevents tree-shaking, and it breaks Node's native TypeScript19runner. Use flat top-level exports combined with a self-reexport at the bottom20of the file:2122```ts23// src/foo/foo.ts24export interface Interface { ... }25export class Service extends Context.Service<Service, Interface>()("@opencode/Foo") {}26export const layer = Layer.effect(Service, ...)27export const defaultLayer = layer.pipe(...)2829export * as Foo from "./foo"30```3132Consumers import the namespace projection:3334```ts35import { Foo } from "@/foo/foo"3637yield * Foo.Service38Foo.layer39Foo.defaultLayer40```4142Namespace-private helpers stay as non-exported top-level declarations in the43same file — they remain inaccessible to consumers (they are not projected by44`export * as`) but are usable by the file's own code.4546## When the file is an `index.ts`4748If the module is `foo/index.ts` (single-namespace directory), use `"."` for49the self-reexport source rather than `"./index"`:5051```ts52// src/foo/index.ts53export const thing = ...5455export * as Foo from "."56```5758## Multi-sibling directories5960For directories with several independent modules (e.g. `src/session/`,61`src/config/`), keep each sibling as its own file with its own self-reexport,62and do not add a barrel `index.ts`. Consumers import the specific sibling:6364```ts65import { SessionRetry } from "@/session/retry"66import { SessionStatus } from "@/session/status"67```6869Barrels in multi-sibling directories force every import through the barrel to70evaluate every sibling, which defeats tree-shaking and slows module load.7172# opencode Effect rules7374Use these rules when writing or migrating Effect code.7576See `specs/effect/migration.md` for the compact pattern reference and examples.7778## Core7980- Use `Effect.gen(function* () { ... })` for composition.81- Use `Effect.fn("Domain.method")` for named/traced effects and `Effect.fnUntraced` for internal helpers.82- `Effect.fn` / `Effect.fnUntraced` accept pipeable operators as extra arguments, so avoid unnecessary outer `.pipe()` wrappers.83- Use `Effect.callback` for callback-based APIs.84- Use `Effect.void` instead of `Effect.succeed(undefined)` or `Effect.succeed(void 0)`.85- Prefer `DateTime.nowAsDate` over `new Date(yield* Clock.currentTimeMillis)` when you need a `Date`.8687## Module conventions8889- In `src/config`, follow the existing self-export pattern at the top of the file (for example `export * as ConfigAgent from "./agent"`) when adding a new config module.9091## Schemas and errors9293- Use `Schema.Class` for multi-field data.94- Use branded schemas (`Schema.brand`) for single-value types.95- Use `Schema.TaggedErrorClass` for typed errors.96- Use `Schema.Defect` instead of `unknown` for defect-like causes.97- In `Effect.gen` / `Effect.fn`, prefer `yield* new MyError(...)` over `yield* Effect.fail(new MyError(...))` for direct early-failure branches.9899## Runtime vs InstanceState100101- Use `makeRuntime` (from `src/effect/run-service.ts`) for all services. It returns `{ runPromise, runFork, runCallback }` backed by a shared `memoMap` that deduplicates layers.102- Use `InstanceState` (from `src/effect/instance-state.ts`) for per-directory or per-project state that needs per-instance cleanup. It uses `ScopedCache` keyed by directory — each open project gets its own state, automatically cleaned up on disposal.103- If two open directories should not share one copy of the service, it needs `InstanceState`.104- Do the work directly in the `InstanceState.make` closure — `ScopedCache` handles run-once semantics. Don't add fibers, `ensure()` callbacks, or `started` flags on top.105- Use `Effect.addFinalizer` or `Effect.acquireRelease` inside the `InstanceState.make` closure for cleanup (subscriptions, process teardown, etc.).106- Use `Effect.forkScoped` inside the closure for background stream consumers — the fiber is interrupted when the instance is disposed.107- To make a service's `init()` non-blocking, fork `InstanceState.get(state)` at the `init()` call site (e.g. `Effect.forkIn(scope)`), not by forking work inside the `InstanceState.make` closure. Forking inside the closure leaves state incomplete for other methods that read it.108- `src/project/bootstrap.ts` already wraps every service `init()` in `Effect.forkDetach`, so `init()` is fire-and-forget in production. Keep `init()` methods synchronous internally; the caller controls concurrency.109110## Effect v4 beta API111112- `Effect.fork` and `Effect.forkDaemon` do not exist. Use `Effect.forkIn(scope)` to fork a fiber into a specific scope.113114## Preferred Effect services115116- In effectified services, prefer yielding existing Effect services over dropping down to ad hoc platform APIs.117- Prefer `FileSystem.FileSystem` instead of raw `fs/promises` for effectful file I/O.118- Prefer `ChildProcessSpawner.ChildProcessSpawner` with `ChildProcess.make(...)` instead of custom process wrappers.119- Prefer `HttpClient.HttpClient` instead of raw `fetch`.120- Prefer `Path.Path`, `Config`, `Clock`, and `DateTime` when those concerns are already inside Effect code.121- For background loops or scheduled tasks, use `Effect.repeat` or `Effect.schedule` with `Effect.forkScoped` in the layer definition.122123## Effect.cached for deduplication124125Use `Effect.cached` when multiple concurrent callers should share a single in-flight computation rather than storing `Fiber | undefined` or `Promise | undefined` manually. See `specs/effect/migration.md` for the full pattern.126127## Callback boundaries128129Use `EffectBridge` for native or external callbacks (`@parcel/watcher`, `node-pty`, native `fs.watch`, plugin callbacks, etc.) that need to re-enter Effect services with instance/workspace context.130131Plain async code should pass explicit context or stay inside an Effect fiber; do not add ambient instance context shims.132
Also in anomalyco/opencode
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| anomalyco/opencodeAGENTS.md · 193k | AGENTS.md | testlint-formatstyletypes+3 | 80/100 | 3 days ago | |
| anomalyco/opencodepackages/app/AGENTS.md · 193k | AGENTS.md | style | 56/100 | 3 days ago | |
| anomalyco/opencodepackages/app/e2e/performance/AGENTS.md · 193k | AGENTS.md | no sections | 16/100 | 3 days ago | |
| anomalyco/opencodepackages/codemode/AGENTS.md · 193k | AGENTS.md | api | 43/100 | 3 days ago | |
| anomalyco/opencodepackages/core/src/tool/AGENTS.md · 193k | AGENTS.md | stylesecurity | 58/100 | 3 days ago | |
| anomalyco/opencodepackages/effect-drizzle-sqlite/AGENTS.md · 193k | AGENTS.md | database | 38/100 | 3 days ago | |
| anomalyco/opencodepackages/llm/AGENTS.md · 193k | AGENTS.md | stylearchtesting-strategygit+1 | 57/100 | 3 days ago | |
| anomalyco/opencodepackages/opencode/src/server/routes/instance/httpapi/AGENTS.md · 193k | AGENTS.md | styleapi | 40/100 | 3 days ago | |
| anomalyco/opencodepackages/opencode/src/session/llm/AGENTS.md · 193k | AGENTS.md | arch | 61/100 | 3 days ago | |
| anomalyco/opencodepackages/opencode/test/AGENTS.md · 193k | AGENTS.md | teststylearchtesting-strategy+1 | 81/100 | 3 days ago | |
| anomalyco/opencodepackages/opencode/test/server/AGENTS.md · 193k | AGENTS.md | teststyleapi | 38/100 | 3 days ago | |
| anomalyco/opencodepackages/schema/AGENTS.md · 193k | AGENTS.md | styletypesdatabaseapi+1 | 65/100 | 3 days ago |
Diff against AGENTS.md Diff against packages/app/AGENTS.md Diff against packages/app/e2e/performance/AGENTS.md Diff against packages/codemode/AGENTS.md Diff against packages/core/src/tool/AGENTS.md Diff against packages/effect-drizzle-sqlite/AGENTS.md Diff against packages/llm/AGENTS.md Diff against packages/opencode/src/server/routes/instance/httpapi/AGENTS.md Diff against packages/opencode/src/session/llm/AGENTS.md Diff against packages/opencode/test/AGENTS.md Diff against packages/opencode/test/server/AGENTS.md Diff against packages/schema/AGENTS.md
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| aaif-goose/gooseAGENTS.md · 52k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| n8n-io/n8npackages/@n8n/agents/AGENTS.md · 199k | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| duckduckgo/content-scope-scriptsspecial-pages/AGENTS.md · 70 | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| code-yeongyu/oh-my-openagentpackages/web/AGENTS.md · 67k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 2 days ago | |
| mui/material-uiAGENTS.md · 99k | AGENTS.md | setupbuildtestlint-format+9 | 100/100 | 3 days ago | |
| TryGhost/Ghoste2e/AGENTS.md · 55k | AGENTS.md | setupteststylearch+2 | 100/100 | 3 days ago | |
| elastic/elasticsearchx-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/AGENTS.md · 78k | AGENTS.md | buildtestlint-formatstyle+2 | 100/100 | 3 days ago | |
| elastic/elasticsearchx-pack/plugin/inference/AGENTS.md · 78k | AGENTS.md | buildtestlint-formatstyle+3 | 100/100 | 3 days ago |
