chore: merge dev into v2 (#34788)

Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com>
Co-authored-by: Kit Langton <kit.langton@gmail.com>
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: Affan Ali <93028901+affanali2k3@users.noreply.github.com>
Co-authored-by: affanali2k3 <affanalikhanxx@gmail.com>
Co-authored-by: Frank <frank@anoma.ly>
Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴 <little-frank@opencord.local>
Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
Co-authored-by: Jay V <air@live.ca>
Co-authored-by: Dax Raad <d@ironbay.co>
Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com>
Co-authored-by: OpeOginni <107570612+OpeOginni@users.noreply.github.com>
Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com>
Co-authored-by: Ben Guthrie <benjee.012@gmail.com>
Co-authored-by: Dax <mail@thdxr.com>
Co-authored-by: Filip <34747899+neriousy@users.noreply.github.com>
Co-authored-by: Max Anderson <max.a.anderson95@gmail.com>
Co-authored-by: Brendan Allan <git@brendonovich.dev>
Co-authored-by: Jack <jack@anoma.ly>
Co-authored-by: Shoubhit Dash <shoubhit2005@gmail.com>
Co-authored-by: Dustin Deus <deusdustin@gmail.com>
Co-authored-by: starptech <starptech@starptechs-MBP.fritz.box>
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
Co-authored-by: usrnk1 <7547651+usrnk1@users.noreply.github.com>
Co-authored-by: Jay <53023+jayair@users.noreply.github.com>
Co-authored-by: runvip <164729189+runvip@users.noreply.github.com>
Co-authored-by: opencode <opencode@sst.dev>
Co-authored-by: Julian Coy <julian@ex-machina.co>
Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com>
This commit is contained in:
James Long
2026-07-01 17:12:00 -04:00
committed by GitHub
co-authored by Brendan Allan Kit Langton opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Affan Ali affanali2k3 Frank opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴 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
parent 932a40cfd9
commit 8c94e9005f
590 changed files with 15772 additions and 5530 deletions
@@ -7,12 +7,9 @@ import { APICallError } from "ai"
import { Cause, Deferred, Effect, Exit, Fiber, Layer, Schema } from "effect"
import * as Stream from "effect/Stream"
import { Config } from "@/config/config"
import { Image } from "@/image/image"
import { Agent } from "../../src/agent/agent"
import { LLM } from "../../src/session/llm"
import { SessionCompaction } from "../../src/session/compaction"
import { Token } from "@/util/token"
import { Permission } from "../../src/permission"
import { Plugin } from "../../src/plugin"
import { provideTmpdirInstance, TestInstance } from "../fixture/fixture"
import { Session as SessionNs } from "@/session/session"
@@ -21,12 +18,11 @@ import { MessageID, PartID, SessionID } from "../../src/session/schema"
import { SessionStatus } from "../../src/session/status"
import { SessionSummary } from "../../src/session/summary"
import { SessionV2 } from "@opencode-ai/core/session"
import { locationServiceMapLayer } from "@opencode-ai/core/location-services"
import { SessionExecution } from "@opencode-ai/core/session/execution"
import { SessionProjector } from "@opencode-ai/core/session/projector"
import type { Provider } from "@/provider/provider"
import { Provider } from "@/provider/provider"
import * as SessionProcessorModule from "../../src/session/processor"
import { Snapshot } from "../../src/snapshot"
import { ProviderTest } from "../fake/provider"
import { testEffect } from "../lib/effect"
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
@@ -35,6 +31,8 @@ import { RuntimeFlags } from "@/effect/runtime-flags"
import { LLMEvent, Usage } from "@opencode-ai/llm"
import { ProviderV2 } from "@opencode-ai/core/provider"
import { ModelV2 } from "@opencode-ai/core/model"
import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
const summary = Layer.succeed(
SessionSummary.Service,
@@ -210,7 +208,7 @@ function fake(
} satisfies SessionProcessorModule.SessionProcessor.Handle
}
function layer(result: "continue" | "compact") {
function processorLayer(result: "continue" | "compact") {
return Layer.succeed(
SessionProcessorModule.SessionProcessor.Service,
SessionProcessorModule.SessionProcessor.Service.of({
@@ -221,38 +219,28 @@ function layer(result: "continue" | "compact") {
function cfg(compaction?: ConfigV1.Info["compaction"]) {
const base = Schema.decodeUnknownSync(ConfigV1.Info)({}) as ConfigV1.Info
return TestConfig.layer({
get: () => Effect.succeed({ ...base, compaction }),
})
return Layer.succeed(Config.Service, TestConfig.make({ get: () => Effect.succeed({ ...base, compaction }) }))
}
const deps = Layer.mergeAll(
wide().layer,
layer("continue"),
Agent.defaultLayer,
Plugin.defaultLayer,
EventV2Bridge.defaultLayer,
Config.defaultLayer,
RuntimeFlags.layer({ experimentalEventSystem: true }),
Database.defaultLayer,
EventV2Bridge.defaultLayer,
)
const env = Layer.mergeAll(
SessionNs.defaultLayer,
Database.defaultLayer,
EventV2Bridge.defaultLayer,
CrossSpawnSpawner.defaultLayer,
SessionCompaction.layer.pipe(Layer.provide(SessionNs.defaultLayer), Layer.provideMerge(deps)),
)
const defaultProvider = wide()
const compactionTestNode = LayerNode.group([
SessionCompaction.node,
SessionNs.node,
SessionProjector.node,
Database.node,
EventV2Bridge.node,
CrossSpawnSpawner.node,
])
const env = AppNodeBuilder.build(compactionTestNode, [
[Provider.node, defaultProvider.layer],
[SessionProcessorModule.SessionProcessor.node, processorLayer("continue")],
[RuntimeFlags.node, RuntimeFlags.layer({ experimentalEventSystem: true })],
])
const it = testEffect(env)
const compactionEnv = Layer.mergeAll(
SessionNs.defaultLayer,
Database.defaultLayer,
EventV2Bridge.defaultLayer,
CrossSpawnSpawner.defaultLayer,
const compactionEnv = AppNodeBuilder.build(
LayerNode.group([SessionNs.node, SessionProjector.node, Database.node, EventV2Bridge.node, CrossSpawnSpawner.node]),
)
const itCompaction = testEffect(compactionEnv)
@@ -260,7 +248,7 @@ type CompactionProcessOptions = {
result?: "continue" | "compact"
llm?: Layer.Layer<LLM.Service>
plugin?: Layer.Layer<Plugin.Service>
provider?: ReturnType<typeof ProviderTest.fake>
provider?: ReturnType<typeof wide>
config?: Layer.Layer<Config.Service>
}
@@ -269,30 +257,25 @@ function withCompaction(options?: CompactionProcessOptions) {
}
function compactionProcessLayer(options?: CompactionProcessOptions) {
const events = EventV2Bridge.defaultLayer
const status = SessionStatus.layer.pipe(Layer.provide(events))
const processor = options?.llm
? SessionProcessorModule.SessionProcessor.layer.pipe(
Layer.provide(summary),
Layer.provide(Image.defaultLayer),
Layer.provide(RuntimeFlags.layer({ experimentalEventSystem: true })),
Layer.provide(status),
)
: layer(options?.result ?? "continue")
return Layer.mergeAll(SessionCompaction.layer.pipe(Layer.provide(processor)), processor, events, status).pipe(
Layer.provide(SessionNs.defaultLayer),
Layer.provide((options?.provider ?? wide()).layer),
Layer.provide(Snapshot.defaultLayer),
Layer.provide(options?.llm ?? LLM.defaultLayer),
Layer.provide(Permission.defaultLayer),
Layer.provide(Agent.defaultLayer),
Layer.provide(options?.plugin ?? Plugin.defaultLayer),
Layer.provide(status),
Layer.provide(events),
Layer.provide(options?.config ?? Config.defaultLayer),
Layer.provide(RuntimeFlags.layer({ experimentalEventSystem: true })),
Layer.provide(EventV2Bridge.defaultLayer),
)
const replacements: LayerNode.Replacements = [
[Provider.node, (options?.provider ?? wide()).layer],
[RuntimeFlags.node, RuntimeFlags.layer({ experimentalEventSystem: true })],
[SessionSummary.node, summary],
]
if (!options?.llm) {
return AppNodeBuilder.build(compactionTestNode, [
...replacements,
[SessionProcessorModule.SessionProcessor.node, processorLayer(options?.result ?? "continue")],
...(options?.plugin ? ([[Plugin.node, options.plugin]] as const) : []),
...(options?.config ? ([[Config.node, options.config]] as const) : []),
])
}
return AppNodeBuilder.build(compactionTestNode, [
...replacements,
[LLM.node, options.llm],
...(options?.plugin ? ([[Plugin.node, options.plugin]] as const) : []),
...(options?.config ? ([[Config.node, options.config]] as const) : []),
])
}
function createSummaryCompaction(sessionID: SessionID) {
@@ -318,7 +301,7 @@ function llm() {
push(stream: Stream.Stream<LLMEvent, unknown> | ((input: LLM.StreamInput) => Stream.Stream<LLMEvent, unknown>)) {
queue.push(stream)
},
layer: Layer.succeed(
llmLayer: Layer.succeed(
LLM.Service,
LLM.Service.of({
stream: (input) => {
@@ -614,9 +597,7 @@ describe("session.compaction.create", () => {
})
const v2 = yield* SessionV2.Service.use((svc) => svc.messages({ sessionID: info.id })).pipe(
Effect.provide(SessionV2.defaultLayer),
Effect.provide(SessionExecution.noopLayer),
Effect.provide(locationServiceMapLayer),
Effect.provide(AppNodeBuilder.build(SessionV2.node, [[SessionExecution.node, SessionExecution.noopLayer]])),
)
expect(v2.at(-1)).toMatchObject({
type: "compaction",
@@ -1014,7 +995,7 @@ describe("session.compaction.process", () => {
expect(part?.type).toBe("compaction")
expect(part?.tail_start_id).toBeUndefined()
expect(captured).toContain("yyyy")
}).pipe(withCompaction({ llm: stub.layer, config: cfg({ tail_turns: 1, preserve_recent_tokens: 20 }) }))
}).pipe(withCompaction({ llm: stub.llmLayer, config: cfg({ tail_turns: 1, preserve_recent_tokens: 20 }) }))
},
{ git: true },
)
@@ -1051,7 +1032,7 @@ describe("session.compaction.process", () => {
expect(part?.tail_start_id).toBeUndefined()
expect(captured).toContain("recent image turn")
expect(captured).toContain("Attached image/png: big.png")
}).pipe(withCompaction({ llm: stub.layer, config: cfg({ tail_turns: 1, preserve_recent_tokens: 100 }) }))
}).pipe(withCompaction({ llm: stub.llmLayer, config: cfg({ tail_turns: 1, preserve_recent_tokens: 100 }) }))
},
{ git: true },
)
@@ -1102,7 +1083,7 @@ describe("session.compaction.process", () => {
expect(filtered[1]?.info.role).toBe("assistant")
expect(filtered[1]?.info.role === "assistant" ? filtered[1].info.summary : false).toBe(true)
expect(filtered.map((msg) => msg.info.id)).not.toContain(large.id)
}).pipe(withCompaction({ llm: stub.layer, config: cfg({ tail_turns: 1, preserve_recent_tokens: 100 }) }))
}).pipe(withCompaction({ llm: stub.llmLayer, config: cfg({ tail_turns: 1, preserve_recent_tokens: 100 }) }))
},
{ git: true },
)
@@ -1263,7 +1244,7 @@ describe("session.compaction.process", () => {
expect(Cause.hasInterrupts(exit.cause)).toBe(true)
expect(Date.now() - start).toBeLessThan(250)
}
}).pipe(withCompaction({ llm: stub.layer }))
}).pipe(withCompaction({ llm: stub.llmLayer }))
},
{ git: true },
{ timeout: 10_000 },
@@ -1336,7 +1317,7 @@ describe("session.compaction.process", () => {
expect(summary?.parts.some((part) => part.type === "reasoning")).toBe(false)
// Sanity: the text part still got through.
expect(summary?.parts.some((part) => part.type === "text" && part.text === "summary")).toBe(true)
}).pipe(withCompaction({ llm: stub.layer }))
}).pipe(withCompaction({ llm: stub.llmLayer }))
},
{ git: true },
)
@@ -1372,7 +1353,7 @@ describe("session.compaction.process", () => {
expect(summary?.info.role).toBe("assistant")
expect(summary?.parts.some((part) => part.type === "tool")).toBe(false)
}).pipe(withCompaction({ llm: stub.layer }))
}).pipe(withCompaction({ llm: stub.llmLayer }))
},
{ git: true },
)
@@ -1409,7 +1390,7 @@ describe("session.compaction.process", () => {
expect(captured).not.toContain("keep this turn")
expect(captured).not.toContain("and this one too")
expect(captured).not.toContain("What did we do so far?")
}).pipe(withCompaction({ llm: stub.layer }))
}).pipe(withCompaction({ llm: stub.llmLayer }))
},
{ git: true },
)
@@ -1451,7 +1432,7 @@ describe("session.compaction.process", () => {
expect(captured.match(/summary one/g)?.length).toBe(1)
expect(captured).toContain("## Constraints & Preferences")
expect(captured).toContain("## Progress")
}).pipe(withCompaction({ llm: stub.layer }))
}).pipe(withCompaction({ llm: stub.llmLayer }))
},
{ git: true },
)
@@ -1493,7 +1474,7 @@ describe("session.compaction.process", () => {
expect(
filtered.some((msg) => msg.info.role === "user" && msg.parts.some((part) => part.type === "compaction")),
).toBe(true)
}).pipe(withCompaction({ llm: stub.layer, config: cfg({ tail_turns: 2, preserve_recent_tokens: 10_000 }) }))
}).pipe(withCompaction({ llm: stub.llmLayer, config: cfg({ tail_turns: 2, preserve_recent_tokens: 10_000 }) }))
})
itCompaction.instance(