@songsid/agend 2.4.0-beta.15 → 2.4.0-beta.17
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-profiles.d.ts +1 -1
- package/dist/accounts-view.d.ts +3 -0
- package/dist/accounts-view.js.map +1 -1
- package/dist/auth-api.js +6 -0
- package/dist/auth-api.js.map +1 -1
- package/dist/backend/claude-code.d.ts +15 -1
- package/dist/backend/claude-code.js +64 -8
- package/dist/backend/claude-code.js.map +1 -1
- package/dist/backend/kiro.js +6 -1
- package/dist/backend/kiro.js.map +1 -1
- package/dist/backend/types.d.ts +8 -0
- package/dist/backend/types.js.map +1 -1
- package/dist/backend-command.d.ts +4 -2
- package/dist/backend-command.js +3 -0
- package/dist/backend-command.js.map +1 -1
- package/dist/browser-backend-signins.d.ts +1 -0
- package/dist/browser-backend-signins.js +3 -1
- package/dist/browser-backend-signins.js.map +1 -1
- package/dist/build-provenance.json +1 -1
- package/dist/classic-channel-manager.d.ts +1 -0
- package/dist/classic-channel-manager.js +4 -1
- package/dist/classic-channel-manager.js.map +1 -1
- package/dist/claude-credential-change.d.ts +22 -0
- package/dist/claude-credential-change.js +47 -0
- package/dist/claude-credential-change.js.map +1 -0
- package/dist/claude-credential-launch.d.ts +63 -0
- package/dist/claude-credential-launch.js +315 -0
- package/dist/claude-credential-launch.js.map +1 -0
- package/dist/claude-credential-runner.d.ts +1 -0
- package/dist/claude-credential-runner.js +56 -0
- package/dist/claude-credential-runner.js.map +1 -0
- package/dist/claude-credential-vault.d.ts +57 -0
- package/dist/claude-credential-vault.js +277 -0
- package/dist/claude-credential-vault.js.map +1 -0
- package/dist/claude-request-observation.d.ts +7 -0
- package/dist/claude-request-observation.js +26 -0
- package/dist/claude-request-observation.js.map +1 -0
- package/dist/claude-setup-token-transport.d.ts +9 -0
- package/dist/claude-setup-token-transport.js +82 -0
- package/dist/claude-setup-token-transport.js.map +1 -0
- package/dist/claude-setup-token.d.ts +51 -0
- package/dist/claude-setup-token.js +83 -0
- package/dist/claude-setup-token.js.map +1 -0
- package/dist/cli-audited.js +15 -12
- package/dist/cli-audited.js.map +1 -1
- package/dist/command-report.d.ts +11 -0
- package/dist/command-report.js +2 -0
- package/dist/command-report.js.map +1 -0
- package/dist/config-validator.js +9 -0
- package/dist/config-validator.js.map +1 -1
- package/dist/config.js +4 -2
- package/dist/config.js.map +1 -1
- package/dist/daemon.d.ts +5 -0
- package/dist/daemon.js +65 -3
- package/dist/daemon.js.map +1 -1
- package/dist/fleet-level-config.d.ts +1 -1
- package/dist/fleet-level-config.js +1 -0
- package/dist/fleet-level-config.js.map +1 -1
- package/dist/fleet-manager.d.ts +53 -2
- package/dist/fleet-manager.js +511 -22
- package/dist/fleet-manager.js.map +1 -1
- package/dist/general-knowledge/skills/web-appearance/SKILL.md +4 -1
- package/dist/general-knowledge/skills/web-dashboard/SKILL.md +25 -6
- package/dist/host-monitoring-config.d.ts +15 -0
- package/dist/host-monitoring-config.js +36 -0
- package/dist/host-monitoring-config.js.map +1 -0
- package/dist/host-monitoring-history-files.d.ts +2 -0
- package/dist/host-monitoring-history-files.js +16 -0
- package/dist/host-monitoring-history-files.js.map +1 -0
- package/dist/host-monitoring-history-policy.d.ts +55 -0
- package/dist/host-monitoring-history-policy.js +93 -0
- package/dist/host-monitoring-history-policy.js.map +1 -0
- package/dist/host-monitoring-history-store.d.ts +52 -0
- package/dist/host-monitoring-history-store.js +176 -0
- package/dist/host-monitoring-history-store.js.map +1 -0
- package/dist/host-monitoring-history-worker.d.ts +1 -0
- package/dist/host-monitoring-history-worker.js +50 -0
- package/dist/host-monitoring-history-worker.js.map +1 -0
- package/dist/host-monitoring-history.d.ts +71 -0
- package/dist/host-monitoring-history.js +265 -0
- package/dist/host-monitoring-history.js.map +1 -0
- package/dist/host-monitoring-platform.d.ts +73 -0
- package/dist/host-monitoring-platform.js +273 -0
- package/dist/host-monitoring-platform.js.map +1 -0
- package/dist/host-monitoring-runtime.d.ts +34 -0
- package/dist/host-monitoring-runtime.js +80 -0
- package/dist/host-monitoring-runtime.js.map +1 -0
- package/dist/host-monitoring-settings-store.d.ts +5 -0
- package/dist/host-monitoring-settings-store.js +49 -0
- package/dist/host-monitoring-settings-store.js.map +1 -0
- package/dist/host-monitoring.d.ts +106 -0
- package/dist/host-monitoring.js +157 -0
- package/dist/host-monitoring.js.map +1 -0
- package/dist/hub/group-policy/resources.d.ts +1 -1
- package/dist/instance-config-impact.js +1 -1
- package/dist/instance-config-impact.js.map +1 -1
- package/dist/instructions.js +1 -0
- package/dist/instructions.js.map +1 -1
- package/dist/locale.d.ts +2 -0
- package/dist/locale.js +13 -1
- package/dist/locale.js.map +1 -1
- package/dist/office-share-page.js +1 -1
- package/dist/office-share-page.js.map +1 -1
- package/dist/profile-signins.d.ts +1 -0
- package/dist/profile-signins.js +3 -1
- package/dist/profile-signins.js.map +1 -1
- package/dist/public-web-gateway.js +6 -0
- package/dist/public-web-gateway.js.map +1 -1
- package/dist/public-web-link.d.ts +21 -2
- package/dist/public-web-link.js +22 -2
- package/dist/public-web-link.js.map +1 -1
- package/dist/runtime-cli-install.js +17 -16
- package/dist/runtime-cli-install.js.map +1 -1
- package/dist/settings-api.d.ts +15 -0
- package/dist/settings-api.js +154 -8
- package/dist/settings-api.js.map +1 -1
- package/dist/settings-baseline.d.ts +1 -0
- package/dist/settings-baseline.js +5 -4
- package/dist/settings-baseline.js.map +1 -1
- package/dist/settings-change.js +10 -0
- package/dist/settings-change.js.map +1 -1
- package/dist/settings-effect.d.ts +2 -0
- package/dist/settings-effect.js +15 -1
- package/dist/settings-effect.js.map +1 -1
- package/dist/topic-commands.d.ts +7 -1
- package/dist/topic-commands.js +98 -88
- package/dist/topic-commands.js.map +1 -1
- package/dist/transcript-monitor.d.ts +1 -0
- package/dist/transcript-monitor.js +18 -0
- package/dist/transcript-monitor.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/ui/accounts-view.js +16 -8
- package/dist/ui/backend-signin.js +3 -1
- package/dist/ui/chat-commands.js +2 -0
- package/dist/ui/chat-popout-transport.js +49 -19
- package/dist/ui/chat-popout.js +15 -1
- package/dist/ui/chat-store.js +1 -1
- package/dist/ui/claude-credentials.js +123 -0
- package/dist/ui/claude-setup-token.js +36 -0
- package/dist/ui/contact-auth-client.js +7 -2
- package/dist/ui/contact-auth-strings.js +45 -14
- package/dist/ui/contact-authorizations.js +47 -26
- package/dist/ui/contact-needs.js +4 -4
- package/dist/ui/fleet-canvas.js +3 -2
- package/dist/ui/fleet-office-card.js +414 -41
- package/dist/ui/fleet-office-dialogue.js +3 -3
- package/dist/ui/fleet-office-pack.d.ts +67 -1
- package/dist/ui/fleet-office-pack.js +412 -18
- package/dist/ui/fleet-office-play.js +401 -3
- package/dist/ui/fleet-office-skin.js +133 -21
- package/dist/ui/fleet-office-store.js +41 -0
- package/dist/ui/fleet-office-zones.js +34 -9
- package/dist/ui/fleet-office.js +513 -62
- package/dist/ui/host-health-model.js +42 -0
- package/dist/ui/host-health.js +74 -0
- package/dist/ui/office-share-page.js +5 -1
- package/dist/ui/panel-chat.js +146 -46
- package/dist/ui/panel-fleet.js +24 -11
- package/dist/ui/panel-hub.js +5 -1
- package/dist/ui/panel-settings.js +5 -4
- package/dist/ui/preview-popout.js +134 -0
- package/dist/ui/reply-file-preview.js +1 -1
- package/dist/ui/search-dialog.js +8 -1
- package/dist/ui/settings-capabilities.js +2 -0
- package/dist/ui/settings-host-monitoring.js +69 -0
- package/dist/ui/settings-registry.js +4 -1
- package/dist/ui/settings-shared.js +3 -2
- package/dist/ui/shared/accounts.css +8 -4
- package/dist/ui/shared/agent-sheet.js +5 -2
- package/dist/ui/shared/app-route.js +1 -1
- package/dist/ui/shared/app.css +248 -27
- package/dist/ui/shared/app.js +8 -1
- package/dist/ui/shared/chat-strings.js +10 -4
- package/dist/ui/shared/chat-thread.js +42 -10
- package/dist/ui/shared/info-tip.js +64 -0
- package/dist/ui/shared/instance-nav.js +47 -5
- package/dist/ui/shared/jump-idle.js +36 -0
- package/dist/ui/shared/office-dialogue.css +12 -0
- package/dist/ui/shared/preview-panel.js +44 -18
- package/dist/ui/shared/preview-popout.css +11 -0
- package/dist/ui/shared/theme.js +15 -1
- package/dist/ui/shared/ui-menu.js +17 -11
- package/dist/ui/shared/usage-dialog.js +9 -34
- package/dist/ui/shared/view-strings.js +2 -0
- package/dist/usage/i18n-keys.d.ts +1 -1
- package/dist/usage/i18n-keys.js +1 -1
- package/dist/usage/i18n-keys.js.map +1 -1
- package/dist/usage/providers.d.ts +1 -0
- package/dist/usage/providers.js +14 -1
- package/dist/usage/providers.js.map +1 -1
- package/dist/usage/usage-api.js +5 -2
- package/dist/usage/usage-api.js.map +1 -1
- package/dist/web-api.d.ts +6 -1
- package/dist/web-api.js +83 -9
- package/dist/web-api.js.map +1 -1
- package/dist/web-chat-history.d.ts +7 -1
- package/dist/web-chat-history.js +19 -3
- package/dist/web-chat-history.js.map +1 -1
- package/dist/web-claude-credentials.d.ts +31 -0
- package/dist/web-claude-credentials.js +138 -0
- package/dist/web-claude-credentials.js.map +1 -0
- package/dist/web-commands.d.ts +5 -2
- package/dist/web-commands.js +4 -2
- package/dist/web-commands.js.map +1 -1
- package/dist/web-office-skins.d.ts +7 -2
- package/dist/web-office-skins.js +42 -16
- package/dist/web-office-skins.js.map +1 -1
- package/dist/web-session.d.ts +20 -1
- package/dist/web-session.js +27 -0
- package/dist/web-session.js.map +1 -1
- package/dist/web-shell-routes.d.ts +1 -1
- package/dist/web-shell-routes.js +1 -1
- package/dist/web-shell-routes.js.map +1 -1
- package/dist/web-terminal.d.ts +4 -0
- package/dist/web-terminal.js +16 -1
- package/dist/web-terminal.js.map +1 -1
- package/package.json +1 -1
package/dist/fleet-manager.js
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
import { readHostMonitoringDrive, writeHostMonitoringDrive, validMonitoringDrive } from './host-monitoring-settings-store.js';
|
|
2
|
+
import { HostMonitoringHistory } from './host-monitoring-history.js';
|
|
3
|
+
import { HostMonitoringRuntime } from "./host-monitoring-runtime.js";
|
|
4
|
+
import { NativeHostMonitoring } from "./host-monitoring-platform.js";
|
|
5
|
+
import { disabledHostHealth } from "./host-monitoring.js";
|
|
6
|
+
import { monitoringConfig } from "./host-monitoring-config.js";
|
|
7
|
+
import { ClaudeSetupTokens } from "./claude-setup-token.js";
|
|
8
|
+
import { changeIdleClaudeCredential } from "./claude-credential-change.js";
|
|
9
|
+
import { readClaudeCredentialSelection, claudeSubscriptionSuppressed } from "./claude-credential-launch.js";
|
|
10
|
+
import { ClaudeCredentialVault, ClaudeCredentialError } from "./claude-credential-vault.js";
|
|
1
11
|
import { withHubRoomReplyWarning } from "./hub-room-reply-warning.js";
|
|
2
12
|
import { ContactAuthService } from "./contact-auth-service.js";
|
|
3
13
|
import { stageContactFiles } from "./contact-auth-files.js";
|
|
@@ -245,7 +255,7 @@ import { createNativeWindowsInstance, updateNativeWindowsInstance } from "./nati
|
|
|
245
255
|
import { NativeInstanceConfigEdit, parseNativeInstanceCreate } from "./native-instance-input.js";
|
|
246
256
|
import { LogService, thinkingOn } from "./log-service.js";
|
|
247
257
|
import { viewHistory } from "./view-history.js";
|
|
248
|
-
import { WebChatHistory, WEB_CHAT_TEXT_MAX, isWebMessageId, newWebMessageId, webChatFrom } from "./web-chat-history.js";
|
|
258
|
+
import { WebChatHistory, WEB_CHAT_TEXT_MAX, isWebMessageId, newWebMessageId, webChatFrom, webChatReplyRef } from "./web-chat-history.js";
|
|
249
259
|
import { WEB_ECHO_COPIES_MAX, WEB_MIRROR_TIMEOUT_MS, webReactionEmoji, webReactionProblem } from "./web-reactions.js";
|
|
250
260
|
import { WebChatDiskStore, isSafeInstanceDirName } from "./web-chat-store.js";
|
|
251
261
|
import { WebChatArchive } from "./web-chat-archive.js";
|
|
@@ -312,7 +322,7 @@ import { BrowserBackendSignIns } from "./browser-backend-signins.js";
|
|
|
312
322
|
import { createStructuredSignInTransport } from "./structured-signin-transport.js";
|
|
313
323
|
import { ONBOARDING_BACKENDS, ONBOARDING_BROWSER_BACKENDS, readPendingBackendSignIns } from "./backend-signin-pending.js";
|
|
314
324
|
import { hostFacts, runtimeAccountsCapability, runtimeFacts } from "./cli-registry.js";
|
|
315
|
-
import { handleSettingsRequest, switchClassicRoomProfile } from "./settings-api.js";
|
|
325
|
+
import { handleSettingsRequest, switchClassicRoomProfile, switchClassicRoomBackend } from "./settings-api.js";
|
|
316
326
|
import { setLocale, detectLocale, getLocale, t } from "./locale.js";
|
|
317
327
|
import { remoteCardAction, remoteCardChoiceLabel, remoteCardOutcomeText, remoteCardPrompt, REMOTE_CARD_TEXT_MAX } from "./remote-card-prompt.js";
|
|
318
328
|
import { recentChatContext } from "./log-tail.js";
|
|
@@ -799,6 +809,59 @@ export class FleetManager {
|
|
|
799
809
|
stormWindow;
|
|
800
810
|
spawnGate;
|
|
801
811
|
memoryPressure;
|
|
812
|
+
hostMonitor = null;
|
|
813
|
+
hostHistory = null;
|
|
814
|
+
startHostMonitoringRuntime() {
|
|
815
|
+
this.hostHistory ??= new HostMonitoringHistory({ path: join(this.dataDir, 'host-monitoring.sqlite'), unblocked: () => this.hostMonitor?.apply() });
|
|
816
|
+
this.hostMonitor ??= new HostMonitoringRuntime({
|
|
817
|
+
history: this.hostHistory,
|
|
818
|
+
supported: () => process.platform === "linux" || process.platform === "darwin",
|
|
819
|
+
drive: () => readHostMonitoringDrive(this.dataDir),
|
|
820
|
+
committed: () => monitoringConfig(this.fleetConfig?.monitoring),
|
|
821
|
+
raw: () => { if (!this.configPath)
|
|
822
|
+
throw Error("config unavailable"); return { monitoring: loadRawFleetConfig(this.configPath).monitoring }; },
|
|
823
|
+
pin: patches => this.saveFleetConfig(patches),
|
|
824
|
+
factory: () => new NativeHostMonitoring({ statePath: this.dataDir, memory: () => this.memoryPressure.snapshot(), wslDrive: readHostMonitoringDrive(this.dataDir) }),
|
|
825
|
+
});
|
|
826
|
+
this.hostMonitor.start();
|
|
827
|
+
}
|
|
828
|
+
hostHistoryQuery(range, series) { return this.hostHistory?.query(range, series) ?? Promise.resolve({ ok: false, reason: 'history_unavailable' }); }
|
|
829
|
+
hostMonitoringAvailable() { return this.hostMonitor?.available() === true; }
|
|
830
|
+
hostHealthSnapshot() { return this.hostMonitor?.snapshot() ?? disabledHostHealth(); }
|
|
831
|
+
/** Effective Settings view: the drive is intentionally outside FleetConfig/fleet.yaml. */
|
|
832
|
+
hostMonitoringSettings() {
|
|
833
|
+
const drive = readHostMonitoringDrive(this.dataDir);
|
|
834
|
+
return { ...monitoringConfig(this.fleetConfig?.monitoring), ...(drive ? { wsl_drive: drive } : {}) };
|
|
835
|
+
}
|
|
836
|
+
saveHostMonitoringSettings(patch) {
|
|
837
|
+
if (!this.fleetConfig || !this.configPath)
|
|
838
|
+
throw Error('fleet unavailable');
|
|
839
|
+
const previous = this.fleetConfig.monitoring, oldDrive = readHostMonitoringDrive(this.dataDir);
|
|
840
|
+
const raw = loadRawFleetConfig(this.configPath).monitoring;
|
|
841
|
+
const legacy = raw && Object.hasOwn(raw, 'wsl_drive');
|
|
842
|
+
const change = Object.hasOwn(patch, 'wsl_drive') || legacy;
|
|
843
|
+
const nextDrive = Object.hasOwn(patch, 'wsl_drive') ? patch.wsl_drive : legacy ? raw.wsl_drive : oldDrive;
|
|
844
|
+
// Sidecar first: failure cannot leave new YAML pointing at an unsaved selection.
|
|
845
|
+
if (change) {
|
|
846
|
+
if (!validMonitoringDrive(nextDrive))
|
|
847
|
+
throw Error('invalid_monitoring_drive');
|
|
848
|
+
writeHostMonitoringDrive(this.dataDir, nextDrive);
|
|
849
|
+
}
|
|
850
|
+
try {
|
|
851
|
+
this.fleetConfig.monitoring = monitoringConfig({ ...monitoringConfig(previous), ...patch });
|
|
852
|
+
this.saveFleetConfig([
|
|
853
|
+
...Object.entries(this.fleetConfig.monitoring).map(([key, value]) => ({ path: ['monitoring', key], value })),
|
|
854
|
+
{ path: ['monitoring', 'wsl_drive'], remove: true },
|
|
855
|
+
]);
|
|
856
|
+
}
|
|
857
|
+
catch (error) {
|
|
858
|
+
this.fleetConfig.monitoring = previous;
|
|
859
|
+
if (change)
|
|
860
|
+
writeHostMonitoringDrive(this.dataDir, oldDrive ?? '');
|
|
861
|
+
throw error;
|
|
862
|
+
}
|
|
863
|
+
return this.hostMonitoringSettings();
|
|
864
|
+
}
|
|
802
865
|
/** Fleet-level backend reachability memory (fed by pty_error / startup panes). */
|
|
803
866
|
backendOutage = new BackendOutageTracker();
|
|
804
867
|
/** Stable for this FleetManager OS-process lifetime; Daemon objects have their own boot IDs. */
|
|
@@ -4206,6 +4269,7 @@ export class FleetManager {
|
|
|
4206
4269
|
generalLocation: input => this.previewGeneralLocation(input),
|
|
4207
4270
|
hubMembership: raw => hubMembershipSettings(raw),
|
|
4208
4271
|
hubPageSharing: raw => hubPageSharingSettings(raw),
|
|
4272
|
+
hostMonitoringAvailable: () => this.hostMonitoringAvailable(),
|
|
4209
4273
|
hubPilotTrust: raw => hubPilotTrustSettings(raw, RUNNING_AGEND_VERSION),
|
|
4210
4274
|
// S3c (S-55): a Hub exposure publish's confirmation summary, while a member composition is attached.
|
|
4211
4275
|
hubBrowserCertificate: (input, binding) => {
|
|
@@ -6164,6 +6228,26 @@ export class FleetManager {
|
|
|
6164
6228
|
since: group.since, detail: "", contactSuggestionCount: group.count, quiet: true,
|
|
6165
6229
|
}))];
|
|
6166
6230
|
}
|
|
6231
|
+
/** Identity for reminder visibility/dismissal ONLY. Never a verified contact/action permit. */
|
|
6232
|
+
contactSuggestionActor(req, url) {
|
|
6233
|
+
const verdict = evaluateWebRequest(req, url, this.webToken, this.webSessions, { touch: false });
|
|
6234
|
+
if (verdict.kind !== "allow" || verdict.via !== "session" || verdict.session.tier !== "admin")
|
|
6235
|
+
return null;
|
|
6236
|
+
const verified = this.contactActor(req, url);
|
|
6237
|
+
if (verified)
|
|
6238
|
+
return verified;
|
|
6239
|
+
const owner = verdict.session.owner, adapter = owner && this.adapters.get(owner.adapterId);
|
|
6240
|
+
if (!owner || !adapter || (adapter.type !== "discord" && adapter.type !== "telegram"))
|
|
6241
|
+
return null;
|
|
6242
|
+
return { platform: adapter.type, adapterId: owner.adapterId, userId: owner.userId, label: owner.userId };
|
|
6243
|
+
}
|
|
6244
|
+
/** Dismissing a reminder grants no authority: current room-admin membership is still checked below. */
|
|
6245
|
+
acknowledgeContactSuggestionFromWeb(instance, req, url) {
|
|
6246
|
+
const actor = this.contactSuggestionActor(req, url);
|
|
6247
|
+
if (!actor)
|
|
6248
|
+
throw Error("verification-required");
|
|
6249
|
+
this.acknowledgeContactSuggestion(instance, actor);
|
|
6250
|
+
}
|
|
6167
6251
|
acknowledgeContactSuggestion(instance, actor) {
|
|
6168
6252
|
if (!this.contactAdminOf(instance, actor) || !this.contactRoom(instance))
|
|
6169
6253
|
throw Error("forbidden");
|
|
@@ -6309,6 +6393,18 @@ export class FleetManager {
|
|
|
6309
6393
|
if (this.workingStateListeners.has(daemon))
|
|
6310
6394
|
return;
|
|
6311
6395
|
this.workingStateListeners.add(daemon);
|
|
6396
|
+
daemon.on("claude_credential_request", (event) => {
|
|
6397
|
+
try {
|
|
6398
|
+
if (this.daemons.get(name) !== daemon || !sameInteractionOwner(event.owner, daemon.getInteractionSnapshot().owner) || resolvePath(event.binding.home) !== resolvePath(this.dataDir) || event.binding.kind === "subscription")
|
|
6399
|
+
return;
|
|
6400
|
+
const { binding, record } = event, kind = binding.kind;
|
|
6401
|
+
if (kind === "subscription")
|
|
6402
|
+
return;
|
|
6403
|
+
if (this.withClaudeVault(vault => vault.observeRequest(binding.profile, binding.id, binding.revision, kind, record)))
|
|
6404
|
+
broadcastSseEvent(this.sseClients, "backend_login", {}, () => { });
|
|
6405
|
+
}
|
|
6406
|
+
catch { /* Metadata observation never changes the source or interrupts work. */ }
|
|
6407
|
+
});
|
|
6312
6408
|
daemon.on("working_state", (event) => {
|
|
6313
6409
|
try {
|
|
6314
6410
|
if (this.daemons.get(name) !== daemon || !sameInteractionOwner(event.observation.owner, daemon.getInteractionSnapshot().owner))
|
|
@@ -7310,6 +7406,9 @@ export class FleetManager {
|
|
|
7310
7406
|
process.env.AGEND_FLEET_CONFIG_PATH = resolvePath(configPath);
|
|
7311
7407
|
if (options.remember !== false && existsSync(configPath))
|
|
7312
7408
|
history.accepted("fleet.yaml", configPath, selected);
|
|
7409
|
+
// The normal lossless writer owns migration; never hand-edit YAML or retain this beta.17-only key for rollback.
|
|
7410
|
+
if (options.startup && raw.monitoring && Object.hasOwn(raw.monitoring, 'wsl_drive'))
|
|
7411
|
+
this.saveFleetConfig();
|
|
7313
7412
|
return this.fleetConfig;
|
|
7314
7413
|
}
|
|
7315
7414
|
relayLoginModeWarned = false;
|
|
@@ -8234,6 +8333,14 @@ export class FleetManager {
|
|
|
8234
8333
|
return;
|
|
8235
8334
|
this.cancelButtonIdleRetireTimers.delete(name);
|
|
8236
8335
|
if (this.getInstanceExecutionState(name) === "idle") {
|
|
8336
|
+
// #4270: a pause between tool calls can read as idle mid-turn, and nothing re-shows the bubble when the turn
|
|
8337
|
+
// goes back to working. While the turn is still open (no completion delivered, not cancelled), check again
|
|
8338
|
+
// after another grace instead of retiring. The turn's close, or the 5-minute idle backstop for a turn that
|
|
8339
|
+
// never closes, still retires it.
|
|
8340
|
+
if (this.instanceTurnOpen(name) && this.instanceHasCancelButton(name)) {
|
|
8341
|
+
this.scheduleIdleButtonRetirement(name);
|
|
8342
|
+
return;
|
|
8343
|
+
}
|
|
8237
8344
|
this.markCancelButtonPublicationForRetirement(name, publication);
|
|
8238
8345
|
this.retireInstanceButtons(name);
|
|
8239
8346
|
}
|
|
@@ -8241,6 +8348,27 @@ export class FleetManager {
|
|
|
8241
8348
|
timer.unref?.();
|
|
8242
8349
|
this.cancelButtonIdleRetireTimers.set(name, timer);
|
|
8243
8350
|
}
|
|
8351
|
+
/** #4270: the daemon's turn is still open (turn_started seen, no turn_closed, no completion delivered, not cancelled). */
|
|
8352
|
+
instanceTurnOpen(name) {
|
|
8353
|
+
const daemon = this.daemons.get(name);
|
|
8354
|
+
if (!daemon || typeof daemon.getWorkingStateObservation !== "function")
|
|
8355
|
+
return false;
|
|
8356
|
+
try {
|
|
8357
|
+
const turn = daemon.getWorkingStateObservation().turn;
|
|
8358
|
+
return !!turn && !turn.cancelled && !turn.completionDelivered;
|
|
8359
|
+
}
|
|
8360
|
+
catch {
|
|
8361
|
+
return false;
|
|
8362
|
+
}
|
|
8363
|
+
}
|
|
8364
|
+
instanceHasCancelButton(name) {
|
|
8365
|
+
if (this.cancelButtonPublications.get(name)?.inFlight)
|
|
8366
|
+
return true;
|
|
8367
|
+
for (const entry of this.cancelButtons.values())
|
|
8368
|
+
if (entry.instanceName === name)
|
|
8369
|
+
return true;
|
|
8370
|
+
return false;
|
|
8371
|
+
}
|
|
8244
8372
|
cacheInstanceProcessStatus(name, status) {
|
|
8245
8373
|
// #1386: every transition into crashed is a new occurrence (a new "Needs you" item), and every other status ends
|
|
8246
8374
|
// the previous one — at once, not when the coalesced collector next runs: running then crashed in one IPC chunk is
|
|
@@ -9874,8 +10002,10 @@ export class FleetManager {
|
|
|
9874
10002
|
}
|
|
9875
10003
|
// CLI single-instance cold starts bypass startAll. Start diagnostics before
|
|
9876
10004
|
// any lifecycle/wake work; a shutdown must not revive the stopped sampler.
|
|
9877
|
-
if (!this.shuttingDown)
|
|
10005
|
+
if (!this.shuttingDown) {
|
|
9878
10006
|
this.memoryPressure?.start();
|
|
10007
|
+
this.startHostMonitoringRuntime();
|
|
10008
|
+
}
|
|
9879
10009
|
// Any start supersedes a pending automatic retry (it would otherwise fire
|
|
9880
10010
|
// into a running instance — harmless, but noisy — or race this start).
|
|
9881
10011
|
this.cancelStartupRetry(name);
|
|
@@ -11044,6 +11174,8 @@ export class FleetManager {
|
|
|
11044
11174
|
gatewayPolicy: () => publicLinkSessionPolicy(this.fleetConfig?.web?.session?.public_link, publicLinkNamedHostname(this.fleetConfig?.web)),
|
|
11045
11175
|
// A session over the temporary link ends with the link (its TTL, at most 8 h on a quick tunnel).
|
|
11046
11176
|
exposureEnd: id => this.publicWebLink?.endOf(id) ?? null,
|
|
11177
|
+
// M-3399: a session made over the fixed link carries its identity, to outlive a restart or an update.
|
|
11178
|
+
linkKeyOf: id => this.publicWebLink?.keyOf?.(id) ?? null,
|
|
11047
11179
|
});
|
|
11048
11180
|
this.enforceGuestSwitch(); // #1920: guests off while the fleet was down
|
|
11049
11181
|
}
|
|
@@ -11249,9 +11381,16 @@ export class FleetManager {
|
|
|
11249
11381
|
reserve: id => this.getTunnelLane().reserve("dashboard", id),
|
|
11250
11382
|
createGateway: (exposureId, current, open, failed, named) => createPublicWebGateway({ ...named, exposureId, isCurrent: current, isOpen: open, onError: failed,
|
|
11251
11383
|
dispatch: (req, res) => this.dispatchWebHttp(req, res, this.fleetConfig?.health_port ?? 19280) }),
|
|
11252
|
-
revoke: id => {
|
|
11384
|
+
revoke: (id, keep) => {
|
|
11253
11385
|
this.webLoginCodes?.revokeAudience(id);
|
|
11254
11386
|
this.webGuestLoginCodes?.revokeAudience(id);
|
|
11387
|
+
// M-3399 (the user: "sign-in should survive an update or restart"): the fixed link closing because the fleet stops
|
|
11388
|
+
// keeps its sessions — and their verified authority — for the same link to take back when it opens again. Sign-in
|
|
11389
|
+
// codes still end; nothing over the link answers until it is open again.
|
|
11390
|
+
if (keep?.keepSessions) {
|
|
11391
|
+
this.logger.info({ exposureId: id }, "Public web link: fixed-link sessions kept across the fleet stop");
|
|
11392
|
+
return;
|
|
11393
|
+
}
|
|
11255
11394
|
// #2453 (§0.2): the link's sessions end, and the authorizations kept for them go with them (housekeeping: their
|
|
11256
11395
|
// handles can never match again).
|
|
11257
11396
|
const ended = new Set(this.webSessions?.list(undefined, r => r.exposureId === id).map(r => r.handle) ?? []);
|
|
@@ -11261,6 +11400,21 @@ export class FleetManager {
|
|
|
11261
11400
|
if (result && !result.durable)
|
|
11262
11401
|
this.logger.warn("Public session revocation could not be saved; exposure remains closed");
|
|
11263
11402
|
},
|
|
11403
|
+
// M-3399: the fixed link open again (auto_open, or a /web): its kept sessions rejoin it; ones kept for another hostname
|
|
11404
|
+
// or token end, with their authorizations.
|
|
11405
|
+
opened: (id, configuration) => {
|
|
11406
|
+
const result = this.webSessions?.adoptLink(configuration, id);
|
|
11407
|
+
if (!result)
|
|
11408
|
+
return;
|
|
11409
|
+
if (result.ended.length) {
|
|
11410
|
+
const ended = new Set(result.ended);
|
|
11411
|
+
this.sessionAuthorizationStore()?.prune(a => !ended.has(a.handle));
|
|
11412
|
+
}
|
|
11413
|
+
if (result.adopted || result.ended.length)
|
|
11414
|
+
this.logger.info({ exposureId: id, adopted: result.adopted, ended: result.ended.length }, "Public web link: kept fixed-link sessions rejoined");
|
|
11415
|
+
if (!result.durable)
|
|
11416
|
+
this.logger.warn("Fixed-link session changes could not be saved");
|
|
11417
|
+
},
|
|
11264
11418
|
log: (event, exposureId, detail) => this.logger.info({ event, exposureId, ...(detail ? { detail } : {}) }, "Public web link"),
|
|
11265
11419
|
createPreview: ({ id, expiresAt, binary, protocol, dashboardOrigin, isCurrent }) => {
|
|
11266
11420
|
if (!publicPreviewWanted(this.fleetConfig?.web))
|
|
@@ -12715,6 +12869,7 @@ export class FleetManager {
|
|
|
12715
12869
|
// Must run before the first General/CLI spawn: pressure can hold startup.
|
|
12716
12870
|
// Logs remain available even before the adapters and health listener exist.
|
|
12717
12871
|
this.memoryPressure.start();
|
|
12872
|
+
this.startHostMonitoringRuntime();
|
|
12718
12873
|
// #2910: a web-only fleet's agents run in topic mode too (their cross-instance tools work; the dashboard is their place).
|
|
12719
12874
|
const topicMode = daemonTopicMode(fleet);
|
|
12720
12875
|
// Set tmux socket isolation for custom AGEND_HOME
|
|
@@ -15363,7 +15518,7 @@ export class FleetManager {
|
|
|
15363
15518
|
}
|
|
15364
15519
|
return;
|
|
15365
15520
|
}
|
|
15366
|
-
//
|
|
15521
|
+
// /backend uses the shared staged picker for a ClassicBot room, with the same admin gate as /model.
|
|
15367
15522
|
if (text === "/backend" || text.startsWith("/backend ") || text.startsWith("/backend@")) {
|
|
15368
15523
|
if (!this.isModelAdmin(msg.userId, chatId, msg.adapterId)) {
|
|
15369
15524
|
await msgAdapter?.sendText(chatId, t("permission.denied"));
|
|
@@ -16128,6 +16283,14 @@ export class FleetManager {
|
|
|
16128
16283
|
});
|
|
16129
16284
|
}
|
|
16130
16285
|
};
|
|
16286
|
+
// M-3491: a `reply_to` that names a kept web-chat message (by its web id, or a copy elsewhere) becomes that
|
|
16287
|
+
// message's copy on this platform, so the reply is a native reply there; an id the chat does not know is left as
|
|
16288
|
+
// it is (the adapter ignores one that is not its own: no quote, no error, as before).
|
|
16289
|
+
if (typeof args.reply_to === "string" && args.reply_to && outAdapter !== WEB_ONLY_REPLY_SINK) {
|
|
16290
|
+
const native = this.nativeReplyTo(instanceName, args.reply_to, outAdapter.id ?? contextAdapterId ?? "", String(args.chat_id ?? ""), String(args.thread_id ?? threadId ?? ""));
|
|
16291
|
+
if (native)
|
|
16292
|
+
args.reply_to = native;
|
|
16293
|
+
}
|
|
16131
16294
|
if (routeToolCall(outAdapter, tool, args, threadId, respondAndRecord, { ...restrictedExtras, ...(replySet ? { replyButtons: replySet.callbacks, ...(replySet.poll ? { replyPoll: replySet.poll } : {}) } : {}) })) {
|
|
16132
16295
|
return;
|
|
16133
16296
|
}
|
|
@@ -16197,6 +16360,18 @@ export class FleetManager {
|
|
|
16197
16360
|
return false;
|
|
16198
16361
|
}
|
|
16199
16362
|
}
|
|
16363
|
+
/**
|
|
16364
|
+
* M-3491: the platform message id a reply to `id` uses on `adapterId`'s chat and thread — the copy there of the kept
|
|
16365
|
+
* web-chat message `id` names (#2281 posts) — or undefined when the chat keeps no such message or it has no copy there.
|
|
16366
|
+
*/
|
|
16367
|
+
nativeReplyTo(instance, id, adapterId, chatId, threadId) {
|
|
16368
|
+
const row = this.webChatHistory.findByReplyId(instance, id);
|
|
16369
|
+
if (!row || !adapterId)
|
|
16370
|
+
return undefined;
|
|
16371
|
+
const here = this.webChatHistory.postsOf(row).filter(p => p.adapterId === adapterId && p.chatId === chatId && (p.threadId ?? "") === threadId);
|
|
16372
|
+
// An id that already is one of its copies here (its buttons message, say) stays the one the agent named.
|
|
16373
|
+
return here.find(p => p.messageId === id)?.messageId ?? here[0]?.messageId;
|
|
16374
|
+
}
|
|
16200
16375
|
captureReplyPreview(instance, args) {
|
|
16201
16376
|
if (!replyPreviews(args.previews)?.length)
|
|
16202
16377
|
return undefined;
|
|
@@ -16211,6 +16386,13 @@ export class FleetManager {
|
|
|
16211
16386
|
const sent = (sentAs?.result && typeof sentAs.result === "object" ? sentAs.result : {});
|
|
16212
16387
|
const post = inChannel && sentAs && typeof sent.messageId === "string" && typeof sent.chatId === "string"
|
|
16213
16388
|
? { adapterId: sentAs.adapterId, chatId: sent.chatId, ...(typeof sent.threadId === "string" && sent.threadId ? { threadId: sent.threadId } : {}), messageId: sent.messageId } : undefined;
|
|
16389
|
+
// M-3491: a long reply's buttons ride its last part, a message of its own: a later `reply_to` may name that one.
|
|
16390
|
+
const buttonsPost = post && typeof sent.buttonsMessageId === "string" && sent.buttonsMessageId && sent.buttonsMessageId !== post.messageId
|
|
16391
|
+
? { ...post, messageId: sent.buttonsMessageId } : undefined;
|
|
16392
|
+
// M-3491: what the reply quotes in the web chat — the kept message its `reply_to` names (a web id, the id an earlier
|
|
16393
|
+
// reply returned, or a Discord/Telegram copy's id), taken now; an id the chat does not keep quotes nothing, as before.
|
|
16394
|
+
const quotedRow = typeof args.reply_to === "string" && args.reply_to ? this.webChatHistory.findByReplyId(instanceName, args.reply_to) : undefined;
|
|
16395
|
+
const quoted = quotedRow ? webChatReplyRef(quotedRow) : undefined;
|
|
16214
16396
|
// A reply is NOT proof the turn is over (#410) — but it is not proof of
|
|
16215
16397
|
// more work either. Split the difference: an instance that is clearly
|
|
16216
16398
|
// idle loses the button now; one that looks busy keeps it (re-posted
|
|
@@ -16257,7 +16439,8 @@ export class FleetManager {
|
|
|
16257
16439
|
...(buttons ? { buttons } : {}), // #1266
|
|
16258
16440
|
...(replyPreviews(args.previews)?.length ? { previews: replyPreviews(args.previews) } : {}),
|
|
16259
16441
|
...(inChannel ? { channel: true } : {}), // #1920 §5.2
|
|
16260
|
-
...(post ? { posts: [post] } : {}), // #2281
|
|
16442
|
+
...(post ? { posts: buttonsPost ? [post, buttonsPost] : [post] } : {}), // #2281 (M-3491: and its buttons message)
|
|
16443
|
+
...(quoted ? { replyTo: quoted } : {}), // M-3491
|
|
16261
16444
|
...(typeof returned === "string" && returned ? { anchor: returned } : {}), // AGEND-181: what the reply call returned
|
|
16262
16445
|
...(reserved !== undefined ? { reserved } : {}), // #1774
|
|
16263
16446
|
});
|
|
@@ -17800,6 +17983,22 @@ export class FleetManager {
|
|
|
17800
17983
|
this.rawFleetConfig = loadRawFleetConfig(this.configPath);
|
|
17801
17984
|
// #2208: what the file says before this save, aliases expanded — every write below is recorded, and anything that
|
|
17802
17985
|
// changes outside them (a place sharing a node with one written) refuses the save.
|
|
17986
|
+
// Any save repairs a legacy drive key. A Settings transaction which already saved its sidecar supplies remove.
|
|
17987
|
+
const drivePath = (p) => p.path.length === 2 && p.path[0] === 'monitoring' && p.path[1] === 'wsl_drive';
|
|
17988
|
+
const requestedDrive = explicitPatches.find(p => drivePath(p) && !p.remove);
|
|
17989
|
+
const removesDrive = explicitPatches.some(p => drivePath(p) && p.remove);
|
|
17990
|
+
const rawMonitoring = this.rawFleetConfig.monitoring;
|
|
17991
|
+
const legacyDrive = rawMonitoring && Object.hasOwn(rawMonitoring, 'wsl_drive');
|
|
17992
|
+
if (requestedDrive || legacyDrive && !removesDrive) {
|
|
17993
|
+
const value = requestedDrive ? requestedDrive.value : rawMonitoring.wsl_drive;
|
|
17994
|
+
if (!validMonitoringDrive(value))
|
|
17995
|
+
throw Error('invalid_monitoring_drive');
|
|
17996
|
+
writeHostMonitoringDrive(this.dataDir, value);
|
|
17997
|
+
}
|
|
17998
|
+
if (this.fleetConfig.monitoring)
|
|
17999
|
+
this.fleetConfig.monitoring = monitoringConfig(this.fleetConfig.monitoring);
|
|
18000
|
+
explicitPatches = explicitPatches.filter(p => !drivePath(p));
|
|
18001
|
+
explicitPatches.push({ path: ['monitoring', 'wsl_drive'], remove: true });
|
|
17803
18002
|
const fileBefore = this.rawFleetDocument.toJS({ maxAliasCount: -1 });
|
|
17804
18003
|
const writes = this.fleetDocumentWrites = []; // a throw below leaves it to the next save
|
|
17805
18004
|
this.patchFleetDocument(this.rawFleetDocument, [], this.savedFleetConfigSnapshot, this.fleetConfig);
|
|
@@ -17891,6 +18090,7 @@ export class FleetManager {
|
|
|
17891
18090
|
this.logger.info({ path: this.configPath, strippedDefaults: redundantPaths.length }, "Saved fleet config (lossless patch)");
|
|
17892
18091
|
this.observeRuntimeSwitches(); // M-2255: a saved Windows runtime switch applies now
|
|
17893
18092
|
this.observeHubSwitches(); // S-51: so does a saved Hub switch
|
|
18093
|
+
this.hostMonitor?.apply();
|
|
17894
18094
|
}
|
|
17895
18095
|
/** A permission tightening is effective when its save returns, independently of the later apply job or IPC. */
|
|
17896
18096
|
refreshSavedDashboardPermissions() {
|
|
@@ -22147,6 +22347,10 @@ export class FleetManager {
|
|
|
22147
22347
|
return runWebCommand({
|
|
22148
22348
|
scope: (instance) => this.webCommandScope(instance),
|
|
22149
22349
|
platform: (instance) => this.commandPlatform(instance),
|
|
22350
|
+
report: (command) => {
|
|
22351
|
+
const lang = this.webPrefs?.read("operator").values.lang;
|
|
22352
|
+
return this.topicCommands.getWebReport(command, lang === "en" || lang === "zh-TW" ? lang : getLocale());
|
|
22353
|
+
},
|
|
22150
22354
|
ctx: (instance) => this.topicCommands.getCtxText(instance),
|
|
22151
22355
|
// Board 003648ac: a watch for the paste, armed when the daemon says it was written (raw_paste_written); one
|
|
22152
22356
|
// for a command that was not handed over is dropped.
|
|
@@ -22203,12 +22407,15 @@ export class FleetManager {
|
|
|
22203
22407
|
const refusal = this.backendCommandRefusal(instance);
|
|
22204
22408
|
if (refusal)
|
|
22205
22409
|
return { error: refusal };
|
|
22410
|
+
const target = this.backendCommandTarget(instance);
|
|
22206
22411
|
// The cached model lists, as the web's /model; an empty one is discovered once, bounded (moving to a CLI
|
|
22207
22412
|
// never signed in at startup, or probed before it was installed, must not offer an empty list).
|
|
22208
22413
|
const wanted = backendArgs(args)[0];
|
|
22209
22414
|
if (wanted && KNOWN_BACKENDS.includes(wanted))
|
|
22210
22415
|
await this.ensureModelCatalog(wanted, instance);
|
|
22211
22416
|
const step = await backendStep({ ...this.backendCommandDeps(instance, { live: false }), models: async (backend) => this.modelCatalogFor(backend, instance) }, instance, backendArgs(args));
|
|
22417
|
+
if (!this.backendTargetIs(instance, target))
|
|
22418
|
+
return { error: t("menu.click_stale") };
|
|
22212
22419
|
if (step.kind === "refuse")
|
|
22213
22420
|
return step.noop ? { text: step.text } : { error: step.text };
|
|
22214
22421
|
if (step.kind === "choose") {
|
|
@@ -22229,7 +22436,7 @@ export class FleetManager {
|
|
|
22229
22436
|
const token = randomBytes(16).toString("hex");
|
|
22230
22437
|
this.webBackendTokens.set(token, {
|
|
22231
22438
|
instance, asked: joinBackendArgs(backendArgs(args)), args: step.args, from: step.from,
|
|
22232
|
-
target
|
|
22439
|
+
target, deadline: now + CLASSIC_BACKEND_SELECTION_TIMEOUT_MS,
|
|
22233
22440
|
});
|
|
22234
22441
|
return { confirm: { token, message: step.text } };
|
|
22235
22442
|
},
|
|
@@ -23734,6 +23941,7 @@ export class FleetManager {
|
|
|
23734
23941
|
get browserBackendSignIns() {
|
|
23735
23942
|
return this.browserBackendSignInsInstance ??= new BrowserBackendSignIns({
|
|
23736
23943
|
dataDir: this.dataDir, lock: this.loginWindow,
|
|
23944
|
+
allowed: backend => backend !== "claude-code" || !claudeSubscriptionSuppressed(this.dataDir, null),
|
|
23737
23945
|
current: owner => this.browserSignInOwnerCurrent(owner),
|
|
23738
23946
|
installed: async () => {
|
|
23739
23947
|
const found = await Promise.all(ONBOARDING_BACKENDS.map(async (backend) => (await this.isCliInstalledOffLoop(backend)) ? backend : null));
|
|
@@ -23777,6 +23985,7 @@ export class FleetManager {
|
|
|
23777
23985
|
*/
|
|
23778
23986
|
get profileSignIns() {
|
|
23779
23987
|
return this.profileSignInsInstance ??= new ProfileSignIns({
|
|
23988
|
+
allowed: (backend, profile) => backend !== "claude-code" || !claudeSubscriptionSuppressed(this.dataDir, profile),
|
|
23780
23989
|
lock: this.loginWindow,
|
|
23781
23990
|
current: owner => this.browserSignInOwnerCurrent(owner),
|
|
23782
23991
|
installed: backend => this.isCliInstalledOffLoop(backend),
|
|
@@ -23872,7 +24081,8 @@ export class FleetManager {
|
|
|
23872
24081
|
signInIdentityGeneration = 0;
|
|
23873
24082
|
signInIdentitySlots = 0;
|
|
23874
24083
|
signInIdentityWaiters = [];
|
|
23875
|
-
signInIdentity(backend, profile) {
|
|
24084
|
+
signInIdentity(backend, profile) { if (backend === "claude-code" && this.dataDir && claudeSubscriptionSuppressed(this.dataDir, profile ?? null))
|
|
24085
|
+
return undefined; return this.signInIdentities.get(`${backend}\0${profile ?? ""}`)?.identity ?? undefined; }
|
|
23876
24086
|
/** A sign-in finished (or changed): forget what was read and let no read that was already running put its answer back. */
|
|
23877
24087
|
forgetSignInIdentities() { this.signInIdentityGeneration++; this.signInIdentities.clear(); this.signInIdentityReads.clear(); }
|
|
23878
24088
|
/** At most three `claude auth status` at once across the whole host, however many requests ask. */
|
|
@@ -23890,6 +24100,8 @@ export class FleetManager {
|
|
|
23890
24100
|
}
|
|
23891
24101
|
/** One `claude auth status` for a sign-in (the default one, or a credential profile's folder). */
|
|
23892
24102
|
async readSignInIdentity(target) {
|
|
24103
|
+
if (target.backend === "claude-code" && claudeSubscriptionSuppressed(this.dataDir, target.profile ?? null))
|
|
24104
|
+
return undefined;
|
|
23893
24105
|
let env, launch;
|
|
23894
24106
|
if (target.profile) {
|
|
23895
24107
|
const l = credentialProfileLaunch(this.dataDir, target.backend, target.profile);
|
|
@@ -24028,8 +24240,31 @@ export class FleetManager {
|
|
|
24028
24240
|
this.logger.debug({ err: err.message }, "Computer accounts not read");
|
|
24029
24241
|
}
|
|
24030
24242
|
}
|
|
24031
|
-
|
|
24243
|
+
const view = buildAccountsView({ targets, diskProfiles, agents, classic, fleetDefaults, usage, keepAlive, machines, installShown: this.webHostInstalls.view()?.backend ?? null,
|
|
24032
24244
|
versions: new Map(this.backendAvailabilityRows().map(row => [row.backend, row.version ?? null])), claudeInstall: await this.claudeInstallShown() });
|
|
24245
|
+
for (const cli of view.clis)
|
|
24246
|
+
for (const row of cli.rows) {
|
|
24247
|
+
if (row.backend !== "claude-code" || row.scope.kind !== "host")
|
|
24248
|
+
continue;
|
|
24249
|
+
try {
|
|
24250
|
+
const selected = readClaudeCredentialSelection(this.dataDir, row.profile);
|
|
24251
|
+
if (selected)
|
|
24252
|
+
row.credential = selected;
|
|
24253
|
+
}
|
|
24254
|
+
catch {
|
|
24255
|
+
row.credentialUnavailable = true;
|
|
24256
|
+
}
|
|
24257
|
+
if (row.credentialUnavailable || row.credential?.source === "managed") {
|
|
24258
|
+
delete row.identity;
|
|
24259
|
+
delete row.usageGroups;
|
|
24260
|
+
delete row.usageStale;
|
|
24261
|
+
delete row.usageStaleInfo;
|
|
24262
|
+
delete row.keepAlive;
|
|
24263
|
+
delete row.reconnect;
|
|
24264
|
+
row.state = row.credential?.kind || row.credentialUnavailable ? "unknown" : "not_signed_in";
|
|
24265
|
+
}
|
|
24266
|
+
}
|
|
24267
|
+
return view;
|
|
24033
24268
|
}
|
|
24034
24269
|
/**
|
|
24035
24270
|
* M-3307: the install kind as the AI accounts page is told it — paths `~`-abbreviated (Fable note 2 on #4163) — and, for a native install, the npm copy still left on
|
|
@@ -24185,8 +24420,11 @@ export class FleetManager {
|
|
|
24185
24420
|
if (!isKeepAliveBackend(backend) || isWindowsInstance(config))
|
|
24186
24421
|
return null;
|
|
24187
24422
|
let key = this.launchCredentialKey(config, backend);
|
|
24188
|
-
for (
|
|
24189
|
-
|
|
24423
|
+
for (;;) {
|
|
24424
|
+
const waiting = this.claudeCredentialChanges?.get(key) ?? this.keepAliveRenewing.get(key);
|
|
24425
|
+
if (!waiting)
|
|
24426
|
+
break;
|
|
24427
|
+
await waiting;
|
|
24190
24428
|
assertCurrent();
|
|
24191
24429
|
key = this.launchCredentialKey(config, backend);
|
|
24192
24430
|
}
|
|
@@ -24267,6 +24505,8 @@ export class FleetManager {
|
|
|
24267
24505
|
* sign-in admission reopens after a restart only once it has ended. `release()` only after its CLI has exited.
|
|
24268
24506
|
*/
|
|
24269
24507
|
acquireKeepAliveRun(backend, profile) {
|
|
24508
|
+
if (backend === "claude-code" && claudeSubscriptionSuppressed(this.dataDir, profile))
|
|
24509
|
+
return "in_use";
|
|
24270
24510
|
if (this.keepAliveInUse(backend, profile))
|
|
24271
24511
|
return "in_use";
|
|
24272
24512
|
const claim = this.loginWindow.tryClaim("keepalive", backend);
|
|
@@ -24335,6 +24575,178 @@ export class FleetManager {
|
|
|
24335
24575
|
}
|
|
24336
24576
|
return { agents, classic, fleetDefaults };
|
|
24337
24577
|
}
|
|
24578
|
+
claudeCredentialChanges = new Map();
|
|
24579
|
+
claudeCredentialConsumers(profile) {
|
|
24580
|
+
const configured = this.accountUses(), rooms = readClassicBindingsStrict(this.dataDir);
|
|
24581
|
+
if (rooms.kind === "unknown")
|
|
24582
|
+
throw new ClaudeCredentialError("unavailable");
|
|
24583
|
+
const live = [];
|
|
24584
|
+
for (const [name, daemon] of this.daemons) {
|
|
24585
|
+
const snapshot = daemon.getConfigSnapshot();
|
|
24586
|
+
if (isWindowsInstance(snapshot))
|
|
24587
|
+
continue;
|
|
24588
|
+
const backend = snapshot.backend ?? this.fleetConfig?.defaults?.backend ?? "claude-code";
|
|
24589
|
+
if (backend !== "claude-code")
|
|
24590
|
+
continue;
|
|
24591
|
+
if (resolveCredentialProfile(snapshot.backend_options?.[backend]) === profile)
|
|
24592
|
+
live.push({ name, epoch: this.lifecycle.epochOf(name), snapshot });
|
|
24593
|
+
}
|
|
24594
|
+
const users = [...new Set([...configured.agents.filter(a => a.backend === "claude-code" && a.profile === profile).map(a => a.name), ...configured.classic.filter(a => a.backend === "claude-code" && a.profile === profile).map(a => a.key), ...live.map(a => a.name)])].sort();
|
|
24595
|
+
return { users, revision: createHash("sha256").update(JSON.stringify([this.settingsGeneration, this.fleetConfig, rooms, live])).digest("hex") };
|
|
24596
|
+
}
|
|
24597
|
+
async changeClaudeCredential(profile, revision, change, actor, confirmation, authorized, ownClaim) {
|
|
24598
|
+
if (profile !== null && !accountFolderExists(this.dataDir, "claude-code", profile))
|
|
24599
|
+
throw new ClaudeCredentialError("profile-unknown");
|
|
24600
|
+
const before = this.claudeCredentialConsumers(profile);
|
|
24601
|
+
if (before.users.length && !confirmation.restart)
|
|
24602
|
+
throw new ClaudeCredentialError("in-use");
|
|
24603
|
+
if (before.users.length && confirmation.consumersRevision !== before.revision)
|
|
24604
|
+
throw new ClaudeCredentialError("conflict");
|
|
24605
|
+
const targets = [...this.daemons].filter(([, d]) => { const snap = d.getConfigSnapshot(); return !isWindowsInstance(snap) && (snap.backend ?? this.fleetConfig?.defaults?.backend ?? "claude-code") === "claude-code" && resolveCredentialProfile(snap.backend_options?.["claude-code"]) === profile; }).sort(([a], [b]) => a.localeCompare(b));
|
|
24606
|
+
const records = targets.map(([name, daemon]) => ({ name, daemon, epoch: this.lifecycle.epochOf(name), stopped: false, retired: false }));
|
|
24607
|
+
const claim = ownClaim ?? this.loginWindow.tryClaim("account", "claude-code");
|
|
24608
|
+
if (!claim || !this.loginWindow.isCurrent(claim) || claim.backend !== "claude-code" || (ownClaim && claim.kind !== "web"))
|
|
24609
|
+
throw new ClaudeCredentialError("in-use");
|
|
24610
|
+
let writerFinished;
|
|
24611
|
+
const writerLife = new Promise(resolve => { writerFinished = resolve; });
|
|
24612
|
+
this.accountWriters.add(writerLife);
|
|
24613
|
+
const key = this.credentialKey("claude-code", profile);
|
|
24614
|
+
let release;
|
|
24615
|
+
const gate = new Promise(r => { release = r; });
|
|
24616
|
+
this.claudeCredentialChanges.set(key, gate);
|
|
24617
|
+
const generation = this.settingsGeneration, configImage = JSON.stringify([this.fleetConfig, readClassicBindingsStrict(this.dataDir)]);
|
|
24618
|
+
let committed = false, released = false;
|
|
24619
|
+
const releaseStarts = () => { if (released)
|
|
24620
|
+
return; released = true; if (this.claudeCredentialChanges.get(key) === gate)
|
|
24621
|
+
this.claudeCredentialChanges.delete(key); release(); };
|
|
24622
|
+
const check = () => {
|
|
24623
|
+
if (!authorized())
|
|
24624
|
+
throw new ClaudeCredentialError("session-changed");
|
|
24625
|
+
if (this.shuttingDown || this.settingsGeneration !== generation || JSON.stringify([this.fleetConfig, readClassicBindingsStrict(this.dataDir)]) !== configImage || !this.loginWindow.isCurrent(claim))
|
|
24626
|
+
throw new ClaudeCredentialError("conflict");
|
|
24627
|
+
for (const record of records)
|
|
24628
|
+
if (this.lifecycle.epochOf(record.name) !== record.epoch || this.daemons.get(record.name) !== (record.stopped ? undefined : record.daemon))
|
|
24629
|
+
throw new ClaudeCredentialError("conflict");
|
|
24630
|
+
const prior = this.claudeCredentialMetadata(profile);
|
|
24631
|
+
if ((prior?.revision ?? 0) !== revision)
|
|
24632
|
+
throw new ClaudeCredentialError("conflict");
|
|
24633
|
+
};
|
|
24634
|
+
const handles = new Map();
|
|
24635
|
+
const locked = async (index) => {
|
|
24636
|
+
if (index < records.length)
|
|
24637
|
+
return this.lifecycle.runTransition(records[index].name, async (handle) => { handles.set(handle.name, handle); return locked(index + 1); });
|
|
24638
|
+
check();
|
|
24639
|
+
if ([...this.credentialLeases.values()].some(lease => lease.key === key && lease.starting) || [...this.credentialOrphans.values()].some(orphan => orphan.key === key)) {
|
|
24640
|
+
this.recheckCredentialOrphans();
|
|
24641
|
+
throw new ClaudeCredentialError("in-use");
|
|
24642
|
+
}
|
|
24643
|
+
if (this.claudeCredentialConsumers(profile).revision !== before.revision)
|
|
24644
|
+
throw new ClaudeCredentialError("conflict");
|
|
24645
|
+
return changeIdleClaudeCredential({
|
|
24646
|
+
assertCurrent: check, releaseStarts, restart: change !== null,
|
|
24647
|
+
commit: () => { check(); const result = this.withClaudeVault(v => v.write(profile, revision, change, actor)); committed = true; return result; },
|
|
24648
|
+
consumers: records.map(record => ({ name: record.name,
|
|
24649
|
+
quiesce: () => record.daemon.quiesceClaudeCredential(),
|
|
24650
|
+
stop: async () => {
|
|
24651
|
+
const stopping = this.stopInstance(record.name, handles.get(record.name));
|
|
24652
|
+
record.epoch++;
|
|
24653
|
+
await stopping;
|
|
24654
|
+
record.stopped = true;
|
|
24655
|
+
record.retired = await record.daemon.claudeCredentialRetired();
|
|
24656
|
+
if (!record.retired) {
|
|
24657
|
+
this.credentialOrphans.set(Symbol(record.name), { key, backend: "claude-code", profile, ended: () => record.daemon.claudeCredentialRetired() });
|
|
24658
|
+
throw new ClaudeCredentialError("unavailable");
|
|
24659
|
+
}
|
|
24660
|
+
},
|
|
24661
|
+
current: () => !this.shuttingDown && (!record.stopped || record.retired) && this.settingsGeneration === generation && this.lifecycle.epochOf(record.name) === record.epoch && this.daemons.get(record.name) === (record.stopped ? undefined : record.daemon),
|
|
24662
|
+
recover: async () => {
|
|
24663
|
+
if (!record.stopped) {
|
|
24664
|
+
const stopping = this.stopInstance(record.name, handles.get(record.name));
|
|
24665
|
+
record.epoch++;
|
|
24666
|
+
await stopping;
|
|
24667
|
+
record.stopped = true;
|
|
24668
|
+
record.retired = await record.daemon.claudeCredentialRetired();
|
|
24669
|
+
if (!record.retired) {
|
|
24670
|
+
this.credentialOrphans.set(Symbol(record.name), { key, backend: "claude-code", profile, ended: () => record.daemon.claudeCredentialRetired() });
|
|
24671
|
+
throw new ClaudeCredentialError("unavailable");
|
|
24672
|
+
}
|
|
24673
|
+
}
|
|
24674
|
+
const current = () => !this.shuttingDown && this.settingsGeneration === generation && this.lifecycle.epochOf(record.name) === record.epoch;
|
|
24675
|
+
const execution = new SettingsExecution({ current, snapshot: () => null });
|
|
24676
|
+
try {
|
|
24677
|
+
execution.assert();
|
|
24678
|
+
const config = this.fleetConfig?.instances[record.name];
|
|
24679
|
+
if (config)
|
|
24680
|
+
await this.startInstance(record.name, config, daemonTopicMode(this.fleetConfig) ?? false, "fleet-topic", false, handles.get(record.name), execution);
|
|
24681
|
+
else {
|
|
24682
|
+
const room = this.classicChannels?.getAll().find(room => room.instanceName === record.name);
|
|
24683
|
+
if (!room)
|
|
24684
|
+
throw new ClaudeCredentialError("conflict");
|
|
24685
|
+
await this.startClassicInstance(record.name, this.classicChannels.getBackendByInstance(record.name, this.fleetConfig?.defaults?.backend), this.classicChannels.getPreTaskCommand(room.channelId, room.adapterId), this.classicChannels.getModel(room.channelId, room.adapterId, this.fleetConfig?.defaults?.model), this.classicChannels.getAutoPauseAfter(room.channelId, room.adapterId, this.fleetConfig?.defaults?.auto_pause_after), handles.get(record.name), execution);
|
|
24686
|
+
}
|
|
24687
|
+
}
|
|
24688
|
+
finally {
|
|
24689
|
+
execution.close();
|
|
24690
|
+
}
|
|
24691
|
+
}
|
|
24692
|
+
}))
|
|
24693
|
+
});
|
|
24694
|
+
};
|
|
24695
|
+
try {
|
|
24696
|
+
return await locked(0);
|
|
24697
|
+
}
|
|
24698
|
+
finally {
|
|
24699
|
+
releaseStarts();
|
|
24700
|
+
if (!ownClaim)
|
|
24701
|
+
this.loginWindow.release(claim);
|
|
24702
|
+
this.accountWriters.delete(writerLife);
|
|
24703
|
+
writerFinished();
|
|
24704
|
+
if (committed) {
|
|
24705
|
+
this.forgetSignInIdentities();
|
|
24706
|
+
this.usageAfterSignIn();
|
|
24707
|
+
broadcastSseEvent(this.sseClients, "backend_login", {}, () => { });
|
|
24708
|
+
}
|
|
24709
|
+
}
|
|
24710
|
+
}
|
|
24711
|
+
claudeSetupTokensInstance = null;
|
|
24712
|
+
claudeSetupTokenOperation(owner, request) {
|
|
24713
|
+
this.claudeSetupTokensInstance ??= new ClaudeSetupTokens({ lock: this.loginWindow,
|
|
24714
|
+
metadata: profile => this.claudeCredentialMetadata(profile),
|
|
24715
|
+
commit: (profile, revision, value, actor, confirmation, current, claim) => this.changeClaudeCredential(profile, revision, { kind: "setup-token", value }, actor, confirmation, () => !this.shuttingDown && current(), claim),
|
|
24716
|
+
});
|
|
24717
|
+
return this.claudeSetupTokensInstance.operation({ ...owner, current: () => !this.shuttingDown && owner.current() }, request);
|
|
24718
|
+
}
|
|
24719
|
+
/** M-3419: private host credential store. No secret is logged or returned by the metadata API. */
|
|
24720
|
+
withClaudeVault(fn) {
|
|
24721
|
+
const vault = new ClaudeCredentialVault(this.dataDir);
|
|
24722
|
+
try {
|
|
24723
|
+
return fn(vault);
|
|
24724
|
+
}
|
|
24725
|
+
finally {
|
|
24726
|
+
vault.close();
|
|
24727
|
+
}
|
|
24728
|
+
}
|
|
24729
|
+
claudeCredentialMetadata(profile) {
|
|
24730
|
+
if (profile !== null && !accountFolderExists(this.dataDir, "claude-code", profile))
|
|
24731
|
+
throw new ClaudeCredentialError("profile-unknown");
|
|
24732
|
+
return readClaudeCredentialSelection(this.dataDir, profile);
|
|
24733
|
+
}
|
|
24734
|
+
auditClaudeCredential(actor, action, outcome) {
|
|
24735
|
+
this.withClaudeVault(vault => vault.audit(actor, null, action, null, null, outcome));
|
|
24736
|
+
}
|
|
24737
|
+
writeClaudeCredential(profile, revision, change, actor) {
|
|
24738
|
+
if (profile !== null && !accountFolderExists(this.dataDir, "claude-code", profile))
|
|
24739
|
+
throw new ClaudeCredentialError("profile-unknown");
|
|
24740
|
+
// This storage slice never changes a credential underneath a current consumer or concurrent sign-in.
|
|
24741
|
+
// The integration slice supplies the explicit idle/restart confirmation before replacing a used profile.
|
|
24742
|
+
const uses = this.accountUses();
|
|
24743
|
+
if ([...uses.agents, ...uses.classic].some(x => x.backend === "claude-code" && x.profile === profile)
|
|
24744
|
+
|| (profile !== null && uses.fleetDefaults.get("claude-code") === profile)
|
|
24745
|
+
|| this.loginWindow.holderFor("claude-code")
|
|
24746
|
+
|| this.keepAliveInUse("claude-code", profile))
|
|
24747
|
+
throw new ClaudeCredentialError("in-use");
|
|
24748
|
+
return this.withClaudeVault(vault => vault.write(profile, revision, change, actor));
|
|
24749
|
+
}
|
|
24338
24750
|
/** #3212 PR 2: Settings → Accounts → + Add account (accounts-profiles.ts). `by`: the session's label, for the fleet log. */
|
|
24339
24751
|
addAccountProfile(backend, name, by, machine) {
|
|
24340
24752
|
// #3190 Part 3c: on a paired computer the profile's folder is made by its Runtime when the first sign-in starts; this only checks what can be checked first.
|
|
@@ -24367,6 +24779,23 @@ export class FleetManager {
|
|
|
24367
24779
|
return this.machineAccounts.remove(backend, name, confirm, machine.id, machine, by); // #3190 Part 3c: that computer's Runtime deletes its own folder
|
|
24368
24780
|
const profile = typeof name === "string" ? name : "";
|
|
24369
24781
|
const shown = validCredentialProfileName(name) ? name : "(invalid)";
|
|
24782
|
+
// A profile name must not be recreated with an old managed secret still attached.
|
|
24783
|
+
const managedRefusal = () => {
|
|
24784
|
+
if (backend === "claude-code" && validCredentialProfileName(name)
|
|
24785
|
+
&& existsSync(join(this.dataDir, "credential-vault", "claude.sqlite"))) {
|
|
24786
|
+
try {
|
|
24787
|
+
if (this.claudeCredentialMetadata(name)?.kind)
|
|
24788
|
+
return { ok: false, error: "credential_connected" };
|
|
24789
|
+
}
|
|
24790
|
+
catch {
|
|
24791
|
+
return { ok: false, error: "unsafe" };
|
|
24792
|
+
}
|
|
24793
|
+
}
|
|
24794
|
+
return null;
|
|
24795
|
+
};
|
|
24796
|
+
const managed = managedRefusal();
|
|
24797
|
+
if (managed)
|
|
24798
|
+
return managed;
|
|
24370
24799
|
// #3321 review ("Cancel sign-in and remove"): the sign-in of exactly this account is ended first — no other account's, and a start whose profile is
|
|
24371
24800
|
// not known yet is not guessed at — and every Remove check below is then made as usual: what is still signing in refuses (`signing_in`).
|
|
24372
24801
|
if (opts?.cancelSignIn && validCredentialProfileName(name)) {
|
|
@@ -24382,6 +24811,9 @@ export class FleetManager {
|
|
|
24382
24811
|
// (run with the folder, once every Remove check has passed) removes that item first. AgEnD never deletes it itself.
|
|
24383
24812
|
// #3305 review: the logout holds the shared login window (no sign-in or other logout starts meanwhile), and after it
|
|
24384
24813
|
// every check is made again — who uses it, sign-ins, ClassicBot's settings — on the same folder (its identity).
|
|
24814
|
+
const afterCancel = managedRefusal();
|
|
24815
|
+
if (afterCancel)
|
|
24816
|
+
return afterCancel;
|
|
24385
24817
|
const signOutDeps = this.accountSignOutDeps ?? ACCOUNT_SIGN_OUT_DEPS;
|
|
24386
24818
|
let keychainLeft = false;
|
|
24387
24819
|
let removed;
|
|
@@ -24399,6 +24831,9 @@ export class FleetManager {
|
|
|
24399
24831
|
if (!this.loginWindow.isCurrent(claim))
|
|
24400
24832
|
return { ok: false, error: "failed" }; // the fleet is stopping
|
|
24401
24833
|
keychainLeft = out.keychainLeft === true;
|
|
24834
|
+
const beforeDelete = managedRefusal();
|
|
24835
|
+
if (beforeDelete)
|
|
24836
|
+
return beforeDelete;
|
|
24402
24837
|
return removeAccountProfile(this.dataDir, this.removalRequest(backend, name, confirm, claim), undefined, { expect: dry.identity });
|
|
24403
24838
|
});
|
|
24404
24839
|
if (!step.ok)
|
|
@@ -24528,6 +24963,8 @@ export class FleetManager {
|
|
|
24528
24963
|
if (machine)
|
|
24529
24964
|
return this.machineAccounts.signOut(backend, profile, confirm, machine.id, machine, by); // #3190 Part 3c: that computer's Runtime runs the CLI's own logout
|
|
24530
24965
|
const named = typeof profile === "string" ? profile : null;
|
|
24966
|
+
if (backend === "claude-code" && claudeSubscriptionSuppressed(this.dataDir, named))
|
|
24967
|
+
return { ok: false, error: "unsafe" };
|
|
24531
24968
|
const shown = named === null ? "(default)" : validCredentialProfileName(named) ? named : "(invalid)";
|
|
24532
24969
|
// #3305 review P2-3: the logout holds the shared login window from before it runs until its cleanup is done — no
|
|
24533
24970
|
// sign-in (chat, dashboard, install) and no other logout starts meanwhile; one already running refuses this.
|
|
@@ -24652,6 +25089,9 @@ export class FleetManager {
|
|
|
24652
25089
|
}
|
|
24653
25090
|
if (!opts.skipAuthCheck)
|
|
24654
25091
|
this.recordLoginFlow(wanted, "login", chat.userId);
|
|
25092
|
+
const backend = LOGIN_BACKEND_ALIASES[backendArg.toLowerCase()] ?? backendArg.toLowerCase();
|
|
25093
|
+
if (backend === "claude-code" && claudeSubscriptionSuppressed(this.dataDir, opts.profile ?? null))
|
|
25094
|
+
return t("login.managed_credentials");
|
|
24655
25095
|
return this.webLogin.start(backendArg, chat, opts);
|
|
24656
25096
|
}
|
|
24657
25097
|
/**
|
|
@@ -24904,6 +25344,9 @@ export class FleetManager {
|
|
|
24904
25344
|
}
|
|
24905
25345
|
/** The sign-in itself, in the web terminal, for a CLI that is installed. */
|
|
24906
25346
|
async launchSignIn(backendArg, chat, opts = {}) {
|
|
25347
|
+
const backend = LOGIN_BACKEND_ALIASES[backendArg.toLowerCase()] ?? backendArg.toLowerCase();
|
|
25348
|
+
if (backend === "claude-code" && claudeSubscriptionSuppressed(this.dataDir, opts.profile ?? null))
|
|
25349
|
+
return t("login.managed_credentials");
|
|
24907
25350
|
return this.webLogin.start(backendArg, chat, opts);
|
|
24908
25351
|
}
|
|
24909
25352
|
/** Fleet shutdown: end any web login or install window and wait for its confirmed teardown. */
|
|
@@ -24961,6 +25404,7 @@ export class FleetManager {
|
|
|
24961
25404
|
// "cancelled" is the detail both legacy onDone handlers keep quiet about —
|
|
24962
25405
|
// a stopping fleet must not announce "login failed — fleet shutdown".
|
|
24963
25406
|
await Promise.all([
|
|
25407
|
+
bounded(this.claudeSetupTokensInstance?.close(), "setup-token"),
|
|
24964
25408
|
bounded(this.browserBackendSignInsInstance?.close().then(confirmed => {
|
|
24965
25409
|
if (confirmed)
|
|
24966
25410
|
this.browserBackendSignInsInstance = null;
|
|
@@ -28153,7 +28597,8 @@ export class FleetManager {
|
|
|
28153
28597
|
resolveInstanceEffort(instanceName) {
|
|
28154
28598
|
if (isWindowsInstance(this.fleetConfig?.instances[instanceName]))
|
|
28155
28599
|
return { effort: null, source: "unset" };
|
|
28156
|
-
const own = this.fleetConfig?.instances[instanceName]?.effort
|
|
28600
|
+
const own = this.fleetConfig?.instances[instanceName]?.effort
|
|
28601
|
+
?? this.contactRoom(instanceName)?.effort;
|
|
28157
28602
|
if (own)
|
|
28158
28603
|
return { effort: own, source: "instance" };
|
|
28159
28604
|
const fallback = this.fleetConfig?.defaults?.effort;
|
|
@@ -28392,6 +28837,7 @@ export class FleetManager {
|
|
|
28392
28837
|
// ── #1806: /backend — another CLI backend, with its model and effort, in one write and one relaunch ──
|
|
28393
28838
|
/** The steps' view of this fleet (backend-command.ts). `live`: a missing or stale model list may be probed (not on the web). */
|
|
28394
28839
|
backendCommandDeps(instanceName, opts) {
|
|
28840
|
+
const classic = this.contactRoom(instanceName);
|
|
28395
28841
|
return {
|
|
28396
28842
|
currentBackend: (name) => this.backendNameForInstance(name),
|
|
28397
28843
|
currentDisplay: (name) => `${this.backendNameForInstance(name)} · ${this.resolveInstanceModel(name).display}`,
|
|
@@ -28401,7 +28847,8 @@ export class FleetManager {
|
|
|
28401
28847
|
modelKnown: (backend, model) => this.backendModelVerdict(instanceName, backend, model).ok,
|
|
28402
28848
|
effortLevels: (backend, model) => this.backendEffortLevels(instanceName, backend, model),
|
|
28403
28849
|
inherited: (key) => {
|
|
28404
|
-
const value =
|
|
28850
|
+
const value = (key === "model" && classic ? this.classicChannels?.getDefaults().model : undefined)
|
|
28851
|
+
?? getEffectiveInstanceDefaults(this.fleetConfig?.defaults)[key];
|
|
28405
28852
|
return typeof value === "string" && value ? value : undefined;
|
|
28406
28853
|
},
|
|
28407
28854
|
modelCompatible: (backend, model) => isModelCompatible(backend, model),
|
|
@@ -28409,7 +28856,8 @@ export class FleetManager {
|
|
|
28409
28856
|
const status = this.getInstanceStatus(name);
|
|
28410
28857
|
return { running: status === "running", busy: status === "running" && !this.getInstanceIdle(name), status };
|
|
28411
28858
|
},
|
|
28412
|
-
|
|
28859
|
+
confirmationNotice: () => classic?.restrictedMode === true ? t("classic.restricted_backend_notice") : undefined,
|
|
28860
|
+
t: (key, ...args) => t(classic && key === "backend.default_inherited" ? "backend.default_classic_inherited" : key, ...args),
|
|
28413
28861
|
};
|
|
28414
28862
|
}
|
|
28415
28863
|
/**
|
|
@@ -28702,14 +29150,30 @@ export class FleetManager {
|
|
|
28702
29150
|
* #1806 review: the instance a `/backend` was asked about is still this config entry — not one deleted and created
|
|
28703
29151
|
* again under the same name, or replaced by a Settings edit (both put a new object there), stopped or not.
|
|
28704
29152
|
*/
|
|
28705
|
-
|
|
29153
|
+
backendCommandTarget(instanceName) {
|
|
28706
29154
|
const instances = this.fleetConfig?.instances;
|
|
28707
|
-
|
|
29155
|
+
const fleet = instances && Object.hasOwn(instances, instanceName) ? instances[instanceName] : undefined;
|
|
29156
|
+
const rooms = (this.classicChannels?.getAll?.() ?? []).filter(room => room.instanceName === instanceName);
|
|
29157
|
+
if (fleet)
|
|
29158
|
+
return rooms.length ? undefined : { value: fleet };
|
|
29159
|
+
if (rooms.length !== 1)
|
|
29160
|
+
return undefined;
|
|
29161
|
+
try {
|
|
29162
|
+
return { value: rooms[0], classicSnapshot: createHash("sha256")
|
|
29163
|
+
.update(readFileSync(join(this.dataDir, "classicBot.yaml"))).update("\0")
|
|
29164
|
+
.update(JSON.stringify(this.fleetConfig?.defaults ?? {})).digest("hex") };
|
|
29165
|
+
}
|
|
29166
|
+
catch {
|
|
29167
|
+
return undefined;
|
|
29168
|
+
}
|
|
29169
|
+
}
|
|
29170
|
+
backendTargetIs(instanceName, target) {
|
|
29171
|
+
const now = this.backendCommandTarget(instanceName);
|
|
29172
|
+
return !!target && now?.value === target.value && now.classicSnapshot === target.classicSnapshot;
|
|
28708
29173
|
}
|
|
28709
|
-
/**
|
|
29174
|
+
/** An absent, ambiguous or unreadable room is never a backend-switch target. */
|
|
28710
29175
|
backendCommandRefusal(instanceName) {
|
|
28711
|
-
return this.
|
|
28712
|
-
? null : t("backend.classic_unsupported", instanceName);
|
|
29176
|
+
return this.backendCommandTarget(instanceName) ? null : t("classic.no_agent");
|
|
28713
29177
|
}
|
|
28714
29178
|
/**
|
|
28715
29179
|
* Apply a confirmed `/backend`: judged again first (a menu lives a minute — the backend may have moved, a CLI been
|
|
@@ -28733,6 +29197,15 @@ export class FleetManager {
|
|
|
28733
29197
|
return t("menu.click_stale");
|
|
28734
29198
|
const { plan } = step;
|
|
28735
29199
|
const shown = planDisplay(deps, plan);
|
|
29200
|
+
const room = this.contactRoom(instanceName);
|
|
29201
|
+
if (room && !Object.hasOwn(this.fleetConfig?.instances ?? {}, instanceName)) {
|
|
29202
|
+
const saved = await switchClassicRoomBackend(this, room, plan, from, stillCurrent);
|
|
29203
|
+
if (!saved.ok)
|
|
29204
|
+
return t("backend.failed", instanceName, plan.backend, saved.error);
|
|
29205
|
+
return this.getInstanceStatus(instanceName) === "running"
|
|
29206
|
+
? t("backend.switched", instanceName, plan.backend, shown.model, shown.effort)
|
|
29207
|
+
: t("backend.switched_not_running", instanceName, plan.backend, shown.model, shown.effort, this.getInstanceStatus(instanceName));
|
|
29208
|
+
}
|
|
28736
29209
|
const { value, error } = await new Promise(resolve => {
|
|
28737
29210
|
applyInstanceConfigPatch(this, instanceName, { backend: plan.backend, model: plan.model, effort: plan.effort }, (value, error) => resolve({ value, error }));
|
|
28738
29211
|
});
|
|
@@ -28820,7 +29293,7 @@ export class FleetManager {
|
|
|
28820
29293
|
await pending.respond(text);
|
|
28821
29294
|
return undefined;
|
|
28822
29295
|
}
|
|
28823
|
-
/** Start `/backend` for a
|
|
29296
|
+
/** Start the shared `/backend` picker for a Fleet instance or ClassicBot room. */
|
|
28824
29297
|
async beginBackendCommand(place, args) {
|
|
28825
29298
|
const refusal = this.backendCommandRefusal(place.instanceName);
|
|
28826
29299
|
if (refusal) {
|
|
@@ -28831,12 +29304,16 @@ export class FleetManager {
|
|
|
28831
29304
|
await place.respond(t("backend.usage"));
|
|
28832
29305
|
return;
|
|
28833
29306
|
}
|
|
28834
|
-
place = { ...place, target: this.
|
|
29307
|
+
place = { ...place, target: this.backendCommandTarget(place.instanceName) };
|
|
28835
29308
|
const deps = this.backendCommandDeps(place.instanceName, {
|
|
28836
29309
|
live: true,
|
|
28837
29310
|
onLiveProbe: () => { void place.respond(t("model.refreshing")).catch(() => { }); },
|
|
28838
29311
|
});
|
|
28839
29312
|
const step = await backendStep(deps, place.instanceName, args);
|
|
29313
|
+
if (!this.backendTargetIs(place.instanceName, place.target)) {
|
|
29314
|
+
await place.respond(t("menu.click_stale"));
|
|
29315
|
+
return;
|
|
29316
|
+
}
|
|
28840
29317
|
if (step.kind === "refuse") {
|
|
28841
29318
|
await place.respond(step.text);
|
|
28842
29319
|
return;
|
|
@@ -28868,6 +29345,10 @@ export class FleetManager {
|
|
|
28868
29345
|
/** Telegram `/backend` in a fleet topic (topic-commands) or a ClassicBot chat; the caller has checked the admin. */
|
|
28869
29346
|
async runBackendCommand(instanceName, text, userId, channelId, adapter, chatId, threadId, adapterId) {
|
|
28870
29347
|
const respond = async (reply) => (await adapter.sendText(chatId, reply, { threadId })).messageId;
|
|
29348
|
+
if (!this.isModelAdmin(userId, channelId, adapterId)) {
|
|
29349
|
+
await respond(t("permission.denied"));
|
|
29350
|
+
return;
|
|
29351
|
+
}
|
|
28871
29352
|
await this.beginBackendCommand({ instanceName, userId, channelId, adapterId, respond, adapter, adapterChatId: chatId, adapterThreadId: threadId }, backendArgs(text.replace(/^\/backend(@\S+)?/, "")));
|
|
28872
29353
|
}
|
|
28873
29354
|
/** Consume a `/backend` click: the next step, or on the confirmation the switch itself. True for every backend-select id. */
|
|
@@ -28904,6 +29385,10 @@ export class FleetManager {
|
|
|
28904
29385
|
return true;
|
|
28905
29386
|
}
|
|
28906
29387
|
const next = await backendStep(this.backendCommandDeps(pending.instanceName, { live: true }), pending.instanceName, [...step.args, choice.token]);
|
|
29388
|
+
if (!this.backendTargetIs(pending.instanceName, pending.target)) {
|
|
29389
|
+
await this.endBackendMenu(pending, t("menu.click_stale")).catch(() => { });
|
|
29390
|
+
return true;
|
|
29391
|
+
}
|
|
28907
29392
|
if (next.kind === "refuse") {
|
|
28908
29393
|
await this.endBackendMenu(pending, next.text).catch(() => { });
|
|
28909
29394
|
return true;
|
|
@@ -29206,6 +29691,7 @@ export class FleetManager {
|
|
|
29206
29691
|
reply_completion_guard: replyCompletionGuard ?? true,
|
|
29207
29692
|
...(backend ? { backend } : {}),
|
|
29208
29693
|
...(model ? { model } : {}),
|
|
29694
|
+
...(classicIdentity?.effort ? { effort: classicIdentity.effort } : {}),
|
|
29209
29695
|
...(classicIdentity?.displayName ? { display_name: classicIdentity.displayName } : {}),
|
|
29210
29696
|
...(classicIdentity?.description ? { description: classicIdentity.description } : {}),
|
|
29211
29697
|
...(autoPauseAfter !== undefined ? { auto_pause_after: autoPauseAfter } : {}),
|
|
@@ -29388,6 +29874,7 @@ export class FleetManager {
|
|
|
29388
29874
|
// because we asked it to. Set synchronously — doStopAll runs to its first
|
|
29389
29875
|
// await in the same tick as the signal handler, so no event can slip in.
|
|
29390
29876
|
this.shuttingDown = true;
|
|
29877
|
+
this.hostMonitor?.stop();
|
|
29391
29878
|
this.stopQuotaObserver?.();
|
|
29392
29879
|
this.stopQuotaObserver = null;
|
|
29393
29880
|
const quotaNoticesStopped = this.quotaNotices?.stop();
|
|
@@ -29442,7 +29929,8 @@ export class FleetManager {
|
|
|
29442
29929
|
this.ownerAppControl = null;
|
|
29443
29930
|
const ownerAppStopped = ownerAppControl?.close();
|
|
29444
29931
|
this.publicLinkAutoOpen?.stop();
|
|
29445
|
-
|
|
29932
|
+
// M-3399: a stop (a restart, an update) is not a person closing the link: the fixed link's sessions are kept.
|
|
29933
|
+
const publicStopped = this.publicWebLink?.close("fleet shutdown", undefined, { keepNamedSessions: true });
|
|
29446
29934
|
this.webRemoteAccessState?.close(); // #3008: an unsaved switch gets its last write
|
|
29447
29935
|
const sharesStopped = this.officeSharesInstance?.close(); // #2636: every Office share ends, and its tunnel
|
|
29448
29936
|
// #1386: every live "Needs you" message says the fleet stopped (capabilities revoked first) — while the
|
|
@@ -29913,6 +30401,7 @@ export class FleetManager {
|
|
|
29913
30401
|
this.reregisterClassicChannels();
|
|
29914
30402
|
this.scheduler?.reload();
|
|
29915
30403
|
this.reconcilePreviewListener();
|
|
30404
|
+
this.hostMonitor?.apply();
|
|
29916
30405
|
this.publicWebLink?.refresh();
|
|
29917
30406
|
const newInstances = this.fleetConfig.instances;
|
|
29918
30407
|
const topicMode = daemonTopicMode(this.fleetConfig);
|