mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-16 20:11:08 +00:00
* 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>
75 lines
3.5 KiB
TypeScript
75 lines
3.5 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import { readFileSync } from 'node:fs';
|
|
import test from 'node:test';
|
|
|
|
const panelSource = readFileSync(new URL('./AIChatPanelContent.tsx', import.meta.url), 'utf8');
|
|
const selectorSource = readFileSync(new URL('./ai/AgentSelector.tsx', import.meta.url), 'utf8');
|
|
const preparingSource = readFileSync(new URL('./AIChatSidePanel.tsx', import.meta.url), 'utf8');
|
|
|
|
const primaryToolbarSources = [
|
|
panelSource,
|
|
readFileSync(new URL('./ScriptsSidePanel.tsx', import.meta.url), 'utf8'),
|
|
readFileSync(new URL('./HistorySidePanel.tsx', import.meta.url), 'utf8'),
|
|
readFileSync(new URL('./SftpSidePanel.tsx', import.meta.url), 'utf8'),
|
|
readFileSync(new URL('./notes/NotesManager.tsx', import.meta.url), 'utf8'),
|
|
readFileSync(new URL('./systemManager/SystemManagerSidePanel.tsx', import.meta.url), 'utf8'),
|
|
readFileSync(new URL('./terminal/ThemeSidePanel.tsx', import.meta.url), 'utf8'),
|
|
];
|
|
|
|
test('AI chat header matches the compact system panel toolbar height', () => {
|
|
assert.match(panelSource, /TERMINAL_SIDE_PANEL_INNER_HEADER_CLASS/);
|
|
assert.match(selectorSource, /className="group flex h-6/);
|
|
assert.match(selectorSource, /truncate text-\[11px\]/);
|
|
assert.match(panelSource, /className="h-6 w-6 rounded-md/);
|
|
});
|
|
|
|
test('AI chat preparing state keeps the same compact header height', () => {
|
|
assert.match(preparingSource, /TERMINAL_SIDE_PANEL_INNER_HEADER_CLASS/);
|
|
assert.match(preparingSource, /className="h-6 w-32/);
|
|
});
|
|
|
|
test('agent selector menu stays compact with restrained corners', () => {
|
|
assert.match(selectorSource, /w-\[256px\].*rounded-md/);
|
|
assert.match(selectorSource, /flex h-9 w-full items-center gap-2\.5 px-3/);
|
|
assert.doesNotMatch(selectorSource, /rounded-lg/);
|
|
assert.doesNotMatch(selectorSource, /rounded-2xl/);
|
|
});
|
|
|
|
test('terminal side panel tools share one primary toolbar height', () => {
|
|
for (const source of primaryToolbarSources) {
|
|
assert.match(source, /TERMINAL_SIDE_PANEL_INNER_HEADER_CLASS/);
|
|
}
|
|
});
|
|
|
|
test('/rename and /chats panel commands stay out of the agent message path', () => {
|
|
const sidePanel = preparingSource;
|
|
// Panel implements the commands with updateSessionTitle + a note state —
|
|
// never addMessageToSession, so the commands cannot leak into chat history.
|
|
assert.match(sidePanel, /handleRenameSession = useCallback/);
|
|
assert.match(sidePanel, /handleListChats = useCallback/);
|
|
assert.match(sidePanel, /updateSessionTitle\(sessionId, title\)/);
|
|
assert.match(sidePanel, /setPanelCommandNote\(formatAiChatsListingNote\(entries, t\)\)/);
|
|
const renameHandler = sidePanel.slice(
|
|
sidePanel.indexOf('handleRenameSession = useCallback'),
|
|
sidePanel.indexOf('const handleRenameSlashCommand'),
|
|
);
|
|
assert.doesNotMatch(renameHandler, /addMessageToSession/);
|
|
const chatsHandler = sidePanel.slice(
|
|
sidePanel.indexOf('handleListChats = useCallback'),
|
|
sidePanel.indexOf('const handleSend'),
|
|
);
|
|
assert.doesNotMatch(chatsHandler, /addMessageToSession/);
|
|
// Wiring reaches AIChatPanelContent.
|
|
assert.match(sidePanel, /onRenameActiveChat=\{handleRenameSlashCommand\}/);
|
|
assert.match(sidePanel, /onListChats=\{handleListChats\}/);
|
|
});
|
|
|
|
test('AIChatPanelContent renders the panel command note and wires rename/list props', () => {
|
|
assert.match(panelSource, /panelCommandNote \? \(/);
|
|
assert.match(panelSource, /role="status"/);
|
|
assert.match(panelSource, /onDismissPanelCommandNote/);
|
|
assert.match(panelSource, /onRenameSession=\{onRenameActiveChat\}/);
|
|
assert.match(panelSource, /onListChats=\{onListChats\}/);
|
|
assert.match(panelSource, /onRename=\{onRenameSession\}/);
|
|
});
|