@platless/axom-cli 0.3.13 → 0.6.36

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.
Files changed (320) hide show
  1. package/README.md +18 -5
  2. package/dist/axom-patch/cli/README.md +119 -9
  3. package/dist/axom-patch/cli/account-limits/README.md +27 -0
  4. package/dist/axom-patch/cli/account-limits/antigravity-proxy.mjs +47 -0
  5. package/dist/axom-patch/cli/account-limits/antigravity-read.mjs +90 -0
  6. package/dist/axom-patch/cli/account-limits/antigravity.mjs +46 -0
  7. package/dist/axom-patch/cli/account-limits/generate.py +123 -0
  8. package/dist/axom-patch/cli/account-limits/kimi-proxy.mjs +81 -0
  9. package/dist/axom-patch/cli/account-limits/normalize.mjs +151 -0
  10. package/dist/axom-patch/cli/claude-account-limits.json +37 -0
  11. package/dist/axom-patch/cli/codex-account-limits.json +37 -0
  12. package/dist/axom-patch/cli/codex-terminal-output.json +16 -0
  13. package/dist/axom-patch/cli/commandcode-account-limits.json +30 -0
  14. package/dist/axom-patch/cli/kimi-quota.mjs +12 -0
  15. package/dist/axom-patch/cli/kimi-subagents.mjs +173 -0
  16. package/dist/axom-patch/cli/nightly-task.md +194 -0
  17. package/dist/axom-patch/cli/pi-subagent-subwork.json +23 -0
  18. package/dist/axom-patch/cli/probes/claude-late-async-terminal.mjs +5 -1
  19. package/dist/axom-patch/cli/probes/codex-terminal-output.mjs +33 -0
  20. package/dist/axom-patch/cli/probes/kimi-subagent-subwork.mjs +82 -0
  21. package/dist/axom-patch/cli/probes/pi-subagent-subwork.mjs +211 -0
  22. package/dist/axom-patch/cli/probes/zcode-subagent-subwork.mjs +257 -0
  23. package/dist/axom-patch/cli/qoder/dist/axom-acp-compat.mjs +1591 -0
  24. package/dist/axom-patch/cli/qoder/releases/1.1.75.json +360 -0
  25. package/dist/axom-patch/cli/qoder-background-terminal.md +13 -5
  26. package/dist/axom-patch/cli/qoder-foreground-output.md +14 -7
  27. package/dist/axom-patch/cli/qoder-native-acp.json +227 -0
  28. package/dist/axom-patch/cli/qoder-steering.md +20 -25
  29. package/dist/axom-patch/cli/qoder-subagent-subwork.md +17 -68
  30. package/dist/axom-patch/cli/runtime.json +39 -15
  31. package/dist/axom-patch/cli/zcode-account-limits.json +30 -0
  32. package/dist/axom-patch/cli/zcode-models.json +37 -0
  33. package/dist/axom-patch/cli/zcode-subagent-subwork.json +72 -0
  34. package/dist/cli.js +4 -9
  35. package/dist/commands/knowledge.js +47 -0
  36. package/dist/commands/update.js +65 -3
  37. package/dist/commands/workstation.js +73 -7
  38. package/dist/install/claude/commands.js +13 -13
  39. package/dist/keepers/acp/keeper.mjs +3083 -0
  40. package/dist/keepers/acp/manifest.json +9 -0
  41. package/dist/keepers/terminal/keeper.mjs +8469 -0
  42. package/dist/keepers/terminal/manifest.json +9 -0
  43. package/dist/keepers/terminal/node_modules/node-pty/lib/conpty_console_list_agent.js +25 -0
  44. package/dist/keepers/terminal/node_modules/node-pty/lib/eventEmitter2.js +47 -0
  45. package/dist/keepers/terminal/node_modules/node-pty/lib/index.js +52 -0
  46. package/dist/keepers/terminal/node_modules/node-pty/lib/interfaces.js +7 -0
  47. package/dist/keepers/terminal/node_modules/node-pty/lib/shared/conout.js +10 -0
  48. package/dist/keepers/terminal/node_modules/node-pty/lib/terminal.js +190 -0
  49. package/dist/keepers/terminal/node_modules/node-pty/lib/types.js +7 -0
  50. package/dist/keepers/terminal/node_modules/node-pty/lib/unixTerminal.js +351 -0
  51. package/dist/keepers/terminal/node_modules/node-pty/lib/utils.js +38 -0
  52. package/dist/keepers/terminal/node_modules/node-pty/lib/windowsConoutConnection.js +131 -0
  53. package/dist/keepers/terminal/node_modules/node-pty/lib/windowsPtyAgent.js +344 -0
  54. package/dist/keepers/terminal/node_modules/node-pty/lib/windowsTerminal.js +209 -0
  55. package/dist/keepers/terminal/node_modules/node-pty/lib/worker/conoutSocketWorker.js +22 -0
  56. package/dist/keepers/terminal/node_modules/node-pty/package.json +66 -0
  57. package/dist/keepers/terminal/node_modules/node-pty/prebuilds/darwin-arm64/pty.node +0 -0
  58. package/dist/keepers/terminal/node_modules/node-pty/prebuilds/darwin-arm64/spawn-helper +0 -0
  59. package/dist/keepers/terminal/node_modules/node-pty/prebuilds/darwin-x64/pty.node +0 -0
  60. package/dist/keepers/terminal/node_modules/node-pty/prebuilds/darwin-x64/spawn-helper +0 -0
  61. package/dist/keepers/terminal/node_modules/node-pty/prebuilds/linux-arm64/pty.node +0 -0
  62. package/dist/keepers/terminal/node_modules/node-pty/prebuilds/linux-x64/pty.node +0 -0
  63. package/dist/mcp.js +1 -1
  64. package/dist/native/darwin-arm64/axom-quic +0 -0
  65. package/dist/test/keeperKit.js +67 -0
  66. package/dist/workstation/acp/acpAgents.js +2192 -636
  67. package/dist/workstation/acp/acpClient.js +84 -495
  68. package/dist/workstation/acp/adoption.js +10 -396
  69. package/dist/workstation/acp/binaryInstall.js +100 -27
  70. package/dist/workstation/acp/builds/gc.js +245 -0
  71. package/dist/workstation/acp/builds/install/binary.js +28 -0
  72. package/dist/workstation/acp/builds/install/npm.js +324 -0
  73. package/dist/workstation/acp/builds/install/uv.js +254 -0
  74. package/dist/workstation/acp/builds/migrate.js +195 -0
  75. package/dist/workstation/acp/builds/model.js +128 -0
  76. package/dist/workstation/acp/builds/nodeGate.js +100 -0
  77. package/dist/workstation/acp/builds/store.js +352 -0
  78. package/dist/workstation/acp/commandTableProbe.js +68 -0
  79. package/dist/workstation/acp/configOptions.js +103 -1
  80. package/dist/workstation/acp/envSecrets.js +27 -0
  81. package/dist/workstation/acp/initializeResponse.js +290 -0
  82. package/dist/workstation/acp/installErrors.js +12 -2
  83. package/dist/workstation/acp/installProbe.js +1 -1
  84. package/dist/workstation/acp/managedPatches.js +239 -159
  85. package/dist/workstation/acp/managedRuntime.js +314 -0
  86. package/dist/workstation/acp/outbox.js +330 -0
  87. package/dist/workstation/acp/patchAssets.js +60 -3
  88. package/dist/workstation/acp/permission.js +42 -10
  89. package/dist/workstation/acp/processor/checkpoint.js +78 -0
  90. package/dist/workstation/acp/processor/commands.js +35 -0
  91. package/dist/workstation/acp/processor/control.js +282 -0
  92. package/dist/workstation/acp/processor/emit.js +26 -0
  93. package/dist/workstation/acp/processor/jsonrpc.js +172 -0
  94. package/dist/workstation/acp/processor/memoryLog.js +49 -0
  95. package/dist/workstation/acp/processor/origins.js +48 -0
  96. package/dist/workstation/acp/processor/output.js +67 -0
  97. package/dist/workstation/acp/processor/projection.js +42 -0
  98. package/dist/workstation/acp/processor/record.js +128 -0
  99. package/dist/workstation/acp/processor/runtime.js +105 -0
  100. package/dist/workstation/acp/processor/sdkSchemas.js +61 -0
  101. package/dist/workstation/acp/processor/session.js +496 -0
  102. package/dist/workstation/acp/processor/state.js +67 -0
  103. package/dist/workstation/acp/processor/step.js +442 -0
  104. package/dist/workstation/acp/processor/test/fixtureLog.js +58 -0
  105. package/dist/workstation/acp/processor/test/harness.js +120 -0
  106. package/dist/workstation/acp/processor/test/largeIdEcho.js +50 -0
  107. package/dist/workstation/acp/processor/test/rawAgent.js +70 -0
  108. package/dist/workstation/acp/processor/transport/generations.js +76 -0
  109. package/dist/workstation/acp/processor/transport/keeper.js +130 -0
  110. package/dist/workstation/acp/processor/transport/local.js +269 -0
  111. package/dist/workstation/acp/processor/transport/types.js +78 -0
  112. package/dist/workstation/acp/processor/updates.js +390 -0
  113. package/dist/workstation/acp/processorSession.js +1348 -0
  114. package/dist/workstation/acp/registry/catalog.js +189 -41
  115. package/dist/workstation/acp/registry/launch.js +76 -119
  116. package/dist/workstation/acp/sessionUpdateMapper.js +18 -7
  117. package/dist/workstation/acp/steering.js +58 -0
  118. package/dist/workstation/acp/switching.js +111 -0
  119. package/dist/workstation/acp/terminalLogin.js +16 -42
  120. package/dist/workstation/acp/terminalLoginSpec.js +41 -0
  121. package/dist/workstation/acp/test/adapterFixtures.js +256 -0
  122. package/dist/workstation/acp/test/daemonLife.js +106 -0
  123. package/dist/workstation/acp/test/fakeAgent.js +13 -0
  124. package/dist/workstation/acp/test/keeperWorld.js +295 -0
  125. package/dist/workstation/acp/test/memoryOutbox.js +55 -0
  126. package/dist/workstation/acp/test/raw/fixtures.js +196 -0
  127. package/dist/workstation/acp/test/raw/sanitize.js +344 -0
  128. package/dist/workstation/acp/test/raw/sources.js +135 -0
  129. package/dist/workstation/acp/test/realAdapter.js +331 -0
  130. package/dist/workstation/acp/test/scriptAgent.js +214 -0
  131. package/dist/workstation/acp/test/sessionFrames.js +42 -0
  132. package/dist/workstation/acp/timedCommand.js +4 -2
  133. package/dist/workstation/acp/uvxInstall.js +72 -122
  134. package/dist/workstation/agentFlow.js +103 -0
  135. package/dist/workstation/agentSessions.js +1289 -544
  136. package/dist/workstation/channels/agent.js +7 -5
  137. package/dist/workstation/channels/computer.js +69 -21
  138. package/dist/workstation/channels/computerExecs.js +200 -0
  139. package/dist/workstation/channels/management.js +172 -8
  140. package/dist/workstation/channels/url.js +1 -1
  141. package/dist/workstation/config.js +16 -4
  142. package/dist/workstation/connection/encryptedChannel.js +4 -1
  143. package/dist/workstation/control/bindingStore.js +200 -0
  144. package/dist/workstation/control/commands.js +124 -0
  145. package/dist/workstation/control/daemonIdentity.js +53 -0
  146. package/dist/workstation/control/enrollment.js +106 -0
  147. package/dist/workstation/control/inspect.js +71 -0
  148. package/dist/workstation/control/locks.js +63 -0
  149. package/dist/workstation/control/protocol.js +40 -0
  150. package/dist/workstation/control/restartGuard.js +46 -0
  151. package/dist/workstation/control/runtimeClient.js +97 -0
  152. package/dist/workstation/control/runtimeHost.js +148 -0
  153. package/dist/workstation/control/serverIdentity.js +35 -0
  154. package/dist/workstation/daemon.js +393 -12
  155. package/dist/workstation/daemonctl.js +103 -14
  156. package/dist/workstation/desktopControl/audio.js +99 -0
  157. package/dist/workstation/desktopControl/capabilities.js +92 -0
  158. package/dist/workstation/desktopControl/captureModes.js +9 -0
  159. package/dist/workstation/desktopControl/captureTargetLabel.js +9 -0
  160. package/dist/workstation/desktopControl/deviceSockets.js +246 -0
  161. package/dist/workstation/desktopControl/helperProcess.js +353 -0
  162. package/dist/workstation/desktopControl/lobby.js +129 -0
  163. package/dist/workstation/desktopControl/macProvider.js +155 -0
  164. package/dist/workstation/desktopControl/media.js +331 -0
  165. package/dist/workstation/desktopControl/nativeProvider.js +1018 -0
  166. package/dist/workstation/desktopControl/networkEvidence.js +43 -0
  167. package/dist/workstation/desktopControl/overview.js +58 -0
  168. package/dist/workstation/desktopControl/protocol.js +302 -0
  169. package/dist/workstation/desktopControl/quicMedia.js +240 -0
  170. package/dist/workstation/desktopControl/rateController.js +226 -0
  171. package/dist/workstation/desktopControl/supervisor.js +1681 -0
  172. package/dist/workstation/desktopControl/transport.js +27 -0
  173. package/dist/workstation/desktopControl/wallpaper.js +78 -0
  174. package/dist/workstation/exec/attach.js +126 -0
  175. package/dist/workstation/exec/command.js +40 -0
  176. package/dist/workstation/exec/durable.js +517 -0
  177. package/dist/workstation/exec/fallback.js +106 -0
  178. package/dist/workstation/exec/policy.js +837 -0
  179. package/dist/workstation/exec/shaping.js +211 -0
  180. package/dist/workstation/exec.js +3 -112
  181. package/dist/workstation/files/adapters/computerFileFrames.js +51 -0
  182. package/dist/workstation/files/adapters/toolRequests.js +121 -0
  183. package/dist/workstation/files/client.js +455 -0
  184. package/dist/workstation/files/credentials.js +142 -0
  185. package/dist/workstation/files/errors.js +28 -0
  186. package/dist/workstation/files/fence.js +350 -0
  187. package/dist/workstation/files/find/fileIndex.js +153 -0
  188. package/dist/workstation/files/find/fuzzy.js +155 -0
  189. package/dist/workstation/files/host.js +122 -0
  190. package/dist/workstation/files/hostProtocol.js +2 -0
  191. package/dist/workstation/files/media/cache.js +620 -0
  192. package/dist/workstation/files/media/encoding.js +308 -0
  193. package/dist/workstation/files/media/estimator.js +100 -0
  194. package/dist/workstation/files/media/media.js +325 -0
  195. package/dist/workstation/files/media/packedAudio.js +23 -0
  196. package/dist/workstation/files/media/scheduler.js +551 -0
  197. package/dist/workstation/files/media/types.js +5 -0
  198. package/dist/workstation/files/scope.js +45 -0
  199. package/dist/workstation/files/structured.js +284 -0
  200. package/dist/workstation/{fileOps.js → files/text.js} +152 -39
  201. package/dist/workstation/files/uploads.js +351 -0
  202. package/dist/workstation/journal.js +65 -236
  203. package/dist/workstation/keepers/acp/client.js +101 -0
  204. package/dist/workstation/keepers/acp/envelope.js +62 -0
  205. package/dist/workstation/keepers/acp/host.js +419 -0
  206. package/dist/workstation/keepers/acp/main.js +18 -0
  207. package/dist/workstation/keepers/acp/memoryStream.js +121 -0
  208. package/dist/workstation/keepers/acp/params.js +137 -0
  209. package/dist/workstation/keepers/acp/protocol.js +66 -0
  210. package/dist/workstation/keepers/acp/recover.js +120 -0
  211. package/dist/workstation/keepers/acp/session.js +584 -0
  212. package/dist/workstation/keepers/acp/stderr.js +154 -0
  213. package/dist/workstation/keepers/kit/activity.js +103 -0
  214. package/dist/workstation/keepers/kit/bootstrap.js +164 -0
  215. package/dist/workstation/keepers/kit/buildVersion.js +51 -0
  216. package/dist/workstation/keepers/kit/bundle.js +124 -0
  217. package/dist/workstation/keepers/kit/client.js +432 -0
  218. package/dist/workstation/keepers/kit/identity.js +21 -0
  219. package/dist/workstation/keepers/kit/ipc.js +112 -0
  220. package/dist/workstation/keepers/kit/launchConfig.js +8 -0
  221. package/dist/workstation/keepers/kit/launcher.js +289 -0
  222. package/dist/workstation/keepers/kit/lock.js +123 -0
  223. package/dist/workstation/keepers/kit/orphanSweep.js +86 -0
  224. package/dist/workstation/keepers/kit/paths.js +76 -0
  225. package/dist/workstation/keepers/kit/protocol.js +43 -0
  226. package/dist/workstation/keepers/kit/server.js +518 -0
  227. package/dist/workstation/keepers/kit/streamLog.js +697 -0
  228. package/dist/workstation/keepers/legacy.js +296 -0
  229. package/dist/workstation/keepers/policy.js +576 -0
  230. package/dist/workstation/keepers/stop.js +34 -0
  231. package/dist/workstation/keepers/terminal/client.js +213 -0
  232. package/dist/workstation/keepers/terminal/exec.js +981 -0
  233. package/dist/workstation/keepers/terminal/generations.js +129 -0
  234. package/dist/workstation/keepers/terminal/keeper.js +62 -0
  235. package/dist/workstation/keepers/terminal/main.js +43 -0
  236. package/dist/workstation/keepers/terminal/orphanSweep.js +3 -0
  237. package/dist/workstation/keepers/terminal/params.js +27 -0
  238. package/dist/workstation/keepers/terminal/protocol.js +56 -0
  239. package/dist/workstation/keepers/terminal/pty.js +330 -0
  240. package/dist/workstation/managedInstall.js +57 -0
  241. package/dist/workstation/protocol/accountLimits.js +47 -0
  242. package/dist/workstation/protocol/agent.js +50 -19
  243. package/dist/workstation/protocol/common.js +30 -0
  244. package/dist/workstation/protocol/computer.js +15 -4
  245. package/dist/workstation/protocol/management.js +141 -4
  246. package/dist/workstation/protocol/runtimeDiagnostics.js +15 -0
  247. package/dist/workstation/rd/artifact.js +119 -0
  248. package/dist/workstation/rd/control.js +119 -0
  249. package/dist/workstation/rd/display.js +29 -0
  250. package/dist/workstation/rd/provider.js +222 -0
  251. package/dist/workstation/rd/sessions.js +391 -0
  252. package/dist/workstation/rd/state.js +45 -0
  253. package/dist/workstation/rd/update.js +171 -0
  254. package/dist/workstation/rd/upkeep.js +38 -0
  255. package/dist/workstation/register.js +27 -37
  256. package/dist/workstation/service/installer.js +104 -13
  257. package/dist/workstation/service/launchd.js +1 -0
  258. package/dist/workstation/storageMetrics.js +118 -0
  259. package/dist/workstation/systemMetrics.js +154 -93
  260. package/dist/workstation/toolchain.js +94 -0
  261. package/dist/workstation/tools/browser.js +28 -4
  262. package/dist/workstation/tools/client.js +9 -1
  263. package/dist/workstation/tools/info.js +50 -0
  264. package/dist/workstation/tools/keeperProcess.js +15 -5
  265. package/dist/workstation/tools/router.js +55 -0
  266. package/dist/workstation/tools/terminalRouter.js +222 -0
  267. package/dist/workstation/tools/validation.js +37 -1
  268. package/dist/workstation/update/artifact.js +2 -1
  269. package/dist/workstation/update/coordinator.js +3 -0
  270. package/dist/workstation/update/globalInstall.js +116 -0
  271. package/dist/workstation/update/npmInstaller.js +49 -23
  272. package/dist/workstation/update/ptyPreflight.js +21 -0
  273. package/dist/workstation/update/rdRollback.js +145 -0
  274. package/dist/workstation/update/runUpdate.js +3 -2
  275. package/dist/workstation/update/taskRegistry.js +105 -11
  276. package/dist/workstation/update/watchdog.js +16790 -334
  277. package/package.json +11 -8
  278. package/skills/axom/SKILL.md +11 -11
  279. package/skills/axom-definition/SKILL.md +3 -3
  280. package/skills/axom-platform/SKILL.md +3 -3
  281. package/dist/axom-patch/cli/probes/qoder-steering.mjs +0 -89
  282. package/dist/axom-patch/cli/probes/qoder-subagent-origin.mjs +0 -49
  283. package/dist/axom-patch/cli/qoder-steering.json +0 -52
  284. package/dist/axom-patch/cli/qoder-subagent-origin.json +0 -73
  285. package/dist/commands/guide.js +0 -38
  286. package/dist/workstation/acp/acpSession.js +0 -1475
  287. package/dist/workstation/acp/contract.js +0 -499
  288. package/dist/workstation/acp/delegationMcp.js +0 -24
  289. package/dist/workstation/acp/draftInterceptor.js +0 -163
  290. package/dist/workstation/acp/qoderStartup.js +0 -45
  291. package/dist/workstation/acp/sessionScope.js +0 -19
  292. package/dist/workstation/filePaths.js +0 -174
  293. package/dist/workstation/fileWorker.js +0 -81
  294. package/dist/workstation/fileWorkerClient.js +0 -121
  295. package/dist/workstation/qoderAdapter/backgroundProcess.js +0 -106
  296. package/dist/workstation/qoderAdapter/backgroundTerminal.js +0 -262
  297. package/dist/workstation/qoderAdapter/completedContinuation.js +0 -139
  298. package/dist/workstation/qoderAdapter/contract.js +0 -78
  299. package/dist/workstation/qoderAdapter/foregroundOutput.js +0 -30
  300. package/dist/workstation/qoderAdapter/history.js +0 -87
  301. package/dist/workstation/qoderAdapter/identityIndex.js +0 -191
  302. package/dist/workstation/qoderAdapter/inputQueue.js +0 -42
  303. package/dist/workstation/qoderAdapter/main.js +0 -93
  304. package/dist/workstation/qoderAdapter/mapper.js +0 -117
  305. package/dist/workstation/qoderAdapter/observerPlugin.js +0 -245
  306. package/dist/workstation/qoderAdapter/observerReceiver.js +0 -187
  307. package/dist/workstation/qoderAdapter/permissions.js +0 -61
  308. package/dist/workstation/qoderAdapter/profile.js +0 -93
  309. package/dist/workstation/qoderAdapter/sdkDriver.js +0 -49
  310. package/dist/workstation/qoderAdapter/session.js +0 -319
  311. package/dist/workstation/qoderAdapter/subagentMeta.js +0 -28
  312. package/dist/workstation/qoderAdapter/subwork.js +0 -77
  313. package/dist/workstation/qoderAdapter/taskControl.js +0 -38
  314. package/dist/workstation/qoderAdapter/taskEvent.js +0 -26
  315. package/dist/workstation/qoderAdapter/taskLedger.js +0 -163
  316. package/dist/workstation/qoderAdapter/usage.js +0 -37
  317. package/dist/workstation/tools/core.js +0 -50
  318. package/dist/workstation/tools/files.js +0 -525
  319. package/dist/workstation/tools/terminal.js +0 -214
  320. /package/dist/workstation/{qoderAdapter/types.js → desktopControl/provider.js} +0 -0
