Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
feat(cli-agent): a CLI agent answering the chat reads the owner's notes (RFC-0007 AP.2c, 2 of 2)
trohitg334fceff4f2a
diff --git a/RFC-0007-APPROVALS-ON-TEMPORAL.md b/RFC-0007-APPROVALS-ON-TEMPORAL.mdindex 61732d5e..6bfb6d7c 100644--- a/RFC-0007-APPROVALS-ON-TEMPORAL.md+++ b/RFC-0007-APPROVALS-ON-TEMPORAL.md@@ -482,7 +482,7 @@ Team jobs, Workspace tasks and manual Runs do not carry it, so their calls stay- A held call without a call id is refused.- A retried call is a new request and gets a new row. O4 is settled.- **The answer:** "waiting for the owner". The owner's Allow starts `ApprovedToolCallWorkflow`, which runs the node's own activity; the CLI is not involved.- - **The outcome:** the CLI agent hears it on its next turn. The context bridge (`services/cli_agent/context_bridge.py`) claims the `[update]` notes, which only `agent_activities.py:1762-1771` claims today.+ - **The outcome:** the CLI agent hears it on its next turn. When it answers the owner's chat, `AICliService.run_batch` claims the session's `[update]` notes for the run and puts them ahead of its prompt (`with_chat_notes`), as the native turn does (`chat/guide.py` `chat_turn`). The Claude Code node passes its chat stream; the Context bridge exists only with a Context node, so it is not the place.- **v0 generations keep the refusal.**- **Claude Code's built-in tools keep `dontAsk`.** Answering Claude Code's own permission prompts through cards (stdio `can_use_tool`) is not adopted: it blocks the CLI session, and a restart loses it.- **Codex is out of this RFC** (D17; §9, O8).diff --git a/server/nodes/agent/claude_code_agent/__init__.py b/server/nodes/agent/claude_code_agent/__init__.pyindex 28871c1f..801f442c 100644--- a/server/nodes/agent/claude_code_agent/__init__.py+++ b/server/nodes/agent/claude_code_agent/__init__.py@@ -405,6 +405,8 @@ class ClaudeCodeAgentNode(ActionNode):repo_root = Path(params.working_directory) if params.working_directory else None+ from services.chat.stream import chat_stream_for+svc = get_ai_cli_service()result = await svc.run_batch("claude",@@ -423,6 +425,8 @@ class ClaudeCodeAgentNode(ActionNode):allowed_credentials=params.allowed_credentials,max_parallel=params.max_parallel,ai_service=get_ai_service(),+ # Answering the owner's chat, it reads the owner's notes first.+ chat_stream=chat_stream_for({**ctx.raw, "node_id": node_id}),)elapsed = time.time() - start_timediff --git a/server/services/cli_agent/service.py b/server/services/cli_agent/service.pyindex 703466c9..7355c4a2 100644--- a/server/services/cli_agent/service.py+++ b/server/services/cli_agent/service.py@@ -58,6 +58,25 @@ DEFAULT_MAX_PARALLEL = 5BatchKey = Tuple[str, str] # (workflow_id, node_id)+async def with_chat_notes(database: Any, tasks: List[BaseAICliTaskSpec], chat_stream: Dict[str, Any]) -> List[BaseAICliTaskSpec]:+ """The tasks of a CLI agent answering the owner's chat, each with the+ session's untold notes ahead of its prompt, claimed for the run as the+ native agent's turn claims them (services/chat/guide.py ``chat_turn``):+ the owner's ratings and the outcomes of its held calls. Notes that cannot+ be read are left for the next turn."""+ from services.chat.notes import claim_notes, notes_prompt++ try:+ claimed = await claim_notes(database, session_id=str(chat_stream["session_id"]), run_id=str(chat_stream["run_id"]))+ except Exception: # noqa: BLE001 - the turn goes on without them+ logger.warning("Chat notes could not be read for a CLI turn", run_id=chat_stream.get("run_id"), exc_info=True)+ return tasks+ if not claimed:+ return tasks+ lines = notes_prompt(claimed)+ return [task.model_copy(update={"prompt": f"{lines}\n\n{task.prompt}"}) for task in tasks]++class AICliService:"""Singleton service. Use `get_ai_cli_service()` to access."""@@ -90,8 +109,11 @@ class AICliService:max_parallel: int = DEFAULT_MAX_PARALLEL,mcp_port: Optional[int] = None,ai_service: Any = None,+ chat_stream: Optional[Dict[str, Any]] = None,) -> BatchResult:- """Run a list of CLI tasks under one batch.+ """Run a list of CLI tasks under one batch. ``chat_stream``: the chat+ run the agent answers (services/chat/stream.py ``chat_stream_for``),+ whose untold notes go ahead of each task's prompt.Returns:`BatchResult` aggregating per-task `SessionResult`s.@@ -101,6 +123,10 @@ class AICliService:"""provider = create_cli_provider(provider_name)task_list: List[BaseAICliTaskSpec] = list(tasks)+ if chat_stream:+ from services.plugin.deps import get_database++ task_list = await with_chat_notes(get_database(), task_list, chat_stream)connected_tools = list(connected_tools or [])context_bridge: Optional[SpecializedAgentContextBridge] = Nonecontext_original_prompts: List[str] = []diff --git a/server/tests/services/cli_agent/test_chat_notes.py b/server/tests/services/cli_agent/test_chat_notes.pynew file mode 100644index 00000000..7691fc18--- /dev/null+++ b/server/tests/services/cli_agent/test_chat_notes.py@@ -0,0 +1,40 @@+"""A CLI agent answering the owner's chat reads the session's untold notes+first, as the native agent's turn does (RFC-0007 §4.9): among them the+outcomes of its held calls."""++from __future__ import annotations++from types import SimpleNamespace++import pytest++from services.chat import notes+from services.cli_agent.service import with_chat_notes+from services.cli_agent.types import ClaudeTaskSpec++pytestmark = pytest.mark.asyncio++STREAM = {"session_id": "wf", "run_id": "r_1"}+++async def test_the_notes_go_ahead_of_each_prompt_claimed_for_the_run(monkeypatch):+ claimed = []++ async def claim_notes(database, *, session_id, run_id):+ claimed.append((session_id, run_id))+ return [SimpleNamespace(text='[update]{"result": "sent"}[/update]')]++ monkeypatch.setattr(notes, "claim_notes", claim_notes)+ monkeypatch.setattr(notes, "notes_prompt", lambda found: "\n".join(note.text for note in found))+ tasks = await with_chat_notes(object(), [ClaudeTaskSpec(prompt="Any news?")], STREAM)+ assert tasks[0].prompt == '[update]{"result": "sent"}[/update]\n\nAny news?'+ assert claimed == [("wf", "r_1")]+++async def test_notes_that_cannot_be_read_wait_for_the_next_turn(monkeypatch):+ async def claim_notes(database, *, session_id, run_id):+ raise RuntimeError("database is locked")++ monkeypatch.setattr(notes, "claim_notes", claim_notes)+ tasks = await with_chat_notes(object(), [ClaudeTaskSpec(prompt="Any news?")], STREAM)+ assert tasks[0].prompt == "Any news?"