heyquilt 0.3.170 → 0.3.172
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 +30 -0
- package/bin/quilt.js +16 -9
- package/package.json +2 -2
- package/src/agent-task-workflow.js +2 -9
- package/src/base-pick.js +212 -0
- package/src/boxes.js +6 -7
- package/src/catchup.js +1 -1
- package/src/chat-links.js +1 -3
- package/src/connection.js +24 -5
- package/src/control.js +27 -20
- package/src/duties.js +32 -56
- package/src/github-commit.js +1 -1
- package/src/held.js +323 -0
- package/src/hooks.js +27 -66
- package/src/identity.js +1 -1
- package/src/inbox.js +5 -4
- package/src/key-cli.js +1 -1
- package/src/live-merge.js +599 -0
- package/src/mcp.js +57 -102
- package/src/merge3.js +65 -1
- package/src/now-summary.js +4 -6
- package/src/pathrules.js +1 -1
- package/src/persona.js +1 -1
- package/src/presence.js +2 -0
- package/src/protocol.js +2 -2
- package/src/read-bases.js +123 -0
- package/src/relay-ask.js +2 -2
- package/src/relay-live-write.js +179 -0
- package/src/relay-mcp.js +173 -212
- package/src/relay-prune.js +2 -2
- package/src/relay-turn-sync.js +146 -142
- package/src/runner.js +0 -2
- package/src/server.js +253 -375
- package/src/session-follow.js +3 -1
- package/src/session-quilt.js +2 -21
- package/src/session-seam.js +35 -7
- package/src/session.js +795 -553
- package/src/setup.js +15 -25
- package/src/source-live/bring-in.js +5 -5
- package/src/source-live/land.js +20 -3
- package/src/source-live/live-block.js +503 -52
- package/src/status.js +8 -12
- package/src/swap-in.js +81 -0
- package/src/textdiff.js +54 -0
- package/src/turn-sync-plan.js +6 -18
- package/src/turn-sync.js +28 -21
- package/src/ui/agent-guide.js +13 -13
- package/src/ui/app.css +19 -40
- package/src/ui/boxes.js +8 -16
- package/src/ui/common.js +1 -1
- package/src/ui/fileview.js +11 -15
- package/src/ui/loom-model.js +18 -16
- package/src/ui/loom.css +1 -2
- package/src/ui/loom.js +6 -6
- package/src/ui/rail-model.js +25 -64
- package/src/ui/rail.js +48 -60
- package/src/ui/seam-model.js +39 -3
- package/src/ui/session.js +36 -54
- package/src/ui/tree.js +22 -129
- package/src/ui-server.js +2 -6
- package/src/release-words.js +0 -18
- package/src/seam-claims.js +0 -53
package/src/server.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
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) and
|
|
4
|
-
// room's
|
|
5
|
-
//
|
|
6
|
-
//
|
|
3
|
+
// to disk. It checks who each client is (see identity.js) and keeps the
|
|
4
|
+
// room's boxes (someone's unfinished work on a file, until it's committed).
|
|
5
|
+
// It holds no files: nobody's write is ever refused or undone because someone
|
|
6
|
+
// else is working on the same file (no-holds, 2026-11-13). Safe to
|
|
7
7
|
// run on the public internet: rooms need their secret, creating rooms can
|
|
8
8
|
// require a relay key, and rooms have size quotas.
|
|
9
9
|
//
|
|
@@ -26,6 +26,7 @@ import { WebSocketServer } from 'ws'
|
|
|
26
26
|
import * as Y from 'yjs'
|
|
27
27
|
import { handleAgentMcp, handleHostedMcp, watchFeatures } from './relay-mcp.js'
|
|
28
28
|
import { dropCheckpoints } from './relay-turn-sync.js'
|
|
29
|
+
import { liveWrite } from './relay-live-write.js'
|
|
29
30
|
import { UpdateCheck, needsUpdateWords, withUpdateSteps } from './update-check.js'
|
|
30
31
|
import {
|
|
31
32
|
MSG_SYNC, MSG_AWARENESS, MSG_QUERY_AWARENESS, MSG_AUTH, MSG_CLAIM, MSG_CLAIMS, MAX_SHARED_FILE_BYTES,
|
|
@@ -47,7 +48,8 @@ import { historyQuilt, linkedHistory } from './quilt-history.js'
|
|
|
47
48
|
import { MAX_DIFF_CHARS } from './history.js'
|
|
48
49
|
import { LAYOUT_QUILT, copiedHead, treeIds, treeModes, branchFiles, binariesToUpload, bringsNew, forwardIntoLive, applyChecked, foldBack, writeFold, overlayFor, checkOverlay, copyIntoLive, carryLive, takeGitMeta, restoreGitMeta, squareBase, shareWithPeople, boxOntoHead, writeIntoLive } from './session-layout3.js'
|
|
49
50
|
import { readMerges } from './merges.js'
|
|
50
|
-
import { readTasks, updateTask } from './tasks.js'
|
|
51
|
+
import { readTasks, updateTask, addTask } from './tasks.js'
|
|
52
|
+
import { HELD_MAP, readHeld, noteHeld, heldNoticesDue, heldTasksDue, nextHeldDue, heldNoticeText, heldTaskTitle } from './held.js'
|
|
51
53
|
import { addComment } from './task-comments.js'
|
|
52
54
|
// Seam over HTTP through its client package (@heyquilt/seam), never Seam's code.
|
|
53
55
|
import { quiltClient } from '@heyquilt/seam/lib/quilts/client.js'
|
|
@@ -56,8 +58,6 @@ import { parsePublicKey, verifyChallenge } from './identity.js'
|
|
|
56
58
|
import { verifyPass, PASS_TTL_MS } from './passes.js'
|
|
57
59
|
import { cleanAccess, narrowAccess, relayAccess, fromRelay, sameAccess, mayChange, TALK_REFUSED } from './session-access.js'
|
|
58
60
|
import { canAdmit, cleanAdmitBy, DEFAULT_ADMIT_BY, BAD_ADMIT_BY } from './admit-policy.js'
|
|
59
|
-
import { patternsOverlap } from './fsutil.js'
|
|
60
|
-
import { globMatcher } from './pathrules.js'
|
|
61
61
|
import { personaName, firstName, PERSONA_SEP } from './persona.js'
|
|
62
62
|
import { adoptLegacyEnv } from './legacy.js'
|
|
63
63
|
import { makeStore, DiskStore } from './blobstore.js'
|
|
@@ -92,15 +92,13 @@ export const AWAY_MS = 7 * 24 * 60 * 60 * 1000
|
|
|
92
92
|
const RENAME_MS = 2000
|
|
93
93
|
const MAX_PATTERN = 500
|
|
94
94
|
// eslint-disable-next-line no-control-regex
|
|
95
|
-
const CONTROL_CHARS = /[\u0000-\u001f\u007f]/ // never in a
|
|
95
|
+
const CONTROL_CHARS = /[\u0000-\u001f\u007f]/ // never in a box's path: branch boxes are keyed `<branch>\0<path>`
|
|
96
96
|
// 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.
|
|
97
97
|
const MAX_TOTAL_FACTOR = 10
|
|
98
98
|
const newEpoch = () => crypto.randomBytes(8).toString('hex')
|
|
99
|
-
//
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
const MAX_HANDOFF_TEXT = 2000
|
|
103
|
-
const MAX_QUEUE = 20
|
|
99
|
+
// Quilt holds no files (no-holds, 2026-11-13): what the claim ops older apps still send are answered with.
|
|
100
|
+
const NO_HOLDS = 'Quilt holds no files: nothing to claim'
|
|
101
|
+
const LEGACY_CLAIM_OPS = new Set(['claim', 'release', 'request', 'withdraw', 'handoff', 'touch', 'clear-inactive', 'quilt-claims', 'quilt-released'])
|
|
104
102
|
const MAX_SCOPES = 20
|
|
105
103
|
// Removed accounts remembered per room, so an older pass's grant can't bring them back.
|
|
106
104
|
const MAX_REMOVED = 200
|
|
@@ -159,9 +157,6 @@ export function relayConfig (opts = {}) {
|
|
|
159
157
|
leaseTtlMs: num(opts.leaseTtlMs, undefined),
|
|
160
158
|
leaseMarginMs: num(opts.leaseMarginMs, undefined),
|
|
161
159
|
leaseHeartbeatMs: num(opts.leaseHeartbeatMs, undefined),
|
|
162
|
-
// A claim whose holder has done nothing in the session this long is let go (see sweepClaims):
|
|
163
|
-
// handed to the first one waiting in its file queue, or released.
|
|
164
|
-
claimIdleMs: num(opts.claimIdleMs, 20 * 60 * 1000),
|
|
165
160
|
trustProxy: opts.trustProxy ?? /^(1|true|yes)$/i.test(env.QUILT_TRUST_PROXY || ''),
|
|
166
161
|
// Large files: Supabase Storage when both are set, otherwise the relay's own disk.
|
|
167
162
|
storageUrl: opts.storageUrl ?? env.QUILT_STORAGE_URL ?? '',
|
|
@@ -220,7 +215,10 @@ class Room {
|
|
|
220
215
|
}
|
|
221
216
|
}
|
|
222
217
|
this.meta.identities = this.meta.identities || {} // name -> public key
|
|
223
|
-
|
|
218
|
+
// Boxes: path -> { by, byId?, pattern, note, ts, box: true, branch? }; byId is the account, with sign-in on.
|
|
219
|
+
// Rooms from before no-holds kept them with claims (meta.claims): the boxes stay, every claim goes.
|
|
220
|
+
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] }))
|
|
221
|
+
delete this.meta.claims
|
|
224
222
|
// Each branch's files live in a document of their own (branchdocs.js); the session's
|
|
225
223
|
// branches are key -> { by, at, base, seen, stored }, and the default is the first one joined.
|
|
226
224
|
this.meta.branches = this.meta.branches || {}
|
|
@@ -239,8 +237,8 @@ class Room {
|
|
|
239
237
|
this.pruneBranches(Date.now(), { quiet: true }) // at load; the sweep says it in chat
|
|
240
238
|
this.awareness = new awarenessProtocol.Awareness(this.doc)
|
|
241
239
|
this.awareness.setLocalState(null)
|
|
242
|
-
//
|
|
243
|
-
// document: a file, a message, their AI's feed; or used a hosted tool), for
|
|
240
|
+
// Box holder (see holderKey) -> when they last did something in the session (changed the
|
|
241
|
+
// document: a file, a message, their AI's feed; or used a hosted tool), for sweepBoxes.
|
|
244
242
|
this.meta.seen = this.meta.seen || {}
|
|
245
243
|
this.cloudAiGone = new Map() // a cloud AI's account -> since when the sweep has found it away
|
|
246
244
|
this.loadedAt = Date.now()
|
|
@@ -699,10 +697,10 @@ class Room {
|
|
|
699
697
|
return out
|
|
700
698
|
}
|
|
701
699
|
|
|
702
|
-
/** Tells every connection the
|
|
703
|
-
|
|
700
|
+
/** Tells every connection the boxes changed. MSG_CLAIMS keeps its name and `claims` field for older apps: it lists boxes only. */
|
|
701
|
+
broadcastBoxes () {
|
|
704
702
|
this.saveMeta()
|
|
705
|
-
for (const other of this.conns.keys()) send(other, jsonMessage(MSG_CLAIMS, { claims: this.
|
|
703
|
+
for (const other of this.conns.keys()) send(other, jsonMessage(MSG_CLAIMS, { claims: this.boxList(other.branch) }))
|
|
706
704
|
}
|
|
707
705
|
|
|
708
706
|
/** May this connection change this file? */
|
|
@@ -1014,12 +1012,12 @@ class Room {
|
|
|
1014
1012
|
return true
|
|
1015
1013
|
}
|
|
1016
1014
|
|
|
1017
|
-
/** Takes branch `key` out of the session: its document, its
|
|
1015
|
+
/** Takes branch `key` out of the session: its document, its boxes, hosted agents' choice of it. Never the git branch. */
|
|
1018
1016
|
removeBranch (key, { save = true, archive = false } = {}) {
|
|
1019
1017
|
if (archive) this.store.archive(key, this.archiveDir)
|
|
1020
1018
|
else this.store.remove(key)
|
|
1021
1019
|
delete this.meta.branches[key]
|
|
1022
|
-
for (const [k, c] of Object.entries(this.meta.
|
|
1020
|
+
for (const [k, c] of Object.entries(this.meta.boxes)) if (this.branchOf(c) === key) delete this.meta.boxes[k]
|
|
1023
1021
|
for (const [id, k] of Object.entries(this.meta.hostedBranch || {})) if (k === key) delete this.meta.hostedBranch[id]
|
|
1024
1022
|
if (save) this.saveMeta()
|
|
1025
1023
|
}
|
|
@@ -1196,7 +1194,8 @@ class Room {
|
|
|
1196
1194
|
const force = this.meta.syncStopped ? { stopped: { at: this.meta.syncStopped.at, why: syncStoppedWords(this.meta.syncStopped.at) } } : at != null && this.meta.layout !== LAYOUT_QUILT ? { at: new Date(at).toISOString(), remote: this.hasGitRemote(), ...(act === 'migrate' ? { migrate: true } : {}) } : null
|
|
1197
1195
|
// "Make this a quilt" on a session with a git remote, while Seam imports it (quiltMakeWithRemote).
|
|
1198
1196
|
const imp = !q && !sh && this.meta.quiltImport && process.env.QUILT_SOURCE_URL ? { slug: this.meta.quiltImport.slug || '', repo: this.meta.quiltImport.repo || '' } : null
|
|
1199
|
-
|
|
1197
|
+
// writes: this relay takes a folder's live writes (relay-live-write.js), so apps send them instead of editing texts.
|
|
1198
|
+
return { branches: this.branchList(), writes: 1, ...(q ? { quilt: q } : {}), ...(sh ? { shadow: sh } : {}), ...(imp ? { importing: imp } : {}), ...(this.movingNow ? { moving: this.movingNow } : {}), ...(force ? { force } : {}) }
|
|
1200
1199
|
}
|
|
1201
1200
|
|
|
1202
1201
|
/** Whether the session has a git remote (16: a room with an upstream): it becomes a quilt only with its history. */
|
|
@@ -1330,6 +1329,8 @@ class Room {
|
|
|
1330
1329
|
this.removeBranch(k)
|
|
1331
1330
|
return { ok: true, branch: k, listChanged: true }
|
|
1332
1331
|
}
|
|
1332
|
+
// A folder's live write (relay-live-write.js): merged against the version it started from and applied here, at once.
|
|
1333
|
+
if (req.op === 'live-write') return liveWrite(this, ws, req)
|
|
1333
1334
|
// Quilt source control (src/source-live/live-square.js), behind QUILT_SOURCE, and always once the room is at layout 3: a square's live document's own ops.
|
|
1334
1335
|
if ((req.op === 'seal' || req.op === 'start') && isLiveKey(key) && (process.env.QUILT_SOURCE || this.meta.layout === LAYOUT_QUILT)) {
|
|
1335
1336
|
const k = this.resolveKey(key)
|
|
@@ -1675,7 +1676,7 @@ class Room {
|
|
|
1675
1676
|
|
|
1676
1677
|
/**
|
|
1677
1678
|
* The room as session-quilt.js's dry run reads it: each branch document's files (by hash),
|
|
1678
|
-
* history and merge records,
|
|
1679
|
+
* history and merge records, tasks with pull requests, and commit requests.
|
|
1679
1680
|
* Live square documents (quilt/<id>) are already Seam's and are left out.
|
|
1680
1681
|
*/
|
|
1681
1682
|
quiltSnapshot () {
|
|
@@ -1690,7 +1691,6 @@ class Room {
|
|
|
1690
1691
|
const merges = [...e.doc.getMap('merges').values()].map((m) => ({ id: m && m.id, state: m && m.state }))
|
|
1691
1692
|
branches.push({ key, by: b.by || '', files, history: e.doc.getArray('history').toArray(), merges })
|
|
1692
1693
|
}
|
|
1693
|
-
const claims = Object.values(this.meta.claims || {}).map((c) => ({ pattern: c.pattern, branch: this.branchOf(c), by: c.by || '', byId: c.byId || '', queue: c.queue || [] }))
|
|
1694
1694
|
const tasks = [...this.tasks.entries()].map(([id, t]) => ({ id, pr: t && typeof t.get === 'function' ? t.get('pr') : t && t.pr })).filter((t) => t.pr)
|
|
1695
1695
|
return {
|
|
1696
1696
|
room: this.name,
|
|
@@ -1698,7 +1698,6 @@ class Room {
|
|
|
1698
1698
|
defaultKey: this.defaultKey,
|
|
1699
1699
|
hasRemote: Object.keys(this.meta.upstreams || {}).length > 0,
|
|
1700
1700
|
branches,
|
|
1701
|
-
claims,
|
|
1702
1701
|
tasks,
|
|
1703
1702
|
commitRequests: this.doc.getMap('commitRequests').size
|
|
1704
1703
|
}
|
|
@@ -1757,11 +1756,11 @@ class Room {
|
|
|
1757
1756
|
|
|
1758
1757
|
/**
|
|
1759
1758
|
* What a move into squares made so far, saved as it goes (`meta.quiltMove`): the squares it opened
|
|
1760
|
-
* in Seam
|
|
1759
|
+
* in Seam and the square documents it made here. A relay that stops
|
|
1761
1760
|
* part way (a deploy, a crash) finds it at load (recoverQuiltMove); done or undone, it goes.
|
|
1762
1761
|
*/
|
|
1763
1762
|
startQuiltMove (quilt) {
|
|
1764
|
-
this.meta.quiltMove = { quilt, at: Date.now(), opened: [],
|
|
1763
|
+
this.meta.quiltMove = { quilt, at: Date.now(), opened: [], made: [], ...(this.migrationLease ? { lease: this.migrationLease } : {}) }
|
|
1765
1764
|
this.saveMeta()
|
|
1766
1765
|
return this.meta.quiltMove
|
|
1767
1766
|
}
|
|
@@ -1785,10 +1784,9 @@ class Room {
|
|
|
1785
1784
|
if (this.meta.layout !== LAYOUT_QUILT) {
|
|
1786
1785
|
const live = new Set(Object.values((this.meta.quilt && this.meta.quilt.live) || {}))
|
|
1787
1786
|
for (const lk of mv.made || []) if (isLiveKey(lk) && !live.has(lk) && this.meta.branches[lk]) this.removeBranch(lk, { save: false })
|
|
1788
|
-
const left = this.meta.quiltLeftOver || { quilt: mv.quilt, squares: []
|
|
1787
|
+
const left = this.meta.quiltLeftOver || { quilt: mv.quilt, squares: [] }
|
|
1789
1788
|
if (left.quilt === mv.quilt) {
|
|
1790
1789
|
left.squares = [...new Set([...left.squares, ...(mv.opened || [])])]
|
|
1791
|
-
left.claims = [...left.claims, ...(mv.claimed || [])]
|
|
1792
1790
|
if (mv.lease) left.lease = mv.lease
|
|
1793
1791
|
this.meta.quiltLeftOver = left
|
|
1794
1792
|
}
|
|
@@ -1801,7 +1799,6 @@ class Room {
|
|
|
1801
1799
|
async letGoOfStoppedMove (seam) {
|
|
1802
1800
|
const left = this.meta.quiltLeftOver
|
|
1803
1801
|
if (!left) return
|
|
1804
|
-
for (const c of left.claims || []) if (seam.unclaim) await seam.unclaim(left.quilt, c.square, c.id).catch(() => {})
|
|
1805
1802
|
for (const id of left.squares || []) if (seam.abandon) await seam.abandon(left.quilt, id, { reason: 'a move of the session into the quilt stopped part way' }).catch(() => {})
|
|
1806
1803
|
delete this.meta.quiltLeftOver
|
|
1807
1804
|
this.saveMeta()
|
|
@@ -2114,7 +2111,6 @@ class Room {
|
|
|
2114
2111
|
const Q = into ? into.quilt : this.meta.quilt
|
|
2115
2112
|
const move = this.meta.quiltMove || this.startQuiltMove(q)
|
|
2116
2113
|
const made = []
|
|
2117
|
-
const claimed = []
|
|
2118
2114
|
const unwatch = []
|
|
2119
2115
|
let adoption = null
|
|
2120
2116
|
const by = (a && (a.name || a.sub || a.key)) || ''
|
|
@@ -2157,11 +2153,9 @@ class Room {
|
|
|
2157
2153
|
const main = treeIds(mainTree)
|
|
2158
2154
|
const def = texts(this.defaultKey, mainTree)
|
|
2159
2155
|
const adopt = overlayFor(def, main)
|
|
2160
|
-
//
|
|
2161
|
-
const defaultClaims = Object.values(this.meta.claims || {}).some((c) => (this.branchOf(c) || this.defaultKey) === this.defaultKey)
|
|
2162
|
-
// So does a large file in the session's storage that main lacks: the folders that have it put it there.
|
|
2156
|
+
// A large file in the session's storage that main lacks: the folders that have it put it there.
|
|
2163
2157
|
const defaultLarge = [...this.store.load(this.defaultKey).blobs].some(([p, x]) => x && typeof x.data !== 'string' && !x.blob && !main[p])
|
|
2164
|
-
if (Object.keys(adopt.puts).length || adopt.gone.length ||
|
|
2158
|
+
if (Object.keys(adopt.puts).length || adopt.gone.length || defaultLarge) {
|
|
2165
2159
|
const s = await seam.openSquare(q, { title: `Uncommitted work from ${this.name}`.slice(0, 200) })
|
|
2166
2160
|
adoption = s.id
|
|
2167
2161
|
move.opened.push(s.id)
|
|
@@ -2182,7 +2176,7 @@ class Room {
|
|
|
2182
2176
|
}
|
|
2183
2177
|
for (const p of plan) {
|
|
2184
2178
|
p.boxes = {}
|
|
2185
|
-
for (const c of Object.values(this.meta.
|
|
2179
|
+
for (const c of Object.values(this.meta.boxes || {})) {
|
|
2186
2180
|
const file = c && c.box && (this.branchOf(c) || this.defaultKey) === p.key ? String(c.pattern || '') : ''
|
|
2187
2181
|
if (!file || /[*?[]/.test(file) || typeof p.files[file] !== 'string' || !p.head || !p.tree[file] || p.tree[file] === blobId(Buffer.from(p.files[file]))) continue
|
|
2188
2182
|
const v = await this.versionsOnLine(seam, q, p.head, file, p.tree[file]).catch(() => null)
|
|
@@ -2219,39 +2213,6 @@ class Room {
|
|
|
2219
2213
|
}
|
|
2220
2214
|
// A branch edited since its files were read is copied and checked again in the catch-up below.
|
|
2221
2215
|
for (const p of plan) if (!p.flag.edited) check(p)
|
|
2222
|
-
// Claims move to Seam's claims, on the square made from their branch (16's claims row).
|
|
2223
|
-
const squareOf = Object.fromEntries(plan.map((p) => [p.key, p.sq]))
|
|
2224
|
-
const claimsLeft = []
|
|
2225
|
-
// Claims made while the claims move (or the move waits on Seam) move too: until a look finds none new.
|
|
2226
|
-
const seen = new Set()
|
|
2227
|
-
for (let round = 0; round < MOVE_CATCH_UP_ROUNDS; round++) {
|
|
2228
|
-
const fresh = Object.entries(this.meta.claims || {}).filter(([k]) => !seen.has(k))
|
|
2229
|
-
if (!fresh.length) break
|
|
2230
|
-
for (const [k, c] of fresh) {
|
|
2231
|
-
seen.add(k)
|
|
2232
|
-
const sq = squareOf[this.branchOf(c) || this.defaultKey]
|
|
2233
|
-
if (!sq) { claimsLeft.push({ pattern: c.pattern, branch: this.branchOf(c) || this.defaultKey, by: c.by || '', why: 'no square' }); continue }
|
|
2234
|
-
try {
|
|
2235
|
-
// Seam makes a claim only as its caller (the mover), so the note says whose it was, and the
|
|
2236
|
-
// record keeps them: that person (or the owner) lets go of it from Quilt (quilt-claims).
|
|
2237
|
-
const r = await seam.claim(q, sq, { pattern: c.pattern, note: `${c.by || 'someone'}'s claim from the session${c.note ? `: ${c.note}` : ''}`.slice(0, 280) })
|
|
2238
|
-
claimed.push({ square: sq, id: r && r.id, pattern: c.pattern, by: c.by || '', ...(c.byId ? { byId: c.byId } : {}) })
|
|
2239
|
-
move.claimed.push({ square: sq, id: (r && r.id) || c.pattern })
|
|
2240
|
-
} catch (err) { claimsLeft.push({ pattern: c.pattern, branch: this.branchOf(c) || this.defaultKey, by: c.by || '', why: err.message }) }
|
|
2241
|
-
this.stillHere()
|
|
2242
|
-
this.saveMeta()
|
|
2243
|
-
}
|
|
2244
|
-
}
|
|
2245
|
-
// The post-run check (16, "Dry run and check"): every claim moved names an open square.
|
|
2246
|
-
if (claimed.length) {
|
|
2247
|
-
const now = await seam.claims(q)
|
|
2248
|
-
for (const c of claimed) {
|
|
2249
|
-
const row = (now || []).find((x) => x && (x.id === c.id || (x.square_id === c.square && x.pattern === c.pattern)))
|
|
2250
|
-
if (!row) throw new Error(`the claim on ${c.pattern} is not in the quilt after moving it`)
|
|
2251
|
-
const s = await seam.square(q, c.square)
|
|
2252
|
-
if (!s || s.state !== 'open') throw new Error(`the claim on ${c.pattern} names square ${squareShort(c.square)}, which is ${s ? s.state : 'gone'}`)
|
|
2253
|
-
}
|
|
2254
|
-
}
|
|
2255
2216
|
// Every person in the session writes in every square, not only the holder who moved it, so their AIs (working for them) commit there too.
|
|
2256
2217
|
const people = [...Object.entries(this.meta.members || {}).map(([key, m]) => ({ key, role: m && m.role })), ...(this.meta.ownerSub ? [{ key: this.meta.ownerSub, role: 'editor' }] : [])]
|
|
2257
2218
|
const notShared = []
|
|
@@ -2290,7 +2251,6 @@ class Room {
|
|
|
2290
2251
|
}
|
|
2291
2252
|
if (large.length) Q.large = large
|
|
2292
2253
|
if (adoption) Q.adoption = adoption
|
|
2293
|
-
if (claimed.length || claimsLeft.length) Q.claims = { moved: claimed, left: claimsLeft }
|
|
2294
2254
|
Q.layoutAt = new Date(date).toISOString()
|
|
2295
2255
|
// Git's bookkeeping leaves the room (16: dropped), kept for a rollback.
|
|
2296
2256
|
Q.kept = takeGitMeta(this.meta)
|
|
@@ -2302,9 +2262,8 @@ class Room {
|
|
|
2302
2262
|
if (!ws.hosted && !this.supported(ws)) { ws.endReason = 'needs_update'; ws.close(CLOSE_NEEDS_UPDATE, this.needsUpdate()) }
|
|
2303
2263
|
}
|
|
2304
2264
|
this.broadcastBranches()
|
|
2305
|
-
return { layout: LAYOUT_QUILT, live: Q.live, adoption,
|
|
2265
|
+
return { layout: LAYOUT_QUILT, live: Q.live, adoption, ...(rebased.length ? { rebased } : {}), ...(large.length ? { large } : {}), ...(notShared.length ? { not_shared: notShared } : {}) }
|
|
2306
2266
|
} catch (err) {
|
|
2307
|
-
for (const c of claimed) if (seam.unclaim) await seam.unclaim(q, c.square, c.id || c.pattern).catch(() => {})
|
|
2308
2267
|
if (adoption && seam.abandon) await seam.abandon(q, adoption, { reason: 'the session\'s move into its squares was undone' }).catch(() => {})
|
|
2309
2268
|
for (const lk of made) this.removeBranch(lk)
|
|
2310
2269
|
if (made.length) this.broadcastBranches()
|
|
@@ -2377,14 +2336,13 @@ class Room {
|
|
|
2377
2336
|
*/
|
|
2378
2337
|
async quiltCatchUp (a, seam, branch, { by = '' } = {}) {
|
|
2379
2338
|
if (this.meta.layout !== LAYOUT_QUILT) throw new Error('this session\'s files are not in squares')
|
|
2380
|
-
//
|
|
2381
|
-
//
|
|
2382
|
-
// work had long landed (2026-11-05: 11 of Daniel's, handed on from Moss in October).
|
|
2339
|
+
// Boxes the relay kept from before the session's files went into squares only showed people
|
|
2340
|
+
// holding files whose work had long landed (2026-11-05: 11 of Daniel's, handed on from Moss in October).
|
|
2383
2341
|
const switched = Date.parse((this.meta.quilt || {}).layoutAt || '')
|
|
2384
|
-
if (switched && Object.values(this.meta.
|
|
2385
|
-
this.
|
|
2342
|
+
if (switched && Object.values(this.meta.boxes || {}).some((c) => c && Number(c.ts) < switched)) {
|
|
2343
|
+
this.dropBoxes((c) => !!c && Number(c.ts) < switched)
|
|
2386
2344
|
this.saveMeta()
|
|
2387
|
-
this.
|
|
2345
|
+
this.broadcastBoxes()
|
|
2388
2346
|
}
|
|
2389
2347
|
const key = String(branch || '')
|
|
2390
2348
|
const lk = (this.meta.quilt.live || {})[key]
|
|
@@ -2542,7 +2500,7 @@ class Room {
|
|
|
2542
2500
|
|
|
2543
2501
|
/**
|
|
2544
2502
|
* A branch with no square at layout 3 (the default branch when it equalled main's tip and held no
|
|
2545
|
-
*
|
|
2503
|
+
* box, so the move opened no adoption square; a branch made after a quilt was made without
|
|
2546
2504
|
* history; a branch checked out in git after the move, which the relay has no copy of): its folders' writes reach only its read-only document, so the first member who writes
|
|
2547
2505
|
* there asks for one (`quilt-open`, the app's readOnly answer). It is opened as that member (its
|
|
2548
2506
|
* holder), at the commit the branch document is of (the move's base for it: its ref's imported
|
|
@@ -2665,7 +2623,7 @@ class Room {
|
|
|
2665
2623
|
this.stillHere()
|
|
2666
2624
|
if (r && (r.error || r.copied.length || r.left.length || r.uncommitted)) kept.push(r)
|
|
2667
2625
|
}
|
|
2668
|
-
// Nobody follows a carried square any more (its work is back in the branches): it is abandoned
|
|
2626
|
+
// Nobody follows a carried square any more (its work is back in the branches): it is abandoned.
|
|
2669
2627
|
for (const s of open) if (seam.abandon) await seam.abandon(q, s.id, { reason: 'carried back to the session\'s branches (quilt session migrate --back)' }).catch(() => {})
|
|
2670
2628
|
restoreGitMeta(this.meta, this.meta.quilt.kept)
|
|
2671
2629
|
delete this.meta.quilt.kept
|
|
@@ -3019,11 +2977,10 @@ class Room {
|
|
|
3019
2977
|
if (req.op === 'remove') {
|
|
3020
2978
|
// An account goes with any older entries for keys it has used here, so it can't get back in by key.
|
|
3021
2979
|
const gone = [key, ...((this.meta.accountKeys || {})[key] || [])]
|
|
3022
|
-
// Their
|
|
2980
|
+
// Their boxes open: nobody left could commit them, so their work reaches every folder.
|
|
3023
2981
|
const names = gone.map((id) => this.meta.members[id]?.name).filter(Boolean)
|
|
3024
2982
|
const theirs = (x) => x.byId ? gone.includes(x.byId) : names.includes(x.by)
|
|
3025
|
-
this.
|
|
3026
|
-
this.dropClaims(theirs, (c) => `${c.by} was removed from the session.`)
|
|
2983
|
+
this.dropBoxes(theirs)
|
|
3027
2984
|
for (const id of gone) delete this.meta.members[id]
|
|
3028
2985
|
// A pass issued before now can't bring them back by its grant (see passGrant). Removals
|
|
3029
2986
|
// older than a pass lasts can match no valid pass, so they go; the newest are kept.
|
|
@@ -3033,7 +2990,7 @@ class Room {
|
|
|
3033
2990
|
this.saveMeta()
|
|
3034
2991
|
for (const [cws, a] of this.access) if (gone.includes(a.id)) { cws.endReason = 'removed'; cws.close(CLOSE_DENIED, 'The session owner removed you') }
|
|
3035
2992
|
for (const id of gone) { this.hostedSeen.delete(id); this.forgetHostedBranch(id); if (this.onHostedGone) this.onHostedGone(id, 'removed') }
|
|
3036
|
-
this.
|
|
2993
|
+
this.broadcastBoxes()
|
|
3037
2994
|
return { ok: true }
|
|
3038
2995
|
}
|
|
3039
2996
|
throw new Error('unknown request')
|
|
@@ -3086,84 +3043,75 @@ class Room {
|
|
|
3086
3043
|
return true
|
|
3087
3044
|
}
|
|
3088
3045
|
|
|
3089
|
-
/** Who a
|
|
3090
|
-
|
|
3046
|
+
/** Who a box from this connection belongs to: their name, or with sign-in on, their account; on the branch they're on. */
|
|
3047
|
+
boxOwner (ws, as = null) {
|
|
3091
3048
|
const name = this.names.get(ws)
|
|
3092
3049
|
const a = this.access.get(ws)
|
|
3093
3050
|
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 }
|
|
3094
|
-
// An older app (0.3.109)
|
|
3095
|
-
// name
|
|
3096
|
-
//
|
|
3051
|
+
// An older app (0.3.109) boxes for one of its AI sessions (`as`): the box keeps that session's
|
|
3052
|
+
// name and says whose it is (`of`), so everyone shows it as that person. Nobody can box as
|
|
3053
|
+
// someone else's: the name is built here from the connection's own.
|
|
3097
3054
|
if (!as || typeof as.id !== 'string' || !/^[A-Za-z0-9_-]{4,40}$/.test(as.id)) return who
|
|
3098
3055
|
return { ...who, name: personaName(name, as.label), ...(who.id ? { id: `${who.id}~${as.id}` } : {}), persona: true, of: name }
|
|
3099
3056
|
}
|
|
3100
3057
|
|
|
3101
|
-
/** Which branch a
|
|
3058
|
+
/** Which branch a box is on: its own, or the default branch (boxes from before branches). */
|
|
3102
3059
|
branchOf (c) { return c.branch ? this.resolveKey(c.branch) : this.defaultKey }
|
|
3103
3060
|
|
|
3104
|
-
/** Where a
|
|
3105
|
-
|
|
3061
|
+
/** Where a box on `file` on `branch` is kept in meta.boxes: the default branch keeps bare paths. */
|
|
3062
|
+
boxKey (branch, file) {
|
|
3106
3063
|
const b = this.resolveKey(branch || this.defaultKey)
|
|
3107
|
-
return b === this.defaultKey ?
|
|
3064
|
+
return b === this.defaultKey ? file : `${b}\0${file}`
|
|
3108
3065
|
}
|
|
3109
3066
|
|
|
3110
|
-
|
|
3067
|
+
shownBox (c) { return { ...c, active: this.holderPresent(c), activeAt: this.lastActive(c) } }
|
|
3111
3068
|
|
|
3112
3069
|
/**
|
|
3113
|
-
* The
|
|
3114
|
-
*
|
|
3115
|
-
*
|
|
3070
|
+
* The boxes on one branch (the default when none is given), each with `active` (whoever holds
|
|
3071
|
+
* it is in the session now) and `activeAt` (when they last did something there), oldest first.
|
|
3072
|
+
* Quilt holds no files (no-holds, 2026-11-13): a box is only someone's unfinished work on one
|
|
3073
|
+
* file, kept out of other folders until it is committed; it never stops anyone writing.
|
|
3116
3074
|
*/
|
|
3117
|
-
|
|
3075
|
+
boxList (branch) {
|
|
3118
3076
|
const b = this.resolveKey(branch || this.defaultKey)
|
|
3119
|
-
return Object.values(this.meta.
|
|
3077
|
+
return Object.values(this.meta.boxes).filter((c) => this.branchOf(c) === b).map((c) => this.shownBox(c)).sort((x, y) => x.ts - y.ts)
|
|
3120
3078
|
}
|
|
3121
3079
|
|
|
3122
|
-
/** Every
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
/** The files on a branch, for telling whether two patterns overlap (and the room document's, in rooms from before branches). */
|
|
3126
|
-
branchPaths (branch) {
|
|
3127
|
-
const k = this.resolveKey(branch || this.defaultKey)
|
|
3128
|
-
const e = this.store.load(k)
|
|
3129
|
-
return [...e.files.keys(), ...e.blobs.keys(), ...this.doc.getMap('files').keys(), ...this.doc.getMap('blobs').keys()]
|
|
3130
|
-
}
|
|
3080
|
+
/** Every box on every branch. */
|
|
3081
|
+
allBoxes () { return Object.values(this.meta.boxes).map((c) => this.shownBox(c)).sort((x, y) => x.ts - y.ts) }
|
|
3131
3082
|
|
|
3132
|
-
/** Who holds a
|
|
3083
|
+
/** Who holds a box: their account with sign-in on, otherwise their name. */
|
|
3133
3084
|
holderKey (c) { return c.byId || `name:${c.by}` }
|
|
3134
3085
|
|
|
3135
|
-
/** The holder keys a connection speaks for: its account, and its name (
|
|
3086
|
+
/** The holder keys a connection speaks for: its account, and its name (boxes older than sign-in). */
|
|
3136
3087
|
holderKeys (ws) {
|
|
3137
3088
|
const keys = [`name:${this.names.get(ws)}`]
|
|
3138
3089
|
if (ws.pass) keys.push(`${ws.pass.kind}:${ws.pass.sub}`)
|
|
3139
3090
|
return keys
|
|
3140
3091
|
}
|
|
3141
3092
|
|
|
3142
|
-
/**
|
|
3143
|
-
claimantKey (who) { return who.id || `name:${who.name}` }
|
|
3144
|
-
|
|
3145
|
-
/** Someone did something in the session: their claims' idle time starts again. */
|
|
3093
|
+
/** Someone did something in the session: their boxes' reminder waits again (sweepBoxes). */
|
|
3146
3094
|
noteActivity (keys) {
|
|
3147
3095
|
const now = Date.now()
|
|
3148
3096
|
let save = false
|
|
3149
3097
|
for (const k of keys) {
|
|
3150
|
-
if (!Object.values(this.meta.
|
|
3151
|
-
// Saved now and then, so a relay restart doesn't count them
|
|
3098
|
+
if (!Object.values(this.meta.boxes).some((c) => this.holderKey(c) === k)) continue
|
|
3099
|
+
// Saved now and then, so a relay restart doesn't count them away for longer than they were.
|
|
3152
3100
|
if (now - (this.meta.seen[k] || 0) > 60 * 1000) save = true
|
|
3153
3101
|
this.meta.seen[k] = now
|
|
3154
3102
|
}
|
|
3155
3103
|
if (save) this.saveMeta()
|
|
3156
3104
|
}
|
|
3157
3105
|
|
|
3158
|
-
/** When a
|
|
3106
|
+
/** When a box's holder last did something in the session (since the relay loaded it, at the earliest). */
|
|
3159
3107
|
lastActive (c) {
|
|
3160
3108
|
return Math.max(this.meta.seen[this.holderKey(c)] ?? this.loadedAt, c.ts || 0)
|
|
3161
3109
|
}
|
|
3162
3110
|
|
|
3163
|
-
/** Whether a
|
|
3111
|
+
/** Whether a box's holder is in the session now: connected, or a hosted agent seen lately. */
|
|
3164
3112
|
holderPresent (c) {
|
|
3165
3113
|
if (c.byId) {
|
|
3166
|
-
// An AI session's
|
|
3114
|
+
// An AI session's box (account~session) is here while its person's app is.
|
|
3167
3115
|
const base = c.byId.split('~')[0]
|
|
3168
3116
|
const seen = this.hostedSeen.get(base)
|
|
3169
3117
|
if (seen && Date.now() - seen < HOSTED_ONLINE_MS) return true
|
|
@@ -3174,87 +3122,26 @@ class Room {
|
|
|
3174
3122
|
return this.hostedOnline().some((h) => h.name === c.by)
|
|
3175
3123
|
}
|
|
3176
3124
|
|
|
3177
|
-
/** The
|
|
3178
|
-
|
|
3179
|
-
claimFor (file, branch) {
|
|
3180
|
-
const own = this.meta.claims[this.claimKey(branch, file)]
|
|
3181
|
-
if (own) return own
|
|
3182
|
-
const b = this.resolveKey(branch || this.defaultKey)
|
|
3183
|
-
return Object.values(this.meta.claims).filter((c) => this.branchOf(c) === b && globMatcher(c.pattern)(file)).sort((x, y) => x.ts - y.ts)[0] || null
|
|
3184
|
-
}
|
|
3125
|
+
/** The box on one file on a branch (the live record in meta.boxes), or null. */
|
|
3126
|
+
boxFor (file, branch) { return this.meta.boxes[this.boxKey(branch, file)] || null }
|
|
3185
3127
|
|
|
3186
|
-
/**
|
|
3187
|
-
|
|
3188
|
-
* to the first of them instead of being released (`why` says why, in the message they get).
|
|
3189
|
-
* Returns how many went.
|
|
3190
|
-
*/
|
|
3191
|
-
dropClaims (pick, why = null) {
|
|
3128
|
+
/** Opens the boxes `pick` chooses: their work stays in the session and reaches every folder. Returns how many went. */
|
|
3129
|
+
dropBoxes (pick) {
|
|
3192
3130
|
let n = 0
|
|
3193
|
-
for (const c of Object.
|
|
3131
|
+
for (const [k, c] of Object.entries(this.meta.boxes)) {
|
|
3194
3132
|
if (!pick(c)) continue
|
|
3195
3133
|
n++
|
|
3196
|
-
|
|
3197
|
-
else delete this.meta.claims[this.claimKey(c.branch, c.pattern)]
|
|
3134
|
+
delete this.meta.boxes[k]
|
|
3198
3135
|
}
|
|
3199
3136
|
this.forgetSeen()
|
|
3200
3137
|
return n
|
|
3201
3138
|
}
|
|
3202
3139
|
|
|
3203
|
-
/**
|
|
3204
|
-
* `quilt release <path>` when no claim on this branch is under that name (task 7b480c8b07c4fa02: the relay
|
|
3205
|
-
* held web/lib/docs.js for Sriram, and his release let go of 0 claims, with nothing to say why):
|
|
3206
|
-
* - his own claim on exactly that path on another branch (he holds it on main, his folder is on a task
|
|
3207
|
-
* branch now) is let go of there, as he asked; one someone waits for stays, to be handed off;
|
|
3208
|
-
* - a folder or glob claim that covers the path is named (coveredBy, holder), so he can release that.
|
|
3209
|
-
*/
|
|
3210
|
-
releaseNotHere (who, pattern, branch, { mine, queued }) {
|
|
3211
|
-
const elsewhere = Object.values(this.meta.claims).filter((x) => x.pattern === pattern && mine(x) && this.branchOf(x) !== branch)
|
|
3212
|
-
const free = elsewhere.filter((x) => !queued(x))
|
|
3213
|
-
const held = elsewhere.filter((x) => queued(x)).map((x) => x.pattern)
|
|
3214
|
-
if (free.length) {
|
|
3215
|
-
const branches = free.map((x) => this.branchOf(x))
|
|
3216
|
-
this.dropClaims((x) => free.includes(x), (x) => `${x.by} let go of it.`)
|
|
3217
|
-
return { ok: true, released: free.length, branches, ...(held.length ? { held } : {}) }
|
|
3218
|
-
}
|
|
3219
|
-
const cover = this.claimFor(pattern, branch)
|
|
3220
|
-
if (cover && cover.pattern !== pattern) return { ok: true, released: 0, coveredBy: cover.pattern, holder: cover.by, ...(mine(cover) ? { yours: true } : {}), ...(held.length ? { held } : {}) }
|
|
3221
|
-
return { ok: true, released: 0, ...(held.length ? { held } : {}) }
|
|
3222
|
-
}
|
|
3223
|
-
|
|
3224
|
-
/** Takes the requests `pick` chooses out of every file queue (someone removed, or gone). */
|
|
3225
|
-
dropRequests (pick) {
|
|
3226
|
-
for (const c of Object.values(this.meta.claims)) {
|
|
3227
|
-
if (!c.queue) continue
|
|
3228
|
-
c.queue = c.queue.filter((r) => !pick(r))
|
|
3229
|
-
if (!c.queue.length) delete c.queue
|
|
3230
|
-
}
|
|
3231
|
-
}
|
|
3232
|
-
|
|
3233
3140
|
forgetSeen () {
|
|
3234
|
-
for (const k of Object.keys(this.meta.seen)) if (!Object.values(this.meta.
|
|
3141
|
+
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]
|
|
3235
3142
|
}
|
|
3236
3143
|
|
|
3237
|
-
/**
|
|
3238
|
-
* Gives claim `c` to the one who asked for it in request `r`, with the holder's context,
|
|
3239
|
-
* and tells them in a direct message (which wakes their agent). The rest of the queue
|
|
3240
|
-
* stays with the claim: the new holder hands it on in turn.
|
|
3241
|
-
*/
|
|
3242
|
-
handOff (c, r, { context = '', auto = false } = {}) {
|
|
3243
|
-
const now = Date.now()
|
|
3244
|
-
const queue = (c.queue || []).filter((x) => x.id !== r.id)
|
|
3245
|
-
const next = { ...(c.branch ? { branch: c.branch } : {}), by: r.by, ...(r.byId ? { byId: r.byId } : {}), ...(r.of ? { of: r.of } : {}), pattern: c.pattern, note: String(r.title || '').slice(0, 500), ts: now, from: c.by, ...(r.clash ? { clash: r.clash } : {}) }
|
|
3246
|
-
if (queue.length) next.queue = queue
|
|
3247
|
-
this.meta.claims[this.claimKey(c.branch, c.pattern)] = next
|
|
3248
|
-
this.meta.seen[this.holderKey(next)] = now
|
|
3249
|
-
const text = auto
|
|
3250
|
-
? `📦 ${c.pattern} is yours now: you asked for it ("${r.title}"). ${context}`.trim()
|
|
3251
|
-
: `📦 I'm handing you ${c.pattern} (you asked: "${r.title}"). My context: ${context}`
|
|
3252
|
-
// Sent as from the holder; marked as a handoff, it wakes them but asks for no answer (duties.js).
|
|
3253
|
-
this.postChat({ by: c.by, to: r.by, text, kind: 'handoff', path: c.pattern })
|
|
3254
|
-
this.log(`[${this.name}] ${c.pattern} handed from ${c.by} to ${r.by}${auto ? ' (automatically)' : ''}`)
|
|
3255
|
-
}
|
|
3256
|
-
|
|
3257
|
-
/** A chat entry written by the relay itself (file queue requests and handoffs). */
|
|
3144
|
+
/** A chat entry written by the relay itself (box reminders, answers to @Quilt, approvals). */
|
|
3258
3145
|
postChat ({ by, to = null, text, kind, path: file, re, mail, wake, approval }) {
|
|
3259
3146
|
const chat = this.doc.getArray('chat')
|
|
3260
3147
|
const msg = { id: crypto.randomBytes(8).toString('hex'), by, to, text: String(text).slice(0, 4000), ts: Date.now(), kind, path: file }
|
|
@@ -3293,44 +3180,31 @@ class Room {
|
|
|
3293
3180
|
}
|
|
3294
3181
|
|
|
3295
3182
|
/**
|
|
3296
|
-
*
|
|
3297
|
-
*
|
|
3298
|
-
*
|
|
3299
|
-
*/
|
|
3300
|
-
sweepClaims (now = Date.now()) {
|
|
3301
|
-
const mins = Math.round(this.cfg.claimIdleMs / 60000)
|
|
3302
|
-
// A box never times out: it holds unfinished work nobody else has (sweepBoxes reminds its holder instead).
|
|
3303
|
-
const n = this.dropClaims((c) => !c.box && now - this.lastActive(c) >= this.cfg.claimIdleMs, (c) => `${c.by} had done nothing in the session for ${mins} minutes.`)
|
|
3304
|
-
if (n) this.log(`[${this.name}] let go of ${n} claim(s) idle for ${mins} minutes`)
|
|
3305
|
-
// Also when a holder came or went: everyone's app shows whose claims are held by someone away.
|
|
3306
|
-
const shown = this.allClaims().map((c) => `${c.branch || ''}\0${c.pattern}\0${c.active}`).join('\n')
|
|
3307
|
-
if (n || shown !== this.claimsShown) { this.claimsShown = shown; this.broadcastClaims() }
|
|
3308
|
-
return n
|
|
3309
|
-
}
|
|
3310
|
-
|
|
3311
|
-
/**
|
|
3312
|
-
* Boxes never time out like claims; one whose holder has been away a day gets one reminder a day in chat
|
|
3313
|
-
* (to their person, for an AI session's box). The session owner can release it. Returns how many were sent.
|
|
3183
|
+
* Boxes never time out; one whose holder has been away a day gets one reminder a day in chat
|
|
3184
|
+
* (to their person, for an AI session's box). Returns how many were sent. Also tells everyone
|
|
3185
|
+
* when a box holder came or went, so the app shows whose unfinished work waits on someone away.
|
|
3314
3186
|
*/
|
|
3315
3187
|
sweepBoxes (now = Date.now()) {
|
|
3316
3188
|
this.handBackCloudBoxes(now)
|
|
3317
3189
|
let n = 0
|
|
3318
|
-
for (const c of Object.values(this.meta.
|
|
3319
|
-
if (
|
|
3190
|
+
for (const c of Object.values(this.meta.boxes)) {
|
|
3191
|
+
if (this.holderPresent(c)) continue
|
|
3320
3192
|
if (now - this.lastActive(c) < BOX_REMIND_MS || now - (c.reminded || 0) < BOX_REMIND_MS) continue
|
|
3321
3193
|
c.reminded = now
|
|
3322
3194
|
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.` })
|
|
3323
3195
|
n++
|
|
3324
3196
|
}
|
|
3325
3197
|
if (n) this.saveMeta()
|
|
3198
|
+
const shown = this.allBoxes().map((c) => `${c.branch || ''}\0${c.pattern}\0${c.active}`).join('\n')
|
|
3199
|
+
if (shown !== this.boxesShown) { this.boxesShown = shown; this.broadcastBoxes() }
|
|
3326
3200
|
return n
|
|
3327
3201
|
}
|
|
3328
3202
|
|
|
3329
3203
|
/**
|
|
3330
3204
|
* A person's cloud AI away CLOUD_AI_GONE_MS (its machine asleep or stopped: its daily cap, its tool's
|
|
3331
|
-
* own limit, a crash) never keeps its boxes: each goes to
|
|
3332
|
-
*
|
|
3333
|
-
*
|
|
3205
|
+
* own limit, a crash) never keeps its boxes: each goes to its person, whose folder gets the work to
|
|
3206
|
+
* commit or carry on. If the AI carries on first, it takes back what its person hasn't boxed since
|
|
3207
|
+
* (boxRequestOp). Returns how many went.
|
|
3334
3208
|
*/
|
|
3335
3209
|
handBackCloudBoxes (now = Date.now()) {
|
|
3336
3210
|
const gone = (id) => {
|
|
@@ -3343,16 +3217,12 @@ class Room {
|
|
|
3343
3217
|
if (!people.size) return 0
|
|
3344
3218
|
const given = new Map() // its person -> { ai, files }
|
|
3345
3219
|
let n = 0
|
|
3346
|
-
for (const c of Object.values(this.meta.
|
|
3347
|
-
const ai = c.
|
|
3220
|
+
for (const c of Object.values(this.meta.boxes)) {
|
|
3221
|
+
const ai = c.byId ? people.get(c.byId) : null
|
|
3348
3222
|
if (!ai || !gone(c.byId)) continue
|
|
3349
3223
|
n++
|
|
3350
|
-
if (c.queue && c.queue.length) {
|
|
3351
|
-
this.handOff(c, c.queue[0], { context: `${c.by} stopped before committing its work in it: that work is in it now.`, auto: true })
|
|
3352
|
-
continue
|
|
3353
|
-
}
|
|
3354
3224
|
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 }
|
|
3355
|
-
this.meta.
|
|
3225
|
+
this.meta.boxes[this.boxKey(c.branch, c.pattern)] = next
|
|
3356
3226
|
this.meta.seen[this.holderKey(next)] = now
|
|
3357
3227
|
const g = given.get(ai.name) || { ai: c.by, files: [] }
|
|
3358
3228
|
g.files.push(c.branch ? `${c.pattern} (on ${c.branch})` : c.pattern)
|
|
@@ -3361,168 +3231,145 @@ class Room {
|
|
|
3361
3231
|
if (!n) return 0
|
|
3362
3232
|
for (const [person, g] of given) {
|
|
3363
3233
|
const files = g.files.length > 3 ? `${g.files.slice(0, 3).join(', ')} and ${g.files.length - 3} more` : g.files.join(', ')
|
|
3364
|
-
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 back
|
|
3234
|
+
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.` })
|
|
3365
3235
|
this.log(`[${this.name}] ${g.ai} is away: its boxes (${g.files.join(', ')}) went to ${person}`)
|
|
3366
3236
|
}
|
|
3367
3237
|
this.forgetSeen()
|
|
3368
3238
|
this.saveMeta()
|
|
3369
|
-
this.
|
|
3239
|
+
this.broadcastBoxes()
|
|
3370
3240
|
return n
|
|
3371
3241
|
}
|
|
3372
3242
|
|
|
3243
|
+
/** The owner's name in the session's chat, or '' in a session nobody controls. */
|
|
3244
|
+
ownerName () {
|
|
3245
|
+
if (!this.meta.owner && !this.meta.ownerName) return ''
|
|
3246
|
+
return this.meta.ownerName || Object.entries(this.meta.identities || {}).find(([, k]) => k === this.meta.owner)?.[0] || ''
|
|
3247
|
+
}
|
|
3248
|
+
|
|
3373
3249
|
/**
|
|
3374
|
-
*
|
|
3375
|
-
*
|
|
3376
|
-
*
|
|
3250
|
+
* The person a held record's writer works for (held.js): a person's cloud AI's person, the owner for an
|
|
3251
|
+
* agent of its own (nobody else answers for it here), else the writer (a person, or their AI session).
|
|
3252
|
+
* { name, owner }: `owner` when it fell to the owner for want of a person.
|
|
3377
3253
|
*/
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
const
|
|
3382
|
-
|
|
3383
|
-
return
|
|
3254
|
+
heldPersonOf (r) {
|
|
3255
|
+
const ai = Object.values(this.meta.cloudAis || {}).find((e) => e && e.ofName && ((r.byId && e.agent === r.byId) || e.name === r.by))
|
|
3256
|
+
if (ai) return { name: ai.ofName, owner: false }
|
|
3257
|
+
const m = r.byId ? (this.meta.members || {})[r.byId] : null
|
|
3258
|
+
const agent = m ? m.kind === 'agent' : /^agent:/.test(r.byId || '')
|
|
3259
|
+
if (agent) { const o = this.ownerName(); if (o) return { name: o, owner: true } }
|
|
3260
|
+
return { name: r.by, owner: false }
|
|
3384
3261
|
}
|
|
3385
3262
|
|
|
3386
|
-
|
|
3263
|
+
/**
|
|
3264
|
+
* Held conflicts nobody resolved (held.js; Seam's 07 escalation, ruling 2026-10-30). Open 4 hours: the
|
|
3265
|
+
* writer's person is told; 24: the session's owner too. Each once per record (`flagged4`, `flagged24`),
|
|
3266
|
+
* by a direct message from Quilt, which waits in their inbox and chat until they are back. A record
|
|
3267
|
+
* past the two-attempt budget becomes a task on the board (To do, assigned to the writer's person,
|
|
3268
|
+
* never picked up by an AI on its own). Run from the heartbeat, and for a session nobody has open when
|
|
3269
|
+
* its next notice falls due (`meta.heldDue`, see heldWake). Returns how many notices and tasks went.
|
|
3270
|
+
*/
|
|
3271
|
+
sweepHeld (now = Date.now()) {
|
|
3272
|
+
if (!this.doc || this.ended || this.destroyed) return 0
|
|
3273
|
+
const map = this.doc.getMap(HELD_MAP)
|
|
3274
|
+
let n = 0
|
|
3275
|
+
if (map.size) {
|
|
3276
|
+
const tasks = this.doc.getMap('tasks')
|
|
3277
|
+
for (const r of heldTasksDue(readHeld(map))) {
|
|
3278
|
+
const person = this.heldPersonOf(r)
|
|
3279
|
+
const title = heldTaskTitle(r)
|
|
3280
|
+
// One task per path while it is open: a later record on the same path joins it.
|
|
3281
|
+
const open = readTasks(tasks).find((t) => !t.archived && t.column !== 'done' && t.title === title)
|
|
3282
|
+
let task = open
|
|
3283
|
+
if (!task) {
|
|
3284
|
+
try {
|
|
3285
|
+
task = addTask(this.doc, tasks, { title, by: RELAY_BY, assignee: person.name, files: [r.path], noPickup: true })
|
|
3286
|
+
} catch (err) { this.log(`[${this.name}] could not put the held conflict in ${r.path} on the board: ${err.message}`); continue }
|
|
3287
|
+
this.postChat({ by: RELAY_BY, to: person.name, kind: 'nudge', path: r.path, text: `⚖️ ${r.by === person.name ? 'Your' : `${r.by}'s`} changes to \`${r.path}\` (id ${r.id}) were held again after ${r.attempts} resolutions, so the conflict is a task for you on the board ("${title}"): AIs leave it to you now. Resolve it with quilt_resolve_merge, then move the task on.` })
|
|
3288
|
+
this.log(`[${this.name}] ⚖️ ${r.path}: held again after ${r.attempts} resolutions; a task for ${person.name}`)
|
|
3289
|
+
}
|
|
3290
|
+
noteHeld(this.doc, map, r.id, { task: task.id, taskFor: person.name })
|
|
3291
|
+
n++
|
|
3292
|
+
}
|
|
3293
|
+
// One message per person and step, whatever the number of records.
|
|
3294
|
+
const owner = this.ownerName()
|
|
3295
|
+
const sends = []
|
|
3296
|
+
for (const { record: r, step } of heldNoticesDue(readHeld(map), now)) {
|
|
3297
|
+
const person = this.heldPersonOf(r)
|
|
3298
|
+
const to = step === 24 ? owner : person.name
|
|
3299
|
+
if (to) sends.push({ to, text: heldNoticeText(r, step, step === 24 ? { person: person.name === owner ? '' : person.name } : { self: person.name === r.by, owner: person.owner }), path: r.path })
|
|
3300
|
+
noteHeld(this.doc, map, r.id, step === 24 ? { flagged24: now } : { flagged4: now })
|
|
3301
|
+
}
|
|
3302
|
+
const byTo = new Map()
|
|
3303
|
+
for (const x of sends) byTo.set(x.to, [...(byTo.get(x.to) || []), x])
|
|
3304
|
+
for (const [to, xs] of byTo) {
|
|
3305
|
+
this.postChat({ by: RELAY_BY, to, kind: 'nudge', path: xs[0].path, text: xs.map((x) => x.text).join('\n') })
|
|
3306
|
+
n++
|
|
3307
|
+
}
|
|
3308
|
+
if (sends.length) this.log(`[${this.name}] ⚖️ told ${[...new Set(sends.map((x) => x.to))].join(', ')} of held conflicts left open`)
|
|
3309
|
+
}
|
|
3310
|
+
const due = map.size ? nextHeldDue(readHeld(map)) : null
|
|
3311
|
+
if ((this.meta.heldDue || null) !== due) {
|
|
3312
|
+
if (due) this.meta.heldDue = due
|
|
3313
|
+
else delete this.meta.heldDue
|
|
3314
|
+
this.saveMeta()
|
|
3315
|
+
}
|
|
3316
|
+
return n
|
|
3317
|
+
}
|
|
3318
|
+
|
|
3319
|
+
/** A box request (boxRequestOp). */
|
|
3320
|
+
boxRequest (who, req) { return this.boxRequestOp(who, req) }
|
|
3321
|
+
|
|
3322
|
+
/**
|
|
3323
|
+
* Handles a box request over MSG_CLAIM. `who` is { name } without sign-in, where boxes belong to a
|
|
3324
|
+
* verified name; with it, { name, id, owner }, where they belong to the account (id). Returns the
|
|
3325
|
+
* reply fields. Quilt holds no files (no-holds, 2026-11-13): the claim ops older apps still send
|
|
3326
|
+
* (claim, release, request, withdraw, handoff, touch, clear-inactive, quilt-claims) answer that
|
|
3327
|
+
* there is nothing to hold and change nothing; nobody is ever refused a file.
|
|
3328
|
+
*/
|
|
3329
|
+
boxRequestOp (who, req) {
|
|
3387
3330
|
const { name, id } = who
|
|
3388
|
-
//
|
|
3389
|
-
// name, as they did when made, and claiming one again adopts it under this account.
|
|
3390
|
-
// (The owner may release any of them too.)
|
|
3331
|
+
// Older boxes in a sign-in room have no account: they belong to their name, as they did when made.
|
|
3391
3332
|
const own = (c) => id ? (c.byId ? c.byId === id : c.by === name) : c.by === name
|
|
3392
|
-
// A person may also
|
|
3333
|
+
// A person may also unpack what their own AI sessions boxed (account~session).
|
|
3393
3334
|
const mine = (c) => own(c) || (!who.persona && !!id && !!c.byId && c.byId.startsWith(`${id}~`))
|
|
3394
|
-
const
|
|
3395
|
-
//
|
|
3335
|
+
const file = String(req.pattern ?? '').trim().replace(/^\.\//, '')
|
|
3336
|
+
// Boxes are per branch: one on src/a.js on main is not on src/a.js on feature-x.
|
|
3396
3337
|
const branch = this.resolveKey(who.branch || this.defaultKey)
|
|
3397
|
-
const at = (p) => this.
|
|
3338
|
+
const at = (p) => this.boxKey(branch, p)
|
|
3398
3339
|
const onBranch = branch === this.defaultKey ? {} : { branch }
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
const ids = new Set([].concat(req.ids || []).map(String))
|
|
3408
|
-
const keep = moved.filter((c) => !(ids.has(String(c.id)) && (minePlus(c) || who.owner)))
|
|
3409
|
-
if (keep.length !== moved.length) { this.meta.quilt.claims.moved = keep; this.saveMeta() }
|
|
3410
|
-
return { ok: true, forgot: moved.length - keep.length }
|
|
3411
|
-
}
|
|
3412
|
-
if (req.op === 'claim') {
|
|
3413
|
-
if (!pattern) throw new Error('pattern required')
|
|
3414
|
-
if (pattern.length > MAX_PATTERN) throw new Error('pattern too long')
|
|
3415
|
-
if (CONTROL_CHARS.test(pattern)) throw new Error('a pattern cannot contain control characters')
|
|
3416
|
-
const existing = this.meta.claims[at(pattern)]
|
|
3417
|
-
// A clash task's files (clash.js): claimed for its assignee while it merges, and taken over
|
|
3418
|
-
// from the one before when the task is handed on (only by whoever it is assigned to now).
|
|
3419
|
-
const clash = typeof req.clash === 'string' && /^[0-9a-f]{16}$/.test(req.clash) ? req.clash : null
|
|
3420
|
-
if (clash) {
|
|
3421
|
-
const t = this.tasks.get(clash)
|
|
3422
|
-
if (!t || t.column === 'done' || t.assignee !== name) throw new Error(`task ${clash} isn't yours to merge`)
|
|
3423
|
-
}
|
|
3340
|
+
// An older app boxes an edit with a claim marked as a box.
|
|
3341
|
+
const boxing = req.op === 'box' || (req.op === 'claim' && req.box === true)
|
|
3342
|
+
if (boxing) {
|
|
3343
|
+
if (!file) throw new Error('pattern required')
|
|
3344
|
+
if (file.length > MAX_PATTERN) throw new Error('pattern too long')
|
|
3345
|
+
if (CONTROL_CHARS.test(file)) throw new Error('a path cannot contain control characters')
|
|
3346
|
+
if (/[*?[]/.test(file)) return { ok: true, boxed: 0, note: NO_HOLDS } // a box is on one file, never a glob
|
|
3347
|
+
const existing = this.meta.boxes[at(file)]
|
|
3424
3348
|
// A box its cloud AI stopped with went to its person (handBackCloudBoxes): the AI, carrying on, takes it back.
|
|
3425
|
-
const takeOver = (c) =>
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
// A box (docs/superpowers/specs/2026-10-16-git-boxes-design.md): this claim's file is the holder's
|
|
3431
|
-
// unfinished work, kept out of everyone else's folder until it's committed or unpacked. Only on one
|
|
3432
|
-
// file (never a glob), and sticky: claiming one's own boxed file again keeps the box.
|
|
3433
|
-
const box = (req.box === true || !!(existing && (mine(existing) || (existing.handedFrom && takeOver(existing))) && existing.box)) && !/[*?[]/.test(pattern)
|
|
3434
|
-
this.meta.claims[at(pattern)] = { ...onBranch, by: name, ...(id ? { byId: id } : {}), pattern, note: who.talk === false ? '' : String(req.note ?? '').slice(0, 500), ts: Date.now(), ...(who.persona ? { of: who.of } : {}), ...(clash ? { clash } : {}), ...(existing?.queue ? { queue: existing.queue } : {}), ...(box ? { box: true } : {}) }
|
|
3435
|
-
return { ok: true }
|
|
3436
|
-
}
|
|
3437
|
-
if (req.op === 'release') {
|
|
3438
|
-
// A holder can't just let go of a file someone is waiting for: they hand it off, with
|
|
3439
|
-
// their context (op 'handoff'). Releasing everything lets go of the rest.
|
|
3440
|
-
const queued = (c) => c.queue && c.queue.length
|
|
3441
|
-
if (pattern === '*' || !pattern) {
|
|
3442
|
-
const held = Object.values(this.meta.claims).filter((c) => mine(c) && queued(c) && this.branchOf(c) === branch).map((c) => c.pattern)
|
|
3443
|
-
// Boxes stay: a box opens when it's committed or unpacked (op 'unbox'), not when its holder stops.
|
|
3444
|
-
return { ok: true, released: this.dropClaims((c) => mine(c) && !queued(c) && !c.box && this.branchOf(c) === branch), ...(held.length ? { held } : {}) }
|
|
3445
|
-
}
|
|
3446
|
-
const c = this.meta.claims[at(pattern)]
|
|
3447
|
-
if (!c) return this.releaseNotHere(who, pattern, branch, { mine, queued })
|
|
3448
|
-
// The owner may release anyone's claim. Someone under the same name may release one
|
|
3449
|
-
// held by an account that isn't here (theirs from before a re-invite), but not take it.
|
|
3450
|
-
// Either way, the first one waiting for it gets it.
|
|
3451
|
-
const stale = c.by === name && !this.holderPresent(c)
|
|
3452
|
-
if (!mine(c) && !who.owner && !stale) throw new Error(`${pattern} is claimed by ${c.by}; only they can release it (or the session owner)`)
|
|
3453
|
-
if (mine(c) && queued(c)) throw new Error(`${c.queue.map((r) => r.by).join(', ')} ${c.queue.length === 1 ? 'is' : 'are'} waiting for ${pattern} in its file queue: hand it off with your context instead of releasing it`)
|
|
3454
|
-
this.dropClaims((x) => x === c, () => mine(c) ? `${c.by} let go of it.` : `${name} (the session owner) released ${c.by}'s claim.`)
|
|
3455
|
-
return { ok: true, released: 1 }
|
|
3349
|
+
const takeOver = (c) => !!id && c.handedFrom === id
|
|
3350
|
+
// Someone else's unfinished work on the file stays theirs: this edit goes live (their folder merges it), never refused.
|
|
3351
|
+
if (existing && !mine(existing) && !takeOver(existing)) return { ok: true, boxed: 0 }
|
|
3352
|
+
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 }
|
|
3353
|
+
return { ok: true, boxed: 1 }
|
|
3456
3354
|
}
|
|
3457
3355
|
if (req.op === 'unbox') {
|
|
3458
|
-
// The
|
|
3459
|
-
//
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
if (req.
|
|
3465
|
-
|
|
3356
|
+
// The box opens: its work is in every folder now. Its holder (or their person, or the session
|
|
3357
|
+
// owner) unpacks it, or commits it; anyone who may change the file opens it by editing it
|
|
3358
|
+
// (`edit`), so their change merges with the work in it instead of waiting for it.
|
|
3359
|
+
const c = this.meta.boxes[at(file)]
|
|
3360
|
+
if (!c) return { ok: true, unboxed: 0 }
|
|
3361
|
+
const holder = mine(c) || (!who.persona && c.of === name) || !!who.owner
|
|
3362
|
+
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.`)
|
|
3363
|
+
delete this.meta.boxes[at(file)]
|
|
3364
|
+
this.forgetSeen()
|
|
3365
|
+
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.` })
|
|
3466
3366
|
return { ok: true, unboxed: 1 }
|
|
3467
3367
|
}
|
|
3468
|
-
if (req.op
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
if (CONTROL_CHARS.test(file)) throw new Error('a path cannot contain control characters')
|
|
3474
|
-
if (who.talk === false) throw new Error('you may not post in this session')
|
|
3475
|
-
const c = this.claimFor(file, branch)
|
|
3476
|
-
if (!c) throw new Error(`${file} is not claimed: claim it and go ahead`)
|
|
3477
|
-
if (mine(c)) throw new Error(`${file} is already yours`)
|
|
3478
|
-
const title = String(req.title ?? '').trim().slice(0, MAX_REQUEST_TITLE)
|
|
3479
|
-
if (!title) throw new Error('title required: what you want to do, in a few words')
|
|
3480
|
-
const description = String(req.description ?? '').trim().slice(0, MAX_REQUEST_TEXT)
|
|
3481
|
-
const task = req.task ? String(req.task).slice(0, 80) : undefined
|
|
3482
|
-
c.queue = c.queue || []
|
|
3483
|
-
// One request per person per claim: asking again updates it and keeps its place.
|
|
3484
|
-
const prev = c.queue.find((r) => id ? r.byId === id : r.by === name)
|
|
3485
|
-
if (!prev && c.queue.length >= MAX_QUEUE) throw new Error(`${c.queue.length} are already waiting for ${c.pattern}`)
|
|
3486
|
-
const r = prev || { id: crypto.randomBytes(6).toString('hex'), by: name, ...(id ? { byId: id } : {}), ...(who.persona ? { of: who.of } : {}), ts: Date.now() }
|
|
3487
|
-
Object.assign(r, { path: file, title, description, ...(task ? { task } : {}) })
|
|
3488
|
-
if (!prev) c.queue.push(r)
|
|
3489
|
-
this.postChat({ by: name, to: c.by, kind: 'queue', path: file, text: `📥 File queue · ${file}: ${`${title}${description ? ` — ${description}` : ''}`.replace(/[.!?]+$/, '')}. When you're done with it, hand it off to me with your context.` })
|
|
3490
|
-
return { ok: true, request: r.id, position: c.queue.indexOf(r) + 1, holder: c.by, pattern: c.pattern }
|
|
3491
|
-
}
|
|
3492
|
-
if (req.op === 'withdraw') {
|
|
3493
|
-
// The one who asked (or the owner) takes a request back.
|
|
3494
|
-
for (const c of Object.values(this.meta.claims)) {
|
|
3495
|
-
const r = (c.queue || []).find((x) => x.id === req.request)
|
|
3496
|
-
if (!r) continue
|
|
3497
|
-
if (!(id ? r.byId === id : r.by === name) && !who.owner) throw new Error('that request is not yours')
|
|
3498
|
-
c.queue = c.queue.filter((x) => x !== r)
|
|
3499
|
-
if (!c.queue.length) delete c.queue
|
|
3500
|
-
return { ok: true, withdrawn: 1 }
|
|
3501
|
-
}
|
|
3502
|
-
return { ok: true, withdrawn: 0 }
|
|
3503
|
-
}
|
|
3504
|
-
if (req.op === 'handoff') {
|
|
3505
|
-
// The holder passes a claim to someone waiting for it (the first, unless `to` names a
|
|
3506
|
-
// request id or a person), with what they know: what they changed, what's left, gotchas.
|
|
3507
|
-
const c = this.meta.claims[at(pattern)] || (pattern && this.claimFor(pattern, branch))
|
|
3508
|
-
if (!c) throw new Error(`${pattern || 'that'} is not claimed`)
|
|
3509
|
-
if (!mine(c) && !who.owner) throw new Error(`${c.pattern} is ${c.by}'s to hand off`)
|
|
3510
|
-
const queue = c.queue || []
|
|
3511
|
-
if (!queue.length) throw new Error(`nobody is waiting for ${c.pattern}: release it instead`)
|
|
3512
|
-
const to = req.to ? String(req.to) : ''
|
|
3513
|
-
const r = to ? queue.find((x) => x.id === to || x.by === to) : queue[0]
|
|
3514
|
-
if (!r) throw new Error(`${to} is not waiting for ${c.pattern}`)
|
|
3515
|
-
const context = String(req.context ?? '').trim().slice(0, MAX_HANDOFF_TEXT)
|
|
3516
|
-
if (!context && mine(c)) throw new Error('context required: what you changed, what is left and anything they should know')
|
|
3517
|
-
this.handOff(c, r, { context: context || `${name} (the session owner) handed it on.`, auto: !mine(c) })
|
|
3518
|
-
return { ok: true, to: r.by, pattern: c.pattern, waiting: queue.length - 1 }
|
|
3519
|
-
}
|
|
3520
|
-
if (req.op === 'clear-inactive') {
|
|
3521
|
-
// The owner clears every claim held by someone who isn't in the session now.
|
|
3522
|
-
if (!who.owner) throw new Error('only the session owner can clear claims')
|
|
3523
|
-
return { ok: true, released: this.dropClaims((c) => !this.holderPresent(c)) }
|
|
3524
|
-
}
|
|
3525
|
-
throw new Error('unknown claim operation')
|
|
3368
|
+
if (LEGACY_CLAIM_OPS.has(req.op)) {
|
|
3369
|
+
if (req.op === 'quilt-claims') return { ok: true, moved: [], owner: !!who.owner, note: NO_HOLDS }
|
|
3370
|
+
return { ok: true, released: 0, withdrawn: 0, note: NO_HOLDS }
|
|
3371
|
+
}
|
|
3372
|
+
throw new Error('unknown box operation')
|
|
3526
3373
|
}
|
|
3527
3374
|
|
|
3528
3375
|
saveMeta () {
|
|
@@ -3670,7 +3517,7 @@ class Room {
|
|
|
3670
3517
|
send(ws, jsonMessage(MSG_BRANCHES, { ...this.branchesFields() }))
|
|
3671
3518
|
const states = [...this.awareness.getStates().keys()]
|
|
3672
3519
|
if (states.length && !ws.roomless) send(ws, awarenessMessage(this.awareness, states))
|
|
3673
|
-
send(ws, jsonMessage(MSG_CLAIMS, { claims: this.
|
|
3520
|
+
send(ws, jsonMessage(MSG_CLAIMS, { claims: this.boxList(ws.branch) }))
|
|
3674
3521
|
this.touch()
|
|
3675
3522
|
}
|
|
3676
3523
|
|
|
@@ -3826,9 +3673,9 @@ class Room {
|
|
|
3826
3673
|
delete reply.listChanged
|
|
3827
3674
|
send(ws, jsonMessage(MSG_BRANCHES, { ...this.branchesFields(), reply }))
|
|
3828
3675
|
if (reply.ok && reply.op === 'join') {
|
|
3829
|
-
// What the relay has of the branch, and its
|
|
3676
|
+
// What the relay has of the branch, and its boxes: the app answers with what it has.
|
|
3830
3677
|
send(ws, syncStep1Message(this.store.get(ws.branch).doc, ws.branchAs))
|
|
3831
|
-
send(ws, jsonMessage(MSG_CLAIMS, { claims: this.
|
|
3678
|
+
send(ws, jsonMessage(MSG_CLAIMS, { claims: this.boxList(ws.branch) }))
|
|
3832
3679
|
}
|
|
3833
3680
|
if (listChanged) this.broadcastBranches()
|
|
3834
3681
|
} else if (type === MSG_AWARENESS) {
|
|
@@ -3842,17 +3689,19 @@ class Room {
|
|
|
3842
3689
|
let reply
|
|
3843
3690
|
try {
|
|
3844
3691
|
req = JSON.parse(decoding.readVarString(dec))
|
|
3845
|
-
const who = this.
|
|
3846
|
-
// No box on a file this member's change to would be undone (checkChange): nothing of theirs would be in it.
|
|
3847
|
-
if (req && req.op === 'claim' && req.box === true && !this.mayBox(ws, req.pattern)) req
|
|
3848
|
-
|
|
3849
|
-
|
|
3692
|
+
const who = this.boxOwner(ws, req.as)
|
|
3693
|
+
// No box on a file this member's change to would be undone (checkChange: permissions): nothing of theirs would be in it.
|
|
3694
|
+
if (req && (req.op === 'box' || (req.op === 'claim' && req.box === true)) && !this.mayBox(ws, req.pattern)) req = { ...req, op: 'claim', box: false }
|
|
3695
|
+
// Opening someone's box by editing the file needs the right to change it.
|
|
3696
|
+
if (req && req.op === 'unbox' && req.edit === true && !this.mayBox(ws, req.pattern)) req = { ...req, edit: false }
|
|
3697
|
+
reply = { id: req.id, ...this.boxRequest(who, req) }
|
|
3698
|
+
this.noteActivity(who.persona ? [who.id || `name:${who.name}`] : this.holderKeys(ws))
|
|
3850
3699
|
} catch (err) {
|
|
3851
|
-
return send(ws, jsonMessage(MSG_CLAIMS, { claims: this.
|
|
3700
|
+
return send(ws, jsonMessage(MSG_CLAIMS, { claims: this.boxList(ws.branch), reply: { id: req.id, ok: false, error: err.message } }))
|
|
3852
3701
|
}
|
|
3853
3702
|
this.saveMeta()
|
|
3854
3703
|
for (const other of this.conns.keys()) {
|
|
3855
|
-
const claims = this.
|
|
3704
|
+
const claims = this.boxList(other.branch)
|
|
3856
3705
|
send(other, jsonMessage(MSG_CLAIMS, other === ws ? { claims, reply } : { claims }))
|
|
3857
3706
|
}
|
|
3858
3707
|
} else if (type === MSG_ADMIN) {
|
|
@@ -3926,8 +3775,6 @@ const TALK_WHY = "you can't post in this session"
|
|
|
3926
3775
|
// What an app's activity entries look like (session.js recordActivity, relay-mcp.js quilt_write).
|
|
3927
3776
|
const ACTIVITY_FIELDS = ['by', 'path', 'kind', 'detail', 'ts', 'branch', 'from']
|
|
3928
3777
|
const ACTIVITY_KINDS = ['created', 'edited', 'deleted', 'switched']
|
|
3929
|
-
// Claim ops as the audit trail names them.
|
|
3930
|
-
const CLAIM_ACTIONS = { claim: 'claimed', release: 'released', request: 'requested', handoff: 'handed_off', withdraw: 'withdrew' }
|
|
3931
3778
|
const ACTIVITY_DETAIL = /^(\+\d+ -\d+|\d+ bytes)?$/
|
|
3932
3779
|
const nameTaken = (name) => `The name "${name}" belongs to someone else in this room; pick another name`
|
|
3933
3780
|
|
|
@@ -4062,6 +3909,7 @@ export function startServer ({ port = 4321, host = '0.0.0.0', dataDir = null, lo
|
|
|
4062
3909
|
presence.start()
|
|
4063
3910
|
}
|
|
4064
3911
|
const rooms = new Map() // loaded rooms only
|
|
3912
|
+
const heldWake = new Map() // room -> when a held conflict's next notice falls due, for rooms not loaded (wakeHeld)
|
|
4065
3913
|
const ipConns = new Map()
|
|
4066
3914
|
// New sessions are rate-limited per account when sign-in is on, otherwise per address.
|
|
4067
3915
|
const newRooms = new Map() // starter -> creation timestamps in the last hour
|
|
@@ -4129,6 +3977,8 @@ export function startServer ({ port = 4321, host = '0.0.0.0', dataDir = null, lo
|
|
|
4129
3977
|
room.unloadTimer = setTimeout(() => {
|
|
4130
3978
|
if (room.conns.size || rooms.get(name) !== room) return
|
|
4131
3979
|
collectStored(room)
|
|
3980
|
+
// A held conflict's next notice still falls due with nobody here (sweepHeld): the heartbeat loads it then.
|
|
3981
|
+
if (room.meta.heldDue) heldWake.set(name, room.meta.heldDue)
|
|
4132
3982
|
room.destroy()
|
|
4133
3983
|
rooms.delete(name)
|
|
4134
3984
|
if (!room.exists) unplaceIfNothing(name)
|
|
@@ -4985,10 +4835,34 @@ export function startServer ({ port = 4321, host = '0.0.0.0', dataDir = null, lo
|
|
|
4985
4835
|
ws.isAlive = false
|
|
4986
4836
|
ws.ping()
|
|
4987
4837
|
}
|
|
4988
|
-
for (const room of rooms.values())
|
|
4838
|
+
for (const room of rooms.values()) {
|
|
4839
|
+
if (room.ended) continue
|
|
4840
|
+
room.sweepBoxes(); room.pruneBranches()
|
|
4841
|
+
try { room.sweepHeld() } catch (err) { log(`[${room.name}] held conflicts: ${err.message}`) }
|
|
4842
|
+
heldWake.delete(room.name)
|
|
4843
|
+
}
|
|
4844
|
+
wakeHeld()
|
|
4989
4845
|
if (sweepHosted) sweepHosted()
|
|
4990
4846
|
}, 30000)
|
|
4991
4847
|
|
|
4848
|
+
// Sessions nobody has open whose held conflict's next notice is due (meta.heldDue): each is loaded, told
|
|
4849
|
+
// (sweepHeld) and let go again, a few per beat, so a conflict left open is escalated with every app closed.
|
|
4850
|
+
function wakeHeld (now = Date.now()) {
|
|
4851
|
+
let n = 0
|
|
4852
|
+
for (const [name, due] of heldWake) {
|
|
4853
|
+
if (n >= 5) break
|
|
4854
|
+
if (due > now) continue
|
|
4855
|
+
heldWake.delete(name)
|
|
4856
|
+
if (rooms.has(name) || roomEnded(name) || !dataDir || !fs.existsSync(path.join(dataDir, `${name}.ydoc`))) continue
|
|
4857
|
+
const room = getRoom(name)
|
|
4858
|
+
if (!room) continue
|
|
4859
|
+
n++
|
|
4860
|
+
if (!room.exists) { dropIfUnused(room); continue }
|
|
4861
|
+
try { room.sweepHeld(now) } catch (err) { log(`[${name}] held conflicts: ${err.message}`) }
|
|
4862
|
+
if (!room.conns.size && room.onEmpty) room.onEmpty()
|
|
4863
|
+
}
|
|
4864
|
+
}
|
|
4865
|
+
|
|
4992
4866
|
// Delete rooms nobody has opened for a while (hosted relays shouldn't grow forever).
|
|
4993
4867
|
const sweep = () => {
|
|
4994
4868
|
if (!dataDir || !cfg.roomTtlDays) return
|
|
@@ -5007,8 +4881,11 @@ export function startServer ({ port = 4321, host = '0.0.0.0', dataDir = null, lo
|
|
|
5007
4881
|
log(`[${name}] could not read its metadata (${err.message}); leaving it alone`)
|
|
5008
4882
|
continue
|
|
5009
4883
|
}
|
|
4884
|
+
// A held conflict's notice to come (sweepHeld): the heartbeat loads the session when it falls due.
|
|
4885
|
+
if (typeof meta.heldDue === 'number' && !meta.ended) heldWake.set(name, meta.heldDue)
|
|
5010
4886
|
if ((meta.lastActive || meta.createdAt || 0) > cutoff) continue
|
|
5011
4887
|
if (cluster && cluster.moving.has(name)) continue
|
|
4888
|
+
heldWake.delete(name)
|
|
5012
4889
|
removeRoomData(name)
|
|
5013
4890
|
if (cluster) cluster.forgetPlacement(name)
|
|
5014
4891
|
removed++
|
|
@@ -5040,6 +4917,7 @@ export function startServer ({ port = 4321, host = '0.0.0.0', dataDir = null, lo
|
|
|
5040
4917
|
hosted, // exposed for tests
|
|
5041
4918
|
leases, // the live-sync leases (exposed for tests)
|
|
5042
4919
|
sweepHosted: () => sweepHosted && sweepHosted(), // exposed for tests: ends quiet hosted agents' visits now
|
|
4920
|
+
wakeHeld: (now) => wakeHeld(now), // exposed for tests: escalates held conflicts in sessions nobody has open
|
|
5043
4921
|
features, // exposed for tests
|
|
5044
4922
|
sweep,
|
|
5045
4923
|
cluster, // exposed for tests
|