claude-synapse 1.0.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) 2025 Iulian Leon
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/bin/init.mjs ADDED
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
4
+ import { resolve, dirname } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ const __dirname = dirname(fileURLToPath(import.meta.url));
8
+ const ROOT = resolve(__dirname, '..');
9
+
10
+ export default async function init() {
11
+ const hooksSource = resolve(ROOT, 'hooks', 'claude-hooks.json');
12
+ const targetDir = resolve(process.cwd(), '.claude');
13
+ const targetFile = resolve(targetDir, 'settings.json');
14
+
15
+ const hooksConfig = JSON.parse(readFileSync(hooksSource, 'utf-8'));
16
+
17
+ if (existsSync(targetFile)) {
18
+ // Merge hooks into existing settings
19
+ const existing = JSON.parse(readFileSync(targetFile, 'utf-8'));
20
+ if (!existing.hooks) existing.hooks = {};
21
+
22
+ for (const [event, matchers] of Object.entries(hooksConfig.hooks)) {
23
+ if (!existing.hooks[event]) {
24
+ existing.hooks[event] = matchers;
25
+ } else {
26
+ // Append to existing matchers
27
+ existing.hooks[event].push(...matchers);
28
+ }
29
+ }
30
+
31
+ writeFileSync(targetFile, JSON.stringify(existing, null, 2) + '\n');
32
+ console.log(`[synapse] Merged hooks into ${targetFile}`);
33
+ } else {
34
+ // Create new settings file
35
+ mkdirSync(targetDir, { recursive: true });
36
+ writeFileSync(targetFile, JSON.stringify(hooksConfig, null, 2) + '\n');
37
+ console.log(`[synapse] Created ${targetFile} with hooks config`);
38
+ }
39
+
40
+ console.log('[synapse] Hooks configured! Start synapse in another terminal:');
41
+ console.log(' npx synapse');
42
+ console.log('');
43
+ console.log('Then use Claude Code normally — events will appear in the dashboard.');
44
+ }
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { execSync, spawn } from 'node:child_process';
4
+ import { existsSync } from 'node:fs';
5
+ import { resolve, dirname } from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+
8
+ const __dirname = dirname(fileURLToPath(import.meta.url));
9
+ const ROOT = resolve(__dirname, '..');
10
+ const PORT = process.env.PORT || 4800;
11
+
12
+ // Detect whether we're running from the npm-published bundle or from source
13
+ const bundledCollector = resolve(ROOT, 'dist', 'collector.mjs');
14
+ const bundledDashboard = resolve(ROOT, 'dist', 'dashboard');
15
+ const isBundled = existsSync(bundledCollector);
16
+
17
+ const args = process.argv.slice(2);
18
+ const command = args[0];
19
+
20
+ if (command === 'init') {
21
+ const initPath = resolve(ROOT, 'bin', 'init.mjs');
22
+ const { default: init } = await import(initPath);
23
+ await init();
24
+ process.exit(0);
25
+ }
26
+
27
+ function isDevBuilt() {
28
+ return (
29
+ existsSync(resolve(ROOT, 'packages/protocol/dist/index.js')) &&
30
+ existsSync(resolve(ROOT, 'apps/collector/dist/index.js')) &&
31
+ existsSync(resolve(ROOT, 'apps/dashboard/dist/index.html'))
32
+ );
33
+ }
34
+
35
+ function build() {
36
+ console.log('[synapse] Building...');
37
+ execSync('npm run build', { cwd: ROOT, stdio: 'inherit' });
38
+ console.log('[synapse] Build complete.');
39
+ }
40
+
41
+ function start() {
42
+ let entryPoint;
43
+ let dashboardDir;
44
+
45
+ if (isBundled) {
46
+ // npm-installed mode: use pre-bundled files
47
+ entryPoint = bundledCollector;
48
+ dashboardDir = bundledDashboard;
49
+ } else {
50
+ // Dev mode: build from source if needed
51
+ if (!isDevBuilt()) build();
52
+ entryPoint = resolve(ROOT, 'apps/collector/dist/index.js');
53
+ dashboardDir = resolve(ROOT, 'apps/dashboard/dist');
54
+ }
55
+
56
+ console.log(`[synapse] Starting on http://localhost:${PORT}`);
57
+
58
+ const collector = spawn('node', [entryPoint], {
59
+ cwd: ROOT,
60
+ stdio: 'inherit',
61
+ env: {
62
+ ...process.env,
63
+ PORT: String(PORT),
64
+ SYNAPSE_DASHBOARD_DIR: dashboardDir,
65
+ },
66
+ });
67
+
68
+ collector.on('close', (code) => {
69
+ process.exit(code ?? 0);
70
+ });
71
+
72
+ // Open browser after a short delay
73
+ setTimeout(() => {
74
+ const url = `http://localhost:${PORT}`;
75
+ try {
76
+ const platform = process.platform;
77
+ if (platform === 'darwin') execSync(`open ${url}`);
78
+ else if (platform === 'linux') execSync(`xdg-open ${url}`);
79
+ else if (platform === 'win32') execSync(`start ${url}`);
80
+ } catch {
81
+ // Silently ignore if browser can't be opened
82
+ }
83
+ }, 1500);
84
+
85
+ process.on('SIGINT', () => {
86
+ collector.kill('SIGINT');
87
+ process.exit(0);
88
+ });
89
+
90
+ process.on('SIGTERM', () => {
91
+ collector.kill('SIGTERM');
92
+ process.exit(0);
93
+ });
94
+ }
95
+
96
+ start();