Skip to content

refactor(desktop): move dev state to per-worktree dev-config/ directory#1475

Closed
Kitenite wants to merge 3 commits into
mainfrom
kitenite/side
Closed

refactor(desktop): move dev state to per-worktree dev-config/ directory#1475
Kitenite wants to merge 3 commits into
mainfrom
kitenite/side

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented Feb 13, 2026

Summary

  • In dev mode, store all desktop app runtime state inside {worktree}/dev-config/ instead of ~/.superset-{workspace}/
  • State directory is now tied to the worktree itself rather than the branch name, preventing orphaned state when branches are renamed or checked out via gh
  • Production behavior is unchanged (~/.superset)

Changes

  • app-environment.ts: SUPERSET_HOME_DIR resolves to {worktree}/dev-config/ when !app.isPackaged. Propagated to child processes via process.env.SUPERSET_HOME_DIR
  • terminal-host/index.ts (daemon): Reads SUPERSET_HOME_DIR from inherited env var, falling back to ~/.superset for production
  • terminal-host/client.ts: Imports SUPERSET_HOME_DIR from app-environment instead of constructing inline
  • terminal-history.ts: getTerminalHistoryRootDir() uses imported SUPERSET_HOME_DIR
  • session-store.ts: Chat session store path uses imported SUPERSET_HOME_DIR
  • setup.ts: User config path uses imported SUPERSET_HOME_DIR
  • shell-wrappers.ts: Shell scripts bake in absolute SUPERSET_HOME_DIR/bin path instead of $HOME/.superset/bin
  • .gitignore: Added dev-config/

Test Plan

  • bun run typecheck passes
  • bun run lint:fix reports no issues
  • Start desktop app in dev — verify dev-config/ is created at worktree root with expected files (local.db, app-state.json, terminal-host.sock, etc.)
  • Open a terminal — verify terminal-host daemon connects (socket at dev-config/terminal-host.sock)
  • Restart the app — verify state persists (terminal history cold restore, chat sessions, auth token)
  • Run a second worktree's dev instance simultaneously — verify no conflicts

Summary by CodeRabbit

  • New Features

    • Added an automated local DB seeding step to the setup flow for easier dev environment initialization.
  • Chores

    • Centralized application home-directory handling with a dev-mode/environment override.
    • Ensure required app directories exist and set permissions on startup.
    • Relocated app/window state, terminal history, session and daemon storage into the centralized app directory.
    • Added dev-config/ to .gitignore.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 13, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Centralizes Superset home directory resolution in app-environment.ts (env/dev/package-aware), exports SUPERSET_HOME_DIR plus new state paths and an ensure function, updates consumers to use it, adds dev-config/ to .gitignore, and adds a local DB seeding step to .superset/setup.sh.

Changes

Cohort / File(s) Summary
Core home resolution & exports
apps/desktop/src/main/lib/app-environment.ts
Add resolveSupersetHomeDir(); export computed SUPERSET_HOME_DIR; add ensureSupersetHomeDirExists(); export APP_STATE_PATH and WINDOW_STATE_PATH; propagate SUPERSET_HOME_DIR to child processes.
Path consumers / terminal & agent
apps/desktop/src/lib/trpc/routers/ai-chat/utils/session-store/session-store.ts, apps/desktop/src/lib/trpc/routers/workspaces/utils/setup.ts, apps/desktop/src/main/lib/agent-setup/shell-wrappers.ts, apps/desktop/src/main/lib/terminal-history.ts, apps/desktop/src/main/lib/terminal-host/client.ts, apps/desktop/src/main/terminal-host/index.ts
Replace per-file homedir + SUPERSET_DIR_NAME logic with centralized SUPERSET_HOME_DIR import/usage; allow process.env.SUPERSET_HOME_DIR override in dev; update derived paths and logging references.
Dev tooling & setup
\.gitignore, .superset/setup.sh
Add dev-config/ to .gitignore; add step_seed_local_db() to .superset/setup.sh to copy $HOME/.superset/local.db (and WAL/SHM) into dev-config/local.db, perform WAL checkpoint and optional migrations, and insert the step into the setup sequence.

Sequence Diagram(s)

sequenceDiagram
  participant ElectronApp as Electron App
  participant Env as app-environment
  participant FS as Filesystem
  participant Child as Child Process

  ElectronApp->>Env: initialize (packaged/dev/env present)
  Env->>FS: resolveSupersetHomeDir() -> check/create dir
  FS-->>Env: dir path / ensure result
  Env->>ElectronApp: export SUPERSET_HOME_DIR, APP_STATE_PATH, WINDOW_STATE_PATH
  ElectronApp->>Child: spawn with env SUPERSET_HOME_DIR
  Child->>FS: read/write sockets, tokens, pid under SUPERSET_HOME_DIR
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • AviPeltz

Poem

"I tidy burrows, one path at a time,
Moved configs to home so everything's in line.
Dev-config waits snug beneath the log,
Local DB hops in — no need to slog.
🐰✨ Hop, seed, and restart — neat as a jog."

