@phuetz/code-buddy 2.0.0 → 2.2.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/README.fr.md +56 -0
- package/README.md +74 -16
- package/codebuddy-runtime.json +5 -5
- package/dist/agent/codebuddy-agent.d.ts +18 -0
- package/dist/agent/codebuddy-agent.js +45 -8
- package/dist/agent/execution/agent-executor.d.ts +0 -9
- package/dist/agent/execution/agent-executor.js +176 -12
- package/dist/agent/execution/context-pipeline.d.ts +9 -0
- package/dist/agent/execution/context-pipeline.js +64 -2
- package/dist/agent/execution/tool-loop-guard.d.ts +76 -0
- package/dist/agent/execution/tool-loop-guard.js +165 -0
- package/dist/agent/execution/tool-selection-strategy.d.ts +7 -0
- package/dist/agent/execution/tool-selection-strategy.js +32 -2
- package/dist/agent/facades/session-facade.d.ts +0 -6
- package/dist/agent/facades/session-facade.js +0 -45
- package/dist/agent/hermes-claw-migrate.d.ts +0 -21
- package/dist/agent/hermes-claw-migrate.js +9 -4
- package/dist/agent/hermes-protocol-gateways.js +8 -1
- package/dist/agent/repo-profiler.js +17 -4
- package/dist/agent/self-improvement/authored-tool-runtime.js +10 -2
- package/dist/agent/self-improvement/evolution/ast-novelty.d.ts +5 -0
- package/dist/agent/self-improvement/evolution/ast-novelty.js +58 -23
- package/dist/agent/self-improvement/evolution/code-variant-store.d.ts +3 -0
- package/dist/agent/self-improvement/evolution/evolution-engine.js +2 -0
- package/dist/agent/self-improvement/evolution/protected-paths.js +6 -0
- package/dist/agent/self-improvement/evolution/variant-fitness.d.ts +13 -2
- package/dist/agent/self-improvement/evolution/variant-fitness.js +184 -58
- package/dist/agent/self-improvement/evolution/worktree-scorer.d.ts +2 -0
- package/dist/agent/self-improvement/evolution/worktree-scorer.js +15 -0
- package/dist/agent/self-improvement/evolutionary-archive.d.ts +2 -1
- package/dist/agent/self-improvement/evolutionary-archive.js +34 -5
- package/dist/agent/self-improvement/proposal-store.d.ts +1 -0
- package/dist/agent/self-improvement/proposal-store.js +79 -17
- package/dist/agent/self-improvement/skill-apply-journal.d.ts +44 -0
- package/dist/agent/self-improvement/skill-apply-journal.js +178 -0
- package/dist/agent/self-improvement/skill-behavior-benchmark.d.ts +3 -0
- package/dist/agent/self-improvement/skill-behavior-benchmark.js +19 -0
- package/dist/agent/self-improvement/skill-behavior-gate.d.ts +34 -0
- package/dist/agent/self-improvement/skill-behavior-gate.js +96 -0
- package/dist/agent/self-improvement/skill-engine.d.ts +22 -0
- package/dist/agent/self-improvement/skill-engine.js +385 -13
- package/dist/agent/self-improvement/skill-gate.d.ts +2 -0
- package/dist/agent/self-improvement/skill-gate.js +17 -2
- package/dist/agent/self-improvement/skill-mutator.d.ts +6 -1
- package/dist/agent/self-improvement/skill-mutator.js +51 -15
- package/dist/agent/self-improvement/skill-types.d.ts +2 -1
- package/dist/agent/self-improvement/types.d.ts +11 -0
- package/dist/agent/tool-handler.d.ts +1 -1
- package/dist/agent/tool-handler.js +28 -9
- package/dist/auth/profile-manager.js +1 -1
- package/dist/channels/companion-channel-turn.d.ts +53 -4
- package/dist/channels/companion-channel-turn.js +218 -16
- package/dist/channels/slash-parity.d.ts +4 -6
- package/dist/channels/slash-parity.js +9 -44
- package/dist/cli/session-commands.d.ts +9 -0
- package/dist/cli/session-commands.js +45 -5
- package/dist/cli/session-picker.d.ts +43 -0
- package/dist/cli/session-picker.js +128 -0
- package/dist/codebuddy/a2a-call-tool-defs.d.ts +26 -0
- package/dist/codebuddy/a2a-call-tool-defs.js +12 -0
- package/dist/codebuddy/fleet-tool-defs.d.ts +2 -0
- package/dist/codebuddy/fleet-tool-defs.js +55 -0
- package/dist/codebuddy/providers/chatgpt-headers.d.ts +18 -0
- package/dist/codebuddy/providers/chatgpt-headers.js +37 -0
- package/dist/codebuddy/providers/provider-chatgpt-responses.d.ts +2 -1
- package/dist/codebuddy/providers/provider-chatgpt-responses.js +10 -23
- package/dist/codebuddy/providers/provider-openai-compat.d.ts +7 -0
- package/dist/codebuddy/providers/provider-openai-compat.js +29 -1
- package/dist/codebuddy/ragchat-tool-defs.d.ts +31 -0
- package/dist/codebuddy/ragchat-tool-defs.js +19 -0
- package/dist/codebuddy/resource-catalog-tool-defs.d.ts +28 -0
- package/dist/codebuddy/resource-catalog-tool-defs.js +18 -0
- package/dist/codebuddy/tool-definitions/agent-tools.js +2 -2
- package/dist/codebuddy/tool-definitions/code-exec-tools.js +5 -1
- package/dist/codebuddy/tool-definitions/cron-tools.js +6 -0
- package/dist/codebuddy/tool-definitions/self-describe-tools.js +6 -1
- package/dist/codebuddy/tools.d.ts +0 -6
- package/dist/codebuddy/tools.js +25 -3
- package/dist/commands/cli/daemon-commands.js +3 -1
- package/dist/commands/cli/evolve-command.js +21 -5
- package/dist/commands/cli/fleet-collaboration-commands.d.ts +2 -0
- package/dist/commands/cli/fleet-collaboration-commands.js +57 -0
- package/dist/commands/cli/fleet-commands.js +29 -0
- package/dist/commands/cli/fleet-mission-commands.d.ts +3 -0
- package/dist/commands/cli/fleet-mission-commands.js +72 -0
- package/dist/commands/cli/fleet-rooms-commands.d.ts +10 -0
- package/dist/commands/cli/fleet-rooms-commands.js +289 -0
- package/dist/commands/cli/tools-commands.js +2 -1
- package/dist/commands/cli/triage-command.d.ts +8 -0
- package/dist/commands/cli/triage-command.js +72 -0
- package/dist/commands/cli/utility-commands.js +25 -1
- package/dist/commands/client-dispatcher.d.ts +7 -0
- package/dist/commands/client-dispatcher.js +73 -21
- package/dist/commands/cron-cli/index.d.ts +3 -1
- package/dist/commands/cron-cli/index.js +25 -0
- package/dist/commands/device-auth.d.ts +10 -0
- package/dist/commands/device-auth.js +91 -0
- package/dist/commands/enhanced-command-handler.d.ts +9 -0
- package/dist/commands/enhanced-command-handler.js +28 -6
- package/dist/commands/handlers/agent-handlers.d.ts +1 -1
- package/dist/commands/handlers/agent-handlers.js +4 -4
- package/dist/commands/handlers/channel-handlers.js +53 -2
- package/dist/commands/handlers/export-handlers.d.ts +3 -2
- package/dist/commands/handlers/export-handlers.js +55 -28
- package/dist/commands/handlers/extra-handlers.js +5 -1
- package/dist/commands/handlers/grill-me-handler.js +26 -18
- package/dist/commands/handlers/memory-handlers.d.ts +6 -2
- package/dist/commands/handlers/memory-handlers.js +35 -15
- package/dist/commands/handlers/missing-handlers.d.ts +2 -2
- package/dist/commands/handlers/missing-handlers.js +12 -4
- package/dist/commands/handlers/resources-handler.d.ts +12 -0
- package/dist/commands/handlers/resources-handler.js +52 -0
- package/dist/commands/handlers/starter-handlers.d.ts +1 -1
- package/dist/commands/handlers/starter-handlers.js +32 -2
- package/dist/commands/handlers/switch-handler.d.ts +1 -1
- package/dist/commands/handlers/switch-handler.js +15 -0
- package/dist/commands/handlers/test-handlers.js +4 -86
- package/dist/commands/handlers/ui-handlers.js +11 -5
- package/dist/commands/login-chatgpt.d.ts +8 -0
- package/dist/commands/login-chatgpt.js +17 -0
- package/dist/commands/mcp-import.d.ts +11 -0
- package/dist/commands/mcp-import.js +67 -0
- package/dist/commands/mcp-invoke.d.ts +2 -0
- package/dist/commands/mcp-invoke.js +68 -0
- package/dist/commands/mcp.d.ts +13 -0
- package/dist/commands/mcp.js +66 -21
- package/dist/commands/pipeline.d.ts +7 -1
- package/dist/commands/pipeline.js +104 -7
- package/dist/commands/resources.d.ts +2 -0
- package/dist/commands/resources.js +64 -0
- package/dist/commands/skills-cli/index.js +35 -12
- package/dist/commands/slash/builtin-commands.js +16 -3
- package/dist/commands/slash/index.d.ts +3 -1
- package/dist/commands/slash/index.js +2 -0
- package/dist/commands/slash/surfaces.d.ts +53 -0
- package/dist/commands/slash/surfaces.js +177 -0
- package/dist/commands/slash/types.d.ts +17 -0
- package/dist/commands/try.d.ts +1 -1
- package/dist/commands/try.js +1 -1
- package/dist/companion/companion-identity.d.ts +43 -0
- package/dist/companion/companion-identity.js +136 -0
- package/dist/companion/companion-toolset.d.ts +66 -0
- package/dist/companion/companion-toolset.js +368 -0
- package/dist/companion/companion-turn.d.ts +10 -2
- package/dist/companion/companion-turn.js +38 -1
- package/dist/config/code-exec-policy.d.ts +25 -0
- package/dist/config/code-exec-policy.js +39 -0
- package/dist/config/model-tools.d.ts +9 -0
- package/dist/config/model-tools.js +103 -0
- package/dist/context/context-manager-v2.js +2 -2
- package/dist/context/lm-resizer-compressor.js +3 -2
- package/dist/context/lm-resizer-diagnostics.d.ts +9 -0
- package/dist/context/lm-resizer-diagnostics.js +30 -0
- package/dist/context/tool-output-masking.js +3 -4
- package/dist/curator/curator.d.ts +6 -0
- package/dist/curator/curator.js +53 -3
- package/dist/daemon/cron-agent-bridge.d.ts +6 -0
- package/dist/daemon/cron-agent-bridge.js +31 -4
- package/dist/doctor/index.d.ts +11 -2
- package/dist/doctor/index.js +84 -21
- package/dist/doctor/integrations.d.ts +197 -0
- package/dist/doctor/integrations.js +241 -0
- package/dist/doctor/triage.d.ts +108 -0
- package/dist/doctor/triage.js +304 -0
- package/dist/errors/crash-handler.js +2 -0
- package/dist/fleet/collaboration.d.ts +44 -0
- package/dist/fleet/collaboration.js +170 -0
- package/dist/fleet/fleet-listener.d.ts +1 -0
- package/dist/fleet/fleet-listener.js +87 -46
- package/dist/fleet/fleet-registry.d.ts +2 -0
- package/dist/fleet/resource-catalog.d.ts +245 -0
- package/dist/fleet/resource-catalog.js +211 -0
- package/dist/fleet/rooms/room-access.d.ts +138 -0
- package/dist/fleet/rooms/room-access.js +196 -0
- package/dist/fleet/rooms/room-client.d.ts +158 -0
- package/dist/fleet/rooms/room-client.js +685 -0
- package/dist/fleet/rooms/room-event.d.ts +139 -0
- package/dist/fleet/rooms/room-event.js +330 -0
- package/dist/fleet/rooms/room-filter.d.ts +48 -0
- package/dist/fleet/rooms/room-filter.js +152 -0
- package/dist/fleet/rooms/room-hub.d.ts +154 -0
- package/dist/fleet/rooms/room-hub.js +363 -0
- package/dist/fleet/rooms/room-identity.d.ts +26 -0
- package/dist/fleet/rooms/room-identity.js +82 -0
- package/dist/fleet/rooms/room-lock.d.ts +34 -0
- package/dist/fleet/rooms/room-lock.js +180 -0
- package/dist/fleet/rooms/room-observations.d.ts +7 -0
- package/dist/fleet/rooms/room-observations.js +61 -0
- package/dist/fleet/rooms/room-server.d.ts +28 -0
- package/dist/fleet/rooms/room-server.js +75 -0
- package/dist/fleet/rooms/room-store.d.ts +119 -0
- package/dist/fleet/rooms/room-store.js +448 -0
- package/dist/fleet/rooms/room-ws-bridge.d.ts +27 -0
- package/dist/fleet/rooms/room-ws-bridge.js +137 -0
- package/dist/fleet/sensory-mission-bridge.d.ts +42 -0
- package/dist/fleet/sensory-mission-bridge.js +136 -0
- package/dist/git/worktree-sessions.js +1 -0
- package/dist/harness/contract.d.ts +4 -4
- package/dist/harness/fleet-supervisor.d.ts +16 -0
- package/dist/harness/fleet-supervisor.js +64 -0
- package/dist/harness/index.d.ts +4 -0
- package/dist/harness/index.js +4 -0
- package/dist/harness/mission-runner.d.ts +3 -0
- package/dist/harness/mission-runner.js +53 -0
- package/dist/harness/mission-store.d.ts +93 -0
- package/dist/harness/mission-store.js +297 -0
- package/dist/harness/tool-harness.d.ts +56 -0
- package/dist/harness/tool-harness.js +153 -0
- package/dist/hooks/use-enhanced-input.js +48 -4
- package/dist/hooks/use-input-handler.d.ts +1 -0
- package/dist/hooks/use-input-handler.js +82 -22
- package/dist/hooks/use-input-history.js +1 -0
- package/dist/identity/lisa-introspection.js +5 -2
- package/dist/identity/operational-self-model.d.ts +2 -0
- package/dist/identity/operational-self-model.js +4 -0
- package/dist/index.js +52 -6
- package/dist/mcp/client.d.ts +11 -0
- package/dist/mcp/client.js +68 -3
- package/dist/mcp/config.d.ts +20 -0
- package/dist/mcp/config.js +121 -8
- package/dist/mcp/import-normalize.d.ts +12 -0
- package/dist/mcp/import-normalize.js +114 -0
- package/dist/mcp/mcp-oauth-constants.d.ts +8 -0
- package/dist/mcp/mcp-oauth-constants.js +9 -0
- package/dist/mcp/mcp-oauth-provider.d.ts +80 -0
- package/dist/mcp/mcp-oauth-provider.js +241 -0
- package/dist/mcp/mcp-oauth.d.ts +60 -1
- package/dist/mcp/mcp-oauth.js +241 -65
- package/dist/mcp/transports.d.ts +14 -5
- package/dist/mcp/transports.js +112 -101
- package/dist/mcp/types.d.ts +5 -0
- package/dist/media/comfyui-recipe-contract.d.ts +7 -7
- package/dist/memory/facts-memory.d.ts +11 -1
- package/dist/memory/facts-memory.js +47 -8
- package/dist/memory/memory-candidate-queue.d.ts +2 -2
- package/dist/memory/memory-candidate-queue.js +6 -6
- package/dist/memory/persistent-memory.d.ts +13 -8
- package/dist/memory/persistent-memory.js +77 -30
- package/dist/nodes/device-node.js +5 -9
- package/dist/observability/mobile-supervision-gateway-contract.js +20 -7
- package/dist/observability/run-event-writer.d.ts +21 -0
- package/dist/observability/run-event-writer.js +81 -0
- package/dist/observability/run-store.d.ts +5 -0
- package/dist/observability/run-store.js +18 -13
- package/dist/observability/run-trajectory.js +1 -1
- package/dist/optimization/prompt-cache.d.ts +19 -2
- package/dist/optimization/prompt-cache.js +41 -6
- package/dist/orchestration/orchestrator.d.ts +21 -0
- package/dist/orchestration/orchestrator.js +122 -15
- package/dist/persistence/session-content.d.ts +8 -0
- package/dist/persistence/session-content.js +76 -0
- package/dist/persistence/session-handoff.d.ts +64 -0
- package/dist/persistence/session-handoff.js +80 -0
- package/dist/persistence/session-history.d.ts +4 -0
- package/dist/persistence/session-history.js +38 -0
- package/dist/persistence/session-store.d.ts +9 -0
- package/dist/persistence/session-store.js +48 -20
- package/dist/personas/persona-manager.js +17 -1
- package/dist/plugins/code-explorer/CodeExplorerManager.d.ts +10 -4
- package/dist/plugins/code-explorer/CodeExplorerManager.js +69 -16
- package/dist/plugins/plugin-manager.js +10 -1
- package/dist/prompts/prompt-manager.js +11 -4
- package/dist/prompts/system-base.js +6 -2
- package/dist/protocols/a2a/codebuddy-executor.d.ts +11 -2
- package/dist/protocols/a2a/codebuddy-executor.js +9 -8
- package/dist/protocols/a2a/index.d.ts +1 -1
- package/dist/protocols/a2a/jsonrpc-v1.d.ts +41 -0
- package/dist/protocols/a2a/jsonrpc-v1.js +145 -0
- package/dist/protocols/a2a/peer-config.d.ts +20 -0
- package/dist/protocols/a2a/peer-config.js +55 -0
- package/dist/providers/codex-oauth.js +30 -6
- package/dist/providers/model-provider-compat.js +2 -1
- package/dist/sandbox/os-sandbox.d.ts +1 -1
- package/dist/scheduler/cron-scheduler.d.ts +15 -2
- package/dist/scheduler/cron-scheduler.js +35 -4
- package/dist/scheduler/job-notepad.d.ts +69 -0
- package/dist/scheduler/job-notepad.js +339 -0
- package/dist/security/audit-logger.d.ts +1 -1
- package/dist/security/compute-confinement.d.ts +4 -0
- package/dist/security/compute-confinement.js +89 -0
- package/dist/security/session-encryption.d.ts +4 -0
- package/dist/security/session-encryption.js +31 -0
- package/dist/sensory/voice-loop.d.ts +17 -0
- package/dist/sensory/voice-loop.js +72 -15
- package/dist/server/auth/device-session-context.d.ts +9 -0
- package/dist/server/auth/device-session-context.js +13 -0
- package/dist/server/auth/device-store.d.ts +89 -0
- package/dist/server/auth/device-store.js +261 -0
- package/dist/server/auth/device-token.d.ts +3 -0
- package/dist/server/auth/device-token.js +6 -0
- package/dist/server/auth/jwt.js +4 -0
- package/dist/server/index.d.ts +0 -10
- package/dist/server/index.js +28 -0
- package/dist/server/middleware/auth.js +3 -2
- package/dist/server/routes/a2a-jsonrpc.d.ts +9 -0
- package/dist/server/routes/a2a-jsonrpc.js +66 -0
- package/dist/server/routes/a2a-protocol.d.ts +12 -0
- package/dist/server/routes/a2a-protocol.js +1 -1
- package/dist/server/routes/device-auth.d.ts +4 -0
- package/dist/server/routes/device-auth.js +40 -0
- package/dist/server/types.d.ts +4 -0
- package/dist/server/websocket/handler.d.ts +13 -0
- package/dist/server/websocket/handler.js +102 -17
- package/dist/services/prompt-builder.d.ts +2 -0
- package/dist/services/prompt-builder.js +16 -6
- package/dist/services/runtime-settings-context.d.ts +81 -0
- package/dist/services/runtime-settings-context.js +79 -0
- package/dist/skills/executor.js +2 -0
- package/dist/skills/hub.js +16 -14
- package/dist/skills/local-inventory.d.ts +21 -0
- package/dist/skills/local-inventory.js +72 -0
- package/dist/skills/skill-loader.js +2 -2
- package/dist/skills/skill-usage-store.d.ts +49 -0
- package/dist/skills/skill-usage-store.js +121 -0
- package/dist/testing/ai-integration-tests.js +8 -5
- package/dist/themes/theme-manager.d.ts +12 -0
- package/dist/themes/theme-manager.js +29 -0
- package/dist/themes/theme-schema.d.ts +24 -24
- package/dist/tools/a2a-call-tool.d.ts +34 -0
- package/dist/tools/a2a-call-tool.js +75 -0
- package/dist/tools/bash/streaming-executor.d.ts +1 -0
- package/dist/tools/bash/streaming-executor.js +78 -90
- package/dist/tools/code-exec-preflight-runner.d.ts +41 -0
- package/dist/tools/code-exec-preflight-runner.js +254 -0
- package/dist/tools/code-exec-preflight.d.ts +44 -0
- package/dist/tools/code-exec-preflight.js +501 -0
- package/dist/tools/code-exec-tool.d.ts +48 -1
- package/dist/tools/code-exec-tool.js +191 -47
- package/dist/tools/comment-watcher.js +29 -12
- package/dist/tools/core-code-inspection.d.ts +56 -0
- package/dist/tools/core-code-inspection.js +86 -0
- package/dist/tools/create-skill-tool.d.ts +2 -3
- package/dist/tools/create-skill-tool.js +16 -75
- package/dist/tools/cronjob-tool.d.ts +1 -0
- package/dist/tools/cronjob-tool.js +1 -0
- package/dist/tools/env-doctor-tool.d.ts +2 -0
- package/dist/tools/env-doctor-tool.js +4 -3
- package/dist/tools/execute-code-rpc-invoker.d.ts +1 -1
- package/dist/tools/execute-code-rpc-invoker.js +35 -19
- package/dist/tools/execute-code-runner.d.ts +2 -0
- package/dist/tools/execute-code-runner.js +52 -17
- package/dist/tools/fleet-room-tool.d.ts +104 -0
- package/dist/tools/fleet-room-tool.js +124 -0
- package/dist/tools/integration-tool-hints.d.ts +4 -0
- package/dist/tools/integration-tool-hints.js +19 -0
- package/dist/tools/list-peers-tool.d.ts +3 -0
- package/dist/tools/list-peers-tool.js +11 -4
- package/dist/tools/media-generation-tool.d.ts +16 -1
- package/dist/tools/media-generation-tool.js +341 -9
- package/dist/tools/merge-conflict-tool.js +53 -25
- package/dist/tools/metadata.d.ts +1 -5
- package/dist/tools/metadata.js +30 -28
- package/dist/tools/peer-tool-invoke-tool.d.ts +61 -0
- package/dist/tools/peer-tool-invoke-tool.js +396 -0
- package/dist/tools/ragchat-tool.d.ts +39 -0
- package/dist/tools/ragchat-tool.js +105 -0
- package/dist/tools/registry/fleet-tools.d.ts +21 -3
- package/dist/tools/registry/fleet-tools.js +137 -4
- package/dist/tools/registry/index.d.ts +1 -1
- package/dist/tools/registry/index.js +2 -2
- package/dist/tools/registry/knowledge-tools.d.ts +2 -2
- package/dist/tools/registry/knowledge-tools.js +2 -2
- package/dist/tools/registry/lessons-tools.d.ts +7 -0
- package/dist/tools/registry/lessons-tools.js +43 -3
- package/dist/tools/registry/memory-tools.d.ts +1 -1
- package/dist/tools/registry/memory-tools.js +8 -8
- package/dist/tools/registry/research-tools.d.ts +1 -0
- package/dist/tools/registry/research-tools.js +4 -13
- package/dist/tools/registry/self-describe-tools.d.ts +1 -1
- package/dist/tools/registry/self-describe-tools.js +43 -30
- package/dist/tools/resource-catalog-tool.d.ts +38 -0
- package/dist/tools/resource-catalog-tool.js +46 -0
- package/dist/tools/skills-inspection-tool.js +30 -1
- package/dist/tools/stream-tool-output.d.ts +3 -0
- package/dist/tools/stream-tool-output.js +33 -0
- package/dist/tools/tool-call-scheduler.d.ts +10 -0
- package/dist/tools/tool-call-scheduler.js +58 -0
- package/dist/tools/tool-effect.d.ts +5 -0
- package/dist/tools/tool-effect.js +26 -0
- package/dist/tools/tool-search.d.ts +12 -11
- package/dist/tools/tool-search.js +67 -26
- package/dist/tools/types.d.ts +6 -0
- package/dist/ui/components/ChatHistory.d.ts +1 -1
- package/dist/ui/components/ChatHistory.js +2 -2
- package/dist/ui/components/ChatInput.d.ts +2 -1
- package/dist/ui/components/ChatInput.js +42 -88
- package/dist/ui/components/ChatInterface.d.ts +4 -2
- package/dist/ui/components/ChatInterface.js +27 -63
- package/dist/ui/components/CommandSuggestions.d.ts +0 -1
- package/dist/ui/components/CommandSuggestions.js +4 -6
- package/dist/ui/components/FileAutocomplete.js +1 -1
- package/dist/ui/components/KeyboardHelp.js +8 -6
- package/dist/ui/components/ModelSelection.js +6 -5
- package/dist/ui/components/StatusBar.d.ts +2 -1
- package/dist/ui/components/StatusBar.js +8 -7
- package/dist/ui/context/theme-context.js +3 -2
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +1 -1
- package/dist/ui/utils/markdown-renderer.js +4 -13
- package/dist/utils/atomic-write.d.ts +22 -0
- package/dist/utils/atomic-write.js +29 -0
- package/dist/utils/bounded-output.d.ts +16 -0
- package/dist/utils/bounded-output.js +63 -0
- package/dist/utils/config-validation/schema.d.ts +2 -2
- package/dist/utils/device-store-file.d.ts +4 -0
- package/dist/utils/device-store-file.js +40 -0
- package/dist/utils/export-manager.d.ts +9 -0
- package/dist/utils/export-manager.js +19 -0
- package/dist/utils/first-use-hints.d.ts +25 -0
- package/dist/utils/first-use-hints.js +58 -0
- package/dist/utils/graceful-shutdown.d.ts +8 -0
- package/dist/utils/graceful-shutdown.js +23 -7
- package/dist/utils/history-manager.js +1 -1
- package/dist/utils/update-notifier.js +16 -18
- package/dist/wizard/environment-detection.d.ts +5 -1
- package/dist/wizard/environment-detection.js +49 -7
- package/dist/wizard/onboarding.d.ts +5 -1
- package/dist/wizard/onboarding.js +90 -30
- package/dist/wizard/provider-onboarding.d.ts +2 -0
- package/dist/wizard/provider-onboarding.js +55 -17
- package/package.json +7 -3
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* as they arrive from the spawned process.
|
|
6
6
|
*/
|
|
7
7
|
import { spawn } from 'child_process';
|
|
8
|
+
import { StringDecoder } from 'node:string_decoder';
|
|
9
|
+
import { BoundedOutput } from '../../utils/bounded-output.js';
|
|
8
10
|
import { ConfirmationService } from '../../utils/confirmation-service.js';
|
|
9
11
|
import { validateCommand as validateCommandSafety } from '../../utils/input-validator.js';
|
|
10
12
|
import { validateCommand } from './command-validator.js';
|
|
@@ -149,106 +151,92 @@ export async function* executeStreaming(command, timeout = 30000, deps, signal)
|
|
|
149
151
|
});
|
|
150
152
|
const runningProcesses = deps.getRunningProcesses();
|
|
151
153
|
runningProcesses.add(proc);
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
154
|
+
const stdout = new BoundedOutput(deps.maxOutputBytes);
|
|
155
|
+
const stderr = new BoundedOutput(deps.maxOutputBytes);
|
|
156
|
+
const pending = new BoundedOutput(deps.maxOutputBytes);
|
|
157
|
+
const outDecoder = new StringDecoder('utf8');
|
|
158
|
+
const errDecoder = new StringDecoder('utf8');
|
|
159
|
+
let done = false;
|
|
160
|
+
let failure;
|
|
161
|
+
let wake;
|
|
162
|
+
let killTimer;
|
|
163
|
+
const notify = () => { wake?.(); wake = undefined; };
|
|
164
|
+
const kill = (signal) => {
|
|
159
165
|
try {
|
|
160
|
-
proc.
|
|
161
|
-
|
|
162
|
-
catch { /* ignore */ }
|
|
163
|
-
}, timeout);
|
|
164
|
-
try {
|
|
165
|
-
// Create a readable stream from stdout and stderr combined
|
|
166
|
-
const chunks = [];
|
|
167
|
-
let resolve = null;
|
|
168
|
-
let done = false;
|
|
169
|
-
const killProcess = () => {
|
|
170
|
-
try {
|
|
171
|
-
if (!isWindows && proc.pid)
|
|
172
|
-
process.kill(-proc.pid, 'SIGTERM');
|
|
173
|
-
else
|
|
174
|
-
proc.kill('SIGTERM');
|
|
175
|
-
}
|
|
176
|
-
catch {
|
|
177
|
-
try {
|
|
178
|
-
proc.kill('SIGTERM');
|
|
179
|
-
}
|
|
180
|
-
catch { /* process already exited */ }
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
onAbort = () => {
|
|
184
|
-
aborted = true;
|
|
185
|
-
killProcess();
|
|
186
|
-
if (resolve) {
|
|
187
|
-
resolve();
|
|
188
|
-
resolve = null;
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
signal?.addEventListener('abort', onAbort, { once: true });
|
|
192
|
-
if (signal?.aborted)
|
|
193
|
-
onAbort();
|
|
194
|
-
const onData = (data, isStderr) => {
|
|
195
|
-
const text = data.toString();
|
|
196
|
-
if (isStderr)
|
|
197
|
-
stderr += text;
|
|
166
|
+
if (!isWindows && proc.pid)
|
|
167
|
+
process.kill(-proc.pid, signal);
|
|
198
168
|
else
|
|
199
|
-
|
|
200
|
-
chunks.push(text);
|
|
201
|
-
if (resolve) {
|
|
202
|
-
resolve();
|
|
203
|
-
resolve = null;
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
proc.stdout?.on('data', (data) => onData(data, false));
|
|
207
|
-
proc.stderr?.on('data', (data) => onData(data, true));
|
|
208
|
-
proc.on('close', () => { done = true; if (resolve) {
|
|
209
|
-
resolve();
|
|
210
|
-
resolve = null;
|
|
211
|
-
} });
|
|
212
|
-
while (!done) {
|
|
213
|
-
if (chunks.length > 0) {
|
|
214
|
-
while (chunks.length > 0) {
|
|
215
|
-
yield chunks.shift();
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
await new Promise(r => { resolve = r; });
|
|
220
|
-
}
|
|
169
|
+
proc.kill(signal);
|
|
221
170
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
171
|
+
catch { /* The process or its group already exited. */ }
|
|
172
|
+
};
|
|
173
|
+
const stop = (reason) => {
|
|
174
|
+
if (done || failure)
|
|
175
|
+
return;
|
|
176
|
+
failure = reason;
|
|
177
|
+
kill('SIGTERM');
|
|
178
|
+
// Sending a signal is not proof of exit. Escalate even if the parent
|
|
179
|
+
// closes its pipes while a descendant still holds the process group.
|
|
180
|
+
killTimer = setTimeout(() => {
|
|
181
|
+
kill('SIGKILL');
|
|
182
|
+
done = true;
|
|
183
|
+
notify();
|
|
184
|
+
}, 250);
|
|
185
|
+
notify();
|
|
186
|
+
};
|
|
187
|
+
const timer = setTimeout(() => stop(`Command timed out after ${timeout}ms`), timeout);
|
|
188
|
+
const onAbort = () => stop('Command aborted by user');
|
|
189
|
+
const onError = (error) => {
|
|
190
|
+
failure ??= `Command failed to start: ${error.message}`;
|
|
191
|
+
done = true;
|
|
192
|
+
notify();
|
|
193
|
+
};
|
|
194
|
+
const onClose = () => {
|
|
195
|
+
if (!failure)
|
|
196
|
+
done = true;
|
|
197
|
+
notify();
|
|
198
|
+
};
|
|
199
|
+
const onData = (data, target, decoder) => {
|
|
200
|
+
const text = decoder.write(data);
|
|
201
|
+
target.append(text);
|
|
202
|
+
pending.append(text);
|
|
203
|
+
notify();
|
|
204
|
+
};
|
|
205
|
+
const onStdout = (data) => onData(data, stdout, outDecoder);
|
|
206
|
+
const onStderr = (data) => onData(data, stderr, errDecoder);
|
|
207
|
+
proc.stdout?.on('data', onStdout);
|
|
208
|
+
proc.stderr?.on('data', onStderr);
|
|
209
|
+
proc.on('error', onError);
|
|
210
|
+
proc.on('close', onClose);
|
|
211
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
212
|
+
if (signal?.aborted)
|
|
213
|
+
onAbort();
|
|
214
|
+
try {
|
|
215
|
+
while (!done || pending.retainedBytes > 0) {
|
|
216
|
+
if (pending.retainedBytes > 0)
|
|
217
|
+
yield pending.drain();
|
|
218
|
+
else if (!done)
|
|
219
|
+
await new Promise(resolve => { wake = resolve; });
|
|
225
220
|
}
|
|
226
221
|
}
|
|
227
222
|
finally {
|
|
228
223
|
clearTimeout(timer);
|
|
224
|
+
clearTimeout(killTimer);
|
|
229
225
|
signal?.removeEventListener('abort', onAbort);
|
|
226
|
+
// Also handles a consumer calling return() before the child exits.
|
|
227
|
+
if (!done || failure)
|
|
228
|
+
kill('SIGKILL');
|
|
229
|
+
proc.stdout?.removeListener('data', onStdout);
|
|
230
|
+
proc.stderr?.removeListener('data', onStderr);
|
|
231
|
+
proc.removeListener('close', onClose);
|
|
230
232
|
runningProcesses.delete(proc);
|
|
231
|
-
if (!proc.killed && proc.exitCode === null) {
|
|
232
|
-
proc.kill('SIGTERM');
|
|
233
|
-
setTimeout(() => {
|
|
234
|
-
try {
|
|
235
|
-
if (!proc.killed)
|
|
236
|
-
proc.kill('SIGKILL');
|
|
237
|
-
}
|
|
238
|
-
catch { /* already dead */ }
|
|
239
|
-
}, 5000);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
if (aborted) {
|
|
243
|
-
return { success: false, error: 'Command aborted by user', output: stdout };
|
|
244
|
-
}
|
|
245
|
-
if (timedOut) {
|
|
246
|
-
return { success: false, error: `Command timed out after ${timeout}ms` };
|
|
247
233
|
}
|
|
248
|
-
const
|
|
249
|
-
if (
|
|
250
|
-
return { success: false, error:
|
|
234
|
+
const output = stdout.text();
|
|
235
|
+
if (failure)
|
|
236
|
+
return { success: false, error: failure, output };
|
|
237
|
+
if (proc.exitCode !== 0) {
|
|
238
|
+
return { success: false, error: stderr.text() || `Exit code ${proc.exitCode}`, output };
|
|
251
239
|
}
|
|
252
|
-
return { success: true, output
|
|
240
|
+
return { success: true, output };
|
|
253
241
|
}
|
|
254
242
|
//# sourceMappingURL=streaming-executor.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone isolated TypeScript preflight compiler runner.
|
|
3
|
+
*
|
|
4
|
+
* Runs inside an isolated worker/child process with:
|
|
5
|
+
* - 128MB max heap limit (--max-old-space-size=128)
|
|
6
|
+
* - Virtual in-memory file system (zero disk I/O for guest files)
|
|
7
|
+
* - Bounded diagnostics (max 20 diagnostics / 16KB formatted error size)
|
|
8
|
+
* - Full rejection of global, compiler options, environment, and guest diagnostics
|
|
9
|
+
* - Complete isolation from external module imports
|
|
10
|
+
*/
|
|
11
|
+
export interface PreflightWorkerPayload {
|
|
12
|
+
code: string;
|
|
13
|
+
declarations: string;
|
|
14
|
+
strict?: boolean;
|
|
15
|
+
target?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface PreflightDiagnostic {
|
|
18
|
+
line?: number;
|
|
19
|
+
column?: number;
|
|
20
|
+
message: string;
|
|
21
|
+
code?: number;
|
|
22
|
+
category: 'error' | 'warning' | 'suggestion' | 'message';
|
|
23
|
+
file?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface PreflightWorkerResult {
|
|
26
|
+
success: boolean;
|
|
27
|
+
diagnostics: PreflightDiagnostic[];
|
|
28
|
+
error?: string;
|
|
29
|
+
transpiledCode?: string;
|
|
30
|
+
declarations?: string;
|
|
31
|
+
}
|
|
32
|
+
export declare const PREFLIGHT_LIMITS: Readonly<{
|
|
33
|
+
timeoutMs: 5000;
|
|
34
|
+
maxHeapMb: 128;
|
|
35
|
+
maxDiagnostics: 20;
|
|
36
|
+
maxErrorBytes: number;
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* Execute isolated in-memory TypeScript compilation and diagnostic collection.
|
|
40
|
+
*/
|
|
41
|
+
export declare function executePreflightCompilation(payload: PreflightWorkerPayload): PreflightWorkerResult;
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone isolated TypeScript preflight compiler runner.
|
|
3
|
+
*
|
|
4
|
+
* Runs inside an isolated worker/child process with:
|
|
5
|
+
* - 128MB max heap limit (--max-old-space-size=128)
|
|
6
|
+
* - Virtual in-memory file system (zero disk I/O for guest files)
|
|
7
|
+
* - Bounded diagnostics (max 20 diagnostics / 16KB formatted error size)
|
|
8
|
+
* - Full rejection of global, compiler options, environment, and guest diagnostics
|
|
9
|
+
* - Complete isolation from external module imports
|
|
10
|
+
*/
|
|
11
|
+
import ts from 'typescript';
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
import { createRequire } from 'node:module';
|
|
14
|
+
export const PREFLIGHT_LIMITS = Object.freeze({
|
|
15
|
+
timeoutMs: 5_000,
|
|
16
|
+
maxHeapMb: 128,
|
|
17
|
+
maxDiagnostics: 20,
|
|
18
|
+
maxErrorBytes: 16 * 1024,
|
|
19
|
+
});
|
|
20
|
+
const require = createRequire(import.meta.url);
|
|
21
|
+
const tsLibDir = path.dirname(require.resolve('typescript'));
|
|
22
|
+
const tsLibCache = new Map();
|
|
23
|
+
function getCachedLibSourceFile(fileName, languageVersionOrOptions) {
|
|
24
|
+
const baseName = path.basename(fileName);
|
|
25
|
+
if (tsLibCache.has(baseName)) {
|
|
26
|
+
return tsLibCache.get(baseName);
|
|
27
|
+
}
|
|
28
|
+
const fullPath = path.join(tsLibDir, baseName);
|
|
29
|
+
if (ts.sys.fileExists(fullPath)) {
|
|
30
|
+
const content = ts.sys.readFile(fullPath);
|
|
31
|
+
if (content !== undefined) {
|
|
32
|
+
const sf = ts.createSourceFile(fileName, content, languageVersionOrOptions, true);
|
|
33
|
+
tsLibCache.set(baseName, sf);
|
|
34
|
+
return sf;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
const defaultCompilerOptions = {
|
|
40
|
+
target: ts.ScriptTarget.ES2022,
|
|
41
|
+
module: ts.ModuleKind.ESNext,
|
|
42
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
43
|
+
strict: true,
|
|
44
|
+
noImplicitAny: true,
|
|
45
|
+
strictNullChecks: true,
|
|
46
|
+
strictFunctionTypes: true,
|
|
47
|
+
strictBindCallApply: true,
|
|
48
|
+
strictPropertyInitialization: true,
|
|
49
|
+
noImplicitThis: true,
|
|
50
|
+
alwaysStrict: true,
|
|
51
|
+
noUnusedLocals: false,
|
|
52
|
+
noUnusedParameters: false,
|
|
53
|
+
exactOptionalPropertyTypes: false,
|
|
54
|
+
noEmit: true,
|
|
55
|
+
skipLibCheck: true,
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Execute isolated in-memory TypeScript compilation and diagnostic collection.
|
|
59
|
+
*/
|
|
60
|
+
export function executePreflightCompilation(payload) {
|
|
61
|
+
const { code, declarations, strict, target } = payload;
|
|
62
|
+
const syntax = ts.createSourceFile('/input.ts', code, ts.ScriptTarget.ES2022, true);
|
|
63
|
+
let forbidden;
|
|
64
|
+
const inspect = (node) => {
|
|
65
|
+
if (ts.isImportDeclaration(node) || ts.isImportEqualsDeclaration(node) || ts.isImportTypeNode(node)
|
|
66
|
+
|| (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword)
|
|
67
|
+
|| (ts.isExportDeclaration(node) && node.moduleSpecifier)) {
|
|
68
|
+
forbidden = 'Module imports are not allowed in code_exec scripts';
|
|
69
|
+
}
|
|
70
|
+
if (ts.isModuleDeclaration(node) && ts.isStringLiteral(node.name))
|
|
71
|
+
forbidden = 'Ambient module declarations are not allowed in code_exec scripts';
|
|
72
|
+
ts.forEachChild(node, inspect);
|
|
73
|
+
};
|
|
74
|
+
inspect(syntax);
|
|
75
|
+
if (syntax.referencedFiles.length || syntax.typeReferenceDirectives.length || syntax.libReferenceDirectives.length)
|
|
76
|
+
forbidden = 'TypeScript triple-slash reference directives are not allowed in code_exec scripts';
|
|
77
|
+
if (forbidden)
|
|
78
|
+
return { success: false, diagnostics: [{ message: forbidden, category: 'error' }], error: forbidden };
|
|
79
|
+
const wrappedGuestCode = `async function __codeBuddyMain() {\n${code}\n}`;
|
|
80
|
+
const virtualFiles = new Map([
|
|
81
|
+
['/code_exec_env.d.ts', declarations],
|
|
82
|
+
['/guest_code.ts', wrappedGuestCode],
|
|
83
|
+
]);
|
|
84
|
+
let scriptTarget = ts.ScriptTarget.ES2022;
|
|
85
|
+
if (target) {
|
|
86
|
+
const targetUpper = target.toUpperCase();
|
|
87
|
+
if (targetUpper === 'ES2020')
|
|
88
|
+
scriptTarget = ts.ScriptTarget.ES2020;
|
|
89
|
+
else if (targetUpper === 'ES2021')
|
|
90
|
+
scriptTarget = ts.ScriptTarget.ES2021;
|
|
91
|
+
else if (targetUpper === 'ES2022')
|
|
92
|
+
scriptTarget = ts.ScriptTarget.ES2022;
|
|
93
|
+
else if (targetUpper === 'ESNEXT')
|
|
94
|
+
scriptTarget = ts.ScriptTarget.ESNext;
|
|
95
|
+
}
|
|
96
|
+
const compilerOptions = {
|
|
97
|
+
...defaultCompilerOptions,
|
|
98
|
+
target: scriptTarget,
|
|
99
|
+
...(strict !== undefined ? { strict } : {}),
|
|
100
|
+
};
|
|
101
|
+
const host = {
|
|
102
|
+
getSourceFile: (fileName, languageVersion) => {
|
|
103
|
+
if (virtualFiles.has(fileName)) {
|
|
104
|
+
return ts.createSourceFile(fileName, virtualFiles.get(fileName), languageVersion, true, ts.ScriptKind.TS);
|
|
105
|
+
}
|
|
106
|
+
if (fileName.includes('lib.') && fileName.endsWith('.d.ts')) {
|
|
107
|
+
return getCachedLibSourceFile(fileName, languageVersion);
|
|
108
|
+
}
|
|
109
|
+
return undefined;
|
|
110
|
+
},
|
|
111
|
+
getDefaultLibFileName: (opts) => ts.getDefaultLibFileName(opts),
|
|
112
|
+
writeFile: () => { },
|
|
113
|
+
getCurrentDirectory: () => '/',
|
|
114
|
+
getDirectories: () => [],
|
|
115
|
+
getCanonicalFileName: (fileName) => fileName,
|
|
116
|
+
useCaseSensitiveFileNames: () => true,
|
|
117
|
+
getNewLine: () => '\n',
|
|
118
|
+
fileExists: (fileName) => virtualFiles.has(fileName) ||
|
|
119
|
+
(fileName.includes('lib.') &&
|
|
120
|
+
ts.sys.fileExists(path.join(tsLibDir, path.basename(fileName)))),
|
|
121
|
+
readFile: (fileName) => virtualFiles.get(fileName) ||
|
|
122
|
+
(fileName.includes('lib.')
|
|
123
|
+
? ts.sys.readFile(path.join(tsLibDir, path.basename(fileName)))
|
|
124
|
+
: undefined),
|
|
125
|
+
resolveModuleNameLiterals: () => [],
|
|
126
|
+
resolveModuleNames: () => [],
|
|
127
|
+
};
|
|
128
|
+
const program = ts.createProgram(['/code_exec_env.d.ts', '/guest_code.ts'], compilerOptions, host);
|
|
129
|
+
// Collect all diagnostics: syntactic, global, options, semantic, declaration
|
|
130
|
+
const syntacticDiagnostics = program.getSyntacticDiagnostics();
|
|
131
|
+
const globalDiagnostics = program.getGlobalDiagnostics();
|
|
132
|
+
const optionsDiagnostics = program.getOptionsDiagnostics();
|
|
133
|
+
const semanticDiagnostics = program.getSemanticDiagnostics();
|
|
134
|
+
const declarationDiagnostics = program.getDeclarationDiagnostics();
|
|
135
|
+
const allDiagnostics = [
|
|
136
|
+
...syntacticDiagnostics,
|
|
137
|
+
...globalDiagnostics,
|
|
138
|
+
...optionsDiagnostics,
|
|
139
|
+
...semanticDiagnostics,
|
|
140
|
+
...declarationDiagnostics,
|
|
141
|
+
];
|
|
142
|
+
const errorDiagnostics = allDiagnostics.filter((d) => d.category === ts.DiagnosticCategory.Error);
|
|
143
|
+
if (errorDiagnostics.length === 0) {
|
|
144
|
+
let transpiledCode;
|
|
145
|
+
try {
|
|
146
|
+
const transpiled = ts.transpileModule(code, {
|
|
147
|
+
compilerOptions: {
|
|
148
|
+
target: compilerOptions.target ?? ts.ScriptTarget.ES2022,
|
|
149
|
+
module: ts.ModuleKind.ESNext,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
transpiledCode = transpiled.outputText;
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
// Retain original code if transpilation throws
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
success: true,
|
|
159
|
+
diagnostics: [],
|
|
160
|
+
transpiledCode,
|
|
161
|
+
declarations,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const formattedDiagnostics = [];
|
|
165
|
+
const errorMessages = [];
|
|
166
|
+
for (const d of errorDiagnostics) {
|
|
167
|
+
let line;
|
|
168
|
+
let column;
|
|
169
|
+
const fileName = d.file?.fileName;
|
|
170
|
+
if (d.file && d.start !== undefined) {
|
|
171
|
+
const pos = d.file.getLineAndCharacterOfPosition(d.start);
|
|
172
|
+
if (fileName === '/guest_code.ts') {
|
|
173
|
+
// Adjust line number for the async wrapper
|
|
174
|
+
line = Math.max(1, pos.line);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
line = pos.line + 1;
|
|
178
|
+
}
|
|
179
|
+
column = pos.character + 1;
|
|
180
|
+
}
|
|
181
|
+
const msgText = ts.flattenDiagnosticMessageText(d.messageText, '\n');
|
|
182
|
+
const category = d.category === ts.DiagnosticCategory.Error
|
|
183
|
+
? 'error'
|
|
184
|
+
: d.category === ts.DiagnosticCategory.Warning
|
|
185
|
+
? 'warning'
|
|
186
|
+
: d.category === ts.DiagnosticCategory.Suggestion
|
|
187
|
+
? 'suggestion'
|
|
188
|
+
: 'message';
|
|
189
|
+
formattedDiagnostics.push({
|
|
190
|
+
line,
|
|
191
|
+
column,
|
|
192
|
+
message: msgText,
|
|
193
|
+
code: d.code,
|
|
194
|
+
category,
|
|
195
|
+
file: fileName,
|
|
196
|
+
});
|
|
197
|
+
let loc = '';
|
|
198
|
+
if (fileName === '/guest_code.ts') {
|
|
199
|
+
loc = line !== undefined ? `Line ${line}${column !== undefined ? `:${column}` : ''}: ` : '';
|
|
200
|
+
}
|
|
201
|
+
else if (fileName === '/code_exec_env.d.ts') {
|
|
202
|
+
loc = `[Environment${line !== undefined ? ` Line ${line}` : ''}]: `;
|
|
203
|
+
}
|
|
204
|
+
else if (fileName) {
|
|
205
|
+
loc = `[${fileName}${line !== undefined ? ` Line ${line}` : ''}]: `;
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
loc = '[Global/Compiler]: ';
|
|
209
|
+
}
|
|
210
|
+
errorMessages.push(`${loc}${msgText}`);
|
|
211
|
+
}
|
|
212
|
+
const boundedDiagnostics = formattedDiagnostics.slice(0, PREFLIGHT_LIMITS.maxDiagnostics);
|
|
213
|
+
const totalErrors = errorDiagnostics.length;
|
|
214
|
+
const header = totalErrors > PREFLIGHT_LIMITS.maxDiagnostics
|
|
215
|
+
? `TypeScript preflight validation failed (${PREFLIGHT_LIMITS.maxDiagnostics} of ${totalErrors} errors shown):\n`
|
|
216
|
+
: 'TypeScript preflight validation failed:\n';
|
|
217
|
+
let summary = header + errorMessages.slice(0, PREFLIGHT_LIMITS.maxDiagnostics).map((m) => `• ${m}`).join('\n');
|
|
218
|
+
if (totalErrors > PREFLIGHT_LIMITS.maxDiagnostics) {
|
|
219
|
+
summary += `\n…[truncated ${totalErrors - PREFLIGHT_LIMITS.maxDiagnostics} diagnostic(s)]`;
|
|
220
|
+
}
|
|
221
|
+
if (summary.length > PREFLIGHT_LIMITS.maxErrorBytes) {
|
|
222
|
+
const marker = '\n…[truncated diagnostics exceeding 16KB limit]';
|
|
223
|
+
summary = summary.slice(0, Math.max(0, PREFLIGHT_LIMITS.maxErrorBytes - marker.length)) + marker;
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
success: false,
|
|
227
|
+
diagnostics: boundedDiagnostics,
|
|
228
|
+
error: summary,
|
|
229
|
+
declarations,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
// Standalone child process IPC listener
|
|
233
|
+
if (typeof process.send === 'function') {
|
|
234
|
+
process.on('message', (rawMessage) => {
|
|
235
|
+
if (!rawMessage || typeof rawMessage !== 'object')
|
|
236
|
+
return;
|
|
237
|
+
const msg = rawMessage;
|
|
238
|
+
if (msg.type === 'compile' && msg.payload) {
|
|
239
|
+
try {
|
|
240
|
+
const result = executePreflightCompilation(msg.payload);
|
|
241
|
+
// Full tool catalogues can exceed the IPC pipe buffer. Exit only once
|
|
242
|
+
// Node has flushed the response, otherwise successful checks disappear.
|
|
243
|
+
process.send({ type: 'result', result }, error => process.exit(error ? 1 : 0));
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
process.send({
|
|
247
|
+
type: 'error',
|
|
248
|
+
error: error instanceof Error ? error.message : String(error),
|
|
249
|
+
}, error => process.exit(error ? 1 : 0));
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=code-exec-preflight-runner.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript preflight validation for Code Mode (`code_exec`).
|
|
3
|
+
*
|
|
4
|
+
* Runs isolated TypeScript typechecking in a sandboxed worker/child process
|
|
5
|
+
* against declarations derived exclusively from the runtime-scoped tool catalog.
|
|
6
|
+
*
|
|
7
|
+
* Invariants:
|
|
8
|
+
* 1. Hard 5s deadline + 128MB heap isolation in a separate worker/child process.
|
|
9
|
+
* 2. Lazy loading: TypeScript is NOT imported in the parent process or when typecheck is false.
|
|
10
|
+
* 3. Bounded diagnostics: limited to 20 diagnostics and 16KB total formatted output.
|
|
11
|
+
* 4. Zero guest filesystem access: virtual files only in-memory; no guest file reads/writes.
|
|
12
|
+
* 5. No hidden tool/import exposure: declarations are generated strictly from `availableTools`.
|
|
13
|
+
* 6. Fail-closed: invalid code or compiler/global errors are rejected before child process spawn or tool dispatch.
|
|
14
|
+
*/
|
|
15
|
+
import type { IToolExecutionContext } from './registry/types.js';
|
|
16
|
+
import { type CodeExecRuntime, type ToolCatalogEntry } from './code-exec-tool.js';
|
|
17
|
+
import type { PreflightDiagnostic, PreflightWorkerResult } from './code-exec-preflight-runner.js';
|
|
18
|
+
export type { PreflightDiagnostic, PreflightWorkerResult as PreflightResult };
|
|
19
|
+
export interface PreflightOptions {
|
|
20
|
+
target?: string;
|
|
21
|
+
strict?: boolean;
|
|
22
|
+
catalog?: readonly ToolCatalogEntry[];
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
}
|
|
25
|
+
export declare function jsonSchemaPropertyToTs(prop: unknown, indent?: string): string;
|
|
26
|
+
interface ExtractedArgsType {
|
|
27
|
+
typeName: string;
|
|
28
|
+
typeDeclaration: string;
|
|
29
|
+
hasRequiredProps: boolean;
|
|
30
|
+
}
|
|
31
|
+
export declare function extractToolArgsType(toolName: string, parameters: unknown, typeIndex: number): ExtractedArgsType;
|
|
32
|
+
/**
|
|
33
|
+
* Resolve tool catalog entries strictly scoped to `runtime.availableTools`.
|
|
34
|
+
* Tools not in `runtime.availableTools` are never returned.
|
|
35
|
+
*/
|
|
36
|
+
export declare function resolveScopedToolCatalog(runtime: CodeExecRuntime, context?: IToolExecutionContext): ToolCatalogEntry[];
|
|
37
|
+
/**
|
|
38
|
+
* Generate TypeScript declarations matching the scoped runtime environment.
|
|
39
|
+
*/
|
|
40
|
+
export declare function generateToolDeclarations(scopedTools: readonly ToolCatalogEntry[]): string;
|
|
41
|
+
/**
|
|
42
|
+
* Execute isolated TypeScript preflight typechecking in a worker/child process.
|
|
43
|
+
*/
|
|
44
|
+
export declare function runCodeExecPreflight(code: string, runtime: CodeExecRuntime, context?: IToolExecutionContext, options?: PreflightOptions): Promise<PreflightWorkerResult>;
|