oh-my-openagent 5.1.71 → 5.1.73

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 (76) hide show
  1. package/dist/cli/index.js +2447 -427
  2. package/dist/cli-node/index.js +2447 -427
  3. package/dist/index.js +180 -180
  4. package/dist/skills/browser/runtime/omowright/manifest.json +1 -1
  5. package/dist/skills/frontend/references/design/print-paged-media.md +1 -1
  6. package/dist/skills/ulw-execute/SKILL.md +2 -2
  7. package/dist/skills/ulw-plan/references/full-workflow.md +1 -1
  8. package/dist/skills/ulw-plan/scripts/plan-templates.mjs +1 -1
  9. package/dist/skills/ulw-research/references/research-collection.md +1 -1
  10. package/dist/tui.js +14 -14
  11. package/package.json +14 -14
  12. package/packages/omo-codex/plugin/.codex-plugin/plugin.json +1 -1
  13. package/packages/omo-codex/plugin/components/bootstrap/hooks/hooks.json +1 -1
  14. package/packages/omo-codex/plugin/components/bootstrap/package.json +1 -1
  15. package/packages/omo-codex/plugin/components/comment-checker/hooks/hooks.json +1 -1
  16. package/packages/omo-codex/plugin/components/comment-checker/package.json +1 -1
  17. package/packages/omo-codex/plugin/components/git-bash/hooks/hooks.json +2 -2
  18. package/packages/omo-codex/plugin/components/git-bash/package.json +1 -1
  19. package/packages/omo-codex/plugin/components/lazycodex-executor-verify/hooks/hooks.json +1 -1
  20. package/packages/omo-codex/plugin/components/lazycodex-executor-verify/package.json +1 -1
  21. package/packages/omo-codex/plugin/components/lsp/dist/.omo-runtime-manifest.json +2 -2
  22. package/packages/omo-codex/plugin/components/lsp/hooks/hooks.json +2 -2
  23. package/packages/omo-codex/plugin/components/lsp/package.json +1 -1
  24. package/packages/omo-codex/plugin/components/rules/hooks/hooks.json +4 -4
  25. package/packages/omo-codex/plugin/components/rules/package.json +1 -1
  26. package/packages/omo-codex/plugin/components/teammode/hooks/hooks.json +1 -1
  27. package/packages/omo-codex/plugin/components/teammode/package.json +1 -1
  28. package/packages/omo-codex/plugin/components/telemetry/hooks/hooks.json +1 -1
  29. package/packages/omo-codex/plugin/components/telemetry/package.json +1 -1
  30. package/packages/omo-codex/plugin/components/ultrawork/agents/plan.toml +2 -2
  31. package/packages/omo-codex/plugin/components/ultrawork/hooks/hooks.json +1 -1
  32. package/packages/omo-codex/plugin/components/ultrawork/package.json +1 -1
  33. package/packages/omo-codex/plugin/components/ultrawork/skills/ulw-plan/references/full-workflow.md +1 -1
  34. package/packages/omo-codex/plugin/components/ultrawork/skills/ulw-plan/scripts/plan-templates.mjs +1 -1
  35. package/packages/omo-codex/plugin/components/ulw-execute-continuation/hooks/hooks.json +1 -1
  36. package/packages/omo-codex/plugin/components/ulw-execute-continuation/package.json +1 -1
  37. package/packages/omo-codex/plugin/components/ulw-loop/hooks/hooks.json +5 -5
  38. package/packages/omo-codex/plugin/components/ulw-loop/package.json +1 -1
  39. package/packages/omo-codex/plugin/components/ulw-loop/skills/ulw-loop/references/full-workflow.md +1 -1
  40. package/packages/omo-codex/plugin/hooks/post-compact-resetting-git-bash-mcp-reminder.json +1 -1
  41. package/packages/omo-codex/plugin/hooks/post-compact-resetting-lsp-diagnostics-cache.json +1 -1
  42. package/packages/omo-codex/plugin/hooks/post-compact-resetting-project-rule-cache.json +1 -1
  43. package/packages/omo-codex/plugin/hooks/post-tool-use-checking-comments.json +1 -1
  44. package/packages/omo-codex/plugin/hooks/post-tool-use-checking-lsp-diagnostics.json +1 -1
  45. package/packages/omo-codex/plugin/hooks/post-tool-use-checking-thread-title-hygiene.json +1 -1
  46. package/packages/omo-codex/plugin/hooks/post-tool-use-matching-project-rules.json +1 -1
  47. package/packages/omo-codex/plugin/hooks/post-tool-use-recording-spawn-admission.json +1 -1
  48. package/packages/omo-codex/plugin/hooks/pre-tool-use-enforcing-unlimited-goal-budget.json +1 -1
  49. package/packages/omo-codex/plugin/hooks/pre-tool-use-guarding-ulw-loop-spawns.json +1 -1
  50. package/packages/omo-codex/plugin/hooks/pre-tool-use-recommending-git-bash-mcp.json +1 -1
  51. package/packages/omo-codex/plugin/hooks/session-start-checking-auto-update.json +1 -1
  52. package/packages/omo-codex/plugin/hooks/session-start-checking-bootstrap-provisioning.json +1 -1
  53. package/packages/omo-codex/plugin/hooks/session-start-loading-project-rules.json +1 -1
  54. package/packages/omo-codex/plugin/hooks/session-start-recording-session-telemetry.json +1 -1
  55. package/packages/omo-codex/plugin/hooks/stop-checking-ulw-execute-continuation.json +1 -1
  56. package/packages/omo-codex/plugin/hooks/stop-checking-ulw-loop-resume.json +1 -1
  57. package/packages/omo-codex/plugin/hooks/subagent-stop-verifying-lazycodex-executor-evidence.json +1 -1
  58. package/packages/omo-codex/plugin/hooks/user-prompt-submit-checking-ultrawork-trigger.json +1 -1
  59. package/packages/omo-codex/plugin/hooks/user-prompt-submit-checking-ulw-loop-steering.json +1 -1
  60. package/packages/omo-codex/plugin/hooks/user-prompt-submit-loading-project-rules.json +1 -1
  61. package/packages/omo-codex/plugin/package-lock.json +12 -12
  62. package/packages/omo-codex/plugin/package.json +1 -1
  63. package/packages/omo-codex/plugin/skills/browser/runtime/omowright/manifest.json +1 -1
  64. package/packages/omo-codex/plugin/skills/frontend/references/design/print-paged-media.md +1 -1
  65. package/packages/omo-codex/plugin/skills/ulw-execute/SKILL.md +2 -2
  66. package/packages/omo-codex/plugin/skills/ulw-loop/references/full-workflow.md +1 -1
  67. package/packages/omo-codex/plugin/skills/ulw-plan/references/full-workflow.md +1 -1
  68. package/packages/omo-codex/plugin/skills/ulw-plan/scripts/plan-templates.mjs +1 -1
  69. package/packages/omo-codex/plugin/skills/ulw-research/references/research-collection.md +1 -1
  70. package/packages/omo-codex/scripts/install-dist/install-local.mjs +2 -2
  71. package/packages/shared-skills/skills/browser/runtime/omowright/manifest.json +1 -1
  72. package/packages/shared-skills/skills/frontend/references/design/print-paged-media.md +1 -1
  73. package/packages/shared-skills/skills/ulw-execute/SKILL.md +2 -2
  74. package/packages/shared-skills/skills/ulw-plan/references/full-workflow.md +1 -1
  75. package/packages/shared-skills/skills/ulw-plan/scripts/plan-templates.mjs +1 -1
  76. package/packages/shared-skills/skills/ulw-research/references/research-collection.md +1 -1
