perf: reduce re-renders, fix mobile keyboard handling, add chunk load recovery, and improve PATH management (#1028)
* fix: exclude file content from reverted prompt text Revert and fork now restore only the user's original prompt, not server-injected file content Uses existing isSyntheticPart helper for type-safe filtering * fix: keep scrollbar visible when hovering over thumb * fix: prevent ESC abort from triggering when terminal is focused * fix: pass directory to permission/question reply calls so approvals actually resolve * fix: default model selection not responding after Base UI migration * fix: prevent modal content from shifting and clipping footer buttons * fix: improve session switching performance and add sub-agent export with prompt collapse Defer viewport anchor saving to eliminate ~800ms UI freeze when switching sessions Add export dialog to include sub-agent tasks recursively in markdown export Add collapse chevron button for expanded user prompts in sticky header * fix: resolve sidebar scroll and TDZ crash in session sidebar * perf: reduce CPU overhead and re-renders across chat, layout, and settings * fix: position collapse button at top of message and prevent ESC abort in terminal * fix: position collapse button at top and add padding only when expanded * refactor: extract shared PATH utilities and mobile keyboard hook * refactor: import shared path-utils in electron, use module-level style constants - Electron now imports pathLooksUserConfigured/mergePathValues from shared path-utils.js instead of inline duplication - ToolPart collapsedCustomStyle moved from useMemo([]) to module const * fix: resolve remaining merge conflicts and type errors - Remove duplicate variable declarations in SessionNodeItem - Remove orphaned export callback body from conflict resolution - Fix HelpDialog description -> descriptionKey (i18n rename) * fix: resolve type-check and lint errors in session-actions.test.ts - Added missing bun:test type declarations (beforeEach, mock, mock.module) - Removed unused State import - Replaced 'as any' casts with proper OpencodeClient and ChildStoreManager types - Added eslint-disable for unused _ parameter in mock function * fix PR 1028 export and PATH edge cases * fix startup retry exhaustion state * remove opencode package lock change * fix sub-session rename cancellation --------- Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
This commit is contained in:
committed by
GitHub
co-authored by
Bohdan Triapitsyn
parent
632e6cc97b
commit
4523e9c486
@@ -69,7 +69,7 @@ describe('resolveDesktopBootView', () => {
|
||||
isDesktopShell: true,
|
||||
bootOutcome: { target: 'local', status: 'unreachable' },
|
||||
}),
|
||||
).toEqual({ screen: 'recovery', variant: 'local-unreachable' });
|
||||
).toEqual({ screen: 'recovery', variant: 'local-unavailable' });
|
||||
});
|
||||
|
||||
test('returns recovery view for remote missing', () => {
|
||||
@@ -257,9 +257,9 @@ describe('getInjectedBootOutcome', () => {
|
||||
|
||||
test('returns valid outcome for well-formed main-local', () => {
|
||||
const w = mockWindow();
|
||||
w.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__ = { kind: 'main-local' };
|
||||
w.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__ = { target: 'local', status: 'ok' };
|
||||
try {
|
||||
expect(getInjectedBootOutcome()).toEqual({ kind: 'main-local' });
|
||||
expect(getInjectedBootOutcome()).toEqual({ target: 'local', status: 'ok' });
|
||||
} finally {
|
||||
restoreWindow();
|
||||
}
|
||||
@@ -339,7 +339,7 @@ describe('getBootInjectionStatus', () => {
|
||||
|
||||
test('returns "valid" when global is present and well-formed', () => {
|
||||
const w = mockWindow();
|
||||
w.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__ = { kind: 'main-local' };
|
||||
w.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__ = { target: 'local', status: 'ok' };
|
||||
try {
|
||||
expect(getBootInjectionStatus()).toBe('valid');
|
||||
} finally {
|
||||
|
||||
@@ -5,6 +5,13 @@ import { getRevealLabelKey } from '@/lib/utils';
|
||||
|
||||
type SessionMessageRecord = { info: Message; parts: Part[] };
|
||||
|
||||
export type ChildSessionExport = {
|
||||
title: string;
|
||||
agent?: string;
|
||||
records: SessionMessageRecord[];
|
||||
children: ChildSessionExport[];
|
||||
};
|
||||
|
||||
function formatTimestamp(timestamp: number | undefined): string {
|
||||
if (typeof timestamp !== 'number' || !Number.isFinite(timestamp)) {
|
||||
return '';
|
||||
@@ -65,9 +72,29 @@ function formatMessageAsMarkdown(record: SessionMessageRecord): string {
|
||||
return `${role}\n\n${text}`;
|
||||
}
|
||||
|
||||
function formatChildSessionAsMarkdown(child: ChildSessionExport, depth: number): string {
|
||||
const heading = '#'.repeat(Math.min(depth + 1, 6));
|
||||
const agentLabel = child.agent ? ` — ${child.agent}` : '';
|
||||
const childHeader = `${heading} Sub-agent: ${child.title}${agentLabel}\n\n---\n\n`;
|
||||
|
||||
const childBody = child.records
|
||||
.map(formatMessageAsMarkdown)
|
||||
.filter(Boolean)
|
||||
.join('\n\n---\n\n');
|
||||
|
||||
const parts = [childHeader + childBody];
|
||||
|
||||
for (const grandchild of child.children) {
|
||||
parts.push(formatChildSessionAsMarkdown(grandchild, depth + 1));
|
||||
}
|
||||
|
||||
return parts.join('\n\n---\n\n');
|
||||
}
|
||||
|
||||
export function formatSessionAsMarkdown(
|
||||
messages: SessionMessageRecord[],
|
||||
sessionTitle?: string | null,
|
||||
childSessions?: ChildSessionExport[],
|
||||
): string {
|
||||
const title = sessionTitle?.trim() || 'Session';
|
||||
const date = new Date().toISOString().split('T')[0];
|
||||
@@ -79,7 +106,16 @@ export function formatSessionAsMarkdown(
|
||||
.filter(Boolean)
|
||||
.join('\n\n---\n\n');
|
||||
|
||||
return header + body;
|
||||
let result = header + body;
|
||||
|
||||
if (childSessions && childSessions.length > 0) {
|
||||
const childMarkdown = childSessions
|
||||
.map((child) => formatChildSessionAsMarkdown(child, 1))
|
||||
.join('\n\n---\n\n');
|
||||
result += '\n\n---\n\n' + childMarkdown;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export function downloadAsMarkdown(content: string, filename: string): void {
|
||||
|
||||
@@ -236,6 +236,14 @@ export const dict = {
|
||||
'sessions.sidebar.session.export.nothingToExport': 'Nothing to export',
|
||||
'sessions.sidebar.session.export.success': 'Session exported',
|
||||
'sessions.sidebar.session.export.failedRevealPath': 'Failed to reveal path',
|
||||
'sessions.sidebar.session.export.untitledSubagent': 'Untitled Sub-agent',
|
||||
'sessions.sidebar.session.export.skippedSubtaskSingle': 'Exported session, but skipped {count} sub-agent task that could not be loaded.',
|
||||
'sessions.sidebar.session.export.skippedSubtaskMany': 'Exported session, but skipped {count} sub-agent tasks that could not be loaded.',
|
||||
'sessions.sidebar.session.export.dialog.title': 'Export Markdown',
|
||||
'sessions.sidebar.session.export.dialog.descriptionSingle': 'This session has {count} sub-agent task. Include it in the export?',
|
||||
'sessions.sidebar.session.export.dialog.descriptionMany': 'This session has {count} sub-agent tasks. Include them in the export?',
|
||||
'sessions.sidebar.session.export.dialog.includeSubtasks': 'Include sub-agent tasks',
|
||||
'sessions.sidebar.session.export.dialog.confirm': 'Export',
|
||||
'sessions.sidebar.session.status.active': 'Session active',
|
||||
'sessions.sidebar.session.status.unread': 'Unread updates',
|
||||
'sessions.sidebar.session.status.pinned': 'Pinned session',
|
||||
@@ -1958,6 +1966,10 @@ export const dict = {
|
||||
'onboarding.desktopRecovery.common.useRemote': 'Use Remote',
|
||||
'onboarding.desktopRecovery.actions.retrying': 'Retrying…',
|
||||
'onboarding.desktopRecovery.actions.retryConnection': 'Retry Connection',
|
||||
'startup.initRecovery.title': 'Startup failed',
|
||||
'startup.initRecovery.description': 'OpenChamber could not finish initialization. Check that the server is running, then retry.',
|
||||
'startup.initRecovery.retry': 'Retry',
|
||||
'startup.initRecovery.retrying': 'Retrying…',
|
||||
'onboarding.desktopRecovery.placeholders.remoteServer': 'the remote server',
|
||||
'onboarding.desktopRecovery.placeholders.unknownServer': 'unknown',
|
||||
'vscodeLayout.title.chat': 'Chat',
|
||||
|
||||
@@ -237,6 +237,14 @@ export const dict: Record<I18nKey, string> = {
|
||||
"sessions.sidebar.session.export.nothingToExport": "No hay nada para exportar",
|
||||
"sessions.sidebar.session.export.success": "Sesión exportada",
|
||||
"sessions.sidebar.session.export.failedRevealPath": "No se pudo mostrar la ruta",
|
||||
"sessions.sidebar.session.export.untitledSubagent": "Subagente sin título",
|
||||
"sessions.sidebar.session.export.skippedSubtaskSingle": "La sesión se exportó, pero se omitió {count} tarea de subagente que no se pudo cargar.",
|
||||
"sessions.sidebar.session.export.skippedSubtaskMany": "La sesión se exportó, pero se omitieron {count} tareas de subagente que no se pudieron cargar.",
|
||||
"sessions.sidebar.session.export.dialog.title": "Exportar Markdown",
|
||||
"sessions.sidebar.session.export.dialog.descriptionSingle": "Esta sesión tiene {count} tarea de subagente. ¿Incluirla en la exportación?",
|
||||
"sessions.sidebar.session.export.dialog.descriptionMany": "Esta sesión tiene {count} tareas de subagente. ¿Incluirlas en la exportación?",
|
||||
"sessions.sidebar.session.export.dialog.includeSubtasks": "Incluir tareas de subagente",
|
||||
"sessions.sidebar.session.export.dialog.confirm": "Exportar",
|
||||
"sessions.sidebar.session.status.active": "Sesión activa",
|
||||
"sessions.sidebar.session.status.unread": "Actualizaciones no leídas",
|
||||
"sessions.sidebar.session.status.pinned": "Sesión anclada",
|
||||
@@ -1959,6 +1967,10 @@ export const dict: Record<I18nKey, string> = {
|
||||
"onboarding.desktopRecovery.common.useRemote": "Usar remoto",
|
||||
"onboarding.desktopRecovery.actions.retrying": "Reintentando…",
|
||||
"onboarding.desktopRecovery.actions.retryConnection": "Reintentar conexión",
|
||||
"startup.initRecovery.title": "Error al iniciar",
|
||||
"startup.initRecovery.description": "OpenChamber no pudo completar la inicialización. Comprueba que el servidor esté en ejecución y vuelve a intentarlo.",
|
||||
"startup.initRecovery.retry": "Reintentar",
|
||||
"startup.initRecovery.retrying": "Reintentando…",
|
||||
"onboarding.desktopRecovery.placeholders.remoteServer": "el servidor remoto",
|
||||
"onboarding.desktopRecovery.placeholders.unknownServer": "desconocido",
|
||||
"vscodeLayout.title.chat": "Chat",
|
||||
|
||||
@@ -237,6 +237,14 @@ export const dict: Record<I18nKey, string> = {
|
||||
"sessions.sidebar.session.export.nothingToExport": "Não há nada para exportar",
|
||||
"sessions.sidebar.session.export.success": "Sessão exportada",
|
||||
"sessions.sidebar.session.export.failedRevealPath": "Não foi possível mostrar o caminho",
|
||||
"sessions.sidebar.session.export.untitledSubagent": "Subagente sem título",
|
||||
"sessions.sidebar.session.export.skippedSubtaskSingle": "A sessão foi exportada, mas {count} tarefa de subagente não pôde ser carregada e foi ignorada.",
|
||||
"sessions.sidebar.session.export.skippedSubtaskMany": "A sessão foi exportada, mas {count} tarefas de subagente não puderam ser carregadas e foram ignoradas.",
|
||||
"sessions.sidebar.session.export.dialog.title": "Exportar Markdown",
|
||||
"sessions.sidebar.session.export.dialog.descriptionSingle": "Esta sessão tem {count} tarefa de subagente. Incluí-la na exportação?",
|
||||
"sessions.sidebar.session.export.dialog.descriptionMany": "Esta sessão tem {count} tarefas de subagente. Incluí-las na exportação?",
|
||||
"sessions.sidebar.session.export.dialog.includeSubtasks": "Incluir tarefas de subagente",
|
||||
"sessions.sidebar.session.export.dialog.confirm": "Exportar",
|
||||
"sessions.sidebar.session.status.active": "Sessão ativa",
|
||||
"sessions.sidebar.session.status.unread": "Atualizações não lidas",
|
||||
"sessions.sidebar.session.status.pinned": "Sessão fixada",
|
||||
@@ -1959,6 +1967,10 @@ export const dict: Record<I18nKey, string> = {
|
||||
"onboarding.desktopRecovery.common.useRemote": "Usar remoto",
|
||||
"onboarding.desktopRecovery.actions.retrying": "Retentendo…",
|
||||
"onboarding.desktopRecovery.actions.retryConnection": "Tentar novamente conexão",
|
||||
"startup.initRecovery.title": "Falha ao iniciar",
|
||||
"startup.initRecovery.description": "O OpenChamber não conseguiu concluir a inicialização. Verifique se o servidor está em execução e tente novamente.",
|
||||
"startup.initRecovery.retry": "Tentar novamente",
|
||||
"startup.initRecovery.retrying": "Tentando novamente…",
|
||||
"onboarding.desktopRecovery.placeholders.remoteServer": "o servidor remoto",
|
||||
"onboarding.desktopRecovery.placeholders.unknownServer": "desconhecido",
|
||||
"vscodeLayout.title.chat": "Chat",
|
||||
|
||||
@@ -237,6 +237,14 @@ export const dict: Record<I18nKey, string> = {
|
||||
"sessions.sidebar.session.export.nothingToExport": "Нічого для експорту",
|
||||
"sessions.sidebar.session.export.success": "Сесія експортовано",
|
||||
"sessions.sidebar.session.export.failedRevealPath": "Не вдалося відкрити шлях",
|
||||
"sessions.sidebar.session.export.untitledSubagent": "Під-агент без назви",
|
||||
"sessions.sidebar.session.export.skippedSubtaskSingle": "Сесію експортовано, але пропущено {count} завдання під-агента, яке не вдалося завантажити.",
|
||||
"sessions.sidebar.session.export.skippedSubtaskMany": "Сесію експортовано, але пропущено {count} завдань під-агента, які не вдалося завантажити.",
|
||||
"sessions.sidebar.session.export.dialog.title": "Експорт Markdown",
|
||||
"sessions.sidebar.session.export.dialog.descriptionSingle": "Ця сесія має {count} завдання під-агента. Додати його до експорту?",
|
||||
"sessions.sidebar.session.export.dialog.descriptionMany": "Ця сесія має {count} завдань під-агентів. Додати їх до експорту?",
|
||||
"sessions.sidebar.session.export.dialog.includeSubtasks": "Додати завдання під-агентів",
|
||||
"sessions.sidebar.session.export.dialog.confirm": "Експортувати",
|
||||
"sessions.sidebar.session.status.active": "Сесія активний",
|
||||
"sessions.sidebar.session.status.unread": "Непрочитані оновлення",
|
||||
"sessions.sidebar.session.status.pinned": "Закріплений сесія",
|
||||
@@ -1959,6 +1967,10 @@ export const dict: Record<I18nKey, string> = {
|
||||
"onboarding.desktopRecovery.common.useRemote": "Використовувати Remote",
|
||||
"onboarding.desktopRecovery.actions.retrying": "Повторна спроба…",
|
||||
"onboarding.desktopRecovery.actions.retryConnection": "Повторити підключення",
|
||||
"startup.initRecovery.title": "Не вдалося запустити",
|
||||
"startup.initRecovery.description": "OpenChamber не зміг завершити ініціалізацію. Перевірте, що сервер запущений, і повторіть спробу.",
|
||||
"startup.initRecovery.retry": "Повторити спробу",
|
||||
"startup.initRecovery.retrying": "Повторна спроба…",
|
||||
"onboarding.desktopRecovery.placeholders.remoteServer": "віддалений сервер",
|
||||
"onboarding.desktopRecovery.placeholders.unknownServer": "невідомий",
|
||||
"vscodeLayout.title.chat": "Чат",
|
||||
|
||||
@@ -237,6 +237,14 @@ export const dict: Record<I18nKey, string> = {
|
||||
'sessions.sidebar.session.export.nothingToExport': '没有可导出的内容',
|
||||
'sessions.sidebar.session.export.success': '会话已导出',
|
||||
'sessions.sidebar.session.export.failedRevealPath': '显示路径失败',
|
||||
'sessions.sidebar.session.export.untitledSubagent': '未命名子代理',
|
||||
'sessions.sidebar.session.export.skippedSubtaskSingle': '会话已导出,但跳过了 {count} 个无法加载的子代理任务。',
|
||||
'sessions.sidebar.session.export.skippedSubtaskMany': '会话已导出,但跳过了 {count} 个无法加载的子代理任务。',
|
||||
'sessions.sidebar.session.export.dialog.title': '导出 Markdown',
|
||||
'sessions.sidebar.session.export.dialog.descriptionSingle': '此会话有 {count} 个子代理任务。是否包含在导出中?',
|
||||
'sessions.sidebar.session.export.dialog.descriptionMany': '此会话有 {count} 个子代理任务。是否包含在导出中?',
|
||||
'sessions.sidebar.session.export.dialog.includeSubtasks': '包含子代理任务',
|
||||
'sessions.sidebar.session.export.dialog.confirm': '导出',
|
||||
'sessions.sidebar.session.status.active': '会话活跃中',
|
||||
'sessions.sidebar.session.status.unread': '有未读更新',
|
||||
'sessions.sidebar.session.status.pinned': '已置顶会话',
|
||||
@@ -1959,6 +1967,10 @@ export const dict: Record<I18nKey, string> = {
|
||||
'onboarding.desktopRecovery.common.useRemote': '使用远程',
|
||||
'onboarding.desktopRecovery.actions.retrying': '重试中…',
|
||||
'onboarding.desktopRecovery.actions.retryConnection': '重试连接',
|
||||
'startup.initRecovery.title': '启动失败',
|
||||
'startup.initRecovery.description': 'OpenChamber 未能完成初始化。请检查服务器是否正在运行,然后重试。',
|
||||
'startup.initRecovery.retry': '重试',
|
||||
'startup.initRecovery.retrying': '重试中…',
|
||||
'onboarding.desktopRecovery.placeholders.remoteServer': '远程服务器',
|
||||
'onboarding.desktopRecovery.placeholders.unknownServer': '未知服务器',
|
||||
'vscodeLayout.title.chat': '聊天',
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import type { Part } from "@opencode-ai/sdk/v2"
|
||||
import { isSyntheticPart, isFullySyntheticMessage, filterSyntheticParts } from "./synthetic"
|
||||
|
||||
function createTextPart(id: string, text: string, synthetic?: boolean): Part {
|
||||
return {
|
||||
id,
|
||||
sessionID: "session-1",
|
||||
messageID: "message-1",
|
||||
type: "text",
|
||||
text,
|
||||
...(synthetic !== undefined ? { synthetic } : {}),
|
||||
} as Part
|
||||
}
|
||||
|
||||
function createFilePart(id: string, url: string): Part {
|
||||
return {
|
||||
id,
|
||||
sessionID: "session-1",
|
||||
messageID: "message-1",
|
||||
type: "file",
|
||||
mime: "text/plain",
|
||||
url,
|
||||
} as Part
|
||||
}
|
||||
|
||||
describe("isSyntheticPart", () => {
|
||||
test("returns false for undefined", () => {
|
||||
expect(isSyntheticPart(undefined)).toBe(false)
|
||||
})
|
||||
|
||||
test("returns false for non-object", () => {
|
||||
expect(isSyntheticPart(null as unknown as Part)).toBe(false)
|
||||
expect(isSyntheticPart("string" as unknown as Part)).toBe(false)
|
||||
})
|
||||
|
||||
test("returns false for parts without synthetic property", () => {
|
||||
const part = createTextPart("1", "hello")
|
||||
expect(isSyntheticPart(part)).toBe(false)
|
||||
})
|
||||
|
||||
test("returns false for parts with synthetic: false", () => {
|
||||
const part = createTextPart("1", "hello", false)
|
||||
expect(isSyntheticPart(part)).toBe(false)
|
||||
})
|
||||
|
||||
test("returns true for parts with synthetic: true", () => {
|
||||
const part = createTextPart("1", "file content here", true)
|
||||
expect(isSyntheticPart(part)).toBe(true)
|
||||
})
|
||||
|
||||
test("returns false for file parts", () => {
|
||||
const part = createFilePart("1", "file:///path/to/file")
|
||||
expect(isSyntheticPart(part)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe("isFullySyntheticMessage", () => {
|
||||
test("returns false for undefined", () => {
|
||||
expect(isFullySyntheticMessage(undefined)).toBe(false)
|
||||
})
|
||||
|
||||
test("returns false for empty array", () => {
|
||||
expect(isFullySyntheticMessage([])).toBe(false)
|
||||
})
|
||||
|
||||
test("returns false when all parts are non-synthetic", () => {
|
||||
const parts = [
|
||||
createTextPart("1", "hello"),
|
||||
createFilePart("2", "file:///path"),
|
||||
]
|
||||
expect(isFullySyntheticMessage(parts)).toBe(false)
|
||||
})
|
||||
|
||||
test("returns false when some parts are synthetic", () => {
|
||||
const parts = [
|
||||
createTextPart("1", "user prompt"),
|
||||
createTextPart("2", "file content", true),
|
||||
]
|
||||
expect(isFullySyntheticMessage(parts)).toBe(false)
|
||||
})
|
||||
|
||||
test("returns true when all parts are synthetic", () => {
|
||||
const parts = [
|
||||
createTextPart("1", "file content 1", true),
|
||||
createTextPart("2", "file content 2", true),
|
||||
]
|
||||
expect(isFullySyntheticMessage(parts)).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe("filterSyntheticParts", () => {
|
||||
test("returns empty array for undefined", () => {
|
||||
expect(filterSyntheticParts(undefined)).toEqual([])
|
||||
})
|
||||
|
||||
test("returns empty array for empty array", () => {
|
||||
expect(filterSyntheticParts([])).toEqual([])
|
||||
})
|
||||
|
||||
test("returns all parts when no synthetic parts exist", () => {
|
||||
const parts = [
|
||||
createTextPart("1", "hello"),
|
||||
createFilePart("2", "file:///path"),
|
||||
]
|
||||
expect(filterSyntheticParts(parts)).toEqual(parts)
|
||||
})
|
||||
|
||||
test("filters out synthetic parts when non-synthetic parts exist", () => {
|
||||
const userPart = createTextPart("1", "user prompt")
|
||||
const syntheticPart = createTextPart("2", "file content", true)
|
||||
const parts = [userPart, syntheticPart]
|
||||
expect(filterSyntheticParts(parts)).toEqual([userPart])
|
||||
})
|
||||
|
||||
test("keeps synthetic parts when all parts are synthetic", () => {
|
||||
const parts = [
|
||||
createTextPart("1", "file content 1", true),
|
||||
createTextPart("2", "file content 2", true),
|
||||
]
|
||||
expect(filterSyntheticParts(parts)).toEqual(parts)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user