nova-personal-agent-server 0.0.0-stage → 0.4.1
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,712 @@
|
|
|
1
|
+
import { validateManagedMcpConfig } from './managed-mcp.js';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { CodexProtocolError } from './protocol.js';
|
|
4
|
+
import { snapshotJsonRecord } from './safe-json.js';
|
|
5
|
+
function method(file, fields, required, nullable = [], allowedTypes = {}) {
|
|
6
|
+
return deepFreeze({
|
|
7
|
+
file,
|
|
8
|
+
fields: { ...fields },
|
|
9
|
+
required: [...required],
|
|
10
|
+
...(nullable.length === 0 ? {} : { nullable: [...nullable] }),
|
|
11
|
+
...(Object.keys(allowedTypes).length === 0 ? {} : { allowedTypes }),
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export const APP_SERVER_METHOD_SCHEMAS = deepFreeze({
|
|
15
|
+
initialize: method('v1/InitializeParams.json', { clientInfo: 'object' }, ['clientInfo']),
|
|
16
|
+
'config/read': method('v2/ConfigReadParams.json', { includeLayers: 'boolean', cwd: 'string' }, [], ['cwd']),
|
|
17
|
+
'thread/start': method('v2/ThreadStartParams.json', {
|
|
18
|
+
ephemeral: 'boolean',
|
|
19
|
+
approvalPolicy: 'string',
|
|
20
|
+
approvalsReviewer: 'string',
|
|
21
|
+
permissions: 'string',
|
|
22
|
+
sandbox: 'string',
|
|
23
|
+
developerInstructions: 'string',
|
|
24
|
+
cwd: 'string',
|
|
25
|
+
}, [], ['ephemeral', 'approvalPolicy', 'approvalsReviewer', 'permissions', 'sandbox', 'developerInstructions', 'cwd'], {
|
|
26
|
+
approvalPolicy: ['string', 'object', 'null'],
|
|
27
|
+
}),
|
|
28
|
+
'thread/resume': method('v2/ThreadResumeParams.json', {
|
|
29
|
+
threadId: 'string',
|
|
30
|
+
approvalPolicy: 'string',
|
|
31
|
+
approvalsReviewer: 'string',
|
|
32
|
+
permissions: 'string',
|
|
33
|
+
sandbox: 'string',
|
|
34
|
+
developerInstructions: 'string',
|
|
35
|
+
cwd: 'string',
|
|
36
|
+
}, ['threadId'], ['approvalPolicy', 'approvalsReviewer', 'permissions', 'sandbox', 'developerInstructions', 'cwd'], {
|
|
37
|
+
approvalPolicy: ['string', 'object', 'null'],
|
|
38
|
+
}),
|
|
39
|
+
'mcpServerStatus/list': method('v2/ListMcpServerStatusParams.json', { threadId: 'string', detail: 'string', cursor: 'string', limit: 'integer' }, [], ['threadId', 'detail', 'cursor', 'limit']),
|
|
40
|
+
'turn/start': method('v2/TurnStartParams.json', { threadId: 'string', input: 'array' }, [
|
|
41
|
+
'threadId', 'input',
|
|
42
|
+
]),
|
|
43
|
+
'turn/steer': method('v2/TurnSteerParams.json', {
|
|
44
|
+
threadId: 'string', expectedTurnId: 'string', input: 'array',
|
|
45
|
+
}, ['threadId', 'expectedTurnId', 'input']),
|
|
46
|
+
'turn/interrupt': method('v2/TurnInterruptParams.json', {
|
|
47
|
+
threadId: 'string', turnId: 'string',
|
|
48
|
+
}, ['threadId', 'turnId']),
|
|
49
|
+
'thread/name/set': method('v2/ThreadSetNameParams.json', {
|
|
50
|
+
threadId: 'string', name: 'string',
|
|
51
|
+
}, ['threadId', 'name']),
|
|
52
|
+
});
|
|
53
|
+
const THREAD_NESTED = deepFreeze({
|
|
54
|
+
field: 'thread',
|
|
55
|
+
fields: { id: 'string', cwd: 'string', ephemeral: 'boolean', path: 'string' },
|
|
56
|
+
required: ['id', 'cwd', 'ephemeral'],
|
|
57
|
+
});
|
|
58
|
+
const TURN_NESTED = deepFreeze({
|
|
59
|
+
field: 'turn',
|
|
60
|
+
fields: { id: 'string', items: 'array', status: 'string' },
|
|
61
|
+
required: ['id', 'items', 'status'],
|
|
62
|
+
});
|
|
63
|
+
export const APP_SERVER_INBOUND_SCHEMAS = deepFreeze([
|
|
64
|
+
method('v2/ListMcpServerStatusResponse.json', { data: 'array', nextCursor: 'string' }, ['data'], ['nextCursor']),
|
|
65
|
+
method('v2/ConfigReadResponse.json', { config: 'object', origins: 'object' }, ['config', 'origins']),
|
|
66
|
+
{ ...method('v2/ThreadStartResponse.json', {
|
|
67
|
+
approvalPolicy: 'string', approvalsReviewer: 'string', cwd: 'string', sandbox: 'object', thread: 'object',
|
|
68
|
+
}, ['approvalPolicy', 'approvalsReviewer', 'cwd', 'sandbox', 'thread'], [], {
|
|
69
|
+
approvalPolicy: ['string', 'object'],
|
|
70
|
+
}), nested: THREAD_NESTED },
|
|
71
|
+
{ ...method('v2/ThreadResumeResponse.json', {
|
|
72
|
+
approvalPolicy: 'string',
|
|
73
|
+
approvalsReviewer: 'string',
|
|
74
|
+
cwd: 'string',
|
|
75
|
+
sandbox: 'object',
|
|
76
|
+
thread: 'object',
|
|
77
|
+
}, ['approvalPolicy', 'approvalsReviewer', 'cwd', 'sandbox', 'thread'], [], {
|
|
78
|
+
approvalPolicy: ['string', 'object'],
|
|
79
|
+
}), nested: THREAD_NESTED },
|
|
80
|
+
{ ...method('v2/TurnStartResponse.json', { turn: 'object' }, ['turn']), nested: TURN_NESTED },
|
|
81
|
+
method('v2/TurnSteerResponse.json', { turnId: 'string' }, ['turnId']),
|
|
82
|
+
{ ...method('v2/TurnStartedNotification.json', {
|
|
83
|
+
threadId: 'string', turn: 'object',
|
|
84
|
+
}, ['threadId', 'turn']), nested: TURN_NESTED },
|
|
85
|
+
method('v2/ItemStartedNotification.json', {
|
|
86
|
+
threadId: 'string', turnId: 'string', startedAtMs: 'integer', item: 'object',
|
|
87
|
+
}, ['threadId', 'turnId', 'startedAtMs', 'item']),
|
|
88
|
+
method('v2/ItemCompletedNotification.json', {
|
|
89
|
+
threadId: 'string', turnId: 'string', item: 'object',
|
|
90
|
+
}, ['threadId', 'turnId', 'item']),
|
|
91
|
+
{ ...method('v2/TurnCompletedNotification.json', {
|
|
92
|
+
threadId: 'string', turn: 'object',
|
|
93
|
+
}, ['threadId', 'turn']), nested: TURN_NESTED },
|
|
94
|
+
method('v2/ThreadNameUpdatedNotification.json', {
|
|
95
|
+
threadId: 'string', threadName: 'string',
|
|
96
|
+
}, ['threadId'], ['threadName']),
|
|
97
|
+
]);
|
|
98
|
+
export const APP_SERVER_APPROVAL_SCHEMA_FILES = deepFreeze([
|
|
99
|
+
'ServerRequest.json',
|
|
100
|
+
'FileChangeRequestApprovalParams.json',
|
|
101
|
+
'CommandExecutionRequestApprovalParams.json',
|
|
102
|
+
'FileChangeRequestApprovalResponse.json',
|
|
103
|
+
'CommandExecutionRequestApprovalResponse.json',
|
|
104
|
+
'PermissionsRequestApprovalParams.json',
|
|
105
|
+
'PermissionsRequestApprovalResponse.json',
|
|
106
|
+
]);
|
|
107
|
+
const FILE_APPROVAL_PARAM_FIELDS = deepFreeze({
|
|
108
|
+
grantRoot: 'string',
|
|
109
|
+
itemId: 'string',
|
|
110
|
+
reason: 'string',
|
|
111
|
+
startedAtMs: 'integer',
|
|
112
|
+
threadId: 'string',
|
|
113
|
+
turnId: 'string',
|
|
114
|
+
});
|
|
115
|
+
const FILE_APPROVAL_PARAM_TYPES = deepFreeze({
|
|
116
|
+
grantRoot: ['string', 'null'],
|
|
117
|
+
reason: ['string', 'null'],
|
|
118
|
+
});
|
|
119
|
+
const LEGACY_COMMAND_APPROVAL_PARAM_FIELDS = deepFreeze({
|
|
120
|
+
approvalId: 'string',
|
|
121
|
+
command: 'string',
|
|
122
|
+
commandActions: 'array',
|
|
123
|
+
cwd: 'string',
|
|
124
|
+
environmentId: 'string',
|
|
125
|
+
itemId: 'string',
|
|
126
|
+
networkApprovalContext: 'object',
|
|
127
|
+
proposedExecpolicyAmendment: 'array',
|
|
128
|
+
proposedNetworkPolicyAmendments: 'array',
|
|
129
|
+
reason: 'string',
|
|
130
|
+
startedAtMs: 'integer',
|
|
131
|
+
threadId: 'string',
|
|
132
|
+
turnId: 'string',
|
|
133
|
+
});
|
|
134
|
+
const COMMAND_APPROVAL_PARAM_FIELDS = deepFreeze({
|
|
135
|
+
...LEGACY_COMMAND_APPROVAL_PARAM_FIELDS,
|
|
136
|
+
additionalPermissions: 'object',
|
|
137
|
+
availableDecisions: 'array',
|
|
138
|
+
kind: 'string',
|
|
139
|
+
});
|
|
140
|
+
const COMMAND_APPROVAL_PARAM_TYPES = deepFreeze({
|
|
141
|
+
additionalPermissions: ['object', 'null'],
|
|
142
|
+
availableDecisions: ['array', 'null'],
|
|
143
|
+
approvalId: ['string', 'null'],
|
|
144
|
+
command: ['string', 'null'],
|
|
145
|
+
commandActions: ['array', 'null'],
|
|
146
|
+
cwd: ['string', 'null'],
|
|
147
|
+
environmentId: ['string', 'null'],
|
|
148
|
+
networkApprovalContext: ['object', 'null'],
|
|
149
|
+
proposedExecpolicyAmendment: ['array', 'null'],
|
|
150
|
+
proposedNetworkPolicyAmendments: ['array', 'null'],
|
|
151
|
+
reason: ['string', 'null'],
|
|
152
|
+
});
|
|
153
|
+
const APPROVAL_REQUIRED = deepFreeze(['itemId', 'startedAtMs', 'threadId', 'turnId']);
|
|
154
|
+
export function validateCodexSchemaBundle(bundle) {
|
|
155
|
+
try {
|
|
156
|
+
const bundleSnapshot = snapshotJsonRecord(bundle);
|
|
157
|
+
const client = requireObject(bundleSnapshot['ClientRequest.json']);
|
|
158
|
+
const variants = client.oneOf;
|
|
159
|
+
if (!Array.isArray(variants))
|
|
160
|
+
throw new TypeError('variants');
|
|
161
|
+
const requests = new Map();
|
|
162
|
+
for (const candidate of variants) {
|
|
163
|
+
if (!isPlainObject(candidate))
|
|
164
|
+
continue;
|
|
165
|
+
const properties = candidate.properties;
|
|
166
|
+
if (!isPlainObject(properties))
|
|
167
|
+
continue;
|
|
168
|
+
const methodSchema = properties.method;
|
|
169
|
+
if (!isPlainObject(methodSchema) || !Array.isArray(methodSchema.enum))
|
|
170
|
+
continue;
|
|
171
|
+
if (methodSchema.enum.length !== 1 || typeof methodSchema.enum[0] !== 'string')
|
|
172
|
+
continue;
|
|
173
|
+
requests.set(methodSchema.enum[0], candidate);
|
|
174
|
+
}
|
|
175
|
+
const result = {};
|
|
176
|
+
for (const [name, spec] of Object.entries(APP_SERVER_METHOD_SCHEMAS)) {
|
|
177
|
+
const variant = requests.get(name);
|
|
178
|
+
if (variant === undefined)
|
|
179
|
+
throw new TypeError('missing method');
|
|
180
|
+
requireFields(variant, ['id', 'method', 'params']);
|
|
181
|
+
const properties = requireObject(variant.properties);
|
|
182
|
+
const params = requireObject(properties.params);
|
|
183
|
+
const stem = spec.file.slice(spec.file.lastIndexOf('/') + 1, -'.json'.length);
|
|
184
|
+
if (params.$ref !== `#/definitions/${stem}`)
|
|
185
|
+
throw new TypeError('request reference');
|
|
186
|
+
validateObjectSchema(bundleSnapshot[spec.file], spec.fields, spec.required, undefined, spec.nullable, spec.allowedTypes);
|
|
187
|
+
result[name] = true;
|
|
188
|
+
}
|
|
189
|
+
for (const spec of APP_SERVER_INBOUND_SCHEMAS) {
|
|
190
|
+
const root = requireObject(bundleSnapshot[spec.file]);
|
|
191
|
+
validateObjectSchema(root, spec.fields, spec.required, undefined, spec.nullable, spec.allowedTypes);
|
|
192
|
+
if (spec.nested !== undefined) {
|
|
193
|
+
const properties = requireObject(root.properties);
|
|
194
|
+
const target = resolveLocalSchema(requireObject(properties[spec.nested.field]), root, new Set());
|
|
195
|
+
validateObjectSchema(target, spec.nested.fields, spec.nested.required, root);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
validateApprovalSchemaSurface(bundleSnapshot);
|
|
199
|
+
return deepFreeze(result);
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
throw new CodexProtocolError('unsupported_protocol');
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function validateApprovalSchemaSurface(bundle) {
|
|
206
|
+
const serverRequest = requireObject(bundle['ServerRequest.json']);
|
|
207
|
+
const embeddedCommandKind = validateApprovalServerRequest(serverRequest);
|
|
208
|
+
validateFileApprovalParams(requireObject(bundle['FileChangeRequestApprovalParams.json']));
|
|
209
|
+
const standaloneCommandKind = validateCommandApprovalParams(requireObject(bundle['CommandExecutionRequestApprovalParams.json']));
|
|
210
|
+
if (embeddedCommandKind !== standaloneCommandKind)
|
|
211
|
+
throw new TypeError('approval kind shape');
|
|
212
|
+
validateFileChangeItem(requireObject(bundle['v2/ItemStartedNotification.json']));
|
|
213
|
+
validateDecisionResponse(requireObject(bundle['FileChangeRequestApprovalResponse.json']), 'FileChangeApprovalDecision', ['accept', 'acceptForSession', 'decline', 'cancel'], []);
|
|
214
|
+
validateDecisionResponse(requireObject(bundle['CommandExecutionRequestApprovalResponse.json']), 'CommandExecutionApprovalDecision', ['accept', 'acceptForSession', 'decline', 'cancel'], ['acceptWithExecpolicyAmendment', 'applyNetworkPolicyAmendment']);
|
|
215
|
+
validatePermissionsApprovalParams(requireObject(bundle['PermissionsRequestApprovalParams.json']));
|
|
216
|
+
validatePermissionsApprovalResponse(requireObject(bundle['PermissionsRequestApprovalResponse.json']));
|
|
217
|
+
}
|
|
218
|
+
function validateApprovalServerRequest(root) {
|
|
219
|
+
const variants = root.oneOf;
|
|
220
|
+
if (!Array.isArray(variants))
|
|
221
|
+
throw new TypeError('server request variants');
|
|
222
|
+
for (const [methodName, paramsName] of [
|
|
223
|
+
['item/fileChange/requestApproval', 'FileChangeRequestApprovalParams'],
|
|
224
|
+
['item/commandExecution/requestApproval', 'CommandExecutionRequestApprovalParams'],
|
|
225
|
+
['item/permissions/requestApproval', 'PermissionsRequestApprovalParams'],
|
|
226
|
+
]) {
|
|
227
|
+
const matches = variants.filter(candidate => approvalMethod(candidate) === methodName);
|
|
228
|
+
if (matches.length !== 1)
|
|
229
|
+
throw new TypeError('approval method');
|
|
230
|
+
const variant = requireObject(matches[0]);
|
|
231
|
+
validateExactObjectSchema(variant, { id: 'integer', method: 'string', params: 'object' }, ['id', 'method', 'params'], root, { id: ['string', 'integer'] });
|
|
232
|
+
const properties = requireObject(variant.properties);
|
|
233
|
+
requireReference(requireObject(properties.id), '#/definitions/RequestId');
|
|
234
|
+
requireSingleEnum(requireObject(properties.method), methodName);
|
|
235
|
+
requireReference(requireObject(properties.params), `#/definitions/${paramsName}`);
|
|
236
|
+
}
|
|
237
|
+
const definitions = requireObject(root.definitions);
|
|
238
|
+
const requestId = requireObject(definitions.RequestId);
|
|
239
|
+
requireTypes(requestId, root, ['string', 'integer']);
|
|
240
|
+
validateFileApprovalParams(requireObject(definitions.FileChangeRequestApprovalParams), root);
|
|
241
|
+
const result = validateCommandApprovalParams(requireObject(definitions.CommandExecutionRequestApprovalParams), root);
|
|
242
|
+
validatePermissionsApprovalParams(requireObject(definitions.PermissionsRequestApprovalParams), root);
|
|
243
|
+
return result;
|
|
244
|
+
}
|
|
245
|
+
function validateFileApprovalParams(schema, root = schema) {
|
|
246
|
+
validateExactObjectSchema(schema, FILE_APPROVAL_PARAM_FIELDS, APPROVAL_REQUIRED, root, FILE_APPROVAL_PARAM_TYPES);
|
|
247
|
+
}
|
|
248
|
+
function validateCommandApprovalParams(schema, root = schema) {
|
|
249
|
+
const properties = requireObject(schema.properties);
|
|
250
|
+
const hasKind = Object.hasOwn(properties, 'kind');
|
|
251
|
+
validateExactObjectSchema(schema, hasKind ? COMMAND_APPROVAL_PARAM_FIELDS : LEGACY_COMMAND_APPROVAL_PARAM_FIELDS, APPROVAL_REQUIRED, root, COMMAND_APPROVAL_PARAM_TYPES);
|
|
252
|
+
if (hasKind) {
|
|
253
|
+
const kind = requireObject(properties.kind);
|
|
254
|
+
const kindChoices = kind.allOf;
|
|
255
|
+
if (!Array.isArray(kindChoices) || kindChoices.length !== 1 || kind.default !== 'command') {
|
|
256
|
+
throw new TypeError('approval kind');
|
|
257
|
+
}
|
|
258
|
+
requireReference(requireObject(kindChoices[0]), '#/definitions/CommandExecutionApprovalKind');
|
|
259
|
+
const definitions = requireObject(root.definitions);
|
|
260
|
+
const kindDefinition = requireObject(definitions.CommandExecutionApprovalKind);
|
|
261
|
+
requireTypes(kindDefinition, root, ['string']);
|
|
262
|
+
requireExactEnum(kindDefinition.enum, ['command', 'writeStdin']);
|
|
263
|
+
}
|
|
264
|
+
requireArrayItemReference(properties.commandActions, '#/definitions/CommandAction');
|
|
265
|
+
requireNullableReference(properties.cwd, '#/definitions/LegacyAppPathString');
|
|
266
|
+
requireNullableReference(properties.networkApprovalContext, '#/definitions/NetworkApprovalContext');
|
|
267
|
+
requireArrayItemType(properties.proposedExecpolicyAmendment, 'string');
|
|
268
|
+
requireArrayItemReference(properties.proposedNetworkPolicyAmendments, '#/definitions/NetworkPolicyAmendment');
|
|
269
|
+
requireNullableReference(properties.additionalPermissions, '#/definitions/AdditionalPermissionProfile');
|
|
270
|
+
requireArrayItemReference(properties.availableDecisions, '#/definitions/CommandExecutionApprovalDecision');
|
|
271
|
+
return hasKind;
|
|
272
|
+
}
|
|
273
|
+
function validatePermissionsApprovalParams(schema, root = schema) {
|
|
274
|
+
validateExactObjectSchema(schema, {
|
|
275
|
+
cwd: 'string', environmentId: 'string', itemId: 'string', permissions: 'object', reason: 'string',
|
|
276
|
+
startedAtMs: 'integer', threadId: 'string', turnId: 'string',
|
|
277
|
+
}, ['cwd', 'itemId', 'permissions', 'startedAtMs', 'threadId', 'turnId'], root, {
|
|
278
|
+
environmentId: ['string', 'null'], reason: ['string', 'null'],
|
|
279
|
+
});
|
|
280
|
+
requireReference(requireObject(requireObject(schema.properties).permissions), '#/definitions/RequestPermissionProfile');
|
|
281
|
+
}
|
|
282
|
+
function validatePermissionsApprovalResponse(root) {
|
|
283
|
+
validateExactObjectSchema(root, { permissions: 'object', scope: 'string', strictAutoReview: 'boolean' }, ['permissions'], root, {
|
|
284
|
+
strictAutoReview: ['boolean', 'null'],
|
|
285
|
+
});
|
|
286
|
+
const properties = requireObject(root.properties);
|
|
287
|
+
requireReference(requireObject(properties.permissions), '#/definitions/GrantedPermissionProfile');
|
|
288
|
+
const choices = requireObject(properties.scope).allOf;
|
|
289
|
+
if (!Array.isArray(choices) || choices.length !== 1)
|
|
290
|
+
throw new TypeError('permission scope');
|
|
291
|
+
requireReference(requireObject(choices[0]), '#/definitions/PermissionGrantScope');
|
|
292
|
+
const definition = requireObject(requireObject(root.definitions).PermissionGrantScope);
|
|
293
|
+
requireTypes(definition, root, ['string']);
|
|
294
|
+
requireExactEnum(definition.enum, ['turn', 'session']);
|
|
295
|
+
}
|
|
296
|
+
function validateFileChangeItem(root) {
|
|
297
|
+
const properties = requireObject(root.properties);
|
|
298
|
+
requireReference(requireObject(properties.item), '#/definitions/ThreadItem');
|
|
299
|
+
const definitions = requireObject(root.definitions);
|
|
300
|
+
const threadItem = requireObject(definitions.ThreadItem);
|
|
301
|
+
const choices = threadItem.oneOf;
|
|
302
|
+
if (!Array.isArray(choices))
|
|
303
|
+
throw new TypeError('thread item choices');
|
|
304
|
+
const matches = choices.filter(candidate => {
|
|
305
|
+
if (!isPlainObject(candidate) || !isPlainObject(candidate.properties))
|
|
306
|
+
return false;
|
|
307
|
+
return enumValue(candidate.properties.type) === 'fileChange';
|
|
308
|
+
});
|
|
309
|
+
if (matches.length !== 1)
|
|
310
|
+
throw new TypeError('file change item');
|
|
311
|
+
const fileChange = requireObject(matches[0]);
|
|
312
|
+
validateExactObjectSchema(fileChange, { changes: 'array', id: 'string', status: 'string', type: 'string' }, ['changes', 'id', 'status', 'type'], root);
|
|
313
|
+
const itemProperties = requireObject(fileChange.properties);
|
|
314
|
+
requireArrayItemReference(itemProperties.changes, '#/definitions/FileUpdateChange');
|
|
315
|
+
requireReference(requireObject(itemProperties.status), '#/definitions/PatchApplyStatus');
|
|
316
|
+
requireSingleEnum(requireObject(itemProperties.type), 'fileChange');
|
|
317
|
+
const update = requireObject(definitions.FileUpdateChange);
|
|
318
|
+
validateExactObjectSchema(update, { diff: 'string', kind: 'object', path: 'string' }, ['diff', 'kind', 'path'], root);
|
|
319
|
+
requireReference(requireObject(requireObject(update.properties).kind), '#/definitions/PatchChangeKind');
|
|
320
|
+
const status = requireObject(definitions.PatchApplyStatus);
|
|
321
|
+
requireTypes(status, root, ['string']);
|
|
322
|
+
requireExactEnum(status.enum, ['inProgress', 'completed', 'failed', 'declined']);
|
|
323
|
+
validatePatchChangeKind(requireObject(definitions.PatchChangeKind), root);
|
|
324
|
+
}
|
|
325
|
+
function validatePatchChangeKind(schema, root) {
|
|
326
|
+
const choices = schema.oneOf;
|
|
327
|
+
if (!Array.isArray(choices) || choices.length !== 3)
|
|
328
|
+
throw new TypeError('patch choices');
|
|
329
|
+
for (const kind of ['add', 'delete', 'update']) {
|
|
330
|
+
const matches = choices.filter(candidate => {
|
|
331
|
+
if (!isPlainObject(candidate) || !isPlainObject(candidate.properties))
|
|
332
|
+
return false;
|
|
333
|
+
return enumValue(candidate.properties.type) === kind;
|
|
334
|
+
});
|
|
335
|
+
if (matches.length !== 1)
|
|
336
|
+
throw new TypeError('patch kind');
|
|
337
|
+
const choice = requireObject(matches[0]);
|
|
338
|
+
validateExactObjectSchema(choice, kind === 'update' ? { move_path: 'string', type: 'string' } : { type: 'string' }, ['type'], root, kind === 'update' ? { move_path: ['string', 'null'] } : {});
|
|
339
|
+
requireSingleEnum(requireObject(requireObject(choice.properties).type), kind);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
function validateDecisionResponse(root, definitionName, stringDecisions, objectDecisions) {
|
|
343
|
+
validateExactObjectSchema(root, { decision: 'string' }, ['decision'], root, objectDecisions.length === 0 ? {} : { decision: ['string', 'object'] });
|
|
344
|
+
const decisionField = requireObject(requireObject(root.properties).decision);
|
|
345
|
+
requireReference(decisionField, `#/definitions/${definitionName}`);
|
|
346
|
+
const definition = requireObject(requireObject(root.definitions)[definitionName]);
|
|
347
|
+
const choices = definition.oneOf;
|
|
348
|
+
if (!Array.isArray(choices)
|
|
349
|
+
|| choices.length !== stringDecisions.length + objectDecisions.length) {
|
|
350
|
+
throw new TypeError('decision choices');
|
|
351
|
+
}
|
|
352
|
+
const foundStrings = [];
|
|
353
|
+
const foundObjects = [];
|
|
354
|
+
for (const candidate of choices) {
|
|
355
|
+
const choice = requireObject(candidate);
|
|
356
|
+
if (choice.type === 'string') {
|
|
357
|
+
const value = enumValue(choice);
|
|
358
|
+
if (value === null)
|
|
359
|
+
throw new TypeError('decision enum');
|
|
360
|
+
foundStrings.push(value);
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
if (choice.type !== 'object')
|
|
364
|
+
throw new TypeError('decision type');
|
|
365
|
+
const properties = requireObject(choice.properties);
|
|
366
|
+
const keys = Object.keys(properties);
|
|
367
|
+
if (keys.length !== 1 || choice.additionalProperties !== false) {
|
|
368
|
+
throw new TypeError('object decision');
|
|
369
|
+
}
|
|
370
|
+
validateExactObjectSchema(choice, { [keys[0]]: 'object' }, [keys[0]], root);
|
|
371
|
+
foundObjects.push(keys[0]);
|
|
372
|
+
}
|
|
373
|
+
requireExactEnum(foundStrings, stringDecisions);
|
|
374
|
+
requireExactEnum(foundObjects, objectDecisions);
|
|
375
|
+
}
|
|
376
|
+
function approvalMethod(candidate) {
|
|
377
|
+
if (!isPlainObject(candidate) || !isPlainObject(candidate.properties))
|
|
378
|
+
return null;
|
|
379
|
+
return enumValue(candidate.properties.method);
|
|
380
|
+
}
|
|
381
|
+
function enumValue(candidate) {
|
|
382
|
+
if (!isPlainObject(candidate) || candidate.type !== 'string')
|
|
383
|
+
return null;
|
|
384
|
+
return Array.isArray(candidate.enum)
|
|
385
|
+
&& candidate.enum.length === 1
|
|
386
|
+
&& typeof candidate.enum[0] === 'string'
|
|
387
|
+
? candidate.enum[0]
|
|
388
|
+
: null;
|
|
389
|
+
}
|
|
390
|
+
function validateExactObjectSchema(candidate, fields, required, typeRoot, allowedTypes = {}) {
|
|
391
|
+
validateObjectSchema(candidate, fields, required, typeRoot, [], allowedTypes);
|
|
392
|
+
const schema = requireObject(candidate);
|
|
393
|
+
if (!exactKeys(requireObject(schema.properties), Object.keys(fields))) {
|
|
394
|
+
throw new TypeError('exact properties');
|
|
395
|
+
}
|
|
396
|
+
requireExactEnum(schema.required, required);
|
|
397
|
+
}
|
|
398
|
+
function requireTypes(node, root, expected) {
|
|
399
|
+
const found = schemaTypes(node, root, new Set());
|
|
400
|
+
if (found.size !== expected.length || expected.some(type => !found.has(type))) {
|
|
401
|
+
throw new TypeError('exact types');
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
function requireReference(node, expected) {
|
|
405
|
+
if (node.$ref !== expected)
|
|
406
|
+
throw new TypeError('exact reference');
|
|
407
|
+
}
|
|
408
|
+
function requireNullableReference(candidate, reference) {
|
|
409
|
+
const choices = requireObject(candidate).anyOf;
|
|
410
|
+
if (!Array.isArray(choices) || choices.length !== 2)
|
|
411
|
+
throw new TypeError('nullable reference');
|
|
412
|
+
const references = choices.filter(choice => isPlainObject(choice) && choice.$ref === reference);
|
|
413
|
+
const nulls = choices.filter(choice => isPlainObject(choice) && choice.type === 'null');
|
|
414
|
+
if (references.length !== 1 || nulls.length !== 1)
|
|
415
|
+
throw new TypeError('nullable reference');
|
|
416
|
+
}
|
|
417
|
+
function requireArrayItemReference(candidate, reference) {
|
|
418
|
+
const items = requireObject(requireObject(candidate).items);
|
|
419
|
+
requireReference(items, reference);
|
|
420
|
+
}
|
|
421
|
+
function requireArrayItemType(candidate, type) {
|
|
422
|
+
const items = requireObject(requireObject(candidate).items);
|
|
423
|
+
if (items.type !== type)
|
|
424
|
+
throw new TypeError('array item type');
|
|
425
|
+
}
|
|
426
|
+
function requireSingleEnum(node, expected) {
|
|
427
|
+
if (node.type !== 'string')
|
|
428
|
+
throw new TypeError('enum type');
|
|
429
|
+
requireExactEnum(node.enum, [expected]);
|
|
430
|
+
}
|
|
431
|
+
function requireExactEnum(candidate, expected) {
|
|
432
|
+
if (!Array.isArray(candidate)
|
|
433
|
+
|| candidate.length !== expected.length
|
|
434
|
+
|| candidate.some(value => typeof value !== 'string'))
|
|
435
|
+
throw new TypeError('exact enum');
|
|
436
|
+
const found = new Set(candidate);
|
|
437
|
+
if (found.size !== expected.length || expected.some(value => !found.has(value))) {
|
|
438
|
+
throw new TypeError('exact enum');
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
function validateObjectSchema(candidate, fields, required, typeRoot, nullable = [], allowedTypes = {}) {
|
|
442
|
+
const schema = requireObject(candidate);
|
|
443
|
+
if (schema.type !== 'object')
|
|
444
|
+
throw new TypeError('object type');
|
|
445
|
+
requireFields(schema, required);
|
|
446
|
+
const properties = requireObject(schema.properties);
|
|
447
|
+
const root = typeRoot ?? schema;
|
|
448
|
+
const nullableFields = new Set(nullable);
|
|
449
|
+
if (nullable.some(field => !Object.hasOwn(fields, field)))
|
|
450
|
+
throw new TypeError('nullable field');
|
|
451
|
+
if (Object.keys(allowedTypes).some(field => !Object.hasOwn(fields, field))) {
|
|
452
|
+
throw new TypeError('allowed type field');
|
|
453
|
+
}
|
|
454
|
+
for (const [field, expected] of Object.entries(fields)) {
|
|
455
|
+
const types = schemaTypes(requireObject(properties[field]), root, new Set());
|
|
456
|
+
const explicitlyAllowed = allowedTypes[field];
|
|
457
|
+
if (explicitlyAllowed !== undefined) {
|
|
458
|
+
const wanted = new Set(explicitlyAllowed);
|
|
459
|
+
if (wanted.size !== explicitlyAllowed.length
|
|
460
|
+
|| types.size !== wanted.size
|
|
461
|
+
|| [...wanted].some(type => !types.has(type)))
|
|
462
|
+
throw new TypeError('field type');
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
465
|
+
const permitsNullable = (field === 'path' || nullableFields.has(field))
|
|
466
|
+
&& types.size === 2
|
|
467
|
+
&& types.has(expected)
|
|
468
|
+
&& types.has('null');
|
|
469
|
+
if (!(types.size === 1 && types.has(expected)) && !permitsNullable) {
|
|
470
|
+
throw new TypeError('field type');
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
function requireFields(schema, wanted) {
|
|
475
|
+
const required = schema.required ?? [];
|
|
476
|
+
if (!Array.isArray(required) || required.some(value => typeof value !== 'string')) {
|
|
477
|
+
throw new TypeError('required');
|
|
478
|
+
}
|
|
479
|
+
const found = new Set(required);
|
|
480
|
+
if (wanted.some(field => !found.has(field)))
|
|
481
|
+
throw new TypeError('missing required');
|
|
482
|
+
}
|
|
483
|
+
function schemaTypes(node, root, stack) {
|
|
484
|
+
const found = new Set();
|
|
485
|
+
if (typeof node.type === 'string')
|
|
486
|
+
found.add(node.type);
|
|
487
|
+
else if (Array.isArray(node.type)) {
|
|
488
|
+
for (const item of node.type) {
|
|
489
|
+
if (typeof item !== 'string')
|
|
490
|
+
throw new TypeError('type');
|
|
491
|
+
found.add(item);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (node.$ref !== undefined) {
|
|
495
|
+
const reference = requireLocalReference(node.$ref);
|
|
496
|
+
if (stack.has(reference))
|
|
497
|
+
throw new TypeError('recursive');
|
|
498
|
+
const next = new Set(stack);
|
|
499
|
+
next.add(reference);
|
|
500
|
+
const target = localReferenceTarget(reference, root);
|
|
501
|
+
for (const type of schemaTypes(target, root, next))
|
|
502
|
+
found.add(type);
|
|
503
|
+
}
|
|
504
|
+
for (const keyword of ['anyOf', 'oneOf', 'allOf']) {
|
|
505
|
+
const choices = node[keyword];
|
|
506
|
+
if (choices === undefined)
|
|
507
|
+
continue;
|
|
508
|
+
if (!Array.isArray(choices) || choices.length === 0)
|
|
509
|
+
throw new TypeError('choice');
|
|
510
|
+
for (const choice of choices) {
|
|
511
|
+
for (const type of schemaTypes(requireObject(choice), root, new Set(stack)))
|
|
512
|
+
found.add(type);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
if (found.size === 0)
|
|
516
|
+
throw new TypeError('missing type');
|
|
517
|
+
return found;
|
|
518
|
+
}
|
|
519
|
+
function resolveLocalSchema(node, root, stack) {
|
|
520
|
+
const reference = requireLocalReference(node.$ref);
|
|
521
|
+
if (stack.has(reference))
|
|
522
|
+
throw new TypeError('recursive');
|
|
523
|
+
stack.add(reference);
|
|
524
|
+
const target = localReferenceTarget(reference, root);
|
|
525
|
+
return target.$ref === undefined ? target : resolveLocalSchema(target, root, stack);
|
|
526
|
+
}
|
|
527
|
+
function requireLocalReference(value) {
|
|
528
|
+
if (typeof value !== 'string' || !value.startsWith('#/definitions/')) {
|
|
529
|
+
throw new TypeError('reference');
|
|
530
|
+
}
|
|
531
|
+
const name = value.slice('#/definitions/'.length);
|
|
532
|
+
if (name === '' || name.includes('/'))
|
|
533
|
+
throw new TypeError('reference');
|
|
534
|
+
return value;
|
|
535
|
+
}
|
|
536
|
+
function localReferenceTarget(reference, root) {
|
|
537
|
+
const definitions = requireObject(root.definitions);
|
|
538
|
+
const name = reference.slice('#/definitions/'.length);
|
|
539
|
+
return requireObject(definitions[name]);
|
|
540
|
+
}
|
|
541
|
+
const ROOTS = deepFreeze({
|
|
542
|
+
'.': 'write', '.git': 'read', '.agents': 'read', '.codex': 'read',
|
|
543
|
+
});
|
|
544
|
+
const DISABLED_FEATURES = deepFreeze([
|
|
545
|
+
'hooks',
|
|
546
|
+
'apps',
|
|
547
|
+
'multi_agent',
|
|
548
|
+
'plugins',
|
|
549
|
+
'remote_plugin',
|
|
550
|
+
'plugin_sharing',
|
|
551
|
+
'tool_suggest',
|
|
552
|
+
'remote_control',
|
|
553
|
+
]);
|
|
554
|
+
const SAFE_OPTIONAL_FEATURES = new Set([
|
|
555
|
+
'auth_elicitation',
|
|
556
|
+
'mentions_v2',
|
|
557
|
+
]);
|
|
558
|
+
export function validateEffectiveCodexConfig(response, workspace, options) {
|
|
559
|
+
try {
|
|
560
|
+
const envelope = snapshotJsonRecord(response);
|
|
561
|
+
if (truthy(envelope.warnings) || truthy(envelope.requirements))
|
|
562
|
+
throw new TypeError('diagnostic');
|
|
563
|
+
const config = requireObject(envelope.config);
|
|
564
|
+
const yolo = options.launchProfile?.id === 'yolo';
|
|
565
|
+
if (options.launchProfile !== undefined
|
|
566
|
+
&& (config.approval_policy !== options.launchProfile.thread.approvalPolicy
|
|
567
|
+
|| config.approvals_reviewer !== 'user')) {
|
|
568
|
+
throw new TypeError('approval');
|
|
569
|
+
}
|
|
570
|
+
if (yolo ? config.default_permissions !== null && config.default_permissions !== undefined
|
|
571
|
+
: config.default_permissions !== 'nova_personal_agent')
|
|
572
|
+
throw new TypeError('permissions');
|
|
573
|
+
if (config.web_search !== 'disabled')
|
|
574
|
+
throw new TypeError('web');
|
|
575
|
+
if (config.cwd !== undefined && (typeof config.cwd !== 'string' || resolve(config.cwd) !== resolve(workspace)))
|
|
576
|
+
throw new TypeError('cwd');
|
|
577
|
+
// Live 0.152.0 reports an unset `permissions` table as `null`, not `{}` (observed 2026-09-04).
|
|
578
|
+
const permissions = requireObject(yolo && config.permissions === null ? {} : config.permissions);
|
|
579
|
+
if (yolo) {
|
|
580
|
+
if ((!options.sharedHome && Object.keys(permissions).length !== 0) || config.sandbox_mode !== 'danger-full-access') {
|
|
581
|
+
throw new TypeError('permission profiles');
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
else {
|
|
585
|
+
if (!options.sharedHome && !exactKeys(permissions, ['nova_personal_agent']))
|
|
586
|
+
throw new TypeError('permission profiles');
|
|
587
|
+
const profile = requireObject(permissions.nova_personal_agent);
|
|
588
|
+
if (!requiredKeysWithNullExtras(profile, ['filesystem', 'network']))
|
|
589
|
+
throw new TypeError('profile');
|
|
590
|
+
const filesystem = requireObject(profile.filesystem);
|
|
591
|
+
if (!requiredKeysWithNullExtras(filesystem, [':root', ':workspace_roots'])) {
|
|
592
|
+
throw new TypeError('filesystem');
|
|
593
|
+
}
|
|
594
|
+
if (filesystem[':root'] !== 'read')
|
|
595
|
+
throw new TypeError('root');
|
|
596
|
+
const roots = requireObject(filesystem[':workspace_roots']);
|
|
597
|
+
if (!exactStringRecord(roots, ROOTS))
|
|
598
|
+
throw new TypeError('roots');
|
|
599
|
+
const network = requireObject(profile.network);
|
|
600
|
+
if (!requiredKeysWithNullExtras(network, ['enabled']) || network.enabled !== false) {
|
|
601
|
+
throw new TypeError('network');
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
const shell = { ...requireObject(config.shell_environment_policy) };
|
|
605
|
+
if (options.sharedHome) {
|
|
606
|
+
if (shell.set != null && Object.values(requireObject(shell.set)).some(value => value !== ''))
|
|
607
|
+
throw new TypeError('shell set');
|
|
608
|
+
if (shell.experimental_use_profile === true || shell.ignore_default_excludes === true)
|
|
609
|
+
throw new TypeError('shell profile');
|
|
610
|
+
delete shell.set;
|
|
611
|
+
delete shell.exclude;
|
|
612
|
+
delete shell.experimental_use_profile;
|
|
613
|
+
delete shell.ignore_default_excludes;
|
|
614
|
+
}
|
|
615
|
+
if (!requiredKeysWithNullExtras(shell, ['inherit', 'include_only'])
|
|
616
|
+
|| shell.inherit !== 'core' || !exactStringArray(shell.include_only, ['PATH', 'LANG', 'LC_ALL', 'TERM']))
|
|
617
|
+
throw new TypeError('shell');
|
|
618
|
+
const features = requireObject(config.features);
|
|
619
|
+
for (const name of DISABLED_FEATURES) {
|
|
620
|
+
if (!Object.hasOwn(features, name) || features[name] !== false)
|
|
621
|
+
throw new TypeError('feature');
|
|
622
|
+
}
|
|
623
|
+
for (const [name, enabled] of Object.entries(features)) {
|
|
624
|
+
if (DISABLED_FEATURES.includes(name))
|
|
625
|
+
continue;
|
|
626
|
+
if (SAFE_OPTIONAL_FEATURES.has(name)) {
|
|
627
|
+
if (enabled !== true && enabled !== false && enabled !== null)
|
|
628
|
+
throw new TypeError('feature');
|
|
629
|
+
}
|
|
630
|
+
else if (enabled !== false && enabled !== null) {
|
|
631
|
+
throw new TypeError('feature');
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
const mcp = { ...requireObject(config.mcp_servers) };
|
|
635
|
+
if (options.sharedHome)
|
|
636
|
+
for (const [name, entry] of Object.entries(mcp)) {
|
|
637
|
+
if (!Object.hasOwn(options.managedMcp?.servers ?? {}, name) && requireObject(entry).enabled === false)
|
|
638
|
+
delete mcp[name];
|
|
639
|
+
}
|
|
640
|
+
validateManagedMcpConfig(mcp, options.managedMcp);
|
|
641
|
+
const replacement = config.model_instructions_file;
|
|
642
|
+
if (!options.allowReplacementInstructions && replacement !== null && replacement !== undefined) {
|
|
643
|
+
throw new TypeError('instructions');
|
|
644
|
+
}
|
|
645
|
+
if (options.allowReplacementInstructions
|
|
646
|
+
&& replacement !== null
|
|
647
|
+
&& replacement !== undefined
|
|
648
|
+
&& (typeof replacement !== 'string' || replacement === ''))
|
|
649
|
+
throw new TypeError('instructions');
|
|
650
|
+
return deepFreeze({
|
|
651
|
+
default_permissions: yolo ? null : 'nova_personal_agent',
|
|
652
|
+
filesystem: yolo ? 'full_access' : 'workspace_only',
|
|
653
|
+
network: yolo ? 'unrestricted' : 'blocked',
|
|
654
|
+
web_search: 'disabled',
|
|
655
|
+
shell_environment: 'core_include_only',
|
|
656
|
+
extensions: 'disabled',
|
|
657
|
+
mcp: Object.keys(options.managedMcp?.servers ?? {}).length === 0 ? 'empty' : 'managed',
|
|
658
|
+
instructions: options.allowReplacementInstructions ? 'replacement' : 'builtin',
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
catch {
|
|
662
|
+
throw new CodexProtocolError('config_not_isolated');
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
function truthy(value) {
|
|
666
|
+
if (value === null || value === undefined || value === false || value === 0 || value === '')
|
|
667
|
+
return false;
|
|
668
|
+
if (Array.isArray(value))
|
|
669
|
+
return value.length > 0;
|
|
670
|
+
if (isPlainObject(value))
|
|
671
|
+
return Object.keys(value).length > 0;
|
|
672
|
+
return true;
|
|
673
|
+
}
|
|
674
|
+
function exactStringArray(value, expected) {
|
|
675
|
+
return Array.isArray(value)
|
|
676
|
+
&& value.length === expected.length
|
|
677
|
+
&& value.every((item, index) => item === expected[index]);
|
|
678
|
+
}
|
|
679
|
+
function exactStringRecord(value, expected) {
|
|
680
|
+
const keys = Object.keys(value);
|
|
681
|
+
const expectedKeys = Object.keys(expected);
|
|
682
|
+
return keys.length === expectedKeys.length
|
|
683
|
+
&& expectedKeys.every(key => Object.hasOwn(value, key) && value[key] === expected[key]);
|
|
684
|
+
}
|
|
685
|
+
function exactKeys(value, expected) {
|
|
686
|
+
const keys = Object.keys(value);
|
|
687
|
+
return keys.length === expected.length && expected.every(key => Object.hasOwn(value, key));
|
|
688
|
+
}
|
|
689
|
+
function requiredKeysWithNullExtras(value, required) {
|
|
690
|
+
const requiredSet = new Set(required);
|
|
691
|
+
return required.every(key => Object.hasOwn(value, key))
|
|
692
|
+
&& Object.entries(value).every(([key, field]) => requiredSet.has(key) || field === null);
|
|
693
|
+
}
|
|
694
|
+
function requireObject(value) {
|
|
695
|
+
if (!isPlainObject(value))
|
|
696
|
+
throw new TypeError('object');
|
|
697
|
+
return value;
|
|
698
|
+
}
|
|
699
|
+
function isPlainObject(value) {
|
|
700
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
701
|
+
return false;
|
|
702
|
+
const prototype = Object.getPrototypeOf(value);
|
|
703
|
+
return prototype === Object.prototype || prototype === null;
|
|
704
|
+
}
|
|
705
|
+
function deepFreeze(value) {
|
|
706
|
+
if (typeof value !== 'object' || value === null || Object.isFrozen(value))
|
|
707
|
+
return value;
|
|
708
|
+
for (const child of Object.values(value))
|
|
709
|
+
deepFreeze(child);
|
|
710
|
+
return Object.freeze(value);
|
|
711
|
+
}
|
|
712
|
+
//# sourceMappingURL=app-server-schema.js.map
|