@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,240 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { access } from 'node:fs/promises';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { once } from 'node:events';
|
|
5
|
+
import { homedir } from 'node:os';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { bounded, DesktopQueue, NativeCommandError } from './helperProcess.js';
|
|
8
|
+
import { mediaRequire } from './media.js';
|
|
9
|
+
import { decodeQuicPathStats } from './networkEvidence.js';
|
|
10
|
+
const safeU64 = (b, offset) => { const n = b.readBigUInt64BE(offset); mediaRequire(n <= BigInt(Number.MAX_SAFE_INTEGER)); return Number(n); };
|
|
11
|
+
export function decodeQuicCutEvent(bytes) {
|
|
12
|
+
mediaRequire(bytes.length === 48 && bytes[0] === 1 && bytes[1] >= 1 && bytes[1] <= 6 && bytes[2] <= 7 && bytes[3] === 0 && bytes.readUInt32BE(20) === 0);
|
|
13
|
+
const value = { action: bytes[1], reason: bytes[2], epoch: bytes.readUInt32BE(4), cutId: safeU64(bytes, 8), pictureThrough: bytes.readUInt32BE(16), frameThrough: safeU64(bytes, 24), wireThrough: safeU64(bytes, 32), motionCommittedBytes: safeU64(bytes, 40) };
|
|
14
|
+
mediaRequire(value.epoch > 0 && (value.action === 1 || value.cutId > 0));
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
export class DesktopMediaAdmissionCancelled extends NativeCommandError {
|
|
18
|
+
cutId;
|
|
19
|
+
epoch;
|
|
20
|
+
pictureSequence;
|
|
21
|
+
constructor(cutId, epoch, pictureSequence) {
|
|
22
|
+
super('transport_failed');
|
|
23
|
+
this.cutId = cutId;
|
|
24
|
+
this.epoch = epoch;
|
|
25
|
+
this.pictureSequence = pictureSequence;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export const isQuicMediaQueueEvent = (kind) => kind === 1 || kind === 2 || kind === 3 || kind === 4;
|
|
29
|
+
/** At most one unresolved ticket per lane, sharing the caller's existing bounded reservation. */
|
|
30
|
+
export class DesktopQuicAdmission {
|
|
31
|
+
peer;
|
|
32
|
+
write;
|
|
33
|
+
pending = new Map();
|
|
34
|
+
nextId = 0n;
|
|
35
|
+
totals = new Map([[0, [0, 0, 0]]]);
|
|
36
|
+
epoch = 0;
|
|
37
|
+
dead = false;
|
|
38
|
+
cut;
|
|
39
|
+
constructor(peer, write) {
|
|
40
|
+
this.peer = peer;
|
|
41
|
+
this.write = write;
|
|
42
|
+
}
|
|
43
|
+
ownCut(id, epoch, pictureThrough) { mediaRequire(Number.isSafeInteger(id) && id > 0 && epoch > 0 && !this.cut); this.cut = { id, epoch, pictureThrough }; }
|
|
44
|
+
finishCut(id) { mediaRequire(this.cut?.id === id); this.cut = undefined; }
|
|
45
|
+
async send(kind, bytes) {
|
|
46
|
+
mediaRequire(!this.dead && (kind === 2 || kind === 3) && bytes.length > 0 && bytes.length <= 65600);
|
|
47
|
+
let lane = 255, epoch = 0, sequence = 0, payloadBytes = 0;
|
|
48
|
+
if (kind === 3) {
|
|
49
|
+
mediaRequire(bytes.length >= 65 && bytes.subarray(0, 5).equals(Buffer.from('AXDS\x01')));
|
|
50
|
+
lane = bytes[5] <= 2 ? 0 : bytes[5] <= 4 ? 1 : 2;
|
|
51
|
+
epoch = bytes.readUInt32BE(12);
|
|
52
|
+
sequence = bytes.readUInt32BE(20);
|
|
53
|
+
payloadBytes = bytes.length - 64;
|
|
54
|
+
mediaRequire(bytes[5] >= 1 && bytes[5] <= 5 && epoch > 0 && sequence > 0);
|
|
55
|
+
if (bytes[5] === 1) {
|
|
56
|
+
mediaRequire(epoch > this.epoch);
|
|
57
|
+
const oldest = [...this.totals.keys()].filter(e => e !== 0 && e !== this.epoch);
|
|
58
|
+
for (const old of oldest) {
|
|
59
|
+
mediaRequire(![...this.pending.values()].some(p => p.epoch === old));
|
|
60
|
+
this.totals.delete(old);
|
|
61
|
+
}
|
|
62
|
+
this.epoch = epoch;
|
|
63
|
+
if (!this.totals.has(epoch))
|
|
64
|
+
this.totals.set(epoch, [0, 0, 0]);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
mediaRequire(epoch === this.epoch || this.epoch === 0);
|
|
68
|
+
if (!this.totals.has(epoch))
|
|
69
|
+
this.totals.set(epoch, [0, 0, 0]);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
mediaRequire(![...this.pending.values()].some(p => p.lane === lane));
|
|
73
|
+
const id = ++this.nextId;
|
|
74
|
+
mediaRequire(id <= BigInt(Number.MAX_SAFE_INTEGER));
|
|
75
|
+
const header = Buffer.alloc(21);
|
|
76
|
+
header.writeUInt32BE(bytes.length + 17);
|
|
77
|
+
header[4] = kind;
|
|
78
|
+
header.writeBigUInt64BE(this.peer, 5);
|
|
79
|
+
header.writeBigUInt64BE(id, 13);
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
const item = { id, kind, lane, epoch, sequence, payloadBytes, frame: Buffer.concat([header, bytes]), resolve, reject, busy: false, deadline: setTimeout(() => { this.close(new NativeCommandError('transport_failed')); }, 5000) };
|
|
82
|
+
this.pending.set(id, item);
|
|
83
|
+
void this.write(item.frame).catch(e => this.close(e));
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
accept(peer, bytes) {
|
|
87
|
+
mediaRequire(peer === this.peer && bytes.length === 32 && bytes.readUInt16BE(10) === 0 && bytes.readUInt32BE(20) === 0);
|
|
88
|
+
const id = bytes.readBigUInt64BE(), p = this.pending.get(id);
|
|
89
|
+
mediaRequire(p && bytes[8] >= 1 && bytes[8] <= 3 && bytes[9] === p.lane && bytes.readUInt32BE(12) === p.epoch && bytes.readUInt32BE(16) === p.sequence);
|
|
90
|
+
const total = safeU64(bytes, 24), previous = p.lane === 255 ? 0 : this.totals.get(p.epoch)[p.lane];
|
|
91
|
+
mediaRequire(total === previous + (bytes[8] === 1 ? p.payloadBytes : 0));
|
|
92
|
+
if (bytes[8] === 3) {
|
|
93
|
+
mediaRequire(!p.busy);
|
|
94
|
+
p.busy = true;
|
|
95
|
+
p.timer = setTimeout(() => { p.busy = false; if (this.pending.get(id) === p)
|
|
96
|
+
void this.write(p.frame).catch(e => this.close(e)); }, 10);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (bytes[8] === 2)
|
|
100
|
+
mediaRequire(p.lane === 0 && this.cut && p.epoch === this.cut.epoch && p.sequence <= this.cut.pictureThrough);
|
|
101
|
+
this.pending.delete(id);
|
|
102
|
+
clearTimeout(p.deadline);
|
|
103
|
+
clearTimeout(p.timer);
|
|
104
|
+
if (bytes[8] === 1) {
|
|
105
|
+
if (p.lane !== 255)
|
|
106
|
+
this.totals.get(p.epoch)[p.lane] = total;
|
|
107
|
+
p.resolve();
|
|
108
|
+
}
|
|
109
|
+
else
|
|
110
|
+
p.reject(new DesktopMediaAdmissionCancelled(this.cut.id, p.epoch, p.sequence));
|
|
111
|
+
}
|
|
112
|
+
close(error = new NativeCommandError('transport_failed')) { this.dead = true; for (const p of this.pending.values()) {
|
|
113
|
+
clearTimeout(p.deadline);
|
|
114
|
+
clearTimeout(p.timer);
|
|
115
|
+
p.reject(error);
|
|
116
|
+
} this.pending.clear(); }
|
|
117
|
+
}
|
|
118
|
+
/** The subprocess is a platform build of the same Rust engine embedded by native viewers. */
|
|
119
|
+
export async function openQuicMedia(server, offer, signal, current) {
|
|
120
|
+
const packaged = fileURLToPath(new URL(`../../native/${process.platform}-${process.arch}/axom-quic`, import.meta.url));
|
|
121
|
+
const candidates = [...(process.env.AXOM_QUIC_BINARY ? [process.env.AXOM_QUIC_BINARY] : []), packaged, path.join(homedir(), '.axom/workstation/quic', `${process.platform}-${process.arch}`, 'axom-quic'), '/usr/local/bin/axom-quic'];
|
|
122
|
+
const executable = await (async () => { for (const file of candidates) {
|
|
123
|
+
try {
|
|
124
|
+
await access(file);
|
|
125
|
+
return file;
|
|
126
|
+
}
|
|
127
|
+
catch { }
|
|
128
|
+
} return undefined; })();
|
|
129
|
+
if (!executable)
|
|
130
|
+
return undefined;
|
|
131
|
+
const child = spawn(executable, [], { stdio: ['pipe', 'pipe', 'ignore'] });
|
|
132
|
+
const queue = new DesktopQueue();
|
|
133
|
+
const events = queue[Symbol.asyncIterator]();
|
|
134
|
+
let buffer = Buffer.alloc(0), peer = 0n, dead = false, transportBytes = 0;
|
|
135
|
+
let pathStats;
|
|
136
|
+
let admission;
|
|
137
|
+
const cuts = new DesktopQueue(16);
|
|
138
|
+
const close = () => { if (dead)
|
|
139
|
+
return; dead = true; child.stdin.destroy(); child.kill(); admission?.close(); queue.close(); cuts.close(); signal.removeEventListener('abort', close); };
|
|
140
|
+
const closed = new Promise(resolve => child.once('close', () => { close(); resolve(); }));
|
|
141
|
+
signal.addEventListener('abort', close, { once: true });
|
|
142
|
+
child.once('error', close);
|
|
143
|
+
child.stdin.on('error', close);
|
|
144
|
+
if (signal.aborted)
|
|
145
|
+
close();
|
|
146
|
+
child.stdout.on('data', (bytes) => {
|
|
147
|
+
try {
|
|
148
|
+
mediaRequire(buffer.length + bytes.length <= 2 * 65613);
|
|
149
|
+
buffer = Buffer.concat([buffer, bytes]);
|
|
150
|
+
while (buffer.length >= 4) {
|
|
151
|
+
const length = buffer.readUInt32BE();
|
|
152
|
+
mediaRequire(length >= 9 && length <= 65609);
|
|
153
|
+
if (buffer.length < length + 4)
|
|
154
|
+
break;
|
|
155
|
+
const frame = buffer.subarray(4, 4 + length);
|
|
156
|
+
buffer = buffer.subarray(4 + length);
|
|
157
|
+
const kind = frame[0], eventPeer = frame.readBigUInt64BE(1), payload = Buffer.from(frame.subarray(9));
|
|
158
|
+
if (kind === 1) {
|
|
159
|
+
mediaRequire(peer === 0n && eventPeer > 0n);
|
|
160
|
+
peer = eventPeer;
|
|
161
|
+
}
|
|
162
|
+
if (kind === 9) {
|
|
163
|
+
mediaRequire(eventPeer === peer && payload.length === 8);
|
|
164
|
+
const total = safeU64(payload, 0);
|
|
165
|
+
mediaRequire(total >= transportBytes);
|
|
166
|
+
transportBytes = total;
|
|
167
|
+
}
|
|
168
|
+
else if (kind === 10) {
|
|
169
|
+
mediaRequire(eventPeer === peer);
|
|
170
|
+
const next = decodeQuicPathStats(payload, performance.now());
|
|
171
|
+
mediaRequire(!pathStats || next.sequence > pathStats.sequence && next.pathGeneration >= pathStats.pathGeneration);
|
|
172
|
+
pathStats = next;
|
|
173
|
+
}
|
|
174
|
+
else if (kind === 8) {
|
|
175
|
+
mediaRequire(admission);
|
|
176
|
+
admission.accept(eventPeer, payload);
|
|
177
|
+
}
|
|
178
|
+
else if (kind === 7) {
|
|
179
|
+
mediaRequire(eventPeer === peer);
|
|
180
|
+
cuts.push(decodeQuicCutEvent(payload));
|
|
181
|
+
}
|
|
182
|
+
else if (isQuicMediaQueueEvent(kind))
|
|
183
|
+
queue.push({ kind, peer: eventPeer, bytes: payload });
|
|
184
|
+
// Native event extensions belong to their own lanes. Never let an
|
|
185
|
+
// unrecognized event become an AXDS media packet and retire the RD session.
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
close();
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
const write = async (bytes) => { mediaRequire(current() && !signal.aborted && !dead); if (!child.stdin.write(bytes))
|
|
193
|
+
await bounded(once(child.stdin, 'drain'), 2000); };
|
|
194
|
+
try {
|
|
195
|
+
const config = Buffer.from(JSON.stringify({ mode: 'client', host: new URL(server).hostname.replace(/^\[|\]$/g, ''), port: offer.port, certificate: offer.certificate }));
|
|
196
|
+
const header = Buffer.alloc(4);
|
|
197
|
+
header.writeUInt32BE(config.length);
|
|
198
|
+
await write(Buffer.concat([header, config]));
|
|
199
|
+
const ready = await bounded(events.next(), 1800);
|
|
200
|
+
mediaRequire(!ready.done && ready.value.kind === 1);
|
|
201
|
+
peer = ready.value.peer;
|
|
202
|
+
admission = new DesktopQuicAdmission(peer, write);
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
close();
|
|
206
|
+
if (signal.aborted)
|
|
207
|
+
throw error;
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
const send = (kind, bytes) => admission.send(kind, bytes);
|
|
211
|
+
const sendAudio = async (bytes) => {
|
|
212
|
+
mediaRequire(bytes.length >= 41 && bytes.length <= 1040 && bytes.subarray(0, 4).equals(Buffer.from('AXDA')));
|
|
213
|
+
if (!current() || signal.aborted || dead || child.stdin.writableLength > 4096)
|
|
214
|
+
return false;
|
|
215
|
+
const frame = Buffer.alloc(21);
|
|
216
|
+
frame.writeUInt32BE(17 + bytes.length);
|
|
217
|
+
frame[4] = 12;
|
|
218
|
+
frame.writeBigUInt64BE(peer, 5);
|
|
219
|
+
child.stdin.write(Buffer.concat([frame, bytes]));
|
|
220
|
+
return true;
|
|
221
|
+
};
|
|
222
|
+
const cutCommand = async (kind, cutId, epoch, pictureThrough = 0, frameThrough = 0) => {
|
|
223
|
+
mediaRequire(Number.isSafeInteger(cutId) && cutId > 0 && Number.isInteger(epoch) && epoch > 0);
|
|
224
|
+
const payload = Buffer.alloc(kind === 9 ? 16 : 4);
|
|
225
|
+
payload.writeUInt32BE(epoch);
|
|
226
|
+
if (kind === 9) {
|
|
227
|
+
payload.writeUInt32BE(pictureThrough, 4);
|
|
228
|
+
payload.writeBigUInt64BE(BigInt(frameThrough), 8);
|
|
229
|
+
admission.ownCut(cutId, epoch, pictureThrough);
|
|
230
|
+
}
|
|
231
|
+
const frame = Buffer.alloc(21);
|
|
232
|
+
frame.writeUInt32BE(17 + payload.length);
|
|
233
|
+
frame[4] = kind;
|
|
234
|
+
frame.writeBigUInt64BE(peer, 5);
|
|
235
|
+
frame.writeBigUInt64BE(BigInt(cutId), 13);
|
|
236
|
+
await write(Buffer.concat([frame, payload]));
|
|
237
|
+
};
|
|
238
|
+
return { send, sendAudio, close, closed, transportCost: () => transportBytes, pathStats: () => pathStats, cutEvents: cuts, cutCommand, finishCut: (id) => admission.finishCut(id), receive: async (timeoutMs = 0) => { const event = timeoutMs ? await bounded(events.next(), timeoutMs) : await events.next(); if (event.done || event.value.kind === 4)
|
|
239
|
+
throw new NativeCommandError('transport_failed'); return event.value; } };
|
|
240
|
+
}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { DesktopNetworkEvidence } from './networkEvidence.js';
|
|
2
|
+
export class DesktopRateController {
|
|
3
|
+
min;
|
|
4
|
+
max;
|
|
5
|
+
maxFps;
|
|
6
|
+
networkEvidence = new DesktopNetworkEvidence();
|
|
7
|
+
target;
|
|
8
|
+
fps;
|
|
9
|
+
lastNow = -Infinity;
|
|
10
|
+
lastWindow = -Infinity;
|
|
11
|
+
lastRateChange = -Infinity;
|
|
12
|
+
lastFpsChange = -Infinity;
|
|
13
|
+
lastReopen = -Infinity;
|
|
14
|
+
cooldown = -Infinity;
|
|
15
|
+
reopens = [];
|
|
16
|
+
networkPressure = 0;
|
|
17
|
+
processingPressure = 0;
|
|
18
|
+
networkHealthy = 0;
|
|
19
|
+
headroom = 0;
|
|
20
|
+
recoveryWindows = 0;
|
|
21
|
+
recoveryFps;
|
|
22
|
+
fpsTrialUntil = -Infinity;
|
|
23
|
+
fpsRecoveryAfter = -Infinity;
|
|
24
|
+
paused = false;
|
|
25
|
+
demandBps = 0;
|
|
26
|
+
demandKnown = false;
|
|
27
|
+
windowHadActivity = false;
|
|
28
|
+
windowHadProgress = false;
|
|
29
|
+
windowHadProbeEvidence = false;
|
|
30
|
+
processingSamples = [];
|
|
31
|
+
encodeSamples = [];
|
|
32
|
+
lastEncodeObservation = -Infinity;
|
|
33
|
+
lastDecodeObservation = -Infinity;
|
|
34
|
+
lastNetworkPolicySample;
|
|
35
|
+
lastPath;
|
|
36
|
+
snapshot = { networkState: 'unknown',
|
|
37
|
+
networkQueueMs: 0, observedPayloadBps: 0, processingP95Ms: 0, encodeP95Ms: 0, receiverBudgetMs: 0, reasons: [] };
|
|
38
|
+
constructor(options = {}) {
|
|
39
|
+
const min = options.minBps ?? 500_000, max = options.maxBps ?? 20_000_000;
|
|
40
|
+
if (![min, max, options.targetBps ?? 4_000_000].every(Number.isFinite) || min < 500_000 || max > 20_000_000)
|
|
41
|
+
throw new Error('invalid rate bounds');
|
|
42
|
+
this.min = Math.ceil(min / 4000) * 4000;
|
|
43
|
+
this.max = Math.floor(max / 4000) * 4000;
|
|
44
|
+
if (this.min > this.max)
|
|
45
|
+
throw new Error('unrepresentable rate bounds');
|
|
46
|
+
this.target = this.quantize(options.targetBps ?? 4_000_000);
|
|
47
|
+
this.maxFps = options.maxFps ?? options.fpsCeiling ?? 60;
|
|
48
|
+
this.fps = options.fpsCeiling ?? this.maxFps;
|
|
49
|
+
this.recoveryFps = this.fps;
|
|
50
|
+
if (![15, 30, 60].includes(this.fps) || ![15, 30, 60].includes(this.maxFps) || this.fps > this.maxFps)
|
|
51
|
+
throw new Error('invalid fps bounds');
|
|
52
|
+
}
|
|
53
|
+
get diagnostics() { return { ...this.snapshot, reasons: [...this.snapshot.reasons] }; }
|
|
54
|
+
quantize(rate) {
|
|
55
|
+
return Math.max(this.min, Math.min(this.max, Math.floor(rate / 4000) * 4000));
|
|
56
|
+
}
|
|
57
|
+
sample(s, runtimeRateReconfigure = false) {
|
|
58
|
+
const optional = [s.rttBaselineMs, s.deliveryDelayMs, s.deliveryObservedAtMs, s.encodeObservedAtMs, s.decodeObservedAtMs];
|
|
59
|
+
if (![s.nowMs, s.activeBytes, s.excessRttMs, s.queueAgeMs, s.queuedSendMs, s.encodeMs, s.decodeMs]
|
|
60
|
+
.every(value => Number.isFinite(value) && value >= 0) ||
|
|
61
|
+
optional.some(value => value !== undefined && (!Number.isFinite(value) || value < 0)) ||
|
|
62
|
+
s.nowMs < this.lastNow)
|
|
63
|
+
throw new Error('invalid rate sample');
|
|
64
|
+
const elapsed = Number.isFinite(this.lastNow) ? s.nowMs - this.lastNow : 1000;
|
|
65
|
+
if (elapsed > 0) {
|
|
66
|
+
const observed = Math.min(this.max * 4, s.activeBytes * 8000 / elapsed);
|
|
67
|
+
const weight = -Math.expm1(-elapsed / 1000);
|
|
68
|
+
this.demandBps = this.demandKnown ? this.demandBps + (observed - this.demandBps) * weight : observed;
|
|
69
|
+
this.demandKnown = true;
|
|
70
|
+
}
|
|
71
|
+
this.lastNow = s.nowMs;
|
|
72
|
+
const window = Math.floor(s.nowMs / 1000);
|
|
73
|
+
const contiguous = window === this.lastWindow + 1;
|
|
74
|
+
const activeWindow = s.activeBytes > 0 || (contiguous && this.windowHadActivity);
|
|
75
|
+
const freshnessMs = Math.max(1500, (s.rttBaselineMs ?? 0) * 3);
|
|
76
|
+
const progress = s.deliveryObservedAtMs !== undefined
|
|
77
|
+
? s.deliveryObservedAtMs <= s.nowMs && s.nowMs - s.deliveryObservedAtMs <= freshnessMs
|
|
78
|
+
: s.deliveryDelayMs !== undefined && s.deliveryDelayMs <= 40;
|
|
79
|
+
const progressWindow = progress || contiguous && this.windowHadProgress;
|
|
80
|
+
this.windowHadActivity = window === this.lastWindow ? this.windowHadActivity || s.activeBytes > 0 : s.activeBytes > 0;
|
|
81
|
+
this.windowHadProgress = window === this.lastWindow ? this.windowHadProgress || progress : progress;
|
|
82
|
+
if (s.queuedSendMs > 100)
|
|
83
|
+
this.paused = true;
|
|
84
|
+
else if (s.queuedSendMs === 0)
|
|
85
|
+
this.paused = false;
|
|
86
|
+
const evidence = this.networkEvidence.sample(s.nowMs, s.network, this.demandBps);
|
|
87
|
+
const probeEvidence = progress && (evidence.state === 'usable' || evidence.state === 'unknown' &&
|
|
88
|
+
s.deliveryDelayMs !== undefined && s.deliveryDelayMs <= 40);
|
|
89
|
+
const probeWindow = probeEvidence || contiguous && this.windowHadProbeEvidence;
|
|
90
|
+
this.windowHadProbeEvidence = window === this.lastWindow ? this.windowHadProbeEvidence || probeEvidence : probeEvidence;
|
|
91
|
+
const path = s.network ? `${s.network.id}:${s.network.pathGeneration}` : undefined;
|
|
92
|
+
if (path !== this.lastPath) {
|
|
93
|
+
this.networkPressure = this.networkHealthy = 0;
|
|
94
|
+
this.lastNetworkPolicySample = undefined;
|
|
95
|
+
this.lastPath = path;
|
|
96
|
+
}
|
|
97
|
+
const sampleKey = s.network ? `${path}:${s.network.sequence}` : undefined;
|
|
98
|
+
const freshNetworkWindow = sampleKey !== undefined && sampleKey !== this.lastNetworkPolicySample;
|
|
99
|
+
if (window !== this.lastWindow && !contiguous) {
|
|
100
|
+
this.processingSamples = [];
|
|
101
|
+
this.encodeSamples = [];
|
|
102
|
+
}
|
|
103
|
+
const encodeAt = s.encodeObservedAtMs ?? (s.encodeMs > 0 ? s.nowMs : undefined);
|
|
104
|
+
const decodeAt = s.decodeObservedAtMs ?? (s.decodeMs > 0 ? s.nowMs : undefined);
|
|
105
|
+
const costs = [];
|
|
106
|
+
if (encodeAt !== undefined && encodeAt > this.lastEncodeObservation && encodeAt <= s.nowMs && s.nowMs - encodeAt <= freshnessMs) {
|
|
107
|
+
this.lastEncodeObservation = encodeAt;
|
|
108
|
+
costs.push(s.encodeMs);
|
|
109
|
+
this.encodeSamples.push(s.encodeMs);
|
|
110
|
+
}
|
|
111
|
+
if (decodeAt !== undefined && decodeAt > this.lastDecodeObservation && decodeAt <= s.nowMs && s.nowMs - decodeAt <= freshnessMs) {
|
|
112
|
+
this.lastDecodeObservation = decodeAt;
|
|
113
|
+
costs.push(s.decodeMs);
|
|
114
|
+
}
|
|
115
|
+
if (costs.length)
|
|
116
|
+
this.processingSamples.push(Math.max(...costs));
|
|
117
|
+
if (this.processingSamples.length > 128)
|
|
118
|
+
this.processingSamples.shift();
|
|
119
|
+
if (this.encodeSamples.length > 128)
|
|
120
|
+
this.encodeSamples.shift();
|
|
121
|
+
this.snapshot = { ...this.snapshot, networkState: evidence.state, networkQueueMs: evidence.queueMs,
|
|
122
|
+
observedPayloadBps: Math.round(this.demandBps), reasons: this.paused ? ['sender-backpressure'] : [] };
|
|
123
|
+
const decision = (reopenEpoch = false) => ({ targetBps: this.target,
|
|
124
|
+
fpsCeiling: this.fps, pauseCapture: this.paused, reopenEpoch });
|
|
125
|
+
if (window === this.lastWindow)
|
|
126
|
+
return decision();
|
|
127
|
+
this.lastWindow = window;
|
|
128
|
+
if (!contiguous)
|
|
129
|
+
this.networkPressure = this.processingPressure = this.networkHealthy = this.headroom = this.recoveryWindows = 0;
|
|
130
|
+
const costsInWindow = this.processingSamples.sort((left, right) => left - right);
|
|
131
|
+
this.processingSamples = [];
|
|
132
|
+
const cost = costsInWindow[Math.max(0, Math.ceil(costsInWindow.length * 0.95) - 1)] ?? 0;
|
|
133
|
+
this.snapshot.processingP95Ms = cost;
|
|
134
|
+
const encodeCosts = this.encodeSamples.sort((left, right) => left - right);
|
|
135
|
+
this.encodeSamples = [];
|
|
136
|
+
const encodeCost = encodeCosts[Math.max(0, Math.ceil(encodeCosts.length * 0.95) - 1)] ?? 0;
|
|
137
|
+
const receiverBudget = Math.max(80, 3000 / this.fps);
|
|
138
|
+
this.snapshot.encodeP95Ms = encodeCost;
|
|
139
|
+
this.snapshot.receiverBudgetMs = receiverBudget;
|
|
140
|
+
if (!activeWindow) {
|
|
141
|
+
this.networkPressure = this.processingPressure = this.networkHealthy = this.headroom = this.recoveryWindows = 0;
|
|
142
|
+
this.snapshot.reasons.push('content-idle');
|
|
143
|
+
return decision();
|
|
144
|
+
}
|
|
145
|
+
const net = evidence.state === 'congested' && freshNetworkWindow;
|
|
146
|
+
this.lastNetworkPolicySample = sampleKey;
|
|
147
|
+
const receiverPressure = costsInWindow.length > 0 && cost > 0.8 * 1000 / this.fps && s.queueAgeMs > receiverBudget;
|
|
148
|
+
const sourcePressure = encodeCosts.length > 0 && encodeCost > 0.8 * 1000 / this.fps;
|
|
149
|
+
const processing = sourcePressure || receiverPressure;
|
|
150
|
+
this.networkPressure = net ? this.networkPressure + 1 : 0;
|
|
151
|
+
this.processingPressure = processing ? this.processingPressure + 1 : 0;
|
|
152
|
+
this.networkHealthy = !net && probeWindow && progressWindow && !this.paused ? this.networkHealthy + 1 : 0;
|
|
153
|
+
const nextFps = Math.min(this.maxFps, this.fps === 15 ? 30 : 60);
|
|
154
|
+
this.headroom = encodeCosts.length > 0 && !processing && s.queueAgeMs <= 40 && !this.paused &&
|
|
155
|
+
encodeCost < 0.6 * 1000 / nextFps ? this.headroom + 1 : 0;
|
|
156
|
+
this.recoveryWindows = nextFps > this.fps && nextFps <= this.recoveryFps && encodeCosts.length > 0 &&
|
|
157
|
+
progressWindow && !net && s.queueAgeMs <= 40 && !this.paused && encodeCost < 0.8 * 1000 / nextFps
|
|
158
|
+
? this.recoveryWindows + 1 : 0;
|
|
159
|
+
if (net)
|
|
160
|
+
this.snapshot.reasons.push('sender-path-congestion');
|
|
161
|
+
if (processing)
|
|
162
|
+
this.snapshot.reasons.push('processing-pressure');
|
|
163
|
+
if (sourcePressure)
|
|
164
|
+
this.snapshot.reasons.push('source-encode-pressure');
|
|
165
|
+
if (receiverPressure)
|
|
166
|
+
this.snapshot.reasons.push('receiver-backlog');
|
|
167
|
+
if (evidence.state === 'unknown')
|
|
168
|
+
this.snapshot.reasons.push('network-unknown');
|
|
169
|
+
if (this.fps < this.recoveryFps && s.nowMs < this.fpsRecoveryAfter)
|
|
170
|
+
this.snapshot.reasons.push('fps-recovery-backoff');
|
|
171
|
+
if (s.nowMs < this.cooldown)
|
|
172
|
+
return decision();
|
|
173
|
+
let target = this.target, fps = this.fps;
|
|
174
|
+
if (this.networkPressure >= 2 && s.nowMs - this.lastRateChange >= 2000) {
|
|
175
|
+
target = this.quantize(Math.min(target * 0.85, evidence.bandwidthBps ? evidence.bandwidthBps * 0.9 : target));
|
|
176
|
+
}
|
|
177
|
+
else if (this.networkHealthy >= 3 && s.nowMs - this.lastRateChange >= (runtimeRateReconfigure ? 2000 : 10000) &&
|
|
178
|
+
this.demandBps >= target * 0.25) {
|
|
179
|
+
target = this.quantize(target * (runtimeRateReconfigure ? evidence.state === 'usable' ? 1.5 : 1.2 : 1.1));
|
|
180
|
+
if (target > this.target)
|
|
181
|
+
this.snapshot.reasons.push('bandwidth-probe');
|
|
182
|
+
}
|
|
183
|
+
if (this.processingPressure >= 2 && s.nowMs - this.lastFpsChange >= 2000)
|
|
184
|
+
fps = fps === 60 ? 30 : 15;
|
|
185
|
+
else if ((this.headroom >= 3 || this.recoveryWindows >= 5) && s.nowMs >= this.fpsRecoveryAfter &&
|
|
186
|
+
s.nowMs - this.lastFpsChange >= (runtimeRateReconfigure ? 2000 : 10000)) {
|
|
187
|
+
fps = nextFps;
|
|
188
|
+
if (fps > this.fps && this.headroom < 3)
|
|
189
|
+
this.snapshot.reasons.push('fps-recovery-probe');
|
|
190
|
+
}
|
|
191
|
+
if (target === this.max)
|
|
192
|
+
this.snapshot.reasons.push('policy-limit');
|
|
193
|
+
if (target === this.target && fps === this.fps)
|
|
194
|
+
return decision();
|
|
195
|
+
if (!runtimeRateReconfigure && s.nowMs - this.lastReopen < 2000)
|
|
196
|
+
return decision();
|
|
197
|
+
this.reopens = this.reopens.filter(at => s.nowMs - at < 10000);
|
|
198
|
+
if (!runtimeRateReconfigure && this.reopens.length === 2) {
|
|
199
|
+
fps = 15;
|
|
200
|
+
this.cooldown = s.nowMs + 10000;
|
|
201
|
+
}
|
|
202
|
+
if (target !== this.target) {
|
|
203
|
+
this.lastRateChange = s.nowMs;
|
|
204
|
+
this.networkPressure = this.networkHealthy = 0;
|
|
205
|
+
}
|
|
206
|
+
if (fps !== this.fps) {
|
|
207
|
+
if (fps < this.fps) {
|
|
208
|
+
this.recoveryFps = Math.max(this.recoveryFps, this.fps);
|
|
209
|
+
if (s.nowMs <= this.fpsTrialUntil)
|
|
210
|
+
this.fpsRecoveryAfter = s.nowMs + 30000;
|
|
211
|
+
this.fpsTrialUntil = -Infinity;
|
|
212
|
+
}
|
|
213
|
+
else
|
|
214
|
+
this.fpsTrialUntil = s.nowMs + 10000;
|
|
215
|
+
this.lastFpsChange = s.nowMs;
|
|
216
|
+
this.processingPressure = this.headroom = this.recoveryWindows = 0;
|
|
217
|
+
}
|
|
218
|
+
this.target = target;
|
|
219
|
+
this.fps = fps;
|
|
220
|
+
if (!runtimeRateReconfigure) {
|
|
221
|
+
this.reopens.push(s.nowMs);
|
|
222
|
+
this.lastReopen = s.nowMs;
|
|
223
|
+
}
|
|
224
|
+
return decision(!runtimeRateReconfigure);
|
|
225
|
+
}
|
|
226
|
+
}
|