@@ -0,0 +1,331 @@
1
+ import { z } from 'zod';
2
+ import { DesktopProtocolError, parseDesktopJson } from './protocol.js';
3
+ export function mediaRequire(value) {
4
+ if (!value)
5
+ throw new DesktopProtocolError('Invalid desktop media');
6
+ }
7
+ const integer = (n, min = 0, max = Number.MAX_SAFE_INTEGER) => Number.isSafeInteger(n) && n >= min && n <= max;
8
+ const axis = z.number().int().min(2).max(4096).refine(n => n % 2 === 0);
9
+ const label = z.string().min(1).refine(s => Buffer.byteLength(s) <= 128 && !/[\x00-\x1f\x7f]/.test(s));
10
+ const codecSchema = z.strictObject({ codec: z.literal('h264'), representation: z.literal(1),
11
+ width: axis, height: axis, fpsCeiling: z.union([z.literal(15), z.literal(30), z.literal(60)]),
12
+ profile: label, level: label, colorMatrix: z.literal('bt709'), colorRange: z.literal('limited'), parameterSets: z.array(z.string()) });
13
+ function checked(read) {
14
+ try {
15
+ return read();
16
+ }
17
+ catch {
18
+ throw new DesktopProtocolError('Invalid desktop media');
19
+ }
20
+ }
21
+ export function decodeConfig(bytes) {
22
+ return checked(() => {
23
+ const c = codecSchema.parse(parseDesktopJson(bytes, 16384));
24
+ mediaRequire(c.parameterSets.length === 2);
25
+ c.parameterSets.forEach((encoded, i) => {
26
+ mediaRequire(encoded.length <= 2732);
27
+ const nal = Buffer.from(encoded, 'base64');
28
+ mediaRequire(nal.length >= 1 && nal.length <= 2048 && nal.toString('base64') === encoded &&
29
+ (nal[0] & 128) === 0 && (nal[0] & 31) === (i % 2 === 0 ? 7 : 8));
30
+ });
31
+ return c;
32
+ });
33
+ }
34
+ function validateUnit(p, bytes) {
35
+ if (p.type === 1)
36
+ mediaRequire(decodeConfig(bytes).representation === p.representation);
37
+ else if (p.type === 3) {
38
+ const w = bytes.readUInt16BE(), h = bytes.readUInt16BE(2);
39
+ mediaRequire(w >= 1 && w <= 256 && h >= 1 && h <= 256 && bytes.readUInt16BE(4) < w &&
40
+ bytes.readUInt16BE(6) < h && w * h * 4 + 8 === p.unitLength);
41
+ }
42
+ else if (p.type === 5) {
43
+ mediaRequire(bytes.length >= 95 && bytes.subarray(0, 16).equals(Buffer.from('28b4619e8e524cf29ae8415852473034', 'hex')) && bytes[16] === 4 && bytes[37] === 1 && bytes.readUInt32BE(38) === 0 && bytes.readUInt16BE(42) > 0 && bytes.readUInt16BE(42) <= 1024);
44
+ const focusRevision = bytes.readBigUInt64BE(44), [x, y, w, h, sw, sh] = [52, 56, 60, 64, 68, 72].map(o => bytes.readUInt32BE(o));
45
+ mediaRequire(focusRevision > 0n && focusRevision <= BigInt(Number.MAX_SAFE_INTEGER) && w > 0 && h > 0 && sw >= 2 && sh >= 2 && sw <= 4096 && sh <= 4096 && x + w <= sw && y + h <= sh);
46
+ mediaRequire(axis.safeParse(bytes.readUInt16BE(17)).success && axis.safeParse(bytes.readUInt16BE(19)).success && bytes.readBigUInt64BE(21) > 0n && bytes.readBigUInt64BE(21) <= BigInt(Number.MAX_SAFE_INTEGER) && bytes.readBigUInt64BE(29) > 0n && bytes.readBigUInt64BE(29) <= BigInt(Number.MAX_SAFE_INTEGER));
47
+ }
48
+ else if (p.type === 4)
49
+ cursor(bytes);
50
+ }
51
+ function cursor(bytes) {
52
+ return checked(() => z.strictObject({ x: z.number().int().min(0).max(4095),
53
+ y: z.number().int().min(0).max(4095), visible: z.boolean() }).parse(parseDesktopJson(bytes, 1024)));
54
+ }
55
+ /** Validates the header and current identity before retaining/reassembling payload. */
56
+ export function decodeMedia(bytes, fence = () => { }) {
57
+ return checked(() => {
58
+ mediaRequire(bytes.length >= 65 && bytes.length <= 65600 && bytes.subarray(0, 5).equals(Buffer.from('AXDS\x01')) &&
59
+ bytes.readUInt16BE(8) === 64 && bytes.readUInt16BE(10) === 0 && bytes.readUIntBE(61, 3) === 0);
60
+ const u64 = (offset) => { const n = bytes.readBigUInt64BE(offset); mediaRequire(n <= BigInt(Number.MAX_SAFE_INTEGER)); return Number(n); };
61
+ const length = bytes.readUInt32BE(48);
62
+ const p = { type: bytes[5], flags: bytes.readUInt16BE(6), epoch: bytes.readUInt32BE(12),
63
+ displayRevision: bytes.readUInt32BE(16), sequence: bytes.readUInt32BE(20), frameId: u64(24), timestampUs: u64(32),
64
+ lastInputSequence: u64(40), unitLength: bytes.readUInt32BE(52), fragmentIndex: bytes.readUInt16BE(56),
65
+ fragmentCount: bytes.readUInt16BE(58), representation: bytes[60], payload: Buffer.alloc(0) };
66
+ mediaRequire(p.type >= 1 && p.type <= 5 && p.representation === 1 && p.flags <= 1 &&
67
+ (p.type === 2 || p.flags === 0) && p.epoch > 0 && p.displayRevision > 0 && p.sequence > 0 &&
68
+ ((p.type === 2 || p.type === 5) ? p.frameId > 0 : p.frameId === 0 && p.timestampUs === 0));
69
+ mediaRequire(length > 0 && length <= 65536 && bytes.length === 64 + length && p.unitLength > 0 && p.unitLength <= 8388608);
70
+ const count = Math.ceil(p.unitLength / 65536);
71
+ mediaRequire(p.fragmentCount === count && p.fragmentIndex < count &&
72
+ length === (p.fragmentIndex === count - 1 ? p.unitLength - p.fragmentIndex * 65536 : 65536));
73
+ if (p.type === 1)
74
+ mediaRequire(count === 1 && p.unitLength <= 16384);
75
+ if (p.type === 3)
76
+ mediaRequire(p.unitLength >= 12 && p.unitLength <= 262152);
77
+ if (p.type === 5)
78
+ mediaRequire(count === 1 && p.unitLength >= 95 && p.unitLength <= 24576);
79
+ if (p.type === 4)
80
+ mediaRequire(count === 1 && p.unitLength <= 1024);
81
+ fence(p);
82
+ p.payload = bytes.subarray(64);
83
+ if (count === 1)
84
+ validateUnit(p, p.payload);
85
+ return p;
86
+ });
87
+ }
88
+ export class DesktopMediaStream {
89
+ sourceDimensions;
90
+ constructor(sourceDimensions = () => undefined) {
91
+ this.sourceDimensions = sourceDimensions;
92
+ }
93
+ configuration = null;
94
+ epoch = 0;
95
+ revision = 0;
96
+ picture = { sequence: 0, lastFrame: 0, pending: undefined, storage: undefined, next: 0 };
97
+ cursorLane = { sequence: 0, lastFrame: 0, pending: undefined, storage: undefined, next: 0 };
98
+ exactLane = { sequence: 0, lastFrame: 0, pending: undefined, storage: undefined, next: 0 };
99
+ lane(type) { return type === 3 || type === 4 ? this.cursorLane : type === 5 ? this.exactLane : this.picture; }
100
+ exactSequence = 0;
101
+ recentFrames = [];
102
+ needsIdr = true;
103
+ failed = false;
104
+ accept(bytes) {
105
+ mediaRequire(!this.failed);
106
+ try {
107
+ const p = decodeMedia(bytes, packet => this.validate(packet));
108
+ const lane = this.lane(p.type);
109
+ lane.sequence = p.sequence;
110
+ if (p.type === 1) {
111
+ this.configuration = decodeConfig(p.payload);
112
+ this.epoch = p.epoch;
113
+ this.revision = p.displayRevision;
114
+ this.needsIdr = true;
115
+ this.exactSequence = 0;
116
+ this.exactLane.sequence = 0;
117
+ this.exactLane.pending = undefined;
118
+ this.exactLane.storage = undefined;
119
+ this.exactLane.next = 0;
120
+ this.cursorLane.sequence = 0;
121
+ this.cursorLane.pending = undefined;
122
+ this.cursorLane.storage = undefined;
123
+ this.cursorLane.next = 0;
124
+ return null;
125
+ }
126
+ if (p.fragmentCount === 1)
127
+ return this.complete(p, p.payload);
128
+ if (!lane.pending) {
129
+ lane.pending = { ...p, payload: Buffer.alloc(0) };
130
+ lane.storage = Buffer.alloc(p.unitLength);
131
+ lane.next = 0;
132
+ }
133
+ p.payload.copy(lane.storage, lane.next++ * 65536);
134
+ if (lane.next !== p.fragmentCount)
135
+ return null;
136
+ const first = lane.pending, unit = lane.storage;
137
+ lane.pending = undefined;
138
+ lane.storage = undefined;
139
+ validateUnit(first, unit);
140
+ return this.complete(first, unit);
141
+ }
142
+ catch {
143
+ this.failed = true;
144
+ this.picture.pending = this.cursorLane.pending = this.exactLane.pending = undefined;
145
+ this.picture.storage = this.cursorLane.storage = this.exactLane.storage = undefined;
146
+ throw new DesktopProtocolError('Invalid desktop stream');
147
+ }
148
+ }
149
+ applyMotionCut(pictureThrough, frameThrough) {
150
+ mediaRequire(!this.failed && this.configuration && integer(pictureThrough, this.picture.sequence, 0xffffffff) && integer(frameThrough, this.picture.lastFrame));
151
+ this.picture.sequence = pictureThrough;
152
+ this.picture.lastFrame = frameThrough;
153
+ this.picture.pending = undefined;
154
+ this.picture.storage = undefined;
155
+ this.picture.next = 0;
156
+ this.needsIdr = true;
157
+ }
158
+ validate(p) {
159
+ const lane = this.lane(p.type);
160
+ if (p.type === 1) {
161
+ mediaRequire(!this.picture.pending && p.epoch > this.epoch && p.sequence === 1);
162
+ return;
163
+ }
164
+ mediaRequire(this.configuration && p.epoch === this.epoch && p.displayRevision === this.revision &&
165
+ p.representation === this.configuration.representation && p.sequence === lane.sequence + 1);
166
+ if (!lane.pending) {
167
+ mediaRequire(p.fragmentIndex === 0);
168
+ if (p.type === 2 || p.type === 5)
169
+ mediaRequire(p.frameId > lane.lastFrame && !this.recentFrames.includes(p.frameId) && p.frameId !== this.picture.pending?.frameId && (!this.needsIdr || p.type === 2 && p.flags === 1));
170
+ }
171
+ else {
172
+ const first = lane.pending;
173
+ mediaRequire(['type', 'flags', 'frameId', 'timestampUs', 'lastInputSequence', 'unitLength', 'fragmentCount']
174
+ .every(k => p[k] === first[k]) && p.fragmentIndex === lane.next);
175
+ }
176
+ }
177
+ complete(p, bytes) {
178
+ if (p.type === 4) {
179
+ const c = cursor(bytes), source = this.sourceDimensions() ?? this.configuration;
180
+ mediaRequire(c.x < source.width && c.y < source.height);
181
+ }
182
+ if (p.type !== 2 && p.type !== 5)
183
+ return null;
184
+ const exactSequence = p.type === 5 ? Number(bytes.readBigUInt64BE(29)) : 0;
185
+ if (p.type === 5) {
186
+ mediaRequire(exactSequence === this.exactSequence + 1 && bytes.readUInt16BE(17) === this.configuration.width && bytes.readUInt16BE(19) === this.configuration.height);
187
+ this.exactSequence = exactSequence;
188
+ }
189
+ else
190
+ this.needsIdr = false;
191
+ this.lane(p.type).lastFrame = p.frameId;
192
+ this.recentFrames.push(p.frameId);
193
+ if (this.recentFrames.length > 128)
194
+ this.recentFrames.shift();
195
+ return { ...p, payload: bytes, mainAU: bytes, exactSequence };
196
+ }
197
+ }
198
+ const lanes = ['motion', 'cursor', 'exact'];
199
+ const consumedKey = { motion: 'motionConsumedBytes', cursor: 'cursorConsumedBytes', exact: 'exactConsumedBytes' };
200
+ const freshTotals = () => ({ motion: 0, cursor: 0, exact: 0 });
201
+ export function desktopMediaLane(type) {
202
+ mediaRequire(integer(type, 1, 5));
203
+ return type <= 2 ? 'motion' : type <= 4 ? 'cursor' : 'exact';
204
+ }
205
+ /** One epoch's bounded reservations and actual transport admissions. Pipe writes never commit. */
206
+ export class DesktopMediaFlowWindow {
207
+ window;
208
+ records = new Map();
209
+ committed = freshTotals();
210
+ reserved = freshTotals();
211
+ observed = freshTotals();
212
+ consumed = freshTotals();
213
+ lastId = 0;
214
+ constructor(window = 0) {
215
+ this.window = window;
216
+ mediaRequire(window === 0 || integer(window, 196608, 524288));
217
+ }
218
+ get inFlightBytes() { return lanes.reduce((n, l) => n + this.debt(l), 0); }
219
+ get recordCount() { return this.records.size; }
220
+ get hasCredit() { return this.window > 0; }
221
+ get appliedCredit() { return { motionConsumedBytes: this.consumed.motion, cursorConsumedBytes: this.consumed.cursor, exactConsumedBytes: this.consumed.exact, windowBytes: this.window }; }
222
+ debt(lane) { return this.committed[lane] + this.reserved[lane] - this.consumed[lane]; }
223
+ laneRecords(lane) { return [...this.records.values()].filter(r => r.lane === lane).length; }
224
+ admit(lane, bytes) {
225
+ mediaRequire(lanes.includes(lane) && integer(bytes, 1, lane === 'exact' ? 24576 : 65536));
226
+ const others = lanes.filter(l => l !== lane && l !== 'motion');
227
+ const protectedBytes = others.reduce((n, l) => n + Math.max(0, (l === 'cursor' ? 65536 : 24576) - this.debt(l)), 0);
228
+ const protectedRecords = others.reduce((n, l) => n + (this.laneRecords(l) === 0 ? 1 : 0), 0);
229
+ return this.records.size + 1 <= 128 - protectedRecords && this.inFlightBytes + bytes <= this.window - protectedBytes;
230
+ }
231
+ /** IDs are fresh monotonically increasing local admission attempts, including failed attempts. */
232
+ reserve(id, lane, bytes) {
233
+ mediaRequire(integer(id, this.lastId + 1));
234
+ this.lastId = id;
235
+ if (!this.admit(lane, bytes))
236
+ return false;
237
+ mediaRequire(this.committed[lane] <= Number.MAX_SAFE_INTEGER - this.reserved[lane] - bytes);
238
+ this.reserved[lane] += bytes;
239
+ this.records.set(id, { lane, bytes, remaining: bytes, committed: false });
240
+ return true;
241
+ }
242
+ commit(id) {
243
+ const r = this.records.get(id);
244
+ mediaRequire(r && !r.committed);
245
+ this.reserved[r.lane] -= r.bytes;
246
+ this.committed[r.lane] += r.bytes;
247
+ r.committed = true;
248
+ this.applyPending();
249
+ }
250
+ cancel(id) {
251
+ const r = this.records.get(id);
252
+ mediaRequire(r && !r.committed);
253
+ mediaRequire(this.observed[r.lane] <= this.committed[r.lane] + this.reserved[r.lane] - r.bytes);
254
+ this.reserved[r.lane] -= r.bytes;
255
+ this.records.delete(id);
256
+ }
257
+ credit(value) {
258
+ mediaRequire(integer(value.windowBytes, 196608, 524288) && Number.isSafeInteger(value.motionConsumedBytes + value.cursorConsumedBytes + value.exactConsumedBytes));
259
+ for (const l of lanes)
260
+ mediaRequire(integer(value[consumedKey[l]], this.observed[l], this.committed[l] + this.reserved[l]));
261
+ for (const l of lanes)
262
+ this.observed[l] = value[consumedKey[l]];
263
+ this.window = value.windowBytes;
264
+ this.applyPending();
265
+ }
266
+ applyPending() {
267
+ for (const lane of lanes) {
268
+ if (this.observed[lane] > this.committed[lane])
269
+ continue;
270
+ let delta = this.observed[lane] - this.consumed[lane];
271
+ this.consumed[lane] = this.observed[lane];
272
+ for (const [id, r] of this.records)
273
+ if (delta && r.lane === lane && r.committed) {
274
+ const used = Math.min(delta, r.remaining);
275
+ r.remaining -= used;
276
+ delta -= used;
277
+ if (!r.remaining)
278
+ this.records.delete(id);
279
+ }
280
+ mediaRequire(delta === 0);
281
+ }
282
+ }
283
+ }
284
+ /** Sender-clock complete-frame send -> feedback. Feedback scheduling is not network delay. */
285
+ export class DesktopDeliveryDelay {
286
+ frames = new Map();
287
+ samples = [];
288
+ observation = 0;
289
+ sampled = 0;
290
+ sent(frame, at) {
291
+ this.frames.set(frame, at);
292
+ if (this.frames.size > 512)
293
+ this.frames.delete(this.frames.keys().next().value);
294
+ }
295
+ received(frame, at) {
296
+ const sent = this.frames.get(frame);
297
+ if (sent === undefined)
298
+ return;
299
+ this.samples.push({ at, delay: Math.max(0, at - sent), observation: ++this.observation });
300
+ if (this.samples.length > 500)
301
+ this.samples.shift();
302
+ // Independent exact/motion completion may insert IDs out of numeric order.
303
+ for (const id of this.frames.keys())
304
+ if (id <= frame)
305
+ this.frames.delete(id);
306
+ }
307
+ excess(now) {
308
+ this.samples = this.samples.filter(s => now - s.at <= 90000);
309
+ const recent = this.samples.filter(s => now - s.at <= 1250);
310
+ if (!recent.length)
311
+ return 0;
312
+ return Math.max(0, Math.min(...recent.map(s => s.delay)) - Math.min(...this.samples.map(s => s.delay)));
313
+ }
314
+ sample(now) {
315
+ const raw = this.excess(now);
316
+ const fresh = this.samples.filter(s => s.observation > this.sampled && now - s.at <= 1250);
317
+ this.sampled = this.observation;
318
+ if (!fresh.length)
319
+ return { excessMs: raw, observations: 0, delayMs: undefined };
320
+ const excessMs = Math.max(0, Math.min(...fresh.map(s => s.delay)) - Math.min(...this.samples.map(s => s.delay)));
321
+ // The active feedback cadence allows 200ms of scheduling uncertainty. Only
322
+ // the excess beyond that can establish >40ms congestion; ambiguity must hold.
323
+ const delayMs = excessMs <= 40 ? excessMs : excessMs > 240 ? excessMs - 200 : undefined;
324
+ return { excessMs, observations: fresh.length, delayMs };
325
+ }
326
+ reset() {
327
+ this.frames.clear();
328
+ this.samples = [];
329
+ this.sampled = this.observation;
330
+ }
331
+ }