@mono-agent/agent-runtime 0.19.1 → 0.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/MIGRATION.md +1 -1
  2. package/README.md +101 -4
  3. package/package.json +1 -1
  4. package/src/agent/sandbox-seam.js +16 -2
  5. package/src/agent/tools/bash.js +26 -4
  6. package/src/agent/tools/edit.js +72 -5
  7. package/src/agent/tools/exec.js +22 -4
  8. package/src/agent/tools/glob.js +65 -9
  9. package/src/agent/tools/grep.js +66 -11
  10. package/src/agent/tools/node-repl.js +5 -2
  11. package/src/agent/tools/pi-bridge.js +263 -48
  12. package/src/agent/tools/read.js +50 -10
  13. package/src/agent/tools/shared/path-resolver.js +67 -2
  14. package/src/agent/tools/shared/process-jobs.js +188 -0
  15. package/src/agent/tools/shared/process-runner.js +541 -30
  16. package/src/agent/tools/shared/protected-filesystem.js +150 -0
  17. package/src/agent/tools/web-search.js +63 -8
  18. package/src/agent/tools/write.js +52 -6
  19. package/src/ai/providers/acp.js +4 -0
  20. package/src/ai/providers/claude-cli.js +35 -2
  21. package/src/ai/providers/claude-sdk.js +12 -0
  22. package/src/ai/providers/codex-app.js +15 -2
  23. package/src/ai/providers/pi-native/stream-subscriber.js +29 -2
  24. package/src/ai/providers/pi-native/turn-runner.js +3 -0
  25. package/src/ai/providers/pi-native.js +7 -1
  26. package/src/ai/runtime/capabilities.js +2 -0
  27. package/src/ai/runtime/router.js +78 -6
  28. package/src/ai/streaming/codex-events.js +15 -0
  29. package/src/ai/streaming/opencode-events.js +5 -0
  30. package/src/ai/tool-lifecycle.js +347 -0
  31. package/src/ai/types.js +58 -0
  32. package/src/runtime.js +35 -21
  33. package/types/agent/sandbox-seam.d.ts +19 -6
  34. package/types/agent/tools/bash.d.ts +11 -26
  35. package/types/agent/tools/edit.d.ts +3 -2
  36. package/types/agent/tools/exec.d.ts +13 -26
  37. package/types/agent/tools/glob.d.ts +3 -2
  38. package/types/agent/tools/grep.d.ts +3 -2
  39. package/types/agent/tools/pi-bridge.d.ts +11 -4
  40. package/types/agent/tools/read.d.ts +3 -2
  41. package/types/agent/tools/shared/path-resolver.d.ts +8 -0
  42. package/types/agent/tools/shared/process-jobs.d.ts +64 -0
  43. package/types/agent/tools/shared/process-runner.d.ts +45 -3
  44. package/types/agent/tools/shared/protected-filesystem.d.ts +51 -0
  45. package/types/agent/tools/write.d.ts +3 -2
  46. package/types/ai/providers/pi-native/stream-subscriber.d.ts +2 -0
  47. package/types/ai/runtime/capabilities.d.ts +3 -0
  48. package/types/ai/streaming/codex-events.d.ts +1 -0
  49. package/types/ai/streaming/opencode-events.d.ts +1 -0
  50. package/types/ai/tool-lifecycle.d.ts +43 -0
  51. package/types/ai/types.d.ts +118 -0
@@ -17,6 +17,7 @@ export function toolResultEvent(part: any): {
17
17
  tool_use_id: any;
18
18
  content: any;
19
19
  is_error: boolean;
20
+ tool_lifecycle: any;
20
21
  }[];
21
22
  };
