@heretyc/subagent-mcp 2.8.2 → 2.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,135 +1,136 @@
1
- # subagent-mcp
2
-
3
- MCP server that launches and manages locally installed `claude` and `codex` CLI binaries as child sub-agent processes. Runs on **macOS, Linux, and Windows**.
4
-
5
- **No direct API calls.** subagent-mcp does NOT use the Anthropic or OpenAI HTTP APIs and has no plans to. It invokes your locally installed and authenticated `claude` (Claude Code) and `codex` CLIs. No API keys, no SDKs beyond the CLIs themselves.
6
-
7
- **License:** Apache-2.0 | **Author:** Lexi Blackburn | **Repo:** https://github.com/Heretyc/subagent-mcp
8
-
9
- ---
10
-
11
- ## Features
12
-
13
- - Spawn `claude` or `codex` CLI processes as managed sub-agents from any MCP host
14
- - Poll status, stream stdout/stderr tails, and send stdin messages to live agents
15
- - Concurrency caps: 5 concurrent Claude agents + 5 concurrent Codex agents (counts only actively-streaming `processing` agents, to limit API rate-limit pressure; quiet `stalled` agents don't reserve a slot)
16
- - Liveness tracking via the visible provider stream (Claude `stream-json`, Codex `--json` JSONL): agents with no parsed visible provider stream item for 10 minutes enter `stalled` state (still alive, just quiet -- thinking or awaiting a temp-file handoff), and recover to `processing` if the visible stream resumes
17
- - Ultracode mode for Opus 4.8 -- headless activation via `--settings {"ultracode":true}` (see [docs/usage.md](docs/usage.md))
18
- - Cross-platform exe resolution (Windows: npm-prefix .exe paths; macOS/Linux: PATH + Homebrew/usr-local fallbacks); immediate `taskkill /t /f` (Windows) / `SIGKILL` (POSIX) force-kill; no graceful shutdown period
19
- - stdio MCP transport; built with `@modelcontextprotocol/sdk` + `zod`
20
- - `orchestration-mode` tool — toggles orchestrator directives injected by bundled Claude Code / Codex hooks; Claude also gets a deterministic `PreToolUse` gate (Desktop hosts toggle but do not inject); see [docs/spec/orchestration-mode/_INDEX.md](docs/spec/orchestration-mode/_INDEX.md)
21
-
22
- ---
23
-
24
- ## Quick Start
25
-
26
- **Prerequisites:** Node.js >= 18, plus the `claude` and/or `codex` CLIs installed globally and authenticated.
27
-
28
- Installed via [GitHub Packages](https://github.com/Heretyc/subagent-mcp/pkgs/npm/subagent-mcp). One-time `.npmrc` setup required (GitHub Packages requires auth even for public packages):
29
-
30
- ```bash
31
- # 1. Configure registry for @heretyc scope (once per machine)
32
- echo "@heretyc:registry=https://npm.pkg.github.com" >> ~/.npmrc
33
-
34
- # 2. Authenticate — use a classic PAT with read:packages scope
35
- echo "//npm.pkg.github.com/:_authToken=YOUR_GITHUB_PAT" >> ~/.npmrc
36
-
37
- # 3. Install and wire
38
- npm install -g @heretyc/subagent-mcp
39
- subagent-mcp setup
40
- ```
41
-
42
- `setup` detects which vendors are present, registers the MCP server, and writes orchestration-mode hooks. Idempotent — safe to re-run after updates. Pass `--dry-run` to preview.
43
-
44
- For consumer projects, run `subagent-mcp init --root /path/to/project` to upsert
45
- the managed invariant block into `AGENTS.md`, `CLAUDE.md`, and `GEMINI.md`.
46
- Use `--dry-run` to preview, `--remove` to uninstall the block, and `--force`
47
- only if you intentionally run inside this source repo.
48
-
49
- After setup, restart your Claude Code or Codex session. On Codex, run `/hooks` and trust the new hook.
50
-
51
- **Updating:** `subagent-mcp update && subagent-mcp setup`
52
-
53
- For manual wiring, developer install from source, Gemini CLI, and Claude Desktop, see [docs/registration.md](docs/registration.md).
54
-
55
- ---
56
-
57
- ## Auto Mode
58
-
59
- `launch_agent` supports **auto mode**: pass `prompt` + `task_category` and the server picks the best provider/model/effort for that category from its routing table, silently falling back to the next-best candidate on any launch-time failure.
60
-
61
- `provider`, `model`, and `effort` are optional overrides — omit them to get auto-selected best combination. Rules: passing `model` requires `provider`; passing `effort` requires both `provider` and `model`.
62
-
63
- **task_category** (required) — pick one:
64
-
65
- | Category | What it is |
66
- |---|---|
67
- | `math_proof` | deliverable is a proof/derivation/formally-checkable result |
68
- | `security_review` | security verdict, threat assessment, or demonstrated exploit |
69
- | `debugging` | verified fix/root-cause; requires an observed failure as precondition |
70
- | `quality_review` | evaluative verdict on existing artifact (review, A-vs-B, validate-vs-spec) |
71
- | `architecture` | cross-module design/plan, no code, no execution loop |
72
- | `agentic_execution` | end-state via act/observe/adapt loop (run/deploy/provision/browse) |
73
- | `data_analysis` | empirical finding about structured dataset (query, stat, model) |
74
- | `coding` | bounded runnable code artifact, one-pass (implement, test, refactor) |
75
- | `knowledge_synthesis` | novel integrated prose over sources (synthesize, summarize, draft) |
76
- | `mechanical` | deterministic single-pass transform, exact-match checkable (grep, rename, reformat) |
77
- | `prompt_engineering` | designed/optimized prompt or prompt-system steering an LLM/agent (composite-inferred) |
78
- | `vulnerability_research` | discovery + PoC of a novel vulnerability (composite-inferred) |
79
- | `molecular_biology` | reasoned molecular/computational-biology result over sequences, structures, or -omics data (composite-inferred) |
80
- | `ml_accelerator_design` | hardware/software design for ML acceleration — dataflow, kernel, roofline (composite-inferred) |
81
- | `fallback_default` | no category matches with confidence; prefer splitting work instead |
82
-
83
- The last four are **composite-inferred**: they carry no dedicated benchmark and their routing competency is composed from parent categories rather than measured directly.
84
-
85
- **Atomic-split guidance:** if you are unsure which category fits, do NOT submit one large amorphous task. Break the work into smaller atomic steps each mapping to a single category and launch one agent per step.
86
-
87
- ---
88
-
89
- ## Tools
90
-
91
- Six tools are exposed over the stdio MCP transport:
92
-
93
- | Tool | Purpose |
94
- |------|---------|
95
- | `launch_agent` | Spawn a new `claude`/`codex` sub-agent process |
96
- | `poll_agent` | Get status + output tail of one agent |
97
- | `kill_agent` | Immediately force-kill any live agent |
98
- | `send_message` | Write to a live agent's stdin |
99
- | `list_agents` | List all agents with token-efficient core metrics |
100
- | `wait` | Block until one or more agents finish, or 15-minute timeout |
101
-
102
- Full parameters, return shapes, the `alive` / `idle_seconds` / `hint` / `recent_stream` fields, and `poll_agent`'s last-3 visible-stream items are in [docs/tools.md](docs/tools.md).
103
-
104
- ---
105
-
106
- ## Agent Lifecycle
107
-
108
- Each agent transitions through these states:
109
-
110
- | Status | Meaning |
111
- |--------|---------|
112
- | `processing` | Process alive with a visible provider-stream heartbeat in the last 10 minutes -- actively working. Launch time counts as the initial heartbeat |
113
- | `stalled` | Process STILL ALIVE but no parsed visible provider stream item for >= 10 minutes -- working, thinking, or awaiting a temp-file handoff (not a failure). Recovers to `processing` if the visible stream resumes |
114
- | `finished` | Process exited with code 0, or Codex emitted `turn.completed` event |
115
- | `errored` | Process exited with non-zero code |
116
- | `stopped` | Terminated by `kill_agent` |
117
-
118
- Only `finished`, `errored`, and `stopped` are terminal; `processing` and `stalled` are live. A health monitor runs every 10 seconds, and `poll_agent`/`list_agents` additionally reconcile exit synchronously so an exited process is reported immediately. `wait` does not return just because an agent is `stalled`. `stalled` agents recover to `processing` if the visible stream resumes and are never auto-killed -- prefer `wait`/re-poll (or checking the agent's temp output) over `kill_agent`. Full semantics: [docs/reference/status-lifecycle.md](docs/reference/status-lifecycle.md).
119
-
120
- ---
121
-
122
- ## Documentation
123
-
124
- - [docs/registration.md](docs/registration.md) -- per-platform registration (Claude Code, Codex, Gemini), prerequisites, install, config paths.
125
- - [docs/tools.md](docs/tools.md) -- full Tool Reference for all six tools, including `alive` / `idle_seconds` / `hint` fields.
126
- - [docs/usage.md](docs/usage.md) -- model & effort matrix, ultracode mechanism, underlying CLI invocations, usage examples.
127
- - [docs/SPEC.md](docs/SPEC.md) -- full technical specification (architecture, schemas, status lifecycle, error catalogue).
128
-
129
- ---
130
-
131
- ## License
132
-
133
- Apache-2.0 -- Copyright 2026 Lexi Blackburn
134
-
135
- See [docs/SPEC.md](docs/SPEC.md) for the full technical specification.
1
+ # subagent-mcp
2
+
3
+ MCP server that launches and manages always-interactive Claude Code and Codex sub-agent sessions. Runs on **macOS, Linux, and Windows**.
4
+
5
+ **No direct API calls.** subagent-mcp does NOT use the Anthropic or OpenAI HTTP APIs and has no plans to. Claude sessions use the Claude Agent SDK against your local Claude Code executable; Codex sessions use your local `codex app-server`. No API keys.
6
+
7
+ **License:** Apache-2.0 | **Author:** Lexi Blackburn | **Repo:** https://github.com/Heretyc/subagent-mcp
8
+
9
+ ---
10
+
11
+ ## Features
12
+
13
+ - Start Claude or Codex interactive sessions as managed sub-agents from any MCP host
14
+ - Poll status, stream stdout/stderr tails, and enqueue follow-up messages to live sessions
15
+ - Concurrency caps: 5 concurrent Claude agents + 5 concurrent Codex agents (counts only actively-streaming `processing` agents, to limit API rate-limit pressure; quiet `stalled` agents don't reserve a slot)
16
+ - Liveness tracking via the visible provider stream (Claude SDK events, Codex app-server JSONL): agents with no parsed visible provider stream item for 10 minutes enter `stalled` state (still alive, just quiet -- thinking or awaiting a temp-file handoff), and recover to `processing` if the visible stream resumes
17
+ - Ultracode mode for Opus 4.8 -- headless activation via `--settings {"ultracode":true}` (see [docs/usage.md](docs/usage.md))
18
+ - Cross-platform exe resolution (Windows: npm-prefix .exe paths; macOS/Linux: PATH + Homebrew/usr-local fallbacks); immediate `taskkill /t /f` (Windows) / `SIGKILL` (POSIX) force-kill; no graceful shutdown period
19
+ - stdio MCP transport; built with `@modelcontextprotocol/sdk` + `zod`
20
+ - `orchestration-mode` tool — toggles orchestrator directives injected by bundled Claude Code / Codex hooks; Claude also gets a deterministic `PreToolUse` gate (Desktop hosts toggle but do not inject); see [docs/spec/orchestration-mode/_INDEX.md](docs/spec/orchestration-mode/_INDEX.md)
21
+
22
+ ---
23
+
24
+ ## Quick Start
25
+
26
+ **Prerequisites:** Node.js >= 18, plus the `claude` and/or `codex` CLIs installed globally and authenticated.
27
+
28
+ Installed via [GitHub Packages](https://github.com/Heretyc/subagent-mcp/pkgs/npm/subagent-mcp). One-time `.npmrc` setup required (GitHub Packages requires auth even for public packages):
29
+
30
+ ```bash
31
+ # 1. Configure registry for @heretyc scope (once per machine)
32
+ echo "@heretyc:registry=https://npm.pkg.github.com" >> ~/.npmrc
33
+
34
+ # 2. Authenticate — use a classic PAT with read:packages scope
35
+ echo "//npm.pkg.github.com/:_authToken=YOUR_GITHUB_PAT" >> ~/.npmrc
36
+
37
+ # 3. Install and wire
38
+ npm install -g @heretyc/subagent-mcp
39
+ subagent-mcp setup
40
+ ```
41
+
42
+ `setup` detects which vendors are present, registers the MCP server, and writes orchestration-mode hooks. Idempotent — safe to re-run after updates. Pass `--dry-run` to preview.
43
+
44
+ For consumer projects, run `subagent-mcp init --root /path/to/project` to upsert
45
+ the managed invariant block into `AGENTS.md`, `CLAUDE.md`, and `GEMINI.md`.
46
+ Use `--dry-run` to preview, `--remove` to uninstall the block, and `--force`
47
+ only if you intentionally run inside this source repo.
48
+
49
+ After setup, restart your Claude Code or Codex session. On Codex, run `/hooks` and trust the new hook.
50
+
51
+ **Updating:** `subagent-mcp update && subagent-mcp setup`
52
+
53
+ For manual wiring, developer install from source, Gemini CLI, and Claude Desktop, see [docs/registration.md](docs/registration.md).
54
+
55
+ ---
56
+
57
+ ## Auto Mode
58
+
59
+ `launch_agent` supports **auto mode**: pass `prompt` + `task_category` and the server picks the best provider/model/effort for that category from its routing table, silently falling back to the next-best candidate on any launch-time failure.
60
+
61
+ `provider`, `model`, and `effort` are optional overrides — omit them to get auto-selected best combination. Rules: passing `model` requires `provider`; passing `effort` requires both `provider` and `model`.
62
+
63
+ **task_category** (required) — pick one:
64
+
65
+ | Category | What it is |
66
+ |---|---|
67
+ | `math_proof` | deliverable is a proof/derivation/formally-checkable result |
68
+ | `security_review` | security verdict, threat assessment, or demonstrated exploit |
69
+ | `debugging` | verified fix/root-cause; requires an observed failure as precondition |
70
+ | `quality_review` | evaluative verdict on existing artifact (review, A-vs-B, validate-vs-spec) |
71
+ | `architecture` | cross-module design/plan, no code, no execution loop |
72
+ | `agentic_execution` | end-state via act/observe/adapt loop (run/deploy/provision/browse) |
73
+ | `data_analysis` | empirical finding about structured dataset (query, stat, model) |
74
+ | `coding` | bounded runnable code artifact, one-pass (implement, test, refactor) |
75
+ | `knowledge_synthesis` | novel integrated prose over sources (synthesize, summarize, draft) |
76
+ | `mechanical` | deterministic single-pass transform, exact-match checkable (grep, rename, reformat) |
77
+ | `prompt_engineering` | designed/optimized prompt or prompt-system steering an LLM/agent (composite-inferred) |
78
+ | `vulnerability_research` | discovery + PoC of a novel vulnerability (composite-inferred) |
79
+ | `molecular_biology` | reasoned molecular/computational-biology result over sequences, structures, or -omics data (composite-inferred) |
80
+ | `ml_accelerator_design` | hardware/software design for ML acceleration — dataflow, kernel, roofline (composite-inferred) |
81
+ | `fallback_default` | no category matches with confidence; prefer splitting work instead |
82
+
83
+ The last four are **composite-inferred**: they carry no dedicated benchmark and their routing competency is composed from parent categories rather than measured directly.
84
+
85
+ **Atomic-split guidance:** if you are unsure which category fits, do NOT submit one large amorphous task. Break the work into smaller atomic steps each mapping to a single category and launch one agent per step.
86
+
87
+ ---
88
+
89
+ ## Tools
90
+
91
+ Six tools are exposed over the stdio MCP transport:
92
+
93
+ | Tool | Purpose |
94
+ |------|---------|
95
+ | `launch_agent` | Start a new `claude`/`codex` sub-agent session |
96
+ | `poll_agent` | Get status + output tail of one agent |
97
+ | `kill_agent` | Immediately force-kill any live agent |
98
+ | `send_message` | Enqueue a user message on a live session |
99
+ | `list_agents` | List all agents with token-efficient core metrics |
100
+ | `wait` | Block until one or more agents finish, or 15-minute timeout |
101
+
102
+ Full parameters, return shapes, the `alive` / `idle_seconds` / `hint` / `recent_stream` fields, and `poll_agent`'s last-3 visible-stream items are in [docs/tools.md](docs/tools.md).
103
+
104
+ ---
105
+
106
+ ## Agent Lifecycle
107
+
108
+ Each agent transitions through these states:
109
+
110
+ | Status | Meaning |
111
+ |--------|---------|
112
+ | `processing` | Driver alive with a visible provider-stream heartbeat in the last 10 minutes -- actively working. Launch time counts as the initial heartbeat |
113
+ | `stalled` | Driver STILL ALIVE but no parsed visible provider stream item for >= 10 minutes -- working, thinking, or awaiting a temp-file handoff (not a failure). Recovers to `processing` if the visible stream resumes |
114
+ | `finished` | Current turn completed, or driver exited with code 0 |
115
+ | `errored` | Process exited with non-zero code |
116
+ | `stopped` | Terminated by `kill_agent` |
117
+
118
+ `processing` and `stalled` are live. `finished` is reportable for `wait`; if `alive` is still true, `send_message` can start the next turn on the same session. A health monitor runs every 10 seconds, and `poll_agent`/`list_agents` additionally reconcile driver exit synchronously. `wait` does not return just because an agent is `stalled`. `stalled` agents recover to `processing` if the visible stream resumes and are never auto-killed -- prefer `wait`/re-poll over `kill_agent`. Full semantics: [docs/reference/status-lifecycle.md](docs/reference/status-lifecycle.md).
119
+
120
+ ---
121
+
122
+ ## Documentation
123
+
124
+ - [docs/registration.md](docs/registration.md) -- per-platform registration (Claude Code, Codex, Gemini), prerequisites, install, config paths.
125
+ - [docs/tools.md](docs/tools.md) -- full Tool Reference for all six tools, including `alive` / `idle_seconds` / `hint` fields.
126
+ - [docs/usage.md](docs/usage.md) -- model & effort matrix, ultracode mechanism, underlying CLI invocations, usage examples.
127
+ - [docs/SPEC.md](docs/SPEC.md) -- full technical specification (architecture, schemas, status lifecycle, error catalogue).
128
+ - [docs/spec/interactive-drivers.md](docs/spec/interactive-drivers.md) -- always-interactive Claude/Codex driver model.
129
+
130
+ ---
131
+
132
+ ## License
133
+
134
+ Apache-2.0 -- Copyright 2026 Lexi Blackburn
135
+
136
+ See [docs/SPEC.md](docs/SPEC.md) for the full technical specification.
@@ -1,17 +1,13 @@
1
- <ORCHESTRATION-INVARIANT>
2
- Sub-agent sessions (first prompt began "<this is a request from a parent process>"): ignore this block.
1
+ <!-- INJECTED PRE-PROMPT DIRECTIVE — BINDING, NON-NEGOTIABLE -->
2
+ <ORCHESTRATION-CARRYOVER>
3
3
 
4
- ORCHESTRATION MODE carried over ON from a PRIOR session of this project
5
- (persists until disabled with permission). Not user-enabled THIS session.
4
+ Orchestration MODE was ON at session start — carried over from PRIOR session for this project (persists until disabled with permission). Not enabled THIS session.
6
5
 
7
6
  THIS turn, ONCE:
8
7
  1. NOTIFY user it carried over.
9
8
  2. ASK keep ON? via AskUserQuestion.
10
- 3. ADVISE fit: long-horizon context-filling → keep ON; bounded, interactive, or
11
- core-bound to main-session-only MCP → propose OFF.
9
+ 3. ADVISE fit: long-horizon context-filling → keep ON; bounded/interactive/core-bound to main-session-only MCP → propose OFF.
12
10
 
13
- Until answered, the mandates below still bind. Declines orchestration-mode
14
- enabled:false. NEVER disable on own initiative. After answer: handshake done —
15
- do not re-raise.
11
+ Declines orchestration-mode enabled:false. NEVER disable on own initiative. After answer: handshake done — do not re-raise.
16
12
 
17
- </ORCHESTRATION-INVARIANT>
13
+ </ORCHESTRATION-CARRYOVER>
@@ -1,17 +1,13 @@
1
- <ORCHESTRATION-INVARIANT>
2
- Sub-agent sessions (first prompt began "<this is a request from a parent process>"): ignore this block.
1
+ <!-- INJECTED PRE-PROMPT DIRECTIVE — BINDING, NON-NEGOTIABLE -->
2
+ <ORCHESTRATION-CARRYOVER>
3
3
 
4
- ORCHESTRATION MODE carried over ON from a PRIOR session of this project
5
- (persists until disabled with permission). Not user-enabled THIS session.
4
+ Orchestration MODE was ON at session start — carried over from PRIOR session for this project (persists until disabled with permission). Not enabled THIS session.
6
5
 
7
6
  THIS turn, ONCE:
8
7
  1. NOTIFY user it carried over.
9
8
  2. ASK keep ON? via request-user-input.
10
- 3. ADVISE fit: long-horizon context-filling → keep ON; bounded, interactive, or
11
- core-bound to main-session-only MCP → propose OFF.
9
+ 3. ADVISE fit: long-horizon context-filling → keep ON; bounded/interactive/core-bound to main-session-only MCP → propose OFF.
12
10
 
13
- Until answered, the mandates below still bind. Declines orchestration-mode
14
- enabled:false. NEVER disable on own initiative. After answer: handshake done —
15
- do not re-raise.
11
+ Declines orchestration-mode enabled:false. NEVER disable on own initiative. After answer: handshake done — do not re-raise.
16
12
 
17
- </ORCHESTRATION-INVARIANT>
13
+ </ORCHESTRATION-CARRYOVER>
@@ -1,14 +1,22 @@
1
- <ORCHESTRATION-INVARIANT>
2
- ORCHESTRATION ON. Delegate-default through subagent-mcp; route EVERY sub-agent launch ONLY via subagent-mcp launch_agent. Inline ONLY main-session-only-capability steps (non-inheritable MCP, interactive/consent, verify reruns); temp scratch-file IPC allowed. Repo/system safety rules outrank this.
3
- - Ruthlessly preserve orchestrator context, NO EXCEPTIONS.
4
- - Subagents ask questions through the orchestrator; answers
5
- return to subagents.
6
- - Sub-agents use %TEMP%, /tmp/, /TEMP/ for all IPC.
7
- - NEVER DISABLE ORCHESTRATION: never on own initiative. Propose via AskUserQuestion only; disable only after explicit user permission.
8
- Orchestration Steps:
9
- 1. Map out work before orchestrating.
10
- 2. Decompose into phases which have atomic tasks that are separate subagents. Phases = understand → design → implement → review.
11
- 3. Execute the phases, dispatching sub-agents and between EACH phase dispatch a quality-review sub-agent to validate all work done.
12
-
13
- - For Sub-agent sessions ONLY (first prompt began "<this is a request from a parent process>" or env SUBAGENT_MCP_SUBAGENT=1): ignore this block.
14
- </ORCHESTRATION-INVARIANT>
1
+ <!-- INJECTED PRE-PROMPT DIRECTIVE — BINDING, NON-NEGOTIABLE -->
2
+ <ORCHESTRATION-INVARIANT priority="CRITICAL" override="NONE">
3
+ SCOPE: If this session's prompt begins with "<this is a request from a parent process>", SUB-AGENT-INVARIANT does NOT apply to this session, SKIP the remainder of this directive.
4
+
5
+ ORCHESTRATION MODE ON. You = ORCHESTRATOR. DEFAULT = DELEGATE.
6
+
7
+ INLINE BY RIGHT (no violation): steps bound to main-session-only capability
8
+ MCP tools sub-agents can't inherit, interactive/consent tools, tight verify
9
+ loops. State which + why, one line.
10
+
11
+ MUST DELEGATE/OFFLOAD (breach if not): pure compute (parse/aggregate/transform);
12
+ any payload >50KB or >200 lines → scratch file, hand off the PATH.
13
+ Mixed task = SPLIT. One MCP-bound step never makes the whole task inline.
14
+
15
+ CONFLICT ORDER: safety-scope > user instruction this turn > delegate-default.
16
+ User tool-pin re-partitions work; does not suspend mode.
17
+
18
+ IPC = temp scratch files ONLY. Windows: %TEMP%. POSIX: /tmp.
19
+ Full model + governance: server MCP instructions.
20
+ DISABLE: never on own initiative. Propose via AskUserQuestion only.
21
+
22
+ </ORCHESTRATION-INVARIANT>
@@ -1,13 +1,22 @@
1
- <ORCHESTRATION-INVARIANT>
2
- SCOPE: this session's first prompt began "<this is a request from a parent process>" or env SUBAGENT_MCP_SUBAGENT=1? Sub-agent session — this ORCHESTRATION-INVARIANT does NOT apply; SKIP this block.
3
- ORCHESTRATION ON. Delegate-default through subagent-mcp; route EVERY sub-agent launch ONLY via subagent-mcp launch_agent. Inline ONLY main-session-only-capability steps (non-inheritable MCP, interactive/consent, verify reruns); temp scratch-file IPC allowed. Repo/system safety rules outrank this.
4
- - Ruthlessly preserve orchestrator context, NO EXCEPTIONS.
5
- - Subagents ask questions through the orchestrator; answers
6
- return to subagents.
7
- - Sub-agents use %TEMP%, /tmp/, /TEMP/ for all IPC.
8
- - NEVER DISABLE ORCHESTRATION: never on own initiative. Propose via request-user-input only; disable only after explicit user permission.
9
- Orchestration Steps:
10
- 1. Map out work before orchestrating.
11
- 2. Decompose into phases which have atomic tasks that are separate subagents. Phases = understand → design → implement → review.
12
- 3. Execute the phases, dispatching sub-agents and between EACH phase dispatch a quality-review sub-agent to validate all work done.
13
- </ORCHESTRATION-INVARIANT>
1
+ <!-- INJECTED PRE-PROMPT DIRECTIVE — BINDING, NON-NEGOTIABLE -->
2
+ <ORCHESTRATION-INVARIANT priority="CRITICAL" override="NONE">
3
+ SCOPE: If this session's prompt begins with "<this is a request from a parent process>", SUB-AGENT-INVARIANT does NOT apply to this session, SKIP the remainder of this directive.
4
+
5
+ ORCHESTRATION MODE ON. You = ORCHESTRATOR. DEFAULT = DELEGATE.
6
+
7
+ INLINE BY RIGHT (no violation): steps bound to main-session-only capability —
8
+ MCP tools sub-agents can't inherit, interactive/consent tools, tight verify
9
+ loops. State which + why, one line.
10
+
11
+ MUST DELEGATE/OFFLOAD (breach if not): pure compute (parse/aggregate/transform);
12
+ any payload >50KB or >200 lines scratch file, hand off the PATH.
13
+ Mixed task = SPLIT. One MCP-bound step never makes the whole task inline.
14
+
15
+ CONFLICT ORDER: safety-scope > user instruction this turn > delegate-default.
16
+ User tool-pin re-partitions work; does not suspend mode.
17
+
18
+ IPC = temp scratch files ONLY. Windows: %TEMP%. POSIX: /tmp.
19
+ Full model + governance: server MCP instructions.
20
+ DISABLE: never on own initiative. Propose via request-user-input only.
21
+
22
+ </ORCHESTRATION-INVARIANT>
@@ -1,9 +1,8 @@
1
+ <!-- INJECTED PER-PROMPT REMINDER — BINDING -->
1
2
  <ORCHESTRATION-INVARIANT>
2
- ZERO EXCEPTIONS SUBAGENT MANDATES:
3
- 5-CALL RULE: >5 tool calls needed for this request (all turns, no reset), or >5 already spent? Count reads, greps, test runs. If yes do NOT grind on inline - STOP and ask via AskUserQuestion whether to switch orchestration ON. That STOP+ask satisfies this rule; if the user declines, inline is authorized for THIS request - do not re-ask it.
4
- Why this exists: agents grind through large work without ever considering orchestration.
5
- ORCHESTRATION OFF - still binding:
6
- INVARIANT ZERO EXCEPTIONS SOLE CHANNEL: ANY sub-agent launch goes ONLY via the subagent-mcp; harness-native Task/Agent tools are FORBIDDEN while this server is connected.
7
- Advisory: At all times, delegating via subagent-mcp auto routing is advisable - do not assume your training data is still current.
8
- For Sub-agent sessions ONLY (first prompt began "<this is a request from a parent process>" or env SUBAGENT_MCP_SUBAGENT=1): ignore this block.
3
+
4
+ Orchestration OFF. 5-CALL RULE: request likely needs >5 tool calls, OR 5th call done with work remaining STOP, ask via AskUserQuestion whether to switch Orchestration ON. Even OFF, delegating via subagent-mcp auto routing advisable for durable results calling model not always best fit. Sub-agent sessions: ignore.
5
+
6
+ WAIT-NOT-POLL: learn agent finish via `wait` — blocks until terminal exit, returns exit status (`verbose: true` for final output). Never loop `poll_agent` for completion (floods orchestrator context). `poll_agent` = single-call diagnostic on one agent (stalled stream, one-shot output). Stalled = alive, NOT dead.
7
+
9
8
  </ORCHESTRATION-INVARIANT>
@@ -1,9 +1,8 @@
1
+ <!-- INJECTED PER-PROMPT REMINDER — BINDING -->
1
2
  <ORCHESTRATION-INVARIANT>
2
- ZERO EXCEPTIONS SUBAGENT MANDATES:
3
- 5-CALL RULE: >5 tool calls needed for this request (all turns, no reset), or >5 already spent? Count reads, greps, test runs. If yes do NOT grind on inline - STOP and ask via request-user-input whether to switch orchestration ON. That STOP+ask satisfies this rule; if the user declines, inline is authorized for THIS request - do not re-ask it.
4
- Why this exists: agents grind through large work without ever considering orchestration.
5
- ORCHESTRATION OFF - still binding:
6
- INVARIANT ZERO EXCEPTIONS SOLE CHANNEL: ANY sub-agent launch goes ONLY via the subagent-mcp; harness-native Task/Agent tools are FORBIDDEN while this server is connected.
7
- Advisory: At all times, delegating via subagent-mcp auto routing is advisable - do not assume your training data is still current.
8
- For Sub-agent sessions ONLY (first prompt began "<this is a request from a parent process>" or env SUBAGENT_MCP_SUBAGENT=1): ignore this block.
3
+
4
+ Orchestration OFF. 5-CALL RULE: request likely needs >5 tool calls, OR 5th call done with work remaining STOP, ask via request-user-input whether to switch Orchestration ON. Even OFF, delegating via subagent-mcp auto routing advisable for durable results calling model not always best fit. Sub-agent sessions: ignore.
5
+
6
+ WAIT-NOT-POLL: learn agent finish via `wait` — blocks until terminal exit, returns exit status (`verbose: true` for final output). Never loop `poll_agent` for completion (floods orchestrator context). `poll_agent` = single-call diagnostic on one agent (stalled stream, one-shot output). Stalled = alive, NOT dead.
7
+
9
8
  </ORCHESTRATION-INVARIANT>
@@ -1,15 +1,8 @@
1
+ <!-- INJECTED PER-PROMPT REMINDER — BINDING -->
1
2
  <ORCHESTRATION-INVARIANT>
2
- ORCHESTRATION ON. Route EVERY sub-agent launch ONLY via subagent-mcp launch_agent. Inline ONLY main-session-only-capability steps; temp scratch-file IPC allowed. Repo/system safety rules outrank this.
3
- - Delegate-default. 5-CALL RULE is satisfied by delegation.
4
- EVERY reply starts: route: delegate|inline - <reason>
5
- - Ruthlessly preserve orchestrator context, NO EXCEPTIONS.
6
- - Subagents ask questions through the orchestrator; answers
7
- return to subagents.
8
- - Sub-agents use %TEMP%, /tmp/, /TEMP/ for all IPC.
9
- Orchestration Steps:
10
- 1. Map out work before orchestrating.
11
- 2. Decompose into phases which have atomic tasks that are separate subagents. Phases = understand → design → implement → review.
12
- 3. Execute the phases, dispatching sub-agents and between EACH phase dispatch a quality-review sub-agent to validate all work done.
13
3
 
14
- - For Sub-agent sessions ONLY (first prompt began "<this is a request from a parent process>" or env SUBAGENT_MCP_SUBAGENT=1): ignore this block.
4
+ Orchestration ON. Delegate-default: decompose, delegate, keep orchestrator context lean. 5-CALL RULE satisfied by delegation. Full model + governance: server MCP instructions. Sub-agent sessions: ignore.
5
+
6
+ WAIT-NOT-POLL: learn agent finish via `wait` — blocks until terminal exit, returns exit status (`verbose: true` for final output). Never loop `poll_agent` for completion (floods orchestrator context). `poll_agent` = single-call diagnostic on one agent (stalled stream, one-shot output). Stalled = alive, NOT dead.
7
+
15
8
  </ORCHESTRATION-INVARIANT>
@@ -0,0 +1 @@
1
+ <SUB-AGENT-INVARIANT>Orchestration OFF. 5-CALL RULE applies this turn. Obey last <ORCHESTRATION-INVARIANT> block.</SUB-AGENT-INVARIANT>
@@ -0,0 +1 @@
1
+ <SUB-AGENT-INVARIANT>Orchestration ON. 5-CALL RULE applies this turn. Run user request now via orchestration steps. Obey last <ORCHESTRATION-INVARIANT> block.</SUB-AGENT-INVARIANT>
@@ -1,67 +1,67 @@
1
- #!/usr/bin/env python3
2
- """advanced-ruleset.py — final-authority model-routing override hook for subagent-mcp.
3
-
4
- (a) PERFORMANCE WARNING: this script runs synchronously inside EVERY launch_agent
5
- call. Slow rules slow every agent launch. Keep rules lean and low-latency —
6
- no network calls, no heavy imports at module top. This is YOUR responsibility;
7
- you have been warned.
8
-
9
- (b) OUTPUT CONTRACT (routing mode): print to stdout ONE JSON array — the modified
10
- candidate list (reorder / filter / replace allowed). Template:
11
- [
12
- {"provider": "claude", "model": "sonnet", "effort": "high", "rank": 1},
13
- {"provider": "codex", "model": "gpt-5.5", "effort": "xhigh", "rank": 2}
14
- ]
15
- Valid providers: claude, codex. Valid models: haiku, sonnet, opus, opus-4-8 (claude);
16
- gpt-5.5 (codex). Valid efforts: haiku -> "none" only; sonnet -> low|medium|high|xhigh|max;
17
- opus/opus-4-8 -> those plus ultracode; gpt-5.5 -> low|medium|high|xhigh.
18
- "rank" on output is ignored. An EMPTY array vetoes the launch. Anything else
19
- invalid fails the launch hard — the server validates strictly.
20
-
21
- (c) INPUT CONTRACT (routing mode, invoked as: <python> advanced-ruleset.py route):
22
- stdin receives one JSON object:
23
- { "candidates": [ {"provider","model","effort","rank"} ... ], # rank 1..N best->worst
24
- "context": { "task_category": str, "cwd": str,
25
- "selection_mode": "auto"|"provider"|"provider_model"|"explicit",
26
- "provider": str|None, "model": str|None, "effort": str|None } }
27
- OS environment variables are visible natively (os.environ).
28
-
29
- ENV-CHECK MODE (no arguments): prints {"ready": true|false, "load-rules": true|false}.
30
- Runs once per MCP server process. load-rules false => ruleset silently disabled
31
- for the rest of the process. Set LOAD_RULES = True below to activate.
32
- """
33
- import json
34
- import sys
35
-
36
- LOAD_RULES = False
37
-
38
- # --- Requirements stub (scaffold itself is stdlib-only) ----------------------
39
- # List third-party distributions your rules import, e.g.:
40
- # REQUIREMENTS = ["requests", "pyyaml"]
41
- # Install with: <python> -m pip install <name> ...
42
- REQUIREMENTS = []
43
-
44
- def missing_requirements():
45
- """pip-check helper: returns the REQUIREMENTS entries not importable here."""
46
- import importlib.util
47
- return [r for r in REQUIREMENTS
48
- if importlib.util.find_spec(r.replace("-", "_")) is None]
49
-
50
- def env_check():
51
- missing = missing_requirements()
52
- json.dump({"ready": not missing, "load-rules": bool(LOAD_RULES)}, sys.stdout)
53
-
54
- def apply_rules(candidates, context):
55
- """YOUR RULES HERE. Default: passthrough (returns the list unchanged)."""
56
- return candidates
57
-
58
- def route():
59
- payload = json.load(sys.stdin)
60
- out = apply_rules(payload.get("candidates", []), payload.get("context", {}))
61
- json.dump(out, sys.stdout)
62
-
63
- if __name__ == "__main__":
64
- if len(sys.argv) > 1 and sys.argv[1] == "route":
65
- route()
66
- else:
67
- env_check()
1
+ #!/usr/bin/env python3
2
+ """advanced-ruleset.py — final-authority model-routing override hook for subagent-mcp.
3
+
4
+ (a) PERFORMANCE WARNING: this script runs synchronously inside EVERY launch_agent
5
+ call. Slow rules slow every agent launch. Keep rules lean and low-latency —
6
+ no network calls, no heavy imports at module top. This is YOUR responsibility;
7
+ you have been warned.
8
+
9
+ (b) OUTPUT CONTRACT (routing mode): print to stdout ONE JSON array — the modified
10
+ candidate list (reorder / filter / replace allowed). Template:
11
+ [
12
+ {"provider": "claude", "model": "sonnet", "effort": "high", "rank": 1},
13
+ {"provider": "codex", "model": "gpt-5.5", "effort": "xhigh", "rank": 2}
14
+ ]
15
+ Valid providers: claude, codex. Valid models: haiku, sonnet, opus, opus-4-8 (claude);
16
+ gpt-5.5 (codex). Valid efforts: haiku -> "none" only; sonnet -> low|medium|high|xhigh|max;
17
+ opus/opus-4-8 -> those plus ultracode; gpt-5.5 -> low|medium|high|xhigh.
18
+ "rank" on output is ignored. An EMPTY array vetoes the launch. Anything else
19
+ invalid fails the launch hard — the server validates strictly.
20
+
21
+ (c) INPUT CONTRACT (routing mode, invoked as: <python> advanced-ruleset.py route):
22
+ stdin receives one JSON object:
23
+ { "candidates": [ {"provider","model","effort","rank"} ... ], # rank 1..N best->worst
24
+ "context": { "task_category": str, "cwd": str,
25
+ "selection_mode": "auto"|"provider"|"provider_model"|"explicit",
26
+ "provider": str|None, "model": str|None, "effort": str|None } }
27
+ OS environment variables are visible natively (os.environ).
28
+
29
+ ENV-CHECK MODE (no arguments): prints {"ready": true|false, "load-rules": true|false}.
30
+ Runs once per MCP server process. load-rules false => ruleset silently disabled
31
+ for the rest of the process. Set LOAD_RULES = True below to activate.
32
+ """
33
+ import json
34
+ import sys
35
+
36
+ LOAD_RULES = False
37
+
38
+ # --- Requirements stub (scaffold itself is stdlib-only) ----------------------
39
+ # List third-party distributions your rules import, e.g.:
40
+ # REQUIREMENTS = ["requests", "pyyaml"]
41
+ # Install with: <python> -m pip install <name> ...
42
+ REQUIREMENTS = []
43
+
44
+ def missing_requirements():
45
+ """pip-check helper: returns the REQUIREMENTS entries not importable here."""
46
+ import importlib.util
47
+ return [r for r in REQUIREMENTS
48
+ if importlib.util.find_spec(r.replace("-", "_")) is None]
49
+
50
+ def env_check():
51
+ missing = missing_requirements()
52
+ json.dump({"ready": not missing, "load-rules": bool(LOAD_RULES)}, sys.stdout)
53
+
54
+ def apply_rules(candidates, context):
55
+ """YOUR RULES HERE. Default: passthrough (returns the list unchanged)."""
56
+ return candidates
57
+
58
+ def route():
59
+ payload = json.load(sys.stdin)
60
+ out = apply_rules(payload.get("candidates", []), payload.get("context", {}))
61
+ json.dump(out, sys.stdout)
62
+
63
+ if __name__ == "__main__":
64
+ if len(sys.argv) > 1 and sys.argv[1] == "route":
65
+ route()
66
+ else:
67
+ env_check()