@mcpbox/mcpbox-claude 0.1.2 → 0.1.4

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.
@@ -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} 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.0",
4
+ "version": "0.1.4",
5
5
  "author": {
6
6
  "name": "tupical"
7
7
  },
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # @mcpbox/mcpbox-claude
2
2
 
3
- MCPBox agent harness for **Claude Code**, **Codex**, and **Cursor**. Wires the
4
- single canonical MCP server (`https://mcpbox.ru/v1/mcp` — the daruma tracker
5
- tools plus the platform pipeline `torii→satori→enma→yatagarasu→fujin→daruma`)
3
+ MCPBox agent harness for **Claude Code**, **Codex**, **Cursor**, and **Kimi Code**.
4
+ Wires the single canonical MCP server (`https://mcpbox.ru/v1/mcp` — the daruma
5
+ tracker tools plus the platform pipeline `torii→satori→enma→yatagarasu→fujin→daruma`)
6
6
  and drops a managed policy into each agent's native config file.
7
7
 
8
8
  Normally installed for you by `npx @mcpbox/mcpbox setup` (or
@@ -12,11 +12,26 @@ just the policy.
12
12
 
13
13
  ## What it manages
14
14
 
15
- | Agent | Policy surface | MCP server |
16
- |--------|----------------------------------------|-------------------------------------|
17
- | Claude | `CLAUDE.md` block + plugin (hooks, `/mcpbox:*`) | `claude mcp add` (`.mcp.json` / `~/.claude.json`) |
18
- | Codex | `AGENTS.md` block (`mcpbox:policy`) | `[mcp_servers.mcpbox]` in `~/.codex/config.toml` |
19
- | Cursor | `.cursor/rules/mcpbox-policy.mdc` (`alwaysApply`) | `mcpbox` entry in `.cursor/mcp.json` |
15
+ | Agent | Policy surface | MCP server | Hooks |
16
+ |--------|----------------------------------------|-------------------------------------|-------|
17
+ | Claude | `CLAUDE.md` block + plugin (hooks, `/mcpbox:*`) | `claude mcp add` (`.mcp.json` / `~/.claude.json`) | plugin `hooks.json` |
18
+ | Codex | `AGENTS.md` block (`mcpbox:policy`) | `[mcp_servers.mcpbox]` in `~/.codex/config.toml` | — |
19
+ | Cursor | `.cursor/rules/mcpbox-policy.mdc` + `/mcpbox-mode` | `mcpbox` entry in `.cursor/mcp.json` | — |
20
+ | Kimi | `AGENTS.md` block (`mcpbox:policy`) | `mcpbox` entry in `~/.kimi-code/mcp.json` | `[[hooks]]` block in `~/.kimi-code/config.toml` |
21
+
22
+ All four agents accept `mcpbox mode [off|lite|full]` through the managed
23
+ policy. Claude also exposes `/mcpbox:mode`, Cursor exposes `/mcpbox-mode`, and
24
+ the shared value lives in `~/.agents/mcpbox/mode`.
25
+
26
+ Kimi specifics:
27
+
28
+ - MCP and hooks are **user-level** (Kimi reads hooks only from
29
+ `~/.kimi-code/config.toml`; `$KIMI_CODE_HOME` is honored). One
30
+ `/mcp-config login mcpbox` OAuth then covers every project.
31
+ - The hook scripts (`SessionStart` task summary, `UserPromptSubmit` routing
32
+ hints, `Stop` auto-record nudge) are the same ones the Claude plugin ships;
33
+ `kimi-init` copies them into `~/.kimi-code/mcpbox/` so the config never
34
+ references an ephemeral npx cache path. `kimi-uninit` removes that directory.
20
35
 
21
36
  ## CLI
22
37
 
@@ -27,7 +42,11 @@ mcpbox-claude codex-init [--dir DIR] AGENTS.md policy + ~/.codex/config.toml
27
42
  mcpbox-claude codex-uninit [--dir DIR]
28
43
  mcpbox-claude cursor-init [--dir DIR] .cursor/rules policy + .cursor/mcp.json server.
29
44
  mcpbox-claude cursor-uninit [--dir DIR]
45
+ mcpbox-claude kimi-init [--dir DIR] AGENTS.md policy + ~/.kimi-code/mcp.json server
46
+ + ~/.kimi-code/config.toml [[hooks]].
47
+ mcpbox-claude kimi-uninit [--dir DIR]
30
48
  mcpbox-claude doctor [--json] Check the mcpbox MCP server + policy are wired.
49
+ mcpbox-claude mode [off|lite|full] Show or set the shared pipeline mode.
31
50
  ```
32
51
 
33
52
  All writes are idempotent and preserve surrounding hand-written content.
@@ -6,6 +6,7 @@
6
6
  // (daruma tracker + full pipeline). Idempotent.
7
7
  // mcpbox-claude uninit [--dir DIR] Remove the managed policy block.
8
8
  // mcpbox-claude doctor [--json] Check the mcpbox MCP server + policy are wired.
9
+ // mcpbox-claude mode [off|lite|full] Get/set pipeline strictness (raw-idea routing).
9
10
  // mcpbox-claude --version | --help
10
11
  //
11
12
  // ponytail: no orchestrator (start/team-from-plan) or self-update here — the
@@ -19,12 +20,19 @@ import { dirname, join, resolve } from "node:path";
19
20
  import { spawnSync } from "node:child_process";
20
21
  import { installPolicy, removePolicy, BEGIN } from "../lib/policy.mjs";
21
22
  import { installCodex, removeCodex, installCodexPolicy } from "../lib/codex.mjs";
22
- import { installCursor, removeCursor, installCursorRule } from "../lib/cursor.mjs";
23
+ import {
24
+ installCursor,
25
+ removeCursor,
26
+ installCursorRule,
27
+ installCursorModeCommand,
28
+ } from "../lib/cursor.mjs";
29
+ import { installKimi, removeKimi } from "../lib/kimi.mjs";
30
+ import { readMode, writeMode, MODES } from "../lib/mode.mjs";
23
31
 
24
32
  const __dirname = dirname(fileURLToPath(import.meta.url));
25
33
  const pkg = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf8"));
26
34
 
27
- const HELP = `mcpbox-claude v${pkg.version} — MCPBox agent harness (Claude / Codex / Cursor)
35
+ const HELP = `mcpbox-claude v${pkg.version} — MCPBox agent harness (Claude / Codex / Cursor / Kimi)
28
36
 
29
37
  Usage:
30
38
  mcpbox-claude init [--dir DIR] Write the managed CLAUDE.md policy block
@@ -36,7 +44,12 @@ Usage:
36
44
  mcpbox-claude cursor-init [--dir DIR] Write .cursor/rules/mcpbox-policy.mdc +
37
45
  .cursor/mcp.json mcpbox entry. Idempotent.
38
46
  mcpbox-claude cursor-uninit [--dir DIR]
47
+ mcpbox-claude kimi-init [--dir DIR] Write AGENTS.md policy + ~/.kimi-code/mcp.json
48
+ mcpbox entry + [[hooks]] in ~/.kimi-code/config.toml.
49
+ Idempotent.
50
+ mcpbox-claude kimi-uninit [--dir DIR]
39
51
  mcpbox-claude doctor [--json] Check the mcpbox MCP server + policy are wired.
52
+ mcpbox-claude mode [off|lite|full] Get/set pipeline strictness (how raw ideas route).
40
53
  mcpbox-claude --version | -v
41
54
  mcpbox-claude --help | -h
42
55
  `;
@@ -98,16 +111,34 @@ async function cmdCodexUninit(rest) {
98
111
 
99
112
  async function cmdCursorInit(rest) {
100
113
  const { projectDir } = parseDirFlag(rest);
101
- const { rule, mcp } = await installCursor({ projectDir });
114
+ const { rule, mcp, mode } = await installCursor({ projectDir });
102
115
  report(rule);
103
116
  report(mcp);
117
+ report(mode);
104
118
  }
105
119
 
106
120
  async function cmdCursorUninit(rest) {
107
121
  const { projectDir } = parseDirFlag(rest);
108
- const { rule, mcp } = await removeCursor({ projectDir });
122
+ const { rule, mcp, mode } = await removeCursor({ projectDir });
109
123
  report(rule);
110
124
  report(mcp);
125
+ report(mode);
126
+ }
127
+
128
+ async function cmdKimiInit(rest) {
129
+ const { projectDir } = parseDirFlag(rest);
130
+ const { policy, mcp, hooks } = await installKimi({ projectDir });
131
+ report(policy);
132
+ report(mcp);
133
+ report(hooks);
134
+ }
135
+
136
+ async function cmdKimiUninit(rest) {
137
+ const { projectDir } = parseDirFlag(rest);
138
+ const { policy, mcp, hooks } = await removeKimi({ projectDir });
139
+ report(policy);
140
+ report(mcp);
141
+ report(hooks);
111
142
  }
112
143
 
113
144
  // Policy-only variants — for callers (mcpbox-cli setup) that already own the
@@ -120,6 +151,7 @@ async function cmdCodexPolicy(rest) {
120
151
  async function cmdCursorPolicy(rest) {
121
152
  const { projectDir } = parseDirFlag(rest);
122
153
  report(await installCursorRule({ projectDir }));
154
+ report(await installCursorModeCommand({ projectDir }));
123
155
  }
124
156
 
125
157
  async function policyPresent(projectDir) {
@@ -139,6 +171,16 @@ function mcpServerPresent() {
139
171
  return /(^|\n)\s*mcpbox\b/.test(r.stdout);
140
172
  }
141
173
 
174
+ async function cmdMode(rest) {
175
+ const [arg] = rest;
176
+ if (!arg || arg === "--show") {
177
+ process.stdout.write(`mcpbox pipeline mode: ${readMode()} (${MODES.join(" | ")})\n`);
178
+ return;
179
+ }
180
+ const m = await writeMode(arg); // throws on invalid → caught by main().catch
181
+ process.stdout.write(`✓ mcpbox pipeline mode: ${m}\n`);
182
+ }
183
+
142
184
  async function cmdDoctor(rest) {
143
185
  const json = rest.includes("--json");
144
186
  const flags = rest.filter((a) => a !== "--json");
@@ -186,12 +228,18 @@ async function main(argv) {
186
228
  return cmdCursorInit(rest);
187
229
  case "cursor-uninit":
188
230
  return cmdCursorUninit(rest);
231
+ case "kimi-init":
232
+ return cmdKimiInit(rest);
233
+ case "kimi-uninit":
234
+ return cmdKimiUninit(rest);
189
235
  case "codex-policy":
190
236
  return cmdCodexPolicy(rest);
191
237
  case "cursor-policy":
192
238
  return cmdCursorPolicy(rest);
193
239
  case "doctor":
194
240
  return cmdDoctor(rest);
241
+ case "mode":
242
+ return cmdMode(rest);
195
243
  default:
196
244
  process.stderr.write(`Unknown command: ${cmd}\n\n${HELP}`);
197
245
  process.exit(2);
@@ -0,0 +1,26 @@
1
+ ---
2
+ description: Set how strictly raw ideas route through the mcpbox maturity pipeline (off | lite | full).
3
+ ---
4
+
5
+ The user invoked `/mcpbox:mode` with `$ARGUMENTS` = `off` | `lite` | `full` (empty → show current).
6
+
7
+ ## What each level does
8
+
9
+ - **off** — no pipeline nudging. Treat every request as direct daruma task tracking.
10
+ - **lite** (default) — nudge toward the pipeline only when the input explicitly mentions it
11
+ (pipeline / maturity / handoff / конвейер …).
12
+ - **full** — assess every substantive request for **rawness**. A raw idea, hypothesis, or
13
+ undecided direction matures through the pipeline (`mcpbox_pipeline_run` → …fujin → handoff)
14
+ before any daruma task; a concrete, bounded task goes straight to daruma.
15
+
16
+ The level persists across sessions (stored in `~/.agents/mcpbox/mode`) and is read by the
17
+ UserPromptSubmit hook, which injects the matching reminder on each prompt.
18
+
19
+ ## Steps
20
+
21
+ 1. Run:
22
+ - Claude plugin: `node "${CLAUDE_PLUGIN_ROOT}/bin/mcpbox-claude.mjs" mode $ARGUMENTS`
23
+ - Other agents: `npx -y @mcpbox/mcpbox-claude@latest mode $ARGUMENTS`
24
+ - empty `$ARGUMENTS` → prints the current mode.
25
+ - invalid value → the CLI errors with the allowed set (`off | lite | full`); relay it verbatim.
26
+ 2. Report the resulting mode in one line.
@@ -1,17 +1,22 @@
1
1
  #!/usr/bin/env node
2
2
  // UserPromptSubmit hook: detect capture / sync / status / close / pipeline
3
- // intent in the user's prompt and prepend a short routing hint so Claude routes
4
- // to the right slash command rather than improvising.
3
+ // intent in the user's prompt and prepend a short routing hint so the agent
4
+ // routes to the right slash command rather than improvising.
5
5
  //
6
- // Output goes to stdout — Claude Code injects it as a <system-reminder>.
7
- // Exit 0 always; this hook must never block a prompt from being submitted.
6
+ // Output goes to stdout — Claude Code injects it as a <system-reminder>; Kimi
7
+ // Code appends it to the context on exit 0. Exit 0 always; this hook must
8
+ // never block a prompt from being submitted.
8
9
  //
9
- // Reads the prompt text from CLAUDE_USER_PROMPT env var (set by Claude Code).
10
+ // Prompt source: CLAUDE_USER_PROMPT env var (Claude Code); otherwise the hook
11
+ // event JSON on stdin (Kimi Code passes the payload via stdin, and so does
12
+ // Claude Code — this also covers Claude setups without the env var).
10
13
 
11
14
  import { pathToFileURL } from "node:url";
15
+ import { readMode } from "../lib/mode.mjs";
12
16
 
13
17
  // Intent patterns. Order matters — first match wins. ASCII keywords use \b;
14
18
  // Cyrillic uses whitespace/edge guards since \b is ASCII-only.
19
+ // PATTERNS[0] is the pipeline pattern — mode "off" drops it (see promptSubmitHint).
15
20
  const PATTERNS = [
16
21
  {
17
22
  re: /\b(pipeline|maturity|handoff|action\s*packet)\b|(?<![а-яёА-ЯЁ])(пайплайн|конвейер|зрелость|хендофф)(?![а-яёА-ЯЁ])/,
@@ -44,19 +49,70 @@ const PATTERNS = [
44
49
  },
45
50
  ];
46
51
 
47
- export function promptSubmitHint(promptText = "") {
52
+ // full mode: remind the agent to judge rawness itself — a regex can't. Only
53
+ // fires on substantive prompts that didn't already match an explicit intent.
54
+ const FULL_ASSESS_HINT =
55
+ "[mcpbox:full] Assess this request for rawness before acting: a raw idea / hypothesis / undecided direction matures through the pipeline (mcpbox_pipeline_run → …fujin → handoff) before any daruma task; a concrete, bounded task goes straight to daruma.";
56
+
57
+ // ponytail: length heuristic for "substantive" — cheap and good enough to skip
58
+ // "ok"/"yes"/"go". Swap for a token/keyword check only if it nags in practice.
59
+ const SUBSTANTIVE_MIN = 40;
60
+
61
+ export function promptSubmitHint(promptText = "", mode = "lite") {
48
62
  // Strip fenced code blocks so a keyword pasted inside ``` … ``` doesn't
49
63
  // trigger a routing hint (OMC-style false-positive guard, kept minimal —
50
64
  // these hints are low-stakes suggestions, not mode activation).
51
65
  const prompt = promptText.replace(/```[\s\S]*?```/g, " ").toLowerCase().trim();
52
- for (const { re, hint } of PATTERNS) {
66
+ const patterns = mode === "off" ? PATTERNS.slice(1) : PATTERNS;
67
+ for (const { re, hint } of patterns) {
53
68
  if (re.test(prompt)) return hint;
54
69
  }
70
+ if (mode === "full" && prompt.length >= SUBSTANTIVE_MIN) return FULL_ASSESS_HINT;
55
71
  return "";
56
72
  }
57
73
 
58
- function main() {
59
- const hint = promptSubmitHint(process.env.CLAUDE_USER_PROMPT ?? "");
74
+ // Reads stdin to EOF with a timeout so a hook caller that keeps stdin open
75
+ // can never hang the prompt submit path.
76
+ function readStdin(timeoutMs = 3000) {
77
+ return new Promise((resolve) => {
78
+ if (process.stdin.isTTY) return resolve("");
79
+ let raw = "";
80
+ const done = () => {
81
+ clearTimeout(timer);
82
+ resolve(raw);
83
+ };
84
+ const timer = setTimeout(() => {
85
+ process.stdin.destroy();
86
+ resolve(raw);
87
+ }, timeoutMs);
88
+ process.stdin.setEncoding("utf8");
89
+ process.stdin.on("data", (chunk) => { raw += chunk; });
90
+ process.stdin.on("end", done);
91
+ process.stdin.on("error", done);
92
+ });
93
+ }
94
+
95
+ // Kimi's UserPromptSubmit payload carries the prompt text; the exact field
96
+ // name is not documented, so accept the common shapes.
97
+ export function promptFromHookPayload(payload) {
98
+ if (!payload || typeof payload !== "object") return "";
99
+ for (const key of ["prompt", "user_prompt", "userPrompt", "message", "text"]) {
100
+ if (typeof payload[key] === "string" && payload[key].trim()) return payload[key];
101
+ }
102
+ return "";
103
+ }
104
+
105
+ async function main() {
106
+ let prompt = process.env.CLAUDE_USER_PROMPT ?? "";
107
+ if (!prompt) {
108
+ const raw = await readStdin();
109
+ if (raw.trim()) {
110
+ try {
111
+ prompt = promptFromHookPayload(JSON.parse(raw));
112
+ } catch { /* not JSON — no prompt to route */ }
113
+ }
114
+ }
115
+ const hint = promptSubmitHint(prompt, readMode());
60
116
  if (hint) process.stdout.write(hint + "\n");
61
117
  }
62
118
 
package/lib/cursor.mjs CHANGED
@@ -9,6 +9,7 @@
9
9
 
10
10
  import { promises as fs } from "node:fs";
11
11
  import { dirname, join, resolve } from "node:path";
12
+ import { fileURLToPath } from "node:url";
12
13
  import { BLOCK_BODY, MCP_URL } from "./policy.mjs";
13
14
 
14
15
  const RULE_FRONTMATTER = `---
@@ -34,6 +35,38 @@ function mcpPath(projectDir) {
34
35
  }
35
36
 
36
37
  const MCP_ENTRY = { type: "http", url: MCP_URL };
38
+ const MODE_COMMAND_SOURCE = join(dirname(fileURLToPath(import.meta.url)), "..", "commands", "mode.md");
39
+
40
+ function modeCommandPath(projectDir) {
41
+ const dir = projectDir ? resolve(projectDir) : process.cwd();
42
+ return join(dir, ".cursor", "commands", "mcpbox-mode.md");
43
+ }
44
+
45
+ export async function installCursorModeCommand({ projectDir } = {}) {
46
+ const target = modeCommandPath(projectDir);
47
+ const content = await fs.readFile(MODE_COMMAND_SOURCE, "utf8");
48
+ await fs.mkdir(dirname(target), { recursive: true });
49
+ let existing = null;
50
+ try {
51
+ existing = await fs.readFile(target, "utf8");
52
+ } catch (err) {
53
+ if (err.code !== "ENOENT") throw err;
54
+ }
55
+ if (existing === content) return { action: "unchanged", path: target };
56
+ await fs.writeFile(target, content);
57
+ return { action: existing === null ? "installed" : "updated", path: target };
58
+ }
59
+
60
+ export async function removeCursorModeCommand({ projectDir } = {}) {
61
+ const target = modeCommandPath(projectDir);
62
+ try {
63
+ await fs.unlink(target);
64
+ return { action: "removed-file", path: target };
65
+ } catch (err) {
66
+ if (err.code === "ENOENT") return { action: "missing", path: target };
67
+ throw err;
68
+ }
69
+ }
37
70
 
38
71
  // `.cursor/rules/mcpbox-policy.mdc` — whole-file managed rule.
39
72
  export async function installCursorRule({ projectDir } = {}) {
@@ -109,13 +142,15 @@ export async function removeCursorMcp({ projectDir } = {}) {
109
142
  export async function installCursor({ projectDir } = {}) {
110
143
  const rule = await installCursorRule({ projectDir });
111
144
  const mcp = await installCursorMcp({ projectDir });
112
- return { rule, mcp };
145
+ const mode = await installCursorModeCommand({ projectDir });
146
+ return { rule, mcp, mode };
113
147
  }
114
148
 
115
149
  export async function removeCursor({ projectDir } = {}) {
116
150
  const rule = await removeCursorRule({ projectDir });
117
151
  const mcp = await removeCursorMcp({ projectDir });
118
- return { rule, mcp };
152
+ const mode = await removeCursorModeCommand({ projectDir });
153
+ return { rule, mcp, mode };
119
154
  }
120
155
 
121
- export { rulePath, mcpPath };
156
+ export { rulePath, mcpPath, modeCommandPath };
package/lib/kimi.mjs ADDED
@@ -0,0 +1,192 @@
1
+ // Kimi Code CLI surface for the mcpbox harness — parity with the Claude
2
+ // CLAUDE.md plugin and the Codex AGENTS.md surface. Three idempotent writes:
3
+ // 1. AGENTS.md policy block (Kimi reads AGENTS.md every session in the
4
+ // workspace) — same managed block as the Codex surface.
5
+ // 2. `$KIMI_CODE_HOME/mcp.json` (default `~/.kimi-code/mcp.json`) — upsert
6
+ // the `mcpbox` HTTP server entry, preserving other servers. A bare `url`
7
+ // entry means HTTP transport in Kimi. User-level on purpose: one server
8
+ // entry (and one `/mcp-config login mcpbox` OAuth) covers every project.
9
+ // 3. `$KIMI_CODE_HOME/config.toml` — managed `[[hooks]]` block pointing at
10
+ // the hook scripts copied into `$KIMI_CODE_HOME/mcpbox/`. Kimi reads
11
+ // hooks only from the user-level config.toml (no project-level hooks),
12
+ // so — like the Codex MCP entry — the block is fenced with comment
13
+ // markers and replaced in place; surrounding hand-written TOML is
14
+ // preserved.
15
+ //
16
+ // The policy body is BLOCK_BODY from lib/policy.mjs — one source of truth
17
+ // shared across CLAUDE.md / AGENTS.md / .cursor/rules.
18
+ //
19
+ // Hook semantics in Kimi (https://www.kimi.com/code/docs/en/kimi-code-cli/customization/hooks.html):
20
+ // stdin carries the event JSON; exit 0 + stdout appends text to the context;
21
+ // SessionStart/UserPromptSubmit/Stop all exist. The hook scripts are the same
22
+ // ones the Claude plugin ships (hooks/), copied into the Kimi home so the
23
+ // config never references an ephemeral npx cache path.
24
+
25
+ import { promises as fs } from "node:fs";
26
+ import { homedir } from "node:os";
27
+ import { dirname, join, resolve } from "node:path";
28
+ import { fileURLToPath } from "node:url";
29
+ import {
30
+ BLOCK_BODY,
31
+ MCP_URL,
32
+ installManagedBlock,
33
+ removeManagedBlock,
34
+ } from "./policy.mjs";
35
+
36
+ const BEGIN = "<!-- mcpbox:policy:begin -->";
37
+ const END = "<!-- mcpbox:policy:end -->";
38
+
39
+ const TOML_BEGIN = "# mcpbox:hooks:begin";
40
+ const TOML_END = "# mcpbox:hooks:end";
41
+
42
+ // Hook assets copied into the Kimi home: the three hook scripts plus the
43
+ // stdio MCP client session-start.mjs imports (../lib/mcp-client.mjs).
44
+ const HOOK_ASSETS = [
45
+ ["hooks", "session-start.mjs"],
46
+ ["hooks", "user-prompt-submit.mjs"],
47
+ ["hooks", "stop.mjs"],
48
+ ["lib", "mcp-client.mjs"],
49
+ ["lib", "mode.mjs"],
50
+ ];
51
+
52
+ const MCP_ENTRY = { url: MCP_URL };
53
+
54
+ function packageRoot() {
55
+ return resolve(dirname(fileURLToPath(import.meta.url)), "..");
56
+ }
57
+
58
+ // Kimi data dir: explicit override (tests) > $KIMI_CODE_HOME > ~/.kimi-code.
59
+ export function kimiHomeDir(home) {
60
+ if (home) return resolve(home);
61
+ const env = process.env.KIMI_CODE_HOME?.trim();
62
+ if (env) return env;
63
+ return join(homedir(), ".kimi-code");
64
+ }
65
+
66
+ // --- 1. AGENTS.md policy block in the project directory ---
67
+
68
+ export function installKimiPolicy({ projectDir } = {}) {
69
+ const dir = projectDir ? resolve(projectDir) : process.cwd();
70
+ return installManagedBlock({ target: join(dir, "AGENTS.md"), begin: BEGIN, end: END, block: BLOCK_BODY });
71
+ }
72
+
73
+ export function removeKimiPolicy({ projectDir } = {}) {
74
+ const dir = projectDir ? resolve(projectDir) : process.cwd();
75
+ return removeManagedBlock({ target: join(dir, "AGENTS.md"), begin: BEGIN, end: END });
76
+ }
77
+
78
+ // --- 2. `mcpbox` entry in the user-level mcp.json ---
79
+
80
+ async function readMcp(target) {
81
+ try {
82
+ const doc = JSON.parse(await fs.readFile(target, "utf8"));
83
+ if (!doc || typeof doc !== "object" || Array.isArray(doc)) {
84
+ throw new Error(`${target} is not a JSON object`);
85
+ }
86
+ if (!doc.mcpServers || typeof doc.mcpServers !== "object") doc.mcpServers = {};
87
+ return doc;
88
+ } catch (err) {
89
+ if (err.code === "ENOENT") return { mcpServers: {} };
90
+ throw err;
91
+ }
92
+ }
93
+
94
+ export async function installKimiMcp({ mcpPath, kimiHome } = {}) {
95
+ const target = mcpPath ? resolve(mcpPath) : join(kimiHomeDir(kimiHome), "mcp.json");
96
+ const doc = await readMcp(target);
97
+ const before = doc.mcpServers.mcpbox;
98
+ if (before && JSON.stringify(before) === JSON.stringify(MCP_ENTRY)) {
99
+ return { action: "unchanged", path: target };
100
+ }
101
+ doc.mcpServers.mcpbox = MCP_ENTRY;
102
+ await fs.mkdir(dirname(target), { recursive: true });
103
+ await fs.writeFile(target, JSON.stringify(doc, null, 2) + "\n");
104
+ return { action: before ? "updated" : "installed", path: target };
105
+ }
106
+
107
+ export async function removeKimiMcp({ mcpPath, kimiHome } = {}) {
108
+ const target = mcpPath ? resolve(mcpPath) : join(kimiHomeDir(kimiHome), "mcp.json");
109
+ let doc;
110
+ try {
111
+ doc = await readMcp(target);
112
+ } catch (err) {
113
+ if (err.code === "ENOENT") return { action: "missing", path: target };
114
+ throw err;
115
+ }
116
+ if (!doc.mcpServers.mcpbox) return { action: "missing", path: target };
117
+ delete doc.mcpServers.mcpbox;
118
+ await fs.writeFile(target, JSON.stringify(doc, null, 2) + "\n");
119
+ return { action: "removed-block", path: target };
120
+ }
121
+
122
+ // --- 3. Hooks: copied scripts + managed [[hooks]] block in config.toml ---
123
+
124
+ // TOML literal strings (single quotes) keep absolute paths with spaces or
125
+ // backslashes intact without escaping.
126
+ function hooksTomlBlock(assetsRoot) {
127
+ const command = (file) => `command = 'node "${join(assetsRoot, "hooks", file)}"'`;
128
+ return [
129
+ "[[hooks]]",
130
+ 'event = "SessionStart"',
131
+ command("session-start.mjs"),
132
+ "timeout = 15",
133
+ "",
134
+ "[[hooks]]",
135
+ 'event = "UserPromptSubmit"',
136
+ command("user-prompt-submit.mjs"),
137
+ "",
138
+ "[[hooks]]",
139
+ 'event = "Stop"',
140
+ command("stop.mjs"),
141
+ "",
142
+ ].join("\n");
143
+ }
144
+
145
+ async function copyHookAssets(assetsRoot) {
146
+ for (const [subdir, file] of HOOK_ASSETS) {
147
+ const target = join(assetsRoot, subdir, file);
148
+ await fs.mkdir(dirname(target), { recursive: true });
149
+ await fs.copyFile(join(packageRoot(), subdir, file), target);
150
+ }
151
+ }
152
+
153
+ export async function installKimiHooks({ configPath, kimiHome } = {}) {
154
+ const home = kimiHomeDir(kimiHome);
155
+ const assetsRoot = join(home, "mcpbox");
156
+ await copyHookAssets(assetsRoot);
157
+ const target = configPath ? resolve(configPath) : join(home, "config.toml");
158
+ return installManagedBlock({
159
+ target,
160
+ begin: TOML_BEGIN,
161
+ end: TOML_END,
162
+ block: hooksTomlBlock(assetsRoot),
163
+ });
164
+ }
165
+
166
+ export async function removeKimiHooks({ configPath, kimiHome } = {}) {
167
+ const home = kimiHomeDir(kimiHome);
168
+ const target = configPath ? resolve(configPath) : join(home, "config.toml");
169
+ const block = await removeManagedBlock({ target, begin: TOML_BEGIN, end: TOML_END });
170
+ // The assets dir is ours (namespaced `mcpbox` under the Kimi home) — drop it.
171
+ const assetsRoot = join(home, "mcpbox");
172
+ await fs.rm(assetsRoot, { recursive: true, force: true });
173
+ return block;
174
+ }
175
+
176
+ // --- All three surfaces at once (what `mcpbox-claude kimi-init` calls) ---
177
+
178
+ export async function installKimi({ projectDir, kimiHome } = {}) {
179
+ const policy = await installKimiPolicy({ projectDir });
180
+ const mcp = await installKimiMcp({ kimiHome });
181
+ const hooks = await installKimiHooks({ kimiHome });
182
+ return { policy, mcp, hooks };
183
+ }
184
+
185
+ export async function removeKimi({ projectDir, kimiHome } = {}) {
186
+ const policy = await removeKimiPolicy({ projectDir });
187
+ const mcp = await removeKimiMcp({ kimiHome });
188
+ const hooks = await removeKimiHooks({ kimiHome });
189
+ return { policy, mcp, hooks };
190
+ }
191
+
192
+ export { BEGIN, END, TOML_BEGIN, TOML_END };
package/lib/mode.mjs ADDED
@@ -0,0 +1,44 @@
1
+ // Pipeline strictness mode: how aggressively raw ideas get routed through the
2
+ // mcpbox maturity pipeline (torii→…→fujin→handoff) vs. tracked directly in daruma.
3
+ //
4
+ // off — no pipeline nudging; every request is treated as direct daruma work.
5
+ // lite — nudge toward the pipeline only when the input explicitly mentions it. (default)
6
+ // full — remind the agent to assess every substantive request for "rawness":
7
+ // raw ideas mature through the pipeline; concrete bounded tasks go to daruma.
8
+ //
9
+ // The `mcpbox-claude mode` CLI writes it; hooks and the shared agent policy
10
+ // read it. The old Claude-only file remains a read fallback for upgrades.
11
+
12
+ import { promises as fs, readFileSync } from "node:fs";
13
+ import { homedir } from "node:os";
14
+ import { dirname, join } from "node:path";
15
+
16
+ export const MODES = ["off", "lite", "full"];
17
+ export const DEFAULT_MODE = "lite";
18
+
19
+ // ponytail: one shared file for every agent. Key it on cwd only if per-repo
20
+ // strictness is ever needed.
21
+ export const modeFile = (home = homedir()) => join(home, ".agents", "mcpbox", "mode");
22
+ const legacyModeFile = (home = homedir()) => join(home, ".claude", "mcpbox-mode");
23
+
24
+ export function readMode(home = homedir()) {
25
+ for (const file of [modeFile(home), legacyModeFile(home)]) {
26
+ try {
27
+ const v = readFileSync(file, "utf8").trim();
28
+ if (MODES.includes(v)) return v;
29
+ } catch {
30
+ // missing / unreadable → try the legacy file, then default
31
+ }
32
+ }
33
+ return DEFAULT_MODE;
34
+ }
35
+
36
+ export async function writeMode(mode, home = homedir()) {
37
+ if (!MODES.includes(mode)) {
38
+ throw new Error(`invalid mode "${mode}" — want one of: ${MODES.join(" | ")}`);
39
+ }
40
+ const file = modeFile(home);
41
+ await fs.mkdir(dirname(file), { recursive: true });
42
+ await fs.writeFile(file, mode + "\n");
43
+ return mode;
44
+ }
package/lib/policy.mjs CHANGED
@@ -158,6 +158,23 @@ rule is enforced by the **server**: each layer takes only the persisted output
158
158
  of the previous layer (except \`torii\`), and skipping a layer or targeting
159
159
  \`torii\` returns \`422\`. The agent cannot invent a layer's input.
160
160
 
161
+ ### Pipeline mode
162
+
163
+ The shared mode is stored in \`~/.agents/mcpbox/mode\` (missing means
164
+ \`lite\`) and applies to Claude, Codex, Cursor, and Kimi:
165
+
166
+ - \`off\` — never nudge toward the pipeline.
167
+ - \`lite\` — use it only when the request explicitly asks for pipeline,
168
+ maturity, handoff, or «конвейер».
169
+ - \`full\` — assess every substantive request for rawness; raw ideas go
170
+ through the pipeline, concrete bounded work goes directly to daruma.
171
+
172
+ Before routing a substantive request, read and honor that file. If the user
173
+ enters \`mcpbox mode\` or \`mcpbox mode off|lite|full\`, run
174
+ \`npx -y @mcpbox/mcpbox-claude@latest mode [value]\` and report its one-line
175
+ result. Do not confuse this pipeline mode with the daruma cloud/self-host
176
+ profile.
177
+
161
178
  ### Maturity route
162
179
 
163
180
  \`\`\`
@@ -220,6 +237,7 @@ daruma execution задача/план (терминальный слой
220
237
  - \`/mcpbox:next\` — claim the next ready task.
221
238
  - \`/mcpbox:mine\` — tasks claimed by this session.
222
239
  - \`/mcpbox:status\` — server + pipeline health (\`daruma_healthz\`, recent runs).
240
+ - \`mcpbox mode [off|lite|full]\` — show or set the shared pipeline mode.
223
241
  - \`/mcpbox:pipeline-run "<idea>"\` — open a maturity run from raw input.
224
242
  - \`/mcpbox:trace <run_id>\` — trace a run's lineage and per-hop status.
225
243
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcpbox/mcpbox-claude",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
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": {