@noetic-tools/core 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +13 -3
- package/dist/harness/agent-harness.js +48 -5
- 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 +1 -2
- package/dist/harness/model-schema.d.ts +2 -4
- package/dist/harness/model-schema.js +1 -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 +104 -26
- package/dist/interpreter/execute-control.d.ts +1 -2
- package/dist/interpreter/execute-control.js +1 -3
- 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 +1 -1
- package/dist/runtime/channel-store.js +1 -2
- package/dist/runtime/context-deps.d.ts +3 -3
- package/dist/runtime/context-deps.js +2 -2
- 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 +1 -1
- package/dist/runtime/event-broadcaster.d.ts +1 -1
- 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 +6 -4
- 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,374 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { Slot } from '../../types/memory.js';
|
|
3
|
-
import { SteeringAction } from '../../types/steering.js';
|
|
4
|
-
import { createMessage, estimateTokens } from '../../util/message-helpers.js';
|
|
5
|
-
import { FlowSchema, flowDepth } from '../flow-schema.js';
|
|
6
|
-
import { layerData, layerFn } from '../layer-provides.js';
|
|
7
|
-
//#region Constants
|
|
8
|
-
const MAX_PRD_LENGTH = 5e4;
|
|
9
|
-
const MAX_TREE_DEPTH = 5;
|
|
10
|
-
const MAX_EXECUTION_LOG_ENTRIES = 10;
|
|
11
|
-
const PLAN_SLOT = Slot.PROCEDURAL - 10; // 240
|
|
12
|
-
const ALLOWED_TOOLS_IN_PLAN_MODE = new Set([
|
|
13
|
-
'Read',
|
|
14
|
-
'Grep',
|
|
15
|
-
'Find',
|
|
16
|
-
'Ls',
|
|
17
|
-
'AskUserQuestion',
|
|
18
|
-
'activateSkill',
|
|
19
|
-
'agent',
|
|
20
|
-
'checkAgent',
|
|
21
|
-
'sendMessage',
|
|
22
|
-
'requestPlanApproval',
|
|
23
|
-
'plan/enterPlanMode',
|
|
24
|
-
'plan/updatePrd',
|
|
25
|
-
'plan/setPlanTree',
|
|
26
|
-
'plan/exitPlanMode',
|
|
27
|
-
]);
|
|
28
|
-
//#endregion
|
|
29
|
-
//#region Types
|
|
30
|
-
export const PlanPhase = {
|
|
31
|
-
Idle: 'idle',
|
|
32
|
-
Planning: 'planning',
|
|
33
|
-
Executing: 'executing',
|
|
34
|
-
Completed: 'completed',
|
|
35
|
-
Failed: 'failed',
|
|
36
|
-
};
|
|
37
|
-
//#endregion
|
|
38
|
-
//#region Helpers
|
|
39
|
-
function createDefaultState() {
|
|
40
|
-
return {
|
|
41
|
-
phase: PlanPhase.Idle,
|
|
42
|
-
prd: null,
|
|
43
|
-
planTree: null,
|
|
44
|
-
executionLog: [],
|
|
45
|
-
version: 0,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
function validateTreeDepth(node, maxDepth) {
|
|
49
|
-
return flowDepth(node) <= maxDepth;
|
|
50
|
-
}
|
|
51
|
-
function buildAllowedTools(config) {
|
|
52
|
-
if (!config?.additionalAllowedTools?.length) {
|
|
53
|
-
return ALLOWED_TOOLS_IN_PLAN_MODE;
|
|
54
|
-
}
|
|
55
|
-
return new Set([
|
|
56
|
-
...ALLOWED_TOOLS_IN_PLAN_MODE,
|
|
57
|
-
...config.additionalAllowedTools,
|
|
58
|
-
]);
|
|
59
|
-
}
|
|
60
|
-
function trimExecutionLog(log) {
|
|
61
|
-
if (log.length <= MAX_EXECUTION_LOG_ENTRIES) {
|
|
62
|
-
return log;
|
|
63
|
-
}
|
|
64
|
-
return log.slice(log.length - MAX_EXECUTION_LOG_ENTRIES);
|
|
65
|
-
}
|
|
66
|
-
//#endregion
|
|
67
|
-
//#region Recall Renderers
|
|
68
|
-
function recallPlanning(state, additionalInstructions) {
|
|
69
|
-
const sections = [
|
|
70
|
-
'<plan_mode>',
|
|
71
|
-
'You are in PLAN MODE. You may only use read-only tools (Read, Grep, Find, Ls), AskUserQuestion, skill activation, sub-agent coordination tools, and requestPlanApproval to explore the codebase and request execution approval.',
|
|
72
|
-
'Your goal is to produce a PRD document and (optionally) a structured execution plan.',
|
|
73
|
-
'',
|
|
74
|
-
'## Workflow (5 phases)',
|
|
75
|
-
'',
|
|
76
|
-
'1. **Initial Understanding** — Read code and gather context. To parallelise exploration, use the `agent` tool to spawn bounded read-only sub-agents; up to 3 in parallel. Each sub-agent returns a focused report.',
|
|
77
|
-
'2. **Design** — Synthesise findings. Optionally spawn planning sub-agents (1–3 in parallel) to draft alternative implementation approaches and surface trade-offs.',
|
|
78
|
-
'3. **Review** — Read the critical files identified by your subagents directly so you understand them first-hand. If anything is ambiguous, ask the user a focused question.',
|
|
79
|
-
'4. **Final Plan** — Write the PRD via `plan/updatePrd`. Lead with a **Context** section (why this change), then your single recommended approach, the paths of files to modify, existing functions/utilities to reuse, and a **Verification** section. Then call `plan/setPlanTree` with a JSON noetic flow built from the existing step primitives (`step.llm`, `step.branch`, `step.fork`, `step.spawn`, `step.loop`) — tool refs by name string.',
|
|
80
|
-
'5. **Exit** — Call `plan/exitPlanMode` with `{ action: "execute" }` to request approval. The user must accept before execution begins; if they reject, you stay in Plan Mode and may revise.',
|
|
81
|
-
'',
|
|
82
|
-
'## Available actions',
|
|
83
|
-
'- `plan/updatePrd` — set markdown PRD content',
|
|
84
|
-
'- `plan/setPlanTree` — set the optional JSON execution plan',
|
|
85
|
-
'- `plan/exitPlanMode` `{ action: "execute" }` — request approval and exit to executing',
|
|
86
|
-
'- `plan/exitPlanMode` `{ action: "cancel" }` — discard plan and return to idle',
|
|
87
|
-
'',
|
|
88
|
-
'## Constraints',
|
|
89
|
-
'- DO NOT create, modify, or delete files (other than via `plan/updatePrd` and `plan/setPlanTree`).',
|
|
90
|
-
'- DO NOT run mutating shell commands. Read-only exploration only.',
|
|
91
|
-
'- End each turn either by asking the user a focused clarifying question or by calling `plan/exitPlanMode`.',
|
|
92
|
-
];
|
|
93
|
-
if (additionalInstructions) {
|
|
94
|
-
sections.push('', '## Additional Instructions', '', additionalInstructions);
|
|
95
|
-
}
|
|
96
|
-
if (state.prd) {
|
|
97
|
-
sections.push('', '## Current PRD Draft', '', state.prd);
|
|
98
|
-
}
|
|
99
|
-
if (state.planTree) {
|
|
100
|
-
sections.push('', '## Current Plan Tree', '', JSON.stringify(state.planTree, null, 2));
|
|
101
|
-
}
|
|
102
|
-
sections.push('</plan_mode>');
|
|
103
|
-
return sections.join('\n');
|
|
104
|
-
}
|
|
105
|
-
function recallExecuting(state) {
|
|
106
|
-
const sections = [
|
|
107
|
-
'<active_plan>',
|
|
108
|
-
'## PRD',
|
|
109
|
-
'',
|
|
110
|
-
state.prd ?? '',
|
|
111
|
-
'',
|
|
112
|
-
'## Execution Plan',
|
|
113
|
-
'',
|
|
114
|
-
JSON.stringify(state.planTree, null, 2),
|
|
115
|
-
'</active_plan>',
|
|
116
|
-
];
|
|
117
|
-
return sections.join('\n');
|
|
118
|
-
}
|
|
119
|
-
function recallTerminal(state) {
|
|
120
|
-
const lastEntry = state.executionLog[state.executionLog.length - 1];
|
|
121
|
-
const outcome = lastEntry?.outcome ?? 'unknown';
|
|
122
|
-
return `<plan_outcome>Plan v${state.version} ${outcome}.</plan_outcome>`;
|
|
123
|
-
}
|
|
124
|
-
const RECALL_RENDERERS = {
|
|
125
|
-
[PlanPhase.Planning]: recallPlanning,
|
|
126
|
-
[PlanPhase.Executing]: recallExecuting,
|
|
127
|
-
[PlanPhase.Completed]: recallTerminal,
|
|
128
|
-
[PlanPhase.Failed]: recallTerminal,
|
|
129
|
-
};
|
|
130
|
-
//#endregion
|
|
131
|
-
//#region Public API
|
|
132
|
-
/**
|
|
133
|
-
* Creates a plan memory layer that manages the PRD authoring and plan execution lifecycle.
|
|
134
|
-
*
|
|
135
|
-
* @public
|
|
136
|
-
* @param config - Optional configuration for scope, allowed tools, and limits.
|
|
137
|
-
* @returns A `MemoryLayer` providing plan mode, PRD storage, and execution tracking.
|
|
138
|
-
*/
|
|
139
|
-
export function planMemory(config) {
|
|
140
|
-
const scope = config?.scope ?? 'thread';
|
|
141
|
-
const maxPrdLength = config?.maxPrdLength ?? MAX_PRD_LENGTH;
|
|
142
|
-
const maxTreeDepth = config?.maxTreeDepth ?? MAX_TREE_DEPTH;
|
|
143
|
-
const allowedTools = buildAllowedTools(config);
|
|
144
|
-
const additionalPlanInstructions = config?.additionalPlanInstructions;
|
|
145
|
-
const onEnterSession = config?.onEnterSession;
|
|
146
|
-
const onExit = config?.onExit;
|
|
147
|
-
return {
|
|
148
|
-
id: 'plan',
|
|
149
|
-
name: 'Plan Memory',
|
|
150
|
-
slot: PLAN_SLOT,
|
|
151
|
-
scope,
|
|
152
|
-
budget: {
|
|
153
|
-
min: 100,
|
|
154
|
-
max: 3e3,
|
|
155
|
-
},
|
|
156
|
-
provides: {
|
|
157
|
-
status: layerData({
|
|
158
|
-
read: (state) => ({
|
|
159
|
-
phase: state.phase,
|
|
160
|
-
hasPrd: state.prd !== null,
|
|
161
|
-
hasPlanTree: state.planTree !== null,
|
|
162
|
-
version: state.version,
|
|
163
|
-
}),
|
|
164
|
-
}),
|
|
165
|
-
enterPlanMode: layerFn({
|
|
166
|
-
description: 'Enter plan mode. The agent switches to read-only exploration and PRD authoring.',
|
|
167
|
-
input: z.object({
|
|
168
|
-
goal: z.string().optional(),
|
|
169
|
-
}),
|
|
170
|
-
output: z.string(),
|
|
171
|
-
execute: async (args, state) => {
|
|
172
|
-
if (state.phase !== PlanPhase.Idle) {
|
|
173
|
-
return {
|
|
174
|
-
result: `Cannot enter plan mode: current phase is "${state.phase}".`,
|
|
175
|
-
state,
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
const session = onEnterSession ? await onEnterSession() : null;
|
|
179
|
-
return {
|
|
180
|
-
result: 'Plan mode activated. Explore the codebase, then call plan/updatePrd.',
|
|
181
|
-
state: {
|
|
182
|
-
...state,
|
|
183
|
-
phase: PlanPhase.Planning,
|
|
184
|
-
prd: args.goal ? `# Goal\n\n${args.goal}\n` : null,
|
|
185
|
-
planTree: null,
|
|
186
|
-
version: state.version + 1,
|
|
187
|
-
planSlug: session?.slug ?? null,
|
|
188
|
-
},
|
|
189
|
-
};
|
|
190
|
-
},
|
|
191
|
-
}),
|
|
192
|
-
updatePrd: layerFn({
|
|
193
|
-
description: 'Update the PRD document with new markdown content.',
|
|
194
|
-
input: z.object({
|
|
195
|
-
content: z.string(),
|
|
196
|
-
}),
|
|
197
|
-
output: z.string(),
|
|
198
|
-
execute: async (args, state) => {
|
|
199
|
-
if (state.phase !== PlanPhase.Planning) {
|
|
200
|
-
return {
|
|
201
|
-
result: `Cannot update PRD: current phase is "${state.phase}". Enter plan mode first.`,
|
|
202
|
-
state,
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
if (args.content.length > maxPrdLength) {
|
|
206
|
-
return {
|
|
207
|
-
result: `PRD content exceeds maximum length of ${maxPrdLength} characters.`,
|
|
208
|
-
state,
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
return {
|
|
212
|
-
result: 'PRD updated successfully.',
|
|
213
|
-
state: {
|
|
214
|
-
...state,
|
|
215
|
-
prd: args.content,
|
|
216
|
-
},
|
|
217
|
-
};
|
|
218
|
-
},
|
|
219
|
-
}),
|
|
220
|
-
setPlanTree: layerFn({
|
|
221
|
-
description: 'Set the execution plan tree. Input must be a valid FlowNode — a discriminated union with kind: "llm" | "subagent" | "fork" | "spawn" | "sequence". Structural nodes (sequence, fork, spawn) nest child FlowNodes; leaf nodes (llm, subagent) carry execution instructions.',
|
|
222
|
-
input: FlowSchema,
|
|
223
|
-
output: z.string(),
|
|
224
|
-
execute: async (args, state) => {
|
|
225
|
-
if (state.phase !== PlanPhase.Planning) {
|
|
226
|
-
return {
|
|
227
|
-
result: `Cannot set plan tree: current phase is "${state.phase}". Enter plan mode first.`,
|
|
228
|
-
state,
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
if (!validateTreeDepth(args, maxTreeDepth)) {
|
|
232
|
-
return {
|
|
233
|
-
result: `Plan tree exceeds maximum depth of ${maxTreeDepth}.`,
|
|
234
|
-
state,
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
return {
|
|
238
|
-
result: 'Plan tree set successfully. Call plan/exitPlanMode to begin execution.',
|
|
239
|
-
state: {
|
|
240
|
-
...state,
|
|
241
|
-
planTree: args,
|
|
242
|
-
},
|
|
243
|
-
};
|
|
244
|
-
},
|
|
245
|
-
}),
|
|
246
|
-
exitPlanMode: layerFn({
|
|
247
|
-
description: 'Exit plan mode. Use action "execute" to begin executing the plan, or "cancel" to discard it.',
|
|
248
|
-
input: z.object({
|
|
249
|
-
action: z.enum([
|
|
250
|
-
'execute',
|
|
251
|
-
'cancel',
|
|
252
|
-
]),
|
|
253
|
-
}),
|
|
254
|
-
output: z.string(),
|
|
255
|
-
execute: async (args, state) => {
|
|
256
|
-
if (state.phase !== PlanPhase.Planning) {
|
|
257
|
-
return {
|
|
258
|
-
result: `Cannot exit plan mode: current phase is "${state.phase}".`,
|
|
259
|
-
state,
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
if (args.action === 'cancel') {
|
|
263
|
-
return {
|
|
264
|
-
result: 'Plan cancelled. Returned to idle.',
|
|
265
|
-
state: createDefaultState(),
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
if (!state.prd) {
|
|
269
|
-
return {
|
|
270
|
-
result: 'Cannot execute: no PRD has been written. Call plan/updatePrd first.',
|
|
271
|
-
state,
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
if (!state.planTree) {
|
|
275
|
-
return {
|
|
276
|
-
result: 'Cannot execute: no plan tree has been set. Call plan/setPlanTree first.',
|
|
277
|
-
state,
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
if (onExit) {
|
|
281
|
-
const { approved } = await onExit(state);
|
|
282
|
-
if (!approved) {
|
|
283
|
-
return {
|
|
284
|
-
result: 'User did not approve the plan. Stay in plan mode, address their feedback, and call plan/exitPlanMode again when ready.',
|
|
285
|
-
state,
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
return {
|
|
290
|
-
result: 'Plan mode exited. Execution phase begun.',
|
|
291
|
-
state: {
|
|
292
|
-
...state,
|
|
293
|
-
phase: PlanPhase.Executing,
|
|
294
|
-
},
|
|
295
|
-
};
|
|
296
|
-
},
|
|
297
|
-
}),
|
|
298
|
-
},
|
|
299
|
-
hooks: {
|
|
300
|
-
async init({ storage }) {
|
|
301
|
-
const saved = await storage.get('state');
|
|
302
|
-
return {
|
|
303
|
-
state: saved ?? createDefaultState(),
|
|
304
|
-
};
|
|
305
|
-
},
|
|
306
|
-
async recall({ state }) {
|
|
307
|
-
if (state.phase === PlanPhase.Idle) {
|
|
308
|
-
return null;
|
|
309
|
-
}
|
|
310
|
-
const renderer = RECALL_RENDERERS[state.phase];
|
|
311
|
-
if (!renderer) {
|
|
312
|
-
return null;
|
|
313
|
-
}
|
|
314
|
-
const content = renderer(state, additionalPlanInstructions);
|
|
315
|
-
return {
|
|
316
|
-
items: [
|
|
317
|
-
createMessage(content, 'developer'),
|
|
318
|
-
],
|
|
319
|
-
tokenCount: estimateTokens(content),
|
|
320
|
-
};
|
|
321
|
-
},
|
|
322
|
-
async beforeToolCall({ toolName, state }) {
|
|
323
|
-
if (state.phase !== PlanPhase.Planning) {
|
|
324
|
-
return {
|
|
325
|
-
decision: {
|
|
326
|
-
action: SteeringAction.Allow,
|
|
327
|
-
},
|
|
328
|
-
state,
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
if (allowedTools.has(toolName)) {
|
|
332
|
-
return {
|
|
333
|
-
decision: {
|
|
334
|
-
action: SteeringAction.Allow,
|
|
335
|
-
},
|
|
336
|
-
state,
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
return {
|
|
340
|
-
decision: {
|
|
341
|
-
action: SteeringAction.Deny,
|
|
342
|
-
guidance: `Plan mode is active. "${toolName}" is not allowed during planning. Use read-only tools (Read, Grep, Find, Ls) to explore the codebase, then call plan/updatePrd to write your PRD.`,
|
|
343
|
-
},
|
|
344
|
-
state,
|
|
345
|
-
};
|
|
346
|
-
},
|
|
347
|
-
async onSpawn({ parentState }) {
|
|
348
|
-
return {
|
|
349
|
-
childState: structuredClone(parentState),
|
|
350
|
-
};
|
|
351
|
-
},
|
|
352
|
-
async onComplete({ state, outcome }) {
|
|
353
|
-
if (state.phase !== PlanPhase.Executing) {
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
356
|
-
return {
|
|
357
|
-
state: {
|
|
358
|
-
...state,
|
|
359
|
-
phase: outcome === 'success' ? PlanPhase.Completed : PlanPhase.Failed,
|
|
360
|
-
executionLog: trimExecutionLog([
|
|
361
|
-
...state.executionLog,
|
|
362
|
-
{
|
|
363
|
-
timestamp: Date.now(),
|
|
364
|
-
version: state.version,
|
|
365
|
-
outcome,
|
|
366
|
-
},
|
|
367
|
-
]),
|
|
368
|
-
},
|
|
369
|
-
};
|
|
370
|
-
},
|
|
371
|
-
},
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
//#endregion
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { MemoryScope } from '../../types/memory.js';
|
|
2
|
-
interface StaticContentOpts {
|
|
3
|
-
id?: string;
|
|
4
|
-
slot?: number;
|
|
5
|
-
scope?: MemoryScope;
|
|
6
|
-
load: () => Promise<string>;
|
|
7
|
-
tag?: string;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Creates a read-only memory layer that loads static content once at init and injects it into recall.
|
|
11
|
-
*
|
|
12
|
-
* @public
|
|
13
|
-
* @param opts - Configuration with a `load` function and optional id, slot, scope, and XML tag name.
|
|
14
|
-
* @returns A `MemoryLayer` that provides static instructional content to the model.
|
|
15
|
-
*/
|
|
16
|
-
export declare function staticContent(opts: StaticContentOpts): {
|
|
17
|
-
id: string;
|
|
18
|
-
slot: number;
|
|
19
|
-
scope: MemoryScope;
|
|
20
|
-
hooks: {
|
|
21
|
-
init(): Promise<{
|
|
22
|
-
state: string;
|
|
23
|
-
}>;
|
|
24
|
-
recall({ state }: import("../../index.js").RecallParams<string>): Promise<string | null>;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
export {};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Slot } from '../../types/memory.js';
|
|
2
|
-
/**
|
|
3
|
-
* Creates a read-only memory layer that loads static content once at init and injects it into recall.
|
|
4
|
-
*
|
|
5
|
-
* @public
|
|
6
|
-
* @param opts - Configuration with a `load` function and optional id, slot, scope, and XML tag name.
|
|
7
|
-
* @returns A `MemoryLayer` that provides static instructional content to the model.
|
|
8
|
-
*/
|
|
9
|
-
export function staticContent(opts) {
|
|
10
|
-
const tag = opts.tag ?? 'instructions';
|
|
11
|
-
return {
|
|
12
|
-
id: opts.id ?? 'static-content',
|
|
13
|
-
slot: opts.slot ?? Slot.WORKING_MEMORY + 5,
|
|
14
|
-
scope: opts.scope ?? 'resource',
|
|
15
|
-
hooks: {
|
|
16
|
-
async init() {
|
|
17
|
-
const raw = await opts.load();
|
|
18
|
-
if (!raw) {
|
|
19
|
-
return {
|
|
20
|
-
state: '',
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
return {
|
|
24
|
-
state: `<${tag}>\n${raw}\n</${tag}>`,
|
|
25
|
-
};
|
|
26
|
-
},
|
|
27
|
-
async recall({ state }) {
|
|
28
|
-
if (!state) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
return state;
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { MemoryScope } from '../../types/memory.js';
|
|
2
|
-
import type { AfterModelCallParams, BeforeToolCallParams, LedgerEntry, SteeringConfig, SteeringDecision, SteeringState } from '../../types/steering.js';
|
|
3
|
-
/**
|
|
4
|
-
* Creates a steering memory layer that evaluates rules before tool calls and after model calls.
|
|
5
|
-
*
|
|
6
|
-
* @public
|
|
7
|
-
* @param config - Steering configuration including rules, scope, and max ledger size.
|
|
8
|
-
* @returns A `MemoryLayer` that enforces steering rules via allow/deny/guide decisions.
|
|
9
|
-
*/
|
|
10
|
-
export declare function steering(config: SteeringConfig): {
|
|
11
|
-
id: "steering";
|
|
12
|
-
name: string;
|
|
13
|
-
slot: 90;
|
|
14
|
-
scope: MemoryScope;
|
|
15
|
-
budget: {
|
|
16
|
-
min: number;
|
|
17
|
-
max: number;
|
|
18
|
-
};
|
|
19
|
-
timeouts: {
|
|
20
|
-
beforeToolCall: number;
|
|
21
|
-
afterModelCall: number;
|
|
22
|
-
};
|
|
23
|
-
hooks: {
|
|
24
|
-
init({ storage }: import("../../index.js").InitParams): Promise<{
|
|
25
|
-
state: SteeringState;
|
|
26
|
-
}>;
|
|
27
|
-
recall({ state }: import("../../index.js").RecallParams<SteeringState>): Promise<{
|
|
28
|
-
items: import("../../index.js").InputMessageItem[];
|
|
29
|
-
tokenCount: number;
|
|
30
|
-
state: SteeringState;
|
|
31
|
-
} | null>;
|
|
32
|
-
store(): Promise<undefined>;
|
|
33
|
-
beforeToolCall({ toolName, toolArgs, ctx, state }: BeforeToolCallParams<SteeringState>): Promise<{
|
|
34
|
-
decision: SteeringDecision;
|
|
35
|
-
state: SteeringState;
|
|
36
|
-
}>;
|
|
37
|
-
afterModelCall({ response, ctx, state }: AfterModelCallParams<SteeringState>): Promise<{
|
|
38
|
-
decision: SteeringDecision;
|
|
39
|
-
state: SteeringState;
|
|
40
|
-
}>;
|
|
41
|
-
onSpawn({ parentState }: import("../../index.js").SpawnParams<SteeringState>): Promise<{
|
|
42
|
-
childState: {
|
|
43
|
-
ledger: LedgerEntry[];
|
|
44
|
-
pendingAsync: never[];
|
|
45
|
-
};
|
|
46
|
-
}>;
|
|
47
|
-
onComplete({ state, outcome }: import("../../index.js").CompleteParams<SteeringState>): Promise<{
|
|
48
|
-
state: SteeringState;
|
|
49
|
-
}>;
|
|
50
|
-
};
|
|
51
|
-
};
|