@clearideas/agent-runtime-cli 0.7.1 → 0.9.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 +41 -2
- package/dist/index.d.ts +8 -43
- package/dist/index.js +296 -354
- package/package.json +9 -13
package/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# Clear Ideas Agent Runtime CLI
|
|
2
2
|
|
|
3
3
|
The `agent-runtime` CLI validates and runs agent manifests, resumes stored
|
|
4
|
-
runs, inspects events,
|
|
4
|
+
runs, inspects events, starts worker processes, and serves manifests over an
|
|
5
|
+
OpenAI-compatible API.
|
|
5
6
|
|
|
6
7
|
Install it in a project and run it with `npx`:
|
|
7
8
|
|
|
@@ -23,8 +24,12 @@ npx agent-runtime inspect run_123 --store ./.agent-runtime
|
|
|
23
24
|
npx agent-runtime events ./.agent-runtime/events.jsonl --run run_123 --tail 20
|
|
24
25
|
npx agent-runtime examples run variables --stream
|
|
25
26
|
npx agent-runtime run ./agent.yaml --store-driver sqlite --store ./.agent-runtime/runs.sqlite
|
|
27
|
+
npx agent-runtime serve ./support-chat.agent.yaml --port 8000
|
|
28
|
+
npx agent-runtime serve --server-config ./agent-runtime.server.yaml
|
|
26
29
|
```
|
|
27
30
|
|
|
31
|
+
Options accept `--name value` or `--name=value`.
|
|
32
|
+
|
|
28
33
|
`--stream` shows model text on stdout and lifecycle progress on stderr. Use
|
|
29
34
|
`--format ndjson` for a machine-readable stream containing event and result
|
|
30
35
|
messages, and `--show-reasoning` to opt into reasoning deltas in the pretty
|
|
@@ -131,7 +136,7 @@ events and must define their retention and redaction policy.
|
|
|
131
136
|
The default file store is intended for one process. Select
|
|
132
137
|
`--store-driver sqlite --store ./runs.sqlite` for a transactional local store
|
|
133
138
|
that can safely fence resume attempts across processes. The SQLite driver uses
|
|
134
|
-
Node's built-in SQLite API and therefore requires Node
|
|
139
|
+
Node's built-in SQLite API and therefore requires Node.js 22.20.0 or newer.
|
|
135
140
|
|
|
136
141
|
For a reusable invocation, define an agent run manifest that references an
|
|
137
142
|
agent:
|
|
@@ -155,6 +160,20 @@ For an ad hoc run, `--variables ./overrides.json` accepts the override array
|
|
|
155
160
|
directly. Agent Runtime rejects undeclared keys, duplicate keys, dotted override
|
|
156
161
|
keys, and values that do not match the declared type.
|
|
157
162
|
|
|
163
|
+
For an agent that declares conversation messages, `--messages ./turn.json`
|
|
164
|
+
supplies the history (an array, or `{ messages, signature }`),
|
|
165
|
+
`--messages-scope` binds signatures to a conversation, and
|
|
166
|
+
`--messages-out ./next.json` writes the returned history and signature in the
|
|
167
|
+
form the next turn reads. The completion summary reports only the message
|
|
168
|
+
count and whether the history is signed. Signing keys come from the
|
|
169
|
+
configuration's `messages.signing` section:
|
|
170
|
+
|
|
171
|
+
```sh
|
|
172
|
+
npx agent-runtime run ./chat.agent.yaml --config ./agent-runtime.config.yaml \
|
|
173
|
+
--messages ./turn-3.json --messages-scope conversation:42 \
|
|
174
|
+
--messages-out ./turn-3.out.json
|
|
175
|
+
```
|
|
176
|
+
|
|
158
177
|
## Runtime modules
|
|
159
178
|
|
|
160
179
|
Capabilities that depend on the host are supplied by an optional local ESM
|
|
@@ -233,3 +252,23 @@ newline-delimited `ready`, `event`, `result`, or `error` messages to stdout.
|
|
|
233
252
|
Child-process and remote execution adapters launch this command. The worker
|
|
234
253
|
uses only host-pinned `--config` and `--runtime-module` files; request-supplied
|
|
235
254
|
paths and inline configuration are rejected by default.
|
|
255
|
+
|
|
256
|
+
## Serve command
|
|
257
|
+
|
|
258
|
+
`agent-runtime serve` exposes agent manifests as models on an
|
|
259
|
+
OpenAI-compatible API (`/v1/models`, `/v1/chat/completions`), so chat front
|
|
260
|
+
ends and OpenAI SDKs can run whole agents:
|
|
261
|
+
|
|
262
|
+
```sh
|
|
263
|
+
export AGENT_RUNTIME_API_KEY="a-key-you-choose"
|
|
264
|
+
npx agent-runtime serve ./support-chat.agent.yaml --config ./runtime.yaml --port 8000
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
With no arguments, it reads `agent-runtime.server.yaml` (or `.yml`, `.json`)
|
|
268
|
+
from the working directory; `--server-config <file>` selects another file.
|
|
269
|
+
Manifests that declare `messages` receive the chat as conversation turns;
|
|
270
|
+
others receive variables mapped with `--input <variable>=<source>`. Serve
|
|
271
|
+
follows the worker's trust rules: webhook steps need an authorizing executor
|
|
272
|
+
from the runtime module, and requests never supply configuration. `--check`
|
|
273
|
+
validates everything and exits. See
|
|
274
|
+
[Serve agents over an OpenAI-compatible API](https://agent-runtime.clearideas.com/serving).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,40 +1,14 @@
|
|
|
1
|
-
import type { AgentManifest, RunResult
|
|
2
|
-
import { type ArtifactStore, type ApprovalAdapter, type ConnectionCredentialProvider, type EventSink, type ModelAdapter, type RunSandboxProvider, type RunStore, type SandboxAdapter, type StepExecutor, type SubRunAdapter, type ContextSummarizerAdapter, type ToolAdapter, type WorkspaceProvider } from "@clearideas/agent-runtime-core";
|
|
3
|
-
import type { SandboxProvider } from "@clearideas/agent-runtime-sandbox";
|
|
1
|
+
import type { AgentManifest, RunResult } from "@clearideas/agent-runtime-contracts";
|
|
4
2
|
import { type ExecutionRequest, type WorkerInvocation, type WorkerMessage } from "@clearideas/agent-runtime-execution";
|
|
5
3
|
import { type AgentRuntimeConfig, type ConfiguredMcpToolAdapterOptions, type ModelAuthorizationPolicy, type WorkspaceCompositionOptions } from "@clearideas/agent-runtime-config";
|
|
4
|
+
import { type HostRuntime, type HostRuntimeModule, type ServeOptions } from "@clearideas/agent-runtime-server";
|
|
6
5
|
export interface CliIo {
|
|
7
6
|
stdout: (text: string) => void;
|
|
8
7
|
stderr: (text: string) => void;
|
|
9
8
|
}
|
|
10
9
|
export type CliStoreDriver = "file" | "sqlite";
|
|
11
10
|
/** Adapters a local runtime module may contribute to CLI execution. */
|
|
12
|
-
export
|
|
13
|
-
/** Called once after execution, including failed setup. Own only module-created resources. */
|
|
14
|
-
shutdown?: () => void | Promise<void>;
|
|
15
|
-
runStore?: RunStore;
|
|
16
|
-
artifactStore?: ArtifactStore;
|
|
17
|
-
model?: ModelAdapter;
|
|
18
|
-
tools?: ToolAdapter;
|
|
19
|
-
connectionCredentials?: ConnectionCredentialProvider;
|
|
20
|
-
approvals?: ApprovalAdapter;
|
|
21
|
-
sandbox?: SandboxAdapter;
|
|
22
|
-
subRuns?: SubRunAdapter;
|
|
23
|
-
/** Resolves manifest workspace bindings instead of the configuration's `workspaces` section. */
|
|
24
|
-
workspaces?: WorkspaceProvider;
|
|
25
|
-
/** Opens run sandboxes instead of the configuration's `sandbox` section. */
|
|
26
|
-
runSandbox?: RunSandboxProvider;
|
|
27
|
-
/** Backs `sandbox.driver: host` in the configuration. */
|
|
28
|
-
sandboxProvider?: SandboxProvider;
|
|
29
|
-
eventSinks?: EventSink[];
|
|
30
|
-
stepExecutors?: StepExecutor[];
|
|
31
|
-
/** Host default execution policies; manifests and steps override them. */
|
|
32
|
-
policies?: ExecutionPolicies;
|
|
33
|
-
/** Host execution policies applied last; manifests cannot override them. */
|
|
34
|
-
enforcedPolicies?: ExecutionPolicies;
|
|
35
|
-
/** Observes, changes, or replaces context summarization. */
|
|
36
|
-
summarizer?: ContextSummarizerAdapter;
|
|
37
|
-
}
|
|
11
|
+
export type CliRuntime = HostRuntime;
|
|
38
12
|
export interface CliRuntimeContext {
|
|
39
13
|
manifest: AgentManifest;
|
|
40
14
|
runId?: string;
|
|
@@ -45,20 +19,7 @@ export interface CliRuntimeContext {
|
|
|
45
19
|
artifactDirectory?: string;
|
|
46
20
|
}
|
|
47
21
|
export type CliStoreContext = Omit<CliRuntimeContext, "manifest">;
|
|
48
|
-
export
|
|
49
|
-
store?: RunStore;
|
|
50
|
-
artifacts?: ArtifactStore;
|
|
51
|
-
modelAdapter?: ModelAdapter;
|
|
52
|
-
toolAdapter?: ToolAdapter;
|
|
53
|
-
credentialProvider?: ConnectionCredentialProvider;
|
|
54
|
-
approvalAdapter?: ApprovalAdapter;
|
|
55
|
-
sandboxAdapter?: SandboxAdapter;
|
|
56
|
-
subRunAdapter?: SubRunAdapter;
|
|
57
|
-
workspaceProvider?: WorkspaceProvider;
|
|
58
|
-
runSandboxProvider?: RunSandboxProvider;
|
|
59
|
-
eventSink?: EventSink;
|
|
60
|
-
executors?: StepExecutor[];
|
|
61
|
-
}
|
|
22
|
+
export type CliRuntimeModule = HostRuntimeModule;
|
|
62
23
|
export interface PortableWorkerOptions {
|
|
63
24
|
storeDirectory: string;
|
|
64
25
|
storeDriver?: CliStoreDriver;
|
|
@@ -100,6 +61,10 @@ export interface PortableWorkerOptions {
|
|
|
100
61
|
}
|
|
101
62
|
/** Runs one provider-neutral worker invocation in the current process. */
|
|
102
63
|
export declare const executeWorkerInvocation: (invocation: WorkerInvocation, options: PortableWorkerOptions) => Promise<RunResult>;
|
|
64
|
+
/** Parse `agent-runtime serve` arguments into server options. */
|
|
65
|
+
export declare const parseServeArguments: (args: string[]) => ServeOptions & {
|
|
66
|
+
check?: boolean;
|
|
67
|
+
};
|
|
103
68
|
export interface CliRunOptions {
|
|
104
69
|
signal?: AbortSignal;
|
|
105
70
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { fileURLToPath
|
|
4
|
-
import {
|
|
5
|
-
import { executionPoliciesSchema, parseAgentVariableOverrides, } from "@clearideas/agent-runtime-contracts";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { messagesSignatureSchema, parseAgentVariableOverrides, parseConversationMessages, } from "@clearideas/agent-runtime-contracts";
|
|
6
5
|
import { AgentRuntime, } from "@clearideas/agent-runtime-core";
|
|
7
6
|
import { EXECUTION_PROTOCOL_VERSION, parseWorkerInvocation, serializeWorkerMessage, } from "@clearideas/agent-runtime-execution";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { PromptStepExecutor } from "@clearideas/agent-runtime-step-prompt";
|
|
11
|
-
import { ApprovalStepExecutor, CodeStepExecutor, SubRunStepExecutor, WebhookStepExecutor, } from "@clearideas/agent-runtime-step-standard";
|
|
7
|
+
import { discoverMcpConnectionTools, loadAgentRuntimeConfig, parseAgentRuntimeConfig, validateRuntimeConfiguration, } from "@clearideas/agent-runtime-config";
|
|
8
|
+
import { composeHostRuntime, hostRuntimeDependencies, loadHostRunStore, loadHostRuntime, resolveAgentRuntimeConfig, runServe, validateHostRuntime, } from "@clearideas/agent-runtime-server";
|
|
12
9
|
import { FileArtifactStore, FileAgentManifestSource, FileAgentRunManifestSource, FileRunStore, JsonlEventSink, } from "@clearideas/agent-runtime-store-local";
|
|
13
|
-
import { Document as YamlDocument, YAMLMap, isPair, isScalar } from "yaml";
|
|
10
|
+
import { Document as YamlDocument, YAMLMap, isPair, isScalar, parse as parseYamlDocument, } from "yaml";
|
|
14
11
|
const defaultIo = {
|
|
15
12
|
stdout: (text) => process.stdout.write(text),
|
|
16
13
|
stderr: (text) => process.stderr.write(text),
|
|
@@ -21,8 +18,8 @@ Usage:
|
|
|
21
18
|
agent-runtime validate <manifest.json|manifest.yaml> [--config <config.yaml>]
|
|
22
19
|
agent-runtime config validate <config.json|config.yaml>
|
|
23
20
|
agent-runtime connections inspect <config.json|config.yaml> [--connection <name>] [--runtime-module <local-js-file>] [--format <json|yaml>]
|
|
24
|
-
agent-runtime run <manifest.json|manifest.yaml> [--variables <overrides.json>] [--max-total-tokens <count>] [--config <config.yaml>] [--run-id <id>] [--store <path>] [--store-driver <file|sqlite>] [--events <file|none>] [--artifacts <directory|none>] [--runtime-module <local-js-file>] [--stream] [--format <json|pretty|ndjson>] [--show-reasoning]
|
|
25
|
-
agent-runtime run-manifest <run.json|run.yaml> [--config <config.yaml>] [--store <path>] [--store-driver <file|sqlite>] [--events <file|none>] [--artifacts <directory|none>] [--runtime-module <local-js-file>] [--stream] [--format <json|pretty|ndjson>] [--show-reasoning]
|
|
21
|
+
agent-runtime run <manifest.json|manifest.yaml> [--variables <overrides.json>] [--messages <messages.json|messages.yaml>] [--messages-scope <scope>] [--messages-out <file>] [--max-total-tokens <count>] [--config <config.yaml>] [--run-id <id>] [--store <path>] [--store-driver <file|sqlite>] [--events <file|none>] [--artifacts <directory|none>] [--runtime-module <local-js-file>] [--stream] [--format <json|pretty|ndjson>] [--show-reasoning]
|
|
22
|
+
agent-runtime run-manifest <run.json|run.yaml> [--messages-scope <scope>] [--messages-out <file>] [--config <config.yaml>] [--store <path>] [--store-driver <file|sqlite>] [--events <file|none>] [--artifacts <directory|none>] [--runtime-module <local-js-file>] [--stream] [--format <json|pretty|ndjson>] [--show-reasoning]
|
|
26
23
|
agent-runtime resume <run-id> [--max-total-tokens <count>] [--config <config.yaml>] [--store <path>] [--store-driver <file|sqlite>] [--events <file|none>] [--artifacts <directory|none>] [--runtime-module <local-js-file>] [--stream] [--format <json|pretty|ndjson>] [--show-reasoning]
|
|
27
24
|
agent-runtime inspect <run-id> [--store <path>] [--store-driver <file|sqlite>] [--runtime-module <local-js-file>]
|
|
28
25
|
agent-runtime events <events.jsonl> [--run <run-id>] [--type <event-type>] [--tail <count>]
|
|
@@ -30,6 +27,9 @@ Usage:
|
|
|
30
27
|
agent-runtime examples show <variables|conditions|loops>
|
|
31
28
|
agent-runtime examples run <variables|conditions|loops> [run options]
|
|
32
29
|
agent-runtime worker [--store <path>] [--store-driver <file|sqlite>] [--config <config.yaml>] [--runtime-module <local-js-file>]
|
|
30
|
+
agent-runtime serve [<manifest>] [--server-config <server.yaml>] [--no-server-config] [--served-model-name <name>] [--config <runtime.yaml>] [--runtime-module <local-js-file>] [--host <host>] [--port <port>] [--api-key-env <VAR>] [--allow-unauthenticated] [--input <variable>=<source>]... [--output <final|step:id|variable:name>] [--stream-mode <auto|live|committed>] [--progress <none|status>] [--store-driver <memory|sqlite>] [--store <path>] [--ledger <memory|sqlite:path>] [--on-unrecognized <unsigned|reject|restart>] [--client-tools <ignore|reject>] [--max-concurrent-runs <count>] [--request-timeout <ms>] [--warmup] [--check]
|
|
31
|
+
|
|
32
|
+
Options accept --name value or --name=value.
|
|
33
33
|
`;
|
|
34
34
|
const packageDirectory = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
35
35
|
const bundledExamplesDirectory = path.join(packageDirectory, "examples");
|
|
@@ -81,33 +81,55 @@ const resolveCliStore = async (parsed) => {
|
|
|
81
81
|
},
|
|
82
82
|
};
|
|
83
83
|
};
|
|
84
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Parse `--name value` and `--name=value` options. Flags take no value;
|
|
86
|
+
* repeatable options may appear more than once.
|
|
87
|
+
*/
|
|
88
|
+
const parseOptions = (args, allowed, flags = new Set(), repeatable = new Set()) => {
|
|
85
89
|
const positional = [];
|
|
86
90
|
const options = new Map();
|
|
91
|
+
const repeated = new Map();
|
|
87
92
|
for (let index = 0; index < args.length; index += 1) {
|
|
88
93
|
const value = args[index];
|
|
89
94
|
if (!value.startsWith("--")) {
|
|
90
95
|
positional.push(value);
|
|
91
96
|
continue;
|
|
92
97
|
}
|
|
93
|
-
const
|
|
98
|
+
const separator = value.indexOf("=");
|
|
99
|
+
const name = value.slice(2, separator < 0 ? undefined : separator);
|
|
100
|
+
const option = `--${name}`;
|
|
94
101
|
if (!allowed.has(name))
|
|
95
|
-
throw new Error(`Unknown option: ${
|
|
102
|
+
throw new Error(`Unknown option: ${option}`);
|
|
96
103
|
if (flags.has(name)) {
|
|
104
|
+
if (separator >= 0)
|
|
105
|
+
throw new Error(`Option ${option} does not take a value.`);
|
|
97
106
|
if (options.has(name))
|
|
98
|
-
throw new Error(`Option ${
|
|
107
|
+
throw new Error(`Option ${option} may only be provided once.`);
|
|
99
108
|
options.set(name, "true");
|
|
100
109
|
continue;
|
|
101
110
|
}
|
|
102
|
-
|
|
103
|
-
if (
|
|
104
|
-
|
|
111
|
+
let optionValue;
|
|
112
|
+
if (separator >= 0) {
|
|
113
|
+
optionValue = value.slice(separator + 1);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
optionValue = args[index + 1];
|
|
117
|
+
if (optionValue?.startsWith("--"))
|
|
118
|
+
optionValue = undefined;
|
|
119
|
+
index += 1;
|
|
120
|
+
}
|
|
121
|
+
if (!optionValue)
|
|
122
|
+
throw new Error(`Option ${option} requires a value.`);
|
|
123
|
+
if (repeatable.has(name)) {
|
|
124
|
+
repeated.set(name, [...(repeated.get(name) ?? []), optionValue]);
|
|
125
|
+
options.set(name, optionValue);
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
105
128
|
if (options.has(name))
|
|
106
|
-
throw new Error(`Option ${
|
|
129
|
+
throw new Error(`Option ${option} may only be provided once.`);
|
|
107
130
|
options.set(name, optionValue);
|
|
108
|
-
index += 1;
|
|
109
131
|
}
|
|
110
|
-
return { positional, options };
|
|
132
|
+
return { positional, options, repeated };
|
|
111
133
|
};
|
|
112
134
|
const requireOnePositional = (parsed, label) => {
|
|
113
135
|
if (parsed.positional.length !== 1)
|
|
@@ -210,7 +232,7 @@ const inspectConnections = async (args, io) => {
|
|
|
210
232
|
throw new Error(`Unknown connection "${name}".`);
|
|
211
233
|
}
|
|
212
234
|
const runtimeModulePath = parsed.options.get("runtime-module");
|
|
213
|
-
const moduleRuntime = await
|
|
235
|
+
const moduleRuntime = await loadHostRuntime(runtimeModulePath, {
|
|
214
236
|
manifest: {
|
|
215
237
|
schemaVersion: "1.0",
|
|
216
238
|
connections: names.map((ref) => ({ ref })),
|
|
@@ -260,7 +282,7 @@ const inspect = async (args, io) => {
|
|
|
260
282
|
const runId = requireOnePositional(parsed, "run id");
|
|
261
283
|
const resolved = await resolveCliStore(parsed);
|
|
262
284
|
try {
|
|
263
|
-
const store = (await
|
|
285
|
+
const store = (await loadHostRunStore(parsed.options.get("runtime-module"), {
|
|
264
286
|
runId,
|
|
265
287
|
storeDirectory: resolved.baseDirectory,
|
|
266
288
|
storeDriver: resolved.driver,
|
|
@@ -304,241 +326,6 @@ const events = async (args, io) => {
|
|
|
304
326
|
for (const event of selected)
|
|
305
327
|
io.stdout(`${JSON.stringify(event)}\n`);
|
|
306
328
|
};
|
|
307
|
-
const adapterMethod = (value, name) => value != null &&
|
|
308
|
-
typeof value === "object" &&
|
|
309
|
-
typeof value[name] === "function";
|
|
310
|
-
const validateRuntime = (runtime) => {
|
|
311
|
-
if (runtime.shutdown !== undefined && typeof runtime.shutdown !== "function")
|
|
312
|
-
throw new Error("Runtime shutdown must be a function.");
|
|
313
|
-
if (runtime.runStore &&
|
|
314
|
-
(!adapterMethod(runtime.runStore, "createRun") ||
|
|
315
|
-
!adapterMethod(runtime.runStore, "loadRun") ||
|
|
316
|
-
!adapterMethod(runtime.runStore, "saveCheckpoint"))) {
|
|
317
|
-
throw new Error("Runtime runStore must implement the RunStore lifecycle methods.");
|
|
318
|
-
}
|
|
319
|
-
if (runtime.artifactStore &&
|
|
320
|
-
(!adapterMethod(runtime.artifactStore, "put") ||
|
|
321
|
-
!adapterMethod(runtime.artifactStore, "get"))) {
|
|
322
|
-
throw new Error("Runtime artifactStore must implement ArtifactStore.put() and get().");
|
|
323
|
-
}
|
|
324
|
-
if (runtime.model && !adapterMethod(runtime.model, "generate"))
|
|
325
|
-
throw new Error("Runtime model must implement ModelAdapter.generate().");
|
|
326
|
-
if (runtime.tools &&
|
|
327
|
-
(!adapterMethod(runtime.tools, "listTools") ||
|
|
328
|
-
!adapterMethod(runtime.tools, "executeTool"))) {
|
|
329
|
-
throw new Error("Runtime tools must implement ToolAdapter.listTools() and executeTool().");
|
|
330
|
-
}
|
|
331
|
-
if (runtime.connectionCredentials &&
|
|
332
|
-
!adapterMethod(runtime.connectionCredentials, "getCredential")) {
|
|
333
|
-
throw new Error("Runtime connectionCredentials must implement ConnectionCredentialProvider.getCredential().");
|
|
334
|
-
}
|
|
335
|
-
if (runtime.approvals && !adapterMethod(runtime.approvals, "requestApproval"))
|
|
336
|
-
throw new Error("Runtime approvals must implement ApprovalAdapter.requestApproval().");
|
|
337
|
-
if (runtime.sandbox && !adapterMethod(runtime.sandbox, "execute"))
|
|
338
|
-
throw new Error("Runtime sandbox must implement SandboxAdapter.execute().");
|
|
339
|
-
if (runtime.subRuns && !adapterMethod(runtime.subRuns, "execute"))
|
|
340
|
-
throw new Error("Runtime subRuns must implement SubRunAdapter.execute().");
|
|
341
|
-
if (runtime.summarizer && !adapterMethod(runtime.summarizer, "summarize"))
|
|
342
|
-
throw new Error("Runtime summarizer must implement ContextSummarizerAdapter.summarize().");
|
|
343
|
-
if (runtime.workspaces &&
|
|
344
|
-
!adapterMethod(runtime.workspaces, "resolveWorkspace")) {
|
|
345
|
-
throw new Error("Runtime workspaces must implement WorkspaceProvider.resolveWorkspace().");
|
|
346
|
-
}
|
|
347
|
-
if (runtime.runSandbox &&
|
|
348
|
-
(!adapterMethod(runtime.runSandbox, "open") ||
|
|
349
|
-
!adapterMethod(runtime.runSandbox, "validate") ||
|
|
350
|
-
!adapterMethod(runtime.runSandbox, "tools"))) {
|
|
351
|
-
throw new Error("Runtime runSandbox must implement RunSandboxProvider.tools(), validate(), and open().");
|
|
352
|
-
}
|
|
353
|
-
if (runtime.sandboxProvider &&
|
|
354
|
-
(!adapterMethod(runtime.sandboxProvider, "create") ||
|
|
355
|
-
!adapterMethod(runtime.sandboxProvider, "execute") ||
|
|
356
|
-
!adapterMethod(runtime.sandboxProvider, "terminate"))) {
|
|
357
|
-
throw new Error("Runtime sandboxProvider must implement the SandboxProvider lifecycle methods.");
|
|
358
|
-
}
|
|
359
|
-
if (runtime.eventSinks &&
|
|
360
|
-
(!Array.isArray(runtime.eventSinks) ||
|
|
361
|
-
runtime.eventSinks.some((sink) => !adapterMethod(sink, "emit")))) {
|
|
362
|
-
throw new Error("Runtime eventSinks must be an array of EventSink values.");
|
|
363
|
-
}
|
|
364
|
-
if (runtime.stepExecutors &&
|
|
365
|
-
(!Array.isArray(runtime.stepExecutors) ||
|
|
366
|
-
runtime.stepExecutors.some((executor) => !executor ||
|
|
367
|
-
typeof executor !== "object" ||
|
|
368
|
-
typeof executor.type !== "string" ||
|
|
369
|
-
!adapterMethod(executor, "execute")))) {
|
|
370
|
-
throw new Error("Runtime stepExecutors must implement StepExecutor.");
|
|
371
|
-
}
|
|
372
|
-
return runtime;
|
|
373
|
-
};
|
|
374
|
-
const normalizeRuntime = (runtime) => ({
|
|
375
|
-
...(runtime.shutdown ? { shutdown: runtime.shutdown } : {}),
|
|
376
|
-
...((runtime.runStore ?? runtime.store)
|
|
377
|
-
? { runStore: runtime.runStore ?? runtime.store }
|
|
378
|
-
: {}),
|
|
379
|
-
...((runtime.artifactStore ?? runtime.artifacts)
|
|
380
|
-
? { artifactStore: runtime.artifactStore ?? runtime.artifacts }
|
|
381
|
-
: {}),
|
|
382
|
-
...((runtime.model ?? runtime.modelAdapter)
|
|
383
|
-
? { model: runtime.model ?? runtime.modelAdapter }
|
|
384
|
-
: {}),
|
|
385
|
-
...((runtime.tools ?? runtime.toolAdapter)
|
|
386
|
-
? { tools: runtime.tools ?? runtime.toolAdapter }
|
|
387
|
-
: {}),
|
|
388
|
-
...((runtime.connectionCredentials ?? runtime.credentialProvider)
|
|
389
|
-
? {
|
|
390
|
-
connectionCredentials: runtime.connectionCredentials ?? runtime.credentialProvider,
|
|
391
|
-
}
|
|
392
|
-
: {}),
|
|
393
|
-
...((runtime.approvals ?? runtime.approvalAdapter)
|
|
394
|
-
? { approvals: runtime.approvals ?? runtime.approvalAdapter }
|
|
395
|
-
: {}),
|
|
396
|
-
...((runtime.sandbox ?? runtime.sandboxAdapter)
|
|
397
|
-
? { sandbox: runtime.sandbox ?? runtime.sandboxAdapter }
|
|
398
|
-
: {}),
|
|
399
|
-
...((runtime.subRuns ?? runtime.subRunAdapter)
|
|
400
|
-
? { subRuns: runtime.subRuns ?? runtime.subRunAdapter }
|
|
401
|
-
: {}),
|
|
402
|
-
...((runtime.workspaces ?? runtime.workspaceProvider)
|
|
403
|
-
? { workspaces: runtime.workspaces ?? runtime.workspaceProvider }
|
|
404
|
-
: {}),
|
|
405
|
-
...((runtime.runSandbox ?? runtime.runSandboxProvider)
|
|
406
|
-
? { runSandbox: runtime.runSandbox ?? runtime.runSandboxProvider }
|
|
407
|
-
: {}),
|
|
408
|
-
...(runtime.sandboxProvider
|
|
409
|
-
? { sandboxProvider: runtime.sandboxProvider }
|
|
410
|
-
: {}),
|
|
411
|
-
...(runtime.policies
|
|
412
|
-
? { policies: executionPoliciesSchema.parse(runtime.policies) }
|
|
413
|
-
: {}),
|
|
414
|
-
...(runtime.enforcedPolicies
|
|
415
|
-
? {
|
|
416
|
-
enforcedPolicies: executionPoliciesSchema.parse(runtime.enforcedPolicies),
|
|
417
|
-
}
|
|
418
|
-
: {}),
|
|
419
|
-
...(runtime.summarizer ? { summarizer: runtime.summarizer } : {}),
|
|
420
|
-
...((runtime.eventSinks?.length ?? 0) > 0 || runtime.eventSink
|
|
421
|
-
? {
|
|
422
|
-
eventSinks: [
|
|
423
|
-
...(runtime.eventSinks ?? []),
|
|
424
|
-
...(runtime.eventSink ? [runtime.eventSink] : []),
|
|
425
|
-
],
|
|
426
|
-
}
|
|
427
|
-
: {}),
|
|
428
|
-
...((runtime.stepExecutors?.length ?? 0) > 0 ||
|
|
429
|
-
(runtime.executors?.length ?? 0) > 0
|
|
430
|
-
? { stepExecutors: runtime.stepExecutors ?? runtime.executors }
|
|
431
|
-
: {}),
|
|
432
|
-
});
|
|
433
|
-
const defaultStepExecutors = (allowUnsafeWebhooks) => [
|
|
434
|
-
new PromptStepExecutor(),
|
|
435
|
-
new LoopStepExecutor(),
|
|
436
|
-
...(allowUnsafeWebhooks
|
|
437
|
-
? [new WebhookStepExecutor({ allowUnsafeDestinations: true })]
|
|
438
|
-
: []),
|
|
439
|
-
new ApprovalStepExecutor(),
|
|
440
|
-
new CodeStepExecutor(),
|
|
441
|
-
new SubRunStepExecutor(),
|
|
442
|
-
];
|
|
443
|
-
const resolveStepExecutors = (runtime, options = {}) => {
|
|
444
|
-
const byType = new Map(defaultStepExecutors(options.allowUnsafeWebhooks === true).map((executor) => [executor.type, executor]));
|
|
445
|
-
for (const executor of runtime.stepExecutors ?? [])
|
|
446
|
-
byType.set(executor.type, executor);
|
|
447
|
-
return [...byType.values()];
|
|
448
|
-
};
|
|
449
|
-
const loadRuntime = async (modulePath, context) => {
|
|
450
|
-
if (!modulePath)
|
|
451
|
-
return {};
|
|
452
|
-
const absolutePath = path.resolve(modulePath);
|
|
453
|
-
let imported;
|
|
454
|
-
try {
|
|
455
|
-
imported = (await import(pathToFileURL(absolutePath).href));
|
|
456
|
-
}
|
|
457
|
-
catch (error) {
|
|
458
|
-
throw new Error(`Could not load runtime module ${absolutePath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
459
|
-
}
|
|
460
|
-
const staticRuntime = imported.default ?? imported.runtime ?? imported;
|
|
461
|
-
const composedRuntime = imported.createRuntime
|
|
462
|
-
? await imported.createRuntime(context)
|
|
463
|
-
: normalizeRuntime(staticRuntime);
|
|
464
|
-
if (!composedRuntime || typeof composedRuntime !== "object") {
|
|
465
|
-
throw new Error(`Runtime module ${absolutePath} did not export a runtime object.`);
|
|
466
|
-
}
|
|
467
|
-
const runtime = !composedRuntime.runStore && imported.createRunStore
|
|
468
|
-
? { ...composedRuntime, runStore: await imported.createRunStore(context) }
|
|
469
|
-
: composedRuntime;
|
|
470
|
-
return validateRuntime(runtime);
|
|
471
|
-
};
|
|
472
|
-
const loadRuntimeStore = async (modulePath, context) => {
|
|
473
|
-
if (!modulePath)
|
|
474
|
-
return undefined;
|
|
475
|
-
const absolutePath = path.resolve(modulePath);
|
|
476
|
-
let imported;
|
|
477
|
-
try {
|
|
478
|
-
imported = (await import(pathToFileURL(absolutePath).href));
|
|
479
|
-
}
|
|
480
|
-
catch (error) {
|
|
481
|
-
throw new Error(`Could not load runtime module ${absolutePath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
482
|
-
}
|
|
483
|
-
const staticRuntime = imported.default ?? imported.runtime ?? imported;
|
|
484
|
-
const store = imported.createRunStore
|
|
485
|
-
? await imported.createRunStore(context)
|
|
486
|
-
: (staticRuntime.runStore ?? staticRuntime.store);
|
|
487
|
-
if (store &&
|
|
488
|
-
(!adapterMethod(store, "createRun") ||
|
|
489
|
-
!adapterMethod(store, "loadRun") ||
|
|
490
|
-
!adapterMethod(store, "saveCheckpoint"))) {
|
|
491
|
-
throw new Error("Runtime runStore must implement the RunStore lifecycle methods.");
|
|
492
|
-
}
|
|
493
|
-
return store;
|
|
494
|
-
};
|
|
495
|
-
const defaultConfigNames = [
|
|
496
|
-
"agent-runtime.config.yaml",
|
|
497
|
-
"agent-runtime.config.yml",
|
|
498
|
-
"agent-runtime.config.json",
|
|
499
|
-
];
|
|
500
|
-
const resolveConfig = async (requested, searchDirectory = process.cwd()) => {
|
|
501
|
-
if (requested)
|
|
502
|
-
return loadAgentRuntimeConfig(requested);
|
|
503
|
-
for (const candidate of defaultConfigNames) {
|
|
504
|
-
const absolute = path.resolve(searchDirectory, candidate);
|
|
505
|
-
try {
|
|
506
|
-
await access(absolute);
|
|
507
|
-
return await loadAgentRuntimeConfig(absolute);
|
|
508
|
-
}
|
|
509
|
-
catch (error) {
|
|
510
|
-
if (error.code !== "ENOENT")
|
|
511
|
-
throw error;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
return emptyAgentRuntimeConfig();
|
|
515
|
-
};
|
|
516
|
-
/** Host-supplied workspace and sandbox adapters take precedence over configuration. */
|
|
517
|
-
const workspaceCompositionOptions = (...runtimes) => {
|
|
518
|
-
const options = {};
|
|
519
|
-
for (const runtime of runtimes) {
|
|
520
|
-
if (runtime.workspaces && !options.provider)
|
|
521
|
-
options.provider = runtime.workspaces;
|
|
522
|
-
if (runtime.runSandbox && !options.runSandbox)
|
|
523
|
-
options.runSandbox = runtime.runSandbox;
|
|
524
|
-
if (runtime.sandboxProvider && !options.sandboxProvider)
|
|
525
|
-
options.sandboxProvider = runtime.sandboxProvider;
|
|
526
|
-
}
|
|
527
|
-
return options;
|
|
528
|
-
};
|
|
529
|
-
const mergeRuntimes = (configured, moduleRuntime) => validateRuntime({
|
|
530
|
-
...configured,
|
|
531
|
-
...moduleRuntime,
|
|
532
|
-
...((configured.eventSinks?.length ?? 0) > 0 ||
|
|
533
|
-
(moduleRuntime.eventSinks?.length ?? 0) > 0
|
|
534
|
-
? {
|
|
535
|
-
eventSinks: [
|
|
536
|
-
...(configured.eventSinks ?? []),
|
|
537
|
-
...(moduleRuntime.eventSinks ?? []),
|
|
538
|
-
],
|
|
539
|
-
}
|
|
540
|
-
: {}),
|
|
541
|
-
});
|
|
542
329
|
const sensitiveKey = /(?:authorization|cookie|credential|password|secret|token|api[-_]?key)/iu;
|
|
543
330
|
const redactValue = (value, key = "") => {
|
|
544
331
|
if (sensitiveKey.test(key))
|
|
@@ -671,9 +458,37 @@ class CliStreamingEventSink {
|
|
|
671
458
|
this.#io.stderr(`${label}\n`);
|
|
672
459
|
}
|
|
673
460
|
}
|
|
461
|
+
/**
|
|
462
|
+
* Read `--messages`: a JSON or YAML array of messages, or `{ messages,
|
|
463
|
+
* signature }` as written by `--messages-out`.
|
|
464
|
+
*/
|
|
465
|
+
const readMessagesFile = async (file) => {
|
|
466
|
+
const source = await readFile(file, "utf8");
|
|
467
|
+
let value;
|
|
468
|
+
try {
|
|
469
|
+
value = file.endsWith(".json")
|
|
470
|
+
? JSON.parse(source)
|
|
471
|
+
: parseYamlDocument(source);
|
|
472
|
+
}
|
|
473
|
+
catch (error) {
|
|
474
|
+
throw new Error(`Could not parse conversation messages ${file}: ${error instanceof Error ? error.message : String(error)}`);
|
|
475
|
+
}
|
|
476
|
+
const envelope = value != null && typeof value === "object" && !Array.isArray(value)
|
|
477
|
+
? value
|
|
478
|
+
: { messages: value };
|
|
479
|
+
return {
|
|
480
|
+
messages: parseConversationMessages(envelope.messages),
|
|
481
|
+
...(envelope.signature != null
|
|
482
|
+
? { signature: messagesSignatureSchema.parse(envelope.signature) }
|
|
483
|
+
: {}),
|
|
484
|
+
};
|
|
485
|
+
};
|
|
674
486
|
const executionOptions = new Set([
|
|
675
487
|
"config",
|
|
676
488
|
"variables",
|
|
489
|
+
"messages",
|
|
490
|
+
"messages-scope",
|
|
491
|
+
"messages-out",
|
|
677
492
|
"run-id",
|
|
678
493
|
"store",
|
|
679
494
|
"store-driver",
|
|
@@ -699,6 +514,15 @@ const execute = async (command, args, io, signal) => {
|
|
|
699
514
|
if (command === "resume" && parsed.options.has("variables")) {
|
|
700
515
|
throw new Error("--variables is only valid with the run command.");
|
|
701
516
|
}
|
|
517
|
+
if (command === "resume" &&
|
|
518
|
+
(parsed.options.has("messages") ||
|
|
519
|
+
parsed.options.has("messages-scope") ||
|
|
520
|
+
parsed.options.has("messages-out"))) {
|
|
521
|
+
throw new Error("Conversation messages are fixed when a run is created; --messages, --messages-scope, and --messages-out are not valid with resume.");
|
|
522
|
+
}
|
|
523
|
+
if (command === "run-manifest" && parsed.options.has("messages")) {
|
|
524
|
+
throw new Error("--messages cannot be combined with an agent run manifest; declare messages in the agent run manifest.");
|
|
525
|
+
}
|
|
702
526
|
if (command === "run-manifest" &&
|
|
703
527
|
(parsed.options.has("variables") ||
|
|
704
528
|
parsed.options.has("run-id") ||
|
|
@@ -725,7 +549,7 @@ const execute = async (command, args, io, signal) => {
|
|
|
725
549
|
const maxTotalTokens = positiveSafeIntegerOption(parsed, "max-total-tokens");
|
|
726
550
|
const runtimeModulePath = parsed.options.get("runtime-module");
|
|
727
551
|
const runtimeStore = command === "resume"
|
|
728
|
-
? await
|
|
552
|
+
? await loadHostRunStore(runtimeModulePath, {
|
|
729
553
|
runId: target,
|
|
730
554
|
storeDirectory,
|
|
731
555
|
storeDriver: resolvedStore.driver,
|
|
@@ -737,6 +561,10 @@ const execute = async (command, args, io, signal) => {
|
|
|
737
561
|
const variableOverrides = command === "run" && parsed.options.has("variables")
|
|
738
562
|
? parseAgentVariableOverrides(JSON.parse(await readFile(path.resolve(parsed.options.get("variables")), "utf8")))
|
|
739
563
|
: undefined;
|
|
564
|
+
const suppliedMessages = command === "run" && parsed.options.has("messages")
|
|
565
|
+
? await readMessagesFile(path.resolve(parsed.options.get("messages")))
|
|
566
|
+
: undefined;
|
|
567
|
+
const messagesScope = parsed.options.get("messages-scope");
|
|
740
568
|
let configSearchDirectory = process.cwd();
|
|
741
569
|
if (command === "run") {
|
|
742
570
|
const manifestFile = path.resolve(target);
|
|
@@ -772,21 +600,13 @@ const execute = async (command, args, io, signal) => {
|
|
|
772
600
|
...(eventFile ? { eventFile } : {}),
|
|
773
601
|
...(artifactDirectory ? { artifactDirectory } : {}),
|
|
774
602
|
};
|
|
775
|
-
const loadedModuleRuntime = await
|
|
603
|
+
const loadedModuleRuntime = await loadHostRuntime(runtimeModulePath, context);
|
|
776
604
|
shutdown = loadedModuleRuntime.shutdown;
|
|
777
605
|
const moduleRuntime = runtimeStore
|
|
778
|
-
?
|
|
606
|
+
? validateHostRuntime({ ...loadedModuleRuntime, runStore: runtimeStore })
|
|
779
607
|
: loadedModuleRuntime;
|
|
780
|
-
const config = await
|
|
781
|
-
const
|
|
782
|
-
model: !moduleRuntime.model,
|
|
783
|
-
tools: !moduleRuntime.tools,
|
|
784
|
-
...(moduleRuntime.connectionCredentials
|
|
785
|
-
? { connectionCredentials: moduleRuntime.connectionCredentials }
|
|
786
|
-
: {}),
|
|
787
|
-
workspaceOptions: workspaceCompositionOptions(moduleRuntime),
|
|
788
|
-
});
|
|
789
|
-
const runtime = mergeRuntimes(configuredRuntime, moduleRuntime);
|
|
608
|
+
const config = await resolveAgentRuntimeConfig(parsed.options.get("config"), configSearchDirectory);
|
|
609
|
+
const runtime = composeHostRuntime(manifest, config, [moduleRuntime]);
|
|
790
610
|
const jsonlSink = eventFile ? new JsonlEventSink(eventFile) : undefined;
|
|
791
611
|
const requestedFormat = parsed.options.get("format") ??
|
|
792
612
|
(parsed.options.has("stream") ? "pretty" : "json");
|
|
@@ -798,7 +618,9 @@ const execute = async (command, args, io, signal) => {
|
|
|
798
618
|
? undefined
|
|
799
619
|
: new CliStreamingEventSink(io, outputFormat, parsed.options.has("show-reasoning"));
|
|
800
620
|
const warnedSinks = new Set();
|
|
801
|
-
const runner = new AgentRuntime({
|
|
621
|
+
const runner = new AgentRuntime(hostRuntimeDependencies(runtime, {
|
|
622
|
+
// The operator runs manifests they chose on their own machine.
|
|
623
|
+
trust: "local-operator",
|
|
802
624
|
onEventSinkError(_error, _event, sink) {
|
|
803
625
|
if (warnedSinks.has(sink))
|
|
804
626
|
return;
|
|
@@ -806,48 +628,52 @@ const execute = async (command, args, io, signal) => {
|
|
|
806
628
|
io.stderr(`Warning: event delivery failed for ${sink instanceof SafeLocalEventSink ? `local log ${eventFile}` : sink.constructor.name}. Check permissions and available disk space. Execution continues.\n`);
|
|
807
629
|
},
|
|
808
630
|
runStore: runtime.runStore ?? store,
|
|
809
|
-
|
|
810
|
-
stepExecutors: resolveStepExecutors(runtime, {
|
|
811
|
-
allowUnsafeWebhooks: true,
|
|
812
|
-
}),
|
|
813
|
-
conditionEvaluator: new JexlConditionEvaluator(),
|
|
631
|
+
agentManifestSource,
|
|
814
632
|
eventSinks: [
|
|
815
633
|
...(jsonlSink ? [new SafeLocalEventSink(jsonlSink)] : []),
|
|
816
634
|
...(streamingSink ? [streamingSink] : []),
|
|
817
|
-
...(runtime.eventSinks ?? []),
|
|
818
635
|
],
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
...(runtime.workspaces ? { workspaces: runtime.workspaces } : {}),
|
|
825
|
-
...(runtime.runSandbox ? { runSandbox: runtime.runSandbox } : {}),
|
|
826
|
-
...(runtime.policies ? { policies: runtime.policies } : {}),
|
|
827
|
-
...(runtime.enforcedPolicies
|
|
828
|
-
? { enforcedPolicies: runtime.enforcedPolicies }
|
|
829
|
-
: {}),
|
|
830
|
-
...(runtime.summarizer ? { summarizer: runtime.summarizer } : {}),
|
|
831
|
-
...(runtime.artifactStore
|
|
832
|
-
? { artifacts: runtime.artifactStore }
|
|
833
|
-
: artifactDirectory
|
|
834
|
-
? { artifacts: new FileArtifactStore(artifactDirectory) }
|
|
835
|
-
: {}),
|
|
836
|
-
});
|
|
636
|
+
artifacts: runtime.artifactStore ??
|
|
637
|
+
(artifactDirectory
|
|
638
|
+
? new FileArtifactStore(artifactDirectory)
|
|
639
|
+
: undefined),
|
|
640
|
+
}));
|
|
837
641
|
try {
|
|
838
642
|
const result = await runner.run(command === "run-manifest" && agentRunManifest
|
|
839
643
|
? {
|
|
840
644
|
agentRunManifest,
|
|
645
|
+
...(messagesScope != null ? { messagesScope } : {}),
|
|
841
646
|
...(signal ? { signal } : {}),
|
|
842
647
|
}
|
|
843
648
|
: {
|
|
844
649
|
manifest,
|
|
845
650
|
...(runId ? { runId } : {}),
|
|
846
651
|
...(variableOverrides ? { variables: variableOverrides } : {}),
|
|
652
|
+
...(suppliedMessages
|
|
653
|
+
? { messages: suppliedMessages.messages }
|
|
654
|
+
: {}),
|
|
655
|
+
...(suppliedMessages?.signature
|
|
656
|
+
? { messagesSignature: suppliedMessages.signature }
|
|
657
|
+
: {}),
|
|
658
|
+
...(messagesScope != null ? { messagesScope } : {}),
|
|
847
659
|
...(maxTotalTokens ? { budget: { maxTotalTokens } } : {}),
|
|
848
660
|
...(signal ? { signal } : {}),
|
|
849
661
|
...(command === "resume" ? { resume: true } : {}),
|
|
850
662
|
});
|
|
663
|
+
// The output history contains model output, so it is written only to
|
|
664
|
+
// an explicitly requested file, in the format --messages reads.
|
|
665
|
+
const messagesOut = parsed.options.get("messages-out");
|
|
666
|
+
if (messagesOut) {
|
|
667
|
+
if (!result.messages) {
|
|
668
|
+
throw new Error("--messages-out requires an agent manifest that declares messages.");
|
|
669
|
+
}
|
|
670
|
+
await writeFile(path.resolve(messagesOut), `${JSON.stringify({
|
|
671
|
+
messages: result.messages,
|
|
672
|
+
...(result.messagesSignature
|
|
673
|
+
? { signature: result.messagesSignature }
|
|
674
|
+
: {}),
|
|
675
|
+
}, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
676
|
+
}
|
|
851
677
|
// Deliberately exclude variables, transcript and model output. They may
|
|
852
678
|
// contain secrets; inspect is an explicit command for persisted details.
|
|
853
679
|
if (outputFormat === "ndjson") {
|
|
@@ -870,6 +696,12 @@ const execute = async (command, args, io, signal) => {
|
|
|
870
696
|
status: "completed",
|
|
871
697
|
stepCount: result.stepResults.length,
|
|
872
698
|
artifactCount: result.artifacts.length,
|
|
699
|
+
...(result.messages
|
|
700
|
+
? {
|
|
701
|
+
messageCount: result.messages.length,
|
|
702
|
+
messagesSigned: result.messagesSignature != null,
|
|
703
|
+
}
|
|
704
|
+
: {}),
|
|
873
705
|
}, null, 2)}\n`);
|
|
874
706
|
}
|
|
875
707
|
}
|
|
@@ -903,6 +735,9 @@ const assertSafeInlineWorkerConfiguration = (config) => {
|
|
|
903
735
|
if (Object.keys(config.workspaces ?? {}).length > 0 || config.sandbox) {
|
|
904
736
|
throw new Error("Inline worker configuration cannot define workspaces or a sandbox; use a trusted configReference.");
|
|
905
737
|
}
|
|
738
|
+
if (config.messages?.signing) {
|
|
739
|
+
throw new Error("Inline worker configuration cannot define message signing keys; use a trusted configReference.");
|
|
740
|
+
}
|
|
906
741
|
};
|
|
907
742
|
const MAXIMUM_WORKER_INPUT_BYTES = 16 * 1024 * 1024;
|
|
908
743
|
class PortableWorkerEventSink {
|
|
@@ -924,6 +759,7 @@ export const executeWorkerInvocation = async (invocation, options) => {
|
|
|
924
759
|
const invocationVariables = invocation.action === "run"
|
|
925
760
|
? request.variables
|
|
926
761
|
: undefined;
|
|
762
|
+
const invocationMessages = invocation.action === "run" ? request : undefined;
|
|
927
763
|
const manifest = request.manifest;
|
|
928
764
|
const storeLocation = path.resolve(options.storeDirectory);
|
|
929
765
|
const storeDriver = options.storeDriver ?? "file";
|
|
@@ -945,8 +781,8 @@ export const executeWorkerInvocation = async (invocation, options) => {
|
|
|
945
781
|
throw new Error("Worker request runtimeReference requires a host resolveRuntimeReference callback.");
|
|
946
782
|
})()
|
|
947
783
|
: undefined;
|
|
948
|
-
const moduleRuntime = await
|
|
949
|
-
const hostRuntime =
|
|
784
|
+
const moduleRuntime = await loadHostRuntime(runtimeReference, context);
|
|
785
|
+
const hostRuntime = validateHostRuntime(options.runtime ?? {});
|
|
950
786
|
let requestSuppliedConfiguration = false;
|
|
951
787
|
const config = options.configFile
|
|
952
788
|
? await loadAgentRuntimeConfig(options.configFile)
|
|
@@ -963,40 +799,22 @@ export const executeWorkerInvocation = async (invocation, options) => {
|
|
|
963
799
|
: (() => {
|
|
964
800
|
throw new Error("Worker request configReference requires a host resolveConfigReference callback.");
|
|
965
801
|
})()
|
|
966
|
-
: await
|
|
802
|
+
: await resolveAgentRuntimeConfig(undefined, process.cwd());
|
|
967
803
|
if (requestSuppliedConfiguration) {
|
|
968
804
|
assertSafeInlineWorkerConfiguration(config);
|
|
969
805
|
}
|
|
970
|
-
const
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
tools: !moduleRuntime.tools && !hostRuntime.tools,
|
|
977
|
-
workspaceOptions: {
|
|
978
|
-
...options.workspaceOptions,
|
|
979
|
-
...workspaceCompositionOptions(hostRuntime, moduleRuntime),
|
|
980
|
-
},
|
|
806
|
+
const runtime = composeHostRuntime(manifest, config, [moduleRuntime, hostRuntime], {
|
|
807
|
+
...(requestSuppliedConfiguration
|
|
808
|
+
? { environment: options.environment ?? {} }
|
|
809
|
+
: options.environment
|
|
810
|
+
? { environment: options.environment }
|
|
811
|
+
: {}),
|
|
981
812
|
...(options.modelPolicy ? { modelPolicy: options.modelPolicy } : {}),
|
|
982
|
-
...(options.toolOptions
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
? {
|
|
986
|
-
toolOptions: {
|
|
987
|
-
...options.toolOptions,
|
|
988
|
-
...((hostRuntime.connectionCredentials ??
|
|
989
|
-
moduleRuntime.connectionCredentials)
|
|
990
|
-
? {
|
|
991
|
-
credentialProvider: hostRuntime.connectionCredentials ??
|
|
992
|
-
moduleRuntime.connectionCredentials,
|
|
993
|
-
}
|
|
994
|
-
: {}),
|
|
995
|
-
},
|
|
996
|
-
}
|
|
813
|
+
...(options.toolOptions ? { toolOptions: options.toolOptions } : {}),
|
|
814
|
+
...(options.workspaceOptions
|
|
815
|
+
? { workspaceOptions: options.workspaceOptions }
|
|
997
816
|
: {}),
|
|
998
817
|
});
|
|
999
|
-
const runtime = mergeRuntimes(mergeRuntimes(configuredRuntime, moduleRuntime), hostRuntime);
|
|
1000
818
|
const store = runtime.runStore ??
|
|
1001
819
|
(storeDriver === "sqlite"
|
|
1002
820
|
? new (await import("@clearideas/agent-runtime-store-sqlite")).SqliteRunStore(storeLocation)
|
|
@@ -1038,40 +856,29 @@ export const executeWorkerInvocation = async (invocation, options) => {
|
|
|
1038
856
|
await store.saveCheckpoint(importedCheckpoint);
|
|
1039
857
|
}
|
|
1040
858
|
}
|
|
1041
|
-
const runner = new AgentRuntime({
|
|
859
|
+
const runner = new AgentRuntime(hostRuntimeDependencies(runtime, {
|
|
860
|
+
// Webhook execution is host-supplied in worker mode so destination
|
|
861
|
+
// policy cannot be bypassed by a remote manifest.
|
|
862
|
+
trust: "untrusted-request",
|
|
1042
863
|
runStore: store,
|
|
1043
|
-
|
|
1044
|
-
// cannot be bypassed by a remote manifest.
|
|
1045
|
-
stepExecutors: resolveStepExecutors(runtime),
|
|
1046
|
-
conditionEvaluator: new JexlConditionEvaluator(),
|
|
1047
|
-
eventSinks: [
|
|
1048
|
-
new PortableWorkerEventSink(options.onMessage),
|
|
1049
|
-
...(runtime.eventSinks ?? []),
|
|
1050
|
-
],
|
|
1051
|
-
...(runtime.model ? { model: runtime.model } : {}),
|
|
1052
|
-
...(runtime.tools ? { tools: runtime.tools } : {}),
|
|
1053
|
-
...(runtime.approvals ? { approvals: runtime.approvals } : {}),
|
|
1054
|
-
...(runtime.sandbox ? { sandbox: runtime.sandbox } : {}),
|
|
1055
|
-
...(runtime.subRuns ? { subRuns: runtime.subRuns } : {}),
|
|
1056
|
-
...(runtime.workspaces ? { workspaces: runtime.workspaces } : {}),
|
|
1057
|
-
...(runtime.runSandbox ? { runSandbox: runtime.runSandbox } : {}),
|
|
1058
|
-
...(runtime.policies ? { policies: runtime.policies } : {}),
|
|
1059
|
-
...(runtime.enforcedPolicies
|
|
1060
|
-
? { enforcedPolicies: runtime.enforcedPolicies }
|
|
1061
|
-
: {}),
|
|
1062
|
-
...(runtime.summarizer ? { summarizer: runtime.summarizer } : {}),
|
|
864
|
+
eventSinks: [new PortableWorkerEventSink(options.onMessage)],
|
|
1063
865
|
artifacts,
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
...(options.eventSinkFailurePolicy
|
|
1068
|
-
? { eventSinkFailurePolicy: options.eventSinkFailurePolicy }
|
|
1069
|
-
: {}),
|
|
1070
|
-
});
|
|
866
|
+
maxParallelSteps: options.maxParallelSteps,
|
|
867
|
+
eventSinkFailurePolicy: options.eventSinkFailurePolicy,
|
|
868
|
+
}));
|
|
1071
869
|
return await runner.run({
|
|
1072
870
|
manifest,
|
|
1073
871
|
...(request.runId ? { runId: request.runId } : {}),
|
|
1074
872
|
...(invocationVariables ? { variables: invocationVariables } : {}),
|
|
873
|
+
...(invocationMessages?.messages
|
|
874
|
+
? { messages: invocationMessages.messages }
|
|
875
|
+
: {}),
|
|
876
|
+
...(invocationMessages?.messagesSignature
|
|
877
|
+
? { messagesSignature: invocationMessages.messagesSignature }
|
|
878
|
+
: {}),
|
|
879
|
+
...(invocationMessages?.messagesScope != null
|
|
880
|
+
? { messagesScope: invocationMessages.messagesScope }
|
|
881
|
+
: {}),
|
|
1075
882
|
...(request.execution ? { execution: request.execution } : {}),
|
|
1076
883
|
...(request.budget ? { budget: request.budget } : {}),
|
|
1077
884
|
...(options.signal ? { signal: options.signal } : {}),
|
|
@@ -1150,6 +957,139 @@ const worker = async (args, io, signal) => {
|
|
|
1150
957
|
return false;
|
|
1151
958
|
}
|
|
1152
959
|
};
|
|
960
|
+
const serveOptionNames = new Set([
|
|
961
|
+
"server-config",
|
|
962
|
+
"no-server-config",
|
|
963
|
+
"served-model-name",
|
|
964
|
+
"config",
|
|
965
|
+
"runtime-config",
|
|
966
|
+
"runtime-module",
|
|
967
|
+
"host",
|
|
968
|
+
"port",
|
|
969
|
+
"api-key-env",
|
|
970
|
+
"allow-unauthenticated",
|
|
971
|
+
"input",
|
|
972
|
+
"output",
|
|
973
|
+
"stream-mode",
|
|
974
|
+
"progress",
|
|
975
|
+
"store-driver",
|
|
976
|
+
"store",
|
|
977
|
+
"ledger",
|
|
978
|
+
"on-unrecognized",
|
|
979
|
+
"client-tools",
|
|
980
|
+
"max-concurrent-runs",
|
|
981
|
+
"request-timeout",
|
|
982
|
+
"warmup",
|
|
983
|
+
"check",
|
|
984
|
+
]);
|
|
985
|
+
const serveFlags = new Set([
|
|
986
|
+
"no-server-config",
|
|
987
|
+
"allow-unauthenticated",
|
|
988
|
+
"warmup",
|
|
989
|
+
"check",
|
|
990
|
+
]);
|
|
991
|
+
const INPUT_SOURCES = new Set([
|
|
992
|
+
"last-user",
|
|
993
|
+
"transcript",
|
|
994
|
+
"system",
|
|
995
|
+
"json",
|
|
996
|
+
"client",
|
|
997
|
+
]);
|
|
998
|
+
const oneOf = (parsed, name, values) => {
|
|
999
|
+
const value = parsed.options.get(name);
|
|
1000
|
+
if (value === undefined)
|
|
1001
|
+
return undefined;
|
|
1002
|
+
if (!values.includes(value))
|
|
1003
|
+
throw new Error(`--${name} must be one of ${values.join(", ")}.`);
|
|
1004
|
+
return value;
|
|
1005
|
+
};
|
|
1006
|
+
/** Parse `agent-runtime serve` arguments into server options. */
|
|
1007
|
+
export const parseServeArguments = (args) => {
|
|
1008
|
+
const parsed = parseOptions(args, serveOptionNames, serveFlags, new Set(["input"]));
|
|
1009
|
+
if (parsed.positional.length > 1)
|
|
1010
|
+
throw new Error("Serve one manifest, or use --server-config for several.");
|
|
1011
|
+
if (parsed.options.has("config") && parsed.options.has("runtime-config"))
|
|
1012
|
+
throw new Error("--runtime-config is an alias of --config; use one.");
|
|
1013
|
+
const manifest = parsed.positional[0];
|
|
1014
|
+
const input = {};
|
|
1015
|
+
for (const entry of parsed.repeated.get("input") ?? []) {
|
|
1016
|
+
const separator = entry.indexOf("=");
|
|
1017
|
+
const variable = entry.slice(0, separator);
|
|
1018
|
+
const source = entry.slice(separator + 1);
|
|
1019
|
+
if (separator <= 0 || !INPUT_SOURCES.has(source)) {
|
|
1020
|
+
throw new Error(`--input expects <variable>=<source> with source last-user, transcript, system, json, or client; got ${JSON.stringify(entry)}.`);
|
|
1021
|
+
}
|
|
1022
|
+
if (input[variable])
|
|
1023
|
+
throw new Error(`--input maps ${variable} twice.`);
|
|
1024
|
+
input[variable] = source;
|
|
1025
|
+
}
|
|
1026
|
+
const port = parsed.options.get("port");
|
|
1027
|
+
const portNumber = port === undefined ? undefined : Number(port);
|
|
1028
|
+
if (portNumber !== undefined &&
|
|
1029
|
+
(!Number.isInteger(portNumber) || portNumber < 0 || portNumber > 65_535))
|
|
1030
|
+
throw new Error("--port must be an integer from 0 to 65535.");
|
|
1031
|
+
const runtimeConfig = parsed.options.get("config") ?? parsed.options.get("runtime-config");
|
|
1032
|
+
const streamMode = oneOf(parsed, "stream-mode", [
|
|
1033
|
+
"auto",
|
|
1034
|
+
"live",
|
|
1035
|
+
"committed",
|
|
1036
|
+
]);
|
|
1037
|
+
const progress = oneOf(parsed, "progress", ["none", "status"]);
|
|
1038
|
+
const storeDriver = oneOf(parsed, "store-driver", [
|
|
1039
|
+
"memory",
|
|
1040
|
+
"sqlite",
|
|
1041
|
+
]);
|
|
1042
|
+
const onUnrecognized = oneOf(parsed, "on-unrecognized", [
|
|
1043
|
+
"unsigned",
|
|
1044
|
+
"reject",
|
|
1045
|
+
"restart",
|
|
1046
|
+
]);
|
|
1047
|
+
const clientTools = oneOf(parsed, "client-tools", [
|
|
1048
|
+
"ignore",
|
|
1049
|
+
"reject",
|
|
1050
|
+
]);
|
|
1051
|
+
const maxConcurrentRuns = positiveSafeIntegerOption(parsed, "max-concurrent-runs");
|
|
1052
|
+
const requestTimeoutMs = positiveSafeIntegerOption(parsed, "request-timeout");
|
|
1053
|
+
if (storeDriver === "sqlite" && !parsed.options.has("store"))
|
|
1054
|
+
throw new Error("--store-driver sqlite requires --store <path>.");
|
|
1055
|
+
const value = (name) => parsed.options.get(name);
|
|
1056
|
+
return {
|
|
1057
|
+
...(manifest ? { manifest } : {}),
|
|
1058
|
+
...(value("server-config")
|
|
1059
|
+
? { serverConfig: value("server-config") }
|
|
1060
|
+
: {}),
|
|
1061
|
+
...(parsed.options.has("no-server-config") ? { noServerConfig: true } : {}),
|
|
1062
|
+
...(value("served-model-name")
|
|
1063
|
+
? { servedModelName: value("served-model-name") }
|
|
1064
|
+
: {}),
|
|
1065
|
+
...(runtimeConfig ? { runtimeConfig } : {}),
|
|
1066
|
+
...(value("runtime-module")
|
|
1067
|
+
? { runtimeModule: value("runtime-module") }
|
|
1068
|
+
: {}),
|
|
1069
|
+
...(value("host") ? { host: value("host") } : {}),
|
|
1070
|
+
...(portNumber !== undefined ? { port: portNumber } : {}),
|
|
1071
|
+
...(value("api-key-env") ? { apiKeyEnv: value("api-key-env") } : {}),
|
|
1072
|
+
...(parsed.options.has("allow-unauthenticated")
|
|
1073
|
+
? { allowUnauthenticated: true }
|
|
1074
|
+
: {}),
|
|
1075
|
+
...(Object.keys(input).length > 0 ? { input } : {}),
|
|
1076
|
+
...(value("output") ? { output: value("output") } : {}),
|
|
1077
|
+
...(streamMode ? { streamMode } : {}),
|
|
1078
|
+
...(progress ? { progress } : {}),
|
|
1079
|
+
...(storeDriver ? { storeDriver } : {}),
|
|
1080
|
+
...(value("store") ? { store: value("store") } : {}),
|
|
1081
|
+
...(value("ledger") ? { ledger: value("ledger") } : {}),
|
|
1082
|
+
...(onUnrecognized ? { onUnrecognized } : {}),
|
|
1083
|
+
...(clientTools ? { clientTools } : {}),
|
|
1084
|
+
...(maxConcurrentRuns ? { maxConcurrentRuns } : {}),
|
|
1085
|
+
...(requestTimeoutMs ? { requestTimeoutMs } : {}),
|
|
1086
|
+
...(parsed.options.has("warmup") ? { warmup: true } : {}),
|
|
1087
|
+
...(parsed.options.has("check") ? { check: true } : {}),
|
|
1088
|
+
};
|
|
1089
|
+
};
|
|
1090
|
+
const serve = async (args, io, signal) => {
|
|
1091
|
+
await runServe(parseServeArguments(args), io, signal);
|
|
1092
|
+
};
|
|
1153
1093
|
const examples = async (args, io, signal) => {
|
|
1154
1094
|
const [subcommand, name, ...remaining] = args;
|
|
1155
1095
|
if (subcommand === "list") {
|
|
@@ -1204,6 +1144,8 @@ export const runCli = async (args, io = defaultIo, options = {}) => {
|
|
|
1204
1144
|
}
|
|
1205
1145
|
else if (command === "worker")
|
|
1206
1146
|
return (await worker(commandArgs, io, options.signal)) ? 0 : 1;
|
|
1147
|
+
else if (command === "serve")
|
|
1148
|
+
await serve(commandArgs, io, options.signal);
|
|
1207
1149
|
else {
|
|
1208
1150
|
io.stderr(`Unknown command: ${command}\n\n${usage}`);
|
|
1209
1151
|
return 2;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clearideas/agent-runtime-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Standalone CLI for validating, running, resuming, and inspecting declarative agents.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Clear Ideas Incorporated",
|
|
@@ -40,17 +40,13 @@
|
|
|
40
40
|
"postpack": "node ../../scripts/cleanup-package-license.mjs"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@clearideas/agent-runtime-
|
|
44
|
-
"@clearideas/agent-runtime-
|
|
45
|
-
"@clearideas/agent-runtime-
|
|
46
|
-
"@clearideas/agent-runtime-
|
|
47
|
-
"@clearideas/agent-runtime-
|
|
48
|
-
"@clearideas/agent-runtime-
|
|
49
|
-
"@clearideas/agent-runtime-
|
|
50
|
-
"@clearideas/agent-runtime-step-prompt": "0.7.1",
|
|
51
|
-
"@clearideas/agent-runtime-step-standard": "0.7.1",
|
|
52
|
-
"@clearideas/agent-runtime-store-local": "0.7.1",
|
|
53
|
-
"@clearideas/agent-runtime-store-sqlite": "0.7.1",
|
|
43
|
+
"@clearideas/agent-runtime-config": "0.9.0",
|
|
44
|
+
"@clearideas/agent-runtime-contracts": "0.9.0",
|
|
45
|
+
"@clearideas/agent-runtime-core": "0.9.0",
|
|
46
|
+
"@clearideas/agent-runtime-execution": "0.9.0",
|
|
47
|
+
"@clearideas/agent-runtime-server": "0.9.0",
|
|
48
|
+
"@clearideas/agent-runtime-store-local": "0.9.0",
|
|
49
|
+
"@clearideas/agent-runtime-store-sqlite": "0.9.0",
|
|
54
50
|
"yaml": "^2.9.1"
|
|
55
51
|
},
|
|
56
52
|
"devDependencies": {
|
|
@@ -59,7 +55,7 @@
|
|
|
59
55
|
"vitest": "^5.1.0"
|
|
60
56
|
},
|
|
61
57
|
"engines": {
|
|
62
|
-
"node": ">=
|
|
58
|
+
"node": ">=22.20.0"
|
|
63
59
|
},
|
|
64
60
|
"homepage": "https://github.com/clearideas/agent-runtime#readme",
|
|
65
61
|
"bugs": {
|