@skitterbyte/skitterspec-github 2.18.1 → 3.1.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 (36) hide show
  1. package/MIGRATION.md +126 -0
  2. package/README.md +11 -2
  3. package/assets/claude-md-section.md +23 -123
  4. package/assets/core/SETUP.md +4 -2
  5. package/assets/project-conventions.md +17 -0
  6. package/assets/rules/commit-trailers.md +41 -99
  7. package/assets/rules/negative-checks.md +21 -48
  8. package/assets/rules/offered-unblocks.md +39 -74
  9. package/assets/rules/spec-format.md +117 -0
  10. package/assets/rules/spec-planning.md +128 -1013
  11. package/assets/rules/spec-reports.md +70 -607
  12. package/assets/skills/no-spec/SKILL.md +4 -4
  13. package/assets/skills/spec/SKILL.md +7 -7
  14. package/assets/skills/spec/kind-routing.md +35 -0
  15. package/assets/skills/spec-bug/SKILL.md +6 -6
  16. package/assets/skills/spec-cancel/SKILL.md +1 -1
  17. package/assets/skills/spec-complete/SKILL.md +1 -1
  18. package/assets/skills/spec-diff/SKILL.md +6 -2
  19. package/assets/skills/spec-diff/review-page.md +89 -0
  20. package/assets/skills/spec-diff/review-wait.md +133 -0
  21. package/assets/skills/spec-epic-next/SKILL.md +2 -1
  22. package/assets/skills/spec-epic-next/epics.md +44 -0
  23. package/assets/skills/spec-hotfix/SKILL.md +5 -5
  24. package/assets/skills/spec-incident/SKILL.md +1 -1
  25. package/assets/skills/spec-next/SKILL.md +5 -5
  26. package/assets/skills/spec-resume/SKILL.md +204 -8
  27. package/assets/skills/spec-review/SKILL.md +1 -1
  28. package/assets/skills/spec-start/isolation.md +90 -0
  29. package/bin/skitterspec-github.js +3 -2
  30. package/package.json +2 -3
  31. package/src/cli.js +72 -5
  32. package/src/conventions.js +43 -0
  33. package/src/env/resume.js +116 -3
  34. package/src/init.js +180 -30
  35. package/src/spec-planning-history.json +103 -0
  36. package/src/updateall.js +152 -0
package/src/env/resume.js CHANGED
@@ -177,8 +177,18 @@ function planResume(target, env) {
177
177
  const how =
178
178
  target.bucket === 'backlog'
179
179
  ? ' — it was never started; /spec-start puts it in flight'
180
- : ' — there is nothing left to resume'
181
- return { ok: false, ...base, refused: `${target.folder} is in ${target.bucket}${how}` }
180
+ : reopenable(target)
181
+ ? ' — re-opening it forks a fresh branch from the base branch as it is now'
182
+ : ' — there is nothing left to resume'
183
+ const r = { ok: false, ...base, refused: `${target.folder} is in ${target.bucket}${how}` }
184
+ if (reopenable(target)) {
185
+ r.offer = {
186
+ kind: 'satisfy',
187
+ label: `Re-open ${target.folder}`,
188
+ command: `skitterspec spec-env resume ${target.folder} --reopen`,
189
+ }
190
+ }
191
+ return r
182
192
  }
183
193
  if (env.worktreeExists) return { ok: true, ...base, commands: [], then: [] }
184
194
 
@@ -204,6 +214,95 @@ function planResume(target, env) {
204
214
  return { ok: true, ...base, commands, then: [`skitterspec spec-env bootstrap ${target.folder}`] }
205
215
  }
206
216
 
