fix(tui): keep context view concise
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import {
|
||||
BoxRenderable,
|
||||
TextAttributes,
|
||||
TextRenderable,
|
||||
type CliRenderer,
|
||||
} from "@opentui/core"
|
||||
@@ -9,7 +8,6 @@ import type { SessionContextSnapshot } from "./protocol"
|
||||
|
||||
export interface ContextPanelTheme {
|
||||
text: string
|
||||
muted: string
|
||||
border: string
|
||||
accent: string
|
||||
}
|
||||
@@ -23,16 +21,14 @@ export function formatTokenCount(value: number): string {
|
||||
/** Read-only explanation of the session-owned context replayed to the agent. */
|
||||
export class ContextPanel {
|
||||
readonly root: BoxRenderable
|
||||
private readonly title: TextRenderable
|
||||
private readonly stats: TextRenderable
|
||||
private readonly summary: TextRenderable
|
||||
private readonly note: TextRenderable
|
||||
|
||||
constructor(renderer: CliRenderer, theme: ContextPanelTheme) {
|
||||
this.root = new BoxRenderable(renderer, {
|
||||
id: "nanobot-tui-context-panel",
|
||||
width: "100%",
|
||||
maxHeight: 12,
|
||||
maxHeight: 9,
|
||||
flexShrink: 0,
|
||||
flexDirection: "column",
|
||||
border: true,
|
||||
@@ -42,14 +38,6 @@ export class ContextPanel {
|
||||
paddingRight: 1,
|
||||
visible: false,
|
||||
})
|
||||
this.title = new TextRenderable(renderer, {
|
||||
id: "nanobot-tui-context-title",
|
||||
content: "Agent context",
|
||||
width: "100%",
|
||||
height: 1,
|
||||
fg: theme.text,
|
||||
attributes: TextAttributes.BOLD,
|
||||
})
|
||||
this.stats = new TextRenderable(renderer, {
|
||||
id: "nanobot-tui-context-stats",
|
||||
content: "",
|
||||
@@ -65,17 +53,8 @@ export class ContextPanel {
|
||||
fg: theme.text,
|
||||
wrapMode: "word",
|
||||
})
|
||||
this.note = new TextRenderable(renderer, {
|
||||
id: "nanobot-tui-context-note",
|
||||
content: "Session view only · memory, instructions, and skills are added separately · Esc close",
|
||||
width: "100%",
|
||||
fg: theme.muted,
|
||||
wrapMode: "word",
|
||||
})
|
||||
this.root.add(this.title)
|
||||
this.root.add(this.stats)
|
||||
this.root.add(this.summary)
|
||||
this.root.add(this.note)
|
||||
}
|
||||
|
||||
get visible(): boolean {
|
||||
@@ -83,13 +62,8 @@ export class ContextPanel {
|
||||
}
|
||||
|
||||
show(context: SessionContextSnapshot): void {
|
||||
const archived = context.archivedMessages > 0
|
||||
? `${context.archivedMessages} archived · summary ${context.archivedSummary ? "active" : "unavailable"}`
|
||||
: "No archived messages"
|
||||
this.stats.content = `~${formatTokenCount(context.estimatedSessionTokens)} session tokens · ${context.replayMessages} replay messages · ${archived}`
|
||||
this.summary.content = context.archivedSummary
|
||||
? `Summary\n${context.archivedSummary}`
|
||||
: "The agent is currently replaying raw session messages; no compacted summary exists yet."
|
||||
this.stats.content = `~${formatTokenCount(context.estimatedSessionTokens)} tokens · ${context.replayMessages} replay · ${context.archivedMessages} archived`
|
||||
this.summary.content = context.archivedSummary ?? ""
|
||||
this.root.visible = true
|
||||
}
|
||||
|
||||
@@ -102,15 +76,12 @@ export class ContextPanel {
|
||||
const medium = terminalHeight < 20
|
||||
this.summary.visible = !compact
|
||||
this.summary.maxHeight = medium ? 2 : 6
|
||||
this.note.visible = !medium
|
||||
this.root.maxHeight = compact ? 4 : medium ? 6 : 12
|
||||
this.root.maxHeight = compact ? 3 : medium ? 5 : 9
|
||||
}
|
||||
|
||||
setTheme(theme: ContextPanelTheme): void {
|
||||
this.root.borderColor = theme.border
|
||||
this.title.fg = theme.text
|
||||
this.stats.fg = theme.accent
|
||||
this.summary.fg = theme.text
|
||||
this.note.fg = theme.muted
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user