@ok-ggwp/git-gloss 0.4.0 → 0.6.0
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 +49 -3
- package/dist/ary/browse.js +4 -61
- package/dist/ary/picker.js +163 -0
- package/dist/ary/server.js +87 -37
- package/dist/batch.js +129 -0
- package/dist/cli.js +2 -1
- package/dist/commands/ary.js +3 -3
- package/dist/commands/lint.js +96 -0
- package/dist/commands/review.js +5 -4
- package/dist/commands/reviews.js +117 -6
- package/dist/commands/show.js +14 -6
- package/dist/commands/signals.js +9 -8
- package/dist/commands/sync.js +14 -2
- package/dist/commands/why.js +3 -2
- package/dist/config.js +61 -5
- package/dist/findings.js +254 -0
- package/dist/floor.js +39 -12
- package/dist/git.js +18 -2
- package/dist/html/client.js +56 -11
- package/dist/html/data.js +20 -3
- package/dist/html/page.js +1 -1
- package/dist/html/style.css +39 -1
- package/dist/loader.js +6 -2
- package/dist/plain.js +10 -0
- package/dist/render.js +6 -4
- package/dist/reviews.js +112 -4
- package/dist/safe-match.js +5 -3
- package/dist/schema.js +10 -3
- package/dist/selection.js +21 -0
- package/dist/signals.js +13 -3
- package/dist/validate.js +8 -3
- package/package.json +2 -2
- package/skills/gloss/SKILL.md +26 -3
- package/dist/ary/client.js +0 -401
- package/dist/ary/index.html +0 -13
- package/dist/ary/style.css +0 -115
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@ git gloss hunks [<commit>|wip] list hunks, numbering changed lines for h3
|
|
|
15
15
|
git gloss signals [<commit>|<range>|wip] [--json]
|
|
16
16
|
what the diff itself says about attention: path classes, pattern
|
|
17
17
|
hits, dependency bumps and the computed floor
|
|
18
|
+
git gloss lint [<commit>|wip] [--json]
|
|
19
|
+
advisory checks of a gloss that a reviewer would make by eye
|
|
18
20
|
git gloss adopt [<commit>] move the gloss of uncommitted work onto the commit made from it
|
|
19
21
|
git gloss add [<commit>] -f a.json attach an annotation (validated against the diff; --allow-underrate)
|
|
20
22
|
git gloss carry <source>... [--to <c>] gloss a commit from the glosses of the commits its changes came from
|
|
@@ -35,7 +37,12 @@ git gloss review [<commit>|<range>] print a review prompt: git gloss review ma
|
|
|
35
37
|
--material ...only the gloss and code, for a reviewer with its own instructions
|
|
36
38
|
(which must tell it the author's text is untrusted)
|
|
37
39
|
git gloss versions [<commit>|wip] every gloss a commit has had, newest first (--show <n>, --restore <n>)
|
|
38
|
-
git gloss reviews [<commit>|<range>] the reviews recorded for commits, with their findings
|
|
40
|
+
git gloss reviews [<commit>|<range>] the reviews recorded for commits, with their findings and decisions
|
|
41
|
+
--decide <review-id> --finding <text> --outcome fixed|follow-up|rejected|accepted [--note <text>]
|
|
42
|
+
record what was decided about one finding
|
|
43
|
+
--decide <review-id> --complete the arbiter has finished with that review
|
|
44
|
+
--decide-template <review-id> print a JSON skeleton with a row per finding
|
|
45
|
+
--decide <review-id> --decide-file <file|-> record a filled-in skeleton, all or nothing
|
|
39
46
|
git gloss schema print the annotation JSON Schema
|
|
40
47
|
```
|
|
41
48
|
|
|
@@ -121,6 +128,10 @@ git gloss adopt # ...or move it by hand
|
|
|
121
128
|
|
|
122
129
|
The snapshot is a commit object built from a temporary index, kept by the private ref `refs/worktree/gloss/wip` (one per linked worktree); your branch, index and files are never touched. Taking a new snapshot keeps the gloss of groups whose changes are unchanged, so after committing part of the work or editing one part, only the rest needs glossing again. Its gloss lives in `refs/notes/gloss-wip`, which `sync` doesn't push. Untracked files that look like secrets (`.env`, `*.key`, `*.pem`, `credentials.json`, …) are left out of the snapshot, with a note, because snapshots are shown and sent to reviewers; stage one with `git add` to include it. If a branch or tag is called `wip`, `wip` still means it when there's no snapshot; otherwise use `heads/wip`. Commands warn when you've edited files or committed since the snapshot. `adopt` matches the snapshot's hunks to the commit's by content, so the work can be committed in several commits (each takes the groups whose changes it contains), and changes made after glossing are reported as unexplained rather than silently covered. Once everything is committed, the snapshot is cleared.
|
|
123
130
|
|
|
131
|
+
## Linting a gloss
|
|
132
|
+
|
|
133
|
+
`git gloss lint [<commit>|wip]` checks a gloss deterministically for what a reviewer checking its honesty would look for by eye, and prints one line per finding with a stable code: `no-impact`, `impact-below-floor`, `attention-below-floor`, `mechanical-on-floor` (graded mechanical over a floor signal such as CI or sensitive code; a lockfile bump is fine), `unknown-serves`, `test-serves-nothing`, `required-but-nothing-breaks` (`removal_impact` begins "nothing breaks", "no effect" and the like), `missing-risks` (attention `careful` or above and no `risks`) and `uncovered-hunks` (a stale gloss). It is advisory: findings never change the exit code (errors such as no gloss still do). `--json` prints `{target, findings: [{code, group?, hunk?, message}]}`. When the diff signals are unavailable (a malformed `.gloss/config.json`), the rating checks are skipped and lint says `incomplete` (`"incomplete": true` in `--json`) instead of `clean`. Run it after `add` and fix what it reports, or be ready to defend it.
|
|
134
|
+
|
|
124
135
|
## Glosses that follow your history
|
|
125
136
|
|
|
126
137
|
A gloss is attached to a commit, so anything that makes new commits from old ones has to bring it along. With `git gloss init --hooks`:
|
|
@@ -159,6 +170,41 @@ reviews: honesty: no issues (claude, 2026-10-18) · bugs: defects found (claude,
|
|
|
159
170
|
|
|
160
171
|
A review says that something was checked, not that it passed. Each review ends with a verdict (`VERDICT: CLEAN` or `VERDICT: ISSUES`). For each part of the commit, the latest review that saw it decides, and a clean result that followed one with issues says so.
|
|
161
172
|
|
|
173
|
+
### Decisions
|
|
174
|
+
|
|
175
|
+
A review holds a report and a verdict, so by itself it cannot tell "3 fixed, 2 deferred" from "5 ignored". Whoever arbitrates a review (the `gg-deliver` arbiter, or a person) records **decisions** about it, in the same notes ref and on the same commits as the review. A decision is one JSON line:
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
{"decision":1,"review":"<review id>","at":"…","by":"…","finding":"1","outcome":"fixed","note":"…"}
|
|
179
|
+
{"decision":1,"review":"<review id>","at":"…","by":"…","complete":true}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
`finding` is free text naming the finding. Reports are free markdown, so git-gloss does not parse findings out of the stored text, but for display (in `reviews` and the html page; the stored report stays raw) it labels every top-level list item `**[S.N]**`, S the section (a `#` heading, a bold-only line such as `**2. Removal**`, or a short plain `3. Title` line with a blank line on each side, followed by a bullet list; its own number if it has one, else the previous section plus one; unnumbered headings before the first item are titles and take none) and N the item's place in it, replacing the source's own bullet or number. Items before the first heading are labelled `[N]` and must be named `N:` or `N)` in `--decide` (`1 wording nit` is free text); a numbered heading (`3. Removal`) counts as the ref `3` for `--decide` although no label is printed for it.
|
|
183
|
+
|
|
184
|
+
Name a decision's finding by that ref, e.g. `--finding "1.2 wording nit"`: `--decide` warns on stderr (and records anyway) when the report has no such ref.
|
|
185
|
+
|
|
186
|
+
Decisions whose finding starts with a ref (`1.2 `, `1.2: `, or a bare `3:`, `3)`, `3.`; numbers over 3 digits are text) are listed in ref order (1.2 before 1.10), the others after them in time order.
|
|
187
|
+
|
|
188
|
+
A finding must have visible text: one that is empty, whitespace or only invisible characters is refused by `--decide` and skipped by the reader. `outcome` is `fixed`, `follow-up`, `rejected` or `accepted`; `note` is optional. The second line says the arbiter has finished and no more decisions are coming, which is what separates "all arbitrated" from "5 ignored". The marker carries no `finding`, `outcome` or `note` (`--complete` refuses them, and the reader skips a marker that has one, or `"complete": false`, which only a hand-written line has). The reader takes the keys in any order. The marker is advisory: decisions added after it are still accepted and counted. A review whose verdict is clean needs none.
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
git gloss reviews wip --decide <review-id> --finding "Rework: wip rule claim" --outcome follow-up --note "next release"
|
|
192
|
+
git gloss reviews wip --decide <review-id> --complete
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
To decide many findings at once, print a skeleton, fill in each `outcome` (and `note`), and record the file:
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
git gloss reviews wip --decide-template <review-id> > d.json # one row per ref, outcome ""
|
|
199
|
+
git gloss reviews wip --decide <review-id> --decide-file d.json # or - for stdin
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
The file is either an array of `{"finding", "outcome", "note"?}` or the template's object `{"review", "complete", "decisions": [...]}` (`review` and unknown keys are ignored, though a `review` that isn't the `--decide` id is refused; `"complete": true` also records the complete marker). Keys may come in any order. Each finding is the ref and the start of its text (`1.2 wording nit`), checked as for the single call, with the same warning for a ref the report lacks. Validation is all or nothing: everything is checked before anything is written (a repeated finding is refused too), and the records go in one write per commit, with a range written commit by commit (so a git failure midway can leave earlier commits written), so a bad row (naming its entry number), an empty `outcome` (an unfilled row), or a file over 500 entries or 1 MiB records nothing. It prints `recorded N decisions on M commits`. It cannot be combined with `--finding`, `--outcome`, `--note`, `--stamp` or `--record`.
|
|
203
|
+
|
|
204
|
+
The target (`wip`, a commit, a range) is as for `reviews`; the decision is added to every commit there that holds that review, and an unknown review id is an error. `by` is `--by <name>`, else `git config user.name`, else "unknown". `reviews` prints each review's id in its header line (the id `--decide` takes) and lists its decisions under it with a summary ("3 fixed, 2 follow-up · complete", or "4 decided · not marked complete"), and `show` carries the same summary on its reviews line. The HTML view (`html` and `ary`) shows the same under each review in its Reviews pane, with an outcome chip per decision, and adds how far they got to the stage's rail row (the latest 200 decisions of a review are listed). Decisions follow their reviews through `adopt` (so decisions made on `wip` survive committing), `carry`, rebases and `sync`. In the terminal, text from notes (decisions and review records) and commit subjects is shown with control characters, escape sequences, and bidi and zero-width characters (U+200B, U+200E, U+200F, U+061C, U+2060-U+2064, U+FEFF, tag characters) removed (each becomes a space; ZWNJ and ZWJ stay, so Persian words and emoji sequences render intact, and so does the soft hyphen; the html page applies none of this, so bidi overrides there are not removed), since it can arrive from a remote; decision lines over 16 KB are skipped silently, and review lines over 8 MiB or with findings text over 256 KiB are skipped with a warning; unknown outcomes and decisions for a review that is not on the commit are ignored.
|
|
205
|
+
|
|
206
|
+
Known cost: decisions share the review note, and a git-gloss without this feature ignores decision lines when reading but does not know to keep them: when it copies review records onto another commit (`adopt` and `carry`), it writes only the review records, so the decisions are lost on that copy (git's own note rewriting on an amend or rebase copies whole notes, so that path keeps them). Keep everyone who arbitrates on the same version. Likewise, decisions follow their reviews through `adopt` and `carry` only in versions that know them.
|
|
207
|
+
|
|
162
208
|
Like glosses, reviews follow rebased commits in repos set up with `git gloss init`. Reviews are shared by `git gloss sync` (and so by every push with the hooks) like glosses, for commits the remote has. They never conflict: everyone's reviews are kept. Other tools can record reviews too: `git gloss reviews --stamp <rev>` before the review, then `git gloss reviews --record` with the stamp and the report as JSON on stdin.
|
|
163
209
|
|
|
164
210
|
## Impact and attention
|
|
@@ -179,7 +225,7 @@ Notes using these fields are format 4; a git-gloss that predates them refuses su
|
|
|
179
225
|
- **Floor of the change**: skim for `local`, look for `module`, careful for `shared` and `contract`, must-read for `sensitive`, and at least careful when more than `attention.largeChangeFiles` (default 50) files changed.
|
|
180
226
|
- **Derived attention** (when the gloss declares none): start from the highest group impact (declared, else the group's floor) with the same mapping, then raise it one step (capped at must-read, once however many apply) for a behaviour-changing group that no test group serves, for a speculative or defensive group outside tests, or for more than `largeChangeFiles` files; never below the floor. A group is *behaviour-changing* when its necessity is not `mechanical` and not all its hunks are tests, docs, generated files or lockfiles. It is *served by tests* when a group made only of test-file hunks names it in `serves`, directly or through groups it serves; a test group serving `"task"` doesn't count.
|
|
181
227
|
|
|
182
|
-
`add` checks a gloss against the floor. A group whose declared `impact` is below its floor (above plain `module`) is a warning naming the signal. A declared `attention.level` below the floor is an error unless `attention.override_reason` says why; `--allow-underrate` turns that error into a warning.
|
|
228
|
+
`add` checks a gloss against the floor. A group whose declared `impact` is below its floor (above plain `module`) is a warning naming the signal. A declared `attention.level` below the floor is an error unless `attention.override_reason` says why; `--allow-underrate` turns that error into a warning. `add` also warns, once, naming the groups with no `impact` that should have one: every group except a `mechanical` one on plain source (floor `module` or below); a mechanical lockfile bump, say, still counts. It still accepts the gloss, and leaving `impact` or `attention` out is never an error. An `override_reason` is shown by `show` and `html` next to the floor, flagged as a mismatch.
|
|
183
229
|
|
|
184
230
|
### Config
|
|
185
231
|
|
|
@@ -212,7 +258,7 @@ All gloss and diff text is rendered as text, and a Content-Security-Policy with
|
|
|
212
258
|
|
|
213
259
|
## Browsing
|
|
214
260
|
|
|
215
|
-
`git gloss ary` starts a small web server and opens it in your browser, so you can explore glosses without working out commits, branches and ranges on the command line.
|
|
261
|
+
`git gloss ary` starts a small web server and opens it in your browser, so you can explore glosses without working out commits, branches and ranges on the command line. The page is the review desk that `git gloss html` writes, with the pickers in its top bar: choose a branch and a branch to compare it with (the repo's `main` or `master` by default); each picker has a search box, for repos with many branches. With a base, the desk's own sidebar lists the commits of the range; with "none" (or when there is nothing beyond the base, or more than 200 commits) the page shows just the branch's newest commit and its groups. To look at anything else, such as `HEAD~3` or `release..main`, type it into the revision box. As everywhere in git-gloss, `wip` there means the snapshot of uncommitted work, which is what opens first once it has been snapshotted (`git gloss hunks wip`); to view a branch or tag called `wip`, type `heads/wip` or `tags/wip`. Every choice loads a new page (`/?rev=…&head=…&base=…`), regenerated from the repo each time, so reloading picks up new glosses and reviews, and the address keeps the selection (with a random port, a bookmark lasts only until you stop the server; pass `--port` for a stable address).
|
|
216
262
|
|
|
217
263
|
It serves one repository, the one you run it in, until you press Ctrl-C. It listens on 127.0.0.1 only, on a free port (or `--port`), only answers requests addressed to that host name, and never writes anything: it doesn't take snapshots or change notes. A page shows at most 200 commits; pick a narrower range for more. `--no-open` doesn't launch a browser.
|
|
218
264
|
|
package/dist/ary/browse.js
CHANGED
|
@@ -1,80 +1,23 @@
|
|
|
1
1
|
import { basename } from 'node:path';
|
|
2
|
-
import {
|
|
3
|
-
import { REVIEWS_REF } from '../reviews.js';
|
|
4
|
-
// The commits a notes ref has notes on ("<note> <commit>" per line). A missing
|
|
5
|
-
// ref is no notes.
|
|
6
|
-
function notedCommits(ref) {
|
|
7
|
-
const lines = (gitTry(['notes', '--ref', ref, 'list']) ?? '').split('\n');
|
|
8
|
-
return new Set(lines.filter(Boolean).map((l) => l.split(' ')[1]));
|
|
9
|
-
}
|
|
2
|
+
import { git, gitTry } from '../git.js';
|
|
10
3
|
function refList(namespace) {
|
|
11
|
-
return git(['for-each-ref', '--sort=-committerdate', '--format=%(refname)%00%(refname:short)
|
|
4
|
+
return git(['for-each-ref', '--sort=-committerdate', '--format=%(refname)%00%(refname:short)', namespace])
|
|
12
5
|
.split('\n')
|
|
13
6
|
.filter(Boolean)
|
|
14
7
|
.map((l) => l.split('\0'))
|
|
15
8
|
// refs/remotes/<remote>/HEAD is a pointer to another branch, not a branch.
|
|
16
9
|
.filter(([full]) => !full.endsWith('/HEAD'))
|
|
17
|
-
.map(([, name
|
|
10
|
+
.map(([, name]) => name);
|
|
18
11
|
}
|
|
19
12
|
export function listRefs() {
|
|
20
13
|
const branches = refList('refs/heads');
|
|
21
14
|
const remotes = refList('refs/remotes');
|
|
22
|
-
const names = new Set([...branches, ...remotes]
|
|
23
|
-
const wipSha = gitTry(['rev-parse', '--verify', '--quiet', WIP_REF])?.trim();
|
|
24
|
-
let stale = null;
|
|
25
|
-
if (wipSha) {
|
|
26
|
-
try {
|
|
27
|
-
stale = wipStaleness(wipSha);
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
// Staleness is advice; the snapshot is still viewable without it.
|
|
31
|
-
}
|
|
32
|
-
}
|
|
15
|
+
const names = new Set([...branches, ...remotes]);
|
|
33
16
|
return {
|
|
34
17
|
repo: basename(git(['rev-parse', '--show-toplevel']).trim()),
|
|
35
18
|
current: gitTry(['symbolic-ref', '--short', '--quiet', 'HEAD'])?.trim() || null,
|
|
36
19
|
branches,
|
|
37
20
|
remotes,
|
|
38
21
|
defaultBase: ['main', 'master', 'origin/main', 'origin/master'].find((n) => names.has(n)) ?? null,
|
|
39
|
-
wip: wipSha ? { sha: wipSha, glossed: notedCommits(WIP_NOTES_REF).has(wipSha), stale } : null,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
// Newest first: the commits of `head`, or only those not in `base` when given.
|
|
43
|
-
// `query` keeps the commits whose message or author contains it (any case).
|
|
44
|
-
export function listLog(head, base, limit, skip, query = '') {
|
|
45
|
-
const range = base ? `${base}..${head}` : head;
|
|
46
|
-
const format = '--format=%H%x00%an%x00%aI%x00%s%x00%P';
|
|
47
|
-
let out;
|
|
48
|
-
if (query) {
|
|
49
|
-
// git ANDs --grep with --author, so ask for each on its own and merge, then
|
|
50
|
-
// list the union by commit date (what --no-walk=sorted gives, which can
|
|
51
|
-
// differ from the order of an unfiltered log when dates are skewed).
|
|
52
|
-
const shas = new Set();
|
|
53
|
-
for (const filter of ['--grep', '--author']) {
|
|
54
|
-
const found = git(['log', '--format=%H', '--regexp-ignore-case', '--fixed-strings', `${filter}=${query}`, '--end-of-options', range, '--']);
|
|
55
|
-
for (const sha of found.split('\n').filter(Boolean))
|
|
56
|
-
shas.add(sha);
|
|
57
|
-
}
|
|
58
|
-
// No -n or --skip here: git then walks on to the parents, so page by hand.
|
|
59
|
-
out = shas.size
|
|
60
|
-
? git(['log', '--no-walk=sorted', '--stdin', format], [...shas].join('\n') + '\n').split('\n').slice(skip, skip + limit + 1).join('\n')
|
|
61
|
-
: '';
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
// One more than asked for, to know whether there are more.
|
|
65
|
-
out = git(['log', format, '-n', String(limit + 1), '--skip', String(skip), '--end-of-options', range, '--']);
|
|
66
|
-
}
|
|
67
|
-
const glossed = notedCommits(NOTES_REF);
|
|
68
|
-
const reviewed = notedCommits(REVIEWS_REF);
|
|
69
|
-
const rows = out.split('\n').filter(Boolean).map((l) => l.split('\0'));
|
|
70
|
-
return {
|
|
71
|
-
commits: rows.slice(0, limit).map(([sha, author, date, subject, parents]) => ({
|
|
72
|
-
sha, author, date, subject,
|
|
73
|
-
merge: parents.includes(' '),
|
|
74
|
-
glossed: glossed.has(sha),
|
|
75
|
-
reviewed: reviewed.has(sha),
|
|
76
|
-
})),
|
|
77
|
-
more: rows.length > limit,
|
|
78
|
-
total: base && !query ? Number(git(['rev-list', '--count', '--end-of-options', range, '--']).trim()) : null,
|
|
79
22
|
};
|
|
80
23
|
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// The branch pickers and revision box in the desk's top bar when served by
|
|
2
|
+
// `git gloss ary`. Included by page.ts only in that mode, ahead of the desk's
|
|
3
|
+
// script, in the same nonce'd <script>; `el` and `add` are the desk's helpers. It makes no requests: the branches
|
|
4
|
+
// arrive in the page data. Choosing something loads the URL for it, and the
|
|
5
|
+
// server renders that page. Text only goes through textContent.
|
|
6
|
+
function aryBar(ary, el, add) {
|
|
7
|
+
'use strict'
|
|
8
|
+
// A branch picker with a search box: a repo can have hundreds of branches,
|
|
9
|
+
// too many to scan in a <select>. Matching is case-insensitive and every
|
|
10
|
+
// space-separated word must appear in the name.
|
|
11
|
+
var SHOWN = 200
|
|
12
|
+
function picker(onPick) {
|
|
13
|
+
var root = el('div', 'combo')
|
|
14
|
+
var button = el('button', 'combo-btn')
|
|
15
|
+
button.type = 'button'
|
|
16
|
+
button.setAttribute('aria-haspopup', 'listbox')
|
|
17
|
+
var panel = el('div', 'combo-panel')
|
|
18
|
+
panel.hidden = true
|
|
19
|
+
var input = el('input')
|
|
20
|
+
input.type = 'search'
|
|
21
|
+
input.spellcheck = false
|
|
22
|
+
input.placeholder = 'Search branches…'
|
|
23
|
+
input.setAttribute('aria-label', 'Search branches')
|
|
24
|
+
var list = el('div', 'combo-list')
|
|
25
|
+
list.setAttribute('role', 'listbox')
|
|
26
|
+
add(panel, input, list)
|
|
27
|
+
add(root, button, panel)
|
|
28
|
+
|
|
29
|
+
var groups = []
|
|
30
|
+
var noneLabel = null
|
|
31
|
+
var value = null
|
|
32
|
+
var items = [] // the rows now shown: { value, node }
|
|
33
|
+
var active = 0
|
|
34
|
+
|
|
35
|
+
function matches(name, words) {
|
|
36
|
+
var n = name.toLowerCase()
|
|
37
|
+
return words.every(function (w) { return n.indexOf(w) >= 0 })
|
|
38
|
+
}
|
|
39
|
+
function paint() {
|
|
40
|
+
items.forEach(function (it, i) { it.node.classList.toggle('active', i === active) })
|
|
41
|
+
if (items[active]) items[active].node.scrollIntoView({ block: 'nearest' })
|
|
42
|
+
}
|
|
43
|
+
function render() {
|
|
44
|
+
var words = input.value.toLowerCase().split(/\s+/).filter(Boolean)
|
|
45
|
+
list.textContent = ''
|
|
46
|
+
items = []
|
|
47
|
+
var shown = 0
|
|
48
|
+
var hidden = 0
|
|
49
|
+
function item(label, v) {
|
|
50
|
+
var node = el('button', 'combo-item', label)
|
|
51
|
+
node.type = 'button'
|
|
52
|
+
node.setAttribute('role', 'option')
|
|
53
|
+
node.setAttribute('aria-selected', String(v === value))
|
|
54
|
+
node.addEventListener('click', function () { pick(v) })
|
|
55
|
+
items.push({ value: v, node: node })
|
|
56
|
+
return node
|
|
57
|
+
}
|
|
58
|
+
if (noneLabel && !words.length) list.appendChild(item(noneLabel, null))
|
|
59
|
+
groups.forEach(function (g) {
|
|
60
|
+
var found = g.names.filter(function (n) { return matches(n, words) })
|
|
61
|
+
var room = found.slice(0, Math.max(0, SHOWN - shown))
|
|
62
|
+
hidden += found.length - room.length
|
|
63
|
+
shown += room.length
|
|
64
|
+
if (!room.length) return
|
|
65
|
+
add(list, add(el('div', 'combo-group', g.label), el('span', 'count', found.length)))
|
|
66
|
+
room.forEach(function (n) { list.appendChild(item(n, n)) })
|
|
67
|
+
})
|
|
68
|
+
if (hidden) add(list, el('div', 'combo-more', hidden + ' more: keep typing to narrow the list'))
|
|
69
|
+
if (!items.length) add(list, el('div', 'combo-more', 'No branches match.'))
|
|
70
|
+
// Start on the current value, or on the first match when searching.
|
|
71
|
+
var at = words.length ? -1 : items.findIndex(function (it) { return it.value === value })
|
|
72
|
+
active = at >= 0 ? at : 0
|
|
73
|
+
paint()
|
|
74
|
+
}
|
|
75
|
+
function open() {
|
|
76
|
+
panel.hidden = false
|
|
77
|
+
button.setAttribute('aria-expanded', 'true')
|
|
78
|
+
input.value = ''
|
|
79
|
+
render()
|
|
80
|
+
input.focus()
|
|
81
|
+
}
|
|
82
|
+
function close() {
|
|
83
|
+
panel.hidden = true
|
|
84
|
+
button.setAttribute('aria-expanded', 'false')
|
|
85
|
+
}
|
|
86
|
+
function pick(v) {
|
|
87
|
+
close()
|
|
88
|
+
button.focus()
|
|
89
|
+
if (v !== value) onPick(v)
|
|
90
|
+
}
|
|
91
|
+
button.addEventListener('click', function () { if (panel.hidden) open(); else close() })
|
|
92
|
+
input.addEventListener('input', render)
|
|
93
|
+
input.addEventListener('keydown', function (ev) {
|
|
94
|
+
if (ev.key === 'ArrowDown' || ev.key === 'ArrowUp') {
|
|
95
|
+
ev.preventDefault()
|
|
96
|
+
if (items.length) active = (active + (ev.key === 'ArrowDown' ? 1 : items.length - 1)) % items.length
|
|
97
|
+
paint()
|
|
98
|
+
} else if (ev.key === 'Enter') {
|
|
99
|
+
ev.preventDefault()
|
|
100
|
+
if (items[active]) pick(items[active].value)
|
|
101
|
+
} else if (ev.key === 'Escape') {
|
|
102
|
+
ev.preventDefault()
|
|
103
|
+
close()
|
|
104
|
+
button.focus()
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
document.addEventListener('mousedown', function (ev) { if (!panel.hidden && !root.contains(ev.target)) close() })
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
root: root,
|
|
111
|
+
// Local and remote branches, and what choosing "no branch" is called (if allowed).
|
|
112
|
+
setOptions: function (g, none) { groups = g; noneLabel = none },
|
|
113
|
+
setValue: function (v) {
|
|
114
|
+
value = v
|
|
115
|
+
button.textContent = v || noneLabel || 'choose a branch'
|
|
116
|
+
button.title = button.textContent
|
|
117
|
+
},
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function branchGroups() {
|
|
122
|
+
return [
|
|
123
|
+
{ label: 'Local branches', names: ary.branches },
|
|
124
|
+
{ label: 'Remote branches', names: ary.remotes },
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
function go(head, base, rev) {
|
|
128
|
+
var p = new URLSearchParams()
|
|
129
|
+
if (rev) p.set('rev', rev)
|
|
130
|
+
if (head) p.set('head', head)
|
|
131
|
+
if (base) p.set('base', base)
|
|
132
|
+
location.assign('/?' + p.toString())
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
var headPicker = picker(function (name) {
|
|
136
|
+
// A feature branch is most useful against the usual base; the base itself is listed whole.
|
|
137
|
+
go(name, name === ary.defaultBase ? null : ary.defaultBase, null)
|
|
138
|
+
})
|
|
139
|
+
headPicker.setOptions(branchGroups(), null)
|
|
140
|
+
headPicker.setValue(ary.head)
|
|
141
|
+
var basePicker = picker(function (name) { go(ary.head, name, null) })
|
|
142
|
+
basePicker.setOptions(branchGroups(), '(none: just the newest commit)')
|
|
143
|
+
basePicker.setValue(ary.base)
|
|
144
|
+
|
|
145
|
+
var input = el('input')
|
|
146
|
+
input.type = 'text'
|
|
147
|
+
input.spellcheck = false
|
|
148
|
+
input.placeholder = 'HEAD~3, abc123, main..feature, wip'
|
|
149
|
+
input.setAttribute('aria-label', 'Any revision or range')
|
|
150
|
+
input.value = ary.rev || ''
|
|
151
|
+
var form = add(el('form', 'ary-rev'), input)
|
|
152
|
+
form.addEventListener('submit', function (ev) {
|
|
153
|
+
ev.preventDefault()
|
|
154
|
+
var v = input.value.trim()
|
|
155
|
+
if (v) go(ary.head, ary.base, v)
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
function field(label, node) { return add(el('div', 'ary-field'), el('span', null, label), node) }
|
|
159
|
+
var bar = add(el('div', 'ary-bar'), el('span', 'ary-repo', ary.repo),
|
|
160
|
+
field('Branch', headPicker.root), field('Compare with', basePicker.root), field('Revision', form))
|
|
161
|
+
if (ary.notice) bar.appendChild(el('p', 'ary-notice', ary.notice))
|
|
162
|
+
return bar
|
|
163
|
+
}
|
package/dist/ary/server.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
1
|
import { createServer } from 'node:http';
|
|
3
|
-
import { GlossError, WIP_REF, gitTry, resolveCommits } from '../git.js';
|
|
2
|
+
import { GlossError, WIP_REF, git, gitTry, resolveCommits } from '../git.js';
|
|
4
3
|
import { buildPageData } from '../html/data.js';
|
|
5
4
|
import { escapeHtml, renderPage } from '../html/page.js';
|
|
6
|
-
import {
|
|
7
|
-
const asset = (name) => readFileSync(new URL(name, import.meta.url), 'utf8');
|
|
5
|
+
import { listRefs } from './browse.js';
|
|
8
6
|
// A range page loads and lays out every commit in it, so a huge one would hang
|
|
9
7
|
// the browser. Narrowing it is a better answer than a spinner.
|
|
10
8
|
export const MAX_RANGE_COMMITS = 200;
|
|
11
|
-
// The shell page loads only its own script and style, and may frame only
|
|
12
|
-
// /view pages. Those carry their own policy: an inline script with a nonce.
|
|
13
|
-
const SHELL_CSP = "default-src 'none'; script-src 'self'; style-src 'self'; connect-src 'self'; frame-src 'self'; base-uri 'none'; form-action 'none'";
|
|
14
9
|
class BadRequest extends GlossError {
|
|
15
10
|
}
|
|
16
11
|
// A revision, branch or range typed by the user or taken from the sidebar. An
|
|
@@ -26,10 +21,6 @@ function revParam(url, name, required = true) {
|
|
|
26
21
|
throw new BadRequest(`not a revision: ${v.slice(0, 80)}`);
|
|
27
22
|
return v;
|
|
28
23
|
}
|
|
29
|
-
const intParam = (url, name, fallback, min, max) => {
|
|
30
|
-
const n = Number(url.searchParams.get(name) ?? fallback);
|
|
31
|
-
return Number.isInteger(n) && n >= min ? Math.min(n, max) : fallback;
|
|
32
|
-
};
|
|
33
24
|
function send(res, status, type, body, headers = {}) {
|
|
34
25
|
res.writeHead(status, {
|
|
35
26
|
'content-type': `${type}; charset=utf-8`,
|
|
@@ -41,9 +32,74 @@ function send(res, status, type, body, headers = {}) {
|
|
|
41
32
|
});
|
|
42
33
|
res.end(body);
|
|
43
34
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
35
|
+
// The page may not be framed by anyone: it shows the code of your commits.
|
|
36
|
+
const PAGE_HEADERS = { 'content-security-policy': "frame-ancestors 'none'" };
|
|
37
|
+
function errorPage(res, status, message) {
|
|
38
|
+
send(res, status, 'text/html', `<!doctype html><meta charset="utf-8"><meta name="color-scheme" content="light dark"><pre style="white-space:pre-wrap;font:14px/1.5 system-ui;padding:16px">${escapeHtml(message)}</pre><p style="font:14px/1.5 system-ui;padding:0 16px"><a href="/">Back to the default view</a></p>`, { 'content-security-policy': "default-src 'none'; style-src 'unsafe-inline'; frame-ancestors 'none'" });
|
|
39
|
+
}
|
|
40
|
+
// The commits of `head` the page shows when nothing else is chosen: those
|
|
41
|
+
// beyond `base` (when a page can show them all), or else the newest one (as a sha, so a branch called "wip"
|
|
42
|
+
// doesn't mean the snapshot).
|
|
43
|
+
function defaultRev(head, base) {
|
|
44
|
+
if (!head)
|
|
45
|
+
return null;
|
|
46
|
+
if (base) {
|
|
47
|
+
// A range beyond what a page shows would only be an error page: show the newest commit.
|
|
48
|
+
const n = Number(git(['rev-list', '--count', '--end-of-options', `${base}..${head}`, '--']).trim());
|
|
49
|
+
if (n > 0 && n <= MAX_RANGE_COMMITS)
|
|
50
|
+
return `${base}..${head}`;
|
|
51
|
+
}
|
|
52
|
+
return gitTry(['rev-parse', '--verify', '--quiet', `${head}^{commit}`])?.trim() || null;
|
|
53
|
+
}
|
|
54
|
+
// The page for ?rev=&head=&base=. head and base only fill the pickers and
|
|
55
|
+
// choose the default rev; the rev alone decides which commits are shown.
|
|
56
|
+
function deskPage(url, res) {
|
|
57
|
+
const refs = listRefs();
|
|
58
|
+
const known = new Set([...refs.branches, ...refs.remotes]);
|
|
59
|
+
const wantHead = revParam(url, 'head', false);
|
|
60
|
+
const wantBase = revParam(url, 'base', false);
|
|
61
|
+
let rev = revParam(url, 'rev', false);
|
|
62
|
+
// The default base goes with the default branch.
|
|
63
|
+
const baseFor = (head) => (head === refs.defaultBase ? null : refs.defaultBase);
|
|
64
|
+
// A link or bookmark may name a branch that has since been deleted or
|
|
65
|
+
// renamed: use the usual choice instead, and say so.
|
|
66
|
+
let head = wantHead && known.has(wantHead) ? wantHead : null;
|
|
67
|
+
const fallback = refs.current || refs.defaultBase || refs.branches[0] || null;
|
|
68
|
+
let base;
|
|
69
|
+
let notice = null;
|
|
70
|
+
if (wantHead && !head) {
|
|
71
|
+
head = fallback;
|
|
72
|
+
base = baseFor(head);
|
|
73
|
+
notice = `Branch \u201c${wantHead}\u201d no longer exists; showing ${head ?? 'the default'} instead.`;
|
|
74
|
+
}
|
|
75
|
+
else if (wantBase && !known.has(wantBase)) {
|
|
76
|
+
head ??= fallback;
|
|
77
|
+
base = null;
|
|
78
|
+
notice = `The branch to compare with, \u201c${wantBase}\u201d, no longer exists; showing the newest commit of ${head ?? 'the default'}.`;
|
|
79
|
+
}
|
|
80
|
+
else if (head) {
|
|
81
|
+
base = wantBase;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
head = fallback;
|
|
85
|
+
base = wantBase ?? baseFor(head);
|
|
86
|
+
}
|
|
87
|
+
if (!rev) {
|
|
88
|
+
// Opening with nothing chosen shows the uncommitted work, if snapshotted;
|
|
89
|
+
// choosing a branch shows that branch.
|
|
90
|
+
const wip = !wantHead && !wantBase && gitTry(['rev-parse', '--verify', '--quiet', WIP_REF]);
|
|
91
|
+
rev = wip ? 'wip' : defaultRev(head, base);
|
|
92
|
+
if (!rev)
|
|
93
|
+
throw new GlossError(head ? `${head} has no commits to show` : 'there are no branches to show; pass ?rev= to view a commit');
|
|
94
|
+
if (!notice) {
|
|
95
|
+
const p = new URLSearchParams({ rev });
|
|
96
|
+
if (head)
|
|
97
|
+
p.set('head', head);
|
|
98
|
+
if (base)
|
|
99
|
+
p.set('base', base);
|
|
100
|
+
return send(res, 302, 'text/plain', 'redirecting', { location: `/?${p}` });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
47
103
|
// "wip" is the latest snapshot of uncommitted work. The server never takes
|
|
48
104
|
// one (that is `git gloss hunks wip`): browsing doesn't change anything.
|
|
49
105
|
const target = rev === 'wip' ? gitTry(['rev-parse', '--verify', '--quiet', WIP_REF])?.trim() : rev;
|
|
@@ -53,22 +109,14 @@ function viewPage(url) {
|
|
|
53
109
|
if (shas.length > MAX_RANGE_COMMITS) {
|
|
54
110
|
throw new GlossError(`${rev} has ${shas.length} commits; a page shows at most ${MAX_RANGE_COMMITS}. Pick a narrower range.`);
|
|
55
111
|
}
|
|
56
|
-
|
|
112
|
+
const data = buildPageData(shas, range, merges);
|
|
113
|
+
data.ary = { repo: refs.repo, branches: refs.branches, remotes: refs.remotes, defaultBase: refs.defaultBase, head, base, rev, notice };
|
|
114
|
+
send(res, 200, 'text/html', renderPage(data), PAGE_HEADERS);
|
|
57
115
|
}
|
|
58
|
-
function route(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
case '/ary.js': return shell('./client.js', 'text/javascript');
|
|
63
|
-
case '/ary.css': return shell('./style.css', 'text/css');
|
|
64
|
-
case '/api/refs': return sendJson(res, listRefs());
|
|
65
|
-
case '/api/log':
|
|
66
|
-
return sendJson(res, listLog(revParam(url, 'head'), revParam(url, 'base', false), intParam(url, 'limit', 100, 1, 500), intParam(url, 'skip', 0, 0, 1e6), (url.searchParams.get('q') ?? '').slice(0, 200)));
|
|
67
|
-
case '/view':
|
|
68
|
-
// The page may only be framed by the shell, not by another site.
|
|
69
|
-
return send(res, 200, 'text/html', viewPage(url), { 'content-security-policy': "frame-ancestors 'self'" });
|
|
70
|
-
default: return send(res, 404, 'text/plain', 'not found');
|
|
71
|
-
}
|
|
116
|
+
function route(res, url) {
|
|
117
|
+
if (url.pathname === '/')
|
|
118
|
+
return deskPage(url, res);
|
|
119
|
+
send(res, 404, 'text/plain', 'not found');
|
|
72
120
|
}
|
|
73
121
|
export function createAry(port) {
|
|
74
122
|
return createServer((req, res) => {
|
|
@@ -80,9 +128,16 @@ export function createAry(port) {
|
|
|
80
128
|
return send(res, 403, 'text/plain', `forbidden host: this server answers to ${allowed.join(' and ')} (it listens on this machine only; through an SSH tunnel, forward the same port number)`);
|
|
81
129
|
if (req.method !== 'GET' && req.method !== 'HEAD')
|
|
82
130
|
return send(res, 405, 'text/plain', 'read-only', { allow: 'GET, HEAD' });
|
|
83
|
-
const url = new URL(req.url ?? '/', 'http://localhost');
|
|
84
131
|
try {
|
|
85
|
-
|
|
132
|
+
// A request target need not be a URL ("//[" is not), and a throw here would end the process.
|
|
133
|
+
let url;
|
|
134
|
+
try {
|
|
135
|
+
url = new URL(req.url ?? '/', 'http://localhost');
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
throw new BadRequest('not a valid request target');
|
|
139
|
+
}
|
|
140
|
+
route(res, url);
|
|
86
141
|
}
|
|
87
142
|
catch (err) {
|
|
88
143
|
if (!(err instanceof GlossError)) {
|
|
@@ -90,12 +145,7 @@ export function createAry(port) {
|
|
|
90
145
|
return send(res, 500, 'text/plain', 'internal error');
|
|
91
146
|
}
|
|
92
147
|
const status = err instanceof BadRequest ? 400 : 422;
|
|
93
|
-
|
|
94
|
-
send(res, status, 'text/html', `<!doctype html><meta charset="utf-8"><meta name="color-scheme" content="light dark"><pre style="white-space:pre-wrap;font:14px/1.5 system-ui;padding:16px">${escapeHtml(err.message)}</pre>`, { 'content-security-policy': "default-src 'none'; style-src 'unsafe-inline'; frame-ancestors 'self'" });
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
send(res, status, 'application/json', JSON.stringify({ error: err.message }));
|
|
98
|
-
}
|
|
148
|
+
errorPage(res, status, err.message);
|
|
99
149
|
}
|
|
100
150
|
});
|
|
101
151
|
}
|