@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/codeFolders.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// spaces/public/codeFolders.js — "allow this folder": ONE card for a folder outside the project, for the whole conversation.
|
|
2
|
+
//
|
|
3
|
+
// The owner, with a session refused twice reading ~/witbitz-code-pub: "It should ask for permission once for the whole new
|
|
4
|
+
// project like the parent directory which should be enough". OpenCode asks `external_directory` for the folder of EACH file
|
|
5
|
+
// it reaches (`<dirname>/*`) and for each folder a command touches, so every new subfolder asked again — and Auto answered
|
|
6
|
+
// only "once", judging each one. Now the card names the folder the ask belongs to (its git root, or the top folder under
|
|
7
|
+
// home), and allowing it adds `external_directory <folder>/* allow` to the session (the connector: tools/code-folders.mjs,
|
|
8
|
+
// witbitz_code/folders.py). Session rules are last-match-wins and `*` crosses "/" (measured, OpenCode 1.18.30), so
|
|
9
|
+
// everything inside is allowed from then on — for this conversation and the subagents it starts.
|
|
10
|
+
//
|
|
11
|
+
// Pure, shared by the page, the connector and Auto (tools/code-auto.mjs); the Python twin answers the same
|
|
12
|
+
// (tools/code-folders.vectors.json).
|
|
13
|
+
export const FOLDER_ROUTE = '/witbitz/folder'
|
|
14
|
+
|
|
15
|
+
const SYSTEM = ['/bin', '/boot', '/dev', '/etc', '/lib', '/lib32', '/lib64', '/libx32', '/proc', '/root', '/run', '/sbin', '/sys', '/usr', '/var']
|
|
16
|
+
const SECRET_PARTS = new Set(['.ssh', '.aws', '.gnupg', '.kube', '.docker', '.git'])
|
|
17
|
+
const GLOB = /[*?[\]{}]/
|
|
18
|
+
|
|
19
|
+
/** posix.normalize for absolute paths, without node:path (this module also runs in the browser). '' when not absolute. */
|
|
20
|
+
export function normAbs(p) {
|
|
21
|
+
if (typeof p !== 'string' || !p.startsWith('/') || p.includes('\0')) return ''
|
|
22
|
+
const out = []
|
|
23
|
+
for (const part of p.split('/')) {
|
|
24
|
+
if (!part || part === '.') continue
|
|
25
|
+
if (part === '..') out.pop(); else out.push(part)
|
|
26
|
+
}
|
|
27
|
+
return '/' + out.join('/')
|
|
28
|
+
}
|
|
29
|
+
const under = (p, root) => root === '/' ? p.startsWith('/') : p === root || p.startsWith(root + '/')
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The folder an outside path belongs to — what "allow this folder" allows. null when it must not be widened: the home
|
|
33
|
+
* folder itself, "/", a system folder, a secret store, or a hidden folder right under home (~/.config, ~/.local…).
|
|
34
|
+
* dir the directory OpenCode asked for (a pattern's `<dir>` of `<dir>/*`)
|
|
35
|
+
* home this computer's home directory
|
|
36
|
+
* hasGit (path) => whether `path/.git` exists — the nearest one below home (or anywhere, outside home) is the root
|
|
37
|
+
*/
|
|
38
|
+
export function folderRoot(dir, { home = '', hasGit = () => false } = {}) {
|
|
39
|
+
const d = normAbs(dir)
|
|
40
|
+
const h = normAbs(home) === '/' ? '' : normAbs(home) // a home of "/" is no home to go by
|
|
41
|
+
if (!d || d === '/' || (h && d === h) || GLOB.test(d)) return null
|
|
42
|
+
if (d.split('/').some((part) => SECRET_PARTS.has(part))) return null
|
|
43
|
+
if (SYSTEM.some((s) => under(d, s))) return null
|
|
44
|
+
if (h && under(h, d)) return null // an ancestor of home holds home
|
|
45
|
+
const inHome = !!h && under(d, h)
|
|
46
|
+
if (inHome && d.slice(h.length + 1).startsWith('.')) return null
|
|
47
|
+
// the nearest git root — never home or /tmp themselves, or above them (a stray /tmp/.git must not swallow every temp folder)
|
|
48
|
+
for (let p = d; p !== '/' && !(h && p === h) && p !== '/tmp'; p = p.slice(0, p.lastIndexOf('/')) || '/') {
|
|
49
|
+
if (inHome && !under(p, h)) break
|
|
50
|
+
let git = false
|
|
51
|
+
try { git = !!hasGit(p) } catch { git = false }
|
|
52
|
+
if (git) return p
|
|
53
|
+
}
|
|
54
|
+
if (inHome) return h + '/' + d.slice(h.length + 1).split('/')[0]
|
|
55
|
+
if (under(d, '/tmp')) return d === '/tmp' ? '/tmp' : '/tmp/' + d.slice(5).split('/')[0]
|
|
56
|
+
return d
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The directories an external_directory ask names: its patterns' `<dir>` of `<dir>/*`. null when any is not that shape. */
|
|
60
|
+
export function askDirs(ask) {
|
|
61
|
+
const pats = ask && Array.isArray(ask.patterns) ? ask.patterns : []
|
|
62
|
+
if (!pats.length) return null
|
|
63
|
+
const dirs = []
|
|
64
|
+
for (const p of pats) {
|
|
65
|
+
if (typeof p !== 'string' || !p.endsWith('/*')) return null
|
|
66
|
+
const d = normAbs(p.slice(0, -2))
|
|
67
|
+
if (!d || GLOB.test(p.slice(0, -2))) return null
|
|
68
|
+
dirs.push(d)
|
|
69
|
+
}
|
|
70
|
+
return dirs
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The folders to allow for an ask — one per distinct root, in order; null when any of its directories cannot be widened. */
|
|
74
|
+
export function foldersForAsk(ask, opts) {
|
|
75
|
+
if (!ask || ask.permission !== 'external_directory') return null
|
|
76
|
+
const dirs = askDirs(ask)
|
|
77
|
+
if (!dirs) return null
|
|
78
|
+
const roots = []
|
|
79
|
+
for (const d of dirs) {
|
|
80
|
+
const r = folderRoot(d, opts)
|
|
81
|
+
if (!r) return null
|
|
82
|
+
if (!roots.includes(r)) roots.push(r)
|
|
83
|
+
}
|
|
84
|
+
return roots
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The rule that allows a folder. */
|
|
88
|
+
export const folderRule = (root) => ({ permission: 'external_directory', pattern: root + '/*', action: 'allow' })
|
|
89
|
+
|
|
90
|
+
/** The folders a session's rules allow outside its project: every `external_directory <abs>/*` whose LAST matching rule of
|
|
91
|
+
* that exact pattern allows (OpenCode's last-match-wins). */
|
|
92
|
+
export function allowedFolders(rules) {
|
|
93
|
+
const last = new Map()
|
|
94
|
+
for (const r of Array.isArray(rules) ? rules : []) {
|
|
95
|
+
if (!r || r.permission !== 'external_directory' || typeof r.pattern !== 'string' || !r.pattern.endsWith('/*')) continue
|
|
96
|
+
last.set(r.pattern, r.action)
|
|
97
|
+
}
|
|
98
|
+
const out = []
|
|
99
|
+
for (const [pattern, action] of last) {
|
|
100
|
+
const d = normAbs(pattern.slice(0, -2))
|
|
101
|
+
if (action === 'allow' && d && d !== '/' && !GLOB.test(pattern.slice(0, -2)) && !out.includes(d)) out.push(d)
|
|
102
|
+
}
|
|
103
|
+
return out
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Is the absolute path inside one of the folders? */
|
|
107
|
+
export const insideFolders = (abs, folders) => { const a = normAbs(abs); return !!a && (Array.isArray(folders) ? folders : []).some((f) => { const r = normAbs(f); return !!r && r !== '/' && under(a, r) }) }
|
|
108
|
+
|
|
109
|
+
/** Does an external_directory ask fall entirely inside allowed folders? */
|
|
110
|
+
export function foldersCover(ask, folders) {
|
|
111
|
+
const dirs = askDirs(ask)
|
|
112
|
+
return !!dirs && dirs.every((d) => insideFolders(d, folders))
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** "~/witbitz-code-pub" for the card. */
|
|
116
|
+
export const displayPath = (p, home) => { const h = normAbs(home); return h && h !== '/' && under(p, h) ? '~' + p.slice(h.length) : p }
|
package/codeHistory.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// codeHistory: a conversation's messages without re-reading all of them (the owner: "When I change code sessions it
|
|
2
|
+
// reloads every time. Can't it be cached somehow? … only the last part of the conv, and when scrolled back gets the past
|
|
3
|
+
// context. A lazy load will also be fine.").
|
|
4
|
+
//
|
|
5
|
+
// Measured on opencode 1.18.30 (the owner's computer, 2026-09-14):
|
|
6
|
+
// • GET /session/:id/message sent the WHOLE history: "Witbitz 1" was 9,753,679 bytes (136 messages; one message alone
|
|
7
|
+
// 2.5 MB of tool output) — through the relay to a phone on every switch, and again after EVERY step of a turn.
|
|
8
|
+
// • `?limit=N` returns the LAST N messages (the last 20 of that session: 206 KB), oldest first, with an `x-next-cursor`
|
|
9
|
+
// header and `Link: …&before=<cursor>; rel="next"` for the page before them. `before=<message id>` is refused (400).
|
|
10
|
+
// • The cursor is base64url(JSON {"id": <oldest message id>, "time": <its info.time.created>}) — built here it equals
|
|
11
|
+
// the header byte for byte, and walking back 40 at a time returned all 136 messages in order, none twice. The relay
|
|
12
|
+
// does not forward response headers, so the page builds it itself.
|
|
13
|
+
// The page keeps a window: the newest messages, plus whatever older pages were scrolled into, per session in memory.
|
|
14
|
+
|
|
15
|
+
// Sizes from the owner's longest conversation: its newest 30 messages were 1,325 KB, 20 → 206 KB, 8 → 34 KB, 4 → 20 KB
|
|
16
|
+
// (tool output makes recent messages heavy). A turn's step needs only what changed since the last read.
|
|
17
|
+
export const TAIL = 20 // messages read when a conversation opens
|
|
18
|
+
export const STEP_TAIL = 6 // messages re-read after each step of a running turn (more is read only when they do not overlap)
|
|
19
|
+
export const PAGE = 20 // messages read each time you scroll back past the top
|
|
20
|
+
export const CACHED_SESSIONS = 8
|
|
21
|
+
|
|
22
|
+
const b64url = (s) => (typeof btoa === 'function' ? btoa(s) : Buffer.from(s, 'binary').toString('base64')).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
|
|
23
|
+
|
|
24
|
+
/** The cursor for the page BEFORE `message` (the oldest one you hold) — '' when it cannot be built. */
|
|
25
|
+
export function cursorBefore(message) {
|
|
26
|
+
const info = (message && message.info) || {}
|
|
27
|
+
const time = info.time && Number(info.time.created)
|
|
28
|
+
if (typeof info.id !== 'string' || !info.id || !Number.isFinite(time)) return ''
|
|
29
|
+
return b64url(JSON.stringify({ id: info.id, time }))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The query for the newest `limit` messages, or the `limit` before `cursor`. */
|
|
33
|
+
export const pageQuery = ({ limit = TAIL, cursor = '' } = {}) => `limit=${limit}${cursor ? `&before=${encodeURIComponent(cursor)}` : ''}`
|
|
34
|
+
|
|
35
|
+
/** Did a page come back full, i.e. may there be more before it? */
|
|
36
|
+
export const mayHaveMore = (page, limit) => Array.isArray(page) && page.length >= limit
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Fold a freshly read TAIL into the messages you hold. The tail's oldest message is found in yours, and everything from
|
|
40
|
+
* there on is taken from the server (a step's parts grew, a message was added — or removed by an undo that went final).
|
|
41
|
+
* No overlap (more new messages than one tail, e.g. after a long time offline): `overlap:false` — the caller reads further
|
|
42
|
+
* back, or starts a new window.
|
|
43
|
+
*/
|
|
44
|
+
export function mergeTail(current, tail) {
|
|
45
|
+
const cur = Array.isArray(current) ? current : []
|
|
46
|
+
if (!Array.isArray(tail)) return { messages: cur, overlap: true }
|
|
47
|
+
if (!tail.length) return { messages: [], overlap: true } // the server holds none: the conversation is empty
|
|
48
|
+
const at = cur.findIndex((m) => m && m.info && m.info.id === tail[0].info.id)
|
|
49
|
+
if (at < 0) return { messages: tail, overlap: false }
|
|
50
|
+
return { messages: [...cur.slice(0, at), ...tail], overlap: true }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** An older page in front of the messages you hold, without a message twice. */
|
|
54
|
+
export function prependOlder(current, older) {
|
|
55
|
+
const cur = Array.isArray(current) ? current : []
|
|
56
|
+
const have = new Set(cur.map((m) => m && m.info && m.info.id))
|
|
57
|
+
return [...(older || []).filter((m) => m && m.info && !have.has(m.info.id)), ...cur]
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Per-session windows, the most recently used kept. { messages, cursor } — cursor '' once the start is reached. */
|
|
61
|
+
export class HistoryCache {
|
|
62
|
+
constructor(max = CACHED_SESSIONS) { this.max = max; this.map = new Map() }
|
|
63
|
+
get(sid) {
|
|
64
|
+
const v = this.map.get(sid)
|
|
65
|
+
if (v) { this.map.delete(sid); this.map.set(sid, v) }
|
|
66
|
+
return v || null
|
|
67
|
+
}
|
|
68
|
+
set(sid, value) {
|
|
69
|
+
if (!sid) return
|
|
70
|
+
this.map.delete(sid)
|
|
71
|
+
this.map.set(sid, value)
|
|
72
|
+
while (this.map.size > this.max) this.map.delete(this.map.keys().next().value)
|
|
73
|
+
}
|
|
74
|
+
drop(sid) { this.map.delete(sid) }
|
|
75
|
+
clear() { this.map.clear() }
|
|
76
|
+
}
|
package/codeLanguage.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// spaces/public/codeLanguage.js — the language the person writes in, so the coding agent narrates in it.
|
|
2
|
+
//
|
|
3
|
+
// The owner: "when deepseek is in a hebew project it thinks in english". Measured (2026-09-14, DeepSeek V4 Flash through
|
|
4
|
+
// OpenCode, a Hebrew request): no reasoning comes back — the English was the NARRATION between steps ("I'll analyze the
|
|
5
|
+
// case file…"), because everything around the model is English (OpenCode's prompt, the tools, this page's PROGRESS rule).
|
|
6
|
+
// An English "answer in the person's language" line changed nothing; a line written IN HEBREW, first in the turn's
|
|
7
|
+
// `system`, made the narration Hebrew and kept the answers right at the same token cost (spaces/test/codeLanguage.test.mjs).
|
|
8
|
+
// Only Hebrew is measured; another language gets no line until it is.
|
|
9
|
+
|
|
10
|
+
export const HEBREW_LINE = 'שפה: האדם כותב בעברית. כתוב בעברית כל טקסט שאתה מציג — גם את עדכוני ההתקדמות הקצרים לפני פעולה ובין שלבים, וגם את התשובה. שמות קבצים, פקודות וקוד נשארים כפי שהם.'
|
|
11
|
+
|
|
12
|
+
// …and beside the question itself. In a long session (the owner's: ≈677k tokens, mostly English narration) the line alone
|
|
13
|
+
// was not enough — the answer opened with an English paragraph. A synthetic part right after the person's words was.
|
|
14
|
+
export const HEBREW_NUDGE = '(ענה בעברית בלבד — גם עדכוני ההתקדמות, ההסברים וכל משפט אחר שאתה כותב. שמות קבצים, פקודות וקוד נשארים כפי שהם.)'
|
|
15
|
+
|
|
16
|
+
const HEBREW = /[א-ת]/g
|
|
17
|
+
const LATIN = /[A-Za-z]/g
|
|
18
|
+
|
|
19
|
+
/** 'he' | 'other' | '' (too few letters to say). Code, links and path-like words are left out of the count. */
|
|
20
|
+
export function languageOf(text) {
|
|
21
|
+
const words = String(text || '')
|
|
22
|
+
.replace(/```[\s\S]*?```/g, ' ')
|
|
23
|
+
.replace(/`[^`]*`/g, ' ')
|
|
24
|
+
.replace(/\bhttps?:\/\/\S+/g, ' ')
|
|
25
|
+
.split(/\s+/)
|
|
26
|
+
.filter((w) => !/[/\\._]/.test(w.replace(/^[א-ת]-/, '')) || !/[A-Za-z]/.test(w))
|
|
27
|
+
.join(' ')
|
|
28
|
+
const he = (words.match(HEBREW) || []).length
|
|
29
|
+
const latin = (words.match(LATIN) || []).length
|
|
30
|
+
if (he + latin < 3) return ''
|
|
31
|
+
return he / (he + latin) >= 0.3 ? 'he' : 'other'
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The line for the person's messages, newest first: the first one that says anything decides. */
|
|
35
|
+
export function languageLine(texts) {
|
|
36
|
+
for (const t of texts || []) {
|
|
37
|
+
const lang = languageOf(t)
|
|
38
|
+
if (lang === 'he') return HEBREW_LINE
|
|
39
|
+
if (lang) return ''
|
|
40
|
+
}
|
|
41
|
+
return ''
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The turn's instructions with the language line FIRST — where it was measured to work. */
|
|
45
|
+
export function withLanguage(system, texts) {
|
|
46
|
+
const line = languageLine(texts)
|
|
47
|
+
return line ? `${line}\n\n${system}` : system
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The reminder that rides beside the person's words on a Hebrew turn — a synthetic part (the model reads it, the
|
|
51
|
+
* transcript does not show it) — or null. */
|
|
52
|
+
export function languageNudge(texts) {
|
|
53
|
+
return languageLine(texts) === HEBREW_LINE ? { type: 'text', text: HEBREW_NUDGE, synthetic: true } : null
|
|
54
|
+
}
|
package/codeMkdir.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// spaces/public/codeMkdir.js — the page-side constant + helper for "New folder" in the New-session picker
|
|
2
|
+
// (tools/code-mkdir.mjs is the connector side; this module holds what the browser needs, so no fs leaks into the page).
|
|
3
|
+
// The route is connector-owned and never reaches OpenCode — the page names the home (directory) and the relative path
|
|
4
|
+
// under it (path) it is already browsing, plus one clean leaf (name). Pure: no DOM, no fs.
|
|
5
|
+
export const MKDIR_ROUTE = '/witbitz/mkdir'
|
|
6
|
+
|
|
7
|
+
/** Build the mkdir request path: `/witbitz/mkdir?path=<rel>` (withDir appends `directory=`). */
|
|
8
|
+
export const mkdirPath = (rel) => MKDIR_ROUTE + (rel ? '?path=' + encodeURIComponent(rel) : '')
|
package/codeModes.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// spaces/public/codeModes.js — the Code composer's ACCEPT EDITS mode, as OpenCode permission rules.
|
|
2
|
+
//
|
|
3
|
+
// The owner, beside Claude Code's modes: "What about an equivalent of accept edits" — and chose "secrets still ask".
|
|
4
|
+
// Unlike Auto (decided by the connector), Accept edits is decided by OpenCode ITSELF: the page appends rules to the
|
|
5
|
+
// session (PATCH /session/:id {permission}), so it holds with every phone closed and on any connector.
|
|
6
|
+
//
|
|
7
|
+
// Measured on opencode 1.18.30 (the evaluator and matcher below are copied from its bundle, and a real turn confirmed it):
|
|
8
|
+
// • evaluate = rules.flat().findLast(match permission && match pattern) ?? ask — the LAST matching rule wins
|
|
9
|
+
// • PATCH /session/:id {permission} APPENDS to the session's rules; it never replaces them
|
|
10
|
+
// • the edit/write/apply_patch tools ask as `edit`, with the path RELATIVE to the worktree ("src/a.ts", ".env")
|
|
11
|
+
// • a wildcard `*` crosses "/", the match is anchored and case-sensitive
|
|
12
|
+
// So switching appends: Accept edits = allow every edit, then ask again for protected files; Manual = one "ask" rule.
|
|
13
|
+
// Edits outside the project still ask first through `external_directory`, which these rules never touch.
|
|
14
|
+
|
|
15
|
+
/** OpenCode 1.18 Wildcard.match. */
|
|
16
|
+
export const unsuitableCodeModels = catalog => (catalog || []).filter(m => m?.maxTools).map(m => String(m.wire || '')).filter(Boolean)
|
|
17
|
+
|
|
18
|
+
export function wildcardMatch(str, pattern) {
|
|
19
|
+
const s = String(str).replaceAll('\\', '/')
|
|
20
|
+
let re = String(pattern).replaceAll('\\', '/').replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*').replace(/\?/g, '.')
|
|
21
|
+
if (re.endsWith(' .*')) re = re.slice(0, -3) + '( .*)?'
|
|
22
|
+
return new RegExp('^' + re + '$', 's').test(s)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** OpenCode 1.18 Permission.evaluate over one ruleset → 'allow' | 'ask' | 'deny'. */
|
|
26
|
+
export function evaluateRules(permission, pattern, rules) {
|
|
27
|
+
const hit = (Array.isArray(rules) ? rules : []).findLast((r) => r && wildcardMatch(permission, r.permission) && wildcardMatch(pattern, r.pattern))
|
|
28
|
+
return hit ? hit.action : 'ask'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Protected files — the same families tools/code-auto.mjs keeps out of Auto's fast allow. Each name is matched at the
|
|
32
|
+
// project root AND under any folder ("*/" — a wildcard crosses "/"). OpenCode's match is case-sensitive, so the common
|
|
33
|
+
// spellings are listed.
|
|
34
|
+
const DIRS = ['.git', '.ssh', '.aws', '.gnupg', '.kube', '.docker']
|
|
35
|
+
const NAMES = ['.env', '.env.*', '.npmrc', '.netrc', '.pypirc', ...['id_rsa', 'id_dsa', 'id_ecdsa', 'id_ed25519'].flatMap((k) => [k, k + '.pub'])]
|
|
36
|
+
const KEY_EXTS = ['pem', 'key', 'p12', 'pfx', 'jks', 'keystore'].flatMap((e) => [e, e.toUpperCase()])
|
|
37
|
+
const WORDS = ['secret', 'Secret', 'SECRET', 'credential', 'Credential', 'CREDENTIAL']
|
|
38
|
+
const SAFE_ENV = ['.env.example', '.env.sample', '.env.template', '.env.dist']
|
|
39
|
+
|
|
40
|
+
const rule = (pattern, action) => ({ permission: 'edit', pattern, action })
|
|
41
|
+
const atAnyDepth = (p) => [p, '*/' + p]
|
|
42
|
+
|
|
43
|
+
/** Appended to switch a session to Accept edits. */
|
|
44
|
+
export function acceptEditsRules() {
|
|
45
|
+
return [
|
|
46
|
+
rule('*', 'allow'),
|
|
47
|
+
...NAMES.flatMap(atAnyDepth).map((p) => rule(p, 'ask')),
|
|
48
|
+
...SAFE_ENV.flatMap(atAnyDepth).map((p) => rule(p, 'allow')), // a template is not a secret — but only here: the
|
|
49
|
+
...DIRS.flatMap((d) => atAnyDepth(d + '/*')).map((p) => rule(p, 'ask')), // asks after it still win (.git/…, secrets/…)
|
|
50
|
+
...KEY_EXTS.map((e) => rule('*.' + e, 'ask')),
|
|
51
|
+
...WORDS.map((w) => rule('*' + w + '*', 'ask')),
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Appended to go back: the last matching rule wins, so one rule undoes all of the above. */
|
|
56
|
+
export const askEditsRules = () => [rule('*', 'ask')]
|
|
57
|
+
|
|
58
|
+
/** Whether a session's rules let an ordinary edit through without asking — how the chip knows the mode. */
|
|
59
|
+
export const acceptsEdits = (rules) => evaluateRules('edit', 'src/index.ts', rules) === 'allow'
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// codeOrphanKeys.js — COMPUTERS THAT HOLD CODING KEYS BUT ARE ON NO LIST (the owner, 2026-10-29: "Why does my laptop appear twice?"
|
|
2
|
+
// — a new laptop was refused "this account already codes on 3 computers (Laptop, Laptop (WSL), Laptop)", and only one
|
|
3
|
+
// "Laptop" was a computer the account still knew). The coding keys live per pairing at the control plane
|
|
4
|
+
// (control-plane/src/lib/codeKeys.mjs); a computer set up again without unpairing first is a NEW pairing, and the old one's
|
|
5
|
+
// keys stay live under the same name, counted against the account's computers (one free, three when invited). The Computers list is the account's registry, so
|
|
6
|
+
// its Remove could never reach them. The control plane has listed every computer with live keys all along
|
|
7
|
+
// (POST /v1/spaces/code-keys/list); this reads it and offers Remove for the ones the registry does not name.
|
|
8
|
+
export const CODE_KEYS_LIST = 'https://api.witbitz.chat/v1/spaces/code-keys/list'
|
|
9
|
+
export const CODE_KEYS_REVOKE = 'https://api.witbitz.chat/v1/spaces/code-keys/revoke'
|
|
10
|
+
|
|
11
|
+
/** The key rows whose computer is on none of `computers` (the registry's entries, by id). */
|
|
12
|
+
export function orphanKeyRows (rows, computers) {
|
|
13
|
+
const known = new Set((computers || []).map((c) => c && c.id).filter(Boolean))
|
|
14
|
+
return (Array.isArray(rows) ? rows : []).filter((r) => r && typeof r.computerId === 'string' && !known.has(r.computerId))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const post = async (fetchImpl, url, body) => {
|
|
18
|
+
const r = await fetchImpl(url, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) })
|
|
19
|
+
const j = await r.json().catch(() => null)
|
|
20
|
+
if (!r.ok) throw new Error((j && j.error && (j.error.message || j.error.code)) || 'HTTP ' + r.status)
|
|
21
|
+
return (j && j.data) || {}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Every computer of the account with live coding keys: [{ keyId, computerId, name, createdAt }]. */
|
|
25
|
+
export async function listKeyComputers (token, fetchImpl = (...a) => fetch(...a)) {
|
|
26
|
+
const d = await post(fetchImpl, CODE_KEYS_LIST, { idToken: token })
|
|
27
|
+
return Array.isArray(d.computers) ? d.computers : []
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Cancel one computer's coding keys (as removing a listed computer does, drawer.js revokeCodeKeys). → true when revoked. */
|
|
31
|
+
export async function revokeKeyComputer (token, computerId, fetchImpl = (...a) => fetch(...a)) {
|
|
32
|
+
const d = await post(fetchImpl, CODE_KEYS_REVOKE, { idToken: token, computerId })
|
|
33
|
+
return !!d.revoked
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** "added 12 Oct" — which of two same-named computers is the old one. */
|
|
37
|
+
export function addedOn (ms, now = Date.now()) {
|
|
38
|
+
const t = Number(ms); if (!(t > 0)) return ''
|
|
39
|
+
const d = new Date(t)
|
|
40
|
+
const o = { day: 'numeric', month: 'short', ...(new Date(now).getFullYear() !== d.getFullYear() ? { year: 'numeric' } : {}) }
|
|
41
|
+
try { return 'added ' + d.toLocaleDateString(undefined, o) } catch { return 'added ' + d.toISOString().slice(0, 10) }
|
|
42
|
+
}
|
package/codeOutputs.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// spaces/public/codeOutputs.js — the files a Code reply PRODUCED, previewed under it without asking.
|
|
2
|
+
//
|
|
3
|
+
// The owner, after an agent fixed a PDF and — asked to "upload it here" — answered that a PDF cannot be shown in the chat:
|
|
4
|
+
// "I think the user should automatically see a preview". Its answer had named the file's full path all along.
|
|
5
|
+
//
|
|
6
|
+
// A result is a file the reply WROTE or EDITED (its write/edit tools), or one its ANSWER names that CHANGED while the reply
|
|
7
|
+
// ran (the page checks the file's time on the computer: a folder listing that named an old gated_temp2.txt is not a result —
|
|
8
|
+
// "I think the rule for showing files is not good") — the text after its last step, not the narration between steps (the owner's "something went wrong": notes about a test in /tmp named min.html
|
|
9
|
+
// and min.pdf, which read as files in the session folder, while the answer's `דוח מסכם.pdf` was taken for a command
|
|
10
|
+
// because it has a space) — never one it only read, never a path in your own prompt. Only kinds a phone can show preview (a PDF's first page, a picture, the first lines of
|
|
11
|
+
// a table or a text); office files, archives and media get a chip with Download; code gets nothing (its diff is in the
|
|
12
|
+
// steps). Only inside the session's folder — the connector serves nothing else (tools/code-outputs.mjs) — and never a
|
|
13
|
+
// name that looks like a secret. Pure: no DOM, no fs — the page and the JS connector import it; the Python connector
|
|
14
|
+
// holds to the same cases (spaces/test/codeOutputs.vectors.json).
|
|
15
|
+
|
|
16
|
+
/** The connector-owned route a page asks for a produced file on (never forwarded to OpenCode). */
|
|
17
|
+
export const OUTPUT_ROUTE = '/witbitz/output'
|
|
18
|
+
export const MAX_OUTPUTS = 6
|
|
19
|
+
export const MAX_PATH = 4096
|
|
20
|
+
|
|
21
|
+
const KINDS = {
|
|
22
|
+
pdf: 'pdf',
|
|
23
|
+
png: 'image', jpg: 'image', jpeg: 'image', gif: 'image', webp: 'image',
|
|
24
|
+
csv: 'table', tsv: 'table',
|
|
25
|
+
md: 'text', markdown: 'text', txt: 'text',
|
|
26
|
+
docx: 'file', doc: 'file', xlsx: 'file', xls: 'file', pptx: 'file', ppt: 'file', odt: 'file', ods: 'file', odp: 'file',
|
|
27
|
+
rtf: 'file', zip: 'file', epub: 'file', heic: 'file', svg: 'file', html: 'file', htm: 'file',
|
|
28
|
+
mp3: 'file', wav: 'file', m4a: 'file', mp4: 'file', mov: 'file',
|
|
29
|
+
}
|
|
30
|
+
const MIME = {
|
|
31
|
+
pdf: 'application/pdf', png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', gif: 'image/gif', webp: 'image/webp',
|
|
32
|
+
csv: 'text/csv', tsv: 'text/tab-separated-values', md: 'text/markdown', markdown: 'text/markdown', txt: 'text/plain',
|
|
33
|
+
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', doc: 'application/msword',
|
|
34
|
+
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', xls: 'application/vnd.ms-excel',
|
|
35
|
+
pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation', ppt: 'application/vnd.ms-powerpoint',
|
|
36
|
+
odt: 'application/vnd.oasis.opendocument.text', ods: 'application/vnd.oasis.opendocument.spreadsheet',
|
|
37
|
+
odp: 'application/vnd.oasis.opendocument.presentation', rtf: 'application/rtf', zip: 'application/zip',
|
|
38
|
+
epub: 'application/epub+zip', heic: 'image/heic', svg: 'image/svg+xml', html: 'text/html', htm: 'text/html',
|
|
39
|
+
mp3: 'audio/mpeg', wav: 'audio/wav', m4a: 'audio/mp4', mp4: 'video/mp4', mov: 'video/quicktime',
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The extension of a file whose name does not start with a dot (`.pdf` alone is a dot-file, not a PDF). */
|
|
43
|
+
const extOf = (path) => { const m = /(?:^|\/)[^/.][^/]*\.([A-Za-z0-9]+)$/.exec(String(path || '')); return m ? m[1].toLowerCase() : '' }
|
|
44
|
+
|
|
45
|
+
/** 'pdf' | 'image' | 'table' | 'text' | 'file' — or null: not something to show. */
|
|
46
|
+
export const outputKind = (path) => KINDS[extOf(path)] || null
|
|
47
|
+
export const outputMime = (path) => MIME[extOf(path)] || 'application/octet-stream'
|
|
48
|
+
|
|
49
|
+
// The same rule Auto mode uses for a name that looks like a secret (tools/code-auto.mjs sensitivePath — the Python
|
|
50
|
+
// connector uses auto.py's): a .git/.ssh/.aws/… folder on the way, a .env, a private key, "secret"/"credential".
|
|
51
|
+
const SENSITIVE_BASE = /^(\.env(\..+)?|\.npmrc|\.netrc|\.pypirc|id_(rsa|dsa|ecdsa|ed25519)(\.pub)?)$/
|
|
52
|
+
const SAFE_ENV = /^\.env\.(example|sample|template|dist)$/
|
|
53
|
+
/** `rel`: the path below the session folder, starting with "/". */
|
|
54
|
+
export function sensitivePath(rel) {
|
|
55
|
+
const parts = String(rel || '').split('/')
|
|
56
|
+
const base = parts[parts.length - 1] || ''
|
|
57
|
+
if (parts.some((p) => ['.git', '.ssh', '.aws', '.gnupg', '.kube', '.docker'].includes(p))) return true
|
|
58
|
+
if (SENSITIVE_BASE.test(base) && !SAFE_ENV.test(base)) return true
|
|
59
|
+
if (/\.(pem|key|p12|pfx|jks|keystore)$/i.test(base)) return true
|
|
60
|
+
return /secret|credential/i.test(base)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** A path a page may ask for: absolute, at most 4096 characters, one line, no NUL. */
|
|
64
|
+
export const validOutputPath = (p) => typeof p === 'string' && p.startsWith('/') && p.length <= MAX_PATH && !/[\0\r\n]/.test(p)
|
|
65
|
+
|
|
66
|
+
/** posix normalize of an absolute path; null when it is not absolute. */
|
|
67
|
+
function normalize(p) {
|
|
68
|
+
if (!String(p).startsWith('/')) return null
|
|
69
|
+
const out = []
|
|
70
|
+
for (const seg of String(p).split('/')) {
|
|
71
|
+
if (!seg || seg === '.') continue
|
|
72
|
+
if (seg === '..') { out.pop(); continue }
|
|
73
|
+
out.push(seg)
|
|
74
|
+
}
|
|
75
|
+
return '/' + out.join('/')
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const EXT_ALT = Object.keys(KINDS).join('|')
|
|
79
|
+
const BARE = new RegExp(`(?:^|[\\s(\\[<"'«])((?:\\.{1,2}\\/|\\/)?[^\\s\`'"()<>\\[\\]«»]+\\.(?:${EXT_ALT}))(?=$|[\\s)\\]>"'».,;:!?])`, 'giu')
|
|
80
|
+
|
|
81
|
+
// What a command in backticks has and a file name does not: a flag, a pipe or redirect, &&, ;, $, =, a glob.
|
|
82
|
+
const COMMANDISH = /(?:^|\s)--?[A-Za-z]|[|&;<>$=*]/
|
|
83
|
+
|
|
84
|
+
const escapeRe = (x) => x.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&')
|
|
85
|
+
/** Candidate paths an answer names: whole `code spans`; then, outside them, paths under the session's folder written out
|
|
86
|
+
* in full — matched from the folder itself, because a folder name with a space ("תיקייה 1") would otherwise be cut at the
|
|
87
|
+
* space into a wrong relative path; then bare tokens in what is left. */
|
|
88
|
+
function namedIn(text, dir) {
|
|
89
|
+
const s = String(text || '')
|
|
90
|
+
const out = []
|
|
91
|
+
for (const m of s.matchAll(/`([^`\n]{1,4096})`/g)) out.push({ raw: m[1].trim(), spaced: true })
|
|
92
|
+
let rest = s.replace(/`[^`\n]*`/g, ' ')
|
|
93
|
+
const underDir = new RegExp(`${escapeRe(dir)}\\/[^\\n\`<>"]*?\\.(?:${EXT_ALT})(?=$|[\\s)\\]>"'».,;:!?])`, 'giu')
|
|
94
|
+
rest = rest.replace(underDir, (m) => { out.push({ raw: m, spaced: false }); return ' ' })
|
|
95
|
+
for (const m of rest.matchAll(BARE)) out.push({ raw: m[1], spaced: false })
|
|
96
|
+
return out
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The results of one reply: `messages` is the run of assistant messages after a prompt (user messages are skipped).
|
|
101
|
+
* → [{path, kind, source: 'wrote'|'shot'|'named'}] — files written first, then screenshots, each once, at most MAX_OUTPUTS.
|
|
102
|
+
*/
|
|
103
|
+
export function replyOutputs(messages, { directory = '', session = '' } = {}) {
|
|
104
|
+
const dir = normalize(directory)
|
|
105
|
+
if (!dir || dir === '/') return []
|
|
106
|
+
const seen = new Set()
|
|
107
|
+
const out = []
|
|
108
|
+
const take = (raw, source, { spaced = false, under = dir } = {}) => {
|
|
109
|
+
if (out.length >= MAX_OUTPUTS || typeof raw !== 'string' || !raw || raw.includes('://') || raw.startsWith('~')) return
|
|
110
|
+
if (!raw.startsWith('/') && spaced && /\s/.test(raw) && COMMANDISH.test(raw)) return // a command in backticks, not a relative path
|
|
111
|
+
const abs = normalize(raw.startsWith('/') ? raw : `${dir}/${raw}`)
|
|
112
|
+
if (!abs || !validOutputPath(abs) || !abs.startsWith(under + '/') || seen.has(abs)) return
|
|
113
|
+
const kind = outputKind(abs)
|
|
114
|
+
if (!kind || sensitivePath(abs.slice(dir.length))) return
|
|
115
|
+
seen.add(abs)
|
|
116
|
+
out.push({ path: abs, kind, source })
|
|
117
|
+
}
|
|
118
|
+
const assistant = (Array.isArray(messages) ? messages : []).filter((m) => m && m.info && m.info.role === 'assistant')
|
|
119
|
+
const parts = assistant.flatMap((m) => (Array.isArray(m.parts) ? m.parts : []))
|
|
120
|
+
for (const p of parts) {
|
|
121
|
+
if (p && p.type === 'tool' && (p.tool === 'write' || p.tool === 'edit') && p.state && p.state.status === 'completed') {
|
|
122
|
+
take(p.state.input && p.state.input.filePath, 'wrote')
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// THE AGENT'S SCREENSHOTS (the owner, 2026-10-25: "how can I get a screen snapshot in the chat"): browser_screenshot saves
|
|
126
|
+
// into <home>/.witbitz/screens/<this session>/ (tools/browse-cdp.mjs) — outside the project, served for this session only
|
|
127
|
+
// (tools/code-outputs.mjs `shots`). Taken from the tool's own result, so a path the answer merely names never reaches there.
|
|
128
|
+
if (/^[A-Za-z0-9_-]{1,128}$/.test(String(session))) {
|
|
129
|
+
const shot = new RegExp(`(\\/[^\\s'"]*\\/\\.witbitz\\/screens\\/${session})\\/screen-[A-Za-z0-9-]+\\.jpg`)
|
|
130
|
+
for (const p of parts) {
|
|
131
|
+
if (!p || p.type !== 'tool' || p.tool !== 'browser_screenshot' || !p.state || p.state.status !== 'completed') continue
|
|
132
|
+
const m = shot.exec(String(p.state.output || ''))
|
|
133
|
+
if (m) take(m[0], 'shot', { under: m[1] })
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const lastStep = parts.map((p) => !!p && p.type === 'tool').lastIndexOf(true)
|
|
137
|
+
for (const p of parts.slice(lastStep + 1)) {
|
|
138
|
+
if (p && p.type === 'text' && !p.synthetic) for (const c of namedIn(p.text, dir)) take(c.raw, 'named', c)
|
|
139
|
+
}
|
|
140
|
+
return out
|
|
141
|
+
}
|
package/codeProgress.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// codeProgress: what a confidential model is doing while nothing of its answer has reached OpenCode yet.
|
|
2
|
+
//
|
|
3
|
+
// The owner, watching Kimi K3 · confidential show "Thinking…" for minutes: "Why can't we see what he is thinking about".
|
|
4
|
+
// Measured on that turn: no thinking was sent at all (0 reasoning tokens) — 154 s went to reading a 78,518-token
|
|
5
|
+
// conversation before the first word, and a later step spent 4½ minutes writing a whole document as ONE tool call, which
|
|
6
|
+
// the confidential proxy holds back until TrustedRouter's receipt verifies. OpenCode cannot be told any of that (its AI SDK
|
|
7
|
+
// runs every tool call still open when a stream closes), so the proxy tells the connector, and the connector tells the
|
|
8
|
+
// phone: { t:'progress', sessionID, label, phase, attempt, tool?, subject?, chars?, bytes? } (tools/code-confidential.mjs).
|
|
9
|
+
// Never the tool call's contents — its name, the file it names, and how big it has grown.
|
|
10
|
+
|
|
11
|
+
export const PHASES = new Set(['waiting', 'answering', 'writing', 'checking', 'retrying', 'end'])
|
|
12
|
+
|
|
13
|
+
const str = (v, max) => (typeof v === 'string' ? v.slice(0, max) : '')
|
|
14
|
+
const num = (v) => (Number.isFinite(v) && v >= 0 ? v : 0)
|
|
15
|
+
|
|
16
|
+
/** A progress message from the connector, checked — or null. */
|
|
17
|
+
export function normProgress(m) {
|
|
18
|
+
if (!m || typeof m !== 'object') return null
|
|
19
|
+
if (typeof m.sessionID !== 'string' || !/^ses[A-Za-z0-9_-]{1,80}$/.test(m.sessionID)) return null
|
|
20
|
+
if (!PHASES.has(m.phase)) return null
|
|
21
|
+
return {
|
|
22
|
+
sessionID: m.sessionID,
|
|
23
|
+
phase: m.phase,
|
|
24
|
+
label: str(m.label, 60),
|
|
25
|
+
attempt: Math.min(num(m.attempt) || 1, 9),
|
|
26
|
+
tool: str(m.tool, 40),
|
|
27
|
+
subject: str(m.subject, 200),
|
|
28
|
+
chars: num(m.chars),
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const fileName = (p) => String(p).split(/[\\/]/).filter(Boolean).pop() || ''
|
|
33
|
+
const size = (n) => (n >= 1000 ? `${Math.round(n / 1000).toLocaleString('en-US')} KB` : '')
|
|
34
|
+
|
|
35
|
+
function writingWhat(tool, subject) {
|
|
36
|
+
const file = fileName(subject)
|
|
37
|
+
if (tool === 'write') return file ? `Writing ${file}` : 'Writing a file'
|
|
38
|
+
if (tool === 'edit' || tool === 'multiedit' || tool === 'patch' || tool === 'apply_patch') return file ? `Editing ${file}` : 'Editing a file'
|
|
39
|
+
if (tool === 'bash') return 'Preparing a command'
|
|
40
|
+
if (tool === 'todowrite') return 'Updating the to-do list'
|
|
41
|
+
if (tool === 'task') return 'Starting an agent'
|
|
42
|
+
return tool ? `Preparing ${tool}` : 'Preparing a step'
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The working line's words for a progress report — '' when the transcript itself says it better (words are arriving). */
|
|
46
|
+
export function progressLine(p) {
|
|
47
|
+
if (!p) return ''
|
|
48
|
+
const who = p.label || 'The model'
|
|
49
|
+
if (p.phase === 'waiting') return p.attempt > 1 ? `Asking ${who} again` : `${who} is reading the conversation`
|
|
50
|
+
if (p.phase === 'writing') { const s = size(p.chars), what = writingWhat(p.tool, p.subject); return s ? `${what} · ${s}` : what }
|
|
51
|
+
if (p.phase === 'checking') return "Checking TrustedRouter's receipt"
|
|
52
|
+
if (p.phase === 'retrying') return 'TrustedRouter renewed its proof — asking again'
|
|
53
|
+
return ''
|
|
54
|
+
}
|