fix(tui): hide editor context from transcript (#36264)
This commit is contained in:
parent
accaa792d8
commit
41d0a9f010
2 changed files with 22 additions and 19 deletions
|
|
@ -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
|
- 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.
|
- 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 `try`/`catch` where possible
|
||||||
- Avoid using the `any` type
|
- Avoid using the `any` type
|
||||||
- Use Bun APIs when possible, like `Bun.file()`
|
- Use Bun APIs when possible, like `Bun.file()`
|
||||||
|
|
|
||||||
|
|
@ -1044,22 +1044,7 @@ export function Prompt(props: PromptProps) {
|
||||||
// Capture mode before it gets reset
|
// Capture mode before it gets reset
|
||||||
const currentMode = store.mode
|
const currentMode = store.mode
|
||||||
const editorSelection = editorContext()
|
const editorSelection = editorContext()
|
||||||
const editorParts =
|
const pendingEditorSelection = editorSelection && editor.labelState() === "pending" ? editorSelection : undefined
|
||||||
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,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: []
|
|
||||||
|
|
||||||
if (store.mode === "shell") {
|
if (store.mode === "shell") {
|
||||||
move.startSubmit()
|
move.startSubmit()
|
||||||
|
|
@ -1135,10 +1120,27 @@ export function Prompt(props: PromptProps) {
|
||||||
return false
|
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
|
const error = await sdk.api.session
|
||||||
.prompt({
|
.prompt({
|
||||||
sessionID,
|
sessionID,
|
||||||
text: [...editorParts.map((part) => part.text), inputText].filter(Boolean).join("\n\n"),
|
text: inputText,
|
||||||
files: store.prompt.files,
|
files: store.prompt.files,
|
||||||
agents: store.prompt.agents,
|
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" })
|
toast.show({ title: "Failed to send prompt", message: errorMessage(error), variant: "error" })
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (editorParts.length > 0) editor.markSelectionSent()
|
if (pendingEditorSelection) editor.markSelectionSent()
|
||||||
}
|
}
|
||||||
history.append({
|
history.append({
|
||||||
...store.prompt,
|
...store.prompt,
|
||||||
|
|
@ -1163,7 +1165,7 @@ export function Prompt(props: PromptProps) {
|
||||||
|
|
||||||
// temporary hack to make sure the message is sent
|
// temporary hack to make sure the message is sent
|
||||||
if (!props.sessionID) {
|
if (!props.sessionID) {
|
||||||
if (editorParts.length > 0) editor.preserveSelectionFromNewSession()
|
if (pendingEditorSelection) editor.preserveSelectionFromNewSession()
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
route.navigate({
|
route.navigate({
|
||||||
type: "session",
|
type: "session",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue