@songsid/agend 2.3.5-alpha.5 → 2.3.5-alpha.6
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/THIRD_PARTY_NOTICES.md +0 -1
- package/dist/accounts-profiles.d.ts +96 -0
- package/dist/accounts-profiles.js +178 -0
- package/dist/accounts-profiles.js.map +1 -0
- package/dist/accounts-signout.d.ts +59 -0
- package/dist/accounts-signout.js +184 -0
- package/dist/accounts-signout.js.map +1 -0
- package/dist/accounts-view.d.ts +54 -0
- package/dist/accounts-view.js +55 -11
- package/dist/accounts-view.js.map +1 -1
- package/dist/agent-workspace.d.ts +11 -0
- package/dist/agent-workspace.js +28 -0
- package/dist/agent-workspace.js.map +1 -1
- package/dist/auth-api.js +27 -5
- package/dist/auth-api.js.map +1 -1
- package/dist/authority/session-authorizations.d.ts +2 -0
- package/dist/authority/session-authorizations.js +7 -1
- package/dist/authority/session-authorizations.js.map +1 -1
- package/dist/backend/codex.js +1 -0
- package/dist/backend/codex.js.map +1 -1
- package/dist/backend/types.d.ts +2 -0
- package/dist/backend/types.js.map +1 -1
- package/dist/build-provenance.json +1 -1
- package/dist/bundled-tmux-guard.d.ts +19 -0
- package/dist/bundled-tmux-guard.js +83 -0
- package/dist/bundled-tmux-guard.js.map +1 -0
- package/dist/classic-bindings.d.ts +13 -0
- package/dist/classic-bindings.js +28 -2
- package/dist/classic-bindings.js.map +1 -1
- package/dist/classic-channel-manager.d.ts +2 -0
- package/dist/classic-channel-manager.js +5 -1
- package/dist/classic-channel-manager.js.map +1 -1
- package/dist/cli.js +116 -11
- package/dist/cli.js.map +1 -1
- package/dist/config-validator.js +11 -0
- package/dist/config-validator.js.map +1 -1
- package/dist/config.js +3 -1
- package/dist/config.js.map +1 -1
- package/dist/daemon.d.ts +27 -2
- package/dist/daemon.js +107 -6
- package/dist/daemon.js.map +1 -1
- package/dist/doctor.js +3 -4
- package/dist/doctor.js.map +1 -1
- package/dist/e2e-isolation.js +5 -2
- package/dist/e2e-isolation.js.map +1 -1
- package/dist/fleet-control-audit.d.ts +1 -1
- package/dist/fleet-manager.d.ts +129 -0
- package/dist/fleet-manager.js +725 -53
- package/dist/fleet-manager.js.map +1 -1
- package/dist/general-knowledge/skills/credential-profiles/SKILL.md +10 -0
- package/dist/hub/compose/server.js +1 -0
- package/dist/hub/compose/server.js.map +1 -1
- package/dist/hub/directory/directory.d.ts +1 -1
- package/dist/hub/directory/directory.js +115 -3
- package/dist/hub/directory/directory.js.map +1 -1
- package/dist/hub/directory/groups.d.ts +29 -0
- package/dist/hub/directory/groups.js +29 -0
- package/dist/hub/directory/groups.js.map +1 -0
- package/dist/hub/directory/index.d.ts +1 -0
- package/dist/hub/directory/types.d.ts +4 -0
- package/dist/hub/directory/types.js.map +1 -1
- package/dist/hub/group-policy/model.d.ts +56 -0
- package/dist/hub/group-policy/model.js +46 -0
- package/dist/hub/group-policy/model.js.map +1 -0
- package/dist/hub/group-policy/resources.d.ts +52 -0
- package/dist/hub/group-policy/resources.js +166 -0
- package/dist/hub/group-policy/resources.js.map +1 -0
- package/dist/hub/group-policy/store.d.ts +52 -0
- package/dist/hub/group-policy/store.js +149 -0
- package/dist/hub/group-policy/store.js.map +1 -0
- package/dist/hub/http/compose.js +4 -3
- package/dist/hub/http/compose.js.map +1 -1
- package/dist/hub/pairing.d.ts +3 -1
- package/dist/hub/pairing.js +6 -3
- package/dist/hub/pairing.js.map +1 -1
- package/dist/hub/server.d.ts +2 -0
- package/dist/hub/server.js +12 -2
- package/dist/hub/server.js.map +1 -1
- package/dist/instance-config-impact.js +4 -3
- package/dist/instance-config-impact.js.map +1 -1
- package/dist/instance-lifecycle.d.ts +17 -0
- package/dist/instance-lifecycle.js +38 -1
- package/dist/instance-lifecycle.js.map +1 -1
- package/dist/locale.js +21 -0
- package/dist/locale.js.map +1 -1
- package/dist/login-controller.d.ts +5 -0
- package/dist/login-controller.js +11 -0
- package/dist/login-controller.js.map +1 -1
- package/dist/login-window-lock.d.ts +2 -1
- package/dist/login-window-lock.js.map +1 -1
- package/dist/ls-rows.d.ts +1 -1
- package/dist/ls-rows.js +1 -1
- package/dist/ls-rows.js.map +1 -1
- package/dist/machine-accounts.d.ts +110 -0
- package/dist/machine-accounts.js +229 -0
- package/dist/machine-accounts.js.map +1 -0
- package/dist/machine-signins.d.ts +89 -0
- package/dist/machine-signins.js +182 -0
- package/dist/machine-signins.js.map +1 -0
- package/dist/muse-usage-relay.d.ts +2 -0
- package/dist/muse-usage-relay.js +5 -3
- package/dist/muse-usage-relay.js.map +1 -1
- package/dist/needs-you-hub.d.ts +3 -0
- package/dist/needs-you-hub.js +13 -3
- package/dist/needs-you-hub.js.map +1 -1
- package/dist/needs-you.d.ts +35 -2
- package/dist/needs-you.js +19 -0
- package/dist/needs-you.js.map +1 -1
- package/dist/quickstart.js +7 -18
- package/dist/quickstart.js.map +1 -1
- package/dist/quiet-run.d.ts +31 -0
- package/dist/quiet-run.js +50 -0
- package/dist/quiet-run.js.map +1 -0
- package/dist/quota-notice-config.d.ts +22 -0
- package/dist/quota-notice-config.js +41 -0
- package/dist/quota-notice-config.js.map +1 -0
- package/dist/runtime-api.d.ts +13 -0
- package/dist/runtime-api.js +125 -1
- package/dist/runtime-api.js.map +1 -1
- package/dist/runtime-build-info.d.ts +2 -1
- package/dist/runtime-build-info.js +7 -3
- package/dist/runtime-build-info.js.map +1 -1
- package/dist/runtime-cli-install.d.ts +153 -0
- package/dist/runtime-cli-install.js +675 -0
- package/dist/runtime-cli-install.js.map +1 -0
- package/dist/runtime-cli.js +157 -12
- package/dist/runtime-cli.js.map +1 -1
- package/dist/runtime-client.d.ts +64 -2
- package/dist/runtime-client.js +277 -20
- package/dist/runtime-client.js.map +1 -1
- package/dist/runtime-coordinator.d.ts +10 -1
- package/dist/runtime-coordinator.js +93 -2
- package/dist/runtime-coordinator.js.map +1 -1
- package/dist/runtime-credential-profiles.d.ts +11 -2
- package/dist/runtime-credential-profiles.js +28 -4
- package/dist/runtime-credential-profiles.js.map +1 -1
- package/dist/runtime-install.js +9 -6
- package/dist/runtime-install.js.map +1 -1
- package/dist/runtime-pane-link.js +2 -1
- package/dist/runtime-pane-link.js.map +1 -1
- package/dist/runtime-pane-service.js +2 -2
- package/dist/runtime-pane-service.js.map +1 -1
- package/dist/runtime-pane-store.d.ts +10 -0
- package/dist/runtime-pane-store.js +13 -1
- package/dist/runtime-pane-store.js.map +1 -1
- package/dist/runtime-profile-ownership.d.ts +66 -0
- package/dist/runtime-profile-ownership.js +391 -0
- package/dist/runtime-profile-ownership.js.map +1 -0
- package/dist/runtime-protocol.d.ts +88 -2
- package/dist/runtime-protocol.js +40 -0
- package/dist/runtime-protocol.js.map +1 -1
- package/dist/runtime-remote-accounts.d.ts +197 -0
- package/dist/runtime-remote-accounts.js +663 -0
- package/dist/runtime-remote-accounts.js.map +1 -0
- package/dist/runtime-remote-setup.d.ts +105 -0
- package/dist/runtime-remote-setup.js +529 -0
- package/dist/runtime-remote-setup.js.map +1 -0
- package/dist/runtime-signin-transport.d.ts +39 -0
- package/dist/runtime-signin-transport.js +110 -0
- package/dist/runtime-signin-transport.js.map +1 -0
- package/dist/runtime-signin.d.ts +132 -0
- package/dist/runtime-signin.js +289 -0
- package/dist/runtime-signin.js.map +1 -0
- package/dist/runtime-update-attention.d.ts +4 -0
- package/dist/runtime-update-attention.js +11 -0
- package/dist/runtime-update-attention.js.map +1 -0
- package/dist/runtime-update-controller.d.ts +75 -0
- package/dist/runtime-update-controller.js +691 -0
- package/dist/runtime-update-controller.js.map +1 -0
- package/dist/runtime-update-ipc.d.ts +42 -0
- package/dist/runtime-update-ipc.js +144 -0
- package/dist/runtime-update-ipc.js.map +1 -0
- package/dist/runtime-update-journal.d.ts +5 -0
- package/dist/runtime-update-journal.js +7 -0
- package/dist/runtime-update-journal.js.map +1 -1
- package/dist/runtime-update-lock.js +17 -2
- package/dist/runtime-update-lock.js.map +1 -1
- package/dist/runtime-update-status.d.ts +30 -0
- package/dist/runtime-update-status.js +31 -0
- package/dist/runtime-update-status.js.map +1 -0
- package/dist/settings-api.js +3 -0
- package/dist/settings-api.js.map +1 -1
- package/dist/settings-change.js +8 -0
- package/dist/settings-change.js.map +1 -1
- package/dist/settings-instance-patch.js +1 -1
- package/dist/settings-instance-patch.js.map +1 -1
- package/dist/setup-wizard.js +3 -5
- package/dist/setup-wizard.js.map +1 -1
- package/dist/signin-keepalive.d.ts +203 -0
- package/dist/signin-keepalive.js +652 -0
- package/dist/signin-keepalive.js.map +1 -0
- package/dist/structured-signin-transport.js +4 -0
- package/dist/structured-signin-transport.js.map +1 -1
- package/dist/structured-signin.d.ts +7 -0
- package/dist/structured-signin.js +1 -1
- package/dist/structured-signin.js.map +1 -1
- package/dist/tmux-binary.d.ts +23 -23
- package/dist/tmux-binary.js +35 -46
- package/dist/tmux-binary.js.map +1 -1
- package/dist/tmux-exec-helper.js +3 -3
- package/dist/tmux-exec-helper.js.map +1 -1
- package/dist/tmux-legacy.d.ts +94 -0
- package/dist/tmux-legacy.js +309 -0
- package/dist/tmux-legacy.js.map +1 -0
- package/dist/tmux-manager.d.ts +7 -1
- package/dist/tmux-manager.js +21 -11
- package/dist/tmux-manager.js.map +1 -1
- package/dist/tmux-rollback.d.ts +31 -0
- package/dist/tmux-rollback.js +72 -0
- package/dist/tmux-rollback.js.map +1 -0
- package/dist/tmux-server.d.ts +102 -0
- package/dist/tmux-server.js +248 -0
- package/dist/tmux-server.js.map +1 -0
- package/dist/transcript-monitor.js +43 -5
- package/dist/transcript-monitor.js.map +1 -1
- package/dist/transcript-records.d.ts +2 -1
- package/dist/transcript-records.js +3 -0
- package/dist/transcript-records.js.map +1 -1
- package/dist/transcript-sources.js +3 -0
- package/dist/transcript-sources.js.map +1 -1
- package/dist/types.d.ts +3 -0
- package/dist/ui/accounts-keepalive.js +112 -0
- package/dist/ui/accounts-manage.js +237 -0
- package/dist/ui/accounts-view.js +175 -31
- package/dist/ui/agent-runtime-settings.js +2 -1
- package/dist/ui/app.html +8 -1
- package/dist/ui/hub-attachments.js +90 -0
- package/dist/ui/hub-chat-store.js +9 -4
- package/dist/ui/hub-client.js +20 -1
- package/dist/ui/hub-preview.js +101 -0
- package/dist/ui/machine-signin.js +56 -0
- package/dist/ui/panel-fleet.js +1 -1
- package/dist/ui/panel-hub.js +126 -31
- package/dist/ui/panel-needs.js +14 -8
- package/dist/ui/panel-notices.js +4 -3
- package/dist/ui/panel-runtimes.js +19 -6
- package/dist/ui/panel-settings.js +12 -6
- package/dist/ui/panel-windows-agent.js +2 -1
- package/dist/ui/preview-pages.js +3 -41
- package/dist/ui/preview-panel-actions.js +3 -161
- package/dist/ui/preview-panel.js +10 -557
- package/dist/ui/preview-versions.js +3 -155
- package/dist/ui/runtime-cli-install.js +114 -0
- package/dist/ui/runtime-update-commands.d.ts +2 -0
- package/dist/ui/runtime-update-commands.js +11 -0
- package/dist/ui/runtime-update-status.js +53 -0
- package/dist/ui/search-dialog.js +3 -2
- package/dist/ui/settings-guests.js +3 -2
- package/dist/ui/settings-hub-browser-certificate.js +2 -0
- package/dist/ui/settings-hub-membership.js +12 -6
- package/dist/ui/settings-hub-retention.js +2 -0
- package/dist/ui/settings-hub.js +11 -3
- package/dist/ui/settings-quota-notice.js +100 -0
- package/dist/ui/settings-registry.js +1 -0
- package/dist/ui/settings-strings.js +2 -2
- package/dist/ui/settings-web-authority.js +2 -1
- package/dist/ui/shared/accounts-keepalive.css +7 -0
- package/dist/ui/shared/accounts.css +13 -0
- package/dist/ui/shared/app-route.js +1 -1
- package/dist/ui/shared/app-shell.js +9 -3
- package/dist/ui/shared/app-store.js +2 -2
- package/dist/ui/shared/app.css +13 -0
- package/dist/ui/shared/app.js +2 -1
- package/dist/ui/shared/hub-chat.css +1 -0
- package/dist/ui/shared/hub-owner.css +1 -1
- package/dist/ui/shared/loading.css +37 -0
- package/dist/ui/shared/preview-pages.js +41 -0
- package/dist/ui/shared/preview-panel-actions.js +168 -0
- package/dist/ui/shared/preview-panel.js +565 -0
- package/dist/ui/shared/preview-versions.js +155 -0
- package/dist/ui/shared/runtime-install.css +4 -0
- package/dist/ui/shared/signin.js +68 -6
- package/dist/ui/shared/ui-states.js +14 -3
- package/dist/ui/shared/workspace-follow.css +19 -0
- package/dist/ui/signin.html +7 -3
- package/dist/ui/structured-signin.js +31 -7
- package/dist/ui/workspace-follow-strings.js +28 -0
- package/dist/ui/workspace-panel.js +225 -36
- package/dist/update-install.d.ts +7 -0
- package/dist/update-install.js +23 -0
- package/dist/update-install.js.map +1 -1
- package/dist/usage/providers.d.ts +5 -0
- package/dist/usage/providers.js +5 -0
- package/dist/usage/providers.js.map +1 -1
- package/dist/usage/quota-notices.d.ts +38 -0
- package/dist/usage/quota-notices.js +160 -0
- package/dist/usage/quota-notices.js.map +1 -0
- package/dist/usage/usage-api.d.ts +1 -0
- package/dist/usage/usage-api.js +16 -0
- package/dist/usage/usage-api.js.map +1 -1
- package/dist/web-api.d.ts +33 -0
- package/dist/web-api.js +342 -8
- package/dist/web-api.js.map +1 -1
- package/dist/web-login.d.ts +35 -1
- package/dist/web-login.js +51 -5
- package/dist/web-login.js.map +1 -1
- package/dist/web-session.d.ts +11 -0
- package/dist/web-session.js +38 -1
- package/dist/web-session.js.map +1 -1
- package/dist/web-shell-routes.d.ts +1 -1
- package/dist/web-shell-routes.js +1 -1
- package/dist/web-shell-routes.js.map +1 -1
- package/dist/web-signin-link.d.ts +42 -0
- package/dist/web-signin-link.js +110 -0
- package/dist/web-signin-link.js.map +1 -0
- package/dist/windows-cli-api.d.ts +6 -0
- package/dist/windows-cli-api.js +11 -0
- package/dist/windows-cli-api.js.map +1 -1
- package/dist/windows-cli-worker.d.ts +3 -1
- package/dist/windows-cli-worker.js +18 -3
- package/dist/windows-cli-worker.js.map +1 -1
- package/dist/workspace-follow-parse.d.ts +36 -0
- package/dist/workspace-follow-parse.js +208 -0
- package/dist/workspace-follow-parse.js.map +1 -0
- package/dist/workspace-follow-records.d.ts +17 -0
- package/dist/workspace-follow-records.js +88 -0
- package/dist/workspace-follow-records.js.map +1 -0
- package/dist/workspace-follow.d.ts +41 -0
- package/dist/workspace-follow.js +143 -0
- package/dist/workspace-follow.js.map +1 -0
- package/dist/wsl-detect.d.ts +1 -0
- package/dist/wsl-detect.js +20 -0
- package/dist/wsl-detect.js.map +1 -0
- package/launcher/tmux-bundle.cjs +26 -10
- package/package.json +6 -2
- package/templates/runtime-install/install.ps1 +154 -13
package/dist/runtime-client.js
CHANGED
|
@@ -5,6 +5,7 @@ import { createServer } from "node:http";
|
|
|
5
5
|
import { hostname } from "node:os";
|
|
6
6
|
import { randomBytes, randomUUID } from "node:crypto";
|
|
7
7
|
import { join } from "node:path";
|
|
8
|
+
import { readFileSync } from "node:fs";
|
|
8
9
|
import { WindowsCliBridge, nativeWindowsTransport, WINDOWS_CLI_INVENTORY_FILE } from "./windows-cli.js";
|
|
9
10
|
import { probeCredentialProfileStatus, validateNativeTask, validWindowsAgentId } from "./windows-cli-worker.js";
|
|
10
11
|
import { validNativeSessionId } from "./windows-cli-providers.js";
|
|
@@ -12,8 +13,18 @@ import { RUNTIME_CREDENTIAL_CAPABILITY, credentialLoginRequired, credentialProfi
|
|
|
12
13
|
import { runtimeJobDigest, validateRuntimeServer } from "./runtime-client-store.js";
|
|
13
14
|
import { RUNTIME_ROTATE_PATH, RUNTIME_REINSTALL_CLOSE_PREFIX, runtimeClaimFingerprint } from "./runtime-protocol.js";
|
|
14
15
|
import { readRuntimeInfo } from "./runtime-build-info.js";
|
|
16
|
+
import { ProcessNotConfirmedEnded, RemoteAccounts } from "./runtime-remote-accounts.js";
|
|
17
|
+
import { isCreatedProfile } from "./runtime-profile-ownership.js";
|
|
18
|
+
import { killTree } from "./runtime-signin.js";
|
|
19
|
+
import { CLI_INSTALL_CAPABILITY, REMOTE_SIGNIN_CAPABILITY } from "./runtime-remote-setup.js";
|
|
20
|
+
import { managedCliRoot, managedInstaller, nativeInstallSupported } from "./runtime-cli-install.js";
|
|
21
|
+
import { isRuntimeRemoteOperation } from "./runtime-protocol.js";
|
|
22
|
+
import { PANE_IN_PROCESS_DIRECTORY, paneLedgerFiles } from "./runtime-pane-store.js";
|
|
23
|
+
import { findCli, nativeCliEnvironment } from "./windows-cli-worker.js";
|
|
24
|
+
import { spawn as childSpawn } from "./child-process.js";
|
|
15
25
|
import { RuntimeUpdateActivity } from "./runtime-update-activity.js";
|
|
16
26
|
import { parseRuntimeUpdateControl, RUNTIME_MANAGED_UPDATE_CAPABILITY, validRuntimeUpdateId } from "./runtime-update-protocol.js";
|
|
27
|
+
import { parseRuntimeUpdateStatus, RUNTIME_UPDATE_STATUS_CAPABILITY } from "./runtime-update-status.js";
|
|
17
28
|
import { validatePaneMcpBody } from "./runtime-pane-mcp-protocol.js";
|
|
18
29
|
import { validateRuntimePaneRequest, validateRuntimePaneShutdown } from "./runtime-pane-protocol.js";
|
|
19
30
|
export { RUNTIME_PANE_MODULES } from "./runtime-pane-assets.js";
|
|
@@ -73,6 +84,33 @@ function jsonBody(req) {
|
|
|
73
84
|
} });
|
|
74
85
|
});
|
|
75
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* `claude auth logout` for a profile. Output is not read, kept or logged: only whether the command ended well. A program that never started (no pid) has
|
|
89
|
+
* ended; for one that exists, ONLY its `close` is evidence that it ended (an `error` event can also mean it could not be killed). On the 30 s limit the
|
|
90
|
+
* whole process tree is killed and `close` is waited for up to five more seconds; if it still has not come the result is a ProcessNotConfirmedEnded, whose
|
|
91
|
+
* `ended` settles when the process really ends, so that whoever owns the profile keeps it busy until then.
|
|
92
|
+
*/
|
|
93
|
+
export function runLogoutProcess(executable, args, env, limitMs = 30_000, waitMs = 5_000, spawnChild = childSpawn, kill = killTree) {
|
|
94
|
+
return new Promise((done, fail) => {
|
|
95
|
+
const child = spawnChild(executable.command, [...executable.args, ...args], { env, shell: false, stdio: "ignore", windowsHide: true });
|
|
96
|
+
let ended = false, timer;
|
|
97
|
+
const closed = new Promise(accept => { child.on("close", () => accept()); });
|
|
98
|
+
closed.then(() => { ended = true; });
|
|
99
|
+
child.on("error", () => { if (child.pid === undefined) {
|
|
100
|
+
clearTimeout(timer);
|
|
101
|
+
ended = true;
|
|
102
|
+
done(null);
|
|
103
|
+
} });
|
|
104
|
+
child.on("close", code => { clearTimeout(timer); done(code); });
|
|
105
|
+
timer = setTimeout(() => {
|
|
106
|
+
kill(child);
|
|
107
|
+
const gave = setTimeout(() => { if (!ended)
|
|
108
|
+
fail(new ProcessNotConfirmedEnded(closed)); }, waitMs);
|
|
109
|
+
gave.unref?.();
|
|
110
|
+
}, limitMs);
|
|
111
|
+
timer.unref?.();
|
|
112
|
+
});
|
|
113
|
+
}
|
|
76
114
|
export class RuntimeClient {
|
|
77
115
|
options;
|
|
78
116
|
bootId = randomUUID();
|
|
@@ -96,6 +134,15 @@ export class RuntimeClient {
|
|
|
96
134
|
machinePaneLimit = 4;
|
|
97
135
|
paneEpoch = randomUUID();
|
|
98
136
|
active = new Set();
|
|
137
|
+
/** Run id -> the credential profile it runs under, so removing or signing out a profile waits for its runs. */
|
|
138
|
+
activeProfiles = new Map();
|
|
139
|
+
/** Terminals being opened right now, by profile (lower-case): they are not in the pane ledger until the host has answered. */
|
|
140
|
+
openingPanes = new Map();
|
|
141
|
+
remoteAccounts = null;
|
|
142
|
+
/** Ends a CLI install that is still running when this Runtime stops (the install's child process is the exact one it started). */
|
|
143
|
+
installAbort = new AbortController();
|
|
144
|
+
/** The Runtime's own installer (native Windows only): its closed table, its pinned versions and one install at a time. */
|
|
145
|
+
managed;
|
|
99
146
|
snapshots = new Map();
|
|
100
147
|
pendingPaneTools = new Map();
|
|
101
148
|
pendingTools = new Map();
|
|
@@ -107,10 +154,17 @@ export class RuntimeClient {
|
|
|
107
154
|
stoppedListeners = new Set();
|
|
108
155
|
activity = new RuntimeUpdateActivity();
|
|
109
156
|
stopPromise;
|
|
157
|
+
/** A stop that could not finish (an account process was not confirmed gone): everything is still held, and stop() may be called again. */
|
|
158
|
+
stopIncomplete = false;
|
|
159
|
+
/** A stop asked for the durable panes to be retired (a revocation does): that stays true across a stop that failed and is called again, a plain one included (Ctrl+C), until a stop has completed. */
|
|
160
|
+
retirePanesRequested = false;
|
|
110
161
|
generation = 0;
|
|
111
162
|
updateProtocol = false;
|
|
163
|
+
updateStatusProtocol = false;
|
|
164
|
+
updateStatus;
|
|
112
165
|
preparingUpdate = false;
|
|
113
166
|
trialFence;
|
|
167
|
+
activatedTrialId;
|
|
114
168
|
updateWait;
|
|
115
169
|
/** Set only when AgEnD ended the connection and the person must act; a local stop (Ctrl+C) leaves it undefined. */
|
|
116
170
|
stopReason;
|
|
@@ -118,15 +172,25 @@ export class RuntimeClient {
|
|
|
118
172
|
selfClosed = null;
|
|
119
173
|
constructor(options) {
|
|
120
174
|
this.options = options;
|
|
121
|
-
|
|
175
|
+
this.managed = nativeInstallSupported() ? managedInstaller({ root: managedCliRoot(options.store.directory), ...(options.installRoot ? { installRoot: options.installRoot } : {}) }, () => this.installAbort.signal) : null;
|
|
176
|
+
this.updateStatus = options.updateStatus === undefined ? undefined : parseRuntimeUpdateStatus(options.updateStatus);
|
|
177
|
+
const info = readRuntimeInfo({ panes: process.platform === "win32" || !!options.createPaneHost || !!options.openPaneLink, install: !!options.remoteAccounts?.installer || nativeInstallSupported() });
|
|
122
178
|
// Offered only when this client has a profile root to resolve names under; otherwise AgEnD must not ask for a profile.
|
|
123
179
|
if (options.managedUpdate?.trialId !== undefined && !validRuntimeUpdateId(options.managedUpdate.trialId))
|
|
124
180
|
throw Error("Invalid Runtime update trial");
|
|
125
|
-
this.runtimeInfo = { ...info, capabilities: [...info.capabilities.filter(name => options.credentialProfilesRoot || name !== RUNTIME_CREDENTIAL_CAPABILITY), ...(options.managedUpdate ? [RUNTIME_MANAGED_UPDATE_CAPABILITY] : [])] };
|
|
181
|
+
this.runtimeInfo = { ...info, capabilities: [...info.capabilities.filter(name => options.credentialProfilesRoot || name !== RUNTIME_CREDENTIAL_CAPABILITY), ...(options.managedUpdate ? [RUNTIME_MANAGED_UPDATE_CAPABILITY] : []), ...(this.updateStatus ? [RUNTIME_UPDATE_STATUS_CAPABILITY] : [])] };
|
|
182
|
+
// Remote account operations need the profile folder, and a way to run the Windows CLI (native Windows, or a test's own). `cli-install` also needs an installer.
|
|
183
|
+
const remote = !!options.credentialProfilesRoot && (process.platform === "win32" || !!options.remoteAccounts);
|
|
184
|
+
this.runtimeInfo = { ...this.runtimeInfo, capabilities: this.runtimeInfo.capabilities.filter(name => name === REMOTE_SIGNIN_CAPABILITY ? remote : name === CLI_INSTALL_CAPABILITY ? remote && !!(options.remoteAccounts?.installer || nativeInstallSupported()) : true) };
|
|
126
185
|
this.bridge = options.bridge ?? new WindowsCliBridge(nativeWindowsTransport, join(options.store.directory, WINDOWS_CLI_INVENTORY_FILE));
|
|
127
186
|
}
|
|
128
187
|
report(text) { this.options.report?.(text); }
|
|
129
188
|
online() { return !this.trialFence && this.welcomed && this.socket?.readyState === WebSocket.OPEN; }
|
|
189
|
+
setUpdateStatus(value) { this.updateStatus = parseRuntimeUpdateStatus(value); this.publishUpdateStatus(); }
|
|
190
|
+
publishUpdateStatus() {
|
|
191
|
+
if (this.updateStatus && this.updateStatusProtocol && this.online() && this.runtimeInfo.capabilities.includes(RUNTIME_UPDATE_STATUS_CAPABILITY))
|
|
192
|
+
this.send({ v: 1, type: "update.status", bootId: this.bootId, generation: this.generation, status: this.updateStatus });
|
|
193
|
+
}
|
|
130
194
|
waitUntilStopped() { return this.stopPromise ?? (this.stopped && this.closed ? Promise.resolve() : new Promise(done => this.stoppedListeners.add(done))); }
|
|
131
195
|
async start() {
|
|
132
196
|
if (!this.stopped)
|
|
@@ -136,6 +200,11 @@ export class RuntimeClient {
|
|
|
136
200
|
this.stopPromise = undefined;
|
|
137
201
|
this.activity = new RuntimeUpdateActivity();
|
|
138
202
|
}
|
|
203
|
+
// A previous stop that was not completed still owns a pairing lock and possibly a sign-in or logout process that was not confirmed ended: nothing starts
|
|
204
|
+
// over it, and its account module is never replaced while it holds anything.
|
|
205
|
+
if (this.stopIncomplete || this.unlock !== null || (this.remoteAccounts && !this.remoteAccounts.idle()))
|
|
206
|
+
throw new Error("The previous stop was not completed (an account process was not confirmed ended). Call stop() again, or inspect processes, before starting");
|
|
207
|
+
this.retirePanesRequested = false; // fully closed: whatever an earlier stop asked for is over
|
|
139
208
|
let credentials = this.options.store.credentials();
|
|
140
209
|
if (!credentials)
|
|
141
210
|
throw new Error("Pair this runtime before connecting");
|
|
@@ -143,6 +212,8 @@ export class RuntimeClient {
|
|
|
143
212
|
this.stopped = false;
|
|
144
213
|
this.closed = false;
|
|
145
214
|
this.stopReason = undefined;
|
|
215
|
+
this.activatedTrialId = undefined;
|
|
216
|
+
this.remoteAccounts = null; // a stopped one is closed to new work for good
|
|
146
217
|
try {
|
|
147
218
|
const systemBootId = process.platform === "win32" ? await readPaneSystemBootId() : undefined;
|
|
148
219
|
if (this.stopped)
|
|
@@ -190,6 +261,9 @@ export class RuntimeClient {
|
|
|
190
261
|
connect() {
|
|
191
262
|
if (this.stopped || !this.credentials)
|
|
192
263
|
return;
|
|
264
|
+
// A previous connection's positive check cannot vouch for this server generation.
|
|
265
|
+
if (this.updateStatus?.state === "current")
|
|
266
|
+
this.updateStatus = { state: "unknown" };
|
|
193
267
|
const url = validateRuntimeServer(this.credentials.server);
|
|
194
268
|
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
195
269
|
url.pathname = "/runtime/v1/connect";
|
|
@@ -198,6 +272,7 @@ export class RuntimeClient {
|
|
|
198
272
|
maxPayload: MAX_FRAME, handshakeTimeout: 15_000, perMessageDeflate: false });
|
|
199
273
|
this.welcomed = false;
|
|
200
274
|
this.updateProtocol = false;
|
|
275
|
+
this.updateStatusProtocol = false;
|
|
201
276
|
this.paneEpoch = randomUUID();
|
|
202
277
|
socket.on("open", () => {
|
|
203
278
|
if (this.stopped || this.socket !== socket) {
|
|
@@ -224,7 +299,7 @@ export class RuntimeClient {
|
|
|
224
299
|
if (response.statusCode === 401 || response.statusCode === 403) {
|
|
225
300
|
this.report("Runtime credential was refused. Re-pair after the machine is authorized.");
|
|
226
301
|
this.stopReason = { kind: "refused", ...(response.statusCode === 403 ? { detail: "HTTP 403" } : {}) };
|
|
227
|
-
void this.stop();
|
|
302
|
+
void this.stop().catch(error => this.report(error instanceof Error ? error.message : "Runtime stop was not completed"));
|
|
228
303
|
}
|
|
229
304
|
else
|
|
230
305
|
socket.terminate();
|
|
@@ -235,6 +310,8 @@ export class RuntimeClient {
|
|
|
235
310
|
this.socket = null;
|
|
236
311
|
this.welcomed = false;
|
|
237
312
|
this.paneEpoch = randomUUID();
|
|
313
|
+
// Whatever the old connection started over account requests is over with it: a sign-in it opened is ended, and what it still has in flight may not start more.
|
|
314
|
+
this.remoteAccounts?.connectionChanged();
|
|
238
315
|
if (this.updateWait) {
|
|
239
316
|
const pending = this.updateWait;
|
|
240
317
|
this.updateWait = undefined;
|
|
@@ -250,7 +327,7 @@ export class RuntimeClient {
|
|
|
250
327
|
const why = reason.toString().replace(/[^ -~]/g, "?").slice(0, 120);
|
|
251
328
|
this.report(this.selfClosed === socket ? "This Runtime could not read a message from AgEnD and closed the connection." : `AgEnD closed the connection (code 1008${why ? `: ${why}` : ""}).`);
|
|
252
329
|
this.stopReason = this.selfClosed === socket ? { kind: "incompatible" } : { kind: why === "Machine revoked" ? "revoked" : why === "Connection replaced" ? "replaced" : why.startsWith(RUNTIME_REINSTALL_CLOSE_PREFIX) ? "reinstall" : "rejected", ...(why ? { detail: why } : {}) };
|
|
253
|
-
void this.stop({ retirePanes: why === "Machine revoked" });
|
|
330
|
+
void this.stop({ retirePanes: why === "Machine revoked" }).catch(error => this.report(error instanceof Error ? error.message : "Runtime stop was not completed"));
|
|
254
331
|
return;
|
|
255
332
|
}
|
|
256
333
|
this.report("Disconnected. Existing execution is not replayed; reconnecting…");
|
|
@@ -294,6 +371,7 @@ export class RuntimeClient {
|
|
|
294
371
|
this.welcomed = true;
|
|
295
372
|
this.generation = value.generation;
|
|
296
373
|
this.updateProtocol = value.updateProtocol === 1;
|
|
374
|
+
this.updateStatusProtocol = value.updateStatusProtocol === 1;
|
|
297
375
|
this.reconnectAttempt = 0;
|
|
298
376
|
if (this.graceTimer) {
|
|
299
377
|
clearTimeout(this.graceTimer);
|
|
@@ -303,6 +381,7 @@ export class RuntimeClient {
|
|
|
303
381
|
if (!this.trialFence)
|
|
304
382
|
for (const job of this.options.store.list())
|
|
305
383
|
this.publish(job);
|
|
384
|
+
this.publishUpdateStatus();
|
|
306
385
|
this.options.managedUpdate?.authenticated?.({ bootId: this.bootId, generation: this.generation, ...(this.updateProtocol ? { updateProtocol: 1 } : {}), runtimeInfo: this.runtimeInfo });
|
|
307
386
|
return;
|
|
308
387
|
}
|
|
@@ -313,6 +392,7 @@ export class RuntimeClient {
|
|
|
313
392
|
if (control.phase === "activated") {
|
|
314
393
|
if (this.trialFence?.id !== control.id || !this.trialFence.current() || !this.locallyIdle())
|
|
315
394
|
throw Error("Runtime trial is no longer idle");
|
|
395
|
+
this.activatedTrialId = control.id;
|
|
316
396
|
this.trialFence.release();
|
|
317
397
|
this.trialFence = undefined;
|
|
318
398
|
// Release synchronously: the server's next ordered frame may already contain ordinary work.
|
|
@@ -328,7 +408,7 @@ export class RuntimeClient {
|
|
|
328
408
|
if (value.type === "revoked") {
|
|
329
409
|
this.report("This machine was revoked by AgEnD.");
|
|
330
410
|
this.stopReason = { kind: "revoked" };
|
|
331
|
-
await this.stop({ retirePanes: true });
|
|
411
|
+
await this.stop({ retirePanes: true }).catch(error => this.report(error instanceof Error ? error.message : "Runtime stop was not completed"));
|
|
332
412
|
return;
|
|
333
413
|
}
|
|
334
414
|
if (!this.welcomed)
|
|
@@ -373,9 +453,20 @@ export class RuntimeClient {
|
|
|
373
453
|
const request = validateRuntimePaneRequest(value.request);
|
|
374
454
|
this.machinePaneLimit = value.maxAgents;
|
|
375
455
|
const epoch = this.paneEpoch;
|
|
376
|
-
let leave;
|
|
456
|
+
let leave, opening;
|
|
377
457
|
try {
|
|
378
458
|
leave = this.activity.enter();
|
|
459
|
+
// A terminal that would run under a profile that AgEnD is signing out, removing or signing in right now is not started; and from here until the host
|
|
460
|
+
// has answered it counts as using its profile, because the pane ledger does not show it yet.
|
|
461
|
+
if (request.action === "open") {
|
|
462
|
+
const profile = request.launch.credentialProfile ?? this.credentialProfileFor(request.launch.cli, undefined);
|
|
463
|
+
if (profile !== undefined) {
|
|
464
|
+
if (this.remoteAccounts?.profileReserved(profile))
|
|
465
|
+
throw new Error(`Credential profile "${profile}" is being changed from AgEnD; try again in a moment`);
|
|
466
|
+
opening = profile.toLowerCase();
|
|
467
|
+
this.openingPanes.set(opening, (this.openingPanes.get(opening) ?? 0) + 1);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
379
470
|
const host = await this.panes();
|
|
380
471
|
// A terminal for an agent with no profile of its own starts under this pairing's default profile, when there is one. The default is passed
|
|
381
472
|
// beside the launch, not inside it: the host decides with it only for a pane that is new, so a pane that is already running reattaches
|
|
@@ -398,6 +489,40 @@ export class RuntimeClient {
|
|
|
398
489
|
catch (error) {
|
|
399
490
|
this.send({ v: 1, type: "pane.response", id: value.id, ok: false, error: message(error) });
|
|
400
491
|
}
|
|
492
|
+
finally {
|
|
493
|
+
if (opening !== undefined) {
|
|
494
|
+
const left = (this.openingPanes.get(opening) ?? 1) - 1;
|
|
495
|
+
if (left > 0)
|
|
496
|
+
this.openingPanes.set(opening, left);
|
|
497
|
+
else
|
|
498
|
+
this.openingPanes.delete(opening);
|
|
499
|
+
}
|
|
500
|
+
leave?.();
|
|
501
|
+
}
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
if (value.type === "account.request") {
|
|
505
|
+
// Not journaled by AgEnD and not stored here: a sign-in's URL and code travel in these frames and nowhere else.
|
|
506
|
+
if (Object.keys(value).some(key => !["v", "type", "id", "operation", "payload"].includes(key)) || typeof value.id !== "string" || !/^[A-Za-z0-9._:-]{1,128}$/.test(value.id)
|
|
507
|
+
|| !isRuntimeRemoteOperation(value.operation))
|
|
508
|
+
throw new Error("Invalid account request");
|
|
509
|
+
// The answer belongs to the connection that asked: it is sent only while that very connection (socket and AgEnD's generation for it) is still the live
|
|
510
|
+
// one, never to a later connection, and the request is refused outright while a managed update is holding new work.
|
|
511
|
+
const socket = this.socket, generation = this.generation, id = value.id;
|
|
512
|
+
const sameConnection = () => !this.stopped && !!socket && this.socket === socket && this.generation === generation && this.welcomed && socket.readyState === WebSocket.OPEN;
|
|
513
|
+
const current = () => sameConnection() && this.online();
|
|
514
|
+
const reply = (frame) => { if (sameConnection())
|
|
515
|
+
this.send(frame); };
|
|
516
|
+
let leave;
|
|
517
|
+
try {
|
|
518
|
+
if (this.trialFence)
|
|
519
|
+
throw new Error("Runtime update is holding new work");
|
|
520
|
+
leave = this.activity.enter();
|
|
521
|
+
reply({ v: 1, type: "account.response", id, ok: true, result: await this.remote().handle(value.operation, value.payload, current) });
|
|
522
|
+
}
|
|
523
|
+
catch (error) {
|
|
524
|
+
reply({ v: 1, type: "account.response", id, ok: false, error: message(error) });
|
|
525
|
+
}
|
|
401
526
|
finally {
|
|
402
527
|
leave?.();
|
|
403
528
|
}
|
|
@@ -427,7 +552,7 @@ export class RuntimeClient {
|
|
|
427
552
|
this.send({ v: 1, type: "pane.output", snapshot }); };
|
|
428
553
|
if (this.options.createPaneHost)
|
|
429
554
|
this.paneOpening = import("./runtime-pane-store.js").then(({ RuntimePaneStore }) => {
|
|
430
|
-
const store = new RuntimePaneStore(join(this.options.store.directory,
|
|
555
|
+
const store = new RuntimePaneStore(join(this.options.store.directory, PANE_IN_PROCESS_DIRECTORY));
|
|
431
556
|
store.recoverInterrupted();
|
|
432
557
|
return this.paneHost = this.options.createPaneHost({ store, bootId: this.bootId, online: () => !this.stopped && this.online(), maxAgents: () => this.machinePaneLimit, output });
|
|
433
558
|
});
|
|
@@ -475,6 +600,7 @@ export class RuntimeClient {
|
|
|
475
600
|
this.publish(job);
|
|
476
601
|
if (task.finishedAt) {
|
|
477
602
|
this.active.delete(task.id);
|
|
603
|
+
this.activeProfiles.delete(task.id);
|
|
478
604
|
this.closeMcp(task.id);
|
|
479
605
|
}
|
|
480
606
|
}
|
|
@@ -519,12 +645,14 @@ export class RuntimeClient {
|
|
|
519
645
|
}, this.options.credentialWatchMs ?? 5000);
|
|
520
646
|
this.credentialWatch.unref?.();
|
|
521
647
|
}
|
|
522
|
-
statusOf(cli, directory) {
|
|
648
|
+
statusOf(cli, directory, authorized) {
|
|
523
649
|
if (this.options.credentialStatus)
|
|
524
|
-
return this.options.credentialStatus(cli, directory);
|
|
650
|
+
return authorized ? this.options.credentialStatus(cli, directory, authorized) : this.options.credentialStatus(cli, directory);
|
|
525
651
|
if (this.options.credentialLogin)
|
|
526
652
|
return this.options.credentialLogin(cli, directory).then(loggedIn => ({ loggedIn }));
|
|
527
|
-
|
|
653
|
+
// The lookup of the CLI is the Runtime's own (a test or the install work may supply one); production leaves it to `findCli`.
|
|
654
|
+
const find = this.options.remoteAccounts?.find;
|
|
655
|
+
return probeCredentialProfileStatus(cli, directory, find ? id => find(id) : undefined, undefined, authorized);
|
|
528
656
|
}
|
|
529
657
|
remember(root, cli, name, answer) {
|
|
530
658
|
rememberCredentialStatus(root, cli, name, answer);
|
|
@@ -545,16 +673,23 @@ export class RuntimeClient {
|
|
|
545
673
|
return directory;
|
|
546
674
|
}
|
|
547
675
|
/** Names and signed-in yes/no only. `force` (an explicit "Detect again") asks each profile's CLI; otherwise the last known answer is reported. */
|
|
548
|
-
async credentialReport(force) {
|
|
676
|
+
async credentialReport(force, authorized) {
|
|
549
677
|
const root = this.options.credentialProfilesRoot;
|
|
550
678
|
if (!root)
|
|
551
679
|
return undefined;
|
|
680
|
+
// `authorized` (an install's live consent and connection check) is asked before each profile's status is started and again before its answer is written to the cache.
|
|
681
|
+
const still = () => { if (authorized && !authorized())
|
|
682
|
+
throw new Error("Authorization expired during CLI discovery"); };
|
|
552
683
|
if (force)
|
|
553
684
|
for (const name of listCredentialProfileNames(root, "claude-code")) {
|
|
685
|
+
still();
|
|
554
686
|
try {
|
|
555
|
-
|
|
687
|
+
const answer = await this.statusOf("claude-code", requireCredentialProfile(root, "claude-code", name), authorized);
|
|
688
|
+
still();
|
|
689
|
+
this.remember(root, "claude-code", name, answer);
|
|
556
690
|
}
|
|
557
691
|
catch {
|
|
692
|
+
still();
|
|
558
693
|
this.remember(root, "claude-code", name, { loggedIn: null });
|
|
559
694
|
}
|
|
560
695
|
}
|
|
@@ -563,15 +698,110 @@ export class RuntimeClient {
|
|
|
563
698
|
name = this.options.store.credentialDefault();
|
|
564
699
|
}
|
|
565
700
|
catch { /* reported as no default; a run refuses with the real error */ }
|
|
566
|
-
return credentialProfileReport(root, name);
|
|
701
|
+
return credentialProfileReport(root, name, profile => isCreatedProfile(root, "claude-code", profile));
|
|
702
|
+
}
|
|
703
|
+
computerBoot;
|
|
704
|
+
computerBootValue;
|
|
705
|
+
/** The computer's boot identity, read once (it cannot change while this Runtime runs). Unknown is never evidence either way. */
|
|
706
|
+
systemBoot() { return this.computerBoot ??= (this.options.remoteAccounts?.systemBootId ?? readPaneSystemBootId)().catch(() => undefined).then(value => this.computerBootValue = value); }
|
|
707
|
+
/**
|
|
708
|
+
* Whether a task or terminal is running under this profile (case-insensitively: on Windows `Work` and `work` are one folder). Terminals come from the
|
|
709
|
+
* pane ledgers (`paneLedgerFiles`: the pane host's own state folder in production, the in-process folder in tests; a missing ledger is "none") and from
|
|
710
|
+
* the terminals this Runtime is opening right now. A row recorded under another boot of the computer is a terminal that cannot still be running (the pane
|
|
711
|
+
* store treats it the same way). A ledger that cannot be read, or a default profile that cannot be read while a terminal needs it, is `unknown`: the
|
|
712
|
+
* caller refuses with a message that says the state could not be confirmed. A Claude Code terminal that names no profile runs under this pairing's
|
|
713
|
+
* default, which the ledger does not hold.
|
|
714
|
+
*/
|
|
715
|
+
async profileInUse(name) { await this.systemBoot(); return this.profileInUseNow(name); }
|
|
716
|
+
/** The same answer with no await, from the boot identity read earlier (before it is read, a row with a boot id is counted as running: the safe side). */
|
|
717
|
+
profileInUseNow(name) {
|
|
718
|
+
const same = (other) => typeof other === "string" && other.toLowerCase() === name.toLowerCase();
|
|
719
|
+
for (const used of this.activeProfiles.values())
|
|
720
|
+
if (same(used))
|
|
721
|
+
return "task";
|
|
722
|
+
if (this.openingPanes.has(name.toLowerCase()))
|
|
723
|
+
return "pane";
|
|
724
|
+
let fallback, fallbackReadable = true;
|
|
725
|
+
try {
|
|
726
|
+
fallback = this.options.store.credentialDefault();
|
|
727
|
+
}
|
|
728
|
+
catch {
|
|
729
|
+
fallbackReadable = false;
|
|
730
|
+
}
|
|
731
|
+
const boot = this.computerBootValue;
|
|
732
|
+
let unknown = false;
|
|
733
|
+
for (const file of paneLedgerFiles(this.options.store.directory)) {
|
|
734
|
+
try {
|
|
735
|
+
const raw = JSON.parse(readFileSync(file, "utf8"));
|
|
736
|
+
for (const row of object(raw) && object(raw.panes) ? Object.values(raw.panes) : []) {
|
|
737
|
+
const launch = object(row) && object(row.launch) ? row.launch : undefined, snapshot = object(row) && object(row.snapshot) ? row.snapshot : undefined;
|
|
738
|
+
if (!launch || snapshot?.state === "exited")
|
|
739
|
+
continue;
|
|
740
|
+
if (typeof row.systemBootId === "string" && boot && boot !== row.systemBootId)
|
|
741
|
+
continue;
|
|
742
|
+
if (same(launch.credentialProfile))
|
|
743
|
+
return "pane";
|
|
744
|
+
if (launch.credentialProfile === undefined && launch.cli === "claude-code") {
|
|
745
|
+
if (!fallbackReadable)
|
|
746
|
+
unknown = true;
|
|
747
|
+
else if (same(fallback))
|
|
748
|
+
return "pane";
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
catch (error) {
|
|
753
|
+
if (error.code !== "ENOENT")
|
|
754
|
+
unknown = true;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
return unknown ? "unknown" : undefined;
|
|
758
|
+
}
|
|
759
|
+
/** #3190 Part 3a: the remote account operations (switches, sign-in, sign-out, remove, install), built on first use. */
|
|
760
|
+
remote() {
|
|
761
|
+
const root = this.options.credentialProfilesRoot, extra = this.options.remoteAccounts;
|
|
762
|
+
if (!root)
|
|
763
|
+
throw new Error("This Runtime has no credential profile folder, so it cannot manage accounts. Update or restart the Runtime.");
|
|
764
|
+
if (process.platform !== "win32" && !extra)
|
|
765
|
+
throw new Error("Managing accounts from AgEnD needs native Windows Node, under the Windows user whose Claude Code this Runtime uses.");
|
|
766
|
+
return this.remoteAccounts ??= new RemoteAccounts({
|
|
767
|
+
pairingDirectory: this.options.store.directory, credentialRoot: root,
|
|
768
|
+
status: (cli, directory) => this.statusOf(cli, directory),
|
|
769
|
+
find: extra?.find ?? ((cli) => findCli(cli)),
|
|
770
|
+
environment: extra?.environment ?? (() => nativeCliEnvironment()),
|
|
771
|
+
runLogout: extra?.runLogout ?? ((executable, args, env) => runLogoutProcess(executable, args, env)),
|
|
772
|
+
inUse: name => this.profileInUse(name), inUseNow: name => this.profileInUseNow(name), report: text => this.report(text),
|
|
773
|
+
// Throws when `credential-default.json` cannot be read: an unreadable default is not "no default" (the remove then answers `unconfirmed`).
|
|
774
|
+
defaultProfile: () => this.options.store.credentialDefault(),
|
|
775
|
+
enter: () => this.activity.enter(),
|
|
776
|
+
// With `authorized` (an account operation still waiting for its answer, which already holds a share of the Runtime's activity) the new inventory is sent over the same
|
|
777
|
+
// connection BEFORE the answer, so the dashboard that reads it on the answer sees the change; a revoked consent sends nothing. Without it (an install) it is only started.
|
|
778
|
+
changed: authorized => {
|
|
779
|
+
this.credentialStamp = this.stamp();
|
|
780
|
+
if (authorized)
|
|
781
|
+
return authorized() ? this.readInventory(false, authorized).then(() => { }, () => { }) : undefined;
|
|
782
|
+
void this.refreshInventory(false).catch(() => { });
|
|
783
|
+
},
|
|
784
|
+
// A CLI was just installed: the cached list is stale, so detect for real and send it (this request already holds a share of the Runtime's activity).
|
|
785
|
+
installed: async (authorized) => { await this.readInventory(true, authorized); },
|
|
786
|
+
// Native Windows installs from the Runtime's own closed table (3b); a test supplies its own installer.
|
|
787
|
+
...(extra?.installer ? { installer: extra.installer } : this.managed ? { installer: this.managed } : {}),
|
|
788
|
+
...(extra?.switchWatchMs ? { switchWatchMs: extra.switchWatchMs } : {}), ...(extra?.signIn ? { signIn: extra.signIn } : {}), ...(extra?.ownership ? { ownership: extra.ownership } : {}),
|
|
789
|
+
...(extra?.now ? { now: extra.now } : {}),
|
|
790
|
+
});
|
|
567
791
|
}
|
|
568
792
|
beginDiscovery() {
|
|
569
793
|
void this.refreshInventory().catch(() => this.report("CLI discovery failed; refresh it from AgEnD after checking the local installation."));
|
|
570
794
|
this.watchCredentialCache();
|
|
571
795
|
}
|
|
572
796
|
refreshInventory(force = false) { return this.activity.run(() => this.readInventory(force)); }
|
|
573
|
-
async readInventory(force) {
|
|
574
|
-
const
|
|
797
|
+
async readInventory(force, authorized) {
|
|
798
|
+
const still = (when) => { if (authorized && !authorized())
|
|
799
|
+
throw new Error(`Authorization expired ${when} CLI discovery`); };
|
|
800
|
+
still("before");
|
|
801
|
+
const probed = await (authorized ? this.bridge.probe({ force }, authorized) : this.bridge.probe({ force }));
|
|
802
|
+
still("during");
|
|
803
|
+
const credentialProfiles = await this.credentialReport(force, authorized);
|
|
804
|
+
still("during");
|
|
575
805
|
const inventory = credentialProfiles ? { ...probed, credentialProfiles } : probed;
|
|
576
806
|
this.inventory = inventory;
|
|
577
807
|
if (this.online())
|
|
@@ -652,6 +882,12 @@ export class RuntimeClient {
|
|
|
652
882
|
try {
|
|
653
883
|
// Fail closed, and as a confirmed failed turn: an unknown, unsigned or unusable profile never falls back to another account.
|
|
654
884
|
const profile = this.credentialProfileFor(task.cli, run.credentialProfile);
|
|
885
|
+
// Registered (or refused) in one synchronous step with the look at AgEnD's own change of that profile, so a sign-out or removal that has reserved the
|
|
886
|
+
// profile is never raced by a task, and one that has not yet reserved it finds this task in `activeProfiles`.
|
|
887
|
+
if (profile && this.remoteAccounts?.profileReserved(profile))
|
|
888
|
+
throw new Error(`Credential profile "${profile}" is being changed from AgEnD; try again in a moment`);
|
|
889
|
+
if (profile)
|
|
890
|
+
this.activeProfiles.set(task.requestId, profile);
|
|
655
891
|
const credentialHome = profile ? await this.credentialHome(task.cli, profile) : undefined;
|
|
656
892
|
const mcp = payload.mcp ? await this.openMcp(task.requestId, payload.mcp.tools) : undefined;
|
|
657
893
|
if (this.stopped || !this.online())
|
|
@@ -667,6 +903,7 @@ export class RuntimeClient {
|
|
|
667
903
|
}
|
|
668
904
|
catch (error) {
|
|
669
905
|
this.active.delete(task.requestId);
|
|
906
|
+
this.activeProfiles.delete(task.requestId);
|
|
670
907
|
this.closeMcp(task.requestId);
|
|
671
908
|
const failed = { ...accepted.job.task, status: "failed", error: message(error), finishedAt: Date.now(), outcomeConfirmed: true };
|
|
672
909
|
this.update(failed);
|
|
@@ -676,7 +913,7 @@ export class RuntimeClient {
|
|
|
676
913
|
locallyIdle() {
|
|
677
914
|
return this.activity.pending === 0 && this.active.size === 0 && !this.options.store.blocked()
|
|
678
915
|
&& this.bridge.idleForUpdate?.() === true && this.pendingTools.size === 0 && this.pendingPaneTools.size === 0
|
|
679
|
-
&& !(this.paneOpening && !this.paneHost) && (this.socket?.bufferedAmount ?? 1) === 0;
|
|
916
|
+
&& !(this.paneOpening && !this.paneHost) && (this.socket?.bufferedAmount ?? 1) === 0 && (this.remoteAccounts?.idle() ?? true);
|
|
680
917
|
}
|
|
681
918
|
updateRpc(phase, id, phases) {
|
|
682
919
|
if (!this.welcomed || !this.updateProtocol || this.socket?.readyState !== WebSocket.OPEN || this.updateWait)
|
|
@@ -753,6 +990,9 @@ export class RuntimeClient {
|
|
|
753
990
|
}
|
|
754
991
|
/** The parent persists activation intent before this call; an unconfirmed answer is never rollback permission. */
|
|
755
992
|
async activateTrial(id) {
|
|
993
|
+
// A received exact acknowledgement is a durable fact for this process lifetime, not a second admission.
|
|
994
|
+
if (this.activatedTrialId === id && this.options.managedUpdate?.trialId === id)
|
|
995
|
+
return true;
|
|
756
996
|
if (this.trialFence?.id !== id || !this.locallyIdle())
|
|
757
997
|
return false;
|
|
758
998
|
return await this.updateRpc("activate", id, ["activated", "busy", "cancelled"]) === "activated";
|
|
@@ -847,15 +1087,24 @@ export class RuntimeClient {
|
|
|
847
1087
|
this.pendingTools.clear();
|
|
848
1088
|
}
|
|
849
1089
|
stop(options = {}) {
|
|
1090
|
+
// The request is remembered before anything else: a stop already running (it may be a plain one) picks it up when it reaches the panes, and a stop that fails
|
|
1091
|
+
// before the panes (an account process not confirmed ended) keeps it for the plain stop() that tries again.
|
|
1092
|
+
if (options.retirePanes)
|
|
1093
|
+
this.retirePanesRequested = true;
|
|
850
1094
|
if (this.stopPromise)
|
|
851
1095
|
return this.stopPromise;
|
|
852
|
-
if (this.stopped)
|
|
1096
|
+
if (this.stopped && !this.stopIncomplete)
|
|
853
1097
|
return Promise.resolve();
|
|
854
1098
|
this.stopped = true;
|
|
855
1099
|
this.welcomed = false;
|
|
1100
|
+
this.stopIncomplete = false;
|
|
1101
|
+
this.installAbort.abort();
|
|
856
1102
|
this.activity.close();
|
|
857
|
-
// Own cleanup before callbacks (bridge.close, pane cleanup) can re-enter stop().
|
|
858
|
-
|
|
1103
|
+
// Own cleanup before callbacks (bridge.close, pane cleanup) can re-enter stop(). A stop that fails leaves the lock and the account module held and can be
|
|
1104
|
+
// called again.
|
|
1105
|
+
const stopping = Promise.resolve().then(() => this.stopOwned(options)).catch(error => { if (this.stopPromise === stopping)
|
|
1106
|
+
this.stopPromise = undefined; this.stopIncomplete = true; throw error; });
|
|
1107
|
+
return this.stopPromise = stopping;
|
|
859
1108
|
}
|
|
860
1109
|
async stopOwned(options) {
|
|
861
1110
|
if (this.updateWait) {
|
|
@@ -888,9 +1137,16 @@ export class RuntimeClient {
|
|
|
888
1137
|
}
|
|
889
1138
|
// A cancelled start may still finish its durable credential write. Do not release the profile to another writer.
|
|
890
1139
|
await this.startupRotation?.catch(() => { });
|
|
1140
|
+
// A sign-in that is open ends with the connection (its child is killed), and the folded counts of the audit log are written. A login or logout process that
|
|
1141
|
+
// is not confirmed gone fails the stop HERE, before the pairing's lock is let go, so no other client can start over a process that may still be writing.
|
|
1142
|
+
if (this.remoteAccounts) {
|
|
1143
|
+
await this.remoteAccounts.stop();
|
|
1144
|
+
if (!this.remoteAccounts.idle())
|
|
1145
|
+
throw new Error("Account process shutdown was not confirmed; inspect processes before stopping or restarting");
|
|
1146
|
+
}
|
|
891
1147
|
await this.paneOpening?.then(async (host) => {
|
|
892
1148
|
try {
|
|
893
|
-
if (options.retirePanes && "retireOwned" in host)
|
|
1149
|
+
if ((options.retirePanes || this.retirePanesRequested) && "retireOwned" in host)
|
|
894
1150
|
await host.retireOwned();
|
|
895
1151
|
}
|
|
896
1152
|
finally {
|
|
@@ -920,6 +1176,7 @@ export class RuntimeClient {
|
|
|
920
1176
|
this.unlock?.();
|
|
921
1177
|
this.unlock = null;
|
|
922
1178
|
this.closed = true;
|
|
1179
|
+
this.retirePanesRequested = false;
|
|
923
1180
|
for (const done of this.stoppedListeners)
|
|
924
1181
|
done();
|
|
925
1182
|
this.stoppedListeners.clear();
|