From 541f3c09f50a2c3a7845bf1ef0ba50442cd0f902 Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Tue, 20 Oct 2026 11:12:14 +0000 Subject: [PATCH 1/4] A goal its sprints did not meet is retired, and the loop moves on (M9.50) `mission goal retire GOAL --eval EVAL` records goal.retired in the committed ledger when every intent of the goal was sprinted, its sprints closed and the newest eval of it, made after those closes, still lists gaps. A retired goal takes no intents, sprints or close; `mission evaluate` covers the whole mission again and the next goal is derived. `mission tick` hands this out as RETIRE_GOAL (mission-planner) from the command's own rule (goal.retire_problems), else BLOCKED with its reason; a retirement counts toward the 3-failed-goals block. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Aw6CiQcdpzdzZZXKf8WbUM --- CHANGELOG.md | 1 + docs/ROADMAP.md | 7 +- docs/TRACKING.md | 2 +- plugin/bin/_mission.py | 4 +- plugin/bin/events | 1 + plugin/mission/README.md | 8 +- plugin/mission/evaluate.py | 22 +++-- plugin/mission/goal.py | 130 ++++++++++++++++++++++++++++-- plugin/mission/tick.py | 44 +++++++--- plugin/skills/mission/SKILL.md | 4 +- scripts/test/mission-goal.test.py | 65 ++++++++++++++- scripts/test/mission-tick.test.py | 64 +++++++++++++-- 12 files changed, 309 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e67b80f7..3022e43e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ tag in lockstep. Tag releases as `vMAJOR.MINOR.PATCH`. - Core agent principles and the one-way / two-way door rule (ROADMAP §4.12, M9.30): seven core principles from Amazon's Leadership Principles, the door rule first, go to every aloop agent at session start (`aloop mission principles show --core`). A two-way door (a branch, a local edit, a test, a draft PR) is decided, not asked. A one-way door (`aloop mission doors list`: a push or merge to the default branch, a force-push, a release, a deploy, a message sent outside, a secret, dropped data, …) is stopped by a PreToolUse gate with `ASK[door] ` until the human records an authorization in their own terminal (`aloop mission doors authorize ID --by NAME --reason TEXT [--until DATE] [--once DIGEST]`, a hash-chained ledger row); a wall (switching a gate off, forging a human record) is never crossed. While a run is live, a question to the human must name a door the gate stopped and nobody authorized. Reason: Adeel's request that agents decide two-way doors themselves and ask only at a one-way door not already authorized. Test: `mission-doors.test.py`. Hardened by an adversarial review (15 findings, each a test): the gate reads Bash as the shell does (comments, line continuations, heredoc bodies, `xargs`, `find -exec`, `echo … | sh`), a branch condition reads the directory the command acts on (`git -C`, `cd`), settings are guarded wherever they live, dry runs and `command -v` are two-way, the newest decision by time counts and a revoke holds on every branch, a once-grant is crossed once under a lock, a broken ledger is named, and `doors authorize` refuses an agent's shell. - DeepSeek Harness (dsh) host (ROADMAP §4.9): `aloop install dsh` (alias `deepseek`; `--project P` or `--global`) renders a `dsh --profile aloop` profile in `$DSH_HOME` and installs the skills. Its native plugin (`plugin/hosts/dsh/aloop.mjs`) runs the same gates as Claude Code on dsh's own events: a deny before a tool runs, a block after an invalid artifact write, and a stop gate that steers a role back up to 3 times before the supervisor is told it is BLOCKED (or STUCK, released unverified). Roles are agent presets on two subagent tools, one per model route (`deepseek-v4-pro` for planning, `deepseek-flash` for work by default; `MODEL_PLANNING_DSH` / `MODEL_WORKER_DSH` override). A writer's `aloop bind` moves its working directory into its worktree, and `host-adapter` confines its commands, edits and `working_directory` there. Usage is recorded Claude-shaped per role, so budgets, the ledger and `run-summary` work unchanged. `make e2e-live HOST=dsh` drives it live and exits 2 with the fix when no `DEEPSEEK_API_KEY` is set. Reason: DeepSeek's own harness is the cheapest route to a strong model. The profile records the project it serves (or `--global`), so another project's `aloop-init` never re-renders it, and gates get the worker shell's environment (no API key). The mission layer's six roles run on dsh too: presets on their route group's subagent tool, `gate-mission-scope` on every write and command, and `gate-mission-artifact` at each role's start and stop; the mission skill installs as `aloop-mission`. A second review (3 lenses; 11 confirmed findings, each fixed with a test) closed: a working directory that vanished (dsh's tools move it back to the main tree, so the plugin judges `ensure()`'s directory and `host-adapter` refuses to run from a missing one), gate switches from the project's `.env` (dsh loads it; `SKIP_HOOKS`, `GATE_RUN_TESTS`, `REPO_DIR`, `AGENTIC_*` from it never reach a gate), an interrupted Stop that dropped the sprint-close notice, and the shared profile: its owner is the main tree, an older unrecorded profile is claimed only by the project that installed it, and a project it does not serve is told so by `install status`, `aloop-init` and the session itself. Tests: `dsh-plugin.test.mjs` (40 checks, emulated), `dsh-runtime.test.mjs` (32 checks on the real pinned dsh 0.2.1-rc.2 with a scripted model; the CI hosts job installs it) and `dsh-install.test.py` (9). - Brand kit and repo front page: `docs/brand/` holds the mark (an **a** whose bowl is a red-to-green loop passing a gold gate, with a 16 px cut), lockups, light and dark README banners, favicons, app icons, the site's OG card and the GitHub social preview, all generated by `docs/brand/gen_brand.py` from one palette with WCAG checks (rules in `docs/brand/README.md`). The README leads with the mission layer, the agent principles and the door rule, the supported hosts and the measured demo runs; the site carries the favicon and Open Graph/Twitter card metadata; `SECURITY.md` and bug/feature issue forms are new. +- A goal its sprints did not meet is retired, and the loop moves on (ROADMAP §4.12, M9.50): `aloop mission goal retire GOAL --eval EVAL` records `goal.retired` in the committed ledger once every intent of the goal was sprinted, its sprints closed and the newest eval of it, made after those closes, still lists gaps. A retired goal takes no more intents, sprints or close, `mission evaluate` covers the whole mission again and the next goal is derived. `mission tick` hands this out as `RETIRE_GOAL` (role `mission-planner`) where it used to stop at `BLOCKED` for the human, and asks the command's own rule first; 3 retired goals in a row still go to the human. Tests: `mission-goal` check 13, `mission-tick` checks 28 and 33. - A mission's gap lists count only as `mission evaluate` computed them (ROADMAP §4.12, M9.27): `evaluate` records `eval.completed` in the committed ledger, and `mission tick`, `evaluate check` and `goal` take the newest eval whose content that record covers, with a matching seal, in the ledger's order. An eval file written by hand, or edited (or re-stamped) after it was recorded, no longer sends the loop to `RESEARCH` as "goal met" or makes `goal derive` refuse what tick handed out, a clock that is behind no longer reorders them, and a fresh checkout derives and closes goals from the evals it committed. An eval or state named as journey or baseline evidence needs its record too. Tests: `mission-tick` check 32, `mission-journeys`. - A mission's stop at a spend cap holds on a fresh checkout (ROADMAP §4.12, M9.24): the first `STOP_BUDGET` tick records a `mission.budget_exhausted` ledger row for the mission's content (once per content), and `mission tick` stops on it whatever the checkout's token ledger says, until a raised cap changes the content. - Lifting a mission block is the human's own words (ROADMAP §4.12, M9.51): `aloop mission tick --force --by` now asks (exit 3) for the human's typed `lift ` line, the code bound to this occurrence of that block, and records a `mission.lifted` ledger row, so `--by` alone, a lift only the run log has (or a replayed one), an old line or a line typed for an earlier block lift nothing, a lift of 3 failed goals reaches only those goals whatever `--now` says, and a fresh checkout keeps a lifted block lifted. `/aloop:mission` counts a lift among the typed grants it relays. A lift recorded before this (run data only) no longer counts. diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index e663526f..1af59e5e 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -406,7 +406,8 @@ replacement applies after the mission's veto window) → open goal? its `ETHICS_ `PLAN_INTENTS` (spoon-fed: `OFFER_OPTIONS`) → `SPRINT` (Aladdin, one per intent; spoon-fed: `APPROVE_PLAN`) → `WAIT` until the sprint closes, with an `ASSESS`/`EVALUATE` whenever the cadence is due mid-sprint (12h silent → `BLOCKED`) → `ASSESS` → `EVALUATE` → goal met? `RESEARCH` (raise the -bar, at most once per cadence) : `DERIVE_GOAL` (3 failed goals in a row → `BLOCKED`). The budget +bar, at most once per cadence) : every intent sprinted and gaps still open? `RETIRE_GOAL`, then a +whole-mission `EVALUATE` : `DERIVE_GOAL` (3 failed goals in a row → `BLOCKED`). The budget comes before the mission's review because a review spends tokens. Human decisions, the baseline, state reports and gap lists are read from the committed ledger, the way their areas decide them, so on a fresh checkout these decide the same, a stop at a spend cap included (the spend itself is the @@ -442,7 +443,7 @@ Each task flips only its own row here and in TRACKING.md. | M9.5 | Judges: rubric setup check and an agreement verdict from recorded runs | M9.0 | `plugin/mission/judge.py`, `schemas/rubric.json`, `scripts/test/mission-judge.test.py` | yes | done: `mission-judge.test.py` (24 checks: pinned models, majority, frozen rubrics, records matched to their judge.run events, verdict shopping, fresh clones). `verdict(…, rubric_sha256=)` lets an approved journey pin its rubric (M9.3 adopts it). Open: a judge on Codex/OpenCode needs an envelope that names the served model (plain text never counts); assess should pass `input_sha256` of a runner-made artifact, since today the judged agent picks the input | | M9.6 | Telemetry (GA4): opt-in consent, Admin API setup, Measurement Protocol debug hit, fixed Data API reports (+ realtime), minimum-sample rule, static emit check; network faked in tests | M9.0 | `plugin/mission/telemetry.py`, `schemas/telemetry.json`, `scripts/test/mission-telemetry.test.py`, `scripts/test/fixtures/fake-ga.py` | yes | done: `mission-telemetry.test.py` (15 checks, fake GA); consent and revoke are human rows in the ledger, the newest by time decides (a union merge keeps order-free), a ledger failing its check decides nothing, and a fresh checkout keeps them (their provenance rides M9.17); the journeys it binds are what the records pin (frozen or a recorded replacement, not retired, unchanged); `verify` is the live round-trip (MP hit → realtime report), and the probe's client is never a counted user | | M9.7 | Principles in two variants with tension pairs; `principles show --mode`, hashed and injected into goals | M9.0 | `plugin/mission/principles.{md,py}`, `scripts/test/mission-principles.test.py` | yes | done: `mission principles show / hash / check`, `stamp()` / `verify()` / `stale()` for goals; `mission-principles.test.py` (7 checks). Calls: a goal keeps the stamp it was derived under (an older block is stale, not invalid: re-stamping would void its ethics review and approval); the Amazon tension pairs map onto our principle ids; the standing set and the four pairs are required, more may be added; a variant is at most 280 characters (the block rides on every goal) | -| M9.8 | Loop: `tick` (the state machine above), `due` (zero-token cadence check), `cron` (host routine or crontab line), budget caps from the token ledger | M9.0 | `plugin/mission/{tick,due,cron}.py`, `scripts/test/mission-tick.test.py` | yes | done: `mission-tick.test.py` (32 checks, on baselines proposed, measured and confirmed through `aloop mission`; on a fresh checkout the human decisions, the baseline, state reports and gap lists decide the same). Review (13 findings, each a test that failed before its fix): a restore is never undone; an unmeasurable or vetoed proposal names what the gates accept; distinct block keys; the ledger folds by time; a committed hard review fails closed; a state needs its `state.assessed` record; only the 3-failed-goals grant resets that count; the facts fingerprint covers spend, reviews, intents, plans, the lock and grants | +| M9.8 | Loop: `tick` (the state machine above), `due` (zero-token cadence check), `cron` (host routine or crontab line), budget caps from the token ledger | M9.0 | `plugin/mission/{tick,due,cron}.py`, `scripts/test/mission-tick.test.py` | yes | done: `mission-tick.test.py` (33 checks, on baselines proposed, measured and confirmed through `aloop mission`; on a fresh checkout the human decisions, the baseline, state reports and gap lists decide the same). Review (13 findings, each a test that failed before its fix): a restore is never undone; an unmeasurable or vetoed proposal names what the gates accept; distinct block keys; the ledger folds by time; a committed hard review fails closed; a state needs its `state.assessed` record; only the 3-failed-goals grant resets that count; the facts fingerprint covers spend, reviews, intents, plans, the lock and grants | | M9.9 | Roles and wiring: the six personas, hook matchers, model routes, host install, eval suites, role counts in docs; `gate-mission-scope` (role path guards) and `gate-mission-artifact` (a role's artifact passes its check at stop) | M9.0 | `plugin/agents/` (6 new files), `plugin/mission/roles.json` (the role table), `plugin/bin/_mission_roles.py`, `plugin/hooks/hooks.json`, `plugin/hosts/`, `plugin/evals/`, `plugin/bin/gate-mission-*`, the role lists in `_routes` / `install` / `gate-dispatch` / `selfcheck` / `budget`, role counts in README / OVERVIEW / plugin docs | yes (the only track touching shared lists) | done: `mission-roles.test.py` (33 checks, two of them runs of each role through master's real research, judge, journeys, baseline, assess, evaluate, ethics and goal areas), `mission-scope-bash.test.py` (225 Bash commands from two adversarial reviews and the M9.2/M9.3/M9.8/M9.17 asks), 6 OpenCode and 3 dsh end-to-end checks. Calls: judges (researcher, evaluator, planner, ethics) take the planning route, the two measuring roles the worker route; every mission role is read-only on source and writes only its own dirs (the planner also `docs/agents/intents/`, where only its `source: mission` intents are its work) and never the event log or the gates' state; the supervisor never hand-writes a role's artifact (mission.json stays the human's) and no one hand-writes `ledger.jsonl` (an edit made inside a role's run blocks its stop) or the captured prompts a grant reads (`/transcripts/`), runs a hook's `transcripts prompt|record|…`, or, where a mission is set, starts a host session from a tool call (`claude -p`, `codex exec`, `opencode run`, `dsh ` fire UserPromptSubmit: M9.17); no dispatched agent runs a human's step (`approve`, `confirm`, `veto`, `restore`…, `tick --force`, `events authority`, an `events emit|decide` with role `human`) or hand-emits a mission-layer event; a mission write never arms the sprint lock; an area's check runs once per artifact with its id or subject (`area_checks` in roles.json), and an ethics hard line is the reviewer's finding, not a defect, and a goal check that waits only on the goal's ethics review is the reviewer's step, not the planner's defect; a status change an event of the run explains (a human's step, or the role's own command: `baseline apply` freezing journeys, a hard line blocking its goal) is not another role's write; at stop a role must have written an artifact, and a content or status change to another role's artifact blocks unless a run of that role overlapped or the human approved it; a human event during a role's run is named, not blocked (the gate cannot tell who ran it: M9.17); the scope gate reads Bash with its own shell reader (`_shellread.py`), and what only running a command would tell is judged by its known directory or not at all | | 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) | @@ -481,7 +482,7 @@ Each task flips only its own row here and in TRACKING.md. | M9.45 | DEFINE_JOURNEYS names who writes a journey's runner (the program its pinned `runner.command` runs) and where it lives, and the journey check refuses a runner that does not exist yet. Reason: found designing the live run (M9.13), `market-researcher.md` derives the steps and pass criteria, `state-assessor.md` runs the pinned runner, and no persona or prompt says who writes it | M9.3, M9.9 | `plugin/agents/market-researcher.md`, `plugin/mission/journeys.py`, `mission-journeys.test.py` | yes | open | | M9.46 | `aloop mission due` is not read-only for a dispatched agent: it records the handout tick of a human action, so only the supervisor or the cron may run it (or `due --peek` for anyone). Reason: found designing the live run (M9.13), `roles.json` lists `due` as read-only, so a builder's `aloop mission due` marks a BLOCKED or STOP_BUDGET as told inside its own transcript and the cron stays silent | M9.8, M9.9 | `plugin/mission/roles.json`, `plugin/bin/gate-mission-scope`, `mission-scope-bash.test.py` | yes | open | | M9.47 | Computed command text: a `$VAR` program or argument (`M=npm; $M publish`, `B=main; git push origin $B`), `eval "$X"`, `sh -c "$(…)"`, and a group's output into a shell (`(echo X) | bash`). Read what is knowable (an assignment earlier in the line, echo/printf/cat output) and name the backstops for the rest (M9.34 pre-push, M9.36 provenance). Reason: the M9.30 third review; the gate reads static text, so this class is open (before M9.30 too) | M9.30 | `plugin/mission/doors.py`, its test | yes | open | -| M9.50 | A goal whose intents were all sprinted and whose eval still lists gaps gets a next step (re-plan the open gaps as intents, or a recorded retirement so a new goal can be derived). Reason: found wiring M9.28, `goal close` refuses an unmet goal and `goal next` has no intent left, so the loop can only hand it to the human | M9.11 | `plugin/mission/goal.py`, `mission-goal.test.py`, then `tick.py` | yes | open | +| M9.50 | A goal whose intents were all sprinted and whose eval still lists gaps gets a next step (re-plan the open gaps as intents, or a recorded retirement so a new goal can be derived). Reason: found wiring M9.28, `goal close` refuses an unmet goal and `goal next` has no intent left, so the loop can only hand it to the human | M9.11 | `plugin/mission/goal.py`, `mission-goal.test.py`, then `tick.py` | yes | done: `mission-goal.test.py` check 13, `mission-tick.test.py` checks 28 and 33. The call: retirement, not a re-plan (a re-plan of the same gaps repeats work the sprints already tried; the 3-failed-goals breaker bounds a run of retirements). `mission goal retire GOAL --eval EVAL` records `goal.retired` (role `mission-planner`, in `LEDGER_EVENTS`, gate-owned) when every intent of the goal was sprinted, its sprints are closed and EVAL is the newest eval, narrowed to the goal, made after those closes and not met; a retired goal takes no intents, sprints or close, and `evaluate` covers the whole mission again. `tick` hands out `RETIRE_GOAL` from the gate's own rule (`goal.retire_problems`), else `BLOCKED` with the gate's reason; a retirement counts toward the 3-failed-goals block | | M9.51 | Lifting a block (`mission tick --force --by`) is the human's own words: it asks (exit 3) for their typed `lift ` line, the code bound to this occurrence of the block (its key, the lifts of it so far, and the handout that tripped it or the newest failed goal), and records a `mission.lifted` ledger row (`APPROVAL_EVENTS`, `GRANT_VERBS`); a repeat restarts only at that row's own run-log event (first copy), and the 3-failed-goals count only up to the goals the human lifted; `/aloop:mission` counts a lift among the typed grants. Reason: found after M9.17 merged, `--by` alone still lifted a block and the lift was run data, so a fresh checkout blocked again (M9.24's first part) | M9.8, M9.12, M9.17 | `plugin/mission/tick.py`, `plugin/bin/_mission.py`, `plugin/bin/_events.py`, `plugin/skills/mission/`, `scripts/test/mission-{tick,skill}.test.py` | yes | done: `mission-tick.test.py` check 30 (`--by` alone, a run-log-only or replayed lift, a negated line, another code, an old line and a line typed for an earlier block lift nothing; a far `--now` lifts no later goals; a fresh checkout keeps a lift), `mission-skill.test.py` check 8 | | M9.52 | `tick` reads a gap list only when it still recomputes from its inputs, as `evaluate check` does (an intact eval that a changed `compute`, an edited journey or goal no longer reproduces asks for `EVALUATE`). Reason: found in M9.27's review, `tick` reads the record, shape and seal but not the recomputation (the tick test's synthetic evals cannot recompute), so after an upgrade that changes `compute` `goal derive` refuses while `tick` hands out `DERIVE_GOAL` until it blocks | M9.27 | `plugin/mission/tick.py`, `mission-tick.test.py` (real evals in its synthetic sections) | yes | open | | M9.53 | `tick` hands out a goal's commands (`PLAN_INTENTS`, `SPRINT`, its close) only when `goal check` passes, else names the goal's problem. Reason: found in M9.27's review, a goal whose source eval changed or is gone (or one derived before evals were ledger records) gets `PLAN_INTENTS` 3 times while `goal intents` refuses, then `BLOCKED` with no cause named (M9.43 is one case of it) | M9.11, M9.28 | `plugin/mission/tick.py`, `mission-tick.test.py` | yes | open | diff --git a/docs/TRACKING.md b/docs/TRACKING.md index 08a86400..b13b52d5 100644 --- a/docs/TRACKING.md +++ b/docs/TRACKING.md @@ -94,7 +94,7 @@ Status of every requirement in [ROADMAP.md](ROADMAP.md), in the four states §8 | M9.44 | A goal is re-measured between its sprints | NOT_IMPLEMENTED | §4.12 | | M9.45 | A journey's runner has a named author | NOT_IMPLEMENTED | §4.12 | | M9.46 | `mission due` is the supervisor's, not a role's | NOT_IMPLEMENTED | §4.12 | -| M9.50 | A goal sprinted with gaps still open gets a next step | NOT_IMPLEMENTED | §4.12 | +| M9.50 | A goal sprinted with gaps still open gets a next step | IMPLEMENTED_TESTED | `scripts/test/mission-goal.test.py` | | M9.51 | Lifting a mission block is the human's typed line, kept in the ledger | IMPLEMENTED_TESTED | `scripts/test/mission-tick.test.py` | | M9.52 | The mission loop reads a gap list only when it still recomputes | NOT_IMPLEMENTED | §4.12 | | M9.53 | The mission loop hands out a goal's commands only when `goal check` passes | NOT_IMPLEMENTED | §4.12 | diff --git a/plugin/bin/_mission.py b/plugin/bin/_mission.py index 5517a981..0a57c877 100644 --- a/plugin/bin/_mission.py +++ b/plugin/bin/_mission.py @@ -242,11 +242,11 @@ def emit(cwd, event, role="", refs=None, event_id=None, **data): # a human decision that is not an approval: a veto, an opt-out, a door opened or closed (M9.30) 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, reviewed (a hard ethics line stays +# 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) LEDGER_EVENTS = HUMAN_EVENTS + ("baseline.measured", "state.assessed", "eval.completed", "journey.retired", - "ethics.reviewed", "ethics.blocked", "goal.derived", "goal.met", + "ethics.reviewed", "ethics.blocked", "goal.derived", "goal.met", "goal.retired", "mission.budget_exhausted", "door.crossed") diff --git a/plugin/bin/events b/plugin/bin/events index 269d6f58..60cef7e9 100755 --- a/plugin/bin/events +++ b/plugin/bin/events @@ -40,6 +40,7 @@ import _paths # noqa: E402 # events only their own command may write (ROADMAP §4.12): human decisions, the ethics and door gates' # records and the goal lineage (`events trace` and `mission goal close` read them) GATE_OWNED = set(_mission.HUMAN_EVENTS) | {"ethics.reviewed", "ethics.blocked", "goal.derived", "goal.met", + "goal.retired", # `mission goal retire` (M9.50) "door.denied", "door.crossed", # the door gate's own records (M9.30) "state.assessed", "eval.completed", # what goals are derived and closed from "intent.received"} # an intent's lineage (`intent new`) diff --git a/plugin/mission/README.md b/plugin/mission/README.md index 00b18aa5..9772abae 100644 --- a/plugin/mission/README.md +++ b/plugin/mission/README.md @@ -60,7 +60,7 @@ A gate checks structure and evidence, never whether a judgment is right. draft or changed since its newest approval. - **The ledger** `docs/agents/mission/ledger.jsonl` holds every record a gate decides from (`LEDGER_EVENTS`: the human decisions, `baseline.measured`, `journey.retired`, `ethics.reviewed`, - `ethics.blocked`, `goal.derived`, `goal.met`, `door.crossed`), committed with the artifacts. + `ethics.blocked`, `goal.derived`, `goal.met`, `goal.retired`, `door.crossed`), committed with the artifacts. `M.record(cwd, event, subject, role, **data)` appends one (and emits the event); `M.record_human` / `M.approve` are the human-only forms. The event stream is git-ignored run data, so a fresh checkout reads the ledger only. Each row carries the hash of the row it follows: an edited, removed, @@ -111,8 +111,8 @@ A gate checks structure and evidence, never whether a judgment is right. matches it, and the newest is the newest by the ledger's order. Every input is the content its record covers: the state a `state.assessed` ledger record (only `mission assess` measures), the baseline a confirmation, each journey the content the baseline froze, and the goal a `goal.derived` - or `goal.approved` record (the newest such goal with no later `goal.met` record is the active one; a - status field activates nothing) whose targets are criteria the baseline froze. Anything else blocks + or `goal.approved` record (the newest such goal with no later `goal.met` record, no `goal.retired` + record and no hard line is the active one; a status field activates nothing) whose targets are criteria the baseline froze. Anything else blocks `evaluate` and `evaluate check`. ## Notes for the tracks (from mapping the repo, 2026-10-20) @@ -186,7 +186,7 @@ loop to move on records them: | the baseline | as `baseline.py` decides it: `current` (the newest `baseline.confirmed` row), `measured_ok`, `vetoed`, `evaluate`; a replacement applies after the mission's `veto_window_h` from its `baseline.measured` row | | journeys defined | a journey that `journeys.lifecycle` does not call retired | | 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; status `derived` → `approved` → `active` (`goal intents` handed it to Aladdin) · `retired` · `blocked`; an eval narrowed to it (`goal_id`) decides its close | +| 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 the newest eval of it, made after the closes, still lists gaps); 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 | | 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/plugin/mission/evaluate.py b/plugin/mission/evaluate.py index eaaced00..06fbe28e 100644 --- a/plugin/mission/evaluate.py +++ b/plugin/mission/evaluate.py @@ -38,9 +38,9 @@ def active_goal(cwd): """The goal being worked, from the records: the newest goal whose current content a goal.derived (or the human's goal.approved) record covers, no later goal.met record closed and - no ethics hard line retired (M9.29: it never closes, so the next eval covers the whole mission - and the loop derives past it). A status field activates nothing. A goal (M9.11) names its - targets as [{"journey_id", "criterion_id"}].""" + nothing retired (an ethics hard line, M9.29, or `goal retire` once its sprints left gaps open, + M9.50: it never closes, so the next eval covers the whole mission and the loop derives past it). + A status field activates nothing. A goal (M9.11) names its targets as [{"journey_id", "criterion_id"}].""" best = None for path, d in M.artifacts(cwd, "goal"): ref, sha = M.rel(cwd, path), M.digest(d) @@ -53,8 +53,20 @@ def active_goal(cwd): def retired(cwd, goal): - """A goal an ethics hard line holds (the verdict's own rule: this goal, or its words under any id).""" - return isinstance(goal.get("goal_id"), str) and E.verdict(cwd, "goal", goal["goal_id"])[2].get("state") == "hard" + """A goal set aside: `goal retire` recorded it (M9.50), or an ethics hard line holds it (the + verdict's own rule: this goal, or its words under any id).""" + return isinstance(goal.get("goal_id"), str) and (bool(retirement(cwd, goal)) or + E.verdict(cwd, "goal", goal["goal_id"])[2].get("state") == "hard") + + +def retirement(cwd, goal): + """The goal.retired ledger record of this goal's content (`mission goal retire`: its intents were + all sprinted and an evaluation of it after them still listed gaps), or None.""" + if not isinstance(goal.get("goal_id"), str): + return None + sha = M.digest(goal) + return next((r for r in reversed(M.records(cwd, "goal.retired", M.rel(cwd, M.path_of(cwd, "goal", goal["goal_id"])))) + if r["data"].get("sha256") == sha), None) def goal_problems(cwd, goal, bdoc): diff --git a/plugin/mission/goal.py b/plugin/mission/goal.py index 42be70c7..5ac3ed4b 100644 --- a/plugin/mission/goal.py +++ b/plugin/mission/goal.py @@ -37,6 +37,12 @@ an active goal (sealed, as derived) and a recorded evaluation of it, newer than the goal, that says goal_met: status met, a goal.met ledger record (a goal already met: exit 0, no new record). Exit 2 while a target (or a regression) is still open, or for a goal that is not active + mission goal retire GOAL_ID --eval EVAL_ID + an active goal (sealed, as derived) whose every intent was sprinted (its sprints closed), and the + newest evaluation, of this goal, made after those closes, that still lists gaps: status retired, a + goal.retired ledger record + (a goal already retired: exit 0, no new record). `mission evaluate` then covers the whole + mission and a new goal is derived; a retired goal takes no more intents or sprints (M9.50) mission goal show GOAL_ID [--json] the goal, its check, and the principles block it carries """ @@ -170,6 +176,10 @@ def check(cwd, gid): facts = {"goal_id": gid, "path": M.rel(cwd, gpath), "status": g.get("status"), "autonomy": g.get("autonomy"), "sha256": sha, "ethics": None} blocks += derived_problems(cwd, g) if not blocks else [] + rec = EV.retirement(cwd, g) if not blocks else None + if rec: + blocks.append("goal %s was retired (eval %s still listed its gaps after every intent was sprinted): " + "derive another goal" % (gid, rec["data"].get("eval_id"))) if blocks: return 2, blocks, asks, facts mpath, m = mission_of(cwd) @@ -283,9 +293,10 @@ def cmd_derive(cwd, o): if edoc.get("goal_id"): gdoc, _ = M.load(M.path_of(cwd, "goal", edoc["goal_id"])) if isinstance(gdoc, dict) and EV.retired(cwd, gdoc): - report(["eval %s is narrowed to goal %s, which an ethics hard line has retired: run mission evaluate " - "(with no active goal it covers the whole mission), then derive from it" - % (edoc["eval_id"], edoc["goal_id"])], []) + report(["eval %s is narrowed to goal %s, which %s: run mission evaluate (with no active goal it covers " + "the whole mission), then derive from it" + % (edoc["eval_id"], edoc["goal_id"], "was retired with its gaps still open" + if EV.retirement(cwd, gdoc) else "an ethics hard line has retired")], []) else: report(["eval %s is narrowed to goal %s's targets (it was active): a new goal comes from an eval of the " "whole mission (close goal %s, then mission evaluate)" @@ -487,8 +498,8 @@ def cmd_next(cwd, gid): return r.returncode print(p) return 0 - print("[goal] every intent of %s has a plan; when its sprints close, evaluate and `mission goal close`" % gid, - file=sys.stderr) + print("[goal] every intent of %s has a plan; when its sprints close, evaluate: `mission goal close` if it is " + "met, else `mission goal retire`" % gid, file=sys.stderr) return 1 @@ -511,6 +522,9 @@ def cmd_close(cwd, gid, eid): if M.records(cwd, "goal.met", M.rel(cwd, gpath)): # the record decides, never the status field print("[goal] %s is already met" % gid, file=sys.stderr) return 0 + if EV.retirement(cwd, g): + report(["goal %s was retired: a retired goal never closes (derive another)" % gid], []) + return 2 if g["status"] != "active": report(["goal %s is %s: only an active goal closes (handed off with `mission goal intents`)" % (gid, g["status"])], []) @@ -539,6 +553,101 @@ def cmd_close(cwd, gid, eid): return 0 +def sprint_closes(cwd): + """{sprint number: close stamp} from `stats sprint-close`'s sprints.json, as `mission tick` reads it.""" + st, _ = M.load(os.path.join(_paths.home(cwd, "state", make=False), "sprints.json")) + out = {} + for c in st.get("closed") if isinstance(st, dict) and isinstance(st.get("closed"), list) else []: + try: + out[int(c.get("sprint"))] = c.get("at") + except (AttributeError, TypeError, ValueError): + continue + return out + + +def retire_problems(cwd, g, eid): + """(eval doc, eval.completed record, why goal g is not retired on eval eid yet) (ROADMAP M9.50), the + rule `mission tick` asks before it hands out RETIRE_GOAL: eid is the newest eval, narrowed to the goal + and not met, made after every one of the goal's intents was planned and its sprints closed.""" + import tick as T # noqa: E402 — the loop's own clocks, so the gate and the loop agree on "after" + gid = g["goal_id"] + doc, ev, bad = eval_record(cwd, eid) + if bad: + return doc, ev, bad + if doc.get("goal_id") != gid: + return doc, ev, ["eval %s is not an evaluation of goal %s (it evaluates %s): evaluate while the goal is " + "active" % (eid, gid, doc.get("goal_id") or "the whole mission")] + if doc["goal_met"]: + return doc, ev, ["goal %s is met in eval %s: close it (mission goal close %s --eval %s)" % (gid, eid, gid, eid)] + newest = latest_eval(cwd) + if newest != eid: + return doc, ev, ["eval %s is not the newest eval (%s is): retire on what the loop reads now" % (eid, newest)] + have = goal_intents(cwd, gid) + sprints = {} + for e in _events.read(cwd): + d = e.get("data") or {} + m = re.match(r"^S(\d+)$", str(d.get("sprint") or (e.get("ids") or {}).get("sprint") or "")) + if e.get("event") == "plan.created" and m: + sprints.setdefault(d.get("intent_id"), set()).add(int(m.group(1))) + unplanned = [gap["gap_id"] for gap in g["gaps"] if gap["gap_id"] not in have + or have[gap["gap_id"]][1].get("intent_id") not in sprints] + if unplanned: + return doc, ev, ["goal %s's gap %s has no plan yet (its intent is not sprinted): sprint every intent first " + "(mission goal next %s)" % (gid, ", ".join(unplanned), gid)] + closes = sprint_closes(cwd) + mine = sorted(set().union(*(sprints[have[gap["gap_id"]][1]["intent_id"]] for gap in g["gaps"]))) + open_ = [n for n in mine if n not in closes] + if open_: + return doc, ev, ["goal %s's sprint %d is not closed (`stats sprint-close`): retire after its sprints" + % (gid, open_[0])] + if T.ms_doc(doc, "eval") <= max(T.ms_end(closes[n]) or 0 for n in mine): + return doc, ev, ["eval %s was made before goal %s's last sprint closed: assess and evaluate after its sprints" + % (eid, gid)] + return doc, ev, [] + + +def cmd_retire(cwd, gid, eid): + """Set aside an active goal whose sprints left its gaps open (ROADMAP M9.50): a goal.retired ledger + record, so `mission evaluate` covers the whole mission again and the loop derives past it.""" + gpath = M.path_of(cwd, "goal", gid) + g, _ = M.load(gpath) + if not isinstance(g, dict): + report(["no goal %s" % gid], []) + return 2 + try: + bad = list(M.problems(g, "goal", gpath)) + except ValueError as e: + bad = ["goal %s cannot be hashed (%s)" % (gid, e)] + bad = bad or derived_problems(cwd, g) + if bad: + report(bad, []) + return 2 + if M.ledger_block(cwd, "goal"): + return 2 + if EV.retirement(cwd, g): + print("[goal] %s is already retired" % gid, file=sys.stderr) + return 0 + if M.records(cwd, "goal.met", M.rel(cwd, gpath)): + report(["goal %s is met: a met goal is never retired" % gid], []) + return 2 + if g["status"] != "active": + report(["goal %s is %s: only an active goal is retired (handed off with `mission goal intents`, every " + "intent sprinted)" % (gid, g["status"])], []) + return 2 + doc, ev, bad = retire_problems(cwd, g, eid) + if bad: + report(bad, []) + return 2 + g["status"] = "retired" + M.save(gpath, g) + still = [x.get("gap_id") for x in doc["gaps"] if isinstance(x, dict)] + M.record(cwd, "goal.retired", M.rel(cwd, gpath), "mission-planner", goal_id=gid, eval_id=eid, + eval_event=ev.get("event_id"), sha256=M.digest(g), open=still) + print("[goal] %s retired with %d gap(s) still open (eval %s): evaluate the whole mission and derive another" + % (gid, len(still), eid), file=sys.stderr) + return 0 + + def cmd_show(cwd, gid, as_json): g, _ = M.load(M.path_of(cwd, "goal", gid)) if not isinstance(g, dict): @@ -586,9 +695,9 @@ def main(argv, cwd): return cmd_options(cwd, o) if cmd == "derive": return cmd_derive(cwd, o) - if cmd not in ("check", "approve", "intents", "next", "close", "show"): - print("mission goal: unknown command %r (options, derive, check, approve, intents, next, close, show)" % cmd, - file=sys.stderr) + if cmd not in ("check", "approve", "intents", "next", "close", "retire", "show"): + print("mission goal: unknown command %r (options, derive, check, approve, intents, next, close, retire, show)" + % cmd, file=sys.stderr) return 64 if not pos or not GOAL_ID.match(pos[0]): print("mission goal %s GOAL_ID (gol_…)" % cmd, file=sys.stderr) @@ -616,4 +725,9 @@ def main(argv, cwd): print("mission goal close GOAL_ID --eval EVAL_ID", file=sys.stderr) return 64 return cmd_close(cwd, gid, o["eval"]) + if cmd == "retire": + if not o.get("eval"): + print("mission goal retire GOAL_ID --eval EVAL_ID", file=sys.stderr) + return 64 + return cmd_retire(cwd, gid, o["eval"]) return cmd_show(cwd, gid, o.get("json")) diff --git a/plugin/mission/tick.py b/plugin/mission/tick.py index 310921cf..7ac46575 100644 --- a/plugin/mission/tick.py +++ b/plugin/mission/tick.py @@ -39,6 +39,9 @@ ASSESS state-assessor no state report since the baseline, the last sprint, or the cadence EVALUATE evaluator the latest eval is older than the state, research, journeys or baseline DERIVE_GOAL mission-planner the latest eval shows gaps and no goal is in flight + RETIRE_GOAL mission-planner every intent of the goal was sprinted and the newest eval, narrowed + to it and made after its sprints closed, still lists its gaps + (`mission goal retire` would accept it; else BLOCKED, its reason) WAIT — a sprint is running; or the raised bar is still met Facts, never a model's word: `mission check`; artifact status, harness ids (their time) and @@ -55,8 +58,9 @@ re-derived; one rule with the gate: a hard line follows its words to any goal, a review edited after it was recorded is broken), and a committed review of tier hard, so a checkout without the run log fails closed; a gap list -only with its eval.completed record (its `goal_met` and gaps); a goal only with its goal.derived (or goal.approved) record, closed by goal.met, and an -eval narrowed to it (goal_id) decides its close (`aloop mission goal close`); Aladdin's intent, +only with its eval.completed record (its `goal_met` and gaps); a goal only with its goal.derived (or goal.approved) record, closed by goal.met or set +aside by goal.retired, and an eval narrowed to it (goal_id) decides its close or retirement (`aloop mission goal +close`, `retire`); Aladdin's intent, plan and sprint events and .aladdin/state/sprints.json; the sprint lock; and the token ledger (/ledger/). A goal's sprints are planned from its intents (intent.received goal_id → plan.created intent_id), else since the loop handed out its SPRINT. A stamp kept to @@ -98,7 +102,8 @@ "OFFER_OPTIONS": ("human", ["mission-planner"]), "PLAN_INTENTS": ("role", ["mission-planner"]), "SPRINT": ("supervisor", []), "APPROVE_PLAN": ("human", []), "ASSESS": ("role", ["state-assessor"]), "EVALUATE": ("role", ["evaluator"]), - "DERIVE_GOAL": ("role", ["mission-planner"]), "WAIT": ("none", []), + "DERIVE_GOAL": ("role", ["mission-planner"]), "RETIRE_GOAL": ("role", ["mission-planner"]), + "WAIT": ("none", []), } EXIT = {"role": 0, "supervisor": 0, "human": 3, "none": 4} MAX_HANDOUTS = 3 # the same action in a row without a result, then BLOCKED (a retry is not progress) @@ -293,7 +298,7 @@ def rel(p): # decides, so restoring content an older approval covered is a rollback, not approved raw, _ = M.ledger_rows(cwd) rows = sorted(raw, key=lambda r: r["ts"]) # the core's order: a union merge interleaves branches - assessed, born, met = {}, {}, {} + assessed, born, met, retired = {}, {}, {}, set() f["lifted"], f["lifts"], f["stops"] = {}, {}, {} for r in rows: name, d = r["event"], r["data"] @@ -303,6 +308,8 @@ def rel(p): born.setdefault((d.get("subject"), d.get("sha256")), []).append(r["ts"]) if name == "goal.met": met.setdefault(d.get("subject"), []).append(r["ts"]) + if name == "goal.retired": # `mission goal retire` set it aside (M9.50) + retired.add((d.get("subject"), d.get("sha256"))) if name == "mission.budget_exhausted": # the loop stopped at a cap for this content f["stops"].setdefault(d.get("sha256"), d) if name == "mission.lifted" and r.get("role") == "human" and str(d.get("by") or "").strip() \ @@ -327,7 +334,8 @@ def rel(p): f["kinds"]["eval"] = [evals[r] for r in order if r in evals] # a goal is one `mission goal derive` recorded (goal.derived, or the human's goal.approved, for # its content) and it is closed by its goal.met record, as `mission evaluate` reads them - f["kinds"]["goal"] = [dict(a, met=any(t >= max(born[(a["ref"], a["sha"])]) for t in met.get(a["ref"], []))) + f["kinds"]["goal"] = [dict(a, met=any(t >= max(born[(a["ref"], a["sha"])]) for t in met.get(a["ref"], [])), + retired=(a["ref"], a["sha"]) in retired) for a in f["kinds"]["goal"] if (a["ref"], a["sha"]) in born] # fail closed: a committed hard review holds on a checkout without the run log (ROADMAP M9.24); # every other ethics fact is `mission ethics`'s verdict (ethics_of) @@ -461,9 +469,9 @@ def failed_goals(f): if g["ms"] <= f["reset_at"]: break hard = ethics_of(f, "goal", g)[0] == "hard" - if not hard and g["status"] not in ("blocked", "retired"): + if not hard and not g["retired"] and g["status"] not in ("blocked", "retired"): break - out.append((g, "crosses a hard line" if hard else "was %s" % g["status"])) + out.append((g, "crosses a hard line" if hard else "was retired" if g["retired"] else "was %s" % g["status"])) return out @@ -527,7 +535,7 @@ def rules(f): if b: return b g = latest(f, "goal") - if g and not g["met"] and g["status"] not in ("blocked", "retired"): + if g and not g["met"] and not g["retired"] and g["status"] not in ("blocked", "retired"): r = goal_rule(f, g, mode, now, cad) if r: return r @@ -719,9 +727,17 @@ def goal_rule(f, g, mode, now, cad): if done and not left: s = latest(f, "state") if mine and mine["ms"] > max(f["closed"][n] for n in done) and (not s or mine["ms"] >= s["ms"]): - return act("BLOCKED", "goal %s's intents were all sprinted and eval %s still lists %d gap(s) of it: the " - "human decides (a goal that is not met is never closed: ROADMAP M9.50)" - % (g["id"], mine["id"], len(mine["doc"].get("gaps") or [])), g["ref"], pin=mine["id"]) + import goal as G # noqa: E402 — the gate's own rule (ROADMAP M9.50), so the loop and it agree + why = G.retire_problems(f["cwd"], g["doc"], mine["id"])[2] + if why: + return act("BLOCKED", "goal %s's intents were all sprinted and eval %s still lists its gaps, but " + "`mission goal retire` refuses (%s): the human looks" % (g["id"], mine["id"], why[0]), + g["ref"], pin=mine["id"]) + return act("RETIRE_GOAL", "goal %s's intents were all sprinted and eval %s still lists %d gap(s) of it: " + "retire it (aloop mission goal retire %s --eval %s), then evaluate the whole " + "mission and derive the next goal" + % (g["id"], mine["id"], len(mine["doc"].get("gaps") or []), g["id"], mine["id"]), + g["ref"], pin=mine["id"]) return None # every intent sprinted and closed: assess and evaluate since = max([f["closed"][n] for n in done] + [sprint_handout(f, g) or 0, g["ms"]]) if f["lock"] and f["lock"] > since: @@ -764,7 +780,7 @@ def cycle(f, now, cad): s, e, r, j = latest(f, "state"), latest(f, "eval"), latest(f, "research"), latest(f, "journey") fails = failed_goals(f) if len(fails) >= MAX_GOALS: - return act("BLOCKED", "%d goals in a row were blocked or crossed a hard line (latest: %s): the human looks; " + return act("BLOCKED", "%d goals in a row were blocked, retired or crossed a hard line (latest: %s): the human looks; " "`aloop mission tick --force --by NAME` lets the loop derive again" % (len(fails), fails[0][0]["id"]), fails[0][0]["ref"], grant="GOALS") closes = sorted((t, n) for n, t in f["closed"].items()) @@ -790,6 +806,10 @@ def cycle(f, now, cad): return act("EVALUATE", "goal %s crossed a hard line, so it is retired and eval %s, narrowed to it, says " "nothing: evaluate the whole mission (aloop mission evaluate)" % (gid, e["id"]), e["ref"]) + if g and not g["met"] and g["retired"]: + return act("EVALUATE", "goal %s was retired with its gaps still open, so eval %s, narrowed to it, says " + "nothing: evaluate the whole mission (aloop mission evaluate)" % (gid, e["id"]), + e["ref"]) if not g or g["met"]: return act("EVALUATE", "eval %s was narrowed to goal %s, which is closed: evaluate the whole mission " "(aloop mission evaluate)" % (e["id"], gid), e["ref"]) diff --git a/plugin/skills/mission/SKILL.md b/plugin/skills/mission/SKILL.md index f39daa2f..ceb3cf58 100644 --- a/plugin/skills/mission/SKILL.md +++ b/plugin/skills/mission/SKILL.md @@ -19,7 +19,8 @@ do exactly the action it names, and tick again. *Models explore. Gates decide.* The loop is IBM's autonomic MAPE-K over `docs/agents/mission/`: monitor (ASSESS), analyze (EVALUATE), plan (DERIVE_GOAL, PLAN_INTENTS), execute (SPRINT, an Aladdin sprint). A met goal -sends it back to the mission to raise the bar. Every command is `aloop mission …`; each +sends it back to the mission to raise the bar; a goal its sprints did not meet is retired +(RETIRE_GOAL) and the next one is derived. Every command is `aloop mission …`; each area explains itself with `aloop mission --help`, and `aloop mission --list` lists them. ## Setting a mission (first run only) @@ -84,6 +85,7 @@ paste artifacts into it. A role writes its artifact only through `aloop mission | `ASSESS` | `state-assessor` | Measure the product with the pinned scripts; numbers only, no opinions (`aloop mission assess`). | a new state report | | `EVALUATE` | `evaluator` | Compare the state with the baseline and the rivals: the gap list and `goal_met` (`aloop mission evaluate`); it never builds. A goal met in its eval: `aloop mission goal close --eval `. | a new eval, or a closed goal | | `DERIVE_GOAL` | `mission-planner` | The eval's top gaps become one goal, with the standing principles for the mode (`aloop mission goal derive`). | a derived goal | +| `RETIRE_GOAL` | `mission-planner` | Every intent of the goal was sprinted and the newest eval of it still lists gaps: set it aside (`aloop mission goal retire --eval `); the next eval covers the whole mission and another goal is derived. | a `goal.retired` record | | `WAIT` | — | A sprint is running, planning is under way, or the raised bar is still met. Stop. | the cron wakes the loop | Usage telemetry (Google Analytics) is opt-in (`aloop mission telemetry`): it feeds research diff --git a/scripts/test/mission-goal.test.py b/scripts/test/mission-goal.test.py index 4208b470..e7d1af11 100644 --- a/scripts/test/mission-goal.test.py +++ b/scripts/test/mission-goal.test.py @@ -14,12 +14,14 @@ import shutil import subprocess import sys +import time sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), "fixtures")) from mission_fixture import ASKED, Project, M, BIN # noqa: E402 sys.path.insert(0, M.AREAS_DIR) import _events # noqa: E402 +import _paths # noqa: E402 import ethics as E # noqa: E402 import evaluate as EV # noqa: E402 import goal as G # noqa: E402 @@ -431,10 +433,69 @@ def setup(mode, extra=()): json.dump(it, open(paths[0], "w")) ok("intent: a mission intent names its goal and gap, passes the goal's gate, and is checked in the goal's autonomy") -# 13) the area is discovered; --help is the docstring +# 13) retire (M9.50): an active goal whose every intent was sprinted, and whose newest evaluation, made after +# its sprints closed, still lists its gaps, is set aside by a goal.retired ledger record (the planner's): `mission evaluate` +# then covers the whole mission and a new goal is derived; a retired goal takes no more intents or sprints +p4, (k1, _), ek = setup("autonomous") +assert review(p4, "mission").returncode == 0 +gk = made(p4.run("goal", "derive"))["goal_id"] +assert review(p4, gk).returncode == 0 +r = p4.run("goal", "retire", gk, "--eval", ek["eval_id"]) +assert r.returncode == 2 and "only an active goal" in r.stderr, r.stderr +assert p4.run("goal", "retire", gk).returncode == 64 +assert len(p4.run("goal", "intents", gk).stdout.split()) == 2 +ek2 = evaluate(p4) +assert ek2["goal_id"] == gk and not ek2["goal_met"] +r = p4.run("goal", "retire", gk, "--eval", ek2["eval_id"]) +assert r.returncode == 2 and "has no plan yet" in r.stderr, r.stderr # sprint every intent first +for n in (1, 2): + path = p4.run("goal", "next", gk).stdout.strip() + _events.emit(p4.dir, "plan.created", role="planner", sprint="S%d" % n, intent_id=json.load(open(path))["intent_id"]) +r = p4.run("goal", "retire", gk, "--eval", ek2["eval_id"]) +assert r.returncode == 2 and "sprint 1 is not closed" in r.stderr, r.stderr # its sprints still run +closes = os.path.join(_paths.home(p4.dir, "state"), "sprints.json") +stamp = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()) +json.dump({"closed": [{"sprint": 1, "at": stamp}]}, open(closes, "w")) +r = p4.run("goal", "retire", gk, "--eval", ek2["eval_id"]) +assert r.returncode == 2 and "sprint 2 is not closed" in r.stderr, r.stderr +json.dump({"closed": [{"sprint": 1, "at": stamp}, {"sprint": 2, "at": stamp}]}, open(closes, "w")) +r = p4.run("goal", "retire", gk, "--eval", ek2["eval_id"]) +assert r.returncode == 2 and "before" in r.stderr and "evaluate" in r.stderr, r.stderr # it predates the closes +r = p4.run("goal", "retire", gk, "--eval", ek["eval_id"]) +assert r.returncode == 2 and "not an evaluation of goal" in r.stderr, r.stderr +time.sleep(1.05) # a close stamp keeps the second: after it is the next one +ek3 = evaluate(p4) +assert ek3["goal_id"] == gk and not ek3["goal_met"] +r = p4.run("goal", "retire", gk, "--eval", ek2["eval_id"]) +assert r.returncode == 2 and "not the newest eval" in r.stderr, r.stderr # the loop reads ek3 now +r = p4.run("goal", "retire", gk, "--eval", ek3["eval_id"]) +assert r.returncode == 0, r.stderr +gkref = M.rel(p4.dir, p4.path("goal", gk)) +recs = M.records(p4.dir, "goal.retired", gkref) +assert len(recs) == 1 and recs[0]["role"] == "mission-planner" and recs[0]["data"]["eval_id"] == ek3["eval_id"], recs +assert recs[0]["data"]["sha256"] == M.digest(p4.load("goal", gk)) and p4.load("goal", gk)["status"] == "retired" +assert recs[0]["data"]["open"] == [x["gap_id"] for x in ek3["gaps"]], recs[0]["data"] +r = p4.run("goal", "retire", gk, "--eval", ek3["eval_id"]) +assert r.returncode == 0 and len(M.records(p4.dir, "goal.retired", gkref)) == 1, r.stderr # once +for args in (("next", gk), ("intents", gk), ("check", gk), ("close", gk, "--eval", ek3["eval_id"])): + r = p4.run("goal", *args) + assert r.returncode == 2 and "retired" in r.stderr, (args, r.returncode, r.stderr) +r = p4.run("goal", "derive") +assert r.returncode == 2 and "was retired with its gaps still open" in r.stderr, r.stderr # the eval narrowed to it +assert EV.active_goal(p4.dir) is None +ek4 = evaluate(p4) +assert ek4["goal_id"] is None +assert made(p4.run("goal", "derive"))["goal_id"] != gk +r = tool(p4, EVENTS, "emit", "goal.retired", "--data", "goal_id=%s" % gk) +assert r.returncode == 64 and "only its own command" in r.stderr, r.stderr +ok("retire: an active goal whose intents were all sprinted (sprints closed) and whose newest evaluation, made after " + "the closes, still lists gaps is retired by a goal.retired record (once); it takes no more work, and the whole " + "mission is evaluated and derived again") + +# 14) the area is discovered; --help is the docstring assert "goal" in p.run("--list").stdout.split() and "Aladdin handoff" in p.run("goal", "--help").stdout assert p.run("goal", "nope").returncode == 64 and p.run("goal", "check").returncode == 64 -for x in (p, s, h): +for x in (p, s, h, p4): shutil.rmtree(x.dir, ignore_errors=True) ok("discovered as an area; usage errors are 64") diff --git a/scripts/test/mission-tick.test.py b/scripts/test/mission-tick.test.py index 9cc4d0ae..cfef4241 100755 --- a/scripts/test/mission-tick.test.py +++ b/scripts/test/mission-tick.test.py @@ -9,6 +9,7 @@ """ import contextlib import fcntl +import glob import io import json import os @@ -1029,8 +1030,8 @@ def pick(doc, hours, eid): # 27) goals through `aloop mission goal`, on the real clock: derive → review → intents → next and a sprint per # intent → evaluate (narrowed to the goal) → close → evaluate the whole mission; a goal file nobody derived -# is no goal; a goal whose sprints all closed with gaps open, or that crossed a hard line while evaluate -# still narrows to it, is the human's +# is no goal; a goal whose sprints all closed with gaps open is the planner's to retire (M9.50), and one +# that crossed a hard line while evaluate still narrows to it is retired (M9.29) def later(p): time.sleep(1.05) # stamps are kept to the second return (time.time() * 1000 - p.t0) / H @@ -1060,8 +1061,9 @@ def later(p): expect(p.tick(later(p)), "ASSESS", 0, "sprint 2 closed") assert p.mi("assess").returncode == 0 expect(p.tick(later(p)), "EVALUATE", 0) -assert p.mi("evaluate").returncode == 0 # narrowed to the goal: not met -expect(p.tick(later(p)), "BLOCKED", 2, "M9.50") +r = p.mi("evaluate") # narrowed to the goal: not met +expect(p.tick(later(p), "--peek"), "RETIRE_GOAL", 0, "aloop mission goal retire %s --eval %s" + % (gid, json.load(open(r.stdout.strip()))["eval_id"])) p.app(**PASSING) assert p.mi("assess").returncode == 0 expect(p.tick(later(p)), "EVALUATE", 0) @@ -1096,7 +1098,7 @@ def later(p): assert s.mi("assess").returncode == 0 and s.mi("evaluate").returncode == 0 expect(s.tick(later(s)), "OFFER_OPTIONS", 3, "aloop mission goal options") ok("goals run through `aloop mission goal` (derive, intents, next, close) and the loop names each command; a " - "goal file nobody derived is none; open gaps after every sprint go to the human; a hard-lined goal is retired " + "goal file nobody derived is none; open gaps after every sprint: retire it; a hard-lined goal is retired " "and the loop derives another (M9.29); spoon-fed offers the gap list") # 28) discovery and help: the three areas are found by name @@ -1311,4 +1313,56 @@ def lifts(p): "or an edited one says nothing, and the loop, `evaluate check` and `goal` take the newest intact one by the " "ledger's order; on a fresh checkout they, `goal derive` and `goal close` read the same records") +# 32) a goal whose intents were all sprinted and whose evaluation still lists its gaps is retired (M9.50): the +# planner's `goal retire` records goal.retired in the ledger, the loop evaluates the whole mission and +# derives past it (the retired goal counts as a failed one, 3 in a row are the human's), and a fresh +# checkout keeps the retirement +p = Project().init() +cleared(p) +assert p.mi("assess").returncode == 0 and p.mi("evaluate").returncode == 0 +gid = json.load(open(p.mi("goal", "derive").stdout.strip()))["goal_id"] +p.review(p.ref("goal", gid), p.load("goal", gid), "clear") +assert p.mi("goal", "intents", gid).returncode == 0 +n = 0 +while True: + r = p.mi("goal", "next", gid) + if r.returncode == 1: + break + assert r.returncode == 0, r.stderr + n += 1 + p.event("plan.created", later(p), sprint="S%d" % n, intent_id=json.load(open(r.stdout.strip()))["intent_id"]) + p.sprint_closed(n, later(p)) +assert n == len(p.load("goal", gid)["gaps"]) > 0 +later(p) # the close keeps its second: assess after it +assert p.mi("assess").returncode == 0 +expect(p.tick(later(p)), "EVALUATE", 0) +eid = json.load(open(p.mi("evaluate").stdout.strip()))["eval_id"] +d = p.tick(later(p)) +expect(d, "RETIRE_GOAL", 0, "aloop mission goal retire %s --eval %s" % (gid, eid)) +assert d["roles"] == ["mission-planner"] and d["who"] == "role", d +ip = sorted(glob.glob(os.path.join(p.dir, "docs", "agents", "intents", "int_*.json")))[0] +os.rename(ip, ip + ".aside") # the gate refuses: the loop says why +expect(p.tick(later(p), "--peek"), "BLOCKED", 2, "`mission goal retire` refuses") +assert "has no plan yet" in p.tick(later(p), "--peek")["reason"] +os.rename(ip + ".aside", ip) +r = p.mi("goal", "retire", gid, "--eval", eid) +assert r.returncode == 0, r.stderr +assert [x["data"]["eval_id"] for x in M.ledger_rows(p.dir)[0] if x["event"] == "goal.retired"] == [eid] +expect(p.tick(later(p)), "EVALUATE", 0, "retired") # its narrowed eval says nothing now +assert p.mi("evaluate").returncode == 0 +expect(p.tick(later(p), "--peek"), "DERIVE_GOAL", 0, "goal %s was retired" % gid) +shutil.rmtree(os.path.join(p.dir, ".aladdin")) # a fresh checkout keeps the retirement +expect(p.tick(later(p), "--peek"), "DERIVE_GOAL", 0, "goal %s was retired" % gid) +w = Project().init() # 3 retired goals in a row: the human's +cleared(w) +w.art("state", "recorded", 1) +w.art("eval", "recorded", 1.1, goal_met=False) +for h in (1.2, 1.4, 1.6): + g, gd = w.art("goal", "active", h) # its status says active; the record decides + with w.clock(h + 0.05): + M.record(w.dir, "goal.retired", w.ref("goal", g), "mission-planner", goal_id=g, sha256=M.digest(gd)) +expect(w.tick(1.7), "BLOCKED", 2, "3 goals") +ok("a goal sprinted with gaps still open is the planner's to retire: a goal.retired ledger record, then the whole " + "mission is evaluated and another goal derived (a fresh checkout keeps it); 3 retired in a row are the human's") + print("mission-tick: %d checks passed" % PASS[0]) From 6a35eefe766f2fff4a4bb34bc0f30e299dce2c8f Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Tue, 20 Oct 2026 13:23:30 +0000 Subject: [PATCH 2/4] Retire only on a fresh eval of every intent's closed sprints; hold the gaps it tried (M9.50 review) An adversarial review of the first commit found these, each reproduced: - A retirement could be made from a state measured before the sprints closed, or from an eval older than the newest state. Now the eval must be computed from the newest state report, and that state must be measured after the last close. Tick maps the gate's refusal to ASSESS or EVALUATE. - A second intent for a gap, still sprinting, was not counted. Now every intent of the goal counts, the same set tick reads. - The planner's stop gate refused every retirement. The goal check now reports `retired` as the planner's finding (roles.json verdicts). - The next goal re-derived the same gaps. A retired goal's open gaps are now held on that baseline until a new version or the human's next approval of the mission. - evaluate fell back to an older goal nobody works. active_goal is now only ever the newest goal. - The record is written before the status, and a bare `retired` status is repaired, never trusted (tick reads the record). - Malformed run-log lines and sprints.json rows no longer crash tick or retire. - Tick now asks the whole rule (derived content, status, met), not part of it. Tests pin each rule (goal check 13, tick checks 28 and 33, roles). M9.54 records the remaining one-goal-in-flight gap. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Aw6CiQcdpzdzZZXKf8WbUM --- CHANGELOG.md | 2 +- docs/ROADMAP.md | 3 +- docs/TRACKING.md | 1 + plugin/mission/README.md | 2 +- plugin/mission/evaluate.py | 15 ++- plugin/mission/goal.py | 186 ++++++++++++++++++++--------- plugin/mission/roles.json | 2 +- plugin/mission/tick.py | 49 +++++--- plugin/skills/mission/SKILL.md | 4 +- scripts/test/mission-goal.test.py | 103 ++++++++++++---- scripts/test/mission-roles.test.py | 21 +++- scripts/test/mission-tick.test.py | 27 ++++- 12 files changed, 298 insertions(+), 117 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63d7a13d..ce48e83f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +27,7 @@ tag in lockstep. Tag releases as `vMAJOR.MINOR.PATCH`. - Core agent principles and the one-way / two-way door rule (ROADMAP §4.12, M9.30): seven core principles from Amazon's Leadership Principles, the door rule first, go to every aloop agent at session start (`aloop mission principles show --core`). A two-way door (a branch, a local edit, a test, a draft PR) is decided, not asked. A one-way door (`aloop mission doors list`: a push or merge to the default branch, a force-push, a release, a deploy, a message sent outside, a secret, dropped data, …) is stopped by a PreToolUse gate with `ASK[door] ` until the human records an authorization in their own terminal (`aloop mission doors authorize ID --by NAME --reason TEXT [--until DATE] [--once DIGEST]`, a hash-chained ledger row); a wall (switching a gate off, forging a human record) is never crossed. While a run is live, a question to the human must name a door the gate stopped and nobody authorized. Reason: Adeel's request that agents decide two-way doors themselves and ask only at a one-way door not already authorized. Test: `mission-doors.test.py`. Hardened by an adversarial review (15 findings, each a test): the gate reads Bash as the shell does (comments, line continuations, heredoc bodies, `xargs`, `find -exec`, `echo … | sh`), a branch condition reads the directory the command acts on (`git -C`, `cd`), settings are guarded wherever they live, dry runs and `command -v` are two-way, the newest decision by time counts and a revoke holds on every branch, a once-grant is crossed once under a lock, a broken ledger is named, and `doors authorize` refuses an agent's shell. - DeepSeek Harness (dsh) host (ROADMAP §4.9): `aloop install dsh` (alias `deepseek`; `--project P` or `--global`) renders a `dsh --profile aloop` profile in `$DSH_HOME` and installs the skills. Its native plugin (`plugin/hosts/dsh/aloop.mjs`) runs the same gates as Claude Code on dsh's own events: a deny before a tool runs, a block after an invalid artifact write, and a stop gate that steers a role back up to 3 times before the supervisor is told it is BLOCKED (or STUCK, released unverified). Roles are agent presets on two subagent tools, one per model route (`deepseek-v4-pro` for planning, `deepseek-flash` for work by default; `MODEL_PLANNING_DSH` / `MODEL_WORKER_DSH` override). A writer's `aloop bind` moves its working directory into its worktree, and `host-adapter` confines its commands, edits and `working_directory` there. Usage is recorded Claude-shaped per role, so budgets, the ledger and `run-summary` work unchanged. `make e2e-live HOST=dsh` drives it live and exits 2 with the fix when no `DEEPSEEK_API_KEY` is set. Reason: DeepSeek's own harness is the cheapest route to a strong model. The profile records the project it serves (or `--global`), so another project's `aloop-init` never re-renders it, and gates get the worker shell's environment (no API key). The mission layer's six roles run on dsh too: presets on their route group's subagent tool, `gate-mission-scope` on every write and command, and `gate-mission-artifact` at each role's start and stop; the mission skill installs as `aloop-mission`. A second review (3 lenses; 11 confirmed findings, each fixed with a test) closed: a working directory that vanished (dsh's tools move it back to the main tree, so the plugin judges `ensure()`'s directory and `host-adapter` refuses to run from a missing one), gate switches from the project's `.env` (dsh loads it; `SKIP_HOOKS`, `GATE_RUN_TESTS`, `REPO_DIR`, `AGENTIC_*` from it never reach a gate), an interrupted Stop that dropped the sprint-close notice, and the shared profile: its owner is the main tree, an older unrecorded profile is claimed only by the project that installed it, and a project it does not serve is told so by `install status`, `aloop-init` and the session itself. Tests: `dsh-plugin.test.mjs` (40 checks, emulated), `dsh-runtime.test.mjs` (32 checks on the real pinned dsh 0.2.1-rc.2 with a scripted model; the CI hosts job installs it) and `dsh-install.test.py` (9). - Brand kit and repo front page: `docs/brand/` holds the mark (an **a** whose bowl is a red-to-green loop passing a gold gate, with a 16 px cut), lockups, light and dark README banners, favicons, app icons, the site's OG card and the GitHub social preview, all generated by `docs/brand/gen_brand.py` from one palette with WCAG checks (rules in `docs/brand/README.md`). The README leads with the mission layer, the agent principles and the door rule, the supported hosts and the measured demo runs; the site carries the favicon and Open Graph/Twitter card metadata; `SECURITY.md` and bug/feature issue forms are new. -- A goal its sprints did not meet is retired, and the loop moves on (ROADMAP §4.12, M9.50): `aloop mission goal retire GOAL --eval EVAL` records `goal.retired` in the committed ledger once every intent of the goal was sprinted, its sprints closed and the newest eval of it, made after those closes, still lists gaps. A retired goal takes no more intents, sprints or close, `mission evaluate` covers the whole mission again and the next goal is derived. `mission tick` hands this out as `RETIRE_GOAL` (role `mission-planner`) where it used to stop at `BLOCKED` for the human, and asks the command's own rule first; 3 retired goals in a row still go to the human. Tests: `mission-goal` check 13, `mission-tick` checks 28 and 33. +- A goal its sprints did not meet is retired, and the loop moves on (ROADMAP §4.12, M9.50): `aloop mission goal retire GOAL --eval EVAL` records `goal.retired` in the committed ledger once every intent of the goal was sprinted and its sprints closed, and the newest eval of it, made after those closes from a state measured after them, still lists gaps. A retired goal takes no more intents, sprints or close. `mission evaluate` covers the whole mission again, and the retired goal's open gaps are held from the next goal until a new baseline version or the human's next approval of the mission, so the loop does not sprint the same gaps again. `mission tick` hands this out as `RETIRE_GOAL` (role `mission-planner`) where it used to stop at `BLOCKED` for the human. It asks the command's own rule first: a stale state or eval becomes `ASSESS` or `EVALUATE`, and any other refusal is `BLOCKED` with its reason. 3 retired goals in a row still go to the human. The planner's stop takes a retired goal as its finding. Tests: `mission-goal` check 13, `mission-tick` checks 28 and 33, `mission-roles`. - A mission's gap lists count only as `mission evaluate` computed them (ROADMAP §4.12, M9.27): `evaluate` records `eval.completed` in the committed ledger, and `mission tick`, `evaluate check` and `goal` take the newest eval whose content that record covers, with a matching seal, in the ledger's order. An eval file written by hand, or edited (or re-stamped) after it was recorded, no longer sends the loop to `RESEARCH` as "goal met" or makes `goal derive` refuse what tick handed out, a clock that is behind no longer reorders them, and a fresh checkout derives and closes goals from the evals it committed. An eval or state named as journey or baseline evidence needs its record too. Tests: `mission-tick` check 32, `mission-journeys`. - A mission's stop at a spend cap holds on a fresh checkout (ROADMAP §4.12, M9.24): the first `STOP_BUDGET` tick records a `mission.budget_exhausted` ledger row for the mission's content (once per content), and `mission tick` stops on it whatever the checkout's token ledger says, until a raised cap changes the content. - Lifting a mission block is the human's own words (ROADMAP §4.12, M9.51): `aloop mission tick --force --by` now asks (exit 3) for the human's typed `lift ` line, the code bound to this occurrence of that block, and records a `mission.lifted` ledger row, so `--by` alone, a lift only the run log has (or a replayed one), an old line or a line typed for an earlier block lift nothing, a lift of 3 failed goals reaches only those goals whatever `--now` says, and a fresh checkout keeps a lifted block lifted. `/aloop:mission` counts a lift among the typed grants it relays. A lift recorded before this (run data only) no longer counts. diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 78bf13e7..4ed9fbf7 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -483,10 +483,11 @@ Each task flips only its own row here and in TRACKING.md. | M9.45 | DEFINE_JOURNEYS names who writes a journey's runner (the program its pinned `runner.command` runs) and where it lives, and the journey check refuses a runner that does not exist yet. Reason: found designing the live run (M9.13), `market-researcher.md` derives the steps and pass criteria, `state-assessor.md` runs the pinned runner, and no persona or prompt says who writes it | M9.3, M9.9 | `plugin/agents/market-researcher.md`, `plugin/mission/journeys.py`, `mission-journeys.test.py` | yes | open | | M9.46 | `aloop mission due` is not read-only for a dispatched agent: it records the handout tick of a human action, so only the supervisor or the cron may run it (or `due --peek` for anyone). Reason: found designing the live run (M9.13), `roles.json` lists `due` as read-only, so a builder's `aloop mission due` marks a BLOCKED or STOP_BUDGET as told inside its own transcript and the cron stays silent | M9.8, M9.9 | `plugin/mission/roles.json`, `plugin/bin/gate-mission-scope`, `mission-scope-bash.test.py` | yes | open | | M9.47 | Computed command text: a `$VAR` program or argument (`M=npm; $M publish`, `B=main; git push origin $B`), `eval "$X"`, `sh -c "$(…)"`, and a group's output into a shell (`(echo X) | bash`). Read what is knowable (an assignment earlier in the line, echo/printf/cat output) and name the backstops for the rest (M9.34 pre-push, M9.36 provenance). Reason: the M9.30 third review; the gate reads static text, so this class is open (before M9.30 too) | M9.30 | `plugin/mission/doors.py`, its test | yes | open | -| M9.50 | A goal whose intents were all sprinted and whose eval still lists gaps gets a next step (re-plan the open gaps as intents, or a recorded retirement so a new goal can be derived). Reason: found wiring M9.28, `goal close` refuses an unmet goal and `goal next` has no intent left, so the loop can only hand it to the human | M9.11 | `plugin/mission/goal.py`, `mission-goal.test.py`, then `tick.py` | yes | done: `mission-goal.test.py` check 13, `mission-tick.test.py` checks 28 and 33. The call: retirement, not a re-plan (a re-plan of the same gaps repeats work the sprints already tried; the 3-failed-goals breaker bounds a run of retirements). `mission goal retire GOAL --eval EVAL` records `goal.retired` (role `mission-planner`, in `LEDGER_EVENTS`, gate-owned) when every intent of the goal was sprinted, its sprints are closed and EVAL is the newest eval, narrowed to the goal, made after those closes and not met; a retired goal takes no intents, sprints or close, and `evaluate` covers the whole mission again. `tick` hands out `RETIRE_GOAL` from the gate's own rule (`goal.retire_problems`), else `BLOCKED` with the gate's reason; a retirement counts toward the 3-failed-goals block | +| M9.50 | A goal whose intents were all sprinted and whose eval still lists gaps gets a next step (re-plan the open gaps as intents, or a recorded retirement so a new goal can be derived). Reason: found wiring M9.28, `goal close` refuses an unmet goal and `goal next` has no intent left, so the loop can only hand it to the human | M9.11 | `plugin/mission/goal.py`, `mission-goal.test.py`, then `tick.py` | yes | done: `mission-goal.test.py` check 13, `mission-tick.test.py` checks 28 and 33, `mission-roles.test.py` (the planner's stop). The call: retirement, not a re-plan (a re-plan of the same gaps repeats work the sprints already tried; the 3-failed-goals breaker bounds a run of retirements). `mission goal retire GOAL --eval EVAL` records `goal.retired` (role `mission-planner`, in `LEDGER_EVENTS`, gate-owned) when the goal is the content `derive` recorded, active and not met; every gap has an intent and every intent of the goal (a second one for a gap included) was sprinted and its sprints closed; and EVAL is the newest eval, narrowed to the goal and not met, made after the last close from the newest state report, itself measured after that close. The record is written before the status (a bare `retired` status is repaired, never trusted). A retired goal takes no intents, sprints or close; `evaluate` covers the whole mission again (`active_goal` is only ever the newest goal); and the retired goal's open gaps are held from `derive` on that baseline until a new version or the human's next approval of the mission (every gap held → `BLOCKED`). `tick` hands out `RETIRE_GOAL` from the gate's own rule (`goal.retire_problems`): a refusal the loop fixes itself is its `ASSESS` or `EVALUATE`, any other is `BLOCKED` with the gate's reason; a retirement, by its record, counts toward the 3-failed-goals block. At the planner's stop the goal check's `retired` state is the planner's finding (`roles.json` verdicts) | | M9.51 | Lifting a block (`mission tick --force --by`) is the human's own words: it asks (exit 3) for their typed `lift ` line, the code bound to this occurrence of the block (its key, the lifts of it so far, and the handout that tripped it or the newest failed goal), and records a `mission.lifted` ledger row (`APPROVAL_EVENTS`, `GRANT_VERBS`); a repeat restarts only at that row's own run-log event (first copy), and the 3-failed-goals count only up to the goals the human lifted; `/aloop:mission` counts a lift among the typed grants. Reason: found after M9.17 merged, `--by` alone still lifted a block and the lift was run data, so a fresh checkout blocked again (M9.24's first part) | M9.8, M9.12, M9.17 | `plugin/mission/tick.py`, `plugin/bin/_mission.py`, `plugin/bin/_events.py`, `plugin/skills/mission/`, `scripts/test/mission-{tick,skill}.test.py` | yes | done: `mission-tick.test.py` check 30 (`--by` alone, a run-log-only or replayed lift, a negated line, another code, an old line and a line typed for an earlier block lift nothing; a far `--now` lifts no later goals; a fresh checkout keeps a lift), `mission-skill.test.py` check 8 | | M9.52 | `tick` reads a gap list only when it still recomputes from its inputs, as `evaluate check` does (an intact eval that a changed `compute`, an edited journey or goal no longer reproduces asks for `EVALUATE`). Reason: found in M9.27's review, `tick` reads the record, shape and seal but not the recomputation (the tick test's synthetic evals cannot recompute), so after an upgrade that changes `compute` `goal derive` refuses while `tick` hands out `DERIVE_GOAL` until it blocks | M9.27 | `plugin/mission/tick.py`, `mission-tick.test.py` (real evals in its synthetic sections) | yes | open | | M9.53 | `tick` hands out a goal's commands (`PLAN_INTENTS`, `SPRINT`, its close) only when `goal check` passes, else names the goal's problem. Reason: found in M9.27's review, a goal whose source eval changed or is gone (or one derived before evals were ledger records) gets `PLAN_INTENTS` 3 times while `goal intents` refuses, then `BLOCKED` with no cause named (M9.43 is one case of it) | M9.11, M9.28 | `plugin/mission/tick.py`, `mission-tick.test.py` | yes | open | +| M9.54 | One goal in flight: `goal derive` refuses while a goal is active, and `tick` and `evaluate.active_goal` pick the newest goal by one clock. Reason: found in M9.50's review, a retried `DERIVE_GOAL` can leave two goals, and tick orders goals by their id time while `active_goal` uses the newest `goal.derived`/`goal.approved` row, so a spoon-fed re-approval of an older goal can split them | M9.11, M9.28 | `plugin/mission/{goal,evaluate,tick}.py`, their tests | 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 58293aec..1cce8abb 100644 --- a/docs/TRACKING.md +++ b/docs/TRACKING.md @@ -99,6 +99,7 @@ Status of every requirement in [ROADMAP.md](ROADMAP.md), in the four states §8 | M9.51 | Lifting a mission block is the human's typed line, kept in the ledger | IMPLEMENTED_TESTED | `scripts/test/mission-tick.test.py` | | M9.52 | The mission loop reads a gap list only when it still recomputes | NOT_IMPLEMENTED | §4.12 | | M9.53 | The mission loop hands out a goal's commands only when `goal check` passes | NOT_IMPLEMENTED | §4.12 | +| M9.54 | One goal in flight, picked by one clock | NOT_IMPLEMENTED | §4.12 | | M10.1 | Workers run with the network off and writes confined to their worktree, via the host sandbox | NOT_IMPLEMENTED | §4.13 | | M10.2 | Secret scan and dependency audit in acceptance; no unplanned dependency | NOT_IMPLEMENTED | §4.13 | | M10.3 | Fetched web content is data (no shell for fetching roles, injection eval case) | NOT_IMPLEMENTED | §4.13 | diff --git a/plugin/mission/README.md b/plugin/mission/README.md index 498a955f..2f5b8199 100644 --- a/plugin/mission/README.md +++ b/plugin/mission/README.md @@ -187,7 +187,7 @@ loop to move on records them: | the baseline | as `baseline.py` decides it: `current` (the newest `baseline.confirmed` row), `measured_ok`, `vetoed`, `evaluate`; a replacement applies after the mission's `veto_window_h` from its `baseline.measured` row | | journeys defined | a journey that `journeys.lifecycle` does not call retired | | 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 the newest eval of it, made after the closes, still lists gaps); 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 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 | | 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/plugin/mission/evaluate.py b/plugin/mission/evaluate.py index 06fbe28e..d41d672a 100644 --- a/plugin/mission/evaluate.py +++ b/plugin/mission/evaluate.py @@ -37,8 +37,8 @@ def active_goal(cwd): """The goal being worked, from the records: the newest goal whose current content a - goal.derived (or the human's goal.approved) record covers, no later goal.met record closed and - nothing retired (an ethics hard line, M9.29, or `goal retire` once its sprints left gaps open, + goal.derived (or the human's goal.approved) record covers, while no later goal.met record closed it and + nothing retired it (an ethics hard line, M9.29, or `goal retire` once its sprints left gaps open, M9.50: it never closes, so the next eval covers the whole mission and the loop derives past it). A status field activates nothing. A goal (M9.11) names its targets as [{"journey_id", "criterion_id"}].""" best = None @@ -46,10 +46,13 @@ def active_goal(cwd): ref, sha = M.rel(cwd, path), M.digest(d) starts = [r["ts"] for ev in ("goal.derived", "goal.approved") for r in M.records(cwd, ev, ref) if r["data"].get("sha256") == sha] - if starts and not any(r["ts"] >= max(starts) for r in M.records(cwd, "goal.met", ref)) \ - and (best is None or max(starts) > best[0]) and not retired(cwd, d): - best = (max(starts), d) - return best[1] if best else None + if starts and (best is None or max(starts) > best[0]): + best = (max(starts), d, ref) + # only the newest goal is in flight, as `mission tick` reads it: once it is met or retired the next + # eval covers the whole mission, never an older goal nobody works + if not best or any(r["ts"] >= best[0] for r in M.records(cwd, "goal.met", best[2])) or retired(cwd, best[1]): + return None + return best[1] def retired(cwd, goal): diff --git a/plugin/mission/goal.py b/plugin/mission/goal.py index 5ac3ed4b..76762d06 100644 --- a/plugin/mission/goal.py +++ b/plugin/mission/goal.py @@ -119,12 +119,44 @@ def eval_gaps(cwd, edoc): return [gap_of(cwd, g) for g in edoc.get("gaps") or [] if isinstance(g, dict) and g.get("gap_id")] -def split_held(cwd, gaps): +def split_held(cwd, gaps, edoc=None): """(open, held): a gap whose summary a hard line fixed is held for good (ethics.hard_words), so a - goal derived again never takes it and the loop moves on to the next gap.""" + goal derived again never takes it and the loop moves on to the next gap. A gap a retired goal left + open is held too (M9.50: its sprints already tried it), on that eval's baseline, until a new + baseline version or the human's next approval of the mission. Each held gap names what holds it.""" hard, ids = E.hard_words(cwd), E.held_gaps(cwd) - held = [g for g in gaps if E.word_key(g["summary"]) in hard or g["gap_id"] in ids] - return [g for g in gaps if g not in held], held + tried = retired_gaps(cwd, edoc.get("baseline_id")) if isinstance(edoc, dict) else {} + held = [] + for g in gaps: + if E.word_key(g["summary"]) in hard or g["gap_id"] in ids: + held.append(dict(g, held_by="a hard line")) + elif g["gap_id"] in tried: + held.append(dict(g, held_by="retired goal %s" % tried[g["gap_id"]])) + out = {g["gap_id"] for g in held} + return [g for g in gaps if g["gap_id"] not in out], held + + +def retired_gaps(cwd, baseline_id): + """{gap_id: goal_id} of the gaps a goal.retired record left open, measured on this baseline and + recorded after the mission's newest human approval (a new version or a new approval frees them).""" + mref = M.rel(cwd, M.path_of(cwd, "mission")) + since = max([r["ts"] for r in M.records(cwd, "mission.approved", mref, role="human")] or [""]) + out = {} + for r in M.records(cwd, "goal.retired"): + d = r["data"] + if baseline_id and d.get("baseline_id") == baseline_id and r["ts"] > since: + for x in d.get("open") if isinstance(d.get("open"), list) else []: + if isinstance(x, str): + out.setdefault(x, d.get("goal_id")) + return out + + +def held_text(held): + """'2 held by a hard line, 1 by retired goal gol_…' for a refusal.""" + by = {} + for g in held: + by[g["held_by"]] = by.get(g["held_by"], 0) + 1 + return ", ".join("%d by %s" % (n, k) for k, n in sorted(by.items())) def ledger_index(cwd, event_id): @@ -178,6 +210,7 @@ def check(cwd, gid): blocks += derived_problems(cwd, g) if not blocks else [] rec = EV.retirement(cwd, g) if not blocks else None if rec: + facts["state"] = "retired" # the planner's recorded finding, not a defect (roles.json verdicts) blocks.append("goal %s was retired (eval %s still listed its gaps after every intent was sprinted): " "derive another goal" % (gid, rec["data"].get("eval_id"))) if blocks: @@ -232,7 +265,7 @@ def cmd_options(cwd, o): if bad: report(bad, []) return 2 - gaps, held = split_held(cwd, eval_gaps(cwd, doc)) + gaps, held = split_held(cwd, eval_gaps(cwd, doc), doc) opts = [dict(g, rank=i) for i, g in enumerate(gaps, 1)] if o.get("json"): print(json.dumps({"eval_id": doc["eval_id"], "goal_met": doc["goal_met"], "goal_id": doc.get("goal_id"), @@ -241,7 +274,7 @@ def cmd_options(cwd, o): for x in opts: print("%d. %s (%s): %s; now %s" % (x["rank"], x["gap_id"], x["kind"], x["summary"], x["now"] or "-")) for x in held: - print("- %s held by a hard line (never a goal): %s" % (x["gap_id"], x["summary"])) + print("- %s held by %s (no goal takes it): %s" % (x["gap_id"], x["held_by"], x["summary"])) return 0 @@ -306,13 +339,15 @@ def cmd_derive(cwd, o): report(["the evaluation %s says the goal is met: go back to research and raise the bar (new journeys " "and a new eval), not a goal from this one" % edoc["eval_id"]], []) return 2 - gaps, held = split_held(cwd, eval_gaps(cwd, edoc)) + gaps, held = split_held(cwd, eval_gaps(cwd, edoc), edoc) if mode == "spoon-fed": want = [x.strip() for x in o["pick"].split(",") if x.strip()] by_id = {g["gap_id"]: g for g in gaps} - stuck = [x for x in want if x in {g["gap_id"] for g in held}] + stuck = [g for g in held if g["gap_id"] in want] if stuck: - report(["%s held by a hard line: no goal takes it (aloop mission ethics check)" % ", ".join(stuck)], []) + report(["%s held by %s: no goal takes it (a hard line: aloop mission ethics check; a retired goal's gap: " + "a new baseline version or the human's approval of the mission frees it)" + % (", ".join(g["gap_id"] for g in stuck), stuck[0]["held_by"])], []) return 2 missing = [x for x in want if x not in by_id] if missing or not want: @@ -323,7 +358,7 @@ def cmd_derive(cwd, o): else: chosen = gaps[:top] if not chosen: - report(["the evaluation %s lists no open gaps%s" % (edoc["eval_id"], " (%d held by a hard line)" % len(held) + report(["the evaluation %s lists no open gaps%s" % (edoc["eval_id"], " (%d held: %s)" % (len(held), held_text(held)) if held else "")], []) return 2 gid = M.new_id("goal") @@ -393,8 +428,8 @@ def goal_intents(cwd, gid): intent.received (written by `intent new --source mission`) names the goal and the gap.""" out, seen = {}, set() for e in _events.read(cwd): - d = e.get("data") or {} - if e.get("event") != "intent.received" or d.get("intent_id") in seen: + d = e.get("data") if isinstance(e.get("data"), dict) else {} + if e.get("event") != "intent.received" or not isinstance(d.get("intent_id"), str) or d["intent_id"] in seen: continue seen.add(d.get("intent_id")) # an intent's first record is the one `intent new` wrote if d.get("goal_id") != gid: @@ -480,8 +515,9 @@ def cmd_next(cwd, gid): return 2 g, _ = M.load(M.path_of(cwd, "goal", gid)) have = goal_intents(cwd, gid) - planned = {(e.get("data") or {}).get("intent_id") for e in _events.read(cwd) - if e.get("event") in ("plan.created", "plan.revised")} + planned = {e["data"].get("intent_id") for e in _events.read(cwd) + if e.get("event") in ("plan.created", "plan.revised") and isinstance(e.get("data"), dict) + and isinstance(e["data"].get("intent_id"), str)} for gap in g["gaps"]: if gap["gap_id"] not in have: continue @@ -560,50 +596,95 @@ def sprint_closes(cwd): for c in st.get("closed") if isinstance(st, dict) and isinstance(st.get("closed"), list) else []: try: out[int(c.get("sprint"))] = c.get("at") - except (AttributeError, TypeError, ValueError): + except (AttributeError, TypeError, ValueError, OverflowError): + continue + return out + + +def goal_intent_ids(cwd, gid): + """Every intent handed off for this goal, oldest first: each one whose first intent.received (the + one `intent new` wrote) names the goal; a second intent for a gap counts too (`mission tick` reads these).""" + out, seen = [], set() + for e in _events.read(cwd): + d = e.get("data") if isinstance(e.get("data"), dict) else {} + iid = d.get("intent_id") + if e.get("event") != "intent.received" or not isinstance(iid, str) or iid in seen: continue + seen.add(iid) + if d.get("goal_id") == gid: + out.append(iid) return out def retire_problems(cwd, g, eid): - """(eval doc, eval.completed record, why goal g is not retired on eval eid yet) (ROADMAP M9.50), the - rule `mission tick` asks before it hands out RETIRE_GOAL: eid is the newest eval, narrowed to the goal - and not met, made after every one of the goal's intents was planned and its sprints closed.""" + """(eval doc, eval.completed record, why goal g is not retired on eval eid yet, the loop's step that + fixes it or None) (ROADMAP M9.50): the whole rule `mission tick` asks before it hands out RETIRE_GOAL. + The goal is the content `derive` recorded, active (or set retired with no record, which this repairs) + and not met; every gap has an intent and every intent of the goal was sprinted, its sprints closed; + eid is the newest eval, narrowed to the goal, not met, made after the last close from the newest state + report, itself measured after that close.""" + import assess as A # noqa: E402 — the newest state report, as `mission assess` and `evaluate` read it import tick as T # noqa: E402 — the loop's own clocks, so the gate and the loop agree on "after" - gid = g["goal_id"] + gid, gpath = g.get("goal_id"), M.path_of(cwd, "goal", str(g.get("goal_id"))) + try: + bad = list(M.problems(g, "goal", gpath)) or derived_problems(cwd, g) + except ValueError as e: + bad = ["goal %s cannot be hashed (%s)" % (gid, e)] + if bad: + return None, None, bad, None + if M.records(cwd, "goal.met", M.rel(cwd, gpath)): + return None, None, ["goal %s is met: a met goal is never retired" % gid], None + if g["status"] not in ("active", "retired"): + return None, None, ["goal %s is %s: only an active goal is retired (handed off with `mission goal intents`, " + "every intent sprinted)" % (gid, g["status"])], None doc, ev, bad = eval_record(cwd, eid) if bad: - return doc, ev, bad + return doc, ev, bad, None if doc.get("goal_id") != gid: return doc, ev, ["eval %s is not an evaluation of goal %s (it evaluates %s): evaluate while the goal is " - "active" % (eid, gid, doc.get("goal_id") or "the whole mission")] + "active" % (eid, gid, doc.get("goal_id") or "the whole mission")], None if doc["goal_met"]: - return doc, ev, ["goal %s is met in eval %s: close it (mission goal close %s --eval %s)" % (gid, eid, gid, eid)] + return doc, ev, ["goal %s is met in eval %s: close it (mission goal close %s --eval %s)" + % (gid, eid, gid, eid)], None newest = latest_eval(cwd) if newest != eid: - return doc, ev, ["eval %s is not the newest eval (%s is): retire on what the loop reads now" % (eid, newest)] - have = goal_intents(cwd, gid) + return doc, ev, ["eval %s is not the newest eval (%s is): retire on what the loop reads now" + % (eid, newest)], None + have, ids = goal_intents(cwd, gid), goal_intent_ids(cwd, gid) sprints = {} for e in _events.read(cwd): - d = e.get("data") or {} - m = re.match(r"^S(\d+)$", str(d.get("sprint") or (e.get("ids") or {}).get("sprint") or "")) - if e.get("event") == "plan.created" and m: - sprints.setdefault(d.get("intent_id"), set()).add(int(m.group(1))) + d = e.get("data") if isinstance(e.get("data"), dict) else {} + tags = e.get("ids") if isinstance(e.get("ids"), dict) else {} + m = re.match(r"^S(\d+)$", str(d.get("sprint") or tags.get("sprint") or "")) + if e.get("event") == "plan.created" and m and isinstance(d.get("intent_id"), str): + sprints.setdefault(d["intent_id"], set()).add(int(m.group(1))) unplanned = [gap["gap_id"] for gap in g["gaps"] if gap["gap_id"] not in have or have[gap["gap_id"]][1].get("intent_id") not in sprints] if unplanned: return doc, ev, ["goal %s's gap %s has no plan yet (its intent is not sprinted): sprint every intent first " - "(mission goal next %s)" % (gid, ", ".join(unplanned), gid)] + "(mission goal next %s)" % (gid, ", ".join(unplanned), gid)], None + left = [i for i in ids if i not in sprints] + if left: + return doc, ev, ["goal %s's intent %s has no plan yet: sprint it first" % (gid, left[0])], None closes = sprint_closes(cwd) - mine = sorted(set().union(*(sprints[have[gap["gap_id"]][1]["intent_id"]] for gap in g["gaps"]))) + mine = sorted(set().union(*(sprints[i] for i in ids))) open_ = [n for n in mine if n not in closes] if open_: return doc, ev, ["goal %s's sprint %d is not closed (`stats sprint-close`): retire after its sprints" - % (gid, open_[0])] - if T.ms_doc(doc, "eval") <= max(T.ms_end(closes[n]) or 0 for n in mine): + % (gid, open_[0])], None + last = max(T.ms_end(closes[n]) or 0 for n in mine) + if T.ms_doc(doc, "eval") <= last: return doc, ev, ["eval %s was made before goal %s's last sprint closed: assess and evaluate after its sprints" - % (eid, gid)] - return doc, ev, [] + % (eid, gid)], "EVALUATE" + state, _ = M.load(M.path_of(cwd, "state", doc["state_id"])) + if not isinstance(state, dict) or T.ms_doc(state, "state") < last: + return doc, ev, ["eval %s was worked out from state %s, measured before goal %s's last sprint closed: assess " + "after its sprints, then evaluate" % (eid, doc["state_id"], gid)], "ASSESS" + now = (A.latest(cwd)[1] or {}).get("state_id") + if now != doc["state_id"]: + return doc, ev, ["eval %s was worked out from state %s, not the newest state report %s: evaluate it, then " + "retire on the new eval" % (eid, doc["state_id"], now)], "EVALUATE" + return doc, ev, [], None def cmd_retire(cwd, gid, eid): @@ -611,38 +692,29 @@ def cmd_retire(cwd, gid, eid): record, so `mission evaluate` covers the whole mission again and the loop derives past it.""" gpath = M.path_of(cwd, "goal", gid) g, _ = M.load(gpath) - if not isinstance(g, dict): + if not isinstance(g, dict) or g.get("goal_id") != gid: report(["no goal %s" % gid], []) return 2 - try: - bad = list(M.problems(g, "goal", gpath)) - except ValueError as e: - bad = ["goal %s cannot be hashed (%s)" % (gid, e)] - bad = bad or derived_problems(cwd, g) - if bad: - report(bad, []) - return 2 if M.ledger_block(cwd, "goal"): return 2 - if EV.retirement(cwd, g): - print("[goal] %s is already retired" % gid, file=sys.stderr) - return 0 - if M.records(cwd, "goal.met", M.rel(cwd, gpath)): - report(["goal %s is met: a met goal is never retired" % gid], []) - return 2 - if g["status"] != "active": - report(["goal %s is %s: only an active goal is retired (handed off with `mission goal intents`, every " - "intent sprinted)" % (gid, g["status"])], []) - return 2 - doc, ev, bad = retire_problems(cwd, g, eid) + try: + if EV.retirement(cwd, g): + print("[goal] %s is already retired" % gid, file=sys.stderr) + return 0 + except ValueError: + pass # no digest: retire_problems names it + doc, ev, bad, _ = retire_problems(cwd, g, eid) if bad: report(bad, []) return 2 - g["status"] = "retired" - M.save(gpath, g) still = [x.get("gap_id") for x in doc["gaps"] if isinstance(x, dict)] + # the record first (its digest leaves the status out), then the status: a stop between them leaves + # a goal every reader already takes as retired, and running retire again is a no-op M.record(cwd, "goal.retired", M.rel(cwd, gpath), "mission-planner", goal_id=gid, eval_id=eid, - eval_event=ev.get("event_id"), sha256=M.digest(g), open=still) + eval_event=ev.get("event_id"), sha256=M.digest(g), open=still, baseline_id=doc.get("baseline_id"), + state_id=doc.get("state_id")) + g["status"] = "retired" + M.save(gpath, g) print("[goal] %s retired with %d gap(s) still open (eval %s): evaluate the whole mission and derive another" % (gid, len(still), eid), file=sys.stderr) return 0 diff --git a/plugin/mission/roles.json b/plugin/mission/roles.json index 7082f6ac..6a4e510d 100644 --- a/plugin/mission/roles.json +++ b/plugin/mission/roles.json @@ -57,7 +57,7 @@ "assess": {"args": ["{id}"]}, "journeys": {"args": ["{id}"]}, "ethics": {"args": ["--subject", "{subject}", "--json"], "verdicts": ["hard"]}, - "goal": {"args": ["{id}", "--json"], "foreign": ["ethics: "]} + "goal": {"args": ["{id}", "--json"], "foreign": ["ethics: "], "verdicts": ["retired"]} }, "human_verbs": ["approve", "confirm", "consent", "veto", "accept", "revoke", "restore"], "read_only": ["status", "show", "check", "list", "diff", "due", "help", "--list", "--help", "-h"] diff --git a/plugin/mission/tick.py b/plugin/mission/tick.py index 7ac46575..2ce6405b 100644 --- a/plugin/mission/tick.py +++ b/plugin/mission/tick.py @@ -19,7 +19,7 @@ STOP_BUDGET human spend since the mission was set reached a cap, or the deadline passed ETHICS_REVIEW ethics-reviewer the mission, or the goal in flight, has no review for its content BLOCKED human a hard line on the mission, or on a goal whose sprint runs; every open - gap held by a hard line; 3 failed goals in a row; a stalled sprint; an + gap held (a hard line, or a retired goal's gaps on this baseline); 3 failed goals in a row; a stalled sprint; an action handed out 3 times; the ledger or the confirmed baseline fails its check (a hard-lined goal with no sprint is retired: evaluate again) ASK_CONSENT human a gray review with no consent for that exact content (and review) @@ -41,7 +41,8 @@ DERIVE_GOAL mission-planner the latest eval shows gaps and no goal is in flight RETIRE_GOAL mission-planner every intent of the goal was sprinted and the newest eval, narrowed to it and made after its sprints closed, still lists its gaps - (`mission goal retire` would accept it; else BLOCKED, its reason) + (`mission goal retire`'s own rule: a stale state or eval is its + ASSESS or EVALUATE, any other refusal BLOCKED with its reason) WAIT — a sprint is running; or the raised bar is still met Facts, never a model's word: `mission check`; artifact status, harness ids (their time) and @@ -292,7 +293,7 @@ def rel(p): f["loop_log"] = [e for e in evs if e.get("event") in ("mission.tick", "mission.lifted")] f["ethics"], f["hard_refs"], f["verdicts"] = {}, set(), {} f["intents"], f["plans"], f["approved_plans"], f["activity"] = {}, [], set(), {} - planned, closed, resets, newest = {}, {}, [0], {} + planned, closed, resets, newest, received = {}, {}, [0], {}, set() # human decisions come from the committed ledger (a fresh checkout keeps them), and count only as # a human's: role human and a name (`--by`), as M.approve records them; the newest one per subject # decides, so restoring content an older approval covered is a rollback, not approved @@ -349,9 +350,12 @@ def rel(p): for e in evs: name, d = e.get("event"), e["data"] ts = ms_end(e.get("ts")) - if name == "intent.received" and isinstance(d.get("goal_id"), str) and isinstance(d.get("intent_id"), str): - f["intents"].setdefault(d["goal_id"], []).append(d["intent_id"]) - m = re.match(r"^S(\d+)$", str(d.get("sprint") or (e.get("ids") or {}).get("sprint") or "")) + if name == "intent.received" and isinstance(d.get("intent_id"), str) and d["intent_id"] not in received: + received.add(d["intent_id"]) # its first record, as `goal` reads it (goal_intent_ids) + if isinstance(d.get("goal_id"), str): + f["intents"].setdefault(d["goal_id"], []).append(d["intent_id"]) + tags = e.get("ids") if isinstance(e.get("ids"), dict) else {} + m = re.match(r"^S(\d+)$", str(d.get("sprint") or tags.get("sprint") or "")) if m and ts: n = int(m.group(1)) f["activity"][n] = max(ts, f["activity"].get(n, 0)) @@ -365,7 +369,7 @@ def rel(p): for c in cl if isinstance(cl, list) else []: try: closed[int(c.get("sprint"))] = ms_end(c.get("at")) or 0 - except (AttributeError, TypeError, ValueError): + except (AttributeError, TypeError, ValueError, OverflowError): continue f["planned"], f["closed"], f["lock"] = planned, closed, lock_ms(root, now) mpath = M.path_of(cwd, "mission") @@ -469,9 +473,9 @@ def failed_goals(f): if g["ms"] <= f["reset_at"]: break hard = ethics_of(f, "goal", g)[0] == "hard" - if not hard and not g["retired"] and g["status"] not in ("blocked", "retired"): + if not hard and not g["retired"] and g["status"] != "blocked": break - out.append((g, "crosses a hard line" if hard else "was retired" if g["retired"] else "was %s" % g["status"])) + out.append((g, "crosses a hard line" if hard else "was retired" if g["retired"] else "was blocked")) return out @@ -535,7 +539,7 @@ def rules(f): if b: return b g = latest(f, "goal") - if g and not g["met"] and not g["retired"] and g["status"] not in ("blocked", "retired"): + if g and not g["met"] and not g["retired"] and g["status"] != "blocked": # retired: its record (M9.50) r = goal_rule(f, g, mode, now, cad) if r: return r @@ -726,9 +730,12 @@ def goal_rule(f, g, mode, now, cad): left = [i for i in f["intents"].get(g["id"]) or [] if i not in sprinted] if done and not left: s = latest(f, "state") - if mine and mine["ms"] > max(f["closed"][n] for n in done) and (not s or mine["ms"] >= s["ms"]): + if mine and mine["ms"] > max(f["closed"][n] for n in done) and (not s or mine["ms"] >= s["ms"]) \ + and not stale_inputs(f, mine): import goal as G # noqa: E402 — the gate's own rule (ROADMAP M9.50), so the loop and it agree - why = G.retire_problems(f["cwd"], g["doc"], mine["id"])[2] + _, _, why, step = G.retire_problems(f["cwd"], g["doc"], mine["id"]) + if why and step: # the loop's own next step fixes it (a state after the closes, a new eval) + return act(step, "%s (aloop mission %s)" % (why[0], step.lower()), mine["ref"]) if why: return act("BLOCKED", "goal %s's intents were all sprinted and eval %s still lists its gaps, but " "`mission goal retire` refuses (%s): the human looks" % (g["id"], mine["id"], why[0]), @@ -776,6 +783,13 @@ def measured_other(f, a): return bool(f["baseline_at"]) and a["ms"] < f["baseline_at"] +def stale_inputs(f, e): + """What eval e is older than: the state report, research, journeys, or another baseline (re-evaluate).""" + s, r, j = latest(f, "state"), latest(f, "research"), latest(f, "journey") + return [n for n, t in (("state report", s and s["ms"]), ("research", r and r["ms"]), ("journeys", j and j["ms"])) + if t and t > e["ms"]] + (["baseline"] if measured_other(f, e) else []) + + def cycle(f, now, cad): s, e, r, j = latest(f, "state"), latest(f, "eval"), latest(f, "research"), latest(f, "journey") fails = failed_goals(f) @@ -795,8 +809,7 @@ def cycle(f, now, cad): return act("ASSESS", "the cadence (%s) is due: the last state report is from %s" % (hours(cad), iso(s["ms"]))) if not e: return act("EVALUATE", "no eval yet: compare the state with the baseline and the rivals") - stale = [n for n, t in (("state report", s["ms"]), ("research", r and r["ms"]), ("journeys", j and j["ms"])) - if t and t > e["ms"]] + (["baseline"] if measured_other(f, e) else []) + stale = stale_inputs(f, e) if stale: return act("EVALUATE", "the latest eval %s is older than the %s" % (e["id"], ", ".join(stale)), e["ref"]) gid = e["doc"].get("goal_id") @@ -823,11 +836,15 @@ def cycle(f, now, cad): return act("WAIT", "sprint %d is running; the next goal is derived after it closes" % n, "", iso(nxt)) if not goal_met(f, e): import goal as G # noqa: E402 — here: goal imports most of the mission layer - opened, held = G.split_held(f["cwd"], G.eval_gaps(f["cwd"], e["doc"])) - if held and not opened: + opened, held = G.split_held(f["cwd"], G.eval_gaps(f["cwd"], e["doc"]), e["doc"]) + if held and not opened and all(x["held_by"] == "a hard line" for x in held): return act("BLOCKED", "every gap of eval %s is held by a hard line (%d): no goal may take one, so only a " "human-approved change of the mission moves on (aloop mission ethics check)" % (e["id"], len(held)), e["ref"]) + if held and not opened: + return act("BLOCKED", "every gap of eval %s is held (%s): a retired goal's sprints already tried them, so " + "the human looks; a new baseline version or their approval of the mission frees a " + "retired goal's gaps" % (e["id"], G.held_text(held)), e["ref"]) why = "goal %s %s: derive another from" % (fails[0][0]["id"], fails[0][1]) if fails else "eval %s shows " \ "gaps: derive the next goal from" % e["id"] if f["mission"].get("mode") == "spoon-fed": diff --git a/plugin/skills/mission/SKILL.md b/plugin/skills/mission/SKILL.md index 62b5ec34..df9a3bd1 100644 --- a/plugin/skills/mission/SKILL.md +++ b/plugin/skills/mission/SKILL.md @@ -72,7 +72,7 @@ paste artifacts into it. A role writes its artifact only through `aloop mission | `CONFIRM_MISSION` | human | Show `aloop mission show` and relay the reason's `approve ` line; once they have typed it, `aloop mission approve --by`. | the content is approved | | `STOP_BUDGET` | human | Show the spend and cap from `aloop mission tick --json` (`budget`). A higher cap is a mission change: edit, then their approval. | the cap is raised or the mission ends | | `ETHICS_REVIEW` | `ethics-reviewer` | Review the subject (the mission or a goal) against the mission's constraints; it records the tier with `aloop mission ethics`. | a review covers that content | -| `BLOCKED` | human | A hard line, 3 failed goals in a row, a stalled sprint, an action repeated without result, or a broken record (the ledger, the confirmed baseline). Report it. | the human fixes the subject; a repeat or 3 failed goals: `aloop mission tick --force --by ""`, then their `lift …` line | +| `BLOCKED` | human | A hard line, every open gap held (a hard line, or a retired goal's gaps: a new baseline version or their approval of the mission frees those), 3 failed goals in a row, a stalled sprint, an action repeated without result, or a broken record (the ledger, the confirmed baseline). Report it. | the human fixes the subject; a repeat or 3 failed goals: `aloop mission tick --force --by ""`, then their `lift …` line | | `ASK_CONSENT` | human | Gray tier: show the review's reason and relay the `consent ` line tick names; once they have typed it, run the `aloop mission ethics consent` it names. It never carries over to another goal. | consent covers that content | | `RESEARCH` | `market-researcher` | Sourced landscape: rival products, papers, benchmarks (`aloop mission research`). When the goal is met: raise the bar, "what is best that the user is not even thinking of?" | a new research artifact | | `DEFINE_JOURNEYS` | `market-researcher` | User journeys from the research: scripted steps, pass criteria, an event per step, sources (`aloop mission journeys`). A baseline with nothing to earn: raise the bar (new or stricter journeys). A listed journey that no longer runs as pinned: a journey that supersedes it. | a proposed journey | @@ -85,7 +85,7 @@ paste artifacts into it. A role writes its artifact only through `aloop mission | `ASSESS` | `state-assessor` | Measure the product with the pinned scripts; numbers only, no opinions (`aloop mission assess`). | a new state report | | `EVALUATE` | `evaluator` | Compare the state with the baseline and the rivals: the gap list and `goal_met` (`aloop mission evaluate`); it never builds. A goal met in its eval: `aloop mission goal close --eval `. | a new eval, or a closed goal | | `DERIVE_GOAL` | `mission-planner` | The eval's top gaps become one goal, with the standing principles for the mode (`aloop mission goal derive`). | a derived goal | -| `RETIRE_GOAL` | `mission-planner` | Every intent of the goal was sprinted and the newest eval of it still lists gaps: set it aside (`aloop mission goal retire --eval `); the next eval covers the whole mission and another goal is derived. | a `goal.retired` record | +| `RETIRE_GOAL` | `mission-planner` | Every intent of the goal was sprinted and the newest eval of it still lists gaps: set it aside (`aloop mission goal retire --eval `). The next eval covers the whole mission, and the next goal is derived from the gaps the retired goal did not hold open. | a `goal.retired` record | | `WAIT` | — | A sprint is running, planning is under way, or the raised bar is still met. Stop. | the cron wakes the loop | Usage telemetry (Google Analytics) is opt-in (`aloop mission telemetry`): it feeds research diff --git a/scripts/test/mission-goal.test.py b/scripts/test/mission-goal.test.py index e7d1af11..cc64d67b 100644 --- a/scripts/test/mission-goal.test.py +++ b/scripts/test/mission-goal.test.py @@ -434,63 +434,116 @@ def setup(mode, extra=()): ok("intent: a mission intent names its goal and gap, passes the goal's gate, and is checked in the goal's autonomy") # 13) retire (M9.50): an active goal whose every intent was sprinted, and whose newest evaluation, made after -# its sprints closed, still lists its gaps, is set aside by a goal.retired ledger record (the planner's): `mission evaluate` -# then covers the whole mission and a new goal is derived; a retired goal takes no more intents or sprints +# its sprints closed from a state measured after them, still lists its gaps, is set aside by a goal.retired +# ledger record (the planner's): `mission evaluate` then covers the whole mission, the retired goal's open +# gaps are held (its sprints tried them), and a retired goal takes no more intents, sprints or close p4, (k1, _), ek = setup("autonomous") assert review(p4, "mission").returncode == 0 gk = made(p4.run("goal", "derive"))["goal_id"] assert review(p4, gk).returncode == 0 -r = p4.run("goal", "retire", gk, "--eval", ek["eval_id"]) -assert r.returncode == 2 and "only an active goal" in r.stderr, r.stderr +gkref = M.rel(p4.dir, p4.path("goal", gk)) + + +def refused(eid, *words): + r = p4.run("goal", "retire", gk, "--eval", eid) + assert r.returncode == 2 and all(w in r.stderr for w in words), (words, r.returncode, r.stderr) + assert not M.records(p4.dir, "goal.retired", gkref) + + +refused(ek["eval_id"], "only an active goal") assert p4.run("goal", "retire", gk).returncode == 64 assert len(p4.run("goal", "intents", gk).stdout.split()) == 2 ek2 = evaluate(p4) assert ek2["goal_id"] == gk and not ek2["goal_met"] -r = p4.run("goal", "retire", gk, "--eval", ek2["eval_id"]) -assert r.returncode == 2 and "has no plan yet" in r.stderr, r.stderr # sprint every intent first +refused(ek2["eval_id"], "has no plan yet") # sprint every intent first for n in (1, 2): path = p4.run("goal", "next", gk).stdout.strip() _events.emit(p4.dir, "plan.created", role="planner", sprint="S%d" % n, intent_id=json.load(open(path))["intent_id"]) -r = p4.run("goal", "retire", gk, "--eval", ek2["eval_id"]) -assert r.returncode == 2 and "sprint 1 is not closed" in r.stderr, r.stderr # its sprints still run -closes = os.path.join(_paths.home(p4.dir, "state"), "sprints.json") -stamp = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()) -json.dump({"closed": [{"sprint": 1, "at": stamp}]}, open(closes, "w")) -r = p4.run("goal", "retire", gk, "--eval", ek2["eval_id"]) -assert r.returncode == 2 and "sprint 2 is not closed" in r.stderr, r.stderr -json.dump({"closed": [{"sprint": 1, "at": stamp}, {"sprint": 2, "at": stamp}]}, open(closes, "w")) -r = p4.run("goal", "retire", gk, "--eval", ek2["eval_id"]) -assert r.returncode == 2 and "before" in r.stderr and "evaluate" in r.stderr, r.stderr # it predates the closes -r = p4.run("goal", "retire", gk, "--eval", ek["eval_id"]) -assert r.returncode == 2 and "not an evaluation of goal" in r.stderr, r.stderr +refused(ek2["eval_id"], "sprint 1 is not closed") # its sprints still run +closes, FMT = os.path.join(_paths.home(p4.dir, "state"), "sprints.json"), "%Y-%m-%dT%H:%M:%SZ" +past = time.strftime(FMT, time.gmtime(time.time() - 10)) +junk = {"sprint": float("inf"), "at": past} # a hand-edited row is skipped, never a crash +json.dump({"closed": [{"sprint": 1, "at": past}, junk]}, open(closes, "w")) +refused(ek2["eval_id"], "sprint 2 is not closed") +em = evaluate(p4) # after sprint 1 closed, before sprint 2 +time.sleep(1.05) +stamp = time.strftime(FMT, time.gmtime()) +json.dump({"closed": [{"sprint": 1, "at": past}, {"sprint": 2, "at": stamp}, junk]}, open(closes, "w")) +refused(em["eval_id"], "made before goal %s's last sprint closed" % gk) +refused(ek["eval_id"], "not an evaluation of goal") +r = tool(p4, INTENT, "new", "--source", "mission", "--goal", gk, "--gap", em["gaps"][0]["gap_id"], "--raw", "try again") +assert r.returncode == 0, r.stderr # a second intent for a gap is the goal's too +i3 = p4.events("intent.received")[-1]["data"]["intent_id"] +refused(em["eval_id"], "intent %s has no plan yet" % i3) +_events.emit(p4.dir, "plan.created", role="planner", sprint="S3", intent_id=i3) +refused(em["eval_id"], "sprint 3 is not closed") +json.dump({"closed": [{"sprint": 1, "at": past}, {"sprint": 2, "at": stamp}, {"sprint": 3, "at": stamp}, junk]}, + open(closes, "w")) time.sleep(1.05) # a close stamp keeps the second: after it is the next one +eo = made(p4.run("evaluate", ek2["state_id"])) # after the closes, from a state before them +refused(eo["eval_id"], "measured before goal %s's last sprint closed" % gk, "assess") ek3 = evaluate(p4) assert ek3["goal_id"] == gk and not ek3["goal_met"] -r = p4.run("goal", "retire", gk, "--eval", ek2["eval_id"]) -assert r.returncode == 2 and "not the newest eval" in r.stderr, r.stderr # the loop reads ek3 now +assert p4.run("assess").returncode == 0 # a newer state report: evaluate it first +refused(ek3["eval_id"], "not the newest state report") +ek3 = made(p4.run("evaluate")) +refused(ek2["eval_id"], "not the newest eval") # the loop reads ek3 now +p4.app(seconds_to_first_task=2.0, working_steps=["open", "add", "see"], tasks_shown=1) +emet = evaluate(p4) +assert emet["goal_id"] == gk and emet["goal_met"] is True +refused(emet["eval_id"], "is met in eval", "close it") # a met goal is closed, never retired +p4.app(seconds_to_first_task=9.0, working_steps=["open", "add"], tasks_shown=0) +ek3 = evaluate(p4) +assert not ek3["goal_met"] +gpath = p4.path("goal", gk) +orig = open(gpath).read() +gd = json.loads(orig) +gd["gaps"] = gd["gaps"][:1] +M.seal(gd) +json.dump(gd, open(gpath, "w")) +refused(ek3["eval_id"], "not the content goal.derived recorded") # an edited, resealed goal is not the derived one +open(gpath, "w").write(orig) +refused("evl_" + "0" * 20, "no evaluation") +lrows = open(M.ledger(p4.dir)).read() +open(M.ledger(p4.dir), "a").write('{"event": "goal.retired", "role": "mission-planner"}\n') +refused(ek3["eval_id"], "BLOCK") # a broken ledger decides nothing +open(M.ledger(p4.dir), "w").write(lrows) +with open(_events.path(p4.dir), "a") as f: # a malformed run-log line crashes nothing + f.write(json.dumps({"event": "plan.created", "data": "text", "ids": "S9"}) + "\n") +json.dump(dict(json.loads(orig), status="retired"), open(gpath, "w")) # a status with no record: retire repairs it r = p4.run("goal", "retire", gk, "--eval", ek3["eval_id"]) assert r.returncode == 0, r.stderr -gkref = M.rel(p4.dir, p4.path("goal", gk)) recs = M.records(p4.dir, "goal.retired", gkref) assert len(recs) == 1 and recs[0]["role"] == "mission-planner" and recs[0]["data"]["eval_id"] == ek3["eval_id"], recs assert recs[0]["data"]["sha256"] == M.digest(p4.load("goal", gk)) and p4.load("goal", gk)["status"] == "retired" assert recs[0]["data"]["open"] == [x["gap_id"] for x in ek3["gaps"]], recs[0]["data"] +assert recs[0]["data"]["baseline_id"] == ek3["baseline_id"], recs[0]["data"] r = p4.run("goal", "retire", gk, "--eval", ek3["eval_id"]) assert r.returncode == 0 and len(M.records(p4.dir, "goal.retired", gkref)) == 1, r.stderr # once -for args in (("next", gk), ("intents", gk), ("check", gk), ("close", gk, "--eval", ek3["eval_id"])): +json.dump(dict(json.loads(orig), status="active"), open(gpath, "w")) # the record decides, not the status +c = json.loads(p4.run("goal", "check", gk, "--json").stdout) +assert c["exit"] == 2 and c["state"] == "retired" and len(c["blocks"]) == 1, c # the planner's finding (roles.json) +for args in (("next", gk), ("intents", gk), ("check", gk), ("close", gk, "--eval", emet["eval_id"])): r = p4.run("goal", *args) assert r.returncode == 2 and "retired" in r.stderr, (args, r.returncode, r.stderr) +assert not M.records(p4.dir, "goal.met", gkref) r = p4.run("goal", "derive") assert r.returncode == 2 and "was retired with its gaps still open" in r.stderr, r.stderr # the eval narrowed to it assert EV.active_goal(p4.dir) is None ek4 = evaluate(p4) assert ek4["goal_id"] is None +r = p4.run("goal", "derive") # its sprints already tried these gaps: held +assert r.returncode == 2 and "2 held: 2 by retired goal %s" % gk in r.stderr, r.stderr +o4 = json.loads(p4.run("goal", "options", "--json").stdout) +assert o4["options"] == [] and {x["held_by"] for x in o4["held"]} == {"retired goal %s" % gk}, o4 +assert p4.run("approve", "--by", "Adeel").returncode == 0 # the human's approval of the mission frees them assert made(p4.run("goal", "derive"))["goal_id"] != gk r = tool(p4, EVENTS, "emit", "goal.retired", "--data", "goal_id=%s" % gk) assert r.returncode == 64 and "only its own command" in r.stderr, r.stderr -ok("retire: an active goal whose intents were all sprinted (sprints closed) and whose newest evaluation, made after " - "the closes, still lists gaps is retired by a goal.retired record (once); it takes no more work, and the whole " - "mission is evaluated and derived again") +ok("retire: an active goal whose every intent was sprinted (sprints closed) and whose newest evaluation, made after " + "the closes from a state measured after them, still lists gaps is retired by a goal.retired record (once); the " + "record, not the status, decides; it takes no more work, the whole mission is evaluated again and its open gaps " + "are held until the human approves the mission again") # 14) the area is discovered; --help is the docstring assert "goal" in p.run("--list").stdout.split() and "Aladdin handoff" in p.run("goal", "--help").stdout diff --git a/scripts/test/mission-roles.test.py b/scripts/test/mission-roles.test.py index d4c3bb58..bea9ab1b 100644 --- a/scripts/test/mission-roles.test.py +++ b/scripts/test/mission-roles.test.py @@ -696,6 +696,22 @@ def work(): assert rec.returncode == 0 and r.returncode == 0, (rec.stderr, r.stderr) # its check needs --subject r, gl = role_run("aloop:mission-planner", "mpd", lambda: made(X.run("goal", "derive"))) assert r.returncode == 0 and "waits on another role's step" in r.stderr, r.stderr # the goal's own review is pending +r, rec = role_run("aloop:ethics-reviewer", "er0", review(gl["goal_id"], [], "clear")) +assert rec.returncode == 0 and r.returncode == 0, (rec.stderr, r.stderr) +assert X.run("goal", "intents", gl["goal_id"]).returncode == 0 +for n in (1, 2): # a sprint per intent, then each one closed + it = json.load(open(made_path(X.run("goal", "next", gl["goal_id"])))) + assert sh(os.path.join(BIN, "events"), "emit", "plan.created", "--role", "planner", "--data", "sprint=S%d" % n, + "--data", "intent_id=" + it["intent_id"], cwd=X.dir, env=XENV).returncode == 0 +os.makedirs(os.path.join(X.dir, ".aladdin", "state"), exist_ok=True) +json.dump({"closed": [{"sprint": n, "at": RealM.now()} for n in (1, 2)]}, + open(os.path.join(X.dir, ".aladdin", "state", "sprints.json"), "w")) +time.sleep(1.05) +assert X.run("assess").returncode == 0 +er = made(X.run("evaluate")) +assert er["goal_id"] == gl["goal_id"] and not er["goal_met"] +r, rt = role_run("aloop:mission-planner", "mpr", lambda: X.run("goal", "retire", gl["goal_id"], "--eval", er["eval_id"])) +assert rt.returncode == 0 and r.returncode == 0 and "holds a retired verdict" in r.stderr, (rt.stderr, r.stderr) gid = M.new_id("goal") g = {"goal_id": gid, "statement": "post fake reviews of our rivals", "status": "derived", "created_at": M.now()} M.seal(g) @@ -724,7 +740,8 @@ def apply(): r, _ = role_run("aloop:product-tester", "pt1", lambda: X.run("journeys", "retire", j3, "--evidence", researched.rid + "#c1")) assert X.load("journey", j3)["status"] == "retired" assert r.returncode == 2 and "journeys/%s.json changed during your run" % j3 in r.stderr, r.stderr -ok("the real ethics, baseline and journeys commands: an ethics check gets its subject and a hard line is the reviewer's" - " finding; a status its own command cascades passes; another area's status change blocks") +ok("the real ethics, baseline, journeys and goal commands: an ethics check gets its subject and a hard line is the " + "reviewer's finding, as a retired goal is the planner's (M9.50); a status its own command cascades passes; another " + "area's status change blocks") print("\n%d checks passed" % PASS[0]) diff --git a/scripts/test/mission-tick.test.py b/scripts/test/mission-tick.test.py index cfef4241..10707031 100755 --- a/scripts/test/mission-tick.test.py +++ b/scripts/test/mission-tick.test.py @@ -1333,13 +1333,24 @@ def lifts(p): p.event("plan.created", later(p), sprint="S%d" % n, intent_id=json.load(open(r.stdout.strip()))["intent_id"]) p.sprint_closed(n, later(p)) assert n == len(p.load("goal", gid)["gaps"]) > 0 -later(p) # the close keeps its second: assess after it +later(p) # the close keeps its second: after it +assert p.mi("evaluate").returncode == 0 # an eval of the state before the sprints +expect(p.tick(later(p), "--peek"), "ASSESS", 0, "measured before goal %s's last sprint closed" % gid) assert p.mi("assess").returncode == 0 expect(p.tick(later(p)), "EVALUATE", 0) eid = json.load(open(p.mi("evaluate").stdout.strip()))["eval_id"] d = p.tick(later(p)) expect(d, "RETIRE_GOAL", 0, "aloop mission goal retire %s --eval %s" % (gid, eid)) assert d["roles"] == ["mission-planner"] and d["who"] == "role", d +assert p.mi("assess").returncode == 0 # a newer state: evaluate it first +expect(p.tick(later(p), "--peek"), "EVALUATE", 0, "older than the state report") +r = p.mi("goal", "retire", gid, "--eval", eid) +assert r.returncode == 2 and "not the newest state report" in r.stderr, r.stderr +eid = json.load(open(p.mi("evaluate").stdout.strip()))["eval_id"] +expect(p.tick(later(p), "--peek"), "RETIRE_GOAL", 0, "--eval %s" % eid) +with open(os.path.join(p.dir, ".aladdin", "logs", "events.jsonl"), "a") as f: # a malformed line crashes nothing + f.write(json.dumps({"event": "plan.created", "data": "text", "ids": "S9"}) + "\n") +expect(p.tick(later(p), "--peek"), "RETIRE_GOAL", 0, "--eval %s" % eid) ip = sorted(glob.glob(os.path.join(p.dir, "docs", "agents", "intents", "int_*.json")))[0] os.rename(ip, ip + ".aside") # the gate refuses: the loop says why expect(p.tick(later(p), "--peek"), "BLOCKED", 2, "`mission goal retire` refuses") @@ -1350,9 +1361,13 @@ def lifts(p): assert [x["data"]["eval_id"] for x in M.ledger_rows(p.dir)[0] if x["event"] == "goal.retired"] == [eid] expect(p.tick(later(p)), "EVALUATE", 0, "retired") # its narrowed eval says nothing now assert p.mi("evaluate").returncode == 0 -expect(p.tick(later(p), "--peek"), "DERIVE_GOAL", 0, "goal %s was retired" % gid) +held = "held (%d by retired goal %s)" % (n, gid) # its sprints already tried every gap +expect(p.tick(later(p), "--peek"), "BLOCKED", 2, held) +json.dump(dict(p.load("goal", gid), status="active"), open(M.path_of(p.dir, "goal", gid), "w")) # the record decides shutil.rmtree(os.path.join(p.dir, ".aladdin")) # a fresh checkout keeps the retirement -expect(p.tick(later(p), "--peek"), "DERIVE_GOAL", 0, "goal %s was retired" % gid) +expect(p.tick(later(p), "--peek"), "BLOCKED", 2, held) +assert p.mi("approve", "--by", "Adeel").returncode == 0 # the human's approval frees the gaps +expect(p.tick(later(p), "--peek"), "DERIVE_GOAL", 0, "aloop mission goal derive") w = Project().init() # 3 retired goals in a row: the human's cleared(w) w.art("state", "recorded", 1) @@ -1362,7 +1377,9 @@ def lifts(p): with w.clock(h + 0.05): M.record(w.dir, "goal.retired", w.ref("goal", g), "mission-planner", goal_id=g, sha256=M.digest(gd)) expect(w.tick(1.7), "BLOCKED", 2, "3 goals") -ok("a goal sprinted with gaps still open is the planner's to retire: a goal.retired ledger record, then the whole " - "mission is evaluated and another goal derived (a fresh checkout keeps it); 3 retired in a row are the human's") +ok("a goal sprinted with gaps still open is the planner's to retire, on the newest eval of a state measured after " + "its sprints (else ASSESS or EVALUATE first): a goal.retired ledger record, then the whole mission is evaluated " + "and its gaps are held until the human approves the mission again (a fresh checkout keeps it, whatever the status " + "field says); 3 retired in a row are the human's") print("mission-tick: %d checks passed" % PASS[0]) From 2e6b4738fd6ebd2e2e711252a53fb7ad62ef3ba0 Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Tue, 20 Oct 2026 14:29:36 +0000 Subject: [PATCH 3/4] Hand out retry intents, hold only the goal's own gaps, let the human lift the hold (M9.50 review 2) A second adversarial review found these, each reproduced: - `goal next` handed out only the first intent per gap, so a retry intent that `goal retire` and tick count could never be sprinted. It now queues every intent of the goal. - The retirement's `open` listed every gap of the eval, a regression elsewhere included. It now lists the goal's own gaps, and a regression is never held. - A BLOCKED with every gap held had no lift. It now carries grant GOALS on the newest retired goal, so the human's `tick --force --by` and `lift` line free those gaps (`goal.retired_gaps` reads the lift). - Two goals derived in the same second tied in `evaluate.active_goal`. The newer id now wins. Tests: mission-goal 14 checks, mission-tick 33 checks (status-only retirement, held BLOCKED with grant GOALS, `goal derive` refusing, the lift giving DERIVE_GOAL). Removing the lift clause fails check 33. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Aw6CiQcdpzdzZZXKf8WbUM --- CHANGELOG.md | 2 +- docs/ROADMAP.md | 2 +- plugin/mission/evaluate.py | 7 +++--- plugin/mission/goal.py | 37 ++++++++++++++++++++++--------- plugin/mission/tick.py | 27 +++++++++++++--------- plugin/skills/mission/SKILL.md | 2 +- scripts/test/mission-goal.test.py | 23 ++++++++++++++----- scripts/test/mission-tick.test.py | 21 +++++++++++++----- 8 files changed, 83 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce48e83f..52545da1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +27,7 @@ tag in lockstep. Tag releases as `vMAJOR.MINOR.PATCH`. - Core agent principles and the one-way / two-way door rule (ROADMAP §4.12, M9.30): seven core principles from Amazon's Leadership Principles, the door rule first, go to every aloop agent at session start (`aloop mission principles show --core`). A two-way door (a branch, a local edit, a test, a draft PR) is decided, not asked. A one-way door (`aloop mission doors list`: a push or merge to the default branch, a force-push, a release, a deploy, a message sent outside, a secret, dropped data, …) is stopped by a PreToolUse gate with `ASK[door] ` until the human records an authorization in their own terminal (`aloop mission doors authorize ID --by NAME --reason TEXT [--until DATE] [--once DIGEST]`, a hash-chained ledger row); a wall (switching a gate off, forging a human record) is never crossed. While a run is live, a question to the human must name a door the gate stopped and nobody authorized. Reason: Adeel's request that agents decide two-way doors themselves and ask only at a one-way door not already authorized. Test: `mission-doors.test.py`. Hardened by an adversarial review (15 findings, each a test): the gate reads Bash as the shell does (comments, line continuations, heredoc bodies, `xargs`, `find -exec`, `echo … | sh`), a branch condition reads the directory the command acts on (`git -C`, `cd`), settings are guarded wherever they live, dry runs and `command -v` are two-way, the newest decision by time counts and a revoke holds on every branch, a once-grant is crossed once under a lock, a broken ledger is named, and `doors authorize` refuses an agent's shell. - DeepSeek Harness (dsh) host (ROADMAP §4.9): `aloop install dsh` (alias `deepseek`; `--project P` or `--global`) renders a `dsh --profile aloop` profile in `$DSH_HOME` and installs the skills. Its native plugin (`plugin/hosts/dsh/aloop.mjs`) runs the same gates as Claude Code on dsh's own events: a deny before a tool runs, a block after an invalid artifact write, and a stop gate that steers a role back up to 3 times before the supervisor is told it is BLOCKED (or STUCK, released unverified). Roles are agent presets on two subagent tools, one per model route (`deepseek-v4-pro` for planning, `deepseek-flash` for work by default; `MODEL_PLANNING_DSH` / `MODEL_WORKER_DSH` override). A writer's `aloop bind` moves its working directory into its worktree, and `host-adapter` confines its commands, edits and `working_directory` there. Usage is recorded Claude-shaped per role, so budgets, the ledger and `run-summary` work unchanged. `make e2e-live HOST=dsh` drives it live and exits 2 with the fix when no `DEEPSEEK_API_KEY` is set. Reason: DeepSeek's own harness is the cheapest route to a strong model. The profile records the project it serves (or `--global`), so another project's `aloop-init` never re-renders it, and gates get the worker shell's environment (no API key). The mission layer's six roles run on dsh too: presets on their route group's subagent tool, `gate-mission-scope` on every write and command, and `gate-mission-artifact` at each role's start and stop; the mission skill installs as `aloop-mission`. A second review (3 lenses; 11 confirmed findings, each fixed with a test) closed: a working directory that vanished (dsh's tools move it back to the main tree, so the plugin judges `ensure()`'s directory and `host-adapter` refuses to run from a missing one), gate switches from the project's `.env` (dsh loads it; `SKIP_HOOKS`, `GATE_RUN_TESTS`, `REPO_DIR`, `AGENTIC_*` from it never reach a gate), an interrupted Stop that dropped the sprint-close notice, and the shared profile: its owner is the main tree, an older unrecorded profile is claimed only by the project that installed it, and a project it does not serve is told so by `install status`, `aloop-init` and the session itself. Tests: `dsh-plugin.test.mjs` (40 checks, emulated), `dsh-runtime.test.mjs` (32 checks on the real pinned dsh 0.2.1-rc.2 with a scripted model; the CI hosts job installs it) and `dsh-install.test.py` (9). - Brand kit and repo front page: `docs/brand/` holds the mark (an **a** whose bowl is a red-to-green loop passing a gold gate, with a 16 px cut), lockups, light and dark README banners, favicons, app icons, the site's OG card and the GitHub social preview, all generated by `docs/brand/gen_brand.py` from one palette with WCAG checks (rules in `docs/brand/README.md`). The README leads with the mission layer, the agent principles and the door rule, the supported hosts and the measured demo runs; the site carries the favicon and Open Graph/Twitter card metadata; `SECURITY.md` and bug/feature issue forms are new. -- A goal its sprints did not meet is retired, and the loop moves on (ROADMAP §4.12, M9.50): `aloop mission goal retire GOAL --eval EVAL` records `goal.retired` in the committed ledger once every intent of the goal was sprinted and its sprints closed, and the newest eval of it, made after those closes from a state measured after them, still lists gaps. A retired goal takes no more intents, sprints or close. `mission evaluate` covers the whole mission again, and the retired goal's open gaps are held from the next goal until a new baseline version or the human's next approval of the mission, so the loop does not sprint the same gaps again. `mission tick` hands this out as `RETIRE_GOAL` (role `mission-planner`) where it used to stop at `BLOCKED` for the human. It asks the command's own rule first: a stale state or eval becomes `ASSESS` or `EVALUATE`, and any other refusal is `BLOCKED` with its reason. 3 retired goals in a row still go to the human. The planner's stop takes a retired goal as its finding. Tests: `mission-goal` check 13, `mission-tick` checks 28 and 33, `mission-roles`. +- A goal its sprints did not meet is retired, and the loop moves on (ROADMAP §4.12, M9.50): `aloop mission goal retire GOAL --eval EVAL` records `goal.retired` in the committed ledger once every intent of the goal was sprinted and its sprints closed, and the newest eval of it, made after those closes from a state measured after them, still lists gaps. A retired goal takes no more intents, sprints or close. `mission evaluate` covers the whole mission again, and the retired goal's own open gaps are held from the next goal until a new baseline version, the human's lift of that hold (`aloop mission tick --force --by NAME`) or their next approval of the mission, so the loop does not sprint the same gaps again; a regression is never held. `mission tick` hands this out as `RETIRE_GOAL` (role `mission-planner`) where it used to stop at `BLOCKED` for the human. It asks the command's own rule first: a stale state or eval becomes `ASSESS` or `EVALUATE`, and any other refusal is `BLOCKED` with its reason. 3 retired goals in a row still go to the human. The planner's stop takes a retired goal as its finding. Tests: `mission-goal` check 13, `mission-tick` checks 28 and 33, `mission-roles`. - A mission's gap lists count only as `mission evaluate` computed them (ROADMAP §4.12, M9.27): `evaluate` records `eval.completed` in the committed ledger, and `mission tick`, `evaluate check` and `goal` take the newest eval whose content that record covers, with a matching seal, in the ledger's order. An eval file written by hand, or edited (or re-stamped) after it was recorded, no longer sends the loop to `RESEARCH` as "goal met" or makes `goal derive` refuse what tick handed out, a clock that is behind no longer reorders them, and a fresh checkout derives and closes goals from the evals it committed. An eval or state named as journey or baseline evidence needs its record too. Tests: `mission-tick` check 32, `mission-journeys`. - A mission's stop at a spend cap holds on a fresh checkout (ROADMAP §4.12, M9.24): the first `STOP_BUDGET` tick records a `mission.budget_exhausted` ledger row for the mission's content (once per content), and `mission tick` stops on it whatever the checkout's token ledger says, until a raised cap changes the content. - Lifting a mission block is the human's own words (ROADMAP §4.12, M9.51): `aloop mission tick --force --by` now asks (exit 3) for the human's typed `lift ` line, the code bound to this occurrence of that block, and records a `mission.lifted` ledger row, so `--by` alone, a lift only the run log has (or a replayed one), an old line or a line typed for an earlier block lift nothing, a lift of 3 failed goals reaches only those goals whatever `--now` says, and a fresh checkout keeps a lifted block lifted. `/aloop:mission` counts a lift among the typed grants it relays. A lift recorded before this (run data only) no longer counts. diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 4ed9fbf7..8196cbc0 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -483,7 +483,7 @@ Each task flips only its own row here and in TRACKING.md. | M9.45 | DEFINE_JOURNEYS names who writes a journey's runner (the program its pinned `runner.command` runs) and where it lives, and the journey check refuses a runner that does not exist yet. Reason: found designing the live run (M9.13), `market-researcher.md` derives the steps and pass criteria, `state-assessor.md` runs the pinned runner, and no persona or prompt says who writes it | M9.3, M9.9 | `plugin/agents/market-researcher.md`, `plugin/mission/journeys.py`, `mission-journeys.test.py` | yes | open | | M9.46 | `aloop mission due` is not read-only for a dispatched agent: it records the handout tick of a human action, so only the supervisor or the cron may run it (or `due --peek` for anyone). Reason: found designing the live run (M9.13), `roles.json` lists `due` as read-only, so a builder's `aloop mission due` marks a BLOCKED or STOP_BUDGET as told inside its own transcript and the cron stays silent | M9.8, M9.9 | `plugin/mission/roles.json`, `plugin/bin/gate-mission-scope`, `mission-scope-bash.test.py` | yes | open | | M9.47 | Computed command text: a `$VAR` program or argument (`M=npm; $M publish`, `B=main; git push origin $B`), `eval "$X"`, `sh -c "$(…)"`, and a group's output into a shell (`(echo X) | bash`). Read what is knowable (an assignment earlier in the line, echo/printf/cat output) and name the backstops for the rest (M9.34 pre-push, M9.36 provenance). Reason: the M9.30 third review; the gate reads static text, so this class is open (before M9.30 too) | M9.30 | `plugin/mission/doors.py`, its test | yes | open | -| M9.50 | A goal whose intents were all sprinted and whose eval still lists gaps gets a next step (re-plan the open gaps as intents, or a recorded retirement so a new goal can be derived). Reason: found wiring M9.28, `goal close` refuses an unmet goal and `goal next` has no intent left, so the loop can only hand it to the human | M9.11 | `plugin/mission/goal.py`, `mission-goal.test.py`, then `tick.py` | yes | done: `mission-goal.test.py` check 13, `mission-tick.test.py` checks 28 and 33, `mission-roles.test.py` (the planner's stop). The call: retirement, not a re-plan (a re-plan of the same gaps repeats work the sprints already tried; the 3-failed-goals breaker bounds a run of retirements). `mission goal retire GOAL --eval EVAL` records `goal.retired` (role `mission-planner`, in `LEDGER_EVENTS`, gate-owned) when the goal is the content `derive` recorded, active and not met; every gap has an intent and every intent of the goal (a second one for a gap included) was sprinted and its sprints closed; and EVAL is the newest eval, narrowed to the goal and not met, made after the last close from the newest state report, itself measured after that close. The record is written before the status (a bare `retired` status is repaired, never trusted). A retired goal takes no intents, sprints or close; `evaluate` covers the whole mission again (`active_goal` is only ever the newest goal); and the retired goal's open gaps are held from `derive` on that baseline until a new version or the human's next approval of the mission (every gap held → `BLOCKED`). `tick` hands out `RETIRE_GOAL` from the gate's own rule (`goal.retire_problems`): a refusal the loop fixes itself is its `ASSESS` or `EVALUATE`, any other is `BLOCKED` with the gate's reason; a retirement, by its record, counts toward the 3-failed-goals block. At the planner's stop the goal check's `retired` state is the planner's finding (`roles.json` verdicts) | +| M9.50 | A goal whose intents were all sprinted and whose eval still lists gaps gets a next step (re-plan the open gaps as intents, or a recorded retirement so a new goal can be derived). Reason: found wiring M9.28, `goal close` refuses an unmet goal and `goal next` has no intent left, so the loop can only hand it to the human | M9.11 | `plugin/mission/goal.py`, `mission-goal.test.py`, then `tick.py` | yes | done: `mission-goal.test.py` check 13, `mission-tick.test.py` checks 28 and 33, `mission-roles.test.py` (the planner's stop). The call: retirement, not a re-plan (a re-plan of the same gaps repeats work the sprints already tried; the 3-failed-goals breaker bounds a run of retirements). `mission goal retire GOAL --eval EVAL` records `goal.retired` (role `mission-planner`, in `LEDGER_EVENTS`, gate-owned) when the goal is the content `derive` recorded, active and not met; every gap has an intent and every intent of the goal (a second one for a gap included, which `goal next` hands out too) was sprinted and its sprints closed; and EVAL is the newest eval, narrowed to the goal and not met, made after the last close from the newest state report, itself measured after that close. The record is written before the status (a bare `retired` status is repaired, never trusted). A retired goal takes no intents, sprints or close; `evaluate` covers the whole mission again (`active_goal` is only ever the newest goal); and the retired goal's own open gaps (the record's `open`) are held from `derive` on that baseline until a new version, the human's lift of that hold or their next approval of the mission, while a regression is never held (every gap held → `BLOCKED` with grant `GOALS`, which `tick --force --by` and the human's `lift` line clear). `tick` hands out `RETIRE_GOAL` from the gate's own rule (`goal.retire_problems`): a refusal the loop fixes itself is its `ASSESS` or `EVALUATE`, any other is `BLOCKED` with the gate's reason; a retirement, by its record, counts toward the 3-failed-goals block. At the planner's stop the goal check's `retired` state is the planner's finding (`roles.json` verdicts) | | M9.51 | Lifting a block (`mission tick --force --by`) is the human's own words: it asks (exit 3) for their typed `lift ` line, the code bound to this occurrence of the block (its key, the lifts of it so far, and the handout that tripped it or the newest failed goal), and records a `mission.lifted` ledger row (`APPROVAL_EVENTS`, `GRANT_VERBS`); a repeat restarts only at that row's own run-log event (first copy), and the 3-failed-goals count only up to the goals the human lifted; `/aloop:mission` counts a lift among the typed grants. Reason: found after M9.17 merged, `--by` alone still lifted a block and the lift was run data, so a fresh checkout blocked again (M9.24's first part) | M9.8, M9.12, M9.17 | `plugin/mission/tick.py`, `plugin/bin/_mission.py`, `plugin/bin/_events.py`, `plugin/skills/mission/`, `scripts/test/mission-{tick,skill}.test.py` | yes | done: `mission-tick.test.py` check 30 (`--by` alone, a run-log-only or replayed lift, a negated line, another code, an old line and a line typed for an earlier block lift nothing; a far `--now` lifts no later goals; a fresh checkout keeps a lift), `mission-skill.test.py` check 8 | | M9.52 | `tick` reads a gap list only when it still recomputes from its inputs, as `evaluate check` does (an intact eval that a changed `compute`, an edited journey or goal no longer reproduces asks for `EVALUATE`). Reason: found in M9.27's review, `tick` reads the record, shape and seal but not the recomputation (the tick test's synthetic evals cannot recompute), so after an upgrade that changes `compute` `goal derive` refuses while `tick` hands out `DERIVE_GOAL` until it blocks | M9.27 | `plugin/mission/tick.py`, `mission-tick.test.py` (real evals in its synthetic sections) | yes | open | | M9.53 | `tick` hands out a goal's commands (`PLAN_INTENTS`, `SPRINT`, its close) only when `goal check` passes, else names the goal's problem. Reason: found in M9.27's review, a goal whose source eval changed or is gone (or one derived before evals were ledger records) gets `PLAN_INTENTS` 3 times while `goal intents` refuses, then `BLOCKED` with no cause named (M9.43 is one case of it) | M9.11, M9.28 | `plugin/mission/tick.py`, `mission-tick.test.py` | yes | open | diff --git a/plugin/mission/evaluate.py b/plugin/mission/evaluate.py index d41d672a..f8037f2f 100644 --- a/plugin/mission/evaluate.py +++ b/plugin/mission/evaluate.py @@ -46,11 +46,12 @@ def active_goal(cwd): ref, sha = M.rel(cwd, path), M.digest(d) starts = [r["ts"] for ev in ("goal.derived", "goal.approved") for r in M.records(cwd, ev, ref) if r["data"].get("sha256") == sha] - if starts and (best is None or max(starts) > best[0]): - best = (max(starts), d, ref) + key = (max(starts), str(d.get("goal_id"))) if starts else None # a tie in the second: the newer id + if key and (best is None or key > best[0]): + best = (key, d, ref) # only the newest goal is in flight, as `mission tick` reads it: once it is met or retired the next # eval covers the whole mission, never an older goal nobody works - if not best or any(r["ts"] >= best[0] for r in M.records(cwd, "goal.met", best[2])) or retired(cwd, best[1]): + if not best or any(r["ts"] >= best[0][0] for r in M.records(cwd, "goal.met", best[2])) or retired(cwd, best[1]): return None return best[1] diff --git a/plugin/mission/goal.py b/plugin/mission/goal.py index 76762d06..399d1e4c 100644 --- a/plugin/mission/goal.py +++ b/plugin/mission/goal.py @@ -123,14 +123,15 @@ def split_held(cwd, gaps, edoc=None): """(open, held): a gap whose summary a hard line fixed is held for good (ethics.hard_words), so a goal derived again never takes it and the loop moves on to the next gap. A gap a retired goal left open is held too (M9.50: its sprints already tried it), on that eval's baseline, until a new - baseline version or the human's next approval of the mission. Each held gap names what holds it.""" + baseline version, the human's lift of that hold (`tick --force`) or their next approval of the + mission; a regression is never held. Each held gap names what holds it.""" hard, ids = E.hard_words(cwd), E.held_gaps(cwd) tried = retired_gaps(cwd, edoc.get("baseline_id")) if isinstance(edoc, dict) else {} held = [] for g in gaps: if E.word_key(g["summary"]) in hard or g["gap_id"] in ids: held.append(dict(g, held_by="a hard line")) - elif g["gap_id"] in tried: + elif g["gap_id"] in tried and g.get("kind") != "regression": # a regression always comes back held.append(dict(g, held_by="retired goal %s" % tried[g["gap_id"]])) out = {g["gap_id"] for g in held} return [g for g in gaps if g["gap_id"] not in out], held @@ -138,13 +139,21 @@ def split_held(cwd, gaps, edoc=None): def retired_gaps(cwd, baseline_id): """{gap_id: goal_id} of the gaps a goal.retired record left open, measured on this baseline and - recorded after the mission's newest human approval (a new version or a new approval frees them).""" + recorded after the mission's newest human approval, for a goal no human lift of failed goals + reached (`tick --force` on that block, as tick reads it): a new version, approval or lift frees them.""" + import tick as T # noqa: E402 — the lift's own rule mref = M.rel(cwd, M.path_of(cwd, "mission")) since = max([r["ts"] for r in M.records(cwd, "mission.approved", mref, role="human")] or [""]) + reach = max([r["data"]["occurrence"] for r in M.records(cwd, "mission.lifted", role="human") + if r["data"].get("grant") == "GOALS" and isinstance(r["data"].get("occurrence"), int) + and str(r["data"].get("by") or "").strip() and r["data"].get("sha256") == M.digest(T.lifted(r["data"]))] + or [0]) out = {} for r in M.records(cwd, "goal.retired"): d = r["data"] - if baseline_id and d.get("baseline_id") == baseline_id and r["ts"] > since: + gid = d.get("goal_id") if isinstance(d.get("goal_id"), str) else "" + if baseline_id and d.get("baseline_id") == baseline_id and r["ts"] > since \ + and T.ms_doc({"goal_id": gid}, "goal") > reach: for x in d.get("open") if isinstance(d.get("open"), list) else []: if isinstance(x, str): out.setdefault(x, d.get("goal_id")) @@ -346,7 +355,8 @@ def cmd_derive(cwd, o): stuck = [g for g in held if g["gap_id"] in want] if stuck: report(["%s held by %s: no goal takes it (a hard line: aloop mission ethics check; a retired goal's gap: " - "a new baseline version or the human's approval of the mission frees it)" + "a new baseline version, the human's `aloop mission tick --force --by NAME` or their approval " + "of the mission frees it)" % (", ".join(g["gap_id"] for g in stuck), stuck[0]["held_by"])], []) return 2 missing = [x for x in want if x not in by_id] @@ -518,10 +528,16 @@ def cmd_next(cwd, gid): planned = {e["data"].get("intent_id") for e in _events.read(cwd) if e.get("event") in ("plan.created", "plan.revised") and isinstance(e.get("data"), dict) and isinstance(e["data"].get("intent_id"), str)} - for gap in g["gaps"]: - if gap["gap_id"] not in have: - continue - p, it = have[gap["gap_id"]] + # each gap's intent in the goal's order, then any later intent of the goal (a retry for a gap): every + # intent `mission tick` and `goal retire` count is handed out here + queue = [have[gap["gap_id"]] for gap in g["gaps"] if gap["gap_id"] in have] + first = {it.get("intent_id") for _, it in queue} + for iid in goal_intent_ids(cwd, gid): + p = os.path.join(_paths.docs(cwd), "intents", "%s.json" % iid) + doc, _ = M.load(p) + if iid not in first and isinstance(doc, dict) and doc.get("intent_id") == iid: + queue.append((p, doc)) + for p, it in queue: if it.get("intent_id") in planned: continue others = [os.path.getmtime(x) for x in glob.glob(os.path.join(os.path.dirname(p), "int_*.json")) if x != p] @@ -707,7 +723,8 @@ def cmd_retire(cwd, gid, eid): if bad: report(bad, []) return 2 - still = [x.get("gap_id") for x in doc["gaps"] if isinstance(x, dict)] + own = {x["gap_id"] for x in g["gaps"]} # a regression elsewhere is the next eval's, not this goal's + still = [x.get("gap_id") for x in doc["gaps"] if isinstance(x, dict) and x.get("gap_id") in own] # the record first (its digest leaves the status out), then the status: a stop between them leaves # a goal every reader already takes as retired, and running retire again is a no-op M.record(cwd, "goal.retired", M.rel(cwd, gpath), "mission-planner", goal_id=gid, eval_id=eid, diff --git a/plugin/mission/tick.py b/plugin/mission/tick.py index 2ce6405b..6ce9a8a9 100644 --- a/plugin/mission/tick.py +++ b/plugin/mission/tick.py @@ -6,10 +6,11 @@ Each call records a mission.tick event (--peek records nothing). The same action is handed out at most 3 times in a row without a result, then BLOCKED. mission tick --force --by NAME - the human lifts a block the loop set (that repeat guard, or 3 failed goals in a row). It - is their own words (M9.17): it asks (exit 3) for the line they reply, `lift - `, then records the lift in the ledger (mission.lifted), so the next tick, from any - session or a fresh checkout, goes on. A hard line or a stalled sprint is not lifted this way. + the human lifts a block the loop set (that repeat guard, 3 failed goals in a row, or a + retired goal's held gaps). It is their own words (M9.17): it asks (exit 3) for the line + they reply, `lift `, then records the lift in the ledger (mission.lifted), + so the next tick, from any session or a fresh checkout, goes on. A hard line or a stalled + sprint is not lifted this way. The loop is IBM's autonomic MAPE-K over docs/agents/mission/: monitor (ASSESS), analyze (EVALUATE), plan (DERIVE_GOAL, PLAN_INTENTS), execute (SPRINT). Actions, first match wins: @@ -841,10 +842,14 @@ def cycle(f, now, cad): return act("BLOCKED", "every gap of eval %s is held by a hard line (%d): no goal may take one, so only a " "human-approved change of the mission moves on (aloop mission ethics check)" % (e["id"], len(held)), e["ref"]) - if held and not opened: + if held and not opened: # the newest retired goal holding one: a lift of it reaches every older one + tried = [x["held_by"].split()[-1] for x in held if x["held_by"].startswith("retired goal ")] + newest = max(tried, key=lambda gid: ms_doc({"goal_id": gid}, "goal")) return act("BLOCKED", "every gap of eval %s is held (%s): a retired goal's sprints already tried them, so " - "the human looks; a new baseline version or their approval of the mission frees a " - "retired goal's gaps" % (e["id"], G.held_text(held)), e["ref"]) + "the human looks; `aloop mission tick --force --by NAME` lets the loop try them " + "again (so do their approval of the mission and a new baseline version)" + % (e["id"], G.held_text(held)), M.rel(f["cwd"], M.path_of(f["cwd"], "goal", newest)), + grant="GOALS") why = "goal %s %s: derive another from" % (fails[0][0]["id"], fails[0][1]) if fails else "eval %s shows " \ "gaps: derive the next goal from" % e["id"] if f["mission"].get("mode") == "spoon-fed": @@ -938,10 +943,10 @@ def lift_of(f, d): def force(cwd, now, by): - """The human lifts a block the loop set (the repeat guard, or 3 failed goals in a row): their typed - `lift` line (M9.17; M.NeedsHuman asks for it), recorded in the ledger, and a grant tick, so the next - tick, from any session or a fresh checkout, hands the action out again. A hard line or a stalled - sprint is not lifted this way.""" + """The human lifts a block the loop set (the repeat guard, 3 failed goals in a row, or a retired goal's + held gaps): their typed `lift` line (M9.17; M.NeedsHuman asks for it), recorded in the ledger, and a + grant tick, so the next tick, from any session or a fresh checkout, hands the action out again. A hard + line or a stalled sprint is not lifted this way.""" d = decide(cwd, now) if d["action"] != "BLOCKED": print("mission tick --force: nothing is blocked; the next action is %s" % line(d), file=sys.stderr) diff --git a/plugin/skills/mission/SKILL.md b/plugin/skills/mission/SKILL.md index df9a3bd1..08a6d49f 100644 --- a/plugin/skills/mission/SKILL.md +++ b/plugin/skills/mission/SKILL.md @@ -72,7 +72,7 @@ paste artifacts into it. A role writes its artifact only through `aloop mission | `CONFIRM_MISSION` | human | Show `aloop mission show` and relay the reason's `approve ` line; once they have typed it, `aloop mission approve --by`. | the content is approved | | `STOP_BUDGET` | human | Show the spend and cap from `aloop mission tick --json` (`budget`). A higher cap is a mission change: edit, then their approval. | the cap is raised or the mission ends | | `ETHICS_REVIEW` | `ethics-reviewer` | Review the subject (the mission or a goal) against the mission's constraints; it records the tier with `aloop mission ethics`. | a review covers that content | -| `BLOCKED` | human | A hard line, every open gap held (a hard line, or a retired goal's gaps: a new baseline version or their approval of the mission frees those), 3 failed goals in a row, a stalled sprint, an action repeated without result, or a broken record (the ledger, the confirmed baseline). Report it. | the human fixes the subject; a repeat or 3 failed goals: `aloop mission tick --force --by ""`, then their `lift …` line | +| `BLOCKED` | human | A hard line, every open gap held (a hard line, or a retired goal's gaps: a new baseline version, their lift or their approval of the mission frees those), 3 failed goals in a row, a stalled sprint, an action repeated without result, or a broken record (the ledger, the confirmed baseline). Report it. | the human fixes the subject; a repeat, 3 failed goals or a retired goal's held gaps: `aloop mission tick --force --by ""`, then their `lift …` line | | `ASK_CONSENT` | human | Gray tier: show the review's reason and relay the `consent ` line tick names; once they have typed it, run the `aloop mission ethics consent` it names. It never carries over to another goal. | consent covers that content | | `RESEARCH` | `market-researcher` | Sourced landscape: rival products, papers, benchmarks (`aloop mission research`). When the goal is met: raise the bar, "what is best that the user is not even thinking of?" | a new research artifact | | `DEFINE_JOURNEYS` | `market-researcher` | User journeys from the research: scripted steps, pass criteria, an event per step, sources (`aloop mission journeys`). A baseline with nothing to earn: raise the bar (new or stricter journeys). A listed journey that no longer runs as pinned: a journey that supersedes it. | a proposed journey | diff --git a/scripts/test/mission-goal.test.py b/scripts/test/mission-goal.test.py index cc64d67b..03c2a6fa 100644 --- a/scripts/test/mission-goal.test.py +++ b/scripts/test/mission-goal.test.py @@ -437,8 +437,9 @@ def setup(mode, extra=()): # its sprints closed from a state measured after them, still lists its gaps, is set aside by a goal.retired # ledger record (the planner's): `mission evaluate` then covers the whole mission, the retired goal's open # gaps are held (its sprints tried them), and a retired goal takes no more intents, sprints or close -p4, (k1, _), ek = setup("autonomous") +p4, (k1, k2), ek = setup("autonomous") assert review(p4, "mission").returncode == 0 +gold = made(p4.run("goal", "derive"))["goal_id"] # an older goal nobody works gk = made(p4.run("goal", "derive"))["goal_id"] assert review(p4, gk).returncode == 0 gkref = M.rel(p4.dir, p4.path("goal", gk)) @@ -475,7 +476,14 @@ def refused(eid, *words): assert r.returncode == 0, r.stderr # a second intent for a gap is the goal's too i3 = p4.events("intent.received")[-1]["data"]["intent_id"] refused(em["eval_id"], "intent %s has no plan yet" % i3) +ip3 = os.path.join(p4.dir, "docs", "agents", "intents", i3 + ".json") +d3, d1 = json.load(open(ip3)), json.load(open(G.goal_intents(p4.dir, gk)[em["gaps"][0]["gap_id"]][0])) +d3.update({k: d1[k] for k in ("actor", "want", "why", "done_looks_like", "success_scenarios", "failure_scenarios")}) +json.dump(d3, open(ip3, "w")) # the planner fills it, as intake would +r = p4.run("goal", "next", gk) +assert os.path.basename(r.stdout.strip()) == i3 + ".json", (r.returncode, r.stdout, r.stderr) # `next` hands it out _events.emit(p4.dir, "plan.created", role="planner", sprint="S3", intent_id=i3) +assert p4.run("goal", "next", gk).returncode == 1 # every intent has a plan refused(em["eval_id"], "sprint 3 is not closed") json.dump({"closed": [{"sprint": 1, "at": past}, {"sprint": 2, "at": stamp}, {"sprint": 3, "at": stamp}, junk]}, open(closes, "w")) @@ -492,9 +500,10 @@ def refused(eid, *words): emet = evaluate(p4) assert emet["goal_id"] == gk and emet["goal_met"] is True refused(emet["eval_id"], "is met in eval", "close it") # a met goal is closed, never retired -p4.app(seconds_to_first_task=9.0, working_steps=["open", "add"], tasks_shown=0) +p4.app(seconds_to_first_task=12.0, working_steps=["open", "add"], tasks_shown=0) # and the 10s journey regresses ek3 = evaluate(p4) -assert not ek3["goal_met"] +assert not ek3["goal_met"] and {"gap_id": k2 + "#ok10", "kind": "regression"}.items() <= \ + next(x for x in ek3["gaps"] if x["gap_id"] == k2 + "#ok10").items(), ek3["gaps"] gpath = p4.path("goal", gk) orig = open(gpath).read() gd = json.loads(orig) @@ -516,7 +525,9 @@ def refused(eid, *words): recs = M.records(p4.dir, "goal.retired", gkref) assert len(recs) == 1 and recs[0]["role"] == "mission-planner" and recs[0]["data"]["eval_id"] == ek3["eval_id"], recs assert recs[0]["data"]["sha256"] == M.digest(p4.load("goal", gk)) and p4.load("goal", gk)["status"] == "retired" -assert recs[0]["data"]["open"] == [x["gap_id"] for x in ek3["gaps"]], recs[0]["data"] +own = [x["gap_id"] for x in p4.load("goal", gk)["gaps"]] +assert recs[0]["data"]["open"] == [x["gap_id"] for x in ek3["gaps"] if x["gap_id"] in own], recs[0]["data"] +assert sorted(recs[0]["data"]["open"]) == sorted(own) and k2 + "#ok10" not in recs[0]["data"]["open"] # not the regression assert recs[0]["data"]["baseline_id"] == ek3["baseline_id"], recs[0]["data"] r = p4.run("goal", "retire", gk, "--eval", ek3["eval_id"]) assert r.returncode == 0 and len(M.records(p4.dir, "goal.retired", gkref)) == 1, r.stderr # once @@ -529,13 +540,15 @@ def refused(eid, *words): assert not M.records(p4.dir, "goal.met", gkref) r = p4.run("goal", "derive") assert r.returncode == 2 and "was retired with its gaps still open" in r.stderr, r.stderr # the eval narrowed to it -assert EV.active_goal(p4.dir) is None +assert EV.active_goal(p4.dir) is None # not the older goal nobody worked either +p4.app(seconds_to_first_task=9.0, working_steps=["open", "add"], tasks_shown=0) ek4 = evaluate(p4) assert ek4["goal_id"] is None r = p4.run("goal", "derive") # its sprints already tried these gaps: held assert r.returncode == 2 and "2 held: 2 by retired goal %s" % gk in r.stderr, r.stderr o4 = json.loads(p4.run("goal", "options", "--json").stdout) assert o4["options"] == [] and {x["held_by"] for x in o4["held"]} == {"retired goal %s" % gk}, o4 +assert not G.split_held(p4.dir, [dict(o4["held"][0], kind="regression")], ek4)[1] # a regression is never held assert p4.run("approve", "--by", "Adeel").returncode == 0 # the human's approval of the mission frees them assert made(p4.run("goal", "derive"))["goal_id"] != gk r = tool(p4, EVENTS, "emit", "goal.retired", "--data", "goal_id=%s" % gk) diff --git a/scripts/test/mission-tick.test.py b/scripts/test/mission-tick.test.py index 10707031..590bf81d 100755 --- a/scripts/test/mission-tick.test.py +++ b/scripts/test/mission-tick.test.py @@ -1356,17 +1356,26 @@ def lifts(p): expect(p.tick(later(p), "--peek"), "BLOCKED", 2, "`mission goal retire` refuses") assert "has no plan yet" in p.tick(later(p), "--peek")["reason"] os.rename(ip + ".aside", ip) -r = p.mi("goal", "retire", gid, "--eval", eid) +gp = M.path_of(p.dir, "goal", gid) +json.dump(dict(p.load("goal", gid), status="retired"), open(gp, "w")) # a status field alone retires nothing +expect(p.tick(later(p), "--peek"), "RETIRE_GOAL", 0, "--eval %s" % eid) +r = p.mi("goal", "retire", gid, "--eval", eid) # the record repairs it assert r.returncode == 0, r.stderr assert [x["data"]["eval_id"] for x in M.ledger_rows(p.dir)[0] if x["event"] == "goal.retired"] == [eid] expect(p.tick(later(p)), "EVALUATE", 0, "retired") # its narrowed eval says nothing now assert p.mi("evaluate").returncode == 0 held = "held (%d by retired goal %s)" % (n, gid) # its sprints already tried every gap expect(p.tick(later(p), "--peek"), "BLOCKED", 2, held) -json.dump(dict(p.load("goal", gid), status="active"), open(M.path_of(p.dir, "goal", gid), "w")) # the record decides +json.dump(dict(p.load("goal", gid), status="active"), open(gp, "w")) # the record decides shutil.rmtree(os.path.join(p.dir, ".aladdin")) # a fresh checkout keeps the retirement -expect(p.tick(later(p), "--peek"), "BLOCKED", 2, held) -assert p.mi("approve", "--by", "Adeel").returncode == 0 # the human's approval frees the gaps +d = p.tick(later(p), "--peek") +expect(d, "BLOCKED", 2, held) +assert d["grant"] == "GOALS", d +r = p.mi("goal", "derive") +assert r.returncode == 2 and "held" in r.stderr, (r.returncode, r.stderr) # the gate holds them too +r = p.mi("tick", "--force", "--by", "Adeel") # the human's lift frees them +assert r.returncode == 0 and r.stdout.startswith("FORCE"), (r.stdout, r.stderr) +assert [x["data"]["grant"] for x in M.ledger_rows(p.dir)[0] if x["event"] == "mission.lifted"] == ["GOALS"] expect(p.tick(later(p), "--peek"), "DERIVE_GOAL", 0, "aloop mission goal derive") w = Project().init() # 3 retired goals in a row: the human's cleared(w) @@ -1379,7 +1388,7 @@ def lifts(p): expect(w.tick(1.7), "BLOCKED", 2, "3 goals") ok("a goal sprinted with gaps still open is the planner's to retire, on the newest eval of a state measured after " "its sprints (else ASSESS or EVALUATE first): a goal.retired ledger record, then the whole mission is evaluated " - "and its gaps are held until the human approves the mission again (a fresh checkout keeps it, whatever the status " - "field says); 3 retired in a row are the human's") + "and its gaps are held until the human lifts the hold or approves the mission again (a fresh checkout keeps it, " + "whatever the status field says); 3 retired in a row are the human's") print("mission-tick: %d checks passed" % PASS[0]) From 2d1d96550e4f4351a3bf7f89f7a62524bb7162df Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Tue, 20 Oct 2026 15:29:48 +0000 Subject: [PATCH 4/4] Hand a broken retry intent to intent check; date a GOALS lift by the goal id (M9.50 review 3) A third adversarial review found these, each reproduced: - `goal next` skipped a goal intent whose file was gone, unreadable or another intent's copy, while tick and `goal retire` still counted it, so the loop repeated SPRINT until BLOCKED. Every goal intent now goes to `intent check`, and `goal next` names the one that fails. - A GOALS lift took its occurrence from the goal file, so after the retired goal's file was edited the lift recorded 0 and freed nothing while `tick --force` said it lifted. The occurrence now comes from the goal id the block names, as the hold reads the record. - The spoon-fed `derive --pick` refusal offered `tick --force` when it only works once every gap is held. The message and docs now say so. Tests: mission-goal check 13 (gone, unreadable and copied retry intent), mission-tick check 33 (the retired goal's file edited before the lift). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Aw6CiQcdpzdzZZXKf8WbUM --- CHANGELOG.md | 2 +- docs/ROADMAP.md | 2 +- plugin/mission/goal.py | 36 ++++++++++++++++--------------- plugin/mission/tick.py | 7 +++--- scripts/test/mission-goal.test.py | 4 ++++ scripts/test/mission-tick.test.py | 2 +- 6 files changed, 30 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52545da1..cae2ad37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +27,7 @@ tag in lockstep. Tag releases as `vMAJOR.MINOR.PATCH`. - Core agent principles and the one-way / two-way door rule (ROADMAP §4.12, M9.30): seven core principles from Amazon's Leadership Principles, the door rule first, go to every aloop agent at session start (`aloop mission principles show --core`). A two-way door (a branch, a local edit, a test, a draft PR) is decided, not asked. A one-way door (`aloop mission doors list`: a push or merge to the default branch, a force-push, a release, a deploy, a message sent outside, a secret, dropped data, …) is stopped by a PreToolUse gate with `ASK[door] ` until the human records an authorization in their own terminal (`aloop mission doors authorize ID --by NAME --reason TEXT [--until DATE] [--once DIGEST]`, a hash-chained ledger row); a wall (switching a gate off, forging a human record) is never crossed. While a run is live, a question to the human must name a door the gate stopped and nobody authorized. Reason: Adeel's request that agents decide two-way doors themselves and ask only at a one-way door not already authorized. Test: `mission-doors.test.py`. Hardened by an adversarial review (15 findings, each a test): the gate reads Bash as the shell does (comments, line continuations, heredoc bodies, `xargs`, `find -exec`, `echo … | sh`), a branch condition reads the directory the command acts on (`git -C`, `cd`), settings are guarded wherever they live, dry runs and `command -v` are two-way, the newest decision by time counts and a revoke holds on every branch, a once-grant is crossed once under a lock, a broken ledger is named, and `doors authorize` refuses an agent's shell. - DeepSeek Harness (dsh) host (ROADMAP §4.9): `aloop install dsh` (alias `deepseek`; `--project P` or `--global`) renders a `dsh --profile aloop` profile in `$DSH_HOME` and installs the skills. Its native plugin (`plugin/hosts/dsh/aloop.mjs`) runs the same gates as Claude Code on dsh's own events: a deny before a tool runs, a block after an invalid artifact write, and a stop gate that steers a role back up to 3 times before the supervisor is told it is BLOCKED (or STUCK, released unverified). Roles are agent presets on two subagent tools, one per model route (`deepseek-v4-pro` for planning, `deepseek-flash` for work by default; `MODEL_PLANNING_DSH` / `MODEL_WORKER_DSH` override). A writer's `aloop bind` moves its working directory into its worktree, and `host-adapter` confines its commands, edits and `working_directory` there. Usage is recorded Claude-shaped per role, so budgets, the ledger and `run-summary` work unchanged. `make e2e-live HOST=dsh` drives it live and exits 2 with the fix when no `DEEPSEEK_API_KEY` is set. Reason: DeepSeek's own harness is the cheapest route to a strong model. The profile records the project it serves (or `--global`), so another project's `aloop-init` never re-renders it, and gates get the worker shell's environment (no API key). The mission layer's six roles run on dsh too: presets on their route group's subagent tool, `gate-mission-scope` on every write and command, and `gate-mission-artifact` at each role's start and stop; the mission skill installs as `aloop-mission`. A second review (3 lenses; 11 confirmed findings, each fixed with a test) closed: a working directory that vanished (dsh's tools move it back to the main tree, so the plugin judges `ensure()`'s directory and `host-adapter` refuses to run from a missing one), gate switches from the project's `.env` (dsh loads it; `SKIP_HOOKS`, `GATE_RUN_TESTS`, `REPO_DIR`, `AGENTIC_*` from it never reach a gate), an interrupted Stop that dropped the sprint-close notice, and the shared profile: its owner is the main tree, an older unrecorded profile is claimed only by the project that installed it, and a project it does not serve is told so by `install status`, `aloop-init` and the session itself. Tests: `dsh-plugin.test.mjs` (40 checks, emulated), `dsh-runtime.test.mjs` (32 checks on the real pinned dsh 0.2.1-rc.2 with a scripted model; the CI hosts job installs it) and `dsh-install.test.py` (9). - Brand kit and repo front page: `docs/brand/` holds the mark (an **a** whose bowl is a red-to-green loop passing a gold gate, with a 16 px cut), lockups, light and dark README banners, favicons, app icons, the site's OG card and the GitHub social preview, all generated by `docs/brand/gen_brand.py` from one palette with WCAG checks (rules in `docs/brand/README.md`). The README leads with the mission layer, the agent principles and the door rule, the supported hosts and the measured demo runs; the site carries the favicon and Open Graph/Twitter card metadata; `SECURITY.md` and bug/feature issue forms are new. -- A goal its sprints did not meet is retired, and the loop moves on (ROADMAP §4.12, M9.50): `aloop mission goal retire GOAL --eval EVAL` records `goal.retired` in the committed ledger once every intent of the goal was sprinted and its sprints closed, and the newest eval of it, made after those closes from a state measured after them, still lists gaps. A retired goal takes no more intents, sprints or close. `mission evaluate` covers the whole mission again, and the retired goal's own open gaps are held from the next goal until a new baseline version, the human's lift of that hold (`aloop mission tick --force --by NAME`) or their next approval of the mission, so the loop does not sprint the same gaps again; a regression is never held. `mission tick` hands this out as `RETIRE_GOAL` (role `mission-planner`) where it used to stop at `BLOCKED` for the human. It asks the command's own rule first: a stale state or eval becomes `ASSESS` or `EVALUATE`, and any other refusal is `BLOCKED` with its reason. 3 retired goals in a row still go to the human. The planner's stop takes a retired goal as its finding. Tests: `mission-goal` check 13, `mission-tick` checks 28 and 33, `mission-roles`. +- A goal its sprints did not meet is retired, and the loop moves on (ROADMAP §4.12, M9.50): `aloop mission goal retire GOAL --eval EVAL` records `goal.retired` in the committed ledger once every intent of the goal was sprinted and its sprints closed, and the newest eval of it, made after those closes from a state measured after them, still lists gaps. A retired goal takes no more intents, sprints or close. `mission evaluate` covers the whole mission again, and the retired goal's own open gaps are held from the next goal until a new baseline version or the human's next approval of the mission, so the loop does not sprint the same gaps again; a regression is never held. When every gap is held, `mission tick` says `BLOCKED` and the human's `aloop mission tick --force --by NAME` lifts it. `mission tick` hands this out as `RETIRE_GOAL` (role `mission-planner`) where it used to stop at `BLOCKED` for the human. It asks the command's own rule first: a stale state or eval becomes `ASSESS` or `EVALUATE`, and any other refusal is `BLOCKED` with its reason. 3 retired goals in a row still go to the human. The planner's stop takes a retired goal as its finding. Tests: `mission-goal` check 13, `mission-tick` checks 28 and 33, `mission-roles`. - A mission's gap lists count only as `mission evaluate` computed them (ROADMAP §4.12, M9.27): `evaluate` records `eval.completed` in the committed ledger, and `mission tick`, `evaluate check` and `goal` take the newest eval whose content that record covers, with a matching seal, in the ledger's order. An eval file written by hand, or edited (or re-stamped) after it was recorded, no longer sends the loop to `RESEARCH` as "goal met" or makes `goal derive` refuse what tick handed out, a clock that is behind no longer reorders them, and a fresh checkout derives and closes goals from the evals it committed. An eval or state named as journey or baseline evidence needs its record too. Tests: `mission-tick` check 32, `mission-journeys`. - A mission's stop at a spend cap holds on a fresh checkout (ROADMAP §4.12, M9.24): the first `STOP_BUDGET` tick records a `mission.budget_exhausted` ledger row for the mission's content (once per content), and `mission tick` stops on it whatever the checkout's token ledger says, until a raised cap changes the content. - Lifting a mission block is the human's own words (ROADMAP §4.12, M9.51): `aloop mission tick --force --by` now asks (exit 3) for the human's typed `lift ` line, the code bound to this occurrence of that block, and records a `mission.lifted` ledger row, so `--by` alone, a lift only the run log has (or a replayed one), an old line or a line typed for an earlier block lift nothing, a lift of 3 failed goals reaches only those goals whatever `--now` says, and a fresh checkout keeps a lifted block lifted. `/aloop:mission` counts a lift among the typed grants it relays. A lift recorded before this (run data only) no longer counts. diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 1e7a41cd..5ac08c6e 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -483,7 +483,7 @@ Each task flips only its own row here and in TRACKING.md. | M9.45 | DEFINE_JOURNEYS names who writes a journey's runner (the program its pinned `runner.command` runs) and where it lives, and the journey check refuses a runner that does not exist yet. Reason: found designing the live run (M9.13), `market-researcher.md` derives the steps and pass criteria, `state-assessor.md` runs the pinned runner, and no persona or prompt says who writes it | M9.3, M9.9 | `plugin/agents/market-researcher.md`, `plugin/mission/journeys.py`, `mission-journeys.test.py` | yes | open | | M9.46 | `aloop mission due` is not read-only for a dispatched agent: it records the handout tick of a human action, so only the supervisor or the cron may run it (or `due --peek` for anyone). Reason: found designing the live run (M9.13), `roles.json` lists `due` as read-only, so a builder's `aloop mission due` marks a BLOCKED or STOP_BUDGET as told inside its own transcript and the cron stays silent | M9.8, M9.9 | `plugin/mission/roles.json`, `plugin/bin/gate-mission-scope`, `mission-scope-bash.test.py` | yes | open | | M9.47 | Computed command text: a `$VAR` program or argument (`M=npm; $M publish`, `B=main; git push origin $B`), `eval "$X"`, `sh -c "$(…)"`, and a group's output into a shell (`(echo X) | bash`). Read what is knowable (an assignment earlier in the line, echo/printf/cat output) and name the backstops for the rest (M9.34 pre-push, M9.36 provenance). Reason: the M9.30 third review; the gate reads static text, so this class is open (before M9.30 too) | M9.30 | `plugin/mission/doors.py`, its test | yes | open | -| M9.50 | A goal whose intents were all sprinted and whose eval still lists gaps gets a next step (re-plan the open gaps as intents, or a recorded retirement so a new goal can be derived). Reason: found wiring M9.28, `goal close` refuses an unmet goal and `goal next` has no intent left, so the loop can only hand it to the human | M9.11 | `plugin/mission/goal.py`, `mission-goal.test.py`, then `tick.py` | yes | done: `mission-goal.test.py` check 13, `mission-tick.test.py` checks 28 and 33, `mission-roles.test.py` (the planner's stop). The call: retirement, not a re-plan (a re-plan of the same gaps repeats work the sprints already tried; the 3-failed-goals breaker bounds a run of retirements). `mission goal retire GOAL --eval EVAL` records `goal.retired` (role `mission-planner`, in `LEDGER_EVENTS`, gate-owned) when the goal is the content `derive` recorded, active and not met; every gap has an intent and every intent of the goal (a second one for a gap included, which `goal next` hands out too) was sprinted and its sprints closed; and EVAL is the newest eval, narrowed to the goal and not met, made after the last close from the newest state report, itself measured after that close. The record is written before the status (a bare `retired` status is repaired, never trusted). A retired goal takes no intents, sprints or close; `evaluate` covers the whole mission again (`active_goal` is only ever the newest goal); and the retired goal's own open gaps (the record's `open`) are held from `derive` on that baseline until a new version, the human's lift of that hold or their next approval of the mission, while a regression is never held (every gap held → `BLOCKED` with grant `GOALS`, which `tick --force --by` and the human's `lift` line clear). `tick` hands out `RETIRE_GOAL` from the gate's own rule (`goal.retire_problems`): a refusal the loop fixes itself is its `ASSESS` or `EVALUATE`, any other is `BLOCKED` with the gate's reason; a retirement, by its record, counts toward the 3-failed-goals block. At the planner's stop the goal check's `retired` state is the planner's finding (`roles.json` verdicts) | +| M9.50 | A goal whose intents were all sprinted and whose eval still lists gaps gets a next step (re-plan the open gaps as intents, or a recorded retirement so a new goal can be derived). Reason: found wiring M9.28, `goal close` refuses an unmet goal and `goal next` has no intent left, so the loop can only hand it to the human | M9.11 | `plugin/mission/goal.py`, `mission-goal.test.py`, then `tick.py` | yes | done: `mission-goal.test.py` check 13, `mission-tick.test.py` checks 28 and 33, `mission-roles.test.py` (the planner's stop). The call: retirement, not a re-plan (a re-plan of the same gaps repeats work the sprints already tried; the 3-failed-goals breaker bounds a run of retirements). `mission goal retire GOAL --eval EVAL` records `goal.retired` (role `mission-planner`, in `LEDGER_EVENTS`, gate-owned) when the goal is the content `derive` recorded, active and not met; every gap has an intent and every intent of the goal (a second one for a gap included, which `goal next` hands out too) was sprinted and its sprints closed; and EVAL is the newest eval, narrowed to the goal and not met, made after the last close from the newest state report, itself measured after that close. The record is written before the status (a bare `retired` status is repaired, never trusted). A retired goal takes no intents, sprints or close; `evaluate` covers the whole mission again (`active_goal` is only ever the newest goal); and the retired goal's own open gaps (the record's `open`) are held from `derive` on that baseline until a new version or the human's next approval of the mission, while a regression is never held; every gap held is `BLOCKED` with grant `GOALS` on the newest retired goal, which `tick --force --by` and the human's `lift` line clear (the lift is dated by the goal id the block names, so an edited goal file still lifts). `goal next` hands every goal intent to `intent check`, so a retry intent whose file is gone or broken is named instead of skipped. `tick` hands out `RETIRE_GOAL` from the gate's own rule (`goal.retire_problems`): a refusal the loop fixes itself is its `ASSESS` or `EVALUATE`, any other is `BLOCKED` with the gate's reason; a retirement, by its record, counts toward the 3-failed-goals block. At the planner's stop the goal check's `retired` state is the planner's finding (`roles.json` verdicts) | | M9.51 | Lifting a block (`mission tick --force --by`) is the human's own words: it asks (exit 3) for their typed `lift ` line, the code bound to this occurrence of the block (its key, the lifts of it so far, and the handout that tripped it or the newest failed goal), and records a `mission.lifted` ledger row (`APPROVAL_EVENTS`, `GRANT_VERBS`); a repeat restarts only at that row's own run-log event (first copy), and the 3-failed-goals count only up to the goals the human lifted; `/aloop:mission` counts a lift among the typed grants. Reason: found after M9.17 merged, `--by` alone still lifted a block and the lift was run data, so a fresh checkout blocked again (M9.24's first part) | M9.8, M9.12, M9.17 | `plugin/mission/tick.py`, `plugin/bin/_mission.py`, `plugin/bin/_events.py`, `plugin/skills/mission/`, `scripts/test/mission-{tick,skill}.test.py` | yes | done: `mission-tick.test.py` check 30 (`--by` alone, a run-log-only or replayed lift, a negated line, another code, an old line and a line typed for an earlier block lift nothing; a far `--now` lifts no later goals; a fresh checkout keeps a lift), `mission-skill.test.py` check 8 | | M9.52 | `tick` reads a gap list only when it still recomputes from its inputs, as `evaluate check` does (an intact eval that a changed `compute`, an edited journey or goal no longer reproduces asks for `EVALUATE`). Reason: found in M9.27's review, `tick` reads the record, shape and seal but not the recomputation (the tick test's synthetic evals cannot recompute), so after an upgrade that changes `compute` `goal derive` refuses while `tick` hands out `DERIVE_GOAL` until it blocks | M9.27 | `plugin/mission/tick.py`, `mission-tick.test.py` (real evals in its synthetic sections) | yes | open | | M9.53 | `tick` hands out a goal's commands (`PLAN_INTENTS`, `SPRINT`, its close) only when `goal check` passes, else names the goal's problem. Reason: found in M9.27's review, a goal whose source eval changed or is gone (or one derived before evals were ledger records) gets `PLAN_INTENTS` 3 times while `goal intents` refuses, then `BLOCKED` with no cause named (M9.43 is one case of it) | M9.11, M9.28 | `plugin/mission/tick.py`, `mission-tick.test.py` | yes | open | diff --git a/plugin/mission/goal.py b/plugin/mission/goal.py index 399d1e4c..807df9b1 100644 --- a/plugin/mission/goal.py +++ b/plugin/mission/goal.py @@ -123,8 +123,8 @@ def split_held(cwd, gaps, edoc=None): """(open, held): a gap whose summary a hard line fixed is held for good (ethics.hard_words), so a goal derived again never takes it and the loop moves on to the next gap. A gap a retired goal left open is held too (M9.50: its sprints already tried it), on that eval's baseline, until a new - baseline version, the human's lift of that hold (`tick --force`) or their next approval of the - mission; a regression is never held. Each held gap names what holds it.""" + baseline version, the human's next approval of the mission or their lift of the block tick sets + when every gap is held (`tick --force`); a regression is never held. Each held gap names what holds it.""" hard, ids = E.hard_words(cwd), E.held_gaps(cwd) tried = retired_gaps(cwd, edoc.get("baseline_id")) if isinstance(edoc, dict) else {} held = [] @@ -355,8 +355,8 @@ def cmd_derive(cwd, o): stuck = [g for g in held if g["gap_id"] in want] if stuck: report(["%s held by %s: no goal takes it (a hard line: aloop mission ethics check; a retired goal's gap: " - "a new baseline version, the human's `aloop mission tick --force --by NAME` or their approval " - "of the mission frees it)" + "a new baseline version or the human's approval of the mission frees it, and so does their " + "`aloop mission tick --force --by NAME` once every gap is held)" % (", ".join(g["gap_id"] for g in stuck), stuck[0]["held_by"])], []) return 2 missing = [x for x in want if x not in by_id] @@ -529,24 +529,26 @@ def cmd_next(cwd, gid): if e.get("event") in ("plan.created", "plan.revised") and isinstance(e.get("data"), dict) and isinstance(e["data"].get("intent_id"), str)} # each gap's intent in the goal's order, then any later intent of the goal (a retry for a gap): every - # intent `mission tick` and `goal retire` count is handed out here - queue = [have[gap["gap_id"]] for gap in g["gaps"] if gap["gap_id"] in have] - first = {it.get("intent_id") for _, it in queue} - for iid in goal_intent_ids(cwd, gid): - p = os.path.join(_paths.docs(cwd), "intents", "%s.json" % iid) - doc, _ = M.load(p) - if iid not in first and isinstance(doc, dict) and doc.get("intent_id") == iid: - queue.append((p, doc)) - for p, it in queue: - if it.get("intent_id") in planned: + # intent `mission tick` and `goal retire` count is handed out here, and one whose file is gone or + # broken goes to `intent check`, which names it + queue = [(p, it.get("intent_id")) for p, it in (have[gap["gap_id"]] for gap in g["gaps"] if gap["gap_id"] in have)] + first = {iid for _, iid in queue} + queue += [(os.path.join(_paths.docs(cwd), "intents", "%s.json" % iid), iid) + for iid in goal_intent_ids(cwd, gid) if iid not in first] + for p, iid in queue: + if iid in planned: continue - others = [os.path.getmtime(x) for x in glob.glob(os.path.join(os.path.dirname(p), "int_*.json")) if x != p] - t = max(others + [time.time()]) + 0.01 - os.utime(p, (t, t)) # gate-intake re-checks the newest intent file: the one handed off + if os.path.isfile(p): + others = [os.path.getmtime(x) for x in glob.glob(os.path.join(os.path.dirname(p), "int_*.json")) + if x != p] + t = max(others + [time.time()]) + 0.01 + os.utime(p, (t, t)) # gate-intake re-checks the newest intent file: the one handed off r = subprocess.run([os.path.join(BIN, "intent"), "check", p, "--mode", facts["autonomy"]], cwd=cwd, capture_output=True, text=True) sys.stderr.write(r.stderr) if r.returncode: + print("[goal] %s's next intent %s does not pass `intent check` (%s): the planner fixes it" + % (gid, iid, M.rel(cwd, p)), file=sys.stderr) return r.returncode print(p) return 0 diff --git a/plugin/mission/tick.py b/plugin/mission/tick.py index 6ce9a8a9..c9390cda 100644 --- a/plugin/mission/tick.py +++ b/plugin/mission/tick.py @@ -932,10 +932,11 @@ def lifted(data): def lift_of(f, d): """This block's lift: its key, how many lifts of that key the ledger has, and the occurrence: for - 3 failed goals the newest one's time (the reset reaches that far, whatever the clock says), for - a repeat the handout that tripped it. So a line typed for one block never lifts another.""" + 3 failed goals or a retired goal's held gaps the newest goal's time, from the id the block names (the + reset reaches that far, whatever the clock or the goal's file says), for a repeat the handout that + tripped it. So a line typed for one block never lifts another.""" if d["grant"] == "GOALS": - at = max([g["ms"] for g in f["kinds"]["goal"] if g["ref"] == d["subject"]] or [0]) + at = ms_doc({"goal_id": os.path.splitext(os.path.basename(d["subject"]))[0]}, "goal") else: at = next((e.get("event_id") for e in reversed(f["ticks"]) if e["data"].get("key") == d["grant"] and e["data"].get("who") in ("role", "supervisor")), "") diff --git a/scripts/test/mission-goal.test.py b/scripts/test/mission-goal.test.py index 03c2a6fa..0485eb5c 100644 --- a/scripts/test/mission-goal.test.py +++ b/scripts/test/mission-goal.test.py @@ -478,6 +478,10 @@ def refused(eid, *words): refused(em["eval_id"], "intent %s has no plan yet" % i3) ip3 = os.path.join(p4.dir, "docs", "agents", "intents", i3 + ".json") d3, d1 = json.load(open(ip3)), json.load(open(G.goal_intents(p4.dir, gk)[em["gaps"][0]["gap_id"]][0])) +for broken in (None, "{", json.dumps(d1)): # gone, unreadable, another intent's copy + os.remove(ip3) if broken is None else open(ip3, "w").write(broken) + r = p4.run("goal", "next", gk) # `next` names the file it cannot hand out + assert r.returncode == 2 and i3 in r.stderr and "BLOCK[intent]" in r.stderr, (broken, r.returncode, r.stderr) d3.update({k: d1[k] for k in ("actor", "want", "why", "done_looks_like", "success_scenarios", "failure_scenarios")}) json.dump(d3, open(ip3, "w")) # the planner fills it, as intake would r = p4.run("goal", "next", gk) diff --git a/scripts/test/mission-tick.test.py b/scripts/test/mission-tick.test.py index 590bf81d..34d9a7c9 100755 --- a/scripts/test/mission-tick.test.py +++ b/scripts/test/mission-tick.test.py @@ -1366,7 +1366,7 @@ def lifts(p): assert p.mi("evaluate").returncode == 0 held = "held (%d by retired goal %s)" % (n, gid) # its sprints already tried every gap expect(p.tick(later(p), "--peek"), "BLOCKED", 2, held) -json.dump(dict(p.load("goal", gid), status="active"), open(gp, "w")) # the record decides +json.dump(dict(p.load("goal", gid), status="active", note="tried"), open(gp, "w")) # the record decides shutil.rmtree(os.path.join(p.dir, ".aladdin")) # a fresh checkout keeps the retirement d = p.tick(later(p), "--peek") expect(d, "BLOCKED", 2, held)