@sema-agent/core 7.5.1 → 7.6.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 (132) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/dist/agents/cascade.d.ts +2 -2
  3. package/dist/agents/cascade.js +12 -10
  4. package/dist/agents/repair-loop.d.ts +5 -3
  5. package/dist/agents/repair-loop.js +13 -15
  6. package/dist/agents/subagent.d.ts +24 -42
  7. package/dist/agents/subagent.js +119 -105
  8. package/dist/agents/suspend-guard.d.ts +31 -19
  9. package/dist/agents/suspend-guard.js +14 -8
  10. package/dist/agents/teacher.js +9 -9
  11. package/dist/agents/team.d.ts +4 -3
  12. package/dist/agents/team.js +10 -8
  13. package/dist/agents/verify.d.ts +3 -3
  14. package/dist/agents/verify.js +17 -17
  15. package/dist/core/a2a.js +2 -1
  16. package/dist/core/ask-origin.d.ts +60 -7
  17. package/dist/core/ask-origin.js +26 -1
  18. package/dist/core/checkpoint-store.d.ts +78 -76
  19. package/dist/core/checkpoint-store.js +17 -1
  20. package/dist/core/gate-outcome.d.ts +189 -0
  21. package/dist/core/gate-outcome.js +70 -0
  22. package/dist/core/hooks.d.ts +18 -92
  23. package/dist/core/hooks.js +88 -85
  24. package/dist/core/mcp-failure.d.ts +104 -0
  25. package/dist/core/mcp-failure.js +128 -0
  26. package/dist/core/mcp.d.ts +21 -77
  27. package/dist/core/mcp.js +76 -150
  28. package/dist/core/pause-registry.d.ts +131 -0
  29. package/dist/core/pause-registry.js +27 -0
  30. package/dist/core/protocol-table.d.ts +5 -0
  31. package/dist/core/protocol-table.js +1 -0
  32. package/dist/core/runner/abort-race.d.ts +41 -0
  33. package/dist/core/runner/abort-race.js +38 -0
  34. package/dist/core/runner/assemble-result.d.ts +32 -41
  35. package/dist/core/runner/assemble-result.js +55 -74
  36. package/dist/core/runner/checkpoint-scope.d.ts +15 -3
  37. package/dist/core/runner/checkpoint-scope.js +3 -0
  38. package/dist/core/runner/compaction-call-options.d.ts +1 -1
  39. package/dist/core/runner/content-ask-bindings.d.ts +27 -0
  40. package/dist/core/runner/content-ask-bindings.js +1 -0
  41. package/dist/core/runner/contracts.d.ts +144 -50
  42. package/dist/core/runner/denial-limit-arms.d.ts +24 -1
  43. package/dist/core/runner/denial-limit-arms.js +24 -3
  44. package/dist/core/runner/gate-exit.d.ts +74 -0
  45. package/dist/core/runner/gate-exit.js +55 -0
  46. package/dist/core/runner/inherited-ask-grants.d.ts +46 -0
  47. package/dist/core/runner/inherited-ask-grants.js +29 -0
  48. package/dist/core/runner/park-commit.d.ts +102 -0
  49. package/dist/core/runner/park-commit.js +31 -0
  50. package/dist/core/runner/{prepare-permission-rules.d.ts → permission-rule-lanes.d.ts} +109 -3
  51. package/dist/core/runner/{prepare-permission-rules.js → permission-rule-lanes.js} +47 -1
  52. package/dist/core/runner/prepare-ask-lane.d.ts +107 -0
  53. package/dist/core/runner/prepare-ask-lane.js +131 -0
  54. package/dist/core/runner/prepare-boundary-parks.d.ts +102 -0
  55. package/dist/core/runner/prepare-boundary-parks.js +169 -0
  56. package/dist/core/runner/prepare-caps-and-workflow.js +1 -1
  57. package/dist/core/runner/prepare-context-lane.d.ts +119 -0
  58. package/dist/core/runner/prepare-context-lane.js +230 -0
  59. package/dist/core/runner/prepare-gate-stations.d.ts +174 -0
  60. package/dist/core/runner/prepare-gate-stations.js +265 -0
  61. package/dist/core/runner/prepare-hands-readface.d.ts +4 -4
  62. package/dist/core/runner/prepare-inherited-gate.d.ts +4 -4
  63. package/dist/core/runner/prepare-inherited-gate.js +1 -1
  64. package/dist/core/runner/prepare-memory-engine-session.d.ts +84 -0
  65. package/dist/core/runner/prepare-memory-engine-session.js +233 -0
  66. package/dist/core/runner/prepare-memory.d.ts +44 -26
  67. package/dist/core/runner/prepare-park-ask.d.ts +162 -0
  68. package/dist/core/runner/prepare-park-ask.js +377 -0
  69. package/dist/core/runner/prepare-policy-chain.d.ts +208 -0
  70. package/dist/core/runner/prepare-policy-chain.js +584 -0
  71. package/dist/core/runner/prepare-project-context.d.ts +1 -13
  72. package/dist/core/runner/prepare-project-context.js +1 -3
  73. package/dist/core/runner/prepare-prompt-assembly.d.ts +95 -0
  74. package/dist/core/runner/prepare-prompt-assembly.js +162 -0
  75. package/dist/core/runner/prepare-prompt-inputs.d.ts +1 -20
  76. package/dist/core/runner/prepare-protocol-tools.d.ts +3 -3
  77. package/dist/core/runner/prepare-protocol-tools.js +0 -3
  78. package/dist/core/runner/prepare-question-face.d.ts +3 -21
  79. package/dist/core/runner/prepare-question-face.js +2 -1
  80. package/dist/core/runner/prepare-safety-scan.d.ts +0 -5
  81. package/dist/core/runner/prepare-safety-scan.js +1 -2
  82. package/dist/core/runner/prepare-suspend-saga.d.ts +170 -0
  83. package/dist/core/runner/prepare-suspend-saga.js +308 -0
  84. package/dist/core/runner/prepare-task.d.ts +9 -136
  85. package/dist/core/runner/prepare-task.js +47 -2745
  86. package/dist/core/runner/prepare-turn-wiring.d.ts +154 -0
  87. package/dist/core/runner/prepare-turn-wiring.js +201 -0
  88. package/dist/core/runner/prepare-wiring-manifest.d.ts +17 -17
  89. package/dist/core/runner/prepare-wiring-manifest.js +16 -10
  90. package/dist/core/runner/prepare-workspace-restore.d.ts +2 -29
  91. package/dist/core/runner/prepare-workspace-restore.js +3 -16
  92. package/dist/core/runner/prompt-hash-salt.d.ts +1 -0
  93. package/dist/core/runner/prompt-hash-salt.js +2 -0
  94. package/dist/core/runner/remote-env-retry.d.ts +29 -0
  95. package/dist/core/runner/remote-env-retry.js +16 -0
  96. package/dist/core/runner/runtask.d.ts +16 -31
  97. package/dist/core/runner/runtask.js +110 -121
  98. package/dist/core/runner/terminal-projection.d.ts +22 -0
  99. package/dist/core/runner/terminal-projection.js +28 -0
  100. package/dist/core/session.d.ts +12 -0
  101. package/dist/core/session.js +3 -0
  102. package/dist/core/store-contracts/checkpoint-store-contract.d.ts +4 -1
  103. package/dist/core/store-contracts/checkpoint-store-contract.js +8 -2
  104. package/dist/core/terminal-cause.d.ts +137 -0
  105. package/dist/core/terminal-cause.js +9 -0
  106. package/dist/core/tool-policy.d.ts +43 -139
  107. package/dist/core/tool-policy.js +79 -112
  108. package/dist/core/types.d.ts +67 -164
  109. package/dist/core/wiring-manifest.d.ts +6 -3
  110. package/dist/core/workflow-journal-store.js +3 -4
  111. package/dist/engine/harness/agent-harness.d.ts +1 -1
  112. package/dist/index.d.ts +10 -7
  113. package/dist/index.js +8 -5
  114. package/dist/orchestration/builtin-workflows.d.ts +2 -2
  115. package/dist/orchestration/builtin-workflows.js +1 -1
  116. package/dist/orchestration/goal.js +8 -7
  117. package/dist/orchestration/run-spec.js +5 -3
  118. package/dist/orchestration/run-workflow-tool.d.ts +1 -1
  119. package/dist/orchestration/run-workflow-tool.js +4 -4
  120. package/dist/orchestration/workflow-governance.d.ts +4 -4
  121. package/dist/orchestration/workflow-governance.js +4 -2
  122. package/dist/orchestration/workflow-primitives.d.ts +1 -1
  123. package/dist/orchestration/workflow-primitives.js +1 -1
  124. package/dist/orchestration/workflow.d.ts +11 -0
  125. package/dist/orchestration/workflow.js +64 -39
  126. package/dist/prompts/supervisor.d.ts +1 -1
  127. package/dist/prompts/supervisor.js +3 -3
  128. package/dist/scenarios/scenario-registry.js +1 -1
  129. package/package.json +3 -1
  130. package/test/export-surface.snapshot.json +74 -22
  131. /package/dist/core/runner/{prepare-announce-once.d.ts → announce-once-ledger.d.ts} +0 -0
  132. /package/dist/core/runner/{prepare-announce-once.js → announce-once-ledger.js} +0 -0
@@ -0,0 +1,16 @@
1
+ import { isRetryableRemoteErrorCode, RETRYABLE_REMOTE_ERROR_CODES } from "../remote-env.js";
2
+ import { withRetry } from "../with-retry.js";
3
+ export function remoteEnvFailureNote(op, error, attempts) {
4
+ return { op, code: error.code, retryable: isRetryableRemoteErrorCode(error.code), attempts, message: error.message };
5
+ }
6
+ const REMOTE_RESTORE_MAX_ATTEMPTS = 2;
7
+ const REMOTE_RESTORE_BACKOFF_MS = 200;
8
+ export async function restoreWorkspaceWithRetry(env, snapshotId, options, onAttempt) {
9
+ let attempts = 0;
10
+ const outcome = await withRetry(async (attempt) => {
11
+ attempts = attempt;
12
+ onAttempt?.(attempt);
13
+ return env.resumeVM(snapshotId, options);
14
+ }, { retryableCodes: RETRYABLE_REMOTE_ERROR_CODES, maxAttempts: REMOTE_RESTORE_MAX_ATTEMPTS, backoffMs: () => REMOTE_RESTORE_BACKOFF_MS }, { ...(options.abortSignal !== undefined ? { signal: options.abortSignal } : {}) });
15
+ return { outcome, attempts };
16
+ }
@@ -5,7 +5,8 @@ import { type TaskOutcome } from "../task-outcome.js";
5
5
  import { type SideQuerySpec, type SideQueryResult } from "../side-query.js";
6
6
  import type { SessionStore } from "../session.js";
7
7
  import { type RecoveredOrphan } from "../session-reconcile.js";
8
- import { type ApprovalSettledBy } from "../tool-policy.js";
8
+ import type { GateOutcome } from "../gate-outcome.js";
9
+ import { type McpDelivered } from "../mcp-failure.js";
9
10
  import type { AgentDefinition, ModelRef, RunnerDeps, TaskEvent, TaskResult, TaskSpec, TaskStream } from "../types.js";
10
11
  /**
11
12
  * Config re-supplied to {@link Runner.resume} (design/45). A suspended task's tools / model / policy /
@@ -80,45 +81,29 @@ interface ResumeRun {
80
81
  * the live loop's frames and the resumed batch's frames (`resolvePendingCall` + the deferred-sibling
81
82
  * close): the resumed frames used to carry only `isError`, so a client rendering tool output from frames
82
83
  * showed an empty body for every durable-approved call. Same projection = same source as the transcript.
83
- * Also the one place `settledBy` reaches a frame — see the parameter. */
84
+ * Also the one place the gate outcome reaches a frame — see the parameter. */
84
85
  declare function toolEndBodyFrom(result: unknown, isError: boolean,
85
- /** What ended the approval this call was waiting on, supplied by the CALLER of this projection — the
86
- * live loop reads it off the gate's per-call sideband, the resumed leg off the decide. Deliberately
87
- * a parameter and never derived from `result`: a tool's own `details` (which post-tool hooks may
88
- * also replace) is writable by layers that adjudicate nothing, so reading provenance out of it would
89
- * let a failing tool claim a person approved it. Omitted ⇒ the caller supplied no source: the call
90
- * settled no approval, OR an approval settled whose decider named none (a caller predating the
91
- * field) — absence is not a fact about the call (see the `tool_end.settledBy` doc, the one home). */
92
- settledBy?: ApprovalSettledBy,
93
- /** design/252 G-7 — WHOSE settlement, from the same caller and the same channel as `settledBy`, and
94
- * for the same reason it is a parameter: an attribution read out of a tool's own result would let a
95
- * tool name the person who approved it. Omitted ⇒ this call's settlement named nobody. */
96
- approver?: string,
97
- /** The ask resolver's deny-arm classification — same caller, same engine-owned channel and the same
98
- * never-derived-from-`result` posture as the two above. Omitted ⇒ not an ask-resolution deny. */
99
- resolution?: import("../tool-policy.js").AskDenyResolution,
86
+ /** The gate's record of the pass that admitted or refused this call, supplied by the CALLER of this
87
+ * projection — the live loop reads it off the gate's per-call sideband, the resumed leg off the decide's
88
+ * minted record. Deliberately a parameter and never derived from `result`: a tool's own `details`
89
+ * (which post-tool hooks may also replace) is writable by layers that adjudicate nothing, so reading
90
+ * provenance out of it would let a failing tool claim a person approved it. Omitted ⇒ the call never
91
+ * went through the gate (see the `tool_end.gate` doc, the one home). */
92
+ gate?: GateOutcome,
100
93
  /** WHICH call this run's committed durable park is holding ({@link gatedCallIdOf}), for the frames the
101
- * abort short-circuits. Same never-derived-from-`result` posture as the three above, and for the
94
+ * abort short-circuits. Same never-derived-from-`result` posture as the outcome above, and for the
102
95
  * sharpest version of that reason: this one is an assertion about a DIFFERENT call, so a tool able to
103
96
  * author it could point an approval UI at a call nobody is waiting on. Omitted ⇒ no park is holding a
104
97
  * call (nothing parked, or the park that did holds none), and the frame then carries no id at all. */
105
- gatedCallIdOfRun?: string,
106
- /** #557 — the classifier denial-limit fallback's own auto-deny marker, from the same engine-owned
107
- * settlement sideband as `resolution` (same never-derived-from-`result` posture). Omitted ⇒ absent.
108
- * The pair `settledBy:"timeout"` + `resolution:"window_expired"` WITHOUT this bit is the approval
109
- * factory's own `approvalTimeoutMs` window; a durable park's expiry is neither — the decide lane's
110
- * emitter passes no `resolution` at all (see the `tool_end.autoDenied` doc on the event type). */
111
- autoDenied?: true): {
98
+ gatedCallIdOfRun?: string): {
112
99
  output?: unknown;
113
100
  truncated?: boolean;
114
101
  totalChars?: number;
115
102
  structured?: unknown;
116
103
  errorCode?: string;
104
+ delivered?: McpDelivered;
117
105
  gatedCallId?: string;
118
- settledBy?: ApprovalSettledBy;
119
- approver?: string;
120
- resolution?: import("../tool-policy.js").AskDenyResolution;
121
- autoDenied?: true;
106
+ gate?: GateOutcome;
122
107
  };
123
108
  /**
124
109
  * scan-1/A1 — the BODY of the synthetic `tool_end` that closes a reconcile-recovered orphan. ONE
@@ -440,12 +425,12 @@ export declare class Runner {
440
425
  * factory-minted remote/worktree lane captured an already-destroyed env (plain host/static lanes were
441
426
  * false-green).
442
427
  *
443
- * design/49 v1.5 / design/76 §2.5: a SUSPENDED (`suspendRef.token`) or `needs_review` (`reviewRef.token`) pause
428
+ * design/49 v1.5 / design/76 §2.5: a committed durable pause (`pausedRef.current`, any gate kind)
444
429
  * `suspendVM`-paused the env and persisted its `workspaceHandle` into the checkpoint — destroying it would
445
430
  * discard the paused VM and make resume fail to restore. Skip teardown; `resume()` rebuilds + `resumeVM`s it. A
446
431
  * cancelled pause is reaped via `TaskStream.destroy()` (design/51); an abandoned one is the service container
447
432
  * reaper's backstop. The gate here MIRRORS the tail's reap-stash (same durable fact
448
- * `suspendRef.token===undefined && reviewRef.token===undefined`), so exactly one path owns the env's fate.
433
+ * `pausedRef.current === undefined`), so exactly one path owns the env's fate.
449
434
  */
450
435
  private teardownOwnedEnv;
451
436
  }