Skip to content

feat: add pty_wait tool - #56

Open
FAZuH wants to merge 1 commit into
shekohex:mainfrom
FAZuH:feat/add-pty-wait
Open

feat: add pty_wait tool#56
FAZuH wants to merge 1 commit into
shekohex:mainfrom
FAZuH:feat/add-pty-wait

Conversation

@FAZuH

@FAZuH FAZuH commented Aug 18, 2026

Copy link
Copy Markdown

Summary

  • Add a pty_wait tool that blocks until a PTY session finishes running, with an optional timeoutSeconds.
  • Returns a <pty_waited> block with final status, exit code/signal, output line count, and the last 20 lines of output; returns a <pty_wait_timeout> block instead of blocking forever when the timeout elapses.
image

Motivation

Exit notifications (notifyOnExit<pty_exited>) require the agent to go idle and wait for the injected message. This is unreliable when:

  • A subagent goes idle waiting for <pty_exited> and the parent interprets idleness as task completion.
  • A /goal plugin auto-resumes idle agents, so an agent idling to wait for <pty_exited> gets repeatedly resumed.

pty_wait gives the agent a synchronous blocking alternative in both scenarios.

Changes

  • src/plugin/pty/tools/wait.ts: new tool: one-shot session-update callback raced against an optional timeout (Promise.race), closing the register/exit race window
  • src/plugin/pty/tools/wait.txt: tool description
  • src/plugin.ts: registers pty_wait alongside the other pty_* tools
  • src/plugin/pty/manager.ts:: iterate a snapshot of sessionUpdateCallbacks so a callback removing itself mid-iteration can't skip other subscribers (e.g. the web UI's WS broadcast)
  • README.md: tools table row + a "Wait for a session to finish" section
  • test/pty-tools.test.ts: ptyWait suite: already-exited, tail window, callback-driven exit, timeout, exit-signal, not-found, plus callback-leak hygiene

Verification

  • bun lint
  • bun format
  • bun run typecheck
  • bun unittest (73 passed, 1 skipped)

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