Skip to content

Commit f82e176

Browse files
fix(server): keep $skills from OpenCode's first read when its reread fails
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 9e02a6f commit f82e176

2 files changed

Lines changed: 39 additions & 6 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2289,6 +2289,40 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
22892289
}).pipe(Effect.scoped),
22902290
);
22912291

2292+
it.effect(
2293+
"keeps a $skill found on the first read when the reread after the scan comes back empty",
2294+
() =>
2295+
Effect.gen(function* () {
2296+
const prompts: Array<unknown> = [];
2297+
const greet = {
2298+
id: "greet",
2299+
name: "greet",
2300+
path: `${WORK}/.opencode/skills/greet/SKILL.md`,
2301+
content: "Say hello.",
2302+
};
2303+
const { runtime, thread } = yield* resumed(
2304+
[
2305+
out("skill.list", { "location[directory]": WORK }),
2306+
reply("skill.list", { location: { directory: WORK }, data: [greet] }),
2307+
...directoryModels(WORK),
2308+
out("skill.list", { "location[directory]": WORK }),
2309+
reply("skill.list", { location: { directory: WORK }, data: [] }),
2310+
out("session.prompt", { sessionID: SESSION, text: "<any>" }),
2311+
promptAccepted,
2312+
event("session.execution.succeeded", { sessionID: SESSION }),
2313+
],
2314+
{ onPrompt: (input) => prompts.push(input) },
2315+
);
2316+
const terminal = yield* terminalOf(runtime).pipe(Effect.forkScoped);
2317+
yield* runtime.startTurn({
2318+
...turnInput(thread),
2319+
message: { ...turnInput(thread).message, text: "$greet then echo $HOME" },
2320+
});
2321+
assert.equal((yield* Fiber.join(terminal))?.status, "completed");
2322+
assert.deepInclude(prompts[0], { skills: [{ id: "greet" }] });
2323+
}).pipe(Effect.scoped),
2324+
);
2325+
22922326
it.effect("keeps a turn still running after a reconnect open for its next events", () =>
22932327
Effect.gen(function* () {
22942328
const { runtime, thread } = yield* resumed([

‎packages/provider-opencode/src/server/v2/adapter.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3306,17 +3306,16 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
33063306
Effect.orElseSucceed(() => new Set<string>()),
33073307
);
33083308

3309-
// A directory OpenCode is still scanning lists none or some of its skills; its model list waits for the scan.
3309+
// A directory OpenCode is still scanning lists none or some of its skills.
3310+
// OpenCode 2.2.5 answers its model list only once the scan has ended (observed, not documented).
33103311
const skillsMentioned = Effect.fnUntraced(function* (
33113312
location: { readonly directory: string },
33123313
mentions: ReadonlyArray<string>,
33133314
) {
3314-
let known = yield* listSkills(location);
3315+
const known = yield* listSkills(location);
33153316
if (mentions.some((name) => !known.has(name))) {
3316-
yield* client.model
3317-
.list({ location })
3318-
.pipe(Effect.timeout(INVENTORY_TIMEOUT), Effect.ignore);
3319-
known = yield* listSkills(location);
3317+
yield* readModels(location.directory);
3318+
for (const name of yield* listSkills(location)) known.add(name);
33203319
}
33213320
return mentions.filter((name) => known.has(name));
33223321
});

0 commit comments

Comments
 (0)