rvlib-shipkit 2.14.0 → 2.15.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 CHANGED
@@ -1,3 +1,9 @@
1
+ ## 2.15.0
2
+
3
+ - **`sk drill clean <run folder>`** moves a recorded drill run folder to the trash, never deletes it, and refuses a folder that is not a drill copy: a git repo of its own, one commit named « drill base », no remote. `--dry-run` says what would move.
4
+ - **`sk media link --help` names a neutral file** in its example.
5
+ - **The agent folder never leaves the repo.** A CLAUDE.md last include through `..`, `.`, `node_modules` or `.git` names no agent folder, so SK003 fails on it instead of SK033 repairing a file outside the repo or inside a dependency, and an `@` line inside a code fence is an example, never the agent line.
6
+
1
7
  ## 2.14.0
2
8
 
3
9
  - **`sk mv` turns a page into a topic folder.** `sk mv wiki/a/x.md wiki/b/x/index.md` makes the page's asset dir the folder and the page its `index.md`, in place too (`wiki/a/x.md` → `wiki/a/x/index.md`); an existing folder is refused, never merged into. An empty leftover dir no longer stops a move, and a renamed page renames its `.check.shipkit.ts`, `.check.ts` and `.shipkit.ts` files with it.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rvlib-shipkit",
3
- "version": "2.14.0",
3
+ "version": "2.15.0",
4
4
  "funding": "https://github.com/sponsors/rvion",
5
5
  "description": "All-in-one repo companion: ci gate (task DAG), auto-discovered health checks, release-contract fulfillness, asks queue, md-wiki tools, asset atelier, live tui",
6
6
  "license": "MIT",
@@ -2,6 +2,7 @@
2
2
  // as run<n>.json + run<n>.md, verdict = the judged quality added to a run, compare = every run of a drill side
3
3
  // by side. It reads transcripts and writes files; it never starts an agent (core/agent-spawn.ts). Exit 0 with
4
4
  // the files written, 1 when a transcript or a run is missing or an argument does not parse, 2 on a bad verdict or --out.
5
+ // clean = a run folder moved to the trash once it is recorded, refused unless it is a drill copy.
5
6
  import { Command, Option } from 'clipanion'
6
7
  import { existsSync, readdirSync, readFileSync, writeFileSync } from 'fs'
7
8
  import { basename, dirname, join, resolve } from 'path'
@@ -143,3 +144,31 @@ export class DrillCompareCommand extends Command {
143
144
  return 0
144
145
  }
145
146
  }
147
+
148
+ export class DrillCleanCommand extends Command {
149
+ static override paths = [['drill', 'clean']]
150
+ static override usage = Command.Usage({
151
+ category: 'Drill',
152
+ description: 'a recorded drill run folder moved to the trash, never deleted, refused unless it is a drill copy',
153
+ details: 'A drill copy is a git repo of its own (no worktree) holding one commit named « drill base » and no remote. Anything else is refused with the reason, so a wrong path never moves. The folder lands in the trash under its name and the time, to put back by hand. --dry-run says what would move. Exit 0 when every folder moved, 1 when one was refused.',
154
+ examples: [
155
+ ['one run, once its report is written', 'sk drill clean ~/drills/app--form'],
156
+ ['see first', 'sk drill clean ~/drills/app--form ~/drills/app--list --dry-run'],
157
+ ],
158
+ })
159
+ dirs = Option.Rest({ required: 1, name: 'run folder' })
160
+ dry = Option.Boolean('--dry-run', false, { description: 'say what would move, move nothing' })
161
+
162
+ async execute(): Promise<number> {
163
+ const { cleanDrillCopy } = await import('../drill/clean.ts')
164
+ let refused = 0
165
+ for (const dir of this.dirs) {
166
+ const r = cleanDrillCopy(dir.replace(/^~(?=\/)/, process.env.HOME ?? '~'), { dry: this.dry })
167
+ if ('refused' in r) {
168
+ refused++
169
+ this.context.stderr.write(`REFUSE: ${r.dir} ${r.refused}: not a drill copy, nothing moved\n`)
170
+ } else this.context.stdout.write(`${this.dry ? 'would move' : 'ok: moved'} ${r.dir} → ${r.to}\n`)
171
+ }
172
+ return refused === 0 ? 0 : 1
173
+ }
174
+ }
@@ -206,7 +206,7 @@ export class MediaLinkCommand extends Command {
206
206
  details: `${PUT_DETAILS}\n\nThe reference is a key (<label>/<sha256>.<ext>), a sha (12 hex of it are enough), or a file the store holds. The link downloads under the name the index keeps for it, or --name. --for defaults to 24h, at most 7d. --json prints { key, sha, size, name, url, expires }.`,
207
207
  examples: [
208
208
  ['a link for a day', 'sk media link private-build/<sha>.zip'],
209
- ['a week, under a name, as json', 'sk media link private-build/<sha>.zip --for 7d --name dgen-1.2.0-mac-arm64.zip --json'],
209
+ ['a week, under a name, as json', 'sk media link private-build/<sha>.zip --for 7d --name my-app-1.2.0-mac-arm64.zip --json'],
210
210
  ],
211
211
  })
