@muggleai/works 5.22.0-staging.153 → 5.22.0-staging.155

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.
Files changed (136) hide show
  1. package/README.md +74 -17
  2. package/dist/{chunk-KHHZKYJX.js → chunk-6ROSBSNR.js} +104 -4
  3. package/dist/{chunk-7GF5CYNK.js → chunk-E3T2RN6R.js} +8 -0
  4. package/dist/cli.js +2 -2
  5. package/dist/index.js +2 -2
  6. package/dist/plugin/.claude-plugin/plugin.json +1 -1
  7. package/dist/plugin/.codex-mcp.json +55 -0
  8. package/dist/plugin/.codex-plugin/plugin.json +46 -0
  9. package/dist/plugin/.cursor-plugin/plugin.json +1 -1
  10. package/dist/plugin/README.md +15 -4
  11. package/dist/plugin/hooks/README.md +12 -0
  12. package/dist/plugin/hooks/codex-hooks.json +147 -0
  13. package/dist/plugin/hooks/hooks.json +1 -1
  14. package/dist/plugin/scripts/codex-hook-windows.mjs +81 -0
  15. package/dist/plugin/scripts/ensure-electron-app.sh +16 -1
  16. package/dist/plugin/scripts/guard-run.mjs +16 -7
  17. package/dist/plugin/scripts/guardrail-capability-claim.sh +10 -4
  18. package/dist/plugin/scripts/guardrail-classify-gate.sh +3 -2
  19. package/dist/plugin/scripts/guardrail-record-stage-read.sh +14 -9
  20. package/dist/plugin/scripts/guardrail-record-stage-signals.sh +1 -1
  21. package/dist/plugin/scripts/guardrail-record-tests.sh +1 -1
  22. package/dist/plugin/scripts/guardrails.mjs +234 -64
  23. package/dist/plugin/skills/CLAUDE.md +6 -0
  24. package/dist/plugin/skills/_shared/host-tool-equivalents.md +27 -0
  25. package/dist/plugin/skills/m/SKILL.md +1 -1
  26. package/dist/plugin/skills/m/agents/openai.yaml +7 -0
  27. package/dist/plugin/skills/mbt/SKILL.md +1 -1
  28. package/dist/plugin/skills/mbt/agents/openai.yaml +7 -0
  29. package/dist/plugin/skills/mdo/SKILL.md +1 -1
  30. package/dist/plugin/skills/mdo/agents/openai.yaml +7 -0
  31. package/dist/plugin/skills/mfeedback/SKILL.md +1 -1
  32. package/dist/plugin/skills/mfeedback/agents/openai.yaml +7 -0
  33. package/dist/plugin/skills/mimport/SKILL.md +1 -1
  34. package/dist/plugin/skills/mimport/agents/openai.yaml +7 -0
  35. package/dist/plugin/skills/mpr/SKILL.md +1 -1
  36. package/dist/plugin/skills/mpr/agents/openai.yaml +7 -0
  37. package/dist/plugin/skills/mprefs/SKILL.md +1 -1
  38. package/dist/plugin/skills/mprefs/agents/openai.yaml +7 -0
  39. package/dist/plugin/skills/mprfollowup/SKILL.md +1 -1
  40. package/dist/plugin/skills/mprfollowup/agents/openai.yaml +7 -0
  41. package/dist/plugin/skills/mregen/SKILL.md +1 -1
  42. package/dist/plugin/skills/mregen/agents/openai.yaml +7 -0
  43. package/dist/plugin/skills/mrepair/SKILL.md +1 -1
  44. package/dist/plugin/skills/mrepair/agents/openai.yaml +7 -0
  45. package/dist/plugin/skills/mstatus/SKILL.md +1 -1
  46. package/dist/plugin/skills/mstatus/agents/openai.yaml +7 -0
  47. package/dist/plugin/skills/mtest/SKILL.md +1 -1
  48. package/dist/plugin/skills/mtest/agents/openai.yaml +7 -0
  49. package/dist/plugin/skills/mtestlocal/SKILL.md +1 -1
  50. package/dist/plugin/skills/mtestlocal/agents/openai.yaml +7 -0
  51. package/dist/plugin/skills/mtestprep/SKILL.md +1 -1
  52. package/dist/plugin/skills/mtestprep/agents/openai.yaml +7 -0
  53. package/dist/plugin/skills/muggle/SKILL.md +2 -0
  54. package/dist/plugin/skills/muggle-browser-task/SKILL.md +2 -0
  55. package/dist/plugin/skills/muggle-do/SKILL.md +2 -0
  56. package/dist/plugin/skills/muggle-feedback/SKILL.md +2 -0
  57. package/dist/plugin/skills/muggle-pr-followup/SKILL.md +2 -0
  58. package/dist/plugin/skills/muggle-pr-visual-walkthrough/SKILL.md +43 -41
  59. package/dist/plugin/skills/muggle-preferences/SKILL.md +28 -26
  60. package/dist/plugin/skills/muggle-repair/SKILL.md +2 -0
  61. package/dist/plugin/skills/muggle-status/SKILL.md +2 -0
  62. package/dist/plugin/skills/muggle-test/SKILL.md +2 -0
  63. package/dist/plugin/skills/muggle-test-feature-local/SKILL.md +2 -0
  64. package/dist/plugin/skills/muggle-test-import/SKILL.md +2 -0
  65. package/dist/plugin/skills/muggle-test-prepare/SKILL.md +145 -143
  66. package/dist/plugin/skills/muggle-test-regenerate-missing/SKILL.md +2 -0
  67. package/dist/plugin/skills/muggle-upgrade/SKILL.md +2 -0
  68. package/dist/plugin/skills/mupgrade/SKILL.md +1 -1
  69. package/dist/plugin/skills/mupgrade/agents/openai.yaml +7 -0
  70. package/dist/release-manifest.json +3 -3
  71. package/dist/{src-VVWBQMWR.js → src-V245RV7L.js} +1 -1
  72. package/package.json +4 -2
  73. package/plugin/.claude-plugin/plugin.json +1 -1
  74. package/plugin/.codex-mcp.json +55 -0
  75. package/plugin/.codex-plugin/plugin.json +46 -0
  76. package/plugin/.cursor-plugin/plugin.json +1 -1
  77. package/plugin/README.md +15 -4
  78. package/plugin/hooks/README.md +12 -0
  79. package/plugin/hooks/codex-hooks.json +147 -0
  80. package/plugin/hooks/hooks.json +1 -1
  81. package/plugin/scripts/codex-hook-windows.mjs +81 -0
  82. package/plugin/scripts/ensure-electron-app.sh +16 -1
  83. package/plugin/scripts/guard-run.mjs +16 -7
  84. package/plugin/scripts/guardrail-capability-claim.sh +10 -4
  85. package/plugin/scripts/guardrail-classify-gate.sh +3 -2
  86. package/plugin/scripts/guardrail-record-stage-read.sh +14 -9
  87. package/plugin/scripts/guardrail-record-stage-signals.sh +1 -1
  88. package/plugin/scripts/guardrail-record-tests.sh +1 -1
  89. package/plugin/scripts/guardrails.mjs +234 -64
  90. package/plugin/skills/CLAUDE.md +6 -0
  91. package/plugin/skills/_shared/host-tool-equivalents.md +27 -0
  92. package/plugin/skills/m/SKILL.md +1 -1
  93. package/plugin/skills/m/agents/openai.yaml +7 -0
  94. package/plugin/skills/mbt/SKILL.md +1 -1
  95. package/plugin/skills/mbt/agents/openai.yaml +7 -0
  96. package/plugin/skills/mdo/SKILL.md +1 -1
  97. package/plugin/skills/mdo/agents/openai.yaml +7 -0
  98. package/plugin/skills/mfeedback/SKILL.md +1 -1
  99. package/plugin/skills/mfeedback/agents/openai.yaml +7 -0
  100. package/plugin/skills/mimport/SKILL.md +1 -1
  101. package/plugin/skills/mimport/agents/openai.yaml +7 -0
  102. package/plugin/skills/mpr/SKILL.md +1 -1
  103. package/plugin/skills/mpr/agents/openai.yaml +7 -0
  104. package/plugin/skills/mprefs/SKILL.md +1 -1
  105. package/plugin/skills/mprefs/agents/openai.yaml +7 -0
  106. package/plugin/skills/mprfollowup/SKILL.md +1 -1
  107. package/plugin/skills/mprfollowup/agents/openai.yaml +7 -0
  108. package/plugin/skills/mregen/SKILL.md +1 -1
  109. package/plugin/skills/mregen/agents/openai.yaml +7 -0
  110. package/plugin/skills/mrepair/SKILL.md +1 -1
  111. package/plugin/skills/mrepair/agents/openai.yaml +7 -0
  112. package/plugin/skills/mstatus/SKILL.md +1 -1
  113. package/plugin/skills/mstatus/agents/openai.yaml +7 -0
  114. package/plugin/skills/mtest/SKILL.md +1 -1
  115. package/plugin/skills/mtest/agents/openai.yaml +7 -0
  116. package/plugin/skills/mtestlocal/SKILL.md +1 -1
  117. package/plugin/skills/mtestlocal/agents/openai.yaml +7 -0
  118. package/plugin/skills/mtestprep/SKILL.md +1 -1
  119. package/plugin/skills/mtestprep/agents/openai.yaml +7 -0
  120. package/plugin/skills/muggle/SKILL.md +2 -0
  121. package/plugin/skills/muggle-browser-task/SKILL.md +2 -0
  122. package/plugin/skills/muggle-do/SKILL.md +2 -0
  123. package/plugin/skills/muggle-feedback/SKILL.md +2 -0
  124. package/plugin/skills/muggle-pr-followup/SKILL.md +2 -0
  125. package/plugin/skills/muggle-pr-visual-walkthrough/SKILL.md +43 -41
  126. package/plugin/skills/muggle-preferences/SKILL.md +28 -26
  127. package/plugin/skills/muggle-repair/SKILL.md +2 -0
  128. package/plugin/skills/muggle-status/SKILL.md +2 -0
  129. package/plugin/skills/muggle-test/SKILL.md +2 -0
  130. package/plugin/skills/muggle-test-feature-local/SKILL.md +2 -0
  131. package/plugin/skills/muggle-test-import/SKILL.md +2 -0
  132. package/plugin/skills/muggle-test-prepare/SKILL.md +145 -143
  133. package/plugin/skills/muggle-test-regenerate-missing/SKILL.md +2 -0
  134. package/plugin/skills/muggle-upgrade/SKILL.md +2 -0
  135. package/plugin/skills/mupgrade/SKILL.md +1 -1
  136. package/plugin/skills/mupgrade/agents/openai.yaml +7 -0
