2code icon indicating copy to clipboard operation
2code copied to clipboard

Task 9: Delete the Local PTY runtime

Open AkaraChen opened this issue 2 months ago • 0 comments

Summary

Delete the Local PTY runtime for parent plan #436. After Task 8 (#451 on task-8-drop-profiles) sqlite profiles / mapping tables are DROPped, notes live on checkout_notes, and Herdr is already the production default — but TWOCODE_RUNTIME=local / --twocode-runtime=local still constructs LocalAdapter, spawns portable-pty sessions, writes pty_sessions, and keeps a dual-runtime RuntimeRouter. This task removes that second owner: Local adapter, PTY spawn path, Local-only IPC, the env/flag fallback, and the pty_sessions table. Do not leave an unused dual-runtime router "just in case".

A profile remains an open Herdr workspace. The profile id is the Herdr workspace_id (wN). Join key: canonical projects.folder ↔ live checkout / pane cwd (Task 1 contract, docs/herdr-integration.md). projects / project_groups / checkout_notes stay. Do not launch/adopt the project-folder default (Task 10). Do not start a second events.subscribe / name HerdrRuntimeSync in lib.rs. Pin stays v0.9.0. GUI exit still does not server stop. Local must never own a worktree Herdr already owns — after this branch Local cannot own anything.

This branch finishes #446 by deleting the Local-flag path (no git worktree remove from TWOCODE_RUNTIME=local). Do not implement a live-path Local-delete lock instead of deletion. #447 is already closed by Task 6/8 (pane_id / leftover UUID removal); DROP pty_sessions here is leftover-table cleanup, not a session-store rewrite.

Dependencies: Parent plan #436. Prerequisites: #437 (Task 1), #439 (Task 2), #441 (Task 3), #443 (Task 4), #445 (Task 5), #448 (Task 6), #449 (Task 7), #451 (Task 8). Open #438, #440, #442, #444, #450 are line-count tracking only — not blockers. Open #394 issues #395–#434 (including #394 Task 9 / #419, #394 Task 22 / local agent detector, and #403) must not be implemented or closed here.

Work to complete

  1. Remove the Local fallback and Local adapter

    • Delete TWOCODE_RUNTIME=local and --twocode-runtime=local. select_gui_backend / build_gui_runtime / bridge::build_runtime always attach Herdr (ensure_herdr_listener + JSON clients). Do not add a Settings runtime toggle. Do not silently fail over to a Local shell when the sidecar is absent — keep today’s fail-closed HerdrServerAbsent / HerdrServerIncompatible.
    • Delete LocalAdapter and the Local field on RuntimeRouter. Collapse the router to Herdr-only: no with_backend(Local) production path, no Local match arms in create_with_runtime / list_with_runtime / reconcile_profile_checkout / notes / watcher / Git. Remove synthetic default-{project_id} list/create/delete (list_synthetic_local_profiles, reconcile_local_profile_checkout, local_extras_*_closed). Checkout is live Herdr only.
    • Remove RuntimeBackend::Local from production (enum + generated TS union). get_session_backend may be deleted if unused, or may always return Herdr — do not keep a code path that still returns "local". Dual-ownership Local+Herdr refusal becomes vacuous; do not keep unused Local-PTY kill-refusal "just in case".
  2. Delete the PTY spawn path and Local-only IPC

    • Remove portable-pty spawn (infra::pty), Local session lifecycle (service::pty create/restore/close/gc), pty_log files, and Local PtySessionMap / flush-sender / PtyOutputSinks byte plumbing in lib.rs / bridge.rs. Drop mark_all_closed / gc_orphan_logs startup that only served sqlite PTY rows. Shell-init ZDOTDIR injection used only by Local spawn goes with it. Keep Herdr pane.send_input init/startup. Keep list_available_shells (GUI shell picker, not a spawn backend).
    • Local-only IPC is dead: stream_pty_output / Local attach_pty_output sinks, Local restore_pty_session spawn, get_pty_session_history log files, delete_pty_session_record sqlite delete, flush_pty_output as a Local log flush. Keep Herdr-backed commands the GUI already uses (create_pty_session, write_to_pty, resize_pty, close_pty_session, list_project_sessions, stream_herdr_output, Herdr attach). Frontend always uses the Herdr frame stream (startHerdrFrameStream); delete startLocalByteStream and the Local branch in Terminal.tsx.
    • hydrateRestorableSessions always reattaches Herdr pane_id tabs (Task 6). Delete the Local pending-restore path (restorePtySession spawn, sessionHistory sqlite scrollback map). Same New Tab / tab strip clicks and labels. Do not remove the frontend xterm agent detector (detector/ / OSC) — that is #394 Task 22 leftover, not this plan.
  3. DROP pty_sessions

    • New embedded Diesel migration DROPs pty_sessions. Keep projects / project_groups / checkout_notes. Regenerate schema.rs via Diesel; do not hand-edit. Remove repo::pty and Diesel #[diesel(table_name = pty_sessions)] models.
    • IPC DTO PtySessionRecord (id = pane_id, profile_id = workspace_id, …) stays as a derived GUI type from session.snapshot, same as Task 8’s Profile. Decouple it from the dropped table. Herdr still must not INSERT/UPDATE/DELETE sqlite session rows (there are none).
  4. Prove without swallowing Task 10

    • Colocated / integration tests: production constructor has no Local backend; TWOCODE_RUNTIME / --twocode-runtime=local are gone from production source; create_session / New Tab never increment a live portable-pty count; Herdr-down still fail-closes (no Local spawn); list/create/delete/Git/FS/watcher/notes have no Local synthetic default-{project_id} arm; after migrate pty_sessions is absent and projects / checkout_notes remain; Herdr list still live workspace_id / pane_id; production guards (no LocalAdapter, no native_pty_system spawn, no INSERT INTO pty_sessions, no HerdrRuntimeSync name in lib.rs).
    • Rewrite or delete tests that construct RuntimeRouter::with_backend(Local) / TWOCODE_RUNTIME=local / sqlite pty_sessions as the session store. Keep Herdr adapter fakes. Invert frontend transport/restoration tests that mock getSessionBackend("local").
    • Update docs/herdr-integration.md: Task 9 done on this branch; Local PTY / env flag / pty_sessions gone; dual-runtime router not retained. Do not bump v0.9.0. If line count grows past the estimate, open a tracking issue; do not fold Task 10 into this branch.

Likely files and directories

  • Delete: src-tauri/crates/service/src/runtime/local.rs, Local spawn in src-tauri/crates/infra/src/pty.rs / src-tauri/crates/infra/src/pty_log.rs, Local lifecycle in src-tauri/crates/service/src/pty.rs, src-tauri/crates/repo/src/pty.rs. Local-only shell-init injection if unused after spawn removal.
  • New: src-tauri/migrations/<timestamp>_drop_pty_sessions/ — DROP pty_sessions only.
  • Update: src-tauri/crates/model/src/schema.rs (regenerate), src-tauri/crates/model/src/runtime.rs (no Local variant), src-tauri/crates/model/src/pty.rs (DTO, not Diesel table).
  • Update: src-tauri/crates/service/src/runtime.rs — Herdr-only router; delete env/flag parse and Local adapter field.
  • Update: src-tauri/crates/service/src/runtime/herdr.rs, src-tauri/crates/service/src/project.rs, src-tauri/crates/service/src/profile.rs, src-tauri/crates/service/src/filesystem.rs, src-tauri/crates/service/src/watcher.rs — remove Local match arms only; do not change Herdr list/create/close/live-cwd behavior.
  • Update: src-tauri/src/bridge.rs, src-tauri/src/lib.rs, src-tauri/src/handler/pty.rs — drop Local byte sinks / session map; keep Herdr commands.
  • Update frontend: src/features/terminal/lib/terminalTransport.ts, src/features/terminal/Terminal.tsx, src/features/terminal/restoration.ts and colocated tests — Herdr-only transport/reattach.
  • Update: docs/herdr-integration.md — Task 9 done on this branch.
  • Update tests: colocated runtime/profile/project tests plus src-tauri/tests/integration_pty_db.rs, src-tauri/tests/integration_migrations.rs. bun run typegen if IPC signatures change; do not edit src/generated/ by hand.
  • Do not change: Herdr adapter create/list/close/attach internals beyond deleting Local branches, sidecar pin, Settings runtime toggle, launch/adopt on project open (Task 10), Git/file-tree/notes/tab UI redesign, lib.rs naming HerdrRuntimeSync, frontend detector/ agent manifests.

Estimated changes: 700–1100 lines total, additions plus deletions, including tests and migration SQL; excluding generated files, lockfile churn and binary artifacts. Material scope growth should become a separate issue.

Acceptance criteria

  • [ ] Local PTY is gone: no LocalAdapter, no portable-pty spawn, no TWOCODE_RUNTIME / --twocode-runtime=local, no production RuntimeBackend::Local. RuntimeRouter is Herdr-only; there is no unused dual-runtime Local arm.
  • [ ] Diesel migration DROPs pty_sessions. projects / project_groups / checkout_notes remain. sqlite profiles stays absent (Task 8). sqlite profiles is not source of truth.
  • [ ] New Tab / write / resize / close / list / restore use Herdr (pane_id / snapshot). GUI always uses the Herdr frame stream. Local byte stream IPC and sqlite scrollback restore are gone. Herdr-down still fail-closes; it does not spawn a Local PTY.
  • [ ] Profile list/create/delete, Git, file tree, watchers, and notes have no Local synthetic default-{project_id} catalog. Checkout stays live Herdr cwd. projects still round-trip in sqlite.
  • [ ] Named UX exceptions: route ids are workspace_id; tab ids are pane_id; empty Herdr profile list until Task 10; splits flattened as extra tabs; non-git New Profile is folder workspace.create; Herdr-down New Tab errors instead of a Local shell. TWOCODE_RUNTIME=local is gone (not a GUI click/label). Default Herdr New Profile / Delete Profile / tab clicks and labels stay. Do not add a Settings runtime toggle.
  • [ ] No launch/adopt of the project-folder default. No second events.subscribe. lib.rs still does not name HerdrRuntimeSync. Pin stays v0.9.0. GUI exit still does not server stop. Frontend xterm agent detector stays (#394 Task 22 leftover).
  • [ ] Tests: cargo test --workspace from src-tauri (or cargo test --workspace --exclude code where GTK is unavailable). Frontend lint/typecheck/tests for transport/restoration/Terminal scope. bun run typegen if IPC signatures change; do not edit src/generated/ by hand.
  • [ ] No pull request until parent #436 is complete.

Out of scope

  • Launch/adopt of the project-folder default (worktree.open / workspace.create on project open) (Task 10).
  • Reintroducing a Local fallback, Settings runtime toggle, or unused dual-runtime Local arm.
  • Starting a new HerdrRuntimeSync / events.subscribe, changing the v0.9.0 pin, or #394 Task 16 / #432.
  • Removing the frontend xterm agent detector (#394 Task 22).
  • Implementing or closing #394 issues #395–#434 (including #394 Task 9 / #419 and #403) or line-count trackers.
  • Opening a pull request.

Standing constraints

  • Do not treat sqlite profiles as source of truth. Do not add a path cache that can disagree with live Herdr and still win.
  • projects (and project groups / notes-as-2code-data) remain 2code sqlite.
  • Join key remains path ↔ live Herdr cwd/worktree group.
  • Deleting the Local PTY/agent spawn path is in scope. Never let Local and Herdr own the same worktree (Local is removed).
  • Preserve existing 2code interaction. UX change is allowed only when Herdr cannot back the old clicks/labels; this task names no new GUI exception. Removing the Local env/flag is not a click/label redesign.
  • One task; stack on task-8-drop-profiles. Do not open a PR until the parent plan is complete.

AkaraChen avatar Sep 16 '26 10:09 AkaraChen