tokensniff 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,8 @@
1
+ #!/usr/bin/env node
2
+ import { main } from '../dist/status.js';
3
+
4
+ Promise.resolve(main()).catch((error) => {
5
+ const message = error instanceof Error ? error.message : String(error);
6
+ console.error(`[tokensniff-status] ${message}`);
7
+ process.exit(1);
8
+ });
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ import { main } from '../dist/cli.js';
3
+
4
+ Promise.resolve(main()).catch((error) => {
5
+ const message = error instanceof Error ? error.message : String(error);
6
+ console.error(`[tokensniff] ${message}`);
7
+ process.exit(1);
8
+ });
@@ -0,0 +1,64 @@
1
+ /**
2
+ * tokensniff — Master CLI Orchestrator (v1 Production)
3
+ *
4
+ * Automates the entire telemetry pipeline with multi-terminal reference-counted session lifecycle management:
5
+ * 1. Checks if proxy is already active on port 4000 (multi-terminal smart attach).
6
+ * 2. Checks if upstream is already running on upstreamPort before spawning upstreamCommand.
7
+ * 3. Registers process ID in ~/.tokensniff/sessions/ for active session reference counting.
8
+ * 4. On Ctrl+C or exit, decrements active session count:
9
+ * - If other terminal sessions are alive: terminates only the local harness, leaving the proxy and upstream alive.
10
+ * - If this was the last session: cleans up the proxy server and upstream process.
11
+ */
12
+ import { type TokenSniffConfig } from '../collector/config.js';
13
+ import { start as startCollector } from '../collector/index.js';
14
+ export interface RunDependencies {
15
+ readonly config?: TokenSniffConfig;
16
+ readonly startProxy?: typeof startCollector;
17
+ readonly waitMs?: number;
18
+ }
19
+ /**
20
+ * Validates TCP availability across host candidates with timeout.
21
+ */
22
+ export declare function waitForTcp(host: string, port: number, timeoutMs?: number): Promise<void>;
23
+ /**
24
+ * Checks if a TCP port is currently open and actively accepting connections.
25
+ */
26
+ export declare function isPortActive(host: string, port: number): Promise<boolean>;
27
+ /**
28
+ * Generates the global ~/.tokensniff/config.json configuration template.
29
+ */
30
+ export declare function writeInitFile(): string;
31
+ /**
32
+ * Prints the configuration blocks for ~/.claude/settings.json.
33
+ */
34
+ export declare function printClaudeInstructions(): void;
35
+ /**
36
+ * Cross-platform process tree termination.
37
+ */
38
+ export declare function terminateProcessTree(pid: number | undefined): void;
39
+ /**
40
+ * Kills any detached process listening on a specific TCP port.
41
+ */
42
+ export declare function killProcessOnPort(port: number): void;
43
+ /**
44
+ * Checks if a process identifier is currently running on the host OS.
45
+ */
46
+ export declare function isProcessAlive(pid: number): boolean;
47
+ /**
48
+ * Resolves the persistent active sessions tracking directory: ~/.tokensniff/sessions.
49
+ */
50
+ export declare function getSessionsDir(): string;
51
+ /**
52
+ * Registers the current CLI terminal process into the shared active sessions pool.
53
+ * Returns an idempotent unregister function to remove the session lock on exit.
54
+ */
55
+ export declare function registerSession(pid?: number): () => void;
56
+ /**
57
+ * Counts how many other terminal sessions are still alive, auto-pruning stale dead PID files.
58
+ */
59
+ export declare function countActiveSessions(excludePid?: number): number;
60
+ /**
61
+ * Main command-line orchestrator.
62
+ */
63
+ export declare function main(argv?: readonly string[], deps?: RunDependencies): Promise<void>;
64
+ //# sourceMappingURL=run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/cli/run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH,OAAO,EAIL,KAAK,gBAAgB,EACtB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,KAAK,IAAI,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGhE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,gBAAgB,CAAC;IACnC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,cAAc,CAAC;IAC5C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,SA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