fix(opencode): stop adding a "This chat uses OpenCode v2" row to chats (#10490)
The notice flagged chats moved to the then-new v2 runtime. v2 has been stable, so the row is noise. Previously saved openCodeRuntimeNotices metadata is left in place and no longer read.
This commit is contained in:
1 parent
fa37fd20ca
commit
b2ecec8719
4 files changed
+8
-197
No files matched your search
@@ -398,37 +398,11 @@ test("v2 native tool bridge preserves caller identity", async () => {
|
||||
}, 120_000);
|
||||
|
||||
test.each([
|
||||
{
|
||||
major: 1,
|
||||
package: "opencode-ai@1.14.46",
|
||||
windowsPackage: "opencode-windows",
|
||||
expectedTimeline: [],
|
||||
expectedInitialTimeline: undefined,
|
||||
expectedNotices: undefined,
|
||||
},
|
||||
{
|
||||
major: 2,
|
||||
package: "@opencode/cli@2.0.10",
|
||||
windowsPackage: "@opencode/cli-windows",
|
||||
expectedTimeline: [
|
||||
{ type: "notification", level: "info", message: "This chat uses OpenCode v2." },
|
||||
],
|
||||
expectedInitialTimeline: [
|
||||
expect.objectContaining({
|
||||
item: { type: "notification", level: "info", message: "This chat uses OpenCode v2." },
|
||||
}),
|
||||
],
|
||||
expectedNotices: [expect.objectContaining({ major: 2 })],
|
||||
},
|
||||
{ major: 1, package: "opencode-ai@1.14.46", windowsPackage: "opencode-windows" },
|
||||
{ major: 2, package: "@opencode/cli@2.0.10", windowsPackage: "@opencode/cli-windows" },
|
||||
])(
|
||||
"versioned runtime v$major discovers models and preserves a native session handle",
|
||||
async ({
|
||||
package: cliPackage,
|
||||
windowsPackage,
|
||||
expectedTimeline,
|
||||
expectedInitialTimeline,
|
||||
expectedNotices,
|
||||
}) => {
|
||||
async ({ package: cliPackage, windowsPackage }) => {
|
||||
const root = await mkdtemp(path.join(os.tmpdir(), "paseo-opencode-versioned-"));
|
||||
const client = new OpenCodeRuntimeClient(createTestLogger(), {
|
||||
command: {
|
||||
@@ -488,15 +462,14 @@ test.each([
|
||||
{ persistSession: false },
|
||||
);
|
||||
const handle = await original.describePersistence();
|
||||
expect(original.initialTimeline).toEqual(expectedInitialTimeline);
|
||||
expect(handle.metadata?.openCodeRuntimeNotices).toEqual(expectedNotices);
|
||||
expect(original.initialTimeline).toBeUndefined();
|
||||
resumed = await client.resumeSession(handle, { cwd: root });
|
||||
expect((await resumed.describePersistence()).nativeHandle).toBe(handle.nativeHandle);
|
||||
expect(
|
||||
(await drainPersistedTimeline(resumed)).map((event) =>
|
||||
event.type === "timeline" ? event.item : event,
|
||||
),
|
||||
).toEqual(expectedTimeline);
|
||||
).toEqual([]);
|
||||
} finally {
|
||||
await resumed?.close();
|
||||
await original?.close();
|
||||
|
||||
@@ -18,44 +18,6 @@ test.each(["3.0.0", "2.0.9", "2.0.7", "2.0.4", "2.0.3", "v2.0.1"])(
|
||||
},
|
||||
);
|
||||
|
||||
test("records the runtime once and retains its position across resume", async () => {
|
||||
const { withOpenCodeRuntimeNotice } = await import("./runtime-notice.js");
|
||||
const { V2Harness } = await import("./test-utils/v2-harness.js");
|
||||
const { OpenCodeV2AgentClient } = await import("./v2/agent.js");
|
||||
const { createTestLogger } = await import("../../../../test-utils/test-logger.js");
|
||||
const harness = new V2Harness();
|
||||
const client = new OpenCodeV2AgentClient({
|
||||
logger: createTestLogger(),
|
||||
runtime: harness.runtime,
|
||||
});
|
||||
const original = withOpenCodeRuntimeNotice(
|
||||
await client.createSession({ provider: "opencode", cwd: "/tmp/project" }),
|
||||
2,
|
||||
);
|
||||
const notice = { type: "notification", level: "info", message: "This chat uses OpenCode v2." };
|
||||
try {
|
||||
expect(original.initialTimeline?.map((entry) => entry.item)).toEqual([notice]);
|
||||
const handle = original.describePersistence()!;
|
||||
await original.close();
|
||||
const resumed = withOpenCodeRuntimeNotice(await client.resumeSession(handle), 2, handle);
|
||||
try {
|
||||
expect(resumed.initialTimeline).toEqual([]);
|
||||
const history = [];
|
||||
for await (const event of resumed.streamHistory()) history.push(event);
|
||||
expect(history).toEqual([
|
||||
{ type: "timeline", provider: "opencode", ...original.initialTimeline![0] },
|
||||
]);
|
||||
expect(resumed.describePersistence()?.metadata?.openCodeRuntimeNotices).toEqual(
|
||||
handle.metadata?.openCodeRuntimeNotices,
|
||||
);
|
||||
} finally {
|
||||
await resumed.close();
|
||||
}
|
||||
} finally {
|
||||
await client.shutdown();
|
||||
}
|
||||
});
|
||||
|
||||
test("retries a rejected version probe after the configured binary changes", async () => {
|
||||
const { mkdtemp, writeFile, rm } = await import("node:fs/promises");
|
||||
const { tmpdir } = await import("node:os");
|
||||
@@ -218,59 +180,6 @@ test.each([0, 1, 2, 3, 4, 5, 6, 8])(
|
||||
},
|
||||
);
|
||||
|
||||
test("appends a first notice after old history and records a changed major version", async () => {
|
||||
const { withOpenCodeRuntimeNotice } = await import("./runtime-notice.js");
|
||||
const { V2Harness } = await import("./test-utils/v2-harness.js");
|
||||
const { OpenCodeV2AgentClient } = await import("./v2/agent.js");
|
||||
const { createTestLogger } = await import("../../../../test-utils/test-logger.js");
|
||||
const harness = new V2Harness();
|
||||
harness.history.push({ id: "old", type: "user", text: "Earlier prompt", time: { created: 1 } });
|
||||
const client = new OpenCodeV2AgentClient({
|
||||
logger: createTestLogger(),
|
||||
runtime: harness.runtime,
|
||||
});
|
||||
const previous = {
|
||||
provider: "opencode",
|
||||
sessionId: "session",
|
||||
metadata: { cwd: "/tmp/project" },
|
||||
};
|
||||
const session = withOpenCodeRuntimeNotice(await client.resumeSession(previous), 2, previous);
|
||||
try {
|
||||
const history = [];
|
||||
for await (const event of session.streamHistory()) history.push(event);
|
||||
expect(history).toEqual([
|
||||
expect.objectContaining({
|
||||
type: "timeline",
|
||||
item: { type: "user_message", text: "Earlier prompt", messageId: "old" },
|
||||
}),
|
||||
expect.objectContaining({
|
||||
type: "timeline",
|
||||
item: { type: "notification", level: "info", message: "This chat uses OpenCode v2." },
|
||||
}),
|
||||
]);
|
||||
await session.close();
|
||||
const v1Handle = {
|
||||
...previous,
|
||||
metadata: {
|
||||
...previous.metadata,
|
||||
openCodeRuntimeNotices: [{ major: 1, timestamp: "2026-01-01T00:00:00.000Z" }],
|
||||
},
|
||||
};
|
||||
const changed = withOpenCodeRuntimeNotice(await client.resumeSession(v1Handle), 2, v1Handle);
|
||||
try {
|
||||
expect(changed.initialTimeline?.map((entry) => entry.item)).toEqual([
|
||||
{ type: "notification", level: "info", message: "This chat uses OpenCode v2." },
|
||||
]);
|
||||
expect(changed.describePersistence()?.metadata?.openCodeRuntimeNotices).toHaveLength(2);
|
||||
} finally {
|
||||
await changed.close();
|
||||
}
|
||||
} finally {
|
||||
await session.close();
|
||||
await client.shutdown();
|
||||
}
|
||||
});
|
||||
|
||||
test.each([
|
||||
"process.exit(1)",
|
||||
'console.log("custom wrapper output")',
|
||||
|
||||
@@ -22,7 +22,6 @@ import { execCommand } from "../../../../utils/spawn.js";
|
||||
import { OpenCodeAgentClient } from "../opencode-agent.js";
|
||||
import type { OpenCodeV2AgentClient } from "./v2/agent.js";
|
||||
import { resolveExternalOpenCodeServer } from "./v2/external-server.js";
|
||||
import { withOpenCodeRuntimeNotice } from "./runtime-notice.js";
|
||||
import { selectOpenCodeService } from "./v2/service-selection.js";
|
||||
import { createCliInstallation } from "../cli-installation.js";
|
||||
|
||||
@@ -165,9 +164,7 @@ export class OpenCodeRuntimeClient implements AgentClient {
|
||||
launch?: AgentLaunchContext,
|
||||
options?: AgentCreateSessionOptions,
|
||||
) {
|
||||
const client = await this.client();
|
||||
const session = await client.createSession(config, launch, options);
|
||||
return client === this.legacy ? session : withOpenCodeRuntimeNotice(session, 2);
|
||||
return (await this.client()).createSession(config, launch, options);
|
||||
}
|
||||
async resumeSession(
|
||||
handle: AgentPersistenceHandle,
|
||||
@@ -175,9 +172,7 @@ export class OpenCodeRuntimeClient implements AgentClient {
|
||||
launch?: AgentLaunchContext,
|
||||
options?: AgentResumeSessionOptions,
|
||||
) {
|
||||
const client = await this.client();
|
||||
const session = await client.resumeSession(handle, config, launch, options);
|
||||
return client === this.legacy ? session : withOpenCodeRuntimeNotice(session, 2, handle);
|
||||
return (await this.client()).resumeSession(handle, config, launch, options);
|
||||
}
|
||||
async fetchCatalog(options: FetchCatalogOptions, context?: ProviderRefreshContext) {
|
||||
if (options.force) await this.reprobeLegacySelection();
|
||||
@@ -202,11 +197,7 @@ export class OpenCodeRuntimeClient implements AgentClient {
|
||||
return (await this.client()).listImportableSessions(options);
|
||||
}
|
||||
async importSession(input: ImportProviderSessionInput, context: ImportProviderSessionContext) {
|
||||
const client = await this.client();
|
||||
const imported = await client.importSession(input, context);
|
||||
return client === this.legacy
|
||||
? imported
|
||||
: { ...imported, session: withOpenCodeRuntimeNotice(imported.session, 2) };
|
||||
return (await this.client()).importSession(input, context);
|
||||
}
|
||||
async archiveNativeSession(handle: AgentPersistenceHandle) {
|
||||
const client = await this.client();
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
import { z } from "zod";
|
||||
import type {
|
||||
AgentPersistenceHandle,
|
||||
AgentSession,
|
||||
AgentStreamEvent,
|
||||
ImportedTimelineEntry,
|
||||
} from "../../agent-sdk-types.js";
|
||||
|
||||
const Notices = z.array(
|
||||
z.object({ major: z.union([z.literal(1), z.literal(2)]), timestamp: z.string().datetime() }),
|
||||
);
|
||||
|
||||
// These rows belong to Paseo, not OpenCode's conversation. Keep their original
|
||||
// timestamps in the persistence handle so history rebuilds preserve placement.
|
||||
export function withOpenCodeRuntimeNotice(
|
||||
session: AgentSession,
|
||||
major: 1 | 2,
|
||||
previous?: AgentPersistenceHandle,
|
||||
): AgentSession {
|
||||
const notices = Notices.parse(previous?.metadata?.openCodeRuntimeNotices ?? []);
|
||||
const added = notices.at(-1)?.major !== major;
|
||||
if (added) notices.push({ major, timestamp: new Date().toISOString() });
|
||||
const entries: ImportedTimelineEntry[] = notices.map(({ major: recordedMajor, timestamp }) => ({
|
||||
timestamp,
|
||||
item: {
|
||||
type: "notification",
|
||||
level: "info",
|
||||
message: `This chat uses OpenCode v${recordedMajor}.`,
|
||||
},
|
||||
}));
|
||||
const describePersistence = session.describePersistence.bind(session);
|
||||
const streamHistory = session.streamHistory.bind(session);
|
||||
return Object.assign(session, {
|
||||
initialTimeline: added ? entries.slice(-1) : [],
|
||||
describePersistence() {
|
||||
const handle = describePersistence();
|
||||
return (
|
||||
handle && { ...handle, metadata: { ...handle.metadata, openCodeRuntimeNotices: notices } }
|
||||
);
|
||||
},
|
||||
async *streamHistory(): AsyncGenerator<AgentStreamEvent> {
|
||||
const pending = [...entries];
|
||||
const event = (entry: ImportedTimelineEntry): AgentStreamEvent => ({
|
||||
type: "timeline",
|
||||
provider: "opencode",
|
||||
...entry,
|
||||
});
|
||||
for await (const row of streamHistory()) {
|
||||
while (
|
||||
row.type === "timeline" &&
|
||||
row.timestamp &&
|
||||
pending[0]?.timestamp &&
|
||||
pending[0].timestamp <= row.timestamp
|
||||
) {
|
||||
yield event(pending.shift()!);
|
||||
}
|
||||
yield row;
|
||||
}
|
||||
for (const entry of pending) yield event(entry);
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user