feat(core): compact v2 session context (#30986)

This commit is contained in:
Kit Langton
2026-06-05 13:17:23 -04:00
committed by GitHub
parent a7bd1cd0d0
commit beae7290f3
26 changed files with 571 additions and 298 deletions
@@ -23,13 +23,6 @@ function ownedAssistant(messages: SessionMessage[], messageID: string) {
return message?.type === "assistant" ? message : undefined
}
function activeCompaction(messages: SessionMessage[]) {
const index = messages.findIndex((message) => message.type === "compaction")
if (index < 0) return
const compaction = messages[index]
return compaction?.type === "compaction" ? compaction : undefined
}
function activeShell(messages: SessionMessage[], callID: string) {
const index = messages.findIndex((message) => message.type === "shell" && message.callID === callID)
if (index < 0) return
@@ -410,32 +403,21 @@ export const { use: useSyncV2, provider: SyncProviderV2 } = createSimpleContext(
})
break
case "session.next.retried":
break
case "session.next.compaction.started":
case "session.next.compaction.delta":
break
case "session.next.compaction.ended":
update(event.properties.sessionID, (draft) => {
prepend(draft, {
id: event.properties.messageID,
type: "compaction",
reason: event.properties.reason,
summary: "",
summary: event.properties.text,
recent: event.properties.recent,
time: { created: event.properties.timestamp },
})
})
break
case "session.next.compaction.delta":
update(event.properties.sessionID, (draft) => {
const match = activeCompaction(draft)
if (match) match.summary += event.properties.text
})
break
case "session.next.compaction.ended":
update(event.properties.sessionID, (draft) => {
const match = activeCompaction(draft)
if (!match) return
match.summary = event.properties.text
match.include = event.properties.include
})
break
}
}
@@ -231,7 +231,7 @@ function ShellMessage(props: { message: SessionMessageShell }) {
}
function CompactionMessage(props: { message: SessionMessageCompaction }) {
const { theme, syntax } = useTheme()
const { theme } = useTheme()
return (
<box
marginTop={1}
@@ -240,23 +240,7 @@ function CompactionMessage(props: { message: SessionMessageCompaction }) {
titleAlignment="center"
borderColor={theme.borderActive}
flexShrink={0}
>
<Show when={props.message.summary}>
{(summary) => (
<box paddingLeft={3} paddingTop={1}>
<code
filetype="markdown"
drawUnstyledText={false}
streaming={false}
syntaxStyle={syntax()}
content={summary().trim()}
conceal={true}
fg={theme.text}
/>
</box>
)}
</Show>
</box>
/>
)
}