@open-agent-sdk/cli 0.1.0-canary.202602270920

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.
Files changed (2) hide show
  1. package/package.json +28 -0
  2. package/src/index.ts +73 -0
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@open-agent-sdk/cli",
3
+ "version": "0.1.0-canary.202602270920",
4
+ "description": "CLI agent built on open-agent-sdk",
5
+ "bin": {
6
+ "oas": "./src/index.ts"
7
+ },
8
+ "files": [
9
+ "src"
10
+ ],
11
+ "scripts": {
12
+ "start": "bun run src/index.ts"
13
+ },
14
+ "dependencies": {
15
+ "open-agent-sdk": "0.1.0-canary.202602270920"
16
+ },
17
+ "devDependencies": {
18
+ "@types/bun": "^1.3.8",
19
+ "typescript": "^5.3.0"
20
+ },
21
+ "engines": {
22
+ "bun": ">=1.0.0",
23
+ "node": ">=18.0.0"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ }
28
+ }
package/src/index.ts ADDED
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env bun
2
+ import { prompt } from 'open-agent-sdk';
3
+
4
+ const args = process.argv.slice(2);
5
+
6
+ function getFlag(name: string): string | undefined {
7
+ const idx = args.indexOf(name);
8
+ if (idx !== -1 && idx + 1 < args.length) return args[idx + 1];
9
+ return undefined;
10
+ }
11
+
12
+ const instruction = getFlag('-p');
13
+ const model = getFlag('--model') ?? process.env.OAS_MODEL;
14
+ const provider = getFlag('--provider') as 'openai' | 'google' | 'anthropic' | undefined;
15
+ const outputFormat = getFlag('--output-format') ?? 'text';
16
+ const maxTurns = parseInt(getFlag('--max-turns') ?? '50', 10);
17
+ const cwd = getFlag('--cwd') ?? process.cwd();
18
+ const baseURL = getFlag('--base-url') ?? process.env.ANTHROPIC_BASE_URL ?? process.env.OPENAI_BASE_URL;
19
+
20
+ if (!instruction) {
21
+ console.error('Usage: oas -p <instruction> [--model <model>] [--provider openai|google|anthropic] [--output-format text|json] [--max-turns <n>] [--cwd <path>]');
22
+ process.exit(1);
23
+ }
24
+
25
+ if (!model) {
26
+ console.error('Error: --model flag or OAS_MODEL environment variable is required');
27
+ process.exit(1);
28
+ }
29
+
30
+ const SYSTEM_PROMPT = `You are a terminal agent. Complete the given task using the available tools.
31
+
32
+ Guidelines:
33
+ - Complete the task fully before stopping
34
+ - After making changes, verify the result (e.g., read the file back, run a check command)
35
+ - If a command fails, diagnose why and try an alternative approach
36
+ - Be efficient: don't repeat commands that already succeeded
37
+ - When the task is complete, provide a brief summary of what was accomplished`;
38
+
39
+ async function main() {
40
+ try {
41
+ const result = await prompt(instruction!, {
42
+ model: model!,
43
+ provider,
44
+ maxTurns,
45
+ systemPrompt: SYSTEM_PROMPT,
46
+ allowedTools: ['Bash', 'Read', 'Write', 'Edit', 'Glob', 'Grep', 'BashOutput', 'KillBash'],
47
+ permissionMode: 'bypassPermissions',
48
+ allowDangerouslySkipPermissions: true,
49
+ cwd,
50
+ baseURL,
51
+ logLevel: 'error',
52
+ });
53
+
54
+ if (outputFormat === 'json') {
55
+ console.log(JSON.stringify({
56
+ result: result.result,
57
+ duration_ms: result.duration_ms,
58
+ usage: result.usage,
59
+ }));
60
+ } else {
61
+ console.log(result.result);
62
+ }
63
+ } catch (err) {
64
+ if (outputFormat === 'json') {
65
+ console.log(JSON.stringify({ error: String(err) }));
66
+ } else {
67
+ console.error(String(err));
68
+ }
69
+ process.exit(1);
70
+ }
71
+ }
72
+
73
+ main();