Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

## Unreleased

- Desktop: changing the run, mode or redaction in the export panel clears the old preview at once and leaves `Copy JSON` and `Save…` disabled until the new selection builds successfully; a late result cannot replace another selection's preview or its feedback (#3834, fixes #3829). Thanks to @AIFlowML.

- Web: the engine address may be an OpenAI base URL ending in `/v1` as well as a server root; health, the relay and Connect derive the server root with `engine_root` and append the API suffix once, and settings keeps the supplied address so a reverse-proxy prefix ending in `/v1` survives a reload (#3831, fixes #3830). Thanks to @AIFlowML.

- Desktop: the library scan uses four convolution taps for Qwen3.5-2B, so the supported checkpoint is offered instead of being refused at scan time; a checkpoint with the old value still gets a geometry refusal (#3768). Thanks to @AIFlowML.
Expand Down
129 changes: 129 additions & 0 deletions app/src/components/ExportPanel.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import assert from 'node:assert/strict'
import { find, harness, jsx, load, settle, text } from './reading/reading-test-harness'

type Request = { threadId: string; options: { mode: string; redact: boolean } }
const hook = harness()
hook.hooks.useCallback = (callback: unknown) => hook.hooks.useRef(callback).current
const builds: (Request & { finish: (label: string) => void; fail: () => void })[] = []
const saves: (Request & { finish: () => void })[] = []
const copies: { json: string; finish: () => void }[] = []
const windowFixture = new EventTarget()
Object.defineProperty(globalThis, 'window', { configurable: true, value: windowFixture })
Object.defineProperty(globalThis, 'navigator', { configurable: true, value: {
clipboard: { writeText: (json: string) => new Promise<void>((finish) => copies.push({ json, finish })) },
} })

const api = {
buildExport: (threadId: string, options: Request['options']) => new Promise((resolve, reject) => {
builds.push({
threadId,
options,
finish: (label) => resolve({ json: label, bundle: {
thread: { title: label },
stats: { messages: 0, toolCalls: 0, diffs: 0, denied: 0, errors: 0 },
redactionReport: [],
} }),
fail: () => reject(new Error('synthetic build failure')),
})
}),
saveExport: (threadId: string, options: Request['options']) => new Promise((resolve) => {
saves.push({ threadId, options, finish: () => resolve({ saved: true }) })
}),
}
const { ExportPanel } = load('src/components/ExportPanel.tsx', {
react: hook.hooks, 'react/jsx-runtime': jsx,
clsx: (...classes: string[]) => classes.filter(Boolean).join(' '),
'../lib/ipc': { api }, '../lib/icons': { Icon: () => null },
})
const render = () => hook.render(() => ExportPanel())
const open = () => windowFixture.dispatchEvent(new CustomEvent('vontra:export', { detail: { threadId: 'test-run' } }))
const button = (tree: ReturnType<typeof render>, label: string) => find(tree, (node) => node.type === 'button' && text(node) === label)
const setRedact = (checked: boolean) => find(render(), (node) => node.type === 'input').props.onChange({ target: { checked } })
const preview = (tree: ReturnType<typeof render>) => text(find(tree, (node) => node.type === 'pre'))
const assertUnavailable = (tree: ReturnType<typeof render>) => {
assert.equal(button(tree, 'Copy JSON').props.disabled, true)
assert.equal(button(tree, 'Save…').props.disabled, true)
}

render()
hook.flush()
open()
render()
hook.flush()
builds[0].finish('first preview')
await settle()
const ready = render()
assert.equal(preview(ready), 'first preview')
assert.equal(button(ready, 'Copy JSON').props.disabled, false)
assert.equal(button(ready, 'Save…').props.disabled, false)
const copy = button(ready, 'Copy JSON').props.onClick
const save = button(ready, 'Save…').props.onClick
const copying = copy()
const saving = save()
assert.equal(copies[0].json, 'first preview')
assert.deepEqual(saves[0].options, { mode: 'full', redact: true })

setRedact(false)
const staleCopy = copy()
const staleSave = save()
const pending = render()
assert.equal(preview(pending), 'Building…')
assert.equal(text(pending).includes('first preview'), false)
assertUnavailable(pending)
await Promise.all([staleCopy, staleSave])
assert.equal(copies.length, 1)
assert.equal(saves.length, 1)
hook.flush()
assert.deepEqual(builds[1].options, { mode: 'full', redact: false })
setRedact(true)
render()
hook.flush()
assert.deepEqual(builds[2].options, { mode: 'full', redact: true })
copies[0].finish()
saves[0].finish()
await Promise.all([copying, saving])
assert.equal(text(render()).includes('Saved'), false)
assertUnavailable(render())
builds[2].finish('replacement preview')
await settle()
builds[1].fail()
await settle()
assert.equal(preview(render()), 'replacement preview')

button(render(), 'Share packet').props.onClick()
render()
hook.flush()
assert.deepEqual(builds[3].options, { mode: 'share', redact: true })
builds[3].fail()
await settle()
assert.equal(preview(render()), 'Nothing to export.')
assertUnavailable(render())
button(render(), 'Full run').props.onClick()
render()
hook.flush()
button(render(), 'esc').props.onClick()
assert.equal(render(), null)
hook.flush()
open()
assertUnavailable(render())
hook.flush()
assert.equal(builds[5].threadId, 'test-run')
builds[4].finish('closed preview')
await settle()
assert.equal(preview(render()), 'Building…')
assertUnavailable(render())
builds[5].finish('reopened preview')
await settle()
const reopened = render()
assert.equal(preview(reopened), 'reopened preview')
const reopenedCopy = button(reopened, 'Copy JSON').props.onClick()
const reopenedSave = button(reopened, 'Save…').props.onClick()
assert.equal(copies[1].json, 'reopened preview')
assert.equal(saves[1].threadId, 'test-run')
assert.deepEqual(saves[1].options, { mode: 'full', redact: true })
copies[1].finish()
saves[1].finish()
await Promise.all([reopenedCopy, reopenedSave])
assert.ok(button(render(), 'Copied'))
assert.equal(text(render()).includes('Saved'), true)
hook.cleanup()
75 changes: 48 additions & 27 deletions app/src/components/ExportPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useAuthoredText } from '../lib/preferences/useAuthoredText'
import { authoredText } from '../lib/preferences/language-packs'
import { useStore as useLocaleStore } from '../lib/store'
import { useEffect, useRef, useState } from 'react'
import { useCallback, useEffect, useRef, useState } from 'react'
import clsx from 'clsx'
import { api } from '../lib/ipc'
import { Icon, type IconName } from '../lib/icons'
Expand All @@ -17,40 +17,52 @@ const MODES: { id: ExportMode; label: string; icon: IconName; blurb: string }[]
{ id: 'eval', get label() { return authoredText(useLocaleStore.getState().settings?.uiPreferences?.locale, "Eval replay") }, icon: 'spark', blurb: 'Replay skeleton — prompts, tool calls and outcomes only; reasoning dropped, anonymized.' },
]

