@myagentroam/agent 0.11.33 → 0.11.35
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/dist/cli/catalog-file.d.ts +78 -0
- package/dist/cli/catalog-file.js +102 -0
- package/dist/cli/codex-auth-file.d.ts +1 -1
- package/dist/cli/codex-auth-file.js +9 -10
- package/dist/cli/main.js +44 -54
- package/dist/error.d.ts +15 -0
- package/dist/error.js +74 -0
- package/dist/extensions/agents.d.ts +100 -0
- package/dist/extensions/agents.js +121 -0
- package/dist/extensions/capabilities.d.ts +4 -0
- package/dist/extensions/commands.d.ts +23 -0
- package/dist/extensions/commands.js +45 -0
- package/dist/extensions/compaction.d.ts +36 -0
- package/dist/extensions/contracts.d.ts +147 -0
- package/dist/extensions/data.d.ts +81 -0
- package/dist/extensions/data.js +78 -0
- package/dist/extensions/environment.d.ts +39 -0
- package/dist/extensions/environment.js +52 -0
- package/dist/extensions/files.d.ts +68 -0
- package/dist/extensions/files.js +26 -0
- package/dist/extensions/hooks.d.ts +32 -0
- package/dist/extensions/host-ports.d.ts +24 -0
- package/dist/extensions/manager.d.ts +42 -0
- package/dist/extensions/manager.js +457 -0
- package/dist/extensions/mcp.d.ts +116 -0
- package/dist/extensions/mcp.js +434 -0
- package/dist/extensions/model-request.d.ts +65 -0
- package/dist/extensions/model-request.js +197 -0
- package/dist/extensions/model-stream.d.ts +18 -0
- package/dist/extensions/model-stream.js +108 -0
- package/dist/extensions/models.d.ts +46 -0
- package/dist/extensions/models.js +7 -0
- package/dist/extensions/network.d.ts +40 -0
- package/dist/extensions/network.js +97 -0
- package/dist/extensions/operation.d.ts +32 -0
- package/dist/extensions/processes.d.ts +64 -0
- package/dist/extensions/processes.js +284 -0
- package/dist/extensions/prompt-composition.d.ts +38 -0
- package/dist/extensions/prompt-composition.js +100 -0
- package/dist/extensions/prompt-input.d.ts +30 -0
- package/dist/extensions/prompt-input.js +48 -0
- package/dist/extensions/prompts.d.ts +31 -0
- package/dist/extensions/prompts.js +88 -0
- package/dist/extensions/resources.d.ts +26 -0
- package/dist/extensions/resources.js +221 -0
- package/dist/extensions/services.d.ts +31 -0
- package/dist/extensions/services.js +61 -0
- package/dist/extensions/session-api.d.ts +6 -0
- package/dist/extensions/session-api.js +52 -0
- package/dist/extensions/session-input.d.ts +184 -0
- package/dist/extensions/session-input.js +422 -0
- package/dist/extensions/session-messages.d.ts +41 -0
- package/dist/extensions/session-messages.js +76 -0
- package/dist/extensions/session-tools.d.ts +32 -0
- package/dist/extensions/session-tools.js +208 -0
- package/dist/extensions/session.d.ts +60 -0
- package/dist/extensions/session.js +265 -0
- package/dist/extensions/settings.d.ts +76 -0
- package/dist/extensions/settings.js +115 -0
- package/dist/extensions/store.d.ts +10 -0
- package/dist/extensions/store.js +131 -0
- package/dist/extensions/tool-runtime.d.ts +16 -0
- package/dist/extensions/tools.d.ts +80 -0
- package/dist/extensions/tools.js +270 -0
- package/dist/extensions.d.ts +22 -0
- package/dist/host/contracts.d.ts +58 -0
- package/dist/host/contracts.js +18 -0
- package/dist/host/description.d.ts +19 -0
- package/dist/host/local-agent-host.d.ts +96 -0
- package/dist/host/local-agent-host.js +429 -0
- package/dist/host/local-exec-tool.d.ts +26 -0
- package/dist/host/local-exec-tool.js +686 -0
- package/dist/host/local-file-access.d.ts +30 -0
- package/dist/host/local-file-access.js +107 -0
- package/dist/host/local-network-access.d.ts +6 -0
- package/dist/host/local-network-access.js +101 -0
- package/dist/host/local-process-executor.d.ts +5 -0
- package/dist/host/local-process-executor.js +17 -0
- package/dist/host/local-session-environment.d.ts +18 -0
- package/dist/host/local-shell.d.ts +3 -0
- package/dist/host/local-tool-registry.d.ts +34 -0
- package/dist/host/local-tool-registry.js +134 -0
- package/dist/host/network.d.ts +5 -0
- package/dist/host/network.js +42 -0
- package/dist/host/process-control.d.ts +2 -0
- package/dist/host/process-control.js +26 -0
- package/dist/host/skill-contract.d.ts +6 -0
- package/dist/host.d.ts +17 -0
- package/dist/host.js +3 -0
- package/dist/index.d.ts +26 -51
- package/dist/index.js +9 -12
- package/dist/model/anthropic-messages.d.ts +10 -0
- package/dist/model/anthropic-messages.js +692 -0
- package/dist/model/anthropic-thinking.js +33 -0
- package/dist/model/configuration.d.ts +111 -0
- package/dist/model/configuration.js +201 -0
- package/dist/model/contracts.d.ts +229 -0
- package/dist/model/http.d.ts +13 -0
- package/dist/model/http.js +119 -0
- package/dist/model/image-contract.d.ts +10 -0
- package/dist/model/image.d.ts +9 -0
- package/dist/model/inline-media-budget.d.ts +7 -0
- package/dist/model/inline-media-budget.js +36 -0
- package/dist/model/input-images.d.ts +3 -0
- package/dist/model/input-images.js +16 -0
- package/dist/model/openai-responses.d.ts +59 -0
- package/dist/model/openai-responses.js +1586 -0
- package/dist/model/recovery.js +80 -0
- package/dist/model/request-configuration.d.ts +17 -0
- package/dist/model/request-configuration.js +47 -0
- package/dist/model/responses-event-projection.d.ts +24 -0
- package/dist/model/responses-event-projection.js +194 -0
- package/dist/model/responses-request.d.ts +5 -0
- package/dist/model/responses-request.js +363 -0
- package/dist/model/responses-session-cache.d.ts +33 -0
- package/dist/model/responses-session-cache.js +64 -0
- package/dist/model/runtime-credential.d.ts +1 -0
- package/dist/model/runtime-credential.js +1 -0
- package/dist/model/sse.js +281 -0
- package/dist/model/text-blocks.js +40 -0
- package/dist/model/tool-declarations.d.ts +4 -0
- package/dist/model/tool-definition-projection.d.ts +6 -0
- package/dist/model/tool-definition-projection.js +11 -0
- package/dist/model/tool-schema.d.ts +2 -0
- package/dist/model/tool-schema.js +17 -0
- package/dist/model/transport-test.d.ts +10 -0
- package/dist/model/transport-test.js +27 -0
- package/dist/model/usage-observer.d.ts +5 -0
- package/dist/model/usage.d.ts +40 -0
- package/dist/network/credential-runtime.d.ts +8 -0
- package/dist/network/credential-runtime.js +72 -0
- package/dist/network/credentials.d.ts +20 -0
- package/dist/network/credentials.js +18 -0
- package/dist/network/http.d.ts +20 -0
- package/dist/network/http.js +421 -0
- package/dist/network/product-user-agent.d.ts +5 -0
- package/dist/network/product-user-agent.js +22 -0
- package/dist/network/transport-error.d.ts +5 -0
- package/dist/network/transport-error.js +31 -0
- package/dist/process/contracts.d.ts +26 -0
- package/dist/prompts/index.d.ts +20 -0
- package/dist/prompts/index.js +49 -0
- package/dist/prompts/prompt-sections.d.ts +6 -0
- package/dist/prompts/prompt-sections.js +6 -0
- package/dist/prompts/read-context.js +152 -0
- package/dist/runtime/compaction/contracts.d.ts +23 -0
- package/dist/runtime/compaction/coordinator.js +88 -0
- package/dist/runtime/compaction/generate.d.ts +31 -0
- package/dist/runtime/compaction/generate.js +84 -0
- package/dist/runtime/compaction/history.d.ts +16 -0
- package/dist/runtime/compaction/operation.d.ts +30 -0
- package/dist/runtime/compaction/operation.js +131 -0
- package/dist/runtime/compaction/requests.d.ts +16 -0
- package/dist/runtime/compaction/requests.js +114 -0
- package/dist/runtime/compaction/retained-context.d.ts +6 -0
- package/dist/runtime/compaction/retained-context.js +48 -0
- package/dist/runtime/compaction/smart.d.ts +14 -0
- package/dist/runtime/compaction/smart.js +59 -0
- package/dist/runtime/context/contextual-blocks.d.ts +31 -0
- package/dist/runtime/context/contextual-blocks.js +158 -0
- package/dist/runtime/context/environment.d.ts +5 -0
- package/dist/runtime/context/gc-candidates-code.d.ts +6 -0
- package/dist/runtime/context/gc-candidates-code.js +102 -0
- package/dist/runtime/context/gc-candidates-exec.d.ts +6 -0
- package/dist/runtime/context/gc-candidates-exec.js +131 -0
- package/dist/runtime/context/gc-candidates-read-patch.d.ts +7 -0
- package/dist/runtime/context/gc-candidates-read-patch.js +118 -0
- package/dist/runtime/context/gc-candidates-subagent.d.ts +6 -0
- package/dist/runtime/context/gc-candidates-subagent.js +100 -0
- package/dist/runtime/context/gc-candidates-web.d.ts +6 -0
- package/dist/runtime/context/gc-candidates-web.js +58 -0
- package/dist/runtime/context/gc-candidates.d.ts +12 -0
- package/dist/runtime/context/gc-candidates.js +192 -0
- package/dist/runtime/context/gc-contracts.d.ts +57 -0
- package/dist/runtime/context/gc-economics.d.ts +48 -0
- package/dist/runtime/context/gc-economics.js +161 -0
- package/dist/runtime/context/gc-runtime.d.ts +43 -0
- package/dist/runtime/context/gc-tokens.d.ts +26 -0
- package/dist/runtime/context/gc-tokens.js +106 -0
- package/dist/runtime/context/gc.d.ts +7 -0
- package/dist/runtime/context/gc.js +552 -0
- package/dist/runtime/context/instructions.d.ts +37 -0
- package/dist/runtime/context/instructions.js +297 -0
- package/dist/runtime/context/normalize.d.ts +5 -0
- package/dist/runtime/context/projection.d.ts +23 -0
- package/dist/runtime/context/projection.js +284 -0
- package/dist/runtime/context/request-budget.d.ts +5 -0
- package/dist/runtime/context/request-budget.js +25 -0
- package/dist/runtime/context/restore.d.ts +27 -0
- package/dist/runtime/context/restore.js +186 -0
- package/dist/runtime/context/usage.d.ts +17 -0
- package/dist/runtime/context/usage.js +124 -0
- package/dist/runtime/context/world-state.d.ts +34 -0
- package/dist/runtime/context/world-state.js +232 -0
- package/dist/runtime/contracts.d.ts +29 -0
- package/dist/runtime/event-projection.d.ts +14 -0
- package/dist/runtime/event-projection.js +87 -0
- package/dist/runtime/events.d.ts +195 -0
- package/dist/runtime/execution-handle.d.ts +12 -0
- package/dist/runtime/execution-handle.js +1 -0
- package/dist/runtime/execution.d.ts +55 -0
- package/dist/runtime/execution.js +444 -0
- package/dist/runtime/model-progress.js +85 -0
- package/dist/runtime/resource-publication.d.ts +27 -0
- package/dist/runtime/resource-publication.js +60 -0
- package/dist/runtime/tool-round-contract.d.ts +19 -0
- package/dist/runtime/tool-round-contract.js +1 -0
- package/dist/runtime/wait.js +82 -0
- package/dist/sandbox/linux/bubblewrap-sandbox-executor.d.ts +1 -1
- package/dist/sandbox/linux/bubblewrap-sandbox-executor.js +8 -8
- package/dist/sdk/agent.d.ts +7 -0
- package/dist/sdk/agent.js +321 -0
- package/dist/sdk/execution-code-mode.d.ts +18 -0
- package/dist/sdk/execution-code-mode.js +51 -0
- package/dist/sdk/execution-compact-commit.d.ts +23 -0
- package/dist/sdk/execution-compact-commit.js +41 -0
- package/dist/sdk/execution-compact-extension.d.ts +12 -0
- package/dist/sdk/execution-compact-extension.js +46 -0
- package/dist/sdk/execution-compact-generation.d.ts +17 -0
- package/dist/sdk/execution-compact-generation.js +30 -0
- package/dist/sdk/execution-compaction-flight.d.ts +31 -0
- package/dist/sdk/execution-compaction-flight.js +50 -0
- package/dist/sdk/execution-compaction.d.ts +47 -0
- package/dist/sdk/execution-compaction.js +121 -0
- package/dist/sdk/execution-context-coordinator.d.ts +56 -0
- package/dist/sdk/execution-context-coordinator.js +102 -0
- package/dist/sdk/execution-input.d.ts +58 -0
- package/dist/sdk/execution-input.js +266 -0
- package/dist/sdk/execution-model-context.d.ts +52 -0
- package/dist/sdk/execution-model-context.js +156 -0
- package/dist/sdk/execution-model-lifecycle.d.ts +39 -0
- package/dist/sdk/execution-model-lifecycle.js +73 -0
- package/dist/sdk/execution-model-request.d.ts +40 -0
- package/dist/sdk/execution-model-request.js +45 -0
- package/dist/sdk/execution-round-preparation.d.ts +11 -0
- package/dist/sdk/execution-round-preparation.js +18 -0
- package/dist/sdk/execution-round-request.d.ts +30 -0
- package/dist/sdk/execution-round-request.js +31 -0
- package/dist/sdk/execution-tool-catalog.d.ts +46 -0
- package/dist/sdk/execution-tool-catalog.js +103 -0
- package/dist/sdk/execution-tool-scope.d.ts +67 -0
- package/dist/sdk/execution-tool-scope.js +147 -0
- package/dist/sdk/extension-agent-controller.d.ts +3 -0
- package/dist/sdk/extension-agent-controller.js +69 -0
- package/dist/sdk/extension-agents.d.ts +9 -0
- package/dist/sdk/extension-agents.js +58 -0
- package/dist/sdk/extension-models.d.ts +17 -0
- package/dist/sdk/extension-models.js +142 -0
- package/dist/sdk/extension-session-launch.d.ts +18 -0
- package/dist/sdk/extension-session-launch.js +73 -0
- package/dist/sdk/extension-session.d.ts +30 -0
- package/dist/sdk/extension-session.js +107 -0
- package/dist/sdk/extension-tool-runtime.d.ts +2 -0
- package/dist/sdk/extension-tool-runtime.js +14 -0
- package/dist/sdk/extension-tools.d.ts +16 -0
- package/dist/sdk/extension-tools.js +126 -0
- package/dist/sdk/model-input-projection.d.ts +4 -0
- package/dist/sdk/model-input-projection.js +27 -0
- package/dist/sdk/model-runtime.d.ts +21 -0
- package/dist/sdk/model-runtime.js +91 -0
- package/dist/sdk/native-steer.d.ts +20 -0
- package/dist/sdk/native-steer.js +84 -0
- package/dist/sdk/request-preparation.d.ts +9 -0
- package/dist/sdk/resource-input.d.ts +33 -0
- package/dist/sdk/resource-input.js +402 -0
- package/dist/sdk/session-catalog.d.ts +2 -0
- package/dist/sdk/session-catalog.js +12 -0
- package/dist/sdk/session-composition.d.ts +54 -0
- package/dist/sdk/session-composition.js +1 -0
- package/dist/sdk/session-execution-factory.d.ts +43 -0
- package/dist/sdk/session-execution-factory.js +937 -0
- package/dist/sdk/session-execution.d.ts +163 -0
- package/dist/sdk/session-execution.js +388 -0
- package/dist/sdk/session-extension-messages.d.ts +16 -0
- package/dist/sdk/session-extension-messages.js +64 -0
- package/dist/sdk/session-extension-prompt.d.ts +35 -0
- package/dist/sdk/session-extension-prompt.js +62 -0
- package/dist/sdk/session-maintenance.d.ts +25 -0
- package/dist/sdk/session-maintenance.js +205 -0
- package/dist/sdk/session-model-adapters.d.ts +28 -0
- package/dist/sdk/session-model-adapters.js +96 -0
- package/dist/sdk/session-open.d.ts +22 -0
- package/dist/sdk/session-open.js +44 -0
- package/dist/sdk/session-registry.d.ts +17 -0
- package/dist/sdk/session-registry.js +83 -0
- package/dist/sdk/session-runtime.d.ts +72 -0
- package/dist/sdk/session-runtime.js +205 -0
- package/dist/sdk/session.d.ts +3 -0
- package/dist/sdk/session.js +313 -0
- package/dist/sdk/subagent-backend.d.ts +3 -0
- package/dist/sdk/subagent-backend.js +49 -0
- package/dist/sdk/types.d.ts +80 -0
- package/dist/sdk/types.js +1 -0
- package/dist/session/catalog.d.ts +70 -0
- package/dist/session/catalog.js +194 -0
- package/dist/session/code-observation-contract.d.ts +40 -0
- package/dist/session/code-observation-contract.js +1 -0
- package/dist/session/code-observation-projection.d.ts +54 -0
- package/dist/session/code-observation-projection.js +165 -0
- package/dist/session/code-state.d.ts +27 -0
- package/dist/session/code-state.js +89 -0
- package/dist/session/context-gc-checkpoint.d.ts +26 -0
- package/dist/session/context-gc-checkpoint.js +935 -0
- package/dist/session/context-gc-contract.d.ts +141 -0
- package/dist/session/context-gc-contract.js +1 -0
- package/dist/session/context-gc-observations.d.ts +58 -0
- package/dist/session/context-gc-observations.js +187 -0
- package/dist/session/context-gc-replacements.d.ts +63 -0
- package/dist/session/context-gc-subagent.d.ts +54 -0
- package/dist/session/deferred-input.d.ts +5 -0
- package/dist/session/deferred-input.js +74 -0
- package/dist/session/extension-checkpoint.d.ts +8 -0
- package/dist/session/extension-checkpoint.js +30 -0
- package/dist/session/history-input-limits.d.ts +4 -0
- package/dist/session/history-input-limits.js +4 -0
- package/dist/session/inline-media-contract.d.ts +16 -0
- package/dist/session/inline-media-contract.js +1 -0
- package/dist/session/inline-media.d.ts +26 -0
- package/dist/session/inline-media.js +138 -0
- package/dist/session/model-request.d.ts +14 -0
- package/dist/session/model-request.js +1 -0
- package/dist/session/record-contract.d.ts +19 -0
- package/dist/session/record-contract.js +1 -0
- package/dist/session/record-projection.d.ts +6 -0
- package/dist/session/record-projection.js +80 -0
- package/dist/session/resource-contract.d.ts +9 -0
- package/dist/session/resource-contract.js +1 -0
- package/dist/session/rollback.d.ts +13 -0
- package/dist/session/rollback.js +46 -0
- package/dist/session/store/contracts.d.ts +160 -0
- package/dist/session/store/contracts.js +1 -0
- package/dist/session/store/current-state.d.ts +17 -0
- package/dist/session/store/current-state.js +53 -0
- package/dist/session/store/execution-state.d.ts +13 -0
- package/dist/session/store/execution-state.js +103 -0
- package/dist/session/store/index.d.ts +4 -0
- package/dist/session/store/index.js +2 -0
- package/dist/session/store/jsonl/directory-index.d.ts +26 -0
- package/dist/session/store/jsonl/directory-index.js +283 -0
- package/dist/session/store/jsonl/fork-session.d.ts +19 -0
- package/dist/session/store/jsonl/fork-session.js +142 -0
- package/dist/session/store/jsonl/fs-durability.d.ts +3 -0
- package/dist/session/store/jsonl/fs-durability.js +17 -0
- package/dist/session/store/jsonl/history-replacement.d.ts +48 -0
- package/dist/session/store/jsonl/history-replacement.js +147 -0
- package/dist/session/store/jsonl/history.d.ts +25 -0
- package/dist/session/store/jsonl/history.js +181 -0
- package/dist/session/store/jsonl/images.d.ts +19 -0
- package/dist/session/store/jsonl/images.js +122 -0
- package/dist/session/store/jsonl/index-transaction.d.ts +13 -0
- package/dist/session/store/jsonl/index-transaction.js +87 -0
- package/dist/session/store/jsonl/jsonl-admission.d.ts +10 -0
- package/dist/session/store/jsonl/jsonl-admission.js +205 -0
- package/dist/session/store/jsonl/jsonl-codec.d.ts +11 -0
- package/dist/session/store/jsonl/jsonl-codec.js +138 -0
- package/dist/session/store/jsonl/jsonl-migration.d.ts +12 -0
- package/dist/session/store/jsonl/jsonl-migration.js +105 -0
- package/dist/session/store/jsonl/jsonl-store.d.ts +171 -0
- package/dist/session/store/jsonl/jsonl-store.js +2395 -0
- package/dist/session/store/jsonl/open-recovery.d.ts +13 -0
- package/dist/session/store/jsonl/open-recovery.js +131 -0
- package/dist/session/store/jsonl/read-pins.d.ts +4 -0
- package/dist/session/store/jsonl/read-pins.js +131 -0
- package/dist/session/store/jsonl/record-append.d.ts +16 -0
- package/dist/session/store/jsonl/record-append.js +49 -0
- package/dist/session/store/jsonl/records.d.ts +30 -0
- package/dist/session/store/jsonl/records.js +313 -0
- package/dist/session/store/jsonl/resources.d.ts +19 -0
- package/dist/session/store/jsonl/resources.js +209 -0
- package/dist/session/store/jsonl/store-pool.d.ts +12 -0
- package/dist/session/store/jsonl/store-pool.js +55 -0
- package/dist/session/store/jsonl/transaction-recovery.d.ts +48 -0
- package/dist/session/store/jsonl/transaction-recovery.js +374 -0
- package/dist/session/store/jsonl/tree-maintenance.d.ts +12 -0
- package/dist/session/store/jsonl/tree-maintenance.js +59 -0
- package/dist/session/store/types.d.ts +69 -0
- package/dist/session/store/types.js +1 -0
- package/dist/session/summary.d.ts +18 -0
- package/dist/session/summary.js +1 -0
- package/dist/session/todo.d.ts +11 -0
- package/dist/session/todo.js +30 -0
- package/dist/session/tool-result-resources.d.ts +27 -0
- package/dist/session/tool-result-resources.js +255 -0
- package/dist/session/types.js +1 -0
- package/dist/session/user-history.d.ts +17 -0
- package/dist/session/user-history.js +1 -0
- package/dist/session-store.d.ts +2 -0
- package/dist/session-store.js +1 -0
- package/dist/shared/auto-title.d.ts +3 -3
- package/dist/shared/auto-title.js +6 -6
- package/dist/shared/model-text.d.ts +8 -8
- package/dist/shared/model-text.js +8 -7
- package/dist/storage/file-lock.js +83 -0
- package/dist/subagent/contracts.d.ts +107 -0
- package/dist/subagent/contracts.js +1 -0
- package/dist/subagent/limits.d.ts +17 -0
- package/dist/subagent/limits.js +17 -0
- package/dist/subagent/model-update.js +81 -0
- package/dist/subagent/session-controller.d.ts +87 -0
- package/dist/subagent/session-controller.js +1343 -0
- package/dist/subagent/task.d.ts +134 -0
- package/dist/subagent/task.js +436 -0
- package/dist/subagent/turn-contracts.d.ts +64 -0
- package/dist/subagent/turn-contracts.js +1 -0
- package/dist/subagent/wait-targets.d.ts +10 -0
- package/dist/subagent/wait-targets.js +26 -0
- package/dist/subagent/wait.d.ts +26 -0
- package/dist/subagent/wait.js +73 -0
- package/dist/tools/agent/agent-cancel.d.ts +7 -0
- package/dist/tools/agent/agent-cancel.js +29 -0
- package/dist/tools/agent/agent-message.d.ts +7 -0
- package/dist/tools/agent/agent-message.js +57 -0
- package/dist/tools/agent/agent-start.d.ts +12 -0
- package/dist/tools/agent/agent-start.js +106 -0
- package/dist/tools/agent/agent-wait.d.ts +7 -0
- package/dist/tools/agent/agent-wait.js +91 -0
- package/dist/tools/agent/question.d.ts +7 -0
- package/dist/tools/agent/question.js +125 -0
- package/dist/tools/agent/skill.d.ts +11 -0
- package/dist/tools/agent/skill.js +38 -0
- package/dist/tools/agent/sleep.d.ts +9 -0
- package/dist/tools/agent/sleep.js +54 -0
- package/dist/tools/agent/smart-compact.d.ts +9 -0
- package/dist/tools/agent/smart-compact.js +23 -0
- package/dist/tools/agent/todo-read.d.ts +14 -0
- package/dist/tools/agent/todo-write.d.ts +14 -0
- package/dist/tools/agent/todo-write.js +66 -0
- package/dist/tools/agent/todo.d.ts +25 -0
- package/dist/tools/agent/todo.js +32 -0
- package/dist/tools/callers.d.ts +7 -0
- package/dist/tools/callers.js +39 -0
- package/dist/tools/code-mode/cells.d.ts +29 -0
- package/dist/tools/code-mode/cells.js +338 -0
- package/dist/tools/code-mode/dispatch.d.ts +20 -0
- package/dist/tools/code-mode/dispatch.js +80 -0
- package/dist/tools/code-mode/engine.d.ts +60 -0
- package/dist/tools/code-mode/engine.js +1 -0
- package/dist/tools/code-mode/index.d.ts +31 -0
- package/dist/tools/code-mode/index.js +751 -0
- package/dist/tools/code-mode/observations.d.ts +8 -0
- package/dist/tools/code-mode/observations.js +64 -0
- package/dist/tools/code-mode/worker.d.ts +1 -0
- package/dist/tools/contracts.d.ts +193 -0
- package/dist/tools/contracts.js +1 -0
- package/dist/tools/definition-projection.d.ts +1 -0
- package/dist/tools/definition-projection.js +1 -0
- package/dist/tools/execution-limits.d.ts +69 -0
- package/dist/tools/execution-limits.js +58 -0
- package/dist/tools/execution.d.ts +30 -0
- package/dist/tools/execution.js +191 -0
- package/dist/tools/local/apply-patch-parser.js +177 -0
- package/dist/tools/local/apply-patch.d.ts +19 -0
- package/dist/tools/local/apply-patch.js +489 -0
- package/dist/tools/local/exec.d.ts +28 -0
- package/dist/tools/local/exec.js +194 -0
- package/dist/tools/local/image-processing.js +146 -0
- package/dist/tools/local/read.d.ts +43 -0
- package/dist/tools/local/read.js +470 -0
- package/dist/tools/local/view-image.d.ts +15 -0
- package/dist/tools/local/view-image.js +317 -0
- package/dist/tools/mcp/catalog.js +220 -0
- package/dist/tools/mcp/history.d.ts +4 -0
- package/dist/tools/mcp/tool-search.d.ts +45 -0
- package/dist/tools/mcp/tool-search.js +294 -0
- package/dist/tools/output-projection.d.ts +18 -0
- package/dist/tools/output-projection.js +341 -0
- package/dist/tools/permission-contract.d.ts +25 -0
- package/dist/tools/permission-contract.js +1 -0
- package/dist/tools/permissions.d.ts +61 -0
- package/dist/tools/permissions.js +237 -0
- package/dist/tools/registry.d.ts +7 -0
- package/dist/tools/result-extension-contract.d.ts +37 -0
- package/dist/tools/result-extension-contract.js +32 -0
- package/dist/tools/result-extensions.d.ts +12 -0
- package/dist/tools/result-extensions.js +104 -0
- package/dist/tools/runtime-context.d.ts +89 -0
- package/dist/tools/runtime-context.js +1 -0
- package/dist/tools/runtime-resource-handles.js +28 -0
- package/dist/tools/runtime.js +77 -0
- package/dist/tools/scheduler.d.ts +12 -0
- package/dist/tools/shared/path-resolver.js +133 -0
- package/dist/tools/wait.d.ts +1 -0
- package/dist/tools/wait.js +1 -0
- package/package.json +15 -3
- package/dist/agent-core/error.d.ts +0 -15
- package/dist/agent-core/error.js +0 -74
- package/dist/agent-core/extensions/agents.d.ts +0 -79
- package/dist/agent-core/extensions/agents.js +0 -186
- package/dist/agent-core/extensions/compaction.d.ts +0 -48
- package/dist/agent-core/extensions/contracts.d.ts +0 -265
- package/dist/agent-core/extensions/data.d.ts +0 -84
- package/dist/agent-core/extensions/data.js +0 -83
- package/dist/agent-core/extensions/environment.d.ts +0 -27
- package/dist/agent-core/extensions/environment.js +0 -52
- package/dist/agent-core/extensions/files.d.ts +0 -64
- package/dist/agent-core/extensions/files.js +0 -26
- package/dist/agent-core/extensions/hooks.d.ts +0 -32
- package/dist/agent-core/extensions/manager.d.ts +0 -39
- package/dist/agent-core/extensions/manager.js +0 -458
- package/dist/agent-core/extensions/mcp.d.ts +0 -99
- package/dist/agent-core/extensions/mcp.js +0 -433
- package/dist/agent-core/extensions/model-request.d.ts +0 -56
- package/dist/agent-core/extensions/model-request.js +0 -197
- package/dist/agent-core/extensions/model-stream.d.ts +0 -9
- package/dist/agent-core/extensions/model-stream.js +0 -108
- package/dist/agent-core/extensions/models.d.ts +0 -43
- package/dist/agent-core/extensions/network.d.ts +0 -32
- package/dist/agent-core/extensions/network.js +0 -97
- package/dist/agent-core/extensions/operation.d.ts +0 -30
- package/dist/agent-core/extensions/processes.d.ts +0 -52
- package/dist/agent-core/extensions/processes.js +0 -284
- package/dist/agent-core/extensions/prompt-composition.d.ts +0 -24
- package/dist/agent-core/extensions/prompt-composition.js +0 -106
- package/dist/agent-core/extensions/prompt-input.d.ts +0 -23
- package/dist/agent-core/extensions/prompt-input.js +0 -48
- package/dist/agent-core/extensions/resources.d.ts +0 -27
- package/dist/agent-core/extensions/resources.js +0 -221
- package/dist/agent-core/extensions/services.d.ts +0 -31
- package/dist/agent-core/extensions/services.js +0 -61
- package/dist/agent-core/extensions/session-input.d.ts +0 -163
- package/dist/agent-core/extensions/session-input.js +0 -411
- package/dist/agent-core/extensions/session-messages.d.ts +0 -41
- package/dist/agent-core/extensions/session-messages.js +0 -76
- package/dist/agent-core/extensions/session.d.ts +0 -69
- package/dist/agent-core/extensions/session.js +0 -607
- package/dist/agent-core/extensions/settings.d.ts +0 -59
- package/dist/agent-core/extensions/settings.js +0 -115
- package/dist/agent-core/extensions/store.d.ts +0 -10
- package/dist/agent-core/extensions/store.js +0 -131
- package/dist/agent-core/extensions/tools.d.ts +0 -61
- package/dist/agent-core/extensions/tools.js +0 -269
- package/dist/agent-core/host/contracts.d.ts +0 -100
- package/dist/agent-core/host/contracts.js +0 -18
- package/dist/agent-core/host/local-agent-host.d.ts +0 -96
- package/dist/agent-core/host/local-agent-host.js +0 -425
- package/dist/agent-core/host/local-file-access.d.ts +0 -30
- package/dist/agent-core/host/local-file-access.js +0 -107
- package/dist/agent-core/host/local-network-access.d.ts +0 -6
- package/dist/agent-core/host/local-network-access.js +0 -101
- package/dist/agent-core/host/local-process-executor.d.ts +0 -29
- package/dist/agent-core/host/local-process-executor.js +0 -41
- package/dist/agent-core/host/local-session-environment.d.ts +0 -18
- package/dist/agent-core/host/local-shell.d.ts +0 -3
- package/dist/agent-core/host/network.d.ts +0 -4
- package/dist/agent-core/host/network.js +0 -6
- package/dist/agent-core/model/anthropic-messages.d.ts +0 -10
- package/dist/agent-core/model/anthropic-messages.js +0 -707
- package/dist/agent-core/model/anthropic-thinking.js +0 -33
- package/dist/agent-core/model/catalog-file.d.ts +0 -80
- package/dist/agent-core/model/catalog-file.js +0 -103
- package/dist/agent-core/model/configuration.d.ts +0 -127
- package/dist/agent-core/model/configuration.js +0 -168
- package/dist/agent-core/model/contracts.d.ts +0 -229
- package/dist/agent-core/model/http.d.ts +0 -27
- package/dist/agent-core/model/http.js +0 -534
- package/dist/agent-core/model/image.d.ts +0 -17
- package/dist/agent-core/model/openai-responses.d.ts +0 -77
- package/dist/agent-core/model/openai-responses.js +0 -2123
- package/dist/agent-core/model/product-user-agent.d.ts +0 -5
- package/dist/agent-core/model/product-user-agent.js +0 -22
- package/dist/agent-core/model/recovery.js +0 -80
- package/dist/agent-core/model/request-configuration.d.ts +0 -17
- package/dist/agent-core/model/request-configuration.js +0 -47
- package/dist/agent-core/model/runtime-credential.d.ts +0 -8
- package/dist/agent-core/model/runtime-credential.js +0 -72
- package/dist/agent-core/model/sse.js +0 -281
- package/dist/agent-core/model/text-blocks.js +0 -40
- package/dist/agent-core/model/tool-declarations.d.ts +0 -4
- package/dist/agent-core/model/transport-test.d.ts +0 -3
- package/dist/agent-core/model/transport-test.js +0 -23
- package/dist/agent-core/model/usage-observer.d.ts +0 -31
- package/dist/agent-core/prompts/index.d.ts +0 -20
- package/dist/agent-core/prompts/index.js +0 -49
- package/dist/agent-core/runtime/compaction/coordinator.js +0 -88
- package/dist/agent-core/runtime/compaction/generate.d.ts +0 -28
- package/dist/agent-core/runtime/compaction/generate.js +0 -84
- package/dist/agent-core/runtime/compaction/history.d.ts +0 -16
- package/dist/agent-core/runtime/compaction/operation.d.ts +0 -29
- package/dist/agent-core/runtime/compaction/operation.js +0 -131
- package/dist/agent-core/runtime/compaction/requests.d.ts +0 -16
- package/dist/agent-core/runtime/compaction/requests.js +0 -114
- package/dist/agent-core/runtime/compaction/retained-context.d.ts +0 -6
- package/dist/agent-core/runtime/compaction/retained-context.js +0 -47
- package/dist/agent-core/runtime/compaction/smart.d.ts +0 -14
- package/dist/agent-core/runtime/compaction/smart.js +0 -59
- package/dist/agent-core/runtime/context/contextual-blocks.d.ts +0 -30
- package/dist/agent-core/runtime/context/contextual-blocks.js +0 -146
- package/dist/agent-core/runtime/context/environment.d.ts +0 -5
- package/dist/agent-core/runtime/context/gc-runtime.d.ts +0 -38
- package/dist/agent-core/runtime/context/gc-tokens.d.ts +0 -25
- package/dist/agent-core/runtime/context/gc-tokens.js +0 -103
- package/dist/agent-core/runtime/context/gc.d.ts +0 -75
- package/dist/agent-core/runtime/context/gc.js +0 -1386
- package/dist/agent-core/runtime/context/instructions.d.ts +0 -37
- package/dist/agent-core/runtime/context/instructions.js +0 -297
- package/dist/agent-core/runtime/context/normalize.d.ts +0 -5
- package/dist/agent-core/runtime/context/projection.d.ts +0 -23
- package/dist/agent-core/runtime/context/projection.js +0 -284
- package/dist/agent-core/runtime/context/request-budget.d.ts +0 -4
- package/dist/agent-core/runtime/context/request-budget.js +0 -25
- package/dist/agent-core/runtime/context/restore.d.ts +0 -25
- package/dist/agent-core/runtime/context/restore.js +0 -186
- package/dist/agent-core/runtime/context/usage.d.ts +0 -17
- package/dist/agent-core/runtime/context/usage.js +0 -124
- package/dist/agent-core/runtime/context/world-state.d.ts +0 -33
- package/dist/agent-core/runtime/context/world-state.js +0 -232
- package/dist/agent-core/runtime/contracts.d.ts +0 -41
- package/dist/agent-core/runtime/event-projection.d.ts +0 -14
- package/dist/agent-core/runtime/event-projection.js +0 -87
- package/dist/agent-core/runtime/events.d.ts +0 -197
- package/dist/agent-core/runtime/execution-handle.d.ts +0 -12
- package/dist/agent-core/runtime/execution.d.ts +0 -50
- package/dist/agent-core/runtime/execution.js +0 -445
- package/dist/agent-core/runtime/model-progress.js +0 -85
- package/dist/agent-core/runtime/resource-publication.d.ts +0 -8
- package/dist/agent-core/runtime/resource-publication.js +0 -60
- package/dist/agent-core/sdk/agent.d.ts +0 -11
- package/dist/agent-core/sdk/agent.js +0 -474
- package/dist/agent-core/sdk/extension-agents.d.ts +0 -9
- package/dist/agent-core/sdk/extension-agents.js +0 -58
- package/dist/agent-core/sdk/extension-models.d.ts +0 -13
- package/dist/agent-core/sdk/extension-models.js +0 -137
- package/dist/agent-core/sdk/extension-session.d.ts +0 -30
- package/dist/agent-core/sdk/extension-session.js +0 -105
- package/dist/agent-core/sdk/extension-tools.d.ts +0 -16
- package/dist/agent-core/sdk/extension-tools.js +0 -126
- package/dist/agent-core/sdk/model-runtime.d.ts +0 -18
- package/dist/agent-core/sdk/model-runtime.js +0 -93
- package/dist/agent-core/sdk/native-steer.d.ts +0 -20
- package/dist/agent-core/sdk/native-steer.js +0 -84
- package/dist/agent-core/sdk/request-preparation.d.ts +0 -7
- package/dist/agent-core/sdk/resource-input.d.ts +0 -32
- package/dist/agent-core/sdk/resource-input.js +0 -403
- package/dist/agent-core/sdk/session.d.ts +0 -94
- package/dist/agent-core/sdk/session.js +0 -2377
- package/dist/agent-core/sdk/subagent-backend.d.ts +0 -3
- package/dist/agent-core/sdk/subagent-backend.js +0 -49
- package/dist/agent-core/sdk/types.d.ts +0 -81
- package/dist/agent-core/session/catalog.d.ts +0 -99
- package/dist/agent-core/session/catalog.js +0 -200
- package/dist/agent-core/session/context-gc-checkpoint.d.ts +0 -165
- package/dist/agent-core/session/context-gc-checkpoint.js +0 -935
- package/dist/agent-core/session/context-gc-observations.d.ts +0 -60
- package/dist/agent-core/session/context-gc-observations.js +0 -187
- package/dist/agent-core/session/context-gc-replacements.d.ts +0 -62
- package/dist/agent-core/session/context-gc-subagent.d.ts +0 -53
- package/dist/agent-core/session/deferred-input.d.ts +0 -5
- package/dist/agent-core/session/deferred-input.js +0 -74
- package/dist/agent-core/session/inline-media.d.ts +0 -45
- package/dist/agent-core/session/inline-media.js +0 -163
- package/dist/agent-core/session/rollback.d.ts +0 -13
- package/dist/agent-core/session/rollback.js +0 -46
- package/dist/agent-core/session/store/contracts.d.ts +0 -158
- package/dist/agent-core/session/store/current-state.d.ts +0 -17
- package/dist/agent-core/session/store/current-state.js +0 -53
- package/dist/agent-core/session/store/directory-index.d.ts +0 -18
- package/dist/agent-core/session/store/directory-index.js +0 -169
- package/dist/agent-core/session/store/execution-state.d.ts +0 -18
- package/dist/agent-core/session/store/execution-state.js +0 -175
- package/dist/agent-core/session/store/history.d.ts +0 -25
- package/dist/agent-core/session/store/history.js +0 -181
- package/dist/agent-core/session/store/images.d.ts +0 -19
- package/dist/agent-core/session/store/images.js +0 -110
- package/dist/agent-core/session/store/index.d.ts +0 -4
- package/dist/agent-core/session/store/index.js +0 -2
- package/dist/agent-core/session/store/jsonl-store.d.ts +0 -171
- package/dist/agent-core/session/store/jsonl-store.js +0 -2078
- package/dist/agent-core/session/store/records.d.ts +0 -23
- package/dist/agent-core/session/store/records.js +0 -261
- package/dist/agent-core/session/store/resources.d.ts +0 -26
- package/dist/agent-core/session/store/resources.js +0 -197
- package/dist/agent-core/session/store/types.d.ts +0 -82
- package/dist/agent-core/session/tool-result-resources.d.ts +0 -26
- package/dist/agent-core/session/tool-result-resources.js +0 -256
- package/dist/agent-core/session/transaction-recovery.d.ts +0 -16
- package/dist/agent-core/session/transaction-recovery.js +0 -135
- package/dist/agent-core/storage/file-lock.js +0 -83
- package/dist/agent-core/subagent/contracts.d.ts +0 -117
- package/dist/agent-core/subagent/model-update.js +0 -81
- package/dist/agent-core/subagent/scheduler.d.ts +0 -135
- package/dist/agent-core/subagent/scheduler.js +0 -369
- package/dist/agent-core/subagent/session-controller.d.ts +0 -138
- package/dist/agent-core/subagent/session-controller.js +0 -1594
- package/dist/agent-core/subagent/wait.d.ts +0 -14
- package/dist/agent-core/subagent/wait.js +0 -32
- package/dist/agent-core/tools/agent/agent-cancel.d.ts +0 -7
- package/dist/agent-core/tools/agent/agent-cancel.js +0 -29
- package/dist/agent-core/tools/agent/agent-message.d.ts +0 -7
- package/dist/agent-core/tools/agent/agent-message.js +0 -57
- package/dist/agent-core/tools/agent/agent-start.d.ts +0 -12
- package/dist/agent-core/tools/agent/agent-start.js +0 -106
- package/dist/agent-core/tools/agent/agent-wait.d.ts +0 -7
- package/dist/agent-core/tools/agent/agent-wait.js +0 -91
- package/dist/agent-core/tools/agent/question.d.ts +0 -7
- package/dist/agent-core/tools/agent/question.js +0 -125
- package/dist/agent-core/tools/agent/skill.d.ts +0 -11
- package/dist/agent-core/tools/agent/skill.js +0 -38
- package/dist/agent-core/tools/agent/sleep.d.ts +0 -12
- package/dist/agent-core/tools/agent/sleep.js +0 -54
- package/dist/agent-core/tools/agent/smart-compact.d.ts +0 -9
- package/dist/agent-core/tools/agent/smart-compact.js +0 -23
- package/dist/agent-core/tools/agent/todo-read.d.ts +0 -14
- package/dist/agent-core/tools/agent/todo-write.d.ts +0 -14
- package/dist/agent-core/tools/agent/todo-write.js +0 -66
- package/dist/agent-core/tools/agent/todo.d.ts +0 -26
- package/dist/agent-core/tools/agent/todo.js +0 -60
- package/dist/agent-core/tools/callers.d.ts +0 -6
- package/dist/agent-core/tools/callers.js +0 -39
- package/dist/agent-core/tools/code-mode/cells.d.ts +0 -29
- package/dist/agent-core/tools/code-mode/cells.js +0 -337
- package/dist/agent-core/tools/code-mode/dispatch.d.ts +0 -20
- package/dist/agent-core/tools/code-mode/dispatch.js +0 -80
- package/dist/agent-core/tools/code-mode/engine.d.ts +0 -60
- package/dist/agent-core/tools/code-mode/index.d.ts +0 -29
- package/dist/agent-core/tools/code-mode/index.js +0 -749
- package/dist/agent-core/tools/code-mode/observations.d.ts +0 -98
- package/dist/agent-core/tools/code-mode/observations.js +0 -228
- package/dist/agent-core/tools/code-mode/state.d.ts +0 -9
- package/dist/agent-core/tools/code-mode/state.js +0 -82
- package/dist/agent-core/tools/contracts.d.ts +0 -211
- package/dist/agent-core/tools/definition-projection.d.ts +0 -7
- package/dist/agent-core/tools/definition-projection.js +0 -26
- package/dist/agent-core/tools/execution-limits.d.ts +0 -69
- package/dist/agent-core/tools/execution-limits.js +0 -69
- package/dist/agent-core/tools/execution.d.ts +0 -46
- package/dist/agent-core/tools/execution.js +0 -191
- package/dist/agent-core/tools/local/apply-patch-parser.js +0 -177
- package/dist/agent-core/tools/local/apply-patch.d.ts +0 -19
- package/dist/agent-core/tools/local/apply-patch.js +0 -489
- package/dist/agent-core/tools/local/exec.d.ts +0 -53
- package/dist/agent-core/tools/local/exec.js +0 -877
- package/dist/agent-core/tools/local/image-processing.js +0 -146
- package/dist/agent-core/tools/local/read-context.js +0 -152
- package/dist/agent-core/tools/local/read.d.ts +0 -43
- package/dist/agent-core/tools/local/read.js +0 -470
- package/dist/agent-core/tools/local/registry.d.ts +0 -34
- package/dist/agent-core/tools/local/registry.js +0 -132
- package/dist/agent-core/tools/local/view-image.d.ts +0 -15
- package/dist/agent-core/tools/local/view-image.js +0 -317
- package/dist/agent-core/tools/local/workspace-tools.d.ts +0 -12
- package/dist/agent-core/tools/local/workspace-tools.js +0 -28
- package/dist/agent-core/tools/mcp/catalog.js +0 -220
- package/dist/agent-core/tools/mcp/history.d.ts +0 -4
- package/dist/agent-core/tools/mcp/tool-search.d.ts +0 -45
- package/dist/agent-core/tools/mcp/tool-search.js +0 -294
- package/dist/agent-core/tools/output-projection.d.ts +0 -18
- package/dist/agent-core/tools/output-projection.js +0 -341
- package/dist/agent-core/tools/permissions.d.ts +0 -85
- package/dist/agent-core/tools/permissions.js +0 -237
- package/dist/agent-core/tools/registry.d.ts +0 -7
- package/dist/agent-core/tools/result-extensions.d.ts +0 -46
- package/dist/agent-core/tools/result-extensions.js +0 -134
- package/dist/agent-core/tools/runtime-context.d.ts +0 -74
- package/dist/agent-core/tools/runtime-resource-handles.js +0 -28
- package/dist/agent-core/tools/runtime.js +0 -77
- package/dist/agent-core/tools/scheduler.d.ts +0 -12
- package/dist/agent-core/tools/shared/path-resolver.js +0 -133
- package/dist/agent-core/tools/wait.js +0 -82
- /package/dist/{agent-core/extensions/models.js → extensions/capabilities.js} +0 -0
- /package/dist/{agent-core/extensions → extensions}/compaction.js +0 -0
- /package/dist/{agent-core/model → extensions}/contracts.js +0 -0
- /package/dist/{agent-core/extensions → extensions}/hooks.js +0 -0
- /package/dist/{agent-core/runtime/context/contracts.js → extensions/host-ports.js} +0 -0
- /package/dist/{agent-core/extensions → extensions}/operation.js +0 -0
- /package/dist/{agent-core/runtime/contracts.js → extensions/tool-runtime.js} +0 -0
- /package/dist/{agent-core/extensions/contracts.js → extensions.js} +0 -0
- /package/dist/{agent-core/runtime/events.js → host/description.js} +0 -0
- /package/dist/{agent-core/host → host}/local-session-environment.js +0 -0
- /package/dist/{agent-core/host → host}/local-shell.js +0 -0
- /package/dist/{agent-core/runtime/execution-handle.js → host/skill-contract.js} +0 -0
- /package/dist/{agent-core/model → model}/anthropic-thinking.d.ts +0 -0
- /package/dist/{agent-core/model → model}/attempt-diagnostics.d.ts +0 -0
- /package/dist/{agent-core/model → model}/attempt-diagnostics.js +0 -0
- /package/dist/{agent-core/session/store → model}/contracts.js +0 -0
- /package/dist/{agent-core/sdk/types.js → model/image-contract.js} +0 -0
- /package/dist/{agent-core/model → model}/image.js +0 -0
- /package/dist/{agent-core/model → model}/native-context.d.ts +0 -0
- /package/dist/{agent-core/model → model}/native-context.js +0 -0
- /package/dist/{agent-core/model → model}/recovery.d.ts +0 -0
- /package/dist/{agent-core/model → model}/sse.d.ts +0 -0
- /package/dist/{agent-core/model → model}/text-blocks.d.ts +0 -0
- /package/dist/{agent-core/model → model}/tool-declarations.js +0 -0
- /package/dist/{agent-core/model → model}/tool-input.d.ts +0 -0
- /package/dist/{agent-core/model → model}/tool-input.js +0 -0
- /package/dist/{agent-core/model → model}/usage-observer.js +0 -0
- /package/dist/{agent-core/session/store/types.js → model/usage.js} +0 -0
- /package/dist/{agent-core/subagent → process}/contracts.js +0 -0
- /package/dist/{agent-core/prompts → prompts}/compact.d.ts +0 -0
- /package/dist/{agent-core/prompts → prompts}/compact.js +0 -0
- /package/dist/{agent-core/prompts → prompts}/core.d.ts +0 -0
- /package/dist/{agent-core/prompts → prompts}/core.js +0 -0
- /package/dist/{agent-core/prompts → prompts}/markup.d.ts +0 -0
- /package/dist/{agent-core/prompts → prompts}/markup.js +0 -0
- /package/dist/{agent-core/prompts → prompts}/modes.d.ts +0 -0
- /package/dist/{agent-core/prompts → prompts}/modes.js +0 -0
- /package/dist/{agent-core/prompts → prompts}/output.d.ts +0 -0
- /package/dist/{agent-core/prompts → prompts}/output.js +0 -0
- /package/dist/{agent-core/prompts → prompts}/permissions.d.ts +0 -0
- /package/dist/{agent-core/prompts → prompts}/permissions.js +0 -0
- /package/dist/{agent-core/tools/local → prompts}/read-context.d.ts +0 -0
- /package/dist/{agent-core/prompts → prompts}/resources.d.ts +0 -0
- /package/dist/{agent-core/prompts → prompts}/resources.js +0 -0
- /package/dist/{agent-core/prompts → prompts}/subagent.d.ts +0 -0
- /package/dist/{agent-core/prompts → prompts}/subagent.js +0 -0
- /package/dist/{agent-core/prompts → prompts}/workflow.d.ts +0 -0
- /package/dist/{agent-core/prompts → prompts}/workflow.js +0 -0
- /package/dist/{agent-core/runtime → runtime}/async-queue.d.ts +0 -0
- /package/dist/{agent-core/runtime → runtime}/async-queue.js +0 -0
- /package/dist/{agent-core/tools → runtime/compaction}/contracts.js +0 -0
- /package/dist/{agent-core/runtime → runtime}/compaction/coordinator.d.ts +0 -0
- /package/dist/{agent-core/runtime → runtime}/compaction/history.js +0 -0
- /package/dist/{agent-core/runtime → runtime}/context/contracts.d.ts +0 -0
- /package/dist/{agent-core/session/types.js → runtime/context/contracts.js} +0 -0
- /package/dist/{agent-core/runtime → runtime}/context/environment.js +0 -0
- /package/dist/{agent-core/tools/code-mode/engine.js → runtime/context/gc-contracts.js} +0 -0
- /package/dist/{agent-core/runtime → runtime}/context/gc-runtime.js +0 -0
- /package/dist/{agent-core/runtime → runtime}/context/normalize.js +0 -0
- /package/dist/{agent-core/tools/code-mode/worker.d.ts → runtime/contracts.js} +0 -0
- /package/dist/{agent-core/tools/runtime-context.js → runtime/events.js} +0 -0
- /package/dist/{agent-core/runtime → runtime}/execution-policy.d.ts +0 -0
- /package/dist/{agent-core/runtime → runtime}/execution-policy.js +0 -0
- /package/dist/{agent-core/runtime → runtime}/model-generation-timing.d.ts +0 -0
- /package/dist/{agent-core/runtime → runtime}/model-generation-timing.js +0 -0
- /package/dist/{agent-core/runtime → runtime}/model-progress.d.ts +0 -0
- /package/dist/{agent-core/runtime → runtime}/plan-output.d.ts +0 -0
- /package/dist/{agent-core/runtime → runtime}/plan-output.js +0 -0
- /package/dist/{agent-core/tools/public-metadata.d.ts → runtime/public-tool-metadata.d.ts} +0 -0
- /package/dist/{agent-core/tools/public-metadata.js → runtime/public-tool-metadata.js} +0 -0
- /package/dist/{agent-core/runtime → runtime}/token-budget.d.ts +0 -0
- /package/dist/{agent-core/runtime → runtime}/token-budget.js +0 -0
- /package/dist/{agent-core/tools → runtime}/wait.d.ts +0 -0
- /package/dist/{agent-core/sdk → sdk}/request-preparation.js +0 -0
- /package/dist/{agent-core/session → session}/context-gc-markup.d.ts +0 -0
- /package/dist/{agent-core/session → session}/context-gc-markup.js +0 -0
- /package/dist/{agent-core/session → session}/context-gc-replacements.js +0 -0
- /package/dist/{agent-core/session → session}/context-gc-subagent.js +0 -0
- /package/dist/{agent-core/session → session}/types.d.ts +0 -0
- /package/dist/{agent-core/storage → storage}/file-lock.d.ts +0 -0
- /package/dist/{agent-core/subagent → subagent}/model-update.d.ts +0 -0
- /package/dist/{agent-core/tools → tools}/agent/todo-read.js +0 -0
- /package/dist/{agent-core/tools → tools}/code-mode/quickjs-engine.d.ts +0 -0
- /package/dist/{agent-core/tools → tools}/code-mode/quickjs-engine.js +0 -0
- /package/dist/{agent-core/tools → tools}/code-mode/text-output.d.ts +0 -0
- /package/dist/{agent-core/tools → tools}/code-mode/text-output.js +0 -0
- /package/dist/{agent-core/tools → tools}/code-mode/worker.js +0 -0
- /package/dist/{agent-core/tools → tools}/file-change-diff.d.ts +0 -0
- /package/dist/{agent-core/tools → tools}/file-change-diff.js +0 -0
- /package/dist/{agent-core/tools → tools}/input-diagnostics/source-preview.d.ts +0 -0
- /package/dist/{agent-core/tools → tools}/input-diagnostics/source-preview.js +0 -0
- /package/dist/{agent-core/tools → tools}/input.d.ts +0 -0
- /package/dist/{agent-core/tools → tools}/input.js +0 -0
- /package/dist/{agent-core/tools → tools}/local/apply-patch-parser.d.ts +0 -0
- /package/dist/{agent-core/tools → tools}/local/image-processing.d.ts +0 -0
- /package/dist/{agent-core/tools → tools}/mcp/catalog.d.ts +0 -0
- /package/dist/{agent-core/tools → tools}/mcp/history.js +0 -0
- /package/dist/{agent-core/tools → tools}/registry.js +0 -0
- /package/dist/{agent-core/tools → tools}/runtime-resource-handles.d.ts +0 -0
- /package/dist/{agent-core/tools → tools}/runtime.d.ts +0 -0
- /package/dist/{agent-core/tools → tools}/scheduler.js +0 -0
- /package/dist/{agent-core/tools → tools}/shared/patch-result.d.ts +0 -0
- /package/dist/{agent-core/tools → tools}/shared/patch-result.js +0 -0
- /package/dist/{agent-core/tools → tools}/shared/path-resolver.d.ts +0 -0
|
@@ -1,877 +0,0 @@
|
|
|
1
|
-
import { RuntimeResourceHandles } from '../runtime-resource-handles.js';
|
|
2
|
-
import { StringDecoder } from 'node:string_decoder';
|
|
3
|
-
import { MarAgentError } from '../../error.js';
|
|
4
|
-
import { directLocalProcessExecutor, signalProcessTree } from '../../host/local-process-executor.js';
|
|
5
|
-
import { TOOL_EXECUTION_LIMITS } from '../execution-limits.js';
|
|
6
|
-
import { waitForToolCondition, waitMetadata } from '../wait.js';
|
|
7
|
-
import { validateCoreProcessInput } from '../../extensions/processes.js';
|
|
8
|
-
/** Share the model-facing body across direct calls and original Code Mode observations. */
|
|
9
|
-
export function formatExecResult(result) {
|
|
10
|
-
const visible = { ...result };
|
|
11
|
-
if (result.stderr === '')
|
|
12
|
-
delete visible.stderr;
|
|
13
|
-
if (!result.truncated) {
|
|
14
|
-
delete visible.truncated;
|
|
15
|
-
// Incremental output may be smaller than the cumulative stream counts.
|
|
16
|
-
if (result.stdoutBytes === Buffer.byteLength(result.stdout))
|
|
17
|
-
delete visible.stdoutBytes;
|
|
18
|
-
if (result.stderrBytes === Buffer.byteLength(result.stderr))
|
|
19
|
-
delete visible.stderrBytes;
|
|
20
|
-
}
|
|
21
|
-
if (result.stdoutDroppedBytes === 0)
|
|
22
|
-
delete visible.stdoutDroppedBytes;
|
|
23
|
-
if (result.stderrDroppedBytes === 0)
|
|
24
|
-
delete visible.stderrDroppedBytes;
|
|
25
|
-
if (result.cached === false)
|
|
26
|
-
delete visible.cached;
|
|
27
|
-
return { content: JSON.stringify(visible), data: result, truncated: result.truncated };
|
|
28
|
-
}
|
|
29
|
-
export const execToolDefinition = {
|
|
30
|
-
name: 'exec',
|
|
31
|
-
allowedCallers: ['direct', 'programmatic'],
|
|
32
|
-
parallelSafety: 'safe',
|
|
33
|
-
description: 'Start a platform-native command, script, or program in workspace/default cwd. Returns a stable processId (p_ plus 12 lowercase hex characters), status, bounded stdout/stderr, cumulative byte counts, dropped-byte counts, exitCode and truncated. A completed status does not imply exitCode 0; inspect stderr/exitCode. For subsequent waiting, stdin writes or cancellation, call exec_wait directly with processId, not exec. Truncation does not stop the process. Cancelling the initial wait does not terminate the process. waitOutcome distinguishes snapshot, completion, and timeout. A foreground wait may return interrupted with reason=steer; the process keeps running.',
|
|
34
|
-
outputSchema: {
|
|
35
|
-
type: 'object',
|
|
36
|
-
required: ['content', 'data'],
|
|
37
|
-
properties: {
|
|
38
|
-
content: { type: 'string' },
|
|
39
|
-
data: {
|
|
40
|
-
type: 'object',
|
|
41
|
-
required: [
|
|
42
|
-
'status',
|
|
43
|
-
'stdout',
|
|
44
|
-
'stderr',
|
|
45
|
-
'truncated',
|
|
46
|
-
'stdoutBytes',
|
|
47
|
-
'stderrBytes',
|
|
48
|
-
'stdoutDroppedBytes',
|
|
49
|
-
'stderrDroppedBytes'
|
|
50
|
-
],
|
|
51
|
-
properties: {
|
|
52
|
-
status: { enum: ['running', 'completed', 'cancelled'] },
|
|
53
|
-
waitOutcome: { enum: ['snapshot', 'completion', 'timeout', 'yield', 'interrupted'] },
|
|
54
|
-
reason: { enum: ['steer'] },
|
|
55
|
-
processId: { type: 'string' },
|
|
56
|
-
stdout: { type: 'string' },
|
|
57
|
-
stderr: { type: 'string' },
|
|
58
|
-
exitCode: { type: ['number', 'null'] },
|
|
59
|
-
truncated: { type: 'boolean' },
|
|
60
|
-
stdoutBytes: { type: 'number' },
|
|
61
|
-
stderrBytes: { type: 'number' },
|
|
62
|
-
stdoutDroppedBytes: { type: 'number' },
|
|
63
|
-
stderrDroppedBytes: { type: 'number' },
|
|
64
|
-
cached: { type: 'boolean' }
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
inputSchema: {
|
|
70
|
-
type: 'object',
|
|
71
|
-
properties: {
|
|
72
|
-
command: {
|
|
73
|
-
type: 'string',
|
|
74
|
-
description: 'Platform-native command to start.'
|
|
75
|
-
},
|
|
76
|
-
cwd: {
|
|
77
|
-
type: 'string',
|
|
78
|
-
description: 'Optional relative/absolute start directory; defaults to workspace. Command-internal relative paths resolve from this directory.'
|
|
79
|
-
},
|
|
80
|
-
login: {
|
|
81
|
-
type: 'boolean',
|
|
82
|
-
default: true,
|
|
83
|
-
description: 'Use the Shell login/profile initialization. Defaults to true; false skips login startup. Does not force an interactive Shell.'
|
|
84
|
-
},
|
|
85
|
-
timeoutMs: {
|
|
86
|
-
type: 'integer',
|
|
87
|
-
minimum: 1,
|
|
88
|
-
maximum: TOOL_EXECUTION_LIMITS.execMaxTimeoutMs,
|
|
89
|
-
description: 'Optional process lifetime limit in milliseconds. Omitted means no process timeout; yieldMs only controls waiting.'
|
|
90
|
-
},
|
|
91
|
-
yieldMs: {
|
|
92
|
-
type: 'integer',
|
|
93
|
-
minimum: 0,
|
|
94
|
-
maximum: TOOL_EXECUTION_LIMITS.execMaxYieldMs,
|
|
95
|
-
default: TOOL_EXECUTION_LIMITS.execDefaultYieldMs,
|
|
96
|
-
description: `Wait before yielding output. Defaults to ${TOOL_EXECUTION_LIMITS.execDefaultYieldMs} ms. Maximum ${TOOL_EXECUTION_LIMITS.execMaxYieldMs} ms. Zero returns immediately. This does not extend the process timeout.`
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
required: ['command'],
|
|
100
|
-
additionalProperties: false
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
export const execWaitToolDefinition = {
|
|
104
|
-
name: 'exec_wait',
|
|
105
|
-
allowedCallers: ['direct', 'programmatic'],
|
|
106
|
-
parallelSafety: 'safe',
|
|
107
|
-
description: 'Wait for or control a managed process by processId. action defaults to poll: collect output until termination or the wait window ends, then return incremental stdout/stderr. New output does not end the wait. write sends data to stdin; cancel terminates the process or removes its cached result. Terminal polls return a bounded snapshot marked cached for up to five minutes. Cancelling a wait does not terminate the process. Uses the same Session-owned processes as exec; cannot start a process or extend its timeout. Inspect stderr/exitCode; completed does not imply success. Supports direct and programmatic calls; in Code Mode use tools.exec_wait. Poll results include waitOutcome; interrupted with reason=steer ends only a foreground wait, never the process.',
|
|
108
|
-
outputSchema: execToolDefinition.outputSchema,
|
|
109
|
-
inputSchema: {
|
|
110
|
-
type: 'object',
|
|
111
|
-
properties: {
|
|
112
|
-
processId: {
|
|
113
|
-
type: 'string',
|
|
114
|
-
minLength: 1,
|
|
115
|
-
description: 'Copy the complete processId returned by exec (p_ followed by 12 lowercase hex characters). Never use a cellId (c_); use code_exec_wait for cells.'
|
|
116
|
-
},
|
|
117
|
-
action: { enum: ['poll', 'write', 'cancel'], default: 'poll' },
|
|
118
|
-
yieldMs: {
|
|
119
|
-
type: 'integer',
|
|
120
|
-
minimum: 0,
|
|
121
|
-
maximum: TOOL_EXECUTION_LIMITS.execMaxPollYieldMs,
|
|
122
|
-
default: TOOL_EXECUTION_LIMITS.execDefaultYieldMs,
|
|
123
|
-
description: `Poll wait window in milliseconds; default ${TOOL_EXECUTION_LIMITS.execDefaultYieldMs}, maximum ${TOOL_EXECUTION_LIMITS.execMaxPollYieldMs}. Zero returns immediately. Not a process timeout.`
|
|
124
|
-
},
|
|
125
|
-
data: { type: 'string', description: 'Required stdin data for write.' }
|
|
126
|
-
},
|
|
127
|
-
required: ['processId'],
|
|
128
|
-
additionalProperties: false
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
/** Validate the public entry points before delegating to the single process manager. */
|
|
132
|
-
export function execToolInput(name, value) {
|
|
133
|
-
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
134
|
-
return invalidExecInput();
|
|
135
|
-
const input = value;
|
|
136
|
-
const allowed = name === 'exec'
|
|
137
|
-
? ['command', 'cwd', 'login', 'timeoutMs', 'yieldMs']
|
|
138
|
-
: ['processId', 'action', 'yieldMs', 'data'];
|
|
139
|
-
if (Object.keys(input).some((key) => !allowed.includes(key)))
|
|
140
|
-
return invalidExecInput();
|
|
141
|
-
if (name === 'exec')
|
|
142
|
-
return parseExecInput(input);
|
|
143
|
-
const action = input.action ?? 'poll';
|
|
144
|
-
if (!['poll', 'write', 'cancel'].includes(String(action)))
|
|
145
|
-
return invalidExecInput();
|
|
146
|
-
return parseExecInput({ ...input, action });
|
|
147
|
-
}
|
|
148
|
-
export class ExecTool {
|
|
149
|
-
paths;
|
|
150
|
-
maxOutputBytes;
|
|
151
|
-
maxProcesses;
|
|
152
|
-
environment;
|
|
153
|
-
shell;
|
|
154
|
-
processExecutor;
|
|
155
|
-
#processes = new Map();
|
|
156
|
-
#completed = new Map();
|
|
157
|
-
#handles = new RuntimeResourceHandles('process', (id) => this.#processes.has(id) || this.#completed.has(id));
|
|
158
|
-
#startingProcesses = new Set();
|
|
159
|
-
constructor(paths, maxOutputBytes = TOOL_EXECUTION_LIMITS.execDefaultMaxOutputBytes, maxProcesses = TOOL_EXECUTION_LIMITS.maxProcesses, environment = process.env, shell, processExecutor = directLocalProcessExecutor) {
|
|
160
|
-
this.paths = paths;
|
|
161
|
-
this.maxOutputBytes = maxOutputBytes;
|
|
162
|
-
this.maxProcesses = maxProcesses;
|
|
163
|
-
this.environment = environment;
|
|
164
|
-
this.shell = shell;
|
|
165
|
-
this.processExecutor = processExecutor;
|
|
166
|
-
}
|
|
167
|
-
async execute(arguments_, signal, owner, waitInterrupt, onOutput) {
|
|
168
|
-
if (signal?.aborted)
|
|
169
|
-
throw executionAbortReason(signal);
|
|
170
|
-
const input = parseExecInput(arguments_);
|
|
171
|
-
if ('processId' in input) {
|
|
172
|
-
this.#handles.assertType(input.processId);
|
|
173
|
-
const process = this.#processes.get(input.processId);
|
|
174
|
-
const completed = this.#completed.get(input.processId);
|
|
175
|
-
if (completed) {
|
|
176
|
-
if (owner !== undefined && completed.ownerSessionId !== owner.sessionId)
|
|
177
|
-
throw new MarAgentError('MAR_AGENT_PROCESS_NOT_FOUND', 'Managed process was not found.');
|
|
178
|
-
if (input.action === 'write')
|
|
179
|
-
throw new MarAgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'Completed process cannot accept input.');
|
|
180
|
-
if (input.action === 'cancel')
|
|
181
|
-
this.#removeCompleted(input.processId);
|
|
182
|
-
return {
|
|
183
|
-
...completed.result,
|
|
184
|
-
cached: true,
|
|
185
|
-
...(input.action === 'poll'
|
|
186
|
-
? waitMetadata(input.yieldMs === 0 ? 'snapshot' : 'completion')
|
|
187
|
-
: {})
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
if (!process ||
|
|
191
|
-
process.native ||
|
|
192
|
-
(owner !== undefined && process.ownerSessionId !== owner.sessionId))
|
|
193
|
-
throw new MarAgentError('MAR_AGENT_PROCESS_NOT_FOUND', 'Managed process was not found.');
|
|
194
|
-
let outcome;
|
|
195
|
-
if (input.action === 'poll' && input.yieldMs)
|
|
196
|
-
outcome = await waitForProcessCompletion(input.processId, process, Math.min(Math.max(input.yieldMs, 0), TOOL_EXECUTION_LIMITS.execMaxPollYieldMs), signal, waitInterrupt, onOutput);
|
|
197
|
-
if (input.action === 'write') {
|
|
198
|
-
if (process.status !== 'running')
|
|
199
|
-
throw new MarAgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'Completed process cannot accept input.');
|
|
200
|
-
process.child.stdin.write(input.data);
|
|
201
|
-
}
|
|
202
|
-
if (input.action === 'cancel')
|
|
203
|
-
await this.#terminate(process, true);
|
|
204
|
-
const result = this.#result(input.processId, process);
|
|
205
|
-
if (process.status !== 'running') {
|
|
206
|
-
this.#retainCompleted(input.processId, process);
|
|
207
|
-
if (input.action === 'cancel')
|
|
208
|
-
this.#removeCompleted(input.processId);
|
|
209
|
-
}
|
|
210
|
-
return {
|
|
211
|
-
...result,
|
|
212
|
-
...(input.action === 'poll'
|
|
213
|
-
? waitMetadata(input.yieldMs === 0
|
|
214
|
-
? 'snapshot'
|
|
215
|
-
: result.status !== 'running'
|
|
216
|
-
? 'completion'
|
|
217
|
-
: outcome === 'interrupted'
|
|
218
|
-
? 'interrupted'
|
|
219
|
-
: 'timeout')
|
|
220
|
-
: {})
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
const { id, managed } = await this.#startManaged(async () => {
|
|
224
|
-
const cwd = await this.paths.resolveWithDisplay(input.cwd ?? '.');
|
|
225
|
-
return {
|
|
226
|
-
command: input.command,
|
|
227
|
-
cwd: cwd.physicalPath,
|
|
228
|
-
shell: this.shell ?? true,
|
|
229
|
-
shellLogin: input.login ?? true,
|
|
230
|
-
environment: this.environment,
|
|
231
|
-
displayCwd: cwd.displayPath,
|
|
232
|
-
detached: process.platform !== 'win32',
|
|
233
|
-
...(owner === undefined ? {} : { owner }),
|
|
234
|
-
...(signal === undefined ? {} : { signal })
|
|
235
|
-
};
|
|
236
|
-
}, owner?.sessionId, false);
|
|
237
|
-
if (input.timeoutMs !== undefined) {
|
|
238
|
-
managed.timer = setTimeout(() => {
|
|
239
|
-
void this.#terminate(managed, true).then(() => this.#retainCompleted(id, managed));
|
|
240
|
-
}, Math.min(input.timeoutMs, TOOL_EXECUTION_LIMITS.execMaxTimeoutMs));
|
|
241
|
-
managed.timer.unref();
|
|
242
|
-
}
|
|
243
|
-
const yieldMs = Math.min(input.yieldMs ?? TOOL_EXECUTION_LIMITS.execDefaultYieldMs, TOOL_EXECUTION_LIMITS.execMaxYieldMs);
|
|
244
|
-
const outcome = yieldMs === 0
|
|
245
|
-
? undefined
|
|
246
|
-
: await waitForProcessCompletion(id, managed, yieldMs, signal, waitInterrupt, onOutput);
|
|
247
|
-
const result = this.#result(id, managed);
|
|
248
|
-
if (managed.status !== 'running')
|
|
249
|
-
this.#retainCompleted(id, managed);
|
|
250
|
-
return {
|
|
251
|
-
...result,
|
|
252
|
-
...waitMetadata(yieldMs === 0
|
|
253
|
-
? 'snapshot'
|
|
254
|
-
: result.status !== 'running'
|
|
255
|
-
? 'completion'
|
|
256
|
-
: outcome === 'interrupted'
|
|
257
|
-
? 'interrupted'
|
|
258
|
-
: 'timeout')
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
async #startManaged(request, ownerSessionId, native) {
|
|
262
|
-
if (this.#processes.size + this.#startingProcesses.size >= this.maxProcesses)
|
|
263
|
-
throw new MarAgentError('MAR_AGENT_PROCESS_LIMIT', `The Local Host shared managed-process limit (${this.maxProcesses}) was reached.`);
|
|
264
|
-
let resolveStarting;
|
|
265
|
-
const starting = {
|
|
266
|
-
...(ownerSessionId === undefined ? {} : { ownerSessionId }),
|
|
267
|
-
settled: new Promise((resolve) => (resolveStarting = resolve)),
|
|
268
|
-
resolveSettled: () => resolveStarting()
|
|
269
|
-
};
|
|
270
|
-
this.#startingProcesses.add(starting);
|
|
271
|
-
try {
|
|
272
|
-
const { displayCwd, ...input } = await request();
|
|
273
|
-
input.signal?.throwIfAborted();
|
|
274
|
-
let child;
|
|
275
|
-
try {
|
|
276
|
-
child = await this.processExecutor.spawn(input);
|
|
277
|
-
}
|
|
278
|
-
catch (error) {
|
|
279
|
-
input.signal?.throwIfAborted();
|
|
280
|
-
if (!native || error instanceof MarAgentError)
|
|
281
|
-
throw error;
|
|
282
|
-
throw new MarAgentError('MAR_AGENT_PROCESS_START_FAILED', 'Native process executor failed to start.', {
|
|
283
|
-
details: { reasonCode: error?.code ?? 'UNKNOWN' }
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
const id = this.#handles.create();
|
|
287
|
-
let resolveExited;
|
|
288
|
-
let resolveSettled;
|
|
289
|
-
const managed = {
|
|
290
|
-
child,
|
|
291
|
-
native,
|
|
292
|
-
...(ownerSessionId === undefined ? {} : { ownerSessionId }),
|
|
293
|
-
command: input.command,
|
|
294
|
-
cwd: displayCwd ?? input.cwd,
|
|
295
|
-
stdout: createOutputBuffer(),
|
|
296
|
-
stderr: createOutputBuffer(),
|
|
297
|
-
stdoutHistory: createOutputBuffer(),
|
|
298
|
-
stderrHistory: createOutputBuffer(),
|
|
299
|
-
status: 'running',
|
|
300
|
-
exited: new Promise((resolve) => (resolveExited = resolve)),
|
|
301
|
-
settled: new Promise((resolve) => (resolveSettled = resolve)),
|
|
302
|
-
resolveExited,
|
|
303
|
-
resolveSettled,
|
|
304
|
-
exitObserved: child.exitCode !== null || child.signalCode != null,
|
|
305
|
-
...(child.exitCode === null ? {} : { exitCode: child.exitCode }),
|
|
306
|
-
...(child.signalCode == null ? {} : { exitSignal: child.signalCode }),
|
|
307
|
-
finalized: false,
|
|
308
|
-
terminalResultReturned: false,
|
|
309
|
-
waiters: new Set()
|
|
310
|
-
};
|
|
311
|
-
this.#processes.set(id, managed);
|
|
312
|
-
if (native) {
|
|
313
|
-
// Keep unread bytes in the Readable buffer: Node otherwise resumes unused stdio at exit.
|
|
314
|
-
const readable = () => { };
|
|
315
|
-
child.stdout.on('readable', readable);
|
|
316
|
-
child.stderr.on('readable', readable);
|
|
317
|
-
child.once('close', () => {
|
|
318
|
-
child.stdout.removeListener('readable', readable);
|
|
319
|
-
child.stderr.removeListener('readable', readable);
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
if (!native) {
|
|
323
|
-
const listen = (name) => child[name].on('data', (chunk) => {
|
|
324
|
-
if (managed.finalized)
|
|
325
|
-
return;
|
|
326
|
-
const decoded = Buffer.from(managed[name].decoder.write(chunk));
|
|
327
|
-
appendOutput(managed[name], decoded, this.maxOutputBytes, chunk.length);
|
|
328
|
-
appendOutput(managed[name === 'stdout' ? 'stdoutHistory' : 'stderrHistory'], decoded, this.maxOutputBytes, chunk.length);
|
|
329
|
-
notifyProcessChange(managed);
|
|
330
|
-
});
|
|
331
|
-
listen('stdout');
|
|
332
|
-
listen('stderr');
|
|
333
|
-
}
|
|
334
|
-
child.once('exit', (code, signal) => {
|
|
335
|
-
managed.exitObserved = true;
|
|
336
|
-
managed.exitCode = code;
|
|
337
|
-
managed.exitSignal = signal;
|
|
338
|
-
managed.resolveExited();
|
|
339
|
-
if (!native)
|
|
340
|
-
void finalizeAfterOutputGrace(managed, this.maxOutputBytes).then(() => this.#retainCompleted(id, managed));
|
|
341
|
-
});
|
|
342
|
-
child.once('close', (code, signal) => {
|
|
343
|
-
managed.exitObserved = true;
|
|
344
|
-
managed.exitSignal = signal;
|
|
345
|
-
managed.resolveExited();
|
|
346
|
-
finalizeManagedProcess(managed, this.maxOutputBytes, code);
|
|
347
|
-
if (native)
|
|
348
|
-
this.#processes.delete(id);
|
|
349
|
-
else
|
|
350
|
-
this.#retainCompleted(id, managed);
|
|
351
|
-
});
|
|
352
|
-
child.once('error', (error) => {
|
|
353
|
-
if (managed.finalized)
|
|
354
|
-
return;
|
|
355
|
-
if (native) {
|
|
356
|
-
managed.failure = new MarAgentError('MAR_AGENT_PROCESS_START_FAILED', 'Native process failed to start.', {
|
|
357
|
-
details: { reasonCode: error.code ?? 'UNKNOWN' }
|
|
358
|
-
});
|
|
359
|
-
managed.exitObserved = true;
|
|
360
|
-
managed.resolveExited();
|
|
361
|
-
}
|
|
362
|
-
else {
|
|
363
|
-
const message = Buffer.from(error.message);
|
|
364
|
-
appendOutput(managed.stderr, message, this.maxOutputBytes);
|
|
365
|
-
appendOutput(managed.stderrHistory, message, this.maxOutputBytes);
|
|
366
|
-
notifyProcessChange(managed);
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
if (managed.exitObserved) {
|
|
370
|
-
managed.resolveExited();
|
|
371
|
-
if (child.stdout.closed && child.stderr.closed) {
|
|
372
|
-
finalizeManagedProcess(managed, this.maxOutputBytes, child.exitCode);
|
|
373
|
-
if (native)
|
|
374
|
-
this.#processes.delete(id);
|
|
375
|
-
else
|
|
376
|
-
this.#retainCompleted(id, managed);
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
return { id, managed };
|
|
380
|
-
}
|
|
381
|
-
finally {
|
|
382
|
-
this.#startingProcesses.delete(starting);
|
|
383
|
-
starting.resolveSettled();
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
async spawn(input, call) {
|
|
387
|
-
validateCoreProcessInput(input);
|
|
388
|
-
input = {
|
|
389
|
-
...input,
|
|
390
|
-
...(input.argv === undefined ? {} : { argv: [...input.argv] }),
|
|
391
|
-
...(input.env === undefined ? {} : { env: { ...input.env } }),
|
|
392
|
-
...(input.input instanceof Uint8Array ? { input: new Uint8Array(input.input) } : {})
|
|
393
|
-
};
|
|
394
|
-
const { id, managed } = await this.#startManaged(async () => {
|
|
395
|
-
const cwd = await this.paths.resolve(input.cwd ?? '.');
|
|
396
|
-
return {
|
|
397
|
-
command: input.executable,
|
|
398
|
-
args: [...(input.argv ?? [])],
|
|
399
|
-
cwd,
|
|
400
|
-
shell: false,
|
|
401
|
-
environment: { ...this.environment, ...input.env },
|
|
402
|
-
environmentKeys: Object.keys(input.env ?? {}),
|
|
403
|
-
...(input.env === undefined ? {} : { environmentOverrides: input.env }),
|
|
404
|
-
detached: process.platform !== 'win32',
|
|
405
|
-
signal: call.signal,
|
|
406
|
-
owner: {
|
|
407
|
-
sessionId: call.sessionId,
|
|
408
|
-
operationId: call.operationId,
|
|
409
|
-
...(call.executionId ? { executionId: call.executionId } : {}),
|
|
410
|
-
...(call.ownerInstanceId ? { ownerInstanceId: call.ownerInstanceId } : {})
|
|
411
|
-
}
|
|
412
|
-
};
|
|
413
|
-
}, call.sessionId, true);
|
|
414
|
-
let cleanup;
|
|
415
|
-
const cancel = () => (cleanup ??= (async () => {
|
|
416
|
-
call.signal.removeEventListener('abort', abort);
|
|
417
|
-
await this.#terminate(managed, false);
|
|
418
|
-
destroyManagedStreams(managed);
|
|
419
|
-
this.#processes.delete(id);
|
|
420
|
-
})());
|
|
421
|
-
const abort = () => {
|
|
422
|
-
void cancel().catch(() => undefined);
|
|
423
|
-
};
|
|
424
|
-
call.signal.addEventListener('abort', abort, { once: true });
|
|
425
|
-
managed.child.once('close', () => call.signal.removeEventListener('abort', abort));
|
|
426
|
-
managed.child.stdin.on('error', (error) => {
|
|
427
|
-
if (error.code !== 'EPIPE' && !cleanup)
|
|
428
|
-
managed.failure = new MarAgentError('MAR_AGENT_PROCESS_IO_FAILED', 'Native process input failed.', {
|
|
429
|
-
details: { reasonCode: error.code ?? 'UNKNOWN' }
|
|
430
|
-
});
|
|
431
|
-
});
|
|
432
|
-
managed.child.stdin.end(input.input);
|
|
433
|
-
if (call.signal.aborted) {
|
|
434
|
-
await cancel();
|
|
435
|
-
call.signal.throwIfAborted();
|
|
436
|
-
}
|
|
437
|
-
const opened = new Promise((resolve, reject) => {
|
|
438
|
-
if (managed.child.pid) {
|
|
439
|
-
resolve();
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
|
-
if (managed.failure) {
|
|
443
|
-
reject(managed.failure);
|
|
444
|
-
return;
|
|
445
|
-
}
|
|
446
|
-
const spawned = () => {
|
|
447
|
-
managed.child.removeListener('error', failed);
|
|
448
|
-
resolve();
|
|
449
|
-
};
|
|
450
|
-
const failed = () => {
|
|
451
|
-
managed.child.removeListener('spawn', spawned);
|
|
452
|
-
reject(managed.failure);
|
|
453
|
-
};
|
|
454
|
-
managed.child.once('spawn', spawned);
|
|
455
|
-
managed.child.once('error', failed);
|
|
456
|
-
});
|
|
457
|
-
try {
|
|
458
|
-
await opened;
|
|
459
|
-
}
|
|
460
|
-
catch (error) {
|
|
461
|
-
await cancel();
|
|
462
|
-
throw error;
|
|
463
|
-
}
|
|
464
|
-
const stream = (name) => ({
|
|
465
|
-
async *[Symbol.asyncIterator]() {
|
|
466
|
-
try {
|
|
467
|
-
for await (const chunk of managed.child[name])
|
|
468
|
-
yield new Uint8Array(chunk);
|
|
469
|
-
}
|
|
470
|
-
catch (error) {
|
|
471
|
-
if (!cleanup && !call.signal.aborted)
|
|
472
|
-
throw new MarAgentError('MAR_AGENT_PROCESS_IO_FAILED', 'Native process output failed.', {
|
|
473
|
-
details: {
|
|
474
|
-
stream: name,
|
|
475
|
-
reasonCode: error.code ?? 'UNKNOWN'
|
|
476
|
-
}
|
|
477
|
-
});
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
});
|
|
481
|
-
return {
|
|
482
|
-
processId: id,
|
|
483
|
-
stdout: stream('stdout'),
|
|
484
|
-
stderr: stream('stderr'),
|
|
485
|
-
cancel,
|
|
486
|
-
wait: async () => {
|
|
487
|
-
await managed.exited;
|
|
488
|
-
call.signal.throwIfAborted();
|
|
489
|
-
if (managed.failure)
|
|
490
|
-
throw managed.failure;
|
|
491
|
-
return { code: managed.exitCode ?? null, signal: managed.exitSignal ?? null };
|
|
492
|
-
}
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
listSessionResources(sessionId) {
|
|
496
|
-
return [
|
|
497
|
-
...[...this.#processes.entries()].flatMap(([processId, process]) => !process.native && process.ownerSessionId === sessionId
|
|
498
|
-
? [{ processId, status: process.status, command: process.command, cwd: process.cwd }]
|
|
499
|
-
: []),
|
|
500
|
-
...[...this.#completed.entries()].flatMap(([processId, process]) => process.ownerSessionId === sessionId
|
|
501
|
-
? [
|
|
502
|
-
{
|
|
503
|
-
processId,
|
|
504
|
-
status: process.result.status,
|
|
505
|
-
command: process.command,
|
|
506
|
-
cwd: process.cwd
|
|
507
|
-
}
|
|
508
|
-
]
|
|
509
|
-
: [])
|
|
510
|
-
];
|
|
511
|
-
}
|
|
512
|
-
async disposeSession(sessionId) {
|
|
513
|
-
await Promise.all([...this.#startingProcesses]
|
|
514
|
-
.filter((process) => process.ownerSessionId === sessionId)
|
|
515
|
-
.map((process) => process.settled));
|
|
516
|
-
const owned = [...this.#processes.entries()].filter(([, process]) => process.ownerSessionId === sessionId);
|
|
517
|
-
await Promise.all(owned.map(([, process]) => process.status === 'running' ? this.#terminate(process, false) : process.settled));
|
|
518
|
-
for (const [processId] of owned)
|
|
519
|
-
this.#processes.delete(processId);
|
|
520
|
-
for (const [processId, process] of this.#completed)
|
|
521
|
-
if (process.ownerSessionId === sessionId)
|
|
522
|
-
this.#removeCompleted(processId);
|
|
523
|
-
}
|
|
524
|
-
#removeCompleted(id) {
|
|
525
|
-
const completed = this.#completed.get(id);
|
|
526
|
-
if (!completed)
|
|
527
|
-
return;
|
|
528
|
-
clearTimeout(completed.timer);
|
|
529
|
-
this.#completed.delete(id);
|
|
530
|
-
}
|
|
531
|
-
#retainCompleted(id, process) {
|
|
532
|
-
if (process.native ||
|
|
533
|
-
process.status === 'running' ||
|
|
534
|
-
!process.finalized ||
|
|
535
|
-
!process.terminalResultReturned ||
|
|
536
|
-
this.#processes.get(id) !== process)
|
|
537
|
-
return;
|
|
538
|
-
this.#processes.delete(id);
|
|
539
|
-
const stdout = consumeOutput(process.stdoutHistory);
|
|
540
|
-
const stderr = consumeOutput(process.stderrHistory);
|
|
541
|
-
const timer = setTimeout(() => this.#removeCompleted(id), TOOL_EXECUTION_LIMITS.execCompletedRetentionMs);
|
|
542
|
-
timer.unref();
|
|
543
|
-
this.#completed.set(id, {
|
|
544
|
-
...(process.ownerSessionId === undefined ? {} : { ownerSessionId: process.ownerSessionId }),
|
|
545
|
-
command: process.command,
|
|
546
|
-
cwd: process.cwd,
|
|
547
|
-
timer,
|
|
548
|
-
result: {
|
|
549
|
-
status: process.status,
|
|
550
|
-
processId: id,
|
|
551
|
-
stdout: stdout.value,
|
|
552
|
-
stderr: stderr.value,
|
|
553
|
-
...(process.exitCode === undefined ? {} : { exitCode: process.exitCode }),
|
|
554
|
-
truncated: stdout.droppedBytes > 0 || stderr.droppedBytes > 0,
|
|
555
|
-
stdoutBytes: process.stdout.totalBytes,
|
|
556
|
-
stderrBytes: process.stderr.totalBytes,
|
|
557
|
-
stdoutDroppedBytes: stdout.droppedBytes,
|
|
558
|
-
stderrDroppedBytes: stderr.droppedBytes
|
|
559
|
-
}
|
|
560
|
-
});
|
|
561
|
-
while (this.#completed.size > TOOL_EXECUTION_LIMITS.execMaxCompletedResults)
|
|
562
|
-
this.#removeCompleted(this.#completed.keys().next().value);
|
|
563
|
-
}
|
|
564
|
-
async #terminate(managed, waitForOutputClose) {
|
|
565
|
-
if (managed.terminate)
|
|
566
|
-
return managed.terminate;
|
|
567
|
-
managed.terminate = (async () => {
|
|
568
|
-
if (managed.exitObserved || managed.child.exitCode !== null) {
|
|
569
|
-
if (managed.native && !managed.finalized)
|
|
570
|
-
await signalProcessTree(managed.child, 'SIGKILL');
|
|
571
|
-
if (managed.child.exitCode !== null)
|
|
572
|
-
managed.exitCode = managed.child.exitCode;
|
|
573
|
-
if (waitForOutputClose) {
|
|
574
|
-
const settled = await waitForExit(managed.settled, TOOL_EXECUTION_LIMITS.execTerminationGraceMs);
|
|
575
|
-
if (settled)
|
|
576
|
-
return;
|
|
577
|
-
}
|
|
578
|
-
finalizeManagedProcess(managed, this.maxOutputBytes, managed.child.exitCode);
|
|
579
|
-
destroyManagedStreams(managed);
|
|
580
|
-
return;
|
|
581
|
-
}
|
|
582
|
-
managed.status = 'cancelled';
|
|
583
|
-
if (managed.timer)
|
|
584
|
-
clearTimeout(managed.timer);
|
|
585
|
-
await signalProcessTree(managed.child, 'SIGTERM');
|
|
586
|
-
const exited = await waitForExit(managed.exited, TOOL_EXECUTION_LIMITS.execTerminationGraceMs);
|
|
587
|
-
if (!exited) {
|
|
588
|
-
await signalProcessTree(managed.child, 'SIGKILL');
|
|
589
|
-
await managed.exited;
|
|
590
|
-
}
|
|
591
|
-
// A parent may exit on TERM while descendants ignore it and keep the pipes alive.
|
|
592
|
-
if (managed.native)
|
|
593
|
-
await signalProcessTree(managed.child, 'SIGKILL');
|
|
594
|
-
if (waitForOutputClose) {
|
|
595
|
-
const settled = await waitForExit(managed.settled, TOOL_EXECUTION_LIMITS.execTerminationGraceMs);
|
|
596
|
-
if (settled)
|
|
597
|
-
return;
|
|
598
|
-
}
|
|
599
|
-
finalizeManagedProcess(managed, this.maxOutputBytes, managed.exitCode);
|
|
600
|
-
destroyManagedStreams(managed);
|
|
601
|
-
})();
|
|
602
|
-
return managed.terminate;
|
|
603
|
-
}
|
|
604
|
-
#result(id, process) {
|
|
605
|
-
// Uncollected terminal output is a live resource, not an expiring replay.
|
|
606
|
-
if (process.status !== 'running')
|
|
607
|
-
process.terminalResultReturned = true;
|
|
608
|
-
const stdout = consumeOutput(process.stdout);
|
|
609
|
-
const stderr = consumeOutput(process.stderr);
|
|
610
|
-
return {
|
|
611
|
-
status: process.status,
|
|
612
|
-
processId: id,
|
|
613
|
-
stdout: stdout.value,
|
|
614
|
-
stderr: stderr.value,
|
|
615
|
-
...(process.exitCode === undefined ? {} : { exitCode: process.exitCode }),
|
|
616
|
-
truncated: stdout.droppedBytes > 0 || stderr.droppedBytes > 0,
|
|
617
|
-
stdoutBytes: process.stdout.totalBytes,
|
|
618
|
-
stderrBytes: process.stderr.totalBytes,
|
|
619
|
-
stdoutDroppedBytes: stdout.droppedBytes,
|
|
620
|
-
stderrDroppedBytes: stderr.droppedBytes
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
async dispose() {
|
|
624
|
-
await Promise.all([...this.#startingProcesses].map((process) => process.settled));
|
|
625
|
-
await Promise.all([...this.#processes.values()].map((process) => process.status === 'running' ? this.#terminate(process, false) : process.settled));
|
|
626
|
-
this.#processes.clear();
|
|
627
|
-
for (const id of this.#completed.keys())
|
|
628
|
-
this.#removeCompleted(id);
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
function createOutputBuffer() {
|
|
632
|
-
return {
|
|
633
|
-
chunks: [],
|
|
634
|
-
bytes: 0,
|
|
635
|
-
totalBytes: 0,
|
|
636
|
-
droppedBytes: 0,
|
|
637
|
-
windowOffset: 0,
|
|
638
|
-
decoder: new StringDecoder('utf8')
|
|
639
|
-
};
|
|
640
|
-
}
|
|
641
|
-
function finalizeManagedProcess(managed, maximumOutputBytes, exitCode) {
|
|
642
|
-
if (managed.finalized)
|
|
643
|
-
return;
|
|
644
|
-
managed.finalized = true;
|
|
645
|
-
const stdoutEnd = Buffer.from(managed.stdout.decoder.end());
|
|
646
|
-
const stderrEnd = Buffer.from(managed.stderr.decoder.end());
|
|
647
|
-
appendOutput(managed.stdout, stdoutEnd, maximumOutputBytes);
|
|
648
|
-
appendOutput(managed.stderr, stderrEnd, maximumOutputBytes);
|
|
649
|
-
appendOutput(managed.stdoutHistory, stdoutEnd, maximumOutputBytes);
|
|
650
|
-
appendOutput(managed.stderrHistory, stderrEnd, maximumOutputBytes);
|
|
651
|
-
managed.status = managed.status === 'cancelled' ? 'cancelled' : 'completed';
|
|
652
|
-
if (exitCode !== undefined)
|
|
653
|
-
managed.exitCode = exitCode;
|
|
654
|
-
if (managed.timer)
|
|
655
|
-
clearTimeout(managed.timer);
|
|
656
|
-
notifyProcessChange(managed);
|
|
657
|
-
managed.resolveSettled();
|
|
658
|
-
}
|
|
659
|
-
async function finalizeAfterOutputGrace(managed, maximumOutputBytes) {
|
|
660
|
-
const settled = await waitForExit(managed.settled, TOOL_EXECUTION_LIMITS.execTerminationGraceMs);
|
|
661
|
-
if (settled)
|
|
662
|
-
return;
|
|
663
|
-
finalizeManagedProcess(managed, maximumOutputBytes, managed.exitCode);
|
|
664
|
-
destroyManagedStreams(managed);
|
|
665
|
-
}
|
|
666
|
-
function destroyManagedStreams(managed) {
|
|
667
|
-
managed.child.stdin.destroy();
|
|
668
|
-
managed.child.stdout.destroy();
|
|
669
|
-
managed.child.stderr.destroy();
|
|
670
|
-
}
|
|
671
|
-
function appendOutput(output, chunk, maximumBytes, receivedBytes = chunk.length) {
|
|
672
|
-
output.totalBytes += receivedBytes;
|
|
673
|
-
if (!chunk.length)
|
|
674
|
-
return;
|
|
675
|
-
output.chunks.push(chunk);
|
|
676
|
-
output.bytes += chunk.length;
|
|
677
|
-
// Retain the oldest and newest halves symmetrically so early failures stay
|
|
678
|
-
// visible next to the latest progress; droppedBytes makes the discarded
|
|
679
|
-
// middle explicit because it is not recoverable from this bounded buffer.
|
|
680
|
-
const overflow = output.bytes - maximumBytes;
|
|
681
|
-
if (overflow <= 0)
|
|
682
|
-
return;
|
|
683
|
-
const head = Math.ceil(maximumBytes / 2);
|
|
684
|
-
// Materialize the current window once per overflow so subsequent appends slice
|
|
685
|
-
// it zero-copy instead of re-concatenating the whole retained buffer per chunk.
|
|
686
|
-
let span = output.window;
|
|
687
|
-
if (!span || output.bytes !== span.length - output.windowOffset) {
|
|
688
|
-
span = Buffer.concat(output.chunks, output.bytes);
|
|
689
|
-
output.windowOffset = 0;
|
|
690
|
-
}
|
|
691
|
-
const content = span.subarray(output.windowOffset, output.windowOffset + output.bytes);
|
|
692
|
-
output.chunks = [];
|
|
693
|
-
output.bytes = 0;
|
|
694
|
-
const pushSlice = (start, end) => {
|
|
695
|
-
while (start < end && (content[start] & 0xc0) === 0x80)
|
|
696
|
-
start++;
|
|
697
|
-
while (end > start && end < content.length && (content[end] & 0xc0) === 0x80)
|
|
698
|
-
end--;
|
|
699
|
-
if (start >= end)
|
|
700
|
-
return;
|
|
701
|
-
const slice = content.subarray(start, end);
|
|
702
|
-
output.chunks.push(slice);
|
|
703
|
-
output.bytes += slice.length;
|
|
704
|
-
};
|
|
705
|
-
pushSlice(0, Math.min(head, content.length));
|
|
706
|
-
pushSlice(Math.min(head + overflow, content.length), content.length);
|
|
707
|
-
output.droppedBytes += content.length - output.bytes;
|
|
708
|
-
output.window = span;
|
|
709
|
-
}
|
|
710
|
-
function consumeOutput(output) {
|
|
711
|
-
const value = Buffer.concat(output.chunks, output.bytes).toString('utf8');
|
|
712
|
-
const droppedBytes = output.droppedBytes;
|
|
713
|
-
output.chunks = [];
|
|
714
|
-
output.bytes = 0;
|
|
715
|
-
output.droppedBytes = 0;
|
|
716
|
-
delete output.window;
|
|
717
|
-
output.windowOffset = 0;
|
|
718
|
-
return { value, droppedBytes };
|
|
719
|
-
}
|
|
720
|
-
function parseExecInput(value) {
|
|
721
|
-
if (!value || typeof value !== 'object')
|
|
722
|
-
return invalidExecInput();
|
|
723
|
-
const input = value;
|
|
724
|
-
const action = input.action == null && typeof input.command === 'string' ? 'start' : input.action;
|
|
725
|
-
if (!['start', 'poll', 'write', 'cancel'].includes(String(action)))
|
|
726
|
-
return invalidExecInput();
|
|
727
|
-
const yieldMs = optionalBoundedInteger(input.yieldMs, 0, action === 'poll'
|
|
728
|
-
? TOOL_EXECUTION_LIMITS.execMaxPollYieldMs
|
|
729
|
-
: TOOL_EXECUTION_LIMITS.execMaxYieldMs);
|
|
730
|
-
if (action === 'start') {
|
|
731
|
-
if (typeof input.command !== 'string' || input.command.trim() === '')
|
|
732
|
-
return invalidExecInput();
|
|
733
|
-
if (input.cwd !== undefined && input.cwd !== null && typeof input.cwd !== 'string')
|
|
734
|
-
return invalidExecInput();
|
|
735
|
-
if (input.login !== undefined && input.login !== null && typeof input.login !== 'boolean')
|
|
736
|
-
return invalidExecInput();
|
|
737
|
-
const timeoutMs = optionalBoundedInteger(input.timeoutMs, 1, TOOL_EXECUTION_LIMITS.execMaxTimeoutMs);
|
|
738
|
-
return {
|
|
739
|
-
...(input.action === 'start' ? { action: 'start' } : {}),
|
|
740
|
-
command: input.command,
|
|
741
|
-
...(typeof input.cwd === 'string' ? { cwd: input.cwd } : {}),
|
|
742
|
-
...(typeof input.login === 'boolean' ? { login: input.login } : {}),
|
|
743
|
-
...(timeoutMs === undefined ? {} : { timeoutMs }),
|
|
744
|
-
...(yieldMs === undefined ? {} : { yieldMs })
|
|
745
|
-
};
|
|
746
|
-
}
|
|
747
|
-
if (typeof input.processId !== 'string' || input.processId === '')
|
|
748
|
-
return invalidExecInput();
|
|
749
|
-
if (action === 'poll')
|
|
750
|
-
return {
|
|
751
|
-
action,
|
|
752
|
-
processId: input.processId,
|
|
753
|
-
yieldMs: yieldMs ?? TOOL_EXECUTION_LIMITS.execDefaultYieldMs
|
|
754
|
-
};
|
|
755
|
-
if (action === 'write') {
|
|
756
|
-
if (typeof input.data !== 'string')
|
|
757
|
-
return invalidExecInput();
|
|
758
|
-
return { action, processId: input.processId, data: input.data };
|
|
759
|
-
}
|
|
760
|
-
return { action: 'cancel', processId: input.processId };
|
|
761
|
-
}
|
|
762
|
-
function optionalBoundedInteger(value, minimum, maximum) {
|
|
763
|
-
if (value === undefined || value === null)
|
|
764
|
-
return undefined;
|
|
765
|
-
if (!Number.isInteger(value) || value < minimum)
|
|
766
|
-
invalidExecInput();
|
|
767
|
-
return Math.min(value, maximum);
|
|
768
|
-
}
|
|
769
|
-
function invalidExecInput() {
|
|
770
|
-
throw new MarAgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'Exec input is invalid.');
|
|
771
|
-
}
|
|
772
|
-
async function waitForExit(exited, delayMs) {
|
|
773
|
-
let timer;
|
|
774
|
-
try {
|
|
775
|
-
return await Promise.race([
|
|
776
|
-
exited.then(() => true),
|
|
777
|
-
new Promise((resolve) => {
|
|
778
|
-
timer = setTimeout(() => resolve(false), delayMs);
|
|
779
|
-
timer.unref();
|
|
780
|
-
})
|
|
781
|
-
]);
|
|
782
|
-
}
|
|
783
|
-
finally {
|
|
784
|
-
if (timer)
|
|
785
|
-
clearTimeout(timer);
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
function notifyProcessChange(managed) {
|
|
789
|
-
for (const resolve of managed.waiters)
|
|
790
|
-
resolve();
|
|
791
|
-
}
|
|
792
|
-
async function waitForProcessCompletion(processId, managed, waitMs, signal, interrupt, onOutput) {
|
|
793
|
-
const stopOutput = onOutput && watchProcessOutput(processId, managed, onOutput);
|
|
794
|
-
try {
|
|
795
|
-
return await waitForToolCondition({
|
|
796
|
-
ready: () => managed.finalized,
|
|
797
|
-
subscribe: (notify) => {
|
|
798
|
-
managed.waiters.add(notify);
|
|
799
|
-
return () => {
|
|
800
|
-
managed.waiters.delete(notify);
|
|
801
|
-
};
|
|
802
|
-
},
|
|
803
|
-
waitMs,
|
|
804
|
-
signal,
|
|
805
|
-
interrupt
|
|
806
|
-
});
|
|
807
|
-
}
|
|
808
|
-
finally {
|
|
809
|
-
stopOutput?.();
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
/** Coalesce display snapshots without consuming output or queueing behind a slow observer. */
|
|
813
|
-
function watchProcessOutput(processId, managed, onOutput) {
|
|
814
|
-
let stopped = false;
|
|
815
|
-
let dirty = false;
|
|
816
|
-
let timer;
|
|
817
|
-
let inFlight;
|
|
818
|
-
let failed = false;
|
|
819
|
-
const publish = () => {
|
|
820
|
-
dirty = false;
|
|
821
|
-
const preview = (output) => {
|
|
822
|
-
const bounded = createOutputBuffer();
|
|
823
|
-
for (const chunk of output.chunks)
|
|
824
|
-
appendOutput(bounded, chunk, TOOL_EXECUTION_LIMITS.execProgressMaxOutputBytes);
|
|
825
|
-
const result = consumeOutput(bounded);
|
|
826
|
-
return { ...result, droppedBytes: result.droppedBytes + output.droppedBytes };
|
|
827
|
-
};
|
|
828
|
-
const stdout = preview(managed.stdout);
|
|
829
|
-
const stderr = preview(managed.stderr);
|
|
830
|
-
inFlight = Promise.resolve()
|
|
831
|
-
.then(() => {
|
|
832
|
-
if (stopped)
|
|
833
|
-
return;
|
|
834
|
-
return onOutput({
|
|
835
|
-
processId,
|
|
836
|
-
stdout: stdout.value,
|
|
837
|
-
stderr: stderr.value,
|
|
838
|
-
truncated: stdout.droppedBytes > 0 || stderr.droppedBytes > 0
|
|
839
|
-
});
|
|
840
|
-
})
|
|
841
|
-
.catch(() => {
|
|
842
|
-
// Display delivery must not change the process result or wait deadline.
|
|
843
|
-
failed = true;
|
|
844
|
-
})
|
|
845
|
-
.finally(() => {
|
|
846
|
-
inFlight = undefined;
|
|
847
|
-
if (dirty)
|
|
848
|
-
schedule();
|
|
849
|
-
});
|
|
850
|
-
};
|
|
851
|
-
const schedule = () => {
|
|
852
|
-
if (stopped || failed || timer || inFlight)
|
|
853
|
-
return;
|
|
854
|
-
timer = setTimeout(() => {
|
|
855
|
-
timer = undefined;
|
|
856
|
-
publish();
|
|
857
|
-
}, TOOL_EXECUTION_LIMITS.execProgressIntervalMs);
|
|
858
|
-
timer.unref();
|
|
859
|
-
};
|
|
860
|
-
const changed = () => {
|
|
861
|
-
if (managed.stdout.bytes === 0 && managed.stderr.bytes === 0)
|
|
862
|
-
return;
|
|
863
|
-
dirty = true;
|
|
864
|
-
schedule();
|
|
865
|
-
};
|
|
866
|
-
managed.waiters.add(changed);
|
|
867
|
-
changed();
|
|
868
|
-
return () => {
|
|
869
|
-
stopped = true;
|
|
870
|
-
managed.waiters.delete(changed);
|
|
871
|
-
if (timer)
|
|
872
|
-
clearTimeout(timer);
|
|
873
|
-
};
|
|
874
|
-
}
|
|
875
|
-
function executionAbortReason(signal) {
|
|
876
|
-
return (signal?.reason ?? new MarAgentError('MAR_AGENT_EXECUTION_CANCELLED', 'Execution cancelled.'));
|
|
877
|
-
}
|