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/held.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
// Held conflicts (
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// branch
|
|
7
|
-
// (a branch document is read-only once the session is in Seam, and a square's live document only
|
|
8
|
-
// reaches the members on that square).
|
|
1
|
+
// Held conflicts (ruling 2026-11-13): a live write whose lines clashed with what had landed first.
|
|
2
|
+
// The shared file keeps the first-landed version; the writer's clashing lines are kept here, in the
|
|
3
|
+
// room's document, so every member's app and every AI (local MCP, hosted MCP, quilt_status) sees
|
|
4
|
+
// each open one until someone resolves it. Nothing holds the file meanwhile. One map for the whole
|
|
5
|
+
// session, whatever branch the file is on, because the room's document is the one every member has
|
|
6
|
+
// (a branch's document only reaches the members on that branch).
|
|
9
7
|
import crypto from 'node:crypto'
|
|
10
8
|
import { isSafeRelPath } from './pathrules.js'
|
|
11
9
|
|
|
@@ -17,10 +15,7 @@ export const MAX_HUNKS = 20
|
|
|
17
15
|
export const MAX_HUNK_LINES = 40
|
|
18
16
|
export const MAX_HELD = 60
|
|
19
17
|
export const DONE_TTL_MS = 24 * 60 * 60 * 1000
|
|
20
|
-
//
|
|
21
|
-
export const STALE_WRITE_MINUTES = 15
|
|
22
|
-
export const SETTINGS_MAP = 'mergeSettings'
|
|
23
|
-
// Seam's 07 "Who is asked to resolve, and the escalation budget" (ruling 2026-10-30): an open record
|
|
18
|
+
// Who is asked to resolve, and when it goes further (ruling 2026-10-30): an open record
|
|
24
19
|
// nobody resolved in ESCALATE_MS tells its writer's person (an agent's: the person it works for); at
|
|
25
20
|
// ADMIN_MS the session's owner is told too. Each once per record (`flagged4`, `flagged24`). The relay
|
|
26
21
|
// does it (server.js sweepHeld), so it happens whatever AI tool wrote it and with nobody's app open.
|
|
@@ -63,6 +58,7 @@ export function publicHeld (v) {
|
|
|
63
58
|
by: flat(v.by, 80),
|
|
64
59
|
byId: typeof v.byId === 'string' ? v.byId.slice(0, 128) : null,
|
|
65
60
|
others: Array.isArray(v.others) ? v.others.filter((n) => typeof n === 'string').slice(0, 10).map((n) => flat(n, 80)) : [],
|
|
61
|
+
// Where the file is: { branch }. A record stored by an earlier version may name a `square` instead: it is read as it is.
|
|
66
62
|
where: v.where && typeof v.where === 'object' ? { ...(typeof v.where.branch === 'string' ? { branch: v.where.branch.slice(0, 200) } : {}), ...(typeof v.where.square === 'string' ? { square: v.where.square.slice(0, 64) } : {}) } : {},
|
|
67
63
|
ts: v.ts,
|
|
68
64
|
hunks: publicHunks(v.hunks),
|
|
@@ -261,7 +257,7 @@ const overlaps = (x, y) => {
|
|
|
261
257
|
const sameWhere = (x, y) => ((x && x.branch) || '') === ((y && y.branch) || '') && ((x && x.square) || '') === ((y && y.square) || '')
|
|
262
258
|
|
|
263
259
|
/**
|
|
264
|
-
* The open record a new clash of `fields` joins: on the same path and branch
|
|
260
|
+
* The open record a new clash of `fields` joins: on the same path and branch, on the same lines (or
|
|
265
261
|
* the same whole file). A writer that has a version there already joins only when its new clash covers every
|
|
266
262
|
* line of that version (its newer version of the same lines replaces the older one, losing nothing).
|
|
267
263
|
*/
|
|
@@ -504,43 +500,6 @@ function pruneIn (map, now = Date.now()) {
|
|
|
504
500
|
if (tm) for (const key of [...tm.keys()]) if (!live(key.split('\0')[0])) tm.delete(key)
|
|
505
501
|
}
|
|
506
502
|
|
|
507
|
-
/**
|
|
508
|
-
* The paths with an open held conflict on square `square` (Seam's 07 "Terms held aside": a path with a
|
|
509
|
-
* held term counts as conflicted, so it cannot land until it is resolved). `square` may be a prefix of
|
|
510
|
-
* the id, or the id of a record's prefix. Records held on a branch document are not a square's.
|
|
511
|
-
*/
|
|
512
|
-
export function heldPathsOn (list, square) {
|
|
513
|
-
const sq = String(square || '').replace(/^sq:/, '')
|
|
514
|
-
if (!sq) return []
|
|
515
|
-
const on = (r) => r && r.state === 'open' && r.where && !r.where.branch && typeof r.where.square === 'string' && r.where.square && (r.where.square.startsWith(sq) || sq.startsWith(r.where.square))
|
|
516
|
-
return [...new Set((list || []).filter(on).map((r) => r.path))]
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
/** Why a commit or merge leaves `paths` out (an open held conflict on each); `none`: nothing else was there to land. */
|
|
520
|
-
export function heldLandingNote (paths, { none = false } = {}) {
|
|
521
|
-
const one = paths.length === 1
|
|
522
|
-
const named = paths.slice(0, 5).map((p) => `\`${p}\``).join(', ') + (paths.length > 5 ? ` and ${paths.length - 5} more` : '')
|
|
523
|
-
return `${named} ${one ? 'has an open held conflict' : 'have open held conflicts'} (two writes changed the same lines and the second writer's are held), so ${one ? 'it does' : 'they do'} not land until resolved: ${none ? 'nothing else was there to commit' : 'everything else landed'}. ` +
|
|
524
|
-
`Resolve ${one ? 'it' : 'each'} with quilt_resolve_merge { path, how: "theirs" (drop the held lines), "mine" (put them in) or "edited" (you fixed the file yourself) }, then commit again.`
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
/** The session's `stale_write_minutes`: the owner's setting (as voice's transcripts are), else 15. */
|
|
528
|
-
export function staleWriteMinutes (doc, members = []) {
|
|
529
|
-
const v = doc && doc.getMap(SETTINGS_MAP).get('staleWriteMinutes')
|
|
530
|
-
const owner = (members || []).find((m) => m && m.role === 'owner')
|
|
531
|
-
if (!v || typeof v !== 'object' || !owner || v.by !== owner.name) return STALE_WRITE_MINUTES
|
|
532
|
-
const n = Number(v.minutes)
|
|
533
|
-
return Number.isFinite(n) && n >= 0 && n <= 24 * 60 ? n : STALE_WRITE_MINUTES
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
/** The owner sets `stale_write_minutes` for everyone in the session (0 turns the check off). */
|
|
537
|
-
export function setStaleWriteMinutes (doc, { minutes, by, now = Date.now() }) {
|
|
538
|
-
const n = Number(minutes)
|
|
539
|
-
if (!Number.isFinite(n) || n < 0 || n > 24 * 60) throw new Error('stale_write_minutes is a number of minutes from 0 to 1440')
|
|
540
|
-
doc.getMap(SETTINGS_MAP).set('staleWriteMinutes', { minutes: Math.round(n), by, ts: now })
|
|
541
|
-
return Math.round(n)
|
|
542
|
-
}
|
|
543
|
-
|
|
544
503
|
const ago = (ts, now = Date.now()) => {
|
|
545
504
|
const s = Math.max(0, Math.round((now - ts) / 1000))
|
|
546
505
|
if (s < 60) return `${s}s ago`
|
|
@@ -550,8 +509,8 @@ const ago = (ts, now = Date.now()) => {
|
|
|
550
509
|
|
|
551
510
|
const WHAT = {
|
|
552
511
|
lines: (r) => `${r.others.length ? `${r.others.join(', ')} had changed` : 'someone had changed'} the same lines first`,
|
|
553
|
-
stale: () => 'the
|
|
554
|
-
parse: () => 'the merged file would not parse',
|
|
512
|
+
stale: () => 'the save was made from an older copy and lacks lines changed since',
|
|
513
|
+
parse: () => 'the merged file would not parse', // records from before 0.3.175
|
|
555
514
|
binary: (r) => `${r.others.length ? r.others.join(', ') : 'someone'} changed it first`
|
|
556
515
|
}
|
|
557
516
|
|
|
@@ -602,7 +561,7 @@ export function describeHeld (r) {
|
|
|
602
561
|
}
|
|
603
562
|
|
|
604
563
|
/** quilt_resolve_merge's description, the same for the local and the hosted MCP. */
|
|
605
|
-
export const RESOLVE_DESCRIPTION = 'Resolve a held conflict. When two writes change the same lines, the file keeps the version that landed first and the second writer\'s lines are held; clashes on the same lines join one open conflict that keeps each writer\'s held version.
|
|
564
|
+
export const RESOLVE_DESCRIPTION = 'Resolve a held conflict. When two writes change the same lines, the file keeps the version that landed first and the second writer\'s lines are held; clashes on the same lines join one open conflict that keeps each writer\'s held version. A save made from an older copy of the file is put onto that copy first, so what a teammate changed since stays. ' +
|
|
606
565
|
'Every open one is listed at the top of every Quilt answer until it is resolved. A conflict must not sit: its writer\'s AI is woken at once and asked first, and while you have one of your own, moving a task to QA or Done, quilt_set_work "done" and commits are refused. If its writer\'s AI has left or gone quiet it is handed to another AI in the session; any AI may take it, and nothing holds the file meanwhile. ' +
|
|
607
566
|
'Give the path or id, and how: "theirs" drops the held lines (the file stays as it is), "mine" puts your held lines (or the first held version, when none is yours) over the shared ones, merged with whatever changed since, "edited" says you already wrote the resolved file (if that write of yours was held in this conflict, it goes in). ' +
|
|
608
567
|
'Without how, it shows the conflict in full: each held version\'s hunks with their base, the kept lines and the held ones. Resolving one already resolved is harmless and says so. ' +
|
package/src/history.js
CHANGED
|
@@ -261,22 +261,6 @@ export function queryHistory (entries, { path, by, since, task, limit = 50 } = {
|
|
|
261
261
|
return list
|
|
262
262
|
}
|
|
263
263
|
|
|
264
|
-
export const LEGACY_DAYS = 90
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* The chronology once the session became a quilt at `at` (an ISO date, meta.quilt.at): entries from
|
|
268
|
-
* before then are its legacy tail (Seam's plans/quilt-source-control/16), marked `legacy: true` for
|
|
269
|
-
* LEGACY_DAYS and then left out. Not a quilt (no `at`): the entries as they are.
|
|
270
|
-
*/
|
|
271
|
-
export function legacyTail (entries, { at, now = Date.now(), history = false } = {}) {
|
|
272
|
-
const t = at ? Date.parse(at) : NaN
|
|
273
|
-
if (!Number.isFinite(t)) return entries
|
|
274
|
-
if (now - t > LEGACY_DAYS * 24 * 60 * 60 * 1000) return entries.filter((e) => !(e && e.ts < t))
|
|
275
|
-
// With history (the quilt is the session's imported git remote), git's own writes before then
|
|
276
|
-
// (pulls, first copies) are the log's imported patches: they are dropped, not shown twice.
|
|
277
|
-
return entries.filter((e) => !(history && e && e.ts < t && (e.pulled || e.seed))).map((e) => e && e.ts < t ? { ...e, legacy: true } : e)
|
|
278
|
-
}
|
|
279
|
-
|
|
280
264
|
function ago (ts, now) {
|
|
281
265
|
const s = Math.max(0, Math.round((now - ts) / 1000))
|
|
282
266
|
if (s < 60) return `${s}s ago`
|
|
@@ -290,18 +274,10 @@ export function formatHistory (list, { withDiff = false, now = Date.now() } = {}
|
|
|
290
274
|
if (!list.length) return 'No changes match.'
|
|
291
275
|
const out = []
|
|
292
276
|
for (const e of list) {
|
|
293
|
-
if (e.seam) {
|
|
294
|
-
// A commit in the quilt's log (quilt-history.js): who, which patch, its message, how many files.
|
|
295
|
-
const where = e.patch ? `patch ${e.patch.line && e.patch.line !== 'main' ? `${e.patch.line}:` : ''}${e.patch.no}` : `commit ${e.short || String(e.commit || '').slice(0, 12)}`
|
|
296
|
-
const n = e.files ? ` (${e.files} file${e.files === 1 ? '' : 's'})` : ''
|
|
297
|
-
out.push(`[${ago(e.ts, now)}] ${e.by} committed ${where}: ${e.message || '(no message)'}${n}${e.task ? ` [task ${e.task.id}]` : ''}`)
|
|
298
|
-
if (withDiff && e.diff) out.push(e.diff, '')
|
|
299
|
-
continue
|
|
300
|
-
}
|
|
301
277
|
const span = e.from && e.ts - e.from > 60000 ? ` over ${Math.round((e.ts - e.from) / 60000)}m` : ''
|
|
302
278
|
const what = e.detail ? ` (${e.detail})` : ''
|
|
303
279
|
const task = e.task ? ` for "${e.task.title}" [${e.task.id}]` : ''
|
|
304
|
-
out.push(`[${ago(e.ts, now)}] ${e.by} ${e.kind} ${e.path}${what}${e.pulled ? ' by pulling from git' : ''}${span}${task}
|
|
280
|
+
out.push(`[${ago(e.ts, now)}] ${e.by} ${e.kind} ${e.path}${what}${e.pulled ? ' by pulling from git' : ''}${span}${task}`)
|
|
305
281
|
if (withDiff && e.diff) out.push(e.diff, '')
|
|
306
282
|
}
|
|
307
283
|
return out.join('\n').replace(/\n+$/, '')
|
package/src/live-merge.js
CHANGED
|
@@ -1,36 +1,32 @@
|
|
|
1
|
-
// What happens to a live write when it arrives
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
1
|
+
// What happens to a live write when it arrives: it is merged against the version its writer started
|
|
2
|
+
// from, as git merges two branches, in milliseconds, with no AI and no project code. A clash is two
|
|
3
|
+
// writers changing the same lines since the writer's copy, and nothing else (2026-11-15, Daniel: the
|
|
4
|
+
// 15-minute rule and the parse rule, which held writes that clashed with nothing, are gone). One engine
|
|
5
|
+
// for every live path: on the relay, a folder's save sent as a live write (relay-live-write.js, from
|
|
6
|
+
// session.js ingest), a hosted agent's quilt_write_file and a sandboxed agent's `quilt sync`
|
|
7
|
+
// (relay-mcp.js, relay-turn-sync.js); in a folder, what a relay without
|
|
7
8
|
// live writes leaves to it, and offline merges (session.js autoSettle).
|
|
8
9
|
//
|
|
9
10
|
// same lines both changed them: the shared file keeps what landed first, the writer's lines are held
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
// nothing is taken for an edit because it looks like one.
|
|
11
|
+
// older copy the save was made from a text older than its folder's last one (base-pick.js): it is put onto
|
|
12
|
+
// that text first, so what changed since stays; lines both changed are a same-line clash
|
|
13
13
|
// removed name an identifier gone from the file is still used elsewhere: a warning, never a block
|
|
14
|
-
// parse a .json or plain .js file the merge broke: the whole write is held
|
|
15
14
|
// moves one writer deleted a path and added the same text elsewhere: edits to the old path follow
|
|
16
15
|
//
|
|
17
16
|
// Held lines go to the room's document (held.js), where every member's app and AI sees them. Clashes on the
|
|
18
17
|
// same lines join one open record; a record's version closes by itself when its writer's own later write to
|
|
19
18
|
// those lines lands, or when its held lines already match the file.
|
|
20
|
-
import vm from 'node:vm'
|
|
21
19
|
import path from 'node:path'
|
|
22
20
|
import { diffLines as diffIndices } from './textdiff.js'
|
|
23
|
-
import { mergeLive } from './merge3.js'
|
|
24
|
-
import { HELD_MAP, addHeld, readHeld, dropVersions, heldRegions, locateHunk, overBudget, heldTaskTitle
|
|
21
|
+
import { mergeLive, withHeldMarkers } from './merge3.js'
|
|
22
|
+
import { HELD_MAP, addHeld, readHeld, dropVersions, heldRegions, locateHunk, overBudget, heldTaskTitle } from './held.js'
|
|
25
23
|
|
|
26
|
-
export const ADDS_MAP = 'lineAdds' // in the file's document: "<path>\0<writer>" -> [{ ts, lines }]
|
|
27
24
|
export const MOVES_MAP = 'moves' // in the file's document: old path -> { to, by, ts, text }
|
|
28
25
|
export const MOVE_MS = 2 * 60 * 1000 // a deletion and an add of the same text by one writer this close together are a move
|
|
29
26
|
export const MOVE_KEEP_MS = 30 * 60 * 1000 // and edits to the old path follow it to the new one for this long
|
|
30
27
|
export const MAX_NAME_TEXT = 512 * 1024 // files past this are not searched for removed names
|
|
31
28
|
export const MAX_NAMES = 10
|
|
32
29
|
export const MAX_USES = 10
|
|
33
|
-
const ADDS_PER_KEY = 20
|
|
34
30
|
const MAX_MOVE_TEXT = 64 * 1024
|
|
35
31
|
|
|
36
32
|
const lines = (s) => String(s ?? '').split('\n')
|
|
@@ -50,61 +46,6 @@ export function addedLines (before, after) {
|
|
|
50
46
|
return out
|
|
51
47
|
}
|
|
52
48
|
|
|
53
|
-
/**
|
|
54
|
-
* The stale-write check: `next` is what a write would make of `cur` (the shared text). Any change of
|
|
55
|
-
* it that erases one of `protect` (lines someone else added recently) is undone, so those lines stay;
|
|
56
|
-
* each undone change is a hunk held for the writer to confirm. A hunk that puts other lines in a
|
|
57
|
-
* protected line's place changes that line: it is held too, marked `edit` (a same-line clash). Nothing
|
|
58
|
-
* is told apart by what the lines look like. { text, held, lines }.
|
|
59
|
-
*/
|
|
60
|
-
export function protectLines (cur, next, protect) {
|
|
61
|
-
const P = new Set((protect || []).filter(significant))
|
|
62
|
-
if (!P.size || cur === next) return { text: next, held: [], lines: [] }
|
|
63
|
-
const a = lines(cur)
|
|
64
|
-
const b = lines(next)
|
|
65
|
-
const ca = counts(a)
|
|
66
|
-
const cb = counts(b)
|
|
67
|
-
const out = []
|
|
68
|
-
const held = []
|
|
69
|
-
const kept = new Set()
|
|
70
|
-
let pos = 0
|
|
71
|
-
for (const h of diffIndices(a, b)) {
|
|
72
|
-
const [bs, bl] = h.buffer2
|
|
73
|
-
out.push(...b.slice(pos, bs))
|
|
74
|
-
const lost = h.buffer1Content.filter((l) => P.has(l) && (cb.get(l) || 0) < (ca.get(l) || 0))
|
|
75
|
-
if (lost.length) {
|
|
76
|
-
const edit = h.buffer2Content.some(significant)
|
|
77
|
-
held.push({ at: out.length, base: h.buffer1Content, ours: h.buffer2Content, theirs: h.buffer1Content, ...(edit ? { edit: true } : {}) })
|
|
78
|
-
out.push(...h.buffer1Content)
|
|
79
|
-
for (const l of lost) kept.add(l)
|
|
80
|
-
} else out.push(...h.buffer2Content)
|
|
81
|
-
pos = bs + bl
|
|
82
|
-
}
|
|
83
|
-
out.push(...b.slice(pos))
|
|
84
|
-
return { text: out.join('\n'), held, lines: [...kept] }
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const MODULE = /^\s*(import\s*[\w{*'"]|export\s|export\{)/m
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Why `text` does not parse as `p`'s language, or null when it does or there is nothing to check
|
|
91
|
-
* it with: a .json file must JSON.parse; a plain .js/.cjs file (no top-level import or export) must
|
|
92
|
-
* compile as a script. Nothing else is checked (no parser dependency).
|
|
93
|
-
*/
|
|
94
|
-
export function parseProblem (p, text) {
|
|
95
|
-
const ext = path.posix.extname(String(p)).toLowerCase()
|
|
96
|
-
if (ext === '.json') {
|
|
97
|
-
try { JSON.parse(text); return null } catch (err) { return err.message }
|
|
98
|
-
}
|
|
99
|
-
if (ext === '.js' || ext === '.cjs') {
|
|
100
|
-
if (MODULE.test(text)) return null
|
|
101
|
-
const body = String(text).replace(/^#!.*/, '')
|
|
102
|
-
// Compiled as a function body, never run: a CommonJS file may `return` at its top level.
|
|
103
|
-
try { new vm.Script(`(function () {\n${body}\n})`, { filename: p }); return null } catch (err) { return err.message } // eslint-disable-line no-new
|
|
104
|
-
}
|
|
105
|
-
return null
|
|
106
|
-
}
|
|
107
|
-
|
|
108
49
|
const KEYWORDS = new Set(('abstract arguments async await boolean break byte case catch char class const continue debugger default delete do double else enum eval export extends false final finally float for function goto if implements import in instanceof int interface let long native new null package private protected public return short static super switch synchronized this throw throws transient true try typeof var void volatile while with yield ' +
|
|
109
50
|
'undefined NaN Infinity console window document require module exports process global globalThis ' +
|
|
110
51
|
'def elif except lambda nonlocal pass raise None True False self from print assert ' +
|
|
@@ -227,42 +168,6 @@ export function applyMine (rec, current, { mine = rec && rec.mine, result = rec
|
|
|
227
168
|
return r.held.length ? r.mine : r.text
|
|
228
169
|
}
|
|
229
170
|
|
|
230
|
-
/** What others added to `p` in `doc` since `since` (not by `not`): one entry per write, [{ by, ts, lines }]. */
|
|
231
|
-
export function recentAdds (doc, p, { not = '', since = 0 } = {}) {
|
|
232
|
-
const out = []
|
|
233
|
-
if (!doc) return out
|
|
234
|
-
const m = doc.getMap(ADDS_MAP)
|
|
235
|
-
const prefix = `${p}\0`
|
|
236
|
-
m.forEach((list, key) => {
|
|
237
|
-
const by = key.slice(prefix.length)
|
|
238
|
-
if (!key.startsWith(prefix) || by === not || !Array.isArray(list)) return
|
|
239
|
-
for (const e of list) if (e && e.ts >= since && Array.isArray(e.lines)) out.push({ by, ts: e.ts, lines: e.lines.filter((l) => typeof l === 'string') })
|
|
240
|
-
})
|
|
241
|
-
return out
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/** The lines a write must not erase or change without asking: every significant line of each recent addition by someone else. */
|
|
245
|
-
export const recentLines = (adds) => adds.flatMap((e) => e.lines.filter(significant))
|
|
246
|
-
|
|
247
|
-
/** Notes lines `by` added to `p` now (`keepMs`: older entries are dropped as it goes). */
|
|
248
|
-
export function noteAdds (doc, p, by, added, { now = Date.now(), keepMs = STALE_WRITE_MINUTES * 60_000 } = {}) {
|
|
249
|
-
if (!doc || !by) return
|
|
250
|
-
const m = doc.getMap(ADDS_MAP)
|
|
251
|
-
const key = `${p}\0${by}`
|
|
252
|
-
const old = Array.isArray(m.get(key)) ? m.get(key) : []
|
|
253
|
-
const kept = old.filter((e) => e && now - e.ts <= keepMs)
|
|
254
|
-
const cut = (l) => String(l).slice(0, 500)
|
|
255
|
-
const ls = added.slice(0, 200).map(cut)
|
|
256
|
-
const next = added.length ? [...kept, { ts: now, lines: ls }].slice(-ADDS_PER_KEY) : kept
|
|
257
|
-
if (next.length) { if (next.length !== old.length || added.length) m.set(key, next) } else if (m.has(key)) m.delete(key)
|
|
258
|
-
// Anyone's entries gone stale with nothing newer: nobody needs them.
|
|
259
|
-
const stale = []
|
|
260
|
-
m.forEach((list, k) => { if (k !== key && Array.isArray(list) && !list.some((e) => e && now - e.ts <= keepMs)) stale.push(k) })
|
|
261
|
-
for (const k of stale) m.delete(k)
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// Names a write removed from a file lately (removedNames), in the room's document, so a use another write
|
|
265
|
-
// adds of one still gone is said to its writer: name -> { path, by, ts }.
|
|
266
171
|
export const GONE_NAMES_MAP = 'goneNames'
|
|
267
172
|
export const GONE_KEEP_MS = 60 * 60 * 1000
|
|
268
173
|
const GONE_MAX = 200
|
|
@@ -315,22 +220,32 @@ export function goneNameWarning (p, list, me = '') {
|
|
|
315
220
|
return `${parts.join('; ')}. Nothing was blocked: check it still exists (it may have been renamed or moved).`
|
|
316
221
|
}
|
|
317
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
|
+
|
|
318
233
|
/**
|
|
319
234
|
* The engine both live paths share, one per session. Options: `room()` the room's Y.Doc (held
|
|
320
|
-
* conflicts
|
|
235
|
+
* conflicts); `notice(text)` for the writer's AI;
|
|
321
236
|
* `log(text)`; `texts()` the session's text files as [path, text] for the removed-name search;
|
|
322
237
|
* `origin` for the room's transactions; `folder` false for a writer with no folder (a hosted agent),
|
|
323
238
|
* which its notices say.
|
|
324
239
|
*/
|
|
325
240
|
export class LiveRules {
|
|
326
|
-
constructor ({ room,
|
|
327
|
-
Object.assign(this, { room,
|
|
241
|
+
constructor ({ room, notice = () => {}, log = () => {}, texts = () => [], origin = null, keepLocal = null, folder = true }) {
|
|
242
|
+
Object.assign(this, { room, notice, log, texts, origin, keepLocal, folder })
|
|
328
243
|
this.recentGone = new Map() // path -> { text, by, ts }: deletions by this folder, for moves
|
|
329
244
|
this.recentNew = new Map() // path -> { text, by, ts }: files this folder created, for moves
|
|
330
|
-
this.trusted = new Map() // path -> text a resolution wrote to disk
|
|
245
|
+
this.trusted = new Map() // path -> text a resolution wrote to disk: made from the folder's last text, whatever it looks like
|
|
331
246
|
}
|
|
332
247
|
|
|
333
|
-
/** The next
|
|
248
|
+
/** The next save of `p` with exactly `text` is a resolution's ("mine"): its base is the folder's last text (base-pick.js). */
|
|
334
249
|
trust (p, text) { this.trusted.set(p, text) }
|
|
335
250
|
|
|
336
251
|
heldMap () { const d = this.room(); return d ? d.getMap(HELD_MAP) : null }
|
|
@@ -338,13 +253,13 @@ export class LiveRules {
|
|
|
338
253
|
/**
|
|
339
254
|
* One write of `p` by `by`: `ours` the writer's text, made on `base` (null when not known),
|
|
340
255
|
* `theirs` what the shared file holds now (null when it has nothing). `doc` is the file's own
|
|
341
|
-
* document (where additions and moves are kept). `where`: { branch }
|
|
256
|
+
* document (where additions and moves are kept). `where`: { branch }; `others`: who
|
|
342
257
|
* landed first; `union`: the project marks the path merge=union (.gitattributes), so both sides'
|
|
343
258
|
* lines go in where both changed them. Returns { text, held: [records], warnings: [strings] }:
|
|
344
259
|
* `text` is what the shared file and the writer's folder get.
|
|
345
260
|
* `older`: a save proven made from an older text than `base` (it landed in the file Quilt replaced: base-pick.js).
|
|
346
261
|
*/
|
|
347
|
-
write ({ doc, where = {}, path: p, base = null, ours, theirs = null, by, byId = null, others = [], texts = null, union = false,
|
|
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 }) {
|
|
348
263
|
const now = Date.now()
|
|
349
264
|
const map = this.heldMap()
|
|
350
265
|
const all = map ? readHeld(map) : []
|
|
@@ -358,7 +273,7 @@ export class LiveRules {
|
|
|
358
273
|
let olderLines = []
|
|
359
274
|
// Held are only the lines both the save and the newer text changed: a line the save merely has as the older
|
|
360
275
|
// text had it (it never touched it) takes the newer one, with nothing held.
|
|
361
|
-
if (typeof older === 'string' && typeof base === 'string' && older !== base
|
|
276
|
+
if (typeof older === 'string' && typeof base === 'string' && older !== base) {
|
|
362
277
|
const r0 = mergeLive(older, ours, base, { union })
|
|
363
278
|
if (r0.text !== ours) {
|
|
364
279
|
olderHeld = r0.held.map((h) => ({ at: h.at, base: h.base, ours: h.ours, theirs: h.theirs }))
|
|
@@ -373,45 +288,25 @@ export class LiveRules {
|
|
|
373
288
|
let text = ours
|
|
374
289
|
let mine = ours
|
|
375
290
|
let held = []
|
|
376
|
-
let kind = null
|
|
377
|
-
let parseWhy = ''
|
|
378
291
|
if (landed) {
|
|
379
292
|
const r = mergeLive(base, ours, theirs, { union })
|
|
380
293
|
text = r.text; mine = r.mine; held = r.held
|
|
381
|
-
if (held.length) kind = 'lines'
|
|
382
|
-
// Parse: a file both sides left parsing that the merge broke is the writer's to settle, whole.
|
|
383
|
-
const bad = text !== ours && text !== theirs ? parseProblem(p, held.length ? mine : text) : null
|
|
384
|
-
if (bad && !parseProblem(p, ours) && !parseProblem(p, theirs)) {
|
|
385
|
-
held = diffIndices(lines(theirs), lines(mine)).map((h) => ({ at: h.buffer1[0], base: h.buffer1Content, ours: h.buffer2Content, theirs: h.buffer1Content }))
|
|
386
|
-
text = theirs
|
|
387
|
-
kind = 'parse'
|
|
388
|
-
parseWhy = bad
|
|
389
|
-
}
|
|
390
294
|
}
|
|
391
|
-
//
|
|
392
|
-
//
|
|
393
|
-
//
|
|
394
|
-
|
|
395
|
-
|
|
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
|
+
}
|
|
396
304
|
const cur = typeof theirs === 'string' ? theirs : null
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
// A text a resolution wrote ("mine"): what it removes was decided by whoever resolved it.
|
|
400
|
-
const trusted = this.trusted.get(p) === ours
|
|
401
|
-
if (trusted) this.trusted.delete(p)
|
|
402
|
-
// The open records on this path, here (branch or square): this write may join, supersede or match them.
|
|
305
|
+
// The open records on this path, on this branch: this write may join, supersede or match them. (A record
|
|
306
|
+
// stored by an earlier version may name a `square` instead of a branch: it is no branch's.)
|
|
403
307
|
const sameWhere = (r) => ((r.where && r.where.branch) || '') === (where.branch || '') && ((r.where && r.where.square) || '') === (where.square || '')
|
|
404
308
|
const onPath = all.filter((r) => r.state === 'open' && r.path === p && sameWhere(r) && !overBudget(r) && r.kind !== 'parse' && r.kind !== 'binary')
|
|
405
309
|
const curLines = cur !== null ? lines(cur) : null
|
|
406
|
-
if (cur !== null && kind !== 'parse' && minutes > 0 && text !== cur && !trusted) {
|
|
407
|
-
const windowMs = minutes * 60_000
|
|
408
|
-
const adds = recentAdds(doc, p, { not: strict ? '' : by, since: now - windowMs })
|
|
409
|
-
const keep = recentLines(adds)
|
|
410
|
-
stale = protectLines(cur, text, keep)
|
|
411
|
-
preStale = text
|
|
412
|
-
text = stale.text
|
|
413
|
-
if (kind === 'lines') mine = protectLines(cur, mine, keep).text
|
|
414
|
-
}
|
|
415
310
|
// Open records on this path, closed version by version: a version whose writer's own write changed those
|
|
416
311
|
// lines and landed (superseded), or whose held lines the file already has (matches).
|
|
417
312
|
if (map && onPath.length && cur !== null) {
|
|
@@ -438,20 +333,8 @@ export class LiveRules {
|
|
|
438
333
|
const records = []
|
|
439
334
|
const who = others.filter((n) => n && n !== by)
|
|
440
335
|
if (held.length && map) {
|
|
441
|
-
const reason =
|
|
442
|
-
records.push(this.hold({ path: p, kind, by, byId, others: who, where, hunks: held, reason, result: text, mine }))
|
|
443
|
-
}
|
|
444
|
-
if (stale.held.length && map) {
|
|
445
|
-
// A line someone else wrote in the last minutes, changed by this write: a same-line clash.
|
|
446
|
-
const edits = stale.held.filter((h) => h.edit).map(({ edit, ...h }) => h)
|
|
447
|
-
const removed = stale.held.filter((h) => !h.edit)
|
|
448
|
-
const editLines = new Set(edits.flatMap((h) => h.theirs))
|
|
449
|
-
const whose = strict ? 'written' : `${who.join(', ') || 'someone else'} wrote`
|
|
450
|
-
if (edits.length) records.push(this.hold({ path: p, kind: 'lines', by, byId, others: who, where, hunks: edits, reason: `it changes line(s) ${whose} in the last ${minutes} minutes`, result: text, mine: preStale }))
|
|
451
|
-
if (removed.length) {
|
|
452
|
-
const ls = stale.lines.filter((l) => !editLines.has(l))
|
|
453
|
-
records.push(this.hold({ path: p, kind: 'stale', by, byId, others: who, where, hunks: removed, lines: ls, reason: `the write would erase ${ls.length} line(s) ${strict ? 'added' : 'someone else added'} in the last ${minutes} minutes${strict ? ', and the version it started from is not known' : ''}`, result: text, mine: preStale }))
|
|
454
|
-
}
|
|
336
|
+
const reason = `${who.join(', ') || 'Someone'} changed the same lines first`
|
|
337
|
+
records.push(this.hold({ path: p, kind: 'lines', by, byId, others: who, where, hunks: held, reason, result: text, mine }))
|
|
455
338
|
}
|
|
456
339
|
if (olderHeld.length && map) {
|
|
457
340
|
const n = olderHeld.length
|
|
@@ -460,9 +343,7 @@ export class LiveRules {
|
|
|
460
343
|
: `${who.join(', ') || 'Someone'} changed the same line(s) after the version this save was made from (an older read of ${p}); ${n === 1 ? 'that hunk keeps' : 'those hunks keep'} the newer lines`
|
|
461
344
|
records.push(this.hold({ path: p, kind: olderKind, by, byId, others: who, where, hunks: olderHeld, lines: olderLines, reason, result: text, mine: mergeLive(base, saved, text).text }))
|
|
462
345
|
}
|
|
463
|
-
// What this write added, for the next writer's stale check (with the lines they replaced).
|
|
464
346
|
const prev = cur ?? base ?? ''
|
|
465
|
-
if (doc && minutes > 0) noteAdds(doc, p, by, addedLines(prev, text), { now, keepMs: minutes * 60_000 })
|
|
466
347
|
// Removed names still used elsewhere: a warning, never a block (`nameSearch` false: the caller searches, with `gone`).
|
|
467
348
|
const warnings = []
|
|
468
349
|
const gone = removedNames(p, cur ?? base, text)
|