@heretyc/subagent-mcp 2.12.2 → 2.12.3

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,163 +1,163 @@
1
- # subagent-mcp
2
-
3
- [![npm version](https://img.shields.io/npm/v/@heretyc/subagent-mcp?label=npm)](https://www.npmjs.com/package/@heretyc/subagent-mcp)
4
- [![license](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE)
5
- [![node](https://img.shields.io/node/v/@heretyc/subagent-mcp)](https://www.npmjs.com/package/@heretyc/subagent-mcp)
6
- [![CI](https://github.com/Heretyc/subagent-mcp/actions/workflows/claude-routine.yml/badge.svg)](https://github.com/Heretyc/subagent-mcp/actions/workflows/claude-routine.yml)
7
-
8
- Turn any AI coding assistant into a **manager of other AI agents**. subagent-mcp
9
- lets your Claude Code or Codex session start, watch, message, and stop a whole
10
- team of AI sub-agents — on macOS, Linux, and Windows. **No direct API calls. No
11
- API keys.** It drives the `claude` and `codex` command-line tools you already
12
- signed into.
13
-
14
- ## What it does
15
-
16
- Normally one AI assistant does all the work in one conversation. That
17
- conversation fills up, slows down, and eventually forgets its early context. As
18
- of a certain size it "compacts" — summarizing and dropping detail.
19
-
20
- subagent-mcp changes the shape of the work. Your assistant becomes an
21
- **orchestrator**: it hands each task to a fresh sub-agent, watches the results,
22
- and moves on — without ever doing the reading or writing itself.
23
-
24
- ## Why it works this way
25
-
26
- Four bets drive the whole design. The full reasoning lives in
27
- [docs/spec/arch-rationale.md](docs/spec/arch-rationale.md); the short version:
28
-
29
- - **The effective memory grows geometrically.** Because the orchestrator only
30
- ever holds *summaries* of what its sub-agents did — never the raw files — its
31
- own memory fills up far more slowly. That means **very long tasks with little
32
- or no compaction**.
33
- - **Mixed providers avoid blind spots.** Using Claude *and* Codex together means
34
- one vendor's weak spot or outage doesn't blind or block the whole job — and
35
- you're never locked in to a single vendor.
36
- - **Ruthless token efficiency.** Every hand-off is compressed and every read is
37
- kept small, so the system stays fast and cheap even on marathon tasks.
38
- - **Durable, authoritative reminders.** The operating rules are re-injected every
39
- turn through official host hooks, so the assistant doesn't drift off-task or
40
- start making things up over a long run.
41
-
42
- ## Install
43
-
44
- ### What you need first
45
-
46
- - Node.js 18 or newer (`node --version`)
47
- - `claude` CLI — installed and signed in (`claude --version`)
48
- - `codex` CLI — installed and signed in (`codex --version`; optional if you
49
- only use Claude)
50
-
51
- Building from source needs extra developer tools — see
52
- [CONTRIBUTING.md](CONTRIBUTING.md).
53
-
54
- ### Install the package
55
-
56
- ```bash
57
- npm install -g @heretyc/subagent-mcp
58
- ```
59
-
60
- This is the standard install for everyone. (Organizations pinning the package
61
- through GitHub Packages should see [docs/registration.md](docs/registration.md).)
62
-
63
- ### Wire it into your assistant
64
-
65
- ```bash
66
- subagent-mcp setup
67
- ```
68
-
69
- Installing the package only ships the program — it does **not** connect anything
70
- on its own. `subagent-mcp setup` finds your Claude Code / Codex install and
71
- registers both the server and the per-turn orchestration hooks. Preview first
72
- with `subagent-mcp setup --dry-run`.
73
-
74
- ### Restart, then turn on the invariant
75
-
76
- Restart your Claude Code or Codex session so it picks up the new tools. On Codex,
77
- run `/hooks` and trust the new hook. Then (recommended):
78
-
79
- ```bash
80
- subagent-mcp init --global
81
- ```
82
-
83
- This writes a small managed "always delegate" rule block into your global
84
- assistant config once, so it works across every project. For a single project
85
- instead, use `subagent-mcp init --root /path/to/project`. Full per-platform
86
- wiring (Gemini CLI, Claude Desktop, manual setup) is in
87
- [docs/registration.md](docs/registration.md).
88
-
89
- ## How to operate it
90
-
91
- ### Orchestration mode: ON vs OFF
92
-
93
- - **ON** — your assistant acts as a pure manager. It never reads or writes files
94
- directly; it delegates every step to sub-agents. Best for big, long-running
95
- jobs.
96
- - **OFF** — your assistant works normally, on its own, with no delegation rules.
97
-
98
- Flip it with the `orchestration-mode` tool. (Desktop apps can toggle the mode
99
- but don't receive the per-turn hook reminders.)
100
-
101
- ### The 8 tools at a glance
102
-
103
- | Tool | What it does |
104
- |---|---|
105
- | `launch_agent` | Start a sub-agent on a task (just give a prompt + a task category) |
106
- | `poll_agent` | Check how an agent is doing and read its latest output |
107
- | `kill_agent` | Stop a running or quiet agent |
108
- | `send_message` | Send a follow-up message to a live agent |
109
- | `list_agents` | See every agent and its current status |
110
- | `wait` | Pause until a specific agent finishes |
111
- | `orchestration-mode` | Turn manager-mode ON or OFF |
112
- | `model-selection-mode` | Let the server auto-pick the model, or allow manual overrides |
113
-
114
- You never have to choose a model. Give `launch_agent` a plain-English prompt and
115
- a **task category** (e.g. "coding", "debugging", "security_review") and the
116
- server picks the best provider, model, and effort for that kind of work.
117
-
118
- ### How many run at once
119
-
120
- There is a single machine-wide limit on how many sub-agents run at the same time
121
- across everything on your computer. The **default is 20**. When the limit is
122
- reached, a new `launch_agent` is turned down right away — it does not wait in a
123
- queue. You change the number in the `global-concurrency.jsonc` file in the
124
- install folder (minimum 10); the file is re-read on every launch, so no restart
125
- is needed.
126
-
127
- The same settings file includes `checkForUpdates` (default `true`). When a newer
128
- npm version exists, the per-turn hook can show a throttled notice to run
129
- `subagent-mcp update` and then `subagent-mcp setup`. Set `checkForUpdates` to
130
- `false`, or run with `SUBAGENT_UPDATE_CHECK=0` / `false`, to disable that check.
131
-
132
- ## Basic debugging
133
-
134
- - **"An agent looks stuck."** A quiet agent is usually **still alive**, not
135
- dead. After ~10 minutes with no output an agent is marked `stalled` — it's
136
- thinking or waiting on a hand-off. It recovers on its own. **Do not kill a
137
- stalled agent**, and `wait` will not return on one.
138
- - **"It won't start a new agent (cap reached)."** You've hit the concurrent
139
- limit. Use `list_agents` to see what's running and `kill_agent` on anything
140
- you no longer need — that frees a slot immediately. Raising the number in
141
- `global-concurrency.jsonc` also works.
142
- - **"Where are the logs?"** Each agent's recent output is available any time via
143
- `poll_agent`. The server's own diagnostics go to your host's normal MCP
144
- server log (your Claude Code or Codex session logs) — all server logging goes
145
- to stderr, never mixed into results.
146
-
147
- ## Documentation
148
-
149
- | Document | Contents |
150
- |---|---|
151
- | [docs/spec/arch-rationale.md](docs/spec/arch-rationale.md) | Why it's built this way — the full design rationale |
152
- | [docs/registration.md](docs/registration.md) | Per-platform setup: Claude Code, Codex, Gemini CLI, Claude Desktop |
153
- | [docs/tools.md](docs/tools.md) | Full tool reference — all eight tools, parameters, return shapes |
154
- | [docs/usage.md](docs/usage.md) | Model & effort matrix, ultracode mode, usage examples |
155
- | [docs/SPEC.md](docs/SPEC.md) | Full technical specification |
156
- | [docs/reference/status-lifecycle.md](docs/reference/status-lifecycle.md) | Agent status meanings (processing / stalled / finished / errored / stopped) |
157
- | [CONTRIBUTING.md](CONTRIBUTING.md) | Developer guide — build, test, publish, contribution workflow |
158
-
159
- ## License
160
-
161
- Apache-2.0 — Copyright 2026 Lexi Blackburn
162
-
163
- See [LICENSE](LICENSE).
1
+ # subagent-mcp
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@heretyc/subagent-mcp?label=npm)](https://www.npmjs.com/package/@heretyc/subagent-mcp)
4
+ [![license](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE)
5
+ [![node](https://img.shields.io/node/v/@heretyc/subagent-mcp)](https://www.npmjs.com/package/@heretyc/subagent-mcp)
6
+ [![CI](https://github.com/Heretyc/subagent-mcp/actions/workflows/claude-routine.yml/badge.svg)](https://github.com/Heretyc/subagent-mcp/actions/workflows/claude-routine.yml)
7
+
8
+ Turn any AI coding assistant into a **manager of other AI agents**. subagent-mcp
9
+ lets your Claude Code or Codex session start, watch, message, and stop a whole
10
+ team of AI sub-agents — on macOS, Linux, and Windows. **No direct API calls. No
11
+ API keys.** It drives the `claude` and `codex` command-line tools you already
12
+ signed into.
13
+
14
+ ## What it does
15
+
16
+ Normally one AI assistant does all the work in one conversation. That
17
+ conversation fills up, slows down, and eventually forgets its early context. As
18
+ of a certain size it "compacts" — summarizing and dropping detail.
19
+
20
+ subagent-mcp changes the shape of the work. Your assistant becomes an
21
+ **orchestrator**: it hands each task to a fresh sub-agent, watches the results,
22
+ and moves on — without ever doing the reading or writing itself.
23
+
24
+ ## Why it works this way
25
+
26
+ Four bets drive the whole design. The full reasoning lives in
27
+ [docs/spec/arch-rationale.md](docs/spec/arch-rationale.md); the short version:
28
+
29
+ - **The effective memory grows geometrically.** Because the orchestrator only
30
+ ever holds *summaries* of what its sub-agents did — never the raw files — its
31
+ own memory fills up far more slowly. That means **very long tasks with little
32
+ or no compaction**.
33
+ - **Mixed providers avoid blind spots.** Using Claude *and* Codex together means
34
+ one vendor's weak spot or outage doesn't blind or block the whole job — and
35
+ you're never locked in to a single vendor.
36
+ - **Ruthless token efficiency.** Every hand-off is compressed and every read is
37
+ kept small, so the system stays fast and cheap even on marathon tasks.
38
+ - **Durable, authoritative reminders.** The operating rules are re-injected every
39
+ turn through official host hooks, so the assistant doesn't drift off-task or
40
+ start making things up over a long run.
41
+
42
+ ## Install
43
+
44
+ ### What you need first
45
+
46
+ - Node.js 18 or newer (`node --version`)
47
+ - `claude` CLI — installed and signed in (`claude --version`)
48
+ - `codex` CLI — installed and signed in (`codex --version`; optional if you
49
+ only use Claude)
50
+
51
+ Building from source needs extra developer tools — see
52
+ [CONTRIBUTING.md](CONTRIBUTING.md).
53
+
54
+ ### Install the package
55
+
56
+ ```bash
57
+ npm install -g @heretyc/subagent-mcp
58
+ ```
59
+
60
+ This is the standard install for everyone. (Organizations pinning the package
61
+ through GitHub Packages should see [docs/registration.md](docs/registration.md).)
62
+
63
+ ### Wire it into your assistant
64
+
65
+ ```bash
66
+ subagent-mcp setup
67
+ ```
68
+
69
+ Installing the package only ships the program — it does **not** connect anything
70
+ on its own. `subagent-mcp setup` finds your Claude Code / Codex install and
71
+ registers both the server and the per-turn orchestration hooks. Preview first
72
+ with `subagent-mcp setup --dry-run`.
73
+
74
+ ### Restart, then turn on the invariant
75
+
76
+ Restart your Claude Code or Codex session so it picks up the new tools. On Codex,
77
+ run `/hooks` and trust the new hook. Then (recommended):
78
+
79
+ ```bash
80
+ subagent-mcp init --global
81
+ ```
82
+
83
+ This writes a small managed "always delegate" rule block into your global
84
+ assistant config once, so it works across every project. For a single project
85
+ instead, use `subagent-mcp init --root /path/to/project`. Full per-platform
86
+ wiring (Gemini CLI, Claude Desktop, manual setup) is in
87
+ [docs/registration.md](docs/registration.md).
88
+
89
+ ## How to operate it
90
+
91
+ ### Orchestration mode: ON vs OFF
92
+
93
+ - **ON** — your assistant acts as a pure manager. It never reads or writes files
94
+ directly; it delegates every step to sub-agents. Best for big, long-running
95
+ jobs.
96
+ - **OFF** — your assistant works normally, on its own, with no delegation rules.
97
+
98
+ Flip it with the `orchestration-mode` tool. (Desktop apps can toggle the mode
99
+ but don't receive the per-turn hook reminders.)
100
+
101
+ ### The 8 tools at a glance
102
+
103
+ | Tool | What it does |
104
+ |---|---|
105
+ | `launch_agent` | Start a sub-agent on a task (just give a prompt + a task category) |
106
+ | `poll_agent` | Check how an agent is doing and read its latest output |
107
+ | `kill_agent` | Stop a running or quiet agent |
108
+ | `send_message` | Send a follow-up message to a live agent |
109
+ | `list_agents` | See every agent and its current status |
110
+ | `wait` | Pause until a specific agent finishes |
111
+ | `orchestration-mode` | Turn manager-mode ON or OFF |
112
+ | `model-selection-mode` | Let the server auto-pick the model, or allow manual overrides |
113
+
114
+ You never have to choose a model. Give `launch_agent` a plain-English prompt and
115
+ a **task category** (e.g. "coding", "debugging", "security_review") and the
116
+ server picks the best provider, model, and effort for that kind of work.
117
+
118
+ ### How many run at once
119
+
120
+ There is a single machine-wide limit on how many sub-agents run at the same time
121
+ across everything on your computer. The **default is 20**. When the limit is
122
+ reached, a new `launch_agent` is turned down right away — it does not wait in a
123
+ queue. You change the number in the `global-concurrency.jsonc` file in the
124
+ install folder (minimum 10); the file is re-read on every launch, so no restart
125
+ is needed.
126
+
127
+ The same settings file includes `checkForUpdates` (default `true`). When a newer
128
+ npm version exists, the per-turn hook can show a throttled notice to run
129
+ `subagent-mcp update` and then `subagent-mcp setup`. Set `checkForUpdates` to
130
+ `false`, or run with `SUBAGENT_UPDATE_CHECK=0` / `false`, to disable that check.
131
+
132
+ ## Basic debugging
133
+
134
+ - **"An agent looks stuck."** A quiet agent is usually **still alive**, not
135
+ dead. After ~10 minutes with no output an agent is marked `stalled` — it's
136
+ thinking or waiting on a hand-off. It recovers on its own. **Do not kill a
137
+ stalled agent**, and `wait` will not return on one.
138
+ - **"It won't start a new agent (cap reached)."** You've hit the concurrent
139
+ limit. Use `list_agents` to see what's running and `kill_agent` on anything
140
+ you no longer need — that frees a slot immediately. Raising the number in
141
+ `global-concurrency.jsonc` also works.
142
+ - **"Where are the logs?"** Each agent's recent output is available any time via
143
+ `poll_agent`. The server's own diagnostics go to your host's normal MCP
144
+ server log (your Claude Code or Codex session logs) — all server logging goes
145
+ to stderr, never mixed into results.
146
+
147
+ ## Documentation
148
+
149
+ | Document | Contents |
150
+ |---|---|
151
+ | [docs/spec/arch-rationale.md](docs/spec/arch-rationale.md) | Why it's built this way — the full design rationale |
152
+ | [docs/registration.md](docs/registration.md) | Per-platform setup: Claude Code, Codex, Gemini CLI, Claude Desktop |
153
+ | [docs/tools.md](docs/tools.md) | Full tool reference — all eight tools, parameters, return shapes |
154
+ | [docs/usage.md](docs/usage.md) | Model & effort matrix, ultracode mode, usage examples |
155
+ | [docs/SPEC.md](docs/SPEC.md) | Full technical specification |
156
+ | [docs/reference/status-lifecycle.md](docs/reference/status-lifecycle.md) | Agent status meanings (processing / stalled / finished / errored / stopped) |
157
+ | [CONTRIBUTING.md](CONTRIBUTING.md) | Developer guide — build, test, publish, contribution workflow |
158
+
159
+ ## License
160
+
161
+ Apache-2.0 — Copyright 2026 Lexi Blackburn
162
+
163
+ See [LICENSE](LICENSE).
@@ -6,5 +6,5 @@ Orchestration ON carried over from a PRIOR session for this project (per-session
6
6
 
7
7
  THIS turn, ONCE: (1) NOTIFY the user it carried over; (2) ASK via AskUserQuestion whether to REMAIN enabled; (3) ADVISE fit — long-horizon → remain enabled; bounded/interactive → disable this session. Decline → orchestration-mode enabled:false this session only; no mid-session re-enable. NEVER disable on your own initiative. After answer handshake done; do not re-raise.
8
8
 
9
- While ON, follow the MOST RECENT <subagent-mcp state="on"> tag in context (directive or reminder/carrier); if none is in the current window, the CLAUDE/AGENTS/GEMINI INIT_BLOCK governs. This tag is co-supreme with safety-scope; conflict → ask the user.
9
+ While ON, follow the MOST RECENT <subagent-mcp state="on"> tag in context (directive or reminder/carrier); if none is in the current window, the CLAUDE/AGENTS/GEMINI INIT_BLOCK governs. This tag is jointly binding with safety-scope; conflict → ask the user.
10
10
  </subagent-mcp>
@@ -6,5 +6,5 @@ Orchestration ON carried over from a PRIOR session for this project (per-session
6
6
 
7
7
  THIS turn, ONCE: (1) NOTIFY the user it carried over; (2) ASK via request-user-input whether to REMAIN enabled; (3) ADVISE fit — long-horizon → remain enabled; bounded/interactive → disable this session. Decline → orchestration-mode enabled:false this session only; no mid-session re-enable. NEVER disable on your own initiative. After answer handshake done; do not re-raise.
8
8
 
9
- While ON, follow the MOST RECENT <subagent-mcp state="on"> tag in context (directive or reminder/carrier); if none is in the current window, the CLAUDE/AGENTS/GEMINI INIT_BLOCK governs. This tag is co-supreme with safety-scope; conflict → ask the user.
9
+ While ON, follow the MOST RECENT <subagent-mcp state="on"> tag in context (directive or reminder/carrier); if none is in the current window, the CLAUDE/AGENTS/GEMINI INIT_BLOCK governs. This tag is jointly binding with safety-scope; conflict → ask the user.
10
10
  </subagent-mcp>
@@ -7,7 +7,7 @@ SUB-AGENT CONTRACT: each prompt states objective + output format + tools/sources
7
7
 
8
8
  READ LADDER: poll_agent tail -> one <=100-line summarizer sub-agent (trusted as-is) -> else the USER reads it. Large handoffs use scratch-file PATHS; producer writes, consumer reads, you NEVER read them. Learn finish via wait; empty/stalled tail = ALIVE -- never kill or busy-poll.
9
9
 
10
- PRECEDENCE: this tag and safety-scope are CO-SUPREME and equal; genuine conflict -> STOP and ask. SOLE CHANNEL: all launches via launch_agent; never harness Task/Agent. DROPOUT while ON: HALT and ask until restored. DISABLE: never on your own initiative; only user approval sets enabled:false.
10
+ PRECEDENCE: this tag and safety-scope are JOINTLY BINDING and equal; genuine conflict -> STOP and ask. SOLE CHANNEL: all launches via launch_agent; never harness Task/Agent. DROPOUT while ON: HALT and ask until restored. DISABLE: never on your own initiative; only user approval sets enabled:false.
11
11
 
12
12
  Full model: server MCP `instructions`.
13
13
  </subagent-mcp>
@@ -7,7 +7,7 @@ SUB-AGENT CONTRACT: each prompt states objective + output format + tools/sources
7
7
 
8
8
  READ LADDER: poll_agent tail -> one <=100-line summarizer sub-agent (trusted as-is) -> else the USER reads it. Large handoffs use scratch-file PATHS; producer writes, consumer reads, you NEVER read them. Learn finish via wait; empty/stalled tail = ALIVE -- never kill or busy-poll.
9
9
 
10
- PRECEDENCE: this tag and safety-scope are CO-SUPREME and equal; genuine conflict -> STOP and ask. SOLE CHANNEL: all launches via launch_agent; never harness Task/Agent. DROPOUT while ON: HALT and ask until restored. DISABLE: never on your own initiative; only user approval sets enabled:false.
10
+ PRECEDENCE: this tag and safety-scope are JOINTLY BINDING and equal; genuine conflict -> STOP and ask. SOLE CHANNEL: all launches via launch_agent; never harness Task/Agent. DROPOUT while ON: HALT and ask until restored. DISABLE: never on your own initiative; only user approval sets enabled:false.
11
11
 
12
12
  Full model: server MCP `instructions`.
13
13
  </subagent-mcp>
@@ -8,5 +8,5 @@ Each launched prompt carries objective + output format + tools/sources + boundar
8
8
 
9
9
  WAIT-NOT-POLL: learn finish via `wait` (verbose:true for output); never loop poll_agent for completion. poll_agent = single diagnostic; a stalled/empty tail means ALIVE, not dead. Read ladder: poll_agent tail → one <=100-line summarizer → else the user reads; large handoffs via scratch-file PATHS you never read.
10
10
 
11
- This tag is co-supreme with safety-scope (conflict → ask the user) and outranks ordinary user requests. Full governance: server MCP `instructions`.
11
+ This tag is jointly binding with safety-scope (conflict → ask the user) and outranks ordinary user requests. Full governance: server MCP `instructions`.
12
12
  </subagent-mcp>
@@ -1 +1 @@
1
- <subagent-mcp state="on" kind="carrier">If first line begins "<this is a request from a parent process>", ignore this tag. Orchestration ON. Delegate-only via subagent-mcp; allowed tools = structured-question tool + subagent-mcp + /workflows (Claude Code CLI only); no direct reads/writes; inline-by-right does not exist. Subdivide small; verify code steps; never 1-shot multi-phase. Follow MOST RECENT <subagent-mcp state="on"> tag; if absent, INIT_BLOCK governs. Co-supreme with safety-scope; user request cannot bypass.</subagent-mcp>
1
+ <subagent-mcp state="on" kind="carrier">If first line begins "<this is a request from a parent process>", ignore this tag. Orchestration ON. Delegate-only via subagent-mcp; allowed tools = structured-question tool + subagent-mcp + /workflows (Claude Code CLI only); no direct reads/writes; inline-by-right does not exist. Subdivide small; verify code steps; never 1-shot multi-phase. Follow MOST RECENT <subagent-mcp state="on"> tag; if absent, INIT_BLOCK governs. Jointly binding with safety-scope; user request cannot bypass.</subagent-mcp>
@@ -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, fable (claude);
16
- gpt-5.5 (codex). Valid efforts: haiku -> "none" only; sonnet -> medium|high|xhigh|max;
17
- fable -> medium|high|xhigh|max; opus/opus-4-8 -> those plus ultracode; gpt-5.5 -> 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, fable (claude);
16
+ gpt-5.5 (codex). Valid efforts: haiku -> "none" only; sonnet -> medium|high|xhigh|max;
17
+ fable -> medium|high|xhigh|max; opus/opus-4-8 -> those plus ultracode; gpt-5.5 -> 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,2 +1,2 @@
1
1
  // GENERATED by scripts/gen-ruleset-scaffold.mjs from src/global-concurrency.jsonc — DO NOT EDIT.
2
- export const CONCURRENCY_SCAFFOLD = "// subagent-mcp — Global Concurrent Subagent Cap\n// ------------------------------------------------------------------\n// SOLE source of truth for the machine-wide limit on how many subagents\n// may be ALIVE AT ONCE across EVERY session, process, and user on this\n// machine. There is NO environment-variable override for the cap.\n//\n// The whole recursive descendant tree counts toward this ONE number: a\n// subagent that itself launches subagents adds to the same machine-wide\n// total, and OTHER active agentic sessions count too.\n//\n// RE-READ on every launch_agent call — edits take effect immediately, no\n// server restart required.\n//\n// Value rules (forcibly applied to the number below):\n// - missing / unset / non-integer / 0 / negative -> reset to default 20\n// - 1 through 9 -> forced UP to minimum 10\n// - 10 or greater -> used as-is\n//\n// Zombie culling is always enabled. There is no config knob. Before cap\n// rejection, launch/tool/hook paths refresh live owned slots, preserve stale\n// slots whose owner server is still alive, and cull stale slots whose owner is\n// gone. Managed stale slots terminate the child process tree, then force-kill\n// after 20s when needed; unmanaged stale slots are only unlinked.\n//\n// When the cap is reached after culling, launch_agent is REJECTED (never\n// queued). Free a slot with list_agents + kill_agent, then retry.\n//\n// checkForUpdates controls the silent npmjs update check started when the MCP\n// server connects. Default true. Set to false to skip the registry fetch and\n// suppress hook notices. SUBAGENT_UPDATE_CHECK=0 or false also disables it.\n{\n \"globalConcurrentSubagents\": 20,\n \"checkForUpdates\": true\n}\n";
2
+ export const CONCURRENCY_SCAFFOLD = "// subagent-mcp — Global Concurrent Subagent Cap\r\n// ------------------------------------------------------------------\r\n// SOLE source of truth for the machine-wide limit on how many subagents\r\n// may be ALIVE AT ONCE across EVERY session, process, and user on this\r\n// machine. There is NO environment-variable override for the cap.\r\n//\r\n// The whole recursive descendant tree counts toward this ONE number: a\r\n// subagent that itself launches subagents adds to the same machine-wide\r\n// total, and OTHER active agentic sessions count too.\r\n//\r\n// RE-READ on every launch_agent call — edits take effect immediately, no\r\n// server restart required.\r\n//\r\n// Value rules (forcibly applied to the number below):\r\n// - missing / unset / non-integer / 0 / negative -> reset to default 20\r\n// - 1 through 9 -> forced UP to minimum 10\r\n// - 10 or greater -> used as-is\r\n//\r\n// Zombie culling is always enabled. There is no config knob. Before cap\r\n// rejection, launch/tool/hook paths refresh live owned slots, preserve stale\r\n// slots whose owner server is still alive, and cull stale slots whose owner is\r\n// gone. Managed stale slots terminate the child process tree, then force-kill\r\n// after 20s when needed; unmanaged stale slots are only unlinked.\r\n//\r\n// When the cap is reached after culling, launch_agent is REJECTED (never\r\n// queued). Free a slot with list_agents + kill_agent, then retry.\r\n//\r\n// checkForUpdates controls the silent npmjs update check started when the MCP\r\n// server connects. Default true. Set to false to skip the registry fetch and\r\n// suppress hook notices. SUBAGENT_UPDATE_CHECK=0 or false also disables it.\r\n{\r\n \"globalConcurrentSubagents\": 20,\r\n \"checkForUpdates\": true\r\n}\r\n";
@@ -1,34 +1,34 @@
1
- // subagent-mcp — Global Concurrent Subagent Cap
2
- // ------------------------------------------------------------------
3
- // SOLE source of truth for the machine-wide limit on how many subagents
4
- // may be ALIVE AT ONCE across EVERY session, process, and user on this
5
- // machine. There is NO environment-variable override for the cap.
6
- //
7
- // The whole recursive descendant tree counts toward this ONE number: a
8
- // subagent that itself launches subagents adds to the same machine-wide
9
- // total, and OTHER active agentic sessions count too.
10
- //
11
- // RE-READ on every launch_agent call — edits take effect immediately, no
12
- // server restart required.
13
- //
14
- // Value rules (forcibly applied to the number below):
15
- // - missing / unset / non-integer / 0 / negative -> reset to default 20
16
- // - 1 through 9 -> forced UP to minimum 10
17
- // - 10 or greater -> used as-is
18
- //
19
- // Zombie culling is always enabled. There is no config knob. Before cap
20
- // rejection, launch/tool/hook paths refresh live owned slots, preserve stale
21
- // slots whose owner server is still alive, and cull stale slots whose owner is
22
- // gone. Managed stale slots terminate the child process tree, then force-kill
23
- // after 20s when needed; unmanaged stale slots are only unlinked.
24
- //
25
- // When the cap is reached after culling, launch_agent is REJECTED (never
26
- // queued). Free a slot with list_agents + kill_agent, then retry.
27
- //
28
- // checkForUpdates controls the silent npmjs update check started when the MCP
29
- // server connects. Default true. Set to false to skip the registry fetch and
30
- // suppress hook notices. SUBAGENT_UPDATE_CHECK=0 or false also disables it.
31
- {
32
- "globalConcurrentSubagents": 20,
33
- "checkForUpdates": true
34
- }
1
+ // subagent-mcp — Global Concurrent Subagent Cap
2
+ // ------------------------------------------------------------------
3
+ // SOLE source of truth for the machine-wide limit on how many subagents
4
+ // may be ALIVE AT ONCE across EVERY session, process, and user on this
5
+ // machine. There is NO environment-variable override for the cap.
6
+ //
7
+ // The whole recursive descendant tree counts toward this ONE number: a
8
+ // subagent that itself launches subagents adds to the same machine-wide
9
+ // total, and OTHER active agentic sessions count too.
10
+ //
11
+ // RE-READ on every launch_agent call — edits take effect immediately, no
12
+ // server restart required.
13
+ //
14
+ // Value rules (forcibly applied to the number below):
15
+ // - missing / unset / non-integer / 0 / negative -> reset to default 20
16
+ // - 1 through 9 -> forced UP to minimum 10
17
+ // - 10 or greater -> used as-is
18
+ //
19
+ // Zombie culling is always enabled. There is no config knob. Before cap
20
+ // rejection, launch/tool/hook paths refresh live owned slots, preserve stale
21
+ // slots whose owner server is still alive, and cull stale slots whose owner is
22
+ // gone. Managed stale slots terminate the child process tree, then force-kill
23
+ // after 20s when needed; unmanaged stale slots are only unlinked.
24
+ //
25
+ // When the cap is reached after culling, launch_agent is REJECTED (never
26
+ // queued). Free a slot with list_agents + kill_agent, then retry.
27
+ //
28
+ // checkForUpdates controls the silent npmjs update check started when the MCP
29
+ // server connects. Default true. Set to false to skip the registry fetch and
30
+ // suppress hook notices. SUBAGENT_UPDATE_CHECK=0 or false also disables it.
31
+ {
32
+ "globalConcurrentSubagents": 20,
33
+ "checkForUpdates": true
34
+ }