* fix(ai): keep dropped AI chats recoverable with dangling marking and /rebind
Closing a member terminal or dissolving a workspace used to clear the
chat's active pointer, making it invisible (scope rank 0) and
unrecoverable from the UI even though the record survived in storage.
- orphan cleanup now marks dropped chats `scopeDangling: true` and keeps
record + active pointer intact; the flag clears when the target
returns or the chat is rebound
- `/chats` lists dangling chats with a numbered inline affordance and
hint line
- new `/rebind <n>` panel action rewrites `scope` to the panel's current
scope, clears the marker and restores the active pointer
- i18n keys added for en / zh-CN / zh-TW / es / ru
Stacked on #4018. Refs #4015 (R2).
* fix(workspace): reuse existing workspace id when merging tabs with a workspace
createWorkspaceFromSessions silently no-opped when either merged tab
already belonged to a workspace (e.g. dragging a workspace pane onto a
standalone terminal), and the older dissolve->recreate behavior
regenerated the id that workspace-scoped AI chats bind to.
When one of the merged tabs has a workspace, the orphan tab now joins
that existing workspace (pane inserted next to the anchor session, tab
slot collapsed), so workspace-scoped chat bindings survive. Merging two
standalone tabs still creates a fresh workspace.
Stacked on #4018. Refs #4015 (R3).
* fix(ai): persist cleaned active map on dangling chat rebind
rebindSessionScope was updating React state to drop stale old-scope
pointers, then rebuilding localStorage from the pre-rebind snapshot and
resurrecting them. Persist the same cleaned map via rebindActiveSessionMap.
* fix(ai): persist rebind map inside setState; wire backup actions on terminal panel
- Write cleaned active-session map from inside the rebind updater so a
deferred React setState cannot skip snapshot/localStorage persistence.
- Pass exportSessionsBackup/importSessionsBackup through TerminalLayerSupport
and include them in AI_CHAT_SIDE_PANEL_AI_STATE_KEYS so history-drawer
backup buttons work on the normal terminal path.
* fix(ai): guard backup restore races and use app-wide live targets for /chats
- Skip restore when in-memory sessions already exist; apply snapshot,
storage write, and AI state emit atomically inside the empty-state path
so peer useAIState instances see the restore.
- Thread validAIScopeTargetIds into AIChatSidePanel as liveScopeTargetIds
so /chats does not mark chats bound to other open terminals as dangling.
* fix(ai): open rebound chat in panel view and refresh /chats listing
- rebindSessionScope also sets the panel view to the rebound session so an
existing draft/other chat does not keep hiding the recovery.
- After /rebind, rewrite the stored listing instead of rebuilding from the
stale render so the chat is no longer offered as dangling.
* fix(workspace): invert join split when dragged pane owns workspace; refresh /chats titles
- When merging a workspace-owned dragged pane onto a standalone tab, the
orphan is inserted — invert the drop position so the previewed side matches.
- Compare workspaces in AIChatSidePanel memo so /chats picks up renames.
* fix(ai): validate live sessions array on boot; mark imported orphans dangling
- Reject parseable non-array store values (e.g. {}) via readLiveSessionsArray
so boot restore is not blocked by a corrupt-but-truthy value.
- After manual import, re-run orphan cleanup with the last known live target
set so chats bound to closed scopes become dangling and /rebind-able.
* fix(ai): merge imported sessions before orphan cleanup
Apply import merge to the snapshot/ref synchronously, then run dangling
marking, so a deferred setState cannot let cleanup rewrite over the import.
* fix(ai): mark restored/imported orphans dangling even with no live targets
Restore and import do not change live terminals/workspaces, so the orphan
cleanup effect will not re-run. Always call cleanup against the last known
live target set after those paths — an empty set is a valid observed state
(nothing mounted), not an unavailable snapshot — so chats bound to missing
scopes become dangling and /chats can offer /rebind.
* fix(ai): apply backup restore synchronously before dangling cleanup
Do not gate restore + orphan marking on a setState updater having run.
A deferred updater left didRestore false, skipped cleanup, and could leave
restored chats with missing scopes unmarked and unrebindable from /chats.
* fix(ai): complete /rebind from a partial slash picker selection
Selecting Rebind after typing `/re` left the composer unchanged, so a
following number became `/re 1` and could be sent to the agent. Replace the
slash query with `/rebind ` the same way Rename does.
* fix(ai): replace hostIds on rebind; skip non-array backup generations
- Rebind builds a fresh destination scope (including hostIds from the
panel) instead of spreading the old scope, so history matching follows
the new terminal/workspace host.
- readLatestGeneration treats valid JSON that is not a session array as
unusable and continues to older generations, matching corrupt skips.
* fix(ai): revalidate dangling chat before /rebind from stale /chats listing
Skip rebind when the cached entry is deleted or already bound to a live
scope; drop stale listing entries so a second panel cannot steal the chat.
* fix(ai): reject malformed /rebind numbers
Require the entire trimmed argument to be digits so /rebind 1foo and
/rebind 1.5 show usage instead of silently targeting index 1.
---------
Co-authored-by: binaricat <binaricat@users.noreply.github.com>
Co-authored-by: 陈大猫 <16399091+binaricat@users.noreply.github.com>
* feat(ai): add /rename and /chats slash commands plus a session durability layer
Panel slash commands (#4015 feedback):
- /rename <title> renames the current chat via updateSessionTitle; the
command is intercepted in ChatInput's system-command branch and never
reaches the agent. Empty title shows a usage hint. The history drawer
gains an inline rename affordance.
- /chats renders a dismissible system-style note listing the panel's
visible chats (title / agent backend / workspace-or-terminal scope with
a dangling marker / relative last-active time; current chat marked).
Deliberately not named /resume: session.resume already means
flow-recovery-after-cancel. Listing logic is pure (aiChatsListing.ts)
so a future rebind action can attach per-entry actions.
- i18n keys added for en/es/ru/zh-CN/zh-TW.
Durability layer (additive; cleanup/eviction semantics untouched):
- Every successful store write schedules a debounced (~2s) mirror of the
exact persisted JSON to {userData}/ai-sessions-backup/ through a new
aiSessionsBackupBridge: atomic temp+rename writes, 5 rolling
generations, timestamped names.
- On boot, a missing/empty live store is restored from the newest
parseable backup generation. The asymmetry is deliberate: empty ->
restore, non-empty -> leave alone, so restored data can never
resurrect explicitly deleted chats.
- Manual export/import in the history drawer via real file dialogs
(fixed-path fallback where dialogs are unavailable); import merges by
id with newer updatedAt winning.
Tests: bridge rotation/corruption/rejection, restore decisions, merge
semantics, debounce throttle, mirror-on-write, slash interception and
/chats listing seams. eslint clean; tsc unchanged vs baseline.
* fix(ai): repair sessions backup IPC and restore/import guards
- Forward write/export payloads through preload unchanged so the main
bridge receives a string json (was double-wrapped → invalid-json).
- Restore from disk only when the live store is missing or corrupt;
treat a valid [] as an intentional clear. Flush the debounced mirror
on beforeunload so deletions land before quit.
- Require id + messages[] + finite updatedAt when parsing backup/
import entries so malformed objects cannot reach pruneSessionsForStorage.
Co-authored-by: Netcatty Maintainer <binaricat@users.noreply.github.com>
* fix(ai): complete /rename from partial slash and harden import shape
- Selecting Rename from the slash picker replaces the active slash token
with `/rename ` so a following title is intercepted, not sent to the agent.
- parseBackupSessions also requires title, agentId, and a scope object with
a string type before accepting an imported/backup entry.
Co-authored-by: Netcatty Maintainer <binaricat@users.noreply.github.com>
* fix(ai): validate backup messages and skip prune on synced restore
- Drop backup/import sessions whose messages lack id/role/timestamp.
- When cloud AI-session sync is enabled, restore parsed sessions without
pruneSessionsForStorage so local retention cannot truncate synced history.
Co-authored-by: Netcatty Maintainer <binaricat@users.noreply.github.com>
* fix(ai): export prepareRestoredSessions helper
Missed in the previous commit; required by useAIState boot restore and tests.
Co-authored-by: Netcatty Maintainer <binaricat@users.noreply.github.com>
* fix(ai): require message content on backup import; raise disk cap to 64MB
* fix(ai): normalize corrupt sessions store to [] before boot restore
* fix(ai): skip non-array backup generations when reading latest
* fix(ai): emit sessions change on backup restore; skip unusable gens
* fix(ai): treat empty backup gen as wipe; align gen usability with parser
* fix(ai): seed backup on boot for live store; report durable import count
* fix(ai): emit sessions change after backup import
* docs(ai): clarify sessions backup recovers in-profile store only
---------
Co-authored-by: binaricat <binaricat@users.noreply.github.com>
Codex P2: switching to a catalog model dropped context_length, so
Catty budgeted 128k instead of the advertised window. Keep the
metadata on picker models and write it to modelContextWindows.
Give Catty a two-column provider/model menu in the composer, add search
plus recent/pinned models, and move thinking effort onto its own chip
so Claude, Codex, Grok, and Catty share the same compact controls.
Closes#2137Closes#2637Closes#1884
Gate /compact behind canCompact so the composer is not cleared as a
silent no-op, hide the usage ring until a real context snapshot arrives,
and summarize only the UI head that the persisted compaction boundary
will drop. Drop unused clearSessionMessages surface and add slash-command
regression tests.
Expose snippets and automation scripts to Catty, MCP, and CLI with full run lifecycle, vault bridge CRUD, and clickable tool-result cards in the chat message list.
Co-authored-by: Cursor <cursoragent@cursor.com>
* feat(ai): unify capability registry, harness tools, and agent runtime
Centralize MCP/CLI/Catty tool surfaces in the capability catalog with codegen,
move Catty-only harness tools into catalog with local execution, converge
mcpServerBridge builtin dispatch via registry, and wire AgentRuntime with
vault bridge, permission grants, and Round 2 catalog parity.
Co-authored-by: Cursor <cursoragent@cursor.com>
* feat(ai): vault host tools, artifact cards, and external agent vault guidance
Unify vault host create/import with capability RPC routing, add chat artifact cards with Vault navigation, and align external MCP agents with Catty rules so host creation never falls back to Vault Notes.
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix(ai): address Bugbot findings for streaming, vault bridge, and grants
Clear Catty streaming by chat sessionId, read latest vault state via getters on agent mutations, and stack grant persisters so unmounting one AI panel does not break others.
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix(vault): clear pending openNoteId after chat navigation focus
NotesManager notifies VaultView once the one-shot openNoteId request is applied so the id does not stick for the rest of the session.
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix(vault): serialize vault agent IPC mutations to prevent lost writes
Queue vault agent bridge handlers so concurrent hosts.create or note.create tool calls cannot overwrite each other via stale read-modify-write snapshots.
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix(vault): keep synchronous vault snapshot for agent IPC reads
Mirror hosts, notes, and groups in a ref updated immediately on agent writes so serialized mutations see the latest state before React re-renders.
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix(ai): sync Catty MCP sessions and defer runtime cleanup on delete
Register terminal sessions with the main process before Catty tool calls, and clear ToolOutputStore only after stopping an active turn when deleting a chat session.
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix(ai): avoid deleting a newer abort controller on late stop
Only remove the session abort-controller entry when stop finishes if it still refers to the controller that was stopped.
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix(ai): sync vault snapshot on render and await active turn on stop
Refresh vault agent reads when React props change without clobbering in-flight agent writes, and wait for runTurn to finish before clearing ToolOutputStore on session delete.
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix(ai): reload permission grants from storage before auto-approve
Re-read persisted grant rules on each approval check so revocations in Settings take effect without requiring a chat hook remount.
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix(ai): sync permission grants to main process immediately on write
Push MCP permissionGrantsSnapshot as soon as Always allow persists a rule so the next tool call in the same agent turn sees the grant without waiting for useEffect.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Cursor <cursoragent@cursor.com>