Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion CONTRIBUTING_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 自动重编译)
Expand All @@ -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)。

### 桌面端调试工具
Expand Down
3 changes: 2 additions & 1 deletion docs/architecture/agent-runtime-deployment-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 内容与
Expand Down
57 changes: 46 additions & 11 deletions scripts/dev-startup.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
Expand All @@ -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',
Expand All @@ -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);
});
Expand All @@ -71,16 +75,16 @@ 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,
});
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'),
Expand All @@ -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')), {
Expand All @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions scripts/dev.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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' };
Expand Down
10 changes: 6 additions & 4 deletions src/apps/desktop/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 14 additions & 7 deletions src/apps/desktop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading