@jagit/hook-copilot 0.0.2 → 0.0.3

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/index.d.ts CHANGED
@@ -14,24 +14,40 @@ export interface CopilotStopStdin {
14
14
  */
15
15
  stop_hook_active?: boolean;
16
16
  }
17
- export interface CopilotTranscriptEntry {
17
+ export interface CopilotTranscriptSessionStart {
18
+ type: "session.start";
19
+ timestamp?: string;
20
+ data: {
21
+ sessionId?: string;
22
+ version?: number;
23
+ producer?: string;
24
+ copilotVersion?: string;
25
+ vscodeVersion?: string;
26
+ startTime?: string;
27
+ };
28
+ }
29
+ export interface CopilotTranscriptToolRequest {
30
+ toolCallId?: string;
31
+ name?: string;
32
+ arguments?: string;
18
33
  type?: string;
34
+ }
35
+ export interface CopilotTranscriptAssistantMessage {
36
+ type: "assistant.message";
19
37
  timestamp?: string;
20
- message?: {
21
- role?: string;
22
- model?: string;
23
- content?: unknown;
24
- usage?: {
25
- input_tokens?: number;
26
- cache_read_input_tokens?: number;
27
- cache_creation_input_tokens?: number;
28
- output_tokens?: number;
29
- inputTokens?: number;
30
- cachedInputTokens?: number;
31
- outputTokens?: number;
32
- };
38
+ id?: string;
39
+ data: {
40
+ messageId?: string;
41
+ content?: string;
42
+ /** Tool calls made in this assistant turn */
43
+ toolRequests?: CopilotTranscriptToolRequest[];
33
44
  };
34
45
  }
46
+ export type CopilotTranscriptEntry = CopilotTranscriptSessionStart | CopilotTranscriptAssistantMessage | {
47
+ type: string;
48
+ timestamp?: string;
49
+ data?: unknown;
50
+ };
35
51
  export interface CopilotInfo {
36
52
  model?: string;
37
53
  inputTokens?: number;
@@ -41,7 +57,11 @@ export interface CopilotInfo {
41
57
  }
42
58
  /**
43
59
  * Build payload from a real VS Code Copilot agent Stop-hook stdin.
44
- * Reads the transcript to aggregate token usage and detect the model.
60
+ *
61
+ * Reads the transcript to count tool calls and extract the session start time.
62
+ * Token usage (input/cached/output) and model name are NOT available in the
63
+ * VS Code Copilot transcript — Copilot uses seat-based billing and does not
64
+ * expose per-call telemetry. These fields are reported as 0/null/"copilot".
45
65
  */
46
66
  export declare function buildPayloadFromStdin(stdin: CopilotStopStdin, read?: (path: string) => CopilotTranscriptEntry[]): AgentSessionPayload;
47
67
  /**
package/dist/index.js CHANGED
@@ -12,25 +12,50 @@ function readTranscript(path) {
12
12
  return JSON.parse(l);
13
13
  }
14
14
  catch {
15
- return {};
15
+ return { type: "__parse_error__" };
16
16
  }
17
17
  });
18
18
  }
19
- function hasToolUse(content) {
20
- return Array.isArray(content) && content.some((b) => b?.type === "tool_use");
19
+ /**
20
+ * Count tool calls from assistant.message entries.
21
+ * Each assistant.message with at least one toolRequest counts as one tool-call turn;
22
+ * we sum the total number of individual tool requests across all turns.
23
+ */
24
+ function countToolCalls(entries) {
25
+ let count = 0;
26
+ for (const e of entries) {
27
+ if (e.type !== "assistant.message")
28
+ continue;
29
+ const msg = e;
30
+ count += msg.data?.toolRequests?.length ?? 0;
31
+ }
32
+ return count;
33
+ }
34
+ /**
35
+ * Extract the earliest timestamp from the transcript.
36
+ * Prefers session.start data.startTime, then falls back to the first entry timestamp.
37
+ */
38
+ function extractStartTime(entries) {
39
+ for (const e of entries) {
40
+ if (e.type === "session.start") {
41
+ const s = e;
42
+ if (s.data?.startTime)
43
+ return s.data.startTime;
44
+ }
45
+ }
46
+ // Fall back to the first entry with a timestamp
47
+ return entries.find((e) => e.timestamp)?.timestamp;
21
48
  }
22
49
  // ─── Payload builders ─────────────────────────────────────────────────────────
23
50
  /**
24
51
  * Build payload from a real VS Code Copilot agent Stop-hook stdin.
25
- * Reads the transcript to aggregate token usage and detect the model.
52
+ *
53
+ * Reads the transcript to count tool calls and extract the session start time.
54
+ * Token usage (input/cached/output) and model name are NOT available in the
55
+ * VS Code Copilot transcript — Copilot uses seat-based billing and does not
56
+ * expose per-call telemetry. These fields are reported as 0/null/"copilot".
26
57
  */
27
58
  export function buildPayloadFromStdin(stdin, read = readTranscript) {
28
- let inputTokens = 0;
29
- let cachedInputTokens = 0;
30
- let cacheCreationInputTokens = 0;
31
- let outputTokens = 0;
32
- let toolCallCount = 0;
33
- let model = "copilot";
34
59
  const entries = stdin.transcript_path ? (() => {
35
60
  try {
36
61
  return read(stdin.transcript_path);
@@ -39,33 +64,20 @@ export function buildPayloadFromStdin(stdin, read = readTranscript) {
39
64
  return [];
40
65
  }
41
66
  })() : [];
42
- for (const e of entries) {
43
- if (e.message?.role !== "assistant")
44
- continue;
45
- if (e.message.model)
46
- model = e.message.model;
47
- if (hasToolUse(e.message.content))
48
- toolCallCount += 1;
49
- const u = e.message.usage;
50
- if (u) {
51
- // Prefer snake_case (Claude-compatible), fall back to camelCase (OpenAI-style)
52
- inputTokens += u.input_tokens ?? u.inputTokens ?? 0;
53
- cachedInputTokens += u.cache_read_input_tokens ?? u.cachedInputTokens ?? 0;
54
- cacheCreationInputTokens += u.cache_creation_input_tokens ?? 0;
55
- outputTokens += u.output_tokens ?? u.outputTokens ?? 0;
56
- }
57
- }
58
- const startedAt = entries.find((e) => e.timestamp)?.timestamp ?? stdin.timestamp ?? new Date().toISOString();
67
+ const toolCallCount = countToolCalls(entries);
68
+ const startedAt = extractStartTime(entries) ?? stdin.timestamp ?? new Date().toISOString();
59
69
  return {
60
70
  tool: "copilot",
61
71
  // session_id is optional per VS Code spec; synthesize a fallback if absent
62
72
  sessionId: stdin.session_id ?? `copilot-${Date.now()}-${process.pid}`,
63
73
  gitUsername: resolveGitUsername(stdin.cwd),
64
- model,
65
- inputTokens,
66
- cachedInputTokens,
67
- cacheCreationInputTokens,
68
- outputTokens,
74
+ // Model name is not exposed in the Copilot hook transcript (seat-based billing)
75
+ model: "copilot",
76
+ // Token usage is not available in the Copilot hook transcript
77
+ inputTokens: 0,
78
+ cachedInputTokens: 0,
79
+ cacheCreationInputTokens: 0,
80
+ outputTokens: 0,
69
81
  costUsd: null,
70
82
  toolCallCount,
71
83
  startedAt,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jagit/hook-copilot",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "jagit-hook-copilot": "dist/index.js"
@@ -9,7 +9,7 @@
9
9
  "dist"
10
10
  ],
11
11
  "dependencies": {
12
- "@jagit/agent-reporter": "0.0.2"
12
+ "@jagit/agent-reporter": "0.0.3"
13
13
  },
14
14
  "devDependencies": {
15
15
  "@types/node": "^25.9.3",