@sema-agent/core 7.59.0 → 7.60.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 +564 -0
- package/dist/agents/agent-definition.d.ts +7 -0
- package/dist/agents/agent-definition.js +12 -0
- package/dist/agents/agent-transcript-tool.d.ts +2 -1
- package/dist/agents/agent-transcript-tool.js +3 -1
- package/dist/agents/child-model-seat.js +6 -3
- package/dist/agents/cumulative-stats.js +0 -1
- package/dist/agents/inherited-tool-pool.d.ts +26 -1
- package/dist/agents/inherited-tool-pool.js +22 -0
- package/dist/agents/retain-ledger.d.ts +11 -1
- package/dist/agents/retain-ledger.js +13 -2
- package/dist/agents/roster-store.d.ts +1 -1
- package/dist/agents/roster-store.js +3 -1
- package/dist/agents/send-message-tool.d.ts +8 -19
- package/dist/agents/send-message-tool.js +11 -38
- package/dist/agents/subagent.d.ts +51 -17
- package/dist/agents/subagent.js +117 -78
- package/dist/agents/tool-filter.d.ts +1 -3
- package/dist/agents/tool-filter.js +4 -12
- package/dist/bench/metrics.d.ts +3 -5
- package/dist/bench/metrics.js +0 -1
- package/dist/brain/degrading.js +3 -1
- package/dist/brain/route-adjudicator.js +3 -1
- package/dist/brain/status-sink.d.ts +7 -1
- package/dist/brain/status-sink.js +6 -0
- package/dist/brain/timeout.d.ts +3 -1
- package/dist/brain/timeout.js +18 -5
- package/dist/core/a2a.d.ts +15 -5
- package/dist/core/a2a.js +34 -19
- package/dist/core/agent-definition.d.ts +20 -0
- package/dist/core/allow-entry.d.ts +2 -0
- package/dist/core/allow-entry.js +3 -1
- package/dist/core/artifact-host.d.ts +0 -2
- package/dist/core/artifact-host.js +0 -1
- package/dist/core/auto-mode-defaults.d.ts +8 -0
- package/dist/core/auto-mode-defaults.js +1 -0
- package/dist/core/auto-mode-rebuild.d.ts +2 -1
- package/dist/core/auto-mode.d.ts +39 -4
- package/dist/core/auto-mode.js +63 -12
- package/dist/core/background-agent-store.d.ts +10 -1
- package/dist/core/background-agent-store.js +3 -2
- package/dist/core/background-shell.d.ts +12 -1
- package/dist/core/background-shell.js +12 -0
- package/dist/core/checkpoint-store.d.ts +8 -13
- package/dist/core/checkpoint-store.js +4 -3
- package/dist/core/compliance.d.ts +1 -1
- package/dist/core/credential-echo.d.ts +52 -0
- package/dist/core/credential-echo.js +65 -0
- package/dist/core/credential-vocabulary.d.ts +13 -3
- package/dist/core/credential-vocabulary.js +12 -4
- package/dist/core/cross-boundary-taint.d.ts +4 -5
- package/dist/core/engine-notice.d.ts +58 -15
- package/dist/core/frame-settlement.d.ts +5 -0
- package/dist/core/frame-settlement.js +4 -0
- package/dist/core/gate-fold.js +7 -5
- package/dist/core/gate-lanes.js +39 -8
- package/dist/core/governance-codes.d.ts +9 -1
- package/dist/core/governance-codes.js +12 -0
- package/dist/core/hands-band-screen.js +0 -1
- package/dist/core/hands-band.d.ts +0 -3
- package/dist/core/hooks.d.ts +39 -56
- package/dist/core/hooks.js +123 -77
- package/dist/core/image-admission.d.ts +104 -51
- package/dist/core/image-admission.js +170 -46
- package/dist/core/image-downsample.d.ts +36 -69
- package/dist/core/image-downsample.js +111 -73
- package/dist/core/integer-option.d.ts +21 -0
- package/dist/core/integer-option.js +13 -0
- package/dist/core/locked-config.d.ts +54 -3
- package/dist/core/locked-config.js +81 -50
- package/dist/core/mcp-call-meta.d.ts +2 -2
- package/dist/core/mcp-call-meta.js +9 -10
- package/dist/core/mcp-failure.d.ts +9 -3
- package/dist/core/mcp-failure.js +10 -0
- package/dist/core/mcp-host-seat.d.ts +92 -0
- package/dist/core/mcp-host-seat.js +131 -0
- package/dist/core/mcp-probe.d.ts +7 -2
- package/dist/core/mcp-probe.js +7 -2
- package/dist/core/mcp-server-spec.d.ts +38 -9
- package/dist/core/mcp-server-spec.js +55 -21
- package/dist/core/mcp.d.ts +17 -6
- package/dist/core/mcp.js +67 -55
- package/dist/core/memory-admission.d.ts +23 -6
- package/dist/core/memory-admission.js +19 -9
- package/dist/core/memory-engine/content-origin.d.ts +13 -0
- package/dist/core/memory-engine/content-origin.js +21 -3
- package/dist/core/memory-engine/index.d.ts +2 -1
- package/dist/core/memory-engine/index.js +2 -1
- package/dist/core/memory-engine/scope-contract.d.ts +13 -3
- package/dist/core/memory-engine/scope-contract.js +2 -2
- package/dist/core/memory-engine/sync-client.d.ts +45 -11
- package/dist/core/memory-engine/sync-client.js +82 -11
- package/dist/core/memory-engine/sync-report.d.ts +103 -0
- package/dist/core/memory-engine/sync-report.js +119 -0
- package/dist/core/memory-engine/sync.d.ts +4 -2
- package/dist/core/mode-policy.d.ts +9 -1
- package/dist/core/mode-policy.js +11 -1
- package/dist/core/model-receipt.d.ts +39 -0
- package/dist/core/model-receipt.js +139 -0
- package/dist/core/mods/agent-stations.d.ts +65 -0
- package/dist/core/mods/agent-stations.js +105 -0
- package/dist/core/mods/kernel/dispatch.d.ts +5 -1
- package/dist/core/mods/kernel/dispatch.js +4 -4
- package/dist/core/mods/kernel/events.d.ts +10 -4
- package/dist/core/mods/kernel/events.js +10 -6
- package/dist/core/mods/kernel/receive.d.ts +5 -0
- package/dist/core/mods/kernel/receive.js +10 -0
- package/dist/core/mods/lifecycle-stations.d.ts +41 -0
- package/dist/core/mods/lifecycle-stations.js +35 -0
- package/dist/core/mods/stations.d.ts +51 -59
- package/dist/core/mods/stations.js +32 -42
- package/dist/core/mods/tool-call.d.ts +10 -4
- package/dist/core/mods/tool-call.js +28 -12
- package/dist/core/mounted-mcp.d.ts +5 -0
- package/dist/core/mounted-mcp.js +2 -2
- package/dist/core/namespaced-rule-name.d.ts +7 -1
- package/dist/core/namespaced-rule-name.js +13 -2
- package/dist/core/oracle-isolation.js +1 -1
- package/dist/core/own-property-receipt.d.ts +3 -0
- package/dist/core/own-property-receipt.js +3 -0
- package/dist/core/park-selfcheck.js +8 -8
- package/dist/core/peer-seat.d.ts +63 -8
- package/dist/core/peer-seat.js +179 -34
- package/dist/core/permission-rule-consent.d.ts +0 -21
- package/dist/core/permission-rule-consent.js +1 -2
- package/dist/core/permission-rule-model.d.ts +4 -2
- package/dist/core/permission-rule-model.js +7 -6
- package/dist/core/protocol-http-auth.d.ts +14 -2
- package/dist/core/protocol-http-auth.js +16 -7
- package/dist/core/read-face-seats.d.ts +7 -5
- package/dist/core/read-face-seats.js +4 -1
- package/dist/core/redaction-marks.d.ts +4 -3
- package/dist/core/redaction-marks.js +2 -2
- package/dist/core/remote-env.d.ts +146 -98
- package/dist/core/remote-env.js +113 -14
- package/dist/core/retention.js +37 -12
- package/dist/core/retired-keys.d.ts +6 -1
- package/dist/core/retired-keys.js +4 -1
- package/dist/core/rewrite-rejudge.d.ts +12 -5
- package/dist/core/rewrite-rejudge.js +9 -5
- package/dist/core/roles.d.ts +37 -3
- package/dist/core/roles.js +126 -78
- package/dist/core/rule-owner.d.ts +3 -0
- package/dist/core/runner/assemble-result.d.ts +0 -5
- package/dist/core/runner/assemble-result.js +0 -1
- package/dist/core/runner/call-hook-stations.d.ts +17 -10
- package/dist/core/runner/call-hook-stations.js +21 -10
- package/dist/core/runner/child-tree.d.ts +7 -8
- package/dist/core/runner/child-tree.js +6 -6
- package/dist/core/runner/classifier-ladder.d.ts +10 -2
- package/dist/core/runner/classifier-ladder.js +39 -8
- package/dist/core/runner/construction-doors.js +5 -0
- package/dist/core/runner/contracts.d.ts +62 -41
- package/dist/core/runner/cross-boundary-lane.d.ts +3 -5
- package/dist/core/runner/cross-boundary-lane.js +11 -2
- package/dist/core/runner/env-capability-census.d.ts +15 -20
- package/dist/core/runner/env-capability-census.js +25 -34
- package/dist/core/runner/file-history-request.d.ts +2 -2
- package/dist/core/runner/file-history-request.js +0 -8
- package/dist/core/runner/gate-exit.d.ts +75 -7
- package/dist/core/runner/gate-exit.js +20 -1
- package/dist/core/runner/git-status-frame.d.ts +5 -2
- package/dist/core/runner/git-status-frame.js +3 -4
- package/dist/core/runner/image.d.ts +7 -2
- package/dist/core/runner/image.js +14 -8
- package/dist/core/runner/inline-image.d.ts +10 -8
- package/dist/core/runner/inline-image.js +11 -9
- package/dist/core/runner/memory-consolidation-driver.js +4 -4
- package/dist/core/runner/permission-rule-lanes.js +1 -1
- package/dist/core/runner/prepare-boundary-parks.d.ts +2 -2
- package/dist/core/runner/prepare-boundary-parks.js +3 -3
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +4 -0
- package/dist/core/runner/prepare-caps-and-workflow.js +4 -3
- package/dist/core/runner/prepare-config-doors.d.ts +6 -1
- package/dist/core/runner/prepare-config-doors.js +14 -9
- package/dist/core/runner/prepare-delegation-surface.d.ts +5 -3
- package/dist/core/runner/prepare-delegation-surface.js +4 -4
- package/dist/core/runner/prepare-file-history.d.ts +10 -12
- package/dist/core/runner/prepare-file-history.js +3 -12
- package/dist/core/runner/prepare-gate-stations.d.ts +4 -3
- package/dist/core/runner/prepare-gate-stations.js +4 -3
- package/dist/core/runner/prepare-hands-readface.d.ts +3 -1
- package/dist/core/runner/prepare-hands-readface.js +15 -7
- package/dist/core/runner/prepare-inherited-gate.d.ts +5 -4
- package/dist/core/runner/prepare-inherited-gate.js +9 -5
- package/dist/core/runner/prepare-memory-engine-session.js +1 -1
- package/dist/core/runner/prepare-memory.d.ts +2 -2
- package/dist/core/runner/prepare-memory.js +2 -2
- package/dist/core/runner/prepare-park-ask.d.ts +3 -5
- package/dist/core/runner/prepare-park-ask.js +3 -8
- package/dist/core/runner/prepare-policy-chain.d.ts +5 -4
- package/dist/core/runner/prepare-policy-chain.js +120 -108
- package/dist/core/runner/prepare-project-context.js +8 -5
- package/dist/core/runner/prepare-prompt-inputs.d.ts +4 -1
- package/dist/core/runner/prepare-prompt-inputs.js +3 -2
- package/dist/core/runner/prepare-protocol-tools.d.ts +5 -3
- package/dist/core/runner/prepare-protocol-tools.js +9 -2
- package/dist/core/runner/prepare-suspend-saga.d.ts +0 -2
- package/dist/core/runner/prepare-suspend-saga.js +5 -7
- package/dist/core/runner/prepare-task.js +41 -27
- package/dist/core/runner/prepare-turn-wiring.d.ts +2 -0
- package/dist/core/runner/prepare-turn-wiring.js +7 -2
- package/dist/core/runner/prepare-wiring-manifest.d.ts +4 -3
- package/dist/core/runner/prepare-wiring-manifest.js +32 -18
- package/dist/core/runner/prepare-workspace-restore.js +3 -3
- package/dist/core/runner/resume-checkpoint-screen.js +4 -4
- package/dist/core/runner/retired-runner-deps.js +4 -1
- package/dist/core/runner/run-attachment-seats.js +3 -3
- package/dist/core/runner/run-brain-sinks.js +1 -0
- package/dist/core/runner/run-git-lane.d.ts +3 -1
- package/dist/core/runner/run-git-lane.js +1 -1
- package/dist/core/runner/run-harness-handlers.d.ts +3 -1
- package/dist/core/runner/run-harness-handlers.js +3 -1
- package/dist/core/runner/run-identity-wiring.js +1 -1
- package/dist/core/runner/run-leg.js +26 -28
- package/dist/core/runner/run-notification-lane.d.ts +3 -1
- package/dist/core/runner/run-notification-lane.js +16 -10
- package/dist/core/runner/run-settle-and-teardown.js +5 -1
- package/dist/core/runner/run-stop-and-final-verify.d.ts +4 -0
- package/dist/core/runner/run-stop-and-final-verify.js +12 -4
- package/dist/core/runner/run-turn-boundary.js +12 -7
- package/dist/core/runner/runtask.d.ts +7 -4
- package/dist/core/runner/runtask.js +19 -11
- package/dist/core/runner/skills-seat.js +2 -2
- package/dist/core/runner/sub-agent-deny-lists.js +10 -7
- package/dist/core/runner/synthetic-tools.js +2 -2
- package/dist/core/runner/tool-disclosure.js +0 -2
- package/dist/core/runner/tool-face-overlay.d.ts +1 -1
- package/dist/core/runner/tool-face-overlay.js +26 -19
- package/dist/core/runner/tool-result-media-seat.d.ts +9 -1
- package/dist/core/runner/tool-result-media-seat.js +17 -1
- package/dist/core/runner/turn-attachments.d.ts +3 -5
- package/dist/core/runner/turn-attachments.js +3 -16
- package/dist/core/runner-deps.d.ts +31 -18
- package/dist/core/secret-env.d.ts +3 -2
- package/dist/core/session-policy-store.d.ts +9 -2
- package/dist/core/session-policy-store.js +16 -1
- package/dist/core/session-store.d.ts +3 -2
- package/dist/core/session-store.js +50 -11
- package/dist/core/skill-grant.d.ts +9 -0
- package/dist/core/skill-grant.js +18 -0
- package/dist/core/store-contracts/tool-result-store-contract.d.ts +1 -1
- package/dist/core/store-contracts/tool-result-store-contract.js +37 -0
- package/dist/core/stub-env.d.ts +5 -5
- package/dist/core/stub-env.js +11 -1
- package/dist/core/swappable-deps.d.ts +17 -43
- package/dist/core/swappable-deps.js +15 -5
- package/dist/core/synthetic-read-verdict.d.ts +1 -1
- package/dist/core/task-event.d.ts +18 -2
- package/dist/core/task-notification.d.ts +88 -5
- package/dist/core/task-notification.js +130 -7
- package/dist/core/task-registry-agent.d.ts +18 -12
- package/dist/core/task-registry-agent.js +18 -6
- package/dist/core/task-registry-monitor.d.ts +7 -0
- package/dist/core/task-registry-monitor.js +28 -1
- package/dist/core/task-registry-shared.d.ts +38 -3
- package/dist/core/task-registry-shared.js +21 -7
- package/dist/core/task-registry-workflow.js +1 -1
- package/dist/core/task-registry.d.ts +50 -35
- package/dist/core/task-registry.js +64 -23
- package/dist/core/task-result.d.ts +3 -12
- package/dist/core/task-spec.d.ts +3 -6
- package/dist/core/task-stream.d.ts +1 -1
- package/dist/core/tool-catalog-entries.js +1 -1
- package/dist/core/tool-face-reader.d.ts +7 -6
- package/dist/core/tool-face-reader.js +4 -3
- package/dist/core/tool-name-aliases.d.ts +19 -0
- package/dist/core/tool-name-aliases.js +54 -2
- package/dist/core/tool-policy.d.ts +5 -4
- package/dist/core/tool-policy.js +1 -1
- package/dist/core/tool-registry.d.ts +5 -5
- package/dist/core/tool-registry.js +2 -2
- package/dist/core/tool-result-store.d.ts +88 -5
- package/dist/core/tool-result-store.js +51 -12
- package/dist/core/tool-spec.d.ts +20 -4
- package/dist/core/trace.d.ts +0 -1
- package/dist/core/types.d.ts +3 -3
- package/dist/core/types.js +1 -1
- package/dist/core/untrusted-text.js +1 -1
- package/dist/core/user-attachment.d.ts +10 -5
- package/dist/core/user-attachment.js +14 -6
- package/dist/engine/execution-env/node-execution-env.d.ts +7 -2
- package/dist/engine/execution-env/node-execution-env.js +12 -1
- package/dist/engine/harness/agent-harness.d.ts +1 -1
- package/dist/engine/harness/agent-harness.js +8 -4
- package/dist/engine/harness/types.d.ts +112 -29
- package/dist/engine/loop/agent-loop.d.ts +12 -12
- package/dist/engine/loop/agent-loop.js +153 -21
- package/dist/engine/loop/types.d.ts +9 -2
- package/dist/engine/lsp/node-lsp-manager.d.ts +3 -3
- package/dist/engine/lsp/node-lsp-manager.js +32 -13
- package/dist/index.d.ts +22 -14
- package/dist/index.js +15 -10
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/orchestration/run-workflow-tool.d.ts +9 -3
- package/dist/orchestration/run-workflow-tool.js +59 -29
- package/dist/orchestration/workflow-governance.d.ts +1 -1
- package/dist/orchestration/workflow-governance.js +2 -1
- package/dist/orchestration/workflow.d.ts +4 -0
- package/dist/orchestration/workflow.js +25 -4
- package/dist/prompts/default.d.ts +1 -10
- package/dist/prompts/default.js +0 -2
- package/dist/stores/file/background-agent-store.d.ts +1 -1
- package/dist/stores/file/background-agent-store.js +3 -1
- package/dist/stores/file/checkpoint-store.d.ts +127 -2
- package/dist/stores/file/checkpoint-store.js +19 -14
- package/dist/stores/file/file-history-store.d.ts +1 -1
- package/dist/stores/file/file-history-store.js +3 -1
- package/dist/stores/file/index.d.ts +4 -3
- package/dist/stores/file/index.js +17 -8
- package/dist/stores/file/mailbox-store.d.ts +1 -1
- package/dist/stores/file/mailbox-store.js +3 -1
- package/dist/stores/file/memory-store.d.ts +1 -1
- package/dist/stores/file/memory-store.js +3 -1
- package/dist/stores/file/session-policy-store.d.ts +1 -1
- package/dist/stores/file/session-policy-store.js +3 -1
- package/dist/stores/file/session-store.d.ts +1 -1
- package/dist/stores/file/session-store.js +3 -1
- package/dist/stores/file/shared-ledger.d.ts +26 -0
- package/dist/stores/file/shared-ledger.js +38 -9
- package/dist/stores/file/tool-result-store.d.ts +20 -2
- package/dist/stores/file/tool-result-store.js +74 -6
- package/dist/stores/file/usage-window-store.d.ts +1 -1
- package/dist/stores/file/usage-window-store.js +3 -1
- package/dist/stores/file/workflow-journal-store.d.ts +1 -11
- package/dist/stores/file/workflow-journal-store.js +3 -2
- package/dist/tools/fs/containment-face.d.ts +5 -0
- package/dist/tools/fs/encoding.d.ts +13 -4
- package/dist/tools/fs/encoding.js +17 -2
- package/dist/tools/fs/fs-bash-background-text.d.ts +7 -0
- package/dist/tools/fs/fs-bash-background-text.js +1 -0
- package/dist/tools/fs/fs-bash.d.ts +8 -4
- package/dist/tools/fs/fs-bash.js +26 -35
- package/dist/tools/fs/fs-pdf.d.ts +2 -2
- package/dist/tools/fs/fs-pdf.js +26 -21
- package/dist/tools/fs/fs-read.d.ts +5 -4
- package/dist/tools/fs/fs-read.js +35 -18
- package/dist/tools/fs/fs-search-tools.js +4 -1
- package/dist/tools/fs/fs-shared.d.ts +11 -13
- package/dist/tools/fs/fs-shared.js +11 -7
- package/dist/tools/fs/fs-write.js +5 -5
- package/dist/tools/fs/index.d.ts +14 -8
- package/dist/tools/fs/index.js +8 -4
- package/dist/tools/fs/read-floor.d.ts +44 -1
- package/dist/tools/fs/read-floor.js +35 -0
- package/dist/tools/fs/removal-targets.d.ts +9 -4
- package/dist/tools/fs/removal-targets.js +17 -9
- package/dist/tools/fs/search.d.ts +3 -3
- package/dist/tools/fs/search.js +4 -4
- package/dist/tools/monitor.d.ts +5 -4
- package/dist/tools/monitor.js +15 -8
- package/dist/tools/scheduler-tools.js +42 -4
- package/dist/tools/web.d.ts +0 -10
- package/dist/tools/web.js +1 -4
- package/package.json +4 -2
- package/test/export-surface.snapshot.json +75 -21
- package/wire-changes/core-stores-sql@7.60.0.json +30 -0
- package/wire-changes/core@7.60.0.json +3274 -0
- package/wire-changes/mods-kernel@7.60.0.json +62 -0
- package/wire-changes/primitives@7.60.0.json +30 -0
|
@@ -3,7 +3,8 @@ import { READ_OUTCOMES } from "../tools/fs/fs-read.js";
|
|
|
3
3
|
import { renderDirectoryListing } from "../tools/fs/dir-entries.js";
|
|
4
4
|
import { MAX_READ_OUTPUT_CHARS } from "../tools/fs/fs-shared.js";
|
|
5
5
|
import { normalizeFileText } from "../tools/fs/encoding.js";
|
|
6
|
-
import { ADMITTED_IMAGE_MIME_TYPES, admitImageBytes } from "./image-admission.js";
|
|
6
|
+
import { ADMITTED_IMAGE_MIME_TYPES, admitImageBytes, firstUnprocessedOverTarget, IMAGE_ADMISSION, unprocessedSizeClause } from "./image-admission.js";
|
|
7
|
+
import { resolveImageProcessor } from "./image-downsample.js";
|
|
7
8
|
import { PDF_MAX_PAGES_PER_READ } from "../tools/fs/pdf.js";
|
|
8
9
|
import { MARKED_BLOCK_AFTER_DATA, mintSystemReminder } from "./reminder-mint.js";
|
|
9
10
|
import { commitReminderDisclosureEffects, planReminderDisclosure } from "./reminder-disclosure.js";
|
|
@@ -151,12 +152,12 @@ function declarationOf(a, ordinal) {
|
|
|
151
152
|
? { ordinal, supply: a.supply, path: a.path }
|
|
152
153
|
: { ordinal, supply: a.supply, name: a.name, bytes: a.supply === "content_text" ? Buffer.byteLength(a.text, "utf8") : Buffer.from(a.data, "base64").byteLength };
|
|
153
154
|
}
|
|
154
|
-
export async function admitUserAttachmentImages(screened) {
|
|
155
|
+
export async function admitUserAttachmentImages(screened, processor) {
|
|
155
156
|
const out = new Map();
|
|
156
157
|
for (const [i, a] of screened.entries()) {
|
|
157
158
|
if (a.supply !== "content_image")
|
|
158
159
|
continue;
|
|
159
|
-
const admitted = await admitImageBytes(Buffer.from(a.data, "base64"), a.mimeType,
|
|
160
|
+
const admitted = await admitImageBytes(Buffer.from(a.data, "base64"), a.mimeType, processor);
|
|
160
161
|
if (admitted.ok) {
|
|
161
162
|
out.set(i + 1, admitted.block);
|
|
162
163
|
continue;
|
|
@@ -169,8 +170,11 @@ export async function admitUserAttachmentImages(screened) {
|
|
|
169
170
|
throw userAttachmentRefusal(memberRef(imageAt, "data"), `does not open with a valid ${a.mimeType} header (empty, truncated, mis-declared, not base64, or a variant such as an Apple-optimized PNG that model APIs cannot read) — refused rather than sent.`);
|
|
170
171
|
case "raw_too_large":
|
|
171
172
|
throw userAttachmentRefusal(memberRef(imageAt, "data"), `${admitted.rawBytes} bytes, over the ${admitted.cap}-byte cap.`);
|
|
173
|
+
case "dimensions_unreadable":
|
|
174
|
+
case "dimensions_too_large":
|
|
175
|
+
throw userAttachmentRefusal(memberRef(imageAt, "data"), `refused rather than sent: ${unprocessedSizeClause(admitted)}.`);
|
|
172
176
|
case "base64_too_large":
|
|
173
|
-
throw userAttachmentRefusal(memberRef(imageAt, "data"), `base64 of ${admitted.base64.length} characters, over the API's
|
|
177
|
+
throw userAttachmentRefusal(memberRef(imageAt, "data"), `base64 of ${admitted.base64.length} characters, over the API's ${IMAGE_ADMISSION.hard.imageBase64Chars}-character image limit — shrink the image first.`);
|
|
174
178
|
}
|
|
175
179
|
}
|
|
176
180
|
return out;
|
|
@@ -485,15 +489,16 @@ function refuseFramesOverWindow(frames, model, window) {
|
|
|
485
489
|
const n = frames.length;
|
|
486
490
|
throw userAttachmentRefusal(SEAT_REF, `the ${n} ${n === 1 ? "attachment" : "attachments"} and the objective come to about ${tokens} tokens, over the ${budget} tokens one request can hold on this model — to send it the engine would have to drop the objective or some of the attachments. Nothing was sent; attach fewer or smaller parts.`);
|
|
487
491
|
}
|
|
488
|
-
export async function readObjectiveAttachments(prepared, inputId, blocked, window) {
|
|
492
|
+
export async function readObjectiveAttachments(prepared, inputId, blocked, window, imageSeat) {
|
|
489
493
|
if (blocked || prepared.userAttachments === undefined)
|
|
490
494
|
return { frames: [], chars: 0 };
|
|
495
|
+
const processor = await resolveImageProcessor(imageSeat);
|
|
491
496
|
const frames = await readUserAttachments({
|
|
492
497
|
screened: prepared.userAttachments,
|
|
493
498
|
inputId,
|
|
494
499
|
reader: prepared.modelFileReader,
|
|
495
500
|
judge: prepared.syntheticReadVerdict,
|
|
496
|
-
images: await admitUserAttachmentImages(prepared.userAttachments),
|
|
501
|
+
images: await admitUserAttachmentImages(prepared.userAttachments, processor),
|
|
497
502
|
cwd: prepared.cwdRef?.current,
|
|
498
503
|
mark: prepared.reminderMark,
|
|
499
504
|
counts: prepared.reminderDisclosureCounts,
|
|
@@ -501,6 +506,9 @@ export async function readObjectiveAttachments(prepared, inputId, blocked, windo
|
|
|
501
506
|
mentions: { bus: prepared.modBus, ...(agentIdOf(prepared.hookIdentity) !== undefined ? { agentId: agentIdOf(prepared.hookIdentity) } : {}) },
|
|
502
507
|
});
|
|
503
508
|
refuseFramesOverWindow(frames, prepared.harness.getModel(), window);
|
|
509
|
+
const unprocessed = firstUnprocessedOverTarget(frames.flatMap((f) => f.seed.content), processor);
|
|
510
|
+
if (unprocessed !== undefined)
|
|
511
|
+
prepared.imageUnprocessed(unprocessed);
|
|
504
512
|
return { frames, chars: frames.reduce((n, f) => n + f.seed.content.reduce((m, b) => m + (b.type === "text" ? b.text.length : 0), 0), 0) };
|
|
505
513
|
}
|
|
506
514
|
export const COMPACTION_RESTORE_PROBE_FACE = "compaction-restore";
|
|
@@ -2,7 +2,7 @@ import { type FileHandle } from "node:fs/promises";
|
|
|
2
2
|
import { type BoundFileObject, type ExecResult, type ExecutionEnv, ExecutionError, type ExecutionEnvExecOptions, FileError, type FileInfo, type Result } from "../harness/types.js";
|
|
3
3
|
import { type SecretEnvFinding } from "../../core/secret-env.js";
|
|
4
4
|
import type { EngineNotice } from "../../core/engine-notice.js";
|
|
5
|
-
import type { SymlinkChain } from "../harness/types.js";
|
|
5
|
+
import type { ExecutionEnvCapabilities, SymlinkChain } from "../harness/types.js";
|
|
6
6
|
import type { BackgroundHardKillOutcome, BackgroundShellCapability, BackgroundShellId, BackgroundPoll, BackgroundSpawnOptions } from "../../core/background-shell.js";
|
|
7
7
|
import { BackgroundShellError } from "../../core/background-shell.js";
|
|
8
8
|
import type { SchedulerCapability, ScheduledIntent, SchedulerContext, ScheduledTaskId, ScheduledTaskSummary } from "../../core/scheduler.js";
|
|
@@ -82,6 +82,9 @@ export declare function openSpoolPair(base: string): {
|
|
|
82
82
|
};
|
|
83
83
|
export declare class NodeExecutionEnv implements ExecutionEnv, BackgroundShellCapability, SchedulerCapability {
|
|
84
84
|
cwd: string;
|
|
85
|
+
/** `ExecutionEnv.capabilities`: the engine's own host — commands are this process's children on its own disk, not
|
|
86
|
+
* contained, not snapshotable; its resolver always answers; it does not keep the byte floor (no process confinement). */
|
|
87
|
+
readonly capabilities: ExecutionEnvCapabilities;
|
|
85
88
|
/** `ExecutionEnv.homeDir` = the `HOME` the shell child receives (its `~`/`$HOME`/`${HOME}` all expand to it), read LIVE off the same `shellEnv`-over-`inheritEnv` merge each exec gets; ABSENT when the
|
|
86
89
|
* child gets none (an allowlist that withholds it: `~` then falls back to passwd while `$HOME` is empty — two values, no single home, home-relative operands stay fail-closed). Residual: a per-exec `env.HOME` override. */
|
|
87
90
|
get homeDir(): string | undefined;
|
|
@@ -172,7 +175,9 @@ export declare class NodeExecutionEnv implements ExecutionEnv, BackgroundShellCa
|
|
|
172
175
|
* (Esc during a large Write — ctx.signal reaches here directly), ENOSPC, or a crash left the target as
|
|
173
176
|
* a torn prefix of the NEW content with the original unrecoverable. Post-fix contract: the target is
|
|
174
177
|
* either fully old or fully new; `aborted` means it was never touched. Known semantic change (same as
|
|
175
|
-
* CC): rename breaks a hard link — the other link keeps the old content.
|
|
178
|
+
* CC): rename breaks a hard link — the other link keeps the old content. The replacement is a new inode made
|
|
179
|
+
* by the writing process: its owner is the writer and its group follows the new-file rule, so the target's
|
|
180
|
+
* group bits can land on another group; no fchown (KL-3120-b). */
|
|
176
181
|
writeFile(path: string, content: string | Uint8Array, abortSignal?: AbortSignal): Promise<Result<void, FileError>>;
|
|
177
182
|
/** RB-221: the historical single-step in-place overwrite — kept for targets where
|
|
178
183
|
* staging+rename would change node identity (symlink chains, non-regular files) and as the
|
|
@@ -15,6 +15,16 @@ import { RollingTailBuffer, markTruncated, newStreamCursorState, sliceStreamIncr
|
|
|
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
|
+
const NODE_ENV_CAPABILITIES = Object.freeze({
|
|
19
|
+
isolation: false,
|
|
20
|
+
suspendable: false,
|
|
21
|
+
sharesProcessTable: true,
|
|
22
|
+
canonicalPathAuthoritative: true,
|
|
23
|
+
hostLocalPaths: true,
|
|
24
|
+
externalContentTarget: false,
|
|
25
|
+
io: true,
|
|
26
|
+
keepsReadFloor: false,
|
|
27
|
+
});
|
|
18
28
|
function resolvePath(cwd, path) {
|
|
19
29
|
if (isAbsolute(path))
|
|
20
30
|
return path;
|
|
@@ -314,6 +324,7 @@ export function openSpoolPair(base) {
|
|
|
314
324
|
}
|
|
315
325
|
export class NodeExecutionEnv {
|
|
316
326
|
cwd;
|
|
327
|
+
capabilities = NODE_ENV_CAPABILITIES;
|
|
317
328
|
get homeDir() {
|
|
318
329
|
return this.childEnvForRead()?.HOME;
|
|
319
330
|
}
|
|
@@ -886,7 +897,7 @@ export class NodeExecutionEnv {
|
|
|
886
897
|
const tmp = `${target}.tmp.${process.pid}.${randomUUID().replace(/-/g, "").slice(0, 12)}`;
|
|
887
898
|
let tmpDurable = false;
|
|
888
899
|
try {
|
|
889
|
-
const handle = await open(tmp, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | (constants.O_NOFOLLOW ?? 0));
|
|
900
|
+
const handle = await open(tmp, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | (constants.O_NOFOLLOW ?? 0), existingMode === undefined ? 0o666 : 0o600);
|
|
890
901
|
try {
|
|
891
902
|
await handle.writeFile(content, { signal: abortSignal });
|
|
892
903
|
if (existingMode !== undefined) {
|
|
@@ -339,7 +339,7 @@ export declare class AgentHarness<TSkill extends Skill = Skill, TPromptTemplate
|
|
|
339
339
|
private activeRun?;
|
|
340
340
|
private loopTrace?;
|
|
341
341
|
private onToolInputValidationFault?;
|
|
342
|
-
private
|
|
342
|
+
private toolResultMedia;
|
|
343
343
|
private resilience?;
|
|
344
344
|
private maxToolConcurrency?;
|
|
345
345
|
private streamingToolExecution?;
|
|
@@ -329,7 +329,7 @@ export class AgentHarness {
|
|
|
329
329
|
activeRun;
|
|
330
330
|
loopTrace;
|
|
331
331
|
onToolInputValidationFault;
|
|
332
|
-
|
|
332
|
+
toolResultMedia;
|
|
333
333
|
resilience;
|
|
334
334
|
maxToolConcurrency;
|
|
335
335
|
streamingToolExecution;
|
|
@@ -366,7 +366,11 @@ export class AgentHarness {
|
|
|
366
366
|
this.executeTool = options.executeTool;
|
|
367
367
|
this.loopTrace = options.loopTrace;
|
|
368
368
|
this.onToolInputValidationFault = options.onToolInputValidationFault;
|
|
369
|
-
this.
|
|
369
|
+
this.toolResultMedia = {
|
|
370
|
+
...(options.imageProcessor !== undefined ? { imageProcessor: options.imageProcessor } : {}),
|
|
371
|
+
...(options.onToolMediaRefused !== undefined ? { onToolMediaRefused: options.onToolMediaRefused } : {}),
|
|
372
|
+
...(options.onImageUnprocessed !== undefined ? { onImageUnprocessed: options.onImageUnprocessed } : {}),
|
|
373
|
+
};
|
|
370
374
|
this.resilience = options.resilience;
|
|
371
375
|
this.maxToolConcurrency = options.maxToolConcurrency;
|
|
372
376
|
this.streamingToolExecution = options.streamingToolExecution;
|
|
@@ -685,7 +689,7 @@ export class AgentHarness {
|
|
|
685
689
|
...(this.abortResultDetails !== undefined ? { abortResultDetails: this.abortResultDetails } : {}),
|
|
686
690
|
...(this.executeTool !== undefined ? { executeTool: this.executeTool } : {}),
|
|
687
691
|
...(this.onToolInputValidationFault !== undefined ? { onToolInputValidationFault: this.onToolInputValidationFault } : {}),
|
|
688
|
-
...
|
|
692
|
+
...this.toolResultMedia,
|
|
689
693
|
...(this.resilience !== undefined ? { resilience: this.resilience } : {}),
|
|
690
694
|
...(this.maxToolConcurrency !== undefined ? { maxToolConcurrency: this.maxToolConcurrency } : {}),
|
|
691
695
|
...(this.streamingToolExecution === true && (this.getHandlers("tool_call")?.size ?? 0) === 0
|
|
@@ -1307,7 +1311,7 @@ export class AgentHarness {
|
|
|
1307
1311
|
return patch;
|
|
1308
1312
|
}
|
|
1309
1313
|
finalizeToolCall(toolCall, args, executed) {
|
|
1310
|
-
return finalizeToolOutcome(toolCall, executed, (result, isError) => this.afterToolCallHook(toolCall, args, result, isError), this.
|
|
1314
|
+
return finalizeToolOutcome(toolCall, executed, (result, isError) => this.afterToolCallHook(toolCall, args, result, isError), this.toolResultMedia);
|
|
1311
1315
|
}
|
|
1312
1316
|
async callTool(toolCall, signal, admit) {
|
|
1313
1317
|
const run = this.activeRun;
|
|
@@ -340,7 +340,8 @@ export interface ExecutionEnvExecOptions {
|
|
|
340
340
|
* behavior. Envs without detach support ignore this (opt-in, backward compatible).
|
|
341
341
|
*/
|
|
342
342
|
autoBackgroundOnTimeout?: boolean;
|
|
343
|
-
/** VENDORED EDIT (the byte floor) — the read-deny table in force for the call starting this command ({@link ReadFloor}); what its processes OPEN is the environment's to keep
|
|
343
|
+
/** VENDORED EDIT (the byte floor) — the read-deny table in force for the call starting this command ({@link ReadFloor}); what its processes OPEN is the environment's to keep,
|
|
344
|
+
* and whether it keeps it is its declaration ({@link ExecutionEnvCapabilities.keepsReadFloor}). Carried by every start whose output the engine relays to the model. */
|
|
344
345
|
readFloor?: ReadFloor;
|
|
345
346
|
}
|
|
346
347
|
/** The read-deny table one command start carries ({@link ExecutionEnvExecOptions.readFloor}); what an environment keeps of it is INTEGRATION-CORE §11.1. */
|
|
@@ -490,8 +491,114 @@ export interface Shell {
|
|
|
490
491
|
/** Release shell resources. Must be best-effort and must not throw or reject. */
|
|
491
492
|
cleanup(): Promise<void>;
|
|
492
493
|
}
|
|
494
|
+
/**
|
|
495
|
+
* #2891 — what an execution environment can do and where its actions land: the ONE place each of these questions is
|
|
496
|
+
* answered, declared by the ADAPTER on every environment ({@link ExecutionEnv.capabilities}), local or remote.
|
|
497
|
+
*
|
|
498
|
+
* Every key is REQUIRED and has no default reading: for each one, either answer an absent value could be given is
|
|
499
|
+
* wrong for some environment, so an adapter states it. A value that is absent, not a boolean, or cannot be received (a
|
|
500
|
+
* throwing getter, a Proxy — a JS adapter's block) — and a member outside the eight keys — is announced once per run at
|
|
501
|
+
* the admission point (`config.execution_env_capability_invalid`, `detail.key` naming it, or `capabilities` for a block
|
|
502
|
+
* that is no object or cannot be received), and each reader takes that key's SAFE side, written beside the readers
|
|
503
|
+
* (`UNDECLARED_CAPABILITY_READING`, `src/core/remote-env.ts`). Every key is read through its one reader there.
|
|
504
|
+
*
|
|
505
|
+
* What an INTERFACE answers is a different question: whether a group of methods can be called (the remote seam's
|
|
506
|
+
* lifecycle, a background shell, a scheduler, an optional filesystem method). Implementing a group of methods never
|
|
507
|
+
* declares a capability, and a capability never stands in for a method.
|
|
508
|
+
*
|
|
509
|
+
* The block is a constant of the adapter: the engine receives it ONCE per environment object (at its first read, a
|
|
510
|
+
* run's admission point) into a frozen copy every reader reads; a later change by the host is never read.
|
|
511
|
+
*/
|
|
512
|
+
export interface ExecutionEnvCapabilities {
|
|
513
|
+
/** True iff the commands run inside a sandbox that IS the security boundary (container, microVM, pod); false for
|
|
514
|
+
* a real target (the engine's own host, an SSH host, a device). Every consumer of a `true` here RELAXES something
|
|
515
|
+
* (autonomy, a policy tier, a containment leg the sandbox is then answerable for), so only the boolean `true`
|
|
516
|
+
* counts. Undeclared ⇒ `false`. Read through `isIsolated`. */
|
|
517
|
+
readonly isolation: boolean;
|
|
518
|
+
/** True iff the environment can be snapshot (`suspendVM`) and restored; false for one that cannot (a local
|
|
519
|
+
* process, an SSH host, a device).
|
|
520
|
+
*
|
|
521
|
+
* ⚠️ LOAD-BEARING INVARIANT: `suspendable: false` on a remote environment also asserts the workspace is
|
|
522
|
+
* EXTERNALLY DURABLE — it persists on the target across the environment object's lifetime (true for SSH hosts and
|
|
523
|
+
* devices). The durable-park-only suspend degrade rests on this: it skips `suspendVM` and trusts the factory to
|
|
524
|
+
* reconnect to the SAME workspace on resume. An adapter for a non-suspendable EPHEMERAL backend (a snapshot-less
|
|
525
|
+
* container torn down with its transport) must NOT be modeled as `suspendable: false` remote — it would silently
|
|
526
|
+
* take the park-only branch and resume onto a fresh empty workspace. Model such a backend as a per-task
|
|
527
|
+
* environment without durable suspend instead (the human gate refuses it), or split this key before building one.
|
|
528
|
+
* Undeclared ⇒ neither suspendable nor parkable. Read through `declaredSuspend` (three states) and `isSuspendable`
|
|
529
|
+
* (a declared `true` with the remote interface and its restore surface). */
|
|
530
|
+
readonly suspendable: boolean;
|
|
531
|
+
/** True iff the commands this environment runs are processes on a table that holds THIS process — the table the
|
|
532
|
+
* engine itself and the processes above it are on, so a kill the model writes there can reach them. `true` for an
|
|
533
|
+
* environment that spawns the commands as this process's own descendants (`NodeExecutionEnv`, a host lane) and for
|
|
534
|
+
* one whose commands run in a PID namespace that contains this process's (the host of the container the engine
|
|
535
|
+
* runs in); `false` only for one whose commands run where this process is not: another machine (SSH host, device,
|
|
536
|
+
* cloud sandbox) or a PID namespace this process is not in (a sandbox container, a pod). Not {@link isolation}: a
|
|
537
|
+
* non-isolated SSH host is a real machine and still another table. The self-preservation guard of the Bash tool
|
|
538
|
+
* asks its question exactly when this is `true`, and does not ask where it is `false`.
|
|
539
|
+
*
|
|
540
|
+
* What a `true` buys is the guard's question exactly as a `NodeExecutionEnv` gets it, limits included: on this
|
|
541
|
+
* process's own table, of the platform's `pgrep`, with the kill's words as written, from this process's own
|
|
542
|
+
* working directory. It is put as for this process's descendants, so for commands on the same table that are not
|
|
543
|
+
* (SSH to `localhost`) BSD's `pgrep` leaves its OWN caller's ancestors out where the real kill would not, and from
|
|
544
|
+
* an enclosing namespace the question sees only this process's namespace, not the ancestors above it.
|
|
545
|
+
*
|
|
546
|
+
* Undeclared ⇒ the guard refuses every pattern kill that needs the question on this environment (`pkill -P $$`
|
|
547
|
+
* runs), naming this declaration. Read through `processTableOf`. */
|
|
548
|
+
readonly sharesProcessTable: boolean;
|
|
549
|
+
/** True iff this environment's {@link FileSystem.canonicalPath} is the AUTHORITY on where a path lands — it
|
|
550
|
+
* answers for the very filesystem the commands run on, so a failure to answer is a failure of the resolver rather
|
|
551
|
+
* than a namespace it cannot see into. A `true` makes the read boundary's execute-time recheck REFUSE a chain its
|
|
552
|
+
* resolver cannot answer at all instead of passing the written spelling through; `false` keeps the lexical
|
|
553
|
+
* verdict for a chain the resolver answers `not_supported` (no file face). A resolver that FAILS (any other
|
|
554
|
+
* non-answer) is a failure either way. `NodeExecutionEnv` declares `true` (its resolver always answers `/`, so the
|
|
555
|
+
* arm has no case to fire on); an environment with no path resolution surface declares `false`. Undeclared ⇒
|
|
556
|
+
* `true` (silence refuses). Read through `canonicalPathIsAuthoritative`. */
|
|
557
|
+
readonly canonicalPathAuthoritative: boolean;
|
|
558
|
+
/** True iff a path this environment names is the same file on the ENGINE HOST's filesystem — the engine may
|
|
559
|
+
* present this environment's cwd as a host path (the workflow workspace observer's `worktreeDir`) and record
|
|
560
|
+
* host-path receipts for it. `true` for `NodeExecutionEnv` and for a host lane that drives the engine's own
|
|
561
|
+
* machine; `false` for an environment whose paths never map onto the host (an in-memory environment, a sandbox
|
|
562
|
+
* or container the host does not mount at the same paths, another machine). Undeclared ⇒ `false`. Read through
|
|
563
|
+
* `pathsAreHostLocal`. */
|
|
564
|
+
readonly hostLocalPaths: boolean;
|
|
565
|
+
/** True iff content produced by THIS environment (every FileSystem / Shell result — stdout, file bytes, listings,
|
|
566
|
+
* names) originates from a target OUTSIDE the deployment's trust boundary (a personal device, an unmanaged host).
|
|
567
|
+
* `true` feeds three existing channels, no new vocabulary:
|
|
568
|
+
* - memory: the run's hand-tool results are treated as external-class content — the session mark
|
|
569
|
+
* (`memory.session_polluted`) and the origin carriage at harvest, via the same fold `execIsExternalContent`
|
|
570
|
+
* upgrades through (this key ORs into that fold for the run);
|
|
571
|
+
* - env facts / prompt renderer: one declarative line disclosing the execution locus and trust posture;
|
|
572
|
+
* - audit: TaskResult / checkpoint carry it implicitly through `WorkspaceHandle{provider, deviceId}`.
|
|
573
|
+
* Suspend / resume: the run-level fold is PRESENCE-persisted on the checkpoint (`CheckpointState.externalContentTarget`,
|
|
574
|
+
* monotonic) and resume joins persisted OR live declaration — a run minted under a declaring adapter never
|
|
575
|
+
* silently downgrades on an undeclaring or older one. ONE declaration, two readers: the content-class fold above
|
|
576
|
+
* (no gate, policy or roster reads that fold) and the cross-boundary taint (it arms the run tree's taint bit; a
|
|
577
|
+
* call's `env` leg is judged by whether the environment THAT CALL reaches declares this, never by the
|
|
578
|
+
* fold). ORTHOGONAL to {@link isolation}: an SSH environment to an organization-managed build host can be
|
|
579
|
+
* non-isolated and still declare `false`. Undeclared ⇒ each consumer's safe side: the content fold reads it as outside,
|
|
580
|
+
* and a call that reaches the environment owes what reaching the target and what leaving it both owe. Read through
|
|
581
|
+
* `targetIsExternal` (three states). */
|
|
582
|
+
readonly externalContentTarget: boolean;
|
|
583
|
+
/** True iff the filesystem and shell faces reach a target. `false` only for a placeholder whose every operation
|
|
584
|
+
* refuses (each filesystem operation `not_supported`, every `exec` `shell_unavailable` — `StubExecutionEnv`, the
|
|
585
|
+
* environment of a run without hands). Undeclared ⇒ no shell face mounts, and the project marker is still read
|
|
586
|
+
* through it, never past its read limits. Read through `performsIo` (three states). */
|
|
587
|
+
readonly io: boolean;
|
|
588
|
+
/** True iff this environment keeps the byte floor a command start carries ({@link ExecutionEnvExecOptions.readFloor}):
|
|
589
|
+
* every path its `denies` answers non-null for stays unreadable to every program the command runs, judged where the
|
|
590
|
+
* environment itself resolves the path — or the environment refuses a start whose whole table it cannot keep
|
|
591
|
+
* (`spawn_error`, naming the row) rather than run with fewer rows (INTEGRATION-CORE §11.1). `false` for an
|
|
592
|
+
* environment that cannot confine a process (`NodeExecutionEnv`, a host lane, an SSH host, a device): a run whose
|
|
593
|
+
* read-deny table is non-empty on such an environment is announced (`config.read_deny_floor_unkept`), or refused
|
|
594
|
+
* at prepare when the deployment sets `RunnerDeps.readDenyFloorRequired`. `StubExecutionEnv` declares `true`:
|
|
595
|
+
* it refuses every start, so no byte can be read through it. Undeclared ⇒ `false`. Read through `keepsReadFloor`. */
|
|
596
|
+
readonly keepsReadFloor: boolean;
|
|
597
|
+
}
|
|
493
598
|
/** Filesystem and process execution environment used by the harness. */
|
|
494
599
|
export interface ExecutionEnv extends FileSystem, Shell {
|
|
600
|
+
/** What this environment can do and where its actions land — {@link ExecutionEnvCapabilities}, every key required. */
|
|
601
|
+
readonly capabilities: ExecutionEnvCapabilities;
|
|
495
602
|
/**
|
|
496
603
|
* design/164 件四 — the environment's PLATFORM LIFETIME in milliseconds: how long this sandbox/VM is
|
|
497
604
|
* allowed to exist before the platform reclaims it, counted from {@link lifetimeStartedAt}. Declared by
|
|
@@ -522,34 +629,6 @@ export interface ExecutionEnv extends FileSystem, Shell {
|
|
|
522
629
|
* mechanism exists to prevent.
|
|
523
630
|
*/
|
|
524
631
|
readonly lifetimeStartedAt?: number;
|
|
525
|
-
/**
|
|
526
|
-
* #211 (design/199 seam) — does this environment's path NAMESPACE live on the CONTROL-PLANE HOST's
|
|
527
|
-
* filesystem? Declared by the ADAPTER: `false` for a virtual/sandboxed env whose paths never map
|
|
528
|
-
* onto the host (an in-memory env, a container the host cannot mount) — consumers that record
|
|
529
|
-
* host-path receipts (the workflow workspace observer's `worktreeDir`) then refuse to present this
|
|
530
|
-
* env's cwd as a host path. Omitted ⇒ the historical structural inference stays in force
|
|
531
|
-
* (isRemoteExecutionEnv shape detection; a plain NodeExecutionEnv is host-local). `true` is a
|
|
532
|
-
* harmless explicit spelling of the local default.
|
|
533
|
-
*/
|
|
534
|
-
readonly hostLocalPaths?: boolean;
|
|
535
|
-
/**
|
|
536
|
-
* design/380 O9 — declared by the ADAPTER: content produced by THIS env (every FileSystem/Shell
|
|
537
|
-
* result — stdout, file bytes, listings, names) originates from a target OUTSIDE the deployment's
|
|
538
|
-
* trust boundary (a personal device, an unmanaged host). Omitted ⇒ historic behavior (trusted-side
|
|
539
|
-
* results). `true` feeds three EXISTING channels, no new vocabulary:
|
|
540
|
-
* - memory: the run's hand-tool results are treated as external-class content — the session mark
|
|
541
|
-
* (`memory.session_polluted`) + the design/336 origin carriage at harvest, via the same fold
|
|
542
|
-
* `execIsExternalContent` upgrades through (this flag ORs into that fold for the run);
|
|
543
|
-
* - env facts / prompt renderer: one declarative line disclosing the execution locus + trust posture;
|
|
544
|
-
* - audit: TaskResult/checkpoint carry it implicitly through WorkspaceHandle{provider, deviceId}.
|
|
545
|
-
* Suspend/resume: the run-level fold is PRESENCE-persisted on the checkpoint
|
|
546
|
-
* (`CheckpointState.externalContentTarget`, monotonic) and resume joins persisted OR live
|
|
547
|
-
* declaration — a run minted under a declaring adapter never silently downgrades on an
|
|
548
|
-
* undeclared/older one. ONE declaration, two readers: the content-class fold above (the design/378 red line binds that fold — no gate/policy/roster reads it) and the
|
|
549
|
-
* cross-boundary taint (it arms the run tree's taint bit; a call's `env` leg is judged by whether the env it reaches declares this flag AT THAT MOMENT, never by the fold).
|
|
550
|
-
* ORTHOGONAL to `capabilities.isolation` — an SSH env to an organization-managed build host can be non-isolated yet omit this flag.
|
|
551
|
-
*/
|
|
552
|
-
readonly externalContentTarget?: boolean;
|
|
553
632
|
/**
|
|
554
633
|
* #644 — declared by the ADAPTER: the HOME DIRECTORY of the user this environment runs as, as an absolute
|
|
555
634
|
* path in the environment's own namespace. The base a `~/`-relative permission rule (`Edit(~/.ssh/**)`)
|
|
@@ -1552,6 +1631,10 @@ export interface AgentHarnessOptions<TSkill extends Skill = Skill, TPromptTempla
|
|
|
1552
1631
|
/** Loop-config pass-through — see `AgentLoopConfig.onToolMediaRefused` (the tool-result seat's account of the media it
|
|
1553
1632
|
* refused); the harness's own finalization of a resumed approved call reports through the same sink. */
|
|
1554
1633
|
onToolMediaRefused?: import("../loop/types.js").AgentLoopConfig["onToolMediaRefused"];
|
|
1634
|
+
/** Loop-config pass-through — see `AgentLoopConfig.imageProcessor` (the tool-result seat's processor). */
|
|
1635
|
+
imageProcessor?: import("../loop/types.js").AgentLoopConfig["imageProcessor"];
|
|
1636
|
+
/** Loop-config pass-through — see `AgentLoopConfig.onImageUnprocessed` (an image that goes on unprocessed over the soft target). */
|
|
1637
|
+
onImageUnprocessed?: import("../loop/types.js").AgentLoopConfig["onImageUnprocessed"];
|
|
1555
1638
|
/**
|
|
1556
1639
|
* design/131 (拍): per-task resilience intent flags, forwarded to every provider
|
|
1557
1640
|
* call (`StreamOptions.resilience`) so the deployment's decorator stack (degrading / failover /
|
|
@@ -71,12 +71,9 @@ export type LoopTerminalReason =
|
|
|
71
71
|
* path and was reported as a plain `"completed"`, indistinguishable from a turn that genuinely had
|
|
72
72
|
* nothing left to do.
|
|
73
73
|
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* 成功恢复过的畸形调用,和刚刚才第一次触发畸形调用但恰好撞上早已用尽的预算,在这个 reason 面前不可
|
|
78
|
-
* 区分;调用方若需要"最近是否连续失败"这类更细的语义,需要自行在更高层维护窗口计数,这个 reason 只
|
|
79
|
-
* 承诺"预算耗尽"这一件事。 */
|
|
74
|
+
* `malformedToolUseRetries` 数的是**连续**畸形轮:任何带可解析工具调用的轮(即工具真的跑了)都把它
|
|
75
|
+
* 清零,与上游「重试至多两次、成功即复位」同形——"exhausted" 说的是"刚刚连续 maxRetries + 1 个轮次
|
|
76
|
+
* 全部畸形",不是"这个 run 总共累计过多少次畸形"。早先已恢复成功的畸形调用不再占用后来的预算。 */
|
|
80
77
|
| "malformed_tool_use_exhausted"
|
|
81
78
|
/** RB-258(RB-206 口径追查的衍生发现;RB-206 的同族对仗):the model kept ending its turn on the
|
|
82
79
|
* provider's output cap (`length`) with no tool calls, and the bounded truncated-output continue
|
|
@@ -90,9 +87,9 @@ export type LoopTerminalReason =
|
|
|
90
87
|
* - Only the CONFIGURED lane reports it. With `recovery.truncatedOutput` absent (the loop default
|
|
91
88
|
* is OFF) there is no budget to exhaust, so a `length` stop still ends as a plain `completed` —
|
|
92
89
|
* the pre-④b behavior, unchanged.
|
|
93
|
-
* - `truncatedOutputContinues` counts CONSECUTIVE nudges and RESETS on any non-`length` turn (
|
|
94
|
-
* `malformedToolUseRetries
|
|
95
|
-
* `length` maxContinues+1 times in a row", not "this run has burnt N recoveries in total".
|
|
90
|
+
* - `truncatedOutputContinues` counts CONSECUTIVE nudges and RESETS on any non-`length` turn (as
|
|
91
|
+
* `malformedToolUseRetries` resets on any turn whose tool calls ran). So this reason means "the model
|
|
92
|
+
* just ended `length` maxContinues+1 times in a row", not "this run has burnt N recoveries in total".
|
|
96
93
|
* - Like every other terminal, it stops the loop BEFORE drain point B — a follow-up queue / Stop-hook
|
|
97
94
|
* continuation no longer gets consulted on this path. That is the point (a stop-gate rescue would
|
|
98
95
|
* re-enter the same wall with a spent budget), and queued follow-ups stay queued for the next
|
|
@@ -223,13 +220,16 @@ export declare const TOOL_INPUT_VALIDATION_TIMEOUT_MS = 10000;
|
|
|
223
220
|
* same function, so the two cannot drift into two dialects of one finalization: the `afterToolCall` patch
|
|
224
221
|
* (content / details / terminate / isError), the D4 posture on a throwing hook, the delivery mark, and last
|
|
225
222
|
* the media admission — the tool-result seat every supply of media reaches after the last hand that can change
|
|
226
|
-
* it (`
|
|
227
|
-
*
|
|
223
|
+
* it (`toolResultMediaBlocks`, then `admitToolResultMediaBlocks` with the run's image processor `media.imageProcessor`,
|
|
224
|
+
* resolved only once a block claims media): a refused block becomes its text placeholder in the result,
|
|
225
|
+
* `media.onToolMediaRefused` hears the call's refusals once, and `media.onImageUnprocessed` hears an image that goes on
|
|
226
|
+
* unprocessed over the soft target. `after` absent and no media ⇒ the executed outcome stands as is (same object), with
|
|
227
|
+
* nothing awaited.
|
|
228
228
|
*/
|
|
229
229
|
export declare function finalizeToolOutcome<C extends {
|
|
230
230
|
id: string;
|
|
231
231
|
name: string;
|
|
232
|
-
}>(toolCall: C, executed: ExecutedToolCallOutcome, after: ((result: AgentToolResult<unknown>, isError: boolean) => Promise<AfterToolCallResult | undefined>) | undefined,
|
|
232
|
+
}>(toolCall: C, executed: ExecutedToolCallOutcome, after: ((result: AgentToolResult<unknown>, isError: boolean) => Promise<AfterToolCallResult | undefined>) | undefined, media?: Pick<AgentLoopConfig, "imageProcessor" | "onToolMediaRefused" | "onImageUnprocessed">): Promise<ExecutedToolCallOutcome & {
|
|
233
233
|
toolCall: C;
|
|
234
234
|
}>;
|
|
235
235
|
export {};
|
|
@@ -7,7 +7,8 @@ import { isErrorLike, readMember, readOwnMembers, thrownMarksOf } from "../../co
|
|
|
7
7
|
import { egressThrownText, egressValue } from "../../core/untrusted-egress.js";
|
|
8
8
|
import { remoteWords } from "../../core/protocol-http-auth.js";
|
|
9
9
|
import { types } from "node:util";
|
|
10
|
-
import {
|
|
10
|
+
import { admitToolResultMediaBlocks, firstUnprocessedOverTarget, toolResultMediaBlocks } from "../../core/image-admission.js";
|
|
11
|
+
import { resolveImageProcessor } from "../../core/image-downsample.js";
|
|
11
12
|
import { IMAGE_REFUSAL_KIND, imageRefusalRemoves } from "../llm/rejected-images.js";
|
|
12
13
|
const IMAGE_REFUSAL_RETRIES = 3;
|
|
13
14
|
function appendTextDeltaToAssistantMessage(message, contentIndex, delta) {
|
|
@@ -459,6 +460,8 @@ async function runTurnPhases(state, signal, turnController, publishSeat, retract
|
|
|
459
460
|
withhold?.discard();
|
|
460
461
|
await withhold?.flush();
|
|
461
462
|
state.newMessages.push(message);
|
|
463
|
+
if (message.content.some((c) => c.type === "toolCall"))
|
|
464
|
+
state.malformedToolUseRetries = 0;
|
|
462
465
|
if (message.staticReasoningCut === true)
|
|
463
466
|
state.staticReasoningCutRecoveries++;
|
|
464
467
|
if (interruptOwnsTurn) {
|
|
@@ -565,7 +568,7 @@ async function runTurnPhases(state, signal, turnController, publishSeat, retract
|
|
|
565
568
|
}
|
|
566
569
|
const malformed = state.config.recovery?.malformedToolUse;
|
|
567
570
|
if (malformed && message.stopReason === "toolUse" && toolCalls.length === 0 && state.pendingMessages.length === 0) {
|
|
568
|
-
if (state.malformedToolUseRetries < (malformed.maxRetries ??
|
|
571
|
+
if (state.malformedToolUseRetries < (malformed.maxRetries ?? 2)) {
|
|
569
572
|
state.malformedToolUseRetries++;
|
|
570
573
|
state.pendingMessages = [createMalformedToolUseNudge()];
|
|
571
574
|
return { kind: "ran", recovered: "malformed_tool_use_retry" };
|
|
@@ -723,30 +726,20 @@ async function streamAssistantResponse(context, config, signal, emit, streamFn,
|
|
|
723
726
|
const perCallMaxTokens = config.maxTokensPerCall?.();
|
|
724
727
|
const perCallStallTimeouts = config.stallTimeoutsPerCall?.();
|
|
725
728
|
if (signal?.aborted) {
|
|
726
|
-
const abortedBeforeDispatch =
|
|
727
|
-
role: "assistant",
|
|
728
|
-
content: [{ type: "text", text: "" }],
|
|
729
|
-
api: config.model.api,
|
|
730
|
-
provider: config.model.provider,
|
|
731
|
-
model: config.model.id,
|
|
732
|
-
stopReason: "aborted",
|
|
733
|
-
timestamp: Date.now(),
|
|
734
|
-
usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } },
|
|
735
|
-
usageMissing: true,
|
|
736
|
-
};
|
|
729
|
+
const abortedBeforeDispatch = engineAbortedFinal(config.model);
|
|
737
730
|
context.messages.push(abortedBeforeDispatch);
|
|
738
731
|
await emit({ type: "message_start", message: { ...abortedBeforeDispatch } });
|
|
739
732
|
await emit({ type: "message_end", message: abortedBeforeDispatch });
|
|
740
733
|
return { message: abortedBeforeDispatch, cutAtSettle: true };
|
|
741
734
|
}
|
|
742
|
-
const response =
|
|
735
|
+
const response = cutByTurnSignal(() => streamFunction(config.model, llmContext, {
|
|
743
736
|
...config,
|
|
744
737
|
...(perCallMaxTokens !== undefined ? { maxTokens: perCallMaxTokens, maxTokensDynamic: true } : {}),
|
|
745
738
|
...(perCallStallTimeouts !== undefined ? { stallTimeouts: perCallStallTimeouts } : {}),
|
|
746
739
|
...(staticReasoningCutDowngrade === true ? { staticReasoningCutDowngrade: true } : {}),
|
|
747
740
|
apiKey: resolvedApiKey,
|
|
748
741
|
signal,
|
|
749
|
-
});
|
|
742
|
+
}), signal, config.model);
|
|
750
743
|
let partialMessage = null;
|
|
751
744
|
let addedPartial = false;
|
|
752
745
|
for await (const event of response) {
|
|
@@ -818,6 +811,136 @@ async function streamAssistantResponse(context, config, signal, emit, streamFn,
|
|
|
818
811
|
await emit({ type: "message_end", message: finalMessage });
|
|
819
812
|
return { message: finalMessage, cutAtSettle };
|
|
820
813
|
}
|
|
814
|
+
function engineAbortedFinal(model) {
|
|
815
|
+
return {
|
|
816
|
+
role: "assistant",
|
|
817
|
+
content: [{ type: "text", text: "" }],
|
|
818
|
+
api: model.api,
|
|
819
|
+
provider: model.provider,
|
|
820
|
+
model: model.id,
|
|
821
|
+
stopReason: "aborted",
|
|
822
|
+
timestamp: Date.now(),
|
|
823
|
+
usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } },
|
|
824
|
+
usageMissing: true,
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
function cutByTurnSignal(open, signal, model) {
|
|
828
|
+
const steps = [];
|
|
829
|
+
let wake;
|
|
830
|
+
let answered = false;
|
|
831
|
+
let settled = false;
|
|
832
|
+
let resolveFinal;
|
|
833
|
+
let rejectFinal;
|
|
834
|
+
const final = new Promise((resolve, reject) => ((resolveFinal = resolve), (rejectFinal = reject)));
|
|
835
|
+
final.catch(() => undefined);
|
|
836
|
+
const deliver = (step) => {
|
|
837
|
+
steps.push(step);
|
|
838
|
+
wake?.();
|
|
839
|
+
};
|
|
840
|
+
let iterator;
|
|
841
|
+
let letGo = false;
|
|
842
|
+
const release = () => {
|
|
843
|
+
letGo = true;
|
|
844
|
+
const it = iterator;
|
|
845
|
+
iterator = undefined;
|
|
846
|
+
if (it?.return !== undefined)
|
|
847
|
+
void Promise.resolve(it).then((held) => held.return?.()).catch(() => undefined);
|
|
848
|
+
};
|
|
849
|
+
const settle = (outcome) => {
|
|
850
|
+
if (settled)
|
|
851
|
+
return;
|
|
852
|
+
settled = true;
|
|
853
|
+
signal?.removeEventListener("abort", onAbort);
|
|
854
|
+
if ("message" in outcome)
|
|
855
|
+
resolveFinal(outcome.message);
|
|
856
|
+
else
|
|
857
|
+
rejectFinal(outcome.error);
|
|
858
|
+
};
|
|
859
|
+
const onAbort = () => void setImmediate(() => {
|
|
860
|
+
if (settled)
|
|
861
|
+
return;
|
|
862
|
+
const shell = engineAbortedFinal(model);
|
|
863
|
+
if (!answered) {
|
|
864
|
+
answered = true;
|
|
865
|
+
deliver({ event: { type: "error", reason: "aborted", error: shell } });
|
|
866
|
+
deliver("end");
|
|
867
|
+
}
|
|
868
|
+
settle({ message: shell });
|
|
869
|
+
release();
|
|
870
|
+
});
|
|
871
|
+
if (signal?.aborted)
|
|
872
|
+
onAbort();
|
|
873
|
+
else
|
|
874
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
875
|
+
void (async () => {
|
|
876
|
+
try {
|
|
877
|
+
const inner = await open();
|
|
878
|
+
const it = (iterator = inner[Symbol.asyncIterator]());
|
|
879
|
+
if (letGo)
|
|
880
|
+
return release();
|
|
881
|
+
for (;;) {
|
|
882
|
+
const step = await it.next();
|
|
883
|
+
if (letGo)
|
|
884
|
+
return;
|
|
885
|
+
if (step.done === true)
|
|
886
|
+
break;
|
|
887
|
+
const event = step.value;
|
|
888
|
+
deliver({ event });
|
|
889
|
+
if (event.type !== "done" && event.type !== "error")
|
|
890
|
+
continue;
|
|
891
|
+
answered = true;
|
|
892
|
+
settle({ message: await inner.result() });
|
|
893
|
+
return release();
|
|
894
|
+
}
|
|
895
|
+
iterator = undefined;
|
|
896
|
+
if (!answered) {
|
|
897
|
+
answered = true;
|
|
898
|
+
deliver("end");
|
|
899
|
+
settle({ message: await inner.result() });
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
catch (error) {
|
|
903
|
+
if (!answered) {
|
|
904
|
+
iterator = undefined;
|
|
905
|
+
answered = true;
|
|
906
|
+
deliver({ error });
|
|
907
|
+
}
|
|
908
|
+
else
|
|
909
|
+
release();
|
|
910
|
+
settle({ error });
|
|
911
|
+
}
|
|
912
|
+
finally {
|
|
913
|
+
deliver("end");
|
|
914
|
+
}
|
|
915
|
+
})();
|
|
916
|
+
return {
|
|
917
|
+
async *[Symbol.asyncIterator]() {
|
|
918
|
+
let readToEnd = false;
|
|
919
|
+
try {
|
|
920
|
+
for (;;) {
|
|
921
|
+
const step = steps.shift();
|
|
922
|
+
if (step === undefined) {
|
|
923
|
+
await new Promise((resolve) => (wake = resolve));
|
|
924
|
+
wake = undefined;
|
|
925
|
+
continue;
|
|
926
|
+
}
|
|
927
|
+
if (step === "end")
|
|
928
|
+
return void (readToEnd = true);
|
|
929
|
+
if ("error" in step)
|
|
930
|
+
throw step.error;
|
|
931
|
+
yield step.event;
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
finally {
|
|
935
|
+
if (!readToEnd) {
|
|
936
|
+
signal?.removeEventListener("abort", onAbort);
|
|
937
|
+
release();
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
},
|
|
941
|
+
result: () => final,
|
|
942
|
+
};
|
|
943
|
+
}
|
|
821
944
|
async function executeToolCalls(currentContext, assistantMessage, config, signal, emit, executor) {
|
|
822
945
|
const toolCalls = assistantMessage.content.filter((c) => c.type === "toolCall");
|
|
823
946
|
if (config.toolExecution === "sequential") {
|
|
@@ -1570,9 +1693,9 @@ async function executePreparedWithDisclosure(currentContext, assistantMessage, p
|
|
|
1570
1693
|
function finalizeExecutedToolCall(currentContext, assistantMessage, prepared, executed, config, signal) {
|
|
1571
1694
|
return finalizeToolOutcome(prepared.toolCall, executed, config.afterToolCall === undefined
|
|
1572
1695
|
? undefined
|
|
1573
|
-
: (result, isError) => config.afterToolCall({ assistantMessage, toolCall: prepared.toolCall, args: prepared.args, result, isError, context: currentContext }, signal), config
|
|
1696
|
+
: (result, isError) => config.afterToolCall({ assistantMessage, toolCall: prepared.toolCall, args: prepared.args, result, isError, context: currentContext }, signal), config);
|
|
1574
1697
|
}
|
|
1575
|
-
export async function finalizeToolOutcome(toolCall, executed, after,
|
|
1698
|
+
export async function finalizeToolOutcome(toolCall, executed, after, media) {
|
|
1576
1699
|
let result = executed.result;
|
|
1577
1700
|
let isError = executed.isError;
|
|
1578
1701
|
const deliveryMark = readDeliveryFailureMark(executed.result.details);
|
|
@@ -1598,13 +1721,22 @@ export async function finalizeToolOutcome(toolCall, executed, after, onMediaRefu
|
|
|
1598
1721
|
result = { ...result, details };
|
|
1599
1722
|
}
|
|
1600
1723
|
}
|
|
1601
|
-
const
|
|
1602
|
-
if (
|
|
1603
|
-
const
|
|
1724
|
+
const mediaBlocks = toolResultMediaBlocks(result.content);
|
|
1725
|
+
if (mediaBlocks !== undefined) {
|
|
1726
|
+
const processor = await resolveImageProcessor(media?.imageProcessor);
|
|
1727
|
+
const admitted = await admitToolResultMediaBlocks(mediaBlocks, toolCall.name, processor);
|
|
1604
1728
|
result = { ...result, content: admitted.content };
|
|
1729
|
+
const unprocessed = firstUnprocessedOverTarget(admitted.content, processor);
|
|
1605
1730
|
if (admitted.refused.length > 0) {
|
|
1606
1731
|
try {
|
|
1607
|
-
|
|
1732
|
+
media?.onToolMediaRefused?.({ toolName: toolCall.name, toolCallId: toolCall.id, refused: admitted.refused });
|
|
1733
|
+
}
|
|
1734
|
+
catch {
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
if (unprocessed !== undefined) {
|
|
1738
|
+
try {
|
|
1739
|
+
media?.onImageUnprocessed?.(unprocessed);
|
|
1608
1740
|
}
|
|
1609
1741
|
catch {
|
|
1610
1742
|
}
|