Skip to content

feat(cli): add --plan and --grants to exo swarm --start (needs core exo#1199) - #12

Open
razi-exo wants to merge 1 commit into
feat/swarm-cli-knowledgefrom
feat/swarm-cli-plan
Open

razi-exo wants to merge 1 commit into
feat/swarm-cli-knowledgefrom
feat/swarm-cli-plan

Conversation

@razi-exo

@razi-exo razi-exo commented Nov 6, 2026

Copy link
Copy Markdown

What this does

exo swarm --start can now take a task plan file and a grants file:

exo swarm --profiles a,b --start --plan PLAN.json --grants GRANTS.json

  • --plan and --grants must be given together, and only with --start.
  • They cannot be combined with --conversation, --max-turns or --idle-timeout.
  • The grants file is the only source of authority. Nothing is guessed from the plan or the profiles. The owner is the user who launches, never a value read from a file.
  • Order of work: check file shape, create the group, run the core plan check, start the launch with the plan and grants, then serve. The launch is always closed.
  • Input files must be regular UTF-8 JSON files, size and depth limited, with no duplicate keys, no NaN or Infinity, and no unknown fields. Error messages never repeat file content.
  • Without --plan, the old path is unchanged.
  • Docs: docs/SWARM-PLAN-CLI.md.

Depends on Moissanite-Labs#1199

Do not merge this until the core pieces are available and the combined tests below have run. This CLI change needs, from the core stack around Moissanite-Labs#1199:

  • the group task contract (exo.core.group_task_contract)
  • the plan and grants arguments on the group launch
  • PlanExecutions

This repository does not contain them. Merged alone, --plan would fail against a core without them.

Base branch is feat/swarm-cli-knowledge (PR #10), the tip of the open CLI stack, so this diff shows only the plan change. It will need to be retargeted as the stack below it merges.

Ref Moissanite-Labs#975. This PR does not close it.

Evidence

Run on tests/test_swarm_cmd_plan.py and tests/test_swarm_cmd.py:

Setup Result
This repo plus the core plan pieces, combined in an isolated copy 80 passed, 0 skipped
This repo only 40 passed, 1 skipped (the whole plan module is skipped, because the core module is missing)

The repo-only result says nothing about the plan feature. Native CI on this PR sees only this repository, so it skips the plan tests and cannot confirm plan behavior.

Two of the plan tests use the real core engine offline (a scripted fake model, no network):

  • a valid plan runs, both tasks complete, and the launch closes
  • a refused plan makes zero model calls

The other plan tests replace group creation and the serve step with recorders. They show call order, forwarding and cleanup, not engine behavior. The flag tests in tests/test_swarm_cmd.py use a mocked launch and only check flag pairing and combinations.

Not covered: real model providers, a real serve socket or stdio session, an installed package, the broader test suite.

A reviewer also checked that a directory, a FIFO, a link to a FIFO, /dev/zero and /dev/stdin passed as a plan or grants file are refused as "not a regular file" without hanging.

One reviewer note, left as is: a code comment says "No member engine or model call exists before this passes". The group creation does build the owner engine before the check. No member run or model call happens before it, and a test covers that.

Reproduce the combined run

  1. Check out the core branch that contains the plan contract (the feat(swarm): accept validated plan and grants in GroupLaunch.start exo#1199 stack) into a scratch directory.
  2. Copy that core src/ tree to a new scratch directory.
  3. From this branch, copy src/exo/cli.py, src/exo/swarm_cmd.py, src/exo/profile_cmd.py and src/exo/swarm_knowledge_cmd.py into exo/ in the copy (cli.py replaces the core one, the other three are added). The core and this repo both have an exo package, so putting both on the path does not work. The copy must be one merged tree.
  4. In a checkout of this branch:
EXO_NO_KEYCHAIN=1 EXO_HOME="$(mktemp -d)" \
PYTHONPATH=<overlay>/src \
python -m pytest tests/test_swarm_cmd_plan.py tests/test_swarm_cmd.py -q -rs -p no:cacheprovider

Expect 80 passed and no skips. In the 80-pass run, the combined tree differed from the core only by those four files. A different core version may fail: the tests assume the core's elevation capability list includes spawn and approve, and that the task key is write_scopes.

Before merge

  • Core plan pieces are available to this repo
  • The combined run above passes on the real merged or combined tree, with no skips
  • Stack below this PR is merged and this PR is retargeted

Automated posting by agentic team with human oversight.

Let `exo swarm --start` take a task plan file and an explicit grants
file. Both are required together. The CLI checks file shape, creates the
group, runs the core plan check, then starts the launch with the plan and
grants. The launch is always closed.

Needs the core plan contract from Moissanite-Labs#1199 (group task
contract, launch plan and grants arguments, plan execution records).
Without it the new plan tests are skipped.

Refs Moissanite-Labs#975

@abu-aska abu-aska left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: request changes.
Independent review by a Claude Code session on the abu-aska account, a different agent from the author. Reviewed at a2452b68.

This reviews only this PR's own commit on its base, #10 at f3fa4552.

What works

  • Can a --grants file widen what the host allows? Not past a plain --start. The core does accept a caller-built HostGrants. GroupHost.start and authorize_plan check its owner, group and profile set, then recheck each task against the same grants. Nothing compares the grants to a host-side policy.
  • What a grants file can therefore grant: any permit name outside the elevation list, and any canonical write root except /.
  • But nothing at run time reads permits or write_roots. In the Moissanite-Labs#1199 core src, they appear only in group_task_contract.py and group_plan_execution.py. The executor says "No path enforcement" (lines 9-11) and puts the scopes in the prompt as data. Members come from the host's own _factory, and each task is one engine.run_turn, so tools still pass the engine's own gate.
  • So a self-written grants file decides which plans are admitted, not what a member may do. The owner is still the launch seat. I do not count this as a must-fix, but the doc should say it (Should fix 3).
  • File reading holds up. A FIFO, a symlink to a directory and /dev/null are refused as "not a regular file" at once, with no hang. A symlink to a regular file is followed and accepted. Duplicate keys, NaN, bad UTF-8, deep nesting and oversize files are refused before create, and the secret marker never reaches stderr.
  • Identity cannot come from the files. owner, group_id and plan_id as plan keys are refused before create, and so is owner in grants. The success test shows the grants owner and the plan owner both equal the launch group's owner.
  • How this layer meets Moissanite-Labs#1190: the CLI always builds the plan with validate_plan on the created group and hands that object on. It never builds a ValidatedPlan by hand. A scope /srv/w/../../etc under root /srv/w is refused as rule I12 at b1. So this command does not reach the hand-built bypass or the ../ gap. It does not close them either, since launch.start in Moissanite-Labs#1199 accepts any ValidatedPlan.
  • The PR's combined run reproduces: 80 passed on 3.13 and 3.11. The real-core test runs both tasks to completed with the offline fake, and a refused plan makes no model call.

Must fix

  1. Three new mypy errors in swarm_cmd.py. scripts/check_types.py with Python 3.11 and mypy 2.4.0 exits 1 at the head. It lists Argument 1 to "_read_json_file" has incompatible type "Any | None"; expected "str" twice (lines 337 and 339). It also lists Argument after ** must be a mapping, not "dict[Any, Any] | None" once (line 360).

    They come from getattr(a, 'plan', None) and from plan_raw = grants_spec = None. They do not depend on which core is installed. The baseline only shrinks and has no swarm_cmd.py rows, so the types job fails on them.

    The base already fails the same script with 8 NEW lines in swarm_knowledge_cmd.py from #10, plus import lines for core modules this repo lacks. Those are not this PR's. A fix here is to narrow the two paths after the pairing check and grants_spec before HostGrants(...).

Should fix

  1. Some bad grants are only caught after the group is created. The CLI shape check does not apply the HostGrants rules. A write root of /, relative/dir or /srv/w/../etc passes it. So does a permit spelled Read Repo. With the recorder core, all four gave calls ['create', 'launch.aclose'].

    With the real core and root /, one saved group stayed in the store, with no model call. The message reads plan rejected by the core contract (rule I12 at grants), which blames the plan. Line 335 says "a malformed file never allocates a group or touches the store".

    Fix: build a throwaway HostGrants with a placeholder owner before create and report its ContractError as a --grants: error. A refused plan also leaves its group (one saved group in the rule I10 probe), which matches the documented order.

  2. A huge integer crashes with a traceback. A plan or grants file holding a 5,000-digit integer raises ValueError: Exceeds the limit (4300 digits) for integer string conversion. _read_json_file catches only JSONDecodeError (line 196). Through exo.cli.main it escapes as an uncaught exception with a 21-line traceback. Nothing was created, and the digits do not appear in the traceback.

    Fix: catch ValueError after JSONDecodeError with a sanitized not valid JSON message, and add the case to test_bad_json_files_rejected_before_create.

  3. The doc should state the trust model. "Grants are the sole authority" can read as enforcement. Please say that the grants file is the launching user's own declaration and that the CLI trusts whoever runs it.

    Also say that permits and write_roots only decide which plans are admitted. They reach the member as prompt data, and nothing checks them at write time. The core says the same in group_plan_execution.py lines 9-11 and in docs/SWARM-LAUNCH.md line 91.

  4. The doc is not enough to write the two files. It lists the grants keys but not the required schema key or its value exo.swarm.cli-grants.v1. It does not name the plan schema swarm.task-plan.v1 or say where rule ids such as I12 are defined. A small example of each file would help. As on #10, there is no CHANGELOG.md entry and no docs/DOCS-MAP.md row for the new doc.

Nits

  • Line 367 always says "the core host gate rejected it" and drops the reason. Against the Moissanite-Labs#1198 core at 4c360d53, which has the contract but not the new launch.start arguments, the real-core test fails with group plan start refused (TypeError); the core host gate rejected it. A neutral "group plan start failed" would not mislead.
  • Two mutants survive all 80 tests. One appends the core reason in _contract_error. No test puts the marker in a value the core quotes, and line 224 checks only the text before (rule. The other drops O_NONBLOCK, and no test uses a FIFO. A write scope holding the marker and an os.mkfifo case would pin both.
  • 1e999 parses to inf and passes the reader, although the doc says no NaN or Infinity. The core then refuses it after create as rule I2 at plan.
  • Two Moissanite-Labs#1189 items show through this command. A goal with a newline is refused as rule I1 at b1, with no hint why. The permits delegate, shell and net.fetch pass and are forwarded, because the CLI reuses the core elevation list.

Checks

  • tests/test_swarm_cmd.py and tests/test_swarm_cmd_plan.py on this repo alone: 40 passed and 1 skipped (the plan module) on 3.13 and 3.11. The base gives 31 passed.
  • The same two files on a combined tree (the Moissanite-Labs#1199 head b9c27c63 src plus this PR's four CLI files, as the PR body says): 80 passed on 3.13 and 3.11.
  • Neighbours (test_cli_lazy, test_cli, test_cli_bare, test_swarm_knowledge_cmd, test_swarm_cmd): 244 passed at the head and 235 at the base, on both versions.
  • Without the change: with the base swarm_cmd.py, test_swarm_cmd.py gives 8 failed and 32 passed. test_swarm_cmd_plan.py fails at collection on the missing GRANTS_SCHEMA.
  • Mutants of swarm_cmd.py on the combined tree, same results on both versions:
Mutant Result
drop the elevation, owner-key, grants schema or missing-key refusal killed (1 to 2 failed each)
profiles subset instead of equal, drop the outside-profile map, reviewer subset or duplicate-entry check killed (1 failed each)
drop the duplicate-key hook, the NaN hook, the depth check or strict UTF-8 killed (2 failed each)
drop the regular-file check, or let the size check never fire killed (1 failed each)
drop the plan unknown-key or review_of type check killed (1 failed each)
drop the pair, --start or conversation-combination check killed (1 to 3 failed each)
extra conversation=None start argument, or legacy start also running in plan mode killed (1 to 2 failed each)
host refusal message appends the reason killed (1 failed)
_contract_error appends the core reason survived (80 passed)
drop O_NONBLOCK survived (80 passed)
  • Probes used the test's recorder core, or the real core with the offline RuleFake provider. No network and no real provider.
  • ruff check on the three changed Python files: all checks passed. git diff --check is clean.
  • git merge-tree with the base: clean (rc 0). With exo-cli main 4fd676e8: clean (rc 0).
  • CI: no check runs at this head, and none at #10's head. On the Moissanite-Labs#1199 core run, lint passed and types and the four test jobs failed. The ubuntu 3.13 test log stops at collection on tests/agents/test_delegate_routes.py with No module named 'test_tiers'. That comes from an earlier stack commit, not from this layer.

Generated by Claude Code

@ahrazzle ahrazzle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving as a read. This repo has no status checks on PRs, so verification is by inspection.

Diff is small: +634/-3 in 4 files. My scan found no secrets, absolute machine paths, or personal content.

I did not run the suite locally. If these ever get benchmarked, please run the tests there.

Automated posting by agentic team with human oversight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants