rvlib-shipkit 2.8.0 → 2.10.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/CHANGELOG.md +16 -0
- package/package.json +1 -1
- package/src/checks/SK005-rvlib-versions.check.ts +17 -11
- package/src/cli/cmd_Fleet.ts +8 -5
- package/src/cli/cmd_Review.ts +2 -1
- package/src/core/update-policy.ts +6 -0
- package/src/fleet/commit-bump.ts +123 -0
- package/src/fleet/push-fleet.ts +9 -3
- package/src/fleet/update-fleet.ts +38 -9
- package/src/review/cells.ts +548 -0
- package/src/review/format.ts +1 -1
- package/src/review/model.ts +29 -4
- package/src/review/previews.ts +124 -0
- package/src/review/routes.ts +82 -45
- package/src/review/store.ts +6 -5
- package/src/serve/hub-app/auto-text.tsx +52 -0
- package/src/serve/hub-app/hub.css +2 -0
- package/src/serve/hub-app/media-view.tsx +3 -11
- package/src/serve/hub-app/review/kind-view.tsx +21 -22
- package/src/serve/hub-app/review/kit.tsx +11 -12
- package/src/serve/hub-app/review/review-board.tsx +15 -13
- package/src/serve/hub-app/review/review-cells.tsx +241 -0
- package/src/serve/hub-app/review/review-kit.ts +79 -0
- package/src/serve/hub-app/review/review-list.tsx +87 -122
- package/src/serve/hub-app/review/review-page.tsx +25 -66
- package/src/serve/hub-app/review/review-st.ts +269 -668
- package/src/serve/hub-app/review/review-thread.tsx +301 -0
- package/src/serve/hub-app/review/review-views.tsx +372 -234
- package/src/serve/hub-app/review/thread-st.ts +770 -0
- package/src/serve/hub-app/review/trailer-page.tsx +5 -4
- package/src/serve/hub-app/review.css +252 -90
- package/src/serve/hub-app/review/review-answer.tsx +0 -248
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
## 2.10.0
|
|
2
|
+
|
|
3
|
+
- **Every old review card reads well as a thread, and his draft survives a new version.** A version that lands while he writes leaves his draft on the version he started it on (« move it to v4 / keep it on v3 »), a draft orphaned under an older version is found again, and what he types while an answer is on its way stays. The card opened with none named stays open when a poll reorders the list. An agent's word goes read when its cell shows with the tab visible, and `POST …/read` takes `{ of }` so only the words drawn are marked. The thread index is kept per store, so two repos' pages keep their 304s.
|
|
4
|
+
- **Views are lettered, never numbered: `3.A`, `3.B`, then `AA`.** In the page (sub cells, rows, contents, verdict notes, the pick) and the CLI (`[B voice 1]`, `view B added`).
|
|
5
|
+
- **The review card reads like a notebook.** A version's gutter carries a big sticky `v3`; each view has one sticky header row (its `3.A`, title, kind, labelled OK / Fix / No, its tools). A clip opened under its row has one clock (its own bar), the downloads say « save mp4 » and « show in Finder ». The minimap (the thin strip, the contents' head, a row under the title on the phone) shows every version and, under the one he answers, a mark per view coloured by his answer, and the card's head says « 3 of 5 views waiting for you ». His draft notes are listed under their view, marked a draft the verdict sends. Long agent texts fold to « more », runs of state changes say their count and time span, forks are links, an agent with no lane names its session, a verdict on a raised item says « on the note », a view whose media the store lost says so.
|
|
6
|
+
- **A clip that opens on black previews on a lit frame.** A black poster (a trailer fading in) is previewed from the first frame of its clip at 10, 25 or 50 % of its length that is not black, cached like every preview.
|
|
7
|
+
- **The review card reads as one chat of framed cells.** The open card is one thread top to bottom, the newest at the bottom, the column opening on the newest version (or the agent word he has not read, or the version an old link names), his answer box pinned under it. Every version, verdict, reply and note is a framed cell with a header bar (who, when, the kind, `v2`, fold, copy the id); a folded cell is its header and one line, and loads no media. Inside a version each view is its own numbered sub cell (`3.2`) with a big title and its kind, drawn as before (image, the four compare modes, clip, sound, gallery, option rows), and what each answer said on it (rectangles in his pink, reactions, words) sits right under it. A verdict points back at its version and lists his notes, each a click from its view. A contents strip lists every version, view, verdict and reply, a click unfolds and scrolls there: beside the cells on a wide column, else a thin strip of version pills that opens it as a sheet. One word box sends a verdict with his marks or a reply alone (⌘Enter); his draft starts empty on each version. The list reads `GET /api/review/threads` a page at a time, its search and filters asked of the server; the thread reads `GET /api/review/threads/<id>`; images come at the column's or the list's size, the full file only on zoom. On pkm-multi a card's title shows in 0.52 s warm (was 0.8 to 1.8 s) and 4.0 s cold (was 6.7 to 7.3 s), and a card open moves 0.24 to 0.5 MB of review data (was 9 MB and more). The phone shows the same thread one pane at a time, the verdicts and « Reply » in one row under the thumb. The old layout (`top`, `left`, `auto`, the answer column) is gone; `GET /api/review/board` serves the dispatcher's board; `GET /api/review` stays for pkm-multi's admin only.
|
|
8
|
+
- **A review card reads as one thread of cells, and the hub can fetch one page and one thread.** A supersedes chain (v1, v2, v3…) folds at read time into one thread, nothing rewritten: each version, verdict, reply, raised note and state change is a cell in time order, with a one line summary and its default fold (`src/review/cells.ts`). `GET /api/review/threads` answers one page of the list (the waiting cards first, handled ones with `handled=1`, `subject`, `whose`, `status`, `lane`, a search over every version and message, `offset`, `limit`), about 1 to 6 KB where the whole list was 1.1 MB gzipped. `GET /api/review/threads/<id>` answers one thread by any of its ids, an old version's included. Both carry an ETag.
|
|
9
|
+
- **Review previews: a thumb and a fit size, made once per image.** `GET /api/review/<id>/preview/thumb|fit/<name>`, a webp 480 or 1600 px wide, kept in `.shipkit/cache/review-previews/` instead of the store's `.thumbs/` (that folder can be deleted); the active cards' previews are made ahead in the background. `…/thumb/<name>` answers the thumb preview.
|
|
10
|
+
|
|
11
|
+
## 2.9.0
|
|
12
|
+
|
|
13
|
+
- **`sk fleet --update` commits and pushes each bump.** Every repo the update moved gets one commit of package.json and its lock alone, by pathspec, through the repo's own hooks: `chore(deps): rvlib-shipkit <range>`, then the plain push of `sk fleet push`. A repo whose manifest held changes before the update, whose package.json moved more than the bump, mid-merge, mid-rebase, on a detached HEAD or nested in another repo is skipped, its bump left in the tree and the command to run printed. A refused hook, a failed push or a branch behind its upstream is a FAIL line, and the command exits 1. `--no-commit` leaves every bump in its tree, as before.
|
|
14
|
+
- **`sk fleet --update` moves a published package's devDependencies.** A repo that declares `release.npm` was only told its bump (« published to npm, never updated by a check »), so comfy-ts stayed behind on every release. Under the fleet, SK005 now moves its devDependencies; a `dependencies` entry stays named, and a plain gate still never writes either.
|
|
15
|
+
- **The review card: a rectangle's note opens beside it, every image starts full, every text box grows.** A rectangle drawn on an image opens its note box right there, under it (over it when it sits low), numbered and focused, to type in at once, Enter or Escape closes it, a click on the rectangle opens it again, ✕ deletes it; the answer column still lists every note. Each image, pair and clip of a choice or a group shows full under its row from the start (⤢ folds one); a sound stays a row. Every text box of the page (the overall word, a view's or a tile's word, a note, the reply, a trailer note) grows with its text, no inner scrollbar and no drag handle: `AutoText` (`hub-app/auto-text.tsx`), which the atelier's prompt now uses too. On a phone the card pane holds the answer under the views (no third « answer » pane), a field's text is 16 px so the page no longer zooms into it, and the views' labels take the whole width. Another card opens at its top. A draft card's history cycles in place over its live frame again (a slider), and its files carry the frame, so a new frame shows. A clip's sound button and volume sit on one line with its time (a sound view's class had taken the same name).
|
|
16
|
+
|
|
1
17
|
## 2.8.0
|
|
2
18
|
|
|
3
19
|
- **A brand's `icon` draws the favicon family at each size.** `icon: canvas(draw)` in `.shipkit/identity/brand.ts` draws `favicon.png` (512), `favicon-32.png`, `favicon-16.png` and `apple-touch-icon.png` (180, flattened on `palette.bg`), each at its own size, `asset.id` naming the file, so a 16 px tab reads a shape made for it, never a shrunk logo. Without one the favicon is the logo master resized, as before.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rvlib-shipkit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.0",
|
|
4
4
|
"funding": "https://github.com/sponsors/rvion",
|
|
5
5
|
"description": "All-in-one repo companion: ci gate (task DAG), auto-discovered health checks, release-contract fulfillness, asks queue, md-wiki tools, asset atelier, live tui",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,7 +40,8 @@
|
|
|
40
40
|
// exists for: package.json moves, package-lock.json does not, and
|
|
41
41
|
// the `npm ci` a deploy runs refuses that pair
|
|
42
42
|
// registry unreachable → loud skip, never red (offline is not a defect)
|
|
43
|
-
// Committing the bump stays with the working agent
|
|
43
|
+
// Committing the bump stays with the working agent: a check never commits
|
|
44
|
+
// (`sk fleet --update` commits the bump it asked for, fleet/commit-bump.ts).
|
|
44
45
|
// Clean passes cache 24h (rule ttl), so the registry is fetched at most
|
|
45
46
|
// daily per repo; skip/WARN/FAIL runs are never cached. The key carries the
|
|
46
47
|
// INSTALLED versions, so a manual `bun add -d rvlib-x@N` busts it: keyed on
|
|
@@ -51,7 +52,7 @@
|
|
|
51
52
|
import { existsSync, readFileSync } from 'fs'
|
|
52
53
|
import { basename, join } from 'path'
|
|
53
54
|
import type { CheckCtx } from '../core/check-ctx.ts'
|
|
54
|
-
import { allowMajor, breakingAdvice, isBreaking, isLinkedInstall, pinFloor } from '../core/update-policy.ts'
|
|
55
|
+
import { allowMajor, breakingAdvice, fleetAsked, isBreaking, isLinkedInstall, pinFloor } from '../core/update-policy.ts'
|
|
55
56
|
import { isRunningCopy, rememberLatest } from '../core/self-update.ts'
|
|
56
57
|
import { rootPublishesNpm } from '../core/repo-facts.ts'
|
|
57
58
|
import { mutateLease, withMutateLease } from '../core/locked-write.ts'
|
|
@@ -153,23 +154,28 @@ export const rvlibVersions = check({
|
|
|
153
154
|
}
|
|
154
155
|
if (stale.length === 0) return
|
|
155
156
|
|
|
156
|
-
const
|
|
157
|
-
const names = stale.map((s) => s.name)
|
|
157
|
+
const driftOf = (xs: typeof stale): string => xs.map((s) => `${s.name}${s.linked ? ' pin' : ''} ${s.installed} → ${s.latest}`).join(', ')
|
|
158
158
|
if (isRefusal(pm)) {
|
|
159
|
-
c.warn(`newer rvlib live: ${
|
|
159
|
+
c.warn(`newer rvlib live: ${driftOf(stale)}, not updating: ${pm.refused}`)
|
|
160
160
|
return
|
|
161
161
|
}
|
|
162
|
-
const cmd = pm.update(names)
|
|
163
162
|
if (process.env['SHIPKIT_FROZEN'] === '1') {
|
|
164
|
-
c.warn(`newer rvlib live: ${
|
|
163
|
+
c.warn(`newer rvlib live: ${driftOf(stale)} (frozen — apply with: ${pm.update(stale.map((s) => s.name)).join(' ')})`)
|
|
165
164
|
return
|
|
166
165
|
}
|
|
167
166
|
// a package published to npm: its package.json is its public
|
|
168
167
|
// contract, so the bump is a release decision, named and never made
|
|
168
|
+
// by a check. `sk fleet --update` is the operator naming it, and a
|
|
169
|
+
// devDependency is read by no one who installs the package: it moves
|
|
170
|
+
let moving = stale
|
|
169
171
|
if (rootPublishesNpm(c.config)) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
+
const held = fleetAsked() ? stale.filter((s) => pkg.dependencies?.[s.name] != null) : stale
|
|
173
|
+
if (held.length > 0) c.warn(`newer rvlib live: ${driftOf(held)} (published to npm, never updated by a check${fleetAsked() ? ' nor the fleet: a dependency its installers get' : ''} — apply with: ${pm.update(held.map((s) => s.name)).join(' ')})`)
|
|
174
|
+
moving = stale.filter((s) => !held.includes(s))
|
|
175
|
+
if (moving.length === 0) return
|
|
172
176
|
}
|
|
177
|
+
const drift = driftOf(moving)
|
|
178
|
+
const cmd = pm.update(moving.map((s) => s.name))
|
|
173
179
|
const dirty = await c.exec(['git', 'status', '--porcelain', '--', ...manifest], { cwd: c.root })
|
|
174
180
|
if (dirty.code !== 0 || dirty.out.trim() !== '') {
|
|
175
181
|
c.warn(`newer rvlib live: ${drift} — self-update deferred (${dirty.code !== 0 ? `git says: ${dirty.out.trim().split('\n')[0] ?? `exit ${dirty.code}`}` : 'package.json/lockfile dirty'}); commit first, then re-run check`)
|
|
@@ -188,7 +194,7 @@ export const rvlibVersions = check({
|
|
|
188
194
|
const up = await c.exec(cmd, { cwd: c.root, timeoutMs: 120_000 })
|
|
189
195
|
// the update may swap a link for the tarball: put every link back,
|
|
190
196
|
// whatever the update did, inside the same lease
|
|
191
|
-
for (const s of
|
|
197
|
+
for (const s of moving) if (s.linked) await c.exec(['bun', 'link', s.name], { cwd: c.root, timeoutMs: 60_000 })
|
|
192
198
|
return up
|
|
193
199
|
})
|
|
194
200
|
if (!leased.ok) {
|
|
@@ -212,7 +218,7 @@ export const rvlibVersions = check({
|
|
|
212
218
|
else c.warn(`self-update failed (${why}) and nothing was written — the registry or the network, not this repo. Retry with: ${cmd.join(' ')}: ${tail}`)
|
|
213
219
|
return
|
|
214
220
|
}
|
|
215
|
-
for (const s of
|
|
221
|
+
for (const s of moving) {
|
|
216
222
|
if (s.linked) {
|
|
217
223
|
const now = pinFloor(readPin(c.root, s.name) ?? '')
|
|
218
224
|
if (!isLinkedInstall(c.root, s.name)) c.fail(`${s.name} pin ${s.installed} → ${now ?? 'unreadable'} but node_modules/${s.name} is no longer linked to its source — run: bun link ${s.name}`)
|
package/src/cli/cmd_Fleet.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// shipkit fleet — every repo on this disk that installs the toolkit, and how
|
|
2
2
|
// far behind each one is. Reports by default. `--update` hands the work to
|
|
3
3
|
// each repo's OWN shipkit, so rule SK005 performs the update with the lease,
|
|
4
|
-
// the dirty-tree guard and the frozen guard it already owns
|
|
4
|
+
// the dirty-tree guard and the frozen guard it already owns, then commits and
|
|
5
|
+
// pushes each repo's bump unless `--no-commit`.
|
|
5
6
|
import { Command, Option } from 'clipanion'
|
|
6
7
|
import { join } from 'path'
|
|
7
8
|
import { npmLatest, resolveLatest, scanFleet, type FleetRepo } from '../fleet/scan-fleet.ts'
|
|
@@ -17,7 +18,8 @@ export class FleetCommand extends Command {
|
|
|
17
18
|
examples: [
|
|
18
19
|
['what is stale out there', 'sk fleet'],
|
|
19
20
|
['filesystem only, no registry', 'sk fleet --offline'],
|
|
20
|
-
['bring every behind repo up
|
|
21
|
+
['bring every behind repo up through its own gate, commit and push each bump', 'sk fleet --update'],
|
|
22
|
+
['update, leave the bumps in the trees', 'sk fleet --update --no-commit'],
|
|
21
23
|
['one repo only', 'sk fleet --update --only my-app'],
|
|
22
24
|
['machine-readable', 'sk fleet --json'],
|
|
23
25
|
],
|
|
@@ -25,6 +27,7 @@ export class FleetCommand extends Command {
|
|
|
25
27
|
|
|
26
28
|
root = Option.String('--root', { required: false, description: 'directory holding the repos (default: the parent of this repo)' })
|
|
27
29
|
update = Option.Boolean('--update', false, { description: "run each behind repo's own `shipkit check`, which is where rule SK005 performs the guarded update" })
|
|
30
|
+
noCommit = Option.Boolean('--no-commit', false, { description: 'with --update: leave each bump in its tree. By default each moved repo commits package.json and its lock alone, by pathspec, as `chore(deps): <dep> <range>`, then pushes; a repo whose manifest was dirty before, whose package.json moved more than the bump, mid-merge, mid-rebase, on a detached HEAD or nested in another repo is skipped with the command to run' })
|
|
28
31
|
only = Option.Array('--only', { description: 'limit to these repo directory names (repeatable)' })
|
|
29
32
|
offline = Option.Boolean('--offline', false, { description: 'skip the registry: report what is installed, never what is current' })
|
|
30
33
|
major = Option.Boolean('--major', false, { description: 'let --update cross a breaking boundary too. Default off: a major (or a 0.x minor, as npm caret reads it) is a porting job, not a bump, and no automatic update path takes one' })
|
|
@@ -58,11 +61,11 @@ export class FleetCommand extends Command {
|
|
|
58
61
|
return 0
|
|
59
62
|
}
|
|
60
63
|
if (!this.update) {
|
|
61
|
-
w(`WARN ${behind.length}/${repos.length} repo(s) behind — rerun with --update, which runs each repo's own gate so SK005 does the write`)
|
|
64
|
+
w(`WARN ${behind.length}/${repos.length} repo(s) behind — rerun with --update, which runs each repo's own gate so SK005 does the write, then commits and pushes each bump`)
|
|
62
65
|
return 0
|
|
63
66
|
}
|
|
64
|
-
await updateFleet(behind, { major: this.major, print: w })
|
|
65
|
-
return 0
|
|
67
|
+
const res = await updateFleet(behind, { major: this.major, commit: !this.noCommit, print: w })
|
|
68
|
+
return res.failed > 0 ? 1 : 0
|
|
66
69
|
}
|
|
67
70
|
|
|
68
71
|
private row(r: FleetRepo): string {
|
package/src/cli/cmd_Review.ts
CHANGED
|
@@ -289,7 +289,8 @@ export class ReviewAddViewCommand extends Command {
|
|
|
289
289
|
if (note !== undefined) v.note = note
|
|
290
290
|
const extra = h.unit?.addView ? await h.unit.addView(v, repoFlags) : {}
|
|
291
291
|
const item = await addView(h.dir, id, v, extra)
|
|
292
|
-
|
|
292
|
+
const { viewLetter } = await import('../review/model.ts')
|
|
293
|
+
h.out(`${id}: view ${viewLetter(item.views.length - 1)} "${label}" added`)
|
|
293
294
|
return 0
|
|
294
295
|
})
|
|
295
296
|
}
|
|
@@ -10,6 +10,12 @@ export const ALLOW_MAJOR_ENV = 'SHIPKIT_ALLOW_MAJOR'
|
|
|
10
10
|
|
|
11
11
|
export const allowMajor = (): boolean => process.env[ALLOW_MAJOR_ENV] === '1'
|
|
12
12
|
|
|
13
|
+
/** set by `shipkit fleet --update` on every repo run it spawns: the operator
|
|
14
|
+
* named the bump, so a published package's devDependencies may move */
|
|
15
|
+
export const FLEET_UPDATE_ENV = 'SHIPKIT_FLEET_UPDATE'
|
|
16
|
+
|
|
17
|
+
export const fleetAsked = (): boolean => process.env[FLEET_UPDATE_ENV] === '1'
|
|
18
|
+
|
|
13
19
|
/** a jump across the boundary npm's caret draws: a changed major, or on a
|
|
14
20
|
* `0.x` package a changed minor (`^0.2.0` means `<0.3.0`). A porting job
|
|
15
21
|
* rather than a bump, so no automatic path takes it. */
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// the commit `fleet --update` makes once a repo moved: package.json and its lock
|
|
2
|
+
// only, by pathspec (never a private index, never `add -A`, never a stash or a
|
|
3
|
+
// branch switch), then the plain push of `sk fleet push`. It commits nothing
|
|
4
|
+
// that is not the bump: a manifest dirty before the update, a package.json diff
|
|
5
|
+
// beyond the moved deps, a merge or rebase under way and a detached HEAD each
|
|
6
|
+
// skip, the files left updated and the line saying what to run.
|
|
7
|
+
import { existsSync, readFileSync } from 'fs'
|
|
8
|
+
import { isAbsolute, join } from 'path'
|
|
9
|
+
import { detectPackageManager, isRefusal, LOCK_FILES } from '../core/package-manager.ts'
|
|
10
|
+
import { git, pushRepo } from './push-fleet.ts'
|
|
11
|
+
|
|
12
|
+
export type BumpResult = { status: 'pushed' | 'skip' | 'fail' | 'none'; line: string }
|
|
13
|
+
|
|
14
|
+
type Change = { path: string; tracked: boolean }
|
|
15
|
+
|
|
16
|
+
/** what the repo held before the update: its manifest (package.json and the
|
|
17
|
+
* locks of the manager it installs with) and which of those files were
|
|
18
|
+
* already changed, someone else's work. Null outside a git repo */
|
|
19
|
+
export type Baseline = { manifest: string[]; dirty: Change[] } | null
|
|
20
|
+
|
|
21
|
+
async function changes(dir: string, manifest: string[]): Promise<Change[] | null> {
|
|
22
|
+
const r = await git(dir, ['status', '--porcelain', '--', ...manifest])
|
|
23
|
+
if (r.code !== 0) return null
|
|
24
|
+
return r.out.split('\n').filter((l) => l !== '').map((l) => ({ path: l.slice(3), tracked: !l.startsWith('??') }))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function bumpBaseline(dir: string): Promise<Baseline> {
|
|
28
|
+
const pm = detectPackageManager(dir)
|
|
29
|
+
const manifest = ['package.json', ...(isRefusal(pm) ? LOCK_FILES : pm.locks)]
|
|
30
|
+
const dirty = await changes(dir, manifest)
|
|
31
|
+
return dirty == null ? null : { manifest, dirty }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const OPERATIONS: Array<[string, string]> = [['MERGE_HEAD', 'a merge'], ['rebase-merge', 'a rebase'], ['rebase-apply', 'a rebase'], ['CHERRY_PICK_HEAD', 'a cherry-pick'], ['REVERT_HEAD', 'a revert']]
|
|
35
|
+
|
|
36
|
+
/** why this repo takes no commit of ours right now, or null. One git call:
|
|
37
|
+
* the dir's place in its work tree (a nested repo is a folder of another
|
|
38
|
+
* repo's history, never committed on), the ref HEAD names (`HEAD` itself
|
|
39
|
+
* when detached), then where each operation in progress leaves its state */
|
|
40
|
+
async function headRefusal(dir: string): Promise<string | null> {
|
|
41
|
+
const r = await git(dir, ['rev-parse', '--show-prefix', '--symbolic-full-name', 'HEAD', ...OPERATIONS.flatMap(([p]) => ['--git-path', p])])
|
|
42
|
+
if (r.code !== 0) return `git rev-parse failed: ${r.err.trim().split('\n')[0]}`
|
|
43
|
+
const [prefix, ref, ...paths] = r.out.split('\n').map((l) => l.trim())
|
|
44
|
+
if (prefix != null && prefix !== '') return `it is the folder ${prefix} of a larger repo, whose history is not its own`
|
|
45
|
+
for (const [i, [, label]] of OPERATIONS.entries()) {
|
|
46
|
+
const p = paths[i]
|
|
47
|
+
if (p != null && p !== '' && existsSync(isAbsolute(p) ? p : join(dir, p))) return `${label} is under way`
|
|
48
|
+
}
|
|
49
|
+
return ref === 'HEAD' ? 'HEAD is detached' : null
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** a value with its object keys sorted, so key order is never a change */
|
|
53
|
+
const canonical = (v: unknown): unknown =>
|
|
54
|
+
Array.isArray(v) ? v.map(canonical) : v != null && typeof v === 'object' ? Object.fromEntries(Object.keys(v).sort().map((k) => [k, canonical((v as Record<string, unknown>)[k])])) : v
|
|
55
|
+
|
|
56
|
+
const DEP_FIELDS = ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']
|
|
57
|
+
|
|
58
|
+
/** every field of package.json the update changed besides the moved deps,
|
|
59
|
+
* as `devDependencies.left-pad` or `scripts` */
|
|
60
|
+
export function extraChanges(before: Record<string, unknown>, after: Record<string, unknown>, moved: string[]): string[] {
|
|
61
|
+
const out: string[] = []
|
|
62
|
+
for (const key of new Set([...Object.keys(before), ...Object.keys(after)])) {
|
|
63
|
+
const [b, a] = [before[key], after[key]]
|
|
64
|
+
if (DEP_FIELDS.includes(key) && (b == null || typeof b === 'object') && (a == null || typeof a === 'object')) {
|
|
65
|
+
const [bs, as] = [(b ?? {}) as Record<string, unknown>, (a ?? {}) as Record<string, unknown>]
|
|
66
|
+
for (const dep of new Set([...Object.keys(bs), ...Object.keys(as)])) {
|
|
67
|
+
if (moved.includes(dep) && (key === 'dependencies' || key === 'devDependencies')) continue
|
|
68
|
+
if (bs[dep] !== as[dep]) out.push(`${key}.${dep}`)
|
|
69
|
+
}
|
|
70
|
+
continue
|
|
71
|
+
}
|
|
72
|
+
if (JSON.stringify(canonical(b)) !== JSON.stringify(canonical(a))) out.push(key)
|
|
73
|
+
}
|
|
74
|
+
return out
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const lastLine = (text: string): string | null => text.split('\n').map((l) => l.trim()).filter((l) => l !== '' && !l.startsWith('hint:')).at(-1) ?? null
|
|
78
|
+
|
|
79
|
+
/** commit and push the bump of `moved` in `dir`, against the baseline read
|
|
80
|
+
* before the update ran */
|
|
81
|
+
export async function commitBump(repo: { name: string; dir: string }, moved: string[], base: Baseline): Promise<BumpResult> {
|
|
82
|
+
const { name, dir } = repo
|
|
83
|
+
const skip = (why: string, then: string): BumpResult => ({ status: 'skip', line: `skip: ${name}: ${why}, so the bump is not committed. It stays in the tree: cd ${dir} && ${then}` })
|
|
84
|
+
if (base == null) return skip('git status failed before the update', 'git status')
|
|
85
|
+
if (base.dirty.length > 0) {
|
|
86
|
+
const held = base.dirty.map((c) => c.path)
|
|
87
|
+
return skip(`${held.join(', ')} held changes before the update`, `git diff -- ${held.join(' ')}, then commit the bump with them by hand`)
|
|
88
|
+
}
|
|
89
|
+
const refused = await headRefusal(dir)
|
|
90
|
+
if (refused != null) return skip(refused, 'commit the bump by hand once it can take one')
|
|
91
|
+
const after = await changes(dir, base.manifest)
|
|
92
|
+
if (after == null) return { status: 'fail', line: `FAIL: ${name}: git status failed after the update: cd ${dir} && git status` }
|
|
93
|
+
const paths = after.filter((c) => c.tracked).map((c) => c.path).sort((a, b) => Number(b === 'package.json') - Number(a === 'package.json'))
|
|
94
|
+
if (paths.length === 0) return { status: 'none', line: `ok: ${name}: package.json and its lock unchanged, nothing to commit` }
|
|
95
|
+
|
|
96
|
+
const head = await git(dir, ['show', 'HEAD:./package.json'])
|
|
97
|
+
let was: Record<string, unknown>
|
|
98
|
+
let now: Record<string, unknown>
|
|
99
|
+
try {
|
|
100
|
+
was = JSON.parse(head.out) as Record<string, unknown>
|
|
101
|
+
now = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')) as Record<string, unknown>
|
|
102
|
+
} catch {
|
|
103
|
+
return skip('package.json is unreadable in HEAD or on disk', 'git diff -- package.json')
|
|
104
|
+
}
|
|
105
|
+
const extra = extraChanges(was, now, moved)
|
|
106
|
+
if (extra.length > 0) return skip(`the update changed ${extra.join(', ')} in package.json too`, 'git diff -- package.json')
|
|
107
|
+
|
|
108
|
+
const deps = now as { dependencies?: Record<string, string>; devDependencies?: Record<string, string> }
|
|
109
|
+
const message = `chore(deps): ${[...moved].sort().map((d) => `${d} ${deps.dependencies?.[d] ?? deps.devDependencies?.[d] ?? '?'}`).join(', ')}`
|
|
110
|
+
const by = `git commit -m '${message}' -- ${paths.join(' ')}`
|
|
111
|
+
|
|
112
|
+
// its first line names the commit: `[main 1a2b3c4] chore(deps): …`
|
|
113
|
+
const done = await git(dir, ['commit', '-m', message, '--', ...paths], 120_000)
|
|
114
|
+
if (done.code !== 0) return { status: 'fail', line: `FAIL: ${name}: the commit was refused: ${lastLine(`${done.out}\n${done.err}`) ?? `git commit exited ${done.code}`}. The bump stays in the tree: cd ${dir} && ${by}` }
|
|
115
|
+
const sha = done.out.match(/^\[\S+ ([0-9a-f]+)\]/m)?.[1] ?? 'HEAD'
|
|
116
|
+
const push = await pushRepo({ name, path: dir })
|
|
117
|
+
const committed = `committed ${sha} ${message}`
|
|
118
|
+
if (push.ok && push.action !== 'none') return { status: 'pushed', line: `ok: ${name}: ${committed}, pushed (${push.branch})` }
|
|
119
|
+
// never a force: a branch behind its upstream waits for a pull, and the
|
|
120
|
+
// operator is told as loudly as a failed push
|
|
121
|
+
if (push.action === 'skip') return { status: 'fail', line: `FAIL: ${name}: ${committed}, not pushed: ${push.why}` }
|
|
122
|
+
return { status: 'fail', line: `FAIL: ${name}: ${committed}, the push failed: ${push.line.replace(/^FAIL: [^:]+: /, '')}. Run: cd ${dir} && git push` }
|
|
123
|
+
}
|
package/src/fleet/push-fleet.ts
CHANGED
|
@@ -15,9 +15,12 @@ export type PushResult = PushPlan & { ok: boolean; line: string }
|
|
|
15
15
|
const PARALLEL = 4
|
|
16
16
|
const PUSH_MS = 60_000
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
/** git in another repo: a push that would ask for a password fails instead of
|
|
19
|
+
* hanging, and a GIT_DIR or GIT_INDEX_FILE this process inherited (a hook) is
|
|
20
|
+
* never carried into it */
|
|
21
|
+
export async function git(cwd: string, args: string[], ms = 15_000): Promise<{ code: number; out: string; err: string }> {
|
|
22
|
+
const env = Object.fromEntries(Object.entries(process.env).filter(([k]) => k !== 'GIT_DIR' && k !== 'GIT_INDEX_FILE' && k !== 'GIT_WORK_TREE'))
|
|
23
|
+
const p = Bun.spawn(['git', ...args], { cwd, stdout: 'pipe', stderr: 'pipe', env: { ...env, GIT_TERMINAL_PROMPT: '0' } })
|
|
21
24
|
const timer = setTimeout(() => p.kill(), ms)
|
|
22
25
|
const [out, err, code] = await Promise.all([new Response(p.stdout).text(), new Response(p.stderr).text(), p.exited])
|
|
23
26
|
clearTimeout(timer)
|
|
@@ -63,6 +66,9 @@ async function pushOne(p: PushPlan): Promise<PushResult> {
|
|
|
63
66
|
return { ...p, ok: false, line: `FAIL: ${p.name}: git ${args.join(' ')}: ${why}` }
|
|
64
67
|
}
|
|
65
68
|
|
|
69
|
+
/** one repo planned and pushed: what `fleet --update` runs after its commit */
|
|
70
|
+
export const pushRepo = async (repo: { name: string; path: string }): Promise<PushResult> => pushOne(await pushPlan(repo))
|
|
71
|
+
|
|
66
72
|
/** every repo planned, the ones that need it pushed, a few at a time; `dry`
|
|
67
73
|
* plans only. Results come back in the repos' order */
|
|
68
74
|
export async function pushFleet(repos: { name: string; path: string }[], o: { dry?: boolean } = {}): Promise<PushResult[]> {
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
// `shipkit fleet --update`: hand each behind repo its own update. The update
|
|
2
2
|
// is NOT performed here. Each repo runs its own binary, which is the only copy
|
|
3
3
|
// whose SK005 matches the rules that repo is pinned to, and the only one
|
|
4
|
-
// holding that repo's mutate lease.
|
|
4
|
+
// holding that repo's mutate lease. What it does write is the commit of the
|
|
5
|
+
// bump each repo made, and its push (commit-bump.ts).
|
|
5
6
|
import { existsSync } from 'fs'
|
|
6
7
|
import { join } from 'path'
|
|
7
8
|
import { spawnWithTimeout } from '../core/spawn-timeout.ts'
|
|
8
9
|
import { detectPackageManager, isRefusal } from '../core/package-manager.ts'
|
|
9
|
-
import { ALLOW_MAJOR_ENV, breakingAdvice } from '../core/update-policy.ts'
|
|
10
|
+
import { ALLOW_MAJOR_ENV, breakingAdvice, FLEET_UPDATE_ENV } from '../core/update-policy.ts'
|
|
10
11
|
import { isBehind, judgedVersion, updateRefusal, type FleetRepo } from './scan-fleet.ts'
|
|
12
|
+
import { bumpBaseline, commitBump } from './commit-bump.ts'
|
|
11
13
|
|
|
12
14
|
|
|
13
15
|
export const short = (name: string): string => name.replace(/^rvlib-/, '')
|
|
@@ -23,26 +25,36 @@ export type FleetUpdateOpts = {
|
|
|
23
25
|
/** cross a breaking boundary too (`--major`) */
|
|
24
26
|
major: boolean
|
|
25
27
|
print: (line: string) => void
|
|
28
|
+
/** commit and push each repo's bump (fleet/commit-bump.ts); `--no-commit` leaves it in the tree */
|
|
29
|
+
commit?: boolean
|
|
30
|
+
/** runs the repo's own binary (tests pass a fake) */
|
|
31
|
+
spawn?: typeof spawnWithTimeout
|
|
26
32
|
/** per repo run (default 10 minutes: a fresh health pass probes the world) */
|
|
27
33
|
timeoutMs?: number
|
|
28
34
|
}
|
|
29
35
|
|
|
30
|
-
/** returns how many repos did not update. A repo whose gate refused (dirty
|
|
31
|
-
* tree, frozen, a lease held elsewhere) is a REPORT, not a failure of the
|
|
32
|
-
* command: SK005 defers on purpose */
|
|
33
36
|
/** the env of one repo's guarded run. It stays in its own process
|
|
34
37
|
* (SHIPKIT_NO_HOME): a check the home daemon answers never sees this env, so
|
|
35
38
|
* --major would be dropped on the way */
|
|
36
39
|
export function fleetEnv(base: Record<string, string | undefined>, major: boolean): Record<string, string> {
|
|
37
40
|
const env: Record<string, string> = Object.fromEntries(Object.entries(base).filter((e): e is [string, string] => e[1] != null && e[0] !== 'SHIPKIT_SELF_UPDATED' && e[0] !== ALLOW_MAJOR_ENV))
|
|
38
41
|
env['SHIPKIT_NO_HOME'] = '1'
|
|
42
|
+
env[FLEET_UPDATE_ENV] = '1'
|
|
39
43
|
if (major) env[ALLOW_MAJOR_ENV] = '1'
|
|
40
44
|
return env
|
|
41
45
|
}
|
|
42
46
|
|
|
43
|
-
|
|
47
|
+
/** `notMoved`: repos that did not update. A repo whose gate refused (dirty
|
|
48
|
+
* tree, frozen, a lease held elsewhere) is a REPORT, not a failure of the
|
|
49
|
+
* command: SK005 defers on purpose. `failed`: a commit a hook refused or a
|
|
50
|
+
* push that failed, the lines the operator must act on */
|
|
51
|
+
export type FleetUpdateResult = { notMoved: number; committed: number; failed: number }
|
|
52
|
+
|
|
53
|
+
export async function updateFleet(behind: FleetRepo[], o: FleetUpdateOpts): Promise<FleetUpdateResult> {
|
|
44
54
|
const w = o.print
|
|
45
55
|
let failed = 0
|
|
56
|
+
let committed = 0
|
|
57
|
+
let broke = 0
|
|
46
58
|
for (const r of behind) {
|
|
47
59
|
// the same policy SK005 applies inside the repo: a breaking jump is reported,
|
|
48
60
|
// never taken, and a safe jump beside it still moves
|
|
@@ -71,8 +83,9 @@ export async function updateFleet(behind: FleetRepo[], o: FleetUpdateOpts): Prom
|
|
|
71
83
|
// way around it: SK005 has no autofix, so the binary refuses the id.
|
|
72
84
|
// The re-exec guard is dropped so the repo's own startup self-update
|
|
73
85
|
// can still fire, and --major travels as the one env the policy reads.
|
|
86
|
+
const before = o.commit === true ? await bumpBaseline(r.dir) : null
|
|
74
87
|
const env = fleetEnv(process.env, o.major === true)
|
|
75
|
-
const res = await spawnWithTimeout(['bun', cli, 'check', '--fresh'], { cwd: r.dir, env, timeoutMs: o.timeoutMs ?? 600_000 })
|
|
88
|
+
const res = await (o.spawn ?? spawnWithTimeout)(['bun', cli, 'check', '--fresh'], { cwd: r.dir, env, timeoutMs: o.timeoutMs ?? 600_000 })
|
|
76
89
|
// judge by what node_modules carries now (the pin, for a linked dep),
|
|
77
90
|
// never by the exit code or a printed line: the code covers every rule
|
|
78
91
|
// in that repo, and the line format belongs to whatever version that repo runs
|
|
@@ -82,13 +95,29 @@ export async function updateFleet(behind: FleetRepo[], o: FleetUpdateOpts): Prom
|
|
|
82
95
|
})
|
|
83
96
|
if (stuck.length === 0) {
|
|
84
97
|
w(`ok: ${r.name} — ${wanted.map((d) => `${short(d.name)}${d.linkedInstall ? ' pin' : ''} ${d.at} → ${judgedVersion(r.dir, d.name)}`).join(', ')}`)
|
|
98
|
+
if (o.commit === true) {
|
|
99
|
+
const c = await commitBump({ name: r.name, dir: r.dir }, wanted.map((d) => d.name), before)
|
|
100
|
+
w(c.line)
|
|
101
|
+
if (c.status === 'pushed') committed++
|
|
102
|
+
if (c.status === 'fail') broke++
|
|
103
|
+
}
|
|
85
104
|
continue
|
|
86
105
|
}
|
|
87
106
|
failed++
|
|
107
|
+
// what did move is committed: left in the tree, the next run reads it
|
|
108
|
+
// as someone else's work
|
|
109
|
+
const moved = wanted.filter((d) => !stuck.includes(d))
|
|
110
|
+
if (o.commit === true && moved.length > 0) {
|
|
111
|
+
const c = await commitBump({ name: r.name, dir: r.dir }, moved.map((d) => d.name), before)
|
|
112
|
+
w(c.line)
|
|
113
|
+
if (c.status === 'pushed') committed++
|
|
114
|
+
if (c.status === 'fail') broke++
|
|
115
|
+
}
|
|
88
116
|
const said = res.out.split('\n').find((l) => /\brvlib-/.test(l) && (l.startsWith('WARN') || l.startsWith('FAIL')))
|
|
89
117
|
w(`WARN ${r.name} did not move ${stuck.map((d) => short(d.name)).join(', ')} — ${said ?? `check exited ${res.code}${res.timedOut ? ', timed out' : ''} with no rvlib line`}`)
|
|
90
118
|
w(` fix: cd ${r.dir} && ${manualUpdate(r)}`)
|
|
91
119
|
}
|
|
92
|
-
|
|
93
|
-
|
|
120
|
+
const commits = o.commit === true ? `, ${committed} committed${broke > 0 ? `, ${broke} FAILED to commit or push` : ''}` : ''
|
|
121
|
+
w(failed === 0 ? `ok: ${behind.length} repo(s) updated through their own gate${commits}` : `WARN ${failed}/${behind.length} repo(s) did not update — each line above says why${commits}`)
|
|
122
|
+
return { notMoved: failed, committed, failed: broke }
|
|
94
123
|
}
|