22
23
  };
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @param {{sink?: (event: any) => Promise<any>, onObserve?: (event: any) => void, onEvent?: (event: any) => void, abortSignal?: AbortSignal}} options
3
+ */
4
+ export function createToolLifecycleEventGate({ sink, onObserve, onEvent, abortSignal }: {
5
+ sink?: (event: any) => Promise<any>;
6
+ onObserve?: (event: any) => void;
7
+ onEvent?: (event: any) => void;
8
+ abortSignal?: AbortSignal;
9
+ }): {
10
+ emit: (event: any) => void;
11
+ flush(): Promise<void>;
12
+ };
13
+ /**
14
+ * Pi-native exact classifier. It consumes structured tool result details, not
15
+ * error text, so timeout/signal/non-zero/cancellation fidelity cannot drift
16
+ * with provider wording.
17
+ * @param {{result?: any,isError?: boolean,aborted?: boolean,approval?: any}} input
18
+ */
19
+ export function classifyPiToolResult(input: {
20
+ result?: any;
21
+ isError?: boolean;
22
+ aborted?: boolean;
23
+ approval?: any;
24
+ }): {
25
+ detailCode?: string;
26
+ failureKind?: string;
27
+ state: string;
28
+ };
29
+ /** @param {any} persisted @param {string|undefined} terminalStateValue */
30
+ export function historyMetadata(persisted: any, terminalStateValue: string | undefined): {
31
+ untrusted: boolean;
32
+ errorCode?: any;
33
+ artifactReferences?: any;
34
+ retainedBytes?: number;
35
+ originalBytes?: number;
36
+ truncated?: any;
37
+ terminalState?: string;
38
+ persistence: string;
39
+ sequence?: number;
40
+ recordId?: any;
41
+ };
42
+ /** Mark a provider adapter's host-derived structured outcome as trusted input to the gate. @param {any} value */
43
+ export function toolLifecycleMetadata(value: any): any;
@@ -34,6 +34,7 @@
34
34
  * @property {RuntimeModelRef} [model]
35
35
  * @property {string} [effort]
36
36
  * @property {Object<string, Object>} [mcpServers]
37
+ * @property {Object} [mcpApps] App-owned exact-connection MCP Apps registry (Pi-native only).
37
38
  */
38
39
  /**
39
40
  * @typedef {Object} RuntimeNativeSubagentsOptions
@@ -90,6 +91,49 @@
90
91
  * shape above; every other event kind (tool_approval_pending,
91
92
  * provider_failover_started, context_compaction, ...) adds its own fields.
92
93
  */
94
+ /** @typedef {"success"|"rejected"|"error"|"exit_nonzero"|"timeout"|"signal"|"cancelled"|"interrupted"} RuntimeToolLifecycleTerminalState */
95
+ /**
96
+ * @typedef {Readonly<{
97
+ * phase: "invocation",
98
+ * toolCallId: string,
99
+ * toolName: string,
100
+ * arguments?: unknown,
101
+ * }>} RuntimeToolLifecycleInvocationEvent
102
+ * Provider-neutral invocation half sent to the host-owned lifecycle sink.
103
+ */
104
+ /**
105
+ * @typedef {Readonly<{
106
+ * phase: "result",
107
+ * toolCallId: string,
108
+ * toolName?: string,
109
+ * content?: unknown,
110
+ * state: RuntimeToolLifecycleTerminalState,
111
+ * failureKind?: string,
112
+ * detailCode?: string,
113
+ * executionMs?: number,
114
+ * artifacts?: ReadonlyArray<Readonly<{path: string, available?: boolean}>>,
115
+ * }>} RuntimeToolLifecycleResultEvent
116
+ * Provider-neutral terminal half sent to the host-owned lifecycle sink.
117
+ */
118
+ /** @typedef {RuntimeToolLifecycleInvocationEvent | RuntimeToolLifecycleResultEvent} RuntimeToolLifecycleEvent */
119
+ /**
120
+ * @typedef {Readonly<{
121
+ * recordId?: string,
122
+ * sequence?: number,
123
+ * persistence: "persisted"|"failed",
124
+ * truncated?: boolean,
125
+ * originalBytes?: number,
126
+ * retainedBytes?: number,
127
+ * artifactReferences?: ReadonlyArray<Readonly<{id: string, available: boolean}>>,
128
+ * errorCode?: string,
129
+ * }>} RuntimeToolLifecyclePersistence
130
+ * Bounded metadata returned after one lifecycle half becomes durable.
131
+ */
132
+ /**
133
+ * @callback RuntimeToolLifecycleSink
134
+ * @param {RuntimeToolLifecycleEvent} event
135
+ * @returns {Promise<RuntimeToolLifecyclePersistence|undefined>}
136
+ */
93
137
  /** @typedef {"uniform"|"per-route-native"} RuntimeRouteSafetyMode */
