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
feat(git): keep local main a mirror of origin/main (#576)
Ruben Lütkee74327082eb1
diff --git a/.githooks/pre-commit b/.githooks/pre-commitindex 5dc1f015a4..b6df12c055 100755--- a/.githooks/pre-commit+++ b/.githooks/pre-commit@@ -22,6 +22,21 @@ PY="/c/Program Files/Python311/python.exe"[ -x "$PY" ] || PY="$(command -v python3 2>/dev/null || command -v python 2>/dev/null)"[ -n "$PY" ] || exit 0+# --- BRANCH gate (FAIL-CLOSED on a commit on main) ----------------------------+# Local main mirrors origin/main and moves only by fast-forward. A commit made+# on it lives on one machine, and since the merge queue squash-merges, local+# and remote main stop sharing history. rc 1 = HEAD is main; any other rc+# fails OPEN.+branch_gate="scripts/ci/check_commit_branch.py"+if [ -f "$branch_gate" ]; then+ "$PY" "$branch_gate" --quiet </dev/null+ if [ "$?" -eq 1 ]; then+ echo ""+ echo "pre-commit BLOCKED: BRANCH gate — main takes no local commits."+ exit 1+ fi+fi+# --- AGENTS.md is the only rulebook -------------------------------------------check="scripts/ci/check_agents_md.py"if [ -f "$check" ]; thendiff --git a/AGENTS.md b/AGENTS.mdindex 0177d643cf..f3af2f2ed9 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -27,9 +27,17 @@ These cost real bugs. Nothing catches them but you.then `python -c "import jarvis; print(jarvis.__file__)"`. (AP-8) Never`pip install -e` from a linked worktree: that pin is the user's desktop app,and their next restart boots your branch with an empty `data/`. (BUG-219)-- **The working tree is SHARED** with other agent sessions. Stage only YOUR- paths — `git add -p` or an explicit pathspec, and `git commit --only -- <paths>`.- `git add -A` sweeps someone else's half-finished work into your commit.+- **`main` takes no local commits.** Local `main` mirrors `origin/main` and+ moves only by `git pull --ff-only`; the commit hook refuses a commit on it.+ Every change lives on a feature branch in a worktree of your own:+ `git worktree add -b <agent>/<topic> <path> origin/main`, one topic per+ branch. A commit on local `main` exists on one machine, and the squash-merging+ queue makes it diverge from the remote for good.+- **The main checkout is SHARED** with other agent sessions and runs the user's+ desktop app. Never switch its branch, reset it or stash in it. Wherever a+ tree is shared, stage only YOUR paths — `git add -p` or an explicit pathspec,+ and `git commit --only -- <paths>`. `git add -A` sweeps someone else's+ half-finished work into your commit.- **A probe against the running app spends the user's real money.** Turns sentto it (`/ws`, `jarvis` CLI, Telegram) bill their own keys: five scriptedtest turns once cost $6.82 on a deep model. Send one turn, on a subscription@@ -192,8 +200,9 @@ standard Git workflow: do not artificially leave completed work local, and donot wait for extra Dodaios permission to commit, branch, push, or opena pull request. Once the scoped review and required checks pass, the agent maymerge an ordinary authorized PR without another confirmation; a draft PR stays-draft until its remaining work is done. `git pull --rebase --ff-only` first if-origin moved. Never+draft until its remaining work is done. Cut each branch from a freshly fetched+`origin/main`; once its PR has merged, fast-forward the main checkout+(`git pull --ff-only`) so the desktop app runs the landed code. Never`--force`, never `--no-verify`. Isolated mission workers must not run git(`add`/`commit`/`branch`/`checkout`/`push`) — the parent runtime captures thediff and lands it. Never push from a linked mission worktree. **A push isdiff --git a/docs/ci-pipeline.md b/docs/ci-pipeline.mdindex 01fea62ea0..745e3f0054 100644--- a/docs/ci-pipeline.md+++ b/docs/ci-pipeline.md@@ -255,9 +255,15 @@ An agent in its own worktree runs one command when its work is done:```bashpython scripts/agent_land.py # feature branch -> PR labelled auto-merge-python scripts/agent_land.py --direct # fast-forward main itself+python scripts/agent_land.py --direct # admin only: fast-forward main itself```+Local `main` is a mirror of `origin/main`: the commit hook+(`scripts/ci/check_commit_branch.py`) refuses a commit on it, and the script+refuses to land from it. Work starts on a branch cut from `origin/main`+(`git worktree add -b <agent>/<topic> <path> origin/main`) and the main+checkout follows with `git pull --ff-only` once the pull request has merged.+It rebases onto the latest main with the same conflict engine, runs thestatic gates, runs the tests the diff can reach, pushes, and asks GitHub toqueue the pull request once it is green. It refuses a dirty worktree anddiff --git a/scripts/agent_land.py b/scripts/agent_land.pyindex 3349829c2a..c427ca6b0d 100644--- a/scripts/agent_land.py+++ b/scripts/agent_land.py@@ -5,7 +5,7 @@ One command for every agent (Claude Code, Codex, Gemini CLI, ...) working inits own worktree or clone::python scripts/agent_land.py # on a feature branch -> PR, auto-merge- python scripts/agent_land.py --direct # fast-forward main itself+ python scripts/agent_land.py --direct # admin only: fast-forward main itselfWhat it does, in order — and it stops at the first real problem:@@ -99,7 +99,11 @@ def main(argv: list[str] | None = None) -> int:parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])parser.add_argument("--remote", default="origin")parser.add_argument("--direct", action="store_true", help="Push straight to main.")- parser.add_argument("--pr", action="store_true", help="Push the branch and open a PR.")+ parser.add_argument(+ "--pr",+ action="store_true",+ help="Accepted for compatibility: a feature branch always lands through a PR.",+ )parser.add_argument("--skip-tests", action="store_true")parser.add_argument("--skip-gates", action="store_true")parser.add_argument("--no-push", action="store_true", help="Check only.")@@ -114,7 +118,12 @@ def main(argv: list[str] | None = None) -> int:stream.reconfigure(encoding="utf-8", errors="replace")branch = run(["git", "rev-parse", "--abbrev-ref", "HEAD"], check=True).stdout.strip()- direct = args.direct or (branch == "main" and not args.pr)+ if branch == "main" and not args.direct:+ print("Refusing to land from main: local main mirrors origin/main and takes no commits.")+ print("Work on a feature branch in your own worktree:")+ print(" git worktree add -b <agent>/<topic> <path> origin/main")+ return 2+ direct = args.directdirty = run(["git", "status", "--porcelain", "--untracked-files=no"]).stdout.strip()if dirty:print("Refusing to land: the worktree has uncommitted changes to tracked files.")diff --git a/scripts/ci/check_commit_branch.py b/scripts/ci/check_commit_branch.pynew file mode 100644index 0000000000..24211919ac--- /dev/null+++ b/scripts/ci/check_commit_branch.py@@ -0,0 +1,77 @@+#!/usr/bin/env python3+"""Refuse a local commit on ``main``.++Local ``main`` is a mirror of ``origin/main``: it moves only by fast-forward+(``git pull --ff-only``). Work is committed on a feature branch and reaches+``main`` through its pull request and the merge queue. A commit made on local+``main`` exists on one machine only, and because the queue squash-merges, the+two histories stop sharing commits: within days local ``main`` is both ahead of+and behind the remote, and every later landing has to untangle that first.++This gate fails when ``HEAD`` is the ``main`` branch. A detached ``HEAD`` and+every other branch pass. CI runners are left alone: the workflows that write to+``main`` do it through their own reviewed path.++Used from ``.githooks/pre-commit``.++stdlib-only.+"""++from __future__ import annotations++import argparse+import os+import subprocess+import sys++PROTECTED_BRANCHES = frozenset({"main"})++# Exit codes: 0 = commit allowed, 1 = commit on a protected branch.+EXIT_OK = 0+EXIT_PROTECTED = 1+++def _current_branch() -> str | None:+ """Return the checked-out branch, or None on a detached HEAD or outside git."""+ proc = subprocess.run(+ ["git", "symbolic-ref", "--quiet", "--short", "HEAD"],+ capture_output=True,+ text=True,+ )+ if proc.returncode != 0:+ return None+ return proc.stdout.strip() or None+++def main(argv: list[str] | None = None) -> int:+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument(+ "--quiet",+ action="store_true",+ help="print nothing on the success path.",+ )+ args = parser.parse_args(argv)++ if os.environ.get("GITHUB_ACTIONS") == "true":+ return EXIT_OK++ branch = _current_branch()+ if branch not in PROTECTED_BRANCHES:+ if not args.quiet:+ print(f"check_commit_branch: commits are allowed on {branch or 'a detached HEAD'}.")+ return EXIT_OK++ sys.stderr.write(+ f"check_commit_branch: '{branch}' mirrors origin/{branch} and takes no local commits.\n"+ "Put the change on a feature branch in a worktree of your own:\n"+ f" git worktree add -b <agent>/<topic> <path> origin/{branch}\n"+ "Your uncommitted edits stay where they are; carry your own paths over with\n"+ " git diff HEAD -- <paths> | git -C <path> apply --3way\n"+ "and land the branch with: python scripts/agent_land.py\n"+ "In a clone nobody else uses, `git switch -c <topic>` does the same in place.\n"+ )+ return EXIT_PROTECTED+++if __name__ == "__main__":+ raise SystemExit(main())diff --git a/tests/unit/ci/test_check_commit_branch.py b/tests/unit/ci/test_check_commit_branch.pynew file mode 100644index 0000000000..6757cf6064--- /dev/null+++ b/tests/unit/ci/test_check_commit_branch.py@@ -0,0 +1,60 @@+"""Local ``main`` mirrors the remote: the commit hook refuses a commit on it."""++from __future__ import annotations++import subprocess+from pathlib import Path++import pytest++from scripts.ci import check_commit_branch+++def _git(repo: Path, *args: str) -> None:+ subprocess.run(["git", "-C", str(repo), *args], check=True, capture_output=True)+++def repo(tmp_path: Path, monkeypatch) -> Path:+ _git(tmp_path, "init", "-q", "-b", "main")+ _git(tmp_path, "config", "user.email", "[email protected]")+ _git(tmp_path, "config", "user.name", "Test")+ _git(tmp_path, "config", "commit.gpgsign", "false")+ (tmp_path / "file.txt").write_text("one\n", encoding="utf-8")+ _git(tmp_path, "add", "--", "file.txt")+ _git(tmp_path, "commit", "-q", "--no-verify", "-m", "chore: seed")+ monkeypatch.chdir(tmp_path)+ monkeypatch.delenv("GITHUB_ACTIONS", raising=False)+ return tmp_path+++def test_commit_on_main_is_refused(repo, capsys):+ assert check_commit_branch.main(["--quiet"]) == check_commit_branch.EXIT_PROTECTED++ err = capsys.readouterr().err+ assert "git worktree add -b" in err+ assert "origin/main" in err+++def test_feature_branch_is_allowed(repo):+ _git(repo, "switch", "-q", "-c", "claude/some-topic")++ assert check_commit_branch.main(["--quiet"]) == check_commit_branch.EXIT_OK+++def test_branch_that_only_starts_with_main_is_allowed(repo):+ _git(repo, "switch", "-q", "-c", "main-mirror-rule")++ assert check_commit_branch.main(["--quiet"]) == check_commit_branch.EXIT_OK+++def test_detached_head_is_allowed(repo):+ _git(repo, "checkout", "-q", "--detach", "HEAD")++ assert check_commit_branch.main(["--quiet"]) == check_commit_branch.EXIT_OK+++def test_ci_runner_is_left_alone(repo, monkeypatch):+ monkeypatch.setenv("GITHUB_ACTIONS", "true")++ assert check_commit_branch.main(["--quiet"]) == check_commit_branch.EXIT_OK