@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
|
@@ -3,20 +3,22 @@ import { randomUUID } from "node:crypto";
|
|
|
3
3
|
import { closeSync, constants, createReadStream, mkdtempSync, openSync, readSync, rmSync, statSync, truncateSync, unlinkSync } from "node:fs";
|
|
4
4
|
import { access, appendFile, lstat, mkdir, mkdtemp, open, readdir, readFile, readlink, rename, rm, stat, unlink, writeFile, } from "node:fs/promises";
|
|
5
5
|
import { tmpdir } from "node:os";
|
|
6
|
-
import { isAbsolute, join,
|
|
6
|
+
import { dirname, isAbsolute, join, sep } from "node:path";
|
|
7
7
|
import { createInterface } from "node:readline";
|
|
8
8
|
import { ExecutionError, err, FileError, ok, toError, } from "../harness/types.js";
|
|
9
9
|
import { killProcessTree, shutdownDebug } from "./kill-tree.js";
|
|
10
10
|
import { __resetSecretEnvScrubNoticeAnnouncement, announceSecretEnvScrub, inheritEnvPolicyProblem, inheritedHostEnv } from "../../core/secret-env.js";
|
|
11
11
|
import { physicalPathOfAsync } from "../../core/physical-path.js";
|
|
12
12
|
import { posixModeBitsMeaningful } from "../../core/posix-mode-face.js";
|
|
13
|
-
import { walkSymlinkChain } from "./symlink-chain.js";
|
|
13
|
+
import { anchorAtLinkDir, walkSymlinkChain } from "./symlink-chain.js";
|
|
14
14
|
import { RollingTailBuffer, markTruncated, newStreamCursorState, sliceStreamIncrement, } from "../../core/exec-output-tail.js";
|
|
15
15
|
import { BackgroundShellError } from "../../core/background-shell.js";
|
|
16
16
|
import { SchedulerError } from "../../core/scheduler.js";
|
|
17
17
|
const MAX_TIMER_TIMEOUT_MS = 2_147_000_000;
|
|
18
18
|
function resolvePath(cwd, path) {
|
|
19
|
-
|
|
19
|
+
if (isAbsolute(path))
|
|
20
|
+
return path;
|
|
21
|
+
return anchorAtLinkDir(isAbsolute(cwd) ? cwd : anchorAtLinkDir(process.cwd(), cwd, sep), path, sep);
|
|
20
22
|
}
|
|
21
23
|
export function resolveExecTimeoutMs(timeoutSeconds) {
|
|
22
24
|
if (typeof timeoutSeconds !== "number" ||
|
|
@@ -396,7 +398,9 @@ export class NodeExecutionEnv {
|
|
|
396
398
|
return ok(resolvePath(this.cwd, path));
|
|
397
399
|
}
|
|
398
400
|
async joinPath(parts) {
|
|
399
|
-
|
|
401
|
+
const leading = sep === "\\" ? /^[\\/]+/ : /^\/+/;
|
|
402
|
+
const named = parts.map((part, i) => (i === 0 ? part : part.replace(leading, ""))).filter((part) => part !== "");
|
|
403
|
+
return ok(named.length === 0 ? "." : named.reduce((at, part) => anchorAtLinkDir(at, part, sep)));
|
|
400
404
|
}
|
|
401
405
|
async exec(command, options) {
|
|
402
406
|
if (options?.abortSignal?.aborted) {
|
|
@@ -831,7 +835,7 @@ export class NodeExecutionEnv {
|
|
|
831
835
|
return aborted;
|
|
832
836
|
}
|
|
833
837
|
try {
|
|
834
|
-
await mkdir(
|
|
838
|
+
await mkdir(dirname(resolved), { recursive: true });
|
|
835
839
|
}
|
|
836
840
|
catch (error) {
|
|
837
841
|
return err(toFileError(error, resolved));
|
|
@@ -854,8 +858,8 @@ export class NodeExecutionEnv {
|
|
|
854
858
|
let hop;
|
|
855
859
|
try {
|
|
856
860
|
const link = await readlink(resolved);
|
|
857
|
-
const parentReal = await physicalPathOfAsync(
|
|
858
|
-
hop = isAbsolute(link) ? link :
|
|
861
|
+
const parentReal = await physicalPathOfAsync(dirname(resolved)).catch(() => dirname(resolved));
|
|
862
|
+
hop = isAbsolute(link) ? link : anchorAtLinkDir(parentReal, link, sep);
|
|
859
863
|
}
|
|
860
864
|
catch {
|
|
861
865
|
hop = undefined;
|
|
@@ -956,7 +960,7 @@ export class NodeExecutionEnv {
|
|
|
956
960
|
return aborted;
|
|
957
961
|
}
|
|
958
962
|
try {
|
|
959
|
-
await mkdir(
|
|
963
|
+
await mkdir(dirname(resolved), { recursive: true });
|
|
960
964
|
}
|
|
961
965
|
catch (error) {
|
|
962
966
|
return err(toFileError(error, resolved));
|
|
@@ -979,7 +983,7 @@ export class NodeExecutionEnv {
|
|
|
979
983
|
async appendFile(path, content) {
|
|
980
984
|
const resolved = resolvePath(this.cwd, path);
|
|
981
985
|
try {
|
|
982
|
-
await mkdir(
|
|
986
|
+
await mkdir(dirname(resolved), { recursive: true });
|
|
983
987
|
await appendFile(resolved, content);
|
|
984
988
|
return ok(undefined);
|
|
985
989
|
}
|
|
@@ -1036,7 +1040,7 @@ export class NodeExecutionEnv {
|
|
|
1036
1040
|
if (loopAbort) {
|
|
1037
1041
|
return loopAbort;
|
|
1038
1042
|
}
|
|
1039
|
-
const entryPath =
|
|
1043
|
+
const entryPath = anchorAtLinkDir(resolved, entry.name, sep);
|
|
1040
1044
|
try {
|
|
1041
1045
|
const info = fileInfoFromStats(entryPath, await lstat(entryPath));
|
|
1042
1046
|
if (info.ok) {
|
|
@@ -1152,7 +1156,7 @@ export class NodeExecutionEnv {
|
|
|
1152
1156
|
const loopAbort = abortResult(abortSignal, resolved);
|
|
1153
1157
|
if (loopAbort)
|
|
1154
1158
|
return loopAbort;
|
|
1155
|
-
const info = fileInfoFromStats(
|
|
1159
|
+
const info = fileInfoFromStats(anchorAtLinkDir(resolved, entry.name, sep), await lstat(anchorAtLinkDir(listed, entry.name, sep)));
|
|
1156
1160
|
if (info.ok)
|
|
1157
1161
|
infos.push(info.value);
|
|
1158
1162
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { type FileError, type Result, type SymlinkChain } from "../harness/types.js";
|
|
2
2
|
/**
|
|
3
|
-
* Anchor a RELATIVE
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
3
|
+
* Anchor a RELATIVE spelling at a directory, UNFOLDED, with exactly one separator between the two — the one anchor of
|
|
4
|
+
* this environment: a symlink target at its link's own directory (the walk below), a path at the environment's `cwd`
|
|
5
|
+
* and a name under the directory that holds it (`NodeExecutionEnv`'s every member). A root directory (`/`, `C:\`,
|
|
6
|
+
* `\\host\share\`) already ends in its own separator, and a second one mints a spelling (`//private/tmp`) that no
|
|
7
|
+
* guarded row matches; `path.resolve`/`join` would fix the separator and fold `..`, which no reader of a path may do —
|
|
8
|
+
* a `..` is the filesystem's to resolve. `separator` is the one the caller's `dirname` writes (a pure function of its
|
|
9
|
+
* inputs); a backslash terminates only where it IS a separator — on a POSIX tree `/a/b\` is an ordinary name.
|
|
8
10
|
*/
|
|
9
11
|
export declare function anchorAtLinkDir(linkDir: string, target: string, separator: string): string;
|
|
10
12
|
/** The walk's bound (the reference CLI's own); the terminal canonicalizer refuses at 16, so this only bounds what is REPORTED. */
|
|
@@ -4,6 +4,7 @@ import { runToolCall, type ExecutedToolCallOutcome } from "../loop/agent-loop.js
|
|
|
4
4
|
import type { HaltRemainingDirective } from "../loop/types.js";
|
|
5
5
|
import type { AgentMessage, AgentTool, AgentToolCall, LoopMalformedToolUseRecovery, LoopThinkingOnlyRecovery, LoopTruncatedOutputRecovery, QueueMode, ThinkingLevel } from "../loop/types.js";
|
|
6
6
|
import { type EngineSegment } from "../../core/untrusted-text.js";
|
|
7
|
+
import { type RunOrigin } from "../../core/run-origin.js";
|
|
7
8
|
import type { CommittedFrameCarrier } from "../../core/frame-settlement.js";
|
|
8
9
|
import type { AbortResult, AgentHarnessEvent, AgentHarnessEventResultMap, AgentHarnessOptions, AgentHarnessOwnEvent, AgentHarnessResources, AgentHarnessStreamOptions, ExecutionEnv, PromptTemplate, Skill } from "./types.js";
|
|
9
10
|
/** [c209-C] 收口 C1/C2 — engine-provenance metadata a caller can stamp on the user message it
|
|
@@ -34,10 +35,11 @@ export interface HaltConsumption {
|
|
|
34
35
|
export interface TrailingToolBatchOptions {
|
|
35
36
|
readonly halt?: HaltRemainingDirective;
|
|
36
37
|
}
|
|
37
|
-
/** `prompt()` option: called
|
|
38
|
-
*
|
|
39
|
-
* caller then still owns whatever the
|
|
40
|
-
|
|
38
|
+
/** `prompt()` option: the prompt's own receipt — called with the entry id once the prompt's user message is in the
|
|
39
|
+
* session (its append returned), before its `message_end` is published. Not called when the append fails or when a
|
|
40
|
+
* trailing-batch settlement ends the run before the prompt is delivered — the caller then still owns whatever the
|
|
41
|
+
* prompt was carrying. */
|
|
42
|
+
export type PromptCommittedCallback = (entryId: string) => void;
|
|
41
43
|
/** An engine-minted message that TRAILS the prompt's human message in the same request (a user-attachment frame):
|
|
42
44
|
* minted from its content blocks, always an engine note, carrying its delivery record. */
|
|
43
45
|
export interface TrailingMessageSeed {
|
|
@@ -84,6 +86,10 @@ export interface UserMessageProvenance {
|
|
|
84
86
|
* projection point `projectHumanInput`) BEFORE the frame wrapping — the harness never rewrites
|
|
85
87
|
* text, so annotation stays adjacent to the frame it attributes. */
|
|
86
88
|
actor?: ActorAssertion;
|
|
89
|
+
/** What brought the one input this message carries ({@link UserMessage.runOrigin}) — the caller passes it with a message
|
|
90
|
+
* that carries a single input only. Threaded onto the message when it is a member of the closed set; anything else is
|
|
91
|
+
* omitted at the mint. */
|
|
92
|
+
runOrigin?: RunOrigin;
|
|
87
93
|
/** backlog #389 — an OPAQUE record the caller rides on a CALLER-AUTHORED queued frame so a durable
|
|
88
94
|
* park can carry the instruction across the suspend instead of losing it. Same sidecar posture as
|
|
89
95
|
* {@link UserMessageProvenance.enginePayload} (a WeakMap entry, never a message field, never
|
|
@@ -173,6 +179,7 @@ export declare class AgentHarness<TSkill extends Skill = Skill, TPromptTemplate
|
|
|
173
179
|
private lastPublishedSeat?;
|
|
174
180
|
private readonly seatCutSources;
|
|
175
181
|
private trailingBatchEndedOn?;
|
|
182
|
+
private promptReceipt?;
|
|
176
183
|
private turnCutConsumed?;
|
|
177
184
|
private readonly committedEntryIds;
|
|
178
185
|
private readonly answerSources;
|
|
@@ -410,7 +417,7 @@ export declare class AgentHarness<TSkill extends Skill = Skill, TPromptTemplate
|
|
|
410
417
|
prompt(text: string, options?: {
|
|
411
418
|
images?: ImageContent[];
|
|
412
419
|
settleUnansweredToolCalls?: TrailingToolBatchOptions;
|
|
413
|
-
|
|
420
|
+
onCommitted?: PromptCommittedCallback;
|
|
414
421
|
} & UserMessageProvenance & PromptTrailing): Promise<AssistantMessage | undefined>;
|
|
415
422
|
/** R2-③: an empty/whitespace-only injection with no images carries ZERO information — it
|
|
416
423
|
* must not mint a user frame (strict endpoints reject empty user content, and an empty follow-up would
|
|
@@ -3,9 +3,11 @@ import { finalizeToolOutcome, isBatchSafeToolCall, runAgentLoop, runToolCall } f
|
|
|
3
3
|
import { resolveAgentCoreStreamFn } from "../loop/runtime-deps.js";
|
|
4
4
|
import { normalizeEngineSegments } from "../../core/untrusted-text.js";
|
|
5
5
|
import { isCredentialHeaderName } from "../../core/secret-env.js";
|
|
6
|
+
import { isRunOrigin } from "../../core/run-origin.js";
|
|
6
7
|
import { isProviderEchoShape } from "../../brain/errors.js";
|
|
7
8
|
import { convertToLlm } from "./messages.js";
|
|
8
9
|
import { readMember, thrownText } from "../../core/thrown-value.js";
|
|
10
|
+
import { remoteWords } from "../../core/protocol-http-auth.js";
|
|
9
11
|
import { AgentHarnessError, CompactionError, SessionError, SYNTHETIC_MESSAGE_MODEL, toError, } from "./types.js";
|
|
10
12
|
const API_FAILURE_RECORD_MAX_CHARS = 2000;
|
|
11
13
|
function createUserMessage(text, images, provenance) {
|
|
@@ -36,6 +38,7 @@ function createUserMessage(text, images, provenance) {
|
|
|
36
38
|
typeof provenance.actor.hostAsserted === "boolean"
|
|
37
39
|
? { actor: snapshotActorAssertion(provenance.actor) }
|
|
38
40
|
: {}),
|
|
41
|
+
...((runOrigin) => (isRunOrigin(runOrigin) ? { runOrigin } : {}))(provenance?.runOrigin),
|
|
39
42
|
};
|
|
40
43
|
}
|
|
41
44
|
function createTrailingMessage(seed) {
|
|
@@ -66,7 +69,7 @@ function createFailureMessage(model, error, aborted) {
|
|
|
66
69
|
provider: model.provider,
|
|
67
70
|
model: model.id,
|
|
68
71
|
stopReason: aborted ? "aborted" : "error",
|
|
69
|
-
errorMessage: thrownText(error),
|
|
72
|
+
errorMessage: remoteWords(thrownText(error), []),
|
|
70
73
|
timestamp: Date.now(),
|
|
71
74
|
usage: {
|
|
72
75
|
input: 0,
|
|
@@ -207,6 +210,7 @@ export class AgentHarness {
|
|
|
207
210
|
lastPublishedSeat;
|
|
208
211
|
seatCutSources = new WeakMap();
|
|
209
212
|
trailingBatchEndedOn;
|
|
213
|
+
promptReceipt;
|
|
210
214
|
turnCutConsumed;
|
|
211
215
|
committedEntryIds = new WeakMap();
|
|
212
216
|
answerSources = new WeakMap();
|
|
@@ -842,6 +846,11 @@ export class AgentHarness {
|
|
|
842
846
|
entryId = await this.session.appendMessage(event.message);
|
|
843
847
|
this.committedEntryIds.set(event.message, entryId);
|
|
844
848
|
this.settleInjectedFrame(event.message, entryId);
|
|
849
|
+
if (this.promptReceipt?.message === event.message) {
|
|
850
|
+
const { commit } = this.promptReceipt;
|
|
851
|
+
this.promptReceipt = undefined;
|
|
852
|
+
commit(entryId);
|
|
853
|
+
}
|
|
845
854
|
if (entryId !== undefined && event.message.role === "toolResult" && typeof event.message.toolCallId === "string") {
|
|
846
855
|
try {
|
|
847
856
|
this.onFrameCommitted?.({ kind: "tool_result", toolCallId: event.message.toolCallId, content: event.message.content }, entryId);
|
|
@@ -908,6 +917,7 @@ export class AgentHarness {
|
|
|
908
917
|
async executeTurn(turnState, text, options, abortController) {
|
|
909
918
|
let activeTurnState = turnState;
|
|
910
919
|
const userMessage = createUserMessage(text, options?.images, options);
|
|
920
|
+
this.promptReceipt = options?.onCommitted !== undefined ? { message: userMessage, commit: options.onCommitted } : undefined;
|
|
911
921
|
const trailingMessages = (options?.trailing ?? []).map(createTrailingMessage);
|
|
912
922
|
this.runHistory = new WeakSet(turnState.messages.filter((m) => m.role === "assistant"));
|
|
913
923
|
const beforeResult = await this.emitHook({
|
|
@@ -967,7 +977,6 @@ export class AgentHarness {
|
|
|
967
977
|
},
|
|
968
978
|
}
|
|
969
979
|
: {}),
|
|
970
|
-
...(options?.onDelivered !== undefined ? { onPromptsDelivered: options.onDelivered } : {}),
|
|
971
980
|
});
|
|
972
981
|
}
|
|
973
982
|
catch (error) {
|
|
@@ -1002,6 +1011,8 @@ export class AgentHarness {
|
|
|
1002
1011
|
finally {
|
|
1003
1012
|
this.runAbortController = undefined;
|
|
1004
1013
|
this.activeRun = undefined;
|
|
1014
|
+
if (this.promptReceipt?.message === userMessage)
|
|
1015
|
+
this.promptReceipt = undefined;
|
|
1005
1016
|
}
|
|
1006
1017
|
}
|
|
1007
1018
|
}
|
|
@@ -344,8 +344,8 @@ export interface ExecutionEnvExecOptions {
|
|
|
344
344
|
/**
|
|
345
345
|
* Filesystem capability used by the harness.
|
|
346
346
|
*
|
|
347
|
-
* Paths passed to methods may be absolute or relative to {@link cwd}
|
|
348
|
-
*
|
|
347
|
+
* Paths passed to methods may be absolute or relative to {@link cwd}: an absolute path as written, a relative one ANCHORED at `cwd`; a `..` segment
|
|
348
|
+
* is the filesystem's to resolve (`bridge/../next`, `bridge` a symlink, is beside what it leads to), never folded lexically. Returned paths are addressed, not canonicalized unless from {@link canonicalPath}.
|
|
349
349
|
*
|
|
350
350
|
* Operation methods must never throw or reject. All filesystem failures, including unexpected backend failures, must be
|
|
351
351
|
* encoded in the returned {@link Result}. Implementations must preserve this invariant.
|
|
@@ -353,9 +353,9 @@ export interface ExecutionEnvExecOptions {
|
|
|
353
353
|
export interface FileSystem {
|
|
354
354
|
/** Current working directory for relative paths. */
|
|
355
355
|
cwd: string;
|
|
356
|
-
/**
|
|
356
|
+
/** An absolute addressed path, existence not required: ANCHOR ONLY (absolute as written, relative joined under {@link cwd}), no `..` folding, no symlink resolution; an environment with no working directory of its own answers an error. */
|
|
357
357
|
absolutePath(path: string, abortSignal?: AbortSignal): Promise<Result<string, FileError>>;
|
|
358
|
-
/** Join path segments in the filesystem namespace without requiring the result to exist
|
|
358
|
+
/** Join path segments in the filesystem namespace without requiring the result to exist, and without folding a `..`. */
|
|
359
359
|
joinPath(parts: string[], abortSignal?: AbortSignal): Promise<Result<string, FileError>>;
|
|
360
360
|
/** Read a UTF-8 text file. */
|
|
361
361
|
readTextFile(path: string, abortSignal?: AbortSignal): Promise<Result<string, FileError>>;
|
|
@@ -710,6 +710,10 @@ export interface ActiveWorktreeSession {
|
|
|
710
710
|
originalCwd: string;
|
|
711
711
|
baseSha: string;
|
|
712
712
|
entered?: boolean;
|
|
713
|
+
/** The managed name (`.sema/worktrees/<name>`) the tree was CREATED under; absent for a tree entered by `path` or an older record. */
|
|
714
|
+
name?: string;
|
|
715
|
+
/** The branch the tree was CREATED on (`sema/<name>`), not refreshed when a shell switches branches; absent as `name` is (ExitWorktree then leaves every branch alone). */
|
|
716
|
+
branch?: string;
|
|
713
717
|
}
|
|
714
718
|
/**
|
|
715
719
|
* REF-D3/D4 merge target: the session's WORKSPACE STATE container (nests {@link ActiveWorktreeSession}) —
|
|
@@ -942,6 +946,30 @@ export interface SessionHead {
|
|
|
942
946
|
readonly incarnation: string | undefined;
|
|
943
947
|
readonly leafId: string | null;
|
|
944
948
|
}
|
|
949
|
+
/** Where a log stood when read: its entry count and last entry id (`null` = empty). Every append adds an id the log never held, so an
|
|
950
|
+
* appended log never shows the same mark again; a log replaced whole does only with as many entries ending on the same id. */
|
|
951
|
+
export interface SessionLogMark {
|
|
952
|
+
readonly length: number;
|
|
953
|
+
readonly lastEntryId: string | null;
|
|
954
|
+
}
|
|
955
|
+
/** What a conditional write of a session row expects of the row, judged by the repo INSIDE the write's own step (`sessionRowMatches`); a
|
|
956
|
+
* miss is refused `SessionError("conflict")` with nothing written, as the leaf CAS refuses a stale append. It is the row as a read of it
|
|
957
|
+
* answered: `row` = that read's owner and occupant cell (a {@link SessionHead} serves; `null` = no row), `log` (when the log binds) = the
|
|
958
|
+
* log's mark as read — a replacement judged against the log binds it, a deletion owed to the occupant does not. */
|
|
959
|
+
export interface SessionRowExpectation {
|
|
960
|
+
readonly row: {
|
|
961
|
+
readonly owner: string | null;
|
|
962
|
+
readonly incarnation: string | undefined;
|
|
963
|
+
} | null;
|
|
964
|
+
readonly log?: SessionLogMark;
|
|
965
|
+
}
|
|
966
|
+
/** One read of a row ({@link SessionRepo.readRow}): its metadata (placement included), its head and its whole log oldest-first, all of
|
|
967
|
+
* one row generation — the head is the one a write expecting this row names. */
|
|
968
|
+
export interface SessionRowRead<TMetadata extends SessionMetadata = SessionMetadata> {
|
|
969
|
+
readonly metadata: TMetadata;
|
|
970
|
+
readonly head: SessionHead;
|
|
971
|
+
readonly entries: SessionTreeEntry[];
|
|
972
|
+
}
|
|
945
973
|
export interface JsonlSessionMetadata extends SessionMetadata {
|
|
946
974
|
cwd: string;
|
|
947
975
|
path: string;
|
|
@@ -1104,7 +1132,10 @@ export interface SessionRepo<TMetadata extends SessionMetadata = SessionMetadata
|
|
|
1104
1132
|
/** Record activity on the row now: the time {@link list} answers as the row's `lastActiveAt` moves to now. A missing row is a no-op; a
|
|
1105
1133
|
* fault rejects. Optional: a repo without it records only what its writes record. */
|
|
1106
1134
|
touch?(sessionId: string): Promise<void>;
|
|
1107
|
-
|
|
1135
|
+
/** Remove the row and its whole log; an id with no row is a no-op. With `expect`, conditional: the repo judges the row against it in the
|
|
1136
|
+
* removal's own step and on a miss — no row, another generation, or (when the log binds) another log — removes nothing and refuses
|
|
1137
|
+
* `SessionError("conflict")` ({@link readRow}: which repos judge it). */
|
|
1138
|
+
delete(metadata: TMetadata, expect?: SessionRowExpectation): Promise<void>;
|
|
1108
1139
|
/** A fork is a NEW row: `options.id` equal to the source's id is refused (`invalid_fork_target`) — onto its source it would mint a new occupant over the source's own transcript. */
|
|
1109
1140
|
fork(source: TMetadata, options: SessionForkOptions & TCreateOptions): Promise<Session<TMetadata>>;
|
|
1110
1141
|
/**
|
|
@@ -1116,10 +1147,19 @@ export interface SessionRepo<TMetadata extends SessionMetadata = SessionMetadata
|
|
|
1116
1147
|
exportEntries?(sessionId: string): Promise<SessionTreeEntry[]>;
|
|
1117
1148
|
/** The row's {@link SessionHead} in one read (`undefined` = no row); `TtlSessionStore` has a head read and an ownership pair only over a repo that has this. */
|
|
1118
1149
|
headOf?(sessionId: string): Promise<SessionHead | undefined>;
|
|
1150
|
+
/** The row in one read — metadata, head and whole log (no compaction floor) of one generation; `undefined` = no row. A repo with this
|
|
1151
|
+
* judges every expectation its writes are handed; `TtlSessionStore` passes them, and has `delete` / `logTransfer`, only over such a repo. */
|
|
1152
|
+
readRow?(sessionId: string): Promise<SessionRowRead<TMetadata> | undefined>;
|
|
1119
1153
|
/**
|
|
1120
1154
|
* 2c session-sync: write a verbatim entry log (produced by {@link exportEntries} on another backend) into `sessionId` (the log is
|
|
1121
|
-
* replaced, never the row: an
|
|
1155
|
+
* replaced, never the row: an absent id is a new row recording `owner`, `undefined` ⇒ `null` — the caller's principal, never the bundle's;
|
|
1156
|
+
* an existing row keeps its metadata whole and takes the log only when it is already `owner`'s — compared null-safe — else the import is
|
|
1157
|
+
* refused `conflict`, and a placed row `placement_refused`, with nothing written; the owner check and the replacement are one step,
|
|
1158
|
+
* so a row another writer created after the caller looked is refused, never taken). The log MUST be passed through `validateEntriesForImport` first (the single fail-closed
|
|
1122
1159
|
* invariant gate); a durable backend persists THAT function's output, it does not re-implement the checks.
|
|
1160
|
+
* With `options.expect`, the replacement is conditional on the row as the caller read it ({@link sessionRowMatches}, judged in the same
|
|
1161
|
+
* step as the owner check and the write): a miss writes nothing and is refused `SessionError("conflict")`. Answers the head of the row
|
|
1162
|
+
* the write committed (its owner and occupant, and the leaf the new log leaves it on), from that same step — never a later read.
|
|
1123
1163
|
* Optional.
|
|
1124
1164
|
*
|
|
1125
1165
|
* design/171 §6.4 — `options.preserveActorAssertions` is the OPERATOR-level trusted-import
|
|
@@ -1131,7 +1171,8 @@ export interface SessionRepo<TMetadata extends SessionMetadata = SessionMetadata
|
|
|
1131
1171
|
*/
|
|
1132
1172
|
importEntries?(sessionId: string, owner: string | undefined, entries: SessionTreeEntry[], options?: {
|
|
1133
1173
|
preserveActorAssertions?: boolean;
|
|
1134
|
-
|
|
1174
|
+
expect?: SessionRowExpectation;
|
|
1175
|
+
}): Promise<SessionHead>;
|
|
1135
1176
|
}
|
|
1136
1177
|
export interface JsonlSessionCreateOptions extends SessionCreateOptions {
|
|
1137
1178
|
cwd: string;
|
|
@@ -128,7 +128,11 @@ export function normalizeWorkspaceState(value) {
|
|
|
128
128
|
return undefined;
|
|
129
129
|
if (w.entered !== undefined && typeof w.entered !== "boolean")
|
|
130
130
|
return undefined;
|
|
131
|
-
|
|
131
|
+
if (w.name !== undefined && (typeof w.name !== "string" || !/^[A-Za-z0-9._/-]{1,64}$/.test(w.name)))
|
|
132
|
+
return undefined;
|
|
133
|
+
if (w.branch !== undefined && (typeof w.branch !== "string" || !/^sema\/[A-Za-z0-9._+-]{1,64}$/.test(w.branch)))
|
|
134
|
+
return undefined;
|
|
135
|
+
out.activeWorktree = { worktreeDir: w.worktreeDir, originalCwd: w.originalCwd, baseSha: w.baseSha, ...(w.entered === true ? { entered: true } : {}), ...(w.name !== undefined ? { name: w.name } : {}), ...(w.branch !== undefined ? { branch: w.branch } : {}) };
|
|
132
136
|
}
|
|
133
137
|
return out;
|
|
134
138
|
}
|
|
@@ -387,6 +387,15 @@ export interface UserMessage {
|
|
|
387
387
|
* old-session-verbatim posture as the engine-provenance fields above.
|
|
388
388
|
*/
|
|
389
389
|
actor?: ActorAssertion;
|
|
390
|
+
/**
|
|
391
|
+
* What brought the ONE input this message carries, when its host said so (`"scheduled"`: the deployment's scheduler handed
|
|
392
|
+
* it) — the objective's `TaskSpec.runOrigin`. A message that carries several inputs (a resumed leg's continuation: parked
|
|
393
|
+
* steers, a wake's message, an approver's words) carries none, exactly like {@link UserMessage.actor}; each input's word rides its
|
|
394
|
+
* `human_input` frame. Attribution metadata only: never sent to a provider ({@link stripEngineMetadata} strips it), never a
|
|
395
|
+
* decision input. The session-import gate keeps a member of the closed set and drops anything else. Absent = the host said
|
|
396
|
+
* nothing.
|
|
397
|
+
*/
|
|
398
|
+
runOrigin?: import("../../core/run-origin.js").RunOrigin;
|
|
390
399
|
/**
|
|
391
400
|
* The DELIVERY RECORD of a user-attachment frame: this message is the engine-minted frame carrying one attachment
|
|
392
401
|
* the user declared on the human message it follows, or one file a landed compaction re-read
|
|
@@ -667,10 +676,10 @@ export interface ToolResultMessage<TDetails = unknown> {
|
|
|
667
676
|
export type Message = UserMessage | AssistantMessage | ToolResultMessage;
|
|
668
677
|
/**
|
|
669
678
|
* RB-3 (stage S4 carry): strip the engine-provenance metadata fields from user messages before
|
|
670
|
-
* serializing a Context to an external wire. The
|
|
671
|
-
* `engineMinted`/`provenance`/`actor`/`engineNoteKey`/`attachment`) are INTERNAL coordination between the engine's
|
|
679
|
+
* serializing a Context to an external wire. The eight fields (`enginePrefixChars`/`engineSegments`/
|
|
680
|
+
* `engineMinted`/`provenance`/`actor`/`engineNoteKey`/`attachment`/`runOrigin`) are INTERNAL coordination between the engine's
|
|
672
681
|
* minting side and its consumers (permission classifier, compaction summarizer, prompt suggestions,
|
|
673
|
-
* multiplayer attribution, attachment delivery) — they must never reach a provider payload. The built-in brains construct
|
|
682
|
+
* multiplayer attribution, attachment delivery, run attribution) — they must never reach a provider payload. The built-in brains construct
|
|
674
683
|
* their own wire shapes and are immune; a CUSTOM Brain that whole-object-serializes messages
|
|
675
684
|
* (`JSON.stringify(context.messages)`) would leak them — run the array through this projection first.
|
|
676
685
|
*/
|
package/dist/engine/llm/types.js
CHANGED
|
@@ -52,7 +52,7 @@ export function stripEngineMetadata(messages) {
|
|
|
52
52
|
return messages.map((m) => {
|
|
53
53
|
if (m.role !== "user")
|
|
54
54
|
return m;
|
|
55
|
-
const { enginePrefixChars: _a, engineSegments: _b, engineMinted: _c, provenance: _d, actor: _e, engineNoteKey: _f, attachment: _g, ...rest } = m;
|
|
55
|
+
const { enginePrefixChars: _a, engineSegments: _b, engineMinted: _c, provenance: _d, actor: _e, engineNoteKey: _f, attachment: _g, runOrigin: _h, ...rest } = m;
|
|
56
56
|
return rest;
|
|
57
57
|
});
|
|
58
58
|
}
|
|
@@ -129,12 +129,9 @@ export interface TrailingToolBatchSettlement {
|
|
|
129
129
|
aborted: boolean;
|
|
130
130
|
}) => void;
|
|
131
131
|
}
|
|
132
|
-
/**
|
|
133
|
-
* settlement, and the moment the prompts enter the loop transcript, before their frames are emitted
|
|
134
|
-
* — delivery accounts precede the carrying messages' commits. */
|
|
132
|
+
/** A prompt run's seam beyond its prompts (the trailing-batch settlement); a prompt is delivered at its `message_end`. */
|
|
135
133
|
export interface RunAgentLoopSeams {
|
|
136
134
|
settle?: TrailingToolBatchSettlement;
|
|
137
|
-
onPromptsDelivered?: () => void;
|
|
138
135
|
}
|
|
139
136
|
/** The last assistant message of `messages` when at least one of its tool calls has no tool result after it. */
|
|
140
137
|
export declare function findUnansweredToolBatch(messages: readonly AgentMessage[]): AssistantMessage | undefined;
|
|
@@ -3,8 +3,10 @@ import { truncateError } from "../../core/tool-errors.js";
|
|
|
3
3
|
import { judgeToolNameMiss, mountedToolNames } from "../../core/tool-name-aliases.js";
|
|
4
4
|
import { INTERRUPTED_BY_USER_FOR_TOOL_USE_MARKER, INTERRUPTED_BY_USER_MARKER, } from "../../core/session-reconcile.js";
|
|
5
5
|
import { resolveAgentCoreStreamFn } from "./runtime-deps.js";
|
|
6
|
-
import { isErrorLike, readMember, thrownMarksOf } from "../../core/thrown-value.js";
|
|
6
|
+
import { isErrorLike, readMember, readOwnMembers, thrownMarksOf } from "../../core/thrown-value.js";
|
|
7
7
|
import { egressThrownText, egressValue } from "../../core/untrusted-egress.js";
|
|
8
|
+
import { remoteWords } from "../../core/protocol-http-auth.js";
|
|
9
|
+
import { types } from "node:util";
|
|
8
10
|
import { admitToolResultMedia } from "../../core/image-admission.js";
|
|
9
11
|
function appendTextDeltaToAssistantMessage(message, contentIndex, delta) {
|
|
10
12
|
const content = [...message.content];
|
|
@@ -75,7 +77,6 @@ export async function runAgentLoop(prompts, context, config, emit, signal, strea
|
|
|
75
77
|
state.hasMoreToolCalls = true;
|
|
76
78
|
state.context.messages.push(...delivered);
|
|
77
79
|
state.newMessages.push(...delivered);
|
|
78
|
-
seams?.onPromptsDelivered?.();
|
|
79
80
|
for (const prompt of delivered) {
|
|
80
81
|
await emit({ type: "message_start", message: prompt });
|
|
81
82
|
await emit({ type: "message_end", message: prompt });
|
|
@@ -756,7 +757,7 @@ async function streamAssistantResponse(context, config, signal, emit, streamFn,
|
|
|
756
757
|
break;
|
|
757
758
|
case "done":
|
|
758
759
|
case "error": {
|
|
759
|
-
const finalMessage = await response.result();
|
|
760
|
+
const finalMessage = receivedFinal(await response.result());
|
|
760
761
|
const cutAtSettle = signal?.aborted === true;
|
|
761
762
|
if (executor && (finalMessage.stopReason === "error" || finalMessage.stopReason === "aborted")) {
|
|
762
763
|
mergeBackAdmittedCalls(finalMessage, executor);
|
|
@@ -775,7 +776,7 @@ async function streamAssistantResponse(context, config, signal, emit, streamFn,
|
|
|
775
776
|
}
|
|
776
777
|
}
|
|
777
778
|
}
|
|
778
|
-
const finalMessage = await response.result();
|
|
779
|
+
const finalMessage = receivedFinal(await response.result());
|
|
779
780
|
const cutAtSettle = signal?.aborted === true;
|
|
780
781
|
if (executor && (finalMessage.stopReason === "error" || finalMessage.stopReason === "aborted")) {
|
|
781
782
|
mergeBackAdmittedCalls(finalMessage, executor);
|
|
@@ -1179,6 +1180,27 @@ async function harvestExecutorOnErrorFinal(executor, state, finalMessage, signal
|
|
|
1179
1180
|
}
|
|
1180
1181
|
return results;
|
|
1181
1182
|
}
|
|
1183
|
+
function receivedFinal(message) {
|
|
1184
|
+
const words = readMember(message, "errorMessage");
|
|
1185
|
+
const minted = typeof words === "string" ? remoteWords(words, []) : undefined;
|
|
1186
|
+
if (minted === words && readsTheSame(message, "errorMessage", words))
|
|
1187
|
+
return message;
|
|
1188
|
+
const copy = {};
|
|
1189
|
+
for (const [key, value] of Object.entries(readOwnMembers(message) ?? {}))
|
|
1190
|
+
if (key !== "errorMessage")
|
|
1191
|
+
Object.defineProperty(copy, key, { value, enumerable: true, writable: true, configurable: true });
|
|
1192
|
+
if (minted !== undefined)
|
|
1193
|
+
copy.errorMessage = minted;
|
|
1194
|
+
return copy;
|
|
1195
|
+
}
|
|
1196
|
+
function readsTheSame(o, key, value) {
|
|
1197
|
+
if (types.isProxy(o))
|
|
1198
|
+
return false;
|
|
1199
|
+
const d = Reflect.getOwnPropertyDescriptor(o, key);
|
|
1200
|
+
if (d === undefined)
|
|
1201
|
+
return value === undefined && !(key in o);
|
|
1202
|
+
return "value" in d && d.value === value;
|
|
1203
|
+
}
|
|
1182
1204
|
function mergeBackAdmittedCalls(finalMessage, executor) {
|
|
1183
1205
|
const admitted = executor.admittedToolCalls();
|
|
1184
1206
|
if (admitted.length === 0)
|
|
@@ -2,6 +2,7 @@ import { SessionError, normalizeAnnouncedListing, normalizeReminderMark, normali
|
|
|
2
2
|
import { leafIdAfterEntry } from "./storage-base.js";
|
|
3
3
|
import { parseSessionTimestampMs } from "./timestamps.js";
|
|
4
4
|
import { flattenableUserText, normalizeEngineSegments } from "../../core/untrusted-text.js";
|
|
5
|
+
import { isRunOrigin } from "../../core/run-origin.js";
|
|
5
6
|
import { readStoredPromptEpoch } from "../../prompt-assembly/epoch.js";
|
|
6
7
|
import { MAX_MINTED_TOOL_RESULT_REF_CHARS } from "../../core/tool-result-store.js";
|
|
7
8
|
import { PERSISTED_OUTPUT_REFS_MAX_ENTRIES, SKILL_RETENTION_PER_SKILL_MAX_CHARS, SKILL_RETENTION_TOTAL_MAX_CHARS, } from "../compaction/utils.js";
|
|
@@ -284,6 +285,8 @@ function normalizeEngineProvenanceStamp(message, preserveActorAssertions = false
|
|
|
284
285
|
}
|
|
285
286
|
if (m.attachment !== undefined)
|
|
286
287
|
delete m.attachment;
|
|
288
|
+
if (m.runOrigin !== undefined && !isRunOrigin(m.runOrigin))
|
|
289
|
+
delete m.runOrigin;
|
|
287
290
|
if (m.engineMinted !== undefined && m.engineMinted !== true)
|
|
288
291
|
delete m.engineMinted;
|
|
289
292
|
if (m.provenance !== undefined && m.provenance !== "engine-note")
|
|
@@ -1,29 +1,37 @@
|
|
|
1
|
-
import { type Session, type SessionCreateOptions, type SessionForkOptions, type SessionHead, type SessionMetadata, type SessionRepo, type SessionRow, type SessionTreeEntry } from "../harness/types.js";
|
|
1
|
+
import { type Session, type SessionCreateOptions, type SessionForkOptions, type SessionHead, type SessionMetadata, type SessionRepo, type SessionRow, type SessionRowExpectation, type SessionRowRead, type SessionTreeEntry } from "../harness/types.js";
|
|
2
2
|
export declare class InMemorySessionRepo implements SessionRepo<SessionMetadata, SessionCreateOptions> {
|
|
3
|
-
private
|
|
3
|
+
private rows;
|
|
4
4
|
/** Each row's last touch (epoch ms). */
|
|
5
5
|
private touched;
|
|
6
6
|
create(options?: SessionCreateOptions): Promise<Session>;
|
|
7
7
|
open(metadata: SessionMetadata): Promise<Session>;
|
|
8
|
-
/** The row's head off the one
|
|
9
|
-
*
|
|
8
|
+
/** The row's head off the one row that IS it: every cell comes from that row, so a delete and re-create of the id while this reads
|
|
9
|
+
* cannot mix two generations. */
|
|
10
10
|
headOf(sessionId: string): Promise<SessionHead | undefined>;
|
|
11
|
+
/** The row in one synchronous read: its metadata, its head and a copy of its log, from the one row that is it. */
|
|
12
|
+
readRow(sessionId: string): Promise<SessionRowRead | undefined>;
|
|
11
13
|
/** Every row, with its last {@link touch} as its activity time where it has one. This repo hands its sessions' storages out and never
|
|
12
14
|
* sees their writes (an entry's own `timestamp` is the writer's data, not the time of the write), so a row never touched carries none
|
|
13
15
|
* and a reader takes its `createdAt`. */
|
|
14
16
|
list(): Promise<SessionRow[]>;
|
|
15
17
|
/** Record activity on the row now (a missing row: nothing to record). The time lives and dies with the row: `delete` drops it. */
|
|
16
18
|
touch(sessionId: string): Promise<void>;
|
|
17
|
-
|
|
19
|
+
/** Remove the row; with `expect`, only the row the expectation names, judged and removed in one synchronous step. */
|
|
20
|
+
delete(metadata: SessionMetadata, expect?: SessionRowExpectation): Promise<void>;
|
|
18
21
|
fork(sourceMetadata: SessionMetadata, options: SessionForkOptions & SessionCreateOptions): Promise<Session>;
|
|
19
|
-
/** 2c session-sync: the FULL log for export
|
|
20
|
-
*
|
|
22
|
+
/** 2c session-sync: the FULL log for export — {@link readRow}'s log (InMemory holds everything, no F3 floor: the full oldest-first log
|
|
23
|
+
* with `id`/`parentId` verbatim). A missing row is `not_found`. */
|
|
21
24
|
exportEntries(sessionId: string): Promise<SessionTreeEntry[]>;
|
|
22
25
|
/** 2c session-sync: import a verbatim log into `sessionId`. The single invariant gate runs first
|
|
23
|
-
* ({@link validateEntriesForImport}, fail-closed);
|
|
26
|
+
* ({@link validateEntriesForImport}, fail-closed); then, in one synchronous step, the row standing now is judged — the expectation
|
|
27
|
+
* (`options.expect`, {@link sessionRowMatches}) and the write law (`importRowCells`: a new row records `owner`, an existing row keeps its
|
|
28
|
+
* metadata whole and must already be `owner`'s) — and the log replaced; the head answered is the new row's.
|
|
24
29
|
* design/171: the operator's trusted-import flag is forwarded to the gate that persists — see
|
|
25
30
|
* SessionRepo.importEntries. */
|
|
26
31
|
importEntries(sessionId: string, owner: string | undefined, entries: SessionTreeEntry[], options?: {
|
|
27
32
|
preserveActorAssertions?: boolean;
|
|
28
|
-
|
|
33
|
+
expect?: SessionRowExpectation;
|
|
34
|
+
}): Promise<SessionHead>;
|
|
35
|
+
/** Lay a row down under its id: one storage, one session over it, the metadata it was built with. */
|
|
36
|
+
private lay;
|
|
29
37
|
}
|