@mcpbox/mcpbox-claude 0.1.27 → 0.1.29
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/.claude-plugin/plugin.json +2 -2
- package/.codex-plugin/plugin.json +4 -4
- package/README.md +280 -20
- package/bin/mcpbox-claude.mjs +61 -11
- package/commands/close.md +2 -0
- package/commands/mine.md +4 -4
- package/commands/mode.md +4 -12
- package/commands/next.md +4 -3
- package/commands/pipeline-run.md +4 -4
- package/commands/plan.md +4 -4
- package/commands/sync.md +1 -1
- package/commands/tasks.md +4 -4
- package/hooks/acceptance-guard.mjs +5 -62
- package/hooks/bootstrap.mjs +167 -0
- package/hooks/edit-gate.mjs +7 -0
- package/hooks/hooks.json +37 -1
- package/hooks/impl/acceptance-guard.mjs +63 -0
- package/hooks/impl/edit-gate.mjs +32 -0
- package/hooks/impl/prepare-commit-msg.mjs +8 -0
- package/hooks/impl/session-gate.mjs +81 -0
- package/hooks/impl/session-start.mjs +89 -0
- package/hooks/impl/stop.mjs +64 -0
- package/hooks/impl/track-claims.mjs +35 -0
- package/hooks/impl/user-prompt-submit.mjs +234 -0
- package/hooks/prepare-commit-msg.mjs +7 -0
- package/hooks/session-gate.mjs +7 -0
- package/hooks/session-start.mjs +5 -204
- package/hooks/stop.mjs +5 -104
- package/hooks/track-claims.mjs +7 -0
- package/hooks/user-prompt-submit.mjs +5 -259
- package/lib/cloud-knowledge.mjs +19 -3
- package/lib/codex.mjs +2 -2
- package/lib/cursor.mjs +1 -1
- package/lib/edit-gate.mjs +120 -0
- package/lib/git-trailer.mjs +104 -0
- package/lib/harness-hooks.mjs +186 -0
- package/lib/hook-doctor.mjs +517 -0
- package/lib/hook-output.mjs +16 -0
- package/lib/kimi.mjs +16 -4
- package/lib/knowledge-skills.mjs +259 -0
- package/lib/mode.mjs +2 -12
- package/lib/policy.mjs +54 -127
- package/lib/session-gate.mjs +385 -0
- package/lib/version.mjs +1 -1
- package/package.json +2 -2
- package/skills/mcpbox/SKILL.md +17 -94
- package/skills/mcpbox-close/SKILL.md +2 -0
- package/skills/mcpbox-mine/SKILL.md +4 -4
- package/skills/mcpbox-mode/SKILL.md +4 -12
- package/skills/mcpbox-next/SKILL.md +4 -3
- package/skills/mcpbox-pipeline-run/SKILL.md +4 -4
- package/skills/mcpbox-plan/SKILL.md +4 -4
- package/skills/mcpbox-sync/SKILL.md +1 -1
- package/skills/mcpbox-tasks/SKILL.md +4 -4
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// Daruma-Task commit trailers: the git side of "closed from git" (T4).
|
|
2
|
+
// A commit names the task it serves, so CI on main can post the outcome and a
|
|
3
|
+
// deploy can complete it even when the agent dropped the task mid-way.
|
|
4
|
+
// Deterministic and offline: no tracker call happens at commit time.
|
|
5
|
+
|
|
6
|
+
import { execFileSync } from "node:child_process";
|
|
7
|
+
import { promises as fs, readFileSync } from "node:fs";
|
|
8
|
+
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
|
|
11
|
+
import { sessionMarker } from "./hook-input.mjs";
|
|
12
|
+
|
|
13
|
+
export const TRAILER_KEY = "Daruma-Task";
|
|
14
|
+
const UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
|
15
|
+
const BRANCH_RE = new RegExp(`^work/(${UUID})$`, "i");
|
|
16
|
+
const MANAGED = "# mcpbox-claude managed prepare-commit-msg";
|
|
17
|
+
const HOOK_SCRIPT = join(dirname(fileURLToPath(import.meta.url)), "..", "hooks", "prepare-commit-msg.mjs");
|
|
18
|
+
|
|
19
|
+
export function branchTaskId(branch) {
|
|
20
|
+
return String(branch ?? "").trim().match(BRANCH_RE)?.[1].toLowerCase() ?? null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Successful claims recorded by track-claims.mjs, one JSON object per line.
|
|
24
|
+
export function claimedTaskIds(claimsText) {
|
|
25
|
+
const ids = String(claimsText ?? "").split("\n").flatMap((line) => {
|
|
26
|
+
try {
|
|
27
|
+
const id = JSON.parse(line)?.task_id;
|
|
28
|
+
return typeof id === "string" && new RegExp(`^${UUID}$`, "i").test(id) ? [id.toLowerCase()] : [];
|
|
29
|
+
} catch { return []; }
|
|
30
|
+
});
|
|
31
|
+
return [...new Set(ids)];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// A work/<id> branch scopes the commit to that one task; elsewhere every task
|
|
35
|
+
// this session claimed is named (a session-wide commit on main, say).
|
|
36
|
+
export function commitTaskIds({ branch, claimsText }) {
|
|
37
|
+
const fromBranch = branchTaskId(branch);
|
|
38
|
+
return fromBranch ? [fromBranch] : claimedTaskIds(claimsText);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function git(args, cwd) {
|
|
42
|
+
return execFileSync("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// git keeps an equal trailer once (addIfDifferent), so amend/re-run is a no-op.
|
|
46
|
+
export function addTrailers(messageFile, ids, cwd) {
|
|
47
|
+
for (const id of ids) {
|
|
48
|
+
git(["interpret-trailers", "--in-place", "--if-exists", "addIfDifferent",
|
|
49
|
+
"--trailer", `${TRAILER_KEY}: ${id}`, messageFile], cwd);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function prepareCommitMsg({ messageFile, cwd = process.cwd(), env = process.env }) {
|
|
54
|
+
if (!messageFile) return [];
|
|
55
|
+
let branch = "";
|
|
56
|
+
try { branch = git(["symbolic-ref", "--short", "-q", "HEAD"], cwd); } catch { /* detached HEAD */ }
|
|
57
|
+
const sessionId = env.CLAUDE_CODE_SESSION_ID || env.MCPBOX_SESSION_ID || "";
|
|
58
|
+
const claimsText = sessionId
|
|
59
|
+
? await fs.readFile(`${sessionMarker(sessionId)}.claims`, "utf8").catch(() => "")
|
|
60
|
+
: "";
|
|
61
|
+
const ids = commitTaskIds({ branch, claimsText });
|
|
62
|
+
if (ids.length) addTrailers(isAbsolute(messageFile) ? messageFile : resolve(cwd, messageFile), ids, cwd);
|
|
63
|
+
return ids;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function hookPath(dir) {
|
|
67
|
+
const path = git(["rev-parse", "--git-path", "hooks/prepare-commit-msg"], dir).trim();
|
|
68
|
+
return isAbsolute(path) ? path : resolve(dir, path);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function hookShim(script = HOOK_SCRIPT) {
|
|
72
|
+
return [
|
|
73
|
+
"#!/bin/sh",
|
|
74
|
+
`${MANAGED}: appends Daruma-Task trailers; never blocks a commit.`,
|
|
75
|
+
`hook='${script.replace(/'/g, "'\\''")}'`,
|
|
76
|
+
'if [ -f "$hook" ]; then node "$hook" "$@"',
|
|
77
|
+
'elif command -v mcpbox-claude >/dev/null 2>&1; then mcpbox-claude prepare-commit-msg "$@"; fi',
|
|
78
|
+
"exit 0",
|
|
79
|
+
"",
|
|
80
|
+
].join("\n");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function isManaged(path) {
|
|
84
|
+
try { return readFileSync(path, "utf8").includes(MANAGED); } catch { return null; }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Never replaces a hook someone else wrote.
|
|
88
|
+
export async function installGitHook(dir = process.cwd()) {
|
|
89
|
+
const path = hookPath(dir);
|
|
90
|
+
if (isManaged(path) === false) {
|
|
91
|
+
return { path, installed: false, reason: "foreign prepare-commit-msg hook exists; leaving it alone" };
|
|
92
|
+
}
|
|
93
|
+
await fs.mkdir(dirname(path), { recursive: true });
|
|
94
|
+
await fs.writeFile(path, hookShim(), { mode: 0o755 });
|
|
95
|
+
await fs.chmod(path, 0o755);
|
|
96
|
+
return { path, installed: true };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export async function removeGitHook(dir = process.cwd()) {
|
|
100
|
+
const path = hookPath(dir);
|
|
101
|
+
if (isManaged(path) !== true) return { path, removed: false };
|
|
102
|
+
await fs.rm(path);
|
|
103
|
+
return { path, removed: true };
|
|
104
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// Session-gate hooks for Codex and Cursor: the same hooks/*.mjs the Claude
|
|
2
|
+
// plugin runs, copied into a stable per-user dir (the npx cache that ran the
|
|
3
|
+
// installer is ephemeral) and registered in each CLI's own hooks.json.
|
|
4
|
+
//
|
|
5
|
+
// ~/.agents/mcpbox/harness/{hooks,lib}/ the copied scripts
|
|
6
|
+
// ~/.codex/hooks.json Claude-compatible events
|
|
7
|
+
// ~/.cursor/hooks.json Cursor camelCase events, failClosed
|
|
8
|
+
//
|
|
9
|
+
// Our entries are recognised by the harness path in their command, so every
|
|
10
|
+
// foreign hook in those files is preserved and an install is idempotent.
|
|
11
|
+
|
|
12
|
+
import { promises as fs } from "node:fs";
|
|
13
|
+
import { homedir } from "node:os";
|
|
14
|
+
import { dirname, join, posix, resolve } from "node:path";
|
|
15
|
+
import { fileURLToPath } from "node:url";
|
|
16
|
+
|
|
17
|
+
export const HARNESS_ASSETS = [
|
|
18
|
+
["hooks", "track-claims.mjs"],
|
|
19
|
+
["hooks", "stop.mjs"],
|
|
20
|
+
["hooks", "session-gate.mjs"],
|
|
21
|
+
["hooks", "bootstrap.mjs"],
|
|
22
|
+
["hooks/impl", "track-claims.mjs"],
|
|
23
|
+
["hooks/impl", "stop.mjs"],
|
|
24
|
+
["hooks/impl", "session-gate.mjs"],
|
|
25
|
+
["lib", "cloud-knowledge.mjs"],
|
|
26
|
+
["lib", "hook-input.mjs"],
|
|
27
|
+
["lib", "hook-output.mjs"],
|
|
28
|
+
["lib", "session-gate.mjs"],
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
const packageRoot = () => resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
32
|
+
export const harnessRoot = (homeDir) => join(resolve(homeDir ?? homedir()), ".agents", "mcpbox", "harness");
|
|
33
|
+
const isOurs = (root) => (h) => typeof h?.command === "string" && h.command.includes(root);
|
|
34
|
+
|
|
35
|
+
async function copyAssets(root) {
|
|
36
|
+
let changed = false;
|
|
37
|
+
for (const [subdir, file] of HARNESS_ASSETS) {
|
|
38
|
+
const target = join(root, subdir, file);
|
|
39
|
+
const content = await fs.readFile(join(packageRoot(), subdir, file));
|
|
40
|
+
const existing = await fs.readFile(target).catch(() => null);
|
|
41
|
+
if (existing && existing.equals(content)) continue;
|
|
42
|
+
await fs.mkdir(dirname(target), { recursive: true });
|
|
43
|
+
await fs.writeFile(target, content);
|
|
44
|
+
changed = true;
|
|
45
|
+
}
|
|
46
|
+
return changed;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Every relative import of a copied script has to be copied too, or the
|
|
50
|
+
// harness copy dies with ERR_MODULE_NOT_FOUND on every event (exit 1, and
|
|
51
|
+
// Codex drops the stderr that would say so).
|
|
52
|
+
const RELATIVE_IMPORT = /(?:\bfrom|\bimport)\s*\(?\s*["'](\.{1,2}\/[^"']+)["']/g;
|
|
53
|
+
|
|
54
|
+
export async function harnessImportGaps({
|
|
55
|
+
assets = HARNESS_ASSETS,
|
|
56
|
+
read = (rel) => fs.readFile(join(packageRoot(), rel), "utf8"),
|
|
57
|
+
} = {}) {
|
|
58
|
+
const shipped = new Set(assets.map(([subdir, file]) => `${subdir}/${file}`));
|
|
59
|
+
const gaps = [];
|
|
60
|
+
for (const rel of shipped) {
|
|
61
|
+
for (const [, spec] of (await read(rel)).matchAll(RELATIVE_IMPORT)) {
|
|
62
|
+
const target = posix.normalize(posix.join(posix.dirname(rel), spec));
|
|
63
|
+
if (!shipped.has(target)) gaps.push({ file: rel, imports: target });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return gaps;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// The installed copy against this package: what codex-init/cursor-init would rewrite.
|
|
70
|
+
export async function harnessStatus({ homeDir } = {}) {
|
|
71
|
+
const root = harnessRoot(homeDir);
|
|
72
|
+
const missing = [];
|
|
73
|
+
const stale = [];
|
|
74
|
+
for (const [subdir, file] of HARNESS_ASSETS) {
|
|
75
|
+
const target = join(root, subdir, file);
|
|
76
|
+
const existing = await fs.readFile(target).catch(() => null);
|
|
77
|
+
if (!existing) missing.push(target);
|
|
78
|
+
else if (!existing.equals(await fs.readFile(join(packageRoot(), subdir, file)))) stale.push(target);
|
|
79
|
+
}
|
|
80
|
+
return { root, missing, stale };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function readHooksFile(target) {
|
|
84
|
+
let doc;
|
|
85
|
+
try {
|
|
86
|
+
doc = JSON.parse(await fs.readFile(target, "utf8"));
|
|
87
|
+
} catch (err) {
|
|
88
|
+
if (err.code === "ENOENT") return null;
|
|
89
|
+
throw err;
|
|
90
|
+
}
|
|
91
|
+
if (!doc || typeof doc !== "object" || Array.isArray(doc)) throw new Error(`${target} is not a JSON object`);
|
|
92
|
+
if (!doc.hooks || typeof doc.hooks !== "object" || Array.isArray(doc.hooks)) doc.hooks = {};
|
|
93
|
+
return doc;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const command = (root, script, args) => `node "${join(root, "hooks", script)}"${args ? ` ${args}` : ""}`;
|
|
97
|
+
|
|
98
|
+
// Codex reads Claude-shaped groups: {matcher?, hooks: [{type, command, timeout}]}.
|
|
99
|
+
function codexEntries(root) {
|
|
100
|
+
const group = (script, args, timeout, matcher) => ({
|
|
101
|
+
...(matcher ? { matcher } : {}),
|
|
102
|
+
hooks: [{ type: "command", command: command(root, script, args), timeout }],
|
|
103
|
+
});
|
|
104
|
+
return {
|
|
105
|
+
SessionStart: group("session-gate.mjs", "start --surface=codex", 10),
|
|
106
|
+
PostToolUse: group("track-claims.mjs", "--surface=codex", 5, "daruma_(plan_drain_next|ready_drain|claim|plan_materialize|set_status|comment|release|complete)$"),
|
|
107
|
+
Stop: group("stop.mjs", "--surface=codex", 10),
|
|
108
|
+
SessionEnd: group("session-gate.mjs", "end --surface=codex", 10),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Cursor takes flat entries per camelCase event; failClosed so a hook that
|
|
113
|
+
// cannot run is not silently skipped (the scripts themselves exit 0 on any
|
|
114
|
+
// tracker failure, so this never blocks on the network).
|
|
115
|
+
function cursorEntries(root) {
|
|
116
|
+
const entry = (script, args) => ({ command: command(root, script, args), failClosed: true });
|
|
117
|
+
return {
|
|
118
|
+
sessionStart: entry("session-gate.mjs", "start --surface=cursor"),
|
|
119
|
+
afterMCPExecution: entry("track-claims.mjs", "--surface=cursor"),
|
|
120
|
+
stop: entry("stop.mjs", "--surface=cursor"),
|
|
121
|
+
sessionEnd: entry("session-gate.mjs", "end --surface=cursor"),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const groupIsOurs = (root) => (g) => isOurs(root)(g) || (Array.isArray(g?.hooks) && g.hooks.some(isOurs(root)));
|
|
126
|
+
|
|
127
|
+
// For flatMap: a group may hold foreign commands beside ours (Codex allows it),
|
|
128
|
+
// so only our entries go; the group and its fields stay while any hook is left.
|
|
129
|
+
const withoutOurs = (root) => (g) => {
|
|
130
|
+
if (isOurs(root)(g)) return [];
|
|
131
|
+
if (!groupIsOurs(root)(g)) return [g];
|
|
132
|
+
const hooks = g.hooks.filter((h) => !isOurs(root)(h));
|
|
133
|
+
return hooks.length ? [{ ...g, hooks }] : [];
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
async function install(target, entries, root, base) {
|
|
137
|
+
const assetsChanged = await copyAssets(root);
|
|
138
|
+
const doc = (await readHooksFile(target)) ?? base();
|
|
139
|
+
const before = JSON.stringify(doc);
|
|
140
|
+
for (const [event, entry] of Object.entries(entries)) {
|
|
141
|
+
const list = Array.isArray(doc.hooks[event]) ? doc.hooks[event] : [];
|
|
142
|
+
doc.hooks[event] = [...list.flatMap(withoutOurs(root)), entry];
|
|
143
|
+
}
|
|
144
|
+
const configChanged = JSON.stringify(doc) !== before;
|
|
145
|
+
if (!assetsChanged && !configChanged) return { action: "unchanged", path: target };
|
|
146
|
+
await fs.mkdir(dirname(target), { recursive: true });
|
|
147
|
+
await fs.writeFile(target, JSON.stringify(doc, null, 2) + "\n");
|
|
148
|
+
return { action: before === JSON.stringify(base()) ? "installed" : "updated", path: target };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function remove(target, root) {
|
|
152
|
+
const doc = await readHooksFile(target);
|
|
153
|
+
let removed = false;
|
|
154
|
+
if (doc) {
|
|
155
|
+
for (const [event, list] of Object.entries(doc.hooks)) {
|
|
156
|
+
if (!Array.isArray(list) || !list.some(groupIsOurs(root))) continue;
|
|
157
|
+
const rest = list.flatMap(withoutOurs(root));
|
|
158
|
+
if (rest.length) doc.hooks[event] = rest;
|
|
159
|
+
else delete doc.hooks[event];
|
|
160
|
+
removed = true;
|
|
161
|
+
}
|
|
162
|
+
if (removed) await fs.writeFile(target, JSON.stringify(doc, null, 2) + "\n");
|
|
163
|
+
}
|
|
164
|
+
return { action: removed ? "removed-block" : "missing", path: target };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export const codexHooksPath = (homeDir) => join(resolve(homeDir ?? homedir()), ".codex", "hooks.json");
|
|
168
|
+
export const cursorHooksPath = (homeDir) => join(resolve(homeDir ?? homedir()), ".cursor", "hooks.json");
|
|
169
|
+
|
|
170
|
+
export function installCodexHooks({ homeDir } = {}) {
|
|
171
|
+
const root = harnessRoot(homeDir);
|
|
172
|
+
return install(codexHooksPath(homeDir), codexEntries(root), root, () => ({ hooks: {} }));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function installCursorHooks({ homeDir } = {}) {
|
|
176
|
+
const root = harnessRoot(homeDir);
|
|
177
|
+
return install(cursorHooksPath(homeDir), cursorEntries(root), root, () => ({ version: 1, hooks: {} }));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function removeCodexHooks({ homeDir } = {}) {
|
|
181
|
+
return remove(codexHooksPath(homeDir), harnessRoot(homeDir));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function removeCursorHooks({ homeDir } = {}) {
|
|
185
|
+
return remove(cursorHooksPath(homeDir), harnessRoot(homeDir));
|
|
186
|
+
}
|