@noetic-tools/core 3.2.0 → 4.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 (94) hide show
  1. package/dist/adapters/in-memory-subprocess/manifest-persistence.d.ts +1 -1
  2. package/dist/adapters/in-memory-subprocess/types.d.ts +1 -1
  3. package/dist/adapters/openrouter.d.ts +2 -2
  4. package/dist/adapters/openrouter.js +2 -2
  5. package/dist/builders/context-builder.d.ts +11 -0
  6. package/dist/builders/context-builder.js +15 -0
  7. package/dist/builders/context-option.d.ts +23 -0
  8. package/dist/builders/context-option.js +22 -0
  9. package/dist/builders/control-flow-builders.d.ts +19 -19
  10. package/dist/builders/every.d.ts +4 -4
  11. package/dist/builders/layer-provides-builders.d.ts +1 -1
  12. package/dist/builders/layer-provides-builders.js +1 -1
  13. package/dist/builders/loop-builder.d.ts +3 -3
  14. package/dist/builders/provide-builder.d.ts +14 -7
  15. package/dist/builders/provide-builder.js +15 -4
  16. package/dist/builders/spawn-builder.d.ts +8 -6
  17. package/dist/builders/spawn-builder.js +7 -2
  18. package/dist/builders/step-builders.d.ts +19 -20
  19. package/dist/builders/tool-builder.d.ts +9 -5
  20. package/dist/builders/tool-builder.js +3 -2
  21. package/dist/builders/workflow-hydrator.d.ts +17 -4
  22. package/dist/builders/workflow-hydrator.js +87 -8
  23. package/dist/builders/workflow-step.d.ts +61 -0
  24. package/dist/builders/workflow-step.js +126 -0
  25. package/dist/conditions/conditions.d.ts +17 -17
  26. package/dist/conditions/conditions.js +1 -1
  27. package/dist/deprecated.d.ts +30 -0
  28. package/dist/deprecated.js +28 -0
  29. package/dist/harness/agent-harness.d.ts +30 -26
  30. package/dist/harness/agent-harness.js +23 -19
  31. package/dist/harness/deps/{memory.d.ts → context.d.ts} +2 -2
  32. package/dist/harness/deps/{memory.js → context.js} +1 -1
  33. package/dist/harness/deps/types.d.ts +1 -1
  34. package/dist/harness/model-schema.d.ts +2 -2
  35. package/dist/index.d.ts +21 -17
  36. package/dist/index.js +14 -8
  37. package/dist/interpreter/action-deps.d.ts +3 -3
  38. package/dist/interpreter/action-deps.js +2 -2
  39. package/dist/interpreter/action-types.d.ts +1 -1
  40. package/dist/interpreter/collect-tools.d.ts +1 -1
  41. package/dist/interpreter/execute-action.d.ts +10 -10
  42. package/dist/interpreter/execute-action.js +13 -13
  43. package/dist/interpreter/execute-control.d.ts +4 -4
  44. package/dist/interpreter/execute-control.js +1 -1
  45. package/dist/interpreter/execute-sub-harness.d.ts +1 -1
  46. package/dist/interpreter/execute.d.ts +3 -3
  47. package/dist/interpreter/execute.js +78 -31
  48. package/dist/interpreter/step-dispatcher.d.ts +3 -3
  49. package/dist/interpreter/sub-harness-events.d.ts +2 -2
  50. package/dist/interpreter/typeguards.d.ts +4 -4
  51. package/dist/patterns/dynamic-workflow.d.ts +7 -4
  52. package/dist/patterns/dynamic-workflow.js +2 -0
  53. package/dist/patterns/interview.d.ts +2 -2
  54. package/dist/patterns/plans.d.ts +5 -5
  55. package/dist/patterns/ralph-wiggum.d.ts +2 -2
  56. package/dist/patterns/react.d.ts +7 -5
  57. package/dist/patterns/react.js +6 -4
  58. package/dist/portable/builders.js +2 -0
  59. package/dist/portable/context-layers.d.ts +8 -0
  60. package/dist/portable/context-layers.js +8 -0
  61. package/dist/portable.d.ts +2 -2
  62. package/dist/portable.js +2 -2
  63. package/dist/runtime/context-deps.d.ts +2 -2
  64. package/dist/runtime/context-deps.js +1 -1
  65. package/dist/runtime/context-impl.d.ts +10 -8
  66. package/dist/runtime/context-impl.js +11 -7
  67. package/dist/runtime/context-type-deps.d.ts +1 -1
  68. package/dist/runtime/durable/checkpoint-store.d.ts +1 -1
  69. package/dist/runtime/durable/harness-checkpoints.d.ts +2 -3
  70. package/dist/runtime/durable/harness-checkpoints.js +2 -3
  71. package/dist/runtime/durable/step-ledger.d.ts +1 -1
  72. package/dist/runtime/durable/step-ledger.js +1 -1
  73. package/dist/runtime/in-memory-storage.d.ts +1 -1
  74. package/dist/runtime/session-runner.d.ts +1 -1
  75. package/dist/runtime/step-registry.d.ts +3 -3
  76. package/dist/runtime/{tool-memory.d.ts → tool-context.d.ts} +1 -2
  77. package/dist/runtime/{tool-memory.js → tool-context.js} +5 -2
  78. package/dist/runtime/tool-ui.d.ts +1 -1
  79. package/dist/runtime/tool-ui.js +1 -1
  80. package/dist/schemas/workflow.d.ts +5 -279
  81. package/dist/schemas/workflow.js +4 -376
  82. package/dist/types/mutable-context.d.ts +2 -2
  83. package/dist/types/step-registrar.d.ts +1 -1
  84. package/dist/unstable.d.ts +5 -5
  85. package/dist/unstable.js +3 -3
  86. package/dist/until/predicates.d.ts +1 -1
  87. package/package.json +4 -4
  88. package/schema/noetic-workflow.schema.json +28 -0
  89. package/dist/builders/memory-builder.d.ts +0 -11
  90. package/dist/builders/memory-builder.js +0 -15
  91. package/dist/patterns/flow.d.ts +0 -2
  92. package/dist/patterns/flow.js +0 -1
  93. package/dist/portable/memory-layers.d.ts +0 -8
  94. package/dist/portable/memory-layers.js +0 -8
@@ -1,10 +1,10 @@
1
- import type { ContextMemory } from '@noetic-tools/memory';
1
+ import type { ContextData } from '@noetic-tools/context';
2
2
  import type { Step } from '@noetic-tools/types';
3
3
  /** Registry-wide step type — stored at the widest generic parameters so
4
4
  * callers can register steps with narrower input/output types without
5
5
  * fighting variance. The public `Step` default already uses `unknown` for
6
6
  * the input and output parameters, matching this shape. */
7
- type RegisteredStep = Step<ContextMemory, unknown, unknown>;
7
+ type RegisteredStep = Step<ContextData, unknown, unknown>;
8
8
  /**
9
9
  * @public
10
10
  * Registers a step so the subprocess adapter can look it up by id.
@@ -18,7 +18,7 @@ type RegisteredStep = Step<ContextMemory, unknown, unknown>;
18
18
  * `clearRegistry` wiring is deferred — see the tracked follow-up task on
19
19
  * the team's board (strict-registry-plus-test-clear).
20
20
  */
21
- export declare function registerStep<TMemory, I, O>(step: Step<TMemory, I, O>): void;
21
+ export declare function registerStep<TContext, I, O>(step: Step<TContext, I, O>): void;
22
22
  /**
23
23
  * @public
24
24
  * Looks up a registered step by id. Returns `null` when the id is not known
@@ -1,4 +1,3 @@
1
- import type { AgentHarnessContract, Context, ToolExecutionContext, ToolMemory } from '@noetic-tools/types';
1
+ import type { AgentHarnessContract, Context, ToolExecutionContext } from '@noetic-tools/types';
2
2
  import type { TurnContext } from '@openrouter/agent';
3
- export declare function buildToolMemory(harness: AgentHarnessContract, ctx: Context): ToolMemory;
4
3
  export declare function buildToolExecutionContext(ctx: Context, harness: AgentHarnessContract, turnContext?: TurnContext): ToolExecutionContext;
@@ -1,4 +1,4 @@
1
- export function buildToolMemory(harness, ctx) {
1
+ function buildToolContext(harness, ctx) {
2
2
  return {
3
3
  get(layerId) {
4
4
  return harness.getLayerState(ctx.id, layerId);
@@ -9,12 +9,15 @@ export function buildToolMemory(harness, ctx) {
9
9
  };
10
10
  }
11
11
  export function buildToolExecutionContext(ctx, harness, turnContext) {
12
+ const toolContext = buildToolContext(harness, ctx);
12
13
  return {
13
14
  ctx,
14
15
  harness,
15
16
  fs: harness.fs,
16
17
  shell: harness.shell,
17
- memory: buildToolMemory(harness, ctx),
18
+ context: toolContext,
19
+ // Deprecated alias — same accessor object, not a copy.
20
+ memory: toolContext,
18
21
  assembledView: ctx.itemLog.items,
19
22
  lastStepMeta: ctx.lastStepMeta,
20
23
  turnContext,
@@ -5,7 +5,7 @@
5
5
  * render functions at the call / progress / result / error lifecycle points and
6
6
  * forwards each returned `UiFragment` as an `openui.fragment` framework event
7
7
  * (namespaced `${agentName}:openui.fragment`). The framework never interprets
8
- * the fragment source — a UI surface (memory layer + transport) composes it.
8
+ * the fragment source — a UI surface (context layer + transport) composes it.
9
9
  *
10
10
  * The `ui` methods are declared bivariantly on `ToolUiDeclaration`, so the
11
11
  * erased `Tool` handle the runtime holds can call them with runtime values.
@@ -5,7 +5,7 @@
5
5
  * render functions at the call / progress / result / error lifecycle points and
6
6
  * forwards each returned `UiFragment` as an `openui.fragment` framework event
7
7
  * (namespaced `${agentName}:openui.fragment`). The framework never interprets
8
- * the fragment source — a UI surface (memory layer + transport) composes it.
8
+ * the fragment source — a UI surface (context layer + transport) composes it.
9
9
  *
10
10
  * The `ui` methods are declared bivariantly on `ToolUiDeclaration`, so the
11
11
  * erased `Tool` handle the runtime holds can call them with runtime values.
@@ -1,281 +1,7 @@
1
1
  /**
2
- * Zod schemas for JSON-serialisable workflow definitions.
3
- *
4
- * A `WorkflowDocument` is a portable, JSON-safe representation of a noetic
5
- * step tree. It covers every step kind. The `run` node carries its body as a
6
- * code STRING (not an in-process closure) dispatched through a subprocess
7
- * adapter, keeping the document JSON-safe. The hydrator in
8
- * `builders/workflow-hydrator.ts` converts a validated document back into live
9
- * `Step` objects via the existing builders.
2
+ * The JSON workflow schema lives in `@noetic-tools/types` so the memory
3
+ * package (which must not import core) can validate workflow documents.
4
+ * This barrel keeps core's public and intra-core import paths unchanged.
10
5
  */
11
- import type { SubHarnessKind } from '@noetic-tools/types';
12
- import { z } from 'zod';
13
- interface UntilAnyPredicate {
14
- kind: 'any';
15
- predicates: UntilPredicate[];
16
- }
17
- interface UntilAllPredicate {
18
- kind: 'all';
19
- predicates: UntilPredicate[];
20
- }
21
- /** @public Discriminated union of named until predicates usable in JSON workflows. */
22
- export type UntilPredicate = {
23
- kind: 'maxSteps';
24
- n: number;
25
- } | {
26
- kind: 'maxCost';
27
- usd: number;
28
- } | {
29
- kind: 'maxDuration';
30
- ms: number;
31
- } | {
32
- kind: 'noToolCalls';
33
- } | {
34
- kind: 'outputContains';
35
- marker: string;
36
- } | {
37
- kind: 'outputEquals';
38
- sentinel: string;
39
- } | {
40
- kind: 'converged';
41
- threshold?: number;
42
- } | UntilAnyPredicate | UntilAllPredicate;
43
- /** @public Zod schema validating a named `until` predicate (including `any`/`all` combinators). */
44
- export declare const UntilPredicateSchema: z.ZodType<UntilPredicate>;
45
- /** @public ESM literal enum for merge strategies. */
46
- export declare const MergeStrategy: {
47
- readonly Last: 'last';
48
- readonly First: 'first';
49
- readonly Concat: 'concat';
50
- };
51
- /** @public Named merge strategy for fork nodes. */
52
- export type MergeStrategy = (typeof MergeStrategy)[keyof typeof MergeStrategy];
53
- /** @public Zod schema for the named merge strategy used by `fork` nodes. */
54
- export declare const MergeStrategySchema: z.ZodEnum<{
55
- concat: "concat";
56
- first: "first";
57
- last: "last";
58
- }>;
59
- declare const ModelParamsSchema: z.ZodObject<{
60
- temperature: z.ZodOptional<z.ZodNumber>;
61
- topP: z.ZodOptional<z.ZodNumber>;
62
- maxTokens: z.ZodOptional<z.ZodNumber>;
63
- stopSequences: z.ZodOptional<z.ZodArray<z.ZodString>>;
64
- }, z.core.$strip>;
65
- /**
66
- * A uniform tool entry on an `llm` node. Every entry is an object keyed by
67
- * `type`:
68
- * - A CLIENT tool is `{ type: "<registered-tool-name>" }`. The hydrator
69
- * resolves `type` against the tool registry; `parameters` (if present) is
70
- * ignored — client tools receive their call args from the model at runtime.
71
- * - A SERVER tool is `{ type: "openrouter:web_search" | "openrouter:web_fetch",
72
- * parameters?: {...} }`. The provider executes it; `parameters` keys are
73
- * camelCase (e.g. `maxResults`, `searchContextSize`) — the SDK re-serialises
74
- * them and silently drops unknown keys.
75
- *
76
- * Server vs client is decided by the `type` value (a reserved `openrouter:*`
77
- * server-tool literal vs an arbitrary tool name), not by the entry's shape.
78
- */
79
- declare const LlmToolEntrySchema: z.ZodObject<{
80
- type: z.ZodString;
81
- parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
82
- }, z.core.$strip>;
83
- /** Retry policy for a `run` node, mirroring `RetryPolicy` in `@noetic-tools/types`. */
84
- declare const RetryPolicySchema: z.ZodObject<{
85
- maxAttempts: z.ZodNumber;
86
- backoff: z.ZodEnum<{
87
- exponential: "exponential";
88
- fixed: "fixed";
89
- linear: "linear";
90
- }>;
91
- initialDelay: z.ZodNumber;
92
- maxDelay: z.ZodOptional<z.ZodNumber>;
93
- }, z.core.$strip>;
94
- declare const HarnessSettingsSchema: z.ZodObject<{
95
- model: z.ZodOptional<z.ZodString>;
96
- permissionMode: z.ZodOptional<z.ZodEnum<{
97
- acceptEdits: "acceptEdits";
98
- bypassPermissions: "bypassPermissions";
99
- default: "default";
100
- plan: "plan";
101
- }>>;
102
- maxTurns: z.ZodOptional<z.ZodNumber>;
103
- allowedTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
104
- extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
105
- }, z.core.$strip>;
106
- declare const HarnessSessionPolicySchema: z.ZodObject<{
107
- reuse: z.ZodOptional<z.ZodString>;
108
- onComplete: z.ZodOptional<z.ZodEnum<{
109
- destroy: "destroy";
110
- detach: "detach";
111
- stop: "stop";
112
- }>>;
113
- }, z.core.$strip>;
114
- interface WorkflowNodeBase {
115
- id: string;
116
- }
117
- /**
118
- * A reference to a streaming `OutputCodec` for an `llm` node's structured
119
- * output. The hydrator resolves `library` from `HydrationContext.uiLibraries`
120
- * to a live codec (e.g. `openUi(myLibrary)` from `@noetic-tools/openui`), the
121
- * same registry-resolution pattern sub-harness nodes use for adapters. Kept a
122
- * *reference* because a codec is a runtime object, not JSON-expressible.
123
- */
124
- export interface OutputCodecRef {
125
- /** The codec dialect. Only `'openui'` is defined today. */
126
- codec: 'openui';
127
- /** Registry key resolved from `HydrationContext.uiLibraries`. */
128
- library: string;
129
- }
130
- export interface LlmWorkflowNode extends WorkflowNodeBase {
131
- kind: 'llm';
132
- model?: string;
133
- instructions: string;
134
- /**
135
- * Tool entries. Every entry is an object `{ type, parameters? }`. A CLIENT
136
- * tool is `{ type: "<registered-tool-name>" }` (resolved from the registry);
137
- * a SERVER tool is `{ type: "openrouter:web_search" | "openrouter:web_fetch",
138
- * parameters?: {...} }` (executed by the provider). Client vs server is
139
- * decided by the `type` value.
140
- */
141
- tools?: z.infer<typeof LlmToolEntrySchema>[];
142
- params?: z.infer<typeof ModelParamsSchema>;
143
- /** Streaming output-codec reference, resolved from `HydrationContext.uiLibraries`. */
144
- output?: OutputCodecRef;
145
- }
146
- export interface ToolWorkflowNode extends WorkflowNodeBase {
147
- kind: 'tool';
148
- toolName: string;
149
- args?: Record<string, unknown>;
150
- }
151
- /**
152
- * A node that runs a serialised code body. Unlike the programmatic `step.run`
153
- * (which carries a closure), the JSON form carries `execute` as a code STRING.
154
- * The code is never eval'd in-process (Cloudflare Workers forbid eval); it is
155
- * dispatched through a subprocess adapter (`ctx.subprocess`, or a named adapter
156
- * resolved by ref). Execution therefore requires a subprocess adapter capable
157
- * of running the code and returning its stdout.
158
- */
159
- export interface RunWorkflowNode extends WorkflowNodeBase {
160
- kind: 'run';
161
- /** Source code executed in the subprocess. Receives the step input on stdin. */
162
- execute: string;
163
- /** Optional retry policy applied to the step. */
164
- retry?: z.infer<typeof RetryPolicySchema>;
165
- /** Named subprocess adapter ref; defaults to `ctx.subprocess` when omitted. */
166
- subprocess?: string;
167
- }
168
- export interface BranchRoute {
169
- match: string;
170
- target: WorkflowNode;
171
- }
172
- export interface BranchWorkflowNode extends WorkflowNodeBase {
173
- kind: 'branch';
174
- routes: BranchRoute[];
175
- default?: WorkflowNode;
176
- }
177
- export interface ForkWorkflowNode extends WorkflowNodeBase {
178
- kind: 'fork';
179
- mode: 'race' | 'all' | 'settle';
180
- /**
181
- * Static fan-out: one child per entry. Mutually exclusive with `each` —
182
- * supply exactly one.
183
- */
184
- paths?: WorkflowNode[];
185
- /**
186
- * Dynamic fan-out: instantiate this body template once per item of a
187
- * runtime-produced array (data-dependent N). Mutually exclusive with `paths`.
188
- */
189
- each?: WorkflowNode;
190
- /**
191
- * Selector key into the fork input (parsed as JSON) locating the array to
192
- * fan out over. When omitted, the input string itself is parsed as a JSON
193
- * array. Only meaningful with `each`.
194
- */
195
- over?: string;
196
- merge?: MergeStrategy;
197
- concurrency?: number;
198
- }
199
- export interface SpawnWorkflowNode extends WorkflowNodeBase {
200
- kind: 'spawn';
201
- child: WorkflowNode;
202
- timeout?: number;
203
- /**
204
- * Memory layers the child runs with, by registered name (resolved from
205
- * `HydrationContext.layers`, like `provide`). Omit to inherit the parent's
206
- * layers — the default spawn behaviour. Naming layers here REPLACES the
207
- * inherited set for the child, so list every layer the child needs.
208
- */
209
- layers?: string[];
210
- }
211
- export interface ProvideWorkflowNode extends WorkflowNodeBase {
212
- kind: 'provide';
213
- child: WorkflowNode;
214
- layers: string[];
215
- }
216
- export interface LoopWorkflowNode extends WorkflowNodeBase {
217
- kind: 'loop';
218
- body: WorkflowNode;
219
- until: UntilPredicate;
220
- maxIterations?: number;
221
- }
222
- export interface SequenceWorkflowNode extends WorkflowNodeBase {
223
- kind: 'sequence';
224
- steps: WorkflowNode[];
225
- }
226
- export interface EveryWorkflowNode extends WorkflowNodeBase {
227
- kind: 'every';
228
- step: WorkflowNode;
229
- ms: number;
230
- onError?: 'continue' | 'fail';
231
- }
232
- /**
233
- * A node that delegates a turn to a coding-agent harness. `kind` is the harness
234
- * id (e.g. `claude-code`); the hydrator resolves the matching adapter from the
235
- * workflow's harness registry.
236
- */
237
- export interface SubHarnessWorkflowNode extends WorkflowNodeBase {
238
- kind: SubHarnessKind;
239
- prompt: string;
240
- instructions?: string;
241
- settings?: z.infer<typeof HarnessSettingsSchema>;
242
- session?: z.infer<typeof HarnessSessionPolicySchema>;
243
- }
244
- /** @public Discriminated union of all JSON-serialisable workflow node kinds. */
245
- export type WorkflowNode = LlmWorkflowNode | ToolWorkflowNode | RunWorkflowNode | BranchWorkflowNode | ForkWorkflowNode | SpawnWorkflowNode | ProvideWorkflowNode | LoopWorkflowNode | SequenceWorkflowNode | EveryWorkflowNode | SubHarnessWorkflowNode;
246
- /** @public Zod schema validating a single `WorkflowNode` (any JSON-safe kind). */
247
- export declare const WorkflowNodeSchema: z.ZodType<WorkflowNode>;
248
- /** @public Top-level envelope for a JSON workflow definition. */
249
- export interface WorkflowDocument {
250
- version: 1;
251
- root: WorkflowNode;
252
- }
253
- /** @public Zod schema validating a complete `WorkflowDocument`. */
254
- export declare const WorkflowDocumentSchema: z.ZodType<WorkflowDocument>;
255
- /** Validates a candidate workflow document. Throws `ZodError` on invalid input. */
256
- export declare function validateWorkflow(input: unknown): WorkflowDocument;
257
- /** Walks a workflow tree depth-first, yielding each node. */
258
- export declare function walkWorkflow(node: WorkflowNode): Iterable<WorkflowNode>;
259
- /** A flattened, JSON-safe view of a workflow tree: its nodes and parent→child edges. */
260
- export interface WorkflowGraph {
261
- nodes: Array<{
262
- id: string;
263
- kind: WorkflowNode['kind'];
264
- }>;
265
- edges: Array<{
266
- from: string;
267
- to: string;
268
- }>;
269
- }
270
- /**
271
- * Flattens a workflow tree into a node + edge list — the static "potential
272
- * paths" of the DAG, suitable for attaching to a trace span so observers can
273
- * reconstruct the declared graph independent of which branches actually ran.
274
- */
275
- export declare function workflowGraph(root: WorkflowNode): WorkflowGraph;
276
- /**
277
- * Returns the maximum depth of a workflow tree.
278
- * Leaf nodes (`llm`, `tool`) have depth 0. Structural nodes add +1.
279
- */
280
- export declare function workflowDepth(node: WorkflowNode): number;
281
- export {};
6
+ export type { BranchRoute, BranchWorkflowNode, EveryWorkflowNode, ForkWorkflowNode, LlmWorkflowNode, LoopWorkflowNode, OutputCodecRef, ProvideWorkflowNode, RunWorkflowNode, SequenceWorkflowNode, SpawnWorkflowNode, SubflowWorkflowNode, SubHarnessWorkflowNode, ToolWorkflowNode, UntilPredicate, WorkflowDocument, WorkflowGraph, WorkflowNode, } from '@noetic-tools/types';
7
+ export { MergeStrategy, MergeStrategySchema, UntilPredicateSchema, validateWorkflow, WorkflowDocumentSchema, WorkflowNodeSchema, walkWorkflow, workflowDepth, workflowGraph, } from '@noetic-tools/types';