@cbartens/bkit 5.2.4 → 5.3.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 +26 -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 +11 -0
- package/.bkit/core/.bkit/README.md +25 -10
- package/.bkit/core/.bkit/cloud.md +9 -8
- package/.bkit/core/.bkit/comparison.md +68 -345
- package/.bkit/core/.bkit/install.md +12 -6
- package/.bkit/core/.bkit/lite.md +73 -0
- package/.bkit/core/.bkit/pipeline.md +345 -0
- package/.bkit/core/.bkit/prompts.md +88 -73
- package/.bkit/core/.bkit/providers.md +41 -22
- package/.bkit/core/.bkit/templates.md +106 -17
- package/.bkit/core/.bkit/trackers.md +47 -1
- package/.bkit/core/.bkit/workflows.md +44 -43
- 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-adoption.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-dependencies.md +14 -10
- package/.bkit/core/docs/templates/bkit-audit-llm.md +20 -14
- package/.bkit/core/docs/templates/bkit-audit-prompts.md +2 -2
- package/.bkit/core/docs/templates/bkit-audit-red-team.md +10 -8
- package/.bkit/core/docs/templates/bkit-audit-security.md +3 -3
- package/.bkit/core/docs/templates/bkit-audit-testing.md +4 -3
- 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 -5
- package/.bkit/core/engine/checks/tips/catalogue.ts +60 -24
- package/.bkit/core/engine/checks/tips/detect.ts +45 -2
- package/.bkit/core/engine/checks/tips/index.ts +37 -8
- package/.bkit/core/engine/cli.ts +39 -16
- package/.bkit/core/engine/commands/analysis.ts +36 -26
- package/.bkit/core/engine/commands/comply.ts +17 -16
- 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 +62 -126
- 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/lib.ts +35 -10
- package/.bkit/core/engine/commands/tips.ts +8 -5
- package/.bkit/core/engine/commands/workflow/branches.ts +4 -4
- package/.bkit/core/engine/commands/workflow/counters.ts +21 -12
- package/.bkit/core/engine/commands/workflow/fids.ts +46 -0
- package/.bkit/core/engine/commands/workflow/ledgers.ts +3 -1
- package/.bkit/core/engine/commands/workflow/prs.ts +4 -2
- package/.bkit/core/engine/commands/workflow/repo.ts +2 -2
- package/.bkit/core/engine/commands/workflow/roadmap.ts +4 -3
- package/.bkit/core/engine/commands/workflow/runs.ts +8 -7
- package/.bkit/core/engine/commands/workflow/steps.ts +1 -0
- package/.bkit/core/engine/commands/workflow/tests.ts +17 -5
- package/.bkit/core/engine/commands/workflow/workflows.ts +15 -14
- package/.bkit/core/engine/commands/workflow/workstreams.ts +2 -1
- package/.bkit/core/engine/commands/workflow/worktrees.ts +13 -5
- 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 +91 -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 +3 -18
- 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 +36 -0
- 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 +60 -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-build.md +3 -3
- package/.bkit/core/workflows/bkit-debug.md +69 -33
- package/.bkit/core/workflows/bkit-design.md +2 -2
- package/.bkit/core/workflows/bkit-plan.md +11 -4
- package/.bkit/core/workflows/bkit-ship.md +5 -5
- package/.bkit/shared/.claude/bkit-cloud.md +46 -13
- package/.bkit/shared/.claude/settings.json +18 -0
- package/.bkit/shared/.cursor/mcp.json +2 -1
- package/.bkit/shared/.opencode/opencode.json +19 -1
- package/.bkit/shared/docs/deployments.md +20 -4
- package/.bkit/shared/docs/security.md +8 -6
- package/.bkit/shared/docs/testing.md +9 -5
- 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 +66 -53
- 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-push +8 -3
- 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/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 +50 -3
- package/README.md +258 -129
- 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 -6
- package/dist/checks/tips/catalogue.js +51 -18
- package/dist/checks/tips/detect.js +41 -2
- package/dist/checks/tips/index.js +25 -5
- package/dist/cli.js +34 -14
- package/dist/commands/analysis.js +21 -5
- package/dist/commands/comply.js +20 -18
- package/dist/commands/harvest.js +12 -13
- package/dist/commands/install/doctor.js +55 -23
- package/dist/commands/install/install.js +62 -118
- package/dist/commands/install/uninstall.js +165 -31
- package/dist/commands/install/upgrade.js +46 -39
- package/dist/commands/lib.js +32 -10
- package/dist/commands/tips.js +6 -3
- package/dist/commands/workflow/branches.js +3 -5
- package/dist/commands/workflow/counters.js +17 -7
- package/dist/commands/workflow/fids.js +39 -0
- package/dist/commands/workflow/ledgers.js +3 -1
- package/dist/commands/workflow/prs.js +3 -3
- package/dist/commands/workflow/repo.js +2 -2
- package/dist/commands/workflow/roadmap.js +4 -4
- package/dist/commands/workflow/runs.js +5 -5
- package/dist/commands/workflow/steps.js +1 -0
- package/dist/commands/workflow/tests.js +16 -3
- package/dist/commands/workflow/workflows.js +15 -15
- package/dist/commands/workflow/workstreams.js +2 -1
- package/dist/commands/workflow/worktrees.js +4 -5
- 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 +82 -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 +3 -16
- 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 +18 -1
- package/package.json +21 -17
- package/.bkit/core/.agents/shortcuts.md +0 -73
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// the provider-templated `opencode.json`.
|
|
3
3
|
import * as fs from "node:fs";
|
|
4
4
|
import * as path from "node:path";
|
|
5
|
-
import { writeTier2, deepMergeJson, ensureDir } from "../write.js";
|
|
5
|
+
import { writeTier2, deepMergeJson, ensureDir, isJsonObject, mergeTrackerEntry, } from "../write.js";
|
|
6
6
|
import { stampManagedVersion } from "../version-file.js";
|
|
7
7
|
import { applyOpencodeAgent, applyOpencodeCommand } from "../../render/hosts.js";
|
|
8
8
|
import { getCoreRoot, getSharedRoot, getWorkflowsRoot, getPromptsRoot, } from "../../shared/package-roots.js";
|
|
@@ -10,8 +10,11 @@ import { DEFAULT_ISSUE_TRACKER } from "../manifest.js";
|
|
|
10
10
|
import { substituteWorkflow } from "../../render/trackers.js";
|
|
11
11
|
import { resolveNetworkAllowlist, extractMcpServers, networkAllowlistBases } from "../cloud-env.js";
|
|
12
12
|
import { OPENCODE_PROVIDER_DEFAULTS } from "../../shared/egress.js";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
13
|
+
import { parseJson, readJsonFile } from "../../shared/json.js";
|
|
14
|
+
import { readBkitConfig } from "../../shared/settings.js";
|
|
15
|
+
import { readInstallingVersion } from "../../shared/package-json.js";
|
|
16
|
+
import { BKIT_PREFIX, installFile, listMdFiles, removeOrphans, trackMirrorWrite } from "./core.js";
|
|
17
|
+
import { isOpencodeProvider, opencodeProviderId } from "../../render/models.js";
|
|
15
18
|
export function renderOpencodeAgentsCommands(ctx) {
|
|
16
19
|
const { dryRun, opencodeModelLookup, effortMap, opencodeProvider, logPrefix } = ctx;
|
|
17
20
|
const tag = dryRun ? "[dry-run] " : "";
|
|
@@ -42,23 +45,11 @@ export function renderOpencodeAgentsCommands(ctx) {
|
|
|
42
45
|
trackMirrorWrite(ctx, rel, written);
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (!f.endsWith(".md"))
|
|
51
|
-
continue;
|
|
52
|
-
if (!f.startsWith(BKIT_PREFIX))
|
|
53
|
-
continue;
|
|
54
|
-
if (!sourceSet.has(f)) {
|
|
55
|
-
const rel = path.join(dest, f);
|
|
56
|
-
if (!dryRun)
|
|
57
|
-
fs.rmSync(path.join(dest, f));
|
|
58
|
-
console.log(`${logPrefix} ${tag}delete orphan: ${rel}`);
|
|
59
|
-
trackMirrorWrite(ctx, rel, written);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
48
|
+
// dryRun still reports would-deletes into ws.writes so `bkit check` fails on stale mirrors.
|
|
49
|
+
for (const f of removeOrphans(dest, sourceSet, dryRun, BKIT_PREFIX)) {
|
|
50
|
+
const rel = path.join(dest, f);
|
|
51
|
+
console.log(`${logPrefix} ${tag}delete orphan: ${rel}`);
|
|
52
|
+
trackMirrorWrite(ctx, rel, written);
|
|
62
53
|
}
|
|
63
54
|
}
|
|
64
55
|
// --- Commands: tracker substitution + applyOpencodeCommand ---
|
|
@@ -78,20 +69,10 @@ export function renderOpencodeAgentsCommands(ctx) {
|
|
|
78
69
|
trackMirrorWrite(ctx, rel, written);
|
|
79
70
|
}
|
|
80
71
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (!f.startsWith(BKIT_PREFIX))
|
|
86
|
-
continue;
|
|
87
|
-
if (!sourceSet.has(f)) {
|
|
88
|
-
const rel = path.join(dest, f);
|
|
89
|
-
if (!dryRun)
|
|
90
|
-
fs.rmSync(path.join(dest, f));
|
|
91
|
-
console.log(`${logPrefix} ${tag}delete orphan: ${rel}`);
|
|
92
|
-
trackMirrorWrite(ctx, rel, written);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
72
|
+
for (const f of removeOrphans(dest, sourceSet, dryRun, BKIT_PREFIX)) {
|
|
73
|
+
const rel = path.join(dest, f);
|
|
74
|
+
console.log(`${logPrefix} ${tag}delete orphan: ${rel}`);
|
|
75
|
+
trackMirrorWrite(ctx, rel, written);
|
|
95
76
|
}
|
|
96
77
|
}
|
|
97
78
|
return written;
|
|
@@ -118,7 +99,7 @@ export function renderOpencodeAgentsCommands(ctx) {
|
|
|
118
99
|
* secret against the installed provider.
|
|
119
100
|
*/
|
|
120
101
|
export function opencodeProviderEnvVar(providerKey) {
|
|
121
|
-
return OPENCODE_PROVIDER_DEFAULTS[providerKey]
|
|
102
|
+
return isOpencodeProvider(providerKey) ? OPENCODE_PROVIDER_DEFAULTS[providerKey].envVar : "";
|
|
122
103
|
}
|
|
123
104
|
/**
|
|
124
105
|
* Detect drift between the self-installed `.github/workflows/opencode.yml` reactive `/oc` handler
|
|
@@ -141,19 +122,8 @@ export function detectOpencodeYmlProviderDrift(cwd) {
|
|
|
141
122
|
if (!fs.existsSync(ymlPath))
|
|
142
123
|
return null;
|
|
143
124
|
// The installed provider — package.json `bkit.opencodeProvider` is the authoritative record
|
|
144
|
-
// written on install. Absent/broken → the null-guard below skips silently.
|
|
145
|
-
|
|
146
|
-
const pkgPath = path.join(cwd, "package.json");
|
|
147
|
-
if (fs.existsSync(pkgPath)) {
|
|
148
|
-
try {
|
|
149
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
150
|
-
if (typeof pkg.bkit?.opencodeProvider === "string")
|
|
151
|
-
provider = pkg.bkit.opencodeProvider;
|
|
152
|
-
}
|
|
153
|
-
catch {
|
|
154
|
-
// Malformed package.json — leave provider null; a JSON-drift advisory covers that separately.
|
|
155
|
-
}
|
|
156
|
-
}
|
|
125
|
+
// written on install. Absent/broken/unsupported → the null-guard below skips silently.
|
|
126
|
+
const provider = readBkitConfig(cwd).opencodeProvider;
|
|
157
127
|
if (!provider)
|
|
158
128
|
return null;
|
|
159
129
|
const expectedPrefix = opencodeProviderId(provider); // model id form is `<providerId>/<model>`
|
|
@@ -222,10 +192,10 @@ export function renderOpencodeJson(templatePath, tracker, provider, cwd = proces
|
|
|
222
192
|
const raw = fs.readFileSync(templatePath, "utf-8");
|
|
223
193
|
// Strict allowlist: provider is gated to OPENCODE_PROVIDERS at the CLI, so it is always
|
|
224
194
|
// a known key here. An unknown id throws; no substitute provider.
|
|
225
|
-
|
|
226
|
-
if (!providerDefaults) {
|
|
195
|
+
if (!isOpencodeProvider(provider)) {
|
|
227
196
|
throw new Error(`renderOpencodeJson: unknown opencode provider ${JSON.stringify(provider)}`);
|
|
228
197
|
}
|
|
198
|
+
const providerDefaults = OPENCODE_PROVIDER_DEFAULTS[provider];
|
|
229
199
|
// Resolve tracker MCP entry
|
|
230
200
|
// opencode's MCP schema differs from Claude/Cursor: remote servers use type "remote"
|
|
231
201
|
// (NOT "http" — not in opencode's enum, which makes the whole config invalid) and read
|
|
@@ -237,7 +207,7 @@ export function renderOpencodeJson(templatePath, tracker, provider, cwd = proces
|
|
|
237
207
|
let mcpEntry;
|
|
238
208
|
if (tracker === "github") {
|
|
239
209
|
mcpEntry =
|
|
240
|
-
'"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" } }';
|
|
210
|
+
'"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" } }';
|
|
241
211
|
}
|
|
242
212
|
else if (tracker === "linear") {
|
|
243
213
|
mcpEntry = '"linear": { "type": "remote", "url": "https://mcp.linear.app/mcp" }';
|
|
@@ -251,7 +221,10 @@ export function renderOpencodeJson(templatePath, tracker, provider, cwd = proces
|
|
|
251
221
|
rendered = rendered.replace(OPENCODE_PROVIDER_BASE_URL_SENTINEL, providerDefaults.baseURL);
|
|
252
222
|
// Parse + re-serialize to normalise JSON (removes empty mcp entry if tracker=none)
|
|
253
223
|
try {
|
|
254
|
-
const
|
|
224
|
+
const renderedDoc = parseJson(rendered);
|
|
225
|
+
if (!renderedDoc.ok)
|
|
226
|
+
return rendered;
|
|
227
|
+
const parsed = renderedDoc.value;
|
|
255
228
|
// Clean up empty mcp object when tracker=none
|
|
256
229
|
const mcp = parsed.mcp;
|
|
257
230
|
if (mcp && Object.keys(mcp).length === 0) {
|
|
@@ -350,20 +323,22 @@ export function reconcileOpencodeJson(renderedTemplate, relDst, dryRun, ws) {
|
|
|
350
323
|
ws.writes.push({ path: relDst, action: "write" });
|
|
351
324
|
return;
|
|
352
325
|
}
|
|
353
|
-
//
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
let existing = null;
|
|
357
|
-
try {
|
|
358
|
-
existing = JSON.parse(fs.readFileSync(relDst, "utf-8"));
|
|
359
|
-
}
|
|
360
|
-
catch {
|
|
361
|
-
existing = null;
|
|
362
|
-
}
|
|
326
|
+
// Malformed consumer JSON is a hard stop: refuse to merge, require a fix.
|
|
327
|
+
const read = readJsonFile(relDst);
|
|
328
|
+
const existing = read.ok ? read.value : null;
|
|
363
329
|
if (existing === null) {
|
|
364
330
|
throw new Error(`[bkit] ${relDst} is malformed JSON — fix manually before running bkit install`);
|
|
365
331
|
}
|
|
366
332
|
const merged = deepMergeJson(existing, template);
|
|
333
|
+
// The tracker `mcp` entry keeps the consumer's extra toolsets (`mergeTrackerEntry`), which
|
|
334
|
+
// the plain merge above would overwrite with the template's list.
|
|
335
|
+
const tmplMcp = template.mcp;
|
|
336
|
+
const existingMcp = existing.mcp;
|
|
337
|
+
if (isJsonObject(tmplMcp) && isJsonObject(existingMcp) && isJsonObject(merged.mcp)) {
|
|
338
|
+
for (const [k, v] of Object.entries(tmplMcp)) {
|
|
339
|
+
merged.mcp[k] = mergeTrackerEntry(existingMcp[k], v);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
367
342
|
// Replace (do not deep-merge) each provider key the template seeds — heals hijacked
|
|
368
343
|
// npm/baseURL/name while keeping other provider keys additive.
|
|
369
344
|
//
|
|
@@ -411,14 +386,8 @@ export function reconcileOpencodeJson(renderedTemplate, relDst, dryRun, ws) {
|
|
|
411
386
|
export function removeOpencodeProviderBlock(dst, providerKey, dryRun, ws) {
|
|
412
387
|
if (!fs.existsSync(dst))
|
|
413
388
|
return;
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
try {
|
|
417
|
-
existing = JSON.parse(fs.readFileSync(dst, "utf-8"));
|
|
418
|
-
}
|
|
419
|
-
catch {
|
|
420
|
-
existing = null;
|
|
421
|
-
}
|
|
389
|
+
const read = readJsonFile(dst);
|
|
390
|
+
const existing = read.ok ? read.value : null;
|
|
422
391
|
if (existing === null) {
|
|
423
392
|
console.warn(`[bkit] ${dst} is malformed — leaving as-is`);
|
|
424
393
|
return;
|
|
@@ -494,7 +463,7 @@ export function runOpencodeModule(ctx) {
|
|
|
494
463
|
detect: `opencode host installed (provider: ${provider}). The opencode CLI and your provider credentials are required before running agents.`,
|
|
495
464
|
action: `opencode setup for provider "${provider}":\n\n` +
|
|
496
465
|
(() => {
|
|
497
|
-
const pd = OPENCODE_PROVIDER_DEFAULTS[provider];
|
|
466
|
+
const pd = isOpencodeProvider(provider) ? OPENCODE_PROVIDER_DEFAULTS[provider] : undefined;
|
|
498
467
|
if (!pd) {
|
|
499
468
|
return (` 1. Set ${provider.toUpperCase()}_API_KEY in your environment / .bkit/.env.\n` +
|
|
500
469
|
` 2. Update .opencode/opencode.json provider.${provider}.options.baseURL for your endpoint.\n`);
|
|
@@ -518,7 +487,7 @@ export function runOpencodeModule(ctx) {
|
|
|
518
487
|
` env — {env:KEY} placeholders in opencode.json resolve empty without this. Quit the\n` +
|
|
519
488
|
` running app first (a running instance ignores the new env).\n` +
|
|
520
489
|
` 4. Model IDs: all four providers (openrouter, ollama, opencode-zen, opencode-go) install ready-to-run curated per-agent pins. ` +
|
|
521
|
-
`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
|
|
490
|
+
`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` +
|
|
522
491
|
` 5. Verify with: \`bkit doctor\` (credentials + tools) and \`bkit status\` (installed hosts + providers).`,
|
|
523
492
|
});
|
|
524
493
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
import * as fs from "node:fs";
|
|
7
|
+
import * as path from "node:path";
|
|
8
|
+
import { resolveNetworkAllowlist } from "./cloud-env.js";
|
|
9
|
+
import { readBkitVersion } from "./version-file.js";
|
|
10
|
+
/** Consumer-relative path of the install-written curl/wget allowlist. */
|
|
11
|
+
export const NETWORK_ALLOWLIST_RELPATH = path.join(".bkit", "allowlist.json");
|
|
12
|
+
/** Where the cursor module wrote the allowlist up to 5.2.4 (migrated away). */
|
|
13
|
+
export const RETIRED_NETWORK_ALLOWLIST_RELPATH = path.join(".cursor", "allowlist.json");
|
|
14
|
+
/** The allowlist file body: `{ domains }`, apex + `*.` wildcard per base, sorted. */
|
|
15
|
+
export function renderNetworkAllowlist(cwd) {
|
|
16
|
+
return JSON.stringify({ domains: resolveNetworkAllowlist(cwd) }, null, 2) + "\n";
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Write `.bkit/allowlist.json` whole (hand edits do not survive — `allowed-domains` in
|
|
20
|
+
* `.agents/context.md` is the source), then migrate the retired copy. Every change is
|
|
21
|
+
* recorded in `ws` under dry-run too, so `bkit check` fails until install / upgrade runs.
|
|
22
|
+
* Returns the consumer-relative paths changed.
|
|
23
|
+
*/
|
|
24
|
+
export function writeNetworkAllowlist(cwd, dryRun, ws, logPrefix) {
|
|
25
|
+
const tag = dryRun ? "[dry-run] " : "";
|
|
26
|
+
const changed = [];
|
|
27
|
+
const abs = path.join(cwd, NETWORK_ALLOWLIST_RELPATH);
|
|
28
|
+
const body = renderNetworkAllowlist(cwd);
|
|
29
|
+
const prev = fs.existsSync(abs) ? fs.readFileSync(abs, "utf-8") : null;
|
|
30
|
+
if (prev !== body) {
|
|
31
|
+
if (!dryRun) {
|
|
32
|
+
fs.mkdirSync(path.dirname(abs), { recursive: true });
|
|
33
|
+
fs.writeFileSync(abs, body, "utf-8");
|
|
34
|
+
}
|
|
35
|
+
ws.writes.push({ path: NETWORK_ALLOWLIST_RELPATH, action: prev === null ? "write" : "update" });
|
|
36
|
+
changed.push(NETWORK_ALLOWLIST_RELPATH);
|
|
37
|
+
console.log(`${logPrefix} ${tag}core: ${NETWORK_ALLOWLIST_RELPATH}`);
|
|
38
|
+
}
|
|
39
|
+
if (migrateRetiredNetworkAllowlist(cwd, dryRun)) {
|
|
40
|
+
ws.writes.push({ path: RETIRED_NETWORK_ALLOWLIST_RELPATH, action: "write" });
|
|
41
|
+
changed.push(RETIRED_NETWORK_ALLOWLIST_RELPATH);
|
|
42
|
+
console.log(`${logPrefix} ${tag}core: removed ${RETIRED_NETWORK_ALLOWLIST_RELPATH} (moved to ${NETWORK_ALLOWLIST_RELPATH})`);
|
|
43
|
+
}
|
|
44
|
+
return changed;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Migration (installs up to 5.2.4, `docs/migrations.md`): delete `.cursor/allowlist.json`
|
|
48
|
+
* when `.bkit/version` records its hash — bkit wrote it and owned it whole. A file bkit
|
|
49
|
+
* never recorded is left alone. Returns whether the file is (or, under dry-run, would be)
|
|
50
|
+
* removed. The stale hash entry is pruned by the `.bkit/version` writer.
|
|
51
|
+
*/
|
|
52
|
+
function migrateRetiredNetworkAllowlist(cwd, dryRun) {
|
|
53
|
+
const abs = path.join(cwd, RETIRED_NETWORK_ALLOWLIST_RELPATH);
|
|
54
|
+
if (!fs.existsSync(abs))
|
|
55
|
+
return false;
|
|
56
|
+
const hashes = readBkitVersion(path.join(cwd, ".bkit", "version"))?.canonicalHashes ?? {};
|
|
57
|
+
if (hashes[RETIRED_NETWORK_ALLOWLIST_RELPATH] === undefined)
|
|
58
|
+
return false;
|
|
59
|
+
if (!dryRun)
|
|
60
|
+
fs.rmSync(abs);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
@@ -1,22 +1,9 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as path from "node:path";
|
|
3
3
|
import { execSync } from "node:child_process";
|
|
4
|
-
import {
|
|
4
|
+
import { readInstallingVersion } from "../shared/package-json.js";
|
|
5
5
|
import { managedVersionMarker } from "./version-file.js";
|
|
6
6
|
import { gitEnv, resolveRepoSlug } from "../ledgers/telemetry.js";
|
|
7
|
-
// Read the INSTALLING bkit version from the package root (NOT the consumer's
|
|
8
|
-
// package.json — that is a different version). Mirrors readInstallingVersion
|
|
9
|
-
// (install/modules/index.ts) / readPkgVersion (checks/after/index.ts); kept local to avoid a
|
|
10
|
-
// tokens → modules import cycle. "0.0.0" on any read failure.
|
|
11
|
-
function readInstallingBkitVersion() {
|
|
12
|
-
try {
|
|
13
|
-
const pkg = JSON.parse(fs.readFileSync(path.join(getPkgRoot(), "package.json"), "utf-8"));
|
|
14
|
-
return pkg.version ?? "0.0.0";
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
return "0.0.0";
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
7
|
// Resolve DEFAULT_BRANCH: git symbolic-ref refs/remotes/origin/HEAD → "main"
|
|
21
8
|
function resolveDefaultBranch(cwd) {
|
|
22
9
|
try {
|
|
@@ -58,7 +45,7 @@ export async function resolveTokens(cwd) {
|
|
|
58
45
|
DEFAULT_BRANCH: resolveDefaultBranch(cwd),
|
|
59
46
|
PROJECT_NAME: name.trim(),
|
|
60
47
|
REPO_SLUG: resolveRepoSlug(cwd),
|
|
61
|
-
BKIT_VERSION:
|
|
48
|
+
BKIT_VERSION: readInstallingVersion(),
|
|
62
49
|
};
|
|
63
50
|
}
|
|
64
51
|
// Substitute {{TOKEN}} placeholders in content string.
|
|
@@ -78,7 +65,7 @@ export function applyTokens(content, tokens) {
|
|
|
78
65
|
// so `# {{BKIT_MANAGED_MARKER}}` yields the hash form. The version is read from the
|
|
79
66
|
// package only when the token is present and the TokenMap omits BKIT_VERSION.
|
|
80
67
|
if (out.includes("{{BKIT_MANAGED_MARKER}}")) {
|
|
81
|
-
const version = tokens.BKIT_VERSION ??
|
|
68
|
+
const version = tokens.BKIT_VERSION ?? readInstallingVersion();
|
|
82
69
|
out = out
|
|
83
70
|
.replace(/^\/\/ \{\{BKIT_MANAGED_MARKER\}\}/gm, () => managedVersionMarker(version, "slash"))
|
|
84
71
|
.replace(/\{\{BKIT_MANAGED_MARKER\}\}/g, () => managedVersionMarker(version, "html"));
|
package/dist/install/write.js
CHANGED
|
@@ -2,6 +2,7 @@ import * as fs from "node:fs";
|
|
|
2
2
|
import * as path from "node:path";
|
|
3
3
|
import { updateManagedBlock, extractFullManagedBlock, extractManagedBlock, findLineAnchoredMarkers, findUnmarkedCopy, selectMarkers, } from "./managed-block.js";
|
|
4
4
|
import { readTemplate } from "../render/parts.js";
|
|
5
|
+
import { parseJson } from "../shared/json.js";
|
|
5
6
|
import { applyTokens } from "./placeholders.js";
|
|
6
7
|
import { sha256 } from "./version-file.js";
|
|
7
8
|
export function deepContains(template, consumer, pathPrefix = "") {
|
|
@@ -135,6 +136,51 @@ export function deepMergeJson(base, override) {
|
|
|
135
136
|
return result;
|
|
136
137
|
}
|
|
137
138
|
// ---------------------------------------------------------------------------
|
|
139
|
+
// MCP tracker entry — bkit owns the template's parts of the entry, not the whole entry (#613)
|
|
140
|
+
//
|
|
141
|
+
// - every key the template sets is reset to the template's value
|
|
142
|
+
// - `headers["X-MCP-Toolsets"]` keeps the consumer's list and appends any template toolset
|
|
143
|
+
// it lacks, so a consumer can enable extra toolsets and a toolset bkit adds still lands
|
|
144
|
+
// - every other consumer key, header and toolset is kept
|
|
145
|
+
// ---------------------------------------------------------------------------
|
|
146
|
+
export const MCP_TOOLSETS_HEADER = "X-MCP-Toolsets";
|
|
147
|
+
/** Split an `X-MCP-Toolsets` value into toolset names (trimmed, empties dropped). */
|
|
148
|
+
export function parseToolsets(value) {
|
|
149
|
+
return value
|
|
150
|
+
.split(",")
|
|
151
|
+
.map((s) => s.trim())
|
|
152
|
+
.filter((s) => s !== "");
|
|
153
|
+
}
|
|
154
|
+
/** True for a JSON object (not null, not an array). */
|
|
155
|
+
export function isJsonObject(v) {
|
|
156
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
157
|
+
}
|
|
158
|
+
/** Merge bkit's tracker entry `owned` into the consumer's `existing` entry (rules above). */
|
|
159
|
+
export function mergeTrackerEntry(existing, owned) {
|
|
160
|
+
if (!isJsonObject(existing) || !isJsonObject(owned))
|
|
161
|
+
return owned;
|
|
162
|
+
const merged = deepMergeJson(existing, owned);
|
|
163
|
+
const ownedHeaders = owned.headers;
|
|
164
|
+
const existingHeaders = existing.headers;
|
|
165
|
+
if (isJsonObject(ownedHeaders) && isJsonObject(existingHeaders)) {
|
|
166
|
+
const ownedSets = ownedHeaders[MCP_TOOLSETS_HEADER];
|
|
167
|
+
const existingSets = existingHeaders[MCP_TOOLSETS_HEADER];
|
|
168
|
+
if (typeof ownedSets === "string" && typeof existingSets === "string") {
|
|
169
|
+
const have = parseToolsets(existingSets);
|
|
170
|
+
const missing = parseToolsets(ownedSets).filter((t) => !have.includes(t));
|
|
171
|
+
merged.headers[MCP_TOOLSETS_HEADER] =
|
|
172
|
+
missing.length === 0 ? existingSets : [...have, ...missing].join(",");
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return merged;
|
|
176
|
+
}
|
|
177
|
+
/** True when `existing` already holds everything `mergeTrackerEntry` would write. */
|
|
178
|
+
export function trackerEntryInSync(existing, owned) {
|
|
179
|
+
if (existing === undefined)
|
|
180
|
+
return false;
|
|
181
|
+
return deepContains(mergeTrackerEntry(existing, owned), existing).ok;
|
|
182
|
+
}
|
|
183
|
+
// ---------------------------------------------------------------------------
|
|
138
184
|
// writeTier2JsonContained — deep-containment JSON helper (BAR-167 Phase 1)
|
|
139
185
|
//
|
|
140
186
|
// Contract:
|
|
@@ -147,13 +193,11 @@ export function deepMergeJson(base, override) {
|
|
|
147
193
|
// ---------------------------------------------------------------------------
|
|
148
194
|
export function writeTier2JsonContained(srcPath, dstPath, dryRun, ws) {
|
|
149
195
|
const srcRaw = fs.readFileSync(srcPath, "utf-8");
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
template = JSON.parse(srcRaw);
|
|
153
|
-
}
|
|
154
|
-
catch {
|
|
196
|
+
const templateRead = parseJson(srcRaw);
|
|
197
|
+
if (!templateRead.ok) {
|
|
155
198
|
throw new Error(`writeTier2JsonContained: template at ${srcPath} is not valid JSON`);
|
|
156
199
|
}
|
|
200
|
+
const template = templateRead.value;
|
|
157
201
|
if (!fs.existsSync(dstPath)) {
|
|
158
202
|
// First install — write template as-is
|
|
159
203
|
ensureDir(path.dirname(dstPath));
|
|
@@ -167,14 +211,12 @@ export function writeTier2JsonContained(srcPath, dstPath, dryRun, ws) {
|
|
|
167
211
|
}
|
|
168
212
|
// dest exists — read and check containment
|
|
169
213
|
const dstRaw = fs.readFileSync(dstPath, "utf-8");
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
existing = JSON.parse(dstRaw);
|
|
173
|
-
}
|
|
174
|
-
catch {
|
|
214
|
+
const existingRead = parseJson(dstRaw);
|
|
215
|
+
if (!existingRead.ok) {
|
|
175
216
|
// Malformed destination — refuse to overwrite; require manual fix (matches malformed-package-json blocker discipline)
|
|
176
217
|
throw new Error(`[bkit] ${dstPath} is malformed JSON — fix manually before running bkit install`);
|
|
177
218
|
}
|
|
219
|
+
const existing = existingRead.value;
|
|
178
220
|
// Check if existing already contains the template
|
|
179
221
|
const containsResult = deepContains(template, existing);
|
|
180
222
|
if (containsResult.ok) {
|
|
@@ -364,13 +406,11 @@ export function ensurePackageJsonScripts(scripts, dryRun, ws) {
|
|
|
364
406
|
return { added: [], preserved: [], missingPkg: true, malformed: false };
|
|
365
407
|
}
|
|
366
408
|
const raw = fs.readFileSync(pkgPath, "utf-8");
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
pkg = JSON.parse(raw);
|
|
370
|
-
}
|
|
371
|
-
catch {
|
|
409
|
+
const parsed = parseJson(raw);
|
|
410
|
+
if (!parsed.ok) {
|
|
372
411
|
return { added: [], preserved: [], missingPkg: false, malformed: true };
|
|
373
412
|
}
|
|
413
|
+
const pkg = parsed.value;
|
|
374
414
|
let pkgScripts = pkg.scripts ?? undefined;
|
|
375
415
|
const added = [];
|
|
376
416
|
const preserved = [];
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
// so an unexpected version surfaces for triage.
|
|
19
19
|
import { spawnSync } from "node:child_process";
|
|
20
20
|
import * as fs from "node:fs";
|
|
21
|
+
import { parseJson } from "../shared/json.js";
|
|
21
22
|
// ---------------------------------------------------------------------------
|
|
22
23
|
// Constants
|
|
23
24
|
// ---------------------------------------------------------------------------
|
|
@@ -397,11 +398,11 @@ export function parse(raw) {
|
|
|
397
398
|
const trimmed = line.trim();
|
|
398
399
|
if (trimmed === "")
|
|
399
400
|
continue;
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
result.events.push(obj);
|
|
401
|
+
const obj = parseJson(trimmed);
|
|
402
|
+
if (obj.ok) {
|
|
403
|
+
result.events.push(obj.value);
|
|
403
404
|
}
|
|
404
|
-
|
|
405
|
+
else {
|
|
405
406
|
result.malformedLineCount++;
|
|
406
407
|
}
|
|
407
408
|
}
|
package/dist/render/hosts.js
CHANGED
|
@@ -103,22 +103,10 @@ export function antigravityToolsBlock(toolsBlock) {
|
|
|
103
103
|
* lookup missing for name.
|
|
104
104
|
*/
|
|
105
105
|
export function applyOpencodeAgent(content, opencodeModelLookup, effortMap, provider) {
|
|
106
|
-
const
|
|
107
|
-
if (!
|
|
106
|
+
const subagent = requireSubagentModel(content, opencodeModelLookup, "opencode");
|
|
107
|
+
if (!subagent)
|
|
108
108
|
return content;
|
|
109
|
-
const fmBlock =
|
|
110
|
-
const afterFm = content.slice(fmMatch[0].length);
|
|
111
|
-
const parsed = parseFrontmatter(fmBlock);
|
|
112
|
-
const name = parsed.get("name") ?? "";
|
|
113
|
-
if (!name) {
|
|
114
|
-
console.error(`${LOG_PREFIX} Subagent frontmatter missing 'name' field`);
|
|
115
|
-
process.exit(1);
|
|
116
|
-
}
|
|
117
|
-
const opencodeModel = opencodeModelLookup.get(name);
|
|
118
|
-
if (!opencodeModel) {
|
|
119
|
-
console.error(`${LOG_PREFIX} Missing opencode model lookup for ${name}`);
|
|
120
|
-
process.exit(1);
|
|
121
|
-
}
|
|
109
|
+
const { fmBlock, afterFm, parsed, name, model: opencodeModel } = subagent;
|
|
122
110
|
const description = parsed.get("description") ?? "";
|
|
123
111
|
const effort = parsed.get("effort");
|
|
124
112
|
const toolsBlock = extractFrontmatterField(fmBlock, "tools");
|
|
@@ -201,22 +189,11 @@ function tomlString(key, value) {
|
|
|
201
189
|
* host (documented in providers.md).
|
|
202
190
|
*/
|
|
203
191
|
export function applyCodexAgent(content, codexModelLookup, effortMap) {
|
|
204
|
-
const
|
|
205
|
-
if (!
|
|
192
|
+
const subagent = requireSubagentModel(content, codexModelLookup, "codex");
|
|
193
|
+
if (!subagent)
|
|
206
194
|
return content;
|
|
207
|
-
const
|
|
208
|
-
const body =
|
|
209
|
-
const parsed = parseFrontmatter(fmBlock);
|
|
210
|
-
const name = parsed.get("name") ?? "";
|
|
211
|
-
if (!name) {
|
|
212
|
-
console.error(`${LOG_PREFIX} Subagent frontmatter missing 'name' field`);
|
|
213
|
-
process.exit(1);
|
|
214
|
-
}
|
|
215
|
-
const model = codexModelLookup.get(name);
|
|
216
|
-
if (!model) {
|
|
217
|
-
console.error(`${LOG_PREFIX} Missing codex model lookup for ${name}`);
|
|
218
|
-
process.exit(1);
|
|
219
|
-
}
|
|
195
|
+
const { afterFm, parsed, name, model } = subagent;
|
|
196
|
+
const body = afterFm.trim();
|
|
220
197
|
const effort = parsed.get("effort");
|
|
221
198
|
let out = "";
|
|
222
199
|
out += tomlString("name", name);
|
|
@@ -347,27 +324,37 @@ function extractFrontmatterField(fmBlock, field) {
|
|
|
347
324
|
const m = fmBlock.match(re);
|
|
348
325
|
return m ? m[1] : null;
|
|
349
326
|
}
|
|
350
|
-
//
|
|
351
|
-
//
|
|
352
|
-
//
|
|
353
|
-
//
|
|
354
|
-
|
|
327
|
+
// Shared opening of the subagent renderers: split off the frontmatter, require `name`, look
|
|
328
|
+
// the model up. Returns null when `content` has no frontmatter (the renderer passes it
|
|
329
|
+
// through); exits 1 when `name` or the model is missing. `host` qualifies the model-lookup
|
|
330
|
+
// message ("" for the unqualified Cursor message).
|
|
331
|
+
function requireSubagentModel(content, lookup, host) {
|
|
355
332
|
const fmMatch = content.match(/^(---\r?\n)([\s\S]*?)(\r?\n---\r?\n?)/);
|
|
356
333
|
if (!fmMatch)
|
|
357
|
-
return
|
|
334
|
+
return null;
|
|
358
335
|
const fmBlock = fmMatch[2];
|
|
359
|
-
const afterFm = content.slice(fmMatch[0].length);
|
|
360
336
|
const parsed = parseFrontmatter(fmBlock);
|
|
361
337
|
const name = parsed.get("name") ?? "";
|
|
362
338
|
if (!name) {
|
|
363
339
|
console.error(`${LOG_PREFIX} Subagent frontmatter missing 'name' field`);
|
|
364
340
|
process.exit(1);
|
|
365
341
|
}
|
|
366
|
-
const
|
|
367
|
-
if (!
|
|
368
|
-
console.error(`${LOG_PREFIX} Missing model lookup for ${name}`);
|
|
342
|
+
const model = lookup.get(name);
|
|
343
|
+
if (!model) {
|
|
344
|
+
console.error(`${LOG_PREFIX} Missing ${host ? `${host} ` : ""}model lookup for ${name}`);
|
|
369
345
|
process.exit(1);
|
|
370
346
|
}
|
|
347
|
+
return { fmBlock, afterFm: content.slice(fmMatch[0].length), parsed, name, model };
|
|
348
|
+
}
|
|
349
|
+
// T3: Cursor subagent frontmatter rewrite.
|
|
350
|
+
// Emits: name, description, model, tools (passthrough — Cursor 2.4+ accepts identical tool names per BAR-113),
|
|
351
|
+
// effort (from prompts.md Cursor column). Drops: permissionMode, maxTurns, readonly, is_background.
|
|
352
|
+
// Hard-fails with non-zero exit if model lookup missing for name.
|
|
353
|
+
export function applyT3(content, modelLookup, effortMap) {
|
|
354
|
+
const subagent = requireSubagentModel(content, modelLookup, "");
|
|
355
|
+
if (!subagent)
|
|
356
|
+
return content;
|
|
357
|
+
const { fmBlock, afterFm, parsed, name, model: cursorModel } = subagent;
|
|
371
358
|
const description = parsed.get("description") ?? "";
|
|
372
359
|
const effort = parsed.get("effort");
|
|
373
360
|
const toolsBlock = extractFrontmatterField(fmBlock, "tools");
|
|
@@ -427,22 +414,10 @@ export function applyAntigravityToolRewrites(content, agentsDir = ANTIGRAVITY_AG
|
|
|
427
414
|
* readonly) are dropped. Hard-fails with non-zero exit if the model lookup is missing.
|
|
428
415
|
*/
|
|
429
416
|
export function applyAntigravityPrompt(content, modelLookup, effortMap) {
|
|
430
|
-
const
|
|
431
|
-
if (!
|
|
417
|
+
const subagent = requireSubagentModel(content, modelLookup, "antigravity");
|
|
418
|
+
if (!subagent)
|
|
432
419
|
return content;
|
|
433
|
-
const fmBlock =
|
|
434
|
-
const afterFm = content.slice(fmMatch[0].length);
|
|
435
|
-
const parsed = parseFrontmatter(fmBlock);
|
|
436
|
-
const name = parsed.get("name") ?? "";
|
|
437
|
-
if (!name) {
|
|
438
|
-
console.error(`${LOG_PREFIX} Subagent frontmatter missing 'name' field`);
|
|
439
|
-
process.exit(1);
|
|
440
|
-
}
|
|
441
|
-
const model = modelLookup.get(name);
|
|
442
|
-
if (!model) {
|
|
443
|
-
console.error(`${LOG_PREFIX} Missing antigravity model lookup for ${name}`);
|
|
444
|
-
process.exit(1);
|
|
445
|
-
}
|
|
420
|
+
const { fmBlock, afterFm, parsed, name, model } = subagent;
|
|
446
421
|
const description = parsed.get("description") ?? "";
|
|
447
422
|
const effort = parsed.get("effort");
|
|
448
423
|
const toolsBlock = extractFrontmatterField(fmBlock, "tools");
|
package/dist/render/models.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import * as fs from "node:fs";
|
|
4
4
|
import { findLineAnchoredMarkers, selectMarkers } from "../install/managed-block.js";
|
|
5
5
|
import { LOG_PREFIX } from "../shared/log-prefix.js";
|
|
6
|
-
import { OPENCODE_PROVIDER_DEFAULTS } from "../shared/egress.js";
|
|
6
|
+
import { OPENCODE_PROVIDERS, OPENCODE_PROVIDER_DEFAULTS, } from "../shared/egress.js";
|
|
7
7
|
/**
|
|
8
8
|
* Parse .bkit/prompts.md § Models table → Map<name, columnValue>.
|
|
9
9
|
* columnHeader is the column header label to extract (e.g. "Cursor model", "opencode model").
|
|
@@ -83,6 +83,9 @@ export function parseModelLookup(subagentsMdPath) {
|
|
|
83
83
|
*
|
|
84
84
|
* Cells hold the BARE, gateway-scoped model id. Any prefix a program's config format needs
|
|
85
85
|
* is added at render time by formatModelPin — never stored in the table.
|
|
86
|
+
*
|
|
87
|
+
* Every allowlisted opencode provider MUST have an entry; the `satisfies Record<OpencodeProvider | …>`
|
|
88
|
+
* check fails tsc when one is missing.
|
|
86
89
|
*/
|
|
87
90
|
const GATEWAY_COLUMN = {
|
|
88
91
|
anthropic: "Anthropic",
|
|
@@ -94,6 +97,9 @@ const GATEWAY_COLUMN = {
|
|
|
94
97
|
openai: "OpenAI",
|
|
95
98
|
google: "Google",
|
|
96
99
|
};
|
|
100
|
+
function isGatewayKey(value) {
|
|
101
|
+
return Object.hasOwn(GATEWAY_COLUMN, value);
|
|
102
|
+
}
|
|
97
103
|
/**
|
|
98
104
|
* Spell a model pin the way a program's config file expects it.
|
|
99
105
|
*
|
|
@@ -110,17 +116,16 @@ export function formatModelPin(program, gateway, bareModel) {
|
|
|
110
116
|
return bareModel;
|
|
111
117
|
}
|
|
112
118
|
/**
|
|
113
|
-
* Build the per-agent
|
|
114
|
-
* Source of truth = prompts.md § Models, which carries one curated column per
|
|
115
|
-
*
|
|
116
|
-
* ships a column;
|
|
119
|
+
* Build the per-agent model lookup for one gateway: an opencode provider, or the Codex
|
|
120
|
+
* "openai" column. Source of truth = prompts.md § Models, which carries one curated column per
|
|
121
|
+
* gateway ("OpenRouter", "Ollama", "OpenAI"). Header-addressed. Every key of GATEWAY_COLUMN
|
|
122
|
+
* ships a column; any other key throws.
|
|
117
123
|
*/
|
|
118
124
|
export function buildOpencodeModelLookup(subagentsMdPath, provider) {
|
|
119
|
-
|
|
120
|
-
if (!header) {
|
|
125
|
+
if (!isGatewayKey(provider)) {
|
|
121
126
|
throw new Error(`buildOpencodeModelLookup: no prompts.md § Models column for provider ${JSON.stringify(provider)}`);
|
|
122
127
|
}
|
|
123
|
-
return parseModelLookupForColumn(subagentsMdPath,
|
|
128
|
+
return parseModelLookupForColumn(subagentsMdPath, GATEWAY_COLUMN[provider]);
|
|
124
129
|
}
|
|
125
130
|
/**
|
|
126
131
|
* Build the per-agent Antigravity model lookup for Google models.
|
|
@@ -293,5 +298,11 @@ export function lookupEffort(effortMap, program, sourceEffort) {
|
|
|
293
298
|
* keys pass through unchanged.
|
|
294
299
|
*/
|
|
295
300
|
export function opencodeProviderId(providerKey) {
|
|
296
|
-
|
|
301
|
+
if (!isOpencodeProvider(providerKey))
|
|
302
|
+
return providerKey;
|
|
303
|
+
return OPENCODE_PROVIDER_DEFAULTS[providerKey].providerId ?? providerKey;
|
|
304
|
+
}
|
|
305
|
+
/** Narrow a raw string to the opencode provider allowlist. */
|
|
306
|
+
export function isOpencodeProvider(value) {
|
|
307
|
+
return OPENCODE_PROVIDERS.some((provider) => provider === value);
|
|
297
308
|
}
|