mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-11-27 23:58:47 +00:00
* fix(proactive): simplify round files and restore failed summaries * fix(proactive): validate document-relative Markdown links * feat(proactive_agent): implement v2 daily record workflow with single-file decision - Add ProactiveAgentStepV2 class to support single daily note decision and reminder - Introduce RoundOutputs for v2 round file tracking, and keep RoundArtifacts for v1 summary backup - Refactor AgentOutbox to support both v1 standalone reminder files and v2 daily reminder records - Add proactive_record utilities to parse and validate v2 daily record frontmatter and metadata - Enhance proactive_agent to prepare, read, and manage artifacts for both v1 and v2 flows - Add configuration profile proactive_v2 to enable new workflow with backward compatibility - Update proactive.yaml and reactive proactive_agent_step configuration comment for easy switching - Provide extensive schema validation for v2 reminders ensuring priority and message consistency - Document v2 workflow and usage in English and Chinese runtime docs - Add unit tests for v2 step verifying single file output and proper decision handling * refactor(agent/runtime): replace ReminderRef with string keys and simplify reminder handling - Remove ReminderRef model and switch to using workspace-relative string keys for reminders - Simplify AgentOutbox to read, write, and manage reminders keyed by strings - Change file locking and version checking to protect concurrent edits on daily record files - Replace legacy and v2 reminder file handling with unified ReminderFiles storage - Adjust ChatNotifications to operate with the new key scheme and update pending/read sets - Refactor RoundOutputs to RoundRecord for safer round record tracking and rollback - Remove unused ProactiveRunResult and related references from imports and exports - Update InboxWakeRequest, AgentReminder, and related models for consistent ID and path validation - Adjust proactive agent runtime and local runtime to check reminder versions before commit - Correct language and docs to describe reminders as daily records instead of separate files - Clean up roles of inbox and outbox for reminder ownership, delivery, and acknowledgments * fix(proactive): serialize round commits and align desktop reminders * refactor(proactive): unify task triggers in Proactive Runtime * fix(proactive): bound reminder payloads and simplify receipts * refactor(studio): share workbench and simplify proactive delivery * fix(studio): update and centralize build dependencies * fix(proactive): guard draft repair and verify Studio deployments * chore(docs): update source-map-js * feat(release): support publishing selected artifacts from a tag * chore(studio): remove the public playground * refactor: simplify reminders and release workflows * fix: preserve proactive records and align release provenance * test(proactive): remove brittle prompt and preset assertions * fix(proactive): register reminders after input acknowledgement * feat(notebook): list projects across todos and ideas * feat(studio): connect mobile apps to configurable ReMe services * fix(proactive): reserve registered reminder paths * fix(studio): request Android local network access * fix(proactive): reserve reminder paths referenced by receipts
182 lines
7.8 KiB
Python
182 lines
7.8 KiB
Python
"""Client projection preserves live/history semantics without exposing provider records."""
|
|
|
|
# pylint: disable=missing-function-docstring
|
|
|
|
from pathlib import Path
|
|
import runpy
|
|
|
|
import pytest
|
|
|
|
from reme.schema import SessionMessage, StreamChunk
|
|
from reme.utils.agent_transcript import TranscriptProjector, project_messages, tool_actions
|
|
|
|
|
|
def project(*chunks, completed=None):
|
|
projector = TranscriptProjector("session", "turn")
|
|
for chunk in chunks:
|
|
projector.update(StreamChunk.model_validate(chunk))
|
|
return projector.message(completed=completed)
|
|
|
|
|
|
def test_null_ends_empty_replacements_final_corrections_and_late_deltas():
|
|
projector = TranscriptProjector("session", "turn")
|
|
for text in ("你", "好"):
|
|
projector.update(StreamChunk(block_id="intro", chunk=text))
|
|
projector.update(StreamChunk(block_id="intro", chunk=None, event="end"))
|
|
projector.update(StreamChunk(block_id="intro", chunk="stale"))
|
|
projector.update(StreamChunk(block_id="answer", chunk="Draft", event="start"))
|
|
projector.update(StreamChunk(block_id="answer", chunk="", event="end"))
|
|
projector.update(StreamChunk(chunk_type="reply_end", status="completed", chunk={"result": "Corrected"}))
|
|
message = projector.message()
|
|
assert message.content == "你好\n\nCorrected"
|
|
assert [item.id for item in message.items] == ["intro", "answer"]
|
|
assert message.items[-1].phase == "final_answer"
|
|
assert message.completed and message.outcome == "completed"
|
|
|
|
|
|
COMMAND = {
|
|
"type": "commandExecution",
|
|
"command": "cat note.md; ls; rg topic; npm test",
|
|
"commandActions": [
|
|
{"type": "read", "path": "note.md"},
|
|
{"type": "listFiles", "path": "daily"},
|
|
{"type": "search", "path": "daily", "query": "topic"},
|
|
{"type": "unknown", "command": "npm test"},
|
|
],
|
|
}
|
|
|
|
|
|
@pytest.mark.parametrize("output", ["Complete output", None, ""])
|
|
def test_native_tool_history_equals_live_projection_and_keeps_action_targets(output):
|
|
final = {
|
|
"chunk_type": "tool_result",
|
|
"tool_call_id": "call",
|
|
"tool_call_name": "commandExecution",
|
|
"event": "end",
|
|
"status": "completed",
|
|
"chunk": {**COMMAND, "aggregatedOutput": output},
|
|
}
|
|
history = project(final)
|
|
live = project(
|
|
{**final, "chunk_type": "tool_call", "event": "start", "status": "running", "chunk": COMMAND},
|
|
{"chunk_type": "tool_result", "tool_call_id": "call", "chunk": "Partial output"},
|
|
final,
|
|
)
|
|
assert history == live
|
|
tool = history.items[0]
|
|
assert tool.input == COMMAND["command"] and tool.output == (output or "")
|
|
assert [action.kind for action in tool.actions] == ["read", "list", "search", "command"]
|
|
assert tool.actions[0].target == "note.md" and tool.actions[2].query == "topic"
|
|
|
|
|
|
def test_interleaved_tools_stay_in_order_and_tool_failure_does_not_fail_the_turn():
|
|
reply = project(
|
|
{"chunk_type": "tool_call", "tool_call_id": "first", "chunk": {"command": "one"}},
|
|
{"chunk_type": "content", "block_id": "text", "chunk": "Progress", "event": "end"},
|
|
{"chunk_type": "tool_call", "tool_call_id": "second", "chunk": {"command": "two"}},
|
|
{"chunk_type": "tool_result", "tool_call_id": "first", "chunk": {"success": False}, "event": "end"},
|
|
{"chunk_type": "reply_end", "status": "completed", "chunk": {"result": "Done"}},
|
|
)
|
|
assert [item.id for item in reply.items] == ["first", "text", "second"]
|
|
assert [item.status for item in reply.items] == ["failed", "completed", "unknown"]
|
|
assert reply.outcome == "completed" and reply.error is None
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"name,payload,kind,target,query",
|
|
[
|
|
("fileChange", {"type": "fileChange", "changes": [{"path": "a.md"}]}, "edit", "a.md", None),
|
|
("functions.view_image", {"path": "chart.png"}, "image", "chart.png", None),
|
|
("read_file", {"arguments": '{"path":"daily/report.md"}'}, "read", "daily/report.md", None),
|
|
("exec_command", {"cmd": "cat README.md"}, "command", "cat README.md", None),
|
|
(
|
|
"webSearch",
|
|
{"type": "webSearch", "action": {"type": "search", "query": "Android", "queries": []}},
|
|
"webSearch",
|
|
None,
|
|
"Android",
|
|
),
|
|
(
|
|
"webSearch",
|
|
{"type": "webSearch", "action": {"type": "openPage", "url": "https://example.com"}},
|
|
"browse",
|
|
"https://example.com",
|
|
None,
|
|
),
|
|
(
|
|
"webSearch",
|
|
{"type": "webSearch", "action": {"type": "findInPage", "url": "https://example.com", "pattern": "ARM64"}},
|
|
"search",
|
|
"https://example.com",
|
|
"ARM64",
|
|
),
|
|
],
|
|
)
|
|
def test_tool_semantics_are_normalized_at_the_backend(name, payload, kind, target, query):
|
|
action = tool_actions(name, payload)[0]
|
|
assert action["kind"] == kind and action.get("target") == target and action.get("query") == query
|
|
|
|
|
|
def test_patches_mcp_results_and_public_attachments_hide_native_diagnostics():
|
|
reply = project(
|
|
{
|
|
"chunk_type": "tool_result",
|
|
"tool_call_id": "read",
|
|
"event": "end",
|
|
"chunk": {"type": "mcpToolCall", "arguments": {"path": "a.md"}, "result": None, "error": None},
|
|
},
|
|
{
|
|
"chunk_type": "tool_result",
|
|
"tool_call_id": "edit",
|
|
"event": "end",
|
|
"chunk": {"type": "fileChange", "changes": [{"path": "a.md", "diff": "+ Updated"}]},
|
|
},
|
|
{
|
|
"chunk_type": "think",
|
|
"block_id": "private",
|
|
"chunk": "secret",
|
|
"metadata": {"native": {"secret": "provider"}},
|
|
},
|
|
{"chunk_type": "think", "block_id": "public", "event": "end", "chunk": "Plan", "metadata": {"kind": "plan"}},
|
|
{"chunk_type": "data", "block_id": "image", "media_type": "image/png", "chunk": "aGVsbG8="},
|
|
)
|
|
assert reply.items[0].input == '{\n "path": "a.md"\n}' and reply.items[0].output == ""
|
|
assert reply.items[1].input == "a.md\n+ Updated" and reply.items[1].output == ""
|
|
assert reply.items[2].type == "summary" and reply.items[2].kind == "plan"
|
|
assert reply.items[3].url == "data:image/png;base64,aGVsbG8=" and reply.items[3].label == "Image"
|
|
assert "secret" not in reply.model_dump_json() and "native" not in reply.model_dump_json()
|
|
|
|
|
|
def test_grouped_history_matches_live_identity_without_mutating_native_messages():
|
|
native = [
|
|
SessionMessage(
|
|
id="model-1",
|
|
role="assistant",
|
|
content="Progress",
|
|
turn_id="turn",
|
|
chunks=[StreamChunk(block_id="intro", chunk="Progress", event="end")],
|
|
),
|
|
SessionMessage(
|
|
id="model-2",
|
|
role="assistant",
|
|
content="Answer",
|
|
turn_id="turn",
|
|
completed=False,
|
|
chunks=[StreamChunk(block_id="answer", chunk="Answer")],
|
|
),
|
|
SessionMessage(id="reminder", role="assistant", source="proactive", content="Reminder", turn_id="turn"),
|
|
]
|
|
before = [item.model_dump() for item in native]
|
|
messages = project_messages("session", native, notifications=True)
|
|
assert [item.id for item in messages] == ["turn:assistant", "reminder"]
|
|
assert messages[0].content == "Progress\n\nAnswer" and not messages[0].completed
|
|
assert [item.id for item in messages[0].items] == ["intro", "answer"]
|
|
assert messages[1].notification_eligible
|
|
assert before == [item.model_dump() for item in native]
|
|
|
|
|
|
def test_generated_client_contract_matches_public_schemas_and_real_projection():
|
|
root = Path(__file__).resolve().parents[2]
|
|
generator = runpy.run_path(str(root / "reme_studio/client/scripts/client-contract.py"))
|
|
assert (root / "reme_studio/client/src/wire.ts").read_text() == generator["render"]()
|
|
assert (root / "reme_studio/client/tests/contract-fixture.ts").read_text() == generator["fixture"]()
|