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.
Files changed (62) hide show
  1. package/RELEASES.md +30 -0
  2. package/bin/quilt.js +16 -9
  3. package/package.json +2 -2
  4. package/src/agent-task-workflow.js +2 -9
  5. package/src/base-pick.js +212 -0
  6. package/src/boxes.js +6 -7
  7. package/src/catchup.js +1 -1
  8. package/src/chat-links.js +1 -3
  9. package/src/connection.js +24 -5
  10. package/src/control.js +27 -20
  11. package/src/duties.js +32 -56
  12. package/src/github-commit.js +1 -1
  13. package/src/held.js +323 -0
  14. package/src/hooks.js +27 -66
  15. package/src/identity.js +1 -1
  16. package/src/inbox.js +5 -4
  17. package/src/key-cli.js +1 -1
  18. package/src/live-merge.js +599 -0
  19. package/src/mcp.js +57 -102
  20. package/src/merge3.js +65 -1
  21. package/src/now-summary.js +4 -6
  22. package/src/pathrules.js +1 -1
  23. package/src/persona.js +1 -1
  24. package/src/presence.js +2 -0
  25. package/src/protocol.js +2 -2
  26. package/src/read-bases.js +123 -0
  27. package/src/relay-ask.js +2 -2
  28. package/src/relay-live-write.js +179 -0
  29. package/src/relay-mcp.js +173 -212
  30. package/src/relay-prune.js +2 -2
  31. package/src/relay-turn-sync.js +146 -142
  32. package/src/runner.js +0 -2
  33. package/src/server.js +253 -375
  34. package/src/session-follow.js +3 -1
  35. package/src/session-quilt.js +2 -21
  36. package/src/session-seam.js +35 -7
  37. package/src/session.js +795 -553
  38. package/src/setup.js +15 -25
  39. package/src/source-live/bring-in.js +5 -5
  40. package/src/source-live/land.js +20 -3
  41. package/src/source-live/live-block.js +503 -52
  42. package/src/status.js +8 -12
  43. package/src/swap-in.js +81 -0
  44. package/src/textdiff.js +54 -0
  45. package/src/turn-sync-plan.js +6 -18
  46. package/src/turn-sync.js +28 -21
  47. package/src/ui/agent-guide.js +13 -13
  48. package/src/ui/app.css +19 -40
  49. package/src/ui/boxes.js +8 -16
  50. package/src/ui/common.js +1 -1
  51. package/src/ui/fileview.js +11 -15
  52. package/src/ui/loom-model.js +18 -16
  53. package/src/ui/loom.css +1 -2
  54. package/src/ui/loom.js +6 -6
  55. package/src/ui/rail-model.js +25 -64
  56. package/src/ui/rail.js +48 -60
  57. package/src/ui/seam-model.js +39 -3
  58. package/src/ui/session.js +36 -54
  59. package/src/ui/tree.js +22 -129
  60. package/src/ui-server.js +2 -6
  61. package/src/release-words.js +0 -18
  62. package/src/seam-claims.js +0 -53
@@ -10,11 +10,11 @@ export const INACTIVE_MS = 7 * 24 * 60 * 60 * 1000
10
10
  export const ARCHIVE_KEEP_MS = 30 * 24 * 60 * 60 * 1000
11
11
  const TRUNKS = new Set(['main', 'master'])
12
12
 
13
- /** Who is on which branch now: connected folders, claims, and hosted agents' choices of a branch worked on this week (chosenBranches). */
13
+ /** Who is on which branch now: connected folders, boxes (unfinished work), and hosted agents' choices of a branch worked on this week (chosenBranches). */
14
14
  function inUse (room, now = Date.now()) {
15
15
  const on = chosenBranches(room, now)
16
16
  for (const ws of room.conns.keys()) if (ws.branch) on.add(ws.branch)
17
- for (const c of Object.values(room.meta.claims || {})) on.add(room.branchOf(c))
17
+ for (const c of Object.values(room.meta.boxes || {})) on.add(room.branchOf(c))
18
18
  return on
19
19
  }
20
20
 
@@ -9,23 +9,28 @@
9
9
  // again against the session as it is now), pull (the session's version of some paths), done (the
10
10
  // folder's manifest after writing; the checkpoint saved).
11
11
  //
