@gaia-ai/addon-claude 0.6.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 keytec GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @gaia-ai/addon-claude
2
+
3
+ GAIA agent plugin for the Claude CLI.
4
+
5
+ Part of the GAIA CLI. Install the meta package `@gaia-ai/gaia` to get the `gaia` CLI with all addons. Source: https://git.key-tec.de/keytec/gaia (gaia-cli/).
@@ -0,0 +1,17 @@
1
+ import { type AgentFootprint } from '@gaia-ai/conductor/contract';
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
+ * `duration_s` is the run's wall-clock length: the span between the first and
13
+ * last entry that carries a parseable `timestamp` (GAIA-151). This makes the
14
+ * transcript the single source of the run length — no `started_at` re-read, no
15
+ * JSON:API timestamp round-trip to mis-parse. Fewer than two timestamps → 0.
16
+ */
17
+ export declare function parseClaudeTranscript(jsonl: string): AgentFootprint;
@@ -0,0 +1,90 @@
1
+ import { emptyAgentFootprint, } from '@gaia-ai/conductor/contract';
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
+ * `duration_s` is the run's wall-clock length: the span between the first and
27
+ * last entry that carries a parseable `timestamp` (GAIA-151). This makes the
28
+ * transcript the single source of the run length — no `started_at` re-read, no
29
+ * JSON:API timestamp round-trip to mis-parse. Fewer than two timestamps → 0.
30
+ */
31
+ export function parseClaudeTranscript(jsonl) {
32
+ const footprint = emptyAgentFootprint();
33
+ let minTs = Number.POSITIVE_INFINITY;
34
+ let maxTs = Number.NEGATIVE_INFINITY;
35
+ for (const raw of jsonl.split('\n')) {
36
+ const line = raw.trim();
37
+ if (line === '') {
38
+ continue;
39
+ }
40
+ let entry;
41
+ try {
42
+ entry = JSON.parse(line);
43
+ }
44
+ catch {
45
+ continue;
46
+ }
47
+ // Track the run span across ANY timestamped entry (user, assistant,
48
+ // system, …) — not just the turns we meter for tokens.
49
+ if (typeof entry.timestamp === 'string') {
50
+ const ts = Date.parse(entry.timestamp);
51
+ if (Number.isFinite(ts)) {
52
+ if (ts < minTs)
53
+ minTs = ts;
54
+ if (ts > maxTs)
55
+ maxTs = ts;
56
+ }
57
+ }
58
+ const message = entry.message;
59
+ if (!message || typeof message !== 'object') {
60
+ continue;
61
+ }
62
+ if (entry.type === 'assistant') {
63
+ footprint.agent_turns += 1;
64
+ const usage = message.usage ?? {};
65
+ for (const key of TOKEN_KEYS) {
66
+ footprint.tokens += num(usage[key]);
67
+ }
68
+ if (Array.isArray(message.content)) {
69
+ for (const block of message.content) {
70
+ if (block &&
71
+ typeof block === 'object' &&
72
+ block.type === 'tool_use') {
73
+ footprint.tool_calls += 1;
74
+ }
75
+ }
76
+ }
77
+ if (typeof message.model === 'string') {
78
+ footprint.model = message.model;
79
+ }
80
+ }
81
+ else if (entry.type === 'user' && typeof message.content === 'string') {
82
+ footprint.user_prompts += 1;
83
+ footprint.user_prompt_words += countWords(message.content);
84
+ }
85
+ }
86
+ if (Number.isFinite(minTs) && Number.isFinite(maxTs) && maxTs > minTs) {
87
+ footprint.duration_s = Math.floor((maxTs - minTs) / 1000);
88
+ }
89
+ return footprint;
90
+ }
@@ -0,0 +1,22 @@
1
+ import type { AgentFootprint, AgentPlugin, GaiaAgent } from '@gaia-ai/conductor/contract';
2
+ export { parseClaudeTranscript } from './footprint.js';
3
+ /**
4
+ * Encode an absolute cwd the way Claude Code names its per-project transcript
5
+ * directory under `~/.claude/projects/`: every non-alphanumeric char → `-`.
6
+ */
7
+ export declare function encodeClaudeProjectDir(cwd: string): string;
8
+ export interface ClaudeAgentOptions {
9
+ model?: string;
10
+ }
11
+ export declare class ClaudeAgent implements GaiaAgent {
12
+ private readonly options;
13
+ private readonly home;
14
+ readonly id = "claude";
15
+ constructor(options: ClaudeAgentOptions, home?: string);
16
+ launchCommand(prompt: string): string;
17
+ getRunLog(worktreePath: string): Promise<string>;
18
+ parseFootprint(log: string): AgentFootprint;
19
+ }
20
+ /** Config-facing factory: `claudeAgent({ model: 'claude-opus-4-8' })`. */
21
+ export declare function claudeAgent(options?: ClaudeAgentOptions): AgentPlugin;
22
+ export default claudeAgent;
@@ -0,0 +1,88 @@
1
+ import { readdir, readFile, stat } from 'node:fs/promises';
2
+ import { homedir } from 'node:os';
3
+ import { join } from 'node:path';
4
+ import { shellQuote } from '@gaia-ai/core';
5
+ import { parseClaudeTranscript } from './footprint.js';
6
+ export { parseClaudeTranscript } from './footprint.js';
7
+ /**
8
+ * Encode an absolute cwd the way Claude Code names its per-project transcript
9
+ * directory under `~/.claude/projects/`: every non-alphanumeric char → `-`.
10
+ */
11
+ export function encodeClaudeProjectDir(cwd) {
12
+ return cwd.replace(/[^a-zA-Z0-9]/g, '-');
13
+ }
14
+ export class ClaudeAgent {
15
+ options;
16
+ home;
17
+ id = 'claude';
18
+ constructor(options, home = homedir()) {
19
+ this.options = options;
20
+ this.home = home;
21
+ }
22
+ launchCommand(prompt) {
23
+ if (prompt === '') {
24
+ return 'claude';
25
+ }
26
+ const parts = ['claude', shellQuote(prompt)];
27
+ if (this.options.model) {
28
+ parts.push('--model', this.options.model);
29
+ }
30
+ parts.push('--dangerously-skip-permissions');
31
+ return parts.join(' ');
32
+ }
33
+ async getRunLog(worktreePath) {
34
+ const dir = join(this.home, '.claude', 'projects', encodeClaudeProjectDir(worktreePath));
35
+ let entries;
36
+ try {
37
+ entries = await readdir(dir);
38
+ }
39
+ catch {
40
+ return '';
41
+ }
42
+ let latest = null;
43
+ for (const name of entries) {
44
+ if (!name.endsWith('.jsonl')) {
45
+ continue;
46
+ }
47
+ const full = join(dir, name);
48
+ try {
49
+ const s = await stat(full);
50
+ if (!latest || s.mtimeMs > latest.mtimeMs) {
51
+ latest = { path: full, mtimeMs: s.mtimeMs };
52
+ }
53
+ }
54
+ catch {
55
+ // entry vanished between readdir and stat — skip.
56
+ }
57
+ }
58
+ if (!latest) {
59
+ return '';
60
+ }
61
+ try {
62
+ return await readFile(latest.path, 'utf8');
63
+ }
64
+ catch {
65
+ return '';
66
+ }
67
+ }
68
+ parseFootprint(log) {
69
+ return parseClaudeTranscript(log);
70
+ }
71
+ }
72
+ /** Config-facing factory: `claudeAgent({ model: 'claude-opus-4-8' })`. */
73
+ export function claudeAgent(options = {}) {
74
+ const agent = new ClaudeAgent(options);
75
+ return {
76
+ kind: 'agent',
77
+ id: 'claude',
78
+ requiredModules: [],
79
+ async createAgent() {
80
+ return agent;
81
+ },
82
+ };
83
+ }
84
+ // Default export: this module also exports the `ClaudeAgent` class, so the
85
+ // config resolver's auto-pick (no `export:`) sees 2 function exports and
86
+ // would otherwise throw "specify export" — see conductor/src/config.ts
87
+ // `loadNamedPlugin`. The default export makes the factory win.
88
+ export default claudeAgent;
@@ -0,0 +1,2 @@
1
+ import type { Preset } from '@gaia-ai/conductor/contract';
2
+ export declare const agents: Preset['agents'];
@@ -0,0 +1,5 @@
1
+ import claudeAgent from './index.js';
2
+ export const agents = (acc, opts) => [
3
+ ...acc,
4
+ { agent: claudeAgent(opts) },
5
+ ];
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@gaia-ai/addon-claude",
3
+ "version": "0.6.1",
4
+ "description": "GAIA agent plugin for the Claude CLI.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "exports": {
8
+ ".": "./dist/src/index.js",
9
+ "./preset": "./dist/src/preset.js"
10
+ },
11
+ "files": [
12
+ "dist/src"
13
+ ],
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://git.key-tec.de/keytec/gaia.git",
20
+ "directory": "gaia-cli/addons/claude"
21
+ },
22
+ "peerDependencies": {
23
+ "@gaia-ai/conductor": "^0.6.1",
24
+ "@gaia-ai/core": "^0.6.1"
25
+ }
26
+ }