bare-agent 0.10.4 → 0.12.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/bin/cli.d.ts +4 -0
- package/bin/cli.js +70 -12
- package/bin/test-provider.d.ts +2 -0
- package/bin/test-provider.js +5 -1
- package/index.d.ts +20 -0
- package/package.json +44 -10
- package/src/bareguard-adapter.d.ts +118 -0
- package/src/bareguard-adapter.js +75 -3
- package/src/checkpoint.d.ts +61 -0
- package/src/checkpoint.js +17 -8
- package/src/circuit-breaker.d.ts +70 -0
- package/src/circuit-breaker.js +20 -4
- package/src/errors.d.ts +106 -0
- package/src/errors.js +50 -1
- package/src/loop.d.ts +135 -0
- package/src/loop.js +80 -18
- package/src/mcp-bridge.d.ts +133 -0
- package/src/mcp-bridge.js +199 -26
- package/src/mcp.d.ts +4 -0
- package/src/memory.d.ts +50 -0
- package/src/memory.js +22 -2
- package/src/planner.d.ts +62 -0
- package/src/planner.js +26 -7
- package/src/provider-anthropic.d.ts +55 -0
- package/src/provider-anthropic.js +34 -10
- package/src/provider-clipipe.d.ts +86 -0
- package/src/provider-clipipe.js +28 -18
- package/src/provider-fallback.d.ts +44 -0
- package/src/provider-fallback.js +18 -8
- package/src/provider-ollama.d.ts +41 -0
- package/src/provider-ollama.js +29 -7
- package/src/provider-openai.d.ts +57 -0
- package/src/provider-openai.js +34 -7
- package/src/providers.d.ts +6 -0
- package/src/retry.d.ts +44 -0
- package/src/retry.js +15 -1
- package/src/run-plan.d.ts +126 -0
- package/src/run-plan.js +46 -13
- package/src/scheduler.d.ts +102 -0
- package/src/scheduler.js +32 -4
- package/src/state.d.ts +45 -0
- package/src/state.js +18 -2
- package/src/store-jsonfile.d.ts +85 -0
- package/src/store-jsonfile.js +50 -8
- package/src/store-sqlite.d.ts +90 -0
- package/src/store-sqlite.js +31 -7
- package/src/stores.d.ts +3 -0
- package/src/stream.d.ts +79 -0
- package/src/stream.js +32 -0
- package/src/tools.d.ts +8 -0
- package/src/transport-jsonl.d.ts +30 -0
- package/src/transport-jsonl.js +13 -0
- package/src/transports.d.ts +2 -0
- package/tools/browse.d.ts +10 -0
- package/tools/browse.js +2 -0
- package/tools/defer.d.ts +33 -0
- package/tools/defer.js +12 -3
- package/tools/mobile.d.ts +34 -0
- package/tools/mobile.js +28 -15
- package/tools/shell.d.ts +31 -0
- package/tools/shell.js +83 -6
- package/tools/spawn.d.ts +107 -0
- package/tools/spawn.js +24 -5
- package/types/index.d.ts +66 -0
- package/types/shims.d.ts +16 -0
package/tools/spawn.js
CHANGED
|
@@ -31,6 +31,8 @@
|
|
|
31
31
|
* per-family.
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
|
+
/** @typedef {import('../src/stream').Stream} Stream */
|
|
35
|
+
|
|
34
36
|
const { spawn: cpSpawn } = require('node:child_process');
|
|
35
37
|
const path = require('node:path');
|
|
36
38
|
const readline = require('node:readline');
|
|
@@ -57,6 +59,17 @@ function resolveCliPath() {
|
|
|
57
59
|
* }
|
|
58
60
|
*
|
|
59
61
|
* Use this from library code; the LLM-callable tool below wraps it with blocking semantics.
|
|
62
|
+
*
|
|
63
|
+
* @typedef {Record<string, any> & {type?: string, text?: string, ts?: string, data?: any}} ChildEvent
|
|
64
|
+
*
|
|
65
|
+
* @typedef {object} SpawnChildOptions
|
|
66
|
+
* @property {string} [config] - Path to a bareagent config JSON file.
|
|
67
|
+
* @property {*} [input] - Optional JSON input passed to the child on stdin.
|
|
68
|
+
* @property {string} [cliPath] - Override the bareagent CLI path.
|
|
69
|
+
* @property {number} [timeoutMs] - Force-kill child after this many ms.
|
|
70
|
+
* @property {Stream} [stream] - bareagent Stream — child:stderr events get re-emitted here.
|
|
71
|
+
*
|
|
72
|
+
* @param {SpawnChildOptions} [opts]
|
|
60
73
|
*/
|
|
61
74
|
function spawnChild({ config, input, cliPath, timeoutMs, stream } = {}) {
|
|
62
75
|
if (typeof config !== 'string' || !config) {
|
|
@@ -81,8 +94,11 @@ function spawnChild({ config, input, cliPath, timeoutMs, stream } = {}) {
|
|
|
81
94
|
}
|
|
82
95
|
child.stdin.end();
|
|
83
96
|
|
|
97
|
+
/** @type {ChildEvent[]} */
|
|
84
98
|
const events = [];
|
|
99
|
+
/** @type {((event: ChildEvent) => void)[]} */
|
|
85
100
|
const lineSubscribers = [];
|
|
101
|
+
/** @param {(event: ChildEvent) => void} fn */
|
|
86
102
|
const onLine = (fn) => { lineSubscribers.push(fn); return () => {
|
|
87
103
|
const i = lineSubscribers.indexOf(fn);
|
|
88
104
|
if (i >= 0) lineSubscribers.splice(i, 1);
|
|
@@ -100,7 +116,7 @@ function spawnChild({ config, input, cliPath, timeoutMs, stream } = {}) {
|
|
|
100
116
|
}
|
|
101
117
|
events.push(event);
|
|
102
118
|
for (const fn of lineSubscribers) {
|
|
103
|
-
try { fn(event); } catch (err) {
|
|
119
|
+
try { fn(event); } catch (/** @type {any} */ err) {
|
|
104
120
|
// never let a subscriber kill the read loop
|
|
105
121
|
process.stderr.write(`[spawn] onLine subscriber threw: ${err.message}\n`);
|
|
106
122
|
}
|
|
@@ -165,7 +181,9 @@ function spawnChild({ config, input, cliPath, timeoutMs, stream } = {}) {
|
|
|
165
181
|
};
|
|
166
182
|
}
|
|
167
183
|
// Pluck the final loop:done event — that's the canonical child result.
|
|
168
|
-
|
|
184
|
+
// `findLast` is es2023; the lib target may not declare it, so reach it via
|
|
185
|
+
// `any` while keeping the runtime fallback for older Node versions.
|
|
186
|
+
const done = /** @type {any} */ (events).findLast?.((/** @type {ChildEvent} */ e) => e.type === 'loop:done')
|
|
169
187
|
|| [...events].reverse().find(e => e.type === 'loop:done');
|
|
170
188
|
if (done) {
|
|
171
189
|
return {
|
|
@@ -191,6 +209,7 @@ function spawnChild({ config, input, cliPath, timeoutMs, stream } = {}) {
|
|
|
191
209
|
};
|
|
192
210
|
}
|
|
193
211
|
|
|
212
|
+
/** @param {NodeJS.Signals} [sig] */
|
|
194
213
|
function kill(sig = 'SIGTERM') {
|
|
195
214
|
try { child.kill(sig); } catch { /* already dead */ }
|
|
196
215
|
}
|
|
@@ -204,8 +223,8 @@ function spawnChild({ config, input, cliPath, timeoutMs, stream } = {}) {
|
|
|
204
223
|
* @param {object} [options]
|
|
205
224
|
* @param {string} [options.cliPath] - Override the bareagent CLI path (default: ./bin/cli.js relative to this file).
|
|
206
225
|
* @param {number} [options.timeoutMs] - Force-kill child after this many ms (default 10 min).
|
|
207
|
-
* @param {
|
|
208
|
-
* @returns {{tool:
|
|
226
|
+
* @param {Stream} [options.stream] - bareagent Stream instance — child:stderr events get re-emitted here.
|
|
227
|
+
* @returns {{tool: import('../types').ToolDef, spawnChild: typeof spawnChild}}
|
|
209
228
|
*/
|
|
210
229
|
function createSpawnTool(options = {}) {
|
|
211
230
|
const tool = {
|
|
@@ -225,7 +244,7 @@ function createSpawnTool(options = {}) {
|
|
|
225
244
|
},
|
|
226
245
|
required: ['config'],
|
|
227
246
|
},
|
|
228
|
-
execute: async ({ config, input }) => {
|
|
247
|
+
execute: async (/** @type {{config: string, input?: *}} */ { config, input }) => {
|
|
229
248
|
const handle = spawnChild({
|
|
230
249
|
config,
|
|
231
250
|
input,
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Shared, cross-cutting type shapes for bare-agent, consumed from JSDoc via
|
|
2
|
+
// /** @typedef {import('../types').Provider} Provider */ (path is relative to the .js file)
|
|
3
|
+
// These describe the structural contracts that flow between components (provider
|
|
4
|
+
// <-> loop <-> tools). Per-file option bags live as local @typedef blocks in
|
|
5
|
+
// each module; only the genuinely shared shapes belong here.
|
|
6
|
+
|
|
7
|
+
/** Token accounting returned by a provider's generate(). */
|
|
8
|
+
export interface Usage {
|
|
9
|
+
inputTokens: number;
|
|
10
|
+
outputTokens: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** A single tool invocation requested by the model. `arguments` is parsed JSON. */
|
|
14
|
+
export interface ToolCall {
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
arguments: any;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Normalized result every provider.generate() resolves to. */
|
|
21
|
+
export interface GenerateResult {
|
|
22
|
+
text: string;
|
|
23
|
+
toolCalls: ToolCall[];
|
|
24
|
+
usage: Usage;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** A conversation message in OpenAI chat format. */
|
|
28
|
+
export interface Message {
|
|
29
|
+
role: string;
|
|
30
|
+
content?: string | null;
|
|
31
|
+
tool_calls?: any[];
|
|
32
|
+
tool_call_id?: string;
|
|
33
|
+
[key: string]: any;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A callable tool exposed to the loop/provider. */
|
|
37
|
+
export interface ToolDef {
|
|
38
|
+
name: string;
|
|
39
|
+
description?: string;
|
|
40
|
+
parameters?: Record<string, any>;
|
|
41
|
+
execute(args: any): any | Promise<any>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Minimal LLM provider contract the Loop and Planner depend on. */
|
|
45
|
+
export interface Provider {
|
|
46
|
+
/** Model id, surfaced for cost estimation. */
|
|
47
|
+
model?: string | null;
|
|
48
|
+
/** Provider name, surfaced in onLlmResult. */
|
|
49
|
+
name?: string | null;
|
|
50
|
+
generate(
|
|
51
|
+
messages: Message[],
|
|
52
|
+
tools?: ToolDef[],
|
|
53
|
+
options?: Record<string, any>,
|
|
54
|
+
): Promise<GenerateResult>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Swappable persistence backend for Memory. */
|
|
58
|
+
export interface Store {
|
|
59
|
+
store(content: any, metadata?: Record<string, any>): any;
|
|
60
|
+
search(query: string, options?: Record<string, any>): any;
|
|
61
|
+
get(id: any): any;
|
|
62
|
+
delete(id: any): any;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Opaque per-run blob forwarded to policy/record callbacks. */
|
|
66
|
+
export type Ctx = any;
|
package/types/shims.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Ambient module declarations for dependencies that ship no TypeScript types.
|
|
2
|
+
//
|
|
3
|
+
// `bareguard` is a required dependency but publishes plain JS with no .d.ts; the
|
|
4
|
+
// others are optional/peer deps that may not be installed in every environment
|
|
5
|
+
// (and aren't installed in CI). Declaring them here lets `tsc --checkJs` run
|
|
6
|
+
// without `npm i`-ing native modules, while keeping our own JSDoc fully checked.
|
|
7
|
+
// Each `require()` of these modules resolves to `any`, so our code is responsible
|
|
8
|
+
// for documenting the shapes it relies on via local @typedef/@param JSDoc.
|
|
9
|
+
|
|
10
|
+
declare module 'bareguard';
|
|
11
|
+
declare module 'better-sqlite3';
|
|
12
|
+
declare module 'barebrowse';
|
|
13
|
+
declare module 'barebrowse/bareagent';
|
|
14
|
+
declare module 'baremobile';
|
|
15
|
+
declare module 'baremobile/ios';
|
|
16
|
+
declare module 'cron-parser';
|