@noetic-tools/core 0.2.0 → 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 +6 -4
  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,306 +0,0 @@
1
- import type { ZodType } from 'zod';
2
- import type { LLMResponse } from './common.js';
3
- import type { ItemLog } from './context-parts/item-log.js';
4
- import type { Item, ItemSchemaExtensions } from './items.js';
5
- import type { ExecutionContext, ExecutionOutcome, MemoryScope } from './memory-context.js';
6
- import type { AfterModelCallParams, AfterModelCallResult, BeforeToolCallParams, BeforeToolCallResult } from './steering.js';
7
- export type { ExecutionContext, ExecutionOutcome, MemoryCallModelRequest, MemoryScope, } from './memory-context.js';
8
- /** @public Isolation scope controlling how a memory layer's state is keyed and shared. */
9
- export type BudgetConfig = number | {
10
- min: number;
11
- max: number;
12
- } | 'auto';
13
- /** @public Per-hook timeout overrides in milliseconds for a memory layer. */
14
- export interface LayerTimeouts {
15
- init?: number;
16
- recall?: number;
17
- store?: number;
18
- onSpawn?: number;
19
- onReturn?: number;
20
- onComplete?: number;
21
- dispose?: number;
22
- beforeToolCall?: number;
23
- afterModelCall?: number;
24
- onItemAppend?: number;
25
- projectHistory?: number;
26
- }
27
- /** @public A read-only data projection from layer state, accessible via `ctx.memory['layerId'].prop`. */
28
- export interface LayerDataDecl<T = unknown, TState = unknown> {
29
- kind: 'data';
30
- /** Project a value from the layer's current state. Method syntax enables bivariant assignability. */
31
- read(state: TState): T;
32
- }
33
- /** @public A callable function backed by layer state, accessible via `ctx.memory['layerId'].fn()` or as an LLM tool. */
34
- export interface LayerFunctionDecl<TInput = unknown, TOutput = unknown, TState = unknown> {
35
- kind: 'function';
36
- /** Human-readable description (used as tool description when exposed to LLM). */
37
- description: string;
38
- /** Zod schema for input arguments. */
39
- input: ZodType<TInput>;
40
- /** Zod schema for return value. */
41
- output: ZodType<TOutput>;
42
- /** Execute the function with the layer's current state. Return optional state update. */
43
- execute(args: TInput, state: TState, ctx: ExecutionContext): Promise<{
44
- result: TOutput;
45
- state?: TState;
46
- }>;
47
- }
48
- /** @public Map of named data and function declarations exposed by a memory layer. */
49
- export type LayerProvides = Record<string, LayerDataDecl | LayerFunctionDecl>;
50
- /**
51
- * Mapped type that produces a flat handle from a layer's `provides` declaration.
52
- * Data entries become direct property reads; function entries become callable async methods.
53
- * @public
54
- */
55
- export type LayerHandle<T extends MemoryLayer> = T extends {
56
- provides: infer P;
57
- } ? {
58
- [K in keyof P]: P[K] extends LayerDataDecl<infer D, unknown> ? D : P[K] extends LayerFunctionDecl<infer I, infer O, unknown> ? (args: I) => Promise<O> : never;
59
- } : Record<string, never>;
60
- /** @public Object keyed by layer ID, where each value is a resolved handle for that layer's provides. */
61
- export type ContextMemory = Readonly<Record<string, Record<string, unknown>>>;
62
- /**
63
- * Maps a tuple of memory layers to a typed object keyed by layer ID.
64
- * Each layer's `provides` is flattened: data → value type, function → async callable.
65
- * @public
66
- */
67
- export type InferMemoryShape<T extends readonly MemoryLayer[]> = {
68
- [L in T[number] as L extends {
69
- readonly id: infer Id extends string;
70
- } ? Id : never]: L extends {
71
- provides: infer P;
72
- } ? {
73
- [K in keyof P]: P[K] extends LayerDataDecl<infer D, unknown> ? D : P[K] extends LayerFunctionDecl<infer I, infer O, unknown> ? (args: I) => Promise<O> : never;
74
- } : Record<string, never>;
75
- };
76
- /**
77
- * Typed wrapper around a tuple of memory layers. Preserves individual layer types
78
- * for compile-time inference via `InferMemory<typeof config>`.
79
- * @public
80
- */
81
- export interface MemoryConfig<TLayers extends readonly MemoryLayer[] = readonly MemoryLayer[]> {
82
- readonly layers: TLayers;
83
- /** Phantom field carrying the inferred memory shape. Never accessed at runtime. */
84
- readonly _shape: InferMemoryShape<TLayers>;
85
- }
86
- /**
87
- * Extract the typed memory shape from a MemoryConfig.
88
- * Constrains structurally on the phantom `_shape` field rather than on
89
- * `MemoryConfig` itself: `MemoryConfig` is invariant in `TLayers` (the `_shape`
90
- * field carries it in an invariant position), so a concrete
91
- * `MemoryConfig<readonly [SomeLayer]>` does not satisfy the defaulted
92
- * `MemoryConfig<readonly MemoryLayer[]>`. Since `InferMemory` only reads
93
- * `_shape`, this constraint accepts any config the `memory()` builder produces.
94
- * @public Usage: `type Mem = InferMemory<typeof config>`
95
- */
96
- export type InferMemory<T extends {
97
- readonly _shape: unknown;
98
- }> = T['_shape'];
99
- /** @public Well-known ordering slots for positioning memory layers in the recall/store pipeline. */
100
- export declare const Slot: {
101
- readonly REMINDER: 80;
102
- readonly STEERING: 90;
103
- readonly WORKING_MEMORY: 100;
104
- readonly ENTITY: 150;
105
- readonly OBSERVATIONS: 200;
106
- readonly PROCEDURAL: 250;
107
- readonly EPISODIC: 300;
108
- readonly RAG: 350;
109
- readonly SEMANTIC_RECALL: 400;
110
- };
111
- /** @public Low-level key-value persistence backend used by scoped storage and memory layers. */
112
- export interface StorageAdapter {
113
- get<T>(key: string): Promise<T | null>;
114
- set<T>(key: string, value: T): Promise<void>;
115
- delete(key: string): Promise<void>;
116
- list(prefix: string): Promise<string[]>;
117
- }
118
- /** @public Scope-namespaced storage interface provided to memory layer init hooks. */
119
- export interface ScopedStorage {
120
- get<T>(key: string): Promise<T | null>;
121
- set<T>(key: string, value: T): Promise<void>;
122
- delete(key: string): Promise<void>;
123
- list(prefix?: string): Promise<string[]>;
124
- }
125
- /** @public Parameters passed to a memory layer's `init` hook. */
126
- export interface InitParams {
127
- storage: ScopedStorage;
128
- scopeKey: string;
129
- ctx: ExecutionContext;
130
- }
131
- /** @public Value returned by a memory layer's `init` hook, carrying the initial state. */
132
- export interface InitResult<TState> {
133
- state: TState;
134
- }
135
- /** @public Parameters passed to a memory layer's `recall` hook before each LLM call. */
136
- export interface RecallParams<TState> {
137
- log: ItemLog;
138
- query: string;
139
- ctx: ExecutionContext;
140
- state: TState;
141
- budget: number;
142
- }
143
- /** @public Value returned by a memory layer's `recall` hook, containing items and token count. */
144
- export interface RecallResult<TState = unknown> {
145
- items: Item[];
146
- tokenCount: number;
147
- state?: TState;
148
- }
149
- /** @public Parameters passed to a memory layer's `store` hook after each LLM response. */
150
- export interface StoreParams<TState> {
151
- newItems: Item[];
152
- log: ItemLog;
153
- response: LLMResponse;
154
- ctx: ExecutionContext;
155
- state: TState;
156
- }
157
- /** @public Value returned by a memory layer's `store` hook, carrying the updated state. */
158
- export interface StoreResult<TState> {
159
- state: TState;
160
- }
161
- /** @public Parameters passed to a memory layer's `onSpawn` hook when a child execution starts. */
162
- export interface SpawnParams<TState> {
163
- parentState: TState;
164
- childCtx: ExecutionContext;
165
- }
166
- /** @public Value returned by a memory layer's `onSpawn` hook with the child's initial state. */
167
- export interface SpawnResult<TState> {
168
- childState: TState | null;
169
- items?: Item[];
170
- }
171
- /** @public Parameters passed to a memory layer's `onReturn` hook when a child execution completes. */
172
- export interface ReturnParams<TState> {
173
- childState: TState;
174
- childLog: ItemLog;
175
- parentState: TState;
176
- result: unknown;
177
- }
178
- /** @public Value returned by a memory layer's `onReturn` hook with the merged parent state. */
179
- export interface ReturnResult<TState> {
180
- parentState: TState;
181
- result?: unknown;
182
- }
183
- /** @public Parameters passed to a memory layer's `onComplete` hook at execution end. */
184
- export interface CompleteParams<TState> {
185
- log: ItemLog;
186
- ctx: ExecutionContext;
187
- state: TState;
188
- outcome: ExecutionOutcome;
189
- }
190
- /** @public Parameters passed to a memory layer's `dispose` hook during teardown. */
191
- export interface DisposeParams<TState> {
192
- state: TState;
193
- }
194
- /** @public Parameters passed to a memory layer's `projectHistory` hook to project the history portion of the LLM context window. */
195
- export interface ProjectHistoryParams<TState> {
196
- /** Full historical items from the item log, uncapped. */
197
- items: ReadonlyArray<Item>;
198
- /** Current execution context. */
199
- ctx: ExecutionContext;
200
- /** Layer's current state snapshot. */
201
- state: TState;
202
- }
203
- /** @public Value returned by a memory layer's `projectHistory` hook, carrying the projected items. */
204
- export interface ProjectHistoryResult {
205
- /** Items to send to the LLM as history. Typically a subset of the input. */
206
- items: ReadonlyArray<Item>;
207
- }
208
- /** @public Controls which layers re-run recall() when a re-render is triggered. */
209
- export type RerenderScope = 'self' | 'slot-after' | 'all';
210
- /** @public Parameters passed to a memory layer's `onItemAppend` hook when input items are about to be appended. */
211
- export interface OnItemAppendParams<TState> {
212
- /** Items to be appended (may have been transformed by prior layers in the pipeline). */
213
- items: Item[];
214
- /** Full item log (read-only). */
215
- log: ItemLog;
216
- /** Current execution context. */
217
- ctx: ExecutionContext;
218
- /** Layer's current state snapshot. */
219
- state: TState;
220
- }
221
- /** @public Value returned by a memory layer's `onItemAppend` hook. */
222
- export interface OnItemAppendResult<TState> {
223
- /**
224
- * Items to actually append to the log.
225
- * - Return original items unchanged to pass through
226
- * - Return modified items to transform
227
- * - Return empty array to filter/drop items
228
- * - Return additional items to inject extras
229
- */
230
- items: Item[];
231
- /** Updated layer state. */
232
- state?: TState;
233
- /** Request context re-render. */
234
- rerender?: boolean;
235
- /** When to apply re-render (default: layer's configured `rerenderTiming`). */
236
- timing?: 'immediate' | 'batched';
237
- /** Which layers to re-recall (default: 'slot-after'). */
238
- scope?: RerenderScope;
239
- }
240
- /** @public Lifecycle hook implementations for a memory layer. Method syntax enables bivariant assignability for typed layers. */
241
- export interface MemoryHooks<TState = unknown> {
242
- init?(params: InitParams): Promise<InitResult<TState>>;
243
- recall?(params: RecallParams<TState>): Promise<RecallResult<TState> | string | null>;
244
- store?(params: StoreParams<TState>): Promise<StoreResult<TState> | undefined>;
245
- onSpawn?(params: SpawnParams<TState>): Promise<SpawnResult<TState> | null>;
246
- onReturn?(params: ReturnParams<TState>): Promise<ReturnResult<TState> | undefined>;
247
- onComplete?(params: CompleteParams<TState>): Promise<undefined | {
248
- state: TState;
249
- }>;
250
- dispose?(params: DisposeParams<TState>): Promise<void>;
251
- beforeToolCall?(params: BeforeToolCallParams<TState>): Promise<BeforeToolCallResult<TState>>;
252
- afterModelCall?(params: AfterModelCallParams<TState>): Promise<AfterModelCallResult<TState>>;
253
- /**
254
- * Called when input items (user messages, tool outputs) are about to be appended.
255
- * Returns items to append — enables filtering, transformation, and injection.
256
- *
257
- * Pipeline: items flow through layers in slot order. Each layer receives
258
- * the output of the previous layer (or original items for first layer).
259
- *
260
- * NOT called for LLM response items — use `store()` for those.
261
- */
262
- onItemAppend?(params: OnItemAppendParams<TState>): Promise<OnItemAppendResult<TState>>;
263
- /**
264
- * Called once per LLM step to project (cap, transform) the history portion
265
- * of the context window before assembleView. Layers compose in slot order:
266
- * each receives the output of the previous layer. Storage (`itemLog`) is
267
- * NOT mutated — this is a read-side projection only.
268
- *
269
- * Use for: capping history, summarising old turns, redacting items.
270
- */
271
- projectHistory?(params: ProjectHistoryParams<TState>): Promise<ProjectHistoryResult>;
272
- }
273
- /**
274
- * A composable memory layer that participates in the recall/store lifecycle.
275
- * @public
276
- */
277
- export interface MemoryLayer<TState = unknown> {
278
- /** Unique identifier for this layer instance. */
279
- id: string;
280
- /** Human-readable name for debugging and trace output. */
281
- name?: string;
282
- /** Ordering slot (lower = recalled first). Use `Slot` constants for well-known positions. */
283
- slot: number;
284
- /** Scope controlling state isolation: `'thread'`, `'resource'`, `'global'`, or `'execution'`. */
285
- scope: MemoryScope;
286
- /** Token budget: a fixed number, a `{ min, max }` range, or `'auto'` for dynamic allocation. */
287
- budget?: BudgetConfig;
288
- /** Lifecycle hooks invoked by the runtime at each phase (init, recall, store, etc.). */
289
- hooks: MemoryHooks<TState>;
290
- /** Per-hook timeout overrides in ms. */
291
- timeouts?: Partial<LayerTimeouts>;
292
- /** Typed functions and data exposed to code steps via `ctx.memory['layerId']` and automatically as LLM tools. */
293
- provides?: LayerProvides;
294
- /** Optional item schemas contributed by this layer, primarily for developer-role memory items. */
295
- itemSchemas?: Pick<ItemSchemaExtensions, 'developerMessages' | 'items'>;
296
- /** Default re-render timing when `onItemAppend` requests a re-render. */
297
- rerenderTiming?: 'immediate' | 'batched';
298
- }
299
- /** @public Configuration for how the runtime projects conversation items into the model's context window. */
300
- export interface ProjectionPolicy {
301
- tokenBudget: number;
302
- responseReserve: number;
303
- overflow: 'truncate' | 'summarize' | 'sliding_window';
304
- overflowModel?: string;
305
- windowSize?: number;
306
- }
@@ -1,13 +0,0 @@
1
- //#endregion
2
- /** @public Well-known ordering slots for positioning memory layers in the recall/store pipeline. */
3
- export const Slot = {
4
- REMINDER: 80,
5
- STEERING: 90,
6
- WORKING_MEMORY: 100,
7
- ENTITY: 150,
8
- OBSERVATIONS: 200,
9
- PROCEDURAL: 250,
10
- EPISODIC: 300,
11
- RAG: 350,
12
- SEMANTIC_RECALL: 400,
13
- };
@@ -1,30 +0,0 @@
1
- /** @public A trace span representing a unit of work within the observability pipeline. */
2
- export interface Span {
3
- readonly traceId: string;
4
- readonly spanId: string;
5
- readonly parentSpanId: string | null;
6
- setAttribute(key: string, value: string | number | boolean): void;
7
- addEvent(name: string, attributes?: Record<string, string | number | boolean>): void;
8
- end(): void;
9
- }
10
- /** @public Backend that receives and persists completed trace spans. */
11
- export interface TraceExporter {
12
- export(spans: Span[]): Promise<void>;
13
- }
14
- /** @public Diagnostic span recording a single memory layer hook invocation and its outcome. */
15
- export interface MemoryTraceSpan {
16
- layerId: string;
17
- hook: 'init' | 'recall' | 'store' | 'onSpawn' | 'onReturn' | 'onComplete' | 'dispose';
18
- durationMs: number;
19
- status: 'ok' | 'error' | 'timeout' | 'skipped';
20
- budget?: {
21
- allocated: number;
22
- used: number;
23
- yielded: number;
24
- };
25
- itemCount?: number;
26
- error?: {
27
- message: string;
28
- stack?: string;
29
- };
30
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,256 +0,0 @@
1
- import type { ZodType } from 'zod';
2
- import type { Channel, ChannelHandle, ExternalChannel } from './channel.js';
3
- import type { LLMResponse, ModelParams } from './common.js';
4
- import type { Context, CwdState } from './context.js';
5
- import type { DetachedHandle } from './detached.js';
6
- import type { FsAdapter } from './fs-adapter.js';
7
- import type { HarnessResponse, StreamEvent, StreamingItem } from './harness-result.js';
8
- import type { ExecuteInput, Item, ItemSchemaExtensions } from './items.js';
9
- import type { ContextMemory, MemoryLayer, StorageAdapter } from './memory.js';
10
- import type { Span } from './observability.js';
11
- import type { ShellAdapter } from './shell-adapter.js';
12
- import type { SteeringDecision } from './steering.js';
13
- import type { Step } from './step.js';
14
- import type { SubprocessAdapter } from './subprocess-adapter.js';
15
- import type { Tool } from './tool.js';
16
- /** @public Optional lifecycle hooks invoked before and after each step execution. */
17
- export interface AgentHooks {
18
- beforeStep?: (step: Step, ctx: Context) => Promise<void>;
19
- afterStep?: (step: Step, result: unknown, ctx: Context) => Promise<void>;
20
- }
21
- /** @public Top-level configuration object that defines an agent's model, tools, memory, and behavior. */
22
- export interface AgentConfig<TParams extends Record<string, unknown> = Record<string, unknown>> {
23
- name: string;
24
- storage?: StorageAdapter;
25
- hooks?: AgentHooks;
26
- params: TParams;
27
- /** Harness-wide item schema extensions used to validate emitted and returned items. */
28
- itemSchemas?: ItemSchemaExtensions;
29
- /** Whether unknown extension item types must match a registered schema. Defaults to true. */
30
- strictItemSchemas?: boolean;
31
- }
32
- /** @public How a message submitted during an active turn is delivered to the model.
33
- *
34
- * - `next-turn` (default): queue the message; it becomes a new user turn after
35
- * the current turn completes.
36
- * - `between-rounds`: inject the message as an additional user item before the
37
- * next tool-round LLM call within the same turn. The model sees it partway
38
- * through. Mirrors Claude Code's inbox-attachment behaviour.
39
- * - `interrupt`: cancel the in-flight LLM stream, append the message, and
40
- * restart the turn from the merged history.
41
- */
42
- export type DeliveryMode = 'next-turn' | 'between-rounds' | 'interrupt';
43
- /** @public Base fields shared by all callModel requests. */
44
- interface CallModelRequestBase {
45
- model: string;
46
- items: ReadonlyArray<Item>;
47
- instructions?: string;
48
- params?: ModelParams;
49
- /** When provided, the harness sends a JSON Schema constraint to the model so it returns structured JSON. */
50
- outputSchema?: ZodType;
51
- /** Controls framework event emission. Defaults to `true`. Passed through from `StepLLM.emit`. */
52
- emit?: boolean | ((eventType: string, data: Record<string, unknown>) => boolean);
53
- /** Optional signal for cancelling the in-flight call (used by session abort). */
54
- signal?: AbortSignal;
55
- }
56
- /** @public Request shape when tools are provided — ctx is required for tool execution callbacks. */
57
- interface CallModelRequestWithTools extends CallModelRequestBase {
58
- tools: Tool[];
59
- ctx: Context;
60
- layers?: MemoryLayer[];
61
- /** When set, restricts which tools the model may invoke for this call. */
62
- allowedToolNames?: string[];
63
- }
64
- /** @public Request shape when no tools are provided — ctx is only needed for tool
65
- * execution callbacks in convertTools, so it is omitted here. */
66
- interface CallModelRequestWithoutTools extends CallModelRequestBase {
67
- tools?: undefined;
68
- ctx?: undefined;
69
- layers?: undefined;
70
- }
71
- /** @public Request object for `AgentHarnessContract.callModel()`. Encapsulates all parameters needed for an LLM call using only Noetic types. */
72
- export type CallModelRequest = CallModelRequestWithTools | CallModelRequestWithoutTools;
73
- /** @public Options for `AgentHarness.execute()` to configure the execution context. */
74
- export interface ExecuteOptions {
75
- threadId?: string;
76
- resourceId?: string;
77
- state?: unknown;
78
- /** Memory layers to apply to the execution context. Overrides harness-level memory if provided. */
79
- memory?: MemoryLayer[];
80
- /** Override the harness's default delivery mode for this message only. */
81
- deliveryMode?: DeliveryMode;
82
- /**
83
- * Stable id used for the enqueued message. When provided, this id is emitted
84
- * in the `turn_started` framework event (`messageIds`), allowing callers to
85
- * correlate their own UI state (e.g. flipping a `queued` indicator to
86
- * `sent`) with the message they submitted. A random id is generated when
87
- * omitted.
88
- */
89
- messageId?: string;
90
- }
91
- /** @public Snapshot of a session's runtime state. */
92
- export type HarnessStatus = {
93
- readonly kind: 'idle';
94
- } | {
95
- readonly kind: 'generating';
96
- readonly startedAt: number;
97
- readonly turnId: string;
98
- } | {
99
- readonly kind: 'aborting';
100
- readonly turnId: string;
101
- };
102
- /** @public Identifies which session the accessor targets. All methods fall back to the harness's default thread when omitted. */
103
- export interface SessionScope {
104
- threadId?: string;
105
- }
106
- /** @public Type-level contract for the agent runtime. Used for type annotations throughout the interpreter, memory layers, and context. Implemented by `AgentHarness`. */
107
- export interface AgentHarnessContract<TParams extends Record<string, unknown> = Record<string, unknown>> {
108
- readonly config: AgentConfig<TParams>;
109
- /** Filesystem adapter for virtual or real filesystem access. */
110
- readonly fs: FsAdapter;
111
- /** Shell adapter for virtual or real shell command execution. */
112
- readonly shell: ShellAdapter;
113
- /** Subprocess adapter for virtual, same-process, or host process execution. */
114
- readonly subprocess: SubprocessAdapter;
115
- callModel(request: CallModelRequest): Promise<LLMResponse>;
116
- /**
117
- * Submit input to the agent. The message is enqueued on the session identified
118
- * by `options.threadId` (or the default thread) and processed by the session
119
- * runner according to the effective `DeliveryMode`.
120
- *
121
- * Returns once the message has been accepted into the queue — NOT when the
122
- * model responds. Use `getAgentResponse()` or `getItemStream()` to observe
123
- * the response.
124
- */
125
- execute(input: ExecuteInput, options?: ExecuteOptions): Promise<void>;
126
- /**
127
- * Resolves with the accumulated response once the session has finished
128
- * processing its queue (status returns to `idle` with no pending messages).
129
- */
130
- getAgentResponse(scope?: SessionScope): Promise<HarnessResponse>;
131
- /** Yields cumulative Item snapshots with isComplete flag across all turns in the session. */
132
- getItemStream(scope?: SessionScope): AsyncIterable<StreamingItem>;
133
- /** Yields text deltas as they arrive from the model, across all turns. */
134
- getTextStream(scope?: SessionScope): AsyncIterable<string>;
135
- /** Yields reasoning token deltas from reasoning-capable models, across all turns. */
136
- getReasoningStream(scope?: SessionScope): AsyncIterable<string>;
137
- /** Yields all raw stream events (SDK + framework) for the session. */
138
- getFullStream(scope?: SessionScope): AsyncIterable<StreamEvent>;
139
- /**
140
- * Cancel the in-flight turn, if any. Queued messages are preserved — the
141
- * runner re-kicks from the queue once abort completes.
142
- */
143
- abort(scope?: SessionScope & {
144
- reason?: string;
145
- }): Promise<void>;
146
- /** Current runtime status of a session. */
147
- getStatus(scope?: SessionScope): HarnessStatus;
148
- /** Number of messages currently queued on a session. */
149
- getQueueSize(scope?: SessionScope): number;
150
- /**
151
- * Pre-populate a session's accumulated history with prior items so the next
152
- * `execute()` turn sees them as established context. Used by resume flows to
153
- * seed a freshly-constructed session from a persisted transcript without
154
- * re-running the prior turns. Creates the session lazily if it does not
155
- * already exist. Replaces any previously-accumulated items for the session.
156
- */
157
- seedSessionHistory(threadId: string, items: ReadonlyArray<Item>): void;
158
- run<I, O>(step: Step<ContextMemory, I, O>, input: I, ctx: Context): Promise<O>;
159
- /**
160
- * Launch `step` as a fire-and-forget background execution.
161
- *
162
- * The returned `DetachedHandle` exposes status / result / error and an
163
- * `await()` for callers that want to block on settlement. The child runs
164
- * concurrently with the caller; pass `overrides.threadId` to give the child
165
- * its own session-scoped item log so background work does not pollute the
166
- * parent's accumulated turn history.
167
- *
168
- * @param step Step to execute in a fresh child context.
169
- * @param input Initial input passed to `step`.
170
- * @param parentCtx Parent context (the child inherits memory layers and,
171
- * by default, threadId/resourceId).
172
- * @param overrides Optional: override threadId or resourceId on the child.
173
- */
174
- detachedSpawn<I, O>(step: Step<ContextMemory, I, O>, input: I, parentCtx: Context, overrides?: {
175
- threadId?: string;
176
- resourceId?: string;
177
- /** Override the child's initial cwd. Used by worktree isolation to root the child at the worktree path. */
178
- cwdInit?: string;
179
- }): DetachedHandle<O>;
180
- createContext(opts?: {
181
- parent?: Context;
182
- items?: Item[];
183
- state?: unknown;
184
- threadId?: string;
185
- resourceId?: string;
186
- memory?: MemoryLayer[];
187
- /** Override the new context's initial cwd. */
188
- cwdInit?: string;
189
- }): Context;
190
- /** Long-lived shared cwd state seeded into root contexts created by this harness. */
191
- readonly rootCwdState: CwdState;
192
- /** Update the harness root cwd. Used by the TUI when the user issues a `! cd`. */
193
- setRootCwd(nextCwd: string): void;
194
- send<T>(channel: Channel<T>, value: T, ctx: Context): void;
195
- recv<T>(channel: Channel<T>, ctx: Context, opts?: {
196
- timeout?: number;
197
- }): Promise<T>;
198
- tryRecv<T>(channel: Channel<T>, ctx: Context): T | null;
199
- getChannelHandle<T>(channel: ExternalChannel<T>, executionId: string): ChannelHandle<T>;
200
- initLayers(layers: MemoryLayer[], ctx: Context, storage: StorageAdapter): Promise<void>;
201
- recallLayers(layers: MemoryLayer[], input: string, ctx: Context): Promise<RecallLayerOutput[]>;
202
- /**
203
- * Compute the items that would be sent to the model on the next turn for a
204
- * session — its accumulated history plus the harness's memory-layer recall
205
- * outputs assembled in the same order `executeLLM` produces.
206
- */
207
- previewRequestItems(scope?: SessionScope): Promise<ReadonlyArray<Item>>;
208
- storeLayers(layers: MemoryLayer[], response: LLMResponse, ctx: Context): Promise<void>;
209
- disposeLayers(layers: MemoryLayer[], ctx: Context): Promise<void>;
210
- checkpoint(ctx: Context): Promise<void>;
211
- restore(executionId: string): Promise<Context | null>;
212
- cancel(ctx: Context, reason?: string): Promise<void>;
213
- createSpan(name: string, parent: Span | null): Span;
214
- getLayerState<T>(executionId: string, layerId: string): T | undefined;
215
- setLayerState<T>(executionId: string, layerId: string, state: T): void;
216
- beforeToolCall(layers: MemoryLayer[], toolName: string, toolArgs: unknown, ctx: Context): Promise<SteeringDecision>;
217
- afterModelCall(layers: MemoryLayer[], response: LLMResponse, ctx: Context): Promise<SteeringDecision>;
218
- /**
219
- * Project the history items through every layer's `projectHistory` hook in
220
- * slot order. Pure read-side projection — `itemLog` is never mutated.
221
- * Returns the input unchanged if no layer registers the hook.
222
- */
223
- projectHistory(layers: MemoryLayer[], items: ReadonlyArray<Item>, ctx: Context): Promise<ReadonlyArray<Item>>;
224
- /**
225
- * Run items through the onItemAppend pipeline before appending.
226
- * Each layer can filter, transform, or inject items.
227
- * Returns final items to append and any re-render requests.
228
- */
229
- runAppendPipeline(layers: MemoryLayer[], items: Item[], ctx: Context): Promise<AppendPipelineResult>;
230
- /**
231
- * Execute re-render based on collected requests.
232
- * Determines which layers need re-recall based on scope and runs them.
233
- */
234
- executeRerender(requests: RerenderRequest[], layers: MemoryLayer[], ctx: Context, budgets: Map<string, number>, query?: string): Promise<RecallLayerOutput[]>;
235
- }
236
- /** @public Output from a single memory layer's recall phase, including items and token budget used. */
237
- export interface RecallLayerOutput {
238
- layerId: string;
239
- items: Item[];
240
- tokenCount: number;
241
- }
242
- /** @public A request to re-render the context window, collected from onItemAppend hooks. */
243
- export interface RerenderRequest {
244
- layerId: string;
245
- slot: number;
246
- timing: 'immediate' | 'batched';
247
- scope: 'self' | 'slot-after' | 'all';
248
- }
249
- /** @public Result of running items through the onItemAppend pipeline. */
250
- export interface AppendPipelineResult {
251
- /** Final items to append after all transformations. */
252
- items: Item[];
253
- /** Re-render requests collected from layers. */
254
- rerenderRequests: RerenderRequest[];
255
- }
256
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,34 +0,0 @@
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
- }
@@ -1,10 +0,0 @@
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