feat(repos): add an "Initialize mise" option to the add-repo step

Some repos an operator wants to manage don't yet define the `.mise.toml`
`[tasks.test]` task the spawn gate hard-requires — a chicken-and-egg,
since you can't run an agent to author that file without it. This adds a
one-click bootstrap.

Ticking "Initialize mise" on the add step enqueues a `mise_init` command
after the clone. The worker launches a dedicated agent that detects the
repo's stack, writes a `.mise.toml` with a canonical `[tasks.test]` task,
and commits + pushes it. That agent runs with the test-task gate off
(creating the task is the point) and a `HANDLER_MISE_INIT` marker on, so
its hooks enforce a bootstrap contract instead of the normal test gate:

- Stop hook blocks the turn until `.mise.toml` defines `[tasks.test]` and
  the change is committed (clean tree) and pushed (no commits ahead of an
  upstream) — so claude cannot end before the work has actually landed.
- git-push hook lets the bootstrap push through, skipping the test/build
  gate (there may be no working suite yet) so the file reaches the remote.

Backend: `mise_init` command type (+ migration 0006), a shared
`control.mise` helper for the test-task check, `spawn(require_tests=,
mise_init=)`, gitops `is_clean`/`ahead_count`, and `init_mise` on the
project-create API (only acts when a git remote exists to push to).
Frontend: the checkbox, plumbed through the store, following the launch.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BxKY28XKCM6o4ag3nmaVsZ
This commit is contained in:
Claude
2026-07-16 18:51:24 +00:00
parent 2ca93a2bc9
commit 072f63bf2d
26 changed files with 540 additions and 23 deletions
+23 -2
View File
@@ -2,15 +2,16 @@
from __future__ import annotations
from handler.control import gitops
from handler.db import repository as repo
from handler.hooks import gate, verify
from handler.hooks.context import HookInput, Identity
def _seed(conn):
def _seed(conn, mise_init=False):
repo.create_project(conn, "p", "/tmp/p")
a = repo.create_agent(conn, "p", "a", "/tmp/p/a")
return Identity(a["id"], "p", "a", "/tmp/p/a")
return Identity(a["id"], "p", "a", "/tmp/p/a", mise_init=mise_init)
def _decision(result):
@@ -73,6 +74,26 @@ def test_git_push_allowed_when_both_pass(conn, monkeypatch):
assert _decision(result) == "allow"
def test_mise_init_push_bypasses_test_gate(conn, monkeypatch):
ident = _seed(conn, mise_init=True)
# The mise-init agent pushes the .mise.toml it just wrote; the test/build gate must
# not run (there may be no working suite yet), and the push is recorded + allowed.
monkeypatch.setattr(
verify, "run_test", lambda cwd: (_ for _ in ()).throw(AssertionError("test gate ran"))
)
monkeypatch.setattr(gitops, "head_sha", lambda cwd: "sha123456789")
hi = HookInput(
{"tool_name": "Bash", "tool_input": {"command": "git push -u origin main"},
"session_id": "s1"},
"pre_tool_use",
)
result = gate.handle_git_push(conn, ident, hi)
assert _decision(result) == "allow"
# The push is recorded in the log so the run shows it landed.
entries = repo.get_log(conn, ident.agent_id, limit=10, offset=0)
assert any(e["push_sha"] == "sha123456789" for e in entries)
def test_non_push_bash_is_ignored(conn):
ident = _seed(conn)
hi = HookInput({"tool_name": "Bash", "tool_input": {"command": "ls -la"}}, "pre_tool_use")