type ExportSelection = { threadId: string; mode: ExportMode; redact: boolean }
type ExportPreview = { selection: ExportSelection; result: ExportResult | null }

export function ExportPanel() {
const tx = useAuthoredText()
const [threadId, setThreadId] = useState<string | null>(null)
const [mode, setMode] = useState<ExportMode>('full')
const [redact, setRedact] = useState(true)
const [result, setResult] = useState<ExportResult | null>(null)
const [building, setBuilding] = useState(false)
const [selection, setSelection] = useState<ExportSelection | null>(null)
const [preview, setPreview] = useState<ExportPreview | null>(null)
const [saved, setSaved] = useState<string | null>(null)
const [copied, setCopied] = useState(false)
const reqRef = useRef(0)
const selectionRef = useRef(selection)
const choose = useCallback((next: ExportSelection | null) => {
selectionRef.current = next
setSelection(next)
setPreview(null)
setSaved(null)
setCopied(false)
}, [])

useEffect(() => {
const onOpen = (e: Event) => {
const id = (e as CustomEvent).detail?.threadId
if (typeof id !== 'string') return
setThreadId(id); setMode('full'); setRedact(true); setSaved(null); setCopied(false)
if (typeof id !== 'string' || !id) return
choose({ threadId: id, mode: 'full', redact: true })
}
window.addEventListener('vontra:export', onOpen as EventListener)
return () => window.removeEventListener('vontra:export', onOpen as EventListener)
}, [])
}, [choose])

// Rebuild the bundle whenever the target or options change (request-id guards races).
useEffect(() => {
if (!threadId) { setResult(null); return }
const req = ++reqRef.current
setBuilding(true); setSaved(null); setCopied(false)
if (!selection) return
const { threadId, mode, redact } = selection
let active = true
const finish = (result: ExportResult | null) => {
if (active && selectionRef.current === selection) setPreview({ selection, result })
}
api.buildExport(threadId, { mode, redact })
.then((r) => { if (req === reqRef.current) setResult(r) })
.catch(() => { if (req === reqRef.current) setResult(null) })
.finally(() => { if (req === reqRef.current) setBuilding(false) })
}, [threadId, mode, redact])

if (!threadId) return null
const close = () => setThreadId(null)
.then(finish, () => finish(null))
return () => { active = false }
}, [selection])

if (!selection) return null
const { threadId, mode, redact } = selection
const currentPreview = preview?.selection === selection ? preview : null
const building = currentPreview === null
const result = currentPreview?.result
const close = () => { if (selectionRef.current === selection) choose(null) }
const bundle = result?.bundle
const totalRedactions = bundle?.redactionReport.reduce((n, r) => n + r.count, 0) ?? 0
const evidence = bundle?.evidence
Expand All @@ -59,13 +71,18 @@ export function ExportPanel() {
: 0

const onCopy = async () => {
if (!result) return
try { await navigator.clipboard.writeText(result.json); setCopied(true); setTimeout(() => setCopied(false), 1600) } catch { /* clipboard blocked */ }
if (!result || selectionRef.current !== selection) return
try {
await navigator.clipboard.writeText(result.json)
if (selectionRef.current !== selection) return
setCopied(true)
setTimeout(() => { if (selectionRef.current === selection) setCopied(false) }, 1600)
} catch { /* clipboard blocked */ }
}
const onSave = async () => {
if (!threadId) return
if (!result || selectionRef.current !== selection) return
const res = await api.saveExport(threadId, { mode, redact })
if (res.saved) setSaved(res.path ?? 'saved')
if (res.saved && selectionRef.current === selection) setSaved(res.path ?? 'saved')
}

return (
Expand All @@ -86,7 +103,9 @@ export function ExportPanel() {
{/* mode picker */}
<div className="grid grid-cols-3 gap-2">
{MODES.map((m) => (
<button key={m.id} onClick={() => setMode(m.id)} className={clsx('flex flex-col gap-1 rounded-lg border px-2.5 py-2 text-left transition-colors', mode === m.id ? 'border-ink-3 bg-ink-5' : 'border-line hover:border-line-strong')}>
<button key={m.id} onClick={() => {
if (m.id !== mode && selectionRef.current === selection) choose({ ...selection, mode: m.id })
}} className={clsx('flex flex-col gap-1 rounded-lg border px-2.5 py-2 text-left transition-colors', mode === m.id ? 'border-ink-3 bg-ink-5' : 'border-line hover:border-line-strong')}>
<span className="flex items-center gap-1.5 text-[13px] font-medium text-ink"><Icon name={m.icon} size={13} className="text-ink-3" />{m.label}</span>
</button>
))}
Expand All @@ -95,7 +114,9 @@ export function ExportPanel() {

{/* redaction control */}
<label className="mt-3 flex items-start gap-2.5 rounded-lg border border-line bg-card-2 px-3 py-2.5">
<input type="checkbox" checked={redact} onChange={(e) => setRedact(e.target.checked)} className="mt-0.5 accent-[var(--ink)]" />
<input type="checkbox" checked={redact} onChange={(e) => {
if (selectionRef.current === selection) choose({ ...selection, redact: e.target.checked })
}} className="mt-0.5 accent-[var(--ink)]" />
<span className="min-w-0 flex-1">
<span className="flex items-center gap-1.5 text-[13px] font-medium text-ink"><Icon name="shield" size={13} className={redact ? 'text-positive' : 'text-warn'} />{tx("Redact secrets & PII")}</span>
<span className="mt-0.5 block text-[12px] leading-relaxed text-ink-3">{redact ? tx("Scans every value for API keys, tokens, private keys, JWTs, emails and home paths before export.") : tx("Off — the bundle may contain raw secrets. Only disable for a local, trusted destination.")}</span>
Expand Down
Loading