@neatlogs/claude-code 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.
@@ -0,0 +1,73 @@
1
+ import {
2
+ updateConfig
3
+ } from "./chunk-RAUPOAL6.js";
4
+
5
+ // src/setup.ts
6
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs";
7
+ import { homedir } from "os";
8
+ import { dirname, join } from "path";
9
+ var HOOK_EVENTS = [
10
+ "SessionStart",
11
+ "UserPromptSubmit",
12
+ "PreToolUse",
13
+ "PostToolUse",
14
+ "PostToolUseFailure",
15
+ "SubagentStart",
16
+ "SubagentStop",
17
+ "PermissionDenied",
18
+ "Stop",
19
+ "StopFailure",
20
+ "SessionEnd",
21
+ "PostCompact",
22
+ "InstructionsLoaded"
23
+ ];
24
+ function getSettingsPath(scope, projectDir) {
25
+ if (scope === "global") {
26
+ return join(homedir(), ".claude", "settings.json");
27
+ }
28
+ const base = projectDir ?? process.cwd();
29
+ return join(base, ".claude", "settings.json");
30
+ }
31
+ function resolveCommand() {
32
+ return "neatlogs-claude-code hook";
33
+ }
34
+ function registerHooks(scope, projectDir) {
35
+ const settingsPath = getSettingsPath(scope, projectDir);
36
+ const dir = dirname(settingsPath);
37
+ mkdirSync(dir, { recursive: true });
38
+ let settings = {};
39
+ if (existsSync(settingsPath)) {
40
+ try {
41
+ settings = JSON.parse(readFileSync(settingsPath, "utf-8"));
42
+ } catch (err) {
43
+ console.warn(`[neatlogs/claude-code] Failed to parse existing settings: ${err.message}`);
44
+ }
45
+ }
46
+ const command = resolveCommand();
47
+ const existingHooks = typeof settings.hooks === "object" && !Array.isArray(settings.hooks) ? settings.hooks : {};
48
+ for (const event of HOOK_EVENTS) {
49
+ const eventGroups = existingHooks[event] ?? [];
50
+ const filtered = eventGroups.filter(
51
+ (g) => !g.hooks.some((h) => h.command.includes("neatlogs-claude-code") || h.command.includes("neatlogs/claude-code"))
52
+ );
53
+ filtered.push({ matcher: "", hooks: [{ type: "command", command }] });
54
+ existingHooks[event] = filtered;
55
+ }
56
+ settings.hooks = existingHooks;
57
+ writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + "\n", "utf-8");
58
+ console.log(`[neatlogs/claude-code] Registered ${HOOK_EVENTS.length} hooks in ${settingsPath}`);
59
+ }
60
+ function runSetup(args) {
61
+ const scope = args.includes("--global") ? "global" : "project";
62
+ const keyIdx = args.indexOf("--api-key");
63
+ const apiKey = keyIdx !== -1 ? args[keyIdx + 1] : void 0;
64
+ if (apiKey) {
65
+ updateConfig({ api_key: apiKey });
66
+ console.log(`[neatlogs/claude-code] API key saved to ~/.config/neatlogs/config.json`);
67
+ }
68
+ registerHooks(scope);
69
+ }
70
+ export {
71
+ registerHooks,
72
+ runSetup
73
+ };
@@ -0,0 +1,17 @@
1
+ {
2
+ "hooks": [
3
+ { "event": "SessionStart", "command": "${CLAUDE_PLUGIN_ROOT}/dist/cli.js hook" },
4
+ { "event": "UserPromptSubmit", "command": "${CLAUDE_PLUGIN_ROOT}/dist/cli.js hook" },
5
+ { "event": "PreToolUse", "command": "${CLAUDE_PLUGIN_ROOT}/dist/cli.js hook" },
6
+ { "event": "PostToolUse", "command": "${CLAUDE_PLUGIN_ROOT}/dist/cli.js hook" },
7
+ { "event": "PostToolUseFailure", "command": "${CLAUDE_PLUGIN_ROOT}/dist/cli.js hook" },
8
+ { "event": "SubagentStart", "command": "${CLAUDE_PLUGIN_ROOT}/dist/cli.js hook" },
9
+ { "event": "SubagentStop", "command": "${CLAUDE_PLUGIN_ROOT}/dist/cli.js hook" },
10
+ { "event": "PermissionDenied", "command": "${CLAUDE_PLUGIN_ROOT}/dist/cli.js hook" },
11
+ { "event": "Stop", "command": "${CLAUDE_PLUGIN_ROOT}/dist/cli.js hook" },
12
+ { "event": "StopFailure", "command": "${CLAUDE_PLUGIN_ROOT}/dist/cli.js hook" },
13
+ { "event": "SessionEnd", "command": "${CLAUDE_PLUGIN_ROOT}/dist/cli.js hook" },
14
+ { "event": "PostCompact", "command": "${CLAUDE_PLUGIN_ROOT}/dist/cli.js hook" },
15
+ { "event": "InstructionsLoaded", "command": "${CLAUDE_PLUGIN_ROOT}/dist/cli.js hook" }
16
+ ]
17
+ }
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@neatlogs/claude-code",
3
+ "version": "0.1.0",
4
+ "description": "Neatlogs observability for Claude Code sessions — automatic tracing of prompts, tool calls, thinking, and LLM responses via hooks",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "bin": { "neatlogs-claude-code": "dist/cli.js" },
8
+ "main": "dist/index.cjs",
9
+ "module": "dist/index.js",
10
+ "types": "dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
14
+ "require": { "types": "./dist/index.d.cts", "default": "./dist/index.cjs" }
15
+ }
16
+ },
17
+ "files": ["dist/**", "README.md", ".claude-plugin/**", "hooks/**"],
18
+ "engines": { "node": ">=18" },
19
+ "scripts": {
20
+ "build": "tsup",
21
+ "postbuild": "chmod +x ./dist/cli.js",
22
+ "dev": "tsup --watch",
23
+ "clean": "rm -rf dist"
24
+ },
25
+ "dependencies": {
26
+ "protobufjs": "^7.4.0"
27
+ },
28
+ "devDependencies": {
29
+ "@types/node": "^20.11.17",
30
+ "tsup": "^8.4.0",
31
+ "typescript": "^5.3.3"
32
+ },
33
+ "publishConfig": { "access": "public" }
34
+ }