Skip to content

Commit 34c1f36

Browse files
committed
wip: v1.17.9 reconciliation — §4 re-home TUI batch 2 + line-streaming flags (checkpoint 6)
Second re-homing wave into packages/tui (live TUI). packages/tui + packages/core both typecheck GREEN. Re-homed (functional): - context/sync.tsx — full streaming feature set: yolo auto-approve (adapted to the new permission.reply API: workspace arg + reply:"once"), smooth-streaming direct-path delta update, and the complete line-streaming buffer feature (lineBuffer + flushLineBuffer + flushAllBuffersForMessage + the 5 event-handler hooks). event.type/.properties is correct here (useEvent unwraps GlobalEvent.payload, unlike sdk.tsx). - routes/session/index.tsx — `builder` agent name on plan_exit, smooth-streaming scroll (toBottom 0ms), calm-mode content width cap (maxWidth via ALTIMATE_CONTENT_MAX_WIDTH). - theme/index.ts — light-mode fg fallback (AltimateAI#704), code-block + inline-code backgrounds for light-theme contrast. NOTE: inline-code uses theme.backgroundElement vs upstream's new theme.background — flagged inline for the next merge's human review. - feature-plugins/home/tips-view.tsx — fork DE-specific tips (/discover, /cost-report, /dbt-docs, /sql-review, /migrate-sql, lineage, anti-patterns) folded into the new Tip pool. Flags re-homed into packages/core/src/flag/flag.ts (tui depends on core, not opencode): ALTIMATE_LINE_STREAMING, ALTIMATE_CONTENT_MAX_WIDTH (+ numberEnv helper), joining the ALTIMATE_CALM_MODE/SMOOTH_STREAMING/CLI_YOLO added in checkpoint 5. MOOT (upstream v1.17.9 shipped equivalents — dropped per upstream_fix rule): - prompt skills-dialog keybind → upstream `prompt_skills` keybind. - session workspace-gate, smooth-streaming memoize, light-theme md fg (upstream ships fg=markdownText + bg=background). DEFERRED — architectural (tracked): enhance feature (enhance-prompt.ts), dialog-provider (AltimateApi), dialog-skill (skill-helpers + keymap port). All three depend on opencode-package code unreachable from packages/tui — need the shared code moved into @opencode-ai/core, routed via SDK/server, or implemented as tui plugins. Real features; not dropped. DEFERRED — render-rewritten: session/index TextPart code-during-streaming, tips first-time-only behavior, sidebar trace section (sidebar_content slot), footer/home UpgradeIndicator (component not yet ported into packages/tui). OLD cli/cmd/tui/** files untouched (deleted in §3.4 after all re-homing verified).
1 parent 2a22e6b commit 34c1f36

6 files changed

Lines changed: 240 additions & 50 deletions

File tree

‎.github/meta/commit.txt‎

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
wip: v1.17.9 reconciliation — §4 re-home TUI customizations into packages/tui (checkpoint 5)
1+
wip: v1.17.9 reconciliation — §4 re-home TUI batch 2 + line-streaming flags (checkpoint 6)
22

3-
The TUI was extracted upstream to packages/tui (live) from cli/cmd/tui/** (dead — no
4-
@tui alias resolves it). Re-apply the fork customizations into the live package,
5-
preserving altimate_change markers. packages/tui + packages/core both typecheck GREEN.
3+
Second re-homing wave into packages/tui (live TUI). packages/tui + packages/core both
4+
typecheck GREEN.
65

7-
Re-homed (functional + branding):
8-
- context/sdk.tsx — smooth-streaming delta pre-merge (ALTIMATE_SMOOTH_STREAMING).
9-
Adapted to v2 GlobalEvent (discriminant nested under `.payload`, not top-level).
10-
- routes/session/footer.tsx — YOLO-mode badge (ALTIMATE_CLI_YOLO).
11-
- routes/session/sidebar.tsx — "Altimate Code" branding (uses InstallationVersion).
12-
- component/logo.tsx — restore brand colors (primary/accent vs textMuted/text) in the
13-
rewritten 8-arg renderLine call-site.
14-
- component/dialog-status.tsx — `altimate mcp auth` branding fix.
15-
- component/error-component.tsx — `altimate-code: fatal:` title + AltimateAI/altimate-code
16-
issue URL (was anomalyco/opencode brand leak).
17-
- context/route.tsx — restore dropped navigate debug log (console.debug; tui has no
18-
structured logger).
6+
Re-homed (functional):
7+
- context/sync.tsx — full streaming feature set: yolo auto-approve (adapted to the new
8+
permission.reply API: workspace arg + reply:"once"), smooth-streaming direct-path delta
9+
update, and the complete line-streaming buffer feature (lineBuffer + flushLineBuffer +
10+
flushAllBuffersForMessage + the 5 event-handler hooks). event.type/.properties is correct
11+
here (useEvent unwraps GlobalEvent.payload, unlike sdk.tsx).
12+
- routes/session/index.tsx — `builder` agent name on plan_exit, smooth-streaming scroll
13+
(toBottom 0ms), calm-mode content width cap (maxWidth via ALTIMATE_CONTENT_MAX_WIDTH).
14+
- theme/index.ts — light-mode fg fallback (#704), code-block + inline-code backgrounds for
15+
light-theme contrast. NOTE: inline-code uses theme.backgroundElement vs upstream's new
16+
theme.background — flagged inline for the next merge's human review.
17+
- feature-plugins/home/tips-view.tsx — fork DE-specific tips (/discover, /cost-report,
18+
/dbt-docs, /sql-review, /migrate-sql, lineage, anti-patterns) folded into the new Tip pool.
1919

20-
Flag re-home (packages/core/src/flag/flag.ts): added ALTIMATE_CALM_MODE,
21-
ALTIMATE_SMOOTH_STREAMING, ALTIMATE_CLI_YOLO getters + altTruthy helper, since packages/tui
22-
depends on @opencode-ai/core (not opencode) and could not otherwise see the fork flags.
20+
Flags re-homed into packages/core/src/flag/flag.ts (tui depends on core, not opencode):
21+
ALTIMATE_LINE_STREAMING, ALTIMATE_CONTENT_MAX_WIDTH (+ numberEnv helper), joining the
22+
ALTIMATE_CALM_MODE/SMOOTH_STREAMING/CLI_YOLO added in checkpoint 5.
2323

24-
MOOT (not re-applied — upstream issue gone): dialog-mcp / dialog-workspace-list logger
25-
fixes (tui uses console.* throughout, has no structured logger, the old console.log/debug
26-
prints don't exist in the rewritten files).
24+
MOOT (upstream v1.17.9 shipped equivalents — dropped per upstream_fix rule):
25+
- prompt skills-dialog keybind → upstream `prompt_skills` keybind.
26+
- session workspace-gate, smooth-streaming memoize, light-theme md fg (upstream ships
27+
fg=markdownText + bg=background).
2728

28-
DEFERRED (tracked, code re-architected into other owner files — next pass):
29-
- theme #704 light-fg + code-block/inline-code bg → packages/tui/src/theme/index.ts
30-
(generateSystem/getSyntaxRules). One human decision: inline-code backgroundElement vs
31-
upstream's new background.
32-
- beginner/first-time tips + onboarding hint → feature-plugins/home/{tips,tips-view}.tsx
33-
(home is now a plugin-slot shell).
34-
- UpgradeIndicator: component + utils exist only in the old tree, not ported → blocks the
35-
footer + home upgrade-indicator blocks until ported into packages/tui/src/component.
36-
- sidebar trace section → sidebar_content plugin slot.
29+
DEFERRED — architectural (tracked): enhance feature (enhance-prompt.ts), dialog-provider
30+
(AltimateApi), dialog-skill (skill-helpers + keymap port). All three depend on opencode-package
31+
code unreachable from packages/tui — need the shared code moved into @opencode-ai/core, routed
32+
via SDK/server, or implemented as tui plugins. Real features; not dropped.
3733

38-
OLD cli/cmd/tui/** files untouched (deleted later in §3.4 after all re-homing verified).
34+
DEFERRED — render-rewritten: session/index TextPart code-during-streaming, tips first-time-only
35+
behavior, sidebar trace section (sidebar_content slot), footer/home UpgradeIndicator (component
36+
not yet ported into packages/tui).
37+
38+
OLD cli/cmd/tui/** files untouched (deleted in §3.4 after all re-homing verified).

‎packages/core/src/flag/flag.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ export function truthy(key: string) {
1111
function altTruthy(altKey: string, openKey: string) {
1212
return truthy(altKey) || truthy(openKey)
1313
}
14+
function numberEnv(key: string) {
15+
const value = process.env[key]
16+
if (!value) return undefined
17+
const parsed = Number(value)
18+
return Number.isInteger(parsed) && parsed > 0 ? parsed : undefined
19+
}
1420
// altimate_change end
1521

1622
const copy = process.env["OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT"]
@@ -91,6 +97,16 @@ export const Flag = {
9197
get ALTIMATE_SMOOTH_STREAMING() {
9298
return this.ALTIMATE_CALM_MODE || altTruthy("ALTIMATE_SMOOTH_STREAMING", "OPENCODE_SMOOTH_STREAMING")
9399
},
100+
get ALTIMATE_LINE_STREAMING() {
101+
return this.ALTIMATE_CALM_MODE || altTruthy("ALTIMATE_LINE_STREAMING", "OPENCODE_LINE_STREAMING")
102+
},
103+
get ALTIMATE_CONTENT_MAX_WIDTH() {
104+
return (
105+
numberEnv("ALTIMATE_CONTENT_MAX_WIDTH") ??
106+
numberEnv("OPENCODE_CONTENT_MAX_WIDTH") ??
107+
(this.ALTIMATE_CALM_MODE ? 100 : undefined)
108+
)
109+
},
94110
get ALTIMATE_CLI_YOLO() {
95111
const alt = process.env["ALTIMATE_CLI_YOLO"]
96112
if (alt !== undefined) {

‎packages/tui/src/context/sync.tsx‎

Lines changed: 127 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ import { useArgs } from "./args"
3131
import { batch, onMount } from "solid-js"
3232
import path from "path"
3333
import { useKV } from "./kv"
34+
// altimate_change start - yolo mode + smooth streaming
35+
import { Flag } from "@opencode-ai/core/flag/flag"
36+
// altimate_change end
3437

3538
const emptyConsoleState: ConsoleState = {
3639
consoleManagedProviders: [],
@@ -149,6 +152,43 @@ export const {
149152
hydratingSessions.get(sessionID)?.parts.add(partID)
150153
}
151154

155+
// altimate_change start - line streaming: buffer deltas, flush only on \n or message completion
156+
const lineBuffer = new Map<string, string>()
157+
158+
function flushLineBuffer(messageID: string, partID: string, field: string, forceAll: boolean) {
159+
const key = `${messageID}:${partID}:${field}`
160+
const buffer = lineBuffer.get(key)
161+
if (!buffer) return
162+
let textToFlush: string
163+
if (forceAll) {
164+
textToFlush = buffer
165+
lineBuffer.delete(key)
166+
} else {
167+
const lastNewline = buffer.lastIndexOf("\n")
168+
if (lastNewline === -1) return
169+
textToFlush = buffer.slice(0, lastNewline + 1)
170+
const remainder = buffer.slice(lastNewline + 1)
171+
if (remainder) lineBuffer.set(key, remainder)
172+
else lineBuffer.delete(key)
173+
}
174+
if (!textToFlush) return
175+
const parts = store.part[messageID]
176+
if (!parts) return
177+
const result = search(parts, partID, (p) => p.id)
178+
if (!result.found) return
179+
const existing = parts[result.index][field as keyof (typeof parts)[number]] as string | undefined
180+
setStore("part", messageID, result.index, field as any, ((existing ?? "") + textToFlush) as any)
181+
}
182+
183+
function flushAllBuffersForMessage(messageID: string) {
184+
for (const [key] of lineBuffer) {
185+
if (!key.startsWith(messageID + ":")) continue
186+
const [, partID, field] = key.split(":")
187+
flushLineBuffer(messageID, partID, field, true)
188+
}
189+
}
190+
// altimate_change end
191+
152192
function sessionListQuery(): { scope?: "project"; path?: string } {
153193
if (!kv.get("session_directory_filter_enabled", true)) return { scope: "project" }
154194
if (!project.data.instance.path.worktree || !project.data.instance.path.directory) return { scope: "project" }
@@ -187,6 +227,23 @@ export const {
187227

188228
case "permission.asked": {
189229
const request = event.properties
230+
// altimate_change start - yolo mode: auto-approve without showing prompt
231+
if (Flag.ALTIMATE_CLI_YOLO) {
232+
void sdk.client.permission
233+
.reply({
234+
requestID: request.id,
235+
reply: "once",
236+
workspace,
237+
})
238+
.catch((e) => {
239+
console.error("yolo mode auto-approve failed", {
240+
error: e instanceof Error ? e.message : String(e),
241+
requestID: request.id,
242+
})
243+
})
244+
break
245+
}
246+
// altimate_change end
190247
const requests = store.permission[request.sessionID]
191248
if (!requests) {
192249
setStore("permission", request.sessionID, [request])
@@ -303,6 +360,15 @@ export const {
303360

304361
case "message.updated": {
305362
touchMessage(event.properties.info.sessionID, event.properties.info.id)
363+
// altimate_change start - line streaming: flush remaining buffer when message completes
364+
if (
365+
Flag.ALTIMATE_LINE_STREAMING &&
366+
"completed" in event.properties.info.time &&
367+
event.properties.info.time.completed
368+
) {
369+
flushAllBuffersForMessage(event.properties.info.id)
370+
}
371+
// altimate_change end
306372
const messages = store.message[event.properties.info.sessionID]
307373
if (!messages) {
308374
setStore("message", event.properties.info.sessionID, [event.properties.info])
@@ -343,6 +409,11 @@ export const {
343409
}
344410
case "message.removed": {
345411
touchMessage(event.properties.sessionID, event.properties.messageID)
412+
// altimate_change start - line streaming: clean up buffers for removed/aborted messages
413+
if (Flag.ALTIMATE_LINE_STREAMING) {
414+
flushAllBuffersForMessage(event.properties.messageID)
415+
}
416+
// altimate_change end
346417
const messages = store.message[event.properties.sessionID]
347418
const result = search(messages, event.properties.messageID, (m) => m.id)
348419
if (result.found) {
@@ -358,6 +429,17 @@ export const {
358429
}
359430
case "message.part.updated": {
360431
touchPart(event.properties.part.sessionID, event.properties.part.id)
432+
// altimate_change start - line streaming: discard buffered text when part is
433+
// authoritatively set by the server (via reconcile). Without this, the buffer
434+
// would append stale text on top of the server's complete content, duplicating
435+
// the trailing partial line.
436+
if (Flag.ALTIMATE_LINE_STREAMING) {
437+
const { messageID, id: partID } = event.properties.part
438+
for (const key of lineBuffer.keys()) {
439+
if (key.startsWith(`${messageID}:${partID}:`)) lineBuffer.delete(key)
440+
}
441+
}
442+
// altimate_change end
361443
const parts = store.part[event.properties.part.messageID]
362444
if (!parts) {
363445
setStore("part", event.properties.part.messageID, [event.properties.part])
@@ -384,21 +466,56 @@ export const {
384466
const result = search(parts, event.properties.partID, (p) => p.id)
385467
if (!result.found) break
386468
touchPart(event.properties.sessionID, event.properties.partID)
387-
setStore(
388-
"part",
389-
event.properties.messageID,
390-
produce((draft) => {
391-
const part = draft[result.index]
392-
const field = event.properties.field as keyof typeof part
393-
const existing = part[field] as string | undefined
394-
;(part[field] as string) = (existing ?? "") + event.properties.delta
395-
}),
396-
)
469+
// altimate_change start - line streaming: buffer deltas, flush only on \n
470+
// Note: when line streaming is enabled (including via calm mode), this branch
471+
// handles all delta processing and breaks — the smooth streaming branch below
472+
// is not reached. This is intentional: flushLineBuffer already does direct
473+
// store path updates, so the produce() bypass is not needed.
474+
if (Flag.ALTIMATE_LINE_STREAMING) {
475+
const { messageID, partID, field, delta } = event.properties
476+
const key = `${messageID}:${partID}:${field}`
477+
lineBuffer.set(key, (lineBuffer.get(key) ?? "") + delta)
478+
flushLineBuffer(messageID, partID, field, false)
479+
break
480+
}
481+
// altimate_change end
482+
// altimate_change start - smooth streaming: direct path update avoids produce() proxy overhead
483+
if (Flag.ALTIMATE_SMOOTH_STREAMING) {
484+
const field = event.properties.field as keyof (typeof parts)[number]
485+
const existing = parts[result.index][field] as string | undefined
486+
setStore(
487+
"part",
488+
event.properties.messageID,
489+
result.index,
490+
field as any,
491+
((existing ?? "") + event.properties.delta) as any,
492+
)
493+
} else {
494+
setStore(
495+
"part",
496+
event.properties.messageID,
497+
produce((draft) => {
498+
const part = draft[result.index]
499+
const field = event.properties.field as keyof typeof part
500+
const existing = part[field] as string | undefined
501+
;(part[field] as string) = (existing ?? "") + event.properties.delta
502+
}),
503+
)
504+
}
505+
// altimate_change end
397506
break
398507
}
399508

400509
case "message.part.removed": {
401510
touchPart(event.properties.sessionID, event.properties.partID)
511+
// altimate_change start - line streaming: discard buffers for removed parts
512+
if (Flag.ALTIMATE_LINE_STREAMING) {
513+
const { messageID, partID } = event.properties
514+
for (const key of lineBuffer.keys()) {
515+
if (key.startsWith(`${messageID}:${partID}:`)) lineBuffer.delete(key)
516+
}
517+
}
518+
// altimate_change end
402519
const parts = store.part[event.properties.messageID]
403520
const result = search(parts, event.properties.partID, (p) => p.id)
404521
if (result.found) {

‎packages/tui/src/feature-plugins/home/tips-view.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,17 @@ const TIPS: Tip[] = [
280280
"Use {highlight}/review{/highlight} to review uncommitted changes, branches, or PRs",
281281
(shortcuts) => `Use ${commandText("/help", shortcuts.helpShow())} to show the help dialog`,
282282
"Use {highlight}/rename{/highlight} to rename the current session",
283+
// altimate_change start — prioritized beginner & data engineering tips
284+
"Run {highlight}/discover{/highlight} to auto-detect your dbt project and warehouse connections",
285+
"Use {highlight}/cost-report{/highlight} to analyze warehouse spending",
286+
"Use {highlight}/dbt-docs{/highlight} to generate dbt model documentation",
287+
"Use {highlight}/generate-tests{/highlight} to auto-generate dbt tests for your models",
288+
"Use {highlight}/sql-review{/highlight} to review SQL for correctness and performance",
289+
"Use {highlight}/migrate-sql{/highlight} to translate SQL between warehouse dialects",
290+
"Use {highlight}/ci-check{/highlight} to run pre-merge SQL validation on changed files",
291+
"Ask me to analyze a SQL query for anti-patterns — I'll detect 19+ issue types with zero false positives",
292+
"Ask me to trace column-level lineage for any SQL query across dialects",
293+
// altimate_change end
283294
]
284295

285296
const INPUT_UNDO_TIP: Tip = (shortcuts) => press(shortcuts.inputUndo(), "to undo changes in your prompt")

‎packages/tui/src/routes/session/index.tsx‎

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ import { DialogRetryAction } from "../../component/dialog-retry-action"
8181
import { getRevertDiffFiles } from "../../util/revert-diff"
8282
import { OPENCODE_BASE_MODE, useBindings, useCommandShortcut, useOpencodeKeymap } from "../../keymap"
8383
import { PathFormatterProvider, usePathFormatter } from "../../context/path-format"
84+
// altimate_change start — smooth streaming flag
85+
import { Flag } from "@opencode-ai/core/flag/flag"
86+
// altimate_change end
8487

8588
addDefaultParsers(parsers.parsers)
8689

@@ -320,7 +323,13 @@ export function Session() {
320323
if (part.id === lastSwitch) return
321324

322325
if (part.tool === "plan_exit") {
323-
local.agent.set("build")
326+
// altimate_change start — canonical "builder" agent name (renamed from "build")
327+
// Previously wrote "build" here which then flowed into the next session.prompt
328+
// request as `agent: "build"`, leaking the legacy name into telemetry. Even
329+
// though prompt.ts now normalizes at the emit boundary, write the canonical
330+
// value at the source so debugging dumps / inspection see consistent state.
331+
local.agent.set("builder")
332+
// altimate_change end
324333
lastSwitch = part.id
325334
} else if (part.tool === "plan_enter") {
326335
local.agent.set("plan")
@@ -409,10 +418,15 @@ export function Session() {
409418
}
410419

411420
function toBottom() {
412-
setTimeout(() => {
413-
if (!scroll || scroll.isDestroyed) return
414-
scroll.scrollTo(scroll.scrollHeight)
415-
}, 50)
421+
// altimate_change start - smooth streaming: reduce scroll lag
422+
setTimeout(
423+
() => {
424+
if (!scroll || scroll.isDestroyed) return
425+
scroll.scrollTo(scroll.scrollHeight)
426+
},
427+
Flag.ALTIMATE_SMOOTH_STREAMING ? 0 : 50,
428+
)
429+
// altimate_change end
416430
}
417431

418432
const local = useLocal()
@@ -1686,9 +1700,28 @@ function ReasoningHeader(props: {
16861700
function TextPart(props: { last: boolean; part: TextPart; message: AssistantMessage }) {
16871701
const ctx = use()
16881702
const { theme, syntax } = useTheme()
1703+
// altimate_change start - calm mode: cap content width for readability, respect small screens
1704+
const cappedWidth = createMemo(() => {
1705+
const cap = Flag.ALTIMATE_CONTENT_MAX_WIDTH
1706+
if (!cap) return undefined
1707+
const available = ctx.width
1708+
// +3 accounts for paddingLeft on this box
1709+
const desired = cap + 3
1710+
// On small screens, don't constrain — let it use full available width
1711+
return available <= desired ? undefined : desired
1712+
})
1713+
// altimate_change end
16891714
return (
16901715
<Show when={props.part.text.trim()}>
1691-
<box ref={(el: BoxRenderable) => alwaysSeparate.add(el)} paddingLeft={3} marginTop={1} flexShrink={0}>
1716+
<box
1717+
ref={(el: BoxRenderable) => alwaysSeparate.add(el)}
1718+
paddingLeft={3}
1719+
marginTop={1}
1720+
flexShrink={0}
1721+
// altimate_change start - calm mode: apply capped content width
1722+
maxWidth={cappedWidth()}
1723+
// altimate_change end
1724+
>
16921725
<markdown
16931726
syntaxStyle={syntax()}
16941727
streaming={true}

0 commit comments

Comments
 (0)