212
212
  for = Option.String('--for', { description: 'how long the link lasts: 30m, 2h, 7d (24h, at most 7d)' })
@@ -9,7 +9,7 @@ import { AssetsAddCommand, AssetsCheckCommand, AssetsFillCommand, AssetsGenComma
9
9
  import { BumpCommand } from './cmd_Bump.ts'
10
10
  import { CallsCommand } from './cmd_Calls.ts'
11
11
  import { TimeCommand } from './cmd_Time.ts'
12
- import { DrillCompareCommand, DrillReportCommand, DrillVerdictCommand } from './cmd_Drill.ts'
12
+ import { DrillCleanCommand, DrillCompareCommand, DrillReportCommand, DrillVerdictCommand } from './cmd_Drill.ts'
13
13
  import { CheckCommand } from './cmd_Check.ts'
14
14
  import { CommandsCommand } from './cmd_Commands.ts'
15
15
  import { withFamilyPage } from './family-pages.ts'
@@ -144,6 +144,7 @@ export function buildCli(): Cli {
144
144
  cli.register(DrillReportCommand)
145
145
  cli.register(DrillVerdictCommand)
146
146
  cli.register(DrillCompareCommand)
147
+ cli.register(DrillCleanCommand)
147
148
  cli.register(ConfigKeysCommand)
148
149
 
149
150
  return cli
@@ -5,11 +5,23 @@
5
5
 
6
6
  export const DEFAULT_AGENT_DIR = 'agent'
7
7
 
8
- /** the agent folder a CLAUDE.md text names, DEFAULT_AGENT_DIR when it names none */
8
+ /** a segment that leaves the repo or lands in what a tool owns: checks write into the agent folder */
9
+ const UNSAFE_SEGMENT = /^(?:\.\.?|node_modules|\.git)$/
10
+
11
+ /** the include lines of a CLAUDE.md, a code fence's lines left out (they are examples, not includes) */
12
+ const includeLines = (claude: string): string[] => {
13
+ let fenced = false
14
+ return claude.split('\n').map((l) => l.trim()).filter((l) => {
15
+ if (/^(```|~~~)/.test(l)) fenced = !fenced
16
+ return !fenced && l.startsWith('@')
17
+ })
18
+ }
19
+
20
+ /** the agent folder a CLAUDE.md text names, DEFAULT_AGENT_DIR when it names none or an unsafe one */
9
21
  export function agentDirOf(claude: string | null): string {
10
- const last = (claude ?? '').split('\n').map((l) => l.trim()).filter((l) => l.startsWith('@')).at(-1)
11
- const m = last == null ? null : /^@\.\/((?:[\w.-]+\/)*[\w.-]+)\/index\.md$/.exec(last)
12
- return m?.[1] ?? DEFAULT_AGENT_DIR
22
+ const last = includeLines(claude ?? '').at(-1)
23
+ const dir = (last == null ? null : /^@\.\/((?:[\w.-]+\/)*[\w.-]+)\/index\.md$/.exec(last))?.[1]
24
+ return dir == null || dir.split('/').some((seg) => UNSAFE_SEGMENT.test(seg)) ? DEFAULT_AGENT_DIR : dir
13
25
  }
14
26
 
15
27
  /** a folder of another wiki (`docs/wiki/agent`), whose own lint and graph cover it */
@@ -0,0 +1,54 @@
1
+ // a drill run folder leaves for the trash, never for rm: the folder is checked to BE a drill copy first
2
+ // (a git repo of its own, one commit named « drill base », no remote), so a wrong path is refused, and a
3
+ // moved folder can be put back. a move across disks fails loud, it never falls back to a delete.
4
+ import { existsSync, lstatSync, mkdirSync, realpathSync, renameSync } from 'fs'
5
+ import { homedir } from 'os'
6
+ import { basename, dirname, join, resolve } from 'path'
7
+ import { gitBin } from '../core/git-bin.ts'
8
+
9
+ export const DRILL_BASE = 'drill base'
10
+
11
+ export const trashDir = (): string =>
12
+ process.platform === 'darwin' ? join(homedir(), '.Trash') : join(process.env.XDG_DATA_HOME ?? join(homedir(), '.local/share'), 'Trash/files')
13
+
14
+ const git = (dir: string, args: string[]): string | null => {
15
+ const p = Bun.spawnSync([gitBin(), '-C', dir, ...args], { stdout: 'pipe', stderr: 'ignore' })
16
+ return p.exitCode === 0 ? p.stdout.toString().trim() : null
17
+ }
18
+
19
+ /** why `dir` is not a drill copy, or null when it is one */
20
+ export function notADrillCopy(dir: string): string | null {
21
+ const abs = resolve(dir)
22
+ if (!existsSync(abs)) return 'does not exist'
23
+ if (lstatSync(abs).isSymbolicLink()) return 'is a symlink'
24
+ if (!lstatSync(abs).isDirectory()) return 'is not a folder'
25
+ if (abs === homedir() || dirname(abs) === abs) return 'is the home or the root folder'
26
+ // a worktree's .git is a file that points into another repo's refs
27
+ if (!existsSync(join(abs, '.git')) || !lstatSync(join(abs, '.git')).isDirectory()) return 'has no .git folder of its own'
28
+ const top = git(abs, ['rev-parse', '--show-toplevel'])
29
+ if (top == null || realpathSync(top) !== realpathSync(abs)) return 'is not the top of its git repo'
30
+ const count = git(abs, ['rev-list', '--count', '--all'])
31
+ if (count !== '1') return `holds ${count ?? 'no'} commits, a drill copy holds one`
32
+ const subject = git(abs, ['log', '-1', '--format=%s'])
33
+ if (subject !== DRILL_BASE) return `its commit is « ${subject ?? ''} », not « ${DRILL_BASE} »`
34
+ if ((git(abs, ['remote']) ?? '') !== '') return 'has a git remote'
35
+ return null
36
+ }
37
+
38
+ export type CleanResult = { dir: string; to: string } | { dir: string; refused: string }
39
+
40
+ /** moves one drill copy into `trash` under a free name; dry = report only */
41
+ export function cleanDrillCopy(dir: string, opts: { trash?: string; dry?: boolean; now?: Date } = {}): CleanResult {
42
+ const abs = resolve(dir)
43
+ const why = notADrillCopy(abs)
44
+ if (why != null) return { dir: abs, refused: why }
45
+ const trash = opts.trash ?? trashDir()
46
+ const stamp = (opts.now ?? new Date()).toISOString().replace(/[-:]/g, '').replace(/\..*/, '')
47
+ let to = join(trash, `${basename(abs)}-${stamp}`)
48
+ for (let i = 2; existsSync(to); i++) to = join(trash, `${basename(abs)}-${stamp}-${i}`)
49
+ if (opts.dry !== true) {
50
+ mkdirSync(trash, { recursive: true })
51
+ renameSync(abs, to)
52
+ }
53
+ return { dir: abs, to }
54
+ }