feat(watch): add --exec hook to run a command on attention transitions#340
Merged
Conversation
`dispatch watch --exec <cmd>` runs a command each time a session changes attention state while streaming. Session context is passed only through DISPATCH_SESSION_* environment variables (ID, STATE, PREV_STATE, REPO, BRANCH, FOLDER, SUMMARY), never interpolated into the command string, so untrusted session metadata cannot alter what runs. The command runs through the platform shell. Hook output and non-zero exits go to stderr, and a slow or failing hook never stops the watch loop. `--exec` requires streaming mode and is rejected with `--once`. Closes #329 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 732fe147-a68b-4784-8e17-ef089fb70ba3
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.
Adds
dispatch watch --exec <cmd>, an automation hook that runs a command every time a session changes attention state while streaming. This turnswatchinto a building block for notifiers, webhooks, and desktop alerts without polling the JSON output yourself.What it does
--exec <cmd>runs the command through your shell on each attention transition (waiting, working, thinking, gone, and so on).DISPATCH_SESSION_ID,DISPATCH_SESSION_STATE,DISPATCH_SESSION_PREV_STATE(nonefor a newly seen session),DISPATCH_SESSION_REPO,DISPATCH_SESSION_BRANCH,DISPATCH_SESSION_FOLDER,DISPATCH_SESSION_SUMMARY.--jsonconsumers.--execrequires streaming mode and is rejected when combined with--once. It composes with the existing--repo,--branch, and--folderfilters.Example
Implementation notes
watchExecFn(defaultrunWatchHook) lets tests capture invocations and env payloads without spawning shells.hookShell()picks the shell per OS ($SHELL -c//bin/sh -con Unix,%COMSPEC% /c/cmd.exe /con Windows).hookEnv()builds theDISPATCH_SESSION_*slice and is unit tested directly.Verification
go build ./...,go vet ./...,go test ./... -count=1,golangci-lint run --timeout 10m(0 issues), andmage deadcode(OK) all pass.Closes #329