@alan-ai-hq/agent-manager 0.1.113 → 0.1.115
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 +88 -0
- package/dist/__tests__/binding-switch-git.test.d.ts +2 -0
- package/dist/__tests__/binding-switch-git.test.d.ts.map +1 -0
- package/dist/__tests__/binding-switch-git.test.js +555 -0
- package/dist/__tests__/binding-switch-git.test.js.map +1 -0
- package/dist/__tests__/cli-ensure-install.test.d.ts +2 -0
- package/dist/__tests__/cli-ensure-install.test.d.ts.map +1 -0
- package/dist/__tests__/cli-ensure-install.test.js +177 -0
- package/dist/__tests__/cli-ensure-install.test.js.map +1 -0
- package/dist/__tests__/cli-executable.test.d.ts +2 -0
- package/dist/__tests__/cli-executable.test.d.ts.map +1 -0
- package/dist/__tests__/cli-executable.test.js +155 -0
- package/dist/__tests__/cli-executable.test.js.map +1 -0
- package/dist/__tests__/cli-executable.windows.test.d.ts +2 -0
- package/dist/__tests__/cli-executable.windows.test.d.ts.map +1 -0
- package/dist/__tests__/cli-executable.windows.test.js +123 -0
- package/dist/__tests__/cli-executable.windows.test.js.map +1 -0
- package/dist/__tests__/cli-help.test.d.ts +2 -0
- package/dist/__tests__/cli-help.test.d.ts.map +1 -0
- package/dist/__tests__/cli-help.test.js +47 -0
- package/dist/__tests__/cli-help.test.js.map +1 -0
- package/dist/__tests__/computer-readiness.test.d.ts +2 -0
- package/dist/__tests__/computer-readiness.test.d.ts.map +1 -0
- package/dist/__tests__/computer-readiness.test.js +63 -0
- package/dist/__tests__/computer-readiness.test.js.map +1 -0
- package/dist/__tests__/core-agent-provider-auth-env.test.d.ts +2 -0
- package/dist/__tests__/core-agent-provider-auth-env.test.d.ts.map +1 -0
- package/dist/__tests__/core-agent-provider-auth-env.test.js +93 -0
- package/dist/__tests__/core-agent-provider-auth-env.test.js.map +1 -0
- package/dist/__tests__/core-agent-workflow-context.test.d.ts +2 -0
- package/dist/__tests__/core-agent-workflow-context.test.d.ts.map +1 -0
- package/dist/__tests__/core-agent-workflow-context.test.js +139 -0
- package/dist/__tests__/core-agent-workflow-context.test.js.map +1 -0
- package/dist/__tests__/daemon-native-hooks.test.d.ts +2 -0
- package/dist/__tests__/daemon-native-hooks.test.d.ts.map +1 -0
- package/dist/__tests__/daemon-native-hooks.test.js +94 -0
- package/dist/__tests__/daemon-native-hooks.test.js.map +1 -0
- package/dist/__tests__/daemon-reconcile-ask.test.d.ts +2 -0
- package/dist/__tests__/daemon-reconcile-ask.test.d.ts.map +1 -0
- package/dist/__tests__/daemon-reconcile-ask.test.js +100 -0
- package/dist/__tests__/daemon-reconcile-ask.test.js.map +1 -0
- package/dist/__tests__/daemon-runner-status.test.d.ts +2 -0
- package/dist/__tests__/daemon-runner-status.test.d.ts.map +1 -0
- package/dist/__tests__/daemon-runner-status.test.js +102 -0
- package/dist/__tests__/daemon-runner-status.test.js.map +1 -0
- package/dist/__tests__/daemon-socket.integration.test.d.ts +2 -0
- package/dist/__tests__/daemon-socket.integration.test.d.ts.map +1 -0
- package/dist/__tests__/daemon-socket.integration.test.js +435 -0
- package/dist/__tests__/daemon-socket.integration.test.js.map +1 -0
- package/dist/__tests__/daemon.test.d.ts +2 -0
- package/dist/__tests__/daemon.test.d.ts.map +1 -0
- package/dist/__tests__/daemon.test.js +4884 -0
- package/dist/__tests__/daemon.test.js.map +1 -0
- package/dist/__tests__/ensure-shared-checkout-branch.test.d.ts +2 -0
- package/dist/__tests__/ensure-shared-checkout-branch.test.d.ts.map +1 -0
- package/dist/__tests__/ensure-shared-checkout-branch.test.js +129 -0
- package/dist/__tests__/ensure-shared-checkout-branch.test.js.map +1 -0
- package/dist/__tests__/event-journal-stress.test.d.ts +2 -0
- package/dist/__tests__/event-journal-stress.test.d.ts.map +1 -0
- package/dist/__tests__/event-journal-stress.test.js +124 -0
- package/dist/__tests__/event-journal-stress.test.js.map +1 -0
- package/dist/__tests__/event-journal.test.d.ts +2 -0
- package/dist/__tests__/event-journal.test.d.ts.map +1 -0
- package/dist/__tests__/event-journal.test.js +264 -0
- package/dist/__tests__/event-journal.test.js.map +1 -0
- package/dist/__tests__/event-outbox-persist-failure.test.d.ts +2 -0
- package/dist/__tests__/event-outbox-persist-failure.test.d.ts.map +1 -0
- package/dist/__tests__/event-outbox-persist-failure.test.js +143 -0
- package/dist/__tests__/event-outbox-persist-failure.test.js.map +1 -0
- package/dist/__tests__/event-outbox.test.d.ts +2 -0
- package/dist/__tests__/event-outbox.test.d.ts.map +1 -0
- package/dist/__tests__/event-outbox.test.js +602 -0
- package/dist/__tests__/event-outbox.test.js.map +1 -0
- package/dist/__tests__/execution-activity-tracker.test.d.ts +2 -0
- package/dist/__tests__/execution-activity-tracker.test.d.ts.map +1 -0
- package/dist/__tests__/execution-activity-tracker.test.js +64 -0
- package/dist/__tests__/execution-activity-tracker.test.js.map +1 -0
- package/dist/__tests__/execution-lease-client.test.d.ts +2 -0
- package/dist/__tests__/execution-lease-client.test.d.ts.map +1 -0
- package/dist/__tests__/execution-lease-client.test.js +274 -0
- package/dist/__tests__/execution-lease-client.test.js.map +1 -0
- package/dist/__tests__/fake-provider-cli.test.d.ts +2 -0
- package/dist/__tests__/fake-provider-cli.test.d.ts.map +1 -0
- package/dist/__tests__/fake-provider-cli.test.js +46 -0
- package/dist/__tests__/fake-provider-cli.test.js.map +1 -0
- package/dist/__tests__/generated-images.test.d.ts +2 -0
- package/dist/__tests__/generated-images.test.d.ts.map +1 -0
- package/dist/__tests__/generated-images.test.js +132 -0
- package/dist/__tests__/generated-images.test.js.map +1 -0
- package/dist/__tests__/helpers/sandbox-outbox.d.ts +3 -0
- package/dist/__tests__/helpers/sandbox-outbox.d.ts.map +1 -0
- package/dist/__tests__/helpers/sandbox-outbox.js +23 -0
- package/dist/__tests__/helpers/sandbox-outbox.js.map +1 -0
- package/dist/__tests__/install-command.test.d.ts +2 -0
- package/dist/__tests__/install-command.test.d.ts.map +1 -0
- package/dist/__tests__/install-command.test.js +185 -0
- package/dist/__tests__/install-command.test.js.map +1 -0
- package/dist/__tests__/integration-cli.test.d.ts +2 -0
- package/dist/__tests__/integration-cli.test.d.ts.map +1 -0
- package/dist/__tests__/integration-cli.test.js +150 -0
- package/dist/__tests__/integration-cli.test.js.map +1 -0
- package/dist/__tests__/lifecycle-contracts.test.d.ts +2 -0
- package/dist/__tests__/lifecycle-contracts.test.d.ts.map +1 -0
- package/dist/__tests__/lifecycle-contracts.test.js +66 -0
- package/dist/__tests__/lifecycle-contracts.test.js.map +1 -0
- package/dist/__tests__/lifecycle-logger.test.d.ts +2 -0
- package/dist/__tests__/lifecycle-logger.test.d.ts.map +1 -0
- package/dist/__tests__/lifecycle-logger.test.js +49 -0
- package/dist/__tests__/lifecycle-logger.test.js.map +1 -0
- package/dist/__tests__/local-daemon-lifecycle.test.d.ts +2 -0
- package/dist/__tests__/local-daemon-lifecycle.test.d.ts.map +1 -0
- package/dist/__tests__/local-daemon-lifecycle.test.js +594 -0
- package/dist/__tests__/local-daemon-lifecycle.test.js.map +1 -0
- package/dist/__tests__/local-git-status.test.d.ts +2 -0
- package/dist/__tests__/local-git-status.test.d.ts.map +1 -0
- package/dist/__tests__/local-git-status.test.js +31 -0
- package/dist/__tests__/local-git-status.test.js.map +1 -0
- package/dist/__tests__/mcp-config-adapters-files.test.d.ts +2 -0
- package/dist/__tests__/mcp-config-adapters-files.test.d.ts.map +1 -0
- package/dist/__tests__/mcp-config-adapters-files.test.js +486 -0
- package/dist/__tests__/mcp-config-adapters-files.test.js.map +1 -0
- package/dist/__tests__/mcp-config-adapters.test.d.ts +2 -0
- package/dist/__tests__/mcp-config-adapters.test.d.ts.map +1 -0
- package/dist/__tests__/mcp-config-adapters.test.js +492 -0
- package/dist/__tests__/mcp-config-adapters.test.js.map +1 -0
- package/dist/__tests__/mcp-sync.test.d.ts +2 -0
- package/dist/__tests__/mcp-sync.test.d.ts.map +1 -0
- package/dist/__tests__/mcp-sync.test.js +21 -0
- package/dist/__tests__/mcp-sync.test.js.map +1 -0
- package/dist/__tests__/model-scan-runner.test.d.ts +2 -0
- package/dist/__tests__/model-scan-runner.test.d.ts.map +1 -0
- package/dist/__tests__/model-scan-runner.test.js +80 -0
- package/dist/__tests__/model-scan-runner.test.js.map +1 -0
- package/dist/__tests__/native-hook-command.test.d.ts +2 -0
- package/dist/__tests__/native-hook-command.test.d.ts.map +1 -0
- package/dist/__tests__/native-hook-command.test.js +386 -0
- package/dist/__tests__/native-hook-command.test.js.map +1 -0
- package/dist/__tests__/native-hook-config.test.d.ts +2 -0
- package/dist/__tests__/native-hook-config.test.d.ts.map +1 -0
- package/dist/__tests__/native-hook-config.test.js +374 -0
- package/dist/__tests__/native-hook-config.test.js.map +1 -0
- package/dist/__tests__/native-hook-drain.test.d.ts +2 -0
- package/dist/__tests__/native-hook-drain.test.d.ts.map +1 -0
- package/dist/__tests__/native-hook-drain.test.js +197 -0
- package/dist/__tests__/native-hook-drain.test.js.map +1 -0
- package/dist/__tests__/native-hook-inbox.test.d.ts +2 -0
- package/dist/__tests__/native-hook-inbox.test.d.ts.map +1 -0
- package/dist/__tests__/native-hook-inbox.test.js +139 -0
- package/dist/__tests__/native-hook-inbox.test.js.map +1 -0
- package/dist/__tests__/native-session.test.d.ts +2 -0
- package/dist/__tests__/native-session.test.d.ts.map +1 -0
- package/dist/__tests__/native-session.test.js +41 -0
- package/dist/__tests__/native-session.test.js.map +1 -0
- package/dist/__tests__/native-stream-outbox.test.d.ts +2 -0
- package/dist/__tests__/native-stream-outbox.test.d.ts.map +1 -0
- package/dist/__tests__/native-stream-outbox.test.js +231 -0
- package/dist/__tests__/native-stream-outbox.test.js.map +1 -0
- package/dist/__tests__/native-stream-platform.test.d.ts +2 -0
- package/dist/__tests__/native-stream-platform.test.d.ts.map +1 -0
- package/dist/__tests__/native-stream-platform.test.js +20 -0
- package/dist/__tests__/native-stream-platform.test.js.map +1 -0
- package/dist/__tests__/native-transcript-cursor.test.d.ts +2 -0
- package/dist/__tests__/native-transcript-cursor.test.d.ts.map +1 -0
- package/dist/__tests__/native-transcript-cursor.test.js +60 -0
- package/dist/__tests__/native-transcript-cursor.test.js.map +1 -0
- package/dist/__tests__/native-transcript-stream.test.d.ts +2 -0
- package/dist/__tests__/native-transcript-stream.test.d.ts.map +1 -0
- package/dist/__tests__/native-transcript-stream.test.js +378 -0
- package/dist/__tests__/native-transcript-stream.test.js.map +1 -0
- package/dist/__tests__/network-diagnostics.test.d.ts +2 -0
- package/dist/__tests__/network-diagnostics.test.d.ts.map +1 -0
- package/dist/__tests__/network-diagnostics.test.js +26 -0
- package/dist/__tests__/network-diagnostics.test.js.map +1 -0
- package/dist/__tests__/observable-map.test.d.ts +2 -0
- package/dist/__tests__/observable-map.test.d.ts.map +1 -0
- package/dist/__tests__/observable-map.test.js +54 -0
- package/dist/__tests__/observable-map.test.js.map +1 -0
- package/dist/__tests__/outbox-baseline.bench.test.d.ts +2 -0
- package/dist/__tests__/outbox-baseline.bench.test.d.ts.map +1 -0
- package/dist/__tests__/outbox-baseline.bench.test.js +108 -0
- package/dist/__tests__/outbox-baseline.bench.test.js.map +1 -0
- package/dist/__tests__/provider-auth-preflight.test.d.ts +2 -0
- package/dist/__tests__/provider-auth-preflight.test.d.ts.map +1 -0
- package/dist/__tests__/provider-auth-preflight.test.js +123 -0
- package/dist/__tests__/provider-auth-preflight.test.js.map +1 -0
- package/dist/__tests__/provider-model-discovery.test.d.ts +2 -0
- package/dist/__tests__/provider-model-discovery.test.d.ts.map +1 -0
- package/dist/__tests__/provider-model-discovery.test.js +1071 -0
- package/dist/__tests__/provider-model-discovery.test.js.map +1 -0
- package/dist/__tests__/resource-diagnostics.test.d.ts +2 -0
- package/dist/__tests__/resource-diagnostics.test.d.ts.map +1 -0
- package/dist/__tests__/resource-diagnostics.test.js +138 -0
- package/dist/__tests__/resource-diagnostics.test.js.map +1 -0
- package/dist/__tests__/resume-fallback-env.test.d.ts +2 -0
- package/dist/__tests__/resume-fallback-env.test.d.ts.map +1 -0
- package/dist/__tests__/resume-fallback-env.test.js +28 -0
- package/dist/__tests__/resume-fallback-env.test.js.map +1 -0
- package/dist/__tests__/run-journal.test.d.ts +2 -0
- package/dist/__tests__/run-journal.test.d.ts.map +1 -0
- package/dist/__tests__/run-journal.test.js +121 -0
- package/dist/__tests__/run-journal.test.js.map +1 -0
- package/dist/__tests__/run-start-gate.test.d.ts +2 -0
- package/dist/__tests__/run-start-gate.test.d.ts.map +1 -0
- package/dist/__tests__/run-start-gate.test.js +18 -0
- package/dist/__tests__/run-start-gate.test.js.map +1 -0
- package/dist/__tests__/runtime-capabilities-sync.test.d.ts +2 -0
- package/dist/__tests__/runtime-capabilities-sync.test.d.ts.map +1 -0
- package/dist/__tests__/runtime-capabilities-sync.test.js +66 -0
- package/dist/__tests__/runtime-capabilities-sync.test.js.map +1 -0
- package/dist/__tests__/runtime-config.test.d.ts +2 -0
- package/dist/__tests__/runtime-config.test.d.ts.map +1 -0
- package/dist/__tests__/runtime-config.test.js +137 -0
- package/dist/__tests__/runtime-config.test.js.map +1 -0
- package/dist/__tests__/runtime-presenter-heartbeat.test.d.ts +2 -0
- package/dist/__tests__/runtime-presenter-heartbeat.test.d.ts.map +1 -0
- package/dist/__tests__/runtime-presenter-heartbeat.test.js +253 -0
- package/dist/__tests__/runtime-presenter-heartbeat.test.js.map +1 -0
- package/dist/__tests__/runtime-registration.test.d.ts +2 -0
- package/dist/__tests__/runtime-registration.test.d.ts.map +1 -0
- package/dist/__tests__/runtime-registration.test.js +109 -0
- package/dist/__tests__/runtime-registration.test.js.map +1 -0
- package/dist/__tests__/sandbox-outbox-storage.test.d.ts +2 -0
- package/dist/__tests__/sandbox-outbox-storage.test.d.ts.map +1 -0
- package/dist/__tests__/sandbox-outbox-storage.test.js +81 -0
- package/dist/__tests__/sandbox-outbox-storage.test.js.map +1 -0
- package/dist/__tests__/sandbox-outbox.test.d.ts +2 -0
- package/dist/__tests__/sandbox-outbox.test.d.ts.map +1 -0
- package/dist/__tests__/sandbox-outbox.test.js +300 -0
- package/dist/__tests__/sandbox-outbox.test.js.map +1 -0
- package/dist/__tests__/sandbox-workflow-context.test.d.ts +2 -0
- package/dist/__tests__/sandbox-workflow-context.test.d.ts.map +1 -0
- package/dist/__tests__/sandbox-workflow-context.test.js +600 -0
- package/dist/__tests__/sandbox-workflow-context.test.js.map +1 -0
- package/dist/__tests__/service-manager-deadline.test.d.ts +2 -0
- package/dist/__tests__/service-manager-deadline.test.d.ts.map +1 -0
- package/dist/__tests__/service-manager-deadline.test.js +36 -0
- package/dist/__tests__/service-manager-deadline.test.js.map +1 -0
- package/dist/__tests__/service-manager.test.d.ts +2 -0
- package/dist/__tests__/service-manager.test.d.ts.map +1 -0
- package/dist/__tests__/service-manager.test.js +769 -0
- package/dist/__tests__/service-manager.test.js.map +1 -0
- package/dist/__tests__/service-stop-ownership.test.d.ts +2 -0
- package/dist/__tests__/service-stop-ownership.test.d.ts.map +1 -0
- package/dist/__tests__/service-stop-ownership.test.js +89 -0
- package/dist/__tests__/service-stop-ownership.test.js.map +1 -0
- package/dist/__tests__/skill-invocation.test.d.ts +2 -0
- package/dist/__tests__/skill-invocation.test.d.ts.map +1 -0
- package/dist/__tests__/skill-invocation.test.js +40 -0
- package/dist/__tests__/skill-invocation.test.js.map +1 -0
- package/dist/__tests__/sleep-inhibitor-real.test.d.ts +2 -0
- package/dist/__tests__/sleep-inhibitor-real.test.d.ts.map +1 -0
- package/dist/__tests__/sleep-inhibitor-real.test.js +68 -0
- package/dist/__tests__/sleep-inhibitor-real.test.js.map +1 -0
- package/dist/__tests__/sleep-inhibitor.test.d.ts +2 -0
- package/dist/__tests__/sleep-inhibitor.test.d.ts.map +1 -0
- package/dist/__tests__/sleep-inhibitor.test.js +236 -0
- package/dist/__tests__/sleep-inhibitor.test.js.map +1 -0
- package/dist/__tests__/status-local-workspace.test.d.ts +2 -0
- package/dist/__tests__/status-local-workspace.test.d.ts.map +1 -0
- package/dist/__tests__/status-local-workspace.test.js +121 -0
- package/dist/__tests__/status-local-workspace.test.js.map +1 -0
- package/dist/__tests__/suspension-detector.test.d.ts +2 -0
- package/dist/__tests__/suspension-detector.test.d.ts.map +1 -0
- package/dist/__tests__/suspension-detector.test.js +112 -0
- package/dist/__tests__/suspension-detector.test.js.map +1 -0
- package/dist/__tests__/web-presenter-parent-events.test.d.ts +2 -0
- package/dist/__tests__/web-presenter-parent-events.test.d.ts.map +1 -0
- package/dist/__tests__/web-presenter-parent-events.test.js +168 -0
- package/dist/__tests__/web-presenter-parent-events.test.js.map +1 -0
- package/dist/__tests__/workspace-probe-concurrency.test.d.ts +2 -0
- package/dist/__tests__/workspace-probe-concurrency.test.d.ts.map +1 -0
- package/dist/__tests__/workspace-probe-concurrency.test.js +54 -0
- package/dist/__tests__/workspace-probe-concurrency.test.js.map +1 -0
- package/dist/__tests__/workspace-relocation.test.d.ts +2 -0
- package/dist/__tests__/workspace-relocation.test.d.ts.map +1 -0
- package/dist/__tests__/workspace-relocation.test.js +66 -0
- package/dist/__tests__/workspace-relocation.test.js.map +1 -0
- package/dist/__tests__/workspace-rpc.test.d.ts +2 -0
- package/dist/__tests__/workspace-rpc.test.d.ts.map +1 -0
- package/dist/__tests__/workspace-rpc.test.js +90 -0
- package/dist/__tests__/workspace-rpc.test.js.map +1 -0
- package/dist/__tests__/workspace-run-lease.test.d.ts +2 -0
- package/dist/__tests__/workspace-run-lease.test.d.ts.map +1 -0
- package/dist/__tests__/workspace-run-lease.test.js +331 -0
- package/dist/__tests__/workspace-run-lease.test.js.map +1 -0
- package/dist/__tests__/ws-client-connection.test.d.ts +2 -0
- package/dist/__tests__/ws-client-connection.test.d.ts.map +1 -0
- package/dist/__tests__/ws-client-connection.test.js +295 -0
- package/dist/__tests__/ws-client-connection.test.js.map +1 -0
- package/dist/__tests__/ws-client-heartbeat-volatile.test.d.ts +2 -0
- package/dist/__tests__/ws-client-heartbeat-volatile.test.d.ts.map +1 -0
- package/dist/__tests__/ws-client-heartbeat-volatile.test.js +63 -0
- package/dist/__tests__/ws-client-heartbeat-volatile.test.js.map +1 -0
- package/dist/__tests__/ws-client-heartbeat.integration.test.d.ts +2 -0
- package/dist/__tests__/ws-client-heartbeat.integration.test.d.ts.map +1 -0
- package/dist/__tests__/ws-client-heartbeat.integration.test.js +236 -0
- package/dist/__tests__/ws-client-heartbeat.integration.test.js.map +1 -0
- package/dist/__tests__/ws-client-user-message-ack.integration.test.d.ts +2 -0
- package/dist/__tests__/ws-client-user-message-ack.integration.test.d.ts.map +1 -0
- package/dist/__tests__/ws-client-user-message-ack.integration.test.js +211 -0
- package/dist/__tests__/ws-client-user-message-ack.integration.test.js.map +1 -0
- package/dist/antigravity-api-key-config.d.ts +2 -0
- package/dist/antigravity-api-key-config.d.ts.map +1 -0
- package/dist/antigravity-api-key-config.js +79 -0
- package/dist/antigravity-api-key-config.js.map +1 -0
- package/dist/binding-switch-git.d.ts +26 -0
- package/dist/binding-switch-git.d.ts.map +1 -0
- package/dist/binding-switch-git.js +871 -0
- package/dist/binding-switch-git.js.map +1 -0
- package/dist/cli-ensure-install.d.ts +34 -0
- package/dist/cli-ensure-install.d.ts.map +1 -0
- package/dist/cli-ensure-install.js +154 -0
- package/dist/cli-ensure-install.js.map +1 -0
- package/dist/cli-executable.d.ts +44 -0
- package/dist/cli-executable.d.ts.map +1 -0
- package/dist/cli-executable.js +435 -0
- package/dist/cli-executable.js.map +1 -0
- package/dist/cli-help.d.ts +11 -0
- package/dist/cli-help.d.ts.map +1 -0
- package/dist/cli-help.js +65 -0
- package/dist/cli-help.js.map +1 -0
- package/dist/computer-readiness.d.ts +41 -0
- package/dist/computer-readiness.d.ts.map +1 -0
- package/dist/computer-readiness.js +191 -0
- package/dist/computer-readiness.js.map +1 -0
- package/dist/core-agent.d.ts +32 -0
- package/dist/core-agent.d.ts.map +1 -0
- package/dist/core-agent.js +331 -0
- package/dist/core-agent.js.map +1 -0
- package/dist/daemon-execute.d.ts +42 -0
- package/dist/daemon-execute.d.ts.map +1 -0
- package/dist/daemon-execute.js +666 -0
- package/dist/daemon-execute.js.map +1 -0
- package/dist/daemon-helpers.d.ts +150 -0
- package/dist/daemon-helpers.d.ts.map +1 -0
- package/dist/daemon-helpers.js +157 -0
- package/dist/daemon-helpers.js.map +1 -0
- package/dist/daemon-local-control.d.ts +208 -0
- package/dist/daemon-local-control.d.ts.map +1 -0
- package/dist/daemon-local-control.js +826 -0
- package/dist/daemon-local-control.js.map +1 -0
- package/dist/daemon-local-http.d.ts +57 -0
- package/dist/daemon-local-http.d.ts.map +1 -0
- package/dist/daemon-local-http.js +375 -0
- package/dist/daemon-local-http.js.map +1 -0
- package/dist/daemon-native-hooks.d.ts +17 -0
- package/dist/daemon-native-hooks.d.ts.map +1 -0
- package/dist/daemon-native-hooks.js +54 -0
- package/dist/daemon-native-hooks.js.map +1 -0
- package/dist/daemon-provider-scan.d.ts +33 -0
- package/dist/daemon-provider-scan.d.ts.map +1 -0
- package/dist/daemon-provider-scan.js +187 -0
- package/dist/daemon-provider-scan.js.map +1 -0
- package/dist/daemon-runner-status.d.ts +164 -0
- package/dist/daemon-runner-status.d.ts.map +1 -0
- package/dist/daemon-runner-status.js +424 -0
- package/dist/daemon-runner-status.js.map +1 -0
- package/dist/daemon-start.d.ts +5 -0
- package/dist/daemon-start.d.ts.map +1 -0
- package/dist/daemon-start.js +1313 -0
- package/dist/daemon-start.js.map +1 -0
- package/dist/daemon-workspace.d.ts +36 -0
- package/dist/daemon-workspace.d.ts.map +1 -0
- package/dist/daemon-workspace.js +154 -0
- package/dist/daemon-workspace.js.map +1 -0
- package/dist/daemon.d.ts +59 -0
- package/dist/daemon.d.ts.map +1 -0
- package/dist/daemon.js +681 -0
- package/dist/daemon.js.map +1 -0
- package/dist/event-journal-crypto.d.ts +14 -0
- package/dist/event-journal-crypto.d.ts.map +1 -0
- package/dist/event-journal-crypto.js +89 -0
- package/dist/event-journal-crypto.js.map +1 -0
- package/dist/event-journal-paths.d.ts +10 -0
- package/dist/event-journal-paths.d.ts.map +1 -0
- package/dist/event-journal-paths.js +29 -0
- package/dist/event-journal-paths.js.map +1 -0
- package/dist/event-journal-recovery.d.ts +83 -0
- package/dist/event-journal-recovery.d.ts.map +1 -0
- package/dist/event-journal-recovery.js +333 -0
- package/dist/event-journal-recovery.js.map +1 -0
- package/dist/event-journal-types.d.ts +54 -0
- package/dist/event-journal-types.d.ts.map +1 -0
- package/dist/event-journal-types.js +10 -0
- package/dist/event-journal-types.js.map +1 -0
- package/dist/event-journal-writer.d.ts +44 -0
- package/dist/event-journal-writer.d.ts.map +1 -0
- package/dist/event-journal-writer.js +182 -0
- package/dist/event-journal-writer.js.map +1 -0
- package/dist/event-outbox.d.ts +113 -0
- package/dist/event-outbox.d.ts.map +1 -0
- package/dist/event-outbox.js +707 -0
- package/dist/event-outbox.js.map +1 -0
- package/dist/execution-activity-tracker.d.ts +43 -0
- package/dist/execution-activity-tracker.d.ts.map +1 -0
- package/dist/execution-activity-tracker.js +116 -0
- package/dist/execution-activity-tracker.js.map +1 -0
- package/dist/execution-lease-client.d.ts +62 -0
- package/dist/execution-lease-client.d.ts.map +1 -0
- package/dist/execution-lease-client.js +271 -0
- package/dist/execution-lease-client.js.map +1 -0
- package/dist/fake-provider-cli.d.ts +13 -0
- package/dist/fake-provider-cli.d.ts.map +1 -0
- package/dist/fake-provider-cli.js +53 -0
- package/dist/fake-provider-cli.js.map +1 -0
- package/dist/generated-images.d.ts +2 -0
- package/dist/generated-images.d.ts.map +1 -0
- package/dist/generated-images.js +2 -0
- package/dist/generated-images.js.map +1 -0
- package/dist/index.cjs +47033 -45514
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +224 -0
- package/dist/index.js.map +1 -0
- package/dist/install-command.d.ts +2 -0
- package/dist/install-command.d.ts.map +1 -0
- package/dist/install-command.js +96 -0
- package/dist/install-command.js.map +1 -0
- package/dist/integration-cli.d.ts +14 -0
- package/dist/integration-cli.d.ts.map +1 -0
- package/dist/integration-cli.js +80 -0
- package/dist/integration-cli.js.map +1 -0
- package/dist/lifecycle-logger.d.ts +25 -0
- package/dist/lifecycle-logger.d.ts.map +1 -0
- package/dist/lifecycle-logger.js +73 -0
- package/dist/lifecycle-logger.js.map +1 -0
- package/dist/local-daemon-lifecycle.d.ts +112 -0
- package/dist/local-daemon-lifecycle.d.ts.map +1 -0
- package/dist/local-daemon-lifecycle.js +433 -0
- package/dist/local-daemon-lifecycle.js.map +1 -0
- package/dist/local-git-status.d.ts +14 -0
- package/dist/local-git-status.d.ts.map +1 -0
- package/dist/local-git-status.js +43 -0
- package/dist/local-git-status.js.map +1 -0
- package/dist/managed-mcp.d.ts +7 -0
- package/dist/managed-mcp.d.ts.map +1 -0
- package/dist/managed-mcp.js +16 -0
- package/dist/managed-mcp.js.map +1 -0
- package/dist/mcp-config-adapters.d.ts +57 -0
- package/dist/mcp-config-adapters.d.ts.map +1 -0
- package/dist/mcp-config-adapters.js +929 -0
- package/dist/mcp-config-adapters.js.map +1 -0
- package/dist/mcp-sync.d.ts +44 -0
- package/dist/mcp-sync.d.ts.map +1 -0
- package/dist/mcp-sync.js +68 -0
- package/dist/mcp-sync.js.map +1 -0
- package/dist/model-scan-runner.d.ts +15 -0
- package/dist/model-scan-runner.d.ts.map +1 -0
- package/dist/model-scan-runner.js +56 -0
- package/dist/model-scan-runner.js.map +1 -0
- package/dist/native-hook-command.d.ts +31 -0
- package/dist/native-hook-command.d.ts.map +1 -0
- package/dist/native-hook-command.js +289 -0
- package/dist/native-hook-command.js.map +1 -0
- package/dist/native-hook-config.d.ts +43 -0
- package/dist/native-hook-config.d.ts.map +1 -0
- package/dist/native-hook-config.js +601 -0
- package/dist/native-hook-config.js.map +1 -0
- package/dist/native-hook-drain.d.ts +34 -0
- package/dist/native-hook-drain.d.ts.map +1 -0
- package/dist/native-hook-drain.js +83 -0
- package/dist/native-hook-drain.js.map +1 -0
- package/dist/native-hook-inbox.d.ts +40 -0
- package/dist/native-hook-inbox.d.ts.map +1 -0
- package/dist/native-hook-inbox.js +217 -0
- package/dist/native-hook-inbox.js.map +1 -0
- package/dist/native-project-config.d.ts +11 -0
- package/dist/native-project-config.d.ts.map +1 -0
- package/dist/native-project-config.js +49 -0
- package/dist/native-project-config.js.map +1 -0
- package/dist/native-session.d.ts +20 -0
- package/dist/native-session.d.ts.map +1 -0
- package/dist/native-session.js +213 -0
- package/dist/native-session.js.map +1 -0
- package/dist/native-stream-journal.d.ts +22 -0
- package/dist/native-stream-journal.d.ts.map +1 -0
- package/dist/native-stream-journal.js +98 -0
- package/dist/native-stream-journal.js.map +1 -0
- package/dist/native-stream-outbox.d.ts +40 -0
- package/dist/native-stream-outbox.d.ts.map +1 -0
- package/dist/native-stream-outbox.js +358 -0
- package/dist/native-stream-outbox.js.map +1 -0
- package/dist/native-stream-platform.d.ts +4 -0
- package/dist/native-stream-platform.d.ts.map +1 -0
- package/dist/native-stream-platform.js +11 -0
- package/dist/native-stream-platform.js.map +1 -0
- package/dist/native-transcript-cursor.d.ts +33 -0
- package/dist/native-transcript-cursor.d.ts.map +1 -0
- package/dist/native-transcript-cursor.js +108 -0
- package/dist/native-transcript-cursor.js.map +1 -0
- package/dist/native-transcript-stream.d.ts +20 -0
- package/dist/native-transcript-stream.d.ts.map +1 -0
- package/dist/native-transcript-stream.js +438 -0
- package/dist/native-transcript-stream.js.map +1 -0
- package/dist/network-diagnostics.d.ts +8 -0
- package/dist/network-diagnostics.d.ts.map +1 -0
- package/dist/network-diagnostics.js +56 -0
- package/dist/network-diagnostics.js.map +1 -0
- package/dist/observable-map.d.ts +13 -0
- package/dist/observable-map.d.ts.map +1 -0
- package/dist/observable-map.js +30 -0
- package/dist/observable-map.js.map +1 -0
- package/dist/provider-auth-preflight.d.ts +19 -0
- package/dist/provider-auth-preflight.d.ts.map +1 -0
- package/dist/provider-auth-preflight.js +107 -0
- package/dist/provider-auth-preflight.js.map +1 -0
- package/dist/provider-model-discovery.d.ts +33 -0
- package/dist/provider-model-discovery.d.ts.map +1 -0
- package/dist/provider-model-discovery.js +731 -0
- package/dist/provider-model-discovery.js.map +1 -0
- package/dist/resource-diagnostics.d.ts +21 -0
- package/dist/resource-diagnostics.d.ts.map +1 -0
- package/dist/resource-diagnostics.js +161 -0
- package/dist/resource-diagnostics.js.map +1 -0
- package/dist/resume-fallback-env.d.ts +3 -0
- package/dist/resume-fallback-env.d.ts.map +1 -0
- package/dist/resume-fallback-env.js +14 -0
- package/dist/resume-fallback-env.js.map +1 -0
- package/dist/run-journal.d.ts +51 -0
- package/dist/run-journal.d.ts.map +1 -0
- package/dist/run-journal.js +193 -0
- package/dist/run-journal.js.map +1 -0
- package/dist/runtime-backends.d.ts +2 -0
- package/dist/runtime-backends.d.ts.map +1 -0
- package/dist/runtime-backends.js +2 -0
- package/dist/runtime-backends.js.map +1 -0
- package/dist/runtime-capabilities-sync.d.ts +40 -0
- package/dist/runtime-capabilities-sync.d.ts.map +1 -0
- package/dist/runtime-capabilities-sync.js +56 -0
- package/dist/runtime-capabilities-sync.js.map +1 -0
- package/dist/runtime-config.d.ts +26 -0
- package/dist/runtime-config.d.ts.map +1 -0
- package/dist/runtime-config.js +170 -0
- package/dist/runtime-config.js.map +1 -0
- package/dist/runtime-presenter.d.ts +81 -0
- package/dist/runtime-presenter.d.ts.map +1 -0
- package/dist/runtime-presenter.js +422 -0
- package/dist/runtime-presenter.js.map +1 -0
- package/dist/runtime-registration.d.ts +40 -0
- package/dist/runtime-registration.d.ts.map +1 -0
- package/dist/runtime-registration.js +143 -0
- package/dist/runtime-registration.js.map +1 -0
- package/dist/sandbox-outbox-storage.d.ts +13 -0
- package/dist/sandbox-outbox-storage.d.ts.map +1 -0
- package/dist/sandbox-outbox-storage.js +98 -0
- package/dist/sandbox-outbox-storage.js.map +1 -0
- package/dist/sandbox-outbox.d.ts +115 -0
- package/dist/sandbox-outbox.d.ts.map +1 -0
- package/dist/sandbox-outbox.js +213 -0
- package/dist/sandbox-outbox.js.map +1 -0
- package/dist/sandbox.d.ts +34 -0
- package/dist/sandbox.d.ts.map +1 -0
- package/dist/sandbox.js +469 -0
- package/dist/sandbox.js.map +1 -0
- package/dist/service-manager.d.ts +113 -0
- package/dist/service-manager.d.ts.map +1 -0
- package/dist/service-manager.js +1065 -0
- package/dist/service-manager.js.map +1 -0
- package/dist/skills/__tests__/local-skill-source.test.d.ts +2 -0
- package/dist/skills/__tests__/local-skill-source.test.d.ts.map +1 -0
- package/dist/skills/__tests__/local-skill-source.test.js +373 -0
- package/dist/skills/__tests__/local-skill-source.test.js.map +1 -0
- package/dist/skills/__tests__/managed-skill-store.test.d.ts +2 -0
- package/dist/skills/__tests__/managed-skill-store.test.d.ts.map +1 -0
- package/dist/skills/__tests__/managed-skill-store.test.js +114 -0
- package/dist/skills/__tests__/managed-skill-store.test.js.map +1 -0
- package/dist/skills/__tests__/runtime-skill-coordinator.test.d.ts +2 -0
- package/dist/skills/__tests__/runtime-skill-coordinator.test.d.ts.map +1 -0
- package/dist/skills/__tests__/runtime-skill-coordinator.test.js +251 -0
- package/dist/skills/__tests__/runtime-skill-coordinator.test.js.map +1 -0
- package/dist/skills/__tests__/runtime-skill-manager.test.d.ts +2 -0
- package/dist/skills/__tests__/runtime-skill-manager.test.d.ts.map +1 -0
- package/dist/skills/__tests__/runtime-skill-manager.test.js +664 -0
- package/dist/skills/__tests__/runtime-skill-manager.test.js.map +1 -0
- package/dist/skills/__tests__/skill-bundle.test.d.ts +2 -0
- package/dist/skills/__tests__/skill-bundle.test.d.ts.map +1 -0
- package/dist/skills/__tests__/skill-bundle.test.js +42 -0
- package/dist/skills/__tests__/skill-bundle.test.js.map +1 -0
- package/dist/skills/__tests__/skill-control-client.test.d.ts +2 -0
- package/dist/skills/__tests__/skill-control-client.test.d.ts.map +1 -0
- package/dist/skills/__tests__/skill-control-client.test.js +49 -0
- package/dist/skills/__tests__/skill-control-client.test.js.map +1 -0
- package/dist/skills/__tests__/skill-source-config.test.d.ts +2 -0
- package/dist/skills/__tests__/skill-source-config.test.d.ts.map +1 -0
- package/dist/skills/__tests__/skill-source-config.test.js +295 -0
- package/dist/skills/__tests__/skill-source-config.test.js.map +1 -0
- package/dist/skills/local-skill-source.d.ts +77 -0
- package/dist/skills/local-skill-source.d.ts.map +1 -0
- package/dist/skills/local-skill-source.js +660 -0
- package/dist/skills/local-skill-source.js.map +1 -0
- package/dist/skills/managed-skill-store.d.ts +44 -0
- package/dist/skills/managed-skill-store.d.ts.map +1 -0
- package/dist/skills/managed-skill-store.js +160 -0
- package/dist/skills/managed-skill-store.js.map +1 -0
- package/dist/skills/runtime-skill-coordinator.d.ts +35 -0
- package/dist/skills/runtime-skill-coordinator.d.ts.map +1 -0
- package/dist/skills/runtime-skill-coordinator.js +166 -0
- package/dist/skills/runtime-skill-coordinator.js.map +1 -0
- package/dist/skills/runtime-skill-manager.d.ts +89 -0
- package/dist/skills/runtime-skill-manager.d.ts.map +1 -0
- package/dist/skills/runtime-skill-manager.js +934 -0
- package/dist/skills/runtime-skill-manager.js.map +1 -0
- package/dist/skills/skill-bundle.d.ts +2 -0
- package/dist/skills/skill-bundle.d.ts.map +1 -0
- package/dist/skills/skill-bundle.js +2 -0
- package/dist/skills/skill-bundle.js.map +1 -0
- package/dist/skills/skill-cli.d.ts +2 -0
- package/dist/skills/skill-cli.d.ts.map +1 -0
- package/dist/skills/skill-cli.js +81 -0
- package/dist/skills/skill-cli.js.map +1 -0
- package/dist/skills/skill-control-client.d.ts +20 -0
- package/dist/skills/skill-control-client.d.ts.map +1 -0
- package/dist/skills/skill-control-client.js +56 -0
- package/dist/skills/skill-control-client.js.map +1 -0
- package/dist/skills/skill-invocation.d.ts +10 -0
- package/dist/skills/skill-invocation.d.ts.map +1 -0
- package/dist/skills/skill-invocation.js +24 -0
- package/dist/skills/skill-invocation.js.map +1 -0
- package/dist/sleep-inhibitor.d.ts +32 -0
- package/dist/sleep-inhibitor.d.ts.map +1 -0
- package/dist/sleep-inhibitor.js +297 -0
- package/dist/sleep-inhibitor.js.map +1 -0
- package/dist/suspension-detector.d.ts +24 -0
- package/dist/suspension-detector.d.ts.map +1 -0
- package/dist/suspension-detector.js +59 -0
- package/dist/suspension-detector.js.map +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/dist/web-presenter.d.ts +52 -0
- package/dist/web-presenter.d.ts.map +1 -0
- package/dist/web-presenter.js +264 -0
- package/dist/web-presenter.js.map +1 -0
- package/dist/workspace-relocation.d.ts +22 -0
- package/dist/workspace-relocation.d.ts.map +1 -0
- package/dist/workspace-relocation.js +90 -0
- package/dist/workspace-relocation.js.map +1 -0
- package/dist/workspace-rpc.d.ts +2 -0
- package/dist/workspace-rpc.d.ts.map +1 -0
- package/dist/workspace-rpc.js +15 -0
- package/dist/workspace-rpc.js.map +1 -0
- package/dist/workspace-run-lease.d.ts +116 -0
- package/dist/workspace-run-lease.d.ts.map +1 -0
- package/dist/workspace-run-lease.js +320 -0
- package/dist/workspace-run-lease.js.map +1 -0
- package/dist/ws-client.d.ts +168 -0
- package/dist/ws-client.d.ts.map +1 -0
- package/dist/ws-client.js +440 -0
- package/dist/ws-client.js.map +1 -0
- package/package.json +4 -3
|
@@ -0,0 +1,1065 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync, } from "node:fs";
|
|
4
|
+
import { homedir, platform, userInfo } from "node:os";
|
|
5
|
+
import { dirname, join, resolve, win32 } from "node:path";
|
|
6
|
+
import { acquireLocalDaemonMaintenanceLease, inspectLocalDaemonRunJournal, probeLocalDaemonEndpoint, readLocalDaemonOwnerLease, releaseLocalDaemonMaintenanceLease, requestLocalDaemonShutdown, } from "./daemon-local-control.js";
|
|
7
|
+
import { configExistsAtPath, resolveAgentConfigDirectory, resolveAgentConfigPath, resolveEndpointProfileFromArgs, } from "./runtime-config.js";
|
|
8
|
+
const SERVICE_LABEL = "ai.tryalan.agent";
|
|
9
|
+
const SYSTEMD_UNIT = "alan-agent.service";
|
|
10
|
+
const WINDOWS_TASK = "Alan Agent";
|
|
11
|
+
const STOP_POLL_INTERVAL_MS = 200;
|
|
12
|
+
function xml(value) {
|
|
13
|
+
return value
|
|
14
|
+
.replaceAll("&", "&")
|
|
15
|
+
.replaceAll("<", "<")
|
|
16
|
+
.replaceAll(">", ">")
|
|
17
|
+
.replaceAll('"', """)
|
|
18
|
+
.replaceAll("'", "'");
|
|
19
|
+
}
|
|
20
|
+
function systemdArg(value) {
|
|
21
|
+
return `"${value.replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`;
|
|
22
|
+
}
|
|
23
|
+
function powershellLiteral(value) {
|
|
24
|
+
return `'${value.replaceAll("'", "''")}'`;
|
|
25
|
+
}
|
|
26
|
+
function powershellCommand(script, tolerateFailure = false) {
|
|
27
|
+
return {
|
|
28
|
+
command: "powershell.exe",
|
|
29
|
+
args: ["-NoProfile", "-NonInteractive", "-Command", script],
|
|
30
|
+
tolerateFailure,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function windowsCommandLineArgument(value) {
|
|
34
|
+
if (value && !/[\s"]/u.test(value))
|
|
35
|
+
return value;
|
|
36
|
+
const escaped = value
|
|
37
|
+
.replace(/(\\*)"/gu, (_match, slashes) => `${slashes}${slashes}\\"`)
|
|
38
|
+
.replace(/\\+$/u, (slashes) => `${slashes}${slashes}`);
|
|
39
|
+
return `"${escaped}"`;
|
|
40
|
+
}
|
|
41
|
+
function serviceNames(profile) {
|
|
42
|
+
if (profile === "production") {
|
|
43
|
+
return { launchd: SERVICE_LABEL, systemd: SYSTEMD_UNIT, windows: WINDOWS_TASK };
|
|
44
|
+
}
|
|
45
|
+
const suffix = profile === "custom" ? "prod" : profile;
|
|
46
|
+
const title = `${suffix[0]?.toUpperCase()}${suffix.slice(1)}`;
|
|
47
|
+
return {
|
|
48
|
+
launchd: `${SERVICE_LABEL}.${suffix}`,
|
|
49
|
+
systemd: `alan-agent-${suffix}.service`,
|
|
50
|
+
windows: `${WINDOWS_TASK} ${title}`,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export function buildDaemonServicePlan(input) {
|
|
54
|
+
const daemonArgs = [input.nodeExecutable, input.cliEntry, "daemon", "--profile", input.profile];
|
|
55
|
+
const names = serviceNames(input.profile);
|
|
56
|
+
if (input.platform === "darwin") {
|
|
57
|
+
const userId = input.userId ?? process.getuid?.();
|
|
58
|
+
if (userId === undefined)
|
|
59
|
+
throw new Error("Cannot determine the current macOS user ID");
|
|
60
|
+
const domain = `gui/${userId}`;
|
|
61
|
+
const serviceTarget = `${domain}/${names.launchd}`;
|
|
62
|
+
const manifestPath = join(input.homeDir, "Library", "LaunchAgents", `${names.launchd}.plist`);
|
|
63
|
+
const logDir = join(resolveAgentConfigDirectory(input.profile, input.homeDir), "logs");
|
|
64
|
+
const programArguments = daemonArgs.map((arg) => ` <string>${xml(arg)}</string>`).join("\n");
|
|
65
|
+
const environmentEntries = Object.entries(input.environment ?? {})
|
|
66
|
+
.map(([key, value]) => ` <key>${xml(key)}</key>\n <string>${xml(value)}</string>`)
|
|
67
|
+
.join("\n");
|
|
68
|
+
const environmentBlock = environmentEntries
|
|
69
|
+
? ` <key>EnvironmentVariables</key>\n <dict>\n${environmentEntries}\n </dict>\n`
|
|
70
|
+
: "";
|
|
71
|
+
const manifest = `<?xml version="1.0" encoding="UTF-8"?>
|
|
72
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
73
|
+
<plist version="1.0">
|
|
74
|
+
<dict>
|
|
75
|
+
<key>Label</key>
|
|
76
|
+
<string>${names.launchd}</string>
|
|
77
|
+
<key>ProgramArguments</key>
|
|
78
|
+
<array>
|
|
79
|
+
${programArguments}
|
|
80
|
+
</array>
|
|
81
|
+
${environmentBlock} <key>RunAtLoad</key>
|
|
82
|
+
<true/>
|
|
83
|
+
<key>KeepAlive</key>
|
|
84
|
+
<dict>
|
|
85
|
+
<key>SuccessfulExit</key>
|
|
86
|
+
<false/>
|
|
87
|
+
</dict>
|
|
88
|
+
<key>ThrottleInterval</key>
|
|
89
|
+
<integer>5</integer>
|
|
90
|
+
<key>StandardOutPath</key>
|
|
91
|
+
<string>${xml(join(logDir, "daemon.log"))}</string>
|
|
92
|
+
<key>StandardErrorPath</key>
|
|
93
|
+
<string>${xml(join(logDir, "daemon-error.log"))}</string>
|
|
94
|
+
</dict>
|
|
95
|
+
</plist>
|
|
96
|
+
`;
|
|
97
|
+
return {
|
|
98
|
+
platform: "darwin",
|
|
99
|
+
manifestPath,
|
|
100
|
+
manifest,
|
|
101
|
+
logDirectory: logDir,
|
|
102
|
+
loadDefinitionCommands: [
|
|
103
|
+
{
|
|
104
|
+
command: "launchctl",
|
|
105
|
+
args: ["bootstrap", domain, manifestPath],
|
|
106
|
+
tolerateFailure: true,
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
reloadDefinitionCommands: [
|
|
110
|
+
{
|
|
111
|
+
command: "launchctl",
|
|
112
|
+
args: ["bootout", domain, manifestPath],
|
|
113
|
+
tolerateFailure: true,
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
command: "launchctl",
|
|
117
|
+
args: ["bootstrap", domain, manifestPath],
|
|
118
|
+
tolerateFailure: false,
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
enableCommands: [
|
|
122
|
+
{
|
|
123
|
+
command: "launchctl",
|
|
124
|
+
args: ["enable", serviceTarget],
|
|
125
|
+
tolerateFailure: true,
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
startCommands: [
|
|
129
|
+
{
|
|
130
|
+
command: "launchctl",
|
|
131
|
+
args: ["kickstart", serviceTarget],
|
|
132
|
+
tolerateFailure: false,
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
stopCommands: [
|
|
136
|
+
{
|
|
137
|
+
command: "launchctl",
|
|
138
|
+
args: ["kill", "SIGTERM", serviceTarget],
|
|
139
|
+
tolerateFailure: true,
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
forceStopCommands: [
|
|
143
|
+
{
|
|
144
|
+
command: "launchctl",
|
|
145
|
+
args: ["bootout", domain, manifestPath],
|
|
146
|
+
tolerateFailure: true,
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
uninstallCommands: [
|
|
150
|
+
{
|
|
151
|
+
command: "launchctl",
|
|
152
|
+
args: ["bootout", domain, manifestPath],
|
|
153
|
+
tolerateFailure: true,
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
statusCommand: {
|
|
157
|
+
command: "launchctl",
|
|
158
|
+
args: ["print", serviceTarget],
|
|
159
|
+
tolerateFailure: true,
|
|
160
|
+
},
|
|
161
|
+
isActiveCommand: {
|
|
162
|
+
command: "launchctl",
|
|
163
|
+
args: ["print", serviceTarget],
|
|
164
|
+
tolerateFailure: true,
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
if (input.platform === "linux") {
|
|
169
|
+
const manifestPath = join(input.homeDir, ".config", "systemd", "user", names.systemd);
|
|
170
|
+
const environmentLines = Object.entries(input.environment ?? {})
|
|
171
|
+
.map(([key, value]) => `Environment=${systemdArg(`${key}=${value}`)}`)
|
|
172
|
+
.join("\n");
|
|
173
|
+
const manifest = `[Unit]
|
|
174
|
+
Description=Alan local agent daemon
|
|
175
|
+
After=network-online.target
|
|
176
|
+
Wants=network-online.target
|
|
177
|
+
StartLimitIntervalSec=300
|
|
178
|
+
StartLimitBurst=3
|
|
179
|
+
|
|
180
|
+
[Service]
|
|
181
|
+
Type=simple
|
|
182
|
+
${environmentLines ? `${environmentLines}\n` : ""}ExecStart=${daemonArgs.map(systemdArg).join(" ")}
|
|
183
|
+
Restart=on-failure
|
|
184
|
+
RestartSec=5
|
|
185
|
+
|
|
186
|
+
[Install]
|
|
187
|
+
WantedBy=default.target
|
|
188
|
+
`;
|
|
189
|
+
return {
|
|
190
|
+
platform: "linux",
|
|
191
|
+
manifestPath,
|
|
192
|
+
manifest,
|
|
193
|
+
logDirectory: null,
|
|
194
|
+
loadDefinitionCommands: [
|
|
195
|
+
{
|
|
196
|
+
command: "systemctl",
|
|
197
|
+
args: ["--user", "daemon-reload"],
|
|
198
|
+
tolerateFailure: false,
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
reloadDefinitionCommands: [
|
|
202
|
+
{
|
|
203
|
+
command: "systemctl",
|
|
204
|
+
args: ["--user", "daemon-reload"],
|
|
205
|
+
tolerateFailure: false,
|
|
206
|
+
},
|
|
207
|
+
],
|
|
208
|
+
enableCommands: [
|
|
209
|
+
{
|
|
210
|
+
command: "systemctl",
|
|
211
|
+
args: ["--user", "enable", names.systemd],
|
|
212
|
+
tolerateFailure: false,
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
startCommands: [
|
|
216
|
+
{
|
|
217
|
+
command: "systemctl",
|
|
218
|
+
args: ["--user", "start", names.systemd],
|
|
219
|
+
tolerateFailure: false,
|
|
220
|
+
},
|
|
221
|
+
],
|
|
222
|
+
stopCommands: [
|
|
223
|
+
{
|
|
224
|
+
command: "systemctl",
|
|
225
|
+
args: ["--user", "stop", names.systemd],
|
|
226
|
+
tolerateFailure: true,
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
forceStopCommands: [],
|
|
230
|
+
uninstallCommands: [
|
|
231
|
+
{
|
|
232
|
+
command: "systemctl",
|
|
233
|
+
args: ["--user", "disable", "--now", names.systemd],
|
|
234
|
+
tolerateFailure: true,
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
command: "systemctl",
|
|
238
|
+
args: ["--user", "daemon-reload"],
|
|
239
|
+
tolerateFailure: false,
|
|
240
|
+
},
|
|
241
|
+
],
|
|
242
|
+
statusCommand: {
|
|
243
|
+
command: "systemctl",
|
|
244
|
+
args: ["--user", "status", names.systemd, "--no-pager"],
|
|
245
|
+
tolerateFailure: true,
|
|
246
|
+
},
|
|
247
|
+
isActiveCommand: {
|
|
248
|
+
command: "systemctl",
|
|
249
|
+
args: ["--user", "is-active", names.systemd],
|
|
250
|
+
tolerateFailure: true,
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
const logDir = win32.join(resolveAgentConfigDirectory(input.profile, input.homeDir), "logs");
|
|
255
|
+
const legacyEnvironmentPrefix = Object.entries(input.environment ?? {})
|
|
256
|
+
.map(([key, value]) => `$env:${key} = ${powershellLiteral(value)}`)
|
|
257
|
+
.join("; ");
|
|
258
|
+
const legacyDirectArguments = [input.cliEntry, "daemon", "--profile", input.profile]
|
|
259
|
+
.map((part) => (part.includes(" ") ? `"${part}"` : part))
|
|
260
|
+
.join(" ");
|
|
261
|
+
const legacyExecutable = legacyEnvironmentPrefix ? "powershell.exe" : input.nodeExecutable;
|
|
262
|
+
const legacyArguments = legacyEnvironmentPrefix
|
|
263
|
+
? `-NoProfile -NonInteractive -WindowStyle Hidden -Command "${legacyEnvironmentPrefix}; & ${powershellLiteral(input.nodeExecutable)} ${powershellLiteral(input.cliEntry)} daemon --profile ${input.profile}"`
|
|
264
|
+
: legacyDirectArguments;
|
|
265
|
+
const daemonArguments = [input.cliEntry, "daemon", "--profile", input.profile]
|
|
266
|
+
.map(windowsCommandLineArgument)
|
|
267
|
+
.join(" ");
|
|
268
|
+
const environmentStatements = Object.entries(input.environment ?? {}).map(([key, value]) => `$startInfo.EnvironmentVariables[${powershellLiteral(key)}] = ${powershellLiteral(value)}`);
|
|
269
|
+
const launcherScript = [
|
|
270
|
+
"$ErrorActionPreference = 'Stop'",
|
|
271
|
+
"$startInfo = [System.Diagnostics.ProcessStartInfo]::new()",
|
|
272
|
+
`$startInfo.FileName = ${powershellLiteral(input.nodeExecutable)}`,
|
|
273
|
+
`$startInfo.Arguments = ${powershellLiteral(daemonArguments)}`,
|
|
274
|
+
`$startInfo.WorkingDirectory = ${powershellLiteral(win32.dirname(input.cliEntry))}`,
|
|
275
|
+
"$startInfo.UseShellExecute = $false",
|
|
276
|
+
"$startInfo.CreateNoWindow = $true",
|
|
277
|
+
"$startInfo.RedirectStandardOutput = $true",
|
|
278
|
+
"$startInfo.RedirectStandardError = $true",
|
|
279
|
+
...environmentStatements,
|
|
280
|
+
`$stdout = [System.IO.File]::Open(${powershellLiteral(win32.join(logDir, "daemon-launcher.log"))}, [System.IO.FileMode]::Create, [System.IO.FileAccess]::Write, [System.IO.FileShare]::ReadWrite)`,
|
|
281
|
+
`$stderr = [System.IO.File]::Open(${powershellLiteral(win32.join(logDir, "daemon-launcher-error.log"))}, [System.IO.FileMode]::Create, [System.IO.FileAccess]::Write, [System.IO.FileShare]::ReadWrite)`,
|
|
282
|
+
"$process = [System.Diagnostics.Process]::new()",
|
|
283
|
+
"$process.StartInfo = $startInfo",
|
|
284
|
+
"try { if (-not $process.Start()) { throw 'Alan daemon process did not start' }; $stdoutCopy = $process.StandardOutput.BaseStream.CopyToAsync($stdout); $stderrCopy = $process.StandardError.BaseStream.CopyToAsync($stderr); $process.WaitForExit(); [System.Threading.Tasks.Task]::WaitAll([System.Threading.Tasks.Task[]]@($stdoutCopy, $stderrCopy)); $exitCode = $process.ExitCode } finally { $stdout.Dispose(); $stderr.Dispose(); $process.Dispose() }",
|
|
285
|
+
"exit $exitCode",
|
|
286
|
+
].join("; ");
|
|
287
|
+
const executable = powershellLiteral("powershell.exe");
|
|
288
|
+
const launcherArguments = `-NoProfile -NonInteractive -WindowStyle Hidden -EncodedCommand ${Buffer.from(launcherScript, "utf16le").toString("base64")}`;
|
|
289
|
+
const settingsScript = "New-ScheduledTaskSettingsSet -RestartCount 3 -RestartInterval (New-TimeSpan -Minutes 1) -ExecutionTimeLimit ([TimeSpan]::Zero) -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries";
|
|
290
|
+
const ownerMarker = `Alan daemon owner v1 ${createHash("sha256")
|
|
291
|
+
.update(JSON.stringify({
|
|
292
|
+
executable: input.nodeExecutable,
|
|
293
|
+
cliEntry: input.cliEntry,
|
|
294
|
+
profile: input.profile,
|
|
295
|
+
taskBaseName: names.windows,
|
|
296
|
+
}))
|
|
297
|
+
.digest("hex")}`;
|
|
298
|
+
const definitionMarker = `${ownerMarker}; definition v3 ${createHash("sha256")
|
|
299
|
+
.update(JSON.stringify({
|
|
300
|
+
executable: "powershell.exe",
|
|
301
|
+
launcherArguments,
|
|
302
|
+
workingDirectory: win32.dirname(input.cliEntry),
|
|
303
|
+
settingsScript,
|
|
304
|
+
taskBaseName: names.windows,
|
|
305
|
+
}))
|
|
306
|
+
.digest("hex")}`;
|
|
307
|
+
const windowsDefinitionContext = [
|
|
308
|
+
`$expectedLauncherArguments = ${powershellLiteral(launcherArguments)}`,
|
|
309
|
+
`$expectedWorkingDirectory = ${powershellLiteral(win32.dirname(input.cliEntry))}`,
|
|
310
|
+
`$expectedOwnerMarker = ${powershellLiteral(`${ownerMarker};`)}`,
|
|
311
|
+
`$expectedDefinitionMarker = ${powershellLiteral(definitionMarker)}`,
|
|
312
|
+
`$expectedLegacyExecutable = ${powershellLiteral(legacyExecutable)}`,
|
|
313
|
+
`$expectedLegacyArguments = ${powershellLiteral(legacyArguments)}`,
|
|
314
|
+
].join("; ");
|
|
315
|
+
const taskContext = [
|
|
316
|
+
"$currentIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()",
|
|
317
|
+
"$currentUser = $currentIdentity.Name",
|
|
318
|
+
"$currentSid = $currentIdentity.User.Value",
|
|
319
|
+
`$taskName = ${powershellLiteral(names.windows)} + ' ' + $currentSid`,
|
|
320
|
+
].join("; ");
|
|
321
|
+
const resolveTaskSid = "function Resolve-TaskSid([string]$value) { try { return ([System.Security.Principal.NTAccount]$value).Translate([System.Security.Principal.SecurityIdentifier]).Value } catch { try { return [System.Security.Principal.SecurityIdentifier]::new($value).Value } catch { return '' } } }";
|
|
322
|
+
const currentLookup = "$task = @(Get-ScheduledTask -ErrorAction Stop | Where-Object { $_.TaskPath -eq '\\' -and $_.TaskName -eq $taskName })[0]";
|
|
323
|
+
const checkCurrentOwnership = [
|
|
324
|
+
currentLookup,
|
|
325
|
+
"$currentOwned = $false",
|
|
326
|
+
"if ($null -ne $task) { try {",
|
|
327
|
+
"$taskAction = @($task.Actions)[0]",
|
|
328
|
+
"$currentOwned = @($task.Actions).Count -eq 1 -and (Resolve-TaskSid ([string]$task.Principal.UserId)) -eq $currentSid -and (([string]$task.Description).StartsWith($expectedOwnerMarker, [System.StringComparison]::Ordinal) -or (([string]$taskAction.Execute) -ieq 'powershell.exe' -and ([string]$taskAction.Arguments) -ceq $expectedLauncherArguments -and ([string]$taskAction.WorkingDirectory) -ieq $expectedWorkingDirectory))",
|
|
329
|
+
"} catch { $currentOwned = $false } }",
|
|
330
|
+
].join("; ");
|
|
331
|
+
const legacyLookup = `$legacyTask = @(Get-ScheduledTask -ErrorAction Stop | Where-Object { $_.TaskPath -eq '\\' -and $_.TaskName -eq ${powershellLiteral(names.windows)} })[0]`;
|
|
332
|
+
const checkLegacyOwnership = [
|
|
333
|
+
legacyLookup,
|
|
334
|
+
"$legacyOwned = $false",
|
|
335
|
+
"$legacyState = 'Missing'",
|
|
336
|
+
"if ($null -ne $legacyTask) { try {",
|
|
337
|
+
"$legacyState = [string]$legacyTask.State",
|
|
338
|
+
"$legacySid = Resolve-TaskSid ([string]$legacyTask.Principal.UserId)",
|
|
339
|
+
"$legacyAction = @($legacyTask.Actions)[0]",
|
|
340
|
+
"if ($null -ne $legacyAction) {",
|
|
341
|
+
"$legacyOwned = $legacySid -eq $currentSid -and @($legacyTask.Actions).Count -eq 1 -and ((([string]$legacyAction.Execute) -ieq $expectedLegacyExecutable -and ([string]$legacyAction.Arguments) -ieq $expectedLegacyArguments -and ([string]$legacyAction.WorkingDirectory) -eq '') -or (([string]$legacyAction.Execute) -ieq 'powershell.exe' -and ([string]$legacyAction.Arguments) -ceq $expectedLauncherArguments -and ([string]$legacyAction.WorkingDirectory) -ieq $expectedWorkingDirectory))",
|
|
342
|
+
"}",
|
|
343
|
+
"} catch { $legacyOwned = $false } }",
|
|
344
|
+
].join("; ");
|
|
345
|
+
const assertOwnedTasks = [
|
|
346
|
+
checkCurrentOwnership,
|
|
347
|
+
checkLegacyOwnership,
|
|
348
|
+
`if ($null -ne $task -and -not $currentOwned) { throw ${powershellLiteral(`${names.windows} task is not owned by this Alan installation`)} }`,
|
|
349
|
+
`if ($null -ne $legacyTask -and -not $legacyOwned) { throw ${powershellLiteral(`Legacy ${names.windows} task is not owned by this Alan installation`)} }`,
|
|
350
|
+
"if ($null -ne $task -and @('Ready', 'Disabled', 'Queued') -notcontains ([string]$task.State)) { throw 'Alan daemon task became active or has unknown state' }",
|
|
351
|
+
"if ($null -ne $legacyTask -and @('Ready', 'Disabled', 'Queued') -notcontains ([string]$legacyTask.State)) { throw 'Legacy Alan daemon task became active or has unknown state' }",
|
|
352
|
+
].join("; ");
|
|
353
|
+
const cleanupLegacyTask = [
|
|
354
|
+
checkLegacyOwnership,
|
|
355
|
+
`if ($null -ne $legacyTask -and -not $legacyOwned) { throw ${powershellLiteral(`Legacy ${names.windows} task is not owned by this Alan installation`)} }`,
|
|
356
|
+
"if ($null -ne $legacyTask -and @('Ready', 'Disabled', 'Queued') -notcontains ([string]$legacyTask.State)) { throw 'Legacy Alan daemon task became active or has unknown state' }",
|
|
357
|
+
`if ($null -ne $legacyTask) { Unregister-ScheduledTask -TaskName ${powershellLiteral(names.windows)} -TaskPath '\\' -Confirm:$false -ErrorAction Stop }`,
|
|
358
|
+
`$legacyRemaining = @(Get-ScheduledTask -ErrorAction Stop | Where-Object { $_.TaskPath -eq '\\' -and $_.TaskName -eq ${powershellLiteral(names.windows)} })[0]`,
|
|
359
|
+
"if ($null -ne $legacyRemaining) { throw 'Legacy Alan daemon task still exists after migration' }",
|
|
360
|
+
].join("; ");
|
|
361
|
+
const registerScript = [
|
|
362
|
+
taskContext,
|
|
363
|
+
resolveTaskSid,
|
|
364
|
+
windowsDefinitionContext,
|
|
365
|
+
`$action = New-ScheduledTaskAction -Execute ${executable} -Argument $expectedLauncherArguments -WorkingDirectory $expectedWorkingDirectory`,
|
|
366
|
+
"$trigger = New-ScheduledTaskTrigger -AtLogOn -User $currentUser",
|
|
367
|
+
"$principal = New-ScheduledTaskPrincipal -UserId $currentUser -LogonType Interactive -RunLevel Limited",
|
|
368
|
+
`$settings = ${settingsScript}`,
|
|
369
|
+
assertOwnedTasks,
|
|
370
|
+
"Register-ScheduledTask -TaskName $taskName -Description $expectedDefinitionMarker -Action $action -Trigger $trigger -Principal $principal -Settings $settings -Force -ErrorAction Stop | Out-Null",
|
|
371
|
+
cleanupLegacyTask,
|
|
372
|
+
"$registeredTask = @(Get-ScheduledTask -ErrorAction Stop | Where-Object { $_.TaskPath -eq '\\' -and $_.TaskName -eq $taskName })[0]",
|
|
373
|
+
"if ($null -eq $registeredTask -or $registeredTask.Description -cne $expectedDefinitionMarker) { throw 'Alan daemon task definition was not applied' }",
|
|
374
|
+
].join("; ");
|
|
375
|
+
const uninstallScript = [
|
|
376
|
+
taskContext,
|
|
377
|
+
resolveTaskSid,
|
|
378
|
+
windowsDefinitionContext,
|
|
379
|
+
assertOwnedTasks,
|
|
380
|
+
"if ($null -ne $legacyTask) { Unregister-ScheduledTask -TaskName $legacyTask.TaskName -TaskPath $legacyTask.TaskPath -Confirm:$false -ErrorAction Stop }",
|
|
381
|
+
"$task = @(Get-ScheduledTask -ErrorAction Stop | Where-Object { $_.TaskPath -eq '\\' -and $_.TaskName -eq $taskName })[0]",
|
|
382
|
+
"if ($null -ne $task) { Unregister-ScheduledTask -TaskName $taskName -TaskPath '\\' -Confirm:$false -ErrorAction Stop }",
|
|
383
|
+
"$remaining = @(Get-ScheduledTask -ErrorAction Stop | Where-Object { $_.TaskPath -eq '\\' -and ($_.TaskName -eq $taskName -or $_.TaskName -eq $legacyTask.TaskName) })",
|
|
384
|
+
"if ($remaining.Count -gt 0) { throw 'Alan daemon task still exists after unregister' }",
|
|
385
|
+
].join("; ");
|
|
386
|
+
const statusScript = [
|
|
387
|
+
taskContext,
|
|
388
|
+
resolveTaskSid,
|
|
389
|
+
windowsDefinitionContext,
|
|
390
|
+
checkCurrentOwnership,
|
|
391
|
+
checkLegacyOwnership,
|
|
392
|
+
"$definitionMatches = $false",
|
|
393
|
+
"if ($null -eq $task) { Write-Output 'State: Missing' } else {",
|
|
394
|
+
"$taskTrigger = @($task.Triggers)[0]",
|
|
395
|
+
"$definitionMatches = @($task.Actions).Count -eq 1 -and @($task.Triggers).Count -eq 1 -and $task.Description -ceq $expectedDefinitionMarker -and (Resolve-TaskSid ([string]$task.Principal.UserId)) -eq $currentSid -and [string]$task.Principal.LogonType -eq 'Interactive' -and [string]$task.Principal.RunLevel -eq 'Limited' -and [string]$taskAction.Execute -ieq 'powershell.exe' -and [string]$taskAction.Arguments -ceq $expectedLauncherArguments -and [string]$taskAction.WorkingDirectory -ieq $expectedWorkingDirectory -and $taskTrigger.CimClass.CimClassName -eq 'MSFT_TaskLogonTrigger' -and (Resolve-TaskSid ([string]$taskTrigger.UserId)) -eq $currentSid -and -not $task.Settings.DisallowStartIfOnBatteries -and -not $task.Settings.StopIfGoingOnBatteries -and $task.Settings.RestartCount -eq 3 -and [string]$task.Settings.RestartInterval -eq 'PT1M' -and [string]$task.Settings.ExecutionTimeLimit -eq 'PT0S'",
|
|
396
|
+
"Write-Output ('TaskName: ' + $task.TaskName); Write-Output ('State: ' + $task.State); Write-Output ('Definition: ' + $task.Description)",
|
|
397
|
+
"}",
|
|
398
|
+
"Write-Output ('DefinitionMatch: ' + $definitionMatches)",
|
|
399
|
+
"Write-Output ('CurrentOwned: ' + $currentOwned)",
|
|
400
|
+
"$legacyPresent = $null -ne $legacyTask",
|
|
401
|
+
"Write-Output ('LegacyTask: ' + $legacyPresent)",
|
|
402
|
+
"Write-Output ('LegacyOwned: ' + $legacyOwned)",
|
|
403
|
+
"Write-Output ('LegacyState: ' + $legacyState)",
|
|
404
|
+
].join("; ");
|
|
405
|
+
const registerCommand = powershellCommand(registerScript);
|
|
406
|
+
return {
|
|
407
|
+
platform: "win32",
|
|
408
|
+
manifestPath: null,
|
|
409
|
+
manifest: null,
|
|
410
|
+
logDirectory: logDir,
|
|
411
|
+
loadDefinitionCommands: [registerCommand],
|
|
412
|
+
reloadDefinitionCommands: [registerCommand],
|
|
413
|
+
enableCommands: [],
|
|
414
|
+
startCommands: [powershellCommand(`${taskContext}; Start-ScheduledTask -TaskName $taskName`)],
|
|
415
|
+
stopCommands: [
|
|
416
|
+
powershellCommand(`${taskContext}; Stop-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue`, true),
|
|
417
|
+
],
|
|
418
|
+
forceStopCommands: [],
|
|
419
|
+
uninstallCommands: [powershellCommand(uninstallScript)],
|
|
420
|
+
statusCommand: powershellCommand(statusScript, true),
|
|
421
|
+
isActiveCommand: powershellCommand(statusScript, true),
|
|
422
|
+
definitionMarker,
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
function resolveCurrentPlatform() {
|
|
426
|
+
const currentPlatform = platform();
|
|
427
|
+
if (currentPlatform !== "darwin" && currentPlatform !== "linux" && currentPlatform !== "win32") {
|
|
428
|
+
throw new Error(`Daemon service installation is not supported on ${currentPlatform}`);
|
|
429
|
+
}
|
|
430
|
+
return currentPlatform;
|
|
431
|
+
}
|
|
432
|
+
function currentServicePlan(args, runtime, options = {}) {
|
|
433
|
+
const currentPlatform = options.platform ?? resolveCurrentPlatform();
|
|
434
|
+
const profile = resolveEndpointProfileFromArgs(args);
|
|
435
|
+
const cliEntry = runtime?.cliEntry ?? process.argv[1];
|
|
436
|
+
if (!cliEntry)
|
|
437
|
+
throw new Error("Cannot determine the alan-agent executable path");
|
|
438
|
+
return buildDaemonServicePlan({
|
|
439
|
+
platform: currentPlatform,
|
|
440
|
+
homeDir: options.homeDir ?? homedir(),
|
|
441
|
+
userId: options.userId,
|
|
442
|
+
nodeExecutable: runtime?.executable ?? process.execPath,
|
|
443
|
+
cliEntry: currentPlatform === "win32" ? win32.resolve(cliEntry) : resolve(cliEntry),
|
|
444
|
+
profile,
|
|
445
|
+
environment: runtime?.environment,
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
function writeManifestAtomic(path, contents) {
|
|
449
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
450
|
+
const pendingPath = `${path}.pending-${process.pid}`;
|
|
451
|
+
try {
|
|
452
|
+
writeFileSync(pendingPath, contents, { mode: 0o600 });
|
|
453
|
+
chmodSync(pendingPath, 0o600);
|
|
454
|
+
renameSync(pendingPath, path);
|
|
455
|
+
}
|
|
456
|
+
finally {
|
|
457
|
+
rmSync(pendingPath, { force: true });
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
function defaultReadManifest(path) {
|
|
461
|
+
if (!existsSync(path))
|
|
462
|
+
return null;
|
|
463
|
+
return readFileSync(path, "utf8");
|
|
464
|
+
}
|
|
465
|
+
export function runServiceCommand(command, options = {}) {
|
|
466
|
+
return new Promise((resolveCommand, reject) => {
|
|
467
|
+
execFile(command.command, command.args, {
|
|
468
|
+
encoding: "utf8",
|
|
469
|
+
shell: false,
|
|
470
|
+
windowsHide: true,
|
|
471
|
+
timeout: options.commandTimeoutMs ?? 10_000,
|
|
472
|
+
killSignal: "SIGKILL",
|
|
473
|
+
maxBuffer: 256 * 1024,
|
|
474
|
+
signal: options.signal,
|
|
475
|
+
}, (error, stdout, stderr) => {
|
|
476
|
+
const status = error ? (typeof error.code === "number" ? error.code : 1) : 0;
|
|
477
|
+
const output = `${stdout ?? ""}${stderr ?? ""}`.trim();
|
|
478
|
+
if (error && (!command.tolerateFailure || error.killed || error.name === "AbortError")) {
|
|
479
|
+
reject(new Error(`Service command failed (${command.command}): ${output || error.message}`, {
|
|
480
|
+
cause: error,
|
|
481
|
+
}));
|
|
482
|
+
}
|
|
483
|
+
else {
|
|
484
|
+
resolveCommand({ status, output: output || error?.message || "" });
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
function defaultSleep(ms) {
|
|
490
|
+
return new Promise((resolveSleep) => {
|
|
491
|
+
setTimeout(resolveSleep, ms);
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
function isProcessAlive(pid) {
|
|
495
|
+
if (pid <= 0)
|
|
496
|
+
return false;
|
|
497
|
+
try {
|
|
498
|
+
process.kill(pid, 0);
|
|
499
|
+
return true;
|
|
500
|
+
}
|
|
501
|
+
catch (error) {
|
|
502
|
+
return error.code === "EPERM";
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
async function requestWindowsDaemonShutdown(owner) {
|
|
506
|
+
try {
|
|
507
|
+
const response = await requestLocalDaemonShutdown(owner.localApiPort, owner.localApiToken);
|
|
508
|
+
return response.ok ? "accepted" : "rejected";
|
|
509
|
+
}
|
|
510
|
+
catch {
|
|
511
|
+
return "unreachable";
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
export function parseServiceHostState(servicePlatform, result) {
|
|
515
|
+
const output = result.output;
|
|
516
|
+
// `systemctl is-active` deliberately exits non-zero for known inactive
|
|
517
|
+
// states. Parse those states before treating other command failures as
|
|
518
|
+
// unknown, otherwise a fresh enabled unit is never started.
|
|
519
|
+
if (servicePlatform === "linux") {
|
|
520
|
+
const trimmed = output.trim().toLowerCase();
|
|
521
|
+
if (trimmed === "inactive" ||
|
|
522
|
+
trimmed === "failed" ||
|
|
523
|
+
trimmed === "dead" ||
|
|
524
|
+
/\binactive\b/i.test(output) ||
|
|
525
|
+
/\bfailed\b/i.test(output)) {
|
|
526
|
+
return "stopped";
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
if (result.status !== 0)
|
|
530
|
+
return "unknown";
|
|
531
|
+
if (servicePlatform === "darwin") {
|
|
532
|
+
if (/\bstate\s*=\s*running\b/i.test(output))
|
|
533
|
+
return "running";
|
|
534
|
+
if (/\bstate\s*=\s*(not running|waiting|stopped)\b/i.test(output))
|
|
535
|
+
return "stopped";
|
|
536
|
+
if (/\bpid\s*=\s*[1-9]\d*\b/i.test(output))
|
|
537
|
+
return "running";
|
|
538
|
+
if (/could not find service/i.test(output))
|
|
539
|
+
return "stopped";
|
|
540
|
+
return "unknown";
|
|
541
|
+
}
|
|
542
|
+
if (servicePlatform === "linux") {
|
|
543
|
+
const trimmed = output.trim().toLowerCase();
|
|
544
|
+
if (trimmed === "active" || /\bactive\s*\(running\)/i.test(output))
|
|
545
|
+
return "running";
|
|
546
|
+
if (trimmed === "activating" || trimmed === "reloading")
|
|
547
|
+
return "starting";
|
|
548
|
+
return "unknown";
|
|
549
|
+
}
|
|
550
|
+
const stateMatch = output.match(/\b(?:State|state)\s*[:=]\s*(\w+)/);
|
|
551
|
+
const state = (stateMatch?.[1] ?? output.trim()).toLowerCase();
|
|
552
|
+
if (state === "running")
|
|
553
|
+
return "running";
|
|
554
|
+
if (state === "queued")
|
|
555
|
+
return "starting";
|
|
556
|
+
if (state === "ready" || state === "disabled")
|
|
557
|
+
return "stopped";
|
|
558
|
+
return "unknown";
|
|
559
|
+
}
|
|
560
|
+
function parseWindowsTaskInspection(result) {
|
|
561
|
+
if (result.status !== 0) {
|
|
562
|
+
throw new Error("Cannot inspect Windows daemon task definition");
|
|
563
|
+
}
|
|
564
|
+
const value = (name) => {
|
|
565
|
+
const match = result.output.match(new RegExp(`^${name}:\\s*(.*)$`, "imu"));
|
|
566
|
+
if (!match)
|
|
567
|
+
throw new Error(`Incomplete Windows daemon task inspection: missing ${name}`);
|
|
568
|
+
return match[1]?.trim() ?? "";
|
|
569
|
+
};
|
|
570
|
+
const boolean = (name) => {
|
|
571
|
+
const parsed = value(name).toLowerCase();
|
|
572
|
+
if (parsed === "true")
|
|
573
|
+
return true;
|
|
574
|
+
if (parsed === "false")
|
|
575
|
+
return false;
|
|
576
|
+
throw new Error(`Incomplete Windows daemon task inspection: invalid ${name}`);
|
|
577
|
+
};
|
|
578
|
+
const currentPresent = /^TaskName:\s*.+$/imu.test(result.output);
|
|
579
|
+
const currentStateValue = value("State");
|
|
580
|
+
const currentOwned = boolean("CurrentOwned");
|
|
581
|
+
const definitionMatches = boolean("DefinitionMatch");
|
|
582
|
+
const legacyPresent = boolean("LegacyTask");
|
|
583
|
+
const legacyOwned = boolean("LegacyOwned");
|
|
584
|
+
const legacyStateValue = value("LegacyState");
|
|
585
|
+
if (currentPresent !== (currentStateValue.toLowerCase() !== "missing")) {
|
|
586
|
+
throw new Error("Incomplete Windows daemon task inspection: inconsistent current task state");
|
|
587
|
+
}
|
|
588
|
+
if (!currentPresent && (currentOwned || definitionMatches)) {
|
|
589
|
+
throw new Error("Incomplete Windows daemon task inspection: absent current task is marked owned");
|
|
590
|
+
}
|
|
591
|
+
if (legacyPresent !== (legacyStateValue.toLowerCase() !== "missing") ||
|
|
592
|
+
(!legacyPresent && legacyOwned)) {
|
|
593
|
+
throw new Error("Incomplete Windows daemon task inspection: inconsistent legacy task state");
|
|
594
|
+
}
|
|
595
|
+
return {
|
|
596
|
+
currentPresent,
|
|
597
|
+
currentOwned,
|
|
598
|
+
currentState: currentPresent
|
|
599
|
+
? parseServiceHostState("win32", { status: 0, output: currentStateValue })
|
|
600
|
+
: "stopped",
|
|
601
|
+
definitionMatches,
|
|
602
|
+
definitionMarker: result.output.match(/^Definition:\s*(.+)$/imu)?.[1]?.trim(),
|
|
603
|
+
legacyPresent,
|
|
604
|
+
legacyOwned,
|
|
605
|
+
legacyState: legacyPresent
|
|
606
|
+
? parseServiceHostState("win32", { status: 0, output: legacyStateValue })
|
|
607
|
+
: "stopped",
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
function windowsTaskHostState(tasks) {
|
|
611
|
+
const states = [tasks.currentState, tasks.legacyState];
|
|
612
|
+
if (states.includes("unknown"))
|
|
613
|
+
return "unknown";
|
|
614
|
+
if (states.includes("running"))
|
|
615
|
+
return "running";
|
|
616
|
+
if (states.includes("starting"))
|
|
617
|
+
return "starting";
|
|
618
|
+
return "stopped";
|
|
619
|
+
}
|
|
620
|
+
function assertWindowsTaskOwnership(tasks) {
|
|
621
|
+
if (tasks.currentPresent && !tasks.currentOwned) {
|
|
622
|
+
throw new Error("Windows daemon task is not owned by this Alan installation");
|
|
623
|
+
}
|
|
624
|
+
if (tasks.legacyPresent && !tasks.legacyOwned) {
|
|
625
|
+
throw new Error("Legacy Windows daemon task is not owned by this Alan installation");
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
export function resolveEnsureDefinitionOutcome(input) {
|
|
629
|
+
if (!input.definitionChanged) {
|
|
630
|
+
return { changed: false, updatePending: false };
|
|
631
|
+
}
|
|
632
|
+
if (input.hostState === "running" || input.hostState === "starting") {
|
|
633
|
+
return { changed: true, updatePending: true };
|
|
634
|
+
}
|
|
635
|
+
return { changed: true, updatePending: false };
|
|
636
|
+
}
|
|
637
|
+
function resolveUsername(options) {
|
|
638
|
+
if (options?.username)
|
|
639
|
+
return options.username;
|
|
640
|
+
try {
|
|
641
|
+
return userInfo().username;
|
|
642
|
+
}
|
|
643
|
+
catch {
|
|
644
|
+
return process.env.USER || process.env.USERNAME || "unknown";
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
async function assertSystemdUserLingerEnabled(options = {}) {
|
|
648
|
+
const username = resolveUsername(options);
|
|
649
|
+
const run = options.runCommand ?? ((command) => runServiceCommand(command, options));
|
|
650
|
+
const result = await run({
|
|
651
|
+
command: "loginctl",
|
|
652
|
+
args: ["show-user", username, "-p", "Linger"],
|
|
653
|
+
tolerateFailure: true,
|
|
654
|
+
});
|
|
655
|
+
if (result.status !== 0) {
|
|
656
|
+
throw new Error(`Cannot verify systemd user linger for ${username} (loginctl failed). ` +
|
|
657
|
+
`For durable headless VM boot run: sudo loginctl enable-linger ${username}`);
|
|
658
|
+
}
|
|
659
|
+
if (!/Linger=yes/i.test(result.output)) {
|
|
660
|
+
throw new Error(`systemd user linger is disabled for ${username}. ` +
|
|
661
|
+
`For durable headless VM boot run: sudo loginctl enable-linger ${username}`);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
function createHostContext(options = {}) {
|
|
665
|
+
const args = options.args ?? [];
|
|
666
|
+
const plan = currentServicePlan(args, options.runtime, options);
|
|
667
|
+
const sleep = options.sleep ?? defaultSleep;
|
|
668
|
+
const nowMs = options.nowMs ?? Date.now;
|
|
669
|
+
const run = async (command) => {
|
|
670
|
+
const remainingMs = options.deadlineMs === undefined ? 15_000 : options.deadlineMs - nowMs();
|
|
671
|
+
if (remainingMs <= 0)
|
|
672
|
+
throw new Error("Windows service setup deadline expired");
|
|
673
|
+
const result = options.runCommand
|
|
674
|
+
? await options.runCommand(command)
|
|
675
|
+
: await runServiceCommand(command, {
|
|
676
|
+
signal: options.signal,
|
|
677
|
+
commandTimeoutMs: Math.min(options.commandTimeoutMs ?? 10_000, remainingMs),
|
|
678
|
+
});
|
|
679
|
+
if (options.deadlineMs !== undefined && nowMs() >= options.deadlineMs) {
|
|
680
|
+
throw new Error("Windows service setup deadline expired");
|
|
681
|
+
}
|
|
682
|
+
return result;
|
|
683
|
+
};
|
|
684
|
+
const readManifest = options.readManifest ?? defaultReadManifest;
|
|
685
|
+
const writeManifest = options.writeManifest ?? writeManifestAtomic;
|
|
686
|
+
const removeManifest = options.removeManifest ?? ((path) => rmSync(path, { force: true }));
|
|
687
|
+
const ensureLogDir = options.ensureLogDir ??
|
|
688
|
+
(() => {
|
|
689
|
+
if (plan.logDirectory)
|
|
690
|
+
mkdirSync(plan.logDirectory, { recursive: true, mode: 0o700 });
|
|
691
|
+
});
|
|
692
|
+
return {
|
|
693
|
+
args,
|
|
694
|
+
plan,
|
|
695
|
+
run,
|
|
696
|
+
sleep,
|
|
697
|
+
nowMs,
|
|
698
|
+
readManifest,
|
|
699
|
+
writeManifest,
|
|
700
|
+
removeManifest,
|
|
701
|
+
ensureLogDir,
|
|
702
|
+
configPath: options.configPath ??
|
|
703
|
+
resolveAgentConfigPath({ profile: resolveEndpointProfileFromArgs(args) }),
|
|
704
|
+
readOwner: options.readOwner ?? readLocalDaemonOwnerLease,
|
|
705
|
+
isProcessAlive: options.isProcessAlive ?? isProcessAlive,
|
|
706
|
+
probeEndpoint: options.probeEndpoint ?? probeLocalDaemonEndpoint,
|
|
707
|
+
requestWindowsShutdown: options.requestWindowsShutdown ?? requestWindowsDaemonShutdown,
|
|
708
|
+
inspectJournal: options.inspectJournal ?? inspectLocalDaemonRunJournal,
|
|
709
|
+
acquireMaintenance: options.acquireMaintenance ?? acquireLocalDaemonMaintenanceLease,
|
|
710
|
+
releaseMaintenance: options.releaseMaintenance ?? releaseLocalDaemonMaintenanceLease,
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
export async function inspectDaemonService(options = {}) {
|
|
714
|
+
const { plan, run, nowMs } = createHostContext(options);
|
|
715
|
+
const result = await run(plan.isActiveCommand);
|
|
716
|
+
let state;
|
|
717
|
+
if (plan.platform === "win32") {
|
|
718
|
+
try {
|
|
719
|
+
const tasks = parseWindowsTaskInspection(result);
|
|
720
|
+
assertWindowsTaskOwnership(tasks);
|
|
721
|
+
state = windowsTaskHostState(tasks);
|
|
722
|
+
}
|
|
723
|
+
catch {
|
|
724
|
+
state = "unknown";
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
else {
|
|
728
|
+
state = parseServiceHostState(plan.platform, result);
|
|
729
|
+
}
|
|
730
|
+
return {
|
|
731
|
+
state,
|
|
732
|
+
platform: plan.platform,
|
|
733
|
+
detail: result.output || undefined,
|
|
734
|
+
observedAtMs: nowMs(),
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
export async function ensureDaemonServiceDefinition(options = {}) {
|
|
738
|
+
const ctx = createHostContext(options);
|
|
739
|
+
const { plan, run, nowMs, readManifest, writeManifest, ensureLogDir } = ctx;
|
|
740
|
+
let definitionChanged = false;
|
|
741
|
+
let inspection;
|
|
742
|
+
if (plan.manifestPath && plan.manifest) {
|
|
743
|
+
ensureLogDir();
|
|
744
|
+
const existing = readManifest(plan.manifestPath);
|
|
745
|
+
definitionChanged = existing !== plan.manifest;
|
|
746
|
+
if (definitionChanged) {
|
|
747
|
+
writeManifest(plan.manifestPath, plan.manifest);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
else if (plan.platform === "win32") {
|
|
751
|
+
ensureLogDir();
|
|
752
|
+
const result = await run(plan.statusCommand);
|
|
753
|
+
const tasks = parseWindowsTaskInspection(result);
|
|
754
|
+
assertWindowsTaskOwnership(tasks);
|
|
755
|
+
if ((tasks.currentPresent && tasks.currentState === "unknown") ||
|
|
756
|
+
(tasks.legacyPresent && tasks.legacyState === "unknown")) {
|
|
757
|
+
throw new Error("Cannot safely update a Windows daemon task with unknown state");
|
|
758
|
+
}
|
|
759
|
+
definitionChanged =
|
|
760
|
+
tasks.definitionMarker !== plan.definitionMarker ||
|
|
761
|
+
!tasks.definitionMatches ||
|
|
762
|
+
tasks.legacyPresent;
|
|
763
|
+
inspection = {
|
|
764
|
+
state: windowsTaskHostState(tasks),
|
|
765
|
+
platform: plan.platform,
|
|
766
|
+
detail: result.output || undefined,
|
|
767
|
+
observedAtMs: nowMs(),
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
inspection ??= await inspectDaemonService(options);
|
|
771
|
+
const definitionHostState = plan.platform === "win32" && inspection.state === "starting" ? "stopped" : inspection.state;
|
|
772
|
+
const outcome = resolveEnsureDefinitionOutcome({
|
|
773
|
+
definitionChanged,
|
|
774
|
+
hostState: definitionHostState,
|
|
775
|
+
});
|
|
776
|
+
if (outcome.updatePending) {
|
|
777
|
+
return outcome;
|
|
778
|
+
}
|
|
779
|
+
if (plan.platform === "win32" && !outcome.changed) {
|
|
780
|
+
return outcome;
|
|
781
|
+
}
|
|
782
|
+
if (definitionHostState === "running" || definitionHostState === "starting") {
|
|
783
|
+
return outcome;
|
|
784
|
+
}
|
|
785
|
+
const definitionCommands = definitionHostState === "stopped" ? plan.reloadDefinitionCommands : plan.loadDefinitionCommands;
|
|
786
|
+
for (const command of definitionCommands)
|
|
787
|
+
await run(command);
|
|
788
|
+
return outcome;
|
|
789
|
+
}
|
|
790
|
+
async function enableDaemonService(options = {}) {
|
|
791
|
+
const { plan, run } = createHostContext(options);
|
|
792
|
+
for (const command of plan.enableCommands)
|
|
793
|
+
await run(command);
|
|
794
|
+
}
|
|
795
|
+
async function startDaemonService(options = {}) {
|
|
796
|
+
const { plan, run } = createHostContext(options);
|
|
797
|
+
for (const command of plan.startCommands)
|
|
798
|
+
await run(command);
|
|
799
|
+
}
|
|
800
|
+
export function ownerMatchesDaemonIdentity(owner, identity) {
|
|
801
|
+
return Boolean(owner &&
|
|
802
|
+
owner.pid === identity.pid &&
|
|
803
|
+
owner.daemonSessionId === identity.daemonSessionId &&
|
|
804
|
+
owner.localApiPort === identity.port &&
|
|
805
|
+
(identity.serviceId === undefined || owner.localServiceId === identity.serviceId) &&
|
|
806
|
+
(identity.startedAtMs === undefined || owner.startedAtMs === identity.startedAtMs));
|
|
807
|
+
}
|
|
808
|
+
export async function stopDaemonServiceAndWait(identity, timeoutMs, options = {}) {
|
|
809
|
+
const { plan, run, sleep, nowMs, configPath, readOwner, isProcessAlive: processIsAlive, probeEndpoint, requestWindowsShutdown: requestShutdown, } = createHostContext(options);
|
|
810
|
+
let owner;
|
|
811
|
+
try {
|
|
812
|
+
owner = readOwner(configPath);
|
|
813
|
+
}
|
|
814
|
+
catch {
|
|
815
|
+
return "identity_changed";
|
|
816
|
+
}
|
|
817
|
+
if (!owner || !ownerMatchesDaemonIdentity(owner, identity)) {
|
|
818
|
+
return "identity_changed";
|
|
819
|
+
}
|
|
820
|
+
const deadline = nowMs() + Math.max(0, timeoutMs);
|
|
821
|
+
if (plan.platform === "win32") {
|
|
822
|
+
const shutdown = await requestShutdown(owner);
|
|
823
|
+
if (shutdown === "rejected")
|
|
824
|
+
return "identity_changed";
|
|
825
|
+
if (shutdown === "unreachable") {
|
|
826
|
+
for (const command of plan.stopCommands)
|
|
827
|
+
await run(command);
|
|
828
|
+
}
|
|
829
|
+
while (nowMs() < deadline) {
|
|
830
|
+
let currentOwner;
|
|
831
|
+
try {
|
|
832
|
+
currentOwner = readOwner(configPath);
|
|
833
|
+
}
|
|
834
|
+
catch {
|
|
835
|
+
return "identity_changed";
|
|
836
|
+
}
|
|
837
|
+
if (currentOwner && !ownerMatchesDaemonIdentity(currentOwner, identity)) {
|
|
838
|
+
return "identity_changed";
|
|
839
|
+
}
|
|
840
|
+
if (!processIsAlive(identity.pid)) {
|
|
841
|
+
const endpoint = await probeEndpoint(identity.port, owner.localApiToken, 250);
|
|
842
|
+
if (endpoint.state === "absent")
|
|
843
|
+
return "exited";
|
|
844
|
+
if (endpoint.state === "listening_unauthorized" ||
|
|
845
|
+
endpoint.status.daemonSessionId !== identity.daemonSessionId) {
|
|
846
|
+
return "identity_changed";
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
await sleep(STOP_POLL_INTERVAL_MS);
|
|
850
|
+
}
|
|
851
|
+
return "timeout";
|
|
852
|
+
}
|
|
853
|
+
for (const command of plan.stopCommands)
|
|
854
|
+
await run(command);
|
|
855
|
+
while (nowMs() < deadline) {
|
|
856
|
+
let currentOwner;
|
|
857
|
+
try {
|
|
858
|
+
currentOwner = readOwner(configPath);
|
|
859
|
+
}
|
|
860
|
+
catch {
|
|
861
|
+
return "identity_changed";
|
|
862
|
+
}
|
|
863
|
+
if (currentOwner && !ownerMatchesDaemonIdentity(currentOwner, identity)) {
|
|
864
|
+
return "identity_changed";
|
|
865
|
+
}
|
|
866
|
+
const result = await run(plan.isActiveCommand);
|
|
867
|
+
const state = parseServiceHostState(plan.platform, result);
|
|
868
|
+
let processExited = false;
|
|
869
|
+
if (identity.pid > 0) {
|
|
870
|
+
try {
|
|
871
|
+
process.kill(identity.pid, 0);
|
|
872
|
+
}
|
|
873
|
+
catch (error) {
|
|
874
|
+
processExited = error.code === "ESRCH";
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
if (processExited && state === "stopped")
|
|
878
|
+
return "exited";
|
|
879
|
+
await sleep(Math.max(0, Math.min(STOP_POLL_INTERVAL_MS, deadline - nowMs())));
|
|
880
|
+
}
|
|
881
|
+
return "timeout";
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* macOS-only escalation for a captured daemon that ignored graceful SIGTERM.
|
|
885
|
+
* Booting the job out prevents launchd KeepAlive from racing a replacement;
|
|
886
|
+
* LocalDaemonLifecycle revalidates work and identity immediately before this.
|
|
887
|
+
*/
|
|
888
|
+
export async function forceStopDaemonServiceAndWait(identity, timeoutMs, options = {}) {
|
|
889
|
+
const { plan, run, sleep, nowMs, configPath, readOwner, isProcessAlive: processIsAlive, } = createHostContext(options);
|
|
890
|
+
if (plan.platform !== "darwin" || plan.forceStopCommands.length === 0)
|
|
891
|
+
return "timeout";
|
|
892
|
+
let owner;
|
|
893
|
+
try {
|
|
894
|
+
owner = readOwner(configPath);
|
|
895
|
+
}
|
|
896
|
+
catch {
|
|
897
|
+
return "identity_changed";
|
|
898
|
+
}
|
|
899
|
+
if (!owner || !ownerMatchesDaemonIdentity(owner, identity))
|
|
900
|
+
return "identity_changed";
|
|
901
|
+
for (const command of plan.forceStopCommands)
|
|
902
|
+
await run(command);
|
|
903
|
+
const deadline = nowMs() + Math.max(0, timeoutMs);
|
|
904
|
+
while (nowMs() < deadline) {
|
|
905
|
+
let currentOwner;
|
|
906
|
+
try {
|
|
907
|
+
currentOwner = readOwner(configPath);
|
|
908
|
+
}
|
|
909
|
+
catch {
|
|
910
|
+
return "identity_changed";
|
|
911
|
+
}
|
|
912
|
+
if (currentOwner && !ownerMatchesDaemonIdentity(currentOwner, identity)) {
|
|
913
|
+
return "identity_changed";
|
|
914
|
+
}
|
|
915
|
+
const result = await run(plan.isActiveCommand);
|
|
916
|
+
const state = parseServiceHostState(plan.platform, result);
|
|
917
|
+
const serviceAbsent = state === "stopped" ||
|
|
918
|
+
(result.status !== 0 && /could not find service/iu.test(result.output));
|
|
919
|
+
if (!processIsAlive(identity.pid) && serviceAbsent)
|
|
920
|
+
return "exited";
|
|
921
|
+
await sleep(Math.max(0, Math.min(STOP_POLL_INTERVAL_MS, deadline - nowMs())));
|
|
922
|
+
}
|
|
923
|
+
return "timeout";
|
|
924
|
+
}
|
|
925
|
+
export async function uninstallDaemonService(args = [], options = {}) {
|
|
926
|
+
const ctx = createHostContext({ ...options, args: options.args ?? args });
|
|
927
|
+
if (ctx.plan.platform === "win32") {
|
|
928
|
+
const ownership = await ctx.run(ctx.plan.statusCommand);
|
|
929
|
+
let tasks;
|
|
930
|
+
try {
|
|
931
|
+
tasks = parseWindowsTaskInspection(ownership);
|
|
932
|
+
}
|
|
933
|
+
catch (error) {
|
|
934
|
+
throw new Error(`Cannot inspect Windows daemon task ownership before uninstall: ${error instanceof Error ? error.message : String(error)}`);
|
|
935
|
+
}
|
|
936
|
+
assertWindowsTaskOwnership(tasks);
|
|
937
|
+
if (!tasks.currentPresent && !tasks.legacyPresent) {
|
|
938
|
+
console.info("[alan-agent] Per-user daemon service removed");
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
const acquired = ctx.acquireMaintenance(ctx.configPath, "watchdog", 30_000);
|
|
942
|
+
if (!acquired.acquired) {
|
|
943
|
+
throw new Error("Cannot uninstall the Windows daemon service while maintenance is active");
|
|
944
|
+
}
|
|
945
|
+
try {
|
|
946
|
+
const journal = ctx.inspectJournal(ctx.configPath);
|
|
947
|
+
if (!journal.safeToRestart) {
|
|
948
|
+
throw new Error(`Windows daemon service uninstall is deferred while ${journal.activeRunCount} active run${journal.activeRunCount === 1 ? "" : "s"} finish`);
|
|
949
|
+
}
|
|
950
|
+
let owner;
|
|
951
|
+
try {
|
|
952
|
+
owner = ctx.readOwner(ctx.configPath);
|
|
953
|
+
}
|
|
954
|
+
catch (error) {
|
|
955
|
+
throw new Error(`Cannot verify Windows daemon ownership before uninstall: ${error instanceof Error ? error.message : String(error)}`);
|
|
956
|
+
}
|
|
957
|
+
if (owner) {
|
|
958
|
+
const stopped = await stopDaemonServiceAndWait({
|
|
959
|
+
pid: owner.pid,
|
|
960
|
+
serviceId: owner.localServiceId,
|
|
961
|
+
daemonSessionId: owner.daemonSessionId,
|
|
962
|
+
port: owner.localApiPort,
|
|
963
|
+
startedAtMs: owner.startedAtMs,
|
|
964
|
+
}, 10_000, { ...options, args: ctx.args });
|
|
965
|
+
if (stopped !== "exited") {
|
|
966
|
+
throw new Error(stopped === "identity_changed"
|
|
967
|
+
? "Windows daemon ownership changed before uninstall"
|
|
968
|
+
: "Timed out waiting for the Windows daemon to stop before uninstall");
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
else {
|
|
972
|
+
if (tasks.currentState !== "stopped" || tasks.legacyState !== "stopped") {
|
|
973
|
+
throw new Error("Cannot uninstall a running Windows daemon without verified ownership");
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
for (const command of ctx.plan.uninstallCommands)
|
|
977
|
+
await ctx.run(command);
|
|
978
|
+
}
|
|
979
|
+
finally {
|
|
980
|
+
ctx.releaseMaintenance(ctx.configPath, acquired.lease.id);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
else {
|
|
984
|
+
for (const command of ctx.plan.uninstallCommands)
|
|
985
|
+
await ctx.run(command);
|
|
986
|
+
if (ctx.plan.manifestPath)
|
|
987
|
+
ctx.removeManifest(ctx.plan.manifestPath);
|
|
988
|
+
}
|
|
989
|
+
console.info("[alan-agent] Per-user daemon service removed");
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* Compatibility wrapper: ensure definition + enable + start only when stopped.
|
|
993
|
+
* Never force-restarts an already-running service.
|
|
994
|
+
*/
|
|
995
|
+
export async function installDaemonService(args = [], runtime, options = {}) {
|
|
996
|
+
const profile = resolveEndpointProfileFromArgs(args);
|
|
997
|
+
const configPath = resolveAgentConfigPath({ profile });
|
|
998
|
+
if (!configExistsAtPath(configPath)) {
|
|
999
|
+
throw new Error(`No ${profile} runtime is configured. Run alan-agent setup or login first.`);
|
|
1000
|
+
}
|
|
1001
|
+
const headless = options.headless ?? args.includes("--headless");
|
|
1002
|
+
const merged = { ...options, args, runtime, headless };
|
|
1003
|
+
const ctx = createHostContext(merged);
|
|
1004
|
+
if (headless) {
|
|
1005
|
+
if (ctx.plan.platform !== "linux") {
|
|
1006
|
+
throw new Error("--headless is only supported on Linux systemd user services");
|
|
1007
|
+
}
|
|
1008
|
+
await assertSystemdUserLingerEnabled(merged);
|
|
1009
|
+
}
|
|
1010
|
+
const ensured = await ensureDaemonServiceDefinition(merged);
|
|
1011
|
+
await enableDaemonService(merged);
|
|
1012
|
+
const inspection = await inspectDaemonService(merged);
|
|
1013
|
+
if (ensured.updatePending) {
|
|
1014
|
+
console.info("[alan-agent] Daemon service definition update pending; leaving running service", {
|
|
1015
|
+
profile,
|
|
1016
|
+
state: inspection.state,
|
|
1017
|
+
});
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
if (inspection.state !== "stopped") {
|
|
1021
|
+
console.info("[alan-agent] Per-user daemon service already present", {
|
|
1022
|
+
profile,
|
|
1023
|
+
state: inspection.state,
|
|
1024
|
+
});
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
await startDaemonService(merged);
|
|
1028
|
+
console.info("[alan-agent] Per-user daemon service installed", { profile });
|
|
1029
|
+
}
|
|
1030
|
+
export async function printDaemonServiceStatus(args = []) {
|
|
1031
|
+
const plan = currentServicePlan(args);
|
|
1032
|
+
const result = await runServiceCommand({ ...plan.statusCommand, tolerateFailure: true });
|
|
1033
|
+
if (result.status !== 0) {
|
|
1034
|
+
process.stdout.write(`unknown\n${result.output}\n`);
|
|
1035
|
+
return;
|
|
1036
|
+
}
|
|
1037
|
+
process.stdout.write(`${result.output}\n`);
|
|
1038
|
+
}
|
|
1039
|
+
export function createOsDaemonServiceHost(options = {}) {
|
|
1040
|
+
const host = {
|
|
1041
|
+
async inspect() {
|
|
1042
|
+
return inspectDaemonService(options);
|
|
1043
|
+
},
|
|
1044
|
+
async ensureDefinition() {
|
|
1045
|
+
return ensureDaemonServiceDefinition(options);
|
|
1046
|
+
},
|
|
1047
|
+
async enable() {
|
|
1048
|
+
await enableDaemonService(options);
|
|
1049
|
+
},
|
|
1050
|
+
async start() {
|
|
1051
|
+
await startDaemonService(options);
|
|
1052
|
+
},
|
|
1053
|
+
async stopAndWait(identity, timeoutMs) {
|
|
1054
|
+
return stopDaemonServiceAndWait(identity, timeoutMs, options);
|
|
1055
|
+
},
|
|
1056
|
+
async uninstall() {
|
|
1057
|
+
await uninstallDaemonService(options.args ?? [], options);
|
|
1058
|
+
},
|
|
1059
|
+
};
|
|
1060
|
+
if (currentServicePlan(options.args ?? [], options.runtime, options).platform === "darwin") {
|
|
1061
|
+
host.forceStopAndWait = async (identity, timeoutMs) => forceStopDaemonServiceAndWait(identity, timeoutMs, options);
|
|
1062
|
+
}
|
|
1063
|
+
return host;
|
|
1064
|
+
}
|
|
1065
|
+
//# sourceMappingURL=service-manager.js.map
|