bare-agent 0.43.0 → 0.44.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.
Files changed (78) hide show
  1. package/package.json +8 -3
  2. package/primitives.json +447 -0
  3. package/src/bareguard-adapter.d.ts +6 -0
  4. package/src/bareguard-adapter.js +6 -0
  5. package/src/checkpoint.d.ts +5 -0
  6. package/src/checkpoint.js +5 -0
  7. package/src/circuit-breaker.d.ts +5 -0
  8. package/src/circuit-breaker.js +5 -0
  9. package/src/complexity.d.ts +9 -0
  10. package/src/complexity.js +9 -0
  11. package/src/context-units.d.ts +12 -0
  12. package/src/context-units.js +12 -0
  13. package/src/evaluator.d.ts +9 -1
  14. package/src/evaluator.js +9 -1
  15. package/src/judge-calibration.d.ts +5 -0
  16. package/src/judge-calibration.js +5 -0
  17. package/src/judge.d.ts +5 -0
  18. package/src/judge.js +5 -0
  19. package/src/loop.d.ts +6 -0
  20. package/src/loop.js +6 -0
  21. package/src/mcp-bridge.d.ts +13 -0
  22. package/src/mcp-bridge.js +13 -0
  23. package/src/memory.d.ts +5 -0
  24. package/src/memory.js +5 -0
  25. package/src/planner.d.ts +6 -0
  26. package/src/planner.js +6 -0
  27. package/src/provider-anthropic.d.ts +4 -0
  28. package/src/provider-anthropic.js +4 -0
  29. package/src/provider-clipipe.d.ts +4 -0
  30. package/src/provider-clipipe.js +4 -0
  31. package/src/provider-fallback.d.ts +4 -0
  32. package/src/provider-fallback.js +4 -0
  33. package/src/provider-gemini.d.ts +7 -1
  34. package/src/provider-gemini.js +7 -1
  35. package/src/provider-ollama.d.ts +4 -0
  36. package/src/provider-ollama.js +4 -0
  37. package/src/provider-openai.d.ts +4 -0
  38. package/src/provider-openai.js +4 -0
  39. package/src/recurse-retrieval.d.ts +22 -0
  40. package/src/recurse-retrieval.js +22 -0
  41. package/src/recurse.d.ts +6 -0
  42. package/src/recurse.js +6 -0
  43. package/src/refine.d.ts +5 -0
  44. package/src/refine.js +5 -0
  45. package/src/remember.d.ts +5 -0
  46. package/src/remember.js +5 -0
  47. package/src/retry.d.ts +8 -1
  48. package/src/retry.js +8 -1
  49. package/src/run-plan.d.ts +5 -0
  50. package/src/run-plan.js +5 -0
  51. package/src/scheduler.d.ts +8 -1
  52. package/src/scheduler.js +8 -1
  53. package/src/skills.d.ts +6 -0
  54. package/src/skills.js +6 -0
  55. package/src/stash.d.ts +5 -0
  56. package/src/stash.js +5 -0
  57. package/src/state.d.ts +8 -1
  58. package/src/state.js +8 -1
  59. package/src/store-jsonfile.d.ts +5 -0
  60. package/src/store-jsonfile.js +5 -0
  61. package/src/store-sqlite.d.ts +5 -0
  62. package/src/store-sqlite.js +5 -0
  63. package/src/stream.d.ts +5 -0
  64. package/src/stream.js +5 -0
  65. package/src/transport-jsonl.d.ts +4 -0
  66. package/src/transport-jsonl.js +4 -0
  67. package/tools/browse.d.ts +5 -0
  68. package/tools/browse.js +5 -0
  69. package/tools/defer.d.ts +13 -1
  70. package/tools/defer.js +13 -1
  71. package/tools/litectx-mcp.d.ts +6 -0
  72. package/tools/litectx-mcp.js +6 -0
  73. package/tools/mobile.d.ts +5 -0
  74. package/tools/mobile.js +5 -0
  75. package/tools/shell.d.ts +5 -0
  76. package/tools/shell.js +5 -0
  77. package/tools/spawn.d.ts +10 -0
  78. package/tools/spawn.js +10 -0
package/src/refine.js CHANGED
@@ -38,6 +38,11 @@
38
38
  *
39
39
  * @param {RefineOptions} options
40
40
  * @returns {Promise<RefineOutcome>}
41
+ * @when you have a caller-supplied attempt + evaluate pair and want to iterate generate → grade → regenerate until it passes or hits a bound
42
+ * @fails returns the last outcome on maxIterations or a terminal `failed` verdict (never a faked pass); a HaltError from either callback propagates clean.
43
+ * @example
44
+ * const { result, passed } = await refine({ attempt, evaluate, maxIterations: 3 });
45
+ * if (!passed) escalate(result);
41
46
  */