217
+ /**
218
+ * Whether a finished spec may be re-opened (feat-resume-reopen): only from
219
+ * `complete`, and never a hotfix (it lands by tag and cherry-pick, so a
220
+ * re-opened one has no landing path) or an epic (it holds no phases). A
221
+ * cancelled spec's code never landed, so "from the current state" would be a
222
+ * rebuild from the text alone — that is a new spec.
223
+ *
224
+ * The kind is read off the `Type:` header, falling back to the folder prefix
225
+ * for a spec written without one.
226
+ */
227
+ function reopenable(target) {
228
+ if (!target || target.bucket !== 'complete') return false
229
+ const type = (headerValue(target.overview, 'Type') || '').toLowerCase()
230
+ if (type === 'hotfix' || type === 'epic') return false
231
+ return !/^(hotfix|epic)-/.test(target.folder)
232
+ }
233
+
234
+ /**
235
+ * The plan for `spec-env resume <spec> --reopen`, or a refusal with no offer.
236
+ *
237
+ * The spec's branch was deleted when it completed, and its work is on the base
238
+ * branch, so re-opening is a fresh branch AT the base. The branch is created
239
+ * here (`git branch -f`) rather than left to `up`, so `up` takes its attach
240
+ * path: left alone, `up` would carry on from a leftover remote branch instead,
241
+ * which is an older state than the base it landed on.
242
+ *
243
+ * WHAT WOULD FOOL THIS: a leftover branch with commits the base does not hold
244
+ * — a teardown that was declined, or a squash merge, whose commits are never
245
+ * ancestors of the base. `-f` over that branch would destroy them, so an
246
+ * unmerged leftover, local or remote, refuses and names it. An answer the
247
+ * caller could not get (`null`) is read the same way: a branch nobody could
248
+ * prove safe is not reset (`.claude/rules/negative-checks.md` rule 4).
249
+ *
250
+ * @param {object} target the copy `findTarget` chose
251
+ * @param {object} env `{ branch, base, worktreePath, worktreeExists,
252
+ * localBranch, localMerged, remoteBranch, remoteMerged, remote }`
253
+ */
254
+ function planReopen(target, env) {
255
+ const spec = target.folder
256
+ const refuse = (refused) => ({ ok: false, spec, bucket: target.bucket, branch: env.branch, refused })
257
+ if (!reopenable(target)) {
258
+ if (target.bucket !== 'complete') return refuse(`${spec} is in ${target.bucket} — only a completed spec can be re-opened`)
259
+ const epic = /^epic-/.test(spec) || (headerValue(target.overview, 'Type') || '').toLowerCase() === 'epic'
260
+ return refuse(
261
+ epic
262
+ ? `${spec} is a completed epic, which holds no phases`
263
+ : `${spec} is a completed hotfix, which lands by tag and has no branch to re-open`,
264
+ )
265
+ }
266
+ if (!env.base) return refuse(`the base branch cannot be resolved, so there is nothing to fork ${spec} from`)
267
+ if (env.worktreeExists) {
268
+ return refuse(`a worktree for ${spec} still exists at ${env.worktreePath} — tear it down (spec-env down ${spec}) or work there`)
269
+ }
270
+ if (env.localBranch && env.localMerged !== true) {
271
+ return refuse(`${env.branch} still exists with commits not on ${env.base} — land or delete it before re-opening`)
272
+ }
273
+ if (env.remoteBranch && env.remoteMerged !== true) {
274
+ return refuse(
275
+ `${env.remote}/${env.branch} still exists with commits not on ${env.base} — ` +
276
+ `delete it (git push ${env.remote} --delete ${env.branch}) before re-opening`,
277
+ )
278
+ }
279
+ return {
280
+ ok: true,
281
+ spec,
282
+ bucket: target.bucket,
283
+ branch: env.branch,
284
+ base: env.base,
285
+ worktree: { path: env.worktreePath, present: false },
286
+ commands: [`git branch -f ${env.branch} ${env.base}`, `skitterspec spec-env up ${spec}`],
287
+ move: [`git -C ${shellPath(env.worktreePath)} mv specs/complete/${spec} specs/in-progress/${spec}`],
288
+ }
289
+ }
290
+
291
+ /** The text report for `--reopen`. */
292
+ function reopenLines(r) {
293
+ if (!r.ok) return [`spec-env resume --reopen: refused — ${r.refused}`]
294
+ return [
295
+ `spec-env resume --reopen: ${r.spec} (complete → in-progress, on ${r.branch} from ${r.base})`,
296
+ ` worktree: ${r.worktree.path}`,
297
+ '',
298
+ ' to provision, run (then run what `up` prints):',
299
+ ...r.commands.map((c) => ` ${c}`),
300
+ '',
301
+ ' then, move the spec:',
302
+ ...r.move.map((c) => ` ${c}`),
303
+ ]
304
+ }
305
+
207
306
  function blockerLine(b) {
208
307
  const where = b.where === 'spec' ? 'spec' : `phase ${b.where}`
209
308
  return `${where} — ${b.text}${b.until ? ` (until ${b.until})` : ''}`
@@ -221,6 +320,7 @@ function resumeLines(r) {
221
320
  for (const b of r.blockers) lines.push(` blocked: ${blockerLine(b)}${r.blocking && b.where === r.blocking.where ? ' ← holds the next build' : ''}`)
222
321
  if (!r.ok) {
223
322
  lines.push(` refused: ${r.refused}`)
323
+ if (r.offer) lines.push(` offer: ${r.offer.label} — ${r.offer.command}`)
224
324
  return lines
225
325
  }
226
326
  lines.push(` worktree: ${r.worktree.path}${r.worktree.present ? '' : ' (missing — provision below)'}`)
@@ -231,4 +331,17 @@ function resumeLines(r) {
231
331
  return lines
232
332
  }
233
333
 
234
- module.exports = { blockers, blockingNext, parseBlockedOn, findTarget, planResume, resumeLines, blockerLine, frontmatterField, sameRef }
334
+ module.exports = {
335
+ blockers,
336
+ blockingNext,
337
+ parseBlockedOn,
338
+ findTarget,
339
+ planResume,
340
+ planReopen,
341
+ reopenable,
342
+ resumeLines,
343
+ reopenLines,
344
+ blockerLine,
345
+ frontmatterField,
346
+ sameRef,
347
+ }
package/src/init.js CHANGED
@@ -10,6 +10,7 @@ const { ensureHooks, removeHooks, HOOKS: GATE_HOOKS } = require('./env/hooks.js'
10
10
  const { repoInfo, expandTokens, describeBaseBranch, baseRemote } = require('./env/resolve.js')
11
11
  const { primaryAnchor } = require('./env/project.js')
12
12
  const { setProjectKeys } = require('./env/projectedit.js')
13
+ const { split, strippedHash, KNOWN } = require('./conventions.js')
13
14
 
14
15
  const ASSETS = path.join(__dirname, '..', 'assets')
15
16
 
@@ -27,6 +28,25 @@ function listSkills() {
27
28
  .sort()
28
29
  }
29
30
 
31
+ // Every file a skill ships, relative to its folder, `SKILL.md` first. A skill's
32
+ // supporting files (`<topic>.md` beside `SKILL.md`) load only when the skill
33
+ // reads them, which is what lets content one skill needs leave the
34
+ // always-loaded rules (feat-rules-budget). Dotfiles are not shipped.
35
+ function listSkillFiles(name) {
36
+ const root = path.join(ASSETS, 'skills', name)
37
+ const out = []
38
+ const walk = (d) => {
39
+ for (const e of fs.readdirSync(d, { withFileTypes: true })) {
40
+ if (e.name.startsWith('.')) continue
41
+ const p = path.join(d, e.name)
42
+ if (e.isDirectory()) walk(p)
43
+ else out.push(path.relative(root, p))
44
+ }
45
+ }
46
+ walk(root)
47
+ return out.sort((a, b) => (a === 'SKILL.md' ? -1 : b === 'SKILL.md' ? 1 : a.localeCompare(b)))
48
+ }
49
+
30
50
  // Slash commands shipped as `assets/commands/*.md`, installed to
31
51
  // `.claude/commands/`. Discovered from the bundled tree exactly like skills, so
32
52
  // each distribution installs precisely what it ships.
@@ -130,19 +150,27 @@ function detectPackageManager(dir) {
130
150
  // name alongside `skitterspec`, and either proves the engine is reachable.
131
151
  const ENGINE_BINS = ['skitterspec', 'skitterspec-linear', 'skitterspec-jira', 'skitterspec-github', 'skitterspec-azure-boards']
132
152
 
133
- function binNames() {
134
- return process.platform === 'win32'
135
- ? ENGINE_BINS.flatMap((n) => [n, `${n}.cmd`, `${n}.exe`])
136
- : ENGINE_BINS
153
+ // `bin` narrows the look to one name. A provider no longer answers to
154
+ // `skitterspec` (feat-global-install), so a line that runs `skitterspec` is
155
+ // only served by the base being installed — any engine name proving "an
156
+ // install" would render a command for a bin that is not there.
157
+ function binNames(bin) {
158
+ const names = bin ? [bin] : ENGINE_BINS
159
+ return process.platform === 'win32' ? names.flatMap((n) => [n, `${n}.cmd`, `${n}.exe`]) : names
160
+ }
161
+
162
+ // The npm package a bin comes from: each distribution's bin carries its name.
163
+ function packageForBin(bin) {
164
+ return ENGINE_BINS.includes(bin) ? `@skitterbyte/${bin}` : distributionPackage()
137
165
  }
138
166
 
139
167
  // Rung 1 — a local install, found by walking up. Bounded at 6 levels, matching
140
168
  // the hooks' own `findEngine`: a git worktree's checkout has its own
141
169
  // `node_modules`, and a monorepo package hoists to the root.
142
- function hasLocalInstall(dir) {
170
+ function hasLocalInstall(dir, bin) {
143
171
  let at = path.resolve(dir)
144
172
  for (let i = 0; i < 6; i++) {
145
- for (const name of binNames()) {
173
+ for (const name of binNames(bin)) {
146
174
  if (fs.existsSync(path.join(at, 'node_modules', '.bin', name))) return true
147
175
  }
148
176
  const up = path.dirname(at)
@@ -165,12 +193,12 @@ const NPX_CACHE_RE = /[\\/]_npx[\\/]/
165
193
  // for it here would bake a bare `skitterspec …` into four COMMITTED files that
166
194
  // stop working the moment init exits. Excluding `_npx` entries is what makes
167
195
  // this rung evidence of an install rather than evidence of the install running.
168
- function hasPathInstall(env = process.env) {
196
+ function hasPathInstall(env = process.env, bin) {
169
197
  const raw = env.PATH || env.Path || ''
170
198
  if (!raw) return false
171
199
  for (const entry of raw.split(path.delimiter)) {
172
200
  if (!entry || NPX_CACHE_RE.test(entry)) continue
173
- for (const name of binNames()) {
201
+ for (const name of binNames(bin)) {
174
202
  if (fs.existsSync(path.join(entry, name))) return true
175
203
  }
176
204
  }
@@ -196,9 +224,9 @@ function hasPathInstall(env = process.env) {
196
224
  * between pristine and updatable as different people run `update`. A lockfile
197
225
  * is committed and answers the same everywhere; PATH is one machine's business.
198
226
  */
199
- function detectRunner(dir, env = process.env) {
200
- if (hasLocalInstall(dir)) return { runner: detectPackageManager(dir), rung: 'local' }
201
- if (hasPathInstall(env)) return { runner: '', rung: 'path' }
227
+ function detectRunner(dir, env = process.env, bin) {
228
+ if (hasLocalInstall(dir, bin)) return { runner: detectPackageManager(dir), rung: 'local' }
229
+ if (hasPathInstall(env, bin)) return { runner: '', rung: 'path' }
202
230
  return { runner: 'npx', rung: 'none' }
203
231
  }
204
232
 
@@ -234,11 +262,14 @@ function distributionPackage() {
234
262
  // `Bash(skitterspec …)` rather than `Bash( skitterspec …)`.
235
263
  const EXEC_RE = /\{\{exec\}\}( ?)([A-Za-z0-9._-]*)/g
236
264
 
265
+ // Each occurrence is detected for ITS bin: a provider skill's
266
+ // `skitterspec-github` and a command's `skitterspec` come from two packages
267
+ // that may be installed in two different places.
237
268
  function renderExec(content, dir, env = process.env) {
238
269
  if (!content.includes('{{exec}}')) return content
239
- const { runner, rung } = detectRunner(dir, env)
240
270
  return content.replace(EXEC_RE, (_m, sp, bin) => {
241
- if (rung === 'none') return bin ? `npx -p ${distributionPackage()} ${bin}` : 'npx'
271
+ const { runner, rung } = detectRunner(dir, env, bin || undefined)
272
+ if (rung === 'none') return bin ? `npx -p ${packageForBin(bin)} ${bin}` : 'npx'
242
273
  const prefix = runner === 'npx' ? 'npx --no-install' : runner
243
274
  if (!prefix) return bin
244
275
  return `${prefix}${sp}${bin}`
@@ -314,7 +345,7 @@ function launcherPrefix(dir) {
314
345
  }
315
346
 
316
347
  function launcherFor(bin, dir) {
317
- const script = LAUNCHER.replace('{{pkg}}', distributionPackage())
348
+ const script = LAUNCHER.replace('{{pkg}}', packageForBin(bin))
318
349
  .replace('{{bin}}', bin)
319
350
  .replace('{{prefix}}', launcherPrefix(dir))
320
351
  return `node -e "${script}" --`
@@ -324,8 +355,10 @@ function launcherFor(bin, dir) {
324
355
  // install and the `npx -p` fallback resolve the same from any directory.
325
356
  function renderCommand(content, dir, env = process.env) {
326
357
  if (!content.includes('{{exec}}')) return content
327
- if (detectRunner(dir, env).rung !== 'local') return renderExec(content, dir, env)
328
- return content.replace(EXEC_RE, (_m, _sp, bin) => (bin ? launcherFor(bin, dir) : 'node'))
358
+ return content.replace(EXEC_RE, (match, _sp, bin) => {
359
+ if (bin && detectRunner(dir, env, bin).rung === 'local') return launcherFor(bin, dir)
360
+ return renderExec(match, dir, env)
361
+ })
329
362
  }
330
363
 
331
364
  // Which managed files carry the token: markdown only. Hooks and JSON templates
@@ -465,7 +498,9 @@ function managedTargets(dir) {
465
498
  abs: targetAbs,
466
499
  bundled: render(fs.readFileSync(path.join(ASSETS, assetRel), 'utf8'), dir),
467
500
  })
468
- for (const name of SKILLS) add(path.join('skills', name, 'SKILL.md'), path.join(dir, '.claude', 'skills', name, 'SKILL.md'))
501
+ for (const name of SKILLS) {
502
+ for (const file of listSkillFiles(name)) add(path.join('skills', name, file), path.join(dir, '.claude', 'skills', name, file))
503
+ }
469
504
  for (const name of COMMANDS)
470
505
  add(path.join('commands', name), path.join(dir, '.claude', 'commands', name), renderCommand)
471
506
  for (const name of RULES) add(path.join('rules', name), path.join(dir, '.claude', 'rules', name))
@@ -507,12 +542,16 @@ function readManifest(dir) {
507
542
  scope: parsed.scope === 'local' ? 'local' : 'team',
508
543
  // Absent means enabled: only `disable` writes the field.
509
544
  enabled: parsed.enabled !== false,
545
+ // The package that wrote it — what `update --all` runs here. Absent on
546
+ // manifests written before feat-global-install: cannot tell, and the
547
+ // caller infers it rather than this guessing.
548
+ distribution: typeof parsed.distribution === 'string' ? parsed.distribution : null,
510
549
  }
511
550
  }
512
551
  } catch {
513
552
  /* missing or malformed → empty baseline */
514
553
  }
515
- return { version: MANIFEST_VERSION, files: {}, baselined: false, scope: 'team', enabled: true }
554
+ return { version: MANIFEST_VERSION, files: {}, baselined: false, scope: 'team', enabled: true, distribution: null }
516
555
  }
517
556
 
518
557
  function writeManifest(dir, files, { local = false, enabled = true } = {}) {
@@ -520,7 +559,7 @@ function writeManifest(dir, files, { local = false, enabled = true } = {}) {
520
559
  ensureDir(path.dirname(target))
521
560
  const sorted = {}
522
561
  for (const k of Object.keys(files).sort()) sorted[k] = files[k]
523
- const body = local ? { version: MANIFEST_VERSION, scope: 'local', files: sorted } : { version: MANIFEST_VERSION, files: sorted }
562
+ const body = { version: MANIFEST_VERSION, distribution: distributionPackage(), ...(local ? { scope: 'local' } : {}), files: sorted }
524
563
  // Written only when false, so an enabled install's manifest reads exactly as
525
564
  // every manifest written before `disable` existed.
526
565
  if (!enabled) body.enabled = false
@@ -669,12 +708,9 @@ function copyAsset(dir, assetRelPath, targetAbs, opts) {
669
708
 
670
709
  function installSkills(dir, opts) {
671
710
  for (const name of SKILLS) {
672
- copyAsset(
673
- dir,
674
- path.join('skills', name, 'SKILL.md'),
675
- path.join(dir, '.claude', 'skills', name, 'SKILL.md'),
676
- opts,
677
- )
711
+ for (const file of listSkillFiles(name)) {
712
+ copyAsset(dir, path.join('skills', name, file), path.join(dir, '.claude', 'skills', name, file), opts)
713
+ }
678
714
  }
679
715
  }
680
716
 
@@ -687,11 +723,18 @@ function installCommands(dir, opts) {
687
723
  // real work to do either way — skills, rules, folders — and none of it needs
688
724
  // the CLI reachable later. Silence here is what let a project install cleanly
689
725
  // and hand back four commands that 404 on first use.
690
- if (COMMANDS.length && detectRunner(dir).rung === 'none') {
726
+ //
727
+ // It asks for `skitterspec` BY NAME: a provider no longer answers to it
728
+ // (feat-global-install), so a provider installed alone leaves every command
729
+ // and every skill's `skitterspec …` with nothing behind it — and the fix is
730
+ // the base installed alongside, which the warning names.
731
+ if (COMMANDS.length && detectRunner(dir, process.env, 'skitterspec').rung === 'none') {
732
+ const base = packageForBin('skitterspec')
733
+ const beside = distributionPackage() === base ? '' : ` alongside ${distributionPackage()}`
691
734
  report.warnings.push(
692
735
  `the skitterspec CLI could not be found here, so the ${COMMANDS.length} slash ` +
693
- `command(s) were written to fetch it on every run (\`npx -p ${distributionPackage()}\`) — ` +
694
- `install it (npm i -g ${distributionPackage()}, or add it as a dev ` +
736
+ `command(s) were written to fetch it on every run (\`npx -p ${base}\`) — ` +
737
+ `install ${base}${beside} (npm i -g, or as a dev ` +
695
738
  'dependency) and re-run `skitterspec update` to rewrite them',
696
739
  )
697
740
  }
@@ -708,6 +751,99 @@ function installRule(dir, opts) {
708
751
  }
709
752
  }
710
753
 
754
+ // The project's own conventions — its typecheck and test commands — written
755
+ // once from a template and then the project's to edit. It is deliberately NOT
756
+ // a managed file: no manifest entry, never overwritten (not even by
757
+ // `--force`), never pruned, so filling it in trips no hash guard. That is the
758
+ // point of it: the conventions used to live inside the managed
759
+ // `spec-planning.md`, where tailoring them made the whole file "customized".
760
+ const CONVENTIONS_FILE = path.join('.claude', 'rules', 'project-conventions.md')
761
+
762
+ function installConventions(dir) {
763
+ const target = path.join(dir, CONVENTIONS_FILE)
764
+ if (fs.existsSync(target)) return // the project's, whatever it holds
765
+ ensureDir(path.dirname(target))
766
+ fs.writeFileSync(target, fs.readFileSync(path.join(ASSETS, 'project-conventions.md'), 'utf8'))
767
+ report.created.push(rel(dir, target))
768
+ }
769
+
770
+ // A customized `spec-planning.md` from before feat-rules-budget, whose only
771
+ // edits are in its old "Project conventions" section: carry the section into
772
+ // `project-conventions.md` and take the new rule, so the host stops loading
773
+ // 66k of the old one. Runs before the managed loop, which then finds the rule
774
+ // pristine and records it. Under `--force` it still runs first, so a
775
+ // forced update keeps the conventions the force would otherwise overwrite.
776
+ //
777
+ // WHAT WOULD FOOL THIS: an edit that exactly restores some other shipped
778
+ // version's text outside the section. That is still unedited text we shipped,
779
+ // so replacing it loses nothing. Everything else is cannot-tell: the file is
780
+ // kept and a warning says how to finish by hand (negative-checks.md rule 4).
781
+ function migrateConventions(dir, manifest, force) {
782
+ const relPath = '.claude/rules/spec-planning.md'
783
+ const target = managedTargets(dir).find((t) => t.relPath === relPath)
784
+ if (!target) return
785
+ const state = managedState(dir, relPath, manifest, target.bundled)
786
+ if (state !== 'customized' && state !== 'adopted') return
787
+ const onDisk = fs.readFileSync(target.abs, 'utf8')
788
+ const conventions = path.join(dir, CONVENTIONS_FILE)
789
+ const template = fs.readFileSync(path.join(ASSETS, 'project-conventions.md'), 'utf8')
790
+ const parts = split(onDisk)
791
+ const known = parts && KNOWN().has(strippedHash(onDisk))
792
+ const free = !fs.existsSync(conventions) || sameContent(fs.readFileSync(conventions, 'utf8'), template)
793
+ if (!known || !free) {
794
+ if (force) return // --force replaces the file anyway; nothing to advise
795
+ report.warnings.push(
796
+ `${relPath} kept (${Math.round(onDisk.length / 1000)}k chars, edited) — it loads in every session. ` +
797
+ `Move your edits into ${CONVENTIONS_FILE.split(path.sep).join('/')}, then run \`skitterspec update --force\``,
798
+ )
799
+ return
800
+ }
801
+ ensureDir(path.dirname(conventions))
802
+ fs.writeFileSync(conventions, `# Project conventions\n\n${parts.body}\n`)
803
+ report.created.push(`${CONVENTIONS_FILE.split(path.sep).join('/')} (moved from ${relPath})`)
804
+ fs.writeFileSync(target.abs, target.bundled)
805
+ writtenHashes[relPath] = sha1(target.bundled)
806
+ }
807
+
808
+ // What Claude Code loads into EVERY session from this install: each rule under
809
+ // `.claude/rules/` that skitterspec wrote (managed, or the conventions file)
810
+ // and that carries no `paths:` front-matter, plus the managed CLAUDE.md block.
811
+ // The budget test hangs on this (feat-rules-budget).
812
+ //
813
+ // WHAT WOULD FOOL THIS: front-matter it cannot parse. Anything other than a
814
+ // leading `---` block holding a `paths:` key counts as always-loaded, so a
815
+ // cannot-tell over-counts — the direction that fails the budget loudly rather
816
+ // than passing it quietly.
817
+ function hasPathsFrontMatter(text) {
818
+ const m = /^---\r?\n([\s\S]*?)\r?\n---\r?\n/.exec(text)
819
+ return Boolean(m && /^paths:/m.test(m[1]))
820
+ }
821
+
822
+ function alwaysLoaded(dir) {
823
+ const rows = []
824
+ const rules = [
825
+ ...managedTargets(dir)
826
+ .filter((t) => t.relPath.startsWith('.claude/rules/'))
827
+ .map((t) => t.abs),
828
+ path.join(dir, CONVENTIONS_FILE),
829
+ ]
830
+ for (const abs of [...new Set(rules)]) {
831
+ if (!fs.existsSync(abs)) continue
832
+ const text = fs.readFileSync(abs, 'utf8')
833
+ if (!hasPathsFrontMatter(text)) rows.push({ path: rel(dir, abs), chars: text.length })
834
+ }
835
+ for (const name of ['CLAUDE.md', 'CLAUDE.local.md']) {
836
+ const file = path.join(dir, name)
837
+ if (!fs.existsSync(file)) continue
838
+ const text = fs.readFileSync(file, 'utf8')
839
+ const start = text.indexOf(SPEC_MARKER_START)
840
+ const end = text.indexOf(SPEC_MARKER_END, start)
841
+ if (start === -1 || end === -1) continue
842
+ rows.push({ path: `${name} (skitterspec section)`, chars: end + SPEC_MARKER_END.length - start })
843
+ }
844
+ return { rows, total: rows.reduce((n, r) => n + r.chars, 0) }
845
+ }
846
+
711
847
  // Register the review-gate hook in the project's committed settings, so a
712
848
  // phase that owes a verdict is enforced one level below the skills. Best-effort
713
849
  // in exactly the way `trustWorktreeRoot` is: a settings file we cannot parse is
@@ -1084,7 +1220,9 @@ function resync(dir, { force = false, claudeMd = true, diff = false, local = fal
1084
1220
  resolveScope(dir, local)
1085
1221
  if (scope === 'local') convertCommitted(dir)
1086
1222
  const manifest = readManifest(dir)
1223
+ migrateConventions(dir, manifest, force)
1087
1224
  for (const t of managedTargets(dir)) resyncManagedFile(dir, t, manifest, force)
1225
+ installConventions(dir)
1088
1226
  installFolders(dir)
1089
1227
  removeRetiredFiles(dir)
1090
1228
  pruneRetiredManaged(dir, manifest)
@@ -1335,6 +1473,7 @@ function localManagedPaths(dir) {
1335
1473
  function localExcludes(dir) {
1336
1474
  return [
1337
1475
  ...localManagedPaths(dir),
1476
+ CONVENTIONS_FILE.replace(/\\/g, '/'),
1338
1477
  'CLAUDE.local.md',
1339
1478
  '.claude/settings.local.json',
1340
1479
  MANIFEST_FILE.replace(/\\/g, '/'),
@@ -1352,7 +1491,7 @@ function localExcludes(dir) {
1352
1491
  // and the hooks into a new .claude/settings.json (bug-local-scope-worktree).
1353
1492
  function localSeedFiles(dir) {
1354
1493
  if (readManifest(dir).scope !== 'local') return []
1355
- return [...localManagedPaths(dir), '.claude/settings.local.json', 'CLAUDE.local.md', MANIFEST_FILE.replace(/\\/g, '/')]
1494
+ return [...localManagedPaths(dir), CONVENTIONS_FILE.replace(/\\/g, '/'), '.claude/settings.local.json', 'CLAUDE.local.md', MANIFEST_FILE.replace(/\\/g, '/')]
1356
1495
  }
1357
1496
 
1358
1497
  const EXCLUDE_START = '# >>> skitterspec (local install)'
@@ -1615,8 +1754,10 @@ function switchNames() {
1615
1754
  return [...SKILLS, ...COMMANDS.map((c) => c.replace(/\.md$/, ''))]
1616
1755
  }
1617
1756
 
1757
+ // The conventions file is switched with the rules: it is not managed, but a
1758
+ // disabled install should not go on loading half of itself.
1618
1759
  function ruleExcludes() {
1619
- return RULES.map((r) => `**/.claude/rules/${r}`)
1760
+ return [...RULES, path.basename(CONVENTIONS_FILE)].map((r) => `**/.claude/rules/${r}`)
1620
1761
  }
1621
1762
 
1622
1763
  // The local settings, parsed — `{}` when absent, null when not valid JSON.
@@ -1803,6 +1944,9 @@ function uninstall(dir, { yes = false, inFlight = [], cannotTell = null, log = (
1803
1944
  const targets = new Map()
1804
1945
  for (const t of managedTargets(dir)) targets.set(t.relPath.split(path.sep).join('/'), t.bundled)
1805
1946
  for (const k of Object.keys(manifest.files)) if (!targets.has(k)) targets.set(k, undefined)
1947
+ // The conventions file is not managed, but a local install wrote it: the
1948
+ // untouched template goes, and a filled-in one is parked like an edit.
1949
+ targets.set(CONVENTIONS_FILE.split(path.sep).join('/'), fs.readFileSync(path.join(ASSETS, 'project-conventions.md'), 'utf8'))
1806
1950
  const remove = []
1807
1951
  const keep = []
1808
1952
  const exclude = localExcludeFile(dir)
@@ -1957,6 +2101,7 @@ async function init({ dir, force, claudeMd, mode, isolation, workspaceMode, gati
1957
2101
  installSkills(dir, { force })
1958
2102
  installCommands(dir, { force })
1959
2103
  installRule(dir, { force })
2104
+ installConventions(dir)
1960
2105
  installHooks(dir, { force })
1961
2106
  installFolders(dir)
1962
2107
  removeRetiredFiles(dir)
@@ -1991,6 +2136,9 @@ module.exports = {
1991
2136
  writeManifest,
1992
2137
  managedTargets,
1993
2138
  managedState,
2139
+ alwaysLoaded,
2140
+ CONVENTIONS_FILE,
2141
+ listSkillFiles,
1994
2142
  claudeMdSectionState,
1995
2143
  checkSync,
1996
2144
  isExistingSetup,
@@ -2004,6 +2152,8 @@ module.exports = {
2004
2152
  detectPackageManager,
2005
2153
  detectRunner,
2006
2154
  renderCommand,
2155
+ hasPathInstall,
2156
+ packageForBin,
2007
2157
  renderExec,
2008
2158
  distributionPackage,
2009
2159
  localExcludes,
@@ -0,0 +1,103 @@
1
+ {
2
+ "stripped": [
3
+ "00d614bcd77d303496dcfa8c083bca7dd4be5e5e",
4
+ "0da16a55e2684023b5d000399705d05118450a6e",
5
+ "101d415dd33d3441d9dd6a0ce3369a346af6e674",
6
+ "142443be77691c80752b9db2b79e9c7844699900",
7
+ "1646238461f08f6e124b69c5695bbf837d05509e",
8
+ "16625ecd12f2532f8d831570571dfe30718811f2",
9
+ "16a8f86d094345c64c8aebf2a0b6f73398edbdff",
10
+ "177c47b3f43231ef71799f97ca69f8ce87655b1b",
11
+ "1bc0427c4d346b6807fa5c716ce05dfaacac807a",
12
+ "1d4bc86bf7591eec3a261484a26103556e824714",
13
+ "27aedcedab1faf84111f9bc3ae6a2009e34b3c94",
14
+ "27d3704fd73e20c844f9a11ea105db22dd9f9dcf",
15
+ "29fdd3f629ae3b20657ce46030d9f20e281e59ce",
16
+ "2a138f3c8e230f082f1d96a98fe313a089bab29a",
17
+ "2ce42303ad4cb04dc07f453f01581106f4ab30e8",
18
+ "30ad650da2613a3456e82c8004c237ba5e6c6e4e",
19
+ "30fcb8f84f591aeda48c512145d143edb7b82b13",
20
+ "319330c5f62e761070707b3c4e3830bfedf0de0d",
21
+ "34a6062629a263593647d4f8d362cfe61c86b39f",
22
+ "35065251debe5a3ba3a61bf7dc6cff490c682a97",
23
+ "37830372d0d71daefb003216fce0c5bf5032ebd1",
24
+ "38e35aefa0f75d7d552465393366c223a2869d75",
25
+ "3d8f0082c299baaef3107cfbb0769c0d47fc3686",
26
+ "3dc35cdbecd966d58865543e4d9938fe051d6215",
27
+ "474c1dcbc23317d9533fc29308ed63fc706ebb4e",
28
+ "4adbda577ea0211a0bd01558b88a79f14bf8bf70",
29
+ "4af24b4e280d53677d65221bed641915b9180697",
30
+ "4e475b5d32dfb0ffddd096a96c93995a52818b8b",
31
+ "525bfb71c1f299ab88aa44205169ed1153102fd0",
32
+ "531d18961bb86aeb10574b11c7ffcb4c68a58f1d",
33
+ "5362a0d7327152e67116eca2dec0f38276141132",
34
+ "5589d4c145cf3d23c3c455ad4352fd731eeeaa76",
35
+ "63d5082fd8d39670709199e0f174e5c4fde73683",
36
+ "66d4b40832bff74063794e82675481af3349ac98",
37
+ "67565db2c18d8fc05e6eeac7b630b4b8bfb58562",
38
+ "6b2c80d5a19d5ef53c216ff65eeaadd6693529ee",
39
+ "72c2ce1ce1956c41b04eb421ff8ea4903a28b461",
40
+ "77d5f7b34ea3d98722aee7b95f794b3288e6b7a8",
41
+ "7873adab80f7bfb13d27aa198eaf392af834866c",
42
+ "7f8ada09afb3eaeb4a950ba2875a26e7fbd28185",
43
+ "82813bbc39d04097f42c3c048fb68814e92b5c80",
44
+ "83cd30d39fa097c1acd3b6caca9b42ec98f221fa",
45
+ "84570f1aeaf2aa25ace79be83d20e2827a9a89e8",
46
+ "866b3bad618e8350c5e9600bdf73d4d6c9ca76c2",
47
+ "87c6382e7d804f28955c2db3d1b5b1213a5518c0",
48
+ "89c8893a89b4fcaff9de38f840695f9b4588ce75",
49
+ "8abebcdb1c8663252946c2d0a598159df57f7660",
50
+ "8b0cd5f98215d0e0e10f633b5cc7734496e546d8",
51
+ "8ec324adae5463e81dab04f2f44a08d3bbb6718a",
52
+ "8fb29110fa777932c34e68fe3c3c12a2bab2c303",
53
+ "8fba597927c698170543572e0d41b77b6e007e8a",
54
+ "94989e916fbf809d022b0eb5a29b4bfa175f19e4",
55
+ "94b5a4b049fb70b9becba4e8adb31ae17d24343e",
56
+ "974d823ad1f2e227d92ff686816fddc8b8702ae8",
57
+ "9f4bd04e3560ce997e95e522a8980e004e59dc1d",
58
+ "a22f4c3a4809593d4442b77c54e02621d6c490b1",
59
+ "a4b002345a4f04aaa944bb7c0d0e2a6fc4687c9b",
60
+ "a5b1e0a0b780e2d9c795b9ec9b1b3bb050999234",
61
+ "a749acd6f2b32cbb8b0916fad79e158936bcf8b8",
62
+ "aca552e82c3e13ee64de3297afba383fa11110ce",
63
+ "acb03230bf1b2e95f548f2587940e67c9a0f1481",
64
+ "acb9fb97b0f7698cf03a75778608674fe782c492",
65
+ "adb102579698445342345a803c140116d7e17212",
66
+ "b166726bca06618ffa7be874b1153d622e156acf",
67
+ "b4624d975b2a73749ffbeefc51c5a7b1ace39916",
68
+ "b49e2c0d724a5c3ef38d29151b5d8e3abe373462",
69
+ "ba2cdbe612ade3b0d1c146921d704da4370873c3",
70
+ "bc7676c1af761ac98fb0d7e430c369639dfb5891",
71
+ "c2b9fbc8df5b7f1e5b7a0228415b529ae952a930",
72
+ "c306804166c56e055727f450d467978a894397ca",
73
+ "c64f9cba2ad04bddfb8c48a15837579be1cd1e40",
74
+ "c80dbed0bde66469fc0ffbbeece9e2037aa28351",
75
+ "caaa3b1c717b1331d87b08953ed212d2f7c4f366",
76
+ "cd3d6b1c5c674f617d29b26f0e79a8d8f11cffc3",
77
+ "d0c3bd01b81d3ced60a29e35abd3125a052a8b4b",
78
+ "d1ff0e181c50833681f3d3827daab9746aee5bc8",
79
+ "d256d8bed251b7ee9f3bc4bd8dc03fa2e8d2f60a",
80
+ "d3290f9c881e9429bce180594d5015fbadbf752c",
81
+ "d4ab31cd6e813b3eee1981f58a2eaa106a543775",
82
+ "d4e89396b13de35687e9977c419cc1691beac50a",
83
+ "d58ce635f3cabac629c9efddd5015faf7d93bc99",
84
+ "d5a12cfe6070fc4f5148cc1bb366c63ff7474138",
85
+ "d886fc1e7416f28d4085e61814528ede767e71ac",
86
+ "da0ee5d1b3fcc1f0230c4404177eb9f4ac687f2b",
87
+ "dbb4d500bff7e609feac9c945891f35891195587",
88
+ "defe012b01373a133226e24a984b161ae66709e1",
89
+ "e018e3e4e8b040250fa6c06e3fa1ca783b12ecd7",
90
+ "e1d2db14ddc1b4ec0f17ea5e1bbf7fc8115d83ef",
91
+ "e89f0d25a3aefe8d9b1807a00cb946458d79bae3",
92
+ "e9afec7f0c9949373b617b8a5593d22be6219204",
93
+ "ea6914674684c6a0cf910abf3afa43053080c9be",
94
+ "eb8de3293bcd6ebe4e79bcbc9a3e8e70093d0cf3",
95
+ "ebaaf560a079abfccf7ba62edde7624168f7d37a",
96
+ "f2d5dba128a50f4c7ddef3f8ceae761f5f62dfb0",
97
+ "f2e648c8bdbbb6134d4cd7e056e8a036a8976ce4",
98
+ "f54a2aa39cd714d694e264067c65a439e6c94ecf",
99
+ "f7995e59839ec4a3bc3fe09d57d0e27db7d1755d",
100
+ "f9223c0d65ff12c6e3d8675cde03c9bcac65ffa4",
101
+ "fdefc8484cbf56d6a9869c291725171a0b45d443"
102
+ ]
103
+ }