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.
Files changed (71) hide show
  1. package/README.md +6 -3
  2. package/RELEASES.md +30 -0
  3. package/bin/quilt.js +1 -75
  4. package/desktop/main.js +22 -9
  5. package/package.json +2 -3
  6. package/src/ai-vm.js +1 -1
  7. package/src/api/memory-store.js +1 -5
  8. package/src/api/server.js +4 -45
  9. package/src/api/supabase-store.js +0 -10
  10. package/src/autowork.js +7 -142
  11. package/src/base-pick.js +125 -12
  12. package/src/branch-view.js +1 -1
  13. package/src/connection.js +12 -37
  14. package/src/control.js +16 -93
  15. package/src/fsutil.js +1 -1
  16. package/src/git-aside.js +70 -0
  17. package/src/github-commit.js +1 -2
  18. package/src/gitstate.js +326 -0
  19. package/src/held.js +12 -53
  20. package/src/history.js +1 -25
  21. package/src/live-merge.js +42 -161
  22. package/src/mcp.js +6 -90
  23. package/src/merge3.js +21 -5
  24. package/src/pathrules.js +1 -1
  25. package/src/protocol.js +6 -11
  26. package/src/read-bases.js +3 -5
  27. package/src/relay-live-write.js +37 -44
  28. package/src/relay-mcp.js +30 -164
  29. package/src/relay-prune.js +3 -6
  30. package/src/relay-turn-sync.js +7 -11
  31. package/src/runner.js +2 -4
  32. package/src/server.js +61 -1717
  33. package/src/session.js +895 -844
  34. package/src/setup.js +11 -3
  35. package/src/status.js +2 -5
  36. package/src/swap-in.js +56 -13
  37. package/src/turn-sync-plan.js +2 -2
  38. package/src/turn-sync.js +1 -1
  39. package/src/ui/agent-guide.js +3 -1
  40. package/src/ui/app.css +4 -96
  41. package/src/ui/app.js +1 -1
  42. package/src/ui/chat.js +2 -6
  43. package/src/ui/cloud-ai-model.js +0 -13
  44. package/src/ui/cloud-ai.js +2 -10
  45. package/src/ui/connections.js +2 -1
  46. package/src/ui/fileview.js +7 -20
  47. package/src/ui/git-rule.js +2 -13
  48. package/src/ui/home.js +2 -8
  49. package/src/ui/session-words.js +27 -0
  50. package/src/ui/session.js +34 -407
  51. package/src/ui-server.js +7 -56
  52. package/src/api/routes/seam-connect.js +0 -103
  53. package/src/api/routes/session-migrate.js +0 -39
  54. package/src/force-date.js +0 -27
  55. package/src/quilt-default.js +0 -84
  56. package/src/quilt-history.js +0 -106
  57. package/src/quilt-remote.js +0 -78
  58. package/src/seam-access.js +0 -97
  59. package/src/seam-url.js +0 -15
  60. package/src/session-follow.js +0 -583
  61. package/src/session-layout3.js +0 -466
  62. package/src/session-migrate.js +0 -123
  63. package/src/session-quilt.js +0 -126
  64. package/src/session-seam.js +0 -312
  65. package/src/source-live/bring-in.js +0 -391
  66. package/src/source-live/land.js +0 -410
  67. package/src/source-live/live-block.js +0 -1166
  68. package/src/source-live/live-square.js +0 -116
  69. package/src/ui/force-words.js +0 -19
  70. package/src/ui/quiltview.js +0 -213
  71. package/src/ui/seam-model.js +0 -309
