@cadenza.io/core 3.26.1 → 3.28.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/README.md CHANGED
@@ -134,11 +134,114 @@ Cadenza.emit('meta.some.event', {foo: 'bar'}); // Emit from anywhere
134
134
 
135
135
  For full examples, see the cadenza-service package (https://github.com/cadenzaio/cadenza-service) or the test suite.
136
136
 
137
+ ### Layer-Scoped Tools
138
+
139
+ Tasks and helpers can now declare helper and global dependencies and consume them through a dedicated `tools` argument.
140
+
141
+ ```typescript
142
+ import Cadenza from "@cadenza.io/core";
143
+
144
+ const currency = Cadenza.createGlobal("Currency config", {
145
+ code: "EUR",
146
+ locale: "sv-SE",
147
+ });
148
+
149
+ const normalizeAmount = Cadenza.createHelper(
150
+ "Normalize amount",
151
+ (context, emit, inquire, tools) => ({
152
+ ...context,
153
+ normalizedAmount: Number(context.amount).toFixed(2),
154
+ currencyCode: tools.globals.currency.code,
155
+ }),
156
+ ).usesGlobals({
157
+ currency,
158
+ });
159
+
160
+ const formatAmount = Cadenza.createTask(
161
+ "Format amount",
162
+ (context, emit, inquire, tools) => {
163
+ const normalized = tools.helpers.normalize({
164
+ amount: context.amount,
165
+ });
166
+ return {
167
+ ...context,
168
+ label: `${normalized.normalizedAmount} ${tools.globals.currency.code}`,
169
+ };
170
+ },
171
+ ).usesHelpers({
172
+ normalize: normalizeAmount,
173
+ }).usesGlobals({
174
+ currency,
175
+ });
176
+ ```
177
+
178
+ Contract rules:
179
+
180
+ - task and helper handlers use `(context, emit, inquire, tools, progressCallback)`
181
+ - only explicitly declared same-layer dependencies appear in `tools`
182
+ - `tools.helpers.<alias>` is the callable helper entrypoint
183
+ - `tools.globals.<alias>` is a deep-frozen JSON-serializable value
184
+ - helpers are definition artifacts, not graph nodes
185
+ - helpers may call declared helpers and read declared globals, but may not mutate graph structure
186
+
187
+ ### Runtime-Direct CLI
188
+
189
+ `@cadenza.io/core` now ships an official machine-facing CLI for local runtime authoring.
190
+
191
+ Start the stdio host:
192
+
193
+ ```bash
194
+ cadenza runtime stdio
195
+ ```
196
+
197
+ Start or attach to a named shared local runtime:
198
+
199
+ ```bash
200
+ cadenza runtime shared start --runtime multi-agent-demo
201
+ cadenza runtime shared stdio --runtime multi-agent-demo
202
+ ```
203
+
204
+ The host speaks JSON lines over stdio and is intended for agent/tool integrations. It supports:
205
+
206
+ - runtime bootstrap, reset, and snapshot inspection
207
+ - runtime subscriptions for queued signal delivery (`runtime.subscribe`, `runtime.unsubscribe`, `runtime.nextEvent`, `runtime.pollEvents`)
208
+ - task, routine, intent, actor, actor-task, helper, and global upserts
209
+ - task links, observed signals, emitted signals, intent bindings, and helper/global dependency bindings
210
+ - direct `run`, `emit`, and `inquire` operations against the live in-process runtime
211
+
212
+ Example handshake:
213
+
214
+ ```json
215
+ {"ready":true,"protocol":"cadenza-runtime-jsonl","protocolVersion":"1","runtimeMode":"core","runtimeSharing":"isolated","runtimeName":null,"sessionId":null,"sessionRole":null,"supportedOperations":["runtime.bootstrap","runtime.info","runtime.detach","runtime.shutdown","runtime.reset","runtime.snapshot","runtime.subscribe","runtime.unsubscribe","runtime.nextEvent","runtime.pollEvents","task.upsert","task.link","task.observeSignal","task.emitSignal","task.respondToIntent","helper.upsert","global.upsert","task.useHelper","task.useGlobal","helper.useHelper","helper.useGlobal","routine.upsert","routine.observeSignal","intent.upsert","actor.upsert","actorTask.upsert","run","emit","inquire"]}
216
+ ```
217
+
218
+ Runtime-authored handlers are supplied as JS/TS source strings and compiled inside a restricted local sandbox. They are session-local and inspectable through `runtime.snapshot`, but v1 does not persist them to disk.
219
+
220
+ Runtime snapshots now also include helper/global definitions and direct task/helper tool bindings.
221
+
222
+ Signal subscriptions are pull-based rather than push-streamed. Agents subscribe to signal patterns, then drain queued events with `runtime.nextEvent` or `runtime.pollEvents`. This keeps the stdio transport request/response only while still allowing reactive agent behavior for both business and runtime meta signals.
223
+
224
+ Shared mode adds a local daemon-backed collaboration path for multiple agents:
225
+
226
+ - `runtime.info` reports whether the session is isolated or shared and which role it has
227
+ - `runtime.detach` disconnects the current attached shared session without stopping the runtime
228
+ - `runtime.shutdown` shuts down the current runtime process or shared daemon
229
+ - shared sessions use one named in-memory runtime per daemon process
230
+ - roles are `owner`, `writer`, and `observer`
231
+
232
+ Shared mode keeps Cadenza semantics intact:
233
+
234
+ - prefer `emit` to trigger system flows
235
+ - prefer `inquire` to retrieve values from the system
236
+ - treat `run` as a manual debugging or direct execution tool
237
+
137
238
  ## Features
138
239
  - **Graph-Based Orchestration**: Define tasks and routines with chaining for dependencies and layering.
139
240
  - **Event-Driven Choreography**: Signals for loose coupling with meta-signals for self-management.
140
241
  - **Context Management**: Immutable contexts with metadata separation and schema validation.
141
242
  - **Execution Engine**: Sync/async strategies, throttling, debouncing, fan-in/fan-out merging, dynamic task creation/chaining/deletion.
243
+ - **Layer-Scoped Tools**: Explicit helper/global definitions, alias-scoped runtime injection, and immutable global values.
244
+ - **Runtime-Direct Authoring**: Agent/tool-friendly stdio host for defining and executing local primitives without file writes.
142
245
 
143
246
  ## Architecture Overview
144
247
  Cadenza's core is divided into:
@@ -148,6 +251,8 @@ Cadenza's core is divided into:
148
251
  - **Context Layer**: GraphContext for data flow.
149
252
  - **Registry Layer**: GraphRegistry for introspection.
150
253
  - **Factory**: Cadenza for creation and bootstrap.
254
+ - **Tool Layer**: Helper/global definitions, alias maps, and runtime tool resolution for tasks and helpers.
255
+ - **Runtime Host Layer**: JSONL stdio protocol + runtime-definition helpers for agent-driven local authoring.
151
256
 
152
257
  ## Contributing
153
258
  Contributions are welcome! Please fork the repo, create a branch, and submit a PR. Follow the code style and add tests for new features.