heyquilt 0.3.170 → 0.3.171

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 (61) hide show
  1. package/RELEASES.md +22 -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 +91 -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 +592 -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 +173 -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 +650 -554
  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 +391 -51
  42. package/src/status.js +8 -12
  43. package/src/textdiff.js +54 -0
  44. package/src/turn-sync-plan.js +6 -18
  45. package/src/turn-sync.js +28 -21
  46. package/src/ui/agent-guide.js +13 -13
  47. package/src/ui/app.css +19 -40
  48. package/src/ui/boxes.js +8 -16
  49. package/src/ui/common.js +1 -1
  50. package/src/ui/fileview.js +11 -15
  51. package/src/ui/loom-model.js +18 -16
  52. package/src/ui/loom.css +1 -2
  53. package/src/ui/loom.js +6 -6
  54. package/src/ui/rail-model.js +25 -64
  55. package/src/ui/rail.js +48 -60
  56. package/src/ui/seam-model.js +39 -3
  57. package/src/ui/session.js +36 -54
  58. package/src/ui/tree.js +22 -129
  59. package/src/ui-server.js +2 -6
  60. package/src/release-words.js +0 -18
  61. package/src/seam-claims.js +0 -53
package/src/held.js ADDED
@@ -0,0 +1,323 @@
1
+ // Held conflicts (Seam's plans/quilt-source-control/07 "Conflicts in the live state", ruling
2
+ // 2026-11-13): a live write whose lines clashed with what had landed first. The shared file keeps
3
+ // the first-landed version; the writer's clashing lines are kept here, in the room's document, so
4
+ // every member's app and every AI (local MCP, hosted MCP, quilt_status) sees each open one until
5
+ // someone resolves it. Nothing holds the file meanwhile. One map for the whole session, whatever
6
+ // branch or square the file is on, because the room's document is the one every member has
7
+ // (a branch document is read-only once the session is in Seam, and a square's live document only
8
+ // reaches the members on that square).
9
+ import crypto from 'node:crypto'
10
+ import { isSafeRelPath } from './pathrules.js'
11
+
12
+ export const HELD_MAP = 'held'
13
+ export const KINDS = ['lines', 'stale', 'parse', 'binary']
14
+ export const HOWS = ['theirs', 'mine', 'edited']
15
+ export const MAX_TEXT = 64 * 1024 // each of a record's texts; past it the texts stay on the writer's machine (`local`)
16
+ export const MAX_HUNKS = 20
17
+ export const MAX_HUNK_LINES = 40
18
+ export const MAX_HELD = 60
19
+ export const DONE_TTL_MS = 24 * 60 * 60 * 1000
20
+ // Seam's 07 setting `stale_write_minutes`: a write that removes lines someone else added this recently is held, not taken.
21
+ export const STALE_WRITE_MINUTES = 15
22
+ export const SETTINGS_MAP = 'mergeSettings'
23
+ // Seam's 07 "Who is asked to resolve, and the escalation budget" (ruling 2026-10-30): an open record
24
+ // nobody resolved in ESCALATE_MS tells its writer's person (an agent's: the person it works for); at
25
+ // ADMIN_MS the session's owner is told too. Each once per record (`flagged4`, `flagged24`). The relay
26
+ // does it (server.js sweepHeld), so it happens whatever AI tool wrote it and with nobody's app open.
27
+ export const ESCALATE_MS = 4 * 60 * 60 * 1000
28
+ export const ADMIN_MS = 24 * 60 * 60 * 1000
29
+ // The two-attempt budget: an attempt is a resolution ("mine" or "edited") whose resolver's next write on
30
+ // that path, within ATTEMPT_WINDOW_MS, is held again. The record that would need a third becomes a task
31
+ // on the board for the writer's person, and every AI is told to leave it to them.
32
+ export const ATTEMPT_BUDGET = 2
33
+ export const ATTEMPT_WINDOW_MS = 2 * 60 * 60 * 1000
34
+
35
+ const HEX_ID = /^[0-9a-f]{16}$/
36
+ // eslint-disable-next-line no-control-regex
37
+ const CONTROL = /[\u0000-\u001f\u007f]+/g
38
+ const stamp = (v) => (typeof v === 'number' && Number.isFinite(v) && v > 0 ? v : null)
39
+ const flat = (s, max) => String(s == null ? '' : s).replace(CONTROL, ' ').replace(/\s+/g, ' ').trim().slice(0, max)
40
+ const capLines = (ls) => (Array.isArray(ls) ? ls : []).slice(0, MAX_HUNK_LINES).map((l) => String(l).slice(0, 500))
41
+
42
+ /** A record as readers show it, or null for anything a modified client pushed that is not this shape. */
43
+ export function publicHeld (v) {
44
+ if (!v || typeof v !== 'object' || typeof v.id !== 'string' || !HEX_ID.test(v.id)) return null
45
+ if (typeof v.path !== 'string' || v.path.length > 1024 || !isSafeRelPath(v.path)) return null
46
+ if (!KINDS.includes(v.kind) || (v.state !== 'open' && v.state !== 'resolved')) return null
47
+ if (typeof v.by !== 'string' || !v.by || typeof v.ts !== 'number') return null
48
+ if (v.how != null && !HOWS.includes(v.how)) return null
49
+ return {
50
+ id: v.id,
51
+ path: v.path,
52
+ kind: v.kind,
53
+ state: v.state,
54
+ by: flat(v.by, 80),
55
+ byId: typeof v.byId === 'string' ? v.byId.slice(0, 128) : null,
56
+ others: Array.isArray(v.others) ? v.others.filter((n) => typeof n === 'string').slice(0, 10).map((n) => flat(n, 80)) : [],
57
+ where: v.where && typeof v.where === 'object' ? { ...(typeof v.where.branch === 'string' ? { branch: v.where.branch.slice(0, 200) } : {}), ...(typeof v.where.square === 'string' ? { square: v.where.square.slice(0, 64) } : {}) } : {},
58
+ ts: v.ts,
59
+ hunks: Array.isArray(v.hunks) ? v.hunks.slice(0, MAX_HUNKS).map((h) => ({ at: Number(h && h.at) || 0, base: capLines(h && h.base), ours: capLines(h && h.ours), theirs: capLines(h && h.theirs) })) : [],
60
+ more: Number(v.more) || 0,
61
+ lines: Array.isArray(v.lines) ? v.lines.filter((l) => typeof l === 'string').slice(0, 50) : [],
62
+ reason: flat(v.reason, 500),
63
+ result: typeof v.result === 'string' ? v.result : null,
64
+ mine: typeof v.mine === 'string' ? v.mine : null,
65
+ local: !!v.local,
66
+ how: v.how ?? null,
67
+ resolvedBy: v.resolvedBy ? flat(v.resolvedBy, 80) : null,
68
+ resolvedTs: typeof v.resolvedTs === 'number' ? v.resolvedTs : null,
69
+ attempts: Number.isInteger(v.attempts) && v.attempts > 0 ? Math.min(v.attempts, 99) : 0,
70
+ prev: typeof v.prev === 'string' && HEX_ID.test(v.prev) ? v.prev : null,
71
+ flagged4: stamp(v.flagged4),
72
+ flagged24: stamp(v.flagged24),
73
+ task: typeof v.task === 'string' && HEX_ID.test(v.task) ? v.task : null,
74
+ taskFor: v.taskFor ? flat(v.taskFor, 80) : null
75
+ }
76
+ }
77
+
78
+ // The relay's escalation notes on records (noteHeld), kept apart from the records themselves.
79
+ export const NOTES_MAP = 'heldNotes'
80
+ const NOTE_KEYS = ['flagged4', 'flagged24', 'task', 'taskFor']
81
+ const notesOf = (map) => (map && map.doc ? map.doc.getMap(NOTES_MAP) : null)
82
+ const withNote = (v, note) => {
83
+ if (!v || typeof v !== 'object' || !note || typeof note !== 'object') return v
84
+ const out = { ...v }
85
+ for (const k of NOTE_KEYS) if (note[k] != null) out[k] = note[k]
86
+ return out
87
+ }
88
+
89
+ /** Every valid record, open ones first, oldest first. */
90
+ export function readHeld (map) {
91
+ const out = []
92
+ if (!map) return out
93
+ const notes = notesOf(map)
94
+ map.forEach((v, key) => { const r = publicHeld(withNote(v, notes && notes.get(key))); if (r && r.id === key) out.push(r) })
95
+ return out.sort((a, b) => (a.state === b.state ? 0 : a.state === 'open' ? -1 : 1) || a.ts - b.ts)
96
+ }
97
+
98
+ export const openHeld = (map) => readHeld(map).filter((r) => r.state === 'open')
99
+
100
+ /**
101
+ * The resolution a new clash of `by`'s on `path` follows, making it a further attempt: the newest record
102
+ * on that path `by` resolved "mine" or "edited" within ATTEMPT_WINDOW_MS. Null when there is none.
103
+ */
104
+ export function priorAttempt (list, { path, by, now = Date.now() }) {
105
+ const tried = (list || []).filter((r) => r.state === 'resolved' && r.path === path && r.resolvedBy === by && (r.how === 'mine' || r.how === 'edited') && now - (r.resolvedTs || 0) <= ATTEMPT_WINDOW_MS)
106
+ return tried.sort((a, b) => (b.resolvedTs || 0) - (a.resolvedTs || 0) || b.attempts - a.attempts || b.ts - a.ts)[0] || null
107
+ }
108
+
109
+ /** Whether a record is past the two-attempt budget: its writer's AI stops, and it is a task for their person. */
110
+ export const overBudget = (r) => !!r && (r.attempts || 0) >= ATTEMPT_BUDGET
111
+
112
+ /**
113
+ * Keeps a writer's clashing lines aside. `result`: what the shared file got; `mine`: what the writer
114
+ * wanted (resolving "mine" writes it, merged with whatever changed since). Texts past MAX_TEXT are
115
+ * left out of the shared record (`local`): only the writer's machine has them (in .quilt/held/<id>/).
116
+ * A clash that follows the writer's own resolution on the path (priorAttempt) counts one more attempt.
117
+ */
118
+ export function addHeld (doc, map, { path, kind, by, byId = null, others = [], where = {}, hunks = [], lines = [], reason = '', result = null, mine = null, now = Date.now() }, origin) {
119
+ if (!KINDS.includes(kind)) throw new Error('bad held kind')
120
+ const fits = (t) => t == null || t.length <= MAX_TEXT
121
+ const local = !fits(result) || !fits(mine)
122
+ const prior = priorAttempt(readHeld(map), { path, by, now })
123
+ const rec = {
124
+ id: crypto.randomBytes(8).toString('hex'),
125
+ path, kind, state: 'open', by, byId, others: others.filter((n) => n && n !== by).slice(0, 10), where, ts: now,
126
+ hunks: hunks.slice(0, MAX_HUNKS).map((h) => ({ at: h.at, base: capLines(h.base), ours: capLines(h.ours), theirs: capLines(h.theirs) })),
127
+ more: Math.max(0, hunks.length - MAX_HUNKS),
128
+ lines: lines.slice(0, 50).map((l) => String(l).slice(0, 500)),
129
+ reason: flat(reason, 500),
130
+ result: local ? null : result, mine: local ? null : mine, local,
131
+ how: null, resolvedBy: null, resolvedTs: null,
132
+ attempts: prior ? prior.attempts + 1 : 0,
133
+ prev: prior ? prior.id : null
134
+ }
135
+ const out = publicHeld(rec)
136
+ if (!out) throw new Error('bad held record')
137
+ doc.transact(() => {
138
+ pruneIn(map)
139
+ map.set(rec.id, rec)
140
+ }, origin)
141
+ return out
142
+ }
143
+
144
+ /** The record `ref` names: its id, or the oldest open one for that path (else the newest resolved one), or null. */
145
+ export function findHeld (map, ref) { return findHeldIn(readHeld(map), ref) }
146
+
147
+ /** findHeld over a list already read (status's, an answer's). */
148
+ export function findHeldIn (all, ref) {
149
+ const key = String(ref || '').trim().replace(/^\.\//, '')
150
+ if (!key) return null
151
+ const byId = all.find((r) => r.id === key)
152
+ if (byId) return byId
153
+ return all.find((r) => r.path === key && r.state === 'open') || all.filter((r) => r.path === key).sort((a, b) => (b.resolvedTs || 0) - (a.resolvedTs || 0))[0] || null
154
+ }
155
+
156
+ /** Marks a record resolved. { record, already }: `already` when it was resolved before (nothing changes then). */
157
+ export function settleHeld (doc, map, id, { how, by }, origin) {
158
+ if (!HOWS.includes(how)) throw new Error(`how is one of ${HOWS.join(', ')}`)
159
+ const cur = publicHeld(map.get(id))
160
+ if (!cur) throw new Error('no such held conflict')
161
+ if (cur.state === 'resolved') return { record: cur, already: true }
162
+ const next = { ...map.get(id), state: 'resolved', how, resolvedBy: by, resolvedTs: Date.now() }
163
+ doc.transact(() => map.set(id, next), origin)
164
+ return { record: publicHeld(next), already: false }
165
+ }
166
+
167
+ /**
168
+ * Notes the relay's escalation on a record: `flagged4` / `flagged24` (when each notice went), `task` and
169
+ * `taskFor` (the board task it became). They go in their own map (NOTES_MAP), never over the record, so
170
+ * a resolution that crosses the relay's note on the wire is never lost to it.
171
+ */
172
+ export function noteHeld (doc, map, id, { flagged4, flagged24, task, taskFor }, origin) {
173
+ const notes = notesOf(map)
174
+ if (!notes || !publicHeld(map.get(id))) return null
175
+ const next = { ...(notes.get(id) || {}) }
176
+ if (stamp(flagged4)) next.flagged4 = flagged4
177
+ if (stamp(flagged24)) next.flagged24 = flagged24
178
+ if (typeof task === 'string' && HEX_ID.test(task)) next.task = task
179
+ if (taskFor) next.taskFor = flat(taskFor, 80)
180
+ doc.transact(() => notes.set(id, next), origin)
181
+ return publicHeld(withNote(map.get(id), next))
182
+ }
183
+
184
+ /**
185
+ * The escalation notices due at `now`: [{ record, step }], step 4 (tell the writer's person) or 24 (tell
186
+ * the session's owner too), each once per open record.
187
+ */
188
+ export function heldNoticesDue (list, now = Date.now()) {
189
+ const out = []
190
+ for (const r of list || []) {
191
+ if (r.state !== 'open') continue
192
+ if (!r.flagged4 && now - r.ts >= ESCALATE_MS) out.push({ record: r, step: 4 })
193
+ if (!r.flagged24 && now - r.ts >= ADMIN_MS) out.push({ record: r, step: 24 })
194
+ }
195
+ return out
196
+ }
197
+
198
+ /** The open records past the attempt budget that are not a task yet. */
199
+ export const heldTasksDue = (list) => (list || []).filter((r) => r.state === 'open' && overBudget(r) && !r.task)
200
+
201
+ /** When the next escalation notice falls due (for a session nobody has open), or null with none to come. */
202
+ export function nextHeldDue (list) {
203
+ let next = null
204
+ for (const r of list || []) {
205
+ if (r.state !== 'open') continue
206
+ const at = !r.flagged4 ? r.ts + ESCALATE_MS : !r.flagged24 ? r.ts + ADMIN_MS : null
207
+ if (at !== null && (next === null || at < next)) next = at
208
+ }
209
+ return next
210
+ }
211
+
212
+ /** The board task's title for a record past the budget. */
213
+ export const heldTaskTitle = (r) => `Resolve \`${r.path}\``
214
+
215
+ /**
216
+ * What a notice says. `step` 4: to the writer's person (`self`: the writer is them; `owner`: an agent with
217
+ * no person, so the session's owner); 24: to the session's owner, `person` having been told at 4 hours.
218
+ */
219
+ export function heldNoticeText (r, step, { person = '', self = false, owner = false } = {}) {
220
+ const whose = self ? 'your' : `${r.by}'s`
221
+ const what = `${whose} ${r.kind === 'stale' ? 'removal of lines from' : 'changes to'} \`${r.path}\` (id ${r.id}) ${r.kind === 'stale' ? 'is' : 'are'} held back, because ${WHAT[r.kind](r)}`
222
+ const how = 'Resolve it with quilt_resolve_merge { path or id, how: "theirs" (drop the held lines), "mine" (put them in) or "edited" (you fixed the file yourself) }, or ask your AI to.'
223
+ if (step === 24) return `⚖️ A conflict has been open a day: ${what}. ${person ? `${person} was told at 4 hours. ` : ''}Anyone in the session may resolve it. ${how}`
224
+ return `⚖️ A conflict has been open 4 hours: ${what}. ${self ? '' : owner ? `${r.by} is an agent with no person of its own here, so it comes to you as the session's owner. ` : `${r.by} works for you, so it comes to you. `}${how}`
225
+ }
226
+
227
+ /** Drops resolved records older than a day and, past MAX_HELD, the oldest resolved ones. Open ones always stay. */
228
+ function pruneIn (map, now = Date.now()) {
229
+ const all = []
230
+ const junk = []
231
+ map.forEach((v, key) => { const r = publicHeld(v); if (!r || r.id !== key) junk.push(key); else all.push(r) })
232
+ for (const key of junk) map.delete(key)
233
+ const notes = notesOf(map)
234
+ if (notes) for (const key of [...notes.keys()]) if (!map.has(key) || junk.includes(key)) notes.delete(key)
235
+ const done = all.filter((r) => r.state === 'resolved').sort((a, b) => (a.resolvedTs || 0) - (b.resolvedTs || 0))
236
+ let count = all.length
237
+ for (const r of done) {
238
+ if ((r.resolvedTs && now - r.resolvedTs > DONE_TTL_MS) || count >= MAX_HELD) { map.delete(r.id); if (notes) notes.delete(r.id); count-- }
239
+ }
240
+ }
241
+
242
+ /**
243
+ * The paths with an open held conflict on square `square` (Seam's 07 "Terms held aside": a path with a
244
+ * held term counts as conflicted, so it cannot land until it is resolved). `square` may be a prefix of
245
+ * the id, or the id of a record's prefix. Records held on a branch document are not a square's.
246
+ */
247
+ export function heldPathsOn (list, square) {
248
+ const sq = String(square || '').replace(/^sq:/, '')
249
+ if (!sq) return []
250
+ const on = (r) => r && r.state === 'open' && r.where && !r.where.branch && typeof r.where.square === 'string' && r.where.square && (r.where.square.startsWith(sq) || sq.startsWith(r.where.square))
251
+ return [...new Set((list || []).filter(on).map((r) => r.path))]
252
+ }
253
+
254
+ /** Why a commit or merge leaves `paths` out (an open held conflict on each); `none`: nothing else was there to land. */
255
+ export function heldLandingNote (paths, { none = false } = {}) {
256
+ const one = paths.length === 1
257
+ const named = paths.slice(0, 5).map((p) => `\`${p}\``).join(', ') + (paths.length > 5 ? ` and ${paths.length - 5} more` : '')
258
+ return `${named} ${one ? 'has an open held conflict' : 'have open held conflicts'} (two writes changed the same lines and the second writer's are held), so ${one ? 'it does' : 'they do'} not land until resolved: ${none ? 'nothing else was there to commit' : 'everything else landed'}. ` +
259
+ `Resolve ${one ? 'it' : 'each'} with quilt_resolve_merge { path, how: "theirs" (drop the held lines), "mine" (put them in) or "edited" (you fixed the file yourself) }, then commit again.`
260
+ }
261
+
262
+ /** The session's `stale_write_minutes`: the owner's setting (as voice's transcripts are), else 15. */
263
+ export function staleWriteMinutes (doc, members = []) {
264
+ const v = doc && doc.getMap(SETTINGS_MAP).get('staleWriteMinutes')
265
+ const owner = (members || []).find((m) => m && m.role === 'owner')
266
+ if (!v || typeof v !== 'object' || !owner || v.by !== owner.name) return STALE_WRITE_MINUTES
267
+ const n = Number(v.minutes)
268
+ return Number.isFinite(n) && n >= 0 && n <= 24 * 60 ? n : STALE_WRITE_MINUTES
269
+ }
270
+
271
+ /** The owner sets `stale_write_minutes` for everyone in the session (0 turns the check off). */
272
+ export function setStaleWriteMinutes (doc, { minutes, by, now = Date.now() }) {
273
+ const n = Number(minutes)
274
+ if (!Number.isFinite(n) || n < 0 || n > 24 * 60) throw new Error('stale_write_minutes is a number of minutes from 0 to 1440')
275
+ doc.getMap(SETTINGS_MAP).set('staleWriteMinutes', { minutes: Math.round(n), by, ts: now })
276
+ return Math.round(n)
277
+ }
278
+
279
+ const ago = (ts, now = Date.now()) => {
280
+ const s = Math.max(0, Math.round((now - ts) / 1000))
281
+ if (s < 60) return `${s}s ago`
282
+ if (s < 3600) return `${Math.round(s / 60)}m ago`
283
+ return `${Math.round(s / 3600)}h ago`
284
+ }
285
+
286
+ const WHAT = {
287
+ lines: (r) => `${r.others.length ? `${r.others.join(', ')} had changed` : 'someone had changed'} the same lines first`,
288
+ stale: () => 'the write removed lines someone else added minutes before',
289
+ parse: () => 'the merged file would not parse',
290
+ binary: (r) => `${r.others.length ? r.others.join(', ') : 'someone'} changed it first`
291
+ }
292
+
293
+ /** One line per open conflict, for the top of every tool answer and quilt_status. '' when there are none. */
294
+ export function renderHeld (list, { me = '', max = 5 } = {}) {
295
+ const open = (list || []).filter((r) => r.state === 'open')
296
+ if (!open.length) return ''
297
+ const shown = open.slice(0, max).map((r) => {
298
+ if (overBudget(r)) return `- \`${r.path}\` (id ${r.id}, ${ago(r.ts)}): held again after ${r.attempts} resolutions, so it is a task for ${r.taskFor || `${r.by}'s person`} on the board${r.task ? ` (${heldTaskTitle(r)})` : ''}. AIs: stop working on this conflict and leave it to ${r.taskFor || 'them'}.`
299
+ const n = r.hunks.length + (r.more || 0)
300
+ const first = r.hunks[0]
301
+ const where = first ? ` at line ${first.at + 1}` : ''
302
+ const whose = r.by === me ? 'your' : `${r.by}'s`
303
+ const ask = r.by === me ? 'you are asked first' : `${r.by} is asked first; any AI may take it`
304
+ return `- \`${r.path}\` (id ${r.id}, ${ago(r.ts)}): ${whose} ${r.kind === 'binary' ? 'version' : `${n} change${n === 1 ? '' : 's'}${where}`} held back, because ${WHAT[r.kind](r)}. The file keeps the version that landed first; ${ask}.`
305
+ })
306
+ const more = open.length > max ? `\n- and ${open.length - max} more (quilt_status lists them)` : ''
307
+ return `⚖️ Open conflicts in this session (${open.length}). Resolve each with quilt_resolve_merge { path or id, how: "theirs" (drop the held lines), "mine" (put them over the shared ones) or "edited" (you wrote the resolved file yourself) }:\n${shown.join('\n')}${more}`
308
+ }
309
+
310
+ /** A record in full for an AI deciding how to resolve it: each hunk's three sides. */
311
+ export function describeHeld (r) {
312
+ const side = (label, ls) => ` ${label}:\n${ls.length ? ls.map((l) => ` ${l}`).join('\n') : ' (nothing)'}`
313
+ const hunks = r.hunks.map((h, i) => `Hunk ${i + 1}, at line ${h.at + 1}:\n${side('base', h.base)}\n${side('kept (landed first)', h.theirs)}\n${side(`held (${r.by}'s)`, h.ours)}`)
314
+ const stop = overBudget(r) ? [`It was held again after ${r.attempts} resolutions, so it is a task for ${r.taskFor || `${r.by}'s person`} on the board: AIs stop working on it and leave it to them.`] : []
315
+ return [`\`${r.path}\` (id ${r.id}): ${r.reason || WHAT[r.kind](r)}.`, ...stop, ...hunks, ...(r.more ? [`… and ${r.more} more hunk(s).`] : [])].join('\n')
316
+ }
317
+
318
+ /** quilt_resolve_merge's description, the same for the local and the hosted MCP. */
319
+ export const RESOLVE_DESCRIPTION = 'Resolve a held conflict. When two writes change the same lines, the file keeps the version that landed first and the second writer\'s lines are held (also: a write that removed lines someone else just added, or a merge that would not parse). ' +
320
+ 'Every open one is listed at the top of every Quilt answer until it is resolved; its writer is asked first, but any AI in the session may take it, and nothing holds the file meanwhile. ' +
321
+ 'Give the path or id, and how: "theirs" drops the held lines (the file stays as it is), "mine" puts them over the shared ones (merged with whatever changed since), "edited" says you already wrote the resolved file (read it, combine both sides by hand, then resolve "edited"). ' +
322
+ 'Without how, it shows the conflict in full: each hunk\'s base, the kept lines and the held ones. Resolving one already resolved is harmless and says so. ' +
323
+ 'If your writes to a path are held again twice after you resolved them, the third becomes a task on the board for your person: stop working on that conflict and leave it to them. One left open 4 hours is sent to its writer\'s person, and at 24 hours to the session\'s owner.'
package/src/hooks.js CHANGED
@@ -1,14 +1,12 @@
1
1
  // `quilt hook`: the AI tools' own delivery of Quilt's rules. The rules themselves are
2
2
  // the same for every agent (duties.js, Session.prepareEdit): every MCP agent gets
3
- // them through quilt_before_edit, its quilt answers and quilt_set_work, and the
4
- // file watcher undoes edits to files someone else holds whatever made them. The
3
+ // them through quilt_before_edit, its quilt answers and quilt_set_work. The
5
4
  // hooks make them automatic in every tool that runs hooks: Claude Code and Cursor
6
5
  // (which reads the project's Claude Code hooks) from .claude/settings.local.json,
7
6
  // Gemini CLI from its user settings (integrations.js). Each speaks its own dialect
8
- // (DIALECTS below); what happens is the same. Before every edit, the file is
9
- // claimed for this person (or the edit is refused when someone else holds it, with
10
- // a nudge to ask them for help) and what was said about it in chat is shown; claims the hooks
11
- // made are released when Claude finishes, once it has answered who wrote to it.
7
+ // (DIALECTS below); what happens is the same. Before every edit, what was said about
8
+ // the file in chat and who else changed it lately are shown. A hook never refuses an
9
+ // edit: Quilt holds no files (no-holds, 2026-11-13), and edits merge as they arrive.
12
10
  // Direct messages, mentions and tasks handed over are shown as Claude works, and when
13
11
  // this person lets their AI pick up work by itself, it is handed its next task as it finishes.
14
12
  //
@@ -21,7 +19,7 @@ import { execFileSync } from 'node:child_process'
21
19
  import { findDaemon } from './control.js'
22
20
  import { migrateDir } from './legacy.js'
23
21
  import { eventLines, REFERS_HOW } from './inbox.js'
24
- import { renderQueued, renderChatAbout, heldRefusal, PERSON_CHAT } from './duties.js'
22
+ import { renderChatAbout, renderRecent, PERSON_CHAT } from './duties.js'
25
23
  import { renderNextTask } from './tasks.js'
26
24
  import { quiltShellCommand } from './integrations.js'
27
25
  import { foldPersonas } from './persona.js'
@@ -41,8 +39,7 @@ export const hookCommand = (dialect = '') => quiltShellCommand(dialect ? ['hook'
41
39
  export const isQuiltHook = (h) => !!h && typeof h.command === 'string' && (h.command.startsWith(HOOK_COMMAND) || /(quilt\.js|\/quilt)"? hook( \w+)?$/.test(h.command))
42
40
  /**
43
41
  * `stop`: the hook as the AI finishes a turn, for an agent of its own (it is held there to answer
44
- * what is written to it and to hand on files someone waits for). A person's AI sessions get none:
45
- * nothing written to the person is theirs to answer, and their claims go when the session ends.
42
+ * what is written to it). A person's AI sessions get none: nothing written to the person is theirs to answer.
46
43
  */
47
44
  export function hookSettings (command = hookCommand(), { stop = true } = {}) {
48
45
  const run = { type: 'command', command, timeout: 10 }
@@ -138,7 +135,7 @@ export async function handleHook (event, { findDaemon: find = findDaemon, call =
138
135
  const d = find(cwd)
139
136
  if (!d) return answer({ exitCode: 0 })
140
137
  // Which AI session this is: the one whose tool process (the parent of its `quilt mcp`) is
141
- // among this hook's parents. Its claims, inbox and duties are its own (persona.js).
138
+ // among this hook's parents. Its inbox and duties are its own (persona.js).
142
139
  const mine = pids || parentPids()
143
140
  const api = (method, route, body) => method === 'GET'
144
141
  ? call(d, method, `${route}${route.includes('?') ? '&' : '?'}pids=${mine.join(',')}`)
@@ -167,15 +164,13 @@ async function sessionStart (api, state, say, name) {
167
164
  const who = others.length ? others.map((p) => p.name + (p.kind === 'agent' ? ' (AI agent)' : '')).join(', ') : 'nobody else yet'
168
165
  const parts = [
169
166
  `This folder is in a live Quilt session (room ${st.room}) with ${who}. Files can change underneath you at any time; re-read a file right before editing it.`,
170
- 'Quilt claims each file for you the moment you edit it, and releases those claims when you finish. ' +
171
- 'If a file is claimed by someone else, your edit is refused: do not retry or work around it. ' +
172
- 'Ask for it in its file queue with quilt_request_file (a title like "Working on <what> for <task>" and up to 300 characters on your plan), then carry on with other work: you are told when it is handed to you, with their context. ' +
173
- 'When someone asks for a file you hold, finish your change, then hand it off with quilt_handoff and your context; you cannot finish before you do.',
167
+ 'Nobody holds files here: edit any file you may change. Edits merge as they arrive; if your change clashes with someone\'s on the same lines, Quilt tells you and you resolve it. ' +
168
+ 'Before you edit a file, Quilt shows you what was said about it in chat and who else changed it lately.',
174
169
  // An agent of its own is shown what is written to it; a person's AI session never is (it is the person's).
175
170
  st.me && st.me.kind === 'agent'
176
171
  ? 'Messages from collaborators, mentions of you and tasks handed to you are shown to you as you work; answer with quilt_message and take a task with quilt_move_task.'
177
172
  : PERSON_CHAT,
178
- 'In the session you are your person: your messages, claims and tasks are theirs, and people see you as them. ' +
173
+ 'In the session you are your person: your messages and tasks are theirs, and people see you as them. ' +
179
174
  '"<person>\'s AI" ("Daniel\'s AI") is only that person\'s cloud AI, when they connected one (Quilt runs their own AI tool for them on their own cloud machine): write to it by that name. Nothing written or handed to "<person>\'s AI" comes to you; when your person asks you to work on tasks, take them from the board (quilt_tasks).'
180
175
  ]
181
176
  const duties = await api('GET', '/duties').catch(() => ({}))
@@ -187,17 +182,17 @@ async function sessionStart (api, state, say, name) {
187
182
 
188
183
  /** One short paragraph naming the files still open for merging, or null when there are none. */
189
184
  export function mergesContext (merges) {
190
- // A file pulled several times while held has a record per pull: one line, its latest.
185
+ // A file with several records: one line, its latest.
191
186
  const open = [...new Map((merges || []).filter((m) => m.state !== 'done').map((m) => [m.path, m])).values()]
192
187
  if (!open.length) return null
193
188
  const describe = (m) => {
194
189
  const action = m.oursDeleted ? 'deleted it offline' : 'changed it offline'
195
- const other = (m.others && m.others[0]) || m.claimedBy
190
+ const other = m.others && m.others[0]
196
191
  return `\`${m.path}\` (${m.by} ${action}${other ? `, ${other} in the session` : ''})`
197
192
  }
198
193
  const shown = open.slice(0, 5).map(describe).join(', ')
199
194
  const more = open.length > 5 ? `, and ${open.length - 5} more` : ''
200
- return `${open.length} file(s) wait for whoever holds them: ${shown}${more}. Quilt merges those changes in by itself when they let go; leave those files alone until then.`
195
+ return `${open.length} file(s) have changes Quilt has not merged in yet: ${shown}${more}.`
201
196
  }
202
197
 
203
198
  async function preEdit (event, d, api, state, say, name) {
@@ -206,21 +201,23 @@ async function preEdit (event, d, api, state, say, name) {
206
201
  .map((file) => path.relative(d.dir, path.resolve(event.cwd || d.dir, String(file))).split(path.sep).join('/'))
207
202
  .filter((rel) => rel && !rel.startsWith('..') && !path.isAbsolute(rel)) // not in the project
208
203
  if (!rels.length) return { exitCode: 0 }
209
- // The same check quilt_before_edit makes for every other agent.
210
- const r = await api('POST', '/before-edit', { paths: rels })
204
+ // The same check quilt_before_edit makes for every other agent. It never refuses: the edit goes ahead.
205
+ const r = await api('POST', '/before-edit', { paths: rels }).catch(() => ({}))
211
206
  const files = (r.files || []).filter((f) => f && f.shared) // Quilt doesn't sync the rest, so nobody can clash on them
212
- const refused = files.find((f) => !f.ok)
213
- if (refused) return { exitCode: 0, output: say.deny(name, heldRefusal(refused.path, refused.claim, refused.error)) }
214
207
  if (!files.length) return { exitCode: 0 }
215
208
  const seen = new Set(state.read().seen)
216
209
  // What people said about these files in chat, shown once per message per AI session.
217
210
  const said = (r.chat || []).filter((q) => q.id && !seen.has(`ask:${q.id}`))
211
+ // Who else changed them lately, shown once per file and writer per AI session.
212
+ const key = (f) => `recent:${f.path}:${(f.recent || []).map((w) => w.by).join(',')}:${f.box ? f.box.by : ''}`
213
+ const recent = files.filter((f) => ((f.recent && f.recent.length) || f.box) && !seen.has(key(f)))
214
+ if (!said.length && !recent.length) return { exitCode: 0 }
218
215
  state.update((s) => {
219
- for (const f of files) if (f.claimed && !s.claims.includes(f.path)) s.claims.push(f.path)
220
216
  for (const q of said) s.seen.push(`ask:${q.id}`)
217
+ for (const f of recent) s.seen.push(key(f))
221
218
  })
222
- if (!said.length) return { exitCode: 0 }
223
- return { exitCode: 0, output: say.context(name, renderChatAbout(said)) }
219
+ const text = [said.length ? renderChatAbout(said) : '', renderRecent(recent)].filter(Boolean).join('\n')
220
+ return { exitCode: 0, output: say.context(name, text) }
224
221
  }
225
222
 
226
223
  async function postEdit (api, state, say, name) {
@@ -241,24 +238,15 @@ async function stop (event, api, state, say, name) {
241
238
  for (const e of owed) if (!events.some((x) => x.id === e.id)) events.push(e)
242
239
  if (events.length) {
243
240
  state.update((s) => { for (const e of events) s.seen.push(e.id); for (const e of owed) s.seen.push(`owed:${e.id}`) })
244
- return { exitCode: 0, output: say.block(name, `${renderAsks(events, me)}\nBefore you finish, reply with quilt_message to what asks something of you (settle what needs nothing back with quilt_inbox no_reply), and take or decline a task you were handed (and release files you no longer need with quilt_release), then finish.`) }
245
- }
246
- // Files someone waits for in the file queue: the AI hands them off with its context before it stops (once per request).
247
- const duties = await api('GET', '/duties').catch(() => ({}))
248
- const queued = duties.queued || []
249
- const fresh = queued.flatMap((q) => q.queue).filter((r) => !asked.has(`queue:${r.id}`))
250
- if (fresh.length) {
251
- state.update((s) => { for (const r of fresh) s.seen.push(`queue:${r.id}`) })
252
- return { exitCode: 0, output: say.block(name, renderQueued(queued, 'finish')) }
241
+ return { exitCode: 0, output: say.block(name, `${renderAsks(events, me)}\nBefore you finish, reply with quilt_message to what asks something of you (settle what needs nothing back with quilt_inbox no_reply), and take or decline a task you were handed, then finish.`) }
253
242
  }
254
243
  // This person lets their AI pick up work by itself: its next task, once per task.
244
+ const duties = await api('GET', '/duties').catch(() => ({}))
255
245
  if (duties.next && !asked.has(`next:${duties.next.id}`)) {
256
- await releaseAll(api, state) // the files of the work just finished are free again
257
246
  state.update((s) => { s.seen.push(`next:${duties.next.id}`) })
258
247
  return { exitCode: 0, output: say.block(name, renderNextTask(duties.next)) }
259
248
  }
260
249
  }
261
- await releaseAll(api, state)
262
250
  await api('POST', '/finish', {}).catch(() => {})
263
251
  return { exitCode: 0 }
264
252
  }
@@ -269,7 +257,6 @@ async function owedAnswers (api) {
269
257
  }
270
258
 
271
259
  async function sessionEnd (api, state) {
272
- await releaseAll(api, state)
273
260
  state.remove()
274
261
  return { exitCode: 0 }
275
262
  }
@@ -289,17 +276,10 @@ async function unseenEvents (api, state) {
289
276
  /** What the hooks show: each event with the conversation before it, like quilt_inbox, so "that" means something. */
290
277
  export function renderAsks (events, me = []) {
291
278
  return `Quilt: collaborators wrote to you, or handed you work, while you were working:\n${eventLines(events, { me }).join('\n')}\n` +
292
- 'Someone asking for a file you hold in its file queue gets it from you with quilt_handoff and your context once your change is done; answer other messages that ask something of you with quilt_message (to: their name); one that needs nothing back (thanks, a greeting, an FYI) gets no reply, settle it with quilt_inbox (no_reply: [its id]). ' +
279
+ 'Answer messages that ask something of you with quilt_message (to: their name); one that needs nothing back (thanks, a greeting, an FYI) gets no reply, settle it with quilt_inbox (no_reply: [its id]). ' +
293
280
  'Take a task you were handed with quilt_move_task when you are free, or say in chat why not. ' + REFERS_HOW
294
281
  }
295
282
 
296
- /** Releases every claim the hooks made for this Claude session. */
297
- async function releaseAll (api, state) {
298
- const s = state.read()
299
- for (const pattern of s.claims) await api('POST', '/release', { pattern }).catch(() => {})
300
- state.update((x) => { x.claims = [] })
301
- }
302
-
303
283
  /** This process's parents, nearest first (a few levels), for finding its AI session. */
304
284
  export function parentPids (start = process.ppid, depth = 6) {
305
285
  const out = []
@@ -312,12 +292,12 @@ export function parentPids (start = process.ppid, depth = 6) {
312
292
  return out
313
293
  }
314
294
 
315
- /** Per-Claude-session state in .quilt/hooks/<session>.json: the claims it made and the messages it has seen. */
295
+ /** Per-Claude-session state in .quilt/hooks/<session>.json: the messages it has seen. */
316
296
  export function hookState (projectDir, sessionId) {
317
297
  const dir = path.join(migrateDir(projectDir), 'hooks')
318
298
  const file = path.join(dir, `${String(sessionId || 'default').replace(/[^\w.-]/g, '_')}.json`)
319
299
  const read = () => {
320
- try { const s = JSON.parse(fs.readFileSync(file, 'utf8')); return { claims: s.claims || [], seen: s.seen || [], after: s.after || 0 } } catch { return { claims: [], seen: [], after: 0 } }
300
+ try { const s = JSON.parse(fs.readFileSync(file, 'utf8')); return { seen: s.seen || [], after: s.after || 0 } } catch { return { seen: [], after: 0 } }
321
301
  }
322
302
  return {
323
303
  file,
@@ -333,25 +313,6 @@ export function hookState (projectDir, sessionId) {
333
313
  }
334
314
  }
335
315
 
336
- /**
337
- * Releases claims left behind by hooks of Claude sessions that ended without
338
- * telling us (a crash, a closed laptop). Run when a session starts for the folder.
339
- */
340
- export async function releaseLeftoverHookClaims (session) {
341
- const dir = path.join(session.stateDir, 'hooks')
342
- let names = []
343
- try { names = fs.readdirSync(dir).filter((n) => n.endsWith('.json')) } catch { return 0 }
344
- let released = 0
345
- for (const n of names) {
346
- const st = hookState(session.root, n.slice(0, -5))
347
- for (const pattern of st.read().claims) {
348
- try { released += await session.release(pattern) } catch {}
349
- }
350
- st.remove()
351
- }
352
- return released
353
- }
354
-
355
316
  async function callWithTimeout (daemon, method, route, body) {
356
317
  const res = await fetch(`http://127.0.0.1:${daemon.port}${route}`, {
357
318
  method,
package/src/identity.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // Per-person identity: an Ed25519 key pair kept in ~/.quilt/identity.json.
2
2
  // The relay ties each name in a room to the first key that used it, and
3
3
  // checks a signature on every connect, so nobody can act under someone
4
- // else's name (for example to fake or release their claims).
4
+ // else's name (for example to fake their messages or open their boxes).
5
5
  import fs from 'node:fs'
6
6
  import os from 'node:os'
7
7
  import path from 'node:path'
package/src/inbox.js CHANGED
@@ -99,8 +99,8 @@ export function scanInbox ({ messages = [], tasks = [], reader, now = Date.now()
99
99
  }
100
100
  }
101
101
  if (seed || seenMsgs.has(m.id) || !me || names.includes(m.by) || own.has(m.by)) continue
102
- // File queue messages (a request for a file the reader holds, or a file handed to them) wake
103
- // them like a direct message, but ask for a handoff rather than a reply (duties.js).
102
+ // File queue messages from before Quilt stopped holding files (no-holds, 2026-11-13): still in older
103
+ // chat, and they ask for no reply (duties.js).
104
104
  const queue = m.kind === 'queue' || m.kind === 'handoff' ? { queue: m.kind, file: typeof m.path === 'string' ? m.path : '' } : {}
105
105
  // A note that work the reader asked to commit was committed (commit.js): it wakes them, and asks for no reply.
106
106
  if (m.kind === 'commit') queue.commit = typeof m.commit === 'string' ? m.commit : true
@@ -178,8 +178,9 @@ const idOf = (e) => e.id ? ` (id ${e.id})` : ''
178
178
  /** One event as a line an agent can act on. */
179
179
  export function describeEvent (e) {
180
180
  const who = e.by || 'someone'
181
- if (e.queue === 'queue') return `${who} asked for ${e.file} in its file queue: ${e.text} Finish what you are doing in it, then hand it off with quilt_handoff and your context.`
182
- if (e.queue === 'handoff') return `${who} handed you ${e.file}, which you asked for: it is yours to edit now. ${e.text}`
181
+ // From before Quilt stopped holding files: nothing to hand off, every file is editable.
182
+ if (e.queue === 'queue') return `${who} asked for ${e.file} (an old file queue request: nobody holds files now, so there is nothing to hand off). ${e.text}`
183
+ if (e.queue === 'handoff') return `${who} handed you ${e.file} (from before Quilt stopped holding files: every file is editable now). ${e.text}`
183
184
  if (e.nudge) return `Quilt reminds you (no reply needed): ${e.text}`
184
185
  if (typeof e.commit === 'string') return `${who} asked you for a commit (request ${e.commit}; it waits here until the request is done, no reply needed): ${e.text}`
185
186
  if (e.commit) return `${who} committed work you asked for (no reply needed): ${e.text}`
package/src/key-cli.js CHANGED
@@ -5,6 +5,7 @@
5
5
  import { SAY_USAGE, isHelpArg, splitSayRecipient } from './say-args.js'
6
6
 
7
7
  /** Commands that work with the key. tasks, task and tool exist only here. */
8
+ // claim and release answer that Quilt holds no files (kept one release for older scripts: no-holds, 2026-11-13).
8
9
  export const KEY_COMMANDS = new Set(['status', 'messages', 'inbox', 'say', 'history', 'claim', 'release', 'focus', 'commits', 'commit-request', 'tasks', 'task', 'tool'])
9
10
 
10
11
  export const KEY_USAGE = `With QUILT_AGENT_KEY (an agent in a sandbox, no quilt join running):
@@ -14,7 +15,6 @@ export const KEY_USAGE = `With QUILT_AGENT_KEY (an agent in a sandbox, no quilt
14
15
  quilt say [@name] <message> [--everyone] [--also]
15
16
  quilt task <id> One task in full, with its comments
16
17
  quilt history [path] [--by name] [--since 2h] [--task id] [--diff] [-n 30]
17
- quilt claim <path|glob> [note] | quilt release [path|glob]
18
18
  quilt focus <what you are doing> Shared with everyone (quilt_share)
19
19
  quilt commit-request <message> [--files a,b] [--task id]
20
20
  quilt tool <quilt_tool_name> [json] Any Quilt tool, e.g. quilt tool quilt_move_task '{"id":"t1","column":"doing"}'