Skip to content

Commit df7dd06

Browse files
authored
refactor(cli/github+run): Stage 4 — drop AppRuntime.runPromise bridges (anomalyco#25539)
1 parent 57d5c09 commit df7dd06

2 files changed

Lines changed: 28 additions & 26 deletions

File tree

packages/opencode/src/cli/cmd/github.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import { Provider } from "@/provider/provider"
2929
import { Bus } from "../../bus"
3030
import { MessageV2 } from "../../session/message-v2"
3131
import { SessionPrompt } from "@/session/prompt"
32-
import { AppRuntime } from "@/effect/app-runtime"
3332
import { Git } from "@/git"
3433
import { setTimeout as sleep } from "node:timers/promises"
3534
import { Process } from "@/util/process"
@@ -206,14 +205,16 @@ export const GithubInstallCommand = effectCmd({
206205
const maybeCtx = yield* InstanceRef
207206
if (!maybeCtx) return yield* Effect.die("InstanceRef not provided")
208207
const ctx = maybeCtx
208+
const modelsDev = yield* ModelsDev.Service
209+
const gitSvc = yield* Git.Service
209210
yield* Effect.promise(async () => {
210211
{
211212
UI.empty()
212213
prompts.intro("Install GitHub agent")
213214
const app = await getAppInfo()
214215
await installGitHubApp()
215216

216-
const providers = await AppRuntime.runPromise(ModelsDev.Service.use((s) => s.get())).then((p) => {
217+
const providers = await Effect.runPromise(modelsDev.get()).then((p) => {
217218
// TODO: add guide for copilot, for now just hide it
218219
delete p["github-copilot"]
219220
return p
@@ -261,9 +262,9 @@ export const GithubInstallCommand = effectCmd({
261262
}
262263

263264
// Get repo info
264-
const info = await AppRuntime.runPromise(
265-
Git.Service.use((git) => git.run(["remote", "get-url", "origin"], { cwd: ctx.worktree })),
266-
).then((x) => x.text().trim())
265+
const info = await Effect.runPromise(gitSvc.run(["remote", "get-url", "origin"], { cwd: ctx.worktree })).then(
266+
(x) => x.text().trim(),
267+
)
267268
const parsed = parseGitHubRemote(info)
268269
if (!parsed) {
269270
prompts.log.error(`Could not find git repository. Please run this command from a git repository.`)
@@ -440,6 +441,10 @@ export const GithubRunCommand = effectCmd({
440441
handler: Effect.fn("Cli.github.run")(function* (args) {
441442
const ctx = yield* InstanceRef
442443
if (!ctx) return yield* Effect.die("InstanceRef not provided")
444+
const gitSvc = yield* Git.Service
445+
const sessionSvc = yield* Session.Service
446+
const sessionShare = yield* SessionShare.Service
447+
const sessionPrompt = yield* SessionPrompt.Service
443448
yield* Effect.promise(async () => {
444449
const isMock = args.token || args.event
445450

@@ -503,21 +508,20 @@ export const GithubRunCommand = effectCmd({
503508
: "issue"
504509
: undefined
505510
const gitText = async (args: string[]) => {
506-
const result = await AppRuntime.runPromise(Git.Service.use((git) => git.run(args, { cwd: ctx.worktree })))
511+
const result = await Effect.runPromise(gitSvc.run(args, { cwd: ctx.worktree }))
507512
if (result.exitCode !== 0) {
508513
throw new Process.RunFailedError(["git", ...args], result.exitCode, result.stdout, result.stderr)
509514
}
510515
return result.text().trim()
511516
}
512517
const gitRun = async (args: string[]) => {
513-
const result = await AppRuntime.runPromise(Git.Service.use((git) => git.run(args, { cwd: ctx.worktree })))
518+
const result = await Effect.runPromise(gitSvc.run(args, { cwd: ctx.worktree }))
514519
if (result.exitCode !== 0) {
515520
throw new Process.RunFailedError(["git", ...args], result.exitCode, result.stdout, result.stderr)
516521
}
517522
return result
518523
}
519-
const gitStatus = (args: string[]) =>
520-
AppRuntime.runPromise(Git.Service.use((git) => git.run(args, { cwd: ctx.worktree })))
524+
const gitStatus = (args: string[]) => Effect.runPromise(gitSvc.run(args, { cwd: ctx.worktree }))
521525
const commitChanges = async (summary: string, actor?: string) => {
522526
const args = ["commit", "-m", summary]
523527
if (actor) args.push("-m", `Co-authored-by: ${actor} <${actor}@users.noreply.github.com>`)
@@ -554,24 +558,22 @@ export const GithubRunCommand = effectCmd({
554558

555559
// Setup opencode session
556560
const repoData = await fetchRepo()
557-
session = await AppRuntime.runPromise(
558-
Session.Service.use((svc) =>
559-
svc.create({
560-
permission: [
561-
{
562-
permission: "question",
563-
action: "deny",
564-
pattern: "*",
565-
},
566-
],
567-
}),
568-
),
561+
session = await Effect.runPromise(
562+
sessionSvc.create({
563+
permission: [
564+
{
565+
permission: "question",
566+
action: "deny",
567+
pattern: "*",
568+
},
569+
],
570+
}),
569571
)
570572
subscribeSessionEvents()
571573
shareId = await (async () => {
572574
if (share === false) return
573575
if (!share && repoData.data.private) return
574-
await AppRuntime.runPromise(SessionShare.Service.use((svc) => svc.share(session.id)))
576+
await Effect.runPromise(sessionShare.share(session.id))
575577
return session.id.slice(-8)
576578
})()
577579
console.log("opencode session", session.id)
@@ -944,9 +946,9 @@ export const GithubRunCommand = effectCmd({
944946
async function chat(message: string, files: PromptFiles = []) {
945947
console.log("Sending message to opencode...")
946948

947-
return AppRuntime.runPromise(
949+
return Effect.runPromise(
948950
Effect.gen(function* () {
949-
const prompt = yield* SessionPrompt.Service
951+
const prompt = sessionPrompt
950952
const result = yield* prompt.prompt({
951953
sessionID: session.id,
952954
messageID: MessageID.ascending(),

packages/opencode/src/cli/cmd/run.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import { ShellTool } from "../../tool/shell"
2727
import { ShellID } from "../../tool/shell/id"
2828
import { TodoWriteTool } from "../../tool/todo"
2929
import { Locale } from "@/util/locale"
30-
import { AppRuntime } from "@/effect/app-runtime"
3130

3231
type ToolProps<T> = {
3332
input: Tool.InferParameters<T>
@@ -300,6 +299,7 @@ export const RunCommand = effectCmd({
300299
default: false,
301300
}),
302301
handler: Effect.fn("Cli.run")(function* (args) {
302+
const agentSvc = yield* Agent.Service
303303
yield* Effect.promise(async () => {
304304
let message = [...args.message, ...(args["--"] || [])]
305305
.map((arg) => (arg.includes(" ") ? `"${arg.replace(/"/g, '\\"')}"` : arg))
@@ -603,7 +603,7 @@ export const RunCommand = effectCmd({
603603
return name
604604
}
605605

606-
const entry = await AppRuntime.runPromise(Agent.Service.use((svc) => svc.get(name)))
606+
const entry = await Effect.runPromise(agentSvc.get(name))
607607
if (!entry) {
608608
UI.println(
609609
UI.Style.TEXT_WARNING_BOLD + "!",

0 commit comments

Comments
 (0)