nova-personal-agent-server 0.0.0-stage → 0.4.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/LICENSE +201 -0
- package/README.md +30 -2
- package/bin/novapersonal-server.mjs +4 -0
- package/package.json +61 -4
- package/resources/endpointing/volcengine-v1/LICENSE.silero-vad.txt +21 -0
- package/resources/endpointing/volcengine-v1/MANIFEST.json +31 -0
- package/resources/endpointing/volcengine-v1/silence-16k-s16le.pcm +0 -0
- package/resources/endpointing/volcengine-v1/speech-16k-s16le.pcm +0 -0
- package/resources/native/codex-sandbox-probe +0 -0
- package/resources/native/project-native/nova_project_native.node +0 -0
- package/resources/native-resources-v1.json +1 -0
- package/runtime/dist/eval/demos.js +156 -0
- package/runtime/dist/eval/fixture-host.js +385 -0
- package/runtime/dist/eval/fixtures.js +319 -0
- package/runtime/dist/eval/realtime/session-fixtures.js +474 -0
- package/runtime/dist/eval/scorecard.js +285 -0
- package/runtime/dist/eval/sim.js +43 -0
- package/runtime/dist/src/cascaded-text-provider.js +31 -0
- package/runtime/dist/src/cli.js +96 -0
- package/runtime/dist/src/composition/assembly.js +352 -0
- package/runtime/dist/src/composition/cascaded-realtime-assembly.js +455 -0
- package/runtime/dist/src/composition/production-composition.js +389 -0
- package/runtime/dist/src/composition/realtime-assembly.js +1330 -0
- package/runtime/dist/src/config/capability-registry.js +315 -0
- package/runtime/dist/src/config/cascaded-realtime-config.js +146 -0
- package/runtime/dist/src/config/coding-backends.js +8 -0
- package/runtime/dist/src/config/coding-profiles.js +98 -0
- package/runtime/dist/src/config/config.js +857 -0
- package/runtime/dist/src/config/diagnostics.js +139 -0
- package/runtime/dist/src/config/environment-contract.js +202 -0
- package/runtime/dist/src/config/self-hosted.js +23 -0
- package/runtime/dist/src/connectors/composio/client.js +195 -0
- package/runtime/dist/src/connectors/composio/google.js +208 -0
- package/runtime/dist/src/connectors/composio/index.js +334 -0
- package/runtime/dist/src/connectors/feishu/cli.js +220 -0
- package/runtime/dist/src/connectors/feishu/index.js +980 -0
- package/runtime/dist/src/connectors/macos/calendar.js +35 -0
- package/runtime/dist/src/connectors/macos/mail.js +32 -0
- package/runtime/dist/src/connectors/macos/reader.js +62 -0
- package/runtime/dist/src/conversation-voice-provider.js +41 -0
- package/runtime/dist/src/core/approval-port.js +9 -0
- package/runtime/dist/src/core/approval.js +1328 -0
- package/runtime/dist/src/core/calls.js +35 -0
- package/runtime/dist/src/core/camera-session.js +32 -0
- package/runtime/dist/src/core/causal-runtime.js +650 -0
- package/runtime/dist/src/core/clock.js +139 -0
- package/runtime/dist/src/core/context-view.js +156 -0
- package/runtime/dist/src/core/effects.js +62 -0
- package/runtime/dist/src/core/events.js +217 -0
- package/runtime/dist/src/core/executor-diagnostic.js +9 -0
- package/runtime/dist/src/core/ids.js +32 -0
- package/runtime/dist/src/core/media-store.js +104 -0
- package/runtime/dist/src/core/memory.js +296 -0
- package/runtime/dist/src/core/pending-decision.js +64 -0
- package/runtime/dist/src/core/ports.js +125 -0
- package/runtime/dist/src/core/runtime.js +1459 -0
- package/runtime/dist/src/core/schedule-tools.js +15 -0
- package/runtime/dist/src/core/sims.js +186 -0
- package/runtime/dist/src/core/slots.js +97 -0
- package/runtime/dist/src/core/source-processing-instructions.js +3 -0
- package/runtime/dist/src/core/source-processing-tools.js +12 -0
- package/runtime/dist/src/core/suggestions.js +143 -0
- package/runtime/dist/src/core/task-tools.js +22 -0
- package/runtime/dist/src/core/tool-schema.js +212 -0
- package/runtime/dist/src/core/trace.js +34 -0
- package/runtime/dist/src/core/work-tools.js +94 -0
- package/runtime/dist/src/desktop/desktop-camera-source.js +31 -0
- package/runtime/dist/src/desktop/desktop-camera.js +281 -0
- package/runtime/dist/src/desktop/desktop-control.js +140 -0
- package/runtime/dist/src/desktop/desktop-progress.js +162 -0
- package/runtime/dist/src/desktop/desktop-session.js +2106 -0
- package/runtime/dist/src/desktop/desktop-tasks.js +80 -0
- package/runtime/dist/src/desktop/desktop-wire.js +605 -0
- package/runtime/dist/src/desktop/phone-desktop-entry.js +17 -0
- package/runtime/dist/src/desktop/startup-error.js +18 -0
- package/runtime/dist/src/desktop/workbench-acceptance.js +262 -0
- package/runtime/dist/src/desktop-entry.js +106 -0
- package/runtime/dist/src/desktop.js +1092 -0
- package/runtime/dist/src/executors/acp/backends.js +105 -0
- package/runtime/dist/src/executors/acp/mcp.js +81 -0
- package/runtime/dist/src/executors/acp/preflight.js +14 -0
- package/runtime/dist/src/executors/acp/process-owner.js +112 -0
- package/runtime/dist/src/executors/acp/transport.js +760 -0
- package/runtime/dist/src/executors/acp/windows-launch.js +68 -0
- package/runtime/dist/src/executors/agent-controller.js +244 -0
- package/runtime/dist/src/executors/autoglm.js +376 -0
- package/runtime/dist/src/executors/browser-device.js +102 -0
- package/runtime/dist/src/executors/browser.js +61 -0
- package/runtime/dist/src/executors/camera.js +101 -0
- package/runtime/dist/src/executors/chromium-frame-source.js +173 -0
- package/runtime/dist/src/executors/codex/adapter-live.js +292 -0
- package/runtime/dist/src/executors/codex/adapter-project.js +1306 -0
- package/runtime/dist/src/executors/codex/app-server-schema.js +712 -0
- package/runtime/dist/src/executors/codex/app-server-transport.js +1798 -0
- package/runtime/dist/src/executors/codex/approval-protocol.js +439 -0
- package/runtime/dist/src/executors/codex/common.js +655 -0
- package/runtime/dist/src/executors/codex/contract.js +581 -0
- package/runtime/dist/src/executors/codex/controller.js +141 -0
- package/runtime/dist/src/executors/codex/credential-snapshot.js +195 -0
- package/runtime/dist/src/executors/codex/factory.js +463 -0
- package/runtime/dist/src/executors/codex/host-config.js +238 -0
- package/runtime/dist/src/executors/codex/host.js +17 -0
- package/runtime/dist/src/executors/codex/index.js +19 -0
- package/runtime/dist/src/executors/codex/launch-profile.js +37 -0
- package/runtime/dist/src/executors/codex/local-sessions.js +119 -0
- package/runtime/dist/src/executors/codex/managed-mcp.js +196 -0
- package/runtime/dist/src/executors/codex/process-owner.js +398 -0
- package/runtime/dist/src/executors/codex/production-host.js +887 -0
- package/runtime/dist/src/executors/codex/progress-instructions.js +10 -0
- package/runtime/dist/src/executors/codex/protocol.js +581 -0
- package/runtime/dist/src/executors/codex/safe-json.js +87 -0
- package/runtime/dist/src/executors/codex/session-title.js +61 -0
- package/runtime/dist/src/executors/codex/shared-home.js +29 -0
- package/runtime/dist/src/executors/codex/spawn-env.js +162 -0
- package/runtime/dist/src/executors/codex/turn-projection.js +435 -0
- package/runtime/dist/src/executors/codex/version.js +38 -0
- package/runtime/dist/src/executors/codex/windows-guardian.js +716 -0
- package/runtime/dist/src/executors/coding/intake-model.js +103 -0
- package/runtime/dist/src/executors/coding/intake.js +824 -0
- package/runtime/dist/src/executors/coding/json-completion.js +14 -0
- package/runtime/dist/src/executors/coding/target-resolution.js +61 -0
- package/runtime/dist/src/executors/coding/work-order.js +50 -0
- package/runtime/dist/src/executors/coding-executor.js +23 -0
- package/runtime/dist/src/executors/computer-backend.js +188 -0
- package/runtime/dist/src/executors/computer-device.js +187 -0
- package/runtime/dist/src/executors/computer-worker.js +125 -0
- package/runtime/dist/src/executors/computer.js +100 -0
- package/runtime/dist/src/executors/device-lock.js +127 -0
- package/runtime/dist/src/executors/frame-source.js +29 -0
- package/runtime/dist/src/executors/gui-evidence.js +30 -0
- package/runtime/dist/src/executors/gui-execution.js +237 -0
- package/runtime/dist/src/executors/gui-runner.js +88 -0
- package/runtime/dist/src/executors/host-executor-capability.js +12 -0
- package/runtime/dist/src/executors/index.js +13 -0
- package/runtime/dist/src/executors/mcp-client.js +198 -0
- package/runtime/dist/src/executors/mcp.js +210 -0
- package/runtime/dist/src/executors/mobile-android.js +180 -0
- package/runtime/dist/src/executors/mobile-ios.js +303 -0
- package/runtime/dist/src/executors/mobile.js +78 -0
- package/runtime/dist/src/executors/search-mcp.js +146 -0
- package/runtime/dist/src/executors/search.js +524 -0
- package/runtime/dist/src/executors/task-resources.js +38 -0
- package/runtime/dist/src/executors/vision/assess.js +296 -0
- package/runtime/dist/src/executors/vision/controller-core.js +373 -0
- package/runtime/dist/src/executors/vision/controller.js +164 -0
- package/runtime/dist/src/executors/vision/lifecycle.js +69 -0
- package/runtime/dist/src/executors/vision.js +5 -0
- package/runtime/dist/src/executors/watcher.js +718 -0
- package/runtime/dist/src/http/bounded-response.js +37 -0
- package/runtime/dist/src/index.js +56 -0
- package/runtime/dist/src/knowledge/assembly.js +60 -0
- package/runtime/dist/src/knowledge/documents.js +520 -0
- package/runtime/dist/src/knowledge/embeddings.js +201 -0
- package/runtime/dist/src/knowledge/mcp.js +218 -0
- package/runtime/dist/src/knowledge/parse-worker.js +122 -0
- package/runtime/dist/src/knowledge/references.js +51 -0
- package/runtime/dist/src/knowledge/service.js +526 -0
- package/runtime/dist/src/knowledge/store-client.js +185 -0
- package/runtime/dist/src/knowledge/store-worker.js +843 -0
- package/runtime/dist/src/knowledge/types.js +2 -0
- package/runtime/dist/src/mcp/http-server.js +177 -0
- package/runtime/dist/src/mem0/resource.js +35 -0
- package/runtime/dist/src/mem0/store-worker.js +330 -0
- package/runtime/dist/src/memory/blackboard-session.js +205 -0
- package/runtime/dist/src/memory/blackboard-store.js +194 -0
- package/runtime/dist/src/memory/blackboard-worker.js +369 -0
- package/runtime/dist/src/memory/entry.js +39 -0
- package/runtime/dist/src/memory/factory.js +20 -0
- package/runtime/dist/src/memory/personal-memory-inspection.js +18 -0
- package/runtime/dist/src/memory/personal-memory.js +10 -0
- package/runtime/dist/src/memory/prerecall.js +20 -0
- package/runtime/dist/src/memory/provenance.js +17 -0
- package/runtime/dist/src/memory/remote-personal-memory.js +194 -0
- package/runtime/dist/src/memory/retrieval.js +235 -0
- package/runtime/dist/src/memory/sensitivity.js +261 -0
- package/runtime/dist/src/memory-ledger/models.js +98 -0
- package/runtime/dist/src/memory-ledger/store-client.js +210 -0
- package/runtime/dist/src/memory-ledger/store-worker.js +130 -0
- package/runtime/dist/src/memory-ledger/store.js +597 -0
- package/runtime/dist/src/memory-substrate/candidates.js +16 -0
- package/runtime/dist/src/memory-substrate/consolidation.js +124 -0
- package/runtime/dist/src/memory-substrate/file-authority.js +111 -0
- package/runtime/dist/src/memory-substrate/life-operations.js +280 -0
- package/runtime/dist/src/memory-substrate/markdown-repository.js +610 -0
- package/runtime/dist/src/memory-substrate/migration.js +87 -0
- package/runtime/dist/src/memory-substrate/profile-source-input.js +9 -0
- package/runtime/dist/src/memory-substrate/purge.js +398 -0
- package/runtime/dist/src/memory-substrate/resolution.js +32 -0
- package/runtime/dist/src/memory-substrate/resource.js +867 -0
- package/runtime/dist/src/memory-substrate/retrieval.js +85 -0
- package/runtime/dist/src/memory-substrate/source-operations.js +306 -0
- package/runtime/dist/src/memory-substrate/source-processing.js +326 -0
- package/runtime/dist/src/memory-substrate/source-state.js +93 -0
- package/runtime/dist/src/memory-substrate/store.js +534 -0
- package/runtime/dist/src/memory-substrate/workspace-projections.js +106 -0
- package/runtime/dist/src/memory-substrate/workspace.js +21 -0
- package/runtime/dist/src/model/jev-client.js +25 -0
- package/runtime/dist/src/model/model-adapters.js +64 -0
- package/runtime/dist/src/model/model-gateway.js +399 -0
- package/runtime/dist/src/model/model-lane.js +34 -0
- package/runtime/dist/src/model/model-purpose.js +5 -0
- package/runtime/dist/src/model/personal-writer.js +361 -0
- package/runtime/dist/src/model/proactivity.js +72 -0
- package/runtime/dist/src/model/prompting.js +279 -0
- package/runtime/dist/src/model/task-verifier.js +217 -0
- package/runtime/dist/src/model/vision-capability.js +10 -0
- package/runtime/dist/src/news/feeds.js +114 -0
- package/runtime/dist/src/news/jev-ranking.js +25 -0
- package/runtime/dist/src/news/ranking.js +26 -0
- package/runtime/dist/src/news/service.js +262 -0
- package/runtime/dist/src/notifications/adapters/feishu.js +10 -0
- package/runtime/dist/src/notifications/adapters/nova.js +15 -0
- package/runtime/dist/src/notifications/content.js +15 -0
- package/runtime/dist/src/notifications/contracts.js +9 -0
- package/runtime/dist/src/notifications/feed.js +8 -0
- package/runtime/dist/src/notifications/service.js +412 -0
- package/runtime/dist/src/notifications/store.js +4 -0
- package/runtime/dist/src/personal-agent/app-context.js +113 -0
- package/runtime/dist/src/personal-agent/approval-scope.js +8 -0
- package/runtime/dist/src/personal-agent/coding-targets.js +82 -0
- package/runtime/dist/src/personal-agent/context-candidates.js +94 -0
- package/runtime/dist/src/personal-agent/contracts.js +32 -0
- package/runtime/dist/src/personal-agent/conversation-runtime.js +536 -0
- package/runtime/dist/src/personal-agent/conversations.js +187 -0
- package/runtime/dist/src/personal-agent/daily-brief.js +53 -0
- package/runtime/dist/src/personal-agent/host.js +2403 -0
- package/runtime/dist/src/personal-agent/intake-task.js +37 -0
- package/runtime/dist/src/personal-agent/life.js +260 -0
- package/runtime/dist/src/personal-agent/memory-overview.js +19 -0
- package/runtime/dist/src/personal-agent/profile-sources.js +34 -0
- package/runtime/dist/src/personal-agent/profile-warmup.js +244 -0
- package/runtime/dist/src/personal-agent/project-digests.js +242 -0
- package/runtime/dist/src/personal-agent/sampling.js +20 -0
- package/runtime/dist/src/personal-agent/schedule-agent.js +60 -0
- package/runtime/dist/src/personal-agent/schedule-api.js +61 -0
- package/runtime/dist/src/personal-agent/schedule-presets.js +13 -0
- package/runtime/dist/src/personal-agent/schedule-reference.js +3 -0
- package/runtime/dist/src/personal-agent/scheduled-response-scope.js +38 -0
- package/runtime/dist/src/personal-agent/scheduled-run-authority.js +44 -0
- package/runtime/dist/src/personal-agent/scheduled-tasks.js +280 -0
- package/runtime/dist/src/personal-agent/scheduled-time.js +99 -0
- package/runtime/dist/src/personal-agent/scheduled-tool-runtime.js +109 -0
- package/runtime/dist/src/personal-agent/source-priority.js +142 -0
- package/runtime/dist/src/personal-agent/source-processing-agent.js +158 -0
- package/runtime/dist/src/personal-agent/source-walk.js +25 -0
- package/runtime/dist/src/personal-agent/sources.js +1484 -0
- package/runtime/dist/src/personal-agent/store-lock-worker.js +17 -0
- package/runtime/dist/src/personal-agent/store.js +146 -0
- package/runtime/dist/src/personal-agent/task-loop.js +163 -0
- package/runtime/dist/src/personal-agent/tasks.js +920 -0
- package/runtime/dist/src/personal-agent/turn-deadline.js +55 -0
- package/runtime/dist/src/personal-agent/understanding.js +160 -0
- package/runtime/dist/src/personal-agent/workbench-context.js +239 -0
- package/runtime/dist/src/projects/confirmed-project-capability.js +60 -0
- package/runtime/dist/src/projects/host-paths.js +133 -0
- package/runtime/dist/src/projects/managed-workspace-maintenance.js +351 -0
- package/runtime/dist/src/projects/project-confirmation.js +486 -0
- package/runtime/dist/src/projects/project-native-resource.js +284 -0
- package/runtime/dist/src/projects/project-node-files.js +169 -0
- package/runtime/dist/src/projects/project-root-file.js +16 -0
- package/runtime/dist/src/projects/project-state.js +504 -0
- package/runtime/dist/src/projects/project-store-files.js +1271 -0
- package/runtime/dist/src/projects/project-store.js +1345 -0
- package/runtime/dist/src/realtime/aoq.js +141 -0
- package/runtime/dist/src/realtime/bridge.js +652 -0
- package/runtime/dist/src/realtime/cascaded/adapter.js +1669 -0
- package/runtime/dist/src/realtime/cascaded/ark-llm.js +219 -0
- package/runtime/dist/src/realtime/cascaded/chat-completions-llm.js +478 -0
- package/runtime/dist/src/realtime/cascaded/gemini-speech.js +232 -0
- package/runtime/dist/src/realtime/cascaded/llm.js +37 -0
- package/runtime/dist/src/realtime/cascaded/ports.js +2 -0
- package/runtime/dist/src/realtime/cascaded/provider.js +216 -0
- package/runtime/dist/src/realtime/cascaded/qwen-llm.js +7 -0
- package/runtime/dist/src/realtime/cascaded/self-hosted-asr.js +110 -0
- package/runtime/dist/src/realtime/cascaded/self-hosted-tts.js +137 -0
- package/runtime/dist/src/realtime/cascaded/transcribe.js +42 -0
- package/runtime/dist/src/realtime/coding-progress-narration.js +28 -0
- package/runtime/dist/src/realtime/confirmation-turn-isolation.js +586 -0
- package/runtime/dist/src/realtime/dictation.js +28 -0
- package/runtime/dist/src/realtime/evidence.js +276 -0
- package/runtime/dist/src/realtime/floor.js +43 -0
- package/runtime/dist/src/realtime/frontend-instructions.js +195 -0
- package/runtime/dist/src/realtime/gemini.js +517 -0
- package/runtime/dist/src/realtime/history.js +122 -0
- package/runtime/dist/src/realtime/host-delivery.js +1711 -0
- package/runtime/dist/src/realtime/integrated-wire-profile.js +128 -0
- package/runtime/dist/src/realtime/memory-board.js +105 -0
- package/runtime/dist/src/realtime/openai-wire-profile.js +46 -0
- package/runtime/dist/src/realtime/playback.js +242 -0
- package/runtime/dist/src/realtime/project-confirmation-flow.js +1428 -0
- package/runtime/dist/src/realtime/prompt-language.js +17 -0
- package/runtime/dist/src/realtime/protocol.js +428 -0
- package/runtime/dist/src/realtime/provider-projection.js +526 -0
- package/runtime/dist/src/realtime/provider-session.js +491 -0
- package/runtime/dist/src/realtime/qwen-transport.js +144 -0
- package/runtime/dist/src/realtime/qwen.js +1377 -0
- package/runtime/dist/src/realtime/recall.js +341 -0
- package/runtime/dist/src/realtime/service-ports.js +8 -0
- package/runtime/dist/src/realtime/service-state.js +259 -0
- package/runtime/dist/src/realtime/service.js +1726 -0
- package/runtime/dist/src/realtime/session-state.js +684 -0
- package/runtime/dist/src/realtime/session.js +1976 -0
- package/runtime/dist/src/realtime/speech-prep.js +63 -0
- package/runtime/dist/src/realtime/streaming-speech.js +120 -0
- package/runtime/dist/src/realtime/system-prompts.en.js +136 -0
- package/runtime/dist/src/realtime/telemetry.js +144 -0
- package/runtime/dist/src/realtime/tool-continuations.js +1510 -0
- package/runtime/dist/src/realtime/transport.js +8 -0
- package/runtime/dist/src/realtime/usage.js +55 -0
- package/runtime/dist/src/realtime/user-origin-binding.js +173 -0
- package/runtime/dist/src/realtime/volcengine/ark.js +428 -0
- package/runtime/dist/src/realtime/volcengine/asr.js +573 -0
- package/runtime/dist/src/realtime/volcengine/audio.js +39 -0
- package/runtime/dist/src/realtime/volcengine/endpointing-capability.js +834 -0
- package/runtime/dist/src/realtime/volcengine/livekit-endpointing.js +714 -0
- package/runtime/dist/src/realtime/volcengine/local-eot-executor.js +33 -0
- package/runtime/dist/src/realtime/volcengine/protocol.js +247 -0
- package/runtime/dist/src/realtime/volcengine/silence-endpointing.js +237 -0
- package/runtime/dist/src/realtime/volcengine/tts.js +444 -0
- package/runtime/dist/src/realtime/volcengine/websocket.js +293 -0
- package/runtime/dist/src/server/aoq-chat-server.js +497 -0
- package/runtime/dist/src/server/client-pairing.js +192 -0
- package/runtime/dist/src/server/client-protocol.js +87 -0
- package/runtime/dist/src/server/client-server.js +312 -0
- package/runtime/dist/src/server/server-config.js +72 -0
- package/runtime/dist/src/server-entry.js +135 -0
- package/runtime/dist/src/storage/bounded-json.js +63 -0
- package/runtime/dist/src/storage/native-file-lock.js +8 -0
- package/runtime/dist/src/storage/native-resource-snapshot.js +41 -0
- package/runtime/dist/src/storage/private-database.js +120 -0
- package/runtime/dist/src/text/canonical-json.js +60 -0
- package/runtime/dist/src/text/python-number.js +18 -0
- package/runtime/dist/src/text/python-text.js +92 -0
- package/runtime/dist/src/text/unicode-casefold.js +29 -0
- package/runtime/dist/src/text/unicode-normalize.js +138 -0
- package/runtime/dist/src/text/unicode-tables.js +210 -0
- package/runtime/dist/src/understanding/candidates.js +77 -0
- package/runtime/dist/src/understanding/fixture.js +7 -0
- package/runtime/dist/src/understanding/jev.js +20 -0
- package/runtime/dist/src/understanding/pipeline.js +38 -0
- package/runtime/dist/src/voicemem/store-client.js +476 -0
- package/runtime/dist/src/voicemem/store-worker.js +380 -0
- package/runtime/dist/src/voicemem/versioned-memory.js +170 -0
- package/runtime/scripts/pair-device.mjs +109 -0
- package/src/command.mjs +48 -0
|
@@ -0,0 +1,887 @@
|
|
|
1
|
+
import { snapshotRegularFile, sameSnapshot } from '../../storage/native-resource-snapshot.js';
|
|
2
|
+
import { hostCodexHomeValue } from './process-owner.js';
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
5
|
+
import { accessSync, constants, chmodSync, lstatSync, mkdtempSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync, } from 'node:fs';
|
|
6
|
+
import { createServer } from 'node:net';
|
|
7
|
+
import { dirname, isAbsolute, join, resolve, sep } from 'node:path';
|
|
8
|
+
import { homedir, tmpdir } from 'node:os';
|
|
9
|
+
import { CodexTransportError, } from './app-server-transport.js';
|
|
10
|
+
import { APP_SERVER_APPROVAL_SCHEMA_FILES, APP_SERVER_INBOUND_SCHEMAS, APP_SERVER_METHOD_SCHEMAS, } from './app-server-schema.js';
|
|
11
|
+
import { hostBinaryPath, hostWorkspacePath } from './process-owner.js';
|
|
12
|
+
import { createPlatformCodexProcessOwnerFactory, hostEphemeralCodexHomeFromConfig, } from './process-owner.js';
|
|
13
|
+
import { loadWindowsGuardianFactoryFromResources } from './windows-guardian.js';
|
|
14
|
+
import { OwnedCodexBackendTransportFactory, unavailableCodexBackendTransportFactory, } from './factory.js';
|
|
15
|
+
import { CredentialSnapshotter, environmentValue, } from './credential-snapshot.js';
|
|
16
|
+
import { expandUserPath } from './host-config.js';
|
|
17
|
+
import { loadProjectNativeHostFromResources, protectDefaultProjectDirectories, } from '../../projects/project-native-resource.js';
|
|
18
|
+
import { stripLikePython } from '../../text/python-text.js';
|
|
19
|
+
import { admitCodexCliVersion } from './version.js';
|
|
20
|
+
const PROBE_ID = 'codex_sandbox_probe';
|
|
21
|
+
const PROBE_PATH = 'native/codex-sandbox-probe';
|
|
22
|
+
const PROBE_PATH_WINDOWS = 'native/codex-sandbox-probe.exe';
|
|
23
|
+
const MAX_MANIFEST_BYTES = 1024 * 1024;
|
|
24
|
+
const MAX_PROBE_BYTES = 4 * 1024 * 1024;
|
|
25
|
+
const MAX_COMMAND_STDOUT = 8192;
|
|
26
|
+
const MAX_COMMAND_STDERR = 64 * 1024;
|
|
27
|
+
const MAX_SCHEMA_BYTES = 1024 * 1024;
|
|
28
|
+
const PERMISSION_PROFILE = '{ filesystem = { ":root" = "read", ":workspace_roots" = { "." = "write", ".git" = "read", ".agents" = "read", ".codex" = "read" } }, network = { enabled = false } }';
|
|
29
|
+
const ENVIRONMENT_ALLOWLIST = new Set([
|
|
30
|
+
'PATH', 'HOME', 'CODEX_HOME', 'LANG', 'LC_ALL', 'TERM', 'SSL_CERT_FILE', 'SSL_CERT_DIR',
|
|
31
|
+
'REQUESTS_CA_BUNDLE', 'CURL_CA_BUNDLE',
|
|
32
|
+
]);
|
|
33
|
+
const PROBE_BOOLEAN_FIELDS = Object.freeze([
|
|
34
|
+
'cwd_matches', 'inside_write', 'inside_remove', 'outside_write_denied',
|
|
35
|
+
'child_outside_write_denied', 'network_denied',
|
|
36
|
+
]);
|
|
37
|
+
const LIMIT_NAMES = Object.freeze(['cpu', 'as', 'nofile']);
|
|
38
|
+
const LIMIT_CLASSES = new Set(['finite', 'unbounded', 'unavailable']);
|
|
39
|
+
const sandboxProbeBrand = Symbol('ManifestBoundCodexSandboxProbe');
|
|
40
|
+
const sandboxProbeValues = new WeakMap();
|
|
41
|
+
/** Build the one host-owned Codex catalog/resource graph used by the desktop entry. */
|
|
42
|
+
export function createProductionCodexHost(settings, options = {}) {
|
|
43
|
+
const environment = options.environment ?? process.env;
|
|
44
|
+
const platform = options.platform ?? process.platform;
|
|
45
|
+
const arch = options.arch ?? process.arch;
|
|
46
|
+
const homeDirectory = canonicalDirectory(options.homeDirectory ?? homedir());
|
|
47
|
+
const workspace = homeDirectory === null
|
|
48
|
+
? null
|
|
49
|
+
: canonicalDirectory(expandUserPath(settings.codex_workspace ?? '', homeDirectory));
|
|
50
|
+
const configuredBinary = stripLikePython(settings.codex_bin);
|
|
51
|
+
const binary = configuredBinary === 'codex' ? null : canonicalRegularExecutable(configuredBinary);
|
|
52
|
+
const catalog = Object.freeze({
|
|
53
|
+
canonicalBinaries: Object.freeze(binary === null ? [] : [binary]),
|
|
54
|
+
canonicalWorkspaces: Object.freeze(workspace === null ? [] : [workspace]),
|
|
55
|
+
defaultBinary: null,
|
|
56
|
+
homeDirectory: homeDirectory ?? resolve(options.homeDirectory ?? homedir()),
|
|
57
|
+
});
|
|
58
|
+
const resourcesPath = options.resourcesPath ?? packagedResourcesPath();
|
|
59
|
+
if (resourcesPath === null
|
|
60
|
+
|| workspace === null
|
|
61
|
+
|| binary === null
|
|
62
|
+
|| homeDirectory === null)
|
|
63
|
+
return Object.freeze({
|
|
64
|
+
catalog,
|
|
65
|
+
transportFactory: unavailableCodexBackendTransportFactory,
|
|
66
|
+
projectHost: null,
|
|
67
|
+
});
|
|
68
|
+
const hostEnvironment = (platform === 'win32'
|
|
69
|
+
|| typeof environment.HOME === 'string' && environment.HOME !== ''
|
|
70
|
+
? environment
|
|
71
|
+
: Object.freeze({ ...environment, HOME: homeDirectory }));
|
|
72
|
+
const probe = loadCodexSandboxProbeFromResources({ resourcesPath, platform, arch });
|
|
73
|
+
if (probe === null)
|
|
74
|
+
return Object.freeze({
|
|
75
|
+
catalog,
|
|
76
|
+
transportFactory: unavailableCodexBackendTransportFactory,
|
|
77
|
+
projectHost: null,
|
|
78
|
+
});
|
|
79
|
+
const windowsGuardianFactory = platform === 'win32'
|
|
80
|
+
? loadWindowsGuardianFactoryFromResources({ resourcesPath, platform, arch })
|
|
81
|
+
: null;
|
|
82
|
+
if (platform === 'win32' && windowsGuardianFactory === null)
|
|
83
|
+
return Object.freeze({
|
|
84
|
+
catalog,
|
|
85
|
+
transportFactory: unavailableCodexBackendTransportFactory,
|
|
86
|
+
projectHost: null,
|
|
87
|
+
});
|
|
88
|
+
let projectHost = loadProjectNativeHostFromResources({
|
|
89
|
+
resourcesPath,
|
|
90
|
+
platform,
|
|
91
|
+
arch,
|
|
92
|
+
electronAbi: options.electronAbi ?? process.versions.modules,
|
|
93
|
+
});
|
|
94
|
+
if (projectHost !== null && !protectDefaultProjectDirectories(projectHost, {
|
|
95
|
+
homeDirectory,
|
|
96
|
+
stateRoot: canonicalDirectory(stripLikePython(settings.codex_project_state_root)),
|
|
97
|
+
managedRoot: canonicalDirectory(stripLikePython(settings.codex_managed_root)),
|
|
98
|
+
workspace,
|
|
99
|
+
}))
|
|
100
|
+
projectHost = null;
|
|
101
|
+
const temporaryDirectory = options.temporaryDirectory === undefined
|
|
102
|
+
? canonicalSystemTemporaryDirectoryForTest(tmpdir())
|
|
103
|
+
: canonicalDirectory(options.temporaryDirectory);
|
|
104
|
+
if (temporaryDirectory === null)
|
|
105
|
+
return Object.freeze({
|
|
106
|
+
catalog,
|
|
107
|
+
transportFactory: unavailableCodexBackendTransportFactory,
|
|
108
|
+
projectHost,
|
|
109
|
+
});
|
|
110
|
+
const credentialSnapshotter = new CredentialSnapshotter({
|
|
111
|
+
environment: hostEnvironment,
|
|
112
|
+
platform,
|
|
113
|
+
...(options.onDiagnostic === undefined ? {} : { onDiagnostic: options.onDiagnostic }),
|
|
114
|
+
});
|
|
115
|
+
const transportFactory = new OwnedCodexBackendTransportFactory({
|
|
116
|
+
processFactory: createPlatformCodexProcessOwnerFactory({
|
|
117
|
+
platform,
|
|
118
|
+
...(windowsGuardianFactory === null ? {} : { windowsGuardianFactory }),
|
|
119
|
+
}),
|
|
120
|
+
credentialSnapshotter,
|
|
121
|
+
preflightRunner: new NativeCodexHostPreflightRunner({
|
|
122
|
+
probe,
|
|
123
|
+
environment: hostEnvironment,
|
|
124
|
+
platform,
|
|
125
|
+
hasApiKey: settings.codex_api_key !== null,
|
|
126
|
+
...(options.onDiagnostic === undefined ? {} : { onDiagnostic: options.onDiagnostic }),
|
|
127
|
+
...(windowsGuardianFactory === null
|
|
128
|
+
? {}
|
|
129
|
+
: { commandRunner: command => windowsGuardianFactory.runCommand(command) }),
|
|
130
|
+
}),
|
|
131
|
+
schemaProbe: new NativeCodexLiveSchemaProbe({
|
|
132
|
+
environment: hostEnvironment,
|
|
133
|
+
platform,
|
|
134
|
+
...(windowsGuardianFactory === null
|
|
135
|
+
? {}
|
|
136
|
+
: { commandRunner: command => windowsGuardianFactory.runCommand(command) }),
|
|
137
|
+
}),
|
|
138
|
+
ephemeralHomeFactory: () => {
|
|
139
|
+
const path = realpathSync(mkdtempSync(join(temporaryDirectory, 'nova-codex-home-')));
|
|
140
|
+
chmodSync(path, 0o700);
|
|
141
|
+
return hostEphemeralCodexHomeFromConfig(path, [path]);
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
return Object.freeze({ catalog, transportFactory, projectHost });
|
|
145
|
+
}
|
|
146
|
+
/** Host-only seam. Renderer, model, work order, and settings values cannot select this path. */
|
|
147
|
+
export function loadCodexSandboxProbeFromResources(options) {
|
|
148
|
+
try {
|
|
149
|
+
const target = supportedTarget(options.platform, options.arch);
|
|
150
|
+
if (target === null || !isAbsolute(options.resourcesPath))
|
|
151
|
+
return null;
|
|
152
|
+
const resourcesRoot = resolve(options.resourcesPath);
|
|
153
|
+
if (realpathSync(resourcesRoot) !== resourcesRoot)
|
|
154
|
+
return null;
|
|
155
|
+
const manifest = JSON.parse(snapshotRegularFile(resolve(resourcesRoot, 'native-resources-v1.json'), MAX_MANIFEST_BYTES).bytes.toString('utf8'));
|
|
156
|
+
const expectedPath = options.platform === 'win32' ? PROBE_PATH_WINDOWS : PROBE_PATH;
|
|
157
|
+
const record = requireProbeRecord(manifest, target, expectedPath, options.platform, options.arch);
|
|
158
|
+
const probePath = resolve(resourcesRoot, expectedPath);
|
|
159
|
+
if (realpathSync(probePath) !== probePath)
|
|
160
|
+
return null;
|
|
161
|
+
const before = snapshotRegularFile(probePath, MAX_PROBE_BYTES);
|
|
162
|
+
if (before.size !== record.byteSize
|
|
163
|
+
|| before.sha256 !== record.sha256
|
|
164
|
+
|| !validExecutable(before.bytes, options.platform, options.arch))
|
|
165
|
+
return null;
|
|
166
|
+
if (process.platform !== 'win32' && options.platform !== 'win32')
|
|
167
|
+
accessSync(probePath, constants.X_OK);
|
|
168
|
+
const after = snapshotRegularFile(probePath, MAX_PROBE_BYTES);
|
|
169
|
+
if (!sameSnapshot(before, after))
|
|
170
|
+
return null;
|
|
171
|
+
const capability = Object.freeze({ [sandboxProbeBrand]: true });
|
|
172
|
+
sandboxProbeValues.set(capability, Object.freeze({
|
|
173
|
+
path: probePath,
|
|
174
|
+
snapshot: before,
|
|
175
|
+
platform: options.platform,
|
|
176
|
+
arch: options.arch,
|
|
177
|
+
}));
|
|
178
|
+
return capability;
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/** Test-only projection; production execution retains the opaque capability. */
|
|
185
|
+
export function codexSandboxProbePathForTest(probe) {
|
|
186
|
+
const value = sandboxProbeValues.get(probe);
|
|
187
|
+
if (value === undefined)
|
|
188
|
+
throw new CodexTransportError('sandbox_failed');
|
|
189
|
+
return value.path;
|
|
190
|
+
}
|
|
191
|
+
export class NativeCodexHostPreflightRunner {
|
|
192
|
+
#probe;
|
|
193
|
+
#testProbe;
|
|
194
|
+
#environment;
|
|
195
|
+
#hasApiKey;
|
|
196
|
+
#runCommand;
|
|
197
|
+
#onDiagnostic;
|
|
198
|
+
constructor(options) {
|
|
199
|
+
if ((options.probe === undefined) === (options.probePath === undefined)) {
|
|
200
|
+
throw new CodexTransportError('sandbox_failed');
|
|
201
|
+
}
|
|
202
|
+
if (options.probe !== undefined) {
|
|
203
|
+
if (sandboxProbeValues.get(options.probe) === undefined) {
|
|
204
|
+
throw new CodexTransportError('sandbox_failed');
|
|
205
|
+
}
|
|
206
|
+
this.#probe = options.probe;
|
|
207
|
+
this.#testProbe = null;
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
const path = options.probePath;
|
|
211
|
+
if (!isAbsolute(path) || realpathSync(path) !== path) {
|
|
212
|
+
throw new CodexTransportError('sandbox_failed');
|
|
213
|
+
}
|
|
214
|
+
this.#probe = null;
|
|
215
|
+
this.#testProbe = Object.freeze({ path, snapshot: snapshotRegularFile(path, MAX_PROBE_BYTES) });
|
|
216
|
+
}
|
|
217
|
+
this.#environment = filteredEnvironment(options.environment, options.platform ?? process.platform);
|
|
218
|
+
this.#hasApiKey = options.hasApiKey;
|
|
219
|
+
this.#runCommand = options.commandRunner ?? runBoundedCodexCommand;
|
|
220
|
+
this.#onDiagnostic = options.onDiagnostic ?? (() => undefined);
|
|
221
|
+
}
|
|
222
|
+
async run(config, timeoutMs, observe) {
|
|
223
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
224
|
+
throw new CodexTransportError('preflight_timeout');
|
|
225
|
+
}
|
|
226
|
+
const deadline = Date.now() + Math.min(timeoutMs, 20_000);
|
|
227
|
+
try {
|
|
228
|
+
const binary = hostBinaryPath(config.binary);
|
|
229
|
+
const prefixArgs = config.prefixArgs ?? [];
|
|
230
|
+
const workspace = hostWorkspacePath(config.workspace);
|
|
231
|
+
requireWorkspaceRoot(workspace);
|
|
232
|
+
observePreflight(observe, 'version');
|
|
233
|
+
const versionResult = await this.#command(binary, [...prefixArgs, '--version'], workspace, deadline, 4096, this.#environment, observe);
|
|
234
|
+
const version = parseVersion(versionResult);
|
|
235
|
+
let credential;
|
|
236
|
+
if (this.#hasApiKey) {
|
|
237
|
+
credential = Object.freeze({ present: true, identity: 'api_key', policy: 'process_only' });
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
observePreflight(observe, 'login');
|
|
241
|
+
const loginResult = await this.#command(binary, [...prefixArgs, 'login', 'status'], workspace, deadline, 4096, config.preserveHome ? { ...this.#environment, CODEX_HOME: hostCodexHomeValue(config.codexHome).path } : this.#environment, observe);
|
|
242
|
+
let identity;
|
|
243
|
+
try {
|
|
244
|
+
identity = parseLogin(loginResult);
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
this.#emitDiagnostic(loginDiagnostic(loginResult));
|
|
248
|
+
throw error;
|
|
249
|
+
}
|
|
250
|
+
credential = Object.freeze({ present: true, identity, policy: 'saved_login' });
|
|
251
|
+
}
|
|
252
|
+
observePreflight(observe, 'sandbox');
|
|
253
|
+
const limits = await this.#runSandboxProbe(binary, prefixArgs, workspace, deadline, observe);
|
|
254
|
+
return Object.freeze({
|
|
255
|
+
version,
|
|
256
|
+
root_matches: true,
|
|
257
|
+
mount: 'workspace_only',
|
|
258
|
+
subprocess: 'contained',
|
|
259
|
+
network: 'blocked',
|
|
260
|
+
credential,
|
|
261
|
+
limits,
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
if (error instanceof CodexTransportError)
|
|
266
|
+
throw new CodexTransportError(error.code);
|
|
267
|
+
throw new CodexTransportError('preflight_failed');
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
#emitDiagnostic(code) {
|
|
271
|
+
try {
|
|
272
|
+
this.#onDiagnostic(code);
|
|
273
|
+
}
|
|
274
|
+
catch { /* diagnostics are advisory */ }
|
|
275
|
+
}
|
|
276
|
+
async #runSandboxProbe(binary, prefixArgs, workspace, deadline, observe) {
|
|
277
|
+
const materialized = this.#materializeProbe();
|
|
278
|
+
const parent = dirname(workspace);
|
|
279
|
+
const sibling = mkdtempSync(join(parent, '.nova-personal-agent-codex-preflight-'));
|
|
280
|
+
const canary = join(sibling, 'canary');
|
|
281
|
+
const marker = join(workspace, `.nova-personal-agent-codex-preflight-${randomUUID().replaceAll('-', '')}`);
|
|
282
|
+
chmodSync(sibling, 0o700);
|
|
283
|
+
writeFileSync(canary, 'host-created-canary', { encoding: 'utf8', mode: 0o600, flag: 'wx' });
|
|
284
|
+
const canonicalCanary = realpathSync(canary);
|
|
285
|
+
const server = createServer(socket => socket.end());
|
|
286
|
+
try {
|
|
287
|
+
const port = await listenLoopback(server, Math.max(1, deadline - Date.now()));
|
|
288
|
+
const result = await this.#command(binary, [...prefixArgs,
|
|
289
|
+
'sandbox', '-P', 'nova_personal_agent', '-C', workspace,
|
|
290
|
+
'-c', `permissions.nova_personal_agent=${PERMISSION_PROFILE}`,
|
|
291
|
+
'-c', 'shell_environment_policy.inherit="core"',
|
|
292
|
+
'-c', 'shell_environment_policy.include_only=["PATH","LANG","LC_ALL","TERM"]',
|
|
293
|
+
materialized.path,
|
|
294
|
+
'--main', workspace, canonicalCanary, marker, String(port),
|
|
295
|
+
], workspace, deadline, MAX_COMMAND_STDOUT, this.#environment, observe);
|
|
296
|
+
const limits = parseProbe(result);
|
|
297
|
+
if (readFileSync(canary, 'utf8') !== 'host-created-canary') {
|
|
298
|
+
throw new CodexTransportError('sandbox_failed');
|
|
299
|
+
}
|
|
300
|
+
try {
|
|
301
|
+
lstatSync(marker);
|
|
302
|
+
throw new CodexTransportError('sandbox_failed');
|
|
303
|
+
}
|
|
304
|
+
catch (error) {
|
|
305
|
+
if (error instanceof CodexTransportError)
|
|
306
|
+
throw error;
|
|
307
|
+
if (!isErrno(error, 'ENOENT'))
|
|
308
|
+
throw new CodexTransportError('sandbox_failed');
|
|
309
|
+
}
|
|
310
|
+
materialized.verify();
|
|
311
|
+
return limits;
|
|
312
|
+
}
|
|
313
|
+
finally {
|
|
314
|
+
await closeServer(server);
|
|
315
|
+
rmSync(sibling, { recursive: true, force: true });
|
|
316
|
+
materialized.cleanup();
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
#materializeProbe() {
|
|
320
|
+
const production = this.#probe === null ? undefined : sandboxProbeValues.get(this.#probe);
|
|
321
|
+
const source = production ?? this.#testProbe;
|
|
322
|
+
if (source === null || source === undefined)
|
|
323
|
+
throw new CodexTransportError('sandbox_failed');
|
|
324
|
+
if (!sameSnapshot(source.snapshot, snapshotRegularFile(source.path, MAX_PROBE_BYTES))) {
|
|
325
|
+
throw new CodexTransportError('sandbox_failed');
|
|
326
|
+
}
|
|
327
|
+
const directory = realpathSync(mkdtempSync(join(tmpdir(), 'nova-codex-probe-')));
|
|
328
|
+
chmodSync(directory, 0o700);
|
|
329
|
+
const suffix = production?.platform === 'win32' ? '.exe' : '';
|
|
330
|
+
const destination = join(directory, `sandbox-probe${suffix}`);
|
|
331
|
+
try {
|
|
332
|
+
writeFileSync(destination, source.snapshot.bytes, { flag: 'wx', mode: 0o700 });
|
|
333
|
+
chmodSync(destination, 0o700);
|
|
334
|
+
const canonical = realpathSync(destination);
|
|
335
|
+
const copied = snapshotRegularFile(canonical, MAX_PROBE_BYTES);
|
|
336
|
+
if (copied.size !== source.snapshot.size
|
|
337
|
+
|| copied.sha256 !== source.snapshot.sha256
|
|
338
|
+
|| (production !== undefined && !validExecutable(copied.bytes, production.platform, production.arch)))
|
|
339
|
+
throw new CodexTransportError('sandbox_failed');
|
|
340
|
+
return Object.freeze({
|
|
341
|
+
path: canonical,
|
|
342
|
+
verify: () => {
|
|
343
|
+
if (!sameSnapshot(copied, snapshotRegularFile(canonical, MAX_PROBE_BYTES))) {
|
|
344
|
+
throw new CodexTransportError('sandbox_failed');
|
|
345
|
+
}
|
|
346
|
+
},
|
|
347
|
+
cleanup: () => { rmSync(directory, { recursive: true, force: true }); },
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
catch (error) {
|
|
351
|
+
rmSync(directory, { recursive: true, force: true });
|
|
352
|
+
if (error instanceof CodexTransportError)
|
|
353
|
+
throw error;
|
|
354
|
+
throw new CodexTransportError('sandbox_failed');
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
#command(binary, argv, cwd, deadline, stdoutLimit, environment = this.#environment, observe) {
|
|
358
|
+
const remaining = deadline - Date.now();
|
|
359
|
+
if (remaining <= 0)
|
|
360
|
+
throw new CodexTransportError('preflight_timeout');
|
|
361
|
+
return this.#runCommand(Object.freeze({
|
|
362
|
+
...(observe === undefined ? {} : { observe }),
|
|
363
|
+
binary,
|
|
364
|
+
argv: Object.freeze([...argv]),
|
|
365
|
+
cwd,
|
|
366
|
+
environment,
|
|
367
|
+
timeoutMs: remaining,
|
|
368
|
+
stdoutLimit,
|
|
369
|
+
stderrLimit: MAX_COMMAND_STDERR,
|
|
370
|
+
shell: false,
|
|
371
|
+
}));
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
export class NativeCodexLiveSchemaProbe {
|
|
375
|
+
#environment;
|
|
376
|
+
#runCommand;
|
|
377
|
+
constructor(options) {
|
|
378
|
+
this.#environment = filteredEnvironment(options.environment, options.platform ?? process.platform);
|
|
379
|
+
this.#runCommand = options.commandRunner ?? runBoundedCodexCommand;
|
|
380
|
+
}
|
|
381
|
+
async generate(config, timeoutMs, observe) {
|
|
382
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
383
|
+
throw new CodexTransportError('preflight_timeout');
|
|
384
|
+
}
|
|
385
|
+
const directory = mkdtempSync(join(dirname(hostWorkspacePath(config.workspace)), '.nova-codex-schema-'));
|
|
386
|
+
chmodSync(directory, 0o700);
|
|
387
|
+
try {
|
|
388
|
+
const result = await this.#runCommand(Object.freeze({
|
|
389
|
+
...(observe === undefined ? {} : { observe }),
|
|
390
|
+
binary: hostBinaryPath(config.binary),
|
|
391
|
+
argv: Object.freeze([
|
|
392
|
+
...(config.prefixArgs ?? []),
|
|
393
|
+
// The pinned 0.152.0 bundle (spec 01) is the `--experimental` output; the live probe must
|
|
394
|
+
// generate the same surface or the approval params fail validation.
|
|
395
|
+
'app-server', 'generate-json-schema', '--experimental', '--out', directory,
|
|
396
|
+
]),
|
|
397
|
+
cwd: hostWorkspacePath(config.workspace),
|
|
398
|
+
environment: this.#environment,
|
|
399
|
+
timeoutMs: Math.min(timeoutMs, 20_000),
|
|
400
|
+
stdoutLimit: MAX_COMMAND_STDERR,
|
|
401
|
+
stderrLimit: MAX_COMMAND_STDERR,
|
|
402
|
+
shell: false,
|
|
403
|
+
}));
|
|
404
|
+
if (result.status !== 0)
|
|
405
|
+
throw new CodexTransportError('unsupported_protocol');
|
|
406
|
+
const files = new Set(['ClientRequest.json']);
|
|
407
|
+
for (const spec of Object.values(APP_SERVER_METHOD_SCHEMAS))
|
|
408
|
+
files.add(spec.file);
|
|
409
|
+
for (const spec of APP_SERVER_INBOUND_SCHEMAS)
|
|
410
|
+
files.add(spec.file);
|
|
411
|
+
for (const file of APP_SERVER_APPROVAL_SCHEMA_FILES)
|
|
412
|
+
files.add(file);
|
|
413
|
+
const bundle = {};
|
|
414
|
+
for (const name of files) {
|
|
415
|
+
const path = resolve(directory, name);
|
|
416
|
+
if (!path.startsWith(`${directory}${sep}`)) {
|
|
417
|
+
throw new CodexTransportError('unsupported_protocol');
|
|
418
|
+
}
|
|
419
|
+
const snapshot = snapshotRegularFile(path, MAX_SCHEMA_BYTES);
|
|
420
|
+
try {
|
|
421
|
+
bundle[name] = JSON.parse(snapshot.bytes.toString('utf8'));
|
|
422
|
+
}
|
|
423
|
+
catch {
|
|
424
|
+
throw new CodexTransportError('unsupported_protocol');
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return Object.freeze(bundle);
|
|
428
|
+
}
|
|
429
|
+
catch (error) {
|
|
430
|
+
if (error instanceof CodexTransportError)
|
|
431
|
+
throw new CodexTransportError(error.code);
|
|
432
|
+
throw new CodexTransportError('unsupported_protocol');
|
|
433
|
+
}
|
|
434
|
+
finally {
|
|
435
|
+
rmSync(directory, { recursive: true, force: true });
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
export async function runBoundedCodexCommand(command) {
|
|
440
|
+
if (!isAbsolute(command.binary)
|
|
441
|
+
|| !isAbsolute(command.cwd)
|
|
442
|
+
|| !Number.isFinite(command.timeoutMs)
|
|
443
|
+
|| command.timeoutMs <= 0)
|
|
444
|
+
throw new CodexTransportError('preflight_failed');
|
|
445
|
+
let child;
|
|
446
|
+
try {
|
|
447
|
+
child = spawn(command.binary, [...command.argv], {
|
|
448
|
+
cwd: command.cwd,
|
|
449
|
+
env: { ...command.environment },
|
|
450
|
+
shell: false,
|
|
451
|
+
detached: process.platform !== 'win32',
|
|
452
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
453
|
+
windowsHide: true,
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
catch {
|
|
457
|
+
throw new CodexTransportError('binary_missing');
|
|
458
|
+
}
|
|
459
|
+
let stdout = Buffer.alloc(0);
|
|
460
|
+
let stderr = Buffer.alloc(0);
|
|
461
|
+
let rejectBoundary;
|
|
462
|
+
const boundary = new Promise((_resolve, reject) => { rejectBoundary = reject; });
|
|
463
|
+
let boundaryFailed = false;
|
|
464
|
+
const fail = (code) => {
|
|
465
|
+
if (boundaryFailed)
|
|
466
|
+
return;
|
|
467
|
+
boundaryFailed = true;
|
|
468
|
+
rejectBoundary(new CodexTransportError(code));
|
|
469
|
+
};
|
|
470
|
+
child.stdout.on('data', (chunk) => {
|
|
471
|
+
if (stdout.byteLength + chunk.byteLength > command.stdoutLimit) {
|
|
472
|
+
fail('preflight_failed');
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
stdout = Buffer.concat([stdout, chunk]);
|
|
476
|
+
});
|
|
477
|
+
child.stderr.on('data', (chunk) => {
|
|
478
|
+
if (stderr.byteLength + chunk.byteLength > command.stderrLimit) {
|
|
479
|
+
fail('preflight_failed');
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
stderr = Buffer.concat([stderr, chunk]);
|
|
483
|
+
});
|
|
484
|
+
const exit = new Promise((resolveExit, rejectExit) => {
|
|
485
|
+
child.once('error', () => { rejectExit(new CodexTransportError('binary_missing')); });
|
|
486
|
+
child.once('exit', status => { resolveExit(status); });
|
|
487
|
+
});
|
|
488
|
+
exit.catch(() => undefined);
|
|
489
|
+
const stdoutClosed = streamClosed(child.stdout);
|
|
490
|
+
const stderrClosed = streamClosed(child.stderr);
|
|
491
|
+
const deadline = Date.now() + command.timeoutMs;
|
|
492
|
+
const timeout = setTimeout(() => { fail('preflight_timeout'); }, command.timeoutMs);
|
|
493
|
+
try {
|
|
494
|
+
const status = await Promise.race([exit, boundary]);
|
|
495
|
+
await settleBefore(Promise.race([Promise.all([stdoutClosed, stderrClosed]), boundary]), deadline, 'preflight_timeout');
|
|
496
|
+
if (process.platform !== 'win32' && processGroupAlive(child.pid)) {
|
|
497
|
+
throw new CodexTransportError('preflight_failed');
|
|
498
|
+
}
|
|
499
|
+
return Object.freeze({
|
|
500
|
+
status,
|
|
501
|
+
stdout,
|
|
502
|
+
...(stderr.byteLength === 0 ? {} : { stderr }),
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
catch (error) {
|
|
506
|
+
observePreflight(command.observe, 'cleanup_started');
|
|
507
|
+
try {
|
|
508
|
+
await stopAndReapCommandTree(child.pid, exit, stdoutClosed, stderrClosed);
|
|
509
|
+
observePreflight(command.observe, 'cleanup_completed');
|
|
510
|
+
}
|
|
511
|
+
catch (cleanupError) {
|
|
512
|
+
observePreflight(command.observe, 'cleanup_failed');
|
|
513
|
+
throw cleanupError;
|
|
514
|
+
}
|
|
515
|
+
if (error instanceof CodexTransportError)
|
|
516
|
+
throw error;
|
|
517
|
+
throw new CodexTransportError('preflight_failed');
|
|
518
|
+
}
|
|
519
|
+
finally {
|
|
520
|
+
clearTimeout(timeout);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
function observePreflight(observe, event) {
|
|
524
|
+
try {
|
|
525
|
+
observe?.(event);
|
|
526
|
+
}
|
|
527
|
+
catch { /* Diagnostics must never interrupt process-tree cleanup. */ }
|
|
528
|
+
}
|
|
529
|
+
function streamClosed(stream) {
|
|
530
|
+
if (Reflect.get(stream, 'closed') === true || Reflect.get(stream, 'destroyed') === true) {
|
|
531
|
+
return Promise.resolve();
|
|
532
|
+
}
|
|
533
|
+
return new Promise(resolveClose => { stream.once('close', () => { resolveClose(); }); });
|
|
534
|
+
}
|
|
535
|
+
async function settleBefore(operation, deadline, code) {
|
|
536
|
+
let timer;
|
|
537
|
+
try {
|
|
538
|
+
return await Promise.race([
|
|
539
|
+
operation,
|
|
540
|
+
new Promise((_resolve, reject) => {
|
|
541
|
+
timer = setTimeout(() => {
|
|
542
|
+
reject(new CodexTransportError(code));
|
|
543
|
+
}, Math.max(0, deadline - Date.now()));
|
|
544
|
+
}),
|
|
545
|
+
]);
|
|
546
|
+
}
|
|
547
|
+
finally {
|
|
548
|
+
if (timer !== undefined)
|
|
549
|
+
clearTimeout(timer);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
async function stopAndReapCommandTree(pid, exit, stdoutClosed, stderrClosed) {
|
|
553
|
+
signalCommandTree(pid);
|
|
554
|
+
const deadline = Date.now() + 5000;
|
|
555
|
+
try {
|
|
556
|
+
await settleBefore(Promise.allSettled([exit, stdoutClosed, stderrClosed]), deadline, 'preflight_failed');
|
|
557
|
+
}
|
|
558
|
+
catch {
|
|
559
|
+
throw new CodexTransportError('preflight_failed');
|
|
560
|
+
}
|
|
561
|
+
while (process.platform !== 'win32' && processGroupAlive(pid)) {
|
|
562
|
+
if (Date.now() >= deadline)
|
|
563
|
+
throw new CodexTransportError('preflight_failed');
|
|
564
|
+
await new Promise(resolveWait => { setTimeout(resolveWait, 25); });
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
function signalCommandTree(pid) {
|
|
568
|
+
if (!Number.isSafeInteger(pid) || pid === undefined || pid <= 0)
|
|
569
|
+
return;
|
|
570
|
+
try {
|
|
571
|
+
process.kill(process.platform === 'win32' ? pid : -pid, 'SIGKILL');
|
|
572
|
+
}
|
|
573
|
+
catch (error) {
|
|
574
|
+
if (!isErrno(error, 'ESRCH'))
|
|
575
|
+
throw new CodexTransportError('preflight_failed');
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
function processGroupAlive(pid) {
|
|
579
|
+
if (!Number.isSafeInteger(pid) || pid === undefined || pid <= 0)
|
|
580
|
+
return false;
|
|
581
|
+
try {
|
|
582
|
+
process.kill(-pid, 0);
|
|
583
|
+
return true;
|
|
584
|
+
}
|
|
585
|
+
catch (error) {
|
|
586
|
+
if (isErrno(error, 'ESRCH'))
|
|
587
|
+
return false;
|
|
588
|
+
if (isErrno(error, 'EPERM'))
|
|
589
|
+
return true;
|
|
590
|
+
throw new CodexTransportError('preflight_failed');
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
function parseVersion(result) {
|
|
594
|
+
const value = decodeSuccessful(result, 'unsupported_version');
|
|
595
|
+
const admitted = admitCodexCliVersion(value);
|
|
596
|
+
if (admitted === null)
|
|
597
|
+
throw new CodexTransportError('unsupported_version');
|
|
598
|
+
return admitted.version;
|
|
599
|
+
}
|
|
600
|
+
function parseLogin(result) {
|
|
601
|
+
const lines = decodeSuccessfulLogin(result)
|
|
602
|
+
.split(/\r?\n/u)
|
|
603
|
+
.map(value => value.trim().replaceAll(/\s+/gu, ' '))
|
|
604
|
+
.filter(Boolean);
|
|
605
|
+
const identities = lines.flatMap(line => {
|
|
606
|
+
if (line === 'Logged in using ChatGPT')
|
|
607
|
+
return ['chatgpt'];
|
|
608
|
+
if (line === 'Logged in using API key' || /^Logged in using an API key - (?:\*\*\*|\S{8}\*\*\*\S{5})$/u.test(line)) {
|
|
609
|
+
return ['api_key'];
|
|
610
|
+
}
|
|
611
|
+
if (/logged in|chatgpt|api key/iu.test(line))
|
|
612
|
+
throw new CodexTransportError('credential_missing');
|
|
613
|
+
return [];
|
|
614
|
+
});
|
|
615
|
+
if (identities.length !== 1)
|
|
616
|
+
throw new CodexTransportError('credential_missing');
|
|
617
|
+
return identities[0];
|
|
618
|
+
}
|
|
619
|
+
function loginDiagnostic(result) {
|
|
620
|
+
if (result.status !== 0)
|
|
621
|
+
return 'codex_login_status_nonzero';
|
|
622
|
+
const streams = [result.stdout, result.stderr]
|
|
623
|
+
.filter((value) => Buffer.isBuffer(value) && value.byteLength > 0);
|
|
624
|
+
if (streams.length === 0)
|
|
625
|
+
return 'codex_login_status_no_output';
|
|
626
|
+
if (streams.length > 1)
|
|
627
|
+
return 'codex_login_status_multiple_streams';
|
|
628
|
+
return 'codex_login_status_unrecognized';
|
|
629
|
+
}
|
|
630
|
+
function decodeSuccessfulLogin(result) {
|
|
631
|
+
const streams = [result.stdout, result.stderr]
|
|
632
|
+
.filter((value) => Buffer.isBuffer(value) && value.byteLength > 0);
|
|
633
|
+
if (result.status !== 0 || streams.length !== 1) {
|
|
634
|
+
throw new CodexTransportError('credential_missing');
|
|
635
|
+
}
|
|
636
|
+
try {
|
|
637
|
+
return stripLikePython(new TextDecoder('utf-8', { fatal: true }).decode(streams[0]));
|
|
638
|
+
}
|
|
639
|
+
catch {
|
|
640
|
+
throw new CodexTransportError('credential_missing');
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
function parseProbe(result) {
|
|
644
|
+
const value = decodeSuccessful(result, 'sandbox_failed');
|
|
645
|
+
let document;
|
|
646
|
+
try {
|
|
647
|
+
document = JSON.parse(value);
|
|
648
|
+
}
|
|
649
|
+
catch {
|
|
650
|
+
throw new CodexTransportError('sandbox_failed');
|
|
651
|
+
}
|
|
652
|
+
if (!isPlainRecord(document))
|
|
653
|
+
throw new CodexTransportError('sandbox_failed');
|
|
654
|
+
if (!exactKeys(document, [...PROBE_BOOLEAN_FIELDS, 'limits'])) {
|
|
655
|
+
throw new CodexTransportError('sandbox_failed');
|
|
656
|
+
}
|
|
657
|
+
if (PROBE_BOOLEAN_FIELDS.some(name => document[name] !== true)) {
|
|
658
|
+
throw new CodexTransportError('sandbox_failed');
|
|
659
|
+
}
|
|
660
|
+
const rawLimits = document.limits;
|
|
661
|
+
if (!isPlainRecord(rawLimits) || !exactKeys(rawLimits, LIMIT_NAMES)) {
|
|
662
|
+
throw new CodexTransportError('sandbox_failed');
|
|
663
|
+
}
|
|
664
|
+
const limits = {};
|
|
665
|
+
for (const name of LIMIT_NAMES) {
|
|
666
|
+
const candidate = rawLimits[name];
|
|
667
|
+
if (typeof candidate !== 'string' || !LIMIT_CLASSES.has(candidate)) {
|
|
668
|
+
throw new CodexTransportError('sandbox_failed');
|
|
669
|
+
}
|
|
670
|
+
limits[name] = candidate;
|
|
671
|
+
}
|
|
672
|
+
return Object.freeze(limits);
|
|
673
|
+
}
|
|
674
|
+
function decodeSuccessful(result, code) {
|
|
675
|
+
if (result.status !== 0 || !Buffer.isBuffer(result.stdout))
|
|
676
|
+
throw new CodexTransportError(code);
|
|
677
|
+
try {
|
|
678
|
+
return new TextDecoder('utf-8', { fatal: true }).decode(result.stdout).trim();
|
|
679
|
+
}
|
|
680
|
+
catch {
|
|
681
|
+
throw new CodexTransportError(code);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
function filteredEnvironment(environment, platform) {
|
|
685
|
+
const result = {};
|
|
686
|
+
try {
|
|
687
|
+
for (const name of ENVIRONMENT_ALLOWLIST) {
|
|
688
|
+
const value = environmentValue(environment, name, platform);
|
|
689
|
+
if (typeof value === 'string' && value !== '' && !value.includes('\0'))
|
|
690
|
+
result[name] = value;
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
catch {
|
|
694
|
+
throw new CodexTransportError('preflight_failed');
|
|
695
|
+
}
|
|
696
|
+
if (result.PATH === undefined || result.HOME === undefined) {
|
|
697
|
+
throw new CodexTransportError('preflight_failed');
|
|
698
|
+
}
|
|
699
|
+
return Object.freeze(result);
|
|
700
|
+
}
|
|
701
|
+
function requireWorkspaceRoot(workspace) {
|
|
702
|
+
try {
|
|
703
|
+
if (realpathSync(workspace) !== workspace || !statSync(workspace).isDirectory())
|
|
704
|
+
throw new Error();
|
|
705
|
+
try {
|
|
706
|
+
const marker = lstatSync(join(workspace, '.git'));
|
|
707
|
+
if (marker.isSymbolicLink() || (!marker.isDirectory() && !marker.isFile()))
|
|
708
|
+
throw new Error();
|
|
709
|
+
}
|
|
710
|
+
catch (error) {
|
|
711
|
+
if (!isErrno(error, 'ENOENT'))
|
|
712
|
+
throw error;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
catch {
|
|
716
|
+
throw new CodexTransportError('workspace_root_mismatch');
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
async function listenLoopback(server, timeoutMs) {
|
|
720
|
+
return await new Promise((resolvePort, rejectPort) => {
|
|
721
|
+
const timer = setTimeout(() => {
|
|
722
|
+
server.close();
|
|
723
|
+
rejectPort(new CodexTransportError('preflight_timeout'));
|
|
724
|
+
}, timeoutMs);
|
|
725
|
+
server.once('error', () => {
|
|
726
|
+
clearTimeout(timer);
|
|
727
|
+
rejectPort(new CodexTransportError('sandbox_failed'));
|
|
728
|
+
});
|
|
729
|
+
server.listen(0, '127.0.0.1', () => {
|
|
730
|
+
clearTimeout(timer);
|
|
731
|
+
const address = server.address();
|
|
732
|
+
if (address === null || typeof address === 'string') {
|
|
733
|
+
rejectPort(new CodexTransportError('sandbox_failed'));
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
resolvePort(address.port);
|
|
737
|
+
});
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
async function closeServer(server) {
|
|
741
|
+
if (!server.listening)
|
|
742
|
+
return;
|
|
743
|
+
await new Promise(resolveClose => { server.close(() => { resolveClose(); }); });
|
|
744
|
+
}
|
|
745
|
+
function requireProbeRecord(manifest, target, expectedPath, platform, arch) {
|
|
746
|
+
requireExactRecord(manifest, ['schema_version', 'target', 'resources']);
|
|
747
|
+
if (manifest.schema_version !== 1
|
|
748
|
+
|| manifest.target !== target
|
|
749
|
+
|| !Array.isArray(manifest.resources)
|
|
750
|
+
|| manifest.resources.length === 0
|
|
751
|
+
|| manifest.resources.length > 256) {
|
|
752
|
+
throw new Error('native resource rejected');
|
|
753
|
+
}
|
|
754
|
+
let selected = null;
|
|
755
|
+
const ids = new Set();
|
|
756
|
+
const paths = new Set();
|
|
757
|
+
for (const resource of manifest.resources) {
|
|
758
|
+
requireExactRecord(resource, [
|
|
759
|
+
'logical_id', 'relative_path', 'byte_size', 'sha256', 'kind', 'platform',
|
|
760
|
+
'architecture', 'electron_abi', 'build_contract_version',
|
|
761
|
+
...(typeof resource === 'object' && resource !== null && 'kind' in resource && resource.kind === 'node_addon' && Object.hasOwn(resource, 'node_api_version') ? ['node_api_version'] : []),
|
|
762
|
+
]);
|
|
763
|
+
if (typeof resource.logical_id !== 'string'
|
|
764
|
+
|| typeof resource.relative_path !== 'string'
|
|
765
|
+
|| ids.has(resource.logical_id)
|
|
766
|
+
|| paths.has(resource.relative_path))
|
|
767
|
+
throw new Error('native resource rejected');
|
|
768
|
+
ids.add(resource.logical_id);
|
|
769
|
+
paths.add(resource.relative_path);
|
|
770
|
+
if (resource.logical_id !== PROBE_ID)
|
|
771
|
+
continue;
|
|
772
|
+
if (resource.relative_path !== expectedPath
|
|
773
|
+
|| resource.kind !== 'executable'
|
|
774
|
+
|| resource.platform !== platform
|
|
775
|
+
|| resource.architecture !== arch
|
|
776
|
+
|| resource.electron_abi !== null
|
|
777
|
+
|| resource.build_contract_version !== 1
|
|
778
|
+
|| typeof resource.byte_size !== 'number'
|
|
779
|
+
|| !Number.isSafeInteger(resource.byte_size)
|
|
780
|
+
|| resource.byte_size <= 0
|
|
781
|
+
|| typeof resource.sha256 !== 'string'
|
|
782
|
+
|| !/^[0-9a-f]{64}$/u.test(resource.sha256)
|
|
783
|
+
|| selected !== null)
|
|
784
|
+
throw new Error('native resource rejected');
|
|
785
|
+
selected = { byteSize: resource.byte_size, sha256: resource.sha256 };
|
|
786
|
+
}
|
|
787
|
+
if (selected === null)
|
|
788
|
+
throw new Error('native resource rejected');
|
|
789
|
+
return selected;
|
|
790
|
+
}
|
|
791
|
+
function validExecutable(bytes, platform, arch) {
|
|
792
|
+
if (platform === 'darwin') {
|
|
793
|
+
const cpu = arch === 'arm64' ? 0x0100000c : 0x01000007;
|
|
794
|
+
return bytes.length >= 16
|
|
795
|
+
&& bytes.readUInt32LE(0) === 0xfeedfacf
|
|
796
|
+
&& bytes.readUInt32LE(4) === cpu
|
|
797
|
+
&& bytes.readUInt32LE(12) === 2;
|
|
798
|
+
}
|
|
799
|
+
if (platform === 'linux') {
|
|
800
|
+
return bytes.length >= 20
|
|
801
|
+
&& bytes.subarray(0, 4).equals(Buffer.from([0x7f, 0x45, 0x4c, 0x46]))
|
|
802
|
+
&& bytes[4] === 2
|
|
803
|
+
&& bytes[5] === 1
|
|
804
|
+
&& bytes.readUInt16LE(16) === 3
|
|
805
|
+
&& bytes.readUInt16LE(18) === 0x3e;
|
|
806
|
+
}
|
|
807
|
+
if (bytes.length < 64 || bytes.subarray(0, 2).toString('ascii') !== 'MZ')
|
|
808
|
+
return false;
|
|
809
|
+
const offset = bytes.readUInt32LE(0x3c);
|
|
810
|
+
return offset + 24 <= bytes.length
|
|
811
|
+
&& bytes.subarray(offset, offset + 4).toString('binary') === 'PE\0\0'
|
|
812
|
+
&& bytes.readUInt16LE(offset + 4) === 0x8664
|
|
813
|
+
&& (bytes.readUInt16LE(offset + 22) & 0x2000) === 0;
|
|
814
|
+
}
|
|
815
|
+
function supportedTarget(platform, arch) {
|
|
816
|
+
if (platform === 'darwin' && (arch === 'arm64' || arch === 'x64'))
|
|
817
|
+
return `darwin-${arch}`;
|
|
818
|
+
if (platform === 'linux' && arch === 'x64')
|
|
819
|
+
return 'linux-x64-gnu';
|
|
820
|
+
if (platform === 'win32' && arch === 'x64')
|
|
821
|
+
return 'win32-x64';
|
|
822
|
+
return null;
|
|
823
|
+
}
|
|
824
|
+
function requireExactRecord(value, keys) {
|
|
825
|
+
if (!isPlainRecord(value) || Object.keys(value).sort().join('\0') !== [...keys].sort().join('\0')) {
|
|
826
|
+
throw new Error('native resource rejected');
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
function isPlainRecord(value) {
|
|
830
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
831
|
+
return false;
|
|
832
|
+
const prototype = Object.getPrototypeOf(value);
|
|
833
|
+
return prototype === Object.prototype || prototype === null;
|
|
834
|
+
}
|
|
835
|
+
function exactKeys(value, expected) {
|
|
836
|
+
const keys = Object.keys(value);
|
|
837
|
+
return keys.length === expected.length && expected.every(key => Object.hasOwn(value, key));
|
|
838
|
+
}
|
|
839
|
+
function isErrno(error, code) {
|
|
840
|
+
return typeof error === 'object' && error !== null && Reflect.get(error, 'code') === code;
|
|
841
|
+
}
|
|
842
|
+
function packagedResourcesPath() {
|
|
843
|
+
const value = process.resourcesPath;
|
|
844
|
+
return typeof value === 'string' && value !== '' ? value : null;
|
|
845
|
+
}
|
|
846
|
+
function canonicalDirectory(candidate) {
|
|
847
|
+
try {
|
|
848
|
+
if (!isAbsolute(candidate))
|
|
849
|
+
return null;
|
|
850
|
+
const link = lstatSync(candidate);
|
|
851
|
+
const canonical = realpathSync(candidate);
|
|
852
|
+
if (link.isSymbolicLink() || !link.isDirectory() || canonical !== resolve(candidate))
|
|
853
|
+
return null;
|
|
854
|
+
return canonical;
|
|
855
|
+
}
|
|
856
|
+
catch {
|
|
857
|
+
return null;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
/** Test seam for the host-owned OS temp alias; caller-configured paths stay lexically canonical. */
|
|
861
|
+
export function canonicalSystemTemporaryDirectoryForTest(candidate) {
|
|
862
|
+
try {
|
|
863
|
+
return canonicalDirectory(realpathSync(candidate));
|
|
864
|
+
}
|
|
865
|
+
catch {
|
|
866
|
+
return null;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
function canonicalRegularExecutable(candidate) {
|
|
870
|
+
try {
|
|
871
|
+
if (!isAbsolute(candidate))
|
|
872
|
+
return null;
|
|
873
|
+
const link = lstatSync(candidate);
|
|
874
|
+
const canonical = realpathSync(candidate);
|
|
875
|
+
const info = statSync(canonical);
|
|
876
|
+
if (link.isSymbolicLink()
|
|
877
|
+
|| !info.isFile()
|
|
878
|
+
|| canonical !== resolve(candidate)
|
|
879
|
+
|| (process.platform !== 'win32' && (info.mode & 0o111) === 0))
|
|
880
|
+
return null;
|
|
881
|
+
return canonical;
|
|
882
|
+
}
|
|
883
|
+
catch {
|
|
884
|
+
return null;
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
//# sourceMappingURL=production-host.js.map
|