@lotagate/cli 0.1.22 → 0.1.23
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/package.json +7 -7
- package/scripts/install-native.mjs +11 -11
- package/dist/application/agent/agent-history.d.ts +0 -3
- package/dist/application/agent/agent-history.js +0 -81
- package/dist/application/agent/agent-input-context.d.ts +0 -9
- package/dist/application/agent/agent-input-context.js +0 -12
- package/dist/application/agent/agent-limit.d.ts +0 -3
- package/dist/application/agent/agent-limit.js +0 -12
- package/dist/application/agent/agent-run-tracker.d.ts +0 -30
- package/dist/application/agent/agent-run-tracker.js +0 -68
- package/dist/application/agent/agent-session-store.d.ts +0 -19
- package/dist/application/agent/agent-session-store.js +0 -74
- package/dist/application/agent/capability-profile.d.ts +0 -37
- package/dist/application/agent/capability-profile.js +0 -13
- package/dist/application/agent/cli-agent-execution-service.d.ts +0 -81
- package/dist/application/agent/cli-agent-execution-service.js +0 -279
- package/dist/application/agent/context-compaction-persistence.d.ts +0 -8
- package/dist/application/agent/context-compaction-persistence.js +0 -27
- package/dist/application/agent/context-compaction.d.ts +0 -20
- package/dist/application/agent/context-compaction.js +0 -114
- package/dist/application/agent/prompt-data-safety.d.ts +0 -14
- package/dist/application/agent/prompt-data-safety.js +0 -38
- package/dist/application/agent/safe-system-prompt.d.ts +0 -3
- package/dist/application/agent/safe-system-prompt.js +0 -19
- package/dist/application/agent/scoped-tool-executor.d.ts +0 -13
- package/dist/application/agent/scoped-tool-executor.js +0 -32
- package/dist/application/agent/system-prompt-builder.d.ts +0 -14
- package/dist/application/agent/system-prompt-builder.js +0 -199
- package/dist/application/agent/tool-catalog.d.ts +0 -14
- package/dist/application/agent/tool-catalog.js +0 -30
- package/dist/application/agent/tool-display.d.ts +0 -6
- package/dist/application/agent/tool-display.js +0 -59
- package/dist/application/agent/tool-hook-lifecycle.d.ts +0 -19
- package/dist/application/agent/tool-hook-lifecycle.js +0 -85
- package/dist/application/auth/authentication-service.d.ts +0 -20
- package/dist/application/auth/authentication-service.js +0 -44
- package/dist/application/chat/chat-service.d.ts +0 -12
- package/dist/application/chat/chat-service.js +0 -19
- package/dist/application/chat/pending-attachment-store.d.ts +0 -12
- package/dist/application/chat/pending-attachment-store.js +0 -28
- package/dist/application/commands/application-command-executor.d.ts +0 -20
- package/dist/application/commands/application-command-executor.js +0 -66
- package/dist/application/commands/cli-args.d.ts +0 -6
- package/dist/application/commands/cli-args.js +0 -43
- package/dist/application/commands/cli-command-services.d.ts +0 -16
- package/dist/application/commands/cli-command-services.js +0 -405
- package/dist/application/commands/command-catalog.d.ts +0 -6
- package/dist/application/commands/command-catalog.js +0 -159
- package/dist/application/commands/command-contract.d.ts +0 -58
- package/dist/application/commands/command-contract.js +0 -1
- package/dist/application/commands/command-hints.d.ts +0 -9
- package/dist/application/commands/command-hints.js +0 -17
- package/dist/application/commands/command-output.d.ts +0 -4
- package/dist/application/commands/command-output.js +0 -1
- package/dist/application/commands/command-parser.d.ts +0 -10
- package/dist/application/commands/command-parser.js +0 -155
- package/dist/application/commands/command-presentation.d.ts +0 -7
- package/dist/application/commands/command-presentation.js +0 -131
- package/dist/application/commands/command-registry.d.ts +0 -11
- package/dist/application/commands/command-registry.js +0 -64
- package/dist/application/commands/command-runtime.d.ts +0 -2
- package/dist/application/commands/command-runtime.js +0 -3
- package/dist/application/commands/goal-command-handlers.d.ts +0 -3
- package/dist/application/commands/goal-command-handlers.js +0 -120
- package/dist/application/commands/media-command-handlers.d.ts +0 -9
- package/dist/application/commands/media-command-handlers.js +0 -307
- package/dist/application/commands/media-command-output.d.ts +0 -11
- package/dist/application/commands/media-command-output.js +0 -8
- package/dist/application/commands/runtime-command-handlers.d.ts +0 -7
- package/dist/application/commands/runtime-command-handlers.js +0 -177
- package/dist/application/commands/stream-output.d.ts +0 -4
- package/dist/application/commands/stream-output.js +0 -10
- package/dist/application/commands/utility-commands.d.ts +0 -6
- package/dist/application/commands/utility-commands.js +0 -81
- package/dist/application/config/execution-config.d.ts +0 -4
- package/dist/application/config/execution-config.js +0 -6
- package/dist/application/extensions/extension-list-contract.d.ts +0 -13
- package/dist/application/extensions/extension-list-contract.js +0 -1
- package/dist/application/extensions/extension-list-formatters.d.ts +0 -31
- package/dist/application/extensions/extension-list-formatters.js +0 -98
- package/dist/application/extensions/extension-list-output.d.ts +0 -3
- package/dist/application/extensions/extension-list-output.js +0 -7
- package/dist/application/extensions/plugin-contribution-registry.d.ts +0 -15
- package/dist/application/extensions/plugin-contribution-registry.js +0 -80
- package/dist/application/extensions/skill-scope-store.d.ts +0 -23
- package/dist/application/extensions/skill-scope-store.js +0 -33
- package/dist/application/formatting/compact-number.d.ts +0 -2
- package/dist/application/formatting/compact-number.js +0 -18
- package/dist/application/formatting/compact-table.d.ts +0 -22
- package/dist/application/formatting/compact-table.js +0 -49
- package/dist/application/media/video-operation-poller.d.ts +0 -5
- package/dist/application/media/video-operation-poller.js +0 -42
- package/dist/application/model/cached-model-catalog.d.ts +0 -13
- package/dist/application/model/cached-model-catalog.js +0 -31
- package/dist/application/model/initial-model-selection.d.ts +0 -10
- package/dist/application/model/initial-model-selection.js +0 -11
- package/dist/application/model/model-catalog-service.d.ts +0 -6
- package/dist/application/model/model-catalog-service.js +0 -13
- package/dist/application/model/model-context-window.d.ts +0 -3
- package/dist/application/model/model-context-window.js +0 -23
- package/dist/application/orchestration/cli-subagent-service.d.ts +0 -70
- package/dist/application/orchestration/cli-subagent-service.js +0 -328
- package/dist/application/orchestration/cli-turn-event-projector.d.ts +0 -12
- package/dist/application/orchestration/cli-turn-event-projector.js +0 -81
- package/dist/application/orchestration/cli-turn-events.d.ts +0 -76
- package/dist/application/orchestration/cli-turn-events.js +0 -39
- package/dist/application/orchestration/cli-turn-persistence.d.ts +0 -6
- package/dist/application/orchestration/cli-turn-persistence.js +0 -14
- package/dist/application/orchestration/goal-evaluator.d.ts +0 -18
- package/dist/application/orchestration/goal-evaluator.js +0 -88
- package/dist/application/orchestration/goal-input.d.ts +0 -3
- package/dist/application/orchestration/goal-input.js +0 -19
- package/dist/application/orchestration/goal-output.d.ts +0 -2
- package/dist/application/orchestration/goal-output.js +0 -11
- package/dist/application/orchestration/goal-runner.d.ts +0 -22
- package/dist/application/orchestration/goal-runner.js +0 -153
- package/dist/application/orchestration/goal-usage.d.ts +0 -9
- package/dist/application/orchestration/goal-usage.js +0 -19
- package/dist/application/orchestration/headless-agent-turn.d.ts +0 -32
- package/dist/application/orchestration/headless-agent-turn.js +0 -82
- package/dist/application/orchestration/plan-generator.d.ts +0 -7
- package/dist/application/orchestration/plan-generator.js +0 -34
- package/dist/application/orchestration/subagent-coordinator.d.ts +0 -33
- package/dist/application/orchestration/subagent-coordinator.js +0 -28
- package/dist/application/orchestration/subagent-handoff.d.ts +0 -2
- package/dist/application/orchestration/subagent-handoff.js +0 -68
- package/dist/application/orchestration/subagent-tool-executor.d.ts +0 -12
- package/dist/application/orchestration/subagent-tool-executor.js +0 -93
- package/dist/application/orchestration/task-assessment.d.ts +0 -4
- package/dist/application/orchestration/task-assessment.js +0 -35
- package/dist/application/orchestration/task-graph.d.ts +0 -13
- package/dist/application/orchestration/task-graph.js +0 -56
- package/dist/application/orchestration/task-scheduler.d.ts +0 -18
- package/dist/application/orchestration/task-scheduler.js +0 -88
- package/dist/application/project/project-trust-service.d.ts +0 -13
- package/dist/application/project/project-trust-service.js +0 -74
- package/dist/application/protocol/browser-host-tool-executor.d.ts +0 -41
- package/dist/application/protocol/browser-host-tool-executor.js +0 -88
- package/dist/application/protocol/desktop-agent-command.d.ts +0 -9
- package/dist/application/protocol/desktop-agent-command.js +0 -663
- package/dist/application/protocol/desktop-attachment-store.d.ts +0 -16
- package/dist/application/protocol/desktop-attachment-store.js +0 -82
- package/dist/application/protocol/desktop-command-catalog.d.ts +0 -2
- package/dist/application/protocol/desktop-command-catalog.js +0 -19
- package/dist/application/protocol/desktop-command-contract.d.ts +0 -22
- package/dist/application/protocol/desktop-command-contract.js +0 -3
- package/dist/application/protocol/desktop-command-executor.d.ts +0 -16
- package/dist/application/protocol/desktop-command-executor.js +0 -47
- package/dist/application/protocol/desktop-command-output.d.ts +0 -15
- package/dist/application/protocol/desktop-command-output.js +0 -24
- package/dist/application/protocol/desktop-execution-policy.d.ts +0 -17
- package/dist/application/protocol/desktop-execution-policy.js +0 -49
- package/dist/application/protocol/desktop-host-tool-executor.d.ts +0 -57
- package/dist/application/protocol/desktop-host-tool-executor.js +0 -53
- package/dist/application/protocol/desktop-orchestration-events.d.ts +0 -5
- package/dist/application/protocol/desktop-orchestration-events.js +0 -37
- package/dist/application/protocol/json-line-writer.d.ts +0 -9
- package/dist/application/protocol/json-line-writer.js +0 -19
- package/dist/application/protocol/jsonl-agent-command.d.ts +0 -3
- package/dist/application/protocol/jsonl-agent-command.js +0 -97
- package/dist/application/protocol/jsonl-protocol.d.ts +0 -52
- package/dist/application/protocol/jsonl-protocol.js +0 -170
- package/dist/application/security/desktop-tool-scope-policy.d.ts +0 -3
- package/dist/application/security/desktop-tool-scope-policy.js +0 -52
- package/dist/application/security/tool-action-risk-analyzer.d.ts +0 -13
- package/dist/application/security/tool-action-risk-analyzer.js +0 -64
- package/dist/application/security/tool-approval-service.d.ts +0 -35
- package/dist/application/security/tool-approval-service.js +0 -97
- package/dist/application/security/tool-risk-classifier.d.ts +0 -11
- package/dist/application/security/tool-risk-classifier.js +0 -65
- package/dist/application/security/workspace-permission-policy.d.ts +0 -10
- package/dist/application/security/workspace-permission-policy.js +0 -50
- package/dist/application/session/project-session-access.d.ts +0 -8
- package/dist/application/session/project-session-access.js +0 -19
- package/dist/application/session/session-compaction-service.d.ts +0 -10
- package/dist/application/session/session-compaction-service.js +0 -43
- package/dist/application/session/session-turn-lifecycle.d.ts +0 -5
- package/dist/application/session/session-turn-lifecycle.js +0 -31
- package/dist/application/workspace/workspace-file-index.d.ts +0 -15
- package/dist/application/workspace/workspace-file-index.js +0 -60
- package/dist/application/workspace/workspace-file-reference-resolver.d.ts +0 -14
- package/dist/application/workspace/workspace-file-reference-resolver.js +0 -123
- package/dist/application/workspace/workspace-instruction-loader.d.ts +0 -8
- package/dist/application/workspace/workspace-instruction-loader.js +0 -55
- package/dist/bootstrap/composition-root.d.ts +0 -6
- package/dist/bootstrap/composition-root.js +0 -4
- package/dist/bootstrap/global-cli-options.d.ts +0 -6
- package/dist/bootstrap/global-cli-options.js +0 -29
- package/dist/bootstrap/native-devtools-stub.d.ts +0 -10
- package/dist/bootstrap/native-devtools-stub.js +0 -10
- package/dist/bootstrap/native-entry.d.ts +0 -1
- package/dist/bootstrap/native-entry.js +0 -6
- package/dist/bootstrap/native-tiktoken.d.ts +0 -4
- package/dist/bootstrap/native-tiktoken.js +0 -5
- package/dist/bootstrap/runtime-factory.d.ts +0 -35
- package/dist/bootstrap/runtime-factory.js +0 -44
- package/dist/bootstrap/shutdown-manager.d.ts +0 -10
- package/dist/bootstrap/shutdown-manager.js +0 -14
- package/dist/bootstrap/startup-sequence.d.ts +0 -5
- package/dist/bootstrap/startup-sequence.js +0 -10
- package/dist/domain/auth/auth-profile.d.ts +0 -14
- package/dist/domain/auth/auth-profile.js +0 -39
- package/dist/domain/config/config-schema.d.ts +0 -17
- package/dist/domain/config/config-schema.js +0 -105
- package/dist/domain/errors/cli-command-hint.d.ts +0 -5
- package/dist/domain/errors/cli-command-hint.js +0 -1
- package/dist/domain/errors/cli-error.d.ts +0 -35
- package/dist/domain/errors/cli-error.js +0 -129
- package/dist/domain/errors/error-codes.d.ts +0 -46
- package/dist/domain/errors/error-codes.js +0 -45
- package/dist/domain/extensions/extension-scope.d.ts +0 -3
- package/dist/domain/extensions/extension-scope.js +0 -23
- package/dist/domain/extensions/extension-state.d.ts +0 -5
- package/dist/domain/extensions/extension-state.js +0 -11
- package/dist/domain/extensions/hook-manifest.d.ts +0 -10
- package/dist/domain/extensions/hook-manifest.js +0 -23
- package/dist/domain/extensions/mcp-config.d.ts +0 -18
- package/dist/domain/extensions/mcp-config.js +0 -111
- package/dist/domain/extensions/plugin-manifest.d.ts +0 -11
- package/dist/domain/extensions/plugin-manifest.js +0 -43
- package/dist/domain/extensions/skill-manifest.d.ts +0 -10
- package/dist/domain/extensions/skill-manifest.js +0 -51
- package/dist/domain/filesystem/file-change-diff.d.ts +0 -21
- package/dist/domain/filesystem/file-change-diff.js +0 -60
- package/dist/domain/media/gateway-media-contract.d.ts +0 -23
- package/dist/domain/media/gateway-media-contract.js +0 -163
- package/dist/domain/media/media-contract.d.ts +0 -28
- package/dist/domain/media/media-contract.js +0 -1
- package/dist/domain/media/media-execution-policy.d.ts +0 -9
- package/dist/domain/media/media-execution-policy.js +0 -31
- package/dist/domain/orchestration/goal.d.ts +0 -58
- package/dist/domain/orchestration/goal.js +0 -113
- package/dist/domain/orchestration/subagent-identity.d.ts +0 -2
- package/dist/domain/orchestration/subagent-identity.js +0 -8
- package/dist/domain/orchestration/subagent.d.ts +0 -33
- package/dist/domain/orchestration/subagent.js +0 -1
- package/dist/domain/orchestration/task.d.ts +0 -31
- package/dist/domain/orchestration/task.js +0 -1
- package/dist/domain/project/project-identity.d.ts +0 -6
- package/dist/domain/project/project-identity.js +0 -4
- package/dist/domain/runtime/assistant-delta-normalizer.d.ts +0 -11
- package/dist/domain/runtime/assistant-delta-normalizer.js +0 -19
- package/dist/domain/runtime/resource-limits.d.ts +0 -60
- package/dist/domain/runtime/resource-limits.js +0 -60
- package/dist/domain/session/attachment.d.ts +0 -13
- package/dist/domain/session/attachment.js +0 -1
- package/dist/domain/session/session-schema.d.ts +0 -6
- package/dist/domain/session/session-schema.js +0 -28
- package/dist/domain/session/session.d.ts +0 -27
- package/dist/domain/session/session.js +0 -1
- package/dist/domain/settings/settings-document.d.ts +0 -8
- package/dist/domain/settings/settings-document.js +0 -36
- package/dist/domain/validation/record-schema.d.ts +0 -4
- package/dist/domain/validation/record-schema.js +0 -9
- package/dist/domain/workspace/workspace-settings.d.ts +0 -12
- package/dist/domain/workspace/workspace-settings.js +0 -44
- package/dist/infrastructure/agent-sdk/agent-instance-factory.d.ts +0 -22
- package/dist/infrastructure/agent-sdk/agent-instance-factory.js +0 -31
- package/dist/infrastructure/agent-sdk/tool-calling-model-client.d.ts +0 -11
- package/dist/infrastructure/agent-sdk/tool-calling-model-client.js +0 -447
- package/dist/infrastructure/cache/cache-policy.d.ts +0 -7
- package/dist/infrastructure/cache/cache-policy.js +0 -18
- package/dist/infrastructure/cache/file-cache-store.d.ts +0 -17
- package/dist/infrastructure/cache/file-cache-store.js +0 -121
- package/dist/infrastructure/clipboard/clipboard-adapter-factory.d.ts +0 -11
- package/dist/infrastructure/clipboard/clipboard-adapter-factory.js +0 -98
- package/dist/infrastructure/clipboard/clipboard-policy.d.ts +0 -8
- package/dist/infrastructure/clipboard/clipboard-policy.js +0 -19
- package/dist/infrastructure/clipboard/clipboard-text-adapter-factory.d.ts +0 -10
- package/dist/infrastructure/clipboard/clipboard-text-adapter-factory.js +0 -94
- package/dist/infrastructure/clipboard/image-normalizer.d.ts +0 -12
- package/dist/infrastructure/clipboard/image-normalizer.js +0 -78
- package/dist/infrastructure/clipboard/windows-clipboard-adapter.d.ts +0 -7
- package/dist/infrastructure/clipboard/windows-clipboard-adapter.js +0 -66
- package/dist/infrastructure/clipboard/windows-clipboard-text-adapter.d.ts +0 -7
- package/dist/infrastructure/clipboard/windows-clipboard-text-adapter.js +0 -70
- package/dist/infrastructure/config/config-loader.d.ts +0 -19
- package/dist/infrastructure/config/config-loader.js +0 -76
- package/dist/infrastructure/config/environment-values.d.ts +0 -2
- package/dist/infrastructure/config/environment-values.js +0 -7
- package/dist/infrastructure/credentials/composite-credential-store.d.ts +0 -11
- package/dist/infrastructure/credentials/composite-credential-store.js +0 -32
- package/dist/infrastructure/credentials/encrypted-file-credential-store.d.ts +0 -17
- package/dist/infrastructure/credentials/encrypted-file-credential-store.js +0 -181
- package/dist/infrastructure/credentials/environment-credential-store.d.ts +0 -11
- package/dist/infrastructure/credentials/environment-credential-store.js +0 -37
- package/dist/infrastructure/credentials/secret-input.d.ts +0 -7
- package/dist/infrastructure/credentials/secret-input.js +0 -44
- package/dist/infrastructure/extensions/composite-mcp-config-store.d.ts +0 -9
- package/dist/infrastructure/extensions/composite-mcp-config-store.js +0 -10
- package/dist/infrastructure/extensions/extension-directory-reader.d.ts +0 -2
- package/dist/infrastructure/extensions/extension-directory-reader.js +0 -15
- package/dist/infrastructure/extensions/extension-source-resolver.d.ts +0 -6
- package/dist/infrastructure/extensions/extension-source-resolver.js +0 -126
- package/dist/infrastructure/extensions/file-mcp-config-store.d.ts +0 -15
- package/dist/infrastructure/extensions/file-mcp-config-store.js +0 -66
- package/dist/infrastructure/extensions/hook-runtime.d.ts +0 -18
- package/dist/infrastructure/extensions/hook-runtime.js +0 -66
- package/dist/infrastructure/extensions/mcp-runtime.d.ts +0 -12
- package/dist/infrastructure/extensions/mcp-runtime.js +0 -52
- package/dist/infrastructure/extensions/plugin-discovery.d.ts +0 -5
- package/dist/infrastructure/extensions/plugin-discovery.js +0 -52
- package/dist/infrastructure/extensions/plugin-manager.d.ts +0 -26
- package/dist/infrastructure/extensions/plugin-manager.js +0 -139
- package/dist/infrastructure/extensions/skill-discovery.d.ts +0 -4
- package/dist/infrastructure/extensions/skill-discovery.js +0 -29
- package/dist/infrastructure/extensions/skill-installer.d.ts +0 -8
- package/dist/infrastructure/extensions/skill-installer.js +0 -88
- package/dist/infrastructure/extensions/skill-manager.d.ts +0 -22
- package/dist/infrastructure/extensions/skill-manager.js +0 -67
- package/dist/infrastructure/extensions/skill-roots.d.ts +0 -19
- package/dist/infrastructure/extensions/skill-roots.js +0 -25
- package/dist/infrastructure/extensions/skill-tool-executor.d.ts +0 -18
- package/dist/infrastructure/extensions/skill-tool-executor.js +0 -53
- package/dist/infrastructure/filesystem/atomic-file-store.d.ts +0 -12
- package/dist/infrastructure/filesystem/atomic-file-store.js +0 -106
- package/dist/infrastructure/filesystem/bounded-file-reader.d.ts +0 -6
- package/dist/infrastructure/filesystem/bounded-file-reader.js +0 -24
- package/dist/infrastructure/filesystem/bounded-json-reader.d.ts +0 -1
- package/dist/infrastructure/filesystem/bounded-json-reader.js +0 -7
- package/dist/infrastructure/filesystem/fs-errors.d.ts +0 -2
- package/dist/infrastructure/filesystem/fs-errors.js +0 -6
- package/dist/infrastructure/filesystem/gateway-media-input-reader.d.ts +0 -12
- package/dist/infrastructure/filesystem/gateway-media-input-reader.js +0 -49
- package/dist/infrastructure/filesystem/local-filesystem-tool-executor.d.ts +0 -21
- package/dist/infrastructure/filesystem/local-filesystem-tool-executor.js +0 -176
- package/dist/infrastructure/filesystem/path-resolver.d.ts +0 -20
- package/dist/infrastructure/filesystem/path-resolver.js +0 -119
- package/dist/infrastructure/filesystem/workspace-media-artifact-store.d.ts +0 -13
- package/dist/infrastructure/filesystem/workspace-media-artifact-store.js +0 -152
- package/dist/infrastructure/logging/daily-rotating-file-writer.d.ts +0 -20
- package/dist/infrastructure/logging/daily-rotating-file-writer.js +0 -75
- package/dist/infrastructure/logging/log-redactor.d.ts +0 -2
- package/dist/infrastructure/logging/log-redactor.js +0 -26
- package/dist/infrastructure/logging/logging-policy.d.ts +0 -6
- package/dist/infrastructure/logging/logging-policy.js +0 -6
- package/dist/infrastructure/logging/structured-logger.d.ts +0 -24
- package/dist/infrastructure/logging/structured-logger.js +0 -40
- package/dist/infrastructure/network/safe-media-downloader.d.ts +0 -23
- package/dist/infrastructure/network/safe-media-downloader.js +0 -239
- package/dist/infrastructure/platform/host-platform.d.ts +0 -14
- package/dist/infrastructure/platform/host-platform.js +0 -23
- package/dist/infrastructure/platform/host-process.d.ts +0 -17
- package/dist/infrastructure/platform/host-process.js +0 -116
- package/dist/infrastructure/platform/platform-paths.d.ts +0 -25
- package/dist/infrastructure/platform/platform-paths.js +0 -33
- package/dist/infrastructure/project/file-project-trust-store.d.ts +0 -12
- package/dist/infrastructure/project/file-project-trust-store.js +0 -59
- package/dist/infrastructure/sdk/chat-completion-adapter.d.ts +0 -8
- package/dist/infrastructure/sdk/chat-completion-adapter.js +0 -115
- package/dist/infrastructure/sdk/lotagate-client-factory.d.ts +0 -3
- package/dist/infrastructure/sdk/lotagate-client-factory.js +0 -8
- package/dist/infrastructure/sdk/model-catalog-adapter.d.ts +0 -19
- package/dist/infrastructure/sdk/model-catalog-adapter.js +0 -28
- package/dist/infrastructure/sdk/sdk-media-gateway-client.d.ts +0 -20
- package/dist/infrastructure/sdk/sdk-media-gateway-client.js +0 -97
- package/dist/infrastructure/sessions/file-goal-store.d.ts +0 -21
- package/dist/infrastructure/sessions/file-goal-store.js +0 -160
- package/dist/infrastructure/sessions/file-session-store.d.ts +0 -48
- package/dist/infrastructure/sessions/file-session-store.js +0 -525
- package/dist/infrastructure/sessions/project-session-paths.d.ts +0 -17
- package/dist/infrastructure/sessions/project-session-paths.js +0 -41
- package/dist/infrastructure/sessions/session-index.d.ts +0 -16
- package/dist/infrastructure/sessions/session-index.js +0 -84
- package/dist/infrastructure/sessions/session-journal.d.ts +0 -22
- package/dist/infrastructure/sessions/session-journal.js +0 -137
- package/dist/infrastructure/sessions/subagent-journal-store.d.ts +0 -28
- package/dist/infrastructure/sessions/subagent-journal-store.js +0 -30
- package/dist/infrastructure/shell/shell-tool-executor.d.ts +0 -17
- package/dist/infrastructure/shell/shell-tool-executor.js +0 -115
- package/dist/infrastructure/tokens/tiktoken-token-estimator.d.ts +0 -18
- package/dist/infrastructure/tokens/tiktoken-token-estimator.js +0 -48
- package/dist/infrastructure/workspace/workspace-settings-store.d.ts +0 -9
- package/dist/infrastructure/workspace/workspace-settings-store.js +0 -75
- package/dist/main.d.ts +0 -7
- package/dist/main.js +0 -66
- package/dist/ports/cache-store.d.ts +0 -10
- package/dist/ports/cache-store.js +0 -1
- package/dist/ports/chat-model.d.ts +0 -30
- package/dist/ports/chat-model.js +0 -1
- package/dist/ports/clipboard-adapter.d.ts +0 -7
- package/dist/ports/clipboard-adapter.js +0 -1
- package/dist/ports/clipboard-text-adapter.d.ts +0 -3
- package/dist/ports/clipboard-text-adapter.js +0 -1
- package/dist/ports/credential-store.d.ts +0 -7
- package/dist/ports/credential-store.js +0 -1
- package/dist/ports/goal-store.d.ts +0 -12
- package/dist/ports/goal-store.js +0 -1
- package/dist/ports/logger.d.ts +0 -8
- package/dist/ports/logger.js +0 -1
- package/dist/ports/media-gateway-client.d.ts +0 -54
- package/dist/ports/media-gateway-client.js +0 -1
- package/dist/ports/model-diagnostics.d.ts +0 -17
- package/dist/ports/model-diagnostics.js +0 -1
- package/dist/ports/project-trust-store.d.ts +0 -12
- package/dist/ports/project-trust-store.js +0 -1
- package/dist/ports/session-store.d.ts +0 -58
- package/dist/ports/session-store.js +0 -1
- package/dist/ports/subagent-lifecycle.d.ts +0 -31
- package/dist/ports/subagent-lifecycle.js +0 -1
- package/dist/ports/tool-activity.d.ts +0 -13
- package/dist/ports/tool-activity.js +0 -1
- package/dist/presentation/themes/theme.d.ts +0 -19
- package/dist/presentation/themes/theme.js +0 -8
- package/dist/presentation/tui/agent-initialization-renderer.d.ts +0 -4
- package/dist/presentation/tui/agent-initialization-renderer.js +0 -37
- package/dist/presentation/tui/context-display.d.ts +0 -21
- package/dist/presentation/tui/context-display.js +0 -33
- package/dist/presentation/tui/formatters.d.ts +0 -6
- package/dist/presentation/tui/formatters.js +0 -60
- package/dist/presentation/tui/ink/choice-window.d.ts +0 -5
- package/dist/presentation/tui/ink/choice-window.js +0 -5
- package/dist/presentation/tui/ink/components/activity-entry.d.ts +0 -6
- package/dist/presentation/tui/ink/components/activity-entry.js +0 -16
- package/dist/presentation/tui/ink/components/activity-status.d.ts +0 -10
- package/dist/presentation/tui/ink/components/activity-status.js +0 -21
- package/dist/presentation/tui/ink/components/choice-modal.d.ts +0 -11
- package/dist/presentation/tui/ink/components/choice-modal.js +0 -29
- package/dist/presentation/tui/ink/components/composer.d.ts +0 -40
- package/dist/presentation/tui/ink/components/composer.js +0 -271
- package/dist/presentation/tui/ink/components/file-diff.d.ts +0 -6
- package/dist/presentation/tui/ink/components/file-diff.js +0 -34
- package/dist/presentation/tui/ink/components/modal.d.ts +0 -8
- package/dist/presentation/tui/ink/components/modal.js +0 -110
- package/dist/presentation/tui/ink/components/shimmer-text.d.ts +0 -6
- package/dist/presentation/tui/ink/components/shimmer-text.js +0 -9
- package/dist/presentation/tui/ink/components/subagent-activity.d.ts +0 -11
- package/dist/presentation/tui/ink/components/subagent-activity.js +0 -61
- package/dist/presentation/tui/ink/components/transcript.d.ts +0 -39
- package/dist/presentation/tui/ink/components/transcript.js +0 -121
- package/dist/presentation/tui/ink/components/welcome-panel.d.ts +0 -6
- package/dist/presentation/tui/ink/components/welcome-panel.js +0 -20
- package/dist/presentation/tui/ink/lotagate-tui.d.ts +0 -6
- package/dist/presentation/tui/ink/lotagate-tui.js +0 -136
- package/dist/presentation/tui/ink/markdown-inline-renderer.d.ts +0 -4
- package/dist/presentation/tui/ink/markdown-inline-renderer.js +0 -20
- package/dist/presentation/tui/ink/markdown-inline.d.ts +0 -13
- package/dist/presentation/tui/ink/markdown-inline.js +0 -91
- package/dist/presentation/tui/ink/markdown-message.d.ts +0 -6
- package/dist/presentation/tui/ink/markdown-message.js +0 -66
- package/dist/presentation/tui/ink/markdown-table.d.ts +0 -16
- package/dist/presentation/tui/ink/markdown-table.js +0 -77
- package/dist/presentation/tui/ink/tui-bridge.d.ts +0 -195
- package/dist/presentation/tui/ink/tui-bridge.js +0 -289
- package/dist/presentation/tui/terminal-capabilities.d.ts +0 -15
- package/dist/presentation/tui/terminal-capabilities.js +0 -7
- package/dist/presentation/tui/terminal-mouse.d.ts +0 -5
- package/dist/presentation/tui/terminal-mouse.js +0 -19
- package/dist/presentation/tui/terminal-screen.d.ts +0 -10
- package/dist/presentation/tui/terminal-screen.js +0 -23
- package/dist/presentation/tui/tui-agent-event-runner.d.ts +0 -24
- package/dist/presentation/tui/tui-agent-event-runner.js +0 -69
- package/dist/presentation/tui/tui-application-contract.d.ts +0 -10
- package/dist/presentation/tui/tui-application-contract.js +0 -8
- package/dist/presentation/tui/tui-application.d.ts +0 -62
- package/dist/presentation/tui/tui-application.js +0 -675
- package/dist/presentation/tui/tui-attachment-input.d.ts +0 -2
- package/dist/presentation/tui/tui-attachment-input.js +0 -5
- package/dist/presentation/tui/tui-clipboard-paste-handlers.d.ts +0 -11
- package/dist/presentation/tui/tui-clipboard-paste-handlers.js +0 -25
- package/dist/presentation/tui/tui-command-context.d.ts +0 -3
- package/dist/presentation/tui/tui-command-context.js +0 -1
- package/dist/presentation/tui/tui-command-executor.d.ts +0 -38
- package/dist/presentation/tui/tui-command-executor.js +0 -214
- package/dist/presentation/tui/tui-command-host-factory.d.ts +0 -40
- package/dist/presentation/tui/tui-command-host-factory.js +0 -23
- package/dist/presentation/tui/tui-context-compaction.d.ts +0 -5
- package/dist/presentation/tui/tui-context-compaction.js +0 -22
- package/dist/presentation/tui/tui-context-service.d.ts +0 -34
- package/dist/presentation/tui/tui-context-service.js +0 -126
- package/dist/presentation/tui/tui-file-suggestions.d.ts +0 -3
- package/dist/presentation/tui/tui-file-suggestions.js +0 -8
- package/dist/presentation/tui/tui-goal-controller.d.ts +0 -14
- package/dist/presentation/tui/tui-goal-controller.js +0 -52
- package/dist/presentation/tui/tui-initial-model.d.ts +0 -3
- package/dist/presentation/tui/tui-initial-model.js +0 -28
- package/dist/presentation/tui/tui-lifecycle-actions.d.ts +0 -13
- package/dist/presentation/tui/tui-lifecycle-actions.js +0 -45
- package/dist/presentation/tui/tui-manual-compaction.d.ts +0 -18
- package/dist/presentation/tui/tui-manual-compaction.js +0 -31
- package/dist/presentation/tui/tui-media-model-selection.d.ts +0 -12
- package/dist/presentation/tui/tui-media-model-selection.js +0 -38
- package/dist/presentation/tui/tui-prompt-dispatcher.d.ts +0 -16
- package/dist/presentation/tui/tui-prompt-dispatcher.js +0 -38
- package/dist/presentation/tui/tui-skill-controller.d.ts +0 -11
- package/dist/presentation/tui/tui-skill-controller.js +0 -13
- package/dist/presentation/tui/tui-tool-approval.d.ts +0 -22
- package/dist/presentation/tui/tui-tool-approval.js +0 -73
- package/dist/version.d.ts +0 -1
- package/dist/version.js +0 -1
|
@@ -1,663 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { AuthenticationService } from '../auth/authentication-service.js';
|
|
3
|
-
import { createLotaGateClient } from '../../infrastructure/sdk/lotagate-client-factory.js';
|
|
4
|
-
import { ModelCatalogAdapter } from '../../infrastructure/sdk/model-catalog-adapter.js';
|
|
5
|
-
import { loadExecutionConfig } from '../config/execution-config.js';
|
|
6
|
-
import { prepareCliAgent } from '../agent/cli-agent-execution-service.js';
|
|
7
|
-
import { buildSafeSystemPrompt } from '../agent/safe-system-prompt.js';
|
|
8
|
-
import { createContextManagement } from '../agent/context-compaction.js';
|
|
9
|
-
import { persistContextCompaction } from '../agent/context-compaction-persistence.js';
|
|
10
|
-
import { buildAgentInputContext } from '../agent/agent-input-context.js';
|
|
11
|
-
import { CliAgentSessionStore } from '../agent/agent-session-store.js';
|
|
12
|
-
import { ChatService } from '../chat/chat-service.js';
|
|
13
|
-
import { SdkChatCompletionAdapter } from '../../infrastructure/sdk/chat-completion-adapter.js';
|
|
14
|
-
import { CliTurnEventProjector } from '../orchestration/cli-turn-event-projector.js';
|
|
15
|
-
import { persistCliTurnEvent } from '../orchestration/cli-turn-persistence.js';
|
|
16
|
-
import { actionDisplayName, actionKind } from '../orchestration/cli-turn-events.js';
|
|
17
|
-
import { createTurnId, recordTurnCompletion, recordTurnFailure, recordTurnStart } from '../session/session-turn-lifecycle.js';
|
|
18
|
-
import { ProjectSessionAccess } from '../session/project-session-access.js';
|
|
19
|
-
import { formatShellCommandForDisplay, formatToolActivityName } from '../agent/tool-display.js';
|
|
20
|
-
import { permissionRuleForRequest } from '../security/workspace-permission-policy.js';
|
|
21
|
-
import { agentLimitNotice, classifyAgentLimit } from '../agent/agent-limit.js';
|
|
22
|
-
import { asCliError, CliError } from '../../domain/errors/cli-error.js';
|
|
23
|
-
import { CLI_ERROR_CODES } from '../../domain/errors/error-codes.js';
|
|
24
|
-
import { readLinesBounded } from './jsonl-protocol.js';
|
|
25
|
-
import { RESOURCE_LIMITS } from '../../domain/runtime/resource-limits.js';
|
|
26
|
-
import { getDesktopCommandCatalog } from './desktop-command-catalog.js';
|
|
27
|
-
import { executeDesktopCommand } from './desktop-command-executor.js';
|
|
28
|
-
import { DesktopAttachmentStore } from './desktop-attachment-store.js';
|
|
29
|
-
import { PlanGenerator } from '../orchestration/plan-generator.js';
|
|
30
|
-
import { planDesktopPayload, planStepPayload, subagentDesktopPayload } from './desktop-orchestration-events.js';
|
|
31
|
-
import { resolveModelContextWindow } from '../model/model-context-window.js';
|
|
32
|
-
import { parseDesktopExecutionPolicy } from './desktop-execution-policy.js';
|
|
33
|
-
import { JsonLineWriter } from './json-line-writer.js';
|
|
34
|
-
export const DESKTOP_PROTOCOL_VERSION = 2;
|
|
35
|
-
/**
|
|
36
|
-
* Local JSONL bridge for the Desktop application. It is deliberately kept in
|
|
37
|
-
* the CLI application layer: Desktop reuses CLI policy and runtime, while the
|
|
38
|
-
* public SDK packages remain independent libraries.
|
|
39
|
-
*/
|
|
40
|
-
export async function runDesktopAgentCommand(runtime, cwd, input, output) {
|
|
41
|
-
const protocol = new DesktopAgentProtocol(runtime, cwd, output);
|
|
42
|
-
return protocol.run(input);
|
|
43
|
-
}
|
|
44
|
-
class DesktopAgentProtocol {
|
|
45
|
-
runtime;
|
|
46
|
-
cwd;
|
|
47
|
-
writer;
|
|
48
|
-
turns = new Map();
|
|
49
|
-
sessionStores = new Map();
|
|
50
|
-
attachments = new DesktopAttachmentStore();
|
|
51
|
-
approvals = new Map();
|
|
52
|
-
trusts = new Map();
|
|
53
|
-
commands = new Map();
|
|
54
|
-
browserRequests = new Map();
|
|
55
|
-
hostRequests = new Map();
|
|
56
|
-
browserHostEnabled = false;
|
|
57
|
-
stopping = false;
|
|
58
|
-
constructor(runtime, cwd, output) {
|
|
59
|
-
this.runtime = runtime;
|
|
60
|
-
this.cwd = cwd;
|
|
61
|
-
this.writer = new JsonLineWriter(output);
|
|
62
|
-
}
|
|
63
|
-
async run(input) {
|
|
64
|
-
let errors = 0;
|
|
65
|
-
try {
|
|
66
|
-
for await (const line of readLinesBounded(input, RESOURCE_LIMITS.jsonlLineBytes)) {
|
|
67
|
-
if (line.trim().length === 0)
|
|
68
|
-
continue;
|
|
69
|
-
let raw;
|
|
70
|
-
try {
|
|
71
|
-
raw = JSON.parse(line);
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
errors += 1;
|
|
75
|
-
await this.writeError('unknown', 'protocol', toDesktopError(error));
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
if (isBrowserHostResponse(raw)) {
|
|
79
|
-
this.resolveBrowserRequest(raw);
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
if (isDesktopHostResponse(raw)) {
|
|
83
|
-
this.resolveDesktopHostRequest(raw);
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
let request;
|
|
87
|
-
try {
|
|
88
|
-
request = parseDesktopRequest(raw);
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
errors += 1;
|
|
92
|
-
await this.writeError('unknown', 'protocol', toDesktopError(error));
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
try {
|
|
96
|
-
await this.handle(request);
|
|
97
|
-
}
|
|
98
|
-
catch (error) {
|
|
99
|
-
errors += 1;
|
|
100
|
-
await this.writeError(request.id, request.method, toDesktopError(error));
|
|
101
|
-
}
|
|
102
|
-
if (this.stopping)
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
catch (error) {
|
|
107
|
-
errors += 1;
|
|
108
|
-
await this.writeError('unknown', 'protocol', toDesktopError(error));
|
|
109
|
-
}
|
|
110
|
-
finally {
|
|
111
|
-
for (const turn of this.turns.values())
|
|
112
|
-
turn.controller.abort();
|
|
113
|
-
await Promise.allSettled([...this.turns.values()].map((turn) => turn.operation));
|
|
114
|
-
for (const command of this.commands.values())
|
|
115
|
-
command.controller.abort();
|
|
116
|
-
await Promise.allSettled([...this.commands.values()].map((command) => command.operation));
|
|
117
|
-
for (const waiter of this.browserRequests.values()) {
|
|
118
|
-
if (waiter.onAbort !== undefined)
|
|
119
|
-
waiter.signal?.removeEventListener('abort', waiter.onAbort);
|
|
120
|
-
waiter.reject(new Error('The Desktop browser bridge was closed.'));
|
|
121
|
-
}
|
|
122
|
-
this.browserRequests.clear();
|
|
123
|
-
for (const waiter of this.hostRequests.values()) {
|
|
124
|
-
if (waiter.onAbort !== undefined)
|
|
125
|
-
waiter.signal?.removeEventListener('abort', waiter.onAbort);
|
|
126
|
-
waiter.reject(new Error('The Desktop execution bridge was closed.'));
|
|
127
|
-
}
|
|
128
|
-
this.hostRequests.clear();
|
|
129
|
-
this.attachments.clear();
|
|
130
|
-
await this.writer.flush();
|
|
131
|
-
}
|
|
132
|
-
return errors === 0 ? 0 : 1;
|
|
133
|
-
}
|
|
134
|
-
async handle(request) {
|
|
135
|
-
switch (request.method) {
|
|
136
|
-
case 'initialize':
|
|
137
|
-
this.browserHostEnabled = request.params['browserHost'] === true;
|
|
138
|
-
return this.respond(request, { protocol: 'lotagate.desktop', version: DESKTOP_PROTOCOL_VERSION, capabilities: ['sessions', 'streaming', 'tool-approval', 'project-trust', 'models', 'auth', 'commands', 'image-attachments', 'file-attachments', 'execution-context', 'tool-allowlist', 'approval-reviews', 'lifecycle-controls', 'execution-broker', ...(this.browserHostEnabled ? ['browser-host'] : [])] });
|
|
139
|
-
case 'session.create': return this.createSession(request);
|
|
140
|
-
case 'session.list': return this.listSessions(request);
|
|
141
|
-
case 'session.resume': return this.resumeSession(request);
|
|
142
|
-
case 'attachment.begin':
|
|
143
|
-
this.attachments.begin({ id: request.params.attachmentId, name: request.params.name, mimeType: request.params.mimeType, sizeBytes: request.params.sizeBytes });
|
|
144
|
-
return this.respond(request, { accepted: true, attachmentId: request.params.attachmentId });
|
|
145
|
-
case 'attachment.chunk':
|
|
146
|
-
this.attachments.appendChunk(request.params.attachmentId, request.params.index, request.params.dataBase64);
|
|
147
|
-
return this.respond(request, { accepted: true, attachmentId: request.params.attachmentId, index: request.params.index });
|
|
148
|
-
case 'attachment.complete':
|
|
149
|
-
this.attachments.complete(request.params.attachmentId);
|
|
150
|
-
return this.respond(request, { accepted: true, attachmentId: request.params.attachmentId });
|
|
151
|
-
case 'turn.start': return this.startTurn(request);
|
|
152
|
-
case 'turn.cancel': return this.cancelTurn(request);
|
|
153
|
-
case 'approval.respond': return this.respondApproval(request);
|
|
154
|
-
case 'trust.respond': return this.respondTrust(request);
|
|
155
|
-
case 'model.list': return this.listModels(request);
|
|
156
|
-
case 'auth.status': return this.authStatus(request);
|
|
157
|
-
case 'command.list': return this.listCommands(request);
|
|
158
|
-
case 'command.execute': return this.startCommand(request);
|
|
159
|
-
case 'command.cancel': return this.cancelCommand(request);
|
|
160
|
-
case 'shutdown':
|
|
161
|
-
this.stopping = true;
|
|
162
|
-
await this.respond(request, { stopping: true });
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
async createSession(request) {
|
|
167
|
-
const identity = await this.runtime.projectTrust.inspect(this.cwd);
|
|
168
|
-
const loaded = await loadExecutionConfig(this.runtime, this.cwd);
|
|
169
|
-
const profile = loaded.config.profile ?? AuthenticationService.defaultProfileName();
|
|
170
|
-
const session = await this.runtime.sessionStore.create({ projectFingerprint: identity.fingerprint, cwd: identity.canonicalPath, model: request.params.model ?? loaded.config.model, profile, status: 'active', ...(request.params.name === undefined ? {} : { name: request.params.name }) });
|
|
171
|
-
await this.respond(request, sessionResult(session));
|
|
172
|
-
}
|
|
173
|
-
async listSessions(request) {
|
|
174
|
-
const identity = await this.runtime.projectTrust.inspect(this.cwd);
|
|
175
|
-
await this.respond(request, { sessions: await this.runtime.sessionStore.list(identity.fingerprint) });
|
|
176
|
-
}
|
|
177
|
-
async resumeSession(request) {
|
|
178
|
-
const identity = await this.runtime.projectTrust.inspect(this.cwd);
|
|
179
|
-
const session = await new ProjectSessionAccess(this.runtime.sessionStore).require(request.params.sessionId, identity.fingerprint);
|
|
180
|
-
await this.respond(request, { ...sessionResult(session), history: await this.runtime.sessionStore.readHistory(session.id) });
|
|
181
|
-
}
|
|
182
|
-
async startTurn(request) {
|
|
183
|
-
const { sessionId } = request.params;
|
|
184
|
-
if ([...this.turns.values()].some((turn) => turn.sessionId === sessionId))
|
|
185
|
-
throw new CliError(CLI_ERROR_CODES.INVALID_ARGUMENT, 'A turn is already active for this session.', { category: 'session', userMessage: 'This session already has an active turn.' });
|
|
186
|
-
const identity = await this.runtime.projectTrust.inspect(this.cwd);
|
|
187
|
-
const session = await new ProjectSessionAccess(this.runtime.sessionStore).require(sessionId, identity.fingerprint);
|
|
188
|
-
const attachments = this.attachments.take(request.params.attachmentIds ?? []);
|
|
189
|
-
const turnId = createTurnId();
|
|
190
|
-
const controller = new AbortController();
|
|
191
|
-
const operation = this.executeTurn(request, session, identity, turnId, controller, attachments).catch(async (error) => {
|
|
192
|
-
await this.writeEvent(controller.signal.aborted ? 'turn.cancelled' : 'turn.failed', { turnId, sessionId, ...(controller.signal.aborted ? {} : { error: toDesktopError(error) }) });
|
|
193
|
-
}).finally(() => { this.turns.delete(turnId); });
|
|
194
|
-
this.turns.set(turnId, { sessionId, controller, operation });
|
|
195
|
-
await this.respond(request, { accepted: true, turnId, sessionId });
|
|
196
|
-
}
|
|
197
|
-
async executeTurn(request, session, identity, turnId, controller, attachments) {
|
|
198
|
-
const loaded = await loadExecutionConfig(this.runtime, this.cwd);
|
|
199
|
-
const trusted = await this.runtime.projectTrust.isTrusted(identity);
|
|
200
|
-
if (!trusted) {
|
|
201
|
-
const trustRequestId = randomUUID();
|
|
202
|
-
await this.writeEvent('trust.requested', { trustRequestId, sessionId: session.id, path: identity.canonicalPath });
|
|
203
|
-
if (!(await this.waitForTrust(trustRequestId, controller.signal)))
|
|
204
|
-
throw new CliError(CLI_ERROR_CODES.PROJECT_TRUST_REQUIRED, 'Project trust was not granted.', { category: 'project', userMessage: 'Trust this project in the Desktop application before running tools.' });
|
|
205
|
-
await this.runtime.projectTrust.grant(identity);
|
|
206
|
-
await this.runtime.workspaceSettings.ensureInitialized(identity.canonicalPath);
|
|
207
|
-
}
|
|
208
|
-
const model = request.params.model ?? session.model ?? loaded.config.model;
|
|
209
|
-
if (model === null || model === undefined)
|
|
210
|
-
throw new CliError(CLI_ERROR_CODES.MODEL_NOT_FOUND, 'No model is selected.', { category: 'model', userMessage: 'Select a model before starting a turn.' });
|
|
211
|
-
const profileName = session.profile ?? loaded.config.profile ?? AuthenticationService.defaultProfileName();
|
|
212
|
-
const credential = await this.runtime.auth.requireCredential(profileName);
|
|
213
|
-
const client = createLotaGateClient(credential.profile, credential.apiKey);
|
|
214
|
-
const contextWindow = await resolveModelContextWindow(this.runtime, model, profileName);
|
|
215
|
-
const store = this.sessionStores.get(session.id) ?? new CliAgentSessionStore();
|
|
216
|
-
this.sessionStores.set(session.id, store);
|
|
217
|
-
const response = [];
|
|
218
|
-
const persistedAttachments = await Promise.all(attachments.map(async (payload) => ({ ...payload, attachment: await this.runtime.sessionStore.saveAttachment(session.id, payload.attachment, payload.bytes) })));
|
|
219
|
-
await recordTurnStart(this.runtime.sessionStore, session.id, turnId, request.params.prompt, persistedAttachments.map(item => item.attachment.id));
|
|
220
|
-
await this.runtime.sessionStore.updateStatus(session.id, 'active');
|
|
221
|
-
await this.writeEvent('turn.started', { turnId, sessionId: session.id, model });
|
|
222
|
-
const plan = new PlanGenerator().generate(request.params.prompt);
|
|
223
|
-
const planned = plan.requiresApproval ? plan : undefined;
|
|
224
|
-
if (planned !== undefined) {
|
|
225
|
-
await this.writeEvent('plan.started', { ...planDesktopPayload(planned, turnId), sessionId: session.id });
|
|
226
|
-
if (planned.tasks[0] !== undefined)
|
|
227
|
-
await this.writeEvent('plan.step.started', { ...planStepPayload(planned, turnId, 0, 'started'), sessionId: session.id });
|
|
228
|
-
}
|
|
229
|
-
const subagentLifecycle = {
|
|
230
|
-
onSubagentLifecycle: event => this.writeEvent(`subagent.${event.type}`, subagentDesktopPayload(event, turnId)),
|
|
231
|
-
};
|
|
232
|
-
let closePrepared;
|
|
233
|
-
const timeout = setTimeout(() => controller.abort(), request.params.execution.timeoutMs);
|
|
234
|
-
try {
|
|
235
|
-
if (persistedAttachments.length > 0) {
|
|
236
|
-
response.push(await this.executeAttachmentTurn(request, session, identity, model, client, persistedAttachments, controller, turnId));
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
const execution = request.params.execution;
|
|
240
|
-
const prepared = await prepareCliAgent({
|
|
241
|
-
runtime: this.runtime, cwd: this.cwd, model, client, profile: 'interactive-trusted', approvalMode: desktopApprovalMode(execution.permissionPolicy), ...(execution.allowedTools === undefined ? {} : { allowedTools: execution.allowedTools }), ...(request.params.skills === undefined ? {} : { selectedSkills: request.params.skills }), browserAccess: execution.browserAccess, subagentLifecycle,
|
|
242
|
-
...(this.browserHostEnabled ? { browserHost: (hostRequest, signal) => this.requestBrowserHost(hostRequest, signal) } : {}),
|
|
243
|
-
...(this.browserHostEnabled ? { desktopHost: ((hostRequest, signal) => this.requestDesktopHost(hostRequest, signal)) } : {}),
|
|
244
|
-
executionBoundary: execution.isolation,
|
|
245
|
-
hostFallback: execution.hostFallback,
|
|
246
|
-
...(this.browserHostEnabled ? { onExecutionFallbackApproval: (approval, reason) => this.waitForApproval(approval, session.id, turnId, controller.signal, 'host', reason) } : {}),
|
|
247
|
-
contextManagement: createContextManagement({
|
|
248
|
-
client,
|
|
249
|
-
model,
|
|
250
|
-
...(contextWindow === undefined ? {} : { contextWindow }),
|
|
251
|
-
onCompactionStart: () => this.writeEvent('context.compacting', { turnId, sessionId: session.id }),
|
|
252
|
-
onSummaryFailure: (error) => this.runtime.logger.warn('Context summarization failed; using fallback summary.', { reason: error instanceof Error ? error.message : String(error) }),
|
|
253
|
-
}),
|
|
254
|
-
agentSessionStore: store,
|
|
255
|
-
prompt: (approval) => this.waitForApproval(approval, session.id, turnId, controller.signal, execution.isolation),
|
|
256
|
-
rememberApproval: (approval) => this.runtime.workspaceSettings.rememberAllow(identity.canonicalPath, permissionRuleForRequest(approval.toolName, approval.input)),
|
|
257
|
-
audit: async (decision) => { this.runtime.logger.info('Tool authorization decision.', { toolName: decision.toolName, decision: decision.decision, reason: decision.reason }); await this.runtime.sessionStore.appendEvent({ type: 'tool.approval', timestamp: new Date().toISOString(), sessionId: session.id, turnId, data: { toolName: decision.toolName, decision: decision.decision, reason: decision.reason } }); },
|
|
258
|
-
onModelComplete: (summary) => { if (summary.usage !== undefined)
|
|
259
|
-
void this.writeEvent('usage.updated', { turnId, sessionId: session.id, usage: summary.usage }); },
|
|
260
|
-
onWrite: (change) => { void this.writeEvent('file.changed', { turnId, sessionId: session.id, change }); },
|
|
261
|
-
});
|
|
262
|
-
closePrepared = prepared.close;
|
|
263
|
-
const projector = new CliTurnEventProjector();
|
|
264
|
-
const input = await prepared.buildInput(request.params.prompt);
|
|
265
|
-
await prepared.agent.initialize();
|
|
266
|
-
for await (const event of prepared.run({ input: input.input, model, sessionId: session.id, stream: true, signal: controller.signal })) {
|
|
267
|
-
if (event.type === 'context.compacted')
|
|
268
|
-
await persistContextCompaction(this.runtime, prepared, session.id, event.metrics, turnId);
|
|
269
|
-
for (const projected of projector.observe(event))
|
|
270
|
-
await this.emitProjected(projected, session.id, turnId, response);
|
|
271
|
-
if (event.type === 'session.failed') {
|
|
272
|
-
const limit = classifyAgentLimit(event.error);
|
|
273
|
-
if (limit === undefined)
|
|
274
|
-
throw event.error;
|
|
275
|
-
const notice = agentLimitNotice(limit);
|
|
276
|
-
response.push(notice);
|
|
277
|
-
const segmentId = `${turnId}:final`;
|
|
278
|
-
await this.writeEvent('assistant.delta', { turnId, sessionId: session.id, segmentId, iteration: 0, content: notice });
|
|
279
|
-
await this.writeEvent('assistant.segment.completed', { turnId, sessionId: session.id, segmentId, iteration: 0, phase: 'final' });
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
if (response.join('').trim().length === 0)
|
|
285
|
-
throw new CliError(CLI_ERROR_CODES.MODEL_PROTOCOL_EMPTY_RESPONSE, 'Agent completed without a final text response.', { category: 'model', userMessage: 'The model completed without a final text response.', retryable: true });
|
|
286
|
-
await recordTurnCompletion(this.runtime.sessionStore, session.id, turnId, response.join(''));
|
|
287
|
-
await this.runtime.sessionStore.updateStatus(session.id, 'completed');
|
|
288
|
-
if (planned !== undefined) {
|
|
289
|
-
for (let index = 0; index < planned.tasks.length; index += 1) {
|
|
290
|
-
await this.writeEvent('plan.step.completed', { ...planStepPayload(planned, turnId, index, 'completed'), sessionId: session.id });
|
|
291
|
-
if (index + 1 < planned.tasks.length)
|
|
292
|
-
await this.writeEvent('plan.step.started', { ...planStepPayload(planned, turnId, index + 1, 'started'), sessionId: session.id });
|
|
293
|
-
}
|
|
294
|
-
await this.writeEvent('plan.completed', { turnId, planId: planned.id, sessionId: session.id });
|
|
295
|
-
}
|
|
296
|
-
await this.writeEvent('turn.completed', { turnId, sessionId: session.id, content: response.join('') });
|
|
297
|
-
}
|
|
298
|
-
catch (error) {
|
|
299
|
-
if (planned !== undefined)
|
|
300
|
-
await this.writeEvent('plan.failed', { turnId, planId: planned.id, sessionId: session.id, error: toDesktopError(error) });
|
|
301
|
-
const cancelled = controller.signal.aborted;
|
|
302
|
-
await recordTurnFailure(this.runtime.sessionStore, session.id, turnId, error, cancelled);
|
|
303
|
-
await this.runtime.sessionStore.updateStatus(session.id, cancelled ? 'cancelled' : 'failed');
|
|
304
|
-
throw error;
|
|
305
|
-
}
|
|
306
|
-
finally {
|
|
307
|
-
if (timeout !== undefined)
|
|
308
|
-
clearTimeout(timeout);
|
|
309
|
-
if (closePrepared !== undefined) {
|
|
310
|
-
try {
|
|
311
|
-
await closePrepared();
|
|
312
|
-
}
|
|
313
|
-
catch (error) {
|
|
314
|
-
this.runtime.logger.warn('Desktop agent cleanup failed.', { reason: error instanceof Error ? error.message : String(error) });
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
async executeAttachmentTurn(request, session, identity, model, client, attachments, controller, turnId) {
|
|
320
|
-
const input = await buildAgentInputContext(request.params.prompt, identity.canonicalPath, true);
|
|
321
|
-
const system = await buildSafeSystemPrompt(this.runtime, this.cwd, model, 'interactive-untrusted');
|
|
322
|
-
const service = new ChatService(new SdkChatCompletionAdapter(client));
|
|
323
|
-
const response = [];
|
|
324
|
-
for await (const event of service.stream(model, input.input, { system, signal: controller.signal, attachments })) {
|
|
325
|
-
if (event.type === 'usage')
|
|
326
|
-
await this.writeEvent('usage.updated', { turnId, sessionId: session.id, usage: event.usage });
|
|
327
|
-
if (event.type === 'delta') {
|
|
328
|
-
response.push(event.content);
|
|
329
|
-
await this.writeEvent('assistant.delta', { turnId, sessionId: session.id, segmentId: `${turnId}:final`, iteration: 0, content: event.content });
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
if (response.length > 0)
|
|
333
|
-
await this.writeEvent('assistant.segment.completed', { turnId, sessionId: session.id, segmentId: `${turnId}:final`, iteration: 0, phase: 'final' });
|
|
334
|
-
return response.join('');
|
|
335
|
-
}
|
|
336
|
-
async emitProjected(event, sessionId, turnId, response) {
|
|
337
|
-
if (event.type === 'assistant.delta') {
|
|
338
|
-
response.push(event.content);
|
|
339
|
-
await this.writeEvent('assistant.delta', { turnId, sessionId, segmentId: event.segmentId, iteration: event.iteration, content: event.content });
|
|
340
|
-
}
|
|
341
|
-
else if (event.type === 'assistant.segment.completed')
|
|
342
|
-
await this.writeEvent('assistant.segment.completed', { turnId, sessionId, segmentId: event.segmentId, iteration: event.iteration, phase: event.phase });
|
|
343
|
-
else if (event.type === 'action.started')
|
|
344
|
-
await this.writeEvent('tool.started', { turnId, sessionId, actionId: event.actionId, toolName: event.toolName, displayName: event.displayName, kind: event.kind, ...(event.source === undefined ? {} : { source: event.source }) });
|
|
345
|
-
else if (event.type === 'action.completed')
|
|
346
|
-
await this.writeEvent('tool.completed', { turnId, sessionId, actionId: event.actionId, toolName: event.toolName, displayName: event.displayName, kind: event.kind, status: event.status, isError: event.isError });
|
|
347
|
-
else if (event.type === 'context.compacted')
|
|
348
|
-
await this.writeEvent('context.compacted', { turnId, sessionId });
|
|
349
|
-
await persistCliTurnEvent(this.runtime.sessionStore, sessionId, event, { turnId });
|
|
350
|
-
}
|
|
351
|
-
async waitForApproval(request, sessionId, turnId, signal, executionBoundary, fallbackReason) {
|
|
352
|
-
const approvalId = randomUUID();
|
|
353
|
-
await this.writeEvent('approval.requested', { approvalId, turnId, sessionId, toolName: request.toolName, displayName: actionDisplayName(request.toolName), kind: actionKind(request.toolName, request.toolInfo?.source), detail: describeApproval(request), executionBoundary, ...(fallbackReason === undefined ? {} : { fallbackReason }) });
|
|
354
|
-
return new Promise((resolve) => {
|
|
355
|
-
const finish = (approved) => { this.approvals.delete(approvalId); resolve(approved); };
|
|
356
|
-
if (signal.aborted) {
|
|
357
|
-
finish(false);
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
signal.addEventListener('abort', () => finish(false), { once: true });
|
|
361
|
-
this.approvals.set(approvalId, { resolve: finish, signal });
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
async waitForTrust(trustRequestId, signal) {
|
|
365
|
-
return new Promise((resolve) => {
|
|
366
|
-
const finish = (trusted) => { this.trusts.delete(trustRequestId); resolve(trusted); };
|
|
367
|
-
if (signal.aborted) {
|
|
368
|
-
finish(false);
|
|
369
|
-
return;
|
|
370
|
-
}
|
|
371
|
-
signal.addEventListener('abort', () => finish(false), { once: true });
|
|
372
|
-
this.trusts.set(trustRequestId, { resolve: finish, signal });
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
async cancelTurn(request) {
|
|
376
|
-
const turn = this.turns.get(request.params.turnId);
|
|
377
|
-
if (turn === undefined)
|
|
378
|
-
throw new CliError(CLI_ERROR_CODES.INVALID_ARGUMENT, 'Turn is not active.', { category: 'session', userMessage: 'The requested turn is not active.' });
|
|
379
|
-
turn.controller.abort();
|
|
380
|
-
await this.respond(request, { cancelled: true, turnId: request.params.turnId });
|
|
381
|
-
}
|
|
382
|
-
async respondApproval(request) {
|
|
383
|
-
const waiter = this.approvals.get(request.params.approvalId);
|
|
384
|
-
if (waiter === undefined)
|
|
385
|
-
throw new CliError(CLI_ERROR_CODES.INVALID_ARGUMENT, 'Approval request is no longer active.', { category: 'arguments', userMessage: 'This approval request is no longer active.' });
|
|
386
|
-
waiter.resolve(request.params.approved);
|
|
387
|
-
await this.respond(request, { accepted: true });
|
|
388
|
-
}
|
|
389
|
-
async respondTrust(request) {
|
|
390
|
-
const waiter = this.trusts.get(request.params.trustRequestId);
|
|
391
|
-
if (waiter === undefined)
|
|
392
|
-
throw new CliError(CLI_ERROR_CODES.INVALID_ARGUMENT, 'Trust request is no longer active.', { category: 'arguments', userMessage: 'This trust request is no longer active.' });
|
|
393
|
-
waiter.resolve(request.params.trusted);
|
|
394
|
-
await this.respond(request, { accepted: true });
|
|
395
|
-
}
|
|
396
|
-
async listModels(request) {
|
|
397
|
-
const loaded = await loadExecutionConfig(this.runtime, this.cwd);
|
|
398
|
-
const profile = loaded.config.profile ?? AuthenticationService.defaultProfileName();
|
|
399
|
-
const credential = await this.runtime.auth.requireCredential(profile);
|
|
400
|
-
const models = await new ModelCatalogAdapter(createLotaGateClient(credential.profile, credential.apiKey)).listModels();
|
|
401
|
-
await this.respond(request, { models: models.data });
|
|
402
|
-
}
|
|
403
|
-
async authStatus(request) {
|
|
404
|
-
const loaded = await this.runtime.configLoader.load(this.cwd, { includeProject: false });
|
|
405
|
-
const profile = loaded.config.profile ?? AuthenticationService.defaultProfileName();
|
|
406
|
-
const credential = await this.runtime.credentialStore.get(profile);
|
|
407
|
-
await this.respond(request, { authenticated: credential !== undefined, profile, ...(credential === undefined ? {} : { baseUrl: credential.profile.baseUrl, credentialRef: credential.profile.credentialRef }) });
|
|
408
|
-
}
|
|
409
|
-
async listCommands(request) {
|
|
410
|
-
await this.respond(request, getDesktopCommandCatalog());
|
|
411
|
-
}
|
|
412
|
-
async startCommand(request) {
|
|
413
|
-
const commandId = randomUUID();
|
|
414
|
-
const controller = new AbortController();
|
|
415
|
-
const operation = Promise.resolve()
|
|
416
|
-
.then(() => this.executeCommand(request, commandId, controller))
|
|
417
|
-
.catch(async (error) => {
|
|
418
|
-
if (controller.signal.aborted) {
|
|
419
|
-
await this.writeEvent('command.cancelled', { commandId, actionId: request.params.actionId });
|
|
420
|
-
return;
|
|
421
|
-
}
|
|
422
|
-
await this.writeEvent('command.failed', { commandId, actionId: request.params.actionId, error: toDesktopError(error) });
|
|
423
|
-
})
|
|
424
|
-
.finally(() => this.commands.delete(commandId));
|
|
425
|
-
this.commands.set(commandId, { controller, operation });
|
|
426
|
-
const result = { accepted: true, commandId, actionId: request.params.actionId };
|
|
427
|
-
await this.respond(request, result);
|
|
428
|
-
}
|
|
429
|
-
async executeCommand(request, commandId, controller) {
|
|
430
|
-
await this.writeEvent('command.started', { commandId, actionId: request.params.actionId });
|
|
431
|
-
const exitCode = await executeDesktopCommand({
|
|
432
|
-
runtime: this.runtime,
|
|
433
|
-
cwd: this.cwd,
|
|
434
|
-
invocation: request.params,
|
|
435
|
-
signal: controller.signal,
|
|
436
|
-
output: {
|
|
437
|
-
write: (content, structured) => this.writeEvent('command.output', {
|
|
438
|
-
commandId,
|
|
439
|
-
actionId: request.params.actionId,
|
|
440
|
-
content,
|
|
441
|
-
...(structured === undefined ? {} : { structured }),
|
|
442
|
-
}),
|
|
443
|
-
},
|
|
444
|
-
activity: {
|
|
445
|
-
started: (key, label) => this.writeEvent('command.activity.started', { commandId, actionId: request.params.actionId, key, label }),
|
|
446
|
-
completed: (key, isError) => this.writeEvent('command.activity.completed', { commandId, actionId: request.params.actionId, key, isError }),
|
|
447
|
-
},
|
|
448
|
-
});
|
|
449
|
-
await this.writeEvent('command.completed', { commandId, actionId: request.params.actionId, exitCode, success: exitCode === 0 });
|
|
450
|
-
}
|
|
451
|
-
async cancelCommand(request) {
|
|
452
|
-
const command = this.commands.get(request.params.commandId);
|
|
453
|
-
if (command === undefined) {
|
|
454
|
-
throw new CliError(CLI_ERROR_CODES.INVALID_ARGUMENT, 'Command is not active.', { category: 'command', userMessage: 'The requested command is not active.' });
|
|
455
|
-
}
|
|
456
|
-
command.controller.abort();
|
|
457
|
-
await this.respond(request, { accepted: true, commandId: request.params.commandId });
|
|
458
|
-
}
|
|
459
|
-
async requestBrowserHost(request, signal) {
|
|
460
|
-
if (this.stopping)
|
|
461
|
-
throw new Error('The Desktop browser bridge is stopping.');
|
|
462
|
-
const operation = new Promise((resolve, reject) => {
|
|
463
|
-
const waiter = { resolve, reject, ...(signal === undefined ? {} : { signal }) };
|
|
464
|
-
if (signal !== undefined) {
|
|
465
|
-
if (signal.aborted) {
|
|
466
|
-
reject(new Error('Browser action was cancelled.'));
|
|
467
|
-
return;
|
|
468
|
-
}
|
|
469
|
-
waiter.onAbort = () => { this.browserRequests.delete(request.requestId); reject(new Error('Browser action was cancelled.')); };
|
|
470
|
-
signal.addEventListener('abort', waiter.onAbort, { once: true });
|
|
471
|
-
}
|
|
472
|
-
this.browserRequests.set(request.requestId, waiter);
|
|
473
|
-
});
|
|
474
|
-
try {
|
|
475
|
-
await this.writer.write(request);
|
|
476
|
-
return await operation;
|
|
477
|
-
}
|
|
478
|
-
finally {
|
|
479
|
-
const waiter = this.browserRequests.get(request.requestId);
|
|
480
|
-
if (waiter !== undefined) {
|
|
481
|
-
if (waiter.onAbort !== undefined)
|
|
482
|
-
waiter.signal?.removeEventListener('abort', waiter.onAbort);
|
|
483
|
-
this.browserRequests.delete(request.requestId);
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
async requestDesktopHost(request, signal) {
|
|
488
|
-
if (this.stopping)
|
|
489
|
-
throw new Error('The Desktop execution bridge is stopping.');
|
|
490
|
-
const operation = new Promise((resolve, reject) => {
|
|
491
|
-
const waiter = { resolve, reject, ...(signal === undefined ? {} : { signal }) };
|
|
492
|
-
if (signal !== undefined) {
|
|
493
|
-
if (signal.aborted) {
|
|
494
|
-
reject(new Error('Host execution was cancelled.'));
|
|
495
|
-
return;
|
|
496
|
-
}
|
|
497
|
-
waiter.onAbort = () => { this.hostRequests.delete(request.requestId); reject(new Error('Host execution was cancelled.')); };
|
|
498
|
-
signal.addEventListener('abort', waiter.onAbort, { once: true });
|
|
499
|
-
}
|
|
500
|
-
this.hostRequests.set(request.requestId, waiter);
|
|
501
|
-
});
|
|
502
|
-
try {
|
|
503
|
-
await this.writer.write(request);
|
|
504
|
-
return await operation;
|
|
505
|
-
}
|
|
506
|
-
finally {
|
|
507
|
-
const waiter = this.hostRequests.get(request.requestId);
|
|
508
|
-
if (waiter !== undefined) {
|
|
509
|
-
if (waiter.onAbort !== undefined)
|
|
510
|
-
waiter.signal?.removeEventListener('abort', waiter.onAbort);
|
|
511
|
-
this.hostRequests.delete(request.requestId);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
resolveBrowserRequest(response) {
|
|
516
|
-
const waiter = this.browserRequests.get(response.requestId);
|
|
517
|
-
if (waiter === undefined)
|
|
518
|
-
return;
|
|
519
|
-
if (waiter.onAbort !== undefined)
|
|
520
|
-
waiter.signal?.removeEventListener('abort', waiter.onAbort);
|
|
521
|
-
this.browserRequests.delete(response.requestId);
|
|
522
|
-
waiter.resolve(response);
|
|
523
|
-
}
|
|
524
|
-
resolveDesktopHostRequest(response) {
|
|
525
|
-
const waiter = this.hostRequests.get(response.requestId);
|
|
526
|
-
if (waiter === undefined)
|
|
527
|
-
return;
|
|
528
|
-
if (waiter.onAbort !== undefined)
|
|
529
|
-
waiter.signal?.removeEventListener('abort', waiter.onAbort);
|
|
530
|
-
this.hostRequests.delete(response.requestId);
|
|
531
|
-
waiter.resolve(response);
|
|
532
|
-
}
|
|
533
|
-
async respond(request, result) { await this.writer.write({ version: DESKTOP_PROTOCOL_VERSION, id: request.id, type: 'response', method: request.method, ok: true, result }); }
|
|
534
|
-
async writeError(id, method, error) { await this.writer.write({ version: DESKTOP_PROTOCOL_VERSION, id, type: 'response', method, ok: false, error }); }
|
|
535
|
-
async writeEvent(event, data) { await this.writer.write({ version: DESKTOP_PROTOCOL_VERSION, type: 'event', event, data }); }
|
|
536
|
-
}
|
|
537
|
-
function parseDesktopRequest(value) {
|
|
538
|
-
if (!isRecord(value) || value['version'] !== DESKTOP_PROTOCOL_VERSION || !validId(value['id']) || !isRecord(value['params']) || typeof value['method'] !== 'string')
|
|
539
|
-
throw protocolError('Invalid Desktop protocol request.');
|
|
540
|
-
const id = value['id'];
|
|
541
|
-
const method = value['method'];
|
|
542
|
-
const params = value['params'];
|
|
543
|
-
if (method === 'initialize' || method === 'session.list' || method === 'model.list' || method === 'auth.status' || method === 'command.list' || method === 'shutdown')
|
|
544
|
-
return { version: 2, id, method, params };
|
|
545
|
-
if (method === 'session.create')
|
|
546
|
-
return { version: 2, id, method, params: { ...(optionalString(params, 'model')), ...(optionalString(params, 'name')) } };
|
|
547
|
-
if (method === 'session.resume')
|
|
548
|
-
return { version: 2, id, method, params: { sessionId: requiredId(params, 'sessionId') } };
|
|
549
|
-
if (method === 'attachment.begin')
|
|
550
|
-
return { version: 2, id, method, params: { attachmentId: requiredId(params, 'attachmentId'), name: requiredAttachmentName(params), mimeType: requiredMimeType(params), sizeBytes: requiredAttachmentSize(params) } };
|
|
551
|
-
if (method === 'attachment.chunk')
|
|
552
|
-
return { version: 2, id, method, params: { attachmentId: requiredId(params, 'attachmentId'), index: requiredChunkIndex(params), dataBase64: requiredChunkData(params) } };
|
|
553
|
-
if (method === 'attachment.complete')
|
|
554
|
-
return { version: 2, id, method, params: { attachmentId: requiredId(params, 'attachmentId') } };
|
|
555
|
-
if (method === 'turn.start')
|
|
556
|
-
return { version: 2, id, method, params: { sessionId: requiredId(params, 'sessionId'), prompt: requiredPrompt(params), ...(optionalString(params, 'model')), ...(optionalAttachmentIds(params)), ...(optionalSkills(params)), execution: requiredExecutionPolicy(params) } };
|
|
557
|
-
if (method === 'turn.cancel')
|
|
558
|
-
return { version: 2, id, method, params: { turnId: requiredId(params, 'turnId') } };
|
|
559
|
-
if (method === 'approval.respond')
|
|
560
|
-
return { version: 2, id, method, params: { approvalId: requiredId(params, 'approvalId'), approved: requiredBoolean(params, 'approved') } };
|
|
561
|
-
if (method === 'trust.respond')
|
|
562
|
-
return { version: 2, id, method, params: { trustRequestId: requiredId(params, 'trustRequestId'), trusted: requiredBoolean(params, 'trusted') } };
|
|
563
|
-
if (method === 'command.execute')
|
|
564
|
-
return { version: 2, id, method, params: parseCommandInvocation(params) };
|
|
565
|
-
if (method === 'command.cancel')
|
|
566
|
-
return { version: 2, id, method, params: { commandId: requiredId(params, 'commandId') } };
|
|
567
|
-
throw protocolError('Unsupported Desktop protocol method.');
|
|
568
|
-
}
|
|
569
|
-
function isBrowserHostResponse(value) {
|
|
570
|
-
if (!isRecord(value) || value['version'] !== DESKTOP_PROTOCOL_VERSION || value['type'] !== 'host.response' || value['tool'] !== 'browser' || !validId(value['requestId']) || typeof value['ok'] !== 'boolean')
|
|
571
|
-
return false;
|
|
572
|
-
if (value['error'] !== undefined && !isRecord(value['error']))
|
|
573
|
-
return false;
|
|
574
|
-
return true;
|
|
575
|
-
}
|
|
576
|
-
function isDesktopHostResponse(value) {
|
|
577
|
-
if (!isRecord(value) || value['version'] !== DESKTOP_PROTOCOL_VERSION || value['type'] !== 'host.response' || !['filesystem', 'shell', 'git', 'artifact'].includes(String(value['tool'])) || !validId(value['requestId']) || typeof value['ok'] !== 'boolean')
|
|
578
|
-
return false;
|
|
579
|
-
if (value['error'] !== undefined && !isRecord(value['error']))
|
|
580
|
-
return false;
|
|
581
|
-
return true;
|
|
582
|
-
}
|
|
583
|
-
function parseCommandInvocation(params) {
|
|
584
|
-
const actionId = requiredId(params, 'actionId');
|
|
585
|
-
const positionals = params['positionals'];
|
|
586
|
-
if (!Array.isArray(positionals) || positionals.some(value => typeof value !== 'string' || Buffer.byteLength(value, 'utf8') > RESOURCE_LIMITS.jsonlPromptBytes)) {
|
|
587
|
-
throw protocolError('Invalid command positionals.');
|
|
588
|
-
}
|
|
589
|
-
const options = params['options'];
|
|
590
|
-
if (!isRecord(options) || Object.entries(options).some(([key, value]) => !validId(key) || (typeof value !== 'string' && typeof value !== 'boolean') || (typeof value === 'string' && Buffer.byteLength(value, 'utf8') > RESOURCE_LIMITS.jsonlPromptBytes))) {
|
|
591
|
-
throw protocolError('Invalid command options.');
|
|
592
|
-
}
|
|
593
|
-
return { actionId, positionals, options: options };
|
|
594
|
-
}
|
|
595
|
-
function requiredId(params, key) { const value = params[key]; if (!validId(value))
|
|
596
|
-
throw protocolError(`Invalid ${key}.`); return value; }
|
|
597
|
-
function requiredPrompt(params) { const value = params['prompt']; if (typeof value !== 'string' || value.trim().length === 0 || Buffer.byteLength(value, 'utf8') > RESOURCE_LIMITS.jsonlPromptBytes)
|
|
598
|
-
throw protocolError('Invalid prompt.'); return value; }
|
|
599
|
-
function requiredBoolean(params, key) { if (typeof params[key] !== 'boolean')
|
|
600
|
-
throw protocolError(`Invalid ${key}.`); return params[key]; }
|
|
601
|
-
function optionalString(params, key) { const value = params[key]; if (value === undefined)
|
|
602
|
-
return {}; if (typeof value !== 'string' || value.length === 0 || Buffer.byteLength(value, 'utf8') > RESOURCE_LIMITS.jsonlIdBytes)
|
|
603
|
-
throw protocolError(`Invalid ${key}.`); return { [key]: value }; }
|
|
604
|
-
function requiredAttachmentName(params) { const value = params['name']; if (typeof value !== 'string' || value.length === 0 || value.length > 200 || value.includes('\0'))
|
|
605
|
-
throw protocolError('Invalid attachment name.'); return value; }
|
|
606
|
-
function requiredMimeType(params) { const value = params['mimeType']; if (typeof value !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]*\/[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]*$/u.test(value) || Buffer.byteLength(value, 'utf8') > RESOURCE_LIMITS.jsonlIdBytes)
|
|
607
|
-
throw protocolError('Invalid attachment MIME type.'); return value; }
|
|
608
|
-
function requiredAttachmentSize(params) { const value = params['sizeBytes']; if (typeof value !== 'number' || !Number.isSafeInteger(value) || value <= 0 || value > RESOURCE_LIMITS.maxAttachmentBytes)
|
|
609
|
-
throw protocolError('Invalid attachment size.'); return value; }
|
|
610
|
-
function requiredChunkIndex(params) { const value = params['index']; if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 0)
|
|
611
|
-
throw protocolError('Invalid attachment chunk index.'); return value; }
|
|
612
|
-
function requiredChunkData(params) { const value = params['dataBase64']; if (typeof value !== 'string' || value.length === 0 || Buffer.byteLength(value, 'utf8') > Math.ceil(RESOURCE_LIMITS.desktopAttachmentChunkBytes / 3) * 4 + 4)
|
|
613
|
-
throw protocolError('Invalid attachment chunk.'); return value; }
|
|
614
|
-
function optionalAttachmentIds(params) {
|
|
615
|
-
const value = params['attachmentIds'];
|
|
616
|
-
if (value === undefined)
|
|
617
|
-
return {};
|
|
618
|
-
if (!Array.isArray(value) || value.length > RESOURCE_LIMITS.pendingAttachments || value.some(id => !validId(id)) || new Set(value).size !== value.length)
|
|
619
|
-
throw protocolError('Invalid attachment ids.');
|
|
620
|
-
return { attachmentIds: value };
|
|
621
|
-
}
|
|
622
|
-
function optionalSkills(params) {
|
|
623
|
-
const value = params['skills'];
|
|
624
|
-
if (value === undefined)
|
|
625
|
-
return {};
|
|
626
|
-
if (!Array.isArray(value) || value.length > 32 || value.some(skill => !validId(skill)) || new Set(value).size !== value.length)
|
|
627
|
-
throw protocolError('Invalid skills.');
|
|
628
|
-
return { skills: value };
|
|
629
|
-
}
|
|
630
|
-
function requiredExecutionPolicy(params) { return parseDesktopExecutionPolicy(params['execution']); }
|
|
631
|
-
function validId(value) { return typeof value === 'string' && value.length > 0 && Buffer.byteLength(value, 'utf8') <= RESOURCE_LIMITS.jsonlIdBytes; }
|
|
632
|
-
function isRecord(value) { return typeof value === 'object' && value !== null && !Array.isArray(value); }
|
|
633
|
-
function protocolError(message) { return new Error(message); }
|
|
634
|
-
function desktopApprovalMode(policy) {
|
|
635
|
-
if (policy === 'allowlist')
|
|
636
|
-
return 'auto';
|
|
637
|
-
if (policy === 'review')
|
|
638
|
-
return 'review';
|
|
639
|
-
if (policy === 'autonomous')
|
|
640
|
-
return 'autonomous';
|
|
641
|
-
return 'ask';
|
|
642
|
-
}
|
|
643
|
-
function toDesktopError(error) {
|
|
644
|
-
if (typeof error === 'object' && error !== null) {
|
|
645
|
-
const value = error;
|
|
646
|
-
if (typeof value['code'] === 'string' && typeof value['category'] === 'string' && typeof value['userMessage'] === 'string' && typeof value['retryable'] === 'boolean')
|
|
647
|
-
return { code: value['code'], category: value['category'], message: value['userMessage'], retryable: value['retryable'] };
|
|
648
|
-
}
|
|
649
|
-
const cliError = asCliError(error);
|
|
650
|
-
return { code: cliError.code, category: cliError.category, message: cliError.userMessage, retryable: cliError.retryable };
|
|
651
|
-
}
|
|
652
|
-
function sessionResult(session) { return { session }; }
|
|
653
|
-
function describeApproval(request) {
|
|
654
|
-
if (request.toolName === 'filesystem.write')
|
|
655
|
-
return { summary: `Write workspace file: ${safeText(request.input['path'])}`, path: safeText(request.input['path']) };
|
|
656
|
-
if (request.toolName === 'shell.exec') {
|
|
657
|
-
const command = typeof request.input['command'] === 'string' ? request.input['command'] : '';
|
|
658
|
-
const args = Array.isArray(request.input['args']) ? request.input['args'].filter((value) => typeof value === 'string') : [];
|
|
659
|
-
return { summary: `Run command: ${formatShellCommandForDisplay(command, args, 240)}`, command, args };
|
|
660
|
-
}
|
|
661
|
-
return { summary: `This ${formatToolActivityName(request.toolName)} operation may change workspace or external state.` };
|
|
662
|
-
}
|
|
663
|
-
function safeText(value) { return String(value ?? '').replace(/Bearer\s+[^\s]+/giu, 'Bearer [REDACTED]').replace(/sk-[A-Za-z0-9_-]{8,}/gu, '[REDACTED]').slice(0, 240); }
|