package/dist/cli/index.js CHANGED
@@ -2132,7 +2132,7 @@ var package_default;
2132
2132
  var init_package = __esm(() => {
2133
2133
  package_default = {
2134
2134
  name: "oh-my-opencode",
2135
- version: "5.1.71",
2135
+ version: "5.1.73",
2136
2136
  description: "The Best AI Agent Harness - Batteries-Included OpenCode Plugin with Multi-Model Orchestration, Parallel Background Agents, and Crafted LSP/AST Tools",
2137
2137
  main: "./dist/index.js",
2138
2138
  types: "dist/index.d.ts",
@@ -2330,7 +2330,7 @@ var init_package = __esm(() => {
2330
2330
  },
2331
2331
  devDependencies: {
2332
2332
  "@clack/prompts": "^1.8.1",
2333
- "@code-yeongyu/senpi": "2026.11.15",
2333
+ "@code-yeongyu/senpi": "2026.11.15-2",
2334
2334
  "@modelcontextprotocol/sdk": "^1.30.0",
2335
2335
  "@oh-my-opencode/agents-md-core": "workspace:*",
2336
2336
  "@oh-my-opencode/ast-grep-mcp": "workspace:*",
@@ -2403,18 +2403,18 @@ var init_package = __esm(() => {
2403
2403
  typescript: "^7.0.2"
2404
2404
  },
2405
2405
  optionalDependencies: {
2406
- "oh-my-opencode-darwin-arm64": "5.1.71",
2407
- "oh-my-opencode-darwin-x64": "5.1.71",
2408
- "oh-my-opencode-darwin-x64-baseline": "5.1.71",
2409
- "oh-my-opencode-linux-arm64": "5.1.71",
2410
- "oh-my-opencode-linux-arm64-musl": "5.1.71",
2411
- "oh-my-opencode-linux-x64": "5.1.71",
2412
- "oh-my-opencode-linux-x64-baseline": "5.1.71",
2413
- "oh-my-opencode-linux-x64-musl": "5.1.71",
2414
- "oh-my-opencode-linux-x64-musl-baseline": "5.1.71",
2415
- "oh-my-opencode-windows-arm64": "5.1.71",
2416
- "oh-my-opencode-windows-x64": "5.1.71",
2417
- "oh-my-opencode-windows-x64-baseline": "5.1.71"
2406
+ "oh-my-opencode-darwin-arm64": "5.1.73",
2407
+ "oh-my-opencode-darwin-x64": "5.1.73",
2408
+ "oh-my-opencode-darwin-x64-baseline": "5.1.73",
2409
+ "oh-my-opencode-linux-arm64": "5.1.73",
2410
+ "oh-my-opencode-linux-arm64-musl": "5.1.73",
2411
+ "oh-my-opencode-linux-x64": "5.1.73",
2412
+ "oh-my-opencode-linux-x64-baseline": "5.1.73",
2413
+ "oh-my-opencode-linux-x64-musl": "5.1.73",
2414
+ "oh-my-opencode-linux-x64-musl-baseline": "5.1.73",
2415
+ "oh-my-opencode-windows-arm64": "5.1.73",
2416
+ "oh-my-opencode-windows-x64": "5.1.73",
2417
+ "oh-my-opencode-windows-x64-baseline": "5.1.73"
2418
2418
  },
2419
2419
  overrides: {
2420
2420
  hono: "^4.13.8",
@@ -92877,7 +92877,7 @@ var package_default2;
92877
92877
  var init_package2 = __esm(() => {
92878
92878
  package_default2 = {
92879
92879
  name: "@oh-my-opencode/omo-codex",
92880
- version: "5.1.71",
92880
+ version: "5.1.73",
92881
92881
  type: "module",
92882
92882
  private: true,
92883
92883
  description: "Codex harness adapter for oh-my-openagent. Vendored Codex plugin namespace (omo) + TypeScript installer + telemetry.",
@@ -100268,6 +100268,7 @@ var REQUIRED_PLUGIN_ARTIFACTS = [
100268
100268
  join66("extensions", "loro_wasm_bg.wasm"),
100269
100269
  join66("extensions", "CaseFolding.txt"),
100270
100270
  join66("extensions", "omo-thread-client.js"),
100271
+ join66("extensions", "omo-wake.js"),
100271
100272
  join66("extensions", "omo-telemetry-recovery.js"),
100272
100273
  join66("extensions", "omo-feedback.js"),
100273
100274
  join66("extensions", "omo-desktop-toolkit.js"),
@@ -109664,8 +109665,8 @@ var package_default3 = {
109664
109665
  },
109665
109666
  dependencies: {
109666
109667
  "@clack/prompts": "^1.8.1",
109667
- "@code-yeongyu/senpi": "2026.11.15",
109668
- "@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.11.15",
109668
+ "@code-yeongyu/senpi": "2026.11.15-2",
109669
+ "@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.11.15-2",
109669
109670
  "@modelcontextprotocol/sdk": "^1.30.0",
109670
109671
  "@oh-my-opencode/agents-md-core": "workspace:*",
109671
109672
  "@oh-my-opencode/boulder-state": "workspace:*",
@@ -116002,20 +116003,25 @@ var CLOSED_WHOAMI_HELP = `Show the current OmO device sign-in.
116002
116003
  omo whoami [--api <url>]
116003
116004
 
116004
116005
  This runs while OmO accounts are closed.`;
116006
+ var CLOSED_AUTH_HELP = { login: CLOSED_LOGIN_HELP, logout: CLOSED_LOGOUT_HELP, whoami: CLOSED_WHOAMI_HELP };
116005
116007
  function refuseClosedServiceAuth() {
116006
116008
  console.error(CLOSED_LOGIN_MESSAGE);
116007
116009
  process.exit(1);
116008
116010
  }
116009
116011
  function describeClosedAuthCommand(name) {
116010
116012
  return () => {
116011
- console.log(name === "login" ? CLOSED_LOGIN_HELP : name === "logout" ? CLOSED_LOGOUT_HELP : CLOSED_WHOAMI_HELP);
116013
+ console.log(CLOSED_AUTH_HELP[name]);
116012
116014
  process.exit(0);
116013
116015
  };
116014
116016
  }
116015
116017
  function configureClosedServiceAuthCommands(program, hooks) {
116016
116018
  configureClosedDeviceLogin(program, hooks);
116017
116019
  for (const name of ["logout", "whoami"]) {
116018
- const command = program.command(name, { hidden: true }).helpOption(false).allowUnknownOption().allowExcessArguments().option("--api <url>").action((options) => {
116020
+ const command = program.command(name, { hidden: true }).helpOption(false).allowUnknownOption().allowExcessArguments().option("--api <url>").option("--help").action((options) => {
116021
+ if (options.help === true) {
116022
+ console.log(CLOSED_AUTH_HELP[name]);
116023
+ return;
116024
+ }
116019
116025
  if (command.args.length !== 0)
116020
116026
  refuseClosedServiceAuth();
116021
116027
  return run3(name, options, hooks);
@@ -116050,12 +116056,19 @@ function configureServiceAuthCommands(program, open = serviceAccountsOpen(), hoo
116050
116056
  import { existsSync as existsSync68 } from "fs";
116051
116057
 
116052
116058
  // packages/device-service-core/src/device-service.ts
116053
- import { homedir as homedir36 } from "os";
116054
- import { join as join120 } from "path";
116059
+ import { join as join122 } from "path";
116055
116060
 
116056
116061
  // packages/device-service-core/src/local-api/access.ts
116057
- import { createHmac as createHmac2, randomBytes as randomBytes7, timingSafeEqual as timingSafeEqual2 } from "crypto";
116058
- import { chmodSync as chmodSync8, closeSync as closeSync5, lstatSync as lstatSync6, openSync as openSync5, readFileSync as readFileSync46, renameSync as renameSync10, rmSync as rmSync10, writeFileSync as writeFileSync18 } from "fs";
116062
+ import {
116063
+ chmodSync as chmodSync8,
116064
+ closeSync as closeSync5,
116065
+ lstatSync as lstatSync6,
116066
+ openSync as openSync5,
116067
+ readFileSync as readFileSync46,
116068
+ renameSync as renameSync10,
116069
+ rmSync as rmSync10,
116070
+ writeFileSync as writeFileSync18
116071
+ } from "fs";
116059
116072
  import { join as join118 } from "path";
116060
116073
 
116061
116074
  // packages/device-service-core/src/local-api/errors.ts
@@ -116066,7 +116079,9 @@ class LocalApiError extends Error {
116066
116079
  limit_chars;
116067
116080
  path_refusal;
116068
116081
  command_id;
116069
- not_sent;
116082
+ candidates;
116083
+ incomplete;
116084
+ sign_in_reason;
116070
116085
  constructor(code, reason, extra = {}) {
116071
116086
  super(`${code}: ${reason}`);
116072
116087
  this.name = "LocalApiError";
@@ -116079,40 +116094,112 @@ class LocalApiError extends Error {
116079
116094
  this.path_refusal = extra.path_refusal;
116080
116095
  if (extra.command_id !== undefined)
116081
116096
  this.command_id = extra.command_id;
116082
- if (extra.not_sent === true)
116083
- this.not_sent = true;
116097
+ if (extra.candidates !== undefined)
116098
+ this.candidates = extra.candidates;
116099
+ if (extra.incomplete !== undefined)
116100
+ this.incomplete = extra.incomplete;
116101
+ if (extra.sign_in_reason !== undefined)
116102
+ this.sign_in_reason = extra.sign_in_reason;
116084
116103
  }
116085
116104
  }
116086
116105
  var protocolViolation = (detail) => {
116087
116106
  throw new LocalApiError("protocol_violation", detail);
116088
116107
  };
116089
116108
 
116109
+ // packages/device-service-core/src/local-api/proof.ts
116110
+ import { createHmac as createHmac2, randomBytes as randomBytes7, timingSafeEqual as timingSafeEqual2 } from "crypto";
116111
+
116112
+ // packages/device-service-core/src/local-api/bytes-encoding.ts
116113
+ var ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
116114
+ var portable = {
116115
+ hex: (bytes) => Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join(""),
116116
+ base64: (bytes) => {
116117
+ let out = "";
116118
+ for (let i = 0;i < bytes.length; i += 3) {
116119
+ const [a = 0, b = 0, c = 0] = [bytes[i], bytes[i + 1], bytes[i + 2]];
116120
+ const n = a << 16 | b << 8 | c;
116121
+ out += ALPHABET.charAt(n >> 18 & 63) + ALPHABET.charAt(n >> 12 & 63);
116122
+ out += i + 1 < bytes.length ? ALPHABET.charAt(n >> 6 & 63) : "=";
116123
+ out += i + 2 < bytes.length ? ALPHABET.charAt(n & 63) : "=";
116124
+ }
116125
+ return out;
116126
+ },
116127
+ fromBase64url: (text) => {
116128
+ if (!/^[A-Za-z0-9_-]*={0,2}$/.test(text))
116129
+ throw new SyntaxError("invalid base64url");
116130
+ const clean = text.replaceAll("-", "+").replaceAll("_", "/").replace(/=+$/, "");
116131
+ if (clean.length % 4 === 1)
116132
+ throw new SyntaxError("invalid base64url");
116133
+ const out = new Uint8Array(Math.floor(clean.length * 3 / 4));
116134
+ let bits = 0;
116135
+ let value = 0;
116136
+ let at = 0;
116137
+ for (const ch of clean) {
116138
+ value = value << 6 | ALPHABET.indexOf(ch);
116139
+ bits += 6;
116140
+ if (bits >= 8) {
116141
+ bits -= 8;
116142
+ out[at++] = value >> bits & 255;
116143
+ }
116144
+ }
116145
+ return out;
116146
+ }
116147
+ };
116148
+ var native = (bytes) => bytes;
116149
+ var from = Uint8Array;
116150
+ var toHex = (bytes) => native(bytes).toHex?.() ?? portable.hex(bytes);
116151
+ var toBase64 = (bytes) => native(bytes).toBase64?.() ?? portable.base64(bytes);
116152
+ var toBase64url = (bytes) => native(bytes).toBase64?.({ alphabet: "base64url", omitPadding: true }) ?? portable.base64(bytes).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
116153
+ var fromBase64url = (text) => from.fromBase64?.(text, { alphabet: "base64url" }) ?? portable.fromBase64url(text);
116154
+ var fromBase64 = (text) => {
116155
+ if (!/^[A-Za-z0-9+/]*={0,2}$/.test(text))
116156
+ throw new SyntaxError("invalid base64");
116157
+ return from.fromBase64?.(text) ?? portable.fromBase64url(text.replaceAll("+", "-").replaceAll("/", "_"));
116158
+ };
116159
+
116160
+ // packages/device-service-core/src/local-api/proof.ts
116161
+ var NONCE_BYTES = 32;
116162
+ var mintNonce = () => toBase64url(randomBytes7(NONCE_BYTES));
116163
+ var mintId = () => toBase64url(randomBytes7(16));
116164
+ var decodedBytes = (value, bytes, what) => {
116165
+ const violation = () => new LocalApiError("protocol_violation", `${what} is not ${bytes} base64url bytes`);
116166
+ let out;
116167
+ try {
116168
+ out = fromBase64url(value);
116169
+ } catch (error) {
116170
+ if (error instanceof Error)
116171
+ throw violation();
116172
+ throw error;
116173
+ }
116174
+ if (out.length !== bytes || toBase64url(out) !== value)
116175
+ throw violation();
116176
+ return out;
116177
+ };
116178
+ var proof = (token, label, nonce, endpoint) => toBase64url(createHmac2("sha256", token).update(label).update(decodedBytes(nonce, NONCE_BYTES, "a nonce")).update(endpoint).digest());
116179
+ var serverProof = (token, clientNonce, endpoint) => proof(token, "server", clientNonce, endpoint);
116180
+ var clientProof = (token, serverNonce, endpoint) => proof(token, "client", serverNonce, endpoint);
116181
+ var proofMatches = (expected, actual) => {
116182
+ const a = new TextEncoder().encode(expected);
116183
+ const b = new TextEncoder().encode(actual);
116184
+ return a.length === b.length && timingSafeEqual2(a, b);
116185
+ };
116186
+
116090
116187
  // packages/device-service-core/src/local-api/dacl.ts
116091
116188
  import { spawn as spawn6 } from "child_process";
116092
116189
  var runPowerShell = async (script, env) => {
116093
116190
  const encoded = Buffer.from(script, "utf16le").toString("base64");
116094
116191
  const proc = spawn6("powershell.exe", ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-EncodedCommand", encoded], { env: { ...process.env, ...env }, stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
116095
116192
  const chunks = [];
116096
- const errChunks = [];
116097
116193
  proc.stdout.on("data", (chunk) => chunks.push(chunk));
116098
- proc.stderr.on("data", (chunk) => errChunks.push(chunk));
116194
+ proc.stderr.resume();
116099
116195
  const code = await new Promise((resolve, reject) => {
116100
116196
  proc.once("error", reject);
116101
116197
  proc.once("close", (exitCode) => resolve(exitCode ?? -1));
116102
116198
  });
116103
- return {
116104
- code,
116105
- out: Buffer.concat(chunks).toString("utf8"),
116106
- err: Buffer.concat(errChunks).toString("utf8")
116107
- };
116199
+ return { code, out: new TextDecoder().decode(Buffer.concat(chunks)) };
116108
116200
  };
116109
- var firstErrorLine = (err) => {
116110
- const line = (err ?? "").split(/\r?\n/).find((text) => text.trim() !== "" && !text.startsWith("#< CLIXML"))?.trim() ?? "";
116111
- return line === "" ? "" : `: ${line.slice(0, 300)}`;
116112
- };
116113
- var APPLY = String.raw`
116201
+ var APPLY_DACL_SCRIPT = String.raw`
116114
116202
  $ErrorActionPreference = 'Stop'
116115
- trap { [Console]::Error.WriteLine($_.Exception.Message); exit 1 }
116116
116203
  $sid = New-Object System.Security.Principal.SecurityIdentifier($env:LA_SID)
116117
116204
  if ($env:LA_KIND -eq 'dir') {
116118
116205
  $acl = New-Object System.Security.AccessControl.DirectorySecurity
@@ -116127,11 +116214,7 @@ $rule = New-Object System.Security.AccessControl.FileSystemAccessRule($sid,
116127
116214
  $acl.SetAccessRuleProtection($true, $false)
116128
116215
  $acl.SetOwner($sid)
116129
116216
  $acl.AddAccessRule($rule)
116130
- if ($env:LA_KIND -eq 'dir') {
116131
- [System.IO.Directory]::SetAccessControl($env:LA_PATH, $acl)
116132
- } else {
116133
- [System.IO.File]::SetAccessControl($env:LA_PATH, $acl)
116134
- }
116217
+ Set-Acl -LiteralPath $env:LA_PATH -AclObject $acl
116135
116218
  Write-Output 'applied'
116136
116219
  `;
116137
116220
  var DESCRIBE_DACL_SCRIPT = String.raw`
@@ -116164,10 +116247,6 @@ public static class LaSddl {
116164
116247
  '@
116165
116248
  [LaSddl]::Read($env:LA_PATH)
116166
116249
  `;
116167
- var SID_TOKEN_SCRIPT = String.raw`
116168
- $ErrorActionPreference = 'Stop'
116169
- (New-Object System.Security.AccessControl.RawSecurityDescriptor("O:$env:LA_SID")).GetSddlForm('Owner')
116170
- `;
116171
116250
  var CURRENT_USER_SID_SCRIPT = "[System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value";
116172
116251
  var ACE_TYPES = new Set([
116173
116252
  "A",
@@ -116253,10 +116332,9 @@ var parseSddl = (sddl) => {
116253
116332
  }
116254
116333
  return { sddl, owner, protected: tokens.includes("P"), flags: tokens.join(""), aces };
116255
116334
  };
116256
- var exactDaclVerdict = (dacl, userSid, kind, userAlias) => {
116257
- const isUser = (token) => token === userSid || userAlias !== undefined && token === userAlias;
116335
+ var exactDaclVerdict = (dacl, userSid, kind) => {
116258
116336
  const [ace, ...others] = dacl.aces;
116259
- return isUser(dacl.owner) && dacl.flags === "PAI" && ace !== undefined && others.length === 0 && ace.type === "A" && ace.flags === (kind === "dir" ? "OICI" : "") && ace.rights === "FA" && ace.objectGuid === "" && ace.inheritObjectGuid === "" && isUser(ace.sid) && ace.extra === undefined;
116337
+ return dacl.owner === userSid && dacl.flags === "PAI" && ace !== undefined && others.length === 0 && ace.type === "A" && ace.flags === (kind === "dir" ? "OICI" : "") && ace.rights === "FA" && ace.objectGuid === "" && ace.inheritObjectGuid === "" && ace.sid === userSid && ace.extra === undefined;
116260
116338
  };
116261
116339
  var currentUserSid = async (run = runPowerShell) => {
116262
116340
  const { code, out } = await run(CURRENT_USER_SID_SCRIPT, {});
@@ -116265,16 +116343,6 @@ var currentUserSid = async (run = runPowerShell) => {
116265
116343
  throw new LocalApiError("insecure_state_dir", "the user SID is unreadable");
116266
116344
  return sid;
116267
116345
  };
116268
- var userSidToken = async (userSid, run = runPowerShell) => {
116269
- const { code, out } = await run(SID_TOKEN_SCRIPT, { LA_SID: userSid });
116270
- const match = code === 0 ? /^O:(S-1-\d+(?:-\d+)+|[A-Z]{2})$/.exec(out.trim()) : null;
116271
- return match?.[1];
116272
- };
116273
- var applyExactDacl = async (path, userSid, kind, run = runPowerShell) => {
116274
- const { code, err } = await run(APPLY, { LA_PATH: path, LA_SID: userSid, LA_KIND: kind });
116275
- if (code !== 0)
116276
- throw new LocalApiError("insecure_state_dir", `the exact DACL could not be applied${firstErrorLine(err)}`);
116277
- };
116278
116346
  var describeDacl = async (path, run = runPowerShell) => {
116279
116347
  const { code, out } = await run(DESCRIBE_DACL_SCRIPT, { LA_PATH: path });
116280
116348
  const dacl = code === 0 ? parseSddl(out.trim()) : undefined;
@@ -116282,51 +116350,16 @@ var describeDacl = async (path, run = runPowerShell) => {
116282
116350
  throw new LocalApiError("insecure_state_dir", "the DACL could not be read back");
116283
116351
  return dacl;
116284
116352
  };
116285
- var verifyExactDacl = async (path, userSid, kind, run = runPowerShell) => {
116286
- let dacl;
116287
- try {
116288
- dacl = await describeDacl(path, run);
116289
- } catch (error) {
116290
- if (error instanceof LocalApiError)
116291
- return false;
116292
- throw error;
116293
- }
116294
- return exactDaclVerdict(dacl, userSid, kind, await userSidToken(userSid, run));
116295
- };
116296
- var windowsSecureFile = (userSid, run = runPowerShell) => async (path, kind) => {
116297
- const target = kind === "dir" ? "dir" : "file";
116298
- await applyExactDacl(path, userSid, target, run);
116299
- if (!await verifyExactDacl(path, userSid, target, run))
116300
- throw new LocalApiError("insecure_state_dir", "the DACL is not exactly one ACE for the user");
116301
- };
116302
116353
 
116303
116354
  // packages/device-service-core/src/local-api/access.ts
116304
116355
  var TOKEN_FILE = "token";
116305
116356
  var TOKEN_BYTES = 32;
116306
- var NONCE_BYTES = 32;
116307
116357
  var SOCKET_FILE = "service.sock";
116308
- var base64url2 = (bytes) => Buffer.from(bytes).toString("base64url");
116309
- var mintNonce = () => base64url2(randomBytes7(NONCE_BYTES));
116310
- var mintId = () => base64url2(randomBytes7(16));
116311
116358
  var insecure = (detail) => {
116312
116359
  throw new LocalApiError("insecure_state_dir", detail);
116313
116360
  };
116314
- var decoded = (value, bytes, what) => {
116315
- const out = Buffer.from(value, "base64url");
116316
- if (out.length !== bytes || base64url2(out) !== value)
116317
- throw new LocalApiError("protocol_violation", `${what} is not ${bytes} base64url bytes`);
116318
- return out;
116319
- };
116320
116361
  var UNIX_ENDPOINT = "unix";
116321
116362
  var tcpEndpoint = (port) => `tcp:${port}`;
116322
- var proof = (token, label, nonce, endpoint) => base64url2(createHmac2("sha256", token).update(label).update(decoded(nonce, NONCE_BYTES, "a nonce")).update(endpoint, "utf8").digest());
116323
- var serverProof = (token, clientNonce, endpoint) => proof(token, "server", clientNonce, endpoint);
116324
- var clientProof = (token, serverNonce, endpoint) => proof(token, "client", serverNonce, endpoint);
116325
- var proofMatches = (expected, actual) => {
116326
- const a = Buffer.from(expected);
116327
- const b = Buffer.from(actual);
116328
- return a.length === b.length && timingSafeEqual2(a, b);
116329
- };
116330
116363
  var isMissing = (error) => typeof error === "object" && error !== null && ("code" in error) && (error.code === "ENOENT" || error.code === "ENOTDIR");
116331
116364
  var currentUid = () => process.getuid?.() ?? insecure("this platform has no uid");
116332
116365
  var privateEntry = (path, kind, uid, checkMode = true) => {
@@ -116368,7 +116401,7 @@ var readToken = (stateDir) => {
116368
116401
  throw error;
116369
116402
  }
116370
116403
  try {
116371
- return decoded(value, TOKEN_BYTES, "the token");
116404
+ return decodedBytes(value, TOKEN_BYTES, "the token");
116372
116405
  } catch (error) {
116373
116406
  if (error instanceof LocalApiError)
116374
116407
  return insecure("the token is malformed");
@@ -116380,31 +116413,45 @@ var readToken = (stateDir) => {
116380
116413
  import { createHash as createHash16 } from "crypto";
116381
116414
 
116382
116415
  // packages/device-service-core/src/local-api/spec-proto.ts
116416
+ class ProtoError extends Error {
116417
+ code;
116418
+ constructor(code, detail) {
116419
+ super(`${code}: ${detail}`);
116420
+ this.code = code;
116421
+ this.name = "ProtoError";
116422
+ }
116423
+ }
116383
116424
  var SESSION_BLOB_MAX = 16777216;
116384
- var SESSION_COMMAND_TEXT_MAX_CHARS = 1e6;
116385
- var SESSION_COMMAND_TEXT_MAX_BYTES = 3000000;
116425
+ var SESSION_KIND_MAX_CHARS = 32;
116426
+ var SESSION_ID_MAX_CHARS = 128;
116386
116427
  var SESSION_DEVICE_MAX_CHARS = 64;
116387
116428
  var SESSION_PROJECT_MAX_CHARS = 256;
116388
- var SESSION_ID_MAX_CHARS = 128;
116389
- var SESSION_KIND_MAX_CHARS = 32;
116390
116429
  var SESSION_READ_TAIL_MAX = 200;
116391
116430
  var SESSION_SUMMARY_TITLE_MAX_CHARS = 256;
116392
116431
  var SESSION_SUMMARY_PROJECT_MAX_CHARS = 128;
116393
116432
  var SESSION_SUMMARY_PATH_MAX_CHARS = 1024;
116394
-
116395
- class ProtoError extends Error {
116396
- code;
116397
- constructor(code, message) {
116398
- super(message);
116399
- this.code = code;
116400
- }
116401
- }
116402
- var validateCommandText = (text) => {
116403
- if (typeof text !== "string" || !text.isWellFormed())
116404
- throw new ProtoError("malformed", "command text");
116405
- if (text.length > SESSION_COMMAND_TEXT_MAX_CHARS || new TextEncoder().encode(text).length > SESSION_COMMAND_TEXT_MAX_BYTES)
116406
- throw new ProtoError("payload_too_large", "session command text over the limit");
116407
- return text;
116433
+ var SESSION_MODEL_PROVIDER_MAX_CHARS = 64;
116434
+ var SESSION_MODEL_ID_MAX_CHARS = 128;
116435
+ var SESSION_SETTLED_DAYS_MAX = 36500;
116436
+ var SESSION_SETTLED_THREAD_TITLE_MAX_CHARS = 256;
116437
+ var SESSION_KEY_CHARS = 22;
116438
+ var UNSAFE_KEYS2 = ["__proto__", "constructor", "prototype"];
116439
+ var sessionFail = (detail) => {
116440
+ throw new ProtoError("bad_request", `session payload ${detail}`);
116441
+ };
116442
+ var B64URL = /^[A-Za-z0-9_-]+$/;
116443
+ var base64UrlId = (v, n, detail) => typeof v === "string" && v.length === n && B64URL.test(v) ? v : sessionFail(detail);
116444
+ var sessionKeyOf = (v) => base64UrlId(v, SESSION_KEY_CHARS, "session key");
116445
+ var safeKey = (key, detail) => UNSAFE_KEYS2.includes(key) ? sessionFail(detail) : key;
116446
+ var STREAM_INLINE_MAX = 12000;
116447
+ var validateStreamSessionKey = (v) => sessionKeyOf(v);
116448
+ var validRosterDeviceId = (value) => typeof value === "string" && value.length > 0 && value.length <= 64 && value.isWellFormed();
116449
+ var METHOD = /^(?=.{1,64}$)[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)*$/;
116450
+ var methodOf = (v, what) => {
116451
+ const type = typeof v === "string" && METHOD.test(v) ? v : sessionFail(what);
116452
+ for (const segment of type.split("."))
116453
+ safeKey(segment, what);
116454
+ return type;
116408
116455
  };
116409
116456
 
116410
116457
  // packages/device-service-core/src/local-api/limits.ts
@@ -116412,6 +116459,10 @@ var LOCAL_INLINE_MAX = 524288;
116412
116459
  var LOCAL_CHUNK_MAX = 262144;
116413
116460
  var LOCAL_JSON_EXPANSION_MAX = 6;
116414
116461
  var LOCAL_BLOB_MAX = LOCAL_JSON_EXPANSION_MAX * SESSION_BLOB_MAX;
116462
+ var MACHINE_UPLOAD_MAX_BYTES = 3840000;
116463
+ var MACHINE_UPLOAD_PARTS_MAX = Math.ceil(MACHINE_UPLOAD_MAX_BYTES / LOCAL_CHUNK_MAX);
116464
+ var grouped = (n) => n.toLocaleString("en-US");
116465
+ var MACHINE_UPLOAD_LIMIT = `an uploaded batch is at most ${grouped(MACHINE_UPLOAD_MAX_BYTES)} bytes (${MACHINE_UPLOAD_PARTS_MAX} parts of ${grouped(LOCAL_CHUNK_MAX)} bytes)`;
116415
116466
  var encoder2 = new TextEncoder;
116416
116467
  var lineBytes = (value) => encoder2.encode(JSON.stringify(value)).length + 1;
116417
116468
  var sha256Hex = (data) => createHash16("sha256").update(data).digest("hex");
@@ -116420,7 +116471,7 @@ var chunkPayload = (data) => {
116420
116471
  for (let off = 0;off < data.length; off += LOCAL_CHUNK_MAX)
116421
116472
  chunks.push({
116422
116473
  off,
116423
- b: Buffer.from(data.subarray(off, off + LOCAL_CHUNK_MAX)).toString("base64")
116474
+ b: toBase64(data.subarray(off, off + LOCAL_CHUNK_MAX))
116424
116475
  });
116425
116476
  return chunks;
116426
116477
  };
@@ -116443,8 +116494,10 @@ var STATUS_STATES = [
116443
116494
  "authorization_stale",
116444
116495
  "service_degraded",
116445
116496
  "update_required",
116446
- "signed_out"
116497
+ "signed_out",
116498
+ "fail_closed"
116447
116499
  ];
116500
+ var STATUS_UPDATE_PHASES = ["trial", "committed"];
116448
116501
  var POLICY_STATES = ["off", "pending", "active"];
116449
116502
  var THIS_DEVICE_STATES = [
116450
116503
  "unclassified",
@@ -116470,9 +116523,26 @@ var ROUND_DEVICE_STATES = [
116470
116523
  var LISTING_SOURCES = ["live", "cache"];
116471
116524
  var SESSION_ROW_STATES = ["running", "idle", "ended"];
116472
116525
  var FILTER_KEYS = ["device", "project", "state"];
116526
+ var LISTING_SETTLED_BY_KINDS = [
116527
+ "user",
116528
+ "agent",
116529
+ "pr-merged",
116530
+ "pr-closed",
116531
+ "inactivity"
116532
+ ];
116473
116533
  var BLOB_OF = ["state", "record", "entry"];
116474
- var BLOB_ABORT_REASONS = ["digest_mismatch", "source_gone", "too_large", "detached"];
116475
- var UPLOAD_ABORT_REASONS = ["message_too_long", "parts_conflict", "malformed", "detached"];
116534
+ var BLOB_ABORT_REASONS = [
116535
+ "digest_mismatch",
116536
+ "source_gone",
116537
+ "too_large",
116538
+ "detached"
116539
+ ];
116540
+ var UPLOAD_ABORT_REASONS = [
116541
+ "message_too_long",
116542
+ "parts_conflict",
116543
+ "malformed",
116544
+ "detached"
116545
+ ];
116476
116546
  var DETACH_REASONS = [
116477
116547
  "authorization_expired",
116478
116548
  "activation_pending",
@@ -116485,6 +116555,14 @@ var DETACH_REASONS = [
116485
116555
  "session_closed",
116486
116556
  "session_replaced"
116487
116557
  ];
116558
+ var UPDATE_NOTICE_PHASES = [
116559
+ "draining",
116560
+ "final",
116561
+ "updated",
116562
+ "rolled_back",
116563
+ "failed"
116564
+ ];
116565
+ var UPDATE_POLICIES = ["defer", "force", "ask"];
116488
116566
  var ATTACH_PENDING_REASONS = ["stream_key_pending"];
116489
116567
  var COMMAND_ID_CHARS = 22;
116490
116568
  var COMMAND_STATES = [
@@ -116509,7 +116587,8 @@ var COMMAND_UNCERTAIN_REASONS = [
116509
116587
  "cancelled",
116510
116588
  "hand_restarted",
116511
116589
  "result_expired",
116512
- "record_too_large"
116590
+ "record_too_large",
116591
+ "result_undecodable"
116513
116592
  ];
116514
116593
  var COMMAND_REFUSAL_REASONS = [
116515
116594
  "parts_conflict",
@@ -116527,9 +116606,15 @@ var COMMAND_REFUSAL_REASONS = [
116527
116606
  "scope_unknown",
116528
116607
  "scope_closed",
116529
116608
  "epoch_fenced",
116530
- "epoch_step_exceeded"
116609
+ "epoch_step_exceeded",
116610
+ "route_unlisted",
116611
+ "rate_limited",
116612
+ "unknown_reason"
116613
+ ];
116614
+ var RETRYABLE_STATES = [
116615
+ "not confirmed",
116616
+ "not delivered: never_sent"
116531
116617
  ];
116532
- var RETRYABLE_STATES = ["not confirmed", "not delivered: never_sent"];
116533
116618
  var ERROR_CODES = [
116534
116619
  "unauthenticated",
116535
116620
  "client_proof_invalid",
@@ -116551,6 +116636,7 @@ var ERROR_CODES = [
116551
116636
  "peer_not_found",
116552
116637
  "peer_not_session_client",
116553
116638
  "session_not_found",
116639
+ "session_ambiguous",
116554
116640
  "engine_too_old",
116555
116641
  "not_attached",
116556
116642
  "command_id_conflict",
@@ -116560,7 +116646,15 @@ var ERROR_CODES = [
116560
116646
  "method_unclassified",
116561
116647
  "method_local_only",
116562
116648
  "host_not_answering",
116563
- "unsupported"
116649
+ "unsupported",
116650
+ "unknown_delivery"
116651
+ ];
116652
+ var ALIAS_INCOMPLETE_REASONS = [
116653
+ "cache",
116654
+ "timed_out",
116655
+ "undelivered",
116656
+ "skipped",
116657
+ "stopped"
116564
116658
  ];
116565
116659
  var PATH_REFUSAL_PROBLEMS = [
116566
116660
  "not_absolute",
@@ -116572,6 +116666,16 @@ var PATH_REFUSAL_PROBLEMS = [
116572
116666
  "world_writable",
116573
116667
  "windows_acl"
116574
116668
  ];
116669
+ var MACHINE_OP_STATES = [
116670
+ "queued",
116671
+ "transport_confirmed",
116672
+ "host_dispatched",
116673
+ "host_applied",
116674
+ "link_down"
116675
+ ];
116676
+ var MACHINE_STATES = ["online", "offline", "unsupported"];
116677
+ var MACHINE_LOOKUP_STATES = ["in_flight", "terminal", "unknown"];
116678
+ var MACHINE_BLOB_ABORT_REASONS = ["digest_mismatch", "source_gone", "too_large"];
116575
116679
  var CHANNEL_CLOSED_REASONS = [
116576
116680
  "event_overflow",
116577
116681
  "event_too_large",
@@ -116651,11 +116755,18 @@ var sha256Field = (v, what) => typeof v === "string" && SHA256_HEX.test(v) ? v :
116651
116755
  var base64Bytes = (v, max, what) => {
116652
116756
  if (typeof v !== "string" || v.length === 0 || v.length > 4 * Math.ceil(max / 3))
116653
116757
  return fail(what);
116654
- const bytes = Buffer.from(v, "base64");
116655
- return bytes.length <= max && bytes.toString("base64") === v ? new Uint8Array(bytes) : fail(what);
116758
+ let bytes;
116759
+ try {
116760
+ bytes = fromBase64(v);
116761
+ } catch (error) {
116762
+ if (error instanceof Error)
116763
+ return fail(what);
116764
+ throw error;
116765
+ }
116766
+ return bytes.length <= max && toBase64(bytes) === v ? bytes : fail(what);
116656
116767
  };
116657
- var UNSAFE_KEYS2 = ["__proto__", "constructor", "prototype"];
116658
- var safeKey = (key, what) => UNSAFE_KEYS2.includes(key) ? fail(what) : key;
116768
+ var UNSAFE_KEYS3 = ["__proto__", "constructor", "prototype"];
116769
+ var safeKey2 = (key, what) => UNSAFE_KEYS3.includes(key) ? fail(what) : key;
116659
116770
  var jsonValue = (v, what) => {
116660
116771
  if (v === null || typeof v === "boolean" || typeof v === "string")
116661
116772
  return v;
@@ -116675,9 +116786,20 @@ var jsonObject = (v, what) => {
116675
116786
  out[key] = jsonValue(item, what);
116676
116787
  return out;
116677
116788
  };
116789
+ // packages/device-service-core/src/local-api/command-text.ts
116790
+ var COMMAND_TEXT_MAX_CHARS = 1e6;
116791
+ var COMMAND_TEXT_MAX_BYTES = 3000000;
116792
+ var validateCommandText = (text) => {
116793
+ if (typeof text !== "string" || !text.isWellFormed())
116794
+ throw new ProtoError("bad_request", "session payload command text");
116795
+ if (text.length > COMMAND_TEXT_MAX_CHARS || new TextEncoder().encode(text).length > COMMAND_TEXT_MAX_BYTES)
116796
+ throw new ProtoError("payload_too_large", "session command text over the limit");
116797
+ return text;
116798
+ };
116799
+
116678
116800
  // packages/device-service-core/src/local-api/upload.ts
116679
- var MESSAGE_LIMIT_CHARS = SESSION_COMMAND_TEXT_MAX_CHARS;
116680
- var LOCAL_UPLOAD_PARTS_MAX = Math.ceil(SESSION_COMMAND_TEXT_MAX_BYTES / LOCAL_CHUNK_MAX);
116801
+ var MESSAGE_LIMIT_CHARS = COMMAND_TEXT_MAX_CHARS;
116802
+ var LOCAL_UPLOAD_PARTS_MAX = Math.ceil(COMMAND_TEXT_MAX_BYTES / LOCAL_CHUNK_MAX);
116681
116803
  var checkCommandText = (value) => {
116682
116804
  try {
116683
116805
  validateCommandText(value);
@@ -116711,7 +116833,7 @@ class LocalBlobAssembler {
116711
116833
  return;
116712
116834
  case "session.blob_chunk": {
116713
116835
  const open = this.#current(event.id);
116714
- const data = Buffer.from(event.b, "base64");
116836
+ const data = fromBase64(event.b);
116715
116837
  const end = this.#received + data.length;
116716
116838
  if (event.off !== this.#received || end > open.bytes)
116717
116839
  return protocolViolation("blob chunk out of order");
@@ -116818,12 +116940,114 @@ class ListingTracker {
116818
116940
  }
116819
116941
  }
116820
116942
 
116943
+ // packages/device-service-core/src/local-api/session-ref.ts
116944
+ var KEY_CHARS = 22;
116945
+ var MIN_CHARS = KEY_CHARS + 2;
116946
+ var MAX_CHARS = KEY_CHARS + 65;
116947
+ var isStreamSessionKey = (v) => {
116948
+ try {
116949
+ validateStreamSessionKey(v);
116950
+ return true;
116951
+ } catch (error) {
116952
+ if (error instanceof ProtoError)
116953
+ return false;
116954
+ throw error;
116955
+ }
116956
+ };
116957
+ var parseSessionRef = (v) => {
116958
+ if (typeof v !== "string" || !v.isWellFormed())
116959
+ return;
116960
+ if (v.length < MIN_CHARS || v.length > MAX_CHARS || v[v.length - KEY_CHARS - 1] !== ".")
116961
+ return;
116962
+ const device = v.slice(0, -KEY_CHARS - 1);
116963
+ const key = v.slice(-KEY_CHARS);
116964
+ return isStreamSessionKey(key) && validRosterDeviceId(device) ? { device, key } : undefined;
116965
+ };
116966
+ var formatSessionRef = (ref) => {
116967
+ if (!isStreamSessionKey(ref.key) || !validRosterDeviceId(ref.device))
116968
+ throw new RangeError("not a session id: the device or the key is malformed");
116969
+ return `${ref.device}.${ref.key}`;
116970
+ };
116971
+ var CONTROL = /[\u0000-\u001f\u007f-\u009f]/;
116972
+ var ALIAS_MAX_CHARS = 256;
116973
+ var unsafeAlias = (s) => s !== s.trim() || CONTROL.test(s) || parseSessionRef(s) !== undefined || isStreamSessionKey(s);
116974
+
116975
+ // packages/device-service-core/src/local-api/validate-snapshot-from.ts
116976
+ var SNAPSHOT_OPTIONAL_FIELDS = ["from"];
116977
+ var snapshotFromOf = (v) => {
116978
+ const m = known(v, ["last_entry_id", "delta"], [], "from");
116979
+ return {
116980
+ last_entry_id: entryId(m["last_entry_id"], "from.last_entry_id"),
116981
+ delta: bool(m["delta"], "from.delta")
116982
+ };
116983
+ };
116984
+
116985
+ // packages/device-service-core/src/local-api/protocol-status.ts
116986
+ var SIGN_IN_REASONS = ["not_adopted", "device_revoked", "reauth_required"];
116987
+
116988
+ // packages/device-service-core/src/local-api/validate-session-answer.ts
116989
+ var refOf = (v, what) => {
116990
+ const m = known(v, ["device", "key", "session"], [], what);
116991
+ const ref = parseSessionRef(m["session"]);
116992
+ if (ref === undefined || ref.device !== m["device"] || ref.key !== m["key"])
116993
+ return fail(what);
116994
+ return { device: ref.device, key: ref.key, session: formatSessionRef(ref) };
116995
+ };
116996
+ var commandAnswerOf = (v) => {
116997
+ const m = known(v, ["command_id"], ["device", "key", "session"], "session.command data");
116998
+ const command_id = commandId(m["command_id"]);
116999
+ if (m["device"] === undefined && m["key"] === undefined && m["session"] === undefined)
117000
+ return { command_id };
117001
+ const { device, key, session } = m;
117002
+ return { command_id, ...refOf({ device, key, session }, "session.command data") };
117003
+ };
117004
+ var listOf = (v, item, what) => Array.isArray(v) ? v.map(item) : fail(what);
117005
+ var incompleteOf = (v) => {
117006
+ const m = known(v, ["device", "reason"], [], "error.incomplete");
117007
+ const device = m["device"];
117008
+ if (typeof device !== "string" || device.length === 0)
117009
+ return fail("error.incomplete");
117010
+ return { device, reason: oneOf(ALIAS_INCOMPLETE_REASONS, m["reason"], "error.incomplete") };
117011
+ };
117012
+ var aliasErrorFields = (code, m) => {
117013
+ const { candidates, incomplete } = m;
117014
+ if (candidates !== undefined !== (code === "session_ambiguous"))
117015
+ return fail("error.candidates");
117016
+ if (incomplete !== undefined && code !== "session_not_found")
117017
+ return fail("error.incomplete");
117018
+ return {
117019
+ ...candidates === undefined ? {} : {
117020
+ candidates: listOf(candidates, (c) => refOf(c, "error.candidates"), "error.candidates")
117021
+ },
117022
+ ...incomplete === undefined ? {} : { incomplete: listOf(incomplete, incompleteOf, "error.incomplete") }
117023
+ };
117024
+ };
117025
+
117026
+ // packages/device-service-core/src/local-api/validate-update.ts
117027
+ var READY_REASON_MAX_CHARS = 64;
117028
+ var statusUpdateOf = (v) => {
117029
+ const m = known(v, ["update_id", "phase", "target_version", "ready", "ready_reason"], [], "status.update");
117030
+ return {
117031
+ update_id: localId(m["update_id"], "status.update.update_id"),
117032
+ phase: oneOf(STATUS_UPDATE_PHASES, m["phase"], "status.update.phase"),
117033
+ target_version: semver(m["target_version"], "status.update.target_version"),
117034
+ ready: bool(m["ready"], "status.update.ready"),
117035
+ ready_reason: nullable2(m["ready_reason"], (r) => text(r, READY_REASON_MAX_CHARS, "status.update.ready_reason"))
117036
+ };
117037
+ };
117038
+ var updateCommittedOf = (m, id) => ({
117039
+ id,
117040
+ type: "owner.update_committed",
117041
+ update_id: localId(m["update_id"], "update_id")
117042
+ });
117043
+
116821
117044
  // packages/device-service-core/src/local-api/validate-shapes.ts
116822
117045
  var CODE = /^[a-z_]{1,64}$/;
116823
117046
  var ATTACH_ID_MAX = 4294967295;
116824
117047
  var MILLIS_MAX = Number.MAX_SAFE_INTEGER;
116825
117048
  var deviceId = (v, what = "device") => text(v, SESSION_DEVICE_MAX_CHARS, what);
116826
117049
  var sessionId = (v) => text(v, SESSION_ID_MAX_CHARS, "session_id");
117050
+ var durableId = (v, what = "durable_id") => text(v, SESSION_ID_MAX_CHARS, what);
116827
117051
  var attachId = (v) => uint(v, 1, ATTACH_ID_MAX, "attach_id");
116828
117052
  var millis = (v, what) => uint(v, 0, MILLIS_MAX, what);
116829
117053
  var deviceRef = (v, what = "device", fields = exactly) => {
@@ -116853,9 +117077,8 @@ var policyOf = (v) => {
116853
117077
  };
116854
117078
  };
116855
117079
  var statusOf = (v) => {
116856
- const m = known(v, ["state", "since_ms", "device", "origin_configured", "enabled"], ["detail", "policy"], "status");
116857
- const detail = m["detail"];
116858
- const policy = m["policy"];
117080
+ const m = known(v, ["state", "since_ms", "device", "origin_configured", "enabled"], ["detail", "policy", "update", "exe"], "status");
117081
+ const { detail, policy, update, exe } = m;
116859
117082
  return {
116860
117083
  state: oneOf(STATUS_STATES, m["state"], "status.state"),
116861
117084
  since_ms: millis(m["since_ms"], "status.since_ms"),
@@ -116863,60 +117086,41 @@ var statusOf = (v) => {
116863
117086
  device: nullable2(m["device"], (d) => deviceRef(d, "status.device", known)),
116864
117087
  origin_configured: bool(m["origin_configured"], "status.origin_configured"),
116865
117088
  enabled: bool(m["enabled"], "status.enabled"),
116866
- ...policy === undefined ? {} : { policy: policyOf(policy) }
117089
+ ...policy === undefined ? {} : { policy: policyOf(policy) },
117090
+ ...update === undefined ? {} : { update: statusUpdateOf(update) },
117091
+ ...exe === undefined ? {} : { exe: absolutePath(exe, "status.exe") }
116867
117092
  };
116868
117093
  };
116869
117094
  var detailOf = (v) => {
116870
- const m = known(v, ["code", "action"], [], "status.detail");
116871
- const code = m["code"];
117095
+ const m = known(v, ["code", "action"], ["sign_in_reason"], "status.detail");
117096
+ const { code, sign_in_reason: reason } = m;
116872
117097
  return {
116873
117098
  code: typeof code === "string" && CODE.test(code) ? code : fail("status.detail.code"),
116874
- action: nullable2(m["action"], (a) => text(a, LABEL_MAX_CHARS, "status.detail.action"))
117099
+ action: nullable2(m["action"], (a) => text(a, LABEL_MAX_CHARS, "status.detail.action")),
117100
+ ...reason === undefined ? {} : { sign_in_reason: oneOf(SIGN_IN_REASONS, reason, "status.detail.sign_in_reason") }
116875
117101
  };
116876
117102
  };
116877
117103
  var deviceRowOf = (v) => {
116878
- const m = known(v, ["device", "label", "kind", "platform", "last_seen_ms", "online"], [], "device row");
117104
+ const m = known(v, ["device", "label", "kind", "platform", "last_seen_ms", "online"], ["managed"], "device row");
117105
+ const managed = m["managed"];
116879
117106
  return {
116880
117107
  device: deviceId(m["device"]),
116881
117108
  label: text(m["label"], LABEL_MAX_CHARS, "label", 0),
116882
117109
  kind: text(m["kind"], 64, "kind", 0),
116883
117110
  platform: text(m["platform"], 64, "platform", 0),
116884
117111
  last_seen_ms: nullable2(m["last_seen_ms"], (t) => millis(t, "last_seen_ms")),
116885
- online: bool(m["online"], "online")
116886
- };
116887
- };
116888
- var ROW_FIELDS = ["device", "session_id", "title", "project", "path", "state", "updated_ms", "source", "as_of"];
116889
- var ROW_KIND = new RegExp(`^[a-z][a-z0-9_-]{0,${SESSION_KIND_MAX_CHARS - 1}}$`);
116890
- var rowLinks = (m) => {
116891
- const kind = m["kind"];
116892
- if (Object.hasOwn(m, "parent") !== Object.hasOwn(m, "parent_listed"))
116893
- fail("parent_listed");
116894
- return {
116895
- ...kind === undefined ? {} : { kind: typeof kind === "string" && ROW_KIND.test(kind) ? kind : fail("row kind") },
116896
- ...m["parent"] === undefined ? {} : {
116897
- parent: sessionId(m["parent"]),
116898
- parent_listed: bool(m["parent_listed"], "parent_listed")
116899
- }
117112
+ online: bool(m["online"], "online"),
117113
+ ...managed === undefined ? {} : { managed: bool(managed, "managed") }
116900
117114
  };
116901
117115
  };
116902
- var listingRowOf = (v) => {
116903
- const m = known(v, ROW_FIELDS, ["kind", "parent", "parent_listed", "durable_id"], "listing row");
116904
- const durable = m["durable_id"];
116905
- return {
116906
- ...rowLinks(m),
116907
- ...durable === undefined ? {} : { durable_id: text(durable, SESSION_ID_MAX_CHARS, "durable_id") },
116908
- device: deviceId(m["device"]),
116909
- session_id: sessionId(m["session_id"]),
116910
- title: text(m["title"], SESSION_SUMMARY_TITLE_MAX_CHARS, "title", 0),
116911
- project: text(m["project"], SESSION_SUMMARY_PROJECT_MAX_CHARS, "project"),
116912
- path: text(m["path"], SESSION_SUMMARY_PATH_MAX_CHARS, "path"),
116913
- state: oneOf(SESSION_ROW_STATES, m["state"], "row state"),
116914
- updated_ms: millis(m["updated_ms"], "updated_ms"),
116915
- source: oneOf(LISTING_SOURCES, m["source"], "row source"),
116916
- as_of: millis(m["as_of"], "as_of")
116917
- };
116918
- };
116919
- var BODY_FIELDS = ["attach_id", "cursor", "state", "entries", "history_truncated", "oldest_entry_id"];
117116
+ var BODY_FIELDS = [
117117
+ "attach_id",
117118
+ "cursor",
117119
+ "state",
117120
+ "entries",
117121
+ "history_truncated",
117122
+ "oldest_entry_id"
117123
+ ];
116920
117124
  var snapshotBodyOf = (m) => {
116921
117125
  const cursor = known(m["cursor"], ["marker_id", "last_entry_id"], [], "cursor");
116922
117126
  const entries = m["entries"];
@@ -116931,10 +117135,11 @@ var snapshotBodyOf = (m) => {
116931
117135
  state: jsonObject(m["state"], "state"),
116932
117136
  entries: entries.map((e) => jsonValue(e, "entries")),
116933
117137
  history_truncated: bool(m["history_truncated"], "history_truncated"),
116934
- oldest_entry_id: nullable2(m["oldest_entry_id"], (e) => entryId(e, "oldest_entry_id"))
117138
+ oldest_entry_id: nullable2(m["oldest_entry_id"], (e) => entryId(e, "oldest_entry_id")),
117139
+ ...m["from"] === undefined ? {} : { from: snapshotFromOf(m["from"]) }
116935
117140
  };
116936
117141
  };
116937
- var snapshotBlobOf = (v) => snapshotBodyOf(known(v, BODY_FIELDS, [], "snapshot"));
117142
+ var snapshotBlobOf = (v) => snapshotBodyOf(known(v, BODY_FIELDS, SNAPSHOT_OPTIONAL_FIELDS, "snapshot"));
116938
117143
  var SNAPSHOT_FIELDS = BODY_FIELDS;
116939
117144
  var readEntryOf = (v) => {
116940
117145
  const m = known(v, ["kind", "entry_id"], ["entry", "bytes", "sha256"], "read entry");
@@ -116961,8 +117166,11 @@ var pathRefusalOf = (v) => {
116961
117166
  };
116962
117167
  };
116963
117168
  var errorBodyOf = (v) => {
116964
- const m = known(v, ["code", "reason", "action"], ["limit_chars", "path_refusal"], "error");
117169
+ const m = known(v, ["code", "reason", "action"], ["limit_chars", "path_refusal", "candidates", "incomplete", "sign_in_reason"], "error");
116965
117170
  const code = oneOf(ERROR_CODES, m["code"], "error.code");
117171
+ const reason = m["sign_in_reason"];
117172
+ if (reason !== undefined && code !== "sign_in_required")
117173
+ return fail("error.sign_in_reason");
116966
117174
  const limit = m["limit_chars"];
116967
117175
  if (code === "message_too_long" !== (limit !== undefined))
116968
117176
  return fail("error.limit_chars");
@@ -116974,78 +117182,12 @@ var errorBodyOf = (v) => {
116974
117182
  reason: text(m["reason"], REASON_MAX_CHARS, "error.reason", 0),
116975
117183
  action: nullable2(m["action"], (a) => text(a, LABEL_MAX_CHARS, "error.action")),
116976
117184
  ...limit === undefined ? {} : { limit_chars: uint(limit, 1, MILLIS_MAX, "error.limit_chars") },
116977
- ...refusal === undefined ? {} : { path_refusal: pathRefusalOf(refusal) }
117185
+ ...refusal === undefined ? {} : { path_refusal: pathRefusalOf(refusal) },
117186
+ ...reason === undefined ? {} : { sign_in_reason: oneOf(SIGN_IN_REASONS, reason, "error.sign_in_reason") },
117187
+ ...aliasErrorFields(code, m)
116978
117188
  };
116979
117189
  };
116980
117190
 
116981
- // packages/device-service-core/src/local-api/validate-command.ts
116982
- var commandRpcOf = (v) => jsonObject(v, "rpc");
116983
- var requestFields = (v, names, optional = []) => exactly(v, ["id", "type", ...names], optional, "request");
116984
- var commandIdField = (v) => v === undefined ? {} : { command_id: commandId(v) };
116985
- var ROUTE_FIELDS = ["command_id", "delegated", "endpoint"];
116986
- var routeFields = (m) => {
116987
- const delegated = m["delegated"];
116988
- if (delegated !== undefined && delegated !== true)
116989
- return fail("delegated");
116990
- return {
116991
- ...delegated === true ? { delegated: true } : {},
116992
- ...m["endpoint"] === undefined ? {} : { endpoint: endpointKey(m["endpoint"]) }
116993
- };
116994
- };
116995
- var COMMAND_REQUEST_VALIDATORS = {
116996
- "session.command": (v, id) => {
116997
- if (Object.hasOwn(v, "device")) {
116998
- const m = requestFields(v, ["device", "endpoint", "rpc"], ["command_id", "locate"]);
116999
- const locate = m["locate"];
117000
- if (locate !== undefined && locate !== true)
117001
- return fail("locate");
117002
- return {
117003
- id,
117004
- type: "session.command",
117005
- device: deviceId(m["device"]),
117006
- endpoint: endpointKey(m["endpoint"]),
117007
- ...commandIdField(m["command_id"]),
117008
- ...locate === true ? { locate: true } : {},
117009
- rpc: commandRpcOf(m["rpc"])
117010
- };
117011
- }
117012
- if (Object.hasOwn(v, "upload_id")) {
117013
- const m = requestFields(v, ["attach", "upload_id"], ROUTE_FIELDS);
117014
- return {
117015
- id,
117016
- type: "session.command",
117017
- attach: localId(m["attach"], "attach"),
117018
- ...commandIdField(m["command_id"]),
117019
- upload_id: localId(m["upload_id"], "upload_id"),
117020
- ...routeFields(m)
117021
- };
117022
- }
117023
- const m = requestFields(v, ["attach", "rpc"], ROUTE_FIELDS);
117024
- return {
117025
- id,
117026
- type: "session.command",
117027
- attach: localId(m["attach"], "attach"),
117028
- ...commandIdField(m["command_id"]),
117029
- rpc: commandRpcOf(m["rpc"]),
117030
- ...routeFields(m)
117031
- };
117032
- },
117033
- "session.command_part": (v, id) => {
117034
- const m = requestFields(v, ["attach", "upload_id", "index", "count", "b"]);
117035
- const count = uint(m["count"], 1, LOCAL_UPLOAD_PARTS_MAX, "count");
117036
- base64Bytes(m["b"], LOCAL_CHUNK_MAX, "b");
117037
- return {
117038
- id,
117039
- type: "session.command_part",
117040
- attach: localId(m["attach"], "attach"),
117041
- upload_id: localId(m["upload_id"], "upload_id"),
117042
- index: uint(m["index"], 0, count - 1, "index"),
117043
- count,
117044
- b: typeof m["b"] === "string" ? m["b"] : fail("b")
117045
- };
117046
- }
117047
- };
117048
-
117049
117191
  // packages/device-service-core/src/local-api/validate-stream-events.ts
117050
117192
  var eventFields = (v, names, optional = []) => known(v, ["type", "kind", ...names], optional, "event");
117051
117193
  var attachOf = (m) => localId(m["attach"], "attach");
@@ -117072,9 +117214,15 @@ var targetOf = (m) => {
117072
117214
  }
117073
117215
  }
117074
117216
  };
117217
+ var seqsOf = (v, count) => {
117218
+ if (!Array.isArray(v) || v.length !== count)
117219
+ return fail("seqs");
117220
+ const seqs = v.map((s) => uint(s, 1, Number.MAX_SAFE_INTEGER, "seq"));
117221
+ return seqs.every((s, i) => i === 0 || s > (seqs[i - 1] ?? s)) ? seqs : fail("seqs order");
117222
+ };
117075
117223
  var STREAM_EVENT_VALIDATORS = {
117076
117224
  "session.snapshot": (v) => {
117077
- const m = eventFields(v, ["attach", ...SNAPSHOT_FIELDS]);
117225
+ const m = eventFields(v, ["attach", ...SNAPSHOT_FIELDS], SNAPSHOT_OPTIONAL_FIELDS);
117078
117226
  return { type: "event", kind: "session.snapshot", attach: attachOf(m), ...snapshotBodyOf(m) };
117079
117227
  },
117080
117228
  "session.snapshot_loading": (v) => {
@@ -117087,7 +117235,7 @@ var STREAM_EVENT_VALIDATORS = {
117087
117235
  };
117088
117236
  },
117089
117237
  "session.records": (v) => {
117090
- const m = eventFields(v, ["attach", "attach_id", "records"]);
117238
+ const m = eventFields(v, ["attach", "attach_id", "records"], ["seqs"]);
117091
117239
  const records = m["records"];
117092
117240
  if (!Array.isArray(records) || records.length === 0)
117093
117241
  return fail("records");
@@ -117097,7 +117245,8 @@ var STREAM_EVENT_VALIDATORS = {
117097
117245
  kind: "session.records",
117098
117246
  attach: attachOf(m),
117099
117247
  attach_id,
117100
- records: records.map((r) => jsonObject(r, "record"))
117248
+ records: records.map((r) => jsonObject(r, "record")),
117249
+ ...m["seqs"] === undefined ? {} : { seqs: seqsOf(m["seqs"], records.length) }
117101
117250
  };
117102
117251
  },
117103
117252
  "session.blob_open": (v) => {
@@ -117161,32 +117310,97 @@ var STREAM_EVENT_VALIDATORS = {
117161
117310
  // packages/device-service-core/src/local-api/validate-delegated.ts
117162
117311
  var ENDPOINT_KEY = /^[A-Za-z0-9_-]{22}$/;
117163
117312
  var ENDPOINTS_MAX = 16;
117313
+ var ENVIRONMENTS_MAX = 4;
117164
117314
  var endpointKey = (v, what = "endpoint") => typeof v === "string" && ENDPOINT_KEY.test(v) ? v : fail(what);
117165
- var ENGINE_ID_MAX_CHARS = 128;
117166
- var engineId = (v) => typeof v === "string" && v.length >= 1 && v.length <= ENGINE_ID_MAX_CHARS && v.isWellFormed() ? v : fail("engine_id");
117315
+ var engineId = (v) => typeof v === "string" && v.length >= 1 && v.length <= SESSION_ID_MAX_CHARS && v.isWellFormed() ? v : fail("engine_id");
117167
117316
  var DELEGATED_REQUEST_VALIDATORS = {
117168
- "session.endpoints": (v, id) => ({
117169
- id,
117170
- type: "session.endpoints",
117171
- device: deviceId(requestFields(v, ["device"])["device"])
117172
- }),
117317
+ "session.endpoints": (v, id) => {
117318
+ const m = requestFields(v, ["device"], ["primary", "environments"]);
117319
+ if (m["primary"] !== undefined && m["primary"] !== true)
117320
+ return fail("primary");
117321
+ if (m["environments"] !== undefined && m["environments"] !== true)
117322
+ return fail("environments");
117323
+ return {
117324
+ id,
117325
+ type: "session.endpoints",
117326
+ device: deviceId(m["device"]),
117327
+ ...m["primary"] === true ? { primary: true } : {},
117328
+ ...m["environments"] === true ? { environments: true } : {}
117329
+ };
117330
+ },
117173
117331
  "session.locate": (v, id) => {
117174
- const m = requestFields(v, ["device", "engine_id"]);
117175
- return { id, type: "session.locate", device: deviceId(m["device"]), engine_id: engineId(m["engine_id"]) };
117332
+ const m = requestFields(v, ["device", "engine_id"], ["single"]);
117333
+ if (m["single"] !== undefined && m["single"] !== true)
117334
+ return fail("single");
117335
+ return {
117336
+ id,
117337
+ type: "session.locate",
117338
+ device: deviceId(m["device"]),
117339
+ engine_id: engineId(m["engine_id"]),
117340
+ ...m["single"] === true ? { single: true } : {}
117341
+ };
117176
117342
  }
117177
117343
  };
117178
- var locateData = (v) => {
117179
- const m = known(v, ["device", "key", "session"], [], "data");
117180
- const device = deviceId(m["device"]);
117181
- const key = endpointKey(m["key"], "key");
117182
- return m["session"] === `${device}.${key}` ? { device, key, session: `${device}.${key}` } : fail("session");
117344
+ var keysOf2 = (v, max, what) => {
117345
+ if (!Array.isArray(v) || v.length > max)
117346
+ return fail(what);
117347
+ const keys = v.map((e) => endpointKey(e, what));
117348
+ return new Set(keys).size === keys.length ? keys : fail(what);
117183
117349
  };
117184
117350
  var endpointsData = (v) => {
117185
- const endpoints = known(v, ["endpoints"], [], "data")["endpoints"];
117186
- if (!Array.isArray(endpoints) || endpoints.length > ENDPOINTS_MAX)
117187
- return fail("endpoints");
117188
- const keys = endpoints.map((e) => endpointKey(e, "endpoints"));
117189
- return new Set(keys).size === keys.length ? { endpoints: keys } : fail("endpoints");
117351
+ const m = known(v, ["endpoints"], ["environments", "primary"], "data");
117352
+ const endpoints = keysOf2(m["endpoints"], ENDPOINTS_MAX, "endpoints");
117353
+ const primary = m["primary"] === undefined ? undefined : endpointKey(m["primary"], "primary");
117354
+ if (primary !== undefined && !endpoints.includes(primary))
117355
+ return fail("primary");
117356
+ return {
117357
+ endpoints,
117358
+ ...m["environments"] === undefined ? {} : { environments: keysOf2(m["environments"], ENVIRONMENTS_MAX, "environments") },
117359
+ ...primary === undefined ? {} : { primary }
117360
+ };
117361
+ };
117362
+ var agentDirOf = (v) => absolutePath(requestFields(v, ["agent_dir"])["agent_dir"], "agent_dir");
117363
+ var environmentOf = (v, required) => {
117364
+ const m = requestFields(v, required);
117365
+ return m["kind"] === "environment" ? m : fail("kind");
117366
+ };
117367
+ var endpointsRegister = (v, id) => {
117368
+ if (v["kind"] === undefined)
117369
+ return { id, type: "endpoints.register", agent_dir: agentDirOf(v) };
117370
+ const m = environmentOf(v, ["kind", "socket", "key_root"]);
117371
+ return {
117372
+ id,
117373
+ type: "endpoints.register",
117374
+ kind: "environment",
117375
+ socket: absolutePath(m["socket"], "socket"),
117376
+ key_root: absolutePath(m["key_root"], "key_root")
117377
+ };
117378
+ };
117379
+ var endpointsUnregister = (v, id) => {
117380
+ if (v["kind"] === undefined)
117381
+ return { id, type: "endpoints.unregister", agent_dir: agentDirOf(v) };
117382
+ const m = environmentOf(v, ["kind", "socket"]);
117383
+ return {
117384
+ id,
117385
+ type: "endpoints.unregister",
117386
+ kind: "environment",
117387
+ socket: absolutePath(m["socket"], "socket")
117388
+ };
117389
+ };
117390
+ var endpointsList = (v, id) => {
117391
+ requestFields(v, []);
117392
+ return { id, type: "endpoints.list" };
117393
+ };
117394
+ var endpointsListData = (m) => {
117395
+ const dirs = m["agent_dirs"];
117396
+ if (!Array.isArray(dirs))
117397
+ return fail("agent_dirs");
117398
+ return { agent_dirs: dirs.map((d) => absolutePath(d, "agent_dirs")) };
117399
+ };
117400
+ var endpointRequests = {
117401
+ "endpoints.register": endpointsRegister,
117402
+ "endpoints.unregister": endpointsUnregister,
117403
+ "endpoints.list": endpointsList
117190
117404
  };
117191
117405
  var blobId = (m) => localId(m["id"], "blob id");
117192
117406
  var blobRefOf = (v) => {
@@ -117199,7 +117413,9 @@ var blobRefOf = (v) => {
117199
117413
  };
117200
117414
  var locatedOf = (device, v) => {
117201
117415
  const m = known(v, ["key", "session"], [], "located");
117202
- const key = endpointKey(m["key"], "located key");
117416
+ const key = m["key"];
117417
+ if (typeof key !== "string" || !isStreamSessionKey(key))
117418
+ return fail("located key");
117203
117419
  return m["session"] === `${device}.${key}` ? { key, session: `${device}.${key}` } : fail("located session");
117204
117420
  };
117205
117421
  var COMMAND_EVENT_FIELDS = ["blob", "frame", "command_id", "response", "located"];
@@ -117256,6 +117472,670 @@ var DELEGATED_EVENT_VALIDATORS = {
117256
117472
  }
117257
117473
  };
117258
117474
 
117475
+ // packages/device-service-core/src/local-api/validate-command.ts
117476
+ var commandRpcOf = (v) => jsonObject(v, "rpc");
117477
+ var requestFields = (v, names, optional = []) => exactly(v, ["id", "type", ...names], optional, "request");
117478
+ var acceptsField = (v) => {
117479
+ if (v === undefined)
117480
+ return {};
117481
+ if (!Array.isArray(v) || v.length !== 1 || v[0] !== "session-wake:v1")
117482
+ return fail("accepts");
117483
+ return { accepts: ["session-wake:v1"] };
117484
+ };
117485
+ var commandIdField = (v) => v === undefined ? {} : { command_id: commandId(v) };
117486
+ var ROUTE_FIELDS = ["command_id", "delegated", "endpoint", "locate"];
117487
+ var routeFields = (m) => {
117488
+ const delegated = m["delegated"];
117489
+ if (delegated !== undefined && delegated !== true)
117490
+ return fail("delegated");
117491
+ const locate = m["locate"];
117492
+ if (locate !== undefined && locate !== true)
117493
+ return fail("locate");
117494
+ return {
117495
+ ...delegated === true ? { delegated: true } : {},
117496
+ ...locate === true ? { locate: true } : {},
117497
+ ...m["endpoint"] === undefined ? {} : { endpoint: endpointKey(m["endpoint"]) }
117498
+ };
117499
+ };
117500
+ var TARGETS = ["attach", "device", "session", "alias", "wake"];
117501
+ var targetField = (v) => {
117502
+ const named = TARGETS.filter((f) => Object.hasOwn(v, f));
117503
+ const [only] = named;
117504
+ return named.length === 1 && only !== undefined ? only : fail("request names one target");
117505
+ };
117506
+ var TARGET_FIELDS = {
117507
+ attach: ["attach"],
117508
+ device: ["device", "endpoint"],
117509
+ session: ["session"],
117510
+ alias: ["alias"],
117511
+ wake: ["wake"]
117512
+ };
117513
+ var sessionField = (v) => typeof v === "string" && parseSessionRef(v) !== undefined ? v : fail("session");
117514
+ var aliasField = (v) => typeof v === "string" && v.length >= 1 && v.length <= ALIAS_MAX_CHARS && v.isWellFormed() && !unsafeAlias(v) ? v : fail("alias");
117515
+ var wakeField = (v) => {
117516
+ const m = exactly(v, ["device", "durable_id"], [], "wake");
117517
+ return { device: deviceId(m["device"], "wake.device"), durable_id: durableId(m["durable_id"]) };
117518
+ };
117519
+ var oneField = (m, field) => {
117520
+ switch (field) {
117521
+ case "attach":
117522
+ return { attach: localId(m["attach"], "attach") };
117523
+ case "session":
117524
+ return { session: sessionField(m["session"]) };
117525
+ case "alias":
117526
+ return { alias: aliasField(m["alias"]) };
117527
+ case "wake":
117528
+ return { wake: wakeField(m["wake"]) };
117529
+ }
117530
+ };
117531
+ var targetOf2 = (m, field) => field === "device" ? { device: deviceId(m["device"]), endpoint: endpointKey(m["endpoint"]) } : oneField(m, field);
117532
+ var partTargetOf = (m, field) => field === "device" ? { device: deviceId(m["device"]) } : oneField(m, field);
117533
+ var COMMAND_REQUEST_VALIDATORS = {
117534
+ "session.command": (v, id) => {
117535
+ const field = targetField(v);
117536
+ if (field !== "device" && Object.hasOwn(v, "locate"))
117537
+ return fail("locate acts only on a device and endpoint command");
117538
+ const target = TARGET_FIELDS[field];
117539
+ const body = Object.hasOwn(v, "upload_id") ? "upload_id" : "rpc";
117540
+ const delegated = field === "session" || field === "alias" || field === "wake";
117541
+ const optional = [
117542
+ ...delegated ? ["command_id"] : ROUTE_FIELDS.filter((f) => !target.includes(f)),
117543
+ "accepts"
117544
+ ];
117545
+ const m = requestFields(v, [...target, body], optional);
117546
+ return {
117547
+ id,
117548
+ type: "session.command",
117549
+ ...commandIdField(m["command_id"]),
117550
+ ...acceptsField(m["accepts"]),
117551
+ ...body === "upload_id" ? { upload_id: localId(m["upload_id"], "upload_id") } : { rpc: commandRpcOf(m["rpc"]) },
117552
+ ...routeFields(m),
117553
+ ...targetOf2(m, field)
117554
+ };
117555
+ },
117556
+ "session.command_part": (v, id) => {
117557
+ const target = targetField(v);
117558
+ const m = requestFields(v, [target, "upload_id", "index", "count", "b"]);
117559
+ const count = uint(m["count"], 1, LOCAL_UPLOAD_PARTS_MAX, "count");
117560
+ base64Bytes(m["b"], LOCAL_CHUNK_MAX, "b");
117561
+ return {
117562
+ id,
117563
+ type: "session.command_part",
117564
+ ...partTargetOf(m, target),
117565
+ upload_id: localId(m["upload_id"], "upload_id"),
117566
+ index: uint(m["index"], 0, count - 1, "index"),
117567
+ count,
117568
+ b: typeof m["b"] === "string" ? m["b"] : fail("b")
117569
+ };
117570
+ }
117571
+ };
117572
+
117573
+ // packages/device-service-core/src/local-api/validate-machine.ts
117574
+ var MACHINE_OPS_MAX = 4096;
117575
+ var MACHINE_REF_MAX_CHARS = 128;
117576
+ var MACHINE_CREDIT_MAX_BYTES = SESSION_BLOB_MAX;
117577
+ var BASE64URL2 = /^[A-Za-z0-9_-]+$/;
117578
+ var machineId = (v, what) => typeof v === "string" && v.length === COMMAND_ID_CHARS && BASE64URL2.test(v) ? v : fail(what);
117579
+ var machineRef = (v, what) => text(v, MACHINE_REF_MAX_CHARS, what);
117580
+ var opName = (v) => {
117581
+ try {
117582
+ return methodOf(v, "op");
117583
+ } catch (error) {
117584
+ if (error instanceof ProtoError)
117585
+ return fail("op");
117586
+ throw error;
117587
+ }
117588
+ };
117589
+ var opOf = (v) => {
117590
+ const m = exactly(v, ["op_id", "op", "args"], ["deadline_ms", "constraints"], "op");
117591
+ const deadline = m["deadline_ms"];
117592
+ const constraints = m["constraints"];
117593
+ return {
117594
+ op_id: machineId(m["op_id"], "op_id"),
117595
+ op: opName(m["op"]),
117596
+ args: jsonObject(m["args"], "args"),
117597
+ ...deadline === undefined ? {} : { deadline_ms: uint(deadline, 1, Number.MAX_SAFE_INTEGER, "deadline_ms") },
117598
+ ...constraints === undefined ? {} : { constraints: jsonObject(constraints, "constraints") }
117599
+ };
117600
+ };
117601
+ var uniqueIds = (ids, what) => new Set(ids).size === ids.length ? ids : fail(`duplicate ${what}`);
117602
+ var machineOpsOf = (v) => {
117603
+ if (!Array.isArray(v) || v.length === 0 || v.length > MACHINE_OPS_MAX)
117604
+ return fail("ops");
117605
+ const ops = v.map(opOf);
117606
+ uniqueIds(ops.map((o) => o.op_id), "op_id");
117607
+ return ops;
117608
+ };
117609
+ var refOf2 = (m) => m["session_ref"] === undefined ? {} : { session_ref: machineRef(m["session_ref"], "session_ref") };
117610
+ var bare = (v) => {
117611
+ requestFields(v, []);
117612
+ };
117613
+ var MACHINE_REQUEST_VALIDATORS = {
117614
+ "machine.list": (v, id) => {
117615
+ bare(v);
117616
+ return { id, type: "machine.list" };
117617
+ },
117618
+ "machine.events.subscribe": (v, id) => {
117619
+ bare(v);
117620
+ return { id, type: "machine.events.subscribe" };
117621
+ },
117622
+ "machine.describe": (v, id) => ({
117623
+ id,
117624
+ type: "machine.describe",
117625
+ device: deviceId(requestFields(v, ["device"])["device"])
117626
+ }),
117627
+ "machine.batch": (v, id) => {
117628
+ if (Object.hasOwn(v, "upload_id")) {
117629
+ const m = requestFields(v, ["device", "upload_id"], ["session_ref"]);
117630
+ const upload_id = localId(m["upload_id"], "upload_id");
117631
+ return { id, type: "machine.batch", device: deviceId(m["device"]), upload_id, ...refOf2(m) };
117632
+ }
117633
+ const m = requestFields(v, ["device", "ops"], ["session_ref"]);
117634
+ if (lineBytes(v) > LOCAL_INLINE_MAX)
117635
+ return fail("an inline batch over LOCAL_INLINE_MAX is an upload");
117636
+ return {
117637
+ id,
117638
+ type: "machine.batch",
117639
+ device: deviceId(m["device"]),
117640
+ ops: machineOpsOf(m["ops"]),
117641
+ ...refOf2(m)
117642
+ };
117643
+ },
117644
+ "machine.batch_part": (v, id) => {
117645
+ const m = requestFields(v, ["upload_id", "index", "count", "b"]);
117646
+ const count = uint(m["count"], 1, MACHINE_UPLOAD_PARTS_MAX, `count: ${MACHINE_UPLOAD_LIMIT}`);
117647
+ base64Bytes(m["b"], LOCAL_CHUNK_MAX, "b");
117648
+ return {
117649
+ id,
117650
+ type: "machine.batch_part",
117651
+ upload_id: localId(m["upload_id"], "upload_id"),
117652
+ index: uint(m["index"], 0, count - 1, "index"),
117653
+ count,
117654
+ b: typeof m["b"] === "string" ? m["b"] : fail("b")
117655
+ };
117656
+ },
117657
+ "machine.cancel": (v, id) => {
117658
+ const ids = requestFields(v, ["op_ids"])["op_ids"];
117659
+ if (!Array.isArray(ids) || ids.length === 0 || ids.length > MACHINE_OPS_MAX)
117660
+ return fail("op_ids");
117661
+ const op_ids = uniqueIds(ids.map((o) => machineId(o, "op_id")), "op_id");
117662
+ return { id, type: "machine.cancel", op_ids };
117663
+ },
117664
+ "machine.credit": (v, id) => {
117665
+ const m = requestFields(v, ["handle", "bytes"]);
117666
+ return {
117667
+ id,
117668
+ type: "machine.credit",
117669
+ handle: machineRef(m["handle"], "handle"),
117670
+ bytes: uint(m["bytes"], 1, MACHINE_CREDIT_MAX_BYTES, "bytes")
117671
+ };
117672
+ },
117673
+ "machine.result_of": (v, id) => ({
117674
+ id,
117675
+ type: "machine.result_of",
117676
+ op_id: machineId(requestFields(v, ["op_id"])["op_id"], "op_id")
117677
+ })
117678
+ };
117679
+ var empty = (v) => {
117680
+ known(v, [], [], "data");
117681
+ return {};
117682
+ };
117683
+ var fields = (v, names) => known(v, names, [], "data");
117684
+ var LEGACY_MACHINE_ROUTE_KINDS = ["internet", "lan"];
117685
+ var legacyRouteOf = (v) => {
117686
+ const r = known(v, ["kind", "online"], [], "machine route");
117687
+ const kind = oneOf(LEGACY_MACHINE_ROUTE_KINDS, r["kind"], "machine route kind");
117688
+ bool(r["online"], "online");
117689
+ return kind;
117690
+ };
117691
+ var machineRowOf = (v) => {
117692
+ const m = known(v, ["device", "label", "state"], ["routes"], "machine row");
117693
+ const routes = m["routes"];
117694
+ if (routes !== undefined && (!Array.isArray(routes) || routes.length > LEGACY_MACHINE_ROUTE_KINDS.length))
117695
+ return fail("routes");
117696
+ const listed = routes?.map(legacyRouteOf);
117697
+ if (listed !== undefined && new Set(listed).size !== listed.length)
117698
+ return fail("routes");
117699
+ return {
117700
+ device: deviceId(m["device"]),
117701
+ label: text(m["label"], LABEL_MAX_CHARS, "label", 0),
117702
+ state: oneOf(MACHINE_STATES, m["state"], "machine state")
117703
+ };
117704
+ };
117705
+ var MACHINE_DATA = {
117706
+ "machine.list": (v) => {
117707
+ const machines = fields(v, ["machines"])["machines"];
117708
+ return Array.isArray(machines) ? { machines: machines.map(machineRowOf) } : fail("machines");
117709
+ },
117710
+ "machine.describe": (v) => {
117711
+ const m = fields(v, ["device", "description"]);
117712
+ if (!isRecord19(m["description"]))
117713
+ return fail("description");
117714
+ return {
117715
+ device: deviceId(m["device"]),
117716
+ description: jsonObject(m["description"], "description")
117717
+ };
117718
+ },
117719
+ "machine.batch": (v) => ({
117720
+ batch_id: machineId(fields(v, ["batch_id"])["batch_id"], "batch_id")
117721
+ }),
117722
+ "machine.batch_part": (v) => ({
117723
+ received: uint(fields(v, ["received"])["received"], 0, MACHINE_UPLOAD_PARTS_MAX - 1, "received")
117724
+ }),
117725
+ "machine.cancel": empty,
117726
+ "machine.credit": empty,
117727
+ "machine.result_of": (v) => ({
117728
+ state: oneOf(MACHINE_LOOKUP_STATES, fields(v, ["state"])["state"], "lookup state")
117729
+ }),
117730
+ "machine.events.subscribe": empty
117731
+ };
117732
+
117733
+ // packages/device-service-core/src/local-api/validate-machine-events.ts
117734
+ var MACHINE_OUTPUT_MAX_BYTES = STREAM_INLINE_MAX;
117735
+ var blobId2 = (m) => localId(m["id"], "blob id");
117736
+ var blobRefOf2 = (v) => {
117737
+ const m = known(v, ["id", "bytes", "sha256"], [], "blob");
117738
+ return {
117739
+ id: blobId2(m),
117740
+ bytes: uint(m["bytes"], 1, LOCAL_BLOB_MAX, "blob bytes"),
117741
+ sha256: sha256Field(m["sha256"], "blob sha256")
117742
+ };
117743
+ };
117744
+ var base64Of = (v, max, what) => {
117745
+ base64Bytes(v, max, what);
117746
+ return typeof v === "string" ? v : fail(what);
117747
+ };
117748
+ var TIMING_FIELDS = [
117749
+ "enqueued_ms",
117750
+ "flushed_ms",
117751
+ "confirmed_ms",
117752
+ "dispatched_ms",
117753
+ "settled_ms",
117754
+ "applied_ms"
117755
+ ];
117756
+ var timingOf = (v) => {
117757
+ const m = known(v, [], TIMING_FIELDS, "timing");
117758
+ return Object.fromEntries(TIMING_FIELDS.flatMap((k) => m[k] === undefined ? [] : [[k, uint(m[k], 0, Number.MAX_SAFE_INTEGER, k)]]));
117759
+ };
117760
+ var opResultOf = (v) => {
117761
+ const head = { type: "event", kind: "machine.op_result" };
117762
+ const all = eventFields(v, ["op_id"], ["blob", "response"]);
117763
+ const shape = (name) => exactly(all, ["type", "kind", "op_id", name], [], "event");
117764
+ if (Object.hasOwn(all, "blob")) {
117765
+ const m = shape("blob");
117766
+ return { ...head, op_id: machineId(m["op_id"], "op_id"), blob: blobRefOf2(m["blob"]) };
117767
+ }
117768
+ const m = shape("response");
117769
+ if (lineBytes(v) > LOCAL_INLINE_MAX)
117770
+ return fail("an inline result over LOCAL_INLINE_MAX is a blob");
117771
+ return {
117772
+ ...head,
117773
+ op_id: machineId(m["op_id"], "op_id"),
117774
+ response: jsonObject(m["response"], "response")
117775
+ };
117776
+ };
117777
+ var MACHINE_EVENT_VALIDATORS = {
117778
+ "machine.op_state": (v) => {
117779
+ const m = eventFields(v, ["op_id", "state"], ["timing"]);
117780
+ return {
117781
+ type: "event",
117782
+ kind: "machine.op_state",
117783
+ op_id: machineId(m["op_id"], "op_id"),
117784
+ state: oneOf(MACHINE_OP_STATES, m["state"], "op state"),
117785
+ ...m["timing"] === undefined ? {} : { timing: timingOf(m["timing"]) }
117786
+ };
117787
+ },
117788
+ "machine.op_result": opResultOf,
117789
+ "machine.output": (v) => {
117790
+ const m = eventFields(v, ["handle", "seq", "bytes"]);
117791
+ return {
117792
+ type: "event",
117793
+ kind: "machine.output",
117794
+ handle: machineRef(m["handle"], "handle"),
117795
+ seq: uint(m["seq"], 0, Number.MAX_SAFE_INTEGER, "seq"),
117796
+ bytes: base64Of(m["bytes"], MACHINE_OUTPUT_MAX_BYTES, "bytes")
117797
+ };
117798
+ },
117799
+ "machine.changed": (v) => {
117800
+ const m = eventFields(v, ["device", "state"]);
117801
+ return {
117802
+ type: "event",
117803
+ kind: "machine.changed",
117804
+ device: deviceId(m["device"]),
117805
+ state: oneOf(MACHINE_STATES, m["state"], "machine state")
117806
+ };
117807
+ },
117808
+ "machine.blob_chunk": (v) => {
117809
+ const m = eventFields(v, ["id", "off", "b"]);
117810
+ return {
117811
+ type: "event",
117812
+ kind: "machine.blob_chunk",
117813
+ id: blobId2(m),
117814
+ off: uint(m["off"], 0, LOCAL_BLOB_MAX, "blob off"),
117815
+ b: base64Of(m["b"], LOCAL_CHUNK_MAX, "blob chunk")
117816
+ };
117817
+ },
117818
+ "machine.blob_done": (v) => ({
117819
+ type: "event",
117820
+ kind: "machine.blob_done",
117821
+ id: blobId2(eventFields(v, ["id"]))
117822
+ }),
117823
+ "machine.blob_abort": (v) => {
117824
+ const m = eventFields(v, ["id", "reason"]);
117825
+ return {
117826
+ type: "event",
117827
+ kind: "machine.blob_abort",
117828
+ id: blobId2(m),
117829
+ reason: oneOf(MACHINE_BLOB_ABORT_REASONS, m["reason"], "blob abort reason")
117830
+ };
117831
+ }
117832
+ };
117833
+
117834
+ // packages/device-service-core/src/local-api/protocol-presenter.ts
117835
+ var PRESENTER_LOCAL_LANES = ["control", "delegated"];
117836
+ var PRESENTER_LOCAL_LINE_MAX = {
117837
+ control: 16 * 1024,
117838
+ delegated: 1024 * 1024
117839
+ };
117840
+ var PRESENTER_ENDED_REASONS = [
117841
+ "viewer_closed",
117842
+ "engine_closed",
117843
+ "no_control_endpoint",
117844
+ "no_delegated_connection",
117845
+ "not_granted",
117846
+ "conn_collision",
117847
+ "busy",
117848
+ "idle",
117849
+ "event_lost",
117850
+ "too_large",
117851
+ "malformed",
117852
+ "rate"
117853
+ ];
117854
+
117855
+ // packages/device-service-core/src/local-api/validate-presenter.ts
117856
+ var BASE64URL3 = /^[A-Za-z0-9_-]+$/;
117857
+ var presenterLineText = (v, lane) => {
117858
+ const max = PRESENTER_LOCAL_LINE_MAX[lane];
117859
+ if (typeof v !== "string" || v.length === 0 || v.length > Math.ceil(max * 4 / 3))
117860
+ return fail("line too long");
117861
+ if (!BASE64URL3.test(v))
117862
+ return fail("line");
117863
+ let bytes;
117864
+ try {
117865
+ bytes = fromBase64url(v);
117866
+ } catch (error) {
117867
+ if (error instanceof Error)
117868
+ return fail("line");
117869
+ throw error;
117870
+ }
117871
+ return bytes.length <= max && toBase64url(bytes) === v ? v : fail("line");
117872
+ };
117873
+ var laneOf = (v) => oneOf(PRESENTER_LOCAL_LANES, v["lane"], "lane");
117874
+ var PRESENTER_REQUEST_VALIDATORS = {
117875
+ "session.presenter_open": (v, id) => {
117876
+ const m = requestFields(v, ["device", "session"]);
117877
+ return {
117878
+ id,
117879
+ type: "session.presenter_open",
117880
+ device: deviceId(m["device"]),
117881
+ session: sessionId(m["session"])
117882
+ };
117883
+ },
117884
+ "session.presenter_send": (v, id) => {
117885
+ const m = requestFields(v, ["device", "lane", "b"]);
117886
+ const lane = laneOf(m);
117887
+ return {
117888
+ id,
117889
+ type: "session.presenter_send",
117890
+ device: deviceId(m["device"]),
117891
+ lane,
117892
+ b: presenterLineText(m["b"], lane)
117893
+ };
117894
+ }
117895
+ };
117896
+ var frameOf = (v) => {
117897
+ const m = eventFields(v, ["device", "lane", "b"]);
117898
+ const lane = laneOf(m);
117899
+ return {
117900
+ type: "event",
117901
+ kind: "session.presenter_frame",
117902
+ device: deviceId(m["device"]),
117903
+ lane,
117904
+ b: presenterLineText(m["b"], lane)
117905
+ };
117906
+ };
117907
+ var PRESENTER_EVENT_VALIDATORS = {
117908
+ "session.presenter_frame": frameOf,
117909
+ "session.presenter_ended": (v) => {
117910
+ const m = eventFields(v, ["device", "reason"]);
117911
+ return {
117912
+ type: "event",
117913
+ kind: "session.presenter_ended",
117914
+ device: deviceId(m["device"]),
117915
+ reason: oneOf(PRESENTER_ENDED_REASONS, m["reason"], "presenter end reason")
117916
+ };
117917
+ }
117918
+ };
117919
+
117920
+ // packages/device-service-core/src/local-api/validate-deliveries.ts
117921
+ var PROTOCOL_MAX = 1e6;
117922
+ var PAIRS_MAX = 4096;
117923
+ var pairOf = (m) => ({
117924
+ sender_device: deviceId(m["sender_device"], "sender_device"),
117925
+ session_id: durableId(m["session_id"], "session_id"),
117926
+ last_command_id: commandId(m["last_command_id"])
117927
+ });
117928
+ var PAIR_FIELDS = ["sender_device", "session_id", "last_command_id"];
117929
+ var DELIVERIES_REQUEST_VALIDATORS = {
117930
+ "delivery.pending": (v, id) => {
117931
+ const pairs = requestFields(v, ["pairs"])["pairs"];
117932
+ if (!Array.isArray(pairs) || pairs.length > PAIRS_MAX)
117933
+ return fail("pairs");
117934
+ return {
117935
+ id,
117936
+ type: "delivery.pending",
117937
+ pairs: pairs.map((p) => pairOf(exactly(p, PAIR_FIELDS, [], "pair")))
117938
+ };
117939
+ },
117940
+ "delivery.drained": (v, id) => ({
117941
+ id,
117942
+ type: "delivery.drained",
117943
+ ...pairOf(requestFields(v, PAIR_FIELDS))
117944
+ }),
117945
+ "deliveries.serve": (v, id) => {
117946
+ const m = requestFields(v, ["agent_dir", "v"]);
117947
+ return {
117948
+ id,
117949
+ type: "deliveries.serve",
117950
+ agent_dir: absolutePath(m["agent_dir"], "agent_dir"),
117951
+ v: uint(m["v"], 0, PROTOCOL_MAX, "v")
117952
+ };
117953
+ },
117954
+ "delivery.answer": (v, id) => {
117955
+ const m = requestFields(v, ["sender_device", "command_id", "reply"]);
117956
+ return {
117957
+ id,
117958
+ type: "delivery.answer",
117959
+ sender_device: deviceId(m["sender_device"], "sender_device"),
117960
+ command_id: commandId(m["command_id"]),
117961
+ reply: jsonObject(m["reply"], "reply")
117962
+ };
117963
+ },
117964
+ "delivery.held": (v, id) => {
117965
+ const m = requestFields(v, ["ask_id", "holds"]);
117966
+ return {
117967
+ id,
117968
+ type: "delivery.held",
117969
+ ask_id: localId(m["ask_id"], "ask_id"),
117970
+ holds: bool(m["holds"], "holds")
117971
+ };
117972
+ },
117973
+ "peer.admitted": (v, id) => ({
117974
+ id,
117975
+ type: "peer.admitted",
117976
+ device: deviceId(requestFields(v, ["device"])["device"])
117977
+ })
117978
+ };
117979
+ var empty2 = (v) => {
117980
+ known(v, [], [], "data");
117981
+ return {};
117982
+ };
117983
+ var DELIVERIES_DATA = {
117984
+ "deliveries.serve": (v) => {
117985
+ const m = known(v, ["wake"], [], "data");
117986
+ return { wake: bool(m["wake"], "wake") };
117987
+ },
117988
+ "delivery.answer": empty2,
117989
+ "delivery.held": empty2,
117990
+ "delivery.pending": empty2,
117991
+ "delivery.drained": (v) => {
117992
+ const m = known(v, ["kept"], ["expecting"], "data");
117993
+ const kept = bool(m["kept"], "kept");
117994
+ if (!kept)
117995
+ return m["expecting"] === undefined ? { kept } : fail("expecting");
117996
+ return { kept, expecting: commandId(m["expecting"]) };
117997
+ },
117998
+ "peer.admitted": (v) => ({
117999
+ admitted: bool(known(v, ["admitted"], [], "data")["admitted"], "admitted")
118000
+ })
118001
+ };
118002
+ var DELIVERIES_EVENT_VALIDATORS = {
118003
+ "delivery.wake": (v) => {
118004
+ const m = eventFields(v, ["enabled"]);
118005
+ return { type: "event", kind: "delivery.wake", enabled: bool(m["enabled"], "enabled") };
118006
+ },
118007
+ "delivery.inbound": (v) => {
118008
+ const m = eventFields(v, ["command_id", "sender_device", "durable_id", "record"]);
118009
+ return {
118010
+ type: "event",
118011
+ kind: "delivery.inbound",
118012
+ command_id: commandId(m["command_id"]),
118013
+ sender_device: deviceId(m["sender_device"], "sender_device"),
118014
+ durable_id: durableId(m["durable_id"]),
118015
+ record: jsonObject(m["record"], "record")
118016
+ };
118017
+ },
118018
+ "delivery.holds": (v) => {
118019
+ const m = eventFields(v, ["ask_id", "durable_id"]);
118020
+ return {
118021
+ type: "event",
118022
+ kind: "delivery.holds",
118023
+ ask_id: localId(m["ask_id"], "ask_id"),
118024
+ durable_id: durableId(m["durable_id"])
118025
+ };
118026
+ }
118027
+ };
118028
+
118029
+ // packages/device-service-core/src/local-api/validate-listing-row.ts
118030
+ var ROW_FIELDS = [
118031
+ "device",
118032
+ "session_id",
118033
+ "title",
118034
+ "project",
118035
+ "path",
118036
+ "state",
118037
+ "updated_ms",
118038
+ "source",
118039
+ "as_of"
118040
+ ];
118041
+ var ROW_KIND = new RegExp(`^[a-z][a-z0-9_-]{0,${SESSION_KIND_MAX_CHARS - 1}}$`);
118042
+ var rowLinks = (m) => {
118043
+ const kind = m["kind"];
118044
+ if (Object.hasOwn(m, "parent") !== Object.hasOwn(m, "parent_listed"))
118045
+ fail("parent_listed");
118046
+ return {
118047
+ ...kind === undefined ? {} : { kind: typeof kind === "string" && ROW_KIND.test(kind) ? kind : fail("row kind") },
118048
+ ...m["parent"] === undefined ? {} : {
118049
+ parent: sessionId(m["parent"]),
118050
+ parent_listed: bool(m["parent_listed"], "parent_listed")
118051
+ }
118052
+ };
118053
+ };
118054
+ var rowModel = (v) => {
118055
+ if (v === undefined)
118056
+ return {};
118057
+ const m = known(v, ["provider", "id"], [], "model");
118058
+ return {
118059
+ model: {
118060
+ provider: text(m["provider"], SESSION_MODEL_PROVIDER_MAX_CHARS, "model provider"),
118061
+ id: text(m["id"], SESSION_MODEL_ID_MAX_CHARS, "model id")
118062
+ }
118063
+ };
118064
+ };
118065
+ var settledByOf = (v) => {
118066
+ const named = known(v, ["kind"], [], "settled_by")["kind"];
118067
+ if (typeof named !== "string")
118068
+ return fail("settled_by kind");
118069
+ const kind = LISTING_SETTLED_BY_KINDS.find((k) => k === named);
118070
+ switch (kind) {
118071
+ case undefined:
118072
+ return;
118073
+ case "user":
118074
+ return { kind };
118075
+ case "agent": {
118076
+ const m = known(v, ["kind"], ["threadId", "threadTitle"], "settled_by");
118077
+ const id = m["threadId"];
118078
+ const title = m["threadTitle"];
118079
+ return {
118080
+ kind,
118081
+ ...id === undefined ? {} : { threadId: text(id, SESSION_ID_MAX_CHARS, "settled_by threadId") },
118082
+ ...title === undefined ? {} : {
118083
+ threadTitle: text(title, SESSION_SETTLED_THREAD_TITLE_MAX_CHARS, "settled_by threadTitle", 0)
118084
+ }
118085
+ };
118086
+ }
118087
+ case "pr-merged":
118088
+ case "pr-closed": {
118089
+ const n = known(v, ["kind"], ["pullRequestNumber"], "settled_by")["pullRequestNumber"];
118090
+ return {
118091
+ kind,
118092
+ ...n === undefined ? {} : {
118093
+ pullRequestNumber: uint(n, 0, Number.MAX_SAFE_INTEGER, "settled_by pullRequestNumber")
118094
+ }
118095
+ };
118096
+ }
118097
+ case "inactivity": {
118098
+ const days = known(v, ["kind", "days"], [], "settled_by")["days"];
118099
+ return { kind, days: uint(days, 0, SESSION_SETTLED_DAYS_MAX, "settled_by days") };
118100
+ }
118101
+ default:
118102
+ return assertNever(kind);
118103
+ }
118104
+ };
118105
+ var rowSettled = (m) => {
118106
+ const reason = m["settled_by"];
118107
+ if (m["settled"] === undefined)
118108
+ return reason === undefined ? {} : fail("settled_by");
118109
+ const settled = bool(m["settled"], "settled");
118110
+ if (reason === undefined)
118111
+ return { settled };
118112
+ if (!settled)
118113
+ return fail("settled_by");
118114
+ const by = settledByOf(reason);
118115
+ return by === undefined ? { settled } : { settled, settled_by: by };
118116
+ };
118117
+ var listingRowOf = (v) => {
118118
+ const m = known(v, ROW_FIELDS, ["kind", "parent", "parent_listed", "durable_id", "model", "archived", "settled", "settled_by"], "listing row");
118119
+ const durable = m["durable_id"];
118120
+ const archived = m["archived"];
118121
+ return {
118122
+ ...rowLinks(m),
118123
+ ...rowModel(m["model"]),
118124
+ ...rowSettled(m),
118125
+ ...archived === undefined ? {} : { archived: archived === true ? true : fail("archived") },
118126
+ ...durable === undefined ? {} : { durable_id: text(durable, SESSION_ID_MAX_CHARS, "durable_id") },
118127
+ device: deviceId(m["device"]),
118128
+ session_id: sessionId(m["session_id"]),
118129
+ title: text(m["title"], SESSION_SUMMARY_TITLE_MAX_CHARS, "title", 0),
118130
+ project: text(m["project"], SESSION_SUMMARY_PROJECT_MAX_CHARS, "project"),
118131
+ path: text(m["path"], SESSION_SUMMARY_PATH_MAX_CHARS, "path"),
118132
+ state: oneOf(SESSION_ROW_STATES, m["state"], "row state"),
118133
+ updated_ms: millis(m["updated_ms"], "updated_ms"),
118134
+ source: oneOf(LISTING_SOURCES, m["source"], "row source"),
118135
+ as_of: millis(m["as_of"], "as_of")
118136
+ };
118137
+ };
118138
+
117259
118139
  // packages/device-service-core/src/local-api/validate-events.ts
117260
118140
  var revisionOf = (m) => uint(m["revision"], 1, Number.MAX_SAFE_INTEGER, "revision");
117261
118141
  var devicesOf = (v) => {
@@ -117263,7 +118143,7 @@ var devicesOf = (v) => {
117263
118143
  return fail("round devices");
117264
118144
  const out = {};
117265
118145
  for (const [device, state] of Object.entries(v))
117266
- out[safeKey(deviceId(device), "round device")] = oneOf(ROUND_DEVICE_STATES, state, "round device state");
118146
+ out[safeKey2(deviceId(device), "round device")] = oneOf(ROUND_DEVICE_STATES, state, "round device state");
117267
118147
  return out;
117268
118148
  };
117269
118149
  var commandStateOf = (v) => {
@@ -117306,7 +118186,10 @@ var commandStateOf = (v) => {
117306
118186
  };
117307
118187
  var VALIDATORS = {
117308
118188
  ...STREAM_EVENT_VALIDATORS,
118189
+ ...MACHINE_EVENT_VALIDATORS,
117309
118190
  ...DELEGATED_EVENT_VALIDATORS,
118191
+ ...PRESENTER_EVENT_VALIDATORS,
118192
+ ...DELIVERIES_EVENT_VALIDATORS,
117310
118193
  "status.changed": (v) => ({
117311
118194
  type: "event",
117312
118195
  kind: "status.changed",
@@ -117345,6 +118228,15 @@ var VALIDATORS = {
117345
118228
  rows: rows.map(listingRowOf)
117346
118229
  };
117347
118230
  },
118231
+ "sessions.listing_changed": (v) => {
118232
+ const m = eventFields(v, ["device", "generation"]);
118233
+ return {
118234
+ type: "event",
118235
+ kind: "sessions.listing_changed",
118236
+ device: deviceId(m["device"]),
118237
+ generation: nullable2(m["generation"], (g) => uint(g, 0, Number.MAX_SAFE_INTEGER, "generation"))
118238
+ };
118239
+ },
117348
118240
  "sessions.listing_end": (v) => {
117349
118241
  const m = eventFields(v, ["query_id", "revision", "incomplete"]);
117350
118242
  const incomplete = m["incomplete"];
@@ -117378,6 +118270,20 @@ var VALIDATORS = {
117378
118270
  next_before
117379
118271
  };
117380
118272
  },
118273
+ "host.update_notice": (v) => {
118274
+ const m = eventFields(v, ["target_version", "phase", "policy"], ["update_id", "deadline_ms"]);
118275
+ const id = m["update_id"];
118276
+ const deadline = m["deadline_ms"];
118277
+ return {
118278
+ type: "event",
118279
+ kind: "host.update_notice",
118280
+ ...id === undefined ? {} : { update_id: localId(id, "update_id") },
118281
+ target_version: semver(m["target_version"], "target_version"),
118282
+ phase: oneOf(UPDATE_NOTICE_PHASES, m["phase"], "update notice phase"),
118283
+ ...deadline === undefined ? {} : { deadline_ms: millis(deadline, "deadline_ms") },
118284
+ policy: oneOf(UPDATE_POLICIES, m["policy"], "update policy")
118285
+ };
118286
+ },
117381
118287
  "session.upload_abort": (v) => {
117382
118288
  const m = eventFields(v, ["upload_id", "reason"]);
117383
118289
  const reason = oneOf(UPLOAD_ABORT_REASONS, m["reason"], "upload abort reason");
@@ -117396,8 +118302,36 @@ var validateEventFields = (v) => {
117396
118302
  return VALIDATORS[oneOf(EVENT_KINDS, v["kind"], "event kind")](v);
117397
118303
  };
117398
118304
 
118305
+ // packages/device-service-core/src/local-api/validate-session-wake.ts
118306
+ var SESSION_WAKE_VALIDATORS = {
118307
+ "control.session_wake.get": (v, id) => {
118308
+ requestFields(v, []);
118309
+ return { id, type: "control.session_wake.get" };
118310
+ },
118311
+ "control.session_wake.set": (v, id) => {
118312
+ const raw = requestFields(v, ["enabled"])["enabled"];
118313
+ return {
118314
+ id,
118315
+ type: "control.session_wake.set",
118316
+ enabled: raw === null ? null : bool(raw, "enabled")
118317
+ };
118318
+ }
118319
+ };
118320
+ var storedOf = (v) => v === null || v === "unreadable" || typeof v === "boolean" ? v : fail("stored");
118321
+ var sessionWakeState = (v) => {
118322
+ const m = known(v, ["enabled", "stored", "changedAt", "overridden"], [], "data");
118323
+ const stored = m["stored"];
118324
+ const changedAt = m["changedAt"];
118325
+ return {
118326
+ enabled: bool(m["enabled"], "enabled"),
118327
+ stored: storedOf(stored),
118328
+ changedAt: typeof changedAt === "string" ? changedAt : fail("changedAt"),
118329
+ overridden: bool(m["overridden"], "overridden")
118330
+ };
118331
+ };
118332
+
117399
118333
  // packages/device-service-core/src/local-api/validate-requests.ts
117400
- var ENVIRONMENTS_MAX = 1024;
118334
+ var ENVIRONMENTS_MAX2 = 1024;
117401
118335
  var PKCS8_KEY_BYTES = 48;
117402
118336
  var PKCS8_PREFIX = {
117403
118337
  ed25519: "302e020100300506032b657004220420",
@@ -117405,7 +118339,7 @@ var PKCS8_PREFIX = {
117405
118339
  };
117406
118340
  var pkcs8 = (v, algorithm, what) => {
117407
118341
  const bytes = base64Bytes(v, PKCS8_KEY_BYTES, what);
117408
- const prefix = Buffer.from(bytes.subarray(0, 16)).toString("hex");
118342
+ const prefix = toHex(bytes.subarray(0, 16));
117409
118343
  const exact = bytes.length === PKCS8_KEY_BYTES && prefix === PKCS8_PREFIX[algorithm];
117410
118344
  return exact && typeof v === "string" ? v : fail(what);
117411
118345
  };
@@ -117418,7 +118352,7 @@ var filterOf = (v) => {
117418
118352
  };
117419
118353
  };
117420
118354
  var environmentsOf = (v) => {
117421
- if (!Array.isArray(v) || v.length > ENVIRONMENTS_MAX)
118355
+ if (!Array.isArray(v) || v.length > ENVIRONMENTS_MAX2)
117422
118356
  return fail("environments");
117423
118357
  const rows = v.map((e) => {
117424
118358
  const m = exactly(e, ["environment_id", "revoked", "closed"], [], "environment");
@@ -117430,33 +118364,62 @@ var environmentsOf = (v) => {
117430
118364
  });
117431
118365
  return new Set(rows.map((r) => r.environment_id)).size === rows.length ? rows : fail("duplicate environment_id");
117432
118366
  };
117433
- var bare = (v) => {
118367
+ var resumeOf = (v) => {
118368
+ const m = exactly(v, ["attach_id", "seq"], [], "resume");
118369
+ const seq = uint(m["seq"], 0, Number.MAX_SAFE_INTEGER, "resume.seq");
118370
+ return { attach_id: attachId(m["attach_id"]), seq };
118371
+ };
118372
+ var fromOf = (v) => {
118373
+ const m = exactly(v, ["last_entry_id"], [], "from");
118374
+ return { last_entry_id: entryId(m["last_entry_id"], "from.last_entry_id") };
118375
+ };
118376
+ var bare2 = (v) => {
117434
118377
  requestFields(v, []);
117435
118378
  };
117436
- var agentDir = (v) => absolutePath(requestFields(v, ["agent_dir"])["agent_dir"], "agent_dir");
117437
118379
  var VALIDATORS2 = {
117438
118380
  ...COMMAND_REQUEST_VALIDATORS,
118381
+ ...MACHINE_REQUEST_VALIDATORS,
117439
118382
  ...DELEGATED_REQUEST_VALIDATORS,
118383
+ ...PRESENTER_REQUEST_VALIDATORS,
118384
+ ...DELIVERIES_REQUEST_VALIDATORS,
117440
118385
  authenticate: (v, id) => {
117441
118386
  const m = requestFields(v, ["client_proof"]);
117442
118387
  return { id, type: "authenticate", client_proof: text(m["client_proof"], 64, "client_proof") };
117443
118388
  },
117444
118389
  "status.get": (v, id) => {
117445
- bare(v);
117446
- return { id, type: "status.get" };
118390
+ const { exe, sign_in_reason: reason } = requestFields(v, [], ["exe", "sign_in_reason"]);
118391
+ if (exe !== undefined && exe !== true)
118392
+ return fail("exe");
118393
+ if (reason !== undefined && reason !== true)
118394
+ return fail("sign_in_reason");
118395
+ return {
118396
+ id,
118397
+ type: "status.get",
118398
+ ...exe === true ? { exe } : {},
118399
+ ...reason === true ? { sign_in_reason: reason } : {}
118400
+ };
117447
118401
  },
117448
118402
  "status.subscribe": (v, id) => {
117449
- bare(v);
118403
+ bare2(v);
117450
118404
  return { id, type: "status.subscribe" };
117451
118405
  },
117452
118406
  "control.attach.get": (v, id) => {
117453
- bare(v);
118407
+ bare2(v);
117454
118408
  return { id, type: "control.attach.get" };
117455
118409
  },
117456
118410
  "control.attach.set": (v, id) => {
117457
118411
  const attached = bool(requestFields(v, ["attached"])["attached"], "attached");
117458
118412
  return { id, type: "control.attach.set", attached };
117459
118413
  },
118414
+ "control.remote_commands.get": (v, id) => {
118415
+ bare2(v);
118416
+ return { id, type: "control.remote_commands.get" };
118417
+ },
118418
+ "control.remote_commands.set": (v, id) => {
118419
+ const enabled = bool(requestFields(v, ["enabled"])["enabled"], "enabled");
118420
+ return { id, type: "control.remote_commands.set", enabled };
118421
+ },
118422
+ ...SESSION_WAKE_VALIDATORS,
117460
118423
  "service.set_enabled": (v, id) => {
117461
118424
  const enabled = bool(requestFields(v, ["enabled"])["enabled"], "enabled");
117462
118425
  return { id, type: "service.set_enabled", enabled };
@@ -117472,32 +118435,42 @@ var VALIDATORS2 = {
117472
118435
  };
117473
118436
  },
117474
118437
  "device.adopt": (v, id) => {
117475
- const m = requestFields(v, ["device", "signing_private_key", "sealing_private_key"]);
118438
+ const m = requestFields(v, ["device", "signing_private_key", "sealing_private_key"], ["account", "sign_in_reason"]);
118439
+ const reason = m["sign_in_reason"];
118440
+ if (reason !== undefined && reason !== true)
118441
+ return fail("sign_in_reason");
117476
118442
  return {
117477
118443
  id,
117478
118444
  type: "device.adopt",
117479
118445
  device: deviceRef(m["device"]),
118446
+ ...m["account"] === undefined ? {} : { account: text(m["account"], 256, "account") },
118447
+ ...reason === true ? { sign_in_reason: reason } : {},
117480
118448
  signing_private_key: pkcs8(m["signing_private_key"], "ed25519", "signing_private_key"),
117481
118449
  sealing_private_key: pkcs8(m["sealing_private_key"], "x25519", "sealing_private_key")
117482
118450
  };
117483
118451
  },
117484
118452
  "device.forget": (v, id) => {
117485
- bare(v);
118453
+ bare2(v);
117486
118454
  return { id, type: "device.forget" };
117487
118455
  },
117488
118456
  "device.info": (v, id) => {
117489
- bare(v);
118457
+ bare2(v);
117490
118458
  return { id, type: "device.info" };
117491
118459
  },
117492
- "endpoints.register": (v, id) => ({ id, type: "endpoints.register", agent_dir: agentDir(v) }),
117493
- "endpoints.unregister": (v, id) => ({ id, type: "endpoints.unregister", agent_dir: agentDir(v) }),
118460
+ ...endpointRequests,
117494
118461
  "devices.list": (v, id) => {
117495
- bare(v);
117496
- return { id, type: "devices.list" };
118462
+ const { managed } = requestFields(v, [], ["managed"]);
118463
+ if (managed !== undefined && managed !== true)
118464
+ return fail("managed");
118465
+ return { id, type: "devices.list", ...managed === undefined ? {} : { managed } };
118466
+ },
118467
+ "sessions.events.subscribe": (v, id) => {
118468
+ bare2(v);
118469
+ return { id, type: "sessions.events.subscribe" };
117497
118470
  },
117498
118471
  "sessions.list": (v, id) => {
117499
118472
  const { filter, rows } = requestFields(v, [], ["filter", "rows"]);
117500
- if (rows !== undefined && rows !== 2 && rows !== 3)
118473
+ if (rows !== undefined && rows !== 2 && rows !== 3 && rows !== 4 && rows !== 5)
117501
118474
  return fail("rows");
117502
118475
  return {
117503
118476
  id,
@@ -117507,12 +118480,20 @@ var VALIDATORS2 = {
117507
118480
  };
117508
118481
  },
117509
118482
  "session.attach": (v, id) => {
117510
- const m = requestFields(v, ["device", "session_id"]);
118483
+ const m = requestFields(v, ["device", "session_id"], ["seqs", "resume", "from"]);
118484
+ const { seqs, resume, from, session_id } = m;
118485
+ if (seqs !== undefined && seqs !== true)
118486
+ return fail("seqs");
118487
+ if (!isStreamSessionKey(session_id))
118488
+ return fail("session_id");
117511
118489
  return {
117512
118490
  id,
117513
118491
  type: "session.attach",
117514
118492
  device: deviceId(m["device"]),
117515
- session_id: sessionId(m["session_id"])
118493
+ session_id,
118494
+ ...seqs === undefined ? {} : { seqs },
118495
+ ...resume === undefined ? {} : { resume: resumeOf(resume) },
118496
+ ...from === undefined ? {} : { from: fromOf(from) }
117516
118497
  };
117517
118498
  },
117518
118499
  "session.detach": (v, id) => ({
@@ -117546,7 +118527,8 @@ var VALIDATORS2 = {
117546
118527
  "owner.shutdown_for_upgrade": (v, id) => {
117547
118528
  const target_version = semver(requestFields(v, ["target_version"])["target_version"], "target_version");
117548
118529
  return { id, type: "owner.shutdown_for_upgrade", target_version };
117549
- }
118530
+ },
118531
+ "owner.update_committed": (v, id) => updateCommittedOf(requestFields(v, ["update_id"]), id)
117550
118532
  };
117551
118533
  var REQUEST_TYPES = keysOf(VALIDATORS2);
117552
118534
 
@@ -117567,7 +118549,16 @@ var validateWelcome = (v) => asViolation(() => {
117567
118549
  }
117568
118550
  if (isRecord19(v) && v["type"] === "welcome" && v["v"] !== LOCAL_API_VERSION)
117569
118551
  return { type: "refused", reason: "version" };
117570
- const fields = ["type", "v", "service_version", "owner", "server_proof", "server_nonce", "capabilities", "state"];
118552
+ const fields = [
118553
+ "type",
118554
+ "v",
118555
+ "service_version",
118556
+ "owner",
118557
+ "server_proof",
118558
+ "server_nonce",
118559
+ "capabilities",
118560
+ "state"
118561
+ ];
117571
118562
  const m = known(v, fields, [], "welcome");
117572
118563
  const capabilities = m["capabilities"];
117573
118564
  if (m["type"] !== "welcome" || m["owner"] !== "service")
@@ -117585,7 +118576,7 @@ var validateWelcome = (v) => asViolation(() => {
117585
118576
  state: statusOf(m["state"])
117586
118577
  };
117587
118578
  });
117588
- var empty = (v) => {
118579
+ var empty3 = (v) => {
117589
118580
  known(v, [], [], "data");
117590
118581
  return {};
117591
118582
  };
@@ -117598,37 +118589,57 @@ var attachState = (v) => {
117598
118589
  changedAt: typeof changedAt === "string" ? changedAt : fail("changedAt")
117599
118590
  };
117600
118591
  };
118592
+ var remoteCommandsState = (v) => {
118593
+ const m = known(v, ["enabled", "changedAt", "overridden"], [], "data");
118594
+ const changedAt = m["changedAt"];
118595
+ return {
118596
+ enabled: bool(m["enabled"], "enabled"),
118597
+ changedAt: typeof changedAt === "string" ? changedAt : fail("changedAt"),
118598
+ overridden: bool(m["overridden"], "overridden")
118599
+ };
118600
+ };
117601
118601
  var DATA = {
117602
- authenticate: empty,
118602
+ authenticate: empty3,
117603
118603
  "status.get": statusOf,
117604
- "status.subscribe": empty,
118604
+ "status.subscribe": empty3,
117605
118605
  "service.set_enabled": (v) => ({ enabled: bool(one(v, "enabled"), "enabled") }),
117606
- "refresher.register": empty,
118606
+ "refresher.register": empty3,
117607
118607
  "device.adopt": (v) => ({ device: deviceRef(one(v, "device"), "device", known) }),
117608
- "device.forget": empty,
118608
+ "device.forget": empty3,
117609
118609
  "device.info": (v) => ({
117610
118610
  device: nullable2(one(v, "device"), (d) => deviceRef(d, "device", known))
117611
118611
  }),
117612
- "endpoints.register": empty,
117613
- "endpoints.unregister": empty,
118612
+ "endpoints.register": empty3,
118613
+ "endpoints.unregister": empty3,
118614
+ "endpoints.list": (v) => endpointsListData(known(v, ["agent_dirs"], [], "data")),
118615
+ "session.presenter_open": empty3,
118616
+ "session.presenter_send": empty3,
117614
118617
  "devices.list": (v) => {
117615
118618
  const devices = one(v, "devices");
117616
118619
  return Array.isArray(devices) ? { devices: devices.map(deviceRowOf) } : fail("devices");
117617
118620
  },
117618
118621
  "sessions.list": (v) => ({ query_id: localId(one(v, "query_id"), "query_id") }),
118622
+ "sessions.events.subscribe": empty3,
117619
118623
  "session.attach": (v) => ({ attach: localId(one(v, "attach"), "attach") }),
117620
- "session.detach": empty,
117621
- "session.command": (v) => ({ command_id: commandId(one(v, "command_id")) }),
118624
+ "session.detach": empty3,
118625
+ "session.command": commandAnswerOf,
117622
118626
  "session.command_part": (v) => ({
117623
118627
  received: uint(one(v, "received"), 0, LOCAL_UPLOAD_PARTS_MAX - 1, "received")
117624
118628
  }),
117625
118629
  "session.read": (v) => ({ query_id: localId(one(v, "query_id"), "query_id") }),
117626
- "enforcement.report": empty,
117627
- "owner.shutdown_for_upgrade": empty,
117628
- "session.endpoints": endpointsData,
117629
- "session.locate": locateData,
118630
+ "enforcement.report": empty3,
118631
+ "owner.shutdown_for_upgrade": empty3,
118632
+ "owner.update_committed": empty3,
117630
118633
  "control.attach.get": attachState,
117631
- "control.attach.set": attachState
118634
+ "control.attach.set": attachState,
118635
+ "control.remote_commands.get": remoteCommandsState,
118636
+ "control.remote_commands.set": remoteCommandsState,
118637
+ "control.session_wake.get": sessionWakeState,
118638
+ "control.session_wake.set": sessionWakeState,
118639
+ "session.endpoints": endpointsData,
118640
+ "session.locate": (v) => refOf(v, "session.locate data"),
118641
+ ...MACHINE_DATA,
118642
+ ...DELIVERIES_DATA
117632
118643
  };
117633
118644
  var validateResponse = (v, type) => asViolation(() => {
117634
118645
  const m = known(v, ["id", "type", "ok"], ["data", "error"], "response");
@@ -117705,16 +118716,30 @@ class EventAssembler {
117705
118716
  case "session.detached":
117706
118717
  return this.#detached(event.attach);
117707
118718
  case "status.changed":
118719
+ case "sessions.listing_changed":
117708
118720
  case "session.snapshot":
117709
118721
  case "session.snapshot_loading":
117710
118722
  case "session.records":
117711
118723
  case "session.attach_pending":
117712
118724
  case "session.command_state":
117713
118725
  case "session.upload_abort":
118726
+ case "machine.op_state":
118727
+ case "machine.op_result":
118728
+ case "machine.output":
118729
+ case "machine.changed":
118730
+ case "machine.blob_chunk":
118731
+ case "machine.blob_done":
118732
+ case "machine.blob_abort":
117714
118733
  case "session.command_event":
117715
118734
  case "session.command_blob_chunk":
117716
118735
  case "session.command_blob_done":
117717
118736
  case "session.channel_closed":
118737
+ case "session.presenter_frame":
118738
+ case "session.presenter_ended":
118739
+ case "host.update_notice":
118740
+ case "delivery.inbound":
118741
+ case "delivery.holds":
118742
+ case "delivery.wake":
117718
118743
  return;
117719
118744
  default:
117720
118745
  return assertNever(event);
@@ -117759,7 +118784,8 @@ class EventAssembler {
117759
118784
  kind: "session.records",
117760
118785
  attach,
117761
118786
  attach_id: open.position.attach_id,
117762
- records
118787
+ records,
118788
+ seqs: [open.position.seq]
117763
118789
  });
117764
118790
  }
117765
118791
  case "entry": {
@@ -117982,12 +119008,8 @@ class ClientConnection {
117982
119008
  throw error;
117983
119009
  }
117984
119010
  if (!response.ok) {
117985
- const { code, reason, action, limit_chars, path_refusal } = response.error;
117986
- reject(new LocalApiError(code, reason, {
117987
- action,
117988
- ...limit_chars === undefined ? {} : { limit_chars },
117989
- ...path_refusal === undefined ? {} : { path_refusal }
117990
- }));
119011
+ const { code, reason, ...extra } = response.error;
119012
+ reject(new LocalApiError(code, reason, extra));
117991
119013
  return;
117992
119014
  }
117993
119015
  onAnswer?.(response.data);
@@ -118045,64 +119067,7 @@ class ClientConnection {
118045
119067
  }
118046
119068
  }
118047
119069
 
118048
- // packages/device-service-core/src/local-api/transport.ts
118049
- import { lstatSync as lstatSync7, readFileSync as readFileSync47, unlinkSync as unlinkSync11 } from "fs";
118050
- import { createConnection, createServer as createServer4 } from "net";
118051
- import { join as join119 } from "path";
118052
- var ENDPOINT_FILE = "endpoint.json";
118053
- var wrap = (socket, endpoint) => {
118054
- const closeListeners = [];
118055
- let closed = false;
118056
- socket.on("close", () => {
118057
- closed = true;
118058
- for (const listener of closeListeners.splice(0))
118059
- listener();
118060
- });
118061
- socket.on("error", () => {});
118062
- return {
118063
- endpoint,
118064
- write: (bytes) => {
118065
- if (!closed)
118066
- socket.write(bytes);
118067
- },
118068
- close: () => {
118069
- socket.end();
118070
- },
118071
- destroy: () => {
118072
- socket.destroy();
118073
- },
118074
- onData: (listener) => {
118075
- socket.on("data", (chunk) => listener(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength)));
118076
- },
118077
- onClose: (listener) => {
118078
- if (closed)
118079
- listener();
118080
- else
118081
- closeListeners.push(listener);
118082
- }
118083
- };
118084
- };
118085
- var readEndpointPort = (stateDir) => {
118086
- const parsed = JSON.parse(readFileSync47(join119(stateDir, ENDPOINT_FILE), "utf8"));
118087
- const port = typeof parsed === "object" && parsed !== null ? Reflect.get(parsed, "port") : undefined;
118088
- if (typeof port !== "number" || !Number.isInteger(port) || port < 1 || port > 65535)
118089
- throw new LocalApiError("insecure_state_dir", "endpoint.json holds no port");
118090
- return port;
118091
- };
118092
- var connectLocal = (stateDir, options = {}) => new Promise((resolve, reject) => {
118093
- const port = process.platform === "win32" ? readEndpointPort(stateDir) : undefined;
118094
- const endpoint = port === undefined ? UNIX_ENDPOINT : tcpEndpoint(port);
118095
- const socket = port === undefined ? createConnection({ path: join119(stateDir, SOCKET_FILE) }) : createConnection({ host: "127.0.0.1", port });
118096
- if (options.background === true)
118097
- socket.unref();
118098
- socket.once("error", reject);
118099
- socket.once("connect", () => {
118100
- socket.off("error", reject);
118101
- resolve(wrap(socket, endpoint));
118102
- });
118103
- });
118104
-
118105
- // packages/device-service-core/src/local-api/client.ts
119070
+ // packages/device-service-core/src/local-api/client-open.ts
118106
119071
  var HANDSHAKE_TIMEOUT_MS = 1e4;
118107
119072
  var REQUEST_TIMEOUT_MS = 30000;
118108
119073
  var realTimer = (expire, ms) => {
@@ -118121,7 +119086,7 @@ var proveAndAuthenticate = async (connection, options) => {
118121
119086
  const welcome = validateWelcome(await connection.firstMessage());
118122
119087
  if (welcome.type === "refused")
118123
119088
  throw new LocalApiError("refused", welcome.reason);
118124
- const token = (options.readToken ?? (() => readToken(options.stateDir)))();
119089
+ const token = options.readToken();
118125
119090
  if (!proofMatches(serverProof(token, nonce, connection.endpoint), welcome.server_proof))
118126
119091
  throw new LocalApiError("server_proof_invalid", "the owner did not prove the per-boot token");
118127
119092
  await connection.request("authenticate", {
@@ -118140,7 +119105,13 @@ var handshake = (connection, options) => new Promise((resolve, reject) => {
118140
119105
  }, HANDSHAKE_TIMEOUT_MS);
118141
119106
  proveAndAuthenticate(connection, options).then(resolve, reject).finally(cancel);
118142
119107
  });
118143
- var sendCommand = async (connection, attach, rpc, command_id, route) => {
119108
+ var sendCommand = async (connection, target, rpc, command_id, given = {}, mark = {}) => {
119109
+ const marked = mark.accepts === undefined ? {} : { accepts: mark.accepts };
119110
+ const route = {
119111
+ ...given.delegated === true && (("attach" in target) || ("endpoint" in target)) ? { delegated: true } : {},
119112
+ ...given.endpoint !== undefined && "attach" in target ? { endpoint: given.endpoint } : {},
119113
+ ...given.locate === true && "endpoint" in target ? { locate: true } : {}
119114
+ };
118144
119115
  const sent = command_id ?? mintId();
118145
119116
  const id = { command_id: sent };
118146
119117
  const timedOut = (error) => {
@@ -118153,8 +119124,9 @@ var sendCommand = async (connection, attach, rpc, command_id, route) => {
118153
119124
  const draft = {
118154
119125
  id: "x".repeat(REQUEST_ID_MAX_CHARS),
118155
119126
  type: "session.command",
118156
- attach,
119127
+ ...target,
118157
119128
  ...id,
119129
+ ...marked,
118158
119130
  ...route,
118159
119131
  rpc
118160
119132
  };
@@ -118165,33 +119137,14 @@ var sendCommand = async (connection, attach, rpc, command_id, route) => {
118165
119137
  limit_chars: MESSAGE_LIMIT_CHARS
118166
119138
  });
118167
119139
  const upload_id = mintId();
118168
- const parts = uploadParts(json).map((part) => connection.request("session.command_part", { attach, upload_id, ...part }));
119140
+ const on = "device" in target ? { device: target.device } : target;
119141
+ const parts = uploadParts(json).map((part) => connection.request("session.command_part", { ...on, upload_id, ...part }));
118169
119142
  await Promise.all(parts);
118170
- return (await connection.request("session.command", { attach, ...id, ...route, upload_id }).catch(timedOut)).command_id;
118171
- }
118172
- return (await connection.request("session.command", { attach, ...id, ...route, rpc }).catch(timedOut)).command_id;
118173
- };
118174
- var sendEndpointCommand = async (connection, device, endpoint, rpc, command_id, locate) => {
118175
- const sent = command_id ?? mintId();
118176
- const params = { device, endpoint, command_id: sent, ...locate ? { locate: true } : {}, rpc };
118177
- if (lineBytes({ id: "x".repeat(REQUEST_ID_MAX_CHARS), type: "session.command", ...params }) > LOCAL_INLINE_MAX)
118178
- throw new LocalApiError("message_too_long", "an endpoint command travels inline only", {
118179
- limit_chars: MESSAGE_LIMIT_CHARS
118180
- });
118181
- try {
118182
- return (await connection.request("session.command", params)).command_id;
118183
- } catch (error) {
118184
- if (error instanceof LocalApiError && error.code === "request_timeout")
118185
- throw new LocalApiError("request_timeout", `command ${sent} may have been dispatched; follow its command state`, {
118186
- command_id: sent
118187
- });
118188
- throw error;
119143
+ return (await connection.request("session.command", { ...target, ...id, ...marked, ...route, upload_id }).catch(timedOut)).command_id;
118189
119144
  }
119145
+ return (await connection.request("session.command", { ...target, ...id, ...marked, ...route, rpc }).catch(timedOut)).command_id;
118190
119146
  };
118191
- var connectLocalApi = async (options) => {
118192
- if (process.platform !== "win32")
118193
- checkPosixAccess(options.stateDir);
118194
- const transport = await (options.transport ?? (() => connectLocal(options.stateDir)))();
119147
+ var openLocalApiClient = async (transport, options) => {
118195
119148
  const listeners = new Set;
118196
119149
  const assembler = new EventAssembler((event) => {
118197
119150
  for (const listener of [...listeners])
@@ -118212,8 +119165,8 @@ var connectLocalApi = async (options) => {
118212
119165
  listeners.delete(listener);
118213
119166
  };
118214
119167
  },
118215
- command: (attach, rpc, command_id, route = {}) => sendCommand(connection, attach, rpc, command_id, route),
118216
- endpointCommand: (device, endpoint, rpc, command_id, options) => sendEndpointCommand(connection, device, endpoint, rpc, command_id, options?.locate === true),
119168
+ command: (attach, rpc, command_id) => sendCommand(connection, { attach }, rpc, command_id),
119169
+ commandTo: (target, rpc, command_id, route, mark) => sendCommand(connection, target, rpc, command_id, route, mark),
118217
119170
  list: (filter, onRevision, rows) => new Promise((resolve, reject) => {
118218
119171
  const params = {
118219
119172
  ...filter === undefined ? {} : { filter },
@@ -118232,6 +119185,134 @@ var connectLocalApi = async (options) => {
118232
119185
  };
118233
119186
  };
118234
119187
 
119188
+ // packages/device-service-core/src/local-api/transport.ts
119189
+ import { lstatSync as lstatSync7, readFileSync as readFileSync47, unlinkSync as unlinkSync11 } from "fs";
119190
+ import { createConnection, createServer as createServer4 } from "net";
119191
+ import { join as join119 } from "path";
119192
+ var ENDPOINT_FILE = "endpoint.json";
119193
+ var wrap = (socket, endpoint) => {
119194
+ const closeListeners = [];
119195
+ let closed = false;
119196
+ socket.on("close", () => {
119197
+ closed = true;
119198
+ for (const listener of closeListeners.splice(0))
119199
+ listener();
119200
+ });
119201
+ socket.on("error", () => {});
119202
+ return {
119203
+ endpoint,
119204
+ write: (bytes) => {
119205
+ if (!closed)
119206
+ socket.write(bytes);
119207
+ },
119208
+ close: () => {
119209
+ socket.end();
119210
+ },
119211
+ destroy: () => {
119212
+ socket.destroy();
119213
+ },
119214
+ onData: (listener) => {
119215
+ socket.on("data", (chunk) => listener(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength)));
119216
+ },
119217
+ onClose: (listener) => {
119218
+ if (closed)
119219
+ listener();
119220
+ else
119221
+ closeListeners.push(listener);
119222
+ }
119223
+ };
119224
+ };
119225
+ var readEndpointPort = (stateDir) => {
119226
+ const parsed = JSON.parse(readFileSync47(join119(stateDir, ENDPOINT_FILE), "utf8"));
119227
+ const port = typeof parsed === "object" && parsed !== null ? Reflect.get(parsed, "port") : undefined;
119228
+ if (typeof port !== "number" || !Number.isInteger(port) || port < 1 || port > 65535)
119229
+ throw new LocalApiError("insecure_state_dir", "endpoint.json holds no port");
119230
+ return port;
119231
+ };
119232
+ var connectLocal = (stateDir) => new Promise((resolve, reject) => {
119233
+ const port = process.platform === "win32" ? readEndpointPort(stateDir) : undefined;
119234
+ const endpoint = port === undefined ? UNIX_ENDPOINT : tcpEndpoint(port);
119235
+ const socket = port === undefined ? createConnection({ path: join119(stateDir, SOCKET_FILE) }) : createConnection({ host: "127.0.0.1", port });
119236
+ socket.once("error", reject);
119237
+ socket.once("connect", () => {
119238
+ socket.off("error", reject);
119239
+ resolve(wrap(socket, endpoint));
119240
+ });
119241
+ });
119242
+
119243
+ // packages/device-service-core/src/local-api/client.ts
119244
+ var connectLocalApi = async (options) => {
119245
+ if (process.platform !== "win32")
119246
+ checkPosixAccess(options.stateDir);
119247
+ const transport = await (options.transport ?? (() => connectLocal(options.stateDir)))();
119248
+ return openLocalApiClient(transport, {
119249
+ client: options.client,
119250
+ readToken: options.readToken ?? (() => readToken(options.stateDir)),
119251
+ ...options.handshakeTimer === undefined ? {} : { handshakeTimer: options.handshakeTimer },
119252
+ ...options.requestTimer === undefined ? {} : { requestTimer: options.requestTimer }
119253
+ });
119254
+ };
119255
+
119256
+ // packages/device-service-core/src/background-transport.ts
119257
+ import { createConnection as createConnection2 } from "net";
119258
+ import { join as join120 } from "path";
119259
+ var wrap2 = (socket, endpoint) => {
119260
+ const closeListeners = [];
119261
+ let closed = false;
119262
+ socket.on("close", () => {
119263
+ closed = true;
119264
+ for (const listener of closeListeners.splice(0))
119265
+ listener();
119266
+ });
119267
+ socket.on("error", () => {});
119268
+ return {
119269
+ endpoint,
119270
+ write: (bytes) => {
119271
+ if (!closed)
119272
+ socket.write(bytes);
119273
+ },
119274
+ close: () => {
119275
+ socket.end();
119276
+ },
119277
+ destroy: () => {
119278
+ socket.destroy();
119279
+ },
119280
+ onData: (listener) => {
119281
+ socket.on("data", (chunk) => listener(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength)));
119282
+ },
119283
+ onClose: (listener) => {
119284
+ if (closed)
119285
+ listener();
119286
+ else
119287
+ closeListeners.push(listener);
119288
+ }
119289
+ };
119290
+ };
119291
+ var connectLocalBackground = (stateDir) => new Promise((resolve, reject) => {
119292
+ const port = process.platform === "win32" ? readEndpointPort(stateDir) : undefined;
119293
+ const endpoint = port === undefined ? UNIX_ENDPOINT : tcpEndpoint(port);
119294
+ const socket = port === undefined ? createConnection2({ path: join120(stateDir, SOCKET_FILE) }) : createConnection2({ host: "127.0.0.1", port });
119295
+ socket.unref();
119296
+ socket.once("error", reject);
119297
+ socket.once("connect", () => {
119298
+ socket.off("error", reject);
119299
+ resolve(wrap2(socket, endpoint));
119300
+ });
119301
+ });
119302
+
119303
+ // packages/device-service-core/src/not-sent-error.ts
119304
+ class NotSentError extends LocalApiError {
119305
+ not_sent = true;
119306
+ }
119307
+ var markNotSent = (error) => error instanceof LocalApiError ? new NotSentError(error.code, error.reason, {
119308
+ action: error.action,
119309
+ ...error.limit_chars === undefined ? {} : { limit_chars: error.limit_chars },
119310
+ ...error.path_refusal === undefined ? {} : { path_refusal: error.path_refusal },
119311
+ ...error.candidates === undefined ? {} : { candidates: error.candidates },
119312
+ ...error.incomplete === undefined ? {} : { incomplete: error.incomplete },
119313
+ ...error.sign_in_reason === undefined ? {} : { sign_in_reason: error.sign_in_reason }
119314
+ }) : error;
119315
+
118235
119316
  // packages/device-service-core/src/remote-attach.ts
118236
119317
  import { randomBytes as randomBytes8 } from "crypto";
118237
119318
 
@@ -118369,7 +119450,12 @@ var toRemote = (event) => {
118369
119450
  return { kind: "snapshot", snapshot };
118370
119451
  }
118371
119452
  case "session.records":
118372
- return { kind: "records", attach_id: event.attach_id, records: event.records };
119453
+ return {
119454
+ kind: "records",
119455
+ attach_id: event.attach_id,
119456
+ records: event.records,
119457
+ ...event.seqs === undefined ? {} : { seqs: event.seqs }
119458
+ };
118373
119459
  case "session.attach_pending":
118374
119460
  return { kind: "pending", reason: event.reason };
118375
119461
  case "session.detached":
@@ -118481,7 +119567,7 @@ function openAttach(client, device, sessionId) {
118481
119567
  failure: () => failure,
118482
119568
  onFrame: (listener) => delegated.onFrame(listener),
118483
119569
  onChannelLoss: (listener) => delegated.onLoss(listener),
118484
- command: (rpc) => new Promise((resolve, reject) => {
119570
+ command: (rpc, options) => new Promise((resolve, reject) => {
118485
119571
  if (ended)
118486
119572
  return reject(new Error("the attach has ended"));
118487
119573
  const commandId = randomBytes8(16).toString("base64url");
@@ -118505,7 +119591,7 @@ function openAttach(client, device, sessionId) {
118505
119591
  resolve(response === undefined ? { outcome: event } : { outcome: event, response });
118506
119592
  });
118507
119593
  commands.add(end);
118508
- client.command(attach, rpc, commandId, { delegated: true }).catch((error) => {
119594
+ client.commandTo({ attach }, rpc, commandId, { delegated: true }, options).catch((error) => {
118509
119595
  settle();
118510
119596
  reject(error);
118511
119597
  });
@@ -118549,6 +119635,9 @@ function newestRowsListing(client) {
118549
119635
  // packages/device-service-core/src/device-service.ts
118550
119636
  import { randomBytes as randomBytes9 } from "crypto";
118551
119637
 
119638
+ // packages/device-service-core/src/minimum-in-effect.ts
119639
+ var minimumInEffect = (option, key, shipped) => option === undefined ? shipped : option[key];
119640
+
118552
119641
  // packages/device-service-core/src/release/version.ts
118553
119642
  var SEMVER2 = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
118554
119643
  var compareIdentifier = (a, b) => {
@@ -118585,9 +119674,49 @@ var compareVersions4 = (a, b) => {
118585
119674
  }
118586
119675
  return 0;
118587
119676
  };
119677
+
119678
+ // packages/device-service-core/src/state-dir.ts
119679
+ import { readFileSync as readFileSync48, statSync as statSync10 } from "fs";
119680
+ import { homedir as homedir36 } from "os";
119681
+ import { dirname as dirname49, join as join121, posix as posix17, win32 as win3212 } from "path";
119682
+ var DEVICE_SERVICE_STATE_DIR_ENV = "OMO_DEVICE_SERVICE_STATE_DIR";
119683
+ var LOCATION_FILE = "device-service.location.json";
119684
+ var isAbsoluteOn = (platform, path) => (platform === "win32" ? win3212 : posix17).isAbsolute(path);
119685
+ function defaultStateDir(platform, env, home) {
119686
+ if (platform !== "win32")
119687
+ return join121(home, ".omo", "device-service");
119688
+ const localAppData = env.LOCALAPPDATA ?? join121(home, "AppData", "Local");
119689
+ return join121(localAppData, "OmO", "device-service");
119690
+ }
119691
+ function discoveredStateDir(platform, defaultDir) {
119692
+ try {
119693
+ const parsed = JSON.parse(readFileSync48(join121(dirname49(defaultDir), LOCATION_FILE), "utf8"));
119694
+ if (typeof parsed !== "object" || parsed === null || !("v" in parsed) || !("state_dir" in parsed))
119695
+ return;
119696
+ const { v, state_dir: stateDir } = parsed;
119697
+ if (v !== 1 || typeof stateDir !== "string" || !isAbsoluteOn(platform, stateDir))
119698
+ return;
119699
+ return statSync10(stateDir).isDirectory() ? stateDir : undefined;
119700
+ } catch {
119701
+ return;
119702
+ }
119703
+ }
119704
+ function deviceServiceStateDir(platform = process.platform, env = process.env, home = homedir36()) {
119705
+ const explicit = env[DEVICE_SERVICE_STATE_DIR_ENV];
119706
+ if (explicit !== undefined && explicit !== "" && isAbsoluteOn(platform, explicit))
119707
+ return explicit;
119708
+ const defaultDir = defaultStateDir(platform, env, home);
119709
+ return discoveredStateDir(platform, defaultDir) ?? defaultDir;
119710
+ }
118588
119711
  // packages/device-service-core/src/device-service.ts
118589
119712
  var ENDPOINT_COMMAND_WAIT_MS = 120000;
118590
119713
  function sendToEndpoint(client, device, endpoint, rpc, locate) {
119714
+ return followDelegatedCommand(client, device, (commandId) => {
119715
+ const send = (asked) => client.commandTo({ device, endpoint }, rpc, commandId, asked ? { locate: true } : {});
119716
+ return send(locate).catch((error) => locate && error instanceof LocalApiError && error.code === "invalid_request" ? send(false) : Promise.reject(error));
119717
+ });
119718
+ }
119719
+ function followDelegatedCommand(client, device, send) {
118591
119720
  return new Promise((resolve, reject) => {
118592
119721
  const commandId = randomBytes9(16).toString("base64url");
118593
119722
  const channel = followDelegatedChannel(device);
@@ -118622,36 +119751,32 @@ function sendToEndpoint(client, device, endpoint, rpc, locate) {
118622
119751
  const timer = setTimeout(() => fail(new Error(`no final state for endpoint command ${commandId} within ${ENDPOINT_COMMAND_WAIT_MS} ms`)), ENDPOINT_COMMAND_WAIT_MS);
118623
119752
  timer.unref?.();
118624
119753
  client.closed.then(() => fail(new Error("the connection closed before the endpoint command settled")));
118625
- const send = (asked) => client.endpointCommand(device, endpoint, rpc, commandId, { locate: asked });
118626
- send(locate).catch((error) => locate && error instanceof LocalApiError && error.code === "invalid_request" ? send(false).catch(fail) : fail(error));
119754
+ send(commandId).catch(fail);
118627
119755
  });
118628
119756
  }
118629
- var markNotSent = (error) => error instanceof LocalApiError ? new LocalApiError(error.code, error.reason, {
118630
- action: error.action,
118631
- ...error.limit_chars === undefined ? {} : { limit_chars: error.limit_chars },
118632
- ...error.path_refusal === undefined ? {} : { path_refusal: error.path_refusal },
118633
- not_sent: true
118634
- }) : error;
118635
- function deviceServiceStateDir(platform = process.platform, env = process.env, home = homedir36()) {
118636
- if (platform !== "win32")
118637
- return join120(home, ".omo", "device-service");
118638
- const localAppData = env.LOCALAPPDATA ?? join120(home, "AppData", "Local");
118639
- return join120(localAppData, "OmO", "device-service");
118640
- }
118641
119757
  function deviceServiceEndpointPath(stateDir, platform = process.platform) {
118642
- return join120(stateDir, platform === "win32" ? ENDPOINT_FILE : SOCKET_FILE);
119758
+ return join122(stateDir, platform === "win32" ? ENDPOINT_FILE : SOCKET_FILE);
118643
119759
  }
118644
119760
  var ADOPT_ACCOUNT_MIN_SERVICE_VERSION = "0.1.3";
118645
119761
  var acceptsAdoptAccount = (serviceVersion) => compareVersions4(serviceVersion, ADOPT_ACCOUNT_MIN_SERVICE_VERSION) >= 0;
119762
+ var WAKE_MARK_MIN_SERVICE_VERSION = "0.1.31";
119763
+ var LOCATE_SINGLE_MIN_SERVICE_VERSION = "0.1.13";
119764
+ var serviceAtLeast = (serviceVersion, minimum) => minimum !== null && compareVersions4(serviceVersion, minimum) >= 0;
118646
119765
  async function connectDeviceService(options) {
118647
119766
  const stateDir = options.stateDir ?? deviceServiceStateDir();
118648
119767
  const client = await (options.connect ?? connectLocalApi)({
118649
119768
  stateDir,
118650
119769
  client: { name: "omo", version: options.version },
118651
- ...options.background === true ? { transport: () => connectLocal(stateDir, { background: true }) } : {}
119770
+ ...options.background === true ? { transport: () => connectLocalBackground(stateDir) } : {}
118652
119771
  });
119772
+ const wakeMarkMinimum = minimumInEffect(options.minimums, "wakeMark", WAKE_MARK_MIN_SERVICE_VERSION);
119773
+ const carriesWakeMark = serviceAtLeast(client.welcome.service_version, wakeMarkMinimum);
119774
+ const takesSingleLocate = serviceAtLeast(client.welcome.service_version, minimumInEffect(options.minimums, "singleLocate", LOCATE_SINGLE_MIN_SERVICE_VERSION));
118653
119775
  return {
118654
119776
  serviceVersion: client.welcome.service_version,
119777
+ carriesWakeMark,
119778
+ wakeMarkMinimum,
119779
+ takesSingleLocate,
118655
119780
  capabilities: client.welcome.capabilities,
118656
119781
  initialStatus: client.welcome.state,
118657
119782
  status: () => client.request("status.get", {}),
@@ -118669,6 +119794,8 @@ async function connectDeviceService(options) {
118669
119794
  return stop;
118670
119795
  },
118671
119796
  setEnabled: async (enabled) => (await client.request("service.set_enabled", { enabled })).enabled,
119797
+ sessionWake: () => client.request("control.session_wake.get", {}),
119798
+ setSessionWake: (enabled) => client.request("control.session_wake.set", { enabled }),
118672
119799
  attachControl: () => client.request("control.attach.get", {}),
118673
119800
  setAttachControl: (attached) => client.request("control.attach.set", { attached }),
118674
119801
  registerRefresher: async (binaryPath, version) => {
@@ -118689,7 +119816,10 @@ async function connectDeviceService(options) {
118689
119816
  thisDevice: async () => (await client.request("device.info", {})).device,
118690
119817
  devices: async () => (await client.request("devices.list", {})).devices,
118691
119818
  sessions: newestRowsListing(client),
118692
- attach: (device, sessionId) => openAttach(client, device, sessionId),
119819
+ attach: async (device, sessionId) => {
119820
+ const attached = await openAttach(client, device, sessionId);
119821
+ return carriesWakeMark ? attached : { ...attached, command: (rpc) => attached.command(rpc) };
119822
+ },
118693
119823
  endpointCommand: async (device, rpc, options) => {
118694
119824
  let endpoint;
118695
119825
  try {
@@ -118698,12 +119828,23 @@ async function connectDeviceService(options) {
118698
119828
  throw markNotSent(error);
118699
119829
  }
118700
119830
  if (endpoint === undefined)
118701
- throw new LocalApiError("unsupported", "the device lists no engine endpoint", { not_sent: true });
119831
+ throw new NotSentError("unsupported", "the device lists no engine endpoint");
118702
119832
  return await sendToEndpoint(client, device, endpoint, rpc, options?.locate === true);
118703
119833
  },
118704
119834
  close: () => client.close(),
118705
119835
  closed: client.closed,
118706
- locate: (device, engineId) => client.request("session.locate", { device, engine_id: engineId })
119836
+ locate: (device, engineId, options) => client.request("session.locate", {
119837
+ device,
119838
+ engine_id: engineId,
119839
+ ...options?.single === true && takesSingleLocate ? { single: true } : {}
119840
+ }),
119841
+ wakeCommand: async (device, durableId, rpc) => {
119842
+ if (!carriesWakeMark)
119843
+ throw new NotSentError("unsupported", "this device service does not carry the wake target");
119844
+ return await followDelegatedCommand(client, device, (commandId) => client.commandTo({ wake: { device, durable_id: durableId } }, rpc, commandId).catch((error) => {
119845
+ throw error instanceof LocalApiError && error.command_id === undefined ? markNotSent(error) : error;
119846
+ }));
119847
+ }
118707
119848
  };
118708
119849
  }
118709
119850
  // packages/device-service-core/src/bootstrap.ts
@@ -118766,6 +119907,66 @@ var forgetDeviceService = async (options) => {
118766
119907
  }
118767
119908
  return "forgotten";
118768
119909
  };
119910
+ // packages/device-service-core/src/cold-wake/service-table.ts
119911
+ var SERVICE_TABLE_ENV = "OMO_RELAYD_SERVICES";
119912
+
119913
+ // packages/device-service-core/src/cold-wake/darwin.ts
119914
+ var TABLE_KEY = `EnvironmentVariables.${SERVICE_TABLE_ENV}`;
119915
+ // packages/device-service-core/src/release/windows-dacl.ts
119916
+ import { spawn as spawn7 } from "child_process";
119917
+ var SID_TOKEN_SCRIPT = String.raw`
119918
+ $ErrorActionPreference = 'Stop'
119919
+ (New-Object System.Security.AccessControl.RawSecurityDescriptor("O:$env:LA_SID")).GetSddlForm('Owner')
119920
+ `;
119921
+ var runPowerShell2 = async (script, env) => {
119922
+ const encoded = Buffer.from(script, "utf16le").toString("base64");
119923
+ const proc = spawn7("powershell.exe", ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-EncodedCommand", encoded], { env: { ...process.env, ...env }, stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
119924
+ const chunks = [];
119925
+ const errChunks = [];
119926
+ proc.stdout.on("data", (chunk) => chunks.push(chunk));
119927
+ proc.stderr.on("data", (chunk) => errChunks.push(chunk));
119928
+ const code = await new Promise((resolve, reject) => {
119929
+ proc.once("error", reject);
119930
+ proc.once("close", (exitCode) => resolve(exitCode ?? -1));
119931
+ });
119932
+ return { code, out: Buffer.concat(chunks).toString("utf8"), err: Buffer.concat(errChunks).toString("utf8") };
119933
+ };
119934
+ var firstErrorLine = (err) => {
119935
+ const line = (err ?? "").split(/\r?\n/).find((text) => text.trim() !== "" && !text.startsWith("#< CLIXML"))?.trim() ?? "";
119936
+ return line === "" ? "" : `: ${line.slice(0, 300)}`;
119937
+ };
119938
+ var userSidToken = async (userSid, run = runPowerShell2) => {
119939
+ const { code, out } = await run(SID_TOKEN_SCRIPT, { LA_SID: userSid });
119940
+ const match = code === 0 ? /^O:(S-1-\d+(?:-\d+)+|[A-Z]{2})$/.exec(out.trim()) : null;
119941
+ return match?.[1];
119942
+ };
119943
+ var aliasedDaclVerdict = (dacl, userSid, kind, userAlias) => {
119944
+ const asSid = (token) => userAlias !== undefined && token === userAlias ? userSid : token;
119945
+ return exactDaclVerdict({ ...dacl, owner: asSid(dacl.owner), aces: dacl.aces.map((ace) => ({ ...ace, sid: asSid(ace.sid) })) }, userSid, kind);
119946
+ };
119947
+ var applyExactDacl2 = async (path, userSid, kind, run = runPowerShell2) => {
119948
+ const { code, err } = await run(APPLY_DACL_SCRIPT, { LA_PATH: path, LA_SID: userSid, LA_KIND: kind });
119949
+ if (code !== 0)
119950
+ throw new LocalApiError("insecure_state_dir", `the exact DACL could not be applied${firstErrorLine(err)}`);
119951
+ };
119952
+ var verifyExactDacl2 = async (path, userSid, kind, run = runPowerShell2) => {
119953
+ let dacl;
119954
+ try {
119955
+ dacl = await describeDacl(path, run);
119956
+ } catch (error) {
119957
+ if (error instanceof LocalApiError)
119958
+ return false;
119959
+ throw error;
119960
+ }
119961
+ return aliasedDaclVerdict(dacl, userSid, kind, await userSidToken(userSid, run));
119962
+ };
119963
+ var windowsSecureFile2 = (userSid, run = runPowerShell2) => async (path, kind) => {
119964
+ const target = kind === "dir" ? "dir" : "file";
119965
+ await applyExactDacl2(path, userSid, target, run);
119966
+ if (!await verifyExactDacl2(path, userSid, target, run))
119967
+ throw new LocalApiError("insecure_state_dir", "the DACL is not exactly one ACE for the user");
119968
+ };
119969
+
118769
119970
  // packages/device-service-core/src/release/release-assets.ts
118770
119971
  var MANIFEST = "latest.json";
118771
119972
  var CHECKSUMS_MAX_BYTES = 64 * 1024;
@@ -118831,13 +120032,13 @@ var parseReleaseKeySet = (value) => {
118831
120032
  };
118832
120033
  var DEVICE_SERVICE_RELEASE_KEYS = parseReleaseKeySet(release_key_default);
118833
120034
  // packages/device-service-core/src/release/acquire.ts
118834
- var platformSecure = process.platform === "win32" ? async (path, kind) => windowsSecureFile(await currentUserSid())(path, kind) : posixSecureFile;
120035
+ var platformSecure = process.platform === "win32" ? async (path, kind) => windowsSecureFile2(await currentUserSid())(path, kind) : posixSecureFile;
118835
120036
  // packages/device-service-core/src/registrant.ts
118836
120037
  var NONE2 = Symbol("none registered");
118837
120038
  // packages/omo-native/package.json
118838
120039
  var package_default4 = {
118839
120040
  name: "omo-ai",
118840
- version: "5.1.71",
120041
+ version: "5.1.73",
118841
120042
  type: "module",
118842
120043
  description: "OmO Native - the standalone omo command with the OMO extension built in: bun add -g omo-ai",
118843
120044
  bin: {
@@ -118854,7 +120055,7 @@ var package_default4 = {
118854
120055
  postinstall: "node bin/senpi-patch.mjs"
118855
120056
  },
118856
120057
  dependencies: {
118857
- "@code-yeongyu/senpi": "2026.11.15"
120058
+ "@code-yeongyu/senpi": "2026.11.15-2"
118858
120059
  },
118859
120060
  repository: {
118860
120061
  type: "git",
@@ -118939,6 +120140,825 @@ function cliDeviceServiceHandoff(options) {
118939
120140
  };
118940
120141
  }
118941
120142
 
120143
+ // packages/memory-core/src/journal/fsync.ts
120144
+ var SKIPPABLE_SYNC_CODES = new Set(["ENOENT", "EISDIR", "EPERM", "EACCES", "EINVAL"]);
120145
+
120146
+ // packages/memory-core/src/sync/crypto/vendor/sync-format/keys.ts
120147
+ var hexBytes = (hex) => {
120148
+ const pairs = hex.match(/../g);
120149
+ return Uint8Array.from((pairs ?? []).map((pair) => Number.parseInt(pair, 16)));
120150
+ };
120151
+ var ED25519_PKCS8_PREFIX = hexBytes("302e020100300506032b657004220420");
120152
+ var ED25519_SPKI_PREFIX = hexBytes("302a300506032b6570032100");
120153
+ // packages/memory-core/src/sync/crypto/anchor.ts
120154
+ var anchors = new WeakSet;
120155
+ var candidates = new WeakSet;
120156
+ var bootstraps = new WeakSet;
120157
+
120158
+ // packages/memory-core/src/sync/crypto/strict-ed25519/strict-ed25519.ts
120159
+ var P2 = (1n << 255n) - 19n;
120160
+ var L2 = (1n << 252n) + 27742317777372353535851937790883648493n;
120161
+ var mod2 = (n) => {
120162
+ const r = n % P2;
120163
+ return r < 0n ? r + P2 : r;
120164
+ };
120165
+ var power2 = (base, exponent) => {
120166
+ let result = 1n;
120167
+ let b = mod2(base);
120168
+ for (let n = exponent;n > 0n; n >>= 1n) {
120169
+ if (n & 1n)
120170
+ result = mod2(result * b);
120171
+ b = mod2(b * b);
120172
+ }
120173
+ return result;
120174
+ };
120175
+ var D2 = mod2(-121665n * power2(121666n, P2 - 2n));
120176
+ var SQRT_MINUS_ONE2 = power2(2n, (P2 - 1n) / 4n);
120177
+ var keyCache2 = new Map;
120178
+
120179
+ // packages/memory-core/src/sync/crypto/trust-pin.ts
120180
+ var SOURCES = new Set(["pairing", "recovery", "creator"]);
120181
+
120182
+ // packages/omo-senpi/src/components/thread/errors.ts
120183
+ var THREAD_ERROR_CODES = [
120184
+ "invalid_arguments",
120185
+ "caller_context_missing",
120186
+ "not_found",
120187
+ "reply_target_mismatch",
120188
+ "ambiguous_target",
120189
+ "scope_denied",
120190
+ "name_conflict",
120191
+ "not_resumable",
120192
+ "orphaned",
120193
+ "foreign_live_owner",
120194
+ "no_active_turn",
120195
+ "turn_conflict",
120196
+ "not_steerable",
120197
+ "message_too_large",
120198
+ "queue_full",
120199
+ "cursor_invalid",
120200
+ "cursor_stale",
120201
+ "idempotency_conflict",
120202
+ "idempotency_in_progress",
120203
+ "idempotency_uncertain",
120204
+ "approval_unavailable",
120205
+ "approval_route_locked",
120206
+ "partial_commit",
120207
+ "unsupported",
120208
+ "overloaded",
120209
+ "transport_closed",
120210
+ "host_unavailable",
120211
+ "internal_error",
120212
+ "model_not_found",
120213
+ "model_ambiguous",
120214
+ "thinking_level_unsupported",
120215
+ "loop_detected",
120216
+ "binding_conflict",
120217
+ "binding_mismatch",
120218
+ "binding_inactive",
120219
+ "stale_revision",
120220
+ "stale_token",
120221
+ "already_answered",
120222
+ "answer_in_progress",
120223
+ "device_offline",
120224
+ "relay_requires_paid_plan",
120225
+ "alias_taken"
120226
+ ];
120227
+ var CODE_SET = new Set(THREAD_ERROR_CODES);
120228
+
120229
+ // packages/omo-senpi/src/components/thread/remote/outcome.ts
120230
+ var READ_UNCERTAIN = {
120231
+ request_gone: "retry",
120232
+ no_receipt: "retry",
120233
+ engine_restarted: "retry",
120234
+ recipient_revoked: "retry",
120235
+ transport_expired: "retry",
120236
+ unconfirmed: "retry",
120237
+ lease_expired: "retry",
120238
+ cancelled: "retry",
120239
+ hand_restarted: "retry",
120240
+ result_expired: "retry",
120241
+ record_too_large: "too_large",
120242
+ result_undecodable: "retry"
120243
+ };
120244
+ var UNANSWERED = new Set([
120245
+ "closed",
120246
+ "protocol_violation",
120247
+ "internal",
120248
+ "read_failed",
120249
+ "request_timeout",
120250
+ "handshake_timeout",
120251
+ "attach_failed",
120252
+ "reply_lost",
120253
+ "host_not_answering",
120254
+ "peer_not_found",
120255
+ "engine_stale",
120256
+ ...Object.entries(READ_UNCERTAIN).filter(([, answer]) => answer === "retry").map(([reason]) => reason)
120257
+ ]);
120258
+
120259
+ // packages/omo-native/remote-attach.ts
120260
+ var MAX_LINE_CHARS = 64 * 1024 * 1024;
120261
+
120262
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/system/memory/metrics.mjs
120263
+ var Metrics = {
120264
+ assign: 0,
120265
+ create: 0,
120266
+ clone: 0,
120267
+ discard: 0,
120268
+ update: 0
120269
+ };
120270
+
120271
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/guard/guard.mjs
120272
+ function IsArray(value) {
120273
+ return Array.isArray(value);
120274
+ }
120275
+ function IsBigInt(value) {
120276
+ return IsEqual(typeof value, "bigint");
120277
+ }
120278
+ function IsBoolean(value) {
120279
+ return IsEqual(typeof value, "boolean");
120280
+ }
120281
+ function IsNull(value) {
120282
+ return IsEqual(value, null);
120283
+ }
120284
+ function IsNumber(value) {
120285
+ return Number.isFinite(value);
120286
+ }
120287
+ function IsObject(value) {
120288
+ return IsEqual(typeof value, "object") && !IsNull(value);
120289
+ }
120290
+ function IsString(value) {
120291
+ return IsEqual(typeof value, "string");
120292
+ }
120293
+ function IsEqual(left, right) {
120294
+ return left === right;
120295
+ }
120296
+ function IsClassInstance(value) {
120297
+ if (!IsObject(value))
120298
+ return false;
120299
+ const proto = globalThis.Object.getPrototypeOf(value);
120300
+ if (IsNull(proto))
120301
+ return false;
120302
+ return IsEqual(typeof proto.constructor, "function") && !(IsEqual(proto.constructor, globalThis.Object) || IsEqual(proto.constructor.name, "Object"));
120303
+ }
120304
+ function IsUnsafePropertyKey(key) {
120305
+ return IsEqual(key, "__proto__") || IsEqual(key, "constructor") || IsEqual(key, "prototype");
120306
+ }
120307
+ function HasPropertyKey(value, key) {
120308
+ return IsUnsafePropertyKey(key) ? Object.prototype.hasOwnProperty.call(value, key) : (key in value);
120309
+ }
120310
+ function Keys(value) {
120311
+ return Object.getOwnPropertyNames(value);
120312
+ }
120313
+ function Symbols(value) {
120314
+ return Object.getOwnPropertySymbols(value);
120315
+ }
120316
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/guard/globals.mjs
120317
+ function IsTypeArray(value) {
120318
+ return globalThis.ArrayBuffer.isView(value);
120319
+ }
120320
+ function IsRegExp(value) {
120321
+ return value instanceof globalThis.RegExp;
120322
+ }
120323
+ function IsSet(value) {
120324
+ return value instanceof globalThis.Set;
120325
+ }
120326
+ function IsMap(value) {
120327
+ return value instanceof globalThis.Map;
120328
+ }
120329
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/system/settings/settings.mjs
120330
+ var settings2 = {
120331
+ immutableTypes: false,
120332
+ maxErrors: 8,
120333
+ maxParseErrors: 1,
120334
+ maxInstantiationCount: 128,
120335
+ useAcceleration: true,
120336
+ exactOptionalPropertyTypes: false,
120337
+ enumerableKind: false,
120338
+ correctiveParse: false,
120339
+ unionPrioritySort: true
120340
+ };
120341
+ function Get() {
120342
+ return settings2;
120343
+ }
120344
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/system/memory/freeze.mjs
120345
+ function Freeze(value) {
120346
+ return Get().immutableTypes ? Object.freeze(value) : value;
120347
+ }
120348
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/system/memory/clone.mjs
120349
+ function FromClassInstance(value) {
120350
+ return value;
120351
+ }
120352
+ function IsSchemaObject(value) {
120353
+ return HasPropertyKey(value, "~kind") || HasPropertyKey(value, "~unsafe");
120354
+ }
120355
+ function FromSchemaObject(value) {
120356
+ const result = {};
120357
+ for (const key of Keys(value)) {
120358
+ if (IsUnsafePropertyKey(key))
120359
+ continue;
120360
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
120361
+ descriptor.value = FromValue(descriptor.value);
120362
+ if (IsEqual(descriptor.enumerable, true)) {
120363
+ result[key] = descriptor.value;
120364
+ } else {
120365
+ Object.defineProperty(result, key, descriptor);
120366
+ }
120367
+ }
120368
+ return result;
120369
+ }
120370
+ function FromPlainObject(value) {
120371
+ const result = {};
120372
+ for (const key of Keys(value)) {
120373
+ if (IsUnsafePropertyKey(key))
120374
+ continue;
120375
+ result[key] = FromValue(value[key]);
120376
+ }
120377
+ for (const key of Symbols(value)) {
120378
+ result[key] = FromValue(value[key]);
120379
+ }
120380
+ return result;
120381
+ }
120382
+ function FromObject(value) {
120383
+ return IsClassInstance(value) ? FromClassInstance(value) : IsSchemaObject(value) ? FromSchemaObject(value) : FromPlainObject(value);
120384
+ }
120385
+ function FromArray(value) {
120386
+ return value.map((element) => FromValue(element));
120387
+ }
120388
+ function FromTypedArray(value) {
120389
+ return value.slice();
120390
+ }
120391
+ function FromRegExp(value) {
120392
+ return new RegExp(value.source, value.flags);
120393
+ }
120394
+ function FromMap(value) {
120395
+ return new Map(FromValue([...value.entries()]));
120396
+ }
120397
+ function FromSet(value) {
120398
+ return new Set(FromValue([...value.values()]));
120399
+ }
120400
+ function FromValue(value) {
120401
+ return IsTypeArray(value) ? FromTypedArray(value) : IsRegExp(value) ? FromRegExp(value) : IsMap(value) ? FromMap(value) : IsSet(value) ? FromSet(value) : IsArray(value) ? FromArray(value) : IsObject(value) ? FromObject(value) : value;
120402
+ }
120403
+ function Clone(value) {
120404
+ Metrics.clone += 1;
120405
+ return FromValue(value);
120406
+ }
120407
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/system/memory/create.mjs
120408
+ function MergeHidden(left, right) {
120409
+ for (const key of Object.keys(right)) {
120410
+ Object.defineProperty(left, key, {
120411
+ configurable: true,
120412
+ writable: true,
120413
+ enumerable: false,
120414
+ value: right[key]
120415
+ });
120416
+ }
120417
+ return left;
120418
+ }
120419
+ function Merge(left, right) {
120420
+ return { ...left, ...right };
120421
+ }
120422
+ function Create(hidden, enumerable, options = {}) {
120423
+ Metrics.create += 1;
120424
+ const withOptions = Merge(enumerable, options);
120425
+ const withHidden = Get().enumerableKind ? Merge(withOptions, hidden) : MergeHidden(withOptions, hidden);
120426
+ return Freeze(withHidden);
120427
+ }
120428
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/system/memory/update.mjs
120429
+ function Update(current, hidden, enumerable) {
120430
+ Metrics.update += 1;
120431
+ const settings = Get();
120432
+ const result = Clone(current);
120433
+ for (const key of Object.keys(hidden)) {
120434
+ Object.defineProperty(result, key, {
120435
+ configurable: true,
120436
+ writable: true,
120437
+ enumerable: settings.enumerableKind,
120438
+ value: hidden[key]
120439
+ });
120440
+ }
120441
+ for (const key of Object.keys(enumerable)) {
120442
+ Object.defineProperty(result, key, {
120443
+ configurable: true,
120444
+ enumerable: true,
120445
+ writable: true,
120446
+ value: enumerable[key]
120447
+ });
120448
+ }
120449
+ return Freeze(result);
120450
+ }
120451
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/engine/optional/instantiate_add.mjs
120452
+ function AddOptionalOperation(type) {
120453
+ return Update(type, { "~optional": true }, {});
120454
+ }
120455
+ function AddOptionalAction(type, options) {
120456
+ const result = Update(AddOptionalOperation(type), {}, options);
120457
+ return result;
120458
+ }
120459
+
120460
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/action/_add_optional.mjs
120461
+ function AddOptional(type, options = {}) {
120462
+ return AddOptionalAction(type, options);
120463
+ }
120464
+
120465
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/types/_optional.mjs
120466
+ function Optional(type) {
120467
+ return AddOptional(type);
120468
+ }
120469
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/system/hashing/hash.mjs
120470
+ var ByteMarker;
120471
+ (function(ByteMarker) {
120472
+ ByteMarker[ByteMarker["Array"] = 0] = "Array";
120473
+ ByteMarker[ByteMarker["BigInt"] = 1] = "BigInt";
120474
+ ByteMarker[ByteMarker["Boolean"] = 2] = "Boolean";
120475
+ ByteMarker[ByteMarker["Date"] = 3] = "Date";
120476
+ ByteMarker[ByteMarker["Constructor"] = 4] = "Constructor";
120477
+ ByteMarker[ByteMarker["Function"] = 5] = "Function";
120478
+ ByteMarker[ByteMarker["Null"] = 6] = "Null";
120479
+ ByteMarker[ByteMarker["Number"] = 7] = "Number";
120480
+ ByteMarker[ByteMarker["Object"] = 8] = "Object";
120481
+ ByteMarker[ByteMarker["RegExp"] = 9] = "RegExp";
120482
+ ByteMarker[ByteMarker["String"] = 10] = "String";
120483
+ ByteMarker[ByteMarker["Symbol"] = 11] = "Symbol";
120484
+ ByteMarker[ByteMarker["TypeArray"] = 12] = "TypeArray";
120485
+ ByteMarker[ByteMarker["Undefined"] = 13] = "Undefined";
120486
+ })(ByteMarker || (ByteMarker = {}));
120487
+ var Accumulator = BigInt("14695981039346656037");
120488
+ var [Prime, Size] = [BigInt("1099511628211"), BigInt("18446744073709551616")];
120489
+ var Bytes = Array.from({ length: 256 }).map((_, i) => BigInt(i));
120490
+ var F64 = new Float64Array(1);
120491
+ var F64In = new DataView(F64.buffer);
120492
+ var F64Out = new Uint8Array(F64.buffer);
120493
+ var encoder4 = new TextEncoder;
120494
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/types/boolean.mjs
120495
+ function Boolean2(options) {
120496
+ return Create({ "~kind": "Boolean" }, { type: "boolean" }, options);
120497
+ }
120498
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/types/integer.mjs
120499
+ var IntegerPattern = "-?(?:0|[1-9][0-9]*)";
120500
+ function Integer(options) {
120501
+ return Create({ "~kind": "Integer" }, { type: "integer" }, options);
120502
+ }
120503
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/types/literal.mjs
120504
+ class InvalidLiteralValue extends Error {
120505
+ constructor(value) {
120506
+ super(`Invalid Literal value`);
120507
+ Object.defineProperty(this, "cause", {
120508
+ value: { value },
120509
+ writable: false,
120510
+ configurable: false,
120511
+ enumerable: false
120512
+ });
120513
+ }
120514
+ }
120515
+ function LiteralTypeName(value) {
120516
+ return IsBigInt(value) ? "bigint" : IsBoolean(value) ? "boolean" : IsNumber(value) ? "number" : IsString(value) ? "string" : (() => {
120517
+ throw new InvalidLiteralValue(value);
120518
+ })();
120519
+ }
120520
+ function Literal(value, options) {
120521
+ return Create({ "~kind": "Literal" }, { type: LiteralTypeName(value), const: value }, options);
120522
+ }
120523
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/types/number.mjs
120524
+ var NumberPattern = "-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?";
120525
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/types/string.mjs
120526
+ var StringPattern = ".*";
120527
+ function String2(options) {
120528
+ return Create({ "~kind": "String" }, { type: "string" }, options);
120529
+ }
120530
+
120531
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/types/union.mjs
120532
+ function Union(anyOf, options = {}) {
120533
+ return Create({ "~kind": "Union" }, { anyOf }, options);
120534
+ }
120535
+
120536
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/types/record.mjs
120537
+ var IntegerKey = `^${IntegerPattern}$`;
120538
+ var NumberKey = `^${NumberPattern}$`;
120539
+ var StringKey = `^${StringPattern}$`;
120540
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/script/token/internal/char.mjs
120541
+ function Range(start, end) {
120542
+ return Array.from({ length: end - start + 1 }, (_, i) => String.fromCharCode(start + i));
120543
+ }
120544
+ var Alpha = [
120545
+ ...Range(97, 122),
120546
+ ...Range(65, 90)
120547
+ ];
120548
+ var Zero = "0";
120549
+ var NonZero = Range(49, 57);
120550
+ var Digit = [Zero, ...NonZero];
120551
+ var UnderScore = "_";
120552
+ var DollarSign = "$";
120553
+
120554
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/script/token/unsigned_integer.mjs
120555
+ var AllowedDigits = [...Digit, UnderScore];
120556
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/script/token/ident.mjs
120557
+ var Initial = [...Alpha, UnderScore, DollarSign];
120558
+ var Remaining = [...Initial, ...Digit];
120559
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/script/token/unsigned_number.mjs
120560
+ var AllowedDigits2 = [...Digit, UnderScore];
120561
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/engine/helpers/keys.mjs
120562
+ var integerKeyPattern = new RegExp("^(?:0|[1-9][0-9]*)$");
120563
+
120564
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/engine/indexed/from_object.mjs
120565
+ var NumericKeyPattern = new RegExp(IntegerKey);
120566
+ // packages/omo-senpi/src/components/thread/gateway/bindings.ts
120567
+ var BINDING_MAX_TTL_SECONDS = 366 * 24 * 60 * 60;
120568
+ var OUTBOX_RETENTION_MS = 30 * 24 * 60 * 60 * 1000;
120569
+ var RELAY_TEXT_MAX_BYTES = 32768;
120570
+
120571
+ // packages/omo-senpi/src/components/thread/contracts/fields.ts
120572
+ var THREAD_MESSAGE_MAX_BYTES = 32768;
120573
+ var THREAD_SUMMARY_MAX_LENGTH = 200;
120574
+ var ThreadAddress = String2({
120575
+ description: "Recipient thread id or unique name as returned by thread_list; a name shared by several threads returns ambiguous_target with candidates."
120576
+ });
120577
+ var AllScope = Optional(Boolean2({
120578
+ description: "Address threads in every workspace on this machine instead of only the caller's workspace; left unset, an exact id from another workspace returns scope_denied."
120579
+ }));
120580
+ var IdempotencyKey = Optional(String2({
120581
+ description: "Caller-chosen key that makes a retried call return the earlier result instead of repeating the side effect; reusing the key with different arguments returns idempotency_conflict."
120582
+ }));
120583
+ var ExpectedTurnId = Optional(String2({
120584
+ description: "Turn id the steer applies to; required with delivery steer, and a changed active turn returns turn_conflict with the message held undelivered."
120585
+ }));
120586
+ var Summary = Optional(String2({
120587
+ maxLength: THREAD_SUMMARY_MAX_LENGTH,
120588
+ description: "One-line preview shown to the caller when the completion notice arrives."
120589
+ }));
120590
+ var Message2 = String2({
120591
+ maxLength: THREAD_MESSAGE_MAX_BYTES,
120592
+ description: `Instruction to deliver to the target thread; longer than ${THREAD_MESSAGE_MAX_BYTES} UTF-8 bytes returns message_too_large.`
120593
+ });
120594
+ var BindingId = String2({
120595
+ minLength: 1,
120596
+ description: "Binding id as returned by thread_bind or thread_bindings."
120597
+ });
120598
+ var ExpectedRevision = Integer({
120599
+ minimum: 1,
120600
+ description: "Revision the caller last saw for this binding; a binding that moved since returns stale_revision."
120601
+ });
120602
+ var RelayText = String2({
120603
+ description: `Text relayed to or from the external thread; longer than ${RELAY_TEXT_MAX_BYTES} UTF-8 bytes returns message_too_large.`
120604
+ });
120605
+ var ThreadDeliveryMode = Union([Literal("auto"), Literal("steer"), Literal("follow_up")], {
120606
+ description: "auto steers the running turn when one is active and starts a new turn otherwise; steer requires expected_turn_id and becomes turn_conflict when the active turn changed; follow_up queues the message behind the running turn."
120607
+ });
120608
+
120609
+ // packages/omo-native/remote-session-args.ts
120610
+ var SESSION_VERBS = ["open", "send", "model", "interrupt", "close"];
120611
+
120612
+ // packages/omo-senpi/src/components/thread/control/port.ts
120613
+ var REFUSAL = Symbol.for("omo.thread.control.refusal");
120614
+
120615
+ // packages/omo-senpi/src/components/thread/control/close-ladder.ts
120616
+ var SESSION_GONE = new Set([
120617
+ "unknown_session",
120618
+ "session_identity_mismatch",
120619
+ "session_not_attached",
120620
+ "not_attached"
120621
+ ]);
120622
+
120623
+ // packages/omo-senpi/src/components/thread/thread-link.ts
120624
+ var THREAD_LINK_SCHEME = "omo-thread";
120625
+ var PREFIX = `${THREAD_LINK_SCHEME}://v1/`;
120626
+
120627
+ // packages/omo-senpi/src/components/thread/remote/address-book.ts
120628
+ var REMOTE_NOT_SET_UP = new Set(["not_configured", "disabled", "signed_out", "sign_in_required"]);
120629
+
120630
+ // packages/omo-senpi/src/components/thread/session-facts.ts
120631
+ var SESSION_FACTS_WINDOW_BYTES = 64 * 1024;
120632
+ var SESSION_FACTS_LAST_LINE_MAX_BYTES = SESSION_FACTS_WINDOW_BYTES * 4;
120633
+
120634
+ // packages/omo-senpi/src/components/thread/metadata.ts
120635
+ var THREAD_TOOL_EXPOSURE = "eval";
120636
+ var ROUTE_TO_TASK = "; to spawn a child task instead, use task.";
120637
+ var THREAD_TOOL_METADATA = [
120638
+ {
120639
+ name: "thread_create",
120640
+ label: "Create session",
120641
+ description: "Starts a fresh agent session that runs alongside this one, for when the user wants a second session working in parallel" + ROUTE_TO_TASK,
120642
+ exposure: THREAD_TOOL_EXPOSURE
120643
+ },
120644
+ {
120645
+ name: "thread_list",
120646
+ label: "List sessions",
120647
+ description: "Shows every addressable session on this device and the account's other devices with its id, name, status and device, plus the account's devices, for when the user needs a valid target address before acting on a session" + ROUTE_TO_TASK,
120648
+ exposure: THREAD_TOOL_EXPOSURE
120649
+ },
120650
+ {
120651
+ name: "thread_read",
120652
+ label: "Read session",
120653
+ description: "Returns the transcript and latest output of another session, for when the user asks what another session said or produced" + ROUTE_TO_TASK,
120654
+ exposure: THREAD_TOOL_EXPOSURE
120655
+ },
120656
+ {
120657
+ name: "thread_send",
120658
+ label: "Send message to session",
120659
+ description: "Delivers a message into another session that is already running, for when the user wants to talk to that session mid-task; its reply comes back through thread_read, and a bound chat thread's replies through thread_report and thread_answer" + ROUTE_TO_TASK,
120660
+ exposure: THREAD_TOOL_EXPOSURE
120661
+ },
120662
+ {
120663
+ name: "thread_interrupt",
120664
+ label: "Interrupt session turn",
120665
+ description: "Stops the turn running in another session, for when the user wants to halt a session that is going down the wrong path" + ROUTE_TO_TASK,
120666
+ exposure: THREAD_TOOL_EXPOSURE
120667
+ },
120668
+ {
120669
+ name: "thread_close",
120670
+ label: "Close session",
120671
+ description: "Closes another session on this device or on another of the account's devices, for when the user is done with that session and wants it shut down" + ROUTE_TO_TASK,
120672
+ exposure: THREAD_TOOL_EXPOSURE
120673
+ },
120674
+ {
120675
+ name: "thread_handoff",
120676
+ label: "Hand off session",
120677
+ description: "Moves the current request to an old session that has the context, for when the user says to hand this off or reopen that earlier conversation" + ROUTE_TO_TASK,
120678
+ exposure: THREAD_TOOL_EXPOSURE
120679
+ },
120680
+ {
120681
+ name: "thread_rename",
120682
+ label: "Rename session",
120683
+ description: "Changes the label a session is listed under, for when the user asks to call a session something clearer",
120684
+ exposure: THREAD_TOOL_EXPOSURE
120685
+ },
120686
+ {
120687
+ name: "thread_set_model",
120688
+ label: "Switch session model",
120689
+ description: "Moves a session onto a different model, for when the user asks to switch that session to another model or a cheaper one",
120690
+ exposure: THREAD_TOOL_EXPOSURE
120691
+ },
120692
+ {
120693
+ name: "thread_set_reasoning",
120694
+ label: "Set session reasoning level",
120695
+ description: "Sets how much reasoning a session applies, for when the user asks to raise or lower the thinking effort of a session",
120696
+ exposure: THREAD_TOOL_EXPOSURE
120697
+ },
120698
+ {
120699
+ name: "thread_bind",
120700
+ label: "Bind session to chat thread",
120701
+ description: "Attaches a session to an external chat thread on Discord, Telegram, Slack, Notion, Feishu, herdr or a custom connector, for when the user wants a chat conversation connected to a session",
120702
+ exposure: THREAD_TOOL_EXPOSURE
120703
+ },
120704
+ {
120705
+ name: "thread_unbind",
120706
+ label: "Unbind chat thread",
120707
+ description: "Detaches a session from its bound chat thread, for when the user wants that chat connection closed",
120708
+ exposure: THREAD_TOOL_EXPOSURE
120709
+ },
120710
+ {
120711
+ name: "thread_rebind",
120712
+ label: "Rebind chat thread",
120713
+ description: "Moves a bound chat thread over to another session, for when the user wants that chat served by a different session",
120714
+ exposure: THREAD_TOOL_EXPOSURE
120715
+ },
120716
+ {
120717
+ name: "thread_bindings",
120718
+ label: "List chat bindings",
120719
+ description: "Shows which chat threads are bound to which sessions with their revisions, for when the user needs a binding id or its revision",
120720
+ exposure: THREAD_TOOL_EXPOSURE
120721
+ },
120722
+ {
120723
+ name: "thread_report",
120724
+ label: "Report to chat thread",
120725
+ description: "Posts a milestone, result, question or completion from this session to its bound chat thread, for when the user wants progress relayed to that chat; replies flow back through thread_read, thread_report and thread_answer",
120726
+ exposure: THREAD_TOOL_EXPOSURE
120727
+ },
120728
+ {
120729
+ name: "thread_outbox",
120730
+ label: "Read chat outbox",
120731
+ description: "Returns the reports waiting for a bound chat thread with a cursor, for when a connector collects what sessions posted",
120732
+ exposure: THREAD_TOOL_EXPOSURE
120733
+ },
120734
+ {
120735
+ name: "thread_outbox_ack",
120736
+ label: "Acknowledge chat outbox",
120737
+ description: "Marks outbox rows up to a cursor as posted to the chat, for when a connector confirms delivery",
120738
+ exposure: THREAD_TOOL_EXPOSURE
120739
+ },
120740
+ {
120741
+ name: "thread_answer",
120742
+ label: "Answer relayed question",
120743
+ description: "Resolves a question a session relayed to a chat thread with the answer that arrived there, for when a connector hands back a chat user's reply",
120744
+ exposure: THREAD_TOOL_EXPOSURE
120745
+ }
120746
+ ];
120747
+
120748
+ // packages/omo-senpi/src/components/thread/control/relay-control.ts
120749
+ var IN_PROGRESS = new Set(["running", "compacting", "opening"]);
120750
+ var RUN_RECORDS = new Set([
120751
+ "agent_start",
120752
+ "turn_start",
120753
+ "message_start",
120754
+ "message_update",
120755
+ "message_end",
120756
+ "tool_execution_start",
120757
+ "tool_execution_update",
120758
+ "tool_execution_end",
120759
+ "turn_end",
120760
+ "agent_end"
120761
+ ]);
120762
+
120763
+ // packages/omo-senpi/src/components/thread/remote/session-state.ts
120764
+ var ACCESS_ENDED = new Set([
120765
+ "authorization_expired",
120766
+ "peer_revoked",
120767
+ "owner_transfer",
120768
+ "service_disabled"
120769
+ ]);
120770
+ var ACCESS_REFUSED = new Set([
120771
+ "unauthenticated",
120772
+ "forbidden",
120773
+ "owner_transfer",
120774
+ "signed_out",
120775
+ "service_disabled",
120776
+ "sign_in_required",
120777
+ "plan_required",
120778
+ "peer_not_found",
120779
+ "peer_not_session_client",
120780
+ "account_changed",
120781
+ "device_changed",
120782
+ "capability_missing",
120783
+ "engine_too_old"
120784
+ ]);
120785
+ var SESSION_LEFT = new Set(["session_closed", "session_replaced"]);
120786
+ var SESSION_GONE2 = new Set([
120787
+ "session_not_found",
120788
+ "unknown_session",
120789
+ "session_identity_mismatch"
120790
+ ]);
120791
+
120792
+ // packages/omo-senpi/src/components/thread/remote/device-service.ts
120793
+ var REFUSED_BEFORE_SENDING = new Set([
120794
+ "unauthenticated",
120795
+ "client_proof_invalid",
120796
+ "invalid_request",
120797
+ "unknown_type",
120798
+ "forbidden",
120799
+ "owner_transfer",
120800
+ "signed_out",
120801
+ "device_mismatch",
120802
+ "device_changed",
120803
+ "account_changed",
120804
+ "device_key_invalid",
120805
+ "service_disabled",
120806
+ "sign_in_required",
120807
+ "plan_required",
120808
+ "activation_pending",
120809
+ "authorization_stale",
120810
+ "peer_not_found",
120811
+ "peer_not_session_client",
120812
+ "session_not_found",
120813
+ "engine_too_old",
120814
+ "not_attached",
120815
+ "command_id_conflict",
120816
+ "message_too_long",
120817
+ "upload_incomplete",
120818
+ "malformed",
120819
+ "method_unclassified",
120820
+ "method_local_only",
120821
+ "host_not_answering",
120822
+ "unsupported"
120823
+ ]);
120824
+ var READ_ONLY_RECORDS = new Set(["get_state", "get_messages"]);
120825
+ var MARKED_RECORDS = new Set(["admit_external_message"]);
120826
+ var LOOKUP_NONE = new Set(["session_not_found", "peer_not_found", "peer_not_session_client"]);
120827
+
120828
+ // packages/omo-senpi/src/components/thread/gateway/constants.ts
120829
+ var QUEUED_TTL_MS = 24 * 60 * 60 * 1000;
120830
+ var ROOT_LIFETIME_MS = 7 * 24 * 60 * 60 * 1000;
120831
+ var TARGET_MAX_BYTES = 1024 * 1024;
120832
+ var GATEWAY_RECEIPT_RETENTION_MS = 30 * 24 * 60 * 60 * 1000;
120833
+ var DELIVERY_RETENTION_MS = 30 * 24 * 60 * 60 * 1000;
120834
+ var RETENTION_SWEEP_INTERVAL_MS = 60 * 60 * 1000;
120835
+
120836
+ // packages/omo-senpi/src/components/thread/gateway/session-args-schema.ts
120837
+ var TYPES = new Set(["object", "string", "number", "integer", "boolean", "array", "null"]);
120838
+ var ANNOTATIONS = new Set(["title", "description", "default", "examples"]);
120839
+ var COUNTS = ["minLength", "maxLength", "minItems", "maxItems"];
120840
+ var BOUNDS = ["minimum", "maximum", "exclusiveMinimum", "exclusiveMaximum"];
120841
+ var KEYWORDS = new Set([
120842
+ "type",
120843
+ "properties",
120844
+ "required",
120845
+ "additionalProperties",
120846
+ "enum",
120847
+ "const",
120848
+ "pattern",
120849
+ "items",
120850
+ "anyOf",
120851
+ ...COUNTS,
120852
+ ...BOUNDS,
120853
+ ...ANNOTATIONS
120854
+ ]);
120855
+
120856
+ // packages/omo-senpi/src/components/thread/remote/relay-transport.ts
120857
+ var ADMIT_UNSUPPORTED = new Set([
120858
+ "method_unclassified",
120859
+ "delegation_unclassified",
120860
+ "unknown_command",
120861
+ "engine_capability_missing",
120862
+ "unsupported_command",
120863
+ "method_unknown"
120864
+ ]);
120865
+ var WAITS = new Set(["wake", "hold", "approval"]);
120866
+
120867
+ // packages/omo-senpi/src/components/thread/remote/this-device.ts
120868
+ var known2 = new WeakMap;
120869
+
120870
+ // packages/omo-native/bin/lib/package-paths.js
120871
+ import { fileURLToPath as fileURLToPath9 } from "url";
120872
+ var packageRoot = fileURLToPath9(new URL("../..", import.meta.url));
120873
+
120874
+ // packages/omo-native/remote-session-verbs.ts
120875
+ var NO_SUCH_SESSION = new Set(["session_not_found", "unknown_session"]);
120876
+
120877
+ // packages/omo-native/remote-usage.ts
120878
+ var USAGE_HEAD = "usage: omo remote <command> [--json]";
120879
+ var USAGE_ENTRIES = [
120880
+ {
120881
+ verbs: ["status"],
120882
+ text: " status the device service's connection state"
120883
+ },
120884
+ {
120885
+ verbs: ["devices"],
120886
+ text: " devices the devices on this account"
120887
+ },
120888
+ {
120889
+ verbs: ["sessions"],
120890
+ text: ` sessions [--device D] [--project P] [--state running|idle|ended]
120891
+ sessions across the account's devices`
120892
+ },
120893
+ {
120894
+ verbs: ["enable", "disable"],
120895
+ text: " enable | disable turn remote sessions on or off for this device"
120896
+ },
120897
+ {
120898
+ verbs: ["control"],
120899
+ text: ` control [on|off] whether your other signed-in devices can view and command this
120900
+ device's sessions (on unless you turn it off)`
120901
+ },
120902
+ {
120903
+ verbs: ["wake"],
120904
+ text: ` wake [on|off|default] whether sessions on this device that are not running may be started
120905
+ by a message from your other signed-in devices; on unless turned off`
120906
+ },
120907
+ {
120908
+ verbs: ["bootstrap"],
120909
+ text: " bootstrap set up this device's service for your sign-in (every omo start runs it)"
120910
+ },
120911
+ {
120912
+ verbs: ["attach"],
120913
+ text: " attach <session> open a session in the terminal UI; also takes <device>/<session>"
120914
+ },
120915
+ {
120916
+ verbs: ["open"],
120917
+ text: ` open <device> [--project P] [--model provider/id] [--thinking LEVEL] [--permission-preset MODE]
120918
+ [--worktree [--branch B] [--base REF]] [--prompt TEXT [--steer|--follow-up]]
120919
+ start a session on another device; prints <device>/<session>; it runs
120920
+ in MODE (default: this device's own setting, else full-access), on the
120921
+ model and thinking level given (a model it cannot run opens nothing),
120922
+ in a new git worktree of P with --worktree, and is handed TEXT first`
120923
+ },
120924
+ {
120925
+ verbs: ["send"],
120926
+ text: ` send <session> <text> [--steer|--follow-up] [--no-wait]
120927
+ send a message and print the answer as it arrives (--steer: into the
120928
+ running turn; --no-wait: return once the session took it).
120929
+ Use the durable thread_id from open --json, or <device>/<session>.`
120930
+ },
120931
+ {
120932
+ verbs: ["model"],
120933
+ text: " model <session> <provider/id> switch the model; also takes <device>/<session>"
120934
+ },
120935
+ {
120936
+ verbs: ["interrupt"],
120937
+ text: " interrupt <session> stop the running turn; also takes <device>/<session>"
120938
+ },
120939
+ {
120940
+ verbs: ["close"],
120941
+ text: " close <session> end the session; also takes <device>/<session>"
120942
+ }
120943
+ ];
120944
+ var REMOTE_USAGE = [USAGE_HEAD, ...USAGE_ENTRIES.map((entry) => entry.text)].join(`
120945
+ `);
120946
+
120947
+ // packages/omo-native/remote-verbs.ts
120948
+ var VERBS = [
120949
+ "status",
120950
+ "devices",
120951
+ "sessions",
120952
+ "enable",
120953
+ "disable",
120954
+ "control",
120955
+ "wake",
120956
+ "bootstrap",
120957
+ ...SESSION_VERBS
120958
+ ];
120959
+ // packages/omo-native/remote-entry.ts
120960
+ var testSkipKey = Symbol.for("omo.test.skipRemoteLoginSetup");
120961
+
118942
120962
  // packages/omo-native/service-auth-command.ts
118943
120963
  var cliServiceAuthHooks = {
118944
120964
  deviceService: (api) => cliDeviceServiceHandoff({ api, log: (line) => process.stderr.write(`${line}
@@ -119148,8 +121168,8 @@ async function boulder(options) {
119148
121168
  return 0;
119149
121169
  }
119150
121170
  // packages/omo-opencode/src/cli/codex-ulw-loop.ts
119151
- import { spawn as spawn7 } from "child_process";
119152
- import { existsSync as existsSync70, readFileSync as readFileSync48, realpathSync as realpathSync14 } from "fs";
121171
+ import { spawn as spawn8 } from "child_process";
121172
+ import { existsSync as existsSync70, readFileSync as readFileSync49, realpathSync as realpathSync14 } from "fs";
119153
121173
  import { homedir as homedir37 } from "os";
119154
121174
  var ULW_LOOP_DELEGATION_SENTINEL = "OMO_ULW_LOOP_DELEGATED";
119155
121175
  function resolveCodexUlwLoopCommand(input = {}) {
@@ -119178,7 +121198,7 @@ async function codexUlwLoop(args) {
119178
121198
  return 1;
119179
121199
  }
119180
121200
  const { promise, resolve } = Promise.withResolvers();
119181
- const child = spawn7(command.executable, [...command.argsPrefix, ...args], {
121201
+ const child = spawn8(command.executable, [...command.argsPrefix, ...args], {
119182
121202
  stdio: "inherit",
119183
121203
  env: { ...process.env, [ULW_LOOP_DELEGATION_SENTINEL]: "1" }
119184
121204
  });
@@ -119199,7 +121219,7 @@ function resolveLegacyLocalOmoBin(env, homeDir, currentExecutablePaths) {
119199
121219
  }
119200
121220
  function isGeneratedRuntimeWrapper(candidate) {
119201
121221
  try {
119202
- return readFileSync48(candidate, "utf8").includes(RUNTIME_WRAPPER_MARKER);
121222
+ return readFileSync49(candidate, "utf8").includes(RUNTIME_WRAPPER_MARKER);
119203
121223
  } catch (error) {
119204
121224
  if (error instanceof Error)
119205
121225
  return false;
@@ -119634,7 +121654,7 @@ prunes.
119634
121654
 
119635
121655
  // packages/omo-opencode/src/cli/config-migrate.ts
119636
121656
  init_startup_migration();
119637
- import { posix as posix17 } from "path";
121657
+ import { posix as posix18 } from "path";
119638
121658
  function reports(result) {
119639
121659
  return result.results.map((entry) => ({
119640
121660
  diagnostics: entry.diagnostics,
@@ -119668,7 +121688,7 @@ function runConfigMigrate(options = {}) {
119668
121688
  dryRun: options.dryRun ?? false,
119669
121689
  environment,
119670
121690
  ...homeDir === undefined ? {} : { env: { HOME: homeDir }, homeDir },
119671
- pathOperations: posix17
121691
+ pathOperations: posix18
119672
121692
  });
119673
121693
  const report = reports(result);
119674
121694
  const response = {