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-mcp.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
// can't install Quilt, connects to https://<relay>/mcp with a pass from the accounts
|
|
5
5
|
// API (the API's /mcp hands it over with the agent's access key). It joins a session
|
|
6
6
|
// from an invite link, waits for the owner like anyone else, and then reads and
|
|
7
|
-
// writes the shared files, shares what it's doing
|
|
8
|
-
//
|
|
7
|
+
// writes the shared files, shares what it's doing and messages. Its file changes are
|
|
8
|
+
// CRDT edits, so they merge with everyone else's: nobody holds files (no-holds, 2026-11-13).
|
|
9
9
|
//
|
|
10
10
|
// The older link-based server (handleAgentMcp) is kept for relays without sign-in.
|
|
11
11
|
import { authorOf } from './ui/chat.js'
|
|
@@ -20,10 +20,10 @@ import { WAKE_DESCRIPTION, WAKE_INPUT, runWakeTool } from './wake-tool.js'
|
|
|
20
20
|
import { WAKE_STEP, wakeCheck } from './wake.js'
|
|
21
21
|
import * as Y from 'yjs'
|
|
22
22
|
import { capText, toolLabel } from './agents/common.js'
|
|
23
|
-
import {
|
|
23
|
+
import { isSafeRelPath } from './pathrules.js'
|
|
24
24
|
import { readTasks, addTask, updateTask, deleteTask, taskMarkdown, formatTasks, columnName, assigneeLabel, assignmentFields, COLUMNS } from './tasks.js'
|
|
25
25
|
import { readComments, addComment, withComments, formatTaskDetails, MAX_COMMENT } from './task-comments.js'
|
|
26
|
-
import {
|
|
26
|
+
import { applyLineDiff } from './textdiff.js'
|
|
27
27
|
import { parseInvite } from './ui/invite.js'
|
|
28
28
|
import { scanInbox, renderInbox } from './inbox.js'
|
|
29
29
|
import { withContext, queryConversation, renderConversation, CONVERSATION_DESCRIPTION } from './conversation.js'
|
|
@@ -33,7 +33,7 @@ import { HistoryLog, queryHistory, parseSince, formatHistory, currentTask, lineD
|
|
|
33
33
|
import { linkedHistory } from './quilt-history.js'
|
|
34
34
|
import { changeRefusal, TALK_REFUSED } from './session-access.js'
|
|
35
35
|
import { MIGRATE_SESSION_DESCRIPTION, describeQuiltPlan } from './session-quilt.js'
|
|
36
|
-
import { chatAbout, renderChatAbout, waitingOn, needsNoReply, renderUnanswered,
|
|
36
|
+
import { chatAbout, renderChatAbout, waitingOn, needsNoReply, renderUnanswered, NO_HOLDS, answered, unaddressed, CHAT_RULES, RE_HELP, replyFor, renderReplied, PERSON_CHAT, PERSON_INBOX } from './duties.js'
|
|
37
37
|
import { describeSubscription, describeWebhookTest, COALESCE_HELP, WEBHOOK_EVENTS } from './webhooks.js'
|
|
38
38
|
import { registerWorkspaceTools, bytesFetcher, WORKSPACE_GUIDE_HOSTED } from './workspace-tools.js'
|
|
39
39
|
import { DEFAULT_KEY, validBranchKey } from './branchdocs.js'
|
|
@@ -43,16 +43,16 @@ import { turnSyncStep, ROOM_KEY } from './relay-turn-sync.js'
|
|
|
43
43
|
import { describeSecretNames, SECRET_NAMES_DESCRIPTION } from './secret-names.js'
|
|
44
44
|
import { quiltOf, seamRefusal, seamNote, seamStatus, seamFileRefusal, seamToolSpec, runSessionSeamTool, seamOnly, seamWorkflow, SEAM_SESSION_TOOLS, SEAM_GUIDE_HOSTED, GIT_TOOLS } from './session-seam.js'
|
|
45
45
|
import { seamAccess } from './seam-access.js'
|
|
46
|
-
import { releaseInSeam } from './seam-claims.js'
|
|
47
|
-
import { releaseWords } from './release-words.js'
|
|
48
46
|
import { LAYOUT_QUILT } from './session-layout3.js'
|
|
47
|
+
import { HELD_MAP, readHeld, findHeld, settleHeld, renderHeld, describeHeld, staleWriteMinutes, RESOLVE_DESCRIPTION } from './held.js'
|
|
48
|
+
import { applyMine, LiveRules } from './live-merge.js'
|
|
49
|
+
import { readBasesOf } from './read-bases.js'
|
|
49
50
|
import { TRANSCRIPT_DESCRIPTION, JOIN_DESCRIPTION, SAY_DESCRIPTION, MAX_LINE, renderLines, readLines, inVoice, transcribeSetting, voiceStatusLines, callAgents, liveCallOf, setAgentLeft, notInCall, agentSays, agentsJoinCalls } from './voice.js'
|
|
50
51
|
|
|
51
52
|
const FEED_CAP = 300
|
|
52
53
|
const ACTIVITY_CAP = 300
|
|
53
54
|
const TAB_STALE_MS = 3 * 60 * 1000
|
|
54
55
|
const MAX_WRITE_BYTES = 1024 * 1024
|
|
55
|
-
const HOSTED_AUTO_CLAIM_QUIET_MS = 10 * 60 * 1000 // a file a hosted agent stopped writing this long ago is let go of
|
|
56
56
|
const EDIT_FRESH_MS = 4 * 60 * 1000 // a peer's edit counts as current this long (as session.js recentEdits)
|
|
57
57
|
|
|
58
58
|
/** The files a peer edited in the last few minutes, newest first: its presence keeps old edits until it edits again. */
|
|
@@ -63,8 +63,8 @@ export function freshEditPaths (editing, now = Date.now()) {
|
|
|
63
63
|
.map(([path]) => path)
|
|
64
64
|
}
|
|
65
65
|
const MAX_READ_CHARS = 200 * 1024
|
|
66
|
-
// Tools that read or change a branch's files
|
|
67
|
-
const FILE_TOOLS = new Set(['quilt_sync', 'quilt_history', 'quilt_list_files', 'quilt_read_file', 'quilt_project_rules', 'quilt_write_file', '
|
|
66
|
+
// Tools that read or change a branch's files or history: a hosted agent's first one pins its branch (Room.pinHostedBranch).
|
|
67
|
+
const FILE_TOOLS = new Set(['quilt_sync', 'quilt_history', 'quilt_list_files', 'quilt_read_file', 'quilt_project_rules', 'quilt_write_file', 'quilt_unpack'])
|
|
68
68
|
const AGENT = 'agent-mcp' // transaction origin
|
|
69
69
|
// The board's columns, from tasks.js: hosted agents move tasks to every one of them (QA included), like the local MCP.
|
|
70
70
|
const COLUMN_IDS_LIST = COLUMNS.map((c) => c.id)
|
|
@@ -77,22 +77,19 @@ export const INSTRUCTIONS =
|
|
|
77
77
|
'Before starting a task, call quilt_status to see who is working on what, and quilt_tasks for the shared board ' +
|
|
78
78
|
'(open tasks assigned to you are listed first). Assign work with quilt_assign_task; quilt_task reads one task in full with its comments, and quilt_comment_task leaves a note or handoff on it. ' +
|
|
79
79
|
'quilt_history tells you who changed which file, when, with the diff: read it for the files you are about to touch. ' +
|
|
80
|
-
'
|
|
81
|
-
'Do not edit files someone else has claimed: ask for the file in its file queue with quilt_request_file (a title and up to 300 characters on what you plan), and you are handed it with context when they are done. ' +
|
|
82
|
-
'When someone waits in the queue for a file you hold, finish your change and hand it off with quilt_handoff and your context; you cannot finish or release it before. Claim ahead only for a larger change across several files. Always re-read a file right before editing it. ' +
|
|
80
|
+
'Nobody holds files: 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. Always re-read a file right before editing it. ' +
|
|
83
81
|
TASK_WORKFLOW
|
|
84
82
|
|
|
85
83
|
export const HOSTED_INSTRUCTIONS =
|
|
86
84
|
'You are an AI agent in Quilt, where people and agents build one project together in real time. ' +
|
|
87
85
|
'Join a session with quilt_join_session and the invite link you were given; the session owner may have to let you in first ' +
|
|
88
86
|
'(quilt_session_info tells you). Then: quilt_status to see who is doing what, quilt_list_files and quilt_read_file to look ' +
|
|
89
|
-
'around, quilt_write_file to change a file (
|
|
87
|
+
'around, quilt_write_file to change a file (read it right before, and give the version quilt_read_file ends with as base), quilt_share to ' +
|
|
90
88
|
'tell everyone what you are doing, and quilt_message to talk. The shared task board is quilt_tasks, quilt_add_task, quilt_assign_task and quilt_move_task; quilt_task reads one in full with its comments, and quilt_comment_task leaves a work note or handoff on it. ' +
|
|
91
89
|
'quilt_history tells you who changed which file, when, with the diff: read it for the files you are about to touch. ' +
|
|
92
|
-
'
|
|
93
|
-
'When someone waits in the queue for a file you hold, every answer says so: finish your change, then hand it off with quilt_handoff and your context (what you changed, what is left). You cannot finish a task or release the file before. A claim whose holder does nothing for 20 minutes goes to the next in its queue. ' +
|
|
90
|
+
'Nobody holds files: no write is refused because someone else is working on a file. Your write merges with what others changed elsewhere in it; if it clashes with someone\'s on the same lines, Quilt tells you and you resolve it. ' +
|
|
94
91
|
'Read what people said about a file before you change it: quilt_read_messages, and each write tells you what was said about that file. ' +
|
|
95
|
-
'This rule is enforced for agents: while someone who messaged or mentioned you waits for an answer, writes
|
|
92
|
+
'This rule is enforced for agents: while someone who messaged or mentioned you waits for an answer, writes and task changes are refused until you answer with quilt_message. ' +
|
|
96
93
|
PERSON_CHAT + ' ' +
|
|
97
94
|
'Everyone sees your changes on their own disk within moments. ' +
|
|
98
95
|
'Chat: ' + CHAT_RULES.replace(/^Send a chat message\. /, '') + ' A message that needs nothing back is settled with quilt_inbox (no_reply: [its id]), not answered. ' +
|
|
@@ -155,7 +152,7 @@ const cleanPath = (p) => String(p || '').trim().replace(/^\.\//, '').replace(/^\
|
|
|
155
152
|
|
|
156
153
|
/**
|
|
157
154
|
* The tools every relay-hosted MCP offers, on whatever room `ctx.room()` gives now.
|
|
158
|
-
* ctx: { room(), me, who(), access(), tool(), warn() }: `who` is what
|
|
155
|
+
* ctx: { room(), me, who(), access(), tool(), warn() }: `who` is what boxes belong to
|
|
159
156
|
* ({ name } or { name, id }), `access` the caller's role and folders, `warn` extra text
|
|
160
157
|
* for status, `withSession(fn)` runs a tool with the current room or explains why not.
|
|
161
158
|
*/
|
|
@@ -168,14 +165,7 @@ function sessionTools (server, ctx) {
|
|
|
168
165
|
if ((!n && !remind) || !r || !Array.isArray(r.content)) return r
|
|
169
166
|
return { ...r, content: [...r.content, ...(n ? [{ type: 'text', text: `⚠️ ${n}` }] : []), ...(remind ? [{ type: 'text', text: `⏰ ${remind}` }] : [])] }
|
|
170
167
|
}
|
|
171
|
-
//
|
|
172
|
-
const queueNote = (room, r) => {
|
|
173
|
-
if (r && typeof r.then === 'function') return r.then((x) => queueNote(room, x))
|
|
174
|
-
const n = renderQueueNotice(queuedFor(claimsOf(room), me))
|
|
175
|
-
if (!n || !r || !Array.isArray(r.content)) return r
|
|
176
|
-
return { ...r, content: [...r.content, { type: 'text', text: `📥 ${n}` }] }
|
|
177
|
-
}
|
|
178
|
-
// Files, claims and history are a branch's: the agent's own (hosted agents can choose one), or the session's active branch.
|
|
168
|
+
// Files and history are a branch's: the agent's own (hosted agents can choose one), or the session's active branch.
|
|
179
169
|
const branchOf = (room) => ctx.branch ? ctx.branch(room) : room.activeBranch ? room.activeBranch() : null
|
|
180
170
|
// The branch document the agent works on (its store entry), or null for a room without branch documents.
|
|
181
171
|
// The session's default branch may always start; any other new branch only for someone who may change files.
|
|
@@ -186,6 +176,26 @@ function sessionTools (server, ctx) {
|
|
|
186
176
|
const editor = room.resolveKey(key) === room.defaultKey || ctx.access(room)?.role !== 'viewer'
|
|
187
177
|
return room.branchDoc(key, { by: me, editor })
|
|
188
178
|
}
|
|
179
|
+
// Every open held conflict in the session (held.js) heads every answer, to every AI, until someone resolves it.
|
|
180
|
+
const heldNote = (room, r) => {
|
|
181
|
+
if (r && typeof r.then === 'function') return r.then((x) => heldNote(room, x))
|
|
182
|
+
const n = room && room.doc ? renderHeld(readHeld(room.doc.getMap(HELD_MAP)), { me }) : ''
|
|
183
|
+
if (!n || !r || !Array.isArray(r.content)) return r
|
|
184
|
+
return { ...r, content: [{ type: 'text', text: n }, ...r.content] }
|
|
185
|
+
}
|
|
186
|
+
// The live-write engine (live-merge.js) for one hosted write or sync: held conflicts go to the room's
|
|
187
|
+
// document, the owner's stale_write_minutes applies, and what the writer must hear lands in `notices`.
|
|
188
|
+
// `folder`: the writer has a folder that gets the result (quilt sync's); a hosted write has none.
|
|
189
|
+
const liveRules = (room, files, notices = [], { folder = true } = {}) => new LiveRules({
|
|
190
|
+
room: () => room.doc,
|
|
191
|
+
staleMinutes: () => staleWriteMinutes(room.doc, room.memberList ? room.memberList() : []),
|
|
192
|
+
notice: (t) => notices.push(t),
|
|
193
|
+
texts: function * () { for (const [p, t] of files) if (t && isSafeRelPath(p)) yield [p, t.toString()] },
|
|
194
|
+
origin: AGENT,
|
|
195
|
+
folder
|
|
196
|
+
})
|
|
197
|
+
// Who this agent is, for what it last read of each file (read-bases.js).
|
|
198
|
+
const readerId = (room) => (ctx.who(room) && ctx.who(room).id) || me
|
|
189
199
|
const tool = (name, def, fn) => server.registerTool(name, ctx.multi ? { ...def, inputSchema: { ...(def.inputSchema || {}), session: SESSION_ARG } } : def, async (given) => {
|
|
190
200
|
// Hosted agents are in several sessions at once: `session` says which this call is about.
|
|
191
201
|
const { session, ...args } = given || {}
|
|
@@ -193,9 +203,7 @@ function sessionTools (server, ctx) {
|
|
|
193
203
|
// A session that is a quilt has no GitHub path for agents: each GitHub tool names its Seam tool.
|
|
194
204
|
// At layout 3 its files are in squares, not branches: the file tools name Seam's (quilt_history reads Seam's log, quilt_project_rules main's rules).
|
|
195
205
|
const quilt = quiltName(room)
|
|
196
|
-
|
|
197
|
-
const seamRelease = name === 'quilt_release' && !!(ctx.seam && ctx.seam())
|
|
198
|
-
const refused = seamRefusal(name, quilt, { hosted: true }) || (quilt && room.meta.layout === LAYOUT_QUILT && FILE_TOOLS.has(name) && name !== 'quilt_history' && name !== 'quilt_project_rules' && !seamRelease ? seamFileRefusal(quilt) : null)
|
|
206
|
+
const refused = seamRefusal(name, quilt, { hosted: true }) || (quilt && room.meta.layout === LAYOUT_QUILT && FILE_TOOLS.has(name) && name !== 'quilt_history' && name !== 'quilt_project_rules' ? seamFileRefusal(quilt) : null)
|
|
199
207
|
if (refused) return fail(refused)
|
|
200
208
|
// A hosted agent with no branch of its own is pinned to the active branch by its first call
|
|
201
209
|
// on files, so a read and the write after it never land on two different branches.
|
|
@@ -215,10 +223,12 @@ function sessionTools (server, ctx) {
|
|
|
215
223
|
const prev = room.auditAs
|
|
216
224
|
room.auditAs = caller && caller.id
|
|
217
225
|
try {
|
|
218
|
-
const r =
|
|
226
|
+
const r = fn(args || {}, parts)
|
|
219
227
|
// The first answer in a session that is a quilt says how work lands there (quilt_status always does).
|
|
220
228
|
const once = quilt && ctx.seamOnce ? ctx.seamOnce(room) : false
|
|
221
|
-
|
|
229
|
+
// quilt_sync answers JSON for `quilt sync` to read: the open conflicts go inside it (`open`), not before it.
|
|
230
|
+
if (name === 'quilt_sync') return r
|
|
231
|
+
return heldNote(room, name === 'quilt_status' && quilt ? withSeamNote(r, quilt) : once ? withSeamLead(r, quilt) : r)
|
|
222
232
|
} finally { room.auditAs = prev }
|
|
223
233
|
}, session))
|
|
224
234
|
})
|
|
@@ -245,9 +255,9 @@ function sessionTools (server, ctx) {
|
|
|
245
255
|
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 })
|
|
246
256
|
return out
|
|
247
257
|
}
|
|
248
|
-
//
|
|
249
|
-
const
|
|
250
|
-
//
|
|
258
|
+
// 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.
|
|
259
|
+
const boxesOf = (room) => (room.boxList ? room.boxList(branchOf(room)) : []).map((c) => (c.of ? { ...c, by: c.of } : c))
|
|
260
|
+
// Boxes are per branch: who the agent is, on the branch it works on.
|
|
251
261
|
const who = (room) => ({ ...ctx.who(room), branch: branchOf(room) })
|
|
252
262
|
// The rules every agent is held to (duties.js), enforced here because hosted agents work through these tools.
|
|
253
263
|
const seen = (doc) => doc.getArray('chat').toArray().filter(visible)
|
|
@@ -273,35 +283,6 @@ function sessionTools (server, ctx) {
|
|
|
273
283
|
if (!Array.isArray(box.told)) box.told = []
|
|
274
284
|
return box
|
|
275
285
|
}
|
|
276
|
-
// Claims follow this agent's writes: a file it changes that nobody holds is claimed for it, and let
|
|
277
|
-
// go when it hasn't written the file for a while (it has no end of turn Quilt can see).
|
|
278
|
-
const autoHeld = new Map() // `${roomId}\0${rel}` -> timer
|
|
279
|
-
// Boxes opened when a commit to the branch's repository landed: no session commits to git now.
|
|
280
|
-
const boxable = () => false
|
|
281
|
-
const roomKey = (room) => `${room.id || room.name || ''}\0${branchOf(room)}` // claims held per branch
|
|
282
|
-
const autoClaim = (room, rel) => {
|
|
283
|
-
const key = `${roomKey(room)}\0${rel}`
|
|
284
|
-
const branch = branchOf(room) // released on this branch, even if the agent has moved on since
|
|
285
|
-
clearTimeout(autoHeld.get(key))
|
|
286
|
-
// A box (docs/superpowers/specs/2026-10-16-git-boxes-design.md) where a commit can open it: a branch that follows
|
|
287
|
-
// a repository. Our own claim with no box (claimed ahead, or unpacked) boxes again with the next write.
|
|
288
|
-
const box = boxable(room, branch)
|
|
289
|
-
const own = claimsOf(room).find((c) => c.pattern === rel && c.by === me)
|
|
290
|
-
if (!autoHeld.has(key) || (box && own && !own.box && !own.clash)) {
|
|
291
|
-
try { room.claimRequest({ ...who(room), talk: ctx.access(room)?.talk !== false }, { op: 'claim', pattern: rel, note: 'editing', ...(box ? { box: true } : {}) }) } catch { return false }
|
|
292
|
-
room.broadcastClaims()
|
|
293
|
-
}
|
|
294
|
-
const timer = setTimeout(() => {
|
|
295
|
-
autoHeld.delete(key)
|
|
296
|
-
// Held for a clash's merge (relay-upstream.js) is not a claim that followed a write: it stays until the merge is done.
|
|
297
|
-
// A box isn't let go of after a quiet while either: it opens when it's committed or unpacked.
|
|
298
|
-
if (!(room.claimList ? room.claimList(branch) : []).some((c) => c.pattern === rel && c.by === me && !c.clash && !c.box)) return
|
|
299
|
-
try { room.claimRequest({ ...ctx.who(room), branch }, { op: 'release', pattern: rel }); room.broadcastClaims() } catch {}
|
|
300
|
-
}, HOSTED_AUTO_CLAIM_QUIET_MS)
|
|
301
|
-
if (timer.unref) timer.unref()
|
|
302
|
-
autoHeld.set(key, timer)
|
|
303
|
-
return true
|
|
304
|
-
}
|
|
305
286
|
// One chronology writer per branch document, shared by every hosted agent's connection.
|
|
306
287
|
const historyOf = (room) => {
|
|
307
288
|
const b = branchEntry(room) || room
|
|
@@ -337,12 +318,12 @@ function sessionTools (server, ctx) {
|
|
|
337
318
|
})
|
|
338
319
|
|
|
339
320
|
tool('quilt_status', {
|
|
340
|
-
description: 'See who else is in the live session, what they and their AIs are doing, recent file changes,
|
|
321
|
+
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.',
|
|
341
322
|
inputSchema: {}
|
|
342
323
|
}, (_, { room, doc, chat, activity }) => {
|
|
343
324
|
const a = ctx.access(room)
|
|
344
325
|
const lines = [`You are ${me} in a live quilt session (room ${room.name}).`]
|
|
345
|
-
if (a && a.role === 'viewer') lines.push('You may only view this session: reading
|
|
326
|
+
if (a && a.role === 'viewer') lines.push('You may only view this session: reading and chat work, file changes are refused.')
|
|
346
327
|
else if (a && a.scopes && a.scopes.length) lines.push(`You may change files only in: ${a.scopes.join(', ')}.`)
|
|
347
328
|
if (a && a.scopesExcept && a.scopesExcept.length && a.role !== 'viewer') lines.push(`You may not change files in: ${a.scopesExcept.join(', ')}.`)
|
|
348
329
|
if (a && a.talk === false) lines.push("You may not post in this session: quilt_message and quilt_share are refused.")
|
|
@@ -363,11 +344,8 @@ function sessionTools (server, ctx) {
|
|
|
363
344
|
if (agents.length) lines.push('', '## Agents and how Quilt wakes them', ...agents.map((m) => `- ${m.name}: ${m.wake || 'not known yet'}`))
|
|
364
345
|
const away = room.memberList ? room.memberList().filter((m) => m.away && m.name !== me && !ps.some((p) => p.name === m.name)) : []
|
|
365
346
|
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)}`))
|
|
366
|
-
const
|
|
367
|
-
const bxs = all.filter((c) => c.box)
|
|
347
|
+
const bxs = boxesOf(room)
|
|
368
348
|
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`}`))
|
|
369
|
-
const cl = all.filter((c) => !c.box)
|
|
370
|
-
lines.push('', '## Claimed files', ...(cl.length ? cl.map((c) => `- ${c.pattern} by ${c.by}${c.note ? ` (${c.note})` : ''}${c.queue.length ? ` · waiting: ${c.queue.map((r) => `${r.by} ("${r.title}")`).join(', ')}` : ''}`) : ['- None.']))
|
|
371
349
|
const acts = activity.toArray().filter(Boolean).slice(-12).reverse()
|
|
372
350
|
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.']))
|
|
373
351
|
const msgs = chat.toArray().filter(visible).slice(-8)
|
|
@@ -408,6 +386,44 @@ function sessionTools (server, ctx) {
|
|
|
408
386
|
return `${label ? `Assigned to ${label}.` : 'Unassigned.'}${files}`
|
|
409
387
|
}
|
|
410
388
|
|
|
389
|
+
tool('quilt_resolve_merge', {
|
|
390
|
+
description: RESOLVE_DESCRIPTION,
|
|
391
|
+
inputSchema: {
|
|
392
|
+
path: z.string().max(1024).optional().describe('The file whose held conflict to resolve (the oldest open one for it)'),
|
|
393
|
+
id: z.string().max(40).optional().describe('The held conflict\'s id, as the list at the top of every answer shows it'),
|
|
394
|
+
how: z.enum(['theirs', 'mine', 'edited']).optional().describe('theirs: drop the held lines (the file stays as it is). mine: put the held lines over the shared ones. edited: you already wrote the resolved file. Omit to see the conflict in full.')
|
|
395
|
+
}
|
|
396
|
+
}, ({ path: p, id: ref0, how }, { room, doc, fdoc, branch, files }) => {
|
|
397
|
+
const map = doc.getMap(HELD_MAP)
|
|
398
|
+
const ref = ref0 || cleanPath(p)
|
|
399
|
+
if (!ref) return text(readHeld(map).filter((r) => r.state === 'open').map(describeHeld).join('\n\n') || 'There are no open held conflicts in this session.')
|
|
400
|
+
const rec = findHeld(map, ref)
|
|
401
|
+
if (!rec) return fail(`There is no held conflict for ${ref}.`)
|
|
402
|
+
if (!how) return text(describeHeld(rec))
|
|
403
|
+
if (rec.state === 'resolved') return text(`${rec.path} (id ${rec.id}) was already resolved${rec.resolvedBy ? ` by ${rec.resolvedBy}` : ''}${rec.how ? ` ("${rec.how}")` : ''}. Nothing changed.`)
|
|
404
|
+
const a = ctx.access(room)
|
|
405
|
+
if (a && a.role === 'viewer') return fail('You can only view this session; resolving a conflict is refused.')
|
|
406
|
+
if (how === 'mine') {
|
|
407
|
+
// On the relay, only in the branch document this agent works on; a square's file is resolved from a folder on it.
|
|
408
|
+
if (!branch || !rec.where.branch || room.resolveKey(rec.where.branch) !== room.resolveKey(branch.key)) return fail(`${rec.path} was held on ${rec.where.square ? 'a square' : `branch ${rec.where.branch || 'another branch'}`}, not where you work: write the file yourself (quilt_write_file) and resolve it "edited", or ask ${rec.by} to resolve it "mine".`)
|
|
409
|
+
const refusal = a && changeRefusal(a, rec.path)
|
|
410
|
+
if (refusal) return fail(`${refusal[0].toUpperCase()}${refusal.slice(1)}.`)
|
|
411
|
+
if (typeof rec.mine !== 'string') return fail(`${rec.path}'s held lines are only on ${rec.by}'s computer: write the file yourself and resolve it "edited", or ask ${rec.by}.`)
|
|
412
|
+
const t = files.get(rec.path)
|
|
413
|
+
const next = applyMine(rec, t ? t.toString() : null)
|
|
414
|
+
fdoc.transact(() => doc.transact(() => {
|
|
415
|
+
let yt = files.get(rec.path)
|
|
416
|
+
if (!yt) { yt = new Y.Text(); files.set(rec.path, yt) }
|
|
417
|
+
const before = yt.toString()
|
|
418
|
+
applyLineDiff(yt, next)
|
|
419
|
+
historyOf(room).record({ by: me, path: rec.path, kind: 'edited', before, after: next, task: currentTask(readTasks(taskMap(doc)), me) })
|
|
420
|
+
}, AGENT), AGENT)
|
|
421
|
+
}
|
|
422
|
+
const r = settleHeld(doc, map, rec.id, { how, by: me }, AGENT)
|
|
423
|
+
if (r.already) return text(`${rec.path} (id ${rec.id}) was already resolved by ${r.record.resolvedBy || 'someone'}. Nothing changed.`)
|
|
424
|
+
return text(`Resolved ${rec.path} (id ${rec.id}): ${how === 'theirs' ? 'the held lines are dropped and the file stays as it is' : how === 'mine' ? 'the held lines went into the file; everyone has it now' : 'the file is taken as you wrote it'}.`)
|
|
425
|
+
})
|
|
426
|
+
|
|
411
427
|
tool('quilt_tasks', {
|
|
412
428
|
description: 'List the shared task board (To do, In progress, QA, Done), with an id on each task. Open tasks assigned to you are listed first.',
|
|
413
429
|
inputSchema: {
|
|
@@ -468,7 +484,7 @@ function sessionTools (server, ctx) {
|
|
|
468
484
|
return projectRules({ list, read: (p) => got.get(p) ?? null })
|
|
469
485
|
}
|
|
470
486
|
tool('quilt_move_task', {
|
|
471
|
-
description: 'Move a task on the shared board. "doing" when you start it: you get a briefing (its files, recent changes to them,
|
|
487
|
+
description: 'Move a task on the shared board. "doing" when you start it: you get a briefing (its files, recent changes to them, the project\'s checks). ' +
|
|
472
488
|
'"qa" when you finish implementing and testing: requires `qaNotes` (what changed and how you self-validated); without it the move is refused. ' +
|
|
473
489
|
'"done" after QA: requires `verified`, what you ran and what you saw; without it the move is refused.',
|
|
474
490
|
inputSchema: {
|
|
@@ -486,7 +502,6 @@ function sessionTools (server, ctx) {
|
|
|
486
502
|
if (!cur) return fail('no such task')
|
|
487
503
|
if (column === 'qa' && !qaNotesEnough(qaNotes)) return fail(qaRefusal({ task: cur, checklist: await checklistOf(files, room, branch) }))
|
|
488
504
|
if (column === 'done' && !verifiedEnough(verified)) return fail(doneRefusal({ task: cur, checklist: await checklistOf(files, room, branch) }))
|
|
489
|
-
{ const q = (column === 'done' || column === 'qa') && renderQueued(queuedFor(claimsOf(room), me), 'move the task again'); if (q) return fail(q) }
|
|
490
505
|
const patch = { id, column }
|
|
491
506
|
if (column === 'qa') patch.qaNotes = qaNotes
|
|
492
507
|
if (column === 'done') patch.verified = verified
|
|
@@ -495,9 +510,8 @@ function sessionTools (server, ctx) {
|
|
|
495
510
|
const tf = task.files || []
|
|
496
511
|
const all = historyOf(room).entries()
|
|
497
512
|
const history = (tf.length ? all.filter((e) => tf.includes(e.path)) : all).slice(-8)
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
return text(pickupBrief({ task: { ...task, comments: readComments(doc.getMap('taskComments'), task.id) }, history, claims, checklist: await checklistOf(files, room, branchEntry(room)), me }))
|
|
513
|
+
if (quiltOf(room.meta)) return text(pickupBrief({ task: { ...task, comments: readComments(doc.getMap('taskComments'), task.id) }, history, checklist: await checklistOf(files, room, null), me, workflow: seamWorkflow(TASK_WORKFLOW, { hosted: true }) }))
|
|
514
|
+
return text(pickupBrief({ task: { ...task, comments: readComments(doc.getMap('taskComments'), task.id) }, history, checklist: await checklistOf(files, room, branchEntry(room)), me }))
|
|
501
515
|
}
|
|
502
516
|
if (column === 'qa') return text(`Moved "${task.title}" to QA. Notes: ${qaNotesLine(task)}`)
|
|
503
517
|
if (column === 'done') return text(`Moved "${task.title}" to Done. Verified: ${verifiedLine(task)}`)
|
|
@@ -779,17 +793,17 @@ function sessionTools (server, ctx) {
|
|
|
779
793
|
})
|
|
780
794
|
|
|
781
795
|
tool('quilt_list_files', {
|
|
782
|
-
description: 'List the shared project files with
|
|
796
|
+
description: 'List the shared project files, with whose unfinished work is boxed on any of them.',
|
|
783
797
|
inputSchema: { under: z.string().optional().describe('Only files under this folder') }
|
|
784
798
|
}, async ({ under }, { room, files, blobs, branch }) => {
|
|
785
799
|
const pre = under ? cleanPath(under).replace(/\/+$/, '') + '/' : ''
|
|
786
|
-
const
|
|
800
|
+
const bx = new Map(boxesOf(room).map((c) => [c.pattern, c]))
|
|
787
801
|
let all
|
|
788
802
|
try { all = branch && isDiff(branch) ? [...(await listPaths(room, branch.key, branch)).keys()] : [...files.keys(), ...blobs.keys()] } catch (err) { return fail(err.message) }
|
|
789
803
|
const paths = [...new Set(all)].filter((p) => isSafeRelPath(p) && (!pre || p.startsWith(pre))).sort()
|
|
790
804
|
const shown = paths.slice(0, 500).map((p) => {
|
|
791
|
-
const c =
|
|
792
|
-
return `- ${p}${c ? ` (
|
|
805
|
+
const c = bx.get(p)
|
|
806
|
+
return `- ${p}${c ? ` (boxed by ${c.by}: their unfinished work)` : ''}`
|
|
793
807
|
})
|
|
794
808
|
return text(paths.length ? shown.join('\n') + (paths.length > 500 ? `\n… and ${paths.length - 500} more` : '') : 'No files.')
|
|
795
809
|
})
|
|
@@ -802,14 +816,19 @@ function sessionTools (server, ctx) {
|
|
|
802
816
|
})
|
|
803
817
|
|
|
804
818
|
tool('quilt_read_file', {
|
|
805
|
-
description: 'Read a shared project file as text, as it is right now.',
|
|
819
|
+
description: 'Read a shared project file as text, as it is right now. The answer ends with the version you read: give it to quilt_write_file as `base`, so your write is merged with whatever others changed since.',
|
|
806
820
|
inputSchema: { path: z.string().min(1).max(500).describe('Relative path, e.g. src/app.ts') }
|
|
807
821
|
}, async ({ path: p }, { room, files, blobs, branch }) => {
|
|
808
822
|
const rel = cleanPath(p)
|
|
809
823
|
if (!isSafeRelPath(rel)) return fail('That is not a path inside the project.')
|
|
810
|
-
const bx =
|
|
811
|
-
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;
|
|
812
|
-
|
|
824
|
+
const bx = boxesOf(room).find((c) => c.by !== me && c.pattern === rel)
|
|
825
|
+
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` : ''
|
|
826
|
+
// 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.
|
|
827
|
+
const shown = (s) => {
|
|
828
|
+
const version = readBasesOf(room).note(readerId(room), branch ? branch.key : '', rel, s)
|
|
829
|
+
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)
|
|
830
|
+
return { content: [{ type: 'text', text: body }, { type: 'text', text: `(Version ${version}: pass it to quilt_write_file as base.)` }] }
|
|
831
|
+
}
|
|
813
832
|
if (branch && isDiff(branch)) {
|
|
814
833
|
// A diff branch: the session's version, else git's at the branch's commit (branch-view.js).
|
|
815
834
|
let r
|
|
@@ -829,28 +848,33 @@ function sessionTools (server, ctx) {
|
|
|
829
848
|
|
|
830
849
|
tool('quilt_write_file', {
|
|
831
850
|
description: 'Write a text file in the shared project (new or existing): everyone gets it on their disk within moments. ' +
|
|
832
|
-
'Give the whole file
|
|
851
|
+
'Give the whole file and, as base, the version quilt_read_file gave you: your write is merged against what you read, so changes others made since, anywhere in the file, survive. ' +
|
|
852
|
+
'Without base it is merged against the version you last read; a version Quilt no longer has is merged as a stale write (lines anyone added lately stay, and you are told). Where someone changed the same lines first, the file keeps theirs and your lines are held for you to resolve (quilt_resolve_merge).',
|
|
833
853
|
inputSchema: {
|
|
834
854
|
path: z.string().min(1).max(500).describe('Relative path, e.g. src/app.ts'),
|
|
835
|
-
content: z.string().max(MAX_WRITE_BYTES).describe('The whole new contents of the file')
|
|
855
|
+
content: z.string().max(MAX_WRITE_BYTES).describe('The whole new contents of the file'),
|
|
856
|
+
base: z.string().max(64).optional().describe('The version you read (quilt_read_file ends with it): what your content was made from')
|
|
836
857
|
}
|
|
837
|
-
}, async ({ path: p, content }, { room, doc, fdoc, branch, files, blobs, activity }) => {
|
|
858
|
+
}, async ({ path: p, content, base: version }, { room, doc, fdoc, branch, files, blobs, activity }) => {
|
|
838
859
|
{ const w = waitRefusal(doc, 'quilt_write_file', room); if (w) return fail(w) }
|
|
839
860
|
const err = writable(room) || branchWritable(room, branch)
|
|
840
861
|
if (err) return fail(err)
|
|
841
|
-
|
|
862
|
+
let rel = cleanPath(p)
|
|
842
863
|
if (!isSafeRelPath(rel)) return fail('That is not a path inside the project.')
|
|
843
864
|
const a = ctx.access(room)
|
|
844
865
|
if (a && a.role === 'viewer') return fail('You can only view this session; file changes are refused.')
|
|
866
|
+
// Every write is a live write (live-merge.js): merged against what this agent read, with the ways a clash is caught.
|
|
867
|
+
const notices = []
|
|
868
|
+
const rules = liveRules(room, files, notices, { folder: false })
|
|
869
|
+
// A file another member moved (deleted it and added the same text elsewhere) lately: the edit goes where it went.
|
|
870
|
+
let moved = null
|
|
871
|
+
if (!files.has(rel) && !blobs.has(rel) && !(branch && isDiff(branch) && hasEntry(branch, rel))) {
|
|
872
|
+
const mv = rules.movedTo({ doc: fdoc, path: rel, by: me })
|
|
873
|
+
if (mv && files.has(mv.to)) { moved = mv; rel = mv.to }
|
|
874
|
+
}
|
|
845
875
|
const refusal = a && changeRefusal(a, rel)
|
|
846
876
|
if (refusal) return fail(`${refusal[0].toUpperCase()}${refusal.slice(1)}.`)
|
|
847
|
-
const claim = claimsOf(room).find((c) => c.by !== me && globMatcher(c.pattern)(rel))
|
|
848
|
-
if (claim) return fail(heldRefusal(rel, claim))
|
|
849
877
|
if (blobs.get(rel)?.stored) return fail(`${rel} is a large file kept in storage; it can't be changed here.`)
|
|
850
|
-
const held = claimsOf(room).some((c) => c.by === me && globMatcher(c.pattern)(rel))
|
|
851
|
-
const claimedNow = !held && autoClaim(room, rel)
|
|
852
|
-
const unboxed = held && boxable(room, branchOf(room)) && claimsOf(room).some((c) => c.by === me && c.pattern === rel && !c.box && !c.clash)
|
|
853
|
-
if (held && (autoHeld.has(`${roomKey(room)}\0${rel}`) || unboxed)) autoClaim(room, rel) // still writing it: keep holding (in a box)
|
|
854
878
|
if (Buffer.byteLength(content, 'utf8') > MAX_WRITE_BYTES) return fail('That file is too big to write here (1 MB at most).')
|
|
855
879
|
// A diff branch: a file the session hasn't changed is git's, so the edit starts from git's text (its history and line count say what really changed).
|
|
856
880
|
const diff = branch && isDiff(branch)
|
|
@@ -858,7 +882,27 @@ function sessionTools (server, ctx) {
|
|
|
858
882
|
if (diff && !hasEntry(branch, rel) && !branch.gone.has(rel)) {
|
|
859
883
|
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) }
|
|
860
884
|
}
|
|
861
|
-
|
|
885
|
+
// Someone else's unfinished work boxed on it: the write is never refused; the box opens, so their
|
|
886
|
+
// work and this change reach every folder together (the write merges with what the file has now).
|
|
887
|
+
const opened = boxesOf(room).find((c) => c.by !== me && c.pattern === rel)
|
|
888
|
+
if (opened) { try { room.boxRequest({ ...who(room), talk: ctx.access(room)?.talk !== false }, { op: 'unbox', pattern: rel, edit: true }); room.broadcastBoxes() } catch {} }
|
|
889
|
+
// The merge, in one step with the write (nothing awaits between them): what the file holds now, against
|
|
890
|
+
// the version this agent's content was made from. Same lines changed first keep theirs; this agent's are held.
|
|
891
|
+
const bases = readBasesOf(room)
|
|
892
|
+
const branchKey = branch ? branch.key : ''
|
|
893
|
+
const cur = files.has(rel) ? files.get(rel).toString() : fromGit
|
|
894
|
+
const known = moved ? { text: moved.text, from: 'given' } : bases.base(readerId(room), branchKey, rel, { version, current: cur })
|
|
895
|
+
const where = branch ? { branch: branch.key } : {}
|
|
896
|
+
const lastBy = activity.toArray().reverse().find((e) => e && e.path === rel && (!branch || !e.branch || e.branch === branch.key))?.by || null
|
|
897
|
+
let next = content
|
|
898
|
+
let merged = null
|
|
899
|
+
// A base not known for sure (a version no longer kept, or nothing read): merged as a stale write, so the
|
|
900
|
+
// lines anyone added lately stay, this agent's own included (another of its loops may have added them).
|
|
901
|
+
const strict = known.from === 'unknown' || known.from === 'none'
|
|
902
|
+
if (typeof cur === 'string') {
|
|
903
|
+
merged = rules.write({ doc: fdoc, where, path: rel, base: typeof known.text === 'string' ? known.text : cur, ours: content, theirs: cur, by: me, byId: readerId(room), others: lastBy && lastBy !== me ? [lastBy] : [], strict })
|
|
904
|
+
next = merged.text
|
|
905
|
+
} else rules.write({ doc: fdoc, where, path: rel, ours: content, by: me }) // a new file: its lines on record as this agent's
|
|
862
906
|
let detail = ''
|
|
863
907
|
let existed = false
|
|
864
908
|
fdoc.transact(() => doc.transact(() => {
|
|
@@ -868,12 +912,14 @@ function sessionTools (server, ctx) {
|
|
|
868
912
|
if (!ytext) { ytext = new Y.Text(); if (fromGit) ytext.insert(0, fromGit); files.set(rel, ytext) }
|
|
869
913
|
if (diff) notePresent(branch, rel, { base: baseOf(room, branch.key, branch) })
|
|
870
914
|
const before = ytext.toString()
|
|
871
|
-
detail =
|
|
915
|
+
detail = applyLineDiff(ytext, next)
|
|
872
916
|
const kind = existed ? 'edited' : 'created'
|
|
873
917
|
activity.push([{ by: me, path: rel, kind, detail, ...(branch ? { branch: branch.key } : {}), ts: Date.now() }])
|
|
874
918
|
if (activity.length > ACTIVITY_CAP) activity.delete(0, activity.length - ACTIVITY_CAP)
|
|
875
|
-
historyOf(room).record({ by: me, path: rel, kind, before, after:
|
|
919
|
+
historyOf(room).record({ by: me, path: rel, kind, before, after: next, task: currentTask(readTasks(taskMap(doc)), me) })
|
|
876
920
|
}, AGENT), AGENT)
|
|
921
|
+
// What the file holds now is what this agent knows of it: its next write's base.
|
|
922
|
+
const version2 = bases.note(readerId(room), branchKey, rel, next)
|
|
877
923
|
// What people said about this file in chat, so the agent works with it in mind (each message once).
|
|
878
924
|
const box = toldAbout(room)
|
|
879
925
|
const said = chatAbout([rel], { messages: seen(doc), me }).filter((m) => m.id && !box.told.includes(m.id))
|
|
@@ -882,64 +928,20 @@ function sessionTools (server, ctx) {
|
|
|
882
928
|
if (ctx.saveInbox) ctx.saveInbox()
|
|
883
929
|
}
|
|
884
930
|
const context = renderChatAbout(said)
|
|
885
|
-
|
|
931
|
+
const notes = []
|
|
932
|
+
if (moved) notes.push(`${moved.by} moved ${cleanPath(p)} to ${rel}: your edit went into ${rel}. Edit ${rel} from now on.`)
|
|
933
|
+
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'}, and lines anyone added in the last few minutes (yours included) were kept. Read the file again before your next write, and give its version as base.`)
|
|
934
|
+
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.`)
|
|
935
|
+
notes.push(...notices)
|
|
936
|
+
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}` : ''}`)
|
|
886
937
|
})
|
|
887
938
|
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
}, ({ pattern, note }, { room, doc }) => {
|
|
895
|
-
{ const w = waitRefusal(doc, 'quilt_claim', room); if (w) return fail(w) }
|
|
896
|
-
const err = writable(room)
|
|
897
|
-
if (err) return fail(err)
|
|
898
|
-
try {
|
|
899
|
-
// Someone who may not post keeps their claim but not its note, which everyone reads.
|
|
900
|
-
const r = room.claimRequest({ ...who(room), talk: ctx.access(room)?.talk !== false }, { op: 'claim', pattern: pattern.trim(), note: note || '' })
|
|
901
|
-
if (r.ok === false) return fail(r.error || 'Could not claim that.')
|
|
902
|
-
const key = `${roomKey(room)}\0${pattern.trim()}`
|
|
903
|
-
clearTimeout(autoHeld.get(key)); autoHeld.delete(key) // claimed on purpose now: kept until released
|
|
904
|
-
} catch (e) { return fail(e.message) }
|
|
905
|
-
room.broadcastClaims()
|
|
906
|
-
return text(`Claimed ${pattern.trim()}. Release it with quilt_release when done.`)
|
|
907
|
-
})
|
|
908
|
-
|
|
909
|
-
const releaseHostedInSeam = async (room, pattern) => {
|
|
910
|
-
const quilt = quiltName(room) && room.meta.quilt_id
|
|
911
|
-
const access = ctx.seam && ctx.seam()
|
|
912
|
-
if (!quilt || !access) return fail(seamFileRefusal(quiltName(room)))
|
|
913
|
-
try {
|
|
914
|
-
const asked = room.claimRequest(who(room), { op: 'quilt-claims' })
|
|
915
|
-
const { gone, ...r } = await releaseInSeam({ access, api: process.env.QUILT_SOURCE_URL, quilt, asked, pattern: pattern ? pattern.trim() : '*' })
|
|
916
|
-
if (gone.length) room.claimRequest(who(room), { op: 'quilt-released', ids: gone })
|
|
917
|
-
return text(releaseWords(r, { cli: 'quilt_release' }))
|
|
918
|
-
} catch (err) { return fail(err.message) }
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
tool('quilt_release', {
|
|
922
|
-
description: 'Release a claim (or all of your claims when no pattern is given).',
|
|
923
|
-
inputSchema: { pattern: z.string().optional() }
|
|
924
|
-
}, ({ pattern }, { room }) => {
|
|
925
|
-
// At layout 3 the claims are Seam's: the agent lets go of its own there, as itself.
|
|
926
|
-
if (room.meta.layout === LAYOUT_QUILT) return releaseHostedInSeam(room, pattern)
|
|
927
|
-
// Releasing everything keeps boxes: a box opens when it's committed (quilt_git_commit) or unpacked (quilt_unpack).
|
|
928
|
-
const mine = claimsOf(room).filter((c) => c.by === me && (pattern ? c.pattern === pattern.trim() : !c.box))
|
|
929
|
-
// A file someone waits for is handed off, not released.
|
|
930
|
-
const waited = mine.filter((c) => c.queue.length)
|
|
931
|
-
if (pattern && waited.length) return fail(renderQueued(queuedFor(waited, me), 'release the rest'))
|
|
932
|
-
const released = []
|
|
933
|
-
for (const c of mine.filter((x) => !x.queue.length)) {
|
|
934
|
-
try { room.claimRequest(who(room), { op: 'release', pattern: c.pattern }); released.push(c.pattern) } catch {}
|
|
935
|
-
const key = `${roomKey(room)}\0${c.pattern}`
|
|
936
|
-
clearTimeout(autoHeld.get(key)); autoHeld.delete(key)
|
|
937
|
-
}
|
|
938
|
-
if (released.length) room.broadcastClaims()
|
|
939
|
-
const boxes = pattern ? [] : claimsOf(room).filter((c) => c.by === me && c.box).map((c) => c.pattern)
|
|
940
|
-
return text((released.length ? `Released ${released.join(', ')}.` : 'Nothing to release.') + (waited.length ? ` Kept ${waited.map((c) => c.pattern).join(', ')}: someone is waiting for ${waited.length === 1 ? 'it' : 'them'}; hand off with quilt_handoff.` : '') +
|
|
941
|
-
(boxes.length ? ` Your boxed work stays boxed (${boxes.slice(0, 10).join(', ')}${boxes.length > 10 ? ', …' : ''}): commit it with quilt_git_commit, or quilt_unpack it.` : ''))
|
|
942
|
-
})
|
|
939
|
+
// Quilt holds no files (no-holds, 2026-11-13): the claim tools stay for one release so older agents
|
|
940
|
+
// don't fail, answer that there is nothing to claim, and change nothing.
|
|
941
|
+
const noHolds = (description, inputSchema) => ({ description: `${description} Quilt holds no files now: this changes nothing.`, inputSchema })
|
|
942
|
+
const anyPath = z.string().max(500).optional()
|
|
943
|
+
tool('quilt_claim', noHolds('No longer needed: nobody holds files.', { pattern: anyPath, note: z.string().max(500).optional() }), () => text(NO_HOLDS))
|
|
944
|
+
tool('quilt_release', noHolds('No longer needed: nobody holds files.', { pattern: anyPath }), () => text(NO_HOLDS))
|
|
943
945
|
|
|
944
946
|
tool('quilt_unpack', {
|
|
945
947
|
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). ' +
|
|
@@ -950,63 +952,18 @@ function sessionTools (server, ctx) {
|
|
|
950
952
|
const done = []
|
|
951
953
|
const not = []
|
|
952
954
|
for (const p of [...new Set(paths.map(cleanPath))]) {
|
|
953
|
-
const c =
|
|
955
|
+
const c = boxesOf(room).find((x) => x.pattern === p && x.by === me)
|
|
954
956
|
if (!c) { not.push(p); continue }
|
|
955
|
-
try { if (room.
|
|
957
|
+
try { if (room.boxRequest(who(room), { op: 'unbox', pattern: p }).unboxed) done.push(p); else not.push(p) } catch { not.push(p) }
|
|
956
958
|
}
|
|
957
|
-
if (done.length) room.
|
|
959
|
+
if (done.length) room.broadcastBoxes()
|
|
958
960
|
if (!done.length) return fail(`${not.join(', ')} ${not.length === 1 ? 'is' : 'are'} not boxed by you.`)
|
|
959
961
|
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(', ')}.` : ''}`)
|
|
960
962
|
})
|
|
961
963
|
|
|
962
|
-
tool('quilt_request_file', {
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
inputSchema: {
|
|
966
|
-
path: z.string().min(1).max(500).describe('The file you need, relative path'),
|
|
967
|
-
title: z.string().min(1).max(120).describe('What you will do, e.g. "Working on retry logic for task t-12"'),
|
|
968
|
-
description: z.string().max(300).optional().describe('Your plan in summary: what you want to change and why (300 characters at most)'),
|
|
969
|
-
task: z.string().max(80).optional().describe('The task id this is for, if any')
|
|
970
|
-
}
|
|
971
|
-
}, ({ path: p, title, description, task }, { room }) => {
|
|
972
|
-
const err = writable(room)
|
|
973
|
-
if (err) return fail(err)
|
|
974
|
-
try {
|
|
975
|
-
const r = room.claimRequest({ ...who(room), talk: ctx.access(room)?.talk !== false }, { op: 'request', path: cleanPath(p), title, description: description || '', task })
|
|
976
|
-
room.broadcastClaims()
|
|
977
|
-
return text(`Asked for ${cleanPath(p)}: you are number ${r.position} in the queue for ${r.pattern} (held by ${r.holder}). ${r.holder} is told; you will be handed it with their context. Carry on with other work.`)
|
|
978
|
-
} catch (e) { return fail(e.message) }
|
|
979
|
-
})
|
|
980
|
-
|
|
981
|
-
tool('quilt_handoff', {
|
|
982
|
-
description: 'Hand a file you hold to someone waiting for it in its file queue (the first, unless you name them), with your context: what you changed, what is left, anything they should know. ' +
|
|
983
|
-
'The claim becomes theirs and they get your context in a direct message. Required before you finish or release a file someone is waiting for.',
|
|
984
|
-
inputSchema: {
|
|
985
|
-
path: z.string().min(1).max(500).describe('The file (or the claimed pattern) to hand off'),
|
|
986
|
-
context: z.string().min(1).max(2000).describe('What you changed, what is left, gotchas'),
|
|
987
|
-
to: z.string().max(80).optional().describe('Who to hand it to (a name or request id); omit for the first in the queue')
|
|
988
|
-
}
|
|
989
|
-
}, ({ path: p, context, to }, { room }) => {
|
|
990
|
-
try {
|
|
991
|
-
const r = room.claimRequest(who(room), { op: 'handoff', pattern: cleanPath(p), context, to: to || '' })
|
|
992
|
-
const key = `${roomKey(room)}\0${r.pattern}`
|
|
993
|
-
clearTimeout(autoHeld.get(key)); autoHeld.delete(key)
|
|
994
|
-
room.broadcastClaims()
|
|
995
|
-
return text(`Handed ${r.pattern} to ${r.to} with your context.${r.waiting ? ` ${r.waiting} more waiting: ${r.to} hands it on next.` : ''}`)
|
|
996
|
-
} catch (e) { return fail(e.message) }
|
|
997
|
-
})
|
|
998
|
-
|
|
999
|
-
tool('quilt_withdraw_request', {
|
|
1000
|
-
description: 'Take back your request for a file (from quilt_request_file) when you no longer need it.',
|
|
1001
|
-
inputSchema: { path: z.string().min(1).max(500).describe('The file you asked for') }
|
|
1002
|
-
}, ({ path: p }, { room }) => {
|
|
1003
|
-
const rel = cleanPath(p)
|
|
1004
|
-
const mine = claimsOf(room).flatMap((c) => c.queue).filter((r) => r.by === me && r.path === rel)
|
|
1005
|
-
let n = 0
|
|
1006
|
-
for (const r of mine) n += room.claimRequest(who(room), { op: 'withdraw', request: r.id }).withdrawn || 0
|
|
1007
|
-
if (n) room.broadcastClaims()
|
|
1008
|
-
return text(n ? `Withdrew your request for ${rel}.` : `You had not asked for ${rel}.`)
|
|
1009
|
-
})
|
|
964
|
+
tool('quilt_request_file', noHolds('No longer needed: nobody holds files, so edit the file instead.', { path: anyPath, title: z.string().max(120).optional(), description: z.string().max(300).optional(), task: z.string().max(80).optional() }), () => text(NO_HOLDS))
|
|
965
|
+
tool('quilt_handoff', noHolds('No longer needed for files: nobody holds them. To hand on a task, use quilt_comment_task and quilt_assign_task.', { path: anyPath, context: z.string().max(2000).optional(), to: z.string().max(80).optional() }), () => text(NO_HOLDS))
|
|
966
|
+
tool('quilt_withdraw_request', noHolds('No longer needed: there is no file queue.', { path: anyPath }), () => text(NO_HOLDS))
|
|
1010
967
|
|
|
1011
968
|
// `quilt sync` (npx heyquilt sync): a sandboxed agent's folder in one shot, its sync state kept
|
|
1012
969
|
// here (relay-turn-sync.js). Hosted only: the CLI reaches it with the agent's QUILT_AGENT_KEY.
|
|
@@ -1056,8 +1013,7 @@ function sessionTools (server, ctx) {
|
|
|
1056
1013
|
if (a && a.role === 'viewer') return { kind: 'aside', why: 'you can only view this session' }
|
|
1057
1014
|
const scope = a && changeRefusal(a, rel)
|
|
1058
1015
|
if (scope) return { kind: 'aside', why: scope }
|
|
1059
|
-
|
|
1060
|
-
return claim ? { kind: 'claimed', why: heldRefusal(rel, claim), by: claim.by } : null
|
|
1016
|
+
return null // nobody holds files: only access keeps a write out
|
|
1061
1017
|
},
|
|
1062
1018
|
record: ({ rel, kind, before, after, detail }) => {
|
|
1063
1019
|
activity.push([{ by: me, path: rel, kind, detail: detail || '', ...(branch ? { branch: branch.key } : {}), ts: Date.now() }])
|
|
@@ -1065,10 +1021,15 @@ function sessionTools (server, ctx) {
|
|
|
1065
1021
|
historyOf(room).record({ by: me, path: rel, kind, before, after, detail, task: currentTask(readTasks(taskMap(doc)), me) })
|
|
1066
1022
|
},
|
|
1067
1023
|
lastEditor: (rel) => activity.toArray().reverse().find((e) => e && e.path === rel && (!branch || !e.branch || e.branch === branch.key))?.by || null,
|
|
1068
|
-
// Others' boxes: their unfinished work stays out of this folder (relay-turn-sync.js).
|
|
1069
|
-
ghosts: new Set(
|
|
1024
|
+
// Others' boxes: their unfinished work stays out of this folder until this folder changes the file (relay-turn-sync.js).
|
|
1025
|
+
ghosts: new Set(boxesOf(room).filter((c) => c.by !== me).map((c) => c.pattern)),
|
|
1026
|
+
openBox: (rel) => { try { room.boxRequest({ ...who(room), talk: a?.talk !== false }, { op: 'unbox', pattern: rel, edit: true }); room.broadcastBoxes() } catch {} },
|
|
1027
|
+
// A push is a live write: the same engine as every other (held conflicts for this agent to resolve).
|
|
1028
|
+
rules: liveRules(room, files)
|
|
1070
1029
|
})
|
|
1071
|
-
|
|
1030
|
+
// Every open held conflict in the session, as every other answer starts with it (`quilt sync` prints it first).
|
|
1031
|
+
const open = args.step === 'done' ? renderHeld(readHeld(doc.getMap(HELD_MAP)), { me }) : ''
|
|
1032
|
+
return text(JSON.stringify({ ...answer, branch: key === DEFAULT_KEY ? room.defaultKey : key, ...(open ? { open } : {}) }))
|
|
1072
1033
|
} catch (e) { return fail(e.message) }
|
|
1073
1034
|
})
|
|
1074
1035
|
}
|
|
@@ -1458,10 +1419,9 @@ export async function handleHostedMcp ({ req, res, pass, relay, workspaces = nul
|
|
|
1458
1419
|
room.hostedSeen.delete(account)
|
|
1459
1420
|
room.forgetHostedBranch(account)
|
|
1460
1421
|
for (const [k, p] of room.pending) if (k.hosted && p.id === account) room.pending.delete(k)
|
|
1461
|
-
// Leaving
|
|
1462
|
-
room.
|
|
1463
|
-
room.
|
|
1464
|
-
room.broadcastClaims()
|
|
1422
|
+
// Leaving opens its boxes: nobody else could commit them.
|
|
1423
|
+
room.dropBoxes((c) => c.byId === account)
|
|
1424
|
+
room.broadcastBoxes()
|
|
1465
1425
|
room.broadcastMembers()
|
|
1466
1426
|
}
|
|
1467
1427
|
const left = allRooms(h)
|
|
@@ -1552,7 +1512,8 @@ export async function handleHostedMcp ({ req, res, pass, relay, workspaces = nul
|
|
|
1552
1512
|
if (!quilt) return fail('This session is not a quilt: its source control is git, as quilt_status says.')
|
|
1553
1513
|
let client
|
|
1554
1514
|
try { client = (await seam.client(quilt)).client } catch (e) { return fail(e.message) }
|
|
1555
|
-
|
|
1515
|
+
// Open held conflicts (held.js) keep their paths from landing until they are resolved.
|
|
1516
|
+
return runSessionSeamTool(name, args, { client, quilt, hosted: true, held: () => readHeld(c.room.doc.getMap(HELD_MAP)) })
|
|
1556
1517
|
})
|
|
1557
1518
|
}
|
|
1558
1519
|
}
|