Repository navigation
feat(#383): interactive relay — bidirectional communication with headless runs - #638
Merged
admarble merged 2 commits intoMay 13, 2026
Conversation
…less runs Adds a file-based IPC channel between the user terminal and a running `sequant run` session. Users can now send query/directive/abort messages into a headless Claude session via `sequant prompt <issue> "<msg>"`, with responses tailed via `sequant watch <issue>`. Implementation: - src/lib/relay/: protocol (types, paths, writer, reader, frame, archive, pid, activation) — 9 modules, all I/O guarded for filesystem failures. - templates/hooks/relay-check.sh: sourced by post-tool.sh on every PostToolUse when SEQUANT_RELAY=true. Fast path is a single env-var test + `test -s` check; slow path renders one framing block per invocation. - templates/relay/frame.txt: framing template with the 6 verbatim anti-derailment rules from the issue body. - bin/cli.ts: new `prompt` and `watch` commands; `--no-relay` flag on `run` to opt out. - src/lib/workflow/: relay lifecycle wired into batch-executor (activate on run start, deactivate before worktree teardown so archives land in .sequant/logs/relay/<issue>-<phase>-<ts>/). phase-executor injects SEQUANT_RELAY + SEQUANT_RELAY_FRAME env vars. - state-schema.ts/state-manager.ts: optional `relay` field on IssueState (legacy state still parses); `setRelayState` / `incrementRelayMessageCount`. Tests: 12 new files, 111 new tests (72 unit + 39 integration). All ACs are covered, including the AC-16 SKILL.md isolation guard that scans all three skill directories. Bug fixes discovered during testing: - relay-check.sh used `cond && return 0 || exit 0`; bash precedence makes this exit prematurely when cond is false. Switched to `if [[...]]; then return ...; fi`. Without this fix, the hook would short-circuit on the very env-var test it was supposed to gate on. - archiveRelayDir now returns archived=false when both inbox and outbox are absent, so repeated deactivation calls are idempotent rather than creating empty archive dirs.
27 tasks
…slint no-useless-assignment
admarble
deleted the
feature/383-interactive-relay-bidirectional-communication-with
branch
May 13, 2026 23:14
admarble
added a commit
that referenced
this pull request
May 14, 2026
…rs (#630) Entire-Checkpoint: 829856a3824f
This was referenced May 14, 2026
admarble
added a commit
that referenced
this pull request
May 14, 2026
…nt (#646) * fix(#645): install relay hook so messages reach the agent Issue #645 reported that interactive relay messages disappear: inbox entries pile up while `.cursor` is never written and no outbox reply appears. Empirical evidence showed PostToolUse hooks were never advancing the read cursor. Root cause: PR #638 added `templates/hooks/relay-check.sh` and the SEQUANT_RELAY sourcing block in `templates/hooks/post-tool.sh`, but the installed copies in `.claude/hooks/` (referenced by `.claude/settings.json`) were never updated. Worktrees inherit the stale checked-in `post-tool.sh`, so the hook chain never sourced relay-check.sh. The mirror-pair config that should have caught this drift (`src/lib/merge-check/types.ts`) had `source: "hooks"` — a directory that doesn't exist — so the check silently no-op'd. Phase 1 — root-cause fix - Add `.claude/hooks/relay-check.sh` (byte-identical to template) - Surgically insert the 11-line SEQUANT_RELAY sourcing block into `.claude/hooks/post-tool.sh`. Wholesale sync is deferred because the installed file has two local-only features (test coverage, post-merge cleanup) that are not in the template. Phase 2 — drift guard - Fix DEFAULT_MIRROR_PAIRS source path: "hooks" -> ".claude/hooks" - Add Vitest assertion that relay-check.sh stays byte-identical to its template and that post-tool.sh keeps sourcing it Phase 3 — watch + archive metadata - `sequant watch` now detects relay deactivation (pidfile removed or absent at startup) and exits with a useful pointer to the archive instead of polling forever (Gap 3) - Archive `meta.json` records `inboxCount` + `outboxCount` separately so unanswered queries are visible post-hoc. `messageCount` preserved for back-compat; schema accepts older archives without the new fields (Gap 5) Out of scope: Gap 4 (prompt UX polish), Gap 6 (stale phase label), Gap 7 (signal-based abort fallback), broader `.claude/hooks/` drift reconciliation — separate follow-ups if requested. * fix(watch): honor cwd override when resolving outbox path watch.ts now passes the resolved cwd to outboxPathFor() so the watch command consistently uses the same root for pid + outbox + archive lookups. Pre-existing prod behavior unchanged (defaults to process.cwd()); enables clean test isolation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #383. File-based IPC channel that lets users send
query/directive/abortmessages into a running headlesssequant runsession via a newsequant promptCLI command, with responses tailed viasequant watch. The PostToolUse hook surfaces inbox messages back to Claude wrapped in an anti-derailment framing block.sequant prompt <issue> "<msg>"— write to<worktree>/.sequant/relay/inbox.jsonl; refuses on dead PIDs.sequant watch <issue>— tail outbox viafs.watch()+ polling fallback.sequant status— gains a Relay column for active runs.--no-relayflag onsequant runfor opt-out;settings.run.relaydefaults totrue.How it works
phase-executorsetsSEQUANT_RELAY=true+SEQUANT_RELAY_FRAME=<path>in the agent env when relay is enabled.post-tool.shsourcesrelay-check.shon every PostToolUse when the env var is set.test -soninbox.jsonl) when nothing is pending. On non-empty inbox, it renders the framing template (with the 6 verbatim rules) and emits all unread messages as a single block to stdout — Claude Code surfaces this as additional context..cursor) is advanced atomically (temp + rename) so each message is shown exactly once.batch-executorarchivesinbox.jsonl+outbox.jsonl+meta.jsonto.sequant/logs/relay/<issue>-<phase>-<ts>/before worktree teardown, preserving transcripts.AC Coverage (25 ACs + 4 derived)
prompt,watch,status)Bugs found and fixed during testgen→exec
relay-check.shshort-circuit bug: the initial guardcond && return 0 2>/dev/null || exit 0exits prematurely whencondis false (the relay-enabled branch) due to bash precedence. Switched to an explicitifblock. Without this fix the hook would always exit before reading the inbox.archiveRelayDiridempotency: repeated deactivation calls now returnarchived=falsewhen both inbox and outbox are absent, instead of creating empty archive directories.--no-relaywiring:RunOptions.noRelaywas inconsistent with how Commander surfaces--no-Xflags. Renamed torelay?: boolean(matcheschainpattern) and the resolver checksrelay === false.Test plan
npm run build— passesnpm test— 3297 tests pass across 147 files (111 new tests across 12 new files)npm run lint:skill-calls— no violationstemplates/hooks/relay-check.shsmoke-tested manually with a multi-message inbox; produces correct frame with---between messages and single[SEQUANT RELAY]headersequant run 1in one terminal,sequant prompt 1 "status?"in another — recommend during human reviewOut of scope (follow-ups)
sequant promptto a> nudge #N:text input inside the live TUI — remains a follow-up on Live multi-issue dashboard forsequant run— concurrent box rendering (read-only TUI) #540, not this issue.--carry-forwardmode could keep inbox/outbox across phase boundaries; deferred.