@muggleai/works 5.22.0-staging.152 → 5.22.0-staging.154
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 +74 -17
- package/dist/{chunk-7GF5CYNK.js → chunk-E3T2RN6R.js} +8 -0
- package/dist/{chunk-KHHZKYJX.js → chunk-HXDEDSP5.js} +102 -3
- package/dist/cli.js +2 -2
- package/dist/index.js +2 -2
- package/dist/plugin/.claude-plugin/plugin.json +1 -1
- package/dist/plugin/.codex-mcp.json +55 -0
- package/dist/plugin/.codex-plugin/plugin.json +46 -0
- package/dist/plugin/.cursor-plugin/plugin.json +1 -1
- package/dist/plugin/README.md +15 -4
- package/dist/plugin/hooks/README.md +12 -0
- package/dist/plugin/hooks/codex-hooks.json +147 -0
- package/dist/plugin/hooks/hooks.json +1 -1
- package/dist/plugin/scripts/codex-hook-windows.mjs +81 -0
- package/dist/plugin/scripts/ensure-electron-app.sh +16 -1
- package/dist/plugin/scripts/guard-run.mjs +7 -2
- package/dist/plugin/scripts/guardrail-capability-claim.sh +10 -4
- package/dist/plugin/scripts/guardrail-classify-gate.sh +3 -2
- package/dist/plugin/scripts/guardrail-record-stage-read.sh +14 -9
- package/dist/plugin/scripts/guardrail-record-stage-signals.sh +1 -1
- package/dist/plugin/scripts/guardrail-record-tests.sh +1 -1
- package/dist/plugin/scripts/guardrails.mjs +222 -60
- package/dist/plugin/skills/CLAUDE.md +6 -0
- package/dist/plugin/skills/_shared/host-tool-equivalents.md +27 -0
- package/dist/plugin/skills/m/SKILL.md +1 -1
- package/dist/plugin/skills/m/agents/openai.yaml +7 -0
- package/dist/plugin/skills/mbt/SKILL.md +1 -1
- package/dist/plugin/skills/mbt/agents/openai.yaml +7 -0
- package/dist/plugin/skills/mdo/SKILL.md +1 -1
- package/dist/plugin/skills/mdo/agents/openai.yaml +7 -0
- package/dist/plugin/skills/mfeedback/SKILL.md +1 -1
- package/dist/plugin/skills/mfeedback/agents/openai.yaml +7 -0
- package/dist/plugin/skills/mimport/SKILL.md +1 -1
- package/dist/plugin/skills/mimport/agents/openai.yaml +7 -0
- package/dist/plugin/skills/mpr/SKILL.md +1 -1
- package/dist/plugin/skills/mpr/agents/openai.yaml +7 -0
- package/dist/plugin/skills/mprefs/SKILL.md +1 -1
- package/dist/plugin/skills/mprefs/agents/openai.yaml +7 -0
- package/dist/plugin/skills/mprfollowup/SKILL.md +1 -1
- package/dist/plugin/skills/mprfollowup/agents/openai.yaml +7 -0
- package/dist/plugin/skills/mregen/SKILL.md +1 -1
- package/dist/plugin/skills/mregen/agents/openai.yaml +7 -0
- package/dist/plugin/skills/mrepair/SKILL.md +1 -1
- package/dist/plugin/skills/mrepair/agents/openai.yaml +7 -0
- package/dist/plugin/skills/mstatus/SKILL.md +1 -1
- package/dist/plugin/skills/mstatus/agents/openai.yaml +7 -0
- package/dist/plugin/skills/mtest/SKILL.md +1 -1
- package/dist/plugin/skills/mtest/agents/openai.yaml +7 -0
- package/dist/plugin/skills/mtestlocal/SKILL.md +1 -1
- package/dist/plugin/skills/mtestlocal/agents/openai.yaml +7 -0
- package/dist/plugin/skills/mtestprep/SKILL.md +1 -1
- package/dist/plugin/skills/mtestprep/agents/openai.yaml +7 -0
- package/dist/plugin/skills/muggle/SKILL.md +2 -0
- package/dist/plugin/skills/muggle-browser-task/SKILL.md +2 -0
- package/dist/plugin/skills/muggle-do/SKILL.md +2 -0
- package/dist/plugin/skills/muggle-feedback/SKILL.md +2 -0
- package/dist/plugin/skills/muggle-pr-followup/SKILL.md +2 -0
- package/dist/plugin/skills/muggle-pr-visual-walkthrough/SKILL.md +43 -41
- package/dist/plugin/skills/muggle-preferences/SKILL.md +28 -26
- package/dist/plugin/skills/muggle-repair/SKILL.md +2 -0
- package/dist/plugin/skills/muggle-status/SKILL.md +2 -0
- package/dist/plugin/skills/muggle-test/SKILL.md +2 -0
- package/dist/plugin/skills/muggle-test-feature-local/SKILL.md +2 -0
- package/dist/plugin/skills/muggle-test-import/SKILL.md +2 -0
- package/dist/plugin/skills/muggle-test-prepare/SKILL.md +145 -143
- package/dist/plugin/skills/muggle-test-regenerate-missing/SKILL.md +2 -0
- package/dist/plugin/skills/muggle-upgrade/SKILL.md +2 -0
- package/dist/plugin/skills/mupgrade/SKILL.md +1 -1
- package/dist/plugin/skills/mupgrade/agents/openai.yaml +7 -0
- package/dist/release-manifest.json +3 -3
- package/dist/{src-VVWBQMWR.js → src-V245RV7L.js} +1 -1
- package/package.json +4 -2
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/.codex-mcp.json +55 -0
- package/plugin/.codex-plugin/plugin.json +46 -0
- package/plugin/.cursor-plugin/plugin.json +1 -1
- package/plugin/README.md +15 -4
- package/plugin/hooks/README.md +12 -0
- package/plugin/hooks/codex-hooks.json +147 -0
- package/plugin/hooks/hooks.json +1 -1
- package/plugin/scripts/codex-hook-windows.mjs +81 -0
- package/plugin/scripts/ensure-electron-app.sh +16 -1
- package/plugin/scripts/guard-run.mjs +7 -2
- package/plugin/scripts/guardrail-capability-claim.sh +10 -4
- package/plugin/scripts/guardrail-classify-gate.sh +3 -2
- package/plugin/scripts/guardrail-record-stage-read.sh +14 -9
- package/plugin/scripts/guardrail-record-stage-signals.sh +1 -1
- package/plugin/scripts/guardrail-record-tests.sh +1 -1
- package/plugin/scripts/guardrails.mjs +222 -60
- package/plugin/skills/CLAUDE.md +6 -0
- package/plugin/skills/_shared/host-tool-equivalents.md +27 -0
- package/plugin/skills/m/SKILL.md +1 -1
- package/plugin/skills/m/agents/openai.yaml +7 -0
- package/plugin/skills/mbt/SKILL.md +1 -1
- package/plugin/skills/mbt/agents/openai.yaml +7 -0
- package/plugin/skills/mdo/SKILL.md +1 -1
- package/plugin/skills/mdo/agents/openai.yaml +7 -0
- package/plugin/skills/mfeedback/SKILL.md +1 -1
- package/plugin/skills/mfeedback/agents/openai.yaml +7 -0
- package/plugin/skills/mimport/SKILL.md +1 -1
- package/plugin/skills/mimport/agents/openai.yaml +7 -0
- package/plugin/skills/mpr/SKILL.md +1 -1
- package/plugin/skills/mpr/agents/openai.yaml +7 -0
- package/plugin/skills/mprefs/SKILL.md +1 -1
- package/plugin/skills/mprefs/agents/openai.yaml +7 -0
- package/plugin/skills/mprfollowup/SKILL.md +1 -1
- package/plugin/skills/mprfollowup/agents/openai.yaml +7 -0
- package/plugin/skills/mregen/SKILL.md +1 -1
- package/plugin/skills/mregen/agents/openai.yaml +7 -0
- package/plugin/skills/mrepair/SKILL.md +1 -1
- package/plugin/skills/mrepair/agents/openai.yaml +7 -0
- package/plugin/skills/mstatus/SKILL.md +1 -1
- package/plugin/skills/mstatus/agents/openai.yaml +7 -0
- package/plugin/skills/mtest/SKILL.md +1 -1
- package/plugin/skills/mtest/agents/openai.yaml +7 -0
- package/plugin/skills/mtestlocal/SKILL.md +1 -1
- package/plugin/skills/mtestlocal/agents/openai.yaml +7 -0
- package/plugin/skills/mtestprep/SKILL.md +1 -1
- package/plugin/skills/mtestprep/agents/openai.yaml +7 -0
- package/plugin/skills/muggle/SKILL.md +2 -0
- package/plugin/skills/muggle-browser-task/SKILL.md +2 -0
- package/plugin/skills/muggle-do/SKILL.md +2 -0
- package/plugin/skills/muggle-feedback/SKILL.md +2 -0
- package/plugin/skills/muggle-pr-followup/SKILL.md +2 -0
- package/plugin/skills/muggle-pr-visual-walkthrough/SKILL.md +43 -41
- package/plugin/skills/muggle-preferences/SKILL.md +28 -26
- package/plugin/skills/muggle-repair/SKILL.md +2 -0
- package/plugin/skills/muggle-status/SKILL.md +2 -0
- package/plugin/skills/muggle-test/SKILL.md +2 -0
- package/plugin/skills/muggle-test-feature-local/SKILL.md +2 -0
- package/plugin/skills/muggle-test-import/SKILL.md +2 -0
- package/plugin/skills/muggle-test-prepare/SKILL.md +145 -143
- package/plugin/skills/muggle-test-regenerate-missing/SKILL.md +2 -0
- package/plugin/skills/muggle-upgrade/SKILL.md +2 -0
- package/plugin/skills/mupgrade/SKILL.md +1 -1
- 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
|
-
|
|
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 =
|
|
28
|
-
var MUGGLE_EVENT_EMIT_TOOL =
|
|
29
|
-
var MUGGLE_FEEDBACK_CREATE_TOOL =
|
|
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
|
|
157
|
+
function commitState(sessionId2, mutate, dirOverride) {
|
|
138
158
|
mkdirSync(baseDir(dirOverride), { recursive: true });
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
()
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
|
515
|
-
|
|
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
|
}
|
|
@@ -1444,15 +1575,36 @@ function mergeHookOutputs(gateOutputs, host2) {
|
|
|
1444
1575
|
return envelope(hookEventName ?? "", contexts.join(MERGED_GATE_OUTPUT_SEPARATOR), host2);
|
|
1445
1576
|
}
|
|
1446
1577
|
|
|
1578
|
+
// src/guardrails/hookInput.ts
|
|
1579
|
+
function normalizeHookInput(raw) {
|
|
1580
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return {};
|
|
1581
|
+
const payload = raw;
|
|
1582
|
+
if (typeof payload.tool_response === "string") {
|
|
1583
|
+
return { ...payload, tool_response: { output: payload.tool_response } };
|
|
1584
|
+
}
|
|
1585
|
+
return payload;
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
// src/guardrails/hookHost.ts
|
|
1589
|
+
function resolveHookHost(env = process.env) {
|
|
1590
|
+
if (env[HOOK_HOST_ENV_VAR] === "codex") return "codex";
|
|
1591
|
+
if (env.CURSOR_PLUGIN_ROOT) return "cursor";
|
|
1592
|
+
return "claude";
|
|
1593
|
+
}
|
|
1594
|
+
function skillInvocation(slashCommand, host2) {
|
|
1595
|
+
if (host2 !== "codex") return slashCommand;
|
|
1596
|
+
return `$muggle:${slashCommand.replace(/^\/(?:muggle:)?/, "")}`;
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1447
1599
|
// src/guardrails/cli.ts
|
|
1448
1600
|
function readStdin() {
|
|
1449
1601
|
try {
|
|
1450
|
-
return JSON.parse(readFileSync(0, "utf-8"));
|
|
1602
|
+
return normalizeHookInput(JSON.parse(readFileSync(0, "utf-8")));
|
|
1451
1603
|
} catch {
|
|
1452
1604
|
return {};
|
|
1453
1605
|
}
|
|
1454
1606
|
}
|
|
1455
|
-
var host =
|
|
1607
|
+
var host = resolveHookHost();
|
|
1456
1608
|
var sub = process.argv[2];
|
|
1457
1609
|
var input = readStdin();
|
|
1458
1610
|
var sessionId = input.session_id ?? "unknown";
|
|
@@ -1463,6 +1615,12 @@ function releaseGate(field) {
|
|
|
1463
1615
|
);
|
|
1464
1616
|
return "{}";
|
|
1465
1617
|
}
|
|
1618
|
+
function muggleSkill(slashCommand) {
|
|
1619
|
+
return skillInvocation(slashCommand, host);
|
|
1620
|
+
}
|
|
1621
|
+
function nextOptionsOfferMethod() {
|
|
1622
|
+
return host === "codex" ? "by asking them in your closing message (request_user_input where it is available)" : "via AskUserQuestion";
|
|
1623
|
+
}
|
|
1466
1624
|
function prOpened() {
|
|
1467
1625
|
const url = detectPrOpened(input);
|
|
1468
1626
|
if (!url) return "{}";
|
|
@@ -1471,7 +1629,7 @@ function prOpened() {
|
|
|
1471
1629
|
reserveWalkthroughComment(url);
|
|
1472
1630
|
const ctx = `A pull request was just opened: ${url}
|
|
1473
1631
|
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.`;
|
|
1632
|
+
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
1633
|
return envelope("PostToolUse", ctx, host);
|
|
1476
1634
|
}
|
|
1477
1635
|
function prTerminal() {
|
|
@@ -1488,43 +1646,48 @@ function prTerminal() {
|
|
|
1488
1646
|
const next = applyPrTerminalDetected(state, terminalEvent.prNumber);
|
|
1489
1647
|
if (next === state) return "{}";
|
|
1490
1648
|
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 (
|
|
1649
|
+
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
1650
|
return envelope("PostToolUse", ctx, host);
|
|
1493
1651
|
}
|
|
1494
1652
|
function offerRan() {
|
|
1495
|
-
if (input.tool_name
|
|
1653
|
+
if (!NEXT_OPTIONS_OFFER_TOOL_NAMES.includes(input.tool_name ?? "")) return "{}";
|
|
1496
1654
|
const state = readState(sessionId);
|
|
1497
1655
|
const next = applyNextOptionsOffered(state);
|
|
1498
1656
|
if (next !== state) writeState(next);
|
|
1499
1657
|
return "{}";
|
|
1500
1658
|
}
|
|
1501
1659
|
function terminalGate() {
|
|
1502
|
-
const
|
|
1660
|
+
const pendingState = readState(sessionId);
|
|
1661
|
+
const state = host === "codex" && closingMessageAsksUser(input.last_assistant_message) ? applyNextOptionsOffered(pendingState) : pendingState;
|
|
1662
|
+
if (state !== pendingState) writeState(state);
|
|
1503
1663
|
const decision = prTerminalGateDecision(state);
|
|
1504
1664
|
if (decision.action === "release" /* Release */) return releaseGate("terminalReleased");
|
|
1505
1665
|
if (decision.action !== "block" /* Block */) return "{}";
|
|
1506
1666
|
state.terminalBlockCount = decision.blockCount;
|
|
1507
1667
|
writeState(state);
|
|
1508
1668
|
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
|
|
1669
|
+
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
1670
|
return blockStop(reason, host);
|
|
1511
1671
|
}
|
|
1512
1672
|
function recordTests() {
|
|
1513
1673
|
const cmd = input.tool_input?.command ?? "";
|
|
1514
|
-
const
|
|
1515
|
-
const
|
|
1516
|
-
const recorded = applyRecordedRun(state, {
|
|
1674
|
+
const judgedSkip = judgeE2eSkip(input, readState(sessionId));
|
|
1675
|
+
const run = {
|
|
1517
1676
|
unitTestPassed: isTestCommand(cmd) && testsPassed(input),
|
|
1518
1677
|
e2eRan: isE2ERun(input),
|
|
1519
1678
|
e2eSkipped: judgedSkip?.accepted === true
|
|
1520
|
-
}
|
|
1521
|
-
const
|
|
1522
|
-
const withBuildSkip = applyBuildSkip(withWatchSkip, isBuildSkipMarker(cmd));
|
|
1523
|
-
const withWalkthroughPost = applyWalkthroughPosted(withBuildSkip, detectWalkthroughPost(input));
|
|
1524
|
-
const withWalkthroughSkip = applyWalkthroughSkip(withWalkthroughPost, isWalkthroughSkipMarker(cmd));
|
|
1679
|
+
};
|
|
1680
|
+
const walkthroughPosted = detectWalkthroughPost(input);
|
|
1525
1681
|
const failedRunId = detectFailedRunId(input);
|
|
1526
|
-
const
|
|
1527
|
-
|
|
1682
|
+
const record = (state) => {
|
|
1683
|
+
const recorded = applyRecordedRun(state, run);
|
|
1684
|
+
const withWatchSkip = applyWatchSkip(recorded, isWatchSkipMarker(cmd));
|
|
1685
|
+
const withBuildSkip = applyBuildSkip(withWatchSkip, isBuildSkipMarker(cmd));
|
|
1686
|
+
const withWalkthroughPost = applyWalkthroughPosted(withBuildSkip, walkthroughPosted);
|
|
1687
|
+
const withWalkthroughSkip = applyWalkthroughSkip(withWalkthroughPost, isWalkthroughSkipMarker(cmd));
|
|
1688
|
+
return failedRunId ? applyFailedRun(withWalkthroughSkip, failedRunId) : withWalkthroughSkip;
|
|
1689
|
+
};
|
|
1690
|
+
const next = commitState(sessionId, record) ?? record(readState(sessionId));
|
|
1528
1691
|
if (judgedSkip?.accepted) recordSkipReasonOnPrs(next, judgedSkip.skip);
|
|
1529
1692
|
if (judgedSkip && !judgedSkip.accepted) {
|
|
1530
1693
|
return envelope("PostToolUse", explainRejection(judgedSkip), host);
|
|
@@ -1539,13 +1702,9 @@ function recordSkipReasonOnPrs(state, skip) {
|
|
|
1539
1702
|
function skillStages() {
|
|
1540
1703
|
const skillName = resolveSkillNameFromToolInput(input.tool_input);
|
|
1541
1704
|
if (!skillName) return "{}";
|
|
1542
|
-
const
|
|
1543
|
-
const
|
|
1544
|
-
|
|
1545
|
-
skillName,
|
|
1546
|
-
resolveSkillStagePaths(skillName, resolvePluginSkillsRoot())
|
|
1547
|
-
);
|
|
1548
|
-
if (next !== state) writeState(next);
|
|
1705
|
+
const stagePaths = resolveSkillStagePaths(skillName, resolvePluginSkillsRoot());
|
|
1706
|
+
const invoke = (state) => applySkillInvocation(state, skillName, stagePaths);
|
|
1707
|
+
const next = commitState(sessionId, invoke) ?? invoke(readState(sessionId));
|
|
1549
1708
|
const unread = unreadMandatoryStages(next);
|
|
1550
1709
|
if (unread.length === 0) return "{}";
|
|
1551
1710
|
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 +1712,11 @@ function skillStages() {
|
|
|
1553
1712
|
}
|
|
1554
1713
|
function recordStageRead() {
|
|
1555
1714
|
const filePath = input.tool_input?.file_path;
|
|
1556
|
-
|
|
1715
|
+
const readPaths = filePath ? [filePath].filter(isSkillTreeMarkdown) : isShellToolCall(input) ? detectShellStageReads(input.tool_input?.command ?? "", input.cwd) : [];
|
|
1716
|
+
if (readPaths.length === 0) return "{}";
|
|
1557
1717
|
if (callFailed(input)) return "{}";
|
|
1558
1718
|
const state = readState(sessionId);
|
|
1559
|
-
const next = applyStageRead
|
|
1719
|
+
const next = readPaths.reduce(applyStageRead, state);
|
|
1560
1720
|
if (next !== state) writeState(next);
|
|
1561
1721
|
return "{}";
|
|
1562
1722
|
}
|
|
@@ -1616,7 +1776,7 @@ function e2eGate() {
|
|
|
1616
1776
|
if (decision.action === "none" /* None */) return "{}";
|
|
1617
1777
|
state.e2eBlockCount = decision.blockCount;
|
|
1618
1778
|
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>"\`.`;
|
|
1779
|
+
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
1780
|
return blockStop(reason, host);
|
|
1621
1781
|
}
|
|
1622
1782
|
function watchGate() {
|
|
@@ -1628,7 +1788,7 @@ function watchGate() {
|
|
|
1628
1788
|
state.watchBlockCount = decision.blockCount;
|
|
1629
1789
|
writeState(state);
|
|
1630
1790
|
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>"\`.`;
|
|
1791
|
+
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
1792
|
return blockStop(reason, host);
|
|
1633
1793
|
}
|
|
1634
1794
|
function buildFollowthroughGate() {
|
|
@@ -1638,7 +1798,7 @@ function buildFollowthroughGate() {
|
|
|
1638
1798
|
if (decision.action === "none" /* None */) return "{}";
|
|
1639
1799
|
state.buildBlockCount = decision.blockCount;
|
|
1640
1800
|
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>"\`.`;
|
|
1801
|
+
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
1802
|
return blockStop(reason, host);
|
|
1643
1803
|
}
|
|
1644
1804
|
function walkthroughGate() {
|
|
@@ -1657,7 +1817,7 @@ function walkthroughGate() {
|
|
|
1657
1817
|
state.walkthroughBlockCount = decision.blockCount;
|
|
1658
1818
|
writeState(state);
|
|
1659
1819
|
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>"\`.`;
|
|
1820
|
+
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
1821
|
return blockStop(reason, host);
|
|
1662
1822
|
}
|
|
1663
1823
|
function slotForSession(state) {
|
|
@@ -1738,23 +1898,25 @@ function buildRouter() {
|
|
|
1738
1898
|
if (state.buildIntentRouted) return "{}";
|
|
1739
1899
|
state.buildIntentRouted = true;
|
|
1740
1900
|
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.`;
|
|
1901
|
+
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
1902
|
return envelope("UserPromptSubmit", ctx, host);
|
|
1743
1903
|
}
|
|
1744
|
-
function
|
|
1745
|
-
|
|
1746
|
-
if (state.capabilityClaimNudged) return "{}";
|
|
1904
|
+
function closingAssistantText() {
|
|
1905
|
+
if (typeof input.last_assistant_message === "string") return input.last_assistant_message;
|
|
1747
1906
|
const transcriptPath = input.transcript_path;
|
|
1748
|
-
if (!transcriptPath) return "
|
|
1749
|
-
let transcriptTail;
|
|
1907
|
+
if (!transcriptPath) return "";
|
|
1750
1908
|
try {
|
|
1751
|
-
|
|
1752
|
-
-CAPABILITY_CLAIM_TRANSCRIPT_TAIL_BYTES
|
|
1909
|
+
return lastAssistantText(
|
|
1910
|
+
readFileSync(transcriptPath, "utf-8").slice(-CAPABILITY_CLAIM_TRANSCRIPT_TAIL_BYTES)
|
|
1753
1911
|
);
|
|
1754
1912
|
} catch {
|
|
1755
|
-
return "
|
|
1913
|
+
return "";
|
|
1756
1914
|
}
|
|
1757
|
-
|
|
1915
|
+
}
|
|
1916
|
+
function capabilityClaimGate() {
|
|
1917
|
+
const state = readState(sessionId);
|
|
1918
|
+
if (state.capabilityClaimNudged) return "{}";
|
|
1919
|
+
if (!detectFalseCapabilityClaim(closingAssistantText())) return "{}";
|
|
1758
1920
|
state.capabilityClaimNudged = true;
|
|
1759
1921
|
writeState(state);
|
|
1760
1922
|
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.
|
|
@@ -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: "mpr"
|
|
5
|
+
short_description: "Short alias for the muggle-pr-visual-walkthrough skill"
|
|
6
|
+
policy:
|
|
7
|
+
allow_implicit_invocation: false
|
|
@@ -6,4 +6,4 @@ disable-model-invocation: true
|
|
|
6
6
|
|
|
7
7
|
# mprefs — alias for muggle-preferences
|
|
8
8
|
|
|
9
|
-
Invoke the `muggle-preferences` skill via the Skill tool. Forward any user-provided arguments unchanged.
|
|
9
|
+
Invoke the `muggle-preferences` skill via the Skill tool. Forward any user-provided arguments unchanged. In a host with no Skill tool (Codex), open `../muggle-preferences/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: "mprefs"
|
|
5
|
+
short_description: "Short alias for the muggle-preferences skill"
|
|
6
|
+
policy:
|
|
7
|
+
allow_implicit_invocation: false
|
|
@@ -6,4 +6,4 @@ disable-model-invocation: true
|
|
|
6
6
|
|
|
7
7
|
# mprfollowup — alias for muggle-pr-followup
|
|
8
8
|
|
|
9
|
-
Invoke the `muggle-pr-followup` skill via the Skill tool. Forward any user-provided arguments unchanged.
|
|
9
|
+
Invoke the `muggle-pr-followup` skill via the Skill tool. Forward any user-provided arguments unchanged. In a host with no Skill tool (Codex), open `../muggle-pr-followup/SKILL.md` and follow it with those arguments.
|