Add experimental agent mode for binding.agent#1188
Draft
st0012 wants to merge 1 commit into
Draft
Conversation
fcfcea9 to
98c28c6
Compare
ecf744e to
6a02408
Compare
6a02408 to
be4ac89
Compare
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.
Problem
Agents usually interact with programs through non-interactive shell commands, so a process that stops at
binding.irbcan leave them stranded at a terminal REPL they cannot reliably drive.The useful debugging loop needs to work without a dedicated client: discover the breakpoint, restart the target in a controllable mode, inspect live locals and receiver state, run normal IRB commands, make a small state change, and then resume the original Ruby program.
That loop also has two output streams with different ownership. IRB results, errors, and command output belong in the agent response, while output from the running application and its other threads must remain on the application's stdout and stderr. Commands that start a second interactive UI cannot honestly fit a one-request/one-response protocol.
Solution
binding.agentwith a self-teaching two-phase workflow.IRB_SOCK_PATH, print complete restart and connection instructions, then exit without initializing an IRB session.IRB_SOCK_PATH, run a normalIRB::Irb#runlifecycle through an agent-specificSocketInputMethod. Each connection supplies one complete request and receives one response; the workspace persists across connections.$stdout. IRB-owned results, diagnostics, paged output, RI output, and built-in command output go to the socket. Application code that writes stdout or stderr continues to write to the host.exitas resume andexit!as process exit. Refuse only commands that require another interactive loop or host UI: debug commands, deprecated multi-IRB commands,edit, and bareshow_doc.0600, reclaim stale sockets, and only remove a socket whose identity still matches the one this session created. Stale-path reclamation is best-effort, so callers should use a unique path in a private directory.Command Behavior
ls,history,show_source, and namedshow_docsource,require,copy, workspace commands, andmeasureexitexit!editand bareshow_docCustom commands that explicitly write process stdout or stderr still target the host by design. Commands using IRB's command output helpers are returned through the socket.
Agent Flow
sequenceDiagram participant Agent participant App as "Ruby process" participant Session as "IRB::AgentSession" participant IRB as "IRB::Irb" participant Host as "Host stdout/stderr" Agent->>App: run without IRB_SOCK_PATH App-->>Agent: print workflow instructions and exit Agent->>App: restart with unique IRB_SOCK_PATH App->>Session: binding.agent Session->>Session: bind protected Unix socket Session->>IRB: run with SocketInputMethod loop one complete request per connection Agent->>Session: connect, send request, close_write Session->>IRB: provide request as IRB input IRB->>IRB: evaluate in persistent workspace IRB-->>Session: result, error, or command output Session-->>Agent: response and EOF App-->>Host: application output remains on host streams end alt exit Agent->>Session: exit Session->>App: close session and resume else exit! Agent->>Session: exit! Session->>App: exit process endEnd-to-End Notes
ls,show_source, namedshow_doc, a registered custom command, narrow command refusals, host-thread output isolation, live mutation, resume, and socket cleanup.RDoc::Markup::DocumentandRDoc::Commentobjects, resolved source into that checkout, preserved state across connections, resumed the target, and confirmed both loaded feature paths.verbose: falseduringIRB::Irbconstruction fixed it; both complete flows were rerun and observed no startup noise on either host or socket output.