@witbitz/sdk 4.5.0 → 4.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,6 +16,6 @@ The guide: https://witbitz.chat/docs/sdk
16
16
 
17
17
  ## The same bytes as the hosted release
18
18
 
19
- Version 4.5.0 of this package is the release folder https://witbitz.chat/sdk/4.5.0/ unchanged (from commit
20
- `fa43bad6c54e944c094d3b0ede5972dd9187ee84`), plus this README, `package.json` and `LICENSE`. Its `manifest.json` lists the sha384 of every file; each file in the
19
+ Version 4.7.0 of this package is the release folder https://witbitz.chat/sdk/4.7.0/ unchanged (from commit
20
+ `a98d5ae3b3fceb654ceed8264e49babac09f8d62`), plus this README, `package.json` and `LICENSE`. Its `manifest.json` lists the sha384 of every file; each file in the
21
21
  package matches it.
package/a2aCore.js CHANGED
@@ -139,6 +139,35 @@ export function disableLaneIn (s, room) {
139
139
  export function pruneGoneIn (s, isGone) { let n = 0; for (const room of Object.keys(s.lanes || {})) { let g = false; try { g = !!isGone(room) } catch { /* unknown: kept */ } if (g && disableLaneIn(s, room)) n++ } return n }
140
140
  /** Every lane off (a revoke): each inbox marked gone, so no other device's copy switches one back on. */
141
141
  export function clearLanesIn (s) { const gone = { ...(s.gone || {}) }; for (const l of Object.values(s.lanes || {})) gone[l.handle] = Date.now(); return { lanes: {}, gone } }
142
+ // ★ A LANE HANDLE ANOTHER ACCOUNT HOLDS (2026-11-29; the Sentinel's `handle_taken`, accountPool.mjs): a backup restored across the
143
+ // regular app and the iPhone / hosted app (two accounts at the Sentinel) brought the OTHER account's lane handles, and the Sentinel
144
+ // files a handle under one account — every grant of this record was refused and nothing said so. Siri's twin is `key_taken`
145
+ // (siriSheet.js push): a fresh key of this account's own, saved first, then the same save once more. Same shape here.
146
+ /** The handles the Sentinel holds for THIS account (its a2astatus answer). */
147
+ export const heldHandles = (st) => new Set((st && Array.isArray(st.lanes) ? st.lanes : []).map((l) => l && l.handle).filter((h) => typeof h === 'string' && h))
148
+ /** A fresh handle for every lane of `s` the Sentinel does not hold for this account (`held`), limited to `only` (the handles that were
149
+ * already in the stored record — a lane this edit just made has a fresh random handle no account can hold). Such a lane's address
150
+ * never reached this account, so no agent loses an address that worked here; a lane the Sentinel holds keeps its own. Its inbox
151
+ * key and its agents (their tokens) stay. `at` moves past the old copy's, so the account's other devices take the new handle
152
+ * (mergeA2ARecords: of two inboxes for one lane, the newer leads). In place → [[room, oldHandle, newHandle, at]] */
153
+ export function rehandleIn (s, held, only = null, now = Date.now()) {
154
+ const moves = []
155
+ for (const [room, l] of Object.entries(s.lanes || {})) {
156
+ if (!l || held.has(l.handle) || (only && !only.has(l.handle))) continue
157
+ const handle = rnd(16), at = Math.max(now, (Number(l.at) || 0) + 1)
158
+ s.lanes[room] = { ...l, handle, at }
159
+ moves.push([room, l.handle, handle, at])
160
+ }
161
+ return moves
162
+ }
163
+ /** The same moves onto another copy (the stored record, a pending edit): only where that copy's lane still has the old handle. → changed */
164
+ export function applyRehandles (s, moves) {
165
+ let changed = false
166
+ for (const [room, from, handle, at] of moves) { const l = s.lanes && s.lanes[room]; if (l && l.handle === from) { s.lanes[room] = { ...l, handle, at }; changed = true } }
167
+ return changed
168
+ }
169
+ /** Removal intents ([room, handle, peerId]) written against an old handle follow it to the new one. */
170
+ export const rehandledRemovals = (list, moves) => list.map(([room, handle, id]) => { const m = moves.find(([r, from]) => r === room && from === handle); return [room, m ? m[2] : handle, id] })
142
171
  export const peersOf = (s, room) => (s.lanes[room] ? s.lanes[room].peers.map(({ id, name, reply, job, own }) => ({ id, name, reply, ...(job ? { job: true } : {}), ...(own ? { own: true } : {}) })) : [])
143
172
 
144
173
  // ── the Sentinel ──
@@ -159,6 +188,9 @@ export function sentinelCalls ({ post, auth = {}, attest, seal, err }) {
159
188
  async sealed (mode, obj) {
160
189
  const { nonce, key } = await attest({ post, auth })
161
190
  const r = await post({ op: 'sentinel', sentinel: { mode, sealed: await seal(key, nonce, obj) }, ...auth })
191
+ if (mode === 'a2agrant' && r?.error === 'handle_taken') {
192
+ throw err('refused', 'Outside-agent access could not be saved because another account already uses an address in this setup.', r)
193
+ }
162
194
  if (!r || r.error || r.ok === false) throw err('refused', `the Sentinel refused ${mode} (${(r && (r.error || r.reason)) || 'no answer'})`, r)
163
195
  return r
164
196
  },
package/acctV2Switch.js CHANGED
@@ -50,9 +50,10 @@ export function prodSwitch(loc = globalThis.location, storage = globalThis.local
50
50
  // made on the new service stay on it.
51
51
  export const NEW_ACCOUNTS_ON_V2 = true
52
52
  /** Where a NEW account made here starts: the new service's address, or '' (the old service, as before). The production
53
- * regular app and the production vault (the hosted app's v2 client runs there — acctV2VaultWiring.js); the staging app keeps
54
- * its preview card as the way in. A device switched off (?acctv2=off) stays off. */
53
+ * regular app and the production vault (the hosted app's v2 client runs there — acctV2VaultWiring.js); the staging app uses
54
+ * the staging service by default. A device switched off (?acctv2=off) stays off. */
55
55
  export function newAccountService({ host, stored, releaseOn = NEW_ACCOUNTS_ON_V2 }) {
56
+ if (host === STAGING_APP) return stored === 'off' ? '' : STAGING_SERVICE
56
57
  if (host === PROD_VAULT && stored !== 'off') return releaseOn ? PROD_SERVICE : '' // the hosted app: its vault
57
58
  if (host !== PROD_APP || stored === 'off') return ''
58
59
  if (stored === PROD_SERVICE) return PROD_SERVICE
package/acctV2UiCore.js CHANGED
@@ -48,7 +48,7 @@ const MESSAGES = {
48
48
  attestation_refused: 'That key can’t be used for Advanced Backup. It must be a YubiKey with a PIN (or fingerprint) set up.',
49
49
  advanced_not_enabled: 'Advanced Backup isn’t available yet.',
50
50
  possession_pending: 'Set up your recovery code first.',
51
- email_only: 'This account was moved with your email only, so Advanced Backup isn’t available for it.',
51
+ email_only: 'This action is unavailable because the old backup was moved using email alone.',
52
52
  too_many_keys: 'This account already has the most security keys it can hold (5).',
53
53
  no_other_key: 'Removing a key needs another of your keys to confirm it.',
54
54
  keys_mismatch: 'The service answered with keys this device didn’t register. Nothing was changed.',
@@ -569,7 +569,7 @@ async function moveAccount(rerender, { auto = false } = {}) {
569
569
  else { try { others = dep().afterMove ? await dep().afterMove({ trust: r.legacy_trust }) : null } catch { others = null } }
570
570
  const emailOnly = r.legacy_trust === 'email_only'
571
571
  await notice('Done. This account now uses the new account service, with the same recovery code.'
572
- + (emailOnly ? '\n\nIt was moved with your email only (its old backup had no account key), so it stays in a lower-trust state: Advanced Backup isn’t available for it, and the original backup is kept as it was for a year.' : '')
572
+ + (emailOnly ? '\n\nIt was moved with your email only (its old backup had no account key), and the original backup is kept as it was for a year.' : '')
573
573
  + (others && others.unconfirmed ? '\n\nThis device could not confirm that your other devices were told to sign out. If one still shows your Spaces, sign it out from Settings → Your devices on this device.'
574
574
  : r.silent ? '\n\nYour other devices join it by themselves the next time they open.'
575
575
  : Array.isArray(others) && !others.length ? '' : '\n\nYour other devices are being signed out: each clears itself the next time it’s online and says why. To use one again, restore your Spaces on it with your recovery code, or add it from this device (Add a device).'))
@@ -0,0 +1,62 @@
1
+ // addPreferred.js — "ADD ME TO SPACES AS @USERNAME": HOW A PERSON IS ADDED IS THEIR PREFERENCE (docs/spaces-usernames.md § 13;
2
+ // owner, 2026-11-27 / 11-29). Before a member list is written (New Space, Add members, Change members — and the SDK), each address
3
+ // goes the way its person prefers:
4
+ // • an EMAIL whose person prefers their @username — the email door (op 'dir' get) names it, and only for a person who left
5
+ // "find me by email" ON (§ 12: a closed door answers like an unknown address, so nothing is learned) — is added as @username,
6
+ // and the list holds the room's tag, not the email: the other members never get it;
7
+ // • a @USERNAME whose person switched the preference OFF, when the adder knows them by email too, is added by the email;
8
+ // • everything else stays as typed: your own email, domains, a person not on Spaces, any lookup that fails.
9
+ // One person once: an email that turns into a @username already on the list is dropped. Pure of the DOM; the client is injected.
10
+ import { resolveHandle, usernameSlotApp } from './inviteEnroll.js'
11
+ import { parseAddress, validUsername } from './address.js'
12
+
13
+ const lc = (s) => String(s || '').trim().toLowerCase()
14
+
15
+ /** The @username the email door names for `email` — the person prefers it and is findable by email — or null. The GLOBAL handle:
16
+ * the username pointer lives there (a scoped app's own slot is under another handle and never carries one). Never throws. */
17
+ export async function preferredUsernameOf(email, client) {
18
+ try {
19
+ if (!client || typeof client.oprf !== 'function' || typeof client.dirGet !== 'function') return null
20
+ const handle = await resolveHandle(email, client, '')
21
+ if (!handle) return null
22
+ // a scoped app (the hosted app) asks for its own slot under the global handle first (inviteEnroll enrollUsernameSlot), then the
23
+ // regular app's: the name is the same either way, and the find-by-email door answers both alike
24
+ const slot = usernameSlotApp()
25
+ let g = slot ? await client.dirGet(handle, { app: slot }) : null
26
+ if (!(g && g.status === 200)) g = await client.dirGet(handle)
27
+ return g && g.status === 200 ? validUsername(String(g.username || '')) : null
28
+ } catch { return null }
29
+ }
30
+
31
+ /** Does the person at `username` prefer to be added by it? false only on a definite "no" (resolve's `asUser:false`). */
32
+ async function prefersUsername(username, client) {
33
+ try {
34
+ if (!client || typeof client.userResolve !== 'function') return true
35
+ const r = await client.userResolve(username)
36
+ return !(r && r.status === 200 && r.asUser === false)
37
+ } catch { return true }
38
+ }
39
+
40
+ /** `keys`: address keys (emails, "@username", "@domain.tld"). `people`: the adder's contacts ({ email?, username? }).
41
+ * → { keys (the same order, as each person prefers, one person once), learned: [{ email, username }] (for the contacts) } */
42
+ export async function preferredAddresses(keys, { client, people = [], me = '' } = {}) {
43
+ const mine = lc(me)
44
+ const learned = []
45
+ const out = await Promise.all((Array.isArray(keys) ? keys : []).map(async (raw) => {
46
+ const k = String(raw || '').trim()
47
+ const a = parseAddress(k)
48
+ if (!a) return k // a domain, or anything that is not a person's address: as typed
49
+ if (a.kind === 'email') {
50
+ if (a.email === mine) return a.email
51
+ const u = await preferredUsernameOf(a.email, client)
52
+ if (!u) return a.email
53
+ learned.push({ email: a.email, username: u })
54
+ return '@' + u
55
+ }
56
+ const c = (people || []).find((p) => p && lc(p.username).replace(/^@/, '') === a.username && p.email)
57
+ if (!c) return '@' + a.username // known only by the name: nothing to switch to
58
+ return (await prefersUsername(a.username, client)) ? '@' + a.username : lc(c.email)
59
+ }))
60
+ const seen = new Set()
61
+ return { keys: out.filter((k) => { const x = lc(k); if (!x || seen.has(x)) return false; seen.add(x); return true }), learned }
62
+ }
@@ -30,4 +30,4 @@
30
30
  // cd17 (2026-11-25, 28779188 — PASS Rekor 4111966802): the device's trail reaches the `logs` op. cd18 (2026-11-25, 234eed2e — PASS on a
31
31
  // fresh build-enclave boot, Rekor 4112152120): a hosted sign-in acts on the hosted app's own Sentinel account (an own agent's report
32
32
  // came back). cd19 runs and KMS opens for cd19. Devices on an older release follow it by its record (followImage FOLLOW_WINDOW).
33
- export const CLOUD_DEVICE_PCR0 = Object.freeze(['8784c47385209fdf983161c3a2927a455c224000deab3395aad501e6cfd8858e6621ded7ded84193eb1f25ab5838ba84']) // cd19
33
+ export const CLOUD_DEVICE_PCR0 = Object.freeze(['d89c0daf2290536038265b116f4e66fd350c342203c6e6624153596d63c96ebcc57e8e9482afd274a6e0c260f2f22829']) // cd20
package/codeBrowse.js CHANGED
@@ -22,7 +22,7 @@ export function watchUrl (cloud, { take = false, origin = BROWSE_ORIGIN, session
22
22
  const relay = (cloud && cloud.relay) || RELAY_URL
23
23
  const hash = new URLSearchParams({ key })
24
24
  if (take) hash.set('take', '1')
25
- // THE CODE SESSION it shows: each session has its own tab on the computer (vm/sessiontabs.go; the owner, 2026-11-24)
25
+ // THE CODE SESSION it shows: on a cloud computer each session has its own browser (docs/cloud-computer.md § 12.w2)
26
26
  if (/^[A-Za-z0-9_-]{1,128}$/.test(String(session || ''))) hash.set('session', session)
27
27
  return `${origin}/watch?${new URLSearchParams({ relay })}#${hash}`
28
28
  }
@@ -37,15 +37,23 @@ export function browseRow (report, cloud, egress, { session = '' } = {}) {
37
37
  if (!report || !report.offered) return null
38
38
  const watch = watchUrl(cloud, { session })
39
39
  if (!watch) return null // no key on this computer: there is nothing to open, so there is nothing to say
40
+ // ★ A BROWSER PER SESSION (the owner, 2026-11-29: "when you see the browser is open in one session it could show it is
41
+ // closed in another. The state is completely separate"). A computer that says `perSession` reports each session's browser
42
+ // in `sessions`; only THIS session's entry decides here. An older connector or image has one browser: `running`, as before.
43
+ const per = !!report.perSession
44
+ const mine = per && /^[A-Za-z0-9_-]{1,128}$/.test(String(session || '')) ? report.sessions?.[session] : null
45
+ const running = per ? !!(mine && mine.open) : !!report.running
46
+ // the controls are held PER SESSION (the owner, 2026-11-29): this session's entry says `held`
47
+ const taken = per ? !!((mine && mine.held) || (Array.isArray(report.held) && report.held.includes('*'))) : !!report.takeover
40
48
 
41
- if (report.error && !report.running) {
49
+ if (report.error && !running && !per) {
42
50
  return { kind: 'error', title: 'The browser could not start', detail: String(report.error).slice(0, 200), actions: [] }
43
51
  }
44
52
  // Not started is not a state worth a row. The agent opens the browser when it needs one; an empty "not browsing"
45
53
  // row every session teaches the owner to ignore the exact place the real thing will appear.
46
- if (!report.running) return null
54
+ if (!running && !taken) return null
47
55
 
48
- if (report.takeover) {
56
+ if (taken) {
49
57
  // ★ FREE BROWSING IS OFFERED HERE AND NOWHERE ELSE — only while the controls are actually held. It is what
50
58
  // take-over buys, not a setting, and a page that offered it beside "Watch" would be offering the `full` the
51
59
  // owner struck with an extra tap. The enclave refuses it without take-over anyway; this is the same rule said
@@ -58,14 +66,16 @@ export function browseRow (report, cloud, egress, { session = '' } = {}) {
58
66
  return {
59
67
  kind: 'taken',
60
68
  title: 'You have the controls',
61
- detail: 'The agent cannot see this browser while you hold it. The whole web is reachable — and the agent can use whatever you log into afterwards, so don\'t type a password you use anywhere else.',
69
+ detail: (per ? 'This session\'s agent cannot see its browser while you hold it; other sessions\' agents go on in their own. ' : 'The agent cannot see this browser while you hold it. ') + 'The whole web is reachable — and the agent can use whatever you log into afterwards, so don\'t type a password you use anywhere else.',
62
70
  actions: [{ label: 'Open', url: watch }],
63
71
  }
64
72
  }
65
73
  return {
66
74
  kind: 'watching',
67
75
  title: 'Browsing' + (report.viewport ? ' · ' + report.viewport : ''),
68
- detail: 'The agent is using a browser on this computer. You can watch it, or take the controls.',
76
+ detail: per
77
+ ? 'The agent is using this session\'s own browser — its own sign-ins, separate from your other sessions (separate so they do not mix by accident; it is not a wall against another session\'s agent on the same computer). You can watch it, or take the controls.'
78
+ : 'The agent is using a browser on this computer. You can watch it, or take the controls.',
69
79
  actions: [
70
80
  { label: 'Watch', url: watch },
71
81
  { label: 'Take over', url: watchUrl(cloud, { take: true, session }) },
@@ -85,7 +95,7 @@ export function browseRow (report, cloud, egress, { session = '' } = {}) {
85
95
  // Windows laptop with a touchscreen can report its primary pointer as coarse, and the panel then never opened there
86
96
  // (the owner's ASUS, 2026-10-17 — still sent to Chrome on the panel build).
87
97
  export const isComputer = () => matchMedia('(any-pointer: fine)').matches && innerWidth >= 700
88
- /** The person switched Code sessions while the panel is open: the viewer shows that session's tab (watch.js listens). */
98
+ /** The person switched Code sessions while the panel is open: the viewer shows that session's browser (watch.js listens). */
89
99
  export function setBrowsePanelSession (session) {
90
100
  const f = document.getElementById('browsePanelFrame')
91
101
  if (!f || !/^[A-Za-z0-9_-]{1,128}$/.test(String(session || ''))) return
package/codeCache.js CHANGED
@@ -98,7 +98,8 @@ export async function clearSession(cid, sid, store = idb, strict = false) {
98
98
  export async function removeCachedSession(cid, sid, store = idb, local) {
99
99
  if (cid && sid) removed.add(SESS(cid, sid))
100
100
  await clearSession(cid, sid, store, true)
101
- const saved = await loadList(cid, store)
101
+ // read strictly: a failed read is not "no list" — the deleted session's title would stay listed offline (sync sweep 11-27 P3)
102
+ const saved = await loadList(cid, store, { strict: true })
102
103
  if (saved?.list.some(row => row.id === sid)) {
103
104
  await saveList(cid, saved.list.filter(row => row.id !== sid), store, { allowEmpty: true })
104
105
  if ((await loadList(cid, store))?.list.some(row => row.id === sid)) throw new Error('The cached session directory could not be updated')
@@ -128,9 +129,9 @@ export async function saveList(cid, list, store = idb, { allowEmpty = false } =
128
129
  await store.set(LIST(cid), { list: list.slice(0, 200), at: Date.now() })
129
130
  }
130
131
 
131
- export async function loadList(cid, store = idb) {
132
+ export async function loadList(cid, store = idb, { strict = false } = {}) {
132
133
  if (!cid) return null
133
- const c = await store.get(LIST(cid))
134
+ const c = await (strict && store.getStrict ? store.getStrict(LIST(cid)) : store.get(LIST(cid)))
134
135
  return c && Array.isArray(c.list) ? c : null
135
136
  }
136
137
 
package/codeCloud.js CHANGED
@@ -49,6 +49,7 @@ export const CLOUD_API = 'https://api.witbitz.chat/v1/cloud-computer'
49
49
  // now seen in the other direction. Per-image epochs remain the fix, and until they land NEITHER number is a usable
50
50
  // stop condition on its own; the check that holds is the file-by-file tarball diff.
51
51
  export const CLOUD_PCR0 = [
52
+ '2f92640e0cd5a84e96de0d0fa1857a7643eddd1bac5c6a2512e0a1879919c7720db7b403c9daa0cd088b946aa6ba31f0', // p3j, reproduced on both fleet hosts from 95eaefba
52
53
  '66c77a098b36a21fa4a7612ecad202ef2c8e46e34f14e9ab56a3a2a9f3108190f6d2bac14c526f501b1e0109d9605a72', // p3i, reproduced twice from c6ca1e6b
53
54
  ]
54
55
  // The published Credential Sentinel image.
@@ -88,6 +89,7 @@ export const CLOUD_PCR0 = [
88
89
  // ⚑ So "SENTINEL_PCR0 must not move when the Sentinel did not change" is a usable stop condition again — the check
89
90
  // that caught the esbuild-cwd leak, and which caught nothing for four cycles because the number always moved.
90
91
  export const SENTINEL_PCR0 = [
92
+ 'cad3d3e47d1a512fcac60c136b840e83ce28304c37da6e8d66bed205ef5d257cc62e1c118191f1c2561bc749a33cd161', // p3j, reproduced on both fleet hosts from 95eaefba
91
93
  'aaeb3d3f64efa4f072372a7f257eaa89fd969614139ca08a8ce817ec46cd0d32cf2b4e6103b984a2b7f9d7ce3354c248', // p3i, reproduced twice from c6ca1e6b
92
94
  ]
93
95
  export const GRANT_TTL_MS = 24 * 3600_000
@@ -308,6 +310,8 @@ export async function openCloud(computer, { token, aws = null, onStep = () => {}
308
310
  if (r.status === 401 && out.code) throw new CloudError(`your AWS key was not accepted: ${out.error || out.code}`, { status: 401, code: out.code })
309
311
  if (r.status === 401 && !askedAgain) { askedAgain = true; await tokenNow(true); continue } // once more, with a fresh one
310
312
  if (r.status === 401) throw new CloudError(`your sign-in was not accepted${out.reason ? ` (${out.reason})` : ''} — sign in again with your email`, { status: 401, code: 'no_token' })
313
+ // heldUsd: what your OTHER open cloud computers hold — the month is not used, they hold the rest of it for now
314
+ if (r.status === 429 && out.code === 'aws_limit' && Number(out.heldUsd) > 0) throw new CloudError(`your other open cloud computer holds the rest of this month's allowance — close it, or wait a few minutes, and try again`, { status: 429, code: 'aws_limit' })
311
315
  if (r.status === 429 && out.code === 'aws_limit') throw new CloudError(`this month's cloud computer allowance is used${out.resetsAt ? ` — it starts again on ${String(out.resetsAt).slice(0, 10)}` : ''}`, { status: 429, code: 'aws_limit' })
312
316
  if (r.status !== 200 || out.error) throw new CloudError(out.error || `the cloud computer service said ${r.status}`, { status: r.status, code: out.code || out.error || '' })
313
317
  return out
package/connections.js CHANGED
@@ -22,7 +22,7 @@ import { sealDisp, withDisplay } from './connDisp.js' // step 2: a connection's
22
22
  /** The standing Sentinel's image, a rollover set of PCR0s (docs/standing-sentinel.md; infra/enclave/sentinel-host/README.md
23
23
  * for the repin). Empty would mean attach REFUSES: the page will not seal an API key to an enclave it cannot name.
24
24
  * Pin it here and in the Lambda's SENTINEL_HOP_PCRS together. */
25
- export const STANDING_SENTINEL_PCR0 = ['1903ce28fc5a75efe2e57a451d667f1ce8b4b6e11872fb2b81d9e62d8cd994ed80fcfa99807f289af5f281aa4e4cc010'] // st56
25
+ export const STANDING_SENTINEL_PCR0 = ['0e424db41977965bc6edf225229eae70fe162dd8264b1ac0b5670cb3f71bf8b923001341e85a665354b25cd8418ac6d3'] // st57
26
26
 
27
27
  const b64 = (u8) => btoa(String.fromCharCode(...new Uint8Array(u8)))
28
28
  const unb64 = (s) => Uint8Array.from(atob(s), (c) => c.charCodeAt(0))
@@ -0,0 +1,32 @@
1
+ // earlierHistory.js — a linked continuation's EARLIER VERSIONS in an export (side sweep: room-export-omits-linked-earlier-history).
2
+ // The conversation draws the parent chain's messages when this device holds their keys (space.js loadEpochChainHistory), but both
3
+ // exports read the selected room's record alone and finished as if that were all of it. The portable file now carries the earlier
4
+ // versions' messages beside its own (`earlier`, additive — a recreate replays `entries` as before), and when they cannot be read, or
5
+ // the export cannot carry them (the sealed download: one Space's record), it SAYS so. Pure — the caller passes the reader.
6
+
7
+ /** This device's keys for a room's earlier versions ({ parentRoom: mk, … }), or null (not a linked continuation here). */
8
+ export function epochKeysOf(room, storage = globalThis.localStorage) {
9
+ try { const s = storage && storage.getItem('space:epoch:' + room); const o = s ? JSON.parse(s) : null; return o && typeof o === 'object' && Object.keys(o).length ? o : null } catch { return null }
10
+ }
11
+
12
+ /** → { earlier: { from, count, entries } | null, note: '' | a sentence for the toast }.
13
+ * `parent` is the room's config's parent; `readChain(parent, mk, epochKeys)` reads the chain (spaceFork readEpochChain).
14
+ * `configRead: false` = the room's settings (where the parent is named) could not be read: a room this device follows earlier
15
+ * versions of then says they are left out, not nothing (side sweep: room-export-omits-linked-earlier-history, reopened). */
16
+ const UNREAD = ' Its earlier versions’ messages couldn’t be read just now, so they are not in the file — export again to try once more.'
17
+ export async function earlierForExport({ parent, epochKeys, readChain, configRead = true }) {
18
+ if (!parent && epochKeys && configRead === false) return { earlier: null, note: UNREAD }
19
+ if (!parent || !epochKeys) return { earlier: null, note: '' } // not a continuation of an earlier version this device follows
20
+ if (!epochKeys[parent] || typeof readChain !== 'function') return { earlier: null, note: ' Its earlier versions’ messages aren’t on this device, so they are not in the file.' }
21
+ try {
22
+ const entries = await readChain(parent, epochKeys[parent], epochKeys)
23
+ if (!Array.isArray(entries)) throw new Error('no_history')
24
+ // the note counts MESSAGES as drawn: a photo's Safe media copy (`kind: 'safe'`) is its own entry, drawn in the photo's place — as
25
+ // spaceExport.js messageCount (side sweep: room-export-counts-hidden-records-as-messages); the file keeps both, `count` = entries
26
+ const shown = entries.filter((e) => !(e && e.kind === 'safe')).length
27
+ return { earlier: { from: parent, count: entries.length, entries }, note: shown ? ' Its earlier versions’ ' + shown + ' message' + (shown === 1 ? ' is' : 's are') + ' included too.' : '' }
28
+ } catch { return { earlier: null, note: UNREAD } }
29
+ }
30
+
31
+ /** The sealed download holds ONE version's record: a continuation says its earlier versions are not in it. */
32
+ export const sealedEarlierNote = (epochKeys) => (epochKeys ? 'This file holds this version of the Space only — its earlier versions’ messages are not in it.' : '')
package/emailFork.js CHANGED
@@ -81,7 +81,9 @@ export const govOf = (cfg) => ({ owners: lower(cfg && cfg.owners && cfg.owners.e
81
81
  * (the server's rule — spaceService refuses a fork notice from a non-admin where there are admins). */
82
82
  export function mayMove(cfg, email) {
83
83
  const { owners, admins } = govOf(cfg), me = String(email || '').toLowerCase()
84
- return !(admins.length || owners.length) || admins.includes(me) || owners.includes(me)
84
+ // a room whose roles name only @username tags (docs/spaces-usernames.md § 13.1) HAS owners: an email alone is not one of them
85
+ const tagged = !!cfg && ['owners', 'admins'].some((k) => cfg[k] && Array.isArray(cfg[k].tags) && cfg[k].tags.length)
86
+ return !(admins.length || owners.length || tagged) || admins.includes(me) || owners.includes(me)
85
87
  }
86
88
 
87
89
  /** The OWNERS step of a move, before anything is minted: fills the new gate's owners (and, unless stated, the admins it
package/emptySpaces.js CHANGED
@@ -16,6 +16,8 @@ let _h = {
16
16
  read: async () => null, // (room) → { entries, config } | null (the server's answer; null = could not read)
17
17
  me: () => '', // → this account's email
18
18
  keep: () => false, // (room) → true for the Help Space, lanes, anything never to touch
19
+ prepare: null, // optional deletion review before presenting a candidate
20
+ checkDeletion: null, // optional check for a queued deletion
19
21
  deleteOnServer: async () => ({ ok: false, status: 0 }), // (room) → roomDelete.deleteOwnRoom
20
22
  forget: async () => {}, // (room) → the device's delete (forgetSpace + afterItemGone)
21
23
  gone: async () => false, // (room) → true when the Space answers 'deleted' (410): the server finished after the call gave up