@abraca/mcp 2.90.0 → 2.91.0
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/package.json +6 -12
- package/src/active-server.ts +0 -91
- package/src/converters/markdownToYjs.ts +0 -13
- package/src/converters/yjsToMarkdown.ts +0 -12
- package/src/hook-bridge.ts +0 -355
- package/src/index.ts +0 -305
- package/src/mentions.ts +0 -42
- package/src/resources/agent-guide.ts +0 -557
- package/src/resources/server-info.ts +0 -47
- package/src/resources/tree-resource.ts +0 -57
- package/src/schema/loader.ts +0 -139
- package/src/schema/validator.ts +0 -31
- package/src/server-manager.ts +0 -182
- package/src/server.ts +0 -1393
- package/src/tool-detail.ts +0 -147
- package/src/tools/awareness.ts +0 -159
- package/src/tools/channel.ts +0 -155
- package/src/tools/content.ts +0 -518
- package/src/tools/files.ts +0 -118
- package/src/tools/hooks.ts +0 -51
- package/src/tools/meta.ts +0 -98
- package/src/tools/servers.ts +0 -211
- package/src/tools/svg.ts +0 -80
- package/src/tools/tree.ts +0 -682
- package/src/utils/sanitizeSvg.ts +0 -71
- package/src/utils.ts +0 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abraca/mcp",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.91.0",
|
|
4
4
|
"description": "MCP server for Abracadabra — AI agent collaboration on CRDT documents",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,28 +14,22 @@
|
|
|
14
14
|
"access": "public"
|
|
15
15
|
},
|
|
16
16
|
"exports": {
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"default": {
|
|
21
|
-
"import": "./dist/abracadabra-mcp.esm.js",
|
|
22
|
-
"require": "./dist/abracadabra-mcp.cjs",
|
|
23
|
-
"types": "./dist/index.d.ts"
|
|
24
|
-
}
|
|
17
|
+
"import": "./dist/abracadabra-mcp.esm.js",
|
|
18
|
+
"require": "./dist/abracadabra-mcp.cjs",
|
|
19
|
+
"types": "./dist/index.d.ts"
|
|
25
20
|
},
|
|
26
21
|
"files": [
|
|
27
|
-
"src",
|
|
28
22
|
"dist"
|
|
29
23
|
],
|
|
30
24
|
"dependencies": {
|
|
31
|
-
"@abraca/dabra": "^2.
|
|
25
|
+
"@abraca/dabra": "^2.90.0",
|
|
32
26
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
33
27
|
"ajv": "^8.17.1",
|
|
34
28
|
"ajv-formats": "^3.0.1",
|
|
35
29
|
"y-protocols": "^1.0.6",
|
|
36
30
|
"yjs": "^13.6.8",
|
|
37
31
|
"zod": "^4.3.6",
|
|
38
|
-
"@abraca/convert": "2.
|
|
32
|
+
"@abraca/convert": "2.91.0"
|
|
39
33
|
},
|
|
40
34
|
"scripts": {
|
|
41
35
|
"test": "node --no-warnings --conditions=source --experimental-transform-types --test 'tests/*.test.ts'"
|
package/src/active-server.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* active-server — a late-binding forwarding proxy over the manager's *currently
|
|
3
|
-
* active* {@link AbracadabraMCPServer} connection.
|
|
4
|
-
*
|
|
5
|
-
* Tools and the hook-bridge capture a `server` reference once at registration.
|
|
6
|
-
* With multi-server support the active connection can change at runtime
|
|
7
|
-
* (`connect_server`/`switch_server`), so a fixed reference would go stale. This
|
|
8
|
-
* proxy forwards every access to `manager.active` at *call time*, so a single
|
|
9
|
-
* stable object behaves like "whatever server is active right now".
|
|
10
|
-
*
|
|
11
|
-
* When nothing is connected it forwards to {@link DISCONNECTED} — a safe stub
|
|
12
|
-
* that returns empty/null data, makes status/awareness calls no-ops (so the
|
|
13
|
-
* hook-bridge never throws), and reports "not found" for space resolution. The
|
|
14
|
-
* net effect is that every tool's existing `if (!rootProvider) return "Not
|
|
15
|
-
* connected"` guard fires naturally, and the agent is told to connect first.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import type { ServerManager } from "./server-manager.ts";
|
|
19
|
-
import type { AbracadabraMCPServer } from "./server.ts";
|
|
20
|
-
|
|
21
|
-
const NOT_CONNECTED =
|
|
22
|
-
"No server connected. Use connect_server (or list_servers) first.";
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Safe defaults used while no server is active. Mirrors the slice of the
|
|
26
|
-
* `AbracadabraMCPServer` surface that tools + the hook-bridge actually touch
|
|
27
|
-
* (see the `server.*` usage survey). Data getters/methods return empty/null so
|
|
28
|
-
* existing guards trip; void status methods no-op; genuine data ops that need a
|
|
29
|
-
* live connection throw a clear message.
|
|
30
|
-
*/
|
|
31
|
-
const DISCONNECTED: Record<string, unknown> = {
|
|
32
|
-
// ── plain getters ──
|
|
33
|
-
client: undefined,
|
|
34
|
-
serverInfo: null,
|
|
35
|
-
rootDocId: null,
|
|
36
|
-
rootDocument: null,
|
|
37
|
-
rootYProvider: null,
|
|
38
|
-
spaces: [],
|
|
39
|
-
userId: null,
|
|
40
|
-
agentName: "AI Assistant",
|
|
41
|
-
agentColor: "hsl(270, 80%, 60%)",
|
|
42
|
-
|
|
43
|
-
// ── data accessors (called as functions) ──
|
|
44
|
-
getTreeMap: () => null,
|
|
45
|
-
getTrashMap: () => null,
|
|
46
|
-
refreshSpaces: async () => [],
|
|
47
|
-
getDocSummary: () => null,
|
|
48
|
-
getEnabledPluginNames: () => [],
|
|
49
|
-
|
|
50
|
-
// ── fire-and-forget status / awareness (must not throw) ──
|
|
51
|
-
setActiveToolCall: () => {},
|
|
52
|
-
setAutoStatus: () => {},
|
|
53
|
-
setWritingStatus: () => {},
|
|
54
|
-
sendTypingIndicator: () => {},
|
|
55
|
-
recordToolDetail: () => {},
|
|
56
|
-
clearAiTask: () => {},
|
|
57
|
-
setFocusedDoc: () => {},
|
|
58
|
-
setDocCursor: () => {},
|
|
59
|
-
startChannelNotifications: () => {},
|
|
60
|
-
|
|
61
|
-
// ── ops that genuinely require a connection ──
|
|
62
|
-
ensureConnected: async () => {},
|
|
63
|
-
// Returning false makes space-resolution guards report "not found" rather
|
|
64
|
-
// than crashing — the tool then surfaces a friendly message.
|
|
65
|
-
ensureSpaceActive: async () => false,
|
|
66
|
-
getChildProvider: async () => {
|
|
67
|
-
throw new Error(NOT_CONNECTED);
|
|
68
|
-
},
|
|
69
|
-
switchSpace: async () => {
|
|
70
|
-
throw new Error(NOT_CONNECTED);
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Build the forwarding proxy. Pass this everywhere a tool/hook-bridge expects an
|
|
76
|
-
* `AbracadabraMCPServer`; it transparently tracks `manager.active`.
|
|
77
|
-
*/
|
|
78
|
-
export function createActiveServerProxy(
|
|
79
|
-
manager: ServerManager,
|
|
80
|
-
): AbracadabraMCPServer {
|
|
81
|
-
return new Proxy({} as AbracadabraMCPServer, {
|
|
82
|
-
get(_target, prop) {
|
|
83
|
-
const target: Record<string, unknown> =
|
|
84
|
-
(manager.active as unknown as Record<string, unknown>) ?? DISCONNECTED;
|
|
85
|
-
const value = target[prop as string];
|
|
86
|
-
return typeof value === "function"
|
|
87
|
-
? (value as (...a: unknown[]) => unknown).bind(target)
|
|
88
|
-
: value;
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// Thin re-export shim — markdown → Yjs conversion now lives in
|
|
2
|
-
// @abraca/convert (extracted from cou-sh + abracadabra-nuxt + this
|
|
3
|
-
// package). Existing imports inside the MCP server keep working
|
|
4
|
-
// through this re-export.
|
|
5
|
-
//
|
|
6
|
-
// New code should import from @abraca/convert directly.
|
|
7
|
-
|
|
8
|
-
export {
|
|
9
|
-
filenameToLabel,
|
|
10
|
-
parseFrontmatter,
|
|
11
|
-
populateYDocFromMarkdown,
|
|
12
|
-
type FrontmatterResult,
|
|
13
|
-
} from '@abraca/convert'
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// Thin re-export shim — Yjs → markdown conversion now lives in
|
|
2
|
-
// @abraca/convert (extracted from cou-sh + abracadabra-nuxt + this
|
|
3
|
-
// package). Existing imports inside the MCP server keep working
|
|
4
|
-
// through this re-export.
|
|
5
|
-
//
|
|
6
|
-
// New code should import from @abraca/convert directly.
|
|
7
|
-
|
|
8
|
-
export {
|
|
9
|
-
yjsToMarkdown,
|
|
10
|
-
yjsToHtml,
|
|
11
|
-
yjsToPlainText,
|
|
12
|
-
} from '@abraca/convert'
|
package/src/hook-bridge.ts
DELETED
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HookBridge — lightweight HTTP server that receives Claude Code hook events
|
|
3
|
-
* and translates them into Yjs awareness updates via AbracadabraMCPServer.
|
|
4
|
-
*
|
|
5
|
-
* Claude Code hooks (PreToolUse, PostToolUse, SubagentStart, SubagentStop, Stop)
|
|
6
|
-
* POST JSON to http://127.0.0.1:{port}/hook. The bridge maps these to awareness
|
|
7
|
-
* fields (status, activeToolCall) so the cou-sh dashboard shows real-time activity.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import * as fs from "node:fs";
|
|
11
|
-
import * as http from "node:http";
|
|
12
|
-
import * as os from "node:os";
|
|
13
|
-
import * as path from "node:path";
|
|
14
|
-
import type { AbracadabraMCPServer } from "./server.ts";
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Expandable detail shown when a tool card is clicked in the dashboard
|
|
18
|
-
* (mirrors the Claude CLI's inline tool views). Strings are capped so the
|
|
19
|
-
* awareness payload stays bounded.
|
|
20
|
-
*/
|
|
21
|
-
export type ToolDetail =
|
|
22
|
-
| { kind: "diff"; file?: string; old?: string; new?: string }
|
|
23
|
-
| { kind: "code"; file?: string; text?: string }
|
|
24
|
-
| { kind: "command"; text?: string }
|
|
25
|
-
| { kind: "text"; text?: string };
|
|
26
|
-
|
|
27
|
-
/** Per-field cap for detail strings (chars). Keeps awareness lean. */
|
|
28
|
-
const DETAIL_MAX = 4000;
|
|
29
|
-
|
|
30
|
-
function cap(s: string | undefined): string | undefined {
|
|
31
|
-
if (typeof s !== "string") return undefined;
|
|
32
|
-
return s.length > DETAIL_MAX ? `${s.slice(0, DETAIL_MAX)}\n… (truncated)` : s;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** Map Claude Code tool names to awareness-friendly names + target + detail. */
|
|
36
|
-
function mapToolCall(
|
|
37
|
-
toolName: string,
|
|
38
|
-
toolInput: Record<string, any>,
|
|
39
|
-
): { name: string; target?: string; detail?: ToolDetail } | null {
|
|
40
|
-
switch (toolName) {
|
|
41
|
-
case "Bash":
|
|
42
|
-
return {
|
|
43
|
-
name: "bash",
|
|
44
|
-
target: truncate(toolInput.command ?? toolInput.description, 60),
|
|
45
|
-
detail: { kind: "command", text: cap(toolInput.command) },
|
|
46
|
-
};
|
|
47
|
-
case "Read":
|
|
48
|
-
return {
|
|
49
|
-
name: "read_file",
|
|
50
|
-
target: basename(toolInput.file_path),
|
|
51
|
-
detail: { kind: "text", text: toolInput.file_path },
|
|
52
|
-
};
|
|
53
|
-
case "Edit": {
|
|
54
|
-
// Single-edit ({old_string,new_string}) or multi-edit ({edits:[…]}).
|
|
55
|
-
let oldText: string | undefined = toolInput.old_string;
|
|
56
|
-
let newText: string | undefined = toolInput.new_string;
|
|
57
|
-
if (!oldText && Array.isArray(toolInput.edits)) {
|
|
58
|
-
oldText = toolInput.edits
|
|
59
|
-
.map((e: any) => e?.old_string ?? "")
|
|
60
|
-
.join("\n");
|
|
61
|
-
newText = toolInput.edits
|
|
62
|
-
.map((e: any) => e?.new_string ?? "")
|
|
63
|
-
.join("\n");
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
name: "edit_file",
|
|
67
|
-
target: basename(toolInput.file_path),
|
|
68
|
-
detail: {
|
|
69
|
-
kind: "diff",
|
|
70
|
-
file: toolInput.file_path,
|
|
71
|
-
old: cap(oldText),
|
|
72
|
-
new: cap(newText),
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
case "Write":
|
|
77
|
-
return {
|
|
78
|
-
name: "write_file",
|
|
79
|
-
target: basename(toolInput.file_path),
|
|
80
|
-
detail: {
|
|
81
|
-
kind: "code",
|
|
82
|
-
file: toolInput.file_path,
|
|
83
|
-
text: cap(toolInput.content),
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
case "Grep":
|
|
87
|
-
return {
|
|
88
|
-
name: "grep",
|
|
89
|
-
target: truncate(toolInput.pattern, 40),
|
|
90
|
-
detail: { kind: "text", text: toolInput.pattern },
|
|
91
|
-
};
|
|
92
|
-
case "Glob":
|
|
93
|
-
return {
|
|
94
|
-
name: "glob",
|
|
95
|
-
target: truncate(toolInput.pattern, 40),
|
|
96
|
-
detail: { kind: "text", text: toolInput.pattern },
|
|
97
|
-
};
|
|
98
|
-
case "Agent":
|
|
99
|
-
return {
|
|
100
|
-
name: "subagent",
|
|
101
|
-
target: toolInput.description || toolInput.subagent_type || "agent",
|
|
102
|
-
detail: { kind: "text", text: cap(toolInput.prompt) },
|
|
103
|
-
};
|
|
104
|
-
case "WebFetch":
|
|
105
|
-
return {
|
|
106
|
-
name: "web_fetch",
|
|
107
|
-
target: hostname(toolInput.url),
|
|
108
|
-
detail: { kind: "text", text: toolInput.url },
|
|
109
|
-
};
|
|
110
|
-
case "WebSearch":
|
|
111
|
-
return {
|
|
112
|
-
name: "web_search",
|
|
113
|
-
target: truncate(toolInput.query, 40),
|
|
114
|
-
detail: { kind: "text", text: toolInput.query },
|
|
115
|
-
};
|
|
116
|
-
default:
|
|
117
|
-
// Unknown tool — use the name as-is, lowercased with underscores
|
|
118
|
-
return {
|
|
119
|
-
name: toolName.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase(),
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function truncate(str: string | undefined, max: number): string | undefined {
|
|
125
|
-
if (!str) return undefined;
|
|
126
|
-
return str.length > max ? str.slice(0, max) + "..." : str;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function basename(filePath: string | undefined): string | undefined {
|
|
130
|
-
if (!filePath) return undefined;
|
|
131
|
-
return path.basename(filePath);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function hostname(url: string | undefined): string | undefined {
|
|
135
|
-
if (!url) return undefined;
|
|
136
|
-
try {
|
|
137
|
-
return new URL(url).hostname;
|
|
138
|
-
} catch {
|
|
139
|
-
return url.slice(0, 30);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export class HookBridge {
|
|
144
|
-
private httpServer: http.Server | null = null;
|
|
145
|
-
private _port: number | null = null;
|
|
146
|
-
private portFilePath: string;
|
|
147
|
-
private portFileTimer: ReturnType<typeof setInterval> | null = null;
|
|
148
|
-
|
|
149
|
-
constructor(private server: AbracadabraMCPServer) {
|
|
150
|
-
// Stable, predictable path (NOT tmpdir) so the Claude Code hook command
|
|
151
|
-
// can read it without depending on a possibly-different $TMPDIR at hook
|
|
152
|
-
// execution time. Override with ABRA_HOOK_PORT_FILE if needed.
|
|
153
|
-
this.portFilePath =
|
|
154
|
-
process.env.ABRA_HOOK_PORT_FILE ||
|
|
155
|
-
path.join(os.homedir(), ".abracadabra-mcp-hook.port");
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
get port(): number | null {
|
|
159
|
-
return this._port;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/** Absolute path of the file the current listening port is written to. */
|
|
163
|
-
get portFile(): string {
|
|
164
|
-
return this.portFilePath;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/** Start the HTTP server on a random port and write the port file. */
|
|
168
|
-
async start(): Promise<number> {
|
|
169
|
-
return new Promise((resolve, reject) => {
|
|
170
|
-
const srv = http.createServer((req, res) => this.handleRequest(req, res));
|
|
171
|
-
|
|
172
|
-
srv.on("error", reject);
|
|
173
|
-
|
|
174
|
-
srv.listen(0, "127.0.0.1", () => {
|
|
175
|
-
const addr = srv.address();
|
|
176
|
-
if (!addr || typeof addr === "string") {
|
|
177
|
-
reject(new Error("Failed to get server address"));
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
this._port = addr.port;
|
|
182
|
-
this.httpServer = srv;
|
|
183
|
-
|
|
184
|
-
// Claim the shared port file, then re-assert it on an interval.
|
|
185
|
-
// Claude Code spawns this MCP server from .mcp.json for health
|
|
186
|
-
// checks; each transient spawn starts its OWN bridge on a fresh
|
|
187
|
-
// random port and overwrites (or, on exit, unlinks) the single
|
|
188
|
-
// shared port file — leaving the hook command pointing at a dead
|
|
189
|
-
// port. Periodically re-writing lets the long-lived serving
|
|
190
|
-
// instance reclaim the file within ~2s of any clobber, so the
|
|
191
|
-
// hook keeps resolving to a live bridge.
|
|
192
|
-
this.writePortFile();
|
|
193
|
-
this.portFileTimer = setInterval(() => this.writePortFile(), 2000);
|
|
194
|
-
this.portFileTimer.unref?.();
|
|
195
|
-
|
|
196
|
-
console.error(`[hook-bridge] Listening on 127.0.0.1:${this._port}`);
|
|
197
|
-
console.error(`[hook-bridge] Port file: ${this.portFilePath}`);
|
|
198
|
-
resolve(this._port);
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/** Write the current listening port to the shared port file (best-effort). */
|
|
204
|
-
private writePortFile(): void {
|
|
205
|
-
if (this._port == null) return;
|
|
206
|
-
try {
|
|
207
|
-
fs.writeFileSync(this.portFilePath, String(this._port), "utf-8");
|
|
208
|
-
} catch (err: any) {
|
|
209
|
-
console.error(
|
|
210
|
-
`[hook-bridge] Warning: could not write port file: ${err.message}`,
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/** Shut down the HTTP server and remove the port file. */
|
|
216
|
-
async destroy(): Promise<void> {
|
|
217
|
-
// Stop re-asserting the port file before we tear down.
|
|
218
|
-
if (this.portFileTimer) {
|
|
219
|
-
clearInterval(this.portFileTimer);
|
|
220
|
-
this.portFileTimer = null;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (this.httpServer) {
|
|
224
|
-
await new Promise<void>((resolve) => {
|
|
225
|
-
this.httpServer!.close(() => resolve());
|
|
226
|
-
});
|
|
227
|
-
this.httpServer = null;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// Only remove the port file if it still points at THIS instance — never
|
|
231
|
-
// clobber a newer/long-lived instance's registration. A transient
|
|
232
|
-
// health-check spawn that overwrote the file must not delete the real
|
|
233
|
-
// serving instance's port on the way out (see start() for why concurrent
|
|
234
|
-
// instances exist).
|
|
235
|
-
try {
|
|
236
|
-
const current = fs.readFileSync(this.portFilePath, "utf-8").trim();
|
|
237
|
-
if (current === String(this._port)) {
|
|
238
|
-
fs.unlinkSync(this.portFilePath);
|
|
239
|
-
}
|
|
240
|
-
} catch {
|
|
241
|
-
// Already gone or never written
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
this._port = null;
|
|
245
|
-
console.error("[hook-bridge] Shut down");
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
private handleRequest(
|
|
249
|
-
req: http.IncomingMessage,
|
|
250
|
-
res: http.ServerResponse,
|
|
251
|
-
): void {
|
|
252
|
-
// Only accept POST /hook
|
|
253
|
-
if (req.method !== "POST" || req.url !== "/hook") {
|
|
254
|
-
res.writeHead(404);
|
|
255
|
-
res.end();
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
let body = "";
|
|
260
|
-
req.on("data", (chunk: Buffer) => {
|
|
261
|
-
body += chunk.toString();
|
|
262
|
-
});
|
|
263
|
-
req.on("end", () => {
|
|
264
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
265
|
-
res.end("{}");
|
|
266
|
-
|
|
267
|
-
try {
|
|
268
|
-
const payload = JSON.parse(body);
|
|
269
|
-
this.routeEvent(payload);
|
|
270
|
-
} catch {
|
|
271
|
-
// Invalid JSON — ignore silently (fire-and-forget)
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
private routeEvent(payload: Record<string, any>): void {
|
|
277
|
-
const event = payload.hook_event_name;
|
|
278
|
-
switch (event) {
|
|
279
|
-
case "UserPromptSubmit":
|
|
280
|
-
this.onUserPromptSubmit();
|
|
281
|
-
break;
|
|
282
|
-
case "PreToolUse":
|
|
283
|
-
this.onPreToolUse(payload);
|
|
284
|
-
break;
|
|
285
|
-
case "PostToolUse":
|
|
286
|
-
this.onPostToolUse(payload);
|
|
287
|
-
break;
|
|
288
|
-
case "SubagentStart":
|
|
289
|
-
this.onSubagentStart(payload);
|
|
290
|
-
break;
|
|
291
|
-
case "SubagentStop":
|
|
292
|
-
this.onSubagentStop();
|
|
293
|
-
break;
|
|
294
|
-
case "Stop":
|
|
295
|
-
this.onStop();
|
|
296
|
-
break;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* UserPromptSubmit — intentionally a NO-OP for channel-driven turns.
|
|
302
|
-
*
|
|
303
|
-
* The MCP dispatch (`_beginTurn` + `setAutoStatus('thinking')`) runs FIRST
|
|
304
|
-
* when a channel message arrives, then the notification is injected into the
|
|
305
|
-
* Claude Code session, which fires THIS hook. If we cleared status/turn here
|
|
306
|
-
* we'd wipe the "thinking" turn the dispatch just set up — killing the
|
|
307
|
-
* incantation phrase AND the typing heartbeat. Each new turn already resets
|
|
308
|
-
* cleanly via `_beginTurn` (fresh turnId + empty toolHistory), so there's
|
|
309
|
-
* nothing to clear here.
|
|
310
|
-
*/
|
|
311
|
-
private onUserPromptSubmit(): void {
|
|
312
|
-
// no-op — see doc comment.
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
private onPreToolUse(payload: Record<string, any>): void {
|
|
316
|
-
const toolName: string = payload.tool_name ?? "";
|
|
317
|
-
// Skip Abracadabra MCP tools — they set awareness themselves
|
|
318
|
-
if (toolName.startsWith("mcp__abracadabra__")) return;
|
|
319
|
-
|
|
320
|
-
const toolInput = payload.tool_input ?? {};
|
|
321
|
-
const mapped = mapToolCall(toolName, toolInput);
|
|
322
|
-
if (mapped) {
|
|
323
|
-
this.server.setActiveToolCall(mapped);
|
|
324
|
-
this.server.setAutoStatus("working");
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
private onPostToolUse(payload: Record<string, any>): void {
|
|
329
|
-
// Clear the live tool pill for EVERY tool (native + MCP) when it
|
|
330
|
-
// finishes. This is what flips the inline card from running (spinner) →
|
|
331
|
-
// done (check) in the dashboard, and — because no tool is "active"
|
|
332
|
-
// between calls — lets the typing-dots show while Claude composes its
|
|
333
|
-
// reply. The completed call stays in the persistent toolHistory; only
|
|
334
|
-
// the transient `activeToolCall` pill is cleared. Status is left intact
|
|
335
|
-
// (the turn is still live) so the dashboard knows Claude is still working.
|
|
336
|
-
this.server.setActiveToolCall(null);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
private onSubagentStart(payload: Record<string, any>): void {
|
|
340
|
-
const agentType: string = payload.agent_type ?? "agent";
|
|
341
|
-
this.server.setActiveToolCall({ name: "subagent", target: agentType });
|
|
342
|
-
this.server.setAutoStatus("thinking");
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
private onSubagentStop(): void {
|
|
346
|
-
// No-op — the parent agent continues working; the next Pre/PostToolUse or
|
|
347
|
-
// Stop will update state. Previously this reset status to 'thinking',
|
|
348
|
-
// which kept the auto-clear timer resetting forever.
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
private onStop(): void {
|
|
352
|
-
this.server.setAutoStatus(null);
|
|
353
|
-
this.server.setActiveToolCall(null);
|
|
354
|
-
}
|
|
355
|
-
}
|