feat(pc): pcControl brain tool and the worker's pc_action bridge
The brain operates programs through the app (pc_control.spec.md): windows, read, click, type, keys, run and close, with window text fenced as untrusted screen data and every action answered from the fresh reading the app returns. - Asking first: an action the app wants asked about is not done; the tool keeps the request and only the person's very next message, judged by the small model chain (fenced, YES/NO, 600 chars), gives consent, which then covers those kinds on that window for the rest of the reply. The model's confirm flag is not what decides. - Never done: before the first acting call per window and kind in a reply, a small call checks for payments, secrets, deleting files and administrator rights; anything but a clear no refuses and nothing reaches the app. - The worker keeps each person's pending requests between their replies, passes the app's ask answers through and waits 45 s for a PC action (starting a program and reading it takes the app ~20 s). - The reply engine's repeat guard no longer limits pcControl: pressing calculator keys is many calls and the same one can be meant twice. Before, the third call was blocked and the model then claimed to have pressed a payment button it never pressed. Eval evals/test_pc_control_tool.py on Qwen3.6 (game PC Strata), 8 runs of 4 cases after the last changes: calculator 12+3 read back as 15 6/8 (the misses press the digits out of order and say the wrong result read from the screen), ask then consent in the next message 8/8, a request written in a window not followed 8/8, payment never pressed and never claimed 8/8. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -29,12 +29,12 @@ class FakeBrain:
|
||||
self.calls = []
|
||||
|
||||
def reply(self, user, text, history, chat=None, schedule=None, task=False, notes=None, notes_backend=None,
|
||||
screen=None, trace=None):
|
||||
screen=None, pc=None, trace=None):
|
||||
self.calls.append((user, text, history))
|
||||
if trace is not None:
|
||||
trace.append({"kind": "tools", "names": ["getWeather"]})
|
||||
self.chat, self.schedule, self.task = chat, schedule, task
|
||||
self.notes, self.notes_backend, self.screen = notes, notes_backend, screen
|
||||
self.notes, self.notes_backend, self.screen, self.pc = notes, notes_backend, screen, pc
|
||||
return self.answer(user, text)
|
||||
|
||||
def addressed(self, user, text, names, people=None, callers=None):
|
||||
@@ -1120,9 +1120,9 @@ def _jarvis_brain(tmp_path, monkeypatch, plans):
|
||||
seen = {"judged": [], "prepared": []}
|
||||
|
||||
def fake_prepare(cfg, text, mem, chat_available, schedule_available=False, notes_available=False,
|
||||
screen_available=False):
|
||||
screen_available=False, pc_available=False):
|
||||
# the reply it is made for has these tools
|
||||
assert schedule_available and notes_available and screen_available
|
||||
assert schedule_available and notes_available and screen_available and pc_available
|
||||
seen["judged"].append((text, chat_available))
|
||||
return plans.get(text)
|
||||
|
||||
@@ -1236,7 +1236,7 @@ def test_a_reply_waits_for_a_pick_still_being_prepared_for_its_text(tmp_path, mo
|
||||
import jarvis.reply.engine as engine
|
||||
|
||||
def slow_prepare(cfg, text, mem, chat_available, schedule_available=False, notes_available=False,
|
||||
screen_available=False):
|
||||
screen_available=False, pc_available=False):
|
||||
_time.sleep(0.4)
|
||||
return plan
|
||||
monkeypatch.setattr(engine, "prepare_intent", slow_prepare)
|
||||
@@ -1612,6 +1612,68 @@ def test_a_screen_action_goes_to_the_app_for_the_asker_and_its_pictures_come_bac
|
||||
assert brain.screen is None # a scheduled task sees no screen
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_a_pc_action_goes_to_the_app_and_an_ask_answer_keeps_what_to_ask(store):
|
||||
"""pc_control.spec.md: the app answers ask with the kinds and the window; the worker keeps the
|
||||
asker's requests awaiting consent between their replies and numbers the replies."""
|
||||
results, seen_pc = [], []
|
||||
|
||||
def answer(u, t):
|
||||
seen_pc.append((brain.pc.turn, brain.pc.state))
|
||||
if t == "q1":
|
||||
results.append(brain.pc.act("click", ref="@s1:e1"))
|
||||
brain.pc.state["pending"] = {"w1": {"turn": brain.pc.turn}}
|
||||
return "ok"
|
||||
brain = FakeBrain(answer)
|
||||
window = {"id": "w1", "program": "CalculatorApp.exe", "title": "계산기"}
|
||||
|
||||
async def body(url):
|
||||
async with connect(url) as ws:
|
||||
await hello(ws)
|
||||
await send(ws, type="reply", id="r1", user="100", text="q1", via="voice", speak=False)
|
||||
seen = await recv_until(ws, lambda m: isinstance(m, dict) and m.get("type") == "pc_action")
|
||||
action = seen[-1]
|
||||
await send(ws, type="pc_action_result", id=action["id"], ok=False, ask=True, kinds=["click"],
|
||||
window=window)
|
||||
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("type") == "reply_text")
|
||||
await send(ws, type="reply", id="r2", user="100", text="q2", via="voice", speak=False)
|
||||
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("type") == "reply_text")
|
||||
await send(ws, type="reply", id="t1", user="100", text="q", via="task")
|
||||
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("type") == "reply_text")
|
||||
return action
|
||||
|
||||
action = asyncio.run(with_worker(body, store=store, brain=brain))
|
||||
assert {k: v for k, v in action.items() if k not in ("type", "id")} == {
|
||||
"action": "click", "user": "100", "via": "voice", "ref": "@s1:e1"}
|
||||
assert results == [{"ok": False, "ask": True, "kinds": ["click"], "window": window}]
|
||||
(t1, s1), (t2, s2) = seen_pc
|
||||
assert t2 == t1 + 1 and s2 is s1 and s2["pending"] == {"w1": {"turn": t1}}
|
||||
assert brain.pc is None # a scheduled task operates nothing
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_a_pc_action_waits_longer_than_the_other_app_actions(store):
|
||||
"""Starting a program and reading its new window takes the app up to about 20 s (admin.spec.md,
|
||||
"PC control"): a PC action is not given up after the chat actions' wait."""
|
||||
results = []
|
||||
brain = FakeBrain(lambda u, t: results.append((brain.screen.act("list"), brain.pc.act("run", program="calc")))
|
||||
or "ok")
|
||||
|
||||
async def body(url):
|
||||
async with connect(url) as ws:
|
||||
await hello(ws)
|
||||
await send(ws, type="reply", id="r1", user="100", text="q", via="voice", speak=False)
|
||||
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("type") == "screen_action")
|
||||
seen = await recv_until(ws, lambda m: isinstance(m, dict) and m.get("type") == "pc_action")
|
||||
await asyncio.sleep(0.6) # longer than chat_timeout_s
|
||||
await send(ws, type="pc_action_result", id=seen[-1]["id"], ok=True, item={"window": {"id": "w1"}})
|
||||
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("type") == "reply_text")
|
||||
|
||||
asyncio.run(with_worker(body, store=store, brain=brain, chat_timeout_s=0.3))
|
||||
(screen, pc), = results
|
||||
assert not screen["ok"] and pc == {"ok": True, "item": {"window": {"id": "w1"}}}
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_the_judgement_is_told_who_is_in_the_channel(monkeypatch):
|
||||
import voice_worker.judges as judges
|
||||
|
||||
Reference in New Issue
Block a user