Skip to content

The agent that grows with you

fix(desktop): keep project idea writes on their owning connection

FroRautf0f98aea3553
diff --git a/apps/desktop/src/i18n/ar_chrome.ts b/apps/desktop/src/i18n/ar_chrome.ts
index 10a85e987ff..03e797711de 100644
--- a/apps/desktop/src/i18n/ar_chrome.ts
+++ b/apps/desktop/src/i18n/ar_chrome.ts
@@ -255,6 +255,7 @@ export const arChrome = {
reveal: 'إظهار في المجلد',
copyPath: 'نسخ المسار',
removeFromSidebar: 'إخفاء من الشريط الجانبي',
+ createdInPreviousContext: 'أُنشئ المشروع على الاتصال أو الملف الشخصي السابق. عُد إليه؛ لم يُكتب ملف IDEA.md.',
createFailed: 'تعذّر إنشاء المشروع',
deleteConfirm: 'هذا يزيل المشروع المحفوظ من Hermes. تبقى الملفات ومستودعات git وأشجار العمل دون تغيير.',
startWork: 'شجرة عمل جديدة',
diff --git a/apps/desktop/src/i18n/de.ts b/apps/desktop/src/i18n/de.ts
index a094cff2270..b3047020b38 100644
--- a/apps/desktop/src/i18n/de.ts
+++ b/apps/desktop/src/i18n/de.ts
@@ -4054,6 +4054,8 @@ export const deOverrides = {
reveal: 'Im Ordner anzeigen',
copyPath: 'Pfad kopieren',
removeFromSidebar: 'Aus der Sidebar ausblenden',
+ createdInPreviousContext:
+ 'Das Projekt wurde auf der vorherigen Verbindung oder im vorherigen Profil erstellt. Wechsle zurück; IDEA.md wurde nicht geschrieben.',
createFailed: 'Projekt konnte nicht erstellt werden',
staleBackend:
'Aktualisieren Sie das Hermes-Backend, um Projekte zu erstellen – Ihr Backend ist älter als diese Desktop-App (Einstellungen → Updates → Backend).',
diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.ts
index 753cd043a9c..5931026a623 100644
--- a/apps/desktop/src/i18n/en.ts
+++ b/apps/desktop/src/i18n/en.ts
@@ -3673,6 +3673,8 @@ export const en: Translations = {
reveal: 'Reveal in folder',
copyPath: 'Copy path',
removeFromSidebar: 'Hide from sidebar',
+ createdInPreviousContext:
+ "Project created on the previous connection or profile. Switch back to find it; IDEA.md wasn't written.",
createFailed: 'Could not create project',
staleBackend:
'Update the Hermes backend to create projects — your backend is older than this desktop app (Settings → Updates → Backend).',
diff --git a/apps/desktop/src/i18n/es.ts b/apps/desktop/src/i18n/es.ts
index eeb2f49701e..ae727608182 100644
--- a/apps/desktop/src/i18n/es.ts
+++ b/apps/desktop/src/i18n/es.ts
@@ -4046,6 +4046,8 @@ export const esOverrides = {
reveal: 'Revelar en carpeta',
copyPath: 'Copiar ruta',
removeFromSidebar: 'Ocultar de la barra lateral',
+ createdInPreviousContext:
+ 'El proyecto se creó en la conexión o el perfil anterior. Vuelve allí; no se escribió IDEA.md.',
createFailed: 'No se pudo crear el proyecto',
staleBackend:
'Actualiza el backend de Hermes para crear proyectos: tu backend es más antiguo que esta aplicación de escritorio (Configuración → Actualizaciones → Backend).',
diff --git a/apps/desktop/src/i18n/fr.ts b/apps/desktop/src/i18n/fr.ts
index 0b5b9a72fb1..37ba7a368f1 100644
--- a/apps/desktop/src/i18n/fr.ts
+++ b/apps/desktop/src/i18n/fr.ts
@@ -4065,6 +4065,8 @@ export const frOverrides = {
reveal: 'Afficher dans le dossier',
copyPath: 'Copier le chemin',
removeFromSidebar: 'Masquer de la barre latérale',
+ createdInPreviousContext:
+ "Le projet a été créé sur la connexion ou le profil précédent. Revenez-y ; IDEA.md n'a pas été écrit.",
createFailed: 'Impossible de créer le projet',
staleBackend:
'Mettez à jour le backend Hermes pour créer des projets — votre backend est plus ancien que cette application de bureau (Paramètres → Mises à jour → Backend).',
diff --git a/apps/desktop/src/i18n/ja.ts b/apps/desktop/src/i18n/ja.ts
index 69db7e9af4a..3b0687ccbff 100644
--- a/apps/desktop/src/i18n/ja.ts
+++ b/apps/desktop/src/i18n/ja.ts
@@ -2588,6 +2588,8 @@ export const ja = defineLocale({
reveal: 'フォルダで表示',
copyPath: 'パスをコピー',
removeFromSidebar: 'サイドバーから削除',
+ createdInPreviousContext:
+ 'プロジェクトは以前の接続またはプロファイルで作成されました。そこに戻ってください。IDEA.md は書き込まれていません。',
createFailed: 'プロジェクトを作成できませんでした',
staleBackend:
'プロジェクトを作成するには Hermes バックエンドを更新してください。バックエンドがこのデスクトップアプリより古いです(設定 → 更新 → バックエンド)。',
diff --git a/apps/desktop/src/i18n/ru.ts b/apps/desktop/src/i18n/ru.ts
index 3d1274cfc24..e48b90a4354 100644
--- a/apps/desktop/src/i18n/ru.ts
+++ b/apps/desktop/src/i18n/ru.ts
@@ -2782,6 +2782,8 @@ export const ru = defineLocale({
reveal: 'Показать в папке',
copyPath: 'Копировать путь',
removeFromSidebar: 'Скрыть из боковой панели',
+ createdInPreviousContext:
+ 'Проект создан в прежнем подключении или профиле. Вернитесь к нему; файл IDEA.md не был записан.',
createFailed: 'Не удалось создать проект',
staleBackend:
'Обновите бэкенд Hermes, чтобы создавать проекты — ваш бэкенд старше этого desktop-приложения (Настройки → Обновления → Бэкенд).',
diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.ts
index 9b7ab4c2e1d..76d1efcedee 100644
--- a/apps/desktop/src/i18n/types.ts
+++ b/apps/desktop/src/i18n/types.ts
@@ -3097,6 +3097,7 @@ export interface Translations {
reveal: string
copyPath: string
removeFromSidebar: string
+ createdInPreviousContext: string
createFailed: string
staleBackend: string
deleteConfirm: string
diff --git a/apps/desktop/src/i18n/zh-hant_chrome.ts b/apps/desktop/src/i18n/zh-hant_chrome.ts
index c56c73c3a7c..1e22c7d604b 100644
--- a/apps/desktop/src/i18n/zh-hant_chrome.ts
+++ b/apps/desktop/src/i18n/zh-hant_chrome.ts
@@ -147,6 +147,7 @@ export const zhHantChrome = {
reveal: '在資料夾中顯示',
copyPath: '複製路徑',
removeFromSidebar: '從側邊欄移除',
+ createdInPreviousContext: '專案已在先前的連線或設定檔中建立。請切換回去;IDEA.md 尚未寫入。',
createFailed: '無法建立專案',
staleBackend: '請更新 Hermes 後端以建立專案——目前後端比桌面應用舊(設定 → 更新 → 後端)。',
deleteConfirm: '這會從 Hermes 中移除已儲存的專案。檔案、git 儲存庫和工作樹維持不變。',
diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.ts
index 5ba2a7f8268..355fa64af22 100644
--- a/apps/desktop/src/i18n/zh.ts
+++ b/apps/desktop/src/i18n/zh.ts
@@ -3442,6 +3442,7 @@ export const zh = defineLocale({
reveal: '在文件夹中显示',
copyPath: '复制路径',
removeFromSidebar: '从侧边栏移除',
+ createdInPreviousContext: '项目已在之前的连接或配置文件中创建。请切换回去;IDEA.md 尚未写入。',
createFailed: '无法创建项目',
staleBackend: '请更新 Hermes 后端以创建项目——当前后端比桌面应用旧(设置 → 更新 → 后端)。',
deleteConfirm: '这会从 Hermes 中移除已保存的项目。文件、git 仓库和工作树保持不变。',
diff --git a/apps/desktop/src/store/projects.test.ts b/apps/desktop/src/store/projects.test.ts
index b7bff129b02..4592f10d50c 100644
--- a/apps/desktop/src/store/projects.test.ts
+++ b/apps/desktop/src/store/projects.test.ts
@@ -1,3 +1,7 @@
+import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
+import { tmpdir } from 'node:os'
+import path from 'node:path'
+
import { waitFor } from '@testing-library/react'
import { atom } from 'nanostores'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
@@ -480,6 +484,71 @@ describe('createProject', () => {
expect(request).not.toHaveBeenCalled()
})
+ it.each(['connection', 'profile'] as const)(
+ 'does not write a project idea or publish its row on a new %s after creation on the old owner',
+ async changed => {
+ const dir = await mkdtemp(path.join(tmpdir(), 'hermes-project-owner-'))
+ const originFile = path.join(dir, 'origin-IDEA.md')
+ const unrelatedFile = path.join(dir, 'unrelated-IDEA.md')
+ const created = { folders: [], id: 'p_created_on_a', name: 'Original project', primary_path: '/shared/project' }
+ const pendingCreate = deferred<{ project: typeof created }>()
+
+ const request = vi.fn((method: string) =>
+ method === 'projects.create' ? pendingCreate.promise : Promise.resolve({ active_id: null, projects: [] })
+ )
+
+ const ownerGateway = { connectionState: 'open', request }
+ const otherGateway = { connectionState: 'open', request: vi.fn() }
+ let currentGateway = ownerGateway
+
+ try {
+ await writeFile(originFile, 'origin idea')
+ await writeFile(unrelatedFile, 'unrelated valuable idea')
+ activeGateway.mockImplementation(() => currentGateway as never)
+ vi.mocked(fs.writeDesktopFileText).mockImplementation(async (_file, text) => {
+ const destination =
+ currentGateway === ownerGateway && $activeGatewayProfile.get() === 'default' ? originFile : unrelatedFile
+
+ await writeFile(destination, text)
+
+ return { path: destination }
+ })
+
+ const result = createProject({
+ folders: ['/shared/project'],
+ idea: 'idea from A',
+ name: created.name,
+ use: true
+ })
+
+ await waitFor(() =>
+ expect(request).toHaveBeenCalledWith('projects.create', expect.objectContaining({ profile: 'default' }))
+ )
+
+ if (changed === 'connection') {
+ currentGateway = otherGateway
+ } else {
+ $activeGatewayProfile.set('other')
+ }
+
+ pendingCreate.resolve({ project: created })
+ await expect(result).resolves.toBeNull()
+
+ expect(await readFile(unrelatedFile, 'utf8')).toBe('unrelated valuable idea')
+ expect(await readFile(originFile, 'utf8')).toBe('origin idea')
+ expect(vi.mocked(fs.writeDesktopFileText)).not.toHaveBeenCalled()
+ expect($projects.get()).not.toContainEqual(created)
+ expect($activeProjectId.get()).toBeNull()
+ expect(notify).toHaveBeenCalledWith({
+ kind: 'info',
+ message: 'sidebar.projects.createdInPreviousContext'
+ })
+ } finally {
+ await rm(dir, { recursive: true, force: true })
+ }
+ }
+ )
+
it('creates the project and flips into the grouped view so a blank slate shows it', async () => {
const created = { folders: [], id: 'p_new', name: 'Demo', primary_path: '/srv/demo' }
diff --git a/apps/desktop/src/store/projects.ts b/apps/desktop/src/store/projects.ts
index 7960b099c41..73ea9a31dd1 100644
--- a/apps/desktop/src/store/projects.ts
+++ b/apps/desktop/src/store/projects.ts
@@ -348,6 +348,12 @@ function stillOnProjectsContext(context: ActiveProjectsContext): boolean {
return activeGateway() === context.gateway && projectProfile() === context.profile
}
+// Writes follow the selected gateway/profile even if the sidebar is showing
+// All profiles. That filter changes the view, not the destination.
+function stillOnWritableProjectOwner(context: ActiveProjectsContext): boolean {
+ return activeGateway() === context.gateway && normalizeProfileKey($activeGatewayProfile.get()) === context.profile
+}
+
async function activeProjectsContext(profile = projectProfile()): Promise<ActiveProjectsContext> {
if (!profile || profile === ALL_PROFILES) {
throw new Error('Projects are unavailable while viewing all profiles')
@@ -1021,11 +1027,12 @@ export async function createProject(input: CreateProjectInput): Promise<ProjectI
}
let res: { project: ProjectInfo | null }
+ let context: ActiveProjectsContext | null = null
try {
// All profiles filters the sidebar, not the owner of a new project.
// Capture the live route so reconnecting cannot retarget the write.
- const context = await activeProjectsContext(writableProjectProfile())
+ context = await activeProjectsContext(writableProjectProfile())
res = await gatewayRequestOn<{ project: ProjectInfo | null }>(
context.gateway,
@@ -1047,13 +1054,27 @@ export async function createProject(input: CreateProjectInput): Promise<ProjectI
)
} catch (err) {
if (isMissingRpcMethod(err)) {
- $projectsRpcAvailable.set(false)
+ if (context && stillOnWritableProjectOwner(context)) {
+ $projectsRpcAvailable.set(false)
+ }
+
throw projectsStaleBackendError()
}
throw err
}
+ // The RPC may have created the project on A while the window moved to B.
+ // The IDEA.md writer and cached/sidebar state below use the current owner;
+ // publishing A's result there can overwrite B's file at the same path.
+ if (!stillOnWritableProjectOwner(context)) {
+ if (res.project) {
+ notify({ kind: 'info', message: translateNow('sidebar.projects.createdInPreviousContext') })
+ }
+
+ return null
+ }
+
markProjectsRpcSuccess()
// Not optimistic (the create awaits the RPC first, so there's nothing to roll