@liy/agent-runner 0.1.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 +290 -0
- package/dist/bin/agent-runner.d.ts +34 -0
- package/dist/bin/agent-runner.js +16076 -0
- package/dist/bin/agent-runner.js.map +7 -0
- package/dist/config.d.ts +121 -0
- package/dist/harness-drivers/codex-jsonl.d.ts +10 -0
- package/dist/harness-drivers/pi-rpc.d.ts +20 -0
- package/dist/harness-drivers/shared.d.ts +98 -0
- package/dist/harness-drivers/types.d.ts +144 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +16135 -0
- package/dist/index.js.map +7 -0
- package/dist/runner.d.ts +76 -0
- package/dist/runtime.d.ts +134 -0
- package/package.json +62 -0
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default Sprite-local agent-runner configuration path.
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEFAULT_AGENT_RUNNER_CONFIG_PATH = "/home/sprite/.config/mote/agent-runner.json";
|
|
7
|
+
/**
|
|
8
|
+
* Harness protocol supported by the Sprite-local runner.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export type AgentRunnerHarnessDriver = "codex-jsonl" | "pi-rpc";
|
|
13
|
+
/**
|
|
14
|
+
* Reasoning budget accepted by harnesses with thinking controls.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export type AgentRunnerThinking = "off" | "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
19
|
+
/**
|
|
20
|
+
* Runtime configuration for one Sprite-local harness profile.
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export interface AgentRunnerHarnessConfig {
|
|
25
|
+
/**
|
|
26
|
+
* Harness driver id used by the runner.
|
|
27
|
+
*/
|
|
28
|
+
driver: AgentRunnerHarnessDriver;
|
|
29
|
+
/**
|
|
30
|
+
* Executable name or absolute command path available inside the Sprite.
|
|
31
|
+
*/
|
|
32
|
+
command: string;
|
|
33
|
+
/**
|
|
34
|
+
* Static arguments supplied before runner-generated prompt/spec arguments.
|
|
35
|
+
*/
|
|
36
|
+
args?: string[];
|
|
37
|
+
/**
|
|
38
|
+
* Optional provider name for harnesses that route provider and model separately.
|
|
39
|
+
*/
|
|
40
|
+
provider?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Harness-local model used when the task spec does not select one.
|
|
43
|
+
*/
|
|
44
|
+
defaultModel?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Optional reasoning budget passed to harnesses with explicit thinking controls.
|
|
47
|
+
*/
|
|
48
|
+
thinking?: AgentRunnerThinking;
|
|
49
|
+
/**
|
|
50
|
+
* Secret environment variables required by this harness profile.
|
|
51
|
+
*/
|
|
52
|
+
secretEnv?: string[];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Sprite-local runner configuration.
|
|
56
|
+
*
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
export interface AgentRunnerConfig {
|
|
60
|
+
/**
|
|
61
|
+
* Harness profile used when the task spec does not select one.
|
|
62
|
+
*/
|
|
63
|
+
defaultHarness: string;
|
|
64
|
+
/**
|
|
65
|
+
* Harness profiles keyed by host-selectable name.
|
|
66
|
+
*/
|
|
67
|
+
harnesses: Record<string, AgentRunnerHarnessConfig>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Resolved harness config after applying task-level host selection.
|
|
71
|
+
*
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
74
|
+
export interface ResolvedAgentRunnerHarnessConfig extends AgentRunnerHarnessConfig {
|
|
75
|
+
/**
|
|
76
|
+
* Selected harness profile name.
|
|
77
|
+
*/
|
|
78
|
+
name: string;
|
|
79
|
+
/**
|
|
80
|
+
* Resolved model id after task-level override and harness default fallback.
|
|
81
|
+
*/
|
|
82
|
+
model?: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Host-selected runner values accepted from task specs.
|
|
86
|
+
*
|
|
87
|
+
* @public
|
|
88
|
+
*/
|
|
89
|
+
export interface AgentRunnerSelection {
|
|
90
|
+
harness?: string;
|
|
91
|
+
model?: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Read and validate the Sprite-local runner config file.
|
|
95
|
+
*
|
|
96
|
+
* @param path - Config path; defaults to the Sprite baseline location.
|
|
97
|
+
* @returns Normalized runner config.
|
|
98
|
+
*
|
|
99
|
+
* @public
|
|
100
|
+
*/
|
|
101
|
+
export declare function readAgentRunnerConfig(path?: string): Promise<AgentRunnerConfig>;
|
|
102
|
+
/**
|
|
103
|
+
* Parse and validate runner config JSON.
|
|
104
|
+
*
|
|
105
|
+
* @param source - Raw JSON config source.
|
|
106
|
+
* @param sourceName - Human-readable source used in errors.
|
|
107
|
+
* @returns Normalized runner config.
|
|
108
|
+
*
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
111
|
+
export declare function parseAgentRunnerConfig(source: string, sourceName?: string): AgentRunnerConfig;
|
|
112
|
+
/**
|
|
113
|
+
* Resolve one task's harness using runner config defaults.
|
|
114
|
+
*
|
|
115
|
+
* @param config - Validated runner config.
|
|
116
|
+
* @param selection - Optional host-selected harness and model.
|
|
117
|
+
* @returns Resolved harness config for driver launch.
|
|
118
|
+
*
|
|
119
|
+
* @public
|
|
120
|
+
*/
|
|
121
|
+
export declare function resolveAgentRunnerHarness(config: AgentRunnerConfig, selection: AgentRunnerSelection | undefined): ResolvedAgentRunnerHarnessConfig;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { HarnessSpawn, TaskAgentHarnessDriver } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Create the Codex JSONL driver adapter.
|
|
4
|
+
*
|
|
5
|
+
* @param spawnProcess - Optional subprocess factory used by tests.
|
|
6
|
+
* @returns Harness driver preserving the existing Codex JSONL behavior.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export declare function createCodexJsonlHarnessDriver(spawnProcess?: HarnessSpawn): TaskAgentHarnessDriver;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ResolvedAgentRunnerHarnessConfig } from "../config.js";
|
|
2
|
+
import type { HarnessSpawn, TaskAgentHarnessDriver } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Create the Pi RPC driver adapter.
|
|
5
|
+
*
|
|
6
|
+
* @param spawnProcess - Optional subprocess factory used by tests.
|
|
7
|
+
* @returns Harness driver that owns Pi RPC protocol framing and lifecycle.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export declare function createPiRpcHarnessDriver(spawnProcess?: HarnessSpawn): TaskAgentHarnessDriver;
|
|
12
|
+
/**
|
|
13
|
+
* Build Pi RPC command arguments from a harness config.
|
|
14
|
+
*
|
|
15
|
+
* @param harness - Pi RPC harness configuration.
|
|
16
|
+
* @returns Complete Pi command arguments owned by the driver.
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export declare function buildPiRpcArgs(harness: ResolvedAgentRunnerHarnessConfig): string[];
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { Readable } from "node:stream";
|
|
2
|
+
import type { ControlChannel, HarnessChildProcess, HarnessProcessResult } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Text and JSON redactor for harness process output.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export interface HarnessOutputSanitizer {
|
|
9
|
+
/**
|
|
10
|
+
* Redact sensitive env names and secret values from text.
|
|
11
|
+
*
|
|
12
|
+
* @param text - Raw harness output.
|
|
13
|
+
* @returns Redacted output safe for control-channel forwarding.
|
|
14
|
+
*/
|
|
15
|
+
redactText(text: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Redact sensitive strings recursively inside a JSON-compatible value.
|
|
18
|
+
*
|
|
19
|
+
* @param value - Parsed JSON payload.
|
|
20
|
+
* @returns Redacted JSON-compatible payload.
|
|
21
|
+
*/
|
|
22
|
+
redactJson(value: unknown): unknown;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create an output sanitizer from the child-process environment.
|
|
26
|
+
*
|
|
27
|
+
* @param env - Environment passed to the harness subprocess.
|
|
28
|
+
* @param extraSensitiveNames - Explicit env names to redact even when absent.
|
|
29
|
+
* @returns Output redactor for text and parsed JSON values.
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export declare function createHarnessOutputSanitizer(env: Record<string, string>, extraSensitiveNames?: string[]): HarnessOutputSanitizer;
|
|
34
|
+
/**
|
|
35
|
+
* Byte-buffer JSONL parser that only treats LF as a record delimiter.
|
|
36
|
+
*
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
export declare class JsonlByteBufferParser {
|
|
40
|
+
private readonly decoder;
|
|
41
|
+
private buffer;
|
|
42
|
+
/**
|
|
43
|
+
* Push one stream chunk into the parser.
|
|
44
|
+
*
|
|
45
|
+
* @param chunk - Buffer or string chunk from a stream.
|
|
46
|
+
* @param onLine - Callback invoked for each full JSONL record.
|
|
47
|
+
*/
|
|
48
|
+
push(chunk: Buffer | string, onLine: (line: string) => void): void;
|
|
49
|
+
/**
|
|
50
|
+
* Flush decoder state at stream end.
|
|
51
|
+
*
|
|
52
|
+
* @param onLine - Callback invoked for a trailing unterminated record.
|
|
53
|
+
*/
|
|
54
|
+
end(onLine: (line: string) => void): void;
|
|
55
|
+
private drain;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Attach the protocol-compliant JSONL byte parser to a stream.
|
|
59
|
+
*
|
|
60
|
+
* @param stream - Subprocess output stream.
|
|
61
|
+
* @param onLine - Callback invoked for each complete line.
|
|
62
|
+
* @returns Promise resolved when the stream ends.
|
|
63
|
+
*/
|
|
64
|
+
export declare function forwardJsonlByteStream(stream: Readable, onLine: (line: string) => void): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Forward one generic harness output line as JSON progress or text log.
|
|
67
|
+
*
|
|
68
|
+
* @param channel - Connected control channel.
|
|
69
|
+
* @param line - Raw harness output line.
|
|
70
|
+
* @param streamName - Source stream name.
|
|
71
|
+
* @param sanitizer - Output sanitizer.
|
|
72
|
+
* @param driver - Optional driver id to include in forwarded payloads.
|
|
73
|
+
*/
|
|
74
|
+
export declare function forwardHarnessLine(channel: ControlChannel, line: string, streamName: "stdout" | "stderr", sanitizer: HarnessOutputSanitizer, driver?: string): void;
|
|
75
|
+
/**
|
|
76
|
+
* Wait for one child process to close.
|
|
77
|
+
*
|
|
78
|
+
* @param child - Harness subprocess.
|
|
79
|
+
* @returns Child close result.
|
|
80
|
+
*/
|
|
81
|
+
export declare function waitForChildClose(child: HarnessChildProcess): Promise<HarnessProcessResult>;
|
|
82
|
+
/**
|
|
83
|
+
* Terminate a child process with SIGTERM and delayed SIGKILL fallback.
|
|
84
|
+
*
|
|
85
|
+
* @param child - Harness subprocess.
|
|
86
|
+
* @param killAfterMs - Milliseconds before SIGKILL fallback.
|
|
87
|
+
* @returns Cleanup function that cancels the fallback timer.
|
|
88
|
+
*
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
export declare function terminateChildProcess(child: HarnessChildProcess, killAfterMs?: number): () => void;
|
|
92
|
+
/**
|
|
93
|
+
* Format a harness exit result for diagnostics.
|
|
94
|
+
*
|
|
95
|
+
* @param result - Child process result.
|
|
96
|
+
* @returns Human-readable exit description.
|
|
97
|
+
*/
|
|
98
|
+
export declare function formatHarnessExit(result: HarnessProcessResult): string;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { ExecuteTaskRpcMessage, ExecuteTaskRunnerSpec } from "@liy/mote-core";
|
|
2
|
+
import type { Readable, Writable } from "node:stream";
|
|
3
|
+
import type { ResolvedAgentRunnerHarnessConfig } from "../config.js";
|
|
4
|
+
/**
|
|
5
|
+
* Minimal Task Control Channel surface used by runner orchestration.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface ControlChannel {
|
|
10
|
+
/**
|
|
11
|
+
* Send one JSON-RPC message to the host.
|
|
12
|
+
*
|
|
13
|
+
* @param message - Control-channel message to serialize and send.
|
|
14
|
+
*/
|
|
15
|
+
send(message: ExecuteTaskRpcMessage): void;
|
|
16
|
+
/**
|
|
17
|
+
* Close the underlying channel.
|
|
18
|
+
*/
|
|
19
|
+
close(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Subscribe to host-originated control messages.
|
|
22
|
+
*
|
|
23
|
+
* @param handler - Callback invoked for each validated control message.
|
|
24
|
+
*/
|
|
25
|
+
onControlMessage(handler: (message: ExecuteTaskRpcMessage) => void): void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Result of one harness subprocess invocation.
|
|
29
|
+
*
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
export interface HarnessProcessResult {
|
|
33
|
+
/**
|
|
34
|
+
* Child process exit code when the process closed.
|
|
35
|
+
*/
|
|
36
|
+
exitCode: number | null;
|
|
37
|
+
/**
|
|
38
|
+
* Child process signal when the process closed due to a signal.
|
|
39
|
+
*/
|
|
40
|
+
signal: NodeJS.Signals | null;
|
|
41
|
+
/**
|
|
42
|
+
* Terminal condition that let the runner continue to completion validation.
|
|
43
|
+
*/
|
|
44
|
+
completedBy: "agent-end" | "process-close";
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Child process surface used by harness drivers and fake-process tests.
|
|
48
|
+
*/
|
|
49
|
+
export interface HarnessChildProcess {
|
|
50
|
+
/**
|
|
51
|
+
* Writable subprocess stdin.
|
|
52
|
+
*/
|
|
53
|
+
stdin: Writable;
|
|
54
|
+
/**
|
|
55
|
+
* Readable subprocess stdout.
|
|
56
|
+
*/
|
|
57
|
+
stdout: Readable;
|
|
58
|
+
/**
|
|
59
|
+
* Readable subprocess stderr.
|
|
60
|
+
*/
|
|
61
|
+
stderr: Readable;
|
|
62
|
+
/**
|
|
63
|
+
* Exit code once known.
|
|
64
|
+
*/
|
|
65
|
+
exitCode: number | null;
|
|
66
|
+
/**
|
|
67
|
+
* Exit signal once known.
|
|
68
|
+
*/
|
|
69
|
+
signalCode: NodeJS.Signals | null;
|
|
70
|
+
/**
|
|
71
|
+
* Send a signal to the subprocess.
|
|
72
|
+
*
|
|
73
|
+
* @param signal - Signal name to send.
|
|
74
|
+
* @returns Whether Node accepted the signal request.
|
|
75
|
+
*/
|
|
76
|
+
kill(signal?: NodeJS.Signals): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Subscribe to a child process event.
|
|
79
|
+
*
|
|
80
|
+
* @param event - Event name.
|
|
81
|
+
* @param listener - Event callback.
|
|
82
|
+
* @returns This child process.
|
|
83
|
+
*/
|
|
84
|
+
once(event: "error", listener: (error: Error) => void): this;
|
|
85
|
+
once(event: "close", listener: (exitCode: number | null, signal: NodeJS.Signals | null) => void): this;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Dependency-injected process spawn function used by driver tests.
|
|
89
|
+
*/
|
|
90
|
+
export type HarnessSpawn = (command: string, args: string[], options: {
|
|
91
|
+
cwd: string;
|
|
92
|
+
env: Record<string, string>;
|
|
93
|
+
stdio: ["pipe", "pipe", "pipe"];
|
|
94
|
+
}) => HarnessChildProcess;
|
|
95
|
+
/**
|
|
96
|
+
* Common input passed from runner orchestration into one harness driver.
|
|
97
|
+
*/
|
|
98
|
+
export interface HarnessDriverInput {
|
|
99
|
+
/**
|
|
100
|
+
* Fully validated task runner spec.
|
|
101
|
+
*/
|
|
102
|
+
spec: ExecuteTaskRunnerSpec;
|
|
103
|
+
/**
|
|
104
|
+
* Resolved Sprite-local harness config for this task.
|
|
105
|
+
*/
|
|
106
|
+
harness: ResolvedAgentRunnerHarnessConfig;
|
|
107
|
+
/**
|
|
108
|
+
* Connected task-control channel.
|
|
109
|
+
*/
|
|
110
|
+
channel: ControlChannel;
|
|
111
|
+
/**
|
|
112
|
+
* Mote task prompt written through the provider-specific harness protocol.
|
|
113
|
+
*/
|
|
114
|
+
prompt: string;
|
|
115
|
+
/**
|
|
116
|
+
* Sanitized child process environment.
|
|
117
|
+
*/
|
|
118
|
+
env: Record<string, string>;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Handle for an active harness subprocess run.
|
|
122
|
+
*/
|
|
123
|
+
export interface HarnessDriverRun {
|
|
124
|
+
/**
|
|
125
|
+
* Terminal process result promise.
|
|
126
|
+
*/
|
|
127
|
+
result: Promise<HarnessProcessResult>;
|
|
128
|
+
/**
|
|
129
|
+
* Cancel the active harness run.
|
|
130
|
+
*/
|
|
131
|
+
cancel(): void;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Driver adapter for one harness protocol.
|
|
135
|
+
*/
|
|
136
|
+
export interface TaskAgentHarnessDriver {
|
|
137
|
+
/**
|
|
138
|
+
* Start the harness subprocess.
|
|
139
|
+
*
|
|
140
|
+
* @param input - Validated runner spec, prompt, environment, and control channel.
|
|
141
|
+
* @returns Active run handle.
|
|
142
|
+
*/
|
|
143
|
+
start(input: HarnessDriverInput): HarnessDriverRun;
|
|
144
|
+
}
|
package/dist/index.d.ts
ADDED