heyquilt 0.3.174 → 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/README.md +6 -3
- package/RELEASES.md +30 -0
- package/bin/quilt.js +1 -75
- package/desktop/main.js +22 -9
- package/package.json +2 -3
- package/src/ai-vm.js +1 -1
- package/src/api/memory-store.js +1 -5
- package/src/api/server.js +4 -45
- package/src/api/supabase-store.js +0 -10
- package/src/autowork.js +7 -142
- package/src/base-pick.js +125 -12
- package/src/branch-view.js +1 -1
- package/src/connection.js +12 -37
- package/src/control.js +16 -93
- package/src/fsutil.js +1 -1
- package/src/git-aside.js +70 -0
- package/src/github-commit.js +1 -2
- package/src/gitstate.js +326 -0
- package/src/held.js +12 -53
- package/src/history.js +1 -25
- package/src/live-merge.js +42 -161
- package/src/mcp.js +6 -90
- package/src/merge3.js +21 -5
- package/src/pathrules.js +1 -1
- package/src/protocol.js +6 -11
- package/src/read-bases.js +3 -5
- package/src/relay-live-write.js +37 -44
- package/src/relay-mcp.js +30 -164
- package/src/relay-prune.js +3 -6
- package/src/relay-turn-sync.js +7 -11
- package/src/runner.js +2 -4
- package/src/server.js +61 -1717
- package/src/session.js +895 -844
- package/src/setup.js +11 -3
- package/src/status.js +2 -5
- package/src/swap-in.js +56 -13
- package/src/turn-sync-plan.js +2 -2
- package/src/turn-sync.js +1 -1
- package/src/ui/agent-guide.js +3 -1
- package/src/ui/app.css +4 -96
- package/src/ui/app.js +1 -1
- package/src/ui/chat.js +2 -6
- package/src/ui/cloud-ai-model.js +0 -13
- package/src/ui/cloud-ai.js +2 -10
- package/src/ui/connections.js +2 -1
- package/src/ui/fileview.js +7 -20
- package/src/ui/git-rule.js +2 -13
- package/src/ui/home.js +2 -8
- package/src/ui/session-words.js +27 -0
- package/src/ui/session.js +34 -407
- package/src/ui-server.js +7 -56
- package/src/api/routes/seam-connect.js +0 -103
- package/src/api/routes/session-migrate.js +0 -39
- package/src/force-date.js +0 -27
- package/src/quilt-default.js +0 -84
- package/src/quilt-history.js +0 -106
- package/src/quilt-remote.js +0 -78
- package/src/seam-access.js +0 -97
- package/src/seam-url.js +0 -15
- package/src/session-follow.js +0 -583
- package/src/session-layout3.js +0 -466
- package/src/session-migrate.js +0 -123
- package/src/session-quilt.js +0 -126
- package/src/session-seam.js +0 -312
- package/src/source-live/bring-in.js +0 -391
- package/src/source-live/land.js +0 -410
- package/src/source-live/live-block.js +0 -1166
- package/src/source-live/live-square.js +0 -116
- package/src/ui/force-words.js +0 -19
- package/src/ui/quiltview.js +0 -213
- package/src/ui/seam-model.js +0 -309
package/src/source-live/land.js
DELETED
|
@@ -1,410 +0,0 @@
|
|
|
1
|
-
// Quilt's side of seam: live squares in a Quilt session. Seam (src/quilts/) never imports this.
|
|
2
|
-
// A person's held work lands by itself (Daniel, 2026-11-03). A folder's square holds the person's live
|
|
3
|
-
// work until someone commits and merges it, and when another merge changed the same lines it held a
|
|
4
|
-
// conflict too, waiting for a person nobody had asked (sq:09a100d0's RELEASES.md against main:1076).
|
|
5
|
-
// Agents' squares have their AI asked; a person's folder square had no one. Now, whatever how long the
|
|
6
|
-
// work was held, the person's app (as them, with their own Seam sign-in) lands it with no step of theirs:
|
|
7
|
-
//
|
|
8
|
-
// 1. Quiet for a moment (LAND_QUIET_MS after the last edit to the square, anyone's): the square's live
|
|
9
|
-
// work is committed with a message naming its files and merged onto its line, waiting for the
|
|
10
|
-
// line's required checks the way `seam merge --wait` does (merge-wait.js); the folder carries on
|
|
11
|
-
// in a new square (the relay's quilt-next).
|
|
12
|
-
// 2. A conflict in the square is settled without asking the person, in this order:
|
|
13
|
-
// a. what Seam offers by itself: a conflict's word-level suggestion, else its additive and
|
|
14
|
-
// whitespace steps (a changelog also its union step: bring-in.js isChangelog), else the work
|
|
15
|
-
// put onto main's copy when it was made on an older one (bring-in.js onOlderCopy);
|
|
16
|
-
// b. the person's own AI on their cloud machine, when they connected one: a task on the board for
|
|
17
|
-
// "<person>'s AI" (the relay wakes it, as for any task given to it; the same for every AI
|
|
18
|
-
// tool), with the file, both sides and what to do. AI_ATTEMPTS tries, as Seam gives an AI.
|
|
19
|
-
// AI sessions on the person's computer ARE the person, and are never handed this;
|
|
20
|
-
// c. else main's side stays in the file, and the person's version of each such file is kept in a
|
|
21
|
-
// square of its own, opened from their work and titled so they find it; the held square then
|
|
22
|
-
// merges, and the person is told once, in chat. Nothing is lost.
|
|
23
|
-
//
|
|
24
|
-
// Only the square's holder's app lands it; a writer's app does once the holder's has been quiet for
|
|
25
|
-
// HOLDER_WAIT_MS more (offline), the same turn as bringing main in (bring-in.js).
|
|
26
|
-
//
|
|
27
|
-
// A path with an open held conflict (held.js: two live writes changed the same lines and the second
|
|
28
|
-
// writer's are held) never lands until someone resolves it with quilt_resolve_merge (Seam's 07 "Terms
|
|
29
|
-
// held aside"): it stays live in the square, said once, and everything else lands as above.
|
|
30
|
-
import { mergeWaiting } from '@heyquilt/seam/lib/quilts/merge-wait.js'
|
|
31
|
-
import { parseMarkers } from '@heyquilt/seam/lib/quilts/conflict-format.js'
|
|
32
|
-
import { blobId } from '@heyquilt/seam/lib/quilts/records.js'
|
|
33
|
-
import { squareShort } from '@heyquilt/seam/lib/quilts/errors.js'
|
|
34
|
-
import { isChangelog, onOlderCopy, olderTexts, unionMarked, HOLDER_WAIT_MS } from './bring-in.js'
|
|
35
|
-
import { heldLandingNote } from '../held.js'
|
|
36
|
-
|
|
37
|
-
const num = (v, d) => (Number(v) > 0 ? Number(v) : d)
|
|
38
|
-
// How long the square's work is left alone after its last edit before it lands.
|
|
39
|
-
export const LAND_QUIET_MS = num(process.env.QUILT_LAND_QUIET_MS, 90 * 1000)
|
|
40
|
-
// Seam's own number of tries an AI gets at one conflict (Seam's events.js AI_ATTEMPTS).
|
|
41
|
-
export const AI_ATTEMPTS = 2
|
|
42
|
-
// How long one try of the person's AI may take before it counts as failed.
|
|
43
|
-
export const AI_ATTEMPT_MS = num(process.env.QUILT_LAND_AI_MS, 15 * 60 * 1000)
|
|
44
|
-
// How long a merge waits for the line's required checks (seconds), as `seam merge --wait` would.
|
|
45
|
-
export const LAND_WAIT_S = num(process.env.QUILT_LAND_WAIT_S, 30 * 60)
|
|
46
|
-
// After a merge the line refused for something only a person can give (an approval, a red check), the next try.
|
|
47
|
-
export const REFUSED_RETRY_MS = 10 * 60 * 1000
|
|
48
|
-
// Seam's ladder steps a person never has to choose, tried on each conflict in turn (seam_resolve's rule).
|
|
49
|
-
export const RULES = ['additive', 'whitespace']
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Whether held work lands by itself: on, unless QUILT_LAND=off or the person turned it off in their
|
|
53
|
-
* settings (autoLand: 'off'). Under node --test (Quilt's own tests) it is off unless a test sets
|
|
54
|
-
* QUILT_LAND=on: a square merging by itself after a quiet moment would change what other tests watch.
|
|
55
|
-
*/
|
|
56
|
-
export function landOn ({ env = process.env, settings = {} } = {}) {
|
|
57
|
-
const v = String(env.QUILT_LAND || '').toLowerCase()
|
|
58
|
-
if (v === 'off') return false
|
|
59
|
-
if (v === 'on') return true
|
|
60
|
-
if (env.NODE_TEST_CONTEXT) return false
|
|
61
|
-
return settings.autoLand !== 'off'
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const listed = (names) => `${names.slice(0, 5).join(', ')}${names.length > 5 ? ` and ${names.length - 5} more` : ''}`
|
|
65
|
-
const clock = (ts) => new Date(ts).toISOString().slice(11, 16) + ' UTC'
|
|
66
|
-
|
|
67
|
-
/** The commit message of work that lands by itself: its files, and that Quilt landed it. */
|
|
68
|
-
export function landMessage (paths) {
|
|
69
|
-
const names = [...new Set(paths)].sort()
|
|
70
|
-
return names.length ? `Work on ${listed(names)}, landed by Quilt once the folder went quiet` : 'Work landed by Quilt once the folder went quiet'
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/** The square the person's version of files is kept in, titled so they find it. */
|
|
74
|
-
export function keptTitle (paths, at) {
|
|
75
|
-
const names = [...new Set(paths)].sort()
|
|
76
|
-
const what = names.length === 1 ? names[0] : `${names.length} files (${listed(names)})`
|
|
77
|
-
return `Your ${what} from ${clock(at)}, kept when main changed the same lines`.slice(0, 200)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** The board task that asks the person's AI to settle a conflict: the file and the square, with the conflict's term so a retry is told apart. */
|
|
81
|
-
export function aiTaskTitle ({ paths, square, term }) {
|
|
82
|
-
return `Settle ${listed(paths)} in ${squareShort(square)}: main changed the same lines as the held work (conflict ${String(term || '').slice(0, 8)})`.slice(0, 200)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** The one notice the person gets when their version was kept aside. */
|
|
86
|
-
export function keptNotice ({ paths, kept, line = 'main', patch = null }) {
|
|
87
|
-
return `Your held work${patch ? ` landed on ${line} as patch ${patch}` : ` is landing on ${line}`}, but ${listed(paths)} changed on ${line} in the same lines, so ${line}'s version stayed there. Your version is kept in square ${squareShort(kept)} ("Your … kept when main changed the same lines"): nothing was lost.`
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* The sides of a conflicted file as Seam writes it in its snapshot format (cat format snapshot):
|
|
92
|
-
* { ours, theirs, base } texts (null for a side that deleted it), or null when it is not one plain
|
|
93
|
-
* two-sided term (a name conflict, more sides, no markers).
|
|
94
|
-
*/
|
|
95
|
-
export function sidesOf (text) {
|
|
96
|
-
let regions
|
|
97
|
-
try { regions = parseMarkers(text) } catch { return null }
|
|
98
|
-
const blocks = regions.filter((r) => !r.ok)
|
|
99
|
-
if (blocks.length !== 1 || blocks[0].format !== 'snapshot' || regions.some((r) => r.ok && r.ok.some((l) => l !== ''))) return null
|
|
100
|
-
const b = blocks[0]
|
|
101
|
-
if (!b.sides || b.sides.length !== 2) return null
|
|
102
|
-
const t = (s) => (s && !s.deleted && typeof s.text === 'string' ? s.text : null)
|
|
103
|
-
const bases = b.removes || []
|
|
104
|
-
return { ours: t(b.sides[0]), theirs: t(b.sides[1]), base: typeof bases[0] === 'string' ? bases[0] : (bases[0] && typeof bases[0].text === 'string' ? bases[0].text : '') }
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Lands one folder's square. Everything it touches comes in `o`: `quilt`, `square`, `line`; `client()`
|
|
109
|
-
* (a Seam client as this member: square, diff, tree, cat, resolve, merge, events, openSquare, upload,
|
|
110
|
-
* commit, pathHistory, blobs, quilt); `block` (the folder's live block: status, commit, moveTo, block);
|
|
111
|
-
* `next()` (the relay moves the branch on to a new square after a merge); `catchUp()` (main brought
|
|
112
|
-
* in first); `hasAi()` (the person connected a cloud AI); `board` ({ list, add, comment, move }) as the
|
|
113
|
-
* person; `notify(text)` (one note to the person, in chat); `log`; `now`, `quietMs`, `aiMs`,
|
|
114
|
-
* `holderWaitMs`, `waitS` and `marked(path)` (a project's merge=union files).
|
|
115
|
-
*/
|
|
116
|
-
export class Lander {
|
|
117
|
-
constructor (o) {
|
|
118
|
-
Object.assign(this, { quietMs: LAND_QUIET_MS, aiMs: AI_ATTEMPT_MS, holderWaitMs: HOLDER_WAIT_MS, waitS: LAND_WAIT_S, now: Date.now, log: () => {}, notify: () => {}, hasAi: () => false, catchUp: async () => null, marked: null }, o)
|
|
119
|
-
this.lastEdit = this.now()
|
|
120
|
-
this.busy = false
|
|
121
|
-
this.timer = null
|
|
122
|
-
this.stopped = false
|
|
123
|
-
this.refusedAt = 0
|
|
124
|
-
this.refusedHead = null
|
|
125
|
-
this.state = null // what it did last, for status: { landed } | { kept } | { asked } | { waiting }
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/** An edit reached the square (anyone's): the quiet starts again, and a look is due once it lasts. */
|
|
129
|
-
edited () {
|
|
130
|
-
this.lastEdit = this.now()
|
|
131
|
-
this.soon(this.quietMs + 50)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
soon (ms) {
|
|
135
|
-
if (this.stopped) return
|
|
136
|
-
clearTimeout(this.timer)
|
|
137
|
-
this.timer = setTimeout(() => { this.timer = null; this.tick().catch(() => {}) }, ms)
|
|
138
|
-
this.timer.unref?.()
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
stop () { this.stopped = true; clearTimeout(this.timer) }
|
|
142
|
-
|
|
143
|
-
async me (c) {
|
|
144
|
-
if (this.memberId) return this.memberId
|
|
145
|
-
const q = await c.quilt(this.quilt).catch(() => null)
|
|
146
|
-
this.memberId = (q && q.you && q.you.member_id) || null
|
|
147
|
-
return this.memberId
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/** One look: lands the square's work, or settles its conflict first. Answers what it did ({ did, ... }). */
|
|
151
|
-
async tick () {
|
|
152
|
-
if (this.busy || this.stopped) return { did: 'busy' }
|
|
153
|
-
this.busy = true
|
|
154
|
-
try { return await this.look() } catch (err) {
|
|
155
|
-
this.log(`couldn't land square ${squareShort(this.square)}'s work by itself (${String(err.message || err).slice(0, 300)}); Quilt tries again in a minute.`)
|
|
156
|
-
return { did: 'failed', error: err.message }
|
|
157
|
-
} finally { this.busy = false }
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
async look () {
|
|
161
|
-
const c = await this.client()
|
|
162
|
-
if (!c) return { did: 'no-client' }
|
|
163
|
-
let sq = await c.square(this.quilt, this.square)
|
|
164
|
-
if (!sq || sq.state !== 'open') return { did: 'closed' }
|
|
165
|
-
// Seam moved the square's head itself (someone settled a conflict there, the person's AI from its own
|
|
166
|
-
// folder): the live document follows first, so a commit of the live work is made on the right head.
|
|
167
|
-
const want = sq.head || sq.base
|
|
168
|
-
if (this.block.moveTo && this.block.head && want && this.block.head !== want) {
|
|
169
|
-
await this.block.moveTo(want, { base: !sq.head }).catch(() => null)
|
|
170
|
-
// Still moving (the relay brings main in this moment): the next look.
|
|
171
|
-
if (this.block.head !== want) { this.soon(15 * 1000); return { did: 'moving' } }
|
|
172
|
-
}
|
|
173
|
-
// Paths with an open held conflict stay live until it is resolved; the rest of the work lands.
|
|
174
|
-
const held = new Set(this.block.heldPaths ? this.block.heldPaths() : [])
|
|
175
|
-
const all = this.block.status ? this.block.status() : []
|
|
176
|
-
const work = all.filter((w) => !held.has(w.path))
|
|
177
|
-
const left = all.filter((w) => held.has(w.path)).map((w) => w.path)
|
|
178
|
-
const heldKey = left.slice().sort().join('\n')
|
|
179
|
-
if (left.length && this.heldTold !== heldKey) { this.heldTold = heldKey; this.log(heldLandingNote(left, { none: !work.length && !sq.head })) }
|
|
180
|
-
if (!work.length && !sq.head) {
|
|
181
|
-
if (!left.length) return { did: 'nothing' }
|
|
182
|
-
// Resolving it "theirs" changes no file (no edit wakes this): looked at again in a minute.
|
|
183
|
-
this.soon(60 * 1000)
|
|
184
|
-
return { did: 'held', held: left }
|
|
185
|
-
}
|
|
186
|
-
const me = await this.me(c)
|
|
187
|
-
const holder = !!me && me === sq.holder
|
|
188
|
-
const quiet = this.now() - this.lastEdit
|
|
189
|
-
const need = this.quietMs + (holder ? 0 : this.holderWaitMs)
|
|
190
|
-
if (quiet < need) { this.soon(need - quiet + 50); return { did: 'waiting', for: need - quiet } }
|
|
191
|
-
// Main first: the square takes main's newer patches (bring-in.js), and then this looks again.
|
|
192
|
-
if (sq.behind_by) {
|
|
193
|
-
await this.catchUp()
|
|
194
|
-
sq = await c.square(this.quilt, this.square)
|
|
195
|
-
if (!sq || sq.state !== 'open') return { did: 'closed' }
|
|
196
|
-
if (sq.behind_by) { this.soon(30 * 1000); return { did: 'behind' } }
|
|
197
|
-
}
|
|
198
|
-
if (sq.conflicted_paths) return this.settle(c, sq)
|
|
199
|
-
// Refused for something only a person gives: not again for a while, unless the square changed.
|
|
200
|
-
const headNow = sq.head || null
|
|
201
|
-
if (this.refusedAt && this.refusedHead === headNow && !work.length && this.now() - this.refusedAt < REFUSED_RETRY_MS) return { did: 'refused-wait' }
|
|
202
|
-
let head = sq.head
|
|
203
|
-
if (work.length) {
|
|
204
|
-
const r = await this.block.commit({ message: landMessage(work.map((w) => w.path)) })
|
|
205
|
-
head = (r && r.square && r.square.head) || (this.block.block && this.block.block.head) || head
|
|
206
|
-
}
|
|
207
|
-
if (!head) return { did: 'nothing' }
|
|
208
|
-
return this.merge(c, sq, head)
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
async merge (c, sq, head) {
|
|
212
|
-
const line = sq.line || this.line || 'main'
|
|
213
|
-
const message = await this.title(c, sq).catch(() => null)
|
|
214
|
-
let r
|
|
215
|
-
try {
|
|
216
|
-
r = await mergeWaiting(c, this.quilt, line, { square: sq.id, expect_head: head, commit_live: false, ...(message ? { message } : {}) }, { wait: this.waitS, say: (t) => this.log(t) })
|
|
217
|
-
} catch (err) {
|
|
218
|
-
// An approval, a red check, a frozen line: a person's to give. Said once; tried again later.
|
|
219
|
-
this.refusedAt = this.now()
|
|
220
|
-
this.refusedHead = head
|
|
221
|
-
this.state = { waiting: String(err.message || err).split('\n')[0].slice(0, 300), at: this.now() }
|
|
222
|
-
this.log(`square ${squareShort(sq.id)}'s held work could not merge onto ${line} yet: ${this.state.waiting}`)
|
|
223
|
-
this.soon(REFUSED_RETRY_MS)
|
|
224
|
-
return { did: 'refused', error: err.message }
|
|
225
|
-
}
|
|
226
|
-
if (r && r.ok && r.merged) {
|
|
227
|
-
this.refusedAt = 0
|
|
228
|
-
const patch = r.merged.patch_no ?? null
|
|
229
|
-
this.state = { landed: { line, patch, at: this.now() } }
|
|
230
|
-
this.log(`landed square ${squareShort(sq.id)}'s held work on ${line}${patch != null ? ` as patch ${patch}` : ''}, with no step of yours.`)
|
|
231
|
-
this.closeAsks(sq, `Settled, and the held work landed on ${line}${patch != null ? ` as patch ${patch}` : ''}.`)
|
|
232
|
-
if (this.keptNote) { const n = this.keptNote; this.keptNote = null; this.notify(keptNotice({ ...n, line, patch })) }
|
|
233
|
-
try { await this.next() } catch (err) { this.log(`the folder's branch did not move to a new square yet (${err.message}); it does on the next look.`) }
|
|
234
|
-
return { did: 'landed', patch, line }
|
|
235
|
-
}
|
|
236
|
-
// A conflict: Seam rebased the square onto the line and kept it there (on_conflict rebase). The folder follows; settled next.
|
|
237
|
-
const to = (r && r.square && r.square.head) || (r && r.head) || null
|
|
238
|
-
if (to && this.block.moveTo) await this.block.moveTo(to).catch(() => {})
|
|
239
|
-
this.soon(1000)
|
|
240
|
-
return { did: 'conflict', terms: ((r && r.terms) || []).map((t) => t.path) }
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/** The patch's title: the square's own commit messages (Seam would take the square's title, "Uncommitted work from …"). */
|
|
244
|
-
async title (c, sq) {
|
|
245
|
-
if (!c.log) return null
|
|
246
|
-
const log = await c.log(this.quilt, { rev: `sq:${sq.id}`, limit: 50 })
|
|
247
|
-
const own = ((log && log.commits) || []).filter((x) => x && x.square_id === sq.id && x.message).map((x) => String(x.message).split('\n')[0].trim()).filter(Boolean).reverse()
|
|
248
|
-
const uniq = [...new Set(own)]
|
|
249
|
-
if (!uniq.length) return null
|
|
250
|
-
if (uniq.length === 1) return uniq[0].slice(0, 200)
|
|
251
|
-
const all = `${uniq.length} commits: ${uniq.join('; ')}`
|
|
252
|
-
return all.length > 200 ? `${all.slice(0, 199)}…` : all
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/** The square's conflicted files at its head: [{ path, term }]. */
|
|
256
|
-
async conflicts (c, sq) {
|
|
257
|
-
if (!sq.head) return []
|
|
258
|
-
const d = await c.diff(this.quilt, { from: `c:${sq.base}`, to: `c:${sq.head}`, format: 'names' })
|
|
259
|
-
const paths = ((d && d.files) || []).map((f) => f.path)
|
|
260
|
-
const out = []
|
|
261
|
-
for (let i = 0; i < paths.length; i += 100) {
|
|
262
|
-
const t = await c.tree(this.quilt, `c:${sq.head}`, paths.slice(i, i + 100))
|
|
263
|
-
for (const e of (t && t.entries) || []) if (e.mode === 'conflict') out.push({ path: e.path, term: e.term || '' })
|
|
264
|
-
}
|
|
265
|
-
return out
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/** Settles the square's conflicts (2a, then 2b, then 2c at the top of this file), then looks again to merge. */
|
|
269
|
-
async settle (c, sq) {
|
|
270
|
-
const line = sq.line || this.line || 'main'
|
|
271
|
-
let head = sq.head
|
|
272
|
-
const resolve = async (path, entry) => {
|
|
273
|
-
const r = await c.resolve(this.quilt, sq.id, { expect_head: head, entries: [{ path, ...entry }] })
|
|
274
|
-
head = (r && r.square && r.square.head) || (r && r.result && r.result.id) || head
|
|
275
|
-
return r
|
|
276
|
-
}
|
|
277
|
-
let left = await this.conflicts(c, sq)
|
|
278
|
-
const settled = []
|
|
279
|
-
// Files the project marks merge=union (.gitattributes) are changelogs too.
|
|
280
|
-
if (!this.marked) this.marked = await unionMarked(c, this.quilt, line)
|
|
281
|
-
for (const x of left) {
|
|
282
|
-
// a. Seam's own answers: its suggestion, then its ladder steps; a changelog keeps both sides.
|
|
283
|
-
const tries = [{ choose: 'suggestion' }, ...RULES.map((rule) => ({ rule })), ...(isChangelog(x.path, this.marked) ? [{ rule: 'union' }] : [])]
|
|
284
|
-
let done = false
|
|
285
|
-
for (const t of tries) {
|
|
286
|
-
try { await resolve(x.path, t); done = true; settled.push({ path: x.path, how: t.choose || `rule:${t.rule}` }); break } catch (err) {
|
|
287
|
-
if (err.status === 409 && err.code !== 'conflict_taken') { head = (await c.square(this.quilt, sq.id)).head } else if (err.status && err.status >= 500) throw err
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
if (done) continue
|
|
291
|
-
// a. Work made on an older copy of main's file: its edits put onto main's copy.
|
|
292
|
-
const moved = await this.olderCopy(c, sq, line, x.path).catch(() => null)
|
|
293
|
-
if (moved) {
|
|
294
|
-
await c.upload(this.quilt, [{ kind: 'blob', id: moved.id, bytes: moved.bytes }])
|
|
295
|
-
try { await resolve(x.path, { choose: { blob: moved.id } }); settled.push({ path: x.path, how: 'older-copy' }); continue } catch {}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
if (settled.length) {
|
|
299
|
-
this.log(`settled ${listed(settled.map((s) => s.path))} in square ${squareShort(sq.id)} as Seam offered (${[...new Set(settled.map((s) => s.how))].join(', ')}), with no step of yours.`)
|
|
300
|
-
if (this.block.moveTo && head) await this.block.moveTo(head).catch(() => {})
|
|
301
|
-
sq = await c.square(this.quilt, sq.id)
|
|
302
|
-
left = sq && sq.conflicted_paths ? await this.conflicts(c, sq) : []
|
|
303
|
-
}
|
|
304
|
-
if (!left.length) { this.closeAsks(sq); this.soon(settled.length ? 1000 : 30 * 1000); return { did: 'settled', settled } }
|
|
305
|
-
// b. The person's AI on their cloud machine, AI_ATTEMPTS tries.
|
|
306
|
-
if (this.hasAi() && this.board) {
|
|
307
|
-
const asked = this.ask(sq, left)
|
|
308
|
-
if (asked) return asked
|
|
309
|
-
}
|
|
310
|
-
// c. Main's side stays; the person's version is kept in a square of its own; the held work merges.
|
|
311
|
-
return this.keepAside(c, sq, left)
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
/** 2a's last step: the conflicted file's own side was made on an older copy of main's. { id, bytes } of the settled text, or null. */
|
|
315
|
-
async olderCopy (c, sq, line, path) {
|
|
316
|
-
const r = await c.cat(this.quilt, `c:${sq.head}`, path, { format: 'snapshot' })
|
|
317
|
-
if (!r || !r.conflict || !r.content) return null
|
|
318
|
-
const s = sidesOf(Buffer.from(r.content, 'base64').toString('utf8'))
|
|
319
|
-
if (!s || s.ours == null || s.theirs == null) return null
|
|
320
|
-
const union = isChangelog(path, this.marked)
|
|
321
|
-
const moved = onOlderCopy(s.ours, s.base, s.theirs, await olderTexts(c, this.quilt, path, line), { union })
|
|
322
|
-
if (!moved) return null
|
|
323
|
-
const bytes = Buffer.from(moved.text, 'utf8')
|
|
324
|
-
return { id: blobId(bytes), bytes }
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/** The board's tasks this lander made for square `sq` (its marker in the title), and those for conflict `term`. */
|
|
328
|
-
asks (sq, term = null) {
|
|
329
|
-
let all = []
|
|
330
|
-
try { all = this.board.list() || [] } catch { return [] }
|
|
331
|
-
const mark = squareShort(sq.id)
|
|
332
|
-
return all.filter((t) => t && typeof t.title === 'string' && t.title.startsWith('Settle ') && t.title.includes(mark) && (!term || t.title.includes(`(conflict ${String(term).slice(0, 8)})`)))
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/** 2b: a try of the person's AI is waiting, or a new one asked: { did }. Null once AI_ATTEMPTS tries failed. */
|
|
336
|
-
ask (sq, left) {
|
|
337
|
-
const term = left[0].term
|
|
338
|
-
const tries = this.asks(sq, term)
|
|
339
|
-
const open = tries.find((t) => !t.archived && t.column !== 'done' && t.column !== 'qa' && this.now() - (t.ts || 0) < this.aiMs)
|
|
340
|
-
if (open) { this.soon(Math.min(60 * 1000, this.aiMs)); return { did: 'asked', task: open.id, attempt: tries.length } }
|
|
341
|
-
if (tries.length >= AI_ATTEMPTS) return null
|
|
342
|
-
const paths = left.map((x) => x.path)
|
|
343
|
-
let task
|
|
344
|
-
// A board this member can't add to (a viewer's, say): straight to the rule, never a wait.
|
|
345
|
-
try { task = this.board.add({ title: aiTaskTitle({ paths, square: sq.id, term }), assignee: this.person, forAi: true }) } catch (err) { this.log(`couldn't ask ${this.person}'s AI on the board (${err.message})`); return null }
|
|
346
|
-
const id = task && (task.id || (task.task && task.task.id))
|
|
347
|
-
const line = sq.line || this.line || 'main'
|
|
348
|
-
const why = [
|
|
349
|
-
`${this.person}'s held work in square ${squareShort(sq.id)} and a newer patch on ${line} changed the same lines of ${listed(paths)}. This is try ${tries.length + 1} of ${AI_ATTEMPTS}.`,
|
|
350
|
-
`Read both sides with seam_square_status and seam_cat (rev sq:${squareShort(sq.id).slice(3)}, format git shows ours = the held work, theirs = ${line}'s). Keep what each side meant: settle each file with seam_resolve, or write the file without the markers, then seam_commit.`,
|
|
351
|
-
`Then move this task to Done. Quilt merges the square by itself once nothing in it is conflicted. If you can't settle it, say why in a comment and move it to Done: Quilt keeps ${line}'s side and keeps ${this.person}'s version in a square of its own.`
|
|
352
|
-
].join('\n\n')
|
|
353
|
-
if (id) { try { this.board.comment(id, why) } catch {} }
|
|
354
|
-
this.state = { asked: { paths, attempt: tries.length + 1, at: this.now() } }
|
|
355
|
-
this.log(`asked ${this.person}'s AI to settle ${listed(paths)} in square ${squareShort(sq.id)} (try ${tries.length + 1} of ${AI_ATTEMPTS}).`)
|
|
356
|
-
this.soon(Math.min(60 * 1000, this.aiMs))
|
|
357
|
-
return { did: 'asked', task: id, attempt: tries.length + 1 }
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
/** Tasks asked of the AI for a square whose conflicts are all settled now: to Done, with a word. */
|
|
361
|
-
closeAsks (sq, words = 'Settled: nothing in the square is conflicted now, and Quilt merges it by itself.') {
|
|
362
|
-
if (!this.board || !sq) return
|
|
363
|
-
for (const t of this.asks(sq)) {
|
|
364
|
-
if (t.archived || t.column === 'done') continue
|
|
365
|
-
try { this.board.comment(t.id, words) } catch {}
|
|
366
|
-
try { this.board.move(t.id, 'done') } catch {}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/** 2c: main's side stays in each file; the person's version goes into a square of its own; the held work merges after. */
|
|
371
|
-
async keepAside (c, sq, left) {
|
|
372
|
-
const line = sq.line || this.line || 'main'
|
|
373
|
-
const at = this.now()
|
|
374
|
-
const mine = []
|
|
375
|
-
for (const x of left) {
|
|
376
|
-
const r = await c.cat(this.quilt, `c:${sq.head}`, x.path, { format: 'snapshot' })
|
|
377
|
-
const s = r && r.conflict && r.content ? sidesOf(Buffer.from(r.content, 'base64').toString('utf8')) : null
|
|
378
|
-
mine.push({ path: x.path, text: s ? s.ours : null, known: !!s })
|
|
379
|
-
}
|
|
380
|
-
const paths = left.map((x) => x.path)
|
|
381
|
-
const kept = await c.openSquare(this.quilt, { title: keptTitle(paths, at), line })
|
|
382
|
-
const changes = mine.filter((m) => m.known).map((m) => m.text == null ? { path: m.path, op: 'delete' } : { path: m.path, op: 'put', content: Buffer.from(m.text, 'utf8').toString('base64') })
|
|
383
|
-
if (changes.length) await c.commit(this.quilt, kept.id, { expect_head: null, message: `${keptTitle(paths, at)} (from square ${squareShort(sq.id)})`, changes })
|
|
384
|
-
let head = sq.head
|
|
385
|
-
for (const x of left) {
|
|
386
|
-
const r = await c.resolve(this.quilt, sq.id, { expect_head: head, entries: [{ path: x.path, choose: 'theirs' }], remember: false })
|
|
387
|
-
head = (r && r.square && r.square.head) || head
|
|
388
|
-
}
|
|
389
|
-
if (this.block.moveTo && head) await this.block.moveTo(head).catch(() => {})
|
|
390
|
-
this.closeAsks(sq, `Quilt kept ${line}'s side and put ${this.person}'s version in square ${squareShort(kept.id)}.`)
|
|
391
|
-
this.state = { kept: { paths, square: kept.id, title: keptTitle(paths, at), at } }
|
|
392
|
-
this.keptNote = { paths, kept: kept.id }
|
|
393
|
-
this.log(`kept ${line}'s side of ${listed(paths)} in square ${squareShort(sq.id)}; your version is in square ${squareShort(kept.id)} ("${keptTitle(paths, at)}").`)
|
|
394
|
-
// The held work merges now: no wait for quiet, the person did nothing since.
|
|
395
|
-
// The rest of the held work (anything still live, not committed) goes with it.
|
|
396
|
-
const now = await c.square(this.quilt, sq.id)
|
|
397
|
-
let r = null
|
|
398
|
-
if (now && !now.conflicted_paths) {
|
|
399
|
-
const held = new Set(this.block.heldPaths ? this.block.heldPaths() : [])
|
|
400
|
-
const work = (this.block.status ? this.block.status() : []).filter((x) => !held.has(x.path))
|
|
401
|
-
let to = now.head
|
|
402
|
-
if (work.length) { const w = await this.block.commit({ message: landMessage(work.map((x) => x.path)) }); to = (w && w.square && w.square.head) || to }
|
|
403
|
-
if (to) r = await this.merge(c, now, to)
|
|
404
|
-
}
|
|
405
|
-
// Told once: with the patch when it landed now, else at once (it lands on a later look).
|
|
406
|
-
if (this.keptNote) { const n = this.keptNote; this.keptNote = null; this.notify(keptNotice({ ...n, line })) }
|
|
407
|
-
if (!r) this.soon(1000)
|
|
408
|
-
return { ...(r || { did: 'kept' }), kept: kept.id }
|
|
409
|
-
}
|
|
410
|
-
}
|