@nimashoghi/code-agent-kit 0.1.0 → 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/README.md +37 -0
- package/cli.js +2 -2
- package/dist/{chunk-ZUMYGBXZ.js → chunk-4LBC5KHN.js} +2 -2
- package/dist/{chunk-AVSJQKCD.js → chunk-4OVN4G22.js} +2 -2
- package/dist/{chunk-EN5WJJ2G.js → chunk-BPQL5GAO.js} +2 -2
- package/dist/{chunk-YAZLCEAU.js → chunk-R7CCLWKJ.js} +1 -1
- package/dist/chunk-R7CCLWKJ.js.map +1 -0
- package/dist/{chunk-CGK4TBZD.js → chunk-UINMTZRO.js} +2 -2
- package/dist/chunk-VPJA6I2O.js +180 -0
- package/dist/chunk-VPJA6I2O.js.map +1 -0
- package/dist/cli/index.d.ts +17 -4
- package/dist/cli/index.js +77 -20
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +39 -14
- package/dist/index.js +30 -8
- package/dist/registry-DkM8QbUx.d.ts +29 -0
- package/dist/{runtime-DxAkSUZk.d.ts → runtime-Zjyjv8M_.d.ts} +2 -2
- package/dist/runtimes/claude.d.ts +1 -1
- package/dist/runtimes/claude.js +2 -2
- package/dist/runtimes/codex.d.ts +1 -1
- package/dist/runtimes/codex.js +2 -2
- package/dist/runtimes/copilot.d.ts +1 -1
- package/dist/runtimes/copilot.js +2 -2
- package/dist/runtimes/gemini.d.ts +1 -1
- package/dist/runtimes/gemini.js +2 -2
- package/package.json +3 -2
- package/dist/chunk-NKMHTQVX.js +0 -60
- package/dist/chunk-NKMHTQVX.js.map +0 -1
- package/dist/chunk-YAZLCEAU.js.map +0 -1
- /package/dist/{chunk-ZUMYGBXZ.js.map → chunk-4LBC5KHN.js.map} +0 -0
- /package/dist/{chunk-AVSJQKCD.js.map → chunk-4OVN4G22.js.map} +0 -0
- /package/dist/{chunk-EN5WJJ2G.js.map → chunk-BPQL5GAO.js.map} +0 -0
- /package/dist/{chunk-CGK4TBZD.js.map → chunk-UINMTZRO.js.map} +0 -0
package/README.md
CHANGED
|
@@ -35,6 +35,7 @@ npm install @anthropic-ai/claude-agent-sdk
|
|
|
35
35
|
|
|
36
36
|
```bash
|
|
37
37
|
code-agent-kit --runtime claude "Fix the failing tests"
|
|
38
|
+
code-agent-kit --model claude-sonnet-4-20250514 "Fix the failing tests"
|
|
38
39
|
code-agent-kit --runtime codex --system "Run tests before finishing." "Add validation"
|
|
39
40
|
code-agent-kit --runtime gemini --file src/runtime.ts "Summarize this file"
|
|
40
41
|
code-agent-kit --runtime claude --resume session-123 "Continue the last task"
|
|
@@ -43,6 +44,7 @@ code-agent-kit --runtime claude --resume session-123 "Continue the last task"
|
|
|
43
44
|
Options:
|
|
44
45
|
|
|
45
46
|
- `--runtime <name>`: `claude`, `codex`, `copilot`, or `gemini`
|
|
47
|
+
- `--model <name>`: model override for the selected runtime
|
|
46
48
|
- `--directory <path>`: working directory for the agent
|
|
47
49
|
- `--system <text>`: system prompt text
|
|
48
50
|
- `--file <path>`: attach a text file, repeatable
|
|
@@ -51,6 +53,41 @@ Options:
|
|
|
51
53
|
|
|
52
54
|
When you explicitly pass `--runtime`, the CLI propagates that choice to child processes through `CODE_AGENT_KIT_RUNTIME`. Nested invocations of `code-agent-kit` use that value as their default runtime.
|
|
53
55
|
|
|
56
|
+
## Local Config
|
|
57
|
+
|
|
58
|
+
The CLI reads a local JSON config from the standard config directory:
|
|
59
|
+
|
|
60
|
+
- Linux: `${XDG_CONFIG_HOME:-~/.config}/code-agent-kit/config.json`
|
|
61
|
+
- macOS: `~/Library/Application Support/code-agent-kit/config.json`
|
|
62
|
+
- Windows: `%APPDATA%\\code-agent-kit\\config.json`
|
|
63
|
+
|
|
64
|
+
Supported keys:
|
|
65
|
+
|
|
66
|
+
- `runtime`
|
|
67
|
+
- `model`
|
|
68
|
+
- `systemPrompt`
|
|
69
|
+
- `directory`
|
|
70
|
+
- `timeoutMs`
|
|
71
|
+
|
|
72
|
+
Priority is:
|
|
73
|
+
|
|
74
|
+
1. Explicit CLI flags
|
|
75
|
+
2. Propagated `CODE_AGENT_KIT_RUNTIME`
|
|
76
|
+
3. `DEFAULT_RUNTIME`
|
|
77
|
+
4. Local config
|
|
78
|
+
5. Built-in defaults
|
|
79
|
+
|
|
80
|
+
Examples:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
code-agent-kit config set runtime codex
|
|
84
|
+
code-agent-kit config set model gpt-5-codex
|
|
85
|
+
code-agent-kit config set timeoutMs 300000
|
|
86
|
+
code-agent-kit config show
|
|
87
|
+
code-agent-kit config unset model
|
|
88
|
+
code-agent-kit config path
|
|
89
|
+
```
|
|
90
|
+
|
|
54
91
|
## Library Usage
|
|
55
92
|
|
|
56
93
|
```ts
|
package/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { runCli } from "./dist/cli/index.js";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
runCli().catch((error) => {
|
|
6
6
|
const message = error instanceof Error ? error.message : String(error);
|
|
7
7
|
console.error(message);
|
|
8
8
|
process.exit(1);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
assertRuntimeRunOptionsSupported,
|
|
3
3
|
buildRuntimePrompt
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-R7CCLWKJ.js";
|
|
5
5
|
|
|
6
6
|
// src/runtimes/gemini.ts
|
|
7
7
|
import { execFile, spawn } from "child_process";
|
|
@@ -225,4 +225,4 @@ function execGemini(args, options) {
|
|
|
225
225
|
export {
|
|
226
226
|
GeminiRuntime
|
|
227
227
|
};
|
|
228
|
-
//# sourceMappingURL=chunk-
|
|
228
|
+
//# sourceMappingURL=chunk-4LBC5KHN.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
assertRuntimeRunOptionsSupported,
|
|
3
3
|
buildRuntimePrompt
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-R7CCLWKJ.js";
|
|
5
5
|
|
|
6
6
|
// src/runtimes/copilot.ts
|
|
7
7
|
var CopilotRuntime = class _CopilotRuntime {
|
|
@@ -51,4 +51,4 @@ ${systemPrompt}`, prompt].join("\n\n");
|
|
|
51
51
|
export {
|
|
52
52
|
CopilotRuntime
|
|
53
53
|
};
|
|
54
|
-
//# sourceMappingURL=chunk-
|
|
54
|
+
//# sourceMappingURL=chunk-4OVN4G22.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
assertRuntimeRunOptionsSupported,
|
|
3
3
|
buildRuntimePrompt
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-R7CCLWKJ.js";
|
|
5
5
|
|
|
6
6
|
// src/runtimes/claude.ts
|
|
7
7
|
import {
|
|
@@ -150,4 +150,4 @@ function emitAssistantBlocks(message, onEvent) {
|
|
|
150
150
|
export {
|
|
151
151
|
ClaudeRuntime
|
|
152
152
|
};
|
|
153
|
-
//# sourceMappingURL=chunk-
|
|
153
|
+
//# sourceMappingURL=chunk-BPQL5GAO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/runtime.ts"],"sourcesContent":["import fs from \"node:fs/promises\";\nimport path from \"node:path\";\n\n/** Core runtime abstractions for running a coding agent on a task. */\n\n/** Event emitted during agent execution for real-time progress streaming. */\nexport type RuntimeEvent =\n | { type: \"text\"; content: string }\n | { type: \"tool_use\"; tool: string; input?: unknown }\n | { type: \"tool_result\"; tool: string; output?: string; isError?: boolean }\n | { type: \"thinking\"; content: string }\n | { type: \"error\"; message: string };\n\nexport type RuntimeFeature =\n | \"resumeSession\"\n | \"eventStreaming\";\n\nexport interface RuntimeCapabilities {\n readonly resumeSession: boolean;\n readonly eventStreaming: boolean;\n}\n\nexport interface RuntimeClass<T extends AgentRuntime = AgentRuntime> {\n new (...args: any[]): T;\n readonly runtimeName: string;\n readonly capabilities: RuntimeCapabilities;\n}\n\nexport type RuntimeSession =\n | { mode: \"new\" }\n | { mode: \"resume\"; sessionId: string };\n\n/** Options passed to AgentRuntime.run(). */\nexport interface RuntimeRunOptions {\n /** Directory the agent operates in. */\n workingDirectory: string;\n\n /** The task/instructions for the agent. */\n prompt: string;\n\n /** Optional system prompt text for the run. */\n systemPrompt?: string;\n\n /** Optional text file attachments included alongside the prompt. */\n attachments?: RuntimeAttachment[];\n\n /** Environment variables injected into the agent process. */\n env?: Record<string, string>;\n\n /** Session behavior for the run. */\n session?: RuntimeSession;\n\n /** Timeout in milliseconds. */\n timeoutMs?: number;\n\n /** Abort signal for cancellation. */\n signal?: AbortSignal;\n\n /** Optional streaming callback for real-time progress. */\n onEvent?: (event: RuntimeEvent) => void;\n}\n\n/** Result returned by AgentRuntime.run(). */\nexport interface AgentResult {\n success: boolean;\n output: string;\n error?: string;\n sessionId?: string;\n}\n\nexport interface RuntimeAttachment {\n /** File path to attach. Relative paths resolve from workingDirectory. */\n path: string;\n\n /** Optional inline content. When omitted, the file is read from disk. */\n content?: string;\n}\n\nfunction featureDescription(feature: RuntimeFeature): string {\n switch (feature) {\n case \"resumeSession\":\n return \"session resume\";\n case \"eventStreaming\":\n return \"event streaming\";\n }\n}\n\nexport class UnsupportedRuntimeFeatureError extends Error {\n readonly runtime: string;\n readonly feature: RuntimeFeature;\n readonly operation: string;\n readonly details?: string;\n\n constructor(options: {\n runtime: string;\n feature: RuntimeFeature;\n operation: string;\n details?: string;\n }) {\n const message = [\n `Runtime \"${options.runtime}\" does not support ${featureDescription(options.feature)} for ${options.operation}.`,\n options.details,\n ]\n .filter(Boolean)\n .join(\" \");\n\n super(message);\n this.name = \"UnsupportedRuntimeFeatureError\";\n this.runtime = options.runtime;\n this.feature = options.feature;\n this.operation = options.operation;\n this.details = options.details;\n }\n}\n\nfunction supportsFeature(\n capabilities: RuntimeCapabilities,\n feature: RuntimeFeature,\n): boolean {\n switch (feature) {\n case \"resumeSession\":\n return capabilities.resumeSession;\n case \"eventStreaming\":\n return capabilities.eventStreaming;\n }\n}\n\nexport function getRequestedRuntimeFeatures(\n options: Pick<RuntimeRunOptions, \"onEvent\" | \"session\">,\n): RuntimeFeature[] {\n const features: RuntimeFeature[] = [];\n\n if (options.onEvent) {\n features.push(\"eventStreaming\");\n }\n\n if (options.session?.mode === \"resume\") {\n features.push(\"resumeSession\");\n }\n\n return features;\n}\n\n/** The core abstraction: run a coding agent on a task. */\nexport interface AgentRuntime {\n readonly name: string;\n\n /** Run the agent on a prompt in a directory, return when done. */\n run(options: RuntimeRunOptions): Promise<AgentResult>;\n\n /** Optional cleanup. */\n dispose?(): Promise<void>;\n}\n\nfunction getRuntimeCapabilities(\n runtime: AgentRuntime | RuntimeClass,\n): RuntimeCapabilities {\n if (typeof runtime === \"function\") {\n return runtime.capabilities;\n }\n\n const runtimeClass = runtime.constructor as RuntimeClass;\n if (!runtimeClass.capabilities) {\n throw new Error(\n `Runtime \"${runtime.name}\" is missing static capabilities metadata on its constructor.`,\n );\n }\n\n return runtimeClass.capabilities;\n}\n\nfunction getRuntimeDisplayName(runtime: AgentRuntime | RuntimeClass): string {\n if (typeof runtime === \"function\") {\n return runtime.runtimeName;\n }\n\n const runtimeClass = runtime.constructor as RuntimeClass;\n return runtimeClass.runtimeName ?? runtime.name;\n}\n\nexport function assertRuntimeSupports(\n runtime: AgentRuntime | RuntimeClass,\n features: readonly RuntimeFeature[],\n operation: string,\n): void {\n const capabilities = getRuntimeCapabilities(runtime);\n const runtimeName = getRuntimeDisplayName(runtime);\n\n for (const feature of features) {\n if (supportsFeature(capabilities, feature)) {\n continue;\n }\n\n throw new UnsupportedRuntimeFeatureError({\n runtime: runtimeName,\n feature,\n operation,\n });\n }\n}\n\nexport function assertRuntimeRunOptionsSupported(\n runtime: AgentRuntime | RuntimeClass,\n options: Pick<RuntimeRunOptions, \"onEvent\" | \"session\">,\n operation: string,\n): void {\n assertRuntimeSupports(\n runtime,\n getRequestedRuntimeFeatures(options),\n operation,\n );\n}\n\nexport async function buildRuntimePrompt(\n options: Pick<RuntimeRunOptions, \"workingDirectory\" | \"prompt\" | \"attachments\">,\n): Promise<string> {\n const attachments = await Promise.all(\n (options.attachments ?? []).map(async (attachment) => {\n const content =\n attachment.content ??\n (await fs.readFile(\n path.resolve(options.workingDirectory, attachment.path),\n \"utf8\",\n ));\n\n return {\n path: attachment.path,\n content,\n };\n }),\n );\n\n if (attachments.length === 0) {\n return options.prompt;\n }\n\n const attachmentText = attachments\n .map(\n (attachment) =>\n [\n `Attached file: ${attachment.path}`,\n \"```\",\n attachment.content,\n \"```\",\n ].join(\"\\n\"),\n )\n .join(\"\\n\\n\");\n\n return [attachmentText, `Task:\\n${options.prompt}`].join(\"\\n\\n\");\n}\n"],"mappings":";AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AA6EjB,SAAS,mBAAmB,SAAiC;AAC3D,UAAQ,SAAS;AAAA,IACf,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,EACX;AACF;AAEO,IAAM,iCAAN,cAA6C,MAAM;AAAA,EAC/C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,SAKT;AACD,UAAM,UAAU;AAAA,MACd,YAAY,QAAQ,OAAO,sBAAsB,mBAAmB,QAAQ,OAAO,CAAC,QAAQ,QAAQ,SAAS;AAAA,MAC7G,QAAQ;AAAA,IACV,EACG,OAAO,OAAO,EACd,KAAK,GAAG;AAEX,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,UAAU,QAAQ;AACvB,SAAK,UAAU,QAAQ;AACvB,SAAK,YAAY,QAAQ;AACzB,SAAK,UAAU,QAAQ;AAAA,EACzB;AACF;AAEA,SAAS,gBACP,cACA,SACS;AACT,UAAQ,SAAS;AAAA,IACf,KAAK;AACH,aAAO,aAAa;AAAA,IACtB,KAAK;AACH,aAAO,aAAa;AAAA,EACxB;AACF;AAEO,SAAS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;AAAA,QACjB;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AAEA,MAAI,YAAY,WAAW,GAAG;AAC5B,WAAO,QAAQ;AAAA,EACjB;AAEA,QAAM,iBAAiB,YACpB;AAAA,IACC,CAAC,eACC;AAAA,MACE,kBAAkB,WAAW,IAAI;AAAA,MACjC;AAAA,MACA,WAAW;AAAA,MACX;AAAA,IACF,EAAE,KAAK,IAAI;AAAA,EACf,EACC,KAAK,MAAM;AAEd,SAAO,CAAC,gBAAgB;AAAA,EAAU,QAAQ,MAAM,EAAE,EAAE,KAAK,MAAM;AACjE;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
assertRuntimeRunOptionsSupported,
|
|
3
3
|
buildRuntimePrompt
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-R7CCLWKJ.js";
|
|
5
5
|
|
|
6
6
|
// src/runtimes/codex.ts
|
|
7
7
|
import {
|
|
@@ -218,4 +218,4 @@ function serializeMcpResult(result) {
|
|
|
218
218
|
export {
|
|
219
219
|
CodexRuntime
|
|
220
220
|
};
|
|
221
|
-
//# sourceMappingURL=chunk-
|
|
221
|
+
//# sourceMappingURL=chunk-UINMTZRO.js.map
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClaudeRuntime
|
|
3
|
+
} from "./chunk-BPQL5GAO.js";
|
|
4
|
+
import {
|
|
5
|
+
CodexRuntime
|
|
6
|
+
} from "./chunk-UINMTZRO.js";
|
|
7
|
+
import {
|
|
8
|
+
CopilotRuntime
|
|
9
|
+
} from "./chunk-4OVN4G22.js";
|
|
10
|
+
import {
|
|
11
|
+
GeminiRuntime
|
|
12
|
+
} from "./chunk-4LBC5KHN.js";
|
|
13
|
+
|
|
14
|
+
// src/runtimes/registry.ts
|
|
15
|
+
var RUNTIME_NAMES = [
|
|
16
|
+
"claude",
|
|
17
|
+
"codex",
|
|
18
|
+
"copilot",
|
|
19
|
+
"gemini"
|
|
20
|
+
];
|
|
21
|
+
var RUNTIME_CLASSES = [
|
|
22
|
+
ClaudeRuntime,
|
|
23
|
+
CodexRuntime,
|
|
24
|
+
CopilotRuntime,
|
|
25
|
+
GeminiRuntime
|
|
26
|
+
];
|
|
27
|
+
function getAvailableRuntimeClasses(requiredCapabilities = []) {
|
|
28
|
+
return RUNTIME_CLASSES.filter(
|
|
29
|
+
(runtimeClass) => requiredCapabilities.every((feature) => runtimeClass.capabilities[feature])
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
function getAvailableRuntimeNames(requiredCapabilities = []) {
|
|
33
|
+
return getAvailableRuntimeClasses(requiredCapabilities).map(
|
|
34
|
+
(runtimeClass) => runtimeClass.runtimeName
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
function createRuntime(options) {
|
|
38
|
+
const requiredCapabilities = options?.requiredCapabilities ?? [];
|
|
39
|
+
const availableRuntimeClasses = getAvailableRuntimeClasses(requiredCapabilities);
|
|
40
|
+
if (availableRuntimeClasses.length === 0) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
`No runtimes support the required capabilities: ${requiredCapabilities.join(", ")}`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
const targetName = options?.name ?? options?.defaultRuntime ?? availableRuntimeClasses[0].runtimeName;
|
|
46
|
+
const selectedRuntimeClass = availableRuntimeClasses.find(
|
|
47
|
+
(runtimeClass) => runtimeClass.runtimeName === targetName
|
|
48
|
+
);
|
|
49
|
+
if (!selectedRuntimeClass) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`Unknown or unsupported runtime: ${targetName}. Available runtimes: ${availableRuntimeClasses.map((runtimeClass) => runtimeClass.runtimeName).join(", ")}`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
return new selectedRuntimeClass(options?.config);
|
|
55
|
+
}
|
|
56
|
+
function getRuntimeCapabilities(runtime) {
|
|
57
|
+
return runtime.constructor.capabilities;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// src/config.ts
|
|
61
|
+
import fs from "fs";
|
|
62
|
+
import os from "os";
|
|
63
|
+
import path from "path";
|
|
64
|
+
import { z } from "zod";
|
|
65
|
+
var CONFIG_DIR_NAME = "code-agent-kit";
|
|
66
|
+
var CONFIG_FILE_NAME = "config.json";
|
|
67
|
+
var CliConfigSchema = z.object({
|
|
68
|
+
runtime: z.enum(RUNTIME_NAMES).optional(),
|
|
69
|
+
model: z.string().min(1).optional(),
|
|
70
|
+
systemPrompt: z.string().min(1).optional(),
|
|
71
|
+
directory: z.string().min(1).optional(),
|
|
72
|
+
timeoutMs: z.number().int().positive().optional()
|
|
73
|
+
}).strict();
|
|
74
|
+
var CLI_CONFIG_KEYS = [
|
|
75
|
+
"runtime",
|
|
76
|
+
"model",
|
|
77
|
+
"systemPrompt",
|
|
78
|
+
"directory",
|
|
79
|
+
"timeoutMs"
|
|
80
|
+
];
|
|
81
|
+
var CLI_CONFIG_VALUE_SCHEMAS = {
|
|
82
|
+
runtime: z.enum(RUNTIME_NAMES),
|
|
83
|
+
model: z.string().min(1),
|
|
84
|
+
systemPrompt: z.string().min(1),
|
|
85
|
+
directory: z.string().min(1),
|
|
86
|
+
timeoutMs: z.coerce.number().int().positive()
|
|
87
|
+
};
|
|
88
|
+
function getCliConfigDir(env = process.env, platform = process.platform) {
|
|
89
|
+
if (platform === "win32") {
|
|
90
|
+
return path.join(
|
|
91
|
+
env.APPDATA ?? path.join(os.homedir(), "AppData", "Roaming"),
|
|
92
|
+
CONFIG_DIR_NAME
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
if (platform === "darwin") {
|
|
96
|
+
return path.join(
|
|
97
|
+
env.XDG_CONFIG_HOME ?? path.join(os.homedir(), "Library", "Application Support"),
|
|
98
|
+
CONFIG_DIR_NAME
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
return path.join(
|
|
102
|
+
env.XDG_CONFIG_HOME ?? path.join(os.homedir(), ".config"),
|
|
103
|
+
CONFIG_DIR_NAME
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
function getCliConfigPath(env = process.env, platform = process.platform) {
|
|
107
|
+
return path.join(getCliConfigDir(env, platform), CONFIG_FILE_NAME);
|
|
108
|
+
}
|
|
109
|
+
function readCliConfig(env = process.env, platform = process.platform) {
|
|
110
|
+
const configPath = getCliConfigPath(env, platform);
|
|
111
|
+
if (!fs.existsSync(configPath)) {
|
|
112
|
+
return {};
|
|
113
|
+
}
|
|
114
|
+
let parsed;
|
|
115
|
+
try {
|
|
116
|
+
parsed = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
117
|
+
} catch (error) {
|
|
118
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
119
|
+
throw new Error(`Failed to read CLI config at ${configPath}: ${message}`);
|
|
120
|
+
}
|
|
121
|
+
const result = CliConfigSchema.safeParse(parsed);
|
|
122
|
+
if (!result.success) {
|
|
123
|
+
throw new Error(
|
|
124
|
+
`Invalid CLI config at ${configPath}: ${result.error.issues.map((issue) => issue.message).join("; ")}`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
return result.data;
|
|
128
|
+
}
|
|
129
|
+
function writeCliConfig(config, env = process.env, platform = process.platform) {
|
|
130
|
+
const validated = CliConfigSchema.parse(config);
|
|
131
|
+
const configPath = getCliConfigPath(env, platform);
|
|
132
|
+
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
|
133
|
+
fs.writeFileSync(configPath, `${JSON.stringify(validated, null, 2)}
|
|
134
|
+
`, "utf8");
|
|
135
|
+
return configPath;
|
|
136
|
+
}
|
|
137
|
+
function setCliConfigValue(key, value, env = process.env, platform = process.platform) {
|
|
138
|
+
const current = readCliConfig(env, platform);
|
|
139
|
+
const next = {
|
|
140
|
+
...current,
|
|
141
|
+
[key]: CLI_CONFIG_VALUE_SCHEMAS[key].parse(value)
|
|
142
|
+
};
|
|
143
|
+
return {
|
|
144
|
+
config: next,
|
|
145
|
+
configPath: writeCliConfig(next, env, platform)
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function unsetCliConfigValue(key, env = process.env, platform = process.platform) {
|
|
149
|
+
const current = { ...readCliConfig(env, platform) };
|
|
150
|
+
delete current[key];
|
|
151
|
+
return {
|
|
152
|
+
config: current,
|
|
153
|
+
configPath: writeCliConfig(current, env, platform)
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function isRuntimeName(value) {
|
|
157
|
+
return value != null && RUNTIME_NAMES.includes(value);
|
|
158
|
+
}
|
|
159
|
+
function isCliConfigKey(value) {
|
|
160
|
+
return value in CLI_CONFIG_VALUE_SCHEMAS;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export {
|
|
164
|
+
RUNTIME_NAMES,
|
|
165
|
+
getAvailableRuntimeClasses,
|
|
166
|
+
getAvailableRuntimeNames,
|
|
167
|
+
createRuntime,
|
|
168
|
+
getRuntimeCapabilities,
|
|
169
|
+
CliConfigSchema,
|
|
170
|
+
CLI_CONFIG_KEYS,
|
|
171
|
+
getCliConfigDir,
|
|
172
|
+
getCliConfigPath,
|
|
173
|
+
readCliConfig,
|
|
174
|
+
writeCliConfig,
|
|
175
|
+
setCliConfigValue,
|
|
176
|
+
unsetCliConfigValue,
|
|
177
|
+
isRuntimeName,
|
|
178
|
+
isCliConfigKey
|
|
179
|
+
};
|
|
180
|
+
//# sourceMappingURL=chunk-VPJA6I2O.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/runtimes/registry.ts","../src/config.ts"],"sourcesContent":["import type {\n AgentRuntime,\n RuntimeCapabilities,\n RuntimeFeature,\n RuntimeClass,\n} from \"../runtime.js\";\nimport { ClaudeRuntime } from \"./claude.js\";\nimport { CodexRuntime } from \"./codex.js\";\nimport { CopilotRuntime } from \"./copilot.js\";\nimport { GeminiRuntime } from \"./gemini.js\";\nimport type { ClaudeRuntimeConfig } from \"./claude.js\";\nimport type { CodexRuntimeConfig } from \"./codex.js\";\nimport type { CopilotRuntimeConfig } from \"./copilot.js\";\nimport type { GeminiRuntimeConfig } from \"./gemini.js\";\n\nexport type RuntimeName = \"claude\" | \"codex\" | \"copilot\" | \"gemini\";\nexport const RUNTIME_NAMES = [\n \"claude\",\n \"codex\",\n \"copilot\",\n \"gemini\",\n] as const satisfies readonly RuntimeName[];\n\nexport interface RuntimeConfigByName {\n claude: ClaudeRuntimeConfig;\n codex: CodexRuntimeConfig;\n copilot: CopilotRuntimeConfig;\n gemini: GeminiRuntimeConfig;\n}\n\nexport type RuntimeConfig = RuntimeConfigByName[RuntimeName];\n\ntype RegisteredRuntimeClass = RuntimeClass<AgentRuntime> & {\n readonly runtimeName: RuntimeName;\n};\n\nconst RUNTIME_CLASSES = [\n ClaudeRuntime,\n CodexRuntime,\n CopilotRuntime,\n GeminiRuntime,\n] as const satisfies readonly RegisteredRuntimeClass[];\n\nexport function getAvailableRuntimeClasses(\n requiredCapabilities: readonly RuntimeFeature[] = [],\n): RegisteredRuntimeClass[] {\n return RUNTIME_CLASSES.filter((runtimeClass) =>\n requiredCapabilities.every((feature) => runtimeClass.capabilities[feature]),\n );\n}\n\nexport function getAvailableRuntimeNames(\n requiredCapabilities: readonly RuntimeFeature[] = [],\n): RuntimeName[] {\n return getAvailableRuntimeClasses(requiredCapabilities).map(\n (runtimeClass) => runtimeClass.runtimeName,\n );\n}\n\nexport function createRuntime(options?: {\n name?: string;\n requiredCapabilities?: readonly RuntimeFeature[];\n defaultRuntime?: RuntimeName;\n config?: RuntimeConfig;\n}): AgentRuntime {\n const requiredCapabilities = options?.requiredCapabilities ?? [];\n const availableRuntimeClasses =\n getAvailableRuntimeClasses(requiredCapabilities);\n\n if (availableRuntimeClasses.length === 0) {\n throw new Error(\n `No runtimes support the required capabilities: ${requiredCapabilities.join(\", \")}`,\n );\n }\n\n const targetName =\n options?.name ??\n options?.defaultRuntime ??\n availableRuntimeClasses[0]!.runtimeName;\n const selectedRuntimeClass = availableRuntimeClasses.find(\n (runtimeClass) => runtimeClass.runtimeName === targetName,\n );\n\n if (!selectedRuntimeClass) {\n throw new Error(\n `Unknown or unsupported runtime: ${targetName}. Available runtimes: ${availableRuntimeClasses\n .map((runtimeClass) => runtimeClass.runtimeName)\n .join(\", \")}`,\n );\n }\n\n return new selectedRuntimeClass(options?.config);\n}\n\nexport function getRuntimeCapabilities(\n runtime: AgentRuntime,\n): RuntimeCapabilities {\n return (runtime.constructor as RuntimeClass).capabilities;\n}\n","import fs from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport { z } from \"zod\";\nimport { RUNTIME_NAMES, type RuntimeName } from \"./runtimes/registry.js\";\n\nconst CONFIG_DIR_NAME = \"code-agent-kit\";\nconst CONFIG_FILE_NAME = \"config.json\";\n\nexport const CliConfigSchema = z\n .object({\n runtime: z.enum(RUNTIME_NAMES).optional(),\n model: z.string().min(1).optional(),\n systemPrompt: z.string().min(1).optional(),\n directory: z.string().min(1).optional(),\n timeoutMs: z.number().int().positive().optional(),\n })\n .strict();\n\nexport type CliConfig = z.infer<typeof CliConfigSchema>;\nexport type CliConfigKey = keyof CliConfig;\nexport const CLI_CONFIG_KEYS = [\n \"runtime\",\n \"model\",\n \"systemPrompt\",\n \"directory\",\n \"timeoutMs\",\n] as const satisfies readonly CliConfigKey[];\n\nconst CLI_CONFIG_VALUE_SCHEMAS = {\n runtime: z.enum(RUNTIME_NAMES),\n model: z.string().min(1),\n systemPrompt: z.string().min(1),\n directory: z.string().min(1),\n timeoutMs: z.coerce.number().int().positive(),\n} as const satisfies Record<CliConfigKey, z.ZodType>;\n\nexport function getCliConfigDir(\n env: NodeJS.ProcessEnv = process.env,\n platform = process.platform,\n): string {\n if (platform === \"win32\") {\n return path.join(\n env.APPDATA ?? path.join(os.homedir(), \"AppData\", \"Roaming\"),\n CONFIG_DIR_NAME,\n );\n }\n\n if (platform === \"darwin\") {\n return path.join(\n env.XDG_CONFIG_HOME ??\n path.join(os.homedir(), \"Library\", \"Application Support\"),\n CONFIG_DIR_NAME,\n );\n }\n\n return path.join(\n env.XDG_CONFIG_HOME ?? path.join(os.homedir(), \".config\"),\n CONFIG_DIR_NAME,\n );\n}\n\nexport function getCliConfigPath(\n env: NodeJS.ProcessEnv = process.env,\n platform = process.platform,\n): string {\n return path.join(getCliConfigDir(env, platform), CONFIG_FILE_NAME);\n}\n\nexport function readCliConfig(\n env: NodeJS.ProcessEnv = process.env,\n platform = process.platform,\n): CliConfig {\n const configPath = getCliConfigPath(env, platform);\n if (!fs.existsSync(configPath)) {\n return {};\n }\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(fs.readFileSync(configPath, \"utf8\"));\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n throw new Error(`Failed to read CLI config at ${configPath}: ${message}`);\n }\n\n const result = CliConfigSchema.safeParse(parsed);\n if (!result.success) {\n throw new Error(\n `Invalid CLI config at ${configPath}: ${result.error.issues\n .map((issue) => issue.message)\n .join(\"; \")}`,\n );\n }\n\n return result.data;\n}\n\nexport function writeCliConfig(\n config: CliConfig,\n env: NodeJS.ProcessEnv = process.env,\n platform = process.platform,\n): string {\n const validated = CliConfigSchema.parse(config);\n const configPath = getCliConfigPath(env, platform);\n fs.mkdirSync(path.dirname(configPath), { recursive: true });\n fs.writeFileSync(configPath, `${JSON.stringify(validated, null, 2)}\\n`, \"utf8\");\n return configPath;\n}\n\nexport function setCliConfigValue<K extends CliConfigKey>(\n key: K,\n value: string,\n env: NodeJS.ProcessEnv = process.env,\n platform = process.platform,\n): { config: CliConfig; configPath: string } {\n const current = readCliConfig(env, platform);\n const next = {\n ...current,\n [key]: CLI_CONFIG_VALUE_SCHEMAS[key].parse(value),\n } as CliConfig;\n\n return {\n config: next,\n configPath: writeCliConfig(next, env, platform),\n };\n}\n\nexport function unsetCliConfigValue<K extends CliConfigKey>(\n key: K,\n env: NodeJS.ProcessEnv = process.env,\n platform = process.platform,\n): { config: CliConfig; configPath: string } {\n const current = { ...readCliConfig(env, platform) };\n delete current[key];\n\n return {\n config: current,\n configPath: writeCliConfig(current, env, platform),\n };\n}\n\nexport function isRuntimeName(value: string | undefined): value is RuntimeName {\n return value != null && RUNTIME_NAMES.includes(value as RuntimeName);\n}\n\nexport function isCliConfigKey(value: string): value is CliConfigKey {\n return value in CLI_CONFIG_VALUE_SCHEMAS;\n}\n"],"mappings":";;;;;;;;;;;;;;AAgBO,IAAM,gBAAgB;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAeA,IAAM,kBAAkB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,SAAS,2BACd,uBAAkD,CAAC,GACzB;AAC1B,SAAO,gBAAgB;AAAA,IAAO,CAAC,iBAC7B,qBAAqB,MAAM,CAAC,YAAY,aAAa,aAAa,OAAO,CAAC;AAAA,EAC5E;AACF;AAEO,SAAS,yBACd,uBAAkD,CAAC,GACpC;AACf,SAAO,2BAA2B,oBAAoB,EAAE;AAAA,IACtD,CAAC,iBAAiB,aAAa;AAAA,EACjC;AACF;AAEO,SAAS,cAAc,SAKb;AACf,QAAM,uBAAuB,SAAS,wBAAwB,CAAC;AAC/D,QAAM,0BACJ,2BAA2B,oBAAoB;AAEjD,MAAI,wBAAwB,WAAW,GAAG;AACxC,UAAM,IAAI;AAAA,MACR,kDAAkD,qBAAqB,KAAK,IAAI,CAAC;AAAA,IACnF;AAAA,EACF;AAEA,QAAM,aACJ,SAAS,QACT,SAAS,kBACT,wBAAwB,CAAC,EAAG;AAC9B,QAAM,uBAAuB,wBAAwB;AAAA,IACnD,CAAC,iBAAiB,aAAa,gBAAgB;AAAA,EACjD;AAEA,MAAI,CAAC,sBAAsB;AACzB,UAAM,IAAI;AAAA,MACR,mCAAmC,UAAU,yBAAyB,wBACnE,IAAI,CAAC,iBAAiB,aAAa,WAAW,EAC9C,KAAK,IAAI,CAAC;AAAA,IACf;AAAA,EACF;AAEA,SAAO,IAAI,qBAAqB,SAAS,MAAM;AACjD;AAEO,SAAS,uBACd,SACqB;AAC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AK,QAAQ;AAC3C,QAAM,OAAO;AAAA,IACX,GAAG;AAAA,IACH,CAAC,GAAG,GAAG,yBAAyB,GAAG,EAAE,MAAM,KAAK;AAAA,EAClD;AAEA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,YAAY,eAAe,MAAM,KAAK,QAAQ;AAAA,EAChD;AACF;AAEO,SAAS,oBACd,KACA,MAAyB,QAAQ,KACjC,WAAW,QAAQ,UACwB;AAC3C,QAAM,UAAU,EAAE,GAAG,cAAc,KAAK,QAAQ,EAAE;AAClD,SAAO,QAAQ,GAAG;AAElB,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,YAAY,eAAe,SAAS,KAAK,QAAQ;AAAA,EACnD;AACF;AAEO,SAAS,cAAc,OAAiD;AAC7E,SAAO,SAAS,QAAQ,cAAc,SAAS,KAAoB;AACrE;AAEO,SAAS,eAAe,OAAsC;AACnE,SAAO,SAAS;AAClB;","names":[]}
|
package/dist/cli/index.d.ts
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from 'commander';
|
|
3
|
-
import { RuntimeName } from '../
|
|
4
|
-
import '../runtime-
|
|
3
|
+
import { R as RuntimeName } from '../registry-DkM8QbUx.js';
|
|
4
|
+
import '../runtime-Zjyjv8M_.js';
|
|
5
|
+
import '../runtimes/claude.js';
|
|
6
|
+
import '@anthropic-ai/claude-agent-sdk';
|
|
7
|
+
import '../runtimes/codex.js';
|
|
8
|
+
import '@openai/codex-sdk';
|
|
9
|
+
import '../runtimes/copilot.js';
|
|
10
|
+
import '../runtimes/gemini.js';
|
|
5
11
|
|
|
6
12
|
declare const RUNTIME_SELECTION_ENV = "CODE_AGENT_KIT_RUNTIME";
|
|
7
|
-
declare function getDefaultRuntime(env?: NodeJS.ProcessEnv
|
|
13
|
+
declare function getDefaultRuntime(env?: NodeJS.ProcessEnv, config?: {
|
|
14
|
+
runtime?: "claude" | "codex" | "copilot" | "gemini" | undefined;
|
|
15
|
+
model?: string | undefined;
|
|
16
|
+
systemPrompt?: string | undefined;
|
|
17
|
+
directory?: string | undefined;
|
|
18
|
+
timeoutMs?: number | undefined;
|
|
19
|
+
}): RuntimeName;
|
|
8
20
|
declare function createCliProgram(): Command;
|
|
21
|
+
declare function runCli(argv?: string[]): Promise<void>;
|
|
9
22
|
|
|
10
|
-
export { RUNTIME_SELECTION_ENV, createCliProgram, getDefaultRuntime };
|
|
23
|
+
export { RUNTIME_SELECTION_ENV, createCliProgram, getDefaultRuntime, runCli };
|
package/dist/cli/index.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
+
CLI_CONFIG_KEYS,
|
|
3
4
|
createRuntime,
|
|
4
|
-
getAvailableRuntimeNames
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
getAvailableRuntimeNames,
|
|
6
|
+
getCliConfigPath,
|
|
7
|
+
isCliConfigKey,
|
|
8
|
+
isRuntimeName,
|
|
9
|
+
readCliConfig,
|
|
10
|
+
setCliConfigValue,
|
|
11
|
+
unsetCliConfigValue
|
|
12
|
+
} from "../chunk-VPJA6I2O.js";
|
|
13
|
+
import "../chunk-BPQL5GAO.js";
|
|
14
|
+
import "../chunk-UINMTZRO.js";
|
|
15
|
+
import "../chunk-4OVN4G22.js";
|
|
16
|
+
import "../chunk-4LBC5KHN.js";
|
|
17
|
+
import "../chunk-R7CCLWKJ.js";
|
|
11
18
|
|
|
12
19
|
// src/cli/index.ts
|
|
13
20
|
import { Command, Option } from "commander";
|
|
@@ -15,23 +22,68 @@ import { pathToFileURL } from "url";
|
|
|
15
22
|
var AVAILABLE_RUNTIMES = getAvailableRuntimeNames();
|
|
16
23
|
var RUNTIME_SELECTION_ENV = "CODE_AGENT_KIT_RUNTIME";
|
|
17
24
|
var FALLBACK_RUNTIME = "claude";
|
|
18
|
-
function
|
|
19
|
-
return AVAILABLE_RUNTIMES.includes(value);
|
|
20
|
-
}
|
|
21
|
-
function getDefaultRuntime(env = process.env) {
|
|
25
|
+
function getDefaultRuntime(env = process.env, config = readCliConfig(env)) {
|
|
22
26
|
if (isRuntimeName(env[RUNTIME_SELECTION_ENV])) {
|
|
23
27
|
return env[RUNTIME_SELECTION_ENV];
|
|
24
28
|
}
|
|
25
29
|
if (isRuntimeName(env.DEFAULT_RUNTIME)) {
|
|
26
30
|
return env.DEFAULT_RUNTIME;
|
|
27
31
|
}
|
|
32
|
+
if (config.runtime) {
|
|
33
|
+
return config.runtime;
|
|
34
|
+
}
|
|
28
35
|
return FALLBACK_RUNTIME;
|
|
29
36
|
}
|
|
37
|
+
function parseTimeoutMs(value) {
|
|
38
|
+
if (value == null) {
|
|
39
|
+
return void 0;
|
|
40
|
+
}
|
|
41
|
+
const timeoutMs = typeof value === "number" ? value : Number.parseInt(value, 10);
|
|
42
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
43
|
+
throw new Error(`Invalid timeout value: ${value}`);
|
|
44
|
+
}
|
|
45
|
+
return timeoutMs;
|
|
46
|
+
}
|
|
47
|
+
function createConfigCommand() {
|
|
48
|
+
const config = new Command("config").description(
|
|
49
|
+
`Manage local CLI config at ${getCliConfigPath()}`
|
|
50
|
+
);
|
|
51
|
+
config.command("show").description("Print the current local CLI config").action(() => {
|
|
52
|
+
console.log(JSON.stringify(readCliConfig(), null, 2));
|
|
53
|
+
});
|
|
54
|
+
config.command("path").description("Print the local CLI config path").action(() => {
|
|
55
|
+
console.log(getCliConfigPath());
|
|
56
|
+
});
|
|
57
|
+
config.command("set").description(`Set a config value (${CLI_CONFIG_KEYS.join(", ")})`).argument("<key>", "Config key").argument("<value>", "Config value").action((key, value) => {
|
|
58
|
+
if (!isCliConfigKey(key)) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
`Unknown config key: ${key}. Supported keys: ${CLI_CONFIG_KEYS.join(", ")}`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
const { configPath } = setCliConfigValue(key, value);
|
|
64
|
+
console.log(`Updated ${key} in ${configPath}`);
|
|
65
|
+
});
|
|
66
|
+
config.command("unset").description(`Remove a config value (${CLI_CONFIG_KEYS.join(", ")})`).argument("<key>", "Config key").action((key) => {
|
|
67
|
+
if (!isCliConfigKey(key)) {
|
|
68
|
+
throw new Error(
|
|
69
|
+
`Unknown config key: ${key}. Supported keys: ${CLI_CONFIG_KEYS.join(", ")}`
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
const { configPath } = unsetCliConfigValue(key);
|
|
73
|
+
console.log(`Removed ${key} from ${configPath}`);
|
|
74
|
+
});
|
|
75
|
+
return config;
|
|
76
|
+
}
|
|
77
|
+
function buildRuntimeConfig(options, config) {
|
|
78
|
+
const model = options.model ?? config.model;
|
|
79
|
+
return model ? { model } : void 0;
|
|
80
|
+
}
|
|
30
81
|
function createCliProgram() {
|
|
31
|
-
const
|
|
32
|
-
|
|
82
|
+
const cliConfig = readCliConfig();
|
|
83
|
+
const defaultRuntime = getDefaultRuntime(process.env, cliConfig);
|
|
84
|
+
return new Command().name("code-agent-kit").description("Run a prompt against a supported coding-agent runtime").version("0.1.0").showHelpAfterError().addCommand(createConfigCommand()).argument("<prompt>", "Task description or prompt for the agent").addOption(
|
|
33
85
|
new Option("-t, --runtime <name>", "Agent runtime to use").choices(AVAILABLE_RUNTIMES).default(defaultRuntime)
|
|
34
|
-
).option("-d, --directory <path>", "Working directory"
|
|
86
|
+
).option("-m, --model <name>", "Model override for the selected runtime").option("-d, --directory <path>", "Working directory override").option("-r, --resume <sessionId>", "Resume a previous session by ID").option("--timeout <ms>", "Timeout in milliseconds").option("-s, --system <text>", "System prompt text").option(
|
|
35
87
|
"-f, --file <path>",
|
|
36
88
|
"Attach a text file (can be used multiple times)",
|
|
37
89
|
(value, previous) => previous.concat(value),
|
|
@@ -41,15 +93,16 @@ function createCliProgram() {
|
|
|
41
93
|
const runtimeOptionSource = command.getOptionValueSource("runtime");
|
|
42
94
|
const runtime = createRuntime({
|
|
43
95
|
name: opts.runtime,
|
|
44
|
-
defaultRuntime
|
|
96
|
+
defaultRuntime,
|
|
97
|
+
config: buildRuntimeConfig(opts, cliConfig)
|
|
45
98
|
});
|
|
46
99
|
const result = await runtime.run({
|
|
47
|
-
workingDirectory: opts.directory,
|
|
100
|
+
workingDirectory: opts.directory ?? cliConfig.directory ?? process.cwd(),
|
|
48
101
|
prompt,
|
|
49
|
-
systemPrompt: opts.system,
|
|
102
|
+
systemPrompt: opts.system ?? cliConfig.systemPrompt,
|
|
50
103
|
attachments: opts.file.map((filePath) => ({ path: filePath })),
|
|
51
104
|
env: runtimeOptionSource === "cli" ? { [RUNTIME_SELECTION_ENV]: opts.runtime } : void 0,
|
|
52
|
-
timeoutMs: opts.timeout
|
|
105
|
+
timeoutMs: parseTimeoutMs(opts.timeout ?? cliConfig.timeoutMs),
|
|
53
106
|
session: opts.resume ? { mode: "resume", sessionId: opts.resume } : void 0
|
|
54
107
|
});
|
|
55
108
|
if (result.sessionId) {
|
|
@@ -66,10 +119,13 @@ function createCliProgram() {
|
|
|
66
119
|
}
|
|
67
120
|
);
|
|
68
121
|
}
|
|
122
|
+
async function runCli(argv = process.argv) {
|
|
123
|
+
await createCliProgram().parseAsync(argv);
|
|
124
|
+
}
|
|
69
125
|
if (process.argv[1]) {
|
|
70
126
|
const entryUrl = pathToFileURL(process.argv[1]).href;
|
|
71
127
|
if (import.meta.url === entryUrl) {
|
|
72
|
-
|
|
128
|
+
runCli().catch((error) => {
|
|
73
129
|
const message = error instanceof Error ? error.message : String(error);
|
|
74
130
|
console.error(message);
|
|
75
131
|
process.exit(1);
|
|
@@ -79,6 +135,7 @@ if (process.argv[1]) {
|
|
|
79
135
|
export {
|
|
80
136
|
RUNTIME_SELECTION_ENV,
|
|
81
137
|
createCliProgram,
|
|
82
|
-
getDefaultRuntime
|
|
138
|
+
getDefaultRuntime,
|
|
139
|
+
runCli
|
|
83
140
|
};
|
|
84
141
|
//# sourceMappingURL=index.js.map
|
package/dist/cli/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/cli/index.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { Command, Option } from \"commander\";\nimport { pathToFileURL } from \"node:url\";\nimport {\n
|
|
1
|
+
{"version":3,"sources":["../../src/cli/index.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { Command, Option } from \"commander\";\nimport { pathToFileURL } from \"node:url\";\nimport {\n CLI_CONFIG_KEYS,\n getCliConfigPath,\n isCliConfigKey,\n isRuntimeName,\n readCliConfig,\n setCliConfigValue,\n unsetCliConfigValue,\n type CliConfig,\n} from \"../config.js\";\nimport { createRuntime, getAvailableRuntimeNames, type RuntimeName } from \"../runtimes/registry.js\";\n\nconst AVAILABLE_RUNTIMES = getAvailableRuntimeNames();\nexport const RUNTIME_SELECTION_ENV = \"CODE_AGENT_KIT_RUNTIME\";\nconst FALLBACK_RUNTIME: RuntimeName = \"claude\";\n\ninterface RunCliOptions {\n runtime: RuntimeName;\n model?: string;\n directory?: string;\n resume?: string;\n timeout?: string;\n system?: string;\n file: string[];\n}\n\nexport function getDefaultRuntime(\n env: NodeJS.ProcessEnv = process.env,\n config = readCliConfig(env),\n): RuntimeName {\n if (isRuntimeName(env[RUNTIME_SELECTION_ENV])) {\n return env[RUNTIME_SELECTION_ENV];\n }\n\n if (isRuntimeName(env.DEFAULT_RUNTIME)) {\n return env.DEFAULT_RUNTIME;\n }\n\n if (config.runtime) {\n return config.runtime;\n }\n\n return FALLBACK_RUNTIME;\n}\n\nfunction parseTimeoutMs(value: number | string | undefined): number | undefined {\n if (value == null) {\n return undefined;\n }\n\n const timeoutMs =\n typeof value === \"number\" ? value : Number.parseInt(value, 10);\n\n if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {\n throw new Error(`Invalid timeout value: ${value}`);\n }\n\n return timeoutMs;\n}\n\nfunction createConfigCommand(): Command {\n const config = new Command(\"config\").description(\n `Manage local CLI config at ${getCliConfigPath()}`,\n );\n\n config\n .command(\"show\")\n .description(\"Print the current local CLI config\")\n .action(() => {\n console.log(JSON.stringify(readCliConfig(), null, 2));\n });\n\n config\n .command(\"path\")\n .description(\"Print the local CLI config path\")\n .action(() => {\n console.log(getCliConfigPath());\n });\n\n config\n .command(\"set\")\n .description(`Set a config value (${CLI_CONFIG_KEYS.join(\", \")})`)\n .argument(\"<key>\", \"Config key\")\n .argument(\"<value>\", \"Config value\")\n .action((key: string, value: string) => {\n if (!isCliConfigKey(key)) {\n throw new Error(\n `Unknown config key: ${key}. Supported keys: ${CLI_CONFIG_KEYS.join(\", \")}`,\n );\n }\n\n const { configPath } = setCliConfigValue(key, value);\n console.log(`Updated ${key} in ${configPath}`);\n });\n\n config\n .command(\"unset\")\n .description(`Remove a config value (${CLI_CONFIG_KEYS.join(\", \")})`)\n .argument(\"<key>\", \"Config key\")\n .action((key: string) => {\n if (!isCliConfigKey(key)) {\n throw new Error(\n `Unknown config key: ${key}. Supported keys: ${CLI_CONFIG_KEYS.join(\", \")}`,\n );\n }\n\n const { configPath } = unsetCliConfigValue(key);\n console.log(`Removed ${key} from ${configPath}`);\n });\n\n return config;\n}\n\nfunction buildRuntimeConfig(\n options: Pick<RunCliOptions, \"model\">,\n config: CliConfig,\n): { model?: string } | undefined {\n const model = options.model ?? config.model;\n return model ? { model } : undefined;\n}\n\nexport function createCliProgram(): Command {\n const cliConfig = readCliConfig();\n const defaultRuntime = getDefaultRuntime(process.env, cliConfig);\n\n return new Command()\n .name(\"code-agent-kit\")\n .description(\"Run a prompt against a supported coding-agent runtime\")\n .version(\"0.1.0\")\n .showHelpAfterError()\n .addCommand(createConfigCommand())\n .argument(\"<prompt>\", \"Task description or prompt for the agent\")\n .addOption(\n new Option(\"-t, --runtime <name>\", \"Agent runtime to use\")\n .choices(AVAILABLE_RUNTIMES)\n .default(defaultRuntime),\n )\n .option(\"-m, --model <name>\", \"Model override for the selected runtime\")\n .option(\"-d, --directory <path>\", \"Working directory override\")\n .option(\"-r, --resume <sessionId>\", \"Resume a previous session by ID\")\n .option(\"--timeout <ms>\", \"Timeout in milliseconds\")\n .option(\"-s, --system <text>\", \"System prompt text\")\n .option(\n \"-f, --file <path>\",\n \"Attach a text file (can be used multiple times)\",\n (value: string, previous: string[]) => previous.concat(value),\n [] as string[],\n )\n .action(\n async (\n prompt: string,\n opts: RunCliOptions,\n command: Command,\n ) => {\n const runtimeOptionSource = command.getOptionValueSource(\"runtime\");\n const runtime = createRuntime({\n name: opts.runtime,\n defaultRuntime,\n config: buildRuntimeConfig(opts, cliConfig),\n });\n\n const result = await runtime.run({\n workingDirectory: opts.directory ?? cliConfig.directory ?? process.cwd(),\n prompt,\n systemPrompt: opts.system ?? cliConfig.systemPrompt,\n attachments: opts.file.map((filePath) => ({ path: filePath })),\n env:\n runtimeOptionSource === \"cli\"\n ? { [RUNTIME_SELECTION_ENV]: opts.runtime }\n : undefined,\n timeoutMs: parseTimeoutMs(opts.timeout ?? cliConfig.timeoutMs),\n session: opts.resume\n ? { mode: \"resume\", sessionId: opts.resume }\n : undefined,\n });\n\n if (result.sessionId) {\n console.error(`Session ID: ${result.sessionId}`);\n }\n\n if (!result.success) {\n console.error(result.error ?? \"Runtime execution failed.\");\n process.exitCode = 1;\n return;\n }\n\n if (result.output) {\n console.log(result.output);\n }\n },\n );\n}\n\nexport async function runCli(argv = process.argv): Promise<void> {\n await createCliProgram().parseAsync(argv);\n}\n\nif (process.argv[1]) {\n const entryUrl = pathToFileURL(process.argv[1]).href;\n if (import.meta.url === entryUrl) {\n runCli().catch((error: unknown) => {\n const message = error instanceof Error ? error.message : String(error);\n console.error(message);\n process.exit(1);\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAEA,SAAS,SAAS,cAAc;AAChC,SAAS,qBAAqB;AAa9B,IAAM,qBAAqB,yBAAyB;AAC7C,IAAM,wBAAwB;AACrC,IAAM,mBAAgC;AAY/B,SA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A,IAChB,CAAC;AAAA,EACH;AACF;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export { A as AgentResult, a as AgentRuntime, R as RuntimeAttachment, b as RuntimeCapabilities, c as RuntimeEvent, d as RuntimeFeature, e as RuntimeRunOptions, f as RuntimeSession, U as UnsupportedRuntimeFeatureError, g as assertRuntimeRunOptionsSupported, h as assertRuntimeSupports, i as buildRuntimePrompt, j as getRequestedRuntimeFeatures } from './runtime-Zjyjv8M_.js';
|
|
2
|
+
import { R as RuntimeName } from './registry-DkM8QbUx.js';
|
|
3
|
+
export { a as RUNTIME_NAMES, b as RuntimeConfig, c as RuntimeConfigByName, d as createRuntime, g as getAvailableRuntimeClasses, e as getAvailableRuntimeNames, f as getRuntimeCapabilities } from './registry-DkM8QbUx.js';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import './runtimes/claude.js';
|
|
6
|
+
import '@anthropic-ai/claude-agent-sdk';
|
|
7
|
+
import './runtimes/codex.js';
|
|
8
|
+
import '@openai/codex-sdk';
|
|
9
|
+
import './runtimes/copilot.js';
|
|
10
|
+
import './runtimes/gemini.js';
|
|
3
11
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
12
|
+
declare const CliConfigSchema: z.ZodObject<{
|
|
13
|
+
runtime: z.ZodOptional<z.ZodEnum<{
|
|
14
|
+
codex: "codex";
|
|
15
|
+
claude: "claude";
|
|
16
|
+
copilot: "copilot";
|
|
17
|
+
gemini: "gemini";
|
|
18
|
+
}>>;
|
|
19
|
+
model: z.ZodOptional<z.ZodString>;
|
|
20
|
+
systemPrompt: z.ZodOptional<z.ZodString>;
|
|
21
|
+
directory: z.ZodOptional<z.ZodString>;
|
|
22
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
23
|
+
}, z.core.$strict>;
|
|
24
|
+
type CliConfig = z.infer<typeof CliConfigSchema>;
|
|
25
|
+
type CliConfigKey = keyof CliConfig;
|
|
26
|
+
declare const CLI_CONFIG_KEYS: readonly ["runtime", "model", "systemPrompt", "directory", "timeoutMs"];
|
|
27
|
+
declare function getCliConfigDir(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): string;
|
|
28
|
+
declare function getCliConfigPath(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): string;
|
|
29
|
+
declare function readCliConfig(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): CliConfig;
|
|
30
|
+
declare function writeCliConfig(config: CliConfig, env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): string;
|
|
31
|
+
declare function setCliConfigValue<K extends CliConfigKey>(key: K, value: string, env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): {
|
|
32
|
+
config: CliConfig;
|
|
33
|
+
configPath: string;
|
|
7
34
|
};
|
|
8
|
-
declare function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}): AgentRuntime;
|
|
15
|
-
declare function getRuntimeCapabilities(runtime: AgentRuntime): RuntimeCapabilities;
|
|
35
|
+
declare function unsetCliConfigValue<K extends CliConfigKey>(key: K, env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): {
|
|
36
|
+
config: CliConfig;
|
|
37
|
+
configPath: string;
|
|
38
|
+
};
|
|
39
|
+
declare function isRuntimeName(value: string | undefined): value is RuntimeName;
|
|
40
|
+
declare function isCliConfigKey(value: string): value is CliConfigKey;
|
|
16
41
|
|
|
17
|
-
export {
|
|
42
|
+
export { CLI_CONFIG_KEYS, type CliConfig, type CliConfigKey, CliConfigSchema, RuntimeName, getCliConfigDir, getCliConfigPath, isCliConfigKey, isRuntimeName, readCliConfig, setCliConfigValue, unsetCliConfigValue, writeCliConfig };
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,35 @@
|
|
|
1
1
|
import {
|
|
2
|
+
CLI_CONFIG_KEYS,
|
|
3
|
+
CliConfigSchema,
|
|
4
|
+
RUNTIME_NAMES,
|
|
2
5
|
createRuntime,
|
|
3
6
|
getAvailableRuntimeClasses,
|
|
4
7
|
getAvailableRuntimeNames,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
getCliConfigDir,
|
|
9
|
+
getCliConfigPath,
|
|
10
|
+
getRuntimeCapabilities,
|
|
11
|
+
isCliConfigKey,
|
|
12
|
+
isRuntimeName,
|
|
13
|
+
readCliConfig,
|
|
14
|
+
setCliConfigValue,
|
|
15
|
+
unsetCliConfigValue,
|
|
16
|
+
writeCliConfig
|
|
17
|
+
} from "./chunk-VPJA6I2O.js";
|
|
18
|
+
import "./chunk-BPQL5GAO.js";
|
|
19
|
+
import "./chunk-UINMTZRO.js";
|
|
20
|
+
import "./chunk-4OVN4G22.js";
|
|
21
|
+
import "./chunk-4LBC5KHN.js";
|
|
11
22
|
import {
|
|
12
23
|
UnsupportedRuntimeFeatureError,
|
|
13
24
|
assertRuntimeRunOptionsSupported,
|
|
14
25
|
assertRuntimeSupports,
|
|
15
26
|
buildRuntimePrompt,
|
|
16
27
|
getRequestedRuntimeFeatures
|
|
17
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-R7CCLWKJ.js";
|
|
18
29
|
export {
|
|
30
|
+
CLI_CONFIG_KEYS,
|
|
31
|
+
CliConfigSchema,
|
|
32
|
+
RUNTIME_NAMES,
|
|
19
33
|
UnsupportedRuntimeFeatureError,
|
|
20
34
|
assertRuntimeRunOptionsSupported,
|
|
21
35
|
assertRuntimeSupports,
|
|
@@ -23,7 +37,15 @@ export {
|
|
|
23
37
|
createRuntime,
|
|
24
38
|
getAvailableRuntimeClasses,
|
|
25
39
|
getAvailableRuntimeNames,
|
|
40
|
+
getCliConfigDir,
|
|
41
|
+
getCliConfigPath,
|
|
26
42
|
getRequestedRuntimeFeatures,
|
|
27
|
-
getRuntimeCapabilities
|
|
43
|
+
getRuntimeCapabilities,
|
|
44
|
+
isCliConfigKey,
|
|
45
|
+
isRuntimeName,
|
|
46
|
+
readCliConfig,
|
|
47
|
+
setCliConfigValue,
|
|
48
|
+
unsetCliConfigValue,
|
|
49
|
+
writeCliConfig
|
|
28
50
|
};
|
|
29
51
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { d as RuntimeFeature, a as AgentRuntime, k as RuntimeClass, b as RuntimeCapabilities } from './runtime-Zjyjv8M_.js';
|
|
2
|
+
import { ClaudeRuntimeConfig } from './runtimes/claude.js';
|
|
3
|
+
import { CodexRuntimeConfig } from './runtimes/codex.js';
|
|
4
|
+
import { CopilotRuntimeConfig } from './runtimes/copilot.js';
|
|
5
|
+
import { GeminiRuntimeConfig } from './runtimes/gemini.js';
|
|
6
|
+
|
|
7
|
+
type RuntimeName = "claude" | "codex" | "copilot" | "gemini";
|
|
8
|
+
declare const RUNTIME_NAMES: readonly ["claude", "codex", "copilot", "gemini"];
|
|
9
|
+
interface RuntimeConfigByName {
|
|
10
|
+
claude: ClaudeRuntimeConfig;
|
|
11
|
+
codex: CodexRuntimeConfig;
|
|
12
|
+
copilot: CopilotRuntimeConfig;
|
|
13
|
+
gemini: GeminiRuntimeConfig;
|
|
14
|
+
}
|
|
15
|
+
type RuntimeConfig = RuntimeConfigByName[RuntimeName];
|
|
16
|
+
type RegisteredRuntimeClass = RuntimeClass<AgentRuntime> & {
|
|
17
|
+
readonly runtimeName: RuntimeName;
|
|
18
|
+
};
|
|
19
|
+
declare function getAvailableRuntimeClasses(requiredCapabilities?: readonly RuntimeFeature[]): RegisteredRuntimeClass[];
|
|
20
|
+
declare function getAvailableRuntimeNames(requiredCapabilities?: readonly RuntimeFeature[]): RuntimeName[];
|
|
21
|
+
declare function createRuntime(options?: {
|
|
22
|
+
name?: string;
|
|
23
|
+
requiredCapabilities?: readonly RuntimeFeature[];
|
|
24
|
+
defaultRuntime?: RuntimeName;
|
|
25
|
+
config?: RuntimeConfig;
|
|
26
|
+
}): AgentRuntime;
|
|
27
|
+
declare function getRuntimeCapabilities(runtime: AgentRuntime): RuntimeCapabilities;
|
|
28
|
+
|
|
29
|
+
export { type RuntimeName as R, RUNTIME_NAMES as a, type RuntimeConfig as b, type RuntimeConfigByName as c, createRuntime as d, getAvailableRuntimeNames as e, getRuntimeCapabilities as f, getAvailableRuntimeClasses as g };
|
|
@@ -25,7 +25,7 @@ interface RuntimeCapabilities {
|
|
|
25
25
|
readonly eventStreaming: boolean;
|
|
26
26
|
}
|
|
27
27
|
interface RuntimeClass<T extends AgentRuntime = AgentRuntime> {
|
|
28
|
-
new (): T;
|
|
28
|
+
new (...args: any[]): T;
|
|
29
29
|
readonly runtimeName: string;
|
|
30
30
|
readonly capabilities: RuntimeCapabilities;
|
|
31
31
|
}
|
|
@@ -94,4 +94,4 @@ declare function assertRuntimeSupports(runtime: AgentRuntime | RuntimeClass, fea
|
|
|
94
94
|
declare function assertRuntimeRunOptionsSupported(runtime: AgentRuntime | RuntimeClass, options: Pick<RuntimeRunOptions, "onEvent" | "session">, operation: string): void;
|
|
95
95
|
declare function buildRuntimePrompt(options: Pick<RuntimeRunOptions, "workingDirectory" | "prompt" | "attachments">): Promise<string>;
|
|
96
96
|
|
|
97
|
-
export { type
|
|
97
|
+
export { type AgentResult as A, type RuntimeAttachment as R, UnsupportedRuntimeFeatureError as U, type AgentRuntime as a, type RuntimeCapabilities as b, type RuntimeEvent as c, type RuntimeFeature as d, type RuntimeRunOptions as e, type RuntimeSession as f, assertRuntimeRunOptionsSupported as g, assertRuntimeSupports as h, buildRuntimePrompt as i, getRequestedRuntimeFeatures as j, type RuntimeClass as k };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PermissionMode, SettingSource } from '@anthropic-ai/claude-agent-sdk';
|
|
2
|
-
import {
|
|
2
|
+
import { a as AgentRuntime, e as RuntimeRunOptions, A as AgentResult } from '../runtime-Zjyjv8M_.js';
|
|
3
3
|
|
|
4
4
|
interface ClaudeRuntimeConfig {
|
|
5
5
|
/** Claude model to use (e.g., "claude-sonnet-4-20250514"). */
|
package/dist/runtimes/claude.js
CHANGED
package/dist/runtimes/codex.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SandboxMode, ApprovalMode, WebSearchMode, ModelReasoningEffort, CodexOptions } from '@openai/codex-sdk';
|
|
2
|
-
import {
|
|
2
|
+
import { a as AgentRuntime, e as RuntimeRunOptions, A as AgentResult } from '../runtime-Zjyjv8M_.js';
|
|
3
3
|
|
|
4
4
|
interface CodexRuntimeConfig {
|
|
5
5
|
/** Codex model to use. */
|
package/dist/runtimes/codex.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as AgentRuntime, e as RuntimeRunOptions, A as AgentResult } from '../runtime-Zjyjv8M_.js';
|
|
2
2
|
|
|
3
3
|
interface CopilotRuntimeConfig {
|
|
4
4
|
/** Copilot model to use. */
|
package/dist/runtimes/copilot.js
CHANGED
package/dist/runtimes/gemini.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nimashoghi/code-agent-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Multi-runtime coding agent runtime toolkit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -58,7 +58,8 @@
|
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@anthropic-ai/claude-agent-sdk": "^0.2.79",
|
|
60
60
|
"@openai/codex-sdk": "^0.115.0",
|
|
61
|
-
"commander": "^13.1.0"
|
|
61
|
+
"commander": "^13.1.0",
|
|
62
|
+
"zod": "^4.3.6"
|
|
62
63
|
},
|
|
63
64
|
"devDependencies": {
|
|
64
65
|
"@eslint/js": "^10.0.1",
|
package/dist/chunk-NKMHTQVX.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ClaudeRuntime
|
|
3
|
-
} from "./chunk-EN5WJJ2G.js";
|
|
4
|
-
import {
|
|
5
|
-
CodexRuntime
|
|
6
|
-
} from "./chunk-CGK4TBZD.js";
|
|
7
|
-
import {
|
|
8
|
-
CopilotRuntime
|
|
9
|
-
} from "./chunk-AVSJQKCD.js";
|
|
10
|
-
import {
|
|
11
|
-
GeminiRuntime
|
|
12
|
-
} from "./chunk-ZUMYGBXZ.js";
|
|
13
|
-
|
|
14
|
-
// src/runtimes/registry.ts
|
|
15
|
-
var RUNTIME_CLASSES = [
|
|
16
|
-
ClaudeRuntime,
|
|
17
|
-
CodexRuntime,
|
|
18
|
-
CopilotRuntime,
|
|
19
|
-
GeminiRuntime
|
|
20
|
-
];
|
|
21
|
-
function getAvailableRuntimeClasses(requiredCapabilities = []) {
|
|
22
|
-
return RUNTIME_CLASSES.filter(
|
|
23
|
-
(runtimeClass) => requiredCapabilities.every((feature) => runtimeClass.capabilities[feature])
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
function getAvailableRuntimeNames(requiredCapabilities = []) {
|
|
27
|
-
return getAvailableRuntimeClasses(requiredCapabilities).map(
|
|
28
|
-
(runtimeClass) => runtimeClass.runtimeName
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
function createRuntime(options) {
|
|
32
|
-
const requiredCapabilities = options?.requiredCapabilities ?? [];
|
|
33
|
-
const availableRuntimeClasses = getAvailableRuntimeClasses(requiredCapabilities);
|
|
34
|
-
if (availableRuntimeClasses.length === 0) {
|
|
35
|
-
throw new Error(
|
|
36
|
-
`No runtimes support the required capabilities: ${requiredCapabilities.join(", ")}`
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
const targetName = options?.name ?? options?.defaultRuntime ?? availableRuntimeClasses[0].runtimeName;
|
|
40
|
-
const selectedRuntimeClass = availableRuntimeClasses.find(
|
|
41
|
-
(runtimeClass) => runtimeClass.runtimeName === targetName
|
|
42
|
-
);
|
|
43
|
-
if (!selectedRuntimeClass) {
|
|
44
|
-
throw new Error(
|
|
45
|
-
`Unknown or unsupported runtime: ${targetName}. Available runtimes: ${availableRuntimeClasses.map((runtimeClass) => runtimeClass.runtimeName).join(", ")}`
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
return new selectedRuntimeClass();
|
|
49
|
-
}
|
|
50
|
-
function getRuntimeCapabilities(runtime) {
|
|
51
|
-
return runtime.constructor.capabilities;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export {
|
|
55
|
-
getAvailableRuntimeClasses,
|
|
56
|
-
getAvailableRuntimeNames,
|
|
57
|
-
createRuntime,
|
|
58
|
-
getRuntimeCapabilities
|
|
59
|
-
};
|
|
60
|
-
//# sourceMappingURL=chunk-NKMHTQVX.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/runtimes/registry.ts"],"sourcesContent":["import type {\n AgentRuntime,\n RuntimeCapabilities,\n RuntimeFeature,\n RuntimeClass,\n} from \"../runtime.js\";\nimport { ClaudeRuntime } from \"./claude.js\";\nimport { CodexRuntime } from \"./codex.js\";\nimport { CopilotRuntime } from \"./copilot.js\";\nimport { GeminiRuntime } from \"./gemini.js\";\n\nexport type RuntimeName = \"claude\" | \"codex\" | \"copilot\" | \"gemini\";\n\ntype RegisteredRuntimeClass = RuntimeClass<AgentRuntime> & {\n readonly runtimeName: RuntimeName;\n};\n\nconst RUNTIME_CLASSES = [\n ClaudeRuntime,\n CodexRuntime,\n CopilotRuntime,\n GeminiRuntime,\n] as const satisfies readonly RegisteredRuntimeClass[];\n\nexport function getAvailableRuntimeClasses(\n requiredCapabilities: readonly RuntimeFeature[] = [],\n): RegisteredRuntimeClass[] {\n return RUNTIME_CLASSES.filter((runtimeClass) =>\n requiredCapabilities.every((feature) => runtimeClass.capabilities[feature]),\n );\n}\n\nexport function getAvailableRuntimeNames(\n requiredCapabilities: readonly RuntimeFeature[] = [],\n): RuntimeName[] {\n return getAvailableRuntimeClasses(requiredCapabilities).map(\n (runtimeClass) => runtimeClass.runtimeName,\n );\n}\n\nexport function createRuntime(options?: {\n name?: string;\n requiredCapabilities?: readonly RuntimeFeature[];\n defaultRuntime?: RuntimeName;\n}): AgentRuntime {\n const requiredCapabilities = options?.requiredCapabilities ?? [];\n const availableRuntimeClasses =\n getAvailableRuntimeClasses(requiredCapabilities);\n\n if (availableRuntimeClasses.length === 0) {\n throw new Error(\n `No runtimes support the required capabilities: ${requiredCapabilities.join(\", \")}`,\n );\n }\n\n const targetName =\n options?.name ??\n options?.defaultRuntime ??\n availableRuntimeClasses[0]!.runtimeName;\n const selectedRuntimeClass = availableRuntimeClasses.find(\n (runtimeClass) => runtimeClass.runtimeName === targetName,\n );\n\n if (!selectedRuntimeClass) {\n throw new Error(\n `Unknown or unsupported runtime: ${targetName}. Available runtimes: ${availableRuntimeClasses\n .map((runtimeClass) => runtimeClass.runtimeName)\n .join(\", \")}`,\n );\n }\n\n return new selectedRuntimeClass();\n}\n\nexport function getRuntimeCapabilities(\n runtime: AgentRuntime,\n): RuntimeCapabilities {\n return (runtime.constructor as RuntimeClass).capabilities;\n}\n"],"mappings":";;;;;;;;;;;;;;AAiBA,IAAM,kBAAkB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,SAAS,2BACd,uBAAkD,CAAC,GACzB;AAC1B,SAAO,gBAAgB;AAAA,IAAO,CAAC,iBAC7B,qBAAqB,MAAM,CAAC,YAAY,aAAa,aAAa,OAAO,CAAC;AAAA,EAC5E;AACF;AAEO,SAAS,yBACd,uBAAkD,CAAC,GACpC;AACf,SAAO,2BAA2B,oBAAoB,EAAE;AAAA,IACtD,CAAC,iBAAiB,aAAa;AAAA,EACjC;AACF;AAEO,SAAS,cAAc,SAIb;AACf,QAAM,uBAAuB,SAAS,wBAAwB,CAAC;AAC/D,QAAM,0BACJ,2BAA2B,oBAAoB;AAEjD,MAAI,wBAAwB,WAAW,GAAG;AACxC,UAAM,IAAI;AAAA,MACR,kDAAkD,qBAAqB,KAAK,IAAI,CAAC;AAAA,IACnF;AAAA,EACF;AAEA,QAAM,aACJ,SAAS,QACT,SAAS,kBACT,wBAAwB,CAAC,EAAG;AAC9B,QAAM,uBAAuB,wBAAwB;AAAA,IACnD,CAAC,iBAAiB,aAAa,gBAAgB;AAAA,EACjD;AAEA,MAAI,CAAC,sBAAsB;AACzB,UAAM,IAAI;AAAA,MACR,mCAAmC,UAAU,yBAAyB,wBACnE,IAAI,CAAC,iBAAiB,aAAa,WAAW,EAC9C,KAAK,IAAI,CAAC;AAAA,IACf;AAAA,EACF;AAEA,SAAO,IAAI,qBAAqB;AAClC;AAEO,SAAS,uBACd,SACqB;AACrB,SAAQ,QAAQ,YAA6B;AAC/C;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/runtime.ts"],"sourcesContent":["import fs from \"node:fs/promises\";\nimport path from \"node:path\";\n\n/** Core runtime abstractions for running a coding agent on a task. */\n\n/** Event emitted during agent execution for real-time progress streaming. */\nexport type RuntimeEvent =\n | { type: \"text\"; content: string }\n | { type: \"tool_use\"; tool: string; input?: unknown }\n | { type: \"tool_result\"; tool: string; output?: string; isError?: boolean }\n | { type: \"thinking\"; content: string }\n | { type: \"error\"; message: string };\n\nexport type RuntimeFeature =\n | \"resumeSession\"\n | \"eventStreaming\";\n\nexport interface RuntimeCapabilities {\n readonly resumeSession: boolean;\n readonly eventStreaming: boolean;\n}\n\nexport interface RuntimeClass<T extends AgentRuntime = AgentRuntime> {\n new (): T;\n readonly runtimeName: string;\n readonly capabilities: RuntimeCapabilities;\n}\n\nexport type RuntimeSession =\n | { mode: \"new\" }\n | { mode: \"resume\"; sessionId: string };\n\n/** Options passed to AgentRuntime.run(). */\nexport interface RuntimeRunOptions {\n /** Directory the agent operates in. */\n workingDirectory: string;\n\n /** The task/instructions for the agent. */\n prompt: string;\n\n /** Optional system prompt text for the run. */\n systemPrompt?: string;\n\n /** Optional text file attachments included alongside the prompt. */\n attachments?: RuntimeAttachment[];\n\n /** Environment variables injected into the agent process. */\n env?: Record<string, string>;\n\n /** Session behavior for the run. */\n session?: RuntimeSession;\n\n /** Timeout in milliseconds. */\n timeoutMs?: number;\n\n /** Abort signal for cancellation. */\n signal?: AbortSignal;\n\n /** Optional streaming callback for real-time progress. */\n onEvent?: (event: RuntimeEvent) => void;\n}\n\n/** Result returned by AgentRuntime.run(). */\nexport interface AgentResult {\n success: boolean;\n output: string;\n error?: string;\n sessionId?: string;\n}\n\nexport interface RuntimeAttachment {\n /** File path to attach. Relative paths resolve from workingDirectory. */\n path: string;\n\n /** Optional inline content. When omitted, the file is read from disk. */\n content?: string;\n}\n\nfunction featureDescription(feature: RuntimeFeature): string {\n switch (feature) {\n case \"resumeSession\":\n return \"session resume\";\n case \"eventStreaming\":\n return \"event streaming\";\n }\n}\n\nexport class UnsupportedRuntimeFeatureError extends Error {\n readonly runtime: string;\n readonly feature: RuntimeFeature;\n readonly operation: string;\n readonly details?: string;\n\n constructor(options: {\n runtime: string;\n feature: RuntimeFeature;\n operation: string;\n details?: string;\n }) {\n const message = [\n `Runtime \"${options.runtime}\" does not support ${featureDescription(options.feature)} for ${options.operation}.`,\n options.details,\n ]\n .filter(Boolean)\n .join(\" \");\n\n super(message);\n this.name = \"UnsupportedRuntimeFeatureError\";\n this.runtime = options.runtime;\n this.feature = options.feature;\n this.operation = options.operation;\n this.details = options.details;\n }\n}\n\nfunction supportsFeature(\n capabilities: RuntimeCapabilities,\n feature: RuntimeFeature,\n): boolean {\n switch (feature) {\n case \"resumeSession\":\n return capabilities.resumeSession;\n case \"eventStreaming\":\n return capabilities.eventStreaming;\n }\n}\n\nexport function getRequestedRuntimeFeatures(\n options: Pick<RuntimeRunOptions, \"onEvent\" | \"session\">,\n): RuntimeFeature[] {\n const features: RuntimeFeature[] = [];\n\n if (options.onEvent) {\n features.push(\"eventStreaming\");\n }\n\n if (options.session?.mode === \"resume\") {\n features.push(\"resumeSession\");\n }\n\n return features;\n}\n\n/** The core abstraction: run a coding agent on a task. */\nexport interface AgentRuntime {\n readonly name: string;\n\n /** Run the agent on a prompt in a directory, return when done. */\n run(options: RuntimeRunOptions): Promise<AgentResult>;\n\n /** Optional cleanup. */\n dispose?(): Promise<void>;\n}\n\nfunction getRuntimeCapabilities(\n runtime: AgentRuntime | RuntimeClass,\n): RuntimeCapabilities {\n if (typeof runtime === \"function\") {\n return runtime.capabilities;\n }\n\n const runtimeClass = runtime.constructor as RuntimeClass;\n if (!runtimeClass.capabilities) {\n throw new Error(\n `Runtime \"${runtime.name}\" is missing static capabilities metadata on its constructor.`,\n );\n }\n\n return runtimeClass.capabilities;\n}\n\nfunction getRuntimeDisplayName(runtime: AgentRuntime | RuntimeClass): string {\n if (typeof runtime === \"function\") {\n return runtime.runtimeName;\n }\n\n const runtimeClass = runtime.constructor as RuntimeClass;\n return runtimeClass.runtimeName ?? runtime.name;\n}\n\nexport function assertRuntimeSupports(\n runtime: AgentRuntime | RuntimeClass,\n features: readonly RuntimeFeature[],\n operation: string,\n): void {\n const capabilities = getRuntimeCapabilities(runtime);\n const runtimeName = getRuntimeDisplayName(runtime);\n\n for (const feature of features) {\n if (supportsFeature(capabilities, feature)) {\n continue;\n }\n\n throw new UnsupportedRuntimeFeatureError({\n runtime: runtimeName,\n feature,\n operation,\n });\n }\n}\n\nexport function assertRuntimeRunOptionsSupported(\n runtime: AgentRuntime | RuntimeClass,\n options: Pick<RuntimeRunOptions, \"onEvent\" | \"session\">,\n operation: string,\n): void {\n assertRuntimeSupports(\n runtime,\n getRequestedRuntimeFeatures(options),\n operation,\n );\n}\n\nexport async function buildRuntimePrompt(\n options: Pick<RuntimeRunOptions, \"workingDirectory\" | \"prompt\" | \"attachments\">,\n): Promise<string> {\n const attachments = await Promise.all(\n (options.attachments ?? []).map(async (attachment) => {\n const content =\n attachment.content ??\n (await fs.readFile(\n path.resolve(options.workingDirectory, attachment.path),\n \"utf8\",\n ));\n\n return {\n path: attachment.path,\n content,\n };\n }),\n );\n\n if (attachments.length === 0) {\n return options.prompt;\n }\n\n const attachmentText = attachments\n .map(\n (attachment) =>\n [\n `Attached file: ${attachment.path}`,\n \"```\",\n attachment.content,\n \"```\",\n ].join(\"\\n\"),\n )\n .join(\"\\n\\n\");\n\n return [attachmentText, `Task:\\n${options.prompt}`].join(\"\\n\\n\");\n}\n"],"mappings":";AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AA6EjB,SAAS,mBAAmB,SAAiC;AAC3D,UAAQ,SAAS;AAAA,IACf,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,EACX;AACF;AAEO,IAAM,iCAAN,cAA6C,MAAM;AAAA,EAC/C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,SAKT;AACD,UAAM,UAAU;AAAA,MACd,YAAY,QAAQ,OAAO,sBAAsB,mBAAmB,QAAQ,OAAO,CAAC,QAAQ,QAAQ,SAAS;AAAA,MAC7G,QAAQ;AAAA,IACV,EACG,OAAO,OAAO,EACd,KAAK,GAAG;AAEX,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,UAAU,QAAQ;AACvB,SAAK,UAAU,QAAQ;AACvB,SAAK,YAAY,QAAQ;AACzB,SAAK,UAAU,QAAQ;AAAA,EACzB;AACF;AAEA,SAAS,gBACP,cACA,SACS;AACT,UAAQ,SAAS;AAAA,IACf,KAAK;AACH,aAAO,aAAa;AAAA,IACtB,KAAK;AACH,aAAO,aAAa;AAAA,EACxB;AACF;AAEO,SAAS,4BACd,SACkB;AAClB,QAAM,WAA6B,CAAC;AAEpC,MAAI,QAAQ,SAAS;AACnB,aAAS,KAAK,gBAAgB;AAAA,EAChC;AAEA,MAAI,QAAQ,SAAS,SAAS,UAAU;AACtC,aAAS,KAAK,eAAe;AAAA,EAC/B;AAEA,SAAO;AACT;AAaA,SAAS,uBACP,SACqB;AACrB,MAAI,OAAO,YAAY,YAAY;AACjC,WAAO,QAAQ;AAAA,EACjB;AAEA,QAAM,eAAe,QAA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CAAC,gBAAgB;AAAA,EAAU,QAAQ,MAAM,EAAE,EAAE,KAAK,MAAM;AACjE;","names":[]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|