@a5c-ai/agent-core 5.0.1-staging.ff407b73 → 5.0.1-staging.ffad3b46492e
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 +20 -7
- package/dist/agenticTools/background/state.d.ts +6 -4
- package/dist/agenticTools/background/state.d.ts.map +1 -1
- package/dist/agenticTools/background/state.js +9 -23
- package/dist/agenticTools/index.d.ts.map +1 -1
- package/dist/agenticTools/index.js +8 -1
- package/dist/agenticTools/tools/programmaticToolCalling.d.ts +4 -0
- package/dist/agenticTools/tools/programmaticToolCalling.d.ts.map +1 -0
- package/dist/agenticTools/tools/programmaticToolCalling.js +137 -0
- package/dist/backgroundProcessRegistry.d.ts +4 -60
- package/dist/backgroundProcessRegistry.d.ts.map +1 -1
- package/dist/backgroundProcessRegistry.js +7 -197
- package/dist/context/index.d.ts +5 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +12 -0
- package/dist/context/manager.d.ts +43 -0
- package/dist/context/manager.d.ts.map +1 -0
- package/dist/context/manager.js +113 -0
- package/dist/context/strategies/index.d.ts +4 -0
- package/dist/context/strategies/index.d.ts.map +1 -0
- package/dist/context/strategies/index.js +9 -0
- package/dist/context/strategies/priority.d.ts +29 -0
- package/dist/context/strategies/priority.d.ts.map +1 -0
- package/dist/context/strategies/priority.js +58 -0
- package/dist/context/strategies/sliding.d.ts +27 -0
- package/dist/context/strategies/sliding.d.ts.map +1 -0
- package/dist/context/strategies/sliding.js +62 -0
- package/dist/context/strategies/summary.d.ts +41 -0
- package/dist/context/strategies/summary.d.ts.map +1 -0
- package/dist/context/strategies/summary.js +75 -0
- package/dist/context/token-estimator.d.ts +25 -0
- package/dist/context/token-estimator.d.ts.map +1 -0
- package/dist/context/token-estimator.js +38 -0
- package/dist/context/types.d.ts +131 -0
- package/dist/context/types.d.ts.map +1 -0
- package/dist/context/types.js +9 -0
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -1
- package/dist/loop/agent-loop.d.ts +51 -0
- package/dist/loop/agent-loop.d.ts.map +1 -0
- package/dist/loop/agent-loop.js +238 -0
- package/dist/loop/index.d.ts +6 -0
- package/dist/loop/index.d.ts.map +1 -0
- package/dist/loop/index.js +11 -0
- package/dist/loop/strategies/concurrent.d.ts +33 -0
- package/dist/loop/strategies/concurrent.d.ts.map +1 -0
- package/dist/loop/strategies/concurrent.js +47 -0
- package/dist/loop/strategies/group-chat.d.ts +42 -0
- package/dist/loop/strategies/group-chat.d.ts.map +1 -0
- package/dist/loop/strategies/group-chat.js +91 -0
- package/dist/loop/strategies/handoff.d.ts +46 -0
- package/dist/loop/strategies/handoff.d.ts.map +1 -0
- package/dist/loop/strategies/handoff.js +86 -0
- package/dist/loop/strategies/index.d.ts +9 -0
- package/dist/loop/strategies/index.d.ts.map +1 -0
- package/dist/loop/strategies/index.js +11 -0
- package/dist/loop/strategies/sequential.d.ts +19 -0
- package/dist/loop/strategies/sequential.d.ts.map +1 -0
- package/dist/loop/strategies/sequential.js +29 -0
- package/dist/loop/types.d.ts +120 -0
- package/dist/loop/types.d.ts.map +1 -0
- package/dist/loop/types.js +9 -0
- package/dist/session.d.ts +2 -1
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +130 -122
- package/dist/session.test.js +92 -234
- package/dist/subagent/index.d.ts +6 -0
- package/dist/subagent/index.d.ts.map +1 -0
- package/dist/subagent/index.js +7 -0
- package/dist/subagent/invoker.d.ts +33 -0
- package/dist/subagent/invoker.d.ts.map +1 -0
- package/dist/subagent/invoker.js +112 -0
- package/dist/subagent/oversight.d.ts +43 -0
- package/dist/subagent/oversight.d.ts.map +1 -0
- package/dist/subagent/oversight.js +63 -0
- package/dist/subagent/types.d.ts +136 -0
- package/dist/subagent/types.d.ts.map +1 -0
- package/dist/subagent/types.js +9 -0
- package/dist/synthesis/index.d.ts +4 -0
- package/dist/synthesis/index.d.ts.map +1 -0
- package/dist/synthesis/index.js +9 -0
- package/dist/synthesis/strategies/index.d.ts +4 -0
- package/dist/synthesis/strategies/index.d.ts.map +1 -0
- package/dist/synthesis/strategies/index.js +9 -0
- package/dist/synthesis/strategies/merge.d.ts +18 -0
- package/dist/synthesis/strategies/merge.d.ts.map +1 -0
- package/dist/synthesis/strategies/merge.js +104 -0
- package/dist/synthesis/strategies/rank.d.ts +25 -0
- package/dist/synthesis/strategies/rank.d.ts.map +1 -0
- package/dist/synthesis/strategies/rank.js +51 -0
- package/dist/synthesis/strategies/vote.d.ts +17 -0
- package/dist/synthesis/strategies/vote.d.ts.map +1 -0
- package/dist/synthesis/strategies/vote.js +59 -0
- package/dist/synthesis/synthesizer.d.ts +25 -0
- package/dist/synthesis/synthesizer.d.ts.map +1 -0
- package/dist/synthesis/synthesizer.js +38 -0
- package/dist/synthesis/types.d.ts +96 -0
- package/dist/synthesis/types.d.ts.map +1 -0
- package/dist/synthesis/types.js +8 -0
- package/dist/tools.test.js +86 -6
- package/dist/types.d.ts +16 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/package.json +11 -4
package/README.md
CHANGED
|
@@ -5,16 +5,16 @@ Built-in programmatic session wrapper and agentic tool surface for Babysitter ru
|
|
|
5
5
|
<!-- docs-status:start -->
|
|
6
6
|
> Status: Public advanced/runtime package.
|
|
7
7
|
> Canonical docs home: [Package and Plugin Docs Map](../../docs/package-and-plugin-map.md).
|
|
8
|
-
> This README defines the package contract for runtime consumers and published dependents such as `@a5c-ai/
|
|
8
|
+
> This README defines the package contract for runtime consumers and published dependents such as `@a5c-ai/agent-platform`.
|
|
9
9
|
<!-- docs-status:end -->
|
|
10
10
|
|
|
11
11
|
## Package role
|
|
12
12
|
|
|
13
|
-
`@a5c-ai/agent-core` sits between `@a5c-ai/
|
|
13
|
+
`@a5c-ai/agent-core` sits between `@a5c-ai/agent-platform`, `@a5c-ai/agent-mux`, and `@a5c-ai/babysitter-sdk`:
|
|
14
14
|
|
|
15
15
|
- `createAgentCoreSession()` wraps an `@a5c-ai/agent-mux` client for in-process prompt execution.
|
|
16
16
|
- `createAgentCoreToolDefinitions()` assembles the built-in Babysitter-flavored tool surface that host runtimes can inject into planning, resume, or delegated-task flows.
|
|
17
|
-
- `@a5c-ai/
|
|
17
|
+
- `@a5c-ai/agent-platform` re-exports these APIs from `src/harness/index.ts`, uses `createAgentCoreSession()` for direct `agent-core` harness invocation in `src/harness/invoker.ts`, and injects tool definitions into plan-process and resume-run flows.
|
|
18
18
|
- `@a5c-ai/babysitter-sdk` still owns run directories, journals, task/effect lifecycle, and config defaults. `agent-core` does not replace the SDK orchestration layer.
|
|
19
19
|
|
|
20
20
|
This package is published as a runtime dependency surface for higher-level Babysitter runtimes. It is still an advanced/operator-facing building block rather than the primary entrypoint for new users.
|
|
@@ -98,7 +98,7 @@ These fields remain on `AgentCoreSessionOptions` for compatibility, but the curr
|
|
|
98
98
|
|
|
99
99
|
| Option | Status | Migration note |
|
|
100
100
|
| --- | --- | --- |
|
|
101
|
-
| `toolsMode` | Deprecated, ignored by agent-core | Use backend-native configuration, or the PI wrapper in `@a5c-ai/
|
|
101
|
+
| `toolsMode` | Deprecated, ignored by agent-core | Use backend-native configuration, or the PI wrapper in `@a5c-ai/agent-platform`, if you still need tool-surface control. |
|
|
102
102
|
| `customTools` | Deprecated, ignored by agent-core | Register host-side tools with `createAgentCoreToolDefinitions()` or use the PI wrapper for runtime custom-tool injection. |
|
|
103
103
|
| `isolated` | Deprecated, ignored by agent-core | Use the PI wrapper if you still need extension/skills isolation controls. |
|
|
104
104
|
| `ephemeral` | Deprecated, ignored by agent-core | Session persistence is determined by the selected agent-mux backend. |
|
|
@@ -106,7 +106,7 @@ These fields remain on `AgentCoreSessionOptions` for compatibility, but the curr
|
|
|
106
106
|
| `enableCompaction` | Deprecated, ignored by agent-core | Compaction behavior belongs to the selected backend/runtime. |
|
|
107
107
|
| `agentDir` | Deprecated, ignored by agent-core | Configure agent directories through the target backend instead. |
|
|
108
108
|
|
|
109
|
-
If you still need the PI-era controls above, use the PI wrapper exposed from `@a5c-ai/
|
|
109
|
+
If you still need the PI-era controls above, use the PI wrapper exposed from `@a5c-ai/agent-platform` rather than `@a5c-ai/agent-core`.
|
|
110
110
|
|
|
111
111
|
## Tool-definition API
|
|
112
112
|
|
|
@@ -118,6 +118,7 @@ If you still need the PI-era controls above, use the PI wrapper exposed from `@a
|
|
|
118
118
|
- delegation tools: `AskUserQuestion`, `task`, `skill`
|
|
119
119
|
- code tools: `calc`, `ast_grep`, `ast_edit`, `render_mermaid`, `notebook`
|
|
120
120
|
- background/discovery/web tools: `background_status`, `background_list`, `tool_search`, `tool_fetch`, `web_search`, `fetch_process`
|
|
121
|
+
- optional programmatic tool calling: `code_executor` when `programmaticToolCalling` is enabled
|
|
121
122
|
|
|
122
123
|
`AgentCoreToolOptions` controls how those definitions are wired into a host runtime:
|
|
123
124
|
|
|
@@ -127,6 +128,18 @@ If you still need the PI-era controls above, use the PI wrapper exposed from `@a
|
|
|
127
128
|
- `onToolUse`: observer callback fired after tool wrapping.
|
|
128
129
|
- `onBackgroundComplete`, `maxBackgroundProcesses`, `backgroundRegistry`: background-process lifecycle hooks and limits.
|
|
129
130
|
- `deferredToolRegistry`: enables `tool_search` and `tool_fetch`.
|
|
131
|
+
- `programmaticToolCalling`: opt-in Code Mode / Programmatic Tool Calling surface. When enabled, `code_executor` runs a bounded JavaScript async body with `tools.<name>(params)` and `callTool(name, params)` helpers for batching existing agent-core tools behind one model-level tool call.
|
|
132
|
+
|
|
133
|
+
Example:
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
const tools = createAgentCoreToolDefinitions({
|
|
137
|
+
workspace: process.cwd(),
|
|
138
|
+
interactive: false,
|
|
139
|
+
deferredToolRegistry,
|
|
140
|
+
programmaticToolCalling: { maxToolCalls: 10, timeout: 60_000 },
|
|
141
|
+
});
|
|
142
|
+
```
|
|
130
143
|
|
|
131
144
|
### Interactive and cancellation contract
|
|
132
145
|
|
|
@@ -179,7 +192,7 @@ Source disambiguation uses `(source, sourceQualifier, name)`, so duplicate tool
|
|
|
179
192
|
|
|
180
193
|
Current downstream integration boundaries in this repo:
|
|
181
194
|
|
|
182
|
-
- `@a5c-ai/
|
|
195
|
+
- `@a5c-ai/agent-platform`
|
|
183
196
|
- re-exports the session/tool APIs from `src/harness/index.ts`
|
|
184
197
|
- uses `createAgentCoreSession()` for the direct `agent-core` harness path in `src/harness/invoker.ts`
|
|
185
198
|
- injects `createAgentCoreToolDefinitions()` into plan-process and delegated-task flows in `src/harness/internal/createRun/planProcess/*`
|
|
@@ -189,7 +202,7 @@ Current downstream integration boundaries in this repo:
|
|
|
189
202
|
- `@a5c-ai/babysitter-sdk`
|
|
190
203
|
- provides config defaults/env wiring used by the `config` tool and remains the owner of orchestration/run-state semantics outside this package
|
|
191
204
|
|
|
192
|
-
In practice, use `agent-core` when you need an in-process runtime wrapper or bundled tool surface. Use `
|
|
205
|
+
In practice, use `agent-core` when you need an in-process runtime wrapper or bundled tool surface. Use `agent-platform` when you need the higher-level harness CLI/runtime entrypoints.
|
|
193
206
|
|
|
194
207
|
## Build, test, and CI
|
|
195
208
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Backwards-compatibility shim -- the canonical implementation now lives in
|
|
3
|
+
* `@a5c-ai/agent-runtime`. This re-export keeps internal agent-core consumers
|
|
4
|
+
* working without changes.
|
|
5
|
+
*/
|
|
6
|
+
export { getBackgroundRegistry, disposeBackgroundRegistry, } from "@a5c-ai/agent-runtime";
|
|
5
7
|
//# sourceMappingURL=state.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/agenticTools/background/state.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/agenticTools/background/state.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,qBAAqB,EACrB,yBAAyB,GAC1B,MAAM,uBAAuB,CAAC"}
|
|
@@ -1,25 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBackgroundRegistry =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (!registry) {
|
|
13
|
-
registry = new backgroundProcessRegistry_1.BackgroundProcessRegistry({ maxConcurrent: options.maxBackgroundProcesses });
|
|
14
|
-
scopedRegistries.set(options, registry);
|
|
15
|
-
}
|
|
16
|
-
return registry;
|
|
17
|
-
}
|
|
18
|
-
function disposeBackgroundRegistry(options) {
|
|
19
|
-
const registry = scopedRegistries.get(options);
|
|
20
|
-
if (!registry) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
registry.dispose();
|
|
24
|
-
scopedRegistries.delete(options);
|
|
25
|
-
}
|
|
3
|
+
exports.disposeBackgroundRegistry = exports.getBackgroundRegistry = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Backwards-compatibility shim -- the canonical implementation now lives in
|
|
6
|
+
* `@a5c-ai/agent-runtime`. This re-export keeps internal agent-core consumers
|
|
7
|
+
* working without changes.
|
|
8
|
+
*/
|
|
9
|
+
var agent_runtime_1 = require("@a5c-ai/agent-runtime");
|
|
10
|
+
Object.defineProperty(exports, "getBackgroundRegistry", { enumerable: true, get: function () { return agent_runtime_1.getBackgroundRegistry; } });
|
|
11
|
+
Object.defineProperty(exports, "disposeBackgroundRegistry", { enumerable: true, get: function () { return agent_runtime_1.disposeBackgroundRegistry; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agenticTools/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agenticTools/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAmBxE,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,kBAAkB,GAAG,oBAAoB,EAAE,CAsBlG;AAED,wBAAgB,+BAA+B,CAAC,WAAW,EAAE,oBAAoB,EAAE,GAAG,IAAI,CAOzF;AAED,eAAO,MAAM,4BAA4B,uCAAiC,CAAC"}
|
|
@@ -14,9 +14,10 @@ const code_1 = require("./tools/code");
|
|
|
14
14
|
const delegation_1 = require("./tools/delegation");
|
|
15
15
|
const execution_1 = require("./tools/execution");
|
|
16
16
|
const fileSystem_1 = require("./tools/fileSystem");
|
|
17
|
+
const programmaticToolCalling_1 = require("./tools/programmaticToolCalling");
|
|
17
18
|
const toolDefinitionScopes = new WeakMap();
|
|
18
19
|
function createAgentCoreToolDefinitions(options) {
|
|
19
|
-
const
|
|
20
|
+
const baseTools = [
|
|
20
21
|
...(0, fileSystem_1.createFileSystemTools)(options),
|
|
21
22
|
...(0, execution_1.createExecutionTools)(options),
|
|
22
23
|
(0, tool_1.createBrowserTool)(),
|
|
@@ -27,6 +28,12 @@ function createAgentCoreToolDefinitions(options) {
|
|
|
27
28
|
...(0, tools_2.createDiscoveryTools)(options),
|
|
28
29
|
...(0, tools_3.createWebTools)(),
|
|
29
30
|
].map((tool) => (0, results_1.wrapToolDefinition)(tool, options.onToolUse));
|
|
31
|
+
const tools = (0, programmaticToolCalling_1.shouldEnableProgrammaticToolCalling)(options)
|
|
32
|
+
? [
|
|
33
|
+
...baseTools,
|
|
34
|
+
(0, results_1.wrapToolDefinition)((0, programmaticToolCalling_1.createProgrammaticToolCallingTool)(options, baseTools), options.onToolUse),
|
|
35
|
+
]
|
|
36
|
+
: baseTools;
|
|
30
37
|
toolDefinitionScopes.set(tools, options);
|
|
31
38
|
return tools;
|
|
32
39
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AgenticToolOptions, CustomToolDefinition } from "../types";
|
|
2
|
+
export declare function shouldEnableProgrammaticToolCalling(options: AgenticToolOptions): boolean;
|
|
3
|
+
export declare function createProgrammaticToolCallingTool(options: AgenticToolOptions, availableTools: CustomToolDefinition[]): CustomToolDefinition;
|
|
4
|
+
//# sourceMappingURL=programmaticToolCalling.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"programmaticToolCalling.d.ts","sourceRoot":"","sources":["../../../src/agenticTools/tools/programmaticToolCalling.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAc,MAAM,UAAU,CAAC;AAgBrF,wBAAgB,mCAAmC,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAExF;AAED,wBAAgB,iCAAiC,CAC/C,OAAO,EAAE,kBAAkB,EAC3B,cAAc,EAAE,oBAAoB,EAAE,GACrC,oBAAoB,CAwEtB"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.shouldEnableProgrammaticToolCalling = shouldEnableProgrammaticToolCalling;
|
|
7
|
+
exports.createProgrammaticToolCallingTool = createProgrammaticToolCallingTool;
|
|
8
|
+
const node_vm_1 = __importDefault(require("node:vm"));
|
|
9
|
+
const typebox_1 = require("@sinclair/typebox");
|
|
10
|
+
const results_1 = require("../shared/results");
|
|
11
|
+
const DEFAULT_TIMEOUT_MS = 120_000;
|
|
12
|
+
const DEFAULT_MAX_TOOL_CALLS = 25;
|
|
13
|
+
function shouldEnableProgrammaticToolCalling(options) {
|
|
14
|
+
return Boolean(options.programmaticToolCalling);
|
|
15
|
+
}
|
|
16
|
+
function createProgrammaticToolCallingTool(options, availableTools) {
|
|
17
|
+
const config = resolveExecutorConfig(options);
|
|
18
|
+
const callableTools = availableTools.filter((tool) => tool.name !== "code_executor");
|
|
19
|
+
return {
|
|
20
|
+
name: "code_executor",
|
|
21
|
+
label: "Programmatic Tool Calling",
|
|
22
|
+
description: [
|
|
23
|
+
"Execute a JavaScript tool chain against the agent-core tool surface.",
|
|
24
|
+
"Use tools.<name>(params) or callTool(name, params) to batch discovery,",
|
|
25
|
+
"fetch, filesystem, shell, web, and other enabled tools in one request.",
|
|
26
|
+
].join(" "),
|
|
27
|
+
promptSnippet: [
|
|
28
|
+
"Programmatic Tool Calling is available through code_executor.",
|
|
29
|
+
"Write JavaScript inside an async function body and return the final value.",
|
|
30
|
+
"Call agent-core tools with await tools.read({ path: 'README.md' }) or await callTool('tool_search', { query: 'git' }).",
|
|
31
|
+
].join("\n"),
|
|
32
|
+
parameters: typebox_1.Type.Object({
|
|
33
|
+
code: typebox_1.Type.String({
|
|
34
|
+
description: "JavaScript async function body. Use return <value> for the final result.",
|
|
35
|
+
}),
|
|
36
|
+
timeout: typebox_1.Type.Optional(typebox_1.Type.Number({ description: `Timeout in ms (default: ${config.timeout})` })),
|
|
37
|
+
max_tool_calls: typebox_1.Type.Optional(typebox_1.Type.Number({
|
|
38
|
+
description: `Maximum nested tool calls (default: ${config.maxToolCalls})`,
|
|
39
|
+
})),
|
|
40
|
+
}),
|
|
41
|
+
execute: async (_toolCallId, params) => {
|
|
42
|
+
const calls = [];
|
|
43
|
+
const timeout = resolveInvocationLimit(params.timeout, config.timeout);
|
|
44
|
+
const maxToolCalls = resolveInvocationLimit(params.max_tool_calls, config.maxToolCalls);
|
|
45
|
+
const logs = [];
|
|
46
|
+
const toolMap = new Map(callableTools.map((tool) => [tool.name, tool]));
|
|
47
|
+
const callTool = async (name, toolParams = {}) => {
|
|
48
|
+
if (calls.length >= maxToolCalls) {
|
|
49
|
+
throw new Error(`code_executor exceeded max_tool_calls (${maxToolCalls})`);
|
|
50
|
+
}
|
|
51
|
+
const tool = toolMap.get(name);
|
|
52
|
+
if (!tool) {
|
|
53
|
+
throw new Error(`Tool "${name}" is not available to code_executor.`);
|
|
54
|
+
}
|
|
55
|
+
calls.push({ tool: name, params: toolParams });
|
|
56
|
+
return unwrapToolResult(await tool.execute(`code-executor:${calls.length}:${name}`, toolParams));
|
|
57
|
+
};
|
|
58
|
+
const tools = Object.create(null);
|
|
59
|
+
for (const tool of callableTools) {
|
|
60
|
+
tools[tool.name] = (toolParams = {}) => callTool(tool.name, toolParams);
|
|
61
|
+
}
|
|
62
|
+
const context = node_vm_1.default.createContext({
|
|
63
|
+
callTool,
|
|
64
|
+
tools,
|
|
65
|
+
console: {
|
|
66
|
+
log: (...items) => logs.push(items.map(stringifyLogItem).join(" ")),
|
|
67
|
+
error: (...items) => logs.push(items.map(stringifyLogItem).join(" ")),
|
|
68
|
+
warn: (...items) => logs.push(items.map(stringifyLogItem).join(" ")),
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
const script = new node_vm_1.default.Script(`(async () => {\n${String(params.code ?? "")}\n})()`);
|
|
72
|
+
const startedAt = Date.now();
|
|
73
|
+
const result = await withTimeout(Promise.resolve(script.runInContext(context, { timeout })), timeout);
|
|
74
|
+
return (0, results_1.jsonResult)({
|
|
75
|
+
result,
|
|
76
|
+
logs,
|
|
77
|
+
toolCalls: calls,
|
|
78
|
+
duration: Date.now() - startedAt,
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function resolveInvocationLimit(value, configuredLimit) {
|
|
84
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
85
|
+
return configuredLimit;
|
|
86
|
+
}
|
|
87
|
+
return Math.min(Math.floor(value), configuredLimit);
|
|
88
|
+
}
|
|
89
|
+
function resolveExecutorConfig(options) {
|
|
90
|
+
const configured = options.programmaticToolCalling;
|
|
91
|
+
if (configured && typeof configured === "object") {
|
|
92
|
+
return {
|
|
93
|
+
timeout: configured.timeout ?? DEFAULT_TIMEOUT_MS,
|
|
94
|
+
maxToolCalls: configured.maxToolCalls ?? DEFAULT_MAX_TOOL_CALLS,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
timeout: DEFAULT_TIMEOUT_MS,
|
|
99
|
+
maxToolCalls: DEFAULT_MAX_TOOL_CALLS,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
async function withTimeout(promise, timeout) {
|
|
103
|
+
let timer;
|
|
104
|
+
try {
|
|
105
|
+
return await Promise.race([
|
|
106
|
+
promise,
|
|
107
|
+
new Promise((_resolve, reject) => {
|
|
108
|
+
timer = setTimeout(() => reject(new Error(`code_executor timed out after ${timeout}ms`)), timeout);
|
|
109
|
+
}),
|
|
110
|
+
]);
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
if (timer) {
|
|
114
|
+
clearTimeout(timer);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function unwrapToolResult(result) {
|
|
119
|
+
const text = result.content.map((item) => item.text).join("\n");
|
|
120
|
+
try {
|
|
121
|
+
return JSON.parse(text);
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return text;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function stringifyLogItem(item) {
|
|
128
|
+
if (typeof item === "string") {
|
|
129
|
+
return item;
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
return JSON.stringify(item);
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return String(item);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -1,63 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* stdout/stderr, fires completion callbacks, and enforces a concurrency limit.
|
|
2
|
+
* Backwards-compatibility shim -- the canonical implementation now lives in
|
|
3
|
+
* `@a5c-ai/agent-runtime`. This re-export keeps internal agent-core consumers
|
|
4
|
+
* (and any external code that deep-imported this path) working without changes.
|
|
6
5
|
*/
|
|
7
|
-
|
|
8
|
-
export interface BackgroundTaskRecord {
|
|
9
|
-
backgroundTaskId: string;
|
|
10
|
-
pid: number;
|
|
11
|
-
command: string;
|
|
12
|
-
description?: string;
|
|
13
|
-
startedAt: string;
|
|
14
|
-
status: "running" | "completed" | "exited" | "cancelled" | "killed";
|
|
15
|
-
exitCode: number | null;
|
|
16
|
-
stdout: string;
|
|
17
|
-
stderr: string;
|
|
18
|
-
durationMs: number | null;
|
|
19
|
-
}
|
|
20
|
-
/** Payload delivered to `onComplete` callbacks. */
|
|
21
|
-
export interface BackgroundCompletionEvent {
|
|
22
|
-
backgroundTaskId: string;
|
|
23
|
-
pid: number;
|
|
24
|
-
command: string;
|
|
25
|
-
description?: string;
|
|
26
|
-
status: "completed" | "exited";
|
|
27
|
-
exitCode: number;
|
|
28
|
-
stdout: string;
|
|
29
|
-
stderr: string;
|
|
30
|
-
durationMs: number;
|
|
31
|
-
}
|
|
32
|
-
/** Options for spawning a background process. */
|
|
33
|
-
export interface SpawnOptions {
|
|
34
|
-
command: string;
|
|
35
|
-
cwd: string;
|
|
36
|
-
env?: Record<string, string>;
|
|
37
|
-
description?: string;
|
|
38
|
-
onComplete?: (event: BackgroundCompletionEvent) => void;
|
|
39
|
-
}
|
|
40
|
-
export declare class BackgroundProcessRegistry {
|
|
41
|
-
private readonly processes;
|
|
42
|
-
private readonly maxConcurrent;
|
|
43
|
-
constructor(options?: {
|
|
44
|
-
maxConcurrent?: number;
|
|
45
|
-
});
|
|
46
|
-
/**
|
|
47
|
-
* Spawn a command in the background and begin tracking it.
|
|
48
|
-
* Returns a snapshot of the initial record.
|
|
49
|
-
*/
|
|
50
|
-
spawn(opts: SpawnOptions): BackgroundTaskRecord;
|
|
51
|
-
/** Get a snapshot of a tracked process by ID, or undefined. */
|
|
52
|
-
get(backgroundTaskId: string): BackgroundTaskRecord | undefined;
|
|
53
|
-
/** List snapshots of all tracked processes. */
|
|
54
|
-
list(): BackgroundTaskRecord[];
|
|
55
|
-
/** Cancel (SIGTERM) a running process. Returns true if found and killed. */
|
|
56
|
-
cancel(backgroundTaskId: string): boolean;
|
|
57
|
-
/** Kill all running processes. */
|
|
58
|
-
killAll(): void;
|
|
59
|
-
/** Kill all processes and clear tracking state. */
|
|
60
|
-
dispose(): void;
|
|
61
|
-
private snapshot;
|
|
62
|
-
}
|
|
6
|
+
export { BackgroundProcessRegistry, type BackgroundTaskRecord, type BackgroundCompletionEvent, type SpawnOptions, } from "@a5c-ai/agent-runtime";
|
|
63
7
|
//# sourceMappingURL=backgroundProcessRegistry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backgroundProcessRegistry.d.ts","sourceRoot":"","sources":["../src/backgroundProcessRegistry.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"backgroundProcessRegistry.d.ts","sourceRoot":"","sources":["../src/backgroundProcessRegistry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,yBAAyB,EACzB,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,YAAY,GAClB,MAAM,uBAAuB,CAAC"}
|
|
@@ -1,200 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Background process lifecycle management for the bash agentic tool (GAP-TOOLS-036).
|
|
4
|
-
*
|
|
5
|
-
* Tracks child processes spawned with `run_in_background: true`, collects
|
|
6
|
-
* stdout/stderr, fires completion callbacks, and enforces a concurrency limit.
|
|
7
|
-
*/
|
|
8
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
-
if (k2 === undefined) k2 = k;
|
|
10
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
-
}
|
|
14
|
-
Object.defineProperty(o, k2, desc);
|
|
15
|
-
}) : (function(o, m, k, k2) {
|
|
16
|
-
if (k2 === undefined) k2 = k;
|
|
17
|
-
o[k2] = m[k];
|
|
18
|
-
}));
|
|
19
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
-
}) : function(o, v) {
|
|
22
|
-
o["default"] = v;
|
|
23
|
-
});
|
|
24
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
-
var ownKeys = function(o) {
|
|
26
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
-
var ar = [];
|
|
28
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
-
return ar;
|
|
30
|
-
};
|
|
31
|
-
return ownKeys(o);
|
|
32
|
-
};
|
|
33
|
-
return function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
-
__setModuleDefault(result, mod);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
})();
|
|
41
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
3
|
exports.BackgroundProcessRegistry = void 0;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
processes = new Map();
|
|
51
|
-
maxConcurrent;
|
|
52
|
-
constructor(options) {
|
|
53
|
-
this.maxConcurrent = options?.maxConcurrent ?? DEFAULT_MAX_CONCURRENT;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Spawn a command in the background and begin tracking it.
|
|
57
|
-
* Returns a snapshot of the initial record.
|
|
58
|
-
*/
|
|
59
|
-
spawn(opts) {
|
|
60
|
-
const runningCount = [...this.processes.values()].filter((p) => p.status === "running").length;
|
|
61
|
-
if (runningCount >= this.maxConcurrent) {
|
|
62
|
-
throw new Error(`Max concurrent background processes limit reached (${this.maxConcurrent}). ` +
|
|
63
|
-
`Cancel or wait for existing processes before spawning new ones.`);
|
|
64
|
-
}
|
|
65
|
-
const backgroundTaskId = (0, babysitter_sdk_1.nextUlid)();
|
|
66
|
-
const startMs = Date.now();
|
|
67
|
-
const shell = process.platform === "win32" ? "cmd.exe" : "/bin/bash";
|
|
68
|
-
const shellArgs = process.platform === "win32"
|
|
69
|
-
? ["/c", opts.command]
|
|
70
|
-
: ["-c", opts.command];
|
|
71
|
-
const child = childProcess.spawn(shell, shellArgs, {
|
|
72
|
-
cwd: opts.cwd,
|
|
73
|
-
env: { ...process.env, ...opts.env },
|
|
74
|
-
shell: false,
|
|
75
|
-
windowsHide: true,
|
|
76
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
77
|
-
});
|
|
78
|
-
const tracked = {
|
|
79
|
-
backgroundTaskId,
|
|
80
|
-
pid: child.pid ?? -1,
|
|
81
|
-
command: opts.command,
|
|
82
|
-
description: opts.description,
|
|
83
|
-
startedAt: new Date(startMs).toISOString(),
|
|
84
|
-
startMs,
|
|
85
|
-
status: "running",
|
|
86
|
-
exitCode: null,
|
|
87
|
-
stdoutChunks: [],
|
|
88
|
-
stderrChunks: [],
|
|
89
|
-
durationMs: null,
|
|
90
|
-
child,
|
|
91
|
-
onComplete: opts.onComplete,
|
|
92
|
-
};
|
|
93
|
-
child.stdout?.on("data", (chunk) => {
|
|
94
|
-
tracked.stdoutChunks.push(chunk);
|
|
95
|
-
});
|
|
96
|
-
child.stderr?.on("data", (chunk) => {
|
|
97
|
-
tracked.stderrChunks.push(chunk);
|
|
98
|
-
});
|
|
99
|
-
child.on("close", (code) => {
|
|
100
|
-
if (tracked.status === "running") {
|
|
101
|
-
tracked.status = code === 0 ? "completed" : "exited";
|
|
102
|
-
}
|
|
103
|
-
tracked.exitCode = code ?? 1;
|
|
104
|
-
tracked.durationMs = Date.now() - tracked.startMs;
|
|
105
|
-
if (tracked.onComplete) {
|
|
106
|
-
try {
|
|
107
|
-
tracked.onComplete({
|
|
108
|
-
backgroundTaskId: tracked.backgroundTaskId,
|
|
109
|
-
pid: tracked.pid,
|
|
110
|
-
command: tracked.command,
|
|
111
|
-
description: tracked.description,
|
|
112
|
-
status: tracked.status,
|
|
113
|
-
exitCode: tracked.exitCode,
|
|
114
|
-
stdout: Buffer.concat(tracked.stdoutChunks).toString("utf8"),
|
|
115
|
-
stderr: Buffer.concat(tracked.stderrChunks).toString("utf8"),
|
|
116
|
-
durationMs: tracked.durationMs,
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
catch {
|
|
120
|
-
// Fire-and-forget — callback errors must not crash.
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
child.on("error", () => {
|
|
125
|
-
if (tracked.status === "running") {
|
|
126
|
-
tracked.status = "exited";
|
|
127
|
-
}
|
|
128
|
-
tracked.exitCode = 1;
|
|
129
|
-
tracked.durationMs = Date.now() - tracked.startMs;
|
|
130
|
-
});
|
|
131
|
-
this.processes.set(backgroundTaskId, tracked);
|
|
132
|
-
return this.snapshot(tracked);
|
|
133
|
-
}
|
|
134
|
-
/** Get a snapshot of a tracked process by ID, or undefined. */
|
|
135
|
-
get(backgroundTaskId) {
|
|
136
|
-
const tracked = this.processes.get(backgroundTaskId);
|
|
137
|
-
if (!tracked)
|
|
138
|
-
return undefined;
|
|
139
|
-
return this.snapshot(tracked);
|
|
140
|
-
}
|
|
141
|
-
/** List snapshots of all tracked processes. */
|
|
142
|
-
list() {
|
|
143
|
-
return [...this.processes.values()].map((t) => this.snapshot(t));
|
|
144
|
-
}
|
|
145
|
-
/** Cancel (SIGTERM) a running process. Returns true if found and killed. */
|
|
146
|
-
cancel(backgroundTaskId) {
|
|
147
|
-
const tracked = this.processes.get(backgroundTaskId);
|
|
148
|
-
if (!tracked)
|
|
149
|
-
return false;
|
|
150
|
-
if (tracked.status !== "running")
|
|
151
|
-
return true;
|
|
152
|
-
tracked.status = "cancelled";
|
|
153
|
-
tracked.durationMs = Date.now() - tracked.startMs;
|
|
154
|
-
try {
|
|
155
|
-
tracked.child.kill("SIGTERM");
|
|
156
|
-
}
|
|
157
|
-
catch {
|
|
158
|
-
// Already dead — fine.
|
|
159
|
-
}
|
|
160
|
-
return true;
|
|
161
|
-
}
|
|
162
|
-
/** Kill all running processes. */
|
|
163
|
-
killAll() {
|
|
164
|
-
for (const tracked of this.processes.values()) {
|
|
165
|
-
if (tracked.status === "running") {
|
|
166
|
-
tracked.status = "killed";
|
|
167
|
-
tracked.durationMs = Date.now() - tracked.startMs;
|
|
168
|
-
try {
|
|
169
|
-
tracked.child.kill("SIGTERM");
|
|
170
|
-
}
|
|
171
|
-
catch {
|
|
172
|
-
// Already dead.
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
/** Kill all processes and clear tracking state. */
|
|
178
|
-
dispose() {
|
|
179
|
-
this.killAll();
|
|
180
|
-
this.processes.clear();
|
|
181
|
-
}
|
|
182
|
-
// -------------------------------------------------------------------------
|
|
183
|
-
// Internals
|
|
184
|
-
// -------------------------------------------------------------------------
|
|
185
|
-
snapshot(t) {
|
|
186
|
-
return {
|
|
187
|
-
backgroundTaskId: t.backgroundTaskId,
|
|
188
|
-
pid: t.pid,
|
|
189
|
-
command: t.command,
|
|
190
|
-
description: t.description,
|
|
191
|
-
startedAt: t.startedAt,
|
|
192
|
-
status: t.status,
|
|
193
|
-
exitCode: t.exitCode,
|
|
194
|
-
stdout: Buffer.concat(t.stdoutChunks).toString("utf8"),
|
|
195
|
-
stderr: Buffer.concat(t.stderrChunks).toString("utf8"),
|
|
196
|
-
durationMs: t.durationMs,
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
exports.BackgroundProcessRegistry = BackgroundProcessRegistry;
|
|
4
|
+
/**
|
|
5
|
+
* Backwards-compatibility shim -- the canonical implementation now lives in
|
|
6
|
+
* `@a5c-ai/agent-runtime`. This re-export keeps internal agent-core consumers
|
|
7
|
+
* (and any external code that deep-imported this path) working without changes.
|
|
8
|
+
*/
|
|
9
|
+
var agent_runtime_1 = require("@a5c-ai/agent-runtime");
|
|
10
|
+
Object.defineProperty(exports, "BackgroundProcessRegistry", { enumerable: true, get: function () { return agent_runtime_1.BackgroundProcessRegistry; } });
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { CompactionStrategyKind, PriorityCompactionStrategy, SlidingCompactionStrategy, SummaryCompactionStrategy, CompactionStrategy, ContextEntry, ContextManagerConfig, ContextManager, } from "./types";
|
|
2
|
+
export { ContextManagerImpl, type ContextManagerImplOptions, } from "./manager";
|
|
3
|
+
export { estimateTokens, estimateEntryTokens } from "./token-estimator";
|
|
4
|
+
export { applyPriorityCompaction, applySlidingCompaction, applySummaryCompaction, type PriorityCompactionResult, type SlidingCompactionResult, type SummaryCompactionResult, type SummarizeFn, } from "./strategies";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,sBAAsB,EACtB,0BAA0B,EAC1B,yBAAyB,EACzB,yBAAyB,EACzB,kBAAkB,EAClB,YAAY,EACZ,oBAAoB,EACpB,cAAc,GACf,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,kBAAkB,EAClB,KAAK,yBAAyB,GAC/B,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExE,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,sBAAsB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,EAC5B,KAAK,WAAW,GACjB,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applySummaryCompaction = exports.applySlidingCompaction = exports.applyPriorityCompaction = exports.estimateEntryTokens = exports.estimateTokens = exports.ContextManagerImpl = void 0;
|
|
4
|
+
var manager_1 = require("./manager");
|
|
5
|
+
Object.defineProperty(exports, "ContextManagerImpl", { enumerable: true, get: function () { return manager_1.ContextManagerImpl; } });
|
|
6
|
+
var token_estimator_1 = require("./token-estimator");
|
|
7
|
+
Object.defineProperty(exports, "estimateTokens", { enumerable: true, get: function () { return token_estimator_1.estimateTokens; } });
|
|
8
|
+
Object.defineProperty(exports, "estimateEntryTokens", { enumerable: true, get: function () { return token_estimator_1.estimateEntryTokens; } });
|
|
9
|
+
var strategies_1 = require("./strategies");
|
|
10
|
+
Object.defineProperty(exports, "applyPriorityCompaction", { enumerable: true, get: function () { return strategies_1.applyPriorityCompaction; } });
|
|
11
|
+
Object.defineProperty(exports, "applySlidingCompaction", { enumerable: true, get: function () { return strategies_1.applySlidingCompaction; } });
|
|
12
|
+
Object.defineProperty(exports, "applySummaryCompaction", { enumerable: true, get: function () { return strategies_1.applySummaryCompaction; } });
|