@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.
Files changed (207) hide show
  1. package/dist/adapters/in-memory-fs-adapter.d.ts +1 -1
  2. package/dist/adapters/in-memory-fs-adapter.js +1 -1
  3. package/dist/adapters/in-memory-shell-adapter.d.ts +1 -1
  4. package/dist/adapters/in-memory-subprocess/manifest-persistence.d.ts +2 -2
  5. package/dist/adapters/in-memory-subprocess/metadata.d.ts +1 -1
  6. package/dist/adapters/in-memory-subprocess/types.d.ts +2 -2
  7. package/dist/adapters/in-memory-subprocess-adapter.d.ts +1 -1
  8. package/dist/adapters/openrouter.d.ts +2 -6
  9. package/dist/adapters/openrouter.js +1 -4
  10. package/dist/builders/channel-builder.d.ts +1 -1
  11. package/dist/builders/control-flow-builders.d.ts +2 -3
  12. package/dist/builders/control-flow-builders.js +1 -2
  13. package/dist/builders/every.d.ts +2 -3
  14. package/dist/builders/every.js +1 -1
  15. package/dist/builders/layer-provides-builders.d.ts +1 -1
  16. package/dist/builders/layer-provides-builders.js +1 -1
  17. package/dist/builders/loop-builder.d.ts +2 -2
  18. package/dist/builders/loop-builder.js +1 -1
  19. package/dist/builders/memory-builder.d.ts +1 -1
  20. package/dist/builders/memory-builder.js +1 -1
  21. package/dist/builders/provide-builder.d.ts +2 -2
  22. package/dist/builders/provide-builder.js +1 -1
  23. package/dist/builders/spawn-builder.d.ts +2 -3
  24. package/dist/builders/spawn-builder.js +1 -1
  25. package/dist/builders/step-builders.d.ts +2 -6
  26. package/dist/builders/step-builders.js +1 -1
  27. package/dist/builders/tool-builder.d.ts +1 -3
  28. package/dist/builders/tool-builder.js +1 -1
  29. package/dist/builders/workflow-hydrator.d.ts +2 -3
  30. package/dist/builders/workflow-hydrator.js +1 -2
  31. package/dist/conditions/conditions.d.ts +2 -3
  32. package/dist/conditions/conditions.js +1 -1
  33. package/dist/harness/agent-harness.d.ts +15 -5
  34. package/dist/harness/agent-harness.js +65 -10
  35. package/dist/harness/deps/memory.d.ts +2 -5
  36. package/dist/harness/deps/memory.js +1 -4
  37. package/dist/harness/deps/types.d.ts +3 -16
  38. package/dist/harness/deps/types.js +1 -1
  39. package/dist/harness/model-call.d.ts +1 -3
  40. package/dist/harness/model-call.js +10 -10
  41. package/dist/harness/model-schema.d.ts +10 -4
  42. package/dist/harness/model-schema.js +9 -1
  43. package/dist/index.d.ts +28 -49
  44. package/dist/index.js +9 -27
  45. package/dist/interpreter/action-deps.d.ts +4 -8
  46. package/dist/interpreter/action-deps.js +2 -6
  47. package/dist/interpreter/action-types.d.ts +3 -8
  48. package/dist/interpreter/action-types.js +1 -1
  49. package/dist/interpreter/collect-tools.d.ts +1 -2
  50. package/dist/interpreter/collect-tools.js +1 -1
  51. package/dist/interpreter/execute-action.js +122 -27
  52. package/dist/interpreter/execute-control.d.ts +1 -2
  53. package/dist/interpreter/execute-control.js +60 -7
  54. package/dist/interpreter/execute.d.ts +2 -3
  55. package/dist/interpreter/execute.js +1 -2
  56. package/dist/interpreter/message-helpers.d.ts +1 -1
  57. package/dist/interpreter/message-helpers.js +1 -1
  58. package/dist/interpreter/step-dispatcher.d.ts +2 -5
  59. package/dist/interpreter/typeguards.d.ts +3 -4
  60. package/dist/interpreter/typeguards.js +1 -1
  61. package/dist/observability/span-impl.d.ts +1 -1
  62. package/dist/observability/trace-exporter.d.ts +1 -1
  63. package/dist/patterns/dynamic-workflow.d.ts +2 -5
  64. package/dist/patterns/dynamic-workflow.js +1 -2
  65. package/dist/patterns/flow.d.ts +2 -2
  66. package/dist/patterns/flow.js +1 -1
  67. package/dist/patterns/interview.d.ts +2 -2
  68. package/dist/patterns/interview.js +1 -1
  69. package/dist/patterns/plans.d.ts +2 -3
  70. package/dist/patterns/plans.js +1 -1
  71. package/dist/patterns/ralph-wiggum.d.ts +2 -3
  72. package/dist/patterns/react.d.ts +2 -3
  73. package/dist/portable/memory-layers.d.ts +1 -7
  74. package/dist/portable/memory-layers.js +1 -7
  75. package/dist/portable.d.ts +2 -2
  76. package/dist/portable.js +2 -2
  77. package/dist/runtime/broadcaster-utils.d.ts +1 -1
  78. package/dist/runtime/channel-store.d.ts +43 -3
  79. package/dist/runtime/channel-store.js +233 -37
  80. package/dist/runtime/context-deps.d.ts +3 -3
  81. package/dist/runtime/context-deps.js +2 -2
  82. package/dist/runtime/context-impl.d.ts +17 -1
  83. package/dist/runtime/context-impl.js +30 -3
  84. package/dist/runtime/context-type-deps.d.ts +2 -11
  85. package/dist/runtime/cwd-helpers.d.ts +1 -1
  86. package/dist/runtime/detached-handle.d.ts +2 -3
  87. package/dist/runtime/detached-handle.js +1 -3
  88. package/dist/runtime/durable/checkpoint-store.d.ts +1 -1
  89. package/dist/runtime/durable/checkpoint-store.js +1 -1
  90. package/dist/runtime/durable/harness-checkpoints.d.ts +2 -5
  91. package/dist/runtime/durable/runnable-loop.d.ts +1 -3
  92. package/dist/runtime/durable/session-seed.d.ts +1 -1
  93. package/dist/runtime/durable/stall-nudge.d.ts +17 -10
  94. package/dist/runtime/durable/stall-nudge.js +29 -10
  95. package/dist/runtime/event-broadcaster.d.ts +10 -2
  96. package/dist/runtime/event-broadcaster.js +43 -19
  97. package/dist/runtime/in-memory-storage.d.ts +1 -1
  98. package/dist/runtime/in-memory-storage.js +1 -1
  99. package/dist/runtime/item-log-impl.d.ts +1 -3
  100. package/dist/runtime/item-log-impl.js +1 -1
  101. package/dist/runtime/message-queue.d.ts +1 -2
  102. package/dist/runtime/session-runner.d.ts +1 -4
  103. package/dist/runtime/session-streams.d.ts +1 -2
  104. package/dist/runtime/session-streams.js +1 -1
  105. package/dist/runtime/step-registry.d.ts +2 -2
  106. package/dist/runtime/step-registry.js +1 -2
  107. package/dist/runtime/tool-memory.d.ts +1 -3
  108. package/dist/types/mutable-context.d.ts +2 -3
  109. package/dist/types/step-registrar.d.ts +1 -1
  110. package/dist/unstable.d.ts +5 -9
  111. package/dist/unstable.js +3 -6
  112. package/dist/until/combinators.d.ts +1 -1
  113. package/dist/until/never.d.ts +1 -1
  114. package/dist/until/predicates.d.ts +2 -2
  115. package/package.json +4 -2
  116. package/dist/errors/noetic-config-error.d.ts +0 -41
  117. package/dist/errors/noetic-config-error.js +0 -44
  118. package/dist/errors/noetic-error.d.ts +0 -18
  119. package/dist/errors/noetic-error.js +0 -54
  120. package/dist/memory/budget.d.ts +0 -23
  121. package/dist/memory/budget.js +0 -117
  122. package/dist/memory/exec-context-factory.d.ts +0 -25
  123. package/dist/memory/exec-context-factory.js +0 -30
  124. package/dist/memory/flow-schema.d.ts +0 -52
  125. package/dist/memory/flow-schema.js +0 -102
  126. package/dist/memory/function-call-utils.d.ts +0 -6
  127. package/dist/memory/function-call-utils.js +0 -27
  128. package/dist/memory/layer-api.d.ts +0 -14
  129. package/dist/memory/layer-api.js +0 -91
  130. package/dist/memory/layer-lifecycle.d.ts +0 -160
  131. package/dist/memory/layer-lifecycle.js +0 -552
  132. package/dist/memory/layer-provides.d.ts +0 -32
  133. package/dist/memory/layer-provides.js +0 -33
  134. package/dist/memory/layer-usage.d.ts +0 -16
  135. package/dist/memory/layer-usage.js +0 -54
  136. package/dist/memory/layers/durable-task-state.d.ts +0 -79
  137. package/dist/memory/layers/durable-task-state.js +0 -118
  138. package/dist/memory/layers/file-reference.d.ts +0 -55
  139. package/dist/memory/layers/file-reference.js +0 -594
  140. package/dist/memory/layers/history-window.d.ts +0 -29
  141. package/dist/memory/layers/history-window.js +0 -114
  142. package/dist/memory/layers/observational-memory.d.ts +0 -53
  143. package/dist/memory/layers/observational-memory.js +0 -109
  144. package/dist/memory/layers/plan.d.ts +0 -55
  145. package/dist/memory/layers/plan.js +0 -374
  146. package/dist/memory/layers/static-content.d.ts +0 -27
  147. package/dist/memory/layers/static-content.js +0 -35
  148. package/dist/memory/layers/steering.d.ts +0 -51
  149. package/dist/memory/layers/steering.js +0 -258
  150. package/dist/memory/layers/temporal.d.ts +0 -91
  151. package/dist/memory/layers/temporal.js +0 -245
  152. package/dist/memory/layers/tool-memory-layer.d.ts +0 -16
  153. package/dist/memory/layers/tool-memory-layer.js +0 -43
  154. package/dist/memory/layers/working-memory.d.ts +0 -44
  155. package/dist/memory/layers/working-memory.js +0 -92
  156. package/dist/memory/projector.d.ts +0 -10
  157. package/dist/memory/projector.js +0 -19
  158. package/dist/memory/scope.d.ts +0 -3
  159. package/dist/memory/scope.js +0 -31
  160. package/dist/memory/strip-unresolved.d.ts +0 -13
  161. package/dist/memory/strip-unresolved.js +0 -35
  162. package/dist/schemas/item.d.ts +0 -35
  163. package/dist/schemas/item.js +0 -155
  164. package/dist/types/channel.d.ts +0 -29
  165. package/dist/types/channel.js +0 -1
  166. package/dist/types/common.d.ts +0 -68
  167. package/dist/types/common.js +0 -1
  168. package/dist/types/context-parts/item-log.d.ts +0 -6
  169. package/dist/types/context-parts/item-log.js +0 -1
  170. package/dist/types/context-parts/layer-usage.d.ts +0 -18
  171. package/dist/types/context-parts/layer-usage.js +0 -1
  172. package/dist/types/context.d.ts +0 -202
  173. package/dist/types/context.js +0 -1
  174. package/dist/types/detached.d.ts +0 -17
  175. package/dist/types/detached.js +0 -7
  176. package/dist/types/error.d.ts +0 -66
  177. package/dist/types/error.js +0 -1
  178. package/dist/types/fs-adapter.d.ts +0 -51
  179. package/dist/types/fs-adapter.js +0 -3
  180. package/dist/types/harness-result.d.ts +0 -43
  181. package/dist/types/harness-result.js +0 -2
  182. package/dist/types/items.d.ts +0 -131
  183. package/dist/types/items.js +0 -2
  184. package/dist/types/memory-context.d.ts +0 -39
  185. package/dist/types/memory-context.js +0 -1
  186. package/dist/types/memory.d.ts +0 -306
  187. package/dist/types/memory.js +0 -13
  188. package/dist/types/observability.d.ts +0 -30
  189. package/dist/types/observability.js +0 -1
  190. package/dist/types/runtime.d.ts +0 -256
  191. package/dist/types/runtime.js +0 -1
  192. package/dist/types/shell-adapter.d.ts +0 -34
  193. package/dist/types/shell-adapter.js +0 -10
  194. package/dist/types/steering.d.ts +0 -89
  195. package/dist/types/steering.js +0 -14
  196. package/dist/types/step.d.ts +0 -231
  197. package/dist/types/step.js +0 -1
  198. package/dist/types/subprocess-adapter.d.ts +0 -157
  199. package/dist/types/subprocess-adapter.js +0 -3
  200. package/dist/types/tool-context.d.ts +0 -34
  201. package/dist/types/tool-context.js +0 -1
  202. package/dist/types/tool.d.ts +0 -64
  203. package/dist/types/tool.js +0 -1
  204. package/dist/util/framework-cast.d.ts +0 -10
  205. package/dist/util/framework-cast.js +0 -16
  206. package/dist/util/message-helpers.d.ts +0 -17
  207. package/dist/util/message-helpers.js +0 -64
@@ -1,12 +1,18 @@
1
- import type { ItemSchemaRegistry } from '../schemas/item.js';
2
- import type { Item } from '../types/items.js';
3
- import type { MemoryLayer } from '../types/memory.js';
4
- import type { Tool } from '../types/tool.js';
1
+ import type { MemoryLayer } from '@noetic-tools/memory';
2
+ import type { Item, ItemSchemaRegistry, Tool } from '@noetic-tools/types';
5
3
  export declare function buildItemSchemaRegistry({ base, layers, tools, }: {
6
4
  base: ItemSchemaRegistry;
7
5
  layers?: ReadonlyArray<MemoryLayer>;
8
6
  tools?: ReadonlyArray<Tool>;
9
7
  }): ItemSchemaRegistry;
8
+ /**
9
+ * Build and validate a `function_call_output` item for a tool result.
10
+ *
11
+ * `roundItemSchemas` must be the OWNER-SCOPED registry for the called tool
12
+ * (harness base extended with only that tool's `itemSchemas`), so one tool's
13
+ * `toolResults` schemas never reject a sibling tool's result items. Tools
14
+ * without `itemSchemas` fall back to the base structural parse.
15
+ */
10
16
  export declare function createToolResultItem({ output, callId, roundItemSchemas, tool, callItem, args, result, error, }: {
11
17
  output: string;
12
18
  callId: string;
@@ -1,4 +1,4 @@
1
- import { mergeExtensions } from '../schemas/item.js';
1
+ import { mergeExtensions } from '@noetic-tools/types';
2
2
  function mergeItemSchemaExtensions(extensions) {
3
3
  let result = {
4
4
  items: [],
@@ -24,6 +24,14 @@ export function buildItemSchemaRegistry({ base, layers, tools, }) {
24
24
  .extend(collectLayerItemSchemaExtensions(layers))
25
25
  .extend(collectToolItemSchemaExtensions(tools));
26
26
  }
27
+ /**
28
+ * Build and validate a `function_call_output` item for a tool result.
29
+ *
30
+ * `roundItemSchemas` must be the OWNER-SCOPED registry for the called tool
31
+ * (harness base extended with only that tool's `itemSchemas`), so one tool's
32
+ * `toolResults` schemas never reject a sibling tool's result items. Tools
33
+ * without `itemSchemas` fall back to the base structural parse.
34
+ */
27
35
  export function createToolResultItem({ output, callId, roundItemSchemas, tool, callItem, args, result, error, }) {
28
36
  const baseItem = {
29
37
  id: crypto.randomUUID(),
package/dist/index.d.ts CHANGED
@@ -41,9 +41,8 @@ export { aiCondition, allCondition, anyCondition, embeddingMatch, otherwise, sem
41
41
  /** @public */
42
42
  export { cosineSimilarity } from './conditions/cosine-similarity.js';
43
43
  /** @public */
44
- export { isNoeticConfigError, NoeticConfigError } from './errors/noetic-config-error.js';
45
44
  /** @public */
46
- export { isNoeticError, NoeticErrorImpl } from './errors/noetic-error.js';
45
+ export { isNoeticConfigError, isNoeticError, NoeticConfigError, NoeticErrorImpl, } from '@noetic-tools/types';
47
46
  /** @public */
48
47
  export type { AskUserAnnotation, AskUserInput, AskUserOption, AskUserOutput, AskUserQuestion, } from './types/ask-user-types.js';
49
48
  /** @public */
@@ -51,43 +50,27 @@ export { AskUserAnnotationSchema, AskUserInputSchema, AskUserOptionSchema, AskUs
51
50
  /** @public */
52
51
  export { execute } from './interpreter/execute.js';
53
52
  /** @public */
54
- export { findFunctionCall } from './memory/function-call-utils.js';
55
53
  /** @public */
56
- export type { DurableTaskState, DurableTaskStateConfig } from './memory/layers/durable-task-state.js';
57
54
  /** @public */
58
- export { durableTaskState } from './memory/layers/durable-task-state.js';
59
55
  /** @public */
60
- export { fileReference } from './memory/layers/file-reference.js';
61
56
  /** @public */
62
- export type { HistoryWindowConfig } from './memory/layers/history-window.js';
63
57
  /** @public */
64
- export { historyWindow } from './memory/layers/history-window.js';
58
+ export type { DurableTaskState, FactExtractor, FactSearcher, HistoryWindowConfig, ObservationalMemoryConfig, ObservationalState, PlanEnterSessionCallback, PlanExecutionEntry, PlanExitCallback, PlanMemoryConfig, PlanState, TemporalFact, TemporalMemoryConfig, TemporalSearchResult, WorkingMemoryConfig, WorkingMemoryState, } from '@noetic-tools/memory';
65
59
  /** @public */
66
- export type { ObservationalMemoryConfig, ObservationalState, } from './memory/layers/observational-memory.js';
67
60
  /** @public */
68
- export { observationalMemory } from './memory/layers/observational-memory.js';
69
61
  /** @public */
70
- export type { PlanEnterSessionCallback, PlanExecutionEntry, PlanExitCallback, PlanMemoryConfig, PlanState, } from './memory/layers/plan.js';
71
62
  /** @public */
72
- export { PlanPhase, planMemory } from './memory/layers/plan.js';
73
63
  /** @public */
74
- export { staticContent } from './memory/layers/static-content.js';
75
64
  /** @public */
76
- export { steering } from './memory/layers/steering.js';
77
65
  /** @public */
78
- export type { FactExtractor, FactSearcher, TemporalFact, TemporalMemoryConfig, TemporalSearchResult, } from './memory/layers/temporal.js';
79
66
  /** @public */
80
- export { temporalMemory } from './memory/layers/temporal.js';
81
67
  /** @public */
82
- export { toolMemoryLayer } from './memory/layers/tool-memory-layer.js';
83
68
  /** @public */
84
- export type { WorkingMemoryConfig, WorkingMemoryState } from './memory/layers/working-memory.js';
85
69
  /** @public */
86
- export { workingMemory } from './memory/layers/working-memory.js';
87
70
  /** @public */
88
- export { stripUnresolvedToolCalls } from './memory/strip-unresolved.js';
71
+ export { durableTaskState, fileReference, findFunctionCall, historyWindow, observationalMemory, PlanPhase, planMemory, staticContent, steering, stripUnresolvedToolCalls, temporalMemory, toolMemoryLayer, workingMemory, } from '@noetic-tools/memory';
89
72
  /** @public */
90
- export { createMessage, estimateTokens } from './util/message-helpers.js';
73
+ export { createMessage, estimateTokens } from '@noetic-tools/types';
91
74
  /** @public */
92
75
  export { GenAI, ToolAttr } from './observability/genai-attributes.js';
93
76
  /** @public */
@@ -123,29 +106,26 @@ export { CheckpointKeys, createCheckpointStore, createDetachedSignal, createNudg
123
106
  /** @public */
124
107
  export { getRegistry, lookupStep, registerStep } from './runtime/step-registry.js';
125
108
  /** @public */
126
- export { defaultItemSchemaRegistry, ItemSchema, ItemSchemaRegistry } from './schemas/item.js';
109
+ export { defaultItemSchemaRegistry, ItemSchema, ItemSchemaRegistry } from '@noetic-tools/types';
127
110
  /** @public */
128
111
  export type { BranchRoute, BranchWorkflowNode, EveryWorkflowNode, ForkWorkflowNode, LlmWorkflowNode, LoopWorkflowNode, MergeStrategy, ProvideWorkflowNode, SequenceWorkflowNode, SpawnWorkflowNode, ToolWorkflowNode, UntilPredicate, WorkflowDocument, WorkflowNode, } from './schemas/workflow.js';
129
112
  /** @public */
130
113
  export { MergeStrategySchema, UntilPredicateSchema, validateWorkflow, WorkflowDocumentSchema, WorkflowNodeSchema, walkWorkflow, workflowDepth, } from './schemas/workflow.js';
131
114
  /** @public */
132
- export type { Channel, ChannelHandle, ExternalChannel } from './types/channel.js';
115
+ export type { Channel, ChannelHandle, ExternalChannel } from '@noetic-tools/types';
133
116
  /** @public */
134
- export type { LLMResponse, LlmProviderConfig, ModelParams, RetryPolicy, StepMeta, TokenUsage, } from './types/common.js';
135
117
  /** @public */
136
- export type { Tool, ToolMemoryDeclaration } from './types/tool.js';
118
+ export type { LLMResponse, LlmProviderConfig, ModelParams, RetryPolicy, StepMeta, TokenUsage, Tool, ToolMemoryDeclaration, } from '@noetic-tools/types';
137
119
  /** @public */
138
- export { getToolCwd, setToolCwd, snapshotCwdState } from './runtime/cwd-helpers.js';
139
120
  /** @public */
140
- export type { Context, ContextHarness, CwdState, } from './types/context.js';
141
121
  /** @public */
142
- export type { ItemLog } from './types/context-parts/item-log.js';
122
+ export type { Context, ContextHarness, CwdState, ItemLog, LastLayerUsage, LayerUsageEntry, } from '@noetic-tools/types';
143
123
  /** @public */
144
- export type { LastLayerUsage, LayerUsageEntry } from './types/context-parts/layer-usage.js';
124
+ export { getToolCwd, setToolCwd, snapshotCwdState } from './runtime/cwd-helpers.js';
145
125
  /** @public */
146
- export type { DetachedHandle } from './types/detached.js';
126
+ export type { DetachedHandle } from '@noetic-tools/types';
147
127
  /** @public */
148
- export { DetachedStatus } from './types/detached.js';
128
+ export { DetachedStatus } from '@noetic-tools/types';
149
129
  /** @public */
150
130
  export type { EmbedFn } from './types/embed.js';
151
131
  /** @public */
@@ -153,39 +133,38 @@ export type { CheckpointSnapshot, CwdSnapshot, FrontierFrame, ItemLogSnapshot, P
153
133
  /** @public */
154
134
  export { CheckpointSchemaVersion, CheckpointSnapshotSchema, CwdSnapshotSchema, FrontierFrameSchema, ItemLogSnapshotSchema, PendingAskUserSnapshotSchema, } from './types/checkpoint.js';
155
135
  /** @public */
156
- export type { NoeticError } from './types/error.js';
136
+ export type { NoeticError } from '@noetic-tools/types';
157
137
  /** @public */
158
- export type { ContentPart, DeveloperMessageExtensionItem, ExecuteInput, ExtendedItem, ExtensionItem, FileSearchItem, FunctionCallItem, FunctionCallOutputItem, ImageGenerationItem, InferExtendedItem, InputContentPart, InputFilePart, InputImagePart, InputMessageItem, InputTextPart, Item, ItemBase, ItemSchemaExtensions, MessageItem, OutputItem, OutputTextPart, ReasoningItem, ReasoningTextPart, RefusalPart, ServerToolItem, SummaryTextPart, WebSearchItem, } from './types/items.js';
138
+ export type { ContentPart, DeveloperMessageExtensionItem, ExecuteInput, ExtendedItem, ExtensionItem, FileSearchItem, FunctionCallItem, FunctionCallOutputItem, ImageGenerationItem, InferExtendedItem, InputContentPart, InputFilePart, InputImagePart, InputMessageItem, InputTextPart, Item, ItemBase, ItemSchemaExtensions, MessageItem, OutputItem, OutputTextPart, ReasoningItem, ReasoningTextPart, RefusalPart, ServerToolItem, SummaryTextPart, WebSearchItem, } from '@noetic-tools/types';
159
139
  /** @public */
160
- export type { BudgetConfig, CompleteParams, ContextMemory, DisposeParams, InferMemory, InferMemoryShape, InitParams, InitResult, LayerDataDecl, LayerFunctionDecl, LayerProvides, LayerTimeouts, MemoryConfig, MemoryHooks, MemoryLayer, ProjectionPolicy, RecallParams, RecallResult, ReturnParams, ReturnResult, ScopedStorage, SpawnParams, SpawnResult, StorageAdapter, StoreParams, StoreResult, } from './types/memory.js';
140
+ export type { BudgetConfig, CompleteParams, ContextMemory, DisposeParams, InferMemory, InferMemoryShape, InitParams, InitResult, LayerDataDecl, LayerFunctionDecl, LayerProvides, LayerTimeouts, MemoryConfig, MemoryHooks, MemoryLayer, ProjectionPolicy, RecallParams, RecallResult, ReturnParams, ReturnResult, ScopedStorage, SpawnParams, SpawnResult, StorageAdapter, StoreParams, StoreResult, } from '@noetic-tools/memory';
161
141
  /** @public */
162
- export { Slot } from './types/memory.js';
142
+ export { Slot } from '@noetic-tools/memory';
163
143
  /** @public */
164
- export type { ExecutionContext, ExecutionOutcome, MemoryCallModelRequest, MemoryScope, } from './types/memory-context.js';
144
+ export type { ExecutionContext, ExecutionOutcome, MemoryCallModelRequest, MemoryScope, } from '@noetic-tools/types';
165
145
  /** @public */
166
- export type { MemoryTraceSpan, Span, TraceExporter } from './types/observability.js';
146
+ export type { MemoryTraceSpan, Span, TraceExporter } from '@noetic-tools/types';
167
147
  /** @public */
168
- export type { FrameworkStreamEvent, HarnessResponse, SdkStreamEvent, StreamEvent, StreamingItem, } from './types/harness-result.js';
148
+ export type { FrameworkStreamEvent, HarnessResponse, SdkStreamEvent, StreamEvent, StreamingItem, } from '@noetic-tools/types';
169
149
  /** @public */
170
- export type { AgentConfig, AgentHarnessContract, AgentHooks, CallModelRequest, DeliveryMode, ExecuteOptions, HarnessStatus, RecallLayerOutput, SessionScope, } from './types/runtime.js';
150
+ export type { AgentConfig, AgentHarnessContract, AgentHooks, CallModelRequest, DeliveryMode, ExecuteOptions, HarnessStatus, RecallLayerOutput, SessionScope, } from '@noetic-tools/types';
171
151
  /** @public */
172
- export type { AfterModelCallParams, AfterModelCallResult, BeforeToolCallParams, BeforeToolCallResult, LedgerEntry, SteeringConfig, SteeringDecision, SteeringRule, SteeringState, } from './types/steering.js';
152
+ export type { AfterModelCallParams, AfterModelCallResult, BeforeToolCallParams, BeforeToolCallResult, LedgerEntry, SteeringConfig, SteeringDecision, SteeringRule, SteeringState, } from '@noetic-tools/types';
173
153
  /** @public */
174
- export { LedgerEntryKind, SteeringAction } from './types/steering.js';
154
+ export { LedgerEntryKind, SteeringAction } from '@noetic-tools/types';
175
155
  /** @public */
176
- export type { ExecuteStepFn, SettleResult, Snapshot, Step, StepBranch, StepFork, StepForkAll, StepForkRace, StepForkSettle, StepLLM, StepLoop, StepProvide, StepRun, StepSpawn, StepTool, Until, Verdict, } from './types/step.js';
156
+ export type { ExecuteStepFn, SettleResult, Snapshot, Step, StepBranch, StepFork, StepForkAll, StepForkRace, StepForkSettle, StepLLM, StepLoop, StepProvide, StepRun, StepSpawn, StepTool, Until, Verdict, } from '@noetic-tools/types';
177
157
  /** @public */
178
- export type { FsAdapter, FsStats } from './types/fs-adapter.js';
179
- /** @public Reusable error-serialiser used by custom SubprocessAdapter implementations. */
180
- export { serializeError } from './adapters/in-memory-subprocess/metadata.js';
158
+ export type { FsAdapter, FsStats } from '@noetic-tools/types';
181
159
  /** @public */
182
- export type { ShellAdapter, ShellExecOptions, ShellExecResult } from './types/shell-adapter.js';
183
160
  /** @public */
184
- export { TIMEOUT_ERROR_PREFIX } from './types/shell-adapter.js';
161
+ export type { ProcessSubprocessRequest, SerializedError, ShellAdapter, ShellExecOptions, ShellExecResult, StepSubprocessOverrides, StepSubprocessRequest, SubprocessAdapter, SubprocessControlResult, SubprocessHandle, SubprocessHandleMetadata, SubprocessRequest, SubprocessStatus, SubprocessStopResult, } from '@noetic-tools/types';
185
162
  /** @public */
186
- export type { ProcessSubprocessRequest, SerializedError, StepSubprocessOverrides, StepSubprocessRequest, SubprocessAdapter, SubprocessControlResult, SubprocessHandle, SubprocessHandleMetadata, SubprocessRequest, SubprocessStatus, SubprocessStopResult, } from './types/subprocess-adapter.js';
163
+ export { TIMEOUT_ERROR_PREFIX } from '@noetic-tools/types';
164
+ /** @public Reusable error-serialiser used by custom SubprocessAdapter implementations. */
165
+ export { serializeError } from './adapters/in-memory-subprocess/metadata.js';
187
166
  /** @public */
188
- export type { ToolExecutionContext, ToolMemory } from './types/tool-context.js';
167
+ export type { ToolExecutionContext, ToolMemory } from '@noetic-tools/types';
189
168
  /** @public */
190
169
  export { all, any } from './until/combinators.js';
191
170
  /** @public */
package/dist/index.js CHANGED
@@ -38,45 +38,31 @@ export { cosineSimilarity } from './conditions/cosine-similarity.js';
38
38
  //#endregion
39
39
  //#region Errors
40
40
  /** @public */
41
- export { isNoeticConfigError, NoeticConfigError } from './errors/noetic-config-error.js';
42
41
  /** @public */
43
- export { isNoeticError, NoeticErrorImpl } from './errors/noetic-error.js';
42
+ export { isNoeticConfigError, isNoeticError, NoeticConfigError, NoeticErrorImpl, } from '@noetic-tools/types';
44
43
  /** @public */
45
44
  export { AskUserAnnotationSchema, AskUserInputSchema, AskUserOptionSchema, AskUserOutputSchema, AskUserQuestionSchema, } from './types/ask-user-types.js';
46
45
  //#endregion
47
46
  //#region Execution
48
47
  /** @public */
49
48
  export { execute } from './interpreter/execute.js';
50
- //#endregion
51
- //#region Memory Layers
52
49
  /** @public */
53
- export { findFunctionCall } from './memory/function-call-utils.js';
54
50
  /** @public */
55
- export { durableTaskState } from './memory/layers/durable-task-state.js';
56
51
  /** @public */
57
- export { fileReference } from './memory/layers/file-reference.js';
58
52
  /** @public */
59
- export { historyWindow } from './memory/layers/history-window.js';
60
53
  /** @public */
61
- export { observationalMemory } from './memory/layers/observational-memory.js';
62
54
  /** @public */
63
- export { PlanPhase, planMemory } from './memory/layers/plan.js';
64
55
  /** @public */
65
- export { staticContent } from './memory/layers/static-content.js';
66
56
  /** @public */
67
- export { steering } from './memory/layers/steering.js';
68
57
  /** @public */
69
- export { temporalMemory } from './memory/layers/temporal.js';
70
58
  /** @public */
71
- export { toolMemoryLayer } from './memory/layers/tool-memory-layer.js';
72
59
  /** @public */
73
- export { workingMemory } from './memory/layers/working-memory.js';
74
60
  /** @public */
75
- export { stripUnresolvedToolCalls } from './memory/strip-unresolved.js';
61
+ export { durableTaskState, fileReference, findFunctionCall, historyWindow, observationalMemory, PlanPhase, planMemory, staticContent, steering, stripUnresolvedToolCalls, temporalMemory, toolMemoryLayer, workingMemory, } from '@noetic-tools/memory';
76
62
  //#endregion
77
63
  //#region Message Utilities
78
64
  /** @public */
79
- export { createMessage, estimateTokens } from './util/message-helpers.js';
65
+ export { createMessage, estimateTokens } from '@noetic-tools/types';
80
66
  //#endregion
81
67
  //#region Observability
82
68
  /** @public */
@@ -108,27 +94,23 @@ export { getRegistry, lookupStep, registerStep } from './runtime/step-registry.j
108
94
  //#endregion
109
95
  //#region Schemas
110
96
  /** @public */
111
- export { defaultItemSchemaRegistry, ItemSchema, ItemSchemaRegistry } from './schemas/item.js';
97
+ export { defaultItemSchemaRegistry, ItemSchema, ItemSchemaRegistry } from '@noetic-tools/types';
112
98
  /** @public */
113
99
  export { MergeStrategySchema, UntilPredicateSchema, validateWorkflow, WorkflowDocumentSchema, WorkflowNodeSchema, walkWorkflow, workflowDepth, } from './schemas/workflow.js';
114
- //#endregion
115
- //#region Types — Context
116
100
  /** @public */
117
101
  export { getToolCwd, setToolCwd, snapshotCwdState } from './runtime/cwd-helpers.js';
118
102
  /** @public */
119
- export { DetachedStatus } from './types/detached.js';
103
+ export { DetachedStatus } from '@noetic-tools/types';
120
104
  /** @public */
121
105
  export { CheckpointSchemaVersion, CheckpointSnapshotSchema, CwdSnapshotSchema, FrontierFrameSchema, ItemLogSnapshotSchema, PendingAskUserSnapshotSchema, } from './types/checkpoint.js';
122
106
  /** @public */
123
- export { Slot } from './types/memory.js';
107
+ export { Slot } from '@noetic-tools/memory';
124
108
  /** @public */
125
- export { LedgerEntryKind, SteeringAction } from './types/steering.js';
126
- //#endregion
127
- //#region Types — Shell
109
+ export { LedgerEntryKind, SteeringAction } from '@noetic-tools/types';
110
+ /** @public */
111
+ export { TIMEOUT_ERROR_PREFIX } from '@noetic-tools/types';
128
112
  /** @public Reusable error-serialiser used by custom SubprocessAdapter implementations. */
129
113
  export { serializeError } from './adapters/in-memory-subprocess/metadata.js';
130
- /** @public */
131
- export { TIMEOUT_ERROR_PREFIX } from './types/shell-adapter.js';
132
114
  //#endregion
133
115
  //#region Until
134
116
  /** @public */
@@ -1,12 +1,8 @@
1
- export { contextToExecCtx } from '../memory/exec-context-factory.js';
2
- export { resolveLayerTools } from '../memory/layer-api.js';
3
- export type { LayerStateStore } from '../memory/layer-lifecycle.js';
4
- export { returnLayers, spawnLayers } from '../memory/layer-lifecycle.js';
5
- export { commitLayerUsage, computeLayerUsage } from '../memory/layer-usage.js';
6
- export { assembleView } from '../memory/projector.js';
1
+ export type { LayerStateStore } from '@noetic-tools/memory';
2
+ export { allocateBudgets, assembleView, commitLayerUsage, computeLayerUsage, contextToExecCtx, DEFAULT_PROJECTION, resolveLayerTools, returnLayers, spawnLayers, } from '@noetic-tools/memory';
3
+ export type { ItemSchemaRegistry } from '@noetic-tools/types';
4
+ export { defaultItemSchemaRegistry } from '@noetic-tools/types';
7
5
  export { emitFrameworkEvent, getBroadcaster } from '../runtime/broadcaster-utils.js';
8
6
  export { ContextImpl } from '../runtime/context-impl.js';
9
7
  export { snapshotCwdState } from '../runtime/cwd-helpers.js';
10
8
  export { buildToolExecutionContext } from '../runtime/tool-memory.js';
11
- export type { ItemSchemaRegistry } from '../schemas/item.js';
12
- export { defaultItemSchemaRegistry } from '../schemas/item.js';
@@ -1,10 +1,6 @@
1
- export { contextToExecCtx } from '../memory/exec-context-factory.js';
2
- export { resolveLayerTools } from '../memory/layer-api.js';
3
- export { returnLayers, spawnLayers } from '../memory/layer-lifecycle.js';
4
- export { commitLayerUsage, computeLayerUsage } from '../memory/layer-usage.js';
5
- export { assembleView } from '../memory/projector.js';
1
+ export { allocateBudgets, assembleView, commitLayerUsage, computeLayerUsage, contextToExecCtx, DEFAULT_PROJECTION, resolveLayerTools, returnLayers, spawnLayers, } from '@noetic-tools/memory';
2
+ export { defaultItemSchemaRegistry } from '@noetic-tools/types';
6
3
  export { emitFrameworkEvent, getBroadcaster } from '../runtime/broadcaster-utils.js';
7
4
  export { ContextImpl } from '../runtime/context-impl.js';
8
5
  export { snapshotCwdState } from '../runtime/cwd-helpers.js';
9
6
  export { buildToolExecutionContext } from '../runtime/tool-memory.js';
10
- export { defaultItemSchemaRegistry } from '../schemas/item.js';
@@ -1,8 +1,3 @@
1
- export type { RetryPolicy, StepMeta } from '../types/common.js';
2
- export type { Context } from '../types/context.js';
3
- export type { FunctionCallItem, Item } from '../types/items.js';
4
- export type { ContextMemory, ExecutionContext, MemoryConfig, MemoryLayer } from '../types/memory.js';
5
- export type { AgentHarnessContract, RecallLayerOutput } from '../types/runtime.js';
6
- export { SteeringAction } from '../types/steering.js';
7
- export type { ExecuteStepFn, StepLLM, StepProvide, StepRun, StepSpawn, StepTool, } from '../types/step.js';
8
- export type { Tool } from '../types/tool.js';
1
+ export type { ContextMemory, ExecutionContext, MemoryConfig, MemoryLayer, } from '@noetic-tools/memory';
2
+ export type { AgentHarnessContract, Context, ContextRerenderRequest, ExecuteStepFn, FunctionCallItem, Item, ProjectionPolicy, RecallLayerOutput, RetryPolicy, StepLLM, StepMeta, StepProvide, StepRun, StepSpawn, StepTool, Tool, } from '@noetic-tools/types';
3
+ export { SteeringAction } from '@noetic-tools/types';
@@ -1 +1 @@
1
- export { SteeringAction } from '../types/steering.js';
1
+ export { SteeringAction } from '@noetic-tools/types';
@@ -1,5 +1,4 @@
1
- import type { Step } from '../types/step.js';
2
- import type { Tool } from '../types/tool.js';
1
+ import type { Step, Tool } from '@noetic-tools/types';
3
2
  /**
4
3
  * Recursively walks a step tree and collects all Tool instances
5
4
  * declared on LLM steps. Used to build the unified tool set
@@ -1,4 +1,4 @@
1
- import { frameworkCast } from '../util/framework-cast.js';
1
+ import { frameworkCast } from '@noetic-tools/types';
2
2
  /**
3
3
  * Recursively walks a step tree and collects all Tool instances
4
4
  * declared on LLM steps. Used to build the unified tool set
@@ -1,12 +1,9 @@
1
1
  /**
2
2
  * Action step handlers: run, llm, spawn, provide, tool.
3
3
  */
4
+ import { createMessage, estimateTokens, extractAssistantText, frameworkCast, isNoeticError, NoeticConfigError, NoeticErrorImpl, } from '@noetic-tools/types';
4
5
  import { ZodError } from 'zod';
5
- import { NoeticConfigError } from '../errors/noetic-config-error.js';
6
- import { NoeticErrorImpl } from '../errors/noetic-error.js';
7
- import { frameworkCast } from '../util/framework-cast.js';
8
- import { createMessage, extractAssistantText } from '../util/message-helpers.js';
9
- import { assembleView, buildToolExecutionContext, ContextImpl, commitLayerUsage, computeLayerUsage, contextToExecCtx, defaultItemSchemaRegistry, emitFrameworkEvent, getBroadcaster, resolveLayerTools, returnLayers, snapshotCwdState, spawnLayers, } from './action-deps.js';
6
+ import { allocateBudgets, assembleView, buildToolExecutionContext, ContextImpl, commitLayerUsage, computeLayerUsage, contextToExecCtx, DEFAULT_PROJECTION, defaultItemSchemaRegistry, emitFrameworkEvent, getBroadcaster, resolveLayerTools, returnLayers, snapshotCwdState, spawnLayers, } from './action-deps.js';
10
7
  import { SteeringAction } from './action-types.js';
11
8
  import { cloneWithGuard } from './clone-guard.js';
12
9
  import { collectAllTools, deduplicateTools } from './collect-tools.js';
@@ -18,10 +15,23 @@ export async function executeRun(step, input, ctx) {
18
15
  const maxAttempts = retry?.maxAttempts ?? 1;
19
16
  let lastError = new Error('No attempts executed');
20
17
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
18
+ // Cancellation is not a retriable error (spec 09) — an abort that
19
+ // arrived between attempts must stop the loop before re-executing.
20
+ if (ctx.aborted) {
21
+ throw new NoeticErrorImpl({
22
+ kind: 'cancelled',
23
+ reason: ctx.abortReason ?? 'context aborted',
24
+ });
25
+ }
21
26
  try {
22
27
  return await step.execute(input, ctx);
23
28
  }
24
29
  catch (e) {
30
+ // Rethrow cancellation immediately — retrying it would re-run side
31
+ // effects after abort and bury the 'cancelled' kind under step_failed.
32
+ if (isNoeticError(e) && e.noeticError.kind === 'cancelled') {
33
+ throw e;
34
+ }
25
35
  lastError = e instanceof Error ? e : new Error(String(e));
26
36
  if (attempt < maxAttempts - 1 && retry) {
27
37
  const delay = computeDelay(retry, attempt);
@@ -55,6 +65,27 @@ function computeDelay(retry, attempt) {
55
65
  //#region llm
56
66
  const MAX_STEERING_RETRIES = 3;
57
67
  const emptyRecall = [];
68
+ /**
69
+ * Merge re-render recall outputs over the base recall results, replacing entries
70
+ * for the same layer and keeping slot order. New layer entries are appended.
71
+ */
72
+ function mergeRecallResults(base, overrides, slotOf) {
73
+ if (overrides.length === 0) {
74
+ return base;
75
+ }
76
+ const byId = new Map(overrides.map((r) => [
77
+ r.layerId,
78
+ r,
79
+ ]));
80
+ const merged = base.map((r) => byId.get(r.layerId) ?? r);
81
+ const seen = new Set(base.map((r) => r.layerId));
82
+ for (const o of overrides) {
83
+ if (!seen.has(o.layerId)) {
84
+ merged.push(o);
85
+ }
86
+ }
87
+ return merged.sort((a, b) => (slotOf.get(a.layerId) ?? 0) - (slotOf.get(b.layerId) ?? 0));
88
+ }
58
89
  /**
59
90
  * Resolves a `Lazy<T>` step field. If the value is a function, it is invoked
60
91
  * with the current context; otherwise the value is returned as-is. Supports
@@ -123,14 +154,15 @@ function resolveToolsAndRestrictions(stepTools, layers, ctx) {
123
154
  allowedToolNames: undefined,
124
155
  };
125
156
  }
126
- async function runInputPipeline({ ctx, layers, input }) {
157
+ async function runInputPipeline({ ctx, layers, input, }) {
127
158
  const userItem = createMessage(input, 'user');
128
- const { items: finalItems } = await ctx.harness.runAppendPipeline(layers, [
159
+ const { items: finalItems, rerenderRequests } = await ctx.harness.runAppendPipeline(layers, [
129
160
  userItem,
130
161
  ], ctx);
131
162
  for (const item of finalItems) {
132
163
  ctx.itemLog.append(item);
133
164
  }
165
+ return rerenderRequests;
134
166
  }
135
167
  export async function executeLLM(step, input, ctx, layers) {
136
168
  const baseCtx = frameworkCast(ctx);
@@ -149,9 +181,12 @@ export async function executeLLM(step, input, ctx, layers) {
149
181
  const resolvedInstructions = await resolveLazy(step.instructions, ctx);
150
182
  const resolvedStepTools = await resolveLazy(step.tools, ctx);
151
183
  // Append user input — through layer pipeline if layers exist, otherwise direct.
184
+ // The append pipeline may request a context re-render (e.g. a layer that
185
+ // expanded an input reference into new content); applied after recall below.
186
+ let rerenderRequests = [];
152
187
  if (typeof input === 'string' && input.length > 0) {
153
188
  if (hasLayers) {
154
- await runInputPipeline({
189
+ rerenderRequests = await runInputPipeline({
155
190
  ctx: baseCtx,
156
191
  layers,
157
192
  input,
@@ -162,14 +197,55 @@ export async function executeLLM(step, input, ctx, layers) {
162
197
  }
163
198
  }
164
199
  const { tools: resolvedTools, allowedToolNames } = resolveToolsAndRestrictions(resolvedStepTools, layers, baseCtx);
165
- // Recall once per LLM step: every layer with a recall hook contributes its
166
- // current view. Results drive both the assembled context window and the
167
- // per-layer usage breakdown (ctx.lastLayerUsage). Recall fires before the
200
+ // Resolve the projection policy (step override > harness default > fallback)
201
+ // and split the context budget across layers via allocateBudgets.
202
+ const policy = step.projection ?? baseCtx.harness.config.projection ?? DEFAULT_PROJECTION;
203
+ // `instructions` are sent to the model as a separate field, outside the
204
+ // assembled view. Reserve their tokens from the projection budget so the
205
+ // view + instructions together stay within the policy's token budget.
206
+ const systemPromptTokens = resolvedInstructions ? estimateTokens(resolvedInstructions) : 0;
207
+ const viewPolicy = {
208
+ ...policy,
209
+ tokenBudget: Math.max(0, policy.tokenBudget - systemPromptTokens),
210
+ };
211
+ let budgetMap = new Map();
212
+ if (hasLayers) {
213
+ const { allocations } = allocateBudgets({
214
+ layers,
215
+ totalBudget: policy.tokenBudget,
216
+ systemPromptTokens,
217
+ responseReserve: policy.responseReserve,
218
+ });
219
+ budgetMap = new Map(allocations.map((a) => [
220
+ a.layerId,
221
+ a.allocated,
222
+ ]));
223
+ }
224
+ // Recall once per LLM step: atomic layers run in the hot path; eventual layers
225
+ // are served from cache. Results drive both the assembled context window and
226
+ // the per-layer usage breakdown (ctx.lastLayerUsage). Recall fires before the
168
227
  // steering retry loop because retries replay the same context.
169
228
  const recallQuery = typeof input === 'string' ? input : '';
170
- const recallResults = hasLayers
171
- ? await baseCtx.harness.recallLayers(layers, recallQuery, baseCtx)
172
- : emptyRecall;
229
+ const slotOf = new Map((layers ?? []).map((l) => [
230
+ l.id,
231
+ l.slot,
232
+ ]));
233
+ let recallResults = emptyRecall;
234
+ if (hasLayers) {
235
+ const atomic = await baseCtx.harness.recallLayersAtomic(layers, recallQuery, baseCtx, budgetMap);
236
+ const eventual = await baseCtx.harness.recallLayersEventual(layers, recallQuery, baseCtx, budgetMap);
237
+ recallResults = [
238
+ ...atomic,
239
+ ...eventual,
240
+ ].sort((a, b) => (slotOf.get(a.layerId) ?? 0) - (slotOf.get(b.layerId) ?? 0));
241
+ // Apply re-render requests collected from the input-append pipeline.
242
+ if (rerenderRequests.length > 0) {
243
+ const rerendered = await baseCtx.harness.executeRerender(rerenderRequests, layers, baseCtx, budgetMap, recallQuery);
244
+ recallResults = mergeRecallResults([
245
+ ...recallResults,
246
+ ], rerendered, slotOf);
247
+ }
248
+ }
173
249
  const layerOutputItems = recallResults.flatMap((r) => r.items);
174
250
  let retries = 0;
175
251
  while (retries <= MAX_STEERING_RETRIES) {
@@ -177,19 +253,34 @@ export async function executeLLM(step, input, ctx, layers) {
177
253
  const projectedHistoryItems = hasLayers
178
254
  ? await baseCtx.harness.projectHistory(layers, rawHistoryItems, baseCtx)
179
255
  : rawHistoryItems;
180
- const assembledItems = layerOutputItems.length > 0
181
- ? assembleView({
182
- systemPromptItems: [],
256
+ let assembledItems;
257
+ if (hasLayers) {
258
+ // Keep system messages at the front; the projector enforces the token
259
+ // budget (drops highest-slot layer output, then oldest history).
260
+ const systemItems = [];
261
+ const nonSystemHistory = [];
262
+ for (const item of projectedHistoryItems) {
263
+ if (item.type === 'message' && item.role === 'system') {
264
+ systemItems.push(item);
265
+ continue;
266
+ }
267
+ nonSystemHistory.push(item);
268
+ }
269
+ assembledItems = assembleView({
270
+ systemPromptItems: systemItems,
183
271
  layerOutputItems,
184
- historyItems: [
185
- ...projectedHistoryItems,
186
- ],
187
- })
188
- : projectedHistoryItems === rawHistoryItems
189
- ? rawHistoryItems
190
- : [
191
- ...projectedHistoryItems,
192
- ];
272
+ historyItems: nonSystemHistory,
273
+ policy: viewPolicy,
274
+ });
275
+ }
276
+ else {
277
+ assembledItems =
278
+ projectedHistoryItems === rawHistoryItems
279
+ ? rawHistoryItems
280
+ : [
281
+ ...projectedHistoryItems,
282
+ ];
283
+ }
193
284
  const request = resolvedTools
194
285
  ? {
195
286
  model: resolvedModel,
@@ -212,6 +303,11 @@ export async function executeLLM(step, input, ctx, layers) {
212
303
  emit: step.emit,
213
304
  };
214
305
  const response = await baseCtx.harness.callModel(request);
306
+ // Track tokens/cost for EVERY model call, including responses steering
307
+ // subsequently rejects (Deny throw / Guide retry below) — the spend is
308
+ // real, and until.maxCost / HarnessResponse.usage must see it (spec 07:
309
+ // tokens accumulate across all LLM calls).
310
+ trackUsage(baseCtx, response);
215
311
  if (hasLayers) {
216
312
  const decision = await baseCtx.harness.afterModelCall(layers, response, baseCtx);
217
313
  if (decision.action === SteeringAction.Deny) {
@@ -242,7 +338,6 @@ export async function executeLLM(step, input, ctx, layers) {
242
338
  if (isMutableContext(baseCtx)) {
243
339
  baseCtx.lastStepMeta = meta;
244
340
  }
245
- trackUsage(baseCtx, response);
246
341
  commitLayerUsage(baseCtx, computeLayerUsage({
247
342
  ctx: baseCtx,
248
343
  modelId: resolvedModel,
@@ -1,8 +1,7 @@
1
1
  /**
2
2
  * Control-flow step handlers: branch, fork, loop, every.
3
3
  */
4
- import type { Context } from '../types/context.js';
5
- import type { ExecuteStepFn, StepBranch, StepEvery, StepFork, StepLoop } from '../types/step.js';
4
+ import type { Context, ExecuteStepFn, StepBranch, StepEvery, StepFork, StepLoop } from '@noetic-tools/types';
6
5
  export declare function executeBranch<TMemory, I, O>(step: StepBranch<TMemory, I, O>, input: I, ctx: Context<TMemory>, executeStep: ExecuteStepFn): Promise<O>;
7
6
  export declare function executeFork<TMemory, I, O>(step: StepFork<TMemory, I, O>, input: I, ctx: Context<TMemory>, executeStep: ExecuteStepFn): Promise<O>;
8
7
  export declare function executeLoop<TMemory, I, O>(step: StepLoop<TMemory, I, O>, input: I, ctx: Context<TMemory>, executeStep: ExecuteStepFn): Promise<O>;