cc-cmd/remote-exp.md

121 lines
3.3 KiB
Markdown

---
description: Enable a remote experiment workflow by patching CLAUDE.md with a Remote Experiment Protocol. Performs remote preflight (mkdir + permission check). Does NOT run any experiments.
allowed-tools:
[
Bash(pwd),
Bash(ls:*),
Bash(cat:*),
Bash(git rev-parse:*),
Bash(sed:*),
Bash(printf:*),
Bash(mkdir:*),
Bash(test:*),
Bash(ssh:*),
Bash(rsync:*),
Bash(scp:*)
]
---
# /remote-exp <HOST> <PATH>
# Purpose: Patch CLAUDE.md to enforce remote experiment workflow (review/edit locally, run experiments remotely).
# This command sets up the protocol. It does NOT execute experiments.
HOST: $1
REMOTE_PATH: $2
## Hard rules (STRICT)
- Do NOT run any experiments in this command.
- This command MAY perform remote preflight: connect via ssh, create REMOTE_PATH if missing, and verify write permission.
- If remote directory creation or write permission check fails (permission, quota, etc.), STOP and report the failure reason to the user.
- Patch CLAUDE.md in a deterministic way using BEGIN/END markers (idempotent).
---
## Step 1: Validate arguments
- If $1 or $2 is missing, ask the user to provide:
- /remote-exp <HOST> <PATH>
HOST parsing rule:
- If HOST looks like "ip:port" (single ":" and port is numeric), then use:
- ssh -p <port> <ip>
- rsync/scp using "-e 'ssh -p <port>'"
- Otherwise use:
- ssh <HOST>
- rsync/scp using "-e ssh"
---
## Step 2: Locate repo root and CLAUDE.md
- Determine repo root via:
- git rev-parse --show-toplevel
- Ensure CLAUDE.md exists at repo root; if missing, create it with a minimal header.
---
## Step 3: Remote preflight (no experiments)
- Connect to remote (ssh) and ensure REMOTE_PATH exists:
- mkdir -p "<REMOTE_PATH>"
- Check write permission:
- test -w "<REMOTE_PATH>"
- If any step fails, STOP and show the exact ssh command used + the stderr reason.
---
## Step 4: Initial sync (code only; still no experiments)
- Sync local repo to remote REMOTE_PATH using rsync (preferred) or scp fallback.
- Exclude:
- .git
- cc-gen-script/
- cc-gen-doc/
- common build artifacts (node_modules, dist, build, __pycache__, .venv, .pytest_cache)
- If rsync is unavailable, fall back to scp (note: scp is slower and may not support excludes; if so, warn and STOP unless the user approves).
---
## Step 5: Patch CLAUDE.md (idempotent)
Insert or replace the following block in CLAUDE.md using markers:
<!-- BEGIN REMOTE-EXP -->
...block...
<!-- END REMOTE-EXP -->
The block must include:
- the resolved HOST and REMOTE_PATH
- the ssh/rsync command templates (with or without -p)
- the workflow rules:
- review & edit locally
- sync to remote before running any heavy experiment
- run experiments only on remote
- pull back results/artifacts/logs to local after experiment
- if remote mkdir/write fails: stop and report
- keep changes visible locally for user review
After patching, print a short summary in chat (what changed, where the protocol lives, and the exact remote target).
---
## Remote Experiment Protocol block (write exactly into CLAUDE.md)
Use the commands computed from HOST parsing:
- SSH_CMD
- RSYNC_SSH
- RSYNC_CMD
The block to insert:
(1) A clear heading
(2) Current remote target
(3) Preflight checks
(4) Sync rules
(5) Results retrieval rules
(6) Failure handling rules
Do NOT include subjective strategy. Keep it operational and objective.