@cbartens/bkit 5.2.4 → 5.4.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/.bkit/README.md +27 -11
- package/.bkit/core/.agents/context.md +1 -1
- package/.bkit/core/.agents/docs.md +1 -1
- package/.bkit/core/.agents/plugins/bkit/hooks/bkit-guardrails.cjs +1 -1
- package/.bkit/core/.agents/rules.md +18 -1
- package/.bkit/core/.bkit/README.md +26 -10
- package/.bkit/core/.bkit/cloud.md +40 -39
- package/.bkit/core/.bkit/comparison.md +68 -345
- package/.bkit/core/.bkit/install.md +16 -9
- package/.bkit/core/.bkit/lite.md +73 -0
- package/.bkit/core/.bkit/pipeline.md +346 -0
- package/.bkit/core/.bkit/prompts.md +90 -74
- package/.bkit/core/.bkit/providers.md +42 -23
- package/.bkit/core/.bkit/templates.md +138 -19
- package/.bkit/core/.bkit/trackers.md +49 -4
- package/.bkit/core/.bkit/workflows.md +144 -123
- package/.bkit/core/.claude/hooks/bkit-guardrails.cjs +1 -1
- package/.bkit/core/.codex/hooks/bkit-guardrails.cjs +7 -4
- package/.bkit/core/.cursor/hooks/bkit-guardrails.cjs +8 -5
- package/.bkit/core/docs/templates/bkit-audit-accessibility.md +3 -2
- package/.bkit/core/docs/templates/bkit-audit-adoption.md +2 -2
- package/.bkit/core/docs/templates/bkit-audit-agents.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-analytics.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-annotations.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-app-performance.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-app-store.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-architecture.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +4 -2
- package/.bkit/core/docs/templates/bkit-audit-config.md +3 -2
- package/.bkit/core/docs/templates/bkit-audit-cost.md +3 -2
- package/.bkit/core/docs/templates/bkit-audit-coverage.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-database.md +3 -2
- package/.bkit/core/docs/templates/bkit-audit-dead-code.md +5 -5
- package/.bkit/core/docs/templates/bkit-audit-deferrals.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-dependencies.md +26 -21
- package/.bkit/core/docs/templates/bkit-audit-documentation.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-duplication.md +2 -2
- package/.bkit/core/docs/templates/bkit-audit-failures.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-flakes.md +3 -2
- package/.bkit/core/docs/templates/bkit-audit-gates.md +5 -2
- package/.bkit/core/docs/templates/bkit-audit-issues.md +3 -2
- package/.bkit/core/docs/templates/bkit-audit-llm.md +22 -15
- package/.bkit/core/docs/templates/bkit-audit-logs.md +10 -6
- package/.bkit/core/docs/templates/bkit-audit-models.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-privacy.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-prompts.md +7 -7
- package/.bkit/core/docs/templates/bkit-audit-red-team.md +12 -9
- package/.bkit/core/docs/templates/bkit-audit-reliability.md +3 -2
- package/.bkit/core/docs/templates/bkit-audit-repo.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-security.md +14 -12
- package/.bkit/core/docs/templates/bkit-audit-slop.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-testing.md +10 -8
- package/.bkit/core/docs/templates/bkit-audit-usability.md +1 -1
- package/.bkit/core/docs/templates/bkit-plan.md +8 -6
- package/.bkit/core/engine/checks/after/auth.ts +9 -9
- package/.bkit/core/engine/checks/after/ci-yml.ts +14 -12
- package/.bkit/core/engine/checks/after/github.ts +29 -120
- package/.bkit/core/engine/checks/after/index.ts +2 -2
- package/.bkit/core/engine/checks/after/managed.ts +8 -28
- package/.bkit/core/engine/checks/after/tools.ts +3 -15
- package/.bkit/core/engine/checks/before/context-fetch.ts +1 -21
- package/.bkit/core/engine/checks/before/index.ts +7 -43
- package/.bkit/core/engine/checks/before/mcp.ts +17 -8
- package/.bkit/core/engine/checks/before/repo.ts +9 -12
- package/.bkit/core/engine/checks/status-holes.ts +4 -6
- package/.bkit/core/engine/checks/tips/catalogue.ts +76 -24
- package/.bkit/core/engine/checks/tips/detect.ts +45 -2
- package/.bkit/core/engine/checks/tips/index.ts +77 -26
- package/.bkit/core/engine/cli.ts +57 -27
- package/.bkit/core/engine/commands/analysis.ts +36 -26
- package/.bkit/core/engine/commands/comply.ts +42 -32
- package/.bkit/core/engine/commands/harvest.ts +12 -12
- package/.bkit/core/engine/commands/install/doctor.ts +57 -28
- package/.bkit/core/engine/commands/install/install.ts +73 -130
- package/.bkit/core/engine/commands/install/uninstall.ts +191 -33
- package/.bkit/core/engine/commands/install/upgrade.ts +49 -43
- package/.bkit/core/engine/commands/land.ts +156 -0
- package/.bkit/core/engine/commands/lib.ts +45 -18
- package/.bkit/core/engine/commands/registry.ts +2 -0
- package/.bkit/core/engine/commands/tips.ts +12 -5
- package/.bkit/core/engine/commands/workflow/branches.ts +386 -286
- package/.bkit/core/engine/commands/workflow/counters.ts +21 -12
- package/.bkit/core/engine/commands/workflow/disk.ts +556 -0
- package/.bkit/core/engine/commands/workflow/fids.ts +46 -0
- package/.bkit/core/engine/commands/workflow/issues.ts +73 -28
- package/.bkit/core/engine/commands/workflow/ledgers.ts +3 -1
- package/.bkit/core/engine/commands/workflow/locks.ts +38 -152
- package/.bkit/core/engine/commands/workflow/prs.ts +15 -4
- package/.bkit/core/engine/commands/workflow/repo.ts +2 -2
- package/.bkit/core/engine/commands/workflow/roadmap.ts +49 -53
- package/.bkit/core/engine/commands/workflow/runs.ts +8 -7
- package/.bkit/core/engine/commands/workflow/runtime.ts +3 -2
- package/.bkit/core/engine/commands/workflow/status.ts +33 -11
- package/.bkit/core/engine/commands/workflow/steps.ts +25 -15
- package/.bkit/core/engine/commands/workflow/tests.ts +17 -5
- package/.bkit/core/engine/commands/workflow/workflows.ts +436 -267
- package/.bkit/core/engine/commands/workflow/workstreams.ts +4 -2
- package/.bkit/core/engine/commands/workflow/worktrees.ts +24 -6
- package/.bkit/core/engine/install/cloud-env.ts +10 -31
- package/.bkit/core/engine/install/manifest.ts +14 -7
- package/.bkit/core/engine/install/modules/antigravity.ts +15 -26
- package/.bkit/core/engine/install/modules/claude.ts +20 -28
- package/.bkit/core/engine/install/modules/cloud.ts +5 -2
- package/.bkit/core/engine/install/modules/codex.ts +15 -29
- package/.bkit/core/engine/install/modules/core.ts +106 -70
- package/.bkit/core/engine/install/modules/cursor.ts +6 -20
- package/.bkit/core/engine/install/modules/index.ts +7 -1
- package/.bkit/core/engine/install/modules/opencode.ts +48 -70
- package/.bkit/core/engine/install/network-allowlist.ts +73 -0
- package/.bkit/core/engine/install/placeholders.ts +16 -35
- package/.bkit/core/engine/install/write.ts +59 -12
- package/.bkit/core/engine/ledgers/telemetry.ts +6 -4
- package/.bkit/core/engine/render/hosts.ts +47 -67
- package/.bkit/core/engine/render/models.ts +29 -11
- package/.bkit/core/engine/shared/branches.ts +13 -0
- package/.bkit/core/engine/shared/egress.ts +3 -3
- package/.bkit/core/engine/shared/json.ts +18 -1
- package/.bkit/core/engine/shared/package-json.ts +63 -0
- package/.bkit/core/engine/shared/package-roots.ts +0 -10
- package/.bkit/core/engine/shared/protected-paths.ts +5 -130
- package/.bkit/core/engine/shared/settings.ts +44 -0
- package/.bkit/core/engine/shared/timeouts.ts +8 -7
- package/.bkit/core/hooks/antigravity-hook.js +1 -0
- package/.bkit/core/hooks/guardrails-shell.js +186 -40
- package/.bkit/core/hooks/guardrails-tiers.js +5 -78
- package/.bkit/core/prompts/bkit-audit-generate.md +103 -7
- package/.bkit/core/prompts/bkit-build-challenge-1.md +1 -1
- package/.bkit/core/prompts/bkit-build-challenge-2.md +1 -1
- package/.bkit/core/prompts/bkit-build-challenge-reconcile.md +1 -1
- package/.bkit/core/prompts/bkit-build-challenge-remediate.md +1 -1
- package/.bkit/core/prompts/bkit-build-challenge-tests.md +1 -1
- package/.bkit/core/prompts/bkit-build-install-skills.md +1 -1
- package/.bkit/core/prompts/bkit-build-plan-current.md +1 -1
- package/.bkit/core/prompts/bkit-build-plan-execute.md +4 -4
- package/.bkit/core/prompts/bkit-build-plan-gaps-remediate.md +1 -1
- package/.bkit/core/prompts/bkit-build-plan-verify.md +2 -2
- package/.bkit/core/prompts/bkit-debug-abort-handover.md +1 -1
- package/.bkit/core/prompts/bkit-debug-failure-diagnose.md +1 -1
- package/.bkit/core/prompts/bkit-debug-failure-remediate.md +1 -1
- package/.bkit/core/prompts/bkit-debug-failure-reproduce.md +78 -0
- package/.bkit/core/prompts/bkit-debug-failure-soak.md +1 -1
- package/.bkit/core/prompts/bkit-debug-summary.md +3 -3
- package/.bkit/core/prompts/bkit-design-spike.md +1 -1
- package/.bkit/core/prompts/bkit-design-summary.md +2 -2
- package/.bkit/core/prompts/bkit-design-update.md +1 -1
- package/.bkit/core/prompts/bkit-plan-complexity-check.md +1 -1
- package/.bkit/core/prompts/bkit-plan-generate.md +1 -1
- package/.bkit/core/prompts/bkit-plan-scope-check-1.md +1 -1
- package/.bkit/core/prompts/bkit-plan-scope-check-2.md +1 -1
- package/.bkit/core/prompts/bkit-plan-summary.md +1 -1
- package/.bkit/core/prompts/bkit-plan-update.md +1 -1
- package/.bkit/core/prompts/bkit-ship-conflict-resolve.md +1 -1
- package/.bkit/core/prompts/bkit-ship-deferred-sweep.md +1 -1
- package/.bkit/core/prompts/bkit-ship-update-docs.md +1 -1
- package/.bkit/core/prompts/bkit-utility-update-decisions.md +9 -2
- package/.bkit/core/prompts/bkit-utility-update-deferrals.md +9 -2
- package/.bkit/core/prompts/bkit-utility-update-documentation.md +2 -1
- package/.bkit/core/prompts/bkit-utility-update-failures.md +9 -2
- package/.bkit/core/prompts/bkit-utility-update-knowledge.md +9 -2
- package/.bkit/core/prompts/bkit-utility-update-roadmap.md +11 -4
- package/.bkit/core/workflows/bkit-auto.md +2 -2
- package/.bkit/core/workflows/bkit-build.md +10 -10
- package/.bkit/core/workflows/bkit-debug.md +80 -44
- package/.bkit/core/workflows/bkit-design.md +22 -13
- package/.bkit/core/workflows/bkit-plan.md +33 -16
- package/.bkit/core/workflows/bkit-ship.md +87 -98
- package/.bkit/shared/.claude/bkit-cloud.md +58 -25
- package/.bkit/shared/.claude/settings.json +19 -0
- package/.bkit/shared/.cursor/mcp.json +2 -1
- package/.bkit/shared/.opencode/opencode.json +19 -1
- package/.bkit/shared/docs/deployments.md +49 -29
- package/.bkit/shared/docs/security.md +8 -6
- package/.bkit/shared/docs/testing.md +9 -5
- package/.bkit/shared/gitignore +1 -2
- package/.bkit/templates/.cursor/Dockerfile +30 -16
- package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-bug.yml +78 -0
- package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-change.yml +91 -0
- package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-idea.yml +56 -0
- package/.bkit/templates/.github/renovate.json5 +91 -12
- package/.bkit/templates/.github/workflows/bkit-ci.yml +73 -55
- package/.bkit/templates/.github/workflows/bkit-cloud.yml +3 -1
- package/.bkit/templates/.github/workflows/bkit-renovate.yml +8 -1
- package/.bkit/templates/.github/workflows/bkit-trivy.yml +67 -0
- package/.bkit/templates/.husky/pre-commit +6 -0
- package/.bkit/templates/.husky/pre-push +15 -3
- package/.bkit/templates/.lintstagedrc.json +5 -1
- package/.bkit/templates/.oxlintrc.json +21 -0
- package/.bkit/templates/docs/capabilities.md +1 -1
- package/.bkit/templates/scripts/ci/check-capstone.mjs +176 -0
- package/.bkit/templates/scripts/ci/check-capstone.test.mjs +311 -0
- package/.bkit/templates/scripts/cleanup/bkit-disk-prune.machine.mjs +197 -0
- package/.bkit/templates/scripts/cleanup/bkit-disk-prune.mjs +164 -0
- package/.bkit/templates/scripts/graphify/bkit-graph-eager.py +2 -2
- package/.bkit/templates/scripts/graphify/bkit-graph-imports.py +43 -20
- package/.bkit/templates/scripts/graphify/bkit-graph-pre-push.sh +33 -11
- package/.bkit/templates/scripts/graphify/bkit-graph-repair.py +3 -2
- package/.bkit/templates/scripts/graphify/bkit-graphify-rollup.py +5 -5
- package/.bkit/templates/scripts/graphify/bkit-graphify.sh +79 -19
- package/CHANGELOG.md +98 -3
- package/README.md +252 -122
- package/dist/checks/after/auth.js +10 -11
- package/dist/checks/after/ci-yml.js +11 -14
- package/dist/checks/after/github.js +32 -125
- package/dist/checks/after/index.js +3 -2
- package/dist/checks/after/managed.js +8 -24
- package/dist/checks/after/tools.js +3 -16
- package/dist/checks/before/context-fetch.js +1 -21
- package/dist/checks/before/index.js +6 -42
- package/dist/checks/before/mcp.js +14 -9
- package/dist/checks/before/repo.js +8 -11
- package/dist/checks/status-holes.js +5 -7
- package/dist/checks/tips/catalogue.js +65 -18
- package/dist/checks/tips/detect.js +41 -2
- package/dist/checks/tips/index.js +61 -25
- package/dist/cli.js +52 -26
- package/dist/commands/analysis.js +21 -5
- package/dist/commands/comply.js +40 -31
- package/dist/commands/harvest.js +12 -13
- package/dist/commands/install/doctor.js +55 -23
- package/dist/commands/install/install.js +72 -122
- package/dist/commands/install/uninstall.js +165 -31
- package/dist/commands/install/upgrade.js +46 -39
- package/dist/commands/land.js +129 -0
- package/dist/commands/lib.js +41 -16
- package/dist/commands/registry.js +2 -0
- package/dist/commands/tips.js +10 -3
- package/dist/commands/workflow/branches.js +303 -248
- package/dist/commands/workflow/counters.js +17 -7
- package/dist/commands/workflow/disk.js +452 -0
- package/dist/commands/workflow/fids.js +39 -0
- package/dist/commands/workflow/issues.js +63 -27
- package/dist/commands/workflow/ledgers.js +3 -1
- package/dist/commands/workflow/locks.js +35 -130
- package/dist/commands/workflow/prs.js +8 -5
- package/dist/commands/workflow/repo.js +2 -2
- package/dist/commands/workflow/roadmap.js +50 -57
- package/dist/commands/workflow/runs.js +5 -5
- package/dist/commands/workflow/runtime.js +3 -2
- package/dist/commands/workflow/status.js +32 -12
- package/dist/commands/workflow/steps.js +19 -11
- package/dist/commands/workflow/tests.js +16 -3
- package/dist/commands/workflow/workflows.js +390 -249
- package/dist/commands/workflow/workstreams.js +4 -2
- package/dist/commands/workflow/worktrees.js +15 -6
- package/dist/install/cloud-env.js +10 -23
- package/dist/install/manifest.js +14 -7
- package/dist/install/modules/antigravity.js +15 -26
- package/dist/install/modules/claude.js +17 -21
- package/dist/install/modules/cloud.js +6 -2
- package/dist/install/modules/codex.js +15 -29
- package/dist/install/modules/core.js +95 -63
- package/dist/install/modules/cursor.js +6 -9
- package/dist/install/modules/index.js +6 -1
- package/dist/install/modules/opencode.js +41 -72
- package/dist/install/network-allowlist.js +62 -0
- package/dist/install/placeholders.js +16 -35
- package/dist/install/write.js +55 -15
- package/dist/ledgers/telemetry.js +5 -4
- package/dist/render/hosts.js +30 -55
- package/dist/render/models.js +20 -9
- package/dist/shared/branches.js +11 -0
- package/dist/shared/egress.js +0 -2
- package/dist/shared/json.js +14 -0
- package/dist/shared/package-json.js +61 -0
- package/dist/shared/package-roots.js +0 -8
- package/dist/shared/protected-paths.js +5 -122
- package/dist/shared/settings.js +23 -1
- package/dist/shared/timeouts.js +8 -7
- package/package.json +21 -17
- package/.bkit/core/.agents/shortcuts.md +0 -73
|
@@ -11,12 +11,15 @@ import {
|
|
|
11
11
|
hashFile,
|
|
12
12
|
mergeCanonicalHashes,
|
|
13
13
|
} from "../version-file.js";
|
|
14
|
+
import { extractManagedBlock, stripManagedBlock } from "../managed-block.js";
|
|
14
15
|
import type { TokenMap } from "../placeholders.js";
|
|
15
16
|
import { listFilesRecursive, syncTemplateCopies } from "../template-copies.js";
|
|
16
17
|
import { PAYLOAD_LINK_RELPATHS, syncPayloadLinks } from "../payload-links.js";
|
|
18
|
+
import { writeNetworkAllowlist } from "../network-allowlist.js";
|
|
17
19
|
import type { PreflightFinding } from "../../checks/before/index.js";
|
|
20
|
+
import { readJsonFile } from "../../shared/json.js";
|
|
21
|
+
import { readInstallingVersion } from "../../shared/package-json.js";
|
|
18
22
|
import {
|
|
19
|
-
getPkgRoot,
|
|
20
23
|
getCoreRoot,
|
|
21
24
|
getSharedRoot,
|
|
22
25
|
getBkitDocsRoot,
|
|
@@ -71,25 +74,46 @@ const ORPHAN_PRUNE_DIRS = [
|
|
|
71
74
|
".claude/commands",
|
|
72
75
|
".cursor/agents",
|
|
73
76
|
".cursor/commands",
|
|
77
|
+
".opencode/agents",
|
|
78
|
+
".opencode/commands",
|
|
79
|
+
".codex/agents",
|
|
80
|
+
".agents/skills",
|
|
81
|
+
".agents/plugins/bkit/agents",
|
|
82
|
+
".agents/plugins/bkit/skills",
|
|
74
83
|
] as const;
|
|
75
84
|
|
|
85
|
+
export interface RemoveOrphansOptions {
|
|
86
|
+
/** Entry-name suffix an orphan must carry. Default `.md`; `""` matches every name. */
|
|
87
|
+
extension?: string;
|
|
88
|
+
/** Orphans are whole folders (skill dirs) removed recursively; `extension` is ignored. */
|
|
89
|
+
wholeFolders?: boolean;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Removes entries of `destDir` that start with `prefix` and are absent from `sourceNames`
|
|
94
|
+
* (entry names as they appear in `destDir`). Returns the removed names; with `dryRun` it
|
|
95
|
+
* reports them without deleting. Throws for any `destDir` outside `ORPHAN_PRUNE_DIRS`.
|
|
96
|
+
*/
|
|
76
97
|
export function removeOrphans(
|
|
77
98
|
destDir: string,
|
|
78
|
-
|
|
99
|
+
sourceNames: Set<string>,
|
|
79
100
|
dryRun: boolean,
|
|
80
101
|
prefix?: string,
|
|
102
|
+
options: RemoveOrphansOptions = {},
|
|
81
103
|
): string[] {
|
|
82
104
|
const resolved = path.resolve(destDir);
|
|
83
105
|
if (!ORPHAN_PRUNE_DIRS.some((d) => path.resolve(d) === resolved)) {
|
|
84
106
|
throw new Error(`removeOrphans: refusing orphan removal outside allowlist: ${destDir}`);
|
|
85
107
|
}
|
|
86
108
|
if (!fs.existsSync(destDir)) return [];
|
|
109
|
+
const { extension = ".md", wholeFolders = false } = options;
|
|
87
110
|
const removed: string[] = [];
|
|
88
111
|
for (const f of fs.readdirSync(destDir)) {
|
|
89
|
-
if (!f.endsWith(
|
|
112
|
+
if (!wholeFolders && !f.endsWith(extension)) continue;
|
|
90
113
|
if (prefix && !f.startsWith(prefix)) continue;
|
|
91
|
-
if (!
|
|
92
|
-
|
|
114
|
+
if (!sourceNames.has(f)) {
|
|
115
|
+
const target = path.join(destDir, f);
|
|
116
|
+
if (!dryRun) fs.rmSync(target, { recursive: wholeFolders, force: wholeFolders });
|
|
93
117
|
removed.push(f);
|
|
94
118
|
}
|
|
95
119
|
}
|
|
@@ -117,13 +141,7 @@ interface CoreTemplateFile {
|
|
|
117
141
|
}
|
|
118
142
|
|
|
119
143
|
/** The markered-text `.agents/*.md` blocks core owns. */
|
|
120
|
-
const CORE_AGENT_FILES = [
|
|
121
|
-
"context.md",
|
|
122
|
-
"docs.md",
|
|
123
|
-
"rules.md",
|
|
124
|
-
"shortcuts.md",
|
|
125
|
-
"skills.md",
|
|
126
|
-
] as const;
|
|
144
|
+
const CORE_AGENT_FILES = ["context.md", "docs.md", "rules.md", "skills.md"] as const;
|
|
127
145
|
|
|
128
146
|
// The two shared-root files core writes: stored in `shared/`, owned by the core
|
|
129
147
|
// manifest, written as html-comment managed blocks.
|
|
@@ -228,16 +246,18 @@ function runCoreTemplates(
|
|
|
228
246
|
// mirrored into the consumer's `.bkit/` on every install so a consumer can read them
|
|
229
247
|
// in-repo without spelunking node_modules. Force-overwritten (Tier 1) — bkit owns
|
|
230
248
|
// them, so a consumer edit is replaced. Source of truth is the package's own
|
|
231
|
-
// `.bkit/core/.bkit/<name>`. (`advisories.md` is a regenerated runtime artifact
|
|
232
|
-
// `wording.md` is repo-only tooling
|
|
233
|
-
//
|
|
234
|
-
//
|
|
249
|
+
// `.bkit/core/.bkit/<name>`. (`advisories.md` is a regenerated runtime artifact and
|
|
250
|
+
// `wording.md` is repo-only tooling — neither belongs here. `LICENSE.md` is the MIT
|
|
251
|
+
// notice that travels with the files bkit writes: MIT requires the copyright and
|
|
252
|
+
// permission notice in every copy.)
|
|
235
253
|
export const BKIT_CANONICAL_DOCS = [
|
|
236
254
|
"cloud.md",
|
|
237
255
|
"comparison.md",
|
|
238
256
|
"install.md",
|
|
239
257
|
"jsonl.md",
|
|
240
258
|
"LICENSE.md",
|
|
259
|
+
"lite.md",
|
|
260
|
+
"pipeline.md",
|
|
241
261
|
"providers.md",
|
|
242
262
|
"prompts.md",
|
|
243
263
|
"templates.md",
|
|
@@ -278,6 +298,59 @@ export function runBkitDocs(
|
|
|
278
298
|
console.log(`${logPrefix} ${tag}core: ${dstPath}`);
|
|
279
299
|
}
|
|
280
300
|
}
|
|
301
|
+
migrateShortcutsToLite(dryRun, ws, logPrefix);
|
|
302
|
+
migrateRetiredDevLock(dryRun, ws, logPrefix);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// Migration (5.1.0 – 5.2.4 installs, `docs/migrations.md`): the lite workflows lived at
|
|
306
|
+
// `.agents/shortcuts.md`. The consumer's own lines below `bkit:end` (minus the seeded
|
|
307
|
+
// heading) move under `.bkit/lite.md`'s consumer section; the old file is deleted. Runs
|
|
308
|
+
// after the docs loop, so `.bkit/lite.md` is already written. The delete is recorded in
|
|
309
|
+
// ws (as orphan-mirror deletes are) so `bkit check` fails until upgrade runs.
|
|
310
|
+
const RETIRED_SHORTCUTS = path.join(".agents", "shortcuts.md");
|
|
311
|
+
const RETIRED_SHORTCUTS_HEADING = "## Project Shortcuts";
|
|
312
|
+
|
|
313
|
+
export function migrateShortcutsToLite(dryRun: boolean, ws: WriteSet, logPrefix: string): void {
|
|
314
|
+
if (!fs.existsSync(RETIRED_SHORTCUTS)) return;
|
|
315
|
+
if (!fs.existsSync(path.join(getBkitDocsRoot(), "lite.md"))) return;
|
|
316
|
+
const tag = dryRun ? "[dry-run] " : "";
|
|
317
|
+
const dst = path.join(".bkit", "lite.md");
|
|
318
|
+
const old = fs.readFileSync(RETIRED_SHORTCUTS, "utf-8");
|
|
319
|
+
if (extractManagedBlock(old, "html-comment") === null) {
|
|
320
|
+
console.warn(
|
|
321
|
+
`${logPrefix} ${RETIRED_SHORTCUTS} has no single bkit managed block — left in place. Move your own lines into ${dst} below \`<!-- bkit:end -->\`, then delete it.`,
|
|
322
|
+
);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
const own = stripManagedBlock(old, "html-comment")
|
|
326
|
+
.split("\n")
|
|
327
|
+
.filter((line) => line.trim() !== RETIRED_SHORTCUTS_HEADING)
|
|
328
|
+
.join("\n")
|
|
329
|
+
.trim();
|
|
330
|
+
if (own.length > 0) {
|
|
331
|
+
if (!dryRun) {
|
|
332
|
+
const current = fs.readFileSync(dst, "utf-8");
|
|
333
|
+
fs.writeFileSync(dst, `${current.replace(/\n*$/, "\n\n")}${own}\n`, "utf-8");
|
|
334
|
+
}
|
|
335
|
+
ws.writes.push({ path: dst, action: "update" });
|
|
336
|
+
}
|
|
337
|
+
if (!dryRun) fs.rmSync(RETIRED_SHORTCUTS);
|
|
338
|
+
ws.writes.push({ path: RETIRED_SHORTCUTS, action: "write" });
|
|
339
|
+
console.log(`${logPrefix} ${tag}core: moved ${RETIRED_SHORTCUTS} → ${dst}`);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// Migration (installs up to 5.3.x, `docs/migrations.md`): `.bkit/.dev.lock` was the
|
|
343
|
+
// repo-wide dev lock. Nothing reads it now, so one a crashed run left behind is deleted.
|
|
344
|
+
// bkit owned the name whole. Recorded in ws so `bkit check` fails until upgrade runs.
|
|
345
|
+
const RETIRED_DEV_LOCK = path.join(".bkit", ".dev.lock");
|
|
346
|
+
|
|
347
|
+
export function migrateRetiredDevLock(dryRun: boolean, ws: WriteSet, logPrefix: string): void {
|
|
348
|
+
if (!fs.lstatSync(RETIRED_DEV_LOCK, { throwIfNoEntry: false })?.isFile()) return;
|
|
349
|
+
if (!dryRun) fs.rmSync(RETIRED_DEV_LOCK);
|
|
350
|
+
ws.writes.push({ path: RETIRED_DEV_LOCK, action: "write" });
|
|
351
|
+
console.log(
|
|
352
|
+
`${logPrefix} ${dryRun ? "[dry-run] " : ""}core: removed ${RETIRED_DEV_LOCK} (the dev lock is gone)`,
|
|
353
|
+
);
|
|
281
354
|
}
|
|
282
355
|
|
|
283
356
|
// ---------------------------------------------------------------------------
|
|
@@ -292,29 +365,6 @@ export function runBkitDocs(
|
|
|
292
365
|
// the consumer-relative dest paths it wrote (for the upgrade summary).
|
|
293
366
|
// ---------------------------------------------------------------------------
|
|
294
367
|
|
|
295
|
-
// ---------------------------------------------------------------------------
|
|
296
|
-
// Managed-version stamping. The marker shape (stampManagedVersion + regexes) lives
|
|
297
|
-
// in install/version-file.ts, shared by the renderer and the `bkit check` detector. Here we
|
|
298
|
-
// only resolve WHICH version to stamp: ctx.version (set by install/upgrade) with a
|
|
299
|
-
// package-root fallback.
|
|
300
|
-
// ---------------------------------------------------------------------------
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Best-effort read of the installing bkit version from the package root's
|
|
304
|
-
* package.json. Mirrors getInstallingVersion in commands/install/install.ts; duplicated here
|
|
305
|
-
* (not imported) to avoid a modules → install dependency cycle. Returns "0.0.0"
|
|
306
|
-
* when unreadable — the same non-fatal fallback the install side uses.
|
|
307
|
-
*/
|
|
308
|
-
export function readInstallingVersion(): string {
|
|
309
|
-
try {
|
|
310
|
-
const pkgPath = path.join(getPkgRoot(), "package.json");
|
|
311
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8")) as { version?: string };
|
|
312
|
-
return pkg.version ?? "0.0.0";
|
|
313
|
-
} catch {
|
|
314
|
-
return "0.0.0";
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
368
|
/** Record a host mirror would-write so `bkit check` exits 1 on content drift. */
|
|
319
369
|
export function trackMirrorWrite(ctx: ModuleContext, relPath: string, written: string[]): void {
|
|
320
370
|
written.push(relPath);
|
|
@@ -368,17 +418,12 @@ const PNPM_NOT_A_SCRIPT = new Set([
|
|
|
368
418
|
* package.json yields none.
|
|
369
419
|
*/
|
|
370
420
|
export function detectGateAdvisories(cwd: string): PreflightFinding[] {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
} catch {
|
|
378
|
-
// Absent or malformed package.json — preflight's no-package-json /
|
|
379
|
-
// malformed-package-json blockers already report it.
|
|
380
|
-
return [];
|
|
381
|
-
}
|
|
421
|
+
const read = readJsonFile(path.join(cwd, "package.json"));
|
|
422
|
+
// Absent or malformed package.json — preflight's no-package-json /
|
|
423
|
+
// malformed-package-json blockers already report it.
|
|
424
|
+
if (!read.ok || read.value === null) return [];
|
|
425
|
+
const pkg = read.value as { scripts?: Record<string, string> };
|
|
426
|
+
const declared: Record<string, string> = { ...BKIT_GATE_SCRIPTS, ...pkg.scripts };
|
|
382
427
|
const findings: PreflightFinding[] = [];
|
|
383
428
|
|
|
384
429
|
// Every script a seeded gate default chains MUST exist, or the gate dies on the first
|
|
@@ -454,16 +499,11 @@ export function isNoopScript(value: string): boolean {
|
|
|
454
499
|
* every branch. Read-only; an absent or unparseable package.json yields none.
|
|
455
500
|
*/
|
|
456
501
|
export function detectNoopGates(cwd: string): PreflightFinding[] {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
declared = pkg.scripts ?? {};
|
|
463
|
-
} catch {
|
|
464
|
-
// Absent or malformed package.json — preflight's blockers already report it.
|
|
465
|
-
return [];
|
|
466
|
-
}
|
|
502
|
+
const read = readJsonFile(path.join(cwd, "package.json"));
|
|
503
|
+
// Absent or malformed package.json — preflight's blockers already report it.
|
|
504
|
+
if (!read.ok || read.value === null) return [];
|
|
505
|
+
const pkg = read.value as { scripts?: Record<string, unknown> };
|
|
506
|
+
const declared: Record<string, unknown> = pkg.scripts ?? {};
|
|
467
507
|
const noop = Object.entries(declared)
|
|
468
508
|
.filter(([name, value]) => name.startsWith("bkit:gate:") && typeof value === "string")
|
|
469
509
|
.filter(([, value]) => isNoopScript(value as string))
|
|
@@ -485,15 +525,7 @@ export function runCoreModule(ctx: ModuleContext): void {
|
|
|
485
525
|
const { dryRun, ws, advisories, logPrefix, postDispatch } = ctx;
|
|
486
526
|
const tag = dryRun ? "[dry-run] " : "";
|
|
487
527
|
const cwd = process.cwd();
|
|
488
|
-
const
|
|
489
|
-
const PKG_PACKAGE_JSON = path.join(PKG_ROOT, "package.json");
|
|
490
|
-
|
|
491
|
-
if (!fs.existsSync(PKG_PACKAGE_JSON)) {
|
|
492
|
-
console.error(`${logPrefix} package.json not found at ${PKG_PACKAGE_JSON} — package corrupt?`);
|
|
493
|
-
process.exit(1);
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
const pkgVersion = JSON.parse(fs.readFileSync(PKG_PACKAGE_JSON, "utf-8")).version as string;
|
|
528
|
+
const pkgVersion = readInstallingVersion();
|
|
497
529
|
|
|
498
530
|
// Capture first-install signal NOW (before any writes) — used for the post-install banner.
|
|
499
531
|
// The .bkit/version write happens in postDispatch, so a mid-install crash in a later
|
|
@@ -507,7 +539,7 @@ export function runCoreModule(ctx: ModuleContext): void {
|
|
|
507
539
|
runCoreTemplates(dryRun, ctx.tokens, ws, logPrefix);
|
|
508
540
|
|
|
509
541
|
// 3b. bkit canonical docs pass — mirror the package's reference docs
|
|
510
|
-
// (cloud/IDEs/prompts/trackers/workflows/README/install/comparison) into the
|
|
542
|
+
// (cloud/IDEs/prompts/trackers/workflows/README/install/comparison/pipeline) into the
|
|
511
543
|
// consumer's `.bkit/` so they are readable in-repo. Force-overwrite (Tier 1).
|
|
512
544
|
console.log(`${logPrefix} ${tag}Running bkit docs pass`);
|
|
513
545
|
runBkitDocs(dryRun, ctx.tokens, ws, logPrefix);
|
|
@@ -550,6 +582,10 @@ export function runCoreModule(ctx: ModuleContext): void {
|
|
|
550
582
|
});
|
|
551
583
|
}
|
|
552
584
|
|
|
585
|
+
// 3b4. `.bkit/allowlist.json` — the network allowlist every host's guardrails hook
|
|
586
|
+
// reads (writeNetworkAllowlist), plus the move off the retired `.cursor/` copy.
|
|
587
|
+
writeNetworkAllowlist(cwd, dryRun, ws, logPrefix);
|
|
588
|
+
|
|
553
589
|
// 3c. The bkit:gate:* / bkit:deps:* package.json scripts (add-if-missing). The
|
|
554
590
|
// advisories read the result.
|
|
555
591
|
seedCorePackageJsonScripts(ctx);
|
|
@@ -13,20 +13,10 @@ import {
|
|
|
13
13
|
} from "../../shared/package-roots.js";
|
|
14
14
|
import { DEFAULT_ISSUE_TRACKER } from "../manifest.js";
|
|
15
15
|
import { substituteWorkflow } from "../../render/trackers.js";
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
writeNetworkAllowlistArtifact,
|
|
19
|
-
writeCursorCliPermissionsArtifact,
|
|
20
|
-
} from "../cloud-env.js";
|
|
16
|
+
import { writeCursorCloudDoc, writeCursorCliPermissionsArtifact } from "../cloud-env.js";
|
|
17
|
+
import { readInstallingVersion } from "../../shared/package-json.js";
|
|
21
18
|
import type { ModuleContext } from "./index.js";
|
|
22
|
-
import {
|
|
23
|
-
BKIT_PREFIX,
|
|
24
|
-
installFile,
|
|
25
|
-
listMdFiles,
|
|
26
|
-
readInstallingVersion,
|
|
27
|
-
removeOrphans,
|
|
28
|
-
trackMirrorWrite,
|
|
29
|
-
} from "./core.js";
|
|
19
|
+
import { BKIT_PREFIX, installFile, listMdFiles, removeOrphans, trackMirrorWrite } from "./core.js";
|
|
30
20
|
import { reconcileMcpJson } from "./claude.js";
|
|
31
21
|
|
|
32
22
|
export function renderCursorAgentsCommands(ctx: ModuleContext): string[] {
|
|
@@ -182,15 +172,11 @@ export function runCursorModule(ctx: ModuleContext): void {
|
|
|
182
172
|
}
|
|
183
173
|
}
|
|
184
174
|
|
|
185
|
-
// Cursor-only runtime curl/wget allowlist (bkit-guardrails.cjs reads `.cursor/allowlist.json`).
|
|
186
|
-
// Same domain set as Claude WebFetch / OpenCode bash allows — sourced from tooling
|
|
187
|
-
// defaults ∪ consumer `allowed-domains`. Not under `.bkit/` (IDE-scoped artifact).
|
|
188
175
|
// Cursor CLI / cloud-agent MCP allows (`.cursor/cli.json`) from consumer `mcp-servers` —
|
|
189
176
|
// same server set as Claude `mcp__…` allows / OpenCode `<server>_*` permission rows.
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
writeCursorCliPermissionsArtifact(process.cwd(), dryRun)
|
|
193
|
-
]) {
|
|
177
|
+
// The curl/wget allowlist the guardrails hook reads is core's `.bkit/allowlist.json`.
|
|
178
|
+
{
|
|
179
|
+
const art = writeCursorCliPermissionsArtifact(process.cwd(), dryRun);
|
|
194
180
|
if (art.wrote) {
|
|
195
181
|
ws.writes.push({ path: art.path, action: "write" });
|
|
196
182
|
console.log(`${logPrefix} ${tag}cursor: ${art.path}`);
|
|
@@ -14,6 +14,7 @@ import type { EffortMap } from "../../render/models.js";
|
|
|
14
14
|
import type { PreflightFinding } from "../../checks/before/index.js";
|
|
15
15
|
import { getCoreRoot, getSharedRoot } from "../../shared/package-roots.js";
|
|
16
16
|
import { getInstallManifest, type IssueTracker } from "../manifest.js";
|
|
17
|
+
import { writeNetworkAllowlist } from "../network-allowlist.js";
|
|
17
18
|
import {
|
|
18
19
|
BKIT_PREFIX,
|
|
19
20
|
listCoreTemplateFiles,
|
|
@@ -115,7 +116,8 @@ export type ModuleFn = (ctx: ModuleContext) => void;
|
|
|
115
116
|
// renderManagedOutputs — re-render the bkit-managed OUTPUT files that the
|
|
116
117
|
// `bkit upgrade` payload walk does NOT cover:
|
|
117
118
|
// host agents/commands (source-rendered), the `.bkit/*.md` canonical docs
|
|
118
|
-
// (runBkitDocs) and core's
|
|
119
|
+
// (runBkitDocs), `.bkit/allowlist.json` (writeNetworkAllowlist) and core's
|
|
120
|
+
// package.json scripts (seedCorePackageJsonScripts).
|
|
119
121
|
// `.bkit/prompts.md` is markered → runBkitDocs block-merges it (managed block
|
|
120
122
|
// refreshed, consumer `## Model Overrides` below bkit:end preserved).
|
|
121
123
|
//
|
|
@@ -140,6 +142,10 @@ export function renderManagedOutputs(modules: Set<ModuleFlag>, ctx: ModuleContex
|
|
|
140
142
|
written.push(String(ctx.ws.writes[i].path));
|
|
141
143
|
}
|
|
142
144
|
|
|
145
|
+
// `.bkit/allowlist.json` — the same pass install's core module runs (writeNetworkAllowlist
|
|
146
|
+
// records into ctx.ws, so the caller refreshes its canonicalHashes).
|
|
147
|
+
written.push(...writeNetworkAllowlist(process.cwd(), ctx.dryRun, ctx.ws, ctx.logPrefix));
|
|
148
|
+
|
|
143
149
|
// Core package.json scripts — the same pass install runs, so `bkit check` after a
|
|
144
150
|
// clean upgrade finds no missing gate name and no superseded script value.
|
|
145
151
|
written.push(...seedCorePackageJsonScripts(ctx));
|
|
@@ -3,7 +3,15 @@
|
|
|
3
3
|
|
|
4
4
|
import * as fs from "node:fs";
|
|
5
5
|
import * as path from "node:path";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
writeTier2,
|
|
8
|
+
deepMergeJson,
|
|
9
|
+
ensureDir,
|
|
10
|
+
isJsonObject,
|
|
11
|
+
mergeTrackerEntry,
|
|
12
|
+
type WriteSet,
|
|
13
|
+
type JsonValue,
|
|
14
|
+
} from "../write.js";
|
|
7
15
|
import { stampManagedVersion } from "../version-file.js";
|
|
8
16
|
import { applyOpencodeAgent, applyOpencodeCommand } from "../../render/hosts.js";
|
|
9
17
|
import type { PreflightFinding } from "../../checks/before/index.js";
|
|
@@ -17,15 +25,12 @@ import { type IssueTracker, DEFAULT_ISSUE_TRACKER } from "../manifest.js";
|
|
|
17
25
|
import { substituteWorkflow } from "../../render/trackers.js";
|
|
18
26
|
import { resolveNetworkAllowlist, extractMcpServers, networkAllowlistBases } from "../cloud-env.js";
|
|
19
27
|
import { OPENCODE_PROVIDER_DEFAULTS } from "../../shared/egress.js";
|
|
28
|
+
import { parseJson, readJsonFile } from "../../shared/json.js";
|
|
29
|
+
import { readBkitConfig } from "../../shared/settings.js";
|
|
30
|
+
import { readInstallingVersion } from "../../shared/package-json.js";
|
|
20
31
|
import type { ModuleContext } from "./index.js";
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
installFile,
|
|
24
|
-
listMdFiles,
|
|
25
|
-
readInstallingVersion,
|
|
26
|
-
trackMirrorWrite,
|
|
27
|
-
} from "./core.js";
|
|
28
|
-
import { opencodeProviderId } from "../../render/models.js";
|
|
32
|
+
import { BKIT_PREFIX, installFile, listMdFiles, removeOrphans, trackMirrorWrite } from "./core.js";
|
|
33
|
+
import { isOpencodeProvider, opencodeProviderId } from "../../render/models.js";
|
|
29
34
|
|
|
30
35
|
export function renderOpencodeAgentsCommands(ctx: ModuleContext): string[] {
|
|
31
36
|
const { dryRun, opencodeModelLookup, effortMap, opencodeProvider, logPrefix } = ctx;
|
|
@@ -68,20 +73,11 @@ export function renderOpencodeAgentsCommands(ctx: ModuleContext): string[] {
|
|
|
68
73
|
}
|
|
69
74
|
}
|
|
70
75
|
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (!f.endsWith(".md")) continue;
|
|
77
|
-
if (!f.startsWith(BKIT_PREFIX)) continue;
|
|
78
|
-
if (!sourceSet.has(f)) {
|
|
79
|
-
const rel = path.join(dest, f);
|
|
80
|
-
if (!dryRun) fs.rmSync(path.join(dest, f));
|
|
81
|
-
console.log(`${logPrefix} ${tag}delete orphan: ${rel}`);
|
|
82
|
-
trackMirrorWrite(ctx, rel, written);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
76
|
+
// dryRun still reports would-deletes into ws.writes so `bkit check` fails on stale mirrors.
|
|
77
|
+
for (const f of removeOrphans(dest, sourceSet, dryRun, BKIT_PREFIX)) {
|
|
78
|
+
const rel = path.join(dest, f);
|
|
79
|
+
console.log(`${logPrefix} ${tag}delete orphan: ${rel}`);
|
|
80
|
+
trackMirrorWrite(ctx, rel, written);
|
|
85
81
|
}
|
|
86
82
|
}
|
|
87
83
|
|
|
@@ -107,17 +103,10 @@ export function renderOpencodeAgentsCommands(ctx: ModuleContext): string[] {
|
|
|
107
103
|
}
|
|
108
104
|
}
|
|
109
105
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (!sourceSet.has(f)) {
|
|
115
|
-
const rel = path.join(dest, f);
|
|
116
|
-
if (!dryRun) fs.rmSync(path.join(dest, f));
|
|
117
|
-
console.log(`${logPrefix} ${tag}delete orphan: ${rel}`);
|
|
118
|
-
trackMirrorWrite(ctx, rel, written);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
106
|
+
for (const f of removeOrphans(dest, sourceSet, dryRun, BKIT_PREFIX)) {
|
|
107
|
+
const rel = path.join(dest, f);
|
|
108
|
+
console.log(`${logPrefix} ${tag}delete orphan: ${rel}`);
|
|
109
|
+
trackMirrorWrite(ctx, rel, written);
|
|
121
110
|
}
|
|
122
111
|
}
|
|
123
112
|
return written;
|
|
@@ -146,7 +135,7 @@ export function renderOpencodeAgentsCommands(ctx: ModuleContext): string[] {
|
|
|
146
135
|
* secret against the installed provider.
|
|
147
136
|
*/
|
|
148
137
|
export function opencodeProviderEnvVar(providerKey: string): string {
|
|
149
|
-
return OPENCODE_PROVIDER_DEFAULTS[providerKey]
|
|
138
|
+
return isOpencodeProvider(providerKey) ? OPENCODE_PROVIDER_DEFAULTS[providerKey].envVar : "";
|
|
150
139
|
}
|
|
151
140
|
|
|
152
141
|
/**
|
|
@@ -170,19 +159,8 @@ export function detectOpencodeYmlProviderDrift(cwd: string): PreflightFinding |
|
|
|
170
159
|
if (!fs.existsSync(ymlPath)) return null;
|
|
171
160
|
|
|
172
161
|
// The installed provider — package.json `bkit.opencodeProvider` is the authoritative record
|
|
173
|
-
// written on install. Absent/broken → the null-guard below skips silently.
|
|
174
|
-
|
|
175
|
-
const pkgPath = path.join(cwd, "package.json");
|
|
176
|
-
if (fs.existsSync(pkgPath)) {
|
|
177
|
-
try {
|
|
178
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8")) as {
|
|
179
|
-
bkit?: { opencodeProvider?: unknown };
|
|
180
|
-
};
|
|
181
|
-
if (typeof pkg.bkit?.opencodeProvider === "string") provider = pkg.bkit.opencodeProvider;
|
|
182
|
-
} catch {
|
|
183
|
-
// Malformed package.json — leave provider null; a JSON-drift advisory covers that separately.
|
|
184
|
-
}
|
|
185
|
-
}
|
|
162
|
+
// written on install. Absent/broken/unsupported → the null-guard below skips silently.
|
|
163
|
+
const provider = readBkitConfig(cwd).opencodeProvider;
|
|
186
164
|
if (!provider) return null;
|
|
187
165
|
|
|
188
166
|
const expectedPrefix = opencodeProviderId(provider); // model id form is `<providerId>/<model>`
|
|
@@ -266,10 +244,10 @@ export function renderOpencodeJson(
|
|
|
266
244
|
const raw = fs.readFileSync(templatePath, "utf-8");
|
|
267
245
|
// Strict allowlist: provider is gated to OPENCODE_PROVIDERS at the CLI, so it is always
|
|
268
246
|
// a known key here. An unknown id throws; no substitute provider.
|
|
269
|
-
|
|
270
|
-
if (!providerDefaults) {
|
|
247
|
+
if (!isOpencodeProvider(provider)) {
|
|
271
248
|
throw new Error(`renderOpencodeJson: unknown opencode provider ${JSON.stringify(provider)}`);
|
|
272
249
|
}
|
|
250
|
+
const providerDefaults = OPENCODE_PROVIDER_DEFAULTS[provider];
|
|
273
251
|
|
|
274
252
|
// Resolve tracker MCP entry
|
|
275
253
|
// opencode's MCP schema differs from Claude/Cursor: remote servers use type "remote"
|
|
@@ -282,7 +260,7 @@ export function renderOpencodeJson(
|
|
|
282
260
|
let mcpEntry: string;
|
|
283
261
|
if (tracker === "github") {
|
|
284
262
|
mcpEntry =
|
|
285
|
-
'"github": { "type": "remote", "url": "https://api.githubcopilot.com/mcp/", "oauth": false, "headers": { "Authorization": "Bearer {env:BKIT_GH_TOKEN}", "X-MCP-Toolsets": "context,issues,pull_requests,repos,users,projects" } }';
|
|
263
|
+
'"github": { "type": "remote", "url": "https://api.githubcopilot.com/mcp/", "oauth": false, "headers": { "Authorization": "Bearer {env:BKIT_GH_TOKEN}", "X-MCP-Toolsets": "context,issues,pull_requests,repos,users,projects,actions" } }';
|
|
286
264
|
} else if (tracker === "linear") {
|
|
287
265
|
mcpEntry = '"linear": { "type": "remote", "url": "https://mcp.linear.app/mcp" }';
|
|
288
266
|
} else {
|
|
@@ -296,7 +274,9 @@ export function renderOpencodeJson(
|
|
|
296
274
|
|
|
297
275
|
// Parse + re-serialize to normalise JSON (removes empty mcp entry if tracker=none)
|
|
298
276
|
try {
|
|
299
|
-
const
|
|
277
|
+
const renderedDoc = parseJson(rendered);
|
|
278
|
+
if (!renderedDoc.ok) return rendered;
|
|
279
|
+
const parsed = renderedDoc.value as Record<string, unknown>;
|
|
300
280
|
// Clean up empty mcp object when tracker=none
|
|
301
281
|
const mcp = parsed.mcp as Record<string, unknown> | undefined;
|
|
302
282
|
if (mcp && Object.keys(mcp).length === 0) {
|
|
@@ -402,15 +382,9 @@ export function reconcileOpencodeJson(
|
|
|
402
382
|
return;
|
|
403
383
|
}
|
|
404
384
|
|
|
405
|
-
//
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
let existing: Record<string, JsonValue> | null = null;
|
|
409
|
-
try {
|
|
410
|
-
existing = JSON.parse(fs.readFileSync(relDst, "utf-8")) as Record<string, JsonValue>;
|
|
411
|
-
} catch {
|
|
412
|
-
existing = null;
|
|
413
|
-
}
|
|
385
|
+
// Malformed consumer JSON is a hard stop: refuse to merge, require a fix.
|
|
386
|
+
const read = readJsonFile(relDst);
|
|
387
|
+
const existing = read.ok ? (read.value as Record<string, JsonValue> | null) : null;
|
|
414
388
|
if (existing === null) {
|
|
415
389
|
throw new Error(
|
|
416
390
|
`[bkit] ${relDst} is malformed JSON — fix manually before running bkit install`,
|
|
@@ -421,6 +395,15 @@ export function reconcileOpencodeJson(
|
|
|
421
395
|
string,
|
|
422
396
|
JsonValue
|
|
423
397
|
>;
|
|
398
|
+
// The tracker `mcp` entry keeps the consumer's extra toolsets (`mergeTrackerEntry`), which
|
|
399
|
+
// the plain merge above would overwrite with the template's list.
|
|
400
|
+
const tmplMcp = template.mcp;
|
|
401
|
+
const existingMcp = existing.mcp;
|
|
402
|
+
if (isJsonObject(tmplMcp) && isJsonObject(existingMcp) && isJsonObject(merged.mcp)) {
|
|
403
|
+
for (const [k, v] of Object.entries(tmplMcp)) {
|
|
404
|
+
merged.mcp[k] = mergeTrackerEntry(existingMcp[k], v);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
424
407
|
// Replace (do not deep-merge) each provider key the template seeds — heals hijacked
|
|
425
408
|
// npm/baseURL/name while keeping other provider keys additive.
|
|
426
409
|
//
|
|
@@ -473,13 +456,8 @@ export function removeOpencodeProviderBlock(
|
|
|
473
456
|
ws: WriteSet,
|
|
474
457
|
): void {
|
|
475
458
|
if (!fs.existsSync(dst)) return;
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
try {
|
|
479
|
-
existing = JSON.parse(fs.readFileSync(dst, "utf-8")) as Record<string, JsonValue>;
|
|
480
|
-
} catch {
|
|
481
|
-
existing = null;
|
|
482
|
-
}
|
|
459
|
+
const read = readJsonFile(dst);
|
|
460
|
+
const existing = read.ok ? (read.value as Record<string, JsonValue> | null) : null;
|
|
483
461
|
if (existing === null) {
|
|
484
462
|
console.warn(`[bkit] ${dst} is malformed — leaving as-is`);
|
|
485
463
|
return;
|
|
@@ -558,7 +536,7 @@ export function runOpencodeModule(ctx: ModuleContext): void {
|
|
|
558
536
|
action:
|
|
559
537
|
`opencode setup for provider "${provider}":\n\n` +
|
|
560
538
|
(() => {
|
|
561
|
-
const pd = OPENCODE_PROVIDER_DEFAULTS[provider];
|
|
539
|
+
const pd = isOpencodeProvider(provider) ? OPENCODE_PROVIDER_DEFAULTS[provider] : undefined;
|
|
562
540
|
if (!pd) {
|
|
563
541
|
return (
|
|
564
542
|
` 1. Set ${provider.toUpperCase()}_API_KEY in your environment / .bkit/.env.\n` +
|
|
@@ -588,7 +566,7 @@ export function runOpencodeModule(ctx: ModuleContext): void {
|
|
|
588
566
|
` env — {env:KEY} placeholders in opencode.json resolve empty without this. Quit the\n` +
|
|
589
567
|
` running app first (a running instance ignores the new env).\n` +
|
|
590
568
|
` 4. Model IDs: all four providers (openrouter, ollama, opencode-zen, opencode-go) install ready-to-run curated per-agent pins. ` +
|
|
591
|
-
`Re-pin any agent via .bkit/prompts.md § Model Overrides or by probing the provider's live /v1/models — see .bkit/providers.md § Models. NOTE: ollama
|
|
569
|
+
`Re-pin any agent via .bkit/prompts.md § Model Overrides or by probing the provider's live /v1/models — see .bkit/providers.md § Models. NOTE: every ollama pin (deepseek-v4.1-flash, kimi-k3) needs a paid Ollama plan. opencode-go pins (deepseek-v4.1-flash, kimi-k3) — prefer pins that stay within the Go 5h usage window; opencode-zen pins are existence-validated via models.dev (the /zen/v1/models REST probe cannot see Go-only models — models.dev is the source of truth).\n` +
|
|
592
570
|
` 5. Verify with: \`bkit doctor\` (credentials + tools) and \`bkit status\` (installed hosts + providers).`,
|
|
593
571
|
});
|
|
594
572
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// install/network-allowlist.ts — `.bkit/allowlist.json`, the resolved network allowlist
|
|
2
|
+
// (shipped egress registry ∪ consumer `allowed-domains`) the guardrails hooks of Claude,
|
|
3
|
+
// Cursor, Codex and Antigravity read at runtime to host-check shell curl / wget. Core
|
|
4
|
+
// owns it: install (runCoreModule) and upgrade (renderManagedOutputs) both write it, so
|
|
5
|
+
// it exists for every host that reads it and `bkit check` reports it missing or stale.
|
|
6
|
+
|
|
7
|
+
import * as fs from "node:fs";
|
|
8
|
+
import * as path from "node:path";
|
|
9
|
+
import { resolveNetworkAllowlist } from "./cloud-env.js";
|
|
10
|
+
import { readBkitVersion } from "./version-file.js";
|
|
11
|
+
import type { WriteSet } from "./write.js";
|
|
12
|
+
|
|
13
|
+
/** Consumer-relative path of the install-written curl/wget allowlist. */
|
|
14
|
+
export const NETWORK_ALLOWLIST_RELPATH = path.join(".bkit", "allowlist.json");
|
|
15
|
+
|
|
16
|
+
/** Where the cursor module wrote the allowlist up to 5.2.4 (migrated away). */
|
|
17
|
+
export const RETIRED_NETWORK_ALLOWLIST_RELPATH = path.join(".cursor", "allowlist.json");
|
|
18
|
+
|
|
19
|
+
/** The allowlist file body: `{ domains }`, apex + `*.` wildcard per base, sorted. */
|
|
20
|
+
export function renderNetworkAllowlist(cwd: string): string {
|
|
21
|
+
return JSON.stringify({ domains: resolveNetworkAllowlist(cwd) }, null, 2) + "\n";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Write `.bkit/allowlist.json` whole (hand edits do not survive — `allowed-domains` in
|
|
26
|
+
* `.agents/context.md` is the source), then migrate the retired copy. Every change is
|
|
27
|
+
* recorded in `ws` under dry-run too, so `bkit check` fails until install / upgrade runs.
|
|
28
|
+
* Returns the consumer-relative paths changed.
|
|
29
|
+
*/
|
|
30
|
+
export function writeNetworkAllowlist(
|
|
31
|
+
cwd: string,
|
|
32
|
+
dryRun: boolean,
|
|
33
|
+
ws: WriteSet,
|
|
34
|
+
logPrefix: string,
|
|
35
|
+
): string[] {
|
|
36
|
+
const tag = dryRun ? "[dry-run] " : "";
|
|
37
|
+
const changed: string[] = [];
|
|
38
|
+
const abs = path.join(cwd, NETWORK_ALLOWLIST_RELPATH);
|
|
39
|
+
const body = renderNetworkAllowlist(cwd);
|
|
40
|
+
const prev = fs.existsSync(abs) ? fs.readFileSync(abs, "utf-8") : null;
|
|
41
|
+
if (prev !== body) {
|
|
42
|
+
if (!dryRun) {
|
|
43
|
+
fs.mkdirSync(path.dirname(abs), { recursive: true });
|
|
44
|
+
fs.writeFileSync(abs, body, "utf-8");
|
|
45
|
+
}
|
|
46
|
+
ws.writes.push({ path: NETWORK_ALLOWLIST_RELPATH, action: prev === null ? "write" : "update" });
|
|
47
|
+
changed.push(NETWORK_ALLOWLIST_RELPATH);
|
|
48
|
+
console.log(`${logPrefix} ${tag}core: ${NETWORK_ALLOWLIST_RELPATH}`);
|
|
49
|
+
}
|
|
50
|
+
if (migrateRetiredNetworkAllowlist(cwd, dryRun)) {
|
|
51
|
+
ws.writes.push({ path: RETIRED_NETWORK_ALLOWLIST_RELPATH, action: "write" });
|
|
52
|
+
changed.push(RETIRED_NETWORK_ALLOWLIST_RELPATH);
|
|
53
|
+
console.log(
|
|
54
|
+
`${logPrefix} ${tag}core: removed ${RETIRED_NETWORK_ALLOWLIST_RELPATH} (moved to ${NETWORK_ALLOWLIST_RELPATH})`,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
return changed;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Migration (installs up to 5.2.4, `docs/migrations.md`): delete `.cursor/allowlist.json`
|
|
62
|
+
* when `.bkit/version` records its hash — bkit wrote it and owned it whole. A file bkit
|
|
63
|
+
* never recorded is left alone. Returns whether the file is (or, under dry-run, would be)
|
|
64
|
+
* removed. The stale hash entry is pruned by the `.bkit/version` writer.
|
|
65
|
+
*/
|
|
66
|
+
function migrateRetiredNetworkAllowlist(cwd: string, dryRun: boolean): boolean {
|
|
67
|
+
const abs = path.join(cwd, RETIRED_NETWORK_ALLOWLIST_RELPATH);
|
|
68
|
+
if (!fs.existsSync(abs)) return false;
|
|
69
|
+
const hashes = readBkitVersion(path.join(cwd, ".bkit", "version"))?.canonicalHashes ?? {};
|
|
70
|
+
if (hashes[RETIRED_NETWORK_ALLOWLIST_RELPATH] === undefined) return false;
|
|
71
|
+
if (!dryRun) fs.rmSync(abs);
|
|
72
|
+
return true;
|
|
73
|
+
}
|