@cbartens/bkit 5.0.0 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/.bkit/README.md +10 -14
  2. package/.bkit/core/.bkit/README.md +9 -13
  3. package/.bkit/core/.bkit/cloud.md +15 -24
  4. package/.bkit/core/.bkit/comparison.md +4 -1
  5. package/.bkit/core/.bkit/install.md +54 -149
  6. package/.bkit/core/.bkit/jsonl.md +5 -5
  7. package/.bkit/core/.bkit/templates.md +2 -3
  8. package/.bkit/core/.bkit/workflows.md +7 -3
  9. package/.bkit/core/engine/checks/after/auth.ts +16 -114
  10. package/.bkit/core/engine/checks/after/ci-yml.ts +36 -74
  11. package/.bkit/core/engine/checks/after/index.ts +156 -182
  12. package/.bkit/core/engine/checks/after/suppression.ts +53 -0
  13. package/.bkit/core/engine/checks/before/env.ts +4 -18
  14. package/.bkit/core/engine/checks/before/files.ts +2 -0
  15. package/.bkit/core/engine/cli.ts +4 -8
  16. package/.bkit/core/engine/commands/install/doctor.ts +9 -2
  17. package/.bkit/core/engine/commands/install/install.ts +24 -2
  18. package/.bkit/core/engine/commands/install/uninstall.ts +23 -0
  19. package/.bkit/core/engine/commands/install/upgrade.ts +14 -3
  20. package/.bkit/core/engine/commands/lib.ts +4 -3
  21. package/.bkit/core/engine/install/cloud-env.ts +0 -1
  22. package/.bkit/core/engine/install/modules/cloud.ts +2 -3
  23. package/.bkit/core/engine/install/modules/core.ts +33 -13
  24. package/.bkit/core/engine/install/payload-links.ts +150 -0
  25. package/.bkit/core/engine/install/template-copies.ts +1 -1
  26. package/.bkit/core/engine/shared/egress.ts +1 -1
  27. package/.bkit/core/workflows/bkit-debug.md +19 -12
  28. package/.bkit/shared/.bkit/.env.example +2 -24
  29. package/.bkit/shared/docs/deployments.md +2 -7
  30. package/.bkit/shared/docs/security.md +1 -1
  31. package/.bkit/shared/gitignore +5 -0
  32. package/.bkit/templates/.claude/hooks/bkit-cloud-bootstrap.sh +0 -5
  33. package/.bkit/templates/.cursor/Dockerfile +1 -1
  34. package/.bkit/templates/.cursor/environment.json +1 -1
  35. package/.bkit/templates/.github/renovate.json5 +0 -15
  36. package/.bkit/templates/.github/workflows/bkit-ci.yml +2 -22
  37. package/.bkit/templates/.github/workflows/bkit-cloud.yml +0 -2
  38. package/.bkit/templates/.github/workflows/bkit-renovate.yml +0 -5
  39. package/CHANGELOG.md +17 -0
  40. package/README.md +5 -6
  41. package/dist/checks/after/auth.js +16 -108
  42. package/dist/checks/after/ci-yml.js +30 -67
  43. package/dist/checks/after/index.js +136 -152
  44. package/dist/checks/after/suppression.js +39 -0
  45. package/dist/checks/before/env.js +4 -14
  46. package/dist/checks/before/files.js +2 -0
  47. package/dist/cli.js +4 -8
  48. package/dist/commands/install/doctor.js +4 -2
  49. package/dist/commands/install/install.js +16 -2
  50. package/dist/commands/install/uninstall.js +24 -0
  51. package/dist/commands/install/upgrade.js +14 -3
  52. package/dist/commands/lib.js +4 -3
  53. package/dist/install/cloud-env.js +0 -1
  54. package/dist/install/modules/cloud.js +2 -3
  55. package/dist/install/modules/core.js +33 -13
  56. package/dist/install/payload-links.js +119 -0
  57. package/dist/install/template-copies.js +1 -1
  58. package/dist/shared/egress.js +1 -1
  59. package/package.json +2 -2
  60. package/.bkit/core/engine/checks/after/vercel.ts +0 -101
  61. package/dist/checks/after/vercel.js +0 -102
@@ -26,6 +26,7 @@ import { readTemplate } from "../../render/parts.js";
26
26
  import { getInstallManifest, } from "../../install/manifest.js";
27
27
  import { isConsumerModified, readBkitVersion } from "../../install/version-file.js";
28
28
  import { getPkgRoot, getSharedRoot, findTemplateSource, TEMPLATE_COPIES_DIR, } from "../../shared/package-roots.js";
29
+ import { PAYLOAD_LINKS } from "../../install/payload-links.js";
29
30
  import { removeOpencodeProviderBlock, renderOpencodeJson } from "../../install/modules/opencode.js";
30
31
  import { CLAUDE_CLOUD_RELPATH, CURSOR_CLOUD_RELPATH, resolveClaudeDerivedAllows, } from "../../install/cloud-env.js";
31
32
  import { LOG_PREFIX, setLogPrefix } from "../../shared/log-prefix.js";
@@ -667,6 +668,29 @@ export async function runUninstall(modules, ctx) {
667
668
  }
668
669
  }
669
670
  }
