Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

chore: synchronize the release candidate with current main

rubenluetke10-beep7f7f87c88113
diff --cc jarvis/agent_chat/service.py
index 1ce87842dd,b0ff9f3574..8de865c782
--- a/jarvis/agent_chat/service.py
+++ b/jarvis/agent_chat/service.py
@@@ -698,22 -684,195 +684,201 @@@ class AgentChatService
turn_id = uuid.uuid4().hex
cancel = asyncio.Event()
run = _Running(turn_id, cancel)
- self._running[session_id] = run
- if session.surface == "jarvis" and direct_user and incoming is None and not control_owned:
- from .store import ChatSelection
+ self._preparing[session_id] = run
+ control_revision: int | None = None
+ control_text = text
+ if (
+ session.surface in ("jarvis", "society")
+ and direct_user
+ and incoming is None
+ and not control_owned
+ ):
+ if hasattr(self, "_controls"):
+ try:
+ control_revision = await self._controls.user_message(session_id, text)
+ except (asyncio.CancelledError, Exception):
+ if self._preparing.get(session_id) is run:
+ self._preparing.pop(session_id, None)
+ run.ready.set()
+ raise
+ try:
+ if read_only:
+ session = replace(session, permission_mode="plan")
+ if session.permission_mode in ("plan", "read-only") and session.surface in (
+ "jarvis",
+ "society",
+ ):
+ from .control import supports_restricted_turn
+
+ if not supports_restricted_turn(session):
+ raise ValueError(
+ "This runner cannot enforce read-only mode; choose an API model"
+ )
+ if incoming is not None:
+ receipt = await self.receive_message(session_id, incoming)
+ if receipt["status"] == "delivered":
+ if self._preparing.get(session_id) is run:
+ self._preparing.pop(session_id, None)
+ run.ready.set()
+ return str(receipt.get("turn_id") or "")
+ if receipt["status"] == "failed":
+ raise ValueError("This internal message already failed")
+ if self.is_running(session_id):
+ raise SessionBusy(session_id)
+ kit = kit_for(session.surface)
+ text = text.strip()
+ attached = chat_attachments.to_analysis(attachments)
+ if not text and not attached:
+ raise ValueError("empty message")
+ # What the turn receives; ``text`` stays what the person typed so the
+ # timeline shows their sentence rather than a page of extracted PDF.
+ prompt = chat_attachments.compose(text, attached)
++ if attached and session.surface == "jarvis":
++ image_context = await asyncio.to_thread(
++ chat_attachments.handoff_context, session.cwd, attached, session_id=session_id,
++ )
++ if image_context:
++ prompt += "\n\n" + image_context
+ # Agent cards serialize Add selections as capability pins. Translate the
+ # browser pin to the same validated receipt used by the root composer.
+ if session.surface == "jarvis" and any(
+ "core:browser" in {item.strip() for item in match.split(",")}
+ for match in re.findall(r"(?m)^\[tools:\s*([^\]\r\n]+)\]\s*$", text)
+ ):
+ tool_choices = list(dict.fromkeys([*(tool_choices or []), "tool:society_browser"]))
+ selected = []
+ if tool_choices:
+ if session.surface != "jarvis":
+ raise ValueError("Tool selections are supported by the Jarvis chat")
+ from jarvis.agent_chat.runner_brain import brain_manager
+ from jarvis.agent_chat.tool_catalog import live_catalog, resolve_choices
+
+ inventory = await asyncio.to_thread(
+ live_catalog, brain_manager(), cwd=session.cwd, stance=session.permission_mode
+ )
+ selected = resolve_choices(tool_choices, inventory)
+ # Discovery yields; another send may have acquired this session.
+ if self.is_running(session_id):
+ raise SessionBusy(session_id)
+
+ # Roster state can change while a control message or an internal
+ # delivery is being recorded. Rebind after those awaits, then reserve
+ # the seat without yielding again. Keep the caller's read-only choice.
+ if session.surface == "society":
+ session = await self.bind_society_session(session_id, routine_run=routine_run)
+ if read_only:
+ session = replace(session, permission_mode="plan")
+ if session.permission_mode in ("plan", "read-only"):
+ from .control import supports_restricted_turn
+
+ if not supports_restricted_turn(session):
+ raise ValueError(
+ "This runner cannot enforce read-only mode; choose an API model"
+ )
- self.store.save_chat_selection(
- ChatSelection(session.provider, session.model, session.effort, session.account_id)
- )
- from jarvis.core.tool_read_only import set_chat_read_only
+ # Revalidate after the last await, then transfer the reservation
+ # to the runner without yielding. Scheduled runs stay independent.
+ if cancel.is_set():
+ raise asyncio.CancelledError
+ if self._preparing.get(session_id) is not run or self.is_running(session_id):
+ raise SessionBusy(session_id)
+ if session.surface == "society":
+ from jarvis.society.chat_binding import direct_chat_owner
+
+ owner = direct_chat_owner(session_id)
+ if owner is not None and any(
+ direct_chat_owner(sid) == owner and self.is_running(sid)
+ for sid in self._running if sid != session_id
+ ):
+ raise SessionBusy(session_id)
+
+ self._preparing.pop(session_id, None)
+ self._running[session_id] = run
+ except (asyncio.CancelledError, Exception):
+ if self._preparing.get(session_id) is run:
+ self._preparing.pop(session_id, None)
+ try:
+ if control_revision is not None:
+ await self._controls.message_rejected(
+ session_id, control_text, control_revision
+ )
+ except Exception:
+ log.exception(
+ "chat control status could not close rejected message in %s", session_id
+ )
+ finally:
+ run.ready.set()
+ raise
+ turn_started_emitted = False
+ try:
+ if (
+ session.surface == "jarvis"
+ and direct_user
+ and incoming is None
+ and not control_owned
+ ):
+ from .store import ChatSelection
+
+ self.store.save_chat_selection(
+ ChatSelection(
+ session.provider, session.model, session.effort, session.account_id
+ )
+ )
+ from jarvis.core.tool_read_only import set_chat_read_only
- set_chat_read_only(session_id, session.permission_mode in ("plan", "read-only"))
+ set_chat_read_only(session_id, session.permission_mode in ("plan", "read-only"))
- history_start = kit.history_start(session) if kit.history_start is not None else 0
- history = self.store.list_events(session_id, after_seq=history_start)
- if incoming is not None:
- await self.message_status(session_id, incoming.message_id, "delivered", turn_id=turn_id)
- else:
+ history_start = kit.history_start(session) if kit.history_start is not None else 0
+ history = self.store.list_events(session_id, after_seq=history_start)
+ if incoming is not None:
+ await self.message_status(
+ session_id, incoming.message_id, "delivered", turn_id=turn_id
+ )
+ else:
+ await self._emit(
+ session_id,
+ make_event(
+ "user_message",
+ {
+ # The full prompt: this is what was actually sent, and the
+ # API runner rebuilds the conversation from these events —
+ # storing only the sentence would lose the picture on the
+ # NEXT turn (runner_api.messages_from_events).
+ "text": prompt,
+ **({"origin": "control"} if control_owned and not direct_user else {}),
+ **(
+ {"tool_choices": [row.model_dump(mode="json") for row in selected]}
+ if selected
+ else {}
+ ),
+ # What the person typed, when it differs from the prompt.
+ # Absent on an ordinary message, so nothing changes there.
+ **(
+ {"typed": display_text if display_text is not None else text}
+ if attached or display_text is not None
+ else {}
+ ),
+ **(
+ {
+ "attachments": [
+ {
+ "name": item.name,
+ "reference": item.reference,
+ "kind": item.kind,
+ "described_by": item.described_by,
+ "note": item.note,
+ }
+ for item in attached
+ ]
+ }
+ if attached
+ else {}
+ ),
+ },
+ ),
+ )
+ runner = selected_runner or resolve_runner(session.provider, surface=session.surface)
+ turn_started_emitted = True
await self._emit(
session_id,
make_event(