Plan: migrate 2code to Herdr-backed architecture
Make 2code a GUI frontend for Herdr, with Herdr owning terminal processes, runtime session state, agent detection, and workspace/worktree lifecycle.
2code retains its Tauri + React application, project catalog, Git UI, file editor, navigation, and appearance settings. The motivation is to remove duplicated runtime infrastructure and let terminals and agents continue running independently of the GUI.
This plan is based on repository commit fa2465a. Estimates below count additions plus deletions, including tests, but exclude generated files, lockfile churn, and binary artifacts.
Architecture
React frontend ↔ generated Tauri IPC ↔ Rust socket bridge ↔ Herdr server ↔ PTYs and agents.
The Tauri application bundles a pinned Herdr executable as a sidecar. It connects to a compatible server in a dedicated 2code namespace, starting one when necessary. Closing 2code releases client connections; the server continues running. Sidecar packaging must not accidentally tie server lifetime to the GUI process.
Herdr’s control API uses newline-delimited JSON over Unix sockets or Windows named pipes. It provides runtime snapshots, subscriptions, and workspace/worktree operations. Its CLI also documents writable terminal streams with ANSI frames, input, resize, scroll, and release commands. Task 1 must verify these interfaces against the selected release before implementation depends on them. See the socket API and terminal stream reference.
| Responsibility | Owner |
|---|---|
| PTYs, shell processes, terminal lifecycle and runtime persistence | Herdr |
| Agent identity and lifecycle detection | Herdr |
| Workspace and worktree creation, discovery and removal | Herdr |
| Terminal rendering, search, selection, links and appearance | 2code |
| Project catalog, groups, profile notes and application preferences | 2code |
| Git operations, file editing and filesystem watching | 2code |
| Protocol adaptation, connection health and runtime-to-project mapping | 2code Rust bridge |
Proposed mapping: a 2code project remains a repository entry; a profile references a Herdr workspace; terminal tabs reference Herdr terminal/pane identities. Default profiles reference the original checkout. Local database fields describing runtime paths are reconciled caches, not an independent workspace authority.
The initial migration targets local operation. Remote machines and additional Herdr product features belong in later issues.
Implementation tasks
Each task produces a separately reviewable result. Dependencies indicate prerequisites, not permission to combine tasks. Keep the existing runtime available behind a temporary migration switch until the Herdr path passes acceptance checks. Never let both runtimes manage the same terminal or worktree.
-
Verify the Herdr integration contract
Description: Establish a concrete, versioned foundation for the migration.
Plan: Select an exact Herdr release and inspect its bundled schema. Exercise server startup, terminal control/observe, resize, scrollback, detach, reconnect, workspace creation, existing-worktree adoption and removal in an isolated fixture. Record frame semantics, controller exclusivity, identity stability, supported platforms and capability gaps. Define the supported mapping for externally created splits. Any missing prerequisite becomes a blocking sub-issue.
Likely files: New
docs/herdr-integration.md; protocol fixtures under a new Rust integration-test directory.Estimated changes: 200–400 lines. Dependencies: None.
-
Introduce a narrow runtime boundary
Description: Separate runtime operations from existing PTY implementation details.
Plan: Define Rust interfaces and application DTOs for lifecycle, terminal transport and runtime discovery. Adapt the current implementation without changing behavior. Add a temporary backend selector and tests for routing. Keep Herdr wire types inside its adapter.
Likely files: New
crates/service/src/runtime.rsandcrates/model/src/runtime.rs;src-tauri/src/handler/pty.rs; relevant crate exports.Estimated changes: 300–550 lines. Dependencies: 1.
-
Bundle the pinned Herdr sidecar
Description: Make the selected binary available in development and packaged builds.
Plan: Add reproducible, checksum-verified acquisition for supported target triples, license notices and Tauri sidecar configuration. Verify executable discovery and version reporting from a packaged application.
Likely files:
src-tauri/tauri.conf.json,src-tauri/build.rs,scripts/,.github/workflows/release.yml, relevant capabilities.Estimated changes: 150–300 lines. Dependencies: 1.
-
Implement server discovery and startup
Description: Connect 2code to its Herdr server without duplicate launches.
Plan: Implement namespace resolution, connection probing, capability validation, serialized startup and readiness timeouts. Distinguish an incompatible server from an absent one. Verify that GUI exit leaves the server alive and cleans up only client helpers.
Likely files: New
crates/infra/src/herdr/process.rs;src-tauri/src/lib.rs; runtime service wiring.Estimated changes: 250–450 lines. Dependencies: 2, 3.
-
Implement the socket request client
Description: Provide typed control requests over native local transport.
Plan: Add Unix socket and Windows pipe support, incremental framing, request correlation, bounded message sizes, cancellation and structured errors. Test fragmented responses, concurrent requests and disconnects. Do not automatically replay mutations with uncertain outcomes.
Likely files: New
crates/infra/src/herdr/transport.rsand protocol tests; relevantCargo.tomlfiles.Estimated changes: 350–600 lines. Dependencies: 4.
-
Synchronize runtime snapshots and events
Description: Build a recoverable projection of Herdr runtime state.
Plan: Implement subscription acknowledgement, buffered bootstrap and snapshot reconciliation using the verified protocol. Resubscribe and rebuild after disconnection. Test events arriving during bootstrap, stale events and externally removed objects.
Likely files: New
crates/service/src/runtime_sync.rs; Herdr adapter;src-tauri/src/bridge.rs.Estimated changes: 300–500 lines. Dependencies: 5.
-
Persist project-to-runtime associations
Description: Associate existing 2code metadata with Herdr objects.
Plan: Add an additive mapping migration containing server namespace and runtime identifiers. Preserve project/profile IDs, notes and ordering. Handle missing or replaced runtime identities explicitly; never identify a workspace by its display name alone.
Likely files:
src-tauri/migrations/;crates/model/src/;crates/repo/src/; migration tests.Estimated changes: 200–350 lines. Dependencies: 2, 6.
-
Adopt existing profiles and worktrees
Description: Connect existing checkouts to Herdr without recreating them.
Plan: Implement resumable adoption for default profiles and existing worktree profiles. Resolve canonical paths, reuse matching associations and record progress after each successful operation. Test interruption and retry without duplicate workspaces or filesystem changes.
Likely files: New migration service;
crates/service/src/profile.rs; runtime mapping repository.Estimated changes: 300–500 lines. Dependencies: 7.
-
Implement Herdr terminal lifecycle commands
Description: Create, enumerate and explicitly close terminals through Herdr.
Plan: Adapt terminal creation and listing to runtime identities. Reuse any root pane returned during workspace/tab creation. Separate releasing a GUI attachment from terminating a terminal. Reconcile ambiguous creation/close outcomes before retrying.
Likely files: Runtime service and Herdr adapter;
src-tauri/src/handler/pty.rs; application DTOs.Estimated changes: 250–450 lines. Dependencies: 5, 7, 8.
-
Bridge live terminal frames into Tauri
Description: Deliver interactive terminal transport without local PTY ownership.
Plan: Implement the terminal control/observe transport selected in task 1, using the pinned CLI helper if needed. Forward decoded frames through Tauri channels and input/resize/release through the bridge. Bound buffering and test split frames, slow consumers, controller conflicts and helper shutdown.
Likely files: New
crates/infra/src/herdr/terminal.rs;src-tauri/src/bridge.rs; terminal handlers.Estimated changes: 350–600 lines. Dependencies: 4, 9.
-
Connect xterm.js to the Herdr transport
Description: Render one Herdr-backed terminal end to end.
Plan: Replace backend-specific calls with a frontend transport adapter. Apply verified frame semantics, coordinate terminal query responses and route keyboard, paste, mouse and resize input correctly. Preserve mounted terminals when switching tabs.
Likely files:
src/features/terminal/Terminal.tsx; new terminal transport module;lib/resizeScheduler.ts;Terminal.test.tsx.Estimated changes: 350–600 lines. Dependencies: 10.
-
Restore terminals by reattachment
Description: Recover the UI from Herdr state rather than respawning shells.
Plan: Rebuild tabs from runtime discovery and attach existing terminals on application reopen. Remove legacy history replay and serialized-buffer restoration from the Herdr path. Define scrolling, history access and search behavior using the verified stream; test reconnect without repeated output or startup commands.
Likely files:
terminal/restoration.ts,store.ts,Terminal.tsx,lib/terminalStorage.ts,projects/ProfileLayout.tsx; related tests.Estimated changes: 300–550 lines. Dependencies: 6, 11.
-
Drive agent indicators from Herdr
Description: Replace local detection with server-provided agent state.
Plan: Map identity and lifecycle states into existing badges and notifications. Define handling for unknown states, viewed completions and reconnects. Stop invoking the local detector for Herdr terminals; test duplicate-notification prevention.
Likely files:
terminal/Terminal.tsx,state.ts,store.ts,AgentStatusDot.tsx,lib/agentNotification.ts; sidebar consumers.Estimated changes: 200–400 lines. Dependencies: 6, 12.
-
Create profiles through Herdr worktree management
Description: Delegate new worktree and workspace creation.
Plan: Replace direct worktree creation with Herdr operations. Translate branch and directory preferences where supported. Preserve setup behavior with one explicit execution owner. Reconcile partial success before updating local metadata or retrying.
Likely files:
crates/service/src/profile.rs;handler/profile.rs;features/profiles/hooks.ts;settings/WorktreeSettings.tsx; configuration adapter.Estimated changes: 300–550 lines. Dependencies: 8, 9.
-
Delegate profile and project runtime cleanup
Description: Route workspace/worktree removal through Herdr.
Plan: Preserve dirty-file and unpushed-commit checks. Define teardown ordering and distinguish forgetting a project from deleting its worktrees. Remove local metadata only after confirmed cleanup or an explicit retained-worktree outcome. Test failures and repeated requests.
Likely files:
crates/service/src/profile.rsandproject.rs; profile/project handlers;DeleteProfileDialog.tsx,DeleteProjectDialog.tsx.Estimated changes: 300–500 lines. Dependencies: 14.
-
Reconcile workspace paths for Git and the editor
Description: Keep retained features pointed at the correct checkout.
Plan: Reconcile Herdr workspace paths into profile projections. Update Git, filesystem, watcher and terminal-link consumers when associations change. Handle unavailable workspaces without falling back to a different checkout.
Likely files:
crates/service/src/project.rs; profile repository;handler/filesystem.rs,handler/watcher.rs; project query hooks;src/shared/lib/queryKeys.ts.Estimated changes: 250–450 lines. Dependencies: 6, 8, 14.
-
Preserve shell and template behavior
Description: Carry supported launch preferences into Herdr.
Plan: Map shell selection, working directory, environment and startup commands. Ensure commands execute once on creation and never on reattachment. Document or resolve unsupported configuration discovered in task 1 before cutover.
Likely files:
terminal/hooks.ts,templates.ts,terminalTemplateActions.ts; terminal settings; runtime adapter;crates/infra/src/config.rs.Estimated changes: 200–350 lines. Dependencies: 9, 12.
-
Expose runtime health and recovery
Description: Make runtime availability understandable and recoverable.
Plan: Show starting, connected, disconnected and incompatible states. Disable writes while disconnected and provide reconnection actions. Surface terminal controller conflicts without silently taking control. Distinguish GUI reconnection from server restart.
Likely files: New runtime frontend feature; terminal actions; settings UI;
messages/en.json,messages/zh.json.Estimated changes: 200–350 lines. Dependencies: 4, 6, 11.
-
Implement legacy-session migration and rollback
Description: Move existing installations onto Herdr safely.
Plan: Add an idempotent migration checkpoint and preserve database/history backups. Present legacy sessions as restartable entries or archives; do not claim live process transfer. Verify rollback before cutover and prevent legacy restoration from duplicating migrated sessions. Keep historical migrations intact.
Likely files: Migration service;
crates/repo/src/pty.rs;terminal/restoration.ts; migration UI and documentation.Estimated changes: 300–550 lines. Dependencies: 8, 12, 15, 17, 18.
-
Add migration acceptance coverage
Description: Verify the integrated runtime against real Herdr.
Plan: Extend isolated integration and Selenium smoke tests for create/type/resize, app close/reopen, reconnection, external runtime changes, profile lifecycle and Git/editor paths. Include sustained output and multiple terminals with recorded latency/memory baselines. Add packaged macOS verification and Linux/Windows transport checks.
Likely files: Rust integration tests; colocated frontend tests;
e2e-tests/;.github/workflows/unit-tests.yml,tauri-smoke.yml,release.yml.Estimated changes: 400–650 lines. Dependencies: 13–19.
-
Make Herdr the default runtime
Description: Enable the migration after acceptance evidence is reviewed.
Plan: Switch the default, activate the migration entry point and document recovery procedures. Verify clean installation and upgrade separately. Retain the temporary rollback path for the agreed validation window.
Likely files: Runtime selection and startup wiring; migration entry point;
README.md; architecture/configuration documentation.Estimated changes: 100–200 lines. Dependencies: 20.
-
Remove the local agent detector
Description: Delete detection code after Herdr state parity is accepted.
Plan: Remove the detector engine, rules and obsolete tests; retain shared presentation types where still needed. Confirm no terminal-output parsing remains responsible for agent lifecycle.
Likely files:
src/features/terminal/detector/; terminal imports and tests.Estimated changes: 1,900–2,200 lines, predominantly deletions. Dependencies: 21 and completed rollback window.
-
Remove the legacy PTY runtime
Description: Finish transferring process and session ownership.
Plan: Delete local PTY spawning, read loops, output logging, shell injection, shutdown cleanup and obsolete dependencies. Remove runtime persistence writers and remaining backend selection. Preserve migration readers and historical user data until their retention policy permits removal. Split service and infrastructure deletion into separate sub-issues if needed.
Likely files:
crates/{infra,service,repo,model}/src/pty.rs;infra/src/pty_log.rs,shell_init.rs;handler/pty.rs;bridge.rs;lib.rs; Cargo manifests.Estimated changes: 2,400–3,500 lines, predominantly deletions. Dependencies: 22.
Execution workflow
- Astra opens one sub-issue at a time, linked to this parent, with exact scope, prerequisites, expected behavior, tests and exclusions.
- Grok 4.6 implements that sub-issue via
/goal. The goal is the individual task, not the entire migration. - Astra reviews the resulting diff, checks ownership boundaries, runs relevant verification and requests corrections where necessary.
- The next task starts only after the current task is accepted and landed. Update this parent with sub-issue links and completion status.
- Each implementation issue includes appropriate checks from
bun run lint:check,bun run typecheck,bun run test, andcargo test --workspaceinsrc-tauri. IPC changes usebun run typegen; generated bindings are never edited manually. - Capability gaps or materially larger changes become separate issues before dependent work proceeds. Cleanup-only tasks may have large deletion counts while remaining narrow in behavior.
Acceptance criteria
- Herdr exclusively owns PTYs, running agents, runtime session persistence, detection and workspace/worktree lifecycle.
- Closing or crashing the GUI leaves running terminals available; reopening reattaches without duplicate processes or startup commands.
- Server restart recovery follows Herdr’s supported restore behavior and is distinguished from preserving a live process across GUI disconnects. See Herdr session recovery.
- Terminal input, paste, Unicode, colors, alternate-screen applications, resize, scrolling, search and links pass agreed compatibility checks.
- Runtime synchronization handles bootstrap races, disconnections and external changes without stale terminal ownership or duplicate notifications.
- Existing projects, groups, notes, worktrees and uncommitted files survive migration. Interrupted migration can resume safely.
- Git, editor, file-tree and watcher operations use the correct workspace checkout.
- Packaged macOS builds work without a separately installed Herdr. Existing experimental Linux and Windows builds retain verified packaging and transport support.
- Integration tests and desktop smoke checks pass; sustained terminal output causes no unbounded bridge buffering or agreed performance regression.
- Legacy runtime and detector code are removed after the rollback window, and architecture, configuration and recovery documentation describe the final system.