ReMe/reme/steps/proactive/agent/api.py
jinliyl ae55e2e570
Some checks are pending
CI / Python packages / Build and verify distributions (push) Waiting to run
CI / Python quality / GitHub Actions (push) Waiting to run
CI / Python quality / Pre-commit (push) Waiting to run
CI / Python tests / Hermes embedded - ubuntu-latest (push) Waiting to run
CI / Python tests / Hermes embedded - windows-latest (push) Waiting to run
CI / Python tests / Unit Tests - py3.11 (push) Waiting to run
CI / Python tests / Unit Tests - py3.12 (push) Waiting to run
CI / Python tests / Unit Tests - py3.13 (push) Waiting to run
CI / Python tests / Unit Tests - py3.14 (push) Waiting to run
CI / ReMe Studio / Studio checks (push) Waiting to run
CI / Windows / CLI smoke - py3.11 (push) Waiting to run
Deploy / Documentation / Build documentation (push) Waiting to run
Deploy / Documentation / deploy (push) Blocked by required conditions
Security / CodeQL / Analyze javascript-typescript (push) Waiting to run
Security / CodeQL / Analyze python (push) Waiting to run
feat!: split proactive runtimes and add Studio backend management (#776)
* refactor(proactive)!: separate runtime ownership and unify delivery

* refactor(proactive): finish runtime and Studio migration

* test(proactive): make scheduled skip coverage deterministic

* refactor(studio): unify navigation and notebook resource loading

* feat(studio): edit workspace documents and update proactive task names

* refactor(studio): simplify task settings and navigation

* feat(studio): secure and supervise backend settings

* feat(studio): unify workbench timelines and refine desktop updates

Use shared timeline panes for notebook, memory, and resources. Add Todo creation ordering, persist companion visibility, and align desktop update handling and release artifacts.

Recheck editor file versions at read and publication boundaries. Retry reminder detail requests from the resource view.

* fix(studio): support unsigned GitHub preview releases

* fix: verify container state and isolate proactive view errors

Mount private supervisor state in Docker smoke tests and verify token and settings persistence. Exercise Studio startup with a loopback-only model fixture, and exclude packaged desktop output from Docker contexts.

Keep Remy subscriptions and healthy tasks available when an individual task has an invalid workspace path or session history.

* fix(home): align candidate Docker context exclusions

* chore(deps): update openai-codex dependency to v0.172.0

- Bump openai-codex from version 0.169.0 to 0.172.0 in pyproject.toml
- Keep other dependencies unchanged
- Ensure compatibility with latest openai-codex features and fixes

* fix(daemon): discover parent dotenv and isolate listeners

Restore parent-directory environment discovery in workers while retaining system precedence. Partition the default supervisor profile and lock by the configured bind address and port.
2026-11-25 21:33:16 +08:00

173 lines
6.6 KiB
Python

"""Current Agent conversations independent of native wrapper or desktop implementation."""
from contextlib import aclosing
from ....constants import CHAT_AGENT_NAME
from .base import BaseAgentStep
from .chat import BaseChatAgentStep
from ....utils.files.path_lock import get_path_lock
from ....core.registry import R
from ....enumeration import ChunkEnum
from ....schema import StreamChunk
from ....utils.agent_transcript import TranscriptProjector
from ....schema.agent_view import (
AskAgentRequest,
AgentRequest,
AgentInboxRequest,
ListTaskRemindersRequest,
AgentReminderRequest,
TaskDocumentRequest,
)
class _AgentViewStep(BaseAgentStep):
"""Validate identities and permissions before reading runtime resources."""
def request(self, schema=AgentRequest):
"""Validate public inputs before authorizing the workspace."""
request = schema.model_validate(self.parameters())
self.require_paths(self.workspace_path)
return request
@R.register("agent_list_step")
class AgentListStep(_AgentViewStep):
"""List Remy and retained task identities without creating sessions."""
async def execute(self):
if self.parameters():
raise ValueError("list_agents accepts no arguments")
self.require_paths(self.workspace_path)
self.context.response.answer = await self.proactive_manager.list_views()
return self.context.response
@R.register("agent_session_step")
class AgentSessionStep(_AgentViewStep):
"""Read Chat history or the latest task turn without changing the formal session."""
async def execute(self):
request = self.request()
self.context.response.answer = await self.proactive_manager.read_agent(request.agent_name)
return self.context.response
@R.register("task_document_step")
class TaskDocumentStep(_AgentViewStep):
"""Reuse contained file operations for a named task's original description."""
async def execute(self):
request = TaskDocumentRequest.model_validate(self.parameters())
manager = self.proactive_manager
self.require_paths(manager.registry.directory)
agent = await manager.definition(request.agent_name)
target = manager.registry.task_path(agent)
self.require_paths(target)
path = target.relative_to(self.workspace_path).as_posix()
if request.action == "read":
async with await get_path_lock(target):
await self.dispatch_steps(["load_step"], path=path)
else:
await self.dispatch_steps(
["save_step"],
path=path,
content=request.content,
expected_mtime=request.expected_mtime,
)
response = self.context.response
if response.success:
response.answer = {
"path": path,
"mtime": response.metadata["mtime"],
**({"content": response.answer} if request.action == "read" else {}),
}
return response
@R.register("watch_agent_session_step")
class WatchAgentSessionStep(_AgentViewStep):
"""Relay Chat history changes or atomic latest-task-turn snapshots with sidebar status."""
async def execute(self):
request = self.request()
async with aclosing(self.proactive_manager.watch_agent(request.agent_name)) as events:
async for event in events:
await self.context.add_stream_chunk(StreamChunk(chunk_type=ChunkEnum.DATA, chunk=event))
return self.context.response
@R.register("ask_agent_step")
class AskAgentStep(_AgentViewStep, BaseChatAgentStep):
"""Continue Chat or ask a read-only fork of the latest task session."""
async def execute(self):
request = self.request(AskAgentRequest)
if not request.query.strip():
raise ValueError("query must not be blank")
projector = TranscriptProjector()
async def publish(chunk):
projector.update(chunk)
if projector.error:
self.context.stream_error = projector.error
# Main Chat content has one authority: the session subscription.
if request.agent_name == CHAT_AGENT_NAME and chunk.chunk_type not in {
ChunkEnum.REPLY_START,
ChunkEnum.REPLY_END,
ChunkEnum.ERROR,
}:
return
await self.context.add_stream_chunk(
StreamChunk(chunk_type=ChunkEnum.DATA, chunk=projector.message().model_dump(mode="json")),
)
if request.agent_name == CHAT_AGENT_NAME:
return await self.chat(request.query, on_chunk=publish)
reply = await self.query_reply(request.agent_name, request.query, on_chunk=publish)
self.context.response.success = reply["status"] == "completed" and self.context.stream_error is None
self.context.response.answer = reply["result"]
self.context.response.metadata.update(reply, agent_name=request.agent_name)
return self.context.response
@R.register("agent_new_session_step")
class AgentNewSessionStep(_AgentViewStep, BaseChatAgentStep):
"""Start a fresh main Chat session while retaining earlier history."""
async def execute(self):
if self.parameters():
raise ValueError("create_chat_session accepts no arguments")
self.require_paths(self.workspace_path)
await self.new_session()
self.context.response.answer = await self.proactive_manager.read_agent(CHAT_AGENT_NAME)
return self.context.response
@R.register("list_task_reminders_step")
class ListTaskRemindersStep(_AgentViewStep):
"""Page a task Agent's committed reminders."""
async def execute(self):
request = self.request(ListTaskRemindersRequest)
self.context.response.answer = await self.proactive_manager.outbox.list(**request.model_dump())
return self.context.response
@R.register("agent_reminder_step")
class AgentReminderStep(_AgentViewStep):
"""Read a task reminder or the sources of a Chat message."""
async def execute(self):
request = self.request(AgentReminderRequest)
self.context.response.answer = await self.proactive_manager.outbox.read(**request.model_dump())
return self.context.response
@R.register("agent_inbox_step")
class AgentInboxStep(_AgentViewStep):
"""Read any Agent's inputs without claiming or acknowledging them."""
async def execute(self):
request = self.request(AgentInboxRequest)
self.context.response.answer = await self.proactive_manager.list_inputs(**request.model_dump())
return self.context.response