@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/dist/api-client.d.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
+
export declare class ApiError extends Error {
|
|
2
|
+
readonly status: number;
|
|
3
|
+
readonly body: unknown;
|
|
4
|
+
readonly retryAfterSeconds: number | null;
|
|
5
|
+
constructor(message: string, status: number, body: unknown, retryAfterSeconds: number | null);
|
|
6
|
+
}
|
|
1
7
|
export declare class ApiClient {
|
|
2
8
|
private baseUrl;
|
|
3
|
-
private apiKey
|
|
4
|
-
constructor(baseUrl: string, apiKey
|
|
9
|
+
private apiKey?;
|
|
10
|
+
constructor(baseUrl: string, apiKey?: string | undefined);
|
|
5
11
|
get(path: string): Promise<unknown>;
|
|
6
12
|
post(path: string, body: unknown): Promise<unknown>;
|
|
13
|
+
private request;
|
|
7
14
|
}
|
|
8
15
|
//# sourceMappingURL=api-client.d.ts.map
|
package/dist/api-client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAS;IAElB,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,MAAM;
|
|
1
|
+
{"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAS,SAAQ,KAAK;IAG/B,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,IAAI,EAAE,OAAO;IACtB,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI;gBAHzC,OAAO,EAAE,MAAM,EACN,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,iBAAiB,EAAE,MAAM,GAAG,IAAI;CAK5C;AAED,qBAAa,SAAS;IAElB,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,MAAM,CAAC;gBADP,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,MAAM,YAAA;IAGnB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAInC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;YAI3C,OAAO;CA2CtB"}
|
package/dist/api-client.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
export class ApiError extends Error {
|
|
2
|
+
status;
|
|
3
|
+
body;
|
|
4
|
+
retryAfterSeconds;
|
|
5
|
+
constructor(message, status, body, retryAfterSeconds) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.status = status;
|
|
8
|
+
this.body = body;
|
|
9
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
10
|
+
this.name = "ApiError";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
1
13
|
export class ApiClient {
|
|
2
14
|
baseUrl;
|
|
3
15
|
apiKey;
|
|
@@ -6,29 +18,82 @@ export class ApiClient {
|
|
|
6
18
|
this.apiKey = apiKey;
|
|
7
19
|
}
|
|
8
20
|
async get(path) {
|
|
9
|
-
|
|
10
|
-
headers: { "X-Api-Key": this.apiKey },
|
|
11
|
-
});
|
|
12
|
-
if (!res.ok) {
|
|
13
|
-
const text = await res.text();
|
|
14
|
-
throw new Error(`API error ${res.status}: ${text}`);
|
|
15
|
-
}
|
|
16
|
-
return res.json();
|
|
21
|
+
return this.request("GET", path);
|
|
17
22
|
}
|
|
18
23
|
async post(path, body) {
|
|
24
|
+
return this.request("POST", path, body);
|
|
25
|
+
}
|
|
26
|
+
async request(method, path, body) {
|
|
27
|
+
let reqBody;
|
|
28
|
+
const extraHeaders = {};
|
|
29
|
+
if (method === "POST" && body !== undefined) {
|
|
30
|
+
const json = JSON.stringify(body);
|
|
31
|
+
try {
|
|
32
|
+
const { gzip } = await import("zlib");
|
|
33
|
+
const buf = await new Promise((resolve, reject) => gzip(Buffer.from(json), (err, result) => err ? reject(err) : resolve(result)));
|
|
34
|
+
reqBody = new Uint8Array(buf);
|
|
35
|
+
extraHeaders["X-Content-Encoding"] = "gzip";
|
|
36
|
+
const ratio = Math.round((1 - buf.length / json.length) * 100);
|
|
37
|
+
console.error(`[gzip] ${Math.round(json.length / 1024)}KB → ${Math.round(buf.length / 1024)}KB (${ratio}% reduction)`);
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
console.error(`[gzip] compression failed, sending uncompressed: ${e}`);
|
|
41
|
+
reqBody = json;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
19
44
|
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
20
|
-
method
|
|
45
|
+
method,
|
|
21
46
|
headers: {
|
|
22
|
-
"Content-Type": "application/json",
|
|
23
|
-
"X-Api-Key": this.apiKey,
|
|
47
|
+
...(method === "POST" ? { "Content-Type": "application/json" } : {}),
|
|
48
|
+
...(this.apiKey ? { "X-Api-Key": this.apiKey } : {}),
|
|
49
|
+
...extraHeaders,
|
|
24
50
|
},
|
|
25
|
-
body:
|
|
51
|
+
body: reqBody,
|
|
26
52
|
});
|
|
53
|
+
const parsedBody = await parseResponseBody(res);
|
|
27
54
|
if (!res.ok) {
|
|
28
|
-
|
|
29
|
-
|
|
55
|
+
throw new ApiError(`API error ${res.status}: ${formatErrorBody(parsedBody)}`, res.status, parsedBody, parseRetryAfterHeader(res.headers.get("retry-after")));
|
|
56
|
+
}
|
|
57
|
+
return parsedBody;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async function parseResponseBody(res) {
|
|
61
|
+
const text = await res.text();
|
|
62
|
+
if (!text) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
return JSON.parse(text);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return text;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function formatErrorBody(body) {
|
|
73
|
+
if (typeof body === "string") {
|
|
74
|
+
return body;
|
|
75
|
+
}
|
|
76
|
+
if (body && typeof body === "object") {
|
|
77
|
+
const error = body.error;
|
|
78
|
+
if (typeof error === "string") {
|
|
79
|
+
return error;
|
|
30
80
|
}
|
|
31
|
-
return res.json();
|
|
32
81
|
}
|
|
82
|
+
return JSON.stringify(body);
|
|
83
|
+
}
|
|
84
|
+
function parseRetryAfterHeader(value) {
|
|
85
|
+
if (!value) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
const numeric = Number.parseInt(value, 10);
|
|
89
|
+
if (Number.isFinite(numeric)) {
|
|
90
|
+
return Math.max(0, numeric);
|
|
91
|
+
}
|
|
92
|
+
const dateMs = Date.parse(value);
|
|
93
|
+
if (Number.isNaN(dateMs)) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const seconds = Math.ceil((dateMs - Date.now()) / 1000);
|
|
97
|
+
return Math.max(0, seconds);
|
|
33
98
|
}
|
|
34
99
|
//# sourceMappingURL=api-client.js.map
|
package/dist/api-client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-client.js","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,SAAS;IAEV;IACA;IAFV,YACU,OAAe,EACf,
|
|
1
|
+
{"version":3,"file":"api-client.js","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,QAAS,SAAQ,KAAK;IAGtB;IACA;IACA;IAJX,YACE,OAAe,EACN,MAAc,EACd,IAAa,EACb,iBAAgC;QAEzC,KAAK,CAAC,OAAO,CAAC,CAAC;QAJN,WAAM,GAAN,MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,CAAS;QACb,sBAAiB,GAAjB,iBAAiB,CAAe;QAGzC,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AAED,MAAM,OAAO,SAAS;IAEV;IACA;IAFV,YACU,OAAe,EACf,MAAe;QADf,YAAO,GAAP,OAAO,CAAQ;QACf,WAAM,GAAN,MAAM,CAAS;IACtB,CAAC;IAEJ,KAAK,CAAC,GAAG,CAAC,IAAY;Q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3,"file":"api-client.test.d.ts","sourceRoot":"","sources":["../src/api-client.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { ApiClient } from "./api-client.js";
|
|
3
|
+
describe("ApiClient", () => {
|
|
4
|
+
const originalFetch = global.fetch;
|
|
5
|
+
afterEach(() => {
|
|
6
|
+
global.fetch = originalFetch;
|
|
7
|
+
vi.restoreAllMocks();
|
|
8
|
+
});
|
|
9
|
+
it("parses retry-after and json error bodies", async () => {
|
|
10
|
+
global.fetch = vi.fn().mockResolvedValue(new Response(JSON.stringify({ error: "busy" }), {
|
|
11
|
+
status: 503,
|
|
12
|
+
headers: {
|
|
13
|
+
"content-type": "application/json",
|
|
14
|
+
"retry-after": "12",
|
|
15
|
+
},
|
|
16
|
+
}));
|
|
17
|
+
const client = new ApiClient("https://example.test", "token");
|
|
18
|
+
await expect(client.post("/api/v1/traces/batch", {})).rejects.toEqual(expect.objectContaining({
|
|
19
|
+
name: "ApiError",
|
|
20
|
+
status: 503,
|
|
21
|
+
retryAfterSeconds: 12,
|
|
22
|
+
body: { error: "busy" },
|
|
23
|
+
}));
|
|
24
|
+
});
|
|
25
|
+
it("returns parsed json bodies on success", async () => {
|
|
26
|
+
global.fetch = vi.fn().mockResolvedValue(new Response(JSON.stringify({ ok: true }), {
|
|
27
|
+
status: 200,
|
|
28
|
+
headers: { "content-type": "application/json" },
|
|
29
|
+
}));
|
|
30
|
+
const client = new ApiClient("https://example.test", "token");
|
|
31
|
+
await expect(client.get("/health")).resolves.toEqual({ ok: true });
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=api-client.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.test.js","sourceRoot":"","sources":["../src/api-client.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,E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,CAAC,EAAE;YACzC,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;SAChD,CAAC,CACa,CAAC;QAElB,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,sBAAsB,EAAE,OAAO,CAAC,CAAC;QAE9D,MAAM,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;IACrE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
import { dirname, join } from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
2
5
|
import { program } from "commander";
|
|
3
6
|
import { loginCommand } from "./commands/login.js";
|
|
4
|
-
import { registerCommand } from "./commands/register.js";
|
|
5
7
|
import { whoamiCommand } from "./commands/whoami.js";
|
|
6
8
|
import { submitCommand } from "./commands/submit.js";
|
|
7
9
|
import { statusCommand } from "./commands/status.js";
|
|
@@ -9,31 +11,36 @@ import { historyCommand } from "./commands/history.js";
|
|
|
9
11
|
import { autoSubmitCommand } from "./commands/auto-submit.js";
|
|
10
12
|
import { setupHookCommand } from "./commands/setup-hook.js";
|
|
11
13
|
import { daemonCommand } from "./commands/daemon.js";
|
|
14
|
+
import { removeHookCommand } from "./commands/remove-hook.js";
|
|
15
|
+
import { removeDaemonCommand } from "./commands/remove-daemon.js";
|
|
16
|
+
import { CLI_NAME, DEFAULT_PROFILE, PROD_SERVER_URL } from "./constants.js";
|
|
17
|
+
const profileOptionDescription = `Config profile (default: ${DEFAULT_PROFILE})`;
|
|
18
|
+
const packageVersion = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), "../package.json"), "utf-8")).version;
|
|
12
19
|
program
|
|
13
|
-
.name(
|
|
20
|
+
.name(CLI_NAME)
|
|
14
21
|
.description("Trace Marketplace CLI — submit AI coding sessions, get paid")
|
|
15
|
-
.version(
|
|
22
|
+
.version(packageVersion);
|
|
16
23
|
program
|
|
17
24
|
.command("login")
|
|
18
|
-
.description("Sign in via browser
|
|
19
|
-
.
|
|
20
|
-
|
|
21
|
-
.
|
|
22
|
-
.description("Register your email and get an API key")
|
|
23
|
-
.option("--server-url <url>", "Server URL (default: https://trace-marketplace-api.fly.dev)")
|
|
24
|
-
.action((opts) => registerCommand({ serverUrl: opts.serverUrl }).catch(handleError));
|
|
25
|
+
.description("Sign in via browser and save your API key")
|
|
26
|
+
.option("--profile <name>", profileOptionDescription)
|
|
27
|
+
.option("--server-url <url>", `Server URL (default prod: ${PROD_SERVER_URL})`)
|
|
28
|
+
.action((opts) => loginCommand({ profile: opts.profile, serverUrl: opts.serverUrl }).catch(handleError));
|
|
25
29
|
program
|
|
26
30
|
.command("whoami")
|
|
27
31
|
.description("Show your account info and balance")
|
|
28
|
-
.
|
|
32
|
+
.option("--profile <name>", profileOptionDescription)
|
|
33
|
+
.action((opts) => whoamiCommand({ profile: opts.profile }).catch(handleError));
|
|
29
34
|
program
|
|
30
35
|
.command("submit")
|
|
31
36
|
.description("Auto-detect and submit traces from Claude Code, Codex CLI, and Cursor")
|
|
37
|
+
.option("--profile <name>", profileOptionDescription)
|
|
32
38
|
.option("--tool <tool>", "Only submit from specific tool (claude-code|codex|cursor)")
|
|
33
39
|
.option("--session <id>", "Only submit a specific session ID")
|
|
34
40
|
.option("--dry-run", "Preview without submitting")
|
|
35
41
|
.option("--created-since <duration>", "Only include sessions created within duration (e.g. 30d, 12h, 30m)", "30d")
|
|
36
42
|
.action((opts) => submitCommand({
|
|
43
|
+
profile: opts.profile,
|
|
37
44
|
tool: opts.tool,
|
|
38
45
|
session: opts.session,
|
|
39
46
|
dryRun: opts.dryRun,
|
|
@@ -42,27 +49,50 @@ program
|
|
|
42
49
|
program
|
|
43
50
|
.command("status")
|
|
44
51
|
.description("Show pending submissions and balance")
|
|
45
|
-
.
|
|
52
|
+
.option("--profile <name>", profileOptionDescription)
|
|
53
|
+
.action((opts) => statusCommand({ profile: opts.profile }).catch(handleError));
|
|
46
54
|
program
|
|
47
55
|
.command("history")
|
|
48
56
|
.description("Show submission history")
|
|
49
|
-
.
|
|
57
|
+
.option("--profile <name>", profileOptionDescription)
|
|
58
|
+
.action((opts) => historyCommand({ profile: opts.profile }).catch(handleError));
|
|
50
59
|
program
|
|
51
|
-
.command("auto-submit")
|
|
60
|
+
.command("auto-submit", { hidden: true })
|
|
52
61
|
.description("Submit the current session (called by tool hooks — do not run manually)")
|
|
62
|
+
.option("--profile <name>", profileOptionDescription)
|
|
53
63
|
.option("--tool <tool>", "Tool that triggered the hook (claude-code|cursor|codex)")
|
|
54
64
|
.option("--session <id>", "Session ID (for cursor/codex hooks)")
|
|
55
65
|
.option("--file <path>", "Direct path to session file (for claude-code)")
|
|
56
|
-
.action((opts) => autoSubmitCommand({ tool: opts.tool, session: opts.session, file: opts.file }));
|
|
66
|
+
.action((opts) => autoSubmitCommand({ profile: opts.profile, tool: opts.tool, session: opts.session, file: opts.file }));
|
|
57
67
|
program
|
|
58
68
|
.command("daemon")
|
|
59
|
-
.description("
|
|
60
|
-
.
|
|
69
|
+
.description("Poll for new sessions and auto-submit them; use --once for cron or --watch for live mode")
|
|
70
|
+
.option("--profile <name>", profileOptionDescription)
|
|
71
|
+
.option("--interval <seconds>", "Polling interval in seconds", "60")
|
|
72
|
+
.option("--once", "Run one polling pass and exit")
|
|
73
|
+
.option("--watch", "Use live filesystem watch mode instead of polling")
|
|
74
|
+
.action((opts) => daemonCommand({
|
|
75
|
+
profile: opts.profile,
|
|
76
|
+
interval: opts.interval,
|
|
77
|
+
once: opts.once,
|
|
78
|
+
watch: opts.watch,
|
|
79
|
+
}).catch(handleError));
|
|
61
80
|
program
|
|
62
81
|
.command("setup-hook")
|
|
63
82
|
.description("Install session-end hooks for Claude Code, Cursor, and Codex CLI")
|
|
83
|
+
.option("--profile <name>", profileOptionDescription)
|
|
64
84
|
.option("--tool <tool>", "Only set up hook for specific tool (claude-code|cursor|codex)")
|
|
65
|
-
.action((opts) => setupHookCommand({ tool: opts.tool }).catch(handleError));
|
|
85
|
+
.action((opts) => setupHookCommand({ profile: opts.profile, tool: opts.tool }).catch(handleError));
|
|
86
|
+
program
|
|
87
|
+
.command("remove-hook")
|
|
88
|
+
.description("Remove tracemp hooks from Claude Code, Cursor, and Codex CLI")
|
|
89
|
+
.option("--tool <tool>", "Only remove hook for specific tool (claude-code|cursor|codex)")
|
|
90
|
+
.action((opts) => removeHookCommand({ tool: opts.tool }).catch(handleError));
|
|
91
|
+
program
|
|
92
|
+
.command("remove-daemon")
|
|
93
|
+
.description("Stop a running tracemp daemon")
|
|
94
|
+
.option("--profile <name>", profileOptionDescription)
|
|
95
|
+
.action((opts) => removeDaemonCommand({ profile: opts.profile }).catch(handleError));
|
|
66
96
|
function handleError(e) {
|
|
67
97
|
console.error(e.message ?? String(e));
|
|
68
98
|
process.exit(1);
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAA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
4
5
|
file?: string;
|
|
5
6
|
}
|
|
6
|
-
export declare function log(msg: string): void;
|
|
7
|
+
export declare function log(msg: string, profile?: string): void;
|
|
7
8
|
export declare function autoSubmitCommand(opts: AutoSubmitOptions): Promise<void>;
|
|
8
9
|
export {};
|
|
9
10
|
//# sourceMappingURL=auto-submit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-submit.d.ts","sourceRoot":"","sources":["../../src/commands/auto-submit.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auto-submit.d.ts","sourceRoot":"","sources":["../../src/commands/auto-submit.ts"],"names":[],"mappings":"AAgBA,UAAU,iBAAiB;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,SAAkB,QAKzD;AAED,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAM9E"}
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* auto-submit — called by tool hooks (Claude Code Stop, Cursor sessionEnd).
|
|
3
3
|
* Non-interactive: never prompts, always exits 0 so it never blocks the user's tool.
|
|
4
|
-
* Logs results to ~/.config/tracemarketplace/auto-submit.log
|
|
4
|
+
* Logs results to ~/.config/tracemarketplace/auto-submit(.<profile>).log
|
|
5
5
|
*/
|
|
6
6
|
import { readFileSync, appendFileSync, mkdirSync } from "fs";
|
|
7
|
-
import {
|
|
8
|
-
import { join } from "path";
|
|
9
|
-
import { loadConfig } from "../config.js";
|
|
7
|
+
import { getAutoSubmitLogPath, getConfigDir, loadConfig, resolveProfile } from "../config.js";
|
|
10
8
|
import { findLatestFile, findCodexFileById } from "../sessions.js";
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
mkdirSync(
|
|
9
|
+
import { loginCommandForProfile, DEFAULT_PROFILE } from "../constants.js";
|
|
10
|
+
import { buildCursorSessionSource, buildFileSessionSource, flushTrackedSessions, } from "../flush.js";
|
|
11
|
+
export function log(msg, profile = DEFAULT_PROFILE) {
|
|
12
|
+
mkdirSync(getConfigDir(), { recursive: true });
|
|
15
13
|
try {
|
|
16
|
-
appendFileSync(
|
|
14
|
+
appendFileSync(getAutoSubmitLogPath(profile), `[${new Date().toISOString()}] ${msg}\n`);
|
|
17
15
|
}
|
|
18
16
|
catch { }
|
|
19
17
|
}
|
|
@@ -22,13 +20,14 @@ export async function autoSubmitCommand(opts) {
|
|
|
22
20
|
await run(opts);
|
|
23
21
|
}
|
|
24
22
|
catch (err) {
|
|
25
|
-
log(`ERROR: ${String(err)}
|
|
23
|
+
log(`ERROR: ${String(err)}`, resolveProfile(opts.profile));
|
|
26
24
|
}
|
|
27
25
|
}
|
|
28
26
|
async function run(opts) {
|
|
29
|
-
const
|
|
27
|
+
const profile = resolveProfile(opts.profile);
|
|
28
|
+
const config = loadConfig(profile);
|
|
30
29
|
if (!config) {
|
|
31
|
-
log(
|
|
30
|
+
log(`Not authenticated — run: ${loginCommandForProfile(profile)}`, profile);
|
|
32
31
|
return;
|
|
33
32
|
}
|
|
34
33
|
// Read hook payload from stdin
|
|
@@ -40,64 +39,52 @@ async function run(opts) {
|
|
|
40
39
|
}
|
|
41
40
|
catch { }
|
|
42
41
|
const tool = opts.tool ?? inferTool(hookPayload);
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
const triggerSource = resolveTriggerSource(tool, opts, hookPayload);
|
|
43
|
+
if (!triggerSource && !tool) {
|
|
44
|
+
log("Could not determine tool", profile);
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
|
-
log(`auto-submit triggered for tool=${tool}
|
|
47
|
+
log(`auto-submit triggered for profile=${profile} tool=${tool ?? "unknown"}`, profile);
|
|
48
|
+
const result = await flushTrackedSessions(config, triggerSource ? [triggerSource] : [], { includeIdleTracked: true });
|
|
49
|
+
logFlushResult(result, profile);
|
|
50
|
+
}
|
|
51
|
+
function logFlushResult(result, profile) {
|
|
52
|
+
for (const session of result.results) {
|
|
53
|
+
if (session.error && session.error !== "Empty session") {
|
|
54
|
+
log(`${session.source.label}: ${session.error}`, profile);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (session.uploadedChunks > 0 || session.duplicateChunks > 0) {
|
|
58
|
+
const status = session.uploadedChunks > 0 ? "uploaded" : "duplicate";
|
|
59
|
+
log(`${session.source.label}: ${status} chunks=${session.uploadedChunks + session.duplicateChunks} pending=${session.pending} payout=$${(session.payoutCents / 100).toFixed(2)}`, profile);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (result.uploadedChunks === 0 && result.duplicateChunks === 0) {
|
|
63
|
+
log(`no finalized chunks ready; pending_sessions=${result.pendingSessions}`, profile);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function resolveTriggerSource(tool, opts, hookPayload) {
|
|
67
|
+
if (!tool) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
48
70
|
if (tool === "claude-code" || tool === "claude_code") {
|
|
49
|
-
// Claude Code Stop hook sends { session_id, transcript_path }
|
|
50
71
|
const filePath = opts.file
|
|
51
72
|
?? hookPayload["transcript_path"]
|
|
52
73
|
?? findLatestFile("claude_code");
|
|
53
|
-
|
|
54
|
-
log("Claude Code: no session file found");
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
const result = await submitFile("claude_code", filePath, config);
|
|
58
|
-
logResult(result, filePath);
|
|
74
|
+
return filePath ? buildFileSessionSource("claude_code", filePath) : null;
|
|
59
75
|
}
|
|
60
|
-
|
|
76
|
+
if (tool === "cursor") {
|
|
61
77
|
const sessionId = opts.session ?? hookPayload["sessionId"];
|
|
62
|
-
|
|
63
|
-
log("Cursor: no sessionId");
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const result = await submitCursorSession(sessionId, config);
|
|
67
|
-
logResult(result, sessionId);
|
|
78
|
+
return sessionId ? buildCursorSessionSource(sessionId) : null;
|
|
68
79
|
}
|
|
69
|
-
|
|
70
|
-
// after_agent payload: { "thread-id": "...", "turn-id": "...", "cwd": "...", "last-assistant-message": "..." }
|
|
71
|
-
// Legacy / manual: session_path or session_id
|
|
80
|
+
if (tool === "codex" || tool === "codex_cli") {
|
|
72
81
|
const threadId = hookPayload["thread-id"] ?? "";
|
|
73
82
|
const filePath = opts.file
|
|
74
83
|
?? hookPayload["session_path"]
|
|
75
84
|
?? findCodexFileById(opts.session ?? hookPayload["session_id"] ?? threadId ?? "");
|
|
76
|
-
|
|
77
|
-
log("Codex: no session file found");
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
const result = await submitFile("codex_cli", filePath, config);
|
|
81
|
-
logResult(result, filePath);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
log(`Unknown tool: ${tool}`);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
function logResult(result, label) {
|
|
88
|
-
if (result.error) {
|
|
89
|
-
log(`${label}: ${result.error}`);
|
|
90
|
-
return;
|
|
85
|
+
return filePath ? buildFileSessionSource("codex_cli", filePath) : null;
|
|
91
86
|
}
|
|
92
|
-
|
|
93
|
-
log(`${label}: already captured — skipped`);
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
if (result.superseded) {
|
|
97
|
-
log(`${label}: updated (${result.turnCount} turns) — $${(result.payoutCents / 100).toFixed(2)}`);
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
log(`${label}: accepted (${result.turnCount} turns) — $${(result.payoutCents / 100).toFixed(2)}`);
|
|
87
|
+
return null;
|
|
101
88
|
}
|
|
102
89
|
function inferTool(payload) {
|
|
103
90
|
if (payload["transcript_path"])
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-submit.js","sourceRoot":"","sources":["../../src/commands/auto-submit.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC7D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"auto-submit.js","sourceRoot":"","sources":["../../src/commands/auto-submit.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9F,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,oBAAoB,GAErB,MAAM,aAAa,CAAC;AASrB,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,OAAO,GAAG,eAAe;IACxD,SAAS,CAAC,YAAY,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/C,IAAI,CAAC;QACH,cAAc,CAAC,oBAAoB,CAAC,OAAO,CAAC,EAAE,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,KAAK,GAAG,IAAI,CAAC,CAAC;IAC1F,CAAC;IAAC,MAAM,CAAC,CAAA,CAAC;AACZ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,IAAuB;IAC7D,IAAI,CAAC;QACH,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC;IAClB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,GAAG,CAAC,UAAU,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7D,CAAC;AACH,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number;
|
|
4
|
+
once?: boolean;
|
|
5
|
+
watch?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function daemonCommand(opts?: DaemonOptions): Promise<void>;
|
|
8
|
+
export {};
|
|
2
9
|
//# sourceMappingURL=daemon.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"daemon.d.ts","sourceRoot":"","sources":["../../src/commands/daemon.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"daemon.d.ts","sourceRoot":"","sources":["../../src/commands/daemon.ts"],"names":[],"mappings":"AAiCA,UAAU,aAAa;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AA6GD,wBAAsB,aAAa,CAAC,IAAI,GAAE,aAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAsD3E"}
|