diff --git a/cli/internal/daemon/events.go b/cli/internal/daemon/events.go index b4c9314ab..4769c9a4d 100644 --- a/cli/internal/daemon/events.go +++ b/cli/internal/daemon/events.go @@ -34,6 +34,9 @@ type ToolActivity struct { Target string `json:"target"` Artifact *ArtifactActivity `json:"artifact,omitempty"` Skill *SkillActivity `json:"skill,omitempty"` + // Title and Description are the display() metadata; they are separate from content. + Title string `json:"title,omitempty"` + Description string `json:"description,omitempty"` // Detail is the markdown a web search answered with or display() showed; empty otherwise. Detail string `json:"detail,omitempty"` // MS and OK are how long the call took and whether it worked, when it diff --git a/cli/internal/daemon/protocol/api.gen.go b/cli/internal/daemon/protocol/api.gen.go index 4214cf660..825950b40 100644 --- a/cli/internal/daemon/protocol/api.gen.go +++ b/cli/internal/daemon/protocol/api.gen.go @@ -3992,6 +3992,9 @@ type ToolActivity struct { Version int64 `json:"version"` } `json:"artifact,omitempty"` + // Description The optional display() description. + Description *string `json:"description,omitempty"` + // Detail What the person watching sees of the result, as markdown; a web search's answer and sources, or displayed content. Detail *string `json:"detail,omitempty"` Kind string `json:"kind"` @@ -4011,6 +4014,9 @@ type ToolActivity struct { Source string `json:"source"` } `json:"skill,omitempty"` Target string `json:"target"` + + // Title The optional display() title. + Title *string `json:"title,omitempty"` } // ToolProgress Examples: {"call_id":"progress-1","intent":"unknown","name":"python","phase":"generating","preview":{"offset_scalars":0,"text":"print(\"hello\")"},"title":"find which go files label python cells","tool_call_id":null} diff --git a/cli/internal/daemon/protocol/digest.gen.go b/cli/internal/daemon/protocol/digest.gen.go index b20d19bb2..6e47d5e5a 100644 --- a/cli/internal/daemon/protocol/digest.gen.go +++ b/cli/internal/daemon/protocol/digest.gen.go @@ -5,4 +5,4 @@ package protocol // APIDigest identifies the wire contract these types were generated from. // The daemon reports its own in GET /server; a different value means this // client's decoders may reject what the daemon sends. -const APIDigest = "6fc282e701173d89cf1e118d51a7a0111608362cf617a99d074438cb4360d988" +const APIDigest = "f91eca9fd65605b520c9949e86bfcf91810939b666821f7cdd4f4e75151f1f7b" diff --git a/cli/internal/tui/burst.go b/cli/internal/tui/burst.go index b3904c576..236103fd8 100644 --- a/cli/internal/tui/burst.go +++ b/cli/internal/tui/burst.go @@ -120,7 +120,7 @@ type entryFacts struct { // lookup is one web search or displayed block a call made: its label, its // detail, and the key its fold opens by. -type lookup struct{ key, query, detail string } +type lookup struct{ key, query, title, description, detail string } // factsOf reads one entry's contribution, using what append already computed // when it can. @@ -158,10 +158,10 @@ func factsOf(entry HistoryEntry) entryFacts { f.searched = append(f.searched, oneLine(activity.Target)) case "web": key := fmt.Sprintf("%x-%x", entry.Timestamp, fnv1a(fnvOffset64, f.key+"\x00"+activity.Target)) - f.looked = append(f.looked, lookup{key, activity.Target, activity.Detail}) + f.looked = append(f.looked, lookup{key, activity.Target, activity.Title, activity.Description, activity.Detail}) case "display": key := fmt.Sprintf("%x-%x", entry.Timestamp, fnv1a(fnvOffset64, fmt.Sprintf("%s\x00display:%d\x00%s", f.key, len(f.displayed), activity.Target))) - f.displayed = append(f.displayed, lookup{key, activity.Target, activity.Detail}) + f.displayed = append(f.displayed, lookup{key, activity.Target, activity.Title, activity.Description, activity.Detail}) case "run": f.ran = append(f.ran, commandName(activity.Target)) case "artifact": @@ -373,7 +373,10 @@ func (r TranscriptRenderer) foldLookup(look lookup, width int) []string { // renderDisplayRows renders a displayed block with diff or markdown styling, // indented by two columns. -func (r TranscriptRenderer) renderDisplayRows(target, detail string, width int) []string { +func (r TranscriptRenderer) renderDisplayRows(target, title, description, detail string, width int) []string { + if title != "" || description != "" { + detail = strings.TrimSpace(strings.Join([]string{title, description, detail}, "\n\n")) + } if detail == "" { return nil } @@ -409,7 +412,7 @@ func (r TranscriptRenderer) renderDisplayRows(target, detail string, width int) // foldDisplay is a displayed block under its burst: rendered with diff or // markdown styling and folded past foldRows until its key is in Open. func (r TranscriptRenderer) foldDisplay(disp lookup, width int) []string { - rows := r.renderDisplayRows(disp.query, disp.detail, width) + rows := r.renderDisplayRows(disp.query, disp.title, disp.description, disp.detail, width) if len(rows) == 0 { return nil } diff --git a/cli/internal/tui/cards.go b/cli/internal/tui/cards.go index f7393aca8..dafa3ef18 100644 --- a/cli/internal/tui/cards.go +++ b/cli/internal/tui/cards.go @@ -209,7 +209,7 @@ func (r TranscriptRenderer) cardCalls(trace *daemon.ToolTrace, flags DisplayFlag } rows = append(rows, markChrome+panel(head+target+took)) if act.Kind == "display" && act.Detail != "" { - for _, row := range r.renderDisplayRows(act.Target, act.Detail, width) { + for _, row := range r.renderDisplayRows(act.Target, act.Title, act.Description, act.Detail, width) { rows = append(rows, panel(row)) } } diff --git a/cli/internal/tui/transcript.go b/cli/internal/tui/transcript.go index 5b2f9d561..c0a006e6d 100644 --- a/cli/internal/tui/transcript.go +++ b/cli/internal/tui/transcript.go @@ -518,7 +518,7 @@ func (r TranscriptRenderer) RenderToolTrace(trace *daemon.ToolTrace, flags Displ } rows = append(rows, DefaultStyles.Faint.Render(r.traceLine(act.Kind, act.Target, isPath(act), width))) if act.Kind == "display" && act.Detail != "" { - rows = append(rows, r.renderDisplayRows(act.Target, act.Detail, width)...) + rows = append(rows, r.renderDisplayRows(act.Target, act.Title, act.Description, act.Detail, width)...) } } for _, change := range trace.Changes { diff --git a/docs/openapi.yaml b/docs/openapi.yaml index ae403dad1..d7338dc77 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -12838,6 +12838,14 @@ components: target: type: string maxLength: 1000 + title: + type: string + maxLength: 1000 + description: The optional display() title. + description: + type: string + maxLength: 4000 + description: The optional display() description. detail: type: string maxLength: 16000 diff --git a/priv/python/albedo_trace.py b/priv/python/albedo_trace.py index 20a90deb6..0155cdc43 100644 --- a/priv/python/albedo_trace.py +++ b/priv/python/albedo_trace.py @@ -142,7 +142,9 @@ class Trace: entry: dict[str, object] = { "kind": "display", "target": label, - "detail": detail[:16000], + "title": title.strip()[:1000], + "description": description.strip()[:4000], + "detail": content[:16000], } self.activities[(f"display:{len(self.activities)}", label)] = entry diff --git a/src/albedo/daemon/api_digest.gleam b/src/albedo/daemon/api_digest.gleam index e44db9f7d..8c5940253 100644 --- a/src/albedo/daemon/api_digest.gleam +++ b/src/albedo/daemon/api_digest.gleam @@ -2,4 +2,4 @@ //// GET /server reports it so a client built from another contract can tell. pub const digest = - "6fc282e701173d89cf1e118d51a7a0111608362cf617a99d074438cb4360d988" + "f91eca9fd65605b520c9949e86bfcf91810939b666821f7cdd4f4e75151f1f7b" diff --git a/src/albedo/daemon/session.gleam b/src/albedo/daemon/session.gleam index fbd0d3a79..6fa970ce7 100644 --- a/src/albedo/daemon/session.gleam +++ b/src/albedo/daemon/session.gleam @@ -6096,7 +6096,9 @@ fn workspace_reset( prepared: None, context: session_state.unprepared(), ) - |> session_namespace.set_notice(Some(session_namespace.lost_notice)), + |> session_namespace.set_notice( + Some(session_state.KernelNotice(session_namespace.lost_notice, True)), + ), pending, True, ) diff --git a/src/albedo/daemon/session_namespace.gleam b/src/albedo/daemon/session_namespace.gleam index 1289204e8..5a9228c8e 100644 --- a/src/albedo/daemon/session_namespace.gleam +++ b/src/albedo/daemon/session_namespace.gleam @@ -494,7 +494,7 @@ pub fn restarted( <> ended_clauses(jobs, ended, "the restart"), ) let state = - set_notice(state, Some(notice)) + set_notice(state, Some(session_state.KernelNotice(notice, True))) |> noted(Some(lost_text(jobs, ended, None))) #(state, list.map(ended, fn(cell) { cell.0 })) } @@ -572,7 +572,7 @@ pub fn ready( fn adopted( state: session_state.State(message), kernel: runtime.Session, - notice: Option(String), + notice: Option(session_state.KernelNotice), text: Option(String), ) -> session_state.State(message) { session_state.State(..state, kernel: Some(kernel)) @@ -585,11 +585,11 @@ fn adopted( /// next step. A newer notice replaces one no turn has read yet. pub fn set_notice( state: session_state.State(message), - notice: Option(String), + notice: Option(session_state.KernelNotice), ) -> session_state.State(message) { let db = runtime.ledger(state.host) let _ = case notice { - Some(text) -> + Some(session_state.KernelNotice(text, _)) -> mail.post_input( db, input.Input( @@ -690,7 +690,14 @@ fn fallen_back( <> reason <> ". Fix that code; the session's next new kernel uses it once it starts.", ) - set_notice(state, Some(option.unwrap(state.notice, "") <> notice)) + set_notice( + state, + Some(session_state.KernelNotice( + option.unwrap(state.notice, session_state.KernelNotice("", False)).text + <> notice, + False, + )), + ) |> session_state.emit(view.note("daemon", fallback_text)) } } @@ -784,7 +791,11 @@ fn resumed( let state = session_state.State(..state, kernel: Some(kernel)) case running, held.rows { Running([], []), False -> state - _, _ -> set_notice(state, Some(resumed_notice(running))) + _, _ -> + set_notice( + state, + Some(session_state.KernelNotice(resumed_notice(running), False)), + ) } |> session_state.emit(view.note("daemon", resumed_text(running))) } @@ -842,7 +853,7 @@ fn upgraded( adopted( state, kernel, - Some(upgraded_notice(carried, ended)), + Some(session_state.KernelNotice(upgraded_notice(carried, ended), False)), Some(upgraded_text(carried, ended)), ) } @@ -926,8 +937,8 @@ fn revive( held: conversation.Held, ) -> session_state.State(message) { let cleared = case state.notice { - Some(notice) -> - notice == lost_notice || string.contains(notice, restarted_sentence) + Some(session_state.KernelNotice(_, True)) -> True + Some(_) -> False None -> False } // A lazy kernel's first boot comes after its turn is committed: a @@ -958,21 +969,29 @@ fn revive_saved( adopted( state, kernel, - Some(unreachable_notice(revived, jobs, ended)), + Some(session_state.KernelNotice( + unreachable_notice(revived, jobs, ended), + False, + )), Some(unreachable_text), ) Ok(saved) -> adopted( state, kernel, - restored_notice(saved, jobs, ended, loss_reason), + option.map(restored_notice(saved, jobs, ended, loss_reason), fn(text) { + session_state.KernelNotice(text, False) + }), restored_text(saved, jobs, ended, loss_reason), ) _ -> adopted( state, kernel, - Some(lost_notice_for(jobs, ended, loss_reason)), + Some(session_state.KernelNotice( + lost_notice_for(jobs, ended, loss_reason), + True, + )), Some(lost_text(jobs, ended, loss_reason)), ) } diff --git a/src/albedo/daemon/session_state.gleam b/src/albedo/daemon/session_state.gleam index e9db38dc1..46d90336e 100644 --- a/src/albedo/daemon/session_state.gleam +++ b/src/albedo/daemon/session_state.gleam @@ -55,6 +55,10 @@ pub type TitleJob { ) } +pub type KernelNotice { + KernelNotice(text: String, resets: Bool) +} + pub type State(message) { State( title_job: Option(TitleJob), @@ -105,7 +109,7 @@ pub type State(message) { /// What the kernel last told the model about itself (restored, lost, /// restarted), until a turn reads it; it waits in the inbox meanwhile /// (`session_namespace.set_notice`). - notice: Option(String), + notice: Option(KernelNotice), context: context_snapshot.Snapshot, pin: loop.Pin, /// Inputs evicted by the last prepared projection; the next live reload diff --git a/web/src/lib/FocusChat.svelte b/web/src/lib/FocusChat.svelte index 43266cdee..2dcebf94c 100644 --- a/web/src/lib/FocusChat.svelte +++ b/web/src/lib/FocusChat.svelte @@ -334,6 +334,7 @@ entryId={panel.entryId} index={panel.index} title={panel.title} + description={panel.description} detail={panel.detail} toolbar />{/key} diff --git a/web/src/lib/api.gen.d.ts b/web/src/lib/api.gen.d.ts index 9212f0309..e734d9c8f 100644 --- a/web/src/lib/api.gen.d.ts +++ b/web/src/lib/api.gen.d.ts @@ -4302,6 +4302,10 @@ export interface components { /** @enum {string} */ kind: "read" | "search" | "list" | "run" | "web" | "display" | "mcp" | "cua" | "artifact" | "skill"; target: string; + /** @description The optional display() title. */ + title?: string; + /** @description The optional display() description. */ + description?: string; /** @description What the person watching sees of the result, as markdown; a web search's answer and sources, or displayed content. */ detail?: string; /** @description How long the call took, when it ended while its cell's trace was open. */ diff --git a/web/src/lib/chat/Chat.svelte b/web/src/lib/chat/Chat.svelte index 0705c1bf1..09f492825 100644 --- a/web/src/lib/chat/Chat.svelte +++ b/web/src/lib/chat/Chat.svelte @@ -1649,6 +1649,7 @@ entryId={displayed.entryId} index={displayed.index} title={displayed.title} + description={displayed.description} detail={displayed.detail} toolbar />{/await} diff --git a/web/src/lib/chat/panel.ts b/web/src/lib/chat/panel.ts index 5c8ea9f68..3bc8c76d7 100644 --- a/web/src/lib/chat/panel.ts +++ b/web/src/lib/chat/panel.ts @@ -8,6 +8,7 @@ export type Panel = entryId: string; index: number; title: string; + description?: string; detail?: string; } | { kind: 'job'; job: string } diff --git a/web/src/lib/display.ts b/web/src/lib/display.ts index 2da7ebb6e..e9b3a788b 100644 --- a/web/src/lib/display.ts +++ b/web/src/lib/display.ts @@ -126,9 +126,14 @@ function codeFile(target: string): boolean { ); } -export function parseDisplay(target: string, detail: string): ParsedDisplay { +export function parseDisplay( + target: string, + detail: string, + description = '', +): ParsedDisplay { const trimmed = target.trim() || 'display'; - const diff = splitDiff(trimmed, detail); + const content = description ? `${description}\n\n${detail}` : detail; + const diff = splitDiff(trimmed, content); if (diff) { const fallback = codeFile(trimmed) ? trimmed : 'display.patch'; const files = splitPatchFiles(diff.diff, fallback); @@ -142,9 +147,9 @@ export function parseDisplay(target: string, detail: string): ParsedDisplay { }; } if (codeFile(trimmed)) { - const { header, body } = splitCodeHeader(trimmed, detail); + const { header, body } = splitCodeHeader(trimmed, content); return { header, body, natural: 'code', fileName: trimmed, files: [] }; } - const { header, body } = splitCodeHeader(trimmed, detail); + const { header, body } = splitCodeHeader(trimmed, content); return { header, body, natural: 'markdown', fileName: trimmed, files: [] }; } diff --git a/web/src/lib/transcript.svelte.ts b/web/src/lib/transcript.svelte.ts index 37257343e..54d36c8b0 100644 --- a/web/src/lib/transcript.svelte.ts +++ b/web/src/lib/transcript.svelte.ts @@ -125,6 +125,7 @@ export interface Displayed { entryId: string; index: number; title: string; + description: string; detail: string; } @@ -140,7 +141,8 @@ export function displayedIn( { entryId, index: index++, - title: oneLine(activity.target) || 'content', + title: activity.title || oneLine(activity.target) || 'content', + description: activity.description ?? '', detail: activity.detail ?? '', }, ] diff --git a/web/src/lib/views/DisplayView.svelte b/web/src/lib/views/DisplayView.svelte index 60e1cc3e1..a883320d6 100644 --- a/web/src/lib/views/DisplayView.svelte +++ b/web/src/lib/views/DisplayView.svelte @@ -19,6 +19,7 @@ index = 0, title = '', detail: initialDetail, + description = '', windowId = `display:${sessionId}:${entryId}:${index}`, chosen = $bindable<'rendered' | 'raw' | null>(null), toolbar = false, @@ -31,6 +32,7 @@ index?: number; title?: string; detail?: string; + description?: string; windowId?: string; chosen?: 'rendered' | 'raw' | null; toolbar?: boolean; @@ -59,7 +61,7 @@ const detail = $derived( initialDetail !== undefined ? initialDetail : (loadedDetail ?? ''), ); - const parsed = $derived(parseDisplay(target, detail)); + const parsed = $derived(parseDisplay(target, detail, description)); const mode = $derived( chosen === 'raw' ? 'code'