94
138
  /**
95
139
  * @typedef {"mono-agent-monotonic"|"disabled"|"mono-agent-srt"|"mono-agent-srt-unsafe-host-fallback"|"provider-native"|"codex-native"|"unsupported"} RuntimeRouteSandboxContract
@@ -178,6 +222,7 @@
178
222
  * @property {AsyncIterable<{body: string, id?: string, receivedAt?: string, acknowledge?: () => void, reject?: (error?: unknown) => void}>} [liveInput] Stream of in-flight user messages for steering an active run. Providers acknowledge only after accepting a message into the active turn.
179
223
  * @property {ReadonlyArray<*>} [observers] Per-call observers (see RuntimeObserver) merged with host-level (createRuntime) observers.
180
224
  * @property {(event: RuntimeEvent) => void} [onEvent]
225
+ * @property {RuntimeToolLifecycleSink} [toolLifecycleSink] Awaited host-owned incremental lifecycle persistence boundary.
181
226
  * @property {ReadonlyArray<Object>} [messages]
182
227
  * @property {string} [effort]
183
228
  * @property {boolean} [fastMode]
@@ -218,10 +263,17 @@
218
263
  * @property {boolean} [codexLoadProjectDocs] Codex app-server only. Omitted/false starts the managed app-server with
219
264
  * `project_doc_max_bytes=0`, preventing automatic repository-instruction discovery. True restores Codex's native
220
265
  * project-doc loading defaults. An explicit `codexAppServerArgs` array wins over this convenience option.
266
+ * @property {boolean} [codexSandboxNetworkAccess] Codex app-server only, code-only. Strict `true` enables native
267
+ * network access for plan/read-only and default/acceptEdits/workspace-write turns; omitted or any other runtime
268
+ * value denies it. No-tool probes always deny network access, and bypass/danger-full-access remains unchanged. This
269
+ * is unrelated to `RuntimeRunOptions.sandboxPolicy`, which controls mono-agent's own sandbox and is not consumed by
270
+ * Codex's provider-owned tool loop. Default/acceptEdits workspace-write plus network true grants repository read and
271
+ * network egress in the same turn; prefer plan when only read-only browsing is needed.
221
272
  * @property {RuntimeNativeSubagentsOptions} [nativeSubagents] Caller-defined Claude native `Task` profiles. Direct
222
273
  * Codex owns its collaboration agents and rejects configured teammate definitions; `codexLoadProjectDocs` controls
223
274
  * whether Codex loads repository instructions for its own agents.
224
275
  * @property {RuntimeSubagentsOptions} [subagents] In-process `Agent` built-in: profiles, caps, and the nested-run callback.
276
+ * @property {import('../agent/tools/shared/process-jobs.js').ProcessJobsController} [processJobs] Pi-native-only structural process-job controller. When absent, Exec/Bash schemas and foreground behavior are unchanged.
225
277
  * @property {Object} [diagnosticsSeed] Set by createRouterRuntime (ai/runtime/router.js) with a `resume_snapshot` when
226
278
  * failing over mid-chain; a host-level coordinator may relay it forward (see agent/transcript.js), not read by any
227
279
  * bridge in this package today.
@@ -490,6 +542,10 @@ export type RuntimeNativeSubagentDefinition = {
490
542
  mcpServers?: {
491
543
  [x: string]: any;
492
544
  };
545
+ /**
546
+ * App-owned exact-connection MCP Apps registry (Pi-native only).
547
+ */
548
+ mcpApps?: any;
493
549
  };
