Proposal: crabbox watch, a live edit-save-rerun loop on a warm lease
Note: I would like to build this feature myself and will submit the PR. Please do not pick this up; I am filing the proposal first so maintainers can shape the design before any code exists.
cc @steipete
Problem
The performance guide documents the hot iteration loop as a manual workflow: warm a lease once, then re-run crabbox run --id <slug> -- <command> after every local edit (docs/performance.md, "Warm leases"). Everything expensive about that loop is already solved: fingerprint sync skips rsync on no-op runs, git seeding plus dirty overlay ships only diffs, and SSH connection multiplexing keeps reruns cheap. What is missing is the automation: watching the local checkout and re-driving the loop on save.
Proposal
crabbox watch [run flags] -- <command...>
crabbox watch --id swift-crab --debounce 300ms -- pnpm test:changed
Behavior:
- With
--id, reuse a warm lease under the existing claim rules. Without it, acquire a fresh lease held for the loop and released on exit (--keepto retain). - Run the command once immediately, then watch the repository root with fsnotify. Events are filtered through the same exclude logic sync already uses (built-in excludes,
sync.exclude,.crabboxignore), so ignored churn such asnode_modulesnever triggers a run. - Debounce and coalesce changes (default 250ms). A change arriving mid-run cancels the in-flight command and restarts;
--no-interruptqueues a single rerun instead. - Each iteration goes through the normal run pipeline against the held lease, so run IDs,
attach,events, results, artifacts, and history work unchanged. Iterations get an automatic label for readable history. - First Ctrl-C cancels the in-flight run; a second exits the loop and applies the lease release policy.
Cost stance: a watch loop must not keep a large box alive unattended. The loop exits on its own after a configurable period with no file changes (--idle-exit, default aligned with the lease idle timeout), releasing any lease it acquired.
Scope for the first PR: SSH-lease providers with crabbox-sync only, dispatched by capability per docs/vision.md; delegated providers get a clear error pointing at run. Interrupt-on-change is POSIX-only initially, with queue mode as the Windows fallback. No hooks, no extra UI. New internal/cli/watch.go plus tests and a command doc; no changes to the run orchestrator beyond what lease-id injection needs.
Questions for maintainers
- Command shape: a new
crabbox watchcommand, or a--watchflag onrun? - Is cancel-and-restart the right default when a change lands mid-run, or should queue-until-finished be the default?
- Is aligning
--idle-exitwith the lease idle timeout the right cost stance, or should watch require an explicit opt-in to hold a lease longer?
If the direction looks right I will follow up with a bounded PR including regression tests and a recorded before/after demo of the loop.
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed July 2, 2026, 1:24 PM ET / 17:24 UTC.
Summary Current main still only supports the manual warm-lease rerun loop; the requested live file-watch loop is a new CLI feature with explicit maintainer design questions, so it should stay open for product direction rather than cleanup closure.
Reproducibility: not applicable. this is a feature proposal, not a bug report. Source and docs inspection confirms current main supports the manual warmup plus run --id loop but not an automated file-watch loop.
Ways to help us reproduce this
- Add a screenshot or short recording showing the behavior.
- Add expected vs actual behavior.
Next step This should stay with maintainers because the reporter explicitly requested design guidance before submitting code, and the blocker is command/API policy rather than a narrow repair.
Review details
Best possible solution:
Keep this as a maintainer-shaped feature proposal; if approved, implement a provider-neutral watch path using existing run, sync, lease, and capability APIs with focused CLI tests and command docs.
Do we have a high-confidence way to reproduce the issue?
Not applicable; this is a feature proposal, not a bug report. Source and docs inspection confirms current main supports the manual warmup plus run --id loop but not an automated file-watch loop.
Is this the best way to solve the issue?
Unclear until maintainers choose the CLI shape and defaults. A provider-neutral internal/cli implementation dispatched by sync/run capabilities looks aligned, but cancel-vs-queue and idle-exit behavior need product direction first.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
- The command shape, interrupt default, idle-exit policy, and Windows fallback are still product decisions rather than implementation details.
- A watch loop could keep expensive leases alive or generate confusing run history if idle and restart semantics are not deliberately specified.
Codex review notes: model internal, reasoning high; reviewed against a28b457ccdeb.
Label changes
Label changes:
- add
P3: This is a useful but speculative new CLI workflow proposal with no broken existing behavior or urgent regression. - add
issue-rating: 🌊 off-meta tidepool: Current issue advisory state selects this label. - add
clawsweeper:no-new-fix-pr: Current issue advisory state selects this label. - add
clawsweeper:needs-maintainer-review: Current issue advisory state selects this label. - add
clawsweeper:needs-product-decision: Current issue advisory state selects this label.
Label justifications:
P3: This is a useful but speculative new CLI workflow proposal with no broken existing behavior or urgent regression.
Evidence reviewed
What I checked:
- Repository policy read: AGENTS.md was read in full; its guidance to keep CLI behavior near internal/cli, preserve generic Crabbox positioning, and keep core provider-neutral applies to this feature review. (
AGENTS.md:1, a28b457ccdeb) - Issue asks for maintainer-shaped feature work: The issue body says the reporter wants to build the feature after maintainers shape the design, then asks questions about command shape, interrupt default, and idle-exit cost stance.
- No watch command is registered on current main: The Kong command tree lists warmup, run, sync-plan, history, events, attach, and other top-level commands, but no watch command. (
internal/cli/cli_kong.go:14, a28b457ccdeb) - No watch implementation or docs files exist: The repository has no internal/cli watch implementation or docs/commands watch page; search hits for watch are unrelated lease watchers, logs wording, or dependency checksums. (a28b457ccdeb)
- Current docs document the manual warm-lease loop: The performance guide describes repeated loops as
warmuponce and reruncrabbox run --id ...manually; it also documents automatic idle release for untouched warm leases. (docs/performance.md:31, a28b457ccdeb) - Existing sync behavior supplies some proposed building blocks: The sync docs show current exclude handling, fingerprint skip behavior, git seeding, rsync manifest flow, and SSH-lease-only sync ownership that a future watch command would need to reuse. (
docs/features/sync.md:9, a28b457ccdeb)
Likely related people:
- steipete: Authored the current docs/vision.md, docs/performance.md warm-lease guidance, command registry baseline, and sync docs via the merge commit for https://github.com/openclaw/crabbox/pull/708; also recently touched repo/config behavior relevant to run setup in https://github.com/openclaw/crabbox/pull/743. (role: feature-history owner; confidence: high; commits: 5001cd1179a4, d4df5141d04b; files:
docs/vision.md,docs/performance.md,internal/cli/cli_kong.go) - TurboTheTurtle: Authored the recent run event lease audit retagging fix in https://github.com/openclaw/crabbox/pull/745, which is adjacent because watch iterations would rely on run events, run IDs, and lease audit behavior. (role: recent run-history contributor; confidence: medium; commits: e0d13b3af5ea; files:
internal/cli/run.go) - yetval: The issue body explicitly says they want to submit the PR after maintainers shape the design, making them relevant for follow-up even though no current-main ownership was found. (role: proposal author and intended implementer; confidence: medium)
How this review workflow works
- ClawSweeper keeps one durable marker-backed review comment per issue or PR.
- Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
- A fresh review can be triggered by eligible
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch. - PR/issue authors and users with repository write access can comment
@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only. - Maintainers can also comment
@clawsweeper reviewto request a fresh review only. - Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
- Maintainer-only repair and merge flows require explicit commands such as
@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review. - Maintainers can comment
@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.
Direction approved. Please use a new crabbox watch command rather than a run --watch mode: this is a long-lived local supervisor with its own lifecycle, idle, signal, and scheduling semantics, while each iteration should still call the existing run path.
For v1, make queue-and-coalesce the default. Do not overlap runs. A file change during an active run should queue exactly one rerun using the newest tree. Current cancellation only terminates the local SSH process; remote process termination is not a provider-neutral contract. Defer interrupt-on-change until that contract exists. One Ctrl-C should exit the watch loop and apply the lease ownership rules; no two-interrupt state machine.
--idle-exit should default to the effective lease idle timeout. Track local qualifying filesystem activity independently, so run/claim bookkeeping cannot keep an abandoned watcher alive. Require a positive value no longer than the effective lease idle timeout; longer sessions must explicitly raise both limits and remain bounded by TTL.
V1 acceptance boundary:
- SSH-lease backends advertising
crabbox-sync; capability dispatch only, no provider-name branches. --idreuses an existing claimed, user-owned lease and does not release it by default. Without--id, acquire once and release on every exit path unless--keepis explicit.- Initial run immediately; default
--debounce=250ms; recursively watch the repository root and newly created directories without following symlink directories outside the root. - Qualify events against the exact sync universe: Git tracked/nonignored files plus built-in, config, and
.crabboxignorerules; reload filters when their source files change. Ignored churn does not trigger a run or reset idle time. - At most one active run plus one pending rerun. A nonzero remote command is an iteration result and the loop continues; watcher, lease, and sync failures are fatal.
- Each iteration uses the normal run/recording path, with a deterministic
watch #Nlabel, so history, results, artifacts, events, and attach behavior remain unchanged where the existing provider/run path supports them. - Clear unsupported-provider error. Windows may use the same queue behavior; no interrupt-specific platform fork is needed in v1.
- Reject one-shot flags that conflict with a persistent session, including pool, sync-only/no-sync, patch/fresh-PR/script-stdin, stop-after, lease-output, keep-on-failure, and fixed local capture/download/proof outputs.
- Use a narrow reusable internal lease/iteration API; do not shell out to Crabbox or scrape CLI output.
- Regression coverage for initial run, ignore filtering, recursive new directories, debounce/coalescing, changes during a run, nonzero-command continuation, idle exit, Ctrl-C, acquisition/reuse, release/keep, and cleanup after failures.
- Command docs, performance guide update, changelog entry thanking the contributor, and a redacted live demo proving acquire/reuse, edit-triggered rerun, and zero-residue exit.
This is ready for a bounded contributor PR on that contract. Please keep changes to the watch command and the smallest reusable run seam; avoid refactoring the run orchestrator in the same PR.
Thanks, I will begin working on this!