refactor(tui): simplify compact slash handling

This commit is contained in:
Shoubhit Dash 2026-05-21 16:33:59 +05:30
parent 4f191187b3
commit b5c6763d11
3 changed files with 18 additions and 28 deletions

View file

@ -543,19 +543,21 @@ export function Autocomplete(props: {
),
)
function insertSlashCommand(name: string) {
const newText = `/${name} `
const cursor = props.input().logicalCursor
props.input().deleteRange(0, 0, cursor.row, cursor.col)
props.input().insertText(newText)
props.input().cursorOffset = Bun.stringWidth(newText)
}
const commands = createMemo((): AutocompleteOption[] => {
const results: AutocompleteOption[] = slashes().map((command) => {
const name = command.display.trim().slice(1)
if (name !== "compact") return command
return {
...command,
onSelect: () => {
const newText = `/${name} `
const cursor = props.input().logicalCursor
props.input().deleteRange(0, 0, cursor.row, cursor.col)
props.input().insertText(newText)
props.input().cursorOffset = Bun.stringWidth(newText)
},
onSelect: () => insertSlashCommand(name),
}
})
@ -565,13 +567,7 @@ export function Autocomplete(props: {
results.push({
display: "/" + serverCommand.name + label,
description: serverCommand.description,
onSelect: () => {
const newText = "/" + serverCommand.name + " "
const cursor = props.input().logicalCursor
props.input().deleteRange(0, 0, cursor.row, cursor.col)
props.input().insertText(newText)
props.input().cursorOffset = Bun.stringWidth(newText)
},
onSelect: () => insertSlashCommand(serverCommand.name),
})
}

View file

@ -1145,18 +1145,12 @@ export function Prompt(props: PromptProps) {
setStore("mode", "normal")
} else if (isCompactSlash(inputText)) {
const instructions = slashArguments(inputText).trim()
const payload: Parameters<typeof sdk.client.session.summarize>[0] & { $body_instructions?: string } = instructions
? {
sessionID,
modelID: selectedModel.modelID,
providerID: selectedModel.providerID,
$body_instructions: instructions,
}
: {
sessionID,
modelID: selectedModel.modelID,
providerID: selectedModel.providerID,
}
const payload: Parameters<typeof sdk.client.session.summarize>[0] & { $body_instructions?: string } = {
sessionID,
modelID: selectedModel.modelID,
providerID: selectedModel.providerID,
...(instructions ? { $body_instructions: instructions } : {}),
}
void sdk.client.session.summarize(payload)
} else if (
inputText.startsWith("/") &&

View file

@ -133,7 +133,7 @@ function buildPrompt(input: { previousSummary?: string; context: string[] }) {
return [anchor, SUMMARY_TEMPLATE, ...input.context].join("\n\n")
}
function withInstructions(prompt: string, instructions: string | undefined) {
function appendInstructions(prompt: string, instructions: string | undefined) {
const trimmed = instructions?.trim()
if (!trimmed) return prompt
return [prompt, "Additional user instructions for this compaction:", trimmed].join("\n\n")
@ -407,7 +407,7 @@ export const layer = Layer.effect(
{ sessionID: input.sessionID },
{ context: [], prompt: undefined },
)
const nextPrompt = withInstructions(
const nextPrompt = appendInstructions(
compacting.prompt ?? buildPrompt({ previousSummary, context: compacting.context }),
compactionPart?.instructions,
)