671
+ // Full/core uninstall: the payload view links (`.bkit/core`, `.bkit/shared`) are
672
+ // bkit-created symlinks into the package and go with it. Symlinks ONLY — a real
673
+ // directory or file at that path is consumer content (install's no-clobber guard)
674
+ // and stays. Never in dogfood, where `.bkit/core` is bkit's own source.
675
+ if (moduleList.includes("core") && path.resolve(ctx.cwd) !== getPkgRoot()) {
676
+ for (const { relPath } of PAYLOAD_LINKS) {
677
+ const linkAbs = path.join(ctx.cwd, relPath);
678
+ let st = null;
679
+ try {
680
+ st = fs.lstatSync(linkAbs);
681
+ }
682
+ catch {
683
+ st = null; // absent
684
+ }
685
+ if (st?.isSymbolicLink() !== true)
686
+ continue;
687
+ result.deleted.push(relPath);
688
+ if (!ctx.dryRun) {
689
+ fs.rmSync(linkAbs, { force: true });
690
+ console.log(`${ctx.logPrefix} delete: ${relPath} (payload view link)`);
691
+ }
692
+ }
693
+ }
670
694
  // Prune bkit-authored dirs left empty by the deletions above (e.g. .claude/agents,
671
695
  // .claude/hooks). Candidates are the parent
672
696
  // dirs of everything deleted, plus their ancestors; each is removed ONLY when it is actually
@@ -34,6 +34,7 @@ import { detectInstalledModules } from "./check.js";
34
34
  import { remapTemplateDest } from "../../install/template-copies.js";
35
35
  import { CLAUDE_CLOUD_RELPATH, CURSOR_CLOUD_RELPATH, writeClaudeCloudDoc, writeCursorCloudDoc, writeNetworkAllowlistArtifact, writeCursorCliPermissionsArtifact, } from "../../install/cloud-env.js";
36
36
  import { syncTemplateCopies, formatTemplateChanges } from "../../install/template-copies.js";
37
+ import { formatPayloadLinkChanges, syncPayloadLinks } from "../../install/payload-links.js";
37
38
  import { renderOpencodeJson, reconcileOpencodeJson } from "../../install/modules/opencode.js";
38
39
  import { renderManagedOutputs } from "../../install/modules/index.js";
39
40
  import { reconcileMcpJson, enrichClaudeSettingsAllows } from "../../install/modules/claude.js";
@@ -359,8 +360,8 @@ async function resolveLatestPublishedVersion(cwd) {
359
360
  const r = spawnSync("pnpm", ["view", "@cbartens/bkit", "version"], { cwd, encoding: "utf-8" });
360
361
  if (r.status !== 0 || !r.stdout || !r.stdout.trim()) {
361
362
  console.error(`${LOG_PREFIX} could not resolve the latest @cbartens/bkit version from the registry ` +
362
- `(pnpm view exit ${r.status ?? "null"}). Ensure GitHub Packages read auth (BKIT_GH_TOKEN_INSTALL, ` +
363
- `classic PAT, read:packages), or pin a version with --to=<version>.`);
363
+ `(pnpm view exit ${r.status ?? "null"}). Check your network / registry access, ` +
364
+ `or pin a version with --to=<version>.`);
364
365
  process.exit(1);
365
366
  }
366
367
  return r.stdout.trim();
@@ -419,7 +420,7 @@ export async function runSelfBump(flags, cwd) {
419
420
  });
420
421
  if (add.status !== 0) {
421
422
  console.error(`${LOG_PREFIX} \`${addCmd}\` failed (exit ${add.status ?? "null"}). ` +
422
- `Most common cause: GitHub Packages auth — set BKIT_GH_TOKEN_INSTALL (classic PAT, read:packages). Nothing re-rendered.`);
423
+ `Check your network / registry access. Nothing re-rendered.`);
423
424
  process.exit(1);
424
425
  }
425
426
  // Re-exec the just-installed (NEW) bkit so IT renders + re-pins, not this old process.