🚥 Pre-merge checks | ✅ 2 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Merge Conflict Detection ⚠️ Warning ❌ Merge conflicts detected (20 files):

⚔️ .gitignore (content)
⚔️ .mcp.json (content)
⚔️ .superset/setup.sh (content)
⚔️ .superset/teardown.sh (content)
⚔️ apps/desktop/package.json (content)
⚔️ apps/desktop/scripts/patch-dev-protocol.ts (content)
⚔️ apps/desktop/src/lib/electron-app/factories/app/setup.ts (content)
⚔️ apps/desktop/src/lib/trpc/routers/ai-chat/utils/session-store/session-store.ts (content)
⚔️ apps/desktop/src/lib/trpc/routers/workspaces/utils/setup.ts (content)
⚔️ apps/desktop/src/main/index.ts (content)
⚔️ apps/desktop/src/main/lib/agent-setup/shell-wrappers.ts (content)
⚔️ apps/desktop/src/main/lib/app-environment.ts (content)
⚔️ apps/desktop/src/main/lib/terminal-history.ts (content)
⚔️ apps/desktop/src/main/lib/terminal-host/client.ts (content)
⚔️ apps/desktop/src/main/terminal-host/index.ts (content)
⚔️ apps/desktop/src/main/windows/main.ts (content)
⚔️ apps/desktop/src/renderer/react-query/projects/useReorderProjects.ts (content)
⚔️ apps/desktop/src/renderer/react-query/workspaces/useReorderWorkspaces.ts (content)
⚔️ apps/desktop/src/shared/env.shared.ts (content)
⚔️ bun.lock (content)

These conflicts must be resolved before merging into main.
Resolve conflicts locally and push changes to this branch.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: moving dev state from branch-specific directories to a per-worktree dev-config directory, which is the central objective of this refactoring.
Description check ✅ Passed The PR description is comprehensive and well-structured, covering summary, detailed changes, and test plan. It follows the template structure and provides clear context for all modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kitenite/side

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 13, 2026

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ✅ Neon database branch
  • ✅ Electric Fly.io app
  • ✅ Streams Fly.io app

Thank you for your contribution! 🎉

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @.superset/setup.sh:
- Around line 515-526: The script silently skips WAL checkpointing and migration
re-application when sqlite3 is missing; add an else branch to the existing if
command -v sqlite3 check so that when sqlite3 is not found it emits a clear
warning referencing the variables dest_db and migrations_dir (e.g., "warning:
sqlite3 not installed; cannot checkpoint $dest_db or apply migrations in
$migrations_dir"), so callers know the DB may have stale WAL or an out-of-date
schema; keep current behavior otherwise (do not change the existing sqlite3
commands or their || true handling).

Comment thread .superset/setup.sh
Comment on lines +515 to +526
if command -v sqlite3 &> /dev/null; then
sqlite3 "$dest_db" "PRAGMA wal_checkpoint(TRUNCATE);" &> /dev/null || true

# Source DB may be from a different branch with divergent migrations.
# Re-apply all migration files so the schema matches this branch.
local migrations_dir="packages/local-db/drizzle"
if [ -d "$migrations_dir" ]; then
for migration in "$migrations_dir"/0*.sql; do
sqlite3 "$dest_db" < "$migration" 2>/dev/null || true
done
fi
fi
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

No feedback when sqlite3 is unavailable — DB may be left with stale WAL and wrong schema.

When sqlite3 is not found, both the WAL checkpoint and migration re-application are silently skipped. The seeded DB could contain uncommitted WAL data and a schema that doesn't match the current branch, which is exactly the scenario the migration loop is meant to fix. A warn here would save debugging time.

Proposed fix
   # Checkpoint the copy's WAL (no lock contention since nothing else has it open)
   if command -v sqlite3 &> /dev/null; then
     sqlite3 "$dest_db" "PRAGMA wal_checkpoint(TRUNCATE);" &> /dev/null || true
 
     # Source DB may be from a different branch with divergent migrations.
     # Re-apply all migration files so the schema matches this branch.
     local migrations_dir="packages/local-db/drizzle"
     if [ -d "$migrations_dir" ]; then
       for migration in "$migrations_dir"/0*.sql; do
         sqlite3 "$dest_db" < "$migration" 2>/dev/null || true
       done
     fi
+  else
+    warn "sqlite3 not found — skipping WAL checkpoint and migration replay on seeded DB"
   fi
🤖 Prompt for AI Agents
In @.superset/setup.sh around lines 515 - 526, The script silently skips WAL
checkpointing and migration re-application when sqlite3 is missing; add an else
branch to the existing if command -v sqlite3 check so that when sqlite3 is not
found it emits a clear warning referencing the variables dest_db and
migrations_dir (e.g., "warning: sqlite3 not installed; cannot checkpoint
$dest_db or apply migrations in $migrations_dir"), so callers know the DB may
have stale WAL or an out-of-date schema; keep current behavior otherwise (do not
change the existing sqlite3 commands or their || true handling).

@Kitenite Kitenite force-pushed the kitenite/side branch 4 times, most recently from bfe6aec to a91cadf Compare February 14, 2026 07:26
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.

1 participant