GeezerVison is showing github.com — Merge remote-tracking branch 'origin/main' into fix/issue-26295 · pingdotgg/t3code@7e0371d
File treeExpand file treeCollapse file tree Open diff view settings server/src/orchestration-v2/Adapters
packages/provider-opencode/src/server/v2
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts +420-2Lines changed: 420 additions & 2 deletions Large diffs are not rendered by default. Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.testkit.ts +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -54,6 +54,10 @@ const operationOf = ( | 54 | 54 | query: Record<string, unknown>, | 55 | 55 | body: unknown, | 56 | 56 | ) => { | | 57 | + if (method === "GET" && path === "/api/experimental/job") | | 58 | + return { type: "imageJobs", input: query }; | | 59 | + if (method === "GET" && path.startsWith("/api/fs/read/")) | | 60 | + return { type: "image.read", input: { path, ...query } }; | 57 | 61 | const rpc = /^\/api\/rpc\/([^/]+)\/([^/]+)$/.exec(path); | 58 | 62 | if (method === "POST" && rpc !== null) | 59 | 63 | return { | @@ -176,6 +180,11 @@ const replayHttpClient = ( | 176 | 180 | } | 177 | 181 | // Recorded responses are the raw HTTP bodies; `null` is an empty 204. | 178 | 182 | const body = await controller.response(operation.type); | | 183 | + if (typeof body === "object" && body !== null && "imageBase64" in body) { | | 184 | + return new Response(Buffer.from(String(body.imageBase64), "base64"), { | | 185 | + headers: { "content-type": "image/png" }, | | 186 | + }); | | 187 | + } | 179 | 188 | if (body === "<hang>") return new Promise<Response>(() => {}); | 180 | 189 | if (typeof body === "object" && body !== null && "status" in body && "body" in body) { | 181 | 190 | return new Response(encodeJson(body.body), { | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/CommandPalette.tsx +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -2650,6 +2650,7 @@ function OpenCommandPaletteDialog(props: { | 2650 | 2650 | scrollCommandPaletteRowIntoView( | 2651 | 2651 | resultListRef.current, | 2652 | 2652 | resultRows.rowIndexByItemIndex[0] ?? 0, | | 2653 | + true, | 2653 | 2654 | ); | 2654 | 2655 | return; | 2655 | 2656 | } | @@ -2921,7 +2922,11 @@ function OpenCommandPaletteDialog(props: { | 2921 | 2922 | setHighlightedItemValue(typeof value === "string" ? value : null); | 2922 | 2923 | const rowIndex = resultRows.rowIndexByItemIndex[eventDetails.index]; | 2923 | 2924 | if (eventDetails.reason === "keyboard" && rowIndex !== undefined) { | 2924 | | - scrollCommandPaletteRowIntoView(resultListRef.current, rowIndex); | | 2925 | + scrollCommandPaletteRowIntoView( | | 2926 | + resultListRef.current, | | 2927 | + rowIndex, | | 2928 | + eventDetails.index === 0, | | 2929 | + ); | 2925 | 2930 | } | 2926 | 2931 | }} | 2927 | 2932 | onValueChange={(nextQuery, { event }) => handleQueryChange(nextQuery, event.target)} | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/CommandPaletteResults.tsx +9-1Lines changed: 9 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -78,7 +78,15 @@ export function CommandPaletteResults(props: CommandPaletteResultsProps) { | 78 | 78 | ); | 79 | 79 | } | 80 | 80 |
| 81 | | -export function scrollCommandPaletteRowIntoView(list: LegendListRef | null, rowIndex: number) { | | 81 | +export function scrollCommandPaletteRowIntoView( | | 82 | + list: LegendListRef | null, | | 83 | + rowIndex: number, | | 84 | + isFirstItem: boolean, | | 85 | +) { | | 86 | + if (isFirstItem) { | | 87 | + void list?.scrollToOffset({ offset: 0, animated: false }); | | 88 | + return; | | 89 | + } | 82 | 90 | void list?.scrollIndexIntoView({ | 83 | 91 | index: rowIndex, | 84 | 92 | animated: false, | |
Collapse file Copy file name to clipboardExpand all lines: docs/operations/scenarios.md +13-1Lines changed: 13 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -70,7 +70,19 @@ cd scripts && pnpm exec e2e run scenarios/replay-turn-streams.e2e.ts --headed | 70 | 70 |
| 71 | 71 | e2e starts the dev stack through [`start-app.ts`](../../scripts/scenarios/start-app.ts) on a free | 72 | 72 | port, runs the tests, and stops it. Results land in `scripts/.e2e`: `report.json`, `summary.md`, | 73 | | -and per test a `trace.md`, its screenshots, and a video. The first run downloads e2e's browser. | | 73 | +and per test a `trace.md`, its screenshots, and a video. `vp run scenarios --target web` runs one | | 74 | +target; flags go straight after the script name, without `--`. | | 75 | + | | 76 | +The first run downloads e2e's browser (about 120 MB). To fetch it ahead of time, such as in a | | 77 | +machine image, run this from the repository root after `vp i`: | | 78 | + | | 79 | +```sh | | 80 | +node scripts/node_modules/playwright-core/cli.js install --only-shell chromium ffmpeg | | 81 | +``` | | 82 | + | | 83 | +e2e opens the web app at `127.0.0.1`, and the start script tells the web dev server to bind that | | 84 | +address. It does not use `localhost`, which some machines resolve to `::1` first. | | 85 | + | 74 | 86 | `e2e run --help` lists the rest: `--grep`, `--watch`, `--last-failed`, `--changed-since`. | 75 | 87 |
| 76 | 88 | Run one at a time per checkout: a run recreates the checkout's scenario T3 home and its `.e2e` | |
Collapse file Copy file name to clipboardExpand all lines: packages/provider-opencode/src/server/v2/OpenCode2Client.test.ts +81Lines changed: 81 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,6 +8,7 @@ import * as Layer from "effect/Layer"; | 8 | 8 | import * as Redacted from "effect/Redacted"; | 9 | 9 | import * as Schema from "effect/Schema"; | 10 | 10 | import * as TestClock from "effect/testing/TestClock"; | | 11 | +import * as UrlParams from "effect/http/UrlParams"; | 11 | 12 | import * as HttpClient from "effect/http/HttpClient"; | 12 | 13 | import * as HttpClientResponse from "effect/http/HttpClientResponse"; | 13 | 14 | import { describe } from "vite-plus/test"; | @@ -167,3 +168,83 @@ describe("OpenCode2Client message history", () => { | 167 | 168 | }), | 168 | 169 | ); | 169 | 170 | }); | | 171 | + | | 172 | +describe("OpenCode2Client native image jobs", () => { | | 173 | + it.effect.each([ | | 174 | + { path: "/work/image.png", location: "/work" }, | | 175 | + { path: "/tmp/images/session/image.png", location: "/tmp/images/session" }, | | 176 | + ])("reads remote image $path through its native filesystem location", ({ path, location }) => | | 177 | + Effect.gen(function* () { | | 178 | + const transport = HttpClient.make((request) => | | 179 | + Effect.sync(() => { | | 180 | + assert.strictEqual(request.url, "http://remote.test/api/fs/read/image.png"); | | 181 | + assert.deepEqual(UrlParams.toRecord(request.urlParams), { | | 182 | + "location[directory]": location, | | 183 | + }); | | 184 | + return HttpClientResponse.fromWeb( | | 185 | + request, | | 186 | + new Response(Buffer.from("iVBORw0KGgo=", "base64")), | | 187 | + ); | | 188 | + }), | | 189 | + ); | | 190 | + const service = yield* OpenCode2Client.make.pipe( | | 191 | + Effect.provideService(HttpClient.HttpClient, transport), | | 192 | + ); | | 193 | + const api = yield* service.connect({ baseUrl: "http://remote.test", password: "secret" }); | | 194 | + assert.deepEqual(yield* api.readImage(path, "/work"), { | | 195 | + uri: "data:image/png;base64,iVBORw0KGgo=", | | 196 | + mime: "image/png", | | 197 | + }); | | 198 | + }), | | 199 | + ); | | 200 | + | | 201 | + it.effect("rejects remote previews above the shared image limit", () => | | 202 | + Effect.gen(function* () { | | 203 | + const transport = HttpClient.make((request) => | | 204 | + Effect.succeed( | | 205 | + HttpClientResponse.fromWeb(request, new Response(new Uint8Array(11 * 1024 * 1024))), | | 206 | + ), | | 207 | + ); | | 208 | + const service = yield* OpenCode2Client.make.pipe( | | 209 | + Effect.provideService(HttpClient.HttpClient, transport), | | 210 | + ); | | 211 | + const api = yield* service.connect({ baseUrl: "http://remote.test", password: "secret" }); | | 212 | + const result = yield* api.readImage("/work/image.png", "/work").pipe(Effect.result); | | 213 | + assert.equal(result._tag, "Failure"); | | 214 | + }), | | 215 | + ); | | 216 | + | | 217 | + it.effect("reads scoped image jobs without accepting other sessions or job kinds", () => | | 218 | + Effect.gen(function* () { | | 219 | + const job = { | | 220 | + kind: "image", | | 221 | + id: "image_test", | | 222 | + sessionID: "ses_owner", | | 223 | + status: "running", | | 224 | + path: "/work/image", | | 225 | + model: "test/image", | | 226 | + } as const; | | 227 | + const transport = HttpClient.make((request) => | | 228 | + Effect.sync(() => { | | 229 | + assert.strictEqual(request.headers.authorization, utf8Basic("secret")); | | 230 | + return HttpClientResponse.fromWeb( | | 231 | + request, | | 232 | + Response.json({ | | 233 | + data: [ | | 234 | + job, | | 235 | + { ...job, sessionID: "ses_other" }, | | 236 | + { ...job, kind: "shell" }, | | 237 | + { ...job, status: "future" }, | | 238 | + ], | | 239 | + }), | | 240 | + ); | | 241 | + }), | | 242 | + ); | | 243 | + const service = yield* OpenCode2Client.make.pipe( | | 244 | + Effect.provideService(HttpClient.HttpClient, transport), | | 245 | + ); | | 246 | + const api = yield* service.connect({ baseUrl: "http://remote.test", password: "secret" }); | | 247 | + assert.deepEqual(yield* api.imageJobs("ses_owner"), [job]); | | 248 | + }), | | 249 | + ); | | 250 | +}); |
Collapse file Copy file name to clipboardExpand all lines: packages/provider-opencode/src/server/v2/OpenCode2Client.ts +82Lines changed: 82 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import * as Path from "effect/Path"; | | 2 | +import { PROVIDER_SEND_TURN_MAX_IMAGE_BYTES } from "@t3tools/contracts"; | 1 | 3 | import { OpenCode, type OpenCodeClient } from "@opencode/client/effect"; | 2 | 4 | import { OpenCodeEvent } from "@opencode/protocol/groups/event"; | 3 | 5 | import * as Context from "effect/Context"; | @@ -50,9 +52,43 @@ export type OpenCode2StreamEvent = | 50 | 52 | | OpenCode2UnreadableTerminal | 51 | 53 | | OpenCode2UnreadableStart; | 52 | 54 |
| | 55 | +export class OpenCode2ImageError extends Schema.TaggedError<OpenCode2ImageError>()( | | 56 | + "OpenCode2ImageError", | | 57 | + { cause: Schema.Defect() }, | | 58 | +) {} | | 59 | + | | 60 | +const IMAGE_MIME: Readonly<Record<string, string>> = { | | 61 | + ".png": "image/png", | | 62 | + ".jpg": "image/jpeg", | | 63 | + ".jpeg": "image/jpeg", | | 64 | + ".webp": "image/webp", | | 65 | + ".gif": "image/gif", | | 66 | +}; | | 67 | +export const imagePreviewMime = (extension: string) => IMAGE_MIME[extension.toLowerCase()]; | | 68 | + | | 69 | +const NativeImageJob = Schema.Struct({ | | 70 | + kind: Schema.Literal("image"), | | 71 | + id: Schema.String, | | 72 | + sessionID: Schema.String, | | 73 | + status: Schema.Literals(["running", "completed", "error", "cancelled"]), | | 74 | + path: Schema.String, | | 75 | + model: Schema.String, | | 76 | +}); | | 77 | +const decodeJobs = Schema.decodeUnknownEffect( | | 78 | + Schema.Struct({ data: Schema.Array(Schema.Unknown) }), | | 79 | +); | | 80 | +const decodeImageJob = Schema.decodeUnknownOption(NativeImageJob); | | 81 | + | 53 | 82 | /** events resolves on subscription acceptance; subscribe before work because the stream is volatile. */ | 54 | 83 | export interface OpenCode2Api { | 55 | 84 | readonly client: OpenCodeClient; | | 85 | + readonly imageJobs: ( | | 86 | + sessionID: string, | | 87 | + ) => Effect.Effect<ReadonlyArray<typeof NativeImageJob.Type>, OpenCode2ImageError>; | | 88 | + readonly readImage: ( | | 89 | + path: string, | | 90 | + directory: string, | | 91 | + ) => Effect.Effect<{ uri: string; mime: string }, OpenCode2ImageError>; | 56 | 92 | readonly events: Effect.Effect< | 57 | 93 | Stream.Stream< | 58 | 94 | OpenCode2StreamEvent, | @@ -202,6 +238,7 @@ const fillCompactionRecents = HttpClient.transformResponse( | 202 | 238 | /** @public */ | 203 | 239 | export const make = Effect.gen(function* () { | 204 | 240 | const httpClient = yield* HttpClient.HttpClient; | | 241 | + const paths = yield* Path.Path.pipe(Effect.provide(Path.layer)); | 205 | 242 | return OpenCode2Client.of({ | 206 | 243 | connect: Effect.fn("OpenCode2Client.connect")(function ({ baseUrl, password }) { | 207 | 244 | const authenticated = HttpClient.mapRequest( | @@ -212,6 +249,51 @@ export const make = Effect.gen(function* () { | 212 | 249 | Effect.provideService(HttpClient.HttpClient, fillCompactionRecents(authenticated)), | 213 | 250 | Effect.map((client) => ({ | 214 | 251 | client, | | 252 | + imageJobs: (sessionID: string) => | | 253 | + authenticated | | 254 | + .get(`${baseUrl}/api/experimental/job`, { | | 255 | + urlParams: { sessionID, kind: "image" }, | | 256 | + }) | | 257 | + .pipe( | | 258 | + Effect.flatMap(HttpClientResponse.filterStatusOk), | | 259 | + Effect.flatMap((response) => response.json), | | 260 | + Effect.flatMap(decodeJobs), | | 261 | + Effect.map((page) => | | 262 | + page.data.flatMap((item) => { | | 263 | + const job = decodeImageJob(item); | | 264 | + return Option.isSome(job) && job.value.sessionID === sessionID | | 265 | + ? [job.value] | | 266 | + : []; | | 267 | + }), | | 268 | + ), | | 269 | + Effect.mapError((cause) => new OpenCode2ImageError({ cause })), | | 270 | + ), | | 271 | + readImage: Effect.fn("OpenCode2Client.readImage")( | | 272 | + function* (path: string, directory: string) { | | 273 | + const mime = imagePreviewMime(paths.extname(path)); | | 274 | + if (mime === undefined) | | 275 | + return yield* new OpenCode2ImageError({ cause: "Unsupported image format" }); | | 276 | + const relative = paths.relative(directory, path); | | 277 | + // OpenCode confines reads to the requested location, including its own temp images. | | 278 | + const outside = | | 279 | + relative === ".." || | | 280 | + relative.startsWith(`..${paths.sep}`) || | | 281 | + paths.isAbsolute(relative); | | 282 | + const location = outside ? paths.dirname(path) : directory; | | 283 | + const file = outside ? paths.basename(path) : relative; | | 284 | + const response = yield* authenticated | | 285 | + .get(`${baseUrl}/api/fs/read/${encodeURIComponent(file)}`, { | | 286 | + urlParams: { "location[directory]": location }, | | 287 | + }) | | 288 | + .pipe(Effect.flatMap(HttpClientResponse.filterStatusOk)); | | 289 | + const bytes = yield* response.arrayBuffer; | | 290 | + if (bytes.byteLength > PROVIDER_SEND_TURN_MAX_IMAGE_BYTES) | | 291 | + return yield* new OpenCode2ImageError({ cause: "Image exceeds preview limit" }); | | 292 | + return { uri: `data:${mime};base64,${Buffer.from(bytes).toString("base64")}`, mime }; | | 293 | + }, | | 294 | + Effect.timeout("10 seconds"), | | 295 | + Effect.mapError((cause) => new OpenCode2ImageError({ cause })), | | 296 | + ), | 215 | 297 | events: readEvents.pipe( | 216 | 298 | Effect.provideService( | 217 | 299 | HttpClient.HttpClient, | |
|