@sema-agent/core 7.63.0 → 7.65.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 +725 -0
- package/dist/agents/cc-peer-directory.js +1 -0
- package/dist/agents/cc-peer-wire.d.ts +4 -0
- package/dist/agents/cc-peer-wire.js +1 -0
- package/dist/agents/cc-uds-peer-channel.js +5 -0
- package/dist/agents/cross-session-judge.d.ts +3 -1
- package/dist/agents/cross-session-judge.js +4 -1
- package/dist/agents/peer-directory.d.ts +8 -0
- package/dist/agents/peer-directory.js +4 -0
- package/dist/agents/peer-held-queue.d.ts +9 -3
- package/dist/agents/peer-held-queue.js +12 -9
- package/dist/agents/peer-idle.d.ts +20 -1
- package/dist/agents/peer-idle.js +23 -12
- package/dist/agents/peer-notice-route.d.ts +16 -5
- package/dist/agents/peer-notice-route.js +11 -9
- package/dist/agents/peer-notices.d.ts +25 -8
- package/dist/agents/peer-notices.js +6 -1
- package/dist/agents/peer-session-drain.d.ts +32 -6
- package/dist/agents/peer-session-drain.js +100 -26
- package/dist/agents/send-message-tool.d.ts +7 -0
- package/dist/agents/send-message-tool.js +18 -6
- package/dist/agents/subagent.js +25 -5
- package/dist/core/allow-entry.d.ts +4 -0
- package/dist/core/ask-origin.d.ts +1 -1
- package/dist/core/ask-origin.js +2 -2
- package/dist/core/ask-unresolvable-notice.d.ts +13 -4
- package/dist/core/ask-unresolvable-notice.js +10 -3
- package/dist/core/auto-compaction.d.ts +7 -5
- package/dist/core/auto-promote.d.ts +3 -2
- package/dist/core/background-agent-store.d.ts +14 -0
- package/dist/core/background-agent-store.js +3 -0
- package/dist/core/checkpoint-queries.d.ts +9 -6
- package/dist/core/checkpoint-queries.js +8 -3
- package/dist/core/checkpoint-store.d.ts +7 -4
- package/dist/core/context-settings.d.ts +39 -9
- package/dist/core/context-settings.js +32 -10
- package/dist/core/engine-attestation.d.ts +26 -6
- package/dist/core/engine-attestation.js +5 -1
- package/dist/core/engine-notice.d.ts +37 -2
- package/dist/core/engine-notice.js +3 -1
- package/dist/core/extension-requester.d.ts +9 -0
- package/dist/core/extension-requester.js +7 -0
- package/dist/core/file-history-store.d.ts +30 -2
- package/dist/core/file-history-store.js +48 -9
- package/dist/core/fs-write-gate-policy.js +1 -1
- package/dist/core/gate-fold.js +5 -1
- package/dist/core/gate-lanes.js +2 -0
- package/dist/core/gate-outcome.d.ts +39 -2
- package/dist/core/gate-outcome.js +20 -1
- package/dist/core/governance-codes.d.ts +8 -4
- package/dist/core/governance-codes.js +8 -3
- package/dist/core/leg-identity.d.ts +35 -1
- package/dist/core/leg-identity.js +10 -0
- package/dist/core/mailbox-store.d.ts +39 -4
- package/dist/core/mailbox-store.js +14 -2
- package/dist/core/memory-engine/consolidation.d.ts +13 -6
- package/dist/core/memory-engine/consolidation.js +26 -0
- package/dist/core/memory-engine/control-objects.d.ts +58 -0
- package/dist/core/memory-engine/control-objects.js +273 -0
- package/dist/core/memory-engine/control-plane-adoption.d.ts +51 -0
- package/dist/core/memory-engine/control-plane-adoption.js +161 -0
- package/dist/core/memory-engine/delegation-settlement.d.ts +73 -40
- package/dist/core/memory-engine/delegation-settlement.js +271 -107
- package/dist/core/memory-engine/dual-root.d.ts +3 -2
- package/dist/core/memory-engine/dual-root.js +7 -3
- package/dist/core/memory-engine/engine.d.ts +54 -33
- package/dist/core/memory-engine/engine.js +150 -157
- package/dist/core/memory-engine/file-backend.d.ts +58 -76
- package/dist/core/memory-engine/file-backend.js +111 -268
- package/dist/core/memory-engine/index.d.ts +3 -2
- package/dist/core/memory-engine/index.js +2 -1
- package/dist/core/memory-engine/layout.d.ts +135 -50
- package/dist/core/memory-engine/layout.js +214 -89
- package/dist/core/memory-engine/memory-age.d.ts +12 -0
- package/dist/core/memory-engine/memory-age.js +17 -0
- package/dist/core/memory-engine/memory-backend-contract.d.ts +10 -3
- package/dist/core/memory-engine/memory-backend-contract.js +159 -2
- package/dist/core/memory-engine/memory-deployment.d.ts +12 -4
- package/dist/core/memory-engine/memory-deployment.js +31 -6
- package/dist/core/memory-engine/origin-clearance.d.ts +12 -3
- package/dist/core/memory-engine/origin-clearance.js +64 -9
- package/dist/core/memory-engine/session-write-home.d.ts +34 -1
- package/dist/core/memory-engine/session-write-home.js +37 -10
- package/dist/core/memory-engine/tools.d.ts +2 -2
- package/dist/core/memory-engine/tools.js +7 -7
- package/dist/core/memory-engine/types.d.ts +55 -12
- package/dist/core/memory-engine/types.js +2 -1
- package/dist/core/memory-vector.d.ts +6 -14
- package/dist/core/memory.d.ts +0 -462
- package/dist/core/memory.js +0 -333
- package/dist/core/mode-policy.js +3 -3
- package/dist/core/mods/agent-stations.d.ts +18 -0
- package/dist/core/mods/agent-stations.js +8 -6
- package/dist/core/mods/extension-call.d.ts +4 -0
- package/dist/core/mods/extension-call.js +8 -0
- package/dist/core/mods/tool-call.js +3 -4
- package/dist/core/parent-spec-seat.d.ts +2 -2
- package/dist/core/peer-channel.d.ts +5 -0
- package/dist/core/permission-rule-consent.d.ts +64 -22
- package/dist/core/permission-rule-consent.js +106 -58
- package/dist/core/permission-rule-store.d.ts +56 -21
- package/dist/core/permission-rule-store.js +2 -0
- package/dist/core/refusal-echo.d.ts +20 -0
- package/dist/core/refusal-echo.js +33 -0
- package/dist/core/retention.d.ts +175 -10
- package/dist/core/retention.js +44 -0
- package/dist/core/retired-keys.d.ts +5 -0
- package/dist/core/retired-keys.js +3 -0
- package/dist/core/rule-offer-read.d.ts +0 -4
- package/dist/core/rule-offer-read.js +2 -18
- package/dist/core/runner/classifier-ladder.d.ts +10 -2
- package/dist/core/runner/classifier-ladder.js +4 -2
- package/dist/core/runner/compact-session.js +10 -7
- package/dist/core/runner/compaction-call-options.d.ts +7 -7
- package/dist/core/runner/compaction-call-options.js +3 -2
- package/dist/core/runner/contracts.d.ts +28 -9
- package/dist/core/runner/delegation-owner.d.ts +2 -3
- package/dist/core/runner/delegation-owner.js +2 -1
- package/dist/core/runner/gate-exit.d.ts +6 -0
- package/dist/core/runner/gate-exit.js +11 -2
- package/dist/core/runner/memory-consolidation-driver.d.ts +4 -2
- package/dist/core/runner/memory-consolidation-driver.js +8 -5
- package/dist/core/runner/prepare-ask-lane.js +3 -3
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +3 -1
- package/dist/core/runner/prepare-caps-and-workflow.js +2 -2
- package/dist/core/runner/prepare-config-doors.js +4 -0
- package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
- package/dist/core/runner/prepare-delegation-surface.js +2 -2
- package/dist/core/runner/prepare-gate-stations.d.ts +8 -0
- package/dist/core/runner/prepare-gate-stations.js +15 -7
- package/dist/core/runner/prepare-hands-readface.js +1 -1
- package/dist/core/runner/prepare-inherited-gate.d.ts +3 -1
- package/dist/core/runner/prepare-inherited-gate.js +4 -2
- package/dist/core/runner/prepare-memory-engine-session.js +1 -1
- package/dist/core/runner/prepare-memory.d.ts +4 -0
- package/dist/core/runner/prepare-memory.js +22 -28
- package/dist/core/runner/prepare-policy-chain.js +18 -10
- package/dist/core/runner/prepare-prompt-inputs.js +1 -1
- package/dist/core/runner/prepare-task.d.ts +5 -1
- package/dist/core/runner/prepare-task.js +16 -11
- package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -1
- package/dist/core/runner/prepare-wiring-manifest.js +3 -2
- package/dist/core/runner/resume-admission.d.ts +2 -2
- package/dist/core/runner/resume-admission.js +2 -23
- package/dist/core/runner/role-resolution-table.d.ts +98 -0
- package/dist/core/runner/role-resolution-table.js +62 -0
- package/dist/core/runner/run-compaction-machinery.js +2 -2
- package/dist/core/runner/run-identity-wiring.js +12 -9
- package/dist/core/runner/run-leg.js +8 -4
- package/dist/core/runner/run-notification-lane.js +23 -23
- package/dist/core/runner/run-recovery-lanes.js +3 -3
- package/dist/core/runner/run-terminal-adoption.js +1 -1
- package/dist/core/runner/run-turn-boundary.js +14 -15
- package/dist/core/runner/runtask.js +1 -1
- package/dist/core/runner/sub-agent-deny-lists.d.ts +19 -0
- package/dist/core/runner/sub-agent-deny-lists.js +25 -0
- package/dist/core/runner/tool-occurrence.d.ts +4 -2
- package/dist/core/runner/tool-occurrence.js +2 -2
- package/dist/core/runner-deps.d.ts +1 -1
- package/dist/core/secret-env.d.ts +2 -2
- package/dist/core/secret-env.js +6 -20
- package/dist/core/session-checkout.d.ts +63 -3
- package/dist/core/session-checkout.js +152 -58
- package/dist/core/session-store.d.ts +6 -6
- package/dist/core/session-store.js +3 -3
- package/dist/core/shell-read-silence.js +8 -0
- package/dist/core/store-contracts/background-agent-store-contract.js +13 -0
- package/dist/core/store-contracts/peer-directory-contract.js +8 -1
- package/dist/core/task-event.d.ts +9 -5
- package/dist/core/task-notification.d.ts +137 -31
- package/dist/core/task-notification.js +198 -100
- package/dist/core/task-registry-agent.d.ts +11 -0
- package/dist/core/task-registry-agent.js +12 -3
- package/dist/core/task-registry-shared.d.ts +11 -0
- package/dist/core/task-registry.d.ts +18 -0
- package/dist/core/task-registry.js +27 -8
- package/dist/core/task-spec.d.ts +7 -2
- package/dist/core/tool-errors.d.ts +17 -9
- package/dist/core/tool-errors.js +1 -1
- package/dist/core/tool-policy.d.ts +18 -1
- package/dist/core/tool-policy.js +16 -7
- package/dist/core/tool-result-store.d.ts +20 -0
- package/dist/core/tool-spec.d.ts +10 -6
- package/dist/core/trace.d.ts +3 -2
- package/dist/core/workflow-journal-store.d.ts +11 -0
- package/dist/core/workflow-journal-store.js +7 -0
- package/dist/core/workflow-run-store.d.ts +9 -0
- package/dist/core/workflow-run-store.js +6 -0
- package/dist/core/write-protect.d.ts +16 -0
- package/dist/core/write-protect.js +10 -0
- package/dist/engine/compaction/compaction.d.ts +2 -1
- package/dist/engine/harness/types.d.ts +1 -0
- package/dist/engine/session/repo-utils.d.ts +14 -4
- package/dist/engine/session/repo-utils.js +5 -4
- package/dist/engine/session/session.d.ts +7 -1
- package/dist/engine/session/session.js +5 -2
- package/dist/index.d.ts +13 -11
- package/dist/index.js +13 -11
- package/dist/orchestration/run-workflow-tool.d.ts +4 -0
- package/dist/orchestration/run-workflow-tool.js +7 -0
- package/dist/orchestration/workflow-types.d.ts +2 -1
- package/dist/orchestration/workflow.d.ts +3 -0
- package/dist/orchestration/workflow.js +2 -1
- package/dist/prompts/default.d.ts +1 -2
- package/dist/scenarios/full-body.d.ts +1 -1
- package/dist/stores/file/adoption/adopt.d.ts +1 -1
- package/dist/stores/file/checkpoint-store.d.ts +6 -0
- package/dist/stores/file/checkpoint-store.js +4 -1
- package/dist/stores/file/file-history-store.d.ts +13 -0
- package/dist/stores/file/file-history-store.js +75 -13
- package/dist/stores/file/index.d.ts +12 -16
- package/dist/stores/file/index.js +7 -25
- package/dist/stores/file/permission-rule-store.d.ts +34 -0
- package/dist/stores/file/permission-rule-store.js +104 -9
- package/dist/stores/file/session-store.js +1 -1
- package/dist/stores/file/tool-result-store.d.ts +14 -0
- package/dist/stores/file/tool-result-store.js +39 -2
- package/dist/stores/file/workflow-journal-store.d.ts +4 -0
- package/dist/stores/file/workflow-journal-store.js +17 -0
- package/dist/stores/file/workflow-run-store.d.ts +3 -0
- package/dist/stores/file/workflow-run-store.js +15 -0
- package/dist/tools/fs/read-deny.d.ts +15 -2
- package/dist/tools/fs/read-deny.js +10 -2
- package/dist/tools/fs/shell-read-check.d.ts +8 -2
- package/dist/tools/fs/shell-read-check.js +7 -7
- package/package.json +2 -2
- package/test/export-surface.snapshot.json +71 -73
- package/wire-changes/core-stores-sql@7.64.0.json +30 -0
- package/wire-changes/core-stores-sql@7.65.0.json +30 -0
- package/wire-changes/core@7.64.0.json +2653 -0
- package/wire-changes/core@7.65.0.json +1650 -0
- package/wire-changes/mods-kernel@7.64.0.json +30 -0
- package/wire-changes/mods-kernel@7.65.0.json +30 -0
- package/wire-changes/primitives@7.64.0.json +30 -0
- package/wire-changes/primitives@7.65.0.json +337 -0
- package/dist/core/memory-recall.d.ts +0 -208
- package/dist/core/memory-recall.js +0 -136
- package/dist/stores/file/memory-store.d.ts +0 -124
- package/dist/stores/file/memory-store.js +0 -353
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which model roles the engine resolves ITSELF at a task's prepare, where, and whether a role that supplies nothing
|
|
3
|
+
* refuses — one table — and the one question a host asks of it: "will this model face (`{ models, tiers, roles }`, what a
|
|
4
|
+
* host hands `new Runner`) make a task's prepare refuse on a role?".
|
|
5
|
+
*
|
|
6
|
+
* Each row is a role the engine reads itself at a hop that can refuse; the hop is the engine's own function, the very
|
|
7
|
+
* one prepare calls — the question below calls it too, so the answer cannot drift from what a task meets, and no
|
|
8
|
+
* judgment is written twice. A hop is not a copy: `resolveTaskModel` (`roles.ts`: the task's own model),
|
|
9
|
+
* `resolveCompactionModel` (`prepare-config-doors.ts`: the `summarize` role; `Runner.compactSession` calls it too) and
|
|
10
|
+
* `assertAutoConsolidationWirable` (`memory-consolidation-driver.ts`: the consolidation arming door) — all three are called
|
|
11
|
+
* from `prepare-config-doors.ts`, and the rows stand in the order prepare reaches them.
|
|
12
|
+
*
|
|
13
|
+
* `when` says WHAT the hop reads. `per-task`: the face AND the task's own spec (`model`, `modelRole`, `compactionModel`,
|
|
14
|
+
* `roles`) — a task that names its model never walks the `default` chain, one that names its compaction model never reads
|
|
15
|
+
* `summarize`. `deployment`: the face alone — the deployment's own question, asked of every prepare (the deps door) and of
|
|
16
|
+
* a host-run consolidation, and only a refusal when auto-consolidation is armed (`autoRunOnRecommendation: true`); an
|
|
17
|
+
* explicit `memoryConsolidationDriver.chat` seat is no part of a face, so a deployment that names one holds a seat the
|
|
18
|
+
* question does not see. Nothing resolves a role at `new Runner` (it receives the catalog and the tier bindings, which are no
|
|
19
|
+
* roles): the first refusal on a role comes at the first prepare.
|
|
20
|
+
*
|
|
21
|
+
* `absence` says what a row does when its role supplies NO model at all: `throws` — the hop refuses; `falls-back` — the
|
|
22
|
+
* hop answers "none" and the caller carries on (the compaction pass rides the task's own model).
|
|
23
|
+
*
|
|
24
|
+
* Not rows, on purpose: the auto-mode classifier seat (`classifierSeatModel`) and the next-prompt suggestion pass resolve
|
|
25
|
+
* a role and take the main model when it supplies none — neither refuses; the `subagent` / `verifier` seats resolve when a
|
|
26
|
+
* child is spawned, not at the parent's prepare; `sideQuery` and `Runner.compactSession` resolve at the caller's call, on a
|
|
27
|
+
* model the caller names. A role resolution site that refuses at prepare and is not a row here is a missing row.
|
|
28
|
+
*/
|
|
29
|
+
import type { Model } from "../../internal/llm.js";
|
|
30
|
+
import type { ModelRef, ModelRole, ModelRoles, TaskSpec } from "../types.js";
|
|
31
|
+
/** When a row's hop reads its role — see the module note. */
|
|
32
|
+
export type RoleResolutionWhen = "per-task" | "deployment";
|
|
33
|
+
/** What a row does when its role supplies no model — see the module note. */
|
|
34
|
+
export type RoleResolutionAbsence = "throws" | "falls-back";
|
|
35
|
+
/** One row: the role, when it is read, the hop that reads it (`file :: function`), and what its absence does. */
|
|
36
|
+
export interface RoleResolutionRow {
|
|
37
|
+
readonly role: ModelRole;
|
|
38
|
+
readonly when: RoleResolutionWhen;
|
|
39
|
+
readonly hop: string;
|
|
40
|
+
readonly absence: RoleResolutionAbsence;
|
|
41
|
+
}
|
|
42
|
+
/** The roles the engine resolves itself at prepare — read-only; the table the question below walks, in the order prepare reaches them. */
|
|
43
|
+
export declare const ROLE_RESOLUTION_TABLE: readonly [Readonly<{
|
|
44
|
+
role: "consolidate";
|
|
45
|
+
when: "deployment";
|
|
46
|
+
hop: "src/core/runner/memory-consolidation-driver.ts :: assertAutoConsolidationWirable";
|
|
47
|
+
absence: "throws";
|
|
48
|
+
}>, Readonly<{
|
|
49
|
+
role: "default";
|
|
50
|
+
when: "per-task";
|
|
51
|
+
hop: "src/core/roles.ts :: resolveTaskModel";
|
|
52
|
+
absence: "throws";
|
|
53
|
+
}>, Readonly<{
|
|
54
|
+
role: "summarize";
|
|
55
|
+
when: "per-task";
|
|
56
|
+
hop: "src/core/runner/prepare-config-doors.ts :: resolveCompactionModel";
|
|
57
|
+
absence: "falls-back";
|
|
58
|
+
}>];
|
|
59
|
+
/** The model face the question is asked of — the three members a host hands `new Runner` for models: the catalog, the tier bindings over it, and the role map. The question applies the Runner's own catalog door to them (do not pre-expand the tiers). */
|
|
60
|
+
export interface ModelFace {
|
|
61
|
+
models?: Record<string, Model>;
|
|
62
|
+
tiers?: Record<string, ModelRef>;
|
|
63
|
+
roles?: ModelRoles;
|
|
64
|
+
}
|
|
65
|
+
/** The task a per-task row is asked about: the members of a `TaskSpec` those hops read. Omitted ⇒ a task that names none of them. */
|
|
66
|
+
export type ModelFaceTask = Pick<TaskSpec, "model" | "modelRole" | "roles" | "compactionModel">;
|
|
67
|
+
export interface ModelFaceOptions {
|
|
68
|
+
/** The task the per-task rows are asked about (default: a task naming no model, no role, no compaction model). */
|
|
69
|
+
spec?: ModelFaceTask;
|
|
70
|
+
/** Which rows to ask (default `["per-task"]`; add `"deployment"` to ask the consolidation seat as armed). */
|
|
71
|
+
when?: readonly RoleResolutionWhen[];
|
|
72
|
+
}
|
|
73
|
+
/** The answer: `ok: true`, or the first row whose hop refuses — its role and the code of the refusal the hop itself throws. */
|
|
74
|
+
export type ModelFaceVerdict = {
|
|
75
|
+
ok: true;
|
|
76
|
+
} | {
|
|
77
|
+
ok: false;
|
|
78
|
+
role: (typeof ROLE_RESOLUTION_TABLE)[number]["role"];
|
|
79
|
+
code: string;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Will a task's prepare refuse on a role resolution, over this model face? Walks the rows of {@link ROLE_RESOLUTION_TABLE}
|
|
83
|
+
* the options select, in table order (the order prepare reaches them), and asks each row's own hop; the first that throws is
|
|
84
|
+
* the answer — `{ ok: false, role, code }`, the `code` the hop's refusal carries (nothing is minted here). `{ ok: true }` ⇔
|
|
85
|
+
* none refuses.
|
|
86
|
+
*
|
|
87
|
+
* Pure: reads the face and the spec, writes nothing; each member is read once, as prepare takes a task's members once, and
|
|
88
|
+
* the catalog and the role maps are received once before any hop reads them (a role map that is no map refuses before any
|
|
89
|
+
* role is read, and the first row asked carries that refusal). A face whose catalog `new Runner` would not accept is refused
|
|
90
|
+
* as `new Runner` refuses it — thrown, not a verdict. A role that supplies no model is a refusal only where the row's
|
|
91
|
+
* `absence` says `throws`; a `summarize` seat that is unset, or names a word the catalog does not hold, is `ok: true` (the
|
|
92
|
+
* compaction pass rides the task's model). A throw that carries no code is not a verdict and is rethrown.
|
|
93
|
+
*
|
|
94
|
+
* Whether a task's prepare refuses on a role over a given face is answered here and nowhere else: a host that derives it from
|
|
95
|
+
* its own copy of the role walk (for example by handing the engine a role map cut down to one key) answers a different
|
|
96
|
+
* question the day the walk moves.
|
|
97
|
+
*/
|
|
98
|
+
export declare function modelFaceResolvable(face: ModelFace, options?: ModelFaceOptions): ModelFaceVerdict;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { bindingShown, receiveModelCatalog, resolveTaskModel, screenRoleMap } from "../roles.js";
|
|
2
|
+
import { assertAutoConsolidationWirable } from "./memory-consolidation-driver.js";
|
|
3
|
+
import { resolveCompactionModel } from "./prepare-config-doors.js";
|
|
4
|
+
export const ROLE_RESOLUTION_TABLE = Object.freeze([
|
|
5
|
+
Object.freeze({ role: "consolidate", when: "deployment", hop: "src/core/runner/memory-consolidation-driver.ts :: assertAutoConsolidationWirable", absence: "throws" }),
|
|
6
|
+
Object.freeze({ role: "default", when: "per-task", hop: "src/core/roles.ts :: resolveTaskModel", absence: "throws" }),
|
|
7
|
+
Object.freeze({ role: "summarize", when: "per-task", hop: "src/core/runner/prepare-config-doors.ts :: resolveCompactionModel", absence: "falls-back" }),
|
|
8
|
+
]);
|
|
9
|
+
const HOPS = {
|
|
10
|
+
consolidate: (_task, deps) => assertAutoConsolidationWirable({ ...deps, memoryConsolidation: {}, autoRunOnRecommendation: true }),
|
|
11
|
+
default: (task, deps) => void resolveTaskModel(task, deps),
|
|
12
|
+
summarize: (task, deps) => void resolveCompactionModel(task, deps, "TaskSpec.compactionModel"),
|
|
13
|
+
};
|
|
14
|
+
const WHEN_WORDS = ["per-task", "deployment"];
|
|
15
|
+
function argumentRefusal(message) {
|
|
16
|
+
const e = new Error(message);
|
|
17
|
+
e.code = "config.invalid_argument";
|
|
18
|
+
return e;
|
|
19
|
+
}
|
|
20
|
+
function refusalCode(thrown) {
|
|
21
|
+
const code = thrown !== null && typeof thrown === "object" ? thrown.code : undefined;
|
|
22
|
+
return typeof code === "string" ? code : undefined;
|
|
23
|
+
}
|
|
24
|
+
function kindOf(value) {
|
|
25
|
+
return value === null ? "null" : Array.isArray(value) ? "a list" : typeof value;
|
|
26
|
+
}
|
|
27
|
+
export function modelFaceResolvable(face, options = {}) {
|
|
28
|
+
if (typeof face !== "object" || face === null || Array.isArray(face))
|
|
29
|
+
throw argumentRefusal(`modelFaceResolvable: the face must be an object { models?, tiers?, roles? } (got ${kindOf(face)}).`);
|
|
30
|
+
if (typeof options !== "object" || options === null)
|
|
31
|
+
throw argumentRefusal(`modelFaceResolvable: the options must be an object { spec?, when? } when present (got ${kindOf(options)}).`);
|
|
32
|
+
const when = options.when ?? ["per-task"];
|
|
33
|
+
if (!Array.isArray(when))
|
|
34
|
+
throw argumentRefusal(`modelFaceResolvable: options.when must be a list of row groups (${WHEN_WORDS.join(" / ")}) when present (got ${kindOf(when)}).`);
|
|
35
|
+
for (const word of when) {
|
|
36
|
+
if (!WHEN_WORDS.includes(word))
|
|
37
|
+
throw argumentRefusal(`modelFaceResolvable: options.when holds ${bindingShown(word)}, which is no row group of the role resolution table (${WHEN_WORDS.join(" / ")}).`);
|
|
38
|
+
}
|
|
39
|
+
const given = options.spec ?? {};
|
|
40
|
+
if (typeof given !== "object" || given === null || Array.isArray(given))
|
|
41
|
+
throw argumentRefusal(`modelFaceResolvable: options.spec must be a task { model?, modelRole?, roles?, compactionModel? } when present (got ${kindOf(given)}).`);
|
|
42
|
+
const { models: heldModels, tiers, roles: deploymentRoles } = face;
|
|
43
|
+
const models = heldModels !== undefined || tiers !== undefined ? receiveModelCatalog(heldModels, tiers, "RunnerDeps").models : undefined;
|
|
44
|
+
const { model, modelRole, roles: taskRoles, compactionModel } = given;
|
|
45
|
+
let read;
|
|
46
|
+
const received = () => (read ??= { deps: { models, roles: screenRoleMap(deploymentRoles, "RunnerDeps.roles") }, task: { model, modelRole, roles: screenRoleMap(taskRoles, "TaskSpec.roles"), compactionModel } });
|
|
47
|
+
for (const row of ROLE_RESOLUTION_TABLE) {
|
|
48
|
+
if (!when.includes(row.when))
|
|
49
|
+
continue;
|
|
50
|
+
try {
|
|
51
|
+
const { deps, task } = received();
|
|
52
|
+
HOPS[row.role](task, deps);
|
|
53
|
+
}
|
|
54
|
+
catch (thrown) {
|
|
55
|
+
const code = refusalCode(thrown);
|
|
56
|
+
if (code === undefined)
|
|
57
|
+
throw thrown;
|
|
58
|
+
return { ok: false, role: row.role, code };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return { ok: true };
|
|
62
|
+
}
|
|
@@ -11,9 +11,9 @@ export function runCompactionMachinery(input) {
|
|
|
11
11
|
prepared.sideCallBookRef.book = bookSideCall;
|
|
12
12
|
const compactionBrain = derivedLegBrain(() => runner.deps.brain, "compaction", bookSideCall);
|
|
13
13
|
const legOverlay = () => contextOverlayFor(runner.deps.contextSettings, prepared.harness.getModelRef(), runner.deps);
|
|
14
|
-
const withinTaskCompaction = () => compactionEnabled(spec.compaction
|
|
14
|
+
const withinTaskCompaction = () => compactionEnabled("autoCompact", spec.compaction, legOverlay()) && (spec.compaction?.withinTask ?? true);
|
|
15
15
|
const compactionBreaker = { failures: 0 };
|
|
16
|
-
if (compactionEnabled(spec.compaction
|
|
16
|
+
if (compactionEnabled("autoCompact", spec.compaction, legOverlay())) {
|
|
17
17
|
const prefixWindow = resolveTriggerWindow(prepared.model, legOverlay()).window;
|
|
18
18
|
if (Number.isFinite(prefixWindow) && prefixWindow > 0) {
|
|
19
19
|
const prefixSettings = sanitizeCompactionSettings({ ...DEFAULT_COMPACTION_SETTINGS, ...spec.compaction }, prefixWindow);
|
|
@@ -4,7 +4,7 @@ import { forwardSafely } from "./forward-sink.js";
|
|
|
4
4
|
import { emitsChildRowFrames, taskStartedFrame } from "../delegation-frames.js";
|
|
5
5
|
import { recordFrameReceipt, toolResultReceiptKey } from "../frame-settlement.js";
|
|
6
6
|
import { createReceivingChain } from "../mods/session-receive.js";
|
|
7
|
-
import { discloseDroppedPending, renderTaskNotificationXml, taskNotificationDedupKey } from "../task-notification.js";
|
|
7
|
+
import { discloseDroppedPending, renderTaskNotificationXml, sessionAddressOf, taskNotificationDedupKey } from "../task-notification.js";
|
|
8
8
|
import { buildAppliedHumanInputEvent } from "../human-input-projection.js";
|
|
9
9
|
import { announceAcceptance, nextHumanInputSeq } from "./steer-admission.js";
|
|
10
10
|
import { deliverDelegationLifecycle, deliverEngineNotice, parentLegIds, parkedInputIdsOf, undrainedUserInputNotices } from "../types.js";
|
|
@@ -13,7 +13,7 @@ import { mintCallerStopGate } from "./caller-stop-gate.js";
|
|
|
13
13
|
export function runIdentityWiring(input) {
|
|
14
14
|
const { spec, queue, prepared, internals, taskIdRef, onReady, manualCompactRef, notifyRef, captureOptOutRef, mcpRedialRef, injectTaskNotification, deliveredAtTurnOpen, peerInboundChainRef, notificationLane, pendingSessionNotifications, runner } = input;
|
|
15
15
|
notificationLane.harness = prepared.harness;
|
|
16
|
-
notificationLane.
|
|
16
|
+
notificationLane.address = sessionAddressOf(prepared);
|
|
17
17
|
if (taskIdRef)
|
|
18
18
|
taskIdRef.effectiveMemoryScopes = prepared.effectiveMemoryScopes;
|
|
19
19
|
if (taskIdRef)
|
|
@@ -54,13 +54,14 @@ export function runIdentityWiring(input) {
|
|
|
54
54
|
queue.push({ type: "compaction_outcome", outcome: "mooted", trigger: "manual", reason, ...ident() });
|
|
55
55
|
};
|
|
56
56
|
prepared.harness.onUndrainedEngineNotes = (payloads) => {
|
|
57
|
-
|
|
57
|
+
const address = notificationLane.address;
|
|
58
|
+
if (address === undefined)
|
|
58
59
|
return;
|
|
59
60
|
const boxBacked = prepared.frameSettlement.boxBacked;
|
|
60
61
|
for (const p of payloads) {
|
|
61
62
|
if (boxBacked !== undefined && boxBacked(p))
|
|
62
63
|
continue;
|
|
63
|
-
pendingSessionNotifications.pend(
|
|
64
|
+
pendingSessionNotifications.pend(address, p);
|
|
64
65
|
}
|
|
65
66
|
};
|
|
66
67
|
prepared.harness.engineInjectionsHeld = () => prepared.batchHaltRef.current !== undefined;
|
|
@@ -83,8 +84,9 @@ export function runIdentityWiring(input) {
|
|
|
83
84
|
const peer = payload?.peer;
|
|
84
85
|
if (peer !== undefined && Array.isArray(peer.hopChain))
|
|
85
86
|
peerInboundChainRef.current = [...peer.hopChain];
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
const address = notificationLane.address;
|
|
88
|
+
if (address !== undefined && typeof payload?.task_id === "string" && typeof payload.status === "string")
|
|
89
|
+
pendingSessionNotifications.markDelivered(address, taskNotificationDedupKey(payload));
|
|
88
90
|
};
|
|
89
91
|
prepared.harness.onUserInputConsumed = (record) => {
|
|
90
92
|
const steer = record;
|
|
@@ -121,7 +123,8 @@ export function runIdentityWiring(input) {
|
|
|
121
123
|
}
|
|
122
124
|
{
|
|
123
125
|
const receiving = createReceivingChain(() => prepared.receiveSeat);
|
|
124
|
-
const
|
|
126
|
+
const ownAddress = sessionAddressOf(prepared);
|
|
127
|
+
const pendingIdle = pendingSessionNotifications.drain(ownAddress);
|
|
125
128
|
if (pendingIdle !== undefined) {
|
|
126
129
|
for (const payload of discloseDroppedPending(pendingIdle, prepared.taskReadHandleOf, () => prepared.listBackgroundTasks({ settled: true }))) {
|
|
127
130
|
const parkedPriority = pendingIdle.priorities?.get(payload);
|
|
@@ -129,10 +132,10 @@ export function runIdentityWiring(input) {
|
|
|
129
132
|
queue.push({ type: "task_notification", notification: payload, ...(parkedPriority !== undefined ? { priority: parkedPriority } : {}), ...ident() });
|
|
130
133
|
const handOver = (shown) => {
|
|
131
134
|
void prepared.harness.nextTurn(renderTaskNotificationXml(shown), { provenance: "engine-note", enginePayload: payload }).catch(() => {
|
|
132
|
-
pendingSessionNotifications.pend(
|
|
135
|
+
pendingSessionNotifications.pend(ownAddress, payload, parkedPriority);
|
|
133
136
|
});
|
|
134
137
|
};
|
|
135
|
-
receiving.pass(payload, { handOver, fault: () => pendingSessionNotifications.pend(
|
|
138
|
+
receiving.pass(payload, { handOver, fault: () => pendingSessionNotifications.pend(ownAddress, payload, parkedPriority) });
|
|
136
139
|
}
|
|
137
140
|
}
|
|
138
141
|
if (receiving.settled !== undefined)
|
|
@@ -175,6 +175,8 @@ export async function runLeg(input) {
|
|
|
175
175
|
const unavailableResume = owedMcpUnavailable(prepared, rs.attach.attachmentsCfg);
|
|
176
176
|
if (unavailableResume !== undefined)
|
|
177
177
|
continuation += "\n\n" + mintSystemReminder(sanitizeUntrustedText(unavailableResume.body, attachmentEnvelopeTags("mcp_unavailable")), prepared.reminderMark);
|
|
178
|
+
if (prepared.memoryNoticesFrame !== undefined)
|
|
179
|
+
continuation += "\n\n" + prepared.memoryNoticesFrame;
|
|
178
180
|
const advisorResumeFrame = advisorFrameText(prepared);
|
|
179
181
|
if (advisorResumeFrame !== undefined)
|
|
180
182
|
continuation += "\n\n" + advisorResumeFrame;
|
|
@@ -431,6 +433,8 @@ export async function runLeg(input) {
|
|
|
431
433
|
}
|
|
432
434
|
if (prepared.outputStyleFrame !== undefined)
|
|
433
435
|
firstFrames.push({ source: "output_style", body: prepared.outputStyleFrame, commit: () => undefined, disclose: () => undefined });
|
|
436
|
+
if (prepared.memoryNoticesFrame !== undefined)
|
|
437
|
+
effectiveObjective = `${prepared.memoryNoticesFrame}\n${effectiveObjective}`;
|
|
434
438
|
if (firstFrames.length > 0) {
|
|
435
439
|
effectiveObjective = `${firstFrames.map((f) => mintSystemReminder(sanitizeUntrustedText(f.body, attachmentEnvelopeTags(f.source)), prepared.reminderMark)).join("\n")}\n${effectiveObjective}`;
|
|
436
440
|
}
|
|
@@ -643,9 +647,9 @@ async function resolvePendingCall(runner, prepared, resume, emit, emitCommitted,
|
|
|
643
647
|
occurrences.gateRound(pendingAction.toolCallId, decidedGate, frozenInputSnapshot(resolvedArgs));
|
|
644
648
|
let notExecuted = false;
|
|
645
649
|
const resultRow = (text, isError) => withRowNotExecuted(toolResultMsg(pendingAction.toolCallId, pendingAction.toolName, text, isError), notExecuted);
|
|
646
|
-
const settleEnd = async (isError, result, refusedBy, neverRan,
|
|
650
|
+
const settleEnd = async (isError, result, refusedBy, neverRan, facts) => {
|
|
647
651
|
if (refusedBy !== undefined)
|
|
648
|
-
occurrences.refuse(pendingAction.toolCallId, refusedBy,
|
|
652
|
+
occurrences.refuse(pendingAction.toolCallId, refusedBy, facts);
|
|
649
653
|
const settled = emitSettled(occurrences, callStart, { result, isError, ...(neverRan ? { notExecuted: true } : {}) }, { push: emit, structured: prepared.structuredProjector, mediaBudgetBase64Chars: runner.deps.mediaBudgetBase64Chars });
|
|
650
654
|
notExecuted = settled.notExecuted === true;
|
|
651
655
|
const gate = settled.gate ?? decidedGate;
|
|
@@ -691,7 +695,7 @@ async function resolvePendingCall(runner, prepared, resume, emit, emitCommitted,
|
|
|
691
695
|
const screened = await prepared.approvedCallScreen?.({ toolCallId: pendingAction.toolCallId, toolName: pendingAction.toolName, args: structuredClone(resolvedArgs), decidedBy: outcome.hostDecision.decidedBy });
|
|
692
696
|
if (screened !== undefined && "refused" in screened) {
|
|
693
697
|
const hookDenial = formatHookFeedback(screened.refused, prepared.reminderMark);
|
|
694
|
-
await settleEnd(true, { content: hookDenial }, "hook", undefined, screened.extension);
|
|
698
|
+
await settleEnd(true, { content: hookDenial }, "hook", undefined, screened.extension !== undefined ? { extension: screened.extension } : undefined);
|
|
695
699
|
emitCommitted(await appendAdmittedRow(prepared.admitRows, prepared.session, resultRow(hookDenial, true)), "toolResult", pendingAction.toolCallId);
|
|
696
700
|
return;
|
|
697
701
|
}
|
|
@@ -845,7 +849,7 @@ async function resolvePendingCall(runner, prepared, resume, emit, emitCommitted,
|
|
|
845
849
|
const reading = readStationAnswer(verdict, { toolName: pendingAction.toolName, toolCallId: pendingAction.toolCallId });
|
|
846
850
|
if (reading.kind === "refuse" || reading.kind === "silence" || (unseen && reading.kind !== "vouch")) {
|
|
847
851
|
const readDenial = formatHookFeedback(`The approved tool call "${pendingAction.toolName}" was not executed: ${reading.verdict.sentence ?? "the read boundary does not vouch for what it reads on this leg"} This approval is spent — the call has to be re-issued and approved again.`, prepared.reminderMark);
|
|
848
|
-
await settleEnd(true, { content: readDenial, ...(reading.verdict.details !== undefined ? { details: reading.verdict.details } : {}) }, "read_boundary");
|
|
852
|
+
await settleEnd(true, { content: readDenial, ...(reading.verdict.details !== undefined ? { details: reading.verdict.details } : {}) }, "read_boundary", undefined, reading.verdict.echoed !== undefined ? { echoed: reading.verdict.echoed } : undefined);
|
|
849
853
|
const eid = await appendAdmittedRow(prepared.admitRows, prepared.session, resultRow(readDenial, true));
|
|
850
854
|
emitCommitted(eid, "toolResult", pendingAction.toolCallId);
|
|
851
855
|
return;
|
|
@@ -2,7 +2,7 @@ import { createPeerInboundChainRef, createPeerSelfRef } from "../../agents/peer-
|
|
|
2
2
|
import { boundInputHashOf } from "../canonical-json.js";
|
|
3
3
|
import { readPendingSteerQueue } from "../checkpoint-store.js";
|
|
4
4
|
import { wakeOpening } from "../run-origin.js";
|
|
5
|
-
import { bindDeliveryObligations, createLiveNotificationLane, DeliveryObligations, DurableAppendObligations, injectionLaneOf, isDelegatedAgentTerminal, isTerminalTaskNotification, renderTaskNotificationXml, routeOrParkNotification, SystemInjectionQueue, taskNotificationDedupKey } from "../task-notification.js";
|
|
5
|
+
import { bindDeliveryObligations, createLiveNotificationLane, DeliveryObligations, DurableAppendObligations, injectionLaneOf, isDelegatedAgentTerminal, isTerminalTaskNotification, renderTaskNotificationXml, routeOrParkNotification, sessionAddressOf, SystemInjectionQueue, taskNotificationDedupKey } from "../task-notification.js";
|
|
6
6
|
import { settleConsumedFrame } from "../frame-settlement.js";
|
|
7
7
|
import { createReceivingChain } from "../mods/session-receive.js";
|
|
8
8
|
import { asThrownError } from "../thrown-value.js";
|
|
@@ -43,11 +43,11 @@ async function runNotificationLaneAs(input, obligations) {
|
|
|
43
43
|
let notificationHarness;
|
|
44
44
|
let notificationIdent = () => ({});
|
|
45
45
|
let notificationLaneLive = true;
|
|
46
|
-
let
|
|
46
|
+
let notificationAddress;
|
|
47
47
|
let descendantAnchorDisclosed = false;
|
|
48
48
|
const parkTaskNotification = (payload, priority, onDisposition) => {
|
|
49
49
|
laneSeat.handOff(payload);
|
|
50
|
-
const ownSession =
|
|
50
|
+
const ownSession = notificationAddress;
|
|
51
51
|
if (ownSession !== undefined)
|
|
52
52
|
routeOrParkNotification(pendingSessionNotifications, ownSession, payload, priority, onDisposition);
|
|
53
53
|
else
|
|
@@ -60,18 +60,18 @@ async function runNotificationLaneAs(input, obligations) {
|
|
|
60
60
|
uplink(payload, { priority });
|
|
61
61
|
}
|
|
62
62
|
catch (e) {
|
|
63
|
-
runner.deps.onError?.(e, { phase: "degraded", sessionId:
|
|
63
|
+
runner.deps.onError?.(e, { phase: "degraded", sessionId: notificationAddress?.sessionId ?? "", classification: "descendant-terminal-uplink" });
|
|
64
64
|
}
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
67
|
const rootAnchor = internals?.rootSessionId;
|
|
68
|
-
if (rootAnchor !== undefined && rootAnchor !==
|
|
69
|
-
routeOrParkNotification(pendingSessionNotifications, rootAnchor, payload, priority);
|
|
68
|
+
if (rootAnchor !== undefined && rootAnchor !== notificationAddress?.sessionId) {
|
|
69
|
+
routeOrParkNotification(pendingSessionNotifications, { sessionId: rootAnchor, occupant: internals?.rootSessionIncarnation }, payload, priority);
|
|
70
70
|
return;
|
|
71
71
|
}
|
|
72
72
|
if (internals?.parentSessionId !== undefined && !descendantAnchorDisclosed) {
|
|
73
73
|
descendantAnchorDisclosed = true;
|
|
74
|
-
runner.deps.onError?.(new Error(`background-agent terminal ${payload.task_id} stayed on this run's own session — the delegation tree's root session is not reachable from this run (no uplink, no root anchor)`), { phase: "degraded", sessionId:
|
|
74
|
+
runner.deps.onError?.(new Error(`background-agent terminal ${payload.task_id} stayed on this run's own session — the delegation tree's root session is not reachable from this run (no uplink, no root anchor)`), { phase: "degraded", sessionId: notificationAddress?.sessionId ?? "", classification: "descendant-terminal-unrouted" });
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
77
|
const receiving = createReceivingChain(() => prepared.receiveSeat);
|
|
@@ -83,7 +83,7 @@ async function runNotificationLaneAs(input, obligations) {
|
|
|
83
83
|
settleConsumedFrame(prepared.frameSettlement, taskNotificationDedupKey(item.payload), verdict.by, verdict.reason);
|
|
84
84
|
item.onDisposition?.("refused");
|
|
85
85
|
},
|
|
86
|
-
fault: (e) => runner.deps.onError?.(asThrownError(e), { phase: "degraded", sessionId:
|
|
86
|
+
fault: (e) => runner.deps.onError?.(asThrownError(e), { phase: "degraded", sessionId: notificationAddress?.sessionId ?? "", classification: "receive-hand-over" }),
|
|
87
87
|
});
|
|
88
88
|
});
|
|
89
89
|
function handOver(item, shown) {
|
|
@@ -152,32 +152,32 @@ async function runNotificationLaneAs(input, obligations) {
|
|
|
152
152
|
sessionReadStates,
|
|
153
153
|
sessionModeSeats,
|
|
154
154
|
onTaskNotification: laneSink,
|
|
155
|
-
}, self, taskIdRef, holdSessionLock, legWrites);
|
|
156
|
-
pendingSessionNotifications.
|
|
157
|
-
const settling = pendingSessionNotifications.settleBoxDebts(prepared
|
|
155
|
+
}, self, taskIdRef, holdSessionLock, legWrites, (destination, delivery) => pendingSessionNotifications.discardsStaleNotice(destination, delivery));
|
|
156
|
+
pendingSessionNotifications.admit(sessionAddressOf(prepared), prepared.sessionBox);
|
|
157
|
+
const settling = pendingSessionNotifications.settleBoxDebts(sessionAddressOf(prepared), prepared.abortController.signal);
|
|
158
158
|
if (settling !== undefined)
|
|
159
159
|
await settling;
|
|
160
160
|
const notificationLane = {
|
|
161
161
|
get harness() { return notificationHarness; }, set harness(h) { notificationHarness = h; },
|
|
162
|
-
get
|
|
163
|
-
set
|
|
164
|
-
if (
|
|
165
|
-
pendingSessionNotifications.liveLanes.unregister(
|
|
166
|
-
|
|
167
|
-
if (
|
|
168
|
-
pendingSessionNotifications.liveLanes.register(
|
|
162
|
+
get address() { return notificationAddress; },
|
|
163
|
+
set address(a) {
|
|
164
|
+
if (notificationAddress !== undefined)
|
|
165
|
+
pendingSessionNotifications.liveLanes.unregister(notificationAddress, takeAsDestination);
|
|
166
|
+
notificationAddress = a;
|
|
167
|
+
if (a !== undefined && notificationLaneLive)
|
|
168
|
+
pendingSessionNotifications.liveLanes.register(a, takeAsDestination);
|
|
169
169
|
},
|
|
170
170
|
get ident() { return notificationIdent; }, set ident(f) { notificationIdent = f; },
|
|
171
171
|
get live() { return notificationLaneLive; },
|
|
172
172
|
set live(v) {
|
|
173
173
|
notificationLaneLive = v;
|
|
174
|
-
if (
|
|
174
|
+
if (notificationAddress === undefined)
|
|
175
175
|
return;
|
|
176
176
|
if (v) {
|
|
177
|
-
pendingSessionNotifications.liveLanes.register(
|
|
177
|
+
pendingSessionNotifications.liveLanes.register(notificationAddress, takeAsDestination);
|
|
178
178
|
}
|
|
179
179
|
else {
|
|
180
|
-
pendingSessionNotifications.liveLanes.unregister(
|
|
180
|
+
pendingSessionNotifications.liveLanes.unregister(notificationAddress, takeAsDestination);
|
|
181
181
|
laneSeat.release();
|
|
182
182
|
}
|
|
183
183
|
},
|
|
@@ -186,8 +186,8 @@ async function runNotificationLaneAs(input, obligations) {
|
|
|
186
186
|
return await next({ prepared, injectTaskNotification, deliveredAtTurnOpen, peerInboundChainRef, modelCatalog, notificationLane, unsubscribeTaskNotifications, deliveryObligations });
|
|
187
187
|
}
|
|
188
188
|
finally {
|
|
189
|
-
if (
|
|
190
|
-
pendingSessionNotifications.liveLanes.unregister(
|
|
189
|
+
if (notificationAddress !== undefined)
|
|
190
|
+
pendingSessionNotifications.liveLanes.unregister(notificationAddress, takeAsDestination);
|
|
191
191
|
await obligations.settle();
|
|
192
192
|
}
|
|
193
193
|
}
|
|
@@ -15,7 +15,7 @@ import { asThrownError } from "../thrown-value.js";
|
|
|
15
15
|
export function runRecoveryLanes(input) {
|
|
16
16
|
const { spec, prepared, queue, rs, ident, compactionBrain, compactionBreaker, windowSafetyOptions, callerStop, runner } = input;
|
|
17
17
|
const runForcedCompactionPass = async (lane, turnSignal) => {
|
|
18
|
-
if (!compactionEnabled(spec.compaction
|
|
18
|
+
if (!compactionEnabled("autoCompact", spec.compaction, legContextOverlayOption(prepared, runner).contextOverlay))
|
|
19
19
|
return false;
|
|
20
20
|
if (compactionBreaker.failures >= MAX_CONSECUTIVE_COMPACTION_FAILURES)
|
|
21
21
|
return false;
|
|
@@ -36,7 +36,7 @@ export function runRecoveryLanes(input) {
|
|
|
36
36
|
brain: compactionBrain,
|
|
37
37
|
getApiKeyAndHeaders: spec.getApiKeyAndHeaders,
|
|
38
38
|
thinking: prepared.thinking,
|
|
39
|
-
settings: legCompactionSettings(spec, legContextOverlayOption(prepared, runner).contextOverlay),
|
|
39
|
+
settings: legCompactionSettings(spec, legContextOverlayOption(prepared, runner).contextOverlay, "autoCompact"),
|
|
40
40
|
customInstructions: spec.compaction?.instructions ?? DEFAULT_COMPACTION_INSTRUCTIONS,
|
|
41
41
|
signal: passSignal,
|
|
42
42
|
manualCancelSignal: callerStop.signal,
|
|
@@ -120,7 +120,7 @@ export function runRecoveryLanes(input) {
|
|
|
120
120
|
return false;
|
|
121
121
|
if (prepared.microCompact.clearOnRejection && attempt === 1) {
|
|
122
122
|
const proj = prepared.microCompact.projectionRef.current;
|
|
123
|
-
const compactionAvailable = compactionEnabled(spec.compaction
|
|
123
|
+
const compactionAvailable = compactionEnabled("autoCompact", spec.compaction, legContextOverlayOption(prepared, runner).contextOverlay) && compactionBreaker.failures < MAX_CONSECUTIVE_COMPACTION_FAILURES;
|
|
124
124
|
const declineArm = compactionAvailable ? "forced_compaction" : "none";
|
|
125
125
|
const plan = proj === undefined
|
|
126
126
|
? { declined: "no_candidates" }
|
|
@@ -166,7 +166,7 @@ async function finish(spec, prepared, opts, runner, sessions) {
|
|
|
166
166
|
brain: opts?.brain ?? runner.deps.brain,
|
|
167
167
|
getApiKeyAndHeaders: spec.getApiKeyAndHeaders,
|
|
168
168
|
thinking: prepared.thinking,
|
|
169
|
-
settings: legCompactionSettings(spec, legContextOverlayOption(prepared, runner).contextOverlay),
|
|
169
|
+
settings: legCompactionSettings(spec, legContextOverlayOption(prepared, runner).contextOverlay, "autoCompact"),
|
|
170
170
|
customInstructions: spec.compaction?.instructions ?? DEFAULT_COMPACTION_INSTRUCTIONS,
|
|
171
171
|
signal: opts.callerStop.signal,
|
|
172
172
|
manualCancelSignal: opts.callerStop.signal,
|
|
@@ -3,6 +3,7 @@ import { mintSystemReminder } from "../reminder-mint.js";
|
|
|
3
3
|
import { eventDefaultOn } from "../../prompt-assembly/event-registry.js";
|
|
4
4
|
import { compactionFailureReason, compactionPassReport, DEFAULT_COMPACTION_INSTRUCTIONS, isCompactionManualCancel, manualCompactOutcomeOf, maybeCompact, mintCompactedEvent, nextTrimForceBackoff, recordCompactionAndCheckRapidRefill } from "../auto-compaction.js";
|
|
5
5
|
import { emitTrace } from "../trace.js";
|
|
6
|
+
import { compactionEnabled } from "../context-settings.js";
|
|
6
7
|
import { steeringPreview } from "./steering-preview.js";
|
|
7
8
|
import { ATTACHMENT_BYTE_CAP, CHANGED_FILES_MAX, TOTAL_TOKENS_REMINDER_DEFAULT_MODE, attachmentEnvelopeTags, clipToBytes, collectDateChange, collectDueAttachments, collectInstructionsChange, commitAgentListing, commitInstructionsChange, commitSkillsListing, isIntactSource, rebaseCadenceWindows, renderAgentListingFrame, renderMcpInstructionsDelta, selectMcpDroppedBatch, renderSkillsListingFrame } from "./turn-attachments.js";
|
|
8
9
|
import { announceListingTruncation } from "../skill-listing-budget.js";
|
|
@@ -514,6 +515,11 @@ export function createTurnBoundary(input) {
|
|
|
514
515
|
return outcome;
|
|
515
516
|
};
|
|
516
517
|
const compactionPass = async (model, call) => {
|
|
518
|
+
if (manualCompactRef.requested && !compactionEnabled("manualCompact", spec.compaction, legContextOverlayOption(prepared, runner).contextOverlay)) {
|
|
519
|
+
emitTrace(rs.telemetry.tracer, () => ({ kind: "compaction.disabled", version: 1, taskId: rs.telemetry.taskId, ts: Date.now() }));
|
|
520
|
+
queue.push({ type: "compaction_outcome", outcome: "disabled", trigger: "manual", ...requesterOf(manualCompactRef.waiters), ...ident() });
|
|
521
|
+
drainManualCompact("disabled");
|
|
522
|
+
}
|
|
517
523
|
const forceManual = manualCompactRef.requested;
|
|
518
524
|
if ((!withinTaskCompaction() && !forceManual) ||
|
|
519
525
|
prepared.abortController.signal.aborted ||
|
|
@@ -570,7 +576,7 @@ export function createTurnBoundary(input) {
|
|
|
570
576
|
const trimPressureArmed = prepared.trimPressureRef.droppedMessages;
|
|
571
577
|
if (trimPressureArmed)
|
|
572
578
|
prepared.trimPressureRef.droppedMessages = false;
|
|
573
|
-
const trimPressure = trimPressureArmed && !rs.counters.trimForceBackoff;
|
|
579
|
+
const trimPressure = trimPressureArmed && !rs.counters.trimForceBackoff && withinTaskCompaction();
|
|
574
580
|
const passTrigger = trimPressure ? "forced" : forceManual ? "manual" : "auto";
|
|
575
581
|
let manualOutcome = "failed";
|
|
576
582
|
const manualInstructions = claimedManual?.instructions;
|
|
@@ -588,7 +594,7 @@ export function createTurnBoundary(input) {
|
|
|
588
594
|
brain: compactionBrain,
|
|
589
595
|
getApiKeyAndHeaders: spec.getApiKeyAndHeaders,
|
|
590
596
|
thinking: prepared.thinking,
|
|
591
|
-
settings: legCompactionSettings(spec, legContextOverlayOption(prepared, runner).contextOverlay),
|
|
597
|
+
settings: legCompactionSettings(spec, legContextOverlayOption(prepared, runner).contextOverlay, forceManual ? "manualCompact" : "autoCompact"),
|
|
592
598
|
customInstructions: manualInstructions ?? spec.compaction?.instructions ?? DEFAULT_COMPACTION_INSTRUCTIONS,
|
|
593
599
|
signal: compactionPassSignal,
|
|
594
600
|
manualCancelSignal,
|
|
@@ -643,23 +649,16 @@ export function createTurnBoundary(input) {
|
|
|
643
649
|
}
|
|
644
650
|
manualOutcome = manualCompactOutcomeOf(comp);
|
|
645
651
|
if (forceManual && !comp.compacted && !comp.blocked) {
|
|
646
|
-
|
|
647
|
-
emitTrace(rs.telemetry.tracer, () => ({ kind: "compaction.disabled", version: 1, taskId: rs.telemetry.taskId, ts: Date.now() }));
|
|
648
|
-
}
|
|
649
|
-
else {
|
|
650
|
-
emitTrace(rs.telemetry.tracer, () => ({ kind: "compaction.noop", version: 1, taskId: rs.telemetry.taskId, ts: Date.now() }));
|
|
651
|
-
}
|
|
652
|
+
emitTrace(rs.telemetry.tracer, () => ({ kind: "compaction.noop", version: 1, taskId: rs.telemetry.taskId, ts: Date.now() }));
|
|
652
653
|
}
|
|
653
654
|
if (!comp.compacted) {
|
|
654
655
|
const outcome = comp.blocked
|
|
655
656
|
? "blocked"
|
|
656
|
-
: comp.
|
|
657
|
-
?
|
|
658
|
-
: comp.
|
|
659
|
-
? "
|
|
660
|
-
:
|
|
661
|
-
? "noop"
|
|
662
|
-
: undefined;
|
|
657
|
+
: comp.suppressedByFloor
|
|
658
|
+
? "suppressed"
|
|
659
|
+
: comp.noop || forceManual
|
|
660
|
+
? "noop"
|
|
661
|
+
: undefined;
|
|
663
662
|
if (outcome !== undefined) {
|
|
664
663
|
queue.push({ type: "compaction_outcome", outcome, trigger: passTrigger, ...requester, ...ident() });
|
|
665
664
|
}
|
|
@@ -83,7 +83,7 @@ export class Runner {
|
|
|
83
83
|
verbLockSeats = { sessionBusy: (id) => this.sessionLocks.has(id) || this.sessionWrites.busy(id), takeSessionLock: (id) => this.acquireSessionLock(id) };
|
|
84
84
|
sessionReadStates = new SessionReadFileStates();
|
|
85
85
|
sessionModeSeats = new SessionModeSeats();
|
|
86
|
-
pendingSessionNotifications = new PendingSessionNotifications();
|
|
86
|
+
pendingSessionNotifications = new PendingSessionNotifications({ onNotice: () => this.deps.onNotice });
|
|
87
87
|
parentConstraintRegistry = new Map();
|
|
88
88
|
suspendedEnvReaps = new Map();
|
|
89
89
|
locallyClaimedTokens = new LocalClaims();
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
*/
|
|
36
36
|
import type { AgentTool } from "../../internal/harness.js";
|
|
37
37
|
import { valveLeaves } from "../../agents/tool-filter.js";
|
|
38
|
+
import type { EngineNotice } from "../engine-notice.js";
|
|
38
39
|
import { type ProtocolId } from "../protocol-table.js";
|
|
39
40
|
import type { ToolLegKind, ToolSelector, ToolSelectorLayer } from "../tool-face.js";
|
|
40
41
|
import { type ConstraintChainEntry } from "../tool-policy.js";
|
|
@@ -103,6 +104,24 @@ export interface PolicyNameFinding {
|
|
|
103
104
|
* the first entry's, `detail.problems` lists the refused entries of the layer in scan order (within the bounds above), `detail.total`
|
|
104
105
|
* counts every one. */
|
|
105
106
|
export declare function policyNameRefusal(first: PolicyNameFinding, more: readonly PolicyNameFinding[]): Error;
|
|
107
|
+
/** One entry of a restricting policy list (`deny` / `ask`) that names a tool the engine retired with no successor to write: the name
|
|
108
|
+
* matches nothing in any roster, so the audit leaves the entry out and says so ({@link retiredToolNameNotice}) instead of refusing
|
|
109
|
+
* the run. `guidance` is the retirement table's own line for the name. */
|
|
110
|
+
export interface RetiredPolicyEntry {
|
|
111
|
+
readonly field: "deny" | "ask";
|
|
112
|
+
readonly entry: string;
|
|
113
|
+
readonly layer: PolicyNameLayer;
|
|
114
|
+
readonly guidance: string;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The notice for the entries of one policy layer's deny or ask list that name a retired tool (`config.legacy_tool_name`, audience
|
|
118
|
+
* `user` — the person who wrote the entry believes it guards a tool): the audit left them out, they reach no tool in any roster, and the
|
|
119
|
+
* run goes on. One notice per audited layer per prepared task, minted here and nowhere else. `detail: { layer, entries: [{ field,
|
|
120
|
+
* entry, layer, guidance }], total, sessionId }` — `entries` are unique by (field, entry) in scan order, at most
|
|
121
|
+
* {@link RETIRED_NOTICE_ENTRIES_SHOWN}, `total` counts every one. The entries that name a tool the engine renamed are not here: their
|
|
122
|
+
* names have a successor, the entry guarded it, and the audit still refuses them.
|
|
123
|
+
*/
|
|
124
|
+
export declare function retiredToolNameNotice(layer: PolicyNameLayer, entries: readonly RetiredPolicyEntry[], sessionId: string): EngineNotice;
|
|
106
125
|
/**
|
|
107
126
|
* The names a definition's denied-tools entries stand for, for a lane that has neither a roster nor a notice sink at the point
|
|
108
127
|
* it builds its own policy (a workflow leg's agentType): each entry is read by the one reading, so `Tool(content)` denies the
|
|
@@ -84,6 +84,31 @@ export function policyNameRefusal(first, more) {
|
|
|
84
84
|
e.detail = { problems: listed.slice(0, POLICY_NAME_PROBLEMS_SHOWN), total: 1 + more.length };
|
|
85
85
|
return e;
|
|
86
86
|
}
|
|
87
|
+
const LAYER_WORD = {
|
|
88
|
+
caller_policy: "the run's tool policy",
|
|
89
|
+
session_rules: "the session's stored permission rules",
|
|
90
|
+
ancestor_session_rules: "the stored permission rules of an ancestor session",
|
|
91
|
+
};
|
|
92
|
+
const RETIRED_NOTICE_ENTRIES_SHOWN = 32;
|
|
93
|
+
export function retiredToolNameNotice(layer, entries, sessionId) {
|
|
94
|
+
const unique = [];
|
|
95
|
+
const seen = new Set();
|
|
96
|
+
for (const e of entries) {
|
|
97
|
+
const key = `${e.field}\u0000${e.entry}`;
|
|
98
|
+
if (seen.has(key))
|
|
99
|
+
continue;
|
|
100
|
+
seen.add(key);
|
|
101
|
+
unique.push(e);
|
|
102
|
+
}
|
|
103
|
+
const one = unique.length === 1;
|
|
104
|
+
const shown = unique.slice(0, 5).map((e) => `${e.field}-list entry "${e.entry}"`);
|
|
105
|
+
const more = unique.length > shown.length ? ` and ${unique.length - shown.length} more` : "";
|
|
106
|
+
return {
|
|
107
|
+
code: POLICY_NAME_REFUSAL_CODE,
|
|
108
|
+
message: `${LAYER_WORD[layer]} holds ${shown.join(", ")}${more}, ${one ? "a RETIRED tool name" : "RETIRED tool names"} that ${one ? "reaches" : "reach"} no tool in this run's roster — ${one ? "it guards" : "they guard"} nothing, and the run goes on without ${one ? "it" : "them"}. Remove ${one ? "the entry" : "the entries"} from the list.`,
|
|
109
|
+
detail: { layer, entries: unique.slice(0, RETIRED_NOTICE_ENTRIES_SHOWN).map((e) => ({ field: e.field, entry: e.entry, layer: e.layer, guidance: e.guidance })), total: unique.length, sessionId },
|
|
110
|
+
};
|
|
111
|
+
}
|
|
87
112
|
const LIST_WORD = { allowed: "allowed tools", denied: "denied tools" };
|
|
88
113
|
const NEAR_MISS_EFFECT = {
|
|
89
114
|
allowed: "it admits nothing, so the tool it was written for is not granted",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
* the resumed leg's), joined by the checkpoint row the resumed leg was opened from — never by a field here.
|
|
25
25
|
*/
|
|
26
26
|
import type { DeniedBy, GateOutcome } from "../gate-outcome.js";
|
|
27
|
+
import { type GateExitFacts } from "./gate-exit.js";
|
|
27
28
|
/** The one clock the occurrence's heartbeat facts are stamped on. MONOTONIC for the reason the progress lane
|
|
28
29
|
* states: every reading is subtracted from another, and a wall-clock step backwards would silence the beat. A
|
|
29
30
|
* host without `performance` falls back to the wall clock and inherits its rollback behaviour. */
|
|
@@ -92,8 +93,9 @@ export interface ToolOccurrenceTable {
|
|
|
92
93
|
/** A gate exit for this call: its record and the input it decided on (frozen by the gate's exit). */
|
|
93
94
|
gateRound(toolCallId: string, outcome: GateOutcome, finalInput?: unknown, rewrite?: import("../task-event.js").ToolInputRewrite): void;
|
|
94
95
|
/** A station after the gate refused the call: one more gate record, minted as a veto of whatever the latest one
|
|
95
|
-
* settled (a person's yes stays on the settlement; the refusing layer is the disposition).
|
|
96
|
-
|
|
96
|
+
* settled (a person's yes stays on the settlement; the refusing layer is the disposition). `facts` is what the refusing
|
|
97
|
+
* station knows beside the layer word: the extension that refused, the literals its sentence quoted. Returns the record. */
|
|
98
|
+
refuse(toolCallId: string, layer: DeniedBy, facts?: Pick<GateExitFacts, "extension" | "echoed">): GateOutcome;
|
|
97
99
|
/** An extension at `tool.call` answered for the call before its body was called (the kernel's record says the body had
|
|
98
100
|
* not started): the body is never called for this attempt. Once per attempt; a second is an engine defect. */
|
|
99
101
|
answeredInPlace(toolCallId: string, by: string): void;
|
|
@@ -91,10 +91,10 @@ export function createToolOccurrenceTable() {
|
|
|
91
91
|
occ.finalInput = finalInput;
|
|
92
92
|
occ.rewrite = rewrite;
|
|
93
93
|
},
|
|
94
|
-
refuse(toolCallId, layer,
|
|
94
|
+
refuse(toolCallId, layer, facts) {
|
|
95
95
|
const occ = held(toolCallId, "a refusal");
|
|
96
96
|
const latest = occ.gateRounds.at(-1);
|
|
97
|
-
const round = mintGateOutcome({ deniedBy: layer, ...(extension !== undefined ? { extension } : {}), ...(latest?.settlement !== undefined && latest.origin !== undefined ? { settled: { settlement: latest.settlement, origin: latest.origin } } : {}) });
|
|
97
|
+
const round = mintGateOutcome({ deniedBy: layer, ...(facts?.extension !== undefined ? { extension: facts.extension } : {}), ...(facts?.echoed !== undefined ? { echoed: facts.echoed } : {}), ...(latest?.settlement !== undefined && latest.origin !== undefined ? { settled: { settlement: latest.settlement, origin: latest.origin } } : {}) });
|
|
98
98
|
occ.gateRounds.push(round);
|
|
99
99
|
return round;
|
|
100
100
|
},
|