heyquilt 0.3.176 → 0.3.178

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/relay-mcp.js CHANGED
@@ -59,7 +59,7 @@ export function freshEditPaths (editing, now = Date.now()) {
59
59
  }
60
60
  const MAX_READ_CHARS = 200 * 1024
61
61
  // Tools that read or change a branch's files or history: a hosted agent's first one pins its branch (Room.pinHostedBranch).
62
- const FILE_TOOLS = new Set(['quilt_sync', 'quilt_history', 'quilt_list_files', 'quilt_read_file', 'quilt_project_rules', 'quilt_write_file', 'quilt_unpack'])
62
+ const FILE_TOOLS = new Set(['quilt_sync', 'quilt_history', 'quilt_list_files', 'quilt_read_file', 'quilt_project_rules', 'quilt_write_file'])
63
63
  const AGENT = 'agent-mcp' // transaction origin
64
64
  // The board's columns, from tasks.js: hosted agents move tasks to every one of them (QA included), like the local MCP.
65
65
  const COLUMN_IDS_LIST = COLUMNS.map((c) => c.id)
@@ -135,7 +135,7 @@ const cleanPath = (p) => String(p || '').trim().replace(/^\.\//, '').replace(/^\
135
135
 
136
136
  /**
137
137
  * The tools every relay-hosted MCP offers, on whatever room `ctx.room()` gives now.
138
- * ctx: { room(), me, who(), access(), tool(), warn() }: `who` is what boxes belong to
138
+ * ctx: { room(), me, who(), access(), tool(), warn() }: `who` is the caller
139
139
  * ({ name } or { name, id }), `access` the caller's role and folders, `warn` extra text
140
140
  * for status, `withSession(fn)` runs a tool with the current room or explains why not.
141
141
  */
@@ -242,10 +242,6 @@ function sessionTools (server, ctx) {
242
242
  for (const h of room.hostedOnline ? room.hostedOnline() : []) if (h.name !== me && !out.some((p) => p.name === h.name)) out.push({ name: h.name, kind: h.kind, tool: 'hosted', hosted: true })
243
243
  return out
244
244
  }
245
- // Boxes (someone's unfinished work on a file) as people see them: an older app's AI session ("Dana · login", of: Dana) is its person.
246
- const boxesOf = (room) => (room.boxList ? room.boxList(branchOf(room)) : []).map((c) => (c.of ? { ...c, by: c.of } : c))
247
- // Boxes are per branch: who the agent is, on the branch it works on.
248
- const who = (room) => ({ ...ctx.who(room), branch: branchOf(room) })
249
245
  // The rules every agent is held to (duties.js), enforced here because hosted agents work through these tools.
250
246
  const seen = (doc) => doc.getArray('chat').toArray().filter(visible)
251
247
  // Messages this agent settled as needing no reply (quilt_inbox no_reply), kept with its inbox.
@@ -297,7 +293,7 @@ function sessionTools (server, ctx) {
297
293
  })
298
294
 
