@gobing-ai/ts-ai-runner 0.4.12 → 0.4.14
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 +1 -1
- package/dist/ai-runner.d.ts +11 -1
- package/dist/ai-runner.d.ts.map +1 -1
- package/dist/ai-runner.js +8 -1
- package/dist/events.d.ts +3 -0
- package/dist/events.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/ai-runner.ts +20 -1
- package/src/events.ts +8 -1
package/README.md
CHANGED
|
@@ -179,7 +179,7 @@ Key design decisions:
|
|
|
179
179
|
|
|
180
180
|
- **Shims are pure**: `AgentShim` produces `{ command, args }` without touching the filesystem or launching processes. All side effects live in `AiRunner` and `TeamAgentProcess`.
|
|
181
181
|
- **ProcessExecutor is injectable**: tests inject a stub executor; production uses `NodeProcessExecutor` (or the Bun pipe-process seam for team mode).
|
|
182
|
-
- **Events are opt-in**: `AiRunnerOptions.events` and `TeamOrchestratorOptions.events` accept an `EventBus<AgentEvents>` for structured observability. Without
|
|
182
|
+
- **Events are opt-in**: `AiRunnerOptions.events` and `TeamOrchestratorOptions.events` accept an `EventBus<AgentEvents>` for structured observability. Per-run `AgentRunOptions.onOutput` forwards incremental stdout/stderr without losing the buffered result, and `correlation` carries application-owned `runId`, `executionId`, and optional `actionId` unchanged on invocation start/exit events. Without observers, the runner is silent.
|
|
183
183
|
- **Team mode is composable**: `AgentSpec`, `TeamAgentProcess`, and `TeamOrchestrator` are small building blocks. `TeamOrchestrator` depends on the ai-runner-owned `MessageStore` port; `InboxMessageDao` from `@gobing-ai/ts-db/inbox` is one structural provider — no adapter class — and in-memory test doubles implement the port directly. Downstream apps compose them into their own orchestration layer.
|
|
184
184
|
|
|
185
185
|
The package depends on `@gobing-ai/ts-runtime` for process execution and `@gobing-ai/ts-infra` for structured logging and EventBus. `@gobing-ai/ts-db` is a development dependency only: production source under `packages/ai-runner/src` has no direct `@gobing-ai/ts-db` imports for message access, and only the DB-backed integration test resolves the concrete `InboxMessageDao`. The target agent CLIs are not bundled; install them separately in the host environment.
|
package/dist/ai-runner.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type BusLifecycleEvents, EventBus, type Logger } from '@gobing-ai/ts-infra';
|
|
2
|
-
import { type ProcessExecutor, type TracerPort } from '@gobing-ai/ts-runtime';
|
|
2
|
+
import { type ProcessExecutor, type ProcessOutputChunk, type TracerPort } from '@gobing-ai/ts-runtime';
|
|
3
3
|
import { type AgentName, type PromptOptions, type ShimCommand } from './agents/shims';
|
|
4
4
|
import type { AgentEvents, AiRunnerProcessEvents } from './events';
|
|
5
5
|
/** Result returned by every AI runner dispatch method. */
|
|
@@ -23,6 +23,16 @@ export interface AgentRunOptions {
|
|
|
23
23
|
timeout?: number;
|
|
24
24
|
/** AbortSignal forwarded to ProcessExecutor — aborts the agent subprocess when fired. */
|
|
25
25
|
signal?: AbortSignal;
|
|
26
|
+
/** Incremental output observer; the final buffered result is still returned. */
|
|
27
|
+
onOutput?: (output: ProcessOutputChunk) => void;
|
|
28
|
+
/** Optional application-owned correlation propagated unchanged to agent lifecycle events. */
|
|
29
|
+
correlation?: AgentRunCorrelation;
|
|
30
|
+
}
|
|
31
|
+
/** Application-owned execution identity carried without coupling the runner to a workflow model. */
|
|
32
|
+
export interface AgentRunCorrelation {
|
|
33
|
+
readonly runId: string;
|
|
34
|
+
readonly executionId: string;
|
|
35
|
+
readonly actionId?: string;
|
|
26
36
|
}
|
|
27
37
|
/** Constructor options for AiRunner. */
|
|
28
38
|
export interface AiRunnerOptions {
|
package/dist/ai-runner.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-runner.d.ts","sourceRoot":"","sources":["../src/ai-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,EAAE,QAAQ,EAAa,KAAK,MAAM,EAAc,MAAM,qBAAqB,CAAC;AAC5G,OAAO,EAGH,KAAK,eAAe,
|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O,CAAC,cAAc,CAAC;IAI1B,6EAA6E;IAC7E,eAAe,CACX,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,aAAa,EAC5B,OAAO,GAAE,eAAoB,GAC9B,OAAO,CAAC,cAAc,CAAC;IAI1B,0DAA0D;IAC1D,kBAAkB,CAAC,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,GAAE,eAAoB,GAAG,WAAW;IAM9G,4EAA4E;IAC5E,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI;YAKjF,MAAM;CAkDvB;AAWD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC7B,KAAK,EAAE,SAAS,EAChB,aAAa,EAAE,aAAa,EAC5B,OAAO,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GAC/B,WAAW,CAEb"}
|
package/dist/ai-runner.js
CHANGED
|
@@ -71,7 +71,12 @@ export class AiRunner {
|
|
|
71
71
|
async invoke(agent, operation, command, options, forceBuffered) {
|
|
72
72
|
const label = `ai-runner.${agent}.${operation}`;
|
|
73
73
|
this.logger.debug('invoke', { label, command: command.command, args: command.args.join(' ') });
|
|
74
|
-
void this.events?.emit('agent.invoke.start', {
|
|
74
|
+
void this.events?.emit('agent.invoke.start', {
|
|
75
|
+
agent,
|
|
76
|
+
operation,
|
|
77
|
+
label,
|
|
78
|
+
...(options.correlation !== undefined ? { correlation: options.correlation } : {}),
|
|
79
|
+
});
|
|
75
80
|
const result = await this.processExecutor.run({
|
|
76
81
|
command: command.command,
|
|
77
82
|
args: command.args,
|
|
@@ -81,6 +86,7 @@ export class AiRunner {
|
|
|
81
86
|
cwd: options.cwd ?? this.defaultCwd,
|
|
82
87
|
timeout: options.timeout ?? this.defaultTimeout,
|
|
83
88
|
...(options.signal !== undefined ? { signal: options.signal } : {}),
|
|
89
|
+
...(options.onOutput !== undefined ? { onOutput: options.onOutput } : {}),
|
|
84
90
|
});
|
|
85
91
|
if (result.exitCode !== 0) {
|
|
86
92
|
this.logger.error('invoke exited non-zero', {
|
|
@@ -96,6 +102,7 @@ export class AiRunner {
|
|
|
96
102
|
exitCode: result.exitCode,
|
|
97
103
|
...(result.signal !== undefined ? { signal: result.signal } : {}),
|
|
98
104
|
durationMs: result.durationMs,
|
|
105
|
+
...(options.correlation !== undefined ? { correlation: options.correlation } : {}),
|
|
99
106
|
});
|
|
100
107
|
return {
|
|
101
108
|
exitCode: result.exitCode,
|
package/dist/events.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ProcessEvents } from '@gobing-ai/ts-runtime';
|
|
2
|
+
import type { AgentRunCorrelation } from './ai-runner';
|
|
2
3
|
/** Typed event map for agent-runner observability. All events prefixed `agent.`. */
|
|
3
4
|
export type AgentEvents = {
|
|
4
5
|
/** Emitted immediately before an agent CLI invocation starts. */
|
|
@@ -6,6 +7,7 @@ export type AgentEvents = {
|
|
|
6
7
|
agent: string;
|
|
7
8
|
operation: string;
|
|
8
9
|
label: string;
|
|
10
|
+
correlation?: AgentRunCorrelation;
|
|
9
11
|
}) => void;
|
|
10
12
|
/** Emitted after an agent CLI invocation exits. */
|
|
11
13
|
'agent.invoke.exit': (data: {
|
|
@@ -15,6 +17,7 @@ export type AgentEvents = {
|
|
|
15
17
|
exitCode: number | null;
|
|
16
18
|
signal?: string;
|
|
17
19
|
durationMs: number;
|
|
20
|
+
correlation?: AgentRunCorrelation;
|
|
18
21
|
}) => void;
|
|
19
22
|
/** Emitted when a long-running team agent process starts. */
|
|
20
23
|
'agent.started': (data: {
|
package/dist/events.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file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MAAM,qBAAqB,GAAG,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gobing-ai/ts-ai-runner",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.14",
|
|
4
4
|
"description": "@gobing-ai/ts-ai-runner — Coding-agent shims, detection, doctor checks, and prompt execution.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -47,12 +47,12 @@
|
|
|
47
47
|
"release": "echo 'Manual publish is disabled. Releases go through GitHub Actions via Trusted Publishing — push a tag: git tag @gobing-ai/ts-ai-runner-v<version> && git push --tags' && exit 1"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@gobing-ai/ts-infra": "^0.4.
|
|
51
|
-
"@gobing-ai/ts-runtime": "^0.4.
|
|
50
|
+
"@gobing-ai/ts-infra": "^0.4.14",
|
|
51
|
+
"@gobing-ai/ts-runtime": "^0.4.14"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@types/bun": "1.3.14",
|
|
55
|
-
"@gobing-ai/ts-db": "^0.4.
|
|
55
|
+
"@gobing-ai/ts-db": "^0.4.14"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|
package/src/ai-runner.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
getProcessCwd,
|
|
4
4
|
nodeBunFactory,
|
|
5
5
|
type ProcessExecutor,
|
|
6
|
+
type ProcessOutputChunk,
|
|
6
7
|
type ProcessResult,
|
|
7
8
|
type TracerPort,
|
|
8
9
|
} from '@gobing-ai/ts-runtime';
|
|
@@ -33,6 +34,17 @@ export interface AgentRunOptions {
|
|
|
33
34
|
timeout?: number;
|
|
34
35
|
/** AbortSignal forwarded to ProcessExecutor — aborts the agent subprocess when fired. */
|
|
35
36
|
signal?: AbortSignal;
|
|
37
|
+
/** Incremental output observer; the final buffered result is still returned. */
|
|
38
|
+
onOutput?: (output: ProcessOutputChunk) => void;
|
|
39
|
+
/** Optional application-owned correlation propagated unchanged to agent lifecycle events. */
|
|
40
|
+
correlation?: AgentRunCorrelation;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Application-owned execution identity carried without coupling the runner to a workflow model. */
|
|
44
|
+
export interface AgentRunCorrelation {
|
|
45
|
+
readonly runId: string;
|
|
46
|
+
readonly executionId: string;
|
|
47
|
+
readonly actionId?: string;
|
|
36
48
|
}
|
|
37
49
|
|
|
38
50
|
/** Constructor options for AiRunner. */
|
|
@@ -152,7 +164,12 @@ export class AiRunner {
|
|
|
152
164
|
): Promise<AgentRunResult> {
|
|
153
165
|
const label = `ai-runner.${agent}.${operation}`;
|
|
154
166
|
this.logger.debug('invoke', { label, command: command.command, args: command.args.join(' ') });
|
|
155
|
-
void this.events?.emit('agent.invoke.start', {
|
|
167
|
+
void this.events?.emit('agent.invoke.start', {
|
|
168
|
+
agent,
|
|
169
|
+
operation,
|
|
170
|
+
label,
|
|
171
|
+
...(options.correlation !== undefined ? { correlation: options.correlation } : {}),
|
|
172
|
+
});
|
|
156
173
|
const result: ProcessResult = await this.processExecutor.run({
|
|
157
174
|
command: command.command,
|
|
158
175
|
args: command.args,
|
|
@@ -162,6 +179,7 @@ export class AiRunner {
|
|
|
162
179
|
cwd: options.cwd ?? this.defaultCwd,
|
|
163
180
|
timeout: options.timeout ?? this.defaultTimeout,
|
|
164
181
|
...(options.signal !== undefined ? { signal: options.signal } : {}),
|
|
182
|
+
...(options.onOutput !== undefined ? { onOutput: options.onOutput } : {}),
|
|
165
183
|
});
|
|
166
184
|
if (result.exitCode !== 0) {
|
|
167
185
|
this.logger.error('invoke exited non-zero', {
|
|
@@ -177,6 +195,7 @@ export class AiRunner {
|
|
|
177
195
|
exitCode: result.exitCode,
|
|
178
196
|
...(result.signal !== undefined ? { signal: result.signal } : {}),
|
|
179
197
|
durationMs: result.durationMs,
|
|
198
|
+
...(options.correlation !== undefined ? { correlation: options.correlation } : {}),
|
|
180
199
|
});
|
|
181
200
|
return {
|
|
182
201
|
exitCode: result.exitCode,
|
package/src/events.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import type { ProcessEvents } from '@gobing-ai/ts-runtime';
|
|
2
|
+
import type { AgentRunCorrelation } from './ai-runner';
|
|
2
3
|
|
|
3
4
|
/** Typed event map for agent-runner observability. All events prefixed `agent.`. */
|
|
4
5
|
export type AgentEvents = {
|
|
5
6
|
/** Emitted immediately before an agent CLI invocation starts. */
|
|
6
|
-
'agent.invoke.start': (data: {
|
|
7
|
+
'agent.invoke.start': (data: {
|
|
8
|
+
agent: string;
|
|
9
|
+
operation: string;
|
|
10
|
+
label: string;
|
|
11
|
+
correlation?: AgentRunCorrelation;
|
|
12
|
+
}) => void;
|
|
7
13
|
/** Emitted after an agent CLI invocation exits. */
|
|
8
14
|
'agent.invoke.exit': (data: {
|
|
9
15
|
agent: string;
|
|
@@ -12,6 +18,7 @@ export type AgentEvents = {
|
|
|
12
18
|
exitCode: number | null;
|
|
13
19
|
signal?: string;
|
|
14
20
|
durationMs: number;
|
|
21
|
+
correlation?: AgentRunCorrelation;
|
|
15
22
|
}) => void;
|
|
16
23
|
/** Emitted when a long-running team agent process starts. */
|
|
17
24
|
'agent.started': (data: { agentId: string; agentType: string; pid: number | null }) => void;
|