GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(opencode): cut forks before slash commands (#44982) · pingdotgg/t3code@1237bd9

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/orchestration-v2
    • OpenCode2OrchestratorV2.integration.test.ts
  • packages/provider-opencode/src/server/v2
    • adapter.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/orchestration-v2/OpenCode2OrchestratorV2.integration.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/OpenCode2OrchestratorV2.integration.test.ts
+45-5Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,24 +442,64 @@ describe("OpenCode 2 through the orchestrator", () => {
442442
}),
443443
);
444444

445-
it.effect("forks from an earlier turn before the next turn's user message", () =>
445+
it.effect.each(["prompt", "slash command"])("forks before the next %s", (nextTurn) =>
446446
Effect.gen(function* () {
447447
const name = "opencode2-fork";
448448
const cwd = yield* checkpointWorkspace(name);
449449
const recorded = yield* readProviderReplayTranscript(
450450
new URL("./testkit/fixtures/opencode2_fork/opencode_transcript.ndjson", import.meta.url),
451451
);
452452

453+
const sessionID = String(recorded.metadata?.["nativeSessionId"]);
454+
const entries = recorded.entries.flatMap((entry): ReadonlyArray<ProviderReplayEntry> => {
455+
if (nextTurn === "prompt" || entry.type === "runtime_exit") return [entry];
456+
if (entry.label === "session.prompt.2") {
457+
return [
458+
out("command.list", "<any>"),
459+
reply("command.list", { location: { directory: cwd }, data: [{ name: "hello" }] }),
460+
out("message.list", { sessionID, order: "desc", limit: "1" }),
461+
reply("message.list", {
462+
data: [
463+
{ id: "msg_idle_one", type: "idle", time: { created: 1 }, outcome: "succeeded" },
464+
],
465+
cursor: { previous: "after-turn-one" },
466+
}),
467+
out("session.command", { sessionID, name: "hello", text: "TWO" }),
468+
reply("session.command", null),
469+
out("session.active"),
470+
reply("session.active", { data: { [sessionID]: { type: "running" } } }),
471+
];
472+
}
473+
if (entry.label === "message.list") {
474+
return [
475+
out("message.list", { sessionID, cursor: "after-turn-one", limit: "1" }),
476+
reply("message.list", {
477+
data: [
478+
{
479+
id: "msg_0eb7b1f9f001g95Bduh3bi8syS",
480+
type: "user",
481+
time: { created: 2 },
482+
text: "Reply exactly TWO.",
483+
},
484+
],
485+
cursor: {},
486+
}),
487+
];
488+
}
489+
return entry.label === "session.prompt.response.2" ||
490+
entry.label?.startsWith("message.list.")
491+
? []
492+
: [entry];
493+
});
453494
const transcript = yield* OpenCode2OrchestratorReplayHarness.decodeTranscript(
454-
withDirectory(recorded, cwd),
495+
withDirectory({ ...recorded, entries }, cwd),
455496
);
456497
const source = threadCommands({ name, worktreePath: cwd });
457498
const target = ThreadId.make(`thread:${name}:target`);
458-
const [one, two] = [source.message("one"), source.message("two")];
459499
const commands: ReadonlyArray<OrchestrationV2Command> = [
460500
source.create,
461-
one,
462-
two,
501+
source.message("one"),
502+
source.message("two", bigPickle, nextTurn === "slash command" ? "/hello TWO" : undefined),
463503
{
464504
type: "thread.fork",
465505
createdBy: "user",
Collapse file

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

Copy file name to clipboardExpand all lines: packages/provider-opencode/src/server/v2/adapter.ts
+53-36Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -740,33 +740,7 @@ const promptOf = (turn: OrchestrationV2ProviderTurn) => {
740740
return nativeId?.startsWith("msg_") === true ? nativeId : undefined;
741741
};
742742

743-
const boundaryAfter = (
744-
turns: ReadonlyArray<OrchestrationV2ProviderTurn>,
745-
providerThreadId: OrchestrationV2ProviderThread["id"],
746-
kept: OrchestrationV2ProviderTurn | undefined,
747-
prompts: ReadonlySet<string>,
748-
) => {
749-
const later = turns
750-
.filter(
751-
(turn) =>
752-
turn.providerThreadId === providerThreadId &&
753-
(kept === undefined || turn.ordinal > kept.ordinal),
754-
)
755-
.toSorted((left, right) => left.ordinal - right.ordinal);
756-
if (later.some((turn) => promptOf(turn) === undefined && !isWakeTurn(turn))) {
757-
return Effect.fail(
758-
new ProviderAdapter.ProviderAdapterProtocolError({
759-
driver: OPENCODE_PROVIDER,
760-
detail:
761-
"This OpenCode conversation has turns from an earlier T3 Code version, so it can't be cut there.",
762-
}),
763-
);
764-
}
765-
return Effect.succeed(
766-
later.map(promptOf).find((messageId) => messageId !== undefined && prompts.has(messageId)) ??
767-
null,
768-
);
769-
};
743+
const COMMAND_CURSOR = "command-cursor:";
770744

771745
const isProviderAdapterError = Schema.is(ProviderAdapter.ProviderAdapterV2Error);
772746

@@ -4364,6 +4338,47 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
43644338
),
43654339
);
43664340

4341+
const boundaryAfter = Effect.fnUntraced(function* (
4342+
sessionId: string,
4343+
turns: ReadonlyArray<OrchestrationV2ProviderTurn>,
4344+
providerThreadId: OrchestrationV2ProviderThread["id"],
4345+
kept: OrchestrationV2ProviderTurn | undefined,
4346+
operation: "fork" | "rollback",
4347+
) {
4348+
const later = turns
4349+
.filter(
4350+
(turn) =>
4351+
turn.providerThreadId === providerThreadId &&
4352+
turn.ordinal > (kept?.ordinal ?? 0) &&
4353+
!turn.promptDropped &&
4354+
!isWakeTurn(turn),
4355+
)
4356+
.toSorted((left, right) => left.ordinal - right.ordinal);
4357+
let prompts = operation === "rollback" ? yield* userMessages(sessionId) : undefined;
4358+
for (const turn of later) {
4359+
const id = turn.nativeTurnRef?.nativeId;
4360+
if (id?.startsWith(COMMAND_CURSOR)) {
4361+
const cursor = id.slice(COMMAND_CURSOR.length);
4362+
const page = yield* client.message.list({
4363+
sessionID: Session.ID.make(sessionId),
4364+
...(cursor ? { cursor } : { order: "asc" }),
4365+
limit: 1,
4366+
});
4367+
return page.data[0]?.id ?? null;
4368+
}
4369+
prompts ??= yield* userMessages(sessionId, ["user", "synthetic"]);
4370+
if (id && prompts.has(id)) return id;
4371+
if (operation === "fork" || promptOf(turn) === undefined) {
4372+
return yield* new ProviderAdapter.ProviderAdapterProtocolError({
4373+
driver: OPENCODE_PROVIDER,
4374+
detail:
4375+
"T3 Code could not locate the exact turn boundary in this OpenCode conversation.",
4376+
});
4377+
}
4378+
}
4379+
return null;
4380+
});
4381+
43674382
const snapshotOf = Effect.fnUntraced(function* (
43684383
providerThread: OrchestrationV2ProviderThread,
43694384
sessionId: string,
@@ -4534,12 +4549,6 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
45344549
}
45354550
});
45364551

4537-
const markBefore = (sessionId: string, before: string | null) =>
4538-
Effect.sync(() => {
4539-
const turn = threads.get(sessionId)?.active;
4540-
if (turn !== undefined) turn.before = before;
4541-
});
4542-
45434552
const beginTurn = Effect.fn("OpenCode2Adapter.beginTurn")(function* (
45444553
state: ThreadState,
45454554
turnInput: ProviderAdapter.ProviderAdapterV2TurnInput,
@@ -4812,8 +4821,14 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
48124821
// session.command neither accepts nor returns our ID; record the preceding history boundary.
48134822
const newest = yield* client.message.list({ sessionID, order: "desc", limit: 1 });
48144823
const before = newest.data[0]?.id ?? null;
4815-
yield* markBefore(sessionId, before);
48164824
if (!sending()) return;
4825+
turn.before = before;
4826+
if (newest.cursor.previous !== undefined || before === null) {
4827+
turn.providerTurn = {
4828+
...turn.providerTurn,
4829+
nativeTurnRef: ref(COMMAND_CURSOR + (newest.cursor.previous ?? ""), "weak"),
4830+
};
4831+
}
48174832
if (goalCommand?.type === "pause" || goalCommand?.type === "clear") {
48184833
// OpenCode rejects pausing or clearing a missing goal; Codex treats that as a no-op.
48194834
yield* client.session.command({ sessionID, ...command }).pipe(
@@ -5568,10 +5583,11 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
55685583
yield* ensureQuiet(sessionId, "roll back");
55695584
}
55705585
const boundary = yield* boundaryAfter(
5586+
sessionId,
55715587
rollbackInput.providerThreadTurns,
55725588
providerThread.id,
55735589
target.type === "provider_turn" ? target.providerTurn : undefined,
5574-
yield* userMessages(sessionId),
5590+
"rollback",
55755591
);
55765592
if (boundary !== null) {
55775593
yield* rollBackTo(sessionId, SessionMessage.ID.make(boundary));
@@ -5613,10 +5629,11 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
56135629
selected === undefined
56145630
? null
56155631
: yield* boundaryAfter(
5632+
sourceId,
56165633
forkInput.sourceProviderTurns ?? [],
56175634
source.id,
56185635
selected,
5619-
yield* userMessages(sourceId, ["user", "synthetic"]),
5636+
"fork",
56205637
);
56215638
const forked = yield* client.session.fork({
56225639
sessionID: Session.ID.make(sourceId),

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.