299
295
  tool('quilt_status', {
300
- description: 'See who else is in the live session, what they and their AIs are doing, recent file changes, boxed work and recent messages. Call this before starting a task.',
296
+ description: 'See who else is in the live session, what they and their AIs are doing, recent file changes and recent messages. Call this before starting a task.',
301
297
  inputSchema: {}
302
298
  }, (_, { room, doc, chat, activity }) => {
303
299
  const a = ctx.access(room)
@@ -323,8 +319,6 @@ function sessionTools (server, ctx) {
323
319
  if (agents.length) lines.push('', '## Agents and how Quilt wakes them', ...agents.map((m) => `- ${m.name}: ${m.wake || 'not known yet'}`))
324
320
  const away = room.memberList ? room.memberList().filter((m) => m.away && m.name !== me && !ps.some((p) => p.name === m.name)) : []
325
321
  if (away.length) lines.push('', '## Away (agents that work in turns, between turns: they read what you write at their next turn)', ...away.map((m) => `- ${m.name} (agent) · last here ${ago(m.lastSeen)}`))
326
- const bxs = boxesOf(room)
327
- if (bxs.length) lines.push('', '## Boxed work', ...bxs.map((c) => `- ${c.pattern}: ${c.by === me ? 'your unfinished work, in nobody else\'s folder until you commit it or quilt_unpack it' : `${c.by}'s unfinished work: not in anyone else's folder until they commit or unpack it`}`))
328
322
  const acts = activity.toArray().filter(Boolean).slice(-12).reverse()
329
323
  lines.push('', '## Recent file changes', ...(acts.length ? acts.map((x) => x.kind === 'pulled' ? `- ${x.by} pulled ${x.detail || 'commits'} (${ago(x.ts)})` : x.kind === 'brought' ? `- ${x.by} brought in ${x.detail || 'commits'}${x.branch ? ` on ${x.branch}` : ''} (${ago(x.ts)})` : x.kind === 'switched' ? `- ${x.by} switched to ${x.branch} (${ago(x.ts)})` : `- ${x.by} ${x.kind} ${x.path} (${ago(x.ts)})`) : ['- None yet.']))
330
324
  const msgs = chat.toArray().filter(visible).slice(-8)
@@ -750,18 +744,14 @@ function sessionTools (server, ctx) {
750
744
  })
751
745
 
752
746
  tool('quilt_list_files', {
753
- description: 'List the shared project files, with whose unfinished work is boxed on any of them.',
747
+ description: 'List the shared project files.',
754
748
  inputSchema: { under: z.string().optional().describe('Only files under this folder') }
755
749
  }, async ({ under }, { room, files, blobs, branch }) => {
756
750
  const pre = under ? cleanPath(under).replace(/\/+$/, '') + '/' : ''
757
- const bx = new Map(boxesOf(room).map((c) => [c.pattern, c]))
758
751
  let all
759
752
  try { all = branch && isDiff(branch) ? [...(await listPaths(room, branch.key, branch)).keys()] : [...files.keys(), ...blobs.keys()] } catch (err) { return fail(err.message) }
760
753
  const paths = [...new Set(all)].filter((p) => isSafeRelPath(p) && (!pre || p.startsWith(pre))).sort()
761
- const shown = paths.slice(0, 500).map((p) => {
762
- const c = bx.get(p)
763
- return `- ${p}${c ? ` (boxed by ${c.by}: their unfinished work)` : ''}`
764
- })
754
+ const shown = paths.slice(0, 500).map((p) => `- ${p}`)
765
755
  return text(paths.length ? shown.join('\n') + (paths.length > 500 ? `\n… and ${paths.length - 500} more` : '') : 'No files.')
766
756
  })
767
757
 
@@ -778,12 +768,10 @@ function sessionTools (server, ctx) {
778
768
  }, async ({ path: p }, { room, files, blobs, branch }) => {
779
769
  const rel = cleanPath(p)
780
770
  if (!isSafeRelPath(rel)) return fail('That is not a path inside the project.')
781
- const bx = boxesOf(room).find((c) => c.by !== me && c.pattern === rel)
782
- const boxNote = bx ? `(Boxed by ${bx.by}: their unfinished work, not committed yet and in nobody else's folder. Don't build on it as if it were done; writing the file opens the box.)\n\n` : ''
783
771
  // What this agent read is its next write's base (read-bases.js): the version goes in a block of its own, never in the file's text.
784
772
  const shown = (s) => {
785
773
  const version = readBasesOf(room).note(readerId(room), branch ? branch.key : '', rel, s)
786
- const body = boxNote + (s.length > MAX_READ_CHARS ? s.slice(0, MAX_READ_CHARS) + `\n… (${s.length - MAX_READ_CHARS} more characters not shown)` : s)
774
+ const body = s.length > MAX_READ_CHARS ? s.slice(0, MAX_READ_CHARS) + `\n… (${s.length - MAX_READ_CHARS} more characters not shown)` : s
787
775
  return { content: [{ type: 'text', text: body }, { type: 'text', text: `(Version ${version}: pass it to quilt_write_file as base.)` }] }
788
776
  }
789
777
  if (branch && isDiff(branch)) {
@@ -839,10 +827,6 @@ function sessionTools (server, ctx) {
839
827
  if (diff && !hasEntry(branch, rel) && !branch.gone.has(rel)) {
840
828
  try { const r = await readPath(room, branch.key, branch, rel); fromGit = r.kind === 'text' ? r.text : r.kind === 'binary' ? '' : null } catch (err) { return fail(err.message) }
841
829
  }
842
- // Someone else's unfinished work boxed on it: the write is never refused; the box opens, so their
843
- // work and this change reach every folder together (the write merges with what the file has now).
844
- const opened = boxesOf(room).find((c) => c.by !== me && c.pattern === rel)
845
- if (opened) { try { room.boxRequest({ ...who(room), talk: ctx.access(room)?.talk !== false }, { op: 'unbox', pattern: rel, edit: true }); room.broadcastBoxes() } catch {} }
846
830
  // The merge, in one step with the write (nothing awaits between them): what the file holds now, against
847
831
  // the version this agent's content was made from. Same lines changed first keep theirs; this agent's are held.
848
832
  const bases = readBasesOf(room)
@@ -887,28 +871,9 @@ function sessionTools (server, ctx) {
887
871
  if (known.from === 'unknown') notes.push(`Quilt no longer has the version ${version ? `you gave as base (${String(version).slice(0, 12)})` : 'you last read'}, so your write was merged against ${typeof known.text === 'string' && known.text !== cur ? 'the oldest version it still has' : 'the file as it is'}. Read the file again before your next write, and give its version as base.`)
888
872
  if (next !== content && !(merged && merged.held.length)) notes.push(`Others had changed ${rel} since you read it: their changes are kept alongside yours, so the file is not exactly what you wrote. Read it again before your next write.`)
889
873
  notes.push(...notices)
890
- return text(`${existed ? 'Updated' : 'Created'} ${rel}${onBranchNote(room, branch)}${detail ? ` (${detail} lines)` : ' (no change)'}. Everyone in the session has it now.${opened ? ` It was in ${opened.by}'s box: the box opened, and your change went in with their work.` : ''} (Version ${version2}: your next write's base.)${notes.length ? `\n\n${notes.join('\n\n')}` : ''}${context ? `\n\n${context}` : ''}`)
874
+ return text(`${existed ? 'Updated' : 'Created'} ${rel}${onBranchNote(room, branch)}${detail ? ` (${detail} lines)` : ' (no change)'}. Everyone in the session has it now. (Version ${version2}: your next write's base.)${notes.length ? `\n\n${notes.join('\n\n')}` : ''}${context ? `\n\n${context}` : ''}`)
891
875
  })
892
876
 
893
- tool('quilt_unpack', {
894
- description: 'Share boxed work before it is committed. Your writes stay in a box: everyone sees the change, but it is in nobody else\'s folder, so nobody else\'s git can commit it, until you commit it (quilt_git_commit). ' +
895
- 'Unpack when someone needs your change now: your boxed files reach everyone\'s folder, and you keep them. Decide this yourself; for a large, risky or critical change, or when the project\'s rules say so, ask your person first.',
896
- inputSchema: { paths: z.array(z.string().min(1).max(500)).min(1).max(100).describe('Your boxed files, relative paths') }
897
- }, ({ paths }, { room, doc }) => {
898
- { const w = waitRefusal(doc, 'quilt_unpack', room); if (w) return fail(w) }
899
- const done = []
900
- const not = []
901
- for (const p of [...new Set(paths.map(cleanPath))]) {
902
- const c = boxesOf(room).find((x) => x.pattern === p && x.by === me)
903
- if (!c) { not.push(p); continue }
904
- try { if (room.boxRequest(who(room), { op: 'unbox', pattern: p }).unboxed) done.push(p); else not.push(p) } catch { not.push(p) }
905
- }
906
- if (done.length) room.broadcastBoxes()
907
- if (!done.length) return fail(`${not.join(', ')} ${not.length === 1 ? 'is' : 'are'} not boxed by you.`)
908
- return text(`Unpacked ${done.join(', ')}: in everyone's folder now. Your next write to one boxes it again.${not.length ? ` Not boxed by you: ${not.join(', ')}.` : ''}`)
909
- })
910
-
911
-
912
877
  // `quilt sync` (npx heyquilt sync): a sandboxed agent's folder in one shot, its sync state kept
913
878
  // here (relay-turn-sync.js). Hosted only: the CLI reaches it with the agent's QUILT_AGENT_KEY.
914
879
  if (ctx.multi) {
@@ -965,9 +930,6 @@ function sessionTools (server, ctx) {
965
930
  historyOf(room).record({ by: me, path: rel, kind, before, after, detail, task: currentTask(readTasks(taskMap(doc)), me) })
966
931
  },
967
932
  lastEditor: (rel) => lastWriter(room, activity, branch, rel),
968
- // Others' boxes: their unfinished work stays out of this folder until this folder changes the file (relay-turn-sync.js).
969
- ghosts: new Set(boxesOf(room).filter((c) => c.by !== me).map((c) => c.pattern)),
970
- openBox: (rel) => { try { room.boxRequest({ ...who(room), talk: a?.talk !== false }, { op: 'unbox', pattern: rel, edit: true }); room.broadcastBoxes() } catch {} },
971
933
  // A push is a live write: the same engine as every other (held conflicts for this agent to resolve).
972
934
  rules: liveRules(room, files)
973
935
  })
@@ -1327,9 +1289,6 @@ export async function handleHostedMcp ({ req, res, pass, relay, workspaces = nul
1327
1289
  room.hostedSeen.delete(account)
1328
1290
  room.forgetHostedBranch(account)
1329
1291
  for (const [k, p] of room.pending) if (k.hosted && p.id === account) room.pending.delete(k)
1330
- // Leaving opens its boxes: nobody else could commit them.
1331
- room.dropBoxes((c) => c.byId === account)
1332
- room.broadcastBoxes()
1333
1292
  room.broadcastMembers()
1334
1293
  }
1335
1294
  const left = allRooms(h)
@@ -10,11 +10,10 @@ 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, boxes (unfinished work), and hosted agents' choices of a branch worked on this week (chosenBranches). */
13
+ /** Who is on which branch now: connected folders, 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.boxes || {})) on.add(room.branchOf(c))
18
17
  return on
19
18
  }
20
19
 
@@ -14,9 +14,8 @@
14
14
  // changed the same lines the session keeps what landed first and the folder's lines are held for its
15
15
  // writer (or any AI) to resolve (held.js, quilt_resolve_merge): the agent hears in the sync's answer
16
16
  // (`held`), and its copy is kept aside in the folder. The newer edit no longer wins. The removed-name
17
- // warning runs on it too. Nobody holds files (no-holds, 2026-11-13): a folder's
18
- // change to someone else's boxed file opens the box (ctx.openBox) and is merged the same way. Versions
19
- // an older relay held for someone ('claimed' records) go in at the agent's next sync (settleWaiting).
17
+ // warning runs on it too. Nobody holds files: versions an older relay held for someone ('claimed'
18
+ // records) go in at the agent's next sync (settleWaiting).
20
19
  import fs from 'node:fs'
21
20
  import path from 'node:path'
22
21
  import zlib from 'node:zlib'
@@ -179,11 +178,8 @@ const heldOut = (r) => { const v = r.version || r; return { path: r.path, id: r.
179
178
  * One step of a sync. `args`: { step, slot, files?, paths? }. `ctx`: { room, fdoc, files, blobs,
180
179
  * branchKey, epoch, account, me, origin, globalRefusal(), pathRefusal(rel) -> { kind: 'aside' |
181
180
  * 'keep', why } | null (access only: a viewer, outside its folders), record({ rel, kind, before, after, detail }),
182
- * lastEditor(rel), ghosts?, openBox(rel)?, rules? }.
181
+ * lastEditor(rel), rules? }.
183
182
  * `rules`: the live-write engine (live-merge.js LiveRules); else one on ctx.room's document.
184
- * `ghosts`: the paths someone else has boxed (docs/superpowers/specs/2026-10-16-git-boxes-design.md): their
185
- * unfinished work never reaches this folder. The folder sees each as it last had it (its checkpoint), or as it
186
- * has it now. An edit to one is never refused: `openBox(rel)` opens the box, and the edit merges with the work in it.
187
183
  * Returns the answer (a plain object, sent as JSON).
188
184
  */
189
185
  export function turnSyncStep (args, ctx) {
@@ -194,28 +190,16 @@ export function turnSyncStep (args, ctx) {
194
190
  const saved = all[ctx.branchKey]
195
191
  // A checkpoint of an older document of this branch (removed and started again) says nothing about this one.
196
192
  const checkpoint = saved && (saved.epoch || null) === (ctx.epoch || null) ? saved : null
197
- const ghosts = ctx.ghosts instanceof Set ? ctx.ghosts : new Set()
198
193
  // A diff branch says what it deleted (ctx.gone); a full one, by the entries Yjs remembers it had.
199
- const deleted = (rel) => !ghosts.has(rel) && !ctx.files.has(rel) && !ctx.blobs.has(rel) && (ctx.git ? ctx.gone.has(rel) : (ctx.files._map.has(rel) || ctx.blobs._map.has(rel)))
200
- const cpFiles = (checkpoint && checkpoint.files) || {}
201
- // The session as this folder may see it: someone else's box shows as the folder's own version.
202
- const session = (local = null) => {
203
- const out = sessionState(ctx.files, ctx.blobs, ctx.git)
204
- for (const rel of ghosts) {
205
- const cp = cpFiles[rel]
206
- if (cp && HASH.test(String(cp.h || ''))) out.set(rel, sessionEntry(cp.h, { text: typeof cp.t === 'string' ? cp.t : null }))
207
- else if (local && local[rel] && local[rel] !== SKIP) out.set(rel, sessionEntry(local[rel]))
208
- else out.delete(rel)
209
- }
210
- return out
211
- }
194
+ const deleted = (rel) => !ctx.files.has(rel) && !ctx.blobs.has(rel) && (ctx.git ? ctx.gone.has(rel) : (ctx.files._map.has(rel) || ctx.blobs._map.has(rel)))
195
+ const session = () => sessionState(ctx.files, ctx.blobs, ctx.git)
212
196
  const step = args.step
213
197
 
214
198
  if (step === 'plan') {
215
199
  const local = cleanManifest(args.files)
216
200
  // What an older relay kept waiting for a holder goes in first, so the plan already sees it.
217
- const settled = settleWaiting(ctx, ghosts)
218
- const p = planSync({ local, session: session(local), checkpoint, deleted })
201
+ const settled = settleWaiting(ctx)
202
+ const p = planSync({ local, session: session(), checkpoint, deleted })
219
203
  const refused = p.upload.length || p.delete.length ? ctx.globalRefusal() : null
220
204
  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 } : {}) }
221
205
  }
@@ -226,20 +210,12 @@ export function turnSyncStep (args, ctx) {
226
210
  const refusedAll = ctx.globalRefusal()
227
211
  const first = !checkpoint
228
212
  const base = (checkpoint && checkpoint.files) || {}
229
- // Each path is only changed once, after it was looked at: one look at the session is enough
230
- // (again only when a box this folder changed opens).
231
- let state = session()
213
+ // Each path is only changed once, after it was looked at: one look at the session is enough.
214
+ const state = session()
232
215
  for (const [rel, v] of Object.entries(args.files || {})) {
233
216
  if (!isSafeRelPath(rel)) continue
234
217
  const c = content(v)
235
218
  if (!c) { out.skipped.push(rel); continue }
236
- // Someone else's box this folder changed: it opens, so this change merges with the work in it (never refused).
237
- if (ghosts.has(rel) && (c.gone || !cpFiles[rel] || c.hash !== cpFiles[rel].h)) {
238
- if (!ctx.openBox) { out.kept.push({ path: rel, why: `${rel} is someone else's unfinished work` }); continue }
239
- ctx.openBox(rel)
240
- ghosts.delete(rel)
241
- state = session()
242
- }
243
219
  const now = state.get(rel) || null
244
220
  const d = decide({ local: c.gone ? null : c.hash, session: now, base: base[rel] || null, first, deleted: deleted(rel) })
245
221
  if (d === 'same') continue
@@ -269,8 +245,6 @@ export function turnSyncStep (args, ctx) {
269
245
  if (typeof rel !== 'string' || !isSafeRelPath(rel)) continue
270
246
  const s = now.get(rel)
271
247
  if (bytes >= MAX_PULL_BYTES) { more.push(rel); continue }
272
- // Someone else's box: the folder's own last version when it has the text, else nothing (the folder keeps what it has).
273
- if (ghosts.has(rel)) { if (s && typeof s.text === 'string') { files[rel] = { text: s.text, h: s.h }; bytes += s.text.length } continue }
274
248
  if (!s) { files[rel] = { gone: true }; continue }
275
249
  if (s.stored) { files[rel] = { stored: true }; continue }
276
250
  if (typeof s.text === 'string') { files[rel] = { text: s.text, h: s.h }; bytes += s.text.length; continue }
@@ -486,13 +460,13 @@ function closeWaiting (rel, ctx, reason) {
486
460
  * too long for the record, is only in the folder: it goes in with the folder's next push.
487
461
  * Returns { merged, lost, held, warnings }.
488
462
  */
489
- function settleWaiting (ctx, ghosts) {
463
+ function settleWaiting (ctx) {
490
464
  const res = { merged: [], lost: [], held: [], warnings: [] }
491
465
  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))
492
466
  if (!mine.length || ctx.globalRefusal()) return res
493
467
  for (const rec of mine) {
494
468
  const rel = rec.path
495
- if (ghosts.has(rel) || ctx.pathRefusal(rel)) continue // someone's box, or no longer ours to change
469
+ if (ctx.pathRefusal(rel)) continue // no longer ours to change
496
470
  if (rec.binary || (rec.ours === null && !rec.oursDeleted)) continue
497
471
  const now = sessionState(ctx.files, ctx.blobs, ctx.git).get(rel) || null
498
472
  const holder = rec.claimedBy || rec.others[0] || 'someone'