heyquilt 0.3.176 → 0.3.178
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/RELEASES.md +16 -0
- package/bin/quilt.js +1 -1
- package/package.json +2 -2
- package/src/agent-task-workflow.js +15 -3
- package/src/connection.js +1 -9
- package/src/control.js +9 -3
- package/src/duties.js +2 -4
- package/src/gitstate.js +174 -10
- package/src/hooks.js +2 -2
- package/src/identity.js +1 -1
- package/src/mcp.js +7 -21
- package/src/now-summary.js +2 -4
- package/src/pathrules.js +1 -1
- package/src/protocol.js +2 -2
- package/src/relay-ask.js +2 -3
- package/src/relay-live-write.js +0 -1
- package/src/relay-mcp.js +7 -48
- package/src/relay-prune.js +1 -2
- package/src/relay-turn-sync.js +11 -37
- package/src/server.js +20 -287
- package/src/session.js +399 -240
- package/src/setup.js +17 -27
- package/src/status.js +3 -8
- package/src/ui/agent-guide.js +8 -17
- package/src/ui/app.css +22 -121
- package/src/ui/common.js +1 -4
- package/src/ui/feedback.js +3 -3
- package/src/ui/fileview.js +6 -12
- package/src/ui/rail-model.js +19 -35
- package/src/ui/rail.js +13 -153
- package/src/ui/session.js +63 -146
- package/src/ui/tree.js +5 -28
- package/src/ui-server.js +0 -4
- package/src/boxes.js +0 -36
- package/src/ui/boxes.js +0 -80
package/src/server.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Relay server: holds one shared Yjs document per room, relays updates and
|
|
2
2
|
// presence between clients, stores files shared in chat, and persists rooms
|
|
3
|
-
// to disk. It checks who each client is (see identity.js)
|
|
4
|
-
// room's boxes (someone's unfinished work on a file, until it's committed).
|
|
3
|
+
// to disk. It checks who each client is (see identity.js).
|
|
5
4
|
// It holds no files: nobody's write is ever refused or undone because someone
|
|
6
5
|
// else is working on the same file (no-holds, 2026-11-13). Safe to
|
|
7
6
|
// run on the public internet: rooms need their secret, creating rooms can
|
|
@@ -42,7 +41,6 @@ import { parsePublicKey, verifyChallenge } from './identity.js'
|
|
|
42
41
|
import { verifyPass, PASS_TTL_MS } from './passes.js'
|
|
43
42
|
import { cleanAccess, narrowAccess, relayAccess, fromRelay, sameAccess, mayChange, TALK_REFUSED } from './session-access.js'
|
|
44
43
|
import { canAdmit, cleanAdmitBy, DEFAULT_ADMIT_BY, BAD_ADMIT_BY } from './admit-policy.js'
|
|
45
|
-
import { personaName, firstName, PERSONA_SEP } from './persona.js'
|
|
46
44
|
import { adoptLegacyEnv } from './legacy.js'
|
|
47
45
|
import { makeStore, DiskStore } from './blobstore.js'
|
|
48
46
|
import { JOIN_HOST } from './ui/invite.js'
|
|
@@ -73,23 +71,17 @@ export const AWAY_MS = 7 * 24 * 60 * 60 * 1000
|
|
|
73
71
|
// A room's renames: each one saves the room and queues a presence report, so they're rationed.
|
|
74
72
|
const RENAME_MS = 2000
|
|
75
73
|
const MAX_PATTERN = 500
|
|
76
|
-
// eslint-disable-next-line no-control-regex
|
|
77
|
-
const CONTROL_CHARS = /[\u0000-\u001f\u007f]/ // never in a box's path: branch boxes are keyed `<branch>\0<path>`
|
|
78
74
|
// A room's documents together (the room's and every branch's) may take this many times the size limit before new branches are refused.
|
|
79
75
|
const MAX_TOTAL_FACTOR = 10
|
|
80
76
|
const newEpoch = () => crypto.randomBytes(8).toString('hex')
|
|
81
|
-
//
|
|
82
|
-
const
|
|
77
|
+
// Apps before 0.3.177 keep a list of files held out of their folder: an empty one lets every file through.
|
|
78
|
+
const NO_CLAIMS = { claims: [] }
|
|
83
79
|
const MAX_SCOPES = 20
|
|
84
80
|
// Removed accounts remembered per room, so an older pass's grant can't bring them back.
|
|
85
81
|
const MAX_REMOVED = 200
|
|
86
82
|
const ROLES = ['editor', 'viewer']
|
|
87
83
|
const MB = 1024 * 1024
|
|
88
84
|
const DAY = 24 * 60 * 60 * 1000
|
|
89
|
-
const BOX_REMIND_MS = DAY // a box whose holder is away: one reminder a day (sweepBoxes)
|
|
90
|
-
// A person's cloud AI gone this long (its machine asleep or stopped: its cap, its tool's own limit, a crash)
|
|
91
|
-
// hands its boxes to its person (sweepBoxes): its unfinished work never waits on a machine that isn't running.
|
|
92
|
-
const CLOUD_AI_GONE_MS = 5 * 60 * 1000
|
|
93
85
|
// How often a branch's "last used" time (see Room.noteBranchSeen) is saved while it is busy.
|
|
94
86
|
const BRANCH_SEEN_SAVE_MS = 60 * 60 * 1000
|
|
95
87
|
// A message to the relay older than this when it reaches the relay gets no answer (answerRelay).
|
|
@@ -142,8 +134,6 @@ export function relayConfig (opts = {}) {
|
|
|
142
134
|
}
|
|
143
135
|
}
|
|
144
136
|
|
|
145
|
-
|
|
146
|
-
|
|
147
137
|
/** Who loaded a branch document, from the stack: the first two callers outside the branch store. */
|
|
148
138
|
function loadedFor (stack) {
|
|
149
139
|
const frames = String(stack || '').split('\n').slice(1).map((l) => l.trim().replace(/^at /, ''))
|
|
@@ -186,10 +176,8 @@ class Room {
|
|
|
186
176
|
}
|
|
187
177
|
}
|
|
188
178
|
this.meta.identities = this.meta.identities || {} // name -> public key
|
|
189
|
-
//
|
|
190
|
-
|
|
191
|
-
if (!this.meta.boxes) this.meta.boxes = Object.fromEntries(Object.entries(this.meta.claims || {}).filter(([, c]) => c && c.box === true).map(([k, c]) => { const { queue, clash, ...box } = c; return [k, box] }))
|
|
192
|
-
delete this.meta.claims
|
|
179
|
+
// What older relays kept of files held out of other folders: nothing is held any more.
|
|
180
|
+
for (const k of ['boxes', 'claims', 'seen']) delete this.meta[k]
|
|
193
181
|
// Each branch's files live in a document of their own (branchdocs.js); the session's
|
|
194
182
|
// branches are key -> { by, at, base, seen, stored }, and the default is the first one joined.
|
|
195
183
|
this.meta.branches = this.meta.branches || {}
|
|
@@ -208,10 +196,6 @@ class Room {
|
|
|
208
196
|
this.pruneBranches(Date.now(), { quiet: true }) // at load; the sweep says it in chat
|
|
209
197
|
this.awareness = new awarenessProtocol.Awareness(this.doc)
|
|
210
198
|
this.awareness.setLocalState(null)
|
|
211
|
-
// Box holder (see holderKey) -> when they last did something in the session (changed the
|
|
212
|
-
// document: a file, a message, their AI's feed; or used a hosted tool), for sweepBoxes.
|
|
213
|
-
this.meta.seen = this.meta.seen || {}
|
|
214
|
-
this.cloudAiGone = new Map() // a cloud AI's account -> since when the sweep has found it away
|
|
215
199
|
this.loadedAt = Date.now()
|
|
216
200
|
// Member id -> { name, kind, role, scopes, since }. The id is the public key, or
|
|
217
201
|
// '<kind>:<sub>' for members approved with a pass (an account, on any computer).
|
|
@@ -289,10 +273,7 @@ class Room {
|
|
|
289
273
|
this.doc.on('update', (update, origin, doc, tr) => {
|
|
290
274
|
if (origin === this.guard && this.roomParts.undoing) { this.roomParts.undoing.push(update); return } // sent merged, below
|
|
291
275
|
if (origin && origin !== this.guard && this.guard.trackedOrigins.has(origin) && !this.checkChange(origin, update, tr)) return
|
|
292
|
-
if (origin && this.conns.has(origin)) {
|
|
293
|
-
this.noteActivity(this.holderKeys(origin))
|
|
294
|
-
if (this.cloudAiWaker) this.cloudAiWaker.personActive(this, origin).catch(() => {}) // their cloud AI wakes while they work
|
|
295
|
-
}
|
|
276
|
+
if (origin && this.conns.has(origin) && this.cloudAiWaker) this.cloudAiWaker.personActive(this, origin).catch(() => {}) // their cloud AI wakes while they work
|
|
296
277
|
const msg = updateMessage(update)
|
|
297
278
|
for (const ws of this.conns.keys()) if (ws !== origin) send(ws, msg)
|
|
298
279
|
this.bytes += update.length
|
|
@@ -653,7 +634,6 @@ class Room {
|
|
|
653
634
|
hostedActive (id) {
|
|
654
635
|
const was = this.hostedSeen.get(id) || 0
|
|
655
636
|
this.hostedSeen.set(id, Date.now())
|
|
656
|
-
this.noteActivity([id])
|
|
657
637
|
for (const [k, p] of this.pending) if (k.hosted && p.id === id) this.pending.delete(k)
|
|
658
638
|
// Newly online, or a newer check-in time: everyone's member list shows it (once a minute at most).
|
|
659
639
|
if (Date.now() - was >= 60 * 1000) this.broadcastMembers()
|
|
@@ -679,22 +659,9 @@ class Room {
|
|
|
679
659
|
return out
|
|
680
660
|
}
|
|
681
661
|
|
|
682
|
-
/** Tells every connection the boxes changed. MSG_CLAIMS keeps its name and `claims` field for older apps: it lists boxes only. */
|
|
683
|
-
broadcastBoxes () {
|
|
684
|
-
this.saveMeta()
|
|
685
|
-
for (const other of this.conns.keys()) send(other, jsonMessage(MSG_CLAIMS, { claims: this.boxList(other.branch) }))
|
|
686
|
-
}
|
|
687
|
-
|
|
688
662
|
/** May this connection change this file? */
|
|
689
663
|
mayWrite (a, rel) { return mayChange(a, rel) }
|
|
690
664
|
|
|
691
|
-
/** Whether a change by this connection to rel would stand (checkChange), so a box on it would hold their work. */
|
|
692
|
-
mayBox (ws, rel) {
|
|
693
|
-
const a = this.access.get(ws)
|
|
694
|
-
rel = String(rel ?? '').trim().replace(/^\.\//, '')
|
|
695
|
-
return !(a && !this.mayWrite(a, rel))
|
|
696
|
-
}
|
|
697
|
-
|
|
698
665
|
/**
|
|
699
666
|
* A restricted member (viewer, or agent limited to folders) changed a document: the room's
|
|
700
667
|
* (`d` = roomParts) or a branch's (`d` = its entry). Returns true to pass it on, or false
|
|
@@ -894,10 +861,7 @@ class Room {
|
|
|
894
861
|
if (origin && origin !== e.guard && this.guard.trackedOrigins.has(origin) && !this.checkChange(origin, update, tr, e)) return
|
|
895
862
|
// Written on in the session: an idle branch counts from its last change (relay-prune.js).
|
|
896
863
|
if (origin && this.meta.branches[e.key]) this.meta.branches[e.key].changed = Date.now()
|
|
897
|
-
if (origin && this.conns.has(origin)) {
|
|
898
|
-
this.noteActivity(this.holderKeys(origin))
|
|
899
|
-
if (this.cloudAiWaker) this.cloudAiWaker.personActive(this, origin).catch(() => {})
|
|
900
|
-
}
|
|
864
|
+
if (origin && this.conns.has(origin) && this.cloudAiWaker) this.cloudAiWaker.personActive(this, origin).catch(() => {})
|
|
901
865
|
for (const ws of e.conns) if (ws !== origin) send(ws, updateMessage(update, ws.branchAs))
|
|
902
866
|
const was = e.bytes > this.cfg.maxRoomBytes
|
|
903
867
|
e.bytes += update.length
|
|
@@ -1013,12 +977,11 @@ class Room {
|
|
|
1013
977
|
return true
|
|
1014
978
|
}
|
|
1015
979
|
|
|
1016
|
-
/** Takes branch `key` out of the session: its document
|
|
980
|
+
/** Takes branch `key` out of the session: its document and hosted agents' choice of it. Never the git branch. */
|
|
1017
981
|
removeBranch (key, { save = true, archive = false } = {}) {
|
|
1018
982
|
if (archive) this.store.archive(key, this.archiveDir)
|
|
1019
983
|
else this.store.remove(key)
|
|
1020
984
|
delete this.meta.branches[key]
|
|
1021
|
-
for (const [k, c] of Object.entries(this.meta.boxes)) if (this.branchOf(c) === key) delete this.meta.boxes[k]
|
|
1022
985
|
for (const [id, k] of Object.entries(this.meta.hostedBranch || {})) if (k === key) delete this.meta.hostedBranch[id]
|
|
1023
986
|
if (save) this.saveMeta()
|
|
1024
987
|
}
|
|
@@ -1472,10 +1435,6 @@ class Room {
|
|
|
1472
1435
|
if (req.op === 'remove') {
|
|
1473
1436
|
// An account goes with any older entries for keys it has used here, so it can't get back in by key.
|
|
1474
1437
|
const gone = [key, ...((this.meta.accountKeys || {})[key] || [])]
|
|
1475
|
-
// Their boxes open: nobody left could commit them, so their work reaches every folder.
|
|
1476
|
-
const names = gone.map((id) => this.meta.members[id]?.name).filter(Boolean)
|
|
1477
|
-
const theirs = (x) => x.byId ? gone.includes(x.byId) : names.includes(x.by)
|
|
1478
|
-
this.dropBoxes(theirs)
|
|
1479
1438
|
for (const id of gone) delete this.meta.members[id]
|
|
1480
1439
|
// A pass issued before now can't bring them back by its grant (see passGrant). Removals
|
|
1481
1440
|
// older than a pass lasts can match no valid pass, so they go; the newest are kept.
|
|
@@ -1485,7 +1444,6 @@ class Room {
|
|
|
1485
1444
|
this.saveMeta()
|
|
1486
1445
|
for (const [cws, a] of this.access) if (gone.includes(a.id)) { cws.endReason = 'removed'; cws.close(CLOSE_DENIED, 'The session owner removed you') }
|
|
1487
1446
|
for (const id of gone) { this.hostedSeen.delete(id); this.forgetHostedBranch(id); if (this.onHostedGone) this.onHostedGone(id, 'removed') }
|
|
1488
|
-
this.broadcastBoxes()
|
|
1489
1447
|
return { ok: true }
|
|
1490
1448
|
}
|
|
1491
1449
|
throw new Error('unknown request')
|
|
@@ -1538,105 +1496,7 @@ class Room {
|
|
|
1538
1496
|
return true
|
|
1539
1497
|
}
|
|
1540
1498
|
|
|
1541
|
-
/**
|
|
1542
|
-
boxOwner (ws, as = null) {
|
|
1543
|
-
const name = this.names.get(ws)
|
|
1544
|
-
const a = this.access.get(ws)
|
|
1545
|
-
const who = ws.pass ? { name, id: `${ws.pass.kind}:${ws.pass.sub}`, owner: !!(a && a.owner), talk: !(a && a.talk === false), branch: ws.branch } : { name, branch: ws.branch }
|
|
1546
|
-
// An older app (0.3.109) boxes for one of its AI sessions (`as`): the box keeps that session's
|
|
1547
|
-
// name and says whose it is (`of`), so everyone shows it as that person. Nobody can box as
|
|
1548
|
-
// someone else's: the name is built here from the connection's own.
|
|
1549
|
-
if (!as || typeof as.id !== 'string' || !/^[A-Za-z0-9_-]{4,40}$/.test(as.id)) return who
|
|
1550
|
-
return { ...who, name: personaName(name, as.label), ...(who.id ? { id: `${who.id}~${as.id}` } : {}), persona: true, of: name }
|
|
1551
|
-
}
|
|
1552
|
-
|
|
1553
|
-
/** Which branch a box is on: its own, or the default branch (boxes from before branches). */
|
|
1554
|
-
branchOf (c) { return c.branch ? this.resolveKey(c.branch) : this.defaultKey }
|
|
1555
|
-
|
|
1556
|
-
/** Where a box on `file` on `branch` is kept in meta.boxes: the default branch keeps bare paths. */
|
|
1557
|
-
boxKey (branch, file) {
|
|
1558
|
-
const b = this.resolveKey(branch || this.defaultKey)
|
|
1559
|
-
return b === this.defaultKey ? file : `${b}\0${file}`
|
|
1560
|
-
}
|
|
1561
|
-
|
|
1562
|
-
shownBox (c) { return { ...c, active: this.holderPresent(c), activeAt: this.lastActive(c) } }
|
|
1563
|
-
|
|
1564
|
-
/**
|
|
1565
|
-
* The boxes on one branch (the default when none is given), each with `active` (whoever holds
|
|
1566
|
-
* it is in the session now) and `activeAt` (when they last did something there), oldest first.
|
|
1567
|
-
* Quilt holds no files (no-holds, 2026-11-13): a box is only someone's unfinished work on one
|
|
1568
|
-
* file, kept out of other folders until it is committed; it never stops anyone writing.
|
|
1569
|
-
*/
|
|
1570
|
-
boxList (branch) {
|
|
1571
|
-
const b = this.resolveKey(branch || this.defaultKey)
|
|
1572
|
-
return Object.values(this.meta.boxes).filter((c) => this.branchOf(c) === b).map((c) => this.shownBox(c)).sort((x, y) => x.ts - y.ts)
|
|
1573
|
-
}
|
|
1574
|
-
|
|
1575
|
-
/** Every box on every branch. */
|
|
1576
|
-
allBoxes () { return Object.values(this.meta.boxes).map((c) => this.shownBox(c)).sort((x, y) => x.ts - y.ts) }
|
|
1577
|
-
|
|
1578
|
-
/** Who holds a box: their account with sign-in on, otherwise their name. */
|
|
1579
|
-
holderKey (c) { return c.byId || `name:${c.by}` }
|
|
1580
|
-
|
|
1581
|
-
/** The holder keys a connection speaks for: its account, and its name (boxes older than sign-in). */
|
|
1582
|
-
holderKeys (ws) {
|
|
1583
|
-
const keys = [`name:${this.names.get(ws)}`]
|
|
1584
|
-
if (ws.pass) keys.push(`${ws.pass.kind}:${ws.pass.sub}`)
|
|
1585
|
-
return keys
|
|
1586
|
-
}
|
|
1587
|
-
|
|
1588
|
-
/** Someone did something in the session: their boxes' reminder waits again (sweepBoxes). */
|
|
1589
|
-
noteActivity (keys) {
|
|
1590
|
-
const now = Date.now()
|
|
1591
|
-
let save = false
|
|
1592
|
-
for (const k of keys) {
|
|
1593
|
-
if (!Object.values(this.meta.boxes).some((c) => this.holderKey(c) === k)) continue
|
|
1594
|
-
// Saved now and then, so a relay restart doesn't count them away for longer than they were.
|
|
1595
|
-
if (now - (this.meta.seen[k] || 0) > 60 * 1000) save = true
|
|
1596
|
-
this.meta.seen[k] = now
|
|
1597
|
-
}
|
|
1598
|
-
if (save) this.saveMeta()
|
|
1599
|
-
}
|
|
1600
|
-
|
|
1601
|
-
/** When a box's holder last did something in the session (since the relay loaded it, at the earliest). */
|
|
1602
|
-
lastActive (c) {
|
|
1603
|
-
return Math.max(this.meta.seen[this.holderKey(c)] ?? this.loadedAt, c.ts || 0)
|
|
1604
|
-
}
|
|
1605
|
-
|
|
1606
|
-
/** Whether a box's holder is in the session now: connected, or a hosted agent seen lately. */
|
|
1607
|
-
holderPresent (c) {
|
|
1608
|
-
if (c.byId) {
|
|
1609
|
-
// An AI session's box (account~session) is here while its person's app is.
|
|
1610
|
-
const base = c.byId.split('~')[0]
|
|
1611
|
-
const seen = this.hostedSeen.get(base)
|
|
1612
|
-
if (seen && Date.now() - seen < HOSTED_ONLINE_MS) return true
|
|
1613
|
-
for (const ws of this.conns.keys()) if (ws.pass && `${ws.pass.kind}:${ws.pass.sub}` === base) return true
|
|
1614
|
-
return false
|
|
1615
|
-
}
|
|
1616
|
-
for (const n of this.names.values()) if (n === c.by || (c.by.startsWith(`${firstName(n)}${PERSONA_SEP}`))) return true
|
|
1617
|
-
return this.hostedOnline().some((h) => h.name === c.by)
|
|
1618
|
-
}
|
|
1619
|
-
|
|
1620
|
-
/** The box on one file on a branch (the live record in meta.boxes), or null. */
|
|
1621
|
-
boxFor (file, branch) { return this.meta.boxes[this.boxKey(branch, file)] || null }
|
|
1622
|
-
|
|
1623
|
-
/** Opens the boxes `pick` chooses: their work stays in the session and reaches every folder. Returns how many went. */
|
|
1624
|
-
dropBoxes (pick) {
|
|
1625
|
-
let n = 0
|
|
1626
|
-
for (const [k, c] of Object.entries(this.meta.boxes)) {
|
|
1627
|
-
if (!pick(c)) continue
|
|
1628
|
-
n++
|
|
1629
|
-
delete this.meta.boxes[k]
|
|
1630
|
-
}
|
|
1631
|
-
this.forgetSeen()
|
|
1632
|
-
return n
|
|
1633
|
-
}
|
|
1634
|
-
|
|
1635
|
-
forgetSeen () {
|
|
1636
|
-
for (const k of Object.keys(this.meta.seen)) if (!Object.values(this.meta.boxes).some((c) => this.holderKey(c) === k)) delete this.meta.seen[k]
|
|
1637
|
-
}
|
|
1638
|
-
|
|
1639
|
-
/** A chat entry written by the relay itself (box reminders, answers to @Quilt, approvals). */
|
|
1499
|
+
/** A chat entry written by the relay itself (answers to @Quilt, approvals). */
|
|
1640
1500
|
postChat ({ by, to = null, text, kind, path: file, re, mail, wake, approval }) {
|
|
1641
1501
|
const chat = this.doc.getArray('chat')
|
|
1642
1502
|
const msg = { id: crypto.randomBytes(8).toString('hex'), by, to, text: String(text).slice(0, 4000), ts: Date.now(), kind, path: file }
|
|
@@ -1674,67 +1534,6 @@ class Room {
|
|
|
1674
1534
|
})
|
|
1675
1535
|
}
|
|
1676
1536
|
|
|
1677
|
-
/**
|
|
1678
|
-
* Boxes never time out; one whose holder has been away a day gets one reminder a day in chat
|
|
1679
|
-
* (to their person, for an AI session's box). Returns how many were sent. Also tells everyone
|
|
1680
|
-
* when a box holder came or went, so the app shows whose unfinished work waits on someone away.
|
|
1681
|
-
*/
|
|
1682
|
-
sweepBoxes (now = Date.now()) {
|
|
1683
|
-
this.handBackCloudBoxes(now)
|
|
1684
|
-
let n = 0
|
|
1685
|
-
for (const c of Object.values(this.meta.boxes)) {
|
|
1686
|
-
if (this.holderPresent(c)) continue
|
|
1687
|
-
if (now - this.lastActive(c) < BOX_REMIND_MS || now - (c.reminded || 0) < BOX_REMIND_MS) continue
|
|
1688
|
-
c.reminded = now
|
|
1689
|
-
this.postChat({ by: RELAY_BY, to: c.of || c.by, kind: 'nudge', path: c.pattern, text: `📦 Your unfinished work on ${c.pattern}${c.branch ? ` (on ${c.branch})` : ''} is still in a box: nobody else has it in their folder. When you're back, commit it, unpack it (quilt_unpack) or put it back.` })
|
|
1690
|
-
n++
|
|
1691
|
-
}
|
|
1692
|
-
if (n) this.saveMeta()
|
|
1693
|
-
const shown = this.allBoxes().map((c) => `${c.branch || ''}\0${c.pattern}\0${c.active}`).join('\n')
|
|
1694
|
-
if (shown !== this.boxesShown) { this.boxesShown = shown; this.broadcastBoxes() }
|
|
1695
|
-
return n
|
|
1696
|
-
}
|
|
1697
|
-
|
|
1698
|
-
/**
|
|
1699
|
-
* A person's cloud AI away CLOUD_AI_GONE_MS (its machine asleep or stopped: its daily cap, its tool's
|
|
1700
|
-
* own limit, a crash) never keeps its boxes: each goes to its person, whose folder gets the work to
|
|
1701
|
-
* commit or carry on. If the AI carries on first, it takes back what its person hasn't boxed since
|
|
1702
|
-
* (boxRequestOp). Returns how many went.
|
|
1703
|
-
*/
|
|
1704
|
-
handBackCloudBoxes (now = Date.now()) {
|
|
1705
|
-
const gone = (id) => {
|
|
1706
|
-
if (this.holderPresent({ byId: id, by: '' })) { this.cloudAiGone.delete(id); return false }
|
|
1707
|
-
if (!this.cloudAiGone.has(id)) this.cloudAiGone.set(id, now)
|
|
1708
|
-
return now - this.cloudAiGone.get(id) >= CLOUD_AI_GONE_MS
|
|
1709
|
-
}
|
|
1710
|
-
// Each cloud AI that joined (meta.cloudAis, relay-ai-vm.js: keyed by its person's account): its account -> its person.
|
|
1711
|
-
const people = new Map(Object.entries(this.meta.cloudAis || {}).filter(([of, e]) => e && e.agent && e.ofName).map(([of, e]) => [e.agent, { of, name: e.ofName }]))
|
|
1712
|
-
if (!people.size) return 0
|
|
1713
|
-
const given = new Map() // its person -> { ai, files }
|
|
1714
|
-
let n = 0
|
|
1715
|
-
for (const c of Object.values(this.meta.boxes)) {
|
|
1716
|
-
const ai = c.byId ? people.get(c.byId) : null
|
|
1717
|
-
if (!ai || !gone(c.byId)) continue
|
|
1718
|
-
n++
|
|
1719
|
-
const next = { ...(c.branch ? { branch: c.branch } : {}), by: ai.name, byId: ai.of, pattern: c.pattern, note: `${c.by}'s unfinished work`, ts: now, box: true, handedFrom: c.byId }
|
|
1720
|
-
this.meta.boxes[this.boxKey(c.branch, c.pattern)] = next
|
|
1721
|
-
this.meta.seen[this.holderKey(next)] = now
|
|
1722
|
-
const g = given.get(ai.name) || { ai: c.by, files: [] }
|
|
1723
|
-
g.files.push(c.branch ? `${c.pattern} (on ${c.branch})` : c.pattern)
|
|
1724
|
-
given.set(ai.name, g)
|
|
1725
|
-
}
|
|
1726
|
-
if (!n) return 0
|
|
1727
|
-
for (const [person, g] of given) {
|
|
1728
|
-
const files = g.files.length > 3 ? `${g.files.slice(0, 3).join(', ')} and ${g.files.length - 3} more` : g.files.join(', ')
|
|
1729
|
-
this.postChat({ by: RELAY_BY, to: person, kind: 'nudge', text: `📦 ${g.ai} stopped before committing its work on ${files}: that work is yours now, in your folder. Commit it, or carry on with it. If your AI carries on first, it takes it back.` })
|
|
1730
|
-
this.log(`[${this.name}] ${g.ai} is away: its boxes (${g.files.join(', ')}) went to ${person}`)
|
|
1731
|
-
}
|
|
1732
|
-
this.forgetSeen()
|
|
1733
|
-
this.saveMeta()
|
|
1734
|
-
this.broadcastBoxes()
|
|
1735
|
-
return n
|
|
1736
|
-
}
|
|
1737
|
-
|
|
1738
1537
|
/** The owner's name in the session's chat, or '' in a session nobody controls. */
|
|
1739
1538
|
ownerName () {
|
|
1740
1539
|
if (!this.meta.owner && !this.meta.ownerName) return ''
|
|
@@ -1943,57 +1742,6 @@ class Room {
|
|
|
1943
1742
|
return n
|
|
1944
1743
|
}
|
|
1945
1744
|
|
|
1946
|
-
/** A box request (boxRequestOp). */
|
|
1947
|
-
boxRequest (who, req) { return this.boxRequestOp(who, req) }
|
|
1948
|
-
|
|
1949
|
-
/**
|
|
1950
|
-
* Handles a box request over MSG_CLAIM. `who` is { name } without sign-in, where boxes belong to a
|
|
1951
|
-
* verified name; with it, { name, id, owner }, where they belong to the account (id). Returns the
|
|
1952
|
-
* reply fields. Quilt holds no files (no-holds, 2026-11-13): nobody is ever refused a file, and the
|
|
1953
|
-
* claim ops older apps still send never reach here (dropped unanswered, MSG_CLAIM).
|
|
1954
|
-
*/
|
|
1955
|
-
boxRequestOp (who, req) {
|
|
1956
|
-
const { name, id } = who
|
|
1957
|
-
// Older boxes in a sign-in room have no account: they belong to their name, as they did when made.
|
|
1958
|
-
const own = (c) => id ? (c.byId ? c.byId === id : c.by === name) : c.by === name
|
|
1959
|
-
// A person may also unpack what their own AI sessions boxed (account~session).
|
|
1960
|
-
const mine = (c) => own(c) || (!who.persona && !!id && !!c.byId && c.byId.startsWith(`${id}~`))
|
|
1961
|
-
const file = String(req.pattern ?? '').trim().replace(/^\.\//, '')
|
|
1962
|
-
// Boxes are per branch: one on src/a.js on main is not on src/a.js on feature-x.
|
|
1963
|
-
const branch = this.resolveKey(who.branch || this.defaultKey)
|
|
1964
|
-
const at = (p) => this.boxKey(branch, p)
|
|
1965
|
-
const onBranch = branch === this.defaultKey ? {} : { branch }
|
|
1966
|
-
// An older app boxes an edit with a claim marked as a box.
|
|
1967
|
-
const boxing = req.op === 'box' || (req.op === 'claim' && req.box === true)
|
|
1968
|
-
if (boxing) {
|
|
1969
|
-
if (!file) throw new Error('pattern required')
|
|
1970
|
-
if (file.length > MAX_PATTERN) throw new Error('pattern too long')
|
|
1971
|
-
if (CONTROL_CHARS.test(file)) throw new Error('a path cannot contain control characters')
|
|
1972
|
-
if (/[*?[]/.test(file)) return { ok: true, boxed: 0 } // a box is on one file, never a glob
|
|
1973
|
-
const existing = this.meta.boxes[at(file)]
|
|
1974
|
-
// A box its cloud AI stopped with went to its person (handBackCloudBoxes): the AI, carrying on, takes it back.
|
|
1975
|
-
const takeOver = (c) => !!id && c.handedFrom === id
|
|
1976
|
-
// Someone else's unfinished work on the file stays theirs: this edit goes live (their folder merges it), never refused.
|
|
1977
|
-
if (existing && !mine(existing) && !takeOver(existing)) return { ok: true, boxed: 0 }
|
|
1978
|
-
this.meta.boxes[at(file)] = { ...onBranch, by: name, ...(id ? { byId: id } : {}), pattern: file, note: who.talk === false ? '' : String(req.note ?? '').slice(0, 500), ts: existing && mine(existing) ? existing.ts : Date.now(), ...(who.persona ? { of: who.of } : {}), box: true }
|
|
1979
|
-
return { ok: true, boxed: 1 }
|
|
1980
|
-
}
|
|
1981
|
-
if (req.op === 'unbox') {
|
|
1982
|
-
// The box opens: its work is in every folder now. Its holder (or their person, or the session
|
|
1983
|
-
// owner) unpacks it, or commits it; anyone who may change the file opens it by editing it
|
|
1984
|
-
// (`edit`), so their change merges with the work in it instead of waiting for it.
|
|
1985
|
-
const c = this.meta.boxes[at(file)]
|
|
1986
|
-
if (!c) return { ok: true, unboxed: 0 }
|
|
1987
|
-
const holder = mine(c) || (!who.persona && c.of === name) || !!who.owner
|
|
1988
|
-
if (!holder && req.edit !== true) throw new Error(`${file} is boxed by ${c.by}; only they can unpack it (or the session owner). Editing it opens it.`)
|
|
1989
|
-
delete this.meta.boxes[at(file)]
|
|
1990
|
-
this.forgetSeen()
|
|
1991
|
-
if (!holder) this.postChat({ by: RELAY_BY, to: c.of || c.by, kind: 'nudge', path: file, text: `📦 ${name} changed ${file}, so your unfinished work on it is in every folder now, merged with their change. Nothing to do.` })
|
|
1992
|
-
return { ok: true, unboxed: 1 }
|
|
1993
|
-
}
|
|
1994
|
-
throw new Error('unknown box operation')
|
|
1995
|
-
}
|
|
1996
|
-
|
|
1997
1745
|
saveMeta () {
|
|
1998
1746
|
if (this.ended || !this.metaFile || this.crashed || this.released) return // crashed: a failure injected in a test (relay-sync.js crashPoint)
|
|
1999
1747
|
// Written whole, then renamed: a crash mid-write leaves the old file, never a cut-off one.
|
|
@@ -2151,7 +1899,7 @@ class Room {
|
|
|
2151
1899
|
send(ws, jsonMessage(MSG_BRANCHES, { ...this.branchesFields() }))
|
|
2152
1900
|
const states = [...this.awareness.getStates().keys()]
|
|
2153
1901
|
if (states.length) send(ws, awarenessMessage(this.awareness, states))
|
|
2154
|
-
send(ws, jsonMessage(MSG_CLAIMS,
|
|
1902
|
+
send(ws, jsonMessage(MSG_CLAIMS, NO_CLAIMS))
|
|
2155
1903
|
this.touch()
|
|
2156
1904
|
}
|
|
2157
1905
|
|
|
@@ -2250,9 +1998,9 @@ class Room {
|
|
|
2250
1998
|
delete reply.listChanged
|
|
2251
1999
|
send(ws, jsonMessage(MSG_BRANCHES, { ...this.branchesFields(), reply }))
|
|
2252
2000
|
if (reply.ok && reply.op === 'join') {
|
|
2253
|
-
// What the relay has of the branch
|
|
2001
|
+
// What the relay has of the branch: the app answers with what it has.
|
|
2254
2002
|
send(ws, syncStep1Message(this.store.get(ws.branch).doc, ws.branchAs))
|
|
2255
|
-
send(ws, jsonMessage(MSG_CLAIMS,
|
|
2003
|
+
send(ws, jsonMessage(MSG_CLAIMS, NO_CLAIMS))
|
|
2256
2004
|
}
|
|
2257
2005
|
if (listChanged) this.broadcastBranches()
|
|
2258
2006
|
} else if (type === MSG_AWARENESS) {
|
|
@@ -2262,28 +2010,13 @@ class Room {
|
|
|
2262
2010
|
} else if (type === MSG_QUERY_AWARENESS) {
|
|
2263
2011
|
send(ws, awarenessMessage(this.awareness, [...this.awareness.getStates().keys()]))
|
|
2264
2012
|
} else if (type === MSG_CLAIM) {
|
|
2265
|
-
let
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
const who = this.boxOwner(ws, req.as)
|
|
2273
|
-
// No box on a file this member's change to would be undone (checkChange: permissions): nothing of theirs would be in it.
|
|
2274
|
-
if (boxing && !this.mayBox(ws, req.pattern)) return send(ws, jsonMessage(MSG_CLAIMS, { claims: this.boxList(ws.branch), reply: { id: req.id, ok: true, boxed: 0 } }))
|
|
2275
|
-
// Opening someone's box by editing the file needs the right to change it.
|
|
2276
|
-
if (req && req.op === 'unbox' && req.edit === true && !this.mayBox(ws, req.pattern)) req = { ...req, edit: false }
|
|
2277
|
-
reply = { id: req.id, ...this.boxRequest(who, req) }
|
|
2278
|
-
this.noteActivity(who.persona ? [who.id || `name:${who.name}`] : this.holderKeys(ws))
|
|
2279
|
-
} catch (err) {
|
|
2280
|
-
return send(ws, jsonMessage(MSG_CLAIMS, { claims: this.boxList(ws.branch), reply: { id: req.id, ok: false, error: err.message } }))
|
|
2281
|
-
}
|
|
2282
|
-
this.saveMeta()
|
|
2283
|
-
for (const other of this.conns.keys()) {
|
|
2284
|
-
const claims = this.boxList(other.branch)
|
|
2285
|
-
send(other, jsonMessage(MSG_CLAIMS, other === ws ? { claims, reply } : { claims }))
|
|
2286
|
-
}
|
|
2013
|
+
// An app before 0.3.177 asks to keep a file out of other folders ('box') or to let it through
|
|
2014
|
+
// ('unbox'): nothing is kept out, and it is told so. Every other op older apps send is dropped unanswered.
|
|
2015
|
+
let req = null
|
|
2016
|
+
try { req = JSON.parse(decoding.readVarString(dec)) } catch { return }
|
|
2017
|
+
const boxing = !!req && (req.op === 'box' || (req.op === 'claim' && req.box === true))
|
|
2018
|
+
if (!boxing && !(req && req.op === 'unbox')) return
|
|
2019
|
+
send(ws, jsonMessage(MSG_CLAIMS, { ...NO_CLAIMS, reply: { id: req.id, ok: true, ...(boxing ? { boxed: 0 } : { unboxed: 0 }) } }))
|
|
2287
2020
|
} else if (type === MSG_ADMIN) {
|
|
2288
2021
|
let req = {}
|
|
2289
2022
|
let reply
|
|
@@ -3368,7 +3101,7 @@ export function startServer ({ port = 4321, host = '0.0.0.0', dataDir = null, lo
|
|
|
3368
3101
|
}
|
|
3369
3102
|
for (const room of rooms.values()) {
|
|
3370
3103
|
if (room.ended) continue
|
|
3371
|
-
room.
|
|
3104
|
+
room.pruneBranches()
|
|
3372
3105
|
try { room.sweepHeld() } catch (err) { log(`[${room.name}] held conflicts: ${err.message}`) }
|
|
3373
3106
|
heldWake.delete(room.name)
|
|
3374
3107
|
}
|