@alan-ai-hq/agent-manager 0.1.88 → 0.1.90
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/dist/index.cjs +524 -222
- package/package.json +2 -3
- package/dist/__tests__/binding-switch-git.test.d.ts +0 -2
- package/dist/__tests__/binding-switch-git.test.d.ts.map +0 -1
- package/dist/__tests__/binding-switch-git.test.js +0 -610
- package/dist/__tests__/binding-switch-git.test.js.map +0 -1
- package/dist/__tests__/cli-ensure-install.test.d.ts +0 -2
- package/dist/__tests__/cli-ensure-install.test.d.ts.map +0 -1
- package/dist/__tests__/cli-ensure-install.test.js +0 -109
- package/dist/__tests__/cli-ensure-install.test.js.map +0 -1
- package/dist/__tests__/cli-executable.test.d.ts +0 -2
- package/dist/__tests__/cli-executable.test.d.ts.map +0 -1
- package/dist/__tests__/cli-executable.test.js +0 -129
- package/dist/__tests__/cli-executable.test.js.map +0 -1
- package/dist/__tests__/cli-help.test.d.ts +0 -2
- package/dist/__tests__/cli-help.test.d.ts.map +0 -1
- package/dist/__tests__/cli-help.test.js +0 -34
- package/dist/__tests__/cli-help.test.js.map +0 -1
- package/dist/__tests__/computer-readiness.test.d.ts +0 -2
- package/dist/__tests__/computer-readiness.test.d.ts.map +0 -1
- package/dist/__tests__/computer-readiness.test.js +0 -63
- package/dist/__tests__/computer-readiness.test.js.map +0 -1
- package/dist/__tests__/core-agent-workflow-context.test.d.ts +0 -2
- package/dist/__tests__/core-agent-workflow-context.test.d.ts.map +0 -1
- package/dist/__tests__/core-agent-workflow-context.test.js +0 -139
- package/dist/__tests__/core-agent-workflow-context.test.js.map +0 -1
- package/dist/__tests__/daemon-reconcile-ask.test.d.ts +0 -2
- package/dist/__tests__/daemon-reconcile-ask.test.d.ts.map +0 -1
- package/dist/__tests__/daemon-reconcile-ask.test.js +0 -86
- package/dist/__tests__/daemon-reconcile-ask.test.js.map +0 -1
- package/dist/__tests__/daemon-socket.integration.test.d.ts +0 -2
- package/dist/__tests__/daemon-socket.integration.test.d.ts.map +0 -1
- package/dist/__tests__/daemon-socket.integration.test.js +0 -450
- package/dist/__tests__/daemon-socket.integration.test.js.map +0 -1
- package/dist/__tests__/daemon.test.d.ts +0 -2
- package/dist/__tests__/daemon.test.d.ts.map +0 -1
- package/dist/__tests__/daemon.test.js +0 -3975
- package/dist/__tests__/daemon.test.js.map +0 -1
- package/dist/__tests__/ensure-shared-checkout-branch.test.d.ts +0 -2
- package/dist/__tests__/ensure-shared-checkout-branch.test.d.ts.map +0 -1
- package/dist/__tests__/ensure-shared-checkout-branch.test.js +0 -129
- package/dist/__tests__/ensure-shared-checkout-branch.test.js.map +0 -1
- package/dist/__tests__/event-outbox-persist-failure.test.d.ts +0 -2
- package/dist/__tests__/event-outbox-persist-failure.test.d.ts.map +0 -1
- package/dist/__tests__/event-outbox-persist-failure.test.js +0 -84
- package/dist/__tests__/event-outbox-persist-failure.test.js.map +0 -1
- package/dist/__tests__/event-outbox.test.d.ts +0 -2
- package/dist/__tests__/event-outbox.test.d.ts.map +0 -1
- package/dist/__tests__/event-outbox.test.js +0 -256
- package/dist/__tests__/event-outbox.test.js.map +0 -1
- package/dist/__tests__/fake-provider-cli.test.d.ts +0 -2
- package/dist/__tests__/fake-provider-cli.test.d.ts.map +0 -1
- package/dist/__tests__/fake-provider-cli.test.js +0 -46
- package/dist/__tests__/fake-provider-cli.test.js.map +0 -1
- package/dist/__tests__/generated-images.test.d.ts +0 -2
- package/dist/__tests__/generated-images.test.d.ts.map +0 -1
- package/dist/__tests__/generated-images.test.js +0 -132
- package/dist/__tests__/generated-images.test.js.map +0 -1
- package/dist/__tests__/lifecycle-logger.test.d.ts +0 -2
- package/dist/__tests__/lifecycle-logger.test.d.ts.map +0 -1
- package/dist/__tests__/lifecycle-logger.test.js +0 -49
- package/dist/__tests__/lifecycle-logger.test.js.map +0 -1
- package/dist/__tests__/local-skill-scan.test.d.ts +0 -2
- package/dist/__tests__/local-skill-scan.test.d.ts.map +0 -1
- package/dist/__tests__/local-skill-scan.test.js +0 -91
- package/dist/__tests__/local-skill-scan.test.js.map +0 -1
- package/dist/__tests__/local-workspace-migration.test.d.ts +0 -2
- package/dist/__tests__/local-workspace-migration.test.d.ts.map +0 -1
- package/dist/__tests__/local-workspace-migration.test.js +0 -195
- package/dist/__tests__/local-workspace-migration.test.js.map +0 -1
- package/dist/__tests__/mcp-inspect-timeout.test.d.ts +0 -2
- package/dist/__tests__/mcp-inspect-timeout.test.d.ts.map +0 -1
- package/dist/__tests__/mcp-inspect-timeout.test.js +0 -97
- package/dist/__tests__/mcp-inspect-timeout.test.js.map +0 -1
- package/dist/__tests__/mcp-readiness.test.d.ts +0 -2
- package/dist/__tests__/mcp-readiness.test.d.ts.map +0 -1
- package/dist/__tests__/mcp-readiness.test.js +0 -267
- package/dist/__tests__/mcp-readiness.test.js.map +0 -1
- package/dist/__tests__/mcp-registration-cli.test.d.ts +0 -2
- package/dist/__tests__/mcp-registration-cli.test.d.ts.map +0 -1
- package/dist/__tests__/mcp-registration-cli.test.js +0 -71
- package/dist/__tests__/mcp-registration-cli.test.js.map +0 -1
- package/dist/__tests__/mcp-registration.test.d.ts +0 -2
- package/dist/__tests__/mcp-registration.test.d.ts.map +0 -1
- package/dist/__tests__/mcp-registration.test.js +0 -426
- package/dist/__tests__/mcp-registration.test.js.map +0 -1
- package/dist/__tests__/model-scan-runner.test.d.ts +0 -2
- package/dist/__tests__/model-scan-runner.test.d.ts.map +0 -1
- package/dist/__tests__/model-scan-runner.test.js +0 -67
- package/dist/__tests__/model-scan-runner.test.js.map +0 -1
- package/dist/__tests__/network-diagnostics.test.d.ts +0 -2
- package/dist/__tests__/network-diagnostics.test.d.ts.map +0 -1
- package/dist/__tests__/network-diagnostics.test.js +0 -26
- package/dist/__tests__/network-diagnostics.test.js.map +0 -1
- package/dist/__tests__/observable-map.test.d.ts +0 -2
- package/dist/__tests__/observable-map.test.d.ts.map +0 -1
- package/dist/__tests__/observable-map.test.js +0 -54
- package/dist/__tests__/observable-map.test.js.map +0 -1
- package/dist/__tests__/provider-auth-preflight.test.d.ts +0 -2
- package/dist/__tests__/provider-auth-preflight.test.d.ts.map +0 -1
- package/dist/__tests__/provider-auth-preflight.test.js +0 -123
- package/dist/__tests__/provider-auth-preflight.test.js.map +0 -1
- package/dist/__tests__/provider-model-discovery.test.d.ts +0 -2
- package/dist/__tests__/provider-model-discovery.test.d.ts.map +0 -1
- package/dist/__tests__/provider-model-discovery.test.js +0 -472
- package/dist/__tests__/provider-model-discovery.test.js.map +0 -1
- package/dist/__tests__/remove-worktrees-if-clean.test.d.ts +0 -2
- package/dist/__tests__/remove-worktrees-if-clean.test.d.ts.map +0 -1
- package/dist/__tests__/remove-worktrees-if-clean.test.js +0 -221
- package/dist/__tests__/remove-worktrees-if-clean.test.js.map +0 -1
- package/dist/__tests__/resume-fallback-env.test.d.ts +0 -2
- package/dist/__tests__/resume-fallback-env.test.d.ts.map +0 -1
- package/dist/__tests__/resume-fallback-env.test.js +0 -28
- package/dist/__tests__/resume-fallback-env.test.js.map +0 -1
- package/dist/__tests__/run-journal.test.d.ts +0 -2
- package/dist/__tests__/run-journal.test.d.ts.map +0 -1
- package/dist/__tests__/run-journal.test.js +0 -121
- package/dist/__tests__/run-journal.test.js.map +0 -1
- package/dist/__tests__/run-start-gate.test.d.ts +0 -2
- package/dist/__tests__/run-start-gate.test.d.ts.map +0 -1
- package/dist/__tests__/run-start-gate.test.js +0 -29
- package/dist/__tests__/run-start-gate.test.js.map +0 -1
- package/dist/__tests__/runtime-capabilities-sync.test.d.ts +0 -2
- package/dist/__tests__/runtime-capabilities-sync.test.d.ts.map +0 -1
- package/dist/__tests__/runtime-capabilities-sync.test.js +0 -66
- package/dist/__tests__/runtime-capabilities-sync.test.js.map +0 -1
- package/dist/__tests__/runtime-config.test.d.ts +0 -2
- package/dist/__tests__/runtime-config.test.d.ts.map +0 -1
- package/dist/__tests__/runtime-config.test.js +0 -102
- package/dist/__tests__/runtime-config.test.js.map +0 -1
- package/dist/__tests__/runtime-presenter-heartbeat.test.d.ts +0 -2
- package/dist/__tests__/runtime-presenter-heartbeat.test.d.ts.map +0 -1
- package/dist/__tests__/runtime-presenter-heartbeat.test.js +0 -159
- package/dist/__tests__/runtime-presenter-heartbeat.test.js.map +0 -1
- package/dist/__tests__/sandbox-outbox.test.d.ts +0 -2
- package/dist/__tests__/sandbox-outbox.test.d.ts.map +0 -1
- package/dist/__tests__/sandbox-outbox.test.js +0 -214
- package/dist/__tests__/sandbox-outbox.test.js.map +0 -1
- package/dist/__tests__/sandbox-workflow-context.test.d.ts +0 -2
- package/dist/__tests__/sandbox-workflow-context.test.d.ts.map +0 -1
- package/dist/__tests__/sandbox-workflow-context.test.js +0 -396
- package/dist/__tests__/sandbox-workflow-context.test.js.map +0 -1
- package/dist/__tests__/service-manager.test.d.ts +0 -2
- package/dist/__tests__/service-manager.test.d.ts.map +0 -1
- package/dist/__tests__/service-manager.test.js +0 -50
- package/dist/__tests__/service-manager.test.js.map +0 -1
- package/dist/__tests__/sleep-inhibitor.test.d.ts +0 -2
- package/dist/__tests__/sleep-inhibitor.test.d.ts.map +0 -1
- package/dist/__tests__/sleep-inhibitor.test.js +0 -236
- package/dist/__tests__/sleep-inhibitor.test.js.map +0 -1
- package/dist/__tests__/status-local-workspace.test.d.ts +0 -2
- package/dist/__tests__/status-local-workspace.test.d.ts.map +0 -1
- package/dist/__tests__/status-local-workspace.test.js +0 -121
- package/dist/__tests__/status-local-workspace.test.js.map +0 -1
- package/dist/__tests__/suspension-detector.test.d.ts +0 -2
- package/dist/__tests__/suspension-detector.test.d.ts.map +0 -1
- package/dist/__tests__/suspension-detector.test.js +0 -112
- package/dist/__tests__/suspension-detector.test.js.map +0 -1
- package/dist/__tests__/web-presenter-parent-events.test.d.ts +0 -2
- package/dist/__tests__/web-presenter-parent-events.test.d.ts.map +0 -1
- package/dist/__tests__/web-presenter-parent-events.test.js +0 -130
- package/dist/__tests__/web-presenter-parent-events.test.js.map +0 -1
- package/dist/__tests__/workspace-relocation.test.d.ts +0 -2
- package/dist/__tests__/workspace-relocation.test.d.ts.map +0 -1
- package/dist/__tests__/workspace-relocation.test.js +0 -66
- package/dist/__tests__/workspace-relocation.test.js.map +0 -1
- package/dist/__tests__/workspace-run-lease.test.d.ts +0 -2
- package/dist/__tests__/workspace-run-lease.test.d.ts.map +0 -1
- package/dist/__tests__/workspace-run-lease.test.js +0 -230
- package/dist/__tests__/workspace-run-lease.test.js.map +0 -1
- package/dist/__tests__/ws-client-heartbeat-volatile.test.d.ts +0 -2
- package/dist/__tests__/ws-client-heartbeat-volatile.test.d.ts.map +0 -1
- package/dist/__tests__/ws-client-heartbeat-volatile.test.js +0 -61
- package/dist/__tests__/ws-client-heartbeat-volatile.test.js.map +0 -1
- package/dist/__tests__/ws-client-heartbeat.integration.test.d.ts +0 -2
- package/dist/__tests__/ws-client-heartbeat.integration.test.d.ts.map +0 -1
- package/dist/__tests__/ws-client-heartbeat.integration.test.js +0 -109
- package/dist/__tests__/ws-client-heartbeat.integration.test.js.map +0 -1
- package/dist/__tests__/ws-client-user-message-ack.integration.test.d.ts +0 -2
- package/dist/__tests__/ws-client-user-message-ack.integration.test.d.ts.map +0 -1
- package/dist/__tests__/ws-client-user-message-ack.integration.test.js +0 -167
- package/dist/__tests__/ws-client-user-message-ack.integration.test.js.map +0 -1
- package/dist/aiden-system-prompt.d.ts +0 -6
- package/dist/aiden-system-prompt.d.ts.map +0 -1
- package/dist/aiden-system-prompt.js +0 -6
- package/dist/aiden-system-prompt.js.map +0 -1
- package/dist/binding-switch-git.d.ts +0 -26
- package/dist/binding-switch-git.d.ts.map +0 -1
- package/dist/binding-switch-git.js +0 -973
- package/dist/binding-switch-git.js.map +0 -1
- package/dist/cli-ensure-install.d.ts +0 -39
- package/dist/cli-ensure-install.d.ts.map +0 -1
- package/dist/cli-ensure-install.js +0 -133
- package/dist/cli-ensure-install.js.map +0 -1
- package/dist/cli-executable.d.ts +0 -97
- package/dist/cli-executable.d.ts.map +0 -1
- package/dist/cli-executable.js +0 -432
- package/dist/cli-executable.js.map +0 -1
- package/dist/cli-help.d.ts +0 -7
- package/dist/cli-help.d.ts.map +0 -1
- package/dist/cli-help.js +0 -49
- package/dist/cli-help.js.map +0 -1
- package/dist/computer-readiness.d.ts +0 -42
- package/dist/computer-readiness.d.ts.map +0 -1
- package/dist/computer-readiness.js +0 -191
- package/dist/computer-readiness.js.map +0 -1
- package/dist/core-agent.d.ts +0 -47
- package/dist/core-agent.d.ts.map +0 -1
- package/dist/core-agent.js +0 -364
- package/dist/core-agent.js.map +0 -1
- package/dist/daemon.d.ts +0 -392
- package/dist/daemon.d.ts.map +0 -1
- package/dist/daemon.js +0 -4711
- package/dist/daemon.js.map +0 -1
- package/dist/event-outbox.d.ts +0 -83
- package/dist/event-outbox.d.ts.map +0 -1
- package/dist/event-outbox.js +0 -440
- package/dist/event-outbox.js.map +0 -1
- package/dist/fake-provider-cli.d.ts +0 -13
- package/dist/fake-provider-cli.d.ts.map +0 -1
- package/dist/fake-provider-cli.js +0 -53
- package/dist/fake-provider-cli.js.map +0 -1
- package/dist/generated-images.d.ts +0 -2
- package/dist/generated-images.d.ts.map +0 -1
- package/dist/generated-images.js +0 -2
- package/dist/generated-images.js.map +0 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -209
- package/dist/index.js.map +0 -1
- package/dist/lifecycle-logger.d.ts +0 -25
- package/dist/lifecycle-logger.d.ts.map +0 -1
- package/dist/lifecycle-logger.js +0 -73
- package/dist/lifecycle-logger.js.map +0 -1
- package/dist/local-skill-scan.d.ts +0 -21
- package/dist/local-skill-scan.d.ts.map +0 -1
- package/dist/local-skill-scan.js +0 -109
- package/dist/local-skill-scan.js.map +0 -1
- package/dist/local-workspace-migration.d.ts +0 -68
- package/dist/local-workspace-migration.d.ts.map +0 -1
- package/dist/local-workspace-migration.js +0 -157
- package/dist/local-workspace-migration.js.map +0 -1
- package/dist/mcp-readiness.d.ts +0 -59
- package/dist/mcp-readiness.d.ts.map +0 -1
- package/dist/mcp-readiness.js +0 -202
- package/dist/mcp-readiness.js.map +0 -1
- package/dist/mcp-registration.d.ts +0 -75
- package/dist/mcp-registration.d.ts.map +0 -1
- package/dist/mcp-registration.js +0 -563
- package/dist/mcp-registration.js.map +0 -1
- package/dist/model-scan-runner.d.ts +0 -15
- package/dist/model-scan-runner.d.ts.map +0 -1
- package/dist/model-scan-runner.js +0 -51
- package/dist/model-scan-runner.js.map +0 -1
- package/dist/network-diagnostics.d.ts +0 -8
- package/dist/network-diagnostics.d.ts.map +0 -1
- package/dist/network-diagnostics.js +0 -56
- package/dist/network-diagnostics.js.map +0 -1
- package/dist/observable-map.d.ts +0 -25
- package/dist/observable-map.d.ts.map +0 -1
- package/dist/observable-map.js +0 -42
- package/dist/observable-map.js.map +0 -1
- package/dist/provider-auth-preflight.d.ts +0 -22
- package/dist/provider-auth-preflight.d.ts.map +0 -1
- package/dist/provider-auth-preflight.js +0 -110
- package/dist/provider-auth-preflight.js.map +0 -1
- package/dist/provider-model-discovery.d.ts +0 -38
- package/dist/provider-model-discovery.d.ts.map +0 -1
- package/dist/provider-model-discovery.js +0 -519
- package/dist/provider-model-discovery.js.map +0 -1
- package/dist/resume-fallback-env.d.ts +0 -20
- package/dist/resume-fallback-env.d.ts.map +0 -1
- package/dist/resume-fallback-env.js +0 -30
- package/dist/resume-fallback-env.js.map +0 -1
- package/dist/run-journal.d.ts +0 -53
- package/dist/run-journal.d.ts.map +0 -1
- package/dist/run-journal.js +0 -193
- package/dist/run-journal.js.map +0 -1
- package/dist/run-start-gate.d.ts +0 -9
- package/dist/run-start-gate.d.ts.map +0 -1
- package/dist/run-start-gate.js +0 -24
- package/dist/run-start-gate.js.map +0 -1
- package/dist/runtime-backends.d.ts +0 -2
- package/dist/runtime-backends.d.ts.map +0 -1
- package/dist/runtime-backends.js +0 -2
- package/dist/runtime-backends.js.map +0 -1
- package/dist/runtime-capabilities-sync.d.ts +0 -33
- package/dist/runtime-capabilities-sync.d.ts.map +0 -1
- package/dist/runtime-capabilities-sync.js +0 -56
- package/dist/runtime-capabilities-sync.js.map +0 -1
- package/dist/runtime-config.d.ts +0 -24
- package/dist/runtime-config.d.ts.map +0 -1
- package/dist/runtime-config.js +0 -124
- package/dist/runtime-config.js.map +0 -1
- package/dist/sandbox-outbox.d.ts +0 -122
- package/dist/sandbox-outbox.d.ts.map +0 -1
- package/dist/sandbox-outbox.js +0 -180
- package/dist/sandbox-outbox.js.map +0 -1
- package/dist/sandbox.d.ts +0 -44
- package/dist/sandbox.d.ts.map +0 -1
- package/dist/sandbox.js +0 -438
- package/dist/sandbox.js.map +0 -1
- package/dist/service-manager.d.ts +0 -28
- package/dist/service-manager.d.ts.map +0 -1
- package/dist/service-manager.js +0 -259
- package/dist/service-manager.js.map +0 -1
- package/dist/sleep-inhibitor.d.ts +0 -111
- package/dist/sleep-inhibitor.d.ts.map +0 -1
- package/dist/sleep-inhibitor.js +0 -412
- package/dist/sleep-inhibitor.js.map +0 -1
- package/dist/suspension-detector.d.ts +0 -48
- package/dist/suspension-detector.d.ts.map +0 -1
- package/dist/suspension-detector.js +0 -89
- package/dist/suspension-detector.js.map +0 -1
- package/dist/types.d.ts +0 -6
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -6
- package/dist/types.js.map +0 -1
- package/dist/updater.d.ts +0 -15
- package/dist/updater.d.ts.map +0 -1
- package/dist/updater.js +0 -50
- package/dist/updater.js.map +0 -1
- package/dist/version.d.ts +0 -2
- package/dist/version.d.ts.map +0 -1
- package/dist/version.js +0 -2
- package/dist/version.js.map +0 -1
- package/dist/web-presenter.d.ts +0 -55
- package/dist/web-presenter.d.ts.map +0 -1
- package/dist/web-presenter.js +0 -265
- package/dist/web-presenter.js.map +0 -1
- package/dist/workspace-relocation.d.ts +0 -22
- package/dist/workspace-relocation.d.ts.map +0 -1
- package/dist/workspace-relocation.js +0 -90
- package/dist/workspace-relocation.js.map +0 -1
- package/dist/workspace-run-lease.d.ts +0 -97
- package/dist/workspace-run-lease.d.ts.map +0 -1
- package/dist/workspace-run-lease.js +0 -241
- package/dist/workspace-run-lease.js.map +0 -1
- package/dist/ws-client.d.ts +0 -194
- package/dist/ws-client.d.ts.map +0 -1
- package/dist/ws-client.js +0 -282
- package/dist/ws-client.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -15167,6 +15167,10 @@ function hasRunSessionEnv(env) {
|
|
|
15167
15167
|
env.ALAN_WS_URL && env.ALAN_SESSION_ID && env.ALAN_TASK_ID && env.ALAN_SESSION_TOKEN && env.ALAN_TASK !== void 0
|
|
15168
15168
|
);
|
|
15169
15169
|
}
|
|
15170
|
+
function resolveInstallConfigurationMode(args, configured) {
|
|
15171
|
+
if (args.includes("--setup-token")) return "setup";
|
|
15172
|
+
return configured.runtimeId && configured.runtimeToken ? "reuse" : "login";
|
|
15173
|
+
}
|
|
15170
15174
|
function resolveCommand(args, env) {
|
|
15171
15175
|
const [command, ...commandArgs] = args;
|
|
15172
15176
|
if (!command) {
|
|
@@ -15180,7 +15184,7 @@ function resolveCommand(args, env) {
|
|
|
15180
15184
|
|
|
15181
15185
|
// src/daemon.ts
|
|
15182
15186
|
var import_node_crypto19 = require("crypto");
|
|
15183
|
-
var
|
|
15187
|
+
var import_node_os13 = require("os");
|
|
15184
15188
|
|
|
15185
15189
|
// src/sleep-inhibitor.ts
|
|
15186
15190
|
var import_node_child_process2 = require("child_process");
|
|
@@ -15447,7 +15451,7 @@ function describeError(error61) {
|
|
|
15447
15451
|
}
|
|
15448
15452
|
|
|
15449
15453
|
// src/version.ts
|
|
15450
|
-
var AGENT_VERSION = "0.1.
|
|
15454
|
+
var AGENT_VERSION = "0.1.90";
|
|
15451
15455
|
|
|
15452
15456
|
// src/daemon-worktree.ts
|
|
15453
15457
|
var import_node_child_process3 = require("child_process");
|
|
@@ -19549,9 +19553,9 @@ var asciiTabOrNewline = /[\t\n\r]/g;
|
|
|
19549
19553
|
function stripTabAndNewline(value2) {
|
|
19550
19554
|
return value2.replace(asciiTabOrNewline, "");
|
|
19551
19555
|
}
|
|
19552
|
-
function urlHostnameOk(url3,
|
|
19553
|
-
|
|
19554
|
-
return
|
|
19556
|
+
function urlHostnameOk(url3, hostname5) {
|
|
19557
|
+
hostname5.lastIndex = 0;
|
|
19558
|
+
return hostname5.test(url3.hostname);
|
|
19555
19559
|
}
|
|
19556
19560
|
function urlProtocolOk(url3, protocol4) {
|
|
19557
19561
|
protocol4.lastIndex = 0;
|
|
@@ -35648,14 +35652,14 @@ function configuredConfigPathFromEnvironment() {
|
|
|
35648
35652
|
const explicit = process.env.ALAN_AGENT_CONFIG_PATH?.trim() || process.env.ALAN_AGENT_CONFIG?.trim();
|
|
35649
35653
|
return explicit || void 0;
|
|
35650
35654
|
}
|
|
35651
|
-
function resolveIsolatedAgentBaseDir(profile) {
|
|
35655
|
+
function resolveIsolatedAgentBaseDir(profile, homeDirectory2 = (0, import_node_os4.homedir)()) {
|
|
35652
35656
|
switch (profile) {
|
|
35653
35657
|
case "local":
|
|
35654
|
-
return (0, import_node_path5.join)(
|
|
35658
|
+
return (0, import_node_path5.join)(homeDirectory2, ".alan-dev", "agent");
|
|
35655
35659
|
case "staging":
|
|
35656
|
-
return (0, import_node_path5.join)(
|
|
35660
|
+
return (0, import_node_path5.join)(homeDirectory2, ".alan-staging", "agent");
|
|
35657
35661
|
case "custom":
|
|
35658
|
-
return (0, import_node_path5.join)(
|
|
35662
|
+
return (0, import_node_path5.join)(homeDirectory2, ".alan-prod", "agent");
|
|
35659
35663
|
default:
|
|
35660
35664
|
return null;
|
|
35661
35665
|
}
|
|
@@ -35732,6 +35736,9 @@ function migrateLegacyAgentConfig(input2) {
|
|
|
35732
35736
|
return false;
|
|
35733
35737
|
}
|
|
35734
35738
|
}
|
|
35739
|
+
function resolveAgentConfigDirectory(profile = "production", homeDirectory2 = (0, import_node_os4.homedir)()) {
|
|
35740
|
+
return resolveIsolatedAgentBaseDir(profile, homeDirectory2) ?? (0, import_node_path5.join)(homeDirectory2, ".alan", "agent");
|
|
35741
|
+
}
|
|
35735
35742
|
function resolveAgentConfigPath(input2) {
|
|
35736
35743
|
if (input2?.explicitPath?.trim()) return input2.explicitPath.trim();
|
|
35737
35744
|
const profile = normalizeAgentEndpointProfile(
|
|
@@ -35740,10 +35747,8 @@ function resolveAgentConfigPath(input2) {
|
|
|
35740
35747
|
if (input2?.baseDir !== void 0) {
|
|
35741
35748
|
return (0, import_node_path5.join)(input2.baseDir, resolveAgentConfigFileName(profile));
|
|
35742
35749
|
}
|
|
35743
|
-
|
|
35744
|
-
|
|
35745
|
-
migrateLegacyAgentConfig({ profile });
|
|
35746
|
-
return (0, import_node_path5.join)(DEFAULT_AGENT_DIR, resolveAgentConfigFileName(profile));
|
|
35750
|
+
if (profile === "production") migrateLegacyAgentConfig({ profile });
|
|
35751
|
+
return (0, import_node_path5.join)(resolveAgentConfigDirectory(profile), "config.json");
|
|
35747
35752
|
}
|
|
35748
35753
|
function configExistsAtPath(configPath) {
|
|
35749
35754
|
return (0, import_node_fs5.existsSync)(configPath);
|
|
@@ -49460,7 +49465,7 @@ function bindConfigPath(args) {
|
|
|
49460
49465
|
return boundAgentConfigPath;
|
|
49461
49466
|
}
|
|
49462
49467
|
function getConfigPath() {
|
|
49463
|
-
return process.env.ALAN_AGENT_CONFIG_PATH ??
|
|
49468
|
+
return boundAgentConfigPath ?? process.env.ALAN_AGENT_CONFIG_PATH ?? resolveAgentConfigPath({ profile: "production" });
|
|
49464
49469
|
}
|
|
49465
49470
|
function getEndpointDefaultsPath() {
|
|
49466
49471
|
return process.env.ALAN_AGENT_ENDPOINTS_PATH ?? (0, import_node_path11.join)((0, import_node_path11.dirname)(getConfigPath()), "endpoints.json");
|
|
@@ -49515,7 +49520,7 @@ function readLocalDaemonMaintenanceLease(configPath, nowMs = Date.now()) {
|
|
|
49515
49520
|
if (!(0, import_node_fs13.existsSync)(path2)) return null;
|
|
49516
49521
|
try {
|
|
49517
49522
|
const lease = JSON.parse((0, import_node_fs13.readFileSync)(path2, "utf8"));
|
|
49518
|
-
if (lease.version !== 1 || typeof lease.id !== "string" || lease.reason !== "credential_cleanup" && lease.reason !== "daemon_startup" && lease.reason !== "watchdog" || !(lease.reason === "credential_cleanup" && lease.expiresAtMs === null || typeof lease.expiresAtMs === "number" && Number.isFinite(lease.expiresAtMs))) {
|
|
49523
|
+
if (lease.version !== 1 || typeof lease.id !== "string" || lease.reason !== "credential_cleanup" && lease.reason !== "credential_swap" && lease.reason !== "daemon_startup" && lease.reason !== "watchdog" || !(lease.reason === "credential_cleanup" && lease.expiresAtMs === null || typeof lease.expiresAtMs === "number" && Number.isFinite(lease.expiresAtMs))) {
|
|
49519
49524
|
throw new Error("invalid maintenance lease");
|
|
49520
49525
|
}
|
|
49521
49526
|
if (lease.reason !== "credential_cleanup" && lease.expiresAtMs <= nowMs) {
|
|
@@ -50894,7 +50899,7 @@ function scheduleRuntimeModelScan(getBaseMetadata, options) {
|
|
|
50894
50899
|
var import_node_crypto18 = require("crypto");
|
|
50895
50900
|
var import_node_fs22 = require("fs");
|
|
50896
50901
|
var import_node_http = __toESM(require("http"), 1);
|
|
50897
|
-
var
|
|
50902
|
+
var import_node_os12 = require("os");
|
|
50898
50903
|
var import_node_path24 = require("path");
|
|
50899
50904
|
|
|
50900
50905
|
// ../../node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.node.js
|
|
@@ -51480,8 +51485,8 @@ var Transport = class extends Emitter {
|
|
|
51480
51485
|
return schema + "://" + this._hostname() + this._port() + this.opts.path + this._query(query);
|
|
51481
51486
|
}
|
|
51482
51487
|
_hostname() {
|
|
51483
|
-
const
|
|
51484
|
-
return
|
|
51488
|
+
const hostname5 = this.opts.hostname;
|
|
51489
|
+
return hostname5.indexOf(":") === -1 ? hostname5 : "[" + hostname5 + "]";
|
|
51485
51490
|
}
|
|
51486
51491
|
_port() {
|
|
51487
51492
|
if (this.opts.port && (this.opts.secure && Number(this.opts.port) !== 443 || !this.opts.secure && Number(this.opts.port) !== 80)) {
|
|
@@ -70429,8 +70434,8 @@ function applyPostAuth(clientId, clientSecret, params) {
|
|
|
70429
70434
|
function applyPublicAuth(clientId, params) {
|
|
70430
70435
|
params.set("client_id", clientId);
|
|
70431
70436
|
}
|
|
70432
|
-
function isLoopbackHost(
|
|
70433
|
-
return
|
|
70437
|
+
function isLoopbackHost(hostname5) {
|
|
70438
|
+
return hostname5 === "localhost" || hostname5 === "127.0.0.1" || hostname5 === "[::1]" || hostname5 === "::1";
|
|
70434
70439
|
}
|
|
70435
70440
|
function assertSecureTokenEndpoint(tokenEndpoint) {
|
|
70436
70441
|
const url3 = new URL(String(tokenEndpoint));
|
|
@@ -75335,7 +75340,8 @@ function createLocalDaemonHttpHandler(deps) {
|
|
|
75335
75340
|
queueFullShutdown,
|
|
75336
75341
|
wsUrl,
|
|
75337
75342
|
inspectLocalSkill,
|
|
75338
|
-
readLocalSkillFile
|
|
75343
|
+
readLocalSkillFile,
|
|
75344
|
+
adoptRuntimeSetupGrant
|
|
75339
75345
|
} = deps;
|
|
75340
75346
|
const localApiPort = getLocalApiPort2();
|
|
75341
75347
|
const heartbeatSeq = getHeartbeatSeq();
|
|
@@ -75393,6 +75399,15 @@ function createLocalDaemonHttpHandler(deps) {
|
|
|
75393
75399
|
res.writeHead(401, { "content-type": "application/json" }).end(JSON.stringify({ error: "Unauthorized" }));
|
|
75394
75400
|
return;
|
|
75395
75401
|
}
|
|
75402
|
+
if (req.method === "POST" && req.url === "/credentials/setup") {
|
|
75403
|
+
void readJsonRequest(req).then((value2) => parseRuntimeSetupGrantInput(value2)).then(adoptRuntimeSetupGrant).then((result) => {
|
|
75404
|
+
res.writeHead(200, { "cache-control": "no-store", "content-type": "application/json" }).end(JSON.stringify(result));
|
|
75405
|
+
}).catch((error61) => {
|
|
75406
|
+
pushLog(`runtime-credential-setup-failed ${error61.message}`);
|
|
75407
|
+
res.writeHead(409, { "cache-control": "no-store", "content-type": "application/json" }).end(JSON.stringify({ error: error61.message }));
|
|
75408
|
+
});
|
|
75409
|
+
return;
|
|
75410
|
+
}
|
|
75396
75411
|
if (req.method === "GET" && req.url?.startsWith("/skills/preview/file?")) {
|
|
75397
75412
|
const url3 = new URL(req.url, "http://127.0.0.1");
|
|
75398
75413
|
const input2 = localSkillRequestInput(url3, true);
|
|
@@ -75574,6 +75589,31 @@ function createLocalDaemonHttpHandler(deps) {
|
|
|
75574
75589
|
res.writeHead(404, { "content-type": "application/json" }).end(JSON.stringify({ error: "Not found" }));
|
|
75575
75590
|
};
|
|
75576
75591
|
}
|
|
75592
|
+
async function readJsonRequest(req) {
|
|
75593
|
+
const chunks = [];
|
|
75594
|
+
let size = 0;
|
|
75595
|
+
for await (const chunk of req) {
|
|
75596
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
75597
|
+
size += buffer.length;
|
|
75598
|
+
if (size > 16384) throw new Error("credential setup request is too large");
|
|
75599
|
+
chunks.push(buffer);
|
|
75600
|
+
}
|
|
75601
|
+
try {
|
|
75602
|
+
return JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
75603
|
+
} catch {
|
|
75604
|
+
throw new Error("credential setup request must be valid JSON");
|
|
75605
|
+
}
|
|
75606
|
+
}
|
|
75607
|
+
function parseRuntimeSetupGrantInput(value2) {
|
|
75608
|
+
if (!value2 || typeof value2 !== "object") {
|
|
75609
|
+
throw new Error("credential setup request must be an object");
|
|
75610
|
+
}
|
|
75611
|
+
const input2 = value2;
|
|
75612
|
+
if (typeof input2.apiUrl !== "string" || typeof input2.wsUrl !== "string" || input2.endpointProfile !== "production" && input2.endpointProfile !== "local" && input2.endpointProfile !== "staging" && input2.endpointProfile !== "custom" || typeof input2.setupToken !== "string" || input2.setupToken.length === 0 || typeof input2.displayName !== "string" || input2.displayName.length === 0 || typeof input2.installationId !== "string" || input2.installationId.length === 0 || input2.teamId !== void 0 && typeof input2.teamId !== "string") {
|
|
75613
|
+
throw new Error("credential setup request is incomplete");
|
|
75614
|
+
}
|
|
75615
|
+
return input2;
|
|
75616
|
+
}
|
|
75577
75617
|
function localSkillRequestInput(url3, requirePath) {
|
|
75578
75618
|
const localKey = url3.searchParams.get("localKey") ?? "";
|
|
75579
75619
|
const expectedContentHash = url3.searchParams.get("expectedContentHash") ?? "";
|
|
@@ -76463,6 +76503,125 @@ var RuntimeRunJournal = class {
|
|
|
76463
76503
|
}
|
|
76464
76504
|
};
|
|
76465
76505
|
|
|
76506
|
+
// src/runtime-registration.ts
|
|
76507
|
+
var import_node_os11 = require("os");
|
|
76508
|
+
var RuntimeSetupGrantExpiredError = class extends Error {
|
|
76509
|
+
constructor() {
|
|
76510
|
+
super("Runtime setup grant expired");
|
|
76511
|
+
this.name = "RuntimeSetupGrantExpiredError";
|
|
76512
|
+
}
|
|
76513
|
+
};
|
|
76514
|
+
async function createRuntimeSetupGrant(input2) {
|
|
76515
|
+
const response = await fetch(`${input2.apiUrl}/public/runtimes/setup-tokens`, {
|
|
76516
|
+
method: "POST",
|
|
76517
|
+
headers: {
|
|
76518
|
+
authorization: `Bearer ${input2.accessToken}`,
|
|
76519
|
+
"content-type": "application/json"
|
|
76520
|
+
},
|
|
76521
|
+
body: JSON.stringify({
|
|
76522
|
+
scope: input2.scope,
|
|
76523
|
+
...input2.scope === "team" ? { teamId: input2.teamId } : {},
|
|
76524
|
+
ttlMinutes: 5
|
|
76525
|
+
}),
|
|
76526
|
+
signal: AbortSignal.timeout(1e4)
|
|
76527
|
+
});
|
|
76528
|
+
const body = await response.json();
|
|
76529
|
+
if (!response.ok || typeof body.setupToken !== "string") {
|
|
76530
|
+
const detail = typeof body.error === "string" ? `: ${body.error}` : "";
|
|
76531
|
+
throw new Error(`runtime setup grant creation failed with HTTP ${response.status}${detail}`);
|
|
76532
|
+
}
|
|
76533
|
+
return body.setupToken;
|
|
76534
|
+
}
|
|
76535
|
+
async function exchangeRuntimeSetupGrant(input2) {
|
|
76536
|
+
const registrationAttemptId = getOrCreateSetupAttemptId(input2.setupToken);
|
|
76537
|
+
const signal = AbortSignal.timeout(15e3);
|
|
76538
|
+
const registrationInit = {
|
|
76539
|
+
method: "POST",
|
|
76540
|
+
headers: { "content-type": "application/json" },
|
|
76541
|
+
body: JSON.stringify({
|
|
76542
|
+
...input2.teamId ? { teamId: input2.teamId } : {},
|
|
76543
|
+
setupToken: input2.setupToken,
|
|
76544
|
+
registrationAttemptId,
|
|
76545
|
+
displayName: input2.displayName,
|
|
76546
|
+
hostname: (0, import_node_os11.hostname)(),
|
|
76547
|
+
runtimeKind: "machine",
|
|
76548
|
+
managementKind: "user_managed",
|
|
76549
|
+
hostKind: "daemon",
|
|
76550
|
+
lifecycle: "durable",
|
|
76551
|
+
capabilities: discoverCapabilities(),
|
|
76552
|
+
metadata: {
|
|
76553
|
+
...await collectRuntimeMetadataWithProviderLimits(),
|
|
76554
|
+
installationId: input2.installationId
|
|
76555
|
+
}
|
|
76556
|
+
}),
|
|
76557
|
+
signal
|
|
76558
|
+
};
|
|
76559
|
+
let response;
|
|
76560
|
+
let transportError;
|
|
76561
|
+
for (let attempt = 1; attempt <= 3; attempt += 1) {
|
|
76562
|
+
try {
|
|
76563
|
+
response = await fetch(
|
|
76564
|
+
`${input2.apiUrl}/public/runtimes/register-with-setup-token`,
|
|
76565
|
+
registrationInit
|
|
76566
|
+
);
|
|
76567
|
+
transportError = void 0;
|
|
76568
|
+
} catch (error61) {
|
|
76569
|
+
transportError = error61;
|
|
76570
|
+
}
|
|
76571
|
+
const retriable = response && (response.status === 408 || response.status === 429 || response.status >= 500);
|
|
76572
|
+
if (response && (!retriable || response.ok) || attempt === 3) break;
|
|
76573
|
+
await new Promise((resolve15) => setTimeout(resolve15, attempt * 100));
|
|
76574
|
+
}
|
|
76575
|
+
if (!response) {
|
|
76576
|
+
const detail = transportError instanceof Error ? transportError.message : String(transportError);
|
|
76577
|
+
throw new Error(`runtime registration failed: unable to reach Alan (${detail})`);
|
|
76578
|
+
}
|
|
76579
|
+
if (!response.ok) {
|
|
76580
|
+
const responseBody = await response.text();
|
|
76581
|
+
let errorCode2;
|
|
76582
|
+
try {
|
|
76583
|
+
const parsed = JSON.parse(responseBody);
|
|
76584
|
+
if (typeof parsed.error === "string") errorCode2 = parsed.error;
|
|
76585
|
+
} catch {
|
|
76586
|
+
}
|
|
76587
|
+
if (response.status === 401 && errorCode2 === "setup_token_expired") {
|
|
76588
|
+
clearPendingSetupIntent();
|
|
76589
|
+
throw new RuntimeSetupGrantExpiredError();
|
|
76590
|
+
}
|
|
76591
|
+
throw new Error(`runtime registration failed: ${response.status} ${responseBody}`);
|
|
76592
|
+
}
|
|
76593
|
+
const body = await response.json();
|
|
76594
|
+
if (typeof body.runtime?.id !== "string" || typeof body.runtime.credentialGeneration !== "number" || typeof body.runtimeToken !== "string" || !body.runtimeToken.startsWith("alan_runtime_") || typeof body.runtimeRenewalToken !== "string" || !body.runtimeRenewalToken.startsWith("alan_runtime_renew_")) {
|
|
76595
|
+
throw new Error("runtime registration returned an invalid credential bundle");
|
|
76596
|
+
}
|
|
76597
|
+
return {
|
|
76598
|
+
runtimeId: body.runtime.id,
|
|
76599
|
+
displayName: typeof body.runtime.displayName === "string" ? body.runtime.displayName : input2.displayName,
|
|
76600
|
+
credentialGeneration: body.runtime.credentialGeneration,
|
|
76601
|
+
runtimeToken: body.runtimeToken,
|
|
76602
|
+
runtimeRenewalToken: body.runtimeRenewalToken
|
|
76603
|
+
};
|
|
76604
|
+
}
|
|
76605
|
+
async function handoffRuntimeSetupGrant(input2) {
|
|
76606
|
+
const response = await fetch(`http://127.0.0.1:${input2.port}/credentials/setup`, {
|
|
76607
|
+
method: "POST",
|
|
76608
|
+
headers: {
|
|
76609
|
+
authorization: `Bearer ${input2.localApiToken}`,
|
|
76610
|
+
"content-type": "application/json"
|
|
76611
|
+
},
|
|
76612
|
+
body: JSON.stringify(input2.setup),
|
|
76613
|
+
signal: AbortSignal.timeout(input2.timeoutMs ?? 2e4)
|
|
76614
|
+
});
|
|
76615
|
+
const body = await response.json();
|
|
76616
|
+
if (!response.ok) {
|
|
76617
|
+
throw new Error(body.error ?? `daemon credential setup failed with HTTP ${response.status}`);
|
|
76618
|
+
}
|
|
76619
|
+
if (typeof body.runtimeId !== "string" || typeof body.credentialGeneration !== "number") {
|
|
76620
|
+
throw new Error("daemon credential setup returned an invalid activation receipt");
|
|
76621
|
+
}
|
|
76622
|
+
return { runtimeId: body.runtimeId, credentialGeneration: body.credentialGeneration };
|
|
76623
|
+
}
|
|
76624
|
+
|
|
76466
76625
|
// src/skills/local-skill-source.ts
|
|
76467
76626
|
var import_node_buffer2 = require("buffer");
|
|
76468
76627
|
var import_node_crypto14 = require("crypto");
|
|
@@ -78923,7 +79082,7 @@ async function startDaemon(args) {
|
|
|
78923
79082
|
getRuntimeToken: () => runtimeToken
|
|
78924
79083
|
});
|
|
78925
79084
|
const runtimeSkillManager = await RuntimeSkillManager.open({
|
|
78926
|
-
homeDirectory: (0,
|
|
79085
|
+
homeDirectory: (0, import_node_os12.homedir)(),
|
|
78927
79086
|
endpointProfile,
|
|
78928
79087
|
profileStorageIdentity: configPath,
|
|
78929
79088
|
controlClient: skillControl
|
|
@@ -78931,7 +79090,7 @@ async function startDaemon(args) {
|
|
|
78931
79090
|
const runtimeSkillCoordinator = new RuntimeSkillCoordinator(
|
|
78932
79091
|
runtimeSkillManager,
|
|
78933
79092
|
skillControl,
|
|
78934
|
-
(input2) => resolveSkillScanInput((0,
|
|
79093
|
+
(input2) => resolveSkillScanInput((0, import_node_os12.homedir)(), input2)
|
|
78935
79094
|
);
|
|
78936
79095
|
const runSkillSync = async (reason) => {
|
|
78937
79096
|
const operation = reason === "startup" ? runtimeSkillCoordinator.runStartup() : reason === "interval" ? runtimeSkillCoordinator.runIncremental() : reason === "refresh" ? runtimeSkillCoordinator.runAudit() : runtimeSkillCoordinator.run();
|
|
@@ -79246,31 +79405,24 @@ async function startDaemon(args) {
|
|
|
79246
79405
|
releaseStartupLease();
|
|
79247
79406
|
throw error61;
|
|
79248
79407
|
}
|
|
79408
|
+
let runtimeCredentialOperationTail = Promise.resolve();
|
|
79409
|
+
const runCredentialOperation = (operation) => {
|
|
79410
|
+
const result = runtimeCredentialOperationTail.catch(() => {
|
|
79411
|
+
}).then(operation);
|
|
79412
|
+
runtimeCredentialOperationTail = result.then(
|
|
79413
|
+
() => {
|
|
79414
|
+
},
|
|
79415
|
+
() => {
|
|
79416
|
+
}
|
|
79417
|
+
);
|
|
79418
|
+
return result;
|
|
79419
|
+
};
|
|
79249
79420
|
let runtimeRenewalInFlight = null;
|
|
79250
79421
|
const renewRuntimeLease = () => {
|
|
79251
79422
|
if (runtimeRenewalInFlight) return runtimeRenewalInFlight;
|
|
79252
|
-
const attempt = (async () => {
|
|
79253
|
-
const
|
|
79254
|
-
|
|
79255
|
-
if (current2.runtimeId !== runtimeId) return false;
|
|
79256
|
-
const nextToken = current2.runtimeToken;
|
|
79257
|
-
const nextRenewal = current2.runtimeRenewalToken;
|
|
79258
|
-
if (typeof nextToken !== "string" || !nextToken.startsWith("alan_runtime_") || typeof nextRenewal !== "string" || !nextRenewal.startsWith("alan_runtime_renew_")) {
|
|
79259
|
-
return false;
|
|
79260
|
-
}
|
|
79261
|
-
if (nextToken === runtimeToken && nextRenewal === runtimeRenewalToken) {
|
|
79262
|
-
return false;
|
|
79263
|
-
}
|
|
79264
|
-
runtimeToken = nextToken;
|
|
79265
|
-
runtimeRenewalToken = nextRenewal;
|
|
79266
|
-
socket.auth = { token: nextToken };
|
|
79267
|
-
clearConnectErrors();
|
|
79268
|
-
pushLog("runtime-credentials-reloaded-from-config");
|
|
79269
|
-
socket.connect();
|
|
79270
|
-
return true;
|
|
79271
|
-
};
|
|
79272
|
-
if (!stored.apiUrl || !runtimeRenewalToken) {
|
|
79273
|
-
if (adoptRewrittenCredentials()) return true;
|
|
79423
|
+
const attempt = runCredentialOperation(async () => {
|
|
79424
|
+
const renewalToken = runtimeRenewalToken;
|
|
79425
|
+
if (!stored.apiUrl || !renewalToken) {
|
|
79274
79426
|
return false;
|
|
79275
79427
|
}
|
|
79276
79428
|
let response = null;
|
|
@@ -79280,7 +79432,7 @@ async function startDaemon(args) {
|
|
|
79280
79432
|
response = await fetch(`${stored.apiUrl}/public/runtimes/${runtimeId}/tokens/renew`, {
|
|
79281
79433
|
method: "POST",
|
|
79282
79434
|
headers: {
|
|
79283
|
-
authorization: `Bearer ${
|
|
79435
|
+
authorization: `Bearer ${renewalToken}`,
|
|
79284
79436
|
"content-type": "application/json"
|
|
79285
79437
|
},
|
|
79286
79438
|
body: "{}",
|
|
@@ -79302,9 +79454,6 @@ async function startDaemon(args) {
|
|
|
79302
79454
|
return false;
|
|
79303
79455
|
}
|
|
79304
79456
|
if (!response.ok) {
|
|
79305
|
-
if (response.status === 401 && adoptRewrittenCredentials()) {
|
|
79306
|
-
return true;
|
|
79307
|
-
}
|
|
79308
79457
|
const code = response.status === 401 ? "runtime_renewal_rejected" : response.status === 403 ? "runtime_disabled" : response.status === 410 ? "runtime_deleted" : response.status >= 500 ? "backend_unreachable" : "runtime_renewal_failed";
|
|
79309
79458
|
rememberConnectErrorCode(code);
|
|
79310
79459
|
lastConnectError = `Runtime renewal failed: ${response.status} ${await response.text()}`;
|
|
@@ -79319,8 +79468,7 @@ async function startDaemon(args) {
|
|
|
79319
79468
|
return false;
|
|
79320
79469
|
}
|
|
79321
79470
|
const current = readConfig();
|
|
79322
|
-
if (current.runtimeId !== runtimeId || current.runtimeRenewalToken !==
|
|
79323
|
-
if (adoptRewrittenCredentials()) return true;
|
|
79471
|
+
if (current.runtimeId !== runtimeId || current.runtimeRenewalToken !== renewalToken) {
|
|
79324
79472
|
rememberConnectErrorCode("runtime_renewal_superseded");
|
|
79325
79473
|
lastConnectError = "Runtime credentials changed while renewal was in progress";
|
|
79326
79474
|
pushLog("runtime-renewal-superseded");
|
|
@@ -79340,7 +79488,7 @@ async function startDaemon(args) {
|
|
|
79340
79488
|
pushLog("runtime-renewal-succeeded");
|
|
79341
79489
|
socket.connect();
|
|
79342
79490
|
return true;
|
|
79343
|
-
})
|
|
79491
|
+
});
|
|
79344
79492
|
runtimeRenewalInFlight = attempt;
|
|
79345
79493
|
void attempt.finally(() => {
|
|
79346
79494
|
if (runtimeRenewalInFlight === attempt) runtimeRenewalInFlight = null;
|
|
@@ -79348,6 +79496,88 @@ async function startDaemon(args) {
|
|
|
79348
79496
|
});
|
|
79349
79497
|
return attempt;
|
|
79350
79498
|
};
|
|
79499
|
+
let queueIdentityRestart = () => {
|
|
79500
|
+
};
|
|
79501
|
+
let runtimeSetupInFlight = null;
|
|
79502
|
+
const adoptRuntimeSetupGrant = (input2) => {
|
|
79503
|
+
if (runtimeSetupInFlight) return runtimeSetupInFlight;
|
|
79504
|
+
const attempt = runCredentialOperation(async () => {
|
|
79505
|
+
const activeRunCount = activeAgents.size + pendingRunStarts.size;
|
|
79506
|
+
if (activeRunCount > 0) {
|
|
79507
|
+
throw new Error(
|
|
79508
|
+
`credential setup is deferred while ${activeRunCount} active run${activeRunCount === 1 ? " finishes" : "s finish"}`
|
|
79509
|
+
);
|
|
79510
|
+
}
|
|
79511
|
+
const current = readConfig();
|
|
79512
|
+
if (current.runtimeId !== runtimeId || current.installationId !== installationId || input2.installationId !== installationId) {
|
|
79513
|
+
throw new Error("credential setup does not belong to this daemon installation");
|
|
79514
|
+
}
|
|
79515
|
+
if (input2.apiUrl !== stored.apiUrl || input2.wsUrl !== wsUrl) {
|
|
79516
|
+
throw new Error("credential setup cannot change a running daemon's endpoints");
|
|
79517
|
+
}
|
|
79518
|
+
const bundle = await exchangeRuntimeSetupGrant(input2);
|
|
79519
|
+
if (bundle.runtimeId !== runtimeId) {
|
|
79520
|
+
writeConfig({
|
|
79521
|
+
...current,
|
|
79522
|
+
runtimeId: bundle.runtimeId,
|
|
79523
|
+
runtimeToken: bundle.runtimeToken,
|
|
79524
|
+
runtimeRenewalToken: bundle.runtimeRenewalToken,
|
|
79525
|
+
displayName: bundle.displayName
|
|
79526
|
+
});
|
|
79527
|
+
clearPendingSetupIntent();
|
|
79528
|
+
pushLog(
|
|
79529
|
+
`runtime-identity-switch-queued from=${runtimeId} to=${bundle.runtimeId} generation=${bundle.credentialGeneration}`
|
|
79530
|
+
);
|
|
79531
|
+
const restartTimer = setTimeout(queueIdentityRestart, 100);
|
|
79532
|
+
restartTimer.unref?.();
|
|
79533
|
+
return {
|
|
79534
|
+
runtimeId: bundle.runtimeId,
|
|
79535
|
+
credentialGeneration: bundle.credentialGeneration
|
|
79536
|
+
};
|
|
79537
|
+
}
|
|
79538
|
+
writeConfig({
|
|
79539
|
+
...current,
|
|
79540
|
+
runtimeToken: bundle.runtimeToken,
|
|
79541
|
+
runtimeRenewalToken: bundle.runtimeRenewalToken,
|
|
79542
|
+
displayName: bundle.displayName
|
|
79543
|
+
});
|
|
79544
|
+
clearPendingSetupIntent();
|
|
79545
|
+
runtimeToken = bundle.runtimeToken;
|
|
79546
|
+
runtimeRenewalToken = bundle.runtimeRenewalToken;
|
|
79547
|
+
socket.auth = { token: bundle.runtimeToken };
|
|
79548
|
+
clearConnectErrors();
|
|
79549
|
+
const ready = new Promise((resolveReady, rejectReady) => {
|
|
79550
|
+
const timeout = setTimeout(() => {
|
|
79551
|
+
socket.off("runtime.ready", onReady);
|
|
79552
|
+
rejectReady(
|
|
79553
|
+
new Error("backend did not acknowledge the replacement credential generation")
|
|
79554
|
+
);
|
|
79555
|
+
}, 15e3);
|
|
79556
|
+
const onReady = (payload) => {
|
|
79557
|
+
if (payload?.credentialGeneration !== bundle.credentialGeneration) return;
|
|
79558
|
+
clearTimeout(timeout);
|
|
79559
|
+
socket.off("runtime.ready", onReady);
|
|
79560
|
+
resolveReady();
|
|
79561
|
+
};
|
|
79562
|
+
socket.on("runtime.ready", onReady);
|
|
79563
|
+
});
|
|
79564
|
+
pushLog(`runtime-credential-setup-redial generation=${bundle.credentialGeneration}`);
|
|
79565
|
+
if (socket.connected) socket.disconnect();
|
|
79566
|
+
socket.connect();
|
|
79567
|
+
await ready;
|
|
79568
|
+
pushLog(`runtime-credential-setup-ready generation=${bundle.credentialGeneration}`);
|
|
79569
|
+
return {
|
|
79570
|
+
runtimeId: bundle.runtimeId,
|
|
79571
|
+
credentialGeneration: bundle.credentialGeneration
|
|
79572
|
+
};
|
|
79573
|
+
});
|
|
79574
|
+
runtimeSetupInFlight = attempt;
|
|
79575
|
+
void attempt.finally(() => {
|
|
79576
|
+
if (runtimeSetupInFlight === attempt) runtimeSetupInFlight = null;
|
|
79577
|
+
}).catch(() => {
|
|
79578
|
+
});
|
|
79579
|
+
return attempt;
|
|
79580
|
+
};
|
|
79351
79581
|
const relocationInFlight = /* @__PURE__ */ new Set();
|
|
79352
79582
|
const persistWorkspaceRelocations = () => {
|
|
79353
79583
|
const current = readConfig();
|
|
@@ -79555,6 +79785,16 @@ async function startDaemon(args) {
|
|
|
79555
79785
|
const wsHint = isLocalEndpoint(wsUrl) ? ` Nothing is listening at ${wsUrl}. For local dev run setup with --profile local and start the stack (WS on ws://localhost:8401).` : ` Verify wsUrl in ${getConfigPath()} and that you can reach ${wsUrl}.`;
|
|
79556
79786
|
console.warn("[alan-agent] Daemon connection error:", `${error61.message}.${wsHint}`);
|
|
79557
79787
|
});
|
|
79788
|
+
socket.on("connection_directive", (value2) => {
|
|
79789
|
+
if (!value2 || typeof value2 !== "object") return;
|
|
79790
|
+
const directive = value2;
|
|
79791
|
+
if (directive.retryable !== false || typeof directive.code !== "string") return;
|
|
79792
|
+
rememberConnectErrorCode(directive.code);
|
|
79793
|
+
if (typeof directive.reason === "string") lastConnectError = directive.reason;
|
|
79794
|
+
pushLog(
|
|
79795
|
+
`connection_directive ${directive.code}${lastConnectError ? ` reason=${lastConnectError}` : ""}`
|
|
79796
|
+
);
|
|
79797
|
+
});
|
|
79558
79798
|
socket.on("disconnect", (reason) => {
|
|
79559
79799
|
setConnectedRuntimeSocket(null);
|
|
79560
79800
|
relocationInFlight.clear();
|
|
@@ -79773,7 +80013,8 @@ async function startDaemon(args) {
|
|
|
79773
80013
|
queueFullShutdown: () => queueFullShutdown(),
|
|
79774
80014
|
wsUrl,
|
|
79775
80015
|
inspectLocalSkill: (input2) => runtimeSkillManager.inspectLocalPackage(input2),
|
|
79776
|
-
readLocalSkillFile: (input2) => runtimeSkillManager.readLocalPackageFile(input2)
|
|
80016
|
+
readLocalSkillFile: (input2) => runtimeSkillManager.readLocalPackageFile(input2),
|
|
80017
|
+
adoptRuntimeSetupGrant
|
|
79777
80018
|
})
|
|
79778
80019
|
);
|
|
79779
80020
|
const occupiedProbe = await probeLocalDaemonEndpoint(localApiPort, localApiToken);
|
|
@@ -79906,6 +80147,9 @@ async function startDaemon(args) {
|
|
|
79906
80147
|
queueFullShutdown = () => {
|
|
79907
80148
|
void stop().then(() => controller.whenExternallyStopped?.());
|
|
79908
80149
|
};
|
|
80150
|
+
queueIdentityRestart = () => {
|
|
80151
|
+
void stop().then(() => controller.whenExternallyStopped?.("runtime_identity_changed"));
|
|
80152
|
+
};
|
|
79909
80153
|
return controller;
|
|
79910
80154
|
}
|
|
79911
80155
|
|
|
@@ -79967,7 +80211,7 @@ async function setupDaemon(args) {
|
|
|
79967
80211
|
const teamId = argValue(args, "--team") ?? process.env.ALAN_TEAM_ID;
|
|
79968
80212
|
const setupToken = argValue(args, "--setup-token") ?? process.env.ALAN_RUNTIME_SETUP_TOKEN;
|
|
79969
80213
|
const token = argValue(args, "--token") ?? process.env.ALAN_SETUP_TOKEN;
|
|
79970
|
-
const displayName = argValue(args, "--name") ?? (0,
|
|
80214
|
+
const displayName = argValue(args, "--name") ?? (0, import_node_os13.hostname)();
|
|
79971
80215
|
const scope = argValue(args, "--scope") ?? process.env.ALAN_RUNTIME_SCOPE ?? (setupToken ? "team" : "user");
|
|
79972
80216
|
const installationId = argValue(args, "--installation-id") ?? previousConfig.installationId ?? (0, import_node_crypto19.randomUUID)();
|
|
79973
80217
|
if (scope !== "team" && scope !== "user") {
|
|
@@ -79978,69 +80222,71 @@ async function setupDaemon(args) {
|
|
|
79978
80222
|
"setup requires --setup-token <token> or --token <Alan access token>.\nFor normal setup, copy the setup token from Alan and run: alan-agent setup --setup-token <token>\nFor browser authorization, run: alan-agent login"
|
|
79979
80223
|
);
|
|
79980
80224
|
}
|
|
79981
|
-
const
|
|
79982
|
-
|
|
79983
|
-
|
|
79984
|
-
|
|
79985
|
-
|
|
79986
|
-
|
|
79987
|
-
|
|
79988
|
-
|
|
79989
|
-
|
|
79990
|
-
|
|
79991
|
-
|
|
79992
|
-
|
|
79993
|
-
|
|
79994
|
-
|
|
79995
|
-
managementKind: "user_managed",
|
|
79996
|
-
hostKind: "daemon",
|
|
79997
|
-
lifecycle: "durable",
|
|
79998
|
-
capabilities: discoverCapabilities(),
|
|
79999
|
-
metadata: {
|
|
80000
|
-
...await collectRuntimeMetadataWithProviderLimits(),
|
|
80001
|
-
installationId
|
|
80002
|
-
}
|
|
80003
|
-
})
|
|
80225
|
+
const registrationGrant = setupToken ?? await createRuntimeSetupGrant({
|
|
80226
|
+
apiUrl,
|
|
80227
|
+
accessToken: token,
|
|
80228
|
+
scope,
|
|
80229
|
+
teamId
|
|
80230
|
+
});
|
|
80231
|
+
const setup = {
|
|
80232
|
+
apiUrl,
|
|
80233
|
+
wsUrl,
|
|
80234
|
+
endpointProfile,
|
|
80235
|
+
setupToken: registrationGrant,
|
|
80236
|
+
teamId,
|
|
80237
|
+
displayName,
|
|
80238
|
+
installationId
|
|
80004
80239
|
};
|
|
80005
|
-
let
|
|
80006
|
-
|
|
80007
|
-
|
|
80008
|
-
|
|
80009
|
-
|
|
80010
|
-
|
|
80011
|
-
|
|
80012
|
-
|
|
80013
|
-
|
|
80014
|
-
|
|
80015
|
-
|
|
80016
|
-
|
|
80240
|
+
let liveConfig = previousConfig;
|
|
80241
|
+
const localApiPort = getLocalApiPort(args, liveConfig);
|
|
80242
|
+
let live = liveConfig.localApiToken ? await probeLocalDaemon(localApiPort, liveConfig.localApiToken) : null;
|
|
80243
|
+
if (!live && liveConfig.localServiceId && liveConfig.localServiceSecret) {
|
|
80244
|
+
live = await adoptConfiguredLocalDaemon(args);
|
|
80245
|
+
liveConfig = readConfigForRegistration();
|
|
80246
|
+
}
|
|
80247
|
+
if (live) {
|
|
80248
|
+
if (!liveConfig.localApiToken) {
|
|
80249
|
+
throw new Error("running daemon could not be authenticated for credential setup");
|
|
80250
|
+
}
|
|
80251
|
+
const liveSetup = {
|
|
80252
|
+
...setup,
|
|
80253
|
+
apiUrl: liveConfig.apiUrl ?? setup.apiUrl,
|
|
80254
|
+
wsUrl: liveConfig.wsUrl ?? setup.wsUrl,
|
|
80255
|
+
endpointProfile: liveConfig.endpointProfile ?? setup.endpointProfile
|
|
80256
|
+
};
|
|
80257
|
+
const body2 = await handoffRuntimeSetupGrant({
|
|
80258
|
+
port: localApiPort,
|
|
80259
|
+
localApiToken: liveConfig.localApiToken,
|
|
80260
|
+
setup: liveSetup
|
|
80261
|
+
});
|
|
80262
|
+
console.info("[alan-agent] Runtime credentials adopted by running daemon", {
|
|
80263
|
+
runtimeId: body2.runtimeId,
|
|
80264
|
+
credentialGeneration: body2.credentialGeneration,
|
|
80265
|
+
configPath: getConfigPath()
|
|
80266
|
+
});
|
|
80267
|
+
return { daemonAlreadyRunning: true };
|
|
80017
80268
|
}
|
|
80018
|
-
if (
|
|
80019
|
-
|
|
80020
|
-
|
|
80269
|
+
if (readLocalDaemonOwnerLease(getConfigPath())) {
|
|
80270
|
+
throw new Error(
|
|
80271
|
+
"the daemon still owns this runtime configuration, but its authenticated local API is unreachable; recover or stop the daemon before running setup again"
|
|
80272
|
+
);
|
|
80021
80273
|
}
|
|
80022
|
-
|
|
80023
|
-
|
|
80024
|
-
|
|
80025
|
-
|
|
80026
|
-
|
|
80027
|
-
if (typeof parsed.error === "string") errorCode2 = parsed.error;
|
|
80028
|
-
} catch {
|
|
80029
|
-
}
|
|
80030
|
-
if (setupToken && response.status === 401 && errorCode2 === "setup_token_expired") {
|
|
80031
|
-
clearPendingSetupIntent();
|
|
80274
|
+
let body;
|
|
80275
|
+
try {
|
|
80276
|
+
body = await exchangeRuntimeSetupGrant(setup);
|
|
80277
|
+
} catch (error61) {
|
|
80278
|
+
if (setupToken && error61 instanceof RuntimeSetupGrantExpiredError) {
|
|
80032
80279
|
console.info("[alan-agent] Setup link expired; continuing with browser authorization");
|
|
80033
80280
|
await loginWithDeviceCode(args);
|
|
80034
|
-
return;
|
|
80281
|
+
return { daemonAlreadyRunning: false };
|
|
80035
80282
|
}
|
|
80036
|
-
throw
|
|
80283
|
+
throw error61;
|
|
80037
80284
|
}
|
|
80038
|
-
const body = await response.json();
|
|
80039
80285
|
writeConfig({
|
|
80040
80286
|
apiUrl,
|
|
80041
80287
|
wsUrl,
|
|
80042
80288
|
endpointProfile,
|
|
80043
|
-
runtimeId: body.
|
|
80289
|
+
runtimeId: body.runtimeId,
|
|
80044
80290
|
runtimeToken: body.runtimeToken,
|
|
80045
80291
|
runtimeRenewalToken: body.runtimeRenewalToken,
|
|
80046
80292
|
localApiPort: getLocalApiPort(args, {}),
|
|
@@ -80049,14 +80295,15 @@ async function setupDaemon(args) {
|
|
|
80049
80295
|
localServiceSecret: previousConfig.localServiceSecret ?? (0, import_node_crypto19.randomBytes)(32).toString("base64url"),
|
|
80050
80296
|
eventSpoolKey: previousConfig.eventSpoolKey ?? (0, import_node_crypto19.randomBytes)(32).toString("base64url"),
|
|
80051
80297
|
daemonEpoch: previousConfig.daemonEpoch,
|
|
80052
|
-
displayName: body.
|
|
80298
|
+
displayName: body.displayName,
|
|
80053
80299
|
installationId
|
|
80054
80300
|
});
|
|
80055
|
-
|
|
80301
|
+
clearPendingSetupIntent();
|
|
80056
80302
|
console.info("[alan-agent] Runtime registered", {
|
|
80057
|
-
runtimeId: body.
|
|
80303
|
+
runtimeId: body.runtimeId,
|
|
80058
80304
|
configPath: getConfigPath()
|
|
80059
80305
|
});
|
|
80306
|
+
return { daemonAlreadyRunning: false };
|
|
80060
80307
|
}
|
|
80061
80308
|
async function loginWithDeviceCode(args) {
|
|
80062
80309
|
bindConfigPath(args);
|
|
@@ -80074,7 +80321,7 @@ async function loginWithDeviceCode(args) {
|
|
|
80074
80321
|
}
|
|
80075
80322
|
const previousConfig = readConfigForRegistration();
|
|
80076
80323
|
const { apiUrl, wsUrl, endpointProfile } = resolveEndpoints(args);
|
|
80077
|
-
const displayName = argValue(args, "--name") ?? (0,
|
|
80324
|
+
const displayName = argValue(args, "--name") ?? (0, import_node_os13.hostname)();
|
|
80078
80325
|
const maxPolls = Number.parseInt(argValue(args, "--max-polls") ?? "300", 10);
|
|
80079
80326
|
const resumed = readPendingDeviceAuthorization(apiUrl);
|
|
80080
80327
|
const installationId = resumed?.installationId ?? previousConfig.installationId ?? (0, import_node_crypto19.randomUUID)();
|
|
@@ -80086,7 +80333,7 @@ async function loginWithDeviceCode(args) {
|
|
|
80086
80333
|
headers: { "content-type": "application/json" },
|
|
80087
80334
|
body: JSON.stringify({
|
|
80088
80335
|
displayName,
|
|
80089
|
-
hostname: (0,
|
|
80336
|
+
hostname: (0, import_node_os13.hostname)(),
|
|
80090
80337
|
capabilities: discoverCapabilities(),
|
|
80091
80338
|
metadata: {
|
|
80092
80339
|
...await collectRuntimeMetadataWithProviderLimits(),
|
|
@@ -80245,8 +80492,8 @@ async function runDaemon(args) {
|
|
|
80245
80492
|
return;
|
|
80246
80493
|
}
|
|
80247
80494
|
const controller = await startDaemon(args);
|
|
80248
|
-
const shutdown = () => {
|
|
80249
|
-
void controller.stop().finally(() => process.exit(
|
|
80495
|
+
const shutdown = (reason) => {
|
|
80496
|
+
void controller.stop().finally(() => process.exit(daemonExternalStopExitCode(reason)));
|
|
80250
80497
|
};
|
|
80251
80498
|
controller.whenExternallyStopped = shutdown;
|
|
80252
80499
|
process.once("SIGINT", shutdown);
|
|
@@ -80254,6 +80501,9 @@ async function runDaemon(args) {
|
|
|
80254
80501
|
await new Promise(() => {
|
|
80255
80502
|
});
|
|
80256
80503
|
}
|
|
80504
|
+
function daemonExternalStopExitCode(reason) {
|
|
80505
|
+
return reason === "runtime_identity_changed" ? 1 : 0;
|
|
80506
|
+
}
|
|
80257
80507
|
async function recoverDaemonConnection(args = [], options) {
|
|
80258
80508
|
bindConfigPath(args);
|
|
80259
80509
|
const getStatus = async () => {
|
|
@@ -80516,7 +80766,7 @@ async function printDoctor(args = []) {
|
|
|
80516
80766
|
// src/mcp-config-adapters.ts
|
|
80517
80767
|
var import_node_crypto20 = require("crypto");
|
|
80518
80768
|
var import_node_fs23 = require("fs");
|
|
80519
|
-
var
|
|
80769
|
+
var import_node_os14 = require("os");
|
|
80520
80770
|
var import_node_path25 = require("path");
|
|
80521
80771
|
var log = {
|
|
80522
80772
|
info: (...args) => console.info("[mcp-config-adapters]", ...args),
|
|
@@ -80526,7 +80776,7 @@ var log = {
|
|
|
80526
80776
|
};
|
|
80527
80777
|
var homeDirectoryOverride;
|
|
80528
80778
|
function homeDirectory() {
|
|
80529
|
-
return homeDirectoryOverride ?? (0,
|
|
80779
|
+
return homeDirectoryOverride ?? (0, import_node_os14.homedir)();
|
|
80530
80780
|
}
|
|
80531
80781
|
var MalformedToolConfigError = class extends Error {
|
|
80532
80782
|
};
|
|
@@ -81271,7 +81521,7 @@ var McpSyncService = class {
|
|
|
81271
81521
|
|
|
81272
81522
|
// src/native-hook-config.ts
|
|
81273
81523
|
var import_node_fs24 = require("fs");
|
|
81274
|
-
var
|
|
81524
|
+
var import_node_os15 = require("os");
|
|
81275
81525
|
var import_node_path26 = require("path");
|
|
81276
81526
|
var ALAN_HOOK_MARKER = "# alan-native-session-hook";
|
|
81277
81527
|
var ALAN_KIMI_HOOKS_START = "# alan-native-session-hooks:start";
|
|
@@ -81365,7 +81615,7 @@ function nativeHookCommand(input2) {
|
|
|
81365
81615
|
if (environment.length === 0) {
|
|
81366
81616
|
return { type: "command", command: input2.nodeExecutable, args, timeout: 5 };
|
|
81367
81617
|
}
|
|
81368
|
-
if ((input2.platform ?? (0,
|
|
81618
|
+
if ((input2.platform ?? (0, import_node_os15.platform)()) === "win32") {
|
|
81369
81619
|
const environmentPrefix2 = environment.map(([key, value2]) => `$env:${key}=${powershellQuote(value2)}`).join("; ");
|
|
81370
81620
|
const command2 = [input2.nodeExecutable, ...args].map(powershellQuote).join(" ");
|
|
81371
81621
|
return {
|
|
@@ -81410,11 +81660,11 @@ function resolveRuntime(input2 = {}) {
|
|
|
81410
81660
|
}
|
|
81411
81661
|
return {
|
|
81412
81662
|
configPath,
|
|
81413
|
-
homeDir: input2.homeDir ?? (0,
|
|
81663
|
+
homeDir: input2.homeDir ?? (0, import_node_os15.homedir)(),
|
|
81414
81664
|
nodeExecutable: input2.nodeExecutable ?? process.execPath,
|
|
81415
81665
|
cliEntry,
|
|
81416
81666
|
environment: input2.environment,
|
|
81417
|
-
platform: input2.platform ?? (0,
|
|
81667
|
+
platform: input2.platform ?? (0, import_node_os15.platform)()
|
|
81418
81668
|
};
|
|
81419
81669
|
}
|
|
81420
81670
|
function readSettings(path2, providerLabel) {
|
|
@@ -81505,7 +81755,7 @@ function reconcileClaudeNativeHooks(input2 = {}) {
|
|
|
81505
81755
|
})
|
|
81506
81756
|
});
|
|
81507
81757
|
}
|
|
81508
|
-
function removeClaudeNativeHooks(homeDir = (0,
|
|
81758
|
+
function removeClaudeNativeHooks(homeDir = (0, import_node_os15.homedir)()) {
|
|
81509
81759
|
return removeNestedCommandHooks((0, import_node_path26.join)(homeDir, ".claude", "settings.json"), "Claude");
|
|
81510
81760
|
}
|
|
81511
81761
|
function reconcileCodexNativeHooks(input2 = {}) {
|
|
@@ -81522,7 +81772,7 @@ function reconcileCodexNativeHooks(input2 = {}) {
|
|
|
81522
81772
|
})
|
|
81523
81773
|
});
|
|
81524
81774
|
}
|
|
81525
|
-
function removeCodexNativeHooks(homeDir = (0,
|
|
81775
|
+
function removeCodexNativeHooks(homeDir = (0, import_node_os15.homedir)()) {
|
|
81526
81776
|
return removeNestedCommandHooks((0, import_node_path26.join)(homeDir, ".codex", "hooks.json"), "Codex");
|
|
81527
81777
|
}
|
|
81528
81778
|
function reconcileCopilotNativeHooks(input2 = {}) {
|
|
@@ -81546,7 +81796,7 @@ function reconcileCopilotNativeHooks(input2 = {}) {
|
|
|
81546
81796
|
);
|
|
81547
81797
|
return writeSettings(path2, { version: 1, hooks });
|
|
81548
81798
|
}
|
|
81549
|
-
function removeCopilotNativeHooks(homeDir = (0,
|
|
81799
|
+
function removeCopilotNativeHooks(homeDir = (0, import_node_os15.homedir)()) {
|
|
81550
81800
|
const path2 = (0, import_node_path26.join)(homeDir, ".copilot", "hooks", "alan-native-session.json");
|
|
81551
81801
|
if (!(0, import_node_fs24.existsSync)(path2)) return false;
|
|
81552
81802
|
if (!(0, import_node_fs24.readFileSync)(path2, "utf8").includes(ALAN_HOOK_MARKER)) return false;
|
|
@@ -81571,7 +81821,7 @@ function reconcileCursorNativeHooks(input2 = {}) {
|
|
|
81571
81821
|
}
|
|
81572
81822
|
return writeSettings(path2, { ...settings, version: settings.version ?? 1, hooks });
|
|
81573
81823
|
}
|
|
81574
|
-
function removeCursorNativeHooks(homeDir = (0,
|
|
81824
|
+
function removeCursorNativeHooks(homeDir = (0, import_node_os15.homedir)()) {
|
|
81575
81825
|
const path2 = (0, import_node_path26.join)(homeDir, ".cursor", "hooks.json");
|
|
81576
81826
|
if (!(0, import_node_fs24.existsSync)(path2)) return false;
|
|
81577
81827
|
const settings = readSettings(path2, "Cursor");
|
|
@@ -81609,7 +81859,7 @@ function reconcileKimiNativeHooks(input2 = {}) {
|
|
|
81609
81859
|
`;
|
|
81610
81860
|
return writeTextFile(path2, content);
|
|
81611
81861
|
}
|
|
81612
|
-
function removeKimiNativeHooks(homeDir = (0,
|
|
81862
|
+
function removeKimiNativeHooks(homeDir = (0, import_node_os15.homedir)()) {
|
|
81613
81863
|
const path2 = (0, import_node_path26.join)(homeDir, ".kimi-code", "config.toml");
|
|
81614
81864
|
if (!(0, import_node_fs24.existsSync)(path2)) return false;
|
|
81615
81865
|
const current = (0, import_node_fs24.readFileSync)(path2, "utf8");
|
|
@@ -81635,7 +81885,7 @@ function reconcileGrokNativeHooks(input2 = {}) {
|
|
|
81635
81885
|
})
|
|
81636
81886
|
});
|
|
81637
81887
|
}
|
|
81638
|
-
function removeGrokNativeHooks(homeDir = (0,
|
|
81888
|
+
function removeGrokNativeHooks(homeDir = (0, import_node_os15.homedir)()) {
|
|
81639
81889
|
const path2 = (0, import_node_path26.join)(homeDir, ".grok", "hooks", "alan-native-session.json");
|
|
81640
81890
|
if (!(0, import_node_fs24.existsSync)(path2)) return false;
|
|
81641
81891
|
if (!(0, import_node_fs24.readFileSync)(path2, "utf8").includes(ALAN_HOOK_MARKER)) return false;
|
|
@@ -81739,7 +81989,7 @@ function reconcileOpencodeNativePlugin(input2 = {}) {
|
|
|
81739
81989
|
(0, import_node_fs24.renameSync)(temporary, path2);
|
|
81740
81990
|
return true;
|
|
81741
81991
|
}
|
|
81742
|
-
function removeOpencodeNativePlugin(homeDir = (0,
|
|
81992
|
+
function removeOpencodeNativePlugin(homeDir = (0, import_node_os15.homedir)()) {
|
|
81743
81993
|
const path2 = (0, import_node_path26.join)(homeDir, ".config", "opencode", "plugins", "alan-native-session.js");
|
|
81744
81994
|
if (!(0, import_node_fs24.existsSync)(path2)) return false;
|
|
81745
81995
|
if (!(0, import_node_fs24.readFileSync)(path2, "utf8").includes(ALAN_OPENCODE_PLUGIN_MARKER)) return false;
|
|
@@ -81754,7 +82004,7 @@ function configFileContainsMarker(path2, marker) {
|
|
|
81754
82004
|
return false;
|
|
81755
82005
|
}
|
|
81756
82006
|
}
|
|
81757
|
-
function inspectNativeHooksConfigured(providerKind, homeDir = (0,
|
|
82007
|
+
function inspectNativeHooksConfigured(providerKind, homeDir = (0, import_node_os15.homedir)(), expectedConfigPath) {
|
|
81758
82008
|
const matchesActiveProfile = (path2, marker) => {
|
|
81759
82009
|
if (!configFileContainsMarker(path2, marker)) return false;
|
|
81760
82010
|
if (!expectedConfigPath) return true;
|
|
@@ -94335,7 +94585,7 @@ async function runMcpStdioProxy(env = process.env, local = new StdioServerTransp
|
|
|
94335
94585
|
// src/native-hook-command.ts
|
|
94336
94586
|
var import_node_crypto21 = require("crypto");
|
|
94337
94587
|
var import_node_fs26 = require("fs");
|
|
94338
|
-
var
|
|
94588
|
+
var import_node_os16 = require("os");
|
|
94339
94589
|
var import_node_path28 = require("path");
|
|
94340
94590
|
|
|
94341
94591
|
// src/native-project-config.ts
|
|
@@ -94615,7 +94865,7 @@ function resolveCodexSessionIdFromTranscriptPath(transcriptPath) {
|
|
|
94615
94865
|
);
|
|
94616
94866
|
return match?.[1];
|
|
94617
94867
|
}
|
|
94618
|
-
function resolveKimiTranscriptPath(externalSessionId, kimiHomeDir = process.env.KIMI_CODE_HOME?.trim() || (0, import_node_path28.join)((0,
|
|
94868
|
+
function resolveKimiTranscriptPath(externalSessionId, kimiHomeDir = process.env.KIMI_CODE_HOME?.trim() || (0, import_node_path28.join)((0, import_node_os16.homedir)(), ".kimi-code")) {
|
|
94619
94869
|
if ((0, import_node_path28.basename)(externalSessionId) !== externalSessionId) return void 0;
|
|
94620
94870
|
const sessionsDir = (0, import_node_path28.join)(kimiHomeDir, "sessions");
|
|
94621
94871
|
if (!(0, import_node_fs26.existsSync)(sessionsDir)) return void 0;
|
|
@@ -94840,7 +95090,7 @@ function collectNativeIntegrationStatus(args = []) {
|
|
|
94840
95090
|
const config2 = readConfig();
|
|
94841
95091
|
const configPath = getConfigPath();
|
|
94842
95092
|
const env = getDaemonCliEnvironment();
|
|
94843
|
-
const homeDir = (0,
|
|
95093
|
+
const homeDir = (0, import_node_os16.homedir)();
|
|
94844
95094
|
return NATIVE_SESSION_PROVIDER_CAPABILITIES.map((capability) => ({
|
|
94845
95095
|
provider: capability.providerKind,
|
|
94846
95096
|
command: capability.command,
|
|
@@ -94869,7 +95119,7 @@ function decodeResumeFallbackContext(encoded) {
|
|
|
94869
95119
|
}
|
|
94870
95120
|
|
|
94871
95121
|
// src/sandbox.ts
|
|
94872
|
-
var
|
|
95122
|
+
var import_node_os17 = require("os");
|
|
94873
95123
|
|
|
94874
95124
|
// src/execution-activity-tracker.ts
|
|
94875
95125
|
var ExecutionActivityTracker = class {
|
|
@@ -95484,10 +95734,6 @@ var agentProbeAckSchema = external_exports.object({
|
|
|
95484
95734
|
// src/sandbox-outbox.ts
|
|
95485
95735
|
var import_node_crypto23 = require("crypto");
|
|
95486
95736
|
var import_node_fs27 = require("fs");
|
|
95487
|
-
var SANDBOX_EVENT_OUTBOX_ENV = "ALAN_EVENT_OUTBOX_ENABLED";
|
|
95488
|
-
function isSandboxEventOutboxEnabled(env = process.env) {
|
|
95489
|
-
return env[SANDBOX_EVENT_OUTBOX_ENV] === "true";
|
|
95490
|
-
}
|
|
95491
95737
|
function deriveSandboxOutboxKey(sessionToken) {
|
|
95492
95738
|
if (!sessionToken) {
|
|
95493
95739
|
throw new Error("sandbox event outbox requires ALAN_SESSION_TOKEN for key derivation");
|
|
@@ -95497,16 +95743,50 @@ function deriveSandboxOutboxKey(sessionToken) {
|
|
|
95497
95743
|
function sandboxOutboxSpoolPath(conversationId) {
|
|
95498
95744
|
return `/tmp/alan-agent-outbox-${conversationId}.enc`;
|
|
95499
95745
|
}
|
|
95746
|
+
function sandboxOutboxKeyPath(spoolPath) {
|
|
95747
|
+
return `${spoolPath}.key`;
|
|
95748
|
+
}
|
|
95749
|
+
function assertValidOutboxKey(key, path2) {
|
|
95750
|
+
if (Buffer.from(key, "base64url").length !== 32) {
|
|
95751
|
+
throw new Error(`sandbox event outbox key at ${path2} must contain exactly 32 bytes`);
|
|
95752
|
+
}
|
|
95753
|
+
return key;
|
|
95754
|
+
}
|
|
95755
|
+
function loadOrCreateSandboxOutboxKey(input2) {
|
|
95756
|
+
const keyPath = sandboxOutboxKeyPath(input2.spoolPath);
|
|
95757
|
+
if ((0, import_node_fs27.existsSync)(keyPath)) {
|
|
95758
|
+
(0, import_node_fs27.chmodSync)(keyPath, 384);
|
|
95759
|
+
return assertValidOutboxKey((0, import_node_fs27.readFileSync)(keyPath, "utf8").trim(), keyPath);
|
|
95760
|
+
}
|
|
95761
|
+
const initialKey = deriveSandboxOutboxKey(input2.sessionToken);
|
|
95762
|
+
try {
|
|
95763
|
+
(0, import_node_fs27.writeFileSync)(keyPath, initialKey, { encoding: "utf8", flag: "wx", mode: 384 });
|
|
95764
|
+
return initialKey;
|
|
95765
|
+
} catch (error61) {
|
|
95766
|
+
if (error61.code !== "EEXIST") throw error61;
|
|
95767
|
+
(0, import_node_fs27.chmodSync)(keyPath, 384);
|
|
95768
|
+
return assertValidOutboxKey((0, import_node_fs27.readFileSync)(keyPath, "utf8").trim(), keyPath);
|
|
95769
|
+
}
|
|
95770
|
+
}
|
|
95771
|
+
function quarantineUnusableOutbox(path2) {
|
|
95772
|
+
const suffix = `corrupt-${Date.now()}-${process.pid}`;
|
|
95773
|
+
for (const candidate of [path2, eventJournalDir(path2)]) {
|
|
95774
|
+
if ((0, import_node_fs27.existsSync)(candidate)) (0, import_node_fs27.renameSync)(candidate, `${candidate}.${suffix}`);
|
|
95775
|
+
}
|
|
95776
|
+
}
|
|
95500
95777
|
function createSandboxEventOutbox(input2) {
|
|
95501
95778
|
const path2 = input2.spoolPath ?? sandboxOutboxSpoolPath(input2.conversationId);
|
|
95502
|
-
const key =
|
|
95779
|
+
const key = loadOrCreateSandboxOutboxKey({
|
|
95780
|
+
spoolPath: path2,
|
|
95781
|
+
sessionToken: input2.sessionToken
|
|
95782
|
+
});
|
|
95503
95783
|
try {
|
|
95504
95784
|
return new EncryptedEventOutbox(path2, key, input2.pushLog, input2.options);
|
|
95505
95785
|
} catch (error61) {
|
|
95506
95786
|
input2.pushLog?.(
|
|
95507
|
-
`
|
|
95787
|
+
`sandbox_outbox_spool_quarantined ${error61 instanceof Error ? error61.message : String(error61)}`
|
|
95508
95788
|
);
|
|
95509
|
-
(
|
|
95789
|
+
quarantineUnusableOutbox(path2);
|
|
95510
95790
|
return new EncryptedEventOutbox(path2, key, input2.pushLog, input2.options);
|
|
95511
95791
|
}
|
|
95512
95792
|
}
|
|
@@ -95526,7 +95806,12 @@ var SandboxOutboxSocket = class {
|
|
|
95526
95806
|
seq = this.seqCounter;
|
|
95527
95807
|
this.seqByEventId.set(payload.eventId, seq);
|
|
95528
95808
|
}
|
|
95529
|
-
const wirePayload = {
|
|
95809
|
+
const wirePayload = {
|
|
95810
|
+
...payload.event,
|
|
95811
|
+
eventId: payload.eventId,
|
|
95812
|
+
seq,
|
|
95813
|
+
deliveryRunId: payload.runId
|
|
95814
|
+
};
|
|
95530
95815
|
this.socket.emit("agent_event", wirePayload, (result) => {
|
|
95531
95816
|
if (result?.ok) this.seqByEventId.delete(payload.eventId);
|
|
95532
95817
|
acknowledge({ ok: Boolean(result?.ok), retryable: result?.retryable });
|
|
@@ -95540,54 +95825,42 @@ var SandboxEventDispatcher = class {
|
|
|
95540
95825
|
currentRunId;
|
|
95541
95826
|
constructor(input2) {
|
|
95542
95827
|
this.conversationId = input2.conversationId;
|
|
95543
|
-
|
|
95544
|
-
|
|
95545
|
-
|
|
95546
|
-
|
|
95547
|
-
|
|
95548
|
-
|
|
95549
|
-
|
|
95550
|
-
|
|
95551
|
-
});
|
|
95552
|
-
this.outboxSocket = new SandboxOutboxSocket(input2.socket);
|
|
95553
|
-
} catch (error61) {
|
|
95554
|
-
input2.onInitError?.(error61);
|
|
95555
|
-
this.outbox = void 0;
|
|
95556
|
-
this.outboxSocket = void 0;
|
|
95557
|
-
}
|
|
95558
|
-
}
|
|
95559
|
-
/** True when events are being durably queued rather than fired-and-forgotten. */
|
|
95560
|
-
get active() {
|
|
95561
|
-
return this.outbox !== void 0 && this.outboxSocket !== void 0;
|
|
95828
|
+
this.outbox = createSandboxEventOutbox({
|
|
95829
|
+
conversationId: input2.conversationId,
|
|
95830
|
+
sessionToken: input2.sessionToken,
|
|
95831
|
+
pushLog: input2.pushLog,
|
|
95832
|
+
options: input2.options,
|
|
95833
|
+
spoolPath: input2.spoolPath
|
|
95834
|
+
});
|
|
95835
|
+
this.outboxSocket = new SandboxOutboxSocket(input2.socket);
|
|
95562
95836
|
}
|
|
95563
95837
|
/** Set the run id used for fair replay and per-run heartbeat pruning. */
|
|
95564
95838
|
setRunId(runId) {
|
|
95565
95839
|
this.currentRunId = runId;
|
|
95566
95840
|
}
|
|
95567
95841
|
/**
|
|
95568
|
-
* Durably deliver one event (enqueue-before-send, remove-on-ack).
|
|
95569
|
-
* outbox is inactive, defers to `fireAndForget` so behaviour is unchanged.
|
|
95842
|
+
* Durably deliver one event (enqueue-before-send, remove-on-ack).
|
|
95570
95843
|
*/
|
|
95571
|
-
emit(event
|
|
95572
|
-
if (!this.outbox || !this.outboxSocket) {
|
|
95573
|
-
fireAndForget(event);
|
|
95574
|
-
return;
|
|
95575
|
-
}
|
|
95844
|
+
emit(event) {
|
|
95576
95845
|
if (isBackgroundHeartbeat(event) && !this.outboxSocket.connected) return;
|
|
95577
95846
|
this.outbox.enqueue(this.conversationId, this.currentRunId ?? this.conversationId, event);
|
|
95578
95847
|
this.outbox.flush(this.outboxSocket);
|
|
95579
95848
|
}
|
|
95580
95849
|
/** Replay un-acked events in order — called on (re)connect before new events. */
|
|
95581
95850
|
flush() {
|
|
95582
|
-
|
|
95851
|
+
this.outbox.flush(this.outboxSocket);
|
|
95583
95852
|
}
|
|
95584
95853
|
/** Reset in-flight state on disconnect so the next flush replays from the head. */
|
|
95585
95854
|
disconnect() {
|
|
95586
|
-
this.outbox
|
|
95855
|
+
this.outbox.disconnect();
|
|
95587
95856
|
}
|
|
95588
95857
|
/** Diagnostics: number of events still awaiting a server ack. */
|
|
95589
95858
|
pendingCount() {
|
|
95590
|
-
return this.outbox
|
|
95859
|
+
return this.outbox.pendingCount();
|
|
95860
|
+
}
|
|
95861
|
+
/** Drain the async writer so a replacement process can recover the journal. */
|
|
95862
|
+
flushDurable() {
|
|
95863
|
+
return this.outbox.flushDurable();
|
|
95591
95864
|
}
|
|
95592
95865
|
};
|
|
95593
95866
|
|
|
@@ -95631,20 +95904,13 @@ var WSClient = class {
|
|
|
95631
95904
|
upgrade: false,
|
|
95632
95905
|
extraHeaders: { "ngrok-skip-browser-warning": "1" }
|
|
95633
95906
|
});
|
|
95634
|
-
const outboxEnabled = isSandboxEventOutboxEnabled();
|
|
95635
95907
|
this.eventDispatcher = new SandboxEventDispatcher({
|
|
95636
95908
|
conversationId: sessionId,
|
|
95637
95909
|
sessionToken: token,
|
|
95638
|
-
enabled: outboxEnabled,
|
|
95639
95910
|
socket: this.socket,
|
|
95640
|
-
pushLog: (message) => this.lifecycle?.info("sandbox_agent_event_outbox", { detail: message })
|
|
95641
|
-
onInitError: (error61) => this.lifecycle?.warn("sandbox_agent_event_outbox_init_failed", {
|
|
95642
|
-
error: error61 instanceof Error ? error61 : new Error(String(error61))
|
|
95643
|
-
})
|
|
95911
|
+
pushLog: (message) => this.lifecycle?.info("sandbox_agent_event_outbox", { detail: message })
|
|
95644
95912
|
});
|
|
95645
|
-
|
|
95646
|
-
this.lifecycle?.info("sandbox_agent_event_outbox_enabled", { conversationId: sessionId });
|
|
95647
|
-
}
|
|
95913
|
+
this.lifecycle?.info("sandbox_agent_event_outbox_enabled", { conversationId: sessionId });
|
|
95648
95914
|
this.setupListeners(callbacks);
|
|
95649
95915
|
}
|
|
95650
95916
|
socket;
|
|
@@ -95659,11 +95925,7 @@ var WSClient = class {
|
|
|
95659
95925
|
intentionalClose = false;
|
|
95660
95926
|
agentVersion;
|
|
95661
95927
|
getRunState;
|
|
95662
|
-
/**
|
|
95663
|
-
* Durable at-least-once delivery for stream events. Active only when
|
|
95664
|
-
* `ALAN_EVENT_OUTBOX_ENABLED === "true"`; otherwise events are fired-and-
|
|
95665
|
-
* forgotten exactly as before (see {@link SandboxEventDispatcher}).
|
|
95666
|
-
*/
|
|
95928
|
+
/** Durable at-least-once delivery for stream events (see {@link SandboxEventDispatcher}). */
|
|
95667
95929
|
eventDispatcher;
|
|
95668
95930
|
/**
|
|
95669
95931
|
* Bounded record of `messageId`s whose handoff to `onUserMessage` already
|
|
@@ -95686,8 +95948,7 @@ var WSClient = class {
|
|
|
95686
95948
|
}
|
|
95687
95949
|
/**
|
|
95688
95950
|
* Record the run id for events emitted from here on, so the durable outbox can
|
|
95689
|
-
* bucket per-run caps and terminal-event condensation correctly.
|
|
95690
|
-
* outbox is disabled.
|
|
95951
|
+
* bucket per-run caps and terminal-event condensation correctly.
|
|
95691
95952
|
*/
|
|
95692
95953
|
setCurrentRunId(runId) {
|
|
95693
95954
|
this.eventDispatcher.setRunId(runId);
|
|
@@ -95728,9 +95989,7 @@ var WSClient = class {
|
|
|
95728
95989
|
}
|
|
95729
95990
|
}
|
|
95730
95991
|
emitEvent(event) {
|
|
95731
|
-
this.eventDispatcher.emit(event
|
|
95732
|
-
this.socket.emit("agent_event", payload);
|
|
95733
|
-
});
|
|
95992
|
+
this.eventDispatcher.emit(event);
|
|
95734
95993
|
}
|
|
95735
95994
|
waitForConnection(timeoutMs = 15e3) {
|
|
95736
95995
|
return new Promise((resolve15, reject) => {
|
|
@@ -96172,7 +96431,7 @@ async function runSandbox(config2) {
|
|
|
96172
96431
|
}
|
|
96173
96432
|
const presenter = new WebPresenter(wsClient, config2.sessionId, config2.projectPath);
|
|
96174
96433
|
presenter.setSuppressSessionLifecycle(true);
|
|
96175
|
-
const runtimeSkillManager = await RuntimeSkillManager.open({ homeDirectory: (0,
|
|
96434
|
+
const runtimeSkillManager = await RuntimeSkillManager.open({ homeDirectory: (0, import_node_os17.homedir)() });
|
|
96176
96435
|
let lastProviderSessionId = config2.providerSessionId;
|
|
96177
96436
|
let resumeFallbackContext = config2.resumeFallbackContext;
|
|
96178
96437
|
let activeBackendKind = config2.backendKind || "claude_cli";
|
|
@@ -96472,7 +96731,7 @@ async function runSandbox(config2) {
|
|
|
96472
96731
|
// src/service-manager.ts
|
|
96473
96732
|
var import_node_child_process9 = require("child_process");
|
|
96474
96733
|
var import_node_fs28 = require("fs");
|
|
96475
|
-
var
|
|
96734
|
+
var import_node_os18 = require("os");
|
|
96476
96735
|
var import_node_path29 = require("path");
|
|
96477
96736
|
var SERVICE_LABEL = "ai.tryalan.agent";
|
|
96478
96737
|
var SYSTEMD_UNIT = "alan-agent.service";
|
|
@@ -96486,15 +96745,28 @@ function systemdArg(value2) {
|
|
|
96486
96745
|
function powershellLiteral(value2) {
|
|
96487
96746
|
return `'${value2.replaceAll("'", "''")}'`;
|
|
96488
96747
|
}
|
|
96748
|
+
function serviceNames(profile) {
|
|
96749
|
+
if (profile === "production") {
|
|
96750
|
+
return { launchd: SERVICE_LABEL, systemd: SYSTEMD_UNIT, windows: WINDOWS_TASK };
|
|
96751
|
+
}
|
|
96752
|
+
const suffix = profile === "custom" ? "prod" : profile;
|
|
96753
|
+
const title = `${suffix[0]?.toUpperCase()}${suffix.slice(1)}`;
|
|
96754
|
+
return {
|
|
96755
|
+
launchd: `${SERVICE_LABEL}.${suffix}`,
|
|
96756
|
+
systemd: `alan-agent-${suffix}.service`,
|
|
96757
|
+
windows: `${WINDOWS_TASK} ${title}`
|
|
96758
|
+
};
|
|
96759
|
+
}
|
|
96489
96760
|
function buildDaemonServicePlan(input2) {
|
|
96490
96761
|
const daemonArgs = [input2.nodeExecutable, input2.cliEntry, "daemon", "--profile", input2.profile];
|
|
96762
|
+
const names = serviceNames(input2.profile);
|
|
96491
96763
|
if (input2.platform === "darwin") {
|
|
96492
96764
|
const userId = input2.userId ?? process.getuid?.();
|
|
96493
96765
|
if (userId === void 0) throw new Error("Cannot determine the current macOS user ID");
|
|
96494
96766
|
const domain2 = `gui/${userId}`;
|
|
96495
|
-
const serviceTarget = `${domain2}/${
|
|
96496
|
-
const manifestPath = (0, import_node_path29.join)(input2.homeDir, "Library", "LaunchAgents", `${
|
|
96497
|
-
const logDir = (0, import_node_path29.join)(input2.
|
|
96767
|
+
const serviceTarget = `${domain2}/${names.launchd}`;
|
|
96768
|
+
const manifestPath = (0, import_node_path29.join)(input2.homeDir, "Library", "LaunchAgents", `${names.launchd}.plist`);
|
|
96769
|
+
const logDir = (0, import_node_path29.join)(resolveAgentConfigDirectory(input2.profile, input2.homeDir), "logs");
|
|
96498
96770
|
const programArguments = daemonArgs.map((arg) => ` <string>${xml(arg)}</string>`).join("\n");
|
|
96499
96771
|
const environmentEntries = Object.entries(input2.environment ?? {}).map(([key, value2]) => ` <key>${xml(key)}</key>
|
|
96500
96772
|
<string>${xml(value2)}</string>`).join("\n");
|
|
@@ -96508,7 +96780,7 @@ ${environmentEntries}
|
|
|
96508
96780
|
<plist version="1.0">
|
|
96509
96781
|
<dict>
|
|
96510
96782
|
<key>Label</key>
|
|
96511
|
-
<string>${
|
|
96783
|
+
<string>${names.launchd}</string>
|
|
96512
96784
|
<key>ProgramArguments</key>
|
|
96513
96785
|
<array>
|
|
96514
96786
|
${programArguments}
|
|
@@ -96533,6 +96805,7 @@ ${environmentBlock} <key>RunAtLoad</key>
|
|
|
96533
96805
|
platform: "darwin",
|
|
96534
96806
|
manifestPath,
|
|
96535
96807
|
manifest,
|
|
96808
|
+
logDirectory: logDir,
|
|
96536
96809
|
loadDefinitionCommands: [
|
|
96537
96810
|
{
|
|
96538
96811
|
command: "launchctl",
|
|
@@ -96540,6 +96813,18 @@ ${environmentBlock} <key>RunAtLoad</key>
|
|
|
96540
96813
|
tolerateFailure: true
|
|
96541
96814
|
}
|
|
96542
96815
|
],
|
|
96816
|
+
reloadDefinitionCommands: [
|
|
96817
|
+
{
|
|
96818
|
+
command: "launchctl",
|
|
96819
|
+
args: ["bootout", domain2, manifestPath],
|
|
96820
|
+
tolerateFailure: true
|
|
96821
|
+
},
|
|
96822
|
+
{
|
|
96823
|
+
command: "launchctl",
|
|
96824
|
+
args: ["bootstrap", domain2, manifestPath],
|
|
96825
|
+
tolerateFailure: false
|
|
96826
|
+
}
|
|
96827
|
+
],
|
|
96543
96828
|
enableCommands: [
|
|
96544
96829
|
{
|
|
96545
96830
|
command: "launchctl",
|
|
@@ -96599,7 +96884,7 @@ ${environmentBlock} <key>RunAtLoad</key>
|
|
|
96599
96884
|
};
|
|
96600
96885
|
}
|
|
96601
96886
|
if (input2.platform === "linux") {
|
|
96602
|
-
const manifestPath = (0, import_node_path29.join)(input2.homeDir, ".config", "systemd", "user",
|
|
96887
|
+
const manifestPath = (0, import_node_path29.join)(input2.homeDir, ".config", "systemd", "user", names.systemd);
|
|
96603
96888
|
const environmentLines = Object.entries(input2.environment ?? {}).map(([key, value2]) => `Environment=${systemdArg(`${key}=${value2}`)}`).join("\n");
|
|
96604
96889
|
const manifest = `[Unit]
|
|
96605
96890
|
Description=Alan local agent daemon
|
|
@@ -96622,6 +96907,7 @@ WantedBy=default.target
|
|
|
96622
96907
|
platform: "linux",
|
|
96623
96908
|
manifestPath,
|
|
96624
96909
|
manifest,
|
|
96910
|
+
logDirectory: null,
|
|
96625
96911
|
loadDefinitionCommands: [
|
|
96626
96912
|
{
|
|
96627
96913
|
command: "systemctl",
|
|
@@ -96629,24 +96915,31 @@ WantedBy=default.target
|
|
|
96629
96915
|
tolerateFailure: false
|
|
96630
96916
|
}
|
|
96631
96917
|
],
|
|
96918
|
+
reloadDefinitionCommands: [
|
|
96919
|
+
{
|
|
96920
|
+
command: "systemctl",
|
|
96921
|
+
args: ["--user", "daemon-reload"],
|
|
96922
|
+
tolerateFailure: false
|
|
96923
|
+
}
|
|
96924
|
+
],
|
|
96632
96925
|
enableCommands: [
|
|
96633
96926
|
{
|
|
96634
96927
|
command: "systemctl",
|
|
96635
|
-
args: ["--user", "enable",
|
|
96928
|
+
args: ["--user", "enable", names.systemd],
|
|
96636
96929
|
tolerateFailure: false
|
|
96637
96930
|
}
|
|
96638
96931
|
],
|
|
96639
96932
|
startCommands: [
|
|
96640
96933
|
{
|
|
96641
96934
|
command: "systemctl",
|
|
96642
|
-
args: ["--user", "start",
|
|
96935
|
+
args: ["--user", "start", names.systemd],
|
|
96643
96936
|
tolerateFailure: false
|
|
96644
96937
|
}
|
|
96645
96938
|
],
|
|
96646
96939
|
stopCommands: [
|
|
96647
96940
|
{
|
|
96648
96941
|
command: "systemctl",
|
|
96649
|
-
args: ["--user", "stop",
|
|
96942
|
+
args: ["--user", "stop", names.systemd],
|
|
96650
96943
|
tolerateFailure: true
|
|
96651
96944
|
}
|
|
96652
96945
|
],
|
|
@@ -96658,14 +96951,14 @@ WantedBy=default.target
|
|
|
96658
96951
|
},
|
|
96659
96952
|
{
|
|
96660
96953
|
command: "systemctl",
|
|
96661
|
-
args: ["--user", "restart",
|
|
96954
|
+
args: ["--user", "restart", names.systemd],
|
|
96662
96955
|
tolerateFailure: false
|
|
96663
96956
|
}
|
|
96664
96957
|
],
|
|
96665
96958
|
uninstallCommands: [
|
|
96666
96959
|
{
|
|
96667
96960
|
command: "systemctl",
|
|
96668
|
-
args: ["--user", "disable", "--now",
|
|
96961
|
+
args: ["--user", "disable", "--now", names.systemd],
|
|
96669
96962
|
tolerateFailure: true
|
|
96670
96963
|
},
|
|
96671
96964
|
{
|
|
@@ -96676,12 +96969,12 @@ WantedBy=default.target
|
|
|
96676
96969
|
],
|
|
96677
96970
|
statusCommand: {
|
|
96678
96971
|
command: "systemctl",
|
|
96679
|
-
args: ["--user", "status",
|
|
96972
|
+
args: ["--user", "status", names.systemd, "--no-pager"],
|
|
96680
96973
|
tolerateFailure: true
|
|
96681
96974
|
},
|
|
96682
96975
|
isActiveCommand: {
|
|
96683
96976
|
command: "systemctl",
|
|
96684
|
-
args: ["--user", "is-active",
|
|
96977
|
+
args: ["--user", "is-active", names.systemd],
|
|
96685
96978
|
tolerateFailure: true
|
|
96686
96979
|
},
|
|
96687
96980
|
lingerStatusCommand: {
|
|
@@ -96703,12 +96996,13 @@ WantedBy=default.target
|
|
|
96703
96996
|
"$trigger = New-ScheduledTaskTrigger -AtLogOn -User $currentUser",
|
|
96704
96997
|
"$principal = New-ScheduledTaskPrincipal -UserId $currentUser -LogonType Interactive -RunLevel Limited",
|
|
96705
96998
|
"$settings = New-ScheduledTaskSettingsSet -RestartCount 3 -RestartInterval (New-TimeSpan -Minutes 1) -ExecutionTimeLimit ([TimeSpan]::Zero)",
|
|
96706
|
-
`Register-ScheduledTask -TaskName ${powershellLiteral(
|
|
96999
|
+
`Register-ScheduledTask -TaskName ${powershellLiteral(names.windows)} -Action $action -Trigger $trigger -Principal $principal -Settings $settings -Force | Out-Null`
|
|
96707
97000
|
].join("; ");
|
|
96708
97001
|
return {
|
|
96709
97002
|
platform: "win32",
|
|
96710
97003
|
manifestPath: null,
|
|
96711
97004
|
manifest: null,
|
|
97005
|
+
logDirectory: null,
|
|
96712
97006
|
loadDefinitionCommands: [
|
|
96713
97007
|
{
|
|
96714
97008
|
command: "powershell.exe",
|
|
@@ -96716,6 +97010,13 @@ WantedBy=default.target
|
|
|
96716
97010
|
tolerateFailure: false
|
|
96717
97011
|
}
|
|
96718
97012
|
],
|
|
97013
|
+
reloadDefinitionCommands: [
|
|
97014
|
+
{
|
|
97015
|
+
command: "powershell.exe",
|
|
97016
|
+
args: ["-NoProfile", "-NonInteractive", "-Command", registerScript],
|
|
97017
|
+
tolerateFailure: false
|
|
97018
|
+
}
|
|
97019
|
+
],
|
|
96719
97020
|
enableCommands: [],
|
|
96720
97021
|
startCommands: [
|
|
96721
97022
|
{
|
|
@@ -96724,7 +97025,7 @@ WantedBy=default.target
|
|
|
96724
97025
|
"-NoProfile",
|
|
96725
97026
|
"-NonInteractive",
|
|
96726
97027
|
"-Command",
|
|
96727
|
-
`Start-ScheduledTask -TaskName ${powershellLiteral(
|
|
97028
|
+
`Start-ScheduledTask -TaskName ${powershellLiteral(names.windows)}`
|
|
96728
97029
|
],
|
|
96729
97030
|
tolerateFailure: false
|
|
96730
97031
|
}
|
|
@@ -96736,7 +97037,7 @@ WantedBy=default.target
|
|
|
96736
97037
|
"-NoProfile",
|
|
96737
97038
|
"-NonInteractive",
|
|
96738
97039
|
"-Command",
|
|
96739
|
-
`Stop-ScheduledTask -TaskName ${powershellLiteral(
|
|
97040
|
+
`Stop-ScheduledTask -TaskName ${powershellLiteral(names.windows)} -ErrorAction SilentlyContinue`
|
|
96740
97041
|
],
|
|
96741
97042
|
tolerateFailure: true
|
|
96742
97043
|
}
|
|
@@ -96748,7 +97049,7 @@ WantedBy=default.target
|
|
|
96748
97049
|
"-NoProfile",
|
|
96749
97050
|
"-NonInteractive",
|
|
96750
97051
|
"-Command",
|
|
96751
|
-
`${registerScript}; Start-ScheduledTask -TaskName ${powershellLiteral(
|
|
97052
|
+
`${registerScript}; Start-ScheduledTask -TaskName ${powershellLiteral(names.windows)}`
|
|
96752
97053
|
],
|
|
96753
97054
|
tolerateFailure: false
|
|
96754
97055
|
}
|
|
@@ -96760,7 +97061,7 @@ WantedBy=default.target
|
|
|
96760
97061
|
"-NoProfile",
|
|
96761
97062
|
"-NonInteractive",
|
|
96762
97063
|
"-Command",
|
|
96763
|
-
`Unregister-ScheduledTask -TaskName ${powershellLiteral(
|
|
97064
|
+
`Unregister-ScheduledTask -TaskName ${powershellLiteral(names.windows)} -Confirm:$false -ErrorAction SilentlyContinue`
|
|
96764
97065
|
],
|
|
96765
97066
|
tolerateFailure: true
|
|
96766
97067
|
}
|
|
@@ -96771,7 +97072,7 @@ WantedBy=default.target
|
|
|
96771
97072
|
"-NoProfile",
|
|
96772
97073
|
"-NonInteractive",
|
|
96773
97074
|
"-Command",
|
|
96774
|
-
`Get-ScheduledTask -TaskName ${powershellLiteral(
|
|
97075
|
+
`Get-ScheduledTask -TaskName ${powershellLiteral(names.windows)} | Format-List TaskName,State`
|
|
96775
97076
|
],
|
|
96776
97077
|
tolerateFailure: true
|
|
96777
97078
|
},
|
|
@@ -96781,7 +97082,7 @@ WantedBy=default.target
|
|
|
96781
97082
|
"-NoProfile",
|
|
96782
97083
|
"-NonInteractive",
|
|
96783
97084
|
"-Command",
|
|
96784
|
-
`(Get-ScheduledTask -TaskName ${powershellLiteral(
|
|
97085
|
+
`(Get-ScheduledTask -TaskName ${powershellLiteral(names.windows)} -ErrorAction SilentlyContinue).State`
|
|
96785
97086
|
],
|
|
96786
97087
|
tolerateFailure: true
|
|
96787
97088
|
},
|
|
@@ -96789,7 +97090,7 @@ WantedBy=default.target
|
|
|
96789
97090
|
};
|
|
96790
97091
|
}
|
|
96791
97092
|
function resolveCurrentPlatform() {
|
|
96792
|
-
const currentPlatform = (0,
|
|
97093
|
+
const currentPlatform = (0, import_node_os18.platform)();
|
|
96793
97094
|
if (currentPlatform !== "darwin" && currentPlatform !== "linux" && currentPlatform !== "win32") {
|
|
96794
97095
|
throw new Error(`Daemon service installation is not supported on ${currentPlatform}`);
|
|
96795
97096
|
}
|
|
@@ -96802,7 +97103,7 @@ function currentServicePlan(args, runtime) {
|
|
|
96802
97103
|
if (!cliEntry) throw new Error("Cannot determine the alan-agent executable path");
|
|
96803
97104
|
return buildDaemonServicePlan({
|
|
96804
97105
|
platform: currentPlatform,
|
|
96805
|
-
homeDir: (0,
|
|
97106
|
+
homeDir: (0, import_node_os18.homedir)(),
|
|
96806
97107
|
nodeExecutable: runtime?.executable ?? process.execPath,
|
|
96807
97108
|
cliEntry: (0, import_node_path29.resolve)(cliEntry),
|
|
96808
97109
|
profile,
|
|
@@ -96883,7 +97184,7 @@ function shouldStartOnInstall(hostState) {
|
|
|
96883
97184
|
function resolveUsername(options) {
|
|
96884
97185
|
if (options?.username) return options.username;
|
|
96885
97186
|
try {
|
|
96886
|
-
return (0,
|
|
97187
|
+
return (0, import_node_os18.userInfo)().username;
|
|
96887
97188
|
} catch {
|
|
96888
97189
|
return process.env.USER || process.env.USERNAME || "unknown";
|
|
96889
97190
|
}
|
|
@@ -96920,9 +97221,7 @@ function createHostContext(options = {}) {
|
|
|
96920
97221
|
const writeManifest = options.writeManifest ?? writeManifestAtomic;
|
|
96921
97222
|
const removeManifest = options.removeManifest ?? ((path2) => (0, import_node_fs28.rmSync)(path2, { force: true }));
|
|
96922
97223
|
const ensureLogDir = options.ensureLogDir ?? (() => {
|
|
96923
|
-
if (plan.
|
|
96924
|
-
(0, import_node_fs28.mkdirSync)((0, import_node_path29.join)((0, import_node_os17.homedir)(), ".alan", "agent", "logs"), { recursive: true, mode: 448 });
|
|
96925
|
-
}
|
|
97224
|
+
if (plan.logDirectory) (0, import_node_fs28.mkdirSync)(plan.logDirectory, { recursive: true, mode: 448 });
|
|
96926
97225
|
});
|
|
96927
97226
|
return {
|
|
96928
97227
|
args,
|
|
@@ -96970,7 +97269,11 @@ function ensureDaemonServiceDefinition(options = {}) {
|
|
|
96970
97269
|
if (outcome.updatePending) {
|
|
96971
97270
|
return outcome;
|
|
96972
97271
|
}
|
|
96973
|
-
|
|
97272
|
+
if (inspection.state === "running" || inspection.state === "starting") {
|
|
97273
|
+
return outcome;
|
|
97274
|
+
}
|
|
97275
|
+
const definitionCommands = inspection.state === "stopped" ? plan.reloadDefinitionCommands : plan.loadDefinitionCommands;
|
|
97276
|
+
for (const command of definitionCommands) run(command);
|
|
96974
97277
|
return outcome;
|
|
96975
97278
|
}
|
|
96976
97279
|
function enableDaemonService(options = {}) {
|
|
@@ -97037,11 +97340,11 @@ ${result.output}
|
|
|
97037
97340
|
|
|
97038
97341
|
// src/skills/skill-cli.ts
|
|
97039
97342
|
var import_promises6 = require("fs/promises");
|
|
97040
|
-
var
|
|
97343
|
+
var import_node_os19 = require("os");
|
|
97041
97344
|
var import_node_path30 = require("path");
|
|
97042
97345
|
async function runSkillsCommand(args) {
|
|
97043
97346
|
const [subcommand, ...options] = args;
|
|
97044
|
-
const homeDirectory2 = option(options, "--home") ?? (0,
|
|
97347
|
+
const homeDirectory2 = option(options, "--home") ?? (0, import_node_os19.homedir)();
|
|
97045
97348
|
const manager = await RuntimeSkillManager.open({ homeDirectory: homeDirectory2 });
|
|
97046
97349
|
if (subcommand === "scan") {
|
|
97047
97350
|
const inputPath = option(options, "--input");
|
|
@@ -97235,11 +97538,10 @@ async function main() {
|
|
|
97235
97538
|
if (command === "install") {
|
|
97236
97539
|
bindConfigPath(commandArgs);
|
|
97237
97540
|
const configured = readConfig();
|
|
97238
|
-
|
|
97239
|
-
|
|
97240
|
-
|
|
97241
|
-
|
|
97242
|
-
installDaemonService(commandArgs);
|
|
97541
|
+
const configurationMode = resolveInstallConfigurationMode(commandArgs, configured);
|
|
97542
|
+
const setup = configurationMode === "setup" ? await setupDaemon(commandArgs) : null;
|
|
97543
|
+
if (configurationMode === "login") await loginWithDeviceCode(commandArgs);
|
|
97544
|
+
if (!setup?.daemonAlreadyRunning) installDaemonService(commandArgs);
|
|
97243
97545
|
runMcpIntegrationCommand(["reconcile", ...commandArgs]);
|
|
97244
97546
|
return;
|
|
97245
97547
|
}
|