@songsid/agend 2.3.5-alpha.10 → 2.3.5-alpha.11
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/accounts-view.d.ts +14 -0
- package/dist/accounts-view.js +22 -6
- package/dist/accounts-view.js.map +1 -1
- package/dist/agent-cli-instructions.md +2 -2
- package/dist/auth-api.d.ts +48 -16
- package/dist/auth-api.js +99 -32
- package/dist/auth-api.js.map +1 -1
- package/dist/authority/settings-role.d.ts +56 -0
- package/dist/authority/settings-role.js +48 -0
- package/dist/authority/settings-role.js.map +1 -0
- package/dist/backend/claude-code.d.ts +2 -0
- package/dist/backend/claude-code.js +16 -3
- package/dist/backend/claude-code.js.map +1 -1
- package/dist/backend/cli-env-probe.js +6 -2
- package/dist/backend/cli-env-probe.js.map +1 -1
- package/dist/backend/codex.d.ts +5 -3
- package/dist/backend/codex.js +31 -13
- package/dist/backend/codex.js.map +1 -1
- package/dist/backend/credential-profile.d.ts +2 -0
- package/dist/backend/credential-profile.js +2 -0
- package/dist/backend/credential-profile.js.map +1 -1
- package/dist/backend/kiro.js +1 -1
- package/dist/backend/kiro.js.map +1 -1
- package/dist/backend/types.d.ts +5 -1
- package/dist/backend/types.js.map +1 -1
- package/dist/backend-availability.d.ts +15 -0
- package/dist/backend-availability.js +37 -1
- package/dist/backend-availability.js.map +1 -1
- package/dist/build-provenance.json +1 -1
- package/dist/bundled-tmux-guard.d.ts +4 -0
- package/dist/bundled-tmux-guard.js +7 -0
- package/dist/bundled-tmux-guard.js.map +1 -1
- package/dist/claude-auth-status.d.ts +20 -8
- package/dist/claude-auth-status.js +38 -22
- package/dist/claude-auth-status.js.map +1 -1
- package/dist/cli-audited.d.ts +60 -0
- package/dist/cli-audited.js +84 -0
- package/dist/cli-audited.js.map +1 -0
- package/dist/cli-capability.d.ts +36 -5
- package/dist/cli-capability.js +2 -2
- package/dist/cli-capability.js.map +1 -1
- package/dist/cli-caps-module.d.ts +5 -1
- package/dist/cli-caps-module.js +4 -2
- package/dist/cli-caps-module.js.map +1 -1
- package/dist/cli-registry-check.js +16 -2
- package/dist/cli-registry-check.js.map +1 -1
- package/dist/cli-registry.d.ts +56 -4
- package/dist/cli-registry.js +1 -1
- package/dist/cli-registry.js.map +1 -1
- package/dist/cli-spec-antigravity.d.ts +12 -1
- package/dist/cli-spec-antigravity.js +13 -1
- package/dist/cli-spec-antigravity.js.map +1 -1
- package/dist/cli-spec-claude-code.d.ts +9 -0
- package/dist/cli-spec-claude-code.js +4 -2
- package/dist/cli-spec-claude-code.js.map +1 -1
- package/dist/cli-spec-codex.d.ts +10 -1
- package/dist/cli-spec-codex.js +5 -3
- package/dist/cli-spec-codex.js.map +1 -1
- package/dist/cli-spec-grok.d.ts +5 -0
- package/dist/cli-spec-grok.js +6 -1
- package/dist/cli-spec-grok.js.map +1 -1
- package/dist/cli-spec-kiro-cli.d.ts +7 -1
- package/dist/cli-spec-kiro-cli.js +7 -3
- package/dist/cli-spec-kiro-cli.js.map +1 -1
- package/dist/cli-spec-muse.d.ts +2 -0
- package/dist/cli-spec-muse.js +3 -1
- package/dist/cli-spec-muse.js.map +1 -1
- package/dist/cli-spec-opencode.d.ts +11 -1
- package/dist/cli-spec-opencode.js +7 -2
- package/dist/cli-spec-opencode.js.map +1 -1
- package/dist/cli.js +28 -1
- package/dist/cli.js.map +1 -1
- package/dist/daemon.d.ts +3 -0
- package/dist/daemon.js +17 -2
- package/dist/daemon.js.map +1 -1
- package/dist/fleet-context.d.ts +5 -1
- package/dist/fleet-manager.d.ts +337 -69
- package/dist/fleet-manager.js +1247 -355
- package/dist/fleet-manager.js.map +1 -1
- package/dist/fleet-process-handlers.d.ts +1 -1
- package/dist/fleet-process-handlers.js +3 -2
- package/dist/fleet-process-handlers.js.map +1 -1
- package/dist/general-knowledge/skills/concepts/SKILL.md +21 -14
- package/dist/general-knowledge/skills/credential-profiles/SKILL.md +9 -8
- package/dist/general-knowledge/skills/cross-instance-messaging/SKILL.md +9 -1
- package/dist/general-knowledge/skills/web-dashboard/SKILL.md +27 -20
- package/dist/instance-lifecycle.js +4 -2
- package/dist/instance-lifecycle.js.map +1 -1
- package/dist/instructions.js +29 -6
- package/dist/instructions.js.map +1 -1
- package/dist/locale.js +119 -75
- package/dist/locale.js.map +1 -1
- package/dist/login-manager.d.ts +2 -2
- package/dist/login-manager.js +3 -2
- package/dist/login-manager.js.map +1 -1
- package/dist/native-model-catalog.d.ts +20 -0
- package/dist/native-model-catalog.js +107 -2
- package/dist/native-model-catalog.js.map +1 -1
- package/dist/public-web-gateway.js +1 -1
- package/dist/public-web-gateway.js.map +1 -1
- package/dist/runtime-api.d.ts +1 -1
- package/dist/runtime-api.js +104 -12
- package/dist/runtime-api.js.map +1 -1
- package/dist/runtime-autostart.d.ts +61 -0
- package/dist/runtime-autostart.js +161 -0
- package/dist/runtime-autostart.js.map +1 -0
- package/dist/runtime-background.d.ts +200 -0
- package/dist/runtime-background.js +480 -0
- package/dist/runtime-background.js.map +1 -0
- package/dist/runtime-build-info.js +5 -5
- package/dist/runtime-build-info.js.map +1 -1
- package/dist/runtime-cli-background.d.ts +92 -0
- package/dist/runtime-cli-background.js +336 -0
- package/dist/runtime-cli-background.js.map +1 -0
- package/dist/runtime-cli-install.d.ts +148 -8
- package/dist/runtime-cli-install.js +253 -59
- package/dist/runtime-cli-install.js.map +1 -1
- package/dist/runtime-cli.d.ts +8 -1
- package/dist/runtime-cli.js +206 -44
- package/dist/runtime-cli.js.map +1 -1
- package/dist/runtime-client-store.d.ts +11 -0
- package/dist/runtime-client-store.js +20 -5
- package/dist/runtime-client-store.js.map +1 -1
- package/dist/runtime-client.d.ts +23 -1
- package/dist/runtime-client.js +92 -6
- package/dist/runtime-client.js.map +1 -1
- package/dist/runtime-connection.d.ts +1 -1
- package/dist/runtime-connection.js +1 -1
- package/dist/runtime-connection.js.map +1 -1
- package/dist/runtime-coordinator.d.ts +95 -1
- package/dist/runtime-coordinator.js +344 -10
- package/dist/runtime-coordinator.js.map +1 -1
- package/dist/runtime-enroll-notice.d.ts +4 -0
- package/dist/runtime-enroll-notice.js +21 -0
- package/dist/runtime-enroll-notice.js.map +1 -0
- package/dist/runtime-enrollment.d.ts +21 -0
- package/dist/runtime-enrollment.js +52 -0
- package/dist/runtime-enrollment.js.map +1 -0
- package/dist/runtime-pane-native.js +4 -4
- package/dist/runtime-pane-native.js.map +1 -1
- package/dist/runtime-protocol.d.ts +78 -1
- package/dist/runtime-protocol.js +95 -5
- package/dist/runtime-protocol.js.map +1 -1
- package/dist/runtime-remote-accounts.d.ts +12 -0
- package/dist/runtime-remote-accounts.js +56 -5
- package/dist/runtime-remote-accounts.js.map +1 -1
- package/dist/runtime-remote-setup.d.ts +4 -1
- package/dist/runtime-remote-setup.js +4 -1
- package/dist/runtime-remote-setup.js.map +1 -1
- package/dist/runtime-update-controller.d.ts +11 -0
- package/dist/runtime-update-controller.js +56 -4
- package/dist/runtime-update-controller.js.map +1 -1
- package/dist/settings-api.d.ts +13 -1
- package/dist/settings-api.js +39 -3
- package/dist/settings-api.js.map +1 -1
- package/dist/settings-change.d.ts +5 -13
- package/dist/settings-change.js.map +1 -1
- package/dist/settings-confirmation.d.ts +11 -13
- package/dist/settings-confirmation.js +2 -6
- package/dist/settings-confirmation.js.map +1 -1
- package/dist/settings-effect.d.ts +5 -0
- package/dist/settings-effect.js +76 -10
- package/dist/settings-effect.js.map +1 -1
- package/dist/settings-http-confirmation.d.ts +8 -1
- package/dist/settings-http-confirmation.js +39 -13
- package/dist/settings-http-confirmation.js.map +1 -1
- package/dist/settings-request-capability.d.ts +7 -0
- package/dist/settings-request-capability.js +3 -1
- package/dist/settings-request-capability.js.map +1 -1
- package/dist/setup-i18n.js +4 -4
- package/dist/setup-i18n.js.map +1 -1
- package/dist/subagent-records.d.ts +45 -0
- package/dist/subagent-records.js +214 -0
- package/dist/subagent-records.js.map +1 -0
- package/dist/subagent-service.d.ts +27 -0
- package/dist/subagent-service.js +199 -0
- package/dist/subagent-service.js.map +1 -0
- package/dist/tmux-manager.d.ts +2 -2
- package/dist/tmux-manager.js +5 -3
- package/dist/tmux-manager.js.map +1 -1
- package/dist/ui/account-identity.js +7 -5
- package/dist/ui/accounts-keepalive.js +17 -17
- package/dist/ui/accounts-manage.js +34 -34
- package/dist/ui/accounts-view.js +63 -21
- package/dist/ui/agent-runtime-settings.js +1 -1
- package/dist/ui/backend-signin.js +67 -67
- package/dist/ui/chat-msg-actions.js +50 -4
- package/dist/ui/chat-quote.js +256 -0
- package/dist/ui/chat-store.js +9 -4
- package/dist/ui/cli-caps.js +7 -7
- package/dist/ui/credential-profile-select.js +4 -4
- package/dist/ui/general-location.js +1 -1
- package/dist/ui/host-install.js +290 -0
- package/dist/ui/hub-company-join-strings.js +3 -0
- package/dist/ui/hub-company-join.js +20 -2
- package/dist/ui/hub-owner-strings.js +5 -4
- package/dist/ui/hub-pairing-progress-strings.js +1 -1
- package/dist/ui/hub-quick-strings.js +4 -4
- package/dist/ui/machine-signin.js +4 -4
- package/dist/ui/model-picker.js +68 -0
- package/dist/ui/panel-chat.js +73 -13
- package/dist/ui/panel-fleet.js +1 -1
- package/dist/ui/panel-hub.js +8 -4
- package/dist/ui/panel-needs.js +2 -2
- package/dist/ui/panel-runtimes.js +232 -33
- package/dist/ui/panel-windows-cli.js +1 -1
- package/dist/ui/runtime-cli-install.js +99 -20
- package/dist/ui/runtime-commands.d.ts +2 -0
- package/dist/ui/runtime-commands.js +34 -1
- package/dist/ui/runtime-update-status.js +2 -2
- package/dist/ui/search-dialog.js +1 -0
- package/dist/ui/settings-access-strings.js +1 -1
- package/dist/ui/settings-catalog.js +19 -3
- package/dist/ui/settings-confirm.js +2 -2
- package/dist/ui/settings-devices.js +59 -25
- package/dist/ui/settings-dialogs.js +12 -13
- package/dist/ui/settings-guests.js +1 -1
- package/dist/ui/settings-hub-company-join.js +10 -7
- package/dist/ui/settings-hub-connection.js +121 -0
- package/dist/ui/settings-hub-membership.js +1 -1
- package/dist/ui/settings-hub-run.js +5 -6
- package/dist/ui/settings-hub-section.js +3 -6
- package/dist/ui/settings-hub.js +12 -7
- package/dist/ui/settings-layout.js +6 -6
- package/dist/ui/settings-outside.js +87 -19
- package/dist/ui/settings-registry.js +2 -1
- package/dist/ui/settings-revoke-strings.js +28 -0
- package/dist/ui/settings-strings.js +19 -19
- package/dist/ui/settings-web-authority.js +11 -4
- package/dist/ui/shared/accounts.css +11 -1
- package/dist/ui/shared/agend-auth.js +8 -1
- package/dist/ui/shared/app-i18n.js +10 -12
- package/dist/ui/shared/app-session.js +13 -16
- package/dist/ui/shared/app-shell.js +36 -36
- package/dist/ui/shared/app.css +35 -2
- package/dist/ui/shared/chat-strings.js +4 -4
- package/dist/ui/shared/device-roles.js +27 -0
- package/dist/ui/shared/host-install.css +10 -0
- package/dist/ui/shared/hub-owner.css +6 -0
- package/dist/ui/shared/model-picker.css +21 -0
- package/dist/ui/shared/runtime-install.css +26 -1
- package/dist/ui/shared/setup-host-text.js +4 -4
- package/dist/ui/shared/signin-authenticator.js +60 -0
- package/dist/ui/shared/signin.js +45 -25
- package/dist/ui/shared/subagent-row.css +15 -0
- package/dist/ui/shared/usage-dialog.js +1 -1
- package/dist/ui/shared/view-strings.js +7 -7
- package/dist/ui/shared/web-authorize.js +53 -3
- package/dist/ui/signin-authenticator.html +60 -0
- package/dist/ui/structured-signin.js +30 -30
- package/dist/ui/subagent-row.js +72 -0
- package/dist/ui/web-terminal/terminal.js +9 -9
- package/dist/update-launch.js +4 -1
- package/dist/update-launch.js.map +1 -1
- package/dist/update-npm-env.d.ts +70 -0
- package/dist/update-npm-env.js +128 -0
- package/dist/update-npm-env.js.map +1 -0
- package/dist/usage/providers.js +2 -2
- package/dist/usage/providers.js.map +1 -1
- package/dist/web-api.d.ts +33 -4
- package/dist/web-api.js +312 -18
- package/dist/web-api.js.map +1 -1
- package/dist/web-auth.js +1 -1
- package/dist/web-auth.js.map +1 -1
- package/dist/web-channel-echo.js +3 -1
- package/dist/web-channel-echo.js.map +1 -1
- package/dist/web-commands.d.ts +9 -1
- package/dist/web-commands.js +7 -1
- package/dist/web-commands.js.map +1 -1
- package/dist/web-host-install.d.ts +127 -0
- package/dist/web-host-install.js +165 -0
- package/dist/web-host-install.js.map +1 -0
- package/dist/web-remote-access.d.ts +126 -11
- package/dist/web-remote-access.js +267 -34
- package/dist/web-remote-access.js.map +1 -1
- package/dist/web-session.d.ts +11 -3
- package/dist/web-session.js.map +1 -1
- package/dist/web-signin-device.d.ts +16 -0
- package/dist/web-signin-device.js +81 -0
- package/dist/web-signin-device.js.map +1 -0
- package/dist/web-update.js +3 -1
- package/dist/web-update.js.map +1 -1
- package/dist/windows-cli-api.js +2 -1
- package/dist/windows-cli-api.js.map +1 -1
- package/dist/windows-cli-worker.d.ts +14 -0
- package/dist/windows-cli-worker.js +145 -1
- package/dist/windows-cli-worker.js.map +1 -1
- package/dist/windows-cli.d.ts +4 -0
- package/dist/windows-cli.js +9 -1
- package/dist/windows-cli.js.map +1 -1
- package/launcher/agend-install.cjs +16 -3
- package/package.json +1 -1
- package/templates/runtime-install/install.ps1 +219 -12
package/dist/fleet-manager.js
CHANGED
|
@@ -5,6 +5,7 @@ import { NativePaneRecoveryError } from "./native-pane-recovery.js";
|
|
|
5
5
|
import { nativePaneToolAvailable, nativePaneToolRefusal } from "./native-pane-tools.js";
|
|
6
6
|
import { windowsAgentsFor } from "./windows-agents.js";
|
|
7
7
|
import { AgentRuntimeChanges } from "./agent-runtime-change.js";
|
|
8
|
+
import { SubagentService } from "./subagent-service.js";
|
|
8
9
|
import { QuotaNotices } from "./usage/quota-notices.js";
|
|
9
10
|
import { quotaNoticeRule } from "./quota-notice-config.js";
|
|
10
11
|
import { onUsageSnapshot } from "./usage/usage-api.js";
|
|
@@ -224,6 +225,7 @@ import { RuntimeWindowsBridge } from "./runtime-windows-bridge.js";
|
|
|
224
225
|
import { FleetWindowsRuntime } from "./fleet-windows-runtime.js";
|
|
225
226
|
import { NativeMcpSessions } from "./native-mcp.js";
|
|
226
227
|
import { nativeProviderMcpSupported } from "./windows-cli-providers.js";
|
|
228
|
+
import { cachedNativeModelCatalog } from "./native-model-catalog.js";
|
|
227
229
|
import { isWindowsInstance, isNativePaneInstance, isNativeExecInstance, WINDOWS_CONFIG_REFUSED, nativeCredentialProfile } from "./native-instance-registry.js";
|
|
228
230
|
import { createNativeWindowsInstance, updateNativeWindowsInstance } from "./native-instance-api.js";
|
|
229
231
|
import { NativeInstanceConfigEdit, parseNativeInstanceCreate } from "./native-instance-input.js";
|
|
@@ -281,6 +283,8 @@ import { resolveUpdateLaunch, openUpdateLog, updateLogPath, watchUpdateLaunch }
|
|
|
281
283
|
import { isWebUpdateTarget, readLogTail, RUNNING_AGEND_VERSION, updateOffer, webProgressOf, webUpdateTarget } from "./web-update.js";
|
|
282
284
|
import { admitProfileLogin, LoginController, LOGIN_TOKEN_RESEND_PREFIX, POST_LOGIN_RECOVERY_DEADLINE_MS } from "./login-controller.js";
|
|
283
285
|
import { WebBackendLogins, dashboardSignInSupported } from "./web-backend-login.js";
|
|
286
|
+
import { WebHostInstalls, hostUpdatePlan } from "./web-host-install.js";
|
|
287
|
+
import { cliUpdateView, versionOf } from "./cli-audited.js";
|
|
284
288
|
import { runBeforeDeadline } from "./deadline.js";
|
|
285
289
|
import { LoginWindowLock } from "./login-window-lock.js";
|
|
286
290
|
import { BrowserBackendSignIns } from "./browser-backend-signins.js";
|
|
@@ -334,9 +338,12 @@ import { bypassesWebGate, handleAuthRequest, serveGuestRefusedPage, serveSigninP
|
|
|
334
338
|
import { isWebPageNavigation } from "./web-shell-routes.js";
|
|
335
339
|
import { guestSessionPolicy, localSessionPolicy, sessionVia, tokenEpoch, WebSessionStore } from "./web-session.js";
|
|
336
340
|
import { WebNotices, WEB_NOTICES_FILE } from "./web-notices.js";
|
|
341
|
+
import { enrolledRuntimeNotice } from "./runtime-enroll-notice.js";
|
|
337
342
|
import { DeviceLoginRequests } from "./web-device-login.js";
|
|
338
|
-
import {
|
|
339
|
-
import {
|
|
343
|
+
import { findSigninKnownEntry, addSigninKnownDevice } from "./web-signin-device.js";
|
|
344
|
+
import { adminKey, HOST_ADMIN_KEY, isOutsideLinkOwner, OUTSIDE_LINK_OWNER, OUTSIDE_LINK_RETRY_MS, OUTSIDE_OWN_CLOSES, outsideDuration, outsideTimer, TOTP_SIGNIN_OVER_PUBLIC_LINK, TOTP_STEP_SECONDS, WEB_REMOTE_ACCESS_FILE, WebRemoteAccess } from "./web-remote-access.js";
|
|
345
|
+
import { evaluateSettingsRole } from "./authority/settings-role.js";
|
|
346
|
+
import { authorityNow, evaluateWebAuthority, HOST_OPERATOR, VERIFIED_SESSION_HOURS, webAuthorityPolicy } from "./authority/web-authority.js";
|
|
340
347
|
import { AuthorityStateStore } from "./authority/authority-state.js";
|
|
341
348
|
import { SessionAuthorizations } from "./authority/session-authorizations.js";
|
|
342
349
|
import { SessionAuthorizationRequests } from "./web-session-authorization.js";
|
|
@@ -840,6 +847,123 @@ export class FleetManager {
|
|
|
840
847
|
localPaneRelay = null;
|
|
841
848
|
openingLocalPane = null;
|
|
842
849
|
runtimeHub = null;
|
|
850
|
+
/**
|
|
851
|
+
* A message the owner must get (a computer joined with an install-command token, so nobody approved it). It is written to `pending-owner-notices.json` FIRST and removed only
|
|
852
|
+
* when a delivery is acknowledged: the platform took the message (the send's promise resolved) or the dashboard's Notices recorded it. So none of these loses it: no place to
|
|
853
|
+
* send it yet (a chat-connected fleet with no General and no primary notice target, adapters not up), a send the platform refuses after it was dispatched, a retry that is
|
|
854
|
+
* refused again, a restart. Each kept notice is tried again every minute until it is acknowledged. The file is private. Capacity is explicit, never silent: past
|
|
855
|
+
* OWNER_NOTICE_CAP undelivered notices the oldest are folded into ONE notice that says how many computers joined without a delivered notice and tells the owner to review
|
|
856
|
+
* Settings → Runtime, so the fact is never dropped. Delivery is at least once: a crash between the send and its acknowledgement can send a notice twice.
|
|
857
|
+
*/
|
|
858
|
+
ownerNoticeTimer = null;
|
|
859
|
+
/** One physical send per kept notice at a time: the claim is held until THAT attempt settles (never aged out) and each attempt's callbacks only act on its own claim. */
|
|
860
|
+
ownerNoticeLive = new Set();
|
|
861
|
+
ownerNoticeInFlight = new Map();
|
|
862
|
+
pendingOwnerNoticesFile() { return this.dataDir ? join(this.dataDir, "pending-owner-notices.json") : null; }
|
|
863
|
+
readPendingOwnerNotices() {
|
|
864
|
+
const file = this.pendingOwnerNoticesFile();
|
|
865
|
+
try {
|
|
866
|
+
const value = file && existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : [];
|
|
867
|
+
if (!Array.isArray(value))
|
|
868
|
+
return [];
|
|
869
|
+
const rows = [];
|
|
870
|
+
for (const row of value) {
|
|
871
|
+
if (typeof row === "string" && row.length > 0 && row.length <= 4000)
|
|
872
|
+
rows.push({ id: `legacy-${createHash("sha256").update(row).digest("hex").slice(0, 16)}`, text: row });
|
|
873
|
+
else if (row && typeof row === "object" && typeof row.id === "string" && typeof row.text === "string" && row.text.length > 0 && row.text.length <= 4000) {
|
|
874
|
+
const folded = row.folded;
|
|
875
|
+
rows.push({ id: row.id, text: row.text, ...(Number.isSafeInteger(folded) && folded > 0 ? { folded: folded } : {}) });
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
return rows;
|
|
879
|
+
}
|
|
880
|
+
catch {
|
|
881
|
+
return [];
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
writePendingOwnerNotices(rows) {
|
|
885
|
+
const file = this.pendingOwnerNoticesFile();
|
|
886
|
+
if (!file)
|
|
887
|
+
return;
|
|
888
|
+
try {
|
|
889
|
+
if (rows.length)
|
|
890
|
+
atomicWriteFileSync(file, JSON.stringify(rows), { mode: 0o600 });
|
|
891
|
+
else
|
|
892
|
+
rmSync(file, { force: true });
|
|
893
|
+
}
|
|
894
|
+
catch (error) {
|
|
895
|
+
this.logger.warn({ err: error }, "Could not keep a pending owner notice");
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
static OWNER_NOTICE_CAP = 100;
|
|
899
|
+
/** Past the cap, the oldest are folded into one notice (a count, and where to look); it never silently disappears. */
|
|
900
|
+
foldOwnerNotices(rows) {
|
|
901
|
+
const cap = FleetManager.OWNER_NOTICE_CAP;
|
|
902
|
+
if (rows.length <= cap)
|
|
903
|
+
return rows;
|
|
904
|
+
const old = rows.slice(0, rows.length - (cap - 1)), keep = rows.slice(rows.length - (cap - 1));
|
|
905
|
+
const folded = old.reduce((sum, row) => sum + (row.folded ?? 1), 0);
|
|
906
|
+
this.logger.warn({ folded }, "Too many undelivered owner notices: the oldest were folded into one summary notice");
|
|
907
|
+
for (const row of old)
|
|
908
|
+
this.ownerNoticeInFlight.delete(row.id);
|
|
909
|
+
return [{ id: randomUUID(), text: t("runtime.enroll_folded", String(folded)), folded }, ...keep];
|
|
910
|
+
}
|
|
911
|
+
/** Keeps the notice, then tries to deliver it; it stays on disk until a delivery is acknowledged. */
|
|
912
|
+
deliverOwnerNotice(text) {
|
|
913
|
+
const entry = { id: randomUUID(), text };
|
|
914
|
+
this.writePendingOwnerNotices(this.foldOwnerNotices([...this.readPendingOwnerNotices(), entry]));
|
|
915
|
+
this.attemptOwnerNotice(entry.id, text);
|
|
916
|
+
this.scheduleOwnerNoticeFlush();
|
|
917
|
+
}
|
|
918
|
+
attemptOwnerNotice(id, text) {
|
|
919
|
+
if (this.ownerNoticeInFlight.has(id))
|
|
920
|
+
return; // a send is still waiting for its answer: it keeps the claim until it settles
|
|
921
|
+
const claim = Symbol(id);
|
|
922
|
+
this.ownerNoticeInFlight.set(id, claim);
|
|
923
|
+
let settled = false;
|
|
924
|
+
const finish = (delivered) => {
|
|
925
|
+
if (settled)
|
|
926
|
+
return;
|
|
927
|
+
settled = true;
|
|
928
|
+
if (this.ownerNoticeInFlight.get(id) === claim)
|
|
929
|
+
this.ownerNoticeInFlight.delete(id); // only its own claim: a late answer never retires a successor
|
|
930
|
+
if (delivered)
|
|
931
|
+
this.writePendingOwnerNotices(this.readPendingOwnerNotices().filter(row => row.id !== id));
|
|
932
|
+
};
|
|
933
|
+
let dispatched = false;
|
|
934
|
+
try {
|
|
935
|
+
dispatched = this.notifyFleetError(text, { throttle: false, ack: finish });
|
|
936
|
+
}
|
|
937
|
+
catch {
|
|
938
|
+
dispatched = false;
|
|
939
|
+
}
|
|
940
|
+
if (!dispatched)
|
|
941
|
+
finish(false);
|
|
942
|
+
}
|
|
943
|
+
/** Tries every kept notice that has no attempt in flight (oldest first); returns how many are kept. */
|
|
944
|
+
flushOwnerNotices() {
|
|
945
|
+
for (const row of this.readPendingOwnerNotices())
|
|
946
|
+
this.attemptOwnerNotice(row.id, row.text);
|
|
947
|
+
return this.readPendingOwnerNotices().length;
|
|
948
|
+
}
|
|
949
|
+
scheduleOwnerNoticeFlush(delayMs = 60_000) {
|
|
950
|
+
if (this.ownerNoticeTimer || !this.pendingOwnerNoticesFile())
|
|
951
|
+
return;
|
|
952
|
+
this.ownerNoticeTimer = setTimeout(() => {
|
|
953
|
+
this.ownerNoticeTimer = null;
|
|
954
|
+
let left = 0;
|
|
955
|
+
try {
|
|
956
|
+
left = this.flushOwnerNotices();
|
|
957
|
+
}
|
|
958
|
+
catch (error) {
|
|
959
|
+
this.logger.warn({ err: error }, "Could not deliver a pending owner notice");
|
|
960
|
+
left = 1;
|
|
961
|
+
}
|
|
962
|
+
if (left > 0)
|
|
963
|
+
this.scheduleOwnerNoticeFlush();
|
|
964
|
+
}, delayMs);
|
|
965
|
+
this.ownerNoticeTimer.unref?.();
|
|
966
|
+
}
|
|
843
967
|
runtimeInstall;
|
|
844
968
|
/** One service for the public installer routes and the administrator API: the hash the dashboard shows is the hash of what is sent. */
|
|
845
969
|
runtimeInstaller() { return this.runtimeInstall ??= new RuntimeInstallService(); }
|
|
@@ -850,10 +974,27 @@ export class FleetManager {
|
|
|
850
974
|
runtimeCoordinator() {
|
|
851
975
|
if (!remoteRuntimeEnabled())
|
|
852
976
|
throw new Error("Remote runtimes are not enabled");
|
|
977
|
+
if (!this.runtimeHub && this.readPendingOwnerNotices().length)
|
|
978
|
+
this.scheduleOwnerNoticeFlush(30_000); // a notice kept before a restart is delivered once the fleet is up
|
|
853
979
|
return this.runtimeHub ??= new RuntimeCoordinator(this.dataDir, {
|
|
854
980
|
handleMcp: (machineId, runId, body) => this.runtimeWindowsExecutor().mcp(machineId, runId, body),
|
|
855
981
|
handlePaneMcp: async (machineId, body, current) => (await this.nativePanes()).handle(machineId, body, current),
|
|
856
982
|
warn: (fields, message) => this.logger.warn(fields, message),
|
|
983
|
+
// Issue, use, revocation (and a refused use) of an install-command token: ids and an opaque actor handle only, never the token.
|
|
984
|
+
audit: entry => {
|
|
985
|
+
this.logger[entry.event === "rejected" || entry.event === "throttled" ? "warn" : "info"]({ runtimeEnrollment: entry }, `Runtime install-command token ${entry.event}`);
|
|
986
|
+
// A computer that joined with a token was approved by the token alone: tell the owner out of band (never lets a failure here change the join).
|
|
987
|
+
if (entry.event === "used")
|
|
988
|
+
try {
|
|
989
|
+
const text = enrolledRuntimeNotice(entry, entry.machineId ? this.runtimeHub?.machine(entry.machineId) ?? null : null);
|
|
990
|
+
// Kept first, removed only when a delivery is acknowledged (see deliverOwnerNotice): no destination yet, a refused send and a restart do not lose it.
|
|
991
|
+
if (text)
|
|
992
|
+
this.deliverOwnerNotice(text);
|
|
993
|
+
}
|
|
994
|
+
catch (error) {
|
|
995
|
+
this.logger.warn({ err: error }, "Could not announce a computer that joined with an install-command token");
|
|
996
|
+
}
|
|
997
|
+
},
|
|
857
998
|
changed: event => {
|
|
858
999
|
if (event?.type === "machine")
|
|
859
1000
|
this.needsYou?.poke();
|
|
@@ -1487,6 +1628,19 @@ export class FleetManager {
|
|
|
1487
1628
|
hubMemberPairingApi = null;
|
|
1488
1629
|
hubPairingNotices = null;
|
|
1489
1630
|
hubMemberPairing() { return this.hubMemberPairingApi; }
|
|
1631
|
+
/** Explicit owner Settings read only. A paused binding is not permission to mount or connect a member. */
|
|
1632
|
+
async hubMemberPairingView() {
|
|
1633
|
+
const raw = this.rawFleetConfig;
|
|
1634
|
+
if (this.shuttingDown)
|
|
1635
|
+
throw Error("Fleet is stopping");
|
|
1636
|
+
if (hubMembershipSettings(raw).enabled && this.hubMemberPairingApi)
|
|
1637
|
+
return this.hubMemberPairingApi.view();
|
|
1638
|
+
const { createHubMemberPairingApi } = await import("./hub/member/pairing-api.js");
|
|
1639
|
+
if (this.shuttingDown || this.rawFleetConfig !== raw)
|
|
1640
|
+
throw Error("Hub membership changed");
|
|
1641
|
+
// This factory schedules nothing; only its private-file projection is called. No write method escapes.
|
|
1642
|
+
return createHubMemberPairingApi({ home: this.dataDir, enabled: () => false }).view();
|
|
1643
|
+
}
|
|
1490
1644
|
attachHubMemberPairing(api) { this.hubMemberPairingApi = api; }
|
|
1491
1645
|
generalLocationFlights = new Map();
|
|
1492
1646
|
generalAttentionEpisodes = new Map();
|
|
@@ -3374,14 +3528,17 @@ export class FleetManager {
|
|
|
3374
3528
|
if (auth.kind !== "ok" || !current())
|
|
3375
3529
|
return null;
|
|
3376
3530
|
const record = auth.session, sessions = this.webSessions, exposure = gatewayRequestContext(req);
|
|
3377
|
-
return { localSession: this.hubCompanySession(req) ?? undefined, id: record.idHash, label: record.label, source: exposure ? "public_link" : "web_session",
|
|
3531
|
+
return { requester: { handle: record.handle, label: record.label }, localSession: this.hubCompanySession(req) ?? undefined, id: record.idHash, label: record.label, source: exposure ? "public_link" : "web_session",
|
|
3378
3532
|
localAdmin: () => record.tier === "admin" && record.surface === "local" && !exposure,
|
|
3379
3533
|
current: () => current() && sessions === this.webSessions && !!this.webToken
|
|
3380
3534
|
&& sessions.isCurrent(record, tokenEpoch(this.webToken)) && (!exposure || exposure.isCurrent()) };
|
|
3381
3535
|
}, baseline: () => baselines.read(), snapshot: () => baselines.snapshot(),
|
|
3382
3536
|
selfConfirm: (req, id) => this.settingsSelfConfirmation(store, req, id),
|
|
3383
3537
|
totp: { state: (req, id) => this.settingsTotpState(store, req, id), confirm: (req, id, code, digest) => this.settingsTotpConfirm(store, req, id, code, digest) },
|
|
3538
|
+
remote: req => this.settingsPageIsRemote(req),
|
|
3539
|
+
directCreationPolicy: req => this.settingsDirectCreationAllowed(req),
|
|
3384
3540
|
directAgentCreation: true,
|
|
3541
|
+
directHostInstall: true,
|
|
3385
3542
|
directCompanyJoin: true,
|
|
3386
3543
|
job: async (id) => {
|
|
3387
3544
|
const settlement = this.settingsJobSettlements.get(id);
|
|
@@ -3398,199 +3555,308 @@ export class FleetManager {
|
|
|
3398
3555
|
return gate;
|
|
3399
3556
|
}
|
|
3400
3557
|
/**
|
|
3401
|
-
* #
|
|
3402
|
-
*
|
|
3403
|
-
*
|
|
3404
|
-
*
|
|
3405
|
-
*
|
|
3406
|
-
* -
|
|
3407
|
-
*
|
|
3408
|
-
* -
|
|
3409
|
-
*
|
|
3410
|
-
*
|
|
3411
|
-
*
|
|
3412
|
-
*
|
|
3413
|
-
* in, its cookie) confirms the same way. A public link never qualifies (evaluateWebAuthority refuses it). General
|
|
3414
|
-
* still hears it: a notice, not a step.
|
|
3558
|
+
* AGEND-122 (upstream #3486, R1): a held change confirmed by the request itself — by the role of whoever asks, not by a
|
|
3559
|
+
* proof given once per browser. A signed-in human fleet admin on a web cookie session may press Apply now from wherever
|
|
3560
|
+
* the dashboard is reached (this computer, a LAN or tailnet name, a link), for every kind of change, on a chat fleet and
|
|
3561
|
+
* on a web-only one alike. settings-role.ts has the checks, asked of the live session now and again at execution:
|
|
3562
|
+
* - a cookie session of an admin (a guest, a read-only session, a header token, the CLI and an agent's request never);
|
|
3563
|
+
* - the owner's own knobs: the web authorization switch, "Only this computer can authorize", and the link option of a
|
|
3564
|
+
* link the session arrived over;
|
|
3565
|
+
* - a chat account is still an admin of its connection, and of every connection the change touches (the scope the
|
|
3566
|
+
* store holds; when that is not known, its own connection's admin list is all there is to ask).
|
|
3567
|
+
* It no longer asks that a chat card could have been posted, that the account confirmed this browser in a DM (#1939),
|
|
3568
|
+
* or that the host's own session confirms: those were what sent a remote admin to the AgEnD computer. The chat card
|
|
3569
|
+
* stays another way to confirm; General is told of a change a chat account confirmed here, when one can be.
|
|
3415
3570
|
*/
|
|
3416
3571
|
settingsSelfConfirmation(store, req, id) {
|
|
3417
|
-
const
|
|
3418
|
-
if (
|
|
3572
|
+
const first = this.settingsRole(req);
|
|
3573
|
+
if (!first.role.ok || !first.handle)
|
|
3419
3574
|
return null;
|
|
3420
|
-
|
|
3421
|
-
//
|
|
3422
|
-
//
|
|
3423
|
-
|
|
3424
|
-
// (A web-only fleet's host operator has its own rule below, with its revocable authorization.) The noSelfConfirm changes
|
|
3425
|
-
// the leader ruled on are included: the outward Hub changes (hostLocalConfirm) and a link option turned on
|
|
3426
|
-
// (hostSessionOnly, cid-d3) — this session is exactly the one those allow.
|
|
3427
|
-
// "No card": none could be posted now, or the one tried could not be (posting failed or ran out — the view says
|
|
3428
|
-
// host_cli; #3362 review N1).
|
|
3429
|
-
const noCard = () => !this.settingsCardPossible(store, id) || store.inspect(id)?.confirmation.kind === "host_cli";
|
|
3430
|
-
if (!this.isWebOnlyFleet() && hostSessionHere(auth.session, req) && noCard()
|
|
3431
|
-
&& (store.selfConfirmable(id) || store.hostLocalConfirmable(id) || store.hostSessionConfirmable(id))) {
|
|
3432
|
-
// A card that could not be posted stays unposted (no card is attached later): fixed now, not re-read at execution,
|
|
3433
|
-
// where the store has already marked the change as confirmed from the web.
|
|
3434
|
-
const handle = auth.session.handle, postFailed = store.inspect(id)?.confirmation.kind === "host_cli";
|
|
3435
|
-
const here = () => {
|
|
3436
|
-
const now = authorizeSession(req, this.webToken, this.webSessions, { touch: false });
|
|
3437
|
-
return now.kind === "ok" && now.session.handle === handle && hostSessionHere(now.session, req) && !this.isWebOnlyFleet();
|
|
3438
|
-
};
|
|
3439
|
-
return {
|
|
3440
|
-
label: t("settings_confirm.host_operator_label"),
|
|
3441
|
-
current: () => here() && (postFailed || !this.settingsCardPossible(store, id)),
|
|
3442
|
-
done: view => { this.logger.info({ id: view.id, state: view.state }, "Settings change confirmed from the web by this computer's admin (no General could take it)"); },
|
|
3443
|
-
};
|
|
3444
|
-
}
|
|
3445
|
-
// #2453 (§0.2): never over the public link — not even a named-link session that is web-verified there. #3008: except
|
|
3446
|
-
// this computer's admin signed in from outside (the authenticator's code, over the link connections from outside
|
|
3447
|
-
// opened): the web-only fleet's owner, judged below by the same authority as here (hostOperator).
|
|
3448
|
-
if (gatewayRequestContext(req) && auth.session.remote !== "totp")
|
|
3575
|
+
const handle = first.handle, actor = first.role.actor, account = first.role.account;
|
|
3576
|
+
// This admin's own stricter switch: off this computer, each of THEIR confirmations takes their authenticator's code instead
|
|
3577
|
+
// (settingsCodeSession) — never Apply now, whatever the session is (a link's, the owner signed in from outside, a LAN's).
|
|
3578
|
+
if (this.strictFor(first.role.actor) && !first.role.onHost)
|
|
3449
3579
|
return null;
|
|
3450
|
-
|
|
3451
|
-
// ruling on #3352 F1; threat model A 64a289a0): the outward Hub changes (hostLocalConfirm) are the one exception — for
|
|
3452
|
-
// the host operator's own local session only (below).
|
|
3453
|
-
if (!store.selfConfirmable(id) && !store.hostLocalConfirmable(id) && !store.hostSessionConfirmable(id))
|
|
3580
|
+
if (account && !this.settingsAccountMayConfirm(store, id, actor))
|
|
3454
3581
|
return null;
|
|
3455
|
-
|
|
3456
|
-
const
|
|
3457
|
-
const now = this.
|
|
3458
|
-
|
|
3459
|
-
|
|
3582
|
+
// Asked again at execution, from the same request's cookie: still this session, still this role, still an admin.
|
|
3583
|
+
const current = () => {
|
|
3584
|
+
const now = this.settingsRole(req);
|
|
3585
|
+
return now.role.ok && now.handle === handle && now.role.actor.user_id === actor.user_id && now.role.actor.adapter_id === actor.adapter_id
|
|
3586
|
+
&& (!now.role.account || this.settingsAccountMayConfirm(store, id, actor));
|
|
3460
3587
|
};
|
|
3461
|
-
const
|
|
3462
|
-
if (!
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
// link option turned on (hostSessionOnly — the outside sign-in, a gateway, never may).
|
|
3471
|
-
const hostLocal = () => hostSessionHere(record, req);
|
|
3472
|
-
if (hostOperator(actor) && (store.selfConfirmable(id) || hostLocal())) {
|
|
3473
|
-
return {
|
|
3474
|
-
label: t("settings_confirm.host_operator_label"),
|
|
3475
|
-
current: () => hostOperator(verified()) && (store.selfConfirmable(id) || hostLocal()),
|
|
3476
|
-
done: view => { this.logger.info({ id: view.id, state: view.state }, "Settings change confirmed from the web by this computer's admin"); },
|
|
3477
|
-
};
|
|
3588
|
+
const notice = this.settingsRemoteNoticeKind(store, id, first.role.onHost);
|
|
3589
|
+
if (!account) {
|
|
3590
|
+
const who = t("settings_confirm.host_operator_label");
|
|
3591
|
+
return { label: who, current,
|
|
3592
|
+
done: view => {
|
|
3593
|
+
this.logger.info({ id: view.id, state: view.state }, "Settings change confirmed from the web by this fleet's admin");
|
|
3594
|
+
if (notice)
|
|
3595
|
+
this.postSettingsRemoteNotice(view, notice, who);
|
|
3596
|
+
} };
|
|
3478
3597
|
}
|
|
3479
|
-
|
|
3480
|
-
|
|
3598
|
+
const name = this.webPerson({ adapterId: actor.adapter_id, userId: actor.user_id }).name;
|
|
3599
|
+
// General hears of it when a chat card could have been posted (the old rule's own scope); it is a notice, not a step.
|
|
3481
3600
|
const chat = this.settingsChatAuthority(store, id);
|
|
3482
|
-
if (!chat)
|
|
3483
|
-
return null;
|
|
3484
|
-
const channels = this.fleetConfig?.channels ?? (this.fleetConfig?.channel ? [this.fleetConfig.channel] : []);
|
|
3485
|
-
const own = channels.filter(ch => (ch.id ?? ch.type) === actor.adapter_id);
|
|
3486
|
-
if (own.length !== 1 || own[0].type !== chat.platform || !chat.admin(actor.user_id))
|
|
3487
|
-
return null;
|
|
3488
3601
|
const affected = [...store.affectedConnections(id)]; // read now: a finished change no longer has them
|
|
3489
|
-
const destinations = this.settingsNoticeGenerals(affected, chat.platform);
|
|
3490
|
-
if (!destinations.length)
|
|
3491
|
-
return null;
|
|
3492
|
-
const name = this.webPerson({ adapterId: actor.adapter_id, userId: actor.user_id }).name;
|
|
3602
|
+
const destinations = chat ? this.settingsNoticeGenerals(affected, chat.platform) : [];
|
|
3493
3603
|
return {
|
|
3494
3604
|
label: t("settings_confirm.web_verified_label", name),
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3605
|
+
current,
|
|
3606
|
+
...(destinations.length ? { followStop: async (stopped, begin) => {
|
|
3607
|
+
const route = destinations.find(item => item.current());
|
|
3608
|
+
if (!route)
|
|
3609
|
+
throw Error("Settings route expired");
|
|
3610
|
+
await route.followStop(stopped, begin);
|
|
3611
|
+
} } : {}),
|
|
3612
|
+
done: view => {
|
|
3613
|
+
if (notice) {
|
|
3614
|
+
this.postSettingsRemoteNotice(view, notice, name);
|
|
3615
|
+
return;
|
|
3616
|
+
} // that Notice says it already, to General or the web
|
|
3617
|
+
if (chat && destinations.length)
|
|
3618
|
+
return this.settingsWebConfirmedNotice(view, affected, name, chat.platform);
|
|
3619
|
+
},
|
|
3500
3620
|
};
|
|
3501
3621
|
}
|
|
3502
3622
|
/**
|
|
3503
|
-
*
|
|
3504
|
-
*
|
|
3505
|
-
*
|
|
3506
|
-
*
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
//
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
//
|
|
3517
|
-
|
|
3518
|
-
|
|
3623
|
+
* AGEND-122 (Prism P2): whether the ordinary New Agent shortcut — created at once, web-confirmed, with no held change — is open to
|
|
3624
|
+
* this request. It is the same policy as Apply now: refused where "Only this computer can authorize" is on and this is not the
|
|
3625
|
+
* AgEnD computer, and off the computer for an admin whose own "ask for my code" switch is on (the creation then waits as a held
|
|
3626
|
+
* change and takes their code). Everything else is as before the role existed.
|
|
3627
|
+
*/
|
|
3628
|
+
settingsDirectCreationAllowed(req) {
|
|
3629
|
+
// Admin eligibility is asked with the web authorization switch taken OUT of the question (`ignoreSwitch`): that switch governs
|
|
3630
|
+
// what a web message carries to an agent and has never stopped a local admin creating one, but it must not stand in for the
|
|
3631
|
+
// other checks — an admin tier session, the token epoch, "Only this computer can authorize", and a chat account that is
|
|
3632
|
+
// still an admin of its connection (or the host's / a web-only fleet's own admin). A refused role is not permission.
|
|
3633
|
+
const { role } = this.settingsRole(req, { ignoreSwitch: true });
|
|
3634
|
+
if (!role.ok)
|
|
3635
|
+
return false;
|
|
3636
|
+
// Switch off: no Apply now exists, so nothing is asked of an admin's own "ask for my code" switch either (the legacy path).
|
|
3637
|
+
if (!this.webAuthorityState().enabled)
|
|
3638
|
+
return true;
|
|
3639
|
+
return role.onHost || !this.strictFor(role.actor);
|
|
3640
|
+
}
|
|
3641
|
+
/** AGEND-122: this request's role over a held change — its cookie session asked afresh each time (settings-role.ts). */
|
|
3642
|
+
settingsRole(req, opts = {}) {
|
|
3643
|
+
const auth = authorizeSession(req, this.webToken, this.webSessions, { touch: false });
|
|
3644
|
+
if (auth.kind !== "ok")
|
|
3645
|
+
return { role: { ok: false, reason: "not_session" }, handle: null };
|
|
3646
|
+
const state = this.webAuthorityState();
|
|
3647
|
+
const role = evaluateSettingsRole({
|
|
3648
|
+
session: auth.session, gateway: !!gatewayRequestContext(req), peer: webPeerOf(req),
|
|
3649
|
+
tokenEpoch: this.webToken ? tokenEpoch(this.webToken) : null, webOnly: this.isWebOnlyFleet(),
|
|
3650
|
+
policy: { enabled: state.enabled || opts.ignoreSwitch === true, loopbackOnly: state.loopbackOnly, namedLink: state.namedLink, quickLink: state.quickLink },
|
|
3651
|
+
isAdmin: (userId, adapterId) => this.adminGate(userId, adapterId) === "ok", outside: this.outsideLink(),
|
|
3652
|
+
});
|
|
3653
|
+
return { role, handle: auth.session.handle };
|
|
3654
|
+
}
|
|
3655
|
+
/**
|
|
3656
|
+
* AGEND-122 (upstream R1): a change that opens a link, or one that changes a secret, confirmed from another device always
|
|
3657
|
+
* posts a Notice — the audit trail alone is not what the owner sees. Null: not one of those, or confirmed on this computer.
|
|
3658
|
+
*/
|
|
3659
|
+
settingsRemoteNoticeKind(store, id, onHost) {
|
|
3660
|
+
if (onHost)
|
|
3661
|
+
return null;
|
|
3662
|
+
if (store.opensLink(id))
|
|
3663
|
+
return "link";
|
|
3664
|
+
return store.inspect(id)?.section === "secret" ? "secret" : null;
|
|
3665
|
+
}
|
|
3666
|
+
/**
|
|
3667
|
+
* Where that Notice goes: a web-only fleet's dashboard Notices; a chat fleet's General, else its primary connection's notice
|
|
3668
|
+
* target (notifyFleetError) — and when nothing could be posted there, the web Notices, which a chat fleet's dashboard then
|
|
3669
|
+
* shows. Never throttled, and never silent. It names the change as the card showed it (redacted), who confirmed and how.
|
|
3670
|
+
*/
|
|
3671
|
+
postSettingsRemoteNotice(view, kind, who) {
|
|
3672
|
+
const outcome = view.outcome ? view.outcome.message : view.state;
|
|
3673
|
+
const text = t("settings_confirm.remote_notice", who, t(`settings_confirm.remote_kind_${kind}`), view.summary.join("\n"), outcome);
|
|
3674
|
+
this.postFleetSecurityNotice(text, view.id);
|
|
3675
|
+
}
|
|
3676
|
+
/**
|
|
3677
|
+
* A security Notice that must not be silent: where a fleet notice goes (General, else the primary connection's notice target,
|
|
3678
|
+
* else a web-only fleet's dashboard Notices) and, when nothing could be posted there, the web Notices store directly — which a
|
|
3679
|
+
* chat fleet's dashboard then shows (recordWebNotice itself refuses a chat fleet). Never throttled; redacted like any Notice.
|
|
3680
|
+
*/
|
|
3681
|
+
postFleetSecurityNotice(text, id) {
|
|
3682
|
+
// The usual fleet notice (General, else the primary connection's notice target; a web-only fleet's dashboard Notices) ...
|
|
3683
|
+
let sent = false;
|
|
3684
|
+
try {
|
|
3685
|
+
sent = this.notifyFleetError(text, { throttle: false });
|
|
3686
|
+
}
|
|
3687
|
+
catch (err) {
|
|
3688
|
+
this.logger.warn({ err, id }, "A security Notice could not be sent to the primary General");
|
|
3689
|
+
}
|
|
3690
|
+
if (this.isWebOnlyFleet()) {
|
|
3691
|
+
if (sent)
|
|
3692
|
+
return;
|
|
3693
|
+
}
|
|
3694
|
+
else {
|
|
3695
|
+
// ... and every OTHER connection's General too: their admin lists can be disjoint, so the primary one is not everyone.
|
|
3696
|
+
const generals = Object.entries(this.fleetConfig?.instances ?? {}).filter(([, cfg]) => cfg.general_topic === true).map(([name]) => name);
|
|
3697
|
+
for (const name of generals.slice(1)) {
|
|
3698
|
+
try {
|
|
3699
|
+
this.notifyInstanceTopic(name, text);
|
|
3700
|
+
}
|
|
3701
|
+
catch (err) {
|
|
3702
|
+
this.logger.warn({ err, id }, "A security Notice could not be sent to one General");
|
|
3703
|
+
}
|
|
3704
|
+
}
|
|
3705
|
+
}
|
|
3706
|
+
// And on a chat fleet always the shared web Notices — persisted, shown to every admin of the dashboard: a chat send reports a
|
|
3707
|
+
// dispatch, not a delivery, and may fail afterwards or never reach an admin of another connection.
|
|
3708
|
+
const store = this.webNoticeStore(), note = store?.add({ kind: "fleet", text: stripPlaceRefs(text) });
|
|
3709
|
+
if (note && store)
|
|
3710
|
+
this.emitSseEvent("notice", { notice: note, unread: store.unread() });
|
|
3711
|
+
else
|
|
3712
|
+
this.logger.warn({ id }, "A security Notice could not be announced on the dashboard");
|
|
3713
|
+
}
|
|
3714
|
+
/** Who an authenticator action is named after in its Notice. */
|
|
3715
|
+
adminName(actor) {
|
|
3716
|
+
return actor.adapter_id === HOST_OPERATOR.adapterId && actor.user_id === HOST_OPERATOR.userId
|
|
3717
|
+
? t("settings_confirm.host_operator_label") : this.webPerson({ adapterId: actor.adapter_id, userId: actor.user_id }).name;
|
|
3718
|
+
}
|
|
3719
|
+
/**
|
|
3720
|
+
* AGEND-122: a chat account confirms a change only as an admin of every connection it touches — settingsChatAuthority's own
|
|
3721
|
+
* rule, without needing a General to post to: the scope the store holds (a scope not known: none, fail closed), and, for a
|
|
3722
|
+
* change with `primaryGeneral` (the Hub, the connection list and order, whole-fleet sensitive settings), the connection that owns
|
|
3723
|
+
* the primary General too. Every connection involved, the account's own included, is configured exactly once and on one platform
|
|
3724
|
+
* (user ids are per platform). Asked at entry and again by `current()`.
|
|
3725
|
+
*/
|
|
3726
|
+
settingsAccountMayConfirm(store, id, actor) {
|
|
3727
|
+
const scope = store.authorityOf(id);
|
|
3728
|
+
if (!scope || scope.unknown || !actor.user_id)
|
|
3729
|
+
return false;
|
|
3730
|
+
const targets = new Set(scope.connections);
|
|
3731
|
+
if (scope.primaryGeneral) {
|
|
3732
|
+
const primary = this.settingsPrimaryGeneral();
|
|
3733
|
+
if (!primary)
|
|
3734
|
+
return false;
|
|
3735
|
+
targets.add(primary.owner);
|
|
3736
|
+
}
|
|
3737
|
+
const channels = this.fleetConfig?.channels ?? (this.fleetConfig?.channel ? [this.fleetConfig.channel] : []);
|
|
3738
|
+
const configured = (connection) => channels.filter(ch => (ch.id ?? ch.type) === connection);
|
|
3739
|
+
if ([actor.adapter_id, ...targets].some(connection => configured(connection).length !== 1))
|
|
3740
|
+
return false;
|
|
3741
|
+
const platform = configured(actor.adapter_id)[0].type;
|
|
3742
|
+
return [...targets].every(connection => configured(connection)[0].type === platform && this.isFleetAdmin(actor.user_id, connection));
|
|
3743
|
+
}
|
|
3744
|
+
/**
|
|
3745
|
+
* AGEND-122 (upstream #3486, per admin): each admin's own stricter switch — off by default, kept with their own authenticator
|
|
3746
|
+
* (web-remote-access.ts) and never in fleet.yaml. While it is on, THEIR confirmations from a page that is not the browser on the
|
|
3747
|
+
* AgEnD computer itself do not press Apply now: each takes the code of their own app, bound to that one change
|
|
3748
|
+
* (settingsTotpConfirm). Another admin is never asked, and cannot turn it on or off for them. The computer's own browser is not
|
|
3749
|
+
* asked. The switch lives in the app's record, so it can only be on while the app is set up.
|
|
3750
|
+
*/
|
|
3751
|
+
strictFor(actor) {
|
|
3752
|
+
return !!this.webRemoteAccess()?.strictOf(adminKey(actor.adapter_id, actor.user_id));
|
|
3753
|
+
}
|
|
3754
|
+
/**
|
|
3755
|
+
* Who is asked for the code: a session with a role over a held change (settings-role.ts) that is not on this computer,
|
|
3756
|
+
* while the option is on. The role carries every check Apply now has — the web authorization switch, "Only this computer
|
|
3757
|
+
* can authorize" (Q6), the link options, a chat account still an admin of the connections the change touches — asked at
|
|
3758
|
+
* entry and again by `current()` at execution, so a demoted admin's pending change never runs. One refusal on top: a change
|
|
3759
|
+
* that opens a link is never confirmed over a link (the public gateway, bound by the gateway itself, never by a header), the
|
|
3760
|
+
* code or not. The code is the authority; the session only carries it.
|
|
3761
|
+
*/
|
|
3762
|
+
settingsCodeSession(store, req, id) {
|
|
3763
|
+
const check = (asking) => {
|
|
3764
|
+
const { role, handle } = this.settingsRole(req);
|
|
3765
|
+
if (!role.ok || !handle || role.onHost)
|
|
3519
3766
|
return null;
|
|
3520
|
-
|
|
3521
|
-
if (auth.kind !== "ok")
|
|
3767
|
+
if (asking && !this.strictFor(role.actor))
|
|
3522
3768
|
return null;
|
|
3523
|
-
|
|
3524
|
-
if (s.tier !== "admin" || s.owner)
|
|
3769
|
+
if (role.account && !this.settingsAccountMayConfirm(store, id, role.actor))
|
|
3525
3770
|
return null;
|
|
3526
|
-
if (
|
|
3771
|
+
if (store.opensLink(id) && gatewayRequestContext(req))
|
|
3527
3772
|
return null;
|
|
3528
|
-
|
|
3529
|
-
return s.surface === "local" && (peer === "loopback" || peer === "lan") ? { handle: s.handle } : null;
|
|
3773
|
+
return { handle, actor: role.actor, account: role.account };
|
|
3530
3774
|
};
|
|
3531
|
-
const first =
|
|
3775
|
+
const first = check(true);
|
|
3532
3776
|
if (!first)
|
|
3533
3777
|
return null;
|
|
3534
|
-
|
|
3778
|
+
// Asked again at execution: the same session and account, the same role (an option turned off since stays what was confirmed).
|
|
3779
|
+
return { ...first, current: () => { const now = check(false); return !!now && now.handle === first.handle && now.actor.user_id === first.actor.user_id && now.actor.adapter_id === first.actor.adapter_id; } };
|
|
3780
|
+
}
|
|
3781
|
+
/** One look at a code, for every place that asks for one: the fleet-wide wrong-code limit and a clock that looks off, logged and noticed the same way. */
|
|
3782
|
+
checkAuthenticatorCode(access, who, code, what) {
|
|
3783
|
+
const enrollment = access.enrollmentOf(who);
|
|
3784
|
+
const v = access.verify(code, who);
|
|
3785
|
+
if (v.kind === "ok")
|
|
3786
|
+
return enrollment ? { ok: true, enrollment } : { ok: false, error: "not_here" };
|
|
3787
|
+
if (v.kind === "paused")
|
|
3788
|
+
return { ok: false, error: "paused", retryAfterMs: v.retryAfterMs };
|
|
3789
|
+
if (v.kind === "not_enrolled")
|
|
3790
|
+
return { ok: false, error: "not_here" };
|
|
3791
|
+
if (v.kind === "unavailable")
|
|
3792
|
+
return { ok: false, error: "unavailable" };
|
|
3793
|
+
if (v.skewSteps !== null)
|
|
3794
|
+
this.logger.warn({ offsetSeconds: v.skewSteps * TOTP_STEP_SECONDS }, "A wrong authenticator code matched a nearby time step: this computer's clock may be off");
|
|
3795
|
+
this.logger.info({ what }, "A wrong authenticator code was refused");
|
|
3796
|
+
if (v.paused) {
|
|
3797
|
+
this.logger.warn({ waitMs: v.retryAfterMs }, "Authenticator codes paused after wrong codes");
|
|
3798
|
+
this.recordWebNotice("fleet", t("outside.notice_paused", outsideDuration(v.retryAfterMs), v.wrong));
|
|
3799
|
+
return { ok: false, error: "paused", retryAfterMs: v.retryAfterMs };
|
|
3800
|
+
}
|
|
3801
|
+
return { ok: false, error: "wrong" };
|
|
3802
|
+
}
|
|
3803
|
+
/**
|
|
3804
|
+
* AGEND-122: a page that is not the browser on the AgEnD computer itself — a LAN or tailnet connection (a Host that is
|
|
3805
|
+
* not loopback, a forwarding header, a peer that is not this machine) or a link. Said to the card so it names no host
|
|
3806
|
+
* command and no "go to that computer" step the reader cannot take; asked per request and never a check: what a page may
|
|
3807
|
+
* confirm is still settingsSelfConfirmation / settingsCodeSession, and the card's wording is all this changes.
|
|
3808
|
+
*/
|
|
3809
|
+
settingsPageIsRemote(req) {
|
|
3810
|
+
return webPeerOf(req) !== "loopback";
|
|
3535
3811
|
}
|
|
3536
3812
|
settingsTotpState(store, req, id) {
|
|
3537
|
-
|
|
3538
|
-
//
|
|
3539
|
-
if (
|
|
3540
|
-
return
|
|
3541
|
-
|
|
3813
|
+
const { role } = this.settingsRole(req);
|
|
3814
|
+
// The owner turned on "Only this computer can authorize": a page that is not on this computer is told so, in plain words.
|
|
3815
|
+
if (!role.ok)
|
|
3816
|
+
return role.reason === "loopback_only" ? "host_only" : null;
|
|
3817
|
+
// Apply now is open to it (the option is off, or this is the AgEnD computer's own browser): no code is asked.
|
|
3818
|
+
if (!this.strictFor(role.actor) || role.onHost)
|
|
3542
3819
|
return null;
|
|
3543
|
-
|
|
3544
|
-
if (gatewayRequestContext(req))
|
|
3545
|
-
return this.isWebOnlyFleet() && !this.settingsSelfConfirmation(store, req, id) ? "on_host" : null;
|
|
3546
|
-
if (!this.settingsTotpSession(req))
|
|
3820
|
+
if (role.account && !this.settingsAccountMayConfirm(store, id, role.actor))
|
|
3547
3821
|
return null;
|
|
3548
|
-
if (
|
|
3549
|
-
return
|
|
3550
|
-
return this.webRemoteAccess()?.
|
|
3822
|
+
if (store.opensLink(id) && gatewayRequestContext(req))
|
|
3823
|
+
return "on_host";
|
|
3824
|
+
return this.webRemoteAccess()?.isEnrolled(adminKey(role.actor.adapter_id, role.actor.user_id)) ? "ready" : "not_set_up";
|
|
3551
3825
|
}
|
|
3826
|
+
/**
|
|
3827
|
+
* The code, checked: the change's digest first (a stale page never burns a code), then one use per time step and the
|
|
3828
|
+
* fleet-wide wrong-code limit (web-remote-access.ts), then a confirmation asked again at execution (`current`) — the same
|
|
3829
|
+
* session and role, the same enrolment (an app replaced, or removed and set up again, while the change waits ends it for good).
|
|
3830
|
+
*/
|
|
3552
3831
|
settingsTotpConfirm(store, req, id, code, digest) {
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
const
|
|
3556
|
-
if (!local || !local.current() || !access?.
|
|
3832
|
+
const local = this.settingsCodeSession(store, req, id), access = this.webRemoteAccess();
|
|
3833
|
+
// The code checked is the CONFIRMING admin's own: their record, never another admin's or the fleet's.
|
|
3834
|
+
const mine = local ? adminKey(local.actor.adapter_id, local.actor.user_id) : "";
|
|
3835
|
+
if (!local || !local.current() || !access?.isEnrolled(mine))
|
|
3557
3836
|
return { error: "not_here" };
|
|
3558
3837
|
// #3352 security review, point 2: the code confirms exactly the change the page showed — checked before the code is.
|
|
3559
3838
|
if (digest !== store.confirmDigest(id))
|
|
3560
3839
|
return { error: "changed" };
|
|
3561
3840
|
const shown = store.inspectHost(id)?.view.summary ?? [];
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
const
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
if (v.kind === "not_enrolled")
|
|
3582
|
-
return { error: "not_here" };
|
|
3583
|
-
if (v.kind === "unavailable")
|
|
3584
|
-
return { error: "unavailable" };
|
|
3585
|
-
if (v.skewSteps !== null)
|
|
3586
|
-
this.logger.warn({ offsetSeconds: v.skewSteps * TOTP_STEP_SECONDS }, "A wrong authenticator code matched a nearby time step: this computer's clock may be off");
|
|
3587
|
-
this.logger.info({ id, handle: local.handle }, "Settings change: a wrong authenticator code was refused");
|
|
3588
|
-
if (v.paused) {
|
|
3589
|
-
this.logger.warn({ waitMs: v.retryAfterMs }, "Authenticator codes paused after wrong codes");
|
|
3590
|
-
this.recordWebNotice("fleet", t("outside.notice_paused", outsideDuration(v.retryAfterMs), v.wrong));
|
|
3591
|
-
return { error: "paused", retryAfterMs: v.retryAfterMs };
|
|
3592
|
-
}
|
|
3593
|
-
return { error: "wrong" };
|
|
3841
|
+
const checked = this.checkAuthenticatorCode(access, mine, code, "settings change");
|
|
3842
|
+
if (!checked.ok)
|
|
3843
|
+
return { error: checked.error, ...(checked.retryAfterMs !== undefined ? { retryAfterMs: checked.retryAfterMs } : {}) };
|
|
3844
|
+
const enrollment = checked.enrollment;
|
|
3845
|
+
this.logger.info({ id, handle: local.handle }, "Settings change confirmed with the authenticator code");
|
|
3846
|
+
const notice = this.settingsRemoteNoticeKind(store, id, false); // the code is asked off this computer only
|
|
3847
|
+
const who = `${this.adminName(local.actor)} · ${t("settings_confirm.totp_label")}`;
|
|
3848
|
+
let lost = false;
|
|
3849
|
+
const current = () => {
|
|
3850
|
+
if (!lost && !(local.current() && this.webRemoteAccess()?.enrollmentOf(mine) === enrollment))
|
|
3851
|
+
lost = true;
|
|
3852
|
+
return !lost;
|
|
3853
|
+
};
|
|
3854
|
+
return { label: t("settings_confirm.totp_label"), current, audit: { confirmed_with: "authenticator_code", summary: shown },
|
|
3855
|
+
done: view => {
|
|
3856
|
+
this.logger.info({ id: view.id, state: view.state }, "Settings change confirmed with the authenticator code: done");
|
|
3857
|
+
if (notice)
|
|
3858
|
+
this.postSettingsRemoteNotice(view, notice, who);
|
|
3859
|
+
} };
|
|
3594
3860
|
}
|
|
3595
3861
|
/**
|
|
3596
3862
|
* alpha.2 (M-2300; #2973's agent requests, junsion's §6): on a fleet with no chat connection there is no General to
|
|
@@ -3637,72 +3903,123 @@ export class FleetManager {
|
|
|
3637
3903
|
return this.fleetConfig?.web?.login_qr === true;
|
|
3638
3904
|
}
|
|
3639
3905
|
/**
|
|
3640
|
-
* GET /ui/devices: is this a web-only fleet, may THIS session
|
|
3641
|
-
*
|
|
3642
|
-
*
|
|
3643
|
-
*
|
|
3644
|
-
*
|
|
3906
|
+
* GET /ui/devices — the one device list, for every fleet (AGEND-138, #3486): is this a web-only fleet, may THIS session
|
|
3907
|
+
* approve a new device (web-only: the verified owner) and end the others' (`canEndOthers`), and — to an admin session,
|
|
3908
|
+
* never to a guest or the CLI's header token — every signed-in session of any tier, one row each (webDeviceRows).
|
|
3909
|
+
* `owner`: the verified owner (web-only: this computer's admin here or from outside; a chat fleet: an admin whose chat
|
|
3910
|
+
* account confirmed this session). `authority`: web authorization is on; with it off nobody is an owner, so on a web-only
|
|
3911
|
+
* fleet nobody may add a device or sign another out and the page says so.
|
|
3645
3912
|
*/
|
|
3646
3913
|
webDevicesStatus(req) {
|
|
3647
3914
|
const webOnly = this.isWebOnlyFleet();
|
|
3648
|
-
const owner = webOnly
|
|
3649
|
-
|
|
3915
|
+
const owner = webOnly ? !!this.deviceApprovalOwner(req) : !!this.webAuthorityRevoker(req);
|
|
3916
|
+
const rule = this.sessionEndRule(req);
|
|
3917
|
+
return { webOnly, owner, authority: this.webAuthorityState().enabled, canEndOthers: !!rule && (webOnly ? owner : true), devices: this.webDeviceRows(req) };
|
|
3918
|
+
}
|
|
3919
|
+
/**
|
|
3920
|
+
* AGEND-138 (#3486): which sessions may this ADMIN request sign out — one rule for every way in (POST /ui/devices/signout,
|
|
3921
|
+
* DELETE /auth/sessions[/<handle>]) and for the list's `canSignOut`; asked of the live session each time. Null: not an
|
|
3922
|
+
* admin session (a guest or read-only one ends only its own account's, auth-api; the header token none).
|
|
3923
|
+
* - a web-only fleet: the verified owner ends any; every other admin only itself (`any: false`);
|
|
3924
|
+
* - a fleet with a chat connection: an admin ends their OWN other devices (the same chat account) and any guest's or
|
|
3925
|
+
* read-only one; ANOTHER admin's devices only that admin. Every admin sign-in there records its account (`owner`: /web,
|
|
3926
|
+
* /dashboard and the per-admin authenticator); only a session with NO chat account (the host's own `agend web --code`,
|
|
3927
|
+
* or one persisted before accounts were recorded) counts as the host's — one principal that only another such session
|
|
3928
|
+
* may end, and that ends no chat admin's. It does not re-check that the account is still an admin (an existing
|
|
3929
|
+
* limitation of every admin API; follow-up).
|
|
3930
|
+
* Revoke-all (`revokeWebSessions`, /dashboard revoke) is the host's emergency button and is not this rule.
|
|
3931
|
+
*/
|
|
3932
|
+
sessionEndRule(req) {
|
|
3933
|
+
const auth = authorizeSession(req, this.webToken, this.webSessions, { touch: false });
|
|
3934
|
+
if (auth.kind !== "ok" || auth.session.tier !== "admin")
|
|
3935
|
+
return null;
|
|
3936
|
+
const me = auth.session;
|
|
3937
|
+
if (this.isWebOnlyFleet()) {
|
|
3938
|
+
const owner = !!this.deviceApprovalOwner(req);
|
|
3939
|
+
return { session: me, any: owner, may: r => r.handle === me.handle || owner, blocked: "owner_required" };
|
|
3940
|
+
}
|
|
3941
|
+
const principal = (r) => (r.owner ? `${r.owner.adapterId}\u0000${r.owner.userId}` : "\u0000host");
|
|
3942
|
+
return { session: me, any: true, may: r => r.handle === me.handle || r.tier !== "admin" || principal(r) === principal(me), blocked: "other_admin" };
|
|
3943
|
+
}
|
|
3944
|
+
/**
|
|
3945
|
+
* AGEND-138: auth-api's narrowing of `DELETE /auth/sessions[/<handle>]` for an admin. Three answers, never confused:
|
|
3946
|
+
* a predicate (what this caller may end), `undefined` (a web-only fleet: no narrowing here, its own owner check stands) and
|
|
3947
|
+
* `null` — the caller could not be authenticated AGAIN just now (expired or signed out since auth-api's first check): a denial,
|
|
3948
|
+
* which must never be read as "no restriction" (PR #3553 review).
|
|
3949
|
+
*/
|
|
3950
|
+
endableSessions(req) {
|
|
3951
|
+
if (this.isWebOnlyFleet())
|
|
3952
|
+
return undefined;
|
|
3953
|
+
return this.sessionEndRule(req)?.may ?? null;
|
|
3650
3954
|
}
|
|
3651
3955
|
/**
|
|
3652
|
-
* Refs #3061 (P2b): the device list —
|
|
3653
|
-
*
|
|
3654
|
-
*
|
|
3956
|
+
* Refs #3061 (P2b), AGEND-138: the device list — every signed-in session of any tier, newest activity first: its tier,
|
|
3957
|
+
* how it was approved, whether it carries owner authority, whether it is the reader's own, and whether the reader may sign
|
|
3958
|
+
* it out (and if not, why). Only an admin session reads it: a guest, a read-only session and the header token get none,
|
|
3959
|
+
* so no one sees another person's devices unless they are an admin.
|
|
3655
3960
|
*
|
|
3656
|
-
* `
|
|
3657
|
-
*
|
|
3658
|
-
* not an owner until the authenticator vouches for it. Display only — the checks that act
|
|
3961
|
+
* `verified` is the §3 verdict for an admin session as it would be used from where it signs in (a host session from this
|
|
3962
|
+
* computer, a session from outside over the link, a chat account's confirmed one): one that signed in with a one-time
|
|
3963
|
+
* code or a device approval is not an owner until the authenticator vouches for it. Display only — the checks that act
|
|
3964
|
+
* on it run again at each use.
|
|
3659
3965
|
*/
|
|
3660
3966
|
webDeviceRows(req) {
|
|
3661
|
-
const
|
|
3662
|
-
if (
|
|
3967
|
+
const rule = this.sessionEndRule(req);
|
|
3968
|
+
if (!rule || !this.webSessions)
|
|
3663
3969
|
return [];
|
|
3664
3970
|
const authorizations = this.sessionAuthorizationStore();
|
|
3665
|
-
return this.webSessions.list(
|
|
3971
|
+
return this.webSessions.list(rule.session.idHash, () => true).map(summary => {
|
|
3666
3972
|
const record = this.webSessions.findByHandle(summary.handle);
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3973
|
+
// The reader's own row is judged on the request that asks (as the session menu's /ui/authorization is: tests/…-138), another
|
|
3974
|
+
// session as it signed in (we cannot know where it is now).
|
|
3975
|
+
const gateway = summary.current ? !!gatewayRequestContext(req) : summary.surface === "gateway";
|
|
3976
|
+
const peer = summary.current ? webPeerOf(req)
|
|
3977
|
+
: gateway ? authorizations?.get(summary.handle)?.peer ?? "quick_link" : record?.host === true ? "loopback" : authorizations?.get(summary.handle)?.peer ?? "lan";
|
|
3978
|
+
const verified = summary.tier === "admin" && !!record && !this.webAuthority({ session: record, gateway, peer }).refusal;
|
|
3979
|
+
const may = !summary.current && !!record && rule.may(record);
|
|
3980
|
+
return { handle: summary.handle, label: summary.label, tier: summary.tier, via: summary.via, verified, current: summary.current, surface: summary.surface,
|
|
3670
3981
|
created: summary.created, lastSeen: summary.lastSeen, expiresAt: Math.min(summary.absoluteExpiry, summary.idleExpiry),
|
|
3671
|
-
|
|
3982
|
+
canSignOut: may, ...(!summary.current && !may ? { signOutBlocked: rule.blocked } : {}) };
|
|
3672
3983
|
});
|
|
3673
3984
|
}
|
|
3674
3985
|
/**
|
|
3675
3986
|
* Refs #3061 (P2b): may this request's session end ANOTHER session — one signed in elsewhere, or all of them (auth-api
|
|
3676
3987
|
* `DELETE /auth/sessions…`, which an admin session could always do). On a web-only fleet that is the verified owner's:
|
|
3677
3988
|
* a session a code or a device approval made is signed in but not an owner, and could otherwise sign out the owner's
|
|
3678
|
-
* own. A fleet with a chat connection
|
|
3989
|
+
* own. A fleet with a chat connection: yes for an admin, within endableSessions' rule (AGEND-138). Ending one's OWN
|
|
3990
|
+
* session is never this.
|
|
3679
3991
|
*/
|
|
3680
3992
|
mayEndOtherSessions(req) {
|
|
3681
3993
|
return !this.isWebOnlyFleet() || !!this.deviceApprovalOwner(req);
|
|
3682
3994
|
}
|
|
3683
3995
|
/**
|
|
3684
|
-
* Refs #3061 (P2b): POST /ui/devices/signout {handle} —
|
|
3685
|
-
*
|
|
3686
|
-
* 403
|
|
3687
|
-
*
|
|
3688
|
-
*
|
|
3996
|
+
* Refs #3061 (P2b), AGEND-138: POST /ui/devices/signout {handle} — an admin ends another signed-in session, by the one
|
|
3997
|
+
* rule (sessionEndRule), asked of the live session each time. A web-only fleet: only the verified owner, and a non-owner
|
|
3998
|
+
* is refused (403 `owner_required`) BEFORE any handle is looked up, so it learns nothing about which handles exist. A chat
|
|
3999
|
+
* fleet: any admin for their own devices and any guest's or read-only one; another admin's device is refused (403
|
|
4000
|
+
* `other_admin`). Never the reader's own session here (Sign out is /auth/logout). The device's authorization goes with
|
|
4001
|
+
* it, so a copy of its cookie is nobody's.
|
|
3689
4002
|
*/
|
|
3690
4003
|
webDeviceSignOut(req, handle) {
|
|
3691
|
-
if (!this.
|
|
4004
|
+
if (!this.webSessions)
|
|
3692
4005
|
return { status: 404, body: { error: "not_found" } };
|
|
3693
|
-
const
|
|
3694
|
-
if (!
|
|
4006
|
+
const rule = this.sessionEndRule(req);
|
|
4007
|
+
if (!rule)
|
|
4008
|
+
return { status: 403, body: { error: "owner_required" } }; // not an admin session at all: the header token, a guest
|
|
4009
|
+
if (this.isWebOnlyFleet() && !rule.any)
|
|
3695
4010
|
return { status: 403, body: { error: "owner_required" } };
|
|
3696
|
-
if (handle ===
|
|
4011
|
+
if (handle === rule.session.handle)
|
|
3697
4012
|
return { status: 400, body: { error: "this_device" } };
|
|
3698
4013
|
const target = this.webSessions.findByHandle(handle);
|
|
3699
|
-
if (!target
|
|
4014
|
+
if (!target)
|
|
3700
4015
|
return { status: 404, body: { error: "not_found" } };
|
|
3701
|
-
|
|
4016
|
+
if (!rule.may(target))
|
|
4017
|
+
return { status: 403, body: { error: rule.blocked } };
|
|
4018
|
+
const { found, durable } = this.webSessions.revokeByHandle(handle);
|
|
3702
4019
|
if (!found)
|
|
3703
4020
|
return { status: 404, body: { error: "not_found" } };
|
|
3704
4021
|
this.sessionAuthorizationStore()?.prune(a => a.handle !== handle);
|
|
3705
|
-
this.logger.info({ by:
|
|
4022
|
+
this.logger.info({ by: rule.session.handle.slice(0, 8), handle, label: target.label, tier: target.tier, via: sessionVia(target), durable }, "Device signed out by an admin");
|
|
3706
4023
|
if (!durable)
|
|
3707
4024
|
return { status: 500, body: { ok: false, durable: false, error: "not_durable" } };
|
|
3708
4025
|
return { status: 200, body: { ok: true } };
|
|
@@ -3816,6 +4133,13 @@ export class FleetManager {
|
|
|
3816
4133
|
}
|
|
3817
4134
|
this.logger.info({ id: view.id }, "Settings change confirmed from the web: no General reachable for the notice");
|
|
3818
4135
|
}
|
|
4136
|
+
/** The primary General: the General on the primary connection, else the first one — and the connection that owns it. */
|
|
4137
|
+
settingsPrimaryGeneral() {
|
|
4138
|
+
const generals = Object.entries(this.fleetConfig?.instances ?? {}).filter(([, cfg]) => cfg.general_topic === true);
|
|
4139
|
+
const selected = generals.find(([name]) => this.getInstanceAdapterId(name) === this.getPrimaryAdapterId()) ?? generals[0];
|
|
4140
|
+
const owner = selected && this.getInstanceAdapterId(selected[0]);
|
|
4141
|
+
return selected && owner ? { name: selected[0], owner } : undefined;
|
|
4142
|
+
}
|
|
3819
4143
|
/** Exact configured effect owners; this does not depend on prompt location. */
|
|
3820
4144
|
settingsChatAuthority(store, id) {
|
|
3821
4145
|
const scope = store.authorityOf(id);
|
|
@@ -3824,12 +4148,7 @@ export class FleetManager {
|
|
|
3824
4148
|
const channels = this.fleetConfig?.channels ?? (this.fleetConfig?.channel ? [this.fleetConfig.channel] : []);
|
|
3825
4149
|
const targets = new Set(scope.connections);
|
|
3826
4150
|
let primaryGeneral;
|
|
3827
|
-
const selectPrimary = () =>
|
|
3828
|
-
const generals = Object.entries(this.fleetConfig?.instances ?? {}).filter(([, cfg]) => cfg.general_topic === true);
|
|
3829
|
-
const selected = generals.find(([name]) => this.getInstanceAdapterId(name) === this.getPrimaryAdapterId()) ?? generals[0];
|
|
3830
|
-
const owner = selected && this.getInstanceAdapterId(selected[0]);
|
|
3831
|
-
return selected && owner ? { name: selected[0], owner } : undefined;
|
|
3832
|
-
};
|
|
4151
|
+
const selectPrimary = () => this.settingsPrimaryGeneral();
|
|
3833
4152
|
if (scope.primaryGeneral) {
|
|
3834
4153
|
primaryGeneral = selectPrimary();
|
|
3835
4154
|
if (!primaryGeneral)
|
|
@@ -6483,6 +6802,8 @@ export class FleetManager {
|
|
|
6483
6802
|
}
|
|
6484
6803
|
/** #1218: GET /ui/steps — an instance's steps, read on demand (null: no such instance). */
|
|
6485
6804
|
logSteps(name, q) { return this.log.steps(name, q); }
|
|
6805
|
+
subagentReader = new SubagentService(name => this.lifecycle.daemons.get(name)?.subagentSource() ?? null);
|
|
6806
|
+
subagentRuns(name) { return this.subagentReader.read(name); }
|
|
6486
6807
|
/**
|
|
6487
6808
|
* #1218: where an instance's steps are read from, resolved only when its Log asks: the transcript its daemon follows
|
|
6488
6809
|
* now; for claude-code, also the path its statusline last named (so a stopped instance's Log still shows its last
|
|
@@ -9198,12 +9519,14 @@ export class FleetManager {
|
|
|
9198
9519
|
* A single-use login code for the dashboard, for a channel only the operator
|
|
9199
9520
|
* can read (`/dashboard`). Null while the panel is closed (no web.token).
|
|
9200
9521
|
*/
|
|
9201
|
-
issueDashboardLogin() {
|
|
9522
|
+
issueDashboardLogin(recipient) {
|
|
9202
9523
|
const token = this.webToken;
|
|
9203
9524
|
if (!token)
|
|
9204
9525
|
return null;
|
|
9205
9526
|
this.initializeWebSessions();
|
|
9206
|
-
|
|
9527
|
+
// AGEND-138 (#3486): given the admin it is for, the session this code makes is that admin's own (auth-api binds the session's
|
|
9528
|
+
// `owner` to the recipient) — so the devices rule (sessionEndRule) tells two admins apart. Without one: no account, the host's.
|
|
9529
|
+
const issued = this.webLoginCodes.issue({ tier: "admin", epoch: tokenEpoch(token), ...(recipient ? { recipient } : {}) });
|
|
9207
9530
|
return { display: issued.display, expiresAt: issued.expiresAt, ttlMinutes: Math.round(LOGIN_CODE_TTL_MS / 60_000) };
|
|
9208
9531
|
}
|
|
9209
9532
|
tunnelPurposeLane = null;
|
|
@@ -10917,6 +11240,8 @@ export class FleetManager {
|
|
|
10917
11240
|
if (ch.adapterId)
|
|
10918
11241
|
this.instanceWorldBinding.set(ch.instanceName, ch.adapterId);
|
|
10919
11242
|
}
|
|
11243
|
+
// #3526: catalogs belong to the fleet, including a fleet with no chat adapter.
|
|
11244
|
+
this.probeCliEnvs();
|
|
10920
11245
|
// #1565: the web chat as it was before this process — the configured instances' only (fleet.yaml and ClassicBot
|
|
10921
11246
|
// rooms), before the dashboard serves anything; from now on every change is written back (off the loop).
|
|
10922
11247
|
this.restoreWebChat(fleet);
|
|
@@ -12111,9 +12436,6 @@ export class FleetManager {
|
|
|
12111
12436
|
}, this.logger, "adapter.slash_command"));
|
|
12112
12437
|
// This adapter's own Telegram menus — each Telegram adapter registers its own when it starts (#1191).
|
|
12113
12438
|
this.registerTelegramCommandsFor(channelConfig);
|
|
12114
|
-
// Background-probe each backend's CLI env (version/models) → cli-env cache.
|
|
12115
|
-
// Non-blocking: /model & status views read the cache; never delays startup.
|
|
12116
|
-
this.probeCliEnvs();
|
|
12117
12439
|
adapter.on("started", safeHandler((username, userId) => {
|
|
12118
12440
|
if (!isCurrentAdapter())
|
|
12119
12441
|
return;
|
|
@@ -14085,6 +14407,13 @@ export class FleetManager {
|
|
|
14085
14407
|
isWebOnlyFleet() {
|
|
14086
14408
|
return isWebOnlyFleetConfig(this.fleetConfig);
|
|
14087
14409
|
}
|
|
14410
|
+
/**
|
|
14411
|
+
* S-117 story 1: the sign-in page's "no chat" words (no /web to send) — a web-only fleet, or one whose chat is not
|
|
14412
|
+
* connected yet (a fresh install whose bot is still being set up, or is down): /web cannot answer there.
|
|
14413
|
+
*/
|
|
14414
|
+
signinWithoutChat() {
|
|
14415
|
+
return this.isWebOnlyFleet() || ![...this.adapterState.values()].some(state => state.status === "connected");
|
|
14416
|
+
}
|
|
14088
14417
|
/** On a fleet with no chat platform, the dashboard is where an instance-health prompt is posted (#1307 item 6). */
|
|
14089
14418
|
webOnlyPromptPlace() {
|
|
14090
14419
|
return this.worlds.size === 0 && this.isWebOnlyFleet() ? { adapter: WEB_ONLY_PROMPT_SINK, adapterId: "web", chatId: "web" } : null;
|
|
@@ -15784,8 +16113,10 @@ export class FleetManager {
|
|
|
15784
16113
|
delete current[key];
|
|
15785
16114
|
Object.assign(current, resolved);
|
|
15786
16115
|
}
|
|
16116
|
+
const previousCatalogConfig = this.savedFleetConfigSnapshot;
|
|
15787
16117
|
this.savedFleetConfigSnapshot = structuredClone(this.fleetConfig);
|
|
15788
16118
|
this.nativeMcpStore?.observePolicies();
|
|
16119
|
+
this.probeChangedCliEnvs(previousCatalogConfig);
|
|
15789
16120
|
this.agentCredentialsCache?.observePolicies();
|
|
15790
16121
|
this.refreshSavedDashboardPermissions();
|
|
15791
16122
|
this.logger.info({ path: this.configPath, strippedDefaults: redundantPaths.length }, "Saved fleet config (lossless patch)");
|
|
@@ -17626,8 +17957,17 @@ export class FleetManager {
|
|
|
17626
17957
|
// rejects the message afterwards still consumes the throttle window, which
|
|
17627
17958
|
// is the pre-existing semantic and not something this change alters.
|
|
17628
17959
|
let dispatched = false;
|
|
17629
|
-
|
|
17630
|
-
|
|
17960
|
+
// A native-exec General is a web-chat status line (an SSE event with no browser receipt and no store): fine for a message nobody must not miss, never an acknowledgement.
|
|
17961
|
+
// For a caller that needs one it is shown best-effort (once) and delivery goes on to the primary channel or the durable Notice.
|
|
17962
|
+
const generalIsNative = !!general && isNativeExecInstance(this.fleetConfig?.instances[general]);
|
|
17963
|
+
if (general && opts.ack && generalIsNative && !this.ownerNoticeLive.has(body)) {
|
|
17964
|
+
this.ownerNoticeLive.add(body);
|
|
17965
|
+
if (this.ownerNoticeLive.size > 200)
|
|
17966
|
+
this.ownerNoticeLive.delete(this.ownerNoticeLive.values().next().value);
|
|
17967
|
+
this.emitSseEvent("message", { instance: general, role: "status", sender: "AgEnD", text: body, ts: new Date().toISOString() });
|
|
17968
|
+
}
|
|
17969
|
+
if (general && !(opts.ack && generalIsNative)) {
|
|
17970
|
+
dispatched = this.notifyInstanceTopic(general, body, undefined, opts.ack);
|
|
17631
17971
|
}
|
|
17632
17972
|
else {
|
|
17633
17973
|
// No General instance — fall back to the primary channel's own notice
|
|
@@ -17637,14 +17977,20 @@ export class FleetManager {
|
|
|
17637
17977
|
if (this.adapter && target) {
|
|
17638
17978
|
const out = this.renderPlaces(this.getPrimaryAdapterId(), body, target.opts);
|
|
17639
17979
|
this.adapter.sendText(target.chatId, out.text, out.opts)
|
|
17640
|
-
.
|
|
17980
|
+
.then(() => opts.ack?.(true), err => { this.logger.warn({ err }, "Failed to send fleet error notification"); opts.ack?.(false); });
|
|
17641
17981
|
dispatched = true;
|
|
17642
17982
|
}
|
|
17643
17983
|
}
|
|
17644
17984
|
// #2910 D2: a web-only fleet has no General: the notice goes to the dashboard's Notices instead (and spends the
|
|
17645
17985
|
// throttle window like a post would).
|
|
17646
|
-
|
|
17647
|
-
|
|
17986
|
+
// A caller that needs an acknowledgement (the owner notice) gets one only from a Notice that was WRITTEN: WebNotices.add keeps its item in memory even when the file cannot be written.
|
|
17987
|
+
if (!dispatched) {
|
|
17988
|
+
const recorded = opts.ack ? this.recordWebNoticeDurable("fleet", body) : this.recordWebNotice("fleet", body);
|
|
17989
|
+
if (recorded) {
|
|
17990
|
+
dispatched = true;
|
|
17991
|
+
opts.ack?.(true);
|
|
17992
|
+
}
|
|
17993
|
+
}
|
|
17648
17994
|
if (!dispatched) {
|
|
17649
17995
|
// Do NOT record the throttle key. It used to be claimed before delivery
|
|
17650
17996
|
// was attempted, so a message nobody could receive — every fleet error
|
|
@@ -17669,7 +18015,9 @@ export class FleetManager {
|
|
|
17669
18015
|
}
|
|
17670
18016
|
webNotices = null;
|
|
17671
18017
|
/** #2910 D2 (web-api): the Notices on a web-only fleet; null on any other (its General says them). */
|
|
17672
|
-
webNoticesFeed() { return this.
|
|
18018
|
+
webNoticesFeed() { return this.hasWebNotices() ? this.webNoticeStore() : null; }
|
|
18019
|
+
/** A web-only fleet always has its Notices; a chat fleet only once something was put there (AGEND-122: a confirmation that nothing else could carry). */
|
|
18020
|
+
hasWebNotices() { return !!this.webOnlyPromptPlace() || (this.webNoticeStore()?.newest() ?? 0) > 0; }
|
|
17673
18021
|
/** #2910 D2: the web-only fleet's Notices (web-notices.json), read on first use. */
|
|
17674
18022
|
webNoticeStore() {
|
|
17675
18023
|
if (!this.dataDir)
|
|
@@ -17693,11 +18041,12 @@ export class FleetManager {
|
|
|
17693
18041
|
return true;
|
|
17694
18042
|
}
|
|
17695
18043
|
/** #3373 review P2: recordWebNotice for a notice that must be on disk first — true only once it was written. */
|
|
17696
|
-
recordWebNoticeDurable(kind, text) {
|
|
18044
|
+
recordWebNoticeDurable(kind, text, instance) {
|
|
17697
18045
|
if (!this.webOnlyPromptPlace())
|
|
17698
18046
|
return false;
|
|
17699
18047
|
const store = this.webNoticeStore();
|
|
17700
|
-
const
|
|
18048
|
+
const known = instance !== undefined && Object.hasOwn(this.fleetConfig?.instances ?? {}, instance) ? instance : undefined;
|
|
18049
|
+
const notice = store?.addDurable({ kind, text: stripPlaceRefs(text), ...(known ? { instance: known } : {}) }) ?? null;
|
|
17701
18050
|
if (!notice)
|
|
17702
18051
|
return false;
|
|
17703
18052
|
this.emitSseEvent("notice", { notice, unread: store.unread() });
|
|
@@ -17715,18 +18064,23 @@ export class FleetManager {
|
|
|
17715
18064
|
* rejection surfaces only as a warn in its .catch. True delivery confirmation
|
|
17716
18065
|
* would have to make this async and change every caller.
|
|
17717
18066
|
*/
|
|
17718
|
-
notifyInstanceTopic(instanceName, text, extraOpts) {
|
|
18067
|
+
notifyInstanceTopic(instanceName, text, extraOpts, ack) {
|
|
17719
18068
|
if (isNativeExecInstance(this.fleetConfig?.instances[instanceName])) {
|
|
17720
18069
|
this.emitSseEvent("message", { instance: instanceName, role: "status", sender: "AgEnD", text, ts: new Date().toISOString() });
|
|
17721
|
-
return
|
|
18070
|
+
return !ack; // an SSE event is no acknowledgement
|
|
17722
18071
|
}
|
|
17723
18072
|
// #2910 D2: a web-only fleet has no topics: what the agent's topic would have been told is a Notice about it.
|
|
17724
|
-
if (this.webOnlyPromptPlace())
|
|
17725
|
-
|
|
18073
|
+
if (this.webOnlyPromptPlace()) {
|
|
18074
|
+
const recorded = ack ? this.recordWebNoticeDurable("instance", text, instanceName) : this.recordWebNotice("instance", text, instanceName);
|
|
18075
|
+
if (recorded)
|
|
18076
|
+
ack?.(true);
|
|
18077
|
+
return recorded;
|
|
18078
|
+
}
|
|
17726
18079
|
const send = this.sendToInstanceTopic(instanceName, text, extraOpts);
|
|
17727
18080
|
if (!send)
|
|
17728
18081
|
return false;
|
|
17729
|
-
|
|
18082
|
+
// `ack` (a caller that must not lose the message) is told when the platform took it or refused it; everyone else only gets the log line.
|
|
18083
|
+
send.sent.then(() => ack?.(true), e => { this.logger.warn({ err: e, instanceName }, send.failure); ack?.(false); });
|
|
17730
18084
|
return true;
|
|
17731
18085
|
}
|
|
17732
18086
|
/**
|
|
@@ -19040,7 +19394,7 @@ export class FleetManager {
|
|
|
19040
19394
|
tokenEpoch: this.webToken ? tokenEpoch(this.webToken) : null,
|
|
19041
19395
|
...(input.instance !== undefined ? { target: { adapterId: this.getInstanceAdapterId(input.instance) } } : {}),
|
|
19042
19396
|
isAdmin: (userId, adapterId) => this.adminGate(userId, adapterId) === "ok",
|
|
19043
|
-
authorization: input.session ? this.sessionAuthorizationStore()?.get(input.session.handle) ?? null : null,
|
|
19397
|
+
authorization: input.authorization !== undefined ? input.authorization : input.session ? this.sessionAuthorizationStore()?.get(input.session.handle) ?? null : null,
|
|
19044
19398
|
policy: { ...webAuthorityPolicy(this.fleetConfig?.web), enabled: state.enabled, loopbackOnly: state.loopbackOnly, namedLink: state.namedLink, quickLink: state.quickLink }, epoch: state.epoch, now: Date.now(),
|
|
19045
19399
|
hostOperator: this.isWebOnlyFleet(), outside: this.outsideLink(),
|
|
19046
19400
|
});
|
|
@@ -19172,56 +19526,175 @@ export class FleetManager {
|
|
|
19172
19526
|
isOutsideLink(exposureId) {
|
|
19173
19527
|
return this.outsideLink()?.exposureId === exposureId;
|
|
19174
19528
|
}
|
|
19175
|
-
/**
|
|
19529
|
+
/**
|
|
19530
|
+
* What Settings shows: THIS admin's own authenticator (set up or not, when, their own "ask for my code" switch), whether they
|
|
19531
|
+
* may set it up or change it here and whether that asks their current code; and, for the host operator on a web-only fleet,
|
|
19532
|
+
* the outside switch, a wait in force and the link — its address only to this computer.
|
|
19533
|
+
*/
|
|
19176
19534
|
webOutsideStatus(req) {
|
|
19177
|
-
const store = this.webRemoteAccess()
|
|
19535
|
+
const store = this.webRemoteAccess();
|
|
19536
|
+
const manager = this.authenticatorOwner(req);
|
|
19537
|
+
const status = store?.status(manager?.who ?? HOST_ADMIN_KEY);
|
|
19178
19538
|
const here = !!this.liveOwner(req, { hostOnly: true });
|
|
19179
19539
|
const open = this.outsideOn() ? this.publicWebLink?.openSignin() : null;
|
|
19180
19540
|
const mine = !!open && isOutsideLinkOwner(open.owner);
|
|
19181
19541
|
const linkStatus = this.outsideOn() ? this.getPublicWebStatus() : null;
|
|
19182
|
-
|
|
19542
|
+
const signinName = manager && manager.who !== HOST_ADMIN_KEY && status?.enrolled
|
|
19543
|
+
? this.signinHandleOf({ adapterId: manager.actor.adapter_id, userId: manager.actor.user_id }) ?? manager.actor.user_id : null;
|
|
19544
|
+
return { webOnly: this.isWebOnlyFleet(), here, enrolled: !!status?.enrolled, enrolledAt: status?.enrolledAt ?? null, signinName,
|
|
19545
|
+
manage: !!manager, codeNeeded: !!manager && !!store && this.authenticatorCodeAsked(manager, store), strict: !!status?.strict,
|
|
19183
19546
|
outside: this.outsideOn(), pausedForMs: status?.pausedForMs ?? 0,
|
|
19184
19547
|
link: linkStatus && linkStatus.state !== "closed" ? { ...linkStatus, ...(here && mine ? { url: open.url } : {}), quick: !publicLinkNamedHostname(this.fleetConfig?.web) } : null };
|
|
19185
19548
|
}
|
|
19186
|
-
/**
|
|
19187
|
-
|
|
19188
|
-
|
|
19549
|
+
/**
|
|
19550
|
+
* AGEND-122 (per admin): who may set up, replace or remove an authenticator, and turn its switch on or off — an admin with a
|
|
19551
|
+
* role over held changes (settings-role.ts) on a direct connection (never a link), on a chat fleet and a web-only one alike, and
|
|
19552
|
+
* only THEIR OWN (`who`: their connection and account; a web-only fleet's one admin and a chat fleet's host session are the host
|
|
19553
|
+
* operator's). Another admin's is never reachable from here: a stolen session can lock out at most the admin it belongs to, and
|
|
19554
|
+
* every such change posts a Notice to the fleet. On the AgEnD computer's own browser no code is asked. Connections from outside
|
|
19555
|
+
* and their switch are another thing and stay a web-only fleet's, on its own computer (liveOwner).
|
|
19556
|
+
*/
|
|
19557
|
+
authenticatorOwner(req) {
|
|
19558
|
+
if (gatewayRequestContext(req))
|
|
19559
|
+
return null;
|
|
19560
|
+
const first = this.settingsRole(req);
|
|
19561
|
+
if (!first.role.ok || !first.handle)
|
|
19562
|
+
return null;
|
|
19563
|
+
const handle = first.handle, actor = first.role.actor, who = adminKey(actor.adapter_id, actor.user_id);
|
|
19564
|
+
return { handle, who, actor, onHost: first.role.onHost,
|
|
19565
|
+
current: () => { const now = this.settingsRole(req); return now.role.ok && now.handle === handle && adminKey(now.role.actor.adapter_id, now.role.actor.user_id) === who; } };
|
|
19566
|
+
}
|
|
19567
|
+
/**
|
|
19568
|
+
* Changing an app that exists — replacing it, removing it, turning its switch off — is the OWNER'S, proven by its current code off
|
|
19569
|
+
* the AgEnD computer, whatever the "ask for my code on confirmations" switch says (that switch is about ordinary Settings
|
|
19570
|
+
* confirmations; this is lifecycle ownership). With no app there is no old code to ask: a first set-up asks nothing, and the AgEnD
|
|
19571
|
+
* computer's own browser is never asked — the recovery controls.
|
|
19572
|
+
*/
|
|
19573
|
+
authenticatorCodeAsked(owner, access) {
|
|
19574
|
+
return !owner.onHost && access.isEnrolled(owner.who);
|
|
19575
|
+
}
|
|
19576
|
+
/** What changing the app asks of this session: nothing, or the current code (of its own app). */
|
|
19577
|
+
authenticatorStep(owner, access, code) {
|
|
19578
|
+
if (owner.onHost)
|
|
19579
|
+
return { ok: true, verified: true };
|
|
19580
|
+
if (!this.authenticatorCodeAsked(owner, access))
|
|
19581
|
+
return { ok: true, verified: false };
|
|
19582
|
+
if (typeof code !== "string" || code.trim() === "")
|
|
19583
|
+
return { ok: false, error: "code_required" };
|
|
19584
|
+
const checked = this.checkAuthenticatorCode(access, owner.who, code, "authenticator change");
|
|
19585
|
+
return checked.ok ? { ok: true, verified: true } : checked;
|
|
19586
|
+
}
|
|
19587
|
+
/**
|
|
19588
|
+
* An app being set up, per session handle: whether that start was on this computer or passed the code. A set-up begun while the
|
|
19589
|
+
* code was not asked (the secret lives ten minutes) must not be finished by a session whose switch is on by then, and one begun
|
|
19590
|
+
* on this computer is not finished from another device: it never passed the code, so the finish is refused. A "code" start also
|
|
19591
|
+
* records WHICH app the code proved (`enrollment`, the opaque id of the owner's app at that moment, null when there was none): a
|
|
19592
|
+
* code is a proof about that app and about nothing that replaces it — the finish is refused once the owner's app has been
|
|
19593
|
+
* replaced or removed since (say, a recovery on the computer), so an earlier remote set-up can never overwrite the newer app.
|
|
19594
|
+
*/
|
|
19595
|
+
authenticatorStarts = new Map();
|
|
19596
|
+
/** Set up (or set up again) your own: a new secret, shown once. Null: not you. A code is asked first when your switch needs one. */
|
|
19597
|
+
webOutsideBeginEnrollment(req, code) {
|
|
19598
|
+
const owner = this.authenticatorOwner(req), store = this.webRemoteAccess();
|
|
19189
19599
|
if (!owner || !store)
|
|
19190
19600
|
return null;
|
|
19191
|
-
|
|
19601
|
+
const step = this.authenticatorStep(owner, store, code);
|
|
19602
|
+
if (!step.ok) {
|
|
19603
|
+
if (step.error === "not_here")
|
|
19604
|
+
return null;
|
|
19605
|
+
return { error: step.error, ...(step.retryAfterMs !== undefined ? { retryAfterMs: step.retryAfterMs } : {}) };
|
|
19606
|
+
}
|
|
19607
|
+
if (!owner.current() || !store.hasRoom(owner.who))
|
|
19608
|
+
return null;
|
|
19609
|
+
const begun = store.beginEnrollment(owner.handle, hostname() || "fleet", owner.who);
|
|
19610
|
+
this.authenticatorStarts.set(owner.handle, { kind: owner.onHost ? "host" : step.verified ? "code" : "none", enrollment: store.enrollmentOf(owner.who) });
|
|
19611
|
+
if (this.authenticatorStarts.size > 64)
|
|
19612
|
+
this.authenticatorStarts.delete(this.authenticatorStarts.keys().next().value);
|
|
19613
|
+
return begun;
|
|
19192
19614
|
}
|
|
19193
|
-
/** The new app's first code: on "ok" it replaces the old one,
|
|
19615
|
+
/** The new app's first code: on "ok" it is now yours (the host operator's replaces the old one, ending the sessions from outside). */
|
|
19194
19616
|
webOutsideConfirmEnrollment(req, code) {
|
|
19195
|
-
const owner = this.
|
|
19617
|
+
const owner = this.authenticatorOwner(req), store = this.webRemoteAccess();
|
|
19196
19618
|
if (!owner || !store || !owner.current())
|
|
19197
19619
|
return "not_here";
|
|
19198
|
-
const had = store.
|
|
19199
|
-
|
|
19620
|
+
const had = store.isEnrolled(owner.who);
|
|
19621
|
+
// Asked again here, not only at the start: the switch may have been turned on since (see authenticatorStarts).
|
|
19622
|
+
const start = this.authenticatorStarts.get(owner.handle);
|
|
19623
|
+
// A set-up is finished only by the attempt that was started, and only while what its start proved still holds. No start on
|
|
19624
|
+
// record (never made here, or already refused) and a start whose app is no longer the owner's (replaced or removed since —
|
|
19625
|
+
// a recovery on the computer, say; for a start with no app, one has appeared) VOID the attempt for good: its secret is dropped
|
|
19626
|
+
// from the store too, so repeating the same finish can never revive it. The only way on is a fresh begin.
|
|
19627
|
+
if (!start || (start.kind !== "host" && start.enrollment !== store.enrollmentOf(owner.who))) {
|
|
19628
|
+
this.authenticatorStarts.delete(owner.handle);
|
|
19629
|
+
store.cancelEnrollment(owner.handle);
|
|
19630
|
+
return "not_here";
|
|
19631
|
+
}
|
|
19632
|
+
if (!owner.onHost && this.authenticatorCodeAsked(owner, store) && start.kind !== "code")
|
|
19633
|
+
return "not_here";
|
|
19634
|
+
const r = store.confirmEnrollment(owner.handle, code, { physicalHost: owner.onHost });
|
|
19200
19635
|
if (r === "ok") {
|
|
19201
|
-
this.
|
|
19202
|
-
|
|
19636
|
+
this.authenticatorStarts.delete(owner.handle);
|
|
19637
|
+
this.logger.info({ again: had, here: owner.onHost }, "Authenticator app set up");
|
|
19638
|
+
if (owner.who === HOST_ADMIN_KEY)
|
|
19203
19639
|
this.endOutsideSessions();
|
|
19204
|
-
|
|
19205
|
-
|
|
19206
|
-
this.notifyFleetError(t("outside.reenrolled_notice"));
|
|
19207
|
-
}
|
|
19640
|
+
// Every set-up or replacement, from anywhere, is said to the fleet's admins (#3327; AGEND-122): a set-up they did not make is noticed.
|
|
19641
|
+
this.postFleetSecurityNotice(t(had ? "outside.reenrolled_notice_by" : "outside.enrolled_notice_by", this.adminName(owner.actor)));
|
|
19208
19642
|
}
|
|
19209
19643
|
return r;
|
|
19210
19644
|
}
|
|
19211
|
-
/** Forget
|
|
19212
|
-
webOutsideRemove(req) {
|
|
19213
|
-
const owner = this.
|
|
19645
|
+
/** Forget your own app (your switch with it). A code is asked first when your switch needs one. Nothing set up: nothing happens. */
|
|
19646
|
+
webOutsideRemove(req, code) {
|
|
19647
|
+
const owner = this.authenticatorOwner(req), store = this.webRemoteAccess();
|
|
19214
19648
|
if (!owner || !store || !owner.current())
|
|
19215
19649
|
return "not_here";
|
|
19650
|
+
// Nothing of yours to remove: never reaches the store — a set-up another session (the host's recovery) has begun stays as it is.
|
|
19651
|
+
if (!store.isEnrolled(owner.who))
|
|
19652
|
+
return owner.onHost ? "ok" : "not_here";
|
|
19653
|
+
const step = this.authenticatorStep(owner, store, code);
|
|
19654
|
+
if (!step.ok) {
|
|
19655
|
+
if (step.error === "not_here")
|
|
19656
|
+
return "not_here";
|
|
19657
|
+
return { error: step.error, ...(step.retryAfterMs !== undefined ? { retryAfterMs: step.retryAfterMs } : {}) };
|
|
19658
|
+
}
|
|
19659
|
+
if (!owner.current())
|
|
19660
|
+
return "not_here";
|
|
19216
19661
|
// #3008 review (Prism P2 1): shut at once whatever the disk says; say so when it could not be saved (retried).
|
|
19217
|
-
const
|
|
19218
|
-
|
|
19219
|
-
|
|
19220
|
-
|
|
19221
|
-
|
|
19222
|
-
this.logger.info({ saved }, "Authenticator app removed; connections from outside off");
|
|
19662
|
+
const saved = store.remove(owner.who);
|
|
19663
|
+
if (owner.who === HOST_ADMIN_KEY)
|
|
19664
|
+
this.closeOutsideLink("outside removed");
|
|
19665
|
+
this.postFleetSecurityNotice(t("outside.removed_notice_by", this.adminName(owner.actor)));
|
|
19666
|
+
this.logger.info({ saved }, "Authenticator app removed");
|
|
19223
19667
|
return saved ? "ok" : "unsaved";
|
|
19224
19668
|
}
|
|
19669
|
+
/**
|
|
19670
|
+
* Turn your own "ask for my code to confirm from other devices" switch on or off. On needs your app set up and asks nothing (it
|
|
19671
|
+
* only tightens); off asks your current code off the AgEnD computer — so a session it restricts cannot lift the restriction for
|
|
19672
|
+
* you without it. Never anyone else's. Either way a Notice goes to the fleet's admins.
|
|
19673
|
+
*/
|
|
19674
|
+
webOutsideStrict(req, on, code) {
|
|
19675
|
+
const owner = this.authenticatorOwner(req), store = this.webRemoteAccess();
|
|
19676
|
+
if (!owner || !store || !owner.current())
|
|
19677
|
+
return "not_here";
|
|
19678
|
+
if (!store.isEnrolled(owner.who))
|
|
19679
|
+
return "not_enrolled";
|
|
19680
|
+
if (store.strictOf(owner.who) === on)
|
|
19681
|
+
return "ok";
|
|
19682
|
+
if (!on) {
|
|
19683
|
+
const step = this.authenticatorStep(owner, store, code);
|
|
19684
|
+
if (!step.ok) {
|
|
19685
|
+
if (step.error === "not_here")
|
|
19686
|
+
return "not_here";
|
|
19687
|
+
return { error: step.error, ...(step.retryAfterMs !== undefined ? { retryAfterMs: step.retryAfterMs } : {}) };
|
|
19688
|
+
}
|
|
19689
|
+
if (!owner.current())
|
|
19690
|
+
return "not_here";
|
|
19691
|
+
}
|
|
19692
|
+
const r = store.setStrict(owner.who, on);
|
|
19693
|
+
if (r === "not_enrolled")
|
|
19694
|
+
return r;
|
|
19695
|
+
this.postFleetSecurityNotice(t(on ? "outside.strict_on_notice_by" : "outside.strict_off_notice_by", this.adminName(owner.actor)));
|
|
19696
|
+
return r;
|
|
19697
|
+
}
|
|
19225
19698
|
/** The switch. On: needs an app set up; the link opens. Off: it closes and every session from outside ends. */
|
|
19226
19699
|
webOutsideSwitch(req, on) {
|
|
19227
19700
|
const owner = this.liveOwner(req, { hostOnly: true }), store = this.webRemoteAccess();
|
|
@@ -19313,34 +19786,123 @@ export class FleetManager {
|
|
|
19313
19786
|
this.openOutsideLink(OUTSIDE_LINK_RETRY_MS);
|
|
19314
19787
|
}
|
|
19315
19788
|
/**
|
|
19316
|
-
* #
|
|
19317
|
-
*
|
|
19318
|
-
*
|
|
19319
|
-
|
|
19320
|
-
|
|
19321
|
-
|
|
19322
|
-
|
|
19323
|
-
|
|
19324
|
-
|
|
19325
|
-
|
|
19326
|
-
|
|
19327
|
-
|
|
19328
|
-
|
|
19329
|
-
|
|
19789
|
+
* #3486 (per admin; auth-api POST /auth/totp): a browser that is not signed in yet signs in as ONE admin, with
|
|
19790
|
+
* the code of THAT admin's own authenticator — the same per-admin app their confirmations use. Who is not found by trying the code
|
|
19791
|
+
* against everyone: the person types a name (`account`), which resolves — among the admins that have an app and are still admins —
|
|
19792
|
+
* to at most one; the page lists nobody. A name that resolves to nobody (no such name, an admin with no app, a name two admins
|
|
19793
|
+
* share, one no longer an admin) is answered exactly as a wrong code is, after the same work and the same counting (store.signIn).
|
|
19794
|
+
* A web-only fleet has one admin (the host operator): its one app, no name needed.
|
|
19795
|
+
*
|
|
19796
|
+
* Where it works: a direct connection (LAN, tailnet, the owner's own proxy — and this computer's own browser) on any fleet; on a
|
|
19797
|
+
* chat fleet also a public link (TOTP_SIGNIN_OVER_PUBLIC_LINK, the one switch that takes that back); on a web-only fleet a link
|
|
19798
|
+
* only as before (#3008): the one "Allow connections from outside" opened. "Only this computer can authorize" closes all of it.
|
|
19799
|
+
* What it makes: a chat admin's session is that account's own (owner), exactly as a sign-in code from the chat makes it; a web-only
|
|
19800
|
+
* fleet's is that fleet's admin session (and over the outside link the #3008 `remote` one, authorized as before). No authority beyond
|
|
19801
|
+
* that: no "Authorize this browser", nothing an agent would take as a go-ahead. Every success tells every admin (a Notice).
|
|
19802
|
+
*/
|
|
19803
|
+
totpSignIn(input) {
|
|
19804
|
+
const store = this.webRemoteAccess(), webOnly = this.isWebOnlyFleet(), { exposureId, peer } = input;
|
|
19805
|
+
if (!store || !this.webToken || !this.totpSignInOpen(exposureId, peer))
|
|
19330
19806
|
return { kind: "closed" };
|
|
19807
|
+
const { who, ident } = this.resolveSignInAdmin(store, webOnly, input.account);
|
|
19808
|
+
const enrollment = who ? store.enrollmentOf(who) : null;
|
|
19809
|
+
const epoch = this.webAuthorityState().epoch, now = Date.now();
|
|
19810
|
+
// This browser: its cookie id, and on a direct connection the address too (over a link the gateway's peer is the tunnel, so the cookie alone).
|
|
19811
|
+
// A browser with a valid mark is counted by the MARK (a thief cannot shed it by dropping the cookie id), else by cookie id and address.
|
|
19812
|
+
const mark = findSigninKnownEntry(this.webToken, input.knownCookie, who, enrollment, epoch, now);
|
|
19813
|
+
const browser = mark ? { key: createHash("sha256").update(`agend-signin-mark\0${mark}`).digest("hex"), known: true }
|
|
19814
|
+
: { key: createHash("sha256").update(`agend-signin-browser\0${input.browser.id}\0${input.browser.address ?? "link"}`).digest("hex"), known: false };
|
|
19815
|
+
const v = store.signIn(who, ident, input.code, browser);
|
|
19331
19816
|
if (v.kind === "unavailable")
|
|
19332
19817
|
return v;
|
|
19333
|
-
if (v.
|
|
19334
|
-
|
|
19335
|
-
|
|
19336
|
-
|
|
19337
|
-
|
|
19338
|
-
|
|
19818
|
+
if (v.kind !== "ok") {
|
|
19819
|
+
// Half-way through a real admin's count, or the whole sign-in's: said once per cycle — nothing of the code or the name typed in it.
|
|
19820
|
+
if (v.began.halfFleet || v.began.halfAdmin)
|
|
19821
|
+
this.postFleetSecurityNotice(t("signin.totp_notice_attempts"));
|
|
19822
|
+
// A shared wait that starts is said to the admins when it is the whole sign-in's or a real admin's — never for a name that is nobody's (a flood of those must not be a flood of Notices).
|
|
19823
|
+
if (v.began.fleet || v.began.admin) {
|
|
19824
|
+
this.logger.warn({ fleet: v.began.fleet }, "Sign-in with authenticator codes paused after wrong codes");
|
|
19825
|
+
this.postFleetSecurityNotice(t("signin.totp_notice_paused", outsideDuration(v.began.waitMs)));
|
|
19826
|
+
}
|
|
19827
|
+
if (v.kind === "paused")
|
|
19828
|
+
return { kind: "paused", retryAfterMs: v.retryAfterMs };
|
|
19829
|
+
if (v.skewSteps !== undefined)
|
|
19830
|
+
this.logger.warn({ offsetSeconds: v.skewSteps * TOTP_STEP_SECONDS }, "A wrong authenticator code matched a nearby time step: this computer's clock may be off");
|
|
19831
|
+
this.logger.debug("Sign-in with an authenticator code refused");
|
|
19832
|
+
return { kind: "wrong" };
|
|
19833
|
+
}
|
|
19834
|
+
if (!who || !enrollment)
|
|
19835
|
+
return { kind: "wrong" };
|
|
19836
|
+
const actor = who === HOST_ADMIN_KEY ? null : (() => { const [adapterId, userId] = who.split("\u0000"); return adapterId && userId ? { adapterId, userId } : null; })();
|
|
19837
|
+
if (!actor && who !== HOST_ADMIN_KEY)
|
|
19838
|
+
return { kind: "wrong" };
|
|
19839
|
+
const outside = webOnly && exposureId !== undefined;
|
|
19840
|
+
return {
|
|
19841
|
+
kind: "ok",
|
|
19842
|
+
knownCookie: addSigninKnownDevice(this.webToken, input.knownCookie, who, enrollment, epoch, now),
|
|
19843
|
+
session: outside ? { remote: "totp" } : actor ? { owner: actor } : {},
|
|
19844
|
+
// Asked again as the session is made: the same app, still an admin, still allowed here.
|
|
19845
|
+
commit: (record, label) => {
|
|
19846
|
+
if (!this.totpSignInOpen(exposureId, peer) || store.enrollmentOf(who) !== enrollment)
|
|
19847
|
+
return false;
|
|
19848
|
+
if (actor ? this.adminGate(actor.userId, actor.adapterId) !== "ok" : !webOnly)
|
|
19849
|
+
return false;
|
|
19850
|
+
if (outside)
|
|
19851
|
+
return this.authorizeOutsideSession(record, peer, label);
|
|
19852
|
+
const name = actor ? this.webPerson({ adapterId: actor.adapterId, userId: actor.userId }).name : t("settings_confirm.host_operator_label");
|
|
19853
|
+
this.logger.info({ handle: record.handle, surface: record.surface }, "Web sign-in with an admin's authenticator code");
|
|
19854
|
+
this.postFleetSecurityNotice(t("signin.totp_notice_signed_in", name, label, t(exposureId === undefined ? "signin.totp_where_direct" : "signin.totp_where_link")));
|
|
19855
|
+
return true;
|
|
19856
|
+
},
|
|
19857
|
+
};
|
|
19858
|
+
}
|
|
19859
|
+
/** The platform handle (Discord / Telegram user name) an account last signed in to the web with, exactly as the platform gave it; undefined when none is known. */
|
|
19860
|
+
signinHandleOf(owner) {
|
|
19861
|
+
const handle = this.webPrefs.profile(webPersonKey(owner))?.platformName;
|
|
19862
|
+
return typeof handle === "string" && handle ? handle : undefined;
|
|
19863
|
+
}
|
|
19864
|
+
/** Where the new-device authenticator sign-in is open: the owner's knobs and the link rules in one place (asked again as the session is made). */
|
|
19865
|
+
totpSignInOpen(exposureId, peer) {
|
|
19866
|
+
// "Only this computer can authorize" closes this too: only this computer's own browser, never a link.
|
|
19867
|
+
if (this.webAuthorityState().loopbackOnly && (exposureId !== undefined || peer !== "loopback"))
|
|
19868
|
+
return false;
|
|
19869
|
+
if (exposureId === undefined)
|
|
19870
|
+
return true;
|
|
19871
|
+
if (this.isWebOnlyFleet())
|
|
19872
|
+
return this.outsideLink()?.exposureId === exposureId;
|
|
19873
|
+
return TOTP_SIGNIN_OVER_PUBLIC_LINK && this.publicWebLink?.openSignin()?.exposureId === exposureId;
|
|
19874
|
+
}
|
|
19875
|
+
/**
|
|
19876
|
+
* The admin a typed name stands for, among the chat admins that have an authenticator AND are still admins of their connection: by
|
|
19877
|
+
* the platform user name they sign in with (Discord / Telegram handle, no "@", any case), their user id, or `connection:id`. Exactly
|
|
19878
|
+
* one: a name two of them answer to is nobody's here (they use `connection:id`). The loop never stops early, so it takes as long
|
|
19879
|
+
* for a name that is nobody's. `ident` is the normalized text, for the limiter.
|
|
19880
|
+
*/
|
|
19881
|
+
resolveSignInAdmin(store, webOnly, account) {
|
|
19882
|
+
// A web-only fleet has one admin and one app: no name to give, nothing to tell apart.
|
|
19883
|
+
if (webOnly)
|
|
19884
|
+
return { who: store.isEnrolled(HOST_ADMIN_KEY) ? HOST_ADMIN_KEY : null, ident: "host" };
|
|
19885
|
+
const norm = (v) => (typeof v === "string" ? v.normalize("NFKC").trim().replace(/^@+/, "").toLowerCase().slice(0, 128) : "");
|
|
19886
|
+
const ident = norm(account), found = [];
|
|
19887
|
+
for (const key of store.adminKeys) {
|
|
19888
|
+
const [adapterId, userId] = key.split("\u0000");
|
|
19889
|
+
if (!adapterId || !userId)
|
|
19890
|
+
continue;
|
|
19891
|
+
let platformName = "";
|
|
19892
|
+
try {
|
|
19893
|
+
platformName = norm(this.signinHandleOf({ adapterId, userId }));
|
|
19894
|
+
}
|
|
19895
|
+
catch { /* no handle known: the id still works */ }
|
|
19896
|
+
const answers = [norm(userId), norm(`${adapterId}:${userId}`), platformName].includes(ident) && ident !== "";
|
|
19897
|
+
// Asked of every key, whether or not the name matches it: a name that belongs to a record does no more work than one that belongs to nobody.
|
|
19898
|
+
const admin = this.adminGate(userId, adapterId) === "ok";
|
|
19899
|
+
if (answers && admin)
|
|
19900
|
+
found.push(key);
|
|
19339
19901
|
}
|
|
19340
|
-
return {
|
|
19902
|
+
return { who: found.length === 1 ? found[0] : null, ident };
|
|
19341
19903
|
}
|
|
19342
19904
|
/**
|
|
19343
|
-
* #3008: a session just made by
|
|
19905
|
+
* #3008: a session just made by totpSignIn's "ok" over the outside link is this computer's admin for its authorization's life. False: it
|
|
19344
19906
|
* could not be admitted (its handle not saved, #3015 review r3) — the caller ends it.
|
|
19345
19907
|
*/
|
|
19346
19908
|
authorizeOutsideSession(session, peer, label) {
|
|
@@ -19424,7 +19986,7 @@ export class FleetManager {
|
|
|
19424
19986
|
* written), what fleet.yaml says, the hosts that make the dashboard reachable from elsewhere (the warning while
|
|
19425
19987
|
* loopback_only is off), and the sessions authorized now (§0): each one's device, account, and when it runs out.
|
|
19426
19988
|
*/
|
|
19427
|
-
webAuthorityOverview() {
|
|
19989
|
+
webAuthorityOverview(req) {
|
|
19428
19990
|
const configured = this.fleetConfig?.web?.verified_authority ?? {};
|
|
19429
19991
|
const lanHosts = (this.fleetConfig?.web?.allowed_hosts ?? []).filter(h => { const name = hostnameOf(String(h)); return name !== null && !LOOPBACK_HOST_NAMES.includes(name); });
|
|
19430
19992
|
const state = this.webAuthorityState(), maxMs = webAuthorityPolicy(this.fleetConfig?.web).maxSessionMs, now = Date.now();
|
|
@@ -19439,7 +20001,9 @@ export class FleetManager {
|
|
|
19439
20001
|
// Over a link: the temporary one (§0.3), else the named one (a record from before §0.3 has no peer).
|
|
19440
20002
|
...(sessions.get(a.handle).surface === "gateway" ? (a.peer === "quick_link" ? { quick: true } : { named: true }) : {}) })) : [];
|
|
19441
20003
|
const host = this.fleetConfig?.web?.public_link?.hostname;
|
|
19442
|
-
|
|
20004
|
+
const own = req ? authorizeSession(req, this.webToken, this.webSessions, { touch: false }) : null;
|
|
20005
|
+
return { you: { handle: own && own.kind === "ok" ? own.session.handle : null, canRevoke: !!req && !!this.webAuthorityRevoker(req) },
|
|
20006
|
+
state, configured, hours: VERIFIED_SESSION_HOURS, lanHosts, authorized, namedHost: typeof host === "string" && host ? host : null, webOnly: this.isWebOnlyFleet() };
|
|
19443
20007
|
}
|
|
19444
20008
|
authorizationRequests = null;
|
|
19445
20009
|
/**
|
|
@@ -19566,15 +20130,66 @@ export class FleetManager {
|
|
|
19566
20130
|
return { state: "pending", expiresInMs: pending.expiresInMs };
|
|
19567
20131
|
return { state: "none", reason: this.webAuthorityQualifies(input) ?? (verdict.refusal ?? "not_authorized") };
|
|
19568
20132
|
}
|
|
19569
|
-
/**
|
|
19570
|
-
|
|
20133
|
+
/**
|
|
20134
|
+
* #1939 §10: revoke every web authority given so far (receipts read as none), without signing anyone out.
|
|
20135
|
+
* AGEND-138: `keep` — the session that asked (the verified owner's own): the epoch still moves, so every other session
|
|
20136
|
+
* and every stored receipt is ended, but this one is authorized again under the new epoch at once (§3 asked afresh,
|
|
20137
|
+
* with the end it already had: a revocation never stretches an authorization). A host session only where it is
|
|
20138
|
+
* allowed to be one — on this computer — as at sign-in.
|
|
20139
|
+
*/
|
|
20140
|
+
revokeWebAuthority(keep) {
|
|
19571
20141
|
this.webAuthorityState(); // any switch change first, then this revocation
|
|
20142
|
+
const store = this.sessionAuthorizationStore();
|
|
20143
|
+
const prev = keep ? store?.get(keep.session.handle) ?? null : null;
|
|
19572
20144
|
const result = this.authorityStateStore?.revoke() ?? { epoch: 0, durable: false };
|
|
19573
20145
|
if (result.durable)
|
|
19574
20146
|
this.logger.info({ epoch: result.epoch }, "Web authority revoked");
|
|
19575
20147
|
else
|
|
19576
20148
|
this.logger.warn({ epoch: result.epoch }, "Web authority revoked in memory only — web authority stays off until its state can be written; a restart before then undoes this revocation");
|
|
19577
|
-
|
|
20149
|
+
let kept = false;
|
|
20150
|
+
if (keep && prev && store) {
|
|
20151
|
+
const now = Date.now(), epoch = this.webAuthorityState().epoch;
|
|
20152
|
+
const again = { ...prev, epoch };
|
|
20153
|
+
if (!this.webAuthority({ session: keep.session, gateway: keep.gateway, peer: keep.peer, authorization: again }).refusal) {
|
|
20154
|
+
const live = new Set(this.webSessions?.list(undefined, () => true).map(r => r.handle) ?? []);
|
|
20155
|
+
store.prune(a => a.handle === prev.handle && live.has(a.handle)); // every other authorization ends with the old epoch
|
|
20156
|
+
store.authorize(prev.handle, prev.owner, prev.authorizedAt, epoch, prev.until, prev.peer);
|
|
20157
|
+
kept = true;
|
|
20158
|
+
this.logger.info({ handle: prev.handle, at: now }, "Web authority revoked: the owner's own session kept");
|
|
20159
|
+
}
|
|
20160
|
+
}
|
|
20161
|
+
return { ...result, kept };
|
|
20162
|
+
}
|
|
20163
|
+
/**
|
|
20164
|
+
* AGEND-138: who may "Revoke authorization of other devices" — the verified owner only, asked of the LIVE session each
|
|
20165
|
+
* time. A web-only fleet: its owner (this computer's admin here, or signed in from outside). A fleet with a chat
|
|
20166
|
+
* connection: an admin session that is web-verified now (its account confirmed in Discord / Telegram) — the same §3
|
|
20167
|
+
* verdict the rest of web authority uses. A guest, a read-only session, an admin not verified (a device-code or one-time-code
|
|
20168
|
+
* sign-in), the header token: null. `revoke()` ends everyone else's and keeps this session verified.
|
|
20169
|
+
*/
|
|
20170
|
+
webAuthorityRevoker(req) {
|
|
20171
|
+
if (gatewayRequestContext(req))
|
|
20172
|
+
return null;
|
|
20173
|
+
const auth = authorizeSession(req, this.webToken, this.webSessions, { touch: false });
|
|
20174
|
+
if (auth.kind !== "ok" || auth.session.tier !== "admin")
|
|
20175
|
+
return null;
|
|
20176
|
+
const handle = auth.session.handle, peer = webPeerOf(req);
|
|
20177
|
+
const live = () => {
|
|
20178
|
+
const now = authorizeSession(req, this.webToken, this.webSessions, { touch: false });
|
|
20179
|
+
return now.kind === "ok" && now.session.handle === handle && now.session.tier === "admin" ? now.session : null;
|
|
20180
|
+
};
|
|
20181
|
+
const verified = () => {
|
|
20182
|
+
const session = live();
|
|
20183
|
+
if (!session)
|
|
20184
|
+
return false;
|
|
20185
|
+
if (this.isWebOnlyFleet())
|
|
20186
|
+
return !!this.liveOwner(req, { hostOnly: false })?.current();
|
|
20187
|
+
const v = this.webAuthority({ session, gateway: false, peer });
|
|
20188
|
+
return !v.refusal && v.authority.kind === "web-verified" && v.authority.session?.handle === handle;
|
|
20189
|
+
};
|
|
20190
|
+
if (!verified())
|
|
20191
|
+
return null;
|
|
20192
|
+
return { handle, current: verified, revoke: () => { const session = live(); return this.revokeWebAuthority(session ? { session, peer, gateway: false } : undefined); } };
|
|
19578
20193
|
}
|
|
19579
20194
|
/** #1269: an instance's chat command from the web chat (web-commands.ts); `publicLink`: a gateway request. */
|
|
19580
20195
|
/** #2855: the table scope of an instance the web chat may command (a fleet instance or a ClassicBot room), else null. */
|
|
@@ -19598,13 +20213,17 @@ export class FleetManager {
|
|
|
19598
20213
|
...(opts.guest ? { webGuest: true } : {}), // #2855: a guest's /steer or /btw reaches the agent as a guest's
|
|
19599
20214
|
};
|
|
19600
20215
|
};
|
|
19601
|
-
const choicesFromCache = (instance) => {
|
|
20216
|
+
const choicesFromCache = async (instance, more = false) => {
|
|
20217
|
+
if (isWindowsInstance(this.fleetConfig?.instances[instance])) {
|
|
20218
|
+
const catalog = await this.listModelCatalog({ instanceName: instance });
|
|
20219
|
+
return { current: catalog.current_model, options: catalog.models.map(m => ({ id: m.id, label: m.label })), actions: ["refresh"] };
|
|
20220
|
+
}
|
|
19602
20221
|
const backend = this.backendNameForInstance(instance);
|
|
19603
|
-
const
|
|
19604
|
-
if (!cached?.models.length)
|
|
19605
|
-
return null;
|
|
20222
|
+
const env = this.webModelEnv(backend, instance);
|
|
19606
20223
|
const current = this.resolveInstanceModel(instance).model;
|
|
19607
|
-
|
|
20224
|
+
const models = more ? this.modelCatalogFor(backend, instance) : env?.models ?? [];
|
|
20225
|
+
return { current, options: this.withCurrentModel(models, current).map(o => ({ id: o.id, label: this.modelChoiceLabel(o, current) })),
|
|
20226
|
+
actions: more ? ["refreshAll"] : backend === "claude-code" ? ["refresh", "more"] : ["refresh"] };
|
|
19608
20227
|
};
|
|
19609
20228
|
return runWebCommand({
|
|
19610
20229
|
scope: (instance) => this.webCommandScope(instance),
|
|
@@ -19628,6 +20247,31 @@ export class FleetManager {
|
|
|
19628
20247
|
},
|
|
19629
20248
|
applyModel: (instance, name) => this.applyModel(instance, name),
|
|
19630
20249
|
modelChoices: choicesFromCache,
|
|
20250
|
+
modelAction: async (instance, command, args, action, actionOpts) => {
|
|
20251
|
+
const tokens = backendArgs(args);
|
|
20252
|
+
if ((command === "model" && args) || (command === "backend" && (tokens.length !== 1 || action !== "refresh")))
|
|
20253
|
+
return { error: t("menu.click_stale") };
|
|
20254
|
+
const backend = command === "model" ? this.backendNameForInstance(instance) : tokens[0];
|
|
20255
|
+
if (command === "backend") {
|
|
20256
|
+
const refusal = this.backendCommandRefusal(instance);
|
|
20257
|
+
if (refusal)
|
|
20258
|
+
return { error: refusal };
|
|
20259
|
+
const step = await backendStep(this.backendCommandDeps(instance, { live: false }), instance, tokens);
|
|
20260
|
+
if (step.kind !== "choose" || step.step !== "model")
|
|
20261
|
+
return { error: step.kind === "refuse" ? step.text : t("menu.click_stale") };
|
|
20262
|
+
}
|
|
20263
|
+
if (action === "more" && backend !== "claude-code")
|
|
20264
|
+
return { error: t("menu.click_stale") };
|
|
20265
|
+
if (action !== "more" || !this.webModelEnv(backend, instance)?.apiModels?.length) {
|
|
20266
|
+
const result = await this.refreshModelCatalogFor(backend, instance);
|
|
20267
|
+
if (!result.refreshed)
|
|
20268
|
+
return { error: t("model.refresh_failed") };
|
|
20269
|
+
}
|
|
20270
|
+
if (command === "model")
|
|
20271
|
+
return { choices: await choicesFromCache(instance, action !== "refresh") };
|
|
20272
|
+
// Re-enter the shared backend→model→effort→confirm flow; no configuration write during refresh.
|
|
20273
|
+
return this.webCommand({ instance, command: "backend", args }, { ...opts, publicLink: actionOpts.publicLink }).then(r => r.body);
|
|
20274
|
+
},
|
|
19631
20275
|
applyEffort: (instance, level) => this.applyEffort(instance, level),
|
|
19632
20276
|
effortChoices: (instance) => {
|
|
19633
20277
|
const levels = this.effortLevelsFor(instance);
|
|
@@ -19641,12 +20285,12 @@ export class FleetManager {
|
|
|
19641
20285
|
if (refusal)
|
|
19642
20286
|
return { error: refusal };
|
|
19643
20287
|
// The cached model lists only, as the web's /model: never a live probe on this path.
|
|
19644
|
-
const step = await backendStep(this.backendCommandDeps(instance, { live: false }), instance, backendArgs(args));
|
|
20288
|
+
const step = await backendStep({ ...this.backendCommandDeps(instance, { live: false }), models: async (backend) => this.modelCatalogFor(backend, instance) }, instance, backendArgs(args));
|
|
19645
20289
|
if (step.kind === "refuse")
|
|
19646
20290
|
return step.noop ? { text: step.text } : { error: step.text };
|
|
19647
20291
|
if (step.kind === "choose") {
|
|
19648
20292
|
const id = (token) => joinBackendArgs([...step.args, token]);
|
|
19649
|
-
return { choices: { prompt: step.text, current: step.current === null ? null : id(step.current), options: step.choices.map(c => {
|
|
20293
|
+
return { choices: { step: step.step, args: joinBackendArgs(step.args), ...(step.step === "model" ? { actions: ["refresh"] } : {}), prompt: step.text, current: step.current === null ? null : id(step.current), options: step.choices.map(c => {
|
|
19650
20294
|
// #2233: the web offers Sign in beside it, so its reason is no longer "use /login".
|
|
19651
20295
|
// Not over the public link: Sign in is refused there, so the choice keeps its "(use /login)" (#2262 review).
|
|
19652
20296
|
const signIn = c.signIn && !stepOpts?.publicLink && dashboardSignInSupported(c.signIn) ? c.signIn : null;
|
|
@@ -21360,7 +22004,8 @@ export class FleetManager {
|
|
|
21360
22004
|
this.logger.debug({ err: err.message }, "Computer accounts not read");
|
|
21361
22005
|
}
|
|
21362
22006
|
}
|
|
21363
|
-
return buildAccountsView({ targets, diskProfiles, agents, classic, fleetDefaults, usage, shortUsage: shortWindow, keepAlive, machines
|
|
22007
|
+
return buildAccountsView({ targets, diskProfiles, agents, classic, fleetDefaults, usage, shortUsage: shortWindow, keepAlive, machines, installShown: this.webHostInstalls.view()?.backend ?? null,
|
|
22008
|
+
versions: new Map(this.backendAvailabilityRows().map(row => [row.backend, row.version ?? null])) });
|
|
21364
22009
|
}
|
|
21365
22010
|
/**
|
|
21366
22011
|
* A sign-in just finished for this account: look at its Keep sign-in alive setting once now (when it is on), so what the Accounts row says about
|
|
@@ -22369,39 +23014,6 @@ export class FleetManager {
|
|
|
22369
23014
|
}
|
|
22370
23015
|
if (!claim)
|
|
22371
23016
|
return this.loginWindow.busyMessage();
|
|
22372
|
-
let tmux;
|
|
22373
|
-
try {
|
|
22374
|
-
const sessionName = getTmuxSession();
|
|
22375
|
-
await TmuxManager.ensureSession(sessionName);
|
|
22376
|
-
if (!this.loginWindow.isCurrent(claim)) {
|
|
22377
|
-
this.loginWindow.release(claim);
|
|
22378
|
-
return t("login.web_shutting_down");
|
|
22379
|
-
}
|
|
22380
|
-
tmux = new TmuxManager(sessionName, "");
|
|
22381
|
-
}
|
|
22382
|
-
catch (err) {
|
|
22383
|
-
this.loginWindow.release(claim);
|
|
22384
|
-
return t("install.failed", backend, err.message);
|
|
22385
|
-
}
|
|
22386
|
-
// A synthetic flow: success is decided by the installer's exit code
|
|
22387
|
-
// (LoginSession treats a clean exit as success), never by pane text. The
|
|
22388
|
-
// session only judges that verdict; it does not read the output for URLs or prompts.
|
|
22389
|
-
// M-2281 (#2980): no terminal to ask on, low priority, stoppable as a whole, the user's own $SHELL — see
|
|
22390
|
-
// unattended-install.ts. A prompt nobody can answer fails at once instead of waiting out the timeout.
|
|
22391
|
-
const shell = (await loginShell()) ?? null;
|
|
22392
|
-
if (!this.loginWindow.isCurrent(claim)) {
|
|
22393
|
-
this.loginWindow.release(claim);
|
|
22394
|
-
return t("login.web_shutting_down");
|
|
22395
|
-
}
|
|
22396
|
-
// The wrapper says its own exit code after this marker: tmux may never record it (unattended-install.ts).
|
|
22397
|
-
const exitMarker = installExitMarker();
|
|
22398
|
-
const flow = {
|
|
22399
|
-
backend,
|
|
22400
|
-
command: unattendedInstallCommand(info.unattended ?? info.install, shell, exitMarker),
|
|
22401
|
-
exitMarker,
|
|
22402
|
-
successPattern: /$^/,
|
|
22403
|
-
timeoutMs: this.installTimeoutMs,
|
|
22404
|
-
};
|
|
22405
23017
|
// M-2281: the installer's output, live, in the chat that asked — no page shows this window.
|
|
22406
23018
|
// Telegram gets its own <pre> (its markdown conversion keeps a fence as literal backticks); others a fenced block.
|
|
22407
23019
|
const frameStyle = chat.adapter.type === "telegram" ? "html" : "markdown";
|
|
@@ -22411,7 +23023,7 @@ export class FleetManager {
|
|
|
22411
23023
|
warn: (message, err) => this.logger.debug({ backend, err: err?.message ?? String(err) }, message),
|
|
22412
23024
|
}, t("install.stream_running", backend), undefined, undefined, frameStyle);
|
|
22413
23025
|
const minutes = String(Math.max(1, Math.round(this.installTimeoutMs / 60_000)));
|
|
22414
|
-
const
|
|
23026
|
+
const opened = await this.openInstallWindow(backend, info, claim, {
|
|
22415
23027
|
onProgress: pane => stream.update(pane),
|
|
22416
23028
|
onDone: async ({ ok, detail, cleanupFailed }) => {
|
|
22417
23029
|
this.activeInstall = null;
|
|
@@ -22444,7 +23056,7 @@ export class FleetManager {
|
|
|
22444
23056
|
// fresh login shell sees that, the fleet process's PATH may not.
|
|
22445
23057
|
// #3009 (leader, cid-3017-3029-overlap): both lookups off the fleet's main thread — the login shell's own check,
|
|
22446
23058
|
// then the installer's own directories through backend-availability's check (a killable child tests each one).
|
|
22447
|
-
const installedAt =
|
|
23059
|
+
const installedAt = await this.locateInstalledCli(backend, info.binary);
|
|
22448
23060
|
if (handoff.cancelled || this.installHandoff !== handoff)
|
|
22449
23061
|
return;
|
|
22450
23062
|
if (!installedAt) {
|
|
@@ -22485,29 +23097,217 @@ export class FleetManager {
|
|
|
22485
23097
|
.catch(err => this.logger.warn({ err, backend }, "Could not post the sign-in step after an install"));
|
|
22486
23098
|
}
|
|
22487
23099
|
},
|
|
22488
|
-
}
|
|
22489
|
-
|
|
23100
|
+
});
|
|
23101
|
+
if ("failure" in opened) {
|
|
23102
|
+
if (opened.failure === "shutting_down")
|
|
23103
|
+
return t("login.web_shutting_down");
|
|
23104
|
+
if (opened.failure === "cancelled")
|
|
23105
|
+
return this.loginWindow.isClosed ? t("login.web_shutting_down") : t("install.cancelled", backend);
|
|
23106
|
+
const text = t("install.failed", backend, opened.message);
|
|
23107
|
+
return opened.cleanupFailed ? `${text}\n${t("login.web_cleanup_failed", backend)}` : text;
|
|
23108
|
+
}
|
|
23109
|
+
return t("install.started", backend);
|
|
23110
|
+
}
|
|
23111
|
+
/**
|
|
23112
|
+
* The install window itself, for `/login`'s chat install and the dashboard's Install button alike (AGEND-133): a tmux window running the registry's
|
|
23113
|
+
* command through `unattendedInstallCommand` (no terminal to ask on, low priority, stoppable as a whole, the user's own $SHELL), judged by the installer's
|
|
23114
|
+
* own exit code. The caller holds `claim` (taken before its first await) and gets it released here on every failure; once the session is running,
|
|
23115
|
+
* `events.onDone` owns the release. `activeInstall` is set while it runs, so `/login cancel`, the dashboard's Cancel and a fleet stop all reach it.
|
|
23116
|
+
*/
|
|
23117
|
+
async openInstallWindow(backend, info, claim, events, execution) {
|
|
23118
|
+
let tmux;
|
|
23119
|
+
try {
|
|
23120
|
+
const sessionName = getTmuxSession();
|
|
23121
|
+
await TmuxManager.ensureSession(sessionName);
|
|
23122
|
+
execution?.assert();
|
|
23123
|
+
if (!this.loginWindow.isCurrent(claim)) {
|
|
23124
|
+
this.loginWindow.release(claim);
|
|
23125
|
+
return { failure: "shutting_down" };
|
|
23126
|
+
}
|
|
23127
|
+
tmux = new TmuxManager(sessionName, "");
|
|
23128
|
+
}
|
|
23129
|
+
catch (err) {
|
|
23130
|
+
this.loginWindow.release(claim);
|
|
23131
|
+
return { failure: "start", message: err.message, cleanupFailed: false };
|
|
23132
|
+
}
|
|
23133
|
+
// A synthetic flow: success is decided by the installer's exit code
|
|
23134
|
+
// (LoginSession treats a clean exit as success), never by pane text. The
|
|
23135
|
+
// session only judges that verdict; it does not read the output for URLs or prompts.
|
|
23136
|
+
// M-2281 (#2980): no terminal to ask on, low priority, stoppable as a whole, the user's own $SHELL — see
|
|
23137
|
+
// unattended-install.ts. A prompt nobody can answer fails at once instead of waiting out the timeout.
|
|
23138
|
+
const shell = (await loginShell()) ?? null;
|
|
23139
|
+
if (!this.loginWindow.isCurrent(claim) || (execution && !execution.current())) {
|
|
23140
|
+
this.loginWindow.release(claim);
|
|
23141
|
+
return { failure: "shutting_down" };
|
|
23142
|
+
}
|
|
23143
|
+
// The wrapper says its own exit code after this marker: tmux may never record it (unattended-install.ts).
|
|
23144
|
+
const exitMarker = installExitMarker();
|
|
23145
|
+
const flow = {
|
|
23146
|
+
backend,
|
|
23147
|
+
command: unattendedInstallCommand(info.unattended ?? info.install, shell, exitMarker),
|
|
23148
|
+
exitMarker,
|
|
23149
|
+
successPattern: /$^/,
|
|
23150
|
+
timeoutMs: this.installTimeoutMs,
|
|
23151
|
+
};
|
|
23152
|
+
const session = new LoginSession(flow, tmux, events, this.logger);
|
|
23153
|
+
this.activeInstall = { session, backend };
|
|
22490
23154
|
try {
|
|
22491
|
-
|
|
23155
|
+
// Admission ends at the actual tmux command dispatch, after its own asynchronous preparation.
|
|
23156
|
+
if (execution)
|
|
23157
|
+
await session.start(() => execution.complete());
|
|
23158
|
+
else
|
|
23159
|
+
await session.start();
|
|
22492
23160
|
}
|
|
22493
23161
|
catch (err) {
|
|
22494
23162
|
this.activeInstall = null;
|
|
22495
23163
|
this.loginWindow.release(claim);
|
|
22496
|
-
|
|
22497
|
-
return err.cleanupFailed ? `${text}\n${t("login.web_cleanup_failed", backend)}` : text;
|
|
23164
|
+
return { failure: "start", message: err.message, cleanupFailed: !!err.cleanupFailed };
|
|
22498
23165
|
}
|
|
22499
23166
|
if (session.state === "done") {
|
|
22500
23167
|
this.activeInstall = null;
|
|
22501
23168
|
this.loginWindow.release(claim);
|
|
22502
|
-
return
|
|
23169
|
+
return { failure: "cancelled" };
|
|
22503
23170
|
}
|
|
22504
23171
|
if (!this.loginWindow.isCurrent(claim)) {
|
|
22505
23172
|
await session.cancel("cancelled").catch(() => { });
|
|
22506
23173
|
this.activeInstall = null;
|
|
22507
23174
|
this.loginWindow.release(claim);
|
|
22508
|
-
return
|
|
23175
|
+
return { failure: "shutting_down" };
|
|
22509
23176
|
}
|
|
22510
|
-
return
|
|
23177
|
+
return { session };
|
|
23178
|
+
}
|
|
23179
|
+
/** AGEND-133: the dashboard's Install button — what the Accounts page asks of `/login`'s install, with no chat to report in. */
|
|
23180
|
+
webHostInstallsInstance = null;
|
|
23181
|
+
get webHostInstalls() {
|
|
23182
|
+
this.webHostInstallsInstance ??= new WebHostInstalls({
|
|
23183
|
+
isLocalAdmin: handle => this.isLocalAdminSession(handle),
|
|
23184
|
+
installable: backend => !isRemovedBackend(backend) && !!BACKEND_INSTALLATION_INFO[backend],
|
|
23185
|
+
updatable: backend => !isRemovedBackend(backend) && !!BACKEND_INSTALLATION_INFO[backend] && !!hostUpdatePlan(backend),
|
|
23186
|
+
start: (backend, reporter, execution, mode) => this.startWebInstall(backend, reporter, execution, mode),
|
|
23187
|
+
cancel: async () => { if (!this.activeInstall)
|
|
23188
|
+
return false; await this.cancelInstallSession(); return true; },
|
|
23189
|
+
// No details in the event: each page reads GET /ui/host-install. The Accounts list reads itself again on the same event (the CLI is installed now).
|
|
23190
|
+
changed: () => { broadcastSseEvent(this.sseClients, "backend_login", {}, err => this.logger.debug({ err }, "backend_login event failed")); },
|
|
23191
|
+
});
|
|
23192
|
+
return this.webHostInstallsInstance;
|
|
23193
|
+
}
|
|
23194
|
+
/**
|
|
23195
|
+
* AGEND-133: install a CLI for the dashboard. Only the CLI's id arrives (the caller validated it against the registry's table); the command is
|
|
23196
|
+
* `info.unattended ?? info.install` read here, the window and its judgement are `/login`'s (openInstallWindow). The verdict is then checked the way chat's
|
|
23197
|
+
* is — a fresh login shell, else the installer's own directories — and the availability probe reads the version for the page. Everything is
|
|
23198
|
+
* reported through `reporter`; nothing is posted to any chat, and no sign-in is started (the page offers Sign in itself).
|
|
23199
|
+
*/
|
|
23200
|
+
async startWebInstall(backendArg, reporter, execution, mode = "install") {
|
|
23201
|
+
execution?.assert();
|
|
23202
|
+
const backend = LOGIN_BACKEND_ALIASES[backendArg.toLowerCase()] ?? backendArg.toLowerCase();
|
|
23203
|
+
const base = BACKEND_INSTALLATION_INFO[backend];
|
|
23204
|
+
if (!base || isRemovedBackend(backend))
|
|
23205
|
+
return { refused: "unsupported" };
|
|
23206
|
+
// AGEND-136: an update runs the registry's `host.update` command with the audited release in it (hostUpdatePlan); the window, its judgement and its release are the install's.
|
|
23207
|
+
const plan = mode === "update" ? hostUpdatePlan(backend) : null;
|
|
23208
|
+
if (mode === "update" && !plan)
|
|
23209
|
+
return { refused: "unsupported" };
|
|
23210
|
+
const info = plan ? { install: plan.command } : base;
|
|
23211
|
+
// The fleet-wide window, claimed before the first await (shared with /login, chat's install and sign-in).
|
|
23212
|
+
const claim = this.loginWindow.tryClaim("install", backend);
|
|
23213
|
+
if (!claim)
|
|
23214
|
+
return { refused: this.loginWindow.isClosed ? "shutting_down" : "busy" };
|
|
23215
|
+
// #3542 / AGEND-144 (Prism on #3539): the claim is a lock, not the asker's authority. The confirmed change's own execution (its session, role, confirmation and the settings it was held
|
|
23216
|
+
// against) is asked again after each wait (the binary check, the version refresh), and its admission ends at the tmux command that starts the installer (openInstallWindow → `launch`).
|
|
23217
|
+
const asker = () => { try {
|
|
23218
|
+
return !execution || execution.current();
|
|
23219
|
+
}
|
|
23220
|
+
catch {
|
|
23221
|
+
return false;
|
|
23222
|
+
} };
|
|
23223
|
+
const present = await checkBinaryInstalledAsync(base.binary);
|
|
23224
|
+
if (mode === "install" && present) {
|
|
23225
|
+
this.loginWindow.release(claim);
|
|
23226
|
+
return { refused: "already" };
|
|
23227
|
+
}
|
|
23228
|
+
// An update needs the CLI where the Accounts page found it: on the fleet's PATH, else (a fresh login shell, then) the installer's own directories (~/.grok/bin, ~/.opencode/bin …).
|
|
23229
|
+
if (mode === "update" && !present && !(await this.locateInstalledCli(backend, base.binary).catch(() => null))) {
|
|
23230
|
+
this.loginWindow.release(claim);
|
|
23231
|
+
return { refused: "not_installed" };
|
|
23232
|
+
}
|
|
23233
|
+
if (!asker()) {
|
|
23234
|
+
this.loginWindow.release(claim);
|
|
23235
|
+
return { refused: "failed" };
|
|
23236
|
+
}
|
|
23237
|
+
let versionBefore = null;
|
|
23238
|
+
if (plan) {
|
|
23239
|
+
// The version the page shows as "before" is the binary probe's own, read now (not the last snapshot), and an update only starts when the CLI is really behind the audited release.
|
|
23240
|
+
// AGEND-144 (Prism on #3539, P2-3): that reading must be FRESH, SUCCESSFUL and of the executable that resolves now. The published row is not enough: a forced refresh keeps the previous
|
|
23241
|
+
// version when the new probe fails for the same path (right for the pickers, which fail open), so a replaced binary whose version cannot be read would still carry the old
|
|
23242
|
+
// number and an update to an older release would be accepted. Unreadable refuses. (The published row is refreshed too, as before, for the pickers and the page.)
|
|
23243
|
+
// AGEND-148 (Prism R3 on #3539, P2-3): the admission's reading comes AFTER the other awaited preparation (the forced refresh publishes a probe of its own), so it is the newest
|
|
23244
|
+
// observation — a version published while this update was being prepared is never discarded for an earlier one.
|
|
23245
|
+
await this.backendAvailability.refresh([backend], { force: true }).catch(() => { });
|
|
23246
|
+
const fresh = await this.backendAvailability.freshVersion(backend).catch(() => null);
|
|
23247
|
+
versionBefore = fresh?.version ?? null;
|
|
23248
|
+
if (!this.loginWindow.isCurrent(claim)) {
|
|
23249
|
+
this.loginWindow.release(claim);
|
|
23250
|
+
return { refused: "shutting_down" };
|
|
23251
|
+
}
|
|
23252
|
+
if (!asker()) {
|
|
23253
|
+
this.loginWindow.release(claim);
|
|
23254
|
+
return { refused: "failed" };
|
|
23255
|
+
}
|
|
23256
|
+
if (!fresh) {
|
|
23257
|
+
this.loginWindow.release(claim);
|
|
23258
|
+
return { refused: "version_unreadable" };
|
|
23259
|
+
}
|
|
23260
|
+
// AGEND-153: the named exception (`release: "latest-unaudited"`) is offered at any readable version (it goes to the vendor's newest, not to our audited release), so "behind" does not decide it.
|
|
23261
|
+
if (cliUpdateView(backend, versionBefore, true, plan.target === null)?.button !== true) {
|
|
23262
|
+
this.loginWindow.release(claim);
|
|
23263
|
+
return { refused: "up_to_date" };
|
|
23264
|
+
}
|
|
23265
|
+
try {
|
|
23266
|
+
reporter.update?.(versionOf(versionBefore), plan.target);
|
|
23267
|
+
}
|
|
23268
|
+
catch { /* a view never stops the update */ }
|
|
23269
|
+
}
|
|
23270
|
+
else
|
|
23271
|
+
this.recordLoginFlow(backend, "install_only", "web");
|
|
23272
|
+
const opened = await this.openInstallWindow(backend, info, claim, {
|
|
23273
|
+
onProgress: pane => { try {
|
|
23274
|
+
reporter.progress(pane);
|
|
23275
|
+
}
|
|
23276
|
+
catch { /* a view never stops the install */ } },
|
|
23277
|
+
onDone: async ({ ok, detail, cleanupFailed }) => {
|
|
23278
|
+
this.activeInstall = null;
|
|
23279
|
+
this.loginWindow.release(claim);
|
|
23280
|
+
let verified = false, version = null;
|
|
23281
|
+
if (ok) {
|
|
23282
|
+
// The installer may only have added the binary to a profile PATH; a fresh login shell sees that, the fleet's own PATH may not.
|
|
23283
|
+
const installedAt = await this.locateInstalledCli(backend, base.binary).catch(() => null);
|
|
23284
|
+
if (installedAt) {
|
|
23285
|
+
verified = true;
|
|
23286
|
+
this.adoptBinaryDirectory(installedAt, backend);
|
|
23287
|
+
// The binary probe: the same refresh that makes the pickers know it (#2072) — awaited here, for the version the page shows.
|
|
23288
|
+
await this.backendAvailability.refresh([backend], { force: true }).catch(() => { });
|
|
23289
|
+
version = this.backendAvailabilityRows().find(row => row.backend === backend)?.version ?? null;
|
|
23290
|
+
}
|
|
23291
|
+
}
|
|
23292
|
+
this.logger.info({ backend, mode, ok, verified, ...(plan ? { to: plan.target } : {}), ...(ok ? {} : { detail }) }, mode === "update" ? "Dashboard update ended" : "Dashboard install ended");
|
|
23293
|
+
try {
|
|
23294
|
+
reporter.done({ ok, detail, cleanupFailed, verified, version, signIn: !!LOGIN_FLOWS[backend] && dashboardSignInSupported(backend) });
|
|
23295
|
+
}
|
|
23296
|
+
catch { /* a view never stops the install */ }
|
|
23297
|
+
},
|
|
23298
|
+
}, execution);
|
|
23299
|
+
if ("failure" in opened) {
|
|
23300
|
+
if (opened.failure === "shutting_down")
|
|
23301
|
+
return { refused: "shutting_down" };
|
|
23302
|
+
if (opened.failure === "cancelled")
|
|
23303
|
+
return { refused: this.loginWindow.isClosed ? "shutting_down" : "failed", message: "cancelled" };
|
|
23304
|
+
return { refused: "failed", message: opened.message };
|
|
23305
|
+
}
|
|
23306
|
+
return { started: true };
|
|
23307
|
+
}
|
|
23308
|
+
/** A fresh login shell's answer for `binary`, else the installer's own directories (see locateBinaryOnLoginShell / locateInstalledBackend). */
|
|
23309
|
+
async locateInstalledCli(backend, binary) {
|
|
23310
|
+
return (await this.locateBinaryOnLoginShell(binary)) ?? (await this.locateInstalledBackend(backend));
|
|
22511
23311
|
}
|
|
22512
23312
|
/** Whether this backend's CLI is on the fleet's PATH (what `/login` installs when it is not). */
|
|
22513
23313
|
isCliInstalled(backend) {
|
|
@@ -23718,7 +24518,7 @@ export class FleetManager {
|
|
|
23718
24518
|
/** #1806: null on a switch INTO claude-code — the configured model then belongs to the backend being left. */
|
|
23719
24519
|
configured = this.fleetConfig?.instances[instanceName]?.model ?? this.fleetConfig?.defaults?.model) {
|
|
23720
24520
|
const aliases = ["default", "sonnet", "opus", "haiku", "opusplan", "Fable"];
|
|
23721
|
-
const api = (this.
|
|
24521
|
+
const api = (this.webModelEnv("claude-code", instanceName)?.apiModels ?? []).map(m => m.id);
|
|
23722
24522
|
const lower = model.trim().toLowerCase();
|
|
23723
24523
|
const bare = lower.replace(/\[1m\]$/, "");
|
|
23724
24524
|
const known = aliases.some(a => a.toLowerCase() === bare)
|
|
@@ -23861,6 +24661,8 @@ export class FleetManager {
|
|
|
23861
24661
|
this.pendingCliEnvProbes.clear();
|
|
23862
24662
|
this.pendingVendorCliEnvProbes.clear();
|
|
23863
24663
|
this.pendingInstanceModelProbes.clear();
|
|
24664
|
+
this.webModelRefreshes.clear();
|
|
24665
|
+
this.webModelCatalogs.clear();
|
|
23864
24666
|
}
|
|
23865
24667
|
runBackendProbeWorker(key, input) {
|
|
23866
24668
|
if (this.shuttingDown)
|
|
@@ -24034,20 +24836,37 @@ export class FleetManager {
|
|
|
24034
24836
|
// indefinitely — each is wrapped by CLI_ENV_PROBE_DEADLINE_MS.
|
|
24035
24837
|
for (const b of backends)
|
|
24036
24838
|
void this.probeBackendBounded(b);
|
|
24037
|
-
|
|
24038
|
-
|
|
24039
|
-
|
|
24839
|
+
this.probeChangedCliEnvs(null);
|
|
24840
|
+
}
|
|
24841
|
+
/** Maintain discovery after committed config changes; a model-field read remains passive. */
|
|
24842
|
+
probeChangedCliEnvs(previous) {
|
|
24843
|
+
const signature = (fleet, name) => {
|
|
24844
|
+
const inst = fleet?.instances[name];
|
|
24845
|
+
if (!inst)
|
|
24846
|
+
return null;
|
|
24847
|
+
const backend = inst.backend ?? fleet?.defaults?.backend ?? "claude-code";
|
|
24848
|
+
return JSON.stringify({ backend, options: { ...fleet?.defaults?.backend_options?.[backend], ...inst.backend_options?.[backend] } });
|
|
24849
|
+
};
|
|
24040
24850
|
for (const name of Object.keys(this.fleetConfig?.instances ?? {})) {
|
|
24041
24851
|
if (isWindowsInstance(this.fleetConfig?.instances[name]))
|
|
24042
24852
|
continue;
|
|
24043
|
-
|
|
24853
|
+
const backend = this.backendNameForInstance(name);
|
|
24854
|
+
const binding = this.webModelBinding(backend, name);
|
|
24855
|
+
// A named agy account has no verified relocation/discovery contract. In particular,
|
|
24856
|
+
// never publish the ambient account's models under that profile (#3526 / D7).
|
|
24857
|
+
if (!binding || (binding.profile && !credentialHomeSpec(backend)))
|
|
24858
|
+
continue;
|
|
24859
|
+
// A description/defaults save can retire a scoped answer's full binding even
|
|
24860
|
+
// though its account signature is unchanged. Keep the conservative fence and
|
|
24861
|
+
// re-arm the current binding, unless its answer or flight is already present.
|
|
24862
|
+
if (previous && signature(previous, name) === signature(this.fleetConfig, name)
|
|
24863
|
+
&& (!binding.scoped || this.webModelEnv(backend, name) || this.webModelRefreshes.has(binding.key)))
|
|
24044
24864
|
continue;
|
|
24045
|
-
const
|
|
24046
|
-
|
|
24047
|
-
|
|
24865
|
+
const work = binding.scoped
|
|
24866
|
+
? this.refreshModelCatalogFor(backend, name)
|
|
24867
|
+
: this.probeBackendBounded(backend, { profile: binding.profile });
|
|
24868
|
+
void work.catch(err => this.logger.debug({ backend, name, err }, "Background model discovery failed"));
|
|
24048
24869
|
}
|
|
24049
|
-
for (const profile of profiles)
|
|
24050
|
-
void this.probeBackendBounded("claude-code", { profile });
|
|
24051
24870
|
}
|
|
24052
24871
|
/** Best-effort model list for `/model`: cached CLI env first, else live probe. Never throws. */
|
|
24053
24872
|
async getModelOptions(instanceName, refresh = false, onLiveProbe) {
|
|
@@ -24125,9 +24944,11 @@ export class FleetManager {
|
|
|
24125
24944
|
inventory = await this.runtimeWindowsExecutor().probe({ force: false, machineId: config.machine_id });
|
|
24126
24945
|
}
|
|
24127
24946
|
catch { /* offline remains unavailable */ }
|
|
24947
|
+
const refreshed = cachedNativeModelCatalog(this, { backend, instance: instanceName });
|
|
24948
|
+
const profile = config.backend_options?.[backend]?.credential_profile || (backend === "claude-code" ? inventory?.credentialProfiles?.default : undefined);
|
|
24128
24949
|
const row = inventory?.clis.find(value => value.id === backend);
|
|
24129
24950
|
return { backend, scope: "instance", instance: instanceName, current_model: config.model || null,
|
|
24130
|
-
models: (row?.models ?? []).map(value => ({ id: value.id, label: value.name ?? value.id, ...(value.description ? { description: value.description } : {}) })),
|
|
24951
|
+
models: refreshed?.models ?? (profile ? [] : row?.models ?? []).map(value => ({ id: value.id, label: value.name ?? value.id, ...(value.description ? { description: value.description } : {}) })),
|
|
24131
24952
|
source: row?.models?.length ? "cache" : "fallback",
|
|
24132
24953
|
...(inventory?.probedAt ? { probed_at: new Date(inventory.probedAt).toISOString() } : {}),
|
|
24133
24954
|
note: "Windows runtime's last detected inventory; no coordinator account or live probe is used." };
|
|
@@ -25001,7 +25822,7 @@ export class FleetManager {
|
|
|
25001
25822
|
currentBackend: (name) => this.backendNameForInstance(name),
|
|
25002
25823
|
currentDisplay: (name) => `${this.backendNameForInstance(name)} · ${this.resolveInstanceModel(name).display}`,
|
|
25003
25824
|
availability: () => this.backendAvailabilityFor(instanceName),
|
|
25004
|
-
models: (backend) => this.backendModelOptions(backend, opts),
|
|
25825
|
+
models: (backend) => this.backendModelOptions(backend, { ...opts, instance: instanceName }),
|
|
25005
25826
|
// #1808: the same rule update_instance_config's switch applies (backendModelVerdict).
|
|
25006
25827
|
modelKnown: (backend, model) => this.backendModelVerdict(instanceName, backend, model).ok,
|
|
25007
25828
|
effortLevels: (backend, model) => this.backendEffortLevels(instanceName, backend, model),
|
|
@@ -25056,7 +25877,7 @@ export class FleetManager {
|
|
|
25056
25877
|
// review): only the launch-line rule applies — never the account's list or the default provider's naming pattern.
|
|
25057
25878
|
if (opts.provider)
|
|
25058
25879
|
return modelNameCarried(backend, model) ? { ok: true } : { ok: false, choices: [] };
|
|
25059
|
-
const listed = this.
|
|
25880
|
+
const listed = this.webModelEnv(backend, instanceName)?.models ?? [];
|
|
25060
25881
|
const choices = listed.slice(0, 24).map(o => o.id);
|
|
25061
25882
|
if (!modelNameCarried(backend, model))
|
|
25062
25883
|
return { ok: false, choices };
|
|
@@ -25110,21 +25931,85 @@ export class FleetManager {
|
|
|
25110
25931
|
* #2072 part 3: the models a Settings field offers for `backend` — the cached catalog (an instance's own credential
|
|
25111
25932
|
* profile's, when it is named and has one), claude's account catalog included. Read only: never a probe.
|
|
25112
25933
|
*/
|
|
25113
|
-
|
|
25114
|
-
|
|
25115
|
-
|
|
25934
|
+
webModelTargetIds = new WeakMap();
|
|
25935
|
+
webModelTargetSequence = 0;
|
|
25936
|
+
webModelCatalogs = new Map();
|
|
25937
|
+
webModelRefreshes = new Map();
|
|
25938
|
+
/** Resolve only trusted config; the browser never supplies a home, provider URL or credentials. */
|
|
25939
|
+
webModelBinding(backend, instance, selection) {
|
|
25940
|
+
this.webModelTargetIds ??= new WeakMap();
|
|
25941
|
+
this.webModelTargetSequence ??= 0;
|
|
25942
|
+
this.webModelCatalogs ??= new Map();
|
|
25943
|
+
this.webModelRefreshes ??= new Map();
|
|
25116
25944
|
if (!KNOWN_BACKENDS.includes(backend) || backend === "mock")
|
|
25117
|
-
return
|
|
25118
|
-
const
|
|
25119
|
-
|
|
25120
|
-
const
|
|
25121
|
-
|
|
25122
|
-
|
|
25123
|
-
|
|
25124
|
-
|
|
25125
|
-
|
|
25126
|
-
|
|
25127
|
-
|
|
25945
|
+
return null;
|
|
25946
|
+
const instances = this.fleetConfig?.instances ?? {};
|
|
25947
|
+
const own = instance && Object.hasOwn(instances, instance) ? instances[instance] : null;
|
|
25948
|
+
const classic = instance && !own ? this.classicChannels?.getAll().find(c => c.instanceName === instance) : null;
|
|
25949
|
+
if (instance && !own && !classic || own && isWindowsInstance(own))
|
|
25950
|
+
return null;
|
|
25951
|
+
const options = { ...this.fleetConfig?.defaults?.backend_options?.[backend], ...(own?.backend_options?.[backend] ?? (instance ? this.classicChannels?.getBackendOptionsByInstance(instance)?.[backend] : undefined)) };
|
|
25952
|
+
if (selection?.profile !== undefined) {
|
|
25953
|
+
if (selection.profile && !/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/.test(selection.profile))
|
|
25954
|
+
return null;
|
|
25955
|
+
options.credential_profile = selection.profile || this.fleetConfig?.defaults?.backend_options?.[backend]?.credential_profile || undefined;
|
|
25956
|
+
}
|
|
25957
|
+
const profile = typeof options.credential_profile === "string" ? options.credential_profile : null;
|
|
25958
|
+
const instanceDir = instance ? this.getInstanceDir(instance) : join(getAgendHome(), "cli-env");
|
|
25959
|
+
const config = structuredClone({ workingDirectory: own?.working_directory ?? "", instanceDir,
|
|
25960
|
+
instanceName: instance ?? `probe-${backend}`, mcpServers: {}, backendOptions: options,
|
|
25961
|
+
...(profile ? { credentialStoreHome: credentialProfileStoreHome(getAgendHome(), backend, profile) } : {}) });
|
|
25962
|
+
const target = own ?? classic;
|
|
25963
|
+
if (target && !this.webModelTargetIds.has(target))
|
|
25964
|
+
this.webModelTargetIds.set(target, ++this.webModelTargetSequence);
|
|
25965
|
+
const targetId = target ? this.webModelTargetIds.get(target) : 0;
|
|
25966
|
+
const key = JSON.stringify({ backend, instance, config, targetId, target: own ?? classic, defaults: this.fleetConfig?.defaults });
|
|
25967
|
+
return { key, own, classic, profile, config, scoped: !!options.provider || (!!profile && backend !== "claude-code") };
|
|
25968
|
+
}
|
|
25969
|
+
webModelEnv(backend, instance, selection) {
|
|
25970
|
+
const binding = this.webModelBinding(backend, instance, selection);
|
|
25971
|
+
if (!binding)
|
|
25972
|
+
return null;
|
|
25973
|
+
const disk = binding.scoped ? null : this.readCliEnv(backend, binding.profile);
|
|
25974
|
+
const hit = this.webModelCatalogs.get(binding.key);
|
|
25975
|
+
if (hit && Date.now() - hit.probedAt < CLI_ENV_TTL_MS && (!disk || hit.probedAt >= disk.probedAt))
|
|
25976
|
+
return hit;
|
|
25977
|
+
return disk;
|
|
25978
|
+
}
|
|
25979
|
+
modelCatalogFor(backend, instance, selection) {
|
|
25980
|
+
const env = this.webModelEnv(backend, instance, selection);
|
|
25981
|
+
const seen = new Set();
|
|
25982
|
+
return [...(env?.models ?? []), ...(env?.apiModels ?? [])].filter(m => !seen.has(m.id) && !!seen.add(m.id));
|
|
25983
|
+
}
|
|
25984
|
+
/** Explicit, bounded vendor rediscovery. Never publish an answer under a different account/config/instance. */
|
|
25985
|
+
async refreshModelCatalogFor(backend, instance, selection) {
|
|
25986
|
+
const binding = this.webModelBinding(backend, instance, selection);
|
|
25987
|
+
if (!binding || this.shuttingDown)
|
|
25988
|
+
return { models: [], refreshed: false };
|
|
25989
|
+
const pending = this.webModelRefreshes.get(binding.key);
|
|
25990
|
+
if (pending)
|
|
25991
|
+
return pending;
|
|
25992
|
+
const epoch = this.cliEnvProbeEpoch;
|
|
25993
|
+
const current = () => {
|
|
25994
|
+
const next = this.webModelBinding(backend, instance, selection);
|
|
25995
|
+
return !this.shuttingDown && epoch === this.cliEnvProbeEpoch && next?.key === binding.key && next.own === binding.own && next.classic === binding.classic;
|
|
25996
|
+
};
|
|
25997
|
+
const work = this.runBackendProbeWorker(binding.scoped && !binding.profile ? `instance:${backend}:${binding.config.instanceDir}` : `global:${backend}${binding.profile ? `@${binding.profile}` : ""}`, {
|
|
25998
|
+
mode: "env", backend, instanceDir: binding.config.instanceDir, config: binding.config, refreshVendorCatalog: true,
|
|
25999
|
+
}).then(result => {
|
|
26000
|
+
if (!current())
|
|
26001
|
+
return { models: [], refreshed: false };
|
|
26002
|
+
// Raw failure/empty discovery never masquerades as a successful refresh of the retained catalog.
|
|
26003
|
+
if (!result || Array.isArray(result) || (!Array.isArray(result.models) || !result.models.length || result.catalogRefreshFailed))
|
|
26004
|
+
return { models: this.modelCatalogFor(backend, instance, selection), refreshed: false };
|
|
26005
|
+
if (this.webModelCatalogs.size >= 64)
|
|
26006
|
+
this.webModelCatalogs.delete(this.webModelCatalogs.keys().next().value);
|
|
26007
|
+
this.webModelCatalogs.set(binding.key, { ...result, backend, probedAt: Date.now() });
|
|
26008
|
+
return { models: this.modelCatalogFor(backend, instance, selection), refreshed: true };
|
|
26009
|
+
}).finally(() => { if (this.webModelRefreshes.get(binding.key) === work)
|
|
26010
|
+
this.webModelRefreshes.delete(binding.key); });
|
|
26011
|
+
this.webModelRefreshes.set(binding.key, work);
|
|
26012
|
+
return work;
|
|
25128
26013
|
}
|
|
25129
26014
|
/** Host-default fallback only: Grok has no modeled profile home. Never construct a backend or start a probe. */
|
|
25130
26015
|
async cliModelCatalogFor(backend, instance) {
|
|
@@ -25208,6 +26093,8 @@ export class FleetManager {
|
|
|
25208
26093
|
}
|
|
25209
26094
|
/** The models `/model` would offer on a backend: the cached CLI env, else (live) a bounded probe. Never throws. */
|
|
25210
26095
|
async backendModelOptions(backend, opts) {
|
|
26096
|
+
if (!opts.live && opts.instance)
|
|
26097
|
+
return this.modelCatalogFor(backend, opts.instance);
|
|
25211
26098
|
const cached = this.readCliEnv(backend);
|
|
25212
26099
|
if (!opts.live || (cached?.models.length && !this.cliEnvNeedsRefresh(cached)))
|
|
25213
26100
|
return cached?.models ?? [];
|
|
@@ -25829,6 +26716,10 @@ export class FleetManager {
|
|
|
25829
26716
|
this.fleetWindowsRuntime = null;
|
|
25830
26717
|
this.runtimeHub?.close();
|
|
25831
26718
|
this.runtimeHub = null;
|
|
26719
|
+
if (this.ownerNoticeTimer) {
|
|
26720
|
+
clearTimeout(this.ownerNoticeTimer);
|
|
26721
|
+
this.ownerNoticeTimer = null;
|
|
26722
|
+
}
|
|
25832
26723
|
this.localPaneRelay?.stop();
|
|
25833
26724
|
this.localPaneRelay = null;
|
|
25834
26725
|
closeWindowsBridge(this);
|
|
@@ -26373,6 +27264,7 @@ export class FleetManager {
|
|
|
26373
27264
|
this.agentCredentialsCache?.observePolicies();
|
|
26374
27265
|
if (this.loadedFleetSource)
|
|
26375
27266
|
this.getConfigHistory().accepted("fleet.yaml", this.configPath, this.loadedFleetSource);
|
|
27267
|
+
this.probeChangedCliEnvs(oldConfig);
|
|
26376
27268
|
this.migrateOfficeStorage();
|
|
26377
27269
|
this.migrateNoticeDeliveryStorage();
|
|
26378
27270
|
// Classic behavior settings share the fleet defaults but are not entries
|
|
@@ -28749,7 +29641,7 @@ export class FleetManager {
|
|
|
28749
29641
|
&& String(req.headers.accept ?? "").includes("text/html")
|
|
28750
29642
|
&& isWebPageNavigation(requestPath)) {
|
|
28751
29643
|
const link = gatewayRequestContext(req);
|
|
28752
|
-
serveSigninPage(res, 401, { webOnly: this.isWebOnlyFleet(), outside: !!link && this.isOutsideLink(link.exposureId), deviceLogin: !link && this.deviceLoginAvailable(), loginQr: this.loginQrEnabled() });
|
|
29644
|
+
serveSigninPage(res, 401, { webOnly: this.isWebOnlyFleet(), noChat: this.signinWithoutChat(), outside: !!link && this.isOutsideLink(link.exposureId), deviceLogin: !link && this.deviceLoginAvailable(), loginQr: this.loginQrEnabled() });
|
|
28753
29645
|
return;
|
|
28754
29646
|
}
|
|
28755
29647
|
res.writeHead(decision.status);
|
|
@@ -29485,7 +30377,7 @@ export class FleetManager {
|
|
|
29485
30377
|
// shown here rather than in chat). null when normal, unknown or advisory.
|
|
29486
30378
|
host_memory: this.hostMemoryIndicator(),
|
|
29487
30379
|
// #2910 D2: a web-only fleet's newest Notice — a polling page (no SSE `notice`) reads the list again when it moves.
|
|
29488
|
-
...(this.
|
|
30380
|
+
...(this.hasWebNotices() ? { notices_newest: this.webNoticeStore()?.newest() ?? 0 } : {}),
|
|
29489
30381
|
// alpha.2 (M-2300, #2997 review): agents' requests changed — the owner's page reads GET /ui/agent-proposals again.
|
|
29490
30382
|
...(this.isWebOnlyFleet() ? { agent_proposals_rev: this.agentProposalsRev } : {}),
|
|
29491
30383
|
// #2015: the largest processes while it lasts (name, pid, RSS, and whose: an instance, the fleet or tmux).
|