@moshi-labs/snitch 1.0.1 → 1.0.3
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/cli/collector.js +17 -9
- package/cli/commands/init.js +2 -1
- package/cli/config.js +1 -0
- package/package.json +1 -1
package/cli/collector.js
CHANGED
|
@@ -3,6 +3,7 @@ import { readFileSync, statSync, existsSync } from 'fs';
|
|
|
3
3
|
import { join, basename, dirname } from 'path';
|
|
4
4
|
import { execSync } from 'child_process';
|
|
5
5
|
import { homedir } from 'os';
|
|
6
|
+
import { load } from './config.js';
|
|
6
7
|
|
|
7
8
|
const CLAUDE_PROJECTS_DIR = join(homedir(), '.claude', 'projects');
|
|
8
9
|
|
|
@@ -16,8 +17,13 @@ export class ActivityCollector {
|
|
|
16
17
|
this.watcher = null;
|
|
17
18
|
this.filePositions = new Map(); // Track read position per file
|
|
18
19
|
this.activeThresholdMs = 5 * 60 * 1000; // 5 minutes = active
|
|
19
|
-
//
|
|
20
|
-
|
|
20
|
+
// Load allowed repos from config
|
|
21
|
+
const config = load();
|
|
22
|
+
this.allowedRepos = config.allowedRepos || [];
|
|
23
|
+
// Build regex pattern from allowed repos
|
|
24
|
+
this.repoPattern = this.allowedRepos.length > 0
|
|
25
|
+
? new RegExp(this.allowedRepos.map(r => r.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|'))
|
|
26
|
+
: null;
|
|
21
27
|
}
|
|
22
28
|
|
|
23
29
|
start() {
|
|
@@ -137,9 +143,9 @@ export class ActivityCollector {
|
|
|
137
143
|
}
|
|
138
144
|
// Detect cd into repos
|
|
139
145
|
const cdMatch = cmd.match(/cd\s+['"]*([^'"&|;\s]+)/);
|
|
140
|
-
if (cdMatch) {
|
|
146
|
+
if (cdMatch && this.repoPattern) {
|
|
141
147
|
const path = cdMatch[1];
|
|
142
|
-
const repoMatch = path.match(
|
|
148
|
+
const repoMatch = path.match(this.repoPattern);
|
|
143
149
|
if (repoMatch) {
|
|
144
150
|
activity.repo = repoMatch[0];
|
|
145
151
|
}
|
|
@@ -150,9 +156,11 @@ export class ActivityCollector {
|
|
|
150
156
|
// Extract repo hints from file operations
|
|
151
157
|
if (['Read', 'Edit', 'Write'].includes(block.name) && block.input?.file_path) {
|
|
152
158
|
const path = block.input.file_path;
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
159
|
+
if (this.repoPattern) {
|
|
160
|
+
const repoMatch = path.match(this.repoPattern);
|
|
161
|
+
if (repoMatch) {
|
|
162
|
+
activity.repo = repoMatch[0];
|
|
163
|
+
}
|
|
156
164
|
}
|
|
157
165
|
toolEvent.hint = path;
|
|
158
166
|
}
|
|
@@ -166,8 +174,8 @@ export class ActivityCollector {
|
|
|
166
174
|
if (event.gitBranch) {
|
|
167
175
|
activity.branch = event.gitBranch;
|
|
168
176
|
}
|
|
169
|
-
if (event.cwd) {
|
|
170
|
-
const repoMatch = event.cwd.match(
|
|
177
|
+
if (event.cwd && this.repoPattern) {
|
|
178
|
+
const repoMatch = event.cwd.match(this.repoPattern);
|
|
171
179
|
if (repoMatch) {
|
|
172
180
|
activity.repo = repoMatch[0];
|
|
173
181
|
}
|
package/cli/commands/init.js
CHANGED
|
@@ -26,7 +26,8 @@ export async function initCommand() {
|
|
|
26
26
|
: 'Server URL: ';
|
|
27
27
|
const serverUrl = await question(serverUrlPrompt);
|
|
28
28
|
if (serverUrl.trim()) {
|
|
29
|
-
|
|
29
|
+
// Strip trailing slashes
|
|
30
|
+
config.serverUrl = serverUrl.trim().replace(/\/+$/, '');
|
|
30
31
|
} else if (!config.serverUrl) {
|
|
31
32
|
console.log('Error: Server URL is required');
|
|
32
33
|
rl.close();
|
package/cli/config.js
CHANGED