refactor(cli/github+run): Stage 4 — drop AppRuntime.runPromise bridges (#25539)

This commit is contained in:
Kit Langton
2026-05-03 11:42:05 -04:00
committed by GitHub
parent 57d5c095d8
commit df7dd06a0f
2 changed files with 28 additions and 26 deletions

View File

@@ -29,7 +29,6 @@ import { Provider } from "@/provider/provider"
import { Bus } from "../../bus" import { Bus } from "../../bus"
import { MessageV2 } from "../../session/message-v2" import { MessageV2 } from "../../session/message-v2"
import { SessionPrompt } from "@/session/prompt" import { SessionPrompt } from "@/session/prompt"
import { AppRuntime } from "@/effect/app-runtime"
import { Git } from "@/git" import { Git } from "@/git"
import { setTimeout as sleep } from "node:timers/promises" import { setTimeout as sleep } from "node:timers/promises"
import { Process } from "@/util/process" import { Process } from "@/util/process"
@@ -206,6 +205,8 @@ export const GithubInstallCommand = effectCmd({
const maybeCtx = yield* InstanceRef const maybeCtx = yield* InstanceRef
if (!maybeCtx) return yield* Effect.die("InstanceRef not provided") if (!maybeCtx) return yield* Effect.die("InstanceRef not provided")
const ctx = maybeCtx const ctx = maybeCtx
const modelsDev = yield* ModelsDev.Service
const gitSvc = yield* Git.Service
yield* Effect.promise(async () => { yield* Effect.promise(async () => {
{ {
UI.empty() UI.empty()
@@ -213,7 +214,7 @@ export const GithubInstallCommand = effectCmd({
const app = await getAppInfo() const app = await getAppInfo()
await installGitHubApp() await installGitHubApp()
const providers = await AppRuntime.runPromise(ModelsDev.Service.use((s) => s.get())).then((p) => { const providers = await Effect.runPromise(modelsDev.get()).then((p) => {
// TODO: add guide for copilot, for now just hide it // TODO: add guide for copilot, for now just hide it
delete p["github-copilot"] delete p["github-copilot"]
return p return p
@@ -261,9 +262,9 @@ export const GithubInstallCommand = effectCmd({
} }
// Get repo info // Get repo info
const info = await AppRuntime.runPromise( const info = await Effect.runPromise(gitSvc.run(["remote", "get-url", "origin"], { cwd: ctx.worktree })).then(
Git.Service.use((git) => git.run(["remote", "get-url", "origin"], { cwd: ctx.worktree })), (x) => x.text().trim(),
).then((x) => x.text().trim()) )
const parsed = parseGitHubRemote(info) const parsed = parseGitHubRemote(info)
if (!parsed) { if (!parsed) {
prompts.log.error(`Could not find git repository. Please run this command from a git repository.`) prompts.log.error(`Could not find git repository. Please run this command from a git repository.`)
@@ -440,6 +441,10 @@ export const GithubRunCommand = effectCmd({
handler: Effect.fn("Cli.github.run")(function* (args) { handler: Effect.fn("Cli.github.run")(function* (args) {
const ctx = yield* InstanceRef const ctx = yield* InstanceRef
if (!ctx) return yield* Effect.die("InstanceRef not provided") if (!ctx) return yield* Effect.die("InstanceRef not provided")
const gitSvc = yield* Git.Service
const sessionSvc = yield* Session.Service
const sessionShare = yield* SessionShare.Service
const sessionPrompt = yield* SessionPrompt.Service
yield* Effect.promise(async () => { yield* Effect.promise(async () => {
const isMock = args.token || args.event const isMock = args.token || args.event
@@ -503,21 +508,20 @@ export const GithubRunCommand = effectCmd({
: "issue" : "issue"
: undefined : undefined
const gitText = async (args: string[]) => { const gitText = async (args: string[]) => {
const result = await AppRuntime.runPromise(Git.Service.use((git) => git.run(args, { cwd: ctx.worktree }))) const result = await Effect.runPromise(gitSvc.run(args, { cwd: ctx.worktree }))
if (result.exitCode !== 0) { if (result.exitCode !== 0) {
throw new Process.RunFailedError(["git", ...args], result.exitCode, result.stdout, result.stderr) throw new Process.RunFailedError(["git", ...args], result.exitCode, result.stdout, result.stderr)
} }
return result.text().trim() return result.text().trim()
} }
const gitRun = async (args: string[]) => { const gitRun = async (args: string[]) => {
const result = await AppRuntime.runPromise(Git.Service.use((git) => git.run(args, { cwd: ctx.worktree }))) const result = await Effect.runPromise(gitSvc.run(args, { cwd: ctx.worktree }))
if (result.exitCode !== 0) { if (result.exitCode !== 0) {
throw new Process.RunFailedError(["git", ...args], result.exitCode, result.stdout, result.stderr) throw new Process.RunFailedError(["git", ...args], result.exitCode, result.stdout, result.stderr)
} }
return result return result
} }
const gitStatus = (args: string[]) => const gitStatus = (args: string[]) => Effect.runPromise(gitSvc.run(args, { cwd: ctx.worktree }))
AppRuntime.runPromise(Git.Service.use((git) => git.run(args, { cwd: ctx.worktree })))
const commitChanges = async (summary: string, actor?: string) => { const commitChanges = async (summary: string, actor?: string) => {
const args = ["commit", "-m", summary] const args = ["commit", "-m", summary]
if (actor) args.push("-m", `Co-authored-by: ${actor} <${actor}@users.noreply.github.com>`) if (actor) args.push("-m", `Co-authored-by: ${actor} <${actor}@users.noreply.github.com>`)
@@ -554,24 +558,22 @@ export const GithubRunCommand = effectCmd({
// Setup opencode session // Setup opencode session
const repoData = await fetchRepo() const repoData = await fetchRepo()
session = await AppRuntime.runPromise( session = await Effect.runPromise(
Session.Service.use((svc) => sessionSvc.create({
svc.create({ permission: [
permission: [ {
{ permission: "question",
permission: "question", action: "deny",
action: "deny", pattern: "*",
pattern: "*", },
}, ],
], }),
}),
),
) )
subscribeSessionEvents() subscribeSessionEvents()
shareId = await (async () => { shareId = await (async () => {
if (share === false) return if (share === false) return
if (!share && repoData.data.private) return if (!share && repoData.data.private) return
await AppRuntime.runPromise(SessionShare.Service.use((svc) => svc.share(session.id))) await Effect.runPromise(sessionShare.share(session.id))
return session.id.slice(-8) return session.id.slice(-8)
})() })()
console.log("opencode session", session.id) console.log("opencode session", session.id)
@@ -944,9 +946,9 @@ export const GithubRunCommand = effectCmd({
async function chat(message: string, files: PromptFiles = []) { async function chat(message: string, files: PromptFiles = []) {
console.log("Sending message to opencode...") console.log("Sending message to opencode...")
return AppRuntime.runPromise( return Effect.runPromise(
Effect.gen(function* () { Effect.gen(function* () {
const prompt = yield* SessionPrompt.Service const prompt = sessionPrompt
const result = yield* prompt.prompt({ const result = yield* prompt.prompt({
sessionID: session.id, sessionID: session.id,
messageID: MessageID.ascending(), messageID: MessageID.ascending(),

View File

@@ -27,7 +27,6 @@ import { ShellTool } from "../../tool/shell"
import { ShellID } from "../../tool/shell/id" import { ShellID } from "../../tool/shell/id"
import { TodoWriteTool } from "../../tool/todo" import { TodoWriteTool } from "../../tool/todo"
import { Locale } from "@/util/locale" import { Locale } from "@/util/locale"
import { AppRuntime } from "@/effect/app-runtime"
type ToolProps<T> = { type ToolProps<T> = {
input: Tool.InferParameters<T> input: Tool.InferParameters<T>
@@ -300,6 +299,7 @@ export const RunCommand = effectCmd({
default: false, default: false,
}), }),
handler: Effect.fn("Cli.run")(function* (args) { handler: Effect.fn("Cli.run")(function* (args) {
const agentSvc = yield* Agent.Service
yield* Effect.promise(async () => { yield* Effect.promise(async () => {
let message = [...args.message, ...(args["--"] || [])] let message = [...args.message, ...(args["--"] || [])]
.map((arg) => (arg.includes(" ") ? `"${arg.replace(/"/g, '\\"')}"` : arg)) .map((arg) => (arg.includes(" ") ? `"${arg.replace(/"/g, '\\"')}"` : arg))
@@ -603,7 +603,7 @@ export const RunCommand = effectCmd({
return name return name
} }
const entry = await AppRuntime.runPromise(Agent.Service.use((svc) => svc.get(name))) const entry = await Effect.runPromise(agentSvc.get(name))
if (!entry) { if (!entry) {
UI.println( UI.println(
UI.Style.TEXT_WARNING_BOLD + "!", UI.Style.TEXT_WARNING_BOLD + "!",