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/relay-prune.js
CHANGED
|
@@ -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,
|
|
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.
|
|
17
|
+
for (const c of Object.values(room.meta.boxes || {})) on.add(room.branchOf(c))
|
|
18
18
|
return on
|
|
19
19
|
}
|
|
20
20
|
|
package/src/relay-turn-sync.js
CHANGED
|
@@ -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
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
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 {
|
|
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 {
|
|
28
|
-
import { decide, planSync, nextCheckpoint,
|
|
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
|
-
/**
|
|
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
|
-
|
|
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)
|
|
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)
|
|
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
|
-
* '
|
|
150
|
-
*
|
|
151
|
-
*
|
|
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
|
|
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
|
|
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`
|
|
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
|
-
|
|
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
|
|
204
|
-
if (ghosts.has(rel) && !cpFiles[rel]
|
|
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) {
|
|
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')
|
|
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 =
|
|
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
|
|
354
|
-
* records stay as a log"), with the folder's version in it. `id`: the record to close
|
|
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
|
-
*
|
|
382
|
-
*
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
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
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
426
|
-
if (
|
|
427
|
-
|
|
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
|
-
*
|
|
441
|
-
*
|
|
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
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
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
|
|
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
|
|
487
|
-
* in,
|
|
488
|
-
* is only in the folder: it goes in with the folder's next push.
|
|
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 //
|
|
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 = `
|
|
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
|
|
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
|