heyquilt 0.3.175 → 0.3.176
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 +13 -0
- package/package.json +2 -2
- package/src/connection.js +5 -3
- package/src/gitstate.js +326 -0
- package/src/live-merge.js +21 -2
- package/src/mcp.js +1 -1
- package/src/merge3.js +17 -1
- package/src/relay-live-write.js +10 -4
- package/src/session.js +836 -36
- package/src/setup.js +8 -0
- package/src/status.js +2 -0
- package/src/ui/agent-guide.js +2 -1
package/RELEASES.md
CHANGED
|
@@ -11,6 +11,19 @@ Format: `## <version> — <YYYY-MM-DD>`, an optional one-line summary, then bull
|
|
|
11
11
|
Lead each bullet with a short bold phrase. Inline `code` and **bold** are rendered;
|
|
12
12
|
nothing else is.
|
|
13
13
|
|
|
14
|
+
## 0.3.176 — 2026-11-16
|
|
15
|
+
|
|
16
|
+
A clash stays in your own file for your AI to settle, the way git does it. And your folder follows the git branch you check out.
|
|
17
|
+
|
|
18
|
+
- **Your folder follows its git branch.** When you check out another branch in git (`git checkout`, `git switch`), your folder moves to that branch in the session by itself. The files git changed for the checkout are not sent to the branch you left, and nobody still on it gets them. A branch the session has not seen starts from your folder as git left it; on a branch the session already has, your folder gets the session's work there, uncommitted work included. Before this, the checkout went unnoticed and the other branch's files were shared as edits to the branch you started on.
|
|
19
|
+
- **Nothing is shared while git is at work.** While git is busy in your folder (a checkout, a pull, a stash, a rebase), Quilt takes nothing in from it and writes nobody's changes into it. It carries on about half a second after git is done, and nothing is lost: what you saved and what others changed meanwhile both arrive then.
|
|
20
|
+
- **Uncommitted work stays on its branch.** Work the session has on one branch, which git carries along when you switch, stays in the session on the branch it was made on. On a branch the session already has, your folder gets that branch's own files in its place.
|
|
21
|
+
- **Switched while Quilt was off.** When it starts again it joins the branch your folder is on now. What it had saved of the other branch is kept for when you go back, and is never mixed into this one.
|
|
22
|
+
- **A checkout of a commit** (a detached HEAD) gets a place of its own in the session, named after the commit. During a rebase or a bisect your folder stays on its branch and waits; what the rebase changed is shared when it is over.
|
|
23
|
+
- **Git may still ask you to stash first.** The session's uncommitted work is in your folder, so git refuses a checkout that would overwrite it, as it does with your own. `git stash` and then the checkout, one right after the other, is safe: neither is taken for an edit.
|
|
24
|
+
- **A clash stays in your file.** When your save changes the same lines someone else just changed, none of that save is shared. Your file gets both versions of those lines between conflict markers (`<<<<<<< mine`, `=======`, `>>>>>>> session`), with their other changes already merged in, and your AI is told why. Once it has settled them and saved, the file is shared. Nobody else ever gets a file with markers in it, and a partner's later change is never written over a file you are still settling.
|
|
25
|
+
- **No side record for it.** A clash between folders no longer parks your lines in a record that needs `quilt_resolve_merge`. Agents with no folder and apps before this version keep the old way for now.
|
|
26
|
+
|
|
14
27
|
## 0.3.175 — 2026-11-16
|
|
15
28
|
|
|
16
29
|
Quilt works with git only: its own source control is gone from the app, the relay and the AI tools. Two rules that held saves which clashed with nothing are gone too, and a save made from an old copy of a file no longer erases a teammate's change.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "heyquilt",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.176",
|
|
4
4
|
"description": "Real-time, tool-agnostic pair vibe coding: sync a project folder live between collaborators using any AI coding tool.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Daniel Carmichael",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"build": {
|
|
71
71
|
"appId": "dev.quilt.app",
|
|
72
72
|
"productName": "Quilt",
|
|
73
|
-
"copyright": "Copyright
|
|
73
|
+
"copyright": "Copyright \u00a9 2026 Daniel Carmichael. All rights reserved.",
|
|
74
74
|
"directories": {
|
|
75
75
|
"buildResources": "desktop/build",
|
|
76
76
|
"output": "dist"
|
package/src/connection.js
CHANGED
|
@@ -498,11 +498,13 @@ export class Connection extends EventEmitter {
|
|
|
498
498
|
*/
|
|
499
499
|
async liveWrite (req, { baseOf = null, timeoutMs = REQUEST_TIMEOUT_MS } = {}) {
|
|
500
500
|
if (this.branchKey === null) throw new Error('not on a branch')
|
|
501
|
-
|
|
501
|
+
// The branch the write was made on, asked again on that one: the folder may move to another meanwhile.
|
|
502
|
+
const branch = this.branchKey
|
|
503
|
+
let r = await this.branchRequest({ op: 'live-write', branch, ...req }, { timeoutMs })
|
|
502
504
|
if (r.needBase) {
|
|
503
505
|
const t = baseOf ? baseOf() : null
|
|
504
|
-
r = await this.branchRequest({ op: 'live-write', branch
|
|
505
|
-
if (r.needBase) r = await this.branchRequest({ op: 'live-write', branch
|
|
506
|
+
r = await this.branchRequest({ op: 'live-write', branch, ...req, ...(typeof t === 'string' ? { baseText: t } : { retry: true }) }, { timeoutMs })
|
|
507
|
+
if (r.needBase) r = await this.branchRequest({ op: 'live-write', branch, ...req, retry: true }, { timeoutMs })
|
|
506
508
|
}
|
|
507
509
|
return r
|
|
508
510
|
}
|
package/src/gitstate.js
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
// What git is doing to a synced folder. Quilt only reads git here: which branch (or commit) the
|
|
2
|
+
// folder is on, whether git is at work in it, and what a file looked like at a commit, so a
|
|
3
|
+
// checkout of another branch is told apart from edits and the folder can follow its branch
|
|
4
|
+
// (session.js). Nothing here writes to git, fetches, or talks to a remote. Every git call is
|
|
5
|
+
// asynchronous (the app's window and its relay connection never wait on git); the file reads
|
|
6
|
+
// below are synchronous.
|
|
7
|
+
import fs from 'node:fs'
|
|
8
|
+
import path from 'node:path'
|
|
9
|
+
import { execFile } from 'node:child_process'
|
|
10
|
+
import { watch } from 'chokidar'
|
|
11
|
+
import { looksBinary, sha1, MAX_STORED_BINARY_BYTES, closeWatcher } from './fsutil.js'
|
|
12
|
+
|
|
13
|
+
export const GIT_TIMEOUT_MS = 5000
|
|
14
|
+
// A hold ends this long after the last file or git event in the folder.
|
|
15
|
+
export const SETTLE_MS = 500
|
|
16
|
+
// An index.lock this old, with no other operation under way, may be one a crashed git left behind.
|
|
17
|
+
export const STALE_LOCK_MS = 60 * 1000
|
|
18
|
+
|
|
19
|
+
// What marks git at work in a folder: its index lock, and the operations that take HEAD off its
|
|
20
|
+
// branch until they finish (a rebase, a bisect).
|
|
21
|
+
const MARKERS = [
|
|
22
|
+
['index.lock', 'index-lock'], ['rebase-merge', 'rebase'], ['rebase-apply', 'rebase'], ['BISECT_LOG', 'bisect']
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
// Output read in one go: a listing of a big repository, or a batch of files (see filesAt).
|
|
26
|
+
const MAX_OUTPUT = 256 * 1024 * 1024
|
|
27
|
+
// More paths than this are not passed on the command line: the whole tree is asked, and filtered.
|
|
28
|
+
const MAX_PATHSPECS = 200
|
|
29
|
+
|
|
30
|
+
/** Runs git: its output (a string, or a Buffer with `buffer`), or null when it fails. */
|
|
31
|
+
async function run (root, args, opts) {
|
|
32
|
+
return (await call(root, args, opts)).out
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const gitBinary = () => process.env.QUILT_GIT || 'git'
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Runs git: { out } or, when it fails, { out: null, missing, timedOut }
|
|
39
|
+
* (missing: the git binary could not be started at all; timedOut: it ran
|
|
40
|
+
* past GIT_TIMEOUT_MS and was stopped). Never rejects. Git is told to take
|
|
41
|
+
* no lock it can do without, so a read here never looks like git at work.
|
|
42
|
+
*/
|
|
43
|
+
function call (root, args, { buffer = false, input, timeout = GIT_TIMEOUT_MS, env = {} } = {}) {
|
|
44
|
+
// QUILT_GIT lets tests point at a git binary that doesn't exist, to exercise
|
|
45
|
+
// the "git is unreachable" path without touching the real PATH.
|
|
46
|
+
const bin = gitBinary()
|
|
47
|
+
return new Promise((resolve) => {
|
|
48
|
+
const done = (out, missing, late, stderr = '') => resolve({ out, missing, timedOut: late, stderr })
|
|
49
|
+
let child
|
|
50
|
+
try {
|
|
51
|
+
child = execFile(bin, args, {
|
|
52
|
+
cwd: root,
|
|
53
|
+
encoding: buffer ? 'buffer' : 'utf8',
|
|
54
|
+
timeout,
|
|
55
|
+
maxBuffer: MAX_OUTPUT,
|
|
56
|
+
env: { ...process.env, GIT_OPTIONAL_LOCKS: '0', ...env }
|
|
57
|
+
}, (err, stdout, stderr) => {
|
|
58
|
+
if (!err) return done(stdout, false, false)
|
|
59
|
+
const missing = err.code === 'ENOENT' || err.code === 'EACCES'
|
|
60
|
+
done(null, missing, !missing && (err.killed === true || err.signal === 'SIGTERM'), String(stderr || ''))
|
|
61
|
+
})
|
|
62
|
+
} catch (err) { // a cwd that is gone, say
|
|
63
|
+
return done(null, err.code === 'ENOENT' || err.code === 'EACCES', false)
|
|
64
|
+
}
|
|
65
|
+
child.stdin.on('error', () => {}) // git may exit before reading all of it
|
|
66
|
+
child.stdin.end(input)
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** The branch .git/HEAD names (even one with no commits yet), or null (detached, or not a repo). No git call. */
|
|
71
|
+
export function headRef (root) {
|
|
72
|
+
const dir = gitDir(root)
|
|
73
|
+
if (!dir) return null
|
|
74
|
+
try {
|
|
75
|
+
const m = /^ref:\s*refs\/heads\/(.+)$/.exec(fs.readFileSync(path.join(dir, 'HEAD'), 'utf8').trim())
|
|
76
|
+
return m ? m[1] : null
|
|
77
|
+
} catch { return null }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** A file's bytes as Quilt keys them (lastKnown, sharedKey): its text, or "bin:<sha1>". */
|
|
81
|
+
function keyOf (buf) {
|
|
82
|
+
return looksBinary(buf) ? `bin:${sha1(buf)}` : buf.toString('utf8')
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The folder's .git directory (a worktree's .git file points at it), or null. */
|
|
86
|
+
export function gitDir (root) {
|
|
87
|
+
const dot = path.join(root, '.git')
|
|
88
|
+
let st
|
|
89
|
+
try { st = fs.statSync(dot) } catch { return null }
|
|
90
|
+
if (st.isDirectory()) return dot
|
|
91
|
+
try {
|
|
92
|
+
const m = /^gitdir:\s*(.+)$/m.exec(fs.readFileSync(dot, 'utf8'))
|
|
93
|
+
if (!m) return null
|
|
94
|
+
const dir = path.resolve(root, m[1].trim())
|
|
95
|
+
return fs.existsSync(dir) ? dir : null
|
|
96
|
+
} catch { return null }
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Where HEAD points, read from .git/HEAD alone (no git call): a branch's name, `@<12 hex>` for a
|
|
101
|
+
* detached commit, or null (not a repo, or unreadable). The same key headKey gives.
|
|
102
|
+
*/
|
|
103
|
+
export function headName (root) {
|
|
104
|
+
const dir = gitDir(root)
|
|
105
|
+
if (!dir) return null
|
|
106
|
+
let head
|
|
107
|
+
try { head = fs.readFileSync(path.join(dir, 'HEAD'), 'utf8').trim() } catch { return null }
|
|
108
|
+
const ref = /^ref:\s*refs\/heads\/(.+)$/.exec(head)
|
|
109
|
+
if (ref) return ref[1]
|
|
110
|
+
return /^[0-9a-f]{40,64}$/.test(head) ? `@${head.slice(0, 12)}` : null
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Where HEAD points: a branch, or a detached commit. Null when the folder is not a
|
|
115
|
+
* repo, when git is unreachable (sha lookup fails), or on an unborn branch (a fresh
|
|
116
|
+
* `git init` with no commits yet): in every case there's nothing to compare against.
|
|
117
|
+
*/
|
|
118
|
+
export async function headKey (root) {
|
|
119
|
+
const dir = gitDir(root)
|
|
120
|
+
if (!dir) return null
|
|
121
|
+
let head
|
|
122
|
+
try { head = fs.readFileSync(path.join(dir, 'HEAD'), 'utf8').trim() } catch { return null }
|
|
123
|
+
const sha = ((await run(root, ['rev-parse', '--verify', '-q', 'HEAD'])) || '').trim() || null
|
|
124
|
+
if (!sha) return null
|
|
125
|
+
const ref = /^ref:\s*refs\/heads\/(.+)$/.exec(head)
|
|
126
|
+
if (ref) return { key: ref[1], branch: ref[1], sha }
|
|
127
|
+
return { key: `@${sha.slice(0, 12)}`, branch: null, sha }
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** The commit a branch points at (wherever HEAD is), or null. */
|
|
131
|
+
export async function branchTip (root, branch) {
|
|
132
|
+
if (!branch || !gitDir(root)) return null
|
|
133
|
+
return ((await run(root, ['rev-parse', '--verify', '-q', `refs/heads/${branch}^{commit}`])) || '').trim() || null
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The git operation in progress in this folder, or null. `dir` lets a caller
|
|
138
|
+
* that already has it skip re-resolving it. `leftover`: an index.lock known to
|
|
139
|
+
* be left behind (its lockStamp, from leftoverLock), not counted.
|
|
140
|
+
*/
|
|
141
|
+
export function busy (root, dir = gitDir(root), leftover = null) {
|
|
142
|
+
if (!dir) return null
|
|
143
|
+
for (const [file, kind] of MARKERS) {
|
|
144
|
+
if (!fs.existsSync(path.join(dir, file))) continue
|
|
145
|
+
if (kind === 'index-lock' && leftover && lockStamp(root, dir) === leftover) continue
|
|
146
|
+
return kind
|
|
147
|
+
}
|
|
148
|
+
return null
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Which index.lock is there (its mtime and inode), or null. A new lock is another stamp. */
|
|
152
|
+
export function lockStamp (root, dir = gitDir(root)) {
|
|
153
|
+
if (!dir) return null
|
|
154
|
+
try { const st = fs.statSync(path.join(dir, 'index.lock')); return `${st.mtimeMs}:${st.ino}` } catch { return null }
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The index.lock's stamp when it looks left behind by a git that crashed: the
|
|
159
|
+
* only marker of an operation, older than STALE_LOCK_MS, and `git status`
|
|
160
|
+
* runs. Null otherwise. The file is never touched: deleting it is yours to do.
|
|
161
|
+
*/
|
|
162
|
+
export async function leftoverLock (root, now = Date.now()) {
|
|
163
|
+
const dir = gitDir(root)
|
|
164
|
+
if (busy(root, dir) !== 'index-lock') return null
|
|
165
|
+
const stamp = lockStamp(root, dir)
|
|
166
|
+
if (!stamp || busy(root, dir, stamp)) return null // another operation under way too
|
|
167
|
+
if (now - Number(stamp.split(':')[0]) < STALE_LOCK_MS) return null
|
|
168
|
+
if (await run(root, ['status', '--porcelain', '--untracked-files=no']) === null) return null
|
|
169
|
+
return lockStamp(root, dir) === stamp ? stamp : null
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** A cheap signal that git wrote the index (stash, reset, checkout, add...). Editors never do. */
|
|
173
|
+
export function indexStamp (root) {
|
|
174
|
+
const dir = gitDir(root)
|
|
175
|
+
if (!dir) return null
|
|
176
|
+
try { const st = fs.statSync(path.join(dir, 'index')); return `${st.mtimeMs}:${st.size}` } catch { return null }
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Several files at one commit, in a few git calls whatever their number:
|
|
181
|
+
* rel -> key (the file as Quilt keys it: its text, or "bin:<sha1>", as checkout
|
|
182
|
+
* would write it), null (not there), or undefined (not read: bigger than Quilt
|
|
183
|
+
* shares, behind a filter such as Git LFS, or a git call failed). `out.failed`
|
|
184
|
+
* counts the files a failed git call left unread. Null only when git itself
|
|
185
|
+
* can't be run.
|
|
186
|
+
*/
|
|
187
|
+
export async function filesAt (root, sha, rels) {
|
|
188
|
+
const out = new Map()
|
|
189
|
+
out.failed = 0
|
|
190
|
+
if (!rels.length) return out
|
|
191
|
+
const unread = (list) => { for (const rel of list) out.set(rel, undefined); out.failed += list.length }
|
|
192
|
+
// Sizes first, so a huge file can't overflow the read of the contents.
|
|
193
|
+
const check = await call(root, ['cat-file', '--batch-check=%(objectname) %(objecttype) %(objectsize)'], { input: rels.map((r) => `${sha}:${r}\n`).join('') })
|
|
194
|
+
if (check.missing) return null
|
|
195
|
+
const lines = check.out === null ? [] : check.out.split('\n').slice(0, rels.length)
|
|
196
|
+
if (lines.length !== rels.length) { unread(rels); return out }
|
|
197
|
+
// A path with a filter (Git LFS, say) is never read: its smudged size is unknown (the blob is
|
|
198
|
+
// a pointer), and running the filter can be slow or fail. The attributes are asked in one call.
|
|
199
|
+
const filtered = await filterOf(root, rels)
|
|
200
|
+
if (filtered === null) { unread(rels); return out }
|
|
201
|
+
const fetch = [] // [rel, blob id, size]
|
|
202
|
+
rels.forEach((rel, i) => {
|
|
203
|
+
const [id, type, size] = lines[i].split(' ')
|
|
204
|
+
if (type !== 'blob' || !/^\d+$/.test(size)) out.set(rel, null) // "<name> missing", or a folder there
|
|
205
|
+
else if (Number(size) > MAX_STORED_BINARY_BYTES || filtered.has(rel)) out.set(rel, undefined)
|
|
206
|
+
else fetch.push([rel, id, Number(size)])
|
|
207
|
+
})
|
|
208
|
+
// With --filters each line is "<blob> <path>": the path picks the line-ending conversion, as
|
|
209
|
+
// checkout would. That can change a size, so each file's own size is read from the batch's headers.
|
|
210
|
+
// Older git (2.34, say, as many Windows machines have) gives the blob's own size there instead, so where
|
|
211
|
+
// the conversion changes the length the size is checked: the content must end on the newline before the
|
|
212
|
+
// next header (or the end). Where it doesn't, the rest are read one at a time, which is exact.
|
|
213
|
+
const one = async (rel, id) => {
|
|
214
|
+
const r = await call(root, ['cat-file', '--filters', `--path=${rel}`, id], { buffer: true })
|
|
215
|
+
if (r.missing) return false
|
|
216
|
+
if (r.out === null) { unread([rel]); return true }
|
|
217
|
+
const key = keyOf(r.out)
|
|
218
|
+
out.set(rel, key.startsWith(LFS_POINTER) ? undefined : key)
|
|
219
|
+
return true
|
|
220
|
+
}
|
|
221
|
+
const HEADER = /^[0-9a-f]{40,64} (blob \d+|missing)$/
|
|
222
|
+
const read = async (chunk) => {
|
|
223
|
+
const buf = await call(root, ['cat-file', '--batch', '--filters'], { buffer: true, input: chunk.map(([rel, id]) => `${id} ${rel}\n`).join('') })
|
|
224
|
+
if (buf.missing) return false
|
|
225
|
+
if (buf.out === null) { unread(chunk.map(([rel]) => rel)); return true }
|
|
226
|
+
let at = 0
|
|
227
|
+
for (let i = 0; i < chunk.length; i++) {
|
|
228
|
+
const rel = chunk[i][0]
|
|
229
|
+
const nl = buf.out.indexOf(10, at)
|
|
230
|
+
const header = nl < 0 ? '' : buf.out.subarray(at, nl).toString('utf8')
|
|
231
|
+
if (/ missing$/.test(header)) { out.set(rel, null); at = nl + 1; continue }
|
|
232
|
+
const size = Number(header.split(' ')[2])
|
|
233
|
+
if (nl < 0 || !Number.isInteger(size)) { unread(chunk.slice(i).map(([r]) => r)); return true }
|
|
234
|
+
const end = nl + 1 + size
|
|
235
|
+
const last = i === chunk.length - 1
|
|
236
|
+
const after = last ? '' : buf.out.subarray(end + 1, buf.out.indexOf(10, end + 1)).toString('utf8')
|
|
237
|
+
if (buf.out[end] !== 10 || (last ? end + 1 !== buf.out.length : !HEADER.test(after))) {
|
|
238
|
+
for (const [r, id] of chunk.slice(i)) if (!(await one(r, id))) return false
|
|
239
|
+
return true
|
|
240
|
+
}
|
|
241
|
+
const key = keyOf(buf.out.subarray(nl + 1, end))
|
|
242
|
+
out.set(rel, key.startsWith(LFS_POINTER) ? undefined : key) // an LFS pointer is not the file
|
|
243
|
+
at = end + 1
|
|
244
|
+
}
|
|
245
|
+
return true
|
|
246
|
+
}
|
|
247
|
+
let chunk = []; let bytes = 0
|
|
248
|
+
for (const f of fetch) {
|
|
249
|
+
if (chunk.length && bytes + f[2] > MAX_OUTPUT / 4) {
|
|
250
|
+
if (!(await read(chunk))) return null
|
|
251
|
+
chunk = []; bytes = 0
|
|
252
|
+
}
|
|
253
|
+
chunk.push(f); bytes += f[2]
|
|
254
|
+
}
|
|
255
|
+
if (chunk.length && !(await read(chunk))) return null
|
|
256
|
+
return out
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const LFS_POINTER = 'version https://git-lfs'
|
|
260
|
+
|
|
261
|
+
/** The paths with a `filter` attribute set (in .gitattributes), or null when git failed. */
|
|
262
|
+
async function filterOf (root, rels) {
|
|
263
|
+
const out = await run(root, ['check-attr', '-z', '--stdin', 'filter'], { input: rels.join('\0') + '\0' })
|
|
264
|
+
if (out === null) return null
|
|
265
|
+
const f = out.split('\0')
|
|
266
|
+
const filtered = new Set()
|
|
267
|
+
for (let i = 0; i + 2 < f.length; i += 3) if (f[i + 2] !== 'unspecified' && f[i + 2] !== 'unset') filtered.add(f[i])
|
|
268
|
+
return filtered
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** A file's bytes at commit `sha`, as checkout would write it (null when git can't say). */
|
|
272
|
+
export async function blobAt (root, sha, rel) {
|
|
273
|
+
const out = await run(root, ['cat-file', '--filters', `${sha}:${rel}`], { buffer: true })
|
|
274
|
+
return out === null ? null : out
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* What git says about `paths` now (all of the folder with none), in two git calls whatever
|
|
279
|
+
* their number: `dirty` (changed, staged, untracked or conflicted), `unmerged` (a conflict
|
|
280
|
+
* git left for the person to resolve) and `tracked` (in the index). Null when git fails.
|
|
281
|
+
*/
|
|
282
|
+
export async function treeState (root, paths) {
|
|
283
|
+
const spec = paths.length <= MAX_PATHSPECS ? ['--', ...paths] : []
|
|
284
|
+
const status = await run(root, ['--literal-pathspecs', 'status', '--porcelain=v2', '-z', '--untracked-files=all', ...spec])
|
|
285
|
+
if (status === null) return null // not asking for the second when the first failed (or timed out)
|
|
286
|
+
const listed = await run(root, ['--literal-pathspecs', 'ls-files', '-z', ...spec])
|
|
287
|
+
if (listed === null) return null
|
|
288
|
+
const dirty = new Set()
|
|
289
|
+
const unmerged = new Set()
|
|
290
|
+
const f = status.split('\0')
|
|
291
|
+
for (let i = 0; i < f.length; i++) {
|
|
292
|
+
const e = f[i]
|
|
293
|
+
if (e[0] === '1') dirty.add(e.split(' ').slice(8).join(' '))
|
|
294
|
+
else if (e[0] === '2') dirty.add(e.split(' ').slice(9).join(' ')).add(f[++i]) // renamed: both paths
|
|
295
|
+
else if (e[0] === 'u') {
|
|
296
|
+
const rel = e.split(' ').slice(10).join(' ')
|
|
297
|
+
dirty.add(rel)
|
|
298
|
+
unmerged.add(rel)
|
|
299
|
+
} else if (e[0] === '?' || e[0] === '!') dirty.add(e.slice(2))
|
|
300
|
+
}
|
|
301
|
+
return { dirty, unmerged, tracked: new Set(listed.split('\0').filter(Boolean)) }
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Watches the folder's .git for HEAD moving, the index being written and git starting or
|
|
306
|
+
* finishing work (see busy); events: head, index, busy, idle.
|
|
307
|
+
*/
|
|
308
|
+
export function watchGit (root, onEvent) {
|
|
309
|
+
const dir = gitDir(root)
|
|
310
|
+
if (!dir) return { close: async () => {} }
|
|
311
|
+
const names = new Set(['HEAD', 'index', ...MARKERS.map(([f]) => f)])
|
|
312
|
+
let wasBusy = !!busy(root, dir)
|
|
313
|
+
const watcher = watch(dir, { ignoreInitial: true, depth: 0, followSymlinks: false })
|
|
314
|
+
const onAny = (p) => {
|
|
315
|
+
const name = path.basename(p)
|
|
316
|
+
if (!names.has(name)) return
|
|
317
|
+
if (name === 'HEAD') onEvent({ type: 'head' })
|
|
318
|
+
else if (name === 'index') onEvent({ type: 'index' })
|
|
319
|
+
else {
|
|
320
|
+
const now = !!busy(root, dir)
|
|
321
|
+
if (now !== wasBusy) { wasBusy = now; onEvent({ type: now ? 'busy' : 'idle' }) }
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
watcher.on('add', onAny).on('change', onAny).on('unlink', onAny).on('addDir', onAny).on('unlinkDir', onAny).on('error', () => {})
|
|
325
|
+
return { close: () => closeWatcher(watcher) }
|
|
326
|
+
}
|
package/src/live-merge.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
// those lines lands, or when its held lines already match the file.
|
|
19
19
|
import path from 'node:path'
|
|
20
20
|
import { diffLines as diffIndices } from './textdiff.js'
|
|
21
|
-
import { mergeLive } from './merge3.js'
|
|
21
|
+
import { mergeLive, withHeldMarkers } from './merge3.js'
|
|
22
22
|
import { HELD_MAP, addHeld, readHeld, dropVersions, heldRegions, locateHunk, overBudget, heldTaskTitle } from './held.js'
|
|
23
23
|
|
|
24
24
|
export const MOVES_MAP = 'moves' // in the file's document: old path -> { to, by, ts, text }
|
|
@@ -220,6 +220,16 @@ export function goneNameWarning (p, list, me = '') {
|
|
|
220
220
|
return `${parts.join('; ')}. Nothing was blocked: check it still exists (it may have been renamed or moved).`
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
+
/** What a writer's AI hears when its save clashed and both versions are in its own file to settle. */
|
|
224
|
+
export function clashNotice (p, who) {
|
|
225
|
+
return `⚖️ Your save of ${p} was not shared: ${who || 'someone'} changed the same lines first. ${p} in your folder now has both versions of those lines, yours between "<<<<<<< mine" and "=======", theirs between "=======" and ">>>>>>> session", with their other changes merged in. Read ${p}, edit those lines to what they should be, delete the three marker lines of each, and save: it is shared then. Until you do, your changes to ${p} stay in your folder only.`
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** The same file saved again with markers still in it. */
|
|
229
|
+
export function clashStillNotice (p) {
|
|
230
|
+
return `⚖️ ${p} still has conflict markers ("<<<<<<< mine", "=======", ">>>>>>> session"), so it is not shared yet. Settle each one, delete the marker lines, and save.`
|
|
231
|
+
}
|
|
232
|
+
|
|
223
233
|
/**
|
|
224
234
|
* The engine both live paths share, one per session. Options: `room()` the room's Y.Doc (held
|
|
225
235
|
* conflicts); `notice(text)` for the writer's AI;
|
|
@@ -249,7 +259,7 @@ export class LiveRules {
|
|
|
249
259
|
* `text` is what the shared file and the writer's folder get.
|
|
250
260
|
* `older`: a save proven made from an older text than `base` (it landed in the file Quilt replaced: base-pick.js).
|
|
251
261
|
*/
|
|
252
|
-
write ({ doc, where = {}, path: p, base = null, ours, theirs = null, by, byId = null, others = [], texts = null, union = false, nameSearch = true, older = null }) {
|
|
262
|
+
write ({ doc, where = {}, path: p, base = null, ours, theirs = null, by, byId = null, others = [], texts = null, union = false, nameSearch = true, older = null, markers = false }) {
|
|
253
263
|
const now = Date.now()
|
|
254
264
|
const map = this.heldMap()
|
|
255
265
|
const all = map ? readHeld(map) : []
|
|
@@ -282,6 +292,15 @@ export class LiveRules {
|
|
|
282
292
|
const r = mergeLive(base, ours, theirs, { union })
|
|
283
293
|
text = r.text; mine = r.mine; held = r.held
|
|
284
294
|
}
|
|
295
|
+
// A writer who settles a clash in its own file (`markers`: a folder, session.js relayClashed): nothing of
|
|
296
|
+
// this save is taken and no record is kept. It gets the save back merged onto the shared text as it is
|
|
297
|
+
// now, with both versions of each clashing run of lines between markers, and sends it again once settled.
|
|
298
|
+
if (markers && (held.length || olderHeld.length) && typeof theirs === 'string') {
|
|
299
|
+
const made = typeof older === 'string' && typeof base === 'string' ? older : base
|
|
300
|
+
const r = mergeLive(made ?? '', saved, theirs, { union })
|
|
301
|
+
const first = others.filter((n) => n && n !== by)
|
|
302
|
+
if (r.held.length) return { conflict: true, text: withHeldMarkers(r, { mine: by || 'you', theirs: first.join(', ') || 'someone else' }), others: first, held: [], warnings: [], gone: [] }
|
|
303
|
+
}
|
|
285
304
|
const cur = typeof theirs === 'string' ? theirs : null
|
|
286
305
|
// The open records on this path, on this branch: this write may join, supersede or match them. (A record
|
|
287
306
|
// stored by an earlier version may name a `square` instead of a branch: it is no branch's.)
|
package/src/mcp.js
CHANGED
|
@@ -82,7 +82,7 @@ export const MCP_INSTRUCTIONS =
|
|
|
82
82
|
'If the person you work for lets their AI pick up work by itself (their cloud AI, on the cloud machine they connected), finishing (quilt_set_work done, a task to QA or Done) hands you your next task from the board: start it. ' +
|
|
83
83
|
'Before you change files, call quilt_before_edit with their paths: it shows what people said about those files in chat and who else changed them lately, ' +
|
|
84
84
|
'so you know what was asked or planned before you change them. It never refuses: nobody holds files. ' +
|
|
85
|
-
'Edit any file you may change: edits merge as they arrive, and if your change clashes with someone\'s on the same lines, Quilt
|
|
85
|
+
'Edit any file you may change: edits merge as they arrive, and if your change clashes with someone\'s on the same lines, Quilt tells you. In your own folder the clash is in the file itself: your save is not shared, and the file has both versions of those lines between conflict markers ("<<<<<<< mine", "=======", ">>>>>>> session"). Edit them to what they should be, delete the marker lines and save: it is shared then. A conflict listed at the top of a Quilt answer instead (an agent with no folder made it, or an older app) is resolved at once with quilt_resolve_merge. A conflict must not sit: until you resolve your own, moving a task to QA or Done, quilt_set_work done and commits refuse, and a conflict whose writer\'s AI is gone is handed to another AI in the session. ' +
|
|
86
86
|
'A boxed file\'s edits are only in its owner\'s folder; quilt_unpack shares a box when someone needs it: decide yourself, and ask your person first for a large, risky or critical change or when the project\'s rules say so. A file boxed by someone else (quilt_status lists Boxed work) is not in your folder yet: if you edit it, their box opens and your change merges with their work. ' +
|
|
87
87
|
'For an agent of its own (not a person\'s AI session), every quilt answer starts with anything new for it (direct messages, mentions, tasks handed to it): act on it. ' +
|
|
88
88
|
'These rules are enforced for agents: while someone who messaged or mentioned you is waiting for an answer, the tools that move work on (tasks, focus, quilt_set_work) refuse until you answer them with quilt_message. ' +
|
package/src/merge3.js
CHANGED
|
@@ -71,7 +71,23 @@ export const withMarkers = eolAware(function withMarkers (base, ours, theirs, na
|
|
|
71
71
|
return out.join('\n')
|
|
72
72
|
})
|
|
73
73
|
|
|
74
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* A live merge (mergeLive's { text, held }) with each clash written out between markers: the writer's lines,
|
|
76
|
+
* then the lines that landed first. What the writer's own file gets when the relay takes nothing of a save.
|
|
77
|
+
*/
|
|
78
|
+
export function withHeldMarkers (r, names) {
|
|
79
|
+
const crlf = eolOf(r.text) === 'crlf'
|
|
80
|
+
const bare = (ls) => ls.map((l) => l.replace(/\r$/, ''))
|
|
81
|
+
const out = lines(crlf ? r.text.replace(/\r\n/g, '\n') : r.text)
|
|
82
|
+
// From the last clash to the first, so each one's place in the text still holds.
|
|
83
|
+
for (const h of [...r.held].sort((x, y) => y.at - x.at)) {
|
|
84
|
+
out.splice(h.at, h.theirs.length, `${MARK.start} (${names.mine})`, ...bare(h.ours), MARK.mid, ...bare(h.theirs), `${MARK.end} (${names.theirs})`)
|
|
85
|
+
}
|
|
86
|
+
const text = out.join('\n')
|
|
87
|
+
return crlf ? text.replace(/\n/g, '\r\n') : text
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** True when the text still holds markers that withMarkers or withHeldMarkers put there. */
|
|
75
91
|
export function hasMarkers (text) {
|
|
76
92
|
return typeof text === 'string' && text.split('\n').some((l) => l.startsWith(`${MARK.start} (`) || l.startsWith(`${MARK.end} (`))
|
|
77
93
|
}
|
package/src/relay-live-write.js
CHANGED
|
@@ -3,15 +3,17 @@
|
|
|
3
3
|
// check-then-write race."). A folder that saw a text file change on disk (session.js ingest, into its
|
|
4
4
|
// branch document) sends the relay
|
|
5
5
|
//
|
|
6
|
-
// MSG_BRANCH { op: 'live-write', branch, path, base, baseText?, text, older?, retry?, baseUnknown?, fromGit? }
|
|
6
|
+
// MSG_BRANCH { op: 'live-write', branch, path, base, baseText?, text, older?, retry?, baseUnknown?, fromGit?, markers? }
|
|
7
7
|
//
|
|
8
8
|
// `base`: the version (sha1, read-bases.js versionOf) of the shared text the folder last synced for the
|
|
9
9
|
// path, null for a file it never had; `baseText`: that text itself, when the relay may not know it
|
|
10
10
|
// (the folder sends it when it is small, or when the relay asked for it); `text`: what disk holds now;
|
|
11
11
|
// `older`: the older text the save was made from, one its folder's disk held before Quilt wrote over it
|
|
12
12
|
// (base-pick.js); `fromGit`: a diff branch's first edit of a file only git had, `base` being git's text (the
|
|
13
|
-
// shared file has no entry: it is git's, so the base is what it holds)
|
|
14
|
-
//
|
|
13
|
+
// shared file has no entry: it is git's, so the base is what it holds); `markers`: the folder settles a clash
|
|
14
|
+
// in its own file, so a save that clashes is not taken at all (the reply is { ok, conflict: true, text, base,
|
|
15
|
+
// others }: the save with both versions of the clashing lines between markers, made on `base`, the shared
|
|
16
|
+
// text now). A `trusted` or a `seen` from older folders is ignored.
|
|
15
17
|
// The relay merges it here, synchronously (nothing else runs on the room between the read of the
|
|
16
18
|
// shared text and the write of the result), through the same engine every live write uses
|
|
17
19
|
// (live-merge.js LiveRules: same lines keep what landed first and the writer's are held; the removed-name
|
|
@@ -132,7 +134,8 @@ export function liveWrite (room, ws, req, { origin = WRITE_ORIGIN, now = Date.no
|
|
|
132
134
|
const before = t0 ? t0.toString() : theirs
|
|
133
135
|
// The merge and the result: one transaction, so every member gets the write as one update.
|
|
134
136
|
doc.transact(() => {
|
|
135
|
-
r = rules.write({ doc, where, path: rel, base, ours: req.text, theirs, by, byId, others, nameSearch: false, older })
|
|
137
|
+
r = rules.write({ doc, where, path: rel, base, ours: req.text, theirs, by, byId, others, nameSearch: false, older, markers: req.markers === true })
|
|
138
|
+
if (r.conflict) return
|
|
136
139
|
let t = files.get(rel)
|
|
137
140
|
blobs.delete(rel)
|
|
138
141
|
// Who wrote it, in the same update as the text (WRITERS_MAP): a folder that takes the text in names its
|
|
@@ -141,6 +144,9 @@ export function liveWrite (room, ws, req, { origin = WRITE_ORIGIN, now = Date.no
|
|
|
141
144
|
if (!t) { t = new Y.Text(); if (typeof theirs === 'string') t.insert(0, theirs); files.set(rel, t) }
|
|
142
145
|
detail = applyLineDiff(t, r.text)
|
|
143
146
|
}, origin)
|
|
147
|
+
// Someone changed the same lines first, and this writer settles that in its own file: nothing is taken.
|
|
148
|
+
// `base` is the shared text its marked-up file was made on, which its next save is merged against.
|
|
149
|
+
if (r.conflict) return { ok: true, path: rel, conflict: true, text: r.text, base: theirs, others: r.others, notices, logs }
|
|
144
150
|
if (r.text !== (theirs ?? '')) {
|
|
145
151
|
room.liveWriters.delete(wkey)
|
|
146
152
|
room.liveWriters.set(wkey, { by, ts: now })
|