-
Notifications
You must be signed in to change notification settings - Fork 330
Expand file tree
/
Copy pathrun.ts
More file actions
160 lines (152 loc) · 5.77 KB
/
run.ts
File metadata and controls
160 lines (152 loc) · 5.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import { Command } from 'commander';
import { resolve } from 'node:path';
import { error, heading, info, label, divider } from '../utils/format.js';
import { loadAgentManifest, agentDirExists } from '../utils/loader.js';
import { exportToSystemPrompt } from '../adapters/system-prompt.js';
import { resolveRepo } from '../utils/git-cache.js';
import { runWithClaude } from '../runners/claude.js';
import { runWithOpenAI } from '../runners/openai.js';
import { runWithCrewAI } from '../runners/crewai.js';
import { runWithOpenClaw } from '../runners/openclaw.js';
import { runWithNanobot } from '../runners/nanobot.js';
import { runWithLyzr } from '../runners/lyzr.js';
import { runWithGitHub } from '../runners/github.js';
import { runWithGit } from '../runners/git.js';
import { runWithOpenCode } from '../runners/opencode.js';
import { runWithGemini } from '../runners/gemini.js';
import { runWithGitclaw } from '../runners/gitclaw.js';
interface RunOptions {
repo?: string;
adapter: string;
branch: string;
refresh: boolean;
cache: boolean;
prompt?: string;
dir?: string;
workspace?: string;
}
export const runCommand = new Command('run')
.description('Run an agent from a git repository or local directory')
.option('-r, --repo <url>', 'Git repository URL')
.option('-a, --adapter <name>', 'Adapter: claude, openai, crewai, openclaw, nanobot, lyzr, github, opencode, gemini, gitclaw, git, prompt', 'claude')
.option('-b, --branch <branch>', 'Git branch/tag to clone', 'main')
.option('--refresh', 'Force re-clone (pull latest)', false)
.option('--no-cache', 'Clone to temp dir, delete on exit')
.option('-p, --prompt <query>', 'Initial prompt to send to the agent')
.option('-d, --dir <dir>', 'Use local directory instead of git URL')
.option('-w, --workspace <dir>', 'Working directory for the spawned agent process')
.action(async (options: RunOptions) => {
let agentDir: string;
let cleanup: (() => void) | undefined;
// Resolve agent directory
if (options.dir) {
agentDir = resolve(options.dir);
} else if (options.repo) {
heading('Resolving repository');
info(`URL: ${options.repo}`);
info(`Branch: ${options.branch}`);
try {
const result = resolveRepo(options.repo, {
branch: options.branch,
refresh: options.refresh,
noCache: !options.cache,
});
agentDir = result.dir;
cleanup = result.cleanup;
} catch (e) {
error(`Failed to clone repository: ${(e as Error).message}`);
process.exit(1);
}
} else {
error('Either --repo (-r) or --dir (-d) is required');
process.exit(1);
}
// Validate agent directory
if (!agentDirExists(agentDir)) {
error(`No agent.yaml found in ${agentDir}`);
if (cleanup) cleanup();
process.exit(1);
}
// Load manifest
let manifest;
try {
manifest = loadAgentManifest(agentDir);
} catch (e) {
error(`Failed to load agent: ${(e as Error).message}`);
if (cleanup) cleanup();
process.exit(1);
}
// Print agent info
heading(`Running agent: ${manifest.name}`);
label('Version', manifest.version);
label('Description', manifest.description);
if (manifest.model?.preferred) {
label('Model', manifest.model.preferred);
}
label('Adapter', options.adapter);
if (options.workspace) {
label('Workspace', resolve(options.workspace));
}
divider();
// Run with selected adapter
try {
switch (options.adapter) {
case 'claude':
runWithClaude(agentDir, manifest, { prompt: options.prompt, workspace: options.workspace });
break;
case 'openai':
runWithOpenAI(agentDir, manifest, { workspace: options.workspace });
break;
case 'crewai':
runWithCrewAI(agentDir, manifest, { workspace: options.workspace });
break;
case 'openclaw':
runWithOpenClaw(agentDir, manifest, { prompt: options.prompt, workspace: options.workspace });
break;
case 'nanobot':
runWithNanobot(agentDir, manifest, { prompt: options.prompt, workspace: options.workspace });
break;
case 'lyzr':
await runWithLyzr(agentDir, manifest, { prompt: options.prompt, workspace: options.workspace });
break;
case 'github':
await runWithGitHub(agentDir, manifest, { prompt: options.prompt, workspace: options.workspace });
break;
case 'opencode':
runWithOpenCode(agentDir, manifest, { prompt: options.prompt, workspace: options.workspace });
break;
case 'gemini':
runWithGemini(agentDir, manifest, { prompt: options.prompt, workspace: options.workspace });
break;
case 'gitclaw':
runWithGitclaw(agentDir, manifest, { prompt: options.prompt, workspace: options.workspace });
break;
case 'git':
if (!options.repo) {
error('The git adapter requires --repo (-r)');
process.exit(1);
}
await runWithGit(options.repo, {
repo: options.repo,
branch: options.branch,
refresh: options.refresh,
noCache: !options.cache,
prompt: options.prompt,
workspace: options.workspace,
});
break;
case 'prompt':
console.log(exportToSystemPrompt(agentDir));
break;
default:
error(`Unknown adapter: ${options.adapter}`);
info('Supported adapters: claude, openai, crewai, openclaw, nanobot, lyzr, github, opencode, gemini, gitclaw, git, prompt');
process.exit(1);
}
} catch (e) {
error(`Run failed: ${(e as Error).message}`);
process.exit(1);
} finally {
if (cleanup) cleanup();
}
});