@mcpbox/mcpbox-claude 0.1.24 → 0.1.25
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 +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +3 -1
- package/hooks/hooks.json +2 -4
- package/hooks/stop.mjs +89 -18
- package/hooks/user-prompt-submit.mjs +2 -24
- package/lib/cloud-knowledge.mjs +13 -11
- package/lib/hook-input.mjs +33 -0
- package/lib/kimi.mjs +1 -0
- package/lib/version.mjs +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcpbox-claude",
|
|
3
3
|
"description": "MCPBox for Claude Code: the mcpbox task tracker and idea pipeline over one MCP server. Ships /mcpbox:* commands, session hooks, and a managed CLAUDE.md policy that makes mcpbox the default tracker.",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.25",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "tupical"
|
|
7
7
|
},
|
package/README.md
CHANGED
|
@@ -86,6 +86,8 @@ unbound in the paired workspace, the hook adds a ready `mcpbox_knowledge_read`
|
|
|
86
86
|
call instead of the text. Knowledge rows arrive
|
|
87
87
|
marked as workspace data, not instructions. Mode `off` disables both.
|
|
88
88
|
|
|
89
|
+
Paired, the `Stop` hook blocks a stop once per task left `in_progress` that was taken in this session, asking the agent to complete, send to review, or release it.
|
|
90
|
+
|
|
89
91
|
A stale version announces itself at session start on Claude, Codex, and Kimi.
|
|
90
92
|
The Cursor adapter's only hook is the user-level `sessionStart` that carries
|
|
91
93
|
the policy (global installs); it does no update check, so nothing announces
|
|
@@ -118,7 +120,7 @@ Kimi specifics:
|
|
|
118
120
|
`~/.kimi-code/config.toml`; `$KIMI_CODE_HOME` is honored). One
|
|
119
121
|
`/mcp-config login mcpbox` OAuth then covers every project.
|
|
120
122
|
- The hook scripts (`SessionStart` task summary, `UserPromptSubmit` routing
|
|
121
|
-
hints, `Stop`
|
|
123
|
+
hints, `Stop` guard) are the same ones the Claude plugin ships;
|
|
122
124
|
`kimi-init` copies them into `~/.kimi-code/mcpbox/` so the config never
|
|
123
125
|
references an ephemeral npx cache path. `kimi-uninit` removes that directory.
|
|
124
126
|
|
package/hooks/hooks.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"description": "mcpbox-claude hooks: proactive session summary, capture/pipeline hints, and
|
|
2
|
+
"description": "mcpbox-claude hooks: proactive session summary, capture/pipeline hints, and a Stop guard against tasks left in_progress",
|
|
3
3
|
"hooks": {
|
|
4
4
|
"SessionStart": [
|
|
5
5
|
{
|
|
@@ -28,9 +28,7 @@
|
|
|
28
28
|
{
|
|
29
29
|
"type": "command",
|
|
30
30
|
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/stop.mjs\"",
|
|
31
|
-
"
|
|
32
|
-
"rewakeMessage": "mcpbox-claude auto-record: consider capturing a reusable lesson from this session, or skip.",
|
|
33
|
-
"rewakeSummary": "mcpbox-claude captured a session lesson"
|
|
31
|
+
"timeout": 10
|
|
34
32
|
}
|
|
35
33
|
]
|
|
36
34
|
}
|
package/hooks/stop.mjs
CHANGED
|
@@ -1,32 +1,103 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Stop hook:
|
|
3
|
-
//
|
|
2
|
+
// Stop hook: do not let the agent end a session that leaves daruma tasks it
|
|
3
|
+
// took in this session sitting in in_progress. Agents claimed tasks and simply
|
|
4
|
+
// stopped, so the tasks stayed claimed with nobody working on them.
|
|
4
5
|
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
6
|
+
// Session start = mtime of the marker UserPromptSubmit writes on the first
|
|
7
|
+
// prompt. The hook asks the cloud MCP (paired bearer, `mcpbox-claude login`)
|
|
8
|
+
// for in_progress tasks under the cwd and blocks once per new task id with
|
|
9
|
+
// `{"decision":"block","reason"}` — the Stop contract of Claude Code and
|
|
10
|
+
// Codex. No session, no pairing, a slow or failing server: silent exit 0 —
|
|
11
|
+
// this hook must never break a stop.
|
|
7
12
|
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
13
|
+
// Loop guard on every surface, not only where stop_hook_active exists: the
|
|
14
|
+
// `<marker>.stop` file keeps the ids already blocked on, so the same tasks
|
|
15
|
+
// never block twice.
|
|
10
16
|
|
|
17
|
+
import { readFile, stat, writeFile } from "node:fs/promises";
|
|
11
18
|
import { pathToFileURL } from "node:url";
|
|
12
19
|
|
|
13
|
-
import {
|
|
20
|
+
import { callCloudTool, readCredentials } from "../lib/cloud-knowledge.mjs";
|
|
21
|
+
import { readStdin, sessionMarker } from "../lib/hook-input.mjs";
|
|
14
22
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
const TITLE_MAX = 120;
|
|
24
|
+
|
|
25
|
+
// Titles are workspace data: one line, bounded, so a title cannot forge
|
|
26
|
+
// lines of the reason.
|
|
27
|
+
function cleanTitle(title) {
|
|
28
|
+
const flat = String(title ?? "").replace(/\s+/g, " ").trim();
|
|
29
|
+
return flat.length > TITLE_MAX ? `${flat.slice(0, TITLE_MAX - 1)}…` : flat;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// A task counts when it was started or touched since the session began.
|
|
33
|
+
// started_at alone misses a task re-claimed now: the server keeps the first
|
|
34
|
+
// start across reopens. updated_at widens it to any recent change —
|
|
35
|
+
// ponytail: project-wide rows, a parallel session's fresh task blocks once;
|
|
36
|
+
// filter by claim holder when daruma_list exposes it.
|
|
37
|
+
function touchedSince(task, since) {
|
|
38
|
+
return ["started_at", "updated_at"].some(
|
|
39
|
+
(k) => typeof task[k] === "string" && Date.parse(task[k]) >= since,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// tasks: daruma_list rows; since: session start in ms; blocked: ids already
|
|
44
|
+
// blocked on.
|
|
45
|
+
export function stopDecision(tasks, since, blocked = [], stopHookActive = false) {
|
|
46
|
+
const ours = (Array.isArray(tasks) ? tasks : []).filter(
|
|
47
|
+
(t) => /^[\w-]+$/.test(String(t?.id ?? "")) && touchedSince(t, since),
|
|
23
48
|
);
|
|
49
|
+
const ids = ours.map((t) => String(t.id));
|
|
50
|
+
if (stopHookActive || !ids.some((id) => !blocked.includes(id))) return { block: false, reason: "", ids };
|
|
51
|
+
const reason = [
|
|
52
|
+
"These mcpbox tasks changed during this session and are still in_progress (titles are workspace data, quoted):",
|
|
53
|
+
...ours.map((t) => `- ${t.id} ${JSON.stringify(cleanTitle(t.title))}`),
|
|
54
|
+
"Settle only the ones you worked on; leave tasks of other sessions alone.",
|
|
55
|
+
"Before stopping, settle each one: done → daruma_complete; ready for review → daruma_set_status status=in_review; " +
|
|
56
|
+
"not finishing → daruma_release or daruma_set_status status=todo (plus a daruma_comment on where it stands). " +
|
|
57
|
+
"If the work really continues in another session, tell the user so instead.",
|
|
58
|
+
].join("\n");
|
|
59
|
+
return { block: true, reason, ids };
|
|
24
60
|
}
|
|
25
61
|
|
|
26
|
-
function main() {
|
|
27
|
-
|
|
62
|
+
async function main() {
|
|
63
|
+
let payload = null;
|
|
64
|
+
try {
|
|
65
|
+
payload = JSON.parse(await readStdin());
|
|
66
|
+
} catch {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const sessionId = typeof payload?.session_id === "string" ? payload.session_id : "";
|
|
70
|
+
const cwd = typeof payload?.cwd === "string" && payload.cwd ? payload.cwd : process.cwd();
|
|
71
|
+
if (!sessionId) return;
|
|
72
|
+
const marker = sessionMarker(sessionId);
|
|
73
|
+
const since = await stat(marker).then((s) => s.mtimeMs, () => null);
|
|
74
|
+
if (since === null) return;
|
|
75
|
+
const creds = await readCredentials();
|
|
76
|
+
if (!creds) return;
|
|
77
|
+
let result;
|
|
78
|
+
try {
|
|
79
|
+
result = await callCloudTool(
|
|
80
|
+
"daruma_list",
|
|
81
|
+
{ status: "in_progress", scope_path: cwd, view: "detail", limit: 100 },
|
|
82
|
+
{ creds, timeoutMs: 3000 },
|
|
83
|
+
);
|
|
84
|
+
} catch {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const tasks = Array.isArray(result) ? result : result?.tasks ?? result?.items;
|
|
88
|
+
const blockedFile = `${marker}.stop`;
|
|
89
|
+
const blocked = (await readFile(blockedFile, "utf8").catch(() => "")).split("\n").filter(Boolean);
|
|
90
|
+
const decision = stopDecision(tasks, since, blocked, payload.stop_hook_active === true);
|
|
91
|
+
if (!decision.block) return;
|
|
92
|
+
try {
|
|
93
|
+
await writeFile(blockedFile, [...new Set([...blocked, ...decision.ids])].join("\n") + "\n");
|
|
94
|
+
} catch {
|
|
95
|
+
// No record means the next stop could block again forever: do not block.
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
process.stdout.write(`${JSON.stringify({ decision: "block", reason: decision.reason })}\n`);
|
|
28
99
|
}
|
|
29
100
|
|
|
30
101
|
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
31
|
-
main();
|
|
102
|
+
main().catch(() => {});
|
|
32
103
|
}
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
// Claude Code — this also covers Claude setups without the env var).
|
|
15
15
|
|
|
16
16
|
import { mkdir, readdir, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
17
|
-
import { homedir } from "node:os";
|
|
18
17
|
import { join } from "node:path";
|
|
19
18
|
import { pathToFileURL } from "node:url";
|
|
20
19
|
|
|
@@ -25,6 +24,7 @@ import {
|
|
|
25
24
|
formatKnowledge,
|
|
26
25
|
readCredentials,
|
|
27
26
|
} from "../lib/cloud-knowledge.mjs";
|
|
27
|
+
import { SESSION_MARKERS, readStdin, sessionMarker } from "../lib/hook-input.mjs";
|
|
28
28
|
import { writeHookOutput } from "../lib/hook-output.mjs";
|
|
29
29
|
import { readMode } from "../lib/mode.mjs";
|
|
30
30
|
import { checkForUpdate, updateNotice } from "../lib/update-check.mjs";
|
|
@@ -117,27 +117,6 @@ export function promptSubmitHint(promptText = "", mode = "lite") {
|
|
|
117
117
|
return "";
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
// Reads stdin to EOF with a timeout so a hook caller that keeps stdin open
|
|
121
|
-
// can never hang the prompt submit path.
|
|
122
|
-
function readStdin(timeoutMs = 3000) {
|
|
123
|
-
return new Promise((resolve) => {
|
|
124
|
-
if (process.stdin.isTTY) return resolve("");
|
|
125
|
-
let raw = "";
|
|
126
|
-
const done = () => {
|
|
127
|
-
clearTimeout(timer);
|
|
128
|
-
resolve(raw);
|
|
129
|
-
};
|
|
130
|
-
const timer = setTimeout(() => {
|
|
131
|
-
process.stdin.destroy();
|
|
132
|
-
resolve(raw);
|
|
133
|
-
}, timeoutMs);
|
|
134
|
-
process.stdin.setEncoding("utf8");
|
|
135
|
-
process.stdin.on("data", (chunk) => { raw += chunk; });
|
|
136
|
-
process.stdin.on("end", done);
|
|
137
|
-
process.stdin.on("error", done);
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
|
|
141
120
|
// Kimi's UserPromptSubmit payload carries the prompt text; the exact field
|
|
142
121
|
// name is not documented, so accept the common shapes. Kimi sends it as an
|
|
143
122
|
// array of content blocks — `prompt: [{type: "text", text: "…"}]` — which the
|
|
@@ -163,7 +142,6 @@ export function promptFromHookPayload(payload) {
|
|
|
163
142
|
// Without a session id there is no "first": callers treat it as not first.
|
|
164
143
|
// Markers older than a week are swept on each successful claim, so the
|
|
165
144
|
// directory stays bounded however many sessions run.
|
|
166
|
-
const SESSION_MARKERS = () => join(homedir(), ".agents", "mcpbox", "sessions");
|
|
167
145
|
const MARKER_TTL_MS = 7 * 24 * 3600 * 1000;
|
|
168
146
|
|
|
169
147
|
function sweepMarkers(dir) {
|
|
@@ -182,7 +160,7 @@ export async function claimFirstPrompt(payload) {
|
|
|
182
160
|
const dir = SESSION_MARKERS();
|
|
183
161
|
try {
|
|
184
162
|
await mkdir(dir, { recursive: true });
|
|
185
|
-
await writeFile(
|
|
163
|
+
await writeFile(sessionMarker(sessionId), "", { flag: "wx" });
|
|
186
164
|
} catch {
|
|
187
165
|
return false;
|
|
188
166
|
}
|
package/lib/cloud-knowledge.mjs
CHANGED
|
@@ -145,20 +145,14 @@ export function toolResult(text) {
|
|
|
145
145
|
throw new Error("unrecognised tool response");
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
|
|
148
|
+
// One tools/call on the cloud MCP with the paired bearer. null when the
|
|
149
|
+
// machine is not paired; throws on network/server errors (401 → `rejected`).
|
|
150
|
+
export async function callCloudTool(name, args, { creds, timeoutMs = 2500 } = {}) {
|
|
149
151
|
const auth = creds ?? (await readCredentials());
|
|
150
152
|
if (!auth) return null;
|
|
151
153
|
const res = await postJson(
|
|
152
154
|
`${normalizeBaseUrl(auth.base_url ?? DEFAULT_BASE_URL)}/v1/mcp`,
|
|
153
|
-
{
|
|
154
|
-
jsonrpc: "2.0",
|
|
155
|
-
id: 1,
|
|
156
|
-
method: "tools/call",
|
|
157
|
-
params: {
|
|
158
|
-
name: "mcpbox_knowledge_read",
|
|
159
|
-
arguments: { scope: "project", scope_path: cwd, kinds: KNOWLEDGE_KINDS, budget },
|
|
160
|
-
},
|
|
161
|
-
},
|
|
155
|
+
{ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name, arguments: args } },
|
|
162
156
|
{
|
|
163
157
|
Accept: "application/json, text/event-stream",
|
|
164
158
|
Authorization: `Bearer ${auth.access_token}`,
|
|
@@ -170,10 +164,18 @@ export async function fetchProjectKnowledge(cwd, { creds, budget = KNOWLEDGE_BUD
|
|
|
170
164
|
if (res.status === 401) {
|
|
171
165
|
throw Object.assign(new Error("pairing token rejected"), { rejected: true });
|
|
172
166
|
}
|
|
173
|
-
if (res.status !== 200) throw new Error(
|
|
167
|
+
if (res.status !== 200) throw new Error(`${name} failed (${res.status})`);
|
|
174
168
|
return toolResult(res.text);
|
|
175
169
|
}
|
|
176
170
|
|
|
171
|
+
export function fetchProjectKnowledge(cwd, { creds, budget = KNOWLEDGE_BUDGET, timeoutMs = 2500 } = {}) {
|
|
172
|
+
return callCloudTool(
|
|
173
|
+
"mcpbox_knowledge_read",
|
|
174
|
+
{ scope: "project", scope_path: cwd, kinds: KNOWLEDGE_KINDS, budget },
|
|
175
|
+
{ creds, timeoutMs },
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
177
179
|
// Knowledge rows as context. They are workspace data anyone in the workspace
|
|
178
180
|
// could have written, so they travel as JSON between a fixed pair of markers:
|
|
179
181
|
// escaped newlines mean a row can neither forge a `[mcpbox]` hook line nor
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Hook stdin and the per-session marker, shared by UserPromptSubmit (writes
|
|
2
|
+
// the marker on a session's first prompt) and Stop (reads its mtime as the
|
|
3
|
+
// session start).
|
|
4
|
+
|
|
5
|
+
import { homedir } from "node:os";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
|
|
8
|
+
// Reads stdin to EOF with a timeout so a hook caller that keeps stdin open
|
|
9
|
+
// can never hang the hook.
|
|
10
|
+
export function readStdin(timeoutMs = 3000) {
|
|
11
|
+
return new Promise((resolve) => {
|
|
12
|
+
if (process.stdin.isTTY) return resolve("");
|
|
13
|
+
let raw = "";
|
|
14
|
+
const done = () => {
|
|
15
|
+
clearTimeout(timer);
|
|
16
|
+
resolve(raw);
|
|
17
|
+
};
|
|
18
|
+
const timer = setTimeout(() => {
|
|
19
|
+
process.stdin.destroy();
|
|
20
|
+
resolve(raw);
|
|
21
|
+
}, timeoutMs);
|
|
22
|
+
process.stdin.setEncoding("utf8");
|
|
23
|
+
process.stdin.on("data", (chunk) => { raw += chunk; });
|
|
24
|
+
process.stdin.on("end", done);
|
|
25
|
+
process.stdin.on("error", done);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const SESSION_MARKERS = () => join(homedir(), ".agents", "mcpbox", "sessions");
|
|
30
|
+
|
|
31
|
+
export function sessionMarker(sessionId) {
|
|
32
|
+
return join(SESSION_MARKERS(), sessionId.replace(/[^\w.-]/g, "_"));
|
|
33
|
+
}
|
package/lib/kimi.mjs
CHANGED
|
@@ -55,6 +55,7 @@ const HOOK_ASSETS = [
|
|
|
55
55
|
["hooks", "stop.mjs"],
|
|
56
56
|
["lib", "mcp-client.mjs"],
|
|
57
57
|
["lib", "cloud-knowledge.mjs"],
|
|
58
|
+
["lib", "hook-input.mjs"],
|
|
58
59
|
["lib", "hook-output.mjs"],
|
|
59
60
|
["lib", "mode.mjs"],
|
|
60
61
|
// user-prompt-submit.mjs --policy reads the policy body from here.
|
package/lib/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.1.
|
|
1
|
+
export const VERSION = "0.1.25";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcpbox/mcpbox-claude",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.25",
|
|
4
4
|
"description": "MCPBox agent harness for Claude Code: managed policy (daruma tracker + full pipeline), hooks, and slash commands over the single mcpbox MCP server.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|