@jagit/agent-reporter 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.
- package/dist/git-username.d.ts +1 -0
- package/dist/git-username.js +16 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/report.d.ts +6 -0
- package/dist/report.js +38 -0
- package/dist/schema.d.ts +21 -0
- package/dist/schema.js +15 -0
- package/package.json +23 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function resolveGitUsername(cwd?: string): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { execSync } from "node:child_process";
|
|
2
|
+
function tryGit(args, cwd) {
|
|
3
|
+
try {
|
|
4
|
+
const out = execSync(`git -C "${cwd}" ${args}`, { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
5
|
+
return out.length > 0 ? out : undefined;
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export function resolveGitUsername(cwd = process.cwd()) {
|
|
12
|
+
const fromEnv = process.env.JAGIT_GIT_USERNAME?.trim();
|
|
13
|
+
if (fromEnv)
|
|
14
|
+
return fromEnv;
|
|
15
|
+
return tryGit("config user.email", cwd) ?? tryGit("config user.name", cwd) ?? "unknown";
|
|
16
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/report.d.ts
ADDED
package/dist/report.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { withRetry } from "@jagit/shared";
|
|
2
|
+
import { AgentSessionPayloadSchema } from "./schema.js";
|
|
3
|
+
class RetryableError extends Error {
|
|
4
|
+
}
|
|
5
|
+
export async function reportSession(payload, opts = {}) {
|
|
6
|
+
try {
|
|
7
|
+
const parsed = AgentSessionPayloadSchema.safeParse(payload);
|
|
8
|
+
if (!parsed.success) {
|
|
9
|
+
console.error("[agent-reporter] invalid payload, skipping:", parsed.error.message);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const baseUrl = process.env.JAGIT_BASE_URL?.trim();
|
|
13
|
+
const apiKey = process.env.JAGIT_API_KEY?.trim();
|
|
14
|
+
if (!baseUrl || !apiKey) {
|
|
15
|
+
console.error("[agent-reporter] JAGIT_BASE_URL and JAGIT_API_KEY required; skipping report");
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const url = `${baseUrl.replace(/\/+$/, "")}/api/agent-sessions`;
|
|
19
|
+
const maxRetries = opts.maxRetries ?? 3;
|
|
20
|
+
const baseDelayMs = opts.baseDelayMs ?? 500;
|
|
21
|
+
await withRetry(async () => {
|
|
22
|
+
const res = await fetch(url, {
|
|
23
|
+
method: "POST",
|
|
24
|
+
headers: { "content-type": "application/json", "x-api-key": apiKey },
|
|
25
|
+
body: JSON.stringify(parsed.data),
|
|
26
|
+
});
|
|
27
|
+
if (res.ok)
|
|
28
|
+
return;
|
|
29
|
+
const detail = await res.text().catch(() => "");
|
|
30
|
+
if (res.status >= 500)
|
|
31
|
+
throw new RetryableError(`${res.status} ${detail}`);
|
|
32
|
+
console.error(`[agent-reporter] non-retryable ${res.status}: ${detail}`);
|
|
33
|
+
}, { maxRetries, baseDelayMs });
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
console.error("[agent-reporter] report failed:", err instanceof Error ? err.message : err);
|
|
37
|
+
}
|
|
38
|
+
}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const AGENT_TOOLS: readonly ["claude-code", "codex", "copilot"];
|
|
3
|
+
export type AgentToolWire = (typeof AGENT_TOOLS)[number];
|
|
4
|
+
export declare const AgentSessionPayloadSchema: z.ZodObject<{
|
|
5
|
+
tool: z.ZodEnum<{
|
|
6
|
+
"claude-code": "claude-code";
|
|
7
|
+
codex: "codex";
|
|
8
|
+
copilot: "copilot";
|
|
9
|
+
}>;
|
|
10
|
+
sessionId: z.ZodString;
|
|
11
|
+
gitUsername: z.ZodString;
|
|
12
|
+
model: z.ZodString;
|
|
13
|
+
inputTokens: z.ZodNumber;
|
|
14
|
+
cachedInputTokens: z.ZodNumber;
|
|
15
|
+
outputTokens: z.ZodNumber;
|
|
16
|
+
costUsd: z.ZodNullable<z.ZodNumber>;
|
|
17
|
+
toolCallCount: z.ZodNullable<z.ZodNumber>;
|
|
18
|
+
startedAt: z.ZodString;
|
|
19
|
+
rawPayload: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
export type AgentSessionPayload = z.infer<typeof AgentSessionPayloadSchema>;
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const AGENT_TOOLS = ["claude-code", "codex", "copilot"];
|
|
3
|
+
export const AgentSessionPayloadSchema = z.object({
|
|
4
|
+
tool: z.enum(AGENT_TOOLS),
|
|
5
|
+
sessionId: z.string().min(1).max(200),
|
|
6
|
+
gitUsername: z.string().min(1).max(200),
|
|
7
|
+
model: z.string().min(1).max(200),
|
|
8
|
+
inputTokens: z.number().int().nonnegative(),
|
|
9
|
+
cachedInputTokens: z.number().int().nonnegative(),
|
|
10
|
+
outputTokens: z.number().int().nonnegative(),
|
|
11
|
+
costUsd: z.number().nonnegative().nullable(),
|
|
12
|
+
toolCallCount: z.number().int().nonnegative().nullable(),
|
|
13
|
+
startedAt: z.string().datetime(),
|
|
14
|
+
rawPayload: z.record(z.string(), z.unknown()).optional(),
|
|
15
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jagit/agent-reporter",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"zod": "^4.4.3",
|
|
12
|
+
"@jagit/shared": "0.0.1"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@types/node": "^25.9.3",
|
|
16
|
+
"vitest": "^2.1.9"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc -p tsconfig.json",
|
|
20
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
21
|
+
"test": "vitest run"
|
|
22
|
+
}
|
|
23
|
+
}
|