@noetic-tools/types 2.2.0 → 3.0.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.
@@ -2,8 +2,8 @@ import type { ZodType } from 'zod';
2
2
  import type { Channel } from './channel.js';
3
3
  import type { ModelParams, RetryPolicy, ServerToolSpec, StepMeta } from './common.js';
4
4
  import type { Context } from './context.js';
5
+ import type { ContextConfig, ContextData, ContextLayer, ProjectionPolicy } from './context-layer.js';
5
6
  import type { NoeticError } from './error.js';
6
- import type { ContextMemory, MemoryConfig, MemoryLayer, ProjectionPolicy } from './memory.js';
7
7
  import type { OutputCodec } from './output-codec.js';
8
8
  import type { SubHarness, SubHarnessKind, SubHarnessSessionPolicy, SubHarnessSettings } from './sub-harness.js';
9
9
  import type { SubprocessAdapter } from './subprocess-adapter.js';
@@ -56,7 +56,7 @@ export type Until = (snapshot: Snapshot) => Verdict | Promise<Verdict>;
56
56
  * tool list). The getter runs at step execution time with the live context.
57
57
  * @public
58
58
  */
59
- export type Lazy<T, TMemory = ContextMemory> = T | ((ctx: Context<TMemory>) => T | Promise<T>);
59
+ export type Lazy<T, TContext = ContextData> = T | ((ctx: Context<TContext>) => T | Promise<T>);
60
60
  /**
61
61
  * Outcome of a single path in a `settle`-mode fork (mirrors `Promise.allSettled`).
62
62
  * @public
@@ -72,12 +72,12 @@ export interface SettleResult<O> {
72
72
  error?: NoeticError;
73
73
  }
74
74
  /** @public Discriminated union of all step kinds that can be composed into an execution tree. */
75
- export type Step<TMemory = ContextMemory, I = unknown, O = unknown> = StepRun<TMemory, I, O> | StepLLM<TMemory, I, O> | StepSubHarness<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>;
75
+ export type Step<TContext = ContextData, I = unknown, O = unknown> = StepRun<TContext, I, O> | StepLLM<TContext, I, O> | StepSubHarness<TContext, I, O> | StepTool<TContext, I, O> | StepBranch<TContext, I, O> | StepFork<TContext, I, O> | StepSpawn<TContext, I, O> | StepProvide<TContext, I, O> | StepLoop<TContext, I, O> | StepEvery<TContext, I, O>;
76
76
  /** @public A step that executes arbitrary async logic via a user-supplied function. */
