@tracemarketplace/cli 0.0.13 → 0.0.17
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/dist/api-client.d.ts +9 -2
- package/dist/api-client.d.ts.map +1 -1
- package/dist/api-client.js +80 -15
- package/dist/api-client.js.map +1 -1
- package/dist/api-client.test.d.ts +2 -0
- package/dist/api-client.test.d.ts.map +1 -0
- package/dist/api-client.test.js +34 -0
- package/dist/api-client.test.js.map +1 -0
- package/dist/cli.js +48 -18
- package/dist/cli.js.map +1 -1
- package/dist/commands/auto-submit.d.ts +2 -1
- package/dist/commands/auto-submit.d.ts.map +1 -1
- package/dist/commands/auto-submit.js +43 -56
- package/dist/commands/auto-submit.js.map +1 -1
- package/dist/commands/daemon.d.ts +8 -1
- package/dist/commands/daemon.d.ts.map +1 -1
- package/dist/commands/daemon.js +184 -63
- package/dist/commands/daemon.js.map +1 -1
- package/dist/commands/history.d.ts +3 -1
- package/dist/commands/history.d.ts.map +1 -1
- package/dist/commands/history.js +8 -4
- package/dist/commands/history.js.map +1 -1
- package/dist/commands/login.d.ts +5 -1
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +25 -9
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/register.d.ts +1 -0
- package/dist/commands/register.d.ts.map +1 -1
- package/dist/commands/register.js +4 -39
- package/dist/commands/register.js.map +1 -1
- package/dist/commands/remove-daemon.d.ts +6 -0
- package/dist/commands/remove-daemon.d.ts.map +1 -0
- package/dist/commands/remove-daemon.js +66 -0
- package/dist/commands/remove-daemon.js.map +1 -0
- package/dist/commands/remove-hook.d.ts +6 -0
- package/dist/commands/remove-hook.d.ts.map +1 -0
- package/dist/commands/remove-hook.js +174 -0
- package/dist/commands/remove-hook.js.map +1 -0
- package/dist/commands/setup-hook.d.ts +2 -0
- package/dist/commands/setup-hook.d.ts.map +1 -1
- package/dist/commands/setup-hook.js +85 -41
- package/dist/commands/setup-hook.js.map +1 -1
- package/dist/commands/status.d.ts +3 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +8 -4
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/submit.d.ts +1 -0
- package/dist/commands/submit.d.ts.map +1 -1
- package/dist/commands/submit.js +138 -83
- package/dist/commands/submit.js.map +1 -1
- package/dist/commands/whoami.d.ts +3 -1
- package/dist/commands/whoami.d.ts.map +1 -1
- package/dist/commands/whoami.js +8 -4
- package/dist/commands/whoami.js.map +1 -1
- package/dist/config.d.ts +38 -6
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +175 -17
- package/dist/config.js.map +1 -1
- package/dist/constants.d.ts +8 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +16 -0
- package/dist/constants.js.map +1 -0
- package/dist/flush.d.ts +49 -0
- package/dist/flush.d.ts.map +1 -0
- package/dist/flush.js +405 -0
- package/dist/flush.js.map +1 -0
- package/dist/flush.test.d.ts +2 -0
- package/dist/flush.test.d.ts.map +1 -0
- package/dist/flush.test.js +330 -0
- package/dist/flush.test.js.map +1 -0
- package/dist/submitter.d.ts.map +1 -1
- package/dist/submitter.js +5 -2
- package/dist/submitter.js.map +1 -1
- package/package.json +8 -7
- package/src/api-client.test.ts +47 -0
- package/src/api-client.ts +100 -16
- package/src/cli.ts +55 -19
- package/src/commands/auto-submit.ts +80 -40
- package/src/commands/daemon.ts +243 -60
- package/src/commands/history.ts +9 -4
- package/src/commands/login.ts +37 -9
- package/src/commands/remove-daemon.ts +75 -0
- package/src/commands/remove-hook.ts +194 -0
- package/src/commands/setup-hook.ts +93 -43
- package/src/commands/status.ts +8 -4
- package/src/commands/submit.ts +191 -83
- package/src/commands/whoami.ts +8 -4
- package/src/config.ts +241 -21
- package/src/constants.ts +18 -0
- package/src/flush.test.ts +395 -0
- package/src/flush.ts +591 -0
- package/vitest.config.ts +8 -0
- package/src/commands/register.ts +0 -52
- package/src/submitter.ts +0 -110
package/src/submitter.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* submitter.ts — extract one session file and submit it to the API.
|
|
3
|
-
* Shared by auto-submit (hook), submit (batch), and daemon (watch).
|
|
4
|
-
*/
|
|
5
|
-
import { readFile } from "fs/promises";
|
|
6
|
-
import { homedir } from "os";
|
|
7
|
-
import { extractClaudeCode, extractCodex, extractCursor, redactTrace, chunkTrace, type NormalizedTrace } from "@tracemarketplace/shared";
|
|
8
|
-
import { ApiClient } from "./api-client.js";
|
|
9
|
-
import { CURSOR_DB_PATH } from "./sessions.js";
|
|
10
|
-
import { loadState, saveState, stateKey } from "./config.js";
|
|
11
|
-
import type { Config } from "./config.js";
|
|
12
|
-
|
|
13
|
-
export interface SubmitResult {
|
|
14
|
-
accepted: boolean;
|
|
15
|
-
superseded: boolean;
|
|
16
|
-
duplicate: boolean;
|
|
17
|
-
turnCount: number;
|
|
18
|
-
payoutCents: number;
|
|
19
|
-
traceId: string | null;
|
|
20
|
-
error?: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Extract a claude_code or codex_cli session from a file path and submit it.
|
|
25
|
-
*/
|
|
26
|
-
export async function submitFile(
|
|
27
|
-
tool: "claude_code" | "codex_cli",
|
|
28
|
-
filePath: string,
|
|
29
|
-
config: Config
|
|
30
|
-
): Promise<SubmitResult> {
|
|
31
|
-
let trace;
|
|
32
|
-
try {
|
|
33
|
-
if (tool === "claude_code") {
|
|
34
|
-
trace = await extractClaudeCode(filePath, config.email);
|
|
35
|
-
} else {
|
|
36
|
-
const buf = await readFile(filePath);
|
|
37
|
-
trace = await extractCodex(buf, config.email);
|
|
38
|
-
}
|
|
39
|
-
} catch (err) {
|
|
40
|
-
return { accepted: false, superseded: false, duplicate: false, turnCount: 0, payoutCents: 0, traceId: null, error: `Extraction failed: ${err}` };
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (trace.turn_count === 0) {
|
|
44
|
-
return { accepted: false, superseded: false, duplicate: false, turnCount: 0, payoutCents: 0, traceId: null, error: "Empty session" };
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return submitTrace(trace, config);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Extract a Cursor session by session ID and submit it.
|
|
52
|
-
*/
|
|
53
|
-
export async function submitCursorSession(
|
|
54
|
-
sessionId: string,
|
|
55
|
-
config: Config
|
|
56
|
-
): Promise<SubmitResult> {
|
|
57
|
-
let trace;
|
|
58
|
-
try {
|
|
59
|
-
trace = await extractCursor(CURSOR_DB_PATH, sessionId, config.email);
|
|
60
|
-
} catch (err) {
|
|
61
|
-
return { accepted: false, superseded: false, duplicate: false, turnCount: 0, payoutCents: 0, traceId: null, error: `Cursor extraction failed: ${err}` };
|
|
62
|
-
}
|
|
63
|
-
return submitTrace(trace, config);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async function submitTrace(trace: Awaited<ReturnType<typeof extractClaudeCode>>, config: Config): Promise<SubmitResult> {
|
|
67
|
-
const state = loadState();
|
|
68
|
-
const key = stateKey(trace.source_tool, trace.source_session_id);
|
|
69
|
-
const lastSubmittedChunk = state.chunks[key] ?? -1;
|
|
70
|
-
|
|
71
|
-
// Chunk the session and only send new chunks
|
|
72
|
-
const chunks = chunkTrace(trace);
|
|
73
|
-
const newChunks = chunks.filter((c) => (c.chunk_index ?? 0) > lastSubmittedChunk);
|
|
74
|
-
|
|
75
|
-
if (newChunks.length === 0) {
|
|
76
|
-
return { accepted: false, superseded: false, duplicate: true, turnCount: trace.turn_count, payoutCents: 0, traceId: null };
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const home = homedir();
|
|
80
|
-
const client = new ApiClient(config.serverUrl, config.apiKey);
|
|
81
|
-
|
|
82
|
-
try {
|
|
83
|
-
const result = await client.post("/api/v1/traces/batch", {
|
|
84
|
-
traces: newChunks.map((c) => redactTrace(c, { homeDir: home })),
|
|
85
|
-
source_tool: trace.source_tool,
|
|
86
|
-
}) as {
|
|
87
|
-
accepted: number;
|
|
88
|
-
duplicate: number;
|
|
89
|
-
traces: Array<{ trace_id?: string; payout_cents?: number }>;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
// Persist the highest chunk index we successfully submitted
|
|
93
|
-
const maxChunk = Math.max(...newChunks.map((c) => c.chunk_index ?? 0));
|
|
94
|
-
state.chunks[key] = maxChunk;
|
|
95
|
-
saveState(state);
|
|
96
|
-
|
|
97
|
-
const totalPayout = result.traces?.reduce((s, t) => s + (t.payout_cents ?? 0), 0) ?? 0;
|
|
98
|
-
const first = result.traces?.[0];
|
|
99
|
-
return {
|
|
100
|
-
accepted: result.accepted > 0,
|
|
101
|
-
superseded: false,
|
|
102
|
-
duplicate: result.duplicate > 0 && result.accepted === 0,
|
|
103
|
-
turnCount: trace.turn_count,
|
|
104
|
-
payoutCents: totalPayout,
|
|
105
|
-
traceId: first?.trace_id ?? null,
|
|
106
|
-
};
|
|
107
|
-
} catch (err) {
|
|
108
|
-
return { accepted: false, superseded: false, duplicate: false, turnCount: trace.turn_count, payoutCents: 0, traceId: null, error: `Submit failed: ${err}` };
|
|
109
|
-
}
|
|
110
|
-
}
|