Skip to content

Commit 7591027

Browse files
committed
Merge remote-tracking branch 'github/main' into fix/mobile-ime-custom-answer
2 parents f122be2 + 3cdc504 commit 7591027

16 files changed

Lines changed: 1135 additions & 61 deletions

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

Lines changed: 555 additions & 11 deletions
Large diffs are not rendered by default.

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ const operationOf = (
5454
query: Record<string, unknown>,
5555
body: unknown,
5656
) => {
57+
const rpc = /^\/api\/rpc\/([^/]+)\/([^/]+)$/.exec(path);
58+
if (method === "POST" && rpc !== null)
59+
return {
60+
type: "rpc.call",
61+
input: { rpcID: rpc[1], method: rpc[2], ...query, ...(body as object) },
62+
};
5763
const session = /^\/api\/session\/([^/]+)(\/.*)?$/.exec(path);
5864
if (method === "GET" && path === "/api/event") return { type: "event.subscribe" };
5965
if (method === "GET" && path === "/api/model") return { type: "model.list", input: query };
@@ -292,6 +298,7 @@ export const openCode2ReplayRuntime = (
292298
entries: ReadonlyArray<ProviderReplayEntry>,
293299
options?: {
294300
readonly external?: boolean;
301+
readonly version?: string;
295302
readonly onPrompt?: (input: unknown) => void;
296303
readonly borrowers?: { current: number };
297304
readonly replayGate?: ProviderReplayGate;
@@ -306,7 +313,7 @@ export const openCode2ReplayRuntime = (
306313
{
307314
provider: OPENCODE_PROVIDER,
308315
protocol: OPENCODE2_HTTP_PROTOCOL,
309-
version: "2.0.18",
316+
version: options?.version ?? "2.0.18",
310317
scenario: "opencode2_adapter",
311318
entries,
312319
},

‎apps/server/src/orchestration-v2/Orchestrator.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,9 +1168,12 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
11681168
command: OrchestrationV2ServerCommand,
11691169
providerInstanceId: ProviderInstanceId,
11701170
) {
1171-
const { driver } = yield* providerAdapters
1172-
.get(providerInstanceId)
1173-
.pipe(mapDispatchError(command));
1171+
const adapter = yield* providerAdapters.get(providerInstanceId).pipe(mapDispatchError(command));
1172+
const { driver } = adapter;
1173+
if (driver === "opencode") {
1174+
const capabilities = yield* adapter.getCapabilities().pipe(mapDispatchError(command));
1175+
return capabilities.turns.supportsNativeGoals === true ? driver : undefined;
1176+
}
11741177
return driver === "codex" || driver === "claudeAgent" ? driver : undefined;
11751178
});
11761179

@@ -6107,7 +6110,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
61076110
) {
61086111
dispatchMode = { type: "queue_after_active" };
61096112
}
6110-
// Codex and Claude own /goal; elsewhere it is ordinary text that cannot steer.
6113+
// Native goal commands must not steer an existing turn.
61116114
const parsedGoalCommand = parseGoalCommand(command);
61126115
const goalCommand =
61136116
parsedGoalCommand === null ||

‎apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ it.each([
269269

270270
function makeLocalCommandHarness(input: {
271271
readonly text: string;
272+
readonly nativeGoals?: boolean;
272273
readonly worktreePath?: string;
273274
readonly worktreesDir?: string;
274275
readonly workspaceRoot?: string;
@@ -337,7 +338,7 @@ function makeLocalCommandHarness(input: {
337338
};
338339
const providerThread: OrchestrationV2ThreadProjection["providerThreads"][number] = {
339340
id: providerThreadId,
340-
driver: ProviderDriverKind.make("codex"),
341+
driver: ProviderDriverKind.make(input.nativeGoals === undefined ? "codex" : "opencode"),
341342
providerInstanceId: newInstanceId,
342343
providerSessionId,
343344
appThreadId: threadId,
@@ -778,7 +779,13 @@ function makeLocalCommandHarness(input: {
778779
status: "ready",
779780
cwd: "/tmp/native-account-command",
780781
model: null,
781-
capabilities: CodexProviderCapabilitiesV2,
782+
capabilities: {
783+
...CodexProviderCapabilitiesV2,
784+
turns: {
785+
...CodexProviderCapabilitiesV2.turns,
786+
...(input.nativeGoals === undefined ? {} : { supportsNativeGoals: input.nativeGoals }),
787+
},
788+
},
782789
createdAt: now,
783790
updatedAt: now,
784791
lastError: null,
@@ -1338,6 +1345,23 @@ effectIt.effect.each([
13381345
}),
13391346
);
13401347

1348+
effectIt.effect.each([false, true])(
1349+
"OpenCode goal prompts defer switched-provider history only with native support: %s",
1350+
(nativeGoals) =>
1351+
Effect.gen(function* () {
1352+
const harness = makeLocalCommandHarness({
1353+
text: "/goal all tests pass",
1354+
nativeGoals,
1355+
sideChat: { contextRun: "failed", switchedProvider: true },
1356+
});
1357+
harness.tryHandlePromptCommand.mockReturnValue(Effect.succeed(false));
1358+
yield* harness.start;
1359+
expect(harness.startTurn.mock.calls[0]?.[0].message.text.includes("SIDE_CHAT_CONTEXT")).toBe(
1360+
!nativeGoals,
1361+
);
1362+
}),
1363+
);
1364+
13411365
effectIt.effect.each([
13421366
{ runStatus: "failed", turnStatus: "completed" },
13431367
{ runStatus: "completed", turnStatus: "completed" },

‎apps/server/src/orchestration-v2/ProviderTurnStartService.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -841,8 +841,12 @@ export const layer: Layer.Layer<
841841
text: message.text,
842842
records: message.context?.records ?? [],
843843
});
844-
// Codex and Claude parse /goal from the prompt, so it goes verbatim and history waits a turn.
845-
const goalDriver = session.driver === "codex" || session.driver === "claudeAgent";
844+
// Native goal commands go verbatim; handoff history waits a turn.
845+
const goalDriver =
846+
session.driver === "codex" ||
847+
session.driver === "claudeAgent" ||
848+
(session.driver === "opencode" &&
849+
session.providerSession.capabilities.turns.supportsNativeGoals === true);
846850
const goalCommand = goalDriver && parseGoalCommand(message) !== null;
847851
// The provider turn marks cancellation work delivered; restart continuations use their own text or resume natively.
848852
const noteContinuation = isRestartNoteContinuation(

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

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,9 @@ const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function*
488488
canSteer = true,
489489
interruptTurn: Effect.Effect<void> = Effect.void,
490490
steeringAcceptsAttachments = true,
491+
nativeGoals?: boolean,
491492
) {
493+
const driver = ProviderDriverKind.make(nativeGoals === undefined ? "codex" : "opencode");
492494
const cwd = yield* checkpointWorkspace(name);
493495
const events = yield* Queue.unbounded<ProviderAdapter.ProviderAdapterV2Event>();
494496
const started: ProviderAdapter.ProviderAdapterV2TurnInput[] = [];
@@ -501,6 +503,7 @@ const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function*
501503
supportsActiveSteering: canSteer,
502504
supportsSteeringByInterruptRestart: canRestart,
503505
activeSteeringAcceptsAttachments: steeringAcceptsAttachments,
506+
...(nativeGoals === undefined ? {} : { supportsNativeGoals: nativeGoals }),
504507
},
505508
};
506509
const adapter: ProviderAdapter.ProviderAdapterV2["Service"] = {
@@ -2060,8 +2063,15 @@ it.effect("queues a plain send behind the stopped queue and releases its hold",
20602063
),
20612064
);
20622065

2063-
const goalHarness = Effect.fn("goalHarness")(function* (name: string) {
2064-
const harness = yield* nextTurnSelectionHarness(name);
2066+
const goalHarness = Effect.fn("goalHarness")(function* (name: string, nativeGoals?: boolean) {
2067+
const harness = yield* nextTurnSelectionHarness(
2068+
name,
2069+
false,
2070+
true,
2071+
Effect.void,
2072+
true,
2073+
nativeGoals,
2074+
);
20652075
const send = (id: string, text: string, delivery: "queue" | "auto", freshContext = false) =>
20662076
Effect.gen(function* () {
20672077
const orchestrator = yield* Orchestrator.OrchestratorV2;
@@ -2101,26 +2111,34 @@ const goalHarness = Effect.fn("goalHarness")(function* (name: string) {
21012111
return { ...harness, send, read };
21022112
});
21032113

2104-
it.effect("stops the running turn and starts a goal sent into it next", () =>
2105-
Effect.scoped(
2106-
Effect.gen(function* () {
2107-
const { steered, layer, startFirstTurn, send, read } = yield* goalHarness("goal-steer");
2108-
yield* Effect.gen(function* () {
2109-
const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
2110-
const threadId = yield* startFirstTurn;
2111-
yield* send("queued", "queued", "queue");
2112-
yield* send("goal", "/goal all tests pass", "auto");
2113-
yield* worker.drain();
2114+
it.effect.each([undefined, false, true])(
2115+
"goal dispatch stops the active turn only with native support: %s",
2116+
(nativeGoals) =>
2117+
Effect.scoped(
2118+
Effect.gen(function* () {
2119+
const { steered, layer, startFirstTurn, send, read } = yield* goalHarness(
2120+
"goal-steer",
2121+
nativeGoals,
2122+
);
2123+
yield* Effect.gen(function* () {
2124+
const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
2125+
const threadId = yield* startFirstTurn;
2126+
yield* send("queued", "queued", "queue");
2127+
const sending = send("goal", "/goal all tests pass", "auto");
2128+
if (nativeGoals === false) {
2129+
yield* Effect.flip(sending);
2130+
} else yield* sending;
2131+
yield* worker.drain();
21142132

2115-
assert.deepEqual(steered, []);
2116-
assert.deepEqual(yield* read(threadId), {
2117-
queue: ["queued"],
2118-
started: ["first", "/goal all tests pass"],
2119-
stopRequested: true,
2120-
});
2121-
}).pipe(Effect.provide(layer));
2122-
}),
2123-
),
2133+
assert.deepEqual(steered, []);
2134+
assert.deepEqual(yield* read(threadId), {
2135+
queue: ["queued"],
2136+
started: nativeGoals === false ? ["first"] : ["first", "/goal all tests pass"],
2137+
stopRequested: nativeGoals !== false,
2138+
});
2139+
}).pipe(Effect.provide(layer));
2140+
}),
2141+
),
21242142
);
21252143

21262144
it.effect("starts a goal that names no model on the thread's model ahead of a queued pick", () =>

‎apps/server/src/project/ProjectEnrichmentService.test.ts‎

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { assert, it } from "@effect/vitest";
22
import type { RepositoryIdentity } from "@t3tools/contracts";
33
import * as Deferred from "effect/Deferred";
4+
import * as Duration from "effect/Duration";
45
import * as Effect from "effect/Effect";
6+
import * as Fiber from "effect/Fiber";
57
import * as Layer from "effect/Layer";
68
import * as PubSub from "effect/PubSub";
79
import * as Ref from "effect/Ref";
10+
import * as TestClock from "effect/testing/TestClock";
811

912
import * as ProjectEnrichment from "./ProjectEnrichmentService.ts";
1013
import * as ProjectFaviconResolver from "./ProjectFaviconResolver.ts";
@@ -257,3 +260,131 @@ it.effect("deduplicates requests, bounds pending work, and reloads invalidated r
257260
);
258261
}),
259262
);
263+
264+
it.effect(
265+
"keeps the last resolved repository identity after it expires and while it refreshes",
266+
() =>
267+
Effect.gen(function* () {
268+
const refreshStarted = yield* Deferred.make<void>();
269+
const releaseRefresh = yield* Deferred.make<void>();
270+
const resolveCalls = yield* Ref.make(0);
271+
const layerMetadata = Layer.merge(
272+
Layer.succeed(RepositoryIdentityResolver.RepositoryIdentityResolver, {
273+
resolve: (workspaceRoot) =>
274+
Effect.gen(function* () {
275+
if ((yield* Ref.updateAndGet(resolveCalls, (count) => count + 1)) > 1) {
276+
yield* Deferred.succeed(refreshStarted, undefined);
277+
yield* Deferred.await(releaseRefresh);
278+
}
279+
return identity(workspaceRoot);
280+
}),
281+
}),
282+
Layer.succeed(ProjectFaviconResolver.ProjectFaviconResolver, {
283+
invalidate: () => Effect.void,
284+
resolvePath: () => Effect.succeed(null),
285+
}),
286+
);
287+
288+
yield* Effect.gen(function* () {
289+
const service = yield* ProjectEnrichment.ProjectEnrichmentService;
290+
const changes = yield* service.subscribeChanges;
291+
yield* service.request("/widgets");
292+
const resolved = yield* PubSub.take(changes);
293+
assert.equal(
294+
resolved.enrichment.repositoryIdentity?.canonicalKey,
295+
"example.test/v1/widgets",
296+
);
297+
298+
yield* TestClock.adjust(Duration.seconds(61));
299+
300+
const expired = yield* service.getAvailable("/widgets");
301+
assert.equal(
302+
expired.repositoryIdentity?.canonicalKey,
303+
"example.test/v1/widgets",
304+
"an expired repository identity should still be returned until a refresh replaces it",
305+
);
306+
307+
yield* Deferred.await(refreshStarted);
308+
const refreshing = yield* service.peek("/widgets");
309+
assert.equal(
310+
refreshing.repositoryIdentity?.canonicalKey,
311+
"example.test/v1/widgets",
312+
"a repository identity should still be returned while its refresh is pending",
313+
);
314+
}).pipe(Effect.provide(layer(layerMetadata)));
315+
}),
316+
);
317+
318+
it.effect("does not let a lookup invalidated mid-flight replace a newer last identity", () =>
319+
Effect.gen(function* () {
320+
const firstStarted = yield* Deferred.make<void>();
321+
const releaseFirst = yield* Deferred.make<void>();
322+
const resolveCalls = yield* Ref.make(0);
323+
const layerMetadata = Layer.merge(
324+
Layer.succeed(RepositoryIdentityResolver.RepositoryIdentityResolver, {
325+
resolve: (workspaceRoot) =>
326+
Effect.gen(function* () {
327+
const call = yield* Ref.updateAndGet(resolveCalls, (count) => count + 1);
328+
if (call === 1) {
329+
yield* Deferred.succeed(firstStarted, undefined);
330+
yield* Deferred.await(releaseFirst);
331+
}
332+
return identity(workspaceRoot, call);
333+
}),
334+
}),
335+
Layer.succeed(ProjectFaviconResolver.ProjectFaviconResolver, {
336+
invalidate: () => Effect.void,
337+
resolvePath: () => Effect.succeed(null),
338+
}),
339+
);
340+
341+
yield* Effect.gen(function* () {
342+
const service = yield* ProjectEnrichment.ProjectEnrichmentService;
343+
const firstLookup = yield* Effect.forkChild(service.readRepositoryIdentity("/widgets"));
344+
yield* Deferred.await(firstStarted);
345+
yield* service.invalidate(["/widgets"]);
346+
const newer = yield* service.readRepositoryIdentity("/widgets");
347+
assert.equal(newer?.canonicalKey, "example.test/v2/widgets");
348+
349+
yield* Deferred.succeed(releaseFirst, undefined);
350+
yield* Fiber.join(firstLookup);
351+
yield* TestClock.adjust(Duration.seconds(61));
352+
353+
const expired = yield* service.peek("/widgets");
354+
assert.equal(expired.repositoryIdentity?.canonicalKey, "example.test/v2/widgets");
355+
}).pipe(Effect.provide(layer(layerMetadata)));
356+
}),
357+
);
358+
359+
it.effect("keeps a lookup's identity when another root is invalidated mid-flight", () =>
360+
Effect.gen(function* () {
361+
const started = yield* Deferred.make<void>();
362+
const release = yield* Deferred.make<void>();
363+
const layerMetadata = Layer.merge(
364+
Layer.succeed(RepositoryIdentityResolver.RepositoryIdentityResolver, {
365+
resolve: (workspaceRoot) =>
366+
Deferred.succeed(started, undefined).pipe(
367+
Effect.andThen(Deferred.await(release)),
368+
Effect.as(identity(workspaceRoot)),
369+
),
370+
}),
371+
Layer.succeed(ProjectFaviconResolver.ProjectFaviconResolver, {
372+
invalidate: () => Effect.void,
373+
resolvePath: () => Effect.succeed(null),
374+
}),
375+
);
376+
377+
yield* Effect.gen(function* () {
378+
const service = yield* ProjectEnrichment.ProjectEnrichmentService;
379+
const lookup = yield* Effect.forkChild(service.readRepositoryIdentity("/widgets"));
380+
yield* Deferred.await(started);
381+
yield* service.invalidate(["/other"]);
382+
yield* Deferred.succeed(release, undefined);
383+
yield* Fiber.join(lookup);
384+
yield* TestClock.adjust(Duration.seconds(61));
385+
386+
const expired = yield* service.peek("/widgets");
387+
assert.equal(expired.repositoryIdentity?.canonicalKey, "example.test/v1/widgets");
388+
}).pipe(Effect.provide(layer(layerMetadata)));
389+
}),
390+
);

0 commit comments

Comments
 (0)