vibetracking 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.
Files changed (46) hide show
  1. package/README.md +77 -0
  2. package/dist/auth.d.ts +17 -0
  3. package/dist/auth.d.ts.map +1 -0
  4. package/dist/auth.js +162 -0
  5. package/dist/auth.js.map +1 -0
  6. package/dist/cli.d.ts +8 -0
  7. package/dist/cli.d.ts.map +1 -0
  8. package/dist/cli.js +440 -0
  9. package/dist/cli.js.map +1 -0
  10. package/dist/credentials.d.ts +36 -0
  11. package/dist/credentials.d.ts.map +1 -0
  12. package/dist/credentials.js +82 -0
  13. package/dist/credentials.js.map +1 -0
  14. package/dist/cursor.d.ts +136 -0
  15. package/dist/cursor.d.ts.map +1 -0
  16. package/dist/cursor.js +400 -0
  17. package/dist/cursor.js.map +1 -0
  18. package/dist/graph-types.d.ts +152 -0
  19. package/dist/graph-types.d.ts.map +1 -0
  20. package/dist/graph-types.js +6 -0
  21. package/dist/graph-types.js.map +1 -0
  22. package/dist/native-runner.d.ts +11 -0
  23. package/dist/native-runner.d.ts.map +1 -0
  24. package/dist/native-runner.js +61 -0
  25. package/dist/native-runner.js.map +1 -0
  26. package/dist/native.d.ts +98 -0
  27. package/dist/native.d.ts.map +1 -0
  28. package/dist/native.js +309 -0
  29. package/dist/native.js.map +1 -0
  30. package/dist/sessions/types.d.ts +28 -0
  31. package/dist/sessions/types.d.ts.map +1 -0
  32. package/dist/sessions/types.js +27 -0
  33. package/dist/sessions/types.js.map +1 -0
  34. package/dist/spinner.d.ts +75 -0
  35. package/dist/spinner.d.ts.map +1 -0
  36. package/dist/spinner.js +203 -0
  37. package/dist/spinner.js.map +1 -0
  38. package/dist/submit.d.ts +23 -0
  39. package/dist/submit.d.ts.map +1 -0
  40. package/dist/submit.js +144 -0
  41. package/dist/submit.js.map +1 -0
  42. package/dist/table.d.ts +6 -0
  43. package/dist/table.d.ts.map +1 -0
  44. package/dist/table.js +10 -0
  45. package/dist/table.js.map +1 -0
  46. package/package.json +61 -0
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Type definitions for contribution graph data
3
+ * Note: intensity is calculated based on COST ($), not tokens
4
+ */
5
+ /**
6
+ * Valid source identifiers
7
+ */
8
+ export type SourceType = "opencode" | "claude" | "codex" | "gemini" | "cursor" | "amp" | "droid";
9
+ /**
10
+ * Token breakdown by category
11
+ */
12
+ export interface TokenBreakdown {
13
+ input: number;
14
+ output: number;
15
+ cacheRead: number;
16
+ cacheWrite: number;
17
+ reasoning: number;
18
+ }
19
+ /**
20
+ * Per-source contribution for a single day
21
+ */
22
+ export interface SourceContribution {
23
+ /** Source identifier */
24
+ source: SourceType;
25
+ /** Exact model ID as reported by the source */
26
+ modelId: string;
27
+ /** Provider ID if available */
28
+ providerId?: string;
29
+ /** Token counts */
30
+ tokens: TokenBreakdown;
31
+ /** Calculated cost for this source/model combination */
32
+ cost: number;
33
+ /** Number of messages/requests */
34
+ messages: number;
35
+ }
36
+ /**
37
+ * Daily contribution entry with full granularity
38
+ */
39
+ export interface DailyContribution {
40
+ /** ISO date string (YYYY-MM-DD) */
41
+ date: string;
42
+ /** Aggregated totals for the day */
43
+ totals: {
44
+ /** Total tokens (input + output + cache) */
45
+ tokens: number;
46
+ /** Total cost in USD */
47
+ cost: number;
48
+ /** Number of messages/requests */
49
+ messages: number;
50
+ };
51
+ /**
52
+ * Calculated intensity grade (0-4)
53
+ * Based on COST, not tokens
54
+ * 0 = no activity, 4 = highest cost relative to max
55
+ */
56
+ intensity: 0 | 1 | 2 | 3 | 4;
57
+ /** Token breakdown by category (aggregated across all sources) */
58
+ tokenBreakdown: TokenBreakdown;
59
+ /** Per-source breakdown with model information */
60
+ sources: SourceContribution[];
61
+ }
62
+ /**
63
+ * Year-level summary
64
+ */
65
+ export interface YearSummary {
66
+ /** Year as string (e.g., "2024") */
67
+ year: string;
68
+ /** Total tokens for the year */
69
+ totalTokens: number;
70
+ /** Total cost for the year */
71
+ totalCost: number;
72
+ /** Date range for this year's data */
73
+ range: {
74
+ start: string;
75
+ end: string;
76
+ };
77
+ }
78
+ /**
79
+ * Summary statistics
80
+ */
81
+ export interface DataSummary {
82
+ /** Total tokens across all time */
83
+ totalTokens: number;
84
+ /** Total cost across all time */
85
+ totalCost: number;
86
+ /** Total number of days in date range */
87
+ totalDays: number;
88
+ /** Number of days with activity */
89
+ activeDays: number;
90
+ /** Average cost per day (based on active days) */
91
+ averagePerDay: number;
92
+ /** Maximum cost in a single day (used for intensity calculation) */
93
+ maxCostInSingleDay: number;
94
+ /** All sources present in the data */
95
+ sources: SourceType[];
96
+ /** All unique model IDs across all sources */
97
+ models: string[];
98
+ }
99
+ /**
100
+ * Metadata about the export
101
+ */
102
+ export interface ExportMeta {
103
+ /** ISO timestamp of when the data was generated */
104
+ generatedAt: string;
105
+ /** CLI version that generated this data */
106
+ version: string;
107
+ /** Date range of the data */
108
+ dateRange: {
109
+ start: string;
110
+ end: string;
111
+ };
112
+ }
113
+ /**
114
+ * Root data structure exported by CLI
115
+ * This is the complete JSON schema for contribution graph data
116
+ */
117
+ export interface TokenContributionData {
118
+ /** Metadata about the export */
119
+ meta: ExportMeta;
120
+ /** Summary statistics */
121
+ summary: DataSummary;
122
+ /** Year-by-year breakdown for multi-year views */
123
+ years: YearSummary[];
124
+ /** Daily contribution data - the core dataset */
125
+ contributions: DailyContribution[];
126
+ }
127
+ /**
128
+ * Options for graph data generation
129
+ */
130
+ export interface GraphOptions {
131
+ /** Filter to specific sources */
132
+ sources?: SourceType[];
133
+ /** Start date filter (ISO format) */
134
+ since?: string;
135
+ /** End date filter (ISO format) */
136
+ until?: string;
137
+ /** Filter to specific year */
138
+ year?: string;
139
+ }
140
+ /**
141
+ * Unified message format for aggregation
142
+ * Used internally to normalize data from different sources
143
+ */
144
+ export interface UnifiedMessage {
145
+ source: SourceType;
146
+ modelId: string;
147
+ providerId?: string;
148
+ timestamp: number;
149
+ tokens: TokenBreakdown;
150
+ cost: number;
151
+ }
152
+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OAAO,CAAC,EAAE,UAAU,EAAE,CAAC;IAEvB,qCAAqC;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,mCAAmC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,8BAA8B;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,cAAc,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CACd"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Type definitions for contribution graph data
3
+ * Note: intensity is calculated based on COST ($), not tokens
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=graph-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-types.js","sourceRoot":"","sources":["../src/graph-types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * Native Runner - Subprocess for non-blocking native Rust calls
4
+ *
5
+ * This script runs in a separate process to keep the main event loop free
6
+ * for UI rendering (e.g., spinner animation).
7
+ *
8
+ * Communication: file (JSON input) -> stdout (JSON output)
9
+ */
10
+ export {};
11
+ //# sourceMappingURL=native-runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-runner.d.ts","sourceRoot":"","sources":["../src/native-runner.ts"],"names":[],"mappings":";AACA;;;;;;;GAOG"}
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * Native Runner - Subprocess for non-blocking native Rust calls
4
+ *
5
+ * This script runs in a separate process to keep the main event loop free
6
+ * for UI rendering (e.g., spinner animation).
7
+ *
8
+ * Communication: file (JSON input) -> stdout (JSON output)
9
+ */
10
+ import nativeCore from "@starknetid/vibetracking-core";
11
+ import { readFileSync } from "node:fs";
12
+ async function main() {
13
+ const inputFile = process.argv[2];
14
+ if (!inputFile) {
15
+ process.stderr.write(JSON.stringify({ error: "No input file provided" }));
16
+ process.exit(1);
17
+ }
18
+ const input = readFileSync(inputFile, "utf-8");
19
+ let request;
20
+ try {
21
+ request = JSON.parse(input);
22
+ }
23
+ catch (e) {
24
+ throw new Error(`Malformed JSON input: ${e.message}`);
25
+ }
26
+ const { method, args } = request;
27
+ if (!Array.isArray(args) || args.length === 0) {
28
+ throw new Error(`Invalid args for method '${method}': expected at least 1 argument`);
29
+ }
30
+ let result;
31
+ switch (method) {
32
+ case "parseLocalSources":
33
+ result = nativeCore.parseLocalSources(args[0]);
34
+ break;
35
+ case "finalizeReport":
36
+ result = await nativeCore.finalizeReport(args[0]);
37
+ break;
38
+ case "finalizeMonthlyReport":
39
+ result = await nativeCore.finalizeMonthlyReport(args[0]);
40
+ break;
41
+ case "finalizeGraph":
42
+ result = await nativeCore.finalizeGraph(args[0]);
43
+ break;
44
+ case "finalizeReportAndGraph":
45
+ result = await nativeCore.finalizeReportAndGraph(args[0]);
46
+ break;
47
+ default:
48
+ throw new Error(`Unknown method: ${method}`);
49
+ }
50
+ // Write result to stdout (no newline - pure JSON)
51
+ process.stdout.write(JSON.stringify(result));
52
+ }
53
+ main().catch((e) => {
54
+ const error = e;
55
+ process.stderr.write(JSON.stringify({
56
+ error: error.message,
57
+ stack: error.stack,
58
+ }));
59
+ process.exit(1);
60
+ });
61
+ //# sourceMappingURL=native-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-runner.js","sourceRoot":"","sources":["../src/native-runner.ts"],"names":[],"mappings":";AACA;;;;;;;GAOG;AAEH,OAAO,UAAU,MAAM,+BAA+B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAOvC,KAAK,UAAU,IAAI;IACjB,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAElC,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,CAAmD,CAAC,CAAC;YACnG,MAAM;QACR,KAAK,wBAAwB;YAC3B,MAAM,GAAG,MAAM,UAAU,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAA4D,CAAC,CAAC;YACrH,MAAM;QACR;YACE,MAAM,IAAI,KAAK,CAAC,mBAAmB,MAAM,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,kDAAkD;IAClD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;IACjB,MAAM,KAAK,GAAG,CAAU,CAAC;IACzB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;QAClC,KAAK,EAAE,KAAK,CAAC,OAAO;QACpB,KAAK,EAAE,KAAK,CAAC,KAAK;KACnB,CAAC,CAAC,CAAC;IACJ,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Native module loader for Rust core
3
+ *
4
+ * Exposes all Rust functions with proper TypeScript types.
5
+ * Native module is REQUIRED - no TypeScript fallback.
6
+ */
7
+ import type { TokenContributionData, SourceType } from "./graph-types.js";
8
+ /**
9
+ * Check if native module is available
10
+ */
11
+ export declare function isNativeAvailable(): boolean;
12
+ /**
13
+ * Get native module version
14
+ */
15
+ export declare function getNativeVersion(): string | null;
16
+ export interface ModelUsage {
17
+ source: string;
18
+ model: string;
19
+ provider: string;
20
+ input: number;
21
+ output: number;
22
+ cacheRead: number;
23
+ cacheWrite: number;
24
+ reasoning: number;
25
+ messageCount: number;
26
+ cost: number;
27
+ }
28
+ export interface ModelReport {
29
+ entries: ModelUsage[];
30
+ totalInput: number;
31
+ totalOutput: number;
32
+ totalCacheRead: number;
33
+ totalCacheWrite: number;
34
+ totalMessages: number;
35
+ totalCost: number;
36
+ processingTimeMs: number;
37
+ }
38
+ export interface MonthlyUsage {
39
+ month: string;
40
+ models: string[];
41
+ input: number;
42
+ output: number;
43
+ cacheRead: number;
44
+ cacheWrite: number;
45
+ messageCount: number;
46
+ cost: number;
47
+ }
48
+ export interface MonthlyReport {
49
+ entries: MonthlyUsage[];
50
+ totalCost: number;
51
+ processingTimeMs: number;
52
+ }
53
+ export interface ParsedMessages {
54
+ messages: Array<{
55
+ source: string;
56
+ modelId: string;
57
+ providerId: string;
58
+ timestamp: number;
59
+ date: string;
60
+ input: number;
61
+ output: number;
62
+ cacheRead: number;
63
+ cacheWrite: number;
64
+ reasoning: number;
65
+ sessionId: string;
66
+ agent?: string;
67
+ }>;
68
+ opencodeCount: number;
69
+ claudeCount: number;
70
+ codexCount: number;
71
+ geminiCount: number;
72
+ ampCount: number;
73
+ droidCount: number;
74
+ processingTimeMs: number;
75
+ }
76
+ export interface LocalParseOptions {
77
+ sources?: SourceType[];
78
+ since?: string;
79
+ until?: string;
80
+ year?: string;
81
+ }
82
+ export interface FinalizeOptions {
83
+ localMessages: ParsedMessages;
84
+ includeCursor: boolean;
85
+ since?: string;
86
+ until?: string;
87
+ year?: string;
88
+ }
89
+ export declare function parseLocalSourcesAsync(options: LocalParseOptions): Promise<ParsedMessages>;
90
+ export declare function finalizeReportAsync(options: FinalizeOptions): Promise<ModelReport>;
91
+ export declare function finalizeMonthlyReportAsync(options: FinalizeOptions): Promise<MonthlyReport>;
92
+ export declare function finalizeGraphAsync(options: FinalizeOptions): Promise<TokenContributionData>;
93
+ export interface ReportAndGraph {
94
+ report: ModelReport;
95
+ graph: TokenContributionData;
96
+ }
97
+ export declare function finalizeReportAndGraphAsync(options: FinalizeOptions): Promise<ReportAndGraph>;
98
+ //# sourceMappingURL=native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KA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AAED,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAgBjG;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,WAAW,CAAC;IACpB,KAAK,EAAE,qBAAqB,CAAC;CAC9B;AAOD,wBAAsB,2BAA2B,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CAmBnG"}
package/dist/native.js ADDED
@@ -0,0 +1,309 @@
1
+ /**
2
+ * Native module loader for Rust core
3
+ *
4
+ * Exposes all Rust functions with proper TypeScript types.
5
+ * Native module is REQUIRED - no TypeScript fallback.
6
+ */
7
+ // =============================================================================
8
+ // Module loading
9
+ // =============================================================================
10
+ let nativeCore = null;
11
+ let loadError = null;
12
+ try {
13
+ // Type assertion needed because dynamic import returns module namespace
14
+ // nativeCore.version() is called directly, async functions go through subprocess
15
+ nativeCore = await import("@starknetid/vibetracking-core").then((m) => (m.default || m));
16
+ }
17
+ catch (e) {
18
+ loadError = e;
19
+ }
20
+ // =============================================================================
21
+ // Public API
22
+ // =============================================================================
23
+ /**
24
+ * Check if native module is available
25
+ */
26
+ export function isNativeAvailable() {
27
+ return nativeCore !== null;
28
+ }
29
+ /**
30
+ * Get native module version
31
+ */
32
+ export function getNativeVersion() {
33
+ return nativeCore?.version() ?? null;
34
+ }
35
+ /**
36
+ * Convert native result to TypeScript format
37
+ */
38
+ function fromNativeResult(result) {
39
+ return {
40
+ meta: {
41
+ generatedAt: result.meta.generatedAt,
42
+ version: result.meta.version,
43
+ dateRange: {
44
+ start: result.meta.dateRangeStart,
45
+ end: result.meta.dateRangeEnd,
46
+ },
47
+ },
48
+ summary: {
49
+ totalTokens: result.summary.totalTokens,
50
+ totalCost: result.summary.totalCost,
51
+ totalDays: result.summary.totalDays,
52
+ activeDays: result.summary.activeDays,
53
+ averagePerDay: result.summary.averagePerDay,
54
+ maxCostInSingleDay: result.summary.maxCostInSingleDay,
55
+ sources: result.summary.sources,
56
+ models: result.summary.models,
57
+ },
58
+ years: result.years.map((y) => ({
59
+ year: y.year,
60
+ totalTokens: y.totalTokens,
61
+ totalCost: y.totalCost,
62
+ range: {
63
+ start: y.rangeStart,
64
+ end: y.rangeEnd,
65
+ },
66
+ })),
67
+ contributions: result.contributions.map((c) => ({
68
+ date: c.date,
69
+ totals: {
70
+ tokens: c.totals.tokens,
71
+ cost: c.totals.cost,
72
+ messages: c.totals.messages,
73
+ },
74
+ intensity: c.intensity,
75
+ tokenBreakdown: {
76
+ input: c.tokenBreakdown.input,
77
+ output: c.tokenBreakdown.output,
78
+ cacheRead: c.tokenBreakdown.cacheRead,
79
+ cacheWrite: c.tokenBreakdown.cacheWrite,
80
+ reasoning: c.tokenBreakdown.reasoning,
81
+ },
82
+ sources: c.sources.map((s) => ({
83
+ source: s.source,
84
+ modelId: s.modelId,
85
+ providerId: s.providerId,
86
+ tokens: {
87
+ input: s.tokens.input,
88
+ output: s.tokens.output,
89
+ cacheRead: s.tokens.cacheRead,
90
+ cacheWrite: s.tokens.cacheWrite,
91
+ reasoning: s.tokens.reasoning,
92
+ },
93
+ cost: s.cost,
94
+ messages: s.messages,
95
+ })),
96
+ })),
97
+ };
98
+ }
99
+ // =============================================================================
100
+ // Async Subprocess Wrappers (Non-blocking for UI)
101
+ // =============================================================================
102
+ import { fileURLToPath } from "node:url";
103
+ import { dirname, join } from "node:path";
104
+ import { writeFileSync, unlinkSync, mkdirSync } from "node:fs";
105
+ import { tmpdir } from "node:os";
106
+ import { randomUUID } from "node:crypto";
107
+ const __filename = fileURLToPath(import.meta.url);
108
+ const __dirname = dirname(__filename);
109
+ const DEFAULT_TIMEOUT_MS = 300_000;
110
+ const NATIVE_TIMEOUT_MS = parseInt(process.env.VIBETRACKING_NATIVE_TIMEOUT_MS || String(DEFAULT_TIMEOUT_MS), 10);
111
+ const SIGKILL_GRACE_MS = 500;
112
+ const DEFAULT_MAX_OUTPUT_BYTES = 100 * 1024 * 1024;
113
+ const MAX_OUTPUT_BYTES = parseInt(process.env.VIBETRACKING_MAX_OUTPUT_BYTES || String(DEFAULT_MAX_OUTPUT_BYTES), 10);
114
+ function safeKill(proc, signal) {
115
+ try {
116
+ proc.kill(signal);
117
+ }
118
+ catch { }
119
+ }
120
+ async function runInSubprocess(method, args) {
121
+ const runnerPath = join(__dirname, "native-runner.js");
122
+ const input = JSON.stringify({ method, args });
123
+ const tmpDir = join(tmpdir(), "vibetracking");
124
+ mkdirSync(tmpDir, { recursive: true });
125
+ const inputFile = join(tmpDir, `input-${randomUUID()}.json`);
126
+ writeFileSync(inputFile, input, "utf-8");
127
+ const BunGlobal = globalThis.Bun;
128
+ let proc;
129
+ try {
130
+ proc = BunGlobal.spawn([process.execPath, runnerPath, inputFile], {
131
+ stdout: "pipe",
132
+ stderr: "pipe",
133
+ });
134
+ }
135
+ catch (e) {
136
+ unlinkSync(inputFile);
137
+ throw new Error(`Failed to spawn subprocess: ${e.message}`);
138
+ }
139
+ let timeoutId = null;
140
+ let sigkillId = null;
141
+ let weInitiatedKill = false;
142
+ let aborted = false;
143
+ const cleanup = async () => {
144
+ if (timeoutId)
145
+ clearTimeout(timeoutId);
146
+ if (sigkillId)
147
+ clearTimeout(sigkillId);
148
+ try {
149
+ unlinkSync(inputFile);
150
+ }
151
+ catch { }
152
+ if (aborted) {
153
+ safeKill(proc, "SIGKILL");
154
+ await proc.exited.catch(() => { });
155
+ }
156
+ };
157
+ const abort = () => {
158
+ aborted = true;
159
+ weInitiatedKill = true;
160
+ };
161
+ try {
162
+ const stdoutChunks = [];
163
+ const stderrChunks = [];
164
+ let stdoutBytes = 0;
165
+ let stderrBytes = 0;
166
+ const readStream = async (stream, chunks, getBytesRef, setBytesRef) => {
167
+ const reader = stream.getReader();
168
+ try {
169
+ while (!aborted) {
170
+ const { done, value } = await reader.read();
171
+ if (done)
172
+ break;
173
+ const newTotal = getBytesRef() + value.length;
174
+ if (newTotal > MAX_OUTPUT_BYTES) {
175
+ abort();
176
+ throw new Error(`Output exceeded ${MAX_OUTPUT_BYTES} bytes`);
177
+ }
178
+ setBytesRef(newTotal);
179
+ chunks.push(value);
180
+ }
181
+ }
182
+ finally {
183
+ await reader.cancel().catch(() => { });
184
+ reader.releaseLock();
185
+ }
186
+ const combined = new Uint8Array(getBytesRef());
187
+ let offset = 0;
188
+ for (const chunk of chunks) {
189
+ combined.set(chunk, offset);
190
+ offset += chunk.length;
191
+ }
192
+ return new TextDecoder().decode(combined);
193
+ };
194
+ const timeoutPromise = new Promise((_, reject) => {
195
+ timeoutId = setTimeout(() => {
196
+ abort();
197
+ safeKill(proc, "SIGTERM");
198
+ sigkillId = setTimeout(() => {
199
+ safeKill(proc, "SIGKILL");
200
+ reject(new Error(`Subprocess '${method}' timed out after ${NATIVE_TIMEOUT_MS}ms (hard kill)`));
201
+ }, SIGKILL_GRACE_MS);
202
+ }, NATIVE_TIMEOUT_MS);
203
+ });
204
+ const workPromise = Promise.all([
205
+ readStream(proc.stdout, stdoutChunks, () => stdoutBytes, (n) => { stdoutBytes = n; }),
206
+ readStream(proc.stderr, stderrChunks, () => stderrBytes, (n) => { stderrBytes = n; }),
207
+ proc.exited,
208
+ ]);
209
+ const [stdout, stderr, exitCode] = await Promise.race([workPromise, timeoutPromise]);
210
+ // Note: proc.killed is always true after exit in Bun (even for normal exits), so we only check signalCode
211
+ if (weInitiatedKill || proc.signalCode) {
212
+ throw new Error(`Subprocess '${method}' was killed (signal: ${proc.signalCode || "SIGTERM"})`);
213
+ }
214
+ if (exitCode !== 0) {
215
+ let errorMsg = stderr || `Process exited with code ${exitCode}`;
216
+ try {
217
+ const parsed = JSON.parse(stderr);
218
+ if (parsed.error)
219
+ errorMsg = parsed.error;
220
+ }
221
+ catch { }
222
+ throw new Error(`Subprocess '${method}' failed: ${errorMsg}`);
223
+ }
224
+ try {
225
+ return JSON.parse(stdout);
226
+ }
227
+ catch (e) {
228
+ throw new Error(`Failed to parse subprocess output: ${e.message}\nstdout: ${stdout.slice(0, 500)}`);
229
+ }
230
+ }
231
+ finally {
232
+ await cleanup();
233
+ }
234
+ }
235
+ export async function parseLocalSourcesAsync(options) {
236
+ if (!isNativeAvailable()) {
237
+ throw new Error("Native module required. Run: bun run build:core");
238
+ }
239
+ const nativeOptions = {
240
+ homeDir: undefined,
241
+ sources: options.sources,
242
+ since: options.since,
243
+ until: options.until,
244
+ year: options.year,
245
+ };
246
+ return runInSubprocess("parseLocalSources", [nativeOptions]);
247
+ }
248
+ export async function finalizeReportAsync(options) {
249
+ if (!isNativeAvailable()) {
250
+ throw new Error("Native module required. Run: bun run build:core");
251
+ }
252
+ const nativeOptions = {
253
+ homeDir: undefined,
254
+ localMessages: options.localMessages,
255
+ includeCursor: options.includeCursor,
256
+ since: options.since,
257
+ until: options.until,
258
+ year: options.year,
259
+ };
260
+ return runInSubprocess("finalizeReport", [nativeOptions]);
261
+ }
262
+ export async function finalizeMonthlyReportAsync(options) {
263
+ if (!isNativeAvailable()) {
264
+ throw new Error("Native module required. Run: bun run build:core");
265
+ }
266
+ const nativeOptions = {
267
+ homeDir: undefined,
268
+ localMessages: options.localMessages,
269
+ includeCursor: options.includeCursor,
270
+ since: options.since,
271
+ until: options.until,
272
+ year: options.year,
273
+ };
274
+ return runInSubprocess("finalizeMonthlyReport", [nativeOptions]);
275
+ }
276
+ export async function finalizeGraphAsync(options) {
277
+ if (!isNativeAvailable()) {
278
+ throw new Error("Native module required. Run: bun run build:core");
279
+ }
280
+ const nativeOptions = {
281
+ homeDir: undefined,
282
+ localMessages: options.localMessages,
283
+ includeCursor: options.includeCursor,
284
+ since: options.since,
285
+ until: options.until,
286
+ year: options.year,
287
+ };
288
+ const result = await runInSubprocess("finalizeGraph", [nativeOptions]);
289
+ return fromNativeResult(result);
290
+ }
291
+ export async function finalizeReportAndGraphAsync(options) {
292
+ if (!isNativeAvailable()) {
293
+ throw new Error("Native module required. Run: bun run build:core");
294
+ }
295
+ const nativeOptions = {
296
+ homeDir: undefined,
297
+ localMessages: options.localMessages,
298
+ includeCursor: options.includeCursor,
299
+ since: options.since,
300
+ until: options.until,
301
+ year: options.year,
302
+ };
303
+ const result = await runInSubprocess("finalizeReportAndGraph", [nativeOptions]);
304
+ return {
305
+ report: result.report,
306
+ graph: fromNativeResult(result.graph),
307
+ };
308
+ }
309
+ //# sourceMappingURL=native.js.map