Skip to content

Commit 651ef97

Browse files
committed
more rebase fix
1 parent 813b69b commit 651ef97

10 files changed

Lines changed: 213 additions & 81 deletions

File tree

bun.lock

Lines changed: 9 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/opencode/src/config/config.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { ConfigSkills } from "./skills"
4343
import { ConfigVariable } from "./variable"
4444
import { Npm } from "@/npm"
4545
import { SandboxPreset } from "@/sandbox/preset"
46+
import { makeRuntime } from "@/effect/run-service"
4647

4748
const log = Log.create({ service: "config" })
4849

@@ -898,3 +899,37 @@ export const defaultLayer = layer.pipe(
898899
Layer.provide(Account.defaultLayer),
899900
Layer.provide(Npm.defaultLayer),
900901
)
902+
903+
const { runPromise } = makeRuntime(Service, defaultLayer)
904+
905+
export async function get() {
906+
return runPromise((svc) => svc.get())
907+
}
908+
909+
export async function getGlobal() {
910+
return runPromise((svc) => svc.getGlobal())
911+
}
912+
913+
export async function getConsoleState() {
914+
return runPromise((svc) => svc.getConsoleState())
915+
}
916+
917+
export async function update(config: Info) {
918+
return runPromise((svc) => svc.update(config))
919+
}
920+
921+
export async function updateGlobal(config: Info) {
922+
return runPromise((svc) => svc.updateGlobal(config))
923+
}
924+
925+
export async function invalidate(wait = false) {
926+
return runPromise((svc) => svc.invalidate(wait))
927+
}
928+
929+
export async function directories() {
930+
return runPromise((svc) => svc.directories())
931+
}
932+
933+
export async function waitForDependencies() {
934+
return runPromise((svc) => svc.waitForDependencies())
935+
}

