Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions packages/provider-opencode/src/server/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,62 @@ describe("OpenCodeAdapterV2", () => {
),
);

it.effect("drops cancelled OpenCode todos so a finished list completes", () =>
Effect.gen(function* () {
const nativeEvents = asyncEventStream();
const nativeSessionId = "native-opencode-todos";
const harness = yield* makeOpenCodeRuntimeHarness("todos", nativeSessionId, {
event: {
subscribe: async (_input: unknown, options: { signal?: AbortSignal }) => {
options.signal?.addEventListener("abort", () => nativeEvents.close(), { once: true });
return { stream: nativeEvents.stream };
},
},
mcp: { status: async () => ({ data: {} }) },
session: {
create: async () => ({
data: { id: nativeSessionId, time: { created: 1, updated: 1 } },
}),
promptAsync: async () => ({ data: true }),
},
});
yield* harness.startTurn();
const received = yield* harness.runtime.events.pipe(
Stream.takeUntil((event) => event.type === "plan.updated"),
Stream.runCollect,
Effect.forkScoped,
);
yield* Effect.promise(() =>
nativeEvents.push({
type: "todo.updated",
properties: {
sessionID: nativeSessionId,
todos: [
{ content: "Write the fix", status: "completed", priority: "high" },
{ content: "Try another approach", status: "cancelled", priority: "low" },
{ content: "Add a test", status: "completed", priority: "medium" },
],
},
}),
);
const plan = (yield* Fiber.join(received)).flatMap((event) =>
event.type === "plan.updated" ? [event.plan] : [],
)[0];
assert.ok(plan?.kind === "todo_list");
assert.deepEqual(
plan.steps.map((step) => ({ text: step.text, status: step.status })),
[
{ text: "Write the fix", status: "completed" },
{ text: "Add a test", status: "completed" },
],
);
assert.equal(plan.status, "completed");
}).pipe(
Effect.provide(Layer.merge(IdAllocator.layer, McpProviderSessions.layer)),
Effect.scoped,
),
);

it.effect("presents OpenCode MCP calls without treating remote tools as local edits", () =>
Effect.gen(function* () {
const output =
Expand Down
30 changes: 19 additions & 11 deletions packages/provider-opencode/src/server/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1665,17 +1665,25 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
driver: OPENCODE_PROVIDER,
nativeItemId,
});
const steps: Array<OrchestrationV2PlanStep> = todos.map((todo, index) => ({
id: `${nativeItemId}:${index + 1}`,
text: todo.content.trim() || `Todo ${index + 1}`,
status:
todo.status === "completed"
? "completed"
: todo.status === "in_progress"
? "running"
: "pending",
}));
const completed = steps.length > 0 && steps.every((step) => step.status === "completed");
// A cancelled todo is not outstanding work, and plan steps have no
// cancelled status, so drop it rather than show it as pending.
const steps: Array<OrchestrationV2PlanStep> = todos.flatMap((todo, index) =>
todo.status === "cancelled"
? []
: [
{
id: `${nativeItemId}:${index + 1}`,
text: todo.content.trim() || `Todo ${index + 1}`,
status:
todo.status === "completed"
? "completed"
: todo.status === "in_progress"
? "running"
: "pending",
},
],
);
const completed = todos.length > 0 && steps.every((step) => step.status === "completed");
yield* emitProviderEvent({
type: "node.updated",
driver: OPENCODE_PROVIDER,
Expand Down
Loading