@@ -1,126 +0,0 @@
1
- // Quilt's side of Seam: what making a session a quilt would do, without doing it
2
- // (Seam's plans/quilt-source-control/16, "How a session becomes a quilt", "Dry run and check").
3
- // Pure: it reads a snapshot of the room (Room.quiltSnapshot in server.js) and returns the
4
- // report the owner reads before the real migration. Seam (src/quilts/) never imports this.
5
- //
6
- // Snapshot:
7
- // { room, owner, defaultKey, hasRemote,
8
- // branches: [{ key, by, files: { path: { hash, bytes } }, history: [entry], merges: [{ id, state }] }],
9
- // tasks: [{ id, pr }], commitRequests: n }
10
- // Options:
11
- // tip: { path: hash } the imported main's tree, when the room has a remote and its import exists.
12
- import { createHash } from 'node:crypto'
13
-
14
- export const fileHash = (text) => createHash('sha256').update(String(text)).digest('hex')
15
-
16
- const sumBytes = (files) => Object.values(files || {}).reduce((n, f) => n + (Number(f && f.bytes) || 0), 0)
17
-
18
- /** The paths whose content differs between a branch document's files and a tree, both `{ path: hash }`-like. */
19
- export function differingPaths (files, tree) {
20
- const out = []
21
- for (const [p, f] of Object.entries(files || {})) if (tree[p] !== (f && f.hash)) out.push(p)
22
- for (const p of Object.keys(tree || {})) if (!(p in (files || {}))) out.push(p)
23
- return out.sort()
24
- }
25
-
26
- /**
27
- * The dry run's report. `mode` is `with_history` for a room with a git remote (the import and
28
- * its follow come first; `needs_import` until a `tip` is given), else `without_history` (the
29
- * default branch document is sealed as patch 1).
30
- */
31
- export function planSessionQuilt (snap, { tip = null } = {}) {
32
- const withHistory = !!snap.hasRemote
33
- const defaultKey = snap.defaultKey
34
- const owner = snap.owner || ''
35
- const branches = (snap.branches || []).filter((b) => b && typeof b.key === 'string')
36
- const def = branches.find((b) => b.key === defaultKey) || null
37
- const squares = []
38
- const report = {
39
- room: snap.room,
40
- mode: withHistory ? 'with_history' : 'without_history',
41
- needs_import: withHistory && !tip,
42
- first_patch: null,
43
- squares,
44
- tasks: { matched: [], unmatched: [] },
45
- terms: 0,
46
- history: { kept: 0, dropped: 0 },
47
- commit_requests: Number(snap.commitRequests) || 0,
48
- bytes: 0
49
- }
50
- if (def && !withHistory) {
51
- report.first_patch = { from: def.key, message: `Session ${snap.room} as of <date>`, files: Object.keys(def.files || {}).length, bytes: sumBytes(def.files) }
52
- }
53
- if (def && withHistory && tip) {
54
- const paths = differingPaths(def.files, tip)
55
- if (paths.length) {
56
- squares.push({ from: def.key, title: `Uncommitted work from ${snap.room}`, base: 'import:main', holder: owner, adoption: true, files: paths.length, bytes: paths.reduce((n, p) => n + (Number(def.files[p] && def.files[p].bytes) || 0), 0) })
57
- }
58
- }
59
- const squareOf = new Map()
60
- for (const b of branches) {
61
- if (b.key === defaultKey) continue
62
- const at = /^@([0-9a-f]{7,64})$/.exec(b.key)
63
- const base = withHistory ? (at ? `commit:${at[1]}` : `import:${b.key}`) : 'patch:1'
64
- const sq = { from: b.key, title: b.key, base, holder: b.by || owner, adoption: false, files: Object.keys(b.files || {}).length, bytes: sumBytes(b.files) }
65
- squares.push(sq)
66
- squareOf.set(b.key, sq)
67
- }
68
- for (const t of snap.tasks || []) {
69
- if (!t || !t.pr) continue
70
- const b = t.pr.branch
71
- if (b && squareOf.has(b)) report.tasks.matched.push({ id: t.id, square_from: b })
72
- else report.tasks.unmatched.push({ id: t.id, pr: t.pr.number || null })
73
- }
74
- for (const b of branches) {
75
- report.terms += (b.merges || []).filter((m) => m && (m.state === 'open' || m.state === 'editing')).length
76
- for (const h of b.history || []) {
77
- if (withHistory && h && (h.pulled || h.seed)) report.history.dropped++
78
- else report.history.kept++
79
- }
80
- }
81
- report.bytes = squares.reduce((n, s) => n + s.bytes, 0) + (report.first_patch ? report.first_patch.bytes : 0)
82
- report.problems = [
83
- ...report.tasks.unmatched.map((t) => `task ${t.id}'s pull request${t.pr ? ` #${t.pr}` : ''} has no square; it becomes a task comment`)
84
- ]
85
- return report
86
- }
87
-
88
- export const MIGRATE_SESSION_DESCRIPTION =
89
- 'What making this session a quilt (Quilt\'s own source control, Seam) would do, read only: the first patch or the import, ' +
90
- 'which branches become squares, how tasks with pull requests move, and anything that would not carry over. ' +
91
- 'Only the session\'s owner (or, in a session without one, anyone who may change files) can ask. Nothing changes.'
92
-
93
- /** Why `a` (the asker's access) may not see the dry run, or null when they may. */
94
- export function quiltPlanRefusal ({ controlled, access }) {
95
- if (controlled ? !(access && access.owner) : !!(access && access.role === 'viewer')) return 'only the session\'s owner can see what making it a quilt would do'
96
- return null
97
- }
98
-
99
- const kb = (n) => n >= 1024 * 1024 ? `${(n / 1024 / 1024).toFixed(1)} MB` : `${Math.ceil(n / 1024)} KB`
100
-
101
- /** The dry run's report as plain text, for an agent or a person. */
102
- export function describeQuiltPlan (p) {
103
- const out = [`Making session ${p.room} a quilt (dry run, nothing changed):`]
104
- if (p.mode === 'with_history') {
105
- out.push(p.needs_import
106
- ? '- The session has a git remote: its history comes in by an import that follows the remote first (seam import), then the session moves.'
107
- : '- History comes from the import of the session\'s git remote.')
108
- } else if (p.first_patch) {
109
- out.push(`- Patch 1 is the ${p.first_patch.from} branch as it is now: ${p.first_patch.files} file${p.first_patch.files === 1 ? '' : 's'}, ${kb(p.first_patch.bytes)}.`)
110
- } else {
111
- out.push('- The session has no default branch document: patch 1 starts empty.')
112
- }
113
- if (p.squares.length) {
114
- out.push(`- ${p.squares.length} square${p.squares.length === 1 ? '' : 's'}:`)
115
- for (const s of p.squares) out.push(` - ${s.title} from ${s.from}, on ${s.base}, held by ${s.holder || 'nobody'}: ${s.files} file${s.files === 1 ? '' : 's'}`)
116
- } else out.push('- No squares: there is no other branch with work on it.')
117
- if (p.tasks.matched.length) out.push(`- ${p.tasks.matched.length} task${p.tasks.matched.length === 1 ? '' : 's'} with a pull request link${p.tasks.matched.length === 1 ? 's' : ''} to a square.`)
118
- if (p.terms) out.push(`- ${p.terms} open merge${p.terms === 1 ? '' : 's'} become${p.terms === 1 ? 's' : ''} terms on their squares.`)
119
- out.push(`- History: ${p.history.kept} entr${p.history.kept === 1 ? 'y' : 'ies'} kept${p.history.dropped ? `, ${p.history.dropped} dropped (they are in the import)` : ''}.`)
120
- if (p.commit_requests) out.push(`- ${p.commit_requests} commit request${p.commit_requests === 1 ? '' : 's'} must be done or withdrawn first.`)
121
- if (p.problems && p.problems.length) {
122
- out.push('Would not carry over:')
123
- for (const x of p.problems) out.push(`- ${x}`)
124
- }
125
- return out.join('\n')
126
- }
@@ -1,312 +0,0 @@
1
- // Quilt's side of Seam for agents (Seam's plans/quilt-source-control/12 and 16): in a session that is a
2
- // quilt, an agent works through Seam (squares, commits, merges), never GitHub. The same for every
3
- // AI tool: the session's own MCP server (`quilt mcp` in a folder, the relay's for hosted agents)
4
- // serves Seam's everyday tools itself, acting on the session's quilt and the folder's square with
5
- // the member's own Quilt sign-in (seam-access.js), so nothing is set up by hand. There, everything
6
- // an AI is told names only Seam (Daniel, 2026-10-31): the git-era tools are hidden (GIT_TOOLS) or
7
- // refuse with the Seam tool to use, the guidance leaves git out (seamOnly), a push that still
8
- // reaches the hook is refused, and the relay gives no GitHub token to an agent's git there.
9
- //
10
- // A session is a quilt when the relay is on Seam (QUILT_SOURCE_URL) and its room names its quilt
11
- // (meta.quilt_id, set by the migration with layout 3 and cleared when a failed check reverts it).
12
- // Every other session keeps its GitHub path exactly as it is, and offers no Seam tools.
13
- import { z } from 'zod'
14
- // Seam's tools, their descriptions and answers come from Seam's client package (@heyquilt/seam).
15
- import { registerSeamTools, SEAM_INPUTS, SEAM_DESCRIPTIONS } from '@heyquilt/seam/lib/quilts/tools.js'
16
- import { describeWrite } from '@heyquilt/seam/lib/quilts/describe.js'
17
- import { squareShort } from '@heyquilt/seam/lib/quilts/errors.js'
18
- import { heldPathsOn, heldLandingNote } from './held.js'
19
-
20
- /** The quilt a room's session is, or null while it is a GitHub-backed (or plain) session. */
21
- export function quiltOf (meta, env = process.env) {
22
- if (!env || !env.QUILT_SOURCE_URL) return null
23
- if (!meta) return null
24
- return typeof meta.quilt_id === 'string' && meta.quilt_id ? meta.quilt_id : null
25
- }
26
-
27
- /**
28
- * Seam's tools a session that is a quilt serves, the same for a folder's AI sessions and hosted
29
- * agents: the everyday ones (Seam's 'core' profile) an agent in a session needs. A folder's
30
- * square is the session's, so cloning, pulling, listing quilts and abandoning are left out.
31
- */
32
- export const SEAM_SESSION_TOOLS = ['seam_square_status', 'seam_commit', 'seam_merge', 'seam_rebase', 'seam_resolve', 'seam_diff', 'seam_log', 'seam_show', 'seam_cat', 'seam_ls', 'seam_grep', 'seam_blame', 'seam_checks', 'seam_events', 'seam_reviews', 'seam_review', 'seam_interdiff', 'seam_squares', 'seam_open_square']
33
-
34
- // Each GitHub tool, and the Seam tool an agent uses for it in a session that is a quilt.
35
- export const SEAM_FOR = {
36
- quilt_git_commit: 'seam_commit (commits your square)',
37
- quilt_git_status: 'seam_square_status (your square and what changed in it)',
38
- quilt_git_log: 'seam_log',
39
- quilt_git_diff: 'seam_diff',
40
- quilt_git_revert: 'seam_cat (the line\'s copy of a file, to write back)',
41
- quilt_git_pull_requests: 'seam_squares (the squares on a line) and seam_checks',
42
- quilt_git_merge: 'seam_merge (merges your square onto main once its checks pass)',
43
- quilt_git_branch: 'seam_square_status (your folder\'s square)',
44
- quilt_sync_branch: 'seam_square_status (a square follows its line: seam_rebase moves it onto the tip)',
45
- quilt_sync_status: 'seam_square_status',
46
- quilt_github_token: null, // nothing to use instead: the owner's export to GitHub has its own credential
47
- quilt_request_commit: 'seam_commit, then seam_merge once its checks pass (or ask a person to)',
48
- quilt_agent_commits: 'seam_log',
49
- quilt_commit_status: 'seam_square_status',
50
- quilt_commit_request_done: 'seam_square_status',
51
- quilt_github_sync: 'seam_square_status'
52
- }
53
-
54
- /** How work lands in a session that is a quilt, for an AI with a folder (its files are its square's live work). */
55
- export const SEAM_GUIDE = 'Edit files in your folder as always: they are your square\'s live work, shared at once with everyone on it. ' +
56
- 'Commit the square with seam_commit (it commits everything the square holds now, every writer\'s, so say why in the message), and merge it onto main with seam_merge once its checks pass (seam_checks; seam_events with wait: 30 waits for a verdict). ' +
57
- 'A conflict comes back as terms in your square: read them with seam_square_status and settle each with seam_resolve (or edit the file and commit), then merge again. ' +
58
- 'seam_diff, seam_log, seam_show and seam_blame read the history. Work lands only through these tools.'
59
-
60
- /** The same for a hosted agent, which has no folder. */
61
- export const SEAM_GUIDE_HOSTED = 'You have no folder: open a square of your own with seam_open_square, read files with seam_cat and seam_ls (rev: main or your square), and commit their new contents with seam_commit (files, square: your square). ' +
62
- 'Merge it onto main with seam_merge once its checks pass (seam_checks; seam_events with wait: 30 waits for a verdict). ' +
63
- 'A conflict comes back as terms in your square: read them with seam_square_status and settle each with seam_resolve (or commit the file without markers), then merge again. ' +
64
- 'Work lands only through these tools.'
65
-
66
- const guideFor = ({ hosted = false } = {}) => hosted ? SEAM_GUIDE_HOSTED : SEAM_GUIDE
67
-
68
- // How an agent hears of Seam: only as where the session's code is committed and merged. Chat, tasks and
69
- // the session itself stay in Quilt; nobody reaches a session through Seam.
70
- const codeIn = (quiltId) => `This session's code is committed and merged in Seam (the quilt ${quiltId})`
71
-
72
- /**
73
- * Why a git-era tool is refused in a quilt session: just the Seam tool to use (or, for one with no
74
- * counterpart, how work lands there); null when it isn't. An AI whose tool list is from before the
75
- * move may still call one that is hidden now.
76
- */
77
- export function seamRefusal (tool, quiltId, { hosted = false } = {}) {
78
- if (!quiltId) return null
79
- if (Object.hasOwn(SEAM_FOR, tool)) return `${codeIn(quiltId)}: ${SEAM_FOR[tool] ? `use ${SEAM_FOR[tool]} instead.` : 'Seam\'s tools need nothing set up.'}`
80
- return GIT_TOOLS.has(tool) ? `${codeIn(quiltId)}, where ${tool} is not used. ${guideFor({ hosted })}` : null
81
- }
82
-
83
- /**
84
- * The git-era tools a session that is a quilt does not offer (each of SEAM_FOR, and those about
85
- * branches, boxes and merges with git): hidden from the tool list while it is one, so nothing an
86
- * AI reads there names git or GitHub.
87
- */
88
- export const GIT_TOOLS = new Set([...Object.keys(SEAM_FOR), 'quilt_git_status', 'quilt_git_log', 'quilt_git_diff', 'quilt_git_revert', 'quilt_git_pull_requests', 'quilt_git_merge', 'quilt_unpack', 'quilt_merges', 'quilt_adopt_work', 'quilt_branches', 'quilt_clash', 'quilt_migrate_session'])
89
-
90
- // A sentence of guidance about git: branches, boxes, pushes, pull requests or GitHub.
91
- const GITTY = /\bgit\b|GitHub|pull request|\bpush(es|ed|ing)?\b|\bbox(es|ed)?\b|quilt_git_|quilt_unpack|quilt_branches|quilt_sync_|quilt_github|quilt_request_commit|quilt_commit_|quilt_agent_commits|quilt_merges|quilt_adopt_work|quilt_clash|\bbranch(es)?\b/i
92
-
93
- /** Guidance with every sentence about git left out, for a session that is a quilt. */
94
- export function seamOnly (text) {
95
- return String(text || '').split(/(?<=[.!?])\s+(?=[A-Z@"'(*0-9])/).filter((x) => !GITTY.test(x)).join(' ')
96
- }
97
-
98
- // Status sections that are git's alone (status.js), and the lines elsewhere that speak of git.
99
- const GIT_SECTION = /^## (Branches|Commit requests|Pulling|Boxed work|Waiting to go in)\b/
100
- const GIT_LINE = /\bgit\b|GitHub|pull request/i
101
-
102
- /**
103
- * A session's status (status.js markdown) for a session that is a quilt: git's sections left out,
104
- * and lines about git elsewhere too; what people wrote (the messages and chat sections) stays as it is.
105
- */
106
- export function seamStatus (md) {
107
- const out = []
108
- let skip = false
109
- let said = false
110
- for (const line of String(md || '').split('\n')) {
111
- if (line.startsWith('## ')) { skip = GIT_SECTION.test(line); said = /messages|chat/i.test(line) }
112
- if (skip) continue
113
- if (!said && GIT_LINE.test(line)) continue
114
- out.push(line)
115
- }
116
- return out.join('\n')
117
- }
118
-
119
- /** Seam's own description of a tool, without its comparisons to git commands. */
120
- const seamWords = (d) => String(d || '').replace(/\s*\(git [^)]*\)/g, '').replace(/,? as git [^.,;]* does/g, '').replace(/, git:<sha>/g, '')
121
-
122
- /** The task workflow (agent-task-workflow.js) for a session that is a quilt: its git steps left out, the Seam one in. */
123
- export function seamWorkflow (workflow, { hosted = false } = {}) {
124
- return `${seamOnly(workflow)} Before QA, commit the task's work with seam_commit${hosted ? ' in your square' : ''}, saying what the task is; it reaches main with seam_merge once its checks pass.`
125
- }
126
-
127
- /** A hosted agent's file tool at layout 3, where the session's files are in squares, not branches. */
128
- export function seamFileRefusal (quiltId) {
129
- return quiltId ? `${codeIn(quiltId)}: its files are in squares, which Seam's tools read and write. ${SEAM_GUIDE_HOSTED}` : null
130
- }
131
-
132
- /** What a push that still reaches the folder's hook hears in a session that is a quilt: the Seam way, nothing else. */
133
- export function pushRefusal (quiltId) {
134
- return quiltId ? `${codeIn(quiltId)}, so nothing is sent from here. ${SEAM_GUIDE}` : null
135
- }
136
-
137
- /** The line a session's status answers with, in a quilt session; '' otherwise. */
138
- export function seamNote (quiltId, { hosted = false } = {}) {
139
- return quiltId ? `${codeIn(quiltId)}; chat, tasks and the session stay in Quilt. ${guideFor({ hosted })}` : ''
140
- }
141
-
142
- /** Why the relay gives no GitHub token to a member's git here; null when it may. People keep theirs. */
143
- export function gitTokenRefusal (quiltId, kind) {
144
- if (!quiltId || kind !== 'agent') return null
145
- return `this session's code is committed and merged in Seam (the quilt ${quiltId}): agents use seam_commit and seam_merge`
146
- }
147
-
148
- /**
149
- * A folder's MCP server (src/mcp.js), in a session that is a quilt: wraps `registerTool` so each
150
- * GitHub tool refuses with the Seam tool to use. `quiltNow()` is the session's link as the relay
151
- * last said ({ id, slug } or null), asked at call time, so a session that becomes a quilt (or
152
- * stops being one) changes the answer without a restart. Every other tool is untouched.
153
- */
154
- export function seamGate (registerTool, quiltNow) {
155
- return (name, spec, handler) => registerTool(name, spec, GIT_TOOLS.has(name)
156
- ? async (...args) => {
157
- const q = await quiltNow()
158
- const no = q && seamRefusal(name, q.slug || q.id)
159
- return no ? { content: [{ type: 'text', text: no }], isError: true } : handler(...args)
160
- }
161
- : handler)
162
- }
163
-
164
- // What the session adds to Seam's own description of a tool.
165
- const IN_SESSION = {
166
- seam_commit: 'In this Quilt session, with no files: commits your folder\'s square (everything its live work holds now). ',
167
- seam_merge: 'In this Quilt session: merges your folder\'s square onto main (committing its live work first); the folder carries on in a new square. ',
168
- seam_square_status: 'In this Quilt session: your folder\'s square, with its live work not committed yet. ',
169
- seam_open_square: 'In this Quilt session your folder works in a square of its own already (seam_square_status names it): edit there and seam_commit. '
170
- }
171
- const IN_SESSION_HOSTED = { seam_commit: 'You have no folder: give the files\' new contents (files) and your square. ' }
172
-
173
- /** An MCP tool spec for one of SEAM_SESSION_TOOLS: Seam's description and input, quilt and square optional (the session's). */
174
- export function seamToolSpec (name, { hosted = false } = {}) {
175
- const lead = (hosted ? IN_SESSION_HOSTED[name] : IN_SESSION[name]) || ''
176
- const shape = Object.fromEntries(Object.entries(SEAM_INPUTS[name]).map(([k, v]) => [k, v && v.description && seamWords(v.description) !== v.description ? v.describe(seamWords(v.description)) : v]))
177
- return { description: lead + seamWords(SEAM_DESCRIPTIONS[name]), inputSchema: z.looseObject(shape) }
178
- }
179
-
180
- const SQUARE_INPUT = SEAM_INPUTS.seam_square_status.square
181
- // The tools whose answer can move the folder's square on Seam (its live document follows).
182
- const MOVES_HEAD = new Set(['seam_rebase', 'seam_resolve', 'seam_merge', 'seam_commit'])
183
-
184
- /** Seam's own handler for one tool (registerSeamTools on a stand-in server), with `client` for this call. */
185
- function seamHandler (name, client, hosted) {
186
- let handler = null
187
- registerSeamTools({ registerTool: (n, spec, fn) => { handler = fn } }, { client: () => client, tools: [name], hosted })
188
- return handler
189
- }
190
-
191
- const textOf = (r) => ((r && r.content) || []).map((c) => c.text || '').join('\n')
192
- // What a commit left out because of open held conflicts, after its answer ('' with none).
193
- const heldNote = (paths) => (paths && paths.length ? `\n${heldLandingNote(paths)}` : '')
194
- const answer = (text, extra = {}) => ({ content: [{ type: 'text', text }], ...extra })
195
-
196
- /**
197
- * Runs one of SEAM_SESSION_TOOLS for a member of a session that is a quilt: Seam's own handler,
198
- * with the session's quilt (and the folder's square) filled in where the call names none.
199
- * `live` is the folder's live block on that square (source-live/live-block.js), or null: with it,
200
- * seam_commit commits the live work the relay holds, seam_merge commits it first, the status says
201
- * what is uncommitted, and a square whose head Seam moved has its live document follow.
202
- * `next()` is asked after the folder's square merged, to move the branch to its next square.
203
- * `held()`: the session's held conflicts (held.js readHeld): a path with an open one on the square
204
- * never lands until it is resolved (Seam's 07 "Terms held aside"): seam_commit leaves it out and
205
- * commits the rest, refusing only when nothing else is left; seam_merge merges what is committed.
206
- * Returns an MCP tool result.
207
- */
208
- export async function runSessionSeamTool (name, args = {}, { client, quilt, square = null, live = null, hosted = false, next = null, branch = '', held = null }) {
209
- if (!SEAM_SESSION_TOOLS.includes(name)) return answer(`${name} is not one of this session's Seam tools (${SEAM_SESSION_TOOLS.join(', ')}).`, { isError: true })
210
- const shape = SEAM_INPUTS[name]
211
- const a = { ...(args || {}) }
212
- if (Object.hasOwn(shape, 'quilt') && !a.quilt) a.quilt = quilt
213
- // A call that names a square other than the folder's acts on that one, on Seam alone.
214
- const ref = String(a.square || '').replace(/^sq:/, '')
215
- const mine = !ref || !!(square && ref.length >= 4 && String(square).startsWith(ref))
216
- if (square && shape.square === SQUARE_INPUT && !a.square) a.square = square
217
- if (square && name === 'seam_log' && !a.rev) a.rev = `sq:${square}`
218
- if (square && name === 'seam_diff' && !a.from && !a.to) { a.from = 'main'; a.to = `sq:${square}` }
219
- const onFolder = !!(live && square && mine && a.quilt === quilt)
220
- const run = (x) => seamHandler(name, client, hosted)(x)
221
- // A square opened beside the folder's is in no folder: its work could only go in as file contents
222
- // (Seam's agent trial 2026-10-31, finding 10). The folder's square is where work goes.
223
- if (live && square && name === 'seam_open_square') return answer(`This folder is on square ${squareShort(square)} already, and work goes there: edit the files in your folder and commit them with seam_commit, then seam_merge merges the square onto main (and the folder carries on in a new one).`, { isError: true })
224
- try {
225
- if (onFolder && name === 'seam_commit' && !a.files && !a.delete && !a.amend) {
226
- if (!a.message) return answer('Say why: message.')
227
- const r = await live.commit({ message: a.message })
228
- if (r && r.nothing) return answer('Nothing to commit: the square holds no live work since its last commit.')
229
- return answer(describeWrite(r, 'Committed') + heldNote(r && r.left_held), { structuredContent: r })
230
- }
231
- if (onFolder && name === 'seam_merge' && !a.from && !a.dry_run) {
232
- // The relay holds the square's live work: it is committed first, so the merge has all of it
233
- // (but a path with an open held conflict, which stays live until it is resolved).
234
- let c = null
235
- let left = []
236
- try { c = await live.commit({ message: a.message || 'Work in progress' }) } catch (err) {
237
- if (err.code !== 'held_conflict') throw err
238
- left = err.paths || []
239
- }
240
- if (c && c.left_held) left = c.left_held
241
- if (!a.message) { const t = await patchTitle(client, a.quilt, a.square, branch).catch(() => null); if (t) a.message = t }
242
- const r = await run({ ...a, commit_live: false })
243
- const rec = r.structuredContent || {}
244
- const sealed = (c && !c.nothing ? `Committed the square's live work first: ${describeWrite(c, 'committed')}\n` : '') + (left.length ? `${heldLandingNote(left)}\n` : '')
245
- if (rec.ok && rec.merged && next) {
246
- let moved = ''
247
- try { const n = await next(); if (n && n.moved) moved = `\nThe folder carries on in a new square, ${squareShort(n.square)}, on main's new tip: keep editing as before.` } catch (err) { moved = `\nThe folder's branch did not move to a new square yet (${err.message}): ask again with seam_square_status.` }
248
- return { ...r, content: [{ type: 'text', text: sealed + textOf(r) + moved }] }
249
- }
250
- if (rec.ok === false) await followHead(live, rec)
251
- return { ...r, content: [{ type: 'text', text: sealed + textOf(r) + inChat(r) }] }
252
- }
253
- if (name === 'seam_merge' && !a.message && !a.from && !a.dry_run && mine) { const t = await patchTitle(client, a.quilt, a.square, branch).catch(() => null); if (t) a.message = t }
254
- // Files given by content (a hosted agent, or an explicit list): one with an open held conflict on that square stays out.
255
- let leftOut = []
256
- if (name === 'seam_commit' && (a.files || a.delete) && held) {
257
- const on = new Set(heldPathsOn(held() || [], a.square || square))
258
- leftOut = [...(a.files || []).map((f) => f && f.path), ...(a.delete || [])].filter((p) => on.has(p))
259
- if (leftOut.length) {
260
- const files = (a.files || []).filter((f) => !on.has(f && f.path))
261
- const del = (a.delete || []).filter((p) => !on.has(p))
262
- if (!files.length && !del.length && !a.amend && !a.stack) return answer(heldLandingNote([...new Set(leftOut)], { none: true }), { isError: true })
263
- a.files = files.length ? files : undefined
264
- a.delete = del.length ? del : undefined
265
- }
266
- }
267
- const r = await run(a)
268
- if (leftOut.length && !r.isError) return { ...r, content: [{ type: 'text', text: textOf(r) + heldNote([...new Set(leftOut)]) }] }
269
- if (name === 'seam_merge') return { ...r, content: [{ type: 'text', text: textOf(r) + inChat(r) }] }
270
- if (onFolder && name === 'seam_square_status') {
271
- const work = live.status ? live.status() : []
272
- const lines = work.length ? `Live work not committed yet (seam_commit commits it):\n${work.map((w) => ` ${w.status} ${w.path}`).join('\n')}` : 'No live work since the last commit.'
273
- return { ...r, content: [{ type: 'text', text: `${textOf(r)}\n${lines}` }] }
274
- }
275
- if (onFolder && MOVES_HEAD.has(name) && !r.isError) await followHead(live, r.structuredContent || {})
276
- return r
277
- } catch (err) {
278
- return answer(err.message, { isError: true })
279
- }
280
- }
281
-
282
- // Seam tells an agent whose merge waits for an approval to ask for a review (Seam's agent trial
283
- // 2026-10-31, finding 5), which reaches people only in Seam: in a Quilt session they hear it in chat.
284
- const ASKS_REVIEW = /waits for someone else[\s\S]*seam_review with kind request/
285
- const inChat = (r) => ASKS_REVIEW.test(textOf(r)) ? '\nIn this Quilt session, also ask them in chat (quilt_message, naming the square): Seam\'s review request is not shown in Quilt, and they approve with seam_review (kind approve) from their own AI session. Then wait for their answer and merge again.' : ''
286
-
287
- /**
288
- * The title a merge gives its patch when the call names none: Seam takes the square's title, and a square
289
- * the move into Seam opened for a branch is titled with the branch's name, so every patch from main was
290
- * called "main". Then the square's own commits name it: its one message, or "N commits: first; second; …".
291
- * Null (Seam's title stands) for a square named otherwise, or with no message of its own.
292
- */
293
- export async function patchTitle (client, quilt, square, branch) {
294
- if (!branch || !square || !client || !client.square || !client.log) return null
295
- const s = await client.square(quilt, square)
296
- if (!s || String(s.title || '').trim() !== String(branch).trim()) return null
297
- const log = await client.log(quilt, { rev: `sq:${s.id || square}`, limit: 50 })
298
- const own = ((log && log.commits) || []).filter((c) => c && c.square_id === (s.id || square) && c.message)
299
- .map((c) => String(c.message).split('\n')[0].trim()).filter((m) => m && m !== 'Work in progress').reverse()
300
- if (!own.length) return null
301
- if (own.length === 1) return own[0].slice(0, 200)
302
- const all = `${own.length} commits: ${own.join('; ')}`
303
- return all.length > 200 ? `${all.slice(0, 199)}…` : all
304
- }
305
-
306
- /** The square's head after a Seam answer that moved it, and the live document following it. */
307
- async function followHead (live, rec) {
308
- const own = (rec.square && rec.square.head) || rec.head || null
309
- // A square with no commit of its own (a rebase moved its base only): its live work is relative to its base.
310
- const base = !own && rec.square && rec.square.base ? rec.square.base : null
311
- if ((own || base) && live.moveTo) await live.moveTo(own || base, { base: !!base }).catch(() => {})
312
- }