witbitz-code 1.15.0__tar.gz → 1.15.3__tar.gz

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 (121) hide show
  1. {witbitz_code-1.15.0/src/witbitz_code.egg-info → witbitz_code-1.15.3}/PKG-INFO +1 -1
  2. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/pyproject.toml +1 -1
  3. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/__init__.py +1 -1
  4. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/connector.py +29 -17
  5. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/link.py +13 -6
  6. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/opencode_plugins/witbitz-browse-publisher.mjs +47 -5
  7. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/opencode_plugins/witbitz-browse-tree.mjs +5 -5
  8. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/ui.py +3 -2
  9. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/ui_static/app.css +1 -0
  10. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/ui_static/app.js +9 -1
  11. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/ui_static/index.html +5 -0
  12. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/wizard.py +0 -1
  13. {witbitz_code-1.15.0 → witbitz_code-1.15.3/src/witbitz_code.egg-info}/PKG-INFO +1 -1
  14. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_devicelink.py +5 -1
  15. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_remind.py +73 -2
  16. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_ui.py +1 -0
  17. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/LICENSE +0 -0
  18. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/README.md +0 -0
  19. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/setup.cfg +0 -0
  20. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/__main__.py +0 -0
  21. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/_js.py +0 -0
  22. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/account.py +0 -0
  23. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/app.py +0 -0
  24. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/asks.py +0 -0
  25. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/attachments.py +0 -0
  26. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/auto.py +0 -0
  27. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/auto_runner.py +0 -0
  28. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/browse.py +0 -0
  29. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/browsetree.py +0 -0
  30. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/cli.py +0 -0
  31. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/codekeys.py +0 -0
  32. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/codetools.py +0 -0
  33. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/compress.py +0 -0
  34. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/computers.py +0 -0
  35. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/confidential.py +0 -0
  36. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/confidential_models.json +0 -0
  37. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/devicelink.py +0 -0
  38. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/dirs.py +0 -0
  39. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/files.py +0 -0
  40. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/folders.py +0 -0
  41. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/gateway.py +0 -0
  42. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/icons/witbitz-code-wsl.ico +0 -0
  43. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/icons/witbitz-code.ico +0 -0
  44. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/images.py +0 -0
  45. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/keys.py +0 -0
  46. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/mkdir.py +0 -0
  47. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/models.py +0 -0
  48. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/net.py +0 -0
  49. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/offered_models.json +0 -0
  50. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/opencode_plugins/notes-init.md +0 -0
  51. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/opencode_plugins/witbitz-browse-cdp.mjs +0 -0
  52. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/opencode_plugins/witbitz-browse-local.mjs +0 -0
  53. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/opencode_plugins/witbitz-browser.js +0 -0
  54. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/opencode_plugins/witbitz-media-server.mjs +0 -0
  55. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/opencode_plugins/witbitz-notes.js +0 -0
  56. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/opencode_plugins/witbitz-progress.js +0 -0
  57. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/outputs.py +0 -0
  58. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/pair.py +0 -0
  59. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/pairings.py +0 -0
  60. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/payers.py +0 -0
  61. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/plugins.py +0 -0
  62. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/policy.py +0 -0
  63. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/ports.py +0 -0
  64. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/qr.py +0 -0
  65. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/receipt.py +0 -0
  66. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/relay.py +0 -0
  67. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/remind.py +0 -0
  68. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/seccheck.py +0 -0
  69. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/seen.py +0 -0
  70. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/selfupdate.py +0 -0
  71. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/tinfoil_read.py +0 -0
  72. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/tools_catalog.json +0 -0
  73. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/tools_probe.py +0 -0
  74. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/toolsetup.py +0 -0
  75. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/uitools.py +0 -0
  76. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/uninstall.py +0 -0
  77. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/winagent.py +0 -0
  78. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/winbg.py +0 -0
  79. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/winconsole.py +0 -0
  80. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code/wslstart.py +0 -0
  81. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code.egg-info/SOURCES.txt +0 -0
  82. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code.egg-info/dependency_links.txt +0 -0
  83. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code.egg-info/entry_points.txt +0 -0
  84. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code.egg-info/requires.txt +0 -0
  85. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/src/witbitz_code.egg-info/top_level.txt +0 -0
  86. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_asks.py +0 -0
  87. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_attachments.py +0 -0
  88. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_auto.py +0 -0
  89. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_browse.py +0 -0
  90. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_browsetree.py +0 -0
  91. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_cli.py +0 -0
  92. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_codekeys.py +0 -0
  93. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_codetools.py +0 -0
  94. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_confidential.py +0 -0
  95. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_connector_e2e.py +0 -0
  96. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_dirs.py +0 -0
  97. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_files.py +0 -0
  98. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_files_and_compress.py +0 -0
  99. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_folders.py +0 -0
  100. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_images.py +0 -0
  101. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_outputs.py +0 -0
  102. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_pair_flows.py +0 -0
  103. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_plugins.py +0 -0
  104. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_policy.py +0 -0
  105. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_ports.py +0 -0
  106. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_ports_win.py +0 -0
  107. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_registry.py +0 -0
  108. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_relay_codec.py +0 -0
  109. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_seccheck.py +0 -0
  110. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_selfupdate.py +0 -0
  111. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_setup.py +0 -0
  112. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_tools_probe.py +0 -0
  113. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_toolsetup.py +0 -0
  114. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_ui_page.py +0 -0
  115. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_uitools.py +0 -0
  116. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_uninstall.py +0 -0
  117. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_winagent.py +0 -0
  118. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_winbg.py +0 -0
  119. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_winconsole.py +0 -0
  120. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_windows_files.py +0 -0
  121. {witbitz_code-1.15.0 → witbitz_code-1.15.3}/tests/test_wslstart.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: witbitz-code
3
- Version: 1.15.0
3
+ Version: 1.15.3
4
4
  Summary: Reach OpenCode on this computer from the Witbitz Spaces Code section, through an end-to-end sealed relay.
5
5
  Author: Witbitz
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "witbitz-code"
7
- version = "1.15.0"
7
+ version = "1.15.3"
8
8
  description = "Reach OpenCode on this computer from the Witbitz Spaces Code section, through an end-to-end sealed relay."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -4,4 +4,4 @@ The Python implementation of tools/witbitz-code.mjs (docs/opencode-relay.md phas
4
4
  vectors and cross-implementation tests.
5
5
  """
6
6
 
7
- __version__ = "1.15.0"
7
+ __version__ = "1.15.3"
@@ -594,23 +594,35 @@ class PairingServer:
594
594
  """Each waiting approval: a tickle at one minute and a reminder at ten, to the device whose prompt led to it."""
595
595
  if not self._asks_live:
596
596
  return
597
- for directory in self._asks.directories():
598
- for ask, stage in self._remind.due(self._asks.list(directory)):
599
- self._remind.sent(ask["id"], stage)
600
- owner = await self._remind_owner(ask["sessionID"], directory)
601
- e = self._remind.who(owner) if owner else None
602
- if not e:
603
- continue
604
- n = seal_remind(e["key"], {"where": self.name, "what": detail_of(ask) or str(ask.get("permission") or ""),
605
- "computer": self.pairing.get("computerId") or "", "session": owner})
606
- try:
607
- r = await self._client.post(e["url"], json={"op": "coderemind", "grant": e["grant"], "n": n}, timeout=15)
608
- if r.status_code == 410:
609
- self._remind.note(owner, {}) # that device's address is gone: nothing more to it
610
- except asyncio.CancelledError:
611
- raise
612
- except Exception:
613
- pass # offline: the next stage tries again
597
+ # One `due` for every folder (state machines pass 8, K#1): `due` forgets the asks it is not shown, so asked per folder
598
+ # with asks waiting in two, each call forgot the other folder's and neither ever reminded.
599
+ dir_of: dict[str, str] = {}
600
+ everything: list[dict] = []
601
+ for d in self._asks.directories():
602
+ for a in self._asks.list(d):
603
+ if isinstance(a, dict) and isinstance(a.get("id"), str) and a["id"] not in dir_of:
604
+ dir_of[a["id"]] = d
605
+ everything.append(a)
606
+ for ask, stage in self._remind.due(everything):
607
+ directory = dir_of[ask["id"]]
608
+ # A stage is spent only by a tickle that went out (2026-11-08, docs/state-machines.md I16 / C#14): marked before the
609
+ # lookup and the POST, no device yet, a network error or a 5xx used it up. The Node connector does the same.
610
+ owner = await self._remind_owner(ask["sessionID"], directory)
611
+ e = self._remind.who(owner) if owner else None
612
+ if not e:
613
+ continue
614
+ n = seal_remind(e["key"], {"where": self.name, "what": detail_of(ask) or str(ask.get("permission") or ""),
615
+ "computer": self.pairing.get("computerId") or "", "session": owner})
616
+ try:
617
+ r = await self._client.post(e["url"], json={"op": "coderemind", "grant": e["grant"], "n": n}, timeout=15)
618
+ if 200 <= r.status_code < 300 or r.status_code == 410:
619
+ self._remind.sent(ask["id"], stage)
620
+ if r.status_code == 410:
621
+ self._remind.note(owner, {}) # that device's address is gone: nothing more to it
622
+ except asyncio.CancelledError:
623
+ raise
624
+ except Exception:
625
+ pass # offline: the same stage tries again at the next tick
614
626
 
615
627
  def _own_review(self, session: str, start: bool) -> None:
616
628
  if not self._payers:
@@ -68,9 +68,16 @@ def _node_base64(s: str) -> bytes:
68
68
  return _js.atob(body)
69
69
 
70
70
 
71
- async def pull_index_room(account: Any, origins: list[str], post_json: net.PostJson) -> dict | None:
71
+ # The account backup's home — every app's /space-config names it (vaultApi). The old same-origin `/api/backup` (Cloudflare KV)
72
+ # is retired (docs/TODO.md, 2026-11-07); its release tokens were the old home's own, so a token the app mints today never
73
+ # opened anything there.
74
+ VAULT_API = (os.environ.get("WITBITZ_VAULT_API") or "https://api.witbitz.chat/v1/vault").rstrip("/")
75
+
76
+
77
+ async def pull_index_room(account: Any, homes: list[str], post_json: net.PostJson) -> dict | None:
72
78
  """GAP-CLOSER: the link carried no index-room pointer → derive the backup location from the master, read the gated
73
- backup with the release token, and take its indexRoom {room, mk}. Tries each origin; the pointer or None."""
79
+ backup with the release token, and take its indexRoom {room, mk}. `homes`: the backup homes to ask (a vault API base
80
+ each, `<base>/release`); the pointer or None."""
74
81
  if not isinstance(account, dict) or not truthy(account.get("master")):
75
82
  return None
76
83
  try:
@@ -82,15 +89,15 @@ async def pull_index_room(account: Any, origins: list[str], post_json: net.PostJ
82
89
  loc = devicelink.derive_keys_from_secret(master)
83
90
  rel = account.get("rel")
84
91
  token = rel.get("token") if isinstance(rel, dict) else None
85
- for origin in origins:
92
+ for home in homes:
86
93
  blob = None
87
94
  if truthy(token):
88
95
  try:
89
- r = await post_json(f"{origin}/api/backup/release", {"token": token, "id": loc["id"]})
96
+ r = await post_json(f"{home}/release", {"token": token, "id": loc["id"]})
90
97
  if isinstance(r, dict) and truthy(r.get("ok")) and truthy(r.get("blob")):
91
98
  blob = r["blob"]
92
99
  except Exception:
93
- pass # try the next origin
100
+ pass # try the next home
94
101
  if not blob:
95
102
  continue
96
103
  try:
@@ -216,7 +223,7 @@ async def _link(life_ms, poll_s, origins, get_json, post_json, challenge, svg_pa
216
223
  out("witbitz-code: no index pointer in the link — recovering it from your account backup… ", end="")
217
224
  idx = None
218
225
  try:
219
- idx = await pull_index_room(account, origins, post_json)
226
+ idx = await pull_index_room(account, [VAULT_API], post_json)
220
227
  except Exception:
221
228
  pass
222
229
  if idx:
@@ -983,20 +983,27 @@ var closing = false;
983
983
  var first = { out: false, in: false, frame: false };
984
984
  var tellControl = async (path, body) => {
985
985
  try {
986
- await fetch(CTL + path, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) });
986
+ const r = await fetch(CTL + path, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) });
987
+ if (!r.ok) log("control", path, "refused:", r.status);
988
+ return r.ok;
987
989
  } catch (e) {
988
990
  log("control", path, "failed:", String(e).slice(0, 80));
991
+ return false;
989
992
  }
990
993
  };
991
994
  var said = null;
992
995
  var holderVid = null;
996
+ var statusAsk = 0;
997
+ var takeGen = 0;
993
998
  var tellTheViewerWhoHasTheControls = async (why) => {
994
999
  let st = null;
1000
+ const ask = ++statusAsk, gen = takeGen;
995
1001
  try {
996
1002
  st = await (await fetch(CTL + "/status")).json();
997
1003
  } catch {
998
1004
  return;
999
1005
  }
1006
+ if (ask !== statusAsk || gen !== takeGen) return;
1000
1007
  held = !!st.takeover;
1001
1008
  if (!held && cast && cast.incognito && cast.incognito()) closeIncognito("the controls lapsed");
1002
1009
  if (!held) holderVid = null;
@@ -1019,9 +1026,19 @@ var tellTheViewerWhoHasTheControls = async (why) => {
1019
1026
  st.web ? "on" : "off"
1020
1027
  );
1021
1028
  };
1029
+ var HOLDER_SILENT_MS = Number(process.env.WB_BROWSE_HOLDER_SILENT_MS) || 6e4;
1022
1030
  setInterval(() => {
1023
- if (peers > 1) tellTheViewerWhoHasTheControls("poll");
1031
+ const h = holderVid && castViewers.get(holderVid);
1032
+ if (h && h.beats && Date.now() - h.at > HOLDER_SILENT_MS) holderLeft("the holder went silent");
1033
+ if (peers > 1 || held || holderVid) tellTheViewerWhoHasTheControls("poll");
1024
1034
  }, 5e3);
1035
+ function holderLeft(why) {
1036
+ if (!holderVid) return;
1037
+ castViewers.delete(holderVid);
1038
+ assigned.delete(holderVid);
1039
+ log("take-over:", why, "\u2014 the enclave's grace decides");
1040
+ closeIncognito(why).finally(() => tellControl("/takeover", { on: false, gone: true }));
1041
+ }
1025
1042
  var expectHello = false;
1026
1043
  var strays = 0;
1027
1044
  var isHello = (b) => b.byteLength === 12 && b[0] === 82 && b[1] === 70 && b[2] === 66 && b[3] === 32 && b[11] === 10;
@@ -1386,9 +1403,16 @@ function connectRelay() {
1386
1403
  if (!c) return;
1387
1404
  if (c.wb === "takeover") {
1388
1405
  if (!c.on) await closeIncognito("the controls were given back");
1389
- await tellControl("/takeover", { on: !!c.on });
1406
+ takeGen++;
1407
+ if (!await tellControl("/takeover", { on: !!c.on })) {
1408
+ said = null;
1409
+ await tellTheViewerWhoHasTheControls("refused");
1410
+ return;
1411
+ }
1390
1412
  held = !!c.on;
1391
1413
  holderVid = c.on && typeof c.vid === "string" ? c.vid.slice(0, 64) : null;
1414
+ said = null;
1415
+ if (holderVid && castViewers.has(holderVid)) castViewers.get(holderVid).at = Date.now();
1392
1416
  log("take-over", c.on ? "ON \u2014 the agent's CDP session is being closed" : "released");
1393
1417
  if (cast) await cast.setController(c.on ? norm(c.view) || largestView() : null).catch(() => {
1394
1418
  });
@@ -1417,12 +1441,30 @@ function connectRelay() {
1417
1441
  const mode = await cast.setSiteMode(c.mode).catch(() => siteNow());
1418
1442
  log("site: the", mode, "site, for everyone");
1419
1443
  if (relay && relay.readyState === 1) relay.send(await sealCtl(key, { wb: "site", mode }));
1444
+ } else if (c.wb === "leave" && typeof c.vid === "string") {
1445
+ const v = c.vid.slice(0, 64);
1446
+ if (v === holderVid) holderLeft("the holder's page went away");
1447
+ else {
1448
+ castViewers.delete(v);
1449
+ assigned.delete(v);
1450
+ }
1451
+ } else if (c.wb === "hello" && c.hb && typeof c.vid === "string" && castViewers.has(c.vid.slice(0, 64))) {
1452
+ castViewers.get(c.vid.slice(0, 64)).at = Date.now();
1420
1453
  } else if (c.wb === "hello" && c.cast && typeof c.vid === "string" && CDP) {
1421
1454
  const known = castViewers.has(c.vid);
1422
1455
  const mine = held && c.driving && (!holderVid || c.vid.slice(0, 64) === holderVid);
1423
- castViewers.set(c.vid.slice(0, 64), { view: norm(c.view), at: Date.now(), driving: !!mine });
1424
- if (castViewers.size > 8) castViewers.delete(castViewers.keys().next().value);
1456
+ castViewers.set(c.vid.slice(0, 64), { view: norm(c.view), at: Date.now(), driving: !!mine, beats: !!c.beat });
1457
+ assigned.delete(c.vid.slice(0, 64));
1458
+ if (castViewers.size > 8) {
1459
+ const old = castViewers.keys().next().value;
1460
+ castViewers.delete(old);
1461
+ assigned.delete(old);
1462
+ }
1425
1463
  if (!known) log("cast: a viewer said hello \u2014", JSON.stringify(norm(c.view)));
1464
+ if (mine && !known) {
1465
+ await tellControl("/takeover", { on: true });
1466
+ log("take-over: the holder came back \u2014 the controls stay theirs");
1467
+ }
1426
1468
  if (relay && relay.readyState === 1) relay.send(await sealCtl(key, { wb: "cast", on: true, close: true }));
1427
1469
  await startCast();
1428
1470
  if (mine && cast) await cast.setController(norm(c.view)).catch(() => {
@@ -4,14 +4,14 @@
4
4
  // tools/browse-tree/pin.json
5
5
  var pin_default = {
6
6
  _: "THE CLOUD COMPUTER'S BROWSER FOR LINUX that this release installs (tools/browse-tree; make.sh writes it). The files are public at <base><tag>/; both sha256s are checked before anything is unpacked.",
7
- tag: "p2x",
7
+ tag: "p2y",
8
8
  base: "https://drwev5vxt2t2e.cloudfront.net/browse-tree/",
9
- pcr0: "050541844610fd5ed4b586259906d9219edbabc4445ed7943885ac737ee4918e144af2e49838a8313f5823184bc503cf",
10
- commit: "235ef2b815ef74b46e954f48f860197d8d2b612c",
9
+ pcr0: "5a0c2c755715eae50b73fdc13856a6df963bf772e68db5f0155e729c3d822807684f3df10945430f7f75c2e36419e0a0",
10
+ commit: "f45e85eb16a84c90b126915ba8ca8914e2204650",
11
11
  tree: {
12
12
  file: "tree.tar.zst",
13
- sha256: "839b7cc06c70946a4912578115e6cd053cb6b2811cc458457e012ece885b36b6",
14
- size: 664701891
13
+ sha256: "d992f07bbfec50467d9a462a4d443f714332d57cf7dc5a928eb9bde4bd023fc2",
14
+ size: 664651711
15
15
  },
16
16
  lab: {
17
17
  file: "ccvm-lab.bin",
@@ -229,7 +229,7 @@ class Manager:
229
229
  for p in ps:
230
230
  paired.append({"name": p.get("name") or "", "account": p.get("account") or "", "port": wizard.port_of(p), "keys": await self.keys(p),
231
231
  "computer": p.get("computerId") or "", "app": pp.app_label(p)})
232
- pair = {k: v for k, v in self.pair_state.items() if k != "log"}
232
+ pair = {k: v for k, v in self.pair_state.items() if k != "log" and (k != "code" or self.pair_state.get("state") == "waiting")}
233
233
  serving = self.serving()
234
234
  if serving["state"] == "stopped" and ps:
235
235
  el = await self.elsewhere()
@@ -354,7 +354,8 @@ class Manager:
354
354
  ch = devicelink.new_link_challenge()
355
355
  self.qr_svg = qr.qr_svg(ch.text)
356
356
  n = int(self.pair_state.get("n", 0)) + 1
357
- self.pair_state = {"state": "waiting", "n": n, "until": int(time.time() * 1000) + link.LIFE_MS, "message": ""}
357
+ # The code as text beside the QR: a computer cannot scan its own screen, and Add a device takes it pasted.
358
+ self.pair_state = {"state": "waiting", "n": n, "until": int(time.time() * 1000) + link.LIFE_MS, "message": "", "code": ch.text}
358
359
  self.pair_task = asyncio.ensure_future(self._pair_run(ch, await self._pair_port()))
359
360
  return {"ok": True}
360
361
 
@@ -50,6 +50,7 @@ footer { font-size: 13px; text-align: center; }
50
50
  @media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
51
51
  .actions:not(:has(button:not([hidden]))) { display: none; }
52
52
  button.small { font-size: 13px; padding: 2px 10px; margin-left: 8px; }
53
+ pre.cmd.code { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; user-select: all; }
53
54
  pre.cmd { background: var(--off-bg); color: var(--text); padding: 8px 10px; border-radius: 8px; }
54
55
  /* the security check (seccheck.py) */
55
56
  p.small, div.small { font-size: 12.5px; }
@@ -92,11 +92,14 @@ function render(s) {
92
92
  const want = '/api/pair/qr.svg?n=' + s.pair.n
93
93
  if ($('qr').getAttribute('src') !== want) $('qr').setAttribute('src', want)
94
94
  show($('qr').parentElement, true)
95
+ $('pairCode').textContent = s.pair.code || ''
96
+ show($('codeBox'), !!s.pair.code)
95
97
  const left = Math.max(0, Math.round((s.pair.until - Date.now()) / 60000))
96
98
  $('pairMsg').textContent = `Waiting for your phone… (this code works for ${left || 'under a'} minute${left === 1 ? '' : 's'})`
97
99
  show($('pairRetry'), false)
98
100
  } else if (s.pair.state === 'failed') {
99
101
  show($('qr').parentElement, false)
102
+ show($('codeBox'), false)
100
103
  $('pairMsg').textContent = s.pair.message || 'Pairing did not finish.'
101
104
  show($('pairRetry'), true)
102
105
  }
@@ -304,8 +307,13 @@ document.addEventListener('DOMContentLoaded', () => {
304
307
  }
305
308
  // ANOTHER ACCOUNT ON THIS COMPUTER: a new code beside the pairings there are (pairings.json holds one per account, on the
306
309
  // same OpenCode); nothing is unpaired. Code here pauses while the code is up and comes back when it is scanned or cancelled.
307
- $('pairAdd').onclick = () => act('/api/pair', {}, 'Add another account? A new code appears — scan it from the other account: Code in Spaces → Computers → Add a computer. Code on this computer pauses until it is scanned or cancelled.')
310
+ $('pairAdd').onclick = () => act('/api/pair', {}, 'Add another account? A new code appears — scan it (or paste it) from the other account: Spaces → Settings → Privacy & security → Add a device. Code on this computer pauses until it is scanned or cancelled.')
308
311
  $('pairCancel').onclick = () => act('/api/pair/cancel', {})
312
+ $('pairCopy').onclick = async () => {
313
+ const b = $('pairCopy')
314
+ try { await navigator.clipboard.writeText($('pairCode').textContent); b.textContent = 'Copied ✓' } catch { b.textContent = 'Select the code above and copy it' }
315
+ setTimeout(() => { b.textContent = 'Copy the code' }, 2000)
316
+ }
309
317
  $('pairRetry').onclick = () => act('/api/pair', {})
310
318
  $('login').onchange = (e) => act('/api/login', { on: e.target.checked })
311
319
  refresh(true)
@@ -45,6 +45,11 @@
45
45
  <li>Scan this code with the account that should reach this computer.</li>
46
46
  </ol>
47
47
  <div class="qr-wrap"><img id="qr" alt="Pairing code — scan it in Spaces" width="260" height="260"></div>
48
+ <div id="codeBox" hidden>
49
+ <p class="muted">On this computer? Copy the code and paste it under <b>…or paste the code</b> in Add a device.</p>
50
+ <pre id="pairCode" class="cmd code"></pre>
51
+ <div class="actions"><button id="pairCopy" type="button" class="ghost">Copy the code</button></div>
52
+ </div>
48
53
  <p id="pairMsg" class="muted">Waiting for your phone…</p>
49
54
  <div class="actions"><button id="pairCancel" type="button" class="ghost">Cancel</button><button id="pairRetry" type="button" hidden>Show a new code</button></div>
50
55
  </section>
@@ -11,7 +11,6 @@ only way it gets them. `d` (a Deps) holds every outside effect, so the flow is t
11
11
 
12
12
  from __future__ import annotations
13
13
 
14
- import asyncio
15
14
  import os
16
15
  import shutil
17
16
  import socket
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: witbitz-code
3
- Version: 1.15.0
3
+ Version: 1.15.3
4
4
  Summary: Reach OpenCode on this computer from the Witbitz Spaces Code section, through an end-to-end sealed relay.
5
5
  Author: Witbitz
6
6
  License-Expression: MIT
@@ -119,7 +119,7 @@ def test_backup_keys_and_unseal_agree_with_recovery_js():
119
119
  @requires_node
120
120
  def test_link_node_end_to_end_with_a_js_sealed_reply_and_the_backup_fallback(tmp_path):
121
121
  """The whole poll: /api/link answers with a reply a JS device sealed; the payload has no idx, so the index room is
122
- recovered from a JS-sealed backup through /api/backup/release."""
122
+ recovered from a JS-sealed backup through the vault home's /release (never the retired /api/backup)."""
123
123
  master = bytes([9] * 32)
124
124
  ch = devicelink.new_link_challenge()
125
125
  out = run_node("""
@@ -139,7 +139,10 @@ def test_link_node_end_to_end_with_a_js_sealed_reply_and_the_backup_fallback(tmp
139
139
  return {"ok": False, "reason": "unavailable"} if len(polls) == 1 else {"ok": False}
140
140
  return {"ok": True, **out["reply"]}
141
141
 
142
+ released = []
143
+
142
144
  async def post_json(url, body):
145
+ released.append(url)
143
146
  return {"ok": True, "blob": out["blob"]} if body == {"token": "REL", "id": out["id"]} else {"ok": False}
144
147
 
145
148
  lines = []
@@ -148,6 +151,7 @@ def test_link_node_end_to_end_with_a_js_sealed_reply_and_the_backup_fallback(tmp
148
151
  out=lambda *a, **k: lines.append(" ".join(map(str, a))), err=lines.append))
149
152
  assert account and account["email"] == "me@x"
150
153
  assert account["idx"] == {"room": "sp-idx-9", "mk": "idxmk9"}
154
+ assert released == ["https://api.witbitz.chat/v1/vault/release"]
151
155
  assert polls[0] == f"https://a.test/api/link?ref={ch.ref}"
152
156
  assert (tmp_path / "qr.svg").stat().st_mode & 0o777 == 0o600
153
157
  assert not any(_js.btoa(master) in ln for ln in lines), "the master never reaches the terminal"
@@ -63,8 +63,9 @@ def test_the_text_opens_with_the_devices_key_only_and_a_page_message_is_checked(
63
63
 
64
64
 
65
65
  class Receiver:
66
- def __init__(self):
66
+ def __init__(self, fail_first: int = 0):
67
67
  self.got: list = []
68
+ self.failed = 0
68
69
  outer = self
69
70
 
70
71
  class H(BaseHTTPRequestHandler):
@@ -72,7 +73,13 @@ class Receiver:
72
73
  pass
73
74
 
74
75
  def do_POST(self):
75
- outer.got.append({"path": self.path, "body": json.loads(self.rfile.read(int(self.headers.get("content-length") or 0)))})
76
+ body = json.loads(self.rfile.read(int(self.headers.get("content-length") or 0)))
77
+ if outer.failed < fail_first: # the push path is down for a while: 503, not delivered
78
+ outer.failed += 1
79
+ self.send_response(503)
80
+ self.end_headers()
81
+ return
82
+ outer.got.append({"path": self.path, "body": body})
76
83
  self.send_response(200)
77
84
  self.send_header("content-type", "application/json")
78
85
  self.end_headers()
@@ -131,3 +138,67 @@ def test_both_connectors_push_a_waiting_approval_to_the_device_that_asked_twice_
131
138
  run(go())
132
139
  finally:
133
140
  rx.close()
141
+
142
+
143
+ # ⛔ A STAGE IS SPENT ONLY BY A TICKLE THAT WENT OUT (2026-11-08, docs/state-machines.md I16 / C#14): the stage was marked before the
144
+ # POST, so a 5xx (or no device yet, or a network error) used it up — and after the second there was no retry.
145
+ @pytest.mark.parametrize("make,opts", CONNECTORS)
146
+ def test_a_reminder_the_push_path_refused_is_sent_again_not_used_up(make, opts, tmp_path):
147
+ rx = Receiver(fail_first=2)
148
+
149
+ async def go():
150
+ async with Rig() as rig:
151
+ if make is PyConnector:
152
+ PyConnector.OPTION_NAMES = {**PyConnector.OPTION_NAMES, "remindTimes": "remind_times"}
153
+ connector = make(rig, 30_000, autoDir=str(tmp_path / "auto"), **opts)
154
+ await connector.start()
155
+ client = PyClient(rig.secret, rig.relay.url)
156
+ try:
157
+ await client.start()
158
+ assert await until(lambda: rig.oc.global_count() == 1, 10)
159
+ await client.peer.send({"t": "remind", "k": client.nonce, "sid": "ses_main", "dir": "/home/u/repo", "grant": GRANT, "key": KEY, "url": rx.url})
160
+ await asyncio.sleep(0.2)
161
+ rig.oc.emit_global([_asked("/home/u/repo", ASK)])
162
+ assert await until(lambda: len(rx.got) >= 2, 10), f"both stages delivered after {rx.failed} refusals (got {len(rx.got)})"
163
+ assert rx.failed == 2
164
+ finally:
165
+ await client.peer.aclose()
166
+ await connector.stop()
167
+
168
+ try:
169
+ run(go())
170
+ finally:
171
+ rx.close()
172
+
173
+
174
+ # ⛔ ONE `due` FOR EVERY FOLDER (state machines pass 8, K#1): the tick asked the clock once per folder, and the clock forgets every
175
+ # ask it is not shown — so with asks waiting in two folders each call forgot the other's, and neither was ever reminded.
176
+ @pytest.mark.parametrize("make,opts", CONNECTORS)
177
+ def test_asks_waiting_in_two_folders_are_both_reminded(make, opts, tmp_path):
178
+ rx = Receiver()
179
+ other = {**ASK, "id": "per_edit", "permission": "edit", "patterns": ["a.py"], "metadata": {"command": "edit a.py"}}
180
+
181
+ async def go():
182
+ async with Rig() as rig:
183
+ if make is PyConnector:
184
+ PyConnector.OPTION_NAMES = {**PyConnector.OPTION_NAMES, "remindTimes": "remind_times"}
185
+ connector = make(rig, 30_000, autoDir=str(tmp_path / "auto"), **opts)
186
+ await connector.start()
187
+ client = PyClient(rig.secret, rig.relay.url)
188
+ try:
189
+ await client.start()
190
+ assert await until(lambda: rig.oc.global_count() == 1, 10)
191
+ await client.peer.send({"t": "remind", "k": client.nonce, "sid": "ses_main", "dir": "/home/u/repo", "grant": GRANT, "key": KEY, "url": rx.url})
192
+ await asyncio.sleep(0.2)
193
+ rig.oc.emit_global([_asked("/home/u/repo", ASK), _asked("/home/u/other", other)])
194
+ assert await until(lambda: len(rx.got) >= 4, 10), f"two stages for each folder's ask (got {len(rx.got)})"
195
+ whats = sorted(opened(g["body"]["n"])["what"] for g in rx.got)
196
+ assert whats == ["edit a.py", "edit a.py", "npm test", "npm test"], whats
197
+ finally:
198
+ await client.peer.aclose()
199
+ await connector.stop()
200
+
201
+ try:
202
+ run(go())
203
+ finally:
204
+ rx.close()
@@ -147,6 +147,7 @@ def test_unpair_then_pair_again_with_the_code_on_the_page_then_it_serves():
147
147
  assert (await c.post(f"{base}/api/pair", headers=authed(srv), json={})).json() == {"ok": True}
148
148
  st = (await c.get(f"{base}/api/status", headers=authed(srv))).json()
149
149
  assert st["pair"]["state"] == "waiting" and st["pair"]["n"] == 1
150
+ assert st["pair"]["code"].startswith("wbzlink1:"), "the code as text too: a computer cannot scan its own screen, Add a device takes it pasted"
150
151
  qr = await c.get(f"{base}/api/pair/qr.svg?n=1", headers={"cookie": f"wbui_{srv.port}=T0KEN"})
151
152
  assert qr.status_code == 200 and qr.content.startswith(b"<svg"), "the code an <img> loads with the cookie alone"
152
153
  assert (await c.get(f"{base}/api/pair/qr.svg")).status_code == 403
File without changes
File without changes
File without changes