From 4d4d7b838ad82adebcab158d377d4322237a3ef9 Mon Sep 17 00:00:00 2001 From: nonoqing Date: Thu, 29 Oct 2026 17:01:25 +0800 Subject: [PATCH] fix(dev): reuse existing sessions by default --- CONTRIBUTING.md | 8 ++- CONTRIBUTING_CN.md | 7 ++- .../agent-runtime-deployment-design.md | 3 +- scripts/dev-startup.test.mjs | 57 +++++++++++++++---- scripts/dev.cjs | 4 +- src/apps/desktop/AGENTS.md | 10 ++-- src/apps/desktop/README.md | 21 ++++--- 7 files changed, 83 insertions(+), 27 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c265869c33..1b5e81838d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -64,7 +64,7 @@ and local implementation-process notes out of Git. ```bash # Desktop (recommended for daily development) pnpm run desktop:dev # full hot-reload: Vite HMR + Rust auto-rebuild & restart -pnpm run desktop:dev -- --shared-data # run alongside the installed app and share data +pnpm run desktop:dev -- --isolated-data # opt into checkout-local test data pnpm run prepare:dsh-profile # optional: compile the DeepSeek Harness bridge for local sessions # Desktop (lightweight preview, no Rust auto-rebuild) @@ -79,6 +79,12 @@ pnpm run e2e:test > **`desktop:dev` vs `desktop:preview:debug`**: `desktop:dev` runs `tauri dev`, which provides **full hot-reload** — frontend changes apply instantly via Vite HMR, and Rust/backend changes trigger an incremental rebuild followed by an automatic app restart. This is the recommended workflow for active development. `desktop:preview:debug` launches a pre-built debug binary alongside a Vite dev server; frontend edits still get HMR, but **Rust-side changes are not auto-rebuilt** — you must stop and re-run the command (or use `--force-rebuild`). Use `desktop:preview:debug` when you only need to iterate on frontend code or want a faster cold-start without waiting for `tauri dev` initialization. +Both launchers use the installed app's data by default, including existing model +settings, workspaces, and sessions. Use `--isolated-data` for persistent test data +under the current checkout's `.openbitfun/desktop-dev/` directory. Explicit +storage environment overrides still take precedence; `--shared-data` remains a +compatible way to request the default mode. + > For the full script list, see [`package.json`](package.json). For agent-specific commands, verification, and architecture rules, see [`AGENTS.md`](AGENTS.md). ### Desktop debugging tools diff --git a/CONTRIBUTING_CN.md b/CONTRIBUTING_CN.md index 06c7ce1cf9..1319bd06b5 100644 --- a/CONTRIBUTING_CN.md +++ b/CONTRIBUTING_CN.md @@ -60,7 +60,7 @@ Tauri 生成的 `gen/` 目录以及本地实施过程记录不进入 Git。 ```bash # Desktop(日常开发推荐) pnpm run desktop:dev # 完整热更新:Vite HMR + Rust 自动重编译并重启 -pnpm run desktop:dev -- --shared-data # 与安装版同时运行,并共享数据 +pnpm run desktop:dev -- --isolated-data # 显式使用当前仓库的独立测试数据 pnpm run prepare:dsh-profile # 可选:编译 DeepSeek Harness 桥,供本地会话使用 # Desktop(轻量预览,无 Rust 自动重编译) @@ -75,6 +75,11 @@ pnpm run e2e:test > **`desktop:dev` 与 `desktop:preview:debug` 的区别**:`desktop:dev` 运行 `tauri dev`,提供**完整热更新** — 前端改动通过 Vite HMR 即时生效,Rust/后端改动会触发增量重编译并自动重启应用,是日常开发的首选方式。`desktop:preview:debug` 启动预构建的 debug 二进制和 Vite dev server;前端编辑仍可 HMR,但 **Rust 侧改动不会自动重编译** — 需要手动停止并重新运行命令(或使用 `--force-rebuild`)。适合仅需迭代前端代码、或希望跳过 `tauri dev` 初始化以更快冷启动的场景。 +两种启动器默认使用安装版的日常数据,包括已有模型设置、工作区和会话。 +需要独立测试数据时,显式添加 `--isolated-data`,数据保存在当前仓库的 +`.openbitfun/desktop-dev/` 下。显式设置的数据目录环境变量仍优先生效; +`--shared-data` 保留为默认模式的兼容写法。 + > 完整脚本列表见 [`package.json`](package.json)。agent 专用命令、验证与架构规则见 [`AGENTS.md`](AGENTS.md)。 ### 桌面端调试工具 diff --git a/docs/architecture/agent-runtime-deployment-design.md b/docs/architecture/agent-runtime-deployment-design.md index e6add05f2d..c0e83417de 100644 --- a/docs/architecture/agent-runtime-deployment-design.md +++ b/docs/architecture/agent-runtime-deployment-design.md @@ -96,7 +96,8 @@ flowchart LR 具体 `EventQueue` 仍由 Core 产品装配;当前 Shared IPC 只把 TUI 必需的强类型操作和事件映射到同一个 Runtime owner, 没有公开协议承诺。是否以 App Server Shared transport 替换并删除它,由行为等价、性能、安全和回滚证据决定。 -Desktop 开发启动器的 `--shared-data` 允许安装版与一个开发版 Embedded host 共用产品数据目录。 +Desktop 开发启动器默认使用日常产品数据目录,安装版与一个开发版 Embedded host 可共用已有配置与会话。 +`--shared-data` 保留为默认模式的显式写法;`--isolated-data` 才选择当前仓库的独立测试目录,已有隔离数据保持原位。 开发版通过仅在 debug/devtools 构建生效的 `development` MiniApp host channel 分离宿主锁、 私有 IPC discovery 和 native launcher 记录;默认安装版路径与 v1 记录不变,开发版使用 v2 启动记录让旧 Shell 明确拒绝,而不是忽略 channel 后连错宿主。配置、模型、MiniApp 内容与 diff --git a/scripts/dev-startup.test.mjs b/scripts/dev-startup.test.mjs index fabfcd0ecb..15b61b15ba 100644 --- a/scripts/dev-startup.test.mjs +++ b/scripts/dev-startup.test.mjs @@ -11,9 +11,11 @@ import { createRequire } from 'node:module'; const require = createRequire(import.meta.url); const { resolveCommandInvocation, resolveDesktopDevDataMode, resolveDesktopDevStorageEnvironment, runCommandPrefixed } = require('./dev.cjs'); -test('desktop data mode flags default to isolation and support pnpm argument forwarding', () => { - assert.equal(resolveDesktopDevDataMode([]), 'isolated'); +test('desktop data mode defaults to shared history and supports explicit isolation', () => { + assert.equal(resolveDesktopDevDataMode([]), 'shared'); + assert.equal(resolveDesktopDevDataMode(['--force-rebuild']), 'shared'); assert.equal(resolveDesktopDevDataMode(['--isolated-data']), 'isolated'); + assert.equal(resolveDesktopDevDataMode(['--', '--isolated-data']), 'isolated'); assert.equal(resolveDesktopDevDataMode(['--shared-data']), 'shared'); assert.equal(resolveDesktopDevDataMode(['--', '--shared-data', '--force-rebuild']), 'shared'); assert.throws(() => resolveDesktopDevDataMode(['--shared-data', '--isolated-data']), /Choose only one/); @@ -33,8 +35,9 @@ test('conflicting desktop data flags fail before resource preparation', () => { assert.doesNotMatch(result.stdout + result.stderr, /Prepare resources/); }); -test('shared desktop data keeps app defaults and explicit storage overrides intact', () => { +test('default and explicit shared desktop data keep app defaults and storage overrides intact', () => { const channel = { OPENBITFUN_DESKTOP_HOST_CHANNEL: 'development' }; + assert.deepEqual(resolveDesktopDevStorageEnvironment({}, tmpdir()), channel); assert.deepEqual(resolveDesktopDevStorageEnvironment({}, tmpdir(), 'shared'), channel); const env = { OPENBITFUN_USER_ROOT: '/custom/user', @@ -43,20 +46,21 @@ test('shared desktop data keeps app defaults and explicit storage overrides inta OPENBITFUN_E2E_HOME: '/legacy/home', }; const original = { ...env }; + assert.deepEqual(resolveDesktopDevStorageEnvironment(env, tmpdir()), channel); Object.assign(env, resolveDesktopDevStorageEnvironment(env, tmpdir(), 'shared')); assert.deepEqual(env, { ...original, ...channel }); }); -test('desktop development uses persistent storage scoped to each checkout', () => { +test('explicitly isolated desktop development uses persistent storage scoped to each checkout', () => { const root = join(tmpdir(), 'desktop dev & spaces'); - const storage = resolveDesktopDevStorageEnvironment({}, root); + const storage = resolveDesktopDevStorageEnvironment({}, root, 'isolated'); assert.deepEqual(storage, { OPENBITFUN_DESKTOP_HOST_CHANNEL: 'development', OPENBITFUN_USER_ROOT: join(root, '.openbitfun', 'desktop-dev', 'user'), OPENBITFUN_HOME: join(root, '.openbitfun', 'desktop-dev', 'home'), }); - assert.deepEqual(resolveDesktopDevStorageEnvironment({}, root), storage); - const other = resolveDesktopDevStorageEnvironment({}, join(root, 'worktree')); + assert.deepEqual(resolveDesktopDevStorageEnvironment({}, root, 'isolated'), storage); + const other = resolveDesktopDevStorageEnvironment({}, join(root, 'worktree'), 'isolated'); assert.notEqual(other.OPENBITFUN_USER_ROOT, storage.OPENBITFUN_USER_ROOT); assert.notEqual(other.OPENBITFUN_HOME, storage.OPENBITFUN_HOME); }); @@ -71,8 +75,8 @@ test('desktop development preserves explicit and legacy isolated storage overrid OPENBITFUN_E2E_HOME: '/legacy/home', }; const channel = { OPENBITFUN_DESKTOP_HOST_CHANNEL: 'development' }; - assert.deepEqual(resolveDesktopDevStorageEnvironment({ ...legacy, ...explicit }), { ...explicit, ...channel }); - assert.deepEqual(resolveDesktopDevStorageEnvironment(legacy), { + assert.deepEqual(resolveDesktopDevStorageEnvironment({ ...legacy, ...explicit }, tmpdir(), 'isolated'), { ...explicit, ...channel }); + assert.deepEqual(resolveDesktopDevStorageEnvironment(legacy, tmpdir(), 'isolated'), { ...channel, OPENBITFUN_USER_ROOT: legacy.OPENBITFUN_E2E_USER_ROOT, OPENBITFUN_HOME: legacy.OPENBITFUN_E2E_HOME, @@ -80,7 +84,7 @@ test('desktop development preserves explicit and legacy isolated storage overrid const root = tmpdir(); assert.deepEqual(resolveDesktopDevStorageEnvironment({ ...explicit, OPENBITFUN_HOME: '', - }, root), { + }, root, 'isolated'), { ...channel, OPENBITFUN_USER_ROOT: explicit.OPENBITFUN_USER_ROOT, OPENBITFUN_HOME: join(root, '.openbitfun', 'desktop-dev', 'home'), @@ -99,7 +103,7 @@ test('desktop child processes inherit both isolated storage roots', async t => { channel: process.env.OPENBITFUN_DESKTOP_HOST_CHANNEL, })); `); - const env = resolveDesktopDevStorageEnvironment({}, root); + const env = resolveDesktopDevStorageEnvironment({}, root, 'isolated'); const result = await runCommandPrefixed('storage-fixture', 'node', [script, output], root, env); assert.equal(result.ok, true); assert.deepEqual(JSON.parse(readFileSync(output, 'utf8')), { @@ -109,6 +113,37 @@ test('desktop child processes inherit both isolated storage roots', async t => { }); }); +test('default desktop children retain the callers shared data roots without injecting checkout storage', async t => { + const root = mkdtempSync(join(tmpdir(), 'desktop-shared-storage-')); + t.after(() => rmSync(root, { recursive: true, force: true })); + const script = join(root, 'storage-child.cjs'); + const output = join(root, 'storage.json'); + writeFileSync(script, ` + require('node:fs').writeFileSync(process.argv[2], JSON.stringify({ + user: process.env.OPENBITFUN_USER_ROOT, + home: process.env.OPENBITFUN_HOME, + channel: process.env.OPENBITFUN_DESKTOP_HOST_CHANNEL, + })); + `); + const original = { + OPENBITFUN_USER_ROOT: join(root, 'existing user data'), + OPENBITFUN_HOME: join(root, 'existing session data'), + }; + const storage = resolveDesktopDevStorageEnvironment(original, root); + assert.equal(storage.OPENBITFUN_USER_ROOT, undefined); + assert.equal(storage.OPENBITFUN_HOME, undefined); + const result = await runCommandPrefixed('storage-fixture', 'node', [script, output], root, { + ...original, + ...storage, + }); + assert.equal(result.ok, true); + assert.deepEqual(JSON.parse(readFileSync(output, 'utf8')), { + user: original.OPENBITFUN_USER_ROOT, + home: original.OPENBITFUN_HOME, + channel: 'development', + }); +}); + test('desktop preparation invokes pnpm without the Windows batch shim', () => { const invocation = resolveCommandInvocation( 'pnpm', diff --git a/scripts/dev.cjs b/scripts/dev.cjs index 6c1c1f7ccc..37e1fee41c 100644 --- a/scripts/dev.cjs +++ b/scripts/dev.cjs @@ -63,10 +63,10 @@ function resolveDesktopDevDataMode(args = []) { if (args.includes('--shared-data') && args.includes('--isolated-data')) { throw new Error('Choose only one of --shared-data or --isolated-data'); } - return args.includes('--shared-data') ? 'shared' : 'isolated'; + return args.includes('--isolated-data') ? 'isolated' : 'shared'; } -function resolveDesktopDevStorageEnvironment(env = process.env, rootDir = ROOT_DIR, dataMode = 'isolated') { +function resolveDesktopDevStorageEnvironment(env = process.env, rootDir = ROOT_DIR, dataMode = 'shared') { // Shared mode leaves path selection to the app, including caller overrides. if (dataMode === 'shared') { return { OPENBITFUN_DESKTOP_HOST_CHANNEL: 'development' }; diff --git a/src/apps/desktop/AGENTS.md b/src/apps/desktop/AGENTS.md index 9f5a8909aa..1fb6e5f933 100644 --- a/src/apps/desktop/AGENTS.md +++ b/src/apps/desktop/AGENTS.md @@ -320,10 +320,12 @@ For alternate dev-server ports and preview startup URL changes, run `cargo test -p openbitfun-desktop --no-default-features --lib appearance::development_frontend_tests`. For launcher-only development storage mode changes, run `node --test scripts/dev-startup.test.mjs`; no native app launch is required. -By default (or with `--isolated-data`), both desktop development launchers set `OPENBITFUN_USER_ROOT` and -`OPENBITFUN_HOME` before spawning children, defaulting to the checkout-local -`.openbitfun/desktop-dev/{user,home}` directories. `--shared-data` leaves storage -selection to the app; the two flags are mutually exclusive. Preserve explicit +By default (or with `--shared-data`), both desktop development launchers leave +storage selection to the app so existing settings, workspaces and sessions are +visible. Only `--isolated-data` sets `OPENBITFUN_USER_ROOT` and `OPENBITFUN_HOME` +before spawning children, defaulting to the checkout-local +`.openbitfun/desktop-dev/{user,home}` directories. Keep existing isolated data in +place; switching modes must not move, merge or delete it. The two flags are mutually exclusive. Preserve explicit overrides and the legacy E2E aliases in both modes. Development launchers set `OPENBITFUN_DESKTOP_HOST_CHANNEL=development`: its MiniApp lease, discovery and launch records are separate even when product storage is shared. Keep per-session diff --git a/src/apps/desktop/README.md b/src/apps/desktop/README.md index 27aeaa9ac0..1fce2471d9 100644 --- a/src/apps/desktop/README.md +++ b/src/apps/desktop/README.md @@ -669,20 +669,27 @@ main Git checkout's target cache. If absent, curl downloads the version-specific archive, supporting HTTP and SOCKS proxies; Cargo handles extraction and linking. Explicit `SHERPA_ONNX_LIB_DIR` and `SHERPA_ONNX_ARCHIVE_DIR` overrides are preserved. -Development uses separate data by default. Add `--shared-data` to run alongside -the installed app and share its data: +Development shares the installed app's existing settings, workspaces and sessions +by default. Both launchers keep a separate development host channel and retain +the existing session writer and scheduler leases: ```sh -pnpm run desktop:dev -- --shared-data -pnpm run desktop:preview:debug -- --shared-data +pnpm run desktop:dev +pnpm run desktop:preview:debug ``` -Use `--isolated-data` for separate development data (the default). +Use `--isolated-data` for separate development data under the current checkout's +`.openbitfun/desktop-dev/{user,home}` directories. Existing isolated data stays in +place and remains accessible with this flag; switching modes does not move or +delete sessions. Explicit storage environment overrides remain authoritative, +and `--shared-data` is still accepted as an explicit alias for the default. -When another worktree uses the default ports, start a separate dev server: +To run an independent instance in another worktree, isolate its data and choose +different ports. Changing ports alone does not separate the development host +that owns the shared product data: ```sh -OPENBITFUN_DEV_PORT=1432 pnpm run desktop:dev +OPENBITFUN_DEV_PORT=1432 pnpm run desktop:dev -- --isolated-data ``` HMR uses port 1431 in this example; `OPENBITFUN_DEV_HMR_PORT` can override it.