packages/opencode/src/pty/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export const layer = Layer.effect(
189189
const id = PtyID.ascending()
190190
const command = input.command || Shell.preferred()
191191
const cwd = input.cwd || s.dir
192-
const cfg = yield* Effect.promise(() => SandboxSpawn.settings())
192+
const cfg = yield* Effect.promise(Instance.bind(() => SandboxSpawn.settings()))
193193
const blocked = SandboxSpawn.excluded([command, ...(input.args ?? [])], cfg.excluded_commands)
194194
if (blocked) {
195195
throw new SandboxSpawn.CommandError(blocked.command, blocked.rule)

packages/opencode/src/sandbox/spawn.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { Config } from "@/config/config"
1+
import { Config } from "@/config"
22
import { Protected } from "@/file/protected"
33
import { Flag } from "@/flag/flag"
44
import { Global } from "@/global"
55
import { BashArity } from "@/permission/arity"
6-
import { Log } from "@/util/log"
7-
import { Filesystem } from "@/util/filesystem"
6+
import { Filesystem, Log } from "@/util"
87
import os from "os"
98
import path from "path"
109
import { SandboxPolicy } from "./policy"

packages/opencode/test/pty/pty-session.test.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ const pick = (log: Array<{ type: "created" | "exited" | "deleted"; id: PtyID }>,
3232
return log.filter((evt) => evt.id === id).map((evt) => evt.type)
3333
}
3434

35+
function createPty(input: Pty.CreateInput) {
36+
return AppRuntime.runPromise(Pty.Service.use((svc) => svc.create(input)))
37+
}
38+
39+
function removePty(id: PtyID) {
40+
return AppRuntime.runPromise(Pty.Service.use((svc) => svc.remove(id)))
41+
}
42+
43+
function connectPty(id: PtyID, ws: Parameters<Pty.Interface["connect"]>[1]) {
44+
return AppRuntime.runPromise(Pty.Service.use((svc) => svc.connect(id, ws)))
45+
}
46+
47+
function writePty(id: PtyID, data: string) {
48+
return AppRuntime.runPromise(Pty.Service.use((svc) => svc.write(id, data)))
49+
}
50+
3551
describe("pty", () => {
3652
test("publishes created, exited, deleted in order for a short-lived process", async () => {
3753
if (process.platform === "win32") return
@@ -127,10 +143,10 @@ describe("pty", () => {
127143
await Instance.provide({
128144
directory: dir.path,
129145
fn: async () => {
130-
const info = await Pty.create({ command: "cat", title: "cat" })
146+
const info = await createPty({ command: "cat", title: "cat" })
131147
try {
132148
const out: string[] = []
133-
const ws: Parameters<typeof Pty.connect>[1] = {
149+
const ws: Parameters<Pty.Interface["connect"]>[1] = {
134150
readyState: 1,
135151
data: { id: info.id },
136152
send: (data: unknown) => {
@@ -139,12 +155,12 @@ describe("pty", () => {
139155
close: () => {},
140156
}
141157

142-
await Pty.connect(info.id, ws)
158+
await connectPty(info.id, ws)
143159
out.length = 0
144-
await Pty.write(info.id, "AAA\n")
160+
await writePty(info.id, "AAA\n")
145161
await wait(() => out.join("").includes("AAA"))
146162
} finally {
147-
await Pty.remove(info.id)
163+
await removePty(info.id)
148164
}
149165
},
150166
})
@@ -172,7 +188,7 @@ describe("pty", () => {
172188
await Instance.provide({
173189
directory: dir.path,
174190
fn: async () => {
175-
const info = await Pty.create({ command: "/bin/bash", title: "bash" })
191+
const info = await createPty({ command: "/bin/bash", title: "bash" })
176192
try {
177193
await sleep(150)
178194
const hit = await fs
@@ -181,7 +197,7 @@ describe("pty", () => {
181197
.catch(() => false)
182198
expect(hit).toBe(false)
183199
} finally {
184-
await Pty.remove(info.id)
200+
await removePty(info.id)
185201
}
186202
},
187203
})
@@ -202,11 +218,11 @@ describe("pty", () => {
202218
await Instance.provide({
203219
directory: dir.path,
204220
fn: async () => {
205-
await expect(Pty.create({ command: "python", title: "py" })).rejects.toThrow("python")
221+
await expect(createPty({ command: "python", title: "py" })).rejects.toThrow("python")
206222
await expect(
207-
Pty.create({ command: "env", args: ["FOO=1", "python", "-c", "print(1)"], title: "env" }),
223+
createPty({ command: "env", args: ["FOO=1", "python", "-c", "print(1)"], title: "env" }),
208224
).rejects.toThrow("python")
209-
await expect(Pty.create({ command: "sh", args: ["-c", "python -c 'print(1)'"], title: "sh" })).rejects.toThrow(
225+
await expect(createPty({ command: "sh", args: ["-c", "python -c 'print(1)'"], title: "sh" })).rejects.toThrow(
210226
"python",
211227
)
212228
},

packages/opencode/test/sandbox/preset-permission.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { afterEach, describe, expect, test } from "bun:test"
2+
import { AppRuntime } from "../../src/effect/app-runtime"
23
import { Agent } from "../../src/agent/agent"
34
import { Instance } from "../../src/project/instance"
45
import { Permission } from "../../src/permission"
@@ -8,6 +9,10 @@ afterEach(async () => {
89
await Instance.disposeAll()
910
})
1011

12+
function getAgent(name: string) {
13+
return AppRuntime.runPromise(Agent.Service.use((svc) => svc.get(name)))
14+
}
15+
1116
describe("sandbox preset permission overlay", () => {
1217
test("applies the preset overlay when no explicit override exists", async () => {
1318
await using tmp = await tmpdir({
@@ -24,7 +29,7 @@ describe("sandbox preset permission overlay", () => {
2429
await Instance.provide({
2530
directory: tmp.path,
2631
fn: async () => {
27-
const build = await Agent.get("build")
32+
const build = await getAgent("build")
2833
expect(Permission.evaluate("bash", "echo hello", build!.permission).action).toBe("ask")
2934
},
3035
})
@@ -52,7 +57,7 @@ describe("sandbox preset permission overlay", () => {
5257
await Instance.provide({
5358
directory: tmp.path,
5459
fn: async () => {
55-
const build = await Agent.get("build")
60+
const build = await getAgent("build")
5661
expect(Permission.evaluate("bash", "echo hello", build!.permission).action).toBe("allow")
5762
},
5863
})
@@ -76,7 +81,7 @@ describe("sandbox preset permission overlay", () => {
7681
await Instance.provide({
7782
directory: tmp.path,
7883
fn: async () => {
79-
const build = await Agent.get("build")
84+
const build = await getAgent("build")
8085
expect(Permission.evaluate("bash", "echo hello", build!.permission).action).toBe("deny")
8186
},
8287
})
@@ -97,7 +102,7 @@ describe("sandbox preset permission overlay", () => {
97102
await Instance.provide({
98103
directory: tmp.path,
99104
fn: async () => {
100-
const general = await Agent.get("general")
105+
const general = await getAgent("general")
101106
expect(Permission.evaluate("bash", "ls", general!.permission).action).toBe("ask")
102107
},
103108
})
@@ -109,7 +114,7 @@ describe("sandbox preset permission overlay", () => {
109114
await Instance.provide({
110115
directory: tmp.path,
111116
fn: async () => {
112-
const build = await Agent.get("build")
117+
const build = await getAgent("build")
113118
expect(Permission.evaluate("bash", "echo hello", build!.permission).action).toBe("allow")
114119
},
115120
})

packages/opencode/test/sandbox/preset.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { afterEach, describe, expect, test } from "bun:test"
2-
import { Config } from "../../src/config/config"
2+
import { Config } from "../../src/config"
33
import { Instance } from "../../src/project/instance"
44
import { SandboxPreset } from "../../src/sandbox/preset"
55
import { tmpdir } from "../fixture/fixture"

0 commit comments

Comments
 (0)