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

Task 1: Rewrite the integration contract for client-mode

Open AkaraChen opened this issue 2 months ago • 0 comments

Summary

Rewrite the Herdr integration contract for parent plan #436 client-mode. The additive stack on task-17-shell-templates (PR #435 / #394) still treats Local as default, sqlite profiles as catalog rows, and profile_runtime_mappings / session_runtime_mappings / profiles.worktree_path as association caches. This task inverts that architecture in the contract, without switching production defaults or deleting those tables yet.

Keep the pinned Herdr v0.9.0 Linux probe (JSON protocol 22, endpoint generation 1). Do not re-prove frame semantics, controller exclusivity, DSR/DA, or sidecar checksums already recorded in docs/herdr-integration.md and herdr_contract.rs. Reuse that evidence. Replace the #394 mapping ("Local default, mapping tables, path cache") with this plan: a 2code project stays a sqlite row; a profile is a Herdr workspace (workspace_id), derived live from worktree.list / workspace.list / session.snapshot keyed by the project's repo path; sqlite profiles is not source of truth.

Linux live probe against the existing pin. Docs + tests only.

Dependencies: Parent plan #436. No prerequisite #436 sub-issues. Checkout base: task-17-shell-templates (PR #435). Open #394 issues #395–#434 do not block this rewrite and must not be implemented or closed here.

