@viewportai/daemon 0.30.0 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +25 -0
- package/README.md +339 -242
- package/dist/chunk-33YDFYW2.js +355 -0
- package/dist/chunk-5MLJY3NS.js +182 -0
- package/dist/chunk-62D4ICYA.js +634 -0
- package/dist/chunk-76ISR4QO.js +5045 -0
- package/dist/chunk-BFV7PIQD.js +639 -0
- package/dist/chunk-EACFI34X.js +2307 -0
- package/dist/chunk-FXZH5JGQ.js +599 -0
- package/dist/chunk-K2WDCPZB.js +377 -0
- package/dist/chunk-NBLB22VR.js +70 -0
- package/dist/chunk-YJFNBSD3.js +229 -0
- package/dist/cli/bin.d.ts +1 -0
- package/dist/cli/bin.js +2311 -0
- package/dist/client/index.d.ts +294 -0
- package/dist/client/index.js +708 -0
- package/dist/identity-CH_omX_I.d.ts +20 -0
- package/dist/index.d.ts +109 -26
- package/dist/index.js +34 -223
- package/dist/info-aU2-5A8G.d.ts +602 -0
- package/dist/pipe-BlqIy51a.d.ts +19 -0
- package/dist/protocol/index.d.ts +113 -0
- package/dist/protocol/index.js +222 -0
- package/dist/pushes-B1v3BF2N.d.ts +659 -0
- package/dist/relay/index.d.ts +122 -0
- package/dist/relay/index.js +26 -0
- package/dist/results-Ct1ZVYOZ.d.ts +716 -0
- package/dist/serve-MuBojIIs.d.ts +155 -0
- package/dist/server/index.d.ts +165 -0
- package/dist/server/index.js +31 -0
- package/dist/supervisor-CZ_i_hSc.d.ts +791 -0
- package/dist/testing/index.d.ts +163 -0
- package/dist/testing/index.js +445 -0
- package/dist/testing/vitest.d.ts +12 -0
- package/dist/testing/vitest.js +58 -0
- package/package.json +88 -86
- package/spec/schemas/daemon/channel/v1.json +176 -0
- package/spec/schemas/daemon/event/v1.json +551 -0
- package/spec/schemas/daemon/protocol/v1.json +1557 -0
- package/bin/vpd.js +0 -2
- package/dist/adapters/claude-message-normalizer.d.ts +0 -24
- package/dist/adapters/claude-message-normalizer.d.ts.map +0 -1
- package/dist/adapters/claude-message-normalizer.js +0 -192
- package/dist/adapters/claude-message-normalizer.js.map +0 -1
- package/dist/adapters/claude.d.ts +0 -104
- package/dist/adapters/claude.d.ts.map +0 -1
- package/dist/adapters/claude.js +0 -503
- package/dist/adapters/claude.js.map +0 -1
- package/dist/adapters/codex-event-normalizers.d.ts +0 -10
- package/dist/adapters/codex-event-normalizers.d.ts.map +0 -1
- package/dist/adapters/codex-event-normalizers.js +0 -261
- package/dist/adapters/codex-event-normalizers.js.map +0 -1
- package/dist/adapters/codex-sdk-loader.d.ts +0 -48
- package/dist/adapters/codex-sdk-loader.d.ts.map +0 -1
- package/dist/adapters/codex-sdk-loader.js +0 -19
- package/dist/adapters/codex-sdk-loader.js.map +0 -1
- package/dist/adapters/codex.d.ts +0 -65
- package/dist/adapters/codex.d.ts.map +0 -1
- package/dist/adapters/codex.js +0 -606
- package/dist/adapters/codex.js.map +0 -1
- package/dist/adapters/gemini-cli.d.ts +0 -50
- package/dist/adapters/gemini-cli.d.ts.map +0 -1
- package/dist/adapters/gemini-cli.js +0 -205
- package/dist/adapters/gemini-cli.js.map +0 -1
- package/dist/adapters/pty.d.ts +0 -57
- package/dist/adapters/pty.d.ts.map +0 -1
- package/dist/adapters/pty.js +0 -250
- package/dist/adapters/pty.js.map +0 -1
- package/dist/agents/aider.d.ts +0 -9
- package/dist/agents/aider.d.ts.map +0 -1
- package/dist/agents/aider.js +0 -37
- package/dist/agents/aider.js.map +0 -1
- package/dist/agents/built-in.d.ts +0 -4
- package/dist/agents/built-in.d.ts.map +0 -1
- package/dist/agents/built-in.js +0 -6
- package/dist/agents/built-in.js.map +0 -1
- package/dist/agents/claude.d.ts +0 -12
- package/dist/agents/claude.d.ts.map +0 -1
- package/dist/agents/claude.js +0 -93
- package/dist/agents/claude.js.map +0 -1
- package/dist/agents/codex-defaults.d.ts +0 -2
- package/dist/agents/codex-defaults.d.ts.map +0 -1
- package/dist/agents/codex-defaults.js +0 -2
- package/dist/agents/codex-defaults.js.map +0 -1
- package/dist/agents/codex.d.ts +0 -6
- package/dist/agents/codex.d.ts.map +0 -1
- package/dist/agents/codex.js +0 -82
- package/dist/agents/codex.js.map +0 -1
- package/dist/agents/command-detection.d.ts +0 -6
- package/dist/agents/command-detection.d.ts.map +0 -1
- package/dist/agents/command-detection.js +0 -12
- package/dist/agents/command-detection.js.map +0 -1
- package/dist/agents/custom-command.d.ts +0 -3
- package/dist/agents/custom-command.d.ts.map +0 -1
- package/dist/agents/custom-command.js +0 -58
- package/dist/agents/custom-command.js.map +0 -1
- package/dist/agents/gemini.d.ts +0 -6
- package/dist/agents/gemini.d.ts.map +0 -1
- package/dist/agents/gemini.js +0 -36
- package/dist/agents/gemini.js.map +0 -1
- package/dist/cli/agent-commands.d.ts +0 -2
- package/dist/cli/agent-commands.d.ts.map +0 -1
- package/dist/cli/agent-commands.js +0 -97
- package/dist/cli/agent-commands.js.map +0 -1
- package/dist/cli/args.d.ts +0 -9
- package/dist/cli/args.d.ts.map +0 -1
- package/dist/cli/args.js +0 -96
- package/dist/cli/args.js.map +0 -1
- package/dist/cli/bind-command.d.ts +0 -2
- package/dist/cli/bind-command.d.ts.map +0 -1
- package/dist/cli/bind-command.js +0 -61
- package/dist/cli/bind-command.js.map +0 -1
- package/dist/cli/check-command.d.ts +0 -2
- package/dist/cli/check-command.d.ts.map +0 -1
- package/dist/cli/check-command.js +0 -168
- package/dist/cli/check-command.js.map +0 -1
- package/dist/cli/command-shared.d.ts +0 -81
- package/dist/cli/command-shared.d.ts.map +0 -1
- package/dist/cli/command-shared.js +0 -237
- package/dist/cli/command-shared.js.map +0 -1
- package/dist/cli/commands.d.ts +0 -36
- package/dist/cli/commands.d.ts.map +0 -1
- package/dist/cli/commands.js +0 -36
- package/dist/cli/commands.js.map +0 -1
- package/dist/cli/context-access-command.d.ts +0 -3
- package/dist/cli/context-access-command.d.ts.map +0 -1
- package/dist/cli/context-access-command.js +0 -63
- package/dist/cli/context-access-command.js.map +0 -1
- package/dist/cli/context-add-command.d.ts +0 -2
- package/dist/cli/context-add-command.d.ts.map +0 -1
- package/dist/cli/context-add-command.js +0 -74
- package/dist/cli/context-add-command.js.map +0 -1
- package/dist/cli/context-candidate-preview-command.d.ts +0 -2
- package/dist/cli/context-candidate-preview-command.d.ts.map +0 -1
- package/dist/cli/context-candidate-preview-command.js +0 -52
- package/dist/cli/context-candidate-preview-command.js.map +0 -1
- package/dist/cli/context-command-parsers.d.ts +0 -4
- package/dist/cli/context-command-parsers.d.ts.map +0 -1
- package/dist/cli/context-command-parsers.js +0 -32
- package/dist/cli/context-command-parsers.js.map +0 -1
- package/dist/cli/context-command.d.ts +0 -2
- package/dist/cli/context-command.d.ts.map +0 -1
- package/dist/cli/context-command.js +0 -950
- package/dist/cli/context-command.js.map +0 -1
- package/dist/cli/context-github-use-command.d.ts +0 -2
- package/dist/cli/context-github-use-command.d.ts.map +0 -1
- package/dist/cli/context-github-use-command.js +0 -68
- package/dist/cli/context-github-use-command.js.map +0 -1
- package/dist/cli/context-provider-command.d.ts +0 -4
- package/dist/cli/context-provider-command.d.ts.map +0 -1
- package/dist/cli/context-provider-command.js +0 -277
- package/dist/cli/context-provider-command.js.map +0 -1
- package/dist/cli/context-provider-propose.d.ts +0 -27
- package/dist/cli/context-provider-propose.d.ts.map +0 -1
- package/dist/cli/context-provider-propose.js +0 -31
- package/dist/cli/context-provider-propose.js.map +0 -1
- package/dist/cli/context-provider-resolve.d.ts +0 -11
- package/dist/cli/context-provider-resolve.d.ts.map +0 -1
- package/dist/cli/context-provider-resolve.js +0 -22
- package/dist/cli/context-provider-resolve.js.map +0 -1
- package/dist/cli/context-rules-command.d.ts +0 -2
- package/dist/cli/context-rules-command.d.ts.map +0 -1
- package/dist/cli/context-rules-command.js +0 -93
- package/dist/cli/context-rules-command.js.map +0 -1
- package/dist/cli/context-sync-target.d.ts +0 -37
- package/dist/cli/context-sync-target.d.ts.map +0 -1
- package/dist/cli/context-sync-target.js +0 -180
- package/dist/cli/context-sync-target.js.map +0 -1
- package/dist/cli/context-vault-metadata-command.d.ts +0 -36
- package/dist/cli/context-vault-metadata-command.d.ts.map +0 -1
- package/dist/cli/context-vault-metadata-command.js +0 -250
- package/dist/cli/context-vault-metadata-command.js.map +0 -1
- package/dist/cli/context-vault-use-command.d.ts +0 -2
- package/dist/cli/context-vault-use-command.d.ts.map +0 -1
- package/dist/cli/context-vault-use-command.js +0 -55
- package/dist/cli/context-vault-use-command.js.map +0 -1
- package/dist/cli/contract-authorization.d.ts +0 -25
- package/dist/cli/contract-authorization.d.ts.map +0 -1
- package/dist/cli/contract-authorization.js +0 -97
- package/dist/cli/contract-authorization.js.map +0 -1
- package/dist/cli/daemon-client.d.ts +0 -31
- package/dist/cli/daemon-client.d.ts.map +0 -1
- package/dist/cli/daemon-client.js +0 -208
- package/dist/cli/daemon-client.js.map +0 -1
- package/dist/cli/daemon-lifecycle.d.ts +0 -19
- package/dist/cli/daemon-lifecycle.d.ts.map +0 -1
- package/dist/cli/daemon-lifecycle.js +0 -298
- package/dist/cli/daemon-lifecycle.js.map +0 -1
- package/dist/cli/daemon-runtime-state.d.ts +0 -47
- package/dist/cli/daemon-runtime-state.d.ts.map +0 -1
- package/dist/cli/daemon-runtime-state.js +0 -2
- package/dist/cli/daemon-runtime-state.js.map +0 -1
- package/dist/cli/daemon-settings.d.ts +0 -9
- package/dist/cli/daemon-settings.d.ts.map +0 -1
- package/dist/cli/daemon-settings.js +0 -321
- package/dist/cli/daemon-settings.js.map +0 -1
- package/dist/cli/diagnostic-command.d.ts +0 -2
- package/dist/cli/diagnostic-command.d.ts.map +0 -1
- package/dist/cli/diagnostic-command.js +0 -102
- package/dist/cli/diagnostic-command.js.map +0 -1
- package/dist/cli/directory-commands.d.ts +0 -4
- package/dist/cli/directory-commands.d.ts.map +0 -1
- package/dist/cli/directory-commands.js +0 -198
- package/dist/cli/directory-commands.js.map +0 -1
- package/dist/cli/global-flags.d.ts +0 -2
- package/dist/cli/global-flags.d.ts.map +0 -1
- package/dist/cli/global-flags.js +0 -9
- package/dist/cli/global-flags.js.map +0 -1
- package/dist/cli/guard-command.d.ts +0 -34
- package/dist/cli/guard-command.d.ts.map +0 -1
- package/dist/cli/guard-command.js +0 -161
- package/dist/cli/guard-command.js.map +0 -1
- package/dist/cli/hook-command.d.ts +0 -23
- package/dist/cli/hook-command.d.ts.map +0 -1
- package/dist/cli/hook-command.js +0 -169
- package/dist/cli/hook-command.js.map +0 -1
- package/dist/cli/install-command.d.ts +0 -6
- package/dist/cli/install-command.d.ts.map +0 -1
- package/dist/cli/install-command.js +0 -125
- package/dist/cli/install-command.js.map +0 -1
- package/dist/cli/lifecycle-commands.d.ts +0 -15
- package/dist/cli/lifecycle-commands.d.ts.map +0 -1
- package/dist/cli/lifecycle-commands.js +0 -369
- package/dist/cli/lifecycle-commands.js.map +0 -1
- package/dist/cli/lifecycle-doctor-command.d.ts +0 -2
- package/dist/cli/lifecycle-doctor-command.d.ts.map +0 -1
- package/dist/cli/lifecycle-doctor-command.js +0 -100
- package/dist/cli/lifecycle-doctor-command.js.map +0 -1
- package/dist/cli/lifecycle-pair-command.d.ts +0 -6
- package/dist/cli/lifecycle-pair-command.d.ts.map +0 -1
- package/dist/cli/lifecycle-pair-command.js +0 -358
- package/dist/cli/lifecycle-pair-command.js.map +0 -1
- package/dist/cli/lifecycle-pair-server.d.ts +0 -29
- package/dist/cli/lifecycle-pair-server.d.ts.map +0 -1
- package/dist/cli/lifecycle-pair-server.js +0 -208
- package/dist/cli/lifecycle-pair-server.js.map +0 -1
- package/dist/cli/lifecycle-status-command.d.ts +0 -2
- package/dist/cli/lifecycle-status-command.d.ts.map +0 -1
- package/dist/cli/lifecycle-status-command.js +0 -340
- package/dist/cli/lifecycle-status-command.js.map +0 -1
- package/dist/cli/lifecycle-update-command.d.ts +0 -2
- package/dist/cli/lifecycle-update-command.d.ts.map +0 -1
- package/dist/cli/lifecycle-update-command.js +0 -92
- package/dist/cli/lifecycle-update-command.js.map +0 -1
- package/dist/cli/listen-target.d.ts +0 -13
- package/dist/cli/listen-target.d.ts.map +0 -1
- package/dist/cli/listen-target.js +0 -102
- package/dist/cli/listen-target.js.map +0 -1
- package/dist/cli/local-tls.d.ts +0 -9
- package/dist/cli/local-tls.d.ts.map +0 -1
- package/dist/cli/local-tls.js +0 -84
- package/dist/cli/local-tls.js.map +0 -1
- package/dist/cli/managed-session-verification-contract.d.ts +0 -46
- package/dist/cli/managed-session-verification-contract.d.ts.map +0 -1
- package/dist/cli/managed-session-verification-contract.js +0 -2
- package/dist/cli/managed-session-verification-contract.js.map +0 -1
- package/dist/cli/network.d.ts +0 -11
- package/dist/cli/network.d.ts.map +0 -1
- package/dist/cli/network.js +0 -173
- package/dist/cli/network.js.map +0 -1
- package/dist/cli/open-url.d.ts +0 -2
- package/dist/cli/open-url.d.ts.map +0 -1
- package/dist/cli/open-url.js +0 -21
- package/dist/cli/open-url.js.map +0 -1
- package/dist/cli/orchestration-commands.d.ts +0 -8
- package/dist/cli/orchestration-commands.d.ts.map +0 -1
- package/dist/cli/orchestration-commands.js +0 -340
- package/dist/cli/orchestration-commands.js.map +0 -1
- package/dist/cli/org-binding.d.ts +0 -41
- package/dist/cli/org-binding.d.ts.map +0 -1
- package/dist/cli/org-binding.js +0 -211
- package/dist/cli/org-binding.js.map +0 -1
- package/dist/cli/pairing-name-resolver.d.ts +0 -2
- package/dist/cli/pairing-name-resolver.d.ts.map +0 -1
- package/dist/cli/pairing-name-resolver.js +0 -48
- package/dist/cli/pairing-name-resolver.js.map +0 -1
- package/dist/cli/permission-commands.d.ts +0 -2
- package/dist/cli/permission-commands.d.ts.map +0 -1
- package/dist/cli/permission-commands.js +0 -148
- package/dist/cli/permission-commands.js.map +0 -1
- package/dist/cli/policy-schema-validator.d.ts +0 -240
- package/dist/cli/policy-schema-validator.d.ts.map +0 -1
- package/dist/cli/policy-schema-validator.js +0 -315
- package/dist/cli/policy-schema-validator.js.map +0 -1
- package/dist/cli/profile-command.d.ts +0 -3
- package/dist/cli/profile-command.d.ts.map +0 -1
- package/dist/cli/profile-command.js +0 -320
- package/dist/cli/profile-command.js.map +0 -1
- package/dist/cli/profile-runtime-commands.d.ts +0 -6
- package/dist/cli/profile-runtime-commands.d.ts.map +0 -1
- package/dist/cli/profile-runtime-commands.js +0 -127
- package/dist/cli/profile-runtime-commands.js.map +0 -1
- package/dist/cli/relay-binding-config.d.ts +0 -8
- package/dist/cli/relay-binding-config.d.ts.map +0 -1
- package/dist/cli/relay-binding-config.js +0 -62
- package/dist/cli/relay-binding-config.js.map +0 -1
- package/dist/cli/relay-diagnostics.d.ts +0 -8
- package/dist/cli/relay-diagnostics.d.ts.map +0 -1
- package/dist/cli/relay-diagnostics.js +0 -45
- package/dist/cli/relay-diagnostics.js.map +0 -1
- package/dist/cli/relay-launch-bindings.d.ts +0 -22
- package/dist/cli/relay-launch-bindings.d.ts.map +0 -1
- package/dist/cli/relay-launch-bindings.js +0 -36
- package/dist/cli/relay-launch-bindings.js.map +0 -1
- package/dist/cli/remote-commands.d.ts +0 -3
- package/dist/cli/remote-commands.d.ts.map +0 -1
- package/dist/cli/remote-commands.js +0 -312
- package/dist/cli/remote-commands.js.map +0 -1
- package/dist/cli/remote-decision-keys.d.ts +0 -8
- package/dist/cli/remote-decision-keys.d.ts.map +0 -1
- package/dist/cli/remote-decision-keys.js +0 -59
- package/dist/cli/remote-decision-keys.js.map +0 -1
- package/dist/cli/resource-config-command.d.ts +0 -9
- package/dist/cli/resource-config-command.d.ts.map +0 -1
- package/dist/cli/resource-config-command.js +0 -295
- package/dist/cli/resource-config-command.js.map +0 -1
- package/dist/cli/runtime-toolchain.d.ts +0 -35
- package/dist/cli/runtime-toolchain.d.ts.map +0 -1
- package/dist/cli/runtime-toolchain.js +0 -184
- package/dist/cli/runtime-toolchain.js.map +0 -1
- package/dist/cli/service-commands.d.ts +0 -21
- package/dist/cli/service-commands.d.ts.map +0 -1
- package/dist/cli/service-commands.js +0 -295
- package/dist/cli/service-commands.js.map +0 -1
- package/dist/cli/session-commands.d.ts +0 -5
- package/dist/cli/session-commands.d.ts.map +0 -1
- package/dist/cli/session-commands.js +0 -237
- package/dist/cli/session-commands.js.map +0 -1
- package/dist/cli/setup-command.d.ts +0 -17
- package/dist/cli/setup-command.d.ts.map +0 -1
- package/dist/cli/setup-command.js +0 -278
- package/dist/cli/setup-command.js.map +0 -1
- package/dist/cli/signal-command.d.ts +0 -2
- package/dist/cli/signal-command.d.ts.map +0 -1
- package/dist/cli/signal-command.js +0 -258
- package/dist/cli/signal-command.js.map +0 -1
- package/dist/cli/skills-command.d.ts +0 -2
- package/dist/cli/skills-command.d.ts.map +0 -1
- package/dist/cli/skills-command.js +0 -208
- package/dist/cli/skills-command.js.map +0 -1
- package/dist/cli/supervisor-protocol.d.ts +0 -55
- package/dist/cli/supervisor-protocol.d.ts.map +0 -1
- package/dist/cli/supervisor-protocol.js +0 -5
- package/dist/cli/supervisor-protocol.js.map +0 -1
- package/dist/cli/supervisor-runtime-config.d.ts +0 -4
- package/dist/cli/supervisor-runtime-config.d.ts.map +0 -1
- package/dist/cli/supervisor-runtime-config.js +0 -112
- package/dist/cli/supervisor-runtime-config.js.map +0 -1
- package/dist/cli/supervisor.d.ts +0 -10
- package/dist/cli/supervisor.d.ts.map +0 -1
- package/dist/cli/supervisor.js +0 -252
- package/dist/cli/supervisor.js.map +0 -1
- package/dist/cli/support-packet.d.ts +0 -7
- package/dist/cli/support-packet.d.ts.map +0 -1
- package/dist/cli/support-packet.js +0 -19
- package/dist/cli/support-packet.js.map +0 -1
- package/dist/cli/team-resource-command.d.ts +0 -2
- package/dist/cli/team-resource-command.d.ts.map +0 -1
- package/dist/cli/team-resource-command.js +0 -364
- package/dist/cli/team-resource-command.js.map +0 -1
- package/dist/cli/uninstall-command.d.ts +0 -2
- package/dist/cli/uninstall-command.d.ts.map +0 -1
- package/dist/cli/uninstall-command.js +0 -111
- package/dist/cli/uninstall-command.js.map +0 -1
- package/dist/cli/unlock-command.d.ts +0 -2
- package/dist/cli/unlock-command.d.ts.map +0 -1
- package/dist/cli/unlock-command.js +0 -35
- package/dist/cli/unlock-command.js.map +0 -1
- package/dist/cli/watch-command.d.ts +0 -3
- package/dist/cli/watch-command.d.ts.map +0 -1
- package/dist/cli/watch-command.js +0 -42
- package/dist/cli/watch-command.js.map +0 -1
- package/dist/cli/worker-command.d.ts +0 -3
- package/dist/cli/worker-command.d.ts.map +0 -1
- package/dist/cli/worker-command.js +0 -518
- package/dist/cli/worker-command.js.map +0 -1
- package/dist/cli/worker-process-lock.d.ts +0 -27
- package/dist/cli/worker-process-lock.d.ts.map +0 -1
- package/dist/cli/worker-process-lock.js +0 -150
- package/dist/cli/worker-process-lock.js.map +0 -1
- package/dist/cli/worker-profile.d.ts +0 -90
- package/dist/cli/worker-profile.d.ts.map +0 -1
- package/dist/cli/worker-profile.js +0 -302
- package/dist/cli/worker-profile.js.map +0 -1
- package/dist/cli/worker-runtime.d.ts +0 -83
- package/dist/cli/worker-runtime.d.ts.map +0 -1
- package/dist/cli/worker-runtime.js +0 -1825
- package/dist/cli/worker-runtime.js.map +0 -1
- package/dist/cli/workflow-commands.d.ts +0 -3
- package/dist/cli/workflow-commands.d.ts.map +0 -1
- package/dist/cli/workflow-commands.js +0 -404
- package/dist/cli/workflow-commands.js.map +0 -1
- package/dist/cli/workflow-contract-resolver.d.ts +0 -13
- package/dist/cli/workflow-contract-resolver.d.ts.map +0 -1
- package/dist/cli/workflow-contract-resolver.js +0 -68
- package/dist/cli/workflow-contract-resolver.js.map +0 -1
- package/dist/cli/workflow-run-json.d.ts +0 -34
- package/dist/cli/workflow-run-json.d.ts.map +0 -1
- package/dist/cli/workflow-run-json.js +0 -118
- package/dist/cli/workflow-run-json.js.map +0 -1
- package/dist/cli/worktree-commands.d.ts +0 -2
- package/dist/cli/worktree-commands.d.ts.map +0 -1
- package/dist/cli/worktree-commands.js +0 -260
- package/dist/cli/worktree-commands.js.map +0 -1
- package/dist/cli/ws-client.d.ts +0 -20
- package/dist/cli/ws-client.d.ts.map +0 -1
- package/dist/cli/ws-client.js +0 -128
- package/dist/cli/ws-client.js.map +0 -1
- package/dist/config-resolution/approval-rules.d.ts +0 -5
- package/dist/config-resolution/approval-rules.d.ts.map +0 -1
- package/dist/config-resolution/approval-rules.js +0 -14
- package/dist/config-resolution/approval-rules.js.map +0 -1
- package/dist/config-resolution/config-writer.d.ts +0 -51
- package/dist/config-resolution/config-writer.d.ts.map +0 -1
- package/dist/config-resolution/config-writer.js +0 -164
- package/dist/config-resolution/config-writer.js.map +0 -1
- package/dist/config-resolution/context-package-manifest.d.ts +0 -3
- package/dist/config-resolution/context-package-manifest.d.ts.map +0 -1
- package/dist/config-resolution/context-package-manifest.js +0 -23
- package/dist/config-resolution/context-package-manifest.js.map +0 -1
- package/dist/config-resolution/discovery.d.ts +0 -18
- package/dist/config-resolution/discovery.d.ts.map +0 -1
- package/dist/config-resolution/discovery.js +0 -225
- package/dist/config-resolution/discovery.js.map +0 -1
- package/dist/config-resolution/index.d.ts +0 -4
- package/dist/config-resolution/index.d.ts.map +0 -1
- package/dist/config-resolution/index.js +0 -4
- package/dist/config-resolution/index.js.map +0 -1
- package/dist/config-resolution/provider-defaults.d.ts +0 -4
- package/dist/config-resolution/provider-defaults.d.ts.map +0 -1
- package/dist/config-resolution/provider-defaults.js +0 -27
- package/dist/config-resolution/provider-defaults.js.map +0 -1
- package/dist/config-resolution/resolver.d.ts +0 -16
- package/dist/config-resolution/resolver.d.ts.map +0 -1
- package/dist/config-resolution/resolver.js +0 -329
- package/dist/config-resolution/resolver.js.map +0 -1
- package/dist/config-resolution/schema.d.ts +0 -127
- package/dist/config-resolution/schema.d.ts.map +0 -1
- package/dist/config-resolution/schema.js +0 -189
- package/dist/config-resolution/schema.js.map +0 -1
- package/dist/config-resolution/stable-json.d.ts +0 -3
- package/dist/config-resolution/stable-json.d.ts.map +0 -1
- package/dist/config-resolution/stable-json.js +0 -18
- package/dist/config-resolution/stable-json.js.map +0 -1
- package/dist/config-resolution/types.d.ts +0 -134
- package/dist/config-resolution/types.d.ts.map +0 -1
- package/dist/config-resolution/types.js +0 -5
- package/dist/config-resolution/types.js.map +0 -1
- package/dist/context/local-edge-auto-sync.d.ts +0 -17
- package/dist/context/local-edge-auto-sync.d.ts.map +0 -1
- package/dist/context/local-edge-auto-sync.js +0 -94
- package/dist/context/local-edge-auto-sync.js.map +0 -1
- package/dist/context/local-edge-candidates.d.ts +0 -58
- package/dist/context/local-edge-candidates.d.ts.map +0 -1
- package/dist/context/local-edge-candidates.js +0 -276
- package/dist/context/local-edge-candidates.js.map +0 -1
- package/dist/context/local-edge-crypto.d.ts +0 -28
- package/dist/context/local-edge-crypto.d.ts.map +0 -1
- package/dist/context/local-edge-crypto.js +0 -76
- package/dist/context/local-edge-crypto.js.map +0 -1
- package/dist/context/local-edge-decision-applications.d.ts +0 -13
- package/dist/context/local-edge-decision-applications.d.ts.map +0 -1
- package/dist/context/local-edge-decision-applications.js +0 -78
- package/dist/context/local-edge-decision-applications.js.map +0 -1
- package/dist/context/local-edge-decision-signature.d.ts +0 -3
- package/dist/context/local-edge-decision-signature.d.ts.map +0 -1
- package/dist/context/local-edge-decision-signature.js +0 -67
- package/dist/context/local-edge-decision-signature.js.map +0 -1
- package/dist/context/local-edge-engine.d.ts +0 -38
- package/dist/context/local-edge-engine.d.ts.map +0 -1
- package/dist/context/local-edge-engine.js +0 -138
- package/dist/context/local-edge-engine.js.map +0 -1
- package/dist/context/local-edge-key-store.d.ts +0 -4
- package/dist/context/local-edge-key-store.d.ts.map +0 -1
- package/dist/context/local-edge-key-store.js +0 -21
- package/dist/context/local-edge-key-store.js.map +0 -1
- package/dist/context/local-edge-metadata.d.ts +0 -8
- package/dist/context/local-edge-metadata.d.ts.map +0 -1
- package/dist/context/local-edge-metadata.js +0 -105
- package/dist/context/local-edge-metadata.js.map +0 -1
- package/dist/context/local-edge-paths.d.ts +0 -4
- package/dist/context/local-edge-paths.d.ts.map +0 -1
- package/dist/context/local-edge-paths.js +0 -11
- package/dist/context/local-edge-paths.js.map +0 -1
- package/dist/context/local-edge-store.d.ts +0 -137
- package/dist/context/local-edge-store.d.ts.map +0 -1
- package/dist/context/local-edge-store.js +0 -284
- package/dist/context/local-edge-store.js.map +0 -1
- package/dist/context/local-edge-sync.d.ts +0 -104
- package/dist/context/local-edge-sync.d.ts.map +0 -1
- package/dist/context/local-edge-sync.js +0 -716
- package/dist/context/local-edge-sync.js.map +0 -1
- package/dist/context/local-edge-types.d.ts +0 -330
- package/dist/context/local-edge-types.d.ts.map +0 -1
- package/dist/context/local-edge-types.js +0 -5
- package/dist/context/local-edge-types.js.map +0 -1
- package/dist/context-providers/confluence-provider.d.ts +0 -3
- package/dist/context-providers/confluence-provider.d.ts.map +0 -1
- package/dist/context-providers/confluence-provider.js +0 -170
- package/dist/context-providers/confluence-provider.js.map +0 -1
- package/dist/context-providers/github-repo-provider.d.ts +0 -3
- package/dist/context-providers/github-repo-provider.d.ts.map +0 -1
- package/dist/context-providers/github-repo-provider.js +0 -313
- package/dist/context-providers/github-repo-provider.js.map +0 -1
- package/dist/context-providers/notion-provider.d.ts +0 -3
- package/dist/context-providers/notion-provider.d.ts.map +0 -1
- package/dist/context-providers/notion-provider.js +0 -157
- package/dist/context-providers/notion-provider.js.map +0 -1
- package/dist/context-providers/registry.d.ts +0 -5
- package/dist/context-providers/registry.d.ts.map +0 -1
- package/dist/context-providers/registry.js +0 -19
- package/dist/context-providers/registry.js.map +0 -1
- package/dist/context-providers/repo-docs-provider.d.ts +0 -19
- package/dist/context-providers/repo-docs-provider.d.ts.map +0 -1
- package/dist/context-providers/repo-docs-provider.js +0 -188
- package/dist/context-providers/repo-docs-provider.js.map +0 -1
- package/dist/context-providers/types.d.ts +0 -75
- package/dist/context-providers/types.d.ts.map +0 -1
- package/dist/context-providers/types.js +0 -2
- package/dist/context-providers/types.js.map +0 -1
- package/dist/context-providers/viewport-vault-provider.d.ts +0 -3
- package/dist/context-providers/viewport-vault-provider.d.ts.map +0 -1
- package/dist/context-providers/viewport-vault-provider.js +0 -84
- package/dist/context-providers/viewport-vault-provider.js.map +0 -1
- package/dist/core/agent-registry.d.ts +0 -130
- package/dist/core/agent-registry.d.ts.map +0 -1
- package/dist/core/agent-registry.js +0 -131
- package/dist/core/agent-registry.js.map +0 -1
- package/dist/core/config-schema.d.ts +0 -230
- package/dist/core/config-schema.d.ts.map +0 -1
- package/dist/core/config-schema.js +0 -175
- package/dist/core/config-schema.js.map +0 -1
- package/dist/core/config.d.ts +0 -305
- package/dist/core/config.d.ts.map +0 -1
- package/dist/core/config.js +0 -453
- package/dist/core/config.js.map +0 -1
- package/dist/core/daemon.d.ts +0 -147
- package/dist/core/daemon.d.ts.map +0 -1
- package/dist/core/daemon.js +0 -275
- package/dist/core/daemon.js.map +0 -1
- package/dist/core/discovered-sessions.d.ts +0 -7
- package/dist/core/discovered-sessions.d.ts.map +0 -1
- package/dist/core/discovered-sessions.js +0 -44
- package/dist/core/discovered-sessions.js.map +0 -1
- package/dist/core/error-codes.d.ts +0 -32
- package/dist/core/error-codes.d.ts.map +0 -1
- package/dist/core/error-codes.js +0 -31
- package/dist/core/error-codes.js.map +0 -1
- package/dist/core/errors.d.ts +0 -16
- package/dist/core/errors.d.ts.map +0 -1
- package/dist/core/errors.js +0 -45
- package/dist/core/errors.js.map +0 -1
- package/dist/core/events.d.ts +0 -213
- package/dist/core/events.d.ts.map +0 -1
- package/dist/core/events.js +0 -61
- package/dist/core/events.js.map +0 -1
- package/dist/core/interfaces.d.ts +0 -304
- package/dist/core/interfaces.d.ts.map +0 -1
- package/dist/core/interfaces.js +0 -9
- package/dist/core/interfaces.js.map +0 -1
- package/dist/core/logger.d.ts +0 -11
- package/dist/core/logger.d.ts.map +0 -1
- package/dist/core/logger.js +0 -23
- package/dist/core/logger.js.map +0 -1
- package/dist/core/machine-name.d.ts +0 -3
- package/dist/core/machine-name.d.ts.map +0 -1
- package/dist/core/machine-name.js +0 -11
- package/dist/core/machine-name.js.map +0 -1
- package/dist/core/metrics.d.ts +0 -24
- package/dist/core/metrics.d.ts.map +0 -1
- package/dist/core/metrics.js +0 -32
- package/dist/core/metrics.js.map +0 -1
- package/dist/core/output.d.ts +0 -13
- package/dist/core/output.d.ts.map +0 -1
- package/dist/core/output.js +0 -23
- package/dist/core/output.js.map +0 -1
- package/dist/core/package-meta.d.ts +0 -12
- package/dist/core/package-meta.d.ts.map +0 -1
- package/dist/core/package-meta.js +0 -87
- package/dist/core/package-meta.js.map +0 -1
- package/dist/core/permission-coordinator.d.ts +0 -67
- package/dist/core/permission-coordinator.d.ts.map +0 -1
- package/dist/core/permission-coordinator.js +0 -211
- package/dist/core/permission-coordinator.js.map +0 -1
- package/dist/core/profiles.d.ts +0 -43
- package/dist/core/profiles.d.ts.map +0 -1
- package/dist/core/profiles.js +0 -181
- package/dist/core/profiles.js.map +0 -1
- package/dist/core/redaction.d.ts +0 -4
- package/dist/core/redaction.d.ts.map +0 -1
- package/dist/core/redaction.js +0 -76
- package/dist/core/redaction.js.map +0 -1
- package/dist/core/runtime-identity.d.ts +0 -45
- package/dist/core/runtime-identity.d.ts.map +0 -1
- package/dist/core/runtime-identity.js +0 -130
- package/dist/core/runtime-identity.js.map +0 -1
- package/dist/core/session-context-prompt.d.ts +0 -22
- package/dist/core/session-context-prompt.d.ts.map +0 -1
- package/dist/core/session-context-prompt.js +0 -213
- package/dist/core/session-context-prompt.js.map +0 -1
- package/dist/core/session-discovery-runner.d.ts +0 -11
- package/dist/core/session-discovery-runner.d.ts.map +0 -1
- package/dist/core/session-discovery-runner.js +0 -37
- package/dist/core/session-discovery-runner.js.map +0 -1
- package/dist/core/session-manager.d.ts +0 -130
- package/dist/core/session-manager.d.ts.map +0 -1
- package/dist/core/session-manager.js +0 -434
- package/dist/core/session-manager.js.map +0 -1
- package/dist/core/session-state-file.d.ts +0 -20
- package/dist/core/session-state-file.d.ts.map +0 -1
- package/dist/core/session-state-file.js +0 -51
- package/dist/core/session-state-file.js.map +0 -1
- package/dist/core/types.d.ts +0 -290
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/types.js +0 -88
- package/dist/core/types.js.map +0 -1
- package/dist/core/workflow-linked-discovery.d.ts +0 -17
- package/dist/core/workflow-linked-discovery.d.ts.map +0 -1
- package/dist/core/workflow-linked-discovery.js +0 -53
- package/dist/core/workflow-linked-discovery.js.map +0 -1
- package/dist/directories/manager.d.ts +0 -33
- package/dist/directories/manager.d.ts.map +0 -1
- package/dist/directories/manager.js +0 -129
- package/dist/directories/manager.js.map +0 -1
- package/dist/discovery/claude.d.ts +0 -29
- package/dist/discovery/claude.d.ts.map +0 -1
- package/dist/discovery/claude.js +0 -66
- package/dist/discovery/claude.js.map +0 -1
- package/dist/discovery/codex-parser.d.ts +0 -20
- package/dist/discovery/codex-parser.d.ts.map +0 -1
- package/dist/discovery/codex-parser.js +0 -378
- package/dist/discovery/codex-parser.js.map +0 -1
- package/dist/discovery/codex-summary.d.ts +0 -6
- package/dist/discovery/codex-summary.d.ts.map +0 -1
- package/dist/discovery/codex-summary.js +0 -27
- package/dist/discovery/codex-summary.js.map +0 -1
- package/dist/discovery/codex.d.ts +0 -32
- package/dist/discovery/codex.d.ts.map +0 -1
- package/dist/discovery/codex.js +0 -206
- package/dist/discovery/codex.js.map +0 -1
- package/dist/discovery/dedupe.d.ts +0 -3
- package/dist/discovery/dedupe.d.ts.map +0 -1
- package/dist/discovery/dedupe.js +0 -13
- package/dist/discovery/dedupe.js.map +0 -1
- package/dist/discovery/gemini.d.ts +0 -15
- package/dist/discovery/gemini.d.ts.map +0 -1
- package/dist/discovery/gemini.js +0 -151
- package/dist/discovery/gemini.js.map +0 -1
- package/dist/discovery/jsonl-entry-parser.d.ts +0 -74
- package/dist/discovery/jsonl-entry-parser.d.ts.map +0 -1
- package/dist/discovery/jsonl-entry-parser.js +0 -1034
- package/dist/discovery/jsonl-entry-parser.js.map +0 -1
- package/dist/discovery/jsonl-paths.d.ts +0 -17
- package/dist/discovery/jsonl-paths.d.ts.map +0 -1
- package/dist/discovery/jsonl-paths.js +0 -56
- package/dist/discovery/jsonl-paths.js.map +0 -1
- package/dist/discovery/jsonl-reader.d.ts +0 -121
- package/dist/discovery/jsonl-reader.d.ts.map +0 -1
- package/dist/discovery/jsonl-reader.js +0 -458
- package/dist/discovery/jsonl-reader.js.map +0 -1
- package/dist/discovery/watcher.d.ts +0 -29
- package/dist/discovery/watcher.d.ts.map +0 -1
- package/dist/discovery/watcher.js +0 -426
- package/dist/discovery/watcher.js.map +0 -1
- package/dist/hooks/capabilities.d.ts +0 -17
- package/dist/hooks/capabilities.d.ts.map +0 -1
- package/dist/hooks/capabilities.js +0 -114
- package/dist/hooks/capabilities.js.map +0 -1
- package/dist/hooks/context-injector.d.ts +0 -7
- package/dist/hooks/context-injector.d.ts.map +0 -1
- package/dist/hooks/context-injector.js +0 -91
- package/dist/hooks/context-injector.js.map +0 -1
- package/dist/hooks/ephemeral-plan-drafts.d.ts +0 -34
- package/dist/hooks/ephemeral-plan-drafts.d.ts.map +0 -1
- package/dist/hooks/ephemeral-plan-drafts.js +0 -62
- package/dist/hooks/ephemeral-plan-drafts.js.map +0 -1
- package/dist/hooks/index.d.ts +0 -12
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/index.js +0 -9
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/installers/base.d.ts +0 -27
- package/dist/hooks/installers/base.d.ts.map +0 -1
- package/dist/hooks/installers/base.js +0 -9
- package/dist/hooks/installers/base.js.map +0 -1
- package/dist/hooks/installers/claude.d.ts +0 -18
- package/dist/hooks/installers/claude.d.ts.map +0 -1
- package/dist/hooks/installers/claude.js +0 -146
- package/dist/hooks/installers/claude.js.map +0 -1
- package/dist/hooks/plan-extractor.d.ts +0 -20
- package/dist/hooks/plan-extractor.d.ts.map +0 -1
- package/dist/hooks/plan-extractor.js +0 -128
- package/dist/hooks/plan-extractor.js.map +0 -1
- package/dist/hooks/platform-plan-sync.d.ts +0 -24
- package/dist/hooks/platform-plan-sync.d.ts.map +0 -1
- package/dist/hooks/platform-plan-sync.js +0 -115
- package/dist/hooks/platform-plan-sync.js.map +0 -1
- package/dist/hooks/router.d.ts +0 -64
- package/dist/hooks/router.d.ts.map +0 -1
- package/dist/hooks/router.js +0 -245
- package/dist/hooks/router.js.map +0 -1
- package/dist/hooks/specific-events.d.ts +0 -11
- package/dist/hooks/specific-events.d.ts.map +0 -1
- package/dist/hooks/specific-events.js +0 -201
- package/dist/hooks/specific-events.js.map +0 -1
- package/dist/hooks/supervision.d.ts +0 -29
- package/dist/hooks/supervision.d.ts.map +0 -1
- package/dist/hooks/supervision.js +0 -79
- package/dist/hooks/supervision.js.map +0 -1
- package/dist/hooks/trusted-edge-plan-artifacts.d.ts +0 -118
- package/dist/hooks/trusted-edge-plan-artifacts.d.ts.map +0 -1
- package/dist/hooks/trusted-edge-plan-artifacts.js +0 -386
- package/dist/hooks/trusted-edge-plan-artifacts.js.map +0 -1
- package/dist/hooks/types.d.ts +0 -204
- package/dist/hooks/types.d.ts.map +0 -1
- package/dist/hooks/types.js +0 -184
- package/dist/hooks/types.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/permissions/engine.d.ts +0 -23
- package/dist/permissions/engine.d.ts.map +0 -1
- package/dist/permissions/engine.js +0 -43
- package/dist/permissions/engine.js.map +0 -1
- package/dist/plugins/loader.d.ts +0 -44
- package/dist/plugins/loader.d.ts.map +0 -1
- package/dist/plugins/loader.js +0 -200
- package/dist/plugins/loader.js.map +0 -1
- package/dist/relay/bridge-backoff.d.ts +0 -3
- package/dist/relay/bridge-backoff.d.ts.map +0 -1
- package/dist/relay/bridge-backoff.js +0 -10
- package/dist/relay/bridge-backoff.js.map +0 -1
- package/dist/relay/bridge-connections.d.ts +0 -26
- package/dist/relay/bridge-connections.d.ts.map +0 -1
- package/dist/relay/bridge-connections.js +0 -34
- package/dist/relay/bridge-connections.js.map +0 -1
- package/dist/relay/bridge-constants.d.ts +0 -12
- package/dist/relay/bridge-constants.d.ts.map +0 -1
- package/dist/relay/bridge-constants.js +0 -12
- package/dist/relay/bridge-constants.js.map +0 -1
- package/dist/relay/bridge-crypto.d.ts +0 -19
- package/dist/relay/bridge-crypto.d.ts.map +0 -1
- package/dist/relay/bridge-crypto.js +0 -72
- package/dist/relay/bridge-crypto.js.map +0 -1
- package/dist/relay/bridge-daemon-key-registration.d.ts +0 -18
- package/dist/relay/bridge-daemon-key-registration.d.ts.map +0 -1
- package/dist/relay/bridge-daemon-key-registration.js +0 -94
- package/dist/relay/bridge-daemon-key-registration.js.map +0 -1
- package/dist/relay/bridge-errors.d.ts +0 -8
- package/dist/relay/bridge-errors.d.ts.map +0 -1
- package/dist/relay/bridge-errors.js +0 -23
- package/dist/relay/bridge-errors.js.map +0 -1
- package/dist/relay/bridge-frame-logger.d.ts +0 -2
- package/dist/relay/bridge-frame-logger.d.ts.map +0 -1
- package/dist/relay/bridge-frame-logger.js +0 -37
- package/dist/relay/bridge-frame-logger.js.map +0 -1
- package/dist/relay/bridge-handshake-profile.d.ts +0 -3
- package/dist/relay/bridge-handshake-profile.d.ts.map +0 -1
- package/dist/relay/bridge-handshake-profile.js +0 -7
- package/dist/relay/bridge-handshake-profile.js.map +0 -1
- package/dist/relay/bridge-identity-store.d.ts +0 -9
- package/dist/relay/bridge-identity-store.d.ts.map +0 -1
- package/dist/relay/bridge-identity-store.js +0 -77
- package/dist/relay/bridge-identity-store.js.map +0 -1
- package/dist/relay/bridge-jwt.d.ts +0 -18
- package/dist/relay/bridge-jwt.d.ts.map +0 -1
- package/dist/relay/bridge-jwt.js +0 -130
- package/dist/relay/bridge-jwt.js.map +0 -1
- package/dist/relay/bridge-key-exchange.d.ts +0 -46
- package/dist/relay/bridge-key-exchange.d.ts.map +0 -1
- package/dist/relay/bridge-key-exchange.js +0 -186
- package/dist/relay/bridge-key-exchange.js.map +0 -1
- package/dist/relay/bridge-network.d.ts +0 -12
- package/dist/relay/bridge-network.d.ts.map +0 -1
- package/dist/relay/bridge-network.js +0 -90
- package/dist/relay/bridge-network.js.map +0 -1
- package/dist/relay/bridge-noise-v3.d.ts +0 -74
- package/dist/relay/bridge-noise-v3.d.ts.map +0 -1
- package/dist/relay/bridge-noise-v3.js +0 -406
- package/dist/relay/bridge-noise-v3.js.map +0 -1
- package/dist/relay/bridge-org-routing-filter.d.ts +0 -8
- package/dist/relay/bridge-org-routing-filter.d.ts.map +0 -1
- package/dist/relay/bridge-org-routing-filter.js +0 -129
- package/dist/relay/bridge-org-routing-filter.js.map +0 -1
- package/dist/relay/bridge-pairing-channel.d.ts +0 -12
- package/dist/relay/bridge-pairing-channel.d.ts.map +0 -1
- package/dist/relay/bridge-pairing-channel.js +0 -30
- package/dist/relay/bridge-pairing-channel.js.map +0 -1
- package/dist/relay/bridge-pairing-control-handler.d.ts +0 -26
- package/dist/relay/bridge-pairing-control-handler.d.ts.map +0 -1
- package/dist/relay/bridge-pairing-control-handler.js +0 -136
- package/dist/relay/bridge-pairing-control-handler.js.map +0 -1
- package/dist/relay/bridge-relay-sessions.d.ts +0 -45
- package/dist/relay/bridge-relay-sessions.d.ts.map +0 -1
- package/dist/relay/bridge-relay-sessions.js +0 -88
- package/dist/relay/bridge-relay-sessions.js.map +0 -1
- package/dist/relay/bridge-token-issuer.d.ts +0 -33
- package/dist/relay/bridge-token-issuer.d.ts.map +0 -1
- package/dist/relay/bridge-token-issuer.js +0 -173
- package/dist/relay/bridge-token-issuer.js.map +0 -1
- package/dist/relay/daemon-relay-bridge.d.ts +0 -92
- package/dist/relay/daemon-relay-bridge.d.ts.map +0 -1
- package/dist/relay/daemon-relay-bridge.js +0 -549
- package/dist/relay/daemon-relay-bridge.js.map +0 -1
- package/dist/relay/relay-control-frames.d.ts +0 -31
- package/dist/relay/relay-control-frames.d.ts.map +0 -1
- package/dist/relay/relay-control-frames.js +0 -65
- package/dist/relay/relay-control-frames.js.map +0 -1
- package/dist/security/child-env.d.ts +0 -3
- package/dist/security/child-env.d.ts.map +0 -1
- package/dist/security/child-env.js +0 -44
- package/dist/security/child-env.js.map +0 -1
- package/dist/security/epoch-enrollment.d.ts +0 -48
- package/dist/security/epoch-enrollment.d.ts.map +0 -1
- package/dist/security/epoch-enrollment.js +0 -290
- package/dist/security/epoch-enrollment.js.map +0 -1
- package/dist/security/epoch-protocol.d.ts +0 -181
- package/dist/security/epoch-protocol.d.ts.map +0 -1
- package/dist/security/epoch-protocol.js +0 -285
- package/dist/security/epoch-protocol.js.map +0 -1
- package/dist/security/epoch-public-pins.d.ts +0 -19
- package/dist/security/epoch-public-pins.d.ts.map +0 -1
- package/dist/security/epoch-public-pins.js +0 -129
- package/dist/security/epoch-public-pins.js.map +0 -1
- package/dist/security/epoch-recovery.d.ts +0 -56
- package/dist/security/epoch-recovery.d.ts.map +0 -1
- package/dist/security/epoch-recovery.js +0 -314
- package/dist/security/epoch-recovery.js.map +0 -1
- package/dist/security/epoch-store.d.ts +0 -111
- package/dist/security/epoch-store.d.ts.map +0 -1
- package/dist/security/epoch-store.js +0 -224
- package/dist/security/epoch-store.js.map +0 -1
- package/dist/security/epoch-sync.d.ts +0 -47
- package/dist/security/epoch-sync.d.ts.map +0 -1
- package/dist/security/epoch-sync.js +0 -371
- package/dist/security/epoch-sync.js.map +0 -1
- package/dist/security/team-epoch-grant-payloads.d.ts +0 -44
- package/dist/security/team-epoch-grant-payloads.d.ts.map +0 -1
- package/dist/security/team-epoch-grant-payloads.js +0 -100
- package/dist/security/team-epoch-grant-payloads.js.map +0 -1
- package/dist/security/team-epoch-grants.d.ts +0 -31
- package/dist/security/team-epoch-grants.d.ts.map +0 -1
- package/dist/security/team-epoch-grants.js +0 -194
- package/dist/security/team-epoch-grants.js.map +0 -1
- package/dist/server/auth.d.ts +0 -33
- package/dist/server/auth.d.ts.map +0 -1
- package/dist/server/auth.js +0 -82
- package/dist/server/auth.js.map +0 -1
- package/dist/server/context-preview-service.d.ts +0 -26
- package/dist/server/context-preview-service.d.ts.map +0 -1
- package/dist/server/context-preview-service.js +0 -71
- package/dist/server/context-preview-service.js.map +0 -1
- package/dist/server/discovered-session-window.d.ts +0 -4
- package/dist/server/discovered-session-window.d.ts.map +0 -1
- package/dist/server/discovered-session-window.js +0 -5
- package/dist/server/discovered-session-window.js.map +0 -1
- package/dist/server/discovered-watch-key.d.ts +0 -5
- package/dist/server/discovered-watch-key.d.ts.map +0 -1
- package/dist/server/discovered-watch-key.js +0 -31
- package/dist/server/discovered-watch-key.js.map +0 -1
- package/dist/server/hello-builder.d.ts +0 -102
- package/dist/server/hello-builder.d.ts.map +0 -1
- package/dist/server/hello-builder.js +0 -227
- package/dist/server/hello-builder.js.map +0 -1
- package/dist/server/http-context-routes.d.ts +0 -4
- package/dist/server/http-context-routes.d.ts.map +0 -1
- package/dist/server/http-context-routes.js +0 -283
- package/dist/server/http-context-routes.js.map +0 -1
- package/dist/server/http-health-routes.d.ts +0 -11
- package/dist/server/http-health-routes.d.ts.map +0 -1
- package/dist/server/http-health-routes.js +0 -69
- package/dist/server/http-health-routes.js.map +0 -1
- package/dist/server/http-lifecycle-routes.d.ts +0 -6
- package/dist/server/http-lifecycle-routes.d.ts.map +0 -1
- package/dist/server/http-lifecycle-routes.js +0 -17
- package/dist/server/http-lifecycle-routes.js.map +0 -1
- package/dist/server/http-pairing-routes.d.ts +0 -14
- package/dist/server/http-pairing-routes.d.ts.map +0 -1
- package/dist/server/http-pairing-routes.js +0 -110
- package/dist/server/http-pairing-routes.js.map +0 -1
- package/dist/server/http-request-schemas.d.ts +0 -152
- package/dist/server/http-request-schemas.d.ts.map +0 -1
- package/dist/server/http-request-schemas.js +0 -183
- package/dist/server/http-request-schemas.js.map +0 -1
- package/dist/server/http-route-types.d.ts +0 -11
- package/dist/server/http-route-types.d.ts.map +0 -1
- package/dist/server/http-route-types.js +0 -2
- package/dist/server/http-route-types.js.map +0 -1
- package/dist/server/http-server.d.ts +0 -26
- package/dist/server/http-server.d.ts.map +0 -1
- package/dist/server/http-server.js +0 -400
- package/dist/server/http-server.js.map +0 -1
- package/dist/server/http-session-routes.d.ts +0 -4
- package/dist/server/http-session-routes.d.ts.map +0 -1
- package/dist/server/http-session-routes.js +0 -234
- package/dist/server/http-session-routes.js.map +0 -1
- package/dist/server/message-normalizers.d.ts +0 -11
- package/dist/server/message-normalizers.d.ts.map +0 -1
- package/dist/server/message-normalizers.js +0 -104
- package/dist/server/message-normalizers.js.map +0 -1
- package/dist/server/pairing-file-store.d.ts +0 -10
- package/dist/server/pairing-file-store.d.ts.map +0 -1
- package/dist/server/pairing-file-store.js +0 -69
- package/dist/server/pairing-file-store.js.map +0 -1
- package/dist/server/pairing-identity-store.d.ts +0 -5
- package/dist/server/pairing-identity-store.d.ts.map +0 -1
- package/dist/server/pairing-identity-store.js +0 -121
- package/dist/server/pairing-identity-store.js.map +0 -1
- package/dist/server/pairing-offer-types.d.ts +0 -98
- package/dist/server/pairing-offer-types.d.ts.map +0 -1
- package/dist/server/pairing-offer-types.js +0 -2
- package/dist/server/pairing-offer-types.js.map +0 -1
- package/dist/server/pairing-offers.d.ts +0 -29
- package/dist/server/pairing-offers.d.ts.map +0 -1
- package/dist/server/pairing-offers.js +0 -351
- package/dist/server/pairing-offers.js.map +0 -1
- package/dist/server/pairing-peer-bindings.d.ts +0 -18
- package/dist/server/pairing-peer-bindings.d.ts.map +0 -1
- package/dist/server/pairing-peer-bindings.js +0 -198
- package/dist/server/pairing-peer-bindings.js.map +0 -1
- package/dist/server/rate-limiter.d.ts +0 -21
- package/dist/server/rate-limiter.d.ts.map +0 -1
- package/dist/server/rate-limiter.js +0 -70
- package/dist/server/rate-limiter.js.map +0 -1
- package/dist/server/replay-events.d.ts +0 -6
- package/dist/server/replay-events.d.ts.map +0 -1
- package/dist/server/replay-events.js +0 -104
- package/dist/server/replay-events.js.map +0 -1
- package/dist/server/replay-persistence.d.ts +0 -18
- package/dist/server/replay-persistence.d.ts.map +0 -1
- package/dist/server/replay-persistence.js +0 -123
- package/dist/server/replay-persistence.js.map +0 -1
- package/dist/server/replay-types.d.ts +0 -25
- package/dist/server/replay-types.d.ts.map +0 -1
- package/dist/server/replay-types.js +0 -2
- package/dist/server/replay-types.js.map +0 -1
- package/dist/server/ring-buffer.d.ts +0 -48
- package/dist/server/ring-buffer.d.ts.map +0 -1
- package/dist/server/ring-buffer.js +0 -235
- package/dist/server/ring-buffer.js.map +0 -1
- package/dist/server/security.d.ts +0 -22
- package/dist/server/security.d.ts.map +0 -1
- package/dist/server/security.js +0 -127
- package/dist/server/security.js.map +0 -1
- package/dist/server/session-message-reader.d.ts +0 -15
- package/dist/server/session-message-reader.d.ts.map +0 -1
- package/dist/server/session-message-reader.js +0 -107
- package/dist/server/session-message-reader.js.map +0 -1
- package/dist/server/trusted-edge-command-capability.d.ts +0 -15
- package/dist/server/trusted-edge-command-capability.d.ts.map +0 -1
- package/dist/server/trusted-edge-command-capability.js +0 -118
- package/dist/server/trusted-edge-command-capability.js.map +0 -1
- package/dist/server/ws-command-handlers.d.ts +0 -28
- package/dist/server/ws-command-handlers.d.ts.map +0 -1
- package/dist/server/ws-command-handlers.js +0 -489
- package/dist/server/ws-command-handlers.js.map +0 -1
- package/dist/server/ws-daemon-event-bridge.d.ts +0 -22
- package/dist/server/ws-daemon-event-bridge.d.ts.map +0 -1
- package/dist/server/ws-daemon-event-bridge.js +0 -392
- package/dist/server/ws-daemon-event-bridge.js.map +0 -1
- package/dist/server/ws-limits.d.ts +0 -2
- package/dist/server/ws-limits.d.ts.map +0 -1
- package/dist/server/ws-limits.js +0 -12
- package/dist/server/ws-limits.js.map +0 -1
- package/dist/server/ws-protocol.d.ts +0 -858
- package/dist/server/ws-protocol.d.ts.map +0 -1
- package/dist/server/ws-protocol.js +0 -417
- package/dist/server/ws-protocol.js.map +0 -1
- package/dist/server/ws-server.d.ts +0 -26
- package/dist/server/ws-server.d.ts.map +0 -1
- package/dist/server/ws-server.js +0 -314
- package/dist/server/ws-server.js.map +0 -1
- package/dist/server/ws-session-command-handlers.d.ts +0 -29
- package/dist/server/ws-session-command-handlers.d.ts.map +0 -1
- package/dist/server/ws-session-command-handlers.js +0 -320
- package/dist/server/ws-session-command-handlers.js.map +0 -1
- package/dist/server/ws-workflow-command-handlers.d.ts +0 -17
- package/dist/server/ws-workflow-command-handlers.d.ts.map +0 -1
- package/dist/server/ws-workflow-command-handlers.js +0 -68
- package/dist/server/ws-workflow-command-handlers.js.map +0 -1
- package/dist/session-enrichment/git.d.ts +0 -9
- package/dist/session-enrichment/git.d.ts.map +0 -1
- package/dist/session-enrichment/git.js +0 -48
- package/dist/session-enrichment/git.js.map +0 -1
- package/dist/startup-agents.d.ts +0 -6
- package/dist/startup-agents.d.ts.map +0 -1
- package/dist/startup-agents.js +0 -102
- package/dist/startup-agents.js.map +0 -1
- package/dist/startup-prereqs.d.ts +0 -29
- package/dist/startup-prereqs.d.ts.map +0 -1
- package/dist/startup-prereqs.js +0 -209
- package/dist/startup-prereqs.js.map +0 -1
- package/dist/startup-relay-security.d.ts +0 -3
- package/dist/startup-relay-security.d.ts.map +0 -1
- package/dist/startup-relay-security.js +0 -61
- package/dist/startup-relay-security.js.map +0 -1
- package/dist/startup-session-persistence.d.ts +0 -7
- package/dist/startup-session-persistence.d.ts.map +0 -1
- package/dist/startup-session-persistence.js +0 -72
- package/dist/startup-session-persistence.js.map +0 -1
- package/dist/startup-watchers.d.ts +0 -7
- package/dist/startup-watchers.d.ts.map +0 -1
- package/dist/startup-watchers.js +0 -196
- package/dist/startup-watchers.js.map +0 -1
- package/dist/startup.d.ts +0 -29
- package/dist/startup.d.ts.map +0 -1
- package/dist/startup.js +0 -549
- package/dist/startup.js.map +0 -1
- package/dist/tracking/git-tracker.d.ts +0 -56
- package/dist/tracking/git-tracker.d.ts.map +0 -1
- package/dist/tracking/git-tracker.js +0 -342
- package/dist/tracking/git-tracker.js.map +0 -1
- package/dist/tracking/noop-tracker.d.ts +0 -27
- package/dist/tracking/noop-tracker.d.ts.map +0 -1
- package/dist/tracking/noop-tracker.js +0 -42
- package/dist/tracking/noop-tracker.js.map +0 -1
- package/dist/workflows/action-adapters.d.ts +0 -10
- package/dist/workflows/action-adapters.d.ts.map +0 -1
- package/dist/workflows/action-adapters.js +0 -203
- package/dist/workflows/action-adapters.js.map +0 -1
- package/dist/workflows/action-digest.d.ts +0 -8
- package/dist/workflows/action-digest.d.ts.map +0 -1
- package/dist/workflows/action-digest.js +0 -36
- package/dist/workflows/action-digest.js.map +0 -1
- package/dist/workflows/action-execution-ledger.d.ts +0 -8
- package/dist/workflows/action-execution-ledger.d.ts.map +0 -1
- package/dist/workflows/action-execution-ledger.js +0 -64
- package/dist/workflows/action-execution-ledger.js.map +0 -1
- package/dist/workflows/action-policy.d.ts +0 -3
- package/dist/workflows/action-policy.d.ts.map +0 -1
- package/dist/workflows/action-policy.js +0 -13
- package/dist/workflows/action-policy.js.map +0 -1
- package/dist/workflows/action-provider-adapters.d.ts +0 -17
- package/dist/workflows/action-provider-adapters.d.ts.map +0 -1
- package/dist/workflows/action-provider-adapters.js +0 -674
- package/dist/workflows/action-provider-adapters.js.map +0 -1
- package/dist/workflows/action-provider-utils.d.ts +0 -25
- package/dist/workflows/action-provider-utils.d.ts.map +0 -1
- package/dist/workflows/action-provider-utils.js +0 -121
- package/dist/workflows/action-provider-utils.js.map +0 -1
- package/dist/workflows/approval-actor.d.ts +0 -6
- package/dist/workflows/approval-actor.d.ts.map +0 -1
- package/dist/workflows/approval-actor.js +0 -27
- package/dist/workflows/approval-actor.js.map +0 -1
- package/dist/workflows/approval-on-reject.d.ts +0 -17
- package/dist/workflows/approval-on-reject.d.ts.map +0 -1
- package/dist/workflows/approval-on-reject.js +0 -64
- package/dist/workflows/approval-on-reject.js.map +0 -1
- package/dist/workflows/artifact-collector.d.ts +0 -11
- package/dist/workflows/artifact-collector.d.ts.map +0 -1
- package/dist/workflows/artifact-collector.js +0 -59
- package/dist/workflows/artifact-collector.js.map +0 -1
- package/dist/workflows/checkout-node.d.ts +0 -22
- package/dist/workflows/checkout-node.d.ts.map +0 -1
- package/dist/workflows/checkout-node.js +0 -201
- package/dist/workflows/checkout-node.js.map +0 -1
- package/dist/workflows/context-node-resolver.d.ts +0 -51
- package/dist/workflows/context-node-resolver.d.ts.map +0 -1
- package/dist/workflows/context-node-resolver.js +0 -932
- package/dist/workflows/context-node-resolver.js.map +0 -1
- package/dist/workflows/context-update-targets.d.ts +0 -12
- package/dist/workflows/context-update-targets.d.ts.map +0 -1
- package/dist/workflows/context-update-targets.js +0 -52
- package/dist/workflows/context-update-targets.js.map +0 -1
- package/dist/workflows/contract-binding.d.ts +0 -3
- package/dist/workflows/contract-binding.d.ts.map +0 -1
- package/dist/workflows/contract-binding.js +0 -19
- package/dist/workflows/contract-binding.js.map +0 -1
- package/dist/workflows/daemon-session.d.ts +0 -47
- package/dist/workflows/daemon-session.d.ts.map +0 -1
- package/dist/workflows/daemon-session.js +0 -320
- package/dist/workflows/daemon-session.js.map +0 -1
- package/dist/workflows/event-types.d.ts +0 -10
- package/dist/workflows/event-types.d.ts.map +0 -1
- package/dist/workflows/event-types.js +0 -2
- package/dist/workflows/event-types.js.map +0 -1
- package/dist/workflows/expression.d.ts +0 -81
- package/dist/workflows/expression.d.ts.map +0 -1
- package/dist/workflows/expression.js +0 -149
- package/dist/workflows/expression.js.map +0 -1
- package/dist/workflows/git-publish-node.d.ts +0 -43
- package/dist/workflows/git-publish-node.d.ts.map +0 -1
- package/dist/workflows/git-publish-node.js +0 -322
- package/dist/workflows/git-publish-node.js.map +0 -1
- package/dist/workflows/hook-registry.d.ts +0 -24
- package/dist/workflows/hook-registry.d.ts.map +0 -1
- package/dist/workflows/hook-registry.js +0 -52
- package/dist/workflows/hook-registry.js.map +0 -1
- package/dist/workflows/hook-types.d.ts +0 -21
- package/dist/workflows/hook-types.d.ts.map +0 -1
- package/dist/workflows/hook-types.js +0 -2
- package/dist/workflows/hook-types.js.map +0 -1
- package/dist/workflows/inline-agent-types.d.ts +0 -28
- package/dist/workflows/inline-agent-types.d.ts.map +0 -1
- package/dist/workflows/inline-agent-types.js +0 -2
- package/dist/workflows/inline-agent-types.js.map +0 -1
- package/dist/workflows/inline-agents.d.ts +0 -8
- package/dist/workflows/inline-agents.d.ts.map +0 -1
- package/dist/workflows/inline-agents.js +0 -108
- package/dist/workflows/inline-agents.js.map +0 -1
- package/dist/workflows/loop-executor.d.ts +0 -17
- package/dist/workflows/loop-executor.d.ts.map +0 -1
- package/dist/workflows/loop-executor.js +0 -175
- package/dist/workflows/loop-executor.js.map +0 -1
- package/dist/workflows/node-executor.d.ts +0 -31
- package/dist/workflows/node-executor.d.ts.map +0 -1
- package/dist/workflows/node-executor.js +0 -405
- package/dist/workflows/node-executor.js.map +0 -1
- package/dist/workflows/node-registry.d.ts +0 -42
- package/dist/workflows/node-registry.d.ts.map +0 -1
- package/dist/workflows/node-registry.js +0 -931
- package/dist/workflows/node-registry.js.map +0 -1
- package/dist/workflows/parser.d.ts +0 -17
- package/dist/workflows/parser.d.ts.map +0 -1
- package/dist/workflows/parser.js +0 -361
- package/dist/workflows/parser.js.map +0 -1
- package/dist/workflows/platform-command-applier.d.ts +0 -17
- package/dist/workflows/platform-command-applier.d.ts.map +0 -1
- package/dist/workflows/platform-command-applier.js +0 -264
- package/dist/workflows/platform-command-applier.js.map +0 -1
- package/dist/workflows/platform-context-client.d.ts +0 -59
- package/dist/workflows/platform-context-client.d.ts.map +0 -1
- package/dist/workflows/platform-context-client.internal.d.ts +0 -23
- package/dist/workflows/platform-context-client.internal.d.ts.map +0 -1
- package/dist/workflows/platform-context-client.internal.js +0 -124
- package/dist/workflows/platform-context-client.internal.js.map +0 -1
- package/dist/workflows/platform-context-client.js +0 -272
- package/dist/workflows/platform-context-client.js.map +0 -1
- package/dist/workflows/platform-context-client.types.d.ts +0 -41
- package/dist/workflows/platform-context-client.types.d.ts.map +0 -1
- package/dist/workflows/platform-context-client.types.js +0 -2
- package/dist/workflows/platform-context-client.types.js.map +0 -1
- package/dist/workflows/platform-runtime-command.d.ts +0 -40
- package/dist/workflows/platform-runtime-command.d.ts.map +0 -1
- package/dist/workflows/platform-runtime-command.js +0 -104
- package/dist/workflows/platform-runtime-command.js.map +0 -1
- package/dist/workflows/platform-sync-format.d.ts +0 -12
- package/dist/workflows/platform-sync-format.d.ts.map +0 -1
- package/dist/workflows/platform-sync-format.js +0 -60
- package/dist/workflows/platform-sync-format.js.map +0 -1
- package/dist/workflows/platform-sync-payload.d.ts +0 -9
- package/dist/workflows/platform-sync-payload.d.ts.map +0 -1
- package/dist/workflows/platform-sync-payload.js +0 -504
- package/dist/workflows/platform-sync-payload.js.map +0 -1
- package/dist/workflows/platform-sync.d.ts +0 -37
- package/dist/workflows/platform-sync.d.ts.map +0 -1
- package/dist/workflows/platform-sync.js +0 -243
- package/dist/workflows/platform-sync.js.map +0 -1
- package/dist/workflows/plugin-loader.d.ts +0 -28
- package/dist/workflows/plugin-loader.d.ts.map +0 -1
- package/dist/workflows/plugin-loader.js +0 -143
- package/dist/workflows/plugin-loader.js.map +0 -1
- package/dist/workflows/policy-enforcement.d.ts +0 -43
- package/dist/workflows/policy-enforcement.d.ts.map +0 -1
- package/dist/workflows/policy-enforcement.js +0 -0
- package/dist/workflows/policy-enforcement.js.map +0 -1
- package/dist/workflows/preflight.d.ts +0 -9
- package/dist/workflows/preflight.d.ts.map +0 -1
- package/dist/workflows/preflight.js +0 -171
- package/dist/workflows/preflight.js.map +0 -1
- package/dist/workflows/prompt-output.d.ts +0 -10
- package/dist/workflows/prompt-output.d.ts.map +0 -1
- package/dist/workflows/prompt-output.js +0 -93
- package/dist/workflows/prompt-output.js.map +0 -1
- package/dist/workflows/provider-reconciliation.d.ts +0 -28
- package/dist/workflows/provider-reconciliation.d.ts.map +0 -1
- package/dist/workflows/provider-reconciliation.js +0 -218
- package/dist/workflows/provider-reconciliation.js.map +0 -1
- package/dist/workflows/retry-classifier.d.ts +0 -18
- package/dist/workflows/retry-classifier.d.ts.map +0 -1
- package/dist/workflows/retry-classifier.js +0 -30
- package/dist/workflows/retry-classifier.js.map +0 -1
- package/dist/workflows/review-packet.d.ts +0 -3
- package/dist/workflows/review-packet.d.ts.map +0 -1
- package/dist/workflows/review-packet.js +0 -155
- package/dist/workflows/review-packet.js.map +0 -1
- package/dist/workflows/run-preparation.d.ts +0 -24
- package/dist/workflows/run-preparation.d.ts.map +0 -1
- package/dist/workflows/run-preparation.js +0 -258
- package/dist/workflows/run-preparation.js.map +0 -1
- package/dist/workflows/run-types.d.ts +0 -261
- package/dist/workflows/run-types.d.ts.map +0 -1
- package/dist/workflows/run-types.js +0 -2
- package/dist/workflows/run-types.js.map +0 -1
- package/dist/workflows/runner-canceler.d.ts +0 -22
- package/dist/workflows/runner-canceler.d.ts.map +0 -1
- package/dist/workflows/runner-canceler.js +0 -91
- package/dist/workflows/runner-canceler.js.map +0 -1
- package/dist/workflows/runner-hook-events.d.ts +0 -19
- package/dist/workflows/runner-hook-events.d.ts.map +0 -1
- package/dist/workflows/runner-hook-events.js +0 -16
- package/dist/workflows/runner-hook-events.js.map +0 -1
- package/dist/workflows/runner-reconciler.d.ts +0 -19
- package/dist/workflows/runner-reconciler.d.ts.map +0 -1
- package/dist/workflows/runner-reconciler.js +0 -109
- package/dist/workflows/runner-reconciler.js.map +0 -1
- package/dist/workflows/runner-resumer.d.ts +0 -33
- package/dist/workflows/runner-resumer.d.ts.map +0 -1
- package/dist/workflows/runner-resumer.js +0 -81
- package/dist/workflows/runner-resumer.js.map +0 -1
- package/dist/workflows/runner-scheduler.d.ts +0 -38
- package/dist/workflows/runner-scheduler.d.ts.map +0 -1
- package/dist/workflows/runner-scheduler.js +0 -243
- package/dist/workflows/runner-scheduler.js.map +0 -1
- package/dist/workflows/runner-shared.d.ts +0 -21
- package/dist/workflows/runner-shared.d.ts.map +0 -1
- package/dist/workflows/runner-shared.js +0 -92
- package/dist/workflows/runner-shared.js.map +0 -1
- package/dist/workflows/runner.d.ts +0 -49
- package/dist/workflows/runner.d.ts.map +0 -1
- package/dist/workflows/runner.js +0 -661
- package/dist/workflows/runner.js.map +0 -1
- package/dist/workflows/runtime-helpers.d.ts +0 -60
- package/dist/workflows/runtime-helpers.d.ts.map +0 -1
- package/dist/workflows/runtime-helpers.js +0 -267
- package/dist/workflows/runtime-helpers.js.map +0 -1
- package/dist/workflows/session-completion.d.ts +0 -7
- package/dist/workflows/session-completion.d.ts.map +0 -1
- package/dist/workflows/session-completion.js +0 -117
- package/dist/workflows/session-completion.js.map +0 -1
- package/dist/workflows/session-links.d.ts +0 -21
- package/dist/workflows/session-links.d.ts.map +0 -1
- package/dist/workflows/session-links.js +0 -77
- package/dist/workflows/session-links.js.map +0 -1
- package/dist/workflows/session-output.d.ts +0 -30
- package/dist/workflows/session-output.d.ts.map +0 -1
- package/dist/workflows/session-output.js +0 -231
- package/dist/workflows/session-output.js.map +0 -1
- package/dist/workflows/session-policy.d.ts +0 -39
- package/dist/workflows/session-policy.d.ts.map +0 -1
- package/dist/workflows/session-policy.js +0 -93
- package/dist/workflows/session-policy.js.map +0 -1
- package/dist/workflows/shell-abort-registry.d.ts +0 -11
- package/dist/workflows/shell-abort-registry.d.ts.map +0 -1
- package/dist/workflows/shell-abort-registry.js +0 -35
- package/dist/workflows/shell-abort-registry.js.map +0 -1
- package/dist/workflows/store.d.ts +0 -14
- package/dist/workflows/store.d.ts.map +0 -1
- package/dist/workflows/store.js +0 -160
- package/dist/workflows/store.js.map +0 -1
- package/dist/workflows/structured-outputs.d.ts +0 -24
- package/dist/workflows/structured-outputs.d.ts.map +0 -1
- package/dist/workflows/structured-outputs.js +0 -174
- package/dist/workflows/structured-outputs.js.map +0 -1
- package/dist/workflows/subflow-executor.d.ts +0 -15
- package/dist/workflows/subflow-executor.d.ts.map +0 -1
- package/dist/workflows/subflow-executor.js +0 -181
- package/dist/workflows/subflow-executor.js.map +0 -1
- package/dist/workflows/trigger-rule.d.ts +0 -22
- package/dist/workflows/trigger-rule.d.ts.map +0 -1
- package/dist/workflows/trigger-rule.js +0 -57
- package/dist/workflows/trigger-rule.js.map +0 -1
- package/dist/workflows/types.d.ts +0 -418
- package/dist/workflows/types.d.ts.map +0 -1
- package/dist/workflows/types.js +0 -2
- package/dist/workflows/types.js.map +0 -1
- package/dist/workflows/workflow-authority-contract.d.ts +0 -25
- package/dist/workflows/workflow-authority-contract.d.ts.map +0 -1
- package/dist/workflows/workflow-authority-contract.js +0 -389
- package/dist/workflows/workflow-authority-contract.js.map +0 -1
- package/dist/workflows/workflow-executor-schema.d.ts +0 -51
- package/dist/workflows/workflow-executor-schema.d.ts.map +0 -1
- package/dist/workflows/workflow-executor-schema.js +0 -81
- package/dist/workflows/workflow-executor-schema.js.map +0 -1
- package/dist/workflows/workflow-production-schema.d.ts +0 -178
- package/dist/workflows/workflow-production-schema.d.ts.map +0 -1
- package/dist/workflows/workflow-production-schema.js +0 -202
- package/dist/workflows/workflow-production-schema.js.map +0 -1
- package/dist/workflows/workflow-production-types.d.ts +0 -123
- package/dist/workflows/workflow-production-types.d.ts.map +0 -1
- package/dist/workflows/workflow-production-types.js +0 -2
- package/dist/workflows/workflow-production-types.js.map +0 -1
- package/dist/workflows/workflow-schema-common.d.ts +0 -332
- package/dist/workflows/workflow-schema-common.d.ts.map +0 -1
- package/dist/workflows/workflow-schema-common.js +0 -135
- package/dist/workflows/workflow-schema-common.js.map +0 -1
- package/dist/workflows/workflow-schema.d.ts +0 -3037
- package/dist/workflows/workflow-schema.d.ts.map +0 -1
- package/dist/workflows/workflow-schema.js +0 -415
- package/dist/workflows/workflow-schema.js.map +0 -1
- package/dist/workflows/workflow-source.d.ts +0 -3
- package/dist/workflows/workflow-source.d.ts.map +0 -1
- package/dist/workflows/workflow-source.js +0 -29
- package/dist/workflows/workflow-source.js.map +0 -1
- package/docs/README.md +0 -18
- package/docs/configuration.md +0 -248
- package/docs/developer-workflows.md +0 -123
- package/docs/protocol-matrix.json +0 -375
- package/docs/protocol-pin.json +0 -5
- package/docs/releasing.md +0 -36
- package/docs/security.md +0 -49
- package/docs/test-vectors/relay-noise-v2.json +0 -42
- package/docs/test-vectors/relay-noise-v3.json +0 -51
- package/docs/testing.md +0 -112
- package/node_modules/@viewportai/context-engine/README.md +0 -33
- package/node_modules/@viewportai/context-engine/fixtures/protocol-vectors/README.md +0 -37
- package/node_modules/@viewportai/context-engine/fixtures/protocol-vectors/bundle-manifest.json +0 -50
- package/node_modules/@viewportai/context-engine/fixtures/protocol-vectors/erase-receipt.json +0 -10
- package/node_modules/@viewportai/context-engine/fixtures/protocol-vectors/event.json +0 -29
- package/node_modules/@viewportai/context-engine/fixtures/protocol-vectors/hpke-key-grant.json +0 -24
- package/node_modules/@viewportai/context-engine/fixtures/protocol-vectors/key-grant.json +0 -21
- package/node_modules/@viewportai/context-engine/fixtures/protocol-vectors/profile.json +0 -12
- package/node_modules/@viewportai/context-engine/fixtures/protocol-vectors/signed-event.json +0 -28
- package/node_modules/@viewportai/context-engine/fixtures/protocol-vectors/standalone-decoder.mjs +0 -124
- package/node_modules/@viewportai/context-engine/package.json +0 -11
- package/node_modules/@viewportai/context-engine/schemas/context_bundle_manifest_v1.schema.json +0 -134
- package/node_modules/@viewportai/context-engine/schemas/context_erase_receipt_v1.schema.json +0 -27
- package/node_modules/@viewportai/context-engine/schemas/context_event_v1.schema.json +0 -216
- package/node_modules/@viewportai/context-engine/schemas/context_key_grant_hpke_draft_01.schema.json +0 -27
- package/node_modules/@viewportai/context-engine/schemas/context_key_grant_v1.schema.json +0 -24
- package/node_modules/@viewportai/context-engine/schemas/context_profile_v1.schema.json +0 -24
- package/node_modules/@viewportai/context-engine/src/cli.js +0 -177
- package/node_modules/@viewportai/context-engine/src/crypto/canonical.js +0 -21
- package/node_modules/@viewportai/context-engine/src/crypto/envelope.js +0 -37
- package/node_modules/@viewportai/context-engine/src/crypto/hpke-grants.js +0 -298
- package/node_modules/@viewportai/context-engine/src/crypto/keys.js +0 -122
- package/node_modules/@viewportai/context-engine/src/crypto/signatures.js +0 -23
- package/node_modules/@viewportai/context-engine/src/index.js +0 -12
- package/node_modules/@viewportai/context-engine/src/protocol/schemas.js +0 -50
- package/node_modules/@viewportai/context-engine/src/repo/access-model.js +0 -170
- package/node_modules/@viewportai/context-engine/src/repo/bundles.js +0 -180
- package/node_modules/@viewportai/context-engine/src/repo/candidates.js +0 -207
- package/node_modules/@viewportai/context-engine/src/repo/devices.js +0 -141
- package/node_modules/@viewportai/context-engine/src/repo/events.js +0 -101
- package/node_modules/@viewportai/context-engine/src/repo/files.js +0 -33
- package/node_modules/@viewportai/context-engine/src/repo/identities.js +0 -132
- package/node_modules/@viewportai/context-engine/src/repo/key-store.js +0 -126
- package/node_modules/@viewportai/context-engine/src/repo/materializer.js +0 -314
- package/node_modules/@viewportai/context-engine/src/repo/membership.js +0 -192
- package/node_modules/@viewportai/context-engine/src/repo/paths.js +0 -25
- package/node_modules/@viewportai/context-engine/src/repo/profiles.js +0 -54
- package/node_modules/@viewportai/context-engine/src/repo/receipts.js +0 -68
- package/node_modules/@viewportai/context-engine/src/repo/sync.js +0 -163
- package/node_modules/@viewportai/context-engine/src/repo/users.js +0 -134
- package/node_modules/@viewportai/context-engine/src/repo/vault.js +0 -548
- package/node_modules/@viewportai/context-engine/src/store/local-semantic.js +0 -69
- package/node_modules/@viewportai/context-engine/src/store/search.js +0 -25
- package/node_modules/@viewportai/context-engine/src/store/sqlite.js +0 -76
- package/schemas/viewport-config-v1.schema.json +0 -213
- package/schemas/workflow-v1.schema.json +0 -510
package/dist/cli/bin.js
ADDED
|
@@ -0,0 +1,2311 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
checkRelayTransport,
|
|
4
|
+
connectRelay
|
|
5
|
+
} from "../chunk-K2WDCPZB.js";
|
|
6
|
+
import {
|
|
7
|
+
DAEMON_VERSION,
|
|
8
|
+
NO_ISOLATION_WARNING,
|
|
9
|
+
readToken,
|
|
10
|
+
serve,
|
|
11
|
+
socketPathLimit,
|
|
12
|
+
socketPathTooLong
|
|
13
|
+
} from "../chunk-EACFI34X.js";
|
|
14
|
+
import {
|
|
15
|
+
VERSION
|
|
16
|
+
} from "../chunk-62D4ICYA.js";
|
|
17
|
+
import {
|
|
18
|
+
callTool,
|
|
19
|
+
exit,
|
|
20
|
+
fail,
|
|
21
|
+
fakeRunner,
|
|
22
|
+
output,
|
|
23
|
+
say,
|
|
24
|
+
waitForInput
|
|
25
|
+
} from "../chunk-5MLJY3NS.js";
|
|
26
|
+
import {
|
|
27
|
+
CLAUDE_AUTH_FIX,
|
|
28
|
+
CLAUDE_AUTH_SHORT,
|
|
29
|
+
NOT_INSTALLED,
|
|
30
|
+
claudeCodeRunner,
|
|
31
|
+
claudeTokenPath,
|
|
32
|
+
createSupervisor,
|
|
33
|
+
nodePtyStatus,
|
|
34
|
+
sendSignal,
|
|
35
|
+
terminateGroup,
|
|
36
|
+
writeClaudeToken
|
|
37
|
+
} from "../chunk-76ISR4QO.js";
|
|
38
|
+
import "../chunk-NBLB22VR.js";
|
|
39
|
+
import {
|
|
40
|
+
ENV_NAME,
|
|
41
|
+
ensurePrivateDir,
|
|
42
|
+
readJson,
|
|
43
|
+
takeEnvSecrets,
|
|
44
|
+
writeAtomic,
|
|
45
|
+
writeAtomicJson
|
|
46
|
+
} from "../chunk-BFV7PIQD.js";
|
|
47
|
+
import {
|
|
48
|
+
consolePort
|
|
49
|
+
} from "../chunk-YJFNBSD3.js";
|
|
50
|
+
import {
|
|
51
|
+
parseServerMessage
|
|
52
|
+
} from "../chunk-33YDFYW2.js";
|
|
53
|
+
import {
|
|
54
|
+
DaemonError,
|
|
55
|
+
MAX_PAIR_TTL_MS,
|
|
56
|
+
MIN_PAIR_TTL_MS,
|
|
57
|
+
PROTOCOL_ID,
|
|
58
|
+
Status,
|
|
59
|
+
isDaemonError,
|
|
60
|
+
isTerminalStatus
|
|
61
|
+
} from "../chunk-FXZH5JGQ.js";
|
|
62
|
+
|
|
63
|
+
// src/cli/io.ts
|
|
64
|
+
import os from "os";
|
|
65
|
+
import path from "path";
|
|
66
|
+
|
|
67
|
+
// src/cli/exit.ts
|
|
68
|
+
var EXIT = {
|
|
69
|
+
ok: 0,
|
|
70
|
+
/** Anything that failed: a daemon error, a refused request, a timeout, a runner unavailable for another reason than isolation. */
|
|
71
|
+
error: 1,
|
|
72
|
+
/** Bad command line. */
|
|
73
|
+
usage: 2,
|
|
74
|
+
/** No daemon answers on `<home>/daemon.sock`. */
|
|
75
|
+
notRunning: 3,
|
|
76
|
+
/** The requested child isolation cannot be enforced on this machine (`daemon.runner_unavailable` at start). */
|
|
77
|
+
isolationUnavailable: 4,
|
|
78
|
+
/** Interrupted by Ctrl-C while waiting (`pair`). */
|
|
79
|
+
interrupted: 130
|
|
80
|
+
};
|
|
81
|
+
var EXIT_CODES_HELP = `Exit codes:
|
|
82
|
+
0 ok
|
|
83
|
+
1 error (the daemon refused, a request failed, a timeout, the runner is unavailable)
|
|
84
|
+
2 usage (bad flags or arguments)
|
|
85
|
+
3 the daemon is not running
|
|
86
|
+
4 child isolation unavailable
|
|
87
|
+
130 interrupted while waiting
|
|
88
|
+
run and attach exit with the session's own exit code once it ends (128 + n for signal n).`;
|
|
89
|
+
var CliError = class extends Error {
|
|
90
|
+
constructor(message, exitCode = EXIT.error, code2 = "cli.error", details) {
|
|
91
|
+
super(message);
|
|
92
|
+
this.exitCode = exitCode;
|
|
93
|
+
this.code = code2;
|
|
94
|
+
this.details = details;
|
|
95
|
+
this.name = "CliError";
|
|
96
|
+
}
|
|
97
|
+
exitCode;
|
|
98
|
+
code;
|
|
99
|
+
details;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// src/cli/io.ts
|
|
103
|
+
function nodeIO() {
|
|
104
|
+
return {
|
|
105
|
+
stdout: process.stdout,
|
|
106
|
+
stderr: process.stderr,
|
|
107
|
+
stdin: process.stdin,
|
|
108
|
+
env: process.env,
|
|
109
|
+
cwd: process.cwd(),
|
|
110
|
+
onInterrupt(handler, options = {}) {
|
|
111
|
+
const signals = options.terminate ? ["SIGINT", "SIGTERM", "SIGHUP"] : ["SIGINT"];
|
|
112
|
+
for (const signal of signals) process.on(signal, handler);
|
|
113
|
+
return () => {
|
|
114
|
+
for (const signal of signals) process.off(signal, handler);
|
|
115
|
+
};
|
|
116
|
+
},
|
|
117
|
+
onResize(handler) {
|
|
118
|
+
process.on("SIGWINCH", handler);
|
|
119
|
+
return () => process.off("SIGWINCH", handler);
|
|
120
|
+
},
|
|
121
|
+
entry: [process.execPath, ...process.execArgv, path.resolve(process.argv[1] ?? "")]
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function resolveHome(flag, io) {
|
|
125
|
+
const base = flag ?? io.env.VIEWPORT_HOME ?? path.join(io.env.HOME ?? os.homedir(), ".viewport", "daemon");
|
|
126
|
+
const home = path.resolve(io.cwd, base);
|
|
127
|
+
return {
|
|
128
|
+
home,
|
|
129
|
+
socket: path.join(home, "daemon.sock"),
|
|
130
|
+
token: path.join(home, "token"),
|
|
131
|
+
identity: path.join(home, "identity.json"),
|
|
132
|
+
pid: path.join(home, "daemon.pid"),
|
|
133
|
+
state: path.join(home, "daemon.json"),
|
|
134
|
+
log: path.join(home, "daemon.log"),
|
|
135
|
+
lock: path.join(home, "writer.lock")
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function assertSocketPathFits(paths) {
|
|
139
|
+
const tooLong = socketPathTooLong(paths.socket);
|
|
140
|
+
if (tooLong) {
|
|
141
|
+
throw new CliError(
|
|
142
|
+
`Socket path too long, use a shorter --home: ${tooLong}.`,
|
|
143
|
+
EXIT.error,
|
|
144
|
+
"cli.socket_path_too_long",
|
|
145
|
+
{
|
|
146
|
+
socket: paths.socket
|
|
147
|
+
}
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/cli/args.ts
|
|
153
|
+
var GLOBAL_FLAGS = {
|
|
154
|
+
home: { type: "string", value: "<dir>", description: "Daemon home (default $VIEWPORT_HOME or ~/.viewport/daemon)" },
|
|
155
|
+
json: { type: "boolean", description: "Machine output: one JSON document, or JSON lines for streaming commands" },
|
|
156
|
+
help: { type: "boolean", short: "h", description: "Show help for this command" }
|
|
157
|
+
};
|
|
158
|
+
var usage = (message) => new CliError(message, EXIT.usage, "cli.usage");
|
|
159
|
+
function parseArgs(spec, argv) {
|
|
160
|
+
const flags = {};
|
|
161
|
+
const all = { ...spec.flags, ...GLOBAL_FLAGS };
|
|
162
|
+
const shorts = new Map(Object.entries(all).flatMap(([name, f]) => f.short ? [[f.short, name]] : []));
|
|
163
|
+
const positionals = [];
|
|
164
|
+
let rest;
|
|
165
|
+
for (let i = 0; i < argv.length; i++) {
|
|
166
|
+
const arg = argv[i];
|
|
167
|
+
if (arg === "--") {
|
|
168
|
+
if (!spec.rest) throw usage(`${spec.name} does not take arguments after --.`);
|
|
169
|
+
rest = argv.slice(i + 1);
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
if (arg.startsWith("--") || arg.startsWith("-") && arg.length === 2 && arg !== "-") {
|
|
173
|
+
let name;
|
|
174
|
+
let inline;
|
|
175
|
+
if (arg.startsWith("--")) {
|
|
176
|
+
const eq = arg.indexOf("=");
|
|
177
|
+
name = eq < 0 ? arg.slice(2) : arg.slice(2, eq);
|
|
178
|
+
inline = eq < 0 ? void 0 : arg.slice(eq + 1);
|
|
179
|
+
} else {
|
|
180
|
+
const long = shorts.get(arg.slice(1));
|
|
181
|
+
if (!long) throw usage(`Unknown flag ${arg} for ${spec.name}.`);
|
|
182
|
+
name = long;
|
|
183
|
+
}
|
|
184
|
+
const flag = all[name];
|
|
185
|
+
if (!flag) throw usage(`Unknown flag --${name} for ${spec.name}.`);
|
|
186
|
+
if (flag.type === "boolean") {
|
|
187
|
+
if (inline !== void 0) throw usage(`--${name} takes no value.`);
|
|
188
|
+
flags[name] = true;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
let value = inline;
|
|
192
|
+
if (value === void 0) {
|
|
193
|
+
const next = argv[i + 1];
|
|
194
|
+
if (next === void 0 || next === "--")
|
|
195
|
+
throw usage(`--${name} needs a value${flag.value ? ` ${flag.value}` : ""}.`);
|
|
196
|
+
value = next;
|
|
197
|
+
i++;
|
|
198
|
+
}
|
|
199
|
+
if (flag.multiple) flags[name] = [...flags[name] ?? [], value];
|
|
200
|
+
else if (flags[name] !== void 0) throw usage(`--${name} was given twice.`);
|
|
201
|
+
else flags[name] = value;
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
positionals.push(arg);
|
|
205
|
+
}
|
|
206
|
+
if (flags.help) return { flags, positionals, rest };
|
|
207
|
+
const names = spec.positionals ?? [];
|
|
208
|
+
const variadic = names.at(-1)?.endsWith("...") ?? false;
|
|
209
|
+
const required = names.filter((n) => !n.startsWith("[")).length;
|
|
210
|
+
if (positionals.length < required) {
|
|
211
|
+
throw usage(`${spec.name} needs ${names.filter((n) => !n.startsWith("["))[positionals.length]}.`);
|
|
212
|
+
}
|
|
213
|
+
if (!variadic && positionals.length > names.length) {
|
|
214
|
+
throw usage(`Unexpected argument ${JSON.stringify(positionals[names.length])} for ${spec.name}.`);
|
|
215
|
+
}
|
|
216
|
+
return { flags, positionals, rest };
|
|
217
|
+
}
|
|
218
|
+
function commandHelp(program, spec) {
|
|
219
|
+
const rows = Object.entries({ ...spec.flags, ...GLOBAL_FLAGS }).filter(([, f]) => !f.hidden).map(([name, f]) => [
|
|
220
|
+
`${f.short ? `-${f.short}, ` : " "}--${name}${f.value ? ` ${f.value}` : ""}`,
|
|
221
|
+
f.description
|
|
222
|
+
]);
|
|
223
|
+
const width = Math.max(...rows.map(([left]) => left.length));
|
|
224
|
+
const lines = [
|
|
225
|
+
`Usage: ${program} ${spec.usage}`,
|
|
226
|
+
"",
|
|
227
|
+
spec.summary,
|
|
228
|
+
...spec.details ? ["", spec.details] : [],
|
|
229
|
+
"",
|
|
230
|
+
"Flags:",
|
|
231
|
+
...rows.map(([left, right]) => ` ${left.padEnd(width)} ${right}`)
|
|
232
|
+
];
|
|
233
|
+
return `${lines.join("\n")}
|
|
234
|
+
`;
|
|
235
|
+
}
|
|
236
|
+
function parseDuration(text, flag) {
|
|
237
|
+
const match = /^(\d+)(ms|s|m|h)?$/.exec(text.trim());
|
|
238
|
+
if (!match) throw usage(`--${flag} must be a duration like 90s, 10m or 1h.`);
|
|
239
|
+
const n = Number(match[1]);
|
|
240
|
+
const unit = { ms: 1, s: 1e3, m: 6e4, h: 36e5 }[match[2] ?? "s"];
|
|
241
|
+
return n * unit;
|
|
242
|
+
}
|
|
243
|
+
function parseInteger(text, flag, min = 0, max = Number.MAX_SAFE_INTEGER) {
|
|
244
|
+
if (!/^\d+$/.test(text)) throw usage(`--${flag} must be a whole number.`);
|
|
245
|
+
const n = Number(text);
|
|
246
|
+
if (n < min || n > max) throw usage(`--${flag} must be ${min} to ${max}.`);
|
|
247
|
+
return n;
|
|
248
|
+
}
|
|
249
|
+
function parseHostPort(text, flag) {
|
|
250
|
+
const match = /^(?:\[([^\]]+)\]|([^:[\]]+)):(\d{1,5})$/.exec(text);
|
|
251
|
+
if (!match) throw usage(`--${flag} must be host:port, e.g. 127.0.0.1:7070.`);
|
|
252
|
+
const port = Number(match[3]);
|
|
253
|
+
if (port > 65535) throw usage(`--${flag} port must be 0 to 65535.`);
|
|
254
|
+
return { host: match[1] ?? match[2], port };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// src/cli/claude-token.ts
|
|
258
|
+
import fs from "fs/promises";
|
|
259
|
+
|
|
260
|
+
// src/cli/local.ts
|
|
261
|
+
import { WebSocket } from "ws";
|
|
262
|
+
var RequestError = class extends Error {
|
|
263
|
+
constructor(error) {
|
|
264
|
+
super(error.message);
|
|
265
|
+
this.error = error;
|
|
266
|
+
this.name = "RequestError";
|
|
267
|
+
}
|
|
268
|
+
error;
|
|
269
|
+
get code() {
|
|
270
|
+
return this.error.code;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
var notRunning = (paths, why) => new CliError(
|
|
274
|
+
`The daemon is not running (${why}). Start it with \`viewport-daemon up --home ${paths.home}\`.`,
|
|
275
|
+
EXIT.notRunning,
|
|
276
|
+
"cli.not_running",
|
|
277
|
+
{ home: paths.home, socket: paths.socket }
|
|
278
|
+
);
|
|
279
|
+
var LocalDaemon = class _LocalDaemon {
|
|
280
|
+
#ws;
|
|
281
|
+
#pending = /* @__PURE__ */ new Map();
|
|
282
|
+
#listeners = /* @__PURE__ */ new Set();
|
|
283
|
+
#next = 0;
|
|
284
|
+
#closedWith;
|
|
285
|
+
#closed = false;
|
|
286
|
+
closed;
|
|
287
|
+
#resolveClosed;
|
|
288
|
+
hello;
|
|
289
|
+
constructor(ws) {
|
|
290
|
+
this.#ws = ws;
|
|
291
|
+
this.closed = new Promise((resolve) => {
|
|
292
|
+
this.#resolveClosed = resolve;
|
|
293
|
+
});
|
|
294
|
+
ws.on("message", (data, isBinary) => {
|
|
295
|
+
if (isBinary) return;
|
|
296
|
+
const parsed = parseServerMessage(data.toString());
|
|
297
|
+
if (!parsed.ok || !parsed.value) return;
|
|
298
|
+
const message = parsed.value;
|
|
299
|
+
if (message.type === "result") {
|
|
300
|
+
const waiter = this.#pending.get(message.id);
|
|
301
|
+
this.#pending.delete(message.id);
|
|
302
|
+
if (message.ok) waiter?.resolve(message.data);
|
|
303
|
+
else waiter?.reject(new RequestError(message.error));
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
if (message.type === "bye") this.#closedWith = message.reason;
|
|
307
|
+
for (const listener of [...this.#listeners]) listener(message);
|
|
308
|
+
});
|
|
309
|
+
ws.once("close", (code2, reason) => {
|
|
310
|
+
const text = reason.toString();
|
|
311
|
+
if (!this.#closedWith && code2 !== 1e3 && text) this.#closedWith = { code: text, message: "Connection closed." };
|
|
312
|
+
this.#finish();
|
|
313
|
+
});
|
|
314
|
+
ws.on("error", () => this.#finish());
|
|
315
|
+
}
|
|
316
|
+
#finish() {
|
|
317
|
+
if (this.#closed) return;
|
|
318
|
+
this.#closed = true;
|
|
319
|
+
const error = new RequestError(
|
|
320
|
+
this.#closedWith ?? { code: "daemon.shutting_down", message: "The daemon closed the connection." }
|
|
321
|
+
);
|
|
322
|
+
for (const waiter of this.#pending.values()) waiter.reject(error);
|
|
323
|
+
this.#pending.clear();
|
|
324
|
+
this.#resolveClosed(this.#closedWith);
|
|
325
|
+
}
|
|
326
|
+
/** Connect and run `hello`. Fails with exit 3 when no daemon answers. */
|
|
327
|
+
static async open(paths, options = {}) {
|
|
328
|
+
let token;
|
|
329
|
+
try {
|
|
330
|
+
token = await readToken(paths.token);
|
|
331
|
+
} catch (error) {
|
|
332
|
+
throw new CliError(
|
|
333
|
+
isDaemonError(error) ? error.message : `Cannot read ${paths.token}.`,
|
|
334
|
+
EXIT.error,
|
|
335
|
+
"daemon.invalid_identity"
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
if (token === void 0) throw notRunning(paths, `no token at ${paths.token}`);
|
|
339
|
+
const ws = new WebSocket(`ws+unix://${paths.socket}:/v1/ws`, {
|
|
340
|
+
headers: { authorization: `Bearer ${token}` },
|
|
341
|
+
handshakeTimeout: options.timeoutMs ?? 5e3
|
|
342
|
+
});
|
|
343
|
+
token = void 0;
|
|
344
|
+
await new Promise((resolve, reject) => {
|
|
345
|
+
ws.once("open", () => resolve());
|
|
346
|
+
ws.once("unexpected-response", (_req, res) => {
|
|
347
|
+
res.resume();
|
|
348
|
+
ws.terminate();
|
|
349
|
+
reject(
|
|
350
|
+
res.statusCode === 401 ? new CliError(`The daemon refused ${paths.token} (HTTP 401).`, EXIT.error, "daemon.forbidden") : new CliError(`The daemon answered HTTP ${res.statusCode}.`, EXIT.error, "cli.error")
|
|
351
|
+
);
|
|
352
|
+
});
|
|
353
|
+
ws.once("error", (error) => {
|
|
354
|
+
const missing = error.code === "ENOENT" || error.code === "ECONNREFUSED" || error.code === "ENOTSOCK";
|
|
355
|
+
reject(missing ? notRunning(paths, `nothing answers on ${paths.socket}`) : error);
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
const daemon = new _LocalDaemon(ws);
|
|
359
|
+
daemon.hello = await daemon.request("hello", {
|
|
360
|
+
protocols: [PROTOCOL_ID],
|
|
361
|
+
client: { name: "viewport-daemon-cli", version: VERSION }
|
|
362
|
+
});
|
|
363
|
+
return daemon;
|
|
364
|
+
}
|
|
365
|
+
request(type, fields) {
|
|
366
|
+
if (this.#closed) {
|
|
367
|
+
return Promise.reject(
|
|
368
|
+
new RequestError(this.#closedWith ?? { code: "daemon.shutting_down", message: "The connection is closed." })
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
const id = String(++this.#next);
|
|
372
|
+
return new Promise((resolve, reject) => {
|
|
373
|
+
this.#pending.set(id, { resolve, reject });
|
|
374
|
+
this.#ws.send(JSON.stringify({ ...fields, type, id }));
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
onPush(listener) {
|
|
378
|
+
this.#listeners.add(listener);
|
|
379
|
+
return () => this.#listeners.delete(listener);
|
|
380
|
+
}
|
|
381
|
+
close() {
|
|
382
|
+
if (this.#ws.readyState === WebSocket.OPEN || this.#ws.readyState === WebSocket.CONNECTING) this.#ws.close(1e3);
|
|
383
|
+
this.#finish();
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
async function withDaemon(paths, fn) {
|
|
387
|
+
const daemon = await LocalDaemon.open(paths);
|
|
388
|
+
try {
|
|
389
|
+
return await fn(daemon);
|
|
390
|
+
} finally {
|
|
391
|
+
daemon.close();
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// src/cli/output.ts
|
|
396
|
+
var Output = class {
|
|
397
|
+
constructor(io, json) {
|
|
398
|
+
this.io = io;
|
|
399
|
+
this.json = json;
|
|
400
|
+
}
|
|
401
|
+
io;
|
|
402
|
+
json;
|
|
403
|
+
/** One JSON document (or one JSON line of a stream). */
|
|
404
|
+
data(value) {
|
|
405
|
+
this.io.stdout.write(`${JSON.stringify(value)}
|
|
406
|
+
`);
|
|
407
|
+
}
|
|
408
|
+
/** A human line on stdout; nothing in JSON mode. */
|
|
409
|
+
line(text = "") {
|
|
410
|
+
if (!this.json) this.io.stdout.write(`${text}
|
|
411
|
+
`);
|
|
412
|
+
}
|
|
413
|
+
/** A human notice on stderr; nothing in JSON mode. */
|
|
414
|
+
note(text) {
|
|
415
|
+
if (!this.json) this.io.stderr.write(`${text}
|
|
416
|
+
`);
|
|
417
|
+
}
|
|
418
|
+
/** Both modes: `value` as JSON, or `text` for humans. */
|
|
419
|
+
result(value, text) {
|
|
420
|
+
if (this.json) this.data(value);
|
|
421
|
+
else this.io.stdout.write(`${text}
|
|
422
|
+
`);
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
var CONTROL = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/g;
|
|
426
|
+
var ANY_CONTROL = /[\u0000-\u001f\u007f-\u009f]/g;
|
|
427
|
+
function printable(text) {
|
|
428
|
+
return text.replace(CONTROL, "");
|
|
429
|
+
}
|
|
430
|
+
function visible(text) {
|
|
431
|
+
return text.replace(ANY_CONTROL, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
432
|
+
}
|
|
433
|
+
function table(header, rows) {
|
|
434
|
+
const widths = header.map((h, i) => Math.max(h.length, ...rows.map((r) => (r[i] ?? "").length)));
|
|
435
|
+
const line = (cells) => cells.map((c, i) => i === cells.length - 1 ? c : c.padEnd(widths[i])).join(" ").trimEnd();
|
|
436
|
+
return [line(header), ...rows.map(line)].join("\n");
|
|
437
|
+
}
|
|
438
|
+
function groups(id) {
|
|
439
|
+
const [prefix, body] = [id.slice(0, 4), id.slice(4)];
|
|
440
|
+
return `${prefix} ${(body.match(/.{1,4}/g) ?? []).join(" ")}`;
|
|
441
|
+
}
|
|
442
|
+
function when(iso) {
|
|
443
|
+
if (!iso) return "-";
|
|
444
|
+
const d = new Date(iso);
|
|
445
|
+
if (Number.isNaN(d.getTime())) return iso;
|
|
446
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
447
|
+
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
|
|
448
|
+
}
|
|
449
|
+
function shortReason(reason) {
|
|
450
|
+
if (reason === CLAUDE_AUTH_FIX) return CLAUDE_AUTH_SHORT;
|
|
451
|
+
const first = reason.split(/(?<=\.)\s/)[0].replace(/\.$/, "");
|
|
452
|
+
return first.length <= 80 ? first : `${first.slice(0, 79)}\u2026`;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// src/cli/pairing.ts
|
|
456
|
+
var str = (ctx, name) => ctx.flags[name];
|
|
457
|
+
var usage2 = (message) => new CliError(message, EXIT.usage, "cli.usage");
|
|
458
|
+
function rebaseLink(link, consoleUrl) {
|
|
459
|
+
return `${consoleUrl.replace(/[#?].*$/, "").replace(/\/+$/, "")}/pair${link.slice(link.indexOf("#"))}`;
|
|
460
|
+
}
|
|
461
|
+
function readLine(stdin, timeoutMs, signal) {
|
|
462
|
+
if (!stdin) return Promise.resolve(void 0);
|
|
463
|
+
return new Promise((resolve) => {
|
|
464
|
+
let buffer = "";
|
|
465
|
+
const done = (value) => {
|
|
466
|
+
clearTimeout(timer);
|
|
467
|
+
stdin.off("data", onData);
|
|
468
|
+
stdin.off("end", onEnd);
|
|
469
|
+
signal?.removeEventListener("abort", onAbort);
|
|
470
|
+
stdin.pause();
|
|
471
|
+
resolve(value);
|
|
472
|
+
};
|
|
473
|
+
const onData = (chunk) => {
|
|
474
|
+
buffer += chunk.toString();
|
|
475
|
+
const nl = buffer.indexOf("\n");
|
|
476
|
+
if (nl >= 0) done(buffer.slice(0, nl));
|
|
477
|
+
};
|
|
478
|
+
const onEnd = () => done(buffer === "" ? void 0 : buffer);
|
|
479
|
+
const onAbort = () => done(void 0);
|
|
480
|
+
const timer = setTimeout(() => done(void 0), Math.max(0, timeoutMs));
|
|
481
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
482
|
+
stdin.on("data", onData);
|
|
483
|
+
stdin.once("end", onEnd);
|
|
484
|
+
stdin.resume();
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
var ROLES = /* @__PURE__ */ new Set(["viewer", "controller"]);
|
|
488
|
+
var ROLE_LINE = {
|
|
489
|
+
viewer: "Role: VIEWER (watch only: reads sessions and events, cannot start, control or approve)",
|
|
490
|
+
controller: "Role: CONTROLLER (full control: starts sessions, sends input, stops them and answers approvals). Share this link only with someone you would let run commands on this machine."
|
|
491
|
+
};
|
|
492
|
+
var pairCommand = {
|
|
493
|
+
spec: {
|
|
494
|
+
name: "pair",
|
|
495
|
+
summary: "Create a single-use pairing link (watch-only unless --role controller) and wait until a peer pairs.",
|
|
496
|
+
usage: "pair [flags]",
|
|
497
|
+
flags: {
|
|
498
|
+
role: {
|
|
499
|
+
type: "string",
|
|
500
|
+
value: "<viewer|controller>",
|
|
501
|
+
description: "Role of the new peer (default viewer; controller may start sessions and answer approvals)"
|
|
502
|
+
},
|
|
503
|
+
ttl: { type: "string", value: "<duration>", description: "How long the link works: 30s to 60m (default 10m)" },
|
|
504
|
+
relay: {
|
|
505
|
+
type: "string",
|
|
506
|
+
value: "<url>",
|
|
507
|
+
description: "Offer this relay (default: the daemon's registered relay)"
|
|
508
|
+
},
|
|
509
|
+
direct: { type: "string", value: "<url>", description: "Offer this direct URL (default: the daemon's own)" },
|
|
510
|
+
console: { type: "string", value: "<url>", description: "Console to open the link with: <url>/pair#..." },
|
|
511
|
+
confirm: {
|
|
512
|
+
type: "boolean",
|
|
513
|
+
description: "Compare both full fingerprints (groups of 4) and answer y/N before the peer is stored"
|
|
514
|
+
},
|
|
515
|
+
name: { type: "string", value: "<name>", description: "Daemon name shown in the link (n)" },
|
|
516
|
+
"no-wait": { type: "boolean", description: "Print the link and exit (no confirmation, no 'Paired with')" }
|
|
517
|
+
},
|
|
518
|
+
details: "Every target is probed for up to 3 s and only reachable ones go in the link. With --confirm the operator has\n120 s (or until the link expires) to answer; a refusal or timeout closes with daemon.pair_not_confirmed.\nWith --json: one JSON line per step ({type: offer | pending | paired}). Treat the link like a password."
|
|
519
|
+
},
|
|
520
|
+
async run(ctx) {
|
|
521
|
+
const { io, out } = ctx;
|
|
522
|
+
const roleFlag = str(ctx, "role");
|
|
523
|
+
if (roleFlag !== void 0 && !ROLES.has(roleFlag)) throw usage2("--role must be viewer or controller.");
|
|
524
|
+
const role = roleFlag ?? "viewer";
|
|
525
|
+
const ttl = str(ctx, "ttl");
|
|
526
|
+
const ttlMs = ttl === void 0 ? void 0 : parseDuration(ttl, "ttl");
|
|
527
|
+
if (ttlMs !== void 0 && (ttlMs < MIN_PAIR_TTL_MS || ttlMs > MAX_PAIR_TTL_MS)) {
|
|
528
|
+
throw usage2("--ttl must be 30s to 60m.");
|
|
529
|
+
}
|
|
530
|
+
const consoleUrl = str(ctx, "console");
|
|
531
|
+
if (consoleUrl !== void 0 && !/^https?:\/\/[^\s#]+$/.test(consoleUrl)) {
|
|
532
|
+
throw usage2("--console must be an http(s) URL.");
|
|
533
|
+
}
|
|
534
|
+
const confirm = ctx.flags.confirm === true;
|
|
535
|
+
const wait = ctx.flags["no-wait"] !== true;
|
|
536
|
+
if (confirm && !wait) throw usage2("--confirm needs to wait; drop --no-wait.");
|
|
537
|
+
const relay = str(ctx, "relay");
|
|
538
|
+
const direct = str(ctx, "direct");
|
|
539
|
+
const name = str(ctx, "name");
|
|
540
|
+
const fields = {
|
|
541
|
+
role,
|
|
542
|
+
...ttlMs !== void 0 ? { ttl_ms: ttlMs } : {},
|
|
543
|
+
...relay ? { relay_url: relay } : {},
|
|
544
|
+
...direct ? { direct_url: direct } : {},
|
|
545
|
+
...name !== void 0 ? { name } : {},
|
|
546
|
+
...wait ? { watch: true } : {},
|
|
547
|
+
...confirm ? { confirm: true } : {}
|
|
548
|
+
};
|
|
549
|
+
const daemon = await LocalDaemon.open(ctx.paths);
|
|
550
|
+
const queue = [];
|
|
551
|
+
let waiter;
|
|
552
|
+
const emit = (next2) => {
|
|
553
|
+
const w = waiter;
|
|
554
|
+
waiter = void 0;
|
|
555
|
+
if (w) w(next2);
|
|
556
|
+
else queue.push(next2);
|
|
557
|
+
};
|
|
558
|
+
const next = () => queue.length > 0 ? Promise.resolve(queue.shift()) : new Promise((resolve) => waiter = resolve);
|
|
559
|
+
daemon.onPush((push) => {
|
|
560
|
+
if (push.type === "pair.pending" || push.type === "pair.paired") emit(push);
|
|
561
|
+
});
|
|
562
|
+
void daemon.closed.then(() => emit({ type: "closed" }));
|
|
563
|
+
const offInterrupt = io.onInterrupt(() => emit({ type: "interrupted" }));
|
|
564
|
+
let expiry;
|
|
565
|
+
try {
|
|
566
|
+
const offer = await daemon.request("pair.offer", fields).catch((error) => {
|
|
567
|
+
if (error instanceof RequestError && error.code === "daemon.forbidden") {
|
|
568
|
+
throw new CliError(
|
|
569
|
+
"This daemon refuses pair.offer on the local socket (--no-local-pairing). Restart it without that flag to pair.",
|
|
570
|
+
EXIT.error,
|
|
571
|
+
error.code
|
|
572
|
+
);
|
|
573
|
+
}
|
|
574
|
+
if (error instanceof RequestError)
|
|
575
|
+
throw new CliError(error.message, EXIT.error, error.code, error.error.details);
|
|
576
|
+
throw error;
|
|
577
|
+
});
|
|
578
|
+
const link = consoleUrl ? rebaseLink(offer.link, consoleUrl) : offer.link;
|
|
579
|
+
const shownRole = role;
|
|
580
|
+
if (out.json) {
|
|
581
|
+
out.data({ type: "offer", offer_id: offer.offer_id, link, expires_at: offer.expires_at, role: shownRole });
|
|
582
|
+
} else {
|
|
583
|
+
io.stderr.write(`${ROLE_LINE[role]}
|
|
584
|
+
`);
|
|
585
|
+
io.stdout.write(`${link}
|
|
586
|
+
`);
|
|
587
|
+
io.stderr.write(`Single use, ${shownRole}, expires ${when(offer.expires_at)}. Treat it like a password.
|
|
588
|
+
`);
|
|
589
|
+
}
|
|
590
|
+
if (!wait) return EXIT.ok;
|
|
591
|
+
const expires = when(offer.expires_at);
|
|
592
|
+
const afterStop = confirm ? `Nobody is left to confirm, so the daemon refuses everyone who opens this link until it expires (${expires}). Run pair again for a new link.` : `The link stays valid until ${expires}: a ${shownRole} can still pair with it (see peers ls).`;
|
|
593
|
+
out.note(
|
|
594
|
+
confirm ? `Waiting for a ${shownRole} to pair... (Ctrl-C stops waiting and refuses this link: nobody is left to confirm)` : `Waiting for a ${shownRole} to pair... (Ctrl-C stops waiting; the link stays valid until it expires)`
|
|
595
|
+
);
|
|
596
|
+
expiry = setTimeout(() => emit({ type: "expired" }), Math.max(0, Date.parse(offer.expires_at) - Date.now()));
|
|
597
|
+
let carried;
|
|
598
|
+
for (; ; ) {
|
|
599
|
+
const event = carried ?? await next();
|
|
600
|
+
carried = void 0;
|
|
601
|
+
switch (event.type) {
|
|
602
|
+
case "expired":
|
|
603
|
+
throw new CliError(
|
|
604
|
+
`The link expired before a ${shownRole} paired.`,
|
|
605
|
+
EXIT.error,
|
|
606
|
+
"daemon.pair_offer_invalid"
|
|
607
|
+
);
|
|
608
|
+
case "interrupted":
|
|
609
|
+
out.note(`Stopped waiting. ${afterStop}`);
|
|
610
|
+
return EXIT.interrupted;
|
|
611
|
+
case "closed":
|
|
612
|
+
throw new CliError("The daemon closed the connection.", EXIT.error, "daemon.shutting_down");
|
|
613
|
+
case "pair.paired": {
|
|
614
|
+
if (event.offer_id !== offer.offer_id) continue;
|
|
615
|
+
const peerName = event.peer.name ?? event.peer.peer_id;
|
|
616
|
+
out.result(
|
|
617
|
+
{ type: "paired", offer_id: offer.offer_id, peer: event.peer },
|
|
618
|
+
`Paired with ${peerName} (${event.peer.role})`
|
|
619
|
+
);
|
|
620
|
+
return EXIT.ok;
|
|
621
|
+
}
|
|
622
|
+
case "pair.pending": {
|
|
623
|
+
if (event.offer_id !== offer.offer_id) continue;
|
|
624
|
+
const prompt = new AbortController();
|
|
625
|
+
const answered = askOperator(ctx, event, prompt.signal).then((confirmed2) => ({ confirmed: confirmed2 }));
|
|
626
|
+
const interrupting = next().then((other) => ({ other }));
|
|
627
|
+
const first = await Promise.race([answered, interrupting]);
|
|
628
|
+
if ("other" in first) {
|
|
629
|
+
prompt.abort();
|
|
630
|
+
await answered;
|
|
631
|
+
carried = first.other;
|
|
632
|
+
if (first.other.type === "pair.pending" && first.other.offer_id === offer.offer_id) {
|
|
633
|
+
out.note("That viewer left before you answered; a new request came in.");
|
|
634
|
+
}
|
|
635
|
+
continue;
|
|
636
|
+
}
|
|
637
|
+
void interrupting.then(({ other }) => queue.unshift(other));
|
|
638
|
+
const { confirmed } = first;
|
|
639
|
+
try {
|
|
640
|
+
await daemon.request("pair.confirm", { offer_id: event.offer_id, peer_id: event.peer_id, confirmed });
|
|
641
|
+
} catch (error) {
|
|
642
|
+
const why = error instanceof RequestError ? error.message : String(error);
|
|
643
|
+
const code2 = error instanceof RequestError ? error.code : "cli.pair_confirm_failed";
|
|
644
|
+
throw new CliError(
|
|
645
|
+
`Could not ${confirmed ? "confirm" : "refuse"} the pairing: ${why} The viewer may have left or the answer came too late; nothing was stored. ${afterStop}`,
|
|
646
|
+
EXIT.error,
|
|
647
|
+
code2
|
|
648
|
+
);
|
|
649
|
+
}
|
|
650
|
+
if (!confirmed) {
|
|
651
|
+
throw new CliError(
|
|
652
|
+
"Not confirmed: the viewer was refused (daemon.pair_not_confirmed). Run pair again for a new link.",
|
|
653
|
+
EXIT.error,
|
|
654
|
+
"daemon.pair_not_confirmed"
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
} finally {
|
|
661
|
+
if (expiry) clearTimeout(expiry);
|
|
662
|
+
offInterrupt();
|
|
663
|
+
daemon.close();
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
async function askOperator(ctx, push, signal) {
|
|
668
|
+
const { io, out } = ctx;
|
|
669
|
+
const left = Date.parse(push.deadline) - Date.now();
|
|
670
|
+
if (out.json) {
|
|
671
|
+
const { type: _type, ...fields } = push;
|
|
672
|
+
out.data({ type: "pending", ...fields });
|
|
673
|
+
} else {
|
|
674
|
+
io.stderr.write(
|
|
675
|
+
[
|
|
676
|
+
"",
|
|
677
|
+
`Pairing request from ${push.name ?? "an unnamed viewer"} for role ${push.role}.`,
|
|
678
|
+
"Compare every group with what the viewer shows:",
|
|
679
|
+
` peer ${groups(push.peer_id)}`,
|
|
680
|
+
` daemon ${groups(push.daemon_id)}`,
|
|
681
|
+
`All groups match? [y/N] (${Math.max(0, Math.round(left / 1e3))} s) `
|
|
682
|
+
].join("\n")
|
|
683
|
+
);
|
|
684
|
+
}
|
|
685
|
+
const answer = await readLine(io.stdin, left, signal);
|
|
686
|
+
if (answer === void 0 && !signal.aborted) out.note("\nNo answer in time.");
|
|
687
|
+
return /^\s*y(es)?\s*$/i.test(answer ?? "");
|
|
688
|
+
}
|
|
689
|
+
var peersLsCommand = {
|
|
690
|
+
spec: { name: "peers ls", summary: "List paired viewers.", usage: "peers ls [flags]", flags: {} },
|
|
691
|
+
async run(ctx) {
|
|
692
|
+
const { peers } = await withDaemon(ctx.paths, (d) => d.request("peers.list", {}));
|
|
693
|
+
const text = peers.length === 0 ? "No paired peers." : table(
|
|
694
|
+
["PEER", "ROLE", "NAME", "PAIRED", "LAST SEEN"],
|
|
695
|
+
peers.map((p) => [p.peer_id, p.role, p.name ?? "", when(p.paired_at), when(p.last_seen_at)])
|
|
696
|
+
);
|
|
697
|
+
ctx.out.result({ peers }, text);
|
|
698
|
+
return EXIT.ok;
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
var peersRevokeCommand = {
|
|
702
|
+
spec: {
|
|
703
|
+
name: "peers revoke",
|
|
704
|
+
summary: "Remove a peer and close its open channels (idempotent).",
|
|
705
|
+
usage: "peers revoke [flags] <peer_id>",
|
|
706
|
+
flags: {},
|
|
707
|
+
positionals: ["peer_id"]
|
|
708
|
+
},
|
|
709
|
+
async run(ctx) {
|
|
710
|
+
const peerId = ctx.positionals[0];
|
|
711
|
+
if (!/^vpp_[a-z2-7]{26}$/.test(peerId)) throw usage2("peer_id looks like vpp_ plus 26 characters.");
|
|
712
|
+
await withDaemon(ctx.paths, (d) => d.request("peers.revoke", { peer_id: peerId }));
|
|
713
|
+
ctx.out.result({ revoked: peerId }, `Revoked ${peerId}.`);
|
|
714
|
+
return EXIT.ok;
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
|
|
718
|
+
// src/cli/claude-token.ts
|
|
719
|
+
var usage3 = (message) => new CliError(message, EXIT.usage, "cli.usage");
|
|
720
|
+
var claudeTokenCommand = {
|
|
721
|
+
spec: {
|
|
722
|
+
name: "claude-token",
|
|
723
|
+
summary: "Store a Claude Code token (from `claude setup-token`) for sandboxed sessions.",
|
|
724
|
+
usage: "claude-token [flags] (the token is read from stdin)",
|
|
725
|
+
flags: {
|
|
726
|
+
"from-file": {
|
|
727
|
+
type: "string",
|
|
728
|
+
value: "<file>",
|
|
729
|
+
description: "Read the token from this 0600 file instead of stdin"
|
|
730
|
+
},
|
|
731
|
+
clear: { type: "boolean", description: "Remove the stored token" }
|
|
732
|
+
},
|
|
733
|
+
details: "Sandboxed Claude Code runs with its own config dir, so your `claude` login does not carry over. Run\n`claude setup-token`, then pipe or paste the token here. It is stored 0600 in <home>/secrets, which children\ncannot read, and given only to claude-code sessions as CLAUDE_CODE_OAUTH_TOKEN. Never pass it as an argument."
|
|
734
|
+
},
|
|
735
|
+
async run(ctx) {
|
|
736
|
+
const file = claudeTokenPath(ctx.paths.home);
|
|
737
|
+
if (ctx.flags.clear === true) {
|
|
738
|
+
await fs.rm(file, { force: true });
|
|
739
|
+
ctx.out.result({ cleared: file }, `Removed ${file}.`);
|
|
740
|
+
return EXIT.ok;
|
|
741
|
+
}
|
|
742
|
+
const from = ctx.flags["from-file"];
|
|
743
|
+
let token;
|
|
744
|
+
if (from) {
|
|
745
|
+
const stat = await fs.stat(from).catch(() => void 0);
|
|
746
|
+
if (!stat?.isFile()) throw usage3(`--from-file: cannot read ${from}.`);
|
|
747
|
+
if (process.platform !== "win32" && (stat.mode & 63) !== 0) {
|
|
748
|
+
throw usage3(`--from-file: ${from} is readable by other users; run chmod 600 on it.`);
|
|
749
|
+
}
|
|
750
|
+
token = await fs.readFile(from, "utf8");
|
|
751
|
+
} else {
|
|
752
|
+
if (ctx.io.stdin?.isTTY) ctx.out.note("Paste the token from `claude setup-token`, then press Enter:");
|
|
753
|
+
token = await readLine(ctx.io.stdin, 5 * 6e4);
|
|
754
|
+
}
|
|
755
|
+
if (!token?.trim()) throw usage3("No token given: pipe it on stdin or use --from-file.");
|
|
756
|
+
try {
|
|
757
|
+
writeClaudeToken(ctx.paths.home, token);
|
|
758
|
+
} catch (error) {
|
|
759
|
+
throw usage3(error.message);
|
|
760
|
+
}
|
|
761
|
+
ctx.out.result(
|
|
762
|
+
{ stored: file },
|
|
763
|
+
`Stored the Claude Code token in ${file} (0600). New claude-code sessions use it.`
|
|
764
|
+
);
|
|
765
|
+
return EXIT.ok;
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
|
|
769
|
+
// src/cli/daemon.ts
|
|
770
|
+
import { spawn } from "child_process";
|
|
771
|
+
import fs3 from "fs/promises";
|
|
772
|
+
import path2 from "path";
|
|
773
|
+
|
|
774
|
+
// src/runners/command/pty-check.ts
|
|
775
|
+
import os2 from "os";
|
|
776
|
+
async function checkPty(status = nodePtyStatus(), timeoutMs = 5e3) {
|
|
777
|
+
const { pty, problem } = await status;
|
|
778
|
+
if (!pty)
|
|
779
|
+
return {
|
|
780
|
+
ok: problem === NOT_INSTALLED || process.platform === "win32",
|
|
781
|
+
detail: `${problem ?? "node-pty is unavailable"}: terminal sessions use pipes`
|
|
782
|
+
};
|
|
783
|
+
try {
|
|
784
|
+
const handle = pty.spawn("/bin/sh", ["-c", "exit 7"], {
|
|
785
|
+
name: "xterm-256color",
|
|
786
|
+
cols: 80,
|
|
787
|
+
rows: 24,
|
|
788
|
+
cwd: os2.tmpdir(),
|
|
789
|
+
env: { PATH: "/usr/bin:/bin" },
|
|
790
|
+
encoding: null
|
|
791
|
+
});
|
|
792
|
+
handle.onData(() => {
|
|
793
|
+
});
|
|
794
|
+
let timer;
|
|
795
|
+
const exit2 = await Promise.race([
|
|
796
|
+
new Promise((resolve) => handle.onExit(resolve)),
|
|
797
|
+
new Promise((resolve) => {
|
|
798
|
+
timer = setTimeout(() => resolve(void 0), timeoutMs);
|
|
799
|
+
})
|
|
800
|
+
]);
|
|
801
|
+
clearTimeout(timer);
|
|
802
|
+
if (!exit2) {
|
|
803
|
+
try {
|
|
804
|
+
handle.kill("SIGKILL");
|
|
805
|
+
} catch {
|
|
806
|
+
}
|
|
807
|
+
return { ok: false, detail: `node-pty spawned a test shell that did not exit within ${timeoutMs} ms` };
|
|
808
|
+
}
|
|
809
|
+
if (exit2.exitCode !== 7) {
|
|
810
|
+
return {
|
|
811
|
+
ok: false,
|
|
812
|
+
detail: `node-pty test shell ended with ${exit2.signal ? `signal ${exit2.signal}` : `exit ${exit2.exitCode}`}, expected exit 7`
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
return { ok: true, detail: "node-pty spawns terminal sessions (test shell ran)" };
|
|
816
|
+
} catch (error) {
|
|
817
|
+
return { ok: false, detail: `node-pty could not spawn a terminal: ${error.message}` };
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
// src/cli/proc.ts
|
|
822
|
+
import { execFile } from "child_process";
|
|
823
|
+
import fs2 from "fs/promises";
|
|
824
|
+
async function processStartTime(pid) {
|
|
825
|
+
if (!Number.isInteger(pid) || pid <= 0) return void 0;
|
|
826
|
+
if (process.platform === "linux") {
|
|
827
|
+
const stat = await fs2.readFile(`/proc/${pid}/stat`, "utf8").catch(() => void 0);
|
|
828
|
+
if (stat === void 0) return void 0;
|
|
829
|
+
const fields = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
|
|
830
|
+
const start = fields[19];
|
|
831
|
+
return start ? `proc:${start}` : void 0;
|
|
832
|
+
}
|
|
833
|
+
if (process.platform === "win32") return void 0;
|
|
834
|
+
return new Promise((resolve) => {
|
|
835
|
+
execFile(
|
|
836
|
+
"ps",
|
|
837
|
+
["-o", "lstart=", "-p", String(pid)],
|
|
838
|
+
{ env: { ...process.env, LC_ALL: "C", TZ: "UTC" }, timeout: 5e3 },
|
|
839
|
+
(error, stdout) => {
|
|
840
|
+
const text = String(stdout).trim();
|
|
841
|
+
resolve(error || !text ? void 0 : `ps:${text}`);
|
|
842
|
+
}
|
|
843
|
+
);
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
// src/cli/test-runner.ts
|
|
848
|
+
var LEGACY_TEST_RUNNERS_ENV = "VIEWPORT_DAEMON_TEST_RUNNERS";
|
|
849
|
+
var TEST_RUNNER_NAME = "test-script";
|
|
850
|
+
var TEST_RUNNERS_WARNING = "Test runners are on (--test-runners): the test-script runner can fake any tool call or approval, and claude-code is a scripted stand-in. Never use this outside tests.";
|
|
851
|
+
function testRunners(enabled) {
|
|
852
|
+
return enabled ? [scriptRunner(), scriptedClaudeCode()] : [];
|
|
853
|
+
}
|
|
854
|
+
function scriptedClaudeCode() {
|
|
855
|
+
const runner = claudeCodeRunner({ loadQuery: async () => scriptedClaude, checkAuth: true });
|
|
856
|
+
const bare = (context) => ({ ...context, env: {}, sessionEnv: {} });
|
|
857
|
+
return {
|
|
858
|
+
...runner,
|
|
859
|
+
probe: (context) => runner.probe(context && bare(context)),
|
|
860
|
+
preflight: (context) => runner.preflight(bare(context))
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
var scriptedClaude = ({ prompt }) => {
|
|
864
|
+
const messages = [
|
|
865
|
+
{ type: "system", subtype: "init", session_id: "00000000-0000-4000-8000-000000000000", model: "scripted" },
|
|
866
|
+
{
|
|
867
|
+
type: "assistant",
|
|
868
|
+
parent_tool_use_id: null,
|
|
869
|
+
message: { id: "msg_1", content: [{ type: "text", text: `Scripted reply to: ${prompt}` }] }
|
|
870
|
+
},
|
|
871
|
+
{ type: "result", subtype: "success", is_error: false, result: "ok", modelUsage: {} }
|
|
872
|
+
];
|
|
873
|
+
async function* play() {
|
|
874
|
+
yield* messages;
|
|
875
|
+
}
|
|
876
|
+
const generator = play();
|
|
877
|
+
return { [Symbol.asyncIterator]: () => generator, async interrupt() {
|
|
878
|
+
}, close() {
|
|
879
|
+
} };
|
|
880
|
+
};
|
|
881
|
+
function scriptRunner() {
|
|
882
|
+
const probe2 = fakeRunner(TEST_RUNNER_NAME, []);
|
|
883
|
+
return {
|
|
884
|
+
name: TEST_RUNNER_NAME,
|
|
885
|
+
// It takes input and resizes, so it stands in for a terminal session: the CLI forwards raw keys to it.
|
|
886
|
+
probe: async () => {
|
|
887
|
+
const info = await probe2.probe();
|
|
888
|
+
return { ...info, capabilities: { ...info.capabilities, terminal: true } };
|
|
889
|
+
},
|
|
890
|
+
start(spec, io) {
|
|
891
|
+
const { prompt: _script, ...rest } = spec;
|
|
892
|
+
return fakeRunner(TEST_RUNNER_NAME, parseScript(spec.prompt)).start(rest, io);
|
|
893
|
+
}
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
function parseScript(text) {
|
|
897
|
+
let steps;
|
|
898
|
+
try {
|
|
899
|
+
steps = JSON.parse(text ?? "[]");
|
|
900
|
+
} catch {
|
|
901
|
+
throw new DaemonError("daemon.invalid_request", "The test-script prompt must be a JSON array of steps.");
|
|
902
|
+
}
|
|
903
|
+
if (!Array.isArray(steps)) throw new DaemonError("daemon.invalid_request", "The test-script prompt is not an array.");
|
|
904
|
+
return steps.map((step) => {
|
|
905
|
+
if (typeof step.say === "string") return say(step.say);
|
|
906
|
+
if (typeof step.output === "string") return output(step.output, step.stream === "stderr" ? "stderr" : "stdout");
|
|
907
|
+
if (typeof step.tool === "string") {
|
|
908
|
+
return callTool(step.tool, step.args ?? {}, { approval: step.approval === true });
|
|
909
|
+
}
|
|
910
|
+
if (step.wait === true) return waitForInput();
|
|
911
|
+
if (typeof step.exit === "number") return exit(step.exit);
|
|
912
|
+
if (typeof step.fail === "string") return fail(step.fail);
|
|
913
|
+
throw new DaemonError("daemon.invalid_request", `Unknown test-script step ${JSON.stringify(step)}.`);
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
// src/cli/daemon.ts
|
|
918
|
+
var str2 = (ctx, name) => ctx.flags[name];
|
|
919
|
+
var bool = (ctx, name) => ctx.flags[name] === true;
|
|
920
|
+
var usage4 = (message) => new CliError(message, EXIT.usage, "cli.usage");
|
|
921
|
+
var DAEMON_FLAGS = {
|
|
922
|
+
name: { type: "string", value: "<name>", description: "Display name in hello and pair links (default: host name)" },
|
|
923
|
+
direct: {
|
|
924
|
+
type: "string",
|
|
925
|
+
value: "<host:port>",
|
|
926
|
+
description: "Direct channel endpoint (default 127.0.0.1:7070; port 0 picks a free one)"
|
|
927
|
+
},
|
|
928
|
+
"no-direct": { type: "boolean", description: "No direct endpoint (pair through a relay)" },
|
|
929
|
+
relay: { type: "string", value: "<url>", description: "Register on this relay, e.g. wss://relay.example.com" },
|
|
930
|
+
"relay-token-file": {
|
|
931
|
+
type: "string",
|
|
932
|
+
value: "<file>",
|
|
933
|
+
description: "Daemon relay token from this 0600 file (default $VIEWPORT_DAEMON_RELAY_TOKEN)"
|
|
934
|
+
},
|
|
935
|
+
"relay-viewer-token-file": {
|
|
936
|
+
type: "string",
|
|
937
|
+
value: "<file>",
|
|
938
|
+
description: "Viewer relay token put in links as t (default $VIEWPORT_DAEMON_RELAY_VIEWER_TOKEN)"
|
|
939
|
+
},
|
|
940
|
+
"relay-shared-token": { type: "boolean", description: "The relay admits viewers with the daemon token too" },
|
|
941
|
+
"relay-allow-insecure-ws": {
|
|
942
|
+
type: "boolean",
|
|
943
|
+
description: "Allow a plain ws:// relay that is not on loopback (the token travels in cleartext)"
|
|
944
|
+
},
|
|
945
|
+
"local-approvals": { type: "boolean", description: "Let the local token answer approvals (off by default)" },
|
|
946
|
+
"no-local-pairing": {
|
|
947
|
+
type: "boolean",
|
|
948
|
+
description: "Refuse pair.offer on the local socket (this also refuses `viewport-daemon pair`)"
|
|
949
|
+
},
|
|
950
|
+
console: {
|
|
951
|
+
type: "string",
|
|
952
|
+
value: "<url>",
|
|
953
|
+
description: "Console base URL for pair links (default: viewport://pair links, paste them into Console)"
|
|
954
|
+
},
|
|
955
|
+
"allow-origin": {
|
|
956
|
+
type: "string",
|
|
957
|
+
multiple: true,
|
|
958
|
+
value: "<origin>",
|
|
959
|
+
description: "Also let browser pages on this origin open the direct endpoint, e.g. https://console.example.com (repeatable; the --console origin is always allowed)"
|
|
960
|
+
},
|
|
961
|
+
"child-isolation": {
|
|
962
|
+
type: "string",
|
|
963
|
+
value: "<home|none>",
|
|
964
|
+
description: "Child sandbox: home (default; with no sandbox backend runners are unavailable, and an explicit home exits 4) or none"
|
|
965
|
+
},
|
|
966
|
+
"sandbox-deny-read": {
|
|
967
|
+
type: "string",
|
|
968
|
+
multiple: true,
|
|
969
|
+
value: "<path>",
|
|
970
|
+
description: "Also hide this path from agents (repeatable; relay token files are hidden automatically)"
|
|
971
|
+
},
|
|
972
|
+
"sandbox-allow-write": {
|
|
973
|
+
type: "string",
|
|
974
|
+
multiple: true,
|
|
975
|
+
value: "<path>",
|
|
976
|
+
description: "Also let agents write this path, for example a package cache (repeatable)"
|
|
977
|
+
},
|
|
978
|
+
"sandbox-allow-socket": {
|
|
979
|
+
type: "string",
|
|
980
|
+
multiple: true,
|
|
981
|
+
value: "<path>",
|
|
982
|
+
description: "Also let agents connect to this unix socket or socket dir (repeatable; others are refused)"
|
|
983
|
+
},
|
|
984
|
+
"sandbox-network": {
|
|
985
|
+
type: "string",
|
|
986
|
+
value: "<host|none>",
|
|
987
|
+
description: "Child network: host (default) or none (no network for agents; claude-code needs it for its API)"
|
|
988
|
+
},
|
|
989
|
+
"sandbox-allow-cwd": {
|
|
990
|
+
type: "string",
|
|
991
|
+
multiple: true,
|
|
992
|
+
value: "<dir>",
|
|
993
|
+
description: "Also accept session cwds under this dir (home dot-dirs, ~/Library and system dirs are refused)"
|
|
994
|
+
},
|
|
995
|
+
"sandbox-allow-exec": {
|
|
996
|
+
type: "string",
|
|
997
|
+
multiple: true,
|
|
998
|
+
value: "<dir>",
|
|
999
|
+
description: "macOS: also let agents run executables from this directory (repeatable)"
|
|
1000
|
+
},
|
|
1001
|
+
"sandbox-allow-mach": {
|
|
1002
|
+
type: "string",
|
|
1003
|
+
multiple: true,
|
|
1004
|
+
value: "<name>",
|
|
1005
|
+
description: "macOS: also let agents look up this Mach service, an exact name (repeatable)"
|
|
1006
|
+
},
|
|
1007
|
+
"sandbox-deny-credentials": {
|
|
1008
|
+
type: "boolean",
|
|
1009
|
+
description: "Also hide ~/.ssh, cloud CLI configs and other tool credentials from agents"
|
|
1010
|
+
},
|
|
1011
|
+
"env-allow": {
|
|
1012
|
+
type: "string",
|
|
1013
|
+
multiple: true,
|
|
1014
|
+
value: "<name>",
|
|
1015
|
+
description: "Also pass this variable from the daemon's environment to agents (repeatable). By default they get only PATH, HOME, locale, terminal and similar"
|
|
1016
|
+
},
|
|
1017
|
+
"log-level": { type: "string", value: "<level>", description: "debug, info, warn or error (default info)" },
|
|
1018
|
+
"test-runners": {
|
|
1019
|
+
type: "boolean",
|
|
1020
|
+
hidden: true,
|
|
1021
|
+
description: "Register the test-script runner (the CLI's own tests only; it can fake tool calls and approvals)"
|
|
1022
|
+
}
|
|
1023
|
+
};
|
|
1024
|
+
var FORWARDED = Object.keys(DAEMON_FLAGS);
|
|
1025
|
+
var NAME_LISTS = /* @__PURE__ */ new Set(["sandbox-allow-mach", "env-allow", "allow-origin"]);
|
|
1026
|
+
function daemonConfig(ctx) {
|
|
1027
|
+
if (str2(ctx, "direct") !== void 0 && bool(ctx, "no-direct")) throw usage4("--direct and --no-direct conflict.");
|
|
1028
|
+
const relayUrl = str2(ctx, "relay");
|
|
1029
|
+
if (relayUrl !== void 0 && !/^wss?:\/\/[^\s#]+$/.test(relayUrl))
|
|
1030
|
+
throw usage4("--relay must be a ws:// or wss:// URL.");
|
|
1031
|
+
for (const f of ["relay-token-file", "relay-viewer-token-file", "relay-shared-token", "relay-allow-insecure-ws"]) {
|
|
1032
|
+
if (ctx.flags[f] !== void 0 && relayUrl === void 0) throw usage4(`--${f} needs --relay.`);
|
|
1033
|
+
}
|
|
1034
|
+
const allowInsecureWs = bool(ctx, "relay-allow-insecure-ws");
|
|
1035
|
+
if (relayUrl !== void 0) {
|
|
1036
|
+
try {
|
|
1037
|
+
checkRelayTransport(relayUrl, { allowInsecure: allowInsecureWs });
|
|
1038
|
+
} catch (error) {
|
|
1039
|
+
throw usage4(`--relay: ${error.message}`);
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
if (!relayUrl && bool(ctx, "no-direct")) throw usage4("--no-direct needs --relay: the daemon would be unreachable.");
|
|
1043
|
+
const consoleUrl = str2(ctx, "console");
|
|
1044
|
+
if (consoleUrl !== void 0 && !/^https?:\/\/[^\s#]+$/.test(consoleUrl))
|
|
1045
|
+
throw usage4("--console must be an http(s) URL.");
|
|
1046
|
+
const allowedOrigins = ctx.flags["allow-origin"] ?? [];
|
|
1047
|
+
for (const origin of allowedOrigins) {
|
|
1048
|
+
if (!/^https?:\/\/[^\s/?#]+\/?$/.test(origin)) {
|
|
1049
|
+
throw usage4(
|
|
1050
|
+
`--allow-origin takes an http(s) origin such as https://console.example.com, not ${JSON.stringify(origin)}.`
|
|
1051
|
+
);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
const isolation = str2(ctx, "child-isolation");
|
|
1055
|
+
const network = str2(ctx, "sandbox-network");
|
|
1056
|
+
if (network !== void 0 && network !== "host" && network !== "none") {
|
|
1057
|
+
throw usage4("--sandbox-network must be host or none.");
|
|
1058
|
+
}
|
|
1059
|
+
if (isolation !== void 0 && isolation !== "home" && isolation !== "none") {
|
|
1060
|
+
throw usage4("--child-isolation must be home or none.");
|
|
1061
|
+
}
|
|
1062
|
+
const envAllow = ctx.flags["env-allow"] ?? [];
|
|
1063
|
+
for (const name2 of envAllow) {
|
|
1064
|
+
if (!ENV_NAME.test(name2)) throw usage4(`--env-allow takes a variable name, not ${JSON.stringify(name2)}.`);
|
|
1065
|
+
if (/^(LD_|DYLD_)/.test(name2)) throw usage4(`--env-allow ${name2}: LD_* and DYLD_* never reach a child.`);
|
|
1066
|
+
if (/^VIEWPORT_/i.test(name2)) throw usage4(`--env-allow ${name2}: VIEWPORT_* variables never reach a child.`);
|
|
1067
|
+
}
|
|
1068
|
+
const level = str2(ctx, "log-level") ?? "info";
|
|
1069
|
+
if (!["debug", "info", "warn", "error"].includes(level))
|
|
1070
|
+
throw usage4("--log-level must be debug, info, warn or error.");
|
|
1071
|
+
const direct = str2(ctx, "direct");
|
|
1072
|
+
const tokenFile = str2(ctx, "relay-token-file");
|
|
1073
|
+
const viewerTokenFile = str2(ctx, "relay-viewer-token-file");
|
|
1074
|
+
const name = str2(ctx, "name");
|
|
1075
|
+
return {
|
|
1076
|
+
...name !== void 0 ? { name } : {},
|
|
1077
|
+
direct: bool(ctx, "no-direct") ? false : direct ? parseHostPort(direct, "direct") : { host: "127.0.0.1", port: 7070 },
|
|
1078
|
+
...relayUrl ? {
|
|
1079
|
+
relay: {
|
|
1080
|
+
url: relayUrl,
|
|
1081
|
+
...tokenFile ? { tokenFile } : {},
|
|
1082
|
+
...viewerTokenFile ? { viewerTokenFile } : {},
|
|
1083
|
+
shared: bool(ctx, "relay-shared-token"),
|
|
1084
|
+
...allowInsecureWs ? { allowInsecureWs: true } : {}
|
|
1085
|
+
}
|
|
1086
|
+
} : {},
|
|
1087
|
+
localApprovals: bool(ctx, "local-approvals"),
|
|
1088
|
+
localPairing: !bool(ctx, "no-local-pairing"),
|
|
1089
|
+
...consoleUrl ? { consoleUrl } : {},
|
|
1090
|
+
allowedOrigins: [...new Set(allowedOrigins.map((o) => o.replace(/\/$/, "")))],
|
|
1091
|
+
...isolation ? { childIsolation: isolation } : {},
|
|
1092
|
+
sandbox: {
|
|
1093
|
+
denyRead: [
|
|
1094
|
+
...ctx.flags["sandbox-deny-read"] ?? [],
|
|
1095
|
+
...[tokenFile, viewerTokenFile].filter((f) => f !== void 0)
|
|
1096
|
+
].map((p) => path2.resolve(ctx.io.cwd, p)),
|
|
1097
|
+
allowWrite: (ctx.flags["sandbox-allow-write"] ?? []).map(
|
|
1098
|
+
(p) => path2.resolve(ctx.io.cwd, p)
|
|
1099
|
+
),
|
|
1100
|
+
allowUnixSockets: (ctx.flags["sandbox-allow-socket"] ?? []).map(
|
|
1101
|
+
(p) => path2.resolve(ctx.io.cwd, p)
|
|
1102
|
+
),
|
|
1103
|
+
allowExec: (ctx.flags["sandbox-allow-exec"] ?? []).map(
|
|
1104
|
+
(p) => path2.resolve(ctx.io.cwd, p)
|
|
1105
|
+
),
|
|
1106
|
+
allowCwd: (ctx.flags["sandbox-allow-cwd"] ?? []).map(
|
|
1107
|
+
(p) => path2.resolve(ctx.io.cwd, p)
|
|
1108
|
+
),
|
|
1109
|
+
allowMachServices: ctx.flags["sandbox-allow-mach"] ?? [],
|
|
1110
|
+
...network ? { network } : {},
|
|
1111
|
+
denyCredentials: bool(ctx, "sandbox-deny-credentials"),
|
|
1112
|
+
denyListen: [consoleUrl === void 0 ? void 0 : consolePort(consoleUrl)].filter(
|
|
1113
|
+
(p) => p !== void 0
|
|
1114
|
+
)
|
|
1115
|
+
},
|
|
1116
|
+
logLevel: level,
|
|
1117
|
+
env: { inherit: "minimal", allow: [...new Set(envAllow)] }
|
|
1118
|
+
};
|
|
1119
|
+
}
|
|
1120
|
+
async function readSecretFile(file, flag) {
|
|
1121
|
+
let stat;
|
|
1122
|
+
try {
|
|
1123
|
+
stat = await fs3.stat(file);
|
|
1124
|
+
} catch {
|
|
1125
|
+
throw new CliError(`--${flag}: cannot read ${file}.`);
|
|
1126
|
+
}
|
|
1127
|
+
if (!stat.isFile()) throw new CliError(`--${flag}: ${file} is not a regular file.`);
|
|
1128
|
+
if (process.platform !== "win32" && (stat.mode & 63) !== 0) {
|
|
1129
|
+
throw new CliError(`--${flag}: ${file} is readable by other users; run chmod 600 on it.`);
|
|
1130
|
+
}
|
|
1131
|
+
const value = (await fs3.readFile(file, "utf8")).trim();
|
|
1132
|
+
if (!value) throw new CliError(`--${flag}: ${file} is empty.`);
|
|
1133
|
+
return value;
|
|
1134
|
+
}
|
|
1135
|
+
var LEVELS = { debug: 10, info: 20, warn: 30, error: 40 };
|
|
1136
|
+
function lineLogger(io, level) {
|
|
1137
|
+
const write = (at) => (msg, fields) => {
|
|
1138
|
+
if (LEVELS[at] < LEVELS[level]) return;
|
|
1139
|
+
io.stderr.write(`${JSON.stringify({ at: (/* @__PURE__ */ new Date()).toISOString(), level: at, msg, ...fields })}
|
|
1140
|
+
`);
|
|
1141
|
+
};
|
|
1142
|
+
return { debug: write("debug"), info: write("info"), warn: write("warn"), error: write("error") };
|
|
1143
|
+
}
|
|
1144
|
+
var WEAK_SWEEP_WARNING = "Stop's kernel-attributed sweep is unavailable (no Command Line Tools python3 with sandbox_check; run xcode-select --install): processes an agent detaches are found by process ancestry only, best effort.";
|
|
1145
|
+
var FATAL_RELAY_CLOSE = /* @__PURE__ */ new Set([4001, 4003, 4010]);
|
|
1146
|
+
function relayStatus(url, state) {
|
|
1147
|
+
return {
|
|
1148
|
+
url,
|
|
1149
|
+
status: state.status,
|
|
1150
|
+
..."hub" in state ? { hub: state.hub } : {},
|
|
1151
|
+
..."error" in state ? { error: { code: state.error.code, message: state.error.message } } : {}
|
|
1152
|
+
};
|
|
1153
|
+
}
|
|
1154
|
+
async function relayLoop(server, relay, tokens, logger, report2, signal) {
|
|
1155
|
+
let delay = 1e3;
|
|
1156
|
+
while (!signal.aborted) {
|
|
1157
|
+
try {
|
|
1158
|
+
const link = await connectRelay(server, {
|
|
1159
|
+
url: relay.url,
|
|
1160
|
+
...tokens.token ? { token: tokens.token } : {},
|
|
1161
|
+
...tokens.viewerToken ? { viewerToken: tokens.viewerToken } : {},
|
|
1162
|
+
sharedToken: relay.shared,
|
|
1163
|
+
...relay.allowInsecureWs ? { allowInsecureWs: true } : {},
|
|
1164
|
+
logger,
|
|
1165
|
+
onState: (state) => report2(relayStatus(relay.url, state))
|
|
1166
|
+
});
|
|
1167
|
+
if (signal.aborted) {
|
|
1168
|
+
await link.close();
|
|
1169
|
+
return void 0;
|
|
1170
|
+
}
|
|
1171
|
+
return link;
|
|
1172
|
+
} catch (error) {
|
|
1173
|
+
const shape = isDaemonError(error) ? error.toJSON() : { code: "channel.rejected", message: String(error) };
|
|
1174
|
+
const close = isDaemonError(error) ? error.details?.close_code : void 0;
|
|
1175
|
+
if (close !== void 0 && FATAL_RELAY_CLOSE.has(close)) {
|
|
1176
|
+
report2({ url: relay.url, status: "failed", error: shape });
|
|
1177
|
+
logger.error("relay refused this daemon; not retrying", { code: shape.code });
|
|
1178
|
+
return void 0;
|
|
1179
|
+
}
|
|
1180
|
+
report2({ url: relay.url, status: "waiting", error: shape });
|
|
1181
|
+
await new Promise((resolve) => {
|
|
1182
|
+
const timer = setTimeout(resolve, delay);
|
|
1183
|
+
signal.addEventListener(
|
|
1184
|
+
"abort",
|
|
1185
|
+
() => {
|
|
1186
|
+
clearTimeout(timer);
|
|
1187
|
+
resolve();
|
|
1188
|
+
},
|
|
1189
|
+
{ once: true }
|
|
1190
|
+
);
|
|
1191
|
+
});
|
|
1192
|
+
delay = Math.min(delay * 2, 3e4);
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
return void 0;
|
|
1196
|
+
}
|
|
1197
|
+
function startError(error, paths) {
|
|
1198
|
+
if (error instanceof CliError) return error;
|
|
1199
|
+
if (isDaemonError(error, "daemon.runner_unavailable")) {
|
|
1200
|
+
return new CliError(
|
|
1201
|
+
`Child isolation is not available: ${error.message}. Run without --child-isolation home, or see docs/security.mdx.`,
|
|
1202
|
+
EXIT.isolationUnavailable,
|
|
1203
|
+
error.code
|
|
1204
|
+
);
|
|
1205
|
+
}
|
|
1206
|
+
if (isDaemonError(error, "daemon.store_locked")) {
|
|
1207
|
+
return new CliError(
|
|
1208
|
+
`${error.message} If no daemon is running for ${paths.home}, check \`viewport-daemon doctor\` and remove ${paths.lock} yourself.`,
|
|
1209
|
+
EXIT.error,
|
|
1210
|
+
error.code
|
|
1211
|
+
);
|
|
1212
|
+
}
|
|
1213
|
+
if (isDaemonError(error)) return new CliError(error.message, EXIT.error, error.code);
|
|
1214
|
+
const code2 = error.code;
|
|
1215
|
+
if (code2 === "EADDRINUSE")
|
|
1216
|
+
return new CliError(`The direct endpoint's port is in use (${String(error)}).`, EXIT.error, "cli.address_in_use");
|
|
1217
|
+
return new CliError(String(error.message ?? error));
|
|
1218
|
+
}
|
|
1219
|
+
var serveCommand = {
|
|
1220
|
+
spec: {
|
|
1221
|
+
name: "serve",
|
|
1222
|
+
summary: "Run the daemon in the foreground until Ctrl-C or SIGTERM.",
|
|
1223
|
+
usage: "serve [flags]",
|
|
1224
|
+
flags: DAEMON_FLAGS,
|
|
1225
|
+
details: "Local API on <home>/daemon.sock (token in <home>/token, 0600). Writes <home>/daemon.pid and <home>/daemon.json\nwhile it runs. Logs JSON lines to stderr. Relay tokens come from the environment or a file, never a flag value."
|
|
1226
|
+
},
|
|
1227
|
+
async run(ctx) {
|
|
1228
|
+
const { io, out, paths } = ctx;
|
|
1229
|
+
const config = daemonConfig(ctx);
|
|
1230
|
+
assertSocketPathFits(paths);
|
|
1231
|
+
await ensurePrivateDir(paths.home);
|
|
1232
|
+
const envTokens = takeEnvSecrets(io.env);
|
|
1233
|
+
const tokens = {
|
|
1234
|
+
...config.relay?.tokenFile ? { token: await readSecretFile(config.relay.tokenFile, "relay-token-file") } : envTokens.VIEWPORT_DAEMON_RELAY_TOKEN ? { token: envTokens.VIEWPORT_DAEMON_RELAY_TOKEN } : {},
|
|
1235
|
+
...config.relay?.viewerTokenFile ? { viewerToken: await readSecretFile(config.relay.viewerTokenFile, "relay-viewer-token-file") } : envTokens.VIEWPORT_DAEMON_RELAY_VIEWER_TOKEN ? { viewerToken: envTokens.VIEWPORT_DAEMON_RELAY_VIEWER_TOKEN } : {}
|
|
1236
|
+
};
|
|
1237
|
+
const logger = lineLogger(io, config.logLevel);
|
|
1238
|
+
const withTestRunners = bool(ctx, "test-runners");
|
|
1239
|
+
if (withTestRunners) {
|
|
1240
|
+
logger.warn(TEST_RUNNERS_WARNING);
|
|
1241
|
+
if (!out.json) io.stderr.write(`WARNING: ${TEST_RUNNERS_WARNING}
|
|
1242
|
+
`);
|
|
1243
|
+
}
|
|
1244
|
+
const processStart = await processStartTime(process.pid) ?? null;
|
|
1245
|
+
const supervisor = createSupervisor({
|
|
1246
|
+
home: paths.home,
|
|
1247
|
+
logger,
|
|
1248
|
+
runners: testRunners(withTestRunners),
|
|
1249
|
+
sandbox: config.sandbox,
|
|
1250
|
+
env: config.env
|
|
1251
|
+
});
|
|
1252
|
+
let server;
|
|
1253
|
+
try {
|
|
1254
|
+
await supervisor.list({ limit: 1 });
|
|
1255
|
+
server = await serve(supervisor, {
|
|
1256
|
+
home: paths.home,
|
|
1257
|
+
direct: config.direct,
|
|
1258
|
+
localApprovals: config.localApprovals,
|
|
1259
|
+
localPairing: config.localPairing,
|
|
1260
|
+
logger,
|
|
1261
|
+
...config.name !== void 0 ? { name: config.name } : {},
|
|
1262
|
+
...config.consoleUrl ? { consoleUrl: config.consoleUrl } : {},
|
|
1263
|
+
...config.allowedOrigins.length > 0 ? { allowedOrigins: config.allowedOrigins } : {},
|
|
1264
|
+
...config.childIsolation ? { childIsolation: config.childIsolation } : {}
|
|
1265
|
+
});
|
|
1266
|
+
} catch (error) {
|
|
1267
|
+
await supervisor.close().catch(() => {
|
|
1268
|
+
});
|
|
1269
|
+
throw startError(error, paths);
|
|
1270
|
+
}
|
|
1271
|
+
const state = {
|
|
1272
|
+
pid: process.pid,
|
|
1273
|
+
started_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1274
|
+
version: DAEMON_VERSION,
|
|
1275
|
+
daemon_id: server.daemon.id,
|
|
1276
|
+
name: server.daemon.name,
|
|
1277
|
+
socket: paths.socket,
|
|
1278
|
+
direct_url: server.directUrl ?? null,
|
|
1279
|
+
relay: config.relay ? { url: config.relay.url, status: "connecting" } : null,
|
|
1280
|
+
local_approvals: config.localApprovals,
|
|
1281
|
+
local_pairing: config.localPairing,
|
|
1282
|
+
test_runners: withTestRunners,
|
|
1283
|
+
log: paths.log,
|
|
1284
|
+
process_start: processStart,
|
|
1285
|
+
stop_sweep: supervisor.sandbox.stopSweep
|
|
1286
|
+
};
|
|
1287
|
+
if (state.stop_sweep === "process-tree" && config.childIsolation !== "none") logger.warn(WEAK_SWEEP_WARNING);
|
|
1288
|
+
else logger.info("stop sweep", { stop_sweep: state.stop_sweep });
|
|
1289
|
+
let writes = Promise.resolve();
|
|
1290
|
+
const saveState = () => {
|
|
1291
|
+
writes = writes.then(() => writeAtomicJson(paths.state, state)).catch((error) => logger.warn("cannot write daemon.json", { error: String(error) }));
|
|
1292
|
+
return writes;
|
|
1293
|
+
};
|
|
1294
|
+
await writeAtomic(paths.pid, `${process.pid}
|
|
1295
|
+
`);
|
|
1296
|
+
await saveState();
|
|
1297
|
+
const stop = new AbortController();
|
|
1298
|
+
const off = io.onInterrupt(() => stop.abort(), { terminate: true });
|
|
1299
|
+
const relay = config.relay ? relayLoop(
|
|
1300
|
+
server,
|
|
1301
|
+
config.relay,
|
|
1302
|
+
tokens,
|
|
1303
|
+
logger,
|
|
1304
|
+
(status) => {
|
|
1305
|
+
state.relay = status;
|
|
1306
|
+
void saveState();
|
|
1307
|
+
},
|
|
1308
|
+
stop.signal
|
|
1309
|
+
) : Promise.resolve(void 0);
|
|
1310
|
+
logger.info("daemon ready", { daemon_id: state.daemon_id, socket: paths.socket, direct_url: state.direct_url });
|
|
1311
|
+
if (out.json) out.data({ type: "ready", ...state });
|
|
1312
|
+
else io.stderr.write(`viewport-daemon ${state.daemon_id} serving ${paths.socket} (pid ${process.pid})
|
|
1313
|
+
`);
|
|
1314
|
+
await new Promise((resolve) => stop.signal.addEventListener("abort", () => resolve(), { once: true }));
|
|
1315
|
+
off();
|
|
1316
|
+
logger.info("shutting down");
|
|
1317
|
+
await (await relay)?.close().catch(() => {
|
|
1318
|
+
});
|
|
1319
|
+
await server.close();
|
|
1320
|
+
await supervisor.close();
|
|
1321
|
+
await writes;
|
|
1322
|
+
const pid = (await fs3.readFile(paths.pid, "utf8").catch(() => "")).trim();
|
|
1323
|
+
if (pid === String(process.pid))
|
|
1324
|
+
await Promise.all([fs3.rm(paths.pid, { force: true }), fs3.rm(paths.state, { force: true })]);
|
|
1325
|
+
if (out.json) out.data({ type: "stopped", pid: process.pid });
|
|
1326
|
+
return EXIT.ok;
|
|
1327
|
+
}
|
|
1328
|
+
};
|
|
1329
|
+
async function probe(paths) {
|
|
1330
|
+
try {
|
|
1331
|
+
return await LocalDaemon.open(paths, { timeoutMs: 2e3 });
|
|
1332
|
+
} catch (error) {
|
|
1333
|
+
if (error instanceof CliError && error.exitCode === EXIT.notRunning) return void 0;
|
|
1334
|
+
throw error;
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
async function tail(file, lines = 20) {
|
|
1338
|
+
const text = await fs3.readFile(file, "utf8").catch(() => "");
|
|
1339
|
+
return text.trimEnd().split("\n").slice(-lines).join("\n");
|
|
1340
|
+
}
|
|
1341
|
+
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
1342
|
+
var upCommand = {
|
|
1343
|
+
spec: {
|
|
1344
|
+
name: "up",
|
|
1345
|
+
summary: "Start the daemon in the background (a detached `serve`), then wait until it answers.",
|
|
1346
|
+
usage: "up [flags]",
|
|
1347
|
+
flags: {
|
|
1348
|
+
...DAEMON_FLAGS,
|
|
1349
|
+
timeout: { type: "string", value: "<seconds>", description: "How long to wait for it to answer (default 20)" }
|
|
1350
|
+
},
|
|
1351
|
+
details: "Output goes to <home>/daemon.log (0600). Already running: prints its status and exits 0."
|
|
1352
|
+
},
|
|
1353
|
+
async run(ctx) {
|
|
1354
|
+
const { io, out, paths } = ctx;
|
|
1355
|
+
daemonConfig(ctx);
|
|
1356
|
+
assertSocketPathFits(paths);
|
|
1357
|
+
const timeoutS = Number(str2(ctx, "timeout") ?? "20");
|
|
1358
|
+
if (!Number.isFinite(timeoutS) || timeoutS <= 0) throw usage4("--timeout must be a positive number of seconds.");
|
|
1359
|
+
const running = await probe(paths);
|
|
1360
|
+
if (running) {
|
|
1361
|
+
running.close();
|
|
1362
|
+
out.note(`The daemon is already running (${paths.socket}).`);
|
|
1363
|
+
return statusCommand.run(ctx);
|
|
1364
|
+
}
|
|
1365
|
+
await ensurePrivateDir(paths.home);
|
|
1366
|
+
const log = await fs3.open(paths.log, "a", 384);
|
|
1367
|
+
let child;
|
|
1368
|
+
const launchedAt = Date.now();
|
|
1369
|
+
try {
|
|
1370
|
+
await log.chmod(384);
|
|
1371
|
+
const forwarded = FORWARDED.flatMap((name) => {
|
|
1372
|
+
const value = ctx.flags[name];
|
|
1373
|
+
if (value === void 0) return [];
|
|
1374
|
+
if (value === true) return [`--${name}`];
|
|
1375
|
+
if (Array.isArray(value))
|
|
1376
|
+
return value.flatMap((v) => [`--${name}`, NAME_LISTS.has(name) ? v : path2.resolve(io.cwd, v)]);
|
|
1377
|
+
return [`--${name}`, name.endsWith("-file") ? path2.resolve(io.cwd, value) : value];
|
|
1378
|
+
});
|
|
1379
|
+
const [program, ...lead] = io.entry;
|
|
1380
|
+
child = spawn(program, [...lead, "serve", "--home", paths.home, ...forwarded], {
|
|
1381
|
+
detached: true,
|
|
1382
|
+
stdio: ["ignore", log.fd, log.fd],
|
|
1383
|
+
// Only flags turn on test runners; an inherited variable never reaches the daemon.
|
|
1384
|
+
env: Object.fromEntries(Object.entries(io.env).filter(([key]) => key !== LEGACY_TEST_RUNNERS_ENV)),
|
|
1385
|
+
cwd: paths.home
|
|
1386
|
+
});
|
|
1387
|
+
} finally {
|
|
1388
|
+
await log.close();
|
|
1389
|
+
}
|
|
1390
|
+
let exited;
|
|
1391
|
+
child.once("exit", (code2) => {
|
|
1392
|
+
exited = code2 ?? 1;
|
|
1393
|
+
});
|
|
1394
|
+
child.once("error", () => {
|
|
1395
|
+
exited = 1;
|
|
1396
|
+
});
|
|
1397
|
+
child.unref();
|
|
1398
|
+
const deadline = Date.now() + timeoutS * 1e3;
|
|
1399
|
+
for (; ; ) {
|
|
1400
|
+
if (exited !== void 0) {
|
|
1401
|
+
const lines = await tail(paths.log);
|
|
1402
|
+
out.note(lines);
|
|
1403
|
+
throw new CliError(
|
|
1404
|
+
`The daemon exited during startup (code ${exited}); see ${paths.log}.`,
|
|
1405
|
+
exited === EXIT.isolationUnavailable ? EXIT.isolationUnavailable : EXIT.error,
|
|
1406
|
+
exited === EXIT.isolationUnavailable ? "daemon.runner_unavailable" : "cli.start_failed",
|
|
1407
|
+
{ log: paths.log, log_tail: lines }
|
|
1408
|
+
);
|
|
1409
|
+
}
|
|
1410
|
+
const daemon = await probe(paths).catch(() => void 0);
|
|
1411
|
+
if (daemon) {
|
|
1412
|
+
daemon.close();
|
|
1413
|
+
const state = await readJson(paths.state).catch(() => void 0);
|
|
1414
|
+
const fresh = typeof state?.started_at === "string" && Date.parse(state.started_at) >= launchedAt;
|
|
1415
|
+
if (fresh && state?.daemon_id !== void 0 && state.daemon_id === daemon.hello?.daemon.id) break;
|
|
1416
|
+
}
|
|
1417
|
+
if (Date.now() > deadline) {
|
|
1418
|
+
if (child.pid !== void 0 && process.platform !== "win32") await terminateGroup(child.pid, 2e3);
|
|
1419
|
+
else if (child.pid !== void 0) sendSignal(child.pid, "SIGTERM");
|
|
1420
|
+
throw new CliError(
|
|
1421
|
+
`The daemon did not answer within ${timeoutS} s and was stopped; see ${paths.log}.`,
|
|
1422
|
+
EXIT.error,
|
|
1423
|
+
"cli.timeout"
|
|
1424
|
+
);
|
|
1425
|
+
}
|
|
1426
|
+
await sleep(100);
|
|
1427
|
+
}
|
|
1428
|
+
out.note(`Started the daemon (pid ${child.pid}); log ${paths.log}.`);
|
|
1429
|
+
return statusCommand.run(ctx);
|
|
1430
|
+
}
|
|
1431
|
+
};
|
|
1432
|
+
var alive = (pid) => {
|
|
1433
|
+
try {
|
|
1434
|
+
sendSignal(pid, 0);
|
|
1435
|
+
return true;
|
|
1436
|
+
} catch (error) {
|
|
1437
|
+
return error.code === "EPERM";
|
|
1438
|
+
}
|
|
1439
|
+
};
|
|
1440
|
+
async function readPid(file) {
|
|
1441
|
+
const text = await fs3.readFile(file, "utf8").catch(() => void 0);
|
|
1442
|
+
const pid = Number(text?.trim());
|
|
1443
|
+
return Number.isInteger(pid) && pid > 0 ? pid : void 0;
|
|
1444
|
+
}
|
|
1445
|
+
async function verifyDaemonPid(paths, pid, daemonId) {
|
|
1446
|
+
const refuse = (why) => new CliError(
|
|
1447
|
+
`Refusing to signal pid ${pid}: ${why}. Stop the daemon where it was started.`,
|
|
1448
|
+
EXIT.error,
|
|
1449
|
+
"cli.pid_mismatch"
|
|
1450
|
+
);
|
|
1451
|
+
const lock = await readJson(paths.lock).catch(() => void 0);
|
|
1452
|
+
if (lock?.pid !== pid) {
|
|
1453
|
+
throw refuse(`${paths.lock} ${lock?.pid === void 0 ? "names no pid" : `says ${lock.pid}`}, not ${pid}`);
|
|
1454
|
+
}
|
|
1455
|
+
const state = await readJson(paths.state).catch(() => void 0);
|
|
1456
|
+
if (state?.pid !== pid) throw refuse(`${paths.state} ${state ? `says pid ${state.pid}` : "is missing"}`);
|
|
1457
|
+
if (daemonId !== void 0 && state.daemon_id !== daemonId) {
|
|
1458
|
+
throw refuse(`${paths.state} belongs to ${state.daemon_id}, but ${daemonId} answers on ${paths.socket}`);
|
|
1459
|
+
}
|
|
1460
|
+
const started = await processStartTime(pid);
|
|
1461
|
+
const recorded = state.process_start ?? void 0;
|
|
1462
|
+
if (started !== recorded) {
|
|
1463
|
+
throw refuse(
|
|
1464
|
+
recorded === void 0 ? `${paths.state} records no process start time` : `its start time (${started ?? "unknown"}) is not the one serve recorded (${recorded}); the pid may have been reused`
|
|
1465
|
+
);
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
var downCommand = {
|
|
1469
|
+
spec: {
|
|
1470
|
+
name: "down",
|
|
1471
|
+
summary: "Stop the background daemon (SIGTERM; running sessions are stopped) and wait for it to exit.",
|
|
1472
|
+
usage: "down [flags]",
|
|
1473
|
+
flags: { timeout: { type: "string", value: "<seconds>", description: "How long to wait (default 15)" } },
|
|
1474
|
+
details: "Not running: exits 0. The pid comes from <home>/daemon.pid and must match the store's writer lock, daemon.json\nand the process start time serve recorded; otherwise down refuses to signal it."
|
|
1475
|
+
},
|
|
1476
|
+
async run(ctx) {
|
|
1477
|
+
const { out, paths } = ctx;
|
|
1478
|
+
const timeoutS = Number(str2(ctx, "timeout") ?? "15");
|
|
1479
|
+
if (!Number.isFinite(timeoutS) || timeoutS <= 0) throw usage4("--timeout must be a positive number of seconds.");
|
|
1480
|
+
const pid = await readPid(paths.pid);
|
|
1481
|
+
const daemon = await probe(paths);
|
|
1482
|
+
daemon?.close();
|
|
1483
|
+
if (!daemon) {
|
|
1484
|
+
out.result({ running: false, stopped: false, home: paths.home }, "The daemon is not running.");
|
|
1485
|
+
return EXIT.ok;
|
|
1486
|
+
}
|
|
1487
|
+
if (pid === void 0) {
|
|
1488
|
+
throw new CliError(
|
|
1489
|
+
`A daemon answers on ${paths.socket} but there is no ${paths.pid}; stop it where it was started.`
|
|
1490
|
+
);
|
|
1491
|
+
}
|
|
1492
|
+
await verifyDaemonPid(paths, pid, daemon.hello?.daemon.id);
|
|
1493
|
+
sendSignal(pid, "SIGTERM");
|
|
1494
|
+
const deadline = Date.now() + timeoutS * 1e3;
|
|
1495
|
+
while (alive(pid)) {
|
|
1496
|
+
if (Date.now() > deadline) {
|
|
1497
|
+
throw new CliError(`The daemon (pid ${pid}) is still running after ${timeoutS} s.`, EXIT.error, "cli.timeout");
|
|
1498
|
+
}
|
|
1499
|
+
await sleep(100);
|
|
1500
|
+
}
|
|
1501
|
+
out.result({ running: false, stopped: true, pid, home: paths.home }, `Stopped the daemon (pid ${pid}).`);
|
|
1502
|
+
return EXIT.ok;
|
|
1503
|
+
}
|
|
1504
|
+
};
|
|
1505
|
+
async function modeCheck(file, want, label) {
|
|
1506
|
+
const stat = await fs3.stat(file).catch(() => void 0);
|
|
1507
|
+
if (!stat) return void 0;
|
|
1508
|
+
const mode = stat.mode & 511;
|
|
1509
|
+
const ok = process.platform === "win32" || (mode & ~want) === 0;
|
|
1510
|
+
return {
|
|
1511
|
+
name: label,
|
|
1512
|
+
ok,
|
|
1513
|
+
detail: `${file} is ${mode.toString(8).padStart(4, "0")}${ok ? "" : `; want ${want.toString(8).padStart(4, "0")}`}`
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
async function doctorChecks(paths, running) {
|
|
1517
|
+
const checks = [];
|
|
1518
|
+
const major = Number(process.versions.node.split(".")[0]);
|
|
1519
|
+
checks.push({
|
|
1520
|
+
name: "node",
|
|
1521
|
+
ok: major >= 22,
|
|
1522
|
+
detail: `Node ${process.versions.node}${major >= 22 ? "" : "; need 22 or later"}`
|
|
1523
|
+
});
|
|
1524
|
+
const tooLong = socketPathTooLong(paths.socket);
|
|
1525
|
+
const limit = socketPathLimit(paths.socket);
|
|
1526
|
+
checks.push({
|
|
1527
|
+
name: "socket",
|
|
1528
|
+
ok: tooLong === void 0,
|
|
1529
|
+
detail: tooLong ? `path too long, use a shorter --home: ${tooLong}` : `${paths.socket}${limit ? ` (${limit.bytes} of ${limit.max} bytes)` : ""}`
|
|
1530
|
+
});
|
|
1531
|
+
const home = await modeCheck(paths.home, 448, "home");
|
|
1532
|
+
checks.push(home ?? { name: "home", ok: true, detail: `${paths.home} does not exist yet` });
|
|
1533
|
+
for (const [file, label] of [
|
|
1534
|
+
[paths.token, "token"],
|
|
1535
|
+
[paths.identity, "identity"],
|
|
1536
|
+
[paths.log, "log"],
|
|
1537
|
+
[paths.state, "state"],
|
|
1538
|
+
[paths.pid, "pid"]
|
|
1539
|
+
]) {
|
|
1540
|
+
const check = await modeCheck(file, 384, label);
|
|
1541
|
+
if (check) checks.push(check);
|
|
1542
|
+
}
|
|
1543
|
+
const lock = await readJson(paths.lock).catch(() => void 0);
|
|
1544
|
+
if (lock && !running) {
|
|
1545
|
+
const holder = lock.pid !== void 0 && alive(lock.pid);
|
|
1546
|
+
checks.push({
|
|
1547
|
+
name: "lock",
|
|
1548
|
+
ok: false,
|
|
1549
|
+
detail: holder ? `${paths.lock} is held by pid ${lock.pid}, which is alive but not answering on the socket` : `${paths.lock} is stale (pid ${lock.pid ?? "?"} is gone); remove it after checking no daemon uses ${paths.home}`
|
|
1550
|
+
});
|
|
1551
|
+
}
|
|
1552
|
+
checks.push({ name: "pty", ...await checkPty() });
|
|
1553
|
+
return checks;
|
|
1554
|
+
}
|
|
1555
|
+
function statusCommandFor(doctor) {
|
|
1556
|
+
return {
|
|
1557
|
+
spec: doctor ? {
|
|
1558
|
+
name: "doctor",
|
|
1559
|
+
summary: "Status plus checks: file modes, a stale writer lock, Node, PTY support.",
|
|
1560
|
+
usage: "doctor [flags]",
|
|
1561
|
+
flags: {}
|
|
1562
|
+
} : {
|
|
1563
|
+
name: "status",
|
|
1564
|
+
summary: "Is the daemon running, and how is it reachable.",
|
|
1565
|
+
usage: "status [flags]",
|
|
1566
|
+
flags: {},
|
|
1567
|
+
details: "Reports daemon_id, name, version, socket, direct and relay endpoints, relay state, child isolation and\nwarnings. Exits 3 when the daemon is not running."
|
|
1568
|
+
},
|
|
1569
|
+
async run(ctx) {
|
|
1570
|
+
const { out, paths } = ctx;
|
|
1571
|
+
const daemon = await probe(paths);
|
|
1572
|
+
const checks = doctor ? await doctorChecks(paths, daemon !== void 0) : void 0;
|
|
1573
|
+
if (!daemon) {
|
|
1574
|
+
out.result(
|
|
1575
|
+
{ running: false, home: paths.home, socket: paths.socket, warnings: [], ...checks ? { checks } : {} },
|
|
1576
|
+
[`Daemon not running`, `Home ${paths.home}`, ...checks ? ["", ...checkLines(checks)] : []].join(
|
|
1577
|
+
"\n"
|
|
1578
|
+
)
|
|
1579
|
+
);
|
|
1580
|
+
return EXIT.notRunning;
|
|
1581
|
+
}
|
|
1582
|
+
const hello = daemon.hello;
|
|
1583
|
+
daemon.close();
|
|
1584
|
+
const state = await readJson(paths.state).catch(() => void 0);
|
|
1585
|
+
const sameDaemon = state?.daemon_id === hello.daemon.id ? state : void 0;
|
|
1586
|
+
const warnings = [];
|
|
1587
|
+
if (hello.child_isolation === "none") warnings.push(NO_ISOLATION_WARNING);
|
|
1588
|
+
else if (sameDaemon?.stop_sweep === "process-tree") warnings.push(WEAK_SWEEP_WARNING);
|
|
1589
|
+
for (const r of hello.runners) if (!r.available && r.reason) warnings.push(`${r.name}: ${r.reason}`);
|
|
1590
|
+
if (sameDaemon?.test_runners || hello.runners.some((r) => r.name === TEST_RUNNER_NAME)) {
|
|
1591
|
+
warnings.push(TEST_RUNNERS_WARNING);
|
|
1592
|
+
}
|
|
1593
|
+
if (sameDaemon?.local_approvals) {
|
|
1594
|
+
warnings.push(
|
|
1595
|
+
`The local token answers approvals (--local-approvals): any process that can read ${paths.token} can approve tool calls.`
|
|
1596
|
+
);
|
|
1597
|
+
}
|
|
1598
|
+
if (sameDaemon?.relay && sameDaemon.relay.status !== "registered") {
|
|
1599
|
+
warnings.push(
|
|
1600
|
+
`The relay ${sameDaemon.relay.url} is ${sameDaemon.relay.status}${sameDaemon.relay.error ? `: ${sameDaemon.relay.error.message}` : ""}.`
|
|
1601
|
+
);
|
|
1602
|
+
}
|
|
1603
|
+
if (!sameDaemon)
|
|
1604
|
+
warnings.push(`No ${paths.state} for this daemon: endpoints are unknown (not started by the CLI?).`);
|
|
1605
|
+
if (checks) for (const c of checks.filter((c2) => !c2.ok)) warnings.push(`${c.name}: ${c.detail}`);
|
|
1606
|
+
const status = {
|
|
1607
|
+
running: true,
|
|
1608
|
+
home: paths.home,
|
|
1609
|
+
socket: paths.socket,
|
|
1610
|
+
pid: sameDaemon?.pid ?? null,
|
|
1611
|
+
daemon_id: hello.daemon.id,
|
|
1612
|
+
name: hello.daemon.name,
|
|
1613
|
+
version: hello.daemon.version,
|
|
1614
|
+
protocol: hello.protocol,
|
|
1615
|
+
child_isolation: hello.child_isolation,
|
|
1616
|
+
stop_sweep: sameDaemon?.stop_sweep ?? null,
|
|
1617
|
+
direct_url: sameDaemon?.direct_url ?? null,
|
|
1618
|
+
relay: sameDaemon?.relay ?? null,
|
|
1619
|
+
local_approvals: sameDaemon?.local_approvals ?? null,
|
|
1620
|
+
local_pairing: sameDaemon?.local_pairing ?? null,
|
|
1621
|
+
started_at: sameDaemon?.started_at ?? null,
|
|
1622
|
+
log: paths.log,
|
|
1623
|
+
runners: hello.runners.map((r) => ({
|
|
1624
|
+
name: r.name,
|
|
1625
|
+
available: r.available,
|
|
1626
|
+
...r.reason ? { reason: r.reason } : {}
|
|
1627
|
+
})),
|
|
1628
|
+
warnings,
|
|
1629
|
+
...checks ? { checks } : {}
|
|
1630
|
+
};
|
|
1631
|
+
const rows = [
|
|
1632
|
+
["Daemon", `running${status.pid ? ` (pid ${status.pid})` : ""}`],
|
|
1633
|
+
["ID", status.daemon_id],
|
|
1634
|
+
["Name", status.name],
|
|
1635
|
+
["Version", status.version],
|
|
1636
|
+
["Home", status.home],
|
|
1637
|
+
["Socket", status.socket],
|
|
1638
|
+
["Direct", status.direct_url ?? "off"],
|
|
1639
|
+
["Relay", status.relay ? `${status.relay.url} (${status.relay.status})` : "off"],
|
|
1640
|
+
["Isolation", status.child_isolation],
|
|
1641
|
+
[
|
|
1642
|
+
"Stop sweep",
|
|
1643
|
+
status.stop_sweep === "process-tree" ? "best effort (process tree only; a fast double fork escapes it)" : status.stop_sweep ?? "unknown"
|
|
1644
|
+
],
|
|
1645
|
+
["Approvals", status.local_approvals ? "paired controllers and the local token" : "paired controllers only"],
|
|
1646
|
+
["Pairing", status.local_pairing === false ? "refused on the local socket" : "pair over the local socket"],
|
|
1647
|
+
[
|
|
1648
|
+
"Runners",
|
|
1649
|
+
status.runners.map(
|
|
1650
|
+
(r) => r.available ? r.name : `${r.name} (unavailable${r.reason ? `: ${shortReason(r.reason)}` : ""})`
|
|
1651
|
+
).join(", ")
|
|
1652
|
+
]
|
|
1653
|
+
];
|
|
1654
|
+
const text = [
|
|
1655
|
+
...rows.map(([k, v]) => `${k.padEnd(10)} ${v}`),
|
|
1656
|
+
...checks ? ["", ...checkLines(checks)] : [],
|
|
1657
|
+
...warnings.map((w) => `
|
|
1658
|
+
Warning: ${w}`)
|
|
1659
|
+
].join("\n");
|
|
1660
|
+
out.result(status, text);
|
|
1661
|
+
return EXIT.ok;
|
|
1662
|
+
}
|
|
1663
|
+
};
|
|
1664
|
+
}
|
|
1665
|
+
function checkLines(checks) {
|
|
1666
|
+
return table(
|
|
1667
|
+
["CHECK", "OK", "DETAIL"],
|
|
1668
|
+
checks.map((c) => [c.name, c.ok ? "ok" : "FAIL", c.detail])
|
|
1669
|
+
).split("\n");
|
|
1670
|
+
}
|
|
1671
|
+
var statusCommand = statusCommandFor(false);
|
|
1672
|
+
var doctorCommand = statusCommandFor(true);
|
|
1673
|
+
|
|
1674
|
+
// src/cli/sessions.ts
|
|
1675
|
+
import { createHash } from "crypto";
|
|
1676
|
+
import os3 from "os";
|
|
1677
|
+
import path3 from "path";
|
|
1678
|
+
var str3 = (ctx, name) => ctx.flags[name];
|
|
1679
|
+
var usage5 = (message) => new CliError(message, EXIT.usage, "cli.usage");
|
|
1680
|
+
var START_FLAGS = {
|
|
1681
|
+
cwd: { type: "string", value: "<dir>", description: "Working directory (default: the current one)" },
|
|
1682
|
+
name: { type: "string", value: "<name>", description: "Session name" },
|
|
1683
|
+
model: { type: "string", value: "<model>", description: "Model, for agent runners" },
|
|
1684
|
+
tenant: { type: "string", value: "<label>", description: "Tenant label (wire 3.3)" },
|
|
1685
|
+
"idempotency-key": { type: "string", value: "<key>", description: "Same key and intent: the same session" },
|
|
1686
|
+
env: { type: "string", multiple: true, value: "<KEY=VALUE>", description: "Extra environment for the session" },
|
|
1687
|
+
terminal: { type: "boolean", description: "Ask for a PTY (default: when stdout is a terminal)" },
|
|
1688
|
+
"no-terminal": { type: "boolean", description: "Pipes, not a PTY" }
|
|
1689
|
+
};
|
|
1690
|
+
function startFields(ctx, runner, prompt) {
|
|
1691
|
+
const { io, rest } = ctx;
|
|
1692
|
+
if (ctx.flags.terminal && ctx.flags["no-terminal"]) throw usage5("--terminal and --no-terminal conflict.");
|
|
1693
|
+
const env = {};
|
|
1694
|
+
for (const pair of ctx.flags.env ?? []) {
|
|
1695
|
+
const eq = pair.indexOf("=");
|
|
1696
|
+
if (eq <= 0) throw usage5(`--env takes KEY=VALUE, not ${JSON.stringify(pair)}.`);
|
|
1697
|
+
env[pair.slice(0, eq)] = pair.slice(eq + 1);
|
|
1698
|
+
}
|
|
1699
|
+
const terminal = ctx.flags.terminal ? true : ctx.flags["no-terminal"] ? false : io.stdout.isTTY === true;
|
|
1700
|
+
let command = {};
|
|
1701
|
+
if (runner === "command") {
|
|
1702
|
+
if (!rest || rest.length === 0) throw usage5("The command runner needs the program after --, e.g. run -- npm test.");
|
|
1703
|
+
if (prompt !== void 0) throw usage5("The command runner takes no prompt; put the program after --.");
|
|
1704
|
+
command = { command: rest[0], args: rest.slice(1) };
|
|
1705
|
+
} else if (rest && rest.length > 0) {
|
|
1706
|
+
command = { args: rest };
|
|
1707
|
+
}
|
|
1708
|
+
const name = str3(ctx, "name");
|
|
1709
|
+
const model = str3(ctx, "model");
|
|
1710
|
+
const tenant = str3(ctx, "tenant");
|
|
1711
|
+
const key = str3(ctx, "idempotency-key");
|
|
1712
|
+
return {
|
|
1713
|
+
runner,
|
|
1714
|
+
cwd: path3.resolve(io.cwd, str3(ctx, "cwd") ?? "."),
|
|
1715
|
+
...command,
|
|
1716
|
+
...prompt !== void 0 ? { prompt } : {},
|
|
1717
|
+
...name !== void 0 ? { name } : {},
|
|
1718
|
+
...model !== void 0 ? { model } : {},
|
|
1719
|
+
...tenant !== void 0 ? { tenant } : {},
|
|
1720
|
+
...key !== void 0 ? { idempotency_key: key } : {},
|
|
1721
|
+
...Object.keys(env).length > 0 ? { env } : {},
|
|
1722
|
+
terminal,
|
|
1723
|
+
...terminal && io.stdout.columns && io.stdout.rows ? { cols: Math.min(io.stdout.columns, 1e3), rows: Math.min(io.stdout.rows, 1e3) } : {}
|
|
1724
|
+
};
|
|
1725
|
+
}
|
|
1726
|
+
function runnerAndPrompt(ctx) {
|
|
1727
|
+
const [first, second] = ctx.positionals;
|
|
1728
|
+
if (first === void 0) {
|
|
1729
|
+
if (ctx.rest && ctx.rest.length > 0) return { runner: "command", prompt: void 0 };
|
|
1730
|
+
throw usage5("Name a runner, or give a program after --.");
|
|
1731
|
+
}
|
|
1732
|
+
return { runner: first, prompt: second };
|
|
1733
|
+
}
|
|
1734
|
+
function explain(error) {
|
|
1735
|
+
if (!(error instanceof RequestError)) return error;
|
|
1736
|
+
if (error.code === "daemon.runner_unavailable") {
|
|
1737
|
+
const details = error.error.details;
|
|
1738
|
+
if (details?.child_isolation !== void 0 || /^Child isolation is unavailable/.test(error.message)) {
|
|
1739
|
+
return new CliError(error.message, EXIT.isolationUnavailable, error.code, error.error.details);
|
|
1740
|
+
}
|
|
1741
|
+
const short = shortReason(error.message);
|
|
1742
|
+
const message2 = typeof details?.runner === "string" && short !== error.message ? `${details.runner} is unavailable: ${short}. ${error.message}` : error.message;
|
|
1743
|
+
return new CliError(message2, EXIT.error, error.code, error.error.details);
|
|
1744
|
+
}
|
|
1745
|
+
const issues = error.error.details?.issues;
|
|
1746
|
+
const said = Array.isArray(issues) ? issues.map((i) => i.path ? `${i.path}: ${i.message}` : String(i.message)).join("; ") : "";
|
|
1747
|
+
const message = said ? `${error.message} ${said}.` : error.message;
|
|
1748
|
+
return new CliError(message, EXIT.error, error.code, error.error.details);
|
|
1749
|
+
}
|
|
1750
|
+
function forRunner(ctx, daemon, fields) {
|
|
1751
|
+
const info = daemon.hello?.runners.find((r) => r.name === fields.runner);
|
|
1752
|
+
if (!info || info.capabilities.terminal) return fields;
|
|
1753
|
+
if (ctx.flags.terminal) throw usage5(`The ${fields.runner} runner has no terminal; drop --terminal.`);
|
|
1754
|
+
const { terminal: _t, cols: _c, rows: _r, ...rest } = fields;
|
|
1755
|
+
return rest;
|
|
1756
|
+
}
|
|
1757
|
+
function exitCodeOf(info) {
|
|
1758
|
+
if (typeof info.exit_code === "number") return info.exit_code & 255;
|
|
1759
|
+
if (info.signal) {
|
|
1760
|
+
const n = os3.constants.signals[info.signal];
|
|
1761
|
+
return n ? 128 + n : 1;
|
|
1762
|
+
}
|
|
1763
|
+
return info.status === "exited" ? 0 : 1;
|
|
1764
|
+
}
|
|
1765
|
+
async function stream(ctx, daemon, sessionId, options) {
|
|
1766
|
+
const { io, out } = ctx;
|
|
1767
|
+
const result = { ended: false };
|
|
1768
|
+
return new Promise((resolve, reject) => {
|
|
1769
|
+
const finish = (ended) => {
|
|
1770
|
+
off();
|
|
1771
|
+
result.ended = ended;
|
|
1772
|
+
resolve(result);
|
|
1773
|
+
};
|
|
1774
|
+
const off = daemon.onPush((push) => {
|
|
1775
|
+
if (push.type === "session.updated" && push.session.id === sessionId) {
|
|
1776
|
+
result.info = push.session;
|
|
1777
|
+
return;
|
|
1778
|
+
}
|
|
1779
|
+
if (push.type === "session.lagged" && push.session_id === sessionId) {
|
|
1780
|
+
out.note(`[viewport-daemon] output skipped from seq ${push.skipped_from_seq} (slow terminal)`);
|
|
1781
|
+
return;
|
|
1782
|
+
}
|
|
1783
|
+
if (push.type !== "event" || push.session_id !== sessionId) return;
|
|
1784
|
+
if (out.json) out.data(push);
|
|
1785
|
+
const event = push.event;
|
|
1786
|
+
switch (event.type) {
|
|
1787
|
+
case "output": {
|
|
1788
|
+
if (out.json) break;
|
|
1789
|
+
const target = event.stream === "stderr" ? io.stderr : io.stdout;
|
|
1790
|
+
target.write(
|
|
1791
|
+
"data_b64" in event && event.data_b64 !== void 0 ? Buffer.from(event.data_b64, "base64url") : event.data ?? ""
|
|
1792
|
+
);
|
|
1793
|
+
break;
|
|
1794
|
+
}
|
|
1795
|
+
case "message":
|
|
1796
|
+
if (!event.partial) out.line(printable(event.role === "assistant" ? event.content : `> ${event.content}`));
|
|
1797
|
+
break;
|
|
1798
|
+
case "tool_call":
|
|
1799
|
+
out.note(printable(`[tool] ${event.tool_name} ${event.status}`));
|
|
1800
|
+
break;
|
|
1801
|
+
case "approval_requested":
|
|
1802
|
+
out.note(
|
|
1803
|
+
printable(
|
|
1804
|
+
`[approval] ${event.approval_id} for ${event.action.tool_name}: viewport-daemon approve|deny ${event.approval_id}`
|
|
1805
|
+
)
|
|
1806
|
+
);
|
|
1807
|
+
break;
|
|
1808
|
+
case "approval_resolved":
|
|
1809
|
+
out.note(printable(`[approval] ${event.approval_id} ${event.decision} (${event.resolved_by})`));
|
|
1810
|
+
break;
|
|
1811
|
+
case "error":
|
|
1812
|
+
out.note(printable(`[error] ${event.error.code}: ${event.error.message}`));
|
|
1813
|
+
break;
|
|
1814
|
+
case "exit":
|
|
1815
|
+
result.exit = { exit_code: event.exit_code, signal: event.signal };
|
|
1816
|
+
break;
|
|
1817
|
+
case "status":
|
|
1818
|
+
if (isTerminalStatus(event.status)) {
|
|
1819
|
+
result.info = { ...result.info, status: event.status, ...result.exit ?? {} };
|
|
1820
|
+
finish(true);
|
|
1821
|
+
}
|
|
1822
|
+
break;
|
|
1823
|
+
}
|
|
1824
|
+
});
|
|
1825
|
+
options.detach.addEventListener("abort", () => finish(false), { once: true });
|
|
1826
|
+
void daemon.closed.then((reason) => {
|
|
1827
|
+
if (result.ended || options.detach.aborted) return;
|
|
1828
|
+
off();
|
|
1829
|
+
reject(
|
|
1830
|
+
new CliError(`The daemon closed the connection${reason ? ` (${reason.code})` : ""}.`, EXIT.error, reason?.code)
|
|
1831
|
+
);
|
|
1832
|
+
});
|
|
1833
|
+
daemon.request("session.subscribe", { session_id: sessionId, after_seq: options.afterSeq }).then(({ session }) => {
|
|
1834
|
+
result.info ??= session;
|
|
1835
|
+
}).catch((error) => {
|
|
1836
|
+
off();
|
|
1837
|
+
reject(explain(error));
|
|
1838
|
+
});
|
|
1839
|
+
});
|
|
1840
|
+
}
|
|
1841
|
+
function forwardTerminal(ctx, daemon, sessionId) {
|
|
1842
|
+
const { io } = ctx;
|
|
1843
|
+
const stdin = io.stdin;
|
|
1844
|
+
if (!stdin?.isTTY || !stdin.setRawMode) return () => {
|
|
1845
|
+
};
|
|
1846
|
+
stdin.setRawMode(true);
|
|
1847
|
+
const onData = (chunk) => {
|
|
1848
|
+
void daemon.request("session.input", { session_id: sessionId, data_b64: Buffer.from(chunk).toString("base64url") }).catch(() => {
|
|
1849
|
+
});
|
|
1850
|
+
};
|
|
1851
|
+
stdin.on("data", onData);
|
|
1852
|
+
stdin.resume();
|
|
1853
|
+
const offResize = io.onResize?.(() => {
|
|
1854
|
+
if (io.stdout.columns && io.stdout.rows) {
|
|
1855
|
+
void daemon.request("session.resize", {
|
|
1856
|
+
session_id: sessionId,
|
|
1857
|
+
cols: Math.min(io.stdout.columns, 1e3),
|
|
1858
|
+
rows: Math.min(io.stdout.rows, 1e3)
|
|
1859
|
+
}).catch(() => {
|
|
1860
|
+
});
|
|
1861
|
+
}
|
|
1862
|
+
});
|
|
1863
|
+
return () => {
|
|
1864
|
+
offResize?.();
|
|
1865
|
+
stdin.off("data", onData);
|
|
1866
|
+
stdin.setRawMode?.(false);
|
|
1867
|
+
stdin.pause();
|
|
1868
|
+
};
|
|
1869
|
+
}
|
|
1870
|
+
var runCommand = {
|
|
1871
|
+
spec: {
|
|
1872
|
+
name: "run",
|
|
1873
|
+
summary: "Start a session and stream it until it ends; exit with its exit code.",
|
|
1874
|
+
usage: "run [flags] -- <program> [args...] | run [flags] <runner> [prompt]",
|
|
1875
|
+
flags: START_FLAGS,
|
|
1876
|
+
positionals: ["[runner]", "[prompt]"],
|
|
1877
|
+
rest: true,
|
|
1878
|
+
details: "Ctrl-C interrupts the session, a second Ctrl-C stops it. In a terminal, keys go to the session's PTY instead.\nExits with the session's exit code (128 + n for signal n, 1 if it failed without one)."
|
|
1879
|
+
},
|
|
1880
|
+
async run(ctx) {
|
|
1881
|
+
const { runner, prompt } = runnerAndPrompt(ctx);
|
|
1882
|
+
let fields = startFields(ctx, runner, prompt);
|
|
1883
|
+
return withDaemon(ctx.paths, async (daemon) => {
|
|
1884
|
+
fields = forRunner(ctx, daemon, fields);
|
|
1885
|
+
const { session } = await daemon.request("session.start", fields).catch((error) => {
|
|
1886
|
+
throw explain(error);
|
|
1887
|
+
});
|
|
1888
|
+
ctx.out.note(`[viewport-daemon] ${session.id}`);
|
|
1889
|
+
const detach = new AbortController();
|
|
1890
|
+
let interrupts = 0;
|
|
1891
|
+
const offInterrupt = ctx.io.onInterrupt(() => {
|
|
1892
|
+
interrupts += 1;
|
|
1893
|
+
const type = interrupts === 1 ? "session.interrupt" : "session.stop";
|
|
1894
|
+
void daemon.request(type, { session_id: session.id }).catch(() => {
|
|
1895
|
+
});
|
|
1896
|
+
});
|
|
1897
|
+
const undoTerminal = fields.terminal ? forwardTerminal(ctx, daemon, session.id) : () => {
|
|
1898
|
+
};
|
|
1899
|
+
try {
|
|
1900
|
+
const result = await stream(ctx, daemon, session.id, { afterSeq: 0, detach: detach.signal });
|
|
1901
|
+
const info = result.info ?? session;
|
|
1902
|
+
const code2 = exitCodeOf(info);
|
|
1903
|
+
if (ctx.out.json)
|
|
1904
|
+
ctx.out.data({ type: "result", session_id: session.id, status: info.status, exit_code: code2 });
|
|
1905
|
+
return code2;
|
|
1906
|
+
} finally {
|
|
1907
|
+
undoTerminal();
|
|
1908
|
+
offInterrupt();
|
|
1909
|
+
}
|
|
1910
|
+
});
|
|
1911
|
+
}
|
|
1912
|
+
};
|
|
1913
|
+
var startCommand = {
|
|
1914
|
+
spec: {
|
|
1915
|
+
name: "start",
|
|
1916
|
+
summary: "Start a session in the background and print its id.",
|
|
1917
|
+
usage: "start [flags] <runner> [prompt] [-- args...]",
|
|
1918
|
+
flags: START_FLAGS,
|
|
1919
|
+
positionals: ["runner", "[prompt]"],
|
|
1920
|
+
rest: true,
|
|
1921
|
+
details: "For the command runner the program goes after --: start command -- npm test."
|
|
1922
|
+
},
|
|
1923
|
+
async run(ctx) {
|
|
1924
|
+
const { runner, prompt } = runnerAndPrompt(ctx);
|
|
1925
|
+
const fields = startFields(ctx, runner, prompt);
|
|
1926
|
+
const { session } = await withDaemon(ctx.paths, (d) => d.request("session.start", forRunner(ctx, d, fields))).catch(
|
|
1927
|
+
(error) => {
|
|
1928
|
+
throw explain(error);
|
|
1929
|
+
}
|
|
1930
|
+
);
|
|
1931
|
+
ctx.out.result({ session }, session.id);
|
|
1932
|
+
return EXIT.ok;
|
|
1933
|
+
}
|
|
1934
|
+
};
|
|
1935
|
+
var lsCommand = {
|
|
1936
|
+
spec: {
|
|
1937
|
+
name: "ls",
|
|
1938
|
+
summary: "List sessions, newest first.",
|
|
1939
|
+
usage: "ls [flags]",
|
|
1940
|
+
flags: {
|
|
1941
|
+
status: { type: "string", value: "<s,...>", description: "Only these statuses (running, exited, ...)" },
|
|
1942
|
+
pending: { type: "boolean", description: "Only sessions waiting for an approval" },
|
|
1943
|
+
tenant: { type: "string", value: "<label>", description: "Only this tenant" },
|
|
1944
|
+
limit: { type: "string", value: "<n>", description: "At most n (default 50, max 500)" }
|
|
1945
|
+
}
|
|
1946
|
+
},
|
|
1947
|
+
async run(ctx) {
|
|
1948
|
+
const statuses = str3(ctx, "status")?.split(",").map((s) => s.trim()).filter(Boolean);
|
|
1949
|
+
for (const s of statuses ?? []) {
|
|
1950
|
+
if (!Status.safeParse(s).success) throw usage5(`Unknown status ${JSON.stringify(s)}.`);
|
|
1951
|
+
}
|
|
1952
|
+
const limit = str3(ctx, "limit");
|
|
1953
|
+
const tenant = str3(ctx, "tenant");
|
|
1954
|
+
const fields = {
|
|
1955
|
+
...statuses?.length ? { status: statuses } : {},
|
|
1956
|
+
...ctx.flags.pending ? { pending_approvals: true } : {},
|
|
1957
|
+
...tenant ? { tenant } : {},
|
|
1958
|
+
...limit ? { limit: parseInteger(limit, "limit", 1, 500) } : {}
|
|
1959
|
+
};
|
|
1960
|
+
const data = await withDaemon(ctx.paths, (d) => d.request("sessions.list", fields)).catch((error) => {
|
|
1961
|
+
throw explain(error);
|
|
1962
|
+
});
|
|
1963
|
+
const text = data.sessions.length === 0 ? "No sessions." : table(
|
|
1964
|
+
["ID", "RUNNER", "STATUS", "CREATED", "NAME"],
|
|
1965
|
+
data.sessions.map((s) => [
|
|
1966
|
+
s.id,
|
|
1967
|
+
s.runner,
|
|
1968
|
+
s.status === "waiting_approval" ? `${s.status} (${s.pending_approvals_count ?? s.pending_approvals.length})` : s.status,
|
|
1969
|
+
when(s.created_at),
|
|
1970
|
+
printable(s.name ?? "").replace(/[\t\n]/g, " ")
|
|
1971
|
+
])
|
|
1972
|
+
) + (data.more ? "\n(more: use --limit)" : "");
|
|
1973
|
+
ctx.out.result(data, text);
|
|
1974
|
+
return EXIT.ok;
|
|
1975
|
+
}
|
|
1976
|
+
};
|
|
1977
|
+
var attachCommand = {
|
|
1978
|
+
spec: {
|
|
1979
|
+
name: "attach",
|
|
1980
|
+
summary: "Stream a session live (from the start, or --after-seq); Ctrl-C detaches.",
|
|
1981
|
+
usage: "attach [flags] <session_id>",
|
|
1982
|
+
flags: { "after-seq": { type: "string", value: "<n>", description: "Replay only events after seq n (default 0)" } },
|
|
1983
|
+
positionals: ["session_id"],
|
|
1984
|
+
details: "Exits 0 on detach, or with the session's exit code when it ends while attached."
|
|
1985
|
+
},
|
|
1986
|
+
async run(ctx) {
|
|
1987
|
+
const sessionId = ctx.positionals[0];
|
|
1988
|
+
const after = str3(ctx, "after-seq");
|
|
1989
|
+
const afterSeq = after === void 0 ? 0 : parseInteger(after, "after-seq");
|
|
1990
|
+
return withDaemon(ctx.paths, async (daemon) => {
|
|
1991
|
+
const detach = new AbortController();
|
|
1992
|
+
const off = ctx.io.onInterrupt(() => detach.abort());
|
|
1993
|
+
try {
|
|
1994
|
+
const result = await stream(ctx, daemon, sessionId, { afterSeq, detach: detach.signal });
|
|
1995
|
+
if (!result.ended) {
|
|
1996
|
+
ctx.out.note(`[viewport-daemon] detached from ${sessionId}`);
|
|
1997
|
+
if (ctx.out.json) ctx.out.data({ type: "detached", session_id: sessionId });
|
|
1998
|
+
return EXIT.ok;
|
|
1999
|
+
}
|
|
2000
|
+
const code2 = exitCodeOf(result.info);
|
|
2001
|
+
if (ctx.out.json) {
|
|
2002
|
+
ctx.out.data({ type: "result", session_id: sessionId, status: result.info.status, exit_code: code2 });
|
|
2003
|
+
}
|
|
2004
|
+
return code2;
|
|
2005
|
+
} finally {
|
|
2006
|
+
off();
|
|
2007
|
+
}
|
|
2008
|
+
});
|
|
2009
|
+
}
|
|
2010
|
+
};
|
|
2011
|
+
var stopCommand = {
|
|
2012
|
+
spec: {
|
|
2013
|
+
name: "stop",
|
|
2014
|
+
summary: "Stop a session (SIGTERM to its process group, SIGKILL after the grace period).",
|
|
2015
|
+
usage: "stop [flags] <session_id>",
|
|
2016
|
+
flags: { grace: { type: "string", value: "<ms>", description: "Grace period in ms (default 2000)" } },
|
|
2017
|
+
positionals: ["session_id"]
|
|
2018
|
+
},
|
|
2019
|
+
async run(ctx) {
|
|
2020
|
+
const grace = str3(ctx, "grace");
|
|
2021
|
+
const fields = {
|
|
2022
|
+
session_id: ctx.positionals[0],
|
|
2023
|
+
...grace !== void 0 ? { grace_ms: parseInteger(grace, "grace", 0, 36e5) } : {}
|
|
2024
|
+
};
|
|
2025
|
+
const { session } = await withDaemon(ctx.paths, (d) => d.request("session.stop", fields)).catch((error) => {
|
|
2026
|
+
throw explain(error);
|
|
2027
|
+
});
|
|
2028
|
+
ctx.out.result({ session }, `${session.id} ${session.status}`);
|
|
2029
|
+
return EXIT.ok;
|
|
2030
|
+
}
|
|
2031
|
+
};
|
|
2032
|
+
async function fetchAction(daemon, approvalId) {
|
|
2033
|
+
const parts = [];
|
|
2034
|
+
let offset = 0;
|
|
2035
|
+
let digest = "";
|
|
2036
|
+
for (; ; ) {
|
|
2037
|
+
const chunk = await daemon.request("approval.get", { approval_id: approvalId, offset });
|
|
2038
|
+
digest = chunk.action_digest;
|
|
2039
|
+
const bytes = Buffer.from(chunk.chunk_b64, "base64url");
|
|
2040
|
+
parts.push(bytes);
|
|
2041
|
+
offset += bytes.byteLength;
|
|
2042
|
+
if (!chunk.more || bytes.byteLength === 0) break;
|
|
2043
|
+
}
|
|
2044
|
+
const joined = Buffer.concat(parts);
|
|
2045
|
+
const actual = `sha256:${createHash("sha256").update(joined).digest("hex")}`;
|
|
2046
|
+
if (actual !== digest) {
|
|
2047
|
+
throw new CliError(
|
|
2048
|
+
`The action of ${approvalId} does not match its digest.`,
|
|
2049
|
+
EXIT.error,
|
|
2050
|
+
"daemon.approval_action_mismatch"
|
|
2051
|
+
);
|
|
2052
|
+
}
|
|
2053
|
+
return { action: JSON.parse(joined.toString("utf8")), digest };
|
|
2054
|
+
}
|
|
2055
|
+
function describeAction(approvalId, action, digest) {
|
|
2056
|
+
return [
|
|
2057
|
+
`Approval ${approvalId}`,
|
|
2058
|
+
` tool ${visible(action.tool_name)}`,
|
|
2059
|
+
...action.call_id !== void 0 ? [` call ${visible(action.call_id)}`] : [],
|
|
2060
|
+
` digest ${digest}`,
|
|
2061
|
+
" args",
|
|
2062
|
+
// JSON escapes C0 controls; DEL and C1 (a raw CSI is U+009B) are escaped here, so nothing in args drives the terminal.
|
|
2063
|
+
...JSON.stringify(action.args, null, 2).split("\n").map((line) => ` ${visible(line)}`)
|
|
2064
|
+
].join("\n");
|
|
2065
|
+
}
|
|
2066
|
+
var CONFIRM_TIMEOUT_MS = 5 * 6e4;
|
|
2067
|
+
var approvalShowCommand = {
|
|
2068
|
+
spec: {
|
|
2069
|
+
name: "approval show",
|
|
2070
|
+
summary: "Print a pending (or stored) approval's full action: tool, call id, digest and every arg.",
|
|
2071
|
+
usage: "approval show [flags] <approval_id>",
|
|
2072
|
+
flags: {},
|
|
2073
|
+
positionals: ["approval_id"],
|
|
2074
|
+
details: "The action is fetched in full with approval.get and checked against its digest."
|
|
2075
|
+
},
|
|
2076
|
+
async run(ctx) {
|
|
2077
|
+
const approvalId = ctx.positionals[0];
|
|
2078
|
+
return withDaemon(ctx.paths, async (daemon) => {
|
|
2079
|
+
const { action, digest } = await fetchAction(daemon, approvalId).catch((error) => {
|
|
2080
|
+
throw explain(error);
|
|
2081
|
+
});
|
|
2082
|
+
ctx.out.result(
|
|
2083
|
+
{ approval_id: approvalId, action, action_digest: digest },
|
|
2084
|
+
describeAction(approvalId, action, digest)
|
|
2085
|
+
);
|
|
2086
|
+
return EXIT.ok;
|
|
2087
|
+
});
|
|
2088
|
+
}
|
|
2089
|
+
};
|
|
2090
|
+
function answerCommand(decision) {
|
|
2091
|
+
const verb = decision === "allow" ? "approve" : "deny";
|
|
2092
|
+
const allow = decision === "allow";
|
|
2093
|
+
return {
|
|
2094
|
+
spec: {
|
|
2095
|
+
name: verb,
|
|
2096
|
+
summary: `${allow ? "Allow" : "Deny"} a pending tool call, from the local token.`,
|
|
2097
|
+
usage: `${verb} [flags] <approval_id>`,
|
|
2098
|
+
flags: {
|
|
2099
|
+
reason: { type: "string", value: "<text>", description: "Why, recorded on approval_resolved" },
|
|
2100
|
+
actor: { type: "string", value: "<name>", description: "Who decided (a claim, recorded and echoed)" },
|
|
2101
|
+
...allow ? {
|
|
2102
|
+
yes: {
|
|
2103
|
+
type: "boolean",
|
|
2104
|
+
description: "Allow without asking (required when stdin is not a terminal)"
|
|
2105
|
+
}
|
|
2106
|
+
} : {}
|
|
2107
|
+
},
|
|
2108
|
+
positionals: ["approval_id"],
|
|
2109
|
+
details: "Works only when the daemon runs with --local-approvals; otherwise answer from a paired controller.\nThe full action is fetched, checked against its digest and printed first, and the answer carries that digest." + (allow ? "\nOn a terminal it then asks; only y or yes allows. Without a terminal it refuses unless --yes is given." : "")
|
|
2110
|
+
},
|
|
2111
|
+
async run(ctx) {
|
|
2112
|
+
const approvalId = ctx.positionals[0];
|
|
2113
|
+
const reason = str3(ctx, "reason");
|
|
2114
|
+
const actor = str3(ctx, "actor");
|
|
2115
|
+
return withDaemon(ctx.paths, async (daemon) => {
|
|
2116
|
+
const { action, digest } = await fetchAction(daemon, approvalId).catch((error) => {
|
|
2117
|
+
throw explain(error);
|
|
2118
|
+
});
|
|
2119
|
+
if (allow) {
|
|
2120
|
+
const shown = describeAction(approvalId, action, digest);
|
|
2121
|
+
if (ctx.out.json) ctx.out.data({ type: "action", approval_id: approvalId, action, action_digest: digest });
|
|
2122
|
+
else ctx.io.stdout.write(`${shown}
|
|
2123
|
+
`);
|
|
2124
|
+
if (ctx.flags.yes !== true) {
|
|
2125
|
+
if (ctx.io.stdin?.isTTY !== true) {
|
|
2126
|
+
throw new CliError(
|
|
2127
|
+
"Refusing to allow without a terminal to confirm on. Read the action above, then pass --yes.",
|
|
2128
|
+
EXIT.usage,
|
|
2129
|
+
"cli.confirmation_required"
|
|
2130
|
+
);
|
|
2131
|
+
}
|
|
2132
|
+
ctx.io.stderr.write("Allow this tool call? [y/N] ");
|
|
2133
|
+
const answer2 = await readLine(ctx.io.stdin, CONFIRM_TIMEOUT_MS);
|
|
2134
|
+
if (!/^\s*y(es)?\s*$/i.test(answer2 ?? "")) {
|
|
2135
|
+
throw new CliError(`Not allowed; ${approvalId} is still pending.`, EXIT.error, "cli.not_confirmed");
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
const answer = await daemon.request("approval.respond", {
|
|
2140
|
+
approval_id: approvalId,
|
|
2141
|
+
decision,
|
|
2142
|
+
action_digest: digest,
|
|
2143
|
+
...reason !== void 0 ? { reason } : {},
|
|
2144
|
+
...actor !== void 0 ? { actor } : {}
|
|
2145
|
+
}).catch((error) => {
|
|
2146
|
+
if (error instanceof RequestError && error.code === "daemon.forbidden") {
|
|
2147
|
+
throw new CliError(
|
|
2148
|
+
"This daemon does not take approvals from the local token (local_approvals is off, the default). Answer from a paired controller, or restart the daemon with --local-approvals.",
|
|
2149
|
+
EXIT.error,
|
|
2150
|
+
error.code
|
|
2151
|
+
);
|
|
2152
|
+
}
|
|
2153
|
+
throw explain(error);
|
|
2154
|
+
});
|
|
2155
|
+
ctx.out.result(
|
|
2156
|
+
{ ...answer, action },
|
|
2157
|
+
`${allow ? "Allowed" : "Denied"} ${approvalId} (${visible(action.tool_name)}).`
|
|
2158
|
+
);
|
|
2159
|
+
return EXIT.ok;
|
|
2160
|
+
});
|
|
2161
|
+
}
|
|
2162
|
+
};
|
|
2163
|
+
}
|
|
2164
|
+
var approveCommand = answerCommand("allow");
|
|
2165
|
+
var denyCommand = answerCommand("deny");
|
|
2166
|
+
|
|
2167
|
+
// src/cli/main.ts
|
|
2168
|
+
var PROGRAM = "viewport-daemon";
|
|
2169
|
+
var COMMANDS = {
|
|
2170
|
+
up: upCommand,
|
|
2171
|
+
down: downCommand,
|
|
2172
|
+
serve: serveCommand,
|
|
2173
|
+
status: statusCommand,
|
|
2174
|
+
doctor: doctorCommand,
|
|
2175
|
+
run: runCommand,
|
|
2176
|
+
start: startCommand,
|
|
2177
|
+
ls: lsCommand,
|
|
2178
|
+
attach: attachCommand,
|
|
2179
|
+
stop: stopCommand,
|
|
2180
|
+
approve: approveCommand,
|
|
2181
|
+
"approval show": approvalShowCommand,
|
|
2182
|
+
deny: denyCommand,
|
|
2183
|
+
pair: pairCommand,
|
|
2184
|
+
"peers ls": peersLsCommand,
|
|
2185
|
+
"peers revoke": peersRevokeCommand,
|
|
2186
|
+
"claude-token": claudeTokenCommand
|
|
2187
|
+
};
|
|
2188
|
+
var GROUPS = [
|
|
2189
|
+
["Daemon", ["up", "down", "serve", "status", "doctor"]],
|
|
2190
|
+
["Sessions", ["run", "start", "ls", "attach", "stop", "approval show", "approve", "deny"]],
|
|
2191
|
+
["Pairing", ["pair", "peers ls", "peers revoke"]],
|
|
2192
|
+
["Agents", ["claude-token"]]
|
|
2193
|
+
];
|
|
2194
|
+
function overallHelp() {
|
|
2195
|
+
const width = Math.max(...Object.keys(COMMANDS).map((k) => k.length));
|
|
2196
|
+
const lines = [
|
|
2197
|
+
`Usage: ${PROGRAM} [--home <dir>] [--json] <command> [flags] (alias: vpd)`,
|
|
2198
|
+
"",
|
|
2199
|
+
"Run and supervise agents on this machine, and pair viewers with it."
|
|
2200
|
+
];
|
|
2201
|
+
for (const [group, names] of GROUPS) {
|
|
2202
|
+
lines.push("", `${group}:`);
|
|
2203
|
+
for (const name of names) lines.push(` ${name.padEnd(width)} ${COMMANDS[name].spec.summary}`);
|
|
2204
|
+
}
|
|
2205
|
+
lines.push(
|
|
2206
|
+
"",
|
|
2207
|
+
"Every command takes --home <dir>, --json and --help, before or after the command name.",
|
|
2208
|
+
"Home: --home, else $VIEWPORT_HOME, else ~/.viewport/daemon.",
|
|
2209
|
+
"",
|
|
2210
|
+
EXIT_CODES_HELP,
|
|
2211
|
+
""
|
|
2212
|
+
);
|
|
2213
|
+
return lines.join("\n");
|
|
2214
|
+
}
|
|
2215
|
+
function hoistGlobals(argv) {
|
|
2216
|
+
const lead = [];
|
|
2217
|
+
let i = 0;
|
|
2218
|
+
for (; i < argv.length; i++) {
|
|
2219
|
+
const arg = argv[i];
|
|
2220
|
+
if (!arg.startsWith("--") || arg === "--") break;
|
|
2221
|
+
const eq = arg.indexOf("=");
|
|
2222
|
+
const name = arg.slice(2, eq < 0 ? void 0 : eq);
|
|
2223
|
+
const flag = GLOBAL_FLAGS[name];
|
|
2224
|
+
if (!flag || name === "help") break;
|
|
2225
|
+
if (flag.type === "string" && eq < 0) {
|
|
2226
|
+
const value = argv[i + 1];
|
|
2227
|
+
if (value === void 0 || value === "--")
|
|
2228
|
+
throw usageError(`--${name} needs a value${flag.value ? ` ${flag.value}` : ""}.`);
|
|
2229
|
+
lead.push(arg, value);
|
|
2230
|
+
i++;
|
|
2231
|
+
} else lead.push(arg);
|
|
2232
|
+
}
|
|
2233
|
+
return { lead, rest: argv.slice(i) };
|
|
2234
|
+
}
|
|
2235
|
+
var usageError = (message) => new CliError(message, EXIT.usage, "cli.usage");
|
|
2236
|
+
async function main(argv, io) {
|
|
2237
|
+
const dash = argv.indexOf("--");
|
|
2238
|
+
const json = (dash < 0 ? argv : argv.slice(0, dash)).includes("--json");
|
|
2239
|
+
const out = new Output(io, json);
|
|
2240
|
+
let lead;
|
|
2241
|
+
let words;
|
|
2242
|
+
try {
|
|
2243
|
+
({ lead, rest: words } = hoistGlobals(argv));
|
|
2244
|
+
} catch (error) {
|
|
2245
|
+
return report(error, out);
|
|
2246
|
+
}
|
|
2247
|
+
const first = words[0];
|
|
2248
|
+
if (first === void 0 && lead.length > 0) {
|
|
2249
|
+
return report(usageError(`Name a command after the global flags. Run \`${PROGRAM} --help\`.`), out);
|
|
2250
|
+
}
|
|
2251
|
+
if (first === void 0 || first === "--help" || first === "-h" || first === "help") {
|
|
2252
|
+
const topic = first === "help" ? words.slice(1).join(" ") : "";
|
|
2253
|
+
const command2 = COMMANDS[topic];
|
|
2254
|
+
io.stdout.write(command2 ? commandHelp(PROGRAM, command2.spec) : overallHelp());
|
|
2255
|
+
return first === void 0 ? EXIT.usage : EXIT.ok;
|
|
2256
|
+
}
|
|
2257
|
+
if (first === "--version" || first === "-v") {
|
|
2258
|
+
out.result({ version: DAEMON_VERSION }, DAEMON_VERSION);
|
|
2259
|
+
return EXIT.ok;
|
|
2260
|
+
}
|
|
2261
|
+
if (first.startsWith("-")) {
|
|
2262
|
+
return report(usageError(`Unknown flag ${first.split("=")[0]} before the command.`), out);
|
|
2263
|
+
}
|
|
2264
|
+
const two = `${first} ${words[1] ?? ""}`.trim();
|
|
2265
|
+
const grouped = first === "peers" || first === "approval";
|
|
2266
|
+
const [name, tail2] = grouped ? [COMMANDS[two] ? two : void 0, words.slice(2)] : [first, words.slice(1)];
|
|
2267
|
+
const command = name ? COMMANDS[name] : void 0;
|
|
2268
|
+
if (!command) {
|
|
2269
|
+
return report(
|
|
2270
|
+
usageError(
|
|
2271
|
+
first === "peers" ? "Use `peers ls` or `peers revoke <peer_id>`." : first === "approval" ? "Use `approval show <approval_id>`." : `Unknown command ${JSON.stringify(first)}. Run \`${PROGRAM} --help\`.`
|
|
2272
|
+
),
|
|
2273
|
+
out
|
|
2274
|
+
);
|
|
2275
|
+
}
|
|
2276
|
+
try {
|
|
2277
|
+
const parsed = parseArgs(command.spec, [...lead, ...tail2]);
|
|
2278
|
+
if (parsed.flags.help) {
|
|
2279
|
+
io.stdout.write(commandHelp(PROGRAM, command.spec));
|
|
2280
|
+
return EXIT.ok;
|
|
2281
|
+
}
|
|
2282
|
+
const paths = resolveHome(parsed.flags.home, io);
|
|
2283
|
+
return await command.run({ io, out, paths, ...parsed });
|
|
2284
|
+
} catch (error) {
|
|
2285
|
+
return report(error, out);
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
function report(error, out) {
|
|
2289
|
+
const failure = error instanceof CliError ? error : error instanceof RequestError ? new CliError(error.message, EXIT.error, error.code, error.error.details) : new CliError(error instanceof Error ? error.message : String(error));
|
|
2290
|
+
if (out.json) {
|
|
2291
|
+
out.data({
|
|
2292
|
+
error: {
|
|
2293
|
+
code: failure.code,
|
|
2294
|
+
message: failure.message,
|
|
2295
|
+
...failure.details ? { details: failure.details } : {}
|
|
2296
|
+
},
|
|
2297
|
+
exit_code: failure.exitCode
|
|
2298
|
+
});
|
|
2299
|
+
} else {
|
|
2300
|
+
out.io.stderr.write(`${PROGRAM}: ${failure.message}
|
|
2301
|
+
`);
|
|
2302
|
+
if (failure.exitCode === EXIT.usage) out.io.stderr.write(`Run \`${PROGRAM} --help\` for usage.
|
|
2303
|
+
`);
|
|
2304
|
+
}
|
|
2305
|
+
return failure.exitCode;
|
|
2306
|
+
}
|
|
2307
|
+
|
|
2308
|
+
// src/cli/bin.ts
|
|
2309
|
+
var code = await main(process.argv.slice(2), nodeIO());
|
|
2310
|
+
process.exitCode = code;
|
|
2311
|
+
process.stdout.write("", () => process.exit(code));
|