@sema-agent/core 7.56.0 → 7.58.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 +926 -0
- package/LICENSE +1 -1
- package/dist/agents/org-delivery-gate.js +3 -4
- package/dist/agents/peer-held-queue.d.ts +69 -49
- package/dist/agents/peer-held-queue.js +255 -106
- package/dist/agents/peer-session-drain.js +63 -43
- package/dist/agents/send-message-tool.js +3 -2
- package/dist/agents/subagent-steps.js +2 -4
- package/dist/agents/subagent.js +8 -8
- package/dist/brain/anthropic.js +16 -8
- package/dist/brain/open-responses.js +10 -8
- package/dist/brain/openai.js +11 -9
- package/dist/brain/provider-dialect.d.ts +3 -2
- package/dist/brain/provider-dialect.js +2 -2
- package/dist/brain/request-params.d.ts +6 -0
- package/dist/brain/request-params.js +14 -1
- package/dist/brain/route-adjudicator.js +2 -1
- package/dist/brain/stream-engine.d.ts +9 -0
- package/dist/brain/stream-engine.js +24 -10
- package/dist/brain/stream-shared.d.ts +5 -4
- package/dist/brain/stream-shared.js +4 -4
- package/dist/core/a2a.d.ts +2 -1
- package/dist/core/a2a.js +23 -10
- package/dist/core/allow-entry.d.ts +5 -11
- package/dist/core/allow-entry.js +19 -26
- package/dist/core/approval-object.d.ts +21 -5
- package/dist/core/approval-object.js +44 -17
- package/dist/core/ask-origin.d.ts +23 -4
- package/dist/core/ask-origin.js +5 -1
- package/dist/core/auto-compaction.d.ts +75 -6
- package/dist/core/auto-compaction.js +43 -27
- package/dist/core/auto-mode-directive.d.ts +29 -5
- package/dist/core/auto-mode-directive.js +38 -8
- package/dist/core/background-agent-store.d.ts +6 -2
- package/dist/core/background-agent-store.js +1 -1
- package/dist/core/checkpoint-requirements.d.ts +13 -1
- package/dist/core/checkpoint-requirements.js +4 -0
- package/dist/core/checkpoint-store.d.ts +44 -40
- package/dist/core/checkpoint-store.js +32 -14
- package/dist/core/cross-boundary-taint.js +4 -2
- package/dist/core/engine-notice.d.ts +4 -3
- package/dist/core/engine-notice.js +6 -0
- package/dist/core/file-history-store.d.ts +14 -8
- package/dist/core/file-history-store.js +14 -4
- package/dist/core/fs-write-gate-policy.d.ts +4 -2
- package/dist/core/fs-write-gate-policy.js +7 -3
- package/dist/core/gate-fold.js +6 -3
- package/dist/core/gate-lanes.js +13 -5
- package/dist/core/git-worktree-env.d.ts +53 -11
- package/dist/core/git-worktree-env.js +96 -12
- package/dist/core/hooks.d.ts +6 -3
- package/dist/core/hooks.js +12 -5
- package/dist/core/human-input-projection.d.ts +1 -0
- package/dist/core/human-input-projection.js +3 -0
- package/dist/core/locked-config.d.ts +15 -1
- package/dist/core/locked-config.js +38 -2
- package/dist/core/mailbox-store.d.ts +62 -1
- package/dist/core/mailbox-store.js +59 -0
- package/dist/core/mcp-call-meta.d.ts +66 -0
- package/dist/core/mcp-call-meta.js +103 -0
- package/dist/core/mcp-connection-pool.d.ts +3 -1
- package/dist/core/mcp-connection-pool.js +3 -1
- package/dist/core/mcp-failure.d.ts +7 -1
- package/dist/core/mcp-failure.js +10 -0
- package/dist/core/mcp-name-judge.d.ts +46 -0
- package/dist/core/mcp-name-judge.js +61 -0
- package/dist/core/mcp-probe.d.ts +5 -1
- package/dist/core/mcp-probe.js +3 -6
- package/dist/core/mcp-server-link.d.ts +5 -2
- package/dist/core/mcp-server-spec.d.ts +46 -18
- package/dist/core/mcp-server-spec.js +1 -18
- package/dist/core/mcp.d.ts +6 -14
- package/dist/core/mcp.js +85 -65
- package/dist/core/memory-engine/consolidation-driver.js +4 -3
- package/dist/core/memory-engine/distiller.js +26 -17
- package/dist/core/memory-engine/layout.js +5 -2
- package/dist/core/memory-engine/scope-contract.d.ts +45 -4
- package/dist/core/memory-engine/scope-contract.js +80 -11
- package/dist/core/mode-policy.d.ts +8 -5
- package/dist/core/mode-policy.js +5 -4
- package/dist/core/mods/host.js +1 -1
- package/dist/core/mods/kernel/dispatch.d.ts +3 -0
- package/dist/core/mods/kernel/dispatch.js +10 -8
- package/dist/core/mods/kernel/events.d.ts +5 -1
- package/dist/core/mods/kernel/events.js +1 -1
- package/dist/core/mods/kernel/registration.d.ts +5 -1
- package/dist/core/mods/kernel/site-rules.d.ts +3 -0
- package/dist/core/mods/kernel/site-rules.js +10 -0
- package/dist/core/mods/package.d.ts +23 -0
- package/dist/core/mods/package.js +118 -0
- package/dist/core/mods/stations.d.ts +2 -2
- package/dist/core/mods/stations.js +1 -1
- package/dist/core/mods/tool-call.d.ts +5 -1
- package/dist/core/mods/tool-call.js +12 -3
- package/dist/core/park-selfcheck.js +2 -0
- package/dist/core/path-guard-rows.d.ts +20 -0
- package/dist/core/path-guard-rows.js +11 -0
- package/dist/core/peer-seat.d.ts +186 -0
- package/dist/core/peer-seat.js +307 -0
- package/dist/core/permission-rule-consent.d.ts +5 -3
- package/dist/core/permission-rule-consent.js +20 -15
- package/dist/core/permission-rule-model.d.ts +43 -2
- package/dist/core/permission-rule-model.js +52 -8
- package/dist/core/permission-rule-org.js +1 -1
- package/dist/core/present-plan-tool.d.ts +10 -1
- package/dist/core/present-plan-tool.js +46 -2
- package/dist/core/protocol-http-auth.d.ts +56 -31
- package/dist/core/protocol-http-auth.js +71 -42
- package/dist/core/protocol-naming.d.ts +20 -0
- package/dist/core/protocol-naming.js +20 -3
- package/dist/core/read-only-shell.d.ts +20 -5
- package/dist/core/read-only-shell.js +29 -14
- package/dist/core/redaction-marks.d.ts +16 -0
- package/dist/core/redaction-marks.js +16 -0
- package/dist/core/redaction-passes.js +8 -9
- package/dist/core/remote-env.d.ts +37 -1
- package/dist/core/remote-env.js +11 -0
- package/dist/core/resume-startup-cause.d.ts +24 -2
- package/dist/core/resume-startup-cause.js +20 -1
- package/dist/core/retention.d.ts +41 -15
- package/dist/core/retention.js +59 -12
- package/dist/core/rewrite-rejudge.d.ts +37 -0
- package/dist/core/rewrite-rejudge.js +40 -0
- package/dist/core/roles.js +50 -7
- package/dist/core/run-origin.d.ts +40 -0
- package/dist/core/run-origin.js +37 -0
- package/dist/core/runner/advertised-writable-dirs.d.ts +57 -38
- package/dist/core/runner/advertised-writable-dirs.js +126 -0
- package/dist/core/runner/compact-session.d.ts +10 -0
- package/dist/core/runner/compact-session.js +202 -0
- package/dist/core/runner/compaction-call-options.d.ts +2 -2
- package/dist/core/runner/compaction-restate.d.ts +15 -6
- package/dist/core/runner/compaction-restate.js +28 -2
- package/dist/core/runner/compaction-seams.d.ts +21 -1
- package/dist/core/runner/compaction-seams.js +11 -8
- package/dist/core/runner/contracts.d.ts +36 -21
- package/dist/core/runner/derived-route-fallback.d.ts +13 -0
- package/dist/core/runner/derived-route-fallback.js +6 -0
- package/dist/core/runner/env-capability-census.d.ts +3 -2
- package/dist/core/runner/env-capability-census.js +9 -3
- package/dist/core/runner/gate-exit.d.ts +18 -4
- package/dist/core/runner/gate-exit.js +5 -1
- package/dist/core/runner/permission-rule-lanes.d.ts +7 -7
- package/dist/core/runner/permission-rule-lanes.js +17 -11
- package/dist/core/runner/prepare-acquire-reconcile.d.ts +3 -0
- package/dist/core/runner/prepare-acquire-reconcile.js +2 -1
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +2 -0
- package/dist/core/runner/prepare-caps-and-workflow.js +1 -1
- package/dist/core/runner/prepare-config-doors.d.ts +14 -5
- package/dist/core/runner/prepare-config-doors.js +16 -13
- package/dist/core/runner/prepare-delegation-surface.d.ts +4 -0
- package/dist/core/runner/prepare-delegation-surface.js +15 -18
- package/dist/core/runner/prepare-gate-stations.js +1 -1
- package/dist/core/runner/prepare-hands-readface.d.ts +10 -4
- package/dist/core/runner/prepare-hands-readface.js +6 -1
- package/dist/core/runner/prepare-memory.d.ts +3 -0
- package/dist/core/runner/prepare-memory.js +19 -23
- package/dist/core/runner/prepare-park-ask.d.ts +2 -0
- package/dist/core/runner/prepare-park-ask.js +2 -2
- package/dist/core/runner/prepare-policy-chain.d.ts +4 -4
- package/dist/core/runner/prepare-policy-chain.js +4 -6
- package/dist/core/runner/prepare-protocol-tools.d.ts +4 -2
- package/dist/core/runner/prepare-protocol-tools.js +3 -3
- package/dist/core/runner/prepare-suspend-saga.d.ts +2 -0
- package/dist/core/runner/prepare-suspend-saga.js +2 -1
- package/dist/core/runner/prepare-task.d.ts +4 -1
- package/dist/core/runner/prepare-task.js +46 -37
- package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +13 -0
- package/dist/core/runner/prepare-tool-disclosure-mount.js +13 -7
- package/dist/core/runner/prepare-wiring-manifest.d.ts +1 -0
- package/dist/core/runner/prepare-wiring-manifest.js +2 -2
- package/dist/core/runner/prepare-workspace-restore.d.ts +3 -0
- package/dist/core/runner/prepare-workspace-restore.js +4 -4
- package/dist/core/runner/resume-admission.js +1 -1
- package/dist/core/runner/resume-checkpoint-screen.js +2 -0
- package/dist/core/runner/rewind-files.d.ts +2 -5
- package/dist/core/runner/rewind-files.js +9 -51
- package/dist/core/runner/run-harness-handlers.d.ts +3 -4
- package/dist/core/runner/run-harness-handlers.js +1 -8
- package/dist/core/runner/run-identity-wiring.js +1 -0
- package/dist/core/runner/run-leg.js +15 -22
- package/dist/core/runner/run-notification-lane.d.ts +2 -0
- package/dist/core/runner/run-notification-lane.js +5 -2
- package/dist/core/runner/run-recovery-lanes.js +3 -4
- package/dist/core/runner/run-settle-and-teardown.js +5 -11
- package/dist/core/runner/run-terminal-adoption.js +3 -4
- package/dist/core/runner/run-turn-boundary.js +3 -5
- package/dist/core/runner/runtask.d.ts +8 -1
- package/dist/core/runner/runtask.js +28 -34
- package/dist/core/runner/send-message-continuation.js +1 -1
- package/dist/core/runner/session-verb-doors.d.ts +28 -0
- package/dist/core/runner/session-verb-doors.js +48 -0
- package/dist/core/runner/session-write-ledger.d.ts +30 -0
- package/dist/core/runner/session-write-ledger.js +101 -0
- package/dist/core/runner/stream-settle-backstop.js +11 -14
- package/dist/core/runner/sub-agent-deny-lists.d.ts +25 -3
- package/dist/core/runner/sub-agent-deny-lists.js +21 -10
- package/dist/core/runner/teardown-bounded.d.ts +1 -0
- package/dist/core/runner/teardown-bounded.js +1 -0
- package/dist/core/runner/terminal-account.js +3 -3
- package/dist/core/runner/tool-end-body.js +1 -0
- package/dist/core/runner/tool-occurrence.d.ts +4 -1
- package/dist/core/runner/tool-occurrence.js +2 -1
- package/dist/core/runner/write-protection-station.d.ts +8 -2
- package/dist/core/runner/write-protection-station.js +2 -0
- package/dist/core/runner-deps.d.ts +4 -4
- package/dist/core/secret-env.d.ts +4 -0
- package/dist/core/secret-env.js +3 -0
- package/dist/core/sensitive-path-policy.js +6 -7
- package/dist/core/session-log-transfer.d.ts +24 -0
- package/dist/core/session-log-transfer.js +166 -0
- package/dist/core/session-policy-store.d.ts +7 -2
- package/dist/core/session-policy-store.js +1 -1
- package/dist/core/session-store.d.ts +84 -19
- package/dist/core/session-store.js +162 -24
- package/dist/core/session.d.ts +92 -1
- package/dist/core/shell-read-silence.js +1 -0
- package/dist/core/shell-wrapper-projection.d.ts +1 -1
- package/dist/core/steer-replay.d.ts +4 -2
- package/dist/core/steer-replay.js +2 -1
- package/dist/core/store-contracts/background-agent-store-contract.js +1 -0
- package/dist/core/store-contracts/checkpoint-store-contract.js +19 -1
- package/dist/core/store-contracts/file-history-store-contract.js +9 -0
- package/dist/core/store-contracts/mailbox-store-contract.js +49 -1
- package/dist/core/store-contracts/session-repo-contract.js +112 -5
- package/dist/core/store-contracts/session-store-contract.d.ts +4 -1
- package/dist/core/store-contracts/session-store-contract.js +236 -2
- package/dist/core/task-event.d.ts +68 -8
- package/dist/core/task-registry-agent.d.ts +8 -4
- package/dist/core/task-registry-agent.js +14 -8
- package/dist/core/task-registry-shared.d.ts +36 -6
- package/dist/core/task-registry-shared.js +11 -0
- package/dist/core/task-registry.d.ts +1 -1
- package/dist/core/task-registry.js +1 -1
- package/dist/core/task-spec.d.ts +37 -0
- package/dist/core/task-stream.d.ts +2 -1
- package/dist/core/terminal-cause.d.ts +1 -1
- package/dist/core/tool-catalog-entries.d.ts +6 -0
- package/dist/core/tool-catalog-entries.js +2 -0
- package/dist/core/tool-name-aliases.d.ts +32 -2
- package/dist/core/tool-name-aliases.js +23 -0
- package/dist/core/tool-name-readings.d.ts +4 -0
- package/dist/core/tool-name-readings.js +1 -0
- package/dist/core/tool-policy.d.ts +10 -6
- package/dist/core/tool-policy.js +4 -7
- package/dist/core/tool-result-store.d.ts +17 -10
- package/dist/core/tool-result-store.js +3 -1
- package/dist/core/trace.d.ts +4 -1
- package/dist/core/trace.js +2 -1
- package/dist/core/types.d.ts +1 -1
- package/dist/core/untrusted-egress.d.ts +18 -0
- package/dist/core/untrusted-egress.js +82 -12
- package/dist/core/wiring-manifest.d.ts +12 -3
- package/dist/core/wiring-manifest.js +4 -3
- package/dist/core/workspace-snapshot.d.ts +44 -0
- package/dist/core/workspace-snapshot.js +34 -0
- package/dist/core/write-protect.d.ts +43 -3
- package/dist/core/write-protect.js +43 -16
- package/dist/engine/execution-env/node-execution-env.js +15 -11
- package/dist/engine/execution-env/symlink-chain.d.ts +7 -5
- package/dist/engine/harness/agent-harness.d.ts +12 -5
- package/dist/engine/harness/agent-harness.js +13 -2
- package/dist/engine/harness/types.d.ts +48 -7
- package/dist/engine/harness/types.js +5 -1
- package/dist/engine/llm/types.d.ts +12 -3
- package/dist/engine/llm/types.js +1 -1
- package/dist/engine/loop/agent-loop.d.ts +1 -4
- package/dist/engine/loop/agent-loop.js +26 -4
- package/dist/engine/session/import-validate.js +3 -0
- package/dist/engine/session/memory-repo.d.ts +17 -9
- package/dist/engine/session/memory-repo.js +44 -34
- package/dist/engine/session/repo-utils.d.ts +22 -4
- package/dist/engine/session/repo-utils.js +49 -1
- package/dist/engine/session/storage-base.d.ts +10 -1
- package/dist/engine/session/storage-base.js +7 -1
- package/dist/index.d.ts +23 -11
- package/dist/index.js +15 -6
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/internal/harness.d.ts +4 -3
- package/dist/internal/harness.js +3 -2
- package/dist/stores/file/checkpoint-store.d.ts +0 -4
- package/dist/stores/file/checkpoint-store.js +0 -1
- package/dist/stores/file/file-history-store.js +12 -4
- package/dist/stores/file/index.d.ts +4 -1
- package/dist/stores/file/index.js +4 -1
- package/dist/stores/file/mailbox-store.d.ts +2 -1
- package/dist/stores/file/mailbox-store.js +26 -1
- package/dist/stores/file/session-store.d.ts +15 -8
- package/dist/stores/file/session-store.js +28 -13
- package/dist/tools/fs/bash-readonly-classifier.d.ts +15 -19
- package/dist/tools/fs/bash-readonly-classifier.js +5 -10
- package/dist/tools/fs/fs-bash.js +10 -3
- package/dist/tools/fs/fs-write.d.ts +6 -3
- package/dist/tools/fs/fs-write.js +8 -7
- package/dist/tools/fs/index.d.ts +3 -0
- package/dist/tools/fs/index.js +1 -1
- package/dist/tools/fs/pattern-kill-guard.d.ts +3 -2
- package/dist/tools/fs/pattern-kill-guard.js +68 -36
- package/dist/tools/fs/safety.js +40 -8
- package/dist/tools/fs/search.js +6 -24
- package/dist/tools/fs/shell-read-check.d.ts +18 -1
- package/dist/tools/fs/shell-read-check.js +66 -16
- package/dist/tools/fs/shell-read-establish.js +2 -1
- package/dist/tools/fs/shell-read-identity.d.ts +12 -9
- package/dist/tools/fs/shell-read-identity.js +10 -5
- package/dist/tools/fs/shell-read-judge.d.ts +10 -1
- package/dist/tools/web.js +9 -7
- package/dist/tools/worktree.d.ts +42 -15
- package/dist/tools/worktree.js +60 -32
- package/package.json +4 -2
- package/test/export-surface.snapshot.json +141 -3
- package/wire-changes/core-stores-sql@7.57.0.json +29 -0
- package/wire-changes/core-stores-sql@7.58.0.json +29 -0
- package/wire-changes/core@7.57.0.json +1487 -0
- package/wire-changes/core@7.58.0.json +2188 -0
- package/wire-changes/mods-kernel@7.57.0.json +29 -0
- package/wire-changes/mods-kernel@7.58.0.json +81 -0
- package/wire-changes/primitives@7.57.0.json +245 -0
- package/wire-changes/primitives@7.58.0.json +29 -0
|
@@ -1,4 +1,43 @@
|
|
|
1
|
+
import { posix, win32 } from "node:path";
|
|
1
2
|
import { isWithin } from "./session-rule-policy.js";
|
|
3
|
+
import { isWinFormPath, normalizeAbsPathLexically } from "../../tools/fs/safety.js";
|
|
4
|
+
import { validatePath } from "../effective-path-target.js";
|
|
5
|
+
import { inlineUntrusted } from "../untrusted-text.js";
|
|
6
|
+
export const PLAN_FILE_INVALID_CODE = "config.plan_file_invalid";
|
|
7
|
+
export function planFileInvalid(value, why) {
|
|
8
|
+
let shown;
|
|
9
|
+
try {
|
|
10
|
+
shown = JSON.stringify(value) ?? String(value);
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
shown = typeof value;
|
|
14
|
+
}
|
|
15
|
+
const e = new Error(`TaskSpec.planFile ${shown} ${why} — the plan file must be the absolute path, in lexical normal form, of a regular file (or of a file not yet written) whose directory exists, on a leg whose file tools can write; ` +
|
|
16
|
+
`a plan file the gates cannot hold as declared would teach the model a file nobody can write, so the run is refused rather than started without it.`);
|
|
17
|
+
e.code = PLAN_FILE_INVALID_CODE;
|
|
18
|
+
e.detail = { planFile: value, reason: why };
|
|
19
|
+
return e;
|
|
20
|
+
}
|
|
21
|
+
export function checkedPlanFileShape(value) {
|
|
22
|
+
if (value === undefined)
|
|
23
|
+
return undefined;
|
|
24
|
+
if (typeof value !== "string")
|
|
25
|
+
throw planFileInvalid(value, `is a ${value === null ? "null" : typeof value}, not a string`);
|
|
26
|
+
if (value.length === 0)
|
|
27
|
+
throw planFileInvalid(value, "is an empty string");
|
|
28
|
+
if (validatePath(value, { intent: "validate-coordinate" }) === undefined)
|
|
29
|
+
throw planFileInvalid(value, "is not an absolute path");
|
|
30
|
+
if (normalizeAbsPathLexically(value) !== value)
|
|
31
|
+
throw planFileInvalid(value, `is not in lexical normal form (it reads as ${normalizeAbsPathLexically(value)})`);
|
|
32
|
+
if (inlineUntrusted(value, PLAN_PATH_MAX) !== value)
|
|
33
|
+
throw planFileInvalid(value, `cannot be told to the model verbatim (a control character, a run of whitespace, an envelope marker, or more than ${PLAN_PATH_MAX} characters)`);
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
export const PLAN_PATH_MAX = 4096;
|
|
37
|
+
export function planFileShown(path) {
|
|
38
|
+
return inlineUntrusted(path, PLAN_PATH_MAX);
|
|
39
|
+
}
|
|
40
|
+
export const PLAN_FILE_MAX_BYTES = 1024 * 1024;
|
|
2
41
|
export function swallowedFenceRoot(domainCanonical, fenceRootsCanonical) {
|
|
3
42
|
for (const root of fenceRootsCanonical) {
|
|
4
43
|
if (root && isWithin(domainCanonical, root))
|
|
@@ -51,6 +90,93 @@ export class AdvertisedWritableDirs {
|
|
|
51
90
|
get roots() {
|
|
52
91
|
return this.admitted;
|
|
53
92
|
}
|
|
93
|
+
get planFile() {
|
|
94
|
+
return this.admittedPlanFile;
|
|
95
|
+
}
|
|
96
|
+
admittedPlanFile;
|
|
97
|
+
async admitPlanFile(spelled) {
|
|
98
|
+
const win = isWinFormPath(spelled);
|
|
99
|
+
const pathOps = win ? win32 : posix;
|
|
100
|
+
const parent = pathOps.dirname(spelled);
|
|
101
|
+
const name = pathOps.basename(spelled);
|
|
102
|
+
if (!name || parent === spelled)
|
|
103
|
+
throw planFileInvalid(spelled, "names no file below a directory");
|
|
104
|
+
const leaf = await this.env.fileInfo(spelled);
|
|
105
|
+
if (leaf.ok && leaf.value.kind !== "file")
|
|
106
|
+
throw planFileInvalid(spelled, leaf.value.kind === "symlink" ? "is a symbolic link (the plan file must be the file itself, not a link to one)" : `is a ${leaf.value.kind}, not a file`);
|
|
107
|
+
if (!leaf.ok && leaf.error.code !== "not_found")
|
|
108
|
+
throw planFileInvalid(spelled, `could not be examined (${leaf.error.code}: ${leaf.error.message})`);
|
|
109
|
+
const parentCanonical = await this.env.canonicalPath(parent);
|
|
110
|
+
if (!parentCanonical.ok)
|
|
111
|
+
throw planFileInvalid(spelled, `has a directory that does not resolve (${parentCanonical.error.code}: ${parentCanonical.error.message}) — the host creates the plan file's directory before the run`);
|
|
112
|
+
const parentInfo = await this.env.fileInfo(parentCanonical.value);
|
|
113
|
+
if (!parentInfo.ok || parentInfo.value.kind !== "directory")
|
|
114
|
+
throw planFileInvalid(spelled, `has a parent ${parentCanonical.value} that is not a directory`);
|
|
115
|
+
const own = leaf.ok ? await this.env.canonicalPath(spelled) : undefined;
|
|
116
|
+
if (own !== undefined && !own.ok)
|
|
117
|
+
throw planFileInvalid(spelled, `could not be resolved (${own.error.code}: ${own.error.message})`);
|
|
118
|
+
const joined = own?.ok === true ? own : await this.env.joinPath([parentCanonical.value, name]);
|
|
119
|
+
if (!joined.ok)
|
|
120
|
+
throw planFileInvalid(spelled, `could not be joined below its directory (${joined.error.code}: ${joined.error.message})`);
|
|
121
|
+
const key = joined.value;
|
|
122
|
+
await this.resolveDeclaredRoots();
|
|
123
|
+
const swallowed = swallowedFenceRoot(key, [...this.fenceRoots, ...this.admitted]);
|
|
124
|
+
if (swallowed !== undefined && swallowed !== key)
|
|
125
|
+
throw planFileInvalid(spelled, `resolves to ${key}, which holds the root ${swallowed}`);
|
|
126
|
+
if (!this.admitted.includes(key))
|
|
127
|
+
this.admitted.push(key);
|
|
128
|
+
this.admittedPlanFile = Object.freeze({ spelled, key });
|
|
129
|
+
this.verdicts.set("plan", "admitted");
|
|
130
|
+
return key;
|
|
131
|
+
}
|
|
132
|
+
async readPlanFile(signal) {
|
|
133
|
+
const planFile = this.admittedPlanFile;
|
|
134
|
+
if (planFile === undefined)
|
|
135
|
+
return { ok: false, reason: "this run admitted no plan file" };
|
|
136
|
+
const canonical = await this.env.canonicalPath(planFile.key, signal);
|
|
137
|
+
if (!canonical.ok)
|
|
138
|
+
return canonical.error.code === "not_found" ? { ok: true, text: undefined } : { ok: false, reason: `${canonical.error.code}: ${canonical.error.message}` };
|
|
139
|
+
if (canonical.value !== planFile.key)
|
|
140
|
+
return { ok: false, reason: `it now resolves to ${canonical.value} (a link replaced it or one of its directories), which is not read through` };
|
|
141
|
+
let bytes;
|
|
142
|
+
if (this.env.openBound !== undefined) {
|
|
143
|
+
const held = await this.env.openBound(planFile.key, signal);
|
|
144
|
+
if (!held.ok)
|
|
145
|
+
return held.error.code === "not_found" ? { ok: true, text: undefined } : { ok: false, reason: `${held.error.code}: ${held.error.message}` };
|
|
146
|
+
try {
|
|
147
|
+
if (held.value.kind !== "file")
|
|
148
|
+
return { ok: false, reason: `it is now a ${held.value.kind}` };
|
|
149
|
+
const read = await held.value.readBytes(PLAN_FILE_MAX_BYTES, signal);
|
|
150
|
+
if (!read.ok)
|
|
151
|
+
return { ok: false, reason: `${read.error.code}: ${read.error.message}` };
|
|
152
|
+
bytes = read.value;
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
await held.value.close();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
const leaf = await this.env.fileInfo(planFile.key, signal);
|
|
160
|
+
if (!leaf.ok)
|
|
161
|
+
return leaf.error.code === "not_found" ? { ok: true, text: undefined } : { ok: false, reason: `${leaf.error.code}: ${leaf.error.message}` };
|
|
162
|
+
if (leaf.value.kind !== "file")
|
|
163
|
+
return { ok: false, reason: leaf.value.kind === "symlink" ? "it is now a symbolic link, which is not read through" : `it is now a ${leaf.value.kind}` };
|
|
164
|
+
if (leaf.value.size > PLAN_FILE_MAX_BYTES)
|
|
165
|
+
return { ok: false, reason: `it is ${leaf.value.size} bytes, over the ${PLAN_FILE_MAX_BYTES} a plan is read up to` };
|
|
166
|
+
const read = await this.env.readBinaryFile(planFile.key, signal);
|
|
167
|
+
if (!read.ok)
|
|
168
|
+
return read.error.code === "not_found" ? { ok: true, text: undefined } : { ok: false, reason: `${read.error.code}: ${read.error.message}` };
|
|
169
|
+
const after = await this.env.canonicalPath(planFile.key, signal);
|
|
170
|
+
const afterLeaf = await this.env.fileInfo(planFile.key, signal);
|
|
171
|
+
if (!after.ok || after.value !== planFile.key || !afterLeaf.ok || afterLeaf.value.kind !== "file")
|
|
172
|
+
return { ok: false, reason: "it changed while it was read (a link or another object replaced it), so it is not read through" };
|
|
173
|
+
if (read.value.length > PLAN_FILE_MAX_BYTES)
|
|
174
|
+
return { ok: false, reason: `it is ${read.value.length} bytes, over the ${PLAN_FILE_MAX_BYTES} a plan is read up to` };
|
|
175
|
+
bytes = read.value;
|
|
176
|
+
}
|
|
177
|
+
const text = new TextDecoder("utf-8").decode(bytes);
|
|
178
|
+
return { ok: true, text: text.trim() === "" ? undefined : text };
|
|
179
|
+
}
|
|
54
180
|
verdictOf(advertiser) {
|
|
55
181
|
return this.verdicts.get(advertiser) ?? "not-asked";
|
|
56
182
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type CompactSessionRequest, type CompactSessionResult } from "../auto-compaction.js";
|
|
2
|
+
import { type SessionStore } from "../session.js";
|
|
3
|
+
import type { RunnerDeps } from "../types.js";
|
|
4
|
+
import { type SessionLockSeats } from "./session-verb-doors.js";
|
|
5
|
+
/** What the Runner lends the compaction: its current deps, its session store, and its lock. */
|
|
6
|
+
export interface CompactSessionSeats extends SessionLockSeats {
|
|
7
|
+
deps: RunnerDeps;
|
|
8
|
+
sessions: SessionStore;
|
|
9
|
+
}
|
|
10
|
+
export declare function compactIdleSession(seats: CompactSessionSeats, request: CompactSessionRequest): Promise<CompactSessionResult>;
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { convertToLlm, uuidv7 } from "../../internal/harness.js";
|
|
2
|
+
import { compactionFailureReason, compactionPassReport, DEFAULT_COMPACTION_INSTRUCTIONS, isCompactionManualCancel, manualCompactOutcomeOf, maybeCompact, mintCompactedEvent } from "../auto-compaction.js";
|
|
3
|
+
import { contextOverlayFor } from "../context-settings.js";
|
|
4
|
+
import { admitLegMods, legFacadeSeats } from "../mods/stations.js";
|
|
5
|
+
import { malformedPricingField } from "../pricing.js";
|
|
6
|
+
import { resolveTaskModel } from "../roles.js";
|
|
7
|
+
import { StoredSession } from "../session.js";
|
|
8
|
+
import { emitTrace } from "../trace.js";
|
|
9
|
+
import { egressThrownText } from "../untrusted-egress.js";
|
|
10
|
+
import { emitInputTruncated, legCompactionSettings } from "./compaction-call-options.js";
|
|
11
|
+
import { compactionHookOptions, summaryProviderOptions } from "./compaction-seams.js";
|
|
12
|
+
import { compactionSummaryFallback, compactionSummaryIsDerived } from "./derived-route-fallback.js";
|
|
13
|
+
import { resolveCompactionModel } from "./prepare-config-doors.js";
|
|
14
|
+
import { compactionActivationSnapshot } from "./prepare-tool-disclosure-mount.js";
|
|
15
|
+
import { derivedLegBrain, sideCallBookOf } from "./side-call-account.js";
|
|
16
|
+
import { acquireExistingSession, claimIdleSession, readPlainRequest, shownValue } from "./session-verb-doors.js";
|
|
17
|
+
const VERB = "Runner.compactSession";
|
|
18
|
+
const REQUEST_KEYS = new Set(["sessionId", "model", "instructions", "compaction", "compactionModel", "getApiKeyAndHeaders", "signal"]);
|
|
19
|
+
const SETTINGS_KEYS = new Set(["enabled", "reserveTokens", "keepRecentTokens", "instructions", "clampTolerance"]);
|
|
20
|
+
export async function compactIdleSession(seats, request) {
|
|
21
|
+
const req = screenCompactSessionRequest(request);
|
|
22
|
+
const { deps } = seats;
|
|
23
|
+
const resolved = resolveTaskModel({ model: req.model }, deps);
|
|
24
|
+
const named = resolveCompactionModel(req.compactionModel !== undefined ? { compactionModel: req.compactionModel } : {}, deps, "compactSession.compactionModel");
|
|
25
|
+
if (req.signal?.aborted === true)
|
|
26
|
+
return { outcome: "mooted", events: [] };
|
|
27
|
+
const release = await claimIdleSession(seats, req.sessionId, () => sessionBusyRefusal(req.sessionId));
|
|
28
|
+
try {
|
|
29
|
+
const acquired = await acquireExistingSession(seats.sessions, req.sessionId, VERB, "nothing was compacted");
|
|
30
|
+
const legMods = await admitLegMods({ spec: {}, deps, sessionId: req.sessionId });
|
|
31
|
+
return await compactOnSession(req, deps, new StoredSession(acquired.session.getStorage()), resolved, named, legMods);
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
release();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async function compactOnSession(req, deps, session, resolved, named, legMods) {
|
|
38
|
+
const { sessionId } = req;
|
|
39
|
+
const events = [];
|
|
40
|
+
const ident = () => ({ eventId: uuidv7() });
|
|
41
|
+
const passReport = compactionPassReport({ push: (e) => events.push(e) }, ident);
|
|
42
|
+
const stats = { turns: 0, tokens: 0, toolCalls: 0, promptTokens: 0, totalInputTokens: 0, cachedTokens: 0, cacheWriteTokens: 0, cacheWriteTokensLong: 0, outputTokens: 0, costMicroUsd: 0 };
|
|
43
|
+
const telemetry = { unpricedSpend: false, tracer: deps.tracer, taskId: sessionId };
|
|
44
|
+
const accountBook = sideCallBookOf(stats, { telemetry, pricing: () => deps.pricing, noteUnevaluablePriceTable: (p) => void (malformedPricingField(p) !== undefined && (telemetry.unpricedSpend = true)), catalog: deps.models });
|
|
45
|
+
let calls = 0;
|
|
46
|
+
const book = (lane, model, reply) => {
|
|
47
|
+
calls += 1;
|
|
48
|
+
accountBook(lane, model, reply);
|
|
49
|
+
};
|
|
50
|
+
const answer = (outcome) => ({
|
|
51
|
+
outcome,
|
|
52
|
+
events,
|
|
53
|
+
...(calls > 0
|
|
54
|
+
? {
|
|
55
|
+
usage: {
|
|
56
|
+
tokens: stats.tokens,
|
|
57
|
+
totalInputTokens: stats.totalInputTokens,
|
|
58
|
+
promptTokens: stats.promptTokens,
|
|
59
|
+
cachedTokens: stats.cachedTokens,
|
|
60
|
+
cacheWriteTokens: stats.cacheWriteTokens,
|
|
61
|
+
outputTokens: stats.outputTokens,
|
|
62
|
+
costMicroUsd: stats.costMicroUsd,
|
|
63
|
+
...(stats.usageMissing === true ? { usageMissing: true } : {}),
|
|
64
|
+
...(telemetry.unpricedSpend ? { unpriced: true } : {}),
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
: {}),
|
|
68
|
+
});
|
|
69
|
+
const trace = deps.tracer;
|
|
70
|
+
try {
|
|
71
|
+
const compactionModel = compactionSummaryIsDerived(req.compactionModel !== undefined, named) ? await compactionSummaryFallback({ derived: named, primary: resolved.model, brain: deps.brain, getApiKeyAndHeaders: req.getApiKeyAndHeaders, onNotice: deps.onNotice, sessionId }) : named;
|
|
72
|
+
const branch = await session.getBranch();
|
|
73
|
+
const contextMessages = convertToLlm((await session.buildContext()).messages);
|
|
74
|
+
bindSessionFacade(legMods, { deps, req, model: resolved.model, messages: contextMessages, book });
|
|
75
|
+
const overlay = contextOverlayFor(deps.contextSettings, resolved.modelRef, deps);
|
|
76
|
+
const activeTools = compactionActivationSnapshot(branch);
|
|
77
|
+
const thinking = resolved.thinking ?? resolved.model.defaultThinking;
|
|
78
|
+
const comp = await maybeCompact({
|
|
79
|
+
session,
|
|
80
|
+
model: resolved.model,
|
|
81
|
+
...(overlay !== undefined ? { contextOverlay: overlay } : {}),
|
|
82
|
+
...(compactionModel !== undefined ? { compactionModel } : {}),
|
|
83
|
+
brain: derivedLegBrain(() => deps.brain, "compaction", book),
|
|
84
|
+
...(req.getApiKeyAndHeaders !== undefined ? { getApiKeyAndHeaders: req.getApiKeyAndHeaders } : {}),
|
|
85
|
+
...(thinking !== undefined ? { thinking } : {}),
|
|
86
|
+
settings: legCompactionSettings(req.compaction !== undefined ? { compaction: req.compaction } : {}, overlay),
|
|
87
|
+
customInstructions: req.instructions ?? req.compaction?.instructions ?? DEFAULT_COMPACTION_INSTRUCTIONS,
|
|
88
|
+
...(req.signal !== undefined ? { signal: req.signal, manualCancelSignal: req.signal } : {}),
|
|
89
|
+
minTokens: 0,
|
|
90
|
+
force: true,
|
|
91
|
+
onInputTruncated: emitInputTruncated(trace, sessionId),
|
|
92
|
+
...(activeTools.length > 0 ? { activeTools } : {}),
|
|
93
|
+
...summaryProviderOptions({ deps }, 0),
|
|
94
|
+
...compactionHookOptions({ deps }, { modBus: legMods.bus, hookIdentity: undefined, sessionId }, "manual", req.signal),
|
|
95
|
+
onStarted: passReport.onStarted,
|
|
96
|
+
});
|
|
97
|
+
const outcome = manualCompactOutcomeOf(comp);
|
|
98
|
+
if (comp.compacted) {
|
|
99
|
+
events.push(mintCompactedEvent(comp, "manual", ident()));
|
|
100
|
+
return answer(outcome);
|
|
101
|
+
}
|
|
102
|
+
if (comp.blocked)
|
|
103
|
+
emitTrace(trace, () => ({ kind: "compaction.blocked", version: 1, taskId: sessionId, trigger: "manual", ts: Date.now() }));
|
|
104
|
+
else if (comp.disabled)
|
|
105
|
+
emitTrace(trace, () => ({ kind: "compaction.disabled", version: 1, taskId: sessionId, ts: Date.now() }));
|
|
106
|
+
else
|
|
107
|
+
emitTrace(trace, () => ({ kind: "compaction.noop", version: 1, taskId: sessionId, ts: Date.now() }));
|
|
108
|
+
events.push({ type: "compaction_outcome", outcome: outcome, trigger: "manual", ...ident() });
|
|
109
|
+
return answer(outcome);
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
if (isCompactionManualCancel(err)) {
|
|
113
|
+
emitTrace(trace, () => ({ kind: "compaction.mooted", version: 1, taskId: sessionId, reason: "cancelled", ts: Date.now() }));
|
|
114
|
+
events.push({ type: "compaction_outcome", outcome: "mooted", trigger: "manual", reason: "cancelled", ...passReport.end, ...ident() });
|
|
115
|
+
return answer("mooted");
|
|
116
|
+
}
|
|
117
|
+
deps.onError?.(asError(err), { phase: "compaction", sessionId });
|
|
118
|
+
const reason = compactionFailureReason(err);
|
|
119
|
+
emitTrace(trace, () => ({ kind: "compaction.failed", version: 1, taskId: sessionId, trigger: "manual", reason, ts: Date.now() }));
|
|
120
|
+
events.push({ type: "compaction_outcome", outcome: "failed", trigger: "manual", reason, ...passReport.end, ...ident() });
|
|
121
|
+
return answer("failed");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function bindSessionFacade(legMods, input) {
|
|
125
|
+
const unavailable = (method) => {
|
|
126
|
+
throw new Error(`${method}: not available on a session-level compaction (${VERB}) — there is no run, so no execution environment, working directory, tool roster or agent listing`);
|
|
127
|
+
};
|
|
128
|
+
const seats = legFacadeSeats({
|
|
129
|
+
deps: input.deps,
|
|
130
|
+
spec: input.req.getApiKeyAndHeaders !== undefined ? { getApiKeyAndHeaders: input.req.getApiKeyAndHeaders } : {},
|
|
131
|
+
sessionId: input.req.sessionId,
|
|
132
|
+
model: input.model,
|
|
133
|
+
executionEnv: { exec: () => unavailable("process.run") },
|
|
134
|
+
taskRoot: "",
|
|
135
|
+
cwdRef: undefined,
|
|
136
|
+
lastBrainContext: () => ({ messages: input.messages }),
|
|
137
|
+
activeTools: new Set(),
|
|
138
|
+
agentListing: undefined,
|
|
139
|
+
book: (answeredBy, reply) => input.book("mod", answeredBy, reply),
|
|
140
|
+
toolCall: () => unavailable("tool.call"),
|
|
141
|
+
});
|
|
142
|
+
legMods.bindFacade({
|
|
143
|
+
...seats,
|
|
144
|
+
cwd: () => unavailable("session.cwd"),
|
|
145
|
+
root: () => unavailable("session.root"),
|
|
146
|
+
tools: () => unavailable("tool.list"),
|
|
147
|
+
agents: () => unavailable("agent.list"),
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function asError(err) {
|
|
151
|
+
return err instanceof Error ? err : new Error(egressThrownText("same-principal", err));
|
|
152
|
+
}
|
|
153
|
+
function screenCompactSessionRequest(request) {
|
|
154
|
+
const bad = (what) => {
|
|
155
|
+
const e = new Error(`${VERB}: ${what} — nothing was compacted. The request is { sessionId, model, instructions?, compaction?, compactionModel?, getApiKeyAndHeaders?, signal? }.`);
|
|
156
|
+
e.code = "compact.invalid_request";
|
|
157
|
+
throw e;
|
|
158
|
+
};
|
|
159
|
+
const { sessionId, model, instructions, compaction, compactionModel, getApiKeyAndHeaders, signal } = readPlainRequest(request, REQUEST_KEYS, bad);
|
|
160
|
+
if (typeof sessionId !== "string" || sessionId === "")
|
|
161
|
+
return bad(`sessionId must be a non-empty string, got ${shownValue(sessionId)}`);
|
|
162
|
+
if (model === undefined)
|
|
163
|
+
return bad("model is required — the model the session's next turn runs on, whose window bounds the pass");
|
|
164
|
+
if (instructions !== undefined && typeof instructions !== "string")
|
|
165
|
+
return bad(`instructions must be a string when given, got ${shownValue(instructions)}`);
|
|
166
|
+
if (getApiKeyAndHeaders !== undefined && typeof getApiKeyAndHeaders !== "function")
|
|
167
|
+
return bad(`getApiKeyAndHeaders must be a function when given, got ${shownValue(getApiKeyAndHeaders)}`);
|
|
168
|
+
if (signal !== undefined && !(signal instanceof AbortSignal))
|
|
169
|
+
return bad(`signal must be an AbortSignal when given, got ${shownValue(signal)}`);
|
|
170
|
+
return {
|
|
171
|
+
sessionId,
|
|
172
|
+
model: model,
|
|
173
|
+
instructions,
|
|
174
|
+
compaction: compaction === undefined ? undefined : screenSettings(compaction, bad),
|
|
175
|
+
compactionModel: compactionModel,
|
|
176
|
+
getApiKeyAndHeaders: getApiKeyAndHeaders,
|
|
177
|
+
signal,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function screenSettings(raw, bad) {
|
|
181
|
+
const { enabled, reserveTokens, keepRecentTokens, instructions, clampTolerance } = readPlainRequest(raw, SETTINGS_KEYS, (what) => bad(`compaction: ${what}`));
|
|
182
|
+
if (enabled !== undefined && typeof enabled !== "boolean")
|
|
183
|
+
return bad(`compaction.enabled must be a boolean when given, got ${shownValue(enabled)}`);
|
|
184
|
+
for (const [name, v] of [["reserveTokens", reserveTokens], ["keepRecentTokens", keepRecentTokens], ["clampTolerance", clampTolerance]]) {
|
|
185
|
+
if (v !== undefined && typeof v !== "number")
|
|
186
|
+
return bad(`compaction.${name} must be a number when given, got ${shownValue(v)}`);
|
|
187
|
+
}
|
|
188
|
+
if (instructions !== undefined && typeof instructions !== "string")
|
|
189
|
+
return bad(`compaction.instructions must be a string when given, got ${shownValue(instructions)}`);
|
|
190
|
+
return {
|
|
191
|
+
...(enabled !== undefined ? { enabled: enabled } : {}),
|
|
192
|
+
...(reserveTokens !== undefined ? { reserveTokens: reserveTokens } : {}),
|
|
193
|
+
...(keepRecentTokens !== undefined ? { keepRecentTokens: keepRecentTokens } : {}),
|
|
194
|
+
...(instructions !== undefined ? { instructions: instructions } : {}),
|
|
195
|
+
...(clampTolerance !== undefined ? { clampTolerance: clampTolerance } : {}),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function sessionBusyRefusal(sessionId) {
|
|
199
|
+
const e = new Error(`${VERB}: a task is running or queued on session "${sessionId}" in this Runner, or a write one of its tasks issued has not settled — compacting it now would rewrite the transcript under that work, so nothing was compacted; a running task takes the request through its own stream (TaskStream.compact), otherwise retry once it has ended and its writes have settled`);
|
|
200
|
+
e.code = "compact.session_busy";
|
|
201
|
+
return e;
|
|
202
|
+
}
|
|
@@ -156,7 +156,7 @@ export declare function emitInputTruncated(tracer: TracerHook | undefined, taskI
|
|
|
156
156
|
*/
|
|
157
157
|
export declare function legContextOverlayOption(prepared: Prepared, runner: RunnerDepsSeat): Pick<MaybeCompactOptions, "contextOverlay">;
|
|
158
158
|
/**
|
|
159
|
-
* The compaction SETTINGS a pass runs under — the assembly all three lanes share.
|
|
159
|
+
* The compaction SETTINGS a pass runs under — the assembly all three lanes and the out-of-run `Runner.compactSession` share.
|
|
160
160
|
*
|
|
161
161
|
* `{ ...DEFAULT_COMPACTION_SETTINGS, ...spec.compaction }` was hand-copied at each lane, and it is where the
|
|
162
162
|
* deployment's live `enabled` declaration belongs: `maybeCompact` has exactly one enablement gate (it reads
|
|
@@ -165,4 +165,4 @@ export declare function legContextOverlayOption(prepared: Prepared, runner: Runn
|
|
|
165
165
|
* compaction runs" a single expression ({@link compactionEnabled}: the request authored it > the deployment
|
|
166
166
|
* declared it > on).
|
|
167
167
|
*/
|
|
168
|
-
export declare function legCompactionSettings(spec: TaskSpec, overlay: ContextWindowOverlay | undefined): CompactionSettings;
|
|
168
|
+
export declare function legCompactionSettings(spec: Pick<TaskSpec, "compaction">, overlay: ContextWindowOverlay | undefined): CompactionSettings;
|
|
@@ -3,10 +3,10 @@ import { type PostureFacts } from "../auto-mode-directive.js";
|
|
|
3
3
|
import type { Prepared } from "./contracts.js";
|
|
4
4
|
/**
|
|
5
5
|
* The facts the posture composition reads, as the leg IS now: the live effective mode and ask answer, the plan-exit
|
|
6
|
-
* tool's presence on the minted roster,
|
|
6
|
+
* tool's presence on the minted roster, the minted delegation identity, and the session plan file the run admitted. The one place a leg's facts are assembled —
|
|
7
7
|
* the leg's first turn, a resumed continuation, a continuing boundary and a landed compaction all ask through it.
|
|
8
8
|
*/
|
|
9
|
-
export declare function postureFactsOf(prepared: Pick<Prepared, "approvalPosture" | "toolRoster" | "hookIdentity">): PostureFacts;
|
|
9
|
+
export declare function postureFactsOf(prepared: Pick<Prepared, "approvalPosture" | "toolRoster" | "hookIdentity" | "advertisedWritableDirs">): PostureFacts;
|
|
10
10
|
/**
|
|
11
11
|
* The posture question, asked of the ACTIVE context: the frames the leg's mode facts owe now (exits of retired
|
|
12
12
|
* families, the owed frame or its cadence's restatement — `composePostureFrames`), minted as one carrier text —
|
|
@@ -18,7 +18,7 @@ export declare function postureFactsOf(prepared: Pick<Prepared, "approvalPosture
|
|
|
18
18
|
* function's own carriers and a landed compaction (which asks with `"always"`). A context that cannot be read
|
|
19
19
|
* answers "nothing standing": the owed frame is restated rather than withheld.
|
|
20
20
|
*/
|
|
21
|
-
export declare function owedPostureText(prepared: Pick<Prepared, "approvalPosture" | "toolRoster" | "hookIdentity" | "session" | "reminderMark" | "postureFrameRef">, ask: "always" | "on_change"): Promise<string | undefined>;
|
|
21
|
+
export declare function owedPostureText(prepared: Pick<Prepared, "approvalPosture" | "toolRoster" | "hookIdentity" | "advertisedWritableDirs" | "session" | "reminderMark" | "postureFrameRef">, ask: "always" | "on_change"): Promise<string | undefined>;
|
|
22
22
|
/** The posture's COMPACTION arm: after a landed compaction the runner asks the posture question of the compacted
|
|
23
23
|
* context and appends what it owes as one engine-minted message, before any reader of the new baseline (the next
|
|
24
24
|
* model request included). A leg that owes no posture registers nothing: a compaction only REMOVES frames, and a
|
|
@@ -35,7 +35,7 @@ export declare function postureRestateOption(prepared: Prepared): Pick<MaybeComp
|
|
|
35
35
|
* of every engine frame written at a boundary, the git frame's re-assert and the compaction itself: the run continues
|
|
36
36
|
* and the failure is reported, `onError` phase `degraded`). Never throws.
|
|
37
37
|
*/
|
|
38
|
-
export declare function appendOwedPosture(prepared: Pick<Prepared, "approvalPosture" | "toolRoster" | "hookIdentity" | "session" | "reminderMark" | "postureFrameRef" | "batchHaltRef" | "frameReceipts">, ask: "always" | "on_change"): Promise<void>;
|
|
38
|
+
export declare function appendOwedPosture(prepared: Pick<Prepared, "approvalPosture" | "toolRoster" | "hookIdentity" | "advertisedWritableDirs" | "session" | "reminderMark" | "postureFrameRef" | "batchHaltRef" | "frameReceipts">, ask: "always" | "on_change"): Promise<void>;
|
|
39
39
|
/** The declared output style's frame as one engine-marked reminder — the one spelling every site that states it directly
|
|
40
40
|
* (a resumed leg's continuation, a boundary a queued input continues) mints. */
|
|
41
41
|
export declare function mintOutputStyleReminder(prepared: Pick<Prepared, "outputStyleFrame" | "reminderMark">): string | undefined;
|
|
@@ -49,6 +49,15 @@ export declare function frameCarried(ledger: Prepared["frameReceipts"], source:
|
|
|
49
49
|
* carries it ({@link frameCarried}). Both frames keep the posture's halt rule. The guarantee is read synchronously, at
|
|
50
50
|
* the call, before any await — a boundary with nothing queued returns the posture's own promise.
|
|
51
51
|
*/
|
|
52
|
-
export declare function appendBoundaryFrames(prepared: Pick<Prepared, "approvalPosture" | "toolRoster" | "hookIdentity" | "session" | "reminderMark" | "postureFrameRef" | "batchHaltRef" | "outputStyleFrame" | "harness" | "frameReceipts">, turnOwesRequest: boolean): Promise<void>;
|
|
52
|
+
export declare function appendBoundaryFrames(prepared: Pick<Prepared, "approvalPosture" | "toolRoster" | "hookIdentity" | "advertisedWritableDirs" | "session" | "reminderMark" | "postureFrameRef" | "batchHaltRef" | "outputStyleFrame" | "harness" | "frameReceipts">, turnOwesRequest: boolean): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* The session plan file's post-compaction reference (the reference's `plan_file_reference`, CC 2.1.309 `Tmr` (cli309.js:265943)): a compaction
|
|
55
|
+
* summarizes away the turns that wrote the plan, so a leg whose run admitted a plan file that holds a plan is told where
|
|
56
|
+
* it is and what it says, in any mode — the reference's own sentences, the plan fenced as the untrusted model text it is.
|
|
57
|
+
* Read through the seat's one reader; an absent or blank file says nothing (there is no plan to refer to), and an
|
|
58
|
+
* unreadable one is not guessed at. One engine-minted message, appended like the posture's; a failed append is reported
|
|
59
|
+
* and never fails the landed compaction.
|
|
60
|
+
*/
|
|
61
|
+
export declare function planFileRestateOption(prepared: Prepared): Pick<MaybeCompactOptions, "planFileRestate">;
|
|
53
62
|
/** Every post-compaction restatement the turn boundary registers, at one spread site. */
|
|
54
|
-
export declare function compactionRestateOptions(prepared: Prepared): Pick<MaybeCompactOptions, "gitRestate" | "postureRestate" | "advisorRestate">;
|
|
63
|
+
export declare function compactionRestateOptions(prepared: Prepared): Pick<MaybeCompactOptions, "gitRestate" | "postureRestate" | "planFileRestate" | "advisorRestate">;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { composePostureFrames, owedPostureRow, postureStandingOf } from "../auto-mode-directive.js";
|
|
2
|
+
import { planFileShown } from "./advertised-writable-dirs.js";
|
|
2
3
|
import { PRESENT_PLAN_TOOL_NAME } from "../present-plan-tool.js";
|
|
3
4
|
import { mintSystemReminder } from "../reminder-mint.js";
|
|
4
5
|
import { thrownText } from "../thrown-value.js";
|
|
5
6
|
import { rosterEntryNamed } from "../tool-roster.js";
|
|
6
|
-
import { sanitizeUntrustedText } from "../untrusted-text.js";
|
|
7
|
+
import { delimitUntrusted, sanitizeUntrustedText } from "../untrusted-text.js";
|
|
7
8
|
import { appendAdvisorRestate } from "./advisor-instructions.js";
|
|
8
9
|
import { gitRestateOption } from "./git-leg-delivery.js";
|
|
9
10
|
import { attachmentEnvelopeTags } from "./turn-attachments.js";
|
|
@@ -13,6 +14,7 @@ export function postureFactsOf(prepared) {
|
|
|
13
14
|
askEffective: prepared.approvalPosture.askEffective,
|
|
14
15
|
exitToolMounted: rosterEntryNamed(prepared.toolRoster, PRESENT_PLAN_TOOL_NAME) !== undefined,
|
|
15
16
|
isChildLeg: prepared.hookIdentity.isDelegatedChild,
|
|
17
|
+
...(prepared.advertisedWritableDirs?.planFile !== undefined ? { planFile: planFileShown(prepared.advertisedWritableDirs.planFile.spelled) } : {}),
|
|
16
18
|
};
|
|
17
19
|
}
|
|
18
20
|
export async function owedPostureText(prepared, ask) {
|
|
@@ -99,6 +101,30 @@ export function appendBoundaryFrames(prepared, turnOwesRequest) {
|
|
|
99
101
|
const posture = appendOwedPosture(prepared, "on_change");
|
|
100
102
|
return styleOwed ? posture.then(() => appendOutputStyleRestate(prepared)) : posture;
|
|
101
103
|
}
|
|
104
|
+
export function planFileRestateOption(prepared) {
|
|
105
|
+
const seat = prepared.advertisedWritableDirs;
|
|
106
|
+
const planFile = seat?.planFile;
|
|
107
|
+
if (seat === undefined || planFile === undefined)
|
|
108
|
+
return {};
|
|
109
|
+
return {
|
|
110
|
+
planFileRestate: async () => {
|
|
111
|
+
const read = await seat.readPlanFile();
|
|
112
|
+
if (!read.ok || read.text === undefined)
|
|
113
|
+
return;
|
|
114
|
+
const body = `A plan file exists from plan mode at: ${planFileShown(planFile.spelled)}\n\nPlan contents:\n\n${delimitUntrusted("plan", read.text)}\n\nIf this plan is relevant to the current work and not already complete, continue working on it.`;
|
|
115
|
+
try {
|
|
116
|
+
await prepared.session.appendMessage({ role: "user", content: [{ type: "text", text: mintSystemReminder(body, prepared.reminderMark) }], timestamp: Date.now(), engineMinted: true });
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
try {
|
|
120
|
+
prepared.postureFrameRef.report?.(new Error(`the plan file reference could not be written to the transcript after the compaction: ${thrownText(err)}`));
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
102
128
|
export function compactionRestateOptions(prepared) {
|
|
103
|
-
return { ...gitRestateOption(prepared), ...postureRestateOption(prepared), ...(prepared.advisorInstruction?.mounted === true ? { advisorRestate: () => appendAdvisorRestate(prepared) } : {}) };
|
|
129
|
+
return { ...gitRestateOption(prepared), ...postureRestateOption(prepared), ...planFileRestateOption(prepared), ...(prepared.advisorInstruction?.mounted === true ? { advisorRestate: () => appendAdvisorRestate(prepared) } : {}) };
|
|
104
130
|
}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The run loop's COMPACTION SEAMS, verbatim from three private methods of `Runner`: the Seam C
|
|
3
|
+
* cost-optimization options every `maybeCompact` call site spreads, the pre/postCompact hook-option wrapper and
|
|
4
|
+
* the consecutive-reuse counter fold. Layer-1 machinery under a name of its own (the S1 reading: a module the lanes stand
|
|
5
|
+
* on is not a lane) — the turn-boundary lane, the recovery lane and the terminal adoption's end-of-task pass reach DOWN
|
|
6
|
+
* for these three where the driver used to hand each lane the methods as delegates on its Input. Every function reads
|
|
7
|
+
* the Runner's deps LIVE through {@link RunnerDepsSeat}: `runner.deps.x` here is exactly `this.deps.x` in the method it
|
|
8
|
+
* came from, on the tick it is read.
|
|
9
|
+
*/
|
|
10
|
+
import type { HookInvocationIdentity } from "../hooks.js";
|
|
1
11
|
import type { MaybeCompactOptions } from "../auto-compaction.js";
|
|
12
|
+
import { type LegModBus } from "../mods/stations.js";
|
|
2
13
|
import type { Prepared, RunnerDepsSeat } from "./contracts.js";
|
|
3
14
|
/**
|
|
4
15
|
* The cost-optimization compaction options threaded into BOTH `maybeCompact` call
|
|
@@ -12,6 +23,11 @@ import type { Prepared, RunnerDepsSeat } from "./contracts.js";
|
|
|
12
23
|
* function itself always returns an object.
|
|
13
24
|
*/
|
|
14
25
|
export declare function seamCCompactionOptions(runner: RunnerDepsSeat, prepared: Prepared): Pick<MaybeCompactOptions, "summaryProvider" | "onCompaction" | "maxConsecutiveProviderReuse" | "consecutiveProviderReuse" | "onCommitted">;
|
|
26
|
+
/** The Seam C PROVIDER half — the deployment's summary provider, its observer and its drift guard, fed the caller's
|
|
27
|
+
* consecutive-reuse count (a run's counter; `0` for a pass outside a run, which has no earlier reuse to count). Still
|
|
28
|
+
* provider-gated: with no provider wired the four keys stay ABSENT, so every caller spreads exactly what it spread
|
|
29
|
+
* before. */
|
|
30
|
+
export declare function summaryProviderOptions(runner: RunnerDepsSeat, consecutive: number): Pick<MaybeCompactOptions, "summaryProvider" | "onCompaction" | "maxConsecutiveProviderReuse" | "consecutiveProviderReuse">;
|
|
15
31
|
/** The pre/postCompact stations threaded into maybeCompact: `classic.PreCompact` and `classic.PostCompact` raised on the
|
|
16
32
|
* leg's bus (a station is wired only when a handler hangs on its event). Their failure and abort columns are the
|
|
17
33
|
* bus's — a handler that throws or runs past its budget is skipped and reported, so a failed gate is "no block, no
|
|
@@ -19,7 +35,11 @@ export declare function seamCCompactionOptions(runner: RunnerDepsSeat, prepared:
|
|
|
19
35
|
* trigger is reported as ignored (maybeCompact enforces the ignore — blocking a compaction the provider/trim layer
|
|
20
36
|
* already demanded would kill the run). `signal` is the pass's abort (absent ⇒ each handler's own budget is the
|
|
21
37
|
* whole bound). */
|
|
22
|
-
export declare function compactionHookOptions(runner: RunnerDepsSeat, prepared:
|
|
38
|
+
export declare function compactionHookOptions(runner: RunnerDepsSeat, prepared: {
|
|
39
|
+
readonly modBus: LegModBus;
|
|
40
|
+
readonly hookIdentity: HookInvocationIdentity | undefined;
|
|
41
|
+
readonly sessionId: string;
|
|
42
|
+
}, trigger: "auto" | "manual" | "forced", signal: AbortSignal | undefined): Pick<MaybeCompactOptions, "trigger" | "preCompact" | "postCompact">;
|
|
23
43
|
/** Fold a finished compaction's `reused` flag into the run-scoped consecutive-reuse
|
|
24
44
|
* counter: a reused (provider) summary increments it, a real (LLM) summary resets it to 0. A no-op
|
|
25
45
|
* compaction (`compacted:false`) leaves the counter untouched. No-op when no provider is wired. */
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { classicEventBase, dispatchClassic, observeClassic, stringMembersAnswer, stringMembersOf } from "../mods/stations.js";
|
|
2
2
|
export function seamCCompactionOptions(runner, prepared) {
|
|
3
3
|
return {
|
|
4
|
-
...(runner.
|
|
5
|
-
? {
|
|
6
|
-
summaryProvider: runner.deps.summaryProvider,
|
|
7
|
-
onCompaction: runner.deps.onCompaction,
|
|
8
|
-
maxConsecutiveProviderReuse: runner.deps.maxConsecutiveProviderReuse,
|
|
9
|
-
consecutiveProviderReuse: prepared.compactionReuseRef.consecutive,
|
|
10
|
-
}
|
|
11
|
-
: {}),
|
|
4
|
+
...summaryProviderOptions(runner, prepared.compactionReuseRef.consecutive),
|
|
12
5
|
onCommitted: (effect) => {
|
|
13
6
|
if (prepared.frameSettlement.wantsEffects?.() !== true)
|
|
14
7
|
return;
|
|
@@ -16,6 +9,16 @@ export function seamCCompactionOptions(runner, prepared) {
|
|
|
16
9
|
},
|
|
17
10
|
};
|
|
18
11
|
}
|
|
12
|
+
export function summaryProviderOptions(runner, consecutive) {
|
|
13
|
+
return runner.deps.summaryProvider
|
|
14
|
+
? {
|
|
15
|
+
summaryProvider: runner.deps.summaryProvider,
|
|
16
|
+
onCompaction: runner.deps.onCompaction,
|
|
17
|
+
maxConsecutiveProviderReuse: runner.deps.maxConsecutiveProviderReuse,
|
|
18
|
+
consecutiveProviderReuse: consecutive,
|
|
19
|
+
}
|
|
20
|
+
: {};
|
|
21
|
+
}
|
|
19
22
|
export function compactionHookOptions(runner, prepared, trigger, signal) {
|
|
20
23
|
const bus = prepared.modBus;
|
|
21
24
|
const base = classicEventBase(prepared.hookIdentity);
|