@noetic-tools/core 0.2.1 → 0.3.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 (203) hide show
  1. package/dist/adapters/in-memory-fs-adapter.d.ts +1 -1
  2. package/dist/adapters/in-memory-fs-adapter.js +1 -1
  3. package/dist/adapters/in-memory-shell-adapter.d.ts +1 -1
  4. package/dist/adapters/in-memory-subprocess/manifest-persistence.d.ts +2 -2
  5. package/dist/adapters/in-memory-subprocess/metadata.d.ts +1 -1
  6. package/dist/adapters/in-memory-subprocess/types.d.ts +2 -2
  7. package/dist/adapters/in-memory-subprocess-adapter.d.ts +1 -1
  8. package/dist/adapters/openrouter.d.ts +2 -6
  9. package/dist/adapters/openrouter.js +1 -4
  10. package/dist/builders/channel-builder.d.ts +1 -1
  11. package/dist/builders/control-flow-builders.d.ts +2 -3
  12. package/dist/builders/control-flow-builders.js +1 -2
  13. package/dist/builders/every.d.ts +2 -3
  14. package/dist/builders/every.js +1 -1
  15. package/dist/builders/layer-provides-builders.d.ts +1 -1
  16. package/dist/builders/layer-provides-builders.js +1 -1
  17. package/dist/builders/loop-builder.d.ts +2 -2
  18. package/dist/builders/loop-builder.js +1 -1
  19. package/dist/builders/memory-builder.d.ts +1 -1
  20. package/dist/builders/memory-builder.js +1 -1
  21. package/dist/builders/provide-builder.d.ts +2 -2
  22. package/dist/builders/provide-builder.js +1 -1
  23. package/dist/builders/spawn-builder.d.ts +2 -3
  24. package/dist/builders/spawn-builder.js +1 -1
  25. package/dist/builders/step-builders.d.ts +2 -6
  26. package/dist/builders/step-builders.js +1 -1
  27. package/dist/builders/tool-builder.d.ts +1 -3
  28. package/dist/builders/tool-builder.js +1 -1
  29. package/dist/builders/workflow-hydrator.d.ts +2 -3
  30. package/dist/builders/workflow-hydrator.js +1 -2
  31. package/dist/conditions/conditions.d.ts +2 -3
  32. package/dist/conditions/conditions.js +1 -1
  33. package/dist/harness/agent-harness.d.ts +13 -3
  34. package/dist/harness/agent-harness.js +48 -5
  35. package/dist/harness/deps/memory.d.ts +2 -5
  36. package/dist/harness/deps/memory.js +1 -4
  37. package/dist/harness/deps/types.d.ts +3 -16
  38. package/dist/harness/deps/types.js +1 -1
  39. package/dist/harness/model-call.d.ts +1 -3
  40. package/dist/harness/model-call.js +1 -2
  41. package/dist/harness/model-schema.d.ts +2 -4
  42. package/dist/harness/model-schema.js +1 -1
  43. package/dist/index.d.ts +28 -49
  44. package/dist/index.js +9 -27
  45. package/dist/interpreter/action-deps.d.ts +4 -8
  46. package/dist/interpreter/action-deps.js +2 -6
  47. package/dist/interpreter/action-types.d.ts +3 -8
  48. package/dist/interpreter/action-types.js +1 -1
  49. package/dist/interpreter/collect-tools.d.ts +1 -2
  50. package/dist/interpreter/collect-tools.js +1 -1
  51. package/dist/interpreter/execute-action.js +104 -26
  52. package/dist/interpreter/execute-control.d.ts +1 -2
  53. package/dist/interpreter/execute-control.js +1 -3
  54. package/dist/interpreter/execute.d.ts +2 -3
  55. package/dist/interpreter/execute.js +1 -2
  56. package/dist/interpreter/message-helpers.d.ts +1 -1
  57. package/dist/interpreter/message-helpers.js +1 -1
  58. package/dist/interpreter/step-dispatcher.d.ts +2 -5
  59. package/dist/interpreter/typeguards.d.ts +3 -4
  60. package/dist/interpreter/typeguards.js +1 -1
  61. package/dist/observability/span-impl.d.ts +1 -1
  62. package/dist/observability/trace-exporter.d.ts +1 -1
  63. package/dist/patterns/dynamic-workflow.d.ts +2 -5
  64. package/dist/patterns/dynamic-workflow.js +1 -2
  65. package/dist/patterns/flow.d.ts +2 -2
  66. package/dist/patterns/flow.js +1 -1
  67. package/dist/patterns/interview.d.ts +2 -2
  68. package/dist/patterns/interview.js +1 -1
  69. package/dist/patterns/plans.d.ts +2 -3
  70. package/dist/patterns/plans.js +1 -1
  71. package/dist/patterns/ralph-wiggum.d.ts +2 -3
  72. package/dist/patterns/react.d.ts +2 -3
  73. package/dist/portable/memory-layers.d.ts +1 -7
  74. package/dist/portable/memory-layers.js +1 -7
  75. package/dist/portable.d.ts +2 -2
  76. package/dist/portable.js +2 -2
  77. package/dist/runtime/broadcaster-utils.d.ts +1 -1
  78. package/dist/runtime/channel-store.d.ts +1 -1
  79. package/dist/runtime/channel-store.js +1 -2
  80. package/dist/runtime/context-deps.d.ts +3 -3
  81. package/dist/runtime/context-deps.js +2 -2
  82. package/dist/runtime/context-type-deps.d.ts +2 -11
  83. package/dist/runtime/cwd-helpers.d.ts +1 -1
  84. package/dist/runtime/detached-handle.d.ts +2 -3
  85. package/dist/runtime/detached-handle.js +1 -3
  86. package/dist/runtime/durable/checkpoint-store.d.ts +1 -1
  87. package/dist/runtime/durable/checkpoint-store.js +1 -1
  88. package/dist/runtime/durable/harness-checkpoints.d.ts +2 -5
  89. package/dist/runtime/durable/runnable-loop.d.ts +1 -3
  90. package/dist/runtime/durable/session-seed.d.ts +1 -1
  91. package/dist/runtime/durable/stall-nudge.d.ts +1 -1
  92. package/dist/runtime/event-broadcaster.d.ts +1 -1
  93. package/dist/runtime/in-memory-storage.d.ts +1 -1
  94. package/dist/runtime/in-memory-storage.js +1 -1
  95. package/dist/runtime/item-log-impl.d.ts +1 -3
  96. package/dist/runtime/item-log-impl.js +1 -1
  97. package/dist/runtime/message-queue.d.ts +1 -2
  98. package/dist/runtime/session-runner.d.ts +1 -4
  99. package/dist/runtime/session-streams.d.ts +1 -2
  100. package/dist/runtime/session-streams.js +1 -1
  101. package/dist/runtime/step-registry.d.ts +2 -2
  102. package/dist/runtime/step-registry.js +1 -2
  103. package/dist/runtime/tool-memory.d.ts +1 -3
  104. package/dist/types/mutable-context.d.ts +2 -3
  105. package/dist/types/step-registrar.d.ts +1 -1
  106. package/dist/unstable.d.ts +5 -9
  107. package/dist/unstable.js +3 -6
  108. package/dist/until/combinators.d.ts +1 -1
  109. package/dist/until/never.d.ts +1 -1
  110. package/dist/until/predicates.d.ts +2 -2
  111. package/package.json +4 -2
  112. package/dist/errors/noetic-config-error.d.ts +0 -41
  113. package/dist/errors/noetic-config-error.js +0 -44
  114. package/dist/errors/noetic-error.d.ts +0 -18
  115. package/dist/errors/noetic-error.js +0 -54
  116. package/dist/memory/budget.d.ts +0 -23
  117. package/dist/memory/budget.js +0 -117
  118. package/dist/memory/exec-context-factory.d.ts +0 -25
  119. package/dist/memory/exec-context-factory.js +0 -30
  120. package/dist/memory/flow-schema.d.ts +0 -52
  121. package/dist/memory/flow-schema.js +0 -102
  122. package/dist/memory/function-call-utils.d.ts +0 -6
  123. package/dist/memory/function-call-utils.js +0 -27
  124. package/dist/memory/layer-api.d.ts +0 -14
  125. package/dist/memory/layer-api.js +0 -91
  126. package/dist/memory/layer-lifecycle.d.ts +0 -160
  127. package/dist/memory/layer-lifecycle.js +0 -552
  128. package/dist/memory/layer-provides.d.ts +0 -32
  129. package/dist/memory/layer-provides.js +0 -33
  130. package/dist/memory/layer-usage.d.ts +0 -16
  131. package/dist/memory/layer-usage.js +0 -54
  132. package/dist/memory/layers/durable-task-state.d.ts +0 -79
  133. package/dist/memory/layers/durable-task-state.js +0 -118
  134. package/dist/memory/layers/file-reference.d.ts +0 -55
  135. package/dist/memory/layers/file-reference.js +0 -594
  136. package/dist/memory/layers/history-window.d.ts +0 -29
  137. package/dist/memory/layers/history-window.js +0 -114
  138. package/dist/memory/layers/observational-memory.d.ts +0 -53
  139. package/dist/memory/layers/observational-memory.js +0 -109
  140. package/dist/memory/layers/plan.d.ts +0 -55
  141. package/dist/memory/layers/plan.js +0 -374
  142. package/dist/memory/layers/static-content.d.ts +0 -27
  143. package/dist/memory/layers/static-content.js +0 -35
  144. package/dist/memory/layers/steering.d.ts +0 -51
  145. package/dist/memory/layers/steering.js +0 -258
  146. package/dist/memory/layers/temporal.d.ts +0 -91
  147. package/dist/memory/layers/temporal.js +0 -245
  148. package/dist/memory/layers/tool-memory-layer.d.ts +0 -16
  149. package/dist/memory/layers/tool-memory-layer.js +0 -43
  150. package/dist/memory/layers/working-memory.d.ts +0 -44
  151. package/dist/memory/layers/working-memory.js +0 -92
  152. package/dist/memory/projector.d.ts +0 -10
  153. package/dist/memory/projector.js +0 -19
  154. package/dist/memory/scope.d.ts +0 -3
  155. package/dist/memory/scope.js +0 -31
  156. package/dist/memory/strip-unresolved.d.ts +0 -13
  157. package/dist/memory/strip-unresolved.js +0 -35
  158. package/dist/schemas/item.d.ts +0 -35
  159. package/dist/schemas/item.js +0 -155
  160. package/dist/types/channel.d.ts +0 -29
  161. package/dist/types/channel.js +0 -1
  162. package/dist/types/common.d.ts +0 -68
  163. package/dist/types/common.js +0 -1
  164. package/dist/types/context-parts/item-log.d.ts +0 -6
  165. package/dist/types/context-parts/item-log.js +0 -1
  166. package/dist/types/context-parts/layer-usage.d.ts +0 -18
  167. package/dist/types/context-parts/layer-usage.js +0 -1
  168. package/dist/types/context.d.ts +0 -202
  169. package/dist/types/context.js +0 -1
  170. package/dist/types/detached.d.ts +0 -17
  171. package/dist/types/detached.js +0 -7
  172. package/dist/types/error.d.ts +0 -66
  173. package/dist/types/error.js +0 -1
  174. package/dist/types/fs-adapter.d.ts +0 -51
  175. package/dist/types/fs-adapter.js +0 -3
  176. package/dist/types/harness-result.d.ts +0 -43
  177. package/dist/types/harness-result.js +0 -2
  178. package/dist/types/items.d.ts +0 -131
  179. package/dist/types/items.js +0 -2
  180. package/dist/types/memory-context.d.ts +0 -39
  181. package/dist/types/memory-context.js +0 -1
  182. package/dist/types/memory.d.ts +0 -306
  183. package/dist/types/memory.js +0 -13
  184. package/dist/types/observability.d.ts +0 -30
  185. package/dist/types/observability.js +0 -1
  186. package/dist/types/runtime.d.ts +0 -256
  187. package/dist/types/runtime.js +0 -1
  188. package/dist/types/shell-adapter.d.ts +0 -34
  189. package/dist/types/shell-adapter.js +0 -10
  190. package/dist/types/steering.d.ts +0 -89
  191. package/dist/types/steering.js +0 -14
  192. package/dist/types/step.d.ts +0 -231
  193. package/dist/types/step.js +0 -1
  194. package/dist/types/subprocess-adapter.d.ts +0 -157
  195. package/dist/types/subprocess-adapter.js +0 -3
  196. package/dist/types/tool-context.d.ts +0 -34
  197. package/dist/types/tool-context.js +0 -1
  198. package/dist/types/tool.d.ts +0 -64
  199. package/dist/types/tool.js +0 -1
  200. package/dist/util/framework-cast.d.ts +0 -10
  201. package/dist/util/framework-cast.js +0 -16
  202. package/dist/util/message-helpers.d.ts +0 -17
  203. package/dist/util/message-helpers.js +0 -64
@@ -1,89 +0,0 @@
1
- import type { LLMResponse } from './common.js';
2
- import type { ExecutionContext, MemoryScope } from './memory-context.js';
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
- }
@@ -1,14 +0,0 @@
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
@@ -1,231 +0,0 @@
1
- import type { ZodType } from 'zod';
2
- import type { Channel } from './channel.js';
3
- import type { ModelParams, RetryPolicy, StepMeta } from './common.js';
4
- import type { Context } from './context.js';
5
- import type { NoeticError } from './error.js';
6
- import type { ContextMemory, MemoryConfig, MemoryLayer } from './memory.js';
7
- import type { SubprocessAdapter } from './subprocess-adapter.js';
8
- import type { Tool } from './tool.js';
9
- /**
10
- * Cumulative execution snapshot passed to loop `until` predicates.
11
- * @public
12
- */
13
- export interface Snapshot {
14
- /** Number of loop iterations completed so far. */
15
- stepCount: number;
16
- /** Aggregate token usage across all iterations. */
17
- tokens: {
18
- input: number;
19
- output: number;
20
- total: number;
21
- };
22
- /** Wall-clock time in ms since the loop started. */
23
- elapsed: number;
24
- /** Cumulative cost across all iterations. */
25
- cost: number;
26
- /** Raw output of the most recent iteration. */
27
- lastOutput: unknown;
28
- /** Stringified text of the most recent iteration output. */
29
- lastText: string;
30
- /** Array of all prior iteration outputs (bounded by `maxHistorySize`). */
31
- history: unknown[];
32
- /** Nesting depth of the current execution context. */
33
- depth: number;
34
- /** Metadata from the most recent step execution (token usage, tool calls, etc.). */
35
- lastStepMeta?: StepMeta | null;
36
- }
37
- /**
38
- * Decision returned by a loop `until` predicate.
39
- * @public
40
- */
41
- export interface Verdict {
42
- /** When true, the loop terminates after this iteration. */
43
- stop: boolean;
44
- /** Human-readable explanation of why the loop stopped (logged in traces). */
45
- reason?: string;
46
- /** Feedback string injected into the next iteration's context (ignored when `stop` is true). */
47
- feedback?: string;
48
- }
49
- /** @public Predicate function evaluated after each loop iteration to decide whether to stop. */
50
- export type Until = (snapshot: Snapshot) => Verdict | Promise<Verdict>;
51
- /**
52
- * Field type that accepts either an eager value or a `(ctx) => value` getter.
53
- * Used by `step.llm` for params that may vary per execution (model, instructions,
54
- * tool list). The getter runs at step execution time with the live context.
55
- * @public
56
- */
57
- export type Lazy<T, TMemory = ContextMemory> = T | ((ctx: Context<TMemory>) => T | Promise<T>);
58
- /**
59
- * Outcome of a single path in a `settle`-mode fork (mirrors `Promise.allSettled`).
60
- * @public
61
- */
62
- export interface SettleResult<O> {
63
- /** Id of the step that produced this result. */
64
- stepId: string;
65
- /** Whether the path completed successfully or threw. */
66
- status: 'fulfilled' | 'rejected';
67
- /** The path's return value (present when `status` is `'fulfilled'`). */
68
- value?: O;
69
- /** The error that caused rejection (present when `status` is `'rejected'`). */
70
- error?: NoeticError;
71
- }
72
- /** @public Discriminated union of all step kinds that can be composed into an execution tree. */
73
- 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>;
74
- /** @public A step that executes arbitrary async logic via a user-supplied function. */
75
- export interface StepRun<TMemory = ContextMemory, I = unknown, O = unknown> {
76
- kind: 'run';
77
- id: string;
78
- execute: (input: I, ctx: Context<TMemory>) => Promise<O>;
79
- retry?: RetryPolicy;
80
- /**
81
- * Per-step subprocess adapter override. When set, the interpreter
82
- * dispatches this step through the given adapter instead of the harness
83
- * default. Resolution order at dispatch is
84
- * `detachedSpawn-overrides.subprocess ?? step.subprocess ?? harness.subprocess`.
85
- */
86
- subprocess?: SubprocessAdapter;
87
- }
88
- /** @public A step that sends a prompt to a language model and returns its response. */
89
- export interface StepLLM<TMemory = ContextMemory, _I = unknown, O = unknown> {
90
- kind: 'llm';
91
- id: string;
92
- /** Model id. Accepts either an eager string or a `(ctx) => string` getter. */
93
- model: Lazy<string, TMemory>;
94
- /** System instructions. Eager string or `(ctx) => string | undefined` getter. */
95
- instructions?: Lazy<string | undefined, TMemory>;
96
- /** Tools exposed to the LLM. Eager array or `(ctx) => Tool[] | undefined` getter. Function-form tools do not contribute to the pre-computed `ctx.unifiedTools`; they are resolved per execution. */
97
- tools?: Lazy<Tool[] | undefined, TMemory>;
98
- output?: ZodType<O>;
99
- params?: ModelParams;
100
- /** 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`. */
101
- emit?: boolean | ((eventType: string, data: Record<string, unknown>) => boolean);
102
- }
103
- /** @public A step that invokes a single tool directly, bypassing the LLM. */
104
- export interface StepTool<_TMemory = ContextMemory, I = unknown, O = unknown> {
105
- kind: 'tool';
106
- id: string;
107
- tool: Tool<ZodType<I>, ZodType<O>>;
108
- args?: Partial<I>;
109
- }
110
- /** @public A step that dynamically selects and executes one of several possible sub-steps. */
111
- export interface StepBranch<TMemory = ContextMemory, I = unknown, O = unknown> {
112
- kind: 'branch';
113
- id: string;
114
- route: (input: I, ctx: Context<TMemory>) => Step<TMemory, I, O> | null | Promise<Step<TMemory, I, O> | null>;
115
- _optimizable?: Step<TMemory>[];
116
- }
117
- /** @public Union of fork step variants (`race`, `all`, `settle`) for concurrent path execution. */
118
- export type StepFork<TMemory = ContextMemory, I = unknown, O = unknown> = StepForkRace<TMemory, I, O> | StepForkAll<TMemory, I, O> | StepForkSettle<TMemory, I, O>;
119
- /** @public A fork step that returns the result of the first path to complete. */
120
- export interface StepForkRace<TMemory = ContextMemory, I = unknown, O = unknown> {
121
- kind: 'fork';
122
- id: string;
123
- mode: 'race';
124
- paths: (input: I, ctx: Context<TMemory>) => Step<TMemory, I, O>[];
125
- concurrency?: number;
126
- _optimizable?: Step<TMemory>[];
127
- }
128
- /** @public A fork step that runs all paths and merges their results. */
129
- export interface StepForkAll<TMemory = ContextMemory, I = unknown, O = unknown> {
130
- kind: 'fork';
131
- id: string;
132
- mode: 'all';
133
- paths: (input: I, ctx: Context<TMemory>) => Step<TMemory, I, O>[];
134
- merge: (results: O[], ctx: Context<TMemory>) => O;
135
- concurrency?: number;
136
- _optimizable?: Step<TMemory>[];
137
- }
138
- /** @public A fork step that runs all paths and collects fulfilled/rejected outcomes. */
139
- export interface StepForkSettle<TMemory = ContextMemory, I = unknown, O = unknown> {
140
- kind: 'fork';
141
- id: string;
142
- mode: 'settle';
143
- paths: (input: I, ctx: Context<TMemory>) => Step<TMemory, I, O>[];
144
- merge: (results: SettleResult<O>[], ctx: Context<TMemory>) => O;
145
- concurrency?: number;
146
- _optimizable?: Step<TMemory>[];
147
- }
148
- /**
149
- * A step that provides memory layers to its child without creating an isolated context.
150
- * Like React's Context.Provider — layers are available to all descendant steps.
151
- * Spawn and detachedSpawn break the inheritance chain.
152
- * @public
153
- */
154
- export interface StepProvide<TMemory = ContextMemory, I = unknown, O = unknown> {
155
- kind: 'provide';
156
- id: string;
157
- child: Step<TMemory, I, O>;
158
- memory: MemoryConfig | MemoryLayer[];
159
- }
160
- /** @public A step that launches a child execution with its own memory scope. */
161
- export interface StepSpawn<TMemory = ContextMemory, I = unknown, O = unknown> {
162
- kind: 'spawn';
163
- id: string;
164
- child: Step<TMemory, I, O>;
165
- memory?: MemoryConfig | MemoryLayer[];
166
- timeout?: number;
167
- /**
168
- * Per-step subprocess adapter override applied when the interpreter
169
- * dispatches this spawn. Resolution order is
170
- * `detachedSpawn-overrides.subprocess ?? step.subprocess ?? harness.subprocess`.
171
- */
172
- subprocess?: SubprocessAdapter;
173
- }
174
- /**
175
- * A loop step that iterates a body step until a termination predicate is satisfied.
176
- * @public
177
- */
178
- export interface StepLoop<TMemory = ContextMemory, I = unknown, O = unknown> {
179
- kind: 'loop';
180
- /** Unique step identifier used in traces and error messages. */
181
- id: string;
182
- /** Steps to execute sequentially on each iteration. */
183
- steps: ReadonlyArray<Step<TMemory, I, O>>;
184
- /** Termination predicate evaluated after each iteration with a cumulative snapshot. */
185
- until: Until;
186
- /** Hard safety cap on iterations (default: 1000). */
187
- maxIterations?: number;
188
- /** Maximum number of entries kept in the snapshot history array. */
189
- maxHistorySize?: number;
190
- /** Optional channel for injecting messages into the loop mid-execution. */
191
- inbox?: Channel<string>;
192
- /** Ms to wait on inbox before the loop parks itself (default: 0 = no parking). */
193
- parkTimeout?: number;
194
- /** Transforms the previous iteration's output into the next iteration's input. */
195
- prepareNext?: (output: O, verdict: Verdict, ctx: Context<TMemory>) => I;
196
- /** Per-iteration error handler: retry the iteration, skip it, or abort the loop. */
197
- onError?: (error: NoeticError, ctx: Context<TMemory>) => 'retry' | 'skip' | 'abort';
198
- }
199
- /**
200
- * Error policy for the `every` operator when its body step throws.
201
- * - `'continue'` (default): emit a span event recording the error and continue parking.
202
- * - `'fail'`: re-throw, terminating the operator.
203
- * @public
204
- */
205
- export type EveryErrorPolicy = 'continue' | 'fail';
206
- /**
207
- * A step that runs a body step on a fixed-interval schedule, optionally woken
208
- * sooner by a wake channel. Runs forever until the executing context is cancelled.
209
- *
210
- * The operator output is `void` — `every` does not accumulate iteration outputs.
211
- * The `O` type parameter exists only to anchor the body step's output type.
212
- *
213
- * @public
214
- */
215
- export interface StepEvery<TMemory = ContextMemory, I = unknown, O = unknown> {
216
- kind: 'every';
217
- /** Unique step identifier used in traces and error messages. */
218
- id: string;
219
- /** Body step executed on each iteration. */
220
- step: Step<TMemory, I, O>;
221
- /** Park duration between iterations in milliseconds. Must be >= 0. */
222
- ms: number;
223
- /** Optional channel that wakes the parking interval when any value arrives. */
224
- wakeOn?: Channel<unknown>;
225
- /** Behavior when `step` throws. Defaults to `'continue'`. */
226
- onError?: EveryErrorPolicy;
227
- /** Random jitter applied to the park duration in milliseconds. Must be >= 0. Default 0. */
228
- jitter?: number;
229
- }
230
- /** @public Function signature used by the interpreter to recursively execute a step. */
231
- export type ExecuteStepFn = <TMemory, I, O>(step: Step<TMemory, I, O>, input: I, ctx: Context<TMemory>) => Promise<O>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,157 +0,0 @@
1
- /** @public Lifecycle states for a subprocess handle. */
2
- export type SubprocessStatus = 'starting' | 'running' | 'paused' | 'completed' | 'failed' | 'stopped' | 'stale';
3
- /**
4
- * @public
5
- * Plain-object shape used to transport an error from a subprocess back to the
6
- * parent via `SubprocessHandle.metadata.error`. Non-serialisable fields (e.g.
7
- * `Error.cause` chains with functions or cyclic data) are dropped at the
8
- * producer boundary.
9
- */
10
- export interface SerializedError {
11
- /** Human-readable message; always present. */
12
- message: string;
13
- /** Constructor `name` of the underlying error (`Error`, `NoeticError`, etc.). */
14
- name?: string;
15
- /** Best-effort stack trace, when the producing runtime retained one. */
16
- stack?: string;
17
- /**
18
- * Structured `NoeticError` payload carried through for in-process
19
- * transport. Consumers may reconstruct `NoeticErrorImpl` from this when
20
- * they need typed error kinds.
21
- */
22
- noeticError?: unknown;
23
- }
24
- /** @public Fields common to every subprocess request variant. */
25
- interface SubprocessRequestBase {
26
- metadata?: Record<string, unknown>;
27
- }
28
- /**
29
- * @public
30
- * Launches an OS-level child process. This is the classic variant used by the
31
- * tasks runner to spawn planner / implementer children.
32
- *
33
- * When `kind` is omitted the request is treated as a process request — this
34
- * preserves backward compatibility with callers that predate the
35
- * `StepSubprocessRequest` variant.
36
- */
37
- export interface ProcessSubprocessRequest extends SubprocessRequestBase {
38
- kind?: 'process';
39
- command: string;
40
- args?: ReadonlyArray<string>;
41
- cwd?: string;
42
- env?: Record<string, string | undefined>;
43
- detached?: boolean;
44
- stdin?: string;
45
- }
46
- /** @public Overrides applied to the child context when executing a step request. */
47
- export interface StepSubprocessOverrides {
48
- /** Override the child's thread id. */
49
- threadId?: string;
50
- /** Override the child's resource id. */
51
- resourceId?: string;
52
- /** Override the child's initial cwd. */
53
- cwdInit?: string;
54
- }
55
- /**
56
- * @public
57
- * Dispatches a step through the adapter. `stepId` resolves against the shared
58
- * step registry — the in-memory adapter invokes the in-process execute pipeline,
59
- * while out-of-process adapters spawn a child runtime that re-imports the same
60
- * registry via a configured entry point.
61
- */
62
- export interface StepSubprocessRequest extends SubprocessRequestBase {
63
- kind: 'step';
64
- stepId: string;
65
- /** Serialisable input for the step. Stored in `handle.metadata` when needed. */
66
- serializedInput: unknown;
67
- /** Stable id for the execution — used for handle lookup and durable checkpointing. */
68
- executionId: string;
69
- /** Child-context overrides (thread, resource, cwd). */
70
- overrides: StepSubprocessOverrides;
71
- /**
72
- * @internal
73
- * Closure used by the default in-memory adapter to run the step in the same
74
- * process as the caller. Non-serialisable — adapters that cross a process
75
- * boundary MUST ignore this field. Framework-internal callers set it; public
76
- * consumers should not.
77
- */
78
- _localExecutor?: () => Promise<unknown>;
79
- }
80
- /** @public Discriminated union covering every shape `SubprocessAdapter.spawn()` accepts. */
81
- export type SubprocessRequest = ProcessSubprocessRequest | StepSubprocessRequest;
82
- /**
83
- * @public
84
- * Well-known keys carried on `SubprocessHandle.metadata`. Adapters populate
85
- * these during their lifecycle; consumers read them via the helpers exported
86
- * alongside the adapter types.
87
- */
88
- export interface SubprocessHandleMetadata extends Record<string, unknown> {
89
- /** Awaited step result, stored when a step request completes successfully. */
90
- result?: unknown;
91
- /** Serialised error, stored when a step request fails. */
92
- error?: SerializedError;
93
- /** Execution id echoed from the originating `StepSubprocessRequest`. */
94
- executionId?: string;
95
- }
96
- /** @public Handle returned by `SubprocessAdapter.spawn()` — a durable reference to a child. */
97
- export interface SubprocessHandle {
98
- id: string;
99
- status: SubprocessStatus;
100
- startedAt: string;
101
- updatedAt?: string;
102
- metadata?: SubprocessHandleMetadata;
103
- }
104
- /** @public Outcome of `pause` / `resume` calls on a subprocess handle. */
105
- export type SubprocessControlResult = {
106
- kind: 'ok';
107
- handle: SubprocessHandle;
108
- } | {
109
- kind: 'unsupported';
110
- handle: SubprocessHandle;
111
- message: string;
112
- } | {
113
- kind: 'not_found';
114
- handleId: string;
115
- };
116
- /** @public Outcome of a `stop()` call on a subprocess handle. */
117
- export interface SubprocessStopResult {
118
- kind: 'stopped' | 'not_found';
119
- handleId: string;
120
- handle?: SubprocessHandle;
121
- }
122
- /**
123
- * @public
124
- * Contract for dispatching and managing subprocess-style executions — both
125
- * OS-level child processes and in-process step runs. Implementations own the
126
- * lifecycle of every handle they return, including persistence when they opt
127
- * into durable execution via `reattach` / `listLive`.
128
- */
129
- export interface SubprocessAdapter {
130
- /** Dispatches a new request and returns its handle. */
131
- spawn(request: SubprocessRequest): Promise<SubprocessHandle>;
132
- /** Fetches the current handle by id, or `null` when unknown. */
133
- get(handleId: string): Promise<SubprocessHandle | null>;
134
- /** Requests cancellation of a running handle. */
135
- stop(handleId: string, reason?: string): Promise<SubprocessStopResult>;
136
- /** Pauses a running handle (when the adapter supports it). */
137
- pause(handleId: string): Promise<SubprocessControlResult>;
138
- /** Resumes a paused handle (when the adapter supports it). */
139
- resume(handleId: string): Promise<SubprocessControlResult>;
140
- /** Returns true when the underlying execution is still alive. */
141
- isAlive(handle: SubprocessHandle): Promise<boolean>;
142
- /**
143
- * Rebinds to a handle persisted across a host restart. Returns `null` when
144
- * no manifest exists for the given id. Durability is an adapter-level
145
- * concern — the in-memory adapter returns `null` by default (handles are
146
- * ephemeral), while the local adapter consults its storage.
147
- */
148
- reattach(handleId: string): Promise<SubprocessHandle | null>;
149
- /**
150
- * Lists every handle the adapter currently treats as live. Used by host
151
- * recovery to rediscover running children on startup. The in-memory adapter
152
- * returns the set of active in-process handles; the local adapter scans its
153
- * persisted manifest.
154
- */
155
- listLive(): Promise<ReadonlyArray<SubprocessHandle>>;
156
- }
157
- export {};
@@ -1,3 +0,0 @@
1
- //#region Status
2
- export {};
3
- //#endregion
@@ -1,34 +0,0 @@
1
- import type { TurnContext } from '@openrouter/agent';
2
- import type { StepMeta } from './common.js';
3
- import type { Context } from './context.js';
4
- import type { FsAdapter } from './fs-adapter.js';
5
- import type { Item } from './items.js';
6
- import type { AgentHarnessContract } from './runtime.js';
7
- import type { ShellAdapter } from './shell-adapter.js';
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
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,64 +0,0 @@
1
- import type { ZodTypeAny, z } from 'zod';
2
- import type { FunctionCallItem, FunctionCallOutputItem, Item, ItemSchemaExtensions, ToolResultExtensionItem } from './items.js';
3
- type ToolExecutionResult<O extends ZodTypeAny> = Promise<z.infer<O>> | AsyncGenerator<unknown, z.infer<O>>;
4
- /**
5
- * Declares tool-owned memory that the runtime materializes into a MemoryLayer.
6
- * @public
7
- */
8
- export interface ToolMemoryDeclaration<TState = unknown> {
9
- /** Shared id — tools with the same id share state. Defaults to `tool.name`. */
10
- id?: string;
11
- /** Factory for the initial state. */
12
- init(): TState;
13
- /**
14
- * Project state into the LLM context. Return null to omit.
15
- * Declared as a method (bivariant params) so a concrete
16
- * `ToolMemoryDeclaration<MyState>` assigns to the erased
17
- * `ToolMemoryDeclaration` the `tool()` builder and runtime consume.
18
- */
19
- recall(state: TState): string | null;
20
- }
21
- /**
22
- * A tool definition that an LLM can invoke during execution.
23
- *
24
- * The runtime passes a `ToolExecutionContext` (from `./tool-context`) as
25
- * the second argument to `execute`. Callers that need the concrete type
26
- * should import `Tool` from the package root (`@noetic-tools/core`), which
27
- * re-exports it with `ToolExecutionContext` substituted in.
28
- * @public
29
- */
30
- export interface Tool<I extends ZodTypeAny = ZodTypeAny, O extends ZodTypeAny = ZodTypeAny> {
31
- /** Unique tool name used by the LLM for selection. */
32
- name: string;
33
- /** Human-readable description shown to the LLM. */
34
- description: string;
35
- /** Zod schema validating tool input arguments. */
36
- input: I;
37
- /** Zod schema validating tool return value. */
38
- output: O;
39
- /** Optional Zod schema validating streaming events yielded during execution. */
40
- event?: ZodTypeAny;
41
- /** Optional item schemas contributed by this tool for tool call/result extensions. */
42
- itemSchemas?: Pick<ItemSchemaExtensions, 'toolCalls' | 'toolResults' | 'items'>;
43
- /** Decorate the harness-created tool result item before it is appended/emitted. */
44
- decorateResultItem?(params: {
45
- baseItem: FunctionCallOutputItem;
46
- callItem: FunctionCallItem;
47
- args: z.infer<I>;
48
- result: z.infer<O> | undefined;
49
- output: string;
50
- error?: boolean;
51
- }): Item | ToolResultExtensionItem;
52
- /**
53
- * Async function that performs the tool's work. `toolCtx` is a
54
- * `ToolExecutionContext` at runtime — typed as `unknown` here to keep
55
- * this type a dependency leaf. Use `tool()` from `builders/` or cast at
56
- * the call site to get a typed handle.
57
- */
58
- execute(args: z.infer<I>, toolCtx: unknown): ToolExecutionResult<O>;
59
- /** When true, execution pauses for human approval before running. */
60
- needsApproval?: boolean;
61
- /** Optional memory declaration — the runtime generates a MemoryLayer from this. */
62
- memory?: ToolMemoryDeclaration;
63
- }
64
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,10 +0,0 @@
1
- /**
2
- * Explicit cast for framework boundaries where TypeScript's type system
3
- * cannot express the relationship between input and output types.
4
- *
5
- * Used for: pass-through returns (branch null route, loop feedback),
6
- * raw LLM text output, type-erased collections, and cross-library bridges.
7
- *
8
- * This is the single approved location for unsafe type coercion in the codebase.
9
- */
10
- export declare function frameworkCast<T>(value: unknown): T;
@@ -1,16 +0,0 @@
1
- /**
2
- * Explicit cast for framework boundaries where TypeScript's type system
3
- * cannot express the relationship between input and output types.
4
- *
5
- * Used for: pass-through returns (branch null route, loop feedback),
6
- * raw LLM text output, type-erased collections, and cross-library bridges.
7
- *
8
- * This is the single approved location for unsafe type coercion in the codebase.
9
- */
10
- // Declared return type differs from the parameter type intentionally —
11
- // callers specify T to bridge a framework type gap that TypeScript cannot express.
12
- // The runtime value is returned unchanged (identity function).
13
- export function frameworkCast(value) {
14
- // @ts-expect-error — intentional unsafe coercion at framework boundary
15
- return value;
16
- }
@@ -1,17 +0,0 @@
1
- import type { LLMResponse } from '../types/common.js';
2
- import type { Context } from '../types/context.js';
3
- import type { InputMessageItem, Item, MessageItem } from '../types/items.js';
4
- export declare function isAssistantMessage(item: unknown): item is MessageItem;
5
- export declare function isUserMessage(item: unknown): item is MessageItem;
6
- export declare function isOutputText(part: {
7
- type: string;
8
- }): part is {
9
- type: 'output_text';
10
- text: string;
11
- };
12
- export declare function createMessage(text: string, role: 'user' | 'developer'): InputMessageItem;
13
- export declare function extractAssistantText(items: ReadonlyArray<Item>): string;
14
- /** Naive token estimate: ~4 chars per token */
15
- export declare function estimateTokens(text: string): number;
16
- /** Accumulate token usage and cost from an LLM response onto a mutable context. */
17
- export declare function trackUsage(ctx: Context, response: LLMResponse): void;