@mcpbox/mcpbox-claude 0.1.12 → 0.1.14
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 +51 -0
- package/hooks/session-start.mjs +26 -12
- package/hooks/user-prompt-submit.mjs +16 -7
- package/lib/hook-output.mjs +20 -11
- package/lib/kimi.mjs +6 -2
- package/lib/mcp-client.mjs +40 -14
- package/lib/update-check.mjs +81 -0
- package/lib/version.mjs +1 -0
- package/package.json +3 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcpbox-claude",
|
|
3
3
|
"description": "MCPBox × Claude Code glue. Drives the mcpbox MCP server (daruma tracker + full MeiSei pipeline torii→…→fujin→daruma). Ships /mcpbox:{tasks,plan,next,mine,status,close,sync,capture,doctor,mode} and pipeline commands, SessionStart/Stop/UserPromptSubmit hooks, and a managed CLAUDE.md policy that makes mcpbox the default tracker AND pipeline substrate.",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.14",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "tupical"
|
|
7
7
|
},
|
package/README.md
CHANGED
|
@@ -10,6 +10,56 @@ Normally installed for you by `npx @mcpbox/mcpbox setup` (or
|
|
|
10
10
|
server and picks Repository, Repository (user scope), or Global. Use this CLI directly to manage
|
|
11
11
|
just the policy.
|
|
12
12
|
|
|
13
|
+
## Install and update
|
|
14
|
+
|
|
15
|
+
Claude Code and Codex install from the public git marketplace, which is the only
|
|
16
|
+
source either of them will auto-update from — Claude ignores `autoUpdate` on a
|
|
17
|
+
directory source, and Codex refuses outright (`marketplace … is not configured as
|
|
18
|
+
a Git marketplace`). Neither accepts an npm registry as a marketplace source, so
|
|
19
|
+
the repo below is generated from the published package on every release.
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Claude Code
|
|
23
|
+
claude plugin marketplace add https://github.com/tupical/mcpbox-plugin.git
|
|
24
|
+
claude plugin install mcpbox-claude@mcpbox
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Then set `autoUpdate` on the marketplace in `~/.claude/settings.json`:
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
"extraKnownMarketplaces": {
|
|
31
|
+
"mcpbox": {
|
|
32
|
+
"source": { "source": "git", "url": "https://github.com/tupical/mcpbox-plugin.git" },
|
|
33
|
+
"autoUpdate": true
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Claude refreshes in the background 0–10 minutes after a session starts and the
|
|
39
|
+
new version is picked up by `/reload-plugins` or the next session — the running
|
|
40
|
+
one keeps what it loaded at startup.
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# Codex
|
|
44
|
+
codex plugin marketplace add https://github.com/tupical/mcpbox-plugin.git
|
|
45
|
+
codex plugin add mcpbox --marketplace mcpbox
|
|
46
|
+
codex plugin marketplace upgrade mcpbox # later, to update
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Cursor and Kimi have no plugin manager; they are file installs, so re-run their
|
|
50
|
+
init to update:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npx -y @mcpbox/mcpbox-claude@latest cursor-init
|
|
54
|
+
npx -y @mcpbox/mcpbox-claude@latest kimi-init
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
A stale version announces itself at session start on Claude, Codex, and Kimi.
|
|
58
|
+
Cursor exposes no hooks at all, so nothing can announce anything there — check
|
|
59
|
+
manually, or let `cursor-init` in a routine update pass do it. Set
|
|
60
|
+
`MCPBOX_NO_UPDATE_CHECK=1` to disable the registry lookup entirely (air-gapped
|
|
61
|
+
installs, CI).
|
|
62
|
+
|
|
13
63
|
## What it manages
|
|
14
64
|
|
|
15
65
|
| Agent | Policy surface | MCP server | Hooks |
|
|
@@ -50,6 +100,7 @@ mcpbox-claude mode [off|lite|full] Show or set the shared pipeline mode.
|
|
|
50
100
|
```
|
|
51
101
|
|
|
52
102
|
All writes are idempotent and preserve surrounding hand-written content.
|
|
103
|
+
Set `MCPBOX_NO_UPDATE_CHECK=1` to disable hook update checks.
|
|
53
104
|
|
|
54
105
|
## License
|
|
55
106
|
|
package/hooks/session-start.mjs
CHANGED
|
@@ -16,8 +16,11 @@
|
|
|
16
16
|
// MCPBOX_MCP_ARGS — space-separated extra args (default: "mcp serve")
|
|
17
17
|
// MCPBOX_SCOPE — optional project_scope path filter
|
|
18
18
|
|
|
19
|
-
import { writeHookOutput } from "../lib/hook-output.mjs";
|
|
19
|
+
import { isCodexSurface, writeHookOutput } from "../lib/hook-output.mjs";
|
|
20
20
|
import { MCPClient } from "../lib/mcp-client.mjs";
|
|
21
|
+
import { checkForUpdate, updateNotice } from "../lib/update-check.mjs";
|
|
22
|
+
import { VERSION } from "../lib/version.mjs";
|
|
23
|
+
import { pathToFileURL } from "node:url";
|
|
21
24
|
|
|
22
25
|
const TIMEOUT_MS = 12_000;
|
|
23
26
|
const MAX_TASKS = 15;
|
|
@@ -98,14 +101,22 @@ async function fetchSummary() {
|
|
|
98
101
|
}
|
|
99
102
|
}
|
|
100
103
|
|
|
101
|
-
async function main() {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
104
|
+
export async function main() {
|
|
105
|
+
const [data, update] = await Promise.all([
|
|
106
|
+
fetchSummary().catch((err) => {
|
|
107
|
+
if (process.env.MCPBOX_DEBUG) {
|
|
108
|
+
process.stderr.write(`[mcpbox-claude/session-start] error: ${err?.message ?? err}\n`);
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}),
|
|
112
|
+
checkForUpdate({ current: VERSION }),
|
|
113
|
+
]);
|
|
114
|
+
const systemMessage = update?.outdated
|
|
115
|
+
? updateNotice(update.current, update.latest, isCodexSurface() ? "codex" : "claude")
|
|
116
|
+
: undefined;
|
|
117
|
+
|
|
118
|
+
if (!data) {
|
|
119
|
+
writeHookOutput("SessionStart", "", { systemMessage });
|
|
109
120
|
process.exit(0);
|
|
110
121
|
}
|
|
111
122
|
|
|
@@ -114,7 +125,8 @@ async function main() {
|
|
|
114
125
|
if (!tasks || tasks.length === 0) {
|
|
115
126
|
writeHookOutput(
|
|
116
127
|
"SessionStart",
|
|
117
|
-
"[mcpbox] No open tasks — run /mcpbox:tasks to verify, or /mcpbox:pipeline-run \"<idea>\" to open a maturity run."
|
|
128
|
+
"[mcpbox] No open tasks — run /mcpbox:tasks to verify, or /mcpbox:pipeline-run \"<idea>\" to open a maturity run.",
|
|
129
|
+
{ systemMessage },
|
|
118
130
|
);
|
|
119
131
|
process.exit(0);
|
|
120
132
|
}
|
|
@@ -131,8 +143,10 @@ async function main() {
|
|
|
131
143
|
if (extra > 0) lines.push(` …and ${extra} more — /mcpbox:tasks for full list`);
|
|
132
144
|
lines.push("→ /mcpbox:next to claim the next task | /mcpbox:status for server + pipeline health");
|
|
133
145
|
|
|
134
|
-
writeHookOutput("SessionStart", lines.join("\n"));
|
|
146
|
+
writeHookOutput("SessionStart", lines.join("\n"), { systemMessage });
|
|
135
147
|
process.exit(0);
|
|
136
148
|
}
|
|
137
149
|
|
|
138
|
-
|
|
150
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
151
|
+
main();
|
|
152
|
+
}
|
|
@@ -20,6 +20,8 @@ import { pathToFileURL } from "node:url";
|
|
|
20
20
|
|
|
21
21
|
import { writeHookOutput } from "../lib/hook-output.mjs";
|
|
22
22
|
import { readMode } from "../lib/mode.mjs";
|
|
23
|
+
import { checkForUpdate, updateNotice } from "../lib/update-check.mjs";
|
|
24
|
+
import { VERSION } from "../lib/version.mjs";
|
|
23
25
|
|
|
24
26
|
// Intent patterns. Order matters — first match wins. ASCII keywords use \b;
|
|
25
27
|
// Cyrillic uses whitespace/edge guards since \b is ASCII-only.
|
|
@@ -143,19 +145,21 @@ export function promptFromHookPayload(payload) {
|
|
|
143
145
|
// fire, so for Kimi the policy rides in on the first prompt of a session.
|
|
144
146
|
// Claude registers this hook without --policy: it reads CLAUDE.md already.
|
|
145
147
|
async function policyForFirstPrompt(payload) {
|
|
146
|
-
if (!process.argv.includes("--policy")) return "";
|
|
148
|
+
if (!process.argv.includes("--policy")) return { policy: "", firstPrompt: false };
|
|
147
149
|
// PLAIN: this path only ever serves non-Claude surfaces, which have no
|
|
148
150
|
// /mcpbox:* commands.
|
|
149
151
|
const { BLOCK_BODY_PLAIN, BEGIN } = await import("../lib/policy.mjs");
|
|
150
152
|
const cwd = typeof payload?.cwd === "string" && payload.cwd ? payload.cwd : process.cwd();
|
|
153
|
+
let policy = BLOCK_BODY_PLAIN;
|
|
151
154
|
try {
|
|
152
155
|
// An AGENTS.md right here already carries the block — the agent is
|
|
153
156
|
// reading it, so a second copy would be pure noise.
|
|
154
|
-
if ((await readFile(join(cwd, "AGENTS.md"), "utf8")).includes(BEGIN))
|
|
157
|
+
if ((await readFile(join(cwd, "AGENTS.md"), "utf8")).includes(BEGIN)) policy = "";
|
|
155
158
|
} catch { /* no AGENTS.md here — the policy has to come from us */ }
|
|
156
159
|
|
|
160
|
+
if (!policy) return { policy: "", firstPrompt: false };
|
|
157
161
|
const sessionId = typeof payload?.session_id === "string" ? payload.session_id : "";
|
|
158
|
-
if (!sessionId) return
|
|
162
|
+
if (!sessionId) return { policy, firstPrompt: false }; // policy repeats; update notices must not
|
|
159
163
|
// ponytail: one empty marker file per session, never swept. They are 0
|
|
160
164
|
// bytes; add a cleanup pass only if a long-lived install ever complains.
|
|
161
165
|
const marker = join(homedir(), ".agents", "mcpbox", "sessions", sessionId.replace(/[^\w.-]/g, "_"));
|
|
@@ -164,9 +168,9 @@ async function policyForFirstPrompt(payload) {
|
|
|
164
168
|
// wx fails if it exists → the policy already went out this session.
|
|
165
169
|
await writeFile(marker, "", { flag: "wx" });
|
|
166
170
|
} catch {
|
|
167
|
-
return "";
|
|
171
|
+
return { policy: "", firstPrompt: false };
|
|
168
172
|
}
|
|
169
|
-
return
|
|
173
|
+
return { policy, firstPrompt: true };
|
|
170
174
|
}
|
|
171
175
|
|
|
172
176
|
async function main() {
|
|
@@ -181,11 +185,16 @@ async function main() {
|
|
|
181
185
|
} catch { /* not JSON — no prompt to route */ }
|
|
182
186
|
}
|
|
183
187
|
}
|
|
184
|
-
const policy = await policyForFirstPrompt(payload);
|
|
188
|
+
const { policy, firstPrompt } = await policyForFirstPrompt(payload);
|
|
189
|
+
const update = firstPrompt ? await checkForUpdate({ current: VERSION }) : null;
|
|
185
190
|
const hint = promptSubmitHint(prompt, readMode());
|
|
191
|
+
const notice = update?.outdated ? updateNotice(update.current, update.latest, "kimi") : "";
|
|
186
192
|
// One write, not two: Codex parses stdout as a single JSON document, so a
|
|
187
193
|
// policy object followed by a hint object is as invalid as plain text.
|
|
188
|
-
writeHookOutput(
|
|
194
|
+
writeHookOutput(
|
|
195
|
+
"UserPromptSubmit",
|
|
196
|
+
[notice, policy, hint].filter(Boolean).join("\n"),
|
|
197
|
+
);
|
|
189
198
|
}
|
|
190
199
|
|
|
191
200
|
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
package/lib/hook-output.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
// One writer for every hook's stdout, because the surfaces disagree on format.
|
|
2
2
|
//
|
|
3
|
-
// Claude Code and Kimi take plain text. Codex parses hook stdout as
|
|
4
|
-
//
|
|
5
|
-
// which is what every mcpbox hint turned into on Codex 0.147, once per prompt.
|
|
3
|
+
// Claude Code and Kimi normally take plain text. Codex parses hook stdout as
|
|
4
|
+
// JSON; Claude also accepts JSON when a user-visible systemMessage is present.
|
|
6
5
|
//
|
|
7
6
|
// Codex is the surface that exports PLUGIN_DATA (its per-plugin state dir,
|
|
8
7
|
// ~/.codex/plugins/data/<marketplace>-<plugin>); Claude Code exports only
|
|
@@ -14,19 +13,29 @@ export function isCodexSurface(env = process.env) {
|
|
|
14
13
|
// Codex has a *HookSpecificOutputWire for SessionStart / UserPromptSubmit /
|
|
15
14
|
// SubagentStart only; Stop has none and rejects additionalContext there, so a
|
|
16
15
|
// Stop message rides as systemMessage instead.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
/** @param {{ systemMessage?: string }} [options] */
|
|
17
|
+
export function hookOutputPayload(event, text, options = {}) {
|
|
18
|
+
const systemMessage = options?.systemMessage;
|
|
19
|
+
const hasSystemMessage = systemMessage !== undefined;
|
|
20
|
+
if (event === "Stop" || event === "SubagentStop") {
|
|
21
|
+
return { systemMessage: systemMessage ?? text };
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
...(hasSystemMessage ? { systemMessage } : {}),
|
|
25
|
+
...(text ? { hookSpecificOutput: { hookEventName: event, additionalContext: text } } : {}),
|
|
26
|
+
};
|
|
21
27
|
}
|
|
22
28
|
|
|
23
29
|
// Empty output stays empty: every surface reads "no stdout" as "no hint", and
|
|
24
30
|
// Codex only parses when something was written.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
/** @param {{ systemMessage?: string }} [options] */
|
|
32
|
+
export function writeHookOutput(event, text, options = {}, env = process.env) {
|
|
33
|
+
const systemMessage = options?.systemMessage;
|
|
34
|
+
const hasSystemMessage = systemMessage !== undefined;
|
|
35
|
+
if (!text && !hasSystemMessage) return;
|
|
36
|
+
if (!hasSystemMessage && !isCodexSurface(env)) {
|
|
28
37
|
process.stdout.write(text.endsWith("\n") ? text : `${text}\n`);
|
|
29
38
|
return;
|
|
30
39
|
}
|
|
31
|
-
process.stdout.write(`${JSON.stringify(hookOutputPayload(event, text))}\n`);
|
|
40
|
+
process.stdout.write(`${JSON.stringify(hookOutputPayload(event, text, { systemMessage }))}\n`);
|
|
32
41
|
}
|
package/lib/kimi.mjs
CHANGED
|
@@ -45,16 +45,20 @@ const END = "<!-- mcpbox:policy:end -->";
|
|
|
45
45
|
const TOML_BEGIN = "# mcpbox:hooks:begin";
|
|
46
46
|
const TOML_END = "# mcpbox:hooks:end";
|
|
47
47
|
|
|
48
|
-
// Hook assets copied into the Kimi home: the three hook scripts
|
|
49
|
-
//
|
|
48
|
+
// Hook assets copied into the Kimi home: the three hook scripts and all their
|
|
49
|
+
// local imports. Tests import static dependencies and execute --policy for the
|
|
50
|
+
// dynamic policy.mjs import.
|
|
50
51
|
const HOOK_ASSETS = [
|
|
51
52
|
["hooks", "session-start.mjs"],
|
|
52
53
|
["hooks", "user-prompt-submit.mjs"],
|
|
53
54
|
["hooks", "stop.mjs"],
|
|
54
55
|
["lib", "mcp-client.mjs"],
|
|
56
|
+
["lib", "hook-output.mjs"],
|
|
55
57
|
["lib", "mode.mjs"],
|
|
56
58
|
// user-prompt-submit.mjs --policy reads the policy body from here.
|
|
57
59
|
["lib", "policy.mjs"],
|
|
60
|
+
["lib", "update-check.mjs"],
|
|
61
|
+
["lib", "version.mjs"],
|
|
58
62
|
];
|
|
59
63
|
|
|
60
64
|
const MCP_ENTRY = { url: MCP_URL };
|
package/lib/mcp-client.mjs
CHANGED
|
@@ -28,23 +28,31 @@ export class MCPClient {
|
|
|
28
28
|
this._initialized = false;
|
|
29
29
|
this._serverInfo = null;
|
|
30
30
|
this._stderrStream = null;
|
|
31
|
+
this._failure = null;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
async start(cmd, args = [], { cwd = process.cwd(), stderrLog = null, env = process.env } = {}) {
|
|
34
35
|
if (this._proc) throw new Error("MCPClient already started");
|
|
35
|
-
|
|
36
|
+
const proc = spawn(cmd, args, { cwd, env, stdio: ["pipe", "pipe", "pipe"] });
|
|
37
|
+
this._proc = proc;
|
|
38
|
+
this._failure = null;
|
|
39
|
+
|
|
40
|
+
for (const stream of [proc.stdin, proc.stdout, proc.stderr]) {
|
|
41
|
+
stream.on("error", (err) => this._onError(err));
|
|
42
|
+
}
|
|
36
43
|
|
|
37
44
|
if (stderrLog) {
|
|
38
45
|
this._stderrStream = createWriteStream(stderrLog, { flags: "a" });
|
|
39
|
-
this.
|
|
46
|
+
this._stderrStream.on("error", () => {});
|
|
47
|
+
proc.stderr.pipe(this._stderrStream);
|
|
40
48
|
} else {
|
|
41
|
-
|
|
49
|
+
proc.stderr.on("data", () => {}); // drain to avoid backpressure
|
|
42
50
|
}
|
|
43
51
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
proc.stdout.setEncoding("utf8");
|
|
53
|
+
proc.stdout.on("data", (chunk) => this._onData(chunk));
|
|
54
|
+
proc.on("exit", (code, signal) => this._onExit(proc, code, signal));
|
|
55
|
+
proc.on("error", (err) => this._onError(err));
|
|
48
56
|
}
|
|
49
57
|
|
|
50
58
|
async initialize() {
|
|
@@ -56,7 +64,7 @@ export class MCPClient {
|
|
|
56
64
|
this._serverInfo = result.serverInfo ?? null;
|
|
57
65
|
this._initialized = true;
|
|
58
66
|
// Per spec, follow up with a one-way "initialized" notification.
|
|
59
|
-
this._send({ jsonrpc: "2.0", method: "notifications/initialized" });
|
|
67
|
+
await this._send({ jsonrpc: "2.0", method: "notifications/initialized" });
|
|
60
68
|
return result;
|
|
61
69
|
}
|
|
62
70
|
|
|
@@ -73,6 +81,7 @@ export class MCPClient {
|
|
|
73
81
|
}
|
|
74
82
|
|
|
75
83
|
async stop() {
|
|
84
|
+
if (this._stderrStream) this._stderrStream.end();
|
|
76
85
|
if (!this._proc) return;
|
|
77
86
|
const proc = this._proc;
|
|
78
87
|
this._proc = null;
|
|
@@ -87,7 +96,6 @@ export class MCPClient {
|
|
|
87
96
|
}, 2000);
|
|
88
97
|
proc.once("exit", () => { clearTimeout(timer); resolve(); });
|
|
89
98
|
});
|
|
90
|
-
if (this._stderrStream) this._stderrStream.end();
|
|
91
99
|
this._failAll(new Error("MCPClient stopped"));
|
|
92
100
|
}
|
|
93
101
|
|
|
@@ -104,13 +112,24 @@ export class MCPClient {
|
|
|
104
112
|
resolve: (v) => { clearTimeout(timer); resolve(v); },
|
|
105
113
|
reject: (e) => { clearTimeout(timer); reject(e); },
|
|
106
114
|
});
|
|
107
|
-
this._send({ jsonrpc: "2.0", id, method, params })
|
|
115
|
+
this._send({ jsonrpc: "2.0", id, method, params }).catch((err) => {
|
|
116
|
+
const pending = this._pending.get(id);
|
|
117
|
+
if (!pending) return;
|
|
118
|
+
this._pending.delete(id);
|
|
119
|
+
pending.reject(err);
|
|
120
|
+
});
|
|
108
121
|
});
|
|
109
122
|
}
|
|
110
123
|
|
|
111
124
|
_send(msg) {
|
|
112
|
-
|
|
113
|
-
this.
|
|
125
|
+
const proc = this._proc;
|
|
126
|
+
if (this._failure) return Promise.reject(this._failure);
|
|
127
|
+
if (!proc || proc.stdin.destroyed || proc.stdin.writableEnded) {
|
|
128
|
+
return Promise.reject(new Error("MCPClient: server not running"));
|
|
129
|
+
}
|
|
130
|
+
return new Promise((resolve, reject) => {
|
|
131
|
+
proc.stdin.write(JSON.stringify(msg) + "\n", (err) => err ? reject(err) : resolve());
|
|
132
|
+
});
|
|
114
133
|
}
|
|
115
134
|
|
|
116
135
|
_onData(chunk) {
|
|
@@ -148,8 +167,15 @@ export class MCPClient {
|
|
|
148
167
|
// Otherwise: notification or unmatched response — drop it.
|
|
149
168
|
}
|
|
150
169
|
|
|
151
|
-
_onExit(code, signal) {
|
|
152
|
-
this.
|
|
170
|
+
_onExit(proc, code, signal) {
|
|
171
|
+
if (this._proc !== proc) return;
|
|
172
|
+
this._proc = null;
|
|
173
|
+
this._onError(new Error(`MCP server exited (code=${code}, signal=${signal})`));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
_onError(err) {
|
|
177
|
+
this._failure ??= err;
|
|
178
|
+
this._failAll(this._failure);
|
|
153
179
|
}
|
|
154
180
|
|
|
155
181
|
_failAll(err) {
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
|
|
5
|
+
const REGISTRY_URL = "https://registry.npmjs.org/@mcpbox/mcpbox-claude";
|
|
6
|
+
const DEFAULT_TTL_MS = 24 * 60 * 60 * 1000;
|
|
7
|
+
const FAILED_TTL_MS = 60 * 60 * 1000;
|
|
8
|
+
const DEFAULT_TIMEOUT_MS = 1000;
|
|
9
|
+
|
|
10
|
+
export function compareVersions(left, right) {
|
|
11
|
+
const clean = (value) => String(value).split("-")[0];
|
|
12
|
+
const a = clean(left);
|
|
13
|
+
const b = clean(right);
|
|
14
|
+
if (!/^\d+(?:\.\d+)*$/.test(a) || !/^\d+(?:\.\d+)*$/.test(b)) return null;
|
|
15
|
+
const leftSegments = a.split(".").map(Number);
|
|
16
|
+
const rightSegments = b.split(".").map(Number);
|
|
17
|
+
for (let i = 0; i < Math.max(leftSegments.length, rightSegments.length); i += 1) {
|
|
18
|
+
const difference = (leftSegments[i] ?? 0) - (rightSegments[i] ?? 0);
|
|
19
|
+
if (difference) return difference;
|
|
20
|
+
}
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function checkForUpdate({
|
|
25
|
+
current,
|
|
26
|
+
home = homedir(),
|
|
27
|
+
ttlMs = DEFAULT_TTL_MS,
|
|
28
|
+
timeoutMs = DEFAULT_TIMEOUT_MS,
|
|
29
|
+
} = {}) {
|
|
30
|
+
if (process.env.MCPBOX_NO_UPDATE_CHECK) return null;
|
|
31
|
+
const cacheFile = join(home, ".agents", "mcpbox", "update-check.json");
|
|
32
|
+
/** @type {{ checkedAt?: number, failedAt?: number, latest?: string } | null} */
|
|
33
|
+
let cached = null;
|
|
34
|
+
try {
|
|
35
|
+
try {
|
|
36
|
+
cached = JSON.parse(await readFile(cacheFile, "utf8"));
|
|
37
|
+
} catch { /* missing or invalid cache — check the registry */ }
|
|
38
|
+
|
|
39
|
+
if (
|
|
40
|
+
typeof cached?.latest === "string"
|
|
41
|
+
&& Number.isFinite(cached?.checkedAt)
|
|
42
|
+
&& Date.now() - cached.checkedAt < ttlMs
|
|
43
|
+
) {
|
|
44
|
+
const comparison = compareVersions(current, cached.latest);
|
|
45
|
+
return comparison === null
|
|
46
|
+
? null
|
|
47
|
+
: { current, latest: cached.latest, outdated: comparison < 0 };
|
|
48
|
+
}
|
|
49
|
+
if (Number.isFinite(cached?.failedAt) && Date.now() - cached.failedAt < FAILED_TTL_MS) return null;
|
|
50
|
+
|
|
51
|
+
const response = await fetch(REGISTRY_URL, {
|
|
52
|
+
headers: { Accept: "application/vnd.npm.install-v1+json" },
|
|
53
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
54
|
+
});
|
|
55
|
+
if (!response.ok) throw new Error(`registry returned ${response.status}`);
|
|
56
|
+
const latest = (await response.json())?.["dist-tags"]?.latest;
|
|
57
|
+
const comparison = compareVersions(current, latest);
|
|
58
|
+
if (typeof latest !== "string" || comparison === null) throw new Error("invalid registry version");
|
|
59
|
+
await writeCache(cacheFile, { checkedAt: Date.now(), latest }).catch(() => {});
|
|
60
|
+
return { current, latest, outdated: comparison < 0 };
|
|
61
|
+
} catch {
|
|
62
|
+
await writeCache(cacheFile, { ...(cached ?? {}), failedAt: Date.now() }).catch(() => {});
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function writeCache(cacheFile, value) {
|
|
68
|
+
await mkdir(dirname(cacheFile), { recursive: true });
|
|
69
|
+
await writeFile(cacheFile, `${JSON.stringify(value)}\n`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const UPDATE_COMMANDS = Object.assign(Object.create(null), {
|
|
73
|
+
claude: "npx -y @mcpbox/mcpbox-claude@latest export-marketplace && claude plugin marketplace update mcpbox",
|
|
74
|
+
codex: "npx -y @mcpbox/mcpbox-claude@latest export-marketplace && codex plugin add mcpbox --marketplace mcpbox",
|
|
75
|
+
kimi: "npx -y @mcpbox/mcpbox-claude@latest kimi-init",
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
export function updateNotice(current, latest, surface) {
|
|
79
|
+
const command = UPDATE_COMMANDS[surface] ?? "npx -y @mcpbox/mcpbox-claude@latest";
|
|
80
|
+
return `mcpbox ${current} → ${latest}.\nОбновить: ${command}`;
|
|
81
|
+
}
|
package/lib/version.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const VERSION = "0.1.14";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcpbox/mcpbox-claude",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
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": {
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"node": ">=20"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
|
-
"test": "node --test tests/*.test.mjs"
|
|
27
|
+
"test": "node --test tests/*.test.mjs",
|
|
28
|
+
"version": "node scripts/sync-version.mjs && git add lib/version.mjs .claude-plugin/plugin.json .codex-plugin/plugin.json"
|
|
28
29
|
},
|
|
29
30
|
"license": "UNLICENSED"
|
|
30
31
|
}
|