rvlib-shipkit 2.24.0 → 2.25.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.
Files changed (81) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/package.json +1 -1
  3. package/src/agent-time/live.ts +153 -0
  4. package/src/annex/offload.ts +16 -7
  5. package/src/check.ts +3 -1
  6. package/src/checks/SK004-gitignore-policy.check.ts +32 -11
  7. package/src/checks/SK027-agent-wiki-links.check.ts +1 -1
  8. package/src/checks/SK033-global-contribution.check.ts +1 -1
  9. package/src/checks/SK036-draft-media-size.check.ts +1 -1
  10. package/src/checks/SK040-release-words.check.ts +1 -1
  11. package/src/checks/SK042-post-kinds.check.ts +1 -1
  12. package/src/cli/cmd_Annex.ts +12 -7
  13. package/src/cli/cmd_Assets.ts +5 -5
  14. package/src/cli/cmd_Backup.ts +11 -5
  15. package/src/cli/cmd_Capacity.ts +10 -6
  16. package/src/cli/cmd_Checks.ts +12 -1
  17. package/src/cli/cmd_Ci.ts +2 -2
  18. package/src/cli/cmd_Commands.ts +11 -2
  19. package/src/cli/cmd_ConfigKeys.ts +17 -0
  20. package/src/cli/cmd_Home.ts +1 -1
  21. package/src/cli/cmd_Keys.ts +4 -1
  22. package/src/cli/cmd_Lanes.ts +35 -0
  23. package/src/cli/cmd_Mv.ts +6 -7
  24. package/src/cli/cmd_Rec.ts +22 -7
  25. package/src/cli/cmd_Review.ts +107 -39
  26. package/src/cli/cmd_Shot.ts +15 -4
  27. package/src/cli/cmd_Status.ts +6 -5
  28. package/src/cli/cmd_Time.ts +10 -4
  29. package/src/cli/cmd_Veille.ts +10 -6
  30. package/src/cli/family-help.ts +136 -0
  31. package/src/cli/family-pages.ts +0 -19
  32. package/src/cli/kit/calls.ts +35 -0
  33. package/src/cli/kit/project-cli.ts +2 -12
  34. package/src/cli/registry.ts +39 -6
  35. package/src/cli.ts +8 -4
  36. package/src/core/capacity.ts +89 -33
  37. package/src/core/check-runner.ts +5 -1
  38. package/src/core/floor-resolve.ts +6 -2
  39. package/src/core/floor.ts +6 -2
  40. package/src/core/history-files.ts +18 -0
  41. package/src/core/jobs.ts +35 -16
  42. package/src/core/layout.ts +2 -2
  43. package/src/core/nearest.ts +16 -0
  44. package/src/core/remove-tree.ts +19 -0
  45. package/src/core/runs.ts +12 -3
  46. package/src/core/throwaway-worktree.ts +22 -4
  47. package/src/core/trace-audit.ts +17 -4
  48. package/src/home/daemon-jobs.ts +41 -4
  49. package/src/home/machine-temp.ts +2 -10
  50. package/src/ledger/gate-checks.ts +3 -2
  51. package/src/ledger/git-key.ts +25 -4
  52. package/src/ledger/git-scan.ts +10 -0
  53. package/src/media-store/backup/daemon.ts +92 -20
  54. package/src/media-store/backup/run.ts +21 -15
  55. package/src/media-store/backup/sources.ts +166 -21
  56. package/src/media-store/backup/watch.ts +106 -0
  57. package/src/media-store/daemon.ts +36 -8
  58. package/src/media-store/hand.ts +3 -1
  59. package/src/mv/mv-md.ts +50 -18
  60. package/src/pb/run-pb.ts +2 -10
  61. package/src/plan/repo-source.ts +25 -14
  62. package/src/recordings/model.ts +1 -1
  63. package/src/release/run-bump.ts +3 -2
  64. package/src/release/run-release.ts +12 -4
  65. package/src/review/cells.ts +2 -1
  66. package/src/review/format.ts +1 -1
  67. package/src/review/model.ts +14 -1
  68. package/src/review/store.ts +15 -7
  69. package/src/review/trailer-model.ts +2 -2
  70. package/src/shot/client.ts +4 -2
  71. package/src/shot/serve-shot.ts +71 -2
  72. package/src/shot/shooter.ts +65 -11
  73. package/src/shot/shot-ask.ts +32 -9
  74. package/src/suite/select.ts +13 -2
  75. package/src/suite/test-units.ts +31 -12
  76. package/src/trailer/graph.ts +2 -1
  77. package/src/ts/config.ts +12 -35
  78. package/src/ts/rename.ts +31 -17
  79. package/src/ts/workspaces.ts +45 -0
  80. package/src/wiki/run-wiki.ts +7 -2
  81. package/src/wiki/scan-md.ts +2 -1
