Compare commits

..
Author SHA1 Message Date
Brendonovich 1cd328f418 refactor(app): simplify branch picker rows 2026-08-25 07:18:16 +00:00
Brendonovich 57930302a7 refactor(app): clarify worktree selection state 2026-08-25 07:14:15 +00:00
Brendonovich 380ed09653 feat: select worktree base branch 2026-08-25 07:08:25 +00:00
opencode-agent[bot]andBrendonovich 190f189fbe fix(app): route notification clicks through tabs (#44897)
Co-authored-by: Brendonovich <14191578+Brendonovich@users.noreply.github.com>
2026-08-25 14:11:59 +08:00
Major Hayden 8c126e98da fix(ci): check PR body for linked issue on non-default branches (#43964)
Signed-off-by: Major Hayden <major@mhtx.net>
2026-08-25 00:38:02 -05:00
Aiden Cline ce8a489aaa fix(ai): respect prompt cache opt-out (#44891) 2026-08-25 00:36:18 -05:00
Brendan Allan 1f7ae3f638 fix(app): animate composer delivery controls (#44886) 2026-08-25 13:34:53 +08:00
Luke Parker 5ad0f0dc5a fix(app): prevent timeline row identity collisions (#44878) 2026-08-25 15:33:45 +10:00
e589969398 fix(core): resolve compatible shells for commands (#44485)
Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
2026-08-25 00:24:08 -05:00
Aiden Cline 42867d3bbc fix(ai): recover incomplete streamed tool arguments (#44875) 2026-08-25 00:22:03 -05:00
Brendan Allan d4cdb99e4c fix(desktop): suppress resize observer loop warnings (#44883) 2026-08-25 13:17:29 +08:00
Aiden Cline 0a78b11222 fix(ai): ignore unknown Anthropic stream variants (#44817) 2026-08-25 00:03:08 -05:00
Aiden Cline 28c1806950 fix(core): route Copilot fallback models through AI SDK (#44882) 2026-08-25 00:01:42 -05:00
opencode-agent[bot]andrekram1-node 683f5fdee0 fix(tui): inherit model for new sessions (#44879)
Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
2026-08-24 23:58:09 -05:00
Dax Raad e9b5e055f5 fix(docs): refine header links and copy feedback 2026-08-25 00:53:10 -04:00
Aiden Cline f327adb0f2 fix(core): support Zod tool schemas (#44861) 2026-08-24 23:50:01 -05:00
Dax Raad 442bc92a21 feat(docs): add markdown copy button to page headings 2026-08-25 00:48:39 -04:00
Dax Raad f2ff93a5b7 fix(www): use official favicon 2026-08-25 00:44:42 -04:00
Aiden Cline 1b30098e8d fix(ai): default responses to encrypted reasoning (#44863) 2026-08-24 23:43:04 -05:00
Dax Raad 1144ef6c5d feat(www): serve cached markdown documentation 2026-08-25 00:34:34 -04:00
102 changed files with 1582 additions and 387 deletions
+10 -1
View File
@@ -135,7 +135,16 @@ jobs:
const linkedIssues = result.repository.pullRequest.closingIssuesReferences.totalCount;
if (linkedIssues === 0) {
// GitHub only populates closingIssuesReferences when a PR targets the repository's
// default branch (dev). PRs targeting other branches like v2 always return totalCount 0.
// Fall back to checking the PR description for closing keywords (e.g. Closes #123).
const body = pr.body || '';
const issueMatch = body.match(/### Issue for this PR\s*\n([\s\S]*?)(?=###|$)/);
const issueContent = issueMatch ? issueMatch[1].trim() : body;
const hasBodyIssueRef = /(closes|fixes|resolves)\s+#\d+/i.test(issueContent) || /#\d+/.test(issueContent);
const hasLinkedIssue = linkedIssues > 0 || hasBodyIssueRef;
if (!hasLinkedIssue) {
await addLabel('needs:issue');
await comment('issue', `Thanks for your contribution!
+74 -12
View File
@@ -1,5 +1,5 @@
import { Buffer } from "node:buffer"
import { Effect, Schema } from "effect"
import { Effect, Option, Schema } from "effect"
import { Tool } from "@opencode-ai/schema/tool"
import { Route } from "../route/client.js"
import { Auth } from "../route/auth.js"
@@ -361,6 +361,8 @@ const AnthropicStreamBlock = Schema.Struct({
tool_use_id: Schema.optional(Schema.String),
content: Schema.optional(Schema.Unknown),
})
type AnthropicStreamBlock = Schema.Schema.Type<typeof AnthropicStreamBlock>
const decodeAnthropicStreamBlock = Schema.decodeUnknownOption(AnthropicStreamBlock)
const AnthropicStreamDelta = Schema.Struct({
type: Schema.optional(Schema.String),
@@ -371,13 +373,15 @@ const AnthropicStreamDelta = Schema.Struct({
stop_reason: optionalNull(Schema.String),
stop_sequence: optionalNull(Schema.String),
})
type AnthropicStreamDelta = Schema.Schema.Type<typeof AnthropicStreamDelta>
const decodeAnthropicStreamDelta = Schema.decodeUnknownOption(AnthropicStreamDelta)
const AnthropicEvent = Schema.Struct({
type: Schema.String,
index: Schema.optional(Schema.Number),
message: Schema.optional(Schema.Struct({ usage: Schema.optional(AnthropicUsage) })),
content_block: Schema.optional(AnthropicStreamBlock),
delta: Schema.optional(AnthropicStreamDelta),
content_block: Schema.optional(Schema.Unknown),
delta: Schema.optional(Schema.Unknown),
usage: Schema.optional(AnthropicUsage),
// `type` and `message` are both required per Anthropic's spec, but
// OpenAI-compatible proxies and gateway translations occasionally drop one
@@ -1106,7 +1110,7 @@ const SERVER_TOOL_RESULT_NAMES: Record<AnthropicServerToolResultType, string> =
const isServerToolResultType = (type: string): type is AnthropicServerToolResultType => type in SERVER_TOOL_RESULT_NAMES
const serverToolResultEvent = (block: NonNullable<AnthropicEvent["content_block"]>): LLMEvent | undefined => {
const serverToolResultEvent = (block: AnthropicStreamBlock): LLMEvent | undefined => {
if (!block.type || !isServerToolResultType(block.type)) return undefined
const errorPayload =
typeof block.content === "object" && block.content !== null && "type" in block.content
@@ -1133,7 +1137,10 @@ const onMessageStart = (state: ParserState, event: AnthropicEvent): StepResult =
return [usage ? { ...state, usage: mergeUsage(state.usage, usage) } : state, NO_EVENTS]
}
const onContentBlockStart = (state: ParserState, event: AnthropicEvent): StepResult => {
const onContentBlockStart = (
state: ParserState,
event: AnthropicEvent & { readonly content_block: AnthropicStreamBlock },
): StepResult => {
const block = event.content_block
if (!block) return [state, NO_EVENTS]
@@ -1224,11 +1231,12 @@ const onContentBlockStart = (state: ParserState, event: AnthropicEvent): StepRes
const onContentBlockDelta = Effect.fn("AnthropicMessages.onContentBlockDelta")(function* (
state: ParserState,
event: AnthropicEvent,
event: AnthropicEvent & { readonly delta: AnthropicStreamDelta },
) {
const delta = event.delta
if (delta?.type === "text_delta" && delta.text) {
if (!state.lifecycle.text.has(`text-${event.index ?? 0}`)) return [state, NO_EVENTS] satisfies StepResult
const events: LLMEvent[] = []
return [
{ ...state, lifecycle: Lifecycle.textDelta(state.lifecycle, events, `text-${event.index ?? 0}`, delta.text) },
@@ -1237,6 +1245,7 @@ const onContentBlockDelta = Effect.fn("AnthropicMessages.onContentBlockDelta")(f
}
if (delta?.type === "thinking_delta" && delta.thinking) {
if (!state.lifecycle.reasoning.has(`reasoning-${event.index ?? 0}`)) return [state, NO_EVENTS] satisfies StepResult
const events: LLMEvent[] = []
return [
{
@@ -1249,6 +1258,7 @@ const onContentBlockDelta = Effect.fn("AnthropicMessages.onContentBlockDelta")(f
if (delta?.type === "signature_delta" && delta.signature) {
const index = event.index ?? 0
if (!state.lifecycle.reasoning.has(`reasoning-${index}`)) return [state, NO_EVENTS] satisfies StepResult
return [
{
...state,
@@ -1301,7 +1311,10 @@ const onContentBlockStop = Effect.fn("AnthropicMessages.onContentBlockStop")(fun
return [{ ...state, lifecycle, tools: result.tools, reasoningSignatures }, events] satisfies StepResult
})
const onMessageDelta = (state: ParserState, event: AnthropicEvent): StepResult => {
const onMessageDelta = (
state: ParserState,
event: AnthropicEvent & { readonly delta?: AnthropicStreamDelta },
): StepResult => {
const usage = mergeUsage(state.usage, mapUsage(event.usage))
return [
{
@@ -1356,11 +1369,49 @@ const onError = (event: AnthropicEvent) =>
}),
)
const isKnownStreamBlockType = (type: string) =>
type === "text" ||
type === "thinking" ||
type === "redacted_thinking" ||
type === "tool_use" ||
type === "server_tool_use" ||
isServerToolResultType(type)
const isKnownStreamDeltaType = (type: string) =>
type === "text_delta" || type === "thinking_delta" || type === "signature_delta" || type === "input_json_delta"
const invalidStreamEvent = (event: AnthropicEvent) =>
Effect.fail(
ProviderShared.eventError(
ADAPTER,
"Invalid anthropic/anthropic-messages stream event",
ProviderShared.encodeJson(event),
),
)
const step = (state: ParserState, event: AnthropicEvent) => {
if (!SSE_EVENTS.has(event.type)) return Effect.succeed<StepResult>([state, NO_EVENTS])
if (
event.type !== "content_block_start" &&
event.content_block !== undefined &&
Option.isNone(decodeAnthropicStreamBlock(event.content_block))
)
return invalidStreamEvent(event)
if (
event.type !== "content_block_delta" &&
event.delta !== undefined &&
Option.isNone(decodeAnthropicStreamDelta(event.delta))
)
return invalidStreamEvent(event)
if (event.type === "message_start") return Effect.succeed(onMessageStart(state, event))
if (event.type === "content_block_start") {
const block = event.content_block
if (block && (block.type === "tool_use" || block.type === "server_tool_use")) {
if (!ProviderShared.isRecord(event.content_block) || typeof event.content_block.type !== "string")
return invalidStreamEvent(event)
if (!isKnownStreamBlockType(event.content_block.type)) return Effect.succeed<StepResult>([state, NO_EVENTS])
const decoded = decodeAnthropicStreamBlock(event.content_block)
if (Option.isNone(decoded)) return invalidStreamEvent(event)
const block = decoded.value
if (block.type === "tool_use" || block.type === "server_tool_use") {
if (event.index === undefined)
return Effect.fail(ProviderShared.eventError(ADAPTER, `Anthropic ${block.type} missing index`))
if (!block.id)
@@ -1368,11 +1419,22 @@ const step = (state: ParserState, event: AnthropicEvent) => {
ProviderShared.eventError(ADAPTER, `Anthropic tool_use missing id at index ${event.index}`),
)
}
return Effect.succeed(onContentBlockStart(state, event))
return Effect.succeed(onContentBlockStart(state, { ...event, content_block: block }))
}
if (event.type === "content_block_delta") {
if (!ProviderShared.isRecord(event.delta)) return invalidStreamEvent(event)
if (typeof event.delta.type === "string" && !isKnownStreamDeltaType(event.delta.type))
return Effect.succeed<StepResult>([state, NO_EVENTS])
const decoded = decodeAnthropicStreamDelta(event.delta)
if (Option.isNone(decoded)) return invalidStreamEvent(event)
return onContentBlockDelta(state, { ...event, delta: decoded.value })
}
if (event.type === "content_block_delta") return onContentBlockDelta(state, event)
if (event.type === "content_block_stop") return onContentBlockStop(state, event)
if (event.type === "message_delta") return Effect.succeed(onMessageDelta(state, event))
if (event.type === "message_delta") {
const decoded = decodeAnthropicStreamDelta(event.delta)
if (Option.isNone(decoded)) return invalidStreamEvent(event)
return Effect.succeed(onMessageDelta(state, { ...event, delta: decoded.value }))
}
if (event.type === "message_stop") return onMessageStop(state)
if (event.type === "error") return onError(event)
return Effect.succeed<StepResult>([state, NO_EVENTS])
+1 -1
View File
@@ -666,7 +666,7 @@ const lowerMessages = Effect.fn("OpenResponses.lowerMessages")(function* (reques
const lowerOptions = (request: LLMRequest) => {
const options = OpenResponsesOptions.resolve(request)
const cacheKey = ProviderShared.clampPromptCacheKey(request.promptCacheKey)
const cacheKey = ProviderShared.promptCacheKey(request)
const parallelToolCalls = resolveParallelToolCalls(request)
return {
...(options.instructions ? { instructions: options.instructions } : {}),
+1 -1
View File
@@ -659,7 +659,7 @@ const detectZaiToolStream = (
const lowerOptions = (request: LLMRequest, supportsStore: boolean) => {
const options = OpenAIOptions.resolve(request)
const cacheKey = ProviderShared.clampPromptCacheKey(request.promptCacheKey)
const cacheKey = ProviderShared.promptCacheKey(request)
return {
...(supportsStore && options.store !== undefined ? { store: options.store } : {}),
// For providers that support `store`, ensure stateless `store:false` is sent
@@ -17,6 +17,7 @@ export const route = Route.make({
protocol: OpenResponses.protocol,
endpoint: Endpoint.path(OpenResponses.PATH),
transport: OpenResponses.httpTransport,
defaults: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
})
export * as OpenAICompatibleResponses from "./openai-compatible-responses.js"
@@ -207,7 +207,7 @@ export const route = Route.make({
endpoint,
auth,
transport,
defaults: { providerOptions: { store: false } },
defaults: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
})
export * as OpenAIResponses from "./openai-responses.js"
+4 -4
View File
@@ -28,10 +28,10 @@ export const OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH = 64
// OpenAI limits `prompt_cache_key` to 64 chars; DeepSeek and Zai inherit the same
// limit via their OpenAI-compatible APIs. Clamp with unicode-aware slicing.
export const clampPromptCacheKey = (key: string | undefined): string | undefined => {
if (key === undefined) return undefined
const chars = Array.from(key)
if (chars.length <= OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH) return key
export const promptCacheKey = (request: LLMRequest): string | undefined => {
if (request.cache === "none" || request.promptCacheKey === undefined) return undefined
const chars = Array.from(request.promptCacheKey)
if (chars.length <= OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH) return request.promptCacheKey
return chars.slice(0, OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH).join("")
}
@@ -42,7 +42,61 @@ export function parseJSON(jsonString: string, allowPartial = Allow.ALL): unknown
try {
return decodeJson(input)
} catch {}
return _parseJSON(input, allowPartial)
const repaired = repairJSON(input)
if (repaired !== input) {
try {
return decodeJson(repaired)
} catch {}
}
try {
return _parseJSON(input, allowPartial)
} catch (error) {
if (repaired !== input) return _parseJSON(repaired, allowPartial)
throw error
}
}
const repairJSON = (input: string) => {
let repaired = ""
let quoted = false
for (let index = 0; index < input.length; index++) {
const character = input[index]
if (!quoted) {
repaired += character
if (character === '"') quoted = true
continue
}
if (character === '"') {
repaired += character
quoted = false
continue
}
if (character === "\\") {
const next = input[index + 1]
if (next === "u" && /^[0-9a-fA-F]{4}$/.test(input.slice(index + 2, index + 6))) {
repaired += input.slice(index, index + 6)
index += 5
continue
}
if (next !== undefined && '"\\/bfnrtu'.includes(next)) {
repaired += `\\${next}`
index++
continue
}
repaired += "\\\\"
continue
}
const code = character.charCodeAt(0)
repaired += code <= 0x1f ? `\\u${code.toString(16).padStart(4, "0")}` : character
}
return repaired
}
const _parseJSON = (jsonString: string, allow: number) => {
@@ -148,7 +202,12 @@ const _parseJSON = (jsonString: string, allow: number) => {
skipBlank()
index++
try {
object[key] = parseAny()
Object.defineProperty(object, key, {
value: parseAny(),
enumerable: true,
configurable: true,
writable: true,
})
} catch (error) {
if (Allow.OBJ & allow) return object
throw error
+23 -25
View File
@@ -1,5 +1,5 @@
import { Effect, Option } from "effect"
import { AIError, LLMEvent, type ProviderMetadata, type ToolCall, type ToolInputError } from "../../schema/index.js"
import { AIError, LLMEvent, type ProviderMetadata, type ToolCall } from "../../schema/index.js"
import { eventError, parseToolInput, type ToolAccumulator } from "../shared.js"
import { parse } from "./partial-json.js"
@@ -59,46 +59,44 @@ const inputStart = (tool: PendingTool) =>
providerMetadata: tool.providerMetadata,
})
const inputDelta = (tool: PendingTool, text: string) => {
const input = parsePartialInput(tool.input)
return LLMEvent.toolInputDelta({
const inputDelta = (tool: PendingTool, text: string) =>
LLMEvent.toolInputDelta({
id: tool.id,
name: tool.name,
text,
...(Option.isSome(input) ? { input: input.value } : {}),
input: Option.getOrElse(parsePartialInput(tool.input), () => ({})),
})
}
const toolCall = (route: string, tool: PendingTool, inputOverride?: string) => {
const raw = inputOverride ?? tool.input
return parseToolInput(route, tool.name, raw).pipe(
Effect.map((input): ToolCall | ToolInputError =>
LLMEvent.toolCall({
id: tool.id,
name: tool.name,
input,
providerExecuted: tool.providerExecuted ? true : undefined,
providerMetadata: tool.providerMetadata,
}),
),
Effect.catch((error) =>
tool.providerExecuted
? Effect.fail(error)
: Effect.succeed(
LLMEvent.toolInputError({
id: tool.id,
name: tool.name,
raw,
}),
Option.getOrElse(
Option.map(parsePartialInput(raw), (input) => input ?? {}),
() => ({}),
),
),
),
Effect.map(
(input): ToolCall =>
LLMEvent.toolCall({
id: tool.id,
name: tool.name,
input,
providerExecuted: tool.providerExecuted ? true : undefined,
providerMetadata: tool.providerMetadata,
}),
),
)
}
const finishEvents = (tool: PendingTool, event: ToolCall | ToolInputError): ReadonlyArray<LLMEvent> =>
event.type === "tool-input-error"
? [event]
: [LLMEvent.toolInputEnd({ id: tool.id, name: tool.name, providerMetadata: tool.providerMetadata }), event]
const finishEvents = (tool: PendingTool, event: ToolCall): ReadonlyArray<LLMEvent> => [
LLMEvent.toolInputEnd({ id: tool.id, name: tool.name, providerMetadata: tool.providerMetadata }),
event,
]
/** Store the updated tool and produce the optional public delta event. */
const appendTool = <K extends StreamKey>(
@@ -181,7 +179,7 @@ export const appendExisting = <K extends StreamKey>(
/**
* Finalize one pending tool call: parse the accumulated raw JSON, remove it
* from state, and return either a call or a non-executable local input error.
* from state, and recover incomplete local arguments when needed.
* Missing keys are a no-op because some providers emit stop events for
* non-tool content blocks.
*/
+1 -3
View File
@@ -9,7 +9,7 @@ import type { ProviderPackage } from "../provider-package.js"
import * as OpenAICompatibleProfiles from "./openai-compatible-profile.js"
import * as OpenAIChat from "../protocols/openai-chat.js"
import { newBreakpoints, ttlBucket } from "../protocols/utils/cache.js"
import { isRecord, ProviderShared } from "../protocols/shared.js"
import { isRecord } from "../protocols/shared.js"
export const profile = OpenAICompatibleProfiles.profiles.openrouter
export const id = ProviderID.make(profile.provider)
@@ -115,12 +115,10 @@ export const protocol = Protocol.make({
reasoning_details: reasoningDetails,
}
})
const cacheKey = ProviderShared.clampPromptCacheKey(request.promptCacheKey)
return {
...body,
messages,
...bodyOptions(request.providerOptions),
...(cacheKey ? { prompt_cache_key: cacheKey } : {}),
} as OpenRouterBody
}),
),
+1 -1
View File
@@ -42,7 +42,7 @@ const responsesRoute = Route.make({
name: "xAI Responses",
rotateAfterMs: RESPONSES_WEBSOCKET_ROTATE_AFTER_MS,
}),
defaults: { providerOptions: { store: false } },
defaults: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
})
const chatRoute = Route.make({
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+15
View File
@@ -18,6 +18,21 @@ describe("partial JSON", () => {
expect(() => parse('"hello', ~Allow.STR)).toThrow(PartialJSON)
})
test("repairs invalid escapes and raw control characters", () => {
expect(parse('{"path":"A\\H","text":"first\tsecond"}')).toEqual({
path: "A\\H",
text: "first\tsecond",
})
})
test("preserves prototype keys in partial objects", () => {
const object = parse('{"__proto__":{"safe":true}') as Record<string, unknown>
expect(Object.hasOwn(object, "__proto__")).toBe(true)
expect(Object.getPrototypeOf(object)).toBe(Object.prototype)
expect(object.__proto__).toEqual({ safe: true })
})
test("controls partial collection values independently", () => {
expect(parse('["', Allow.ARR)).toEqual([])
expect(parse('["', Allow.ARR | Allow.STR)).toEqual([""])
+9 -2
View File
@@ -95,7 +95,11 @@ describe("provider package entrypoints", () => {
})
expect(selected.route.defaults.headers).toEqual({ "x-application": "opencode" })
expect(selected.route.defaults.http?.body).toEqual({ service_tier: "priority" })
expect(selected.route.defaults.providerOptions).toEqual({ reasoningEffort: "low", store: true })
expect(selected.route.defaults.providerOptions).toEqual({
reasoningEffort: "low",
store: true,
include: ["reasoning.encrypted_content"],
})
})
test("maps Anthropic-compatible settings onto the executable model", async () => {
@@ -285,7 +289,10 @@ describe("provider package entrypoints", () => {
baseURL: "https://aiplatform.googleapis.com/v1/projects/vertex-project/locations/global/endpoints/openapi",
path: "/responses",
})
expect(responses.route.defaults.providerOptions).toEqual({ store: false })
expect(responses.route.defaults.providerOptions).toEqual({
store: false,
include: ["reasoning.encrypted_content"],
})
})
test("rejects conflicting Vertex auth settings at runtime", async () => {
@@ -770,6 +770,108 @@ describe("Anthropic Messages route", () => {
}),
)
it.effect("ignores unknown content block and delta variants", () =>
Effect.gen(function* () {
const response = yield* LLMClient.generate(request).pipe(
Effect.provide(
fixedResponse(
sseEvents(
{ type: "message_start", message: { usage: { input_tokens: 5 } } },
{ type: "future_event", content_block: 42, delta: 42 },
{ type: "content_block_start", index: 0, content_block: { type: "future_block", text: 42 } },
{ type: "content_block_delta", index: 0, delta: { text: "ignored" } },
{ type: "content_block_delta", index: 0, delta: { type: "future_delta", text: 42 } },
{ type: "content_block_delta", index: 0, delta: { type: "text_delta", text: "hidden" } },
{ type: "content_block_delta", index: 0, delta: { type: "thinking_delta", thinking: "hidden" } },
{ type: "content_block_delta", index: 0, delta: { type: "signature_delta", signature: "hidden" } },
{ type: "content_block_stop", index: 0 },
{ type: "content_block_start", index: 1, content_block: { type: "text", text: "" } },
{ type: "content_block_delta", index: 1, delta: { type: "text_delta", text: "Hello" } },
{ type: "content_block_stop", index: 1 },
{ type: "message_delta", delta: { stop_reason: "end_turn" }, usage: { output_tokens: 1 } },
{ type: "message_stop" },
),
),
),
)
expect(response.message.content).toEqual([{ type: "text", text: "Hello" }])
expect(response.finishReason).toEqual({ normalized: "stop", raw: "end_turn" })
}),
)
it.effect("rejects malformed recognized content block variants", () =>
Effect.gen(function* () {
const error = yield* LLMClient.generate(request).pipe(
Effect.provide(
fixedResponse(
sseEvents(
{ type: "message_start", message: { usage: { input_tokens: 5 } } },
{ type: "content_block_start", index: 0, content_block: { type: "text", text: 42 } },
),
),
),
Effect.flip,
)
expect(error.reason).toMatchObject({
_tag: "InvalidProviderOutput",
message: "Invalid anthropic/anthropic-messages stream event",
})
}),
)
it.effect("rejects malformed recognized content delta variants", () =>
Effect.gen(function* () {
const error = yield* LLMClient.generate(request).pipe(
Effect.provide(
fixedResponse(
sseEvents(
{ type: "message_start", message: { usage: { input_tokens: 5 } } },
{ type: "content_block_start", index: 0, content_block: { type: "text", text: "" } },
{ type: "content_block_delta", index: 0, delta: { type: "text_delta", text: 42 } },
),
),
),
Effect.flip,
)
expect(error.reason).toMatchObject({
_tag: "InvalidProviderOutput",
message: "Invalid anthropic/anthropic-messages stream event",
})
}),
)
it.effect("rejects malformed payloads on unrelated stream events", () =>
Effect.gen(function* () {
const events = [
{ type: "message_start", message: { usage: { input_tokens: 1 } }, delta: 42 },
{ type: "content_block_start", index: 0 },
{ type: "content_block_delta", index: 0 },
{ type: "content_block_stop", index: 0, content_block: { type: "text", text: 42 } },
{ type: "message_delta" },
{ type: "message_delta", delta: { stop_reason: 42 } },
{ type: "message_stop", delta: { text: 42 } },
{ type: "error", error: { type: "overloaded_error", message: "busy" }, content_block: 42 },
]
yield* Effect.forEach(events, (event) =>
Effect.gen(function* () {
const error = yield* LLMClient.generate(request).pipe(
Effect.provide(fixedResponse(sseEvents(event))),
Effect.flip,
)
expect(error.reason).toMatchObject({
_tag: "InvalidProviderOutput",
message: "Invalid anthropic/anthropic-messages stream event",
})
}),
)
}),
)
it.effect("rejects malformed recognized SSE events", () =>
Effect.gen(function* () {
const error = yield* LLMClient.generate(request).pipe(
@@ -491,7 +491,7 @@ describe("Bedrock Converse route", () => {
}),
)
it.effect("emits malformed tool input as an unexecuted tool error", () =>
it.effect("recovers incomplete tool input at finalization", () =>
Effect.gen(function* () {
const body = eventStreamBody(
["messageStart", { role: "assistant" }],
@@ -508,10 +508,10 @@ describe("Bedrock Converse route", () => {
)
const response = yield* LLMClient.generate(baseRequest).pipe(Effect.provide(fixedBytes(body)))
expect(response.events.find((event) => event.type === "tool-input-error")).toMatchObject({
expect(response.events.find((event) => event.type === "tool-call")).toMatchObject({
id: "tool_1",
name: "lookup",
raw: '{"query":"partial',
input: { query: "partial" },
})
expect(response.finishReason).toEqual({ normalized: "tool-calls", raw: "end_turn" })
}),
@@ -192,6 +192,21 @@ describe("OpenAI Chat route", () => {
}),
)
it.effect("omits the prompt cache key when caching is disabled", () =>
Effect.gen(function* () {
const prepared = yield* compileRequest(
LLM.request({
model,
prompt: "Hello",
promptCacheKey: "session_123",
cache: "none",
}),
)
expect(prepared.body).not.toHaveProperty("prompt_cache_key")
}),
)
it.effect("maps the xAI Chat prompt cache key to conversation affinity", () =>
LLMClient.generate(
LLM.request({
@@ -52,10 +52,28 @@ describe("Open Responses-compatible route", () => {
{ role: "user", content: [{ type: "input_text", text: "Say hello." }] },
],
stream: true,
store: false,
include: ["reasoning.encrypted_content"],
})
}),
)
it.effect("allows callers to override stateless encrypted reasoning defaults", () =>
Effect.gen(function* () {
const model = configure({
apiKey: "test-key",
baseURL: "https://responses.example.test/v1",
provider: "example",
}).model("example-model")
const prepared = yield* compileRequest(
LLM.request({ model, prompt: "Say hello.", providerOptions: { store: true, include: [] } }),
)
expect(prepared.body.store).toBe(true)
expect(prepared.body.include).toBeUndefined()
}),
)
it.effect("lowers chronological system updates as standard developer messages", () =>
Effect.gen(function* () {
const model = configure({
@@ -117,6 +117,7 @@ describe("OpenAI Responses route", () => {
{ role: "user", content: [{ type: "input_text", text: "Say hello." }] },
],
store: false,
include: ["reasoning.encrypted_content"],
stream: true,
max_output_tokens: 20,
temperature: 0,
@@ -313,7 +314,12 @@ describe("OpenAI Responses route", () => {
expect(prepared.route).toBe("openai-responses")
expect(prepared.protocol).toBe("openai-responses")
expect(prepared.metadata).toEqual({ transport: "http-json" })
expect(prepared.body).toMatchObject({ model: "gpt-4.1-mini", store: false, stream: true })
expect(prepared.body).toMatchObject({
model: "gpt-4.1-mini",
store: false,
include: ["reasoning.encrypted_content"],
stream: true,
})
}),
)
@@ -385,6 +391,7 @@ describe("OpenAI Responses route", () => {
model: "gpt-4.1-mini",
input: [{ role: "user", content: [{ type: "input_text", text: "Say hello." }] }],
store: false,
include: ["reasoning.encrypted_content"],
})
}),
)
@@ -1189,6 +1196,7 @@ describe("OpenAI Responses route", () => {
{ type: "function_call_output", call_id: "call_1", output: '{"forecast":"sunny"}' },
],
store: false,
include: ["reasoning.encrypted_content"],
stream: true,
max_output_tokens: undefined,
temperature: undefined,
@@ -1633,11 +1641,11 @@ describe("OpenAI Responses route", () => {
}),
)
it.effect("omits include when no include is set", () =>
it.effect("requests encrypted reasoning by default", () =>
Effect.gen(function* () {
const prepared = yield* compileRequest(LLM.request({ model, prompt: "hi", providerOptions: { store: false } }))
expect(prepared.body.include).toBeUndefined()
expect(prepared.body.include).toEqual(["reasoning.encrypted_content"])
}),
)
@@ -1691,6 +1699,21 @@ describe("OpenAI Responses route", () => {
}),
)
it.effect("omits the prompt cache key when caching is disabled", () =>
Effect.gen(function* () {
const prepared = yield* compileRequest(
LLM.request({
model,
prompt: "Hello",
promptCacheKey: "request_cache",
cache: "none",
}),
)
expect(prepared.body).not.toHaveProperty("prompt_cache_key")
}),
)
it.effect("parses text and usage stream fixtures", () =>
Effect.gen(function* () {
const body = sseEvents(
@@ -3061,7 +3084,7 @@ describe("OpenAI Responses route", () => {
}),
)
it.effect("emits malformed final function arguments as an unexecuted tool error", () =>
it.effect("recovers authoritative incomplete final function arguments", () =>
Effect.gen(function* () {
const body = sseEvents(
{
@@ -3087,18 +3110,17 @@ describe("OpenAI Responses route", () => {
}),
).pipe(Effect.provide(fixedResponse(body)))
expect(response.events.find(LLMEvent.is.toolInputError)).toEqual({
type: "tool-input-error",
expect(response.events.find(LLMEvent.is.toolCall)).toMatchObject({
id: "call_1",
name: "lookup",
raw: '{"query":"partial',
input: { query: "partial" },
})
expect(response.finishReason.normalized).toBe("tool-calls")
expect(response.events.some(LLMEvent.is.toolCall)).toBeFalse()
expect(response.events.some(LLMEvent.is.toolInputError)).toBeFalse()
}),
)
it.effect("settles malformed function arguments when output_item.added is absent", () =>
it.effect("recovers incomplete function arguments when output_item.added is absent", () =>
Effect.gen(function* () {
const body = sseEvents(
{
@@ -3115,10 +3137,10 @@ describe("OpenAI Responses route", () => {
)
const response = yield* LLMClient.generate(request).pipe(Effect.provide(fixedResponse(body)))
expect(response.events.find(LLMEvent.is.toolInputError)).toMatchObject({
expect(response.events.find(LLMEvent.is.toolCall)).toMatchObject({
id: "call_1",
name: "lookup",
raw: '{"query":"partial',
input: { query: "partial" },
})
expect(response.finishReason.normalized).toBe("tool-calls")
}),
@@ -190,6 +190,21 @@ describe("OpenRouter", () => {
}),
)
it.effect("omits the prompt cache key when caching is disabled", () =>
Effect.gen(function* () {
const prepared = yield* compileRequest(
LLM.request({
model: OpenRouter.configure({ apiKey: "test-key" }).model("openai/gpt-4o-mini"),
prompt: "Hello",
promptCacheKey: "session_123",
cache: "none",
}),
)
expect(prepared.body).not.toHaveProperty("prompt_cache_key")
}),
)
it.effect("filters invalid known OpenRouter options while preserving extensions", () =>
Effect.gen(function* () {
const invalid: Record<string, unknown> = {
@@ -21,6 +21,17 @@ describe("xAI Responses route", () => {
const prepared = yield* compileRequest(LLM.request({ model, prompt: "Hello" }))
expect(prepared.protocol).toBe("xai-responses")
expect(prepared.body.store).toBe(false)
expect(prepared.body.include).toEqual(["reasoning.encrypted_content"])
}),
)
it.effect("allows callers to opt out of encrypted reasoning", () =>
Effect.gen(function* () {
const prepared = yield* compileRequest(LLM.request({ model, prompt: "Hello", providerOptions: { include: [] } }))
expect(prepared.body.store).toBe(false)
expect(prepared.body.include).toBeUndefined()
}),
)
+40 -16
View File
@@ -59,7 +59,7 @@ describe("ToolStream", () => {
}),
)
it.effect("omits partial input when the accumulated value cannot be parsed", () =>
it.effect("defaults partial input to an empty object when the accumulated value cannot be parsed", () =>
Effect.gen(function* () {
const result = ToolStream.appendOrStart(
ADAPTER,
@@ -72,7 +72,7 @@ describe("ToolStream", () => {
expect(result.events).toEqual([
{ type: "tool-input-start", id: "call_1", name: "lookup" },
{ type: "tool-input-delta", id: "call_1", name: "lookup", text: "x" },
{ type: "tool-input-delta", id: "call_1", name: "lookup", text: "x", input: {} },
])
}),
)
@@ -132,7 +132,7 @@ describe("ToolStream", () => {
}),
)
it.effect("finalizes malformed local input as a non-executable tool error", () =>
it.effect("finalizes incomplete local input using the partial JSON parser", () =>
Effect.gen(function* () {
const tools = ToolStream.start(ToolStream.empty<string>(), "item_1", {
id: "call_1",
@@ -144,18 +144,46 @@ describe("ToolStream", () => {
expect(finished).toEqual({
tools: {},
events: [
{
type: "tool-input-error",
id: "call_1",
name: "lookup",
raw: '{"query":"partial',
},
{ type: "tool-input-end", id: "call_1", name: "lookup" },
{ type: "tool-call", id: "call_1", name: "lookup", input: { query: "partial" } },
],
})
}),
)
it.effect("preserves valid siblings when one parallel input is malformed", () =>
it.effect("repairs malformed string escapes in final local input", () =>
Effect.gen(function* () {
const tools = ToolStream.start(ToolStream.empty<string>(), "item_1", {
id: "call_1",
name: "lookup",
input: '{"path":"A\\H","text":"first\tsecond"}',
})
const finished = yield* ToolStream.finish(ADAPTER, tools, "item_1")
expect(finished.events).toEqual([
{ type: "tool-input-end", id: "call_1", name: "lookup" },
{ type: "tool-call", id: "call_1", name: "lookup", input: { path: "A\\H", text: "first\tsecond" } },
])
}),
)
it.effect("defaults unrecoverable local input to an empty object", () =>
Effect.gen(function* () {
const tools = ToolStream.start(ToolStream.empty<string>(), "item_1", {
id: "call_1",
name: "lookup",
input: "invalid",
})
const finished = yield* ToolStream.finish(ADAPTER, tools, "item_1")
expect(finished.events).toEqual([
{ type: "tool-input-end", id: "call_1", name: "lookup" },
{ type: "tool-call", id: "call_1", name: "lookup", input: {} },
])
}),
)
it.effect("recovers incomplete input alongside valid parallel tool calls", () =>
Effect.gen(function* () {
const valid = ToolStream.start(ToolStream.empty<number>(), 0, {
id: "call_valid",
@@ -174,12 +202,8 @@ describe("ToolStream", () => {
events: [
{ type: "tool-input-end", id: "call_valid", name: "lookup" },
{ type: "tool-call", id: "call_valid", name: "lookup", input: { query: "weather" } },
{
type: "tool-input-error",
id: "call_invalid",
name: "lookup",
raw: '{"query":"partial',
},
{ type: "tool-input-end", id: "call_invalid", name: "lookup" },
{ type: "tool-call", id: "call_invalid", name: "lookup", input: { query: "partial" } },
],
})
}),
@@ -0,0 +1,53 @@
import { expect, test } from "@playwright/test"
import { mockOpenCodeServer } from "../utils/mock-server"
import { expectAppVisible } from "../utils/waits"
const draftID = "draft_new_session_workspace_branch"
const directory = "C:/OpenCode/WorkspaceBranch"
const server = `http://${process.env.PLAYWRIGHT_SERVER_HOST ?? "127.0.0.1"}:${process.env.PLAYWRIGHT_SERVER_PORT ?? "4096"}`
test("selects a base branch for a new workspace", async ({ page }) => {
await mockOpenCodeServer(page, {
directory,
project: {
id: "proj_new_session_workspace_branch",
worktree: directory,
vcs: "git",
name: "workspace-branch",
time: { created: 1700000000000, updated: 1700000000000 },
sandboxes: [],
},
provider: { all: [], connected: [], default: {} },
sessions: [],
pageMessages: () => ({ items: [] }),
vcsBranches: ["feature/api", "main", "origin/release"],
})
await page.addInitScript(
({ directory, draftID, server }) => {
localStorage.setItem(
"opencode.global.dat:server",
JSON.stringify({
projects: { local: [{ worktree: directory, expanded: true }] },
lastProject: { local: directory },
}),
)
localStorage.setItem(
"opencode.window.browser.dat:tabs",
JSON.stringify([{ type: "draft", draftID, server, directory }]),
)
},
{ directory, draftID, server },
)
await page.goto(`/new-session?draftId=${draftID}`)
await expectAppVisible(page.locator('[data-component="composer-editor"]'))
await page.getByRole("button", { name: "Local", exact: true }).click()
const create = page.getByRole("menuitem", { name: "New workspace", exact: true })
await create.hover()
await page.getByRole("menuitem", { name: "feature/api", exact: true }).click()
await expect(page.getByText("from feature/api", { exact: true })).toBeVisible()
await page.getByRole("button", { name: "New workspace", exact: true }).click()
await page.getByRole("menuitem", { name: "New workspace", exact: true }).hover()
await expect(page.getByRole("menuitem", { name: "feature/api", exact: true })).toContainText("feature/api")
})
@@ -139,7 +139,7 @@ test.describe("regression: session timeline local row state", () => {
expect(siblingProbe).toEqual({
fileMarker: "before",
frameMarker: "before",
rowKey: `assistant-part:part:${assistantMessageID}:${editPartID}`,
rowKey: `assistant-part:file:part:${assistantMessageID}:${editPartID}`,
rowMarker: "before",
shadowRoots: 0,
toolMarker: "before",
@@ -64,6 +64,76 @@ test("transitions shell and question through running error outcomes", async ({ p
await expect(page.locator(`[data-timeline-part-id="${questionID}"]`)).toContainText(/dismissed/i)
})
test("preserves surviving grouped patch state when its first patch fails", async ({ page }) => {
const failed = "prt_grouped_patch_failed"
const surviving = "prt_grouped_patch_surviving"
const timeline = await setupTimeline(page, {
messages: [
userMessage(),
assistantMessage(
[
toolPart(failed, "patch", "running", { patchText: "Update src/failed.ts" }),
toolPart(
surviving,
"patch",
"running",
{ patchText: "Update src/surviving.ts" },
{
metadata: {
files: [
{
file: "src/surviving.ts",
status: "modified",
patch: "@@ -1 +1 @@\n-export const value = 1\n+export const value = 2",
additions: 1,
deletions: 1,
},
],
},
},
),
],
{ completed: false },
),
],
})
const group = page.locator(`[data-timeline-part-ids="${failed},${surviving}"]`)
const file = group.locator('[data-scope="apply-patch"] button')
await expect(file).toBeVisible()
await file.click()
await expect(file).toHaveAttribute("aria-expanded", "true")
await group.evaluate((element) => {
const row = element.closest<HTMLElement>("[data-timeline-key]")
if (row) row.dataset.groupIdentity = "preserved"
})
await timeline.send(
partUpdated(
toolPart(failed, "patch", "error", { patchText: "Update src/failed.ts" }, { error: "Patch failed visibly" }),
),
)
const failedRow = page.locator("[data-timeline-key]", {
has: page.locator(`[data-timeline-part-id="${failed}"]`),
})
const survivingRow = page.locator("[data-timeline-key]", {
has: page.locator(`[data-timeline-part-id="${surviving}"]`),
})
await expect(failedRow).toHaveAttribute("data-timeline-key", /^assistant-part:part:/)
await expect(survivingRow).toHaveAttribute("data-timeline-key", /^assistant-part:file:/)
await expect(failedRow.getByText("Patch failed visibly")).toBeVisible()
await expect(survivingRow).toHaveAttribute("data-group-identity", "preserved")
await expect(survivingRow.locator('[data-scope="apply-patch"] button')).toHaveAttribute("aria-expanded", "true")
await expect
.poll(async () => {
const previous = await failedRow.boundingBox()
const next = await survivingRow.boundingBox()
return previous && next ? next.y - (previous.y + previous.height) : Number.NEGATIVE_INFINITY
})
.toBeGreaterThanOrEqual(-0.5)
})
test("labels all web search provider variants", async ({ page }) => {
const parts = [
toolPart(
+1
View File
@@ -100,6 +100,7 @@ const Group = HttpApiGroup.make("mock")
.add(HttpApiEndpoint.get("formRequests", "/api/form/request", { success: Json }))
.add(HttpApiEndpoint.get("vcs", "/api/vcs", { success: Json }))
.add(HttpApiEndpoint.get("vcsStatus", "/api/vcs/status", { success: Json }))
.add(HttpApiEndpoint.get("vcsBranches", "/api/vcs/branches", { success: Json }))
.add(HttpApiEndpoint.get("vcsDiff", "/api/vcs/diff", { success: Json }))
.add(HttpApiEndpoint.get("fsList", "/api/fs/list", { query: Query, success: Json }))
.add(
+2
View File
@@ -21,6 +21,7 @@ export interface MockServerConfig {
cursor?: string
}
vcsDiff?: unknown[]
vcsBranches?: string[]
messageDelay?: number
beforeMessagesResponse?: (input: { sessionID: string; before?: string }) => Promise<void>
onMessages?: (input: { sessionID: string; before?: string; phase: "start" | "end" }) => void
@@ -296,6 +297,7 @@ function mockHandlers(config: MockServerConfig, state: { cursors: Map<string, st
vcs: () =>
Effect.succeed({ location: location(config), data: { branch: { current: "main", default: "main" } } }),
vcsStatus: () => Effect.succeed({ location: location(config), data: [] }),
vcsBranches: () => Effect.succeed({ location: location(config), data: config.vcsBranches ?? ["main"] }),
vcsDiff: () => Effect.succeed({ location: location(config), data: config.vcsDiff ?? [] }),
fsList: (ctx) =>
Effect.promise(() => Promise.resolve(config.fileList?.(ctx.query.path ?? ""))).pipe(
+11 -3
View File
@@ -1,7 +1,8 @@
import { createEffect, createMemo, For, Show, type JSX } from "solid-js"
import { createEffect, createMemo, createSignal, For, Show, type JSX } from "solid-js"
import { FileIcon } from "@opencode-ai/ui/file-icon"
import { Icon } from "@opencode-ai/ui/icon"
import { IconButton } from "@opencode-ai/ui/icon-button"
import { createAnimatedPresence } from "@/runtime/animated-presence"
import { ProviderIcon } from "@opencode-ai/ui/provider-icon"
import { useI18n } from "@opencode-ai/ui/context/i18n"
import { Button } from "@opencode-ai/ui/button"
@@ -716,16 +717,23 @@ function ComposerEditorAlternateDelivery(props: { controller: ComposerEditorMode
if (queue.editing()) return "steer" as const
return queue.alternate()
})
const [button, setButton] = createSignal<HTMLButtonElement>()
const presence = createAnimatedPresence(action, () => button() ?? null)
return (
<Show when={action()} keyed>
<Show when={presence.present() && presence.value()} keyed>
{(delivery) => (
<Tooltip placement="top" inactive={delivery !== "steer"} value={i18n.t("ui.promptInput.steerHint")}>
<Button
ref={setButton}
data-action="composer-alternate-delivery"
type="button"
variant="ghost-muted"
size="small"
class="me-3 gap-1.5 px-1.5 text-v2-text-text-muted ![font-weight:530]"
class="me-3 gap-1.5 px-1.5 text-v2-text-text-muted ![font-weight:530] duration-150 motion-reduce:animate-none"
classList={{
"animate-in fade-in": presence.animate() && presence.show(),
"animate-out fade-out fill-mode-forwards": presence.animate() && !presence.show(),
}}
onClick={() => props.controller.submit({ alternate: true })}
>
{delivery === "steer" ? i18n.t("ui.promptInput.steer") : i18n.t("ui.promptInput.queue")}
@@ -20,6 +20,7 @@ import { clearSessionMessageHandoff, setSessionMessageHandoff } from "@/session/
export function createNewSessionComposerAdapter(props: {
draftID: string
worktree: () => string
branch: () => string | undefined
submitted: () => void
}) {
const route = useSessionKey()
@@ -48,6 +49,7 @@ export function createNewSessionComposerAdapter(props: {
const sessionDirectory = await resolveSessionDirectory({
projectDirectory,
worktree,
branch: props.branch(),
data,
serverSDK,
language,
@@ -73,7 +75,7 @@ export function createNewSessionComposerAdapter(props: {
return { ok: false as const, error }
},
)
const afterCreation = async <T,>(run: () => Promise<T>) => {
const afterCreation = async <T>(run: () => Promise<T>) => {
const result = await creation
if (!result.ok) throw result.error
return run()
@@ -83,7 +85,7 @@ export function createNewSessionComposerAdapter(props: {
SessionRouteKey.fromRoute(base64Encode(sessionDirectory), created.id),
)
const cleanupReady = startTransition(() => {
tabs.updateDraft(props.draftID, { worktree: undefined })
tabs.updateDraft(props.draftID, { worktree: undefined, branch: undefined })
local.session.promote(sessionDirectory, created.id, {
agent: selection.agent,
model: selection.model,
@@ -161,6 +163,7 @@ function createMessageHandoff(key: string, sessionID: string, event: ServerSDK["
async function resolveSessionDirectory(input: {
projectDirectory: string
worktree: string
branch?: string
data: ReturnType<typeof useData>
serverSDK: ReturnType<typeof useServerSDK>
language: ReturnType<typeof useLanguage>
@@ -172,6 +175,7 @@ async function resolveSessionDirectory(input: {
.create({
projectID: input.data.location.info({ directory: input.projectDirectory })?.project.id ?? "",
strategy: "git",
branch: input.branch,
directory: getDirectory(
input.data.location.info({ directory: input.projectDirectory })?.project.directory ?? input.projectDirectory,
),
@@ -39,6 +39,7 @@ export function createComposerProjectControls(props: { draftId: string }) {
server: ServerConnection.key(connection),
directory: worktree,
worktree: undefined,
branch: undefined,
})
}
const addProject = (title: string, serverKey?: string) => {
+7 -2
View File
@@ -21,15 +21,20 @@ export default function NewSessionPage(props: { draftId: string }) {
tabs.store.find((tab): tab is DraftTab => tab.type === "draft" && tab.draftID === search.draftId),
)
const workspace = createNewSessionWorkspaceController({
selected: () => draftTab()?.worktree,
setSelected: (worktree) => {
selectedWorktree: () => draftTab()?.worktree,
selectedBranch: () => draftTab()?.branch,
setSelectedWorktree: (worktree) => {
if (search.draftId) tabs.updateDraft(search.draftId, { worktree })
},
setSelectedBranch: (branch) => {
if (search.draftId) tabs.updateDraft(search.draftId, { branch })
},
onViewAll: openWorkspaces,
})
const composer = createNewSessionComposerAdapter({
draftID: props.draftId,
worktree: workspace.selection.value,
branch: workspace.bar.branch,
submitted: workspace.selection.remember,
})
const model = createComposerModel(composer.adapter)
+2
View File
@@ -69,9 +69,11 @@ export function NewSessionView(props: {
value={props.workspace.selection.value()}
projectRoot={props.workspace.project.root()}
workspaces={props.workspace.project.workspaces()}
branches={props.workspace.project.branches()}
branch={props.workspace.bar.branch()}
onboarding={onboardingReady() && !onboarding.used}
onChange={select}
onCreate={props.workspace.selection.create}
onDone={props.composer.restoreFocus}
onViewAll={props.workspace.project.openAll}
/>
@@ -65,6 +65,17 @@ describe("new session workspace selection", () => {
).toBe(undefined)
})
test("uses a selected branch for a new workspace", () => {
expect(
resolveNewSessionBranch({
worktree: "create",
directory: "/project/feature",
createBranch: "release",
worktreeBranch: () => "feature",
}),
).toBe("release")
})
test("uses location VCS state when the project inventory is stale", () => {
expect(resolveNewSessionGit({ branch: "dev" })).toBe(true)
expect(resolveNewSessionGit({ projectVcs: "git" })).toBe(true)
@@ -1,4 +1,4 @@
import { createEffect, createMemo } from "solid-js"
import { createEffect, createMemo, createResource } from "solid-js"
import { useWorkspaceLocation } from "@/workspaces/location"
import { useServerSDK } from "@/runtime/server/client"
import { useData } from "@/runtime/server/current"
@@ -32,8 +32,10 @@ export function normalizeNewSessionWorktree(value: string, directory: string, pr
export function resolveNewSessionBranch(input: {
worktree: string
directory: string
createBranch?: string
worktreeBranch: (worktree: string) => string | undefined
}) {
if (input.worktree === "create" && input.createBranch) return input.createBranch
const directory = input.worktree === "main" || input.worktree === "create" ? input.directory : input.worktree
return input.worktreeBranch(directory)
}
@@ -43,8 +45,10 @@ export function resolveNewSessionGit(input: { projectVcs?: string; branch?: stri
}
export function createNewSessionWorkspaceController(input: {
selected: () => string | undefined
setSelected: (worktree: string | undefined) => void
selectedWorktree: () => string | undefined
selectedBranch: () => string | undefined
setSelectedWorktree: (worktree: string | undefined) => void
setSelectedBranch: (branch: string | undefined) => void
onViewAll: () => void
}) {
const sdk = useWorkspaceLocation()
@@ -64,7 +68,7 @@ export function createNewSessionWorkspaceController(input: {
)
const selected = createMemo(() => {
const project = currentProject()
const worktree = input.selected()
const worktree = input.selectedWorktree()
if (!project || !worktree) return
return isWorkspaceSelection(project, worktree) ? worktree : undefined
})
@@ -86,6 +90,14 @@ export function createNewSessionWorkspaceController(input: {
}),
)
const projectRoot = createMemo(() => currentProject()?.worktree ?? sdk().directory)
const [branches] = createResource(
() => (visible() ? projectRoot() : undefined),
(directory) =>
serverSDK.api.vcs
.branches({ location: { directory } })
.then((response) => ({ directory, data: response.data }))
.catch(() => ({ directory, data: [] })),
)
createEffect(() => {
void Promise.all([data.location.syncInfo({ directory: sdk().directory }), data.project.sync()]).catch(
() => undefined,
@@ -98,6 +110,7 @@ export function createNewSessionWorkspaceController(input: {
resolveNewSessionBranch({
worktree: value(),
directory: sdk().directory,
createBranch: input.selectedBranch(),
worktreeBranch: (worktree) => data.location.vcs.info({ directory: worktree })?.branch.current,
}),
)
@@ -116,10 +129,19 @@ export function createNewSessionWorkspaceController(input: {
const current = value()
return current === "create" || (!!project && isWorkspaceDirectory(project, current))
}),
reset: () => input.setSelected(undefined),
reset: () => {
input.setSelectedWorktree(undefined)
input.setSelectedBranch(undefined)
},
remember,
set: (worktree: string) => {
input.setSelected(normalizeNewSessionWorktree(worktree, sdk().directory, currentProject()?.worktree))
input.setSelectedBranch(undefined)
input.setSelectedWorktree(normalizeNewSessionWorktree(worktree, sdk().directory, currentProject()?.worktree))
},
create: (branch: string) => {
input.setSelectedBranch(branch)
input.setSelectedWorktree("create")
remember("create")
},
},
project: {
@@ -129,6 +151,12 @@ export function createNewSessionWorkspaceController(input: {
return project ? workspaceDirectories(project) : []
},
git: visible,
branches: () => {
const current = data.location.vcs.info({ directory: sdk().directory })?.branch.current
const loaded = branches.latest
const list = loaded?.directory === projectRoot() ? loaded.data : []
return [...new Set([...list, ...(current ? [current] : [])])]
},
openAll: input.onViewAll,
},
bar: {
@@ -1,4 +1,5 @@
import { createMemo, createSignal, For, Show } from "solid-js"
import { createMemo, For, Show } from "solid-js"
import { createStore } from "solid-js/store"
import { Menu } from "@opencode-ai/ui/menu"
import { Tooltip } from "@opencode-ai/ui/tooltip"
import { Icon } from "@opencode-ai/ui/icon"
@@ -10,23 +11,32 @@ export function PromptWorkspaceSelector(props: {
value: string
projectRoot: string
workspaces: string[]
branches: string[]
branch?: string
onboarding?: boolean
onChange: (value: string) => void
onCreate: (branch: string) => void
onDone: () => void
onViewAll: () => void
}) {
const language = useLanguage()
const [search, setSearch] = createSignal("")
const [search, setSearch] = createStore({ workspaces: "", branches: "" })
let searchInput: HTMLInputElement | undefined
let branchSearchInput: HTMLInputElement | undefined
let focusSearch = false
let pending: { type: "select"; value: string } | { type: "viewAll" } | undefined
let focusBranchSearch = false
let pending: { type: "select"; value: string } | { type: "create"; branch: string } | { type: "viewAll" } | undefined
const selected = () => (sameDirectory(props.value, props.projectRoot) ? "main" : props.value)
const workspaces = createMemo(() => {
const query = search().trim().toLowerCase()
const query = search.workspaces.trim().toLowerCase()
if (!query) return props.workspaces
return props.workspaces.filter((workspace) => getFilename(workspace).toLowerCase().includes(query))
})
const branches = createMemo(() => {
const query = search.branches.trim().toLowerCase()
if (!query) return props.branches
return props.branches.filter((branch) => branch.toLowerCase().includes(query))
})
const icon = () => {
if (selected() === "main") return "monitor"
if (selected() === "create") return "workspace-new"
@@ -37,12 +47,13 @@ export function PromptWorkspaceSelector(props: {
}
const onOpenChange = (open: boolean) => {
if (open) {
setSearch("")
setSearch({ workspaces: "", branches: "" })
return
}
const action = pending
pending = undefined
if (action?.type === "select") props.onChange(action.value)
if (action?.type === "create") props.onCreate(action.branch)
if (action?.type === "viewAll") {
props.onViewAll()
return
@@ -118,27 +129,88 @@ export function PromptWorkspaceSelector(props: {
<Icon name="check" size="small" class="shrink-0" />
</Show>
</Menu.Item>
<Menu.Item onSelect={() => select("create")}>
<Icon name="workspace-new" />
<Tooltip
placement="right"
openDelay={800}
value={
<span class="flex flex-col gap-0.5">
<span>{language.t("workspace.new")}</span>
<span class="font-[440] text-v2-text-text-muted">
{language.t("session.new.workspace.new.tooltip")}
</span>
</span>
}
class="min-w-0 flex-1"
<Show
when={props.branches.length > 0}
fallback={
<Menu.Item onSelect={() => select("create")}>
<Icon name="workspace-new" />
<span class="min-w-0 flex-1 truncate">{language.t("workspace.new")}</span>
</Menu.Item>
}
>
<Menu.Sub
gutter={0}
overlap
overflowPadding={8}
onOpenChange={(open) => {
if (!open) {
focusBranchSearch = false
return
}
if (!focusBranchSearch || props.branches.length < 10) return
focusBranchSearch = false
requestAnimationFrame(() => branchSearchInput?.focus())
}}
>
<span class="min-w-0 truncate">{language.t("workspace.new")}</span>
</Tooltip>
<Show when={selected() === "create"}>
<Icon name="check" size="small" class="shrink-0" />
</Show>
</Menu.Item>
<Menu.SubTrigger
onKeyDown={(event) => {
if (
event.key === "ArrowRight" ||
event.key === "ArrowLeft" ||
event.key === "Enter" ||
event.key === " "
)
focusBranchSearch = true
}}
>
<Icon name="workspace-new" />
<span class="min-w-0 flex-1 truncate">{language.t("workspace.new")}</span>
<Show when={selected() === "create"}>
<Icon name="check" size="small" class="shrink-0" />
</Show>
</Menu.SubTrigger>
<Menu.Portal>
<Menu.SubContent class="max-h-[calc(100dvh-16px)] w-[220px] overflow-y-auto">
<Menu.GroupLabel>{language.t("session.new.workspace.createFrom")}</Menu.GroupLabel>
<Show when={props.branches.length >= 10}>
<div class="flex h-7 items-center gap-2 rounded-sm ps-3 pe-2 text-v2-icon-icon-muted">
<Icon name="magnifying-glass" size="small" class="shrink-0" />
<input
ref={(element) => {
branchSearchInput = element
}}
value={search.branches}
placeholder={language.t("session.new.workspace.branch.search.placeholder")}
aria-label={language.t("session.new.workspace.branch.search.placeholder")}
class="h-7 min-w-0 flex-1 border-0 bg-transparent text-[13px] font-[440] leading-5 tracking-[-0.04px] text-v2-text-text-base outline-none placeholder:text-v2-text-text-faint"
onInput={(event) => setSearch("branches", event.currentTarget.value)}
onKeyDown={(event) => {
if (
event.key === "Escape" ||
event.key === "ArrowDown" ||
event.key === "ArrowUp" ||
event.key === "Enter"
)
return
event.stopPropagation()
}}
/>
</div>
</Show>
<For each={branches()}>
{(branch) => (
<Menu.Item onSelect={() => (pending = { type: "create", branch })}>
<span class="min-w-0 flex-1 truncate">{branch}</span>
<Show when={selected() === "create" && props.branch === branch}>
<Icon name="check" size="small" class="shrink-0" />
</Show>
</Menu.Item>
)}
</For>
</Menu.SubContent>
</Menu.Portal>
</Menu.Sub>
</Show>
</Menu.Group>
<Show
when={props.workspaces.length > 0}
@@ -191,11 +263,11 @@ export function PromptWorkspaceSelector(props: {
ref={(element) => {
searchInput = element
}}
value={search()}
value={search.workspaces}
placeholder={language.t("session.new.workspace.search.placeholder")}
aria-label={language.t("session.new.workspace.search.placeholder")}
class="h-7 min-w-0 flex-1 border-0 bg-transparent text-[13px] font-[440] leading-5 tracking-[-0.04px] text-v2-text-text-base outline-none placeholder:text-v2-text-text-faint"
onInput={(event) => setSearch(event.currentTarget.value)}
onInput={(event) => setSearch("workspaces", event.currentTarget.value)}
onKeyDown={(event) => {
if (
event.key === "Escape" ||
@@ -0,0 +1,21 @@
import { createMemo, type Accessor } from "solid-js"
import createPresence from "solid-presence"
export function createAnimatedPresence<T>(value: Accessor<T | undefined>, element: Accessor<HTMLElement | null>) {
const animation = createMemo<{ show: boolean; animate: boolean; value: T | undefined }>((previous) => {
const current = value()
const show = current !== undefined
return {
show,
animate: previous !== undefined && (previous.animate || previous.show !== show),
value: current ?? previous?.value,
}
})
const presence = createPresence({ show: () => animation().show, element })
return {
...presence,
show: () => animation().show,
animate: () => animation().animate,
value: () => animation().value,
}
}
+2
View File
@@ -1151,6 +1151,8 @@ export const dict = {
"session.new.workspace.local.tooltip": "Use current checkout",
"session.new.workspace.new.tooltip": "Create isolated checkout",
"session.new.workspace.fromBranch": "from {{branch}}",
"session.new.workspace.createFrom": "Create from branch",
"session.new.workspace.branch.search.placeholder": "Search branches",
"session.new.workspace.trigger.tooltip": "Select where to run session",
"session.new.workspace.search.placeholder": "Search workspaces",
"settings.tab.workspaces": "Workspaces",
@@ -1,6 +1,6 @@
import { createEffect, createMemo, createSignal, For, on, Show, type Accessor, type JSX } from "solid-js"
import createPresence from "solid-presence"
import { createStore } from "solid-js/store"
import { createAnimatedPresence } from "@/runtime/animated-presence"
import type { SessionUserActions } from "@opencode-ai/session-ui/actions"
import { Badge } from "@opencode-ai/ui/badge"
import { DiffChanges } from "@opencode-ai/ui/diff-changes"
@@ -479,17 +479,7 @@ function MessageTimelineView(
return row.group.ref.partID
})
const [backgroundHintRef, setBackgroundHintRef] = createSignal<HTMLDivElement>()
const backgroundHintVisibility = createMemo<{ show: boolean; animate: boolean }>(
(previous) => {
const show = backgroundHintPartID() !== undefined
return { show, animate: previous.animate || previous.show !== show }
},
{ show: backgroundHintPartID() !== undefined, animate: false },
)
const backgroundHintPresence = createPresence({
show: () => backgroundHintVisibility().show,
element: () => backgroundHintRef() ?? null,
})
const backgroundHintPresence = createAnimatedPresence(backgroundHintPartID, () => backgroundHintRef() ?? null)
return (
<VirtualizedTimeline
workspaceSession={workspaceSession}
@@ -507,9 +497,9 @@ function MessageTimelineView(
class="duration-150 motion-reduce:animate-none"
classList={{
[`flex h-9 items-start pt-3 ${turnPadding()}`]: true,
"animate-in fade-in": backgroundHintVisibility().animate && backgroundHintVisibility().show,
"animate-in fade-in": backgroundHintPresence.animate() && backgroundHintPresence.show(),
"animate-out fade-out fill-mode-forwards":
backgroundHintVisibility().animate && !backgroundHintVisibility().show,
backgroundHintPresence.animate() && !backgroundHintPresence.show(),
}}
>
<BackgroundMoveHint />
@@ -0,0 +1,26 @@
import { expect, test } from "bun:test"
import type { ServerConnection } from "@/runtime/server/registry"
import type { Tab } from "@/shell/tabs/tabs"
import { openNotificationSession } from "./notification"
test("opens notification sessions through the tab router", () => {
const server = "local\nhttp://localhost:4096" as ServerConnection.Key
const tab = { type: "session" as const, server, sessionId: "session-1" }
const calls: string[] = []
const tabs = {
addSessionTab: (input: Omit<typeof tab, "type">) => {
calls.push(`add:${input.sessionId}`)
return tab
},
rememberSessionRoute: (_tab: typeof tab, sessionID: string) => {
calls.push(`route:${sessionID}`)
},
select: (input: Tab) => {
calls.push(`select:${input.type === "session" ? input.sessionId : input.draftID}`)
},
}
openNotificationSession(tabs, server, "session-1")
expect(calls).toEqual(["add:session-1", "route:session-1", "select:session-1"])
})
@@ -51,6 +51,19 @@ type NotificationIndex = {
}
}
type NotificationTabs = Pick<ReturnType<typeof useTabs>, "addSessionTab" | "rememberSessionRoute" | "select">
export function openNotificationSession(
tabs: NotificationTabs,
server: ServerConnection.Key,
sessionID: string,
) {
const tab = tabs.addSessionTab({ server, sessionId: sessionID })
if (tab.type !== "session") return
tabs.rememberSessionRoute(tab, sessionID)
tabs.select(tab)
}
const MAX_NOTIFICATIONS = 500
const NOTIFICATION_TTL_MS = 1000 * 60 * 60 * 24 * 30
@@ -211,11 +224,6 @@ export function createServerNotificationState(input: { sdk: ServerSDK; data: Dat
return typeof location !== "undefined" && location.pathname === sessionHref(input.key, sessionID)
}
const navigate = (href: string) => {
history.pushState(null, "", href)
dispatchEvent(new PopStateEvent("popstate"))
}
const handleSessionIdle = (sessionID: string, eventID: string, time: number) => {
void lookup(sessionID).then((session) => {
if (meta.disposed) return
@@ -237,10 +245,9 @@ export function createServerNotificationState(input: { sdk: ServerSDK; data: Dat
session: sessionID,
})
const href = sessionHref(input.key, sessionID)
if (settings.notifications.agent()) {
void platform.notify(language.t("notification.session.responseReady.title"), session.title ?? sessionID, () =>
navigate(href),
openNotificationSession(tabs, input.key, sessionID),
)
}
})
@@ -274,9 +281,10 @@ export function createServerNotificationState(input: { sdk: ServerSDK; data: Dat
const description =
session?.title ??
(typeof error === "string" ? error : language.t("notification.session.error.fallbackDescription"))
const href = sessionHref(input.key, sessionID)
if (settings.notifications.errors()) {
void platform.notify(language.t("notification.session.error.title"), description, () => navigate(href))
void platform.notify(language.t("notification.session.error.title"), description, () =>
openNotificationSession(tabs, input.key, sessionID),
)
}
})
}
+12 -2
View File
@@ -31,9 +31,19 @@ export function migrateTabs(value: unknown): Tab[] {
tab.type === "draft" &&
typeof tab.draftID === "string" &&
typeof tab.directory === "string" &&
(tab.worktree === undefined || typeof tab.worktree === "string")
(tab.worktree === undefined || typeof tab.worktree === "string") &&
(tab.branch === undefined || typeof tab.branch === "string")
) {
return [{ type: tab.type, server, draftID: tab.draftID, directory: tab.directory, worktree: tab.worktree }]
return [
{
type: tab.type,
server,
draftID: tab.draftID,
directory: tab.directory,
worktree: tab.worktree,
branch: tab.branch,
},
]
}
return []
})
+1
View File
@@ -29,6 +29,7 @@ export type DraftTab = {
server: ServerConnection.Key
directory: string
worktree?: string
branch?: string
}
export type Tab = SessionTab | DraftTab
@@ -0,0 +1,49 @@
import { expect, test } from "bun:test"
import { createAnimatedPresence } from "../src/runtime/animated-presence"
import { createRoot, createSignal } from "solid-js"
test("animates visibility changes without animating initial presence", () => {
createRoot((dispose) => {
const [value, setValue] = createSignal<string | undefined>("steer")
const presence = createAnimatedPresence(value, () => null)
expect(presence.show()).toBe(true)
expect(presence.animate()).toBe(false)
expect(presence.value()).toBe("steer")
expect(presence.present()).toBe(true)
setValue("queue")
expect(presence.animate()).toBe(false)
expect(presence.value()).toBe("queue")
setValue(undefined)
expect(presence.show()).toBe(false)
expect(presence.animate()).toBe(true)
expect(presence.value()).toBe("queue")
setValue("steer")
expect(presence.show()).toBe(true)
expect(presence.animate()).toBe(true)
expect(presence.value()).toBe("steer")
dispose()
})
})
test("animates the first appearance when initially hidden", () => {
createRoot((dispose) => {
const [value, setValue] = createSignal<string | undefined>()
const presence = createAnimatedPresence(value, () => null)
expect(presence.show()).toBe(false)
expect(presence.animate()).toBe(false)
expect(presence.present()).toBe(false)
setValue("steer")
expect(presence.show()).toBe(true)
expect(presence.animate()).toBe(true)
expect(presence.value()).toBe("steer")
dispose()
})
})
+8
View File
@@ -1664,6 +1664,7 @@ export type WorktreeCreateInput = {
readonly projectID: Project.ID
readonly strategy: Worktree.StrategyID
readonly from?: AbsolutePath | undefined
readonly branch?: string | undefined
readonly directory: AbsolutePath
readonly name?: string | undefined
}
@@ -1720,6 +1721,12 @@ export type VcsStatusInput = {
export type VcsStatusOutput = { readonly location: Location.Info; readonly data: ReadonlyArray<Vcs.FileStatus> }
export type VcsStatusOperation<E = never> = (input?: VcsStatusInput) => Effect.Effect<VcsStatusOutput, E>
export type VcsBranchesInput = {
readonly location?: { readonly directory?: string | undefined; readonly workspace?: string | undefined } | undefined
}
export type VcsBranchesOutput = { readonly location: Location.Info; readonly data: Vcs.BranchList }
export type VcsBranchesOperation<E = never> = (input?: VcsBranchesInput) => Effect.Effect<VcsBranchesOutput, E>
export type VcsDiffInput = {
readonly location?: { readonly directory?: string | undefined; readonly workspace?: string | undefined } | undefined
readonly mode: Vcs.Mode
@@ -1731,6 +1738,7 @@ export type VcsDiffOperation<E = never> = (input: VcsDiffInput) => Effect.Effect
export interface VcsApi<E = never> {
readonly get: VcsGetOperation<E>
readonly status: VcsStatusOperation<E>
readonly branches: VcsBranchesOperation<E>
readonly diff: VcsDiffOperation<E>
}
+15 -1
View File
@@ -222,6 +222,8 @@ import type {
VcsGetOutput,
VcsStatusInput,
VcsStatusOutput,
VcsBranchesInput,
VcsBranchesOutput,
VcsDiffInput,
VcsDiffOutput,
DebugLocationListOutput,
@@ -1248,7 +1250,13 @@ const EndpointWorktreeCreate = (raw: RawClient["server.worktree"]) => (input: Wo
preserveEffect<WorktreeCreateOutput>()(
raw["worktree.create"]({
params: { projectID: input["projectID"] },
payload: { strategy: input["strategy"], from: input["from"], directory: input["directory"], name: input["name"] },
payload: {
strategy: input["strategy"],
from: input["from"],
branch: input["branch"],
directory: input["directory"],
name: input["name"],
},
}).pipe(Effect.mapError(mapClientError)),
)
@@ -1300,6 +1308,11 @@ const EndpointVcsStatus = (raw: RawClient["server.vcs"]) => (input?: VcsStatusIn
raw["vcs.status"]({ query: { location: input?.["location"] } }).pipe(Effect.mapError(mapClientError)),
)
const EndpointVcsBranches = (raw: RawClient["server.vcs"]) => (input?: VcsBranchesInput) =>
preserveEffect<VcsBranchesOutput>()(
raw["vcs.branches"]({ query: { location: input?.["location"] } }).pipe(Effect.mapError(mapClientError)),
)
const EndpointVcsDiff = (raw: RawClient["server.vcs"]) => (input: VcsDiffInput) =>
preserveEffect<VcsDiffOutput>()(
raw["vcs.diff"]({ query: { location: input["location"], mode: input["mode"], context: input["context"] } }).pipe(
@@ -1310,6 +1323,7 @@ const EndpointVcsDiff = (raw: RawClient["server.vcs"]) => (input: VcsDiffInput)
const adaptGroupVcs = (raw: RawClient["server.vcs"]) => ({
get: EndpointVcsGet(raw),
status: EndpointVcsStatus(raw),
branches: EndpointVcsBranches(raw),
diff: EndpointVcsDiff(raw),
})
@@ -218,6 +218,8 @@ import type {
VcsGetOutput,
VcsStatusInput,
VcsStatusOutput,
VcsBranchesInput,
VcsBranchesOutput,
VcsDiffInput,
VcsDiffOutput,
DebugLocationListOutput,
@@ -1736,6 +1738,7 @@ export function make(options: ClientOptions) {
body: {
strategy: input["strategy"],
from: input["from"],
branch: input["branch"],
directory: input["directory"],
name: input["name"],
},
@@ -1819,6 +1822,18 @@ export function make(options: ClientOptions) {
},
requestOptions,
),
branches: (input?: VcsBranchesInput, requestOptions?: RequestOptions) =>
request<VcsBranchesOutput>(
{
method: "GET",
path: `/api/vcs/branches`,
query: { location: input?.["location"] },
successStatus: 200,
declaredStatuses: [401, 400],
empty: false,
},
requestOptions,
),
diff: (input: VcsDiffInput, requestOptions?: RequestOptions) =>
request<VcsDiffOutput>(
{
@@ -393,6 +393,8 @@ export type VcsFileStatus = {
status: "added" | "deleted" | "modified"
}
export type VcsBranchList = Array<string>
export type WebSearchProvider = { id: string; name: string }
export type WebSearchResult = { url: string; title?: string; content?: string; time: { published?: number } }
@@ -5593,24 +5595,35 @@ export type WorktreeCreateInput = {
readonly strategy: {
readonly strategy: string
readonly from?: string
readonly branch?: string
readonly directory: string
readonly name?: string
}["strategy"]
readonly from?: {
readonly strategy: string
readonly from?: string
readonly branch?: string
readonly directory: string
readonly name?: string
}["from"]
readonly branch?: {
readonly strategy: string
readonly from?: string
readonly branch?: string
readonly directory: string
readonly name?: string
}["branch"]
readonly directory: {
readonly strategy: string
readonly from?: string
readonly branch?: string
readonly directory: string
readonly name?: string
}["directory"]
readonly name?: {
readonly strategy: string
readonly from?: string
readonly branch?: string
readonly directory: string
readonly name?: string
}["name"]
@@ -5663,6 +5676,17 @@ export type VcsStatusOutput = {
data: Array<VcsFileStatus>
}
export type VcsBranchesInput = {
readonly location?: {
readonly location?: { readonly directory?: string | undefined; readonly workspace?: string | undefined } | undefined
}["location"]
}
export type VcsBranchesOutput = {
location: { directory: string; workspaceID?: string; project: { id: string; directory: string; canonical: string } }
data: VcsBranchList
}
export type VcsDiffInput = {
readonly location?: {
readonly location?: { readonly directory?: string | undefined; readonly workspace?: string | undefined } | undefined
+1 -2
View File
@@ -27,7 +27,6 @@ test("exposes every standard HTTP API group", () => {
"event",
"pty",
"shell",
"question",
"reference",
"worktree",
"workspace",
@@ -47,7 +46,7 @@ test("exposes every standard HTTP API group", () => {
expect(Object.keys(client.integration.command)).toEqual(["connect", "status", "cancel"])
expect(Object.keys(client.websearch)).toEqual(["providers", "query"])
expect(Object.keys(client.file)).toEqual(["read", "list", "find"])
expect(Object.keys(client.vcs)).toEqual(["get", "status", "diff"])
expect(Object.keys(client.vcs)).toEqual(["get", "status", "branches", "diff"])
expect(Object.keys(client.pty)).toEqual(["list", "create", "get", "update", "remove", "connect"])
expect(Object.keys(client.pty.connect)).toEqual(["token"])
expect(Object.keys(client.shell)).toEqual(["list", "create", "get", "timeout", "output", "remove"])
+1 -1
View File
@@ -176,7 +176,7 @@ function evaluateTemplate(
: withArguments.trim()
const matches = Array.from(text.matchAll(shellRegex))
if (matches.length === 0) return text
const shell = yield* services.shell.preferred()
const shell = yield* services.shell.resolve({ priority: "config" })
const outputs = yield* Effect.forEach(
matches,
(match) => {
+3 -1
View File
@@ -109,6 +109,7 @@ export interface Interface {
readonly create: (input: {
repository: Repository
directory: AbsolutePath
ref?: string
}) => Effect.Effect<Repository, WorktreeError>
readonly remove: (input: {
repository: Repository
@@ -644,11 +645,12 @@ const layer = Layer.effect(
const worktreeCreate = Effect.fn("Git.worktree.create")(function* (input: {
repository: Repository
directory: AbsolutePath
ref?: string
}) {
yield* worktreeRun(
"create",
input.repository,
["worktree", "add", "--detach", input.directory, "HEAD"],
["worktree", "add", "--detach", "--", input.directory, input.ref ?? "HEAD"],
input.directory,
)
const repository = yield* discover(input.directory)
@@ -207,7 +207,7 @@ export const GithubCopilotPlugin = define({
} else {
for (const id of item.models.keys()) {
evt.model.update(item.provider.id, id, (model) => {
model.package = "@ai-sdk/github-copilot"
model.package = Provider.aisdk("@ai-sdk/github-copilot")
if (loaded.baseURL) model.settings = Provider.mergeOverlay(model.settings, { baseURL: loaded.baseURL })
})
}
+1 -1
View File
@@ -164,7 +164,7 @@ const layer = () =>
const create = Effect.fn("Pty.create")(function* (input: CreateInput) {
const id = PtyID.ascending()
const command = input.command || (yield* shell.preferred())
const command = input.command || (yield* shell.resolve({ priority: "config" }))
const args = ShellSelect.login(command) ? [...(input.args ?? []), "-l"] : [...(input.args ?? [])]
const cwd = input.cwd || location.directory
const env = {
+7 -7
View File
@@ -30,6 +30,9 @@ export const RETENTION = Duration.days(7)
export const DIRECTORY = "shell"
type Info = Shell.Info
type CreateInput = Shell.CreateInput & {
shell?: string
}
type Active = {
// Immutable snapshot; lifecycle updates replace it via immer `produce`.
@@ -52,9 +55,8 @@ type Active = {
* here; callers (e.g. `ShellTool`) own that association and store the shell ID.
*/
export interface Interface {
readonly name: () => Effect.Effect<string>
readonly create: <E = never, R = never>(
input: Shell.CreateInput,
input: CreateInput,
before?: (input: ShellCreateBefore) => Effect.Effect<void, E, R>,
) => Effect.Effect<Shell.Info, E | AppProcess.AppProcessError, R>
// Currently running commands only; exited shells are retained for get/output but excluded here.
@@ -185,8 +187,6 @@ const layer = () =>
return session.info
})
const name = () => shell.preferred().pipe(Effect.map(ShellSelect.name))
const output = Effect.fnUntraced(function* (id: Shell.ID, input?: Shell.OutputInput) {
const session = yield* require(id)
const cursor = input?.cursor ?? 0
@@ -218,7 +218,7 @@ const layer = () =>
})
const create = Effect.fn("Shell.create")(function* <E = never, R = never>(
input: Shell.CreateInput,
input: CreateInput,
before?: (input: ShellCreateBefore) => Effect.Effect<void, E, R>,
) {
const sessionID = input.metadata?.sessionID
@@ -230,7 +230,7 @@ const layer = () =>
command: input.command,
cwd: input.cwd ?? location.directory,
timeout: input.timeout,
shell: yield* shell.preferred(),
shell: input.shell ?? (yield* shell.resolve({ priority: "config" })),
env: {
...(sessionEnvironment ?? process.env),
TERM: "xterm-256color",
@@ -383,7 +383,7 @@ const layer = () =>
return session.info
})
return Service.of({ name, create, list, get, wait, timeout, output, remove })
return Service.of({ create, list, get, wait, timeout, output, remove })
}),
)
+27 -33
View File
@@ -41,8 +41,12 @@ export type Draft = {
configure: (shell: string) => void
}
export type ResolveInput = {
priority: "config" | "compat"
}
export interface Interface extends State.Transformable<Draft> {
readonly preferred: () => Effect.Effect<string>
readonly resolve: (input: ResolveInput) => Effect.Effect<string>
}
export class Service extends Context.Service<Service, Interface>()("@opencode/ShellSelect") {}
@@ -70,7 +74,7 @@ function meta(file: string) {
return META[name(file)]
}
function ok(file: string) {
function compatible(file: string) {
return meta(file)?.deny !== true
}
@@ -78,7 +82,7 @@ function rooted(file: string) {
return path.isAbsolute(FSUtil.windowsPath(file))
}
function resolve(file: string, options?: Options, bin?: string) {
function executable(file: string, options?: Options, bin?: string) {
const shell = full(file, options, bin)
if (rooted(shell)) {
if (stat(shell)?.isFile()) return shell
@@ -108,9 +112,9 @@ async function unix() {
return ["/bin/bash", "/bin/zsh", "/bin/sh"]
}
function select(file: string | undefined, options?: Options, opts?: { acceptable?: boolean }, bin?: string) {
if (file && (!opts?.acceptable || ok(file))) {
const shell = resolve(file, options, bin)
function select(file: string | undefined, options?: Options, opts?: { compatible?: boolean }, bin?: string) {
if (file && (!opts?.compatible || compatible(file))) {
const shell = executable(file, options, bin)
if (shell) return shell
}
if (process.platform === "win32") return win(options, bin)[0]
@@ -151,8 +155,8 @@ function info(file: string, options?: Options, bin?: string): Item {
const n = name(item)
return {
path: item,
name: resolve(n, options, bin) ? n : item,
acceptable: ok(item),
name: executable(n, options, bin) ? n : item,
acceptable: compatible(item),
}
}
@@ -163,38 +167,28 @@ export function args(file: string, command: string) {
return ["-c", command]
}
let defaultPreferred: { bin?: string; value: string } | undefined
let defaultAcceptable: { bin?: string; value: string } | undefined
let defaultConfigured: { bin?: string; value: string } | undefined
let defaultCompatible: { bin?: string; value: string } | undefined
export function preferred(configShell?: string, options?: Options, bin?: string) {
if (configShell) return select(configShell, options, undefined, bin)
if (options?.gitbash) return select(process.env.SHELL, options, undefined, bin)
const cached = defaultPreferred
export function resolve(input: ResolveInput, configShell?: string, options?: Options, bin?: string) {
const filter = input.priority === "compat" ? { compatible: true } : undefined
if (configShell) return select(configShell, options, filter, bin)
if (options?.gitbash) return select(process.env.SHELL, options, filter, bin)
const cached = input.priority === "compat" ? defaultCompatible : defaultConfigured
if (cached && cached.bin === bin) return cached.value
const value = select(process.env.SHELL, undefined, undefined, bin) ?? fallback(bin)
defaultPreferred = { bin, value }
const value = select(process.env.SHELL, undefined, filter, bin) ?? fallback(bin)
if (input.priority === "compat") defaultCompatible = { bin, value }
if (input.priority === "config") defaultConfigured = { bin, value }
return value
}
preferred.reset = () => {
defaultPreferred = undefined
}
export function acceptable(configShell?: string, options?: Options, bin?: string) {
if (configShell) return select(configShell, options, { acceptable: true }, bin)
if (options?.gitbash) return select(process.env.SHELL, options, { acceptable: true }, bin)
const cached = defaultAcceptable
if (cached && cached.bin === bin) return cached.value
const value = select(process.env.SHELL, undefined, { acceptable: true }, bin) ?? fallback(bin)
defaultAcceptable = { bin, value }
return value
}
acceptable.reset = () => {
defaultAcceptable = undefined
resolve.reset = () => {
defaultConfigured = undefined
defaultCompatible = undefined
}
export async function list(options?: Options, bin?: string): Promise<Item[]> {
const shells = process.platform === "win32" ? win(options, bin) : await unix()
return shells.filter((shell) => resolve(shell, options, bin)).map((shell) => info(shell, options, bin))
return shells.filter((shell) => executable(shell, options, bin)).map((shell) => info(shell, options, bin))
}
const layer = (options?: Options) =>
@@ -214,7 +208,7 @@ const layer = (options?: Options) =>
return Service.of({
transform: state.transform,
reload: state.reload,
preferred: () => Effect.sync(() => preferred(state.get().shell, options, global.bin)),
resolve: (input) => Effect.sync(() => resolve(input, state.get().shell, options, global.bin)),
})
}),
)
+5 -1
View File
@@ -13,6 +13,7 @@ import { NonNegativeInt } from "../../schema.js"
import { SessionSchema } from "../../session/schema.js"
import { Shell } from "../../shell.js"
import { ShellParse } from "../../shell/parse.js"
import { ShellSelect } from "../../shell/select.js"
import { ToolOutput } from "../../tool-output.js"
export const name = "shell"
@@ -109,6 +110,8 @@ export const Plugin = {
const environment = yield* Environment.Service
const mutation = yield* LocationMutation.Service
const shell = yield* Shell.Service
const shellSelect = yield* ShellSelect.Service
const compatibleShell = shellSelect.resolve({ priority: "compat" })
const permission = yield* Permission.Service
const config = yield* Config.Service
@@ -185,6 +188,7 @@ export const Plugin = {
command: input.command,
cwd: input.workdir,
timeout,
shell: yield* compatibleShell,
metadata: { sessionID: context.sessionID },
},
(invocation) =>
@@ -340,7 +344,7 @@ export const Plugin = {
Effect.gen(function* () {
const tool = event.tools[name]
if (!tool) return
tool.description = description(yield* shell.name())
tool.description = description(ShellSelect.name(yield* compatibleShell))
}),
)
}),
+15 -6
View File
@@ -2,6 +2,7 @@ import type { ToolDefinition } from "@opencode-ai/ai"
import { Tool } from "@opencode-ai/schema/tool"
import type { StandardJSONSchemaV1, StandardSchemaV1 } from "@standard-schema/spec"
import { Cache, Effect, JsonSchema, Schema, SchemaIssue, SchemaRepresentation } from "effect"
import { $ZodType, toJSONSchema } from "zod/v4/core"
const formatEffectIssues = SchemaIssue.makeFormatterStandardSchemaV1()
@@ -129,13 +130,15 @@ const encodeOutput = (schema: Tool.ValueSchema<any>, value: unknown) => {
)
}
const isStandardSchema = (
schema: Tool.ValueSchema<any>,
): schema is StandardSchemaV1<any, any> & StandardJSONSchemaV1<any, any> =>
const isStandardSchema = (schema: Tool.ValueSchema<any>): schema is StandardSchemaV1<any, any> =>
typeof schema === "object" && schema !== null && "~standard" in schema
const isStandardJSONSchema = (
schema: StandardSchemaV1<any, any>,
): schema is StandardSchemaV1<any, any> & StandardJSONSchemaV1<any, any> => "jsonSchema" in schema["~standard"]
const validateStandard = (
schema: StandardSchemaV1<any, any> & StandardJSONSchemaV1<any, any>,
schema: StandardSchemaV1<any, any>,
value: unknown,
): Effect.Effect<StandardSchemaV1.Result<unknown>> =>
Effect.gen(function* () {
@@ -150,15 +153,21 @@ const validateStandard = (
const inputJsonSchema = (schema: Tool.ValueSchema<any>): JsonSchema.JsonSchema => {
if (schema === undefined || schema === null) return {}
if (isStandardSchema(schema)) return schema["~standard"].jsonSchema.input({ target: "draft-2020-12" })
if (isStandardSchema(schema)) return standardJsonSchema(schema, "input")
return Schema.isSchema(schema) ? toJsonSchema(schema) : schema
}
const outputJsonSchema = (schema: Tool.ValueSchema<any>): JsonSchema.JsonSchema => {
if (isStandardSchema(schema)) return schema["~standard"].jsonSchema.output({ target: "draft-2020-12" })
if (isStandardSchema(schema)) return standardJsonSchema(schema, "output")
return Schema.isSchema(schema) ? toJsonSchema(schema) : schema
}
const standardJsonSchema = (schema: StandardSchemaV1<any, any>, io: "input" | "output"): JsonSchema.JsonSchema => {
if (isStandardJSONSchema(schema)) return schema["~standard"].jsonSchema[io]({ target: "draft-2020-12" })
if (schema instanceof $ZodType) return toJSONSchema(schema, { target: "draft-2020-12", io })
throw new Error(`Schema vendor "${schema["~standard"].vendor}" does not support JSON Schema conversion`)
}
const toJsonSchema = (schema: Schema.Top): JsonSchema.JsonSchema => {
const document = Schema.toJsonSchemaDocument(schema)
// Effect emits valid JSON Schema that some inference providers handle poorly. Simplify it
+7 -2
View File
@@ -4,7 +4,7 @@ import path from "path"
import { Context, Effect, Layer, Stream } from "effect"
import { FileDiff } from "@opencode-ai/schema/file-diff"
import { FileSystem } from "@opencode-ai/schema/filesystem"
import { FileStatus, Info, Mode } from "@opencode-ai/schema/vcs"
import { BranchList, FileStatus, Info, Mode } from "@opencode-ai/schema/vcs"
import { VcsEvent } from "@opencode-ai/schema/vcs-event"
import { makeLocationNode } from "@opencode-ai/util/effect/app-node"
import { FSUtil } from "@opencode-ai/util/fs-util"
@@ -14,7 +14,7 @@ import { Bus } from "./bus.js"
import { VcsGit } from "./vcs/git.js"
import { VcsHg } from "./vcs/hg.js"
export { FileStatus, Info, Mode }
export { BranchList, FileStatus, Info, Mode }
export interface DiffOptions {
readonly context?: number
@@ -22,6 +22,7 @@ export interface DiffOptions {
export interface Interface {
readonly info: () => Effect.Effect<Info>
readonly branches: () => Effect.Effect<BranchList>
readonly status: () => Effect.Effect<FileStatus[]>
readonly diff: (mode: Mode, options?: DiffOptions) => Effect.Effect<FileDiff.Info[]>
}
@@ -73,6 +74,10 @@ const layer = Layer.effect(
info: Effect.fn("Vcs.info")(function* () {
return state.info
}),
branches: Effect.fn("Vcs.branches")(function* () {
if (!impl) return []
return yield* impl.branches()
}),
status: Effect.fn("Vcs.status")(function* () {
if (!impl) return []
return yield* impl.status()
+11 -1
View File
@@ -3,7 +3,7 @@ export * as VcsGit from "./git.js"
import { Effect } from "effect"
import { ChildProcess } from "effect/unstable/process"
import { FileDiff } from "@opencode-ai/schema/file-diff"
import { FileStatus, Info, Mode } from "@opencode-ai/schema/vcs"
import { BranchList, FileStatus, Info, Mode } from "@opencode-ai/schema/vcs"
import { AppProcess } from "@opencode-ai/util/process"
import type { DiffOptions, Interface } from "../vcs.js"
import { chunksByFile, emptyPatch, MAX_PATCH_BYTES, MAX_TOTAL_PATCH_BYTES, PATCH_CONTEXT_LINES } from "./patch.js"
@@ -26,6 +26,9 @@ export function make(proc: AppProcess.Interface, input: { directory: string; wor
})
return { branch: { current, default: root?.name } } satisfies Info
}),
branches: Effect.fn("VcsGit.branches")(function* () {
return yield* ctx.git.branches(ctx.directory)
}),
status: Effect.fn("VcsGit.status")(function* () {
const git = ctx.git
const ref = (yield* git.hasHead(ctx.directory)) ? "HEAD" : undefined
@@ -176,6 +179,12 @@ function makeGit(proc: AppProcess.Interface) {
return result.text().trim() || undefined
})
const branches = Effect.fn("VcsGit.branches")(function* (cwd: string) {
return (yield* lines(["for-each-ref", "--format=%(refname:short)", "refs/heads", "refs/remotes"], { cwd }))
.filter((item) => !item.endsWith("/HEAD"))
.toSorted((a, b) => a.localeCompare(b)) satisfies BranchList
})
const defaultBranch = Effect.fn("VcsGit.defaultBranch")(function* (cwd: string) {
const remote = yield* primary(cwd)
if (remote) {
@@ -313,6 +322,7 @@ function makeGit(proc: AppProcess.Interface) {
return {
branch,
branches,
defaultBranch,
hasHead,
mergeBase,
+3
View File
@@ -76,6 +76,9 @@ export function make(
info: Effect.fn("VcsHg.info")(function* () {
return { branch: { current: yield* hg.branch(), default: "default" } } satisfies Info
}),
branches: Effect.fn("VcsHg.branches")(function* () {
return []
}),
status: Effect.fn("VcsHg.status")(function* () {
const [items, batch] = yield* Effect.all(
// Zero-context patches are enough to count changed lines.
+2
View File
@@ -94,6 +94,7 @@ export interface Strategy {
readonly create: (input: {
sourceDirectory: AbsolutePath
directory: AbsolutePath
branch?: string
}) => Effect.Effect<Info, Git.WorktreeError | DirectoryUnavailableError>
readonly remove: (input: {
directory: AbsolutePath
@@ -251,6 +252,7 @@ const layer = Layer.effect(
const result = yield* selected.create({
directory: worktreeDirectory,
sourceDirectory,
branch: input.branch,
})
yield* changed(
input.projectID,
+1 -1
View File
@@ -16,7 +16,7 @@ export const make = Effect.gen(function* () {
create: Effect.fn("Worktree.Git.create")(function* (input) {
const repository = yield* git.repo.discover(input.sourceDirectory)
if (!repository) return yield* new DirectoryUnavailableError({ directory: input.sourceDirectory })
yield* git.worktree.create({ repository, directory: input.directory })
yield* git.worktree.create({ repository, directory: input.directory, ref: input.branch })
return { directory: yield* canonical(fs, input.directory) }
}),
remove: Effect.fn("Worktree.Git.remove")(function* (input) {
+1 -1
View File
@@ -33,7 +33,7 @@ import { host } from "../plugin/host"
const shellLayer = Layer.succeed(
ShellSelect.Service,
ShellSelect.Service.of({
preferred: () => Effect.succeed("sh"),
resolve: () => Effect.succeed("sh"),
transform: () => Effect.die("unused shell.transform"),
reload: () => Effect.die("unused shell.reload"),
}),
+2
View File
@@ -604,6 +604,7 @@ describe("Config", () => {
provider: {
bedrock: {
npm: "@ai-sdk/amazon-bedrock",
models: { claude: { provider: { npm: "@ai-sdk/anthropic" } } },
options: {
headers: { "x-test": "1" },
body: { trace: true },
@@ -616,6 +617,7 @@ describe("Config", () => {
expect(migrated.providers?.bedrock).toMatchObject({
package: Provider.aisdk("@ai-sdk/amazon-bedrock"),
models: { claude: { package: Provider.aisdk("@ai-sdk/anthropic") } },
settings: { region: "us-east-1", profile: "dev" },
headers: { "x-test": "1" },
body: { trace: true },
+2 -2
View File
@@ -24,12 +24,12 @@ describe("ConfigShellPlugin.Plugin", () => {
yield* ConfigShellPlugin.Plugin.effect(yield* PluginHost.make(plugins))
const configured = process.platform === "win32" ? FSUtil.windowsPath(process.execPath) : process.execPath
expect(yield* shell.preferred()).toBe(configured)
expect(yield* shell.resolve({ priority: "config" })).toBe(configured)
yield* config.setEntries([])
yield* bus.publish(Event.Updated, {})
for (let attempt = 0; attempt < 200; attempt++) {
if ((yield* shell.preferred()) !== configured) return
if ((yield* shell.resolve({ priority: "config" })) !== configured) return
yield* Effect.sleep("10 millis")
}
yield* Effect.die(new Error("Timed out waiting for shell config reload"))
@@ -36,6 +36,18 @@ test("defensively syncs advertised Copilot models", async () => {
supports: { tool_calls: true, vision: true, reasoning_effort: ["low", "high"] },
},
},
{
model_picker_enabled: true,
id: "claude-sonnet",
name: "Claude Sonnet",
version: "claude-sonnet-2026-06-01",
supported_endpoints: ["/v1/messages"],
capabilities: {
family: "claude",
limits: { max_output_tokens: 16384, max_prompt_tokens: 180000 },
supports: { tool_calls: true },
},
},
{
model_picker_enabled: true,
id: "vision-only",
@@ -85,6 +97,7 @@ test("defensively syncs advertised Copilot models", async () => {
const model = models.get(Model.ID.make("gpt-5"))
expect(model?.name).toBe("GPT-5 local")
expect(model?.package).toBe(Provider.aisdk("@ai-sdk/github-copilot"))
expect(model?.settings).toMatchObject({ baseURL: server.url.origin, endpoint: "responses" })
expect(model?.cost[0]).toMatchObject({ input: 0, output: 0, cache: { read: 0, write: 0 } })
expect(model?.variants.map((variant) => variant.id)).toEqual([
@@ -92,6 +105,11 @@ test("defensively syncs advertised Copilot models", async () => {
Model.VariantID.make("high"),
])
expect(model?.capabilities.input).toEqual(["text", "image", "pdf"])
expect(models.get(Model.ID.make("claude-sonnet"))?.package).toBe(Provider.aisdk("@ai-sdk/anthropic"))
expect(models.get(Model.ID.make("claude-sonnet"))?.settings).toMatchObject({
baseURL: `${server.url.origin}/v1`,
endpoint: "messages",
})
expect(models.get(Model.ID.make("vision-only"))?.capabilities.input).toEqual(["text", "image"])
expect(models.get(Model.ID.make("utility"))?.enabled).toBe(false)
expect(models.has(Model.ID.make("stale"))).toBe(false)
+5 -1
View File
@@ -1080,7 +1080,11 @@ describe("ModelResolver", () => {
expect(openrouter.route.id).toBe("openrouter")
expect(openrouter.route.defaults.providerOptions).toEqual({ reasoning: { effort: "high" } })
expect(xai.route.id).toBe("openai-responses")
expect(xai.route.defaults.providerOptions).toEqual({ reasoningEffort: "high", store: false })
expect(xai.route.defaults.providerOptions).toEqual({
reasoningEffort: "high",
store: false,
include: ["reasoning.encrypted_content"],
})
expect(bedrock.route.id).toBe("bedrock-converse")
expect(bedrock.route.defaults.generation).toEqual({ topP: 0.8 })
expect(bedrock.route.defaults.http?.body).toEqual({ serviceTier: { type: "priority" } })
+25
View File
@@ -234,6 +234,31 @@ describe("ModelsDev Service", () => {
}),
)
it.live("normalizes provider and model AI SDK packages from models.dev", () =>
Effect.gen(function* () {
const cache = makeCache()
writeCache(cache, {
acme: {
...fixture.acme,
models: {
"acme-1": {
...fixture.acme.models["acme-1"],
provider: { npm: "@ai-sdk/openai" },
},
},
},
})
const state = yield* Ref.make(initialState)
const result = yield* provided(
state,
cache,
ModelsDev.Service.use((service) => service.get()),
)
expect(result[0]?.info.package).toBe(Provider.aisdk("@ai-sdk/openai-compatible"))
expect(result[0]?.models[0]?.package).toBe(Provider.aisdk("@ai-sdk/openai"))
}),
)
it.live("get() returns empty catalog when KV is empty, fetch disabled, and the bundled snapshot is disabled", () =>
Effect.gen(function* () {
const cache = makeCache()
@@ -6,6 +6,7 @@ import { describe, expect, test } from "bun:test"
import { Effect } from "effect"
import { Catalog } from "@opencode-ai/core/catalog"
import { Model } from "@opencode-ai/core/model"
import { ModelResolver } from "@opencode-ai/core/model-resolver"
import { Plugin } from "@opencode-ai/core/plugin"
import { PluginHost } from "@opencode-ai/core/plugin/host"
import { PluginHooks } from "@opencode-ai/core/plugin/hooks"
@@ -198,16 +199,23 @@ describe("GithubCopilotPlugin", () => {
it.effect("rewrites models.dev fallback models to the GitHub Copilot package", () =>
Effect.gen(function* () {
const catalog = yield* Catalog.Service
const aisdk = yield* AISDK.Service
yield* catalog.transform((catalog) => {
catalog.provider.update(Provider.ID.githubCopilot, () => {})
catalog.model.update(Provider.ID.githubCopilot, Model.ID.make("gpt-5.6-sol"), (model) => {
model.package = "@ai-sdk/openai-compatible"
model.package = Provider.aisdk("@ai-sdk/openai-compatible")
})
})
yield* addPlugin()
expect(required(yield* catalog.model.get(Provider.ID.githubCopilot, Model.ID.make("gpt-5.6-sol"))).package).toBe(
"@ai-sdk/github-copilot",
)
const fallback = required(yield* catalog.model.get(Provider.ID.githubCopilot, Model.ID.make("gpt-5.6-sol")))
expect(fallback.package).toBe(Provider.aisdk("@ai-sdk/github-copilot"))
const resolved = yield* ModelResolver.fromCatalogModel(fallback, undefined, {
loadPackage: () => Effect.die("Copilot must not load a native provider package"),
loadAISDK: (model) => aisdk.model(model),
})
expect(resolved.route.id).toBe("ai-sdk:@ai-sdk/github-copilot")
expect(resolved.route.providerMetadataKey).toBe("copilot")
}),
)
@@ -247,6 +247,10 @@ describe("OpencodePlugin", () => {
cost: { input: 1, output: 2, cache_read: 0.1 },
limit: { context: 1000, output: 100 },
},
override: {
name: "Override",
provider: { npm: "@ai-sdk/anthropic", api: `${origin}/anthropic` },
},
disabled: { name: "Disabled", status: "deprecated" },
},
},
@@ -308,6 +312,9 @@ describe("OpencodePlugin", () => {
settings: { baseURL: `${server.url.origin}/v1`, custom: "value", temperature: 0.5 },
headers: { "x-org-id": "org" },
})
const override = required(yield* catalog.model.get(Provider.ID.make("remote"), Model.ID.make("override")))
expect(override.package).toBe(Provider.aisdk("@ai-sdk/anthropic"))
expect(override.settings?.baseURL).toBe(`${server.url.origin}/anthropic`)
expect(model.variants).toEqual([
{
id: Model.VariantID.make("custom"),
@@ -11,6 +11,7 @@ import type { Info } from "@opencode-ai/schema/tool"
import { LayerNode } from "@opencode-ai/util/effect/layer-node"
import { executeTool, toolDefinitions } from "./lib/tool"
import { Cause, Deferred, Effect, Exit, Fiber, Layer, Schema, SchemaGetter, SchemaIssue, Scope } from "effect"
import { z } from "zod"
import { testEffect } from "./lib/effect"
const imageStore = Layer.mock(Image.Service, {
@@ -556,6 +557,39 @@ describe("Tool", () => {
}),
)
it.effect("registers, advertises, and executes a Zod tool", () =>
Effect.gen(function* () {
const service = yield* Tool.Service
yield* transform(
service,
{
zod: {
name: "zod",
description: "Increment a parsed number",
input: z.object({ count: z.string().transform(Number) }),
output: z.object({ count: z.number() }),
execute: ({ count }) => Effect.succeed({ output: { count: count + 1 } }),
},
},
{ codemode: false },
)
const snapshot = yield* service.snapshot()
expect(snapshot.definitions.find((tool) => tool.name === "zod")?.inputSchema).toMatchObject({
type: "object",
properties: { count: { type: "string" } },
required: ["count"],
})
expect(
yield* snapshot.execute({
sessionID,
...identity,
call: { type: "tool-call", id: "call-zod", name: "zod", input: { count: "41" } },
}),
).toMatchObject({ output: { count: 42 } })
}),
)
it.effect("executes the tool advertised in a model request", () =>
Effect.gen(function* () {
const service = yield* Tool.Service
+18 -20
View File
@@ -8,15 +8,13 @@ const withShell = async (shell: string | undefined, fn: () => void | Promise<voi
const prev = process.env.SHELL
if (shell === undefined) delete process.env.SHELL
else process.env.SHELL = shell
ShellSelect.acceptable.reset()
ShellSelect.preferred.reset()
ShellSelect.resolve.reset()
try {
await fn()
} finally {
if (prev === undefined) delete process.env.SHELL
else process.env.SHELL = prev
ShellSelect.acceptable.reset()
ShellSelect.preferred.reset()
ShellSelect.resolve.reset()
}
}
@@ -36,16 +34,16 @@ describe("shell", () => {
test("falls back when configured shell cannot be resolved", async () => {
await withShell(undefined, async () => {
const preferred = ShellSelect.preferred()
const acceptable = ShellSelect.acceptable()
expect(ShellSelect.preferred("opencode-missing-shell")).toBe(preferred)
expect(ShellSelect.acceptable("opencode-missing-shell")).toBe(acceptable)
const configured = ShellSelect.resolve({ priority: "config" })
const compatible = ShellSelect.resolve({ priority: "compat" })
expect(ShellSelect.resolve({ priority: "config" }, "opencode-missing-shell")).toBe(configured)
expect(ShellSelect.resolve({ priority: "compat" }, "opencode-missing-shell")).toBe(compatible)
})
})
test("falls back for terminal-only acceptable shells", () => {
expect(ShellSelect.name(ShellSelect.acceptable("fish"))).not.toBe("fish")
expect(ShellSelect.name(ShellSelect.acceptable("nu"))).not.toBe("nu")
test("falls back for terminal-only shells when compatibility is required", () => {
expect(ShellSelect.name(ShellSelect.resolve({ priority: "compat" }, "fish"))).not.toBe("fish")
expect(ShellSelect.name(ShellSelect.resolve({ priority: "compat" }, "nu"))).not.toBe("nu")
})
test("builds command args per shell family", () => {
@@ -65,14 +63,14 @@ describe("shell", () => {
if (process.platform === "win32") {
test("rejects blacklisted shells case-insensitively", async () => {
await withShell("NU.EXE", async () => {
expect(ShellSelect.name(ShellSelect.acceptable())).not.toBe("nu")
expect(ShellSelect.name(ShellSelect.resolve({ priority: "compat" }))).not.toBe("nu")
})
})
test("normalizes Git Bash shell paths from env", async () => {
const shell = "/cygdrive/c/Program Files/Git/bin/bash.exe"
await withShell(shell, async () => {
expect(ShellSelect.preferred()).toBe(FSUtil.windowsPath(shell))
expect(ShellSelect.resolve({ priority: "config" })).toBe(FSUtil.windowsPath(shell))
})
})
@@ -80,19 +78,19 @@ describe("shell", () => {
const bash = ShellSelect.gitbash()
if (!bash) return
await withShell("/usr/bin/bash", async () => {
expect(ShellSelect.acceptable()).toBe(bash)
expect(ShellSelect.preferred()).toBe(bash)
expect(ShellSelect.resolve({ priority: "compat" })).toBe(bash)
expect(ShellSelect.resolve({ priority: "config" })).toBe(bash)
})
})
test("resolves bare bash to Git Bash before PATH", async () => {
const bash = ShellSelect.gitbash()
if (!bash) return
expect(ShellSelect.acceptable("bash")).toBe(bash)
expect(ShellSelect.preferred("bash")).toBe(bash)
expect(ShellSelect.resolve({ priority: "compat" }, "bash")).toBe(bash)
expect(ShellSelect.resolve({ priority: "config" }, "bash")).toBe(bash)
await withShell("bash", async () => {
expect(ShellSelect.acceptable()).toBe(bash)
expect(ShellSelect.preferred()).toBe(bash)
expect(ShellSelect.resolve({ priority: "compat" })).toBe(bash)
expect(ShellSelect.resolve({ priority: "config" })).toBe(bash)
})
})
@@ -100,7 +98,7 @@ describe("shell", () => {
const shell = which("pwsh") || which("powershell")
if (!shell) return
await withShell(path.win32.basename(shell), async () => {
expect(ShellSelect.preferred()).toBe(shell)
expect(ShellSelect.resolve({ priority: "config" })).toBe(shell)
})
})
}
+38
View File
@@ -1,5 +1,6 @@
import { expect, test } from "bun:test"
import { Effect, Schema } from "effect"
import { z } from "zod"
import type { Info } from "@opencode-ai/schema/tool"
import { Tool } from "../src/tool"
import { definition, execute } from "../src/tool/runtime"
@@ -139,6 +140,43 @@ test("portable schemas validate and describe typed tools", async () => {
expect(result.output).toBe("42")
})
test("Zod schemas validate, transform, and describe typed tools", async () => {
const tool: Info = {
name: "zod",
description: "Zod tool",
input: z.object({ count: z.string().transform(Number) }),
output: z.object({ count: z.number() }),
execute: ({ count }) => Effect.succeed({ output: { count: count + 1 } }),
}
expect(definition(tool)).toEqual({
name: "zod",
description: "Zod tool",
inputSchema: {
$schema: "https://json-schema.org/draft/2020-12/schema",
type: "object",
properties: { count: { type: "string" } },
required: ["count"],
},
outputSchema: {
$schema: "https://json-schema.org/draft/2020-12/schema",
type: "object",
properties: { count: { type: "number" } },
required: ["count"],
additionalProperties: false,
},
})
expect(await Effect.runPromise(execute(tool, { count: "41" }, {} as Tool.Context))).toMatchObject({
output: { count: 42 },
})
expect(await Effect.runPromise(Effect.flip(execute(tool, { count: 41 }, {} as Tool.Context)))).toEqual(
new Tool.Error({
message:
'Invalid arguments for tool "zod":\n- count: Invalid input: expected string, received number\n\nArguments provided:\n{\n "count": 41\n}\n\nUpdate the arguments and call the tool again.',
}),
)
})
test("portable schema failures become tool failures", async () => {
const input = {
"~standard": {
+2
View File
@@ -32,6 +32,7 @@ import { Permission } from "@opencode-ai/core/permission"
import { PluginRuntime } from "@opencode-ai/core/plugin/runtime"
import { PluginSupervisor } from "@opencode-ai/core/plugin/supervisor"
import { Shell } from "@opencode-ai/core/shell"
import { ShellSelect } from "@opencode-ai/core/shell/select"
import { Shell as ShellSchema } from "@opencode-ai/schema/shell"
import { ShellTool } from "@opencode-ai/core/tool/plugin/shell"
import { ToolOutput } from "@opencode-ai/core/tool-output"
@@ -136,6 +137,7 @@ const shellPluginSupervisor = makeLocationNode({
Permission.node,
PluginRuntime.node,
Shell.node,
ShellSelect.node,
Tool.node,
],
})
+15
View File
@@ -64,6 +64,7 @@ describe("Vcs", () => {
Effect.gen(function* () {
const vcs = yield* Vcs.Service
expect(yield* vcs.info()).toEqual({ branch: {} })
expect(yield* vcs.branches()).toEqual([])
expect(yield* vcs.status()).toEqual([])
expect(yield* vcs.diff("working")).toEqual([])
expect(yield* vcs.diff("branch")).toEqual([])
@@ -71,6 +72,20 @@ describe("Vcs", () => {
),
)
it.live("lists local branches", () =>
withGit((directory) =>
Effect.gen(function* () {
yield* Effect.promise(async () => {
await fs.writeFile(path.join(directory, "file.txt"), "one\n")
await commitAll(directory, "initial")
await $`git branch feature`.cwd(directory).quiet()
})
const vcs = yield* Vcs.Service
expect(yield* vcs.branches()).toEqual(["feature", "main"])
}),
),
)
it.live("reports modified, deleted, and untracked files", () =>
withGit((directory) =>
Effect.gen(function* () {
+52
View File
@@ -192,6 +192,58 @@ describe("Worktree", () => {
}),
)
it.live("creates a git worktree from a selected branch", () =>
Effect.gen(function* () {
const input = yield* setup()
const worktree = yield* Worktree.Service
const parent = abs(`${input.root.path}-branch-worktree`)
yield* Effect.addFinalizer(() =>
Effect.promise(() => fs.rm(parent, { recursive: true, force: true })).pipe(Effect.ignore),
)
yield* Effect.promise(async () => {
await $`git branch feature-base`.cwd(input.sourceDirectory).quiet()
})
const created = yield* worktree.create({
projectID: input.projectID,
strategy: gitWorktree,
branch: "feature-base",
directory: parent,
name: "worktree",
})
const head = (yield* Effect.promise(() => $`git rev-parse HEAD`.cwd(created.directory).quiet().text())).trim()
const branch = (yield* Effect.promise(() =>
$`git rev-parse feature-base`.cwd(input.sourceDirectory).quiet().text(),
)).trim()
expect(head).toBe(branch)
}),
)
it.live("does not interpret a branch as a git option", () =>
Effect.gen(function* () {
const input = yield* setup()
const worktree = yield* Worktree.Service
const parent = abs(`${input.root.path}-option-worktree`)
yield* Effect.addFinalizer(() =>
Effect.promise(() => fs.rm(parent, { recursive: true, force: true })).pipe(Effect.ignore),
)
const error = yield* worktree
.create({
projectID: input.projectID,
strategy: gitWorktree,
branch: "--no-checkout",
directory: parent,
name: "worktree",
})
.pipe(Effect.flip)
expect(error).toBeInstanceOf(Git.WorktreeError)
expect(yield* Effect.promise(() => Bun.file(path.join(parent, "worktree")).exists())).toBe(false)
}),
)
it.live("rejects a missing source directory", () =>
Effect.gen(function* () {
const input = yield* setup()
+3 -64
View File
@@ -2,7 +2,9 @@ const resizeLoopWarning = "ResizeObserver loop completed with undelivered notifi
if (import.meta.env.DEV) {
installConsoleStacks()
installResizeObserverStacks()
window.addEventListener("error", (event) => {
if (event.message === resizeLoopWarning) event.preventDefault()
})
}
function installConsoleStacks() {
@@ -10,60 +12,6 @@ function installConsoleStacks() {
console.error = tracedConsole(console.error.bind(console), "Console error")
}
function installResizeObserverStacks() {
if (typeof ResizeObserver !== "function") return
const NativeResizeObserver = ResizeObserver
type ResizeTrace = {
created: string
last?: { at: number; targets: Element[] }
}
const observers = new Set<ResizeTrace>()
class TracedResizeObserver extends NativeResizeObserver {
private readonly trace: ResizeTrace
constructor(callback: ResizeObserverCallback) {
const trace: ResizeTrace = {
created: diagnosticStack("ResizeObserver created"),
}
super((entries, observer) => {
trace.last = { at: performance.now(), targets: entries.map((entry) => entry.target) }
callback(entries, observer)
})
this.trace = trace
observers.add(trace)
}
override disconnect() {
observers.delete(this.trace)
super.disconnect()
}
}
globalThis.ResizeObserver = TracedResizeObserver
window.addEventListener("error", (event) => {
if (event.message !== resizeLoopWarning) return
const now = performance.now()
const active = [...observers]
.flatMap((observer) => {
if (!observer.last || now - observer.last.at >= 100) return []
return [{ ...observer, last: observer.last }]
})
.sort((a, b) => b.last.at - a.last.at)
.slice(0, 5)
const detail = active.length
? active
.map(
(observer, index) =>
`Recent ResizeObserver ${index + 1}; targets: ${observer.last.targets.map(describeElement).join(", ") || "none"}\n${observer.created}`,
)
.join("\n")
: "No ResizeObserver callback was recorded in the previous 100 ms."
console.warn(`[renderer diagnostics] ${resizeLoopWarning}\n${detail}`)
})
}
function tracedConsole(write: (...args: unknown[]) => void, label: string) {
const pending = new Map<string, { count: number }>()
return (...args: unknown[]) => {
@@ -85,15 +33,6 @@ function tracedConsole(write: (...args: unknown[]) => void, label: string) {
}
}
function describeElement(element: Element) {
const id = element.id ? `#${element.id}` : ""
const classes = [...element.classList]
.slice(0, 3)
.map((name) => `.${name}`)
.join("")
return `${element.tagName.toLowerCase()}${id}${classes}`
}
function diagnosticStack(label: string) {
return new Error(label).stack ?? label
}
+14
View File
@@ -41,6 +41,20 @@ export const VcsGroup = HttpApiGroup.make("server.vcs")
}),
),
)
.add(
HttpApiEndpoint.get("vcs.branches", "/api/vcs/branches", {
query: LocationQuery,
success: Location.response(Vcs.BranchList),
})
.annotateMerge(locationQueryOpenApi)
.annotateMerge(
OpenApi.annotations({
identifier: "v2.vcs.branches",
summary: "VCS branches",
description: "List local and remote branches available at the requested location.",
}),
),
)
.add(
HttpApiEndpoint.get("vcs.diff", "/api/vcs/diff", {
query: DiffQuery,
+2 -5
View File
@@ -1,7 +1,7 @@
export * as Tool from "./tool.js"
import { Effect, JsonSchema, Schema } from "effect"
import type { StandardJSONSchemaV1, StandardSchemaV1 } from "@standard-schema/spec"
import type { StandardSchemaV1 } from "@standard-schema/spec"
import type { Agent } from "./agent.js"
import type { Session } from "./session.js"
import type { SessionMessage } from "./session-message.js"
@@ -36,10 +36,7 @@ export type Options = BaseOptions &
}
)
export type ValueSchema<A = unknown> =
| Schema.Codec<A, any>
| (StandardSchemaV1<any, A> & StandardJSONSchemaV1<any, A>)
| JsonSchema.JsonSchema
export type ValueSchema<A = unknown> = Schema.Codec<A, any> | StandardSchemaV1<any, A> | JsonSchema.JsonSchema
type InputValue<S> = 0 extends 1 & S
? any
+3
View File
@@ -14,6 +14,9 @@ export const Info = Schema.Struct({
}).annotate({ identifier: "Vcs.Info" })
export interface Info extends Schema.Schema.Type<typeof Info> {}
export const BranchList = Schema.Array(Schema.String).annotate({ identifier: "Vcs.BranchList" })
export type BranchList = typeof BranchList.Type
export const Mode = Schema.Literals(["working", "branch"]).annotate({ identifier: "Vcs.Mode" })
export type Mode = typeof Mode.Type
+1
View File
@@ -13,6 +13,7 @@ export const CreateInput = Schema.Struct({
projectID: ProjectID,
strategy: StrategyID,
from: optional(AbsolutePath),
branch: optional(Schema.Trim.pipe(Schema.check(Schema.isNonEmpty()))),
directory: AbsolutePath,
name: optional(Schema.String),
}).annotate({ identifier: "Worktree.CreateInput" })
+8
View File
@@ -23,6 +23,14 @@ export const VcsHandler = HttpApiBuilder.group(Api, "server.vcs", (handlers) =>
}),
),
)
.handle("vcs.branches", () =>
response(
Effect.gen(function* () {
const vcs = yield* Vcs.Service
return yield* vcs.branches()
}),
),
)
.handle("vcs.diff", (ctx) =>
response(
Effect.gen(function* () {
+1
View File
@@ -96,6 +96,7 @@ const vcsLayer = Layer.succeed(
Vcs.Service,
Vcs.Service.of({
info: () => Effect.succeed({ branch: {} }),
branches: () => Effect.succeed([]),
status: () => Effect.succeed([]),
diff: () => Effect.succeed([]),
}),
@@ -24,6 +24,17 @@ const patch = (key: string, partIDs: string[], userMessageID = "user-1") =>
previousAssistantPart: false,
})
const part = (key: string, partID: string) =>
new TimelineRow.AssistantPart({
userMessageID: "user-1",
group: {
key,
type: "part",
ref: { messageID: "assistant-1", partID },
} satisfies PartGroup,
previousAssistantPart: false,
})
const user = (userMessageID = "user-1") => new TimelineRow.UserMessage({ userMessageID })
const keys = (rows: TimelineRow.TimelineRow[]) => rows.map(TimelineRow.key)
@@ -33,49 +44,63 @@ describe("reuseTimelineRows", () => {
name: "reuses an unchanged context group",
previous: [context("context:a", ["a", "b"])],
rows: [context("context:a", ["a", "b"])],
expected: ["assistant-part:context:a"],
expected: ["assistant-part:context:context:a"],
reused: [[0, 0]],
},
{
name: "preserves the group key when a member is appended",
previous: [context("context:a", ["a"])],
rows: [context("context:a", ["a", "b"])],
expected: ["assistant-part:context:a"],
expected: ["assistant-part:context:context:a"],
reused: [],
},
{
name: "preserves a patch group key when a member is appended",
previous: [patch("patch:a", ["a"])],
rows: [patch("patch:a", ["a", "b"])],
expected: ["assistant-part:patch:a"],
expected: ["assistant-part:file:patch:a"],
reused: [],
},
{
name: "preserves the group key when the first member is removed",
previous: [context("context:a", ["a", "b"])],
rows: [context("context:b", ["b"])],
expected: ["assistant-part:context:a"],
expected: ["assistant-part:context:context:a"],
reused: [],
},
{
name: "lets only the natural owner retain an old key after a split",
previous: [context("context:a", ["a", "b"])],
rows: [context("context:a", ["a"]), context("context:b", ["b"])],
expected: ["assistant-part:context:a", "assistant-part:context:b"],
expected: ["assistant-part:context:context:a", "assistant-part:context:context:b"],
reused: [],
},
{
name: "preserves the file group identity when its first member becomes standalone",
previous: [patch("part:a", ["a", "b"])],
rows: [part("part:a", "a"), patch("part:b", ["b"])],
expected: ["assistant-part:part:part:a", "assistant-part:file:part:a"],
reused: [],
},
{
name: "preserves the file group identity before a later standalone member",
previous: [patch("part:a", ["a", "b"])],
rows: [patch("part:b", ["b"]), part("part:a", "a")],
expected: ["assistant-part:file:part:a", "assistant-part:part:part:a"],
reused: [],
},
{
name: "chooses the earliest prior key when groups merge",
previous: [context("context:a", ["a"]), context("context:b", ["b"])],
rows: [context("context:b", ["b", "a"])],
expected: ["assistant-part:context:a"],
expected: ["assistant-part:context:context:a"],
reused: [],
},
{
name: "reserves an old key for its natural owner when two new groups compete",
previous: [context("context:a", ["a", "b"])],
rows: [context("context:b", ["b"]), context("context:a", ["a"])],
expected: ["assistant-part:context:b", "assistant-part:context:a"],
expected: ["assistant-part:context:context:b", "assistant-part:context:context:a"],
reused: [],
},
{
@@ -84,14 +109,14 @@ describe("reuseTimelineRows", () => {
name: "reuses context identity when the same parts move to another user message",
previous: [context("context:a", ["a", "b"], { userMessageID: "user-1" })],
rows: [context("context:b", ["b"], { userMessageID: "user-2" })],
expected: ["assistant-part:context:a"],
expected: ["assistant-part:context:context:a"],
reused: [],
},
{
name: "does not reuse context identity across assistant messages",
previous: [context("context:assistant-1:a", ["a"], { messageID: "assistant-1" })],
rows: [context("context:assistant-2:a", ["a"], { messageID: "assistant-2" })],
expected: ["assistant-part:context:assistant-2:a"],
expected: ["assistant-part:context:context:assistant-2:a"],
reused: [],
},
{
@@ -105,7 +130,7 @@ describe("reuseTimelineRows", () => {
name: "does not create accidental key collisions",
previous: [context("context:a", ["a", "b", "c"])],
rows: [context("context:b", ["b"]), context("context:a", ["a"]), context("context:c", ["c"])],
expected: ["assistant-part:context:b", "assistant-part:context:a", "assistant-part:context:c"],
expected: ["assistant-part:context:context:b", "assistant-part:context:context:a", "assistant-part:context:context:c"],
reused: [],
},
])("$name", ({ previous, rows, expected, reused }) => {
@@ -29,10 +29,10 @@ describe("current session timeline rows", () => {
expect(result.activeMessageID).toBe("msg_3")
expect(result.rows.map(TimelineRow.key)).toEqual([
"user-message:msg_1",
"assistant-part:part:msg_2:msg_2:text:0",
"assistant-part:part:part:msg_2:msg_2:text:0",
"turn-gap:msg_3",
"user-message:msg_3",
"assistant-part:part:msg_4:msg_4:reasoning:0",
"assistant-part:part:part:msg_4:msg_4:reasoning:0",
])
})
@@ -79,7 +79,7 @@ describe("current session timeline rows", () => {
expect(result.activeMessageID).toBe("msg_assistant")
expect(result.rows.map(TimelineRow.key)).toEqual([
"notice:msg_notice",
"assistant-part:part:msg_assistant:msg_assistant:text:0",
"assistant-part:part:part:msg_assistant:msg_assistant:text:0",
])
})
@@ -140,10 +140,10 @@ describe("current session timeline rows", () => {
expect(result.rows.map(TimelineRow.key)).toEqual([
"user-message:msg_user",
"notice:msg_agent",
"assistant-part:part:msg_assistant_1:msg_assistant_1:text:0",
"assistant-part:part:part:msg_assistant_1:msg_assistant_1:text:0",
"notice:msg_background",
"notice:msg_model",
"assistant-part:part:msg_assistant_2:msg_assistant_2:text:0",
"assistant-part:part:part:msg_assistant_2:msg_assistant_2:text:0",
"notice:msg_restart",
"notice:msg_skill",
"notice:msg_compaction",
@@ -518,9 +518,9 @@ describe("current session timeline rows", () => {
expect(keys).toEqual([
"user-message:msg_user",
"assistant-part:context:msg_assistant_1:tool_0",
"assistant-part:part:msg_assistant_2:tool_0",
"assistant-part:context:msg_assistant_3:tool_0",
"assistant-part:context:context:msg_assistant_1:tool_0",
"assistant-part:part:part:msg_assistant_2:tool_0",
"assistant-part:context:context:msg_assistant_3:tool_0",
])
})
@@ -92,7 +92,7 @@ export namespace TimelineRow {
// and its rows regroup under the real user message once older history loads.
// The group key already carries the owning message and part IDs.
case "AssistantPart":
return `assistant-part:${row.group.key}`
return `assistant-part:${row.group.type}:${row.group.key}`
case "Thinking":
return `thinking:${row.userMessageID}`
case "Error":
+2
View File
@@ -716,6 +716,7 @@ function App(props: { pair?: DialogPairCredentials }) {
category: "Session",
slash: { name: "new", aliases: ["clear"] },
run: () => {
const model = local.model.current()
const current =
route.data.type === "session"
? (data.session.get(route.data.sessionID)?.location ?? location.ref)
@@ -729,6 +730,7 @@ function App(props: { pair?: DialogPairCredentials }) {
location.error?.location,
),
})
if (model) local.model.set(model)
dialog.clear()
},
},
+67
View File
@@ -296,6 +296,73 @@ test("session startup prompt is submitted exactly once", async () => {
}
})
test("new session inherits the active session model", async () => {
const setup = await createTestRenderer({ width: 80, height: 24, useThread: false, kittyKeyboard: true })
setup.renderer.start()
const events = createEventStream()
const cwd = process.cwd()
const location = { directory: cwd, project: { id: "project", directory: cwd } }
const session = {
id: "dummy",
title: "Demo session",
projectID: "project",
location: { directory: cwd },
agent: "build",
model: { providerID: "provider", id: "session-model" },
cost: 0,
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
time: { created: 0, updated: 0 },
}
const calls = createFetch((url) => {
if (url.pathname === "/api/location") return json(location)
if (url.pathname === "/api/session") return json({ data: [session], cursor: {} })
if (url.pathname === "/api/session/dummy") return json({ data: session })
if (url.pathname === "/api/session/dummy/message") return json({ data: [], cursor: {} })
if (url.pathname === "/api/session/dummy/inbox") return json({ data: [] })
if (url.pathname === "/api/session/dummy/permission") return json({ data: [] })
if (url.pathname === "/api/agent")
return json({ location, data: [{ id: "build", mode: "primary", hidden: false, permissions: [] }] })
if (url.pathname === "/api/provider") return json({ location, data: [{ id: "provider", name: "Provider" }] })
if (url.pathname === "/api/model")
return json({
location,
data: [
{ id: "home-model", providerID: "provider", name: "Home Model", variants: [] },
{ id: "session-model", providerID: "provider", name: "Session Model", variants: [] },
],
})
}, events)
const server = Bun.serve({ port: 0, fetch: (request) => calls.fetch(request) })
try {
const { run } = await import("../src/app")
const task = Effect.runPromise(
run({
app: { name: "test", version: "test", channel: "test" },
server: { endpoint: { url: server.url.toString() } },
config: { get: async () => ({ animations: false }), update: async () => ({}) },
packages: { resolve: async () => undefined },
terminalHandoff: async () => ({ renderer: setup.renderer, mode: "dark", complete: () => {} }),
args: { sessionID: "dummy" },
log: () => {},
}).pipe(Effect.provide(AppNodeBuilder.build(Global.node)), Effect.provide(FileSystem.layerNoop({}))),
)
await setup.waitForFrame((frame) => frame.includes("Session Model"))
await setup.mockInput.typeText("/new")
setup.mockInput.pressEnter()
await Bun.sleep(50)
await setup.renderOnce()
const frame = setup.captureCharFrame()
expect(frame).toContain("Session Model")
setup.renderer.destroy()
await task
} finally {
if (!setup.renderer.isDestroyed) setup.renderer.destroy()
await server.stop()
}
})
test("keeps the prompt display stable while a new location catalog loads", async () => {
const setup = await createTestRenderer({ width: 100, height: 30, useThread: false, kittyKeyboard: true })
setup.renderer.start()
+7 -5
View File
@@ -1,5 +1,7 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M18 18H6V6H18V18Z" fill="#F5F5F5"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M3 3H21V21H3V3ZM8 8V16H16V8H8Z" fill="#3B7DD8"/>
<path d="M16 8H20V12H16V8Z" fill="#FAB283"/>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" width="512" height="512"><svg width="512" height="512" viewBox="0 0 512 512" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect width="512" height="512" fill="#131010"></rect>
<path d="M320 224V352H192V224H320Z" fill="#5A5858"></path>
<path fill-rule="evenodd" clip-rule="evenodd" d="M384 416H128V96H384V416ZM320 160H192V352H320V160Z" fill="white"></path>
</svg><style>@media (prefers-color-scheme: light) { :root { filter: none; } }
@media (prefers-color-scheme: dark) { :root { filter: none; } }
</style></svg>

Before

Width:  |  Height:  |  Size: 297 B

After

Width:  |  Height:  |  Size: 613 B

+4 -1
View File
@@ -1,5 +1,8 @@
import { cp } from "node:fs/promises"
import config from "../astro.config"
const base = config.base?.replace(/\/$/, "") ?? ""
const docs = `dist/client${base}/docs`
await Bun.$`pagefind --site ${`dist/client${base}/docs`}`
await cp(`dist/client${base}/docs-index`, docs, { recursive: true })
await Bun.$`pagefind --site ${docs}`
+15 -4
View File
@@ -1,10 +1,21 @@
export {}
import { rm } from "node:fs/promises"
import path from "node:path"
import astro from "../astro.config"
const path = "dist/server/wrangler.json"
const config = await Bun.file(path).json()
const base = astro.base?.replace(/\/$/, "") ?? ""
const snapshots = `dist/client${base}/docs-index`
await Promise.all(
(await Array.fromAsync(new Bun.Glob("**/*.html").scan({ cwd: snapshots }))).map((file) =>
rm(path.join(`dist/client${base}/docs`, file)),
),
)
await rm(snapshots, { recursive: true })
const config = await Bun.file("dist/server/wrangler.json").json()
delete config.kv_namespaces
delete config.images
delete config.previews
await Bun.write(path, JSON.stringify(config))
await Bun.write("dist/server/wrangler.json", JSON.stringify(config))
@@ -0,0 +1,25 @@
---
import { render, type CollectionEntry } from "astro:content"
import Callout from "./Callout.astro"
import Card from "./Card.astro"
import CardGroup from "./CardGroup.astro"
import CodeBlock from "./CodeBlock.astro"
import DocsLayout from "../layouts/DocsLayout.astro"
interface Props {
entry: CollectionEntry<"docs">
}
const entry = Astro.props.entry
const rendered = await render(entry)
---
<DocsLayout
title={entry.data.title}
description={entry.data.description}
currentSlug={entry.id}
headings={rendered.headings}
showTableOfContents={entry.data.tableOfContents !== false}
>
<rendered.Content components={{ Callout, Card, CardGroup, CodeBlock }} />
</DocsLayout>
+28 -1
View File
@@ -54,7 +54,18 @@ const canonical = new URL(Astro.url.pathname, "https://opencode.ai").href
</aside>
<main id="docs-content">
<article class="prose" data-pagefind-body data-pagefind-meta={`title:${Astro.props.title}`}>
<h1>{Astro.props.title}</h1>
<h1>
{Astro.props.title}
<button type="button" aria-label="Copy page as Markdown" data-copy-markdown data-pagefind-ignore>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true">
<rect x="8" y="8" width="13" height="13" rx="2" />
<path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" />
</svg>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true">
<path d="m5 12 4 4L19 6" />
</svg>
</button>
</h1>
<slot />
</article>
</main>
@@ -81,5 +92,21 @@ const canonical = new URL(Astro.url.pathname, "https://opencode.ai").href
addHeadingAnchors()
document.addEventListener("astro:page-load", addHeadingAnchors)
</script>
<script>
document.addEventListener("click", async (event) => {
if (!(event.target instanceof Element)) return
const button = event.target.closest<HTMLButtonElement>("[data-copy-markdown]")
if (!button) return
button.dataset.copied = "true"
button.setAttribute("aria-label", "Copied")
window.setTimeout(() => {
delete button.dataset.copied
button.setAttribute("aria-label", "Copy page as Markdown")
}, 1500)
const response = await fetch(window.location.href, { headers: { Accept: "text/markdown" } })
if (!response.ok) return
await navigator.clipboard.writeText(await response.text())
})
</script>
</body>
</html>
+29 -2
View File
@@ -158,8 +158,7 @@ a:hover {
color: var(--foreground);
}
.site-header nav a[aria-current="page"] {
border-bottom: 1px solid;
.site-header a:hover {
text-decoration: none;
}
@@ -788,7 +787,11 @@ main {
}
.prose h1 {
display: flex;
margin: 0 0 3rem;
align-items: center;
justify-content: space-between;
gap: 1rem;
font-size: 1.875rem;
line-height: 1.2;
}
@@ -993,6 +996,30 @@ main {
font-size: 0.75rem;
}
.prose h1 button {
display: inline-flex;
padding: 0;
flex-shrink: 0;
cursor: pointer;
border: 0;
background: transparent;
color: var(--muted);
}
.prose h1 button:hover,
.prose h1 button[data-copied] {
color: var(--foreground);
}
.prose h1 button svg:last-child,
.prose h1 button[data-copied] svg:first-child {
display: none;
}
.prose h1 button[data-copied] svg:last-child {
display: block;
}
.search-dialog {
width: min(42rem, calc(100% - 2rem));
max-height: min(36rem, calc(100vh - 4rem));
@@ -0,0 +1,21 @@
---
import { getCollection, type CollectionEntry } from "astro:content"
import DocsPage from "../../docs/components/DocsPage.astro"
interface Props {
entry: CollectionEntry<"docs">
}
export async function getStaticPaths() {
return (await getCollection("docs")).map((entry) => ({
params: {
slug: entry.id === "index" ? undefined : entry.id.replace(/\/index$/, ""),
},
props: { entry },
}))
}
export const prerender = true
---
<DocsPage entry={Astro.props.entry} />
+18 -28
View File
@@ -1,36 +1,26 @@
---
import { getCollection, render, type CollectionEntry } from "astro:content"
import Callout from "../../docs/components/Callout.astro"
import Card from "../../docs/components/Card.astro"
import CardGroup from "../../docs/components/CardGroup.astro"
import CodeBlock from "../../docs/components/CodeBlock.astro"
import DocsLayout from "../../docs/layouts/DocsLayout.astro"
import { getEntry } from "astro:content"
import DocsPage from "../../docs/components/DocsPage.astro"
interface Props {
entry: CollectionEntry<"docs">
export const prerender = false
const slug = Astro.params.slug || "index"
const entry = (await getEntry("docs", slug)) ?? (await getEntry("docs", `${slug}/index`))
if (!entry) return new Response("Not found", { status: 404, headers: { "Cache-Control": "no-store" } })
const headers = {
"Cache-Control": "public, max-age=300, stale-while-revalidate=3600",
Vary: "Accept",
}
export async function getStaticPaths() {
return (await getCollection("docs")).map((entry) => ({
params: {
slug: entry.id === "index" ? undefined : entry.id.replace(/\/index$/, ""),
},
props: { entry },
}))
const accept = Astro.request.headers.get("accept") ?? ""
if (accept.includes("text/markdown") || accept.includes("text/x-markdown")) {
return new Response(`# ${entry.data.title}\n\n${entry.body ?? ""}`, {
headers: { ...headers, "Content-Type": "text/markdown; charset=utf-8" },
})
}
export const prerender = true
const entry = Astro.props.entry
const rendered = await render(entry)
Object.entries(headers).forEach(([name, value]) => Astro.response.headers.set(name, value))
---
<DocsLayout
title={entry.data.title}
description={entry.data.description}
currentSlug={entry.id}
headings={rendered.headings}
showTableOfContents={entry.data.tableOfContents !== false}
>
<rendered.Content components={{ Callout, Card, CardGroup, CodeBlock }} />
</DocsLayout>
<DocsPage entry={entry} />

Some files were not shown because too many files have changed in this diff Show More