DashboardopencodeSession 1JyMljb40jX8

Session 1JyMljb40jX8

Full ID: 1JyMljb40jX8CuggV
Messages: 92
Distillations: 14
Time range: 2026-09-14 08:13:47 — 2026-09-14 08:28:17

Conversation (92 messages)

Research only, do not edit files. In /home/byk/Code/opencode, trace the current v1/legacy session execution lifecycle used by the Node standalone server. Determine what durable state exists for an in-progress prompt, what startup hooks run, how active/busy session status is represented, and whether safe restart recovery already exists. Focus on exact file paths, symbols, and semantics. Identify duplicate-provider-call/tool-side-effect risks. Return concise findings with file:line references and a feasible minimal design if possible. Thoroughness: very thorough.

gateway · 2026-09-14 08:13:47
result
/home/byk/Code/opencode/CONTRIBUTING.md
gateway · 2026-09-14 08:14:09
result
/home/byk/Code/opencode/package.json
/home/byk/Code/opencode/artifacts/glm52-rise-video/package.json
/home/byk/Code/opencode/packages/codemode/package.json
/home/byk/Code/opencode/github/package.json
/home/byk/Code/opencode/packages/session-ui/package.json
/home/byk/Code/opencode/sdks/vscode/package.json
/home/byk/Code/opencode/packages/script/package.json
/home/byk/Code/opencode/packages/plugin/package.json
/home/byk/Code/opencode/packages/sdk-next/package.json
/home/byk/Code/opencode/packages/schema/package.json
/home/byk/Code/opencode/packages/web/package.json
/home/byk/Code/opencode/packages/protocol/package.json
/home/byk/Code/opencode/packages/httpapi-codegen/package.json
/home/byk/Code/opencode/packages/client/package.json
/home/byk/Code/opencode/packages/effect-drizzle-sqlite/package.json
/home/byk/Code/opencode/packages/tui/package.json
/home/byk/Code/opencode/packages/stats/server/package.json
/home/byk/Code/opencode/packages/opencode/package.json
/home/byk/Code/opencode/pack...
gateway · 2026-09-14 08:14:13
result
/home/byk/Code/opencode/packages/opencode/src/share/session.ts
/home/byk/Code/opencode/packages/opencode/src/session/session.ts
/home/byk/Code/opencode/packages/opencode/src/cli/tui/validate-session.ts
/home/byk/Code/opencode/packages/opencode/src/acp/session.ts
/home/byk/Code/opencode/packages/opencode/src/cli/cmd/session.ts
/home/byk/Code/opencode/packages/opencode/src/cli/cmd/run/session-replay.ts
/home/byk/Code/opencode/packages/opencode/src/cli/cmd/run/session.shared.ts
/home/byk/Code/opencode/packages/opencode/src/cli/cmd/run/session-data.ts
/home/byk/Code/opencode/packages/opencode/src/server/routes/instance/httpapi/groups/session.ts
/home/byk/Code/opencode/packages/opencode/src/server/routes/instance/httpapi/handlers/session.ts
/home/byk/Code/opencode/packages/opencode/src/server/routes/instance/httpapi/handlers/session-errors.ts
gateway · 2026-09-14 08:14:18
result
/home/byk/Code/opencode/AGENTS.md
/home/byk/Code/opencode/packages/codemode/AGENTS.md
/home/byk/Code/opencode/packages/session-ui/AGENTS.md
/home/byk/Code/opencode/packages/schema/AGENTS.md
/home/byk/Code/opencode/packages/effect-drizzle-sqlite/AGENTS.md
/home/byk/Code/opencode/packages/llm/AGENTS.md
/home/byk/Code/opencode/packages/ui/AGENTS.md
/home/byk/Code/opencode/packages/opencode/AGENTS.md
/home/byk/Code/opencode/packages/opencode/test/AGENTS.md
/home/byk/Code/opencode/packages/stats/AGENTS.md
/home/byk/Code/opencode/packages/core/src/tool/AGENTS.md
/home/byk/Code/opencode/packages/opencode/test/server/AGENTS.md
/home/byk/Code/opencode/packages/desktop/AGENTS.md
/home/byk/Code/opencode/packages/opencode/src/session/llm/AGENTS.md
/home/byk/Code/opencode/packages/app/AGENTS.md
/home/byk/Code/opencode/packages/opencode/src/server/routes/instance/httpapi/AGENTS.md
/home/byk/Code/opencode/packages/app/e2e/AGENTS.md
/home/byk/Code/opencode/packages/app/e2e/performance/AGENTS.md
gateway · 2026-09-14 08:14:23
result
<path>/home/byk/Code/opencode/AGENTS.md</path>
<type>file</type>
<content>
1: - To regenerate the legacy JavaScript SDK, run `./packages/sdk/js/script/build.ts`.
2: - After changing the public Protocol or Server `HttpApi`, run `bun run generate` from `packages/client`. Do not edit `src/generated` or `src/generated-effect` directly.
3: - Keep runtime dependencies directed from Schema to Core and Protocol, then from Core and Protocol to Server. Client runtime code may depend on Schema and Protocol but never Core or Server; `sdk-next` composes Client, Core, and Server.
4: - The default branch in this repo is `dev`.
5: - Local `main` ref may not exist; use `dev` or `origin/dev` for diffs.
6: 
7: ## Branch Names
8: 
9: Use a short branch name of at most three words, separated by hyphens. Do not use slashes or type prefixes such as `feat/` or `fix/`.
10: 
11: Examples: `session-recovery`, `fix-scroll-state`, `regenerate-sdk`. ...
gateway · 2026-09-14 08:14:27
result
<path>/home/byk/Code/opencode/packages/opencode/AGENTS.md</path>
<type>file</type>
<content>
1: # opencode database guide
2: 
3: ## Database
4: 
5: - **Schema**: Drizzle schema lives in `packages/core/src/**/*.sql.ts`.
6: - **Migrations**: database migrations live in `packages/core` and are applied by core.
7: 
8: ## Development server
9: 
10: - 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`.
14: 
15: # Module shape
16: 
17: Do not use `export namespace Foo { ... }` for module organization. It is not
18: standard ESM, it prevents tree-shaking, and it breaks Node's native TypeScript
19: runner. ...
gateway · 2026-09-14 08:14:32
result
<path>/home/byk/Code/opencode/packages/opencode/src/server/routes/instance/httpapi/AGENTS.md</path>
<type>file</type>
<content>
1: # HttpApi Route Patterns
2: 
3: Use `HttpApiBuilder.group(...)` for normal HTTP endpoints, including streaming HTTP responses such as server-sent events. Handlers should yield stable services once while building the handler layer, then close over those services in endpoint implementations.
4: 
5: ```ts
6: export const sessionHandlers = HttpApiBuilder.group(InstanceHttpApi, "session", (handlers) =>
7:   Effect.gen(function* () {
8:     const session = yield* Session.Service
9: 
10:     return handlers.handle("list", () => session.list())
11:   }),
12: )
13: ```
14: 
15: For SSE endpoints, stay in `HttpApiBuilder.group(...)` and return `HttpServerResponse.stream(...)` from the handler. Annotate the endpoint success schema with `HttpApiSchema.asText({ contentType: "text/event-stream" })` so OpenAPI documents the stream content type. ...
gateway · 2026-09-14 08:14:36
result
<path>/home/byk/Code/opencode/CONTRIBUTING.md</path>
<type>file</type>
<content>
1: # Contributing to OpenCode
2: 
3: We want to make it easy for you to contribute to OpenCode. Here are the most common type of changes that get merged:
4: 
5: - Bug fixes
6: - Additional LSPs / Formatters
7: - Improvements to LLM performance
8: - Support for new providers
9: - Fixes for environment-specific quirks
10: - Missing standard behavior
11: - Documentation improvements
12: 
13: However, any UI or core product feature must go through a design review with the core team before implementation.
14: 
15: If you are unsure if a PR would be accepted, feel free to ask a maintainer or look for issues with any of the following labels:
16: 
17: - [`help wanted`](https://github.com/anomalyco/opencode/issues?q=is%3Aissue%20state%3Aopen%20label%3Ahelp-wanted)
18: - [`good first issue`](https://github.com/anomalyco/opencode/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22good%20first%20issue%22)
19: - ...
gateway · 2026-09-14 08:14:42
result
<path>/home/byk/Code/opencode/package.json</path>
<type>file</type>
<content>
1: {
2:   "$schema": "https://json.schemastore.org/package.json",
3:   "name": "opencode",
4:   "description": "AI-powered development tool",
5:   "private": true,
6:   "type": "module",
7:   "packageManager": "bun@1.3.14",
8:   "scripts": {
9:     "dev": "bun run --cwd packages/opencode src/index.ts",
10:     "dev:desktop": "bun --cwd packages/desktop dev",
11:     "dev:web": "bun --cwd packages/app dev",
12:     "dev:console": "ulimit -n 10240 2>/dev/null; bun run --cwd packages/console/app dev",
13:     "dev:stats": "bun sst shell --stage=production -- bun run --cwd packages/stats/app dev",
14:     "dev:storybook": "bun --cwd packages/storybook storybook",
15:     "lint": "oxlint",
16:     "typecheck": "bun turbo typecheck",
17:     "upgrade-opentui": "bun run script/upgrade-opentui.ts",
18:     "postinstall": "bun run --cwd packages/core fix-node-pty",
19:     "prepare": "husky",
20:     "random": "echo ...
gateway · 2026-09-14 08:14:48
result
Found 9 matches
/home/byk/Code/opencode/packages/opencode/src/effect/app-runtime.ts:
  Line 31: import { SessionPrompt } from "@/session/prompt"


/home/byk/Code/opencode/packages/opencode/src/control-plane/workspace.ts:
  Line 25: import { SessionPrompt } from "@/session/prompt"


/home/byk/Code/opencode/packages/opencode/src/cli/cmd/github.handler.ts:
  Line 30: import { SessionPrompt } from "@/session/prompt"


/home/byk/Code/opencode/packages/opencode/src/session/prompt.ts:
  Line 152:     const cancel = Effect.fn("SessionPrompt.cancel")(function* (sessionID: SessionID) {

  Line 1053:       "SessionPrompt.prompt",

  Line 1343:     const loop: (input: LoopInput) => Effect.Effect<SessionV1.WithParts> = Effect.fn("SessionPrompt.loop")(function* (


/home/byk/Code/opencode/packages/opencode/src/server/routes/instance/httpapi/server.ts:
  Line 35: import { SessionPrompt } from ...
gateway · 2026-09-14 08:14:55
result
Found 33 matches
/home/byk/Code/opencode/packages/opencode/src/session/run-state.ts:
  Line 9: import { SessionStatus } from "./status"

  Line 33:     const status = yield* SessionStatus.Service

  Line 62:           yield* status.set(sessionID, { type: "idle" })

  Line 64:         onBusy: status.set(sessionID, { type: "busy" }),

  Line 74:       if (existing?.busy) yield* busyError(sessionID)

  Line 82:         yield* status.set(sessionID, { type: "idle" })

  Line 104:         .pipe(Effect.catchTag("RunnerBusy", () => Effect.fail(busyError(sessionID))))

  Line 145: function busyError(sessionID: SessionID) {

  Line 149: export const node = LayerNode.make({ service: Service, layer: layer, deps: [BackgroundJob.node, SessionStatus.node] })


/home/byk/Code/opencode/packages/opencode/src/session/prompt.ts:
  Line 36: import { SessionStatus } from "./status"

  Line 116:     const status = yield* SessionStatus.Service

  Line 1089:           yield* status.set(sessionID, { type: ...
gateway · 2026-09-14 08:15:00
result
Found 6 matches
/home/byk/Code/opencode/packages/opencode/src/cli/tui/worker.ts:
  Line 28: let server: Awaited<ReturnType<typeof Server.listen>> | undefined

  Line 56:     server = await Server.listen(input)


/home/byk/Code/opencode/packages/opencode/src/cli/cmd/acp.ts:
  Line 25:     const server = yield* Effect.promise(() => ACPProfile.measure("cli.acp.server.listen", () => Server.listen(opts)))


/home/byk/Code/opencode/packages/opencode/src/cli/cmd/web.ts:
  Line 44:     const server = yield* Effect.promise(() => Server.listen(opts))


/home/byk/Code/opencode/packages/opencode/src/cli/cmd/serve.ts:
  Line 7:   command: "serve",

  Line 19:     const server = yield* Effect.promise(() => Server.listen(opts))
gateway · 2026-09-14 08:15:07
result
Found 16 matches
/home/byk/Code/opencode/packages/opencode/src/server/routes/instance/httpapi/server.ts:
  Line 35: import { SessionPrompt } from "@/session/prompt"

  Line 246:   SessionPrompt.node,


/home/byk/Code/opencode/packages/opencode/src/server/routes/instance/httpapi/groups/experimental.ts:
  Line 197:             description: "Create a new git worktree for the current project and run any configured startup scripts.",

  Line 229:             identifier: "experimental.session.list",


/home/byk/Code/opencode/packages/opencode/src/server/routes/instance/httpapi/groups/session.ts:
  Line 7: import { SessionPrompt } from "@/session/prompt"

  Line 70: export const PromptPayload = Schema.Struct(Struct.omit(SessionPrompt.PromptInput.fields, ["sessionID"]))

  Line 71: export const CommandPayload = Schema.Struct(Struct.omit(SessionPrompt.CommandInput.fields, ["sessionID"]))

  Line 72: export const ShellPayload = Schema.Struct(Struct.omit(SessionPrompt.ShellInput.fields, ...
gateway · 2026-09-14 08:15:12
result
<path>/home/byk/Code/opencode/packages/opencode/src/cli/cmd/serve.ts</path>
<type>file</type>
<content>
1: import { Effect } from "effect"
2: import { effectCmd } from "../effect-cmd"
3: import { withNetworkOptions, resolveNetworkOptions } from "../network"
4: import { Flag } from "@opencode-ai/core/flag/flag"
5: 
6: export const ServeCommand = effectCmd({
7:   command: "serve",
8:   builder: (yargs) => withNetworkOptions(yargs),
9:   describe: "starts a headless opencode server",
10:   // Server loads instances per-request via x-opencode-directory header — no
11:   // need for an ambient project InstanceContext at startup.
12:   instance: false,
13:   handler: Effect.fn("Cli.serve")(function* (args) {
14:     const { Server } = yield* Effect.promise(() => import("../../server/server"))
15:     if (!Flag.OPENCODE_SERVER_PASSWORD) {
16:       console.log("Warning: OPENCODE_SERVER_PASSWORD is not set; server is unsecured.")
17:     }
18:     const opts = yield* ...
gateway · 2026-09-14 08:15:16
result
<path>/home/byk/Code/opencode/packages/opencode/src/server/server.ts</path>
<type>file</type>
<content>
1: import "./init-projectors"
2: 
3: import { NodeHttpServer } from "@effect/platform-node"
4: import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
5: import { ConfigProvider, Context, Effect, Exit, Layer, Scope } from "effect"
6: import { HttpRouter, HttpServer } from "effect/unstable/http"
7: import { OpenApi } from "effect/unstable/httpapi"
8: import { createServer } from "node:http"
9: import { MDNS } from "./mdns"
10: import { HttpApiApp } from "./routes/instance/httpapi/server"
11: import { disposeMiddleware } from "./routes/instance/httpapi/lifecycle"
12: import { WebSocketTracker } from "./routes/instance/httpapi/websocket-tracker"
13: import { PublicApi } from "./routes/instance/httpapi/public"
14: import type { CorsOptions } from "@opencode-ai/server/cors"
15: import { lazy } from "@/util/lazy"
16: 
17: // @ts-ignore This global is needed to prevent ...
gateway · 2026-09-14 08:15:21
result
<path>/home/byk/Code/opencode/packages/opencode/src/server/routes/instance/httpapi/server.ts</path>
<type>file</type>
<content>
1: import { Config as EffectConfig, Context, Effect, Layer } from "effect"
2: import { HttpApiBuilder, OpenApi } from "effect/unstable/httpapi"
3: import { HttpClient, HttpMiddleware, HttpRouter, HttpServer, HttpServerResponse } from "effect/unstable/http"
4: import * as Socket from "effect/unstable/socket/Socket"
5: import { FSUtil } from "@opencode-ai/core/fs-util"
6: import * as Observability from "@opencode-ai/core/observability"
7: import { Account } from "@/account/account"
8: import { Agent } from "@/agent/agent"
9: import { Auth } from "@/auth"
10: import { BackgroundJob } from "@/background/job"
11: import { Command } from "@/command"
12: import { Config } from "@/config/config"
13: import { Workspace } from "@/control-plane/workspace"
14: import { Env } from "@/env"
15: import { EventV2Bridge } from "@/event-v2-bridge"
16: import { Format } from ...
gateway · 2026-09-14 08:15:29
result
<path>/home/byk/Code/opencode/packages/opencode/src/server/routes/instance/httpapi/server.ts</path>
<type>file</type>
<content>
306:     Layer.provide(AppNodeBuilderV1.build(app)),
307:     // Must stay last: layers provided later in this pipe build beneath earlier ones,
308:     // so Observability must come after every service graph. Otherwise eagerly forked
309:     // fibers (e.g. the ModelsDev background refresh) capture Effect's default stdout
310:     // logger and corrupt the TUI (#34730).
311:     Layer.provideMerge(Observability.layer),
312:   )
313: }
314: 
315: export const routes = createRoutes()
316: 
317: export const webHandler = lazy(() =>
318:   HttpRouter.toWebHandler(routes, {
319:     disableLogger: true,
320:     memoMap,
321:     middleware: disposeMiddleware,
322:   }),
323: )
324: 
325: export * as HttpApiApp from "./server"

(End of file - total 325 lines)
</content>
gateway · 2026-09-14 08:15:33
result
<path>/home/byk/Code/opencode/packages/opencode/src/effect/app-node-builder-v1.ts</path>
<type>file</type>
<content>
1: import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
2: import { LayerNode } from "@opencode-ai/core/effect/layer-node"
3: import { InstanceBootstrap } from "@/project/bootstrap"
4: import { InstanceStore } from "@/project/instance-store"
5: 
6: const bootstrapReplacement = [InstanceStore.bootstrapNode, InstanceBootstrap.node] as const
7: 
8: export function build<A, E>(root: LayerNode.Node<A, E, any>, replacements: LayerNode.Replacements = []) {
9:   return AppNodeBuilder.build(root, replacements.concat([bootstrapReplacement]))
10: }
11: 
12: export * as AppNodeBuilderV1 from "./app-node-builder-v1"

(End of file - total 12 lines)
</content>
gateway · 2026-09-14 08:15:38
result
<path>/home/byk/Code/opencode/packages/opencode/src/project/bootstrap.ts</path>
<type>file</type>
<content>
1: import { makeGlobalNode } from "@opencode-ai/core/effect/app-node"
2: import { Plugin } from "../plugin"
3: import { Format } from "../format"
4: import { LSP } from "@/lsp/lsp"
5: import { Snapshot } from "../snapshot"
6: import * as Project from "./project"
7: import * as Vcs from "./vcs"
8: import { InstanceState } from "@/effect/instance-state"
9: import { ShareNext } from "@/share/share-next"
10: import { Effect, Layer } from "effect"
11: import { Config } from "@/config/config"
12: import { Service } from "./bootstrap-service"
13: 
14: export { Service } from "./bootstrap-service"
15: export type { Interface } from "./bootstrap-service"
16: 
17: const layer = Layer.effect(
18:   Service,
19:   Effect.gen(function* () {
20:     // Yield each bootstrap dep at layer init so `run` itself has R = never. ...
gateway · 2026-09-14 08:15:44
result
<path>/home/byk/Code/opencode/packages/opencode/src/project/instance-store.ts</path>
<type>file</type>
<content>
1: import { LayerNode } from "@opencode-ai/core/effect/layer-node"
2: import { makeGlobalNode, Node } from "@opencode-ai/core/effect/app-node"
3: import { GlobalBus } from "@/bus/global"
4: import { serviceUse } from "@opencode-ai/core/effect/service-use"
5: import { WorkspaceContext } from "@/control-plane/workspace-context"
6: import { InstanceRef } from "@/effect/instance-ref"
7: import { disposeInstance as runDisposers } from "@/effect/instance-registry"
8: import { FSUtil } from "@opencode-ai/core/fs-util"
9: import { Context, Deferred, Duration, Effect, Exit, Layer, Scope } from "effect"
10: import { type InstanceContext } from "./instance-context"
11: import { InstanceBootstrap } from "./bootstrap-service"
12: import * as Project from "./project"
13: 
14: export interface LoadInput {
15:   directory: string
16:   worktree?: string
17:   project?: Project.Info
18: ...
gateway · 2026-09-14 08:15:48
result
<path>/home/byk/Code/opencode/packages/opencode/src/server/routes/instance/httpapi/middleware/instance-context.ts</path>
<type>file</type>
<content>
1: import { InstanceRef, WorkspaceRef } from "@/effect/instance-ref"
2: import { InstanceStore } from "@/project/instance-store"
3: import { Effect, Layer } from "effect"
4: import { HttpServerResponse } from "effect/unstable/http"
5: import { HttpApiMiddleware } from "effect/unstable/httpapi"
6: import { WorkspaceRouteContext } from "./workspace-routing"
7: 
8: export class InstanceContextMiddleware extends HttpApiMiddleware.Service<
9:   InstanceContextMiddleware,
10:   {
11:     requires: WorkspaceRouteContext
12:   }
13: >()("@opencode/ExperimentalHttpApiInstanceContext") {}
14: 
15: function decode(input: string): string {
16:   try {
17:     return decodeURIComponent(input)
18:   } catch {
19:     return input
20:   }
21: }
22: 
23: function provideInstanceContext<E>(
24:   effect: ...
gateway · 2026-09-14 08:15:54
result
<path>/home/byk/Code/opencode/packages/opencode/src/server/routes/instance/httpapi/handlers/session.ts</path>
<type>file</type>
<content>
1: import { PermissionV1 } from "@opencode-ai/core/v1/permission"
2: import { Agent } from "@/agent/agent"
3: import { SessionV1 } from "@opencode-ai/core/v1/session"
4: import { EventV2Bridge } from "@/event-v2-bridge"
5: import { Command } from "@/command"
6: import { Permission } from "@/permission"
7: import { SessionShare } from "@/share/session"
8: import { Session } from "@/session/session"
9: import { SessionCompaction } from "@/session/compaction"
10: import { MessageV2 } from "@/session/message-v2"
11: import { SessionPrompt } from "@/session/prompt"
12: import { SessionRevert } from "@/session/revert"
13: import { SessionRunState } from "@/session/run-state"
14: import { SessionStatus } from "@/session/status"
15: import { SessionSummary } from "@/session/summary"
16: import { Todo } from "@/session/todo"
17: import { MessageID, PartID, ...
gateway · 2026-09-14 08:15:59
result
<path>/home/byk/Code/opencode/packages/opencode/src/server/routes/instance/httpapi/handlers/session.ts</path>
<type>file</type>
<content>
292:       return true
293:     })
294: 
295:     const prompt = Effect.fn("SessionHttpApi.prompt")(function* (ctx: {
296:       params: { sessionID: SessionID }
297:       payload: typeof PromptPayload.Type
298:     }) {
299:       yield* requireSession(ctx.params.sessionID)
300:       const message = yield* promptSvc
301:         .prompt({
302:           ...ctx.payload,
303:           sessionID: ctx.params.sessionID,
304:         })
305:         .pipe(Effect.mapError(() => new HttpApiError.BadRequest({})))
306:       return HttpServerResponse.stream(Stream.make(JSON.stringify(message)).pipe(Stream.encodeText), {
307:         contentType: "application/json",
308:       })
309:     })
310: 
311:     const promptAsync = Effect.fn("SessionHttpApi.promptAsync")(function* (ctx: {
312:       params: { sessionID: SessionID }
313:       payload: typeof ...
gateway · 2026-09-14 08:16:03
result
<path>/home/byk/Code/opencode/packages/opencode/src/session/prompt.ts</path>
<type>file</type>
<content>
1: import { LayerNode } from "@opencode-ai/core/effect/layer-node"
2: import { PermissionV1 } from "@opencode-ai/core/v1/permission"
3: import path from "path"
4: import { SessionV1 } from "@opencode-ai/core/v1/session"
5: import os from "os"
6: import { SessionID, MessageID, PartID } from "./schema"
7: import { MessageV2 } from "./message-v2"
8: import { SessionRevert } from "./revert"
9: import { Session } from "./session"
10: import { Agent } from "../agent/agent"
11: import { Provider } from "@/provider/provider"
12: 
13: import { type Tool as AITool, tool, jsonSchema } from "ai"
14: import type { JSONSchema7 } from "@ai-sdk/provider"
15: import { SessionCompaction } from "./compaction"
16: import { SystemPrompt } from "./system"
17: import { Instruction } from "./instruction"
18: import { Plugin } from "../plugin"
19: import { MAX_STEPS_PROMPT } from ...
gateway · 2026-09-14 08:16:10
result
Found 40 matches
/home/byk/Code/opencode/packages/opencode/src/session/prompt.ts:
  Line 84: function mcpResourceBase64Size(value: string) {

  Line 90: function formatMcpResourceBytes(value: number) {

  Line 96: function isOrphanedInterruptedTool(part: SessionV1.ToolPart) {

  Line 115:   Effect.gen(function* () {

  Line 123:     const commands = yield* Command.Service

  Line 144:     const ops = Effect.fn("SessionPrompt.ops")(function* () {

  Line 152:     const cancel = Effect.fn("SessionPrompt.cancel")(function* (sessionID: SessionID) {

  Line 157:     const resolvePromptParts = Effect.fn("SessionPrompt.resolvePromptParts")(function* (template: string) {

  Line 164:         Effect.fnUntraced(function* (match) {

  Line 193:     const title = Effect.fn("SessionPrompt.ensureTitle")(function* (input: {

  Line 255:     const handleSubtask = Effect.fn("SessionPrompt.handleSubtask")(function* (input: {

  Line 265:       const promptOps = yield* ops()

  Line 334:             ...
gateway · 2026-09-14 08:16:15
result
<path>/home/byk/Code/opencode/packages/opencode/src/session/prompt.ts</path>
<type>file</type>
<content>
430:       if (!task.command) return
431: 
432:       const summaryUserMsg: SessionV1.User = {
433:         id: MessageID.ascending(),
434:         sessionID,
435:         role: "user",
436:         time: { created: Date.now() },
437:         agent: lastUser.agent,
438:         model: lastUser.model,
439:       }
440:       yield* sessions.updateMessage(summaryUserMsg)
441:       yield* sessions.updatePart({
442:         id: PartID.ascending(),
443:         messageID: summaryUserMsg.id,
444:         sessionID,
445:         type: "text",
446:         text: "Summarize the task tool output above and continue with your task.",
447:         synthetic: true,
448:       } satisfies SessionV1.TextPart)
449:     })
450: 
451:     const shellImpl = Effect.fn("SessionPrompt.shellImpl")(function* (input: ShellInput, ready?: Latch.Latch) {
452:       return yield* ...
gateway · 2026-09-14 08:16:23
result
<path>/home/byk/Code/opencode/packages/opencode/src/session/prompt.ts</path>
<type>file</type>
<content>
760:                   })
761:                   pieces.push({
762:                     messageID: info.id,
763:                     sessionID: input.sessionID,
764:                     type: "file",
765:                     mime,
766:                     filename,
767:                     url: `data:${mime};base64,${c.blob}`,
768:                   })
769:                 }
770:               }
771:             } else {
772:               const error = Cause.squash(exit.cause)
773:               yield* Effect.logError("failed to read MCP resource", { error, clientName, uri })
774:               const message = error instanceof Error ? error.message : String(error)
775:               pieces.push({
776:                 messageID: info.id,
777:                 sessionID: input.sessionID,
778:                 type: "text",
779:                 synthetic: true,
780:                 ...
gateway · 2026-09-14 08:16:30
result
<path>/home/byk/Code/opencode/packages/opencode/src/session/prompt.ts</path>
<type>file</type>
<content>
1081:     const runLoop: (sessionID: SessionID) => Effect.Effect<SessionV1.WithParts> = Effect.fn("SessionPrompt.run")(
1082:       function* (sessionID: SessionID) {
1083:         const ctx = yield* InstanceState.context
1084:         let structured: unknown
1085:         let step = 0
1086:         const session = yield* sessions.get(sessionID).pipe(Effect.orDie)
1087: 
1088:         while (true) {
1089:           yield* status.set(sessionID, { type: "busy" })
1090:           yield* Effect.logInfo("loop", { "session.id": sessionID, step })
1091: 
1092:           let msgs = yield* MessageV2.filterCompactedEffect(sessionID).pipe(
1093:             Effect.provideService(Database.Service, database),
1094:           )
1095: 
1096:           const { user: lastUser, assistant: lastAssistant, finished: lastFinished, tasks } = MessageV2.latest(msgs)
1097: 
1098:           if (!lastUser) ...
gateway · 2026-09-14 08:16:34
result
<path>/home/byk/Code/opencode/packages/opencode/src/session/run-state.ts</path>
<type>file</type>
<content>
1: import { LayerNode } from "@opencode-ai/core/effect/layer-node"
2: import { InstanceState } from "@/effect/instance-state"
3: import { SessionV1 } from "@opencode-ai/core/v1/session"
4: import { Runner } from "@/effect/runner"
5: import { BackgroundJob } from "@/background/job"
6: import { Effect, Latch, Layer, Scope, Context } from "effect"
7: import { Session } from "./session"
8: import { SessionID } from "./schema"
9: import { SessionStatus } from "./status"
10: 
11: export interface Interface {
12:   readonly assertNotBusy: (sessionID: SessionID) => Effect.Effect<void, Session.BusyError>
13:   readonly cancel: (sessionID: SessionID) => Effect.Effect<void>
14:   readonly ensureRunning: (
15:     sessionID: SessionID,
16:     onInterrupt: Effect.Effect<SessionV1.WithParts>,
17:     work: Effect.Effect<SessionV1.WithParts>,
18:   ) => Effect.Effect<SessionV1.WithParts>
19:  ...
gateway · 2026-09-14 08:16:40
result
<path>/home/byk/Code/opencode/packages/opencode/src/effect/runner.ts</path>
<type>file</type>
<content>
1: import { Cause, Deferred, Effect, Exit, Fiber, Latch, Schema, Scope, SynchronizedRef } from "effect"
2: 
3: export interface Runner<A, E = never> {
4:   readonly state: State<A, E>
5:   readonly busy: boolean
6:   readonly ensureRunning: (work: Effect.Effect<A, E>) => Effect.Effect<A, E>
7:   readonly startShell: (work: Effect.Effect<A, E>, ready?: Latch.Latch) => Effect.Effect<A, E | Busy>
8:   readonly cancel: Effect.Effect<void>
9: }
10: 
11: export class Cancelled extends Schema.TaggedErrorClass<Cancelled>()("RunnerCancelled", {}) {}
12: export class Busy extends Schema.TaggedErrorClass<Busy>()("RunnerBusy", {}) {}
13: 
14: interface RunHandle<A, E> {
15:   id: number
16:   done: Deferred.Deferred<A, E | Cancelled>
17:   fiber: Fiber.Fiber<A, E>
18: }
19: 
20: interface ShellHandle<A, E> {
21:   id: number
22:   cancelled: Deferred.Deferred<void>
23:   ready?: Latch.Latch
24: ...
gateway · 2026-09-14 08:16:45
result
<path>/home/byk/Code/opencode/packages/opencode/src/session/status.ts</path>
<type>file</type>
<content>
1: import { LayerNode } from "@opencode-ai/core/effect/layer-node"
2: import { InstanceState } from "@/effect/instance-state"
3: import { SessionID } from "./schema"
4: import { Effect, Layer, Context } from "effect"
5: import { EventV2Bridge } from "@/event-v2-bridge"
6: import { SessionStatusEvent } from "@opencode-ai/schema/session-status-event"
7: 
8: export const Info = SessionStatusEvent.Info
9: export type Info = SessionStatusEvent.Info
10: 
11: export const Event = SessionStatusEvent
12: 
13: export interface Interface {
14:   readonly get: (sessionID: SessionID) => Effect.Effect<Info>
15:   readonly list: () => Effect.Effect<Map<SessionID, Info>>
16:   readonly set: (sessionID: SessionID, status: Info) => Effect.Effect<void>
17: }
18: 
19: export class Service extends Context.Service<Service, Interface>()("@opencode/SessionStatus") {}
20: 
21: const layer = ...
gateway · 2026-09-14 08:16:50
result
<path>/home/byk/Code/opencode/packages/schema/src/session-status-event.ts</path>
<type>file</type>
<content>
1: export * as SessionStatusEvent from "./session-status-event"
2: 
3: import { Schema } from "effect"
4: import { optional } from "./schema"
5: import { Event } from "./event"
6: import { NonNegativeInt } from "./schema"
7: import { SessionID } from "./session-id"
8: 
9: export const Info = Schema.Union([
10:   Schema.Struct({
11:     type: Schema.Literal("idle"),
12:   }),
13:   Schema.Struct({
14:     type: Schema.Literal("retry"),
15:     attempt: NonNegativeInt,
16:     message: Schema.String,
17:     action: optional(
18:       Schema.Struct({
19:         reason: Schema.String,
20:         provider: Schema.String,
21:         title: Schema.String,
22:         message: Schema.String,
23:         label: Schema.String,
24:         link: optional(Schema.String),
25:       }),
26:     ),
27:     next: NonNegativeInt,
28:   }),
29:   Schema.Struct({
30:     type: ...
gateway · 2026-09-14 08:16:59
result
<path>/home/byk/Code/opencode/packages/opencode/src/session/processor.ts</path>
<type>file</type>
<content>
1: import { LayerNode } from "@opencode-ai/core/effect/layer-node"
2: import { PermissionV1 } from "@opencode-ai/core/v1/permission"
3: import { Image } from "@/image/image"
4: import { SessionV1 } from "@opencode-ai/core/v1/session"
5: import { Cause, Deferred, Effect, Exit, Layer, Context, Scope, Schema } from "effect"
6: import * as Stream from "effect/Stream"
7: import { Agent } from "@/agent/agent"
8: import { Config } from "@/config/config"
9: import { Permission } from "@/permission"
10: import { Plugin } from "@/plugin"
11: import { Snapshot } from "@/snapshot"
12: import { Session } from "./session"
13: import { LLM } from "./llm"
14: import { MessageV2 } from "./message-v2"
15: import { isOverflow } from "./overflow"
16: import { PartID } from "./schema"
17: import type { SessionID } from "./schema"
18: import { SessionRetry } from "./retry"
19: import { SessionStatus ...
gateway · 2026-09-14 08:17:04
result
<path>/home/byk/Code/opencode/packages/opencode/src/session/processor.ts</path>
<type>file</type>
<content>
160:       const completeToolCall = Effect.fn("SessionProcessor.completeToolCall")(function* (
161:         toolCallID: string,
162:         output: {
163:           title: string
164:           metadata: Record<string, any>
165:           output: string
166:           attachments?: SessionV1.FilePart[]
167:         },
168:       ) {
169:         const match = yield* readToolCall(toolCallID)
170:         if (!match || match.part.state.status !== "running") return
171:         yield* session.updatePart({
172:           ...match.part,
173:           state: {
174:             status: "completed",
175:             input: match.part.state.input,
176:             output: output.output,
177:             metadata: output.metadata,
178:             title: output.title,
179:             time: { start: match.part.state.time.start, end: Date.now() },
180:             attachments: ...
gateway · 2026-09-14 08:17:11
result
<path>/home/byk/Code/opencode/packages/opencode/src/session/processor.ts</path>
<type>file</type>
<content>
490:               .pipe(Effect.ignore, Effect.forkIn(scope))
491:             if (
492:               !ctx.assistantMessage.summary &&
493:               isOverflow({ cfg: yield* config.get(), tokens: usage.tokens, model: ctx.model })
494:             ) {
495:               ctx.needsCompaction = true
496:             }
497:             return
498:           }
499: 
500:           case "text-start":
501:             ctx.currentText = {
502:               id: PartID.ascending(),
503:               messageID: ctx.assistantMessage.id,
504:               sessionID: ctx.assistantMessage.sessionID,
505:               type: "text",
506:               text: "",
507:               time: { start: Date.now() },
508:               metadata: value.providerMetadata,
509:             }
510:             yield* session.updatePart(ctx.currentText)
511:             return
512: 
513:           case ...
gateway · 2026-09-14 08:17:20
result
File not found: /home/byk/Code/opencode/packages/opencode/src/session/llm/index.ts
gateway · 2026-09-14 08:17:27
result
/home/byk/Code/opencode/packages/opencode/src/session/llm.ts
gateway · 2026-09-14 08:17:32
result
<path>/home/byk/Code/opencode/packages/opencode/src/session/llm.ts</path>
<type>file</type>
<content>
1: import { LayerNode } from "@opencode-ai/core/effect/layer-node"
2: import { llmClient } from "@opencode-ai/core/effect/app-node-platform"
3: import { PermissionV1 } from "@opencode-ai/core/v1/permission"
4: import { Provider } from "@/provider/provider"
5: import { SessionV1 } from "@opencode-ai/core/v1/session"
6: import { serviceUse } from "@opencode-ai/core/effect/service-use"
7: import { Context, Effect, Layer } from "effect"
8: import * as Stream from "effect/Stream"
9: import { streamText, wrapLanguageModel, type ModelMessage, type Tool } from "ai"
10: import type { LLMEvent } from "@opencode-ai/llm"
11: import { LLMClient } from "@opencode-ai/llm/route"
12: import type { LLMClientService } from "@opencode-ai/llm/route"
13: import { GitLabWorkflowLanguageModel } from "gitlab-ai-provider"
14: import { ProviderTransform } from "@/provider/transform"
15: import { Config } from ...
gateway · 2026-09-14 08:17:37
result
<path>/home/byk/Code/opencode/packages/opencode/src/session/llm.ts</path>
<type>file</type>
<content>
357:     const stream: Interface["stream"] = (input) =>
358:       Stream.scoped(
359:         Stream.unwrap(
360:           Effect.gen(function* () {
361:             const ctrl = yield* Effect.acquireRelease(
362:               Effect.sync(() => new AbortController()),
363:               (ctrl) => Effect.sync(() => ctrl.abort()),
364:             )
365: 
366:             const result = yield* run({ ...input, abort: ctrl.signal })
367: 
368:             if (result.type === "native") return result.stream
369: 
370:             // Adapter seam: both runtimes expose the same LLMEvent stream. Native
371:             // already returns one; AI SDK streams are converted here.
372:             const state = LLMAISDK.adapterState()
373:             return Stream.fromAsyncIterable(result.result.fullStream, (e) =>
374:               e instanceof Error ? ...
gateway · 2026-09-14 08:17:45
result
<path>/home/byk/Code/opencode/packages/opencode/src/session/tools.ts</path>
<type>file</type>
<content>
1: import { Agent } from "@/agent/agent"
2: import { SessionV1 } from "@opencode-ai/core/v1/session"
3: import { Provider } from "@/provider/provider"
4: import { ProviderTransform } from "@/provider/transform"
5: import { MCP } from "@/mcp"
6: import { McpCatalog } from "@/mcp/catalog"
7: import { Permission } from "@/permission"
8: import { Tool } from "@/tool/tool"
9: import { ToolJsonSchema } from "@/tool/json-schema"
10: import { ToolRegistry } from "@/tool/registry"
11: import { Truncate } from "@/tool/truncate"
12: 
13: import { Plugin } from "@/plugin"
14: import type { TaskPromptOps } from "@/tool/task"
15: import { type Tool as AITool, tool, jsonSchema, type ToolExecutionOptions, asSchema } from "ai"
16: import { Effect } from "effect"
17: import { MessageV2 } from "./message-v2"
18: import { Session } from "./session"
19: import { SessionProcessor } from "./processor"
20: ...
gateway · 2026-09-14 08:17:52
result
<path>/home/byk/Code/opencode/packages/opencode/src/session/tools.ts</path>
<type>file</type>
<content>
388:   if (flags.experimentalCodeMode) return tools
389: 
390:   for (const [key, entry] of Object.entries(yield* mcp.tools())) {
391:     const item = McpCatalog.convertTool(entry.def, entry.client, entry.timeout)
392:     const execute = item.execute
393:     if (!execute) continue
394: 
395:     const schema = yield* Effect.promise(() => Promise.resolve(asSchema(item.inputSchema).jsonSchema))
396:     const transformed = ProviderTransform.schema(input.model, { ...schema, properties: schema.properties ?? {} })
397:     item.inputSchema = jsonSchema(transformed)
398:     item.execute = (args, opts) =>
399:       run.promise(
400:         Effect.gen(function* () {
401:           const ctx = context(args, opts)
402:           yield* plugin.trigger(
403:             "tool.execute.before",
404:             { tool: key, sessionID: ctx.sessionID, callID: opts.toolCallId },
405:           ...
gateway · 2026-09-14 08:18:03
result
<path>/home/byk/Code/opencode/packages/opencode/src/session/session.ts</path>
<type>file</type>
<content>
1: import { LayerNode } from "@opencode-ai/core/effect/layer-node"
2: import { PermissionV1 } from "@opencode-ai/core/v1/permission"
3: import { Slug } from "@opencode-ai/core/util/slug"
4: import { SessionV1 } from "@opencode-ai/core/v1/session"
5: import { serviceUse } from "@opencode-ai/core/effect/service-use"
6: import path from "path"
7: import { BackgroundJob } from "@/background/job"
8: import { Decimal } from "decimal.js"
9: import type { ProviderMetadata, Usage } from "@opencode-ai/llm"
10: import { InstallationVersion } from "@opencode-ai/core/installation/version"
11: import { Database } from "@opencode-ai/core/database/database"
12: import { EventV2Bridge } from "@/event-v2-bridge"
13: import { SessionV2 } from "@opencode-ai/core/session"
14: import * as SessionExecutionLocal from "@opencode-ai/core/session/execution/local"
15: import { locationServiceMapLayer } from ...
gateway · 2026-09-14 08:18:11
result
Found 7 matches
/home/byk/Code/opencode/packages/opencode/src/session/session.ts:
  Line 629:     const updateMessage = <T extends SessionV1.Info>(msg: T): Effect.Effect<T> =>

  Line 635:     const updatePart = <T extends SessionV1.Part>(part: T): Effect.Effect<T> =>

  Line 645:     const getPart: Interface["getPart"] = Effect.fn("Session.getPart")(function* (input) {

  Line 749:     const touch = Effect.fn("Session.touch")(function* (sessionID: SessionID) {

  Line 828:     const messages: Interface["messages"] = Effect.fn("Session.messages")(function* (input) {

  Line 877:     const updatePartDelta = Effect.fnUntraced(function* (input: {

  Line 906:     return Service.of({
gateway · 2026-09-14 08:18:16
result
<path>/home/byk/Code/opencode/packages/opencode/src/session/session.ts</path>
<type>file</type>
<content>
560:       if (input?.cursor) conditions.push(lt(SessionTable.time_updated, input.cursor))
561:       if (input?.search) conditions.push(like(SessionTable.title, `%${input.search}%`))
562:       if (!input?.archived) conditions.push(isNull(SessionTable.time_archived))
563: 
564:       const query =
565:         conditions.length > 0
566:           ? db
567:               .select()
568:               .from(SessionTable)
569:               .where(and(...conditions))
570:           : db.select().from(SessionTable)
571:       const rows = yield* query
572:         .orderBy(desc(SessionTable.time_updated), desc(SessionTable.id))
573:         .limit(input?.limit ?? 100)
574:         .all()
575:         .pipe(Effect.orDie)
576:       const ids = [...new Set(rows.map((row) => row.project_id))]
577:       const projects = new Map<string, ProjectInfo>()
578:       if (ids.length > 0) {
579: ...
gateway · 2026-09-14 08:18:21
result
<path>/home/byk/Code/opencode/packages/opencode/src/server/init-projectors.ts</path>
<type>file</type>
<content>
1: import { initProjectors } from "./projectors"
2: 
3: initProjectors()

(End of file - total 3 lines)
</content>
gateway · 2026-09-14 08:18:26
result
<path>/home/byk/Code/opencode/packages/opencode/src/server/projectors.ts</path>
<type>file</type>
<content>
1: export function initProjectors() {}

(End of file - total 1 lines)
</content>
gateway · 2026-09-14 08:18:32
result
<path>/home/byk/Code/opencode/packages/opencode/src/event-v2-bridge.ts</path>
<type>file</type>
<content>
1: // Opencode publish boundary for core events. Attach routed instance location
2: // so direct EventV2 consumers can isolate directory/workspace streams.
3: import { LayerNode } from "@opencode-ai/core/effect/layer-node"
4: import { InstanceRef, WorkspaceRef } from "@/effect/instance-ref"
5: import { GlobalBus } from "@/bus/global"
6: import { EventV2 } from "@opencode-ai/core/event"
7: import { Location } from "@opencode-ai/core/location"
8: import { Project } from "@opencode-ai/core/project"
9: import { AbsolutePath } from "@opencode-ai/core/schema"
10: import { Context, Effect, Layer } from "effect"
11: 
12: export class Service extends Context.Service<Service, EventV2.Interface>()("@opencode/EventV2Bridge") {}
13: 
14: const layer = Layer.effect(
15:   Service,
16:   Effect.gen(function* () {
17:     const events = yield* EventV2.Service
18: 
19:     const publish: ...
gateway · 2026-09-14 08:18:41
result
Found 100 matches (more matches available)
/home/byk/Code/opencode/packages/sdk/js/src/v2/gen/types.gen.ts:
  Line 15:   | EventMessageUpdated

  Line 16:   | EventMessageRemoved

  Line 17:   | EventMessagePartUpdated

  Line 18:   | EventMessagePartRemoved

  Line 51:   | EventMessagePartDelta

  Line 1607:     | SyncEventMessageUpdated

  Line 1608:     | SyncEventMessageRemoved

  Line 1609:     | SyncEventMessagePartUpdated

  Line 1610:     | SyncEventMessagePartRemoved

  Line 2866:   | MessageUpdated

  Line 2867:   | MessageRemoved

  Line 2868:   | MessagePartUpdated

  Line 2869:   | MessagePartRemoved

  Line 2902:   | MessagePartDelta

  Line 3242: export type SyncEventMessageUpdated = {

  Line 3257: export type SyncEventMessageRemoved = {

  Line 3272: export type SyncEventMessagePartUpdated = {

  Line 3288: export type SyncEventMessagePartRemoved = {

  Line 5149: export type MessageUpdated = {

  Line 5167: export type MessageRemoved = {

  Line 5185: export type ...
gateway · 2026-09-14 08:18:46
result
<path>/home/byk/Code/opencode/packages/core/src/session/projector.ts</path>
<type>file</type>
<content>
1: export * as SessionProjector from "./projector"
2: 
3: import { and, desc, eq, gt, or, sql } from "drizzle-orm"
4: import { DateTime, Effect, Layer, Schema } from "effect"
5: import { Database } from "../database/database"
6: import { EventV2 } from "../event"
7: import { makeGlobalNode } from "../effect/app-node"
8: import { SessionEvent } from "./event"
9: import { SessionV1 } from "../v1/session"
10: import { WorkspaceTable } from "../control-plane/workspace.sql"
11: import { SessionMessage } from "./message"
12: import { SessionMessageUpdater } from "./message-updater"
13: import { SessionInput } from "./input"
14: import { WorkspaceV2 } from "../workspace"
15: import { MessageTable, PartTable, SessionInputTable, SessionMessageTable, SessionTable } from "./sql"
16: import type { DeepMutable } from "../schema"
17: 
18: type DatabaseService = Database.Interface["db"]
19: 
20: ...
gateway · 2026-09-14 08:18:54
result
File not found: /home/byk/Code/opencode/packages/core/src/event/index.ts
gateway · 2026-09-14 08:18:59
result
/home/byk/Code/opencode/packages/core/src/event.ts
/home/byk/Code/opencode/packages/core/src/session/event.ts
gateway · 2026-09-14 08:19:05
result
<path>/home/byk/Code/opencode/packages/core/src/event.ts</path>
<type>file</type>
<content>
1: export * as EventV2 from "./event"
2: 
3: import { Cause, Context, Effect, Layer, Option, PubSub, Queue, Schema, Stream } from "effect"
4: import { Event } from "@opencode-ai/schema/event"
5: import type { Data, Definition, Payload } from "@opencode-ai/schema/event"
6: import { and, asc, eq, gt, inArray } from "drizzle-orm"
7: import { Database } from "./database/database"
8: import { EventSequenceTable, EventTable } from "./event/sql"
9: import { Location } from "./location"
10: import { makeGlobalNode } from "./effect/app-node"
11: import { isDeepStrictEqual } from "node:util"
12: import { Durable } from "@opencode-ai/schema/durable-event-manifest"
13: 
14: export const ID = Event.ID
15: export type ID = import("@opencode-ai/schema/event").ID
16: export type { Data, Definition, Payload } from "@opencode-ai/schema/event"
17: 
18: export type Subscriber<D extends Definition = Definition> = ...
gateway · 2026-09-14 08:19:13
result
<path>/home/byk/Code/opencode/packages/schema/src/v1/session.ts</path>
<type>file</type>
<content>
560:   time: Schema.Struct({
561:     created: NonNegativeInt,
562:     updated: NonNegativeInt,
563:     compacting: optional(NonNegativeInt),
564:     archived: optional(Schema.Finite),
565:   }),
566:   permission: optional(PermissionV1.Ruleset),
567:   revert: optional(SessionRevert),
568: }).annotate({ identifier: "Session" })
569: export type SessionInfo = typeof SessionInfo.Type
570: 
571: const events = {
572:   Created: define({
573:     type: "session.created",
574:     ...options,
575:     schema: {
576:       sessionID: SessionID,
577:       info: SessionInfo,
578:     },
579:   }),
580:   Updated: define({
581:     type: "session.updated",
582:     ...options,
583:     schema: {
584:       sessionID: SessionID,
585:       info: SessionInfo,
586:     },
587:   }),
588:   Deleted: define({
589:     type: "session.deleted",
590:     ...options,
591:     schema: {
592:       ...
gateway · 2026-09-14 08:19:19
result
Found 1 matches
/home/byk/Code/opencode/packages/schema/src/v1/session.ts:
  Line 502: const options = {
gateway · 2026-09-14 08:19:24
result
<path>/home/byk/Code/opencode/packages/schema/src/v1/session.ts</path>
<type>file</type>
<content>
480:     }),
481:   }),
482:   structured: Schema.optional(Schema.Any),
483:   variant: Schema.optional(Schema.String),
484:   finish: Schema.optional(Schema.String),
485: }).annotate({ identifier: "AssistantMessage" })
486: export type Assistant = Omit<Types.DeepMutable<Schema.Schema.Type<typeof Assistant>>, "error"> & {
487:   error?: AssistantError
488: }
489: 
490: export const Info = Schema.Union([User, Assistant]).annotate({ discriminator: "role", identifier: "Message" })
491: export type Info = User | Assistant
492: 
493: export const WithParts = Schema.Struct({
494:   info: Info,
495:   parts: Schema.Array(Part),
496: })
497: export type WithParts = {
498:   info: Info
499:   parts: Part[]
500: }
501: 
502: const options = {
503:   durable: {
504:     aggregate: "sessionID",
505:     version: 1,
506:   },
507: } as const
508: 
509: const SessionSummary = Schema.Struct({
510:   ...
gateway · 2026-09-14 08:19:31
result
<path>/home/byk/Code/opencode/packages/core/src/session/sql.ts</path>
<type>file</type>
<content>
1: import { sqliteTable, text, integer, index, primaryKey, real, uniqueIndex } from "drizzle-orm/sqlite-core"
2: import * as DatabasePath from "../database/path"
3: import { ProjectTable } from "../project/sql"
4: import type { SessionMessage } from "./message"
5: import type { Prompt } from "./prompt"
6: import type { SessionInput } from "./input"
7: import type { Snapshot } from "../snapshot"
8: import { PermissionV1 } from "../v1/permission"
9: import { ProjectV2 } from "../project"
10: import type { SessionSchema } from "./schema"
11: import type { MessageID, PartID, SessionV1 } from "../v1/session"
12: import { WorkspaceV2 } from "../workspace"
13: import { Timestamps } from "../database/schema.sql"
14: import type { SystemContext } from "../system-context/index"
15: import { AgentV2 } from "../agent"
16: import type { Revert } from "@opencode-ai/schema/revert"
17: 
18: type ...
gateway · 2026-09-14 08:19:41
result
Found 2 matches
/home/byk/Code/opencode/packages/opencode/src/session/prompt.ts:
  Line 1343:     const loop: (input: LoopInput) => Effect.Effect<SessionV1.WithParts> = Effect.fn("SessionPrompt.loop")(function* (


/home/byk/Code/opencode/packages/opencode/src/server/routes/instance/httpapi/handlers/session.ts:
  Line 291:       yield* promptSvc.loop({ sessionID: ctx.params.sessionID })
gateway · 2026-09-14 08:19:54
result
Found 30 matches
/home/byk/Code/opencode/packages/opencode/src/effect/app-runtime.ts:
  Line 26: import { SessionRunState } from "@/session/run-state"

  Line 85:     SessionRunState.node,


/home/byk/Code/opencode/packages/opencode/src/session/prompt.ts:
  Line 48: import { SessionRunState } from "./run-state"

  Line 135:     const state = yield* SessionRunState.Service

  Line 1346:       return yield* state.ensureRunning(input.sessionID, lastAssistant(input.sessionID), runLoop(input.sessionID))

  Line 1353:       return yield* state.startShell(input.sessionID, lastAssistant(input.sessionID), shellImpl(input, ready), ready)

  Line 1620:     SessionRunState.node,


/home/byk/Code/opencode/packages/opencode/src/session/revert.ts:
  Line 10: import { SessionRunState } from "./run-state"

  Line 36:     const state = yield* SessionRunState.Service

  Line 133:   deps: [Session.node, Snapshot.node, Storage.node, EventV2Bridge.node, SessionSummary.node, ...
gateway · 2026-09-14 08:20:04
result
Found 2 matches
/home/byk/Code/opencode/packages/opencode/src/cli/cmd/run/session-data.ts:
  Line 526:     // Some models emit a standalone whitespace token before real content.


/home/byk/Code/opencode/packages/opencode/src/server/routes/instance/httpapi/public.ts:
  Line 87:   // of X itself) when the same AST node appears both as a standalone endpoint
gateway · 2026-09-14 08:20:12
result
<path>/home/byk/Code/opencode/packages/opencode/src/background/job.ts</path>
<type>file</type>
<content>
1: import { LayerNode } from "@opencode-ai/core/effect/layer-node"
2: import { BackgroundJob as CoreBackgroundJob } from "@opencode-ai/core/background-job"
3: import { InstanceState } from "@/effect/instance-state"
4: import { Effect, Layer } from "effect"
5: 
6: export {
7:   Service,
8:   type ExtendInput,
9:   type Info,
10:   type Interface,
11:   type StartInput,
12:   type Status,
13:   type WaitInput,
14:   type WaitResult,
15: } from "@opencode-ai/core/background-job"
16: 
17: /** Keeps the legacy service instance-scoped while sharing the core registry engine. */
18: const layer = Layer.effect(
19:   CoreBackgroundJob.Service,
20:   Effect.gen(function* () {
21:     const state = yield* InstanceState.make(() => CoreBackgroundJob.make)
22:     return CoreBackgroundJob.Service.of({
23:       list: () => InstanceState.useEffect(state, (jobs) => jobs.list()),
24:       get: ...
gateway · 2026-09-14 08:20:24
result
<path>/home/byk/Code/opencode/packages/opencode/src/snapshot/index.ts</path>
<type>file</type>
<content>
1: import { LayerNode } from "@opencode-ai/core/effect/layer-node"
2: import { Cause, Duration, Effect, Layer, Schedule, Schema, Semaphore, Context } from "effect"
3: import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process"
4: import { formatPatch, structuredPatch } from "diff"
5: import path from "path"
6: import { AppProcess } from "@opencode-ai/core/process"
7: import { InstanceState } from "@/effect/instance-state"
8: import { FSUtil } from "@opencode-ai/core/fs-util"
9: import { Hash } from "@opencode-ai/core/util/hash"
10: import { Config } from "@/config/config"
11: import { Global } from "@opencode-ai/core/global"
12: import { Info } from "@opencode-ai/schema/file-diff"
13: 
14: export const Patch = Schema.Struct({
15:   hash: Schema.String,
16:   files: Schema.mutable(Schema.Array(Schema.String)),
17: })
18: export type Patch = typeof Patch.Type
19: 
20: ...
gateway · 2026-09-14 08:20:36
result
<path>/home/byk/Code/opencode/packages/opencode/src/effect/app-runtime.ts</path>
<type>file</type>
<content>
1: import { Layer, ManagedRuntime } from "effect"
2: import { attach } from "./run-service"
3: import * as Observability from "@opencode-ai/core/observability"
4: 
5: import { FSUtil } from "@opencode-ai/core/fs-util"
6: import { Database } from "@opencode-ai/core/database/database"
7: import { Auth } from "@/auth"
8: import { Account } from "@/account/account"
9: import { Config } from "@/config/config"
10: import { Git } from "@/git"
11: import { Ripgrep } from "@opencode-ai/core/ripgrep"
12: import { Storage } from "@/storage/storage"
13: import { Snapshot } from "@/snapshot"
14: import { Plugin } from "@/plugin"
15: import { ModelsDev } from "@opencode-ai/core/models-dev"
16: import { Provider } from "@/provider/provider"
17: import { ProviderAuth } from "@/provider/auth"
18: import { Agent } from "@/agent/agent"
19: import { Skill } from "@/skill"
20: import { Discovery } ...
gateway · 2026-09-14 08:20:42
result
<path>/home/byk/Code/opencode/packages/core/src/database/database.ts</path>
<type>file</type>
<content>
1: export * as Database from "./database"
2: 
3: import { EffectDrizzleSqlite } from "@opencode-ai/effect-drizzle-sqlite"
4: import { layer as sqliteLayer } from "#sqlite"
5: import { Context, Effect, Layer } from "effect"
6: import { Global } from "../global"
7: import { Flag } from "../flag/flag"
8: import { isAbsolute, join } from "path"
9: import { DatabaseMigration } from "./migration"
10: import { InstallationChannel } from "../installation/version"
11: import { makeGlobalNode } from "../effect/app-node"
12: 
13: const makeDatabase = EffectDrizzleSqlite.makeWithDefaults()
14: type DatabaseShape = Effect.Success<typeof makeDatabase>
15: 
16: export interface Interface {
17:   db: DatabaseShape
18: }
19: 
20: export class Service extends Context.Service<Service, Interface>()("@opencode/v2/storage/Database") {}
21: 
22: const layer = Layer.effect(
23:   Service,
24:   ...
gateway · 2026-09-14 08:20:52
result
<path>/home/byk/Code/opencode/packages/opencode/src/session/prompt.ts</path>
<type>file</type>
<content>
1410: 
1411:       const taskModel = yield* Effect.gen(function* () {
1412:         if (cmd.model) return Provider.parseModel(cmd.model)
1413:         if (cmd.agent) {
1414:           const cmdAgent = yield* agents.get(cmd.agent)
1415:           if (cmdAgent?.model) return cmdAgent.model
1416:         }
1417:         if (input.model) return Provider.parseModel(input.model)
1418:         return yield* currentModel(input.sessionID)
1419:       })
1420: 
1421:       yield* getModel(taskModel.providerID, taskModel.modelID, input.sessionID)
1422: 
1423:       const agent = agentName ? yield* agents.get(agentName) : yield* agents.defaultInfo()
1424:       if (!agent) {
1425:         const available = (yield* agents.list()).filter((a) => !a.hidden).map((a) => a.name)
1426:         const hint = available.length ? ` Available agents: ${available.join(", ")}` : ""
1427:         const error = ...
gateway · 2026-09-14 08:21:03
result
Found 3 matches
/home/byk/Code/opencode/packages/opencode/src/session/message-v2.ts:
  Line 292:           if (part.state.status === "completed") {

  Line 325:           if (part.state.status === "error") {

  Line 351:           if (part.state.status === "pending" || part.state.status === "running")
gateway · 2026-09-14 08:21:08
result
<path>/home/byk/Code/opencode/packages/opencode/src/session/message-v2.ts</path>
<type>file</type>
<content>
230:             type: "text",
231:             text: "What did we do so far?",
232:           })
233:         }
234:         if (part.type === "subtask") {
235:           userMessage.parts.push({
236:             type: "text",
237:             text: "The following tool was executed by the user",
238:           })
239:         }
240:       }
241:       if (userMessage.parts.length > 0) result.push(userMessage)
242:     }
243: 
244:     if (msg.info.role === "assistant") {
245:       const differentModel = `${model.providerID}/${model.id}` !== `${msg.info.providerID}/${msg.info.modelID}`
246:       const media: Array<{ mime: string; url: string; filename?: string }> = []
247: 
248:       if (
249:         msg.info.error &&
250:         !(
251:           AbortedError.isInstance(msg.info.error) &&
252:           msg.parts.some((part) => part.type !== "step-start" && part.type !== ...
gateway · 2026-09-14 08:21:24
result
<path>/home/byk/Code/opencode/packages/opencode/src/cli/effect-cmd.ts</path>
<type>file</type>
<content>
1: import type { Argv } from "yargs"
2: import { Effect, Schema } from "effect"
3: import type { AppServices } from "@/effect/app-runtime"
4: import type { InstanceStore } from "@/project/instance-store"
5: import { cmd, type WithDoubleDash } from "./cmd/cmd"
6: 
7: /**
8:  * User-visible command failure. Throw via `fail("...")` from an effectCmd handler
9:  * to surface a printed message + non-zero exit. Recognised by the global error
10:  * formatter in `src/cli/error.ts` (FormatError), so the existing top-level
11:  * catch + cleanup in `src/index.ts` runs normally.
12:  */
13: export class CliError extends Schema.TaggedErrorClass<CliError>()("CliError", {
14:   message: Schema.String,
15:   exitCode: Schema.optional(Schema.Number),
16: }) {}
17: 
18: export const fail = (message: string, exitCode = 1) => Effect.fail(new CliError({ message, exitCode }))
19: 
20: interface ...
gateway · 2026-09-14 08:21:40
result
<path>/home/byk/Code/opencode/packages/opencode/src/index.ts</path>
<type>file</type>
<content>
1: import yargs from "yargs"
2: import { hideBin } from "yargs/helpers"
3: import { RunCommand } from "./cli/cmd/run"
4: import { GenerateCommand } from "./cli/cmd/generate"
5: import { ConsoleCommand } from "./cli/cmd/account"
6: import { ProvidersCommand } from "./cli/cmd/providers"
7: import { AgentCommand } from "./cli/cmd/agent"
8: import { UpgradeCommand } from "./cli/cmd/upgrade"
9: import { UninstallCommand } from "./cli/cmd/uninstall"
10: import { ModelsCommand } from "./cli/cmd/models"
11: import { UI } from "./cli/ui"
12: import { InstallationVersion } from "@opencode-ai/core/installation/version"
13: import { FormatError } from "./cli/error"
14: import { ServeCommand } from "./cli/cmd/serve"
15: import { DebugCommand } from "./cli/cmd/debug"
16: import { StatsCommand } from "./cli/cmd/stats"
17: import { McpCommand } from "./cli/cmd/mcp"
18: import { GithubCommand } from ...
gateway · 2026-09-14 08:21:49
result
Found 11 matches
/home/byk/Code/opencode/packages/opencode/src/session/prompt.ts:
  Line 99:   return part.state.status === "error" && part.state.metadata?.interrupted === true

  Line 1105:           // the model, but ignore cleanup-marked interrupted orphans.

  Line 1117:             const orphan = lastAssistantMsg?.parts.find(

  Line 1120:             if (orphan) {

  Line 1121:               yield* Effect.logWarning("loop exit with orphaned interrupted tool", {

  Line 1124:                 tool: orphan.tool,

  Line 1125:                 callID: orphan.callID,


/home/byk/Code/opencode/packages/opencode/src/session/processor.ts:
  Line 295:             // Match dev: silently drop orphan deltas (no preceding reasoning-start).

  Line 603:               metadata: { ...metadata, interrupted: true },


/home/byk/Code/opencode/packages/opencode/src/session/message-v2.ts:
  Line 326:             const output = part.state.metadata?.interrupted === true ? part.state.metadata.output : ...
gateway · 2026-09-14 08:22:12
result
<path>/home/byk/Code/opencode/packages/opencode/src/effect/instance-state.ts</path>
<type>file</type>
<content>
1: import { Effect, ScopedCache, Scope } from "effect"
2: import type { InstanceContext } from "@/project/instance-context"
3: import { InstanceRef, WorkspaceRef } from "./instance-ref"
4: import { registerDisposer } from "./instance-registry"
5: import { WorkspaceContext } from "@/control-plane/workspace-context"
6: 
7: const TypeId = "~opencode/InstanceState"
8: 
9: export interface InstanceState<A, E = never, R = never> {
10:   readonly [TypeId]: typeof TypeId
11:   readonly cache: ScopedCache.ScopedCache<string, A, E, R>
12: }
13: 
14: export const context = Effect.gen(function* () {
15:   const ctx = yield* InstanceRef
16:   if (!ctx) return yield* Effect.die(new Error("InstanceRef not provided"))
17:   return ctx
18: })
19: 
20: export const workspaceID = Effect.gen(function* () {
21:   return (yield* WorkspaceRef) ?? WorkspaceContext.workspaceID
22: })
23: 
24: export ...
gateway · 2026-09-14 08:22:18
result
<path>/home/byk/Code/opencode/packages/core/src/effect/app-node-builder.ts</path>
<type>file</type>
<content>
1: import { buildLocationServiceMap } from "../location-services"
2: import { LocationServiceMap } from "../location-service-map"
3: import { LayerNode } from "./layer-node"
4: import { makeGlobalNode } from "./app-node"
5: 
6: export function build<A, E>(root: LayerNode.Node<A, E, any>, replacements: LayerNode.Replacements = []) {
7:   let allReplacements = replacements
8: 
9:   // Only build the location service map if it's actually needed
10:   if (LayerNode.hasUnbound(root, LocationServiceMap.node) && !hasReplacement(replacements, LocationServiceMap.node)) {
11:     const locationMap = buildLocationServiceMap(replacements)
12:     const locationMapNode = makeGlobalNode({ service: LocationServiceMap.Service, layer: locationMap, deps: [] })
13:     allReplacements = replacements.concat([[LocationServiceMap.node, locationMapNode]])
14:   }
15: 
16:   return ...
gateway · 2026-09-14 08:22:55
result
<path>/home/byk/Code/opencode/packages/opencode/src/session/retry.ts</path>
<type>file</type>
<content>
1: import type { NamedError } from "@opencode-ai/core/util/error"
2: import { SessionV1 } from "@opencode-ai/core/v1/session"
3: import { Cause, Clock, Duration, Effect, Schedule } from "effect"
4: import { MessageV2 } from "./message-v2"
5: import { iife } from "@/util/iife"
6: import { isRecord } from "@/util/record"
7: 
8: export type Err = ReturnType<NamedError["toObject"]>
9: 
10: export const GO_UPSELL_MESSAGE = "Free usage exceeded, subscribe to Go"
11: export const GO_UPSELL_URL = "https://opencode.ai/go"
12: export type RetryReason = "free_tier_limit" | "account_rate_limit" | (string & {})
13: 
14: export type Retryable = {
15:   message: string
16:   action?: {
17:     reason: RetryReason
18:     provider: string
19:     title: string
20:     message: string
21:     label: string
22:     link?: string
23:   }
24: }
25: 
26: export const RETRY_INITIAL_DELAY = 2000
27: ...
gateway · 2026-09-14 08:23:08
result
<path>/home/byk/Code/opencode/packages/opencode/src/server/routes/instance/httpapi/lifecycle.ts</path>
<type>file</type>
<content>
1: import { EffectBridge } from "@/effect/bridge"
2: import type { InstanceContext } from "@/project/instance-context"
3: import { InstanceStore } from "@/project/instance-store"
4: import { Effect } from "effect"
5: import { HttpEffect, HttpMiddleware, HttpServerRequest } from "effect/unstable/http"
6: 
7: type MarkedInstance = {
8:   ctx: InstanceContext
9:   store: InstanceStore.Interface
10:   bridge: EffectBridge.Shape
11: }
12: 
13: // Disposal is requested by an endpoint handler, but must run from the outer
14: // server middleware after the response has been produced. The original Request
15: // object is the stable handoff key between those two phases.
16: const disposeAfterResponse = new WeakMap<object, MarkedInstance>()
17: 
18: const mark = (ctx: InstanceContext) =>
19:   Effect.gen(function* () {
20:     return { ctx, store: yield* ...
gateway · 2026-09-14 08:23:21
result
Found 1 matches
/home/byk/Code/opencode/packages/opencode/script/build-node.ts:
  Line 16:   target: "node",
gateway · 2026-09-14 08:23:28
result
<path>/home/byk/Code/opencode/packages/opencode/script/build-node.ts</path>
<type>file</type>
<content>
1: #!/usr/bin/env bun
2: 
3: import { Script } from "@opencode-ai/script"
4: import path from "path"
5: import { fileURLToPath } from "url"
6: 
7: const __filename = fileURLToPath(import.meta.url)
8: const __dirname = path.dirname(__filename)
9: const dir = path.resolve(__dirname, "..")
10: 
11: process.chdir(dir)
12: 
13: const generated = await import("./generate.ts")
14: 
15: await Bun.build({
16:   target: "node",
17:   entrypoints: ["./src/node.ts"],
18:   outdir: "./dist/node",
19:   format: "esm",
20:   sourcemap: "linked",
21:   external: ["jsonc-parser", "@lydell/node-pty"],
22:   define: {
23:     OPENCODE_MODELS_DEV: generated.modelsData,
24:     OPENCODE_VERSION: `'${Script.version}'`,
25:     OPENCODE_CHANNEL: `'${Script.channel}'`,
26:   },
27:   files: {
28:     "opencode-web-ui.gen.ts": "",
29:   },
30: })
31: 
32: console.log("Build complete")

(End of file - total ...
gateway · 2026-09-14 08:23:34
result
<path>/home/byk/Code/opencode/packages/opencode/src/node.ts</path>
<type>file</type>
<content>
1: export { Config } from "@/config/config"
2: export { Server } from "./server/server"
3: export { bootstrap } from "./cli/bootstrap"
4: export { Database } from "@opencode-ai/core/database/database"

(End of file - total 4 lines)
</content>
gateway · 2026-09-14 08:23:45
result
<path>/home/byk/Code/opencode/packages/core/src/effect/layer-node.ts</path>
<type>file</type>
<content>
1: import { Brand, Context, Layer } from "effect"
2: 
3: type AnyNode = Node<unknown, unknown, any>
4: type RuntimeLayer = Layer.Layer<never, unknown, unknown>
5: type NodeList<Item extends AnyNode = AnyNode> = readonly [] | readonly [Item, ...Item[]]
6: export type Output<Item> = [Item] extends [never] ? never : Item extends Node<infer A, unknown, any> ? A : never
7: export type Error<Item> = [Item] extends [never] ? never : Item extends Node<unknown, infer E, any> ? E : never
8: type NodeTag<Item> = [Item] extends [never] ? undefined : Item extends Node<unknown, unknown, infer T> ? T : never
9: type Missing<Required, Dependencies extends NodeList> = Exclude<Required, Output<Dependencies[number]>>
10: type CheckDependencies<Implementation extends Layer.Any, Dependencies extends NodeList> = [
11:   Missing<Layer.Services<Implementation>, Dependencies>,
12: ] extends [never]
13:   ? ...
gateway · 2026-09-14 08:23:54
result
<path>/home/byk/Code/opencode/packages/opencode/src/cli/bootstrap.ts</path>
<type>file</type>
<content>
1: import { InstanceRuntime } from "../project/instance-runtime"
2: import { context } from "../project/instance-context"
3: 
4: export async function bootstrap<T>(directory: string, cb: () => Promise<T>) {
5:   const ctx = await InstanceRuntime.load({ directory })
6:   try {
7:     return await context.provide(ctx, cb)
8:   } finally {
9:     await InstanceRuntime.disposeInstance(ctx)
10:   }
11: }

(End of file - total 11 lines)
</content>
gateway · 2026-09-14 08:24:05
result
<path>/home/byk/Code/opencode/packages/core/src/event/sql.ts</path>
<type>file</type>
<content>
1: import { sqliteTable, text, integer, index, uniqueIndex } from "drizzle-orm/sqlite-core"
2: import type { EventV2 } from "../event"
3: 
4: export const EventSequenceTable = sqliteTable("event_sequence", {
5:   aggregate_id: text().notNull().primaryKey(),
6:   seq: integer().notNull(),
7:   owner_id: text(),
8: })
9: 
10: export const EventTable = sqliteTable(
11:   "event",
12:   {
13:     id: text().$type<EventV2.ID>().primaryKey(),
14:     aggregate_id: text()
15:       .notNull()
16:       .references(() => EventSequenceTable.aggregate_id, { onDelete: "cascade" }),
17:     seq: integer().notNull(),
18:     type: text().notNull(),
19:     data: text({ mode: "json" }).$type<Record<string, unknown>>().notNull(),
20:   },
21:   (table) => [
22:     uniqueIndex("event_aggregate_seq_idx").on(table.aggregate_id, table.seq),
23:     index("event_aggregate_type_seq_idx").on(table.aggregate_id, ...
gateway · 2026-09-14 08:24:11
result
Found 3 matches
/home/byk/Code/opencode/packages/core/src/event.ts:
  Line 179:       const projectors = new Map<string, Subscriber[]>()

  Line 320:                           for (const projector of list) {

  Line 615:       const project = <D extends Definition>(definition: D, projector: Subscriber<D>): Effect.Effect<void> =>
gateway · 2026-09-14 08:24:20
result
<path>/home/byk/Code/opencode/packages/core/src/event.ts</path>
<type>file</type>
<content>
410:             (listener) => (isolateListeners ? observe(event, listener) : listener(event)),
411:             { discard: true },
412:           )
413:           const typed = pubsub.typed.get(event.type)
414:           if (typed) yield* PubSub.publish(typed, event)
415:           yield* PubSub.publish(pubsub.all, event)
416:         })
417:       }
418: 
419:       function publish<D extends Definition>(definition: D, data: Data<D>, options?: PublishOptions) {
420:         return Effect.gen(function* () {
421:           const serviceLocation = Option.getOrUndefined(yield* Effect.serviceOption(Location.Service))
422:           const location =
423:             options?.location ??
424:             (serviceLocation
425:               ? { directory: serviceLocation.directory, workspaceID: serviceLocation.workspaceID }
426:               : undefined)
427:           return yield* ...
gateway · 2026-09-14 08:24:28
result
Found 1 matches
/home/byk/Code/opencode/packages/opencode/src/session/message-v2.ts:
  Line 582: export function latest(msgs: WithParts[]) {
gateway · 2026-09-14 08:24:34
result
<path>/home/byk/Code/opencode/packages/opencode/src/session/message-v2.ts</path>
<type>file</type>
<content>
550:   const compaction = result[compactionIndex]
551:   const part = compaction?.parts.find(
552:     (item): item is CompactionPart => item.type === "compaction" && item.tail_start_id !== undefined,
553:   )
554:   const summaryIndex = compaction
555:     ? result.findIndex(
556:         (msg, index) =>
557:           index > compactionIndex &&
558:           msg.info.role === "assistant" &&
559:           msg.info.summary &&
560:           msg.info.parentID === compaction.info.id,
561:       )
562:     : -1
563:   const tailIndex = part?.tail_start_id ? result.findIndex((msg) => msg.info.id === part.tail_start_id) : -1
564:   if (tailIndex >= 0 && tailIndex < compactionIndex && summaryIndex > compactionIndex) {
565:     return [
566:       ...result.slice(compactionIndex, summaryIndex + 1),
567:       ...result.slice(tailIndex, compactionIndex),
568:       ...
gateway · 2026-09-14 08:24:47
result
<path>/home/byk/Code/opencode/packages/opencode/src/server/routes/instance/httpapi/groups/session.ts</path>
<type>file</type>
<content>
50:   title: Schema.optional(Schema.String),
51:   metadata: Schema.optional(Session.Metadata),
52:   permission: Schema.optional(PermissionV1.Ruleset),
53:   time: Schema.optional(
54:     Schema.Struct({
55:       archived: Schema.optional(Session.ArchivedTimestamp),
56:     }),
57:   ),
58: })
59: export const ForkPayload = Schema.Struct(Struct.omit(Session.ForkInput.fields, ["sessionID"]))
60: export const InitPayload = Schema.Struct({
61:   modelID: ModelV2.ID,
62:   providerID: ProviderV2.ID,
63:   messageID: MessageID,
64: })
65: export const SummarizePayload = Schema.Struct({
66:   providerID: ProviderV2.ID,
67:   modelID: ModelV2.ID,
68:   auto: Schema.optional(Schema.Boolean),
69: })
70: export const PromptPayload = Schema.Struct(Struct.omit(SessionPrompt.PromptInput.fields, ["sessionID"]))
71: export const CommandPayload = ...
gateway · 2026-09-14 08:25:19
result
<path>/home/byk/Code/opencode/packages/opencode/src/effect/instance-registry.ts</path>
<type>file</type>
<content>
1: const disposers = new Set<(directory: string) => Promise<void>>()
2: 
3: export function registerDisposer(disposer: (directory: string) => Promise<void>) {
4:   disposers.add(disposer)
5:   return () => {
6:     disposers.delete(disposer)
7:   }
8: }
9: 
10: export async function disposeInstance(directory: string) {
11:   await Promise.allSettled([...disposers].map((disposer) => disposer(directory)))
12: }

(End of file - total 12 lines)
</content>
gateway · 2026-09-14 08:25:32
result
Found 1 matches
/home/byk/Code/opencode/packages/opencode/src/control-plane/workspace.ts:
  Line 589:             yield* events.claim(input.sessionID, input.workspaceID ?? previous.projectID)
gateway · 2026-09-14 08:25:50
result
<path>/home/byk/Code/opencode/packages/opencode/src/permission/index.ts</path>
<type>file</type>
<content>
1: import { LayerNode } from "@opencode-ai/core/effect/layer-node"
2: import { ConfigPermissionV1 } from "@opencode-ai/core/v1/config/permission"
3: import { InstanceState } from "@/effect/instance-state"
4: import { Wildcard } from "@opencode-ai/core/util/wildcard"
5: import { Deferred, Effect, Layer, Context } from "effect"
6: import os from "os"
7: import { PermissionV1 } from "@opencode-ai/core/v1/permission"
8: import { EventV2Bridge } from "@/event-v2-bridge"
9: 
10: export const Event = PermissionV1.Event
11: 
12: export interface Interface {
13:   readonly ask: (input: PermissionV1.AskInput) => Effect.Effect<void, PermissionV1.Error>
14:   readonly reply: (input: PermissionV1.ReplyInput) => Effect.Effect<void, PermissionV1.NotFoundError>
15:   readonly list: () => Effect.Effect<ReadonlyArray<PermissionV1.Request>>
16: }
17: 
18: interface PendingEntry {
19:   info: ...
gateway · 2026-09-14 08:25:56
result
No files found
gateway · 2026-09-14 08:26:05
result
/home/byk/Code/opencode/packages/schema/src/v1/permission.ts
/home/byk/Code/opencode/packages/core/src/v1/permission.ts
gateway · 2026-09-14 08:26:12
result
<path>/home/byk/Code/opencode/packages/schema/src/v1/permission.ts</path>
<type>file</type>
<content>
1: export * as PermissionV1 from "./permission"
2: 
3: import { Schema } from "effect"
4: import { define, inventory } from "../event"
5: import { ascending } from "../identifier"
6: import { Project } from "../project"
7: import { statics } from "../schema"
8: import { SessionID } from "../session-id"
9: 
10: export const ID = Schema.String.check(Schema.isStartsWith("per")).pipe(
11:   Schema.brand("PermissionID"),
12:   statics((schema) => ({ ascending: (id?: string) => schema.make(id ?? "per_" + ascending()) })),
13: )
14: export type ID = typeof ID.Type
15: 
16: export const Action = Schema.Literals(["allow", "deny", "ask"]).annotate({ identifier: "PermissionAction" })
17: export type Action = typeof Action.Type
18: 
19: export const Rule = Schema.Struct({ permission: Schema.String, pattern: Schema.String, action: Action }).annotate({
20:   identifier: "PermissionRule",
21: })
22: ...
gateway · 2026-09-14 08:28:17

Verdict

The Node standalone build exports the legacy server from /home/byk/Code/opencode/packages/opencode/src/node.ts:1-4; its build entry is /home/byk/Code/opencode/packages/opencode/script/build-node.ts:15-21.

Legacy V1 preserves the transcript, but not the execution. Safe automatic restart recovery does not exist. After restart, every session appears idle, no startup hook resumes work, and rerunning an uncertain provider Step or tool can duplicate calls and side effects.

Execution lifecycle

  1. Server.listen() builds the Node HTTP listener and the complete route/service graph
    /home/byk/Code/opencode/packages/opencode/src/server/server.ts:73-97
    /home/byk/Code/opencode/packages/opencode/src/server/server.ts:100-138

  2. An instance-routed request lazily loads its directory and runs InstanceBootstrap.run
    /home/byk/Code/opencode/packages/opencode/src/server/routes/instance/httpapi/middleware/instance-context.ts:23-34
    /home/byk/Code/opencode/packages/opencode/src/project/instance-store.ts:45-63

  3. Bootstrap loads config, initializes plugins first, then initializes LSP, sharing, formatting, VCS, snapshots, and project services concurrently. It does not inspect or resume sessions
    /home/byk/Code/opencode/packages/opencode/src/project/bootstrap.ts:32-46

  4. POST /session/:sessionID/message calls SessionPrompt.prompt; prompt_async forks the same operation into the listener scope and returns immediately
    /home/byk/Code/opencode/packages/opencode/src/server/routes/instance/httpapi/groups/session.ts:78-105
    /home/byk/Code/opencode/packages/opencode/src/server/routes/instance/httpapi/handlers/session.ts:295-329

  5. SessionPrompt.prompt:

    • resolves files/resources and runs plugin hooks;
    • persists the user message, then each part separately;
    • touches the session;
    • optionally replaces session permissions from the deprecated tools field;
    • returns immediately for noReply, otherwise ...
gpt-5.6-sol · 2026-09-14 08:28:17 · ~2.9K tokens

Distillations (14)

Gen 0 2026-09-14 09:20:38 · 2730 tokens

Date: Sep 14, 2026 * 🔴 (08:28) `/home/byk/Code/opencode/packages/schema/src/v1/permission.ts` defines `ID` as a branded string beginning with `"per"` and adds `ID.ascending(id?)`, which uses the supplied ID or generates `"per_" + ascending()`. * 🔴 (08:28) `/home/byk/Code/opencode/packages/schema/src/v1/permission.ts` defines `Action` as `"allow" | "deny" | "ask"`; `Rule` as `{ permission: strin…

Gen 0 2026-09-14 09:19:41 · 1171 tokens

Date: Sep 14, 2026 * 🔴 (08:25) `/home/byk/Code/opencode/packages/opencode/src/effect/instance-registry.ts` maintains `disposers` as `Set<(directory: string) => Promise<void>>`; `registerDisposer()` adds a disposer and returns a callback that removes it, while `disposeInstance(directory)` invokes every registered disposer concurrently through `Promise.allSettled(...)`, so individual rejections do…

Gen 0 2026-09-14 09:07:32 · 2159 tokens

* 🔴 (08:22) `/home/byk/Code/opencode/packages/core/src/effect/app-node-builder.ts` defines `build<A, E>(root: LayerNode.Node<A, E, any>, replacements: LayerNode.Replacements = [])`; it lazily builds `LocationServiceMap` only when `LayerNode.hasUnbound(root, LocationServiceMap.node)` and no replacement with the same `node.name` exists, then calls `LayerNode.compile(root, allReplacements)`. * 🔴 (…

Gen 0 2026-09-14 08:54:47 · 710 tokens

* 🟡 (08:22) Search found 11 references related to interrupted/orphan tool execution: `/home/byk/Code/opencode/packages/opencode/src/session/prompt.ts` lines 99, 1105, 1117, 1120, 1121, 1124, and 1125; `/home/byk/Code/opencode/packages/opencode/src/session/processor.ts` lines 295 and 603; `/home/byk/Code/opencode/packages/opencode/src/session/message-v2.ts` lines 326 and 357. * 🟡 (08:22) `/home/…

Gen 0 2026-09-14 08:54:27 · 807 tokens

* 🟡 (08:21) `/home/byk/Code/opencode/packages/opencode/src/index.ts` is the CLI entry point. It derives `args` with `hideBin(process.argv)` and configures yargs with `.parserConfiguration({ "populate--": true })`, `.scriptName("opencode")`, `.wrap(100)`, help aliases `help`/`h`, version aliases `version`/`v`, and `InstallationVersion`. * 🟡 (08:21) The `show(out: string)` helper in `/home/byk/Co…

Gen 0 2026-09-14 08:54:08 · 4321 tokens

* 🟡 (08:19) `/home/byk/Code/opencode/packages/schema/src/v1/session.ts` defines `SessionSummary` with finite `additions`, `deletions`, and `files`, plus optional `diffs: Schema.Array(FileDiff.Info)`; `SessionTokens` has finite `input`, `output`, `reasoning`, and cache `read`/`write`; `SessionShare` has `url: Schema.String`. * 🟡 (08:19) `/home/byk/Code/opencode/packages/core/src/session/sql.ts` …

Gen 0 2026-09-14 08:48:37 · 1335 tokens

* 🔴 (08:18) User established the invariant: “never resume an older assistant projection”; a newer turn supersedes stale incomplete rows. * 🟡 (08:18) `/home/byk/Code/opencode/packages/opencode/src/server/init-projectors.ts` imports `initProjectors` from `./projectors` and immediately invokes `initProjectors()`. * 🟡 (08:18) `/home/byk/Code/opencode/packages/opencode/src/server/projectors.ts` cur…

Gen 0 2026-09-14 08:44:53 · 1364 tokens

* 🟡 (08:17) `packages/opencode/src/session/llm.ts` defines `stream(input)` as a scoped stream: it acquires an `AbortController`, aborts it on scope release, and invokes `run({ ...input, abort: ctrl.signal })`. * 🟡 (08:17) The LLM runtime adapter seam exposes both execution paths as the same `LLMEvent` stream. A result with `type === "native"` returns `result.stream` directly; otherwise `result.…

Gen 0 2026-09-14 08:39:33 · 3178 tokens

* 🟡 (08:16) `packages/opencode/src/session/run-state.ts` defines `SessionRunState.Interface` with `assertNotBusy(sessionID)`, `cancel(sessionID)`, `ensureRunning(sessionID, onInterrupt, work)`, and `startShell(sessionID, onInterrupt, work, ready?)`; `startShell(...)` may fail with `Session.BusyError`. * 🟡 (08:16) `SessionRunState.Service` is registered as `"@opencode/SessionRunState"` and its l…

Gen 0 2026-09-14 08:32:48 · 1491 tokens

* 🟡 (08:16) `packages/opencode/src/session/prompt.ts` defines MCP helpers `mcpResourceBase64Size(value: string)`, `formatMcpResourceBytes(value: number)`, and `isOrphanedInterruptedTool(part: SessionV1.ToolPart)`; `formatMcpResourceBytes(...)` formats bytes as `${Math.ceil(value / (1024 * 1024))} MB`. * 🟡 (08:16) `isOrphanedInterruptedTool(...)` distinguishes interrupted tool parts that are no …

Gen 0 2026-09-14 08:24:47 · 2095 tokens

Date: Sep 14, 2026 * 🔴 (08:15) User stated `OpenApi.fromApi` is non-trivial and should be deferred until `/doc` is requested, so processes that never serve it—CLI and scripts—do not pay the cost at module load. * 🔴 (08:15) User specified that normal HTTP endpoints, including streaming HTTP responses such as server-sent events, should use `HttpApiBuilder.group(...)`; handlers should yield stable…

Gen 0 2026-09-14 08:16:34 · 939 tokens

Date: Sep 14, 2026 * 🟡 (08:15) `packages/opencode/src/server/server.ts` line 1 imports `./init-projectors` as a startup side effect before other imports; the file itself contains no explicit session-continuation or busy-session recovery hook. * 🟡 (08:15) `packages/opencode/src/server/server.ts` defines `listen(opts)` by running `listenEffect(opts)` with `Effect.runPromise`; `listenEffect` start…

Gen 0 2026-09-14 08:16:12 · 1492 tokens

Date: Sep 14, 2026 * 🔴 (08:14) User supplied repository type-checking directive for `/home/byk/Code/opencode`: always run `bun typecheck` from package directories such as `packages/opencode`; never run `tsc` directly. * 🔴 (08:14) User supplied repository runtime dependency rule: dependencies flow from Schema to Core and Protocol, then from Core and Protocol to Server; Client runtime code may de…

Gen 0 2026-09-14 08:15:27 · 157 tokens

Date: Sep 14, 2026 * 🔴 [requested-research-only] (08:13) User instructed research only and no file edits in /home/byk/Code/opencode. * 🟡 (08:13) User asked for a very thorough trace of the current v1/legacy session execution lifecycle used by the Node standalone server in /home/byk/Code/opencode, covering: durable state for an in-progress prompt; startup hooks; representation of active/busy ses…