12
- // Nobody is asked to merge (docs/superpowers/specs/2026-10-18-automatic-merges.md): when the
13
- // folder and the session both changed a file, Quilt combines them here (combine), writes the result
14
- // to the session and sends it back to the folder, and tells whoever's lines lost: the agent in the
15
- // sync's answer (`lost`), a person in a direct message from the relay. A file someone else holds
16
- // is never written under them: the folder keeps its version, a 'claimed' record keeps a copy, and
17
- // it goes in, combined the same way, at the agent's first sync after they let go (settleWaiting).
12
+ // A sync's push is a live write like any other (Seam's 07 "Conflicts in the live state", ruling
13
+ // 2026-11-13): merged against the version the folder last synced (its checkpoint) by the same engine
14
+ // as every live path (live-merge.js LiveRules). Lines only one side changed all go in; where both
15
+ // changed the same lines the session keeps what landed first and the folder's lines are held for its
16
+ // writer (or any AI) to resolve (held.js, quilt_resolve_merge): the agent hears in the sync's answer
17
+ // (`held`), and its copy is kept aside in the folder. The newer edit no longer wins. The stale-write,
18
+ // removed-name and parse rules run on it too. Nobody holds files (no-holds, 2026-11-13): a folder's
19
+ // change to someone else's boxed file opens the box (ctx.openBox) and is merged the same way. Versions
20
+ // an older relay held for someone ('claimed' records) go in at the agent's next sync (settleWaiting).
18
21
  import fs from 'node:fs'
19
22
  import path from 'node:path'
20
23
  import zlib from 'node:zlib'
21
24
  import crypto from 'node:crypto'
22
25
  import * as Y from 'yjs'
23
- import { applyTextDiff } from './textdiff.js'
26
+ import { applyLineDiff } from './textdiff.js'
24
27
  import { isSafeRelPath, LARGE_FILE_BYTES } from './pathrules.js'
25
28
  import { openMerge, updateMerge, readMerges, cleanName, MAX_RECORD_TEXT } from './merges.js'
26
29
  import { unionMatcher } from './merge3.js'
27
- import { RELAY_NAME as RELAY_BY, isRelay } from './ui/chat.js'
28
- import { decide, planSync, nextCheckpoint, mergeTexts, behind, sessionEntry, SKIP } from './turn-sync-plan.js'
30
+ import { isRelay } from './ui/chat.js'
31
+ import { decide, planSync, nextCheckpoint, behind, sessionEntry, SKIP } from './turn-sync-plan.js'
32
+ import { LiveRules } from './live-merge.js'
33
+ import { staleWriteMinutes } from './held.js'
29
34
 
30
35
  export const SLOT = /^[A-Za-z0-9_-]{8,64}$/
31
36
  const HASH = /^[0-9a-f]{40}$/
@@ -124,34 +129,63 @@ export function cleanManifest (files) {
124
129
  return out
125
130
  }
126
131
 
127
- /** A file's content sent in a push: { buf, text, hash } or { gone: true }; null when malformed or too big. */
132
+ /**
133
+ * A file's content sent in a push: { buf, text, hash } or { gone: true }; null when malformed or too
134
+ * big. (A CLI also sends each file's mtime: older relays let the newer edit win; this one merges.)
135
+ */
128
136
  function content (v) {
129
137
  if (!v || typeof v !== 'object') return null
130
- // When the folder last changed the file (ms), if the CLI sent it: who edited last decides the lines both changed.
131
- const mtime = Number.isFinite(v.mtime) && v.mtime > 0 ? v.mtime : null
132
- if (v.deleted === true) return { gone: true, mtime }
138
+ if (v.deleted === true) return { gone: true }
133
139
  if (typeof v.text === 'string') {
134
140
  const buf = Buffer.from(v.text, 'utf8')
135
141
  if (buf.length > MAX_SYNC_TEXT) return null
136
- return { text: v.text, buf, hash: sha1(buf), mtime }
142
+ return { text: v.text, buf, hash: sha1(buf) }
137
143
  }
138
144
  if (typeof v.base64 === 'string') {
139
145
  const buf = Buffer.from(v.base64, 'base64')
140
146
  if (buf.length >= LARGE_FILE_BYTES) return null
141
- return { buf, hash: sha1(buf), mtime }
147
+ return { buf, hash: sha1(buf) }
142
148
  }
143
149
  return null
144
150
  }
145
151
 
