rvlib-shipkit 2.23.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.
- package/CHANGELOG.md +45 -0
- package/package.json +1 -1
- package/src/agent-time/live.ts +153 -0
- package/src/agent-time/render.ts +28 -14
- package/src/agent-time/report.ts +46 -25
- package/src/agent-time/store.ts +30 -10
- package/src/agent-time/timeline.ts +43 -15
- package/src/annex/offload.ts +16 -7
- package/src/asks/asks-queue.ts +32 -11
- package/src/check.ts +3 -1
- package/src/checks/SK004-gitignore-policy.check.ts +32 -11
- package/src/checks/SK027-agent-wiki-links.check.ts +1 -1
- package/src/checks/SK033-global-contribution.check.ts +1 -1
- package/src/checks/SK036-draft-media-size.check.ts +1 -1
- package/src/checks/SK040-release-words.check.ts +1 -1
- package/src/checks/SK042-post-kinds.check.ts +1 -1
- package/src/checks/SK044-behind-upstream.check.ts +38 -0
- package/src/cli/cmd_Annex.ts +12 -7
- package/src/cli/cmd_Asks.ts +2 -0
- package/src/cli/cmd_Assets.ts +5 -5
- package/src/cli/cmd_Backup.ts +16 -8
- package/src/cli/cmd_Bump.ts +1 -0
- package/src/cli/cmd_Capacity.ts +30 -0
- package/src/cli/cmd_Check.ts +1 -0
- package/src/cli/cmd_Checks.ts +13 -1
- package/src/cli/cmd_Ci.ts +3 -2
- package/src/cli/cmd_Commands.ts +61 -16
- package/src/cli/cmd_ConfigKeys.ts +17 -0
- package/src/cli/cmd_Home.ts +1 -30
- package/src/cli/cmd_Hooks.ts +1 -0
- package/src/cli/cmd_Keys.ts +4 -1
- package/src/cli/cmd_Lanes.ts +35 -0
- package/src/cli/cmd_Mv.ts +7 -7
- package/src/cli/cmd_Rec.ts +22 -7
- package/src/cli/cmd_Reflect.ts +1 -0
- package/src/cli/cmd_Releases.ts +1 -0
- package/src/cli/cmd_Review.ts +200 -49
- package/src/cli/cmd_Secret.ts +41 -2
- package/src/cli/cmd_Shot.ts +16 -4
- package/src/cli/cmd_Status.ts +7 -5
- package/src/cli/cmd_Time.ts +13 -5
- package/src/cli/cmd_Tmp.ts +82 -0
- package/src/cli/cmd_Veille.ts +10 -6
- package/src/cli/cmd_Wiki.ts +1 -0
- package/src/cli/family-help.ts +136 -0
- package/src/cli/family-pages.ts +0 -19
- package/src/cli/kit/calls.ts +35 -0
- package/src/cli/kit/project-cli.ts +2 -12
- package/src/cli/registry.ts +52 -7
- package/src/cli.ts +8 -4
- package/src/collections/pings.ts +1 -1
- package/src/core/capacity.ts +127 -0
- package/src/core/check-runner.ts +91 -16
- package/src/core/floor-resolve.ts +6 -2
- package/src/core/floor.ts +6 -2
- package/src/core/history-files.ts +18 -0
- package/src/core/jobs.ts +35 -16
- package/src/core/layout.ts +2 -2
- package/src/core/motherhome.ts +67 -9
- package/src/core/nearest.ts +16 -0
- package/src/core/remove-tree.ts +19 -0
- package/src/core/runs.ts +12 -3
- package/src/core/slots.ts +49 -12
- package/src/core/throwaway-worktree.ts +22 -4
- package/src/core/trace-audit.ts +21 -5
- package/src/drill/run.ts +5 -2
- package/src/home/daemon-jobs.ts +41 -4
- package/src/home/gui-app/ShipkitGui.swift +1 -0
- package/src/home/home-launchd.ts +11 -3
- package/src/home/home-routes.ts +11 -4
- package/src/home/machine-host.ts +65 -0
- package/src/home/machine-stores.ts +19 -17
- package/src/home/machine-temp.ts +485 -0
- package/src/home/other-macs.ts +74 -0
- package/src/home/run-daemon.ts +10 -2
- package/src/home/serve-web.ts +2 -2
- package/src/home/via-hub.ts +6 -1
- package/src/init-repo.ts +7 -3
- package/src/ledger/gate-checks.ts +3 -2
- package/src/ledger/git-key.ts +25 -4
- package/src/ledger/git-scan.ts +10 -0
- package/src/ledger/ledger.ts +6 -0
- package/src/ledger/store.ts +6 -0
- package/src/media-store/backup/daemon.ts +92 -20
- package/src/media-store/backup/keys.ts +21 -6
- package/src/media-store/backup/manifest.ts +52 -11
- package/src/media-store/backup/restore.ts +17 -10
- package/src/media-store/backup/run.ts +26 -17
- package/src/media-store/backup/sources.ts +168 -22
- package/src/media-store/backup/watch.ts +106 -0
- package/src/media-store/daemon.ts +36 -8
- package/src/media-store/hand.ts +3 -1
- package/src/mv/mv-md.ts +167 -56
- package/src/pb/run-pb.ts +2 -10
- package/src/plan/repo-source.ts +25 -14
- package/src/recordings/model.ts +1 -1
- package/src/reflect/transcript.ts +56 -11
- package/src/release/run-bump.ts +3 -2
- package/src/release/run-release.ts +12 -4
- package/src/releases/from-card.ts +45 -3
- package/src/releases/model.ts +6 -0
- package/src/releases/store.ts +8 -1
- package/src/repo-config.ts +5 -3
- package/src/review/cells.ts +26 -4
- package/src/review/format.ts +34 -10
- package/src/review/media-kind.ts +14 -11
- package/src/review/media-read.ts +6 -5
- package/src/review/model.ts +85 -4
- package/src/review/paste.ts +2 -1
- package/src/review/previews.ts +123 -36
- package/src/review/routes.ts +29 -18
- package/src/review/store.ts +89 -19
- package/src/review/threads.ts +7 -5
- package/src/review/trailer-model.ts +2 -2
- package/src/secrets/copy.ts +110 -0
- package/src/secrets/list.ts +17 -7
- package/src/serve/hub-app/home-strip.css +5 -0
- package/src/serve/hub-app/home-strip.tsx +18 -0
- package/src/serve/hub-app/hub-app.tsx +2 -1
- package/src/serve/hub-app/hub.css +14 -0
- package/src/serve/hub-app/inbox.css +1 -0
- package/src/serve/hub-app/pull-refresh.tsx +88 -0
- package/src/serve/hub-app/review/review-cells.tsx +52 -13
- package/src/serve/hub-app/review/review-list.tsx +6 -1
- package/src/serve/hub-app/review/review-st.ts +6 -5
- package/src/serve/hub-app/review/review-thread.tsx +3 -1
- package/src/serve/hub-app/review/review-views.tsx +18 -11
- package/src/serve/hub-app/review/thread-st.ts +82 -14
- package/src/serve/hub-app/review.css +15 -2
- package/src/serve/hub-runtime.ts +2 -1
- package/src/serve/run-serve.ts +4 -2
- package/src/serve/serve-hub.ts +9 -2
- package/src/shot/client.ts +4 -2
- package/src/shot/serve-shot.ts +71 -2
- package/src/shot/shooter.ts +65 -11
- package/src/shot/shot-ask.ts +32 -9
- package/src/suite/child-tools.ts +45 -0
- package/src/suite/judge-suites.ts +10 -22
- package/src/suite/select.ts +95 -9
- package/src/suite/suite-cli.ts +38 -14
- package/src/suite/suite-cores.ts +68 -0
- package/src/suite/suite-reads-preload.ts +8 -6
- package/src/suite/test-units.ts +31 -12
- package/src/trailer/graph.ts +2 -1
- package/src/ts/config.ts +21 -0
- package/src/ts/rename.ts +37 -13
- package/src/ts/workspaces.ts +45 -0
- package/src/wiki/run-wiki.ts +7 -2
- package/src/wiki/scan-md.ts +2 -1
- package/src/home/claude-temp.ts +0 -139
package/src/suite/test-units.ts
CHANGED
|
@@ -100,22 +100,41 @@ export function unitTestBody(pkgText: string | null): { script: string | null; b
|
|
|
100
100
|
return { script: null, body: 'bun test' }
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
/** the
|
|
104
|
-
* in any dependency block, and
|
|
105
|
-
* bench resolving the libs at their source folders
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
103
|
+
/** the package dirs a unit's tests can read, beside its own: every package its
|
|
104
|
+
* package.json names in any dependency block, and every one its tsconfig
|
|
105
|
+
* `paths` point into (a bench resolving the libs at their source folders
|
|
106
|
+
* names them nowhere else), then what those name in turn. A package is a
|
|
107
|
+
* sibling unit or any workspace package, a unit or not: an import reads the
|
|
108
|
+
* folder whatever the release config says of it. Their dirs belong to its
|
|
109
|
+
* inputs. Derived, never hand kept, and over declaring is safe where under
|
|
110
|
+
* declaring is a stale green */
|
|
111
|
+
export function siblingUnits(units: TestUnitDecl[], read: (rel: string) => string | null, workspaces: readonly { name: string; dir: string }[] = []): Map<string, string[]> {
|
|
112
|
+
const manifests = new Map<string, Pkg | null>()
|
|
113
|
+
const manifest = (rel: string): Pkg | null => {
|
|
114
|
+
if (!manifests.has(rel)) manifests.set(rel, parsePkg(read(posix.join(rel, 'package.json'))))
|
|
115
|
+
return manifests.get(rel)!
|
|
116
|
+
}
|
|
117
|
+
const byName = new Map<string, string>(workspaces.map((w) => [w.name, normSuitePath(w.dir).replace(/\/+$/, '')]))
|
|
118
|
+
for (const u of units) { const n = manifest(u.rel)?.name; if (n != null) byName.set(n, u.rel) }
|
|
119
|
+
const dirs = [...new Set([...units.map((u) => u.rel), ...byName.values()])]
|
|
120
|
+
const named = (rel: string): string[] => {
|
|
121
|
+
const p = manifest(rel)
|
|
122
|
+
return [p?.dependencies, p?.devDependencies, p?.peerDependencies, p?.optionalDependencies].flatMap((b) => Object.keys(b ?? {})).flatMap((n) => byName.get(n) ?? [])
|
|
123
|
+
}
|
|
112
124
|
const out = new Map<string, string[]>()
|
|
113
125
|
for (const u of units) {
|
|
114
|
-
const p = pkgs.get(u.id)
|
|
115
|
-
const names = new Set([p?.dependencies, p?.devDependencies, p?.peerDependencies, p?.optionalDependencies].flatMap((b) => Object.keys(b ?? {})))
|
|
116
126
|
const tsconfig = unitTsconfig(u)
|
|
117
127
|
const targets = pathTargets(read(tsconfig)).map((t) => posix.normalize(posix.join(posix.dirname(tsconfig), t)))
|
|
118
|
-
|
|
128
|
+
const own = (d: string): boolean => under(d, u.rel)
|
|
129
|
+
// the unit's own dir is in its inputs already, and what it names is followed all the same
|
|
130
|
+
const seen = new Set<string>()
|
|
131
|
+
const queue = [...named(u.rel), ...dirs.filter((d) => targets.some((t) => under(t, d)))]
|
|
132
|
+
for (let d = queue.shift(); d != null; d = queue.shift()) {
|
|
133
|
+
if (seen.has(d)) continue
|
|
134
|
+
seen.add(d)
|
|
135
|
+
queue.push(...named(d))
|
|
136
|
+
}
|
|
137
|
+
out.set(u.id, [...seen].filter((d) => !own(d)).sort())
|
|
119
138
|
}
|
|
120
139
|
return out
|
|
121
140
|
}
|
package/src/trailer/graph.ts
CHANGED
|
@@ -561,7 +561,8 @@ export function nextMixLevel(master: number | null, passes: readonly MixPass[]):
|
|
|
561
561
|
const trim = over > 0 ? +(level.trim - over - 0.1).toFixed(2) : level.trim
|
|
562
562
|
const left = +(gap - (trim - level.trim)).toFixed(2)
|
|
563
563
|
if (master === null || Math.abs(left) <= MASTER_TOLERANCE) return { gain: level.gain, trim }
|
|
564
|
-
|
|
564
|
+
// no findLast: a consumer's own typecheck reads this source, under whatever lib its tsconfig names
|
|
565
|
+
const before = [...passes].reverse().find((p) => p.level.gain !== level.gain)
|
|
565
566
|
const moved = before ? (m.lufs - level.trim - (before.m.lufs - before.level.trim)) / (level.gain - before.level.gain) : 1
|
|
566
567
|
const slope = Math.min(1, Math.max(MIN_SLOPE, moved))
|
|
567
568
|
return { gain: +(level.gain + left / slope).toFixed(2), trim }
|
package/src/ts/config.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { join } from 'path'
|
|
|
17
17
|
import { gitRoot } from '../core/git-root.ts'
|
|
18
18
|
import { isVendored } from '../core/vendored.ts'
|
|
19
19
|
import { readVendored } from '../core/vendored-read.ts'
|
|
20
|
+
import { workspacePackagesOf } from './workspaces.ts'
|
|
20
21
|
|
|
21
22
|
export type RvtPackage = {
|
|
22
23
|
name: string // package.json "name" — the import root for files inside
|
|
@@ -117,6 +118,26 @@ function discoverPackages(root: string, roots: string[], skip: string[], vendore
|
|
|
117
118
|
return found.sort((a, b) => b.dir.length - a.dir.length)
|
|
118
119
|
}
|
|
119
120
|
|
|
121
|
+
// the package.json `workspaces` (an array, or `{ packages }`), each a dir or a glob of dirs, with each one's `exports`:
|
|
122
|
+
// a workspace outside the roots is still imported by its name, and the test selection's graph follows that edge
|
|
123
|
+
export function workspacePackages(root: string, vendored: readonly string[] = []): (RvtPackage & { exports?: unknown })[] {
|
|
124
|
+
const read = (rel: string): string | null => {
|
|
125
|
+
try {
|
|
126
|
+
return readFileSync(join(root, rel), 'utf8')
|
|
127
|
+
} catch {
|
|
128
|
+
return null
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const subdirs = (rel: string): string[] => {
|
|
132
|
+
try {
|
|
133
|
+
return readdirSync(join(root, rel), { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name)
|
|
134
|
+
} catch {
|
|
135
|
+
return []
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return workspacePackagesOf(read, subdirs, vendored)
|
|
139
|
+
}
|
|
140
|
+
|
|
120
141
|
export function loadConfig(cwd: string = process.cwd()): RvtConfig {
|
|
121
142
|
const root = findRepoRoot(cwd)
|
|
122
143
|
let roots: string[] = []
|
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
|
-
|
|
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(
|
|
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(
|
|
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,11 +262,24 @@ function relativeRewrites(file: string, content: string, movedTo: (rel: string)
|
|
|
251
262
|
return out
|
|
252
263
|
}
|
|
253
264
|
|
|
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 {
|
|
271
|
+
for (let idx = text.indexOf(needle, from); idx !== -1; idx = text.indexOf(needle, idx + 1)) {
|
|
272
|
+
const next = text.slice(idx + needle.length, idx + needle.length + 2)
|
|
273
|
+
if (!/^[\w-]/.test(next) && !/^\.\w/.test(next) && namesMoved(text, idx, needle, needle, where.carrierDir, where.root)) return idx
|
|
274
|
+
}
|
|
275
|
+
return -1
|
|
276
|
+
}
|
|
277
|
+
|
|
254
278
|
// simultaneous multi-needle replace: earliest match wins (longest needle on a
|
|
255
279
|
// tie) and the scan continues PAST the replacement — sequential split/join
|
|
256
280
|
// would let one pair's output feed the next (the package form is a substring
|
|
257
281
|
// of the repo form, so that corrupts content)
|
|
258
|
-
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 } {
|
|
259
283
|
let out = ''
|
|
260
284
|
let i = 0
|
|
261
285
|
let count = 0
|
|
@@ -264,7 +288,7 @@ function scanPairs(text: string, pairs: { from: string; to: string }[]): { text:
|
|
|
264
288
|
let hit: { from: string; to: string } | null = null
|
|
265
289
|
for (const p of pairs) {
|
|
266
290
|
if (p.from.length === 0) continue
|
|
267
|
-
const idx = text
|
|
291
|
+
const idx = pathAt(text, p.from, i, where)
|
|
268
292
|
if (idx === -1) continue
|
|
269
293
|
if (at === -1 || idx < at || (idx === at && p.from.length > (hit?.from.length ?? 0))) {
|
|
270
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
|
+
}
|
package/src/wiki/run-wiki.ts
CHANGED
|
@@ -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
|
|
73
|
-
if (
|
|
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
|
}
|
package/src/wiki/scan-md.ts
CHANGED
|
@@ -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
|
-
|
|
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)
|
package/src/home/claude-temp.ts
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
// claude code's per session scratch, `<temp root>/<project>/<session>/`: nothing
|
|
2
|
-
// trims it but a reboot. A pass of the retention sweep (machine-stores.ts) keeps
|
|
3
|
-
// every session written in the last guard hours, then the newest idle ones while
|
|
4
|
-
// they fit under the cap, and deletes the rest, oldest first.
|
|
5
|
-
//
|
|
6
|
-
// the one constraint a reader breaks first: this deletes for real (the Trash is
|
|
7
|
-
// on the same disk). Nothing outside the checked root, and no link is followed:
|
|
8
|
-
// lstat everywhere, a link is removed as a link.
|
|
9
|
-
import { lstatSync, readdirSync, realpathSync, rmSync } from 'node:fs'
|
|
10
|
-
import { homedir } from 'node:os'
|
|
11
|
-
import { basename, join, sep } from 'node:path'
|
|
12
|
-
import { machineGet, machineSet } from '../core/machine-db.ts'
|
|
13
|
-
|
|
14
|
-
/** what the idle sessions may hold together */
|
|
15
|
-
export const CLAUDE_TEMP_MAX_BYTES = 5e9
|
|
16
|
-
/** a session written this recently is never touched, whatever its size */
|
|
17
|
-
export const CLAUDE_TEMP_GUARD_MS = 24 * 60 * 60 * 1000
|
|
18
|
-
|
|
19
|
-
const AUTO_KEY = 'claude-temp-auto'
|
|
20
|
-
/** the owner's switch, off until it is turned on: the daemon's sweep deletes nothing before */
|
|
21
|
-
export const claudeTempAuto = (): boolean => machineGet<boolean>(AUTO_KEY) === true
|
|
22
|
-
export const setClaudeTempAuto = (on: boolean): boolean => machineSet(AUTO_KEY, on)
|
|
23
|
-
|
|
24
|
-
/** where claude code keeps it on this machine: its own override, else /tmp, then one folder per uid */
|
|
25
|
-
export function claudeTempRoot(env: Record<string, string | undefined> = process.env): string | null {
|
|
26
|
-
const uid = process.getuid?.()
|
|
27
|
-
return uid == null ? null : join(env.CLAUDE_CODE_TMPDIR || '/tmp', `claude-${uid}`)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** the root, resolved once and checked; null when it does not exist; throws on any other shape */
|
|
31
|
-
export function checkedRoot(root: string): string | null {
|
|
32
|
-
const uid = process.getuid?.()
|
|
33
|
-
if (uid == null) throw new Error('no uid on this platform: the claude temp pass does not run')
|
|
34
|
-
if (root.split(/[\\/]/).includes('..')) throw new Error(`${root}: a path with .. is refused`)
|
|
35
|
-
let real: string
|
|
36
|
-
try { real = realpathSync(root) } catch (e) {
|
|
37
|
-
if ((e as { code?: string }).code === 'ENOENT') return null
|
|
38
|
-
throw e
|
|
39
|
-
}
|
|
40
|
-
const s = lstatSync(real)
|
|
41
|
-
if (real === sep || real === homedir() || !s.isDirectory()) throw new Error(`${real}: not a temp folder of its own`)
|
|
42
|
-
if (s.uid !== uid) throw new Error(`${real}: owned by uid ${s.uid}, not ${uid}`)
|
|
43
|
-
if (basename(real) !== `claude-${uid}`) throw new Error(`${real}: not named claude-${uid}`)
|
|
44
|
-
return real
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export type Unit = { path: string; at: number; bytes: number }
|
|
48
|
-
export type Plan = { root: string; keep: Unit[]; drop: Unit[] }
|
|
49
|
-
|
|
50
|
-
/** newest mtime and size of a tree, lstat only; null once an entry is newer than `fresh` or unreadable */
|
|
51
|
-
function scan(top: string, fresh: number, printErr: (l: string) => void): { at: number; bytes: number } | null {
|
|
52
|
-
let at = 0
|
|
53
|
-
let bytes = 0
|
|
54
|
-
const stack = [top]
|
|
55
|
-
while (stack.length > 0) {
|
|
56
|
-
const p = stack.pop()!
|
|
57
|
-
let s
|
|
58
|
-
try { s = lstatSync(p) } catch { continue }
|
|
59
|
-
at = Math.max(at, s.mtimeMs)
|
|
60
|
-
bytes += s.size
|
|
61
|
-
if (at >= fresh) return null
|
|
62
|
-
if (!s.isDirectory()) continue
|
|
63
|
-
try { for (const n of readdirSync(p)) stack.push(join(p, n)) } catch (e) {
|
|
64
|
-
printErr(`WARN claude temp: ${p} unreadable (${(e as Error).message}), its session kept`)
|
|
65
|
-
return null
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return { at, bytes }
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const names = (d: string, printErr: (l: string) => void): string[] => {
|
|
72
|
-
try { return readdirSync(d) } catch (e) {
|
|
73
|
-
printErr(`WARN claude temp: ${d} unreadable (${(e as Error).message}), skipped`)
|
|
74
|
-
return []
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** every idle unit under the root: newest first under the cap kept, the rest dropped, oldest first */
|
|
79
|
-
export function planClaudeTemp(root: string, o: { now: number; capBytes?: number; guardMs?: number; printErr: (l: string) => void }): Plan | null {
|
|
80
|
-
const real = checkedRoot(root)
|
|
81
|
-
if (real == null) return null
|
|
82
|
-
const fresh = o.now - (o.guardMs ?? CLAUDE_TEMP_GUARD_MS)
|
|
83
|
-
const units: (Unit & { loose: boolean })[] = []
|
|
84
|
-
const loose = (path: string): void => {
|
|
85
|
-
try {
|
|
86
|
-
const s = lstatSync(path)
|
|
87
|
-
if (s.mtimeMs < fresh) units.push({ path, at: s.mtimeMs, bytes: s.size, loose: true })
|
|
88
|
-
} catch { /* raced: gone */ }
|
|
89
|
-
}
|
|
90
|
-
for (const project of names(real, o.printErr)) {
|
|
91
|
-
const pp = join(real, project)
|
|
92
|
-
if (!isDir(pp)) { loose(pp); continue }
|
|
93
|
-
for (const session of names(pp, o.printErr)) {
|
|
94
|
-
const sp = join(pp, session)
|
|
95
|
-
if (!isDir(sp)) { loose(sp); continue }
|
|
96
|
-
const r = scan(sp, fresh, o.printErr)
|
|
97
|
-
if (r != null) units.push({ path: sp, ...r, loose: false })
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
// a loose file ranks as the oldest unit: it belongs to no session
|
|
101
|
-
units.sort((a, b) => (b.loose ? -Infinity : b.at) - (a.loose ? -Infinity : a.at))
|
|
102
|
-
const keep: Unit[] = []
|
|
103
|
-
const drop: Unit[] = []
|
|
104
|
-
let total = 0
|
|
105
|
-
for (const u of units) {
|
|
106
|
-
const unit = { path: u.path, at: u.at, bytes: u.bytes }
|
|
107
|
-
if (drop.length === 0 && total + u.bytes <= (o.capBytes ?? CLAUDE_TEMP_MAX_BYTES)) { total += u.bytes; keep.push(unit) } else drop.push(unit)
|
|
108
|
-
}
|
|
109
|
-
return { root: real, keep, drop: drop.reverse() }
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const isDir = (p: string): boolean => {
|
|
113
|
-
try { return lstatSync(p).isDirectory() } catch { return false }
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export const gb = (n: number): string => `${(n / 1e9).toFixed(2)} GB`
|
|
117
|
-
const days = (ms: number): string => `${(ms / 86_400_000).toFixed(1)}d`
|
|
118
|
-
|
|
119
|
-
/** one pass: each dropped unit removed (or only named, `dry`), one line each; the bytes freed */
|
|
120
|
-
export function trimClaudeTemp(root: string, o: { now: number; dry?: boolean; capBytes?: number; guardMs?: number; print: (l: string) => void; printErr: (l: string) => void }): number {
|
|
121
|
-
const plan = planClaudeTemp(root, o)
|
|
122
|
-
if (plan == null) return 0
|
|
123
|
-
let freed = 0
|
|
124
|
-
for (const u of plan.drop) {
|
|
125
|
-
if (!u.path.startsWith(plan.root + sep) || u.path.split(sep).includes('..')) throw new Error(`${u.path}: outside ${plan.root}, the pass stops`)
|
|
126
|
-
const line = `${u.path.slice(plan.root.length + 1)} idle ${days(o.now - u.at)} ${gb(u.bytes)}`
|
|
127
|
-
if (o.dry !== true) {
|
|
128
|
-
try { rmSync(u.path, { recursive: true, force: true }) } catch (e) {
|
|
129
|
-
o.printErr(`WARN claude temp: ${u.path} not deleted (${(e as Error).message})`)
|
|
130
|
-
continue
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
freed += u.bytes
|
|
134
|
-
o.print(`claude temp: ${o.dry === true ? 'would delete' : 'deleted'} ${line}`)
|
|
135
|
-
}
|
|
136
|
-
const kept = plan.keep.reduce((n, u) => n + u.bytes, 0)
|
|
137
|
-
if (o.dry === true || plan.drop.length > 0) o.print(`claude temp: ${o.dry === true ? 'would free' : 'freed'} ${gb(freed)} in ${plan.drop.length} units; kept ${plan.keep.length} idle units, ${gb(kept)} of ${gb(o.capBytes ?? CLAUDE_TEMP_MAX_BYTES)}, and every session written in the last ${(o.guardMs ?? CLAUDE_TEMP_GUARD_MS) / 3_600_000} h`)
|
|
138
|
-
return freed
|
|
139
|
-
}
|