Add persistent workspace shell sessions
Let agents inhabit a workspace across separate calls instead of only submitting one-shot execs. Add workspace shell open/read/write/signal/close across the CLI, Python SDK, and MCP server, with persisted shell records, a local PTY-backed mock implementation, and guest-agent support for real Firecracker workspaces. Mark the 2.5.0 roadmap milestone done, refresh docs/examples and the release metadata, and verify with uv lock, UV_CACHE_DIR=.uv-cache make check, and UV_CACHE_DIR=.uv-cache make dist-check.
This commit is contained in:
parent
2de31306b6
commit
3f8293ad24
28 changed files with 3265 additions and 81 deletions
|
|
@ -105,6 +105,130 @@ def test_vsock_exec_client_upload_archive_round_trip(
|
|||
assert stub.closed is True
|
||||
|
||||
|
||||
def test_vsock_exec_client_shell_round_trip(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(socket, "AF_VSOCK", 40, raising=False)
|
||||
responses = [
|
||||
json.dumps(
|
||||
{
|
||||
"shell_id": "shell-1",
|
||||
"cwd": "/workspace",
|
||||
"cols": 120,
|
||||
"rows": 30,
|
||||
"state": "running",
|
||||
"started_at": 1.0,
|
||||
"ended_at": None,
|
||||
"exit_code": None,
|
||||
}
|
||||
).encode("utf-8"),
|
||||
json.dumps(
|
||||
{
|
||||
"shell_id": "shell-1",
|
||||
"cwd": "/workspace",
|
||||
"cols": 120,
|
||||
"rows": 30,
|
||||
"state": "running",
|
||||
"started_at": 1.0,
|
||||
"ended_at": None,
|
||||
"exit_code": None,
|
||||
"cursor": 0,
|
||||
"next_cursor": 12,
|
||||
"output": "pyro$ pwd\n",
|
||||
"truncated": False,
|
||||
}
|
||||
).encode("utf-8"),
|
||||
json.dumps(
|
||||
{
|
||||
"shell_id": "shell-1",
|
||||
"cwd": "/workspace",
|
||||
"cols": 120,
|
||||
"rows": 30,
|
||||
"state": "running",
|
||||
"started_at": 1.0,
|
||||
"ended_at": None,
|
||||
"exit_code": None,
|
||||
"input_length": 3,
|
||||
"append_newline": True,
|
||||
}
|
||||
).encode("utf-8"),
|
||||
json.dumps(
|
||||
{
|
||||
"shell_id": "shell-1",
|
||||
"cwd": "/workspace",
|
||||
"cols": 120,
|
||||
"rows": 30,
|
||||
"state": "running",
|
||||
"started_at": 1.0,
|
||||
"ended_at": None,
|
||||
"exit_code": None,
|
||||
"signal": "INT",
|
||||
}
|
||||
).encode("utf-8"),
|
||||
json.dumps(
|
||||
{
|
||||
"shell_id": "shell-1",
|
||||
"cwd": "/workspace",
|
||||
"cols": 120,
|
||||
"rows": 30,
|
||||
"state": "stopped",
|
||||
"started_at": 1.0,
|
||||
"ended_at": 2.0,
|
||||
"exit_code": 0,
|
||||
"closed": True,
|
||||
}
|
||||
).encode("utf-8"),
|
||||
]
|
||||
stubs = [StubSocket(response) for response in responses]
|
||||
remaining = list(stubs)
|
||||
|
||||
def socket_factory(family: int, sock_type: int) -> StubSocket:
|
||||
assert family == socket.AF_VSOCK
|
||||
assert sock_type == socket.SOCK_STREAM
|
||||
return remaining.pop(0)
|
||||
|
||||
client = VsockExecClient(socket_factory=socket_factory)
|
||||
opened = client.open_shell(
|
||||
1234,
|
||||
5005,
|
||||
shell_id="shell-1",
|
||||
cwd="/workspace",
|
||||
cols=120,
|
||||
rows=30,
|
||||
)
|
||||
assert opened.shell_id == "shell-1"
|
||||
read = client.read_shell(1234, 5005, shell_id="shell-1", cursor=0, max_chars=1024)
|
||||
assert read.output == "pyro$ pwd\n"
|
||||
write = client.write_shell(
|
||||
1234,
|
||||
5005,
|
||||
shell_id="shell-1",
|
||||
input_text="pwd",
|
||||
append_newline=True,
|
||||
)
|
||||
assert write["input_length"] == 3
|
||||
signaled = client.signal_shell(1234, 5005, shell_id="shell-1", signal_name="INT")
|
||||
assert signaled["signal"] == "INT"
|
||||
closed = client.close_shell(1234, 5005, shell_id="shell-1")
|
||||
assert closed["closed"] is True
|
||||
open_request = json.loads(stubs[0].sent.decode("utf-8").strip())
|
||||
assert open_request["action"] == "open_shell"
|
||||
assert open_request["shell_id"] == "shell-1"
|
||||
|
||||
|
||||
def test_vsock_exec_client_raises_agent_error(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(socket, "AF_VSOCK", 40, raising=False)
|
||||
stub = StubSocket(b'{"error":"shell is unavailable"}')
|
||||
client = VsockExecClient(socket_factory=lambda family, sock_type: stub)
|
||||
with pytest.raises(RuntimeError, match="shell is unavailable"):
|
||||
client.open_shell(
|
||||
1234,
|
||||
5005,
|
||||
shell_id="shell-1",
|
||||
cwd="/workspace",
|
||||
cols=120,
|
||||
rows=30,
|
||||
)
|
||||
|
||||
|
||||
def test_vsock_exec_client_rejects_bad_json(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(socket, "AF_VSOCK", 40, raising=False)
|
||||
stub = StubSocket(b"[]")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue