@sema-agent/core 5.61.0 → 5.63.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/CHANGELOG.md +107 -0
- package/dist/agents/subagent.d.ts +12 -2
- package/dist/agents/subagent.js +3 -2
- package/dist/brain/open-responses.js +8 -3
- package/dist/brain/openai.js +4 -4
- package/dist/brain/stream-engine.d.ts +13 -2
- package/dist/brain/stream-engine.js +3 -3
- package/dist/core/auto-compaction.d.ts +6 -4
- package/dist/core/auto-compaction.js +3 -0
- package/dist/core/auto-mode-prompt-assets.js +1 -1
- package/dist/core/checkpoint-store.d.ts +36 -4
- package/dist/core/checkpoint-store.js +1 -0
- package/dist/core/context-edit.d.ts +36 -29
- package/dist/core/context-edit.js +3 -3
- package/dist/core/governance-codes.d.ts +1 -1
- package/dist/core/governance-codes.js +2 -0
- package/dist/core/hooks.d.ts +86 -4
- package/dist/core/hooks.js +3 -3
- package/dist/core/memory-engine/engine.d.ts +11 -0
- package/dist/core/memory-engine/engine.js +29 -3
- package/dist/core/memory-engine/index.d.ts +1 -1
- package/dist/core/memory-engine/origin-clearance.d.ts +28 -0
- package/dist/core/park-selfcheck.js +2 -0
- package/dist/core/pricing.d.ts +24 -0
- package/dist/core/pricing.js +18 -0
- package/dist/core/runner/prepare-config-doors.d.ts +36 -2
- package/dist/core/runner/prepare-config-doors.js +66 -8
- package/dist/core/runner/prepare-task.d.ts +113 -12
- package/dist/core/runner/prepare-task.js +239 -131
- package/dist/core/runner/runtask.d.ts +7 -0
- package/dist/core/runner/runtask.js +325 -95
- package/dist/core/runner/turn-attachments.d.ts +137 -5
- package/dist/core/runner/turn-attachments.js +25 -2
- package/dist/core/store-contracts/checkpoint-store-contract.js +19 -0
- package/dist/core/tool-errors.d.ts +2 -1
- package/dist/core/tool-policy.d.ts +27 -0
- package/dist/core/trace.d.ts +5 -4
- package/dist/core/types.d.ts +163 -29
- package/dist/core/untrusted-text.d.ts +5 -4
- package/dist/core/untrusted-text.js +8 -0
- package/dist/core/usage-window-store.d.ts +109 -8
- package/dist/core/usage-window-store.js +79 -12
- package/dist/engine/harness/agent-harness.js +20 -5
- package/dist/engine/harness/types.d.ts +38 -0
- package/dist/engine/loop/agent-loop.js +20 -1
- package/dist/engine/loop/types.d.ts +41 -1
- package/dist/index.d.ts +1 -1
- package/dist/orchestration/run-workflow-tool.d.ts +2 -2
- package/dist/orchestration/workflow-types.d.ts +48 -1
- package/dist/orchestration/workflow-types.js +12 -4
- package/dist/orchestration/workflow.d.ts +14 -3
- package/dist/orchestration/workflow.js +44 -19
- package/dist/prompt-assembly/event-registry.js +2 -0
- package/dist/prompts/default.js +1 -1
- package/dist/server/http.d.ts +1 -1
- package/dist/stores/file/usage-window-store.d.ts +1 -1
- package/dist/stores/file/usage-window-store.js +27 -6
- package/dist/tools/loop-tick.js +1 -1
- package/dist/tools/scheduler-tools.js +9 -1
- package/package.json +1 -1
- package/test/export-surface.snapshot.json +3 -1
|
@@ -73,14 +73,24 @@ export declare const USAGE_WINDOW_REAP_MARGIN_MS: number;
|
|
|
73
73
|
export interface UsageGovernance {
|
|
74
74
|
/** The ledger key this run is governed under — the principal, or the shared global key. */
|
|
75
75
|
readonly key: string;
|
|
76
|
+
/** Does any governed window carry a MONEY ceiling? Read by the run loop's pricing seats: only a
|
|
77
|
+
* cost-governing deployment has to treat an unevaluable price table as unpriced spend. */
|
|
78
|
+
readonly governsCost: boolean;
|
|
76
79
|
/** Ms the caller must wait before ANY window would admit work again, or `undefined` when none is
|
|
77
80
|
* exhausted as of `now`. Reads the ledger; propagates a store failure (an unreadable ceiling must not
|
|
78
81
|
* read as an open one). */
|
|
79
82
|
check(now: number): Promise<number | undefined>;
|
|
80
|
-
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Charge whatever of the run's cumulative spend has not been charged yet. Takes the run's CUMULATIVE
|
|
85
|
+
* totals rather than deltas so no caller can double-charge by calling twice, and so a caller that skips
|
|
86
|
+
* a boundary loses nothing.
|
|
87
|
+
*
|
|
88
|
+
* `cumulativeCostMicroUsd` is the MONEY half (integer micro-USD, `stats.costMicroUsd`). Pass `undefined`
|
|
89
|
+
* when the run's spend has no cost figure at all (RB-368's unpriced state) — a deployment governing a
|
|
90
|
+
* `maxCostUsd` window then REFUSES here rather than charging the fabricated 0 that would let the ceiling
|
|
91
|
+
* silently stop applying. A token-only deployment ignores the argument entirely.
|
|
92
|
+
*/
|
|
93
|
+
commit(cumulativeTokens: number, cumulativeCostMicroUsd: number | undefined, now: number): Promise<void>;
|
|
84
94
|
}
|
|
85
95
|
/**
|
|
86
96
|
* design/164 件四 — resolve the moment an env's lifetime EXPIRES (epoch ms), or `undefined` when the env
|
|
@@ -133,8 +143,53 @@ export declare function checkpointScopeOf(spec: {
|
|
|
133
143
|
principal?: string;
|
|
134
144
|
}): string;
|
|
135
145
|
export { resolveCheckpointStore } from "../checkpoint-store.js";
|
|
136
|
-
export { isFableFamilyModelId, resolveModelPromptTraits, resolveTaskLimits } from "./prepare-config-doors.js";
|
|
146
|
+
export { isFableFamilyModelId, resolveAttachmentsConfig, resolveModelPromptTraits, resolveTaskLimits } from "./prepare-config-doors.js";
|
|
137
147
|
export { rebaseWorkspacePath, rebaseWorkspacePathAcross } from "./prepare-workspace-restore.js";
|
|
148
|
+
/** See {@link runGuardChain}. */
|
|
149
|
+
export interface GuardChainArgs {
|
|
150
|
+
/** The post-frontier view the chain starts from. */
|
|
151
|
+
edited: AgentMessage[];
|
|
152
|
+
/** The pre-cap counterpart view (arm A's clearSource — RB-212 durable composition seat). */
|
|
153
|
+
replayed: AgentMessage[];
|
|
154
|
+
index: OccurrenceIndex;
|
|
155
|
+
microCompact: PreparedMicroCompact;
|
|
156
|
+
guardAt: number;
|
|
157
|
+
charsPerToken: number;
|
|
158
|
+
offloadStore: import("../tool-result-store.js").ToolResultStore | undefined;
|
|
159
|
+
sessionId: string;
|
|
160
|
+
taskId: string;
|
|
161
|
+
deps: RunnerDeps;
|
|
162
|
+
trimPressureRef: {
|
|
163
|
+
droppedMessages: boolean;
|
|
164
|
+
};
|
|
165
|
+
recheck: boolean | undefined;
|
|
166
|
+
signal: AbortSignal | undefined;
|
|
167
|
+
/** The r7 per-request observation buffer — the chain DROPS it on its early returns (a discarded
|
|
168
|
+
* provisional projection must not narrate itself). */
|
|
169
|
+
pendingProjectionObservations: Array<() => void>;
|
|
170
|
+
}
|
|
171
|
+
export type GuardChainOutcome = {
|
|
172
|
+
earlyReturn: {
|
|
173
|
+
messages: AgentMessage[];
|
|
174
|
+
adoptSessionRebuild?: boolean;
|
|
175
|
+
};
|
|
176
|
+
} | {
|
|
177
|
+
working: AgentMessage[];
|
|
178
|
+
trimmed: AgentMessage[];
|
|
179
|
+
trimDroppedMessages: boolean;
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* design/374 slice 3 — the GUARD CHAIN over one request build (D-7 case-ii transfer table),
|
|
183
|
+
* module-level per the design/238 body-span bank. design/123 D3: the chain reads the anchored
|
|
184
|
+
* coordinate re-estimated on the EDITED array (pre-anchor clears don't lower it — deliberately;
|
|
185
|
+
* trimToBudget doc). The opt-out machine = the pre-374 backstop order byte-identical
|
|
186
|
+
* (trim as the ordinary second line); otherwise arm A (blocking machine run, only when the
|
|
187
|
+
* frontier pass is off) → arm B (in-turn forced compaction behind the adopt seam) → arm C (trim,
|
|
188
|
+
* the disaster-only last resort and this chain's sole `context.trim` emitter). Returns either the
|
|
189
|
+
* post-chain view for the pipeline tail, or an EARLY hook result the context handler must return
|
|
190
|
+
* verbatim (arm-B adoption / the r8 dead-turn stand-down).
|
|
191
|
+
*/
|
|
192
|
+
export declare function runGuardChain(args: GuardChainArgs): Promise<GuardChainOutcome>;
|
|
138
193
|
export interface Prepared {
|
|
139
194
|
harness: AgentHarness;
|
|
140
195
|
/** The CONCRETE built-in session (engine-internal: prepare constructs/acquires `StoredSession` itself,
|
|
@@ -876,21 +931,38 @@ export interface Prepared {
|
|
|
876
931
|
trimPressureRef: {
|
|
877
932
|
droppedMessages: boolean;
|
|
878
933
|
};
|
|
879
|
-
/** design/374 slices 1b/2 — the microCompact machine state this run: the selected clearing
|
|
934
|
+
/** design/374 slices 1b/2/3 — the microCompact machine state this run: the selected clearing
|
|
880
935
|
* machine, the cleared-projection ledger (request-view application, durable decisions — see
|
|
881
936
|
* `context-edit.ts`'s ledger note; per-run in-memory, so durable resume / `resumeAt` rebuilds
|
|
882
937
|
* start EMPTY by construction), the last request's projection seat (what the provider actually
|
|
883
938
|
* saw — the MC-R rejection arm computes its candidates and savings on THIS view, never on the
|
|
884
|
-
* raw session rebuild),
|
|
885
|
-
* never gains an entry and every replay is a
|
|
939
|
+
* raw session rebuild), the MC-R knob, and the slice-3 arm-B seat. The explicit opt-out
|
|
940
|
+
* (`machine: "legacy"` + MC-R off) ⇒ the ledger never gains an entry and every replay is a
|
|
941
|
+
* same-reference no-op (opt-out bytes unchanged). */
|
|
886
942
|
microCompact: PreparedMicroCompact;
|
|
887
943
|
}
|
|
888
944
|
/** See {@link Prepared.microCompact}. */
|
|
889
945
|
export interface PreparedMicroCompact {
|
|
890
|
-
machine
|
|
946
|
+
/** The frontier-machine selection — `"off"` = no proactive frontier clearing (the unified
|
|
947
|
+
* machine instead gets its one blocking-point shot, slice-3 arm A). */
|
|
948
|
+
machine: "off" | ContextEditMachine;
|
|
891
949
|
/** MC-R (design/374 §3.2): one-shot clear-and-retry on a provider input-too-long rejection.
|
|
892
|
-
* Default
|
|
950
|
+
* Default true since the slice-3 flip. */
|
|
893
951
|
clearOnRejection: boolean;
|
|
952
|
+
/** design/374 slice 3 (arm B) — the in-turn forced-compaction seat: runtask wires a closure
|
|
953
|
+
* that runs the SAME forced-compaction pass the prompt-too-long recovery uses (gates included)
|
|
954
|
+
* and answers whether a compaction landed in the session. The context hook calls it when the
|
|
955
|
+
* pre-send estimate breaks the guard budget and then returns `adoptSessionRebuild` so the
|
|
956
|
+
* harness adopts the reduced transcript. `signal` is the TURN-scoped abort of the request
|
|
957
|
+
* build (r3): a turn interrupt must be able to cut the summary call short instead of waiting
|
|
958
|
+
* it out. `anchoredEstimate` is the chain's own trigger coordinate — the seat consults the
|
|
959
|
+
* §25.2 anti-thrash floor against it (an ineffective landing must not be repeated per request
|
|
960
|
+
* build; the chain's arm C owns the bounded fallback). Unwired (pure-prepare callers) ⇒ arm B
|
|
961
|
+
* declines and the chain falls to the trim last resort — same posture as a compaction-disabled
|
|
962
|
+
* run. */
|
|
963
|
+
inTurnCompactionRef: {
|
|
964
|
+
current?: (signal?: AbortSignal, anchoredEstimate?: number) => Promise<boolean>;
|
|
965
|
+
};
|
|
894
966
|
ledger: ClearedProjectionLedger;
|
|
895
967
|
projectionRef: {
|
|
896
968
|
current?: {
|
|
@@ -1463,8 +1535,8 @@ export interface RunInternals {
|
|
|
1463
1535
|
* receive a subagent's live `task_progress` ticks (which otherwise stay in the child's ISOLATED stream). Threaded
|
|
1464
1536
|
* recursively down the delegation tree (via `ctx.forwardEvent`), so every nested subagent's ticks bubble to the
|
|
1465
1537
|
* SAME sink. The Runner's ctx wrapper forwards `task_progress` always; when the run's spec sets
|
|
1466
|
-
* `forwardSubagentEvents: true` it ALSO forwards the child's content events (`text_delta` / `
|
|
1467
|
-
* `tool_start` / `tool_end` — the subagent viewing pane, carrying the same UNTRUSTED-RAW/consumer-must-redact
|
|
1538
|
+
* `forwardSubagentEvents: true` it ALSO forwards the child's content events (`text_delta` / `text_end` (#447) /
|
|
1539
|
+
* `reasoning_delta` / `tool_start` / `tool_end` — the subagent viewing pane, carrying the same UNTRUSTED-RAW/consumer-must-redact
|
|
1468
1540
|
* contract as the main stream's tool events). Either way the child stream is NEVER merged into the parent's
|
|
1469
1541
|
* MODEL context (this is purely a render channel). Absent unless the deployment opted in.
|
|
1470
1542
|
*/
|
|
@@ -1629,6 +1701,35 @@ export interface ResolvedWorkspace {
|
|
|
1629
1701
|
* which `cwd` is a host path a consumer may diff / merge / remove. */
|
|
1630
1702
|
remote: boolean;
|
|
1631
1703
|
}
|
|
1704
|
+
/**
|
|
1705
|
+
* RB-330 + 5.38 r2 件2 — the SINGLE effective-delegation derivation for a leg, minted once per prepare
|
|
1706
|
+
* and read by EVERY consumer face; two facets, one source:
|
|
1707
|
+
*
|
|
1708
|
+
* - `isDelegatedChild` — the raw delegation fact, forks included. Trusted internals first; on a
|
|
1709
|
+
* resume leg where the caller supplied NO delegation fact, the checkpoint's persisted axis
|
|
1710
|
+
* ({@link import("../checkpoint-store.js").CheckpointState.isDelegatedChild}) stands in — else a
|
|
1711
|
+
* deps-only `resume(token, outcome, config)` of a parked delegation read `false` at every station:
|
|
1712
|
+
* persona flip (subagent consent/notes pack dropped), ask refusal texts on the parent-thread arm
|
|
1713
|
+
* ("wait for the user" in a transcript no user turn ever lands in), and a lifecycle-observer gate
|
|
1714
|
+
* that never opened. Consumed by `askSourceIdentity` (a fork's refusal posture is the child's) and
|
|
1715
|
+
* the `hookIdentity` mint.
|
|
1716
|
+
* - `isNonForkChild` — the fact minus forks, for the authority/context faces: the `loadProjectMemory`
|
|
1717
|
+
* ctx flag ({@link RunnerDeps.loadProjectMemory} `isSubagent`) and the prompt runtime fact
|
|
1718
|
+
* `isSubagent` (RB-204's `SUBAGENT_CONSENT_NOTICE` gate). A FORK is excluded on both, deliberately:
|
|
1719
|
+
* a fork IS the parent continuing (design/110), so it inherits the parent's authority — and, on the
|
|
1720
|
+
* memory face, the parent's own project context; trimming a fork's CLAUDE.md would hand the
|
|
1721
|
+
* continuation LESS context than the run it continues. (RB-330 history: the memory face once used
|
|
1722
|
+
* `parentTaskId !== undefined` alone, which {@link RunInternals.isDelegatedChild}'s own docstring
|
|
1723
|
+
* forbids — a directly-started workflow's children have no nameable parent.)
|
|
1724
|
+
*
|
|
1725
|
+
* `insideFork` is NOT persisted (the checkpoint's documented honest absence), so on a deps-only resume
|
|
1726
|
+
* a FORK child reads as a plain delegated child on the non-fork facet — the honest residue is written
|
|
1727
|
+
* on the checkpoint field's own list, not papered over with a new persistence axis.
|
|
1728
|
+
*/
|
|
1729
|
+
export declare function effectiveDelegationFacts(internals: Pick<RunInternals, "isDelegatedChild" | "insideFork"> | undefined, seedIsDelegatedChild: boolean | undefined): {
|
|
1730
|
+
isDelegatedChild: boolean;
|
|
1731
|
+
isNonForkChild: boolean;
|
|
1732
|
+
};
|
|
1632
1733
|
/**
|
|
1633
1734
|
* From the resumed/active transcript, the batch position of `currentId` (design/45 §4.ter): the tool-call
|
|
1634
1735
|
* ids of the assistant message that issued it (the batch), and the subset already resolved (executed
|