From 22a6b66f55bc2b800a1fc9fb145a0ece5445bac8 Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Tue, 20 Oct 2026 17:43:45 +0000 Subject: [PATCH] A project stop survives a fresh clone: run.stopped/run.resumed are mission ledger rows (M10.4) With a mission ledger, `aloop stop` and `aloop stop --clear` also append hash-chained ledger rows, and the stop flag reader falls back to the ledger's newest stop row, so a clone (another machine, a scheduled run) is refused by the hooks and answered STOPPED by mission tick until the human clears it there. project-stop.test.py check 8 (red on master). Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_015QxyVf3NgwsgRyYpBgDDTC --- README.md | 5 +++-- docs/ROADMAP.md | 2 +- plugin/bin/_mission.py | 6 +++--- plugin/bin/_stop.py | 28 +++++++++++++++++++++++-- plugin/bin/stop | 32 ++++++++++++++++++++++++++--- plugin/mission/README.md | 1 + scripts/test/project-stop.test.py | 34 +++++++++++++++++++++++++++++++ 7 files changed, 97 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 8a751d23..059952ec 100644 --- a/README.md +++ b/README.md @@ -177,8 +177,9 @@ approval of that exact content: `aloop mission approve` records only when a prom first 8 hex of the content's sha256, so an agent cannot approve its own change (M9.17). The records the gates decide from (approvals, measurements, assessments, retirements, goals) are rows in a hash-chained, committed ledger, so an edited or backdated row, or one removed before the newest, -fails the check. The ethics verdicts, the `tick --force` grant and `mission.budget_exhausted` are -still run-log events, and a removed newest row is caught only where the run log survives (M9.24). The confirmed definition of "best" is the +fails the check. The ethics verdicts, the `tick --force` grant, `mission.budget_exhausted` and the +project's stop (`aloop stop`) are ledger rows too, so a clone decides the same; a removed newest row is +caught only where the run log survives (M9.24, M10.4). The confirmed definition of "best" is the mission's RED: a baseline whose journeys all pass already is refused. Usage telemetry (GA4, opt-in) informs goals and is never a gate. diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 717c5178..88141462 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -30,7 +30,7 @@ original plan. | **M7 — Any host** | v0.18 | Session 9: `HostAdapter`, capability matrix, `.aladdin/config.yaml`, host swap, metrics (§4.9–4.10) | done: `HostAdapter` + `host check` in CI, capability matrix, usage accuracy, `.aladdin/config.yaml` with migration, `host swap`, the full metrics table incl. context-window share (tests: `host-adapter`, `portable-config`, `host-swap`, `metrics`); DeepSeek Harness (`dsh`) as a fourth host, tested on its real runtime (tests: `dsh-plugin`, `dsh-runtime`); a measured live dsh run is open (needs a DeepSeek key) | | **M8 — Aladdin 1.0** | v1.0 | Session 10: `/aladdin` + `aladdin` CLI with aliases, site, measured public runs (§4.11). The rename to aloop shipped early in v0.11.0 | in progress: `bin/aladdin` + `/aladdin` with `aloop`/`agentic` aliases (test: `aladdin-cli.test.py`); natural-language auto-trigger on every host (`intent-trigger`, test: `intent-trigger.test.py`); README reordered product-first; site at `docs/index.html` (Pages switch is the owner's). evidence ledger `docs/evidence/README.md` + `run-summary` (test: `evidence.test.py`). `e2e-live.sh --host codex|opencode` runs the same loop on those hosts (`aloop install ` into the run repo, then `codex exec --json` / `opencode run --format json`; `--dry-run` prints the command; test: `e2e-live-hosts.test.py`). Open: the measured public runs themselves (this environment has no `codex`/`opencode` CLI: run `make e2e-live YES=1 HOST=codex` and `HOST=opencode` on a machine with both and add the rows; reason: a number we cannot measure is not published) Mac release run (2026-10-19) found two bugs Linux CI never sees, both fixed with tests: `stats sprint-close` counted 0 attempts when the project sat behind a symlink (macOS `/var` → `/private/var`; paths are now compared by realpath), and `make conformance` hung when another aloop checkout's `plugin/bin` was ahead on PATH (`ensure-tools --resolve` returned that checkout's shim; any aloop bin dir is now skipped). RED is now verified on any language: a non-cargo repo runs its `standards.md` matrix's test command, and a RED whose tests pass or do not collect is blocked (pytest, `go test`; test: `any-language.test.py`). Reason: the north star is any intent, and RED was dynamically checked only for Rust. GREEN and the final gate now refuse Python/Go/JS skips, and the final gate finds a planned `def`/`func` test (before, it found only `fn`, so every planned Python test blocked). `INTENT=slugify` is the Python fixture. Run 36 (slugify, the first Python run): 11/12, 11m37s, $0.83, 5 wakes, 0 plugin-source reads, 15 blocks (9 caught by self-checks). The sprint merged a correct `slugify` with 13 passing tests and the final gate passed. The one failed check was the fixture's own: bare `pytest` leaves the repo root off `sys.path` (now `python3 -m pytest`). It found two gate bugs that Rust runs had hidden. First, a worker's worktree has no `docs/agents/` (git-ignored), so the gates never found `standards.md` and ran the default Rust matrix: RED blocked 4 times on `cargo fmt`, and in a Rust project a custom matrix was silently swapped for the default. Second, `ctx-symbols conflicts` walked the merged task checkout under `.aladdin/worktrees/` and reported `slugify` as a HIGH duplicate, so the structural reviewer was rejected 4 times. Fixed with tests: the gates read the story's sprint `standards.md` (else this tree, else the main tree), and a non-cargo project with no matrix blocks with a message naming `standards.md`; ctx-symbols skips `.aladdin/`. Run 37 on these fixes: 12/12, 9m42s, $0.69, 1 wake, 11 blocks (7 caught by self-checks). It found that a `standards.md` whose matrix is a table parses empty, so RED blocked 3 times; `gate-standards-cited` now refuses a standards.md with no runnable `## Gate matrix` block (test: `any-language.test.py`). Run 38 (`INTENT=roman`, the first Go run): 12/12, 14m15s, $1.02, 3 wakes, 9 blocks (7 caught by self-checks). It found that the sprint dir's `init.md` had no `type: init` header (the supervisor began it with a dispatch block), so the structural reviewer was blocked 7 times; `aloop budget contract` now writes that header (test: `budget-contract.test.py`). Run 39 on the fix: 12/12, 7m52s, $0.56, 0 init.md blocks. It found that GREEN's default scope let it touch Rust test files only, so a Go GREEN removing RED's `_test.go` shim was blocked 10 times; GREEN now shares RED's any-language test globs (test: `any-language.test.py`). Run 40 on it: 12/12, 13m03s, $0.75, 1 wake, 0 GREEN scope blocks (5 blocks, all caught by self-checks). The structural reviewer's HIGH foundation-poisoning finding in runs 38 and 40 was a false positive: a worker's `selfcheck` resolved a stale 0.11.0 `ctx-symbols` (before the `.aladdin/` exclusion) ahead of the session's current build; `ensure-tools --resolve` now skips a stale own build (test: `ensure-tools.test.py`). RED is verified on JS too (a test file that cannot load what it imports is blocked; test: `any-language.test.py`), and `INTENT=camel` is the JS fixture. Run 41 (camel, the first JS run): 12/12, 6m45s, $0.56, 1 wake, 2 blocks (both RED self-checks refusing a source edit). The loop is now measured on Rust, Python, Go and JS. Run 42 (`INTENT=extend`, the first brownfield intent: add `compare` to a crate whose `parse` already works and is tested): 13/13, 7m11s, $0.67, 2 blocks (both self-check catches); the seed's code and tests were left unchanged and still pass (reason: every earlier fixture started from an empty library, and most real intents land on existing code). Run 43 (`INTENT=modify`: change that existing `parse` to accept a leading `v` and trim whitespace): 13/13, 9m10s, $0.67, 6 blocks, all self-check catches; the change was 3 lines in `parse`, with its signature and seed tests kept. `INTENT=cli` (an application: a wc-like binary tested by running it, checked by running the merged binary) is ready; run 44 (the retry after the usage limit lifted): 13/13, 24m55s, $1.54, 6 blocks (all self-check catches), and the merged binary works. Its cost came from planning: 2 stories and 7 tasks for a small tool, so 7 RED/SCAFFOLD/GREEN cycles and 56 supervisor turns (runs 42–43: 1–2 tasks, 16–30 turns). The planner now sizes tasks up to the budget instead of one per behaviour (reason: per-task cost is a fixed ~8 supervisor turns). Run 45 on it: 3 tasks (from 7), 13/13, 16m22s, $1.07. Its HIGH foundation-poisoning halts were `ctx-symbols` reading a test's `const USAGE` as a duplicate of the binary's; a test constant no longer counts (test: `conflicts.rs`). Run 46 on both fixes: 3 tasks, 13/13, 15m19s, $0.99, no review halt, 6/6 blocks self-check catches. Its 4 `targets` "symbol is not defined" blocks were T3 modifying symbols T2 plans in an existing file; a symbol another target plans now counts (test: `semantic-targets.test.py` case 8). Run 47 on it: 13/13, $1.04, 2 blocks (from 6), no "not defined"; but 5 tasks in 2 stories, so planner task count still varies. The spread is now bounded: before execution, `targets check` refuses two adjacent tasks of one story on the same files with 8 or fewer tests between them (replayed on past plans it would have merged runs 23, 40, 43, 44 and 47 and passed every other; test: `semantic-targets.test.py` case 9). Run 48 on it: 2 tasks, 13/13, $0.76, 25 supervisor turns (run 44: 7 tasks, $1.54, 56). One GREEN self-check block in each of runs 46–48 was a false positive: the Rust suppression grep matched an iterator's `args().skip(1)` (a JS pattern); Rust now checks only `#[ignore]` (also with a reason, which it used to miss) and `cfg(not(test))` (test: `suppression-contract.test.py`). Planner friction next: across runs 36–41 the most frequent block was `targets` "create needs planned_symbol" on a new test file (8); a test-file create now takes it from the task's `tests` (test: `semantic-targets.test.py`). The `gate-validate-artifact` plan.md refusals (4) were the persona's bare `stage: 1`, now quoted and checked (test: `persona-shapes.test.py`). Next: the final-gate block order (3). Running every suite under a locally built bash 3.2 found that the `standards.md` gate matrix was silently replaced by the default Rust matrix (`mapfile` does not exist in bash 3.2). It is fixed and guarded by `bash-portable.test.py`. A `macos` CI job now runs the host tests and the conformance fixtures on macOS (reason: both were found only by hand on the owner's Mac). | | **M9 — Mission layer** | v0.13 | The "Missionary Aladdin Genie" spec (2026-10-17): a human-set mission above goals; fixed roles (research, product testing, state, evaluation, planning, ethics) build a confirmed baseline and a reproducible evaluation layer from user journeys; goals derived from the gap list become Aladdin intents; re-evaluate on a cadence and after each sprint; GA4 usage informs goals and is never a gate; every element has a deterministic check (§4.12). Reason: the owner's mission-driven loop, stacked on Aladdin | in progress: M9.0 core (`aloop mission init / check / approve / status`, sealed mission + approval events, area discovery, test glob; test: `mission-core.test.py`); M9.2 baseline, M9.3 journeys and M9.10 assess/evaluate (`mission-{baseline,journeys,evaluate}.test.py`). Open tracks: M9.1, M9.4–M9.9; the task graph is in §4.12, track notes in `plugin/mission/README.md`; hardened after an adversarial review (ledger records over status fields) | -| **M10 — Agent habitat** | v1.1 | Containment around the gates (§4.13): contained workers, a security and supply-chain gate, fetched content treated as data, one stop for a whole project. Reason: a 2026-10-20 comparison with Replit's "agent habitat" (orchestration, error recovery, safety and sandboxing, networking, identity) found aloop strong on orchestration, recovery and gates but missing containment | in progress: M10.2 dependency and secret halves done: GREEN refuses a dependency added to a manifest (Cargo.toml, package.json, requirements*.txt, pyproject.toml, go.mod) that the approved plan does not name (`bin/deps`), and a credential (private key, fixed-prefix token) in the lines it adds; `gate-final` refuses one anywhere in the project (`bin/secrets`, built in rather than a matrix line so it runs on every stack with no install; test: `supply-chain.test.py`); live run 51: no refusal, 13/13, $0.94). Next: M10.2 dependency audit (`cargo audit`, `npm audit`, `pip-audit`, `govulncheck`) in the final gate's matrix, which needs the standards role to write it and the tool on the host; M10.4 done: `aloop stop [REASON]` stops every agent of the project at its next tool call on every host (the check sits in `budget hook pre`), `mission tick` answers STOPPED, and only the human's own terminal clears it (`stop --clear`; events `run.stopped`/`run.resumed`; test: `project-stop.test.py`). `--clear` refuses the agent shells of all four hosts (`CLAUDECODE`, `DSH_SHELL`, `CODEX_THREAD_ID`, and `ALOOP_AGENT_SHELL` once M9.31 makes the OpenCode plugin export it). Next for M10.4: a row in the committed mission ledger so a clone stays stopped; M10.1 and M10.3 planned; plan approval as a gate is M0.9 | +| **M10 — Agent habitat** | v1.1 | Containment around the gates (§4.13): contained workers, a security and supply-chain gate, fetched content treated as data, one stop for a whole project. Reason: a 2026-10-20 comparison with Replit's "agent habitat" (orchestration, error recovery, safety and sandboxing, networking, identity) found aloop strong on orchestration, recovery and gates but missing containment | in progress: M10.2 dependency and secret halves done: GREEN refuses a dependency added to a manifest (Cargo.toml, package.json, requirements*.txt, pyproject.toml, go.mod) that the approved plan does not name (`bin/deps`), and a credential (private key, fixed-prefix token) in the lines it adds; `gate-final` refuses one anywhere in the project (`bin/secrets`, built in rather than a matrix line so it runs on every stack with no install; test: `supply-chain.test.py`); live run 51: no refusal, 13/13, $0.94). Next: M10.2 dependency audit (`cargo audit`, `npm audit`, `pip-audit`, `govulncheck`) in the final gate's matrix, which needs the standards role to write it and the tool on the host; M10.4 done: `aloop stop [REASON]` stops every agent of the project at its next tool call on every host (the check sits in `budget hook pre`), `mission tick` answers STOPPED, and only the human's own terminal clears it (`stop --clear`; events `run.stopped`/`run.resumed`; test: `project-stop.test.py`). `--clear` refuses the agent shells of all four hosts (`CLAUDECODE`, `DSH_SHELL`, `CODEX_THREAD_ID`, and `ALOOP_AGENT_SHELL` once M9.31 makes the OpenCode plugin export it). With a mission ledger the stop and its clear are ledger rows too (`run.stopped`, `run.resumed`), so a fresh clone stays stopped (hooks and `tick`) until the human clears it there (`project-stop.test.py` check 8); M10.1 and M10.3 planned; plan approval as a gate is M0.9 | **Order rationale:** identity and conformance fixtures first, so every later change is measured against today's behaviour; budgets and handoff next, because they shape every run; diff --git a/plugin/bin/_mission.py b/plugin/bin/_mission.py index 0a57c877..555acda5 100644 --- a/plugin/bin/_mission.py +++ b/plugin/bin/_mission.py @@ -243,11 +243,11 @@ def emit(cwd, event, role="", refs=None, event_id=None, **data): HUMAN_EVENTS = tuple(APPROVAL_EVENTS) + ("baseline.vetoed", "telemetry.revoked", "door.authorized", "door.revoked") # every record a mission gate decides from: the human decisions, plus what the harness measured, # assessed, evaluated (a clone trusts the same gap lists), retired (a journey, a goal), reviewed (a hard ethics line stays -# blocked on a fresh checkout), derived, the loop's own stop at a spend cap (a clone stays stopped) -# and the one-way doors crossed under a once-authorization (M9.30) +# blocked on a fresh checkout), derived, the loop's own stop at a spend cap (a clone stays stopped), +# the one-way doors crossed under a once-authorization (M9.30) and the project's stop and resume (M10.4) LEDGER_EVENTS = HUMAN_EVENTS + ("baseline.measured", "state.assessed", "eval.completed", "journey.retired", "ethics.reviewed", "ethics.blocked", "goal.derived", "goal.met", "goal.retired", - "mission.budget_exhausted", "door.crossed") + "mission.budget_exhausted", "door.crossed", "run.stopped", "run.resumed") def ledger(cwd=None): diff --git a/plugin/bin/_stop.py b/plugin/bin/_stop.py index 2a263eae..357684d2 100644 --- a/plugin/bin/_stop.py +++ b/plugin/bin/_stop.py @@ -2,6 +2,10 @@ `aloop stop` sets it; `budget hook pre` (run on every tool call by all four hosts) refuses every acting call while it is set; `mission tick` answers STOPPED. Only the human clears it. + +The flag is run data (git-ignored), so in a project with a mission ledger the stop and its clear are +also ledger rows (`run.stopped`, `run.resumed`): a fresh clone (another machine, a scheduled run) is +stopped while the ledger's newest of the two is a stop, like the budget stop (M9.24). """ import json import os @@ -17,13 +21,33 @@ def path(cwd=None): return os.path.join(_paths.home(cwd, "state", make=False), "STOP") +def ledger_stop(cwd=None): + """The ledger's newest stop row as a stop record when no resume row follows it, else None. Only + the intact rows count; the ledger is read only when it names a stop (this runs on every tool call).""" + import _mission + try: + with open(_mission.ledger(cwd), encoding="utf-8") as f: + if '"run.stopped"' not in f.read(): + return None + except OSError: + return None + last = None + for row in _mission.ledger_rows(cwd)[0]: + if row["event"] in ("run.stopped", "run.resumed"): + last = row + if not last or last["event"] != "run.stopped": + return None + return {"at": last["ts"], "reason": last["data"].get("reason", ""), "by": last.get("role", ""), "ledger": True} + + def read(cwd=None): - """The stop record, or None when the project runs. A flag that is not JSON is still a stop.""" + """The stop record, or None when the project runs. A flag that is not JSON is still a stop, and + with no flag the mission ledger's stop row holds (a clone).""" try: with open(path(cwd)) as f: raw = f.read() except OSError: - return None + return ledger_stop(cwd) try: rec = json.loads(raw) return rec if isinstance(rec, dict) else {"reason": raw.strip()} diff --git a/plugin/bin/stop b/plugin/bin/stop index b623f811..383ca10f 100755 --- a/plugin/bin/stop +++ b/plugin/bin/stop @@ -8,6 +8,9 @@ aloop stop --status exit 0 running, 3 stopped (with the reason) aloop stop --clear resume. Only the human, from their own terminal: a shell an agent host runs is refused. Records run.resumed. + +With a mission ledger (docs/agents/mission/ledger.jsonl) both records are ledger rows too, so a +fresh clone stays stopped until the human clears it there. """ import json import os @@ -17,6 +20,7 @@ import time sys.dont_write_bytecode = True sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) import _events # noqa: E402 +import _mission # noqa: E402 import _paths # noqa: E402 import _stop # noqa: E402 @@ -30,6 +34,22 @@ def now(): return time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()) +def record(cwd, event, role, **data): + """The stop or resume as a mission ledger row when the project has a ledger (its event comes with + it), else as an event. A broken ledger takes no row: say so (BLOCK) and return False.""" + if not os.path.exists(_mission.ledger(cwd)): + _events.emit(cwd, event, role=role, **data) + return True + try: + _mission.record(cwd, event, "project", role, **data) + return True + except _mission.LedgerBroken as e: + print("BLOCK[stop]: the mission ledger is broken (%s), so it cannot record %s: restore it " + "(git checkout -- %s) and run this again" % (e, event, _mission.rel(cwd, _mission.ledger(cwd))), + file=sys.stderr) + return False + + def main(argv): cwd = os.getcwd() rec = _stop.read(cwd) @@ -52,8 +72,14 @@ def main(argv): if not rec: print("running (nothing to clear)") return 0 - os.remove(_stop.path(cwd)) - _events.emit(cwd, "run.resumed", role="human", stopped_at=rec.get("at"), reason=rec.get("reason")) + info = dict(stopped_at=rec.get("at"), reason=rec.get("reason")) + if _stop.ledger_stop(cwd): # the ledger's stop holds every clone: clear it there too + if not record(cwd, "run.resumed", "human", **info): + return 2 + else: + _events.emit(cwd, "run.resumed", role="human", **info) + if os.path.exists(_stop.path(cwd)): + os.remove(_stop.path(cwd)) print("running: the stop of %s is cleared" % (rec.get("at") or "?")) return 0 if argv[:1] and argv[0].startswith("-"): @@ -69,7 +95,7 @@ def main(argv): _paths.home(cwd) # writes .aladdin/.gitignore if missing with open(_stop.path(cwd), "w") as f: json.dump(rec, f) - _events.emit(cwd, "run.stopped", role=by, reason=reason) + record(cwd, "run.stopped", by, reason=reason) # the flag holds here even when the ledger cannot print("stopped: every agent of %s is refused from its next tool call; `aloop stop --clear` in your " "own terminal resumes" % _paths.project(cwd)) return 0 diff --git a/plugin/mission/README.md b/plugin/mission/README.md index 2f5b8199..1f944fae 100644 --- a/plugin/mission/README.md +++ b/plugin/mission/README.md @@ -189,6 +189,7 @@ loop to move on records them: | a state report or eval | its `baseline_id` (another than the current one: re-assess, re-evaluate) and the eval's boolean `goal_met` | | a goal's progress | a goal is one a `goal.derived` (or `goal.approved`) ledger row covers at its content, closed by its `goal.met` row or set aside by its `goal.retired` row (M9.50: `goal retire`, once every intent was sprinted and its sprints closed, and the newest eval of it, from a state measured after the closes, still lists gaps; its open gaps are then held from `derive` on that baseline until a new version or the human's next approval of the mission); status `derived` → `approved` → `active` (`goal intents` handed it to Aladdin) · `retired` · `blocked`; an eval narrowed to it (`goal_id`) decides its close or retirement | | a stop at a spend cap | a `mission.budget_exhausted` ledger row (role mission-loop) for the mission's content, written once by the first `STOP_BUDGET` tick (M9.24): a clone stays stopped until a raised cap changes the content | +| the project stopped | `aloop stop`'s flag (run data), and with a ledger a `run.stopped` row with no `run.resumed` row after it (M10.4): `tick` answers STOPPED first, on a clone too | | a lifted block | a `mission.lifted` ledger row (role human, `--by`, the human's typed `lift ` line) whose code digests `{mission_id, block, lift, occurrence}`: the block's key, how many lifts of it the ledger has, and which block it was (the handout tick that tripped a repeat; the newest of 3 failed goals, which is how far that reset reaches); `tick --force` records it (M9.51). A repeat restarts at the row's own run-log event (its first copy only); the 3-failed-goals count at its `occurrence` | | a goal's sprints | `intent.received` {goal_id, intent_id} → `plan.created` {sprint: "S", intent_id}; with no linked intent, the sprints planned since the loop handed out its `SPRINT`. Closes: `.aladdin/state/sprints.json`; `plan.approved` (spoon-fed) | diff --git a/scripts/test/project-stop.test.py b/scripts/test/project-stop.test.py index 1803b6f3..44abd38c 100644 --- a/scripts/test/project-stop.test.py +++ b/scripts/test/project-stop.test.py @@ -134,4 +134,38 @@ def denied(out): assert r.returncode != 0, (name, r) ok("events emit refuses run.stopped and run.resumed") +# 8) with a mission, the stop is a committed ledger row too: a fresh clone (another machine, a scheduled +# run) stays stopped until the human clears it there, and that clear is a ledger row as well +LEDGER = os.path.join(REPO, "docs", "agents", "mission", "ledger.jsonl") +os.makedirs(os.path.dirname(LEDGER)) +open(LEDGER, "w").close() +sh("git", "add", "-A") +sh("git", "commit", "-qm", "mission ledger") +assert run(STOP, "the scheduled run is burning money").returncode == 0 +rows = [json.loads(ln) for ln in open(LEDGER)] +assert [r["event"] for r in rows] == ["run.stopped"] and rows[0]["data"]["reason"] == "the scheduled run is burning money", rows +assert len(events("run.stopped")) == 2, events("run.stopped") # one event per stop, not two +sh("git", "add", "-A") +sh("git", "commit", "-qm", "stop") +CLONE = os.path.join(T, "clone") +sh("git", "clone", "-q", REPO, CLONE, cwd=T) +assert not os.path.exists(os.path.join(CLONE, ".aladdin", "state", "STOP")) +r = run(STOP, "--status", cwd=CLONE) +assert r.returncode == 3 and "burning money" in r.stdout, r +assert denied(hook("pre", "Bash", CLONE, **SUPERVISOR)) and denied(hook("pre", "Write", CLONE, **WORKER)) +r = run(os.path.join(BIN, "mission"), "tick", "--json", "--peek", cwd=CLONE) +assert json.loads(r.stdout)["action"] == "STOPPED", r.stdout +r = run(STOP, "--clear", cwd=CLONE, env=dict(ENV, CLAUDECODE="1")) +assert r.returncode == 2 and run(STOP, "--status", cwd=CLONE).returncode == 3, r +r = run(STOP, "--clear", cwd=CLONE) +assert r.returncode == 0 and run(STOP, "--status", cwd=CLONE).returncode == 0, r +crows = [json.loads(ln) for ln in open(os.path.join(CLONE, "docs", "agents", "mission", "ledger.jsonl"))] +assert [x["event"] for x in crows] == ["run.stopped", "run.resumed"] and crows[1]["role"] == "human", crows +assert not denied(hook("pre", "Bash", CLONE, **SUPERVISOR)) +# the original checkout still holds its own stop until the human clears it there, with one resume row +assert run(STOP, "--status").returncode == 3 +assert run(STOP, "--clear").returncode == 0 and run(STOP, "--status").returncode == 0 +assert [json.loads(ln)["event"] for ln in open(LEDGER)] == ["run.stopped", "run.resumed"] +ok("with a mission the stop is a committed ledger row: a fresh clone stays stopped (hooks, tick) until the human clears it there") + print("\n%d checks passed" % n[0])