fix(tui): hide editor context from transcript (#36264)

This commit is contained in:
Kit Langton 2026-07-10 11:33:04 -04:00 committed by GitHub
parent accaa792d8
commit 41d0a9f010
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 19 deletions

View file

@ -27,6 +27,7 @@ Never bypass Git hooks. Do not use `--no-verify` or otherwise disable, skip, or
- Keep things in one function unless composable or reusable
- Do not extract single-use helpers preemptively. Inline the logic at the call site unless the helper is reused, hides a genuinely complex boundary, or has a clear independent name that improves the caller.
- Before adding complexity for a speculative or vanishingly unlikely race or security edge case, explain the concrete failure mode, likelihood, and complexity cost to the user and get their buy-in. Do not silently expand scope for theoretical robustness.
- Avoid `try`/`catch` where possible
- Avoid using the `any` type
- Use Bun APIs when possible, like `Bun.file()`

View file

@ -1044,22 +1044,7 @@ export function Prompt(props: PromptProps) {
// Capture mode before it gets reset
const currentMode = store.mode
const editorSelection = editorContext()
const editorParts =
editorSelection && editor.labelState() === "pending"
? [
{
type: "text" as const,
text: formatEditorContext(editorSelection),
synthetic: true,
metadata: {
kind: "editor_context",
source: editorSelection.source ?? "editor",
filePath: editorSelection.filePath,
ranges: editorSelection.ranges,
},
},
]
: []
const pendingEditorSelection = editorSelection && editor.labelState() === "pending" ? editorSelection : undefined
if (store.mode === "shell") {
move.startSubmit()
@ -1135,10 +1120,27 @@ export function Prompt(props: PromptProps) {
return false
}
}
if (pendingEditorSelection) {
// Keep editor context hidden while admitting it before the corresponding user prompt.
const error = await sdk.api.session
.synthetic({
sessionID,
text: formatEditorContext(pendingEditorSelection),
resume: false,
})
.then(
() => undefined,
(error) => error,
)
if (error) {
toast.show({ title: "Failed to send editor context", message: errorMessage(error), variant: "error" })
return false
}
}
const error = await sdk.api.session
.prompt({
sessionID,
text: [...editorParts.map((part) => part.text), inputText].filter(Boolean).join("\n\n"),
text: inputText,
files: store.prompt.files,
agents: store.prompt.agents,
})
@ -1150,7 +1152,7 @@ export function Prompt(props: PromptProps) {
toast.show({ title: "Failed to send prompt", message: errorMessage(error), variant: "error" })
return false
}
if (editorParts.length > 0) editor.markSelectionSent()
if (pendingEditorSelection) editor.markSelectionSent()
}
history.append({
...store.prompt,
@ -1163,7 +1165,7 @@ export function Prompt(props: PromptProps) {
// temporary hack to make sure the message is sent
if (!props.sessionID) {
if (editorParts.length > 0) editor.preserveSelectionFromNewSession()
if (pendingEditorSelection) editor.preserveSelectionFromNewSession()
setTimeout(() => {
route.navigate({
type: "session",