-
Notifications
You must be signed in to change notification settings - Fork 296
Expand file tree
/
Copy pathrun.ts
More file actions
145 lines (137 loc) · 4.94 KB
/
run.ts
File metadata and controls
145 lines (137 loc) · 4.94 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
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 { runWithLangChain } from '../runners/langchain.js';
import { runWithLangGraph } from '../runners/langgraph.js';
interface RunOptions {
repo?: string;
adapter: string;
branch: string;
refresh: boolean;
cache: boolean;
prompt?: string;
dir?: 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, git, prompt, langchain, langgraph', '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')
.action(async (options: RunOptions) => {
let agentDir: string;
let cleanup: (() => void) | undefined;
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);
}
if (!agentDirExists(agentDir)) {
error(`No agent.yaml found in ${agentDir}`);
if (cleanup) cleanup();
process.exit(1);
}
let manifest;
try {
manifest = loadAgentManifest(agentDir);
} catch (e) {
error(`Failed to load agent: ${(e as Error).message}`);
if (cleanup) cleanup();
process.exit(1);
}
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);
divider();
try {
switch (options.adapter) {
case 'claude':
runWithClaude(agentDir, manifest, { prompt: options.prompt });
break;
case 'openai':
runWithOpenAI(agentDir, manifest);
break;
case 'crewai':
runWithCrewAI(agentDir, manifest);
break;
case 'openclaw':
runWithOpenClaw(agentDir, manifest, { prompt: options.prompt });
break;
case 'nanobot':
runWithNanobot(agentDir, manifest, { prompt: options.prompt });
break;
case 'lyzr':
await runWithLyzr(agentDir, manifest, { prompt: options.prompt });
break;
case 'github':
await runWithGitHub(agentDir, manifest, { prompt: options.prompt });
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,
});
break;
case 'langchain':
runWithLangChain(agentDir, manifest, { prompt: options.prompt });
break;
case 'langgraph':
runWithLangGraph(agentDir, manifest, { prompt: options.prompt });
break;
case 'prompt':
console.log(exportToSystemPrompt(agentDir));
break;
default:
error(`Unknown adapter: ${options.adapter}`);
info('Supported adapters: claude, openai, crewai, openclaw, nanobot, lyzr, github, git, prompt, langchain, langgraph');
process.exit(1);
}
} catch (e) {
error(`Run failed: ${(e as Error).message}`);
process.exit(1);
} finally {
if (cleanup) cleanup();
}
});