152
+ /**
153
+ * The live-write engine for this sync: ctx.rules, else one on the room (held conflicts in its
154
+ * document, the owner's stale_write_minutes). What the agent must hear comes back in the answer.
155
+ */
156
+ function rulesOf (ctx) {
157
+ if (ctx.rules) return ctx.rules
158
+ const doc = ctx.room && ctx.room.doc
159
+ if (!doc) return null
160
+ ctx.rules = new LiveRules({
161
+ room: () => doc,
162
+ staleMinutes: () => staleWriteMinutes(doc, typeof ctx.room.memberList === 'function' ? ctx.room.memberList() : []),
163
+ texts: () => textsOf(ctx),
164
+ origin: ctx.origin
165
+ })
166
+ return ctx.rules
167
+ }
168
+
169
+ /** The session's text files on this branch, as [path, text] (the removed-name search). */
170
+ function * textsOf (ctx) {
171
+ for (const [rel, t] of ctx.files) if (t && isSafeRelPath(rel)) yield [rel, t.toString()]
172
+ }
173
+
174
+ /** Where a held conflict from this sync was held: the branch, for a room with branch documents. */
175
+ const whereOf = (ctx) => (ctx.branchKey && ctx.branchKey !== ROOM_KEY ? { branch: ctx.branchKey } : {})
176
+
177
+ /** A held record as the sync's answer carries it. */
178
+ const heldOut = (r) => ({ path: r.path, id: r.id, kind: r.kind, others: r.others, hunks: r.hunks.length + (r.more || 0), ...(r.lines.length ? { lines: r.lines.length } : {}) })
179
+
146
180
  /**
147
181
  * One step of a sync. `args`: { step, slot, files?, paths? }. `ctx`: { room, fdoc, files, blobs,
148
182
  * branchKey, epoch, account, me, origin, globalRefusal(), pathRefusal(rel) -> { kind: 'aside' |
149
- * 'claimed' | 'keep', why, by? } | null, record({ rel, kind, before, after, detail }), lastEditor(rel), ghosts? }.
150
- * Optional: editedAt(rel) (the session's last edit to rel, ms; else read from the room's activity) and
151
- * tell(to, text, rel) (a direct message from the relay; else room.postChat).
183
+ * 'keep', why } | null (access only: a viewer, outside its folders), record({ rel, kind, before, after, detail }),
184
+ * lastEditor(rel), ghosts?, openBox(rel)?, rules? }.
185
+ * `rules`: the live-write engine (live-merge.js LiveRules); else one on ctx.room's document.
152
186
  * `ghosts`: the paths someone else has boxed (docs/superpowers/specs/2026-10-16-git-boxes-design.md): their
153
187
  * unfinished work never reaches this folder. The folder sees each as it last had it (its checkpoint), or as it
154
- * has it now; an edit to one is refused like one to a held file, and the folder's version comes back.
188
+ * has it now. An edit to one is never refused: `openBox(rel)` opens the box, and the edit merges with the work in it.
155
189
  * Returns the answer (a plain object, sent as JSON).
156
190
  */
