@gaia-ai/plugin-claude 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/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/plugin-claude
2
+
3
+ GAIA agent plugin for the Claude CLI.
4
+
5
+ Part of the GAIA conductor. Install the meta package `@gaia-ai/gaia` to get the `gaia` CLI with all plugins. Source: https://git.key-tec.de/keytec/gaia (conductor/).
@@ -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
+ }
@@ -0,0 +1,22 @@
1
+ import { type AgentFootprint, type AgentPlugin, type GaiaAgent } from '@gaia-ai/core';
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;
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@gaia-ai/plugin-claude",
3
+ "version": "0.0.1",
4
+ "description": "GAIA agent plugin for the Claude CLI.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "exports": {
8
+ ".": "./dist/src/index.js"
9
+ },
10
+ "files": [
11
+ "dist/src"
12
+ ],
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://git.key-tec.de/keytec/gaia.git",
19
+ "directory": "conductor/plugins/claude"
20
+ },
21
+ "peerDependencies": {
22
+ "@gaia-ai/core": "^0.0.1"
23
+ }
24
+ }