@noetic-tools/core 0.2.1 → 1.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.
- package/dist/adapters/in-memory-fs-adapter.d.ts +1 -1
- package/dist/adapters/in-memory-fs-adapter.js +1 -1
- package/dist/adapters/in-memory-shell-adapter.d.ts +1 -1
- package/dist/adapters/in-memory-subprocess/manifest-persistence.d.ts +2 -2
- package/dist/adapters/in-memory-subprocess/metadata.d.ts +1 -1
- package/dist/adapters/in-memory-subprocess/types.d.ts +2 -2
- package/dist/adapters/in-memory-subprocess-adapter.d.ts +1 -1
- package/dist/adapters/openrouter.d.ts +2 -6
- package/dist/adapters/openrouter.js +1 -4
- package/dist/builders/channel-builder.d.ts +1 -1
- package/dist/builders/control-flow-builders.d.ts +2 -3
- package/dist/builders/control-flow-builders.js +1 -2
- package/dist/builders/every.d.ts +2 -3
- package/dist/builders/every.js +1 -1
- package/dist/builders/layer-provides-builders.d.ts +1 -1
- package/dist/builders/layer-provides-builders.js +1 -1
- package/dist/builders/loop-builder.d.ts +2 -2
- package/dist/builders/loop-builder.js +1 -1
- package/dist/builders/memory-builder.d.ts +1 -1
- package/dist/builders/memory-builder.js +1 -1
- package/dist/builders/provide-builder.d.ts +2 -2
- package/dist/builders/provide-builder.js +1 -1
- package/dist/builders/spawn-builder.d.ts +2 -3
- package/dist/builders/spawn-builder.js +1 -1
- package/dist/builders/step-builders.d.ts +2 -6
- package/dist/builders/step-builders.js +1 -1
- package/dist/builders/tool-builder.d.ts +1 -3
- package/dist/builders/tool-builder.js +1 -1
- package/dist/builders/workflow-hydrator.d.ts +2 -3
- package/dist/builders/workflow-hydrator.js +1 -2
- package/dist/conditions/conditions.d.ts +2 -3
- package/dist/conditions/conditions.js +1 -1
- package/dist/harness/agent-harness.d.ts +15 -5
- package/dist/harness/agent-harness.js +65 -10
- package/dist/harness/deps/memory.d.ts +2 -5
- package/dist/harness/deps/memory.js +1 -4
- package/dist/harness/deps/types.d.ts +3 -16
- package/dist/harness/deps/types.js +1 -1
- package/dist/harness/model-call.d.ts +1 -3
- package/dist/harness/model-call.js +10 -10
- package/dist/harness/model-schema.d.ts +10 -4
- package/dist/harness/model-schema.js +9 -1
- package/dist/index.d.ts +28 -49
- package/dist/index.js +9 -27
- package/dist/interpreter/action-deps.d.ts +4 -8
- package/dist/interpreter/action-deps.js +2 -6
- package/dist/interpreter/action-types.d.ts +3 -8
- package/dist/interpreter/action-types.js +1 -1
- package/dist/interpreter/collect-tools.d.ts +1 -2
- package/dist/interpreter/collect-tools.js +1 -1
- package/dist/interpreter/execute-action.js +122 -27
- package/dist/interpreter/execute-control.d.ts +1 -2
- package/dist/interpreter/execute-control.js +60 -7
- package/dist/interpreter/execute.d.ts +2 -3
- package/dist/interpreter/execute.js +1 -2
- package/dist/interpreter/message-helpers.d.ts +1 -1
- package/dist/interpreter/message-helpers.js +1 -1
- package/dist/interpreter/step-dispatcher.d.ts +2 -5
- package/dist/interpreter/typeguards.d.ts +3 -4
- package/dist/interpreter/typeguards.js +1 -1
- package/dist/observability/span-impl.d.ts +1 -1
- package/dist/observability/trace-exporter.d.ts +1 -1
- package/dist/patterns/dynamic-workflow.d.ts +2 -5
- package/dist/patterns/dynamic-workflow.js +1 -2
- package/dist/patterns/flow.d.ts +2 -2
- package/dist/patterns/flow.js +1 -1
- package/dist/patterns/interview.d.ts +2 -2
- package/dist/patterns/interview.js +1 -1
- package/dist/patterns/plans.d.ts +2 -3
- package/dist/patterns/plans.js +1 -1
- package/dist/patterns/ralph-wiggum.d.ts +2 -3
- package/dist/patterns/react.d.ts +2 -3
- package/dist/portable/memory-layers.d.ts +1 -7
- package/dist/portable/memory-layers.js +1 -7
- package/dist/portable.d.ts +2 -2
- package/dist/portable.js +2 -2
- package/dist/runtime/broadcaster-utils.d.ts +1 -1
- package/dist/runtime/channel-store.d.ts +43 -3
- package/dist/runtime/channel-store.js +233 -37
- package/dist/runtime/context-deps.d.ts +3 -3
- package/dist/runtime/context-deps.js +2 -2
- package/dist/runtime/context-impl.d.ts +17 -1
- package/dist/runtime/context-impl.js +30 -3
- package/dist/runtime/context-type-deps.d.ts +2 -11
- package/dist/runtime/cwd-helpers.d.ts +1 -1
- package/dist/runtime/detached-handle.d.ts +2 -3
- package/dist/runtime/detached-handle.js +1 -3
- package/dist/runtime/durable/checkpoint-store.d.ts +1 -1
- package/dist/runtime/durable/checkpoint-store.js +1 -1
- package/dist/runtime/durable/harness-checkpoints.d.ts +2 -5
- package/dist/runtime/durable/runnable-loop.d.ts +1 -3
- package/dist/runtime/durable/session-seed.d.ts +1 -1
- package/dist/runtime/durable/stall-nudge.d.ts +17 -10
- package/dist/runtime/durable/stall-nudge.js +29 -10
- package/dist/runtime/event-broadcaster.d.ts +10 -2
- package/dist/runtime/event-broadcaster.js +43 -19
- package/dist/runtime/in-memory-storage.d.ts +1 -1
- package/dist/runtime/in-memory-storage.js +1 -1
- package/dist/runtime/item-log-impl.d.ts +1 -3
- package/dist/runtime/item-log-impl.js +1 -1
- package/dist/runtime/message-queue.d.ts +1 -2
- package/dist/runtime/session-runner.d.ts +1 -4
- package/dist/runtime/session-streams.d.ts +1 -2
- package/dist/runtime/session-streams.js +1 -1
- package/dist/runtime/step-registry.d.ts +2 -2
- package/dist/runtime/step-registry.js +1 -2
- package/dist/runtime/tool-memory.d.ts +1 -3
- package/dist/types/mutable-context.d.ts +2 -3
- package/dist/types/step-registrar.d.ts +1 -1
- package/dist/unstable.d.ts +5 -9
- package/dist/unstable.js +3 -6
- package/dist/until/combinators.d.ts +1 -1
- package/dist/until/never.d.ts +1 -1
- package/dist/until/predicates.d.ts +2 -2
- package/package.json +4 -2
- package/dist/errors/noetic-config-error.d.ts +0 -41
- package/dist/errors/noetic-config-error.js +0 -44
- package/dist/errors/noetic-error.d.ts +0 -18
- package/dist/errors/noetic-error.js +0 -54
- package/dist/memory/budget.d.ts +0 -23
- package/dist/memory/budget.js +0 -117
- package/dist/memory/exec-context-factory.d.ts +0 -25
- package/dist/memory/exec-context-factory.js +0 -30
- package/dist/memory/flow-schema.d.ts +0 -52
- package/dist/memory/flow-schema.js +0 -102
- package/dist/memory/function-call-utils.d.ts +0 -6
- package/dist/memory/function-call-utils.js +0 -27
- package/dist/memory/layer-api.d.ts +0 -14
- package/dist/memory/layer-api.js +0 -91
- package/dist/memory/layer-lifecycle.d.ts +0 -160
- package/dist/memory/layer-lifecycle.js +0 -552
- package/dist/memory/layer-provides.d.ts +0 -32
- package/dist/memory/layer-provides.js +0 -33
- package/dist/memory/layer-usage.d.ts +0 -16
- package/dist/memory/layer-usage.js +0 -54
- package/dist/memory/layers/durable-task-state.d.ts +0 -79
- package/dist/memory/layers/durable-task-state.js +0 -118
- package/dist/memory/layers/file-reference.d.ts +0 -55
- package/dist/memory/layers/file-reference.js +0 -594
- package/dist/memory/layers/history-window.d.ts +0 -29
- package/dist/memory/layers/history-window.js +0 -114
- package/dist/memory/layers/observational-memory.d.ts +0 -53
- package/dist/memory/layers/observational-memory.js +0 -109
- package/dist/memory/layers/plan.d.ts +0 -55
- package/dist/memory/layers/plan.js +0 -374
- package/dist/memory/layers/static-content.d.ts +0 -27
- package/dist/memory/layers/static-content.js +0 -35
- package/dist/memory/layers/steering.d.ts +0 -51
- package/dist/memory/layers/steering.js +0 -258
- package/dist/memory/layers/temporal.d.ts +0 -91
- package/dist/memory/layers/temporal.js +0 -245
- package/dist/memory/layers/tool-memory-layer.d.ts +0 -16
- package/dist/memory/layers/tool-memory-layer.js +0 -43
- package/dist/memory/layers/working-memory.d.ts +0 -44
- package/dist/memory/layers/working-memory.js +0 -92
- package/dist/memory/projector.d.ts +0 -10
- package/dist/memory/projector.js +0 -19
- package/dist/memory/scope.d.ts +0 -3
- package/dist/memory/scope.js +0 -31
- package/dist/memory/strip-unresolved.d.ts +0 -13
- package/dist/memory/strip-unresolved.js +0 -35
- package/dist/schemas/item.d.ts +0 -35
- package/dist/schemas/item.js +0 -155
- package/dist/types/channel.d.ts +0 -29
- package/dist/types/channel.js +0 -1
- package/dist/types/common.d.ts +0 -68
- package/dist/types/common.js +0 -1
- package/dist/types/context-parts/item-log.d.ts +0 -6
- package/dist/types/context-parts/item-log.js +0 -1
- package/dist/types/context-parts/layer-usage.d.ts +0 -18
- package/dist/types/context-parts/layer-usage.js +0 -1
- package/dist/types/context.d.ts +0 -202
- package/dist/types/context.js +0 -1
- package/dist/types/detached.d.ts +0 -17
- package/dist/types/detached.js +0 -7
- package/dist/types/error.d.ts +0 -66
- package/dist/types/error.js +0 -1
- package/dist/types/fs-adapter.d.ts +0 -51
- package/dist/types/fs-adapter.js +0 -3
- package/dist/types/harness-result.d.ts +0 -43
- package/dist/types/harness-result.js +0 -2
- package/dist/types/items.d.ts +0 -131
- package/dist/types/items.js +0 -2
- package/dist/types/memory-context.d.ts +0 -39
- package/dist/types/memory-context.js +0 -1
- package/dist/types/memory.d.ts +0 -306
- package/dist/types/memory.js +0 -13
- package/dist/types/observability.d.ts +0 -30
- package/dist/types/observability.js +0 -1
- package/dist/types/runtime.d.ts +0 -256
- package/dist/types/runtime.js +0 -1
- package/dist/types/shell-adapter.d.ts +0 -34
- package/dist/types/shell-adapter.js +0 -10
- package/dist/types/steering.d.ts +0 -89
- package/dist/types/steering.js +0 -14
- package/dist/types/step.d.ts +0 -231
- package/dist/types/step.js +0 -1
- package/dist/types/subprocess-adapter.d.ts +0 -157
- package/dist/types/subprocess-adapter.js +0 -3
- package/dist/types/tool-context.d.ts +0 -34
- package/dist/types/tool-context.js +0 -1
- package/dist/types/tool.d.ts +0 -64
- package/dist/types/tool.js +0 -1
- package/dist/util/framework-cast.d.ts +0 -10
- package/dist/util/framework-cast.js +0 -16
- package/dist/util/message-helpers.d.ts +0 -17
- package/dist/util/message-helpers.js +0 -64
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* History-window memory layer — caps the number of items projected to the LLM
|
|
3
|
-
* without touching `itemLog` storage. Pure read-side projection via the
|
|
4
|
-
* `projectHistory` hook.
|
|
5
|
-
*
|
|
6
|
-
* Algorithm per turn:
|
|
7
|
-
* 1. Slice the last `maxItems`.
|
|
8
|
-
* 2. If the slice lacks a user `message` or an assistant `message`, expand
|
|
9
|
-
* backward until both are present. The cap may be exceeded — for
|
|
10
|
-
* tool-burst histories the projected length can grow well beyond
|
|
11
|
-
* `maxItems` because the most recent role-pair may be far back.
|
|
12
|
-
* 3. Drop any orphan `function_call` / `function_call_output` left at the
|
|
13
|
-
* slice boundary via `stripUnresolvedToolCalls`.
|
|
14
|
-
*/
|
|
15
|
-
import { NoeticConfigError } from '../../errors/noetic-config-error.js';
|
|
16
|
-
import { Slot } from '../../types/memory.js';
|
|
17
|
-
import { isAssistantMessage, isUserMessage } from '../../util/message-helpers.js';
|
|
18
|
-
import { stripUnresolvedToolCalls } from '../strip-unresolved.js';
|
|
19
|
-
//#region Constants
|
|
20
|
-
const DEFAULT_MAX_ITEMS = 40;
|
|
21
|
-
const MIN_MAX_ITEMS = 2;
|
|
22
|
-
const MAX_MAX_ITEMS = 1e4;
|
|
23
|
-
const HISTORY_WINDOW_SLOT = Slot.PROCEDURAL + 25; // 275 — runs after recall-contributing layers
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region Helpers
|
|
26
|
-
function validateMaxItems(value) {
|
|
27
|
-
if (!Number.isInteger(value) || value < MIN_MAX_ITEMS || value > MAX_MAX_ITEMS) {
|
|
28
|
-
throw new NoeticConfigError({
|
|
29
|
-
code: 'INVALID_HISTORY_WINDOW_MAX_ITEMS',
|
|
30
|
-
message: `historyWindow: maxItems must be an integer in [${MIN_MAX_ITEMS}, ${MAX_MAX_ITEMS}], got ${value}`,
|
|
31
|
-
hint: 'Pass a sensible cap such as { maxItems: 40 }, or omit the layer to keep history uncapped.',
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Walk backwards from the natural slice point until both a user message and
|
|
37
|
-
* an assistant message are present. Returns the index at which the projected
|
|
38
|
-
* window should start in the full `items` array.
|
|
39
|
-
*/
|
|
40
|
-
function expandToMinimumExchange(items, sliceStart) {
|
|
41
|
-
let start = sliceStart;
|
|
42
|
-
let needsUser = true;
|
|
43
|
-
let needsAssistant = true;
|
|
44
|
-
// Pass 1: scan the natural slice for the user/assistant pair. Early-return
|
|
45
|
-
// at the original sliceStart when both roles are already inside.
|
|
46
|
-
for (let i = items.length - 1; i >= start; i--) {
|
|
47
|
-
const item = items[i];
|
|
48
|
-
if (needsUser && isUserMessage(item)) {
|
|
49
|
-
needsUser = false;
|
|
50
|
-
}
|
|
51
|
-
if (needsAssistant && isAssistantMessage(item)) {
|
|
52
|
-
needsAssistant = false;
|
|
53
|
-
}
|
|
54
|
-
if (!needsUser && !needsAssistant) {
|
|
55
|
-
return start;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
// Pass 2: walk backward past the slice until the missing role(s) are found.
|
|
59
|
-
for (let i = start - 1; i >= 0 && (needsUser || needsAssistant); i--) {
|
|
60
|
-
const item = items[i];
|
|
61
|
-
if (needsUser && isUserMessage(item)) {
|
|
62
|
-
needsUser = false;
|
|
63
|
-
start = i;
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
if (needsAssistant && isAssistantMessage(item)) {
|
|
67
|
-
needsAssistant = false;
|
|
68
|
-
start = i;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return start;
|
|
72
|
-
}
|
|
73
|
-
//#endregion
|
|
74
|
-
//#region Public API
|
|
75
|
-
/**
|
|
76
|
-
* Creates a history-window memory layer that caps the trailing items projected
|
|
77
|
-
* to the LLM. Storage stays unbounded; only the wire payload is narrowed.
|
|
78
|
-
*
|
|
79
|
-
* @public
|
|
80
|
-
* @param config - Optional `{ maxItems }`. Defaults to 40.
|
|
81
|
-
* @returns A `MemoryLayer` that contributes only a `projectHistory` hook.
|
|
82
|
-
*/
|
|
83
|
-
export function historyWindow(config) {
|
|
84
|
-
const maxItems = config?.maxItems ?? DEFAULT_MAX_ITEMS;
|
|
85
|
-
validateMaxItems(maxItems);
|
|
86
|
-
return {
|
|
87
|
-
id: 'history-window',
|
|
88
|
-
name: 'History Window',
|
|
89
|
-
slot: HISTORY_WINDOW_SLOT,
|
|
90
|
-
scope: 'execution',
|
|
91
|
-
hooks: {
|
|
92
|
-
async init() {
|
|
93
|
-
return {
|
|
94
|
-
state: null,
|
|
95
|
-
};
|
|
96
|
-
},
|
|
97
|
-
async projectHistory({ items }) {
|
|
98
|
-
if (items.length <= maxItems) {
|
|
99
|
-
return {
|
|
100
|
-
items,
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
const sliceStart = items.length - maxItems;
|
|
104
|
-
const expandedStart = expandToMinimumExchange(items, sliceStart);
|
|
105
|
-
const window = items.slice(expandedStart);
|
|
106
|
-
const cleaned = stripUnresolvedToolCalls(window);
|
|
107
|
-
return {
|
|
108
|
-
items: cleaned,
|
|
109
|
-
};
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
//#endregion
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
export interface ObservationalState {
|
|
2
|
-
observations: string[];
|
|
3
|
-
buffer: string[];
|
|
4
|
-
bufferTokens: number;
|
|
5
|
-
version: number;
|
|
6
|
-
}
|
|
7
|
-
export type ObserverFn = (buffer: string[]) => Promise<string[]>;
|
|
8
|
-
export interface ObservationalMemoryConfig {
|
|
9
|
-
bufferThreshold?: number;
|
|
10
|
-
maxObservations?: number;
|
|
11
|
-
scope?: 'thread' | 'resource';
|
|
12
|
-
observer?: ObserverFn;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Creates a memory layer that buffers raw items and distills them into observations when a token threshold is reached.
|
|
16
|
-
*
|
|
17
|
-
* @public
|
|
18
|
-
* @param config - Optional configuration for buffer threshold, max observations, scope, and observer function.
|
|
19
|
-
* @returns A `MemoryLayer` that accumulates and summarizes observations over time.
|
|
20
|
-
*/
|
|
21
|
-
export declare function observationalMemory(config?: ObservationalMemoryConfig): {
|
|
22
|
-
id: "observational-memory";
|
|
23
|
-
name: string;
|
|
24
|
-
slot: 200;
|
|
25
|
-
scope: "thread" | "resource";
|
|
26
|
-
budget: {
|
|
27
|
-
min: number;
|
|
28
|
-
max: number;
|
|
29
|
-
};
|
|
30
|
-
timeouts: {
|
|
31
|
-
store: number;
|
|
32
|
-
};
|
|
33
|
-
hooks: {
|
|
34
|
-
init({ storage }: import("../../index.js").InitParams): Promise<{
|
|
35
|
-
state: ObservationalState;
|
|
36
|
-
}>;
|
|
37
|
-
recall({ state }: import("../../index.js").RecallParams<ObservationalState>): Promise<{
|
|
38
|
-
items: import("../../index.js").InputMessageItem[];
|
|
39
|
-
tokenCount: number;
|
|
40
|
-
} | null>;
|
|
41
|
-
store({ newItems, state }: import("../../index.js").StoreParams<ObservationalState>): Promise<{
|
|
42
|
-
state: {
|
|
43
|
-
buffer: string[];
|
|
44
|
-
bufferTokens: number;
|
|
45
|
-
observations: string[];
|
|
46
|
-
version: number;
|
|
47
|
-
};
|
|
48
|
-
}>;
|
|
49
|
-
onSpawn({ parentState }: import("../../index.js").SpawnParams<ObservationalState>): Promise<{
|
|
50
|
-
childState: ObservationalState;
|
|
51
|
-
}>;
|
|
52
|
-
};
|
|
53
|
-
};
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { Slot } from '../../types/memory.js';
|
|
2
|
-
import { createMessage, estimateTokens, isOutputText } from '../../util/message-helpers.js';
|
|
3
|
-
const DEFAULT_BUFFER_THRESHOLD_TOKENS = 2_000;
|
|
4
|
-
const DEFAULT_MAX_OBSERVATIONS = 50;
|
|
5
|
-
/**
|
|
6
|
-
* Creates a memory layer that buffers raw items and distills them into observations when a token threshold is reached.
|
|
7
|
-
*
|
|
8
|
-
* @public
|
|
9
|
-
* @param config - Optional configuration for buffer threshold, max observations, scope, and observer function.
|
|
10
|
-
* @returns A `MemoryLayer` that accumulates and summarizes observations over time.
|
|
11
|
-
*/
|
|
12
|
-
export function observationalMemory(config) {
|
|
13
|
-
const maxObs = config?.maxObservations ?? DEFAULT_MAX_OBSERVATIONS;
|
|
14
|
-
const threshold = config?.bufferThreshold ?? DEFAULT_BUFFER_THRESHOLD_TOKENS;
|
|
15
|
-
const observer = config?.observer;
|
|
16
|
-
return {
|
|
17
|
-
id: 'observational-memory',
|
|
18
|
-
name: 'Observational Memory',
|
|
19
|
-
slot: Slot.OBSERVATIONS,
|
|
20
|
-
scope: config?.scope ?? 'resource',
|
|
21
|
-
budget: {
|
|
22
|
-
min: 500,
|
|
23
|
-
max: 2_500,
|
|
24
|
-
},
|
|
25
|
-
timeouts: {
|
|
26
|
-
store: 60_000,
|
|
27
|
-
},
|
|
28
|
-
hooks: {
|
|
29
|
-
async init({ storage }) {
|
|
30
|
-
const saved = await storage.get('state');
|
|
31
|
-
return {
|
|
32
|
-
state: saved ?? {
|
|
33
|
-
observations: [],
|
|
34
|
-
buffer: [],
|
|
35
|
-
bufferTokens: 0,
|
|
36
|
-
version: 0,
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
},
|
|
40
|
-
async recall({ state }) {
|
|
41
|
-
if (!state?.observations?.length) {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
const bullets = state.observations.map((o) => `- ${o}`).join('\n');
|
|
45
|
-
const text = `<observations>\n${bullets}\n</observations>`;
|
|
46
|
-
return {
|
|
47
|
-
items: [
|
|
48
|
-
createMessage(text, 'developer'),
|
|
49
|
-
],
|
|
50
|
-
tokenCount: estimateTokens(text),
|
|
51
|
-
};
|
|
52
|
-
},
|
|
53
|
-
async store({ newItems, state }) {
|
|
54
|
-
const s = state ?? {
|
|
55
|
-
observations: [],
|
|
56
|
-
buffer: [],
|
|
57
|
-
bufferTokens: 0,
|
|
58
|
-
version: 0,
|
|
59
|
-
};
|
|
60
|
-
// Accumulate new items into buffer
|
|
61
|
-
const textItems = newItems
|
|
62
|
-
.filter((i) => i.type === 'message')
|
|
63
|
-
.map((i) => i.content
|
|
64
|
-
.filter(isOutputText)
|
|
65
|
-
.map((c) => c.text)
|
|
66
|
-
.join(''))
|
|
67
|
-
.filter((t) => t.length > 0);
|
|
68
|
-
const newBuffer = [
|
|
69
|
-
...s.buffer,
|
|
70
|
-
...textItems,
|
|
71
|
-
];
|
|
72
|
-
// Token-based threshold: accumulate incrementally
|
|
73
|
-
const newTokens = textItems.reduce((sum, t) => sum + estimateTokens(t), 0);
|
|
74
|
-
const totalBufferTokens = s.bufferTokens + newTokens;
|
|
75
|
-
if (totalBufferTokens >= threshold) {
|
|
76
|
-
const distilled = observer
|
|
77
|
-
? await observer(newBuffer)
|
|
78
|
-
: [
|
|
79
|
-
`Processed ${newBuffer.length} items`,
|
|
80
|
-
];
|
|
81
|
-
const newObservations = [
|
|
82
|
-
...s.observations,
|
|
83
|
-
...distilled,
|
|
84
|
-
].slice(-maxObs);
|
|
85
|
-
return {
|
|
86
|
-
state: {
|
|
87
|
-
observations: newObservations,
|
|
88
|
-
buffer: [],
|
|
89
|
-
bufferTokens: 0,
|
|
90
|
-
version: s.version + 1,
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
return {
|
|
95
|
-
state: {
|
|
96
|
-
...s,
|
|
97
|
-
buffer: newBuffer,
|
|
98
|
-
bufferTokens: totalBufferTokens,
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
|
-
},
|
|
102
|
-
async onSpawn({ parentState }) {
|
|
103
|
-
return {
|
|
104
|
-
childState: structuredClone(parentState),
|
|
105
|
-
};
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
};
|
|
109
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { MemoryLayer, MemoryScope } from '../../types/memory.js';
|
|
2
|
-
import type { FlowNode } from '../flow-schema.js';
|
|
3
|
-
export declare const PlanPhase: {
|
|
4
|
-
readonly Idle: "idle";
|
|
5
|
-
readonly Planning: "planning";
|
|
6
|
-
readonly Executing: "executing";
|
|
7
|
-
readonly Completed: "completed";
|
|
8
|
-
readonly Failed: "failed";
|
|
9
|
-
};
|
|
10
|
-
export type PlanPhase = (typeof PlanPhase)[keyof typeof PlanPhase];
|
|
11
|
-
export interface PlanExecutionEntry {
|
|
12
|
-
timestamp: number;
|
|
13
|
-
version: number;
|
|
14
|
-
outcome: 'success' | 'failure' | 'aborted';
|
|
15
|
-
}
|
|
16
|
-
export interface PlanState {
|
|
17
|
-
phase: PlanPhase;
|
|
18
|
-
prd: string | null;
|
|
19
|
-
planTree: FlowNode | null;
|
|
20
|
-
executionLog: PlanExecutionEntry[];
|
|
21
|
-
version: number;
|
|
22
|
-
/** Identifier of the on-disk plan session (set by `onEnterSession` host callback). */
|
|
23
|
-
planSlug?: string | null;
|
|
24
|
-
}
|
|
25
|
-
/** Host-supplied callback invoked when entering plan mode. Returns a session identifier the host owns (e.g. on-disk dir slug). */
|
|
26
|
-
export type PlanEnterSessionCallback = () => Promise<{
|
|
27
|
-
slug: string;
|
|
28
|
-
}>;
|
|
29
|
-
/**
|
|
30
|
-
* Host-supplied callback invoked when the model requests `exitPlanMode` with `action: 'execute'`.
|
|
31
|
-
* Return `{ approved: false }` to keep the layer in `Planning` (e.g. user rejected the plan in the UI).
|
|
32
|
-
*/
|
|
33
|
-
export type PlanExitCallback = (state: PlanState) => Promise<{
|
|
34
|
-
approved: boolean;
|
|
35
|
-
}>;
|
|
36
|
-
export interface PlanMemoryConfig {
|
|
37
|
-
scope?: MemoryScope;
|
|
38
|
-
additionalAllowedTools?: string[];
|
|
39
|
-
maxPrdLength?: number;
|
|
40
|
-
maxTreeDepth?: number;
|
|
41
|
-
/** Extra free-form instructions appended to the planning-phase recall payload. */
|
|
42
|
-
additionalPlanInstructions?: string;
|
|
43
|
-
/** Called once when the layer transitions Idle → Planning. */
|
|
44
|
-
onEnterSession?: PlanEnterSessionCallback;
|
|
45
|
-
/** Called when `exitPlanMode` is requested with `action: 'execute'`. */
|
|
46
|
-
onExit?: PlanExitCallback;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Creates a plan memory layer that manages the PRD authoring and plan execution lifecycle.
|
|
50
|
-
*
|
|
51
|
-
* @public
|
|
52
|
-
* @param config - Optional configuration for scope, allowed tools, and limits.
|
|
53
|
-
* @returns A `MemoryLayer` providing plan mode, PRD storage, and execution tracking.
|
|
54
|
-
*/
|
|
55
|
-
export declare function planMemory(config?: PlanMemoryConfig): MemoryLayer<PlanState>;
|