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