heyquilt 0.3.181 → 0.3.182
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/RELEASES.md +9 -0
- package/package.json +1 -1
- package/src/gitstate.js +117 -1
- package/src/new-session.js +112 -0
- package/src/repo-ref.js +54 -0
- package/src/session.js +69 -3
- package/src/ui/app.css +26 -0
- package/src/ui/app.js +1 -1
- package/src/ui/home.js +3 -20
- package/src/ui/new-session.js +151 -0
- package/src/ui-server.js +26 -2
package/RELEASES.md
CHANGED
|
@@ -11,6 +11,15 @@ Format: `## <version> — <YYYY-MM-DD>`, an optional one-line summary, then bull
|
|
|
11
11
|
Lead each bullet with a short bold phrase. Inline `code` and **bold** are rendered;
|
|
12
12
|
nothing else is.
|
|
13
13
|
|
|
14
|
+
## 0.3.182 — 2026-11-22
|
|
15
|
+
|
|
16
|
+
Every session's folder comes with git, for whoever starts it and for whoever joins.
|
|
17
|
+
|
|
18
|
+
- **Create a codebase.** New session opens a new pop-up with three ways to start. **Import from GitHub**: paste a repository's address (or `owner/name`) and Quilt clones it with git on your computer. **Start from scratch**: name it and say what you want to build; Quilt makes the folder, sets up git, and puts your idea on the board as the first task. **Use a folder**: any folder on your computer; if it has no git yet, Quilt sets it up and saves what is there as the first commit. The pop-up shows where the folder goes before you start, and **Change** puts it somewhere else.
|
|
19
|
+
- **People who join get git too.** When a session's folder is a clone of a repository, someone who joins with an empty folder gets the files and git with them: the same repository, fetched with their own git sign-in, on the same branch and commit as their partner. What the session has that is not committed shows as changes in their folder. Tickets, branches and commits arriving by themselves then work for them without cloning anything by hand.
|
|
20
|
+
- **If git can't be set up for a joiner, they still join.** With no sign-in for the repository, or no network, they get the files as before, and Quilt says why and what to do. A project started from scratch has no repository to fetch from until it is pushed somewhere, so people who join it get the files without git.
|
|
21
|
+
- **Choose a folder opens in front.** In the browser, the folder picker opened behind Settings and other pop-ups.
|
|
22
|
+
|
|
14
23
|
## 0.3.181 — 2026-11-19
|
|
15
24
|
|
|
16
25
|
- **An agent goes back to main when its ticket is done.** An agent works on its ticket's branch, and once the ticket is moved to Done, by the agent or by you, its folder returns to the main branch by itself. Its next ticket starts from there. If it still has changes of its own on the branch that are not committed, it stays and says so. Your own folder is never moved.
|
package/package.json
CHANGED
package/src/gitstate.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
// at work in it, and what a file looked like at a commit, so a checkout of another branch is told
|
|
3
3
|
// apart from edits and the folder can follow its branch (session.js). Quilt does two things to git
|
|
4
4
|
// itself, all at the end of this file: it fetches the branch's upstream, it moves the branch forward
|
|
5
|
-
// to a commit it is behind (never merging history),
|
|
5
|
+
// to a commit it is behind (never merging history), it checks out the branch of a ticket someone opens,
|
|
6
|
+
// and it gives a folder its git in the first place (a clone, a new repository, or a folder of the
|
|
7
|
+
// session's files made into a checkout). Every git call is asynchronous (the
|
|
6
8
|
// app's window and its relay connection never wait on git); the file reads below are synchronous.
|
|
7
9
|
import fs from 'node:fs'
|
|
8
10
|
import path from 'node:path'
|
|
@@ -100,6 +102,14 @@ export function gitDir (root) {
|
|
|
100
102
|
} catch { return null }
|
|
101
103
|
}
|
|
102
104
|
|
|
105
|
+
/** The nearest folder above `root` that has a .git (root is then inside that repository's checkout), or null. `root` need not exist yet. */
|
|
106
|
+
export function repoAbove (root) {
|
|
107
|
+
for (let dir = path.dirname(path.resolve(root)); ; dir = path.dirname(dir)) {
|
|
108
|
+
if (fs.existsSync(path.join(dir, '.git'))) return dir
|
|
109
|
+
if (dir === path.dirname(dir)) return null
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
103
113
|
/**
|
|
104
114
|
* Where HEAD points, read from .git/HEAD alone (no git call): a branch's name, `@<12 hex>` for a
|
|
105
115
|
* detached commit, or null (not a repo, or unreadable). The same key headKey gives.
|
|
@@ -506,3 +516,109 @@ async function lockIndex (root) {
|
|
|
506
516
|
}
|
|
507
517
|
return null
|
|
508
518
|
}
|
|
519
|
+
|
|
520
|
+
// ---------------------------------------------------------- a folder's git --
|
|
521
|
+
// Every session's folder has git (Daniel, 2026-11-19): cloned from the repository the session is
|
|
522
|
+
// for, made new for a project that starts here, or, for someone who joined and got the files from
|
|
523
|
+
// the session, made a checkout of that repository around those files.
|
|
524
|
+
|
|
525
|
+
const QUIET = { GIT_TERMINAL_PROMPT: '0', GIT_ASKPASS: '', SSH_ASKPASS: '', GCM_INTERACTIVE: 'never', GIT_SSH_COMMAND: process.env.GIT_SSH_COMMAND || 'ssh -o BatchMode=yes' }
|
|
526
|
+
// A clone, or the first fetch of a whole repository, can take minutes.
|
|
527
|
+
export const CLONE_TIMEOUT_MS = 10 * 60 * 1000
|
|
528
|
+
|
|
529
|
+
/** Why git could not reach a repository, in a few plain words (never its address). */
|
|
530
|
+
export function repoProblem ({ stderr = '', timedOut = false, missing = false } = {}) {
|
|
531
|
+
const e = String(stderr || '').toLowerCase()
|
|
532
|
+
if (missing) return "git can't be run on this computer"
|
|
533
|
+
if (timedOut) return 'it took over ten minutes and was stopped'
|
|
534
|
+
if (/repository not found|not found|does not appear to be a git repository|does not exist/.test(e)) return "git can't find that repository (or your sign-in can't see it)"
|
|
535
|
+
if (/could not read (username|password)|terminal prompts disabled|authentication failed|permission denied|host key verification failed|invalid username or password|access denied|returned error: 40[13]/.test(e)) {
|
|
536
|
+
return 'git on this computer is not signed in for that repository (or it does not exist)'
|
|
537
|
+
}
|
|
538
|
+
if (/could not resolve host|failed to connect|connection (timed out|refused)|network is unreachable|operation timed out|couldn't connect|unable to access|no route to host/.test(e)) return "git can't reach it (no network?)"
|
|
539
|
+
const line = String(stderr || '').split('\n').map((l) => l.replace(/^(fatal|error):\s*/i, '').trim()).find(Boolean)
|
|
540
|
+
return line ? line.replace(/[a-z]+:\/\/[^\s'"]*@/gi, '').slice(0, 160) : 'git failed'
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/** Clones `url` into `dir` (which must not exist, or be empty), with the person's own git sign-in and no prompt. '' when it worked, else why not. */
|
|
544
|
+
export async function cloneRepo (url, dir) {
|
|
545
|
+
fs.mkdirSync(path.dirname(dir), { recursive: true })
|
|
546
|
+
const r = await call(path.dirname(dir), ['-c', 'core.askPass=', 'clone', '--quiet', '--', url, dir], { timeout: CLONE_TIMEOUT_MS, env: QUIET })
|
|
547
|
+
if (r.out !== null) { keepQuiltOut(dir); return '' }
|
|
548
|
+
return repoProblem(r)
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/** Git never offers Quilt's own state in a folder (.quilt/) for a commit: said in the repository's own exclude file, which is not shared. */
|
|
552
|
+
export function keepQuiltOut (root) {
|
|
553
|
+
const dir = gitDir(root)
|
|
554
|
+
if (!dir) return
|
|
555
|
+
try {
|
|
556
|
+
const file = path.join(dir, 'info', 'exclude')
|
|
557
|
+
let text = ''
|
|
558
|
+
try { text = fs.readFileSync(file, 'utf8') } catch {}
|
|
559
|
+
if (/^\.quilt\/$/m.test(text)) return
|
|
560
|
+
fs.mkdirSync(path.dirname(file), { recursive: true })
|
|
561
|
+
fs.writeFileSync(file, `${text}${text && !text.endsWith('\n') ? '\n' : ''}.quilt/\n`)
|
|
562
|
+
} catch {}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Makes `root` a new git repository on `branch` with a first commit of `rels` as they are (none: an empty commit).
|
|
567
|
+
* A person with no name set in git commits as `who` here. '' when it worked, else why not.
|
|
568
|
+
*/
|
|
569
|
+
export async function startRepo (root, { branch = 'main', rels = [], message = 'Start', who = null } = {}) {
|
|
570
|
+
const init = await call(root, ['init', '-q', '-b', branch])
|
|
571
|
+
if (init.out === null) return init.missing ? "git can't be run on this computer" : (init.stderr || 'git init failed').trim().split('\n')[0]
|
|
572
|
+
keepQuiltOut(root)
|
|
573
|
+
if (rels.length && !(await stage(root, rels))) return 'git could not add the files'
|
|
574
|
+
const has = async (key) => !!((await run(root, ['config', '--get', key])) || '').trim()
|
|
575
|
+
const as = []
|
|
576
|
+
if (!(await has('user.name'))) as.push('-c', `user.name=${(who && who.name) || 'Quilt'}`)
|
|
577
|
+
if (!(await has('user.email'))) as.push('-c', `user.email=${(who && who.email) || 'noreply@heyquilt.com'}`)
|
|
578
|
+
// An empty folder still gets a first commit: branches are made from one.
|
|
579
|
+
const made = await call(root, [...as, 'commit', '-q', '--no-verify', '--allow-empty', '-m', message], { timeout: 60 * 1000 })
|
|
580
|
+
return made.out !== null ? '' : (made.stderr || 'git could not make the first commit').trim().split('\n')[0]
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
/** The address of the folder's `origin` remote, or '' (no git, no such remote). */
|
|
584
|
+
export async function originUrl (root) {
|
|
585
|
+
if (!gitDir(root)) return ''
|
|
586
|
+
return ((await run(root, ['config', '--get', 'remote.origin.url'])) || '').trim()
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* Makes a folder that holds a branch's files (they came from the session) a git checkout of that
|
|
591
|
+
* branch, with every file left as it is: init, fetch `branch` from `url` with the person's own git
|
|
592
|
+
* sign-in, the branch at `sha` (the commit a partner's folder is at; the remote's tip when it is
|
|
593
|
+
* not given or not there), the index at that commit, the upstream set. What the session has that
|
|
594
|
+
* is not committed then shows as the folder's changes. { ok, sha } or { ok: false, error }; a
|
|
595
|
+
* failure leaves no .git behind. The address came from the session, so git is given only the
|
|
596
|
+
* ways of reaching a repository that run nothing here: https, ssh and git (`local`: file too).
|
|
597
|
+
*/
|
|
598
|
+
export async function adoptRepo (root, { url, branch, sha = null, local = false }) {
|
|
599
|
+
if (fs.existsSync(path.join(root, '.git'))) return { ok: true, had: true }
|
|
600
|
+
const undo = () => { try { fs.rmSync(path.join(root, '.git'), { recursive: true, force: true }) } catch {} }
|
|
601
|
+
const step = async (args, what, opts = {}) => {
|
|
602
|
+
const r = await call(root, args, { timeout: CLONE_TIMEOUT_MS, env: QUIET, ...opts })
|
|
603
|
+
if (r.out === null) throw new Error(what === 'fetch' ? repoProblem(r) : `${what}: ${r.missing ? "git can't be run on this computer" : (r.stderr || 'failed').split('\n').find(Boolean)}`)
|
|
604
|
+
return r.out
|
|
605
|
+
}
|
|
606
|
+
const has = async (rev) => (await call(root, ['cat-file', '-e', `${rev}^{commit}`])).out !== null
|
|
607
|
+
try {
|
|
608
|
+
await step(['init', '-q', '-b', branch], 'git init')
|
|
609
|
+
await step(['remote', 'add', 'origin', url], 'adding the remote')
|
|
610
|
+
const ways = ['-c', 'protocol.allow=never', ...['https', 'http', 'ssh', 'git', ...(local ? ['file'] : [])].flatMap((w) => ['-c', `protocol.${w}.allow=always`])]
|
|
611
|
+
await step(['-c', 'core.askPass=', ...ways, 'fetch', '--quiet', '--no-tags', 'origin'], 'fetch')
|
|
612
|
+
const tracked = (await has(`refs/remotes/origin/${branch}`)) ? `refs/remotes/origin/${branch}` : null
|
|
613
|
+
// A partner's commit that was never pushed is not on the remote: the remote's tip of the branch then.
|
|
614
|
+
const at = sha && await has(sha) ? sha : tracked
|
|
615
|
+
if (!at) throw new Error(`that repository has no branch called ${branch}`)
|
|
616
|
+
const commit = (await step(['rev-parse', `${at}^{commit}`], 'reading the commit')).trim()
|
|
617
|
+
await step(['update-ref', `refs/heads/${branch}`, commit], 'setting the branch')
|
|
618
|
+
await step(['symbolic-ref', 'HEAD', `refs/heads/${branch}`], 'checking out the branch')
|
|
619
|
+
await step(['read-tree', '--reset', commit], 'setting the index')
|
|
620
|
+
if (tracked) await step(['branch', '-q', `--set-upstream-to=origin/${branch}`, branch], 'following the remote')
|
|
621
|
+
keepQuiltOut(root)
|
|
622
|
+
return { ok: true, sha: commit }
|
|
623
|
+
} catch (err) { undo(); return { ok: false, error: err.message } }
|
|
624
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// Where a new session's project comes from, and its folder made ready before the session starts:
|
|
2
|
+
// cloned from a repository, a folder already on this computer, or something new. Whichever it is,
|
|
3
|
+
// the folder has git when the session starts in it (Daniel, 2026-11-19: every session comes with git).
|
|
4
|
+
import fs from 'node:fs'
|
|
5
|
+
import path from 'node:path'
|
|
6
|
+
import { parseRepo, folderName } from './repo-ref.js'
|
|
7
|
+
import { gitDir, repoAbove, cloneRepo, startRepo, keepQuiltOut } from './gitstate.js'
|
|
8
|
+
import { loadIgnore, walk } from './fsutil.js'
|
|
9
|
+
|
|
10
|
+
export const SOURCES = ['folder', 'github', 'scratch']
|
|
11
|
+
const MAX_NAME = 80
|
|
12
|
+
const MAX_BRIEF = 8000
|
|
13
|
+
|
|
14
|
+
const fail = (message) => Object.assign(new Error(message), { status: 400 })
|
|
15
|
+
const empty = (dir) => { try { return fs.readdirSync(dir).length === 0 } catch { return true } }
|
|
16
|
+
|
|
17
|
+
/** `base/name`, or `base/name-2`, `-3`… when a folder with something in it is already there. */
|
|
18
|
+
function freeUnder (base, name) {
|
|
19
|
+
for (let n = 1; n < 200; n++) {
|
|
20
|
+
const dir = path.join(base, n === 1 ? name : `${name}-${n}`)
|
|
21
|
+
if (!fs.existsSync(dir) || empty(dir)) return dir
|
|
22
|
+
}
|
|
23
|
+
throw fail(`There are too many folders called ${name} in ${base}. Choose another folder.`)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** What was typed for a repository or a new project, checked: { url?, name } or a 400 with what to fix. */
|
|
27
|
+
function named ({ source, repo, name }) {
|
|
28
|
+
if (source === 'github') {
|
|
29
|
+
const r = parseRepo(repo)
|
|
30
|
+
if (!r) throw fail('Give the repository as owner/name, or its address (https://github.com/owner/name).')
|
|
31
|
+
return r
|
|
32
|
+
}
|
|
33
|
+
const clean = String(name || '').replace(/\s+/g, ' ').trim().slice(0, MAX_NAME)
|
|
34
|
+
if (!clean || !folderName(clean)) throw fail('Give the project a name.')
|
|
35
|
+
return { name: clean }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The folder a new session's project would go in when the person names none: under `base` (their folder for sessions). */
|
|
39
|
+
export function whereFor ({ source, repo, name, base }) {
|
|
40
|
+
if (source !== 'github' && source !== 'scratch') throw fail('Choose where the project comes from.')
|
|
41
|
+
const n = named({ source, repo, name })
|
|
42
|
+
return freeUnder(base, source === 'github' ? n.name : folderName(n.name))
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* What starting from this would do, shown as the person fills the form in, with nothing made or
|
|
47
|
+
* changed: { dir, name } and, for a folder already here, whether it has git yet (`git`) and
|
|
48
|
+
* whether it is there at all (`exists`). Throws with what to fix.
|
|
49
|
+
*/
|
|
50
|
+
export function lookAt ({ source = 'folder', dir = '', repo = '', name = '', base }) {
|
|
51
|
+
if (!SOURCES.includes(source)) throw fail('Choose where the project comes from.')
|
|
52
|
+
if (source === 'folder') {
|
|
53
|
+
if (!dir) throw fail('Choose a project folder.')
|
|
54
|
+
let st = null
|
|
55
|
+
try { st = fs.statSync(dir) } catch {}
|
|
56
|
+
if (st && !st.isDirectory()) throw fail(`${dir} is a file, not a folder.`)
|
|
57
|
+
return { dir, name: path.basename(dir), exists: !!st, git: !!((st && gitDir(dir)) || repoAbove(dir)) }
|
|
58
|
+
}
|
|
59
|
+
return { dir: whereFor({ source, repo, name, base }), name: named({ source, repo, name }).name }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Makes the folder of a new session ready. `source`: 'folder' (`dir`, there already), 'github'
|
|
64
|
+
* (`repo`, cloned into `dir` or a folder under `base`), 'scratch' (`name` and what to build,
|
|
65
|
+
* `brief`, in a new folder). `who`: { name, email } for a first commit made by someone whose git has
|
|
66
|
+
* no name. Returns { dir, name?, brief? }: where the session starts, what it is called, and what
|
|
67
|
+
* becomes its first ticket; `made`: this call made the folder (a clone, something new), so it may
|
|
68
|
+
* be removed again if the session can't start. Throws with what to tell the person.
|
|
69
|
+
*/
|
|
70
|
+
export async function prepareFolder ({ source = 'folder', dir = '', repo = '', name = '', brief = '', base, who = null }) {
|
|
71
|
+
if (!SOURCES.includes(source)) throw fail('Choose where the project comes from.')
|
|
72
|
+
if (source === 'folder') {
|
|
73
|
+
if (!dir) throw fail('Choose a project folder.')
|
|
74
|
+
let st = null
|
|
75
|
+
try { st = fs.statSync(dir) } catch {}
|
|
76
|
+
if (st && !st.isDirectory()) throw fail(`${dir} is a file, not a folder.`)
|
|
77
|
+
fs.mkdirSync(dir, { recursive: true })
|
|
78
|
+
if (gitDir(dir)) { keepQuiltOut(dir); return { dir } }
|
|
79
|
+
// A folder inside a repository's checkout is that repository's: no second one is made inside it.
|
|
80
|
+
if (repoAbove(dir)) return { dir }
|
|
81
|
+
// No git yet: a repository of its own, with the files the session will share as its first commit.
|
|
82
|
+
const said = await startRepo(dir, { rels: [...walk(dir, loadIgnore(dir))], message: `Start of ${path.basename(dir)}`, who })
|
|
83
|
+
if (said) throw fail(`Quilt could not set up git in ${dir}: ${said}.`)
|
|
84
|
+
return { dir }
|
|
85
|
+
}
|
|
86
|
+
const n = named({ source, repo, name })
|
|
87
|
+
const target = dir || whereFor({ source, repo, name, base })
|
|
88
|
+
if (fs.existsSync(target) && !empty(target)) throw fail(`${target} already has files in it. Choose an empty folder, or start from that folder instead.`)
|
|
89
|
+
if (source === 'github') {
|
|
90
|
+
const said = await cloneRepo(n.url, target)
|
|
91
|
+
if (said) {
|
|
92
|
+
try { if (empty(target)) fs.rmSync(target, { recursive: true, force: true }) } catch {}
|
|
93
|
+
throw fail(`Quilt could not clone ${String(repo).trim()}: ${said}.`)
|
|
94
|
+
}
|
|
95
|
+
return { dir: target, name: n.name, made: true }
|
|
96
|
+
}
|
|
97
|
+
const text = String(brief || '').replace(/\r\n?/g, '\n').trim().slice(0, MAX_BRIEF)
|
|
98
|
+
fs.mkdirSync(target, { recursive: true })
|
|
99
|
+
fs.writeFileSync(path.join(target, 'README.md'), `# ${n.name}\n${text ? `\n${text}\n` : ''}`)
|
|
100
|
+
const said = await startRepo(target, { rels: ['README.md'], message: `Start ${n.name}`, who })
|
|
101
|
+
if (said) throw fail(`Quilt could not set up git in ${target}: ${said}.`)
|
|
102
|
+
return { dir: target, name: n.name, made: true, ...(text ? { brief: text } : {}) }
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** The first ticket of a project started from what someone wants to build: its title (one line) and, when there is more, the rest as its first comment. */
|
|
106
|
+
export function briefTicket (brief, maxTitle = 120) {
|
|
107
|
+
const text = String(brief || '').trim()
|
|
108
|
+
if (!text) return null
|
|
109
|
+
const first = text.split('\n')[0].replace(/\s+/g, ' ').trim()
|
|
110
|
+
const title = first.length > maxTitle ? `${first.slice(0, maxTitle - 1).trimEnd()}…` : first
|
|
111
|
+
return { title, ...(text !== title ? { comment: text } : {}) }
|
|
112
|
+
}
|
package/src/repo-ref.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// What a person types to say which repository they mean ("owner/name", an https or ssh address, or a
|
|
2
|
+
// folder holding one on this computer), read into the address git clones and the name its folder gets.
|
|
3
|
+
// Pure: nothing here runs git or touches the disk.
|
|
4
|
+
|
|
5
|
+
const NAME = /^[A-Za-z0-9_.-]+$/
|
|
6
|
+
|
|
7
|
+
/** The last part of a repository's address, as a folder name: "storefront" for ".../storefront.git". */
|
|
8
|
+
const nameOf = (s) => s.replace(/[\\/]+$/, '').replace(/\.git$/i, '').split(/[\\/:]/).pop() || ''
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* { url, name } for what was typed, or null when it names no repository. "owner/name" is GitHub's.
|
|
12
|
+
* An address is kept as typed (git knows how to reach it); a path on this computer must be absolute.
|
|
13
|
+
*/
|
|
14
|
+
export function parseRepo (text) {
|
|
15
|
+
const t = String(text || '').trim()
|
|
16
|
+
if (!t || /\s/.test(t)) return null
|
|
17
|
+
let url = null
|
|
18
|
+
if (/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(t) && !t.startsWith('.')) url = `https://github.com/${t.replace(/\.git$/i, '')}.git`
|
|
19
|
+
else if (/^(https?|ssh|git):\/\/[^/\s]+\/\S+$/.test(t)) url = t.replace(/\/+$/, '')
|
|
20
|
+
else if (/^[A-Za-z0-9_.-]+@[A-Za-z0-9.-]+:\S+$/.test(t)) url = t
|
|
21
|
+
else if (/^(\/|[A-Za-z]:[\\/])/.test(t)) url = t
|
|
22
|
+
if (!url) return null
|
|
23
|
+
const name = nameOf(url)
|
|
24
|
+
return NAME.test(name) && name !== '.' && name !== '..' ? { url, name } : null
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** A remote's address as it may be shown and shared: without the sign-in some addresses carry ("https://user:token@host/…"). */
|
|
28
|
+
export function cleanRemote (url) {
|
|
29
|
+
return String(url || '').trim().replace(/^(https?:\/\/)[^/@\s]+@/i, '$1')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** A project's name as a folder name: lower case, dashes, at most 60 characters; '' when nothing usable is left. */
|
|
33
|
+
export function folderName (name) {
|
|
34
|
+
return String(name || '').toLowerCase().normalize('NFKD').replace(/[^\w\s-]/g, '').trim().replace(/[\s_]+/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '').slice(0, 60).replace(/-$/, '')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A repository's address as one folder may share it and another may hand to git: an https, ssh or
|
|
39
|
+
* git address, without the sign-in. '' for anything else (a path on someone's computer, a transport
|
|
40
|
+
* that runs a command). `local`: a file:// address counts too (folders on the same computer, tests).
|
|
41
|
+
*/
|
|
42
|
+
export function shareableRemote (url, { local = false } = {}) {
|
|
43
|
+
const u = cleanRemote(url)
|
|
44
|
+
if (!u || u.length > 500 || /\s/.test(u)) return ''
|
|
45
|
+
if (/^(https?|ssh|git):\/\/[A-Za-z0-9][^/\s]*\/\S+$/i.test(u)) return u
|
|
46
|
+
if (/^[A-Za-z0-9][A-Za-z0-9_.-]*@[A-Za-z0-9][A-Za-z0-9.-]*:\S+$/.test(u)) return u
|
|
47
|
+
if (local && /^file:\/\/\/\S+$/.test(u)) return u
|
|
48
|
+
return ''
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A repository's address as it is said to a person: "github.com/owner/name". */
|
|
52
|
+
export function repoLabel (url) {
|
|
53
|
+
return cleanRemote(url).replace(/^file:\/\//i, '').replace(/^[a-z]+:\/\//i, '').replace(/^[^@/\s]+@/, '').replace(/^([^/:]+):(?!\d+\/)/, '$1/').replace(/\/+$/, '').replace(/\.git$/i, '')
|
|
54
|
+
}
|
package/src/session.js
CHANGED
|
@@ -52,8 +52,9 @@ import { exchangeKind } from './exchange.js'
|
|
|
52
52
|
import { HELD_MAP, readHeld, findHeld, settleHeld, renderHeld, versionsOf, versionBy, ownHeld } from './held.js'
|
|
53
53
|
import { RELAY_NAME as RELAY_BY, isRelay } from './ui/chat.js'
|
|
54
54
|
import { cleanTyping, TYPING_MS, AGENT_TYPING_MS } from './ui/chat.js'
|
|
55
|
-
import { DEFAULT_KEY } from './branchdocs.js'
|
|
56
|
-
import { headKey, headName, branchTip, busy as gitBusy, leftoverLock, indexStamp, filesAt, blobAt, treeState, watchGit, SETTLE_MS as GIT_SETTLE_MS, STALE_LOCK_MS, upstreamOf, fetchUpstream, aheadBehind, changesBetween, fastForward, stage, hasBranch, switchBranch, defaultRemote, remoteBranch, follow } from './gitstate.js'
|
|
55
|
+
import { DEFAULT_KEY, validBranchKey } from './branchdocs.js'
|
|
56
|
+
import { headKey, headName, branchTip, busy as gitBusy, leftoverLock, indexStamp, filesAt, blobAt, treeState, watchGit, SETTLE_MS as GIT_SETTLE_MS, STALE_LOCK_MS, upstreamOf, fetchUpstream, aheadBehind, changesBetween, fastForward, stage, hasBranch, switchBranch, defaultRemote, remoteBranch, follow, adoptRepo, originUrl } from './gitstate.js'
|
|
57
|
+
import { shareableRemote, repoLabel } from './repo-ref.js'
|
|
57
58
|
import { cleanVoice, newCallId, voiceView, inVoice, transcribeSetting, setTranscribe, addLine, readLines, MAX_IN_CALL, CALL_FULL, callAgents, setAgentLeft, notInCall, agentSays, markCallForAgents, namedAgents, callPing, spokenReply, AGENT_REPLY_MS } from './voice.js'
|
|
58
59
|
import { toolInUse } from './agents/common.js'
|
|
59
60
|
|
|
@@ -192,12 +193,13 @@ function writeAndStat (abs, data, mode = undefined) {
|
|
|
192
193
|
}
|
|
193
194
|
|
|
194
195
|
export class Session extends EventEmitter {
|
|
195
|
-
constructor ({ dir, server, room, secret, key = '', viewSecret = '', name, tool = 'unknown', color = null, prefer = 'remote', kind = 'human', shareAgent = true, summarize = null, identity = null, passes = null, startName = '', startAgentCommits = '', workspace = '', editQuietMs = EDIT_QUIET_MS, aiTasks = null, pushLocalCommits = null, webhookTransport = null, pullWaitMs = PULL_WAIT_MS, bringInUpstream = true, clashReassignMs = CLASH_REASSIGN_MS, clashWaitMs = CLASH_WAIT_MS, clashSettleMs = CLASH_SETTLE_MS, clashIdleMs = CLASH_IDLE_MS, catcherWaitMs = CATCHER_WAIT_MS, gitBacking = true, gitRemote = null, followsRelay = true, turns = false, features = null, cli = defaultCli() }) {
|
|
196
|
+
constructor ({ dir, server, room, secret, key = '', viewSecret = '', name, tool = 'unknown', color = null, prefer = 'remote', kind = 'human', shareAgent = true, summarize = null, identity = null, passes = null, startName = '', startAgentCommits = '', workspace = '', editQuietMs = EDIT_QUIET_MS, aiTasks = null, pushLocalCommits = null, webhookTransport = null, pullWaitMs = PULL_WAIT_MS, bringInUpstream = true, clashReassignMs = CLASH_REASSIGN_MS, clashWaitMs = CLASH_WAIT_MS, clashSettleMs = CLASH_SETTLE_MS, clashIdleMs = CLASH_IDLE_MS, catcherWaitMs = CATCHER_WAIT_MS, gitBacking = true, gitRemote = null, followsRelay = true, turns = false, features = null, localRepos = process.env.QUILT_LOCAL_REPOS === '1', cli = defaultCli() }) {
|
|
196
197
|
super()
|
|
197
198
|
// An agent that works in turns (agent-join.js keptInProject): the relay shows it away between them.
|
|
198
199
|
this.turns = turns
|
|
199
200
|
this.pullWaitMs = pullWaitMs
|
|
200
201
|
this.bringInUpstream = bringInUpstream // false: commits come in only when someone pulls (tests of the pull path)
|
|
202
|
+
this.localRepos = !!localRepos // a repository at a file:// address is shared with, and taken by, folders that join without git (the same computer, tests)
|
|
201
203
|
this.followsRelay = followsRelay // false: as an app older than 0.3.65, which brings GitHub's commits in itself on every branch (tests)
|
|
202
204
|
this.features = features // what the app says it can do (protocol.js FEATURES), else this version's: an older app's list in tests
|
|
203
205
|
this.catcherWaitMs = catcherWaitMs
|
|
@@ -678,6 +680,7 @@ export class Session extends EventEmitter {
|
|
|
678
680
|
if (first === 'pending') {
|
|
679
681
|
// Finish joining in the background once let in.
|
|
680
682
|
this.admitted = sync.then(async () => {
|
|
683
|
+
await this.gitForJoin()
|
|
681
684
|
this.noteFirstJoin(this.reconcileFirstJoin(null))
|
|
682
685
|
this.goLive()
|
|
683
686
|
await this.startWatcher()
|
|
@@ -690,6 +693,7 @@ export class Session extends EventEmitter {
|
|
|
690
693
|
clearTimeout(timer)
|
|
691
694
|
this.conn.off('access', onAccess)
|
|
692
695
|
}
|
|
696
|
+
await this.gitForJoin()
|
|
693
697
|
this.noteFirstJoin(this.reconcileFirstJoin(null))
|
|
694
698
|
this.goLive()
|
|
695
699
|
}
|
|
@@ -2290,6 +2294,67 @@ export class Session extends EventEmitter {
|
|
|
2290
2294
|
// `git pull --autostash` would. It never merges git history: a branch with commits of its own the
|
|
2291
2295
|
// upstream hasn't, or uncommitted work on the same lines as a commit, is left to the person's git.
|
|
2292
2296
|
|
|
2297
|
+
// ------------------------------------------------------ git for a joiner --
|
|
2298
|
+
// Every session's folder has git (Daniel, 2026-11-19). Whoever starts a session has it already
|
|
2299
|
+
// (new-session.js). A folder that joins without it gets the session's repository around the
|
|
2300
|
+
// files: the address a partner's folder shared (shareRepo), fetched with the joiner's own git
|
|
2301
|
+
// sign-in, its branch at the commit a partner's folder is at, so what the session has that is
|
|
2302
|
+
// not committed shows as the folder's changes. When that can't be done (nobody shared an
|
|
2303
|
+
// address, no sign-in for it, no network) the folder joins as it always did, and says why.
|
|
2304
|
+
|
|
2305
|
+
/** The repository this folder's branch is a checkout of, as a partner's folder shared it ('': none did, or it is no address git may be given). */
|
|
2306
|
+
sessionRepo () { return shareableRemote(this.bdoc.getMap('git').get('origin'), { local: this.localRepos }) }
|
|
2307
|
+
|
|
2308
|
+
/** Shares this folder's origin (never a sign-in in it) and its branch's commit in the branch's document, for folders that join without git. */
|
|
2309
|
+
async shareRepo () {
|
|
2310
|
+
if (!this.git || !this.git.branch || this.stopped || (this.access && this.access.role === 'viewer')) return
|
|
2311
|
+
const url = shareableRemote(await originUrl(this.root), { local: this.localRepos })
|
|
2312
|
+
if (this.stopped || !this.git || !this.git.branch) return
|
|
2313
|
+
const g = this.bdoc.getMap('git')
|
|
2314
|
+
const sha = this.git.sha || null
|
|
2315
|
+
// The first address said stays (two folders may reach one repository by different addresses).
|
|
2316
|
+
const say = { ...(url && !this.sessionRepo() ? { origin: url } : {}), ...(sha && g.get('tip') !== sha ? { tip: sha } : {}) }
|
|
2317
|
+
if (Object.keys(say).length) this.transact(() => { for (const [k, v] of Object.entries(say)) g.set(k, v) })
|
|
2318
|
+
}
|
|
2319
|
+
|
|
2320
|
+
/**
|
|
2321
|
+
* At a first join, before the session's files are written: a folder without git is made a
|
|
2322
|
+
* checkout of the session's repository (gitstate.js adoptRepo). True when it has git now.
|
|
2323
|
+
*/
|
|
2324
|
+
async gitForJoin () {
|
|
2325
|
+
// Whatever goes wrong here, the folder still joins.
|
|
2326
|
+
try { return await this.adoptGit() } catch (err) { this.emit('debug', `git for this folder: ${err && err.message}`); return false }
|
|
2327
|
+
}
|
|
2328
|
+
|
|
2329
|
+
async adoptGit () {
|
|
2330
|
+
if (this.git || this.gitAside || this.stopped || this.prefer === 'local' || hasGitDir(this.root)) return false
|
|
2331
|
+
const url = this.sessionRepo()
|
|
2332
|
+
const branch = this.branchKey()
|
|
2333
|
+
if (!url || !validBranchKey(branch) || branch === DEFAULT_KEY || branch.startsWith('@')) return false
|
|
2334
|
+
const label = repoLabel(url)
|
|
2335
|
+
// The commit the session's files are measured from: where a partner's folder on the branch is now, else where one last said it was.
|
|
2336
|
+
let sha = null
|
|
2337
|
+
for (const [id, st] of this.conn.awareness.getStates()) {
|
|
2338
|
+
if (id !== this.doc.clientID && st && st.tip && st.tip.key === branch && typeof st.tip.sha === 'string') { sha = st.tip.sha; break }
|
|
2339
|
+
}
|
|
2340
|
+
if (!sha) { const said = this.bdoc.getMap('git').get('tip'); if (typeof said === 'string') sha = said }
|
|
2341
|
+
if (sha && !/^[0-9a-f]{40,64}$/.test(sha)) sha = null
|
|
2342
|
+
this.log(`setting up git in this folder from ${label}…`)
|
|
2343
|
+
const r = await adoptRepo(this.root, { url, branch, sha, local: this.localRepos })
|
|
2344
|
+
if (this.stopped) return false
|
|
2345
|
+
if (!r.ok) {
|
|
2346
|
+
const text = `Quilt could not set up git in this folder: ${r.error}. The session's files are here and stay in sync. To have git too, clone ${label} and join the session from that folder.`
|
|
2347
|
+
this.log(`⚠️ ${text}`)
|
|
2348
|
+
this.notice(text)
|
|
2349
|
+
return false
|
|
2350
|
+
}
|
|
2351
|
+
this.git = await this.headAt()
|
|
2352
|
+
this.gitSeen = this.git
|
|
2353
|
+
this.gitIndex = indexStamp(this.root)
|
|
2354
|
+
this.log(`git is set up in this folder: ${branch}, from ${label}.`)
|
|
2355
|
+
return !!this.git
|
|
2356
|
+
}
|
|
2357
|
+
|
|
2293
2358
|
/** Starts looking at the upstream: now, then every UPSTREAM_MS. */
|
|
2294
2359
|
startUpstream () {
|
|
2295
2360
|
if (!this.git || !this.bringInUpstream || this.upstreamPoll) return
|
|
@@ -2305,6 +2370,7 @@ export class Session extends EventEmitter {
|
|
|
2305
2370
|
const was = this.conn.awareness.getLocalState().tip
|
|
2306
2371
|
const tip = this.git.branch && this.git.sha ? { key: this.git.key, sha: this.git.sha } : null
|
|
2307
2372
|
if (JSON.stringify(was || null) !== JSON.stringify(tip)) this.conn.awareness.setLocalStateField('tip', tip)
|
|
2373
|
+
this.shareRepo().catch((err) => this.emit('debug', `sharing the repository: ${err.message}`))
|
|
2308
2374
|
}
|
|
2309
2375
|
|
|
2310
2376
|
/** A partner's folder on this branch is at a commit this one isn't: it may have pushed, so this folder fetches (again a little later: a push follows its commit). */
|
package/src/ui/app.css
CHANGED
|
@@ -1586,6 +1586,7 @@ body.has-update #app { padding-top: var(--update-bar); } /* padding, not margin:
|
|
|
1586
1586
|
/* settings in a pop-up (from inside a session): the Settings cards on a scrolling sheet */
|
|
1587
1587
|
.settings-back { z-index: 30; }
|
|
1588
1588
|
.ask-back { z-index: 40; } /* confirm dialogs (Shut down, sign out…) sit on top of the Settings pop-up */
|
|
1589
|
+
.pick-back { z-index: 40; } /* so does Choose a folder, opened from inside a pop-up */
|
|
1589
1590
|
.settings-modal { position: relative; display: grid; grid-template-columns: 230px minmax(0, 1fr); width: min(80vw, 100%); height: 86vh; max-height: 100%; background: var(--canvas); border-radius: 14px; box-shadow: 0 30px 70px -30px rgba(29, 27, 46, .6), 0 0 0 1px var(--border-strong); overflow: hidden; }
|
|
1590
1591
|
.settings-modal .ss-head { flex: none; background: var(--canvas); }
|
|
1591
1592
|
/* The team window (workspaces.js) is a plain sheet: a heading across the top, the body below. */
|
|
@@ -1597,6 +1598,31 @@ body.has-update #app { padding-top: var(--update-bar); } /* padding, not margin:
|
|
|
1597
1598
|
.settings-close { position: absolute; top: 14px; right: 14px; }
|
|
1598
1599
|
.settings-body { position: relative; flex: 1; min-height: 0; overflow-y: auto; padding: 22px 28px 28px; overscroll-behavior: contain; } /* positioned, so the hidden toggle inputs scroll with the body instead of stretching the sheet */
|
|
1599
1600
|
.settings-body .settings-sec:last-child { margin-bottom: 0; }
|
|
1601
|
+
/* Create a codebase (new-session.js): the same sheet, with what you picked so far at the foot of its list and a bar along the bottom */
|
|
1602
|
+
.nc-label { padding: 0 10px 4px; }
|
|
1603
|
+
.nc-sum { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--border); }
|
|
1604
|
+
.nc-sum .label { display: block; padding-bottom: 6px; }
|
|
1605
|
+
.nc-sum-row { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; font-size: 12.5px; }
|
|
1606
|
+
.nc-sum-row span { flex: none; color: var(--muted); }
|
|
1607
|
+
.nc-sum-row b { min-width: 0; font-weight: 600; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1608
|
+
.nc-where { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 12.5px; color: var(--muted); }
|
|
1609
|
+
.nc-where code { min-width: 0; padding: 2px 7px; border-radius: 4px; background: var(--panel-2); color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1610
|
+
.nc-where .spacer { flex: 1; }
|
|
1611
|
+
.nc-pop .field:last-child { margin-bottom: 0; }
|
|
1612
|
+
.nc-brief { min-height: 96px; line-height: 1.5; }
|
|
1613
|
+
.nc-foot { flex: none; display: flex; align-items: center; gap: 10px; padding: 14px 28px; border-top: 1px solid var(--border); background: var(--canvas); border-radius: 0 0 14px 0; }
|
|
1614
|
+
.nc-foot .grow { flex: 1; min-width: 0; }
|
|
1615
|
+
.nc-foot .error { margin: 0; }
|
|
1616
|
+
.nc-foot .error:not(:empty) + .hint, .nc-foot .hint:has(+ .error:not(:empty)) { display: none; }
|
|
1617
|
+
.nc-foot .btn.primary { min-width: 200px; justify-content: center; }
|
|
1618
|
+
.nc-foot .btn.primary svg { width: 15px; height: 15px; }
|
|
1619
|
+
@media (max-width: 760px) {
|
|
1620
|
+
.nc-sum { display: none; }
|
|
1621
|
+
.nc-label { display: none; }
|
|
1622
|
+
.nc-foot { padding: 12px 14px; border-radius: 0 0 10px 10px; }
|
|
1623
|
+
.nc-foot .hint { display: none; }
|
|
1624
|
+
.nc-foot .btn.primary { min-width: 0; flex: 1; }
|
|
1625
|
+
}
|
|
1600
1626
|
@media (max-width: 760px) {
|
|
1601
1627
|
.settings-modal { width: 100%; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); height: 94vh; border-radius: 10px; }
|
|
1602
1628
|
.settings-modal .ss-nav { border-right: 0; border-bottom: 1px solid var(--border); padding: 14px 10px 10px; }
|
package/src/ui/app.js
CHANGED
|
@@ -423,7 +423,7 @@ export async function pickFolder (input) {
|
|
|
423
423
|
return
|
|
424
424
|
}
|
|
425
425
|
const back = document.createElement('div')
|
|
426
|
-
back.className = 'modal-back'
|
|
426
|
+
back.className = 'modal-back pick-back'
|
|
427
427
|
back.innerHTML = `<div class="card modal" role="dialog" aria-modal="true" aria-labelledby="pick-title">
|
|
428
428
|
<h3 id="pick-title">Choose a folder</h3>
|
|
429
429
|
<p class="lead">Pick the project folder, or type a path. New folders are created for you.</p>
|
package/src/ui/home.js
CHANGED
|
@@ -17,6 +17,7 @@ import { SOUND_EVENTS, playSound } from './sounds.js'
|
|
|
17
17
|
import { thisSessionGitHtml } from './git-rule.js'
|
|
18
18
|
import { cloudAiCardHtml, bindCloudAi, cloudSetupOn, cloudSetupHtml, cloudSetupStep } from './cloud-ai.js'
|
|
19
19
|
import { feedbackDockHtml, bindFeedback } from './feedback.js'
|
|
20
|
+
import { openNewCodebase } from './new-session.js'
|
|
20
21
|
|
|
21
22
|
export const tildify = (p) => state.defaults.home && String(p).startsWith(state.defaults.home) ? `~${String(p).slice(state.defaults.home.length)}` : p
|
|
22
23
|
const hostOf = (url) => { try { return new URL(String(url).replace(/^ws/, 'http')).host } catch { return url } }
|
|
@@ -320,27 +321,9 @@ function dialog (html) {
|
|
|
320
321
|
return { back, form, close }
|
|
321
322
|
}
|
|
322
323
|
|
|
324
|
+
/** New session: the Create a codebase pop-up (new-session.js). `workspace`: the one it starts in, if any. */
|
|
323
325
|
export function newSessionDialog (workspace = '') {
|
|
324
|
-
|
|
325
|
-
<h3>New session${workspace ? ` in ${esc(state.workspaces?.find((w) => w.id === workspace)?.name || 'this workspace')}` : ''}</h3>
|
|
326
|
-
<p class="lead">Pick what you want to work on together. You'll get invites to send once it starts.</p>
|
|
327
|
-
<div id="src-folder">
|
|
328
|
-
<div class="field">
|
|
329
|
-
<label for="n-dir">Project folder</label>
|
|
330
|
-
<div class="row"><input class="input grow" id="n-dir" name="dir" placeholder="~/code/my-app" value="${esc(tildify(state.lastCreateDir || state.defaults.cwd || ''))}" required>
|
|
331
|
-
<button type="button" class="btn icon" id="n-browse" title="Browse" aria-label="Browse">${I.folder}</button></div>
|
|
332
|
-
</div>
|
|
333
|
-
</div>
|
|
334
|
-
<p class="error" id="n-error"></p>
|
|
335
|
-
<div class="actions"><button type="button" class="btn ghost" data-cancel>Cancel</button><button class="btn primary" type="submit">Start session</button></div>`)
|
|
336
|
-
form.querySelector('#n-browse').onclick = () => pickFolder(form.querySelector('#n-dir'))
|
|
337
|
-
form.onsubmit = async (e) => {
|
|
338
|
-
e.preventDefault()
|
|
339
|
-
const dir = form.querySelector('#n-dir').value
|
|
340
|
-
state.lastCreateDir = dir
|
|
341
|
-
if (await submit(form, '#n-error', { mode: 'create', dir, workspace })) close()
|
|
342
|
-
}
|
|
343
|
-
form.querySelector('#n-dir').focus()
|
|
326
|
+
openNewCodebase({ workspace, submit, tildify, pickFolder })
|
|
344
327
|
}
|
|
345
328
|
|
|
346
329
|
/**
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// Create a codebase: the pop-up a new session starts from. Three ways in, listed on the left:
|
|
2
|
+
// import a repository from GitHub (cloned here), start from scratch (a new folder, with what you
|
|
3
|
+
// want to build as the first task), or a folder already on this computer. Whichever it is, the
|
|
4
|
+
// folder has git when the session starts in it (src/new-session.js makes it ready).
|
|
5
|
+
import { I, state, $, esc, api } from './common.js'
|
|
6
|
+
|
|
7
|
+
const WAYS = [
|
|
8
|
+
{ id: 'github', label: 'Import from GitHub', icon: 'github', from: 'GitHub', busy: 'Cloning…' },
|
|
9
|
+
{ id: 'scratch', label: 'Start from scratch', icon: 'plus', from: 'Scratch', busy: 'Setting up…' },
|
|
10
|
+
{ id: 'folder', label: 'Use a folder', heading: 'A folder on this computer', icon: 'folder', from: 'A folder', busy: 'Connecting…' }
|
|
11
|
+
]
|
|
12
|
+
const LOOK_MS = 250
|
|
13
|
+
|
|
14
|
+
const card = (title, lead, body) => `<section class="card settings-sec"><div class="sec-intro"><h2>${title}</h2><p>${lead}</p></div><div class="sec-body">${body}</div></section>`
|
|
15
|
+
const where = (verb) => `<p class="nc-where"><span>${verb}</span><code data-nc-dir>…</code><span class="spacer"></span><button type="button" class="btn sm ghost" data-nc-change>Change</button></p>`
|
|
16
|
+
|
|
17
|
+
/** What the form would send for the way picked: the body of POST /api/sessions, less `mode`. */
|
|
18
|
+
export function newCodebaseBody (way, v) {
|
|
19
|
+
if (way === 'github') return { source: 'github', repo: v.repo.trim(), ...(v.into ? { into: v.into } : {}) }
|
|
20
|
+
if (way === 'scratch') return { source: 'scratch', name: v.name.trim(), brief: v.brief.trim(), ...(v.into ? { into: v.into } : {}) }
|
|
21
|
+
return { source: 'folder', dir: v.dir.trim() }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The line under a folder's path: what Quilt does about git there. `look`: the server's answer for it, or null. */
|
|
25
|
+
export function folderGitNote (look) {
|
|
26
|
+
if (!look) return ''
|
|
27
|
+
if (look.git) return 'This folder has git already. Quilt uses it as it is.'
|
|
28
|
+
if (look.exists) return 'No git here yet. Quilt sets it up and saves what is there as the first commit.'
|
|
29
|
+
return 'This folder is new. Quilt makes it and sets up git.'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Opens the pop-up. `workspace`: the workspace the session starts in, if any. `submit`, `tildify`
|
|
34
|
+
* and `pickFolder` are Home's (home.js): starting the session, showing a path, choosing a folder.
|
|
35
|
+
*/
|
|
36
|
+
export function openNewCodebase ({ workspace = '', submit, tildify, pickFolder }) {
|
|
37
|
+
$('#nc-back')?.remove()
|
|
38
|
+
const v = { repo: '', name: '', brief: '', dir: tildify(state.lastCreateDir || state.defaults.cwd || ''), into: '' }
|
|
39
|
+
let way = 'github'
|
|
40
|
+
let look = null // the server's answer for what is typed now: { dir, name, exists, git }
|
|
41
|
+
let asked = 0
|
|
42
|
+
let timer = null
|
|
43
|
+
const inWorkspace = workspace ? state.workspaces?.find((w) => w.id === workspace)?.name || 'this workspace' : ''
|
|
44
|
+
const back = document.createElement('div')
|
|
45
|
+
back.id = 'nc-back'
|
|
46
|
+
back.className = 'modal-back settings-back'
|
|
47
|
+
back.innerHTML = `
|
|
48
|
+
<form class="settings-modal nc-pop" role="dialog" aria-modal="true" aria-labelledby="nc-title" autocomplete="off">
|
|
49
|
+
<nav class="ss-nav settings-nav" aria-label="Where it starts from">
|
|
50
|
+
<h3 id="nc-title">Create a codebase</h3>
|
|
51
|
+
<p class="lead settings-scope">A place to code together, live${inWorkspace ? `, in ${esc(inWorkspace)}` : ''}. It comes with git, for you and for everyone who joins.</p>
|
|
52
|
+
<div class="label nc-label">Start from</div>
|
|
53
|
+
<div class="ss-tabs settings-tabs" role="tablist" aria-orientation="vertical">${WAYS.map((w) => `<button type="button" role="tab" class="ss-tab" data-nc-way="${w.id}">${I[w.icon]}<span>${w.label}</span></button>`).join('')}</div>
|
|
54
|
+
<div class="nc-sum" data-nc-sum></div>
|
|
55
|
+
</nav>
|
|
56
|
+
<div class="ss-main">
|
|
57
|
+
<div class="ss-head"><h4 class="ss-name"></h4><button class="btn sm ghost icon ss-close" type="button" data-nc-close aria-label="Close">${I.x}</button></div>
|
|
58
|
+
<div class="settings-body" role="tabpanel"></div>
|
|
59
|
+
<div class="nc-foot"><div class="grow"><span class="hint" data-nc-hint>Nothing is shared until you start it.</span><p class="error" id="nc-error"></p></div>
|
|
60
|
+
<button type="button" class="btn ghost" data-nc-close>Cancel</button><button class="btn primary" type="submit"></button></div>
|
|
61
|
+
<input type="hidden" data-nc-into>
|
|
62
|
+
</div>
|
|
63
|
+
</form>`
|
|
64
|
+
document.body.appendChild(back)
|
|
65
|
+
const form = $('form', back)
|
|
66
|
+
const body = $('.settings-body', back)
|
|
67
|
+
const close = () => { clearTimeout(timer); back.remove() }
|
|
68
|
+
back.addEventListener('mousedown', (e) => { if (e.target === back) close() })
|
|
69
|
+
back.addEventListener('keydown', (e) => { if (e.key === 'Escape') close() })
|
|
70
|
+
back.querySelectorAll('[data-nc-close]').forEach((b) => { b.onclick = close })
|
|
71
|
+
|
|
72
|
+
const bodies = {
|
|
73
|
+
github: () => card('Repository', 'Paste its address, or type it as owner/name. Quilt clones it with git on this computer.', `
|
|
74
|
+
<div class="field"><label for="nc-repo">Repository</label><input class="input mono" id="nc-repo" spellcheck="false" placeholder="owner/name or https://github.com/owner/name" value="${esc(v.repo)}" required>
|
|
75
|
+
<span class="hint warn" data-nc-warn hidden></span></div>
|
|
76
|
+
${where('It is cloned to')}`),
|
|
77
|
+
scratch: () => card('What do you want to build?', 'Quilt makes the folder, sets up git, and puts what you write on the board as the first task.', `
|
|
78
|
+
<div class="field"><label for="nc-name">Name</label><input class="input" id="nc-name" placeholder="neon-dungeon" maxlength="80" value="${esc(v.name)}" required></div>
|
|
79
|
+
<div class="field"><label for="nc-brief">The idea</label><textarea class="input nc-brief" id="nc-brief" rows="4" maxlength="8000" placeholder="A small browser game: one level to start, keyboard controls.">${esc(v.brief)}</textarea></div>
|
|
80
|
+
${where('It goes in')}`),
|
|
81
|
+
folder: () => card('Folder', 'Any project on this computer, on GitHub or not.', `
|
|
82
|
+
<div class="field"><label for="nc-dir">Project folder</label>
|
|
83
|
+
<div class="row"><input class="input grow mono" id="nc-dir" spellcheck="false" placeholder="~/code/my-app" value="${esc(v.dir)}" required>
|
|
84
|
+
<button type="button" class="btn icon" data-nc-browse title="Browse" aria-label="Browse">${I.folder}</button></div>
|
|
85
|
+
<span class="hint" data-nc-git></span></div>`)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const draw = () => {
|
|
89
|
+
const w = WAYS.find((x) => x.id === way)
|
|
90
|
+
const name = (look && look.name) || ''
|
|
91
|
+
$('button[type=submit]', back).innerHTML = `<span>${esc(name ? `Start ${name}` : 'Start')}</span>${I.arrowRight}`
|
|
92
|
+
const dir = $('[data-nc-dir]', body)
|
|
93
|
+
if (dir) dir.textContent = look ? tildify(look.dir) : '…'
|
|
94
|
+
const git = $('[data-nc-git]', body)
|
|
95
|
+
if (git) git.textContent = folderGitNote(look)
|
|
96
|
+
const rows = [['Name', name || '…'], ['From', w.from], ['Folder', look ? tildify(look.dir) : '…'],
|
|
97
|
+
['Git', way === 'github' ? 'Cloned for you' : way === 'folder' && look && look.git ? 'Already there' : 'Set up for you']]
|
|
98
|
+
$('[data-nc-sum]', back).innerHTML = `<div class="label">This codebase</div>${rows.map(([k, val]) => `<div class="nc-sum-row"><span>${k}</span><b title="${esc(val)}">${esc(val)}</b></div>`).join('')}`
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// What the server says starting from this would do: where it goes, what it is called, whether git is there.
|
|
102
|
+
const lookNow = async () => {
|
|
103
|
+
const n = ++asked
|
|
104
|
+
const warn = $('[data-nc-warn]', body)
|
|
105
|
+
const typed = way === 'github' ? v.repo : way === 'scratch' ? v.name : v.dir
|
|
106
|
+
if (!typed.trim()) { look = null; if (warn) warn.hidden = true; draw(); return }
|
|
107
|
+
try {
|
|
108
|
+
const r = await api('POST', '/api/new-session/look', newCodebaseBody(way, v))
|
|
109
|
+
if (n !== asked) return
|
|
110
|
+
look = r
|
|
111
|
+
if (warn) warn.hidden = true
|
|
112
|
+
} catch (err) {
|
|
113
|
+
if (n !== asked) return
|
|
114
|
+
look = null
|
|
115
|
+
if (warn) { warn.textContent = err.message; warn.hidden = false }
|
|
116
|
+
}
|
|
117
|
+
draw()
|
|
118
|
+
}
|
|
119
|
+
const lookSoon = () => { clearTimeout(timer); timer = setTimeout(lookNow, LOOK_MS) }
|
|
120
|
+
|
|
121
|
+
const pick = (id) => {
|
|
122
|
+
way = id
|
|
123
|
+
look = null
|
|
124
|
+
for (const b of back.querySelectorAll('[data-nc-way]')) { b.classList.toggle('on', b.dataset.ncWay === id); b.setAttribute('aria-selected', b.dataset.ncWay === id) }
|
|
125
|
+
const w = WAYS.find((x) => x.id === id)
|
|
126
|
+
$('.ss-name', back).textContent = w.heading || w.label
|
|
127
|
+
$('#nc-error', back).textContent = ''
|
|
128
|
+
body.innerHTML = bodies[id]()
|
|
129
|
+
body.scrollTop = 0
|
|
130
|
+
const bind = (sel, key) => { const el = $(sel, body); if (el) el.oninput = () => { v[key] = el.value; lookSoon() } }
|
|
131
|
+
bind('#nc-repo', 'repo'); bind('#nc-name', 'name'); bind('#nc-brief', 'brief'); bind('#nc-dir', 'dir')
|
|
132
|
+
const browse = $('[data-nc-browse]', body)
|
|
133
|
+
if (browse) browse.onclick = async () => { const el = $('#nc-dir', body); await pickFolder(el); if (el.value !== v.dir) { v.dir = el.value; lookNow() } }
|
|
134
|
+
// Change: the folder a clone or a new project is made in, instead of the one in Settings.
|
|
135
|
+
const change = $('[data-nc-change]', body)
|
|
136
|
+
if (change) change.onclick = async () => { into.value = v.into; await pickFolder(into); if (into.value !== v.into) { v.into = into.value; lookNow() } }
|
|
137
|
+
draw()
|
|
138
|
+
lookNow()
|
|
139
|
+
$('input', body)?.focus()
|
|
140
|
+
}
|
|
141
|
+
const into = $('[data-nc-into]', back)
|
|
142
|
+
back.querySelectorAll('[data-nc-way]').forEach((b) => { b.onclick = () => pick(b.dataset.ncWay) })
|
|
143
|
+
|
|
144
|
+
form.onsubmit = async (e) => {
|
|
145
|
+
e.preventDefault()
|
|
146
|
+
if (way === 'folder') state.lastCreateDir = v.dir
|
|
147
|
+
if (await submit(form, '#nc-error', { mode: 'create', workspace, ...newCodebaseBody(way, v) }, WAYS.find((x) => x.id === way).busy)) close()
|
|
148
|
+
else draw() // the button says what it starts again
|
|
149
|
+
}
|
|
150
|
+
pick(way)
|
|
151
|
+
}
|
package/src/ui-server.js
CHANGED
|
@@ -14,6 +14,7 @@ import { runSession, decodeInvite, encodeInvite, newConn, readConfig, recentSess
|
|
|
14
14
|
import { MAX_SHARED_FILE_BYTES } from './protocol.js'
|
|
15
15
|
import { getSettings, saveSettings, unsupportedRelay, relayUrl } from './settings.js'
|
|
16
16
|
import { PICKUP_MODES, pickupMode } from './tasks.js'
|
|
17
|
+
import { prepareFolder, lookAt, briefTicket } from './new-session.js'
|
|
17
18
|
import { execFile } from 'node:child_process'
|
|
18
19
|
import { installedEditors, openIn, copyToClipboard } from './editors.js'
|
|
19
20
|
import { autowork, autoConfig, publicConfig, AUTO_MODES } from './autowork.js'
|
|
@@ -186,6 +187,7 @@ export const STATIC = {
|
|
|
186
187
|
'/feedback-model.js': ['feedback-model.js', 'text/javascript; charset=utf-8'],
|
|
187
188
|
'/loom.css': ['loom.css', 'text/css; charset=utf-8'],
|
|
188
189
|
'/board.js': ['board.js', 'text/javascript; charset=utf-8'],
|
|
190
|
+
'/new-session.js': ['new-session.js', 'text/javascript; charset=utf-8'],
|
|
189
191
|
'/schedule.js': ['schedule.js', 'text/javascript; charset=utf-8'],
|
|
190
192
|
'/workspaces.js': ['workspaces.js', 'text/javascript; charset=utf-8'],
|
|
191
193
|
'/invites.js': ['invites.js', 'text/javascript; charset=utf-8'],
|
|
@@ -444,7 +446,7 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
444
446
|
return dir && !fs.existsSync(dir) ? dir : underJoinDir(joinDir, room)
|
|
445
447
|
}
|
|
446
448
|
|
|
447
|
-
async function start ({ mode, dir, tool, invite, room, name, prefer, workspace }) {
|
|
449
|
+
async function start ({ mode, dir, tool, invite, room, name, prefer, workspace, source, repo, brief, into }) {
|
|
448
450
|
// An older window may still ask for a session from GitHub: it is told to start from a folder.
|
|
449
451
|
if (mode === 'github') throw httpError(410, GITHUB_GONE)
|
|
450
452
|
const me = profile()
|
|
@@ -471,6 +473,15 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
471
473
|
if (mode === 'join' && !dir) {
|
|
472
474
|
dir = room ? byRoomFolder(me.joinDir, byRoom(room).room, name) : underJoinDir(me.joinDir, decodeInvite(invite || '').room)
|
|
473
475
|
}
|
|
476
|
+
// A new session's folder has git before the session starts in it (new-session.js): a clone, a
|
|
477
|
+
// folder already here, or something new, with what the person wants to build as its first ticket.
|
|
478
|
+
let project = null
|
|
479
|
+
if (mode === 'create') {
|
|
480
|
+
if (dir) dir = path.resolve(expandHome(dir))
|
|
481
|
+
if (dir && runs.has(idFor(dir))) return summary(idFor(dir))
|
|
482
|
+
project = await prepareFolder({ source: source || 'folder', dir: dir || '', repo, name, brief, base: path.resolve(expandHome(into || me.joinDir)), who: { name: me.name } })
|
|
483
|
+
dir = project.dir
|
|
484
|
+
}
|
|
474
485
|
if (!dir) throw new Error('Choose a project folder.')
|
|
475
486
|
dir = path.resolve(expandHome(dir))
|
|
476
487
|
const id = idFor(dir)
|
|
@@ -515,7 +526,7 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
515
526
|
// Secrets (`quilt run` in this folder): the API as this computer's account.
|
|
516
527
|
apiAuth: personApiAuth,
|
|
517
528
|
// A new session is named after its folder (the owner can rename it later).
|
|
518
|
-
startName: mode === 'create' ? cleanSessionName([...path.basename(dir)].slice(0, SESSION_NAME_MAX).join('')) || '' : '',
|
|
529
|
+
startName: mode === 'create' ? cleanSessionName([...((project && project.name) || path.basename(dir))].slice(0, SESSION_NAME_MAX).join('')) || '' : '',
|
|
519
530
|
workspace: workspace || '',
|
|
520
531
|
onLog: log,
|
|
521
532
|
onFatal: async (err) => {
|
|
@@ -527,6 +538,9 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
527
538
|
}
|
|
528
539
|
})
|
|
529
540
|
} catch (err) {
|
|
541
|
+
// A clone or a new project made a moment ago for a session that then couldn't start: taken away
|
|
542
|
+
// again, so trying once more doesn't make a second folder beside it.
|
|
543
|
+
if (project && project.made) { try { fs.rmSync(dir, { recursive: true, force: true }) } catch {} }
|
|
530
544
|
if (!current()) throw outlived()
|
|
531
545
|
if (err.signedOut) {
|
|
532
546
|
await signedOut('revoked')
|
|
@@ -541,6 +555,14 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
541
555
|
}
|
|
542
556
|
runs.set(id, entry)
|
|
543
557
|
const s = entry.run.session
|
|
558
|
+
// What the person said they want to build is the project's first ticket, for their AI to pick up.
|
|
559
|
+
const first = project && briefTicket(project.brief)
|
|
560
|
+
if (first) {
|
|
561
|
+
try {
|
|
562
|
+
const t = s.addTask({ title: first.title })
|
|
563
|
+
if (first.comment) s.commentTask({ id: t.id, text: first.comment })
|
|
564
|
+
} catch (err) { log(`could not add the first ticket: ${err.message}`) }
|
|
565
|
+
}
|
|
544
566
|
s.on('status-changed', () => pushSoon(id))
|
|
545
567
|
s.on('access', () => pushSoon(id))
|
|
546
568
|
s.on('message', (m) => broadcast('message', { id, message: m }))
|
|
@@ -1142,6 +1164,8 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
1142
1164
|
workspacesOn
|
|
1143
1165
|
}),
|
|
1144
1166
|
'POST /api/sessions': (b) => start(b),
|
|
1167
|
+
// What starting a session from this would do (new-session.js), shown as the person fills the form in: nothing is made.
|
|
1168
|
+
'POST /api/new-session/look': (b) => lookAt({ source: b.source, dir: b.dir ? path.resolve(expandHome(String(b.dir))) : '', repo: b.repo, name: b.name, base: path.resolve(expandHome(String(b.into || '') || profile().joinDir)) }),
|
|
1145
1169
|
'POST /api/sessions/:id/open-in': async (b, id) => { await openIn(String(b.app || ''), get(id).root); return { ok: true } },
|
|
1146
1170
|
// Gathering the project's AI rules into AGENTS.md (project-rules.js): look first, then apply what was shown.
|
|
1147
1171
|
'GET /api/sessions/:id/rules/gather': (b, id) => get(id).rulesGatherPlan(),
|