@@ -580,6 +581,16 @@ export async function runUpgradeCommand(upgradeFlags) {
580
581
  const templateReport = formatTemplateChanges(templateChanges);
581
582
  if (templateReport)
582
583
  console.log(`${LOG_PREFIX} ${templateReport}`);
584
+ // Payload view links — the same sync install runs (`.bkit/core` + `.bkit/shared`
585
+ // point into the installed package). Never clobbers a real directory; a platform
586
+ // refusal is reported, never fatal. Throwaway WriteSet: links carry no hash.
587
+ const linkChanges = syncPayloadLinks(process.cwd(), {
588
+ dryRun: upgradeFlags.dryRun,
589
+ ws: { writes: [] },
590
+ });
591
+ const linkReport = formatPayloadLinkChanges(linkChanges);
592
+ if (linkReport)
593
+ console.log(`${LOG_PREFIX} ${linkReport}`);
583
594
  // Re-render all installed provider blocks for upgrade.
584
595
  // The candidates walk above handles the ACTIVE provider's block via renderOpencodeJson.
585
596
  // For each ADDITIONAL installed provider, reconcile their template block into opencode.json
@@ -199,8 +199,9 @@ const isHelp = (arg) => arg === "--help" || arg === "-h";
199
199
  * Run `argv` (without the leading `bkit`) if it names a registered command.
200
200
  * Returns the exit code, or null when `argv` is not a command, so the caller falls
201
201
  * through to the classic verbs. A noun that is also a classic verb (`status`)
202
- * routes only when the second word is one of its verbs, so `bkit status` keeps
203
- * its classic meaning.
202
+ * routes only when the second word is one of its verbs or a help flag, so
203
+ * `bkit status` keeps its classic meaning while `bkit status --help` still lists
204
+ * the noun's own verbs.
204
205
  */
205
206
  export async function runCommand(argv, commands, options) {
206
207
  const io = options.io ?? processIo;
@@ -209,7 +210,7 @@ export async function runCommand(argv, commands, options) {
209
210
  return null;
210
211
  const verb = argv[1];
211
212
  const isVerb = verb !== undefined && Object.hasOwn(cmd.verbs, verb);
212
- if (!isVerb && options.classicVerbs.has(cmd.noun))
213
+ if (!isVerb && options.classicVerbs.has(cmd.noun) && !isHelp(verb))
213
214
  return null;
214
215
  const tag = logTag(cmd.noun);
215
216
  if (!isVerb) {
@@ -35,7 +35,6 @@ export const SESSION_HIJACK_KEYS = [
35
35
  // (e.g. BKIT_GH_TOKEN already in `.bkit/.env`) keeps its real resolved value.
36
36
  const BASELINE_TOKEN_PLACEHOLDERS = [
37
37
  ["BKIT_GH_TOKEN", "<fine-grained PAT — see .bkit/cloud.md § BKIT_GH_TOKEN permissions>"],
38
- ["BKIT_GH_TOKEN_INSTALL", "<classic PAT with read:packages>"],
39
38
  ];
40
39
  // Earlier-compaction override — a bkit constant, not a secret. Appended to the
41
40
  // block when not already resolved from a source file. Claude-harness-only knob —
@@ -74,7 +74,6 @@ export function runCloudModule(ctx) {
74
74
  " - Run `/install-github-app` (Claude Code CLI) to install the Claude GitHub App on your repo. This is required — `claude-code-action@v1` authenticates as the App via OIDC (`id-token: write`); without the App it fails at boot with an OIDC error.\n" +
75
75
  " - GitHub Actions permissions — flip BOTH org AND repo: Settings → Actions → General → Workflow permissions = **Read and write permissions** + tick **Allow GitHub Actions to create and approve pull requests**.\n" +
76
76
  " - Add `ANTHROPIC_API_KEY` to repo secrets (Settings → Secrets and variables → Actions). Used by `claude-code-action@v1` (job env keeps this vendor name; local `.bkit/.env` stores it as `BKIT_ANTHROPIC_API_KEY`).\n" +
77
- " - Do NOT add `BKIT_GH_TOKEN_INSTALL` to this workflow — it is package-install scoped and has no access to the consumer repo. Repo git/gh ops use the auto-provided `github.token` via the workflow's `permissions:` block.\n" +
78
77
  " - Label the issue `bkit:auto` before pushing the build commit — without the label the CI auto-route exits no-op.\n\n" +
79
78
  "OPTIONAL (manual phase launch): after `/install-github-app`, comment `@claude /bkit-plan` (or any phase) on a GitHub issue/PR to launch it from the tracker UI. The App's generated `claude.yml` triggers on mention events; `bkit-cloud.yml` triggers on CI completion + `workflow_dispatch` — the two coexist.\n\n" +
80
79
  "Both the CI-driven path and the `@claude` mention path invoke the same `/bkit-auto` orchestrator (mirrored to `.claude/commands/bkit-auto.md` on each `pnpm bkit install`).",
@@ -90,7 +89,7 @@ export function runCloudModule(ctx) {
90
89
  "IN CLAUDE APP (claude.ai/code → environment selector → + Add environment):\n" +
91
90
  " - Name: the repo name (e.g. `acme-web`) — one environment per repo, since secrets are per-repo.\n" +
92
91
  " - Setup script: paste from bkit's `cloud.md` § Setup script (installs vale + gh + corepack-pinned pnpm — exact versions live in cloud.md, not duplicated here).\n" +
93
- " - Environment variables: `BKIT_GH_TOKEN` (fine-grained PAT for GitHub MCP), `BKIT_GH_TOKEN_INSTALL` (classic PAT with read:packages), `CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=70`.\n" +
92
+ " - Environment variables: `BKIT_GH_TOKEN` (fine-grained PAT for GitHub MCP), `CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=70`.\n" +
94
93
  " - Tracker env vars (GitHub): No tracker PAT needed. Run `gh auth login` once for CLI surface. MCP auth is browser OAuth (automatic on first tool call). Set `BKIT_GH_TOKEN` (fine-grained PAT for GitHub MCP server).\n" +
95
94
  " - Network access: `Trusted` (default). One environment per repo (secrets differ per repo); the setup script + variable *names* are identical across repos, only the values change. See cloud.md § Sharing across repos → Claude.",
96
95
  });
@@ -143,7 +142,7 @@ export function runCloudModule(ctx) {
143
142
  detect: "Cloud env config splits across the repo (`.cursor/Dockerfile` + `.cursor/environment.json`, copied from `.bkit/templates/.cursor/`) and the Cursor Cloud Agents dashboard (secrets, manual).",
144
143
  action: "Copy-paste-ready values (resolved from your `.envrc`) are written to `.cursor/bkit-cloud.md` (gitignored) on every install.\n\n" +
145
144
  "IN THE CLOUD AGENTS DASHBOARD (https://cursor.com/dashboard/cloud-agents → your environment → Secrets tab) — add each as a **Runtime Secret** (loaded as an env var, redacted from the agent's transcript):\n" +
146
- " - `BKIT_GH_TOKEN`, `BKIT_GH_TOKEN_INSTALL`.\n" +
145
+ " - `BKIT_GH_TOKEN`.\n" +
147
146
  " - Tracker secret (Linear): `BKIT_LINEAR_API_KEY` (generate at https://linear.app/settings/api). `LINEAR_ISSUE_ID` is injected per-session — don't hardcode.\n" +
148
147
  " - First session after Dockerfile changes rebuilds the image; subsequent sessions reuse cached layers.\n\n" +
149
148
  "Full recipe in bkit's `cloud.md`; the paste-ready block is in `.cursor/bkit-cloud.md`.",
@@ -6,6 +6,7 @@ import * as path from "node:path";
6
6
  import { writeTier1, writeTier2, ensurePackageJsonScripts } from "../write.js";
7
7
  import { readBkitVersion, writeBkitVersion, hashFile, mergeCanonicalHashes, } from "../version-file.js";
8
8
  import { listFilesRecursive, syncTemplateCopies } from "../template-copies.js";
9
+ import { PAYLOAD_LINK_RELPATHS, syncPayloadLinks } from "../payload-links.js";
9
10
  import { getPkgRoot, getCoreRoot, getSharedRoot, getBkitDocsRoot, TEMPLATE_COPIES_DIR, } from "../../shared/package-roots.js";
10
11
  import { getInstallManifest, BKIT_GATE_SCRIPTS, BKIT_OPTIONAL_GATES } from "../manifest.js";
11
12
  export function listMdFiles(dir, prefix) {
@@ -419,6 +420,33 @@ export function runCoreModule(ctx) {
419
420
  console.log(`${logPrefix} ${tag}template ${verb}: ${path.join(TEMPLATE_COPIES_DIR, p)}`);
420
421
  }
421
422
  }
423
+ // 3b3. Payload view links — `.bkit/core` + `.bkit/shared` symlinks into the
424
+ // installed package (browse-only, gitignored; no-op in dogfood). A real
425
+ // directory or file at either path is never clobbered (advisory); a platform
426
+ // refusal is an advisory, never a failure.
427
+ const linkChanges = syncPayloadLinks(cwd, { dryRun, ws });
428
+ for (const rel of linkChanges.created) {
429
+ console.log(`${logPrefix} ${tag}payload link: ${rel}`);
430
+ }
431
+ for (const rel of linkChanges.repaired) {
432
+ console.log(`${logPrefix} ${tag}payload link repaired: ${rel}`);
433
+ }
434
+ for (const rel of linkChanges.skippedRealDir) {
435
+ advisories.push({
436
+ id: "payload-link-real-dir",
437
+ severity: "advisory",
438
+ detect: `${rel} is a real directory or file, not a view symlink into the installed package — left untouched.`,
439
+ action: `bkit never overwrites consumer content. The ${rel} view is a symlink into node_modules/@cbartens/bkit; if you want it, remove your own ${rel} by hand and re-run \`bkit install\`.`,
440
+ });
441
+ }
442
+ for (const rel of linkChanges.failed) {
443
+ advisories.push({
444
+ id: "payload-link-failed",
445
+ severity: "advisory",
446
+ detect: `could not create the ${rel} view symlink into the installed package (the platform refused).`,
447
+ action: `Browse-only — bkit reads its payload from the package regardless. To add the view by hand on POSIX: ln -s ../node_modules/@cbartens/bkit/${rel} ${rel}`,
448
+ });
449
+ }
422
450
  // 3c. The bkit:gate:* / bkit:deps:* package.json scripts (add-if-missing). The
423
451
  // advisories read the result.
424
452
  seedCorePackageJsonScripts(ctx);
@@ -449,6 +477,9 @@ export function runCoreModule(ctx) {
449
477
  // Template copies carry no hash.
450
478
  if (relPath.startsWith(TEMPLATE_COPIES_DIR + path.sep))
451
479
  continue;
480
+ // Payload view links carry no hash either — a symlink's bytes are the package's.
481
+ if (PAYLOAD_LINK_RELPATHS.has(relPath))
482
+ continue;
452
483
  if (!fs.existsSync(absPath))
453
484
  continue;
454
485
  const hash = hashFile(absPath);
@@ -485,19 +516,8 @@ export function runCoreModule(ctx) {
485
516
  severity: "advisory",
486
517
  detect: "First install detected (.bkit/version was absent).",
487
518
  action: "Post-install steps:\n\n" +
488
- "1. Add BKIT_GH_TOKEN_INSTALL to your GitHub Actions repository secrets:\n" +
489
- " - Create a classic PAT with `read:packages` scope (fine-grained PATs are\n" +
490
- " not currently supported by GitHub Packages npm registry).\n" +
491
- " - GitHub Settings → Secrets and variables → Actions → New repository secret\n" +
492
- " - Name: BKIT_GH_TOKEN_INSTALL\n" +
493
- " - See README.md ## Consumer CI auth for full setup.\n\n" +
494
- "2. Add a `.npmrc` at your repo root with the @cbartens registry mapping (the\n" +
495
- " auth token is NOT stored here — it goes in pnpm's user-level config):\n" +
496
- " @cbartens:registry=https://npm.pkg.github.com\n\n" +
497
- "3. Write the token into pnpm's user-level config (run once; CI does this in its\n" +
498
- " install step). pnpm >=10.34.3 401s on a project-.npmrc ${BKIT_GH_TOKEN_INSTALL} ref:\n" +
499
- ' pnpm config set "//npm.pkg.github.com/:_authToken=$BKIT_GH_TOKEN_INSTALL"\n\n' +
500
- "4. Run `pnpm install` to refresh the lockfile, then commit.\n\n" +
519
+ "1. Run `pnpm install` to refresh the lockfile, then commit.\n\n" +
520
+ "2. See `.bkit/install.md` for consumer setup and `.bkit/README.md` for ongoing ops.\n\n" +
501
521
  "Note: bkit seeded the bkit:gate:* / bkit:deps:* package.json scripts every workflow\n" +
502
522
  "runs (existing values are never touched). The tool scripts they chain (typecheck,\n" +
503
523
  "lint, format:check, lint:prose, slop:delta) and the devDeps those need are yours to\n" +
@@ -0,0 +1,119 @@
1
+ // install/payload-links.ts — the consumer's `.bkit/core` and `.bkit/shared` view
2
+ // links: relative symlinks into the installed package payload (#525), so the
3
+ // workflow / prompt / hook sources are browsable from the consumer repo without
4
+ // copying. Views, not copies — always the installed version, never hashed.
5
+ import * as fs from "node:fs";
6
+ import * as path from "node:path";
7
+ import { getCoreRoot, getPkgRoot, getSharedRoot } from "../shared/package-roots.js";
8
+ // The two view links: a symlink at the consumer-relative `relPath` pointing at the
9
+ // package payload dir `target()` resolves to. Relative targets, so the link keeps
10
+ // working when the repo moves; both dangle on a fresh clone or in CI (no
11
+ // node_modules), which is why the managed `.gitignore` block carries both paths
12
+ // and checks/before/files.ts BKIT_GITIGNORE_LINES lists them.
13
+ export const PAYLOAD_LINKS = [
14
+ { relPath: path.join(".bkit", "core"), target: getCoreRoot },
15
+ { relPath: path.join(".bkit", "shared"), target: getSharedRoot },
16
+ ];
17
+ /** The consumer-relative paths above, as a lookup set (version-hash exclusion). */
18
+ export const PAYLOAD_LINK_RELPATHS = new Set(PAYLOAD_LINKS.map((l) => l.relPath));
19
+ /**
20
+ * Create the view link at `linkAbs` pointing at `targetAbs`: a relative `dir`
21
+ * symlink first; where the platform refuses it (Windows without Developer Mode or
22
+ * elevation) fall back to an absolute `junction`, which needs no privilege.
23
+ * `symlinkFn` is injectable so the platform branch is testable off-Windows.
24
+ */
25
+ export function createPayloadLink(targetAbs, linkAbs, symlinkFn = fs.symlinkSync) {
26
+ const relTarget = path.relative(path.dirname(linkAbs), targetAbs);
27
+ try {
28
+ symlinkFn(relTarget, linkAbs, "dir");
29
+ return "relative";
30
+ }
31
+ catch {
32
+ symlinkFn(targetAbs, linkAbs, "junction");
33
+ return "junction";
34
+ }
35
+ }
36
+ // Create or refresh the consumer's `.bkit/core` + `.bkit/shared` view links into
37
+ // the package payload. Idempotent: a correct link is kept, a dangling or
38
+ // mis-pointed symlink is re-pointed, a real directory or file is NEVER clobbered
39
+ // (skippedRealDir) and a platform refusal is only recorded (failed). Every create
40
+ // or repair pushes a ws write in dry-run and live alike, so `bkit check` flags a
41
+ // missing or broken link as drift. No-op in dogfood: there `.bkit/core` IS the
42
+ // package source, never a view onto it.
43
+ export function syncPayloadLinks(cwd, opts) {
44
+ const changes = {
45
+ created: [],
46
+ repaired: [],
47
+ kept: [],
48
+ skippedRealDir: [],
49
+ failed: [],
50
+ };
51
+ if (path.resolve(cwd) === getPkgRoot())
52
+ return changes;
53
+ for (const { relPath, target } of PAYLOAD_LINKS) {
54
+ const linkAbs = path.join(cwd, relPath);
55
+ const targetAbs = target();
56
+ if (!fs.existsSync(targetAbs)) {
57
+ changes.failed.push(relPath); // package payload missing — package corrupt?
58
+ continue;
59
+ }
60
+ // lstat, not stat: the symlink itself is what matters, never its target.
61
+ let st = null;
62
+ try {
63
+ st = fs.lstatSync(linkAbs);
64
+ }
65
+ catch {
66
+ st = null; // absent
67
+ }
68
+ if (st !== null && !st.isSymbolicLink()) {
69
+ changes.skippedRealDir.push(relPath); // consumer content — never clobber
70
+ continue;
71
+ }
72
+ if (st !== null) {
73
+ // A symlink: keep when it already resolves to the payload, re-point otherwise
74
+ // (dangling — realpathSync throws — or pointing somewhere else).
75
+ let resolves = false;
76
+ try {
77
+ resolves = fs.realpathSync(linkAbs) === fs.realpathSync(targetAbs);
78
+ }
79
+ catch {
80
+ resolves = false;
81
+ }
82
+ if (resolves) {
83
+ changes.kept.push(relPath);
84
+ continue;
85
+ }
86
+ if (!opts.dryRun)
87
+ fs.rmSync(linkAbs);
88
+ }
89
+ if (!opts.dryRun) {
90
+ fs.mkdirSync(path.dirname(linkAbs), { recursive: true });
91
+ try {
92
+ createPayloadLink(targetAbs, linkAbs);
93
+ }
94
+ catch {
95
+ changes.failed.push(relPath);
96
+ continue;
97
+ }
98
+ }
99
+ (st !== null ? changes.repaired : changes.created).push(relPath);
100
+ opts.ws.writes.push({ path: relPath, action: "write" });
101
+ }
102
+ return changes;
103
+ }
104
+ // The upgrade report for a link sync: one line per created, repaired, skipped or
105
+ // failed link. Empty when every link was already correct.
106
+ export function formatPayloadLinkChanges(changes) {
107
+ const lines = [
108
+ ...changes.created.map((p) => ` linked: ${p}`),
109
+ ...changes.repaired.map((p) => ` repaired: ${p}`),
110
+ ...changes.skippedRealDir.map((p) => ` skipped: ${p} — a real directory or file, never overwritten; remove it yourself to get the view link`),
111
+ ...changes.failed.map((p) => ` failed: ${p} — platform refused the symlink (browse-only; bkit reads its payload from the package regardless)`),
112
+ ];
113
+ if (lines.length === 0)
114
+ return "";
115
+ return [
116
+ "Payload view links — `.bkit/core` + `.bkit/shared` point into the installed package (gitignored, browse-only):",
117
+ ...lines,
118
+ ].join("\n");
119
+ }
@@ -85,7 +85,7 @@ function pruneEmptyDirs(root) {
85
85
  }
86
86
  }
87
87
  /** One-line pointer to the template docs, shared by the install and upgrade messages. */
88
- export const TEMPLATES_POINTER = "Templates: see .bkit/templates.md; copies live in .bkit/templates/ (if your own gates scan the repo, ignore .bkit/templates/).";
88
+ export const TEMPLATES_POINTER = "Templates (adopt, do not skip): read .bkit/templates.md; bkit never applies templates, so adopt each copy in .bkit/templates/ unless adoption would break existing functionality — state which you did not adopt and why. (If your own gates scan the repo, ignore .bkit/templates/.)";
89
89
  /**
90
90
  * The upgrade report for a template sync: one line per changed, added or removed
91
91
  * template, then where to read about adopting them. Empty when nothing changed.
@@ -129,7 +129,7 @@ export const BKIT_EGRESS_SOURCES = [
129
129
  {
130
130
  id: "pkg-github",
131
131
  kind: "package-registry",
132
- hosts: ["npm.pkg.github.com", "raw.githubusercontent.com"],
132
+ hosts: ["raw.githubusercontent.com"],
133
133
  bases: ["github.com", "githubusercontent.com"],
134
134
  },
135
135
  { id: "skills-sh", kind: "skills", hosts: ["skills.sh"], bases: ["skills.sh"] },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cbartens/bkit",
3
- "version": "5.0.0",
3
+ "version": "5.0.1",
4
4
  "private": false,
5
5
  "description": "Agent-stack consolidation CLI.",
6
6
  "type": "module",
@@ -51,7 +51,7 @@
51
51
  "slop:delta": "bkit ci slop",
52
52
  "bkit:lint:workflows": "bash -c 'if command -v actionlint >/dev/null 2>&1; then actionlint; else echo \"[bkit] actionlint missing — skipping workflow lint (install actionlint to enable)\"; fi'",
53
53
  "test": "vitest run",
54
- "test:coverage:unit": "vitest run --coverage --coverage.reportsDirectory=coverage/unit --exclude '**/*.integration.test.ts' --coverage.include='.bkit/core/engine/{cli,commands/analysis,install/cloud-env,commands/comply,commands/harvest,commands/install/install,commands/launch,install/manifest,install/managed-block,shared/package-roots,shared/protected-paths,checks/after/index,checks/after/auth,checks/after/ci-yml,checks/after/github,checks/after/managed,checks/after/tools,checks/after/vercel,checks/before/index,checks/before/context-fetch,checks/before/env,checks/before/files,checks/before/mcp,checks/before/repo,checks/before/version,ledgers/status,ledgers/telemetry,install/write,install/placeholders,install/template-copies,render/trackers,render/hosts,render/models,commands/install/uninstall,commands/install/upgrade,install/version-file,tools/wording}.ts' --coverage.include='.bkit/core/engine/commands/**/*.ts' --coverage.include='.bkit/core/engine/shared/{settings,package-json,package-manager,timeouts}.ts' --coverage.thresholds.branches=70",
54
+ "test:coverage:unit": "vitest run --coverage --coverage.reportsDirectory=coverage/unit --exclude '**/*.integration.test.ts' --coverage.include='.bkit/core/engine/{cli,commands/analysis,install/cloud-env,commands/comply,commands/harvest,commands/install/install,commands/launch,install/manifest,install/managed-block,shared/package-roots,shared/protected-paths,checks/after/index,checks/after/auth,checks/after/ci-yml,checks/after/github,checks/after/managed,checks/after/tools,checks/after/suppression,checks/before/index,checks/before/context-fetch,checks/before/env,checks/before/files,checks/before/mcp,checks/before/repo,checks/before/version,ledgers/status,ledgers/telemetry,install/write,install/placeholders,install/template-copies,render/trackers,render/hosts,render/models,commands/install/uninstall,commands/install/upgrade,install/version-file,tools/wording}.ts' --coverage.include='.bkit/core/engine/commands/**/*.ts' --coverage.include='.bkit/core/engine/shared/{settings,package-json,package-manager,timeouts}.ts' --coverage.thresholds.branches=70",
55
55
  "bkit:test:bats": "bash -c 'if command -v bats >/dev/null 2>&1; then bats tests/*.bats; else echo \"[bkit] bats missing - skipping bats suite (install bats to enable)\" >&2; fi'",
56
56
  "build": "tsc && chmod +x dist/cli.js",
57
57
  "bkit:check:dist": "rm -rf dist && tsc && chmod +x dist/cli.js && git diff --exit-code dist/ || (echo '[bkit] dist/ is stale — run pnpm build and commit the result' && exit 1)",
@@ -1,101 +0,0 @@
1
- // checks/after/vercel.ts — the Vercel project link, env and install command auth.
2
-
3
- import * as fs from "node:fs";
4
- import * as path from "node:path";
5
- import { execFileSync } from "node:child_process";
6
- import type { TokenPresence } from "./auth.js";
7
-
8
- /**
9
- * Detect whether a Vercel project exists in the consumer's repo.
10
- * Heuristic: presence of vercel.json at root or under apps/<name>/.
11
- */
12
- export function detectVercelProject(cwd: string): boolean {
13
- if (fs.existsSync(path.join(cwd, "vercel.json"))) return true;
14
- const appsDir = path.join(cwd, "apps");
15
- if (!fs.existsSync(appsDir) || !fs.statSync(appsDir).isDirectory()) return false;
16
- for (const entry of fs.readdirSync(appsDir, { withFileTypes: true })) {
17
- if (!entry.isDirectory()) continue;
18
- if (fs.existsSync(path.join(appsDir, entry.name, "vercel.json"))) return true;
19
- }
20
- return false;
21
- }
22
-
23
- /**
24
- * Detect whether BKIT_GH_TOKEN_INSTALL is present in a Vercel environment.
25
- *
26
- * B3 Vercel CLI hang guard: pre-checks `.vercel/project.json` and SKIPS `vercel env ls`
27
- * when the file is absent. Does NOT shell out unless the project file exists — this
28
- * avoids the CLI login prompt / TTY hang in non-interactive CI environments.
29
- *
30
- * Fallback: if detectVercelProject finds vercel.json but .vercel/project.json is absent,
31
- * the project is not yet linked to a Vercel deployment — skip CLI call.
32
- */
33
- export function detectVercelEnv(
34
- env: "preview" | "production",
35
- cwd: string = process.cwd(),
36
- ): TokenPresence {
37
- if (!detectVercelProject(cwd)) return "unknown";
38
- // Runtime guard: reject unexpected env values even though TypeScript narrows them.
39
- if (env !== "preview" && env !== "production") return "unknown";
40
- // B3: Guard against `vercel env ls` hanging when the project is not linked.
41
- // `.vercel/project.json` is written by `vercel link` — absent means not linked.
42
- // Without this guard, `vercel env ls` blocks on a TTY login prompt in CI.
43
- const vercelProjectFile = path.join(cwd, ".vercel", "project.json");
44
- if (!fs.existsSync(vercelProjectFile)) return "unknown";
45
- try {
46
- const out = execFileSync("vercel", ["env", "ls", env], {
47
- encoding: "utf-8",
48
- stdio: ["ignore", "pipe", "ignore"],
49
- timeout: 10000,
50
- });
51
- return out.includes("BKIT_GH_TOKEN_INSTALL") ? "present" : "missing";
52
- } catch {
53
- return "unknown";
54
- }
55
- }
56
-
57
- /**
58
- * Detect Vercel projects whose `vercel.json` does not authenticate to GH Packages in its
59
- * install step. Vercel runs `pnpm install` in a fresh container with no pre-install shell
60
- * hook, so the token must be written by an `installCommand` that runs
61
- * `pnpm config set "//npm.pkg.github.com/:_authToken=$BKIT_GH_TOKEN_INSTALL"` before install — the
62
- * registry-only project .npmrc carries no token on pnpm >=10.34.3. A vercel.json with no
63
- * installCommand (or one whose installCommand lacks that `pnpm config set`) 401s on the
64
- * @cbartens/bkit download even when BKIT_GH_TOKEN_INSTALL is present in the Vercel env.
65
- *
66
- * Uses a raw-content regex (like detectCiYmlMissingTokenEnv), not JSON.parse, so a
67
- * non-standard-but-valid vercel.json still matches.
68
- *
69
- * Returns the offending vercel.json paths (relative to cwd); empty when all authenticate.
70
- */
71
- export function detectVercelInstallCommandMissingAuth(cwd: string): string[] {
72
- // `\\?["']?` tolerates the JSON-escaped (`\"//npm…`), plain-quoted, and unquoted forms
73
- // an installCommand string may take inside vercel.json.
74
- const authPattern = /pnpm\s+config\s+set\s+\\?["']?\/\/npm\.pkg\.github\.com\/:_authToken=/;
75
- const offenders: string[] = [];
76
- const check = (file: string): void => {
77
- if (!fs.existsSync(file)) return;
78
- if (!authPattern.test(fs.readFileSync(file, "utf-8"))) offenders.push(path.relative(cwd, file));
79
- };
80
- check(path.join(cwd, "vercel.json"));
81
- const appsDir = path.join(cwd, "apps");
82
- if (fs.existsSync(appsDir)) {
83
- for (const entry of fs.readdirSync(appsDir, { withFileTypes: true })) {
84
- if (entry.isDirectory()) check(path.join(appsDir, entry.name, "vercel.json"));
85
- }
86
- }
87
- return offenders;
88
- }
89
-
90
- export const VERCEL_MISSING_ACTION =
91
- "Add the @cbartens registry mapping to .npmrc at the repo root (the token is NOT stored here):\n\n" +
92
- " @cbartens:registry=https://npm.pkg.github.com\n\n" +
93
- "Commit this .npmrc — Vercel reads it during its build.\n\n" +
94
- "Vercel runs pnpm install in a fresh container and cannot run a pre-install shell step, so write the auth token via an installCommand in vercel.json:\n\n" +
95
- ' "installCommand": "pnpm config set //npm.pkg.github.com/:_authToken=$BKIT_GH_TOKEN_INSTALL && pnpm install"\n\n' +
96
- "Set BKIT_GH_TOKEN_INSTALL as a Vercel environment variable for each environment:\n\n" +
97
- " vercel env add BKIT_GH_TOKEN_INSTALL preview\n" +
98
- " vercel env add BKIT_GH_TOKEN_INSTALL production\n\n" +
99
- "Or via web: Vercel project → Settings → Environment Variables.\n" +
100
- "The token must be a GitHub PAT with read:packages scope (classic) or Packages: read permission (fine-grained).\n\n" +
101
- "Why the installCommand: pnpm >=10.34.3 does not authenticate a project-.npmrc ${BKIT_GH_TOKEN_INSTALL} env-substitution (it 401s on download), so the token must reach pnpm's user-level config via `pnpm config set` before install.";
@@ -1,102 +0,0 @@
1
- // checks/after/vercel.ts — the Vercel project link, env and install command auth.
2
- import * as fs from "node:fs";
3
- import * as path from "node:path";
4
- import { execFileSync } from "node:child_process";
5
- /**
6
- * Detect whether a Vercel project exists in the consumer's repo.
7
- * Heuristic: presence of vercel.json at root or under apps/<name>/.
8
- */
9
- export function detectVercelProject(cwd) {
10
- if (fs.existsSync(path.join(cwd, "vercel.json")))
11
- return true;
12
- const appsDir = path.join(cwd, "apps");
13
- if (!fs.existsSync(appsDir) || !fs.statSync(appsDir).isDirectory())
14
- return false;
15
- for (const entry of fs.readdirSync(appsDir, { withFileTypes: true })) {
16
- if (!entry.isDirectory())
17
- continue;
18
- if (fs.existsSync(path.join(appsDir, entry.name, "vercel.json")))
19
- return true;
20
- }
21
- return false;
22
- }
23
- /**
24
- * Detect whether BKIT_GH_TOKEN_INSTALL is present in a Vercel environment.
25
- *
26
- * B3 Vercel CLI hang guard: pre-checks `.vercel/project.json` and SKIPS `vercel env ls`
27
- * when the file is absent. Does NOT shell out unless the project file exists — this
28
- * avoids the CLI login prompt / TTY hang in non-interactive CI environments.
29
- *
30
- * Fallback: if detectVercelProject finds vercel.json but .vercel/project.json is absent,
31
- * the project is not yet linked to a Vercel deployment — skip CLI call.
32
- */
33
- export function detectVercelEnv(env, cwd = process.cwd()) {
34
- if (!detectVercelProject(cwd))
35
- return "unknown";
36
- // Runtime guard: reject unexpected env values even though TypeScript narrows them.
37
- if (env !== "preview" && env !== "production")
38
- return "unknown";
39
- // B3: Guard against `vercel env ls` hanging when the project is not linked.
40
- // `.vercel/project.json` is written by `vercel link` — absent means not linked.
41
- // Without this guard, `vercel env ls` blocks on a TTY login prompt in CI.
42
- const vercelProjectFile = path.join(cwd, ".vercel", "project.json");
43
- if (!fs.existsSync(vercelProjectFile))
44
- return "unknown";
45
- try {
46
- const out = execFileSync("vercel", ["env", "ls", env], {
47
- encoding: "utf-8",
48
- stdio: ["ignore", "pipe", "ignore"],
49
- timeout: 10000,
50
- });
51
- return out.includes("BKIT_GH_TOKEN_INSTALL") ? "present" : "missing";
52
- }
53
- catch {
54
- return "unknown";
55
- }
56
- }
57
- /**
58
- * Detect Vercel projects whose `vercel.json` does not authenticate to GH Packages in its
59
- * install step. Vercel runs `pnpm install` in a fresh container with no pre-install shell
60
- * hook, so the token must be written by an `installCommand` that runs
61
- * `pnpm config set "//npm.pkg.github.com/:_authToken=$BKIT_GH_TOKEN_INSTALL"` before install — the
62
- * registry-only project .npmrc carries no token on pnpm >=10.34.3. A vercel.json with no
63
- * installCommand (or one whose installCommand lacks that `pnpm config set`) 401s on the
64
- * @cbartens/bkit download even when BKIT_GH_TOKEN_INSTALL is present in the Vercel env.
65
- *
66
- * Uses a raw-content regex (like detectCiYmlMissingTokenEnv), not JSON.parse, so a
67
- * non-standard-but-valid vercel.json still matches.
68
- *
69
- * Returns the offending vercel.json paths (relative to cwd); empty when all authenticate.
70
- */
71
- export function detectVercelInstallCommandMissingAuth(cwd) {
72
- // `\\?["']?` tolerates the JSON-escaped (`\"//npm…`), plain-quoted, and unquoted forms
73
- // an installCommand string may take inside vercel.json.
74
- const authPattern = /pnpm\s+config\s+set\s+\\?["']?\/\/npm\.pkg\.github\.com\/:_authToken=/;
75
- const offenders = [];
76
- const check = (file) => {
77
- if (!fs.existsSync(file))
78
- return;
79
- if (!authPattern.test(fs.readFileSync(file, "utf-8")))
80
- offenders.push(path.relative(cwd, file));
81
- };
82
- check(path.join(cwd, "vercel.json"));
83
- const appsDir = path.join(cwd, "apps");
84
- if (fs.existsSync(appsDir)) {
85
- for (const entry of fs.readdirSync(appsDir, { withFileTypes: true })) {
86
- if (entry.isDirectory())
87
- check(path.join(appsDir, entry.name, "vercel.json"));
88
- }
89
- }
90
- return offenders;
91
- }
92
- export const VERCEL_MISSING_ACTION = "Add the @cbartens registry mapping to .npmrc at the repo root (the token is NOT stored here):\n\n" +
93
- " @cbartens:registry=https://npm.pkg.github.com\n\n" +
94
- "Commit this .npmrc — Vercel reads it during its build.\n\n" +
95
- "Vercel runs pnpm install in a fresh container and cannot run a pre-install shell step, so write the auth token via an installCommand in vercel.json:\n\n" +
96
- ' "installCommand": "pnpm config set //npm.pkg.github.com/:_authToken=$BKIT_GH_TOKEN_INSTALL && pnpm install"\n\n' +
97
- "Set BKIT_GH_TOKEN_INSTALL as a Vercel environment variable for each environment:\n\n" +
98
- " vercel env add BKIT_GH_TOKEN_INSTALL preview\n" +
99
- " vercel env add BKIT_GH_TOKEN_INSTALL production\n\n" +
100
- "Or via web: Vercel project → Settings → Environment Variables.\n" +
101
- "The token must be a GitHub PAT with read:packages scope (classic) or Packages: read permission (fine-grained).\n\n" +
102
- "Why the installCommand: pnpm >=10.34.3 does not authenticate a project-.npmrc ${BKIT_GH_TOKEN_INSTALL} env-substitution (it 401s on download), so the token must reach pnpm's user-level config via `pnpm config set` before install.";