From 3539129945f3b075e4fce2544f8400a4a93065f1 Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Tue, 20 Oct 2026 05:43:35 +0000 Subject: [PATCH 1/2] Mission loop end to end offline (M9.13); a baseline binds the direction (M9.25); ethics rows in the ledger (M9.24) - mission-e2e.test.py drives `mission tick` from a new mission through research, a journey, a confirmed baseline, a gap list, a goal, its intents and one sprint per intent to GOAL MET and RESEARCH, with zero tokens. - A baseline and its state carry direction_sha256 = M.direction(mission), so a new budget, deadline or cadence keeps the confirmed baseline. - ethics.reviewed/ethics.blocked are ledger rows; M.history reads the ledger first (a run-log copy of a row is ignored) and a broken ledger makes every ethics verdict broken. - The mission skill relays the human's grant line and the command the ASK names after "then". - ROADMAP M9.43: a goal should bind the direction too. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_018RxETAY6S1gcmdctBK8a8Z --- CHANGELOG.md | 2 + docs/ROADMAP.md | 7 +- docs/TRACKING.md | 5 +- plugin/bin/_mission.py | 18 +++ plugin/bin/mission | 4 + plugin/mission/README.md | 7 + plugin/mission/assess.py | 2 +- plugin/mission/baseline.py | 31 +++-- plugin/mission/ethics.py | 28 ++-- plugin/mission/schemas/baseline.json | 4 +- plugin/mission/schemas/state.json | 4 +- plugin/skills/mission/SKILL.md | 4 + scripts/test/mission-baseline.test.py | 22 ++- scripts/test/mission-e2e.test.py | 184 ++++++++++++++++++++++++++ scripts/test/mission-ethics.test.py | 56 ++++++++ scripts/test/mission-skill.test.py | 11 +- scripts/test/mission-tick.test.py | 2 +- 17 files changed, 350 insertions(+), 41 deletions(-) create mode 100755 scripts/test/mission-e2e.test.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ca0ff95..31e55e82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ tag in lockstep. Tag releases as `vMAJOR.MINOR.PATCH`. ### Added - The mission layer's six fixed roles (ROADMAP §4.12, M9.9): `market-researcher`, `product-tester`, `state-assessor`, `evaluator`, `mission-planner` and `ethics-reviewer`, each a persona with a four-case eval suite, a model route (the four that judge on the planning route, the two that measure on the worker route), hook matchers on Claude Code, Codex and OpenCode, and Codex/OpenCode agents from `aloop install` (which also renders the mission skill for OpenCode as `aloop-mission` once it ships). `plugin/mission/roles.json` names the paths each role writes. `gate-mission-scope` (PreToolUse) is the role path guard: a mission role never writes source, mission.json or another role's dir, never commits and never runs a human's approval; a builder never writes `docs/agents/mission/` or runs a writing `mission` command; the supervisor never hand-writes a role's artifact. No one hand-writes `docs/agents/mission/ledger.jsonl` or the captured prompts a grant reads (`/transcripts/`), runs a hook's `transcripts prompt|record|…`, or starts a host session from a tool call where a mission is set (its prompt would count as the human's words, M9.17), and no dispatched agent runs `mission baseline restore`, `events authority` or an `events emit` of a human event. `gate-mission-artifact` records what exists when a role starts and, at its stop, requires an artifact in its own paths that passes the core contract and its area's check, refuses a deleted artifact, a change to another role's or a ledger that no longer verifies, and records `artifact.created|updated` as provenance. A mission write never arms the sprint lock. The scope gate reads a Bash command as the shell would (`_shellread.py`: quotes, comments, line continuations, heredocs, wrappers such as `timeout` and `env`, `bash -c`, `eval`, a script run by an interpreter, variables and `$(mktemp)`). Each area's check runs once per artifact with its id or subject, an ethics hard line is the reviewer's finding, not a defect, and a derived goal whose only blocks are its pending ethics review waits on the Ethics Reviewer, not on the planner. Test: `mission-roles.test.py` (32 checks, with each role run through the real journeys, baseline, assess, evaluate and ethics, goal, research and judge areas), `mission-scope-bash.test.py` (220 commands), `opencode-plugin.test.mjs`. +- The mission loop end to end, offline (ROADMAP §4.12, M9.13): `mission-e2e.test.py` drives `mission tick` from a new mission through research, a journey, a confirmed baseline, a gap list, a goal, its intents and one Aladdin sprint per intent to GOAL MET and the next raise of the bar, with zero tokens and each step done through the CLI the way its role or the human does it. A fresh clone hands out the same action. Ethics reviews and hard lines are now ledger rows (M9.24), so a clone no longer asks for every review again or forgets a hard line; the ledger row wins over its run-log copy, and a broken ledger makes every ethics verdict `broken`. Tests: `mission-e2e.test.py`, `mission-ethics.test.py`. +- A mission baseline binds the mission's direction (ROADMAP §4.12, M9.25): `direction_sha256` covers the mission id, statement, mode and constraints, so raising a budget cap or changing the cadence (and approving it) keeps the confirmed baseline, while a new direction still asks for a new version. Reason: M9.8's budget test, a raised cap asked for a new baseline though "best" had not changed. Test: `mission-baseline.test.py`. - Mission approvals are the human's own words (ROADMAP §4.12, M9.17): `mission approve`, `baseline confirm|restore`, `journeys approve`, `mission ethics consent` and `mission telemetry consent` record only when a prompt the `UserPromptSubmit` hook captured has a line such as `approve msn_… 3f2a9c1b` (the verb and the first 8 hex of the content's sha256); until then they ask (exit 3) with that line. `--by` alone, a negated line, another code, a line older than a later decision about the subject (for a baseline, any version's confirmation) and a hand-appended ledger row without such a line grant nothing. Reason: an approval was only as strong as `--by`, so a role could approve its own mission change. Tests: `mission-core.test.py`, `mission-baseline.test.py`. - Mission goals and the Aladdin handoff (ROADMAP §4.12, M9.11): `aloop mission goal derive` turns the Evaluator's gaps (in its own priority order) into a goal (autonomous: the top N; spoon-fed: the gaps the human picks with `--pick … --by`, which is the goal's approval) that names its targets and is bound to the mission's content, the eval, the principles block for the mission's mode and the Aladdin autonomy it maps to; `goal check` holds every intent until the goal is the content `derive` recorded, the mission is unchanged and approved and the mission's and the goal's ethics pass; `goal intents` writes one Intent Contract per gap (`intent new --source mission --goal --gap`, filled without a model, and refused for a goal that fails its check); `goal next` normalizes them one sprint at a time; `goal close` marks an active goal met once an evaluation of it says so; goals come only from the latest recorded evaluation, whose state `mission assess` measured, and `events emit` can no longer forge the state, eval or intent records; a gap a hard line fixed is held out of every later goal; `events trace` walks a commit back through intent → goal → eval → ethics → mission → its approver. Test: `mission-goal.test.py`. - Mission layer hardening (ROADMAP §4.12, a second adversarial review of M9.0/M9.2/M9.3/M9.10, 31 unique findings, each now a test): gates decide from ledger records, not files. Frozen journeys, replacements and retirements, states (`state.assessed`) and the active goal (`goal.derived`) are read from the ledger, so a hidden or edited file changes nothing. Nothing decides from a broken ledger or an edited current baseline, and a restore cannot be undone by a re-apply. The runner pins every project file it runs and refuses links, inline code and scripts outside the project. A judged metric pins its rubric by sha256. A veto binds the content in any order. An unknown flag exits 64. Text is UTF-8 in any locale. GA4's reserved names are one list, and `ethics.*` and `goal.*` decisions are ledger rows. Tests: `mission-{core,journeys,baseline,evaluate}.test.py`. diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 957c63a7..48ead01c 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -433,7 +433,7 @@ Each task flips only its own row here and in TRACKING.md. | M9.10 | Assess and evaluate: the State Assessor's report (numbers only, from pinned scripts) and the Evaluator's gap list against the baseline and rivals, with `goal_met` | M9.2, M9.3, M9.5 | `plugin/mission/{assess,evaluate}.py`, `schemas/{state,eval}.json`, `scripts/test/mission-evaluate.test.py` | after its needs | done: `mission-evaluate.test.py` (8 checks); judged metrics come from `judge.verdict(cwd, rubric, journey_id, rubric_sha256=…)` (M9.5) for the rubric content the journey pinned and stay pending until a pass or fail verdict; every input is the content its record covers (state `state.assessed`, baseline confirmation, frozen journeys, goal `goal.derived`/`goal.approved`). Open: rival values keyed per benchmark in the baseline, so the gap list compares against rivals (review finding) | | M9.11 | Goals and the Aladdin handoff: top gaps → a goal → intents (`intent` source `mission`), ethics and principles applied, mode → autonomy; `events trace` reaches goal → mission | M9.4, M9.7, M9.10 | `plugin/mission/goal.py`, `schemas/goal.json`, `plugin/bin/intent` (source list), `plugin/bin/events` (trace) | after its needs | done: `mission goal options / derive / check / approve / intents / next / close / show`, `intent new --source mission --goal --gap`, `events trace` adds goal → eval → ethics → mission; `mission-goal.test.py` (13 checks, on the real journeys → baseline → assess → evaluate pipeline; every new gate mutation-tested: deleting it fails a check). Calls: a goal takes M9.10's gaps in its own order (regressions, then closest to target) and names them as `targets` [{journey_id, criterion_id}], which `mission evaluate` narrows to while the goal is active; autonomous takes the top 3 by default, spoon-fed the human's `--pick` (the pick is `goal.approved`); a goal comes only from the latest eval of the whole mission (not an older one, whose gaps may be closed, nor one narrowed to an active goal) whose gap list `evaluate check` confirms, whose content its `eval.completed` recorded, and whose state a `state.assessed` recorded (a hand-written state that `mission evaluate` accepted is still refused); `goal check`, `intents`, `next` and `close` hold a goal to the content its `goal.derived` recorded, so a crafted or edited-and-resealed goal file is never handed off or closed; a goal is stale once the mission's content changes; intents are filled from the gap and the journey without a model (zero tokens), one per gap, normalized one at a time by `next`, which first makes that intent the newest file (gate-intake re-checks the newest, so the sprint's plan links the right gap); `intent new --source mission` needs `--gap` and a goal that passes `goal check` and lists that gap, and `intent check` holds a mission intent to its own `intent.received` record (goal and gap) and to the goal's autonomy (a reviewed goal's intent is not checked as autonomous); the handoff counts only intents whose first `intent.received` names the goal; `intents` and `close` change only the status, never the goal's hashed content (its ethics review, consent and approval stay valid); a goal is met by a newer evaluation of that goal that says `goal_met`, only while it is active (a derived, blocked or retired goal never closes; closing a met goal again is a no-op); `events emit` refuses `goal.derived`, `goal.met`, `state.assessed`, `eval.completed` and `intent.received`, so the lineage `trace` reads and the records a goal is derived and closed from are written only by their commands (edits outside its files: `assess` and `evaluate` add the content's `sha256` to their events, one field each). A gap a hard line fixed is held, by its id and by its summary: listed apart by `options`, never taken by `derive`, so the autonomous loop moves on instead of re-deriving it (`ethics.blocked` names the gaps); a gap's summary is the journey's title, criterion and target (stable across evals); a goal keeps the principles stamp it was derived under (stale after an upgrade, not invalid, since re-stamping would void its ethics review and approval) | | M9.12 | The `/aloop:mission` skill: the supervisor's playbook for the tick loop | M9.8, M9.9 | `plugin/skills/mission/` | after its needs | done: `mission-skill.test.py` (8 checks); a live run needs M9.9's roles | -| M9.13 | End to end: an offline scripted to-do-app mission (mission → baseline → eval → goal → intent, zero tokens), then a live `make e2e-mission YES=1` | M9.10–M9.12 | `scripts/test/mission-e2e.test.py`, `scripts/smoke/e2e-mission.sh` | after its needs | blocked | +| M9.13 | End to end: an offline scripted to-do-app mission (mission → baseline → eval → goal → intent, zero tokens), then a live `make e2e-mission YES=1` | M9.10–M9.12 | `scripts/test/mission-e2e.test.py`, `scripts/smoke/e2e-mission.sh` | after its needs | in progress: offline part done. `mission-e2e.test.py` drives `mission tick` through the whole loop with zero tokens, each step done through the CLI the way its role or the human does it: the human's typed lines, ethics, sourced research (`mission research`), a journey, a baseline measured twice and confirmed, a raised budget, a state report, a gap list, a goal and its review, one intent per gap, one sprint per intent (`ids freeze`, `stats sprint-close`), GOAL MET, the goal closed, then RESEARCH raises the bar. A fresh clone hands out the same action. Open: the live run (`make e2e-mission YES=1`) | | M9.14 | GA4 live on the owner's account (one Google sign-in) | M9.6 | — | — | needs the owner: `aloop mission telemetry auth` prints the steps, then `init`, `consent`, `setup`, `debug-hit`, `verify`; exit: `verify` passes on the owner's property (the MP validator checks no secret, so only that round-trip proves the setup) | | M9.15 | Native voice mode | the owner's scope (spec cut off) | — | — | open question | | M9.16 | Docs: OVERVIEW, README, CHANGELOG, site | M9.13 | shared docs | — | blocked | @@ -444,13 +444,14 @@ Each task flips only its own row here and in TRACKING.md. | M9.21 | Keep `tick`'s USD price table current (pinned 2026-10-06). Reason: found while building M9.8, an unknown model is charged the top rate, so a new model stops the loop early | M9.8 | `plugin/mission/tick.py` (`PRICES`), `mission-tick.test.py` | yes | open | | M9.22 | The ledger keeps `usage.speed` and server tool use, and `tick` prices fast mode (2x on Opus 5, 5.5) and web search ($10 per 1,000). Reason: found reviewing M9.8, the ledger drops both, so a USD cap can be overshot (a fast-mode Opus 5.5 session is priced at half its bill) | M9.8 | `plugin/bin/{_usage.py,stats}`, `plugin/mission/tick.py`, their tests | yes | open | | M9.23 | `tick` takes its ethics facts from `mission ethics`'s verdict (M9.4), so one rule decides (a hard-lined gap reworded into a new goal, a review edited after it was recorded). Reason: found aligning M9.8 with the ledger, `tick` reads the ethics events itself and catches neither | M9.4, M9.8 | `plugin/mission/tick.py`, `mission-tick.test.py` | yes | done: `tick` asks `ethics.verdict` for the mission and each goal (none, pending, hard, broken), so a hard-lined goal's words stay hard under a new id and an edited review blocks; a committed hard review fails closed; `mission-tick.test.py` (28 checks) | -| M9.24 | The human's `mission tick --force --by` grant, the ethics reviews (`ethics.reviewed`/`ethics.blocked`, already `LEDGER_EVENTS`, still only emitted) and `mission.budget_exhausted` are ledger rows, not run data. Reason: found aligning M9.8 with the ledger and in its review, a fresh checkout loses them, so 3 failed goals block again, every review is asked again, and a hit spend cap starts from zero (`tick` fails closed on a committed hard review meanwhile) | M9.0, M9.4 | `plugin/bin/_mission.py` (`LEDGER_EVENTS`), `plugin/mission/{tick,ethics}.py`, their tests | yes | open | -| M9.25 | A baseline binds the mission's direction (statement, mode, constraints), not its whole content. Reason: found in M9.8's budget test, raising a budget cap re-approves the mission and so asks for a new baseline version, though nothing about "best" changed | M9.2 | `plugin/mission/baseline.py`, `mission-baseline.test.py` | yes | open | +| M9.24 | The human's `mission tick --force --by` grant, the ethics reviews (`ethics.reviewed`/`ethics.blocked`, already `LEDGER_EVENTS`, still only emitted) and `mission.budget_exhausted` are ledger rows, not run data. Reason: found aligning M9.8 with the ledger and in its review, a fresh checkout loses them, so 3 failed goals block again, every review is asked again, and a hit spend cap starts from zero (`tick` fails closed on a committed hard review meanwhile) | M9.0, M9.4 | `plugin/bin/_mission.py` (`LEDGER_EVENTS`), `plugin/mission/{tick,ethics}.py`, their tests | yes | ethics part done: `ethics.reviewed` and `ethics.blocked` are ledger rows (`M.record`), and ethics reads `M.history` (the ledger's rows, plus the run-log events that are not ledger rows), so a clone keeps every review, hard line and held gap; an edited run-log copy of a row changes nothing, and a broken ledger makes every verdict `broken` (`mission-ethics.test.py` checks 12 and 13, `mission-e2e.test.py`). Open: the `--force` grant and `mission.budget_exhausted` (`tick.py`) | +| M9.25 | A baseline binds the mission's direction (statement, mode, constraints), not its whole content. Reason: found in M9.8's budget test, raising a budget cap re-approves the mission and so asks for a new baseline version, though nothing about "best" changed | M9.2 | `plugin/mission/baseline.py`, `mission-baseline.test.py` | yes | done: `mission-baseline.test.py` check 5; a baseline and its state carry `direction_sha256` = `M.direction(mission)` (`mission_id`, `statement`, `mode`, `constraints`); a new budget, deadline or cadence keeps the baseline once the mission is approved again, a new direction asks for a new version, and an unapproved mission decides nothing | | M9.26 | A goal's sprint history (intent → goal, sprint planned and closed) is read from committed records. Reason: found in M9.8's review, `intent.received`, `plan.created` and `sprints.json` are run data, so a fresh checkout re-sprints an active goal whose intents were already sprinted | M9.8, M9.11 | `plugin/mission/tick.py`, the sprint-close writer, `mission-tick.test.py` | yes | open | | M9.27 | `tick` trusts an eval only when `evaluate check` would (a record, or a recomputed gap list). Reason: found in M9.8's review, an eval file nobody computed can say `goal_met` and send the loop to `RESEARCH` instead of `DERIVE_GOAL` | M9.8, M9.10 | `plugin/mission/{tick,evaluate}.py`, their tests | yes | open | | M9.40 | Artifact provenance in the loop: `mission tick` and each area's check accept a role's artifact only with the `artifact.created\|updated` event `gate-mission-artifact` records for it (role, agent id, sha256). Reason: found while building M9.9, the path guards stop a tool's write, but an area command the supervisor runs itself can still write a role's artifact | M9.8, M9.9 | `plugin/mission/tick.py` (M9.8's), its test | after its needs | open | | M9.41 | Concurrent role runs: serialize mission dispatches whose `writes` overlap (product-tester and state-assessor both write `baseline/`; the same role twice), and diff the tracked tree at a role's stop. Reason: found in the M9.9 review, two overlapping runs that share a path judge (and credit) each other's files, and a source write made inside a program (`python3 -c`) is invisible to the scope gate | M9.8, M9.9 | `plugin/bin/gate-dispatch`, `plugin/bin/gate-mission-artifact`, their tests | after its needs | open | | M9.42 | Shared role dirs and record files: an artifact's `role` field names its owner (the Product Tester's `research new --role product-tester` in the researcher's dir), a judge run record (`judges/runs/.jsonl`) counts as the Evaluator's work and is checked with its rubric, and no mission role sets `ALOOP_JUDGE_CMD` (a judge command it picks could grade its own work). Reason: found merging M9.1/M9.5 into M9.9, the Product Tester's report blocks as the researcher's, and a judge run alone blocks its stop as "no artifact" | M9.1, M9.5, M9.9 | `plugin/bin/gate-mission-*`, `plugin/mission/roles.json`, `mission-roles.test.py` | yes | open | +| M9.43 | A goal binds the mission's direction and its current approval, like a baseline (M9.25), not the whole mission sha256. Reason: found reviewing M9.25, raising the budget cap during an active goal keeps the baseline but voids the goal (`goal check`: "the mission changed"), so `goal next` refuses while `tick` keeps handing out SPRINT until it blocks and asks for `--force` | M9.11, M9.25 | `plugin/mission/goal.py`, `plugin/mission/tick.py`, `mission-goal.test.py` | yes | open | **Parallel tracks** (one thread each, from M9.0 on master): (1) Research + Judges, M9.1 + M9.5; (2) Baseline + Journeys → Assess/Evaluate, M9.2 + M9.3 → M9.10; (3) Ethics + Principles → Goals, diff --git a/docs/TRACKING.md b/docs/TRACKING.md index 52cd7cb0..f313e9e2 100644 --- a/docs/TRACKING.md +++ b/docs/TRACKING.md @@ -72,16 +72,17 @@ Status of every requirement in [ROADMAP.md](ROADMAP.md), in the four states §8 | M9.10 | State Assessor report and Evaluator gap list | IMPLEMENTED_TESTED | `scripts/test/mission-evaluate.test.py` | | M9.11 | Goals become Aladdin intents; lineage reaches the mission | IMPLEMENTED_TESTED | `scripts/test/mission-goal.test.py` | | M9.12 | `/aloop:mission` skill | IMPLEMENTED_TESTED | `scripts/test/mission-skill.test.py` | -| M9.13 | Mission end to end (offline in CI, one live cycle measured) | NOT_IMPLEMENTED | §4.12 | +| M9.13 | Mission end to end (offline in CI, one live cycle measured) | NOT_IMPLEMENTED | §4.12; offline: `scripts/test/mission-e2e.test.py`; open: the live cycle | | M9.17 | Approvals name the captured human prompt | IMPLEMENTED_TESTED | `scripts/test/mission-core.test.py` | | M9.20 | Mission spend counts mission sessions only | NOT_IMPLEMENTED | §4.12 | | M9.21 | Mission price table kept current | NOT_IMPLEMENTED | §4.12 | | M9.22 | Mission USD meter prices fast mode and server tools | NOT_IMPLEMENTED | §4.12 | | M9.23 | Mission loop takes its ethics facts from the ethics verdict | IMPLEMENTED_TESTED | `scripts/test/mission-tick.test.py` | | M9.24 | `--force` grants, ethics reviews and the budget stop are ledger rows | NOT_IMPLEMENTED | §4.12 | -| M9.25 | A baseline binds the mission's direction, not its budget | NOT_IMPLEMENTED | §4.12 | +| M9.25 | A baseline binds the mission's direction, not its budget | IMPLEMENTED_TESTED | `scripts/test/mission-baseline.test.py` | | M9.26 | A goal's sprint history is read from committed records | NOT_IMPLEMENTED | §4.12 | | M9.27 | The mission loop trusts an eval only when `evaluate check` would | NOT_IMPLEMENTED | §4.12 | | M9.40 | Artifact provenance in the mission loop | NOT_IMPLEMENTED | §4.12 | | M9.41 | Concurrent mission role runs are serialized | NOT_IMPLEMENTED | §4.12 | | M9.42 | Shared mission role dirs, judge run records and the judge command | NOT_IMPLEMENTED | §4.12 | +| M9.43 | A goal binds the mission's direction, not its budget | NOT_IMPLEMENTED | §4.12 | diff --git a/plugin/bin/_mission.py b/plugin/bin/_mission.py index 58ea7fb7..e6498031 100644 --- a/plugin/bin/_mission.py +++ b/plugin/bin/_mission.py @@ -72,6 +72,8 @@ # fields left out of the digest: the digest itself and the bookkeeping that changes on approval UNHASHED = ("sha256", "status", "approval") +# what "best" is measured for: a baseline binds these, so a new budget cap or cadence keeps it +DIRECTION = ("mission_id", "statement", "mode", "constraints") def now(): @@ -118,6 +120,11 @@ def digest(doc, drop=UNHASHED): return hashlib.sha256(canonical(doc, drop)).hexdigest() +def direction(mission_doc): + """The digest of the mission's direction (DIRECTION): what a baseline is confirmed for.""" + return digest({k: (mission_doc or {}).get(k) for k in DIRECTION}, drop=()) + + def load(path): try: with open(path, encoding="utf-8") as f: @@ -465,6 +472,17 @@ def approve(cwd, event, subject_ref, sha, by, reason="", **data): return record_human(cwd, event, subject_ref, by, reason, sha256=sha, **data) +def history(cwd): + """The ledger's intact rows, plus the run log's events that are not ledger rows, oldest first: + what a reader of past decisions iterates, so a clone decides the same. The ledger is the record: + a run-log copy of a row (same event_id) is ignored, whatever it says, and ledger rows keep their + file order (their ts never goes back). A reader that decides checks `ledger_problems` first.""" + rows = ledger_rows(cwd)[0] + have = set(r.get("event_id") for r in rows) + return sorted(rows + [e for e in _events.read(cwd) if isinstance(e, dict) and e.get("event_id") not in have], + key=lambda e: str(e.get("ts") or "")) + + def records(cwd, event, subject_ref=None, role=None): """The ledger's intact rows of one event type (one subject's, one role's), oldest first.""" rows, _ = ledger_rows(cwd) diff --git a/plugin/bin/mission b/plugin/bin/mission index c94ea880..c2a70946 100755 --- a/plugin/bin/mission +++ b/plugin/bin/mission @@ -259,6 +259,10 @@ def main(argv): except M.NeedsHuman as e: print("ASK[%s]: %s" % (argv[0], e), file=sys.stderr) return 3 + except M.LedgerBroken as e: # nothing is recorded past a broken ledger + print("BLOCK[%s]: %s (restore it: git checkout -- docs/agents/mission/ledger.jsonl)" % (argv[0], e), + file=sys.stderr) + return 2 def dispatch(argv): diff --git a/plugin/mission/README.md b/plugin/mission/README.md index ea15ae03..8b3de350 100644 --- a/plugin/mission/README.md +++ b/plugin/mission/README.md @@ -71,10 +71,17 @@ A gate checks structure and evidence, never whether a judgment is right. `git checkout -- docs/agents/mission/ledger.jsonl`. `mission init` marks it `merge=union`. **Not detectable here:** a forged row appended with a valid hash, and, on a checkout without the run log, the newest rows removed. M9.9 denies roles direct writes to the ledger and to the prompt log. +- `M.history(cwd)` is the ledger's intact rows plus the run-log events that are not ledger rows, oldest + first: a reader of past decisions (ethics verdicts, hard lines) iterates it, so a fresh clone decides + the same. A run-log copy of a ledger row is ignored, and a reader that decides checks + `M.ledger_problems` first (`ethics.verdict` is `broken` while the ledger has any). - A confirmation record carries the journeys it froze (`data.journeys`), and a retirement record its replacement (`replaced_by`, `replaced_by_sha256`): `journeys.pins` and `journeys.lifecycle` read those records, so hiding or editing a file never unfreezes, unpins or un-retires a journey. `baseline.current` is the version the newest `baseline.confirmed` record names. +- A baseline is confirmed for the mission's direction, not its caps: `direction_sha256` is + `M.direction(mission)` over `DIRECTION` (`mission_id`, `statement`, `mode`, `constraints`), so a new + budget, deadline or cadence keeps it once the mission is approved again (M9.25). - `plugin/mission/_runner.py` runs a pinned script: each `pinned` tool's probe must print its version, then the command's last stdout line is the result `{"steps": {id: bool}, "metrics": {id: number|bool}}` (NaN and Infinity are refused). The files the diff --git a/plugin/mission/assess.py b/plugin/mission/assess.py index b134bfe6..c51a177b 100644 --- a/plugin/mission/assess.py +++ b/plugin/mission/assess.py @@ -100,7 +100,7 @@ def cmd_assess(cwd, o): diffs, _ = B.disagreements(cwd, bdoc, runs) sid = M.new_id(KIND) doc = {"state_id": sid, "baseline_id": bdoc["baseline_id"], "baseline_version": bdoc["version"], - "mission_sha256": bdoc["mission_sha256"], "head": head(cwd), "runs": runs, "agreed": not diffs, + "direction_sha256": bdoc["direction_sha256"], "head": head(cwd), "runs": runs, "agreed": not diffs, "disagreements": diffs, "judged": scores, "status": "recorded", "created_at": M.now()} M.seal(doc) path = M.save(M.path_of(cwd, KIND, sid), doc) diff --git a/plugin/mission/baseline.py b/plugin/mission/baseline.py index 2ff50054..c46899cb 100644 --- a/plugin/mission/baseline.py +++ b/plugin/mission/baseline.py @@ -156,9 +156,12 @@ def standing_problems(cwd, doc): elif M.digest(jd) != j["sha256"]: out.append("journey %s changed since this baseline listed it: propose a new baseline" % j["journey_id"]) out += listing_problems(cwd, doc["journeys"]) - _, msha, mev = M.mission(cwd) - if not mev or msha != doc.get("mission_sha256"): - out.append("the mission changed since this baseline was proposed (or is not approved): propose a new one") + mdoc, _, mev = M.mission(cwd) + if not mev: + out.append("the mission is not approved (mission check): a baseline decides nothing until it is") + elif M.direction(mdoc) != doc.get("direction_sha256"): + out.append("the mission's direction (statement, mode or constraints) changed since this baseline was " + "proposed: propose a new one") cur = current_id(cwd) if doc.get("supersedes") != cur: out.append("%s supersedes %s, but the current confirmed version is %s: propose a new version against it" @@ -170,7 +173,7 @@ def standing_problems(cwd, doc): def cmd_new(cwd, o): - mdoc, msha, mev = M.mission(cwd) + mdoc, _, mev = M.mission(cwd) if not mev: say("ASK", "the mission is not approved yet (mission check): a baseline is measured for an approved mission") return 3 @@ -220,7 +223,7 @@ def cmd_new(cwd, o): tol = -1 bid = M.new_id(KIND) doc = {"baseline_id": bid, "version": (cur or {}).get("version", 0) + 1 if o.get("supersedes") else 1, - "mission_sha256": msha, "definition_of_best": (o.get("definition") or "").strip(), "journeys": listed, + "direction_sha256": M.direction(mdoc), "definition_of_best": (o.get("definition") or "").strip(), "journeys": listed, "benchmarks": benches, "rivals": o.get("rival", []), "tolerance": tol, "supersedes": o.get("supersedes"), "evidence_refs": o.get("evidence", []), "measurements": None, "status": "proposed", "created_at": M.now()} @@ -503,9 +506,12 @@ def cmd_restore(cwd, bid, o): bad.append("journey %s changed or is gone since %s froze it: propose a new version" % (j["journey_id"], bid)) elif J.lifecycle(cwd, J.jpath(cwd, j["journey_id"]), jd) == "retired": bad.append("journey %s was retired since: propose a new version without it" % j["journey_id"]) - _, msha, mev = M.mission(cwd) - if not mev or msha != doc.get("mission_sha256"): - bad.append("%s was confirmed for an earlier mission content: propose a new version" % bid) + mdoc, _, mev = M.mission(cwd) + if not mev: + bad.append("the mission is not approved (mission check): nothing is restored until it is") + elif M.direction(mdoc) != doc.get("direction_sha256"): + bad.append("%s was confirmed for an earlier mission direction (statement, mode or constraints): " + "propose a new version" % bid) if bad: for b in bad: say("BLOCK", b) @@ -581,9 +587,12 @@ def evaluate(cwd): asks.append("journey %s was retired: a new baseline version supersedes this one" % j["journey_id"]) if bad: return 2, bad, facts - _, msha, mev = M.mission(cwd) - if not mev or msha != doc["mission_sha256"]: - asks.append("the baseline was confirmed for an earlier mission content: the human re-confirms the direction") + mdoc, _, mev = M.mission(cwd) + if not mev: + asks.append("the mission is not approved (mission check): the baseline decides nothing until it is") + elif M.direction(mdoc) != doc.get("direction_sha256"): + asks.append("the baseline was confirmed for an earlier mission direction (statement, mode or constraints): " + "a new baseline version is proposed for the new direction") if asks: return 3, asks, facts facts["confirmed_by"] = rec["data"].get("by") diff --git a/plugin/mission/ethics.py b/plugin/mission/ethics.py index aaaa5ef8..894c9132 100644 --- a/plugin/mission/ethics.py +++ b/plugin/mission/ethics.py @@ -39,7 +39,6 @@ import unicodedata sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "bin")) -import _events # noqa: E402 import _mission as M # noqa: E402 TIERS = ("clear", "gray", "hard") @@ -175,13 +174,13 @@ def word_keys(kind, doc, only=None): def hard_words(cwd): """Every word key a hard line has fixed (the goal module skips gaps that repeat one).""" - return {w for e in _events.read(cwd) if e.get("event") == "ethics.blocked" + return {w for e in M.history(cwd) if e.get("event") == "ethics.blocked" for w in ((e.get("data") or {}).get("words") or []) if isinstance(w, str)} def held_gaps(cwd): """Every gap id a hard line has fixed: the gap is held by its id as well as by its words.""" - return {g for e in _events.read(cwd) if e.get("event") == "ethics.blocked" + return {g for e in M.history(cwd) if e.get("event") == "ethics.blocked" for g in ((e.get("data") or {}).get("gaps") or []) if isinstance(g, str)} @@ -317,8 +316,12 @@ def verdict(cwd, kind, sid): facts = {"subject": ref, "kind": kind, "id": subj["id"], "sha256": sha, "state": "none", "screen": {c: p for c, p in matched}, "tier": None, "review": None, "reviews": [], "consent_event": None} + broken = M.ledger_problems(cwd) # reviews and hard lines are its rows: what is left of it decides nothing + if broken: + facts["state"] = "broken" + return 2, ["%s (restore it: git checkout -- %s)" % (b, M.rel(cwd, M.ledger(cwd))) for b in broken], facts every, recs, hard, consents = [], {}, [], [] - for e in _events.read(cwd): + for e in M.history(cwd): d = e.get("data") or {} if not str(e.get("event", "")).startswith("ethics."): continue @@ -458,19 +461,20 @@ def cmd_record(cwd, path): return 2 M.save(path, rev) kind, sid = parsed - mine = [e for e in _events.read(cwd) if e.get("event") == "ethics.reviewed" + mine = [e for e in M.history(cwd) if e.get("event") == "ethics.reviewed" and (e.get("data") or {}).get("ethics_id") == eid] if not mine or mine[-1]["data"].get("review_sha256") != rev["sha256"]: # re-recording the same file is a no-op - refs = {"review": M.rel(cwd, path), "subject": cur["ref"]} - words = text_digest(doc) - M.emit(cwd, "ethics.reviewed", role="ethics-reviewer", refs=refs, ethics_id=eid, subject=cur["ref"], - sha256=cur["sha256"], text_sha256=words, review_sha256=rev["sha256"], tier=rev["tier"], kind=kind) + if M.ledger_block(cwd, "ethics"): + return 2 + words = text_digest(doc) # a ledger row: a fresh checkout keeps every review and hard line + M.record(cwd, "ethics.reviewed", cur["ref"], "ethics-reviewer", ethics_id=eid, review=M.rel(cwd, path), + sha256=cur["sha256"], text_sha256=words, review_sha256=rev["sha256"], tier=rev["tier"], kind=kind) if rev["tier"] == "hard": cats = [c for c in list(CATEGORIES) + ["other"] if any(f["category"] == c and f["tier"] == "hard" for f in rev["findings"])] - M.emit(cwd, "ethics.blocked", role="ethics-reviewer", refs=refs, ethics_id=eid, subject=cur["ref"], - sha256=cur["sha256"], text_sha256=words, categories=cats, kind=kind, words=hard_keys(kind, doc, rev), - gaps=hard_gaps(kind, doc, rev)) + M.record(cwd, "ethics.blocked", cur["ref"], "ethics-reviewer", ethics_id=eid, review=M.rel(cwd, path), + sha256=cur["sha256"], text_sha256=words, categories=cats, kind=kind, words=hard_keys(kind, doc, rev), + gaps=hard_gaps(kind, doc, rev)) print("[ethics] %s recorded: tier %s for %s" % (eid, rev["tier"], cur["ref"]), file=sys.stderr) rc, bad, facts = verdict(cwd, kind, sid) if facts.get("state") == "hard" and kind == "goal" and doc.get("status") != "blocked": diff --git a/plugin/mission/schemas/baseline.json b/plugin/mission/schemas/baseline.json index 30d7df59..cd15986d 100644 --- a/plugin/mission/schemas/baseline.json +++ b/plugin/mission/schemas/baseline.json @@ -4,7 +4,7 @@ "required": [ "baseline_id", "version", - "mission_sha256", + "direction_sha256", "definition_of_best", "journeys", "benchmarks", @@ -23,7 +23,7 @@ "type": "integer", "minimum": 1 }, - "mission_sha256": { + "direction_sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" }, diff --git a/plugin/mission/schemas/state.json b/plugin/mission/schemas/state.json index dd47bf61..64132164 100644 --- a/plugin/mission/schemas/state.json +++ b/plugin/mission/schemas/state.json @@ -1,13 +1,13 @@ { "title": "state — the State Assessor's measurement of the product now (ROADMAP §4.12, M9.10): docs/agents/mission/state/.json", "type": "object", - "required": ["state_id", "baseline_id", "baseline_version", "mission_sha256", "head", "runs", "agreed", "status", "created_at"], + "required": ["state_id", "baseline_id", "baseline_version", "direction_sha256", "head", "runs", "agreed", "status", "created_at"], "additionalProperties": false, "properties": { "state_id": {"type": "string", "pattern": "^sta_"}, "baseline_id": {"type": "string", "pattern": "^bln_"}, "baseline_version": {"type": "integer", "minimum": 1}, - "mission_sha256": {"type": "string", "pattern": "^[0-9a-f]{64}$"}, + "direction_sha256": {"type": "string", "pattern": "^[0-9a-f]{64}$"}, "head": {"type": "object", "required": ["commit", "dirty"], "properties": { "commit": {"type": "string"}, "dirty": {"type": "boolean"}}}, "runs": {"type": "array", "minItems": 2, "items": {"type": "object", "required": ["journeys", "benchmarks"], diff --git a/plugin/skills/mission/SKILL.md b/plugin/skills/mission/SKILL.md index fbd9ddf0..77651787 100644 --- a/plugin/skills/mission/SKILL.md +++ b/plugin/skills/mission/SKILL.md @@ -95,6 +95,10 @@ and goals once there is usage, and is never a gate. `aloop mission `. `mission.json` changes only with a new human approval. - You record a human approval (the mission, the baseline, a goal pick, a consent) only on the human's explicit yes in this session, with `--by` naming them. Never infer one. +- A grant counts only in the human's own typed words (M9.17). Run the command; it exits 3 with + `they reply `. Give them that exact line once and stop; once they have + typed it, run the command the ASK names after "then" (usually the same command; a spoon-fed + pick names `goal approve`). A yes in other words, or your `--by` alone, grants nothing. - A hard line is final: no consent unlocks it, and re-running the review never helps (the most severe verdict for a content stands). - You never weaken or drop a journey or a metric; a new idea is a new journey. diff --git a/scripts/test/mission-baseline.test.py b/scripts/test/mission-baseline.test.py index 0db18701..6214bd35 100644 --- a/scripts/test/mission-baseline.test.py +++ b/scripts/test/mission-baseline.test.py @@ -43,7 +43,7 @@ def new_id(r): doc = p.load("baseline", b1) assert doc["version"] == 1 and doc["status"] == "proposed" and doc["journeys"] == [ {"journey_id": j1, "sha256": M.digest(p.load("journey", j1))}] -assert doc["mission_sha256"] == M.mission(p.dir)[1] +assert doc["direction_sha256"] == M.direction(M.mission(p.dir)[0]) assert p.run("baseline", "check").returncode == 3 # nothing confirmed yet ok("baseline new: bound to the approved mission, lists its journeys by sha256, rivals are sourced claims") @@ -103,13 +103,23 @@ def new_id(r): p.save("baseline", b1, bd) assert p.run("baseline", "check").returncode == 0 md = p.load("mission") -md["statement"] += ", for teams" -md["status"] = "draft" +md["budget"]["usd"], md["cadence"], md["status"] = 80.0, "12h", "draft" # caps and cadence are not "best" p.save("mission", "", md) -assert p.run("approve", "--by", "Adeel").returncode == 0 r = p.run("baseline", "check") -assert r.returncode == 3 and "earlier mission content" in r.stderr, r.stderr -ok("a frozen journey or baseline edited by hand fails the check; a re-approved mission asks to re-confirm") +assert r.returncode == 3 and "the mission is not approved" in r.stderr, r.stderr # but an unapproved mission decides nothing +assert p.run("approve", "--by", "Adeel").returncode == 0 +assert p.run("baseline", "check").returncode == 0, p.run("baseline", "check").stderr +md = p.load("mission") +for key, value in (("statement", md["statement"] + ", for teams"), ("mode", "spoon-fed"), + ("constraints", ["no paid SaaS"])): + p.save("mission", "", dict(md, status="draft", **{key: value})) + assert p.run("approve", "--by", "Adeel").returncode == 0 + r = p.run("baseline", "check") + assert r.returncode == 3 and "earlier mission direction" in r.stderr, (key, r.stderr) +md["statement"] += ", for teams" +p.save("mission", "", dict(md, status="draft")) +assert p.run("approve", "--by", "Adeel").returncode == 0 +ok("a frozen journey or baseline edited by hand fails the check; a new budget or cadence keeps the baseline, a new direction asks") # 6) a replacement needs evidence; an autonomous mission applies it after the veto window, unless vetoed md["statement"] = md["statement"].replace(", for teams", "") diff --git a/scripts/test/mission-e2e.test.py b/scripts/test/mission-e2e.test.py new file mode 100755 index 00000000..f680237e --- /dev/null +++ b/scripts/test/mission-e2e.test.py @@ -0,0 +1,184 @@ +#!/usr/bin/env python3 +"""ROADMAP §4.12 (M9.13, offline): one mission end to end with zero tokens. Each step is the action +`mission tick` hands out, done the way its role or the human does it, through the CLI only: the +mission (the human's typed line approves it) → an ethics review → sourced research → a journey → a +baseline measured twice and confirmed by the human → a state report → a gap list → a goal → its ethics +review → one Intent Contract per gap → one Aladdin sprint per intent (planned at `ids freeze`, closed +by `stats sprint-close`) → a state report → GOAL MET → the goal closes → RESEARCH raises the bar. A +raised budget keeps the baseline (M9.25); a fresh clone decides the same. + python3 scripts/test/mission-e2e.test.py +""" +import json +import os +import subprocess +import sys +import tempfile +import time + +sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), "fixtures")) +from mission_fixture import ASKED, BIN, Project, M # noqa: E402 + +PASS = [0] +GIT = dict(GIT_AUTHOR_NAME="t", GIT_AUTHOR_EMAIL="t@t", GIT_COMMITTER_NAME="t", GIT_COMMITTER_EMAIL="t@t") + + +def ok(name): + PASS[0] += 1 + print("ok -", name) + + +def must(*args, rc=0): + r = p.run(*args) + assert r.returncode == rc, (args, r.returncode, r.stdout[-300:], r.stderr[-600:]) + return r + + +def tool(name, *args, rc=0): + r = subprocess.run([os.path.join(BIN, name)] + list(args), cwd=p.dir, env=p.env, capture_output=True, text=True) + assert r.returncode == rc, (name, args, r.returncode, r.stdout[-300:], r.stderr[-600:]) + return r + + +def sprint(n, gid): + """One Aladdin sprint on the goal's next intent: `goal next` hands it off, the planner's boundary + (`ids freeze`) records plan.created, and FINAL-GATE's `stats sprint-close` closes it.""" + nxt = must("goal", "next", gid).stdout.strip() + sdir = os.path.join(p.dir, "docs", "agents", "sprint%d" % n) + story = os.path.join(sdir, "s%d-01-gap" % n) + os.makedirs(story) + with open(os.path.join(sdir, "stories.md"), "w") as f: + f.write("# Stories\n\n- S%d-01: close the gap\n" % n) + for name in ("story.md", "tasks.md"): + with open(os.path.join(story, name), "w") as f: + f.write("---\nstory: S%d-01\n---\n\n## T1 close the gap\n" % n) + tool("ids", "freeze", sdir) + plan = [e for e in p.events("plan.created") if e["data"].get("sprint") == "S%d" % n] + assert len(plan) == 1 and plan[0]["data"]["intent_id"] == json.load(open(nxt))["intent_id"], plan + return sdir + + +def tick(want, rc=0, cwd=None): + r = subprocess.run([os.path.join(BIN, "mission"), "tick", "--json"], cwd=cwd or p.dir, env=p.env, + capture_output=True, text=True) + d = json.loads(r.stdout) + assert (d["action"], r.returncode) == (want, rc), (want, rc, d, r.stderr[-400:]) + STEPS.append(want) + return d + + +def review_clear(subject="mission"): + path = must("ethics", "new", "--subject", subject).stdout.strip() + doc = json.load(open(path)) + doc.update(findings=[], tier="clear") # the reviewer's judgment: nothing to flag + with open(path, "w") as f: + json.dump(doc, f) + must("ethics", "record", path) + + +STEPS = [] +p = Project(mode="autonomous", veto_window_h=0, approve=False) + +# 1) the human sets the mission; only their typed line approves it +tick("CONFIRM_MISSION", 3) +r = p.raw("approve", "--by", "Adeel", "--reason", "go") +assert r.returncode == 3 and ASKED.search(r.stderr), r.stderr # a role cannot approve for them +p.say(ASKED.search(r.stderr).group(1)) +assert p.raw("approve", "--by", "Adeel", "--reason", "go").returncode == 0 +ok("the mission counts once the human typed its approval line") + +# 2) the roles build the evaluation layer; the human confirms the baseline +tick("ETHICS_REVIEW") +review_clear() +tick("RESEARCH") +rsr = must("research", "new", "Rival to-do apps", "--question", "how fast do rivals get a user to a first task?") +rid = json.load(open(rsr.stdout.strip()))["research_id"] +with open(os.path.join(p.dir, "rival.html"), "w") as f: # a saved page, as the researcher fetched it + f.write("

Rival A gets a new user to a first task in under 5 seconds.

") +src = must("research", "archive", rid, "https://example.com/rival-a", "--file", "rival.html").stdout.strip() +assert must("research", "claim", rid, "Rival A's first task takes under 5 seconds", "--source", src, "--quote", + "a first task in under 5 seconds", "--kind", "rival").stdout.strip() == "c1" +must("research", "check", rid) +tick("DEFINE_JOURNEYS") +p.journey(p.draft(rid)) +tick("BASELINE") +bid = json.load(open(must("baseline", "new", "--definition", "a first task in under 5 seconds").stdout.strip()))["baseline_id"] +tick("BASELINE") +must("baseline", "measure", bid) +tick("CONFIRM_BASELINE", 3) +must("baseline", "confirm", bid, "--by", "Adeel") +tick("ASSESS") +ok("ethics, research, journeys and a baseline measured twice; the human confirms it") + +# 3) a raised budget cap is a new approval and a new review, not a new baseline (M9.25) +md = p.load("mission") +md["budget"]["usd"], md["status"] = 80.0, "draft" +p.save("mission", "", md) +tick("CONFIRM_MISSION", 3) +must("approve", "--by", "Adeel", "--reason", "a bigger budget") +tick("ETHICS_REVIEW") +review_clear() +tick("ASSESS") +assert must("baseline", "current").stdout.strip() == bid +ok("raising the budget keeps the confirmed baseline") + +# 4) monitor and analyze: the state report and the gap list hand the planner a goal to derive +must("assess") +tick("EVALUATE") +r = must("evaluate") +assert "gap" in r.stderr, r.stderr +d = tick("DERIVE_GOAL") +assert must("evaluate", "check").returncode == 0 +ok("a state report and a gap list; the loop asks for a goal") + +# 5) a fresh clone decides the same from the committed artifacts and ledger (no run data, no prompts) +subprocess.run(["git", "add", "-A"], cwd=p.dir, check=True) +subprocess.run(["git", "commit", "-qm", "mission"], cwd=p.dir, env=dict(p.env, **GIT), check=True) +clone = tempfile.mkdtemp(prefix="aloop-clone-") +subprocess.run(["git", "clone", "-q", p.dir, clone], check=True) +assert not any(os.path.exists(os.path.join(clone, ".aladdin", d)) for d in ("logs", "transcripts")) # run data stays +assert tick("DERIVE_GOAL", cwd=clone)["reason"] == d["reason"] +ok("a fresh clone hands out the same action") + +# 6) plan: the goal, its ethics review, then one Intent Contract per gap +r = must("goal", "derive") +g = json.load(open(r.stdout.strip())) +gid = g["goal_id"] +tick("ETHICS_REVIEW") +review_clear(gid) +tick("PLAN_INTENTS") +assert must("goal", "check", gid).returncode == 0 +paths = must("goal", "intents", gid).stdout.split() +assert len(paths) == len(g["gaps"]) >= 1 and all(json.load(open(x))["source"] == "mission" for x in paths) +ok("a goal from the gap list, its ethics review, and one intent per gap") + +# 7) build: one sprint per intent; the loop waits while one runs and hands out the next when it closes +for n in range(1, len(paths) + 1): + tick("SPRINT") + sdir = sprint(n, gid) + tick("WAIT", 4) # exit 4: nothing to do until next_check + if n == len(paths): + p.app(seconds_to_first_task=3.0, working_steps=["open", "add", "see"], tasks_shown=1) # the sprints' work + tool("stats", "sprint-close", sdir) +assert p.run("goal", "next", gid).returncode == 1 # every intent has its plan +ok("each intent is one sprint: planned at the planner's boundary, closed by sprint-close") + +# 8) re-evaluate: the state after the sprints earns every target; the goal closes; the bar is raised +tick("ASSESS") +time.sleep(1.05 - time.time() % 1) # sprint-close stamps whole seconds: a report in the same second cannot be ordered after it +must("assess") +tick("EVALUATE") +r = must("evaluate") +assert "GOAL MET" in r.stderr and "0 gap(s)" in r.stderr, r.stderr +ev = json.load(open(r.stdout.strip().splitlines()[-1])) +assert ev["goal_id"] == gid and ev["goal_met"] is True, ev +must("goal", "close", gid, "--eval", ev["eval_id"]) +assert p.load("goal", gid)["status"] == "met" +tick("RESEARCH") +assert must("evaluate", "check").returncode == 0 and must("check").returncode == 0 +assert M.ledger_problems(p.dir) == [] +usage = os.path.join(p.dir, ".aladdin", "ledger") +assert not os.path.isdir(usage) or not any(os.scandir(usage)), "an offline run spends no tokens" +ok("the sprints' product meets the goal; it closes and the loop raises the bar; no tokens spent, the ledger intact") + +print("loop:", " → ".join(STEPS)) +print("mission-e2e: %d checks passed" % PASS[0]) diff --git a/scripts/test/mission-ethics.test.py b/scripts/test/mission-ethics.test.py index 9cdf4975..fdc1f9fe 100644 --- a/scripts/test/mission-ethics.test.py +++ b/scripts/test/mission-ethics.test.py @@ -398,6 +398,62 @@ def goal(text, **extra): assert r.returncode == 2 and json.loads(r.stdout)["state"] == "broken" and "restore it" in r.stderr, r.stderr ok("second round: mechanics and modifiers screened; a hard line follows a goal's words to any re-derived goal; state") +# 12) a fresh checkout keeps every verdict (M9.24): reviews and hard lines are ledger rows, not run data +logs = os.path.join(T, ".aladdin", "logs") + + +def clone(fn): + """fn() as a fresh checkout sees it: the run log is git-ignored, so a clone has none.""" + shutil.move(logs, logs + ".aside") + try: + return fn() + finally: + shutil.rmtree(logs, ignore_errors=True) # what the commands wrote meanwhile + shutil.move(logs + ".aside", logs) + + +here = [st(s) for s in (gX, gX2, gN, "mission")] +assert here[:2] == ["hard", "hard"], here +assert clone(lambda: [st(s) for s in (gX, gX2, gN, "mission")]) == here, here +assert os.path.exists(os.path.join(logs, "events.jsonl")) +ok("a fresh checkout keeps every review and hard line (ledger rows): nothing is unlocked or asked again") + +# 13) the ledger decides (M9.24): an edited run-log copy of a ledger row changes nothing; a broken ledger decides nothing +log = os.path.join(logs, "events.jsonl") +kept = open(log).read() +mine = lambda e: e["event"] in ("ethics.reviewed", "ethics.blocked") and e["data"].get("subject", "").endswith(gX + ".json") # noqa: E731 +evs = [json.loads(l) for l in kept.splitlines() if l.strip()] +assert [e["event"] for e in evs if mine(e)] == ["ethics.reviewed", "ethics.blocked"], evs +with open(log, "w") as f: # same event_ids, other events: the run log is not the record + f.write("".join(json.dumps(dict(e, event="judge.run") if mine(e) else e) + "\n" for e in evs)) +assert M.ledger_problems(T) == [] and st(gX) == "hard" and E.held_gaps(T) == {GX["gap_id"]}, st(gX) +assert clone(lambda: E.held_gaps(T)) == {GX["gap_id"]} # a clone holds the gap by its id too +with open(log, "w") as f: + f.write(kept) +led = M.ledger(T) +chain = open(led).read() +rows = chain.splitlines() +at = next(i for i, l in enumerate(rows) if json.loads(l)["event"] == "ethics.blocked") +assert at < len(rows) - 1 # a row follows it: the cut is mid-chain +with open(led, "w") as f: + f.write("".join(l + "\n" for i, l in enumerate(rows) if i != at)) + + +def broken(): + for s in (gX, gN, "mission"): + r = run(MI, "ethics", "check", "--subject", s, "--json") + assert r.returncode == 2 and json.loads(r.stdout)["state"] == "broken", (s, r.stdout, r.stderr) + assert "ledger" in r.stderr and "restore it" in r.stderr, r.stderr + + +broken() # this checkout +clone(broken) # and a fresh clone: nothing decides from what is left +with open(led, "w") as f: + f.write(chain) +assert [st(s) for s in (gX, gX2, gN, "mission")] == here +ok("the ledger decides: an edited run-log copy of a hard line changes nothing, and a ledger cut mid-chain blocks every " + "verdict, in this checkout and a clone") + # 11) usage: unknown subjects and commands; the area is discovered; --help is the docstring assert run(MI, "ethics", "check", "--subject", "gol_000000000000deadbeef").returncode == 2 assert run(MI, "ethics", "check").returncode == 64 diff --git a/scripts/test/mission-skill.test.py b/scripts/test/mission-skill.test.py index 1c520362..576a2468 100755 --- a/scripts/test/mission-skill.test.py +++ b/scripts/test/mission-skill.test.py @@ -77,7 +77,16 @@ def ok(name): for phrase in ("never write", "docs/agents/mission/", "explicit yes", "--by", "hard line", "never weaken", "never gates", "every action comes from", "STOP_BUDGET"): assert phrase.lower() in rules.lower(), "the hard rules do not say %r" % phrase -ok("hard rules: no mission artifact by hand, approvals only on the human's yes, hard lines final, telemetry never gates") +# M9.17: a grant is the human's typed line, so the supervisor relays the line the command asks for, verbatim +for phrase in ("they reply", "exact line", "typed", 'the command the ASK names after "then"', "goal approve", + "grants nothing"): + assert phrase in rules, "the hard rules do not say how a grant is made (M9.17): %r" % phrase +for src, forms in (("bin/_mission.py", ("they reply ", "then run this again")), # what the CLI prints + ("mission/goal.py", ("then aloop mission goal approve",))): + text = open(os.path.join(PLUGIN, src)).read() + assert all(f in text for f in forms), (src, forms) +ok("hard rules: no mission artifact by hand, approvals only in the human's own typed line, hard lines final, " + "telemetry never gates") # 6) setting a mission asks the human only for what requirement 1 gives them setup = SKILL[SKILL.index("## Setting a mission"):] diff --git a/scripts/test/mission-tick.test.py b/scripts/test/mission-tick.test.py index e507e298..a9db06b6 100755 --- a/scripts/test/mission-tick.test.py +++ b/scripts/test/mission-tick.test.py @@ -848,7 +848,7 @@ def active_goal(p, hours, status="active"): p.review(p.mission_ref(), p.mission_doc(), "clear", 0.25) assert p.mi("baseline", "measure", bid).returncode == 2 # what the gate says d2 = p.tick(0.3) -expect(d2, "BASELINE", 0, "can no longer be measured (the mission changed") +expect(d2, "BASELINE", 0, "can no longer be measured (the mission's direction") assert d2["key"] != d1["key"] and d2["handout"] == 1, (d1["key"], d2["key"]) b2 = p.baseline() expect(p.tick(0.4), "CONFIRM_BASELINE", 3) From dcb3c92a2d7c58368d88d0d649bfd9796aaa85ac Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Tue, 20 Oct 2026 06:12:23 +0000 Subject: [PATCH 2/2] mission-e2e: the loop hands out the goal close, then a whole-mission eval (#87) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_018RxETAY6S1gcmdctBK8a8Z --- scripts/test/mission-e2e.test.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/test/mission-e2e.test.py b/scripts/test/mission-e2e.test.py index f680237e..17b39a9b 100755 --- a/scripts/test/mission-e2e.test.py +++ b/scripts/test/mission-e2e.test.py @@ -4,7 +4,8 @@ mission (the human's typed line approves it) → an ethics review → sourced research → a journey → a baseline measured twice and confirmed by the human → a state report → a gap list → a goal → its ethics review → one Intent Contract per gap → one Aladdin sprint per intent (planned at `ids freeze`, closed -by `stats sprint-close`) → a state report → GOAL MET → the goal closes → RESEARCH raises the bar. A +by `stats sprint-close`) → a state report → GOAL MET → the goal closes → a whole-mission eval → +RESEARCH raises the bar. A raised budget keeps the baseline (M9.25); a fresh clone decides the same. python3 scripts/test/mission-e2e.test.py """ @@ -171,8 +172,13 @@ def review_clear(subject="mission"): assert "GOAL MET" in r.stderr and "0 gap(s)" in r.stderr, r.stderr ev = json.load(open(r.stdout.strip().splitlines()[-1])) assert ev["goal_id"] == gid and ev["goal_met"] is True, ev +d = tick("EVALUATE") # the loop hands out the close +assert "goal close %s --eval %s" % (gid, ev["eval_id"]) in d["reason"], d["reason"] must("goal", "close", gid, "--eval", ev["eval_id"]) assert p.load("goal", gid)["status"] == "met" +tick("EVALUATE") # the narrowed eval says nothing about the mission +r = must("evaluate") +assert "GOAL MET" in r.stderr and json.load(open(r.stdout.strip().splitlines()[-1])).get("goal_id") in (None, ""), r.stderr tick("RESEARCH") assert must("evaluate", "check").returncode == 0 and must("check").returncode == 0 assert M.ledger_problems(p.dir) == []