GeezerVison is showing github.com — Refactor to support multiple instances inside single opencode process… · fsinbad/opencode@f993541
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: AGENTS.md +4Lines changed: 4 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| 10 | 10 | - AVOID `let` statements | 11 | 11 | - PREFER single word variable names where possible | 12 | 12 | - Use as many bun apis as possible like Bun.file() | | 13 | + | | 14 | +## Debugging | | 15 | + | | 16 | +- To test opencode in the `packages/opencode` directory you can run `bun dev` |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/agent/agent.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { App } from "../app/app" | 2 | 1 | import { Config } from "../config/config" | 3 | 2 | import z from "zod" | 4 | 3 | import { Provider } from "../provider/provider" | 5 | 4 | import { generateObject, type ModelMessage } from "ai" | 6 | 5 | import PROMPT_GENERATE from "./generate.txt" | 7 | 6 | import { SystemPrompt } from "../session/system" | | 7 | +import { Instance } from "../project/instance" | 8 | 8 | import { mergeDeep } from "remeda" | 9 | 9 |
| 10 | 10 | export namespace Agent { | @@ -36,7 +36,7 @@ export namespace Agent { | 36 | 36 | }) | 37 | 37 | export type Info = z.infer<typeof Info> | 38 | 38 |
| 39 | | - const state = App.state("agent", async () => { | | 39 | + const state = Instance.state(async () => { | 40 | 40 | const cfg = await Config.get() | 41 | 41 | const defaultTools = cfg.tools ?? {} | 42 | 42 | const defaultPermission: Info["permission"] = { | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/app/app.ts -147Lines changed: 0 additions & 147 deletions Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/bus/index.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { z, type ZodType } from "zod" | 2 | | -import { App } from "../app/app" | 3 | 2 | import { Log } from "../util/log" | | 3 | +import { Instance } from "../project/instance" | 4 | 4 |
| 5 | 5 | export namespace Bus { | 6 | 6 | const log = Log.create({ service: "bus" }) | 7 | 7 | type Subscription = (event: any) => void | 8 | 8 |
| 9 | | - const state = App.state("bus", () => { | | 9 | + const state = Instance.state(() => { | 10 | 10 | const subscriptions = new Map<any, Subscription[]>() | 11 | 11 |
| 12 | 12 | return { | |
Collapse file Copy file name to clipboard +6-7Lines changed: 6 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { App } from "../app/app" | 2 | | -import { ConfigHooks } from "../config/hooks" | 3 | 1 | import { Format } from "../format" | 4 | 2 | import { LSP } from "../lsp" | 5 | 3 | import { Plugin } from "../plugin" | | 4 | +import { Instance } from "../project/instance" | 6 | 5 | import { Share } from "../share/share" | 7 | 6 | import { Snapshot } from "../snapshot" | 8 | 7 |
| 9 | | -export async function bootstrap<T>(input: App.Input, cb: (app: App.Info) => Promise<T>) { | 10 | | - return App.provide(input, async (app) => { | | 8 | +export async function bootstrap<T>(directory: string, cb: () => Promise<T>) { | | 9 | + return Instance.provide(directory, async () => { | 11 | 10 | await Plugin.init() | 12 | 11 | Share.init() | 13 | 12 | Format.init() | 14 | | - ConfigHooks.init() | 15 | 13 | LSP.init() | 16 | 14 | Snapshot.init() | 17 | | - | 18 | | - return cb(app) | | 15 | + const result = await cb() | | 16 | + await Instance.dispose() | | 17 | + return result | 19 | 18 | }) | 20 | 19 | } |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/agent.ts +6-5Lines changed: 6 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,25 +5,26 @@ import { Global } from "../../global" | 5 | 5 | import { Agent } from "../../agent/agent" | 6 | 6 | import path from "path" | 7 | 7 | import matter from "gray-matter" | 8 | | -import { App } from "../../app/app" | | 8 | +import { Instance } from "../../project/instance" | 9 | 9 |
| 10 | 10 | const AgentCreateCommand = cmd({ | 11 | 11 | command: "create", | 12 | 12 | describe: "create a new agent", | 13 | 13 | async handler() { | 14 | | - await App.provide({ cwd: process.cwd() }, async (app) => { | | 14 | + await Instance.provide(process.cwd(), async () => { | 15 | 15 | UI.empty() | 16 | 16 | prompts.intro("Create agent") | | 17 | + const project = Instance.project | 17 | 18 |
| 18 | 19 | let scope: "global" | "project" = "global" | 19 | | - if (app.git) { | | 20 | + if (project.vcs === "git") { | 20 | 21 | const scopeResult = await prompts.select({ | 21 | 22 | message: "Location", | 22 | 23 | options: [ | 23 | 24 | { | 24 | 25 | label: "Current project", | 25 | 26 | value: "project" as const, | 26 | | - hint: app.path.root, | | 27 | + hint: Instance.worktree, | 27 | 28 | }, | 28 | 29 | { | 29 | 30 | label: "Global", | @@ -116,7 +117,7 @@ const AgentCreateCommand = cmd({ | 116 | 117 |
| 117 | 118 | const content = matter.stringify(generated.systemPrompt, frontmatter) | 118 | 119 | const filePath = path.join( | 119 | | - scope === "global" ? Global.Path.config : path.join(app.path.root, ".opencode"), | | 120 | + scope === "global" ? Global.Path.config : path.join(Instance.worktree, ".opencode"), | 120 | 121 | `agent`, | 121 | 122 | `${generated.identifier}.md`, | 122 | 123 | ) | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/auth.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,7 +8,7 @@ import path from "path" | 8 | 8 | import os from "os" | 9 | 9 | import { Global } from "../../global" | 10 | 10 | import { Plugin } from "../../plugin" | 11 | | -import { App } from "../../app/app" | | 11 | +import { Instance } from "../../project/instance" | 12 | 12 |
| 13 | 13 | export const AuthCommand = cmd({ | 14 | 14 | command: "auth", | @@ -74,7 +74,7 @@ export const AuthLoginCommand = cmd({ | 74 | 74 | type: "string", | 75 | 75 | }), | 76 | 76 | async handler(args) { | 77 | | - await App.provide({ cwd: process.cwd() }, async () => { | | 77 | + await Instance.provide(process.cwd(), async () => { | 78 | 78 | UI.empty() | 79 | 79 | prompts.intro("Add credential") | 80 | 80 | if (args.url) { | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/debug/app.ts -20Lines changed: 0 additions & 20 deletions Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/debug/file.ts +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,7 +11,7 @@ const FileReadCommand = cmd({ | 11 | 11 | description: "File path to read", | 12 | 12 | }), | 13 | 13 | async handler(args) { | 14 | | - await bootstrap({ cwd: process.cwd() }, async () => { | | 14 | + await bootstrap(process.cwd(), async () => { | 15 | 15 | const content = await File.read(args.path) | 16 | 16 | console.log(content) | 17 | 17 | }) | @@ -22,7 +22,7 @@ const FileStatusCommand = cmd({ | 22 | 22 | command: "status", | 23 | 23 | builder: (yargs) => yargs, | 24 | 24 | async handler() { | 25 | | - await bootstrap({ cwd: process.cwd() }, async () => { | | 25 | + await bootstrap(process.cwd(), async () => { | 26 | 26 | const status = await File.status() | 27 | 27 | console.log(JSON.stringify(status, null, 2)) | 28 | 28 | }) | @@ -38,7 +38,7 @@ const FileListCommand = cmd({ | 38 | 38 | description: "File path to list", | 39 | 39 | }), | 40 | 40 | async handler(args) { | 41 | | - await bootstrap({ cwd: process.cwd() }, async () => { | | 41 | + await bootstrap(process.cwd(), async () => { | 42 | 42 | const files = await File.list(args.path) | 43 | 43 | console.log(JSON.stringify(files, null, 2)) | 44 | 44 | }) | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/debug/index.ts +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { Global } from "../../../global" | 2 | 2 | import { bootstrap } from "../../bootstrap" | 3 | 3 | import { cmd } from "../cmd" | 4 | | -import { AppCommand } from "./app" | 5 | 4 | import { FileCommand } from "./file" | 6 | 5 | import { LSPCommand } from "./lsp" | 7 | 6 | import { RipgrepCommand } from "./ripgrep" | @@ -12,7 +11,6 @@ export const DebugCommand = cmd({ | 12 | 11 | command: "debug", | 13 | 12 | builder: (yargs) => | 14 | 13 | yargs | 15 | | - .command(AppCommand) | 16 | 14 | .command(LSPCommand) | 17 | 15 | .command(RipgrepCommand) | 18 | 16 | .command(FileCommand) | @@ -22,7 +20,7 @@ export const DebugCommand = cmd({ | 22 | 20 | .command({ | 23 | 21 | command: "wait", | 24 | 22 | async handler() { | 25 | | - await bootstrap({ cwd: process.cwd() }, async () => { | | 23 | + await bootstrap(process.cwd(), async () => { | 26 | 24 | await new Promise((resolve) => setTimeout(resolve, 1_000 * 60 * 60 * 24)) | 27 | 25 | }) | 28 | 26 | }, | |
|