@@ -1,5 +1,5 @@
1
1
  import { readFileSync, existsSync, mkdirSync, writeFileSync, renameSync, readdirSync, openSync, writeSync, closeSync, unlinkSync } from 'fs';
2
- import { join, isAbsolute, resolve, dirname } from 'path';
2
+ import { basename, join, isAbsolute, resolve, dirname } from 'path';
3
3
  import { homedir, hostname } from 'os';
4
4
  import { fileURLToPath } from 'url';
5
5
  import { execFileSync } from 'child_process';
@@ -13,20 +13,40 @@ var GH_PR_REOPENED_LINE = /\bReopened pull request [\w./-]*#(\d+)/;
13
13
  var PR_MONITOR_TERMINAL_LINE = /\bTERMINAL pr=(\d+)(?: state=|: )(MERGED|CLOSED)\b/;
14
14
  var MAX_PR_TERMINAL_BLOCKS = 3;
15
15
  var SHELL_TOOL_NAMES = ["Bash", "PowerShell"];
16
+ var HOOK_HOST_ENV_VAR = "MUGGLE_HOOK_HOST";
17
+ var NEXT_OPTIONS_OFFER_TOOL_NAMES = ["AskUserQuestion", "request_user_input"];
18
+ var FILE_PRINTING_PROGRAMS = [
19
+ "cat",
20
+ "sed",
21
+ "head",
22
+ "tail",
23
+ "nl",
24
+ "less",
25
+ "more",
26
+ "bat",
27
+ "batcat",
28
+ "awk",
29
+ "get-content",
30
+ "gc",
31
+ "type"
32
+ ];
16
33
  var MAX_WATCH_BLOCKS = 3;
17
34
  var MAX_BUILD_BLOCKS = 3;
18
35
  var MAX_WALKTHROUGH_BLOCKS = 3;
19
36
  var GH_LOOKUP_TIMEOUT_MS = 1e4;
20
- var MUGGLE_SKILL_EMIT_TOOL = /muggle-local-telemetry-skill-emit/i;
37
+ function mcpToolNamePattern(hyphenatedSource) {
38
+ return new RegExp(hyphenatedSource.replaceAll("-", "[-_]"), "i");
39
+ }
40
+ var MUGGLE_SKILL_EMIT_TOOL = mcpToolNamePattern("muggle-local-telemetry-skill-emit");
21
41
  var MUGGLE_TEST_SKILL_NAME = "muggle-test";
22
42
  var MANDATORY_STAGES_FRONTMATTER_KEY = "mandatoryStages";
23
43
  var SKILL_NAME_INPUT_KEYS = ["skill", "skillName", "name", "command"];
24
44
  var MAX_STAGE_BLOCKS = 3;
25
45
  var MAX_DEBUG_BLOCKS = 3;
26
46
  var ANY_TEST_CASE = "*";
27
- var MUGGLE_EXECUTION_TOOL = /muggle-local-(execute-test-generation|execute-replay)/i;
28
- var MUGGLE_EVENT_EMIT_TOOL = /muggle-local-telemetry-event-emit/i;
29
- var MUGGLE_FEEDBACK_CREATE_TOOL = /muggle-remote-user-feedback-create/i;
47
+ var MUGGLE_EXECUTION_TOOL = mcpToolNamePattern("muggle-local-(execute-test-generation|execute-replay)");
48
+ var MUGGLE_EVENT_EMIT_TOOL = mcpToolNamePattern("muggle-local-telemetry-event-emit");
49
+ var MUGGLE_FEEDBACK_CREATE_TOOL = mcpToolNamePattern("muggle-remote-user-feedback-create");
30
50
  var PRE_EXECUTION_CLASSIFICATION_EVENT = "pre-execution-classification";
31
51
  var FAILURE_DIAGNOSIS_EVENT = /-failure-(classified|resolved)$/;
32
52
  var MUGGLE_RUN_ID_LINE = /\*\*Run ID:\*\*\s*([^\s*]+)/;
@@ -134,20 +154,19 @@ function writeState(state, dirOverride) {
134
154
  writeFileSync(staging, JSON.stringify(state, null, 2));
135
155
  renameSync(staging, target);
136
156
  }
