rvlib-shipkit 2.12.0 → 2.13.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 +48 -13
- package/README.md +1 -1
- package/package.json +4 -2
- package/src/agent-time/store.ts +2 -2
- package/src/check.ts +1 -1
- package/src/checks/SK001-package-json-shape.check.ts +4 -0
- package/src/checks/SK003-claude-md-shape.check.ts +1 -1
- package/src/checks/SK004-gitignore-policy.check.ts +27 -2
- package/src/checks/SK005-rvlib-versions.check.ts +1 -1
- package/src/checks/SK008-reviewer-agent.check.ts +2 -2
- package/src/checks/SK012-config-barrel-import.check.ts +1 -1
- package/src/checks/SK015-nested-repo.check.ts +1 -1
- package/src/checks/SK035-public-clean.check.ts +46 -0
- package/src/checks/SK036-draft-media-size.check.ts +28 -0
- package/src/cli/cmd_Backup.ts +152 -0
- package/src/cli/cmd_Ci.ts +8 -11
- package/src/cli/cmd_Drill.ts +145 -0
- package/src/cli/cmd_Home.ts +50 -3
- package/src/cli/cmd_Media.ts +7 -5
- package/src/cli/cmd_Review.ts +4 -2
- package/src/cli/cmd_Shot.ts +5 -2
- package/src/cli/cmd_Smoke.ts +4 -1
- package/src/cli/cmd_Social.ts +226 -0
- package/src/cli/cmd_Start.ts +1 -1
- package/src/cli/cmd_Time.ts +1 -1
- package/src/cli/cmd_Trailer.ts +5 -2
- package/src/cli/cmd_Veille.ts +173 -0
- package/src/cli/family-pages.ts +3 -0
- package/src/cli/registry.ts +13 -2
- package/src/cli.ts +5 -2
- package/src/collections/actions.ts +1 -49
- package/src/collections/checks.ts +2 -1
- package/src/collections/collection-types.ts +11 -2
- package/src/collections/providers.ts +4 -4
- package/src/collections/review.ts +2 -1
- package/src/collections/tests.ts +19 -8
- package/src/contracts/apply-contracts.ts +1 -3
- package/src/contracts/contract-manifests.ts +2 -3
- package/src/contracts/contract-types.ts +0 -1
- package/src/contracts/contracts-engine.ts +0 -3
- package/src/core/app-icon.ts +9 -3
- package/src/core/bun-builtins.ts +2 -2
- package/src/core/discover-checks.ts +37 -5
- package/src/core/fix-scope.ts +4 -2
- package/src/core/floor-resolve.ts +68 -48
- package/src/core/floor.ts +9 -0
- package/src/core/git-root.ts +24 -0
- package/src/core/last-good.ts +3 -1
- package/src/core/layout.ts +8 -0
- package/src/core/log-stamp.ts +36 -0
- package/src/core/loop-watch.ts +93 -0
- package/src/core/machine-link.ts +134 -0
- package/src/core/memory-watch.ts +41 -0
- package/src/core/one-way-in-policy.ts +27 -19
- package/src/core/run-ci.ts +6 -8
- package/src/core/run-fixers.ts +9 -9
- package/src/core/slots.ts +21 -0
- package/src/core/tree-rev.ts +60 -0
- package/src/core/unit-files.ts +42 -0
- package/src/drill/render.ts +140 -0
- package/src/drill/run.ts +269 -0
- package/src/fleet/scan-fleet.ts +6 -5
- package/src/home/daemon-jobs.ts +201 -0
- package/src/home/global-context.ts +34 -1
- package/src/home/home-routes.ts +22 -15
- package/src/home/hubs.ts +10 -3
- package/src/home/inbox-shape.ts +53 -4
- package/src/home/inbox.ts +16 -1
- package/src/home/lib-watch.ts +10 -3
- package/src/home/machine-stores.ts +15 -29
- package/src/home/run-daemon.ts +15 -18
- package/src/home/run-pm.ts +2 -0
- package/src/home/serve-daemon.ts +4 -3
- package/src/home/serve-web.ts +104 -1
- package/src/hooks/commit-message.ts +28 -19
- package/src/hooks/leak-guard.ts +10 -3
- package/src/hooks/run-hooks.ts +2 -6
- package/src/identities/identities.ts +334 -0
- package/src/identities/machine-route.ts +126 -0
- package/src/identities/machine.ts +62 -0
- package/src/init-repo.ts +1 -1
- package/src/ledger/check-stats.ts +10 -9
- package/src/ledger/gate-checks.ts +32 -1
- package/src/ledger/record-kept.ts +112 -0
- package/src/ledger/repo-view.ts +10 -0
- package/src/ledger/run-log.ts +17 -12
- package/src/ledger/run-timeline.ts +8 -4
- package/src/ledger/store.ts +7 -0
- package/src/ledger/suite-log.ts +17 -13
- package/src/media-kinds.ts +2 -1
- package/src/media-store/backup/daemon.ts +73 -0
- package/src/media-store/backup/keys.ts +25 -0
- package/src/media-store/backup/manifest.ts +193 -0
- package/src/media-store/backup/restore.ts +192 -0
- package/src/media-store/backup/run.ts +278 -0
- package/src/media-store/backup/secret.ts +86 -0
- package/src/media-store/backup/snapshot.ts +64 -0
- package/src/media-store/backup/sources.ts +199 -0
- package/src/media-store/daemon.ts +56 -70
- package/src/media-store/put.ts +4 -2
- package/src/media-store/space.ts +23 -4
- package/src/pages/forward.ts +35 -0
- package/src/pages/frame-client.ts +118 -0
- package/src/pages/routes.ts +29 -0
- package/src/pages/unit.ts +92 -0
- package/src/plan/planner.ts +12 -0
- package/src/plan/repo-source.ts +19 -5
- package/src/reflect/transcript.ts +35 -10
- package/src/release/public-clean.ts +301 -0
- package/src/release/published-here.ts +22 -0
- package/src/release/run-bump.ts +2 -1
- package/src/release/run-release.ts +4 -1
- package/src/repo-config.ts +53 -2
- package/src/review/http.ts +16 -2
- package/src/review/model.ts +15 -4
- package/src/review/notes.ts +77 -0
- package/src/review/project.ts +6 -38
- package/src/review/routes.ts +4 -12
- package/src/review/store.ts +41 -1
- package/src/review/trailer-media.ts +7 -4
- package/src/review/trailer-shots.ts +21 -4
- package/src/review/unit.ts +1 -1
- package/src/scaffold/files/agent-handoff.md +3 -0
- package/src/scaffold/files/agent-index.md +4 -12
- package/src/scaffold/project-scaffold.ts +5 -4
- package/src/serve/embed.ts +1 -1
- package/src/serve/hub-app/col-card.tsx +3 -17
- package/src/serve/hub-app/col-tables-view.tsx +2 -1
- package/src/serve/hub-app/cols-svc.ts +0 -13
- package/src/serve/hub-app/dock-st.ts +4 -2
- package/src/serve/hub-app/dock-view.tsx +2 -0
- package/src/serve/hub-app/frames-st.ts +35 -0
- package/src/serve/hub-app/hash-route.ts +64 -1
- package/src/serve/hub-app/home-st.ts +31 -7
- package/src/serve/hub-app/home-strip.css +9 -1
- package/src/serve/hub-app/home-strip.tsx +7 -6
- package/src/serve/hub-app/home.html +5 -0
- package/src/serve/hub-app/hub-app.tsx +49 -5
- package/src/serve/hub-app/hub.css +29 -11
- package/src/serve/hub-app/icons.tsx +16 -1
- package/src/serve/hub-app/identities-st.ts +210 -0
- package/src/serve/hub-app/identities-view.tsx +352 -0
- package/src/serve/hub-app/identities.css +48 -0
- package/src/serve/hub-app/identity-address.ts +52 -0
- package/src/serve/hub-app/inbox-st.ts +59 -6
- package/src/serve/hub-app/inbox-view.tsx +48 -6
- package/src/serve/hub-app/inbox.css +12 -1
- package/src/serve/hub-app/index.html +3 -0
- package/src/serve/hub-app/keys.ts +10 -2
- package/src/serve/hub-app/list-walk.ts +89 -0
- package/src/serve/hub-app/machine-st.ts +12 -0
- package/src/serve/hub-app/media-view.tsx +2 -1
- package/src/serve/hub-app/pages-frames.tsx +134 -0
- package/src/serve/hub-app/pages-svc.ts +111 -0
- package/src/serve/hub-app/palette-st.ts +18 -3
- package/src/serve/hub-app/palette-view.tsx +9 -2
- package/src/serve/hub-app/planned-view.tsx +2 -1
- package/src/serve/hub-app/project-list.css +18 -14
- package/src/serve/hub-app/project-list.tsx +88 -49
- package/src/serve/hub-app/projects-svc.ts +33 -3
- package/src/serve/hub-app/repo-sections.ts +19 -2
- package/src/serve/hub-app/repo-st.ts +75 -19
- package/src/serve/hub-app/review/review-cells.tsx +3 -3
- package/src/serve/hub-app/review/review-kit.ts +30 -7
- package/src/serve/hub-app/review/review-page.tsx +1 -1
- package/src/serve/hub-app/review/review-st.ts +19 -8
- package/src/serve/hub-app/review/review-thread.tsx +11 -9
- package/src/serve/hub-app/review/review-views.tsx +84 -19
- package/src/serve/hub-app/review/thread-st.ts +1 -10
- package/src/serve/hub-app/review/trailer-page.tsx +2 -1
- package/src/serve/hub-app/review.css +17 -8
- package/src/serve/hub-app/site/site-part.tsx +173 -0
- package/src/serve/hub-app/site/site-st.ts +157 -0
- package/src/serve/hub-app/site.css +35 -0
- package/src/serve/hub-app/social/calendar.tsx +182 -0
- package/src/serve/hub-app/social/comms-page.tsx +306 -0
- package/src/serve/hub-app/social/kit.tsx +244 -0
- package/src/serve/hub-app/social/post-card.tsx +456 -0
- package/src/serve/hub-app/social/problems.tsx +60 -0
- package/src/serve/hub-app/social/social-model.ts +154 -0
- package/src/serve/hub-app/social/social-page.tsx +674 -0
- package/src/serve/hub-app/social/social-st.ts +986 -0
- package/src/serve/hub-app/social.css +289 -0
- package/src/serve/hub-app/stores/stores-page.tsx +311 -0
- package/src/serve/hub-app/stores/stores-st.ts +286 -0
- package/src/serve/hub-app/stores.css +54 -0
- package/src/serve/hub-app/timeline-geometry.ts +1 -1
- package/src/serve/hub-app/timeline-view.tsx +3 -2
- package/src/serve/hub-app/tree-build.ts +6 -0
- package/src/serve/hub-app/tree-row.tsx +27 -4
- package/src/serve/hub-app/tree-svc.ts +18 -49
- package/src/serve/hub-app/veille/veille-page.tsx +514 -0
- package/src/serve/hub-app/veille/veille-st.ts +443 -0
- package/src/serve/hub-app/veille.css +84 -0
- package/src/serve/hub-runtime.ts +14 -9
- package/src/serve/project-gutter-route.ts +44 -12
- package/src/serve/run-lanes.ts +7 -4
- package/src/serve/same-origin.ts +1 -1
- package/src/serve/serve-hub.ts +20 -12
- package/src/serve/tracked-watch.ts +24 -3
- package/src/serve/warm-cell.ts +5 -1
- package/src/shipkit-files.ts +15 -4
- package/src/shipkit.ts +0 -1
- package/src/shot/box.ts +162 -0
- package/src/shot/browser-slot.ts +62 -0
- package/src/shot/client.ts +43 -7
- package/src/shot/clip-encoder.ts +93 -12
- package/src/shot/film-box.ts +188 -0
- package/src/shot/shooter.ts +50 -15
- package/src/shot/shot-ask.ts +10 -2
- package/src/shot/stepped-clip.ts +5 -4
- package/src/site/desk.ts +242 -0
- package/src/site/routes.ts +66 -0
- package/src/site/unit.ts +62 -0
- package/src/social/brands.ts +22 -0
- package/src/social/compose.ts +97 -0
- package/src/social/desk-index.ts +123 -0
- package/src/social/desk-wire.ts +64 -0
- package/src/social/drafts.ts +183 -0
- package/src/social/house.ts +24 -0
- package/src/social/load.ts +319 -0
- package/src/social/md.ts +70 -0
- package/src/social/media-facts.ts +53 -0
- package/src/social/media-kind.ts +189 -0
- package/src/social/media-limit.ts +42 -0
- package/src/social/media-of.ts +30 -0
- package/src/social/migrate.ts +123 -0
- package/src/social/open.ts +17 -0
- package/src/social/post-url.ts +158 -0
- package/src/social/presence.ts +332 -0
- package/src/social/public-read.ts +53 -0
- package/src/social/publish/bluesky.ts +168 -0
- package/src/social/publish/discord.ts +76 -0
- package/src/social/publish/index.ts +24 -0
- package/src/social/publish/secret.ts +13 -0
- package/src/social/push.ts +31 -0
- package/src/social/richtext.ts +37 -0
- package/src/social/routes.ts +180 -0
- package/src/social/stats.ts +134 -0
- package/src/social/text.ts +267 -0
- package/src/social/tracker-route.ts +39 -0
- package/src/social/tracker.ts +255 -0
- package/src/social/unit.ts +53 -0
- package/src/social/writes.ts +130 -0
- package/src/start-repo.ts +14 -9
- package/src/stores/collection.ts +27 -0
- package/src/stores/desk.ts +336 -0
- package/src/stores/model.ts +187 -0
- package/src/stores/routes.ts +126 -0
- package/src/stores/unit.ts +57 -0
- package/src/suite/calibrate.ts +127 -0
- package/src/suite/core-counters.ts +91 -0
- package/src/suite/judge-suites.ts +94 -34
- package/src/suite/suite-cli.ts +44 -10
- package/src/suite/suite-cpu-preload.ts +34 -9
- package/src/trailer/adapter.ts +4 -0
- package/src/trailer/build.ts +42 -11
- package/src/trailer/ffmpeg.ts +11 -0
- package/src/trailer/footage.ts +30 -13
- package/src/trailer/grammar.ts +18 -2
- package/src/trailer/graph.ts +28 -6
- package/src/trailer/passage.ts +17 -5
- package/src/trailer/plan.ts +74 -3
- package/src/trailer/stitch.ts +67 -26
- package/src/trailer/url.ts +1 -1
- package/src/trailer/versions.ts +24 -0
- package/src/ts/gate-typecheck.ts +32 -0
- package/src/ts/typecheck-cli.ts +9 -11
- package/src/tui/tui-app.tsx +0 -1
- package/src/veille/asks.ts +155 -0
- package/src/veille/auto.ts +31 -0
- package/src/veille/batch.ts +27 -0
- package/src/veille/chrome.ts +127 -0
- package/src/veille/collection.ts +28 -0
- package/src/veille/desk.ts +242 -0
- package/src/veille/identity.ts +80 -0
- package/src/veille/import.ts +68 -0
- package/src/veille/log.ts +183 -0
- package/src/veille/platforms.ts +118 -0
- package/src/veille/reads.ts +66 -0
- package/src/veille/replied.ts +110 -0
- package/src/veille/routes.ts +185 -0
- package/src/veille/service.ts +81 -0
- package/src/veille/watch.ts +116 -0
- package/src/veille/worth.ts +46 -0
- package/src/wiki/scan-md.ts +18 -0
- package/src/collections/posts.ts +0 -142
- package/src/contracts/manifests/social.contract.ts +0 -20
- package/src/scaffold/files/agent-coding.md +0 -35
- package/src/ts/typecheck-cache.ts +0 -11
package/src/core/layout.ts
CHANGED
|
@@ -25,10 +25,18 @@ export const LAYOUT = {
|
|
|
25
25
|
// plans, arc boards and lane files: live state a crashed session resumes
|
|
26
26
|
// from. Tracked in a private repo only, since a board quotes the owner
|
|
27
27
|
plans: sk('plans'),
|
|
28
|
+
// the house repo's identities, who speaks: one folder each, its accounts; the house repo tracks it with its own
|
|
29
|
+
// gitignore line (wiki build/shipkit/social.md)
|
|
30
|
+
identities: sk('identities'),
|
|
28
31
|
// local: drafts, private notes, venue listings until they go live
|
|
29
32
|
private: sk('private'),
|
|
30
33
|
reflections: sk('reflections'),
|
|
34
|
+
// the social folder (contract v3): one folder a draft, the week's rhythm. The SK004 block re-includes it in a
|
|
35
|
+
// private repo only, like plans (wiki build/shipkit/social.md)
|
|
31
36
|
social: sk('social'),
|
|
37
|
+
// local: the facts (sha, size, type) of every draft media, so a file the disk let go keeps its key in the media
|
|
38
|
+
// store (wiki build/shipkit/social.md, Media)
|
|
39
|
+
socialMedia: sk('social-media.json'),
|
|
32
40
|
journal: sk('journal'),
|
|
33
41
|
domain: sk('domain'),
|
|
34
42
|
itch: sk('itch'),
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// every line a long running role (pm, the daemon, the web) writes to its log starts with its local time: the log
|
|
2
|
+
// file has no other clock, and a restart or a stall can only be dated from it. Only the role's own entry stamps,
|
|
3
|
+
// so a test that runs a role in process keeps its console as it is
|
|
4
|
+
import { format } from 'node:util'
|
|
5
|
+
|
|
6
|
+
const pad = (n: number, w = 2): string => String(n).padStart(w, '0')
|
|
7
|
+
|
|
8
|
+
/** `2026-11-04 17:15:03.120` */
|
|
9
|
+
export const stampOf = (d: Date): string =>
|
|
10
|
+
`${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}.${pad(d.getMilliseconds(), 3)}`
|
|
11
|
+
|
|
12
|
+
/** each line of `text` behind the stamp of `at` */
|
|
13
|
+
export const stampLines = (text: string, at: Date): string => {
|
|
14
|
+
const s = stampOf(at)
|
|
15
|
+
return text.split('\n').map((l) => `${s} ${l}`).join('\n')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type Io = { print: (l: string) => void; printErr: (l: string) => void }
|
|
19
|
+
|
|
20
|
+
/** the role's io with every line stamped */
|
|
21
|
+
export const stampedIo = (io: Io, now: () => Date = () => new Date()): Io => ({
|
|
22
|
+
print: (l) => io.print(stampLines(l, now())),
|
|
23
|
+
printErr: (l) => io.printErr(stampLines(l, now())),
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
let stamping = false
|
|
27
|
+
|
|
28
|
+
/** console.log, info, warn and error stamp each line from now on, in this process */
|
|
29
|
+
export function stampConsole(now: () => Date = () => new Date()): void {
|
|
30
|
+
if (stamping) return
|
|
31
|
+
stamping = true
|
|
32
|
+
for (const k of ['log', 'info', 'warn', 'error'] as const) {
|
|
33
|
+
const raw = console[k].bind(console)
|
|
34
|
+
console[k] = (...a: unknown[]) => raw(stampLines(format(...a), now()))
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// the daemon's one loop answers every page and runs every background job, so a job that holds the loop holds every
|
|
2
|
+
// page. Work names itself as a span (a request, a tick, a backup run); a beat that comes late says the loop stood
|
|
3
|
+
// still, and names the spans that overlapped the stall, longest overlap first. A span that blocked synchronously has
|
|
4
|
+
// already ended when the late beat fires, so the finished spans are kept too
|
|
5
|
+
export type Span = { what: string; at: number; end: number | null }
|
|
6
|
+
|
|
7
|
+
/** a stall shorter than this is the machine's ordinary jitter: the bar of wiki build/shipkit/home.md (Nothing heavy on the daemon's loop) */
|
|
8
|
+
export const STALL_MS = 200
|
|
9
|
+
const BEAT_MS = 250
|
|
10
|
+
const KEEP = 300
|
|
11
|
+
/** a parent span (a request, the tick) and its named steps both fit on the line */
|
|
12
|
+
const NAMED = 6
|
|
13
|
+
|
|
14
|
+
export class LoopWatch {
|
|
15
|
+
private active = new Set<Span>()
|
|
16
|
+
private done: Span[] = []
|
|
17
|
+
private last: number
|
|
18
|
+
|
|
19
|
+
constructor(private now: () => number = Date.now, private stallMs = STALL_MS, private beatMs = BEAT_MS) {
|
|
20
|
+
this.last = now()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** starts a span; the function it returns ends it */
|
|
24
|
+
span(what: string): () => void {
|
|
25
|
+
const s: Span = { what, at: this.now(), end: null }
|
|
26
|
+
this.active.add(s)
|
|
27
|
+
return () => {
|
|
28
|
+
if (s.end != null) return
|
|
29
|
+
s.end = this.now()
|
|
30
|
+
this.active.delete(s)
|
|
31
|
+
this.done.push(s)
|
|
32
|
+
if (this.done.length > KEEP) this.done.splice(0, this.done.length - KEEP)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** sync `f` inside a span: the span ends even when `f` throws */
|
|
37
|
+
timed<T>(what: string, f: () => T): T {
|
|
38
|
+
const end = this.span(what)
|
|
39
|
+
try {
|
|
40
|
+
return f()
|
|
41
|
+
} finally {
|
|
42
|
+
end()
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** `f` inside a span, sync or async */
|
|
47
|
+
async spanned<T>(what: string, f: () => Promise<T> | T): Promise<T> {
|
|
48
|
+
const end = this.span(what)
|
|
49
|
+
try {
|
|
50
|
+
return await f()
|
|
51
|
+
} finally {
|
|
52
|
+
end()
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** the spans that overlapped [from, to], longest overlap first, with that overlap in ms */
|
|
57
|
+
overlapping(from: number, to: number): { what: string; ms: number; open: boolean }[] {
|
|
58
|
+
return [...this.done, ...this.active]
|
|
59
|
+
.map((s) => ({ what: s.what, ms: Math.min(s.end ?? to, to) - Math.max(s.at, from), open: s.end == null }))
|
|
60
|
+
.filter((x) => x.ms > 0)
|
|
61
|
+
.sort((a, b) => b.ms - a.ms)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** one beat: the stall line when the loop stood still since the last beat, else null */
|
|
65
|
+
beat(): string | null {
|
|
66
|
+
const t = this.now()
|
|
67
|
+
const gap = t - this.last - this.beatMs
|
|
68
|
+
const from = this.last
|
|
69
|
+
this.last = t
|
|
70
|
+
if (gap < this.stallMs) return null
|
|
71
|
+
const by = this.overlapping(from, t)
|
|
72
|
+
const named = by.slice(0, NAMED).map((x) => `${x.what} ${(x.ms / 1000).toFixed(1)}s${x.open ? ' (still running)' : ''}`)
|
|
73
|
+
const more = by.length > NAMED ? `, ${by.length - NAMED} more` : ''
|
|
74
|
+
return `the loop stood still ${(gap / 1000).toFixed(1)}s: ${named.length === 0 ? 'no named work ran in it' : `${named.join(', ')}${more}`}`
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** beats on a timer and says each stall; returns its stop */
|
|
78
|
+
start(say: (l: string) => void): () => void {
|
|
79
|
+
this.last = this.now()
|
|
80
|
+
const t = setInterval(() => {
|
|
81
|
+
const l = this.beat()
|
|
82
|
+
if (l != null) say(`WARN ${l}`)
|
|
83
|
+
}, this.beatMs)
|
|
84
|
+
t.unref()
|
|
85
|
+
return () => clearInterval(t)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** the loop back to whoever waits (a request, a beat), between two steps of a long piece of work */
|
|
90
|
+
export const yieldLoop = (): Promise<void> => new Promise((r) => setImmediate(r))
|
|
91
|
+
|
|
92
|
+
/** the process's one watch: the daemon starts it, its jobs and requests name themselves on it */
|
|
93
|
+
export const loopWatch = new LoopWatch()
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// a house repo's node_modules/rvlib-shipkit is the machine's copy, linked:
|
|
2
|
+
// every path that loads the lib by name (bun test, a bun script, tsc, the
|
|
3
|
+
// editor, the commit hooks) runs the source `sk` runs, so a change made in the
|
|
4
|
+
// house is usable in every house repo at once, and a release is for npm only.
|
|
5
|
+
// Every cli run makes it, a few lstats when it is already there.
|
|
6
|
+
//
|
|
7
|
+
// the one constraint a reader breaks first: a link to a source tree (no
|
|
8
|
+
// node_modules in its real path) is never touched, a worktree linked for live
|
|
9
|
+
// hacking included. Only an install is swapped.
|
|
10
|
+
import { existsSync, lstatSync, readFileSync, realpathSync, renameSync, rmSync, symlinkSync, writeFileSync } from 'fs'
|
|
11
|
+
import { homedir } from 'os'
|
|
12
|
+
import { dirname, join, relative, resolve, sep } from 'path'
|
|
13
|
+
import { CLAUDE_FILES } from '../home/pm-inputs.ts'
|
|
14
|
+
|
|
15
|
+
const NAME = 'rvlib-shipkit'
|
|
16
|
+
|
|
17
|
+
type Env = Record<string, string | undefined>
|
|
18
|
+
const set = (v: string | undefined): boolean => v != null && v !== ''
|
|
19
|
+
|
|
20
|
+
/** the nearest dir at or above `cwd` whose node_modules holds the lib, as bun
|
|
21
|
+
* resolves it from there, else null */
|
|
22
|
+
export function consumerOf(cwd: string): string | null {
|
|
23
|
+
for (let dir = resolve(cwd); ; dir = dirname(dir)) {
|
|
24
|
+
try {
|
|
25
|
+
lstatSync(join(dir, 'node_modules', NAME))
|
|
26
|
+
return dir
|
|
27
|
+
} catch { /* not here */ }
|
|
28
|
+
if (dirname(dir) === dir) return null
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** an install (npm, bun, a cache) rather than a source tree */
|
|
33
|
+
export const isInstall = (real: string): boolean => real.split(sep).includes('node_modules')
|
|
34
|
+
|
|
35
|
+
const declares = (dir: string): boolean => {
|
|
36
|
+
try {
|
|
37
|
+
const pkg = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')) as { dependencies?: Record<string, string>; devDependencies?: Record<string, string> }
|
|
38
|
+
const spec = pkg.dependencies?.[NAME] ?? pkg.devDependencies?.[NAME]
|
|
39
|
+
return spec != null && !spec.startsWith('link:') && !spec.startsWith('file:')
|
|
40
|
+
} catch {
|
|
41
|
+
return false
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const versionOf = (dir: string): string => {
|
|
46
|
+
try {
|
|
47
|
+
return (JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')) as { version?: string }).version ?? '?'
|
|
48
|
+
} catch {
|
|
49
|
+
return '?'
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type LinkPlan =
|
|
54
|
+
| { action: 'none' }
|
|
55
|
+
| { action: 'link'; repo: string; lib: string; was: string }
|
|
56
|
+
| { action: 'no-house'; repo: string; index: string; was: string }
|
|
57
|
+
|
|
58
|
+
/** what the run should do in `repo`, whose node_modules holds an install of
|
|
59
|
+
* the lib. `lib` is the machine's copy, null when this machine has no house */
|
|
60
|
+
export function planLink(o: { repo: string; env: Env; declared: boolean; lib: string | null; house: string | null; missingIndex: string | null; was: string }): LinkPlan {
|
|
61
|
+
if (set(o.env.CI) || set(o.env.SHIPKIT_NO_HOME) || o.env.SHIPKIT_FROZEN === '1' || !o.declared) return { action: 'none' }
|
|
62
|
+
if (o.lib == null || o.house == null) return o.missingIndex == null ? { action: 'none' } : { action: 'no-house', repo: o.repo, index: o.missingIndex, was: o.was }
|
|
63
|
+
// the house runs its source by path: an install inside it is its own business
|
|
64
|
+
if (o.repo === o.house || o.repo.startsWith(`${o.house}${sep}`)) return { action: 'none' }
|
|
65
|
+
return { action: 'link', repo: o.repo, lib: o.lib, was: o.was }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** swap the install for a relative link to `lib`, the shape `bun link` makes.
|
|
69
|
+
* The install is moved aside first and put back when the link fails */
|
|
70
|
+
export function swapInLink(repo: string, lib: string): void {
|
|
71
|
+
const nm = join(repo, 'node_modules')
|
|
72
|
+
const at = join(nm, NAME)
|
|
73
|
+
const aside = join(nm, `.${NAME}-installed-${process.pid}`)
|
|
74
|
+
renameSync(at, aside)
|
|
75
|
+
try {
|
|
76
|
+
// from the real dir: a node_modules that is itself a link sits at another depth
|
|
77
|
+
symlinkSync(relative(realpathSync(nm), lib), at)
|
|
78
|
+
} catch (e) {
|
|
79
|
+
try {
|
|
80
|
+
renameSync(aside, at)
|
|
81
|
+
} catch {
|
|
82
|
+
throw new Error(`${e instanceof Error ? e.message : String(e)}; the install stays at ${aside}`)
|
|
83
|
+
}
|
|
84
|
+
throw e
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
rmSync(aside, { recursive: true, force: true })
|
|
88
|
+
} catch (e) {
|
|
89
|
+
throw new Error(`linked, but the old install stays at ${aside}: ${e instanceof Error ? e.message : String(e)}`)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** an install, or a link that resolves nowhere (its target moved): both are swapped */
|
|
94
|
+
export function needsLink(at: string): boolean {
|
|
95
|
+
try {
|
|
96
|
+
return isInstall(realpathSync(at))
|
|
97
|
+
} catch {
|
|
98
|
+
return lstatSync(at).isSymbolicLink()
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const NO_HOUSE_MARK = `.${NAME}-no-house`
|
|
103
|
+
|
|
104
|
+
/** the cli's step: link the machine's copy into the repo `cwd` sits in. Never
|
|
105
|
+
* throws, prints one line when it links, and one line per install when the
|
|
106
|
+
* repo names a house this machine lacks */
|
|
107
|
+
export async function linkMachineCopy(cwd: string = process.cwd(), env: Env = process.env, print: (s: string) => void = (s) => console.error(s)): Promise<void> {
|
|
108
|
+
try {
|
|
109
|
+
const repo = consumerOf(cwd)
|
|
110
|
+
if (repo == null) return
|
|
111
|
+
const at = join(repo, 'node_modules', NAME)
|
|
112
|
+
if (!needsLink(at)) return
|
|
113
|
+
// a stranger's npm repo names no house: no house lookup on each run
|
|
114
|
+
if (!CLAUDE_FILES.some((f) => existsSync(join(repo, f)))) return
|
|
115
|
+
const { houseCli, houseRootOf } = await import('../home/home-start.ts')
|
|
116
|
+
const { includeTargets } = await import('../serve/project-gutter.ts')
|
|
117
|
+
const house = houseRootOf(repo)
|
|
118
|
+
const cli = house == null ? null : houseCli(house, '')
|
|
119
|
+
const lib = cli == null || cli === '' ? null : resolve(dirname(cli), '..')
|
|
120
|
+
const missingIndex = house == null ? includeTargets(repo, homedir()).find((t) => !t.startsWith(`${repo}${sep}`) && !existsSync(t)) ?? null : null
|
|
121
|
+
const plan = planLink({ repo, env, declared: declares(repo), lib: lib != null && existsSync(join(lib, 'package.json')) ? lib : null, house, missingIndex, was: existsSync(at) ? versionOf(at) : 'a dangling link' })
|
|
122
|
+
if (plan.action === 'link') {
|
|
123
|
+
swapInLink(plan.repo, plan.lib)
|
|
124
|
+
print(`shipkit: ${relative(homedir(), plan.repo) || plan.repo}/node_modules/${NAME} was ${plan.was === 'a dangling link' ? plan.was : `the installed ${plan.was}`}, now a link to the machine's copy (${relative(homedir(), plan.lib)}): bun, tsc and the hooks here run it`)
|
|
125
|
+
} else if (plan.action === 'no-house') {
|
|
126
|
+
const mark = join(repo, 'node_modules', NO_HOUSE_MARK)
|
|
127
|
+
if (existsSync(mark)) return
|
|
128
|
+
writeFileSync(mark, `${plan.index}\n`)
|
|
129
|
+
print(`shipkit: no machine copy here (${plan.index} is absent): this repo runs its installed ${NAME} ${plan.was}`)
|
|
130
|
+
}
|
|
131
|
+
} catch (e) {
|
|
132
|
+
print(`WARN shipkit: node_modules/${NAME} and the machine's copy: ${e instanceof Error ? e.message : String(e)}`)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// the daemon's memory as a trend in its log: one line every 10 minutes, and only when it moved by a tenth since the
|
|
2
|
+
// line before, so a steady daemon writes nothing and a leak reads as a climb. At most 6 lines an hour, and pm trims
|
|
3
|
+
// the log past its cap (capLog), so the disk never fills from it. A restart in place starts it again from zero
|
|
4
|
+
export const MEMORY_EVERY_MS = 10 * 60_000
|
|
5
|
+
/** a move smaller than this share of the last said value says nothing */
|
|
6
|
+
export const MEMORY_STEP = 0.1
|
|
7
|
+
|
|
8
|
+
export type Memory = { rss: number; heap: number }
|
|
9
|
+
|
|
10
|
+
const mb = (b: number): string => `${Math.round(b / 1e6)} MB`
|
|
11
|
+
|
|
12
|
+
export class MemoryWatch {
|
|
13
|
+
private said: Memory | null = null
|
|
14
|
+
private readonly from: Memory
|
|
15
|
+
|
|
16
|
+
constructor(private read: () => Memory = () => {
|
|
17
|
+
const m = process.memoryUsage()
|
|
18
|
+
return { rss: m.rss, heap: m.heapUsed }
|
|
19
|
+
}) {
|
|
20
|
+
this.from = read()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** one look: the line when the resident size moved by MEMORY_STEP since the last line (or the start), else null */
|
|
24
|
+
look(): string | null {
|
|
25
|
+
const m = this.read()
|
|
26
|
+
const base = this.said ?? this.from
|
|
27
|
+
if (Math.abs(m.rss - base.rss) < base.rss * MEMORY_STEP) return null
|
|
28
|
+
this.said = m
|
|
29
|
+
return `memory: ${mb(m.rss)} resident, ${mb(m.heap)} heap (${m.rss >= base.rss ? 'up' : 'down'} from ${mb(base.rss)}, ${mb(this.from.rss)} at start)`
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** looks on a timer and says each move; returns its stop */
|
|
33
|
+
start(say: (l: string) => void): () => void {
|
|
34
|
+
const t = setInterval(() => {
|
|
35
|
+
const l = this.look()
|
|
36
|
+
if (l != null) say(`ok: ${l}`)
|
|
37
|
+
}, MEMORY_EVERY_MS)
|
|
38
|
+
t.unref()
|
|
39
|
+
return () => clearInterval(t)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// The deny is the floor and the hook is the messenger. When the hook cannot
|
|
15
15
|
// run, enforcement degrades to terse rather than to nothing.
|
|
16
16
|
//
|
|
17
|
-
// Subprocesses are NOT intercepted (verified): shipkit spawning
|
|
17
|
+
// Subprocesses are NOT intercepted (verified): shipkit spawning bun check or
|
|
18
18
|
// `bun run test:raw` from inside a permitted `shipkit ci` is invisible to
|
|
19
19
|
// these rules, which is exactly what makes the gate itself still work.
|
|
20
20
|
|
|
@@ -25,34 +25,42 @@ export type RawRunner = {
|
|
|
25
25
|
* the shell command together: a repo that keeps `test` raw is not then
|
|
26
26
|
* refused `bun test` */
|
|
27
27
|
slot: 'test' | 'typecheck'
|
|
28
|
-
/**
|
|
28
|
+
/** what is wrong with the raw call, after its head */
|
|
29
|
+
why: string
|
|
30
|
+
/** the command to type instead */
|
|
29
31
|
use: string
|
|
30
|
-
/** the
|
|
32
|
+
/** the other way in, with what it is for: iterating on a single repro
|
|
31
33
|
* test while you fix a bug is not a verification and stays normal. A
|
|
32
34
|
* FILE filter (measured): bun's positional argument matches the test FILE
|
|
33
35
|
* path, and a test NAME needs `-- -t "<name>"` forwarded through bun run */
|
|
34
|
-
|
|
36
|
+
also?: string
|
|
35
37
|
}
|
|
36
38
|
|
|
39
|
+
const BYPASS = 'bypasses shipkit, so nothing is cached and no other agent\'s run can be attached to'
|
|
40
|
+
const TEST: Omit<RawRunner, 'head'> = { slot: 'test', why: BYPASS, use: 'shipkit ci --only test', also: '`bun run test:raw <test file>` to iterate on ONE suite while you fix a bug' }
|
|
41
|
+
// bun check is bun's own checker: tsc's errors on every core, so it runs bare
|
|
42
|
+
// like `bun lint`. A package.json `check` script runs in its place (SK001 warns)
|
|
43
|
+
const TYPECHECK: Omit<RawRunner, 'head'> = { slot: 'typecheck', why: 'is not the house type checker', use: 'bun check', also: '`shipkit ci --only typecheck` for the gate\'s verdict, cached. Where package.json has a `check` script, `bun check --no-script`' }
|
|
44
|
+
|
|
37
45
|
// the house stack, plus the foreign runners a wired repo is actually found
|
|
38
46
|
// carrying. Kept tight on purpose: a deny an agent hits for no good reason
|
|
39
47
|
// teaches it to route around the whole file.
|
|
40
48
|
export const RAW_RUNNERS: readonly RawRunner[] = [
|
|
41
|
-
{ head: 'bun test',
|
|
42
|
-
{ head: 'bunx vitest',
|
|
43
|
-
{ head: 'npx vitest',
|
|
44
|
-
{ head: 'vitest',
|
|
45
|
-
{ head: 'npx jest',
|
|
46
|
-
{ head: 'jest',
|
|
47
|
-
{ head: 'bunx tsc',
|
|
48
|
-
{ head: 'npx tsc',
|
|
49
|
-
{ head: 'tsc',
|
|
49
|
+
{ head: 'bun test', ...TEST },
|
|
50
|
+
{ head: 'bunx vitest', ...TEST },
|
|
51
|
+
{ head: 'npx vitest', ...TEST },
|
|
52
|
+
{ head: 'vitest', ...TEST },
|
|
53
|
+
{ head: 'npx jest', ...TEST },
|
|
54
|
+
{ head: 'jest', ...TEST },
|
|
55
|
+
{ head: 'bunx tsc', ...TYPECHECK },
|
|
56
|
+
{ head: 'npx tsc', ...TYPECHECK },
|
|
57
|
+
{ head: 'tsc', ...TYPECHECK },
|
|
50
58
|
]
|
|
51
59
|
|
|
52
|
-
// the LINTER
|
|
53
|
-
// `bun fmt` are the house way in: bun's built-ins
|
|
54
|
-
//
|
|
55
|
-
// manual tool the gate never runs.
|
|
60
|
+
// the LINTER, the FORMATTER and `bun check` are deliberately absent. `bun
|
|
61
|
+
// lint`, `bun fmt` and `bun check` are the house way in: bun's built-ins
|
|
62
|
+
// are fast enough over a whole repo that a cache has little to save, and the
|
|
63
|
+
// formatter is a manual tool the gate never runs.
|
|
56
64
|
|
|
57
65
|
/** the `permissions.deny` entries, in the syntax Claude Code matches:
|
|
58
66
|
* `Bash(<head>*)` is a prefix match, and a compound command is checked one
|
|
@@ -175,9 +183,9 @@ export function stashRefusal(segment: string): string {
|
|
|
175
183
|
* does: a long compound refused on `CI=1 bun test --timeout 5` otherwise
|
|
176
184
|
* leaves the reader guessing which of its clauses was the problem */
|
|
177
185
|
export function refusal(r: RawRunner, segment?: string): string {
|
|
178
|
-
const alt = r.
|
|
186
|
+
const alt = r.also == null ? '' : `, or ${r.also}`
|
|
179
187
|
const which = segment == null || segment.trim() === '' || segment.trim() === r.head ? '' : ` (refused on \`${segment.trim().slice(0, 80)}\`)`
|
|
180
|
-
return `\`${r.head}\`${which}
|
|
188
|
+
return `\`${r.head}\`${which} ${r.why}. Use \`${r.use}\`${alt}. Lifting this for good: delete the "Bash(${r.head}*)" line from .claude/settings.json permissions.deny (build/shipkit/one-way-in.md).`
|
|
181
189
|
}
|
|
182
190
|
|
|
183
191
|
/** shell wrappers that do not change what is being run */
|
package/src/core/run-ci.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// prints the structured summary. Every run refreshes STATUS.md
|
|
6
6
|
// (write-status.ts — atomic + lock) unless status:false, and the fix pass plus
|
|
7
7
|
// some checks WRITE, so a run is not read-only unless frozen is set and
|
|
8
|
-
//
|
|
8
|
+
// fix is false (internal callers only).
|
|
9
9
|
import { loadRepoConfig, type RepoConfig } from '../repo-config.ts'
|
|
10
10
|
import { reportToMotherhome } from './motherhome.ts'
|
|
11
11
|
import { passScope, runCheckPass, type CheckOpts } from './run-check.ts'
|
|
@@ -144,12 +144,10 @@ export async function runCi(root: string, o: CiOpts = {}): Promise<number> {
|
|
|
144
144
|
let c = o.config ?? (await loadRepoConfig(root))
|
|
145
145
|
// mechanical failures are not information, so they never cost a round trip
|
|
146
146
|
let fixFailed = false
|
|
147
|
-
// a NARROWED run repairs
|
|
148
|
-
//
|
|
149
|
-
//
|
|
150
|
-
//
|
|
151
|
-
// that it never wrote: in a shared tree a tree wide fixer rewrites every
|
|
152
|
-
// other agent's files too. Arming rewrites hooks/: the full gate's price alone
|
|
147
|
+
// a NARROWED run repairs only what the named checks own: their own ci
|
|
148
|
+
// repair and the fixer slot that governs one of them. No formatter is a
|
|
149
|
+
// fixer, so a repair is mechanical and safe in a shared tree. Arming
|
|
150
|
+
// rewrites hooks/: the full gate's price alone
|
|
153
151
|
const narrowed = (o.onlyIds ?? []).length > 0
|
|
154
152
|
if (fixPassRuns(o)) {
|
|
155
153
|
const pass = await runFixPass(root, c, { rules: o.fixRules !== false, armHooks: !narrowed && o.armHooks === true, print: sink, detail, ...(narrowed ? { only: o.onlyIds } : {}) })
|
|
@@ -163,7 +161,7 @@ export async function runCi(root: string, o: CiOpts = {}): Promise<number> {
|
|
|
163
161
|
return 1
|
|
164
162
|
}
|
|
165
163
|
}
|
|
166
|
-
} else detail(
|
|
164
|
+
} else detail('skip: fix pass (a report-only run)')
|
|
167
165
|
const tier: TestTier = o.tests ?? envTier()
|
|
168
166
|
// announced BEFORE the run (under --verbose, and in every release log),
|
|
169
167
|
// so a log that died mid-way still says which tier it was asking for
|
package/src/core/run-fixers.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// what `shipkit ci` repairs before it gates.
|
|
2
2
|
//
|
|
3
|
-
// mechanical slots
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
3
|
+
// mechanical slots (the import canonicaliser) and the structural SK rule
|
|
4
|
+
// repairs. Each output is total and mechanical, so every run applies them, in
|
|
5
|
+
// a tree other agents share too. no formatter runs here: formatting is a
|
|
6
|
+
// manual `bun fmt`, never a gate step.
|
|
7
7
|
//
|
|
8
8
|
// under CI the same fixers run in verify mode instead: a gate that silently
|
|
9
9
|
// rewrites the tree it checks can turn red green with no commit. one
|
|
@@ -204,7 +204,7 @@ export type FixPassOpts = {
|
|
|
204
204
|
* mutate the tree they are about to ship) */
|
|
205
205
|
armHooks?: boolean
|
|
206
206
|
print: (line: string) => void
|
|
207
|
-
/** a narrowed pass (`sk ci --only <ids
|
|
207
|
+
/** a narrowed pass (`sk ci --only <ids>`): only the repairs these
|
|
208
208
|
* ids own, their own ci repair and the fixer slot that governs one of
|
|
209
209
|
* them */
|
|
210
210
|
only?: string[]
|
|
@@ -235,7 +235,7 @@ export async function runFixPass(root: string, config: RepoConfig, o: FixPassOpt
|
|
|
235
235
|
// loser waits rather than skipping, because a skipped repair never
|
|
236
236
|
// happens; a live holder that outlasts the cap is REFUSED by name rather
|
|
237
237
|
// than overlapped, and the gate below still runs, unrepaired and saying so.
|
|
238
|
-
const lease = await withMutateLease(mutateLease(root, 'fix'), { label: 'fix pass', print: o.print
|
|
238
|
+
const lease = await withMutateLease(mutateLease(root, 'fix'), { label: 'fix pass', print: o.print }, () => fixPassBody(root, config, o, verify))
|
|
239
239
|
if (lease.ok) return lease.value
|
|
240
240
|
// in VERIFY mode the fix pass is the whole check: reporting "not run" and
|
|
241
241
|
// exiting 0 would pass a commit nobody verified, which is the one failure
|
|
@@ -243,7 +243,7 @@ export async function runFixPass(root: string, config: RepoConfig, o: FixPassOpt
|
|
|
243
243
|
// checks below still ran and still mean what they say.
|
|
244
244
|
if (verify) {
|
|
245
245
|
o.print(`FAIL: fixers never ran — ${lease.warn}`)
|
|
246
|
-
o.print(' fix: nothing was verified. re-run once that process finishes
|
|
246
|
+
o.print(' fix: nothing was verified. re-run once that process finishes')
|
|
247
247
|
return { ran: false, touched: [], failed: true, reshaped: false }
|
|
248
248
|
}
|
|
249
249
|
o.print(`WARN fix pass skipped — ${lease.warn}`)
|
|
@@ -258,7 +258,7 @@ async function fixPassBody(root: string, loaded: RepoConfig, o: FixPassOpts, ver
|
|
|
258
258
|
// path: a move is not a decision, so it lands as one machine commit and
|
|
259
259
|
// only what a machine cannot decide reaches a human. Runs before the tree
|
|
260
260
|
// snapshot, and before hooks arm, because the hooks folder may be what moves
|
|
261
|
-
if (!verify) {
|
|
261
|
+
if (!verify && o.only == null) {
|
|
262
262
|
const m = migrateLayout(root, { config, renderGitignore: (t, legacy, cfg) => renderPolicy(t, cfg ?? config, legacy) })
|
|
263
263
|
// the move rewrote repo.config.ts, so the config loaded before it names
|
|
264
264
|
// folders that are gone, and every fixer below must read the new one
|
|
@@ -334,7 +334,7 @@ async function fixPassBody(root: string, loaded: RepoConfig, o: FixPassOpts, ver
|
|
|
334
334
|
}
|
|
335
335
|
putBack(`fix ${s.id} (${s.cmd.join(' ').slice(0, 60)})`)
|
|
336
336
|
}
|
|
337
|
-
// structural repo-config repair
|
|
337
|
+
// structural repo-config repair: never in verify mode
|
|
338
338
|
if (o.rules === true && !verify) {
|
|
339
339
|
await runFix(root, { quiet: true, print: o.print, detail: o.detail, config, ...(o.only == null ? {} : { scope: o.only }) })
|
|
340
340
|
putBack('the rule repairs')
|
package/src/core/slots.ts
CHANGED
|
@@ -44,6 +44,27 @@ export const poolDir = (): string => {
|
|
|
44
44
|
* (a terminal, a button) never takes it, so it never waits behind one */
|
|
45
45
|
export const autoGatePool = (): SlotPool => ({ dir: `${poolDir()}-auto-gate`, size: 1 })
|
|
46
46
|
|
|
47
|
+
/** the headless browsers one repo runs at once (repo.config.ts `browsers.max`, shot/browser-slot.ts): one pool per
|
|
48
|
+
* repo NAME, so its worktrees and checkouts share it */
|
|
49
|
+
export const browserPool = (repo: string, size: number): SlotPool => ({ dir: join(`${poolDir()}-browsers`, repo.replace(/[^\w.-]/g, '_')), size })
|
|
50
|
+
|
|
51
|
+
/** a repo's browser cap when its config names none */
|
|
52
|
+
export const DEFAULT_BROWSERS = 2
|
|
53
|
+
|
|
54
|
+
/** why a `browsers` config is refused, or null when it holds */
|
|
55
|
+
export function browsersProblem(v: unknown): string | null {
|
|
56
|
+
if (v === undefined) return null
|
|
57
|
+
if (v === null || typeof v !== 'object' || Array.isArray(v)) return `browsers is an object, { max: <browsers at once>, box?: <ssh host> }, got ${JSON.stringify(v)}`
|
|
58
|
+
const extra = Object.keys(v).filter((k) => k !== 'max' && k !== 'box')
|
|
59
|
+
if (extra.length > 0) return `browsers has unknown key(s) ${extra.join(', ')}: it takes only max and box`
|
|
60
|
+
const box = (v as { box?: unknown }).box
|
|
61
|
+
if (box !== undefined && !(typeof box === 'string' && /^[\w.-]+$/.test(box))) return `browsers.box is the ssh host whose browser films for this repo, like 'wm', got ${JSON.stringify(box)}`
|
|
62
|
+
const max = (v as { max?: unknown }).max
|
|
63
|
+
if (max !== undefined && !(typeof max === 'number' && Number.isInteger(max) && max >= 1))
|
|
64
|
+
return `browsers.max is a whole number of browsers, 1 or more (default ${DEFAULT_BROWSERS}), got ${JSON.stringify(max)}`
|
|
65
|
+
return null
|
|
66
|
+
}
|
|
67
|
+
|
|
47
68
|
/** this process's pool, or null when it runs inside a check that holds one */
|
|
48
69
|
export function machinePool(): SlotPool | null {
|
|
49
70
|
return process.env[SLOT_HELD_ENV] === '1' ? null : { dir: poolDir(), size: parallelCap(), load: machineLoad }
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// a work tree's revision in this process: a count the save watch (serve/tracked-watch.ts) moves whenever a file the
|
|
2
|
+
// owner edits moves (tracked, or untracked and not ignored). A reader keyed on it reads the tree again only after a
|
|
3
|
+
// move, where a listing costs a git spawn and a stat per file (wiki build/shipkit/home.md, Nothing heavy on the
|
|
4
|
+
// daemon's loop).
|
|
5
|
+
//
|
|
6
|
+
// the one constraint a reader breaks first: no watch, no revision. `treeRev` is null for a root no live watch follows
|
|
7
|
+
// (a cli run, a watch that died), and the reader then reads the tree every time, as it did before
|
|
8
|
+
import { dirname, resolve } from 'node:path'
|
|
9
|
+
|
|
10
|
+
const revs = new Map<string, { rev: number; watches: number }>()
|
|
11
|
+
/** one clock for every tree: a revision is never handed out twice, so a watch that stops and starts again never
|
|
12
|
+
* matches what was kept under the one before */
|
|
13
|
+
let clock = 0
|
|
14
|
+
|
|
15
|
+
/** a live watch starts following `root`; the function it returns says it stopped */
|
|
16
|
+
export function followTree(root: string): () => void {
|
|
17
|
+
const key = resolve(root)
|
|
18
|
+
const r = revs.get(key) ?? { rev: 0, watches: 0 }
|
|
19
|
+
r.watches++
|
|
20
|
+
r.rev = ++clock
|
|
21
|
+
revs.set(key, r)
|
|
22
|
+
let done = false
|
|
23
|
+
return () => {
|
|
24
|
+
if (done) return
|
|
25
|
+
done = true
|
|
26
|
+
r.watches--
|
|
27
|
+
if (r.watches <= 0) revs.delete(key)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** a file under `root` moved */
|
|
32
|
+
export function treeMoved(root: string): void {
|
|
33
|
+
const r = revs.get(resolve(root))
|
|
34
|
+
if (r != null) r.rev = ++clock
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** the revision of the tree at `root`, null when no live watch follows it */
|
|
38
|
+
export function treeRev(root: string): number | null {
|
|
39
|
+
return revs.get(resolve(root))?.rev ?? null
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** the revision of the followed tree `path` sits in (itself or its nearest followed parent), null when none is */
|
|
43
|
+
export function treeRevAt(path: string): number | null {
|
|
44
|
+
for (let p = resolve(path); ; p = dirname(p)) {
|
|
45
|
+
const r = revs.get(p)
|
|
46
|
+
if (r != null) return r.rev
|
|
47
|
+
if (dirname(p) === p) return null
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** `read()` of `root`, kept while its revision holds: the same value until a file moves */
|
|
52
|
+
export function keptOnTree<T>(cache: Map<string, { rev: number; value: T }>, root: string, read: () => T): T {
|
|
53
|
+
const rev = treeRev(root)
|
|
54
|
+
if (rev == null) return read()
|
|
55
|
+
const held = cache.get(root)
|
|
56
|
+
if (held != null && held.rev === rev) return held.value
|
|
57
|
+
const value = read()
|
|
58
|
+
cache.set(root, { rev, value })
|
|
59
|
+
return value
|
|
60
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// the `<name>.shipkit.ts` files that declare one kind of unit (`review(`, `social(`), found by a text test, never an
|
|
2
|
+
// import: the walk's dirs are cached on their times in `.shipkit/cache/<kind>-unit.json`, so a call costs a stat of
|
|
3
|
+
// each walked dir until a file comes or goes
|
|
4
|
+
import { mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs'
|
|
5
|
+
import { join } from 'node:path'
|
|
6
|
+
import { repoUnitFiles } from './discover-checks.ts'
|
|
7
|
+
import { LAYOUT } from './layout.ts'
|
|
8
|
+
|
|
9
|
+
/** the walk's answer kept in the cache: the unit files and every dir it read, each with its time; a dir whose time moved
|
|
10
|
+
* means a file came or went, so the walk runs again */
|
|
11
|
+
interface Found {
|
|
12
|
+
dirs: [string, number][]
|
|
13
|
+
files: [string, number, boolean][]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const mtime = (p: string): number => statSync(p, { throwIfNoEntry: false })?.mtimeMs ?? -1
|
|
17
|
+
|
|
18
|
+
/** the unit files of the repo whose text calls `<kind>(` */
|
|
19
|
+
export function unitFilesDeclaring(root: string, kind: string): string[] {
|
|
20
|
+
const cache = join(root, LAYOUT.cache, `${kind}-unit.json`)
|
|
21
|
+
const calls = new RegExp(`\\b${kind}\\s*\\(`)
|
|
22
|
+
let found: Found | null = null
|
|
23
|
+
try {
|
|
24
|
+
found = JSON.parse(readFileSync(cache, 'utf8')) as Found
|
|
25
|
+
} catch {
|
|
26
|
+
found = null
|
|
27
|
+
}
|
|
28
|
+
const fresh = (f: Found): boolean => f.dirs.every(([d, t]) => mtime(d) === t) && f.files.every(([p, t]) => mtime(p) === t)
|
|
29
|
+
if (!found || !fresh(found)) {
|
|
30
|
+
const dirs: string[] = []
|
|
31
|
+
const files = repoUnitFiles(root, dirs).filter((f) => !f.endsWith('.check.shipkit.ts'))
|
|
32
|
+
found = { dirs: dirs.map((d) => [d, mtime(d)]), files: files.map((f) => [f, mtime(f), calls.test(readFileSync(f, 'utf8'))]) }
|
|
33
|
+
try {
|
|
34
|
+
mkdirSync(join(root, LAYOUT.cache), { recursive: true })
|
|
35
|
+
writeFileSync(`${cache}.${process.pid}.tmp`, JSON.stringify(found))
|
|
36
|
+
renameSync(`${cache}.${process.pid}.tmp`, cache)
|
|
37
|
+
} catch {
|
|
38
|
+
// a read only checkout: the next run walks again
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return found.files.filter(([, , has]) => has).map(([f]) => f)
|
|
42
|
+
}
|