mirror of
https://github.com/Heretek-AI/opencode.git
synced 2026-11-22 00:45:12 -10:00
+21

![opencode-agent[bot]](/assets/img/avatar_default.png)



![opencode-agent[bot]](/assets/img/avatar_default.png)



James Long
Brendan Allan
Kit Langton
opencode-agent[bot]
Affan Ali
affanali2k3
Frank
opencode-agent[bot]
𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴
Aiden Cline
Jay V
Dax Raad
Aarav Sareen
OpeOginni
Luke Parker
Ben Guthrie
Dax
Filip
Max Anderson
Brendan Allan
Jack
Shoubhit Dash
Dustin Deus
starptech
Aiden Cline
usrnk1
Jay
runvip
opencode
Julian Coy
Vladimir Glafirov
8c94e9005f
Co-authored-by: Brendan Allan <[email protected]> Co-authored-by: Kit Langton <[email protected]> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Affan Ali <[email protected]> Co-authored-by: affanali2k3 <[email protected]> Co-authored-by: Frank <[email protected]> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴 <[email protected]> Co-authored-by: Aiden Cline <[email protected]> Co-authored-by: Jay V <[email protected]> Co-authored-by: Dax Raad <[email protected]> Co-authored-by: Aarav Sareen <[email protected]> Co-authored-by: OpeOginni <[email protected]> Co-authored-by: Luke Parker <[email protected]> Co-authored-by: Ben Guthrie <[email protected]> Co-authored-by: Dax <[email protected]> Co-authored-by: Filip <[email protected]> Co-authored-by: Max Anderson <[email protected]> Co-authored-by: Brendan Allan <[email protected]> Co-authored-by: Jack <[email protected]> Co-authored-by: Shoubhit Dash <[email protected]> Co-authored-by: Dustin Deus <[email protected]> Co-authored-by: starptech <[email protected]> Co-authored-by: Aiden Cline <[email protected]> Co-authored-by: usrnk1 <[email protected]> Co-authored-by: Jay <[email protected]> Co-authored-by: runvip <[email protected]> Co-authored-by: opencode <[email protected]> Co-authored-by: Julian Coy <[email protected]> Co-authored-by: Vladimir Glafirov <[email protected]>
130 lines
4.9 KiB
TypeScript
130 lines
4.9 KiB
TypeScript
import { expect, test } from "bun:test"
|
|
import { LLMClient, LLMEvent, Model, type LLMRequest } from "@opencode-ai/llm"
|
|
import { OpenAIChat } from "@opencode-ai/llm/protocols"
|
|
import { Config } from "@opencode-ai/core/config"
|
|
import { Database } from "@opencode-ai/core/database/database"
|
|
import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
|
|
import { llmClient } from "@opencode-ai/core/effect/app-node-platform"
|
|
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
|
|
import { EventV2 } from "@opencode-ai/core/event"
|
|
import { EventTable } from "@opencode-ai/core/event/sql"
|
|
import { SessionCompaction } from "@opencode-ai/core/session/compaction"
|
|
import { SessionEvent } from "@opencode-ai/core/session/event"
|
|
import { SessionMessage } from "@opencode-ai/core/session/message"
|
|
import { SessionProjector } from "@opencode-ai/core/session/projector"
|
|
import { SessionRunnerModel } from "@opencode-ai/core/session/runner/model"
|
|
import { SessionTable } from "@opencode-ai/core/session/sql"
|
|
import { SessionStore } from "@opencode-ai/core/session/store"
|
|
import { SessionV2 } from "@opencode-ai/core/session"
|
|
import { Project } from "@opencode-ai/core/project"
|
|
import { ProjectTable } from "@opencode-ai/core/project/sql"
|
|
import { AbsolutePath } from "@opencode-ai/core/schema"
|
|
import { DateTime, Effect, Layer, Stream } from "effect"
|
|
import { asc, eq } from "drizzle-orm"
|
|
import { testEffect } from "./lib/effect"
|
|
|
|
let requests: LLMRequest[] = []
|
|
const model = Model.make({
|
|
id: "summary-model",
|
|
provider: "test",
|
|
route: OpenAIChat.route.with({ limits: { context: 10_000, output: 1_000 } }),
|
|
})
|
|
const client = Layer.mock(LLMClient.Service)({
|
|
prepare: () => Effect.die("unused"),
|
|
stream: (request: LLMRequest) => {
|
|
requests.push(request)
|
|
return Stream.make(LLMEvent.textDelta({ id: "summary", text: "manual summary" }))
|
|
},
|
|
generate: () => Effect.die("unused"),
|
|
})
|
|
const config = Layer.mock(Config.Service)({ entries: () => Effect.succeed([]) })
|
|
const models = Layer.mock(SessionRunnerModel.Service)({ resolve: () => Effect.succeed(model) })
|
|
const it = testEffect(
|
|
AppNodeBuilder.build(
|
|
LayerNode.group([Database.node, EventV2.node, SessionProjector.node, SessionStore.node, SessionCompaction.node]),
|
|
[
|
|
[llmClient, client],
|
|
[Config.node, config],
|
|
[SessionRunnerModel.node, models],
|
|
],
|
|
),
|
|
)
|
|
|
|
test("compaction describes tool media without embedding base64", () => {
|
|
const base64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAAB"
|
|
const serialized = SessionCompaction.serializeToolContent([
|
|
{ type: "text", text: "Image read successfully" },
|
|
{
|
|
type: "file",
|
|
uri: `data:image/png;base64,${base64}`,
|
|
mime: "image/png",
|
|
name: "pixel.png",
|
|
},
|
|
])
|
|
|
|
expect(serialized).toBe("Image read successfully\n[Attached image/png: pixel.png]")
|
|
expect(serialized).not.toContain(base64)
|
|
})
|
|
|
|
it.effect("manual compaction summarizes short context instead of no-op", () =>
|
|
Effect.gen(function* () {
|
|
requests = []
|
|
const db = (yield* Database.Service).db
|
|
const compaction = yield* SessionCompaction.Service
|
|
const store = yield* SessionStore.Service
|
|
const sessionID = SessionV2.ID.make("ses_manual_compaction")
|
|
const userMessage = {
|
|
id: SessionMessage.ID.create(),
|
|
type: "user" as const,
|
|
text: "Manual compaction should include this short conversation.",
|
|
time: { created: DateTime.makeUnsafe(0) },
|
|
}
|
|
yield* db
|
|
.insert(ProjectTable)
|
|
.values({ id: Project.ID.global, worktree: AbsolutePath.make("/project"), sandboxes: [] })
|
|
.onConflictDoNothing()
|
|
.run()
|
|
.pipe(Effect.orDie)
|
|
yield* db
|
|
.insert(SessionTable)
|
|
.values({
|
|
id: sessionID,
|
|
project_id: Project.ID.global,
|
|
slug: "manual-compaction",
|
|
directory: "/project",
|
|
title: "Manual compaction",
|
|
version: "test",
|
|
})
|
|
.run()
|
|
.pipe(Effect.orDie)
|
|
|
|
const session = yield* store
|
|
.get(sessionID)
|
|
.pipe(
|
|
Effect.flatMap((session) =>
|
|
session ? Effect.succeed(session) : Effect.die("manual compaction test session missing"),
|
|
),
|
|
)
|
|
|
|
expect(yield* compaction.compactManual({ session, messages: [userMessage] })).toBe(true)
|
|
|
|
expect(requests).toHaveLength(1)
|
|
expect(JSON.stringify(requests[0]?.messages)).toContain("Manual compaction should include this short conversation.")
|
|
expect(yield* store.context(sessionID)).toMatchObject([
|
|
{ type: "compaction", reason: "manual", summary: "manual summary", recent: "" },
|
|
])
|
|
expect(
|
|
yield* db
|
|
.select({ type: EventTable.type })
|
|
.from(EventTable)
|
|
.where(eq(EventTable.aggregate_id, sessionID))
|
|
.orderBy(asc(EventTable.seq))
|
|
.all()
|
|
.pipe(Effect.orDie),
|
|
).toEqual([
|
|
{ type: EventV2.versionedType(SessionEvent.Compaction.Started.type, 1) },
|
|
{ type: EventV2.versionedType(SessionEvent.Compaction.Ended.type, 1) },
|
|
])
|
|
}),
|
|
)
|