8000 M11.12: task diff stays in its planned fileset; reasoned two-way exemptions, no human by adeelahmad · Pull Request #123 · adeelahmad/aloop · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ tag in lockstep. Tag releases as `vMAJOR.MINOR.PATCH`.
## [Unreleased]

### Added
- A task's diff stays in its planned fileset, with worker-declared exemptions (ROADMAP M11.12): `targets diffscope` (GREEN and RED stop gates) judges the diff against the task's targets' paths and planned tests, literally. A new test file passes; an existing test outside the plan may only gain lines (GREEN and RED can no longer weaken or delete another task's test). A production file the plan missed passes only as a `### Scope exemptions` line (`- <path>: <reason>`) in the worker's output.md block: a literal path, a reason of 4+ words, at most 3 (`ALOOP_SCOPE_EXEMPT_MAX`), never a one-way path (CI, VCS config, agent settings, secrets, migrations, licences, run data); each one taken is a `scope.exempted` ledger row, with no human step. The contract's SCOPE_GLOBS can only narrow the plan, a task with no targets gets no free scope, `targets check` refuses a glob path, a production file under a nested `target/` (no Cargo.toml beside it) is judged, and non-ASCII paths are read unquoted. Test: `scripts/test/task-scope.test.py`.
- Plan approval is a gate (ROADMAP M0.9): `gate-dispatch` starts no execution role (RED, SCAFFOLD, GREEN, structural review, final gate) of a sprint until the human approved that sprint's plan as it is now. `events authority --sprint N` exits 3 with the line to type, `approve SN <code>` (reviewed, the code naming the sha256 of the sprint's plan files, its intake and standards included) or `autonomous SN <code>` (autonomy for that sprint, re-plans included, the code naming the authority record); the task contract's `STORY_DIR` and task must be a live story and task of that plan's frozen `ids.json`; the line must be among the human's captured prompts and typed after the sprint's last decision (M9.17's mechanism). A changed plan, a re-plan in reviewed mode, a roll-back to an old line, another sprint's line, a negated line and a hand-edited or emitted record all block (`plan.approved` and `human.approval` cannot be `events emit`ted); an approved autonomous mission grants its own sprints autonomy with no line. `events approval SPRINT|TASK_ID` is the check. Codex's `spawn_agent` (`agent_type`, `message`) and OpenCode's `task` now reach `gate-dispatch` too, and `claude -p`, `codex exec` and `opencode run` from a tool call are blocked in every aloop project, not only where a mission is set. `e2e-live.sh` pre-approves with an `autonomous S1 <code>` line in its prompt. Reason: the north star allows no human help beyond approval, and the approval was a playbook rule a supervisor could skip. A 4-lens adversarial review found 9 defects: 7 fixed with a check red on the first head (cross-sprint or unplanned `STORY_DIR`, a retyped line kept stale, mission autonomy over a non-mission sprint, `transcripts prune` dropping the prompts grants cite, `codex plugin add` refused, a code past column 200, a crash on a malformed run-log line), 2 in the playbook (intake reuses a mission's handed-off intent; a reviewed re-plan waits for the human's new line). `transcripts prune` now keeps the human's prompts. Test: `plan-approval.test.py` (20 checks, red on master), plus the host suites. The approved plan's files include the sprint's `intake.md` and `standards.md`, and a grant pins them file by file: GREEN's check for an unplanned dependency reads only the text the human's grant pins, the plan they approved or, under their autonomy grant, the plan as the planner's gate last passed it (`gate-stage2-complete` records `plan.gated` on the planner's stop), as it was then, so text added later names nothing and a re-plan does not undo an approved dependency.
- 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] <id>` 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` (46 checks, emulated), `dsh-runtime.test.mjs` (50 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` (10).
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ test-hosts: ## Budget/worktree regression + Codex hooks emulation + OpenCode and
plugin/bin/layout check
plugin/bin/host check
python3 scripts/test/targets-scope.test.py
python3 scripts/test/task-scope.test.py
python3 scripts/test/plan-render.test.py
python3 scripts/test/persona-shapes.test.py
python3 scripts/check-tracking.py
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ structural, not luck:
blocking it from doing the context-heavy work itself.

Live runs: `make smoke-live YES=1` (hook wiring, ~$0.004) and `make e2e-live YES=1` (the whole
loop, ~$1; each run writes `summary.json` and a row for [docs/evidence/](docs/evidence/README.md)). Offline: `make ci`, which runs Rust fmt/clippy/tests, shellcheck, 58 Python/Node suites plus every `mission-*.test.py`,
loop, ~$1; each run writes `summary.json` and a row for [docs/evidence/](docs/evidence/README.md)). Offline: `make ci`, which runs Rust fmt/clippy/tests, shellcheck, 59 Python/Node suites plus every `mission-*.test.py`,
the gate conformance fixtures (`make conformance`) and eval-suite validation. Every ROADMAP
requirement is tracked with its test in [docs/TRACKING.md](docs/TRACKING.md).

Expand Down
3 changes: 2 additions & 1 deletion docs/OVERVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ The model can ignore a skill; it cannot ignore an exit code.
3. **Execution** — human absent. For each task, a worker runs in its own git worktree:
- **RED** writes tests that must fail *by assertion* and touch no production code;
- **SCAFFOLD** creates each planned symbol exactly once, as a stub;
- **GREEN** makes the tests pass inside the task's scope, with zero suppressions;
- **GREEN** makes the tests pass inside the task's planned fileset (a production file the plan
missed only as a declared, reasoned, recorded exemption), with zero suppressions;
- **STRUCTURAL-REVIEW** looks for orphan, parallel or duplicate code.
8000 Work merges only on a passing gate. A failed gate re-prompts the worker; repeated
failure goes to the supervisor, who acts on facts from `sweep` (accept, retry, re-plan,
Expand Down
3 changes: 3 additions & 0 deletions docs/ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,9 @@ missions stay, opt-in through config or the intent (`aladdin --reviewed "<intent
| M11.10 | A door-classifier decides before execution: a planning-route role, dispatched after the planner, tags every task one-way (`mission doors tag TASK --door ID`) or two-way; `mission doors plan SN` lists the plan's open one-way doors together so the human is asked once; its stop gate (`gate-door-plan`) refuses to finish while a task is untagged or a wall is planned; `gate-dispatch` parks only a task whose door is not authorized. Tags only add. Reason: the owner asked who decides one-way vs two-way; a list checked only at the tool call asks mid-run, after work was built on it. |
| M11.11 | The classification is overridable only with the human's consent: `ALOOP_DOORS_TWO_WAY=<door,…>` (an agent may set it) makes a listed door two-way only while a `door.reclassified` ledger row holds, and that row counts only in the human's typed line `two-way door:<id> <code>` (M9.17, so an agent cannot forge it); walls and question-only doors are never reclassified; `revoke` closes it. Reason: the owner asked for an env override with user consent. |
| M11.9 | Measured: `make e2e-live` runs one intent with no approval line in the prompt to merged code, and a two-sprint intent chains with zero human messages after the intent (`stats` human messages = 1). Reason: the north star, measured. |
| M11.12 | ✅ A task's diff stays in its planned fileset, and a worker steps out of it on its own reasoned word, never a human's: `targets diffscope` (GREEN and RED stop gates) judges base..worktree against the task's targets' paths and planned tests, literally; a new test file passes, an existing test outside the plan may only gain lines; a production file the plan missed passes only as a `### Scope exemptions` line in the worker's output.md block (`- <path>: <reason>`, a literal path, 4+ words, at most `ALOOP_SCOPE_EXEMPT_MAX`=3, never a one-way path: CI, VCS config, agent settings, secrets, migrations, licences, run data), each a `scope.exempted` ledger row. The contract's SCOPE_GLOBS only narrows; `targets check` refuses a glob path. Test: `scripts/test/task-scope.test.py` (31 checks; 9 of the 19 GREEN rows held before). Reason: the 2026-11-19 audit found GREEN could weaken or delete another task's test, hide a file under a nested `target/`, and be widened by the contract or a planner glob, and that the plan had no exemption path, so an honest out-of-plan edit could only fail and re-plan. |
| M11.13 | Live scope enforcement: a PreToolUse check refuses a worker's write outside its planned fileset at the tool call (with the same exemption rule) instead of only at its stop gate, and a structural-review rule reads `scope.exempted` rows. Reason: today a stray edit costs a whole attempt before the stop gate refuses it, and exemptions are recorded but nothing reviews them. |
| M11.14 | A worker's write outside its worktree is refused on Claude Code too: on Codex and dsh `host-adapter` confines a writer to its worktree, but Claude Code is trusted to isolate natively, and a Write with an absolute path into the main tree lands outside every diff the scope gate reads. Reason: found in the 2026-11-19 scope audit; M10.1 (host sandbox) is the full fix, this is the cheap deterministic one. |

Kept human on purpose (security or the human's own limits; they stop only their own item): one-way door
authorizations, spend past the cap, a hard ethics line, `aloop stop --clear`, and changing the intent.
Expand Down
1 change: 1 addition & 0 deletions docs/TRACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,4 @@ Status of every requirement in [ROADMAP.md](ROADMAP.md), in the four states §8
| M11.9 | Live run: one intent to merged code with no human message after it | IMPLEMENTED_UNTESTED | run 54 (docs/evidence/README.md): one sprint, intent only, 12/12; the two-sprint chain waits on M11.5 |
| M11.10 | A door-classifier tags every planned task one-way or two-way before execution; only one-way tasks wait, asked together | IMPLEMENTED_TESTED | `scripts/test/mission-door-plan.test.py` |
| M11.11 | A door is made two-way only by an env var plus the human's typed consent | IMPLEMENTED_TESTED | `scripts/test/mission-doors-reclassify.test.py` |
| M11.12 | A task's diff stays in its planned fileset; a worker steps out only by a declared, reasoned two-way exemption the gate decides and records | IMPLEMENTED_TESTED | `scripts/test/task-scope.test.py` |
6 changes: 5 additions & 1 deletion plugin/agents/green-worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ your init block's `### Budget` line has the exact numbers). Plan for it:

## Hard limits
- No new tests; no refactor a test does not force.
- Touches only files named in tasks.md (+ the RED test file, to drop shims).
- Touches only the files its plan names (its targets' paths and planned tests; RED's test file, to
drop shims). A two-way production file the plan missed: declare it in your output.md block as
`### Scope exemptions` then `- <path>: <why the plan missed it, 4+ words>` (at most 3; never CI,
VCS config, agent settings, secrets, migrations or licences: those need a re-plan). The gate
decides and records each one; never change or delete another task's existing test.
- Never reaches green by suppressing/weakening a test.
- Adds no dependency to a manifest (Cargo.toml, package.json, requirements*.txt, pyproject.toml,
go.mod) that the plan does not name; the gate refuses it. Use what the project already has.
Expand Down
1 change: 1 addition & 0 deletions plugin/bin/_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"ethics.reviewed", "ethics.consent", "ethics.blocked",
"telemetry.consent", "telemetry.revoked", "telemetry.setup", "telemetry.report",
"judge.run",
"scope.exempted",
"door.authorized", "door.revoked", "door.reclassified", "door.tagged", "door.denied", "door.crossed",
}
ENVELOPE = ("schema", "event_id", "ts", "event", "ids", "parent_event_id", "caused_by", "role", "host",
Expand Down
26 changes: 17 additions & 9 deletions plugin/bin/gate-green-verify
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,30 @@ validate_comms
# 2) No suppression anywhere (RED is cleared by GREEN, never by skipping).
assert_no_suppression

# 3) Diff scope: only files this task may touch (tasks.md scope) + its RED test file.
# No SCOPE_GLOBS given but the planner wrote change targets? Derive it (ROADMAP §4.6).
if [ -z "${SCOPE_GLOBS:-}" ] && [ -n "${STORY_DIR:-}" ] && [ -f "$STORY_DIR/targets.json" ]; then
SCOPE_GLOBS="$("$HERE/targets" scope "${TASK_ID##*-}" "$STORY_DIR" 2>/dev/null)"
[ -n "$SCOPE_GLOBS" ] && note "SCOPE_GLOBS derived from targets.json: $SCOPE_GLOBS"
fi
if [ -n "${SCOPE_GLOBS:-}" ]; then
: "${TEST_GLOBS:=$DEFAULT_TEST_GLOBS}" # its RED test files, to drop shims (any language)
# 3) Diff scope: only the files this task's plan names. With the planner's targets.json that is
# its targets' paths and its planned tests, literally (ROADMAP §4.6, M11.12): a new test file
# passes, an existing test outside the plan may only gain lines, and a production file the plan
# missed passes only as a declared, reasoned two-way exemption (`targets diffscope`, a ledger
# row each). The contract's SCOPE_GLOBS can only narrow that. No targets.json: SCOPE_GLOBS.
: "${TEST_GLOBS:=$DEFAULT_TEST_GLOBS}" # its RED test files, to drop shims (any language)
if [ -n "${STORY_DIR:-}" ] && [ -f "$STORY_DIR/targets.json" ]; then
scope_base="$(diff_base)"
[ -n "$scope_base" ] || fail "cannot find where this task's branch left main (BASE_REF unset, no merge-base): the diff scope cannot be judged"
if ! scope_out="$("$HERE/targets" diffscope "${TASK_ID##*-}" "$STORY_DIR" --base "$scope_base" --root "$(repo_dir)" \
--role green --task-id "${TASK_ID:-}" --agent-role "${AGENT_ROLE:-}" --tests "$TEST_GLOBS" --globs "${SCOPE_GLOBS:-}" 2>&1)"; then
fail "GREEN diff is outside this task's plan:
$scope_out"
fi
note "diff in this task's planned fileset${scope_out:+ ($scope_out)}"
elif [ -n "${SCOPE_GLOBS:-}" ]; then
allow="$SCOPE_GLOBS $TEST_GLOBS"
while IFS= read -r p; do
[ -z "$p" ] && continue
path_matches_any "$p" "$allow" \
|| fail "GREEN diff touches out-of-scope path: $p (allowed: $allow)"
done < <(changed_paths)
else
warn "SCOPE_GLOBS unset; tasks.md diff-scope check skipped (set it to enforce R2)"
warn "SCOPE_GLOBS unset and no targets.json; tasks.md diff-scope check skipped (set it to enforce R2)"
fi

# 3b) Supply chain: no dependency the approved plan does not name (ROADMAP M10.2).
Expand Down
9 changes: 9 additions & 0 deletions plugin/bin/gate-red-verify
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ while IFS= read -r p; do
|| fail "RED diff touches a non-test path: $p (allowed: $TEST_GLOBS). RED writes tests only: put shims in tests/common/mod.rs (marked // agentic:shim), then undo the change and commit: git checkout ${BASE_REF:-<base>} -- '$p' (a new file: git rm '$p'), then git commit -am 'RED: tests only'"
done < <(changed_paths)

# 3a) An existing test outside this task's plan may only gain lines: RED never deletes or rewrites
# another task's proof (targets diffscope; new test files pass).
if [ -n "${STORY_DIR:-}" ] && [ -f "$STORY_DIR/targets.json" ] && red_base="$(diff_base)" && [ -n "$red_base" ]; then
red_out="$("$HERE/targets" diffscope "${TASK_ID##*-}" "$STORY_DIR" --base "$red_base" --root "$(repo_dir)" \
--role red --task-id "${TASK_ID:-}" --tests "$TEST_GLOBS" 2>&1)" \
|| fail "RED changes a test outside this task's plan:
$red_out"
fi

# 3b) Format: RED's files must pass the matrix's format check (GREEN may not reformat them).
run_format_checks

Expand Down
Loading
Loading
0