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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(self-build): code builds use the shared provenance key and the loop's own seats (#773)
Ruben Lütke45114eebf980
diff --git a/docs/self-build-code.md b/docs/self-build-code.mdindex 70bff1a9c1..b3cf5020bf 100644--- a/docs/self-build-code.md+++ b/docs/self-build-code.md@@ -77,9 +77,11 @@ the queue; an undo stops it the same way and removes what it made.inside the repository (`<repo>/.worktrees/`). A branch of that name thatalready exists, here or on GitHub, stops the build. The person's checkout isnever touched.-2. At most one planning call on a connected subscription, inside- `cost.attributed(build_id)`. A `large` estimate stops the build. Without a- subscription brain there is no call and the coding agent plans itself.+2. At most one planning call through the loop's shared seats+ (`self_build.brain.ask`: signed-in subscriptions, then keyless local+ models, never a per-token key), inside `cost.attributed(build_id)`. A+ `large` estimate stops the build. Without a seat there is no call and the+ coding agent plans itself.3. A headless coding thread in that worktree (the IDE's thread surface, so theperson can read every step). The prompt holds the brief, the issue, therelevant file outlines and the rules: small change with tests, follow the@@ -112,6 +114,14 @@ minutes):worktree go and the build is `undone`. Each outcome feeds the repository'sprofile (triage) and its brief (`outcomes`, read by the next prompt).+## In the ledger++The record's `artefact` follows the provenance convention every "built by+Dodaios" badge joins on: `{"type": "code", "id": <pull request URL>, "repo":+"<owner>/<repo>"}`, plus `stage` (`worktree`, `coding`, `pushing`, `pushed`,+`pull_request`), `branch`, `draft`, the local test result and the changed+files. Before the pull request exists, `id` is empty.+## UndoThe undoer closes the open pull request, deletes the remote and local branchdiff --git a/dodaios/self_build/code/builder.py b/dodaios/self_build/code/builder.pyindex 24e4fdbee0..329c9bc4d7 100644--- a/dodaios/self_build/code/builder.py+++ b/dodaios/self_build/code/builder.py@@ -302,7 +302,8 @@ async def _record(ctx: Context, record: BuildRecord, stage: str, undo: dict[str, Any], **extra: Any) -> None:artefact = {- "type": "branch",+ "type": "code",+ "id": "", # the pull request's URL, once there is one"repo": undo["repo"],"branch": undo["branch"],"stage": stage,@@ -532,7 +533,9 @@ async def finish()undo.update({"pr_id": pull.id, "pr_number": pull.number, "pr_url": pull.url})artefact = {- "type": "pull_request",+ "type": "code",+ "id": pull.url,+ "stage": "pull_request","repo": repo,"number": pull.number,"url": pull.url,diff --git a/dodaios/self_build/code/context.py b/dodaios/self_build/code/context.pyindex df9753bc7f..0559f46d3a 100644--- a/dodaios/self_build/code/context.py+++ b/dodaios/self_build/code/context.py@@ -37,6 +37,11 @@ def branch_name(number: int, title: str) -> str:return f"{BRANCH_PREFIX}issue-{int(number)}" + (f"-{slug}" if slug else "")+def has_pull(record: Any) -> bool:+ """Has the build opened its pull request? (``artefact.stage == "pull_request"``)"""+ return record.artefact.get("stage") == "pull_request"++def land_repos(config: Any) -> frozenset[str]:"""Repositories the person opted in to "land it" (merge after green CI)."""section = getattr(config, "self_build", None)diff --git a/dodaios/self_build/code/loop.py b/dodaios/self_build/code/loop.pyindex 6f9a33c2be..3ba7ec3ce4 100644--- a/dodaios/self_build/code/loop.py+++ b/dodaios/self_build/code/loop.py@@ -18,6 +18,7 @@ plan call and the coding run of a build.from __future__ import annotationsimport asyncio+import functoolsimport timefrom pathlib import Pathfrom typing import Any, Final@@ -28,7 +29,7 @@ from .. import policyfrom ..ledger import now_msfrom ..records import BuildRecord, Kind, Statefrom . import builder, intake, planner, seat-from .context import Context+from .context import Context, has_pullfrom .github import GitHub, GitHubApifrom .idle import person_idlefrom .runner import RunResult, ThreadRunner@@ -173,7 +174,7 @@ class CodeLoop:if not waiting:return "nothing to build"record = min(waiting, key=lambda r: r.created_ms)- if record.artefact.get("type") == "pull_request":+ if has_pull(record):# The app stopped right after opening the pull request: CI decides now.await asyncio.to_thread(ctx.ledger.set_state, record.id, State.PROVING, "pull request opened"@@ -288,7 +289,7 @@ def install(service: Any, app_state: Any = None) -> CodeLoop:seat=_seat,idle=person_idle,projects=_projects,- plan=planner.plan,+ plan=functools.partial(planner.plan, config=service.config),dodaios_root=Path(dodaios.__file__).resolve().parent.parent,)loop = CodeLoop(ctx)diff --git a/dodaios/self_build/code/planner.py b/dodaios/self_build/code/planner.pyindex 29fca05d51..be0de8f2c4 100644--- a/dodaios/self_build/code/planner.py+++ b/dodaios/self_build/code/planner.py@@ -1,9 +1,10 @@"""The one model call before a coding run: a short plan and a size estimate.It runs only when a build was admitted to building (or accepted), never for a-proposal, and only on a connected subscription-(``brain.resolver.resolve_subscription_brain``). Without one there is no call-at all: the coding agent plans for itself and the estimate stays unknown.+proposal, and only through the loop's shared seat list+(:func:`dodaios.self_build.brain.ask`: signed-in subscriptions, then keyless+local models, never a per-token key). Without a seat there is no call at all:+the coding agent plans for itself and the estimate stays unknown.Every call runs inside :func:`dodaios.self_build.cost.attributed`, so theledger shows what it cost.@@ -13,7 +14,6 @@ something to hand an unattended agent.from __future__ import annotations-import asyncioimport refrom collections.abc import Callablefrom dataclasses import dataclass@@ -53,11 +53,10 @@ def parse(answer: str) -> Plan:return Plan(text=plan.strip()[:2_000], size=size)-def _subscription_brain() -> Any | None:- from dodaios.brain.resolver import resolve_subscription_brain+def _config() -> Any:from dodaios.core.config import load_config- return resolve_subscription_brain(load_config())+ return load_config()async def plan(@@ -65,39 +64,24 @@ async def plan(issue: Issue,brief_text: str,*,- brain: Callable[[], Any | None] = _subscription_brain,+ config: Callable[[], Any] = _config,) -> Plan:- """At most one call; an empty :class:`Plan` when no subscription can answer."""- from dodaios.core.protocols import BrainMessage, BrainRequest+ """At most one call; an empty :class:`Plan` when no seat can answer."""+ from dodaios.brain.background_policy import BackgroundDeferred++ from .. import brain- try:- model = await asyncio.to_thread(brain)- except Exception: # noqa: BLE001 - no brain is an answer: the agent plans itself- logger.opt(exception=True).info("self-build code: no subscription brain for the plan")- model = None- if model is None:- return Plan()prompt = (f"Issue #{issue.number}: {issue.title}\n\n{issue.body[:4_000]}\n\n"f"Project brief:\n{brief_text[:5_000]}")- request = BrainRequest(- messages=(BrainMessage(role="user", content=prompt),),- system=_SYSTEM,- temperature=0.1,- max_tokens=_MAX_TOKENS,- stream=True,- reasoning_effort="low",- )- chunks: list[str] = []try:with attributed(build_id):- async for delta in model.complete(request):- if delta.content:- chunks.append(delta.content)+ answer = await brain.ask(config(), _SYSTEM, prompt, max_tokens=_MAX_TOKENS)+ except BackgroundDeferred: # no subscription or local seat: the agent plans itself+ logger.info("self-build code: no seat for the plan; the coding agent plans")+ return Plan()except Exception: # noqa: BLE001 - a failed plan call leaves planning to the agentlogger.opt(exception=True).info("self-build code: plan call failed")return Plan()- result = parse("".join(chunks))- writer = str(getattr(model, "model", "") or getattr(model, "name", "") or "")- return Plan(text=result.text, size=result.size, writer=writer)+ return parse(answer)diff --git a/dodaios/self_build/code/watch.py b/dodaios/self_build/code/watch.pyindex 998156532e..cabc965355 100644--- a/dodaios/self_build/code/watch.py+++ b/dodaios/self_build/code/watch.py@@ -29,7 +29,7 @@ from loguru import loggerfrom ..ledger import now_msfrom ..records import BuildRecord, Outcome, Statefrom . import brief as brief_mod-from .context import BRANCH_PREFIX, Context, land_repos, parse_signature+from .context import BRANCH_PREFIX, Context, has_pull, land_repos, parse_signaturefrom .github import PullState#: A pull request with no check at all after this long is judged by local tests.@@ -90,7 +90,7 @@ async def _stop_thread(ctx: Context, session_id: str) -> None:async def watch(ctx: Context, record: BuildRecord) -> None:"""One look at the pull request of ``record`` and whatever follows from it."""- if record.artefact.get("type") != "pull_request":+ if not has_pull(record):returnapi = ctx.github()if api is None:diff --git a/tests/unit/self_build/test_self_build_code.py b/tests/unit/self_build/test_self_build_code.pyindex 22c567c24d..c1862123d7 100644--- a/tests/unit/self_build/test_self_build_code.py+++ b/tests/unit/self_build/test_self_build_code.py@@ -249,7 +249,10 @@ def test_issue_becomes_draft_pull_request_proven_by_ci_and_undoable(world: Worldassert pull["base"] == "main"assert pull["body"].startswith("Closes #1")assert "passed in" in pull["body"]- assert record.artefact["type"] == "pull_request"+ # The provenance join key every "built by Dodaios" badge reads.+ assert record.artefact["type"] == "code"+ assert record.artefact["id"] == "https://x/me/proj/pull/100"+ assert record.artefact["repo"] == "me/proj"assert record.artefact["draft"] is Truebranch = record.undo["branch"]assert branch.startswith("dodaios/issue-1-")@@ -758,3 +761,37 @@ def test_thread_runner_stops_at_a_question(monkeypatch: pytest.MonkeyPatch) -> N)assert not result.ok and "question" in result.errorassert chat.cancelled == ["s1"] # the waiting turn is ended, not left open+++def test_plan_call_uses_the_loops_seats_and_is_attributed(monkeypatch: pytest.MonkeyPatch) -> None:+ from dodaios.self_build import brain+ from dodaios.self_build.code import planner++ seen: list[str] = []++ async def answer(system: str, prompt: str, max_tokens: int) -> str:+ from dodaios.costs.ledger import current_caller++ seen.append(current_caller() or "")+ return "SIZE: small\nPLAN:\n- edit calc.py"++ brain.set_override(answer, provider="claude-cli")+ try:+ plan = asyncio.run(planner.plan("b1", make_issue(), "brief", config=lambda: None))+ finally:+ brain.set_override(None)+ assert plan.size == "small" and plan.text == "- edit calc.py"+ assert seen == ["self_build:b1"]+++def test_no_seat_means_no_plan_call(monkeypatch: pytest.MonkeyPatch) -> None:+ from dodaios.brain.background_policy import BackgroundDeferred+ from dodaios.self_build import brain+ from dodaios.self_build.code import planner++ async def refuse(config: Any, system: str, prompt: str, *, max_tokens: int) -> str:+ raise BackgroundDeferred("none")++ monkeypatch.setattr(brain, "ask", refuse)+ plan = asyncio.run(planner.plan("b1", make_issue(), "brief", config=lambda: None))+ assert plan == Plan()