@noetic-tools/types 2.2.0 → 2.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.
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Deprecated aliases from the "memory layer" era of the framework.
3
+ *
4
+ * The layer system assembles the model's *context window* — recall, budget
5
+ * allocation, history projection, the item-append pipeline — so it is named
6
+ * after context, not memory. Every name below still resolves to its
7
+ * replacement; nothing here changes behaviour.
8
+ *
9
+ * These are scheduled for removal in the next major of `@noetic-tools/types`.
10
+ */
11
+ import type { ContextConfig, ContextData, ContextLayer, ContextLayerHooks, InferContext, InferContextShape } from './types/context-layer.js';
12
+ import type { ContextScope, LayerCallModelRequest } from './types/context-scope.js';
13
+ import type { LayerTraceSpan } from './types/observability.js';
14
+ import type { ToolContextDeclaration } from './types/tool.js';
15
+ import type { ToolContext } from './types/tool-context.js';
16
+ /** @public @deprecated Renamed to {@link ContextLayer}. */
17
+ export type MemoryLayer<TState = unknown> = ContextLayer<TState>;
18
+ /** @public @deprecated Renamed to {@link ContextLayerHooks}. */
19
+ export type MemoryHooks<TState = unknown> = ContextLayerHooks<TState>;
20
+ /** @public @deprecated Renamed to {@link ContextConfig}. */
21
+ export type MemoryConfig<TLayers extends readonly ContextLayer[] = readonly ContextLayer[]> = ContextConfig<TLayers>;
22
+ /** @public @deprecated Renamed to {@link ContextData}. */
23
+ export type ContextMemory = ContextData;
24
+ /** @public @deprecated Renamed to {@link InferContext}. */
25
+ export type InferMemory<T extends {
26
+ readonly _shape: unknown;
27
+ }> = InferContext<T>;
28
+ /** @public @deprecated Renamed to {@link InferContextShape}. */
29
+ export type InferMemoryShape<T extends readonly ContextLayer[]> = InferContextShape<T>;
30
+ /** @public @deprecated Renamed to {@link ContextScope}. */
31
+ export type MemoryScope = ContextScope;
32
+ /** @public @deprecated Renamed to {@link LayerCallModelRequest}. */
33
+ export type MemoryCallModelRequest = LayerCallModelRequest;
34
+ /** @public @deprecated Renamed to {@link LayerTraceSpan}. */
35
+ export type MemoryTraceSpan = LayerTraceSpan;
36
+ /** @public @deprecated Renamed to {@link ToolContext}. */
37
+ export type ToolMemory = ToolContext;
38
+ /** @public @deprecated Renamed to {@link ToolContextDeclaration}. */
39
+ export type ToolMemoryDeclaration<TState = unknown> = ToolContextDeclaration<TState>;
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  * @noetic-tools/types — foundational type contracts and primitives shared
3
3
  * across the Noetic framework.
4
4
  */
5
+ export * from './deprecated.js';
5
6
  export * from './errors/noetic-config-error.js';
6
7
  export * from './errors/noetic-error.js';
7
8
  export * from './schemas/item.js';
@@ -9,15 +10,15 @@ export * from './schemas/workflow.js';
9
10
  export * from './types/channel.js';
10
11
  export * from './types/common.js';
11
12
  export * from './types/context.js';
13
+ export * from './types/context-layer.js';
12
14
  export * from './types/context-parts/item-log.js';
13
15
  export * from './types/context-parts/layer-usage.js';
16
+ export * from './types/context-scope.js';
14
17
  export * from './types/detached.js';
15
18
  export * from './types/error.js';
16
19
  export * from './types/fs-adapter.js';
17
20
  export * from './types/harness-result.js';
18
21
  export * from './types/items.js';
19
- export * from './types/memory.js';
20
- export * from './types/memory-context.js';
21
22
  export * from './types/observability.js';
22
23
  export * from './types/output-codec.js';
23
24
  export * from './types/runtime.js';
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  * @noetic-tools/types — foundational type contracts and primitives shared
3
3
  * across the Noetic framework.
4
4
  */
5
+ export * from './deprecated.js';
5
6
  export * from './errors/noetic-config-error.js';
6
7
  export * from './errors/noetic-error.js';
7
8
  export * from './schemas/item.js';
@@ -9,15 +10,15 @@ export * from './schemas/workflow.js';
9
10
  export * from './types/channel.js';
10
11
  export * from './types/common.js';
11
12
  export * from './types/context.js';
13
+ export * from './types/context-layer.js';
12
14
  export * from './types/context-parts/item-log.js';
13
15
  export * from './types/context-parts/layer-usage.js';
16
+ export * from './types/context-scope.js';
14
17
  export * from './types/detached.js';
15
18
  export * from './types/error.js';
16
19
  export * from './types/fs-adapter.js';
17
20
  export * from './types/harness-result.js';
18
21
  export * from './types/items.js';
19
- export * from './types/memory.js';
20
- export * from './types/memory-context.js';
21
22
  export * from './types/observability.js';
22
23
  export * from './types/output-codec.js';
23
24
  export * from './types/runtime.js';
@@ -24,7 +24,7 @@ export declare const ItemSchema: z.ZodCustom<Item, Item>;
24
24
  type ItemSchemaCategory = keyof Required<ItemSchemaExtensions>;
25
25
  export declare function mergeExtensions(a: ItemSchemaExtensions | undefined, b: ItemSchemaExtensions | undefined): ItemSchemaExtensions;
26
26
  /**
27
- * @public Runtime item validator with optional tool, memory-layer, and harness extension schemas.
27
+ * @public Runtime item validator with optional tool, context-layer, and harness extension schemas.
28
28
  *
29
29
  * Extension schemas are pure shape validators (gate, not normalizer): on
30
30
  * match the original value is returned unchanged, including fields the schema
@@ -97,7 +97,7 @@ function schemaMismatch(category) {
97
97
  });
98
98
  }
99
99
  /**
100
- * @public Runtime item validator with optional tool, memory-layer, and harness extension schemas.
100
+ * @public Runtime item validator with optional tool, context-layer, and harness extension schemas.
101
101
  *
102
102
  * Extension schemas are pure shape validators (gate, not normalizer): on
103
103
  * match the original value is returned unchanged, including fields the schema
@@ -1,15 +1,15 @@
1
1
  import type { ZodType } from 'zod';
2
2
  import type { LLMResponse } from './common.js';
3
3
  import type { ItemLog } from './context-parts/item-log.js';
4
+ import type { ContextScope, ExecutionContext, ExecutionOutcome } from './context-scope.js';
4
5
  import type { Item, ItemSchemaExtensions } from './items.js';
5
- import type { ExecutionContext, ExecutionOutcome, MemoryScope } from './memory-context.js';
6
6
  import type { AfterModelCallParams, AfterModelCallResult, BeforeToolCallParams, BeforeToolCallResult } from './steering.js';
7
- /** @public Isolation scope controlling how a memory layer's state is keyed and shared. */
7
+ /** @public Isolation scope controlling how a context layer's state is keyed and shared. */
8
8
  export type BudgetConfig = number | {
9
9
  min: number;
10
10
  max: number;
11
11
  } | 'auto';
12
- /** @public Per-hook timeout overrides in milliseconds for a memory layer. */
12
+ /** @public Per-hook timeout overrides in milliseconds for a context layer. */
13
13
  export interface LayerTimeouts {
14
14
  init?: number;
15
15
  recall?: number;
@@ -23,13 +23,13 @@ export interface LayerTimeouts {
23
23
  onItemAppend?: number;
24
24
  projectHistory?: number;
25
25
  }
26
- /** @public A read-only data projection from layer state, accessible via `ctx.memory['layerId'].prop`. */
26
+ /** @public A read-only data projection from layer state, accessible via `ctx.context['layerId'].prop`. */
27
27
  export interface LayerDataDecl<T = unknown, TState = unknown> {
28
28
  kind: 'data';
29
29
  /** Project a value from the layer's current state. Method syntax enables bivariant assignability. */
30
30
  read(state: TState): T;
31
31
  }
32
- /** @public A callable function backed by layer state, accessible via `ctx.memory['layerId'].fn()` or as an LLM tool. */
32
+ /** @public A callable function backed by layer state, accessible via `ctx.context['layerId'].fn()` or as an LLM tool. */
33
33
  export interface LayerFunctionDecl<TInput = unknown, TOutput = unknown, TState = unknown> {
34
34
  kind: 'function';
35
35
  /** Human-readable description (used as tool description when exposed to LLM). */
@@ -44,26 +44,26 @@ export interface LayerFunctionDecl<TInput = unknown, TOutput = unknown, TState =
44
44
  state?: TState;
45
45
  }>;
46
46
  }
47
- /** @public Map of named data and function declarations exposed by a memory layer. */
47
+ /** @public Map of named data and function declarations exposed by a context layer. */
48
48
  export type LayerProvides = Record<string, LayerDataDecl | LayerFunctionDecl>;
49
49
  /**
50
50
  * Mapped type that produces a flat handle from a layer's `provides` declaration.
51
51
  * Data entries become direct property reads; function entries become callable async methods.
52
52
  * @public
53
53
  */
54
- export type LayerHandle<T extends MemoryLayer> = T extends {
54
+ export type LayerHandle<T extends ContextLayer> = T extends {
55
55
  provides: infer P;
56
56
  } ? {
57
57
  [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;
58
58
  } : Record<string, never>;
59
59
  /** @public Object keyed by layer ID, where each value is a resolved handle for that layer's provides. */
60
- export type ContextMemory = Readonly<Record<string, Record<string, unknown>>>;
60
+ export type ContextData = Readonly<Record<string, Record<string, unknown>>>;
61
61
  /**
62
- * Maps a tuple of memory layers to a typed object keyed by layer ID.
62
+ * Maps a tuple of context layers to a typed object keyed by layer ID.
63
63
  * Each layer's `provides` is flattened: data → value type, function → async callable.
64
64
  * @public
65
65
  */
66
- export type InferMemoryShape<T extends readonly MemoryLayer[]> = {
66
+ export type InferContextShape<T extends readonly ContextLayer[]> = {
67
67
  [L in T[number] as L extends {
68
68
  readonly id: infer Id extends string;
69
69
  } ? Id : never]: L extends {
@@ -73,29 +73,29 @@ export type InferMemoryShape<T extends readonly MemoryLayer[]> = {
73
73
  } : Record<string, never>;
74
74
  };
75
75
  /**
76
- * Typed wrapper around a tuple of memory layers. Preserves individual layer types
77
- * for compile-time inference via `InferMemory<typeof config>`.
76
+ * Typed wrapper around a tuple of context layers. Preserves individual layer types
77
+ * for compile-time inference via `InferContext<typeof config>`.
78
78
  * @public
79
79
  */
80
- export interface MemoryConfig<TLayers extends readonly MemoryLayer[] = readonly MemoryLayer[]> {
80
+ export interface ContextConfig<TLayers extends readonly ContextLayer[] = readonly ContextLayer[]> {
81
81
  readonly layers: TLayers;
82
- /** Phantom field carrying the inferred memory shape. Never accessed at runtime. */
83
- readonly _shape: InferMemoryShape<TLayers>;
82
+ /** Phantom field carrying the inferred context shape. Never accessed at runtime. */
83
+ readonly _shape: InferContextShape<TLayers>;
84
84
  }
85
85
  /**
86
- * Extract the typed memory shape from a MemoryConfig.
86
+ * Extract the typed context shape from a ContextConfig.
87
87
  * Constrains structurally on the phantom `_shape` field rather than on
88
- * `MemoryConfig` itself: `MemoryConfig` is invariant in `TLayers` (the `_shape`
88
+ * `ContextConfig` itself: `ContextConfig` is invariant in `TLayers` (the `_shape`
89
89
  * field carries it in an invariant position), so a concrete
90
- * `MemoryConfig<readonly [SomeLayer]>` does not satisfy the defaulted
91
- * `MemoryConfig<readonly MemoryLayer[]>`. Since `InferMemory` only reads
92
- * `_shape`, this constraint accepts any config the `memory()` builder produces.
93
- * @public Usage: `type Mem = InferMemory<typeof config>`
90
+ * `ContextConfig<readonly [SomeLayer]>` does not satisfy the defaulted
91
+ * `ContextConfig<readonly ContextLayer[]>`. Since `InferContext` only reads
92
+ * `_shape`, this constraint accepts any config the `context()` builder produces.
93
+ * @public Usage: `type Mem = InferContext<typeof config>`
94
94
  */
95
- export type InferMemory<T extends {
95
+ export type InferContext<T extends {
96
96
  readonly _shape: unknown;
97
97
  }> = T['_shape'];
98
- /** @public Well-known ordering slots for positioning memory layers in the recall/store pipeline. */
98
+ /** @public Well-known ordering slots for positioning context layers in the recall/store pipeline. */
99
99
  export declare const Slot: {
100
100
  readonly REMINDER: 80;
101
101
  readonly STEERING: 90;
@@ -107,7 +107,7 @@ export declare const Slot: {
107
107
  readonly RAG: 350;
108
108
  readonly SEMANTIC_RECALL: 400;
109
109
  };
110
- /** @public Low-level key-value persistence backend used by scoped storage and memory layers. */
110
+ /** @public Low-level key-value persistence backend used by scoped storage and context layers. */
111
111
  export interface StorageAdapter {
112
112
  get<T>(key: string): Promise<T | null>;
113
113
  set<T>(key: string, value: T): Promise<void>;
@@ -129,7 +129,7 @@ export interface StorageAdapter {
129
129
  */
130
130
  getMany?<T>(keys: string[]): Promise<Map<string, T>>;
131
131
  }
132
- /** @public Scope-namespaced storage interface provided to memory layer init hooks. */
132
+ /** @public Scope-namespaced storage interface provided to context layer init hooks. */
133
133
  export interface ScopedStorage {
134
134
  get<T>(key: string): Promise<T | null>;
135
135
  set<T>(key: string, value: T): Promise<void>;
@@ -143,17 +143,17 @@ export interface ScopedStorage {
143
143
  */
144
144
  getMany<T>(keys: string[]): Promise<Map<string, T>>;
145
145
  }
146
- /** @public Parameters passed to a memory layer's `init` hook. */
146
+ /** @public Parameters passed to a context layer's `init` hook. */
147
147
  export interface InitParams {
148
148
  storage: ScopedStorage;
149
149
  scopeKey: string;
150
150
  ctx: ExecutionContext;
151
151
  }
152
- /** @public Value returned by a memory layer's `init` hook, carrying the initial state. */
152
+ /** @public Value returned by a context layer's `init` hook, carrying the initial state. */
153
153
  export interface InitResult<TState> {
154
154
  state: TState;
155
155
  }
156
- /** @public Parameters passed to a memory layer's `recall` hook before each LLM call. */
156
+ /** @public Parameters passed to a context layer's `recall` hook before each LLM call. */
157
157
  export interface RecallParams<TState> {
158
158
  log: ItemLog;
159
159
  query: string;
@@ -161,13 +161,13 @@ export interface RecallParams<TState> {
161
161
  state: TState;
162
162
  budget: number;
163
163
  }
164
- /** @public Value returned by a memory layer's `recall` hook, containing items and token count. */
164
+ /** @public Value returned by a context layer's `recall` hook, containing items and token count. */
165
165
  export interface RecallResult<TState = unknown> {
166
166
  items: Item[];
167
167
  tokenCount: number;
168
168
  state?: TState;
169
169
  }
170
- /** @public Parameters passed to a memory layer's `store` hook after each LLM response. */
170
+ /** @public Parameters passed to a context layer's `store` hook after each LLM response. */
171
171
  export interface StoreParams<TState> {
172
172
  newItems: Item[];
173
173
  log: ItemLog;
@@ -175,21 +175,21 @@ export interface StoreParams<TState> {
175
175
  ctx: ExecutionContext;
176
176
  state: TState;
177
177
  }
178
- /** @public Value returned by a memory layer's `store` hook, carrying the updated state. */
178
+ /** @public Value returned by a context layer's `store` hook, carrying the updated state. */
179
179
  export interface StoreResult<TState> {
180
180
  state: TState;
181
181
  }
182
- /** @public Parameters passed to a memory layer's `onSpawn` hook when a child execution starts. */
182
+ /** @public Parameters passed to a context layer's `onSpawn` hook when a child execution starts. */
183
183
  export interface SpawnParams<TState> {
184
184
  parentState: TState;
185
185
  childCtx: ExecutionContext;
186
186
  }
187
- /** @public Value returned by a memory layer's `onSpawn` hook with the child's initial state. */
187
+ /** @public Value returned by a context layer's `onSpawn` hook with the child's initial state. */
188
188
  export interface SpawnResult<TState> {
189
189
  childState: TState | null;
190
190
  items?: Item[];
191
191
  }
192
- /** @public Parameters passed to a memory layer's `onReturn` hook when a child execution completes. */
192
+ /** @public Parameters passed to a context layer's `onReturn` hook when a child execution completes. */
193
193
  export interface ReturnParams<TState> {
194
194
  childState: TState;
195
195
  childLog: ItemLog;
@@ -203,23 +203,23 @@ export interface ReturnParams<TState> {
203
203
  */
204
204
  childCtx: ExecutionContext;
205
205
  }
206
- /** @public Value returned by a memory layer's `onReturn` hook with the merged parent state. */
206
+ /** @public Value returned by a context layer's `onReturn` hook with the merged parent state. */
207
207
  export interface ReturnResult<TState> {
208
208
  parentState: TState;
209
209
  result?: unknown;
210
210
  }
211
- /** @public Parameters passed to a memory layer's `onComplete` hook at execution end. */
211
+ /** @public Parameters passed to a context layer's `onComplete` hook at execution end. */
212
212
  export interface CompleteParams<TState> {
213
213
  log: ItemLog;
214
214
  ctx: ExecutionContext;
215
215
  state: TState;
216
216
  outcome: ExecutionOutcome;
217
217
  }
218
- /** @public Parameters passed to a memory layer's `dispose` hook during teardown. */
218
+ /** @public Parameters passed to a context layer's `dispose` hook during teardown. */
219
219
  export interface DisposeParams<TState> {
220
220
  state: TState;
221
221
  }
222
- /** @public Parameters passed to a memory layer's `projectHistory` hook to project the history portion of the LLM context window. */
222
+ /** @public Parameters passed to a context layer's `projectHistory` hook to project the history portion of the LLM context window. */
223
223
  export interface ProjectHistoryParams<TState> {
224
224
  /** Full historical items from the item log, uncapped. */
225
225
  items: ReadonlyArray<Item>;
@@ -228,14 +228,14 @@ export interface ProjectHistoryParams<TState> {
228
228
  /** Layer's current state snapshot. */
229
229
  state: TState;
230
230
  }
231
- /** @public Value returned by a memory layer's `projectHistory` hook, carrying the projected items. */
231
+ /** @public Value returned by a context layer's `projectHistory` hook, carrying the projected items. */
232
232
  export interface ProjectHistoryResult {
233
233
  /** Items to send to the LLM as history. Typically a subset of the input. */
234
234
  items: ReadonlyArray<Item>;
235
235
  }
236
236
  /** @public Controls which layers re-run recall() when a re-render is triggered. */
237
237
  export type RerenderScope = 'self' | 'slot-after' | 'all';
238
- /** @public Parameters passed to a memory layer's `onItemAppend` hook when input items are about to be appended. */
238
+ /** @public Parameters passed to a context layer's `onItemAppend` hook when input items are about to be appended. */
239
239
  export interface OnItemAppendParams<TState> {
240
240
  /** Items to be appended (may have been transformed by prior layers in the pipeline). */
241
241
  items: Item[];
@@ -246,7 +246,7 @@ export interface OnItemAppendParams<TState> {
246
246
  /** Layer's current state snapshot. */
247
247
  state: TState;
248
248
  }
249
- /** @public Value returned by a memory layer's `onItemAppend` hook. */
249
+ /** @public Value returned by a context layer's `onItemAppend` hook. */
250
250
  export interface OnItemAppendResult<TState> {
251
251
  /**
252
252
  * Items to actually append to the log.
@@ -265,8 +265,8 @@ export interface OnItemAppendResult<TState> {
265
265
  /** Which layers to re-recall (default: 'slot-after'). */
266
266
  scope?: RerenderScope;
267
267
  }
268
- /** @public Lifecycle hook implementations for a memory layer. Method syntax enables bivariant assignability for typed layers. */
269
- export interface MemoryHooks<TState = unknown> {
268
+ /** @public Lifecycle hook implementations for a context layer. Method syntax enables bivariant assignability for typed layers. */
269
+ export interface ContextLayerHooks<TState = unknown> {
270
270
  init?(params: InitParams): Promise<InitResult<TState>>;
271
271
  recall?(params: RecallParams<TState>): Promise<RecallResult<TState> | string | null>;
272
272
  store?(params: StoreParams<TState>): Promise<StoreResult<TState> | undefined>;
@@ -299,10 +299,10 @@ export interface MemoryHooks<TState = unknown> {
299
299
  projectHistory?(params: ProjectHistoryParams<TState>): Promise<ProjectHistoryResult>;
300
300
  }
301
301
  /**
302
- * A composable memory layer that participates in the recall/store lifecycle.
302
+ * A composable context layer that participates in the recall/store lifecycle.
303
303
  * @public
304
304
  */
305
- export interface MemoryLayer<TState = unknown> {
305
+ export interface ContextLayer<TState = unknown> {
306
306
  /** Unique identifier for this layer instance. */
307
307
  id: string;
308
308
  /** Human-readable name for debugging and trace output. */
@@ -310,16 +310,16 @@ export interface MemoryLayer<TState = unknown> {
310
310
  /** Ordering slot (lower = recalled first). Use `Slot` constants for well-known positions. */
311
311
  slot: number;
312
312
  /** Scope controlling state isolation: `'thread'`, `'resource'`, `'global'`, or `'execution'`. */
313
- scope: MemoryScope;
313
+ scope: ContextScope;
314
314
  /** Token budget: a fixed number, a `{ min, max }` range, or `'auto'` for dynamic allocation. */
315
315
  budget?: BudgetConfig;
316
316
  /** Lifecycle hooks invoked by the runtime at each phase (init, recall, store, etc.). */
317
- hooks: MemoryHooks<TState>;
317
+ hooks: ContextLayerHooks<TState>;
318
318
  /** Per-hook timeout overrides in ms. */
319
319
  timeouts?: Partial<LayerTimeouts>;
320
320
  /**
321
321
  * What to do when this layer's `init` hook throws.
322
- * - `'throw'` (default): surface the error and abort the execution — memory is
322
+ * - `'throw'` (default): surface the error and abort the execution — context is
323
323
  * load-bearing, and silent disabling hides failures (and, for the steering
324
324
  * layer, would fail *open*).
325
325
  * - `'disable'`: log a diagnostic and run the execution without this layer
@@ -337,9 +337,9 @@ export interface MemoryLayer<TState = unknown> {
337
337
  * ignoring this field.
338
338
  */
339
339
  recallMode?: 'atomic' | 'eventual';
340
- /** Typed functions and data exposed to code steps via `ctx.memory['layerId']` and automatically as LLM tools. */
340
+ /** Typed functions and data exposed to code steps via `ctx.context['layerId']` and automatically as LLM tools. */
341
341
  provides?: LayerProvides;
342
- /** Optional item schemas contributed by this layer, primarily for developer-role memory items. */
342
+ /** Optional item schemas contributed by this layer, primarily for developer-role context items. */
343
343
  itemSchemas?: Pick<ItemSchemaExtensions, 'developerMessages' | 'items'>;
344
344
  /** Default re-render timing when `onItemAppend` requests a re-render. */
345
345
  rerenderTiming?: 'immediate' | 'batched';
@@ -1,5 +1,5 @@
1
1
  //#endregion
2
- /** @public Well-known ordering slots for positioning memory layers in the recall/store pipeline. */
2
+ /** @public Well-known ordering slots for positioning context layers in the recall/store pipeline. */
3
3
  export const Slot = {
4
4
  REMINDER: 80,
5
5
  STEERING: 90,
@@ -2,17 +2,17 @@ import type { LLMResponse } from './common.js';
2
2
  import type { FsAdapter } from './fs-adapter.js';
3
3
  import type { Item } from './items.js';
4
4
  import type { ShellAdapter } from './shell-adapter.js';
5
- /** @public Isolation scope controlling how a memory layer's state is keyed and shared. */
6
- export type MemoryScope = 'thread' | 'resource' | 'global' | 'execution';
7
- /** @public Terminal outcome of an execution run, reported to memory layers on completion. */
5
+ /** @public Isolation scope controlling how a context layer's state is keyed and shared. */
6
+ export type ContextScope = 'thread' | 'resource' | 'global' | 'execution';
7
+ /** @public Terminal outcome of an execution run, reported to context layers on completion. */
8
8
  export type ExecutionOutcome = 'success' | 'failure' | 'aborted';
9
- /** @public Minimal model-call surface exposed to memory-layer hooks. */
10
- export interface MemoryCallModelRequest {
9
+ /** @public Minimal model-call surface exposed to context-layer hooks. */
10
+ export interface LayerCallModelRequest {
11
11
  model: string;
12
12
  items: ReadonlyArray<Item>;
13
13
  instructions?: string;
14
14
  }
15
- /** @public Runtime metadata available to memory layer hooks during each lifecycle phase. */
15
+ /** @public Runtime metadata available to context layer hooks during each lifecycle phase. */
16
16
  export interface ExecutionContext {
17
17
  executionId: string;
18
18
  threadId: string;
@@ -28,12 +28,12 @@ export interface ExecutionContext {
28
28
  fs: FsAdapter;
29
29
  /** Shell adapter for virtual or real shell command execution. */
30
30
  shell: ShellAdapter;
31
- callModel?: (request: MemoryCallModelRequest) => Promise<LLMResponse>;
31
+ callModel?: (request: LayerCallModelRequest) => Promise<LLMResponse>;
32
32
  tokenize(text: string): number;
33
33
  trace: {
34
34
  setAttribute(key: string, value: string | number | boolean): void;
35
35
  addEvent(name: string, attributes?: Record<string, string | number | boolean>): void;
36
36
  };
37
- /** Snapshot a sibling memory layer's state by its `layer.id`. */
37
+ /** Snapshot a sibling context layer's state by its `layer.id`. */
38
38
  readLayerState<T>(layerId: string): T | undefined;
39
39
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -2,13 +2,13 @@ import type { ZodType } from 'zod';
2
2
  import type { ItemSchemaRegistry } from '../schemas/item.js';
3
3
  import type { Channel, ChannelHandle, ExternalChannel } from './channel.js';
4
4
  import type { LLMResponse, ModelParams, StepMeta, TokenUsage } from './common.js';
5
+ import type { ContextData, ContextLayer, ProjectionPolicy, StorageAdapter } from './context-layer.js';
5
6
  import type { ItemLog } from './context-parts/item-log.js';
6
7
  import type { LastLayerUsage } from './context-parts/layer-usage.js';
7
8
  import type { DetachedHandle } from './detached.js';
8
9
  import type { FsAdapter } from './fs-adapter.js';
9
10
  import type { HarnessResponse, StreamEvent, StreamingItem } from './harness-result.js';
10
11
  import type { ExecuteInput } from './items.js';
11
- import type { ContextMemory, MemoryLayer, ProjectionPolicy, StorageAdapter } from './memory.js';
12
12
  import type { Span, TraceExporter } from './observability.js';
13
13
  import type { ShellAdapter } from './shell-adapter.js';
14
14
  import type { SteeringDecision } from './steering.js';
@@ -47,7 +47,7 @@ interface ContextCallModelRequestBase {
47
47
  interface ContextCallModelRequestWithTools extends ContextCallModelRequestBase {
48
48
  tools: Tool[];
49
49
  ctx: Context;
50
- layers?: MemoryLayer[];
50
+ layers?: ContextLayer[];
51
51
  allowedToolNames?: string[];
52
52
  }
53
53
  interface ContextCallModelRequestWithoutTools extends ContextCallModelRequestBase {
@@ -84,8 +84,10 @@ export interface RestoreContextOptions {
84
84
  parent?: Context;
85
85
  /** Opaque per-execution state, same as `createContext({ state })`. */
86
86
  state?: unknown;
87
- /** Memory layers for the restored context. Defaults to the harness's configured layers. */
88
- memory?: MemoryLayer[];
87
+ /** Context layers for the restored context. Defaults to the harness's configured layers. */
88
+ context?: ContextLayer[];
89
+ /** @deprecated Renamed to `context`. */
90
+ memory?: ContextLayer[];
89
91
  }
90
92
  export interface ContextRerenderRequest {
91
93
  layerId: string;
@@ -102,10 +104,10 @@ export interface ContextRecallLayerOutput {
102
104
  items: import('./items.js').Item[];
103
105
  tokenCount: number;
104
106
  }
105
- export type ContextStep<TMemory = ContextMemory, I = unknown, O = unknown> = {
107
+ export type ContextStep<TContext = ContextData, I = unknown, O = unknown> = {
106
108
  readonly kind: 'run';
107
109
  readonly id: string;
108
- readonly execute: (input: I, ctx: Context<TMemory>) => Promise<O>;
110
+ readonly execute: (input: I, ctx: Context<TContext>) => Promise<O>;
109
111
  } | {
110
112
  readonly kind: 'llm';
111
113
  readonly id: string;
@@ -113,8 +115,8 @@ export type ContextStep<TMemory = ContextMemory, I = unknown, O = unknown> = {
113
115
  } | {
114
116
  readonly kind: 'loop';
115
117
  readonly id: string;
116
- readonly steps: ReadonlyArray<ContextStep<TMemory, I, O>>;
117
- readonly prepareNext?: (output: O, verdict: unknown, ctx: Context<TMemory>) => I;
118
+ readonly steps: ReadonlyArray<ContextStep<TContext, I, O>>;
119
+ readonly prepareNext?: (output: O, verdict: unknown, ctx: Context<TContext>) => I;
118
120
  } | {
119
121
  readonly kind: string;
120
122
  readonly id: string;
@@ -138,7 +140,7 @@ export interface ContextHarness {
138
140
  getTextStream(scope?: unknown): AsyncIterable<string>;
139
141
  getReasoningStream(scope?: unknown): AsyncIterable<string>;
140
142
  getFullStream(scope?: unknown): AsyncIterable<StreamEvent>;
141
- run<I, O>(step: ContextStep<ContextMemory, I, O>, input: I, ctx: Context): Promise<O>;
143
+ run<I, O>(step: ContextStep<ContextData, I, O>, input: I, ctx: Context): Promise<O>;
142
144
  detachedSpawn<I, O>(step: unknown, input: I, parentCtx: Context, overrides?: ContextDetachedSpawnOverrides): DetachedHandle<O>;
143
145
  createContext(opts?: {
144
146
  parent?: Context;
@@ -146,20 +148,22 @@ export interface ContextHarness {
146
148
  state?: unknown;
147
149
  threadId?: string;
148
150
  resourceId?: string;
149
- memory?: MemoryLayer[];
151
+ context?: ContextLayer[];
152
+ /** @deprecated Renamed to `context`. */
153
+ memory?: ContextLayer[];
150
154
  cwdInit?: string;
151
155
  }): Context;
152
156
  setRootCwd(nextCwd: string): void;
153
157
  getLayerState<T>(executionId: string, layerId: string): T | undefined;
154
158
  setLayerState<T>(executionId: string, layerId: string, state: T): void;
155
- beforeToolCall(layers: MemoryLayer[], toolName: string, toolArgs: unknown, ctx: Context): Promise<SteeringDecision>;
156
- afterModelCall(layers: MemoryLayer[], response: LLMResponse, ctx: Context): Promise<SteeringDecision>;
157
- runAppendPipeline(layers: MemoryLayer[], items: import('./items.js').Item[], ctx: Context): Promise<ContextAppendPipelineResult>;
158
- recallLayers(layers: MemoryLayer[], input: string, ctx: Context): Promise<ContextRecallLayerOutput[]>;
159
- recallLayersAtomic(layers: MemoryLayer[], input: string, ctx: Context, budgets: Map<string, number>): Promise<ContextRecallLayerOutput[]>;
160
- recallLayersEventual(layers: MemoryLayer[], input: string, ctx: Context, budgets: Map<string, number>): Promise<ContextRecallLayerOutput[]>;
161
- projectHistory(layers: MemoryLayer[], items: ReadonlyArray<import('./items.js').Item>, ctx: Context): Promise<ReadonlyArray<import('./items.js').Item>>;
162
- storeLayers(layers: MemoryLayer[], response: LLMResponse, ctx: Context): Promise<void>;
159
+ beforeToolCall(layers: ContextLayer[], toolName: string, toolArgs: unknown, ctx: Context): Promise<SteeringDecision>;
160
+ afterModelCall(layers: ContextLayer[], response: LLMResponse, ctx: Context): Promise<SteeringDecision>;
161
+ runAppendPipeline(layers: ContextLayer[], items: import('./items.js').Item[], ctx: Context): Promise<ContextAppendPipelineResult>;
162
+ recallLayers(layers: ContextLayer[], input: string, ctx: Context): Promise<ContextRecallLayerOutput[]>;
163
+ recallLayersAtomic(layers: ContextLayer[], input: string, ctx: Context, budgets: Map<string, number>): Promise<ContextRecallLayerOutput[]>;
164
+ recallLayersEventual(layers: ContextLayer[], input: string, ctx: Context, budgets: Map<string, number>): Promise<ContextRecallLayerOutput[]>;
165
+ projectHistory(layers: ContextLayer[], items: ReadonlyArray<import('./items.js').Item>, ctx: Context): Promise<ReadonlyArray<import('./items.js').Item>>;
166
+ storeLayers(layers: ContextLayer[], response: LLMResponse, ctx: Context): Promise<void>;
163
167
  previewRequestItems(scope?: unknown): Promise<ReadonlyArray<import('./items.js').Item>>;
164
168
  /**
165
169
  * Internal-sender channel write. Resolves immediately unless the target
@@ -173,13 +177,13 @@ export interface ContextHarness {
173
177
  }): Promise<T>;
174
178
  tryRecv<T>(channel: Channel<T>, ctx: Context): T | null;
175
179
  getChannelHandle<T>(channel: ExternalChannel<T>, executionId: string): ChannelHandle<T>;
176
- initLayers(layers: MemoryLayer[], ctx: Context, storage: StorageAdapter): Promise<void>;
177
- disposeLayers(layers: MemoryLayer[], ctx: Context): Promise<void>;
180
+ initLayers(layers: ContextLayer[], ctx: Context, storage: StorageAdapter): Promise<void>;
181
+ disposeLayers(layers: ContextLayer[], ctx: Context): Promise<void>;
178
182
  checkpoint(ctx: Context): Promise<void>;
179
183
  restore(executionId: string, opts?: RestoreContextOptions): Promise<Context | null>;
180
184
  /**
181
185
  * Cancel an execution: abort `ctx` and every live descendant context, then
182
- * run memory-layer teardown (`onComplete` with `outcome: 'aborted'`, then
186
+ * run context-layer teardown (`onComplete` with `outcome: 'aborted'`, then
183
187
  * `dispose`) bottom-up. A no-op on an already-cancelled context.
184
188
  */
185
189
  cancel(ctx: Context, reason?: string): Promise<void>;
@@ -190,17 +194,17 @@ export interface ContextHarness {
190
194
  getStatus(scope?: unknown): ContextHarnessStatus;
191
195
  getQueueSize(scope?: unknown): number;
192
196
  seedSessionHistory(threadId: string, items: ReadonlyArray<import('./items.js').Item>): void;
193
- executeRerender(requests: ContextRerenderRequest[], layers: MemoryLayer[], ctx: Context, budgets: Map<string, number>, query?: string): Promise<ContextRecallLayerOutput[]>;
197
+ executeRerender(requests: ContextRerenderRequest[], layers: ContextLayer[], ctx: Context, budgets: Map<string, number>, query?: string): Promise<ContextRecallLayerOutput[]>;
194
198
  }
195
199
  /** @public Execution context threaded through every step, carrying state, metrics, and channels. */
196
- export interface Context<TMemory = ContextMemory, TState = unknown> {
200
+ export interface Context<TContext = ContextData, TState = unknown> {
197
201
  readonly id: string;
198
202
  readonly stepCount: number;
199
203
  readonly tokens: TokenUsage;
200
204
  readonly elapsed: number;
201
205
  readonly cost: number;
202
206
  state: TState;
203
- readonly parent: Context<ContextMemory> | null;
207
+ readonly parent: Context<ContextData> | null;
204
208
  readonly depth: number;
205
209
  readonly span: Span;
206
210
  readonly threadId: string;
@@ -222,9 +226,17 @@ export interface Context<TMemory = ContextMemory, TState = unknown> {
222
226
  * agent `cd` propagates to subsequent tool calls.
223
227
  */
224
228
  readonly cwdState: CwdState;
225
- readonly layers?: MemoryLayer[];
226
- /** Layer provides keyed by layer ID. Access data/functions via `ctx.memory['layerId'].prop`. */
227
- readonly memory: TMemory;
229
+ readonly layers?: ContextLayer[];
230
+ /** Layer provides keyed by layer ID. Access data/functions via `ctx.context['layerId'].prop`. */
231
+ readonly context: TContext;
232
+ /**
233
+ * @deprecated Renamed to `context`. Reads through to the same object.
234
+ *
235
+ * Required, not optional: pre-rename code does `ctx.memory['layerId']`, and an
236
+ * optional field would make that a `possibly undefined` compile error — which
237
+ * is exactly the break this alias exists to prevent.
238
+ */
239
+ readonly memory: TContext;
228
240
  /** Unified tool set collected from all LLM steps in the step tree before execution. */
229
241
  readonly unifiedTools?: ReadonlyArray<Tool>;
230
242
  /** Runtime item schema registry active for this context. */
@@ -256,7 +268,7 @@ export interface Context<TMemory = ContextMemory, TState = unknown> {
256
268
  * Aborting rejects operations blocked on the context (channel `recv` waiters,
257
269
  * parked back-pressure senders) with `cancelled`, cuts short the in-flight
258
270
  * model call or sub-harness turn, and makes the next step boundary throw
259
- * `cancelled`. Memory-layer teardown is NOT run — use
271
+ * `cancelled`. Context-layer teardown is NOT run — use
260
272
  * `harness.cancel(ctx, reason)` for that.
261
273
  */
262
274
  abort(reason?: string): void;
@@ -34,7 +34,7 @@ export interface HarnessResponse {
34
34
  };
35
35
  readonly cost?: number;
36
36
  readonly text: string;
37
- /** Per-memory-layer context window breakdown captured at the last callModel of this execution. */
37
+ /** Per-context-layer context window breakdown captured at the last callModel of this execution. */
38
38
  readonly lastLayerUsage?: LastLayerUsage;
39
39
  }
40
40
  /** @public An Item snapshot with a completion flag, emitted from getItemStream(). */