@openai/agents-core 0.8.4 → 0.9.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/dist/agentToolRunConfig.js +3 -0
- package/dist/agentToolRunConfig.js.map +1 -1
- package/dist/agentToolRunConfig.mjs +3 -0
- package/dist/agentToolRunConfig.mjs.map +1 -1
- package/dist/errors.d.ts +10 -0
- package/dist/errors.js +15 -1
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs +13 -0
- package/dist/errors.mjs.map +1 -1
- package/dist/handoff.js +1 -1
- package/dist/handoff.js.map +1 -1
- package/dist/handoff.mjs +1 -1
- package/dist/handoff.mjs.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -2
- package/dist/index.mjs.map +1 -1
- package/dist/items.d.ts +13 -0
- package/dist/items.js +15 -0
- package/dist/items.js.map +1 -1
- package/dist/items.mjs +15 -0
- package/dist/items.mjs.map +1 -1
- package/dist/memory/historyMutations.d.ts +6 -0
- package/dist/memory/historyMutations.js +32 -0
- package/dist/memory/historyMutations.js.map +1 -0
- package/dist/memory/historyMutations.mjs +29 -0
- package/dist/memory/historyMutations.mjs.map +1 -0
- package/dist/memory/memorySession.d.ts +3 -2
- package/dist/memory/memorySession.js +7 -0
- package/dist/memory/memorySession.js.map +1 -1
- package/dist/memory/memorySession.mjs +7 -0
- package/dist/memory/memorySession.mjs.map +1 -1
- package/dist/memory/session.d.ts +15 -0
- package/dist/memory/session.js +6 -0
- package/dist/memory/session.js.map +1 -1
- package/dist/memory/session.mjs +5 -0
- package/dist/memory/session.mjs.map +1 -1
- package/dist/metadata.js +2 -2
- package/dist/metadata.mjs +2 -2
- package/dist/model.d.ts +21 -0
- package/dist/run.d.ts +7 -1
- package/dist/run.js +116 -57
- package/dist/run.js.map +1 -1
- package/dist/run.mjs +117 -58
- package/dist/run.mjs.map +1 -1
- package/dist/runState.d.ts +83 -1
- package/dist/runState.js +96 -11
- package/dist/runState.js.map +1 -1
- package/dist/runState.mjs +95 -11
- package/dist/runState.mjs.map +1 -1
- package/dist/runner/errorHandlers.d.ts +13 -4
- package/dist/runner/errorHandlers.js +22 -4
- package/dist/runner/errorHandlers.js.map +1 -1
- package/dist/runner/errorHandlers.mjs +21 -4
- package/dist/runner/errorHandlers.mjs.map +1 -1
- package/dist/runner/items.js +11 -1
- package/dist/runner/items.js.map +1 -1
- package/dist/runner/items.mjs +11 -1
- package/dist/runner/items.mjs.map +1 -1
- package/dist/runner/modelPreparation.d.ts +1 -1
- package/dist/runner/modelPreparation.js +7 -7
- package/dist/runner/modelPreparation.js.map +1 -1
- package/dist/runner/modelPreparation.mjs +7 -7
- package/dist/runner/modelPreparation.mjs.map +1 -1
- package/dist/runner/runLoop.d.ts +2 -1
- package/dist/runner/runLoop.js +2 -2
- package/dist/runner/runLoop.js.map +1 -1
- package/dist/runner/runLoop.mjs +2 -2
- package/dist/runner/runLoop.mjs.map +1 -1
- package/dist/runner/sandbox.d.ts +33 -0
- package/dist/runner/sandbox.js +92 -0
- package/dist/runner/sandbox.js.map +1 -0
- package/dist/runner/sandbox.mjs +83 -0
- package/dist/runner/sandbox.mjs.map +1 -0
- package/dist/runner/toolExecution.js +25 -13
- package/dist/runner/toolExecution.js.map +1 -1
- package/dist/runner/toolExecution.mjs +25 -13
- package/dist/runner/toolExecution.mjs.map +1 -1
- package/dist/runner/tracing.js +1 -0
- package/dist/runner/tracing.js.map +1 -1
- package/dist/runner/tracing.mjs +1 -0
- package/dist/runner/tracing.mjs.map +1 -1
- package/dist/runner/turnPreparation.d.ts +2 -4
- package/dist/runner/turnPreparation.js +7 -3
- package/dist/runner/turnPreparation.js.map +1 -1
- package/dist/runner/turnPreparation.mjs +7 -3
- package/dist/runner/turnPreparation.mjs.map +1 -1
- package/dist/runner/turnResolution.js +158 -31
- package/dist/runner/turnResolution.js.map +1 -1
- package/dist/runner/turnResolution.mjs +160 -33
- package/dist/runner/turnResolution.mjs.map +1 -1
- package/dist/runner/types.d.ts +8 -8
- package/dist/sandbox/agent.d.ts +24 -0
- package/dist/sandbox/agent.js +68 -0
- package/dist/sandbox/agent.js.map +1 -0
- package/dist/sandbox/agent.mjs +64 -0
- package/dist/sandbox/agent.mjs.map +1 -0
- package/dist/sandbox/brand.d.ts +1 -0
- package/dist/sandbox/brand.js +5 -0
- package/dist/sandbox/brand.js.map +1 -0
- package/dist/sandbox/brand.mjs +2 -0
- package/dist/sandbox/brand.mjs.map +1 -0
- package/dist/sandbox/capabilities/base.d.ts +25 -0
- package/dist/sandbox/capabilities/base.js +89 -0
- package/dist/sandbox/capabilities/base.js.map +1 -0
- package/dist/sandbox/capabilities/base.mjs +84 -0
- package/dist/sandbox/capabilities/base.mjs.map +1 -0
- package/dist/sandbox/capabilities/compaction.d.ts +33 -0
- package/dist/sandbox/capabilities/compaction.js +172 -0
- package/dist/sandbox/capabilities/compaction.js.map +1 -0
- package/dist/sandbox/capabilities/compaction.mjs +164 -0
- package/dist/sandbox/capabilities/compaction.mjs.map +1 -0
- package/dist/sandbox/capabilities/filesystem.d.ts +14 -0
- package/dist/sandbox/capabilities/filesystem.js +447 -0
- package/dist/sandbox/capabilities/filesystem.js.map +1 -0
- package/dist/sandbox/capabilities/filesystem.mjs +444 -0
- package/dist/sandbox/capabilities/filesystem.mjs.map +1 -0
- package/dist/sandbox/capabilities/index.d.ts +19 -0
- package/dist/sandbox/capabilities/index.js +31 -0
- package/dist/sandbox/capabilities/index.js.map +1 -0
- package/dist/sandbox/capabilities/index.mjs +17 -0
- package/dist/sandbox/capabilities/index.mjs.map +1 -0
- package/dist/sandbox/capabilities/memory.d.ts +52 -0
- package/dist/sandbox/capabilities/memory.js +290 -0
- package/dist/sandbox/capabilities/memory.js.map +1 -0
- package/dist/sandbox/capabilities/memory.mjs +286 -0
- package/dist/sandbox/capabilities/memory.mjs.map +1 -0
- package/dist/sandbox/capabilities/shell.d.ts +15 -0
- package/dist/sandbox/capabilities/shell.js +130 -0
- package/dist/sandbox/capabilities/shell.js.map +1 -0
- package/dist/sandbox/capabilities/shell.mjs +127 -0
- package/dist/sandbox/capabilities/shell.mjs.map +1 -0
- package/dist/sandbox/capabilities/skills.d.ts +47 -0
- package/dist/sandbox/capabilities/skills.js +453 -0
- package/dist/sandbox/capabilities/skills.js.map +1 -0
- package/dist/sandbox/capabilities/skills.mjs +449 -0
- package/dist/sandbox/capabilities/skills.mjs.map +1 -0
- package/dist/sandbox/capabilities/transport.d.ts +3 -0
- package/dist/sandbox/capabilities/transport.js +33 -0
- package/dist/sandbox/capabilities/transport.js.map +1 -0
- package/dist/sandbox/capabilities/transport.mjs +28 -0
- package/dist/sandbox/capabilities/transport.mjs.map +1 -0
- package/dist/sandbox/client.d.ts +53 -0
- package/dist/sandbox/client.js +34 -0
- package/dist/sandbox/client.js.map +1 -0
- package/dist/sandbox/client.mjs +31 -0
- package/dist/sandbox/client.mjs.map +1 -0
- package/dist/sandbox/entries/factories.d.ts +17 -0
- package/dist/sandbox/entries/factories.js +112 -0
- package/dist/sandbox/entries/factories.js.map +1 -0
- package/dist/sandbox/entries/factories.mjs +94 -0
- package/dist/sandbox/entries/factories.mjs.map +1 -0
- package/dist/sandbox/entries/guards.d.ts +5 -0
- package/dist/sandbox/entries/guards.js +19 -0
- package/dist/sandbox/entries/guards.js.map +1 -0
- package/dist/sandbox/entries/guards.mjs +13 -0
- package/dist/sandbox/entries/guards.mjs.map +1 -0
- package/dist/sandbox/entries/index.d.ts +3 -0
- package/dist/sandbox/entries/index.js +26 -0
- package/dist/sandbox/entries/index.js.map +1 -0
- package/dist/sandbox/entries/index.mjs +3 -0
- package/dist/sandbox/entries/index.mjs.map +1 -0
- package/dist/sandbox/entries/types.d.ts +177 -0
- package/dist/sandbox/entries/types.js +3 -0
- package/dist/sandbox/entries/types.js.map +1 -0
- package/dist/sandbox/entries/types.mjs +2 -0
- package/dist/sandbox/entries/types.mjs.map +1 -0
- package/dist/sandbox/errors.d.ts +151 -0
- package/dist/sandbox/errors.js +303 -0
- package/dist/sandbox/errors.js.map +1 -0
- package/dist/sandbox/errors.mjs +251 -0
- package/dist/sandbox/errors.mjs.map +1 -0
- package/dist/sandbox/events.d.ts +51 -0
- package/dist/sandbox/events.js +104 -0
- package/dist/sandbox/events.js.map +1 -0
- package/dist/sandbox/events.mjs +95 -0
- package/dist/sandbox/events.mjs.map +1 -0
- package/dist/sandbox/index.d.ts +14 -0
- package/dist/sandbox/index.js +31 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/sandbox/index.mjs +15 -0
- package/dist/sandbox/index.mjs.map +1 -0
- package/dist/sandbox/internal.d.ts +7 -0
- package/dist/sandbox/internal.js +46 -0
- package/dist/sandbox/internal.js.map +1 -0
- package/dist/sandbox/internal.mjs +8 -0
- package/dist/sandbox/internal.mjs.map +1 -0
- package/dist/sandbox/local.d.ts +3 -0
- package/dist/sandbox/local.js +20 -0
- package/dist/sandbox/local.js.map +1 -0
- package/dist/sandbox/local.mjs +4 -0
- package/dist/sandbox/local.mjs.map +1 -0
- package/dist/sandbox/localSkills.d.ts +13 -0
- package/dist/sandbox/localSkills.js +62 -0
- package/dist/sandbox/localSkills.js.map +1 -0
- package/dist/sandbox/localSkills.mjs +59 -0
- package/dist/sandbox/localSkills.mjs.map +1 -0
- package/dist/sandbox/manifest.d.ts +86 -0
- package/dist/sandbox/manifest.js +553 -0
- package/dist/sandbox/manifest.js.map +1 -0
- package/dist/sandbox/manifest.mjs +545 -0
- package/dist/sandbox/manifest.mjs.map +1 -0
- package/dist/sandbox/memory/generation.d.ts +56 -0
- package/dist/sandbox/memory/generation.js +426 -0
- package/dist/sandbox/memory/generation.js.map +1 -0
- package/dist/sandbox/memory/generation.mjs +385 -0
- package/dist/sandbox/memory/generation.mjs.map +1 -0
- package/dist/sandbox/memory/prompts.d.ts +16 -0
- package/dist/sandbox/memory/prompts.js +1685 -0
- package/dist/sandbox/memory/prompts.js.map +1 -0
- package/dist/sandbox/memory/prompts.mjs +1679 -0
- package/dist/sandbox/memory/prompts.mjs.map +1 -0
- package/dist/sandbox/memory/rollouts.d.ts +33 -0
- package/dist/sandbox/memory/rollouts.js +228 -0
- package/dist/sandbox/memory/rollouts.js.map +1 -0
- package/dist/sandbox/memory/rollouts.mjs +221 -0
- package/dist/sandbox/memory/rollouts.mjs.map +1 -0
- package/dist/sandbox/memory/storage.d.ts +70 -0
- package/dist/sandbox/memory/storage.js +543 -0
- package/dist/sandbox/memory/storage.js.map +1 -0
- package/dist/sandbox/memory/storage.mjs +537 -0
- package/dist/sandbox/memory/storage.mjs.map +1 -0
- package/dist/sandbox/pathGrants.d.ts +11 -0
- package/dist/sandbox/pathGrants.js +28 -0
- package/dist/sandbox/pathGrants.js.map +1 -0
- package/dist/sandbox/pathGrants.mjs +25 -0
- package/dist/sandbox/pathGrants.mjs.map +1 -0
- package/dist/sandbox/permissions.d.ts +29 -0
- package/dist/sandbox/permissions.js +140 -0
- package/dist/sandbox/permissions.js.map +1 -0
- package/dist/sandbox/permissions.mjs +134 -0
- package/dist/sandbox/permissions.mjs.map +1 -0
- package/dist/sandbox/runtime/agentKeys.d.ts +7 -0
- package/dist/sandbox/runtime/agentKeys.js +76 -0
- package/dist/sandbox/runtime/agentKeys.js.map +1 -0
- package/dist/sandbox/runtime/agentKeys.mjs +69 -0
- package/dist/sandbox/runtime/agentKeys.mjs.map +1 -0
- package/dist/sandbox/runtime/agentPreparation.d.ts +20 -0
- package/dist/sandbox/runtime/agentPreparation.js +178 -0
- package/dist/sandbox/runtime/agentPreparation.js.map +1 -0
- package/dist/sandbox/runtime/agentPreparation.mjs +172 -0
- package/dist/sandbox/runtime/agentPreparation.mjs.map +1 -0
- package/dist/sandbox/runtime/index.d.ts +5 -0
- package/dist/sandbox/runtime/index.js +22 -0
- package/dist/sandbox/runtime/index.js.map +1 -0
- package/dist/sandbox/runtime/index.mjs +6 -0
- package/dist/sandbox/runtime/index.mjs.map +1 -0
- package/dist/sandbox/runtime/livePreservedSessions.d.ts +25 -0
- package/dist/sandbox/runtime/livePreservedSessions.js +58 -0
- package/dist/sandbox/runtime/livePreservedSessions.js.map +1 -0
- package/dist/sandbox/runtime/livePreservedSessions.mjs +51 -0
- package/dist/sandbox/runtime/livePreservedSessions.mjs.map +1 -0
- package/dist/sandbox/runtime/manager.d.ts +68 -0
- package/dist/sandbox/runtime/manager.js +704 -0
- package/dist/sandbox/runtime/manager.js.map +1 -0
- package/dist/sandbox/runtime/manager.mjs +697 -0
- package/dist/sandbox/runtime/manager.mjs.map +1 -0
- package/dist/sandbox/runtime/prompts.d.ts +6 -0
- package/dist/sandbox/runtime/prompts.js +108 -0
- package/dist/sandbox/runtime/prompts.js.map +1 -0
- package/dist/sandbox/runtime/prompts.mjs +101 -0
- package/dist/sandbox/runtime/prompts.mjs.map +1 -0
- package/dist/sandbox/runtime/providedSessionManifest.d.ts +3 -0
- package/dist/sandbox/runtime/providedSessionManifest.js +175 -0
- package/dist/sandbox/runtime/providedSessionManifest.js.map +1 -0
- package/dist/sandbox/runtime/providedSessionManifest.mjs +172 -0
- package/dist/sandbox/runtime/providedSessionManifest.mjs.map +1 -0
- package/dist/sandbox/runtime/runAsManifest.d.ts +4 -0
- package/dist/sandbox/runtime/runAsManifest.js +40 -0
- package/dist/sandbox/runtime/runAsManifest.js.map +1 -0
- package/dist/sandbox/runtime/runAsManifest.mjs +36 -0
- package/dist/sandbox/runtime/runAsManifest.mjs.map +1 -0
- package/dist/sandbox/runtime/sessionLifecycle.d.ts +6 -0
- package/dist/sandbox/runtime/sessionLifecycle.js +222 -0
- package/dist/sandbox/runtime/sessionLifecycle.js.map +1 -0
- package/dist/sandbox/runtime/sessionLifecycle.mjs +215 -0
- package/dist/sandbox/runtime/sessionLifecycle.mjs.map +1 -0
- package/dist/sandbox/runtime/sessionSerialization.d.ts +12 -0
- package/dist/sandbox/runtime/sessionSerialization.js +74 -0
- package/dist/sandbox/runtime/sessionSerialization.js.map +1 -0
- package/dist/sandbox/runtime/sessionSerialization.mjs +71 -0
- package/dist/sandbox/runtime/sessionSerialization.mjs.map +1 -0
- package/dist/sandbox/runtime/sessionState.d.ts +26 -0
- package/dist/sandbox/runtime/sessionState.js +113 -0
- package/dist/sandbox/runtime/sessionState.js.map +1 -0
- package/dist/sandbox/runtime/sessionState.mjs +104 -0
- package/dist/sandbox/runtime/sessionState.mjs.map +1 -0
- package/dist/sandbox/runtime/spans.d.ts +1 -0
- package/dist/sandbox/runtime/spans.js +51 -0
- package/dist/sandbox/runtime/spans.js.map +1 -0
- package/dist/sandbox/runtime/spans.mjs +48 -0
- package/dist/sandbox/runtime/spans.mjs.map +1 -0
- package/dist/sandbox/runtime/toolRehydration.d.ts +34 -0
- package/dist/sandbox/runtime/toolRehydration.js +207 -0
- package/dist/sandbox/runtime/toolRehydration.js.map +1 -0
- package/dist/sandbox/runtime/toolRehydration.mjs +200 -0
- package/dist/sandbox/runtime/toolRehydration.mjs.map +1 -0
- package/dist/sandbox/sandboxes/docker.d.ts +75 -0
- package/dist/sandbox/sandboxes/docker.js +2015 -0
- package/dist/sandbox/sandboxes/docker.js.map +1 -0
- package/dist/sandbox/sandboxes/docker.mjs +2010 -0
- package/dist/sandbox/sandboxes/docker.mjs.map +1 -0
- package/dist/sandbox/sandboxes/index.d.ts +3 -0
- package/dist/sandbox/sandboxes/index.js +20 -0
- package/dist/sandbox/sandboxes/index.js.map +1 -0
- package/dist/sandbox/sandboxes/index.mjs +4 -0
- package/dist/sandbox/sandboxes/index.mjs.map +1 -0
- package/dist/sandbox/sandboxes/shared/localSnapshotPaths.d.ts +1 -0
- package/dist/sandbox/sandboxes/shared/localSnapshotPaths.js +22 -0
- package/dist/sandbox/sandboxes/shared/localSnapshotPaths.js.map +1 -0
- package/dist/sandbox/sandboxes/shared/localSnapshotPaths.mjs +19 -0
- package/dist/sandbox/sandboxes/shared/localSnapshotPaths.mjs.map +1 -0
- package/dist/sandbox/sandboxes/shared/localSnapshots.d.ts +34 -0
- package/dist/sandbox/sandboxes/shared/localSnapshots.js +525 -0
- package/dist/sandbox/sandboxes/shared/localSnapshots.js.map +1 -0
- package/dist/sandbox/sandboxes/shared/localSnapshots.mjs +508 -0
- package/dist/sandbox/sandboxes/shared/localSnapshots.mjs.map +1 -0
- package/dist/sandbox/sandboxes/shared/localWorkspace.d.ts +27 -0
- package/dist/sandbox/sandboxes/shared/localWorkspace.js +693 -0
- package/dist/sandbox/sandboxes/shared/localWorkspace.js.map +1 -0
- package/dist/sandbox/sandboxes/shared/localWorkspace.mjs +684 -0
- package/dist/sandbox/sandboxes/shared/localWorkspace.mjs.map +1 -0
- package/dist/sandbox/sandboxes/shared/manifestPersistence.d.ts +15 -0
- package/dist/sandbox/sandboxes/shared/manifestPersistence.js +191 -0
- package/dist/sandbox/sandboxes/shared/manifestPersistence.js.map +1 -0
- package/dist/sandbox/sandboxes/shared/manifestPersistence.mjs +182 -0
- package/dist/sandbox/sandboxes/shared/manifestPersistence.mjs.map +1 -0
- package/dist/sandbox/sandboxes/shared/pty.d.ts +9 -0
- package/dist/sandbox/sandboxes/shared/pty.js +151 -0
- package/dist/sandbox/sandboxes/shared/pty.js.map +1 -0
- package/dist/sandbox/sandboxes/shared/pty.mjs +148 -0
- package/dist/sandbox/sandboxes/shared/pty.mjs.map +1 -0
- package/dist/sandbox/sandboxes/shared/runProcess.d.ts +16 -0
- package/dist/sandbox/sandboxes/shared/runProcess.js +90 -0
- package/dist/sandbox/sandboxes/shared/runProcess.js.map +1 -0
- package/dist/sandbox/sandboxes/shared/runProcess.mjs +86 -0
- package/dist/sandbox/sandboxes/shared/runProcess.mjs.map +1 -0
- package/dist/sandbox/sandboxes/shared/sessionStateValues.d.ts +18 -0
- package/dist/sandbox/sandboxes/shared/sessionStateValues.js +40 -0
- package/dist/sandbox/sandboxes/shared/sessionStateValues.js.map +1 -0
- package/dist/sandbox/sandboxes/shared/sessionStateValues.mjs +35 -0
- package/dist/sandbox/sandboxes/shared/sessionStateValues.mjs.map +1 -0
- package/dist/sandbox/sandboxes/shared/shellCommand.d.ts +17 -0
- package/dist/sandbox/sandboxes/shared/shellCommand.js +38 -0
- package/dist/sandbox/sandboxes/shared/shellCommand.js.map +1 -0
- package/dist/sandbox/sandboxes/shared/shellCommand.mjs +34 -0
- package/dist/sandbox/sandboxes/shared/shellCommand.mjs.map +1 -0
- package/dist/sandbox/sandboxes/types.d.ts +11 -0
- package/dist/sandbox/sandboxes/types.js +3 -0
- package/dist/sandbox/sandboxes/types.js.map +1 -0
- package/dist/sandbox/sandboxes/types.mjs +2 -0
- package/dist/sandbox/sandboxes/types.mjs.map +1 -0
- package/dist/sandbox/sandboxes/unixLocal.d.ts +95 -0
- package/dist/sandbox/sandboxes/unixLocal.js +863 -0
- package/dist/sandbox/sandboxes/unixLocal.js.map +1 -0
- package/dist/sandbox/sandboxes/unixLocal.mjs +858 -0
- package/dist/sandbox/sandboxes/unixLocal.mjs.map +1 -0
- package/dist/sandbox/session.d.ts +123 -0
- package/dist/sandbox/session.js +58 -0
- package/dist/sandbox/session.js.map +1 -0
- package/dist/sandbox/session.mjs +50 -0
- package/dist/sandbox/session.mjs.map +1 -0
- package/dist/sandbox/shared/compare.d.ts +2 -0
- package/dist/sandbox/shared/compare.js +13 -0
- package/dist/sandbox/shared/compare.js.map +1 -0
- package/dist/sandbox/shared/compare.mjs +9 -0
- package/dist/sandbox/shared/compare.mjs.map +1 -0
- package/dist/sandbox/shared/environment.d.ts +14 -0
- package/dist/sandbox/shared/environment.js +69 -0
- package/dist/sandbox/shared/environment.js.map +1 -0
- package/dist/sandbox/shared/environment.mjs +59 -0
- package/dist/sandbox/shared/environment.mjs.map +1 -0
- package/dist/sandbox/shared/hostPath.d.ts +4 -0
- package/dist/sandbox/shared/hostPath.js +22 -0
- package/dist/sandbox/shared/hostPath.js.map +1 -0
- package/dist/sandbox/shared/hostPath.mjs +16 -0
- package/dist/sandbox/shared/hostPath.mjs.map +1 -0
- package/dist/sandbox/shared/manifestCollections.d.ts +12 -0
- package/dist/sandbox/shared/manifestCollections.js +40 -0
- package/dist/sandbox/shared/manifestCollections.js.map +1 -0
- package/dist/sandbox/shared/manifestCollections.mjs +34 -0
- package/dist/sandbox/shared/manifestCollections.mjs.map +1 -0
- package/dist/sandbox/shared/media.d.ts +6 -0
- package/dist/sandbox/shared/media.js +126 -0
- package/dist/sandbox/shared/media.js.map +1 -0
- package/dist/sandbox/shared/media.mjs +119 -0
- package/dist/sandbox/shared/media.mjs.map +1 -0
- package/dist/sandbox/shared/output.d.ts +12 -0
- package/dist/sandbox/shared/output.js +108 -0
- package/dist/sandbox/shared/output.js.map +1 -0
- package/dist/sandbox/shared/output.mjs +103 -0
- package/dist/sandbox/shared/output.mjs.map +1 -0
- package/dist/sandbox/shared/posixPath.d.ts +7 -0
- package/dist/sandbox/shared/posixPath.js +90 -0
- package/dist/sandbox/shared/posixPath.js.map +1 -0
- package/dist/sandbox/shared/posixPath.mjs +81 -0
- package/dist/sandbox/shared/posixPath.mjs.map +1 -0
- package/dist/sandbox/shared/remoteMountCommandAllowlist.d.ts +3 -0
- package/dist/sandbox/shared/remoteMountCommandAllowlist.js +33 -0
- package/dist/sandbox/shared/remoteMountCommandAllowlist.js.map +1 -0
- package/dist/sandbox/shared/remoteMountCommandAllowlist.mjs +28 -0
- package/dist/sandbox/shared/remoteMountCommandAllowlist.mjs.map +1 -0
- package/dist/sandbox/shared/shell.d.ts +1 -0
- package/dist/sandbox/shared/shell.js +7 -0
- package/dist/sandbox/shared/shell.js.map +1 -0
- package/dist/sandbox/shared/shell.mjs +4 -0
- package/dist/sandbox/shared/shell.mjs.map +1 -0
- package/dist/sandbox/shared/stableJson.d.ts +12 -0
- package/dist/sandbox/shared/stableJson.js +40 -0
- package/dist/sandbox/shared/stableJson.js.map +1 -0
- package/dist/sandbox/shared/stableJson.mjs +35 -0
- package/dist/sandbox/shared/stableJson.mjs.map +1 -0
- package/dist/sandbox/shared/typeGuards.d.ts +6 -0
- package/dist/sandbox/shared/typeGuards.js +34 -0
- package/dist/sandbox/shared/typeGuards.js.map +1 -0
- package/dist/sandbox/shared/typeGuards.mjs +26 -0
- package/dist/sandbox/shared/typeGuards.mjs.map +1 -0
- package/dist/sandbox/snapshot.d.ts +60 -0
- package/dist/sandbox/snapshot.js +45 -0
- package/dist/sandbox/snapshot.js.map +1 -0
- package/dist/sandbox/snapshot.mjs +39 -0
- package/dist/sandbox/snapshot.mjs.map +1 -0
- package/dist/sandbox/users.d.ts +11 -0
- package/dist/sandbox/users.js +31 -0
- package/dist/sandbox/users.js.map +1 -0
- package/dist/sandbox/users.mjs +26 -0
- package/dist/sandbox/users.mjs.map +1 -0
- package/dist/sandbox/workspacePaths.d.ts +20 -0
- package/dist/sandbox/workspacePaths.js +73 -0
- package/dist/sandbox/workspacePaths.js.map +1 -0
- package/dist/sandbox/workspacePaths.mjs +69 -0
- package/dist/sandbox/workspacePaths.mjs.map +1 -0
- package/dist/tool.js +1 -1
- package/dist/tool.js.map +1 -1
- package/dist/tool.mjs +1 -1
- package/dist/tool.mjs.map +1 -1
- package/dist/types/protocol.d.ts +8 -0
- package/dist/types/protocol.js +1 -0
- package/dist/types/protocol.js.map +1 -1
- package/dist/types/protocol.mjs +1 -0
- package/dist/types/protocol.mjs.map +1 -1
- package/dist/utils/messages.d.ts +6 -0
- package/dist/utils/messages.js +21 -0
- package/dist/utils/messages.js.map +1 -1
- package/dist/utils/messages.mjs +20 -0
- package/dist/utils/messages.mjs.map +1 -1
- package/dist/utils/strictToolSchema.d.ts +4 -0
- package/dist/utils/strictToolSchema.js +358 -0
- package/dist/utils/strictToolSchema.js.map +1 -0
- package/dist/utils/strictToolSchema.mjs +353 -0
- package/dist/utils/strictToolSchema.mjs.map +1 -0
- package/dist/utils/tools.d.ts +3 -1
- package/dist/utils/tools.js +18 -7
- package/dist/utils/tools.js.map +1 -1
- package/dist/utils/tools.mjs +18 -7
- package/dist/utils/tools.mjs.map +1 -1
- package/dist/utils/zodJsonSchemaCompat.js +18 -16
- package/dist/utils/zodJsonSchemaCompat.js.map +1 -1
- package/dist/utils/zodJsonSchemaCompat.mjs +18 -16
- package/dist/utils/zodJsonSchemaCompat.mjs.map +1 -1
- package/package.json +25 -1
|
@@ -0,0 +1,858 @@
|
|
|
1
|
+
import { UserError } from "../../errors.mjs";
|
|
2
|
+
import { applyDiff } from "../../utils/applyDiff.mjs";
|
|
3
|
+
import { mkdir, mkdtemp, readFile, readdir, rm, stat, unlink, writeFile, } from 'node:fs/promises';
|
|
4
|
+
import { lstatSync, realpathSync } from 'node:fs';
|
|
5
|
+
import { spawn } from 'node:child_process';
|
|
6
|
+
import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
7
|
+
import { tmpdir, userInfo } from 'node:os';
|
|
8
|
+
import { normalizeSandboxClientCreateArgs } from "../client.mjs";
|
|
9
|
+
import { normalizeExposedPort, recordExposedPortEndpoint, } from "../session.mjs";
|
|
10
|
+
import { normalizeRelativePath } from "../manifest.mjs";
|
|
11
|
+
import { SandboxConfigurationError } from "../errors.mjs";
|
|
12
|
+
import { WorkspacePathPolicy, } from "../workspacePaths.mjs";
|
|
13
|
+
import { applyOwnershipRecursive, assertLocalWorkspaceManifestMetadataSupported, materializeLocalWorkspaceManifest, materializeLocalWorkspaceManifestEntry, materializeLocalWorkspaceManifestMounts, pathExists, } from "./shared/localWorkspace.mjs";
|
|
14
|
+
import { mergeManifestEntryDelta, mergeManifestDelta, sanitizeEnvironmentForPersistence, serializeManifest, } from "./shared/manifestPersistence.mjs";
|
|
15
|
+
import { isHostPathWithinRoot, relativeHostPathEscapesRoot, } from "../shared/hostPath.mjs";
|
|
16
|
+
import { assertViewImageByteLength, imageOutputFromBytes, } from "../shared/media.mjs";
|
|
17
|
+
import { elapsedSeconds, formatExecResponse, truncateOutput, } from "../shared/output.mjs";
|
|
18
|
+
import { canReuseLocalSnapshotWorkspace, createWorkspaceArchive, localSnapshotIsRestorable, persistLocalSnapshot, restoreLocalSnapshotToWorkspace, restoreWorkspaceArchive, serializeLocalSnapshotSpec, } from "./shared/localSnapshots.mjs";
|
|
19
|
+
import { spawnInPseudoTerminal } from "./shared/pty.mjs";
|
|
20
|
+
import { runSandboxProcess } from "./shared/runProcess.mjs";
|
|
21
|
+
import { resolveLocalShellCommand } from "./shared/shellCommand.mjs";
|
|
22
|
+
import { deserializeLocalSandboxSessionStateValues, normalizeExposedPorts, } from "./shared/sessionStateValues.mjs";
|
|
23
|
+
const DEFAULT_EXEC_YIELD_TIME_MS = 10_000;
|
|
24
|
+
const DEFAULT_WRITE_STDIN_YIELD_TIME_MS = 250;
|
|
25
|
+
const MAX_ACTIVE_PROCESS_OUTPUT_CHARS = 1024 * 1024;
|
|
26
|
+
const RUN_AS_LOOKUP_TIMEOUT_MS = 10_000;
|
|
27
|
+
const DEFAULT_SANDBOX_COMMAND_PATH = '/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin';
|
|
28
|
+
export class UnixLocalSandboxSession {
|
|
29
|
+
state;
|
|
30
|
+
defaultShell;
|
|
31
|
+
activeProcesses = new Map();
|
|
32
|
+
nextSessionId = 1;
|
|
33
|
+
closed = false;
|
|
34
|
+
constructor(args) {
|
|
35
|
+
this.state = args.state;
|
|
36
|
+
this.defaultShell = args.defaultShell;
|
|
37
|
+
}
|
|
38
|
+
createEditor(runAs) {
|
|
39
|
+
return new UnixLocalSandboxEditor(this, runAs);
|
|
40
|
+
}
|
|
41
|
+
supportsPty() {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
async resolveExposedPort(port) {
|
|
45
|
+
const exposedPort = normalizeExposedPort(port);
|
|
46
|
+
const configuredPorts = this.state.configuredExposedPorts ?? [];
|
|
47
|
+
if (configuredPorts.length > 0 && !configuredPorts.includes(exposedPort)) {
|
|
48
|
+
throw new SandboxConfigurationError(`UnixLocalSandboxClient was not configured to expose port ${exposedPort}.`, {
|
|
49
|
+
provider: 'UnixLocalSandboxClient',
|
|
50
|
+
port: exposedPort,
|
|
51
|
+
configuredPorts,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return recordExposedPortEndpoint(this.state, {
|
|
55
|
+
host: '127.0.0.1',
|
|
56
|
+
port: exposedPort,
|
|
57
|
+
tls: false,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async execCommand(args) {
|
|
61
|
+
return formatExecResponse(await this.exec(args));
|
|
62
|
+
}
|
|
63
|
+
async exec(args) {
|
|
64
|
+
const start = Date.now();
|
|
65
|
+
const cwd = this.resolveCommandWorkdir(args.workdir);
|
|
66
|
+
const logicalCwd = this.logicalWorkdirForPath(args.workdir);
|
|
67
|
+
const child = await this.spawnShellCommand(this.translateCommandInput(args.cmd), {
|
|
68
|
+
cwd,
|
|
69
|
+
logicalCwd,
|
|
70
|
+
shell: args.shell,
|
|
71
|
+
login: args.login ?? true,
|
|
72
|
+
runAs: args.runAs,
|
|
73
|
+
tty: args.tty ?? false,
|
|
74
|
+
});
|
|
75
|
+
const activeProcess = this.trackChildProcess(child, {
|
|
76
|
+
tty: args.tty ?? false,
|
|
77
|
+
});
|
|
78
|
+
if (!args.tty) {
|
|
79
|
+
await waitForProcessOrTimeout(activeProcess, args.yieldTimeMs ?? DEFAULT_EXEC_YIELD_TIME_MS);
|
|
80
|
+
const processOutput = consumeActiveProcessOutput(activeProcess);
|
|
81
|
+
if (activeProcess.done) {
|
|
82
|
+
const output = truncateOutput(this.translateCommandOutput(processOutput.output), args.maxOutputTokens);
|
|
83
|
+
return {
|
|
84
|
+
output: output.text,
|
|
85
|
+
stdout: this.translateCommandOutput(processOutput.stdout),
|
|
86
|
+
stderr: this.translateCommandOutput(processOutput.stderr),
|
|
87
|
+
wallTimeSeconds: elapsedSeconds(start),
|
|
88
|
+
exitCode: activeProcess.exitCode ?? 1,
|
|
89
|
+
originalTokenCount: output.originalTokenCount,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const output = truncateOutput(this.translateCommandOutput(processOutput.output), args.maxOutputTokens);
|
|
93
|
+
const sessionId = this.allocateProcessId(activeProcess);
|
|
94
|
+
return {
|
|
95
|
+
output: output.text,
|
|
96
|
+
stdout: this.translateCommandOutput(processOutput.stdout),
|
|
97
|
+
stderr: this.translateCommandOutput(processOutput.stderr),
|
|
98
|
+
wallTimeSeconds: elapsedSeconds(start),
|
|
99
|
+
sessionId,
|
|
100
|
+
originalTokenCount: output.originalTokenCount,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const yieldTimeMs = args.yieldTimeMs ?? DEFAULT_EXEC_YIELD_TIME_MS;
|
|
104
|
+
await waitForProcessOrTimeout(activeProcess, yieldTimeMs);
|
|
105
|
+
if (activeProcess.done) {
|
|
106
|
+
const processOutput = consumeActiveProcessOutput(activeProcess);
|
|
107
|
+
const output = truncateOutput(this.translateCommandOutput(processOutput.output), args.maxOutputTokens);
|
|
108
|
+
return {
|
|
109
|
+
output: output.text,
|
|
110
|
+
stdout: this.translateCommandOutput(processOutput.stdout),
|
|
111
|
+
stderr: this.translateCommandOutput(processOutput.stderr),
|
|
112
|
+
wallTimeSeconds: elapsedSeconds(start),
|
|
113
|
+
exitCode: activeProcess.exitCode ?? 1,
|
|
114
|
+
originalTokenCount: output.originalTokenCount,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const sessionId = this.allocateProcessId(activeProcess);
|
|
118
|
+
const processOutput = consumeActiveProcessOutput(activeProcess);
|
|
119
|
+
const output = truncateOutput(this.translateCommandOutput(processOutput.output), args.maxOutputTokens);
|
|
120
|
+
return {
|
|
121
|
+
output: output.text,
|
|
122
|
+
stdout: this.translateCommandOutput(processOutput.stdout),
|
|
123
|
+
stderr: this.translateCommandOutput(processOutput.stderr),
|
|
124
|
+
wallTimeSeconds: elapsedSeconds(start),
|
|
125
|
+
sessionId,
|
|
126
|
+
originalTokenCount: output.originalTokenCount,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
async writeStdin(args) {
|
|
130
|
+
const activeProcess = this.activeProcesses.get(args.sessionId);
|
|
131
|
+
if (!activeProcess) {
|
|
132
|
+
return formatExecResponse({
|
|
133
|
+
output: `write_stdin failed: session not found: ${args.sessionId}`,
|
|
134
|
+
wallTimeSeconds: 0,
|
|
135
|
+
exitCode: 1,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
const start = Date.now();
|
|
139
|
+
const chars = args.chars ?? '';
|
|
140
|
+
if (!activeProcess.tty && chars.includes('\u0003')) {
|
|
141
|
+
activeProcess.child.kill('SIGINT');
|
|
142
|
+
}
|
|
143
|
+
const remainingChars = activeProcess.tty
|
|
144
|
+
? chars
|
|
145
|
+
: chars.split('\u0003').join('');
|
|
146
|
+
if (remainingChars.length > 0) {
|
|
147
|
+
activeProcess.child.stdin.write(remainingChars);
|
|
148
|
+
}
|
|
149
|
+
await waitForProcessOrTimeout(activeProcess, args.yieldTimeMs ?? DEFAULT_WRITE_STDIN_YIELD_TIME_MS);
|
|
150
|
+
const processOutput = consumeActiveProcessOutput(activeProcess);
|
|
151
|
+
const output = truncateOutput(this.translateCommandOutput(processOutput.output), args.maxOutputTokens);
|
|
152
|
+
if (activeProcess.done) {
|
|
153
|
+
this.activeProcesses.delete(args.sessionId);
|
|
154
|
+
return formatExecResponse({
|
|
155
|
+
output: output.text,
|
|
156
|
+
wallTimeSeconds: elapsedSeconds(start),
|
|
157
|
+
exitCode: activeProcess.exitCode ?? 1,
|
|
158
|
+
originalTokenCount: output.originalTokenCount,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
return formatExecResponse({
|
|
162
|
+
output: output.text,
|
|
163
|
+
wallTimeSeconds: elapsedSeconds(start),
|
|
164
|
+
sessionId: args.sessionId,
|
|
165
|
+
originalTokenCount: output.originalTokenCount,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
async viewImage(args) {
|
|
169
|
+
await this.resolveFilesystemRunAs(args.runAs);
|
|
170
|
+
const filePath = this.resolveSandboxPath(args.path);
|
|
171
|
+
const info = await stat(filePath).catch(() => {
|
|
172
|
+
throw new UserError(`Image file not found: ${args.path}`);
|
|
173
|
+
});
|
|
174
|
+
if (!info.isFile()) {
|
|
175
|
+
throw new UserError(`Image path is not a file: ${args.path}`);
|
|
176
|
+
}
|
|
177
|
+
assertViewImageByteLength(args.path, info.size);
|
|
178
|
+
const bytes = await readFile(filePath);
|
|
179
|
+
return imageOutputFromBytes(args.path, bytes);
|
|
180
|
+
}
|
|
181
|
+
async pathExists(path, runAs) {
|
|
182
|
+
await this.resolveFilesystemRunAs(runAs);
|
|
183
|
+
return await pathExists(this.resolveSandboxPath(path));
|
|
184
|
+
}
|
|
185
|
+
async readFile(args) {
|
|
186
|
+
await this.resolveFilesystemRunAs(args.runAs);
|
|
187
|
+
const bytes = await readFile(this.resolveSandboxPath(args.path));
|
|
188
|
+
if (typeof args.maxBytes === 'number' && bytes.byteLength > args.maxBytes) {
|
|
189
|
+
return bytes.subarray(0, args.maxBytes);
|
|
190
|
+
}
|
|
191
|
+
return bytes;
|
|
192
|
+
}
|
|
193
|
+
async listDir(args) {
|
|
194
|
+
await this.resolveFilesystemRunAs(args.runAs);
|
|
195
|
+
const logicalPath = this.resolveLogicalPath(args.path);
|
|
196
|
+
const entries = await readdir(this.resolveSandboxPath(args.path), {
|
|
197
|
+
withFileTypes: true,
|
|
198
|
+
});
|
|
199
|
+
return entries.map((entry) => ({
|
|
200
|
+
name: entry.name,
|
|
201
|
+
path: logicalPath ? `${logicalPath}/${entry.name}` : entry.name,
|
|
202
|
+
type: entry.isDirectory() ? 'dir' : entry.isFile() ? 'file' : 'other',
|
|
203
|
+
}));
|
|
204
|
+
}
|
|
205
|
+
async materializeEntry(args) {
|
|
206
|
+
const runAs = await this.resolveFilesystemRunAs(args.runAs);
|
|
207
|
+
const logicalPath = this.resolveLogicalPath(args.path);
|
|
208
|
+
await materializeLocalWorkspaceManifestEntry(this.state.workspaceRootPath, logicalPath, args.entry);
|
|
209
|
+
if (runAs) {
|
|
210
|
+
await applyOwnershipRecursive(this.resolveSandboxPath(args.path), runAs.uid, runAs.gid);
|
|
211
|
+
}
|
|
212
|
+
this.state.manifest = mergeManifestEntryDelta(this.state.manifest, logicalPath, args.entry);
|
|
213
|
+
}
|
|
214
|
+
async applyManifest(manifest, runAs) {
|
|
215
|
+
assertLocalWorkspaceManifestMetadataSupported('UnixLocalSandboxClient', manifest);
|
|
216
|
+
const identity = await this.resolveFilesystemRunAs(runAs);
|
|
217
|
+
await materializeLocalWorkspaceManifest(manifest, this.state.workspaceRootPath);
|
|
218
|
+
const environment = await manifest.resolveEnvironment();
|
|
219
|
+
if (identity) {
|
|
220
|
+
for (const path of Object.keys(manifest.entries)) {
|
|
221
|
+
await applyOwnershipRecursive(this.resolveSandboxPath(path), identity.uid, identity.gid);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
this.state.environment = {
|
|
225
|
+
...this.state.environment,
|
|
226
|
+
...environment,
|
|
227
|
+
};
|
|
228
|
+
this.state.manifest = mergeManifestDelta(this.state.manifest, manifest);
|
|
229
|
+
}
|
|
230
|
+
async persistWorkspace() {
|
|
231
|
+
return await createWorkspaceArchive(this.state.workspaceRootPath, this.state.manifest.ephemeralPersistencePaths());
|
|
232
|
+
}
|
|
233
|
+
async hydrateWorkspace(data) {
|
|
234
|
+
await restoreWorkspaceArchive(data, this.state.workspaceRootPath);
|
|
235
|
+
await this.materializeRestoredWorkspaceMounts();
|
|
236
|
+
}
|
|
237
|
+
async stop() {
|
|
238
|
+
await this.stopActiveProcesses();
|
|
239
|
+
}
|
|
240
|
+
async shutdown() {
|
|
241
|
+
await this.close();
|
|
242
|
+
}
|
|
243
|
+
async delete() {
|
|
244
|
+
await this.close();
|
|
245
|
+
}
|
|
246
|
+
async close() {
|
|
247
|
+
if (this.closed) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
this.closed = true;
|
|
251
|
+
await this.stopActiveProcesses();
|
|
252
|
+
if (this.state.workspaceRootOwned) {
|
|
253
|
+
await rm(this.state.workspaceRootPath, { recursive: true, force: true });
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
async stopActiveProcesses() {
|
|
257
|
+
await Promise.all([...this.activeProcesses.values()].map(async (activeProcess) => {
|
|
258
|
+
if (!activeProcess.done) {
|
|
259
|
+
activeProcess.child.kill('SIGTERM');
|
|
260
|
+
await waitForProcessOrTimeout(activeProcess, 250);
|
|
261
|
+
}
|
|
262
|
+
if (!activeProcess.done) {
|
|
263
|
+
activeProcess.child.kill('SIGKILL');
|
|
264
|
+
await activeProcess.donePromise.catch(() => { });
|
|
265
|
+
}
|
|
266
|
+
}));
|
|
267
|
+
this.activeProcesses.clear();
|
|
268
|
+
}
|
|
269
|
+
resolveSandboxPath(path, options = {}) {
|
|
270
|
+
const resolved = this.resolveSandboxPathTarget(path, options);
|
|
271
|
+
const workspaceRelativePath = resolved.workspaceRelativePath ?? '';
|
|
272
|
+
if (!workspaceRelativePath && !resolved.grant) {
|
|
273
|
+
return this.state.workspaceRootPath;
|
|
274
|
+
}
|
|
275
|
+
if (resolved.grant) {
|
|
276
|
+
return validateResolvedHostPath({
|
|
277
|
+
path,
|
|
278
|
+
resolvedPath: resolved.path,
|
|
279
|
+
allowedRoot: resolved.grant.path,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
const mountPath = this.resolveLocalBindMountPath(workspaceRelativePath, path, options);
|
|
283
|
+
if (mountPath) {
|
|
284
|
+
return mountPath;
|
|
285
|
+
}
|
|
286
|
+
const resolvedPath = resolve(this.state.workspaceRootPath, workspaceRelativePath);
|
|
287
|
+
const relativeToRoot = relative(this.state.workspaceRootPath, resolvedPath);
|
|
288
|
+
if (relativeHostPathEscapesRoot(relativeToRoot)) {
|
|
289
|
+
throw new UserError(`Sandbox path "${path}" escapes the workspace root.`);
|
|
290
|
+
}
|
|
291
|
+
return validateResolvedHostPath({
|
|
292
|
+
path,
|
|
293
|
+
resolvedPath,
|
|
294
|
+
allowedRoot: this.state.workspaceRootPath,
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
resolveCommandWorkdir(path) {
|
|
298
|
+
return this.resolveSandboxPath(path);
|
|
299
|
+
}
|
|
300
|
+
resolveSandboxPathTarget(path, options = {}) {
|
|
301
|
+
return new WorkspacePathPolicy({
|
|
302
|
+
root: this.state.manifest.root,
|
|
303
|
+
extraPathGrants: this.state.manifest.extraPathGrants,
|
|
304
|
+
}).resolve(path, options);
|
|
305
|
+
}
|
|
306
|
+
resolveLocalBindMountPath(workspaceRelativePath, path, options) {
|
|
307
|
+
for (const { entry, mountPath } of this.state.manifest.mountTargets()) {
|
|
308
|
+
const source = localBindMountSource(entry);
|
|
309
|
+
if (!source) {
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
const mountRelativePath = new WorkspacePathPolicy({
|
|
313
|
+
root: this.state.manifest.root,
|
|
314
|
+
}).resolve(mountPath).workspaceRelativePath;
|
|
315
|
+
if (typeof mountRelativePath !== 'string') {
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
if (!pathWithinLogicalRoot(workspaceRelativePath, mountRelativePath)) {
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
if (options.forWrite && entry.readOnly !== false) {
|
|
322
|
+
throw new UserError(`Sandbox path "${path}" is inside a read-only local bind mount.`);
|
|
323
|
+
}
|
|
324
|
+
const childPath = workspaceRelativePath === mountRelativePath
|
|
325
|
+
? ''
|
|
326
|
+
: workspaceRelativePath.slice(mountRelativePath.length + 1);
|
|
327
|
+
const resolvedPath = childPath ? resolve(source, childPath) : source;
|
|
328
|
+
return validateResolvedHostPath({
|
|
329
|
+
path,
|
|
330
|
+
resolvedPath,
|
|
331
|
+
allowedRoot: source,
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
return undefined;
|
|
335
|
+
}
|
|
336
|
+
resolveLogicalPath(path) {
|
|
337
|
+
if (!path || path.trim().length === 0) {
|
|
338
|
+
return '';
|
|
339
|
+
}
|
|
340
|
+
const logicalRoot = this.state.manifest.root;
|
|
341
|
+
const trimmed = path.trim();
|
|
342
|
+
if (trimmed === logicalRoot) {
|
|
343
|
+
return '';
|
|
344
|
+
}
|
|
345
|
+
if (logicalRoot === '/') {
|
|
346
|
+
return normalizeRelativePath(trimmed.startsWith('/') ? trimmed.slice(1) : trimmed);
|
|
347
|
+
}
|
|
348
|
+
if (trimmed.startsWith(`${logicalRoot}/`)) {
|
|
349
|
+
return normalizeRelativePath(trimmed.slice(logicalRoot.length + 1));
|
|
350
|
+
}
|
|
351
|
+
if (trimmed.startsWith('/')) {
|
|
352
|
+
throw new UserError(`Sandbox path "${path}" must stay within ${logicalRoot}.`);
|
|
353
|
+
}
|
|
354
|
+
return normalizeRelativePath(trimmed);
|
|
355
|
+
}
|
|
356
|
+
async spawnShellCommand(command, args) {
|
|
357
|
+
const { shellPath, flag } = resolveLocalShellCommand({
|
|
358
|
+
shell: args.shell,
|
|
359
|
+
defaultShell: this.defaultShell,
|
|
360
|
+
envShell: process.env.SHELL,
|
|
361
|
+
login: args.login,
|
|
362
|
+
});
|
|
363
|
+
const runAs = await this.resolveCommandRunAs(args.runAs);
|
|
364
|
+
const env = buildCommandEnvironment({
|
|
365
|
+
environment: this.state.environment,
|
|
366
|
+
shellPath,
|
|
367
|
+
home: this.state.workspaceRootPath,
|
|
368
|
+
pwd: args.logicalCwd,
|
|
369
|
+
});
|
|
370
|
+
if (args.tty) {
|
|
371
|
+
return spawnInPseudoTerminal(shellPath, [flag, command], {
|
|
372
|
+
cwd: args.cwd,
|
|
373
|
+
env,
|
|
374
|
+
...(runAs
|
|
375
|
+
? {
|
|
376
|
+
uid: runAs.uid,
|
|
377
|
+
gid: runAs.gid,
|
|
378
|
+
}
|
|
379
|
+
: {}),
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
return spawn(shellPath, [flag, command], {
|
|
383
|
+
cwd: args.cwd,
|
|
384
|
+
env,
|
|
385
|
+
...(runAs
|
|
386
|
+
? {
|
|
387
|
+
uid: runAs.uid,
|
|
388
|
+
gid: runAs.gid,
|
|
389
|
+
}
|
|
390
|
+
: {}),
|
|
391
|
+
stdio: 'pipe',
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
translateCommandInput(command) {
|
|
395
|
+
// Unix-local is not a chroot; command rewriting preserves manifest-root UX while
|
|
396
|
+
// filesystem APIs continue to enforce host-path containment separately.
|
|
397
|
+
if (this.state.manifest.root === '/') {
|
|
398
|
+
return translateRootManifestCommandInput(command, this.state.workspaceRootPath);
|
|
399
|
+
}
|
|
400
|
+
return translateManifestRootCommandInput(command, this.state.manifest.root, this.state.workspaceRootPath);
|
|
401
|
+
}
|
|
402
|
+
translateCommandOutput(output) {
|
|
403
|
+
if (this.state.manifest.root === '/') {
|
|
404
|
+
return translateRootManifestCommandOutput(output, this.state.workspaceRootPath);
|
|
405
|
+
}
|
|
406
|
+
return translateManifestRootCommandOutput(output, this.state.manifest.root, this.state.workspaceRootPath);
|
|
407
|
+
}
|
|
408
|
+
async materializeRestoredWorkspaceMounts() {
|
|
409
|
+
await materializeLocalWorkspaceManifestMounts(this.state.manifest, this.state.workspaceRootPath);
|
|
410
|
+
}
|
|
411
|
+
logicalWorkdirForPath(path) {
|
|
412
|
+
return this.resolveSandboxPathTarget(path).path;
|
|
413
|
+
}
|
|
414
|
+
async resolveCommandRunAs(runAs) {
|
|
415
|
+
const identity = await this.resolveRunAsIdentity(runAs);
|
|
416
|
+
if (!identity || identity.isCurrentUser) {
|
|
417
|
+
return identity;
|
|
418
|
+
}
|
|
419
|
+
if (typeof process.getuid !== 'function' || process.getuid() !== 0) {
|
|
420
|
+
throw new UserError(`Unix-local sandbox runAs="${runAs}" requires the host process to run as root or the requested user.`);
|
|
421
|
+
}
|
|
422
|
+
return identity;
|
|
423
|
+
}
|
|
424
|
+
async resolveFilesystemRunAs(runAs) {
|
|
425
|
+
const identity = await this.resolveRunAsIdentity(runAs);
|
|
426
|
+
if (!identity || identity.isCurrentUser) {
|
|
427
|
+
return identity;
|
|
428
|
+
}
|
|
429
|
+
if (typeof process.getuid !== 'function' || process.getuid() !== 0) {
|
|
430
|
+
throw new UserError(`Unix-local sandbox filesystem operations cannot honor runAs="${runAs}" without root privileges.`);
|
|
431
|
+
}
|
|
432
|
+
return identity;
|
|
433
|
+
}
|
|
434
|
+
async resolveRunAsIdentity(runAs) {
|
|
435
|
+
if (!runAs || runAs.trim().length === 0) {
|
|
436
|
+
return undefined;
|
|
437
|
+
}
|
|
438
|
+
const requestedUser = runAs.trim();
|
|
439
|
+
const currentUser = userInfo().username;
|
|
440
|
+
const currentUid = typeof process.getuid === 'function' ? process.getuid() : undefined;
|
|
441
|
+
const currentGid = typeof process.getgid === 'function' ? process.getgid() : undefined;
|
|
442
|
+
if (requestedUser === currentUser &&
|
|
443
|
+
currentUid !== undefined &&
|
|
444
|
+
currentGid !== undefined) {
|
|
445
|
+
return {
|
|
446
|
+
username: currentUser,
|
|
447
|
+
uid: currentUid,
|
|
448
|
+
gid: currentGid,
|
|
449
|
+
isCurrentUser: true,
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
const [uidResult, gidResult] = await Promise.all([
|
|
453
|
+
runSandboxProcess('id', ['-u', requestedUser], {
|
|
454
|
+
timeoutMs: RUN_AS_LOOKUP_TIMEOUT_MS,
|
|
455
|
+
}),
|
|
456
|
+
runSandboxProcess('id', ['-g', requestedUser], {
|
|
457
|
+
timeoutMs: RUN_AS_LOOKUP_TIMEOUT_MS,
|
|
458
|
+
}),
|
|
459
|
+
]);
|
|
460
|
+
if (uidResult.status !== 0 || gidResult.status !== 0) {
|
|
461
|
+
throw new UserError(`Sandbox runAs user "${requestedUser}" could not be resolved on this host.`);
|
|
462
|
+
}
|
|
463
|
+
const uid = Number(uidResult.stdout.trim());
|
|
464
|
+
const gid = Number(gidResult.stdout.trim());
|
|
465
|
+
return {
|
|
466
|
+
username: requestedUser,
|
|
467
|
+
uid,
|
|
468
|
+
gid,
|
|
469
|
+
isCurrentUser: currentUid !== undefined &&
|
|
470
|
+
currentGid !== undefined &&
|
|
471
|
+
uid === currentUid &&
|
|
472
|
+
gid === currentGid,
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
trackChildProcess(child, options = {}) {
|
|
476
|
+
let resolveDone = () => { };
|
|
477
|
+
const donePromise = new Promise((resolve) => {
|
|
478
|
+
resolveDone = resolve;
|
|
479
|
+
});
|
|
480
|
+
let resolveOutputClosed = () => { };
|
|
481
|
+
const outputClosedPromise = new Promise((resolve) => {
|
|
482
|
+
resolveOutputClosed = resolve;
|
|
483
|
+
});
|
|
484
|
+
const activeProcess = {
|
|
485
|
+
child,
|
|
486
|
+
tty: options.tty ?? false,
|
|
487
|
+
output: '',
|
|
488
|
+
stdout: '',
|
|
489
|
+
stderr: '',
|
|
490
|
+
droppedOutputChars: 0,
|
|
491
|
+
droppedStdoutChars: 0,
|
|
492
|
+
droppedStderrChars: 0,
|
|
493
|
+
exitCode: null,
|
|
494
|
+
done: false,
|
|
495
|
+
donePromise,
|
|
496
|
+
resolveDone,
|
|
497
|
+
outputClosedPromise,
|
|
498
|
+
resolveOutputClosed,
|
|
499
|
+
};
|
|
500
|
+
let openOutputStreams = 2;
|
|
501
|
+
const markOutputStreamClosed = () => {
|
|
502
|
+
openOutputStreams -= 1;
|
|
503
|
+
if (openOutputStreams === 0) {
|
|
504
|
+
activeProcess.resolveOutputClosed();
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
child.stdout.setEncoding('utf8');
|
|
508
|
+
child.stderr.setEncoding('utf8');
|
|
509
|
+
child.stdout.on('data', (chunk) => {
|
|
510
|
+
appendActiveProcessOutput(activeProcess, chunk, 'stdout');
|
|
511
|
+
});
|
|
512
|
+
child.stderr.on('data', (chunk) => {
|
|
513
|
+
appendActiveProcessOutput(activeProcess, chunk, 'stderr');
|
|
514
|
+
});
|
|
515
|
+
child.stdout.once('close', markOutputStreamClosed);
|
|
516
|
+
child.stderr.once('close', markOutputStreamClosed);
|
|
517
|
+
child.on('close', (code, signal) => {
|
|
518
|
+
activeProcess.exitCode = code ?? signalToExitCode(signal);
|
|
519
|
+
activeProcess.done = true;
|
|
520
|
+
activeProcess.resolveDone();
|
|
521
|
+
});
|
|
522
|
+
child.on('error', (error) => {
|
|
523
|
+
appendActiveProcessOutput(activeProcess, `${error.message}\n`, 'stderr');
|
|
524
|
+
activeProcess.exitCode = 1;
|
|
525
|
+
activeProcess.done = true;
|
|
526
|
+
activeProcess.resolveOutputClosed();
|
|
527
|
+
activeProcess.resolveDone();
|
|
528
|
+
});
|
|
529
|
+
return activeProcess;
|
|
530
|
+
}
|
|
531
|
+
allocateProcessId(activeProcess) {
|
|
532
|
+
const sessionId = this.nextSessionId++;
|
|
533
|
+
this.activeProcesses.set(sessionId, activeProcess);
|
|
534
|
+
return sessionId;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
export class UnixLocalSandboxClient {
|
|
538
|
+
backendId = 'unix_local';
|
|
539
|
+
supportsDefaultOptions = true;
|
|
540
|
+
options;
|
|
541
|
+
constructor(options = {}) {
|
|
542
|
+
this.options = options;
|
|
543
|
+
}
|
|
544
|
+
async create(args, manifestOptions) {
|
|
545
|
+
const createArgs = normalizeSandboxClientCreateArgs(args, manifestOptions);
|
|
546
|
+
const manifest = createArgs.manifest;
|
|
547
|
+
const resolvedOptions = {
|
|
548
|
+
...this.options,
|
|
549
|
+
...createArgs.options,
|
|
550
|
+
...(createArgs.snapshot
|
|
551
|
+
? { snapshot: createArgs.snapshot }
|
|
552
|
+
: {}),
|
|
553
|
+
...(createArgs.concurrencyLimits
|
|
554
|
+
? { concurrencyLimits: createArgs.concurrencyLimits }
|
|
555
|
+
: {}),
|
|
556
|
+
};
|
|
557
|
+
assertLocalWorkspaceManifestMetadataSupported('UnixLocalSandboxClient', manifest);
|
|
558
|
+
const workspaceRootPath = await mkdtemp(join(resolvedOptions.workspaceBaseDir ?? tmpdir(), 'openai-agents-sandbox-'));
|
|
559
|
+
await materializeLocalWorkspaceManifest(manifest, workspaceRootPath, {
|
|
560
|
+
concurrencyLimits: resolvedOptions.concurrencyLimits,
|
|
561
|
+
});
|
|
562
|
+
const environment = await manifest.resolveEnvironment();
|
|
563
|
+
const configuredExposedPorts = normalizeExposedPorts(resolvedOptions.exposedPorts);
|
|
564
|
+
return new UnixLocalSandboxSession({
|
|
565
|
+
state: {
|
|
566
|
+
manifest,
|
|
567
|
+
workspaceRootPath,
|
|
568
|
+
workspaceRootOwned: true,
|
|
569
|
+
environment,
|
|
570
|
+
snapshotSpec: resolvedOptions.snapshot ?? null,
|
|
571
|
+
snapshot: null,
|
|
572
|
+
configuredExposedPorts,
|
|
573
|
+
},
|
|
574
|
+
defaultShell: resolvedOptions.defaultShell,
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
async resume(state) {
|
|
578
|
+
const restoredState = await this.restoreIfNeeded(state);
|
|
579
|
+
return new UnixLocalSandboxSession({
|
|
580
|
+
state: restoredState,
|
|
581
|
+
defaultShell: this.options.defaultShell,
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
async serializeSessionState(state) {
|
|
585
|
+
const snapshotSpec = state.snapshotSpec ?? this.options.snapshot ?? null;
|
|
586
|
+
const snapshot = await persistLocalSnapshot('UnixLocalSandboxClient', state, snapshotSpec);
|
|
587
|
+
state.snapshotSpec = snapshotSpec;
|
|
588
|
+
return {
|
|
589
|
+
manifest: serializeManifest(state.manifest),
|
|
590
|
+
workspaceRootPath: state.workspaceRootPath,
|
|
591
|
+
workspaceRootOwned: state.workspaceRootOwned,
|
|
592
|
+
environment: sanitizeEnvironmentForPersistence(state),
|
|
593
|
+
snapshotSpec: serializeLocalSnapshotSpec(snapshotSpec),
|
|
594
|
+
snapshot,
|
|
595
|
+
snapshotFingerprint: state.snapshotFingerprint ?? null,
|
|
596
|
+
snapshotFingerprintVersion: state.snapshotFingerprintVersion ?? null,
|
|
597
|
+
configuredExposedPorts: state.configuredExposedPorts ?? [],
|
|
598
|
+
exposedPorts: state.exposedPorts ?? null,
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
async deserializeSessionState(state) {
|
|
602
|
+
return deserializeLocalSandboxSessionStateValues(state, this.options.snapshot);
|
|
603
|
+
}
|
|
604
|
+
async restoreIfNeeded(state) {
|
|
605
|
+
if (await pathExists(state.workspaceRootPath)) {
|
|
606
|
+
if (await canReuseLocalSnapshotWorkspace(state)) {
|
|
607
|
+
return state;
|
|
608
|
+
}
|
|
609
|
+
if (await localSnapshotIsRestorable(state)) {
|
|
610
|
+
return await restoreSnapshotAndMounts(state, state.workspaceRootPath);
|
|
611
|
+
}
|
|
612
|
+
return state;
|
|
613
|
+
}
|
|
614
|
+
if (!(await localSnapshotIsRestorable(state))) {
|
|
615
|
+
throw new UserError('UnixLocal sandbox workspace is unavailable and no local snapshot could be restored.');
|
|
616
|
+
}
|
|
617
|
+
const workspaceRootPath = await mkdtemp(join(this.options.workspaceBaseDir ?? tmpdir(), 'openai-agents-sandbox-'));
|
|
618
|
+
return await restoreSnapshotAndMounts({
|
|
619
|
+
...state,
|
|
620
|
+
workspaceRootPath,
|
|
621
|
+
workspaceRootOwned: true,
|
|
622
|
+
}, workspaceRootPath);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
async function restoreSnapshotAndMounts(state, workspaceRootPath) {
|
|
626
|
+
const restoredState = await restoreLocalSnapshotToWorkspace(state, workspaceRootPath);
|
|
627
|
+
await materializeLocalWorkspaceManifestMounts(restoredState.manifest, restoredState.workspaceRootPath);
|
|
628
|
+
return restoredState;
|
|
629
|
+
}
|
|
630
|
+
function localBindMountSource(entry) {
|
|
631
|
+
if (entry.type !== 'mount' || typeof entry.source !== 'string') {
|
|
632
|
+
return undefined;
|
|
633
|
+
}
|
|
634
|
+
if (entry.mountStrategy !== undefined &&
|
|
635
|
+
entry.mountStrategy.type !== 'local_bind') {
|
|
636
|
+
return undefined;
|
|
637
|
+
}
|
|
638
|
+
return isAbsolute(entry.source) ? entry.source : undefined;
|
|
639
|
+
}
|
|
640
|
+
function pathWithinLogicalRoot(path, root) {
|
|
641
|
+
return path === root || path.startsWith(`${root}/`);
|
|
642
|
+
}
|
|
643
|
+
function validateResolvedHostPath(args) {
|
|
644
|
+
const allowedRootRealPath = realpathForValidation(args.allowedRoot, args.path);
|
|
645
|
+
const existingPath = nearestExistingPath(args.resolvedPath);
|
|
646
|
+
if (!existingPath) {
|
|
647
|
+
throw new UserError(`Sandbox path "${args.path}" escapes the workspace root.`);
|
|
648
|
+
}
|
|
649
|
+
const realPath = realpathForValidation(existingPath, args.path);
|
|
650
|
+
if (!isHostPathWithinRoot(allowedRootRealPath, realPath)) {
|
|
651
|
+
throw new UserError(`Sandbox path "${args.path}" escapes the workspace root.`);
|
|
652
|
+
}
|
|
653
|
+
return args.resolvedPath;
|
|
654
|
+
}
|
|
655
|
+
function nearestExistingPath(path) {
|
|
656
|
+
let current = path;
|
|
657
|
+
while (true) {
|
|
658
|
+
try {
|
|
659
|
+
lstatSync(current);
|
|
660
|
+
return current;
|
|
661
|
+
}
|
|
662
|
+
catch (error) {
|
|
663
|
+
if (error.code !== 'ENOENT') {
|
|
664
|
+
throw error;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
const parent = dirname(current);
|
|
668
|
+
if (parent === current) {
|
|
669
|
+
return undefined;
|
|
670
|
+
}
|
|
671
|
+
current = parent;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
function realpathForValidation(path, originalPath) {
|
|
675
|
+
try {
|
|
676
|
+
return realpathSync(path);
|
|
677
|
+
}
|
|
678
|
+
catch {
|
|
679
|
+
throw new UserError(`Sandbox path "${originalPath}" escapes the workspace root.`);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
class UnixLocalSandboxEditor {
|
|
683
|
+
session;
|
|
684
|
+
runAs;
|
|
685
|
+
constructor(session, runAs) {
|
|
686
|
+
this.session = session;
|
|
687
|
+
this.runAs = runAs;
|
|
688
|
+
}
|
|
689
|
+
async createFile(operation) {
|
|
690
|
+
const identity = await this.session.resolveFilesystemRunAs(this.runAs);
|
|
691
|
+
const filePath = this.session.resolveSandboxPath(operation.path, {
|
|
692
|
+
forWrite: true,
|
|
693
|
+
});
|
|
694
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
695
|
+
const content = applyDiff('', operation.diff, 'create');
|
|
696
|
+
await writeFile(filePath, content, { encoding: 'utf8', flag: 'wx' });
|
|
697
|
+
if (identity) {
|
|
698
|
+
await applyOwnershipRecursive(filePath, identity.uid, identity.gid);
|
|
699
|
+
}
|
|
700
|
+
return {};
|
|
701
|
+
}
|
|
702
|
+
async updateFile(operation) {
|
|
703
|
+
const identity = await this.session.resolveFilesystemRunAs(this.runAs);
|
|
704
|
+
const moveTo = operation.moveTo;
|
|
705
|
+
const filePath = this.session.resolveSandboxPath(operation.path, {
|
|
706
|
+
forWrite: true,
|
|
707
|
+
});
|
|
708
|
+
const destinationPath = moveTo
|
|
709
|
+
? this.session.resolveSandboxPath(moveTo, { forWrite: true })
|
|
710
|
+
: filePath;
|
|
711
|
+
const current = await readFile(filePath, 'utf8');
|
|
712
|
+
const next = applyDiff(current, operation.diff);
|
|
713
|
+
await mkdir(dirname(destinationPath), { recursive: true });
|
|
714
|
+
await writeFile(destinationPath, next, 'utf8');
|
|
715
|
+
if (moveTo && destinationPath !== filePath) {
|
|
716
|
+
await unlink(filePath);
|
|
717
|
+
}
|
|
718
|
+
if (identity) {
|
|
719
|
+
await applyOwnershipRecursive(destinationPath, identity.uid, identity.gid);
|
|
720
|
+
}
|
|
721
|
+
return {};
|
|
722
|
+
}
|
|
723
|
+
async deleteFile(operation) {
|
|
724
|
+
await this.session.resolveFilesystemRunAs(this.runAs);
|
|
725
|
+
const filePath = this.session.resolveSandboxPath(operation.path, {
|
|
726
|
+
forWrite: true,
|
|
727
|
+
});
|
|
728
|
+
await unlink(filePath);
|
|
729
|
+
return {};
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
function buildCommandEnvironment(args) {
|
|
733
|
+
return {
|
|
734
|
+
PATH: DEFAULT_SANDBOX_COMMAND_PATH,
|
|
735
|
+
HOME: args.home,
|
|
736
|
+
USER: 'sandbox',
|
|
737
|
+
LOGNAME: 'sandbox',
|
|
738
|
+
SHELL: args.shellPath,
|
|
739
|
+
TMPDIR: '/tmp',
|
|
740
|
+
...args.environment,
|
|
741
|
+
PWD: args.pwd,
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
function translateRootManifestCommandInput(command, workspaceRootPath) {
|
|
745
|
+
return command.replace(/(^|[\s"'=<>])\/([^\s"'|&;<>(){}]*)/g, (_match, prefix, pathSuffix) => `${prefix}${workspaceRootPath}/${pathSuffix}`);
|
|
746
|
+
}
|
|
747
|
+
function translateManifestRootCommandInput(command, manifestRoot, workspaceRootPath) {
|
|
748
|
+
const escapedManifestRoot = escapeRegExp(manifestRoot);
|
|
749
|
+
const pathPrefix = String.raw `(^|[\s"'=<>])`;
|
|
750
|
+
const pathSuffix = String.raw `(?=$|[\/\s"'|&;<>(){}])`;
|
|
751
|
+
return command.replace(new RegExp(`${pathPrefix}${escapedManifestRoot}${pathSuffix}`, 'g'), (_match, prefix) => `${prefix}${workspaceRootPath}`);
|
|
752
|
+
}
|
|
753
|
+
function translateRootManifestCommandOutput(output, workspaceRootPath) {
|
|
754
|
+
return translateWorkspaceRootCommandOutput(output, '/', workspaceRootPath);
|
|
755
|
+
}
|
|
756
|
+
function translateManifestRootCommandOutput(output, manifestRoot, workspaceRootPath) {
|
|
757
|
+
return translateWorkspaceRootCommandOutput(output, manifestRoot, workspaceRootPath);
|
|
758
|
+
}
|
|
759
|
+
function translateWorkspaceRootCommandOutput(output, manifestRoot, workspaceRootPath) {
|
|
760
|
+
const nestedPathReplacement = manifestRoot === '/' ? '/' : `${manifestRoot}/`;
|
|
761
|
+
let translated = output;
|
|
762
|
+
for (const path of workspaceRootOutputPaths(workspaceRootPath)) {
|
|
763
|
+
translated = translated
|
|
764
|
+
.split(`${path}/`)
|
|
765
|
+
.join(nestedPathReplacement)
|
|
766
|
+
.split(path)
|
|
767
|
+
.join(manifestRoot);
|
|
768
|
+
}
|
|
769
|
+
return translated;
|
|
770
|
+
}
|
|
771
|
+
function workspaceRootOutputPaths(workspaceRootPath) {
|
|
772
|
+
const paths = [workspaceRootPath];
|
|
773
|
+
try {
|
|
774
|
+
paths.push(realpathSync(workspaceRootPath));
|
|
775
|
+
}
|
|
776
|
+
catch {
|
|
777
|
+
return paths;
|
|
778
|
+
}
|
|
779
|
+
return Array.from(new Set(paths)).sort((a, b) => b.length - a.length);
|
|
780
|
+
}
|
|
781
|
+
function escapeRegExp(value) {
|
|
782
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
783
|
+
}
|
|
784
|
+
function appendActiveProcessOutput(activeProcess, chunk, stream) {
|
|
785
|
+
if (chunk.length === 0) {
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
788
|
+
const combined = appendBoundedOutput(activeProcess.output, activeProcess.droppedOutputChars, chunk);
|
|
789
|
+
activeProcess.output = combined.output;
|
|
790
|
+
activeProcess.droppedOutputChars = combined.droppedChars;
|
|
791
|
+
if (stream === 'stdout') {
|
|
792
|
+
const stdout = appendBoundedOutput(activeProcess.stdout, activeProcess.droppedStdoutChars, chunk);
|
|
793
|
+
activeProcess.stdout = stdout.output;
|
|
794
|
+
activeProcess.droppedStdoutChars = stdout.droppedChars;
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
const stderr = appendBoundedOutput(activeProcess.stderr, activeProcess.droppedStderrChars, chunk);
|
|
798
|
+
activeProcess.stderr = stderr.output;
|
|
799
|
+
activeProcess.droppedStderrChars = stderr.droppedChars;
|
|
800
|
+
}
|
|
801
|
+
function appendBoundedOutput(output, droppedChars, chunk) {
|
|
802
|
+
const nextLength = output.length + chunk.length;
|
|
803
|
+
if (nextLength <= MAX_ACTIVE_PROCESS_OUTPUT_CHARS) {
|
|
804
|
+
return {
|
|
805
|
+
output: output + chunk,
|
|
806
|
+
droppedChars,
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
const nextDroppedChars = droppedChars + nextLength - MAX_ACTIVE_PROCESS_OUTPUT_CHARS;
|
|
810
|
+
if (chunk.length >= MAX_ACTIVE_PROCESS_OUTPUT_CHARS) {
|
|
811
|
+
return {
|
|
812
|
+
output: chunk.slice(-MAX_ACTIVE_PROCESS_OUTPUT_CHARS),
|
|
813
|
+
droppedChars: nextDroppedChars,
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
const existingCharsToKeep = MAX_ACTIVE_PROCESS_OUTPUT_CHARS - chunk.length;
|
|
817
|
+
return {
|
|
818
|
+
output: output.slice(-existingCharsToKeep) + chunk,
|
|
819
|
+
droppedChars: nextDroppedChars,
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
function consumeActiveProcessOutput(activeProcess) {
|
|
823
|
+
const output = withDroppedOutputPrefix(activeProcess.output, activeProcess.droppedOutputChars);
|
|
824
|
+
const stdout = withDroppedOutputPrefix(activeProcess.stdout, activeProcess.droppedStdoutChars);
|
|
825
|
+
const stderr = withDroppedOutputPrefix(activeProcess.stderr, activeProcess.droppedStderrChars);
|
|
826
|
+
activeProcess.output = '';
|
|
827
|
+
activeProcess.stdout = '';
|
|
828
|
+
activeProcess.stderr = '';
|
|
829
|
+
activeProcess.droppedOutputChars = 0;
|
|
830
|
+
activeProcess.droppedStdoutChars = 0;
|
|
831
|
+
activeProcess.droppedStderrChars = 0;
|
|
832
|
+
return { output, stdout, stderr };
|
|
833
|
+
}
|
|
834
|
+
function withDroppedOutputPrefix(output, droppedChars) {
|
|
835
|
+
if (droppedChars === 0) {
|
|
836
|
+
return output;
|
|
837
|
+
}
|
|
838
|
+
return `[...${droppedChars} characters truncated from process output...]\n${output}`;
|
|
839
|
+
}
|
|
840
|
+
async function waitForProcessOrTimeout(activeProcess, timeoutMs) {
|
|
841
|
+
if (activeProcess.done) {
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
await Promise.race([
|
|
845
|
+
activeProcess.donePromise,
|
|
846
|
+
new Promise((resolve) => setTimeout(resolve, timeoutMs)),
|
|
847
|
+
]);
|
|
848
|
+
if (activeProcess.done) {
|
|
849
|
+
await activeProcess.outputClosedPromise;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
function signalToExitCode(signal) {
|
|
853
|
+
if (signal === 'SIGINT') {
|
|
854
|
+
return 130;
|
|
855
|
+
}
|
|
856
|
+
return 1;
|
|
857
|
+
}
|
|
858
|
+
//# sourceMappingURL=unixLocal.mjs.map
|