494
550
  /**
495
551
  * Caller-defined native profiles are supported only by the Claude bridges.
@@ -582,6 +638,51 @@ export type RuntimeEvent = RuntimeSubagentActivityEvent | {
582
638
  type: string;
583
639
  [key: string]: any;
584
640
  };
641
+ export type RuntimeToolLifecycleTerminalState = "success" | "rejected" | "error" | "exit_nonzero" | "timeout" | "signal" | "cancelled" | "interrupted";
642
+ /**
643
+ * Provider-neutral invocation half sent to the host-owned lifecycle sink.
644
+ */
645
+ export type RuntimeToolLifecycleInvocationEvent = Readonly<{
646
+ phase: "invocation";
647
+ toolCallId: string;
648
+ toolName: string;
649
+ arguments?: unknown;
650
+ }>;
651
+ /**
652
+ * Provider-neutral terminal half sent to the host-owned lifecycle sink.
653
+ */
654
+ export type RuntimeToolLifecycleResultEvent = Readonly<{
655
+ phase: "result";
656
+ toolCallId: string;
657
+ toolName?: string;
658
+ content?: unknown;
659
+ state: RuntimeToolLifecycleTerminalState;
660
+ failureKind?: string;
661
+ detailCode?: string;
662
+ executionMs?: number;
663
+ artifacts?: ReadonlyArray<Readonly<{
664
+ path: string;
665
+ available?: boolean;
666
+ }>>;
667
+ }>;
668
+ export type RuntimeToolLifecycleEvent = RuntimeToolLifecycleInvocationEvent | RuntimeToolLifecycleResultEvent;
669
+ /**
670
+ * Bounded metadata returned after one lifecycle half becomes durable.
671
+ */
672
+ export type RuntimeToolLifecyclePersistence = Readonly<{
673
+ recordId?: string;
674
+ sequence?: number;
675
+ persistence: "persisted" | "failed";
676
+ truncated?: boolean;
677
+ originalBytes?: number;
678
+ retainedBytes?: number;
679
+ artifactReferences?: ReadonlyArray<Readonly<{
680
+ id: string;
681
+ available: boolean;
682
+ }>>;
683
+ errorCode?: string;
684
+ }>;
685
+ export type RuntimeToolLifecycleSink = (event: RuntimeToolLifecycleEvent) => Promise<RuntimeToolLifecyclePersistence | undefined>;
585
686
  export type RuntimeRouteSafetyMode = "uniform" | "per-route-native";
586
687
  /**
587
688
  * Fixed telemetry vocabulary for a route's sandbox posture. The
@@ -763,6 +864,10 @@ export type RuntimeRunOptions = {
763
864
  */
764
865
  observers?: ReadonlyArray<any>;
765
866
  onEvent?: (event: RuntimeEvent) => void;
867
+ /**
868
+ * Awaited host-owned incremental lifecycle persistence boundary.
869
+ */
870
+ toolLifecycleSink?: RuntimeToolLifecycleSink;
766
871
  messages?: ReadonlyArray<any>;
767
872
  effort?: string;
768
873
  fastMode?: boolean;
@@ -875,6 +980,15 @@ export type RuntimeRunOptions = {
875
980
  * project-doc loading defaults. An explicit `codexAppServerArgs` array wins over this convenience option.
876
981
  */
877
982
  codexLoadProjectDocs?: boolean;
983
+ /**
984
+ * Codex app-server only, code-only. Strict `true` enables native
985
+ * network access for plan/read-only and default/acceptEdits/workspace-write turns; omitted or any other runtime
986
+ * value denies it. No-tool probes always deny network access, and bypass/danger-full-access remains unchanged. This
987
+ * is unrelated to `RuntimeRunOptions.sandboxPolicy`, which controls mono-agent's own sandbox and is not consumed by
988
+ * Codex's provider-owned tool loop. Default/acceptEdits workspace-write plus network true grants repository read and
989
+ * network egress in the same turn; prefer plan when only read-only browsing is needed.
990
+ */
991
+ codexSandboxNetworkAccess?: boolean;
878
992
  /**
879
993
  * Caller-defined Claude native `Task` profiles. Direct
880
994
  * Codex owns its collaboration agents and rejects configured teammate definitions; `codexLoadProjectDocs` controls
@@ -885,6 +999,10 @@ export type RuntimeRunOptions = {
885
999
  * In-process `Agent` built-in: profiles, caps, and the nested-run callback.
886
1000
  */
887
1001
  subagents?: RuntimeSubagentsOptions;
1002
+ /**
1003
+ * Pi-native-only structural process-job controller. When absent, Exec/Bash schemas and foreground behavior are unchanged.
1004
+ */
1005
+ processJobs?: import("../agent/tools/shared/process-jobs.js").ProcessJobsController;
888
1006
  /**
889
1007
  * Set by createRouterRuntime (ai/runtime/router.js) with a `resume_snapshot` when
890
1008
  * failing over mid-chain; a host-level coordinator may relay it forward (see agent/transcript.js), not read by any