remoting/tools/magi-mode/SKILL.md
This skill implements the "Lean MAGI" protocol, a high-efficiency multi-agent framework designed to resolve complex, high-stakes, or ambiguous software engineering problems. It utilizes a "Verification Loop" of specialized technical modules to enforce invariants, detect conflicts, and synthesize code without human management overhead.
The Orchestrator MUST select an execution path based on the task's complexity and ambiguity:
The Orchestrator MUST dynamically select specialized modules best suited for the specific task.
project.magi.json specification.To maintain focus and avoid context dilution, specialized tasks are delegated:
Consolidation: (Rigor Path Only) Condenses raw feedback from multiple
Scanners into a strict list of actionable constraints in
constraints.magi.[iteration].json.
Training: Captures knowledge or systemic gaps discovered during the process and upgrades the Scanner rulesets.
Release: A terminal module invoked with a clean context to handle workspace hygiene, formatting, and final staging/upload of CLs.
TONE MANDATE (SIGNAL-TO-NOISE): To eliminate conversational noise, conserve tokens, and maximize parsing stability, the Orchestrator MUST instruct ALL sub-agents (except itself) to adopt a neutral, data-driven tone.
TOOL AGNOSTIC MANDATE: The protocol instructions MUST remain tool-agnostic.
Do not assume specific tool names (e.g., update_topic, read_file,
write_file). Use generic terms like "read from disk," "save to disk," or
"report status."
ENVIRONMENT GROUNDING MANDATE: All sub-agents MUST read
project.magi.json#environment immediately upon invocation to ground themselves
in the active VCS (JJ or GIT) and Harness (JETSKI or GENERIC_CLI). They
MUST adjust their tool usage and command construction natively to match this
environment. They MUST also ensure that any interim files generated during
execution (e.g., drafts, reviews, logs) are placed in the dedicated subfolder
remoting/tools/magi-mode/.temp/ to minimize permission prompts and maintain
workspace hygiene.
THE CHECKLIST LIFECYCLE STATE MACHINE: The session's verification integrity is governed by a deterministic boolean checklist state machine. The automated checklist state itself only transitions or is modified during three key steps across the stages:
personas/**/*.json, takes the Union Set of all keys, and initializes
the active checklist in state_block.magi.json with all values set to
false.ReviewFeedback checklist. The Orchestrator (or Consolidation
in RIGOR_PATH) performs a Logical AND consolidation across all reviews. A
key in the consolidated state_block.magi.json#checklist only becomes true
if ALL scanners that have that specific key defined in their persona
asserted true. Any false keys or unlisted_issues_found are translated
into strict constraints in constraints.magi.[iteration].json.true), the Training agent uses unlisted_issues_found history to append
new keys to the appropriate personas/**/*.json checklists.STAGE SIGNALING: The Orchestrator MUST use an appropriate status-reporting mechanism prior to invoking any sub-agents to clearly identify the current stage of the MAGI protocol to the user (e.g., "MAGI Stage 2: Generate").
DECENTRALIZED HANDOFFS: To reduce Orchestrator overhead, agents SHOULD
include a next_stage field in their JSON output to signal the intended
successor. Note: Scanners and Scoping sub-agents are exempt as their successors
are deterministic.
PREPARATIONSYNTHESIS (if iteration needed) or TRAININGTEST_FILLING (if implementation) or ANALYSIS (if review)VALIDATIONDEPLOYMENTremoting/tools/magi-mode/.temp/ directory contains a half-finished
session (e.g., existing state files). If it does, the agent MUST ask the user
whether they want to resume the previous session or start a new task.grep_search, read_file) to understand
context, dependencies, and existing patterns..jj/ directory or run jj status. If successful,
set vcs to "JJ". Otherwise, default to "GIT".code_search, view_file) are
available. If yes, set harness to "JETSKI". Otherwise, set to
"GENERIC_CLI".project.magi.json conforming to
magi_schema.json.execution_path and complexity_level:
complexity_level: LOW (minor bug fixes, small nits), MEDIUM (standard
feature work), or HIGH (architectural changes, security-sensitive code).execution_path: FAST_PATH if complexity is LOW and ambiguity is
LOW. Otherwise, default to RIGOR_PATH.task_type based on
the request:
IMPLEMENTATION: Default. For creating new features or fixing bugs. Sets
next_stage to SCAFFOLDING.REVIEW: For reviewing existing changes or a CL. Sets next_stage to
PREPARATION.AUDIT: For analyzing existing code for modernization or flaws. Sets
next_stage to PREPARATION.ambiguity_level: "LOW".ambiguity_level: "HIGH". The
Gate: If ambiguity_level == "HIGH" OR context_resolved == false, the
Orchestrator MUST pause for human intervention. If
ambiguity_level == "LOW" AND context_resolved == true, the Orchestrator
MAY auto-proceed to the next stage.goal, target_files, and Build Parameters (Debug/Release,
reclient status, and output_directory) to the user for verification.project.magi.json): See EXAMPLES.md for
a full example. Tooling Selection: The combination of repo_type, vcs,
and harness in the environment block determines the exact build, test,
and upload commands used by the agents.This stage is ONLY executed if task_type is IMPLEMENTATION.
project.magi.json to understand the goal. Their mandate is to create
necessary files, define class interfaces, set up Mojo pipes, and GN/DEPS
rules. Leave implementation details empty or stubbed (e.g.,
NOTIMPLEMENTED()). The Implementation MUST signal
next_stage: SCAFFOLDING.*_unittest.cc), define the required test
fixtures, and stub out the critical test cases based on the Implementation's
scaffold. To ensure failure in Chromium's GTest framework (confirming TDD
behavior), the Test Expert MUST insert ADD_FAILURE() << "NOT IMPLEMENTED"
into the stubbed test cases. The Test Expert SHOULD signal
next_stage: PREPARATION.build_targets are defined in
project.magi.json, the Orchestrator MUST verify that the scaffold compiles
and that all newly added tests fail (confirming TDD behavior).project.magi.json and
src/remoting/tools/magi-mode/ROUTING.md (the routing catalog) to select the
appropriate Scanners (Auditors) based on the execution path:
state_block.magi.json. The checklist field is initialized with the
Union Set of all checklist keys from every selected ruleset, set to
false.state_transport
based on the risk score (Scanner Count * Target Files):
state_block.magi.json): See EXAMPLES.md
for a full example.wait_for_previous: false). Instruct each to implement the stubbed
internals from the Base Scaffold.ADD_FAILURE() << "NOT IMPLEMENTED" and a descriptive
TODO comment) rather than fully implementing the test.friend declarations in the production code
that the Test Expert will need to verify internal state.next_stage: ESCALATION and produce a
detailed conflict_report for human review.project.magi.json to ground their
implementation in the actual requirements. They MUST securely save their
draft to disk using the versioned naming convention
[filename].[persona].magi.[iteration] (e.g., host.cc.security.magi.1).
Sub-agents SHOULD signal next_stage: SYNTHESIS upon completion.build_targets are defined in
project.magi.json, Synthesis MUST run the local build/test suite on "Draft
A".
next_stage: TEST_FILLING or ANALYSIS until the build is green.next_stage: TEST_FILLING.MANDATE: Perform technical audit of synthesized code. INPUT: [filename] SPEC: project.magi.json RULESET: [persona_file_path] OUTPUT: JSON object conforming to magi_schema.json#definitions/ReviewFeedback TARGET: review.[persona].magi.[iteration].json TONE: Zero Preamble. Artifacts only.
state_block.magi.json directly. If any checklist items are false, it
generates constraints.magi.[iteration].json and loops back to synthesis.constraints.magi.[iteration].json.True -> False -> True)
across iterations, or if the active_constraints list is identical across
two iterations, Consolidation MUST signal next_stage: ESCALATION.conflict_report in the State Block, identifying the
specific modules and constraints that are in conflict.state_block.magi.json and
constraints.magi.[iteration].json to generate the next iteration.oscillation_detected == true, the Orchestrator
MUST halt and present the conflict_report to the human for a strategic
decision.personas/*.json ruleset by
adding a new Boolean constraint to its checklist.[category]/[domain]/[specialty].json (e.g., split
core/security.json into core/security/memory.json and
core/security/network.json). Do not use flat files with underscores. The
directory depth MUST NOT exceed 5 levels (counting from /personas). Migrate
the relevant checks and update ROUTING.md. Training MUST signal
next_stage: VALIDATION.git cl presubmit and full test suite.project.magi.json#environment/vcs. Run jj st (for JJ) or git status
(for Git). Detect and revert accidental submodule bumps. Remove any
lingering temporary files generated by the protocol (e.g., *.magi,
*.magi.*) and delete the remoting/tools/magi-mode/.temp/ directory.git cl format or project-specific formatters.PERSONAS.md and personas/**/*.json files
updated by Training as a secondary CL.ambiguity_level == "HIGH" or
context_resolved == false, the Orchestrator MUST pause for human
verification before proceeding to execution.Synthesis MUST ensure:
base::RefCountedDeleteOnSequence for timers.std::move and base::RefCountedString.if (callback_)) are
atomically sound or strictly sequence-enforced to prevent double-runs.VCS Isolation Rule: Any modifications to MAGI files (e.g., adding/updating
personas by Training) MUST be excluded from the feature/bugfix CL. The staging
and submission workflow branches dynamically based on
project.magi.json#environment/vcs:
main@origin) from the start: one for the feature/bugfix and one for the MAGI
upgrades. If they accidentally get mixed, Release MUST use jj split or
jj squash -i to cleanly separate the changes before pushing.remoting/tools/magi-mode/.temp/..temp/ directory at the end of the run, rather than requiring the user to
add it to .gitignore.To ensure agents operate safely within the specific environment, specialized
tooling personas are available in personas/infra/:
infra/jj_git.json: Expert in jj on Git workflow. Agents performing
file operations or commit management in a JJ environment SHOULD consult this
persona to avoid losing Gerrit Change-Ids or mishandling detached HEAD
states.infra/chromium_build.json: Expert in Chromium build tools. Agents
performing builds or adding new files SHOULD consult this persona to ensure
correct target discovery and usage of autoninja.The Orchestrator MUST adjust its behavior and instruction set based on the
project.magi.json#environment/orchestration_pattern to optimize for the
specific CLI harness.
Optimized for single-threaded harnesses without native background routing.
next_stage signals from sub-agent JSON outputs and
explicitly invoke the subsequent tools.wait_for_previous: false).state_block.magi.json to ground its context, making the protocol
resilient to turn interruptions or context loss.personas/**/*.json files and inject their mandate and checklist directly
into the sub-agent invocation prompts to save turns. Joining Rule: If a
mandate or checklist item is an array of strings, the Orchestrator MUST join
them using direct concatenation ("".join(array)). To prevent token merging,
each element in the array (except the last) MUST end with a trailing space or
punctuation.Optimized for autonomous harnesses with native multi-agent routing (e.g., Gemini CLI).
next_stage signals to
trigger successor agents directly through the harness.project.magi.json and
state_block.magi.json updates) rather than every interim tool call.To validate the MAGI protocol execution and prevent regressions in prompt instructions and state machine transitions, consult the SKILL_TEST_PLAN.md for the overall strategy and SKILL_TEST.md for the specific unit tests.