@noetic-tools/core 5.21.0 → 5.22.0-next.2

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 (101) hide show
  1. package/dist/adapters/openrouter.d.ts +6 -1
  2. package/dist/adapters/openrouter.js +10 -0
  3. package/dist/builders/decide-builders.d.ts +7 -0
  4. package/dist/builders/tool-builder.d.ts +25 -1
  5. package/dist/builders/tool-builder.js +25 -1
  6. package/dist/builders/workflow-control-nodes.js +1 -0
  7. package/dist/builders/workflow-hydrator.d.ts +19 -0
  8. package/dist/builders/workflow-hydrator.js +19 -0
  9. package/dist/builders/workflow-step.js +7 -1
  10. package/dist/connections/cron-schedule.js +12 -3
  11. package/dist/connections/durability.d.ts +1 -2
  12. package/dist/connections/durability.js +1 -4
  13. package/dist/connections/gates.js +6 -2
  14. package/dist/connections/harness-wiring.d.ts +5 -0
  15. package/dist/connections/harness-wiring.js +76 -10
  16. package/dist/connections/in-memory-connection.d.ts +4 -0
  17. package/dist/connections/in-memory-connection.js +10 -0
  18. package/dist/connections/model-tools.js +5 -1
  19. package/dist/connections/registry.d.ts +6 -2
  20. package/dist/connections/registry.js +10 -0
  21. package/dist/connections/sources.js +261 -20
  22. package/dist/connections/triggers.d.ts +62 -2
  23. package/dist/connections/triggers.js +375 -35
  24. package/dist/harness/agent-harness.d.ts +317 -4
  25. package/dist/harness/agent-harness.js +1264 -96
  26. package/dist/harness/connection-gate.d.ts +3 -0
  27. package/dist/harness/connection-gate.js +4 -0
  28. package/dist/harness/decide-call.d.ts +15 -0
  29. package/dist/harness/decide-call.js +57 -7
  30. package/dist/harness/deps/runtime.d.ts +3 -0
  31. package/dist/harness/deps/runtime.js +2 -0
  32. package/dist/harness/flow-version.d.ts +13 -0
  33. package/dist/harness/flow-version.js +66 -0
  34. package/dist/harness/harness-options.d.ts +91 -0
  35. package/dist/harness/llm-client.d.ts +2 -0
  36. package/dist/harness/llm-client.js +9 -5
  37. package/dist/harness/model-call.js +8 -0
  38. package/dist/harness/model-rounds.d.ts +30 -0
  39. package/dist/harness/model-rounds.js +146 -1
  40. package/dist/harness/model-tool-round.d.ts +3 -0
  41. package/dist/harness/model-tool-round.js +249 -22
  42. package/dist/harness/park-watchers.d.ts +93 -0
  43. package/dist/harness/park-watchers.js +217 -0
  44. package/dist/harness/read-decision.d.ts +23 -0
  45. package/dist/harness/read-decision.js +100 -0
  46. package/dist/harness/spend.js +4 -0
  47. package/dist/harness/steer-inbox.js +3 -1
  48. package/dist/harness/thread-record.d.ts +77 -1
  49. package/dist/harness/thread-record.js +272 -13
  50. package/dist/index.d.ts +22 -8
  51. package/dist/index.js +12 -2
  52. package/dist/interpreter/acp-resume.d.ts +77 -0
  53. package/dist/interpreter/acp-resume.js +164 -0
  54. package/dist/interpreter/acp-tools.d.ts +11 -0
  55. package/dist/interpreter/acp-tools.js +94 -7
  56. package/dist/interpreter/connection-steps.d.ts +24 -1
  57. package/dist/interpreter/connection-steps.js +77 -2
  58. package/dist/interpreter/execute-acp-agent.js +111 -15
  59. package/dist/interpreter/execute-action.js +7 -0
  60. package/dist/interpreter/execute-call.js +30 -4
  61. package/dist/interpreter/execute-control.js +21 -0
  62. package/dist/interpreter/execute-decide.js +5 -0
  63. package/dist/interpreter/execute-invoke-tool.js +149 -5
  64. package/dist/interpreter/execute-wait.js +67 -9
  65. package/dist/interpreter/execute.js +4 -0
  66. package/dist/interpreter/turn-ending.d.ts +15 -0
  67. package/dist/interpreter/turn-ending.js +46 -0
  68. package/dist/portable/builders.d.ts +1 -1
  69. package/dist/portable/builders.js +1 -1
  70. package/dist/portable/runtime.d.ts +4 -0
  71. package/dist/portable/runtime.js +2 -0
  72. package/dist/runtime/durable/parking.d.ts +61 -0
  73. package/dist/runtime/durable/parking.js +137 -0
  74. package/dist/runtime/durable/session-store.d.ts +38 -0
  75. package/dist/runtime/durable/session-store.js +79 -1
  76. package/dist/runtime/durable/step-ledger.d.ts +121 -2
  77. package/dist/runtime/durable/step-ledger.js +352 -15
  78. package/dist/runtime/durable/turn-lease.d.ts +128 -0
  79. package/dist/runtime/durable/turn-lease.js +307 -0
  80. package/dist/runtime/event-broadcaster.d.ts +9 -1
  81. package/dist/runtime/event-broadcaster.js +16 -1
  82. package/dist/runtime/held-calls.d.ts +192 -0
  83. package/dist/runtime/held-calls.js +496 -0
  84. package/dist/runtime/in-memory-storage.d.ts +10 -1
  85. package/dist/runtime/in-memory-storage.js +20 -2
  86. package/dist/runtime/message-queue.d.ts +2 -0
  87. package/dist/runtime/message-queue.js +8 -0
  88. package/dist/runtime/output-store.d.ts +88 -0
  89. package/dist/runtime/output-store.js +241 -0
  90. package/dist/runtime/session-runner.d.ts +18 -2
  91. package/dist/runtime/session-runner.js +88 -3
  92. package/dist/runtime/session-streams.d.ts +28 -7
  93. package/dist/runtime/session-streams.js +112 -67
  94. package/dist/runtime/tool-approval.d.ts +46 -6
  95. package/dist/runtime/tool-approval.js +160 -38
  96. package/dist/runtime/tool-call.d.ts +34 -2
  97. package/dist/runtime/tool-call.js +182 -13
  98. package/dist/runtime/tool-context.d.ts +15 -1
  99. package/dist/runtime/tool-context.js +38 -2
  100. package/package.json +3 -3
  101. package/schema/noetic-workflow.schema.json +27 -0
@@ -1,12 +1,13 @@
1
- import type { ArtifactStore, ConnectionStatus } from '@noetic-tools/types';
1
+ import type { ApproveRequest, ArtifactStore, ConnectionStatus, ConnectionTrigger, ExecuteArgument, HeldCall, HeldResolution, StuckTurn, TrailMark } from '@noetic-tools/types';
2
2
  import { ItemSchemaRegistry } from '@noetic-tools/types';
3
3
  import { AcpSessionStore } from '../runtime/acp-session-store.js';
4
+ import type { OutputSnapshot } from '../runtime/output-store.js';
4
5
  import type { LayerStateStore, RecallCache } from './deps/context.js';
5
6
  import type { DetachedSpawnOverrides } from './deps/interpreter.js';
6
7
  import type { CheckpointStore, EventBroadcaster, RestoreCheckpointOptions, StepLedgerRetention, StepLedgerStore } from './deps/runtime.js';
7
8
  import { ChannelStore, Drains } from './deps/runtime.js';
8
- import type { AcpLiveSession, AcpSessionInfo, AgentConfig, AgentHarnessContract, CallModelRequest, CancelOptions, Channel, ChannelHandle, Context, ContextCacheStore, ContextData, ContextLayer, CustomItem, CustomItemOf, CustomItemStreamEvent, CustomStreamingItem, CwdState, DecideRequest, DecideResponse, DecisionRecord, DeclaredItems, DetachedHandle, DrainReport, ExecuteInput, ExecuteOptions, ExecutionScope, ExecutionStatus, ExternalChannel, FsAdapter, HarnessResponse, HarnessStatus, Item, LLMResponse, OnSteerParams, PendingSpend, RecallLayerOutput, RecallOptions, ReconcileSpendOptions, SessionScope, SessionUsage, ShellAdapter, Span, SpendSettlement, SteeringDecision, SteerVerdict, Step, StepLike, StepsInput, StepsOutput, StorageAdapter, StreamEvent, StreamingItem, SubprocessAdapter, TraceExporter, ValidStepChain, WriteOffSpendOptions } from './deps/types.js';
9
- import type { AgentHarnessOpts } from './harness-options.js';
9
+ import type { AcpLiveSession, AcpSessionInfo, AgentConfig, AgentHarnessContract, CallModelRequest, CancelOptions, Channel, ChannelHandle, Context, ContextCacheStore, ContextData, ContextLayer, CustomItem, CustomItemOf, CustomItemStreamEvent, CustomStreamingItem, CwdState, DecideRequest, DecideResponse, DecisionRecord, DeclaredItems, DetachedHandle, DrainReport, ExecuteOptions, ExecutionScope, ExecutionStatus, ExternalChannel, FsAdapter, HarnessResponse, HarnessStatus, Item, LLMResponse, OnSteerParams, PendingSpend, RecallLayerOutput, RecallOptions, ReconcileSpendOptions, SessionScope, SessionUsage, ShellAdapter, Span, SpendSettlement, SteeringDecision, SteerVerdict, Step, StepLike, StepsInput, StepsOutput, StorageAdapter, StreamEvent, StreamingItem, SubprocessAdapter, TraceExporter, ValidStepChain, WriteOffSpendOptions } from './deps/types.js';
10
+ import type { AgentHarnessOpts, WakeTimeListener } from './harness-options.js';
10
11
  import { Spend } from './spend.js';
11
12
  /**
12
13
  * Default agent harness for executing agent steps with built-in channel, context, and trace support.
@@ -66,10 +67,34 @@ export declare class AgentHarness<TParams extends Record<string, unknown> = Reco
66
67
  private readonly liveRoots;
67
68
  /** Stored sessions for `execute()` threads. Present exactly when durability is on. */
68
69
  private readonly sessionStore?;
70
+ /** Set when sessions are durable and storage can compare-and-set. */
71
+ private readonly leaseOptions?;
72
+ /** The flow version this harness runs, when the host names one. */
73
+ private readonly version?;
74
+ /** Set when turns park (`environment.storage.park`): the grace before one does. */
75
+ private readonly parkGraceMs?;
76
+ /** Set when this harness wakes the turns it parked (`park.autoWake`). */
77
+ private readonly parkWatchers?;
78
+ /** Who hears when the next wake time changes (`onWakeTimeChange`). */
79
+ private readonly wakeTimeListeners;
80
+ /** The wake time listeners last heard; `null` until they have heard one. */
81
+ private announcedWakeTime;
82
+ /** The announcement in flight, so two never run out of order. */
83
+ private announcing;
69
84
  /** Checkpoint capture in flight per execution id — see `saveCheckpoint`. */
70
85
  private readonly pendingCheckpoints;
71
86
  private readonly defaultDeliveryMode;
72
87
  private readonly sessions;
88
+ /** Whether threads keep their streamed output for display (`opts.interactive`). */
89
+ readonly interactive: boolean;
90
+ /** Where display output is kept: the harness's storage, or memory without one. */
91
+ private readonly outputStorage;
92
+ /** The display output each thread of an interactive harness records, by thread id. */
93
+ private readonly outputs;
94
+ /** Thread id → what stops recording it. */
95
+ private readonly stopRecording;
96
+ /** Threads named by a host-built context's own id, dropped when its run ends. */
97
+ private readonly ownThreads;
73
98
  /**
74
99
  * @internal Live ACP connections. Reached by the interpreter via
75
100
  * `frameworkCast`; use {@link listAcpSessions}, {@link getAcpSession},
@@ -148,6 +173,35 @@ export declare class AgentHarness<TParams extends Record<string, unknown> = Reco
148
173
  * @public
149
174
  */
150
175
  start(): Promise<void>;
176
+ /**
177
+ * Hear when `getNextWakeTime()` changes: a turn parks, resumes or ends, a
178
+ * trigger is added or removed, or a scheduled source's event is read. `listener`
179
+ * gets the new time, or `undefined` when there is nothing to wake for. The first
180
+ * call comes when the harness starts. A host with no process of its own between
181
+ * events sets its alarm from it.
182
+ *
183
+ * The harness waits for the listener before a parking turn answers, and a
184
+ * listener that throws there fails that turn's response: a turn nothing will
185
+ * wake must not look safely parked. Anywhere else a throw is logged.
186
+ *
187
+ * It does not replace the harness's own timer (`park.autoWake`).
188
+ *
189
+ * @returns a function that stops the listener hearing.
190
+ * @public
191
+ */
192
+ onWakeTimeChange(listener: WakeTimeListener): () => void;
193
+ /** Tell the listeners the next wake time, when it is not the one they last heard. */
194
+ private announceWakeTime;
195
+ /** `announceWakeTime`, where a listener's failure has no turn to land on. */
196
+ private announceWakeTimeQuietly;
197
+ /**
198
+ * Resolves once the harness has nothing in hand: every scheduled event that is
199
+ * due has been read by its trigger, and every turn has finished or parked. A
200
+ * serverless host awaits it after `start()` and `wake()`, before it lets its
201
+ * process go.
202
+ * @public
203
+ */
204
+ waitForIdle(): Promise<void>;
151
205
  /**
152
206
  * Each connection's state, identity and pool usage; one entry for `name`, or all.
153
207
  * @public
@@ -169,7 +223,53 @@ export declare class AgentHarness<TParams extends Record<string, unknown> = Reco
169
223
  * for passing an absolute, validated path.
170
224
  */
171
225
  setRootCwd(nextCwd: string): void;
172
- execute(input: ExecuteInput, options?: ExecuteOptions): Promise<void>;
226
+ /**
227
+ * Hand the thread a message, a person's decision, or both.
228
+ *
229
+ * A {@link DecisionItem} answers a tool call the thread's turn holds, or settles
230
+ * its stuck turn. It is not written to the conversation, and input that holds
231
+ * nothing else starts no turn: the turn the decision is for goes on.
232
+ *
233
+ * Several decisions in one list are read first, so a malformed one changes
234
+ * nothing, and then taken in order: one the thread's state refuses throws, and
235
+ * those before it stay taken. `options` reach the turn a decision resumes.
236
+ *
237
+ * @throws NoeticError `hold_refused` when an answer to a held call cannot be
238
+ * taken: the thread holds no such call, `argsHash` names other arguments, the
239
+ * answer is the wrong kind for the hold, the call was already answered
240
+ * differently, its `output` is not a JSON value, or a `function_call_output`
241
+ * item names a held call.
242
+ * @throws NoeticError `decision_refused` when a decision does not fit what the
243
+ * thread is waiting on: no turn is stuck, it carries both an `action` and an
244
+ * `output`, or its action is the wrong kind for a decision with, or without,
245
+ * a `callId`.
246
+ * @public
247
+ */
248
+ execute(input: ExecuteArgument, options?: ExecuteOptions): Promise<void>;
249
+ /**
250
+ * Act on the decisions in `input` and resolve what is left of it: the message to
251
+ * deliver, or undefined when the input was decisions only.
252
+ *
253
+ * Every decision is read before any is acted on, so a list with a malformed one
254
+ * changes nothing. They are then acted on in order: one the thread's state
255
+ * refuses throws, and those before it stay taken.
256
+ */
257
+ private takeDecisions;
258
+ /**
259
+ * A held call's result comes in a decision. A `function_call_output` for one
260
+ * would go into the conversation and leave the call waiting, so it is refused.
261
+ */
262
+ private refuseResultsForHeldCalls;
263
+ /** Act on one decision: an answer to a held call, or the settling of a stuck turn. */
264
+ private takeDecision;
265
+ private deliverInput;
266
+ /**
267
+ * Hand a message to its thread. One at a time per thread: what to do with a
268
+ * message is decided by looking at the thread and then acting, and two
269
+ * deliveries doing that at once would each miss the other.
270
+ */
271
+ private deliver;
272
+ private deliverOne;
173
273
  /** The turn's response. `items` holds final items: standard ones and the graph's declared custom items. */
174
274
  getAgentResponse(scope?: SessionScope): Promise<HarnessResponse<Item | CustomItemOf<DeclaredItems<TItem>>>>;
175
275
  /**
@@ -177,6 +277,31 @@ export declare class AgentHarness<TParams extends Record<string, unknown> = Reco
177
277
  * each event in progress (`isComplete: false`), then its final item, under one `id`.
178
278
  */
179
279
  getItemStream(scope?: SessionScope): AsyncIterable<StreamingItem | CustomStreamingItem<DeclaredItems<TItem>>>;
280
+ /**
281
+ * A thread's display output (spec 08 § Display output): the latest snapshot of
282
+ * every item it streamed, unfinished ones included, read from storage. An
283
+ * `interactive` harness records it; any harness over the same storage reads it.
284
+ * For showing a thread again, never for resuming one.
285
+ *
286
+ * @throws OutputStoreError when storage fails, or holds something else under the key.
287
+ * @public
288
+ */
289
+ getSessionOutput(scope?: SessionScope): Promise<OutputSnapshot[]>;
290
+ /**
291
+ * Save display snapshots for a thread, each replacing the stored one with its
292
+ * id, and resolve the thread's whole display output. For a protocol adapter
293
+ * that shows a thread in its own item shapes. Model history is untouched.
294
+ *
295
+ * @throws OutputStoreError when `items` are not snapshots (objects with a string
296
+ * `type`), or storage fails.
297
+ * @public
298
+ */
299
+ saveSessionOutput(items: ReadonlyArray<unknown>, scope: SessionScope): Promise<OutputSnapshot[]>;
300
+ /**
301
+ * The thread's one output store: every write for a thread goes through it, so
302
+ * this harness's writes queue behind each other instead of racing.
303
+ */
304
+ private outputOf;
180
305
  getTextStream(scope?: SessionScope): AsyncIterable<string>;
181
306
  getReasoningStream(scope?: SessionScope): AsyncIterable<string>;
182
307
  /** Every event raw, including each declared custom item's `custom_item_event`. */
@@ -193,15 +318,185 @@ export declare class AgentHarness<TParams extends Record<string, unknown> = Reco
193
318
  getUsage(scope?: SessionScope): SessionUsage;
194
319
  seedSessionHistory(threadId: string, items: ReadonlyArray<Item>): void;
195
320
  private getOrCreateSession;
321
+ /**
322
+ * Resume turns that are parked or were cut off (spec 23 § Parked turns).
323
+ *
324
+ * With no `threadId`, every stored thread is looked at: a parked turn is resumed
325
+ * once its wake time has come, and a cut-off turn at once. With a `threadId`, that
326
+ * thread's turn is resumed whether or not it is due — the call a host makes when
327
+ * it knows the event a parked turn waits for has arrived. A turn another harness
328
+ * holds, or one already running here, is left alone.
329
+ *
330
+ * A resumed turn replays what it finished and goes on. `options` are the
331
+ * `execute()` options it runs with; a stored turn keeps none of its own.
332
+ *
333
+ * Resolves the ids of the threads it resumed. Durable sessions only.
334
+ * @public
335
+ */
336
+ wake(scope?: {
337
+ threadId?: string;
338
+ options?: ExecuteOptions;
339
+ }): Promise<string[]>;
340
+ /**
341
+ * The earliest time the harness has something to do, in epoch ms: a parked turn
342
+ * that needs waking, or the next event of a scheduled source a trigger listens
343
+ * to (`cron()`). Undefined when there is neither. A host with no process of its
344
+ * own between events (a serverless worker) schedules its next `start()` and
345
+ * `wake()` from this.
346
+ * @public
347
+ */
348
+ getNextWakeTime(): Promise<number | undefined>;
349
+ /**
350
+ * When a routine `wake()` would have something to do for the thread's turn: a
351
+ * parked turn at its deadline, a turn cut off by a crash at once. Never before
352
+ * another harness's lease on it runs out, since a wake before then does nothing.
353
+ * Undefined for a turn that waits on something other than time, and one that is
354
+ * stuck or stopped. A turn this harness is running is due one lease period from
355
+ * now: the time to come back if the process running it is gone.
356
+ */
357
+ private turnDueAt;
358
+ /**
359
+ * The tool calls a thread's turn holds for a person (spec 08 § Held tool calls):
360
+ * calls waiting for approval, and calls whose tool left its result open. Each
361
+ * carries what a decision needs to answer it.
362
+ * @public
363
+ */
364
+ pending(scope?: SessionScope | ExecutionScope): Promise<HeldCall[]>;
365
+ /**
366
+ * Answer a held tool call: a decision for one that waits for approval, an output
367
+ * for one that waits for its result. The turn then goes on — at once when it is
368
+ * running here, and by being woken when it is parked.
369
+ *
370
+ * `scope` names the thread, or with `{ executionId }` an execution a host runs
371
+ * itself through `harness.run()`.
372
+ *
373
+ * The first answer wins. The same answer again is a no-op, so a host may retry.
374
+ * Pass the `argsHash` the call was shown with to make sure the answer is for it.
375
+ *
376
+ * @throws NoeticError `hold_refused` when the thread holds no such call,
377
+ * `argsHash` names different arguments, the answer is the wrong kind for the
378
+ * hold, or the call was already answered differently.
379
+ * @internal Hosts answer through `execute()` with a `DecisionItem`, which
380
+ * carries an `executionId` for a call held by a run the host started itself.
381
+ * This is what that calls.
382
+ */
383
+ resolveHeld(scope: SessionScope | ExecutionScope | undefined, answer: HeldResolution & {
384
+ readonly callId: string;
385
+ readonly argsHash?: string;
386
+ }, options?: ExecuteOptions): Promise<void>;
387
+ /**
388
+ * The turns that stopped rather than redo a step that had a lasting effect under
389
+ * another flow version (spec 23 § Versions). Each waits for a `DecisionItem`
390
+ * with `continue`, `restart` or `abandon`, passed to `execute()` on its thread.
391
+ * @public
392
+ */
393
+ listStuckRuns(): Promise<StuckTurn[]>;
394
+ /**
395
+ * Settle a stuck turn (spec 23 § Versions). Resolves false when the thread has none.
396
+ *
397
+ * - `continue`: accept the difference. The turn resumes on this harness's
398
+ * version, and the step that no longer matches runs again.
399
+ * - `restart`: forget what the turn recorded and run it from the top on this
400
+ * harness's version. Every step runs again, effects included.
401
+ * - `abandon`: drop the turn. Its trail is kept.
402
+ */
403
+ private settleStuckTurn;
404
+ /**
405
+ * What a run did, step by step: who ran each step, under which flow version, and
406
+ * the receipt of a step with a lasting effect (spec 23 § The trail). Marks outlive
407
+ * the ledger entries they came from, so the trail of a finished run stays readable.
408
+ *
409
+ * `scope` names an execution, or a thread, whose recent turns are then listed in
410
+ * order.
411
+ * @public
412
+ */
413
+ getAuditTrail(scope: SessionScope | ExecutionScope): Promise<TrailMark[]>;
414
+ /**
415
+ * Add a trigger while the harness runs (spec 35 § Triggers). A trigger written
416
+ * with expressions only is kept in storage, so it is there again after a restart;
417
+ * one with a function in it lasts for this process.
418
+ *
419
+ * @throws NoeticConfigError `CONNECTION_INVALID` for an id already in use, a
420
+ * missing event or an expression that does not parse; `CONNECTION_UNKNOWN` for
421
+ * an unknown connection.
422
+ * @public
423
+ */
424
+ addTrigger(trigger: ConnectionTrigger): Promise<void>;
425
+ /**
426
+ * Stop and forget a trigger. Resolves false when there is none with that id.
427
+ * @public
428
+ */
429
+ removeTrigger(id: string): Promise<boolean>;
430
+ /**
431
+ * Every trigger the harness has: its own, and those added while it ran.
432
+ * @public
433
+ */
434
+ listTriggers(): ConnectionTrigger[];
435
+ /** The watchers that wake this harness's parked turns, when auto-wake is on. */
436
+ private createParkWatchers;
437
+ /**
438
+ * Messages that reached the runner while the thread's turn is parked or stuck
439
+ * (one that landed as the turn was closing out, say). Starting a turn with them
440
+ * would throw the waiting one away, so they are kept in storage for after it. A
441
+ * steer wakes a parked turn, as one delivered a moment later would. An
442
+ * `interrupt` is not set aside: replacing the turn is what it asks for.
443
+ * Resolves true when the messages were set aside.
444
+ */
445
+ private setAside;
446
+ /** Resume a parked turn when one of its held calls already has an answer. */
447
+ private wakeIfAnswered;
448
+ /**
449
+ * A message delivered again after its turn finished (spec 23a § Sessions): a queue
450
+ * that delivers at least once, or a webhook the sender retried. It is answered
451
+ * with the answer that turn gave, and nothing runs. Resolves true when it was.
452
+ */
453
+ private answerAgain;
454
+ /**
455
+ * A message delivered again while this harness already has it in hand: its turn is
456
+ * running, it is queued to run, or its turn finished a moment ago and the runner
457
+ * has not gone idle yet (spec 23a § Sessions). Queuing it would run the same
458
+ * message as a second turn once the first ends. It is dropped; the caller reads
459
+ * the answer of the turn that has it. Resolves true when it was.
460
+ */
461
+ private inHand;
462
+ /**
463
+ * A message for a thread whose turn is parked (spec 23 § Parked turns). It must not
464
+ * start a turn of its own: the thread has one in flight, and starting another would
465
+ * abandon it. Resolves true when the message was taken care of here.
466
+ *
467
+ * - `next-turn` waits in storage for the parked turn to end.
468
+ * - A steer wakes the turn, which offers it to the context layers as it would mid-round.
469
+ * - `interrupt` is not handled here: it replaces the turn, as it does a running one.
470
+ */
471
+ private deliverToParked;
472
+ /** The execution whose held calls `scope` names. */
473
+ private heldExecutionId;
474
+ /** The execution of the thread's turn in flight: running here, or stored. */
475
+ private turnExecutionId;
476
+ /** The harness clock. */
477
+ private now;
478
+ /** Hand the turn's lease back and return the thread record to best-effort writes. */
479
+ private releaseLease;
196
480
  /** The stored record for `threadId`, when durability is on. */