157
191
  export function turnSyncStep (args, ctx) {
@@ -181,27 +215,33 @@ export function turnSyncStep (args, ctx) {
181
215
 
182
216
  if (step === 'plan') {
183
217
  const local = cleanManifest(args.files)
184
- // What waited for someone to let go goes in first, so the plan already sees it.
218
+ // What an older relay kept waiting for a holder goes in first, so the plan already sees it.
185
219
  const settled = settleWaiting(ctx, ghosts)
186
220
  const p = planSync({ local, session: session(local), checkpoint, deleted })
187
221
  const refused = p.upload.length || p.delete.length ? ctx.globalRefusal() : null
188
- return { step, ...p, ...(settled.merged.length ? { settled: settled.merged } : {}), ...(settled.lost.length ? { lost: settled.lost } : {}), ...(refused ? { refused } : {}) }
222
+ return { step, ...p, ...(settled.merged.length ? { settled: settled.merged } : {}), ...(settled.lost.length ? { lost: settled.lost } : {}), ...(settled.held.length ? { held: settled.held } : {}), ...(settled.warnings.length ? { warnings: settled.warnings } : {}), ...(refused ? { refused } : {}) }
189
223
  }
190
224
 
191
225
  if (step === 'push') {
192
- // `merges` stays (always empty) for CLIs from before automatic merges.
193
- const out = { step, pushed: [], deleted: [], merged: [], merges: [], lost: [], waiting: [], pull: [], remove: [], aside: [], kept: [], skipped: [] }
226
+ // `merges` and `waiting` stay (always empty) for CLIs from before automatic merges and no-holds.
227
+ const out = { step, pushed: [], deleted: [], merged: [], merges: [], lost: [], waiting: [], held: [], warnings: [], pull: [], remove: [], aside: [], kept: [], skipped: [] }
194
228
  const refusedAll = ctx.globalRefusal()
195
229
  const first = !checkpoint
196
230
  const base = (checkpoint && checkpoint.files) || {}
197
- // Each path is only changed once, after it was looked at: one look at the session is enough.
198
- const state = session()
231
+ // Each path is only changed once, after it was looked at: one look at the session is enough
232
+ // (again only when a box this folder changed opens).
233
+ let state = session()
199
234
  for (const [rel, v] of Object.entries(args.files || {})) {
200
235
  if (!isSafeRelPath(rel)) continue
201
236
  const c = content(v)
202
237
  if (!c) { out.skipped.push(rel); continue }
203
- // Someone else's box this folder never synced: left as it is here, and not taken into the session.
204
- if (ghosts.has(rel) && !cpFiles[rel]) { const why = ctx.pathRefusal(rel); out.kept.push({ path: rel, why: why ? why.why : `${rel} is someone else's unfinished work` }); continue }
238
+ // Someone else's box this folder changed: it opens, so this change merges with the work in it (never refused).
239
+ if (ghosts.has(rel) && (c.gone || !cpFiles[rel] || c.hash !== cpFiles[rel].h)) {
240
+ if (!ctx.openBox) { out.kept.push({ path: rel, why: `${rel} is someone else's unfinished work` }); continue }
241
+ ctx.openBox(rel)
242
+ ghosts.delete(rel)
243
+ state = session()
244
+ }
205
245
  const now = state.get(rel) || null
206
246
  const d = decide({ local: c.gone ? null : c.hash, session: now, base: base[rel] || null, first, deleted: deleted(rel) })
207
247
  if (d === 'same') continue
@@ -212,11 +252,12 @@ export function turnSyncStep (args, ctx) {
212
252
  if (refusedAll) { out.kept.push({ path: rel, why: refusedAll }); continue }
213
253
  const why = ctx.pathRefusal(rel)
214
254
  if (why && why.kind === 'keep') { out.kept.push({ path: rel, why: why.why }); continue }
215
- if (why) { settle(rel, c, now, base[rel] || null, why, ctx, out); continue }
255
+ if (why) { setAside(rel, now, why, out); continue }
216
256
  // The folder's version is in: an older copy that waited for a holder to let go is no longer needed.
217
257
  closeWaiting(rel, ctx, 'Superseded by a newer version from the same folder')
218
258
  if (d === 'merge') combine(rel, c, now, base[rel] || null, ctx, out)
219
- else if (d === 'push') { write(rel, c, ctx); out.pushed.push(rel) } else if (d === 'delete') { remove(rel, ctx); out.deleted.push(rel) }
259
+ else if (d === 'push') push(rel, c, now, base[rel] || null, ctx, out)
260
+ else if (d === 'delete') { remove(rel, ctx); out.deleted.push(rel) }
220
261
  }
221
262
  return out
222
263
  }
@@ -267,7 +308,7 @@ function write (rel, c, ctx, note = '') {
267
308
  ctx.blobs.delete(rel)
268
309
  let t = ctx.files.get(rel)
269
310
  if (!t) { t = new Y.Text(); if (g && typeof g.text === 'string') t.insert(0, g.text); ctx.files.set(rel, t) }
270
- const detail = applyTextDiff(t, c.text)
311
+ const detail = applyLineDiff(t, c.text)
271
312
  ctx.record({ rel, kind: existed ? 'edited' : 'created', before, after: c.text, detail: note ? [detail, note].filter(Boolean).join(', ') : detail })
272
313
  } else {
273
314
  ctx.files.delete(rel)
@@ -298,31 +339,6 @@ function editorOf (rel, ctx) {
298
339
  return by && by !== ctx.me && !isRelay(by) ? cleanName(by) : null
299
340
  }
300
341
 
301
- /** When the session last changed rel (ms): ctx.editedAt, else the room's activity on this branch; 0 when unknown. */
302
- function sessionEditedAt (rel, ctx) {
303
- if (ctx.editedAt) return ctx.editedAt(rel) || 0
304
- const doc = ctx.room && ctx.room.doc
305
- if (!doc || typeof doc.getArray !== 'function') return 0
306
- const a = doc.getArray('activity')
307
- for (let i = a.length - 1; i >= 0; i--) {
308
- const e = a.get(i)
309
- if (e && e.path === rel && typeof e.ts === 'number' && (!e.branch || ctx.branchKey === ROOM_KEY || e.branch === ctx.branchKey)) return e.ts
310
- }
311
- return 0
312
- }
313
-
314
- /**
315
- * Whether the folder's version is the newer edit (it wins the lines both changed, or the whole of a
316
- * binary). The relay can't see when the agent edited: `quilt sync` sends each file's mtime
317
- * (turn-sync.js), and when it arrives (c.mtime; for a version that waited for a holder, the time it
318
- * was pushed) the session's last edit to the file, from its activity, after it makes the session's
319
- * the newer. Without it the folder's version is the newer: it was written during the turn this sync
320
- * ends. The checkpoint's time can't stand in: every file both changed has a session edit after it.
321
- */
322
- function folderNewer (rel, c, ctx) {
323
- return !c.mtime || c.mtime >= sessionEditedAt(rel, ctx)
324
- }
325
-
326
342
  /** The merge=union matcher from the session's .gitattributes files. */
327
343
  function unionOf (ctx) {
328
344
  const texts = []
@@ -332,15 +348,6 @@ function unionOf (ctx) {
332
348
  return unionMatcher(texts)
333
349
  }
334
350
 
335
- /** A direct message from the relay to `to` (a notice: nothing waits on it). */
336
- function tell (ctx, to, rel, text) {
337
- if (!to || to === ctx.me || isRelay(to)) return
338
- try {
339
- if (ctx.tell) ctx.tell(to, text, rel)
340
- else if (ctx.room && typeof ctx.room.postChat === 'function') ctx.room.postChat({ by: RELAY_BY, to, text, kind: 'nudge', path: rel })
341
- } catch {}
342
- }
343
-
344
351
  /** Marks a record done by Quilt, if it is still open. */
345
352
  function finish (ctx, id, how, reason) {
346
353
  const map = ctx.fdoc.getMap('merges')
@@ -350,9 +357,9 @@ function finish (ctx, id, how, reason) {
350
357
  }
351
358
 
352
359
  /**
353
- * The log of an automatic merge in which something lost: a record already done (the spec's "merge
354
- * records stay as a log"), with the folder's version in it. `id`: the record to close instead (a
355
- * version that waited for a holder).
360
+ * The log of an automatic merge in which something was held or kept: a record already done (the
361
+ * spec's "merge records stay as a log"), with the folder's version in it. `id`: the record to close
362
+ * instead (a version that waited for a holder).
356
363
  */
357
364
  function logMerge (rel, ctx, { c, base, now, by, how, reason, id = null }) {
358
365
  if (!id) {
@@ -378,18 +385,48 @@ function logMerge (rel, ctx, { c, base, now, by, how, reason, id = null }) {
378
385
  }
379
386
 
380
387
  /**
381
- * The folder and the session both changed rel, and it is the agent's to change: combined at once.
382
- * An edit beats a deletion; a binary (or a text too long for its base to be kept) is the newer
383
- * version whole; a text is mergeAuto's (lines one side changed kept, the newer edit where both
384
- * changed the same lines). The result goes to the session and back to the folder (`pull`). The
385
- * folder's lines that lost are in `out.lost` for the agent (its copy kept aside in the folder); the
386
- * session's go to whoever last edited it there, in a direct message.
388
+ * Only the folder changed rel since its checkpoint: its version goes in, as a live write (the
389
+ * stale-write rule still keeps lines someone else added minutes ago, held for this agent to confirm).
390
+ */
391
+ function push (rel, c, now, base, ctx, out) {
392
+ const rules = typeof c.text === 'string' ? rulesOf(ctx) : null
393
+ if (!rules) { write(rel, c, ctx); out.pushed.push(rel); return }
394
+ const by = editorOf(rel, ctx)
395
+ // A new file: nothing to merge, but its lines are on record as this agent's (the next writer's stale check).
396
+ if (!now || typeof now.text !== 'string') {
397
+ if (!now) rules.write({ doc: ctx.fdoc, where: whereOf(ctx), path: rel, ours: c.text, by: ctx.me })
398
+ write(rel, c, ctx)
399
+ out.pushed.push(rel)
400
+ return
401
+ }
402
+ const r = rules.write({ doc: ctx.fdoc, where: whereOf(ctx), path: rel, base: base && typeof base.t === 'string' ? base.t : now.text, ours: c.text, theirs: now.text, by: ctx.me, byId: ctx.account, others: by ? [by] : [], union: unionOf(ctx)(rel) })
403
+ if (r.text !== now.text) write(rel, { text: r.text }, ctx)
404
+ out.pushed.push(rel)
405
+ took(rel, c, r, out)
406
+ }
407
+
408
+ /** What a live write's result means for the folder: the session's text back when it differs, held lines told, its copy kept aside. */
409
+ function took (rel, c, r, out) {
410
+ if (r.text !== c.text) out.pull.push(rel)
411
+ out.warnings.push(...r.warnings)
412
+ if (!r.held.length) return
413
+ if (!out.aside.includes(rel)) out.aside.push(rel)
414
+ out.held.push(...r.held.map(heldOut))
415
+ }
416
+
417
+ /**
418
+ * The folder and the session both changed rel, and it is the agent's to change: merged at once, as
419
+ * a live write against the folder's checkpoint (live-merge.js). An edit beats a deletion. Lines only
420
+ * one side changed all go in; where both changed the same lines the session keeps what landed first
421
+ * and the folder's lines are held (held.js) for this agent, or any AI, to resolve with
422
+ * quilt_resolve_merge; a binary both changed (or a text too long for its base to be kept) keeps the
423
+ * session's version whole, with the folder's held. The result goes to the session and back to the
424
+ * folder (`pull`), the folder's copy kept aside in it; `held` in the answer says what was held.
387
425
  */
388
426
  function combine (rel, c, now, base, ctx, out, { id = null, after = '' } = {}) {
389
427
  const by = editorOf(rel, ctx) // before our write makes us the last editor
390
428
  const who = by || 'the session'
391
429
  const me = ctx.me
392
- const oursNewer = folderNewer(rel, c, ctx)
393
430
  const tail = after ? ` ${after}` : ''
394
431
  if (c.gone) {
395
432
  // Deleted here, changed there: it stays (a deletion is cheap to redo; lost work is not).
@@ -405,77 +442,41 @@ function combine (rel, c, now, base, ctx, out, { id = null, after = '' } = {}) {
405
442
  return
406
443
  }
407
444
  const theirs = typeof now.text === 'string' ? now.text : null
408
- if (typeof c.text !== 'string' || theirs === null || (base && typeof base.t !== 'string')) {
409
- // Lines can't be told apart: the newer version wins whole.
410
- if (oursNewer) {
411
- write(rel, c, ctx, `newer than ${who}'s`)
412
- out.merged.push(rel)
413
- tell(ctx, by, rel, `Quilt merged ${rel}: you and ${me} both changed it, and ${me}'s newer version replaced yours. Yours is in the file's history (Changes).`)
414
- } else {
415
- out.aside.push(rel)
416
- out.pull.push(rel)
417
- out.lost.push({ path: rel, by: who, whole: true })
445
+ const rules = rulesOf(ctx)
446
+ if (typeof c.text !== 'string' || theirs === null || (base && typeof base.t !== 'string') || !rules) {
447
+ // Lines can't be told apart: the session's version, which landed first, stays whole and the folder's is held.
448
+ const binary = typeof c.text !== 'string' || theirs === null
449
+ if (rules) {
450
+ try {
451
+ const rec = rules.hold({ path: rel, kind: binary ? 'binary' : 'lines', by: me, byId: ctx.account, others: by ? [by] : [], where: whereOf(ctx), hunks: binary ? [] : [{ at: 0, base: [], ours: c.text.split('\n'), theirs: theirs.split('\n') }], reason: `${who} changed it first${tail}, and the two versions have nothing in common to merge`, result: binary ? null : theirs, mine: binary ? null : c.text })
452
+ out.held.push(heldOut(rec))
453
+ } catch {}
418
454
  }
419
- logMerge(rel, ctx, { c, base, now, by, id, how: oursNewer ? 'mine' : 'theirs', reason: `Both changed it${tail}: the newer version (${oursNewer ? me : who}'s) stays` })
455
+ out.aside.push(rel)
456
+ out.pull.push(rel)
457
+ logMerge(rel, ctx, { c, base, now, by, id, how: 'theirs', reason: `Both changed it${tail}: ${who}'s version, which landed first, stays; ${me}'s is held` })
420
458
  return
421
459
  }
422
- const r = mergeTexts(base ? base.t : null, c.text, theirs, { oursNewer, union: unionOf(ctx)(rel) })
460
+ // Both made it (no checkpoint of it): the base is ''.
461
+ const r = rules.write({ doc: ctx.fdoc, where: whereOf(ctx), path: rel, base: base ? base.t : '', ours: c.text, theirs, by: me, byId: ctx.account, others: by ? [by] : [], union: unionOf(ctx)(rel) })
423
462
  if (r.text !== theirs) write(rel, { text: r.text }, ctx, `merged with ${who}'s changes`)
424
463
  out.merged.push(rel)
425
- if (r.text !== c.text) out.pull.push(rel)
426
- if (!r.lost.length) return
427
- const lines = r.lost.flatMap((l) => l.lines)
428
- logMerge(rel, ctx, { c, base, now, by, id, how: oursNewer ? 'mine' : 'theirs', reason: `Merged by Quilt${tail}: where both changed the same lines, the newer edit (${oursNewer ? me : who}'s) stays` })
429
- if (oursNewer) {
430
- const shown = lines.slice(0, 12)
431
- tell(ctx, by, rel, `Quilt merged ${rel} with ${me}'s changes: where you both changed the same lines, ${me}'s newer edit stays. Your lines it replaced are in the file's history (Changes)${shown.length ? `:\n${shown.map((l) => `- ${l}`).join('\n')}` : '.'}`)
432
- } else {
433
- // The folder's version is kept aside in the folder before the merged one replaces it.
434
- out.aside.push(rel)
435
- out.lost.push({ path: rel, by: who, lines: lines.slice(0, 50) })
436
- }
464
+ took(rel, c, r, out)
465
+ if (r.held.length) logMerge(rel, ctx, { c, base, now, by, id, how: 'theirs', reason: `Merged by Quilt${tail}: where both changed the same lines, ${who}'s version, which landed first, stays; ${me}'s lines are held` })
466
+ else if (id) finish(ctx, id, 'mine', `Merged by Quilt${tail}`)
437
467
  }
438
468
 
439
469
  /**
440
- * Something stands in the way of rel. Not the agent's to change at all (a viewer, outside its
441
- * folders): the session's version comes back, which is access, not a merge. Held by someone else
442
- * (a claim or a box): never written under them. The folder keeps its version (the checkpoint keeps
443
- * the old base, so the next sync still sees it as changed) and a 'claimed' record keeps a copy for a
444
- * sandbox that is wiped; it goes in, combined, at the agent's first sync after they let go.
470
+ * Not the agent's to change at all (a viewer, outside its folders): the session's version comes
471
+ * back, which is access, not a merge. Nothing else keeps a write out: nobody holds files.
445
472
  */
446
- function settle (rel, c, now, base, why, ctx, out) {
447
- if (why.kind === 'aside') {
448
- out.aside.push(rel)
449
- out[now ? 'pull' : 'remove'].push(rel)
450
- out.kept.push({ path: rel, why: why.why })
451
- return
452
- }
453
- const binary = typeof c.text !== 'string' && !c.gone
454
- // The same version already waiting (synced again while still held): one record is enough.
455
- const same = !binary && readMerges(ctx.fdoc.getMap('merges')).find((m) => m.kind === 'claimed' && m.state === 'open' && m.path === rel && m.by === ctx.me && (!m.byId || m.byId === ctx.account) && !m.binary && (c.gone ? m.oursDeleted : m.ours !== null && m.ours === c.text))
456
- if (same) { out.waiting.push({ path: rel, by: why.by || null, id: same.id }); return }
457
- closeWaiting(rel, ctx, 'Superseded by a newer version from the same folder')
458
- const theirsKey = theirsKeyOf(now)
459
- let id = null
460
- try {
461
- id = openMerge(ctx.fdoc, ctx.fdoc.getMap('merges'), {
462
- path: rel,
463
- by: ctx.me,
464
- byId: ctx.account,
465
- others: why.by && why.by !== ctx.me ? [cleanName(why.by)] : [],
466
- kind: 'claimed',
467
- ours: binary || c.gone ? null : textOf(c.text),
468
- oursDeleted: !!c.gone,
469
- base: binary ? null : textOf(base && base.t),
470
- theirsHash: theirsKey === null ? null : sha1(theirsKey),
471
- binary,
472
- claimedBy: why.by ? cleanName(why.by) : null
473
- }, ctx.origin).id
474
- } catch {}
475
- out.waiting.push({ path: rel, by: why.by || null, ...(id ? { id } : {}) })
473
+ function setAside (rel, now, why, out) {
474
+ out.aside.push(rel)
475
+ out[now ? 'pull' : 'remove'].push(rel)
476
+ out.kept.push({ path: rel, why: why.why })
476
477
  }
477
478
 
478
- /** This agent's versions of rel still waiting for a holder: done, with `reason`. */
479
+ /** This agent's versions of rel an older relay kept waiting for a holder ('claimed' records, read only): done, with `reason`. */
479
480
  function closeWaiting (rel, ctx, reason) {
480
481
  for (const m of readMerges(ctx.fdoc.getMap('merges'))) {
481
482
  if (m.kind === 'claimed' && m.state === 'open' && m.path === rel && m.by === ctx.me && (!m.byId || m.byId === ctx.account)) finish(ctx, m.id, 'mine', reason)
@@ -483,27 +484,28 @@ function closeWaiting (rel, ctx, reason) {
483
484
  }
484
485
 
485
486
  /**
486
- * Versions of this agent's that waited for a holder (settle): each one whose file is free now goes
487
- * in, combined with the session's as `combine` does. A binary, or a text too long for the record,
488
- * is only in the folder: it goes in with the folder's next push. Returns { merged, lost }.
487
+ * Versions of this agent's an older relay kept waiting for a holder ('claimed' records; nothing
488
+ * writes them now): each goes in, merged with the session's as `combine` does. A binary, or a text
489
+ * too long for the record, is only in the folder: it goes in with the folder's next push.
490
+ * Returns { merged, lost, held, warnings }.
489
491
  */
490
492
  function settleWaiting (ctx, ghosts) {
491
- const res = { merged: [], lost: [] }
493
+ const res = { merged: [], lost: [], held: [], warnings: [] }
492
494
  const mine = readMerges(ctx.fdoc.getMap('merges')).filter((m) => m.kind === 'claimed' && m.state === 'open' && m.by === ctx.me && (!m.byId || m.byId === ctx.account))
493
495
  if (!mine.length || ctx.globalRefusal()) return res
494
496
  for (const rec of mine) {
495
497
  const rel = rec.path
496
- if (ghosts.has(rel) || ctx.pathRefusal(rel)) continue // still held, or no longer ours to change
498
+ if (ghosts.has(rel) || ctx.pathRefusal(rel)) continue // someone's box, or no longer ours to change
497
499
  if (rec.binary || (rec.ours === null && !rec.oursDeleted)) continue
498
500
  const now = sessionState(ctx.files, ctx.blobs, ctx.git).get(rel) || null
499
501
  const holder = rec.claimedBy || rec.others[0] || 'someone'
500
- const after = `once ${holder} let go of it`
502
+ const after = `(held for ${holder} before Quilt stopped holding files)`
501
503
  const buf = rec.oursDeleted ? null : Buffer.from(rec.ours, 'utf8')
502
- const c = rec.oursDeleted ? { gone: true, mtime: rec.ts } : { text: rec.ours, buf, hash: sha1(buf), mtime: rec.ts }
504
+ const c = rec.oursDeleted ? { gone: true } : { text: rec.ours, buf, hash: sha1(buf) }
503
505
  if ((!now && c.gone) || (now && now.h === c.hash)) { finish(ctx, rec.id, 'mine', `Already in ${after}`); continue }
504
506
  // The session still has the base ours started from: only we changed it, ours goes in as it is.
505
507
  const onlyOurs = now && typeof now.text === 'string' && rec.base !== null && now.text === rec.base
506
- const out = { merged: [], pull: [], aside: [], lost: [] }
508
+ const out = { merged: [], pull: [], aside: [], lost: [], held: [], warnings: [] }
507
509
  if (onlyOurs) {
508
510
  if (c.gone) remove(rel, ctx); else write(rel, c, ctx, after)
509
511
  out.merged.push(rel)
@@ -514,6 +516,8 @@ function settleWaiting (ctx, ghosts) {
514
516
  finish(ctx, rec.id, 'mine', `Went in ${after}`)
515
517
  res.merged.push(...out.merged)
516
518
  res.lost.push(...out.lost)
519
+ res.held.push(...out.held)
520
+ res.warnings.push(...out.warnings)
517
521
  }
518
522
  return res
519
523
  }
package/src/runner.js CHANGED
@@ -15,7 +15,6 @@ import { writePrivateJson } from './private-file.js'
15
15
  import { listProcesses } from './procs.js'
16
16
  import { JOIN_HOST, INVALID_INVITE, buildInvite, parseInvite } from './ui/invite.js'
17
17
  import { installHooks, HOOKS_FILE } from './setup.js'
18
- import { releaseLeftoverHookClaims } from './hooks.js'
19
18
  import { registerOnStart } from './integrations.js'
20
19
  import { autowork } from './autowork.js'
21
20
  import { keptInProject } from './agent-join.js'
@@ -199,7 +198,6 @@ export async function runSession ({ dir, conn, name, tool, color = null, shareBy
199
198
  // Claude Code also applies Quilt's rules by itself through hooks (src/hooks.js), in this person's own
200
199
  // settings file; everyone's session writes its own, so the rule holds for everyone in the room.
201
200
  try { if (installHooks(dir, { stop: kind === 'agent' })) session.log(`🪝 added Quilt's Claude Code hooks to ${HOOKS_FILE}: files are checked before Claude edits them`) } catch {}
202
- releaseLeftoverHookClaims(session).then((n) => { if (n) session.log(`🔓 released ${n} claim(s) left by an earlier AI session`) }).catch(() => {})
203
201
 
204
202
  // Share this person's AI chat (Claude Code, Cursor) with the room.
205
203
  const readers = agentFeed