137
- function updateState(sessionId2, mutate, dirOverride) {
157
+ function commitState(sessionId2, mutate, dirOverride) {
138
158
  mkdirSync(baseDir(dirOverride), { recursive: true });
139
- const committed = withFileLock(
140
- `${fileFor(sessionId2, dirOverride)}.lock`,
141
- SESSION_STATE_LOCK_WAIT_MS,
142
- () => {
143
- const current = readState(sessionId2, dirOverride);
144
- const next = mutate(current);
145
- if (next === current) return true;
146
- writeState({ ...next, generation: (current.generation ?? 0) + 1 }, dirOverride);
147
- return true;
148
- }
149
- );
150
- return committed === true;
159
+ return withFileLock(`${fileFor(sessionId2, dirOverride)}.lock`, SESSION_STATE_LOCK_WAIT_MS, () => {
160
+ const current = readState(sessionId2, dirOverride);
161
+ const next = mutate(current);
162
+ if (next === current) return current;
163
+ const committed = { ...next, generation: (current.generation ?? 0) + 1 };
164
+ writeState(committed, dirOverride);
165
+ return committed;
166
+ });
167
+ }
168
+ function updateState(sessionId2, mutate, dirOverride) {
169
+ return commitState(sessionId2, mutate, dirOverride) !== void 0;
151
170
  }
152
171
  function markPrHandled(sessionId2, prUrl, dirOverride) {
153
172
  const state = readState(sessionId2, dirOverride);
@@ -240,6 +259,9 @@ function applyNextOptionsOffered(state) {
240
259
  terminalBlockCount: 0
241
260
  };
242
261
  }
262
+ function closingMessageAsksUser(closingMessage) {
263
+ return typeof closingMessage === "string" && closingMessage.includes("?");
264
+ }
243
265
  function prTerminalGateDecision(state, maxBlocks = MAX_PR_TERMINAL_BLOCKS) {
244
266
  const blockCount = state.terminalBlockCount ?? 0;
245
267
  if ((state.terminalPending ?? []).length === 0) {
@@ -290,6 +312,11 @@ var STAGE_SKIP_MARKER = /^\s*echo\s+["']?MUGGLE_STAGE_SKIP\b/;
290
312
  var SKILLS_DIR_NAME = "skills";
291
313
  var SKILLS_PATH_SEGMENT = `/${SKILLS_DIR_NAME}/`;
292
314
  var SINGLE_PATH_SEGMENT = /^[A-Za-z0-9._-]+$/;
315
+ var SHELL_COMMAND_SEPARATOR = /[;&|\n]/;
316
+ var SHELL_ASSIGNMENT = /^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/s;
317
+ var SHELL_VARIABLE_REFERENCE = /\$\{([A-Za-z_][A-Za-z0-9_]*)\}|\$([A-Za-z_][A-Za-z0-9_]*)/g;
318
+ var WINDOWS_ABSOLUTE_PATH = /^[A-Za-z]:[\\/]/;
319
+ var MARKDOWN_FILE = /\.md$/i;
293
320
  var unquote = (raw) => raw.trim().replace(/^["']|["']$/g, "").trim();
294
321
  function parseDeclaredStages(skillMarkdown) {
295
322
  const frontmatter = FRONTMATTER.exec(skillMarkdown)?.[1];
@@ -362,11 +389,113 @@ function applySkillInvocation(state, skillName, stagePaths) {
362
389
  }
363
390
  return { ...state, lastInvokedSkillName: skillName, mandatoryStages: merged };
364
391
  }
392
+ function isSkillTreeMarkdown(filePath) {
393
+ const normalized = normalizeStagePath(filePath);
394
+ return normalized.includes(SKILLS_PATH_SEGMENT) && MARKDOWN_FILE.test(normalized);
395
+ }
365
396
  function applyStageRead(state, filePath) {
366
397
  const stagePath = normalizeStagePath(filePath);
367
398
  if ((state.stagesRead ?? []).includes(stagePath)) return state;
368
399
  return { ...state, stagesRead: [...state.stagesRead ?? [], stagePath] };
369
400
  }
401
+ var SHELL_ESCAPABLE_UNQUOTED = /* @__PURE__ */ new Set([" ", " ", "'", '"', "\\", "$", ";", "&", "|", "\n"]);
402
+ var SHELL_ESCAPABLE_DOUBLE_QUOTED = /* @__PURE__ */ new Set(['"', "\\", "$", "`"]);
403
+ function splitShellCommands(command) {
404
+ const commands = [];
405
+ let words = [];
406
+ let word = "";
407
+ let wordStarted = false;
408
+ let quote = null;
409
+ const endWord = () => {
410
+ if (wordStarted) words.push(word);
411
+ word = "";
412
+ wordStarted = false;
413
+ };
414
+ const endCommand = () => {
415
+ endWord();
416
+ if (words.length > 0) commands.push(words);
417
+ words = [];
418
+ };
419
+ for (let index = 0; index < command.length; index += 1) {
420
+ const character = command[index];
421
+ const nextCharacter = command[index + 1];
422
+ if (quote !== null) {
423
+ if (character === quote) {
424
+ quote = null;
425
+ } else if (character === "\\" && quote === '"' && SHELL_ESCAPABLE_DOUBLE_QUOTED.has(nextCharacter)) {
426
+ word += nextCharacter;
427
+ index += 1;
428
+ } else {
429
+ word += character;
430
+ }
431
+ continue;
432
+ }
433
+ if (character === "'" || character === '"') {
434
+ quote = character;
435
+ wordStarted = true;
436
+ } else if (character === "\\" && SHELL_ESCAPABLE_UNQUOTED.has(nextCharacter)) {
437
+ word += nextCharacter;
438
+ wordStarted = true;
439
+ index += 1;
440
+ } else if (SHELL_COMMAND_SEPARATOR.test(character)) {
441
+ endCommand();
442
+ } else if (/\s/.test(character)) {
443
+ endWord();
444
+ } else {
445
+ word += character;
446
+ wordStarted = true;
447
+ }
448
+ }
449
+ endCommand();
450
+ return commands;
451
+ }
452
+ function expandShellWord(word, variables) {
453
+ const withHome = word === "~" || word.startsWith("~/") ? `${homedir()}${word.slice(1)}` : word;
454
+ return withHome.replace(
455
+ SHELL_VARIABLE_REFERENCE,
456
+ (_reference, bracedName, bareName) => variables[bracedName ?? bareName ?? ""] ?? ""
457
+ );
458
+ }
459
+ function resolveShellPath(path, workingDirectory) {
460
+ return isAbsolute(path) || WINDOWS_ABSOLUTE_PATH.test(path) ? path : resolve(workingDirectory, path);
461
+ }
462
+ function detectShellStageReads(command, cwd, env = process.env) {
463
+ const variables = { ...env };
464
+ let workingDirectory = cwd ?? process.cwd();
465
+ const readPaths = [];
466
+ for (const words of splitShellCommands(command)) {
467
+ let programIndex = 0;
468
+ const assignments = [];
469
+ for (; programIndex < words.length; programIndex += 1) {
470
+ const assignment = SHELL_ASSIGNMENT.exec(words[programIndex]);
471
+ if (!assignment) break;
472
+ assignments.push([assignment[1], expandShellWord(assignment[2], variables)]);
473
+ }
474
+ const programWord = words[programIndex];
475
+ if (programWord === void 0 || programWord === "export") {
476
+ for (const word of words.slice(programIndex + 1)) {
477
+ const exported = SHELL_ASSIGNMENT.exec(word);
478
+ if (exported) assignments.push([exported[1], expandShellWord(exported[2], variables)]);
479
+ }
480
+ for (const [name, value] of assignments) variables[name] = value;
481
+ continue;
482
+ }
483
+ const program = basename(programWord.replaceAll("\\", "/")).toLowerCase().replace(/\.exe$/, "");
484
+ const argumentWords = words.slice(programIndex + 1).map((word) => expandShellWord(word, variables));
485
+ if (program === "cd") {
486
+ const target = argumentWords.find((word) => !word.startsWith("-"));
487
+ if (target) workingDirectory = resolveShellPath(target, workingDirectory);
488
+ continue;
489
+ }
490
+ if (!FILE_PRINTING_PROGRAMS.includes(program)) continue;
491
+ for (const argument of argumentWords) {
492
+ if (argument.startsWith("-") || !MARKDOWN_FILE.test(argument)) continue;
493
+ const readPath = normalizeStagePath(resolveShellPath(argument, workingDirectory));
494
+ if (isSkillTreeMarkdown(readPath) && !readPaths.includes(readPath)) readPaths.push(readPath);
495
+ }
496
+ }
497
+ return readPaths;
498
+ }
370
499
  function unreadMandatoryStages(state) {
371
500
  const read = new Set(state.stagesRead ?? []);
372
501
  return (state.mandatoryStages ?? []).filter((stagePath) => !read.has(stagePath));
@@ -511,8 +640,10 @@ function isTestCommand(cmd) {
511
640
  return TEST_CMD.test(cmd);
512
641
  }
513
642
  function testsPassed(input2) {
514
- const out = `${input2.tool_response?.stdout ?? ""}
515
- ${input2.tool_response?.stderr ?? ""}`;
643
+ const response = input2.tool_response;
644
+ const out = `${response?.stdout ?? ""}
645
+ ${response?.stderr ?? ""}
646
+ ${response?.output ?? ""}`;
516
647
  if (!out.trim()) return false;
517
648
  return !FAIL.test(out);
518
649
  }
@@ -683,7 +814,8 @@ function runGh(args) {
683
814
  return execFileSync("gh", args, {
684
815
  encoding: "utf-8",
685
816
  timeout: GH_LOOKUP_TIMEOUT_MS,
686
- stdio: ["ignore", "pipe", "ignore"]
817
+ stdio: ["ignore", "pipe", "ignore"],
818
+ windowsHide: true
687
819
  });
688
820
  } catch {
689
821
  return null;
@@ -815,7 +947,8 @@ var defaultGhRunner = (args, input2) => {
815
947
  encoding: "utf-8",
816
948
  input: input2,
817
949
  timeout: GH_COMMENT_TIMEOUT_MS,
818
- stdio: ["pipe", "pipe", "ignore"]
950
+ stdio: ["pipe", "pipe", "ignore"],
951
+ windowsHide: true
819
952
  });
820
953
  } catch {
821
954
  return null;
@@ -1052,7 +1185,12 @@ var listFiles = (dir) => {
1052
1185
  };
1053
1186
  var runGit = (args, cwd) => {
1054
1187
  try {
1055
- return execFileSync("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] });
1188
+ return execFileSync("git", args, {
1189
+ cwd,
1190
+ encoding: "utf8",
1191
+ stdio: ["ignore", "pipe", "ignore"],
1192
+ windowsHide: true
1193
+ });
1056
1194
  } catch {
1057
1195
  return null;
1058
1196
  }
@@ -1074,7 +1212,8 @@ var isReachable = (url) => {
1074
1212
  try {
1075
1213
  execFileSync(process.execPath, ["-e", script], {
1076
1214
  timeout: DEV_SERVER_PROBE_TIMEOUT_MS * 2,
1077
- stdio: "ignore"
1215
+ stdio: "ignore",
1216
+ windowsHide: true
1078
1217
  });
1079
1218
  return true;
1080
1219
  } catch {
@@ -1444,15 +1583,36 @@ function mergeHookOutputs(gateOutputs, host2) {
1444
1583
  return envelope(hookEventName ?? "", contexts.join(MERGED_GATE_OUTPUT_SEPARATOR), host2);
1445
1584
  }
1446
1585
 
1586
+ // src/guardrails/hookInput.ts
1587
+ function normalizeHookInput(raw) {
1588
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return {};
1589
+ const payload = raw;
1590
+ if (typeof payload.tool_response === "string") {
1591
+ return { ...payload, tool_response: { output: payload.tool_response } };
1592
+ }
1593
+ return payload;
1594
+ }
1595
+
1596
+ // src/guardrails/hookHost.ts
1597
+ function resolveHookHost(env = process.env) {
1598
+ if (env[HOOK_HOST_ENV_VAR] === "codex") return "codex";
1599
+ if (env.CURSOR_PLUGIN_ROOT) return "cursor";
1600
+ return "claude";
1601
+ }
1602
+ function skillInvocation(slashCommand, host2) {
1603
+ if (host2 !== "codex") return slashCommand;
1604
+ return `$muggle:${slashCommand.replace(/^\/(?:muggle:)?/, "")}`;
1605
+ }
1606
+
1447
1607
  // src/guardrails/cli.ts
1448
1608
  function readStdin() {
1449
1609
  try {
1450
- return JSON.parse(readFileSync(0, "utf-8"));
1610
+ return normalizeHookInput(JSON.parse(readFileSync(0, "utf-8")));
1451
1611
  } catch {
1452
1612
  return {};
1453
1613
  }
1454
1614
  }
1455
- var host = process.env.CURSOR_PLUGIN_ROOT ? "cursor" : "claude";
1615
+ var host = resolveHookHost();
1456
1616
  var sub = process.argv[2];
1457
1617
  var input = readStdin();
1458
1618
  var sessionId = input.session_id ?? "unknown";
@@ -1463,6 +1623,12 @@ function releaseGate(field) {
1463
1623
  );
1464
1624
  return "{}";
1465
1625
  }
1626
+ function muggleSkill(slashCommand) {
1627
+ return skillInvocation(slashCommand, host);
1628
+ }
1629
+ function nextOptionsOfferMethod() {
1630
+ return host === "codex" ? "by asking them in your closing message (request_user_input where it is available)" : "via AskUserQuestion";
1631
+ }
1466
1632
  function prOpened() {
1467
1633
  const url = detectPrOpened(input);
1468
1634
  if (!url) return "{}";
@@ -1471,7 +1637,7 @@ function prOpened() {
1471
1637
  reserveWalkthroughComment(url);
1472
1638
  const ctx = `A pull request was just opened: ${url}
1473
1639
  Its Muggle AI visual-walkthrough comment is reserved and empty \u2014 settle it by posting the walkthrough there once E2E runs, or by recording why E2E does not apply.
1474
- Per the autoWatchPR preference, a muggle-pr-followup watcher should handle its incoming reviews. If autoWatchPR=always, start it now by invoking /muggle:muggle-pr-followup with the PR URL; if =ask, offer it to the user; if =never, do nothing.`;
1640
+ Per the autoWatchPR preference, a muggle-pr-followup watcher should handle its incoming reviews. If autoWatchPR=always, start it now by invoking ${muggleSkill("/muggle:muggle-pr-followup")} with the PR URL; if =ask, offer it to the user; if =never, do nothing.`;
1475
1641
  return envelope("PostToolUse", ctx, host);
1476
1642
  }
1477
1643
  function prTerminal() {
@@ -1488,43 +1654,48 @@ function prTerminal() {
1488
1654
  const next = applyPrTerminalDetected(state, terminalEvent.prNumber);
1489
1655
  if (next === state) return "{}";
1490
1656
  writeState(next);
1491
- const ctx = `PR #${terminalEvent.prNumber} went terminal (${terminalEvent.verdict}). Run the post-merge handoff now: finalize the watcher slot, tear down per autoCleanup, then OFFER NEXT OPTIONS to the user (AskUserQuestion) \u2014 release, queued work, deferred items. The stop gate holds until the offer runs.`;
1657
+ const ctx = `PR #${terminalEvent.prNumber} went terminal (${terminalEvent.verdict}). Run the post-merge handoff now: finalize the watcher slot, tear down per autoCleanup, then OFFER NEXT OPTIONS to the user ${nextOptionsOfferMethod()} \u2014 release, queued work, deferred items. The stop gate holds until the offer runs.`;
1492
1658
  return envelope("PostToolUse", ctx, host);
1493
1659
  }
1494
1660
  function offerRan() {
1495
- if (input.tool_name !== "AskUserQuestion") return "{}";
1661
+ if (!NEXT_OPTIONS_OFFER_TOOL_NAMES.includes(input.tool_name ?? "")) return "{}";
1496
1662
  const state = readState(sessionId);
1497
1663
  const next = applyNextOptionsOffered(state);
1498
1664
  if (next !== state) writeState(next);
1499
1665
  return "{}";
1500
1666
  }
1501
1667
  function terminalGate() {
1502
- const state = readState(sessionId);
1668
+ const pendingState = readState(sessionId);
1669
+ const state = host === "codex" && closingMessageAsksUser(input.last_assistant_message) ? applyNextOptionsOffered(pendingState) : pendingState;
1670
+ if (state !== pendingState) writeState(state);
1503
1671
  const decision = prTerminalGateDecision(state);
1504
1672
  if (decision.action === "release" /* Release */) return releaseGate("terminalReleased");
1505
1673
  if (decision.action !== "block" /* Block */) return "{}";
1506
1674
  state.terminalBlockCount = decision.blockCount;
1507
1675
  writeState(state);
1508
1676
  const pendingPrList = (state.terminalPending ?? []).map((prNumber) => `#${prNumber}`).join(", ");
1509
- const reason = decision.blockCount === 1 ? `Do not end the turn yet. PR ${pendingPrList} went terminal (merged/closed) but the post-merge handoff has not run. Finalize the watcher slot, tear down per autoCleanup, then offer next options to the user via AskUserQuestion \u2014 release, queued work, deferred items. Only the AskUserQuestion offer clears this gate.` : `Post-merge handoff still owed for PR ${pendingPrList} (reminder ${decision.blockCount}/${MAX_PR_TERMINAL_BLOCKS}): finalize + tear down, then run the AskUserQuestion next-options offer.`;
1677
+ const reason = decision.blockCount === 1 ? `Do not end the turn yet. PR ${pendingPrList} went terminal (merged/closed) but the post-merge handoff has not run. Finalize the watcher slot, tear down per autoCleanup, then offer next options to the user ${nextOptionsOfferMethod()} \u2014 release, queued work, deferred items. Only that offer clears this gate.` : `Post-merge handoff still owed for PR ${pendingPrList} (reminder ${decision.blockCount}/${MAX_PR_TERMINAL_BLOCKS}): finalize + tear down, then offer the next options ${nextOptionsOfferMethod()}.`;
1510
1678
  return blockStop(reason, host);
1511
1679
  }
1512
1680
  function recordTests() {
1513
1681
  const cmd = input.tool_input?.command ?? "";
1514
- const state = readState(sessionId);
1515
- const judgedSkip = judgeE2eSkip(input, state);
1516
- const recorded = applyRecordedRun(state, {
1682
+ const judgedSkip = judgeE2eSkip(input, readState(sessionId));
1683
+ const run = {
1517
1684
  unitTestPassed: isTestCommand(cmd) && testsPassed(input),
1518
1685
  e2eRan: isE2ERun(input),
1519
1686
  e2eSkipped: judgedSkip?.accepted === true
1520
- });
1521
- const withWatchSkip = applyWatchSkip(recorded, isWatchSkipMarker(cmd));
1522
- const withBuildSkip = applyBuildSkip(withWatchSkip, isBuildSkipMarker(cmd));
1523
- const withWalkthroughPost = applyWalkthroughPosted(withBuildSkip, detectWalkthroughPost(input));
1524
- const withWalkthroughSkip = applyWalkthroughSkip(withWalkthroughPost, isWalkthroughSkipMarker(cmd));
1687
+ };
1688
+ const walkthroughPosted = detectWalkthroughPost(input);
1525
1689
  const failedRunId = detectFailedRunId(input);
1526
- const next = failedRunId ? applyFailedRun(withWalkthroughSkip, failedRunId) : withWalkthroughSkip;
1527
- if (next !== state) writeState(next);
1690
+ const record = (state) => {
1691
+ const recorded = applyRecordedRun(state, run);
1692
+ const withWatchSkip = applyWatchSkip(recorded, isWatchSkipMarker(cmd));
1693
+ const withBuildSkip = applyBuildSkip(withWatchSkip, isBuildSkipMarker(cmd));
1694
+ const withWalkthroughPost = applyWalkthroughPosted(withBuildSkip, walkthroughPosted);
1695
+ const withWalkthroughSkip = applyWalkthroughSkip(withWalkthroughPost, isWalkthroughSkipMarker(cmd));
1696
+ return failedRunId ? applyFailedRun(withWalkthroughSkip, failedRunId) : withWalkthroughSkip;
1697
+ };
1698
+ const next = commitState(sessionId, record) ?? record(readState(sessionId));
1528
1699
  if (judgedSkip?.accepted) recordSkipReasonOnPrs(next, judgedSkip.skip);
1529
1700
  if (judgedSkip && !judgedSkip.accepted) {
1530
1701
  return envelope("PostToolUse", explainRejection(judgedSkip), host);
@@ -1539,13 +1710,9 @@ function recordSkipReasonOnPrs(state, skip) {
1539
1710
  function skillStages() {
1540
1711
  const skillName = resolveSkillNameFromToolInput(input.tool_input);
1541
1712
  if (!skillName) return "{}";
1542
- const state = readState(sessionId);
1543
- const next = applySkillInvocation(
1544
- state,
1545
- skillName,
1546
- resolveSkillStagePaths(skillName, resolvePluginSkillsRoot())
1547
- );
1548
- if (next !== state) writeState(next);
1713
+ const stagePaths = resolveSkillStagePaths(skillName, resolvePluginSkillsRoot());
1714
+ const invoke = (state) => applySkillInvocation(state, skillName, stagePaths);
1715
+ const next = commitState(sessionId, invoke) ?? invoke(readState(sessionId));
1549
1716
  const unread = unreadMandatoryStages(next);
1550
1717
  if (unread.length === 0) return "{}";
1551
1718
  const ctx = `The ${skillName} skill declares required reading: ${unread.map(stageLabel).join(", ")}. Read those files now, before working through the skill's steps \u2014 they carry mandatory steps SKILL.md only links to, and treating them as optional elaboration is how those steps get silently dropped. A Stop gate holds the turn open until they are opened.`;
@@ -1553,10 +1720,11 @@ function skillStages() {
1553
1720
  }
1554
1721
  function recordStageRead() {
1555
1722
  const filePath = input.tool_input?.file_path;
1556
- if (!filePath) return "{}";
1723
+ const readPaths = filePath ? [filePath].filter(isSkillTreeMarkdown) : isShellToolCall(input) ? detectShellStageReads(input.tool_input?.command ?? "", input.cwd) : [];
1724
+ if (readPaths.length === 0) return "{}";
1557
1725
  if (callFailed(input)) return "{}";
1558
1726
  const state = readState(sessionId);
1559
- const next = applyStageRead(state, filePath);
1727
+ const next = readPaths.reduce(applyStageRead, state);
1560
1728
  if (next !== state) writeState(next);
1561
1729
  return "{}";
1562
1730
  }
@@ -1616,7 +1784,7 @@ function e2eGate() {
1616
1784
  if (decision.action === "none" /* None */) return "{}";
1617
1785
  state.e2eBlockCount = decision.blockCount;
1618
1786
  writeState(state);
1619
- const reason = decision.blockCount === 1 ? `Do not end the turn yet. This session went unit-green or opened a PR, but no E2E acceptance run has happened. Per the autoE2ETest preference (default: always), run change-driven E2E now via /muggle:muggle-test, then finish. A skip states a fact about the environment, never a judgment about the change: run \`echo "MUGGLE_E2E_SKIP: <CODE>: <detail>"\` citing one of ${E2E_SKIP_CODES.join(", ")}. Muggle verifies the code itself, so one that does not hold leaves this gate blocked.` : `E2E acceptance run still owed (reminder ${decision.blockCount}/${MAX_E2E_BLOCKS}): run /muggle:muggle-test, or cite a verifiable code via \`echo "MUGGLE_E2E_SKIP: <CODE>: <detail>"\`.`;
1787
+ const reason = decision.blockCount === 1 ? `Do not end the turn yet. This session went unit-green or opened a PR, but no E2E acceptance run has happened. Per the autoE2ETest preference (default: always), run change-driven E2E now via ${muggleSkill("/muggle:muggle-test")}, then finish. A skip states a fact about the environment, never a judgment about the change: run \`echo "MUGGLE_E2E_SKIP: <CODE>: <detail>"\` citing one of ${E2E_SKIP_CODES.join(", ")}. Muggle verifies the code itself, so one that does not hold leaves this gate blocked.` : `E2E acceptance run still owed (reminder ${decision.blockCount}/${MAX_E2E_BLOCKS}): run ${muggleSkill("/muggle:muggle-test")}, or cite a verifiable code via \`echo "MUGGLE_E2E_SKIP: <CODE>: <detail>"\`.`;
1620
1788
  return blockStop(reason, host);
1621
1789
  }
1622
1790
  function watchGate() {
@@ -1628,7 +1796,7 @@ function watchGate() {
1628
1796
  state.watchBlockCount = decision.blockCount;
1629
1797
  writeState(state);
1630
1798
  const prList = decision.untracked.join(", ");
1631
- const reason = decision.blockCount === 1 ? `Do not end the turn yet. A PR was opened this session but no muggle-do session slot tracks it: ${prList}. Seed the slot and hand off per muggle-do Stage 8 \u2014 /muggle:muggle-pr-followup ${decision.untracked[0]} does both. Seeding is what matters: once a slot exists, reconcile arms it at the next session start and finalizes it when the PR goes terminal, so an unarmed slot is fine but no slot means nothing ever picks this PR up. If it genuinely should not be tracked (autoWatchPR=never, handed off elsewhere), tell the user why and run \`echo "MUGGLE_WATCH_SKIP: <reason>"\` \u2014 that records the skip and keeps this gate quiet for the rest of the session.` : `PR hand-off still owed for ${prList} (reminder ${decision.blockCount}/${MAX_WATCH_BLOCKS}): seed a slot via /muggle:muggle-pr-followup, or record a legitimate skip via \`echo "MUGGLE_WATCH_SKIP: <reason>"\`.`;
1799
+ const reason = decision.blockCount === 1 ? `Do not end the turn yet. A PR was opened this session but no muggle-do session slot tracks it: ${prList}. Seed the slot and hand off per muggle-do Stage 8 \u2014 ${muggleSkill("/muggle:muggle-pr-followup")} ${decision.untracked[0]} does both. Seeding is what matters: once a slot exists, reconcile arms it at the next session start and finalizes it when the PR goes terminal, so an unarmed slot is fine but no slot means nothing ever picks this PR up. If it genuinely should not be tracked (autoWatchPR=never, handed off elsewhere), tell the user why and run \`echo "MUGGLE_WATCH_SKIP: <reason>"\` \u2014 that records the skip and keeps this gate quiet for the rest of the session.` : `PR hand-off still owed for ${prList} (reminder ${decision.blockCount}/${MAX_WATCH_BLOCKS}): seed a slot via ${muggleSkill("/muggle:muggle-pr-followup")}, or record a legitimate skip via \`echo "MUGGLE_WATCH_SKIP: <reason>"\`.`;
1632
1800
  return blockStop(reason, host);
1633
1801
  }
1634
1802
  function buildFollowthroughGate() {
@@ -1638,7 +1806,7 @@ function buildFollowthroughGate() {
1638
1806
  if (decision.action === "none" /* None */) return "{}";
1639
1807
  state.buildBlockCount = decision.blockCount;
1640
1808
  writeState(state);
1641
- const reason = decision.blockCount === 1 ? `Do not end the turn yet. This session took a build/implement/fix request but no PR was opened. A root cause written into the transcript ships nothing \u2014 once the session ends it is gone, and the watcher gate never fires because it only looks at PRs that exist. Carry the work to a PR via /muggle-do, which runs requirements \u2192 build \u2192 impact \u2192 unit tests \u2192 E2E \u2192 PR \u2192 watcher. If no PR is owed here (the user changed their mind, the fix landed in another repo, the answer was advice rather than a change), tell the user why and run \`echo "MUGGLE_BUILD_SKIP: <reason>"\` \u2014 that records the skip and keeps this gate quiet for the rest of the session.` : `Build request still unanswered \u2014 no PR opened (reminder ${decision.blockCount}/${MAX_BUILD_BLOCKS}): carry it to a PR via /muggle-do, or record a legitimate skip via \`echo "MUGGLE_BUILD_SKIP: <reason>"\`.`;
1809
+ const reason = decision.blockCount === 1 ? `Do not end the turn yet. This session took a build/implement/fix request but no PR was opened. A root cause written into the transcript ships nothing \u2014 once the session ends it is gone, and the watcher gate never fires because it only looks at PRs that exist. Carry the work to a PR via ${muggleSkill("/muggle-do")}, which runs requirements \u2192 build \u2192 impact \u2192 unit tests \u2192 E2E \u2192 PR \u2192 watcher. If no PR is owed here (the user changed their mind, the fix landed in another repo, the answer was advice rather than a change), tell the user why and run \`echo "MUGGLE_BUILD_SKIP: <reason>"\` \u2014 that records the skip and keeps this gate quiet for the rest of the session.` : `Build request still unanswered \u2014 no PR opened (reminder ${decision.blockCount}/${MAX_BUILD_BLOCKS}): carry it to a PR via ${muggleSkill("/muggle-do")}, or record a legitimate skip via \`echo "MUGGLE_BUILD_SKIP: <reason>"\`.`;
1642
1810
  return blockStop(reason, host);
1643
1811
  }
1644
1812
  function walkthroughGate() {
@@ -1657,7 +1825,7 @@ function walkthroughGate() {
1657
1825
  state.walkthroughBlockCount = decision.blockCount;
1658
1826
  writeState(state);
1659
1827
  const prList = decision.owed.join(", ");
1660
- const reason = decision.blockCount === 1 ? `Do not end the turn yet. An E2E acceptance run happened this session but no visual walkthrough has reached ${prList}. Per the postPRVisualWalkthrough preference (default: always), post it now via /muggle:muggle-pr-visual-walkthrough \u2014 include the failed runs, which are the ones reviewers most need to see. If this result genuinely should not be posted (postPRVisualWalkthrough=never, someone else's PR, nothing renderable), tell the user why and run \`echo "MUGGLE_WALKTHROUGH_SKIP: <reason>"\` \u2014 that records the skip and keeps this gate quiet for the rest of the session.` : `Walkthrough still owed for ${prList} (reminder ${decision.blockCount}/${MAX_WALKTHROUGH_BLOCKS}): post via /muggle:muggle-pr-visual-walkthrough, or record a legitimate skip via \`echo "MUGGLE_WALKTHROUGH_SKIP: <reason>"\`.`;
1828
+ const reason = decision.blockCount === 1 ? `Do not end the turn yet. An E2E acceptance run happened this session but no visual walkthrough has reached ${prList}. Per the postPRVisualWalkthrough preference (default: always), post it now via ${muggleSkill("/muggle:muggle-pr-visual-walkthrough")} \u2014 include the failed runs, which are the ones reviewers most need to see. If this result genuinely should not be posted (postPRVisualWalkthrough=never, someone else's PR, nothing renderable), tell the user why and run \`echo "MUGGLE_WALKTHROUGH_SKIP: <reason>"\` \u2014 that records the skip and keeps this gate quiet for the rest of the session.` : `Walkthrough still owed for ${prList} (reminder ${decision.blockCount}/${MAX_WALKTHROUGH_BLOCKS}): post via ${muggleSkill("/muggle:muggle-pr-visual-walkthrough")}, or record a legitimate skip via \`echo "MUGGLE_WALKTHROUGH_SKIP: <reason>"\`.`;
1661
1829
  return blockStop(reason, host);
1662
1830
  }
1663
1831
  function slotForSession(state) {
@@ -1738,23 +1906,25 @@ function buildRouter() {
1738
1906
  if (state.buildIntentRouted) return "{}";
1739
1907
  state.buildIntentRouted = true;
1740
1908
  writeState(state);
1741
- const ctx = `This looks like a build/implement/fix request. Per the autoRouteBuildToMuggleDo preference, route it through /muggle-do \u2014 which runs requirements \u2192 build (delegated to superpowers' design\u2192plan\u2192review) \u2192 impact \u2192 unit tests \u2192 E2E \u2192 PR \u2192 watcher. If autoRouteBuildToMuggleDo=always, enter that flow; if =ask, offer it; if =never, proceed normally.`;
1909
+ const ctx = `This looks like a build/implement/fix request. Per the autoRouteBuildToMuggleDo preference, route it through ${muggleSkill("/muggle-do")} \u2014 which runs requirements \u2192 build (delegated to superpowers' design\u2192plan\u2192review) \u2192 impact \u2192 unit tests \u2192 E2E \u2192 PR \u2192 watcher. If autoRouteBuildToMuggleDo=always, enter that flow; if =ask, offer it; if =never, proceed normally.`;
1742
1910
  return envelope("UserPromptSubmit", ctx, host);
1743
1911
  }
1744
- function capabilityClaimGate() {
1745
- const state = readState(sessionId);
1746
- if (state.capabilityClaimNudged) return "{}";
1912
+ function closingAssistantText() {
1913
+ if (typeof input.last_assistant_message === "string") return input.last_assistant_message;
1747
1914
  const transcriptPath = input.transcript_path;
1748
- if (!transcriptPath) return "{}";
1749
- let transcriptTail;
1915
+ if (!transcriptPath) return "";
1750
1916
  try {
1751
- transcriptTail = readFileSync(transcriptPath, "utf-8").slice(
1752
- -CAPABILITY_CLAIM_TRANSCRIPT_TAIL_BYTES
1917
+ return lastAssistantText(
1918
+ readFileSync(transcriptPath, "utf-8").slice(-CAPABILITY_CLAIM_TRANSCRIPT_TAIL_BYTES)
1753
1919
  );
1754
1920
  } catch {
1755
- return "{}";
1921
+ return "";
1756
1922
  }
1757
- if (!detectFalseCapabilityClaim(lastAssistantText(transcriptTail))) return "{}";
1923
+ }
1924
+ function capabilityClaimGate() {
1925
+ const state = readState(sessionId);
1926
+ if (state.capabilityClaimNudged) return "{}";
1927
+ if (!detectFalseCapabilityClaim(closingAssistantText())) return "{}";
1758
1928
  state.capabilityClaimNudged = true;
1759
1929
  writeState(state);
1760
1930
  const reason = `Do not end the turn yet. This turn tells the user that a login- or code-gated flow cannot be tested, reached, or verified \u2014 the one class of blocker Muggle clears. Every managed login profile owns a live inbox, so magic-link and sign-in-link logins, emailed OTPs, email-based 2FA, verification mail, and password resets run end to end with no mail stub and no test-only backdoor. An SMS code is read from the profile's provisioned number, an authenticator code is derived offline from its stored TOTP secret, and stored credentials and CAPTCHA solving are covered too. Re-read plugin/skills/_shared/identity-and-inbox.md, then correct the claim or run the flow. Genuine limits stay sayable: a voice call, an OAuth-only provider, or an account with no phone number provisioned (the runner cannot mint one) \u2014 name the one that applies and move on.`;
@@ -36,6 +36,12 @@ Invoking the skill names those files as required reading, and a Stop gate holds
36
36
 
37
37
  The bar is "must be **read** before the skill runs", not "must be executed". A failure protocol qualifies: by the time a run fails, a skill that never read it is already improvising. What does not qualify is a file only one branch consults for its content — the gate cannot tell that the branch was not taken, so it would block work that legitimately never needed it. Aliases declare nothing; they invoke the canonical skill, which carries the declaration.
38
38
 
39
+ ## Host compatibility
40
+
41
+ Skills are written against Claude Code's tools and ship unchanged to Codex. [`_shared/host-tool-equivalents.md`](_shared/host-tool-equivalents.md) maps each Claude Code name a skill uses — `AskUserQuestion`, the `Skill` tool, `${CLAUDE_PLUGIN_ROOT}`, the PR watcher's monitor — to what plays its part in Codex. Every top-level `SKILL.md` links it right after its telemetry line, and the Codex SessionStart hook names it too.
42
+
43
+ When a skill comes to depend on another Claude Code-only tool, add its row there; never branch a skill's steps per host. An alias also carries `agents/openai.yaml` with `allow_implicit_invocation: false`, which is how Codex reads `disable-model-invocation`. `src/test/skills/codex-skill-compat.test.ts` holds all three.
44
+
39
45
  ## Model tiers
40
46
 
41
47
  Each skill sets a `model:` in its `SKILL.md` frontmatter sized to its cognitive load. `model:` is a native Claude Code field — the override applies while the skill is active and reverts to the session model when it exits. Cheaper, faster models run the mechanical skills; the default (Opus) is reserved for the ones that actually reason. Cost and latency scale with the model, and these skills run often (the watcher fires every minute), so the tier is a real lever, not cosmetics.
@@ -0,0 +1,27 @@
1
+ # Host Tool Equivalents
2
+
3
+ These skills are written against Claude Code's tools. In another agent host — Codex in particular — read each Claude Code name below as the equivalent in the host you are running in. Everything the skills do through the muggle MCP tools, the `muggle` CLI, `gh`/`glab`, and the shell works the same in every host; only the names in this table change.
4
+
5
+ | The skill says | In Claude Code | In Codex |
6
+ | :------------- | :------------- | :------- |
7
+ | `/muggle:<skill>` or a short alias (`/mtest`, `/muggle-do`) | A slash command | The skill `$muggle:<skill>` — for example `$muggle:muggle-test`. The user can also pick it from `/skills`. |
8
+ | Invoke a skill "via the `Skill` tool" | The `Skill` tool | Open that skill's `SKILL.md` — every skill is listed with its path — and follow it. |
9
+ | `AskUserQuestion` | Clickable options | `request_user_input` where Codex offers it. Otherwise end your turn on the question, with the options numbered, and treat the user's reply as their pick. Never pick for them. |
10
+ | `${CLAUDE_PLUGIN_ROOT}` in a command | Set wherever a command runs | Set for hooks only, never in your shell. Set it at the start of the same command that uses it: `CLAUDE_PLUGIN_ROOT='<plugin root>'; bash "${CLAUDE_PLUGIN_ROOT}/scripts/sign-body.sh" …`. The plugin root is the directory that holds this `skills/` folder. Prefixing the variable to the command name alone (`CLAUDE_PLUGIN_ROOT=… bash "${CLAUDE_PLUGIN_ROOT}/…"`) does not work: the shell expands the path before the assignment applies. |
11
+ | `$CLAUDE_CODE_SESSION_ID` | This session's id | `$CODEX_SESSION_ID` — the same id the hooks receive as `session_id`. |
12
+ | Dispatch a plugin agent (`agents/*.md`, subagent type `muggle:<agent>`) | The Agent tool | `spawn_agent` with that agent file's instructions as the task, when multi-agent is enabled; otherwise run the agent file inline, as each skill already allows for a host with no subagents. |
13
+ | `TodoWrite` | The session task list | `update_plan` |
14
+ | `Monitor`, `/loop`, `CronCreate`/`CronDelete` (the PR watcher's background watch) | Wake the session when the watch reports an event | No equivalent: nothing in Codex wakes a session from a background process. Run the drain tick, seed the slot without a loop (`pr-watch-arm.sh … --no-exec`), and tell the user that following the PR up means invoking `$muggle:muggle-pr-followup` again — or scheduling it with `codex exec`. Never leave a loop polling that no session will hear. |
15
+ | `model:` in a skill's frontmatter | Runs the skill on that model | Ignored — the session's model runs every skill. |
16
+
17
+ ## Codex's sandbox
18
+
19
+ Codex runs your shell commands in a sandbox that, by default, blocks the network and writes outside the workspace. The muggle MCP tools are not affected — they run outside it — but `gh`, `glab`, and writes under `~/.muggle-ai/` (session state, PR-watch slots) are. When one of those commands is refused, ask for it to run with escalated permissions rather than working around it. A user who wants fewer prompts can allow the network and that directory in `~/.codex/config.toml`:
20
+
21
+ ```toml
22
+ [sandbox_workspace_write]
23
+ network_access = true
24
+ writable_roots = ["/absolute/path/to/home/.muggle-ai"]
25
+ ```
26
+
27
+ Codex also strips variables whose names contain `KEY`, `SECRET`, or `TOKEN` from your shell, so a `gh` that authenticates through `GH_TOKEN` alone sees no token there; `gh auth login` stores one `gh` can read without it.
@@ -6,4 +6,4 @@ disable-model-invocation: true
6
6
 
7
7
  # m — alias for muggle
8
8
 
9
- Invoke the `muggle` skill via the Skill tool. Forward any user-provided arguments unchanged.
9
+ Invoke the `muggle` skill via the Skill tool. Forward any user-provided arguments unchanged. In a host with no Skill tool (Codex), open `../muggle/SKILL.md` and follow it with those arguments.
@@ -0,0 +1,7 @@
1
+ # Codex reads this beside SKILL.md. An alias is for the user to type, never for
2
+ # the model to pick on its own: Codex's equivalent of disable-model-invocation.
3
+ interface:
4
+ display_name: "m"
5
+ short_description: "Short alias for the muggle skill"
6
+ policy:
7
+ allow_implicit_invocation: false
@@ -6,4 +6,4 @@ disable-model-invocation: true
6
6
 
7
7
  # mbt — alias for muggle-browser-task
8
8
 
9
- Invoke the `muggle-browser-task` skill via the Skill tool. Forward any user-provided arguments unchanged.
9
+ Invoke the `muggle-browser-task` skill via the Skill tool. Forward any user-provided arguments unchanged. In a host with no Skill tool (Codex), open `../muggle-browser-task/SKILL.md` and follow it with those arguments.
@@ -0,0 +1,7 @@
1
+ # Codex reads this beside SKILL.md. An alias is for the user to type, never for
2
+ # the model to pick on its own: Codex's equivalent of disable-model-invocation.
3
+ interface:
4
+ display_name: "mbt"
5
+ short_description: "Short alias for the muggle-browser-task skill"
6
+ policy:
7
+ allow_implicit_invocation: false
@@ -6,4 +6,4 @@ disable-model-invocation: true
6
6
 
7
7
  # mdo — alias for muggle-do
8
8
 
9
- Invoke the `muggle-do` skill via the Skill tool. Forward any user-provided arguments unchanged.
9
+ Invoke the `muggle-do` skill via the Skill tool. Forward any user-provided arguments unchanged. In a host with no Skill tool (Codex), open `../muggle-do/SKILL.md` and follow it with those arguments.
@@ -0,0 +1,7 @@
1
+ # Codex reads this beside SKILL.md. An alias is for the user to type, never for
2
+ # the model to pick on its own: Codex's equivalent of disable-model-invocation.
3
+ interface:
4
+ display_name: "mdo"
5
+ short_description: "Short alias for the muggle-do skill"
6
+ policy:
7
+ allow_implicit_invocation: false
@@ -6,4 +6,4 @@ disable-model-invocation: true
6
6
 
7
7
  # mfeedback — alias for muggle-feedback
8
8
 
9
- Invoke the `muggle-feedback` skill via the Skill tool. Forward any user-provided arguments unchanged.
9
+ Invoke the `muggle-feedback` skill via the Skill tool. Forward any user-provided arguments unchanged. In a host with no Skill tool (Codex), open `../muggle-feedback/SKILL.md` and follow it with those arguments.
@@ -0,0 +1,7 @@
1
+ # Codex reads this beside SKILL.md. An alias is for the user to type, never for
2
+ # the model to pick on its own: Codex's equivalent of disable-model-invocation.
3
+ interface:
4
+ display_name: "mfeedback"
5
+ short_description: "Short alias for the muggle-feedback skill"
6
+ policy:
7
+ allow_implicit_invocation: false
@@ -6,4 +6,4 @@ disable-model-invocation: true
6
6
 
7
7
  # mimport — alias for muggle-test-import
8
8
 
9
- Invoke the `muggle-test-import` skill via the Skill tool. Forward any user-provided arguments unchanged.
9
+ Invoke the `muggle-test-import` skill via the Skill tool. Forward any user-provided arguments unchanged. In a host with no Skill tool (Codex), open `../muggle-test-import/SKILL.md` and follow it with those arguments.
@@ -0,0 +1,7 @@
1
+ # Codex reads this beside SKILL.md. An alias is for the user to type, never for
2
+ # the model to pick on its own: Codex's equivalent of disable-model-invocation.
3
+ interface:
4
+ display_name: "mimport"
5
+ short_description: "Short alias for the muggle-test-import skill"
6
+ policy:
7
+ allow_implicit_invocation: false
@@ -6,4 +6,4 @@ disable-model-invocation: true
6
6
 
7
7
  # mpr — alias for muggle-pr-visual-walkthrough
8
8
 
9
- Invoke the `muggle-pr-visual-walkthrough` skill via the Skill tool. Forward any user-provided arguments unchanged.
9
+ Invoke the `muggle-pr-visual-walkthrough` skill via the Skill tool. Forward any user-provided arguments unchanged. In a host with no Skill tool (Codex), open `../muggle-pr-visual-walkthrough/SKILL.md` and follow it with those arguments.