@gaia-ai/plugin-claude 0.4.3 → 0.4.4

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.
@@ -0,0 +1,12 @@
1
+ import { type AgentFootprint } from '@gaia-ai/core';
2
+ /**
3
+ * Parse a Claude-Code JSONL transcript into an agent footprint (GAIA-132).
4
+ *
5
+ * This is Claude's transcript format specifically — the transcript is one JSON
6
+ * object per line. Assistant turns carry a `message.usage` token breakdown and
7
+ * `message.content` blocks (text / tool_use); genuine user prompts are user
8
+ * messages whose `message.content` is a plain string (tool results come back
9
+ * as an array and are ignored). Blank or malformed lines are skipped — never
10
+ * throws.
11
+ */
12
+ export declare function parseClaudeTranscript(jsonl: string): AgentFootprint;
@@ -0,0 +1,69 @@
1
+ import { emptyAgentFootprint } from '@gaia-ai/core';
2
+ /** Token buckets summed into the total; each defaults to 0 when absent. */
3
+ const TOKEN_KEYS = [
4
+ 'input_tokens',
5
+ 'output_tokens',
6
+ 'cache_creation_input_tokens',
7
+ 'cache_read_input_tokens',
8
+ ];
9
+ function num(value) {
10
+ return typeof value === 'number' && Number.isFinite(value) ? value : 0;
11
+ }
12
+ function countWords(text) {
13
+ const trimmed = text.trim();
14
+ return trimmed === '' ? 0 : trimmed.split(/\s+/).length;
15
+ }
16
+ /**
17
+ * Parse a Claude-Code JSONL transcript into an agent footprint (GAIA-132).
18
+ *
19
+ * This is Claude's transcript format specifically — the transcript is one JSON
20
+ * object per line. Assistant turns carry a `message.usage` token breakdown and
21
+ * `message.content` blocks (text / tool_use); genuine user prompts are user
22
+ * messages whose `message.content` is a plain string (tool results come back
23
+ * as an array and are ignored). Blank or malformed lines are skipped — never
24
+ * throws.
25
+ */
26
+ export function parseClaudeTranscript(jsonl) {
27
+ const footprint = emptyAgentFootprint();
28
+ for (const raw of jsonl.split('\n')) {
29
+ const line = raw.trim();
30
+ if (line === '') {
31
+ continue;
32
+ }
33
+ let entry;
34
+ try {
35
+ entry = JSON.parse(line);
36
+ }
37
+ catch {
38
+ continue;
39
+ }
40
+ const message = entry.message;
41
+ if (!message || typeof message !== 'object') {
42
+ continue;
43
+ }
44
+ if (entry.type === 'assistant') {
45
+ footprint.agent_turns += 1;
46
+ const usage = message.usage ?? {};
47
+ for (const key of TOKEN_KEYS) {
48
+ footprint.tokens += num(usage[key]);
49
+ }
50
+ if (Array.isArray(message.content)) {
51
+ for (const block of message.content) {
52
+ if (block &&
53
+ typeof block === 'object' &&
54
+ block.type === 'tool_use') {
55
+ footprint.tool_calls += 1;
56
+ }
57
+ }
58
+ }
59
+ if (typeof message.model === 'string') {
60
+ footprint.model = message.model;
61
+ }
62
+ }
63
+ else if (entry.type === 'user' && typeof message.content === 'string') {
64
+ footprint.user_prompts += 1;
65
+ footprint.user_prompt_words += countWords(message.content);
66
+ }
67
+ }
68
+ return footprint;
69
+ }
@@ -1,4 +1,5 @@
1
- import { type AgentPlugin, type GaiaAgent } from '@gaia-ai/core';
1
+ import { type AgentFootprint, type AgentPlugin, type GaiaAgent } from '@gaia-ai/core';
2
+ export { parseClaudeTranscript } from './footprint.js';
2
3
  /**
3
4
  * Encode an absolute cwd the way Claude Code names its per-project transcript
4
5
  * directory under `~/.claude/projects/`: every non-alphanumeric char → `-`.
@@ -14,6 +15,7 @@ export declare class ClaudeAgent implements GaiaAgent {
14
15
  constructor(options: ClaudeAgentOptions, home?: string);
15
16
  launchCommand(prompt: string): string;
16
17
  getRunLog(worktreePath: string): Promise<string>;
18
+ parseFootprint(log: string): AgentFootprint;
17
19
  }
18
20
  /** Config-facing factory: `claudeAgent({ model: 'claude-opus-4-8' })`. */
19
21
  export declare function claudeAgent(options?: ClaudeAgentOptions): AgentPlugin;
package/dist/src/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import { readdir, readFile, stat } from 'node:fs/promises';
2
2
  import { homedir } from 'node:os';
3
3
  import { join } from 'node:path';
4
- import { shellQuote } from '@gaia-ai/core';
4
+ import { shellQuote, } from '@gaia-ai/core';
5
+ import { parseClaudeTranscript } from './footprint.js';
6
+ export { parseClaudeTranscript } from './footprint.js';
5
7
  /**
6
8
  * Encode an absolute cwd the way Claude Code names its per-project transcript
7
9
  * directory under `~/.claude/projects/`: every non-alphanumeric char → `-`.
@@ -63,6 +65,9 @@ export class ClaudeAgent {
63
65
  return '';
64
66
  }
65
67
  }
68
+ parseFootprint(log) {
69
+ return parseClaudeTranscript(log);
70
+ }
66
71
  }
67
72
  /** Config-facing factory: `claudeAgent({ model: 'claude-opus-4-8' })`. */
68
73
  export function claudeAgent(options = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gaia-ai/plugin-claude",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "GAIA agent plugin for the Claude CLI.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -19,6 +19,6 @@
19
19
  "directory": "conductor/plugins/claude"
20
20
  },
21
21
  "peerDependencies": {
22
- "@gaia-ai/core": "^0.4.3"
22
+ "@gaia-ai/core": "^0.4.4"
23
23
  }
24
24
  }