Skip to content
Closed
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
14 changes: 14 additions & 0 deletions apps/server/src/mcp/OrchestratorMcpToolkit.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,20 @@ describe("orchestrator MCP toolkit", () => {
expect(finalProjection.runs.find((run) => run.id === queuedFollowup.runId)?.status).toBe(
"completed",
);
for (const body of [delegatedPrompt, cancellationPrompt, queuedFollowupPrompt]) {
expect(finalProjection.messages.find((message) => message.text === body)).toMatchObject(
{
text: body,
createdBy: "agent",
senderThreadId: parentThreadId,
},
);
}
expect(
finalProjection.messages.some((message) =>
message.text.startsWith("Agent-authored message"),
),
).toBe(false);
expect(
finalProjection.turnItems.find(
(item) =>
Expand Down
104 changes: 104 additions & 0 deletions apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import * as Exit from "effect/Exit";
import { TestClock } from "effect/testing";

import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
import { providerTextForTurn } from "@t3tools/shared/agentSendProvenance";
import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions";
import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions";
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
Expand Down Expand Up @@ -2230,6 +2231,109 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
}).pipe(Effect.scoped),
);

it.effect("keeps an agent /hello on the native command after the sender line", () =>
Effect.gen(function* () {
const { runtime, thread } = yield* resumed([
out("command.list", "<any>"),
reply("command.list", { location: { directory: WORK }, data: [{ name: "hello" }] }),
out("message.list", { sessionID: SESSION, order: "desc", limit: "1" }),
reply("message.list", {
data: [
{ id: "msg_idle_before", time: { created: 1 }, type: "idle", outcome: "succeeded" },
],
cursor: {},
}),
out("session.command", { sessionID: SESSION, name: "hello", text: "WORLD" }),
reply("session.command", null),
{ type: "runtime_exit", status: "success" } as const,
out("event.subscribe"),
out("session.active"),
replyData("session.active", {}),
out("message.list", { sessionID: SESSION, order: "desc", limit: "50" }),
reply("message.list", {
data: [
{ id: "msg_idle_cmd", time: { created: 4 }, type: "idle", outcome: "succeeded" },
{
id: "msg_assistant_cmd",
time: { created: 3 },
type: "assistant",
agent: "build",
model: { id: "big-pickle", providerID: "opencode", variant: "default" },
content: [{ type: "text", text: "HELLO WORLD" }],
finish: "stop",
},
{
id: "msg_user_cmd",
time: { created: 2 },
text: "Reply with exactly: HELLO WORLD",
type: "user",
},
{ id: "msg_idle_before", time: { created: 1 }, type: "idle", outcome: "succeeded" },
],
cursor: {},
}),
]);
const text = yield* providerTextForTurn({
text: "/hello WORLD",
createdBy: "agent",
senderThreadId: ThreadId.make("thread:child-review"),
readSenderTitle: () => Effect.die("commands do not look up a sender"),
readReceiverSubagents: () => Effect.die("commands do not look up a sender"),
});
assert.equal(text, "/hello WORLD");
const events = yield* runtime.events.pipe(
Stream.takeUntil((event) => event.type === "turn.terminal"),
Stream.runCollect,
Effect.forkScoped,
);
yield* runtime.startTurn({
...turnInput(thread),
message: { ...turnInput(thread).message, text },
});
const collected = yield* Fiber.join(events);
assert.deepInclude(collected.at(-1), { type: "turn.terminal", status: "completed" });
}).pipe(Effect.scoped),
);

it.effect("keeps an agent /hello with a file on the raw prompt", () =>
Effect.gen(function* () {
const prompts: Array<{ readonly text?: string }> = [];
const notes = ChatFileAttachment.make({
type: "file",
id: ChatAttachmentId.make("thread-opencode2-adapter-45678901-1234-1234-1234-123456789abc"),
name: "notes.txt",
mimeType: "text/plain",
sizeBytes: 4,
});
const { runtime, thread } = yield* resumed(
[
out("session.prompt", { sessionID: SESSION, text: "<any>" }),
promptAccepted,
event("session.execution.succeeded", { sessionID: SESSION }),
],
{ onPrompt: (input) => prompts.push(input as { readonly text?: string }) },
);
const text = yield* providerTextForTurn({
text: "/hello WORLD",
createdBy: "agent",
senderThreadId: ThreadId.make("thread:child-review"),
readSenderTitle: () => Effect.die("commands do not look up a sender"),
readReceiverSubagents: () => Effect.die("commands do not look up a sender"),
});
assert.equal(text, "/hello WORLD");
const terminal = yield* terminalOf(runtime).pipe(Effect.forkScoped);
const input = turnInput(thread);
yield* runtime.startTurn({
...input,
message: { ...input.message, text, attachments: [notes] },
});
assert.equal((yield* Fiber.join(terminal))?.status, "completed");
assert.equal(prompts.length, 1);
assert.match(prompts[0]?.text ?? "", /^\/hello WORLD/);
assert.notMatch(prompts[0]?.text ?? "", /Agent-authored/);
}).pipe(Effect.scoped),
);

it.effect("keeps a turn still running after a reconnect open for its next events", () =>
Effect.gen(function* () {
const { runtime, thread } = yield* resumed([
Expand Down
Loading
Loading