@songsid/agend 2.3.5-alpha.6 → 2.3.5-alpha.8
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 +17 -0
- package/dist/accounts-view.js +33 -6
- package/dist/accounts-view.js.map +1 -1
- package/dist/apply-job.d.ts +5 -0
- package/dist/apply-job.js +10 -3
- package/dist/apply-job.js.map +1 -1
- package/dist/auth-api.d.ts +1 -1
- package/dist/auth-api.js +15 -2
- package/dist/auth-api.js.map +1 -1
- package/dist/authority/web-authority.d.ts +13 -0
- package/dist/authority/web-authority.js +12 -0
- package/dist/authority/web-authority.js.map +1 -1
- package/dist/backend/claude-code.js +47 -9
- package/dist/backend/claude-code.js.map +1 -1
- package/dist/backend/kiro.js +1 -1
- package/dist/backend/kiro.js.map +1 -1
- package/dist/build-provenance.json +1 -1
- package/dist/channel/access-manager.d.ts +1 -6
- package/dist/channel/access-manager.js +4 -94
- package/dist/channel/access-manager.js.map +1 -1
- package/dist/channel/adapters/discord.d.ts +0 -2
- package/dist/channel/adapters/discord.js +0 -8
- package/dist/channel/adapters/discord.js.map +1 -1
- package/dist/channel/adapters/telegram.d.ts +0 -3
- package/dist/channel/adapters/telegram.js +1 -30
- package/dist/channel/adapters/telegram.js.map +1 -1
- package/dist/channel/types.d.ts +0 -2
- package/dist/cli.js +1 -19
- package/dist/cli.js.map +1 -1
- package/dist/config-validator.js +2 -1
- package/dist/config-validator.js.map +1 -1
- package/dist/fleet-manager.d.ts +84 -3
- package/dist/fleet-manager.js +494 -51
- package/dist/fleet-manager.js.map +1 -1
- package/dist/general-knowledge/skills/concepts/SKILL.md +22 -7
- package/dist/general-knowledge/steering/core-rules.md +7 -5
- package/dist/hub/buttons.js +4 -2
- package/dist/hub/buttons.js.map +1 -1
- package/dist/hub/catalog.d.ts +2 -2
- package/dist/hub/catalog.js +233 -48
- package/dist/hub/catalog.js.map +1 -1
- package/dist/hub/client.js +2 -0
- package/dist/hub/client.js.map +1 -1
- package/dist/hub/compose/member.d.ts +6 -0
- package/dist/hub/compose/member.js +9 -1
- package/dist/hub/compose/member.js.map +1 -1
- package/dist/hub/compose/server.d.ts +11 -1
- package/dist/hub/compose/server.js +70 -3
- package/dist/hub/compose/server.js.map +1 -1
- package/dist/hub/directory/directory.d.ts +1 -1
- package/dist/hub/directory/directory.js +32 -23
- package/dist/hub/directory/directory.js.map +1 -1
- package/dist/hub/directory/index.d.ts +1 -1
- package/dist/hub/directory/types.d.ts +8 -2
- package/dist/hub/directory/types.js.map +1 -1
- package/dist/hub/group-policy/admin-api.d.ts +30 -0
- package/dist/hub/group-policy/admin-api.js +83 -0
- package/dist/hub/group-policy/admin-api.js.map +1 -0
- package/dist/hub/group-policy/admin-context.d.ts +23 -0
- package/dist/hub/group-policy/admin-context.js +52 -0
- package/dist/hub/group-policy/admin-context.js.map +1 -0
- package/dist/hub/group-policy/admin-control.d.ts +34 -0
- package/dist/hub/group-policy/admin-control.js +258 -0
- package/dist/hub/group-policy/admin-control.js.map +1 -0
- package/dist/hub/group-policy/admin-dto.d.ts +243 -0
- package/dist/hub/group-policy/admin-dto.js +55 -0
- package/dist/hub/group-policy/admin-dto.js.map +1 -0
- package/dist/hub/group-policy/admin-facts.d.ts +17 -0
- package/dist/hub/group-policy/admin-facts.js +33 -0
- package/dist/hub/group-policy/admin-facts.js.map +1 -0
- package/dist/hub/group-policy/admin-impact.d.ts +51 -0
- package/dist/hub/group-policy/admin-impact.js +88 -0
- package/dist/hub/group-policy/admin-impact.js.map +1 -0
- package/dist/hub/group-policy/admin-inventory.d.ts +24 -0
- package/dist/hub/group-policy/admin-inventory.js +72 -0
- package/dist/hub/group-policy/admin-inventory.js.map +1 -0
- package/dist/hub/group-policy/admin-read.d.ts +21 -0
- package/dist/hub/group-policy/admin-read.js +90 -0
- package/dist/hub/group-policy/admin-read.js.map +1 -0
- package/dist/hub/group-policy/authorization.d.ts +60 -0
- package/dist/hub/group-policy/authorization.js +292 -0
- package/dist/hub/group-policy/authorization.js.map +1 -0
- package/dist/hub/group-policy/impact-inventory.d.ts +21 -0
- package/dist/hub/group-policy/impact-inventory.js +75 -0
- package/dist/hub/group-policy/impact-inventory.js.map +1 -0
- package/dist/hub/group-policy/resources.d.ts +22 -2
- package/dist/hub/group-policy/resources.js +119 -25
- package/dist/hub/group-policy/resources.js.map +1 -1
- package/dist/hub/group-policy/store.d.ts +19 -2
- package/dist/hub/group-policy/store.js +66 -5
- package/dist/hub/group-policy/store.js.map +1 -1
- package/dist/hub/group-policy/welcome.d.ts +36 -0
- package/dist/hub/group-policy/welcome.js +55 -0
- package/dist/hub/group-policy/welcome.js.map +1 -0
- package/dist/hub/http/compose.d.ts +2 -0
- package/dist/hub/http/compose.js +133 -12
- package/dist/hub/http/compose.js.map +1 -1
- package/dist/hub/http/core.d.ts +23 -3
- package/dist/hub/http/core.js +138 -5
- package/dist/hub/http/core.js.map +1 -1
- package/dist/hub/http/deps.d.ts +10 -0
- package/dist/hub/member/pairing-api.d.ts +2 -0
- package/dist/hub/member/pairing-api.js +1 -0
- package/dist/hub/member/pairing-api.js.map +1 -1
- package/dist/hub/member/pairing-notices.d.ts +18 -0
- package/dist/hub/member/pairing-notices.js +58 -0
- package/dist/hub/member/pairing-notices.js.map +1 -0
- package/dist/hub/pairing-notices.d.ts +47 -0
- package/dist/hub/pairing-notices.js +241 -0
- package/dist/hub/pairing-notices.js.map +1 -0
- package/dist/hub/pairing.d.ts +33 -1
- package/dist/hub/pairing.js +315 -15
- package/dist/hub/pairing.js.map +1 -1
- package/dist/hub/policy.d.ts +3 -1
- package/dist/hub/policy.js +13 -6
- package/dist/hub/policy.js.map +1 -1
- package/dist/hub/protocol.d.ts +32 -0
- package/dist/hub/protocol.js +6 -1
- package/dist/hub/protocol.js.map +1 -1
- package/dist/hub/rooms.d.ts +1 -0
- package/dist/hub/rooms.js +76 -26
- package/dist/hub/rooms.js.map +1 -1
- package/dist/hub/runtime.d.ts +4 -1
- package/dist/hub/runtime.js +11 -0
- package/dist/hub/runtime.js.map +1 -1
- package/dist/hub/server.js +4 -0
- package/dist/hub/server.js.map +1 -1
- package/dist/hub/sessions.js +2 -1
- package/dist/hub/sessions.js.map +1 -1
- package/dist/hub/store.d.ts +10 -1
- package/dist/hub/store.js +7 -4
- package/dist/hub/store.js.map +1 -1
- package/dist/hub/types.d.ts +15 -2
- package/dist/locale.js +48 -36
- package/dist/locale.js.map +1 -1
- package/dist/login-controller.d.ts +9 -1
- package/dist/login-controller.js +20 -1
- package/dist/login-controller.js.map +1 -1
- package/dist/login-flows.js +4 -2
- package/dist/login-flows.js.map +1 -1
- package/dist/office-share-page.js +1 -1
- package/dist/office-share-page.js.map +1 -1
- package/dist/outbound-handlers.js +1 -1
- package/dist/outbound-handlers.js.map +1 -1
- package/dist/quickstart-api.js +2 -2
- package/dist/quickstart-api.js.map +1 -1
- package/dist/reply-buttons-controller.d.ts +5 -1
- package/dist/reply-buttons-controller.js +8 -4
- package/dist/reply-buttons-controller.js.map +1 -1
- package/dist/reply-buttons.d.ts +6 -2
- package/dist/reply-buttons.js +7 -3
- package/dist/reply-buttons.js.map +1 -1
- package/dist/runtime-api.js +10 -2
- package/dist/runtime-api.js.map +1 -1
- package/dist/settings-api.d.ts +2 -1
- package/dist/settings-api.js +7 -5
- package/dist/settings-api.js.map +1 -1
- package/dist/settings-change.d.ts +10 -0
- package/dist/settings-change.js +17 -1
- package/dist/settings-change.js.map +1 -1
- package/dist/settings-confirmation.d.ts +25 -1
- package/dist/settings-confirmation.js +11 -3
- package/dist/settings-confirmation.js.map +1 -1
- package/dist/settings-effect.js +18 -6
- package/dist/settings-effect.js.map +1 -1
- package/dist/settings-http-confirmation.d.ts +21 -0
- package/dist/settings-http-confirmation.js +74 -3
- package/dist/settings-http-confirmation.js.map +1 -1
- package/dist/signin-keepalive.d.ts +2 -0
- package/dist/signin-keepalive.js +30 -2
- package/dist/signin-keepalive.js.map +1 -1
- package/dist/structured-signin.js +3 -1
- package/dist/structured-signin.js.map +1 -1
- package/dist/tips.js +4 -4
- package/dist/tips.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.js.map +1 -1
- package/dist/ui/accounts-keepalive.js +14 -8
- package/dist/ui/accounts-manage.js +31 -13
- package/dist/ui/accounts-view.js +93 -35
- package/dist/ui/backend-signin.js +22 -4
- package/dist/ui/general-location.js +28 -14
- package/dist/ui/hub-chat-store.js +2 -1
- package/dist/ui/hub-client.js +43 -3
- package/dist/ui/hub-grant-strings.js +13 -0
- package/dist/ui/hub-group-policy.js +170 -0
- package/dist/ui/hub-group-strings.js +97 -0
- package/dist/ui/hub-owner-strings.js +6 -2
- package/dist/ui/hub-pairing-progress-strings.js +15 -0
- package/dist/ui/hub-quick-pairing.js +202 -0
- package/dist/ui/hub-quick-strings.js +43 -0
- package/dist/ui/hub-read-strings.js +7 -0
- package/dist/ui/hub-strings.js +4 -2
- package/dist/ui/hub-welcome.js +99 -0
- package/dist/ui/panel-hub.js +115 -33
- package/dist/ui/panel-log.js +2 -2
- package/dist/ui/panel-runtimes.js +14 -6
- package/dist/ui/panel-settings.js +12 -21
- package/dist/ui/runtime-cli-install.js +24 -4
- package/dist/ui/settings-apply.js +12 -5
- package/dist/ui/settings-confirm.js +28 -0
- package/dist/ui/settings-devices.js +8 -12
- package/dist/ui/settings-dialogs.js +3 -1
- package/dist/ui/settings-hub-membership.js +24 -10
- package/dist/ui/settings-hub-section.js +60 -0
- package/dist/ui/settings-hub.js +58 -13
- package/dist/ui/settings-layout.js +6 -2
- package/dist/ui/settings-named-test.js +2 -2
- package/dist/ui/settings-outside.js +1 -1
- package/dist/ui/settings-quota-notice.js +8 -6
- package/dist/ui/settings-registry.js +3 -0
- package/dist/ui/settings-restart-strings.js +17 -0
- package/dist/ui/settings-strings.js +12 -10
- package/dist/ui/shared/accounts-keepalive.css +11 -6
- package/dist/ui/shared/accounts.css +68 -18
- package/dist/ui/shared/app-i18n.js +7 -2
- package/dist/ui/shared/app-route.js +1 -1
- package/dist/ui/shared/app-shell.js +114 -7
- package/dist/ui/shared/app.css +16 -0
- package/dist/ui/shared/chat-strings.js +8 -8
- package/dist/ui/shared/hub-groups.css +26 -0
- package/dist/ui/shared/hub-owner.css +2 -2
- package/dist/ui/shared/hub-signin.css +24 -0
- package/dist/ui/shared/hub.css +1 -0
- package/dist/ui/shared/setup-host-text.js +4 -1
- package/dist/ui/shared/signin.js +3 -1
- package/dist/ui/shared/usage-dialog.js +3 -72
- package/dist/ui/shared/usage-meter.js +84 -0
- package/dist/ui/shared/view-strings.js +4 -4
- package/dist/ui/shared/web-authorize.js +4 -4
- package/dist/ui/structured-signin.js +16 -8
- package/dist/update-marker.d.ts +2 -0
- package/dist/update-marker.js.map +1 -1
- package/dist/usage/providers.d.ts +1 -0
- package/dist/usage/providers.js +13 -9
- package/dist/usage/providers.js.map +1 -1
- package/dist/web-api.d.ts +10 -1
- package/dist/web-api.js +40 -11
- package/dist/web-api.js.map +1 -1
- package/dist/web-backend-login.d.ts +16 -2
- package/dist/web-backend-login.js +14 -0
- package/dist/web-backend-login.js.map +1 -1
- package/dist/web-notices.d.ts +9 -0
- package/dist/web-notices.js +19 -0
- package/dist/web-notices.js.map +1 -1
- package/dist/web-remote-access.d.ts +6 -0
- package/dist/web-remote-access.js +10 -1
- package/dist/web-remote-access.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 +7 -0
- package/dist/web-terminal.js +14 -2
- package/dist/web-terminal.js.map +1 -1
- package/dist/windows-cli-api.d.ts +8 -0
- package/dist/windows-cli-api.js +10 -0
- package/dist/windows-cli-api.js.map +1 -1
- package/package.json +2 -1
package/dist/fleet-manager.js
CHANGED
|
@@ -335,7 +335,7 @@ import { guestSessionPolicy, localSessionPolicy, sessionVia, tokenEpoch, WebSess
|
|
|
335
335
|
import { WebNotices, WEB_NOTICES_FILE } from "./web-notices.js";
|
|
336
336
|
import { DeviceLoginRequests } from "./web-device-login.js";
|
|
337
337
|
import { isOutsideLinkOwner, OUTSIDE_LINK_OWNER, OUTSIDE_LINK_RETRY_MS, OUTSIDE_OWN_CLOSES, outsideDuration, outsideTimer, TOTP_STEP_SECONDS, WEB_REMOTE_ACCESS_FILE, WebRemoteAccess } from "./web-remote-access.js";
|
|
338
|
-
import { authorityNow, evaluateWebAuthority, HOST_OPERATOR, VERIFIED_SESSION_HOURS, webAuthorityPolicy } from "./authority/web-authority.js";
|
|
338
|
+
import { authorityNow, evaluateWebAuthority, HOST_OPERATOR, hostSessionHere, VERIFIED_SESSION_HOURS, webAuthorityPolicy } from "./authority/web-authority.js";
|
|
339
339
|
import { AuthorityStateStore } from "./authority/authority-state.js";
|
|
340
340
|
import { SessionAuthorizations } from "./authority/session-authorizations.js";
|
|
341
341
|
import { SessionAuthorizationRequests } from "./web-session-authorization.js";
|
|
@@ -359,7 +359,7 @@ import { kiroHome } from "./backend/kiro-kas-store.js";
|
|
|
359
359
|
import { CHAT_PROFILE_LOGIN_BACKENDS, credentialHomeSpec, credentialProfileHome, credentialProfileEnv, credentialProfileLogin, credentialProfileLoginCommand, credentialProfileStoreHome, credentialSwitchCarriesConversation, credentialSwitchStartsFresh, instanceCredentialProfile, listConfiguredProfiles, resolveCredentialProfile } from "./backend/credential-profile.js";
|
|
360
360
|
import { carryClaudeConversation } from "./backend/claude-carry.js";
|
|
361
361
|
import { classicProfile, mergeBackendOptions, profileKey, profileName, profileOf, readClassicBindings, readClassicBindingsStrict } from "./classic-bindings.js";
|
|
362
|
-
import { ACCOUNT_CLIS, PROFILE_CLIS, buildAccountsView, profilesOnDisk, weeklyUsage } from "./accounts-view.js";
|
|
362
|
+
import { ACCOUNT_CLIS, PROFILE_CLIS, buildAccountsView, profilesOnDisk, shortUsage, weeklyUsage } from "./accounts-view.js";
|
|
363
363
|
import { addAccountProfile, removeAccountProfile } from "./accounts-profiles.js";
|
|
364
364
|
import { signOutAccount } from "./accounts-signout.js";
|
|
365
365
|
import { MachineAccounts, machineAgents } from "./machine-accounts.js";
|
|
@@ -521,6 +521,11 @@ const CANCEL_BTN_MAX_LIFETIME_MS = 24 * 60 * 60_000;
|
|
|
521
521
|
const STALE_CANCEL_CLICK_COOLDOWN_MS = 10_000;
|
|
522
522
|
/** Orphaned-button ledger, swept at startup. Lives in the fleet data dir. */
|
|
523
523
|
const CANCEL_BTN_LEDGER_FILE = "cancel-buttons.json";
|
|
524
|
+
/**
|
|
525
|
+
* S-92: the restart marker's target for a web-only fleet's Settings restart (no chat message carries its progress). It is
|
|
526
|
+
* known by its `surface: "web"` (#3373 review P3: never by this id, which a chat connection could also be called).
|
|
527
|
+
*/
|
|
528
|
+
const WEB_RESTART_TARGET = "web-settings";
|
|
524
529
|
/**
|
|
525
530
|
* How often the cancel button's text is refreshed with elapsed working time.
|
|
526
531
|
*
|
|
@@ -1317,6 +1322,7 @@ export class FleetManager {
|
|
|
1317
1322
|
attachHubMemberExposures(api) { this.hubMemberExposureApi = api; }
|
|
1318
1323
|
/** S3c PR B: the member's pairing API, attached by S5's member composition (null: no Hub member here). */
|
|
1319
1324
|
hubMemberPairingApi = null;
|
|
1325
|
+
hubPairingNotices = null;
|
|
1320
1326
|
hubMemberPairing() { return this.hubMemberPairingApi; }
|
|
1321
1327
|
attachHubMemberPairing(api) { this.hubMemberPairingApi = api; }
|
|
1322
1328
|
generalLocationFlights = new Map();
|
|
@@ -1828,6 +1834,7 @@ export class FleetManager {
|
|
|
1828
1834
|
},
|
|
1829
1835
|
attachExposures: api => this.attachHubMemberExposures(api),
|
|
1830
1836
|
attachAttention: read => this.attachHubExecutionAttention(read),
|
|
1837
|
+
attachPairingNotices: read => { this.hubPairingNotices = read; },
|
|
1831
1838
|
pokeAttention: () => this.needsYou?.poke(),
|
|
1832
1839
|
linkState: state => { this.hubMemberLink = state; },
|
|
1833
1840
|
},
|
|
@@ -1858,6 +1865,7 @@ export class FleetManager {
|
|
|
1858
1865
|
this.hubMemberBinding = currentBinding;
|
|
1859
1866
|
this.attachHubMemberPairing(createHubMemberPairingApi({
|
|
1860
1867
|
home: this.dataDir,
|
|
1868
|
+
notices: () => this.hubPairingNotices?.() ?? [],
|
|
1861
1869
|
enabled: () => this.rawFleetConfig?.hub_member?.enabled === true,
|
|
1862
1870
|
link: () => (this.hubMemberLink === "online" ? "online" : "offline"),
|
|
1863
1871
|
hold: () => (this.hubMemberLink === "revoked" ? "revoked" : null),
|
|
@@ -2132,6 +2140,8 @@ export class FleetManager {
|
|
|
2132
2140
|
}
|
|
2133
2141
|
hubBrowserCertificate() { return this.hubRuntime?.browserCertificateSettings() ?? null; }
|
|
2134
2142
|
hubRetention() { return this.hubRuntime?.retentionSettings() ?? null; }
|
|
2143
|
+
/** #3298 S-89: this fleet's own Hub offers group permissions (the page mark that shows Settings → Hub's Group permissions row). */
|
|
2144
|
+
hubGroupPermissions() { return this.hubRuntime?.groupPermissionsAvailable() ?? false; }
|
|
2135
2145
|
observeRuntimeSwitches() {
|
|
2136
2146
|
setConfiguredRuntimeSwitches(this.fleetConfig?.runtimes);
|
|
2137
2147
|
if (!this.runtimeEffects || this.runtimeEffectsScheduled)
|
|
@@ -2452,6 +2462,8 @@ export class FleetManager {
|
|
|
2452
2462
|
startupDashboard = null;
|
|
2453
2463
|
adapterState = new Map();
|
|
2454
2464
|
adapterRetryInFlight = new Map();
|
|
2465
|
+
/** #3365 review P2: connections whose adapter could not be confirmed stopped — none is admitted for them until a restart. */
|
|
2466
|
+
adapterTeardownUnknown = new Set();
|
|
2455
2467
|
/** Web Settings secret rotation is deliberately separate from reconnect
|
|
2456
2468
|
* recovery: a rotation must build a fresh provider client with the new token,
|
|
2457
2469
|
* and stale callbacks from the old client must not win. */
|
|
@@ -3160,6 +3172,7 @@ export class FleetManager {
|
|
|
3160
3172
|
&& sessions.isCurrent(record, tokenEpoch(this.webToken)) && (!exposure || exposure.isCurrent()) };
|
|
3161
3173
|
}, baseline: () => baselines.read(), snapshot: () => baselines.snapshot(),
|
|
3162
3174
|
selfConfirm: (req, id) => this.settingsSelfConfirmation(store, req, id),
|
|
3175
|
+
totp: { state: (req, id) => this.settingsTotpState(store, req, id), confirm: (req, id, code, digest) => this.settingsTotpConfirm(store, req, id, code, digest) },
|
|
3163
3176
|
directAgentCreation: true,
|
|
3164
3177
|
job: async (id) => {
|
|
3165
3178
|
const settlement = this.settingsJobSettlements.get(id);
|
|
@@ -3195,13 +3208,40 @@ export class FleetManager {
|
|
|
3195
3208
|
const auth = authorizeSession(req, this.webToken, this.webSessions, { touch: false });
|
|
3196
3209
|
if (auth.kind !== "ok")
|
|
3197
3210
|
return null;
|
|
3211
|
+
// D3 (decision bcbb541f): on a fleet with a chat connection, a change no General can take a card for would wait for
|
|
3212
|
+
// `agend settings confirm` on the host. The host's own session, used on this computer (hostSessionHere: its code came
|
|
3213
|
+
// from `agend web` here; never bare loopback), carries that same trust — it confirms at Save, with no click added. A
|
|
3214
|
+
// change a General can take keeps its card (D1). Asked again at execution: the same session, still here, still no card.
|
|
3215
|
+
// (A web-only fleet's host operator has its own rule below, with its revocable authorization.) The noSelfConfirm changes
|
|
3216
|
+
// the leader ruled on are included: the outward Hub changes (hostLocalConfirm) and a link option turned on
|
|
3217
|
+
// (hostSessionOnly, cid-d3) — this session is exactly the one those allow.
|
|
3218
|
+
// "No card": none could be posted now, or the one tried could not be (posting failed or ran out — the view says
|
|
3219
|
+
// host_cli; #3362 review N1).
|
|
3220
|
+
const noCard = () => !this.settingsCardPossible(store, id) || store.inspect(id)?.confirmation.kind === "host_cli";
|
|
3221
|
+
if (!this.isWebOnlyFleet() && hostSessionHere(auth.session, req) && noCard()
|
|
3222
|
+
&& (store.selfConfirmable(id) || store.hostLocalConfirmable(id) || store.hostSessionConfirmable(id))) {
|
|
3223
|
+
// A card that could not be posted stays unposted (no card is attached later): fixed now, not re-read at execution,
|
|
3224
|
+
// where the store has already marked the change as confirmed from the web.
|
|
3225
|
+
const handle = auth.session.handle, postFailed = store.inspect(id)?.confirmation.kind === "host_cli";
|
|
3226
|
+
const here = () => {
|
|
3227
|
+
const now = authorizeSession(req, this.webToken, this.webSessions, { touch: false });
|
|
3228
|
+
return now.kind === "ok" && now.session.handle === handle && hostSessionHere(now.session, req) && !this.isWebOnlyFleet();
|
|
3229
|
+
};
|
|
3230
|
+
return {
|
|
3231
|
+
label: t("settings_confirm.host_operator_label"),
|
|
3232
|
+
current: () => here() && (postFailed || !this.settingsCardPossible(store, id)),
|
|
3233
|
+
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)"); },
|
|
3234
|
+
};
|
|
3235
|
+
}
|
|
3198
3236
|
// #2453 (§0.2): never over the public link — not even a named-link session that is web-verified there. #3008: except
|
|
3199
3237
|
// this computer's admin signed in from outside (the authenticator's code, over the link connections from outside
|
|
3200
3238
|
// opened): the web-only fleet's owner, judged below by the same authority as here (hostOperator).
|
|
3201
3239
|
if (gatewayRequestContext(req) && auth.session.remote !== "totp")
|
|
3202
3240
|
return null;
|
|
3203
|
-
// …and never a change that turns the named-link option on: that one needs a General's card or the host.
|
|
3204
|
-
|
|
3241
|
+
// …and never a change that turns the named-link option on: that one needs a General's card or the host. B2b (the leader's
|
|
3242
|
+
// ruling on #3352 F1; threat model A 64a289a0): the outward Hub changes (hostLocalConfirm) are the one exception — for
|
|
3243
|
+
// the host operator's own local session only (below).
|
|
3244
|
+
if (!store.selfConfirmable(id) && !store.hostLocalConfirmable(id) && !store.hostSessionConfirmable(id))
|
|
3205
3245
|
return null;
|
|
3206
3246
|
const record = auth.session, gateway = !!gatewayRequestContext(req), peer = webPeerOf(req);
|
|
3207
3247
|
const verified = () => {
|
|
@@ -3216,13 +3256,19 @@ export class FleetManager {
|
|
|
3216
3256
|
// change — the trust `agend settings confirm` has here; there is no account to be an admin of and no General to
|
|
3217
3257
|
// ask. Asked again at execution: still the host operator now (this computer, not revoked or run out), still web-only.
|
|
3218
3258
|
const hostOperator = (a) => !!a && a.adapter_id === HOST_OPERATOR.adapterId && a.user_id === HOST_OPERATOR.userId && this.isWebOnlyFleet();
|
|
3219
|
-
|
|
3259
|
+
// The host operator's own LOCAL session: its host session (the bootstrap or launch link), over loopback with no
|
|
3260
|
+
// forwarding header and no gateway (classifyWebPeer, as #3345). Only that one may Apply-now an outward Hub change, or a
|
|
3261
|
+
// link option turned on (hostSessionOnly — the outside sign-in, a gateway, never may).
|
|
3262
|
+
const hostLocal = () => hostSessionHere(record, req);
|
|
3263
|
+
if (hostOperator(actor) && (store.selfConfirmable(id) || hostLocal())) {
|
|
3220
3264
|
return {
|
|
3221
3265
|
label: t("settings_confirm.host_operator_label"),
|
|
3222
|
-
current: () => hostOperator(verified()),
|
|
3266
|
+
current: () => hostOperator(verified()) && (store.selfConfirmable(id) || hostLocal()),
|
|
3223
3267
|
done: view => { this.logger.info({ id: view.id, state: view.state }, "Settings change confirmed from the web by this computer's admin"); },
|
|
3224
3268
|
};
|
|
3225
3269
|
}
|
|
3270
|
+
if (!store.selfConfirmable(id))
|
|
3271
|
+
return null;
|
|
3226
3272
|
const chat = this.settingsChatAuthority(store, id);
|
|
3227
3273
|
if (!chat)
|
|
3228
3274
|
return null;
|
|
@@ -3244,6 +3290,99 @@ export class FleetManager {
|
|
|
3244
3290
|
done: view => this.settingsWebConfirmedNotice(view, affected, name, chat.platform),
|
|
3245
3291
|
};
|
|
3246
3292
|
}
|
|
3293
|
+
/**
|
|
3294
|
+
* alpha.6 feedback #2c — the user's decision hmsg-468cc290 (option A; decisions 28c2d3a3/0471da59 keep the second factor): on a
|
|
3295
|
+
* web-only fleet, a pending change can be confirmed on THIS computer's own page with the owner's authenticator code, by a
|
|
3296
|
+
* local admin session that is not the host operator (who already has "Apply now"), on this computer or the LAN. Never over
|
|
3297
|
+
* a link (named or quick), never a guest; only a change that can be self-confirmed at all (a named-link opener cannot); the code is checked by
|
|
3298
|
+
* the same store as signing in from outside (#3008): each time step once, the fleet-wide wrong-code limit. Asked again at
|
|
3299
|
+
* execution (`current`): the same session, still an admin here (this computer or the LAN), the fleet still web-only, the
|
|
3300
|
+
* same app still set up (not replaced, nor removed and set up again). Audited by the store under its own label; a correct and a refused use are logged.
|
|
3301
|
+
*/
|
|
3302
|
+
settingsTotpSession(req) {
|
|
3303
|
+
// Who is offered the code (the leader's ruling, (b) — Fable's view; threat model 64a289a0): on a web-only fleet, an admin
|
|
3304
|
+
// session with no chat account, on this computer (loopback, no forwarding header) or on the LAN — any such session not
|
|
3305
|
+
// otherwise allowed (a local non-host session may be another OS user). NEVER over a link, named or quick: "over a link" is
|
|
3306
|
+
// the gateway's own context, never a peer address (both links are tunnels arriving from 127.0.0.1). Never a guest.
|
|
3307
|
+
// The code is the authority; the session only carries it (#3352 security review, point 4).
|
|
3308
|
+
const allowed = () => {
|
|
3309
|
+
if (!this.isWebOnlyFleet())
|
|
3310
|
+
return null;
|
|
3311
|
+
const auth = authorizeSession(req, this.webToken, this.webSessions, { touch: false });
|
|
3312
|
+
if (auth.kind !== "ok")
|
|
3313
|
+
return null;
|
|
3314
|
+
const s = auth.session, gateway = gatewayRequestContext(req);
|
|
3315
|
+
if (s.tier !== "admin" || s.owner)
|
|
3316
|
+
return null;
|
|
3317
|
+
if (gateway)
|
|
3318
|
+
return null;
|
|
3319
|
+
const peer = webPeerOf(req);
|
|
3320
|
+
return s.surface === "local" && (peer === "loopback" || peer === "lan") ? { handle: s.handle } : null;
|
|
3321
|
+
};
|
|
3322
|
+
const first = allowed();
|
|
3323
|
+
if (!first)
|
|
3324
|
+
return null;
|
|
3325
|
+
return { handle: first.handle, current: () => { const now = allowed(); return !!now && now.handle === first.handle && !!this.webRemoteAccess()?.enrolled; } };
|
|
3326
|
+
}
|
|
3327
|
+
settingsTotpState(store, req, id) {
|
|
3328
|
+
// A link option turned on (hostSessionOnly): never a code. On a web-only fleet (no General to send it to), any session
|
|
3329
|
+
// but the host's own here is told in plain words to do it in the browser on the AgEnD computer.
|
|
3330
|
+
if (store.hostSessionConfirmable(id))
|
|
3331
|
+
return this.isWebOnlyFleet() && !this.settingsSelfConfirmation(store, req, id) ? "host_browser" : null;
|
|
3332
|
+
if (!(store.selfConfirmable(id) || store.hostLocalConfirmable(id)))
|
|
3333
|
+
return null;
|
|
3334
|
+
// Over a link (web-only fleet): never a code here — the card says to do it in the host computer's own browser, or in General.
|
|
3335
|
+
if (gatewayRequestContext(req))
|
|
3336
|
+
return this.isWebOnlyFleet() && !this.settingsSelfConfirmation(store, req, id) ? "on_host" : null;
|
|
3337
|
+
if (!this.settingsTotpSession(req))
|
|
3338
|
+
return null;
|
|
3339
|
+
if (this.settingsSelfConfirmation(store, req, id))
|
|
3340
|
+
return null; // "Apply now" already (the host operator here)
|
|
3341
|
+
return this.webRemoteAccess()?.enrolled ? "ready" : "not_set_up";
|
|
3342
|
+
}
|
|
3343
|
+
settingsTotpConfirm(store, req, id, code, digest) {
|
|
3344
|
+
if (!(store.selfConfirmable(id) || store.hostLocalConfirmable(id)) || this.settingsSelfConfirmation(store, req, id))
|
|
3345
|
+
return { error: "not_here" };
|
|
3346
|
+
const local = this.settingsTotpSession(req), access = this.webRemoteAccess();
|
|
3347
|
+
if (!local || !local.current() || !access?.enrolled)
|
|
3348
|
+
return { error: "not_here" };
|
|
3349
|
+
// #3352 security review, point 2: the code confirms exactly the change the page showed — checked before the code is.
|
|
3350
|
+
if (digest !== store.confirmDigest(id))
|
|
3351
|
+
return { error: "changed" };
|
|
3352
|
+
const shown = store.inspectHost(id)?.view.summary ?? [];
|
|
3353
|
+
// #3355 review (Prism P2): the code's authority is the app it came from. Bound to that enrollment through execution — an
|
|
3354
|
+
// app replaced, or removed and set up again, while the change waits ends it, for good (a later match never revives it).
|
|
3355
|
+
const enrollment = access.enrollment;
|
|
3356
|
+
const v = access.verify(code);
|
|
3357
|
+
if (v.kind === "ok") {
|
|
3358
|
+
if (!enrollment)
|
|
3359
|
+
return { error: "not_here" };
|
|
3360
|
+
this.logger.info({ id, handle: local.handle }, "Settings change confirmed on this computer with the authenticator code");
|
|
3361
|
+
let lost = false;
|
|
3362
|
+
const current = () => {
|
|
3363
|
+
if (!lost && !(local.current() && this.webRemoteAccess()?.enrollment === enrollment))
|
|
3364
|
+
lost = true;
|
|
3365
|
+
return !lost;
|
|
3366
|
+
};
|
|
3367
|
+
return { label: t("settings_confirm.totp_label"), current, audit: { confirmed_with: "authenticator_code", summary: shown },
|
|
3368
|
+
done: view => { this.logger.info({ id: view.id, state: view.state }, "Settings change confirmed with the authenticator code: done"); } };
|
|
3369
|
+
}
|
|
3370
|
+
if (v.kind === "paused")
|
|
3371
|
+
return { error: "paused", retryAfterMs: v.retryAfterMs };
|
|
3372
|
+
if (v.kind === "not_enrolled")
|
|
3373
|
+
return { error: "not_here" };
|
|
3374
|
+
if (v.kind === "unavailable")
|
|
3375
|
+
return { error: "unavailable" };
|
|
3376
|
+
if (v.skewSteps !== null)
|
|
3377
|
+
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");
|
|
3378
|
+
this.logger.info({ id, handle: local.handle }, "Settings change: a wrong authenticator code was refused");
|
|
3379
|
+
if (v.paused) {
|
|
3380
|
+
this.logger.warn({ waitMs: v.retryAfterMs }, "Authenticator codes paused after wrong codes");
|
|
3381
|
+
this.recordWebNotice("fleet", t("outside.notice_paused", outsideDuration(v.retryAfterMs), v.wrong));
|
|
3382
|
+
return { error: "paused", retryAfterMs: v.retryAfterMs };
|
|
3383
|
+
}
|
|
3384
|
+
return { error: "wrong" };
|
|
3385
|
+
}
|
|
3247
3386
|
/**
|
|
3248
3387
|
* alpha.2 (M-2300; #2973's agent requests, junsion's §6): on a fleet with no chat connection there is no General to
|
|
3249
3388
|
* post an agent's Windows request in — it waited for `agend settings confirm` on the host. Its owner (decision
|
|
@@ -3619,13 +3758,25 @@ export class FleetManager {
|
|
|
3619
3758
|
return updateNativeWindowsInstance(this, name, edit, () => allowed() && sameTarget() && (execution.completed || execution.current()), execution);
|
|
3620
3759
|
} });
|
|
3621
3760
|
}
|
|
3761
|
+
/**
|
|
3762
|
+
* D3: whether a General could take this change's confirmation card now — the same authority and routes
|
|
3763
|
+
* promptSettingsChange posts by. False: it would wait for the host's command (confirmation kind host_cli).
|
|
3764
|
+
*/
|
|
3765
|
+
settingsCardPossible(store, id) {
|
|
3766
|
+
const authority = this.settingsChatAuthority(store, id);
|
|
3767
|
+
if (!authority)
|
|
3768
|
+
return false;
|
|
3769
|
+
const excluded = new Set(store.affectedConnections(id));
|
|
3770
|
+
return Object.keys(this.fleetConfig?.instances ?? {}).some(name => !!this.settingsGeneralRoute(name, authority.platform, excluded));
|
|
3771
|
+
}
|
|
3622
3772
|
async promptSettingsChange(store, view) {
|
|
3623
3773
|
const generation = this.settingsGeneration;
|
|
3624
3774
|
const authority = this.settingsChatAuthority(store, view.id);
|
|
3625
3775
|
if (!authority) {
|
|
3626
3776
|
this.logger.info({ id: view.id }, "Settings authority is unknown or spans platforms; host CLI confirmation required");
|
|
3627
|
-
return;
|
|
3777
|
+
return this.settingsNoCardReason(null, [...store.affectedConnections(view.id), ...(store.authorityOf(view.id)?.connections ?? [])], false);
|
|
3628
3778
|
}
|
|
3779
|
+
let attempted = false;
|
|
3629
3780
|
const excluded = new Set(store.affectedConnections(view.id));
|
|
3630
3781
|
for (const name of Object.keys(this.fleetConfig?.instances ?? {})) {
|
|
3631
3782
|
const route = this.settingsGeneralRoute(name, authority.platform, excluded);
|
|
@@ -3638,6 +3789,7 @@ export class FleetManager {
|
|
|
3638
3789
|
&& route.current() && authority.current();
|
|
3639
3790
|
if (!current())
|
|
3640
3791
|
continue;
|
|
3792
|
+
attempted = true;
|
|
3641
3793
|
try {
|
|
3642
3794
|
const posted = this.postNonceButtonPromptOrThrow({ prefix: "settings-confirm:", alertType: "clear_confirm",
|
|
3643
3795
|
instanceName: name, adapterId, adapter, chatId, threadId: topic,
|
|
@@ -3681,6 +3833,39 @@ export class FleetManager {
|
|
|
3681
3833
|
}
|
|
3682
3834
|
// No platform confirmation was reachable. Host inspection is still required.
|
|
3683
3835
|
this.logger.info({ id: view.id }, "Settings change requires local `agend settings confirm <id>`");
|
|
3836
|
+
return this.settingsNoCardReason(authority.platform, store.affectedConnections(view.id), attempted);
|
|
3837
|
+
}
|
|
3838
|
+
/**
|
|
3839
|
+
* alpha.6 feedback #2c: why no General could take a change's confirm card, so the page says what is missing in plain words
|
|
3840
|
+
* (the user's decision hmsg-77256f66: never "type a host command"). `platform` null: the authority is unknown or spans
|
|
3841
|
+
* platforms. `attempted`: a General route existed and posting to it failed.
|
|
3842
|
+
*/
|
|
3843
|
+
settingsNoCardReason(platform, affected, attempted) {
|
|
3844
|
+
const channels = this.fleetConfig?.channels ?? (this.fleetConfig?.channel ? [this.fleetConfig.channel] : []);
|
|
3845
|
+
if (!channels.length)
|
|
3846
|
+
return "no_chat";
|
|
3847
|
+
if (attempted)
|
|
3848
|
+
return "post_failed";
|
|
3849
|
+
// No General at all comes first: then there is no authority to resolve either (the primary General's is unknown).
|
|
3850
|
+
if (!Object.values(this.fleetConfig?.instances ?? {}).some(cfg => cfg?.general_topic === true))
|
|
3851
|
+
return "no_general";
|
|
3852
|
+
// #3352 review N1: "spans platforms" only when it does — the connections the change touches are on more than one platform.
|
|
3853
|
+
// Any other unresolved authority (a duplicated or missing connection id): no specific reason; the page says the general one.
|
|
3854
|
+
if (!platform) {
|
|
3855
|
+
const touched = new Set(affected);
|
|
3856
|
+
const types = new Set(channels.filter(ch => touched.has(ch.id ?? ch.type)).map(ch => ch.type));
|
|
3857
|
+
return types.size > 1 ? "cross_platform" : undefined;
|
|
3858
|
+
}
|
|
3859
|
+
const excluded = new Set(affected);
|
|
3860
|
+
const generals = Object.keys(this.fleetConfig?.instances ?? {}).filter(name => this.fleetConfig?.instances[name]?.general_topic === true)
|
|
3861
|
+
.filter(name => { const id = this.getInstanceAdapterId(name), adapter = this.getAdapterForInstance(name); return !!id && !!adapter && adapter.type === platform && !excluded.has(id); });
|
|
3862
|
+
if (!generals.length)
|
|
3863
|
+
return "no_general";
|
|
3864
|
+
if (!generals.some(name => this.adapterState.get(this.getInstanceAdapterId(name))?.status === "connected"))
|
|
3865
|
+
return "chat_disconnected";
|
|
3866
|
+
if (!generals.some(name => !!this.getGroupIdForInstance(name) && String(this.fleetConfig?.instances[name]?.topic_id ?? "") !== ""))
|
|
3867
|
+
return "no_topic";
|
|
3868
|
+
return "post_failed";
|
|
3684
3869
|
}
|
|
3685
3870
|
kiroMigrateDeps() {
|
|
3686
3871
|
let token;
|
|
@@ -9935,35 +10120,64 @@ export class FleetManager {
|
|
|
9935
10120
|
...(threadId ? { threadId } : {}),
|
|
9936
10121
|
messageId,
|
|
9937
10122
|
};
|
|
10123
|
+
return this.launchTrackedFullRestart(target, text => this.reportFullRestartFailure(adapter, chatId, threadId, messageId, text), () => this.startUpdateProgressMonitor(adapter));
|
|
10124
|
+
}
|
|
10125
|
+
/**
|
|
10126
|
+
* S-92: the same tracked reload for a web-only fleet's Settings restart — no chat message to carry its progress: the
|
|
10127
|
+
* marker names the web (WEB_RESTART_TARGET), a refusal is a fleet Notice, and the next fleet says it is back as one.
|
|
10128
|
+
*/
|
|
10129
|
+
async requestWebFullRestart(onLateFailure) {
|
|
10130
|
+
const target = { surface: "web", adapterId: WEB_RESTART_TARGET, chatId: WEB_RESTART_TARGET, messageId: `settings-${Date.now()}` };
|
|
10131
|
+
const say = async (text) => { this.recordWebNotice("fleet", text); };
|
|
10132
|
+
// No progress monitor reads the marker for the web: a helper that fails after its launch is said here, and settled.
|
|
10133
|
+
return this.launchTrackedFullRestart(target, say, null, (detail) => {
|
|
10134
|
+
void say(t("restart.full_launch_failed"));
|
|
10135
|
+
onLateFailure?.(detail);
|
|
10136
|
+
});
|
|
10137
|
+
}
|
|
10138
|
+
/**
|
|
10139
|
+
* S-92: a fleet (with no chat connection) that comes up from a web-only Settings restart says it is back as a fleet
|
|
10140
|
+
* Notice — the restart was announced as one. Anything else (a chat restart, an update, a plain boot): nothing here.
|
|
10141
|
+
*/
|
|
10142
|
+
async announceWebRestartDone(pending) {
|
|
10143
|
+
if (!pending || updateProgressOperation(pending.progress) !== "full-restart" || pending.progress.target.surface !== "web")
|
|
10144
|
+
return false;
|
|
10145
|
+
const { createRequire } = await import("node:module");
|
|
10146
|
+
const version = createRequire(import.meta.url)("../package.json").version ?? "unknown";
|
|
10147
|
+
return this.recordWebNotice("fleet", t("restart.settings_done", version));
|
|
10148
|
+
}
|
|
10149
|
+
async launchTrackedFullRestart(target, fail, startMonitor,
|
|
10150
|
+
/** After the launch: the helper failed before the hand-off (with no progress monitor to say so). */
|
|
10151
|
+
lateFailure) {
|
|
9938
10152
|
// This check is synchronous with the marker write below. A second command
|
|
9939
10153
|
// cannot slip through between them on Node's event loop and replace the
|
|
9940
10154
|
// first command's delivery target or launch a competing restart helper.
|
|
9941
10155
|
if (this.shuttingDown || isUpdateInProgress(this.dataDir)) {
|
|
9942
|
-
this.logger.warn({ adapterId:
|
|
9943
|
-
await
|
|
10156
|
+
this.logger.warn({ adapterId: target.adapterId }, "Full restart refused because another planned restart is active");
|
|
10157
|
+
await fail(t("restart.full_busy"));
|
|
9944
10158
|
return false;
|
|
9945
10159
|
}
|
|
9946
10160
|
if (!persistFullRestartProgress(this.dataDir, target)) {
|
|
9947
|
-
this.logger.error({ adapterId:
|
|
9948
|
-
await
|
|
10161
|
+
this.logger.error({ adapterId: target.adapterId }, "Full restart marker could not be persisted — reload refused");
|
|
10162
|
+
await fail(t("restart.full_launch_failed"));
|
|
9949
10163
|
return false;
|
|
9950
10164
|
}
|
|
9951
10165
|
const ownedMarker = readUpdateProgress(this.dataDir);
|
|
9952
10166
|
if (!ownedMarker) {
|
|
9953
|
-
this.logger.error({ adapterId:
|
|
9954
|
-
await
|
|
10167
|
+
this.logger.error({ adapterId: target.adapterId }, "Full restart marker disappeared after persistence — reload refused");
|
|
10168
|
+
await fail(t("restart.full_launch_failed"));
|
|
9955
10169
|
return false;
|
|
9956
10170
|
}
|
|
9957
10171
|
this.lastUpdateProgressText = null;
|
|
9958
|
-
|
|
10172
|
+
startMonitor?.();
|
|
9959
10173
|
await this.waitForFullRestartIdleGrace();
|
|
9960
10174
|
// An update can begin while the idle wait yields. Never launch a second
|
|
9961
10175
|
// process replacement against a marker we no longer own.
|
|
9962
10176
|
if (this.shuttingDown || !this.isOwnedFullRestartMarker(ownedMarker.startedAt, target)) {
|
|
9963
|
-
this.logger.warn({ adapterId:
|
|
10177
|
+
this.logger.warn({ adapterId: target.adapterId }, "Full restart superseded during idle wait — reload refused");
|
|
9964
10178
|
if (this.isOwnedFullRestartMarker(ownedMarker.startedAt, target))
|
|
9965
10179
|
clearUpdateMarker(this.dataDir);
|
|
9966
|
-
await
|
|
10180
|
+
await fail(t("restart.full_busy"));
|
|
9967
10181
|
return false;
|
|
9968
10182
|
}
|
|
9969
10183
|
let helper;
|
|
@@ -9974,7 +10188,7 @@ export class FleetManager {
|
|
|
9974
10188
|
this.logger.error({ err }, "Full restart helper failed to spawn — reload refused");
|
|
9975
10189
|
if (this.isOwnedFullRestartMarker(ownedMarker.startedAt, target))
|
|
9976
10190
|
clearUpdateMarker(this.dataDir);
|
|
9977
|
-
await
|
|
10191
|
+
await fail(t("restart.full_launch_failed"));
|
|
9978
10192
|
return false;
|
|
9979
10193
|
}
|
|
9980
10194
|
void helper.completion.then(result => {
|
|
@@ -9992,6 +10206,7 @@ export class FleetManager {
|
|
|
9992
10206
|
: `reload helper exited before process hand-off (code ${result.code ?? "null"}, signal ${result.signal ?? "none"})`;
|
|
9993
10207
|
this.logger.error({ result }, "Full restart helper exited before the fleet began shutting down");
|
|
9994
10208
|
setUpdateProgressStage(this.dataDir, "failed", { error: detail });
|
|
10209
|
+
lateFailure?.(detail);
|
|
9995
10210
|
});
|
|
9996
10211
|
return true;
|
|
9997
10212
|
}
|
|
@@ -10368,7 +10583,8 @@ export class FleetManager {
|
|
|
10368
10583
|
// from an earlier start) and no AgEnD tmux server was ever recorded — gets the one own-tmux notice. A cleanly stopped
|
|
10369
10584
|
// 2.3 fleet leaves no window ids (no migration journal), so this, not the journal, is the evidence. Read before any
|
|
10370
10585
|
// agent of this start writes its own.
|
|
10371
|
-
this
|
|
10586
|
+
// Persisted before this start records server.json (see ownTmuxStartDecision).
|
|
10587
|
+
this.ownTmuxUpgradedHome = FleetManager.ownTmuxStartDecision(getAgendHome(), bundled.previous, this.logger);
|
|
10372
10588
|
this.tmuxHold = null;
|
|
10373
10589
|
TmuxManager.setHold(null);
|
|
10374
10590
|
if (bundled) {
|
|
@@ -10713,7 +10929,7 @@ export class FleetManager {
|
|
|
10713
10929
|
this.reportClassicUnrecoverableIds();
|
|
10714
10930
|
})();
|
|
10715
10931
|
progressStart = adapterStartup.then(() => {
|
|
10716
|
-
if (pendingUpdateProgress) {
|
|
10932
|
+
if (pendingUpdateProgress && pendingUpdateProgress.progress.target.surface !== "web") {
|
|
10717
10933
|
const saved = pendingUpdateProgress.progress.target;
|
|
10718
10934
|
const target = {
|
|
10719
10935
|
adapter: this.adapters.get(saved.adapterId),
|
|
@@ -10897,6 +11113,9 @@ export class FleetManager {
|
|
|
10897
11113
|
// #named-link-ttl: a named link with auto_open comes back now — after the web listener and the chat connections.
|
|
10898
11114
|
this.startPublicLinkAutoOpen();
|
|
10899
11115
|
}
|
|
11116
|
+
else {
|
|
11117
|
+
await this.announceWebRestartDone(pendingUpdateProgress);
|
|
11118
|
+
}
|
|
10900
11119
|
// #3008: connections from outside were on when the fleet stopped: the link opens again (its address is new for a
|
|
10901
11120
|
// quick link — Settings shows it on this computer).
|
|
10902
11121
|
if (this.outsideOn())
|
|
@@ -11339,6 +11558,8 @@ export class FleetManager {
|
|
|
11339
11558
|
const state = this.adapterState.get(adapterId);
|
|
11340
11559
|
if (this.shuttingDown || !state || state.retryTimer || this.adapterRetryInFlight.has(adapterId))
|
|
11341
11560
|
return;
|
|
11561
|
+
if (this.adapterTeardownUnknown.has(adapterId))
|
|
11562
|
+
return; // #3365 review P2: held until a restart, never retried
|
|
11342
11563
|
const delay = Math.min(INITIAL_DELAY_MS * Math.pow(2, Math.min(state.retryCount, 6)), MAX_DELAY_MS);
|
|
11343
11564
|
this.logger.info({ adapterId, attempt: state.retryCount + 1, delay_ms: delay }, "Scheduling adapter retry");
|
|
11344
11565
|
const timer = setTimeout(() => {
|
|
@@ -11593,6 +11814,8 @@ export class FleetManager {
|
|
|
11593
11814
|
assertSettingsLease(`connection:${this.dataDir}:${ownerId}`, operation?.owner);
|
|
11594
11815
|
if (this.shuttingDown || this.settingsGeneration !== generation)
|
|
11595
11816
|
throw new Error("adapter admission superseded");
|
|
11817
|
+
if (this.adapterTeardownUnknown.has(ownerId))
|
|
11818
|
+
throw new Error("an earlier adapter for this connection could not be confirmed stopped — restart AgEnD");
|
|
11596
11819
|
};
|
|
11597
11820
|
check();
|
|
11598
11821
|
const botToken = process.env[channelConfig.bot_token_env];
|
|
@@ -11752,6 +11975,8 @@ export class FleetManager {
|
|
|
11752
11975
|
assertSettingsLease(`connection:${this.dataDir}:${ownerId}`, operation?.owner);
|
|
11753
11976
|
if (this.shuttingDown || this.settingsGeneration !== generation)
|
|
11754
11977
|
throw new Error("adapter admission superseded");
|
|
11978
|
+
if (this.adapterTeardownUnknown.has(ownerId))
|
|
11979
|
+
throw new Error("an earlier adapter for this connection could not be confirmed stopped — restart AgEnD");
|
|
11755
11980
|
};
|
|
11756
11981
|
check();
|
|
11757
11982
|
const botToken = process.env[channelConfig.bot_token_env];
|
|
@@ -16990,19 +17215,47 @@ export class FleetManager {
|
|
|
16990
17215
|
}
|
|
16991
17216
|
return names.some(n => ["output.log", "session-id"].some(f => existsSync(join(instancesDir, n, f))));
|
|
16992
17217
|
}
|
|
17218
|
+
/** Where an upgraded home's not-yet-dispatched own-tmux notice is kept across restarts; only a dispatch clears it. */
|
|
17219
|
+
static ownTmuxPendingPath(agendHome) { return join(agendHome, "tmux", "own-server-notice-pending"); }
|
|
17220
|
+
/**
|
|
17221
|
+
* Fleet start's decision, made before this start records server.json: an upgraded home is persisted as owing the
|
|
17222
|
+
* notice. A restart before the notice is dispatched (a slow first start; alpha.6 leg M on the real Mac) would otherwise
|
|
17223
|
+
* read the just-recorded server as "not an upgrade" and drop it.
|
|
17224
|
+
*/
|
|
17225
|
+
static ownTmuxStartDecision(agendHome, previous, logger) {
|
|
17226
|
+
const upgraded = FleetManager.ownTmuxUpgraded(agendHome, previous);
|
|
17227
|
+
if (upgraded)
|
|
17228
|
+
FleetManager.persistOwnTmuxPending(agendHome, logger);
|
|
17229
|
+
return upgraded;
|
|
17230
|
+
}
|
|
17231
|
+
/** Record that this home owes the own-tmux notice (unless it was already posted). */
|
|
17232
|
+
static persistOwnTmuxPending(agendHome, logger) {
|
|
17233
|
+
if (existsSync(join(agendHome, "tmux", "own-server-announced")))
|
|
17234
|
+
return;
|
|
17235
|
+
try {
|
|
17236
|
+
mkdirSync(join(agendHome, "tmux"), { recursive: true });
|
|
17237
|
+
writeFileSync(FleetManager.ownTmuxPendingPath(agendHome), `${new Date().toISOString()}\n`);
|
|
17238
|
+
}
|
|
17239
|
+
catch (err) {
|
|
17240
|
+
logger?.warn({ err }, "Could not record the pending own-tmux notice");
|
|
17241
|
+
}
|
|
17242
|
+
}
|
|
16993
17243
|
announceOwnTmux() {
|
|
16994
17244
|
const marker = join(getAgendHome(), "tmux", "own-server-announced");
|
|
17245
|
+
const pending = FleetManager.ownTmuxPendingPath(getAgendHome());
|
|
16995
17246
|
if (existsSync(marker))
|
|
16996
17247
|
return;
|
|
16997
17248
|
// Only a home an earlier AgEnD ran its agents in (on the system tmux) has something to be told (Fable #3312 N3):
|
|
16998
17249
|
// agent state from before this start and no recorded AgEnD tmux server (set at fleet start), or a migration journal
|
|
16999
17250
|
// (2.3 window ids found). A fresh home is marked without a notice.
|
|
17000
|
-
|
|
17251
|
+
// A pending notice persisted by an earlier start counts too: that start's server record must not hide the upgrade.
|
|
17252
|
+
const upgraded = this.ownTmuxUpgradedHome || existsSync(pending) || existsSync(join(getAgendHome(), "tmux-migration.json"));
|
|
17001
17253
|
if (upgraded && !this.notifyFleetError(t("tmux.own_server_notice"), { throttle: false }))
|
|
17002
17254
|
return;
|
|
17003
17255
|
try {
|
|
17004
17256
|
mkdirSync(dirname(marker), { recursive: true });
|
|
17005
17257
|
writeFileSync(marker, `${new Date().toISOString()}\n`);
|
|
17258
|
+
rmSync(pending, { force: true });
|
|
17006
17259
|
}
|
|
17007
17260
|
catch (err) {
|
|
17008
17261
|
this.logger.warn({ err }, "Could not record that the own-tmux notice was posted");
|
|
@@ -17121,6 +17374,17 @@ export class FleetManager {
|
|
|
17121
17374
|
this.emitSseEvent("notice", { notice, unread: store.unread() });
|
|
17122
17375
|
return true;
|
|
17123
17376
|
}
|
|
17377
|
+
/** #3373 review P2: recordWebNotice for a notice that must be on disk first — true only once it was written. */
|
|
17378
|
+
recordWebNoticeDurable(kind, text) {
|
|
17379
|
+
if (!this.webOnlyPromptPlace())
|
|
17380
|
+
return false;
|
|
17381
|
+
const store = this.webNoticeStore();
|
|
17382
|
+
const notice = store?.addDurable({ kind, text: stripPlaceRefs(text) }) ?? null;
|
|
17383
|
+
if (!notice)
|
|
17384
|
+
return false;
|
|
17385
|
+
this.emitSseEvent("notice", { notice, unread: store.unread() });
|
|
17386
|
+
return true;
|
|
17387
|
+
}
|
|
17124
17388
|
static FLEET_ERROR_THROTTLE_MS = 10 * 60_000;
|
|
17125
17389
|
fleetErrorNotices = new Map();
|
|
17126
17390
|
/**
|
|
@@ -18617,8 +18881,12 @@ export class FleetManager {
|
|
|
18617
18881
|
const r = store.confirmEnrollment(owner.handle, code);
|
|
18618
18882
|
if (r === "ok") {
|
|
18619
18883
|
this.logger.info({ again: had }, "Authenticator app set up for connections from outside");
|
|
18620
|
-
if (had)
|
|
18884
|
+
if (had) {
|
|
18621
18885
|
this.endOutsideSessions();
|
|
18886
|
+
// #3327: an authenticator set up again is announced where the owner looks (web Notices on a web-only fleet), so a
|
|
18887
|
+
// set-up they did not make is noticed.
|
|
18888
|
+
this.notifyFleetError(t("outside.reenrolled_notice"));
|
|
18889
|
+
}
|
|
18622
18890
|
}
|
|
18623
18891
|
return r;
|
|
18624
18892
|
}
|
|
@@ -18628,8 +18896,11 @@ export class FleetManager {
|
|
|
18628
18896
|
if (!owner || !store || !owner.current())
|
|
18629
18897
|
return "not_here";
|
|
18630
18898
|
// #3008 review (Prism P2 1): shut at once whatever the disk says; say so when it could not be saved (retried).
|
|
18899
|
+
const had = store.enrolled;
|
|
18631
18900
|
const saved = store.remove();
|
|
18632
18901
|
this.closeOutsideLink("outside removed");
|
|
18902
|
+
if (had)
|
|
18903
|
+
this.notifyFleetError(t("outside.removed_notice")); // #3327: as above
|
|
18633
18904
|
this.logger.info({ saved }, "Authenticator app removed; connections from outside off");
|
|
18634
18905
|
return saved ? "ok" : "unsaved";
|
|
18635
18906
|
}
|
|
@@ -20525,8 +20796,10 @@ export class FleetManager {
|
|
|
20525
20796
|
}
|
|
20526
20797
|
catch { /* safe metadata only */ }
|
|
20527
20798
|
broadcastSseEvent(this.sseClients, "backend_login", {}, err => this.logger.debug({ err }, "backend_login event failed"));
|
|
20528
|
-
if (event.phase === "done")
|
|
20799
|
+
if (event.phase === "done") {
|
|
20529
20800
|
this.forgetSignInIdentities(); // a sign-in may be a different account now
|
|
20801
|
+
this.keepAliveAfterSignIn(event.backend, null); // its file changed, whoever is watching: a "needs sign-in" left from before is no longer the answer
|
|
20802
|
+
}
|
|
20530
20803
|
this.needsYou?.poke();
|
|
20531
20804
|
if (!this.browserSignInOwnerCurrent(owner))
|
|
20532
20805
|
return;
|
|
@@ -20561,7 +20834,7 @@ export class FleetManager {
|
|
|
20561
20834
|
start: (backend, chat, opts) => this.startWebDashboardLogin(backend, chat, opts),
|
|
20562
20835
|
accessToken: sink => this.loginController?.webAccessToken(sink) ?? null,
|
|
20563
20836
|
isActiveFor: sink => this.loginController?.isActiveFor(sink) ?? false,
|
|
20564
|
-
cancelFor: sink => this.loginController?.cancelFor(sink) ?? Promise.resolve(false),
|
|
20837
|
+
cancelFor: (sink, opts) => this.loginController?.cancelFor(sink, opts) ?? Promise.resolve(false),
|
|
20565
20838
|
cancel: () => this.cancelLoginSession(),
|
|
20566
20839
|
notice: ({ shown, label, handle }) => this.notifyFleetError(t("login.web_dashboard_notice", shown, label, handle.slice(0, 8))),
|
|
20567
20840
|
// No details in the event: each page reads its own view (GET /ui/backend-login), as its session may see it.
|
|
@@ -20674,8 +20947,9 @@ export class FleetManager {
|
|
|
20674
20947
|
diskProfiles.set(backend, rows);
|
|
20675
20948
|
}
|
|
20676
20949
|
const { agents, classic, fleetDefaults } = this.accountUses();
|
|
20677
|
-
// Weekly usage, from the usage panel's own (cached, never forced) read.
|
|
20950
|
+
// Weekly and short-window (5h) usage, from the usage panel's own (cached, never forced) read.
|
|
20678
20951
|
const usage = new Map();
|
|
20952
|
+
const shortWindow = new Map();
|
|
20679
20953
|
const ids = new Map(); // provider id → backend\0profile
|
|
20680
20954
|
for (const backend of ACCOUNT_CLIS) {
|
|
20681
20955
|
const pid = usageProviderIdForBackend(backend);
|
|
@@ -20689,9 +20963,14 @@ export class FleetManager {
|
|
|
20689
20963
|
const payload = await Promise.race([getUsageSnapshot(false, undefined, { allowStale: true }), new Promise(r => { const tm = setTimeout(() => r(null), usageWaitMs); tm.unref?.(); })]);
|
|
20690
20964
|
for (const provider of payload?.providers ?? []) {
|
|
20691
20965
|
const at = ids.get(provider.id);
|
|
20692
|
-
|
|
20693
|
-
|
|
20966
|
+
if (!at)
|
|
20967
|
+
continue;
|
|
20968
|
+
const w = weeklyUsage(provider);
|
|
20969
|
+
if (w)
|
|
20694
20970
|
usage.set(at, w);
|
|
20971
|
+
const sh = shortUsage(provider);
|
|
20972
|
+
if (sh)
|
|
20973
|
+
shortWindow.set(at, sh);
|
|
20695
20974
|
}
|
|
20696
20975
|
}
|
|
20697
20976
|
catch { /* the view without usage */ }
|
|
@@ -20718,7 +20997,26 @@ export class FleetManager {
|
|
|
20718
20997
|
this.logger.debug({ err: err.message }, "Computer accounts not read");
|
|
20719
20998
|
}
|
|
20720
20999
|
}
|
|
20721
|
-
return buildAccountsView({ targets, diskProfiles, agents, classic, fleetDefaults, usage, keepAlive, machines });
|
|
21000
|
+
return buildAccountsView({ targets, diskProfiles, agents, classic, fleetDefaults, usage, shortUsage: shortWindow, keepAlive, machines });
|
|
21001
|
+
}
|
|
21002
|
+
/**
|
|
21003
|
+
* 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
|
|
21004
|
+
* "the last check" is not the one from before the sign-in. Never awaited, and never allowed to fail the sign-in's own follow-up.
|
|
21005
|
+
*/
|
|
21006
|
+
keepAliveAfterSignIn(backend, profile) {
|
|
21007
|
+
if (!isKeepAliveBackend(backend))
|
|
21008
|
+
return;
|
|
21009
|
+
// Building the service can throw as well as the check, and the follow-up of a sign-in (waking its agents) must not depend on either.
|
|
21010
|
+
const failed = (err) => { try {
|
|
21011
|
+
this.logger.debug({ err: String(err?.message ?? err), backend }, "Keep-alive check after a sign-in failed");
|
|
21012
|
+
}
|
|
21013
|
+
catch { /* nothing to say it to */ } };
|
|
21014
|
+
try {
|
|
21015
|
+
this.keepAliveService().tick({ only: { backend, profile } }).catch(failed);
|
|
21016
|
+
}
|
|
21017
|
+
catch (err) {
|
|
21018
|
+
failed(err);
|
|
21019
|
+
}
|
|
20722
21020
|
}
|
|
20723
21021
|
/** #3292: the keep-alive service (built on first use, so the Accounts view can read settings before startup finishes). */
|
|
20724
21022
|
keepAliveService() {
|
|
@@ -20962,11 +21260,16 @@ export class FleetManager {
|
|
|
20962
21260
|
* or the login window held for this backend by a sign-in whose profile is not known yet); see accounts-profiles.ts.
|
|
20963
21261
|
* The fleet log records who removed which backend's profile — never what was in it.
|
|
20964
21262
|
*/
|
|
20965
|
-
async removeAccountProfile(backend, name, confirm, by, machine) {
|
|
21263
|
+
async removeAccountProfile(backend, name, confirm, by, machine, opts) {
|
|
20966
21264
|
if (machine)
|
|
20967
21265
|
return this.machineAccounts.remove(backend, name, confirm, machine.id, machine, by); // #3190 Part 3c: that computer's Runtime deletes its own folder
|
|
20968
21266
|
const profile = typeof name === "string" ? name : "";
|
|
20969
21267
|
const shown = validCredentialProfileName(name) ? name : "(invalid)";
|
|
21268
|
+
// #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
|
|
21269
|
+
// 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`).
|
|
21270
|
+
if (opts?.cancelSignIn && validCredentialProfileName(name) && await this.loginController?.cancelAccount(backend, name).catch(() => false)) {
|
|
21271
|
+
this.logger.info({ backend, profile: shown, by }, "Sign-in cancelled for Remove");
|
|
21272
|
+
}
|
|
20970
21273
|
const refused = (r) => { if (!r.ok)
|
|
20971
21274
|
this.logger.info({ backend, profile: shown, by, refused: r.error }, "Credential profile removal refused"); return r; };
|
|
20972
21275
|
// #3212 PR 3: on macOS, Claude Code keeps the account's token in the Keychain, outside the folder — its own logout
|
|
@@ -21549,6 +21852,7 @@ export class FleetManager {
|
|
|
21549
21852
|
async recoverBackendInstances(backend, deadlineMs = POST_LOGIN_RECOVERY_DEADLINE_MS,
|
|
21550
21853
|
/** #1699 part 2: the login just signed in — a profile, or null for the backend's default one. */
|
|
21551
21854
|
profile = null) {
|
|
21855
|
+
this.keepAliveAfterSignIn(backend, profile ?? null);
|
|
21552
21856
|
const woken = [];
|
|
21553
21857
|
const restarted = [];
|
|
21554
21858
|
const pending = [];
|
|
@@ -22761,7 +23065,11 @@ export class FleetManager {
|
|
|
22761
23065
|
// re-enters this path.
|
|
22762
23066
|
const selfMentionRe = new RegExp(`<@${adapterBotUserId}>`, "g");
|
|
22763
23067
|
const strippedText = text.replace(selfMentionRe, "").trim();
|
|
22764
|
-
|
|
23068
|
+
// A bare @mention says nothing by itself, so it is dropped (unchanged)... unless it is a REPLY that carries the mention: then the
|
|
23069
|
+
// replied-to message is what is being asked about, and it travels as reply_to_text (#3340). Telegram already forwards this shape
|
|
23070
|
+
// ("/chat @bot (you)"). Only with the mention in the text: an empty reply to one of our own messages (addressed through #2551, a
|
|
23071
|
+
// sticker or embed only) stays dropped, never an empty turn quoting our own answer (Fable #3342 F1).
|
|
23072
|
+
if (!strippedText && !msg.attachments?.length && !(msg.replyToText && mentionTag && addressText.includes(mentionTag)))
|
|
22765
23073
|
return;
|
|
22766
23074
|
const selfMarker = mentionWorld?.botUsername ? `@${mentionWorld.botUsername} (you)` : `${mentionTag} (you)`;
|
|
22767
23075
|
const cleanText = text.replace(selfMentionRe, selfMarker).trim();
|
|
@@ -25972,7 +26280,7 @@ export class FleetManager {
|
|
|
25972
26280
|
* audit notice — and only once all of that holds is the attempt written to
|
|
25973
26281
|
* disk and fsynced, before anything spawns.
|
|
25974
26282
|
*/
|
|
25975
|
-
async requestSettingsSelfRestart(
|
|
26283
|
+
async requestSettingsSelfRestart(requestedJobId, key) {
|
|
25976
26284
|
// A retry after a lost response must not restart a second time. The key is
|
|
25977
26285
|
// recorded on the job, which survives the restart it triggers.
|
|
25978
26286
|
const already = this.applyJobs.findByRestartKey(key);
|
|
@@ -25989,6 +26297,31 @@ export class FleetManager {
|
|
|
25989
26297
|
error: `fleet.yaml and the running configuration disagree on ${this.fleetSignatureMismatch.join(", ")} — check daemon.log before restarting`,
|
|
25990
26298
|
};
|
|
25991
26299
|
}
|
|
26300
|
+
// S-92 (#3326 D1): a restart asked for the pending changes themselves (`requestedJobId` null) — the restart notice
|
|
26301
|
+
// with no Settings job behind it (a hand edit of fleet.yaml). Only when a fleet-level restart is pending
|
|
26302
|
+
// (settingsRestartPending, the notice's own test): its newest job carries it, else one is made here to carry it, once
|
|
26303
|
+
// (the next ask finds that one). Everything below is the same path as a Save's restart.
|
|
26304
|
+
let jobId = requestedJobId;
|
|
26305
|
+
if (jobId === null) {
|
|
26306
|
+
// One already asked for is in flight (its row "running"): never a second job, nor a second restart.
|
|
26307
|
+
// #3373 review P2: a consumed restart job (and its row) runs until the next process settles it (settleAfterRestart)
|
|
26308
|
+
// or its launch fails (finish) — so this sees only a restart still in flight, never an old one.
|
|
26309
|
+
if (this.applyJobs.all().some(item => item.restart_key && item.targets.some(r => r.target === APPLY_FLEET_TARGET && r.status === "running"))) {
|
|
26310
|
+
return { ok: false, status: 409, error: "a restart is already running" };
|
|
26311
|
+
}
|
|
26312
|
+
const pending = this.settingsRestartPending();
|
|
26313
|
+
if (!pending)
|
|
26314
|
+
return { ok: false, status: 409, error: "no fleet-level change is pending any more" };
|
|
26315
|
+
if (pending.job_id)
|
|
26316
|
+
jobId = pending.job_id;
|
|
26317
|
+
else {
|
|
26318
|
+
const made = this.applyJobs.create(`restart-pending:${key}`, [{ target: APPLY_FLEET_TARGET, kind: "restart" }]);
|
|
26319
|
+
this.applyJobs.setTargetStatus(made.id, APPLY_FLEET_TARGET, "restart-required");
|
|
26320
|
+
this.applyJobs.finish(made.id);
|
|
26321
|
+
this.logger.info({ jobId: made.id, keys: pending.keys }, "Settings restart for pending changes with no Settings job: a job now carries it");
|
|
26322
|
+
jobId = made.id;
|
|
26323
|
+
}
|
|
26324
|
+
}
|
|
25992
26325
|
const job = this.applyJobs.get(jobId);
|
|
25993
26326
|
const row = job?.targets.find(item => item.target === APPLY_FLEET_TARGET);
|
|
25994
26327
|
if (!job || !row || row.status !== "restart-required") {
|
|
@@ -26009,7 +26342,9 @@ export class FleetManager {
|
|
|
26009
26342
|
return {
|
|
26010
26343
|
ok: false,
|
|
26011
26344
|
status: 503,
|
|
26012
|
-
error:
|
|
26345
|
+
error: this.isWebOnlyFleet()
|
|
26346
|
+
? "the restart rate-limit file cannot be read"
|
|
26347
|
+
: "the restart rate-limit file cannot be read — send /restart in General",
|
|
26013
26348
|
};
|
|
26014
26349
|
}
|
|
26015
26350
|
return {
|
|
@@ -26034,12 +26369,23 @@ export class FleetManager {
|
|
|
26034
26369
|
// the admins are. Refusing when it cannot be posted is the same rule as
|
|
26035
26370
|
// refusing when the progress marker cannot be written: no untraceable
|
|
26036
26371
|
// restarts.
|
|
26037
|
-
|
|
26038
|
-
|
|
26372
|
+
// S-92 (leader's ruling, cid-a6-ui-feedback): a web-only fleet has no General to announce it in — its trace is the
|
|
26373
|
+
// dashboard's own fleet Notice (where its admins are) plus the log line below. Every other guard above and below is
|
|
26374
|
+
// the same. A chat fleet is unchanged: General is the trace.
|
|
26375
|
+
const webOnly = this.isWebOnlyFleet();
|
|
26376
|
+
const notice = webOnly ? null : await this.postSelfRestartNotice();
|
|
26377
|
+
if (webOnly) {
|
|
26378
|
+
if (!this.recordWebNoticeDurable("fleet", t("restart.settings_triggered"))) {
|
|
26379
|
+
this.logger.error({ jobId }, "Could not record the Settings-triggered restart as a fleet Notice — refusing to restart silently");
|
|
26380
|
+
return { ok: false, status: 503, error: "couldn't record the restart; try again" };
|
|
26381
|
+
}
|
|
26382
|
+
this.logger.info({ jobId, trace: "web-notice" }, "Settings-triggered restart announced as a fleet Notice (web-only fleet)");
|
|
26383
|
+
}
|
|
26384
|
+
else if (!notice) {
|
|
26039
26385
|
return {
|
|
26040
26386
|
ok: false,
|
|
26041
26387
|
status: 409,
|
|
26042
|
-
error: "no chat channel is available to announce the restart
|
|
26388
|
+
error: "no chat channel is available to announce the restart",
|
|
26043
26389
|
};
|
|
26044
26390
|
}
|
|
26045
26391
|
// Consume the row: it moves to running, which is also what lets the next
|
|
@@ -26048,11 +26394,23 @@ export class FleetManager {
|
|
|
26048
26394
|
const target = current.targets.find(item => item.target === APPLY_FLEET_TARGET);
|
|
26049
26395
|
if (target)
|
|
26050
26396
|
target.status = "running";
|
|
26397
|
+
// #3373 review P2: the job runs again while its restart does (its deadline is the restart's): the next process
|
|
26398
|
+
// settles it (settleAfterRestart only touches running jobs), a failed launch finishes it.
|
|
26399
|
+
current.status = "running";
|
|
26400
|
+
delete current.finishedAt;
|
|
26401
|
+
current.restartStartedAt = Date.now(); // its time counts from now, not from the Save (#3373 review P3)
|
|
26051
26402
|
current.restart_key = key;
|
|
26052
26403
|
current.deadlineMs = SELF_RESTART_DEADLINE_MS;
|
|
26053
26404
|
});
|
|
26054
26405
|
this.emitSseEvent("apply_progress", viewOf(this.applyJobs.get(jobId)));
|
|
26055
|
-
|
|
26406
|
+
// #3373 review P2: a web restart's helper that fails after it was launched (the answer already said "restarting") is
|
|
26407
|
+
// said as a fleet Notice by requestWebFullRestart, and its job settles here as failed.
|
|
26408
|
+
const settleLateFailure = (detail) => {
|
|
26409
|
+
this.applyJobs.setTargetStatus(jobId, APPLY_FLEET_TARGET, "failed", detail);
|
|
26410
|
+
this.applyJobs.finish(jobId, detail);
|
|
26411
|
+
this.emitSseEvent("apply_progress", viewOf(this.applyJobs.get(jobId)));
|
|
26412
|
+
};
|
|
26413
|
+
const launched = await (notice ? this.requestFullRestart(notice.adapter, notice.chatId, notice.threadId, notice.messageId) : this.requestWebFullRestart(settleLateFailure))
|
|
26056
26414
|
.catch(err => {
|
|
26057
26415
|
this.logger.error({ err }, "Settings-triggered self restart failed to launch");
|
|
26058
26416
|
return false;
|
|
@@ -26867,6 +27225,9 @@ export class FleetManager {
|
|
|
26867
27225
|
let store;
|
|
26868
27226
|
const generation = this.settingsGeneration;
|
|
26869
27227
|
let replaced = false;
|
|
27228
|
+
// S-91: whether an adapter ran before. One that did not is never "restored" by starting it with the old token (the token
|
|
27229
|
+
// that would not start it); a failed start goes back to the background retry instead.
|
|
27230
|
+
const wasRunning = this.adapters.has(job.connectionId);
|
|
26870
27231
|
try {
|
|
26871
27232
|
if (!channel || !envKey || !allowed.has(envKey))
|
|
26872
27233
|
throw new Error("connection is not configured for secret rotation");
|
|
@@ -26916,17 +27277,29 @@ export class FleetManager {
|
|
|
26916
27277
|
else
|
|
26917
27278
|
process.env[envKey] = oldToken;
|
|
26918
27279
|
}
|
|
26919
|
-
|
|
26920
|
-
|
|
26921
|
-
|
|
26922
|
-
|
|
26923
|
-
|
|
26924
|
-
|
|
26925
|
-
|
|
26926
|
-
|
|
26927
|
-
|
|
26928
|
-
|
|
26929
|
-
|
|
27280
|
+
if (!wasRunning) {
|
|
27281
|
+
// S-91: it was not running: the new adapter that did not come up is taken down (never left half-started), and
|
|
27282
|
+
// the connection is the background retry's again, as before the token was entered.
|
|
27283
|
+
if (await this.dropAdapterAfterFailedStart(job.connectionId, message))
|
|
27284
|
+
job.result = "rolled_back";
|
|
27285
|
+
else {
|
|
27286
|
+
job.result = "rollback_failed";
|
|
27287
|
+
job.error = "the new adapter could not be confirmed stopped; restart AgEnD";
|
|
27288
|
+
}
|
|
27289
|
+
}
|
|
27290
|
+
else {
|
|
27291
|
+
// Build a fresh adapter from the restored token. If the old adapter
|
|
27292
|
+
// was stopped already, this is the only safe way to return to the
|
|
27293
|
+
// previous runtime without claiming a disk-only rollback succeeded.
|
|
27294
|
+
const cleanup = { owner: execution?.owner ?? Symbol("secret-cleanup"), assert: () => {
|
|
27295
|
+
if (this.shuttingDown || this.settingsGeneration !== generation)
|
|
27296
|
+
throw new Error("secret cleanup superseded");
|
|
27297
|
+
} };
|
|
27298
|
+
const restored = await this.rebuildAdapterForSecret(job.connectionId, this.secureConnectionChannel(job.connectionId) ?? channel, true, cleanup);
|
|
27299
|
+
if (!restored)
|
|
27300
|
+
throw new Error("adapter rollback did not become connected");
|
|
27301
|
+
job.result = "rolled_back";
|
|
27302
|
+
}
|
|
26930
27303
|
}
|
|
26931
27304
|
catch (rollbackErr) {
|
|
26932
27305
|
this.logger.error({ connectionId: job.connectionId, reason: safeSecretError(rollbackErr, oldToken, [secret]) }, "Settings connection secret rollback failed");
|
|
@@ -26944,6 +27317,57 @@ export class FleetManager {
|
|
|
26944
27317
|
secret = "";
|
|
26945
27318
|
}
|
|
26946
27319
|
}
|
|
27320
|
+
/**
|
|
27321
|
+
* S-91: how a connection stands against what this process set up at start. "same": its adapter start ran (and failed, or
|
|
27322
|
+
* found no token), so starting it now is what the background retry does. "changed": its binding waits for the restart —
|
|
27323
|
+
* never started live, whatever its role (#3365 review P2). "added": #1519 P6's rule.
|
|
27324
|
+
*/
|
|
27325
|
+
startedWithConnection(connectionId, channel) {
|
|
27326
|
+
const started = this.startupFleetConfig;
|
|
27327
|
+
const list = started?.channels ?? (started?.channel ? [started.channel] : []);
|
|
27328
|
+
const then = list.find(item => (item.id ?? item.type) === connectionId);
|
|
27329
|
+
return !then ? "added" : isDeepStrictEqual(then, channel) ? "same" : "changed";
|
|
27330
|
+
}
|
|
27331
|
+
/**
|
|
27332
|
+
* S-91: a token's live start for a connection that was not running did not come up. Whatever adapter it left is taken
|
|
27333
|
+
* down (handlers off, stopped, unregistered), and the connection goes back to the background retry with the error.
|
|
27334
|
+
*/
|
|
27335
|
+
async dropAdapterAfterFailedStart(connectionId, error) {
|
|
27336
|
+
const fresh = this.adapters.get(connectionId);
|
|
27337
|
+
// #3365 review P3: the primary's prune interval goes with it (a later start sets it up again, once).
|
|
27338
|
+
if (this.getPrimaryAdapterId() === connectionId && this.sessionPruneTimer) {
|
|
27339
|
+
clearInterval(this.sessionPruneTimer);
|
|
27340
|
+
this.sessionPruneTimer = null;
|
|
27341
|
+
}
|
|
27342
|
+
let stopped = true;
|
|
27343
|
+
if (fresh) {
|
|
27344
|
+
fresh.removeAllListeners();
|
|
27345
|
+
stopped = await fresh.stop().then(() => true, () => false);
|
|
27346
|
+
if (this.adapters.get(connectionId) === fresh)
|
|
27347
|
+
this.adapters.delete(connectionId);
|
|
27348
|
+
if (this.worlds.get(connectionId)?.adapter === fresh)
|
|
27349
|
+
this.worlds.delete(connectionId);
|
|
27350
|
+
if (this.adapter === fresh)
|
|
27351
|
+
this.adapter = null;
|
|
27352
|
+
}
|
|
27353
|
+
const previous = this.adapterState.get(connectionId);
|
|
27354
|
+
if (previous?.retryTimer)
|
|
27355
|
+
clearTimeout(previous.retryTimer);
|
|
27356
|
+
if (!stopped) {
|
|
27357
|
+
// #3365 review P2: a stop that failed leaves the provider client's end unknown (it may still poll the bot). Said so —
|
|
27358
|
+
// never "rolled back" — and no adapter for this connection is admitted again in this process: no retry, and every
|
|
27359
|
+
// start refuses it (startSingleAdapterOwned / startAdditionalAdapterOwned). A restart of AgEnD clears it.
|
|
27360
|
+
this.adapterTeardownUnknown.add(connectionId);
|
|
27361
|
+
this.adapterState.set(connectionId, { status: "failed", retryCount: previous?.retryCount ?? 0, lastError: "the new adapter could not be confirmed stopped — restart AgEnD" });
|
|
27362
|
+
this.logger.error({ connectionId, reason: error }, "Settings connection secret: the adapter that did not start could not be confirmed stopped");
|
|
27363
|
+
return false;
|
|
27364
|
+
}
|
|
27365
|
+
if (this.shuttingDown || !this.secureConnectionChannel(connectionId))
|
|
27366
|
+
return true;
|
|
27367
|
+
this.adapterState.set(connectionId, { status: "retrying", retryCount: previous?.retryCount ?? 0, lastError: error });
|
|
27368
|
+
this.scheduleAdapterRetry(connectionId);
|
|
27369
|
+
return true;
|
|
27370
|
+
}
|
|
26947
27371
|
/** Stop the old provider client and construct a new one from process.env. */
|
|
26948
27372
|
async rebuildAdapterForSecret(connectionId, channel, force = false, execution) {
|
|
26949
27373
|
const generation = this.settingsGeneration;
|
|
@@ -26951,11 +27375,25 @@ export class FleetManager {
|
|
|
26951
27375
|
const check = () => { execution?.assert(); if (!current())
|
|
26952
27376
|
throw new Error("adapter operation superseded"); };
|
|
26953
27377
|
check();
|
|
27378
|
+
// S-91: never two starts of one connection at once. A background retry in flight finishes first: it read the token
|
|
27379
|
+
// before this one was stored, so it gives way (its own check), or it came up and is replaced below like any adapter.
|
|
27380
|
+
const inFlight = this.adapterRetryInFlight.get(connectionId);
|
|
27381
|
+
if (inFlight) {
|
|
27382
|
+
await inFlight.catch(() => { });
|
|
27383
|
+
check();
|
|
27384
|
+
}
|
|
26954
27385
|
const old = this.adapters.get(connectionId);
|
|
26955
|
-
// No adapter:
|
|
26956
|
-
//
|
|
26957
|
-
|
|
26958
|
-
|
|
27386
|
+
// No adapter: one this process started with, unchanged since (its start failed, or it had no token), starts now — S-91,
|
|
27387
|
+
// the way the background retry starts it, the primary included. One added since starts now when it is not the primary
|
|
27388
|
+
// and the fleet runs connections (#1519 P6). One changed since (its binding pending) never does: the secret is valid on
|
|
27389
|
+
// disk and the next start adopts it with its binding.
|
|
27390
|
+
if (!old && !force) {
|
|
27391
|
+
const since = this.startedWithConnection(connectionId, channel);
|
|
27392
|
+
if (since === "changed")
|
|
27393
|
+
return false;
|
|
27394
|
+
if (since === "added" && (this.getPrimaryAdapterId() === connectionId || this.adapters.size === 0))
|
|
27395
|
+
return false;
|
|
27396
|
+
}
|
|
26959
27397
|
if (!old) {
|
|
26960
27398
|
const pending = this.adapterState.get(connectionId)?.retryTimer;
|
|
26961
27399
|
if (pending)
|
|
@@ -27012,10 +27450,15 @@ export class FleetManager {
|
|
|
27012
27450
|
this.adapterState.set(connectionId, { status: "connected", retryCount: 0 });
|
|
27013
27451
|
return true;
|
|
27014
27452
|
}
|
|
27453
|
+
// S-91: a retry timer set while it was coming up (the in-flight retry's own, giving way) must not start it a second time.
|
|
27454
|
+
const settled = () => { const st = this.adapterState.get(connectionId); if (st?.retryTimer) {
|
|
27455
|
+
clearTimeout(st.retryTimer);
|
|
27456
|
+
st.retryTimer = undefined;
|
|
27457
|
+
} return true; };
|
|
27015
27458
|
while (performance.now() < deadline) {
|
|
27016
27459
|
const health = fresh.getHealthSnapshot?.();
|
|
27017
27460
|
if (health?.status === "connected" || this.adapterState.get(connectionId)?.status === "connected")
|
|
27018
|
-
return
|
|
27461
|
+
return settled();
|
|
27019
27462
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
27020
27463
|
check();
|
|
27021
27464
|
}
|