Skip to content

feat(remote): provision daemon-created worktrees like the desktop#90

Merged
Zeus-Deus merged 1 commit into
mainfrom
feature/78-remote-headless-daemon-worktree-creation-run-setup-scripts
Jun 9, 2026
Merged

feat(remote): provision daemon-created worktrees like the desktop#90
Zeus-Deus merged 1 commit into
mainfrom
feature/78-remote-headless-daemon-worktree-creation-run-setup-scripts

Conversation

@Zeus-Deus

Copy link
Copy Markdown
Owner

Closes #78

Summary

The headless daemon's worktree_create MCP tool now runs the same post-create pipeline as the desktop, so workspaces created on a remote host are provisioned (deps, .env, env vars, port) and start from the latest remote commit.

  • Shared setup core: crate::scripts::run_setup_commands is a new UI-free extraction of the setup-command loop. The desktop's run_setup_scripts_with_config is now a thin wrapper that forwards SetupEvents as the unchanged Tauri events — one command loop for both paths, no duplication.
  • Daemon provisioning (remote/tools/mod.rs::provision_worktree_workspace):
    • gitignored include files (.env & co, .codemuxinclude → defaults) are copied from the parent repo synchronously, before the tool returns
    • .codemux/config.json setup commands run on a detached background thread with CODEMUX_ROOT_PATH / CODEMUX_WORKSPACE_PATH / CODEMUX_BRANCH / CODEMUX_PORT (+ NAME/ID), using the same deterministic allocate_workspace_port as the desktop
    • the tool response gains a setup summary: {port, includes_copied, setup_commands, setup_running}
    • progress/failures log to the daemon's stderr (journal); a failing setup script never fails the tool call
  • Fetch-before-branch already landed in remote/git.rs ([git] Fetch origin before creating a new workspace branch so it starts from the latest remote #76 parity); this PR covers it end-to-end through the daemon.
  • Test hygiene: the serve-test fixture now isolates HOME, so the integration suite stops rewriting the developer's real agent configs (~/.claude.json, …) with paths to transient debug binaries. The commands::mcp discovery test is scoped to project-level sources so a legitimate user-level codemux entry no longer fails it.

Headless config is file-based only (.codemux/config.json in worktree → repo root) — the Settings-UI fallback lives in the desktop SQLite DB, which doesn't exist on a headless host.

Acceptance criteria

  • Remote-created workspaces run the project's setup script (deps/.env provisioned)
  • Remote-created new branches start from freshly-fetched origin/<base>
  • CODEMUX_* env vars + a unique port are present for remote workspaces
  • Graceful behavior with no setup script / offline host (tool succeeds, falls back to local refs)

Testing

  • Unit (remote/tools/mod.rs): setup script runs with correct CODEMUX_* env + reported port, .env copied; no-config repo reports setup_commands: 0; failing setup script doesn't fail the tool.
  • Integration (tests/codemux_remote_serve_mcp.rs::http_worktree_create_provisions_like_desktop): real daemon over HTTP with a stale-clone scenario — new branch lands on the freshly-fetched origin tip (not the stale local ref), includes copied, setup marker written with correct env.
  • Live E2E: built codemux-remote and ran it in an Arch container as the remote host, driven over HTTP with curl — verified fresh-tip branching, .env copy, env marker, sequential multi-command setup, graceful no-config repo, and offline-origin fallback.
  • npm run verify fully green (all cargo suites, typecheck, 1826 frontend tests).

Docs updated: docs/core/STATUS.md, docs/features/setup-teardown.md (§ Headless Daemon Parity), docs/features/worktree-setup.md, docs/features/remote-hosts.md, docs/plans/mcp-on-remote.md.

The headless daemon's worktree_create tool now runs the same
post-create pipeline as the desktop (issue #78): gitignored include
files are copied from the parent repo before the tool returns, and the
project's .codemux/config.json setup commands run on a background
thread with the standard CODEMUX_* env and the deterministic
per-workspace port. Combined with the existing fetch-before-branch in
remote/git.rs, remote-created workspaces are provisioned and start
from the freshly-fetched origin tip.

- extract a UI-free run_setup_commands core in scripts.rs; the
  desktop's run_setup_scripts_with_config is now a thin wrapper that
  forwards SetupEvents as the unchanged Tauri events
- provision_worktree_workspace in remote/tools/mod.rs wires the shared
  core into the daemon: includes copy runs inline, setup commands run
  detached, progress logs to stderr, and a failing setup script never
  fails the tool; the response gains a `setup` summary
  ({port, includes_copied, setup_commands, setup_running})
- isolate HOME in the serve-test fixture so the integration suite
  stops rewriting the developer's real agent configs with paths to
  transient debug binaries
- scope the project_codemux_entry_is_filtered_out assertions to
  project-level sources so a legitimate user-level codemux entry no
  longer fails the discovery test
- cover the parity end-to-end: unit tests for env/includes/graceful
  paths plus a stale-clone HTTP integration test against the real
  daemon
@Zeus-Deus Zeus-Deus merged commit 7c64f1e into main Jun 9, 2026
4 checks passed
@Zeus-Deus Zeus-Deus deleted the feature/78-remote-headless-daemon-worktree-creation-run-setup-scripts branch June 9, 2026 22:09
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.

[remote] Headless daemon worktree creation: run setup scripts + fetch-before-branch (desktop parity)

1 participant