@noetic-tools/core 0.0.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 (207) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +38 -0
  3. package/dist/adapters/in-memory-fs-adapter.d.ts +3 -0
  4. package/dist/adapters/in-memory-fs-adapter.js +245 -0
  5. package/dist/adapters/in-memory-shell-adapter.d.ts +9 -0
  6. package/dist/adapters/in-memory-shell-adapter.js +20 -0
  7. package/dist/adapters/in-memory-subprocess-adapter.d.ts +5 -0
  8. package/dist/adapters/in-memory-subprocess-adapter.js +126 -0
  9. package/dist/adapters/local-fs-adapter.d.ts +3 -0
  10. package/dist/adapters/local-fs-adapter.js +43 -0
  11. package/dist/adapters/local-shell-adapter.d.ts +51 -0
  12. package/dist/adapters/local-shell-adapter.js +167 -0
  13. package/dist/adapters/local-subprocess-adapter.d.ts +16 -0
  14. package/dist/adapters/local-subprocess-adapter.js +187 -0
  15. package/dist/adapters/openrouter.d.ts +57 -0
  16. package/dist/adapters/openrouter.js +248 -0
  17. package/dist/builders/channel-builder.d.ts +36 -0
  18. package/dist/builders/channel-builder.js +15 -0
  19. package/dist/builders/control-flow-builders.d.ts +79 -0
  20. package/dist/builders/control-flow-builders.js +53 -0
  21. package/dist/builders/every.d.ts +45 -0
  22. package/dist/builders/every.js +60 -0
  23. package/dist/builders/layer-provides-builders.d.ts +32 -0
  24. package/dist/builders/layer-provides-builders.js +33 -0
  25. package/dist/builders/loop-builder.d.ts +23 -0
  26. package/dist/builders/loop-builder.js +46 -0
  27. package/dist/builders/memory-builder.d.ts +11 -0
  28. package/dist/builders/memory-builder.js +15 -0
  29. package/dist/builders/provide-builder.d.ts +20 -0
  30. package/dist/builders/provide-builder.js +34 -0
  31. package/dist/builders/spawn-builder.d.ts +20 -0
  32. package/dist/builders/spawn-builder.js +33 -0
  33. package/dist/builders/step-builders.d.ts +62 -0
  34. package/dist/builders/step-builders.js +99 -0
  35. package/dist/builders/tool-builder.d.ts +52 -0
  36. package/dist/builders/tool-builder.js +59 -0
  37. package/dist/conditions/conditions.d.ts +114 -0
  38. package/dist/conditions/conditions.js +271 -0
  39. package/dist/conditions/cosine-similarity.d.ts +11 -0
  40. package/dist/conditions/cosine-similarity.js +28 -0
  41. package/dist/conditions/index.d.ts +3 -0
  42. package/dist/conditions/index.js +2 -0
  43. package/dist/errors/noetic-config-error.d.ts +41 -0
  44. package/dist/errors/noetic-config-error.js +44 -0
  45. package/dist/errors/noetic-error.d.ts +18 -0
  46. package/dist/errors/noetic-error.js +52 -0
  47. package/dist/index.d.ts +152 -0
  48. package/dist/index.js +112 -0
  49. package/dist/internal-test.d.ts +11 -0
  50. package/dist/internal-test.js +11 -0
  51. package/dist/interpreter/clone-guard.d.ts +4 -0
  52. package/dist/interpreter/clone-guard.js +18 -0
  53. package/dist/interpreter/collect-tools.d.ts +12 -0
  54. package/dist/interpreter/collect-tools.js +70 -0
  55. package/dist/interpreter/execute-branch.d.ts +3 -0
  56. package/dist/interpreter/execute-branch.js +10 -0
  57. package/dist/interpreter/execute-every.d.ts +15 -0
  58. package/dist/interpreter/execute-every.js +143 -0
  59. package/dist/interpreter/execute-fork.d.ts +3 -0
  60. package/dist/interpreter/execute-fork.js +215 -0
  61. package/dist/interpreter/execute-llm.d.ts +4 -0
  62. package/dist/interpreter/execute-llm.js +217 -0
  63. package/dist/interpreter/execute-loop.d.ts +3 -0
  64. package/dist/interpreter/execute-loop.js +171 -0
  65. package/dist/interpreter/execute-provide.d.ts +10 -0
  66. package/dist/interpreter/execute-provide.js +64 -0
  67. package/dist/interpreter/execute-run.d.ts +3 -0
  68. package/dist/interpreter/execute-run.js +39 -0
  69. package/dist/interpreter/execute-spawn.d.ts +11 -0
  70. package/dist/interpreter/execute-spawn.js +113 -0
  71. package/dist/interpreter/execute-tool.d.ts +5 -0
  72. package/dist/interpreter/execute-tool.js +81 -0
  73. package/dist/interpreter/execute.d.ts +14 -0
  74. package/dist/interpreter/execute.js +119 -0
  75. package/dist/interpreter/framework-cast.d.ts +10 -0
  76. package/dist/interpreter/framework-cast.js +16 -0
  77. package/dist/interpreter/message-helpers.d.ts +9 -0
  78. package/dist/interpreter/message-helpers.js +42 -0
  79. package/dist/interpreter/typeguards.d.ts +25 -0
  80. package/dist/interpreter/typeguards.js +50 -0
  81. package/dist/memory/budget.d.ts +23 -0
  82. package/dist/memory/budget.js +117 -0
  83. package/dist/memory/function-call-utils.d.ts +6 -0
  84. package/dist/memory/function-call-utils.js +25 -0
  85. package/dist/memory/layer-api.d.ts +14 -0
  86. package/dist/memory/layer-api.js +91 -0
  87. package/dist/memory/layer-lifecycle.d.ts +160 -0
  88. package/dist/memory/layer-lifecycle.js +552 -0
  89. package/dist/memory/layer-usage.d.ts +15 -0
  90. package/dist/memory/layer-usage.js +48 -0
  91. package/dist/memory/layers/durable-task-state.d.ts +79 -0
  92. package/dist/memory/layers/durable-task-state.js +118 -0
  93. package/dist/memory/layers/file-reference.d.ts +55 -0
  94. package/dist/memory/layers/file-reference.js +538 -0
  95. package/dist/memory/layers/history-window.d.ts +29 -0
  96. package/dist/memory/layers/history-window.js +114 -0
  97. package/dist/memory/layers/observational-memory.d.ts +53 -0
  98. package/dist/memory/layers/observational-memory.js +110 -0
  99. package/dist/memory/layers/plan.d.ts +55 -0
  100. package/dist/memory/layers/plan.js +369 -0
  101. package/dist/memory/layers/static-content.d.ts +27 -0
  102. package/dist/memory/layers/static-content.js +35 -0
  103. package/dist/memory/layers/steering.d.ts +51 -0
  104. package/dist/memory/layers/steering.js +258 -0
  105. package/dist/memory/layers/tool-memory-layer.d.ts +16 -0
  106. package/dist/memory/layers/tool-memory-layer.js +43 -0
  107. package/dist/memory/layers/working-memory.d.ts +44 -0
  108. package/dist/memory/layers/working-memory.js +92 -0
  109. package/dist/memory/projector.d.ts +10 -0
  110. package/dist/memory/projector.js +19 -0
  111. package/dist/memory/scope.d.ts +3 -0
  112. package/dist/memory/scope.js +31 -0
  113. package/dist/memory/strip-unresolved.d.ts +13 -0
  114. package/dist/memory/strip-unresolved.js +35 -0
  115. package/dist/observability/genai-attributes.d.ts +11 -0
  116. package/dist/observability/genai-attributes.js +12 -0
  117. package/dist/observability/span-impl.d.ts +20 -0
  118. package/dist/observability/span-impl.js +33 -0
  119. package/dist/observability/trace-exporter.d.ts +15 -0
  120. package/dist/observability/trace-exporter.js +26 -0
  121. package/dist/patterns/flow.d.ts +52 -0
  122. package/dist/patterns/flow.js +103 -0
  123. package/dist/patterns/interview.d.ts +53 -0
  124. package/dist/patterns/interview.js +113 -0
  125. package/dist/patterns/plans.d.ts +45 -0
  126. package/dist/patterns/plans.js +125 -0
  127. package/dist/patterns/ralph-wiggum.d.ts +20 -0
  128. package/dist/patterns/ralph-wiggum.js +37 -0
  129. package/dist/patterns/react.d.ts +18 -0
  130. package/dist/patterns/react.js +39 -0
  131. package/dist/portable.d.ts +26 -0
  132. package/dist/portable.js +34 -0
  133. package/dist/runtime/agent-harness.d.ts +206 -0
  134. package/dist/runtime/agent-harness.js +1170 -0
  135. package/dist/runtime/broadcaster-utils.d.ts +30 -0
  136. package/dist/runtime/broadcaster-utils.js +53 -0
  137. package/dist/runtime/channel-store.d.ts +18 -0
  138. package/dist/runtime/channel-store.js +187 -0
  139. package/dist/runtime/context-impl.d.ts +80 -0
  140. package/dist/runtime/context-impl.js +140 -0
  141. package/dist/runtime/cwd-helpers.d.ts +42 -0
  142. package/dist/runtime/cwd-helpers.js +68 -0
  143. package/dist/runtime/detached-handle.d.ts +14 -0
  144. package/dist/runtime/detached-handle.js +56 -0
  145. package/dist/runtime/event-broadcaster.d.ts +61 -0
  146. package/dist/runtime/event-broadcaster.js +187 -0
  147. package/dist/runtime/exec-context-factory.d.ts +25 -0
  148. package/dist/runtime/exec-context-factory.js +30 -0
  149. package/dist/runtime/in-memory-storage.d.ts +9 -0
  150. package/dist/runtime/in-memory-storage.js +33 -0
  151. package/dist/runtime/item-log-impl.d.ts +11 -0
  152. package/dist/runtime/item-log-impl.js +25 -0
  153. package/dist/runtime/message-queue.d.ts +30 -0
  154. package/dist/runtime/message-queue.js +46 -0
  155. package/dist/runtime/session-runner.d.ts +77 -0
  156. package/dist/runtime/session-runner.js +253 -0
  157. package/dist/runtime/session-streams.d.ts +11 -0
  158. package/dist/runtime/session-streams.js +204 -0
  159. package/dist/runtime/tool-memory.d.ts +6 -0
  160. package/dist/runtime/tool-memory.js +22 -0
  161. package/dist/schemas/item.d.ts +35 -0
  162. package/dist/schemas/item.js +155 -0
  163. package/dist/types/channel.d.ts +29 -0
  164. package/dist/types/channel.js +1 -0
  165. package/dist/types/common.d.ts +111 -0
  166. package/dist/types/common.js +1 -0
  167. package/dist/types/context.d.ts +93 -0
  168. package/dist/types/context.js +1 -0
  169. package/dist/types/detached.d.ts +17 -0
  170. package/dist/types/detached.js +7 -0
  171. package/dist/types/embed.d.ts +5 -0
  172. package/dist/types/embed.js +1 -0
  173. package/dist/types/error.d.ts +51 -0
  174. package/dist/types/error.js +1 -0
  175. package/dist/types/fs-adapter.d.ts +51 -0
  176. package/dist/types/fs-adapter.js +3 -0
  177. package/dist/types/harness-result.d.ts +43 -0
  178. package/dist/types/harness-result.js +2 -0
  179. package/dist/types/items.d.ts +115 -0
  180. package/dist/types/items.js +2 -0
  181. package/dist/types/memory.d.ts +336 -0
  182. package/dist/types/memory.js +13 -0
  183. package/dist/types/mutable-context.d.ts +13 -0
  184. package/dist/types/mutable-context.js +1 -0
  185. package/dist/types/observability.d.ts +30 -0
  186. package/dist/types/observability.js +1 -0
  187. package/dist/types/runtime.d.ts +255 -0
  188. package/dist/types/runtime.js +1 -0
  189. package/dist/types/shell-adapter.d.ts +34 -0
  190. package/dist/types/shell-adapter.js +10 -0
  191. package/dist/types/steering.d.ts +89 -0
  192. package/dist/types/steering.js +14 -0
  193. package/dist/types/step.d.ts +206 -0
  194. package/dist/types/step.js +1 -0
  195. package/dist/types/subprocess-adapter.d.ts +41 -0
  196. package/dist/types/subprocess-adapter.js +1 -0
  197. package/dist/types/tool-context.d.ts +34 -0
  198. package/dist/types/tool-context.js +1 -0
  199. package/dist/unstable.d.ts +28 -0
  200. package/dist/unstable.js +24 -0
  201. package/dist/until/combinators.d.ts +17 -0
  202. package/dist/until/combinators.js +49 -0
  203. package/dist/until/never.d.ts +9 -0
  204. package/dist/until/never.js +12 -0
  205. package/dist/until/predicates.d.ts +43 -0
  206. package/dist/until/predicates.js +126 -0
  207. package/package.json +81 -0
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Prefix used by ShellAdapter implementations to signal a timeout-induced
3
+ * kill via the Error.message channel. Format: `${TIMEOUT_ERROR_PREFIX}${seconds}`.
4
+ * Callers parse the seconds back out of `error.message`.
5
+ *
6
+ * @public
7
+ */
8
+ export declare const TIMEOUT_ERROR_PREFIX = "timeout:";
9
+ /** @public Options for a single shell command execution. */
10
+ export interface ShellExecOptions {
11
+ /** Working directory for the command. */
12
+ cwd: string;
13
+ /** Environment variables (merged with process defaults for local, used directly for emulated). */
14
+ env?: Record<string, string>;
15
+ /** Timeout in seconds. */
16
+ timeout?: number;
17
+ /** Standard input to pipe into the command. */
18
+ stdin?: string;
19
+ /** Abort signal for cancellation support. */
20
+ signal?: AbortSignal;
21
+ /** Streaming callback invoked as output data arrives. */
22
+ onData?: (data: Buffer) => void;
23
+ }
24
+ /** @public Result of a shell command execution. */
25
+ export interface ShellExecResult {
26
+ stdout: string;
27
+ stderr: string;
28
+ exitCode: number | null;
29
+ }
30
+ /** @public Shell execution abstraction for agent runtime operations. */
31
+ export interface ShellAdapter {
32
+ /** Execute a shell command string and return its result. */
33
+ exec(command: string, options: ShellExecOptions): Promise<ShellExecResult>;
34
+ }
@@ -0,0 +1,10 @@
1
+ //#region Constants
2
+ /**
3
+ * Prefix used by ShellAdapter implementations to signal a timeout-induced
4
+ * kill via the Error.message channel. Format: `${TIMEOUT_ERROR_PREFIX}${seconds}`.
5
+ * Callers parse the seconds back out of `error.message`.
6
+ *
7
+ * @public
8
+ */
9
+ export const TIMEOUT_ERROR_PREFIX = 'timeout:';
10
+ //#endregion
@@ -0,0 +1,89 @@
1
+ import type { LLMResponse } from './common';
2
+ import type { ExecutionContext, MemoryScope } from './memory';
3
+ /** @public Enumeration of actions a steering rule can take on a tool call or model response. */
4
+ export declare const SteeringAction: {
5
+ Allow: string;
6
+ Deny: string;
7
+ Guide: string;
8
+ };
9
+ export type SteeringAction = (typeof SteeringAction)[keyof typeof SteeringAction];
10
+ /** @public Discriminator for ledger entry types recorded during steering evaluation. */
11
+ export declare const LedgerEntryKind: {
12
+ ToolCall: string;
13
+ ModelTurn: string;
14
+ Custom: string;
15
+ };
16
+ export type LedgerEntryKind = (typeof LedgerEntryKind)[keyof typeof LedgerEntryKind];
17
+ /** @public Result of evaluating steering rules: an action and optional guidance message. */
18
+ export interface SteeringDecision {
19
+ action: SteeringAction;
20
+ guidance?: string;
21
+ }
22
+ /** @public A single entry in the steering ledger, recording a tool call, model turn, or custom event. */
23
+ export interface LedgerEntry {
24
+ kind: LedgerEntryKind;
25
+ timestamp: number;
26
+ toolName?: string;
27
+ toolArgs?: unknown;
28
+ success?: boolean;
29
+ durationMs?: number;
30
+ model?: string;
31
+ tokenUsage?: {
32
+ input: number;
33
+ output: number;
34
+ };
35
+ custom?: Record<string, unknown>;
36
+ ruleId?: string;
37
+ action?: SteeringAction;
38
+ guidance?: string;
39
+ }
40
+ /** @public Parameters passed to a steering rule's `beforeToolCall` evaluation. */
41
+ export interface BeforeToolCallParams<TState = unknown> {
42
+ toolName: string;
43
+ toolArgs: unknown;
44
+ ctx: ExecutionContext;
45
+ state: TState;
46
+ }
47
+ /** @public Value returned by a `beforeToolCall` steering hook with a decision and optional state update. */
48
+ export interface BeforeToolCallResult<TState = unknown> {
49
+ decision: SteeringDecision;
50
+ state?: TState;
51
+ }
52
+ /** @public Parameters passed to a steering rule's `afterModelCall` evaluation. */
53
+ export interface AfterModelCallParams<TState = unknown> {
54
+ response: LLMResponse;
55
+ ctx: ExecutionContext;
56
+ state: TState;
57
+ }
58
+ /** @public Value returned by an `afterModelCall` steering hook with a decision and optional state update. */
59
+ export interface AfterModelCallResult<TState = unknown> {
60
+ decision: SteeringDecision;
61
+ state?: TState;
62
+ }
63
+ /** @public A named rule evaluated by the steering layer before tool calls or after model responses. */
64
+ export interface SteeringRule {
65
+ id: string;
66
+ name?: string;
67
+ appliesTo: ('beforeToolCall' | 'afterModelCall')[];
68
+ predicate?: (params: BeforeToolCallParams | AfterModelCallParams) => SteeringDecision;
69
+ llmEval?: {
70
+ mode: 'sync' | 'async';
71
+ prompt: string;
72
+ model?: string;
73
+ };
74
+ }
75
+ /** @public Top-level configuration for the steering subsystem, including rules and limits. */
76
+ export interface SteeringConfig {
77
+ rules: SteeringRule[];
78
+ maxLedgerEntries?: number;
79
+ maxRetries?: number;
80
+ scope?: MemoryScope;
81
+ }
82
+ /** @public Mutable runtime state maintained by the steering layer across an execution. */
83
+ export interface SteeringState {
84
+ ledger: LedgerEntry[];
85
+ pendingAsync: Array<{
86
+ ruleId: string;
87
+ guidance: string;
88
+ }>;
89
+ }
@@ -0,0 +1,14 @@
1
+ //#region Enums
2
+ /** @public Enumeration of actions a steering rule can take on a tool call or model response. */
3
+ export const SteeringAction = {
4
+ Allow: 'allow',
5
+ Deny: 'deny',
6
+ Guide: 'guide',
7
+ };
8
+ /** @public Discriminator for ledger entry types recorded during steering evaluation. */
9
+ export const LedgerEntryKind = {
10
+ ToolCall: 'tool_call',
11
+ ModelTurn: 'model_turn',
12
+ Custom: 'custom',
13
+ };
14
+ //#endregion
@@ -0,0 +1,206 @@
1
+ import type { ZodType } from 'zod';
2
+ import type { Channel } from './channel';
3
+ import type { ModelParams, RetryPolicy, StepMeta, Tool } from './common';
4
+ import type { Context } from './context';
5
+ import type { NoeticError } from './error';
6
+ import type { ContextMemory, MemoryConfig, MemoryLayer } from './memory';
7
+ /**
8
+ * Cumulative execution snapshot passed to loop `until` predicates.
9
+ * @public
10
+ */
11
+ export interface Snapshot {
12
+ /** Number of loop iterations completed so far. */
13
+ stepCount: number;
14
+ /** Aggregate token usage across all iterations. */
15
+ tokens: {
16
+ input: number;
17
+ output: number;
18
+ total: number;
19
+ };
20
+ /** Wall-clock time in ms since the loop started. */
21
+ elapsed: number;
22
+ /** Cumulative cost across all iterations. */
23
+ cost: number;
24
+ /** Raw output of the most recent iteration. */
25
+ lastOutput: unknown;
26
+ /** Stringified text of the most recent iteration output. */
27
+ lastText: string;
28
+ /** Array of all prior iteration outputs (bounded by `maxHistorySize`). */
29
+ history: unknown[];
30
+ /** Nesting depth of the current execution context. */
31
+ depth: number;
32
+ /** Metadata from the most recent step execution (token usage, tool calls, etc.). */
33
+ lastStepMeta?: StepMeta | null;
34
+ }
35
+ /**
36
+ * Decision returned by a loop `until` predicate.
37
+ * @public
38
+ */
39
+ export interface Verdict {
40
+ /** When true, the loop terminates after this iteration. */
41
+ stop: boolean;
42
+ /** Human-readable explanation of why the loop stopped (logged in traces). */
43
+ reason?: string;
44
+ /** Feedback string injected into the next iteration's context (ignored when `stop` is true). */
45
+ feedback?: string;
46
+ }
47
+ /** @public Predicate function evaluated after each loop iteration to decide whether to stop. */
48
+ export type Until = (snapshot: Snapshot) => Verdict | Promise<Verdict>;
49
+ /**
50
+ * Outcome of a single path in a `settle`-mode fork (mirrors `Promise.allSettled`).
51
+ * @public
52
+ */
53
+ export interface SettleResult<O> {
54
+ /** Id of the step that produced this result. */
55
+ stepId: string;
56
+ /** Whether the path completed successfully or threw. */
57
+ status: 'fulfilled' | 'rejected';
58
+ /** The path's return value (present when `status` is `'fulfilled'`). */
59
+ value?: O;
60
+ /** The error that caused rejection (present when `status` is `'rejected'`). */
61
+ error?: NoeticError;
62
+ }
63
+ /** @public Discriminated union of all step kinds that can be composed into an execution tree. */
64
+ export type Step<TMemory = ContextMemory, I = unknown, O = unknown> = StepRun<TMemory, I, O> | StepLLM<TMemory, I, O> | StepTool<TMemory, I, O> | StepBranch<TMemory, I, O> | StepFork<TMemory, I, O> | StepSpawn<TMemory, I, O> | StepProvide<TMemory, I, O> | StepLoop<TMemory, I, O> | StepEvery<TMemory, I, O>;
65
+ /** @public A step that executes arbitrary async logic via a user-supplied function. */
66
+ export interface StepRun<TMemory = ContextMemory, I = unknown, O = unknown> {
67
+ kind: 'run';
68
+ id: string;
69
+ execute: (input: I, ctx: Context<TMemory>) => Promise<O>;
70
+ retry?: RetryPolicy;
71
+ }
72
+ /** @public A step that sends a prompt to a language model and returns its response. */
73
+ export interface StepLLM<_TMemory = ContextMemory, _I = unknown, O = unknown> {
74
+ kind: 'llm';
75
+ id: string;
76
+ model: string;
77
+ instructions?: string;
78
+ tools?: Tool[];
79
+ output?: ZodType<O>;
80
+ params?: ModelParams;
81
+ /** Controls framework event emission for this step. Defaults to `true`. Set `false` to suppress all framework events. A filter function receives `(eventType, data)` and returns `boolean`. */
82
+ emit?: boolean | ((eventType: string, data: Record<string, unknown>) => boolean);
83
+ }
84
+ /** @public A step that invokes a single tool directly, bypassing the LLM. */
85
+ export interface StepTool<_TMemory = ContextMemory, I = unknown, O = unknown> {
86
+ kind: 'tool';
87
+ id: string;
88
+ tool: Tool<ZodType<I>, ZodType<O>>;
89
+ args?: Partial<I>;
90
+ }
91
+ /** @public A step that dynamically selects and executes one of several possible sub-steps. */
92
+ export interface StepBranch<TMemory = ContextMemory, I = unknown, O = unknown> {
93
+ kind: 'branch';
94
+ id: string;
95
+ route: (input: I, ctx: Context<TMemory>) => Step<TMemory, I, O> | null | Promise<Step<TMemory, I, O> | null>;
96
+ _optimizable?: Step<TMemory>[];
97
+ }
98
+ /** @public Union of fork step variants (`race`, `all`, `settle`) for concurrent path execution. */
99
+ export type StepFork<TMemory = ContextMemory, I = unknown, O = unknown> = StepForkRace<TMemory, I, O> | StepForkAll<TMemory, I, O> | StepForkSettle<TMemory, I, O>;
100
+ /** @public A fork step that returns the result of the first path to complete. */
101
+ export interface StepForkRace<TMemory = ContextMemory, I = unknown, O = unknown> {
102
+ kind: 'fork';
103
+ id: string;
104
+ mode: 'race';
105
+ paths: (input: I, ctx: Context<TMemory>) => Step<TMemory, I, O>[];
106
+ concurrency?: number;
107
+ _optimizable?: Step<TMemory>[];
108
+ }
109
+ /** @public A fork step that runs all paths and merges their results. */
110
+ export interface StepForkAll<TMemory = ContextMemory, I = unknown, O = unknown> {
111
+ kind: 'fork';
112
+ id: string;
113
+ mode: 'all';
114
+ paths: (input: I, ctx: Context<TMemory>) => Step<TMemory, I, O>[];
115
+ merge: (results: O[], ctx: Context<TMemory>) => O;
116
+ concurrency?: number;
117
+ _optimizable?: Step<TMemory>[];
118
+ }
119
+ /** @public A fork step that runs all paths and collects fulfilled/rejected outcomes. */
120
+ export interface StepForkSettle<TMemory = ContextMemory, I = unknown, O = unknown> {
121
+ kind: 'fork';
122
+ id: string;
123
+ mode: 'settle';
124
+ paths: (input: I, ctx: Context<TMemory>) => Step<TMemory, I, O>[];
125
+ merge: (results: SettleResult<O>[], ctx: Context<TMemory>) => O;
126
+ concurrency?: number;
127
+ _optimizable?: Step<TMemory>[];
128
+ }
129
+ /**
130
+ * A step that provides memory layers to its child without creating an isolated context.
131
+ * Like React's Context.Provider — layers are available to all descendant steps.
132
+ * Spawn and detachedSpawn break the inheritance chain.
133
+ * @public
134
+ */
135
+ export interface StepProvide<TMemory = ContextMemory, I = unknown, O = unknown> {
136
+ kind: 'provide';
137
+ id: string;
138
+ child: Step<TMemory, I, O>;
139
+ memory: MemoryConfig | MemoryLayer[];
140
+ }
141
+ /** @public A step that launches a child execution with its own memory scope. */
142
+ export interface StepSpawn<TMemory = ContextMemory, I = unknown, O = unknown> {
143
+ kind: 'spawn';
144
+ id: string;
145
+ child: Step<TMemory, I, O>;
146
+ memory?: MemoryConfig | MemoryLayer[];
147
+ timeout?: number;
148
+ }
149
+ /**
150
+ * A loop step that iterates a body step until a termination predicate is satisfied.
151
+ * @public
152
+ */
153
+ export interface StepLoop<TMemory = ContextMemory, I = unknown, O = unknown> {
154
+ kind: 'loop';
155
+ /** Unique step identifier used in traces and error messages. */
156
+ id: string;
157
+ /** Steps to execute sequentially on each iteration. */
158
+ steps: ReadonlyArray<Step<TMemory, I, O>>;
159
+ /** Termination predicate evaluated after each iteration with a cumulative snapshot. */
160
+ until: Until;
161
+ /** Hard safety cap on iterations (default: 1000). */
162
+ maxIterations?: number;
163
+ /** Maximum number of entries kept in the snapshot history array. */
164
+ maxHistorySize?: number;
165
+ /** Optional channel for injecting messages into the loop mid-execution. */
166
+ inbox?: Channel<string>;
167
+ /** Ms to wait on inbox before the loop parks itself (default: 0 = no parking). */
168
+ parkTimeout?: number;
169
+ /** Transforms the previous iteration's output into the next iteration's input. */
170
+ prepareNext?: (output: O, verdict: Verdict, ctx: Context<TMemory>) => I;
171
+ /** Per-iteration error handler: retry the iteration, skip it, or abort the loop. */
172
+ onError?: (error: NoeticError, ctx: Context<TMemory>) => 'retry' | 'skip' | 'abort';
173
+ }
174
+ /**
175
+ * Error policy for the `every` operator when its body step throws.
176
+ * - `'continue'` (default): emit a span event recording the error and continue parking.
177
+ * - `'fail'`: re-throw, terminating the operator.
178
+ * @public
179
+ */
180
+ export type EveryErrorPolicy = 'continue' | 'fail';
181
+ /**
182
+ * A step that runs a body step on a fixed-interval schedule, optionally woken
183
+ * sooner by a wake channel. Runs forever until the executing context is cancelled.
184
+ *
185
+ * The operator output is `void` — `every` does not accumulate iteration outputs.
186
+ * The `O` type parameter exists only to anchor the body step's output type.
187
+ *
188
+ * @public
189
+ */
190
+ export interface StepEvery<TMemory = ContextMemory, I = unknown, O = unknown> {
191
+ kind: 'every';
192
+ /** Unique step identifier used in traces and error messages. */
193
+ id: string;
194
+ /** Body step executed on each iteration. */
195
+ step: Step<TMemory, I, O>;
196
+ /** Park duration between iterations in milliseconds. Must be >= 0. */
197
+ ms: number;
198
+ /** Optional channel that wakes the parking interval when any value arrives. */
199
+ wakeOn?: Channel<unknown>;
200
+ /** Behavior when `step` throws. Defaults to `'continue'`. */
201
+ onError?: EveryErrorPolicy;
202
+ /** Random jitter applied to the park duration in milliseconds. Must be >= 0. Default 0. */
203
+ jitter?: number;
204
+ }
205
+ /** @public Function signature used by the interpreter to recursively execute a step. */
206
+ export type ExecuteStepFn = <TMemory, I, O>(step: Step<TMemory, I, O>, input: I, ctx: Context<TMemory>) => Promise<O>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,41 @@
1
+ export type SubprocessStatus = 'starting' | 'running' | 'paused' | 'completed' | 'failed' | 'stopped' | 'stale';
2
+ export interface SubprocessRequest {
3
+ command: string;
4
+ args?: ReadonlyArray<string>;
5
+ cwd?: string;
6
+ env?: Record<string, string | undefined>;
7
+ detached?: boolean;
8
+ stdin?: string;
9
+ metadata?: Record<string, unknown>;
10
+ }
11
+ export interface SubprocessHandle {
12
+ id: string;
13
+ status: SubprocessStatus;
14
+ startedAt: string;
15
+ updatedAt?: string;
16
+ metadata?: Record<string, unknown>;
17
+ }
18
+ export type SubprocessControlResult = {
19
+ kind: 'ok';
20
+ handle: SubprocessHandle;
21
+ } | {
22
+ kind: 'unsupported';
23
+ handle: SubprocessHandle;
24
+ message: string;
25
+ } | {
26
+ kind: 'not_found';
27
+ handleId: string;
28
+ };
29
+ export interface SubprocessStopResult {
30
+ kind: 'stopped' | 'not_found';
31
+ handleId: string;
32
+ handle?: SubprocessHandle;
33
+ }
34
+ export interface SubprocessAdapter {
35
+ spawn(request: SubprocessRequest): Promise<SubprocessHandle>;
36
+ get(handleId: string): Promise<SubprocessHandle | null>;
37
+ stop(handleId: string, reason?: string): Promise<SubprocessStopResult>;
38
+ pause(handleId: string): Promise<SubprocessControlResult>;
39
+ resume(handleId: string): Promise<SubprocessControlResult>;
40
+ isAlive(handle: SubprocessHandle): Promise<boolean>;
41
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ import type { TurnContext } from '@openrouter/agent';
2
+ import type { StepMeta } from './common';
3
+ import type { Context } from './context';
4
+ import type { FsAdapter } from './fs-adapter';
5
+ import type { Item } from './items';
6
+ import type { AgentHarnessContract } from './runtime';
7
+ import type { ShellAdapter } from './shell-adapter';
8
+ /** @public Accessor for reading and writing per-layer state from within a tool execution. */
9
+ export interface ToolMemory {
10
+ get<T>(layerId: string): T | undefined;
11
+ set<T>(layerId: string, state: T): void;
12
+ }
13
+ /**
14
+ * Context provided to a tool's `execute` function at invocation time.
15
+ * @public
16
+ */
17
+ export interface ToolExecutionContext {
18
+ /** The current step execution context (access to item log, parent id, etc.). */
19
+ readonly ctx: Context;
20
+ /** The harness instance executing this tool. */
21
+ readonly harness: AgentHarnessContract;
22
+ /** Filesystem adapter for virtual or real filesystem access. */
23
+ readonly fs: FsAdapter;
24
+ /** Shell adapter for virtual or real shell command execution. */
25
+ readonly shell: ShellAdapter;
26
+ /** Per-layer memory accessor for reading/writing tool-specific state. */
27
+ readonly memory: ToolMemory;
28
+ /** The fully assembled conversation view at the point of tool invocation. */
29
+ readonly assembledView: ReadonlyArray<Item>;
30
+ /** Metadata from the most recent step execution (token usage, tool calls, etc.). */
31
+ readonly lastStepMeta: StepMeta | null;
32
+ /** OpenRouter turn context, when using the OpenRouter SDK adapter. */
33
+ readonly turnContext?: TurnContext;
34
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @unstable
3
+ * Unstable exports for framework extenders.
4
+ *
5
+ * Symbols exported from this module may change in any minor release.
6
+ * They are intended for authors of custom memory layers, runtime backends,
7
+ * and other framework extensions. Do not depend on them in application code.
8
+ */
9
+ /** @unstable Unsafe cast utility for bridging internal type boundaries. */
10
+ export { frameworkCast } from './interpreter/framework-cast';
11
+ /** @unstable Budget allocation algorithm for memory layer token budgets. */
12
+ export type { BudgetAllocation, BudgetLimits } from './memory/budget';
13
+ /** @unstable Budget allocation and checking utilities. */
14
+ export { allocateBudgets, checkBudget } from './memory/budget';
15
+ /** @unstable Layer state store type for managing per-layer state during execution. */
16
+ export type { LayerStateStore } from './memory/layer-lifecycle';
17
+ /** @unstable Factory for creating layer state stores. */
18
+ export { createLayerStateStore } from './memory/layer-lifecycle';
19
+ /** @unstable View assembly algorithm that converges memory layer outputs into the LLM context. */
20
+ export { assembleView } from './memory/projector';
21
+ /** @unstable Factory for creating scoped storage wrappers around a StorageAdapter. */
22
+ export { createScopedStorage } from './memory/scope';
23
+ /**
24
+ * @unstable Internal helper used by sync agent-spawn paths (worktree isolation)
25
+ * to seed a child's cwd snapshot without touching `previousCwd`. Not part of
26
+ * the public surface — call sites must hold exclusive use of the parent ctx.
27
+ */
28
+ export { retargetCwdForSpawn } from './runtime/cwd-helpers';
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @unstable
3
+ * Unstable exports for framework extenders.
4
+ *
5
+ * Symbols exported from this module may change in any minor release.
6
+ * They are intended for authors of custom memory layers, runtime backends,
7
+ * and other framework extensions. Do not depend on them in application code.
8
+ */
9
+ /** @unstable Unsafe cast utility for bridging internal type boundaries. */
10
+ export { frameworkCast } from './interpreter/framework-cast';
11
+ /** @unstable Budget allocation and checking utilities. */
12
+ export { allocateBudgets, checkBudget } from './memory/budget';
13
+ /** @unstable Factory for creating layer state stores. */
14
+ export { createLayerStateStore } from './memory/layer-lifecycle';
15
+ /** @unstable View assembly algorithm that converges memory layer outputs into the LLM context. */
16
+ export { assembleView } from './memory/projector';
17
+ /** @unstable Factory for creating scoped storage wrappers around a StorageAdapter. */
18
+ export { createScopedStorage } from './memory/scope';
19
+ /**
20
+ * @unstable Internal helper used by sync agent-spawn paths (worktree isolation)
21
+ * to seed a child's cwd snapshot without touching `previousCwd`. Not part of
22
+ * the public surface — call sites must hold exclusive use of the parent ctx.
23
+ */
24
+ export { retargetCwdForSpawn } from './runtime/cwd-helpers';
@@ -0,0 +1,17 @@
1
+ import type { Until } from '../types/step';
2
+ /**
3
+ * Combines predicates with OR semantics; stops the loop when any predicate says stop.
4
+ *
5
+ * @public
6
+ * @param predicates - Until predicates to evaluate.
7
+ * @returns A combined `Until` that short-circuits on the first stop verdict.
8
+ */
9
+ export declare function any(...predicates: Until[]): Until;
10
+ /**
11
+ * Combines predicates with AND semantics; stops the loop only when all predicates say stop.
12
+ *
13
+ * @public
14
+ * @param predicates - Until predicates to evaluate.
15
+ * @returns A combined `Until` that requires all predicates to be satisfied.
16
+ */
17
+ export declare function all(...predicates: Until[]): Until;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Combines predicates with OR semantics; stops the loop when any predicate says stop.
3
+ *
4
+ * @public
5
+ * @param predicates - Until predicates to evaluate.
6
+ * @returns A combined `Until` that short-circuits on the first stop verdict.
7
+ */
8
+ export function any(...predicates) {
9
+ return async (snapshot) => {
10
+ for (const pred of predicates) {
11
+ const verdict = await pred(snapshot);
12
+ if (verdict.stop) {
13
+ return verdict;
14
+ }
15
+ }
16
+ return {
17
+ stop: false,
18
+ };
19
+ };
20
+ }
21
+ /**
22
+ * Combines predicates with AND semantics; stops the loop only when all predicates say stop.
23
+ *
24
+ * @public
25
+ * @param predicates - Until predicates to evaluate.
26
+ * @returns A combined `Until` that requires all predicates to be satisfied.
27
+ */
28
+ export function all(...predicates) {
29
+ return async (snapshot) => {
30
+ const verdicts = [];
31
+ for (const pred of predicates) {
32
+ const verdict = await pred(snapshot);
33
+ verdicts.push(verdict);
34
+ if (!verdict.stop) {
35
+ return {
36
+ stop: false,
37
+ };
38
+ }
39
+ }
40
+ const reasons = verdicts
41
+ .map((v) => v.reason)
42
+ .filter(Boolean)
43
+ .join('; ');
44
+ return {
45
+ stop: true,
46
+ reason: reasons || 'All predicates satisfied',
47
+ };
48
+ };
49
+ }
@@ -0,0 +1,9 @@
1
+ import type { Until } from '../types/step';
2
+ /**
3
+ * Termination predicate that never stops the loop. Use with `every`-like
4
+ * forever-loops or with explicit cancellation paths.
5
+ *
6
+ * @public
7
+ * @returns An `Until` predicate that always returns `{ stop: false }`.
8
+ */
9
+ export declare function never(): Until;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Termination predicate that never stops the loop. Use with `every`-like
3
+ * forever-loops or with explicit cancellation paths.
4
+ *
5
+ * @public
6
+ * @returns An `Until` predicate that always returns `{ stop: false }`.
7
+ */
8
+ export function never() {
9
+ return () => ({
10
+ stop: false,
11
+ });
12
+ }
@@ -0,0 +1,43 @@
1
+ import type { EmbedFn } from '../types/embed';
2
+ import type { StorageAdapter } from '../types/memory';
3
+ import type { Until } from '../types/step';
4
+ import { never } from './never';
5
+ /** @public Async verification function that checks loop output and optionally returns feedback. */
6
+ export type VerifyFn = (output: unknown) => Promise<{
7
+ pass: boolean;
8
+ feedback?: string;
9
+ }>;
10
+ /** @public Configuration for the `converged` until predicate, supporting exact or embedding-based similarity. */
11
+ export interface ConvergeConfig {
12
+ /** Similarity threshold. Default 1 (exact match). When embed is provided and threshold < 1, uses cosine similarity. */
13
+ threshold?: number;
14
+ /** When provided with threshold < 1, enables embedding-based similarity comparison. */
15
+ embed?: EmbedFn;
16
+ /** Persist previous output vector across ephemeral invocations. */
17
+ cache?: StorageAdapter;
18
+ }
19
+ /**
20
+ * Namespace of built-in loop termination predicates.
21
+ *
22
+ * @public
23
+ */
24
+ export declare const until: {
25
+ /** Stops the loop after `n` steps. @public */
26
+ maxSteps(n: number): Until;
27
+ /** Stops the loop when accumulated cost reaches `usd`. @public */
28
+ maxCost(usd: number): Until;
29
+ /** Stops the loop when elapsed time reaches `ms` milliseconds. @public */
30
+ maxDuration(ms: number): Until;
31
+ /** Stops the loop when the last model response contains no tool calls. @public */
32
+ noToolCalls(): Until;
33
+ /** Never stops the loop — pairs with operators like `every` that rely on cancellation. @public */
34
+ never: typeof never;
35
+ /** Stops the loop when the verify function returns `{ pass: true }`. @public */
36
+ verified(fn: VerifyFn): Until;
37
+ /** Stops the loop when consecutive outputs are similar (exact equality or embedding cosine similarity). @public */
38
+ converged(opts: ConvergeConfig): Until;
39
+ /** Stops the loop when the last output text contains the given marker string. @public */
40
+ outputContains(marker: string): Until;
41
+ /** Wraps an arbitrary `Until` function as a named predicate. @public */
42
+ custom(fn: Until): Until;
43
+ };