Skip to content

feat(opencode): add Monitor tool (per-line background watcher) - #33685

Closed
fl4p wants to merge 1 commit into
anomalyco:devfrom
fl4p:monitor-pr
Closed

feat(opencode): add Monitor tool (per-line background watcher)#33685
fl4p wants to merge 1 commit into
anomalyco:devfrom
fl4p:monitor-pr

Conversation

@fl4p

@fl4p fl4p commented Jun 24, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #

No linked issue — this adds a new capability.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds an experimental monitor tool: 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 BackgroundJob service (the same primitive the task tool uses) rather than adding a new core service: the tool starts a job whose run effect 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-interactive opencode run loop 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 typecheck
  • cd packages/opencode && bun test test/tool/monitor.test.ts test/tool/registry.test.ts (green)
  • Ran it live with OPENCODE_EXPERIMENTAL_MONITOR=true against 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

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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.
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jun 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

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.
@github-actions

Copy link
Copy Markdown
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.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jun 24, 2026
@github-actions github-actions Bot closed this Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant