Skip to content

feat(settings): 自定义数据目录并自动迁移 - #1145

Merged
xiaozhou26 merged 1 commit into
mainfrom
feat/custom-data-dir
Nov 3, 2026
Merged

xiaozhou26 merged 1 commit into
mainfrom
feat/custom-data-dir

Conversation

@xiaozhou26

@xiaozhou26 xiaozhou26 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Linked issue

Closes #1138

Summary

New 设置 → 其他 → 数据目录 section. It moves the whole LiveAgent data root (~/.liveagent by default) to a folder the user picks: desktop config, K-brain sessions, memory, skills, uploads, checkpoints, the automation browser profile and the MCP OAuth file store.

Migration flow (data_dir_migrate):

  1. Validate the target before touching anything. It must be an absolute path, outside the current root (and not containing it), and empty. .DS_Store and desktop.ini are ignored. The UI creates a LiveAgent folder inside the picked directory, so picking a busy drive root works.
  2. Stop K-brain, copy every file, and check each copied size.
  3. Write ~/.liveagent/data-dir.json (temp file + rename), then restart the app.
  4. On any failure: remove the partial target, restart K-brain on the old root, and show the error. The old root stays authoritative.

The old directory is never deleted. The success message shows its path so the user can remove it manually.

Resolution order is unchanged for env overrides. LIVEAGENT_CONFIG_DIR, LIVEAGENT_HOME and K_BRAIN_HOME still win, and while one is set the section is locked with an explanation. The root is resolved once per process (runtime::data_home::data_root()), so every subsystem agrees on one location until restart.

These stay in the default ~/.liveagent on purpose:

  • extension/: Chrome records the unpacked extension's absolute path.
  • worktree/: repositories record worktree absolute paths.
  • The v1 legacy-history reader (chat_history/migration.rs): it reads the frozen v1 source location, and its import payload labels feed the idempotency fingerprint.

No K-brain change is needed: it already takes its root from -data-dir / LIVEAGENT_HOME.

Known limitation: "恢复默认" requires the default root to hold only the pinned entries above. If the old copy is still there, the move is refused with a message to clean it up first, rather than merging stale data.

Change scope

  • Modules: agent-gui (Tauri backend + settings UI)
  • Key paths:
    • src-tauri/src/runtime/data_home.rs: data_root(), pointer read/write, env-override detection
    • src-tauri/src/commands/app/data_dir.rs: data_dir_status and data_dir_migrate, validation, copy/verify/rollback
    • config_dir(), the K-brain root, checkpoints, memory, browser profile, sandbox mask and OAuth file store now resolve through data_root()
    • src/pages/settings/DataDirectorySection.tsx, src/lib/system/dataDir.ts, src/i18n/config.ts

Screenshots / preview

Default location:

default

Confirm dialog:

confirm

After migration and restart (custom location; K-brain runs with -data-dir …/LiveAgent):

custom

Verification

  • cargo test --lib filtered to data_dir, data_home, memory, checkpoint, kbrain_backend, browser, sandbox, mcp_oauth and settings::tests: 273 passed. New tests cover:
    • copy and pointer switch
    • extension/worktree left behind
    • old data kept
    • rollback on failure
    • nested, relative and non-empty target rejection
    • moving back to default
  • pnpm lint, pnpm typecheck; node --test test/settings/data-dir.test.mjs: pass
  • End to end in the debug app with an isolated LIVEAGENT_DEV_HOME:
    • migrated the seeded data root;
    • after restart, data_dir_status and the K-brain -data-dir point at the new folder;
    • "恢复默认" with stale default data is refused, and K-brain keeps running on the current root.

Adds a Data Directory settings section that moves the whole LiveAgent
data root (desktop config + K-brain sessions) to a user-chosen folder.
Migration stops K-brain, copies and verifies every file into an empty
target, records it in ~/.liveagent/data-dir.json and restarts. The old
directory is kept. LIVEAGENT_CONFIG_DIR / LIVEAGENT_HOME / K_BRAIN_HOME
still take priority and lock the setting.

Closes #1138
@xiaozhou26
xiaozhou26 merged commit 3e0f186 into main Nov 3, 2026
15 checks passed
@xiaozhou26
xiaozhou26 deleted the feat/custom-data-dir branch November 3, 2026 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] 设置中自定义 v2 数据目录(K-brain sessions 等,目前固定在 ~/.liveagent)

1 participant