@platless/axom-cli 0.5.9 → 0.6.52
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/README.md +25 -6
- package/dist/axom-patch/cli/README.md +129 -12
- package/dist/axom-patch/cli/account-limits/generate.py +15 -12
- package/dist/axom-patch/cli/account-limits/kimi-proxy.mjs +20 -3
- package/dist/axom-patch/cli/claude-account-limits.json +9 -9
- package/dist/axom-patch/cli/claude-replay-lifecycle.json +16 -0
- package/dist/axom-patch/cli/codex-account-limits.json +11 -11
- package/dist/axom-patch/cli/codex-terminal-output.json +16 -0
- package/dist/axom-patch/cli/commandcode-account-limits.json +9 -9
- package/dist/axom-patch/cli/kimi-quota.mjs +12 -0
- package/dist/axom-patch/cli/kimi-subagents.mjs +173 -0
- package/dist/axom-patch/cli/nightly-task.md +55 -13
- package/dist/axom-patch/cli/probes/claude-replay-lifecycle.mjs +31 -0
- package/dist/axom-patch/cli/probes/codex-terminal-output.mjs +33 -0
- package/dist/axom-patch/cli/probes/kimi-subagent-subwork.mjs +82 -0
- package/dist/axom-patch/cli/probes/zcode-env-account.mjs +81 -0
- package/dist/axom-patch/cli/probes/zcode-subagent-subwork.mjs +7 -0
- package/dist/axom-patch/cli/qoder/dist/axom-acp-compat.mjs +1687 -0
- package/dist/axom-patch/cli/qoder/releases/1.1.75.json +277 -0
- package/dist/axom-patch/cli/qoder-background-terminal.md +13 -6
- package/dist/axom-patch/cli/qoder-foreground-output.md +14 -8
- package/dist/axom-patch/cli/qoder-native-acp.json +227 -0
- package/dist/axom-patch/cli/qoder-steering.md +20 -25
- package/dist/axom-patch/cli/qoder-subagent-subwork.md +17 -68
- package/dist/axom-patch/cli/runtime.json +19 -19
- package/dist/axom-patch/cli/zcode/env-account.mjs +13 -0
- package/dist/axom-patch/cli/zcode/generate-env-account.py +52 -0
- package/dist/axom-patch/cli/zcode-account-limits.json +10 -11
- package/dist/axom-patch/cli/zcode-env-account.json +58 -0
- package/dist/axom-patch/cli/zcode-models.json +9 -10
- package/dist/axom-patch/cli/zcode-subagent-subwork.json +10 -11
- package/dist/cli.js +11 -45
- package/dist/commands/auth.js +4 -1
- package/dist/commands/knowledge.js +47 -0
- package/dist/commands/update.js +126 -3
- package/dist/commands/workstation.js +101 -164
- package/dist/commands/workstationRegistrations.js +116 -0
- package/dist/credentialBroker.js +13 -2
- package/dist/credentials.js +16 -0
- package/dist/install/claude/commands.js +15 -15
- package/dist/keepers/terminal/keeper.mjs +1089 -673
- package/dist/keepers/terminal/manifest.json +4 -4
- package/dist/mcp.js +1 -1
- package/dist/native/darwin-x64/axom-quic +0 -0
- package/dist/workstation/acp/acpAgents.js +113 -102
- package/dist/workstation/acp/acpClient.js +26 -0
- package/dist/workstation/acp/builds/install/npm.js +99 -10
- package/dist/workstation/acp/initializeResponse.js +6 -1
- package/dist/workstation/acp/managedPatches.js +189 -25
- package/dist/workstation/acp/managedRuntime.js +314 -0
- package/dist/workstation/acp/outbox.js +12 -5
- package/dist/workstation/acp/patchAssets.js +40 -0
- package/dist/workstation/acp/permission.js +2 -2
- package/dist/workstation/acp/processor/checkpoint.js +26 -34
- package/dist/workstation/acp/processor/control.js +7 -80
- package/dist/workstation/acp/processor/jsonrpc.js +8 -0
- package/dist/workstation/acp/processor/runtime.js +5 -81
- package/dist/workstation/acp/processor/session.js +54 -82
- package/dist/workstation/acp/processor/state.js +7 -13
- package/dist/workstation/acp/processor/step.js +3 -20
- package/dist/workstation/acp/processor/test/fixtureLog.js +9 -16
- package/dist/workstation/acp/processor/transport/local.js +19 -3
- package/dist/workstation/acp/processor/updates.js +156 -105
- package/dist/workstation/acp/processorSession.js +20 -173
- package/dist/workstation/acp/registry/catalog.js +65 -39
- package/dist/workstation/acp/registry/launch.js +16 -1
- package/dist/workstation/acp/switching.js +0 -3
- package/dist/workstation/acp/test/fakeAgent.js +13 -0
- package/dist/workstation/acp/test/keeperWorld.js +32 -3
- package/dist/workstation/acp/test/raw/sources.js +16 -130
- package/dist/workstation/acp/test/realAdapter.js +1 -47
- package/dist/workstation/acp/test/scriptAgent.js +11 -3
- package/dist/workstation/agentFlow.js +1 -1
- package/dist/workstation/agentSessions.js +114 -166
- package/dist/workstation/channels/agent.js +9 -1
- package/dist/workstation/channels/computer.js +27 -4
- package/dist/workstation/channels/management.js +130 -15
- package/dist/workstation/channels/url.js +1 -1
- package/dist/workstation/config.js +33 -9
- package/dist/workstation/connection/encryptedChannel.js +4 -1
- package/dist/workstation/control/bindingStore.js +204 -0
- package/dist/workstation/control/commands.js +125 -0
- package/dist/workstation/control/daemonIdentity.js +143 -0
- package/dist/workstation/control/deviceCommands.js +191 -0
- package/dist/workstation/control/deviceProtocol.js +68 -0
- package/dist/workstation/control/enrollment.js +106 -0
- package/dist/workstation/control/inspect.js +71 -0
- package/dist/workstation/control/locks.js +110 -0
- package/dist/workstation/control/protocol.js +40 -0
- package/dist/workstation/control/restartGuard.js +46 -0
- package/dist/workstation/control/rootFormat.js +16 -0
- package/dist/workstation/control/runtimeClient.js +152 -0
- package/dist/workstation/control/runtimeHost.js +235 -0
- package/dist/workstation/control/serverIdentity.js +35 -0
- package/dist/workstation/control/updateTransition.js +91 -0
- package/dist/workstation/daemon.js +266 -264
- package/dist/workstation/daemonctl.js +226 -25
- package/dist/workstation/desktopControl/audio.js +99 -0
- package/dist/workstation/desktopControl/automationDevice.js +219 -0
- package/dist/workstation/desktopControl/automationJson.js +74 -0
- package/dist/workstation/desktopControl/automationLocalState.js +23 -0
- package/dist/workstation/desktopControl/automationProtocol.js +253 -0
- package/dist/workstation/desktopControl/automationSchema.generated.js +1 -0
- package/dist/workstation/desktopControl/automationSession.js +81 -0
- package/dist/workstation/desktopControl/automationTransport.js +138 -0
- package/dist/workstation/desktopControl/capabilities.js +93 -0
- package/dist/workstation/desktopControl/captureModes.js +9 -0
- package/dist/workstation/desktopControl/captureTargetLabel.js +9 -0
- package/dist/workstation/desktopControl/deviceAdmission.js +229 -0
- package/dist/workstation/desktopControl/deviceOwnership.js +130 -0
- package/dist/workstation/desktopControl/deviceSockets.js +246 -0
- package/dist/workstation/desktopControl/helperProcess.js +602 -0
- package/dist/workstation/desktopControl/hostGrant.js +65 -0
- package/dist/workstation/desktopControl/lobby.js +131 -0
- package/dist/workstation/desktopControl/macProvider.js +156 -0
- package/dist/workstation/desktopControl/media.js +331 -0
- package/dist/workstation/desktopControl/nativeDeviceAdmission.js +207 -0
- package/dist/workstation/desktopControl/nativeProvider.js +1044 -0
- package/dist/workstation/desktopControl/networkEvidence.js +43 -0
- package/dist/workstation/desktopControl/overview.js +58 -0
- package/dist/workstation/desktopControl/ownershipProtocol.js +31 -0
- package/dist/workstation/desktopControl/protocol.js +311 -0
- package/dist/workstation/desktopControl/provider.js +1 -0
- package/dist/workstation/desktopControl/quicMedia.js +240 -0
- package/dist/workstation/desktopControl/rateController.js +226 -0
- package/dist/workstation/desktopControl/supervisor.js +1774 -0
- package/dist/workstation/desktopControl/transport.js +27 -0
- package/dist/workstation/desktopControl/wallpaper.js +98 -0
- package/dist/workstation/exec/policy.js +5 -0
- package/dist/workstation/files/client.js +10 -1
- package/dist/workstation/files/credentials.js +142 -0
- package/dist/workstation/files/host.js +9 -2
- package/dist/workstation/files/text.js +42 -8
- package/dist/workstation/journal.js +5 -2
- package/dist/workstation/keepers/acp/client.js +38 -2
- package/dist/workstation/keepers/kit/buildVersion.js +35 -11
- package/dist/workstation/keepers/kit/bundle.js +21 -17
- package/dist/workstation/keepers/kit/client.js +2 -2
- package/dist/workstation/keepers/kit/launcher.js +123 -7
- package/dist/workstation/keepers/kit/paths.js +2 -1
- package/dist/workstation/keepers/legacy.js +16 -2
- package/dist/workstation/keepers/policy.js +5 -34
- package/dist/workstation/keepers/terminal/client.js +115 -23
- package/dist/workstation/keepers/terminal/exec.js +6 -3
- package/dist/workstation/keepers/terminal/frames.js +73 -0
- package/dist/workstation/keepers/terminal/generations.js +5 -8
- package/dist/workstation/keepers/terminal/gridProtocol.js +16 -0
- package/dist/workstation/keepers/terminal/input.js +146 -0
- package/dist/workstation/keepers/terminal/keeper.js +22 -8
- package/dist/workstation/keepers/terminal/main.js +1 -1
- package/dist/workstation/keepers/terminal/metadata.js +138 -0
- package/dist/workstation/keepers/terminal/protocol.js +4 -28
- package/dist/workstation/keepers/terminal/pty.js +1 -330
- package/dist/workstation/keepers/terminal/screen.js +246 -0
- package/dist/workstation/keepers/terminal/sessions.js +526 -0
- package/dist/workstation/managedInstall.js +57 -0
- package/dist/workstation/oauth/deviceAuthorization.js +31 -17
- package/dist/workstation/protocol/agent.js +2 -15
- package/dist/workstation/protocol/management.js +113 -5
- package/dist/workstation/protocol/runtimeDiagnostics.js +15 -0
- package/dist/workstation/rd/artifact.js +120 -0
- package/dist/workstation/rd/control.js +117 -0
- package/dist/workstation/rd/display.js +29 -0
- package/dist/workstation/rd/host.js +213 -0
- package/dist/workstation/rd/migrationReadiness.js +46 -0
- package/dist/workstation/rd/provider.js +256 -0
- package/dist/workstation/rd/sessions.js +391 -0
- package/dist/workstation/rd/state.js +57 -0
- package/dist/workstation/rd/update.js +168 -0
- package/dist/workstation/rd/upkeep.js +80 -0
- package/dist/workstation/register.js +27 -37
- package/dist/workstation/registrations/enrollment.js +250 -0
- package/dist/workstation/registrations/enrollmentPending.js +361 -0
- package/dist/workstation/registrations/migration.js +356 -0
- package/dist/workstation/registrations/model.js +34 -0
- package/dist/workstation/registrations/removal.js +222 -0
- package/dist/workstation/registrations/store.js +737 -0
- package/dist/workstation/runtime/desktopBinding.js +20 -0
- package/dist/workstation/runtime/deviceDesktop.js +193 -0
- package/dist/workstation/runtime/deviceRuntime.js +568 -0
- package/dist/workstation/runtime/deviceServices.js +117 -0
- package/dist/workstation/runtime/events.js +20 -0
- package/dist/workstation/runtime/ownership.js +100 -0
- package/dist/workstation/runtime/registrationRuntime.js +575 -0
- package/dist/workstation/runtime/remoteDesktopAdapter.js +186 -0
- package/dist/workstation/runtime/removalActivity.js +184 -0
- package/dist/workstation/service/installer.js +197 -14
- package/dist/workstation/service/launchd.js +2 -0
- package/dist/workstation/service/systemd.js +1 -0
- package/dist/workstation/storageMetrics.js +118 -0
- package/dist/workstation/systemMetrics.js +47 -92
- package/dist/workstation/toolchain.js +94 -0
- package/dist/workstation/tools/browser.js +28 -4
- package/dist/workstation/tools/client.js +8 -27
- package/dist/workstation/tools/info.js +6 -13
- package/dist/workstation/tools/terminalRouter.js +17 -172
- package/dist/workstation/tools/validation.js +55 -1
- package/dist/workstation/update/archiveEvidence.js +206 -0
- package/dist/workstation/update/artifact.js +2 -1
- package/dist/workstation/update/coordinator.js +34 -13
- package/dist/workstation/update/deviceCompatibility.js +119 -0
- package/dist/workstation/update/deviceCoordinator.js +369 -0
- package/dist/workstation/update/deviceHealth.js +104 -0
- package/dist/workstation/update/deviceHealthProtocol.js +26 -0
- package/dist/workstation/update/deviceRecoveryLifecycle.js +46 -0
- package/dist/workstation/update/deviceRollback.js +78 -0
- package/dist/workstation/update/globalInstall.js +186 -0
- package/dist/workstation/update/legacyBridge.js +414 -0
- package/dist/workstation/update/legacyOwner.js +39 -0
- package/dist/workstation/update/npmInstaller.js +51 -25
- package/dist/workstation/update/privateDurability.js +61 -0
- package/dist/workstation/update/rdRollback.js +145 -0
- package/dist/workstation/update/recoveryPlan.js +124 -0
- package/dist/workstation/update/runUpdate.js +10 -3
- package/dist/workstation/update/taskRegistry.js +161 -3
- package/dist/workstation/update/watchdog.js +29806 -333
- package/dist/workstation/update/watchdogProcess.js +72 -0
- package/package.json +11 -7
- package/skills/axom/SKILL.md +11 -11
- package/skills/axom-definition/SKILL.md +3 -3
- package/skills/axom-platform/SKILL.md +3 -3
- package/dist/axom-patch/cli/probes/qoder-steering.mjs +0 -89
- package/dist/axom-patch/cli/probes/qoder-subagent-origin.mjs +0 -61
- package/dist/axom-patch/cli/qoder-steering.json +0 -52
- package/dist/axom-patch/cli/qoder-subagent-origin.json +0 -73
- package/dist/commands/guide.js +0 -38
- package/dist/runtime-deps/qoder-sdk/package-lock.json +0 -1189
- package/dist/runtime-deps/qoder-sdk/package.json +0 -8
- package/dist/workstation/acp/delegationMcp.js +0 -24
- package/dist/workstation/acp/processor/sideChannel.js +0 -80
- package/dist/workstation/acp/qoderStartup.js +0 -45
- package/dist/workstation/acp/test/raw/qoderCaptures.js +0 -125
- package/dist/workstation/qoderAdapter/backgroundProcess.js +0 -118
- package/dist/workstation/qoderAdapter/backgroundTerminal.js +0 -193
- package/dist/workstation/qoderAdapter/backgroundTerminalFold.js +0 -372
- package/dist/workstation/qoderAdapter/callbackContext.js +0 -76
- package/dist/workstation/qoderAdapter/completedContinuation.js +0 -139
- package/dist/workstation/qoderAdapter/contract.js +0 -78
- package/dist/workstation/qoderAdapter/foregroundOutput.js +0 -36
- package/dist/workstation/qoderAdapter/history.js +0 -85
- package/dist/workstation/qoderAdapter/identityIndex.js +0 -191
- package/dist/workstation/qoderAdapter/inputQueue.js +0 -42
- package/dist/workstation/qoderAdapter/main.js +0 -95
- package/dist/workstation/qoderAdapter/mapper.js +0 -117
- package/dist/workstation/qoderAdapter/observerPlugin.js +0 -245
- package/dist/workstation/qoderAdapter/observerReceiver.js +0 -187
- package/dist/workstation/qoderAdapter/permissions.js +0 -61
- package/dist/workstation/qoderAdapter/profile.js +0 -93
- package/dist/workstation/qoderAdapter/sdkDriver.js +0 -48
- package/dist/workstation/qoderAdapter/sdkRuntime.js +0 -93
- package/dist/workstation/qoderAdapter/sdkRuntimeInstall.js +0 -145
- package/dist/workstation/qoderAdapter/session.js +0 -319
- package/dist/workstation/qoderAdapter/subagentMeta.js +0 -28
- package/dist/workstation/qoderAdapter/subwork.js +0 -85
- package/dist/workstation/qoderAdapter/taskControl.js +0 -38
- package/dist/workstation/qoderAdapter/taskLedger.js +0 -163
- package/dist/workstation/qoderAdapter/usage.js +0 -37
- /package/dist/workstation/{qoderAdapter/types.js → desktopControl/automationPreparation.js} +0 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export async function holdDesktopForTargetProbe(adapter) { await adapter?.holdNewAdmission(); }
|
|
2
|
+
export async function replaceDesktopBinding(options) {
|
|
3
|
+
await options.original?.closeAdmission();
|
|
4
|
+
await options.original?.isolateOriginal();
|
|
5
|
+
options.original?.admission.dispose();
|
|
6
|
+
if (options.final())
|
|
7
|
+
return;
|
|
8
|
+
const next = options.create();
|
|
9
|
+
if (next && !options.allowed())
|
|
10
|
+
await next.closeAdmission();
|
|
11
|
+
if (next && options.held?.())
|
|
12
|
+
await next.holdNewAdmission();
|
|
13
|
+
if (options.final()) {
|
|
14
|
+
await next?.closeAdmission();
|
|
15
|
+
await next?.isolateOriginal();
|
|
16
|
+
next?.admission.dispose();
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
return next;
|
|
20
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
export async function resolveDeviceDesktop(root) {
|
|
5
|
+
if (process.platform === 'linux') {
|
|
6
|
+
const { LinuxDeviceHost } = await import('../rd/host.js');
|
|
7
|
+
const pending = await LinuxDeviceHost.recoverPending(root);
|
|
8
|
+
if (pending)
|
|
9
|
+
return { cleanupOnly: true, provider: { deviceAdmission: pending.admission, probe: async () => null,
|
|
10
|
+
prepare: async () => { throw Error('cleanup_only'); }, recoverDisplay: async () => { throw Error('cleanup_only'); } },
|
|
11
|
+
stopOriginal: () => pending.stopOriginal(), finalizeOriginal: () => pending.finalizeOriginal() };
|
|
12
|
+
}
|
|
13
|
+
if (process.platform === 'darwin' || process.platform === 'linux') {
|
|
14
|
+
const cleanup = path.join(root, 'desktop-cleanup');
|
|
15
|
+
let files = [];
|
|
16
|
+
try {
|
|
17
|
+
const stat = await fs.lstat(cleanup);
|
|
18
|
+
if (!stat.isDirectory() || stat.uid !== process.getuid?.() || stat.mode & 0o077)
|
|
19
|
+
throw new Error('unsafe_desktop_cleanup');
|
|
20
|
+
files = (await fs.readdir(cleanup)).sort();
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
if (error.code !== 'ENOENT')
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
if (files.length) {
|
|
27
|
+
const first = files[0];
|
|
28
|
+
if (!/^[a-f0-9]{32}\.json$/.test(first))
|
|
29
|
+
throw new Error('unsafe_desktop_cleanup');
|
|
30
|
+
if (process.platform === 'darwin') {
|
|
31
|
+
const { MacProvider } = await import('../desktopControl/macProvider.js');
|
|
32
|
+
return { provider: await MacProvider.connect(root, path.join(cleanup, first)), cleanupOnly: true };
|
|
33
|
+
}
|
|
34
|
+
const { readDeviceHostGrant } = await import('../desktopControl/hostGrant.js');
|
|
35
|
+
const { NativeDeviceAdmission } = await import('../desktopControl/nativeDeviceAdmission.js');
|
|
36
|
+
const grant = await readDeviceHostGrant(path.join(cleanup, first), true);
|
|
37
|
+
const admission = await NativeDeviceAdmission.connect(grant);
|
|
38
|
+
if (admission.hostLifetimeId !== grant.hostGeneration)
|
|
39
|
+
throw Error('original_native_host_unconfirmed');
|
|
40
|
+
return { cleanupOnly: true, provider: { deviceAdmission: admission, probe: async () => null,
|
|
41
|
+
prepare: async () => { throw Error('cleanup_only'); }, recoverDisplay: async () => { throw Error('cleanup_only'); } } };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (process.platform === 'darwin') {
|
|
45
|
+
const { MacProvider } = await import('../desktopControl/macProvider.js');
|
|
46
|
+
try {
|
|
47
|
+
await fs.lstat(path.join(root, 'desktop-provider.json'));
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
if (error.code === 'ENOENT')
|
|
51
|
+
return;
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
return { provider: await MacProvider.connect(root), cleanupOnly: false };
|
|
55
|
+
}
|
|
56
|
+
if (process.platform === 'linux') {
|
|
57
|
+
const { LinuxDesktopProvider } = await import('../rd/provider.js');
|
|
58
|
+
const provider = await LinuxDesktopProvider.connect(root);
|
|
59
|
+
return provider ? { provider, cleanupOnly: false, stopOriginal: () => provider.stopOriginal(), finalizeOriginal: () => provider.finalizeOriginal(), retirementRequired: () => provider.retirementRequired() } : undefined;
|
|
60
|
+
}
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
export class DeviceDesktopRuntime {
|
|
64
|
+
root;
|
|
65
|
+
owner;
|
|
66
|
+
resolve;
|
|
67
|
+
original;
|
|
68
|
+
published;
|
|
69
|
+
retired = false;
|
|
70
|
+
unknown = false;
|
|
71
|
+
nativeConsumers = 0;
|
|
72
|
+
busy;
|
|
73
|
+
consumers = new Map();
|
|
74
|
+
timer;
|
|
75
|
+
stopped = false;
|
|
76
|
+
finalAcknowledgements = new Set();
|
|
77
|
+
pendingFinalizer;
|
|
78
|
+
constructor(root, owner, resolve = resolveDeviceDesktop) {
|
|
79
|
+
this.root = root;
|
|
80
|
+
this.owner = owner;
|
|
81
|
+
this.resolve = resolve;
|
|
82
|
+
}
|
|
83
|
+
get provider() { return this.published; }
|
|
84
|
+
facts() { return { deviceEpoch: this.owner.snapshot().deviceEpoch, hostLifetimeId: this.original?.provider.deviceAdmission?.hostLifetimeId ?? null, hostRetired: this.retired }; }
|
|
85
|
+
activity() {
|
|
86
|
+
const activity = [...this.consumers.values()].map(consumer => consumer.activity());
|
|
87
|
+
return { known: !this.unknown && activity.every(value => value.known),
|
|
88
|
+
consumers: Math.max(this.unknown ? 1 : 0, this.nativeConsumers, ...activity.map(value => value.consumers), 0) };
|
|
89
|
+
}
|
|
90
|
+
async watch(id, consumer) {
|
|
91
|
+
this.consumers.set(id, consumer);
|
|
92
|
+
await consumer.bind(this.published);
|
|
93
|
+
return () => { if (this.consumers.get(id) === consumer)
|
|
94
|
+
this.consumers.delete(id); };
|
|
95
|
+
}
|
|
96
|
+
async start() {
|
|
97
|
+
await this.refresh();
|
|
98
|
+
if (!this.stopped) {
|
|
99
|
+
this.timer = setInterval(() => { void this.refresh(); }, 1000);
|
|
100
|
+
this.timer.unref();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
refresh() {
|
|
104
|
+
if (this.busy)
|
|
105
|
+
return this.busy;
|
|
106
|
+
const current = this.tick().catch(() => { this.unknown = true; }).finally(() => { if (this.busy === current)
|
|
107
|
+
this.busy = undefined; });
|
|
108
|
+
this.busy = current;
|
|
109
|
+
return current;
|
|
110
|
+
}
|
|
111
|
+
async tick() {
|
|
112
|
+
for (const original of [...this.finalAcknowledgements])
|
|
113
|
+
try {
|
|
114
|
+
await original.acknowledgeHostRetirement(randomUUID());
|
|
115
|
+
this.finalAcknowledgements.delete(original);
|
|
116
|
+
}
|
|
117
|
+
catch { }
|
|
118
|
+
if (this.pendingFinalizer) {
|
|
119
|
+
await this.pendingFinalizer();
|
|
120
|
+
this.pendingFinalizer = undefined;
|
|
121
|
+
this.unknown = false;
|
|
122
|
+
}
|
|
123
|
+
if (!this.original || this.retired) {
|
|
124
|
+
const next = this.stopped ? undefined : await this.resolve(this.root);
|
|
125
|
+
if (!next)
|
|
126
|
+
return;
|
|
127
|
+
if (next.provider.deviceAdmission?.hostLifetimeId === this.original?.provider.deviceAdmission?.hostLifetimeId) {
|
|
128
|
+
if (this.retired && next.finalizeOriginal) {
|
|
129
|
+
this.pendingFinalizer = next.finalizeOriginal;
|
|
130
|
+
await this.pendingFinalizer();
|
|
131
|
+
this.pendingFinalizer = undefined;
|
|
132
|
+
this.unknown = false;
|
|
133
|
+
}
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
this.original = next;
|
|
137
|
+
this.retired = false;
|
|
138
|
+
}
|
|
139
|
+
const candidate = this.original;
|
|
140
|
+
if (!candidate)
|
|
141
|
+
return;
|
|
142
|
+
const original = candidate.provider.deviceAdmission;
|
|
143
|
+
if (!original?.status || !original.retireHost)
|
|
144
|
+
throw new Error('unqualified_native_host');
|
|
145
|
+
const status = await original.status();
|
|
146
|
+
this.nativeConsumers = Math.max(status.workers, status.operations, Number(status.active));
|
|
147
|
+
const epoch = this.owner.snapshot().deviceEpoch;
|
|
148
|
+
const retiring = this.stopped || candidate.cleanupOnly || await candidate.retirementRequired?.() === true || !status.connected || status.deviceEpoch !== null && status.deviceEpoch !== epoch ||
|
|
149
|
+
status.deviceEpoch === null && !status.quiescent ||
|
|
150
|
+
status.rotationRequired && status.quiescent && this.owner.snapshot().state === 'free' && [...this.consumers.values()].every(value => { const activity = value.activity(); return activity.known && activity.consumers === 0; });
|
|
151
|
+
if (retiring) {
|
|
152
|
+
this.published = undefined;
|
|
153
|
+
original.retire();
|
|
154
|
+
const results = await Promise.allSettled([...this.consumers.values()].map(consumer => consumer.bind(undefined)));
|
|
155
|
+
if (candidate.stopOriginal)
|
|
156
|
+
try {
|
|
157
|
+
await candidate.stopOriginal();
|
|
158
|
+
}
|
|
159
|
+
catch { }
|
|
160
|
+
if (results.some(result => result.status === 'rejected'))
|
|
161
|
+
throw new Error('original_desktop_cleanup_unconfirmed');
|
|
162
|
+
await original.retireHost(randomUUID());
|
|
163
|
+
if (this.finalAcknowledgements.size >= 32)
|
|
164
|
+
this.finalAcknowledgements.delete(this.finalAcknowledgements.values().next().value);
|
|
165
|
+
this.retired = true;
|
|
166
|
+
this.unknown = false;
|
|
167
|
+
this.nativeConsumers = 0;
|
|
168
|
+
this.finalAcknowledgements.add(original);
|
|
169
|
+
try {
|
|
170
|
+
await original.acknowledgeHostRetirement(randomUUID());
|
|
171
|
+
this.finalAcknowledgements.delete(original);
|
|
172
|
+
}
|
|
173
|
+
catch { }
|
|
174
|
+
if (candidate.finalizeOriginal) {
|
|
175
|
+
this.pendingFinalizer = candidate.finalizeOriginal;
|
|
176
|
+
await this.pendingFinalizer();
|
|
177
|
+
this.pendingFinalizer = undefined;
|
|
178
|
+
}
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (!original.current())
|
|
182
|
+
throw new Error('original_desktop_cleanup_unconfirmed');
|
|
183
|
+
if (this.published !== candidate.provider) {
|
|
184
|
+
await original.bindDeviceEpoch(randomUUID(), epoch);
|
|
185
|
+
const results = await Promise.allSettled([...this.consumers.values()].map(consumer => consumer.bind(candidate.provider)));
|
|
186
|
+
if (results.some(result => result.status === 'rejected'))
|
|
187
|
+
throw new Error('desktop_rebind_unconfirmed');
|
|
188
|
+
this.published = candidate.provider;
|
|
189
|
+
}
|
|
190
|
+
this.unknown = false;
|
|
191
|
+
}
|
|
192
|
+
async stop() { this.stopped = true; clearInterval(this.timer); await this.busy; await this.refresh(); }
|
|
193
|
+
}
|