feat(opencode): add Monitor tool (per-line background watcher) - #33685
Closed
fl4p wants to merge 1 commit into
Closed
feat(opencode): add Monitor tool (per-line background watcher)#33685fl4p wants to merge 1 commit into
fl4p wants to merge 1 commit into
Conversation
Adds an experimental `monitor` tool: run a long-lived shell command in the background and wake the model on EVERY new stdout line (one synthetic message per line), until the process exits or the session ends. This fills the gap left by the background-bash PRs (anomalyco#33310, anomalyco#32675), which notify once on completion / are poll-based — none stream per-line events. Built on the existing BackgroundJob primitive (same one the task tool uses): the tool registers a job whose run Effect spawns the process and injects a prompt per line; process lifecycle = job scope (re-arm/session-teardown cancels it). A small plain-function liveness shim keeps the non-interactive CLI alive while a monitor runs and reaps PIDs on SIGINT. Gated behind OPENCODE_EXPERIMENTAL_MONITOR.
Contributor
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
fl4p
added a commit
to fl4p/agent-channel
that referenced
this pull request
Jun 24, 2026
…de#33685 Replaces the fl4p/opencode fork reference with the open upstream PR adding the Monitor (per-line background watcher) tool.
Contributor
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
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.
Issue for this PR
Closes #
No linked issue — this adds a new capability.
Type of change
What does this PR do?
Adds an experimental
monitortool: it runs a shell command in the background and sends one message back to the model per new stdout line, until the command exits or the session ends. The point is to watch a log/file/process and react to each event without polling.It reuses the existing
BackgroundJobservice (the same primitive thetasktool uses) rather than adding a new core service: the tool starts a job whoseruneffect spawns the command (scoped) and injects a synthetic prompt for each stdout line; a clean exit injects one final note. Re-arming or session teardown cancels the job, and the process is killed via the job's scope. A small plain-function liveness helper lets the non-interactiveopencode runloop stay alive while a monitor is running and kill the child PID on SIGINT.This is deliberately different from the background-bash PRs: #33310 notifies once on completion and #32675 is poll-based — neither streams per-line events. Gated behind
OPENCODE_EXPERIMENTAL_MONITOR.How did you verify your code works?
cd packages/opencode && bun run typecheckcd packages/opencode && bun test test/tool/monitor.test.ts test/tool/registry.test.ts(green)OPENCODE_EXPERIMENTAL_MONITOR=trueagainst a real model: confirmed a message arrives per stdout line and a single exit note at the end.Screenshots / recordings
N/A — not a UI change.
Checklist