rvlib-shipkit 2.21.0 → 2.22.1
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 +23 -0
- package/package.json +1 -1
- package/src/asks/asks-queue.ts +8 -7
- package/src/assets/kits/identity-kit.ts +158 -2
- package/src/cli/cmd_Bump.ts +3 -3
- package/src/cli/cmd_Rec.ts +349 -0
- package/src/cli/cmd_Releases.ts +4 -1
- package/src/cli/cmd_Secret.ts +10 -3
- package/src/cli/cmd_Sign.ts +24 -0
- package/src/cli/cmd_Social.ts +44 -1
- package/src/cli/family-pages.ts +1 -0
- package/src/cli/registry.ts +4 -0
- package/src/core/agent-spawn.ts +4 -17
- package/src/core/code-lines.ts +49 -0
- package/src/core/discover-checks.ts +27 -3
- package/src/core/hard-reset.ts +34 -0
- package/src/core/raw-access.ts +3 -13
- package/src/core/throwaway-worktree.ts +72 -0
- package/src/home/app-sign.ts +98 -0
- package/src/home/gui-app.ts +31 -12
- package/src/home/home-routes.ts +6 -0
- package/src/home/serve-web.ts +1 -1
- package/src/identities/identities.ts +6 -0
- package/src/media-kinds.ts +5 -3
- package/src/media-store/forget.ts +54 -0
- package/src/media-store/put.ts +4 -3
- package/src/media-store/space.ts +63 -24
- package/src/recordings/delete.ts +19 -0
- package/src/recordings/edit.ts +231 -0
- package/src/recordings/load.ts +37 -0
- package/src/recordings/marks-draw.ts +111 -0
- package/src/recordings/marks-png.ts +25 -0
- package/src/recordings/marks.ts +138 -0
- package/src/recordings/media-kind.ts +67 -0
- package/src/recordings/model.ts +170 -0
- package/src/recordings/open.ts +33 -0
- package/src/recordings/place.ts +89 -0
- package/src/recordings/presets.ts +99 -0
- package/src/recordings/recorder-app/Capture.swift +510 -0
- package/src/recordings/recorder-app/Clip.swift +162 -0
- package/src/recordings/recorder-app/Editor.swift +39 -0
- package/src/recordings/recorder-app/Tray.swift +298 -0
- package/src/recordings/recorder-app/main.swift +862 -0
- package/src/recordings/recorder-app.ts +46 -0
- package/src/recordings/recorder.shipkit.ts +11 -0
- package/src/recordings/routes.ts +140 -0
- package/src/recordings/run-recorder.ts +40 -0
- package/src/recordings/share.ts +107 -0
- package/src/recordings/take.ts +146 -0
- package/src/recordings/view.ts +40 -0
- package/src/release/gate-checkout.ts +74 -0
- package/src/release/release-scope.ts +35 -26
- package/src/release/run-bump.ts +79 -37
- package/src/release/run-release.ts +67 -53
- package/src/releases/add.ts +7 -2
- package/src/releases/from-card.ts +3 -3
- package/src/releases/model.ts +29 -7
- package/src/repo-config.ts +7 -3
- package/src/review/trailer-desk.ts +1 -0
- package/src/review/trailer-model.ts +2 -0
- package/src/secrets/manager.ts +18 -1
- package/src/serve/hub-app/home-st.ts +15 -5
- package/src/serve/hub-app/home.html +1 -0
- package/src/serve/hub-app/hub-app.tsx +6 -1
- package/src/serve/hub-app/icons.tsx +2 -0
- package/src/serve/hub-app/palette-st.ts +1 -0
- package/src/serve/hub-app/project-list.tsx +1 -0
- package/src/serve/hub-app/projects-svc.ts +1 -1
- package/src/serve/hub-app/recordings-st.ts +641 -0
- package/src/serve/hub-app/recordings-view.tsx +504 -0
- package/src/serve/hub-app/recordings.css +82 -0
- package/src/serve/hub-app/repo-st.ts +1 -1
- package/src/serve/hub-app/review/trailer-page.tsx +1 -0
- package/src/serve/hub-app/review/trailer-st.ts +16 -0
- package/src/serve/hub-app/review/trailer-timeline.tsx +3 -0
- package/src/serve/hub-app/review.css +2 -0
- package/src/serve/hub-app/social/post-card.tsx +31 -3
- package/src/serve/hub-app/social/social-model.ts +4 -0
- package/src/serve/hub-app/social/social-st.ts +12 -0
- package/src/serve/hub-app/social.css +4 -0
- package/src/shipkit.ts +2 -2
- package/src/shot/box.ts +23 -17
- package/src/shot/browser-slot.ts +13 -3
- package/src/shot/film-box.ts +193 -117
- package/src/shot/shooter.ts +5 -3
- package/src/smoke/run-smoke.ts +8 -6
- package/src/social/compose.ts +14 -0
- package/src/social/drafts.ts +1 -1
- package/src/social/load.ts +16 -2
- package/src/social/publish/index.ts +3 -1
- package/src/social/publish/secret.ts +12 -4
- package/src/social/release-card.ts +69 -0
- package/src/social/release-stage.ts +49 -10
- package/src/social/routes.ts +5 -0
- package/src/social/stage.ts +9 -5
- package/src/trailer/build.ts +24 -0
- package/src/trailer/ffmpeg.ts +8 -0
- package/src/trailer/grammar.ts +9 -2
- package/src/trailer/look.ts +7 -0
- package/src/veille/chrome.ts +6 -3
package/src/cli/cmd_Releases.ts
CHANGED
|
@@ -49,12 +49,13 @@ export class ReleasesAddCommand extends Command {
|
|
|
49
49
|
category: 'Gate',
|
|
50
50
|
description: 'a change of .shipkit/releases/next.md by hand: its line, text, picture, before, bullets',
|
|
51
51
|
details:
|
|
52
|
-
"one change of the release being filled. With --card, the card's changelog line and media (what his approval adds, run again by hand when it failed: a pair as its after and its before, two stills, the before dropped when blank or the same as the after; a clip as it is, else its image); a category and a title given beside it win. A change of the same card, else of the same title, is replaced, its description, bullets and shots kept unless given; a new --image takes the place of the shot of its rating and drops that shot's before unless --before gives one. Every picture carries its rating (--rating, else the card's; unrated reads explicit, so no SFW venue shows it). A picture goes to the Space private; `sk bump` makes it public. The repo's guard reads every word first. Committed by pathspec",
|
|
52
|
+
"one change of the release being filled. With --card, the card's changelog line and media (what his approval adds, run again by hand when it failed: a pair as its after and its before, two stills, the before dropped when blank or the same as the after; a clip as it is, else its image); a category and a title given beside it win. A change of the same card, else of the same title, is replaced, its description, bullets and shots kept unless given; a new --image takes the place of the shot of its rating and drops that shot's before unless --before gives one. Every picture carries its rating (--rating, else the card's; unrated reads explicit, so no SFW venue shows it). Every change carries its weight (--weight major, feature or improvement): kept when not given, none until one is. A picture goes to the Space private; `sk bump` makes it public. The repo's guard reads every word first. Committed by pathspec",
|
|
53
53
|
examples: [
|
|
54
54
|
['the change of an approved card, again', 'sk releases add --card 20261108-115317-move-her'],
|
|
55
55
|
['a change by hand', 'sk releases add Studio "Move the body anywhere on the floor" --text "Drag the ring at the feet." --bullet "double tap: back to the middle" --image shot.webp'],
|
|
56
56
|
["a card's change, a new after and its before", 'sk releases add --card 20261108-115317-move-her --image after.webp --before before.webp'],
|
|
57
57
|
["a card's picture looked at: safe", 'sk releases add --card 20261108-115317-move-her --rating safe'],
|
|
58
|
+
["a card's change weighs: major, feature or improvement", 'sk releases add --card 20261108-115317-move-her --weight feature'],
|
|
58
59
|
['the next release is a minor one', 'sk releases add --kind minor'],
|
|
59
60
|
],
|
|
60
61
|
})
|
|
@@ -70,6 +71,7 @@ export class ReleasesAddCommand extends Command {
|
|
|
70
71
|
commit = Option.String('--commit', { description: 'the commit it ships' })
|
|
71
72
|
kind = Option.String('--kind', { description: 'what kind of release next is: major, minor or patch' })
|
|
72
73
|
heading = Option.String('--release-title', { description: "the release's own title, its # heading" })
|
|
74
|
+
weight = Option.String('--weight', { description: 'what the change weighs: major (changes how people work), feature (a new thing they can do), improvement (a better version of what they had)' })
|
|
73
75
|
|
|
74
76
|
async execute(): Promise<number> {
|
|
75
77
|
try {
|
|
@@ -86,6 +88,7 @@ export class ReleasesAddCommand extends Command {
|
|
|
86
88
|
...(this.commit !== undefined ? { commit: this.commit } : {}),
|
|
87
89
|
...(this.kind !== undefined ? { kind: this.kind } : {}),
|
|
88
90
|
...(this.heading !== undefined ? { heading: this.heading } : {}),
|
|
91
|
+
...(this.weight !== undefined ? { weight: this.weight } : {}),
|
|
89
92
|
})
|
|
90
93
|
this.context.stdout.write(`ok: ${file}\n`)
|
|
91
94
|
return 0
|
package/src/cli/cmd_Secret.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// shipkit secret — the secrets of the repo you stand in, and the reads and
|
|
2
2
|
// writes through the house's secret manager (`credsReadCommand`, `credsCommand`).
|
|
3
|
-
// Logic in secrets/list.ts and secrets/manager.ts. A value only ever goes to stdout of `get`/`account
|
|
3
|
+
// Logic in secrets/list.ts and secrets/manager.ts. A value only ever goes to stdout of `get`/`account`,
|
|
4
|
+
// and only for a repo in the name's scope.
|
|
4
5
|
import { Command, Option } from 'clipanion'
|
|
5
6
|
import { presence, secretsFor } from '../secrets/list.ts'
|
|
6
|
-
import { managerTemplate as template, NoManager, secretsWhere as where, storeArgv } from '../secrets/manager.ts'
|
|
7
|
+
import { houseScopeOf, managerTemplate as template, NoManager, readRefusal, REFUSED_EXIT, secretsWhere as where, storeArgv } from '../secrets/manager.ts'
|
|
7
8
|
import { secretArgv } from '../smoke/run-smoke.ts'
|
|
8
9
|
|
|
9
10
|
/** runs a verb, printing a refusal as its one line */
|
|
@@ -74,7 +75,13 @@ export class SecretReadCommand extends Command {
|
|
|
74
75
|
async execute(): Promise<number> {
|
|
75
76
|
const field = this.path[1] === 'account' ? 'account' : 'get'
|
|
76
77
|
return refusing(this.context.stderr, async () => {
|
|
77
|
-
const
|
|
78
|
+
const w = await where(process.cwd())
|
|
79
|
+
const refused = readRefusal(this.name, houseScopeOf(w, this.name), w)
|
|
80
|
+
if (refused != null) {
|
|
81
|
+
this.context.stderr.write(`${refused}\n`)
|
|
82
|
+
return REFUSED_EXIT
|
|
83
|
+
}
|
|
84
|
+
const argv = secretArgv(template(w, 'credsReadCommand'), this.name, field)
|
|
78
85
|
return Bun.spawnSync(argv, { stdout: 'inherit', stderr: 'inherit' }).exitCode ?? 1
|
|
79
86
|
})
|
|
80
87
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// sk sign-setup: the machine's code signing identity for shipkit's apps (home/app-sign.ts, wiki tools/shipkit/home-pages.md,
|
|
2
|
+
// Signing). Every module loads inside execute: the cli registers this file on every `sk` call
|
|
3
|
+
import { Command } from 'clipanion'
|
|
4
|
+
|
|
5
|
+
export class SignSetupCommand extends Command {
|
|
6
|
+
static override paths = [['sign-setup']]
|
|
7
|
+
static override usage = Command.Usage({
|
|
8
|
+
category: 'Serve',
|
|
9
|
+
description: "a local code signing identity for shipkit's apps: macOS permissions survive a rebuild",
|
|
10
|
+
details: `An ad hoc signature names the binary's hash, so macOS forgets an app's Screen Recording or Accessibility permission at every rebuild. This makes a self signed code signing certificate in its own keychain (${'~/.config/shipkit/home/signing.keychain-db'}), its random password in the login keychain, then asks macOS to trust it for code signing: macOS shows its own password prompt, once. Every app shipkit builds is then signed with it, and keeps its permissions. Run again: it says it is set up.`,
|
|
11
|
+
examples: [['once per machine', 'sk sign-setup']],
|
|
12
|
+
})
|
|
13
|
+
async execute(): Promise<number> {
|
|
14
|
+
const out = (l: string): void => void this.context.stdout.write(`${l}\n`)
|
|
15
|
+
try {
|
|
16
|
+
const { setupSigning } = await import('../home/app-sign.ts')
|
|
17
|
+
setupSigning(out)
|
|
18
|
+
return 0
|
|
19
|
+
} catch (e) {
|
|
20
|
+
this.context.stderr.write(`FAIL: sign-setup: ${(e as Error).message}\n`)
|
|
21
|
+
return 1
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/cli/cmd_Social.ts
CHANGED
|
@@ -200,6 +200,49 @@ class SocialReleaseCommand extends Command {
|
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
+
class SocialReleaseCardCommand extends Command {
|
|
204
|
+
static override paths = [['social', 'release-card']]
|
|
205
|
+
static override usage = Command.Usage({
|
|
206
|
+
category: 'Social',
|
|
207
|
+
description: "a release draft's picture: the brand's icon, name and version beside a feature, first in its media",
|
|
208
|
+
details:
|
|
209
|
+
"Renders the identity kit's release card (1200x675) into the draft's media/release-<version>.png, puts it first in its media and sets its alt, then commits the two files. The feature is the release file's first safe still unless --feature names one: a SAFE still only, every venue attaches the card; --feature none draws the poster (no feature). The headline is the release file's title, else the change its feature shows, else its first change; --headline gives it. --focus is where the feature's subject sits across it, 0 to 1 (default 0.3). Page: wiki tools/shipkit/social.md, The release card",
|
|
210
|
+
examples: [
|
|
211
|
+
['the release file decides', 'sk social release-card 20261108-120000-app-1-2-0'],
|
|
212
|
+
['a feature and a headline picked', 'sk social release-card app-1-2-0 --feature shots/hands.png --headline "Hands that pinch. A new room."'],
|
|
213
|
+
['the poster', 'sk social release-card app-1-2-1 --feature none'],
|
|
214
|
+
],
|
|
215
|
+
})
|
|
216
|
+
draft = Option.String({ required: true })
|
|
217
|
+
feature = Option.String('--feature', { description: 'a SAFE still beside the brand, or none for the poster (default: the release file\'s first safe still)' })
|
|
218
|
+
headline = Option.String('--headline', { description: "the card's one line (default: the release's title, else its feature's change, else its first change)" })
|
|
219
|
+
focus = Option.String('--focus', { description: "where the feature's subject sits across it, 0 left to 1 right (default 0.3)" })
|
|
220
|
+
override async execute(): Promise<number> {
|
|
221
|
+
return guarded(this.context, async () => {
|
|
222
|
+
const { resolve } = await import('node:path')
|
|
223
|
+
const { desk } = await model(undefined)
|
|
224
|
+
const { findDraft } = await import('../social/load.ts')
|
|
225
|
+
const { loadSocialUnit } = await import('../social/unit.ts')
|
|
226
|
+
const { releaseCardDraft } = await import('../social/release-stage.ts')
|
|
227
|
+
const focus = this.focus === undefined ? undefined : Number(this.focus)
|
|
228
|
+
if (focus !== undefined && !(focus >= 0 && focus <= 1)) throw new Error(`--focus ${this.focus}: a number from 0 to 1`)
|
|
229
|
+
const d = findDraft(desk, this.draft, process.cwd())
|
|
230
|
+
const r = await releaseCardDraft(
|
|
231
|
+
desk.root,
|
|
232
|
+
d.slug,
|
|
233
|
+
{
|
|
234
|
+
...(this.feature === undefined ? {} : { feature: this.feature === 'none' ? null : resolve(process.cwd(), this.feature) }),
|
|
235
|
+
...(this.headline === undefined ? {} : { headline: this.headline }),
|
|
236
|
+
...(focus === undefined ? {} : { focus }),
|
|
237
|
+
},
|
|
238
|
+
{ unit: await loadSocialUnit(desk.root) },
|
|
239
|
+
)
|
|
240
|
+
say(this.context)(`ok: ${d.slug} ${r.media}, ${r.feature ? `beside ${r.feature}` : 'the poster'}, "${r.headline}"`)
|
|
241
|
+
return 0
|
|
242
|
+
})
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
203
246
|
class SocialPlanCommand extends Command {
|
|
204
247
|
static override paths = [['social', 'plan']]
|
|
205
248
|
static override usage = Command.Usage({
|
|
@@ -415,4 +458,4 @@ class IdentitiesPushCommand extends Command {
|
|
|
415
458
|
}
|
|
416
459
|
}
|
|
417
460
|
|
|
418
|
-
export const SOCIAL_COMMANDS = [SocialCommand, SocialTimelineCommand, SocialCoverageCommand, SocialPostCommand, SocialReleaseCommand, SocialPlanCommand, SocialStateCommand, SocialMigrateCommand, SocialDiscordApplyCommand, IdentitiesCommand, IdentitiesPushCommand]
|
|
461
|
+
export const SOCIAL_COMMANDS = [SocialCommand, SocialTimelineCommand, SocialCoverageCommand, SocialPostCommand, SocialReleaseCommand, SocialReleaseCardCommand, SocialPlanCommand, SocialStateCommand, SocialMigrateCommand, SocialDiscordApplyCommand, IdentitiesCommand, IdentitiesPushCommand]
|
package/src/cli/family-pages.ts
CHANGED
|
@@ -14,6 +14,7 @@ export const FAMILY_PAGES: Readonly<Record<string, string>> = {
|
|
|
14
14
|
Home: 'tools/shipkit/home.md',
|
|
15
15
|
Media: 'tools/shipkit/media-store.md',
|
|
16
16
|
Messages: 'tools/shipkit/messages.md',
|
|
17
|
+
Record: 'tools/shipkit/recordings.md',
|
|
17
18
|
Refactor: 'patterns/typescript/index.md',
|
|
18
19
|
Review: 'tools/shipkit/review.md',
|
|
19
20
|
Scaffold: 'patterns/pocketbase/index.md',
|
package/src/cli/registry.ts
CHANGED
|
@@ -48,6 +48,8 @@ import { SOUND_COMMANDS } from './cmd_Sound.ts'
|
|
|
48
48
|
import { REVIEW_COMMANDS } from './cmd_Review.ts'
|
|
49
49
|
import { SOCIAL_COMMANDS } from './cmd_Social.ts'
|
|
50
50
|
import { MEDIA_COMMANDS } from './cmd_Media.ts'
|
|
51
|
+
import { REC_COMMANDS } from './cmd_Rec.ts'
|
|
52
|
+
import { SignSetupCommand } from './cmd_Sign.ts'
|
|
51
53
|
import { ANNEX_COMMANDS } from './cmd_Annex.ts'
|
|
52
54
|
import { BACKUP_COMMANDS } from './cmd_Backup.ts'
|
|
53
55
|
import { VEILLE_COMMANDS } from './cmd_Veille.ts'
|
|
@@ -97,6 +99,8 @@ export function buildCli(): Cli {
|
|
|
97
99
|
for (const c of REVIEW_COMMANDS) cli.register(c)
|
|
98
100
|
for (const c of SOCIAL_COMMANDS) cli.register(c)
|
|
99
101
|
for (const c of MEDIA_COMMANDS) cli.register(c)
|
|
102
|
+
for (const c of REC_COMMANDS) cli.register(c)
|
|
103
|
+
cli.register(SignSetupCommand)
|
|
100
104
|
for (const c of ANNEX_COMMANDS) cli.register(c)
|
|
101
105
|
for (const c of BACKUP_COMMANDS) cli.register(c)
|
|
102
106
|
for (const c of VEILLE_COMMANDS) cli.register(c)
|
package/src/core/agent-spawn.ts
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
// a string that only MENTIONS claude (a url, `~/.claude/projects`, a help
|
|
7
7
|
// line naming the product) is no spawn, and comments are skipped.
|
|
8
8
|
|
|
9
|
+
import { codeLines } from './code-lines.ts'
|
|
10
|
+
|
|
9
11
|
export type AgentSpawn = { line: number; what: string }
|
|
10
12
|
|
|
11
13
|
const SHAPES: { re: RegExp; what: string }[] = [
|
|
@@ -23,24 +25,9 @@ const SHAPES: { re: RegExp; what: string }[] = [
|
|
|
23
25
|
|
|
24
26
|
/** the first agent spawn in one source text, 1-based line, comments skipped */
|
|
25
27
|
export function agentSpawnIn(src: string): AgentSpawn | null {
|
|
26
|
-
const lines = src
|
|
27
|
-
let inBlock = false
|
|
28
|
+
const lines = codeLines(src)
|
|
28
29
|
for (let i = 0; i < lines.length; i++) {
|
|
29
|
-
|
|
30
|
-
if (inBlock) {
|
|
31
|
-
const end = l.indexOf('*/')
|
|
32
|
-
if (end < 0) continue
|
|
33
|
-
l = l.slice(end + 2)
|
|
34
|
-
inBlock = false
|
|
35
|
-
}
|
|
36
|
-
l = l.replace(/\/\*.*?\*\//g, '')
|
|
37
|
-
const open = l.indexOf('/*')
|
|
38
|
-
if (open >= 0) {
|
|
39
|
-
inBlock = true
|
|
40
|
-
l = l.slice(0, open)
|
|
41
|
-
}
|
|
42
|
-
l = l.replace(/(^|\s)\/\/.*$/, '$1')
|
|
43
|
-
for (const s of SHAPES) if (s.re.test(l)) return { line: i + 1, what: s.what }
|
|
30
|
+
for (const s of SHAPES) if (s.re.test(lines[i]!)) return { line: i + 1, what: s.what }
|
|
44
31
|
}
|
|
45
32
|
return null
|
|
46
33
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// a source text's lines with its comments blanked, one entry per line so a
|
|
2
|
+
// hit keeps its 1-based line number. A static guard reads code, never the
|
|
3
|
+
// comment that names what it forbids. String bodies are kept (a guard reads
|
|
4
|
+
// them) and tracked, so a `/*` or `//` inside a glob or a url opens nothing.
|
|
5
|
+
// A regex literal is told from a division by the token before it (a
|
|
6
|
+
// punctuator or a keyword like `return`); a miss can open a false comment, so
|
|
7
|
+
// a guard that must never go blind also reads the raw line (core/hard-reset.ts).
|
|
8
|
+
|
|
9
|
+
/** what ends the code before a `/` that opens a regex literal rather than a division (empty: the line starts) */
|
|
10
|
+
const REGEX_BEFORE = /(?:^|[(,=:[!&|?{};+\-*%<>~^]|\b(?:return|typeof|case|in|of|yield|await|void|delete|throw|else|do|instanceof|new))$/
|
|
11
|
+
|
|
12
|
+
export function codeLines(src: string): string[] {
|
|
13
|
+
const out: string[] = []
|
|
14
|
+
let state: 'code' | 'block' | 'regex' | "'" | '"' | '`' = 'code'
|
|
15
|
+
let inClass = false
|
|
16
|
+
for (const line of src.split('\n')) {
|
|
17
|
+
if (state === "'" || state === '"' || state === 'regex') state = 'code'
|
|
18
|
+
let kept = ''
|
|
19
|
+
for (let i = 0; i < line.length; i++) {
|
|
20
|
+
const c = line[i]!
|
|
21
|
+
const next = line[i + 1]
|
|
22
|
+
if (state === 'block') {
|
|
23
|
+
if (c === '*' && next === '/') { state = 'code'; i++ }
|
|
24
|
+
continue
|
|
25
|
+
}
|
|
26
|
+
if (state === 'regex') {
|
|
27
|
+
kept += c
|
|
28
|
+
if (c === '\\') { kept += next ?? ''; i++ }
|
|
29
|
+
else if (c === '[') inClass = true
|
|
30
|
+
else if (c === ']') inClass = false
|
|
31
|
+
else if (c === '/' && !inClass) state = 'code'
|
|
32
|
+
continue
|
|
33
|
+
}
|
|
34
|
+
if (state !== 'code') {
|
|
35
|
+
kept += c
|
|
36
|
+
if (c === '\\') { kept += next ?? ''; i++ }
|
|
37
|
+
else if (c === state) state = 'code'
|
|
38
|
+
continue
|
|
39
|
+
}
|
|
40
|
+
if (c === '/' && next === '/') break
|
|
41
|
+
if (c === '/' && next === '*') { state = 'block'; i++; continue }
|
|
42
|
+
if (c === '/' && REGEX_BEFORE.test(kept.trimEnd())) { state = 'regex'; inClass = false; kept += c; continue }
|
|
43
|
+
if (c === "'" || c === '"' || c === '`') state = c
|
|
44
|
+
kept += c
|
|
45
|
+
}
|
|
46
|
+
out.push(kept)
|
|
47
|
+
}
|
|
48
|
+
return out
|
|
49
|
+
}
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
// Skipped dirs: node_modules, dist, tmp, references (templates for other
|
|
19
19
|
// repos), every dot-dir, and the repo's vendored dirs (core/vendored.ts).
|
|
20
20
|
import { RETIRED_CHECK_IDS } from './retired-checks.ts'
|
|
21
|
-
import { readdirSync, readFileSync, realpathSync, statSync } from 'fs'
|
|
22
|
-
import { basename, join, relative } from 'path'
|
|
21
|
+
import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from 'fs'
|
|
22
|
+
import { basename, dirname, join, relative } from 'path'
|
|
23
23
|
import { check, type CheckDef, type CheckFrom } from '../check.ts'
|
|
24
24
|
|
|
25
25
|
import { CHECK_SUFFIX as SUFFIX, fallbackNames, isLegacyCheckSource, SKIPPED_DIRS as IGNORED_DIRS, UNIT_SUFFIX, unitBase } from './check-file-names.ts'
|
|
@@ -237,8 +237,32 @@ export type DiscoverOpts = {
|
|
|
237
237
|
builtinDir?: string
|
|
238
238
|
}
|
|
239
239
|
|
|
240
|
+
/** the nearest folder above `from` (itself included) that holds `marker` */
|
|
241
|
+
function above(from: string, marker: string): string | null {
|
|
242
|
+
for (let d = from; ; d = dirname(d)) {
|
|
243
|
+
if (existsSync(join(d, marker))) return d
|
|
244
|
+
if (dirname(d) === d) return null
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const pkgName = (dir: string): string | null => {
|
|
249
|
+
try { return (JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')) as { name?: string }).name ?? null } catch { return null }
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** the built-ins a root gates with: its own copy of the toolkit when it is a checkout of the toolkit's repo (a
|
|
253
|
+
* release gate's clean worktree of HEAD), at the same place and of the same package; else the running toolkit's */
|
|
254
|
+
export function builtinsOf(root: string, running: string): string {
|
|
255
|
+
const pkg = above(running, 'package.json')
|
|
256
|
+
const repo = pkg && above(pkg, '.git')
|
|
257
|
+
if (!pkg || !repo) return running
|
|
258
|
+
const copy = join(root, relative(repo, running))
|
|
259
|
+
const same = (a: string, b: string): boolean => { try { return realpathSync(a) === realpathSync(b) } catch { return false } }
|
|
260
|
+
if (same(copy, running) || !existsSync(copy) || pkgName(join(root, relative(repo, pkg))) !== pkgName(pkg)) return running
|
|
261
|
+
return copy
|
|
262
|
+
}
|
|
263
|
+
|
|
240
264
|
export async function discoverChecks(root: string, o: DiscoverOpts = {}): Promise<DiscoveredCheck[]> {
|
|
241
|
-
const builtinDir = o.builtinDir ?? BUILTIN_CHECK_DIR
|
|
265
|
+
const builtinDir = builtinsOf(root, o.builtinDir ?? BUILTIN_CHECK_DIR)
|
|
242
266
|
const builtins: string[] = []
|
|
243
267
|
walk(builtinDir, builtins)
|
|
244
268
|
const found: string[] = []
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// HARD RESET, found statically: code that runs or tells someone to run
|
|
2
|
+
// `git reset --hard`. In a tree several sessions share it wipes every one of
|
|
3
|
+
// their edits to tracked files, so the sweep tests (tests/no-hard-reset.test.ts,
|
|
4
|
+
// and the house repo's own) fail on any hit outside core/throwaway-worktree.ts,
|
|
5
|
+
// which wipes only a worktree it proved it made.
|
|
6
|
+
//
|
|
7
|
+
// the other resets (`--soft`, `--keep`, `--merge`, `reset -- <path>`) are
|
|
8
|
+
// not this guard's, and a comment may name the command to forbid it: a hit
|
|
9
|
+
// counts on the comment free line, or on the raw line unless it starts as a
|
|
10
|
+
// comment, so a mistracked comment never hides one.
|
|
11
|
+
import { codeLines } from './code-lines.ts'
|
|
12
|
+
|
|
13
|
+
export type HardReset = { line: number; what: string }
|
|
14
|
+
|
|
15
|
+
const SHAPES: { re: RegExp; what: string }[] = [
|
|
16
|
+
// a command line in a string or a shell script: `git reset --hard`, `reset -q --hard HEAD`, `reset origin/main --hard`
|
|
17
|
+
{ re: /\breset(?:[ \t]+[^\s'"`;|&)]+)*?[ \t]+--hard\b/, what: 'a hard reset command line' },
|
|
18
|
+
// the flag alone as a literal: any argv that carries it, split over lines or held in a const
|
|
19
|
+
{ re: /(['"`])--hard\1/, what: 'a --hard flag literal' },
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
/** every hard reset in one source text, 1-based lines, comments skipped */
|
|
23
|
+
export function hardResetsIn(src: string): HardReset[] {
|
|
24
|
+
const lines = codeLines(src)
|
|
25
|
+
const raw = src.split('\n')
|
|
26
|
+
const hits: HardReset[] = []
|
|
27
|
+
for (let i = 0; i < lines.length; i++) {
|
|
28
|
+
const r = raw[i]!.trimStart()
|
|
29
|
+
const comment = r.startsWith('//') || r.startsWith('*') || r.startsWith('/*')
|
|
30
|
+
const s = SHAPES.find((x) => x.re.test(lines[i]!) || (!comment && x.re.test(raw[i]!)))
|
|
31
|
+
if (s != null) hits.push({ line: i + 1, what: s.what })
|
|
32
|
+
}
|
|
33
|
+
return hits
|
|
34
|
+
}
|
package/src/core/raw-access.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { readFileSync } from 'fs'
|
|
|
10
10
|
import { join, relative } from 'path'
|
|
11
11
|
import { loadConfig, type RvtConfig } from '../ts/config.ts'
|
|
12
12
|
import { importClosure } from '../ts/source-graph.ts'
|
|
13
|
+
import { codeLines } from './code-lines.ts'
|
|
13
14
|
|
|
14
15
|
/** where a module reaches the disk or a process around the check context */
|
|
15
16
|
export type RawAccess = { file: string; line: number; what: string }
|
|
@@ -44,20 +45,9 @@ const HITS_MEMO_MAX = 4000
|
|
|
44
45
|
|
|
45
46
|
function scanSource(src: string, o: ClosureKind): { line: number; what: string } | null {
|
|
46
47
|
const SHAPES = [o.dynamic === false ? STATIC_IMPORTS : IMPORTS, CALLS]
|
|
47
|
-
const lines = src
|
|
48
|
-
let inBlock = false
|
|
48
|
+
const lines = codeLines(src)
|
|
49
49
|
for (let i = 0; i < lines.length; i++) {
|
|
50
|
-
|
|
51
|
-
if (inBlock) {
|
|
52
|
-
const end = l.indexOf('*/')
|
|
53
|
-
if (end < 0) continue
|
|
54
|
-
l = l.slice(end + 2)
|
|
55
|
-
inBlock = false
|
|
56
|
-
}
|
|
57
|
-
l = l.replace(/\/\*.*?\*\//g, '')
|
|
58
|
-
const open = l.indexOf('/*')
|
|
59
|
-
if (open >= 0) { inBlock = true; l = l.slice(0, open) }
|
|
60
|
-
l = l.replace(/(^|\s)\/\/.*$/, '$1')
|
|
50
|
+
const l = lines[i]!
|
|
61
51
|
if (/^\s*import\s+type\b/.test(l)) continue
|
|
62
52
|
for (const s of SHAPES) {
|
|
63
53
|
const m = l.match(s.re)
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// a throwaway checkout of a repo's commit: a linked worktree under the temp
|
|
2
|
+
// dir, kept between runs and brought back to the commit asked for, so a build
|
|
3
|
+
// or a gate writes only what changed. Every other tree may hold someone's
|
|
4
|
+
// unsaved work, so this module is the ONE place a working tree is wiped to a
|
|
5
|
+
// commit (tests/no-hard-reset.test.ts allows it here only), and it wipes only
|
|
6
|
+
// a folder it can prove it made: a linked worktree of that repo, at the path
|
|
7
|
+
// this module derives, carrying the mark it wrote into the worktree's own git
|
|
8
|
+
// dir. Anything else at that path is refused and left as it is.
|
|
9
|
+
import { existsSync, lstatSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'fs'
|
|
10
|
+
import { tmpdir } from 'os'
|
|
11
|
+
import { join } from 'path'
|
|
12
|
+
import { gitBin } from './git-bin.ts'
|
|
13
|
+
|
|
14
|
+
const git = (cwd: string, args: string[]): { code: number; out: string } => {
|
|
15
|
+
const p = Bun.spawnSync([gitBin(), ...args], { cwd, stdout: 'pipe', stderr: 'pipe' })
|
|
16
|
+
return { code: p.exitCode, out: `${p.stdout.toString()}${p.stderr.toString()}`.trim() }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const MARK = 'shipkit-throwaway'
|
|
20
|
+
|
|
21
|
+
/** where `repo`'s throwaway checkout for `purpose` lives: one per checkout of a repo and purpose */
|
|
22
|
+
export function throwawayDir(repo: string, purpose: string): string {
|
|
23
|
+
const hash = new Bun.CryptoHasher('sha256').update(realpathSync(repo)).digest('hex').slice(0, 10)
|
|
24
|
+
return join(realpathSync(tmpdir()), `shipkit-throwaway-${purpose}-${hash}`)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** the git dir of `dir` when it is a linked worktree of `repo` carrying this module's mark, else why not */
|
|
28
|
+
function ownGitDir(repo: string, dir: string): { gitDir: string } | { refuse: string } {
|
|
29
|
+
const dotGit = join(dir, '.git')
|
|
30
|
+
if (!existsSync(dotGit) || !lstatSync(dotGit).isFile()) return { refuse: 'it is not a linked worktree' }
|
|
31
|
+
const r = git(dir, ['rev-parse', '--path-format=absolute', '--show-toplevel', '--git-dir', '--git-common-dir'])
|
|
32
|
+
const [top, gitDir, common] = r.out.split('\n')
|
|
33
|
+
if (r.code !== 0 || top == null || gitDir == null || common == null) return { refuse: `git cannot read it (${r.out.split('\n')[0]})` }
|
|
34
|
+
const repoCommon = git(repo, ['rev-parse', '--path-format=absolute', '--git-common-dir']).out
|
|
35
|
+
const real = (p: string): string => { try { return realpathSync(p) } catch { return p } }
|
|
36
|
+
if (real(top) !== real(dir)) return { refuse: `its checkout is ${top}` }
|
|
37
|
+
if (real(gitDir) === real(common)) return { refuse: 'it is a main worktree' }
|
|
38
|
+
if (real(common) !== real(repoCommon)) return { refuse: `it belongs to the repo at ${common}` }
|
|
39
|
+
const mark = join(gitDir, MARK)
|
|
40
|
+
if (!existsSync(mark) || readFileSync(mark, 'utf8') !== real(dir)) return { refuse: 'shipkit did not make it' }
|
|
41
|
+
return { gitDir }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** `repo` at `sha` in its throwaway checkout for `purpose`, every untracked and ignored file removed:
|
|
45
|
+
* made when absent, brought back when it is one this module made, refused when anything else holds the path */
|
|
46
|
+
export function throwawayCheckout(repo: string, purpose: string, sha: string): { dir: string } | { error: string } {
|
|
47
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(purpose)) return { error: `throwaway purpose '${purpose}': lowercase letters, digits and dashes only` }
|
|
48
|
+
const dir = throwawayDir(repo, purpose)
|
|
49
|
+
if (existsSync(dir)) {
|
|
50
|
+
const own = ownGitDir(repo, dir)
|
|
51
|
+
if ('refuse' in own) return { error: `${dir} exists and is not a throwaway checkout shipkit made (${own.refuse}), so nothing in it was touched. fix: move it away (mv ${dir} ${dir}.old), then run again` }
|
|
52
|
+
// the only reset of a working tree to a commit in this toolkit: a proven throwaway
|
|
53
|
+
const back = git(dir, ['reset', '--hard', '--quiet', sha])
|
|
54
|
+
if (back.code !== 0) {
|
|
55
|
+
rmSync(dir, { recursive: true, force: true })
|
|
56
|
+
git(repo, ['worktree', 'prune'])
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (!existsSync(dir)) {
|
|
60
|
+
git(repo, ['worktree', 'prune'])
|
|
61
|
+
const add = git(repo, ['worktree', 'add', '--detach', '--quiet', dir, sha])
|
|
62
|
+
if (add.code !== 0) return { error: `cannot make the throwaway checkout at ${dir}: ${add.out}` }
|
|
63
|
+
const gitDir = git(dir, ['rev-parse', '--path-format=absolute', '--git-dir'])
|
|
64
|
+
if (gitDir.code !== 0) return { error: `cannot read the git dir of ${dir}: ${gitDir.out}` }
|
|
65
|
+
writeFileSync(join(gitDir.out, MARK), realpathSync(dir))
|
|
66
|
+
const own = ownGitDir(repo, dir)
|
|
67
|
+
if ('refuse' in own) return { error: `the throwaway checkout at ${dir} fails its own proof (${own.refuse})` }
|
|
68
|
+
}
|
|
69
|
+
const clean = git(dir, ['clean', '-ffdxq'])
|
|
70
|
+
if (clean.code !== 0) return { error: `cannot clean the throwaway checkout at ${dir}: ${clean.out}` }
|
|
71
|
+
return { dir }
|
|
72
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// the machine's own code signing identity for shipkit's apps (wiki tools/shipkit/home-pages.md, Signing): an ad hoc
|
|
2
|
+
// signature names the binary's hash, so macOS forgets a permission (Screen Recording, Accessibility) at every rebuild;
|
|
3
|
+
// an identity's certificate names the app across rebuilds. Made once by `sk sign-setup`: a self signed code signing
|
|
4
|
+
// certificate in a keychain of its own, its random password kept in the login keychain (never in a file), trusted
|
|
5
|
+
// for code signing by the owner's one password prompt. Absent or not trusted: the apps stay ad hoc, said once
|
|
6
|
+
import { existsSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
7
|
+
import { tmpdir } from 'node:os'
|
|
8
|
+
import { join } from 'node:path'
|
|
9
|
+
import { homeDir } from './home-paths.ts'
|
|
10
|
+
|
|
11
|
+
export const SIGN_NAME = 'Shipkit Local Signing'
|
|
12
|
+
const PW_SERVICE = 'shipkit-signing-keychain'
|
|
13
|
+
export const signingKeychain = (): string => process.env.SHIPKIT_SIGNING_KEYCHAIN ?? join(homeDir(), 'signing.keychain-db')
|
|
14
|
+
|
|
15
|
+
type Run = (cmd: string[], o?: { stdin?: string }) => { code: number; out: string; err: string }
|
|
16
|
+
const run: Run = (cmd, o = {}) => {
|
|
17
|
+
const p = Bun.spawnSync(cmd, { stdout: 'pipe', stderr: 'pipe', ...(o.stdin !== undefined ? { stdin: Buffer.from(o.stdin) } : {}) })
|
|
18
|
+
return { code: p.exitCode ?? 1, out: p.stdout.toString(), err: p.stderr.toString().trim() }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const password = (r: Run = run): string | null => {
|
|
22
|
+
const p = r(['security', 'find-generic-password', '-s', PW_SERVICE, '-a', 'shipkit', '-w'])
|
|
23
|
+
return p.code === 0 ? p.out.trim() : null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** the signing keychain in the user's search list: codesign finds an identity only there, `--keychain` or not */
|
|
27
|
+
function listed(kc: string, r: Run): void {
|
|
28
|
+
const now = r(['security', 'list-keychains', '-d', 'user']).out.split('\n').map((l) => l.trim().replace(/^"|"$/g, '')).filter((l) => l !== '')
|
|
29
|
+
if (now.includes(kc)) return
|
|
30
|
+
r(['security', 'list-keychains', '-d', 'user', '-s', ...now, kc])
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** the identity's SHA-1 when it is there and trusted for code signing, its keychain unlocked; null otherwise */
|
|
34
|
+
export function signingIdentity(r: Run = run): string | null {
|
|
35
|
+
const kc = signingKeychain()
|
|
36
|
+
if (process.platform !== 'darwin' || !existsSync(kc)) return null
|
|
37
|
+
const pw = password(r)
|
|
38
|
+
if (pw === null) return null
|
|
39
|
+
// a keychain locks at a restart: opened again with its own password
|
|
40
|
+
r(['security', 'unlock-keychain', '-p', pw, kc])
|
|
41
|
+
listed(kc, r)
|
|
42
|
+
const v = r(['security', 'find-identity', '-v', '-p', 'codesigning', kc])
|
|
43
|
+
return new RegExp(`([0-9A-F]{40}) "${SIGN_NAME}"`).exec(v.out)?.[1] ?? null
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** the codesign arguments of a bundle: the identity when there is one, else ad hoc */
|
|
47
|
+
export function signArgs(r: Run = run): string[] {
|
|
48
|
+
const id = signingIdentity(r)
|
|
49
|
+
return id ? ['--sign', id, '--keychain', signingKeychain()] : ['--sign', '-']
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** the identity made and trusted: the trust step shows the owner macOS's own password prompt. Idempotent */
|
|
53
|
+
export function setupSigning(say: (l: string) => void, r: Run = run): void {
|
|
54
|
+
if (process.platform !== 'darwin') throw new Error('signing is macOS only')
|
|
55
|
+
if (signingIdentity(r)) {
|
|
56
|
+
say(`ok: ${SIGN_NAME} is set up and trusted (${signingKeychain()})`)
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
const kc = signingKeychain()
|
|
60
|
+
const tmp = mkdtempSync(join(tmpdir(), 'shipkit-sign-'))
|
|
61
|
+
try {
|
|
62
|
+
let pw = password(r)
|
|
63
|
+
if (!existsSync(kc)) {
|
|
64
|
+
pw = crypto.randomUUID() + crypto.randomUUID()
|
|
65
|
+
const kept = r(['security', 'add-generic-password', '-U', '-s', PW_SERVICE, '-a', 'shipkit', '-w', pw])
|
|
66
|
+
if (kept.code !== 0) throw new Error(`the login keychain did not keep the password: ${kept.err}`)
|
|
67
|
+
const cfg = ['[req]', 'distinguished_name=dn', 'x509_extensions=ext', 'prompt=no', '[dn]', `CN=${SIGN_NAME}`, '[ext]', 'basicConstraints=critical,CA:false', 'keyUsage=critical,digitalSignature', 'extendedKeyUsage=critical,codeSigning'].join('\n')
|
|
68
|
+
writeFileSync(join(tmp, 'cfg'), cfg)
|
|
69
|
+
const steps: string[][] = [
|
|
70
|
+
['openssl', 'req', '-x509', '-newkey', 'rsa:2048', '-nodes', '-keyout', join(tmp, 'k.pem'), '-out', join(tmp, 'c.pem'), '-days', '3650', '-config', join(tmp, 'cfg')],
|
|
71
|
+
['openssl', 'pkcs12', '-export', '-legacy', '-inkey', join(tmp, 'k.pem'), '-in', join(tmp, 'c.pem'), '-out', join(tmp, 'id.p12'), '-passout', 'pass:shipkit'],
|
|
72
|
+
['security', 'create-keychain', '-p', pw, kc],
|
|
73
|
+
// no lock on a timer: codesign runs whenever an app is rebuilt
|
|
74
|
+
['security', 'set-keychain-settings', kc],
|
|
75
|
+
['security', 'unlock-keychain', '-p', pw, kc],
|
|
76
|
+
['security', 'import', join(tmp, 'id.p12'), '-k', kc, '-P', 'shipkit', '-T', '/usr/bin/codesign'],
|
|
77
|
+
['security', 'set-key-partition-list', '-S', 'apple-tool:,apple:,codesign:', '-s', '-k', pw, kc],
|
|
78
|
+
]
|
|
79
|
+
for (const s of steps) {
|
|
80
|
+
const res = r(s)
|
|
81
|
+
if (res.code !== 0) throw new Error(`${s.slice(0, 2).join(' ')}: ${res.err.slice(0, 300)}`)
|
|
82
|
+
}
|
|
83
|
+
say(`ok: ${SIGN_NAME} made in ${kc}`)
|
|
84
|
+
} else if (pw === null) throw new Error(`${kc} exists, its password is not in the login keychain: delete ${kc} and run again`)
|
|
85
|
+
// the certificate as the keychain holds it, trusted for code signing in the owner's own trust settings
|
|
86
|
+
const cert = r(['security', 'find-certificate', '-c', SIGN_NAME, '-p', kc])
|
|
87
|
+
if (cert.code !== 0) throw new Error(`no certificate ${SIGN_NAME} in ${kc}: ${cert.err}`)
|
|
88
|
+
writeFileSync(join(tmp, 'trust.pem'), cert.out)
|
|
89
|
+
say('macOS asks for your password once now, to trust it for code signing…')
|
|
90
|
+
const t = r(['security', 'add-trusted-cert', '-r', 'trustRoot', '-p', 'codeSign', join(tmp, 'trust.pem')])
|
|
91
|
+
if (t.code !== 0) throw new Error(`the trust was not given: ${t.err || `exit ${t.code}`}`)
|
|
92
|
+
const id = signingIdentity(r)
|
|
93
|
+
if (!id) throw new Error(`${SIGN_NAME} is still not valid for code signing`)
|
|
94
|
+
say(`ok: ${SIGN_NAME} trusted (${id.slice(0, 12)}): shipkit's apps keep their permissions across rebuilds`)
|
|
95
|
+
} finally {
|
|
96
|
+
rmSync(tmp, { recursive: true, force: true })
|
|
97
|
+
}
|
|
98
|
+
}
|