package/src/ts/rename.ts CHANGED
@@ -12,13 +12,16 @@
12
12
  // file -> path ending with / same, creates folder if missing
13
13
  // folder -> folder path renames the folder (recursive replacement)
14
14
  import { existsSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from 'fs'
15
+ import { isHistoryFile } from '../core/history-files.ts'
15
16
  import { basename, dirname, extname, join, relative, resolve } from 'path'
16
17
  import { canonicalSpecifier, isSkipped, loadConfig, toPosix, type RvtConfig } from 'rvlib-shipkit/src/ts/config.ts'
17
18
  import { extractSpecs } from 'rvlib-shipkit/src/ts/source-graph.ts'
18
19
  import { gitBin } from '../core/git-bin.ts'
19
- import { retargetRelativeRefs } from '../mv/mv-md.ts'
20
+ import { namesMoved, retargetRelativeRefs } from '../mv/mv-md.ts'
20
21
 
21
22
  const CODE_RE = /\.[cm]?[jt]sx?$/
23
+ /** the overreach warnings a dry run prints: a common stem (`index`) names a thousand files */
24
+ const SHOWN = 12
22
25
 
23
26
  const BINARY_EXTS = new Set([
24
27
  '.png', '.jpg', '.jpeg', '.gif', '.webp', '.ico', '.bmp', '.tiff',
@@ -56,9 +59,11 @@ export type RenameResult = {
56
59
  totalRefs: number
57
60
  suspicious: string[]
58
61
  applied: boolean
62
+ /** plans, changelogs and journals that name the path and stay as written */
63
+ left: number
59
64
  }
60
65
 
61
- export function runRename(srcArg: string, dstArg: string, opts: { apply?: boolean; cfg?: RvtConfig } = {}): RenameResult {
66
+ export function runRename(srcArg: string, dstArg: string, opts: { apply?: boolean; cfg?: RvtConfig; /** rewrite the plans, changelogs and journals too */ history?: boolean } = {}): RenameResult {
62
67
  const cfg = opts.cfg ?? loadConfig()
63
68
  const repoRoot = cfg.root
64
69
 
@@ -113,11 +118,11 @@ export function runRename(srcArg: string, dstArg: string, opts: { apply?: boolea
113
118
  const rewriteFile = (file: string, content: string): { text: string; count: number } => {
114
119
  if (file.endsWith('.md')) {
115
120
  const linked = retargetRelativeRefs(repoRoot, content, dirOf(file), dirOf(movedTo(file) ?? file), mdMoves)
116
- const scanned = scanPairs(linked, pairs)
121
+ const scanned = scanPairs(linked, pairs, { carrierDir: dirOf(file), root: repoRoot })
117
122
  return { text: scanned.text, count: scanned.count + (linked === content ? 0 : 1) }
118
123
  }
119
124
  const rel = CODE_RE.test(file) ? relativeRewrites(file, content, movedTo, isFile) : new Map<string, string>()
120
- if (rel.size === 0) return scanPairs(content, pairs)
125
+ if (rel.size === 0) return scanPairs(content, pairs, { carrierDir: dirOf(file), root: repoRoot })
121
126
  // the relative specifiers this move retargets are set aside while the
122
127
  // path scan runs, so the two rewrites can never compound on one string
123
128
  let masked = content
@@ -132,7 +137,7 @@ export function runRename(srcArg: string, dstArg: string, opts: { apply?: boolea
132
137
  holes.push(`${q}${to}${q}`)
133
138
  }
134
139
  }
135
- const scanned = scanPairs(masked, pairs)
140
+ const scanned = scanPairs(masked, pairs, { carrierDir: dirOf(file), root: repoRoot })
136
141
  let text = scanned.text
137
142
  holes.forEach((h, i) => { text = text.split(`\u0000mv${i}\u0000`).join(h) })
138
143
  return { text, count: scanned.count + relCount }
@@ -140,6 +145,7 @@ export function runRename(srcArg: string, dstArg: string, opts: { apply?: boolea
140
145
 
141
146
  const hits: { file: string; count: number }[] = []
142
147
  let totalRefs = 0
148
+ let left = 0
143
149
  for (const file of allFiles) {
144
150
  if (isSkipped(file, cfg, pkgDirs)) continue
145
151
  if (BINARY_EXTS.has(extname(file).toLowerCase())) continue
@@ -152,6 +158,8 @@ export function runRename(srcArg: string, dstArg: string, opts: { apply?: boolea
152
158
  const nul = content.indexOf('\u0000')
153
159
  if (nul !== -1 && nul < 4096) continue // cheap binary sniff
154
160
  const count = rewriteFile(file, content).count
161
+ // a record of what was true stays as written, unless it is itself what moves
162
+ if (count > 0 && opts.history !== true && isHistoryFile(file) && movedTo(file) == null) { left++; continue }
155
163
  if (count > 0) {
156
164
  hits.push({ file, count })
157
165
  totalRefs += count
@@ -191,10 +199,11 @@ export function runRename(srcArg: string, dstArg: string, opts: { apply?: boolea
191
199
  if (mv.exitCode !== 0) renameSync(srcAbs, dstAbs) // untracked file: plain fs move
192
200
  }
193
201
 
194
- return { srcRel, dstRel, isFolder: srcIsFolder, hits, totalRefs, suspicious, applied: opts.apply === true }
202
+ return { srcRel, dstRel, isFolder: srcIsFolder, hits, totalRefs, suspicious, applied: opts.apply === true, left }
195
203
  }
196
204
 
197
- export function renameCli(argv: string[]): number {
205
+ /** `applyFlag`: the flag the caller's own cli applies with, named by the dry run's last line */
206
+ export function renameCli(argv: string[], applyFlag = '-x or --apply'): number {
198
207
  const apply = argv.includes('-x') || argv.includes('--apply')
199
208
  const paths = argv.filter((a) => !a.startsWith('-'))
200
209
  if (paths.length !== 2) {
@@ -203,7 +212,7 @@ export function renameCli(argv: string[]): number {
203
212
  }
204
213
  let r: RenameResult
205
214
  try {
206
- r = runRename(paths[0]!, paths[1]!, { apply })
215
+ r = runRename(paths[0]!, paths[1]!, { apply, history: argv.includes('--history') })
207
216
  } catch (e) {
208
217
  console.error(String(e instanceof Error ? e.message : e))
209
218
  return 1
@@ -212,11 +221,13 @@ export function renameCli(argv: string[]): number {
212
221
  console.log(`type: ${r.isFolder ? 'folder (recursive)' : 'file'}`)
213
222
  console.log(`refs: ${r.totalRefs} across ${r.hits.length} file(s)`)
214
223
  for (const h of r.hits) console.log(` ${h.count.toString().padStart(4)} ${h.file}`)
224
+ if (r.left > 0) console.log(`left as written: ${r.left} plan, changelog or journal file(s) that name it (--history rewrites them too)`)
215
225
  if (r.suspicious.length > 0) {
216
- console.log('\nwarning: possible substring overreach (inspect before applying):')
217
- for (const s of r.suspicious) console.log(` ${s}`)
226
+ console.log(`\nwarning: ${r.suspicious.length} possible substring overreach (inspect before applying):`)
227
+ for (const s of r.suspicious.slice(0, SHOWN)) console.log(` ${s}`)
228
+ if (r.suspicious.length > SHOWN) console.log(` … ${r.suspicious.length - SHOWN} more of the same kind`)
218
229
  }
219
- if (!r.applied) console.log('\ndry-run. pass -x or --apply to commit.')
230
+ if (!r.applied) console.log(`\ndry run: pass ${applyFlag} to apply.`)
220
231
  else console.log(`\napplied: ${r.srcRel} -> ${r.dstRel} (${r.totalRefs} refs rewritten)`)
221
232
  return 0
222
233
  }
@@ -251,12 +262,15 @@ function relativeRewrites(file: string, content: string, movedTo: (rel: string)
251
262
  return out
252
263
  }
253
264
 
254
- /** the next occurrence of a path that ENDS there: `server/staged` inside
255
- * `server/staged.ts` or `server/staged-x` names another file, never the folder */
256
- function pathAt(text: string, needle: string, from: number): number {
265
+ /** where a path is read: the carrier's folder resolves a relative prefix, the root an absolute one */
266
+ type At = { carrierDir: string; root: string }
267
+
268
+ /** the next occurrence of a path that ENDS there and STARTS there: `server/staged` inside `server/staged.ts` or
269
+ * `server/staged-x`, and `src/a.ts` inside `packages/p/src/a.ts`, name another file */
270
+ function pathAt(text: string, needle: string, from: number, where: At): number {
257
271
  for (let idx = text.indexOf(needle, from); idx !== -1; idx = text.indexOf(needle, idx + 1)) {
258
272
  const next = text.slice(idx + needle.length, idx + needle.length + 2)
259
- if (!/^[\w-]/.test(next) && !/^\.\w/.test(next)) return idx
273
+ if (!/^[\w-]/.test(next) && !/^\.\w/.test(next) && namesMoved(text, idx, needle, needle, where.carrierDir, where.root)) return idx
260
274
  }
261
275
  return -1
262
276
  }
@@ -265,7 +279,7 @@ function pathAt(text: string, needle: string, from: number): number {
265
279
  // tie) and the scan continues PAST the replacement — sequential split/join
266
280
  // would let one pair's output feed the next (the package form is a substring
267
281
  // of the repo form, so that corrupts content)
268
- function scanPairs(text: string, pairs: { from: string; to: string }[]): { text: string; count: number } {
282
+ function scanPairs(text: string, pairs: { from: string; to: string }[], where: At): { text: string; count: number } {
269
283
  let out = ''
270
284
  let i = 0
271
285
  let count = 0
@@ -274,7 +288,7 @@ function scanPairs(text: string, pairs: { from: string; to: string }[]): { text:
274
288
  let hit: { from: string; to: string } | null = null
275
289
  for (const p of pairs) {
276
290
  if (p.from.length === 0) continue
277
- const idx = pathAt(text, p.from, i)
291
+ const idx = pathAt(text, p.from, i, where)
278
292
  if (idx === -1) continue
279
293
  if (at === -1 || idx < at || (idx === at && p.from.length > (hit?.from.length ?? 0))) {
280
294
  at = idx
@@ -0,0 +1,45 @@
1
+ // the package.json `workspaces`, expanded through a reader and never the disk:
2
+ // a check's floor resolution reaches this module, and a check reads only
3
+ // through its context, so nothing here may import fs.
4
+ import { isVendored } from '../core/vendored.ts'
5
+
6
+ export type WorkspacePackage = { name: string; dir: string; exports?: unknown }
7
+
8
+ /** the package.json `workspaces` through a reader: `read` answers a repo-relative file, `subdirs`
9
+ * the dir names directly inside a repo-relative dir ('' is the root). A check
10
+ * hands it its context, so the answer stays keyed on what it read */
11
+ export function workspacePackagesOf(read: (rel: string) => string | null, subdirs: (rel: string) => string[], vendored: readonly string[] = []): WorkspacePackage[] {
12
+ let globs: string[] = []
13
+ try {
14
+ const w = (JSON.parse(read('package.json') ?? '') as { workspaces?: string[] | { packages?: string[] } }).workspaces
15
+ globs = Array.isArray(w) ? w : w?.packages ?? []
16
+ } catch {
17
+ return []
18
+ }
19
+ const dirs = (pattern: string): string[] => {
20
+ let at = ['']
21
+ for (const seg of pattern.replace(/^\.\//, '').replace(/\/+$/, '').split('/')) {
22
+ if (!seg.includes('*')) {
23
+ at = at.map((d) => (d === '' ? seg : `${d}/${seg}`))
24
+ continue
25
+ }
26
+ const re = new RegExp(`^${seg.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*')}$`)
27
+ at = at.flatMap((d) => subdirs(d).filter((n) => re.test(n)).map((n) => (d === '' ? n : `${d}/${n}`)))
28
+ }
29
+ return at
30
+ }
31
+ const out: WorkspacePackage[] = []
32
+ for (const g of globs) {
33
+ if (g.startsWith('!')) continue
34
+ for (const dir of dirs(g)) {
35
+ if (isVendored(dir, vendored)) continue
36
+ try {
37
+ const m = JSON.parse(read(`${dir}/package.json`) ?? '') as { name?: string; exports?: unknown }
38
+ if (m.name != null && m.name !== '') out.push({ name: m.name, dir, ...(m.exports !== undefined ? { exports: m.exports } : {}) })
39
+ } catch {
40
+ // no named manifest: not a package
41
+ }
42
+ }
43
+ }
44
+ return out
45
+ }
@@ -2,6 +2,7 @@
2
2
  // lib; that npm package is frozen). Plain modules behind cmd_Wiki —
3
3
  // clipanion owns the option parsing.
4
4
  import { existsSync } from 'fs'
5
+ import { isHistoryFile, onceAPath } from '../core/history-files.ts'
5
6
  import { basename, join, relative, resolve } from 'path'
6
7
  import { agentDirAt, contributionFileAt } from '../core/agent-dir-at.ts'
7
8
  import { lintMd } from './lint-md.ts'
@@ -68,9 +69,13 @@ export function runWikiLint(o: WikiScanOpts): number {
68
69
  : `FAIL no entrypoint: neither index.md nor README.md in ${cfg.root} — pass --index <entry.md>`)
69
70
  return 1
70
71
  }
72
+ // a changelog or a journal names what was true then: a path that is gone holds when git once had it
73
+ const dangling = r.dangling.filter((d) => !(isHistoryFile(d.from) && onceAPath(cfg.root, d.token)))
74
+ const held = r.dangling.length - dangling.length
71
75
  for (const f of r.orphans) say(`FAIL orphan: ${f} — unreachable from ${r.index}; link it or delete it`)
72
- for (const d of r.dangling) say(`FAIL dangling: ${d.from} → ${d.token} — target not found`)
73
- if (!r.ok) { say(`FAIL mdwiki lint: ${r.orphans.length} orphan(s), ${r.dangling.length} dangling ref(s) in ${cfg.root}`); return 1 }
76
+ for (const d of dangling) say(`FAIL dangling: ${d.from} → ${d.token} — target not found`)
77
+ if (r.orphans.length > 0 || dangling.length > 0) { say(`FAIL mdwiki lint: ${r.orphans.length} orphan(s), ${dangling.length} dangling ref(s) in ${cfg.root}`); return 1 }
78
+ if (held > 0) say(`ok ${held} ref(s) of a changelog or journal name a path git once held: left as written`)
74
79
  say(`ok mdwiki lint: ${r.files} files, all reachable from ${r.index}, no dangling refs`)
75
80
  return 0
76
81
  }
@@ -122,7 +122,8 @@ function scanMdNow(cfg: ScanMdConfig): MdScan {
122
122
  }
123
123
  for (const m of prose.matchAll(/(?:^|[\s(])@((?:\.{1,2}\/)*[\w][\w./-]*\.md)/gm)) push(m[1]!, true, true, lineOf(m))
124
124
  for (const m of prose.matchAll(/→\s*([\w][\w./-]*\.md)\b/g)) push(m[1]!, false, true, lineOf(m))
125
- for (const m of prose.matchAll(/\]\(([^)\s:]+\.md)\)/g)) push(m[1]!, false, true, lineOf(m))
125
+ // an anchor or a title never changes the page a link reaches
126
+ for (const m of prose.matchAll(/\]\(([^)\s:#]+\.md)(?:#[^)\s]*)?(?:\s+"[^"]*")?\)/g)) push(m[1]!, false, true, lineOf(m))
126
127
  for (const m of prose.matchAll(/\]\(([^)\s:]*\/)\)/g)) push(m[1]!, false, true, lineOf(m))
127
128
  for (const s of spans) for (const m of s.matchAll(/[\w][\w./-]*\.md/g)) push(m[0], false, false)
128
129
  for (const s of spans) for (const m of s.matchAll(/(?:^|\s)([\w.][\w./-]*\/)(?=$|[\s<*])/g)) push(m[1]!, false, false)