@groundtrack/hooks 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Groundtrack
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # @groundtrack/hooks
2
+
3
+ Lifecycle hook utilities for Groundtrack MCP clients.
4
+
5
+ Install globally so the `groundtrack-hook` command is available to Claude Code,
6
+ Codex, and Cursor hook configurations:
7
+
8
+ ```bash
9
+ npm install -g @groundtrack/hooks
10
+ ```
11
+
12
+ The command reads a pre-tool-use hook payload from standard input and enriches
13
+ Groundtrack `store_event` calls with the client session and model identifiers.
14
+ It does not send network requests or read project files.
15
+
16
+ Update it with:
17
+
18
+ ```bash
19
+ npm update -g @groundtrack/hooks
20
+ ```
@@ -0,0 +1,57 @@
1
+ const PROVIDERS = [
2
+ [/^claude(?:[-_.]|$)/, "anthropic"],
3
+ [/^(?:gpt|o\d|codex)(?:[-_.]|$)/, "openai"],
4
+ [/^gemini(?:[-_.]|$)/, "google"],
5
+ [/^grok(?:[-_.]|$)/, "xai"],
6
+ [/^deepseek(?:[-_.]|$)/, "deepseek"],
7
+ [/^mistral(?:[-_.]|$)/, "mistral"],
8
+ ];
9
+ function nonEmptyString(value) {
10
+ return typeof value === "string" && value.trim() ? value.trim() : null;
11
+ }
12
+ function normalizeModelId(value) {
13
+ const model = nonEmptyString(value)?.toLowerCase();
14
+ if (!model)
15
+ return null;
16
+ if (/^[a-z0-9][a-z0-9._-]*\/[a-z0-9][a-z0-9._+-]*$/i.test(model))
17
+ return model;
18
+ const provider = PROVIDERS.find(([pattern]) => pattern.test(model))?.[1];
19
+ return provider ? `${provider}/${model}` : null;
20
+ }
21
+ function isGroundtrackStoreEvent(toolName) {
22
+ const normalized = nonEmptyString(toolName)?.toLowerCase();
23
+ if (!normalized?.includes("store_event"))
24
+ return false;
25
+ return normalized.includes("groundtrack") || normalized === "mcp:store_event";
26
+ }
27
+ export function enrichInput(hookInput, clientOverride) {
28
+ const toolInput = hookInput.tool_input &&
29
+ typeof hookInput.tool_input === "object" &&
30
+ !Array.isArray(hookInput.tool_input)
31
+ ? { ...hookInput.tool_input }
32
+ : {};
33
+ const isCursor = nonEmptyString(hookInput.conversation_id) != null;
34
+ const host = nonEmptyString(clientOverride)?.toLowerCase() ?? (isCursor ? "cursor" : "codex");
35
+ const hostSessionId = nonEmptyString(isCursor ? hookInput.conversation_id : hookInput.session_id);
36
+ const hostModel = normalizeModelId(isCursor ? (hookInput.model_id ?? hookInput.model) : hookInput.model);
37
+ if (hostSessionId)
38
+ toolInput.sessionId = `${host}:${hostSessionId}`;
39
+ if (hostModel)
40
+ toolInput.modelId = hostModel;
41
+ return toolInput;
42
+ }
43
+ export function hookOutput(hookInput, clientOverride) {
44
+ if (!isGroundtrackStoreEvent(hookInput.tool_name))
45
+ return {};
46
+ const updatedInput = enrichInput(hookInput, clientOverride);
47
+ if (nonEmptyString(hookInput.conversation_id)) {
48
+ return { permission: "allow", updated_input: updatedInput };
49
+ }
50
+ return {
51
+ hookSpecificOutput: {
52
+ hookEventName: "PreToolUse",
53
+ permissionDecision: "allow",
54
+ updatedInput,
55
+ },
56
+ };
57
+ }
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import { hookOutput } from "./enrich-store-event.js";
3
+ async function main() {
4
+ let raw = "";
5
+ for await (const chunk of process.stdin)
6
+ raw += chunk;
7
+ process.stdout.write(JSON.stringify(hookOutput(JSON.parse(raw), process.argv[2])));
8
+ }
9
+ main().catch(() => process.stdout.write("{}"));
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@groundtrack/hooks",
3
+ "version": "0.1.0",
4
+ "description": "Lifecycle hook utilities for Groundtrack MCP clients.",
5
+ "keywords": [
6
+ "claude-code",
7
+ "codex",
8
+ "cursor",
9
+ "groundtrack",
10
+ "hooks",
11
+ "mcp"
12
+ ],
13
+ "license": "MIT",
14
+ "bin": {
15
+ "groundtrack-hook": "./dist/groundtrack-hook.js"
16
+ },
17
+ "files": [
18
+ "dist/",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "type": "module",
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "scripts": {
27
+ "build": "tsc -p tsconfig.json",
28
+ "lint": "oxlint .",
29
+ "prepack": "pnpm run build",
30
+ "test": "pnpm run build && node --test test/*.test.mjs",
31
+ "typecheck": "tsc -p tsconfig.json --noEmit"
32
+ },
33
+ "devDependencies": {
34
+ "@groundtrack/typescript": "workspace:*",
35
+ "@types/node": "^25.9.1",
36
+ "typescript": "~7.0.2"
37
+ },
38
+ "engines": {
39
+ "node": ">=18"
40
+ }
41
+ }