197
481
  private threadRecord;
198
482
  private requireSession;
199
483
  callModel(request: CallModelRequest): Promise<LLMResponse>;
200
484
  decide(request: DecideRequest): Promise<DecideResponse>;
485
+ /**
486
+ * The approval seam (spec 08 § Held tool calls): the `approveToolCall` approver
487
+ * decides, and with none, or when it answers `hold`, the action is held until
488
+ * a decision answers it. Resolves the settled decision.
489
+ * @public
490
+ */
491
+ approve(request: ApproveRequest): Promise<SteeringDecision>;
201
492
  notifyDecision(layers: ContextLayer[], record: DecisionRecord, ctx: Context): Promise<void>;
202
493
  /**
203
494
  * Runs a step — or an array of steps in sequence, each output the next one's
204
495
  * input. Every link of an array is type-checked (`ValidStepChain`).
496
+ *
497
+ * @internal How one step runs another (`execCtx.harness.run` inside a step or a
498
+ * tool), and how a test runs a step on a context it built. A host's way in is
499
+ * `execute()`.
205
500
  */
206
501
  run<I, O>(step: Step<ContextData, I, O>, input: I, ctx: Context): Promise<O>;
207
502
  run<const T extends StepLike | ReadonlyArray<StepLike>>(steps: T & ValidStepChain<T>, input: StepsInput<T>, ctx: Context): Promise<StepsOutput<T>>;
@@ -237,6 +532,18 @@ export declare class AgentHarness<TParams extends Record<string, unknown> = Reco
237
532
  * close anything.
238
533
  */
239
534
  private executeClosingChannels;
535
+ /**
536
+ * Wait for what a run streamed to be saved. Display output never decides a run:
537
+ * a save that failed is logged, stays queued for the next flush, and the run's
538
+ * own result or error stands.
539
+ */
540
+ private saveOutputOfRun;
541
+ /**
542
+ * A thread named by a host-built context's own id has no later turns: once its
543
+ * run ends, the harness drops its session and output store. What was saved stays
544
+ * in storage under `output:<ctx.id>`.
545
+ */
546
+ private forgetOwnThread;
240
547
  /**
241
548
  * Fix the point a resume of this run starts from, and queue it for saving — so even
242
549
  * a run whose first step dies leaves a snapshot to restore. The save is not awaited:
@@ -303,6 +610,12 @@ export declare class AgentHarness<TParams extends Record<string, unknown> = Reco
303
610
  _connectionViews?: ContextLayer[];
304
611
  _broadcaster?: EventBroadcaster;
305
612
  }): Context;
613
+ /**
614
+ * On an interactive harness, a root context a host builds joins its thread: it
615
+ * gets the thread's broadcaster, so `run()` on it streams, and is recorded, like
616
+ * a session turn. A context with no `threadId` is its own thread, named by its id.
617
+ */
618
+ private interactiveThread;
306
619
  send<T>(channel: Channel<T>, value: NoInfer<T>, ctx: Context): Promise<void>;
307
620
  recv<T>(channel: Channel<T>, ctx: Context, opts?: {
308
621
  timeout?: number;