Work to complete

  1. Replace the #394 architecture mapping

    • Update docs/herdr-integration.md so later #436 tasks depend on this contract, not Local-default / mapping-table / path-cache rules from #394.
    • Keep the pin table, checksums, reproduction, JSON/CLI transports, frame semantics, exclusivity, and lifecycle evidence. Do not bump the pin off v0.9.0. Do not retarget latest.
    • Decision for this plan: proceed on Linux x86_64 (executed) for #436 Tasks 2–10, gated only on capabilities this probe marks verified. Remap every "Task N" / Blocked / Later-task row that still numbers #394 Tasks 2–23 so it names #436 tasks (or explicitly "#394 leftover, not this plan").
    • Record that Herdr is the intended default runtime for this plan. Do not change RuntimeRouter::new (still Local). Switching the default is Task 2.
    • State that Local may remain only as an explicit fallback until Task 9 deletes it, and that Local must never own a worktree/workspace Herdr already owns.
  2. Document project ↔ Herdr binding (path → worktree group)

    • Join key: canonical absolute projects.folder ↔ Herdr checkout path / workspace cwd. No parallel sqlite worktree_path (or mapping row) that can disagree with live Herdr and still win.
    • A 2code profile id is the Herdr workspace_id (stable wN in a session; restored across server restart per existing identity table). It is not a UUID 2code mints into profiles.id.
    • Default checkout for a project: the open Herdr workspace whose checkout path is the project folder (primary / non-linked).
    • Linked git worktrees are additional profiles in the same repo group (worktree.create / is_linked_worktree).
    • Non-git project folders: workspace.create (not worktree.*). Probe this on a disposable non-git directory and record whether worktree.list is inapplicable.
    • Empty Herdr (no open workspaces for that path) → empty profile list for that project. Do not fall back to leftover sqlite profiles rows. Task 10 later starts/adopts a workspace so the GUI is not stuck empty; this task only documents the empty case.
    • Git worktrees that exist on disk but are not open in Herdr (open_workspace_id absent) are not profiles until worktree.open / Task 10. Listing them as sqlite-style profiles is a contract failure.
  3. Linux live probe: list/join payloads

    • Extend herdr_contract.rs with a focused probe (new test, not a rewrite of frame/controller tests). Same harness isolation: short /tmp sockets, disposable repo, HERDR_CONTRACT_REQUIRED=1, never the user default session.
    • Exercise JSON (not only CLI) worktree.list with absolute cwd = the disposable repo, and workspace.list / session.snapshot.
    • Sequence: empty server → list (no open workspaces) → workspace.create --cwd primary → worktree.create linked → list again. Capture sanitized fixtures of list/snapshot entries (path, branch, open_workspace_id / workspace_id, is_linked_worktree, cwd, and repo_key if present).
    • Prove the group is repo-scoped: a second disposable repo's workspaces do not appear in the first repo's worktree.list.
    • Re-open / already_open must keep the same workspace_id (already verified for worktree.open; confirm the list/snapshot still keys the profile as that id).
    • Require worktree.list and workspace.list in the schema-excerpt method check if they are not already required.
    • If v0.9.0 cannot join by path the way #436 needs, file a blocking gap issue and mark the contract block for Tasks 3–4/10. Do not invent a sqlite cache to paper over it. Do not change the pin to another release inside this task without recorded evidence and a separate issue.
  4. Inventory sqlite tables that die vs stay

    • Stay (2code authority): projects, project_groups.
    • Die as authority (later #436 tasks, not this PR): profiles (Task 8), profile_runtime_mappings (Task 5), session_runtime_mappings (Task 6), pty_sessions as the Herdr session store (Task 6), and herdr_namespaces if it exists only to scope those mappings.
    • profiles.worktree_path / branch_name / is_default are not path or profile authority. Default checkout is Herdr's workspace at the project folder.
    • Notes: parent plan keeps notes as a 2code feature. Today they live on profiles.notes. Record that they cannot remain on profiles after Task 8; moving them to a project- or workspace_id-keyed 2code table is not this task. Do not store notes in Herdr.
    • One-shot import of existing sqlite profiles into Herdr is allowed in Task 5 or 6; this task only says those rows are ignored as source of truth after import.
  5. Prove docs/tests only

    • No production adapter, handler, frontend, Diesel migration, or RuntimeRouter default change.
    • Do not INSERT/DELETE profiles, drop mapping tables, spawn Local PTYs from the probe except as already required by the existing harness, or call server.stop against a non-fixture socket.
    • Existing cargo test -p infra --test herdr_contract coverage must keep passing. New live tests skip without the binary unless HERDR_CONTRACT_REQUIRED=1.
    • If the line count of this rewrite grows past the estimate below, open a tracking issue; do not fold Task 2+ into this branch.

Likely files and directories

  • Update: docs/herdr-integration.md — client-mode mapping, join key, table inventory, #436 task gating, proceed/block decision. Keep pin/reproduction/frame/lifecycle sections unless a live finding contradicts them (then mark verified vs superseded, do not silently delete evidence).
  • Update: src-tauri/crates/infra/tests/herdr_contract.rs — path→group list/snapshot probe; require worktree.list / workspace.list in the schema method list.
  • New fixtures as needed: src-tauri/crates/infra/tests/fixtures/herdr/ — sanitized worktree.list / workspace.list / snapshot excerpts for the join key (no user paths).
  • Update if the excerpt must list the join methods: schema-excerpt.json.
  • Do not change: src-tauri/crates/service/src/runtime.rs default Local, mapping repos, profiles migrations, frontend profile switcher, PTY/Local adapters, sidecar acquisition.

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

Acceptance criteria

  • [ ] The contract documents client-mode: projects stay sqlite; a profile is a Herdr workspace_id; listing/create/delete/restore go through Herdr; sqlite profiles is not source of truth.
  • [ ] Join key is canonical project folder path ↔ live Herdr checkout/cwd (worktree group). No sqlite worktree_path / mapping table is documented as authority.
  • [ ] Tables that die vs stay are explicit and mapped to later #436 task numbers. pty_sessions is not the Herdr session store. Notes-on-profiles is called out as dying with that table.
  • [ ] Linux live probe (pinned v0.9.0, not latest) captures worktree.list / workspace.list / session.snapshot evidence for empty server, primary workspace, linked worktree, second-repo isolation, and non-git workspace.create. Sanitized fixtures exist. Reproduction still uses HERDR_CONTRACT_REQUIRED=1 and cleans up sockets/state.
  • [ ] Disk git worktrees without an open workspace_id are not profiles. Empty Herdr → empty profile list (no sqlite fallback) is explicit.
  • [ ] #394 task numbering in the contract is remapped or labeled leftover. Proceed/block for #436 Tasks 2–10 is explicit. New capability holes are linked blocking issues, not silent passes.
  • [ ] Production default remains Local on this branch. No GUI, migration, or Local/PTY deletion. Existing contract tests still pass: HERDR_CONTRACT_REQUIRED=1 cargo test -p infra --test herdr_contract -- --nocapture --test-threads=1. If Rust/docs-only: cargo test --workspace from src-tauri (or --exclude code where GTK is unavailable). Frontend lint/typecheck/tests only if frontend scope is introduced (none expected).
  • [ ] Another developer can rerun the new probe from the doc and clean up its processes, endpoints, and temp state.

Out of scope

  • Making Herdr the default runtime (Task 2), including env/flag fallback wiring beyond documenting that it will exist.
  • Sidebar/profile switcher reading Herdr (Task 3), create/delete through Herdr in the GUI (Task 4), dropping mapping writes (Task 5), session restore from snapshot (Task 6), Git/file-tree path consumers (Task 7), dropping profiles (Task 8), deleting Local PTY (Task 9), launch/adopt on project open (Task 10).
  • Production sidecar, socket client, sync, or adapter behavior changes.
  • Implementing or closing #394 issues #395–#434 (including remaining #394 Tasks 18–23, gap issues, and line-count trackers).
  • Remote Herdr machines.
  • Opening a pull request (parent plan: no PR until #436 is complete).

Standing constraints

  • Do not treat sqlite profiles as source of truth in this contract.
  • projects (and project groups / notes-as-2code-data) remain 2code sqlite.
  • Join key is path ↔ live Herdr cwd/worktree group. No competing worktree_path authority.
  • Switching the default runtime is in scope for Task 2, not this task. Deleting Local PTY / profiles rows is in scope for Tasks 8–9, not this task.
  • Never let Local and Herdr own the same worktree.
  • Preserve existing 2code interaction (project list, profile switcher, create/delete profile, Git, file tree, notes, terminal tabs). Do not redesign those flows. UX change is allowed only when Herdr cannot back the old clicks/labels; that exception must be named in the sub-issue that needs it. This task has no UX.
  • One task; stack on task-17-shell-templates. Do not open a PR until the parent plan is complete.

AkaraChen avatar Sep 16 '26 02:09 AkaraChen