@witbitz/sdk 0.0.0-stage → 4.4.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/LICENSE +21 -0
- package/README.md +20 -2
- package/a2aCore.js +221 -0
- package/a2aShared.js +27 -0
- package/accountErase.js +228 -0
- package/accountIndexDoc.js +122 -0
- package/accountOwner.js +59 -0
- package/accountRecord.js +90 -0
- package/accountScope.js +114 -0
- package/accountSeal.js +42 -0
- package/accountStores.js +173 -0
- package/acctV2App.js +619 -0
- package/acctV2Check.js +29 -0
- package/acctV2Client.js +382 -0
- package/acctV2Keys.js +43 -0
- package/acctV2Legacy.js +14 -0
- package/acctV2Switch.js +80 -0
- package/acctV2UiCore.js +857 -0
- package/acctV2WebAuthn.js +61 -0
- package/acctV2Wire.js +59 -0
- package/address.js +42 -0
- package/agentDoorTools.js +28 -0
- package/attestedBox.js +30 -0
- package/attestedRooms.js +78 -0
- package/awsKey.js +98 -0
- package/backupRecord.js +106 -0
- package/backupVault.js +97 -0
- package/blocks.js +115 -0
- package/blocksPush.js +64 -0
- package/browseSeal.js +103 -0
- package/cbor.js +225 -0
- package/changePush.js +75 -0
- package/chatLock.js +165 -0
- package/chatLockSw.js +13 -0
- package/cloudDeviceBuilds.js +11 -0
- package/cloudDevicePins.js +33 -0
- package/cloudDeviceSeal.js +53 -0
- package/codeAttachments.js +100 -0
- package/codeBrowse.js +224 -0
- package/codeCache.js +149 -0
- package/codeCloud.js +650 -0
- package/codeCloudKeys.js +112 -0
- package/codeCommands.js +167 -0
- package/codeComputers.js +389 -0
- package/codeEgress.js +123 -0
- package/codeFilesRoutes.js +17 -0
- package/codeFolders.js +116 -0
- package/codeHistory.js +76 -0
- package/codeLanguage.js +54 -0
- package/codeMkdir.js +8 -0
- package/codeModes.js +59 -0
- package/codeOrphanKeys.js +42 -0
- package/codeOutputs.js +141 -0
- package/codeProgress.js +54 -0
- package/codeRelay.js +505 -0
- package/codeSent.js +68 -0
- package/codeSentinel.js +86 -0
- package/codeSubagents.js +107 -0
- package/codeTransport.js +317 -0
- package/codeUndo.js +48 -0
- package/compress.js +24 -0
- package/config.js +11 -0
- package/connCatalog.js +164 -0
- package/connDisp.js +76 -0
- package/connOtherWays.js +74 -0
- package/connPending.js +16 -0
- package/connWrap.js +53 -0
- package/connectionEntry.js +89 -0
- package/connections.js +561 -0
- package/credits.js +30 -0
- package/csAttest.js +112 -0
- package/decrypt.html +384 -0
- package/deviceAttest.js +527 -0
- package/deviceCall.js +54 -0
- package/deviceKeyCore.js +41 -0
- package/deviceSeal.js +59 -0
- package/e2ee.js +323 -0
- package/eat.js +103 -0
- package/emailFork.js +275 -0
- package/emailSignIn.js +81 -0
- package/emptySpaces.js +111 -0
- package/encSource.js +55 -0
- package/enclaveAccept.js +214 -0
- package/enclaveClaim.js +241 -0
- package/enclaveRoute.js +102 -0
- package/enclaveSnapshotMerge.js +44 -0
- package/entrySig.js +165 -0
- package/env.js +73 -0
- package/eraseFile.js +58 -0
- package/followImage.js +86 -0
- package/healNames.js +45 -0
- package/idb.js +113 -0
- package/idbSeal.js +119 -0
- package/indexGone.js +12 -0
- package/invite.js +51 -0
- package/inviteEnroll.js +67 -0
- package/inviteSend.js +68 -0
- package/jobAgents.js +87 -0
- package/keptMerge.js +91 -0
- package/l1-worker-src.js +2 -0
- package/l1-worker.js +894 -0
- package/laneAssociation.js +68 -0
- package/laneConfig.js +58 -0
- package/laneLinkCore.js +177 -0
- package/ledgerView.js +64 -0
- package/manifest.json +239 -0
- package/mcpRecommended.js +25 -0
- package/memberChange.js +125 -0
- package/mirrorBatch.js +47 -0
- package/mkseal.js +101 -0
- package/nativePush.js +153 -0
- package/nitroVerify.js +220 -0
- package/noble-p256.js +27 -0
- package/notice.js +116 -0
- package/notifKey.js +58 -0
- package/offlineBundle.js +62 -0
- package/ohttp.js +177 -0
- package/opRouting.js +10 -0
- package/opencodeWire.js +282 -0
- package/oprf.js +70 -0
- package/ownAgentLink.js +96 -0
- package/ownerPolicy.js +117 -0
- package/package.json +273 -4
- package/pdfOptions.js +13 -0
- package/pdfText.js +107 -0
- package/pdfjs.mjs +28 -0
- package/pdfjs.worker.mjs +28 -0
- package/pollVerdict.js +33 -0
- package/prefetchPoll.js +60 -0
- package/protectedLocal.js +426 -0
- package/pushCore.js +42 -0
- package/recovery.js +107 -0
- package/regions.js +42 -0
- package/removedMessage.js +11 -0
- package/renameRefusal.js +9 -0
- package/replyQuote.js +34 -0
- package/reqEnvelope.js +126 -0
- package/roomDefaultPrefs.js +76 -0
- package/roomDelete.js +109 -0
- package/roomEmbed.js +111 -0
- package/roomName.js +177 -0
- package/roomPass.js +256 -0
- package/roomRoster.js +305 -0
- package/roomSettings.js +61 -0
- package/roomState.js +58 -0
- package/roomStreamClient.js +115 -0
- package/rosterCount.js +52 -0
- package/rosterHash.js +13 -0
- package/rowSchema.js +113 -0
- package/safeMedia.js +116 -0
- package/safeMediaPins.js +17 -0
- package/schedulesDoc.js +78 -0
- package/sdkA2A.js +524 -0
- package/sdkAccount.js +483 -0
- package/sdkAccountDoc.js +89 -0
- package/sdkAccountSections.js +332 -0
- package/sdkAgui.js +141 -0
- package/sdkAttest.js +34 -0
- package/sdkBackup.js +507 -0
- package/sdkBackupV2.js +630 -0
- package/sdkBrowserPrivate.js +28 -0
- package/sdkBuilds.js +208 -0
- package/sdkCloudDevice.js +221 -0
- package/sdkComputers.js +1009 -0
- package/sdkDictation.js +232 -0
- package/sdkErase.js +288 -0
- package/sdkExports.js +71 -0
- package/sdkInvitations.js +34 -0
- package/sdkKeptAgent.js +188 -0
- package/sdkLaneLink.js +205 -0
- package/sdkPlan.js +96 -0
- package/sdkProtect.js +228 -0
- package/sdkRedact.js +36 -0
- package/sdkRekey.js +340 -0
- package/sdkReport.js +68 -0
- package/sdkSafeMedia.js +255 -0
- package/sdkSchedules.js +39 -0
- package/sdkSpeech.js +71 -0
- package/sdkTemporaryRooms.js +123 -0
- package/sdkTurn.js +117 -0
- package/sdkVault.js +180 -0
- package/sealShare.js +18 -0
- package/sealedNames.js +64 -0
- package/sealedReceipt.js +17 -0
- package/sentinelRelease.js +155 -0
- package/shamir.js +85 -0
- package/sharedViews.js +52 -0
- package/sheetChrome.js +450 -0
- package/siri.js +278 -0
- package/spaceClient.js +1429 -0
- package/spaceConfig.js +81 -0
- package/spaceEmailGate.js +813 -0
- package/spaceExport.js +125 -0
- package/spaceFork.js +216 -0
- package/spaceLock.js +358 -0
- package/spacePasskey.js +180 -0
- package/spaceTemplates.js +99 -0
- package/speechOut.js +102 -0
- package/splitKeyClient.js +90 -0
- package/store.js +656 -0
- package/streamHint.js +36 -0
- package/sttCloud.js +220 -0
- package/sttWorklet.js +38 -0
- package/sw-notif-core.js +540 -0
- package/tempList.js +48 -0
- package/tinfoilVerifier.js +78 -0
- package/toolBooks.js +31 -0
- package/toolRules.js +52 -0
- package/turnCerts.js +254 -0
- package/turnFeed.js +58 -0
- package/turnVerdict.js +37 -0
- package/usageReceipts.js +176 -0
- package/usageSummary.js +90 -0
- package/util.js +181 -0
- package/vault-core.js +2326 -0
- package/vault-kit.mjs +354 -0
- package/vault-screens.js +261 -0
- package/vaultAtRest.js +208 -0
- package/vaultCoreLock.js +111 -0
- package/vaultCorePush.js +140 -0
- package/vaultDeviceKey.js +95 -0
- package/vaultEnclaveHandoff.js +114 -0
- package/vaultKeep.js +287 -0
- package/vaultSealedStore.js +77 -0
- package/vaultWorkerHost.js +117 -0
- package/vcWorker.js +34 -0
- package/voiceAttest.js +50 -0
- package/voiceCert.js +51 -0
- package/witbitz-admin.d.ts +135 -0
- package/witbitz-admin.js +529 -0
- package/witbitz-admin.mjs +1460 -0
- package/witbitz-sdk.d.ts +1197 -0
- package/witbitz-sdk.js +4258 -0
- package/workerClient.js +16 -0
- package/workerLiveness.js +21 -0
- package/x509.js +218 -0
package/chatLock.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// chatLock.js — THE CHAT LOCK'S CORE (docs/chat-lock-plan.md; the owner, 2026-11-24: "a pin — not faceid", "It can be a different
|
|
2
|
+
// pin per room", "Every device with the same pin", "Hidden entirely", "Never delete, slow down", then "Lighter lock everywhere").
|
|
3
|
+
// A LIGHT lock: it hides a Space or a Code session and asks for its PIN before showing it, on every device of the account. Keys,
|
|
4
|
+
// the backup and the sync are untouched — whoever holds the account's data can read the chat without the PIN; the lock is about
|
|
5
|
+
// what the app shows. Pure: no DOM, no network.
|
|
6
|
+
//
|
|
7
|
+
// The synced doc `chat-locks` (sealed in the account's index room like every account doc):
|
|
8
|
+
// { v: 1, locks: { <lockId>: { at, kind: 'room' | 'code', target, salt, pin, title? } | { at, gone: true } } }
|
|
9
|
+
// target: a room id, or '<computerId>/<sessionId>'; pin: the PIN's fingerprint (pinIdFor) under its salt.
|
|
10
|
+
// Per lock the later edit wins; a removal is a tombstone, so an older copy cannot bring a lock back. One salt per account in
|
|
11
|
+
// practice (saltsOf), so a typed PIN is stretched once however many chats it is checked against.
|
|
12
|
+
import { b64url, ub64 } from './accountSeal.js'
|
|
13
|
+
|
|
14
|
+
export const PBKDF2_ITERS = 600_000
|
|
15
|
+
export const CHAT_LOCKS_DOC = 'chat-locks'
|
|
16
|
+
export const LOCKS_MAX = 500
|
|
17
|
+
const enc = new TextEncoder()
|
|
18
|
+
const LOCK_ID = /^lk_[A-Za-z0-9_-]{22}$/
|
|
19
|
+
const SALT = /^[A-Za-z0-9_-]{22}$/
|
|
20
|
+
const PIN_ID = /^[A-Za-z0-9_-]{43}$/
|
|
21
|
+
const KINDS = new Set(['room', 'code'])
|
|
22
|
+
|
|
23
|
+
export const validPin = (pin) => typeof pin === 'string' && /^\d{4,12}$/.test(pin)
|
|
24
|
+
export const isLockId = (s) => typeof s === 'string' && LOCK_ID.test(s)
|
|
25
|
+
const rnd = (n) => crypto.getRandomValues(new Uint8Array(n))
|
|
26
|
+
export const newLockId = () => 'lk_' + b64url(rnd(16))
|
|
27
|
+
export const newSalt = () => b64url(rnd(16))
|
|
28
|
+
export const codeTarget = (computer, sid) => String(computer) + '/' + String(sid)
|
|
29
|
+
|
|
30
|
+
/** The PIN stretched with a salt → 32 raw bytes. Slow on purpose (PBKDF2_ITERS); `iters` only for tests. */
|
|
31
|
+
export async function stretchPin (pin, salt, iters = PBKDF2_ITERS) {
|
|
32
|
+
if (!validPin(pin)) throw new Error('chat lock: a PIN is 4 to 12 digits')
|
|
33
|
+
const km = await crypto.subtle.importKey('raw', enc.encode(pin), 'PBKDF2', false, ['deriveBits'])
|
|
34
|
+
return new Uint8Array(await crypto.subtle.deriveBits({ name: 'PBKDF2', hash: 'SHA-256', salt: ub64(salt), iterations: iters }, km, 256))
|
|
35
|
+
}
|
|
36
|
+
/** The PIN's fingerprint: HMAC(stretched PIN, 'chatlock-pin'), base64url. The same PIN on two chats gives the same one. */
|
|
37
|
+
export async function pinIdFor (stretched) {
|
|
38
|
+
const k = await crypto.subtle.importKey('raw', stretched, { name: 'HMAC', hash: 'SHA-256' }, false, ['sign'])
|
|
39
|
+
return b64url(new Uint8Array(await crypto.subtle.sign('HMAC', k, enc.encode('chatlock-pin'))))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// ── the synced doc ──
|
|
43
|
+
const okAt = (n) => Number.isSafeInteger(n) && n >= 0
|
|
44
|
+
function cleanEntry (e) {
|
|
45
|
+
if (!e || typeof e !== 'object' || !okAt(e.at)) return null
|
|
46
|
+
if (e.gone === true) return { at: e.at, gone: true }
|
|
47
|
+
if (!KINDS.has(e.kind) || typeof e.target !== 'string' || !e.target || e.target.length > 300) return null
|
|
48
|
+
if (typeof e.salt !== 'string' || !SALT.test(e.salt) || typeof e.pin !== 'string' || !PIN_ID.test(e.pin)) return null
|
|
49
|
+
return { at: e.at, kind: e.kind, target: e.target, salt: e.salt, pin: e.pin, ...(typeof e.title === 'string' && e.title ? { title: e.title.slice(0, 200) } : {}) }
|
|
50
|
+
}
|
|
51
|
+
export function cleanChatLocks (doc) {
|
|
52
|
+
if (!doc || typeof doc !== 'object' || doc.v !== 1 || !doc.locks || typeof doc.locks !== 'object') return null
|
|
53
|
+
const locks = {}
|
|
54
|
+
for (const [id, e] of Object.entries(doc.locks)) {
|
|
55
|
+
if (!isLockId(id)) continue
|
|
56
|
+
const c = cleanEntry(e)
|
|
57
|
+
if (c) locks[id] = c
|
|
58
|
+
if (Object.keys(locks).length >= LOCKS_MAX * 2) break // live + tombstones
|
|
59
|
+
}
|
|
60
|
+
const tries = cleanTriesMap(doc.tries)
|
|
61
|
+
return { v: 1, locks, ...(Object.keys(tries).length ? { tries } : {}) }
|
|
62
|
+
}
|
|
63
|
+
// THE WRONG-PIN COUNT, SYNCED (the owner, 2026-11-24: "why can't the tries be synced"): one entry per device in the doc; the
|
|
64
|
+
// account's count is their sum, so a wait set on one device holds on every other, and a second device brings no fresh tries.
|
|
65
|
+
const DEV = /^[A-Za-z0-9_-]{1,64}$/
|
|
66
|
+
function cleanTriesMap (m) {
|
|
67
|
+
const out = {}
|
|
68
|
+
for (const [d, t] of Object.entries(m && typeof m === 'object' ? m : {})) {
|
|
69
|
+
if (!DEV.test(d) || !t || typeof t !== 'object') continue
|
|
70
|
+
const fails = Math.max(0, t.fails | 0), at = Number(t.at) || 0, next = Number(t.next) || 0
|
|
71
|
+
if (fails || next) out[d] = { fails, at, next }
|
|
72
|
+
if (Object.keys(out).length >= 64) break
|
|
73
|
+
}
|
|
74
|
+
return out
|
|
75
|
+
}
|
|
76
|
+
const later = (a, b) => (a.at !== b.at ? (a.at > b.at ? a : b) : (JSON.stringify(a) >= JSON.stringify(b) ? a : b))
|
|
77
|
+
/** Per lock, the later edit wins (equal clocks: a fixed order, so every device lands on the same doc). */
|
|
78
|
+
export function mergeChatLocks (a, b) {
|
|
79
|
+
a = cleanChatLocks(a); b = cleanChatLocks(b)
|
|
80
|
+
if (!a) return b
|
|
81
|
+
if (!b) return a
|
|
82
|
+
const locks = {}
|
|
83
|
+
for (const id of new Set([...Object.keys(a.locks), ...Object.keys(b.locks)])) {
|
|
84
|
+
const x = a.locks[id], y = b.locks[id]
|
|
85
|
+
locks[id] = !x ? y : !y ? x : later(x, y)
|
|
86
|
+
}
|
|
87
|
+
const tries = {} // per device, the entry that moved last
|
|
88
|
+
for (const d of new Set([...Object.keys(a.tries || {}), ...Object.keys(b.tries || {})])) {
|
|
89
|
+
const x = (a.tries || {})[d], y = (b.tries || {})[d]
|
|
90
|
+
tries[d] = !x ? y : !y ? x : (Math.max(y.at, y.next) > Math.max(x.at, x.next) ? y : x)
|
|
91
|
+
}
|
|
92
|
+
return { v: 1, locks: Object.fromEntries(Object.keys(locks).sort().map((k) => [k, locks[k]])), ...(Object.keys(tries).length ? { tries: Object.fromEntries(Object.keys(tries).sort().map((k) => [k, tries[k]])) } : {}) }
|
|
93
|
+
}
|
|
94
|
+
const nextAt = (doc, now) => Math.max(now, ...Object.values((doc && doc.locks) || {}).map((e) => e.at + 1))
|
|
95
|
+
export function addLock (doc, lockId, { kind, target, salt, pin, title }, now = Date.now()) {
|
|
96
|
+
const d = cleanChatLocks(doc) || { v: 1, locks: {} }
|
|
97
|
+
if (!isLockId(lockId)) throw new Error('chat lock: a lock id')
|
|
98
|
+
if (!d.locks[lockId] && liveLocks(d).length >= LOCKS_MAX) throw new Error('chat lock: too many locked chats')
|
|
99
|
+
const e = cleanEntry({ at: nextAt(d, now), kind, target, salt, pin, title })
|
|
100
|
+
if (!e) throw new Error('chat lock: a kind, a target, a salt and a PIN')
|
|
101
|
+
return { ...d, locks: { ...d.locks, [lockId]: e } }
|
|
102
|
+
}
|
|
103
|
+
export function dropLock (doc, lockId, now = Date.now()) {
|
|
104
|
+
const d = cleanChatLocks(doc) || { v: 1, locks: {} }
|
|
105
|
+
return { ...d, locks: { ...d.locks, [lockId]: { at: nextAt(d, now), gone: true } } }
|
|
106
|
+
}
|
|
107
|
+
/** The locks in force: [{ lockId, at, kind, target, salt, pin }]. */
|
|
108
|
+
export const liveLocks = (doc) => Object.entries((cleanChatLocks(doc) || { locks: {} }).locks).filter(([, e]) => !e.gone).map(([lockId, e]) => ({ lockId, ...e }))
|
|
109
|
+
export const saltsOf = (doc) => [...new Set(liveLocks(doc).map((l) => l.salt))]
|
|
110
|
+
export const lockOfTarget = (doc, kind, target) => liveLocks(doc).find((l) => l.kind === kind && l.target === target) || null
|
|
111
|
+
|
|
112
|
+
// ── wrong PINs: slowed, never a deletion (the owner: "Never delete, slow down") ──
|
|
113
|
+
// Counted on this device. None to wait for the first 5 in a row; then 1 min, 5 min, 15 min, 1 h, then a day per try. The count
|
|
114
|
+
// drains one every 6 hours — a right PIN does not reset it, so knowing one chat's PIN does not hide guesses at another's.
|
|
115
|
+
export const FREE_TRIES = 5, DRAIN_MS = 6 * 3600e3
|
|
116
|
+
const WAITS = [60e3, 300e3, 900e3, 3600e3], DAY = 86400e3
|
|
117
|
+
export const waitFor = (fails) => (fails <= FREE_TRIES ? 0 : WAITS[fails - FREE_TRIES - 1] ?? DAY)
|
|
118
|
+
const cleanTries = (t) => ({ fails: Math.max(0, (t && t.fails) | 0), at: Number((t && t.at)) || 0, next: Number((t && t.next)) || 0 })
|
|
119
|
+
export function drainTries (t, now = Date.now()) {
|
|
120
|
+
const x = cleanTries(t)
|
|
121
|
+
if (!x.fails) return { ...x, at: now }
|
|
122
|
+
const n = Math.floor((now - x.at) / DRAIN_MS)
|
|
123
|
+
return n > 0 ? { ...x, fails: Math.max(0, x.fails - n), at: x.at + n * DRAIN_MS } : x
|
|
124
|
+
}
|
|
125
|
+
/** → the time the next PIN may be tried (0 = now). */
|
|
126
|
+
export const tryAfter = (t, now = Date.now()) => { const x = cleanTries(t); return x.next > now ? x.next : 0 }
|
|
127
|
+
/** A wrong PIN: → the new count ({ fails, at, next }). */
|
|
128
|
+
export function wrongTry (t, now = Date.now()) {
|
|
129
|
+
const x = drainTries(t, now)
|
|
130
|
+
const fails = x.fails + 1, w = waitFor(fails)
|
|
131
|
+
return { fails, at: x.fails ? x.at : now, next: w ? now + w : 0 }
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ── the account's count, from the doc ──
|
|
135
|
+
/** The account's wrong tries now (each device's count drained, summed) and the time the next PIN may be tried (0 = now). */
|
|
136
|
+
export function accountTries (doc, now = Date.now()) {
|
|
137
|
+
const m = (cleanChatLocks(doc) || {}).tries || {}
|
|
138
|
+
let fails = 0, next = 0
|
|
139
|
+
for (const t of Object.values(m)) { fails += drainTries(t, now).fails; if (t.next > now) next = Math.max(next, t.next) }
|
|
140
|
+
return { fails, next }
|
|
141
|
+
}
|
|
142
|
+
/** A wrong PIN on device `dev`: → the doc with its count moved; the wait comes from the ACCOUNT's total. */
|
|
143
|
+
export function wrongTryIn (doc, dev, now = Date.now()) {
|
|
144
|
+
const d = cleanChatLocks(doc) || { v: 1, locks: {} }
|
|
145
|
+
const mine = drainTries((d.tries || {})[dev], now), total = accountTries(d, now).fails - drainTries((d.tries || {})[dev], now).fails + mine.fails + 1
|
|
146
|
+
const w = waitFor(total)
|
|
147
|
+
return { ...d, tries: { ...(d.tries || {}), [dev]: { fails: mine.fails + 1, at: mine.fails ? mine.at : now, next: w ? now + w : 0 } } }
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
/** Act only on the listed locks. A target is complete once its removal and the lock update both succeed. */
|
|
152
|
+
export async function deleteLockedTargets(targets, { stillLocked, removeTarget, removeLock }) {
|
|
153
|
+
const outcomes = []
|
|
154
|
+
for (const { lockId, kind, target } of targets) {
|
|
155
|
+
let deleted = false
|
|
156
|
+
try {
|
|
157
|
+
if (await stillLocked(lockId, kind, target) && await removeTarget(kind, target)) {
|
|
158
|
+
await removeLock(lockId, kind, target)
|
|
159
|
+
deleted = true
|
|
160
|
+
}
|
|
161
|
+
} catch { /* record the failure and keep the other targets independent */ }
|
|
162
|
+
outcomes.push({ lockId, kind, target, deleted })
|
|
163
|
+
}
|
|
164
|
+
return outcomes
|
|
165
|
+
}
|
package/chatLockSw.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// chatLockSw.js — THE CHAT LOCK, WHAT THE SERVICE WORKER IS TOLD (docs/chat-lock-plan.md). A push for a locked Space shows only the
|
|
2
|
+
// generic line (sw-notif-core.js wbxChatLocked). The worker holds no account, so the page leaves it the locked Spaces' ids as SHA-256
|
|
3
|
+
// hashes under 'chatlocked:sw' (a name shared with the workers — idbSeal.js IDB_SHARED_NAMES), rewritten whenever the locks change.
|
|
4
|
+
export const CHAT_LOCKED_SW_KEY = 'chatlocked:sw'
|
|
5
|
+
export async function lockedRoomHash (room) {
|
|
6
|
+
const d = new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode('chatlock|' + room)))
|
|
7
|
+
return Array.from(d).map((b) => b.toString(16).padStart(2, '0')).join('')
|
|
8
|
+
}
|
|
9
|
+
/** Leave the worker the list for these rooms (a hidden room; an opened one too — its notices stay plain). */
|
|
10
|
+
export async function mirrorLockedRooms (rooms, idb) {
|
|
11
|
+
const list = await Promise.all([...new Set(rooms)].map(lockedRoomHash))
|
|
12
|
+
try { if (list.length) await idb.set(CHAT_LOCKED_SW_KEY, list.sort()); else await idb.del(CHAT_LOCKED_SW_KEY) } catch { /* the next change writes it */ }
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// cloudDeviceBuilds.js — what the phone hands the cloud device of the turn-enclave builds the account accepted (docs/cloud-device.md
|
|
2
|
+
// § 4.9; cloudDeviceSheet.js). Pure: the device keeps the union, so the phone sends only what the device lacks — a build it does not
|
|
3
|
+
// hold, or a newer "accept new builds automatically" choice. A list not yet known on this phone (`ours` null) is never sent.
|
|
4
|
+
const buildKey = (e) => [e.kernel, e.payload || '', e.policy || ''].join('|')
|
|
5
|
+
export function deviceLacksBuilds (theirs, ours) {
|
|
6
|
+
if (!ours) return false
|
|
7
|
+
const have = new Set(((theirs && theirs.builds) || []).map(buildKey))
|
|
8
|
+
if ((ours.builds || []).some((e) => !have.has(buildKey(e)))) return true
|
|
9
|
+
const a = ours.auto, b = theirs && theirs.auto
|
|
10
|
+
return !!a && (!b || a.at > b.at)
|
|
11
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// cloudDevicePins.js — WHICH cloud-device enclave images this build hands a Space to (docs/cloud-device-enclave-plan.md § 4). A
|
|
2
|
+
// request goes only to an attestation naming one of these PCR0s (and role "clouddevice"), sealed to its key. EMPTY = the EC2
|
|
3
|
+
// prototype (plain, through the Space Lambda) — until the first enclave image is reproduced, logged and pinned here; an image
|
|
4
|
+
// rollover names two (new first), then narrows.
|
|
5
|
+
// cd5 (2026-11-17, 96afffbe): the cloud device's image as REPRODUCED — 460b4daf: built twice on a fresh host and by the build enclave
|
|
6
|
+
// (ba3), the same context (08d727c8). Narrowed 2026-11-18 to it alone (197266f5, what the first host built, runs nowhere; KMS opens
|
|
7
|
+
// for 460b4daf alone).
|
|
8
|
+
// cd7 (2026-11-18, aaa48807, 2b142dad — reproduced by the build enclave, a throwaway host and this host once its builder was fresh;
|
|
9
|
+
// the host first built cb790fd4 from a stale BuildKit builder, c0a6f94bf): a hosted-app account served as the hosted app; a split Space keeps only its user share, the app half asked
|
|
10
|
+
// per wake with the member's proof (cloud-device/apps.mjs). Rollover: cd7 first, cd5 until the switch has run; narrow at the next release.
|
|
11
|
+
// cd8 (2026-11-18, 9e8a2d45, bc8f09da): cd7 + the hosted app's vault in its egress (cd7 could not sign a hosted account in). Rollover:
|
|
12
|
+
// cd8 first, cd7 (running since 08:59Z) until the switch; cd5 runs nowhere (KMS dropped it).
|
|
13
|
+
// cd9 (2026-11-18, 655ddf95, f80f246b — reproduced twice on the host and by the build enclave, Rekor 3976675384): the image on Debian 13
|
|
14
|
+
// (trixie) — the Sentinel family's first; and the 11-18 sweep's scope rules (no lanes, no links, people counted for solo; a tick
|
|
15
|
+
// re-checks and lets go). Running since 2026-11-18 ~20:00Z; narrowed the same day to it alone (cd8 runs nowhere; KMS {cd9}).
|
|
16
|
+
// cd10 (2026-11-21, c3a286c3, 1c348ebf — reproduced twice on the host and by the build enclave, Rekor 4033371976): an attested
|
|
17
|
+
// Space can be kept always on (the device enrols in it as platform 'clouddevice', its key bound to this enclave's attestation);
|
|
18
|
+
// the 11-21 sweep's lane mark and kept-Space rules. Running since 2026-11-21 15:4xZ (end-to-end PASS); narrowed the same day to it alone (cd9 runs nowhere; KMS {cd10}).
|
|
19
|
+
// cd11 (2026-11-23, 275454ac, b2505169 — reproduced twice on the host and by the build enclave, Rekor 4050389884): it seals turns only to
|
|
20
|
+
// turn-enclave builds the owner accepted (the phone hands the account's list; a refused build makes the Space wait — docs/cloud-device.md
|
|
21
|
+
// § 4.9) and the 11-22 sweep's scope fixes. Switched with no Official release first — the apps followed its release record
|
|
22
|
+
// (followImage.js); end to end PASS, and the pause proven live. Narrowed the same day to it alone (cd10 runs nowhere; KMS {cd11}).
|
|
23
|
+
// cd13/cd14 (2026-11-23/24): the always-on agent (no drafts, held tasks, endHeld); cd14 ran on its release record alone.
|
|
24
|
+
// cd15 (2026-11-24, 25a6cbc9 — reproduced twice on the host and by the build enclave): an always-on Space as an outside agent of a
|
|
25
|
+
// private room, like Grok Bot (the owner: "Like grokbot") — door request `report`, the answer also sent into that room's door
|
|
26
|
+
// (cloud-device/report.mjs), agents.witbitz.chat in its egress. Rollover: cd15 first, cd14 until the switch; narrow at the next release.
|
|
27
|
+
// cd16 (2026-11-25, 63d78329 — reproduced twice on the host and by the build enclave, Rekor 4102269470): the SDK opens a split-key
|
|
28
|
+
// Enclave Space (the hosted vault's enc mark is read; the room is routed to the enclave) — a hosted Enclave Space can be kept always on.
|
|
29
|
+
// Rollover: cd16 first, cd15 until the switch; narrow at the next release.
|
|
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
|
+
// 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
|
+
// 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
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// cloudDeviceSeal.js — EVERY REQUEST TO THE CLOUD DEVICE, SEALED TO ITS ENCLAVE (docs/cloud-device-enclave-plan.md § 4). One writer
|
|
2
|
+
// for the regular app (spaceClient.cloudDevice) and the hosted app's vault (vault-loader.js cloudDevicePost):
|
|
3
|
+
// 1. op 'clouddevice' {t:'attest', nonce} → the device's attestation; held to CLOUD_DEVICE_PCR0 and role "clouddevice";
|
|
4
|
+
// 2. the request sealed to the attested share key (sealShare.js — the Sentinel's scheme), carrying the person's OWN sign-in
|
|
5
|
+
// (the device acts for the account it names, never the Lambda's word) and a one-time answer key;
|
|
6
|
+
// 3. op 'clouddevice' {t:'sealed', sealed} → the answer, sealed under that key, opened here.
|
|
7
|
+
// The Space Lambda carries both and can read neither. No pins → REFUSED (sync sweep 11-22: it sent the plain request, a fallback for
|
|
8
|
+
// the EC2 prototype, retired 2026-11-17 — an empty pin list must never mean "in the clear").
|
|
9
|
+
import { verifyAttestation } from './nitroVerify.js'
|
|
10
|
+
import { sealTo } from './sealShare.js'
|
|
11
|
+
import { CLOUD_DEVICE_PCR0 } from './cloudDevicePins.js'
|
|
12
|
+
import { followedImages } from './followImage.js' // an image this build does not pin, accepted by its release log (docs/release-trust-design.md § 6)
|
|
13
|
+
|
|
14
|
+
const b64 = (u8) => btoa(String.fromCharCode(...new Uint8Array(u8)))
|
|
15
|
+
const unb64 = (s) => Uint8Array.from(atob(String(s)), (c) => c.charCodeAt(0))
|
|
16
|
+
const refuse = (error, message, status = 502, detail = '') => ({ status, ok: false, error, message, ...(detail ? { detail: String(detail).slice(0, 200) } : {}) })
|
|
17
|
+
|
|
18
|
+
/** post(body) → { status, ...answer } (the Space API). cd = { t, … }. → the device's answer as a plain post would give it. */
|
|
19
|
+
export async function cloudDeviceCall (post, cd, idToken, { pins = CLOUD_DEVICE_PCR0, verify = verifyAttestation, now, follow = followedImages } = {}) {
|
|
20
|
+
if (!pins || !pins.length) return refuse('no_pins', 'This app names no cloud device build, so nothing was sent to it.')
|
|
21
|
+
const nonce = crypto.getRandomValues(new Uint8Array(32))
|
|
22
|
+
const a = await post({ op: 'clouddevice', cd: { t: 'attest', nonce: b64(nonce) }, idToken })
|
|
23
|
+
if (!a || a.status !== 200 || typeof a.doc !== 'string') return a && a.status && a.status !== 200 ? a : refuse((a && a.error) || 'attest_failed', 'The cloud device could not show what it runs.')
|
|
24
|
+
let doc
|
|
25
|
+
const check = (list) => verify(unb64(a.doc), { nonce, expectedPCRs: { 0: [...list] }, maxAgeMs: 5 * 60_000, ...(now ? { now } : {}) })
|
|
26
|
+
try { doc = await check(pins) } catch (e) {
|
|
27
|
+
// NOT THIS BUILD'S PIN: the newest cloud-device images whose release records verify here (followImage.js) — else refused, as before
|
|
28
|
+
const more = follow ? (await follow('cloud-device')).filter((p) => !pins.includes(p)) : []
|
|
29
|
+
// ★ EACH ON ITS OWN (2026-11-24, the owner's iPhone: "PCR0 pins 3 values; at most 2" — pins {cd13, cd11} + the running cd14
|
|
30
|
+
// followed made three, which the verifier refuses as a set; connections.js learned the same on 10-21)
|
|
31
|
+
let last = e
|
|
32
|
+
for (const p of more) { try { doc = await check([p]); break } catch (ex) { last = ex } }
|
|
33
|
+
try { if (!doc) throw last } catch (e2) {
|
|
34
|
+
return refuse('attestation', 'The cloud device is not running the published Witbitz image, so nothing was sent to it.', 502, (e2 && e2.message) || e2)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
let said = null; try { said = JSON.parse(new TextDecoder().decode(doc.userData || new Uint8Array(0))) } catch { said = null }
|
|
38
|
+
if (!said || said.role !== 'clouddevice' || !doc.publicKey) return refuse('attestation', 'The attestation does not name a cloud device, so nothing was sent to it.', 502, 'role ' + (said && said.role))
|
|
39
|
+
const key = await crypto.subtle.importKey('spki', doc.publicKey, { name: 'ECDH', namedCurve: 'P-384' }, false, [])
|
|
40
|
+
const answerRaw = crypto.getRandomValues(new Uint8Array(32))
|
|
41
|
+
const hint = a.hint && typeof a.hint === 'object' ? a.hint : null // the Lambda's word on the token's issuer (a hosted-app sign-in's own) — the enclave checks it
|
|
42
|
+
const sealed = await sealTo(key, nonce, { ...cd, idToken, ...(hint ? { hint } : {}), answerKey: b64(answerRaw) })
|
|
43
|
+
const r = await post({ op: 'clouddevice', cd: { t: 'sealed', sealed }, idToken })
|
|
44
|
+
if (!r || r.status !== 200) return r
|
|
45
|
+
if (!r.sealed || typeof r.sealed.iv !== 'string' || typeof r.sealed.ct !== 'string') return r.ok === false ? { status: 200, ok: false, error: r.error, message: r.message } : refuse('unsealed', 'The cloud device\'s answer was not sealed to this request.')
|
|
46
|
+
let ans
|
|
47
|
+
try {
|
|
48
|
+
const k = await crypto.subtle.importKey('raw', answerRaw, 'AES-GCM', false, ['decrypt'])
|
|
49
|
+
ans = JSON.parse(new TextDecoder().decode(await crypto.subtle.decrypt({ name: 'AES-GCM', iv: unb64(r.sealed.iv) }, k, unb64(r.sealed.ct))))
|
|
50
|
+
} catch { return refuse('unsealed', 'The cloud device\'s answer did not open.') }
|
|
51
|
+
const { re: _re, ...rest } = ans || {}
|
|
52
|
+
return { status: 200, ...rest }
|
|
53
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// spaces/public/codeAttachments.js — attachments in the Code section, the Claude Code way (docs/code-attachments.md).
|
|
2
|
+
//
|
|
3
|
+
// The connector saves every file a message carries on the computer and puts a NOTE in the message in its place; the agent
|
|
4
|
+
// opens the file (or its Tinfoil text copy) with its read tool when it needs it. This module is the note's one definition:
|
|
5
|
+
// the connector writes it, the page reads it back into chips, and the Python twin matches it through the tests.
|
|
6
|
+
//
|
|
7
|
+
// Measured on opencode 1.18.30 (2026-09-13): OpenCode refuses an Excel or Word file part for every model ("'file part media
|
|
8
|
+
// type …spreadsheetml.sheet' functionality not supported"); a staged text copy named in a synthetic line was read by Kimi K3
|
|
9
|
+
// unprompted, while DeepSeek V4 Flash first reached for the shell on the original — so the note says WHICH file to open.
|
|
10
|
+
// Pure: no DOM, no fs — the same module runs in the page and in Node.
|
|
11
|
+
|
|
12
|
+
const NOTE_HEAD = 'The user attached files. They are saved on this computer — open them with the read tool.'
|
|
13
|
+
const MAX_NAME = 100
|
|
14
|
+
|
|
15
|
+
/** A name that is safe as the last part of a path: no folders, no dot-file, only plain characters, at most 100 long. */
|
|
16
|
+
export function safeName(name) {
|
|
17
|
+
let s = String(name || '').split(/[\\/]/).pop().trim()
|
|
18
|
+
s = s.replace(/[^A-Za-z0-9._ ()-]+/g, '_').replace(/_+/g, '_').replace(/^\./, '_')
|
|
19
|
+
if (!s.replace(/[._ ]/g, '')) s = 'file' // nothing readable left (an empty or all-foreign name)
|
|
20
|
+
if (s.length > MAX_NAME) {
|
|
21
|
+
const ext = (s.match(/\.[A-Za-z0-9]{1,10}$/) || [''])[0]
|
|
22
|
+
s = s.slice(0, MAX_NAME - ext.length) + ext
|
|
23
|
+
}
|
|
24
|
+
return s
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** On disk: the first 8 hex of the content's SHA-256, then the safe name — the same bytes land on the same file. */
|
|
28
|
+
export const stagedFileName = (hashHex, name) => `${String(hashHex).slice(0, 8)}-${safeName(name)}`
|
|
29
|
+
|
|
30
|
+
const extOf = (name) => (String(name || '').toLowerCase().match(/\.([a-z0-9]+)$/) || [])[1] || ''
|
|
31
|
+
const TEXT_EXT = new Set(['txt', 'md', 'markdown', 'csv', 'tsv', 'json', 'log', 'xml', 'yaml', 'yml', 'html', 'htm', 'js', 'mjs', 'ts', 'py', 'sh', 'sql', 'ini', 'toml'])
|
|
32
|
+
|
|
33
|
+
/** A document the read tool cannot show a model (PDF, Word, Excel, slides…) gets a text copy; images and text do not. */
|
|
34
|
+
export function needsTextCopy(mime, name) {
|
|
35
|
+
const m = String(mime || '').toLowerCase()
|
|
36
|
+
if (m.startsWith('image/') || m.startsWith('text/') || m === 'application/json') return false
|
|
37
|
+
return !TEXT_EXT.has(extOf(name))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function formatSize(bytes) {
|
|
41
|
+
const n = Number(bytes) || 0
|
|
42
|
+
if (n < 1024) return `${n} B`
|
|
43
|
+
if (n < 1024 * 1023.95) return `${(n / 1024).toFixed(1)} KB` // never "1024.0 KB"
|
|
44
|
+
return `${(n / 1024 / 1024).toFixed(1)} MB`
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const SHOWN_MAX = 200 // a file name is prompt text the model reads — keep it a name, not a paragraph (review finding)
|
|
48
|
+
const shown = (name) => String(name || 'file').replace(/[\r\n]+/g, ' ').replace(/ — /g, ' - ').slice(0, SHOWN_MAX)
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The note that replaces the files in the message. `entries`: {name, size, path, copy?, inline?, noCopy?} — `copy` is the
|
|
52
|
+
* text copy's path, `inline` means the file also rides the message (an image a model can see), `noCopy` why there is none.
|
|
53
|
+
*/
|
|
54
|
+
export function attachmentNote(entries) {
|
|
55
|
+
const lines = [NOTE_HEAD]
|
|
56
|
+
for (const e of entries) {
|
|
57
|
+
lines.push(`• ${shown(e.name)} — ${formatSize(e.size)} — ${e.path}`)
|
|
58
|
+
if (e.copy) lines.push(` Its text — open THIS with the read tool, not the original: ${e.copy}`)
|
|
59
|
+
else if (e.inline) lines.push(' Shown to you with this message.')
|
|
60
|
+
else if (e.noCopy) lines.push(` No text copy (${e.noCopy}) — open it with the read tool if you can; otherwise ask the user before converting it.`)
|
|
61
|
+
}
|
|
62
|
+
return lines.join('\n')
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The note back → [{name, size, session, file, copy, inline}], or null when the text is not a note. */
|
|
66
|
+
export function parseAttachmentNote(text) {
|
|
67
|
+
const lines = String(text || '').split('\n')
|
|
68
|
+
if (lines[0] !== NOTE_HEAD) return null
|
|
69
|
+
const out = []
|
|
70
|
+
for (const line of lines.slice(1)) {
|
|
71
|
+
const m = /^• (.+?) — (\d+(?:\.\d)? (?:B|KB|MB)) — (\/.+)$/.exec(line)
|
|
72
|
+
if (m) {
|
|
73
|
+
const parts = m[3].split('/')
|
|
74
|
+
out.push({ name: m[1], size: m[2], session: parts[parts.length - 2] || '', file: parts[parts.length - 1] || '', copy: '', inline: false })
|
|
75
|
+
continue
|
|
76
|
+
}
|
|
77
|
+
const last = out[out.length - 1]
|
|
78
|
+
if (!last) continue
|
|
79
|
+
const c = /^ {2}Its text — .*: (\/.+)$/.exec(line)
|
|
80
|
+
if (c) last.copy = c[1].split('/').pop()
|
|
81
|
+
else if (/^ {2}Shown to you with this message\.$/.test(line)) last.inline = true
|
|
82
|
+
}
|
|
83
|
+
return out.length ? out : null
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** A page's request for a staged file names a session and a staged file name — never a path. */
|
|
87
|
+
export function validAttachmentRef(session, file) {
|
|
88
|
+
return /^[A-Za-z0-9_-]{1,128}$/.test(String(session || '')) &&
|
|
89
|
+
/^[0-9a-f]{8}-(?!\.)[A-Za-z0-9._ ()-]{1,110}$/.test(String(file || '')) && !String(file).includes('..')
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const MIME = { pdf: 'application/pdf', png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', gif: 'image/gif', webp: 'image/webp', heic: 'image/heic',
|
|
93
|
+
md: 'text/markdown', txt: 'text/plain', csv: 'text/csv', json: 'application/json',
|
|
94
|
+
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', xls: 'application/vnd.ms-excel',
|
|
95
|
+
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', doc: 'application/msword',
|
|
96
|
+
pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' }
|
|
97
|
+
export const mimeForFile = (file) => MIME[extOf(file)] || 'application/octet-stream'
|
|
98
|
+
|
|
99
|
+
/** The connector-owned route a page asks for a staged file on (never forwarded to OpenCode). */
|
|
100
|
+
export const ATTACHMENT_ROUTE = '/witbitz/attachment'
|
package/codeBrowse.js
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// codeBrowse.js — what the Code section says about the agent's browser, and the link that opens it
|
|
2
|
+
// (docs/cloud-computer.md § 12). Pure: it takes the enclave's own `browse` report — which rides the assign result
|
|
3
|
+
// and the hello beside `egress` and `agent` — plus the computer's cloud entry, and returns a row or nothing.
|
|
4
|
+
//
|
|
5
|
+
// ★ THE ROW IS THE ONLY PLACE THE OWNER LEARNS THE AGENT HAS A BROWSER, so it must not overstate. A computer made
|
|
6
|
+
// before this shipped has no browse key and offers nothing; a browser the agent has never opened is not a browser
|
|
7
|
+
// "waiting to connect"; and the sentence about take-over says what take-over actually buys.
|
|
8
|
+
import { RELAY_URL } from './codeRelay.js'
|
|
9
|
+
|
|
10
|
+
// The viewer's own origin — a DEDICATED Pages project, deliberately not the app's (spaces/browse-connector/_headers
|
|
11
|
+
// explains why: this is the one page allowed to reach the relay, and the app's signed egress-lock cert stays clean).
|
|
12
|
+
export const BROWSE_ORIGIN = 'https://browse.witbitz.chat'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The link the owner opens to watch. The key rides the FRAGMENT, never the query: a fragment is not sent to the
|
|
16
|
+
* server and is not what proxies and access logs keep.
|
|
17
|
+
* @returns {string|null} null when this computer has no browse key at all.
|
|
18
|
+
*/
|
|
19
|
+
export function watchUrl (cloud, { take = false, origin = BROWSE_ORIGIN, session = '' } = {}) {
|
|
20
|
+
const key = cloud && cloud.browse
|
|
21
|
+
if (!key) return null
|
|
22
|
+
const relay = (cloud && cloud.relay) || RELAY_URL
|
|
23
|
+
const hash = new URLSearchParams({ key })
|
|
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)
|
|
26
|
+
if (/^[A-Za-z0-9_-]{1,128}$/.test(String(session || ''))) hash.set('session', session)
|
|
27
|
+
return `${origin}/watch?${new URLSearchParams({ relay })}#${hash}`
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {{offered?:boolean, running?:boolean, takeover?:boolean, viewport?:string, error?:string}} report
|
|
32
|
+
* the enclave's own `browse` report, as it arrives in the hello.
|
|
33
|
+
* @param {{freeBrowsing?:{on?:boolean}}} [egress] the enclave's egress report, for whether the web is open now
|
|
34
|
+
* @returns {{kind:string, title:string, detail:string, actions:{label:string,url?:string,act?:string}[]}|null}
|
|
35
|
+
*/
|
|
36
|
+
export function browseRow (report, cloud, egress, { session = '' } = {}) {
|
|
37
|
+
if (!report || !report.offered) return null
|
|
38
|
+
const watch = watchUrl(cloud, { session })
|
|
39
|
+
if (!watch) return null // no key on this computer: there is nothing to open, so there is nothing to say
|
|
40
|
+
|
|
41
|
+
if (report.error && !report.running) {
|
|
42
|
+
return { kind: 'error', title: 'The browser could not start', detail: String(report.error).slice(0, 200), actions: [] }
|
|
43
|
+
}
|
|
44
|
+
// Not started is not a state worth a row. The agent opens the browser when it needs one; an empty "not browsing"
|
|
45
|
+
// row every session teaches the owner to ignore the exact place the real thing will appear.
|
|
46
|
+
if (!report.running) return null
|
|
47
|
+
|
|
48
|
+
if (report.takeover) {
|
|
49
|
+
// ★ FREE BROWSING IS OFFERED HERE AND NOWHERE ELSE — only while the controls are actually held. It is what
|
|
50
|
+
// take-over buys, not a setting, and a page that offered it beside "Watch" would be offering the `full` the
|
|
51
|
+
// owner struck with an extra tap. The enclave refuses it without take-over anyway; this is the same rule said
|
|
52
|
+
// where a person can see it. docs/cloud-computer-free-browsing.md § 5.
|
|
53
|
+
// ⛑ `act` rather than `url`: this one is a CALL, authenticated by the device half, not a link anyone could share.
|
|
54
|
+
// ★ ONE KIND. There used to be a second — "taken, with the whole web open" — with "Open the web" / "Close the
|
|
55
|
+
// web" actions behind it. The owner asked for that to go (2026-09-21): the browser reaches everything by
|
|
56
|
+
// construction now, so there is nothing to open and nothing to close. `egress` is still accepted so callers
|
|
57
|
+
// need not change; it decides nothing here.
|
|
58
|
+
return {
|
|
59
|
+
kind: 'taken',
|
|
60
|
+
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.',
|
|
62
|
+
actions: [{ label: 'Open', url: watch }],
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
kind: 'watching',
|
|
67
|
+
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.',
|
|
69
|
+
actions: [
|
|
70
|
+
{ label: 'Watch', url: watch },
|
|
71
|
+
{ label: 'Take over', url: watchUrl(cloud, { take: true, session }) },
|
|
72
|
+
],
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ★ ON A COMPUTER THE VIEWER OPENS INSIDE THE APP (the owner, 2026-10-17: "in desktop PWA when I open the cloud computer
|
|
77
|
+
// browser it open a new tab in the browser" → "it is in chrome but not in the PWA"). The viewer lives on its own origin
|
|
78
|
+
// (spaces/browse-connector/_headers), and an installed app sends ANY page outside its own site — a link or a popup —
|
|
79
|
+
// to the browser. So on a computer it is shown in a panel over the Code section; its frame-ancestors names our app's
|
|
80
|
+
// pages only. Opening it again shows the same panel.
|
|
81
|
+
// ★ AND ON A PHONE TOO (the owner, 2026-10-18: "Why can't I get help from the app?" → "Yes"): a phone's link opened a
|
|
82
|
+
// Safari sheet over the installed app; iPhone pauses the app under it, so nothing in the viewer — its ? included — could
|
|
83
|
+
// reach the app. In the panel the viewer is a frame of this page and ? opens Help at once.
|
|
84
|
+
// A COMPUTER = any mouse or touchpad, and a window wider than a phone. Not "the PRIMARY pointer is fine": Chrome on a
|
|
85
|
+
// Windows laptop with a touchscreen can report its primary pointer as coarse, and the panel then never opened there
|
|
86
|
+
// (the owner's ASUS, 2026-10-17 — still sent to Chrome on the panel build).
|
|
87
|
+
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). */
|
|
89
|
+
export function setBrowsePanelSession (session) {
|
|
90
|
+
const f = document.getElementById('browsePanelFrame')
|
|
91
|
+
if (!f || !/^[A-Za-z0-9_-]{1,128}$/.test(String(session || ''))) return
|
|
92
|
+
try { f.contentWindow.postMessage({ ch: 'wb-browse-panel', session }, new URL(f.getAttribute('src')).origin) } catch { /* the panel is closing */ }
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function openBrowsePanel (url) {
|
|
96
|
+
if (!url) return false
|
|
97
|
+
let panel = document.getElementById('browsePanel')
|
|
98
|
+
if (!panel) {
|
|
99
|
+
panel = document.createElement('div')
|
|
100
|
+
panel.id = 'browsePanel'
|
|
101
|
+
panel.style.cssText = 'position:fixed;inset:0;z-index:2147483000;background:#0f1418;display:flex;flex-direction:column'
|
|
102
|
+
// iOS 27 FROSTS the top of an installed web app: a light haze the app hides by keeping that strip in its own background
|
|
103
|
+
// colour. Painted dark here it showed as a grey fade (the owner, iPhone, 2026-10-18: "a kind of fade in the top of the
|
|
104
|
+
// screen", then "Still there is the frost"). So the strip under the status bar (--sat-t, the iOS 27 extra included —
|
|
105
|
+
// codeView.js forwards it into this frame) is the app's background, as everywhere else, and the dark viewer starts below.
|
|
106
|
+
// ⚑ THE × IS IN THE VIEWER'S OWN ROW now (the owner: "the x above the top raw … should move into the top bar"), so there is
|
|
107
|
+
// no bar here — the strip alone keeps the frost off the dark controls: --sat-t, plus 22 px while there is a status bar at
|
|
108
|
+
// all (the frost reached ~95 pt on the owner's iPhone where --sat-t is 74); a phone held sideways has none, so no strip.
|
|
109
|
+
const strip = document.createElement('div')
|
|
110
|
+
strip.style.cssText = 'flex:0 0 auto;height:calc((var(--sat-t, env(safe-area-inset-top)) + min(var(--sat-t, env(safe-area-inset-top)), 22px)) * var(--sat-on, 1));background:var(--bg, #fff)'
|
|
111
|
+
strip.id = 'browsePanelStrip'
|
|
112
|
+
const frame = document.createElement('iframe')
|
|
113
|
+
frame.id = 'browsePanelFrame'; frame.title = "The agent's browser"
|
|
114
|
+
frame.allow = 'fullscreen; clipboard-write; autoplay'
|
|
115
|
+
frame.referrerPolicy = 'no-referrer'
|
|
116
|
+
frame.style.cssText = 'flex:1;width:100%;border:0;background:#000'
|
|
117
|
+
// the viewer shows its own × only when asked (watch.js): this panel hears "leave"; an older one would not
|
|
118
|
+
frame.addEventListener('load', () => { try { frame.contentWindow.postMessage({ ch: 'wb-browse-panel', leave: true }, new URL(frame.getAttribute('src')).origin) } catch { /* */ } })
|
|
119
|
+
panel.append(strip, frame)
|
|
120
|
+
document.body.append(panel)
|
|
121
|
+
playbackSession(true)
|
|
122
|
+
setBrowsing(true)
|
|
123
|
+
addEventListener('resize', onPanelTurn)
|
|
124
|
+
try { if (screen.orientation) screen.orientation.addEventListener('change', onPanelTurn) } catch { /* */ }
|
|
125
|
+
fitStrip()
|
|
126
|
+
noteTurn('open')
|
|
127
|
+
document.addEventListener('keydown', onPanelKey, true)
|
|
128
|
+
}
|
|
129
|
+
const frame = document.getElementById('browsePanelFrame')
|
|
130
|
+
if (frame.getAttribute('src') !== url) frame.src = url
|
|
131
|
+
panel.hidden = false
|
|
132
|
+
try { frame.focus() } catch { /* */ }
|
|
133
|
+
return true
|
|
134
|
+
}
|
|
135
|
+
function onPanelKey (e) { const p = document.getElementById('browsePanel'); if (e.key === 'Escape' && p && !p.hidden) { e.preventDefault(); e.stopPropagation(); closeBrowsePanel() } }
|
|
136
|
+
// ★ THE VIEWER'S ? OPENS HELP (the owner, 2026-10-18: "the help (?) in the browser should open the Help assistance"): the
|
|
137
|
+
// viewer, a frame of the panel, says so to this page, which closes the panel and opens the app's Help assistant.
|
|
138
|
+
let browseHelp = () => {}
|
|
139
|
+
export const setBrowseHelp = (fn) => { browseHelp = typeof fn === 'function' ? fn : () => {} }
|
|
140
|
+
if (typeof addEventListener === 'function') addEventListener('message', (e) => {
|
|
141
|
+
const f = document.getElementById('browsePanelFrame')
|
|
142
|
+
let from = BROWSE_ORIGIN; try { from = new URL(f.getAttribute('src')).origin } catch { /* */ } // the site this panel itself loaded
|
|
143
|
+
if (!f || e.origin !== from || e.source !== f.contentWindow || !e.data) return
|
|
144
|
+
if (e.data.ch === 'wb-browse-leave') { closeBrowsePanel(); return } // the viewer's ×, first in its own row (watch.html #leave)
|
|
145
|
+
if (e.data.ch !== 'wb-browse-help') return
|
|
146
|
+
closeBrowsePanel(); try { browseHelp() } catch { /* */ }
|
|
147
|
+
})
|
|
148
|
+
/** Closing REMOVES it: the viewer's socket goes with it, so a browser nobody watches costs the screen nothing. */
|
|
149
|
+
export function closeBrowsePanel () {
|
|
150
|
+
const p = document.getElementById('browsePanel'); if (!p) return
|
|
151
|
+
document.removeEventListener('keydown', onPanelKey, true)
|
|
152
|
+
p.remove()
|
|
153
|
+
playbackSession(false)
|
|
154
|
+
setBrowsing(false)
|
|
155
|
+
removeEventListener('resize', onPanelTurn)
|
|
156
|
+
try { if (screen.orientation) screen.orientation.removeEventListener('change', onPanelTurn) } catch { /* */ }
|
|
157
|
+
noteTurn('close')
|
|
158
|
+
}
|
|
159
|
+
// SOUND UNDER THE SILENT SWITCH (the owner, iPhone, 2026-10-18: "There is no sound", the ringer off). The viewer's sound is
|
|
160
|
+
// Web Audio, which iOS mutes on silent unless the page is a PLAYER (navigator.audioSession 'playback'). The viewer says so
|
|
161
|
+
// itself, but in the panel it is a frame of another site, and the audio session is the page's — so the app says it while
|
|
162
|
+
// the panel is open, and goes back to the default when it closes. Unproven on a device yet; Safari 17+, elsewhere a no-op.
|
|
163
|
+
// A PHONE MAY TURN SIDEWAYS ONLY WHILE THIS IS OPEN (the owner, 2026-10-18). "Turn your phone back" (space.html #portraitOnly)
|
|
164
|
+
// covers every screen of a phone held sideways — and the panel opens inside the Code FRAME, under the app page's cover
|
|
165
|
+
// (the owner: "it was locked … by the css"). So html.browsing goes on this page AND every same-origin page above it.
|
|
166
|
+
// THE BOOT LOG SAYS WHAT A TURN DID (Settings → Crash trail → Boot log; the owner, 2026-10-18: landscape showed "Turn your
|
|
167
|
+
// phone back" over the browser on Beta, while the same page held sideways in WebKit here lifts it). One line on open, close
|
|
168
|
+
// and every size change while open: the size, whether the app page carries html.browsing, and whether its cover shows.
|
|
169
|
+
let turnT = 0
|
|
170
|
+
// SIDEWAYS THERE IS NO STATUS BAR, so no strip (the owner, landscape full screen: "it is not really full" — a white band
|
|
171
|
+
// the height of the portrait status bar stayed on top: the app's --sat-t keeps its upright value). Wider than tall = none.
|
|
172
|
+
// ⚑ SIDEWAYS BY THE PHONE, NOT BY THIS FRAME (the owner: portrait → landscape → portrait came back "too high without the
|
|
173
|
+
// frost guard"): this page is the Code FRAME, whose size the app re-sets after a turn — read too early it was still wide,
|
|
174
|
+
// so the strip stayed off upright. The phone's own orientation decides, read again as the turn settles.
|
|
175
|
+
const sideways = () => {
|
|
176
|
+
try { const t = screen.orientation && screen.orientation.type; if (t) return t.startsWith('landscape') } catch { /* */ }
|
|
177
|
+
try { return matchMedia('(orientation: landscape)').matches && (window.top.innerWidth > window.top.innerHeight) } catch { return innerWidth > innerHeight }
|
|
178
|
+
}
|
|
179
|
+
// ⚑ AND ITS HEIGHT IS THE LARGEST UPRIGHT STATUS BAR SEEN (the owner's boot log, 2026-10-18: \`browse open … strip 93\`, then
|
|
180
|
+
// \`browse turn 430x932 … strip 24 · portrait-primary\` — after a turn, and after the keyboard opened with no turn at all,
|
|
181
|
+
// the app hands this frame a --sat-t of ~12 px, and the strip sized from it put the controls under the frost again).
|
|
182
|
+
// Upright, the status bar does not shrink: keep the largest --sat-t read upright and size the strip from it in px.
|
|
183
|
+
let satMax = 0
|
|
184
|
+
const satNow = () => { try { const pr = document.createElement('div'); pr.style.cssText = 'position:fixed;top:0;left:0;width:0;visibility:hidden;height:var(--sat-t, env(safe-area-inset-top))'; document.body.appendChild(pr); const h = pr.getBoundingClientRect().height; pr.remove(); return h } catch { return 0 } }
|
|
185
|
+
const fitStrip = () => {
|
|
186
|
+
try {
|
|
187
|
+
const st = document.getElementById('browsePanelStrip'); if (!st) return
|
|
188
|
+
if (sideways()) { st.style.display = 'none'; return }
|
|
189
|
+
satMax = Math.max(satMax, satNow())
|
|
190
|
+
st.style.display = ''; st.style.height = Math.round(satMax + Math.min(satMax, 22)) + 'px'
|
|
191
|
+
} catch { /* */ }
|
|
192
|
+
}
|
|
193
|
+
const onPanelTurn = () => {
|
|
194
|
+
fitStrip(); clearTimeout(turnT)
|
|
195
|
+
for (const ms of [250, 700, 1500]) setTimeout(fitStrip, ms) // a turn lands in steps on iOS (the crash trail caught 430x104 mid-turn)
|
|
196
|
+
turnT = setTimeout(() => { fitStrip(); noteTurn('turn') }, 1600)
|
|
197
|
+
}
|
|
198
|
+
function noteTurn (what) {
|
|
199
|
+
try {
|
|
200
|
+
let w = window, app = null
|
|
201
|
+
for (let i = 0; i < 4 && w; i++) { try { if (w.document.getElementById('portraitOnly')) { app = w; break } } catch { break } if (w === w.parent) break; w = w.parent }
|
|
202
|
+
const top = app || window
|
|
203
|
+
const cover = app ? app.getComputedStyle(app.document.getElementById('portraitOnly')).display : 'no app page'
|
|
204
|
+
const st = document.getElementById('browsePanelStrip'), fe = window.frameElement, fr = fe && fe.getBoundingClientRect(), vv = top.visualViewport
|
|
205
|
+
const where = ` · frame ${innerWidth}x${innerHeight}` + (fr ? ` at top ${Math.round(fr.top)} h ${Math.round(fr.height)}` : '') + (vv ? ` · vv off ${Math.round(vv.offsetTop)} h ${Math.round(vv.height)}` : '') + ` · scrollY ${Math.round(top.scrollY)} · strip ${st ? (st.style.display === 'none' ? 'off' : Math.round(st.getBoundingClientRect().height)) : '-'} · ${(screen.orientation && screen.orientation.type) || '?'}`
|
|
206
|
+
const line = `browse ${what} ${top.innerWidth}x${top.innerHeight} · browsing=${top.document.documentElement.classList.contains('browsing') ? 1 : 0} · cover ${cover}` + where
|
|
207
|
+
const k = 'space:bootlog', a = JSON.parse(localStorage.getItem(k) || '[]'); a.push(new Date().toISOString().slice(11, 23) + ' ' + line); while (a.length > 1000) a.shift(); localStorage.setItem(k, JSON.stringify(a))
|
|
208
|
+
} catch { /* a diagnostic never costs the panel */ }
|
|
209
|
+
}
|
|
210
|
+
function setBrowsing (on) {
|
|
211
|
+
// THE iPHONE APP turns sideways only while this is on (ios/attested-client OrientationBridge.swift; the owner, 2026-11-23): it
|
|
212
|
+
// refuses landscape everywhere else, so the cover below never shows there. Nothing elsewhere has the bridge.
|
|
213
|
+
// …and so does the ANDROID app (android/attested-client OrientationBridge.kt), whose bridge answers at once instead of a promise
|
|
214
|
+
try { if (window.WitbitzOrientation) { const r = window.WitbitzOrientation.landscape(!!on); if (r && typeof r.catch === 'function') r.catch(() => {}) } } catch { /* */ }
|
|
215
|
+
let w = window
|
|
216
|
+
for (let i = 0; i < 4 && w; i++) {
|
|
217
|
+
try { w.document.documentElement.classList.toggle('browsing', on) } catch { break } // a cross-origin parent (the vault) has no cover
|
|
218
|
+
if (w === w.parent) break
|
|
219
|
+
w = w.parent
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function playbackSession (on) {
|
|
223
|
+
try { if (navigator.audioSession) navigator.audioSession.type = on ? 'playback' : 'auto' } catch { /* */ }
|
|
224
|
+
}
|