Skip to content

Commit 9715924

Browse files
e6qukitlangtonrekram1-nodeghost91-altendky
authored
fix: backport 9 upstream bug fixes (B1-B9) (#16)
* fix(vcs): fix inverted HEAD filter in watcher (backport B8 #17829) The file watcher was ignoring HEAD changes instead of filtering non-HEAD changes, so branch switches were never detected. Upstream: anomalyco/opencode#17829 (e5cbecf) Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> * fix(core): detect context_length_exceeded in API call errors (backport B1 #17748) Parse response body for error code so providers returning context_length_exceeded are correctly classified as context overflow. Upstream: anomalyco/opencode#17748 (e718db6) * fix(util): log ZodError issues on schema validation failure (backport B5) Print the specific validation issues alongside the stack trace to make debugging schema mismatches easier. * fix(tui): check for selected text in dialog escape handler (backport B7 #16779) Check getSelectedText() instead of just getSelection() so escape correctly closes dialogs when a selection object exists but has no text. Upstream: anomalyco/opencode#16779 (a64f604) * fix(ui): wrap question option descriptions instead of truncating (backport B6 #17782) Replace overflow:hidden/text-overflow:ellipsis with overflow-wrap:anywhere so long descriptions are visible. Remove the now-redundant data-custom override. Upstream: anomalyco/opencode#17782 (51fcd04) * fix(opencode): apply message transforms during compaction (backport B2 #17823) Run Plugin.trigger("experimental.chat.messages.transform") on a structuredClone of messages before passing them to the compaction model. Upstream: anomalyco/opencode#17823 (4cb2996) * fix(opencode): forward session permission ruleset to LLM stream (backport B3 #17064) Add permission field to StreamInput and merge it with agent permissions when computing disabled tools. Forward session.permission from prompt.ts. Upstream: anomalyco/opencode#17064 (c2ca149) * fix(opencode): add prompt schema validation debug logs (backport B4 #17812) Log info and part schema validation failures before persisting to help diagnose data corruption issues. Upstream: anomalyco/opencode#17812 (fee3c19) --------- Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: Johannes Loher <johannes.loher@tngtech.com> Co-authored-by: Adrian Mârza <adi11235 at gmail dot com> Co-authored-by: Kyle Altendorf <sda@fstab.net> Co-authored-by: Shoubhit Dash <shoubhit2005@gmail.com> Co-authored-by: DS <78942835+Tarquinen@users.noreply.github.com> Co-authored-by: Jason Quense <monastic.panic@gmail.com>
1 parent 73ae3ca commit 9715924

8 files changed

Lines changed: 39 additions & 18 deletions

File tree

packages/opencode/src/cli/cmd/tui/ui/dialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function init() {
7070
useKeyboard((evt) => {
7171
if (store.stack.length === 0) return
7272
if (evt.defaultPrevented) return
73-
if ((evt.name === "escape" || (evt.ctrl && evt.name === "c")) && renderer.getSelection()) return
73+
if ((evt.name === "escape" || (evt.ctrl && evt.name === "c")) && renderer.getSelection()?.getSelectedText()) return
7474
if (evt.name === "escape" || (evt.ctrl && evt.name === "c")) {
7575
const current = store.stack.at(-1)!
7676
current.onClose?.()

packages/opencode/src/project/vcs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export namespace Vcs {
4747
log.info("initialized", { branch: current })
4848

4949
const unsubscribe = Bus.subscribe(FileWatcher.Event.Updated, async (evt) => {
50-
if (evt.properties.file.endsWith("HEAD")) return
50+
if (!evt.properties.file.endsWith("HEAD")) return
5151
const next = await currentBranch()
5252
if (next !== current) {
5353
log.info("branch changed", { from: current, to: next })

packages/opencode/src/provider/error.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ export namespace ProviderError {
167167

168168
export function parseAPICallError(input: { providerID: ProviderID; error: APICallError }): ParsedAPICallError {
169169
const m = message(input.providerID, input.error)
170-
if (isOverflow(m) || input.error.statusCode === 413) {
170+
const body = json(input.error.responseBody)
171+
if (isOverflow(m) || input.error.statusCode === 413 || body?.error?.code === "context_length_exceeded") {
171172
return {
172173
type: "context_overflow",
173174
message: m,

packages/opencode/src/session/compaction.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ When constructing the summary, try to stick to this template:
204204
---`
205205

206206
const promptText = compacting.prompt ?? [defaultPrompt, ...compacting.context].join("\n\n")
207+
const msgs = structuredClone(messages)
208+
await Plugin.trigger("experimental.chat.messages.transform", {}, { messages: msgs })
207209
const result = await processor.process({
208210
user: userMessage,
209211
agent,
@@ -212,7 +214,7 @@ When constructing the summary, try to stick to this template:
212214
tools: {},
213215
system: [],
214216
messages: [
215-
...MessageV2.toModelMessages(messages, model, { stripMedia: true }),
217+
...MessageV2.toModelMessages(msgs, model, { stripMedia: true }),
216218
{
217219
role: "user",
218220
content: [

packages/opencode/src/session/llm.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export namespace LLM {
3737
messages: ModelMessage[]
3838
small?: boolean
3939
tools: Record<string, Tool>
40+
permission?: PermissionNext.Ruleset
4041
retries?: number
4142
toolChoice?: "auto" | "required" | "none"
4243
}
@@ -255,8 +256,11 @@ export namespace LLM {
255256
})
256257
}
257258

258-
async function resolveTools(input: Pick<StreamInput, "tools" | "agent" | "user">) {
259-
const disabled = PermissionNext.disabled(Object.keys(input.tools), input.agent.permission)
259+
async function resolveTools(input: Pick<StreamInput, "tools" | "agent" | "user" | "permission">) {
260+
const disabled = PermissionNext.disabled(
261+
Object.keys(input.tools),
262+
PermissionNext.merge(input.agent.permission, input.permission ?? []),
263+
)
260264
for (const tool of Object.keys(input.tools)) {
261265
if (input.user.tools?.[tool] === false || disabled.has(tool)) {
262266
delete input.tools[tool]

packages/opencode/src/session/prompt.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ export namespace SessionPrompt {
709709
: []),
710710
],
711711
tools,
712+
permission: session.permission,
712713
model,
713714
toolChoice: format.type === "json_schema" ? "required" : undefined,
714715
})
@@ -1351,6 +1352,26 @@ export namespace SessionPrompt {
13511352
},
13521353
)
13531354

1355+
const infoResult = MessageV2.Info.safeParse(info)
1356+
if (!infoResult.success) {
1357+
log.error("info schema validation failed before save", {
1358+
sessionID: input.sessionID,
1359+
messageID: info.id,
1360+
issues: infoResult.error.issues,
1361+
})
1362+
}
1363+
for (const [i, part] of parts.entries()) {
1364+
const partResult = MessageV2.Part.safeParse(part)
1365+
if (!partResult.success) {
1366+
log.error("part schema validation failed before save", {
1367+
sessionID: input.sessionID,
1368+
partID: part.id,
1369+
partType: part.type,
1370+
index: i,
1371+
issues: partResult.error.issues,
1372+
})
1373+
}
1374+
}
13541375
await Session.updateMessage(info)
13551376
for (const part of parts) {
13561377
await Session.updatePart(part)

packages/opencode/src/util/fn.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export function fn<T extends z.ZodType, Result>(schema: T, cb: (input: z.infer<T
77
parsed = schema.parse(input)
88
} catch (e) {
99
console.trace("schema validation failure stack trace:")
10+
if (e instanceof z.ZodError) {
11+
console.error("schema validation issues:", JSON.stringify(e.issues, null, 2))
12+
}
1013
throw e
1114
}
1215

packages/ui/src/components/message-part.css

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,18 +1050,8 @@
10501050
line-height: var(--line-height-large);
10511051
color: var(--text-base);
10521052
min-width: 0;
1053-
overflow: hidden;
1054-
text-overflow: ellipsis;
1055-
white-space: nowrap;
1056-
}
1057-
1058-
[data-slot="question-option"][data-custom="true"] {
1059-
[data-slot="option-description"] {
1060-
overflow: visible;
1061-
text-overflow: clip;
1062-
white-space: normal;
1063-
overflow-wrap: anywhere;
1064-
}
1053+
overflow-wrap: anywhere;
1054+
white-space: normal;
10651055
}
10661056

10671057
[data-slot="question-custom"] {

0 commit comments

Comments
 (0)