The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 19:45 UTC
fix(opencode): a project opened mid-scan lists its OpenCode skills (#35384)
Julius Marminge committed
Nov 12, 2026 at 09:10 UTC
833a15b6c1921dc3ee7a94f5a9fe8db13a6e93ed
3 files changed
+73
-2
packages/provider-opencode/src/server/driver.test.ts
+67
@@ -537,6 +537,73 @@ it.layer(layer)("OpenCodeDriver runtime selection", (it) => {
537
}).pipe(Effect.scoped, Effect.provide(TestClock.layer())),
538
);
539
540
+ it.effect("caches a cold OpenCode 2 directory's skills only after its scan ends", () =>
541
+ Effect.gen(function* () {
542
+ // OpenCode 2.2.7: touching a location lists it as loaded with built-in commands and skills
543
+ // at once, while provider.list waits for the scan that adds the project's skills.
544
+ const scanEnded = yield* Deferred.make<void>();
545
+ const builtinSkills = JSON.stringify({
546
+ location: { directory: "/work" },
547
+ data: (
548
+ JSON.parse(OPENCODE_2_WORKSPACE_RESPONSES["/api/skill"].body).data as Array<{
549
+ id: string;
550
+ }>
551
+ ).filter((skill) => skill.id !== "plum"),
552
+ });
553
+ const http = HttpClient.make((request) => {
554
+ const path = new URL(request.url).pathname;
555
+ const json = (body: string) =>
556
+ Effect.succeed(HttpClientResponse.fromWeb(request, Response.json(JSON.parse(body))));
557
+ const afterScan = (body: string) =>
558
+ Deferred.await(scanEnded).pipe(Effect.andThen(json(body)));
559
+ switch (path) {
560
+ case "/api/info":
561
+ return json(
562
+ JSON.stringify({
563
+ ...JSON.parse(OPENCODE_2_RESPONSES["/api/info"].body),
564
+ version: "2.2.7",
565
+ }),
566
+ );
567
+ case "/api/event":
568
+ return Effect.succeed(
569
+ HttpClientResponse.fromWeb(
570
+ request,
571
+ new Response(new ReadableStream(), {
572
+ headers: { "content-type": "text/event-stream" },
573
+ }),
574
+ ),
575
+ );
576
+ case "/api/debug/location":
577
+ return json('[{"directory":"/work"}]');
578
+ case "/api/provider":
579
+ case "/api/model":
580
+ return afterScan('{"location":{"directory":"/work"},"data":[]}');
581
+ case "/api/command":
582
+ return json(OPENCODE_2_WORKSPACE_RESPONSES["/api/command"].body);
583
+ case "/api/skill":
584
+ return Deferred.isDone(scanEnded).pipe(
585
+ Effect.flatMap((done) =>
586
+ json(done ? OPENCODE_2_WORKSPACE_RESPONSES["/api/skill"].body : builtinSkills),
587
+ ),
588
+ );
589
+ default:
590
+ return Effect.die(`Unexpected request: ${path}`);
591
+ }
592
+ });
593
+ const instance = yield* create({ serverUrl: "http://127.0.0.1:4096" }, http);
594
+
595
+ const snapshot = yield* instance.snapshotForCwd!("/work").pipe(Effect.forkChild);
596
+ yield* TestClock.adjust("1 second");
597
+ yield* Deferred.succeed(scanEnded, undefined);
598
+ yield* TestClock.adjust("30 seconds");
599
+ const { skills } = yield* Fiber.join(snapshot);
600
+ assert.include(
601
+ skills.map((skill) => skill.name),
602
+ "plum",
603
+ );
604
+ }).pipe(Effect.scoped, Effect.provide(TestClock.layer())),
605
+ );
606
+
607
it.effect.each(["probe", "error", "empty"] as const)(
608
"recovers discovery without a manual refresh after %s",
609
(initialCatalog) =>
packages/provider-opencode/src/server/driver.ts
+2
@@ -438,6 +438,8 @@ export const OpenCodeDriver: ProviderDriver<
438
Effect.timeout("2 seconds"),
439
Effect.orElseSucceed(() => true),
440
),
441
+ // OpenCode answers provider.list for a location only once its skill scan has ended.
442
+ client.provider.list({ location }).pipe(Effect.timeout("10 seconds"), Effect.ignore),
443
);
444
}).pipe(Effect.scoped),
445
);
packages/provider-opencode/src/server/status.ts
+4
-2
@@ -578,16 +578,18 @@ export interface OpenCode2Workspace {
578
/**
579
* Reading a location the server has not loaded boots its scan, and only reads after the scan's
580
* `command.updated` plus `skill.updated` are complete; `scanned` must listen before `read`. A
581
- * loaded location listing no commands is still scanning. OpenCode exposes no readiness signal,
582
- * so one another caller booted moments earlier can still read partial.
581
+ * loaded location listing no commands is still scanning. A location another caller booted
582
+ * moments earlier lists as loaded with only built-ins, so `settled` waits out its scan first.
583
*/
584
export const loadOpenCode2Workspace = Effect.fn("OpencodeProviderStatus.loadOpenCode2Workspace")(
585
function* <E>(
586
read: Effect.Effect<OpenCode2Workspace, E>,
587
scanned: Effect.Effect<void>,
588
loaded: Effect.Effect<boolean>,
589
+ settled: Effect.Effect<void> = Effect.void,
590
) {
591
const wasLoaded = yield* loaded;
592
+ yield* settled;
593
const first = yield* read;
594
if (wasLoaded && first.commands.length > 0) return first;
595
yield* scanned.pipe(Effect.timeoutOption("10 seconds"));