42
47
  async function refine(options) {
43
48
  const { attempt, evaluate } = options;
package/src/remember.d.ts CHANGED
@@ -84,6 +84,11 @@ export type Store = import("../types").Store;
84
84
  * Each is a transcript chunk — a raw string, or an object with `content`/`text`. Empty/blank spans are skipped.
85
85
  * @param {RememberOptions} options
86
86
  * @returns {Promise<RememberOutcome>}
87
+ * @when you want to distill durable facts from harvested transcript spans and persist them through a Store socket (the consolidation pass)
88
+ * @fails skips empty spans and never fabricates; a provider HaltError propagates clean. Each pass forwards usage via onLlmResult; a fact counts once via ctx.recordMemoryOp.
89
+ * @example
90
+ * const { facts } = await remember(spans, { provider, store });
91
+ * console.log(`consolidated ${facts.length} durable facts`);
87
92
  */
88
93
  export function remember(spans: Array<string | {
89
94
  content?: string;
package/src/remember.js CHANGED
@@ -73,6 +73,11 @@ const DISTILL_PROMPT = [
73
73
  * Each is a transcript chunk — a raw string, or an object with `content`/`text`. Empty/blank spans are skipped.
74
74
  * @param {RememberOptions} options
75
75
  * @returns {Promise<RememberOutcome>}
76
+ * @when you want to distill durable facts from harvested transcript spans and persist them through a Store socket (the consolidation pass)
77
+ * @fails skips empty spans and never fabricates; a provider HaltError propagates clean. Each pass forwards usage via onLlmResult; a fact counts once via ctx.recordMemoryOp.
78
+ * @example
79
+ * const { facts } = await remember(spans, { provider, store });
80
+ * console.log(`consolidated ${facts.length} durable facts`);
76
81
  */
77
82
  async function remember(spans, options = /** @type {RememberOptions} */ ({})) {
78
83
  if (!Array.isArray(spans)) throw new Error('[remember] spans must be an array');
package/src/retry.d.ts CHANGED
@@ -21,7 +21,14 @@ export type RetryOptions = {
21
21
  jitter?: number | boolean | "full" | "equal" | undefined;
22
22
  };
23
23
  export class Retry {
24
- /** @param {RetryOptions} [options={}] */
24
+ /**
25
+ * @param {RetryOptions} [options={}]
26
+ * @when you want backoff-with-jitter around a flaky async call (a provider request, a plan step) — the retry seam Loop and runPlan wrap providers with
27
+ * @fails rethrows the last error once attempts are exhausted; by default only transient errors (429/5xx/ECONNRESET/ETIMEDOUT) are retried.
28
+ * @example
29
+ * const retry = new Retry({ maxAttempts: 3, jitter: true });
30
+ * const res = await retry.call(() => provider.generate(msgs));
31
+ */
25
32
  constructor(options?: RetryOptions);
26
33
  maxAttempts: number;
27
34
  backoff: number | "linear" | "exponential";
package/src/retry.js CHANGED
@@ -23,7 +23,14 @@ const DEFAULT_RETRY_ON = (err) => {
23
23
  };
24
24
 
25
25
  class Retry {
26
- /** @param {RetryOptions} [options={}] */
26
+ /**
27
+ * @param {RetryOptions} [options={}]
28
+ * @when you want backoff-with-jitter around a flaky async call (a provider request, a plan step) — the retry seam Loop and runPlan wrap providers with
29
+ * @fails rethrows the last error once attempts are exhausted; by default only transient errors (429/5xx/ECONNRESET/ETIMEDOUT) are retried.
30
+ * @example
31
+ * const retry = new Retry({ maxAttempts: 3, jitter: true });
32
+ * const res = await retry.call(() => provider.generate(msgs));
33
+ */
27
34
  constructor(options = {}) {
28
35
  this.maxAttempts = options.maxAttempts !== undefined ? options.maxAttempts : 3;
29
36
  this.backoff = options.backoff || 'exponential';
package/src/run-plan.d.ts CHANGED
@@ -122,5 +122,10 @@ export type StepResult = {
122
122
  * @throws {Error} `[runPlan] executeFn must be a function` — when executeFn is not a function.
123
123
  * @throws {Error} `[runPlan] duplicate step id: "X"` — when two steps share an id.
124
124
  * @throws {Error} `[runPlan] step "X" depends on unknown step "Y"` — when dependsOn references missing id.
125
+ * @when you have a step DAG from the Planner and want to execute it with wave-based parallelism (independent steps run concurrently)
126
+ * @fails throws on a malformed DAG (empty steps, non-function executeFn, duplicate ids, unknown dependency); a step's own error surfaces per StepResult, never crashing the wave.
127
+ * @example
128
+ * const steps = await planner.plan(goal);
129
+ * const results = await runPlan(steps, step => execute(step));
125
130
  */
126
131
  export function runPlan(steps: Step[], executeFn: (step: Step) => any, options?: RunPlanOptions): Promise<StepResult[]>;
package/src/run-plan.js CHANGED
@@ -47,6 +47,11 @@
47
47
  * @throws {Error} `[runPlan] executeFn must be a function` — when executeFn is not a function.
48
48
  * @throws {Error} `[runPlan] duplicate step id: "X"` — when two steps share an id.
49
49
  * @throws {Error} `[runPlan] step "X" depends on unknown step "Y"` — when dependsOn references missing id.
50
+ * @when you have a step DAG from the Planner and want to execute it with wave-based parallelism (independent steps run concurrently)
51
+ * @fails throws on a malformed DAG (empty steps, non-function executeFn, duplicate ids, unknown dependency); a step's own error surfaces per StepResult, never crashing the wave.
52
+ * @example
53
+ * const steps = await planner.plan(goal);
54
+ * const results = await runPlan(steps, step => execute(step));
50
55
  */
51
56
  async function runPlan(steps, executeFn, options = {}) {
52
57
  if (!Array.isArray(steps) || steps.length === 0) {
@@ -48,7 +48,14 @@ export type SchedulerOptions = {
48
48
  * @property {((err: any, job: Job) => void)|null} [onError] - Handler errors callback.
49
49
  */
50
50
  export class Scheduler {
51
- /** @param {SchedulerOptions} [options={}] */
51
+ /**
52
+ * @param {SchedulerOptions} [options={}]
53
+ * @when you need to fire agent turns on a schedule — cron expressions or relative intervals — driven by a periodic tick
54
+ * @fails an errored job routes to the onError handler and never crashes the tick loop; a malformed cron/interval is rejected when the job is added.
55
+ * @example
56
+ * const sched = new Scheduler({ interval: 60000 });
57
+ * sched.add({ id: 'poll', cron: '0 * * * *', run });
58
+ */
52
59
  constructor(options?: SchedulerOptions);
53
60
  _file: string | null;
54
61
  _interval: number;
package/src/scheduler.js CHANGED
@@ -32,7 +32,14 @@ const { readFileSync, writeFileSync, existsSync } = require('node:fs');
32
32
  */
33
33
 
34
34
  class Scheduler {
35
- /** @param {SchedulerOptions} [options={}] */
35
+ /**
36
+ * @param {SchedulerOptions} [options={}]
37
+ * @when you need to fire agent turns on a schedule — cron expressions or relative intervals — driven by a periodic tick
38
+ * @fails an errored job routes to the onError handler and never crashes the tick loop; a malformed cron/interval is rejected when the job is added.
39
+ * @example
40
+ * const sched = new Scheduler({ interval: 60000 });
41
+ * sched.add({ id: 'poll', cron: '0 * * * *', run });
42
+ */
36
43
  constructor(options = {}) {
37
44
  this._file = options.file || null;
38
45
  this._interval = options.interval || 60000;
package/src/skills.d.ts CHANGED
@@ -24,6 +24,12 @@ export class SkillRegistry {
24
24
  * skill tool that would collide with one is rejected at `register` time. Tool names are globally unique
25
25
  * for DISPATCH (PRD §2.6, D6) — this is the collision check across native + MCP + skills, not security.
26
26
  * @param {string} [options.metaToolName='skill_use'] - Override the meta-tool name if `skill_use` is taken.
27
+ * @when you want to expose operator-registered skill bundles to a model by progressive disclosure — one meta-tool whose catalog unlocks a skill's tools on demand
28
+ * @fails register() rejects an unsafe or colliding name fail-fast and commits nothing on failure; governance is unchanged — discovery never authorizes.
29
+ * @example
30
+ * const skills = new SkillRegistry();
31
+ * skills.register({ name: 'deploy', description: 'ship a release', instructions: '...', tools: [] });
32
+ * const loop = new Loop({ provider, tools: skills.activeTools });
27
33
  */
28
34
  constructor(options?: {
29
35
  reserved?: Iterable<string> | undefined;
package/src/skills.js CHANGED
@@ -51,6 +51,12 @@ class SkillRegistry {
51
51
  * skill tool that would collide with one is rejected at `register` time. Tool names are globally unique
52
52
  * for DISPATCH (PRD §2.6, D6) — this is the collision check across native + MCP + skills, not security.
53
53
  * @param {string} [options.metaToolName='skill_use'] - Override the meta-tool name if `skill_use` is taken.
54
+ * @when you want to expose operator-registered skill bundles to a model by progressive disclosure — one meta-tool whose catalog unlocks a skill's tools on demand
55
+ * @fails register() rejects an unsafe or colliding name fail-fast and commits nothing on failure; governance is unchanged — discovery never authorizes.
56
+ * @example
57
+ * const skills = new SkillRegistry();
58
+ * skills.register({ name: 'deploy', description: 'ship a release', instructions: '...', tools: [] });
59
+ * const loop = new Loop({ provider, tools: skills.activeTools });
54
60
  */
55
61
  constructor(options = {}) {
56
62
  /** @type {Map<string, {name: string, description: string, instructions: string, tools: ToolDef[]}>} */
package/src/stash.d.ts CHANGED
@@ -19,6 +19,11 @@ export type ToolDef = import("../types").ToolDef;
19
19
  * @param {number} [options.compaction.keepRecentTurns=3] - Recent turns to keep at the END (live working set).
20
20
  * @param {(msg: string) => void} [options.onNote=console.warn] - Sink for the loud one-time/backstop notes.
21
21
  * @returns {{ skill: { name: string, description: string, instructions: string, tools: ToolDef[] }, trim: (msgs: any[], ctx: any) => Promise<any[]>, restoreHandles: () => string[] }}
22
+ * @when you need compaction-first context hygiene — a registrable skill whose checkpoint/compact/restore tools fold the live transcript at round boundaries
23
+ * @fails never throws for a fold; degrades LOUDLY to a lossless park when summarize is unwired. Preserves tool-pairing and role alternation by construction.
24
+ * @example
25
+ * const { skill, trim } = createStashSkill({ compaction: { ceilingTokens: 100000 } });
26
+ * const loop = new Loop({ provider, trim });
22
27
  */
23
28
  export function createStashSkill(options?: {
24
29
  defaultStrategy?: "summarize" | "stash" | undefined;
package/src/stash.js CHANGED
@@ -82,6 +82,11 @@ const INSTRUCTIONS =
82
82
  * @param {number} [options.compaction.keepRecentTurns=3] - Recent turns to keep at the END (live working set).
83
83
  * @param {(msg: string) => void} [options.onNote=console.warn] - Sink for the loud one-time/backstop notes.
84
84
  * @returns {{ skill: { name: string, description: string, instructions: string, tools: ToolDef[] }, trim: (msgs: any[], ctx: any) => Promise<any[]>, restoreHandles: () => string[] }}
85
+ * @when you need compaction-first context hygiene — a registrable skill whose checkpoint/compact/restore tools fold the live transcript at round boundaries
86
+ * @fails never throws for a fold; degrades LOUDLY to a lossless park when summarize is unwired. Preserves tool-pairing and role alternation by construction.
87
+ * @example
88
+ * const { skill, trim } = createStashSkill({ compaction: { ceilingTokens: 100000 } });
89
+ * const loop = new Loop({ provider, trim });
85
90
  */
86
91
  function createStashSkill(options = {}) {
87
92
  const {
package/src/state.d.ts CHANGED
@@ -12,7 +12,14 @@ export type Task = {
12
12
  * @property {string} updatedAt
13
13
  */
14
14
  export class StateMachine extends EventEmitter<[never]> {
15
- /** @param {{ file?: string|null }} [options={}] */
15
+ /**
16
+ * @param {{ file?: string|null }} [options={}]
17
+ * @when you need to track task lifecycle (pending/running/done/failed/waiting/cancelled) with enforced transitions and optional file persistence
18
+ * @fails rejects an illegal state transition and never throws on a valid one; state changes are emitted as events.
19
+ * @example
20
+ * const sm = new StateMachine();
21
+ * sm.create('t1'); sm.transition('t1', 'running');
22
+ */
16
23
  constructor(options?: {
17
24
  file?: string | null;
18
25
  });
package/src/state.js CHANGED
@@ -21,7 +21,14 @@ const TRANSITIONS = {
21
21
  */
22
22
 
23
23
  class StateMachine extends EventEmitter {
24
- /** @param {{ file?: string|null }} [options={}] */
24
+ /**
25
+ * @param {{ file?: string|null }} [options={}]
26
+ * @when you need to track task lifecycle (pending/running/done/failed/waiting/cancelled) with enforced transitions and optional file persistence
27
+ * @fails rejects an illegal state transition and never throws on a valid one; state changes are emitted as events.
28
+ * @example
29
+ * const sm = new StateMachine();
30
+ * sm.create('t1'); sm.transition('t1', 'running');
31
+ */
25
32
  constructor(options = {}) {
26
33
  super();
27
34
  this.file = options.file || null;
@@ -42,6 +42,11 @@ export class JsonFileStore {
42
42
  /**
43
43
  * @param {{ path?: string }} [options]
44
44
  * @throws {Error} `[JsonFileStore] requires options.path` — when path is missing.
45
+ * @name JsonFile
46
+ * @when you want zero-dependency JSON-file storage for Memory (store/search/get/delete) — the simplest durable backend, no native deps
47
+ * @fails throws on a missing path; implements the four-verb Store socket over a plain JSON file.
48
+ * @example
49
+ * const store = new JsonFile({ path: './agent.json' });
45
50
  */
46
51
  constructor(options?: {
47
52
  path?: string;
@@ -31,6 +31,11 @@ class JsonFileStore {
31
31
  /**
32
32
  * @param {{ path?: string }} [options]
33
33
  * @throws {Error} `[JsonFileStore] requires options.path` — when path is missing.
34
+ * @name JsonFile
35
+ * @when you want zero-dependency JSON-file storage for Memory (store/search/get/delete) — the simplest durable backend, no native deps
36
+ * @fails throws on a missing path; implements the four-verb Store socket over a plain JSON file.
37
+ * @example
38
+ * const store = new JsonFile({ path: './agent.json' });
34
39
  */
35
40
  constructor(options = {}) {
36
41
  if (!options.path) throw new Error('[JsonFileStore] requires options.path');
@@ -43,6 +43,11 @@ export class SQLiteStore {
43
43
  * @param {{ path?: string }} [options]
44
44
  * @throws {Error} `[SQLiteStore] requires options.path` — when path is missing.
45
45
  * @throws {Error} `[SQLiteStore] requires better-sqlite3` — when peer dep is not installed.
46
+ * @name SQLite
47
+ * @when you want durable, queryable SQLite-backed storage for Memory (store/search/get/delete) persisted on disk
48
+ * @fails throws on a missing path or an absent better-sqlite3 peer dep; implements the four-verb Store socket.
49
+ * @example
50
+ * const store = new SQLite({ path: './agent.db' });
46
51
  */
47
52
  constructor(options?: {
48
53
  path?: string;
@@ -23,6 +23,11 @@ class SQLiteStore {
23
23
  * @param {{ path?: string }} [options]
24
24
  * @throws {Error} `[SQLiteStore] requires options.path` — when path is missing.
25
25
  * @throws {Error} `[SQLiteStore] requires better-sqlite3` — when peer dep is not installed.
26
+ * @name SQLite
27
+ * @when you want durable, queryable SQLite-backed storage for Memory (store/search/get/delete) persisted on disk
28
+ * @fails throws on a missing path or an absent better-sqlite3 peer dep; implements the four-verb Store socket.
29
+ * @example
30
+ * const store = new SQLite({ path: './agent.db' });
26
31
  */
27
32
  constructor(options = {}) {
28
33
  if (!options.path) throw new Error('[SQLiteStore] requires options.path');
package/src/stream.d.ts CHANGED
@@ -60,6 +60,11 @@ export type StreamOptions = {
60
60
  export class Stream {
61
61
  /**
62
62
  * @param {StreamOptions} [options={}]
63
+ * @when you want a structured event emitter for loop/tool/governance events, optionally piped to a transport sink
64
+ * @fails never throws on emit; a transport write error is isolated and does not interrupt the run.
65
+ * @example
66
+ * const stream = new Stream({ transport });
67
+ * stream.emit('loop:round', { n: 1 });
63
68
  */
64
69
  constructor(options?: StreamOptions);
65
70
  /** @type {Transport|null} */
package/src/stream.js CHANGED
@@ -36,6 +36,11 @@
36
36
  class Stream {
37
37
  /**
38
38
  * @param {StreamOptions} [options={}]
39
+ * @when you want a structured event emitter for loop/tool/governance events, optionally piped to a transport sink
40
+ * @fails never throws on emit; a transport write error is isolated and does not interrupt the run.
41
+ * @example
42
+ * const stream = new Stream({ transport });
43
+ * stream.emit('loop:round', { n: 1 });
39
44
  */
40
45
  constructor(options = {}) {
41
46
  /** @type {Transport|null} */
@@ -17,6 +17,10 @@ export type JsonlTransportOptions = {
17
17
  export class JsonlTransport {
18
18
  /**
19
19
  * @param {JsonlTransportOptions} [options={}]
20
+ * @when you want to pipe structured Stream events as JSONL to a writable stream — pipe-friendly observability
21
+ * @fails never throws on write; defaults to process.stdout when no output stream is given.
22
+ * @example
23
+ * const stream = new Stream({ transport: new JsonlTransport() });
20
24
  */
21
25
  constructor(options?: JsonlTransportOptions);
22
26
  _output: NodeJS.WritableStream | (NodeJS.WriteStream & {
@@ -15,6 +15,10 @@
15
15
  class JsonlTransport {
16
16
  /**
17
17
  * @param {JsonlTransportOptions} [options={}]
18
+ * @when you want to pipe structured Stream events as JSONL to a writable stream — pipe-friendly observability
19
+ * @fails never throws on write; defaults to process.stdout when no output stream is given.
20
+ * @example
21
+ * const stream = new Stream({ transport: new JsonlTransport() });
18
22
  */
19
23
  constructor(options = {}) {
20
24
  this._output = options.output || process.stdout;
package/tools/browse.d.ts CHANGED
@@ -3,6 +3,11 @@
3
3
  * Returns { tools, close } or null if barebrowse is not installed.
4
4
  * @param {object} [opts] - Options passed to barebrowse createBrowseTools
5
5
  * @returns {Promise<{tools: Array, close: Function}|null>}
6
+ * @when you want to give an agent browser tools (navigate, click, read) via barebrowse for inline snapshots
7
+ * @fails returns null if barebrowse (optional dep) is not installed; otherwise returns {tools, close} — call close() to release the browser.
8
+ * @example
9
+ * const b = await createBrowsingTools();
10
+ * const loop = new Loop({ provider, tools: b.tools });
6
11
  */
7
12
  export function createBrowsingTools(opts?: object): Promise<{
8
13
  tools: any[];
package/tools/browse.js CHANGED
@@ -5,6 +5,11 @@
5
5
  * Returns { tools, close } or null if barebrowse is not installed.
6
6
  * @param {object} [opts] - Options passed to barebrowse createBrowseTools
7
7
  * @returns {Promise<{tools: Array, close: Function}|null>}
8
+ * @when you want to give an agent browser tools (navigate, click, read) via barebrowse for inline snapshots
9
+ * @fails returns null if barebrowse (optional dep) is not installed; otherwise returns {tools, close} — call close() to release the browser.
10
+ * @example
11
+ * const b = await createBrowsingTools();
12
+ * const loop = new Loop({ provider, tools: b.tools });
8
13
  */
9
14
  async function createBrowsingTools(opts = {}) {
10
15
  try {
package/tools/defer.d.ts CHANGED
@@ -2,6 +2,11 @@
2
2
  * @param {object} [options]
3
3
  * @param {string} [options.queuePath] - Override queue file path.
4
4
  * @returns {{tool: import('../types').ToolDef, readQueue: () => Promise<Record<string, any>[]>, queuePath: string}}
5
+ * @when you want a tool that queues an action to a JSONL file for an external waker (cron) to fire later — two-phase governance (emit-time + fire-time)
6
+ * @fails returns {tool, readQueue, queuePath}; the inner action is re-gated at fire time when the waker runs. bareguard caps via defer.ratePerMinute.
7
+ * @example
8
+ * const { tool } = createDeferTool();
9
+ * const loop = new Loop({ provider, tools: [tool] });
5
10
  */
6
11
  export function createDeferTool(options?: {
7
12
  queuePath?: string | undefined;
@@ -15,7 +20,14 @@ export function createDeferTool(options?: {
15
20
  * append-only status lines (latest wins). Exposed for tests + library
16
21
  * users; the wake script does its own jq-based fold.
17
22
  */
18
- /** @param {string} [queuePath] */
23
+ /**
24
+ * @param {string} [queuePath]
25
+ * @name readDeferQueue
26
+ * @when you want to read the deferred-action queue and reconstruct each id's live status (an external waker or a status check)
27
+ * @fails never throws on a missing/empty queue; folds append-only status lines (latest wins) and returns the reconstructed records.
28
+ * @example
29
+ * const queue = await readDeferQueue();
30
+ */
19
31
  export function readQueue(queuePath?: string): Promise<Record<string, any>[]>;
20
32
  /**
21
33
  * Generate a sortable, unique id. 9-char base36 timestamp + 20-char hex
package/tools/defer.js CHANGED
@@ -128,7 +128,14 @@ async function appendRecord(queuePath, record) {
128
128
  * append-only status lines (latest wins). Exposed for tests + library
129
129
  * users; the wake script does its own jq-based fold.
130
130
  */
131
- /** @param {string} [queuePath] */
131
+ /**
132
+ * @param {string} [queuePath]
133
+ * @name readDeferQueue
134
+ * @when you want to read the deferred-action queue and reconstruct each id's live status (an external waker or a status check)
135
+ * @fails never throws on a missing/empty queue; folds append-only status lines (latest wins) and returns the reconstructed records.
136
+ * @example
137
+ * const queue = await readDeferQueue();
138
+ */
132
139
  async function readQueue(queuePath) {
133
140
  const path = resolveQueuePath(queuePath);
134
141
  try {
@@ -156,6 +163,11 @@ async function readQueue(queuePath) {
156
163
  * @param {object} [options]
157
164
  * @param {string} [options.queuePath] - Override queue file path.
158
165
  * @returns {{tool: import('../types').ToolDef, readQueue: () => Promise<Record<string, any>[]>, queuePath: string}}
166
+ * @when you want a tool that queues an action to a JSONL file for an external waker (cron) to fire later — two-phase governance (emit-time + fire-time)
167
+ * @fails returns {tool, readQueue, queuePath}; the inner action is re-gated at fire time when the waker runs. bareguard caps via defer.ratePerMinute.
168
+ * @example
169
+ * const { tool } = createDeferTool();
170
+ * const loop = new Loop({ provider, tools: [tool] });
159
171
  */
160
172
  function createDeferTool(options = {}) {
161
173
  const queuePath = resolveQueuePath(options.queuePath);
@@ -10,6 +10,12 @@
10
10
  * @param {string} [opts.now] - ISO timestamp for `discovered` (default: now). Pre-seed fresh so
11
11
  * `createMCPBridge` skips IDE discovery and connects straight to this curated server.
12
12
  * @returns {import('../src/mcp-bridge').BridgeConfig}
13
+ * @category integration
14
+ * @when you want to connect a litectx instance to a bareagent runner over the MCP bridge — a curated, child-db-local litectx server
15
+ * @fails read-only by default (opt-in `writable` allows remember/forget); pre-seeding `now` makes createMCPBridge skip IDE discovery and connect straight to this server.
16
+ * @example
17
+ * const cfg = liteCtxMcpBridgeConfig({ root: './child.db' });
18
+ * const { tools } = await createMCPBridge({ config: cfg });
13
19
  */
14
20
  export function liteCtxMcpBridgeConfig(opts: {
15
21
  root: string;
@@ -36,6 +36,12 @@ const ADMIN_VERBS = ['index', 'promotions'];
36
36
  * @param {string} [opts.now] - ISO timestamp for `discovered` (default: now). Pre-seed fresh so
37
37
  * `createMCPBridge` skips IDE discovery and connects straight to this curated server.
38
38
  * @returns {import('../src/mcp-bridge').BridgeConfig}
39
+ * @category integration
40
+ * @when you want to connect a litectx instance to a bareagent runner over the MCP bridge — a curated, child-db-local litectx server
41
+ * @fails read-only by default (opt-in `writable` allows remember/forget); pre-seeding `now` makes createMCPBridge skip IDE discovery and connect straight to this server.
42
+ * @example
43
+ * const cfg = liteCtxMcpBridgeConfig({ root: './child.db' });
44
+ * const { tools } = await createMCPBridge({ config: cfg });
39
45
  */
40
46
  function liteCtxMcpBridgeConfig(opts) {
41
47
  if (!opts || typeof opts.root !== 'string' || !opts.root) {
package/tools/mobile.d.ts CHANGED
@@ -23,6 +23,11 @@ export type MobilePage = any;
23
23
  * @param {string} [opts.device] - Device serial or 'auto'
24
24
  * @param {boolean} [opts.termux] - Use Termux ADB on-device mode
25
25
  * @returns {Promise<{tools: ToolDef[], close: Function}|null>}
26
+ * @when you want to give an agent Android/iOS device control (tap, type, snapshot) via baremobile
27
+ * @fails returns null if baremobile (optional dep) is not installed; otherwise returns {tools, close} — call close() to disconnect.
28
+ * @example
29
+ * const m = await createMobileTools({ platform: 'android' });
30
+ * const loop = new Loop({ provider, tools: m.tools });
26
31
  */
27
32
  export function createMobileTools(opts?: {
28
33
  platform?: string | undefined;
package/tools/mobile.js CHANGED
@@ -21,6 +21,11 @@
21
21
  * @param {string} [opts.device] - Device serial or 'auto'
22
22
  * @param {boolean} [opts.termux] - Use Termux ADB on-device mode
23
23
  * @returns {Promise<{tools: ToolDef[], close: Function}|null>}
24
+ * @when you want to give an agent Android/iOS device control (tap, type, snapshot) via baremobile
25
+ * @fails returns null if baremobile (optional dep) is not installed; otherwise returns {tools, close} — call close() to disconnect.
26
+ * @example
27
+ * const m = await createMobileTools({ platform: 'android' });
28
+ * const loop = new Loop({ provider, tools: m.tools });
24
29
  */
25
30
  async function createMobileTools(opts = {}) {
26
31
  const platform = opts.platform || 'android';
package/tools/shell.d.ts CHANGED
@@ -41,6 +41,11 @@ type ToolDef = import("../types").ToolDef;
41
41
  * gating is the caller's responsibility via `new Loop({ policy })`.
42
42
  *
43
43
  * @returns {{tools: ToolDef[]}}
44
+ * @when you want to give an agent shell/file tools (read, grep, write, edit, run, exec) — cross-platform, pure Node, zero deps
45
+ * @fails never throws at creation; gating is the caller's via Loop({ policy }) and fs.writeScope, and shell_edit refuses a non-unique anchor as a tool result (file untouched).
46
+ * @example
47
+ * const { tools } = createShellTools();
48
+ * const loop = new Loop({ provider, tools, policy });
44
49
  */
45
50
  declare function createShellTools(): {
46
51
  tools: ToolDef[];
package/tools/shell.js CHANGED
@@ -499,6 +499,11 @@ function execCommand({ command, cwd, timeout, maxBuffer, env }) {
499
499
  * gating is the caller's responsibility via `new Loop({ policy })`.
500
500
  *
501
501
  * @returns {{tools: ToolDef[]}}
502
+ * @when you want to give an agent shell/file tools (read, grep, write, edit, run, exec) — cross-platform, pure Node, zero deps
503
+ * @fails never throws at creation; gating is the caller's via Loop({ policy }) and fs.writeScope, and shell_edit refuses a non-unique anchor as a tool result (file untouched).
504
+ * @example
505
+ * const { tools } = createShellTools();
506
+ * const loop = new Loop({ provider, tools, policy });
502
507
  */
503
508
  function createShellTools() {
504
509
  /** @type {ToolDef[]} */
package/tools/spawn.d.ts CHANGED
@@ -68,6 +68,11 @@ export type Stream = import("../src/stream").Stream;
68
68
  * (heartbeat watchdog; default off). Resets on every line, so slow-but-working children survive.
69
69
  * @param {Stream} [options.stream] - bareagent Stream instance — child:stderr events get re-emitted here.
70
70
  * @returns {{tool: import('../types').ToolDef, spawnChild: typeof spawnChild}}
71
+ * @when you want an LLM-callable spawn tool so a model can fork child bareagents itself — governed per-family by bareguard
72
+ * @fails returns {tool, spawnChild}; the tool blocks per child and child stderr is re-emitted as child:stderr on the wired Stream.
73
+ * @example
74
+ * const { tool } = createSpawnTool();
75
+ * const loop = new Loop({ provider, tools: [tool] });
71
76
  */
72
77
  export function createSpawnTool(options?: {
73
78
  cliPath?: string | undefined;
@@ -104,6 +109,11 @@ export function createSpawnTool(options?: {
104
109
  * @property {Stream} [stream] - bareagent Stream — child:stderr events get re-emitted here.
105
110
  *
106
111
  * @param {SpawnChildOptions} [opts]
112
+ * @when you want to fork a child bareagent process programmatically and get a handle — heavyweight delegation, not the in-process recurse default
113
+ * @fails bounded by timeoutMs (wall-clock) and opt-in idleTimeoutMs (heartbeat); the result carries idleKilled if the watchdog fired. Threads BAREGUARD env vars to the child.
114
+ * @example
115
+ * const handle = spawnChild({ config, input });
116
+ * const result = await handle.wait();
107
117
  */
108
118
  export function spawnChild({ config, input, cliPath, timeoutMs, idleTimeoutMs, stream }?: SpawnChildOptions): {
109
119
  wait: () => Promise<{
package/tools/spawn.js CHANGED
@@ -74,6 +74,11 @@ function resolveCliPath() {
74
74
  * @property {Stream} [stream] - bareagent Stream — child:stderr events get re-emitted here.
75
75
  *
76
76
  * @param {SpawnChildOptions} [opts]
77
+ * @when you want to fork a child bareagent process programmatically and get a handle — heavyweight delegation, not the in-process recurse default
78
+ * @fails bounded by timeoutMs (wall-clock) and opt-in idleTimeoutMs (heartbeat); the result carries idleKilled if the watchdog fired. Threads BAREGUARD env vars to the child.
79
+ * @example
80
+ * const handle = spawnChild({ config, input });
81
+ * const result = await handle.wait();
77
82
  */
78
83
  function spawnChild({ config, input, cliPath, timeoutMs, idleTimeoutMs, stream } = {}) {
79
84
  if (typeof config !== 'string' || !config) {
@@ -257,6 +262,11 @@ function spawnChild({ config, input, cliPath, timeoutMs, idleTimeoutMs, stream }
257
262
  * (heartbeat watchdog; default off). Resets on every line, so slow-but-working children survive.
258
263
  * @param {Stream} [options.stream] - bareagent Stream instance — child:stderr events get re-emitted here.
259
264
  * @returns {{tool: import('../types').ToolDef, spawnChild: typeof spawnChild}}
265
+ * @when you want an LLM-callable spawn tool so a model can fork child bareagents itself — governed per-family by bareguard
266
+ * @fails returns {tool, spawnChild}; the tool blocks per child and child stderr is re-emitted as child:stderr on the wired Stream.
267
+ * @example
268
+ * const { tool } = createSpawnTool();
269
+ * const loop = new Loop({ provider, tools: [tool] });
260
270
  */
261
271
  function createSpawnTool(options = {}) {
262
272
  const tool = {