77
- export interface StepRun<TMemory = ContextMemory, I = unknown, O = unknown> {
77
+ export interface StepRun<TContext = ContextData, I = unknown, O = unknown> {
78
78
  kind: 'run';
79
79
  id: string;
80
- execute: (input: I, ctx: Context<TMemory>) => Promise<O>;
80
+ execute: (input: I, ctx: Context<TContext>) => Promise<O>;
81
81
  retry?: RetryPolicy;
82
82
  /**
83
83
  * Per-step subprocess adapter override. When set, the interpreter
@@ -88,13 +88,13 @@ export interface StepRun<TMemory = ContextMemory, I = unknown, O = unknown> {
88
88
  subprocess?: SubprocessAdapter;
89
89
  }
90
90
  /** @public A step that sends a prompt to a language model and returns its response. */
91
- export interface StepLLM<TMemory = ContextMemory, _I = unknown, O = unknown> {
91
+ export interface StepLLM<TContext = ContextData, _I = unknown, O = unknown> {
92
92
  kind: 'llm';
93
93
  id: string;
94
94
  /** Model id. Accepts either an eager string or a `(ctx) => string` getter. */
95
- model: Lazy<string, TMemory>;
95
+ model: Lazy<string, TContext>;
96
96
  /** System instructions. Eager string or `(ctx) => string | undefined` getter. */
97
- instructions?: Lazy<string | undefined, TMemory>;
97
+ instructions?: Lazy<string | undefined, TContext>;
98
98
  /**
99
99
  * Tools exposed to the LLM. Eager array or `(ctx) => (...)[] | undefined` getter.
100
100
  * Entries are either a client `Tool` or an inline `ServerToolSpec` (an
@@ -102,7 +102,7 @@ export interface StepLLM<TMemory = ContextMemory, _I = unknown, O = unknown> {
102
102
  * Function-form tools do not contribute to the pre-computed `ctx.unifiedTools`;
103
103
  * they are resolved per execution.
104
104
  */
105
- tools?: Lazy<(Tool | ServerToolSpec)[] | undefined, TMemory>;
105
+ tools?: Lazy<(Tool | ServerToolSpec)[] | undefined, TContext>;
106
106
  /**
107
107
  * Structured output: a Zod schema (assistant text is JSON-parsed and
108
108
  * validated) or a streaming `OutputCodec` (fed each text delta, produces
@@ -122,7 +122,7 @@ export interface StepLLM<TMemory = ContextMemory, _I = unknown, O = unknown> {
122
122
  * interpreter handler.
123
123
  * @public
124
124
  */
125
- export interface StepSubHarness<TMemory = ContextMemory, _I = unknown, O = unknown> {
125
+ export interface StepSubHarness<TContext = ContextData, _I = unknown, O = unknown> {
126
126
  /** The harness kind, equal to the backing adapter's `harnessId`. */
127
127
  kind: SubHarnessKind;
128
128
  id: string;
@@ -131,13 +131,13 @@ export interface StepSubHarness<TMemory = ContextMemory, _I = unknown, O = unkno
131
131
  * Programmatic builders take it inline; the JSON hydrator resolves it from
132
132
  * the workflow's harness registry and inlines it here.
133
133
  */
134
- harness: Lazy<SubHarness, TMemory>;
134
+ harness: Lazy<SubHarness, TContext>;
135
135
  /** Turn prompt. Eager string or `(ctx) => string` getter. */
136
- prompt: Lazy<string, TMemory>;
136
+ prompt: Lazy<string, TContext>;
137
137
  /** Shared harness settings (model, permission mode, …). */
138
138
  settings?: SubHarnessSettings;
139
139
  /** System instructions applied on the first message of a fresh session. */
140
- instructions?: Lazy<string | undefined, TMemory>;
140
+ instructions?: Lazy<string | undefined, TContext>;
141
141
  /** When set, the assistant text is JSON-parsed and validated against this schema. */
142
142
  output?: ZodType<O>;
143
143
  /** Session reuse + teardown policy across steps. */
@@ -146,68 +146,68 @@ export interface StepSubHarness<TMemory = ContextMemory, _I = unknown, O = unkno
146
146
  emit?: boolean | ((eventType: string, data: Record<string, unknown>) => boolean);
147
147
  }
148
148
  /** @public A step that invokes a single tool directly, bypassing the LLM. */
149
- export interface StepTool<_TMemory = ContextMemory, I = unknown, O = unknown> {
149
+ export interface StepTool<_TContext = ContextData, I = unknown, O = unknown> {
150
150
  kind: 'tool';
151
151
  id: string;
152
152
  tool: Tool<ZodType<I>, ZodType<O>>;
153
153
  args?: Partial<I>;
154
154
  }
155
155
  /** @public A step that dynamically selects and executes one of several possible sub-steps. */
156
- export interface StepBranch<TMemory = ContextMemory, I = unknown, O = unknown> {
156
+ export interface StepBranch<TContext = ContextData, I = unknown, O = unknown> {
157
157
  kind: 'branch';
158
158
  id: string;
159
- route: (input: I, ctx: Context<TMemory>) => Step<TMemory, I, O> | null | Promise<Step<TMemory, I, O> | null>;
160
- _optimizable?: Step<TMemory>[];
159
+ route: (input: I, ctx: Context<TContext>) => Step<TContext, I, O> | null | Promise<Step<TContext, I, O> | null>;
160
+ _optimizable?: Step<TContext>[];
161
161
  }
162
162
  /** @public Union of fork step variants (`race`, `all`, `settle`) for concurrent path execution. */
163
- export type StepFork<TMemory = ContextMemory, I = unknown, O = unknown> = StepForkRace<TMemory, I, O> | StepForkAll<TMemory, I, O> | StepForkSettle<TMemory, I, O>;
163
+ export type StepFork<TContext = ContextData, I = unknown, O = unknown> = StepForkRace<TContext, I, O> | StepForkAll<TContext, I, O> | StepForkSettle<TContext, I, O>;
164
164
  /** @public A fork step that returns the result of the first path to complete. */
165
- export interface StepForkRace<TMemory = ContextMemory, I = unknown, O = unknown> {
165
+ export interface StepForkRace<TContext = ContextData, I = unknown, O = unknown> {
166
166
  kind: 'fork';
167
167
  id: string;
168
168
  mode: 'race';
169
- paths: (input: I, ctx: Context<TMemory>) => Step<TMemory, I, O>[];
169
+ paths: (input: I, ctx: Context<TContext>) => Step<TContext, I, O>[];
170
170
  concurrency?: number;
171
- _optimizable?: Step<TMemory>[];
171
+ _optimizable?: Step<TContext>[];
172
172
  }
173
173
  /** @public A fork step that runs all paths and merges their results. */
174
- export interface StepForkAll<TMemory = ContextMemory, I = unknown, O = unknown> {
174
+ export interface StepForkAll<TContext = ContextData, I = unknown, O = unknown> {
175
175
  kind: 'fork';
176
176
  id: string;
177
177
  mode: 'all';
178
- paths: (input: I, ctx: Context<TMemory>) => Step<TMemory, I, O>[];
179
- merge: (results: O[], ctx: Context<TMemory>) => O;
178
+ paths: (input: I, ctx: Context<TContext>) => Step<TContext, I, O>[];
179
+ merge: (results: O[], ctx: Context<TContext>) => O;
180
180
  concurrency?: number;
181
- _optimizable?: Step<TMemory>[];
181
+ _optimizable?: Step<TContext>[];
182
182
  }
183
183
  /** @public A fork step that runs all paths and collects fulfilled/rejected outcomes. */
184
- export interface StepForkSettle<TMemory = ContextMemory, I = unknown, O = unknown> {
184
+ export interface StepForkSettle<TContext = ContextData, I = unknown, O = unknown> {
185
185
  kind: 'fork';
186
186
  id: string;
187
187
  mode: 'settle';
188
- paths: (input: I, ctx: Context<TMemory>) => Step<TMemory, I, O>[];
189
- merge: (results: SettleResult<O>[], ctx: Context<TMemory>) => O;
188
+ paths: (input: I, ctx: Context<TContext>) => Step<TContext, I, O>[];
189
+ merge: (results: SettleResult<O>[], ctx: Context<TContext>) => O;
190
190
  concurrency?: number;
191
- _optimizable?: Step<TMemory>[];
191
+ _optimizable?: Step<TContext>[];
192
192
  }
193
193
  /**
194
- * A step that provides memory layers to its child without creating an isolated context.
194
+ * A step that provides context layers to its child without creating an isolated context.
195
195
  * Like React's Context.Provider — layers are available to all descendant steps.
196
196
  * Spawn and detachedSpawn break the inheritance chain.
197
197
  * @public
198
198
  */
199
- export interface StepProvide<TMemory = ContextMemory, I = unknown, O = unknown> {
199
+ export interface StepProvide<TContext = ContextData, I = unknown, O = unknown> {
200
200
  kind: 'provide';
201
201
  id: string;
202
- child: Step<TMemory, I, O>;
203
- memory: MemoryConfig | MemoryLayer[];
202
+ child: Step<TContext, I, O>;
203
+ context: ContextConfig | ContextLayer[];
204
204
  }
205
- /** @public A step that launches a child execution with its own memory scope. */
206
- export interface StepSpawn<TMemory = ContextMemory, I = unknown, O = unknown> {
205
+ /** @public A step that launches a child execution with its own context scope. */
206
+ export interface StepSpawn<TContext = ContextData, I = unknown, O = unknown> {
207
207
  kind: 'spawn';
208
208
  id: string;
209
- child: Step<TMemory, I, O>;
210
- memory?: MemoryConfig | MemoryLayer[];
209
+ child: Step<TContext, I, O>;
210
+ context?: ContextConfig | ContextLayer[];
211
211
  timeout?: number;
212
212
  /**
213
213
  * Per-step subprocess adapter override applied when the interpreter
@@ -220,12 +220,12 @@ export interface StepSpawn<TMemory = ContextMemory, I = unknown, O = unknown> {
220
220
  * A loop step that iterates a body step until a termination predicate is satisfied.
221
221
  * @public
222
222
  */
223
- export interface StepLoop<TMemory = ContextMemory, I = unknown, O = unknown> {
223
+ export interface StepLoop<TContext = ContextData, I = unknown, O = unknown> {
224
224
  kind: 'loop';
225
225
  /** Unique step identifier used in traces and error messages. */
226
226
  id: string;
227
227
  /** Steps to execute sequentially on each iteration. */
228
- steps: ReadonlyArray<Step<TMemory, I, O>>;
228
+ steps: ReadonlyArray<Step<TContext, I, O>>;
229
229
  /** Termination predicate evaluated after each iteration with a cumulative snapshot. */
230
230
  until: Until;
231
231
  /** Hard safety cap on iterations (default: 1000). */
@@ -237,9 +237,9 @@ export interface StepLoop<TMemory = ContextMemory, I = unknown, O = unknown> {
237
237
  /** Ms to wait on inbox before the loop parks itself (default: 0 = no parking). */
238
238
  parkTimeout?: number;
239
239
  /** Transforms the previous iteration's output into the next iteration's input. */
240
- prepareNext?: (output: O, verdict: Verdict, ctx: Context<TMemory>) => I;
240
+ prepareNext?: (output: O, verdict: Verdict, ctx: Context<TContext>) => I;
241
241
  /** Per-iteration error handler: retry the iteration, skip it, or abort the loop. */
242
- onError?: (error: NoeticError, ctx: Context<TMemory>) => 'retry' | 'skip' | 'abort';
242
+ onError?: (error: NoeticError, ctx: Context<TContext>) => 'retry' | 'skip' | 'abort';
243
243
  }
244
244
  /**
245
245
  * Error policy for the `every` operator when its body step throws.
@@ -257,12 +257,12 @@ export type EveryErrorPolicy = 'continue' | 'fail';
257
257
  *
258
258
  * @public
259
259
  */
260
- export interface StepEvery<TMemory = ContextMemory, I = unknown, O = unknown> {
260
+ export interface StepEvery<TContext = ContextData, I = unknown, O = unknown> {
261
261
  kind: 'every';
262
262
  /** Unique step identifier used in traces and error messages. */
263
263
  id: string;
264
264
  /** Body step executed on each iteration. */
265
- step: Step<TMemory, I, O>;
265
+ step: Step<TContext, I, O>;
266
266
  /** Park duration between iterations in milliseconds. Must be >= 0. */
267
267
  ms: number;
268
268
  /** Optional channel that wakes the parking interval when any value arrives. */
@@ -273,4 +273,4 @@ export interface StepEvery<TMemory = ContextMemory, I = unknown, O = unknown> {
273
273
  jitter?: number;
274
274
  }
275
275
  /** @public Function signature used by the interpreter to recursively execute a step. */
276
- export type ExecuteStepFn = <TMemory, I, O>(step: Step<TMemory, I, O>, input: I, ctx: Context<TMemory>) => Promise<O>;
276
+ export type ExecuteStepFn = <TContext, I, O>(step: Step<TContext, I, O>, input: I, ctx: Context<TContext>) => Promise<O>;
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * A "harness" here is a pluggable backend that drives an external agentic
5
5
  * coding tool — Claude Code, Codex, opencode, pi — as a Noetic step. It is the
6
- * direct analogue of the `MemoryLayer` contract: defined in the dependency-free
6
+ * direct analogue of the `ContextLayer` contract: defined in the dependency-free
7
7
  * `@noetic-tools/types` foundation so both `@noetic-tools/core` (which executes
8
8
  * harness steps) and the per-tool `@noetic-tools/sub-harness-*` packages (which
9
9
  * implement them) can depend on it without forming a cycle.
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * A "harness" here is a pluggable backend that drives an external agentic
5
5
  * coding tool — Claude Code, Codex, opencode, pi — as a Noetic step. It is the
6
- * direct analogue of the `MemoryLayer` contract: defined in the dependency-free
6
+ * direct analogue of the `ContextLayer` contract: defined in the dependency-free
7
7
  * `@noetic-tools/types` foundation so both `@noetic-tools/core` (which executes
8
8
  * harness steps) and the per-tool `@noetic-tools/sub-harness-*` packages (which
9
9
  * implement them) can depend on it without forming a cycle.
@@ -6,7 +6,7 @@ import type { Item } from './items.js';
6
6
  import type { AgentHarnessContract } from './runtime.js';
7
7
  import type { ShellAdapter } from './shell-adapter.js';
8
8
  /** @public Accessor for reading and writing per-layer state from within a tool execution. */
9
- export interface ToolMemory {
9
+ export interface ToolContext {
10
10
  get<T>(layerId: string): T | undefined;
11
11
  set<T>(layerId: string, state: T): void;
12
12
  }
@@ -23,8 +23,15 @@ export interface ToolExecutionContext {
23
23
  readonly fs: FsAdapter;
24
24
  /** Shell adapter for virtual or real shell command execution. */
25
25
  readonly shell: ShellAdapter;
26
- /** Per-layer memory accessor for reading/writing tool-specific state. */
27
- readonly memory: ToolMemory;
26
+ /** Per-layer state accessor for reading/writing tool-specific state. */
27
+ readonly context: ToolContext;
28
+ /**
29
+ * @deprecated Renamed to `context`. Returns the same accessor.
30
+ *
31
+ * Required for the same reason as `Context.memory` — pre-rename code calls
32
+ * `toolCtx.memory.get(...)` directly.
33
+ */
34
+ readonly memory: ToolContext;
28
35
  /** The fully assembled conversation view at the point of tool invocation. */
29
36
  readonly assembledView: ReadonlyArray<Item>;
30
37
  /** Metadata from the most recent step execution (token usage, tool calls, etc.). */
@@ -2,10 +2,10 @@ import type { ZodTypeAny, z } from 'zod';
2
2
  import type { FunctionCallItem, FunctionCallOutputItem, Item, ItemSchemaExtensions, ToolResultExtensionItem } from './items.js';
3
3
  type ToolExecutionResult<O extends ZodTypeAny> = Promise<z.infer<O>> | AsyncGenerator<unknown, z.infer<O>>;
4
4
  /**
5
- * Declares tool-owned memory that the runtime materializes into a MemoryLayer.
5
+ * Declares tool-owned state that the runtime materializes into a ContextLayer.
6
6
  * @public
7
7
  */
8
- export interface ToolMemoryDeclaration<TState = unknown> {
8
+ export interface ToolContextDeclaration<TState = unknown> {
9
9
  /** Shared id — tools with the same id share state. Defaults to `tool.name`. */
10
10
  id?: string;
11
11
  /** Factory for the initial state. */
@@ -13,8 +13,8 @@ export interface ToolMemoryDeclaration<TState = unknown> {
13
13
  /**
14
14
  * Project state into the LLM context. Return null to omit.
15
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.
16
+ * `ToolContextDeclaration<MyState>` assigns to the erased
17
+ * `ToolContextDeclaration` the `tool()` builder and runtime consume.
18
18
  */
19
19
  recall(state: TState): string | null;
20
20
  }
@@ -22,7 +22,7 @@ export interface ToolMemoryDeclaration<TState = unknown> {
22
22
  * A renderable UI fragment in a named dialect (e.g. `'openui-lang/0.5'`).
23
23
  * The framework never interprets `source` — it forwards fragments as
24
24
  * `openui.fragment` framework events and attaches them to items; a UI
25
- * surface (memory layer + transport) composes and renders them.
25
+ * surface (context layer + transport) composes and renders them.
26
26
  * @public
27
27
  */
28
28
  export interface UiFragment {
@@ -34,7 +34,7 @@ export interface UiFragment {
34
34
  /**
35
35
  * Declares tool-owned UI: programmatic render functions invoked at tool
36
36
  * lifecycle points. All methods are optional — an omitted point renders
37
- * nothing (mirrors `ToolMemoryDeclaration`). Declared as methods (bivariant
37
+ * nothing (mirrors `ToolContextDeclaration`). Declared as methods (bivariant
38
38
  * params) so a concretely-typed declaration assigns to the erased form the
39
39
  * `tool()` builder and runtime consume.
40
40
  * @public
@@ -89,8 +89,8 @@ export interface Tool<I extends ZodTypeAny = ZodTypeAny, O extends ZodTypeAny =
89
89
  execute(args: z.infer<I>, toolCtx: unknown): ToolExecutionResult<O>;
90
90
  /** When true, execution pauses for human approval before running. */
91
91
  needsApproval?: boolean;
92
- /** Optional memory declaration — the runtime generates a MemoryLayer from this. */
93
- memory?: ToolMemoryDeclaration;
92
+ /** Optional context declaration — the runtime generates a ContextLayer from this. */
93
+ context?: ToolContextDeclaration;
94
94
  /** Optional UI declaration — the runtime emits the rendered fragments at call/progress/result points. */
95
95
  ui?: ToolUiDeclaration<I, O>;
96
96
  }
@@ -20,10 +20,10 @@ export declare function isTextPart(part: {
20
20
  type: string;
21
21
  text: string;
22
22
  };
23
- /** Extracts assistant/output text from items for memory buffering (one string per message). */
23
+ /** Extracts assistant/output text from items for context buffering (one string per message). */
24
24
  export declare function collectOutputText(items: ReadonlyArray<Item>): string[];
25
25
  /**
26
- * Extracts text from INPUT items for memory buffering: concatenates the text
26
+ * Extracts text from INPUT items for context buffering: concatenates the text
27
27
  * content parts of message items (user `input_text` and any text parts) and
28
28
  * appends the `output` of `function_call_output` (tool result) items. Empty
29
29
  * strings are dropped.
@@ -25,7 +25,7 @@ export function isOutputText(part) {
25
25
  export function isTextPart(part) {
26
26
  return 'text' in part && typeof part.text === 'string';
27
27
  }
28
- /** Extracts assistant/output text from items for memory buffering (one string per message). */
28
+ /** Extracts assistant/output text from items for context buffering (one string per message). */
29
29
  export function collectOutputText(items) {
30
30
  return items
31
31
  .filter(isAssistantMessage)
@@ -36,7 +36,7 @@ export function collectOutputText(items) {
36
36
  .filter((t) => t.length > 0);
37
37
  }
38
38
  /**
39
- * Extracts text from INPUT items for memory buffering: concatenates the text
39
+ * Extracts text from INPUT items for context buffering: concatenates the text
40
40
  * content parts of message items (user `input_text` and any text parts) and
41
41
  * appends the `output` of `function_call_output` (tool result) items. Empty
42
42
  * strings are dropped.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noetic-tools/types",
3
- "version": "2.2.0",
3
+ "version": "3.0.0",
4
4
  "type": "module",
5
5
  "description": "Foundational type contracts and primitives shared across the Noetic framework (items, LLM config, adapters, steering, errors).",
6
6
  "license": "Apache-2.0",
@@ -27,8 +27,8 @@
27
27
  "default": "./dist/index.js"
28
28
  },
29
29
  "./contract": {
30
- "types": "./dist/types/memory.d.ts",
31
- "default": "./dist/types/memory.js"
30
+ "types": "./dist/types/context-layer.d.ts",
31
+ "default": "./dist/types/context-layer.js"
32
32
  },
33
33
  "./package.json": "./package.json"
34
34
  },
File without changes