@gaia-ai/plugin-claude 0.2.0
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/src/index.d.ts +20 -0
- package/dist/src/index.js +86 -0
- package/package.json +24 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AgentPlugin, GaiaAgent } from '@gaia-ai/gaia/plugin';
|
|
2
|
+
/**
|
|
3
|
+
* Encode an absolute cwd the way Claude Code names its per-project transcript
|
|
4
|
+
* directory under `~/.claude/projects/`: every non-alphanumeric char → `-`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function encodeClaudeProjectDir(cwd: string): string;
|
|
7
|
+
export interface ClaudeAgentOptions {
|
|
8
|
+
model?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class ClaudeAgent implements GaiaAgent {
|
|
11
|
+
private readonly options;
|
|
12
|
+
private readonly home;
|
|
13
|
+
readonly id = "claude";
|
|
14
|
+
constructor(options: ClaudeAgentOptions, home?: string);
|
|
15
|
+
launchCommand(prompt: string): string;
|
|
16
|
+
getRunLog(worktreePath: string): Promise<string>;
|
|
17
|
+
}
|
|
18
|
+
/** Config-facing factory: `claudeAgent({ model: 'claude-opus-4-8' })`. */
|
|
19
|
+
export declare function claudeAgent(options?: ClaudeAgentOptions): AgentPlugin;
|
|
20
|
+
export default claudeAgent;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { readdir, readFile, stat } from 'node:fs/promises';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
/** POSIX single-quote a string for safe shell embedding. */
|
|
5
|
+
function shellSingleQuote(value) {
|
|
6
|
+
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Encode an absolute cwd the way Claude Code names its per-project transcript
|
|
10
|
+
* directory under `~/.claude/projects/`: every non-alphanumeric char → `-`.
|
|
11
|
+
*/
|
|
12
|
+
export function encodeClaudeProjectDir(cwd) {
|
|
13
|
+
return cwd.replace(/[^a-zA-Z0-9]/g, '-');
|
|
14
|
+
}
|
|
15
|
+
export class ClaudeAgent {
|
|
16
|
+
options;
|
|
17
|
+
home;
|
|
18
|
+
id = 'claude';
|
|
19
|
+
constructor(options, home = homedir()) {
|
|
20
|
+
this.options = options;
|
|
21
|
+
this.home = home;
|
|
22
|
+
}
|
|
23
|
+
launchCommand(prompt) {
|
|
24
|
+
if (prompt === '') {
|
|
25
|
+
return 'claude';
|
|
26
|
+
}
|
|
27
|
+
const parts = ['claude', shellSingleQuote(prompt)];
|
|
28
|
+
if (this.options.model) {
|
|
29
|
+
parts.push('--model', this.options.model);
|
|
30
|
+
}
|
|
31
|
+
parts.push('--dangerously-skip-permissions');
|
|
32
|
+
return parts.join(' ');
|
|
33
|
+
}
|
|
34
|
+
async getRunLog(worktreePath) {
|
|
35
|
+
const dir = join(this.home, '.claude', 'projects', encodeClaudeProjectDir(worktreePath));
|
|
36
|
+
let entries;
|
|
37
|
+
try {
|
|
38
|
+
entries = await readdir(dir);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
let latest = null;
|
|
44
|
+
for (const name of entries) {
|
|
45
|
+
if (!name.endsWith('.jsonl')) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const full = join(dir, name);
|
|
49
|
+
try {
|
|
50
|
+
const s = await stat(full);
|
|
51
|
+
if (!latest || s.mtimeMs > latest.mtimeMs) {
|
|
52
|
+
latest = { path: full, mtimeMs: s.mtimeMs };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// entry vanished between readdir and stat — skip.
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (!latest) {
|
|
60
|
+
return '';
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
return await readFile(latest.path, 'utf8');
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return '';
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** Config-facing factory: `claudeAgent({ model: 'claude-opus-4-8' })`. */
|
|
71
|
+
export function claudeAgent(options = {}) {
|
|
72
|
+
const agent = new ClaudeAgent(options);
|
|
73
|
+
return {
|
|
74
|
+
kind: 'agent',
|
|
75
|
+
id: 'claude',
|
|
76
|
+
requiredModules: [],
|
|
77
|
+
async createAgent() {
|
|
78
|
+
return agent;
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
// Default export: this module also exports the `ClaudeAgent` class, so the
|
|
83
|
+
// config resolver's auto-pick (no `export:`) sees 2 function exports and
|
|
84
|
+
// would otherwise throw "specify export" — see conductor/src/config.ts
|
|
85
|
+
// `loadNamedPlugin`. The default export makes the factory win.
|
|
86
|
+
export default claudeAgent;
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gaia-ai/plugin-claude",
|
|
3
|
+
"version": "0.2.0",
|
|
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/gaia": "^0.2.0"
|
|
23
|
+
}
|
|
24
|
+
}
|