ask-acp 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +21 -0
- data/README.md +100 -0
- data/exe/record_acp +72 -0
- data/lib/ask/acp/replay_client.rb +30 -18
- data/lib/ask/acp/version.rb +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dd22248dd65fb612b9ff352e2278bc7ed8d0e2c8b86bd6e31f89752cf7b094cb
|
|
4
|
+
data.tar.gz: d9d788c986270c49e7469a877215c07f12f43e2911099b1ae06211894d400b5b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 33bcddcd90137d5ae67e565030a6051ef1a910d1bc102096a03e2cf2d30316c3d7e9fa89d1bf35fda9bb8f4eac06c3a94b7d0602fc12fb5eb876bfa872c0963d
|
|
7
|
+
data.tar.gz: 5ed550a8037651b58e72037d728b592a44ac116e4b29dfceac2134a24c1f308b8a04ae171693ef61e6730a626f43c78d8e75871750892ed7460b6bef6f68783a
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kaka Ruto
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# ask-acp
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/rb/ask-acp)
|
|
4
|
+
|
|
5
|
+
A Ruby implementation of the Agent Client Protocol (ACP): JSON-RPC 2.0 over
|
|
6
|
+
stdio, following the v0.11.3 protocol schema. It provides a client that drives
|
|
7
|
+
an ACP-compliant coding agent as a subprocess, a server base class for making
|
|
8
|
+
a Ruby agent speak ACP, and a replay client for deterministic testing.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```ruby
|
|
13
|
+
gem "ask-acp"
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
### Client: drive an ACP agent subprocess
|
|
19
|
+
|
|
20
|
+
```ruby
|
|
21
|
+
require "ask-acp"
|
|
22
|
+
|
|
23
|
+
client = Ask::ACP::Client.new(command: ["codex", "acp"])
|
|
24
|
+
client.start
|
|
25
|
+
client.initialize!(client_name: "my-app", client_version: "0.1.0")
|
|
26
|
+
|
|
27
|
+
session = client.session_new(cwd: "/tmp")
|
|
28
|
+
|
|
29
|
+
# Stream prompt events as they arrive
|
|
30
|
+
client.session_prompt(session[:id], "Hello!") do |event|
|
|
31
|
+
puts "#{event[:method]}: #{event[:params]}"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
client.stop
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Server: speak ACP as a Ruby agent
|
|
38
|
+
|
|
39
|
+
```ruby
|
|
40
|
+
class MyAgent < Ask::ACP::Server
|
|
41
|
+
def handle_session_new(params)
|
|
42
|
+
{ session: { id: SecureRandom.uuid, status: "running" } }
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
MyAgent.new.run
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Key entry points
|
|
50
|
+
|
|
51
|
+
- `Ask::ACP::Client` - spawns an agent CLI subprocess with Open3 and speaks
|
|
52
|
+
ACP over stdio. Methods: `initialize!`, `authenticate`, `session_new`,
|
|
53
|
+
`session_load`, `session_list`, `session_fork`, `session_resume`,
|
|
54
|
+
`session_close`, `session_prompt` (streams events via a block),
|
|
55
|
+
`session_cancel`, `session_set_config_option`, `session_set_mode`,
|
|
56
|
+
`session_set_model`, `start`, `stop`.
|
|
57
|
+
- `Ask::ACP::Server` - base class to subclass; implement `handle_*` methods
|
|
58
|
+
and run with `.run`.
|
|
59
|
+
- `Ask::ACP::ReplayClient` - replays pre-recorded JSONL interactions from a
|
|
60
|
+
fixture file. No subprocess; instant, deterministic responses.
|
|
61
|
+
- `Ask::ACP::Protocol` - message builders and constants:
|
|
62
|
+
`AGENT_METHODS`, `CLIENT_METHODS`, `PROMPT_EVENTS`, `STATUSES`,
|
|
63
|
+
`PROTOCOL_VERSION`.
|
|
64
|
+
- `Ask::ACP::Error` and `Ask::ACP::TimeoutError` - errors raised by the
|
|
65
|
+
client.
|
|
66
|
+
|
|
67
|
+
## Full documentation
|
|
68
|
+
|
|
69
|
+
The full ask-rb documentation lives at https://ask-rb.github.io/ask-docs.
|
|
70
|
+
The guide — [ACP Client & Server](https://ask-rb.github.io/ask-docs/core/acp) —
|
|
71
|
+
is the narrative walkthrough: driving real agents, hosting your own, the
|
|
72
|
+
session lifecycle, streamed events, and testing. The
|
|
73
|
+
[Gem Index](https://ask-rb.github.io/ask-docs/reference/gems) covers ask-acp
|
|
74
|
+
in depth.
|
|
75
|
+
|
|
76
|
+
## Recording fixtures
|
|
77
|
+
|
|
78
|
+
`record_acp` (installed with the gem) spawns a real agent and records a
|
|
79
|
+
session flow to a JSONL fixture for later replay:
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
record_acp opencode fixtures/opencode_session.jsonl
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```ruby
|
|
86
|
+
client = Ask::ACP::ReplayClient.new(fixture_path: "fixtures/opencode_session.jsonl")
|
|
87
|
+
client.start
|
|
88
|
+
client.initialize!(client_name: "my-app", client_version: "0.1.0")
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Development
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
bundle install
|
|
95
|
+
bundle exec ruby -Itest test/acp_test.rb
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## License
|
|
99
|
+
|
|
100
|
+
MIT
|
data/exe/record_acp
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
# Record ACP interactions to a fixture file for later replay.
|
|
5
|
+
# Usage: OPENCODE_API_KEY=sk-... ruby bin/record_acp opencode fixtures/opencode_session.jsonl
|
|
6
|
+
#
|
|
7
|
+
# This spawns the agent, runs through a standard session flow,
|
|
8
|
+
# and saves all JSON-RPC messages to a fixture file.
|
|
9
|
+
|
|
10
|
+
require "json"
|
|
11
|
+
require "open3"
|
|
12
|
+
require "fileutils"
|
|
13
|
+
|
|
14
|
+
agent = ARGV[0] || "opencode"
|
|
15
|
+
output = ARGV[1] || "fixtures/#{agent}_session.jsonl"
|
|
16
|
+
|
|
17
|
+
commands = {
|
|
18
|
+
"opencode" => ["opencode", "acp"],
|
|
19
|
+
"codex" => ["codex", "app-server", "--stdio"],
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
cmd = commands[agent] || [agent]
|
|
23
|
+
puts "Recording ACP interaction with: #{cmd.join(" ")}"
|
|
24
|
+
puts "Output: #{output}"
|
|
25
|
+
|
|
26
|
+
FileUtils.mkdir_p(File.dirname(output))
|
|
27
|
+
File.open(output, "w") do |fixture|
|
|
28
|
+
stdin, stdout, stderr, thr = Open3.popen3(*cmd)
|
|
29
|
+
|
|
30
|
+
writer = Thread.new do
|
|
31
|
+
# Run through a standard session flow
|
|
32
|
+
requests = [
|
|
33
|
+
{ method: "initialize", params: { protocolVersion: 1, clientInfo: { name: "askoda-record", version: "0.1.0" }, capabilities: {} } },
|
|
34
|
+
{ method: "session/new", params: { cwd: Dir.pwd, mcpServers: [] } },
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
requests.each do |req|
|
|
38
|
+
msg = { jsonrpc: "2.0", id: Time.now.to_i, method: req[:method], params: req[:params] }
|
|
39
|
+
fixture.puts(JSON.generate({ request: msg }))
|
|
40
|
+
stdin.puts(JSON.generate(msg))
|
|
41
|
+
stdin.flush
|
|
42
|
+
sleep 0.5
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
reader = Thread.new do
|
|
47
|
+
stdout.each_line do |line|
|
|
48
|
+
line = line.strip
|
|
49
|
+
next if line.empty?
|
|
50
|
+
begin
|
|
51
|
+
msg = JSON.parse(line)
|
|
52
|
+
if msg["id"]
|
|
53
|
+
fixture.puts(JSON.generate({ response: msg }))
|
|
54
|
+
else
|
|
55
|
+
fixture.puts(JSON.generate({ notification: msg }))
|
|
56
|
+
end
|
|
57
|
+
rescue JSON::ParserError
|
|
58
|
+
# Skip non-JSON output
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
writer.join
|
|
64
|
+
sleep 2
|
|
65
|
+
stdin.close rescue nil
|
|
66
|
+
thr.join(5) rescue nil
|
|
67
|
+
stdout.close rescue nil
|
|
68
|
+
stderr.close rescue nil
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
puts "Done! Recorded #{File.size(output)} bytes to #{output}"
|
|
72
|
+
puts "Replay with: Ask::ACP::ReplayClient.new(fixture_path: '#{output}')"
|
|
@@ -95,26 +95,38 @@ module Ask
|
|
|
95
95
|
prompt_blocks = prompt.is_a?(Array) ? prompt : [{ type: "text", text: prompt.to_s }]
|
|
96
96
|
params = { sessionId: session_id, prompt: prompt_blocks }
|
|
97
97
|
|
|
98
|
-
#
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
end
|
|
105
|
-
@index += 1
|
|
98
|
+
# Same block form as Client: a temporary handler that streams events
|
|
99
|
+
# as { method:, params: } before the response arrives.
|
|
100
|
+
handler = nil
|
|
101
|
+
if block
|
|
102
|
+
handler = ->(msg) { block.call(method: msg["method"], params: msg["params"] || {}) if msg["method"] }
|
|
103
|
+
on_notification(&handler)
|
|
106
104
|
end
|
|
107
105
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
106
|
+
begin
|
|
107
|
+
# Dispatch any notifications before the response
|
|
108
|
+
while @index < @events.length
|
|
109
|
+
event = @events[@index]
|
|
110
|
+
break if event.key?("response")
|
|
111
|
+
if event.key?("notification")
|
|
112
|
+
dispatch_event(event["notification"])
|
|
113
|
+
end
|
|
114
|
+
@index += 1
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Get the response
|
|
118
|
+
event = @events[@index]
|
|
119
|
+
@index += 1
|
|
120
|
+
if event && event["response"]
|
|
121
|
+
result = event["response"]["result"]
|
|
122
|
+
error = event["response"]["error"]
|
|
123
|
+
raise Error.new("[#{error["code"]}] #{error["message"]}") if error
|
|
124
|
+
result
|
|
125
|
+
else
|
|
126
|
+
{ "status" => "completed" }
|
|
127
|
+
end
|
|
128
|
+
ensure
|
|
129
|
+
@mutex.synchronize { @event_handlers.delete(handler) } if handler
|
|
118
130
|
end
|
|
119
131
|
end
|
|
120
132
|
|
data/lib/ask/acp/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ask-acp
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kaka Ruto
|
|
8
|
-
bindir:
|
|
8
|
+
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
@@ -84,10 +84,14 @@ description: Ruby implementation of the Agent Client Protocol (ACP) — a JSON-R
|
|
|
84
84
|
(host Ruby agents via ACP), and transport layer.
|
|
85
85
|
email:
|
|
86
86
|
- kaka@myrrlabs.com
|
|
87
|
-
executables:
|
|
87
|
+
executables:
|
|
88
|
+
- record_acp
|
|
88
89
|
extensions: []
|
|
89
90
|
extra_rdoc_files: []
|
|
90
91
|
files:
|
|
92
|
+
- LICENSE
|
|
93
|
+
- README.md
|
|
94
|
+
- exe/record_acp
|
|
91
95
|
- lib/ask-acp.rb
|
|
92
96
|
- lib/ask/acp.rb
|
|
93
97
|
- lib/ask/acp/client.rb
|