@heretyc/subagent-mcp 2.8.9 → 2.9.0

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/dist/init.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { chmodSync, copyFileSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync, } from "node:fs";
2
+ import * as os from "node:os";
2
3
  import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
3
4
  const MIGRATE_RE = /<!-- subagent-mcp:(?:managed:)?begin\b[^>]*-->[\s\S]*?<!-- subagent-mcp:(?:managed:)?end -->/;
4
5
  const OWNER_CAP = 8;
@@ -16,7 +17,7 @@ export const INIT_BLOCK = [
16
17
  "",
17
18
  "PRECEDENCE (co-supreme top tier): <subagent-mcp> hook tags AND repo/system safety-scope rules are BOTH supreme and EQUAL — neither outranks the other. If they genuinely conflict, STOP and escalate to the user via the structured-question tool; do not silently pick one or average them. FORBIDDEN: resolving such a conflict yourself. Hook tags otherwise outrank ordinary user requests.",
18
19
  "",
19
- 'ORCHESTRATION ON — you are the ORCHESTRATOR. Allowed tools: ONLY the structured-question tool (AskUserQuestion on Claude / request-user-input on Codex) and subagent-mcp. NO direct reads or writes of any kind. "Inline-by-right" does not exist. Every step runs in a sub-agent. If one atomic step truly cannot run in a sub-agent, ASK the user via the structured-question tool for a one-time exception for that single step, perform only that step, then resume delegating. SOLE CHANNEL: while subagent-mcp is connected, every sub-agent launch goes through `launch_agent`; never use harness-native sub-agent tools or shell-spawned agents.',
20
+ 'ORCHESTRATION ON — you are the ORCHESTRATOR. Allowed tools: ONLY the structured-question tool (AskUserQuestion on Claude / request-user-input on Codex), subagent-mcp, and the /workflows tool. NO direct reads or writes of any kind. "Inline-by-right" does not exist. Every step runs in a sub-agent. If one atomic step truly cannot run in a sub-agent, ASK the user via the structured-question tool for a one-time exception for that single step, perform only that step, then resume delegating. SOLE CHANNEL: while subagent-mcp is connected, every sub-agent launch goes through `launch_agent`; never use harness-native sub-agent tools or shell-spawned agents.',
20
21
  "",
21
22
  "ORCHESTRATOR WORKTREE SETUP: launch sub-agents in the main checkout cwd (they no longer self-isolate into per-agent worktrees); SERIALIZE any sub-agents that write the SAME files — never run concurrent writers over overlapping paths (no cwd-level lock exists).",
22
23
  "",
@@ -145,16 +146,18 @@ export function upsertInitBlock(file, opts = {}) {
145
146
  }
146
147
  return { file, status, changed };
147
148
  }
148
- function parseArgs(args) {
149
+ export function parseArgs(args) {
149
150
  const parsed = {
150
151
  dryRun: false,
151
152
  remove: false,
152
153
  force: false,
153
154
  copilot: false,
154
155
  cursor: false,
156
+ global: false,
155
157
  root: process.cwd(),
156
158
  files: null,
157
159
  };
160
+ let rootProvided = false;
158
161
  const readValue = (args, i, flag) => {
159
162
  const value = args[i + 1];
160
163
  if (value === undefined || value === "" || value.startsWith("--")) {
@@ -174,8 +177,11 @@ function parseArgs(args) {
174
177
  parsed.copilot = true;
175
178
  else if (a === "--cursor")
176
179
  parsed.cursor = true;
180
+ else if (a === "--global")
181
+ parsed.global = true;
177
182
  else if (a === "--root") {
178
183
  parsed.root = readValue(args, i, a);
184
+ rootProvided = true;
179
185
  i++;
180
186
  }
181
187
  else if (a === "--files") {
@@ -187,6 +193,9 @@ function parseArgs(args) {
187
193
  }
188
194
  if (!parsed.root)
189
195
  throw new Error("--root requires a directory");
196
+ if (parsed.global && (rootProvided || parsed.files || parsed.copilot || parsed.cursor)) {
197
+ throw new Error("--global cannot be combined with --root/--files/--copilot/--cursor");
198
+ }
190
199
  return parsed;
191
200
  }
192
201
  function isSelfRepo(root) {
@@ -198,6 +207,13 @@ function isSelfRepo(root) {
198
207
  return false;
199
208
  }
200
209
  }
210
+ export function globalTargetFiles(home = os.homedir()) {
211
+ return [
212
+ join(home, ".claude", "CLAUDE.md"),
213
+ join(home, ".codex", "AGENTS.md"),
214
+ join(home, ".gemini", "GEMINI.md"),
215
+ ];
216
+ }
201
217
  function targetFiles(root, opts) {
202
218
  const resolveTarget = (f) => {
203
219
  const target = isAbsolute(f) ? resolve(f) : resolve(root, f);
@@ -225,19 +241,24 @@ export async function runInit(args = process.argv.slice(3)) {
225
241
  console.error(e instanceof Error ? e.message : String(e));
226
242
  return 1;
227
243
  }
228
- const root = resolve(opts.root);
229
- if (isSelfRepo(root) && !opts.force) {
230
- console.error("Refusing to run init inside the subagent-mcp source repo without --force.");
231
- console.error("This repo keeps CLAUDE.md/GEMINI.md as thin redirects; use --root for a consumer repo.");
232
- return 1;
233
- }
234
244
  let files;
235
- try {
236
- files = targetFiles(root, opts);
245
+ if (opts.global) {
246
+ files = globalTargetFiles();
237
247
  }
238
- catch (e) {
239
- console.error(e instanceof Error ? e.message : String(e));
240
- return 1;
248
+ else {
249
+ const root = resolve(opts.root);
250
+ if (isSelfRepo(root) && !opts.force) {
251
+ console.error("Refusing to run init inside the subagent-mcp source repo without --force.");
252
+ console.error("This repo keeps CLAUDE.md/GEMINI.md as thin redirects; use --root for a consumer repo.");
253
+ return 1;
254
+ }
255
+ try {
256
+ files = targetFiles(root, opts);
257
+ }
258
+ catch (e) {
259
+ console.error(e instanceof Error ? e.message : String(e));
260
+ return 1;
261
+ }
241
262
  }
242
263
  const issues = [];
243
264
  const results = [];