@tracemarketplace/shared 0.0.1

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 (63) hide show
  1. package/dist/extractors/claude-code.d.ts +3 -0
  2. package/dist/extractors/claude-code.d.ts.map +1 -0
  3. package/dist/extractors/claude-code.js +158 -0
  4. package/dist/extractors/claude-code.js.map +1 -0
  5. package/dist/extractors/codex.d.ts +3 -0
  6. package/dist/extractors/codex.d.ts.map +1 -0
  7. package/dist/extractors/codex.js +192 -0
  8. package/dist/extractors/codex.js.map +1 -0
  9. package/dist/extractors/cursor.d.ts +3 -0
  10. package/dist/extractors/cursor.d.ts.map +1 -0
  11. package/dist/extractors/cursor.js +99 -0
  12. package/dist/extractors/cursor.js.map +1 -0
  13. package/dist/hash.d.ts +4 -0
  14. package/dist/hash.d.ts.map +1 -0
  15. package/dist/hash.js +13 -0
  16. package/dist/hash.js.map +1 -0
  17. package/dist/hash.test.d.ts +2 -0
  18. package/dist/hash.test.d.ts.map +1 -0
  19. package/dist/hash.test.js +67 -0
  20. package/dist/hash.test.js.map +1 -0
  21. package/dist/index.d.ts +9 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +9 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/scoring.d.ts +5 -0
  26. package/dist/scoring.d.ts.map +1 -0
  27. package/dist/scoring.js +114 -0
  28. package/dist/scoring.js.map +1 -0
  29. package/dist/scoring.test.d.ts +2 -0
  30. package/dist/scoring.test.d.ts.map +1 -0
  31. package/dist/scoring.test.js +157 -0
  32. package/dist/scoring.test.js.map +1 -0
  33. package/dist/types.d.ts +98 -0
  34. package/dist/types.d.ts.map +1 -0
  35. package/dist/types.js +2 -0
  36. package/dist/types.js.map +1 -0
  37. package/dist/utils.d.ts +3 -0
  38. package/dist/utils.d.ts.map +1 -0
  39. package/dist/utils.js +11 -0
  40. package/dist/utils.js.map +1 -0
  41. package/dist/validators.d.ts +247 -0
  42. package/dist/validators.d.ts.map +1 -0
  43. package/dist/validators.js +36 -0
  44. package/dist/validators.js.map +1 -0
  45. package/dist/validators.test.d.ts +2 -0
  46. package/dist/validators.test.d.ts.map +1 -0
  47. package/dist/validators.test.js +52 -0
  48. package/dist/validators.test.js.map +1 -0
  49. package/package.json +42 -0
  50. package/src/extractors/claude-code.ts +178 -0
  51. package/src/extractors/codex.ts +208 -0
  52. package/src/extractors/cursor.ts +118 -0
  53. package/src/hash.test.ts +72 -0
  54. package/src/hash.ts +15 -0
  55. package/src/index.ts +8 -0
  56. package/src/scoring.test.ts +173 -0
  57. package/src/scoring.ts +149 -0
  58. package/src/types.ts +96 -0
  59. package/src/utils.ts +9 -0
  60. package/src/validators.test.ts +61 -0
  61. package/src/validators.ts +41 -0
  62. package/tsconfig.json +8 -0
  63. package/vitest.config.ts +8 -0
@@ -0,0 +1,247 @@
1
+ import { z } from "zod";
2
+ export declare const NormalizedTraceSchema: z.ZodObject<{
3
+ trace_id: z.ZodOptional<z.ZodString>;
4
+ schema_version: z.ZodOptional<z.ZodString>;
5
+ source_tool: z.ZodEnum<["claude_code", "codex_cli", "cursor"]>;
6
+ source_session_id: z.ZodString;
7
+ source_version: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8
+ submitted_by: z.ZodOptional<z.ZodString>;
9
+ submitted_at: z.ZodOptional<z.ZodString>;
10
+ extracted_at: z.ZodOptional<z.ZodString>;
11
+ git_branch: z.ZodOptional<z.ZodNullable<z.ZodString>>;
12
+ cwd_hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
13
+ working_language: z.ZodOptional<z.ZodNullable<z.ZodString>>;
14
+ started_at: z.ZodOptional<z.ZodString>;
15
+ ended_at: z.ZodOptional<z.ZodString>;
16
+ turns: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
17
+ turn_count: z.ZodOptional<z.ZodNumber>;
18
+ tool_call_count: z.ZodOptional<z.ZodNumber>;
19
+ has_tool_calls: z.ZodOptional<z.ZodBoolean>;
20
+ has_thinking_blocks: z.ZodOptional<z.ZodBoolean>;
21
+ has_file_changes: z.ZodOptional<z.ZodBoolean>;
22
+ has_shell_commands: z.ZodOptional<z.ZodBoolean>;
23
+ total_input_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
24
+ total_output_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
25
+ total_cache_read_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
26
+ content_fidelity: z.ZodOptional<z.ZodEnum<["full", "chat_only"]>>;
27
+ env_state: z.ZodOptional<z.ZodNullable<z.ZodAny>>;
28
+ score: z.ZodOptional<z.ZodNullable<z.ZodAny>>;
29
+ raw_r2_key: z.ZodOptional<z.ZodString>;
30
+ normalized_r2_key: z.ZodOptional<z.ZodString>;
31
+ }, "strip", z.ZodTypeAny, {
32
+ source_tool: "claude_code" | "codex_cli" | "cursor";
33
+ source_session_id: string;
34
+ trace_id?: string | undefined;
35
+ schema_version?: string | undefined;
36
+ source_version?: string | null | undefined;
37
+ submitted_by?: string | undefined;
38
+ submitted_at?: string | undefined;
39
+ extracted_at?: string | undefined;
40
+ git_branch?: string | null | undefined;
41
+ cwd_hash?: string | null | undefined;
42
+ working_language?: string | null | undefined;
43
+ started_at?: string | undefined;
44
+ ended_at?: string | undefined;
45
+ turns?: any[] | undefined;
46
+ turn_count?: number | undefined;
47
+ tool_call_count?: number | undefined;
48
+ has_tool_calls?: boolean | undefined;
49
+ has_thinking_blocks?: boolean | undefined;
50
+ has_file_changes?: boolean | undefined;
51
+ has_shell_commands?: boolean | undefined;
52
+ total_input_tokens?: number | null | undefined;
53
+ total_output_tokens?: number | null | undefined;
54
+ total_cache_read_tokens?: number | null | undefined;
55
+ content_fidelity?: "full" | "chat_only" | undefined;
56
+ env_state?: any;
57
+ score?: any;
58
+ raw_r2_key?: string | undefined;
59
+ normalized_r2_key?: string | undefined;
60
+ }, {
61
+ source_tool: "claude_code" | "codex_cli" | "cursor";
62
+ source_session_id: string;
63
+ trace_id?: string | undefined;
64
+ schema_version?: string | undefined;
65
+ source_version?: string | null | undefined;
66
+ submitted_by?: string | undefined;
67
+ submitted_at?: string | undefined;
68
+ extracted_at?: string | undefined;
69
+ git_branch?: string | null | undefined;
70
+ cwd_hash?: string | null | undefined;
71
+ working_language?: string | null | undefined;
72
+ started_at?: string | undefined;
73
+ ended_at?: string | undefined;
74
+ turns?: any[] | undefined;
75
+ turn_count?: number | undefined;
76
+ tool_call_count?: number | undefined;
77
+ has_tool_calls?: boolean | undefined;
78
+ has_thinking_blocks?: boolean | undefined;
79
+ has_file_changes?: boolean | undefined;
80
+ has_shell_commands?: boolean | undefined;
81
+ total_input_tokens?: number | null | undefined;
82
+ total_output_tokens?: number | null | undefined;
83
+ total_cache_read_tokens?: number | null | undefined;
84
+ content_fidelity?: "full" | "chat_only" | undefined;
85
+ env_state?: any;
86
+ score?: any;
87
+ raw_r2_key?: string | undefined;
88
+ normalized_r2_key?: string | undefined;
89
+ }>;
90
+ export type NormalizedTraceInput = z.infer<typeof NormalizedTraceSchema>;
91
+ export declare const BatchSubmitSchema: z.ZodObject<{
92
+ traces: z.ZodArray<z.ZodObject<{
93
+ trace_id: z.ZodOptional<z.ZodString>;
94
+ schema_version: z.ZodOptional<z.ZodString>;
95
+ source_tool: z.ZodEnum<["claude_code", "codex_cli", "cursor"]>;
96
+ source_session_id: z.ZodString;
97
+ source_version: z.ZodOptional<z.ZodNullable<z.ZodString>>;
98
+ submitted_by: z.ZodOptional<z.ZodString>;
99
+ submitted_at: z.ZodOptional<z.ZodString>;
100
+ extracted_at: z.ZodOptional<z.ZodString>;
101
+ git_branch: z.ZodOptional<z.ZodNullable<z.ZodString>>;
102
+ cwd_hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
103
+ working_language: z.ZodOptional<z.ZodNullable<z.ZodString>>;
104
+ started_at: z.ZodOptional<z.ZodString>;
105
+ ended_at: z.ZodOptional<z.ZodString>;
106
+ turns: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
107
+ turn_count: z.ZodOptional<z.ZodNumber>;
108
+ tool_call_count: z.ZodOptional<z.ZodNumber>;
109
+ has_tool_calls: z.ZodOptional<z.ZodBoolean>;
110
+ has_thinking_blocks: z.ZodOptional<z.ZodBoolean>;
111
+ has_file_changes: z.ZodOptional<z.ZodBoolean>;
112
+ has_shell_commands: z.ZodOptional<z.ZodBoolean>;
113
+ total_input_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
114
+ total_output_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
115
+ total_cache_read_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
116
+ content_fidelity: z.ZodOptional<z.ZodEnum<["full", "chat_only"]>>;
117
+ env_state: z.ZodOptional<z.ZodNullable<z.ZodAny>>;
118
+ score: z.ZodOptional<z.ZodNullable<z.ZodAny>>;
119
+ raw_r2_key: z.ZodOptional<z.ZodString>;
120
+ normalized_r2_key: z.ZodOptional<z.ZodString>;
121
+ }, "strip", z.ZodTypeAny, {
122
+ source_tool: "claude_code" | "codex_cli" | "cursor";
123
+ source_session_id: string;
124
+ trace_id?: string | undefined;
125
+ schema_version?: string | undefined;
126
+ source_version?: string | null | undefined;
127
+ submitted_by?: string | undefined;
128
+ submitted_at?: string | undefined;
129
+ extracted_at?: string | undefined;
130
+ git_branch?: string | null | undefined;
131
+ cwd_hash?: string | null | undefined;
132
+ working_language?: string | null | undefined;
133
+ started_at?: string | undefined;
134
+ ended_at?: string | undefined;
135
+ turns?: any[] | undefined;
136
+ turn_count?: number | undefined;
137
+ tool_call_count?: number | undefined;
138
+ has_tool_calls?: boolean | undefined;
139
+ has_thinking_blocks?: boolean | undefined;
140
+ has_file_changes?: boolean | undefined;
141
+ has_shell_commands?: boolean | undefined;
142
+ total_input_tokens?: number | null | undefined;
143
+ total_output_tokens?: number | null | undefined;
144
+ total_cache_read_tokens?: number | null | undefined;
145
+ content_fidelity?: "full" | "chat_only" | undefined;
146
+ env_state?: any;
147
+ score?: any;
148
+ raw_r2_key?: string | undefined;
149
+ normalized_r2_key?: string | undefined;
150
+ }, {
151
+ source_tool: "claude_code" | "codex_cli" | "cursor";
152
+ source_session_id: string;
153
+ trace_id?: string | undefined;
154
+ schema_version?: string | undefined;
155
+ source_version?: string | null | undefined;
156
+ submitted_by?: string | undefined;
157
+ submitted_at?: string | undefined;
158
+ extracted_at?: string | undefined;
159
+ git_branch?: string | null | undefined;
160
+ cwd_hash?: string | null | undefined;
161
+ working_language?: string | null | undefined;
162
+ started_at?: string | undefined;
163
+ ended_at?: string | undefined;
164
+ turns?: any[] | undefined;
165
+ turn_count?: number | undefined;
166
+ tool_call_count?: number | undefined;
167
+ has_tool_calls?: boolean | undefined;
168
+ has_thinking_blocks?: boolean | undefined;
169
+ has_file_changes?: boolean | undefined;
170
+ has_shell_commands?: boolean | undefined;
171
+ total_input_tokens?: number | null | undefined;
172
+ total_output_tokens?: number | null | undefined;
173
+ total_cache_read_tokens?: number | null | undefined;
174
+ content_fidelity?: "full" | "chat_only" | undefined;
175
+ env_state?: any;
176
+ score?: any;
177
+ raw_r2_key?: string | undefined;
178
+ normalized_r2_key?: string | undefined;
179
+ }>, "many">;
180
+ source_tool: z.ZodOptional<z.ZodEnum<["claude_code", "codex_cli", "cursor"]>>;
181
+ }, "strip", z.ZodTypeAny, {
182
+ traces: {
183
+ source_tool: "claude_code" | "codex_cli" | "cursor";
184
+ source_session_id: string;
185
+ trace_id?: string | undefined;
186
+ schema_version?: string | undefined;
187
+ source_version?: string | null | undefined;
188
+ submitted_by?: string | undefined;
189
+ submitted_at?: string | undefined;
190
+ extracted_at?: string | undefined;
191
+ git_branch?: string | null | undefined;
192
+ cwd_hash?: string | null | undefined;
193
+ working_language?: string | null | undefined;
194
+ started_at?: string | undefined;
195
+ ended_at?: string | undefined;
196
+ turns?: any[] | undefined;
197
+ turn_count?: number | undefined;
198
+ tool_call_count?: number | undefined;
199
+ has_tool_calls?: boolean | undefined;
200
+ has_thinking_blocks?: boolean | undefined;
201
+ has_file_changes?: boolean | undefined;
202
+ has_shell_commands?: boolean | undefined;
203
+ total_input_tokens?: number | null | undefined;
204
+ total_output_tokens?: number | null | undefined;
205
+ total_cache_read_tokens?: number | null | undefined;
206
+ content_fidelity?: "full" | "chat_only" | undefined;
207
+ env_state?: any;
208
+ score?: any;
209
+ raw_r2_key?: string | undefined;
210
+ normalized_r2_key?: string | undefined;
211
+ }[];
212
+ source_tool?: "claude_code" | "codex_cli" | "cursor" | undefined;
213
+ }, {
214
+ traces: {
215
+ source_tool: "claude_code" | "codex_cli" | "cursor";
216
+ source_session_id: string;
217
+ trace_id?: string | undefined;
218
+ schema_version?: string | undefined;
219
+ source_version?: string | null | undefined;
220
+ submitted_by?: string | undefined;
221
+ submitted_at?: string | undefined;
222
+ extracted_at?: string | undefined;
223
+ git_branch?: string | null | undefined;
224
+ cwd_hash?: string | null | undefined;
225
+ working_language?: string | null | undefined;
226
+ started_at?: string | undefined;
227
+ ended_at?: string | undefined;
228
+ turns?: any[] | undefined;
229
+ turn_count?: number | undefined;
230
+ tool_call_count?: number | undefined;
231
+ has_tool_calls?: boolean | undefined;
232
+ has_thinking_blocks?: boolean | undefined;
233
+ has_file_changes?: boolean | undefined;
234
+ has_shell_commands?: boolean | undefined;
235
+ total_input_tokens?: number | null | undefined;
236
+ total_output_tokens?: number | null | undefined;
237
+ total_cache_read_tokens?: number | null | undefined;
238
+ content_fidelity?: "full" | "chat_only" | undefined;
239
+ env_state?: any;
240
+ score?: any;
241
+ raw_r2_key?: string | undefined;
242
+ normalized_r2_key?: string | undefined;
243
+ }[];
244
+ source_tool?: "claude_code" | "codex_cli" | "cursor" | undefined;
245
+ }>;
246
+ export type BatchSubmitInput = z.infer<typeof BatchSubmitSchema>;
247
+ //# sourceMappingURL=validators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6BhC,CAAC;AAEH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEzE,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAG5B,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { z } from "zod";
2
+ export const NormalizedTraceSchema = z.object({
3
+ trace_id: z.string().optional(),
4
+ schema_version: z.string().optional(),
5
+ source_tool: z.enum(["claude_code", "codex_cli", "cursor"]),
6
+ source_session_id: z.string().min(1),
7
+ source_version: z.string().nullable().optional(),
8
+ submitted_by: z.string().optional(),
9
+ submitted_at: z.string().optional(),
10
+ extracted_at: z.string().optional(),
11
+ git_branch: z.string().nullable().optional(),
12
+ cwd_hash: z.string().nullable().optional(),
13
+ working_language: z.string().nullable().optional(),
14
+ started_at: z.string().optional(),
15
+ ended_at: z.string().optional(),
16
+ turns: z.array(z.any()).optional(),
17
+ turn_count: z.number().int().nonnegative().optional(),
18
+ tool_call_count: z.number().int().nonnegative().optional(),
19
+ has_tool_calls: z.boolean().optional(),
20
+ has_thinking_blocks: z.boolean().optional(),
21
+ has_file_changes: z.boolean().optional(),
22
+ has_shell_commands: z.boolean().optional(),
23
+ total_input_tokens: z.number().nullable().optional(),
24
+ total_output_tokens: z.number().nullable().optional(),
25
+ total_cache_read_tokens: z.number().nullable().optional(),
26
+ content_fidelity: z.enum(["full", "chat_only"]).optional(),
27
+ env_state: z.any().nullable().optional(),
28
+ score: z.any().nullable().optional(),
29
+ raw_r2_key: z.string().optional(),
30
+ normalized_r2_key: z.string().optional(),
31
+ });
32
+ export const BatchSubmitSchema = z.object({
33
+ traces: z.array(NormalizedTraceSchema).min(1),
34
+ source_tool: z.enum(["claude_code", "codex_cli", "cursor"]).optional(),
35
+ });
36
+ //# sourceMappingURL=validators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.js","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACrC,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;IAC3D,iBAAiB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACpC,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;IAChD,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACnC,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACnC,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACnC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;IAC5C,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;IAC1C,gBAAgB,EAAE,CAAC,CAAC,M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C,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACjC,iBAAiB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACzC,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7C,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAE;CACvE,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=validators.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.test.d.ts","sourceRoot":"","sources":["../src/validators.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,52 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { BatchSubmitSchema, NormalizedTraceSchema } from "./validators.js";
3
+ function makeTrace(overrides = {}) {
4
+ return {
5
+ source_tool: "claude_code",
6
+ source_session_id: "session-abc-123",
7
+ ...overrides,
8
+ };
9
+ }
10
+ describe("NormalizedTraceSchema", () => {
11
+ it("valid minimal trace → success", () => {
12
+ const result = NormalizedTraceSchema.safeParse(makeTrace());
13
+ expect(result.success).toBe(true);
14
+ });
15
+ it("missing source_tool → ZodError", () => {
16
+ const result = NormalizedTraceSchema.safeParse({ source_session_id: "abc" });
17
+ expect(result.success).toBe(false);
18
+ });
19
+ it("missing source_session_id → ZodError", () => {
20
+ const result = NormalizedTraceSchema.safeParse({ source_tool: "claude_code" });
21
+ expect(result.success).toBe(false);
22
+ });
23
+ it("invalid content_fidelity → ZodError", () => {
24
+ const result = NormalizedTraceSchema.safeParse(makeTrace({ content_fidelity: "high_fidelity" }));
25
+ expect(result.success).toBe(false);
26
+ });
27
+ it("negative turn_count → ZodError", () => {
28
+ const result = NormalizedTraceSchema.safeParse(makeTrace({ turn_count: -1 }));
29
+ expect(result.success).toBe(false);
30
+ });
31
+ });
32
+ describe("BatchSubmitSchema", () => {
33
+ it("valid batch → success", () => {
34
+ const result = BatchSubmitSchema.safeParse({ traces: [makeTrace()] });
35
+ expect(result.success).toBe(true);
36
+ });
37
+ it("empty traces array → ZodError", () => {
38
+ const result = BatchSubmitSchema.safeParse({ traces: [] });
39
+ expect(result.success).toBe(false);
40
+ });
41
+ it("missing traces → ZodError", () => {
42
+ const result = BatchSubmitSchema.safeParse({});
43
+ expect(result.success).toBe(false);
44
+ });
45
+ it("invalid source_tool in batch → ZodError", () => {
46
+ const result = BatchSubmitSchema.safeParse({
47
+ traces: [{ source_tool: "vscode", source_session_id: "abc" }],
48
+ });
49
+ expect(result.success).toBe(false);
50
+ });
51
+ });
52
+ //# sourceMappingURL=validators.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.test.js","sourceRoot":"","sources":["../src/validators.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE3E,SAAS,SAAS,CAAC,YAAqC,EAAE;IACxD,OAAO;QACL,WAAW,EAAE,aAAa;QAC1B,iBAAiB,EAAE,iBAAiB;QACpC,GAAG,SAAS;KACb,CAAC;AACJ,CAAC;AAED,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,EAAE,CAAC,+BAA+B,EAAE,GAAG,EAAE;QACvC,MAAM,MAAM,GAAG,qBAAqB,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC,CAAC;QAC5D,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gCAAgC,EAAE,GAAG,E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CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+BAA+B,EAAE,GAAG,EAAE;QACvC,MAAM,MAAM,GAAG,iBAAiB,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;QAC3D,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2BAA2B,EAAE,GAAG,EAAE;QACnC,MAAM,MAAM,GAAG,iBAAiB,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QAC/C,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;QACjD,MAAM,MAAM,GAAG,iBAAiB,CAAC,SAAS,CAAC;YACzC,MAAM,EAAE,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC;SAC9D,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@tracemarketplace/shared",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.js",
10
+ "types": "./dist/index.d.ts"
11
+ },
12
+ "./utils": {
13
+ "import": "./dist/utils.js",
14
+ "types": "./dist/utils.d.ts"
15
+ },
16
+ "./validators": {
17
+ "import": "./dist/validators.js",
18
+ "types": "./dist/validators.d.ts"
19
+ },
20
+ "./types": {
21
+ "import": "./dist/types.js",
22
+ "types": "./dist/types.d.ts"
23
+ }
24
+ },
25
+ "scripts": {
26
+ "build": "tsc",
27
+ "typecheck": "tsc --noEmit",
28
+ "test": "vitest run",
29
+ "test:watch": "vitest"
30
+ },
31
+ "devDependencies": {
32
+ "@types/better-sqlite3": "^7.6.0",
33
+ "@types/node": "^22.0.0",
34
+ "typescript": "^5.4.0",
35
+ "vitest": "^1.0.0"
36
+ },
37
+ "dependencies": {
38
+ "better-sqlite3": "^12.8.0",
39
+ "fzstd": "^0.1.1",
40
+ "zod": "^3.22.0"
41
+ }
42
+ }
@@ -0,0 +1,178 @@
1
+ import { createReadStream } from "fs";
2
+ import { createInterface } from "readline";
3
+ import { randomUUID } from "crypto";
4
+ import { hashString, computeContentHash } from "../hash.js";
5
+ import type {
6
+ NormalizedTrace,
7
+ Turn,
8
+ ContentBlock,
9
+ TokenUsage,
10
+ } from "../types.js";
11
+
12
+ export async function extractClaudeCode(
13
+ sessionFilePath: string,
14
+ submittedBy = "unknown"
15
+ ): Promise<NormalizedTrace> {
16
+ const lines: any[] = [];
17
+ const rl = createInterface({
18
+ input: createReadStream(sessionFilePath),
19
+ crlfDelay: Infinity,
20
+ });
21
+ for await (const line of rl) {
22
+ if (!line.trim()) continue;
23
+ try {
24
+ lines.push(JSON.parse(line));
25
+ } catch {}
26
+ }
27
+
28
+ const sessionId =
29
+ sessionFilePath.split("/").pop()?.replace(".jsonl", "") ?? randomUUID();
30
+ const turns: Turn[] = [];
31
+
32
+ let totalInputTokens = 0;
33
+ let totalOutputTokens = 0;
34
+ let totalCacheReadTokens = 0;
35
+ let gitBranch: string | null = null;
36
+ let cwdHash: string | null = null;
37
+
38
+ for (const line of lines) {
39
+ if (!line.message) continue;
40
+ const { role, content, usage, model } = line.message;
41
+
42
+ const tokenUsage: TokenUsage | null = usage
43
+ ? {
44
+ input_tokens: usage.input_tokens ?? 0,
45
+ output_tokens: usage.output_tokens ?? 0,
46
+ cache_read_input_tokens: usage.cache_read_input_tokens ?? null,
47
+ cache_creation_input_tokens:
48
+ usage.cache_creation_input_tokens ?? null,
49
+ reasoning_tokens: null,
50
+ }
51
+ : null;
52
+ if (tokenUsage) {
53
+ totalInputTokens += tokenUsage.input_tokens;
54
+ totalOutputTokens += tokenUsage.output_tokens;
55
+ totalCacheReadTokens += tokenUsage.cache_read_input_tokens ?? 0;
56
+ }
57
+
58
+ if (line.gitBranch) gitBranch = line.gitBranch;
59
+ if (line.cwd && !cwdHash) cwdHash = hashString(line.cwd);
60
+
61
+ const contentBlocks: ContentBlock[] = [];
62
+ const rawContent = Array.isArray(content)
63
+ ? content
64
+ : typeof content === "string"
65
+ ? [{ type: "text", text: content }]
66
+ : [];
67
+
68
+ for (const block of rawContent) {
69
+ if (!block || !block.type) continue;
70
+ if (block.type === "file-history-snapshot") continue;
71
+ if (block.type === "text") {
72
+ contentBlocks.push({ type: "text", text: block.text ?? "" });
73
+ } else if (block.type === "thinking") {
74
+ contentBlocks.push({
75
+ type: "thinking",
76
+ text: block.thinking ?? block.text ?? "",
77
+ });
78
+ } else if (block.type === "tool_use") {
79
+ contentBlocks.push({
80
+ type: "tool_use",
81
+ tool_call_id: block.id ?? randomUUID(),
82
+ tool_name: block.name ?? "",
83
+ tool_input: block.input ?? {},
84
+ });
85
+ } else if (block.type === "tool_result") {
86
+ const resultContent = Array.isArray(block.content)
87
+ ? block.content.map((c: any) => c.text ?? "").join("\n")
88
+ : block.content ?? null;
89
+ contentBlocks.push({
90
+ type: "tool_result",
91
+ tool_call_id: block.tool_use_id ?? "",
92
+ is_error: block.is_error ?? false,
93
+ result_content: resultContent,
94
+ exit_code: null,
95
+ });
96
+ }
97
+ }
98
+
99
+ if (contentBlocks.length === 0) continue;
100
+
101
+ turns.push({
102
+ turn_id: line.uuid ?? randomUUID(),
103
+ parent_turn_id: line.parentUuid ?? null,
104
+ role: role === "assistant" ? "assistant" : "user",
105
+ timestamp: line.timestamp ?? null,
106
+ content: contentBlocks,
107
+ model: model ?? null,
108
+ usage: tokenUsage,
109
+ source_metadata: {
110
+ uuid: line.uuid,
111
+ parentUuid: line.parentUuid,
112
+ gitBranch: line.gitBranch,
113
+ },
114
+ });
115
+ }
116
+
117
+ const startedAt = turns[0]?.timestamp ?? new Date().toISOString();
118
+ const endedAt = turns[turns.length - 1]?.timestamp ?? new Date().toISOString();
119
+
120
+ const allBlocks = turns.flatMap((t) => t.content);
121
+ const toolCallCount = allBlocks.filter((b) => b.type === "tool_use").length;
122
+ const hasFileChanges = allBlocks.some(
123
+ (b) =>
124
+ b.type === "tool_use" &&
125
+ ((b as any).tool_name?.toLowerCase().includes("write") ||
126
+ (b as any).tool_name?.toLowerCase().includes("edit"))
127
+ );
128
+ const hasShellCommands = allBlocks.some(
129
+ (b) =>
130
+ b.type === "tool_use" &&
131
+ ((b as any).tool_name?.toLowerCase().includes("bash") ||
132
+ (b as any).tool_name?.toLowerCase().includes("exec"))
133
+ );
134
+ const hasThinking = allBlocks.some((b) => b.type === "thinking");
135
+
136
+ const partialTrace: Omit<NormalizedTrace, "trace_id"> = {
137
+ schema_version: "1.0",
138
+ source_tool: "claude_code",
139
+ source_session_id: sessionId,
140
+ source_version: null,
141
+ submitted_by: submittedBy,
142
+ submitted_at: new Date().toISOString(),
143
+ extracted_at: new Date().toISOString(),
144
+ git_branch: gitBranch,
145
+ cwd_hash: cwdHash,
146
+ working_language: null,
147
+ started_at: startedAt,
148
+ ended_at: endedAt,
149
+ turns,
150
+ turn_count: turns.length,
151
+ tool_call_count: toolCallCount,
152
+ has_tool_calls: toolCallCount > 0,
153
+ has_thinking_blocks: hasThinking,
154
+ has_file_changes: hasFileChanges,
155
+ has_shell_commands: hasShellCommands,
156
+ total_input_tokens: totalInputTokens || null,
157
+ total_output_tokens: totalOutputTokens || null,
158
+ total_cache_read_tokens: totalCacheReadTokens || null,
159
+ content_fidelity: "full",
160
+ env_state: {
161
+ git_branch: gitBranch,
162
+ inferred_file_tree: null,
163
+ inferred_changed_files: null,
164
+ inferred_error_files: null,
165
+ shell_exit_codes: null,
166
+ open_files_in_editor: null,
167
+ extraction_method: "passive",
168
+ },
169
+ score: null,
170
+ raw_r2_key: "",
171
+ normalized_r2_key: "",
172
+ };
173
+
174
+ const contentHash = computeContentHash(partialTrace as NormalizedTrace);
175
+ const traceId = hashString("claude_code" + sessionId + contentHash);
176
+
177
+ return { ...partialTrace, trace_id: traceId };
178
+ }