@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
|
@@ -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
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
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
7
|
|
|
@@ -18,21 +18,6 @@ export interface TokenMap {
|
|
|
18
18
|
BKIT_VERSION?: string;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
// Read the INSTALLING bkit version from the package root (NOT the consumer's
|
|
22
|
-
// package.json — that is a different version). Mirrors readInstallingVersion
|
|
23
|
-
// (install/modules/index.ts) / readPkgVersion (checks/after/index.ts); kept local to avoid a
|
|
24
|
-
// tokens → modules import cycle. "0.0.0" on any read failure.
|
|
25
|
-
function readInstallingBkitVersion(): string {
|
|
26
|
-
try {
|
|
27
|
-
const pkg = JSON.parse(fs.readFileSync(path.join(getPkgRoot(), "package.json"), "utf-8")) as {
|
|
28
|
-
version?: string;
|
|
29
|
-
};
|
|
30
|
-
return pkg.version ?? "0.0.0";
|
|
31
|
-
} catch {
|
|
32
|
-
return "0.0.0";
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
21
|
// Resolve DEFAULT_BRANCH: git symbolic-ref refs/remotes/origin/HEAD → "main"
|
|
37
22
|
function resolveDefaultBranch(cwd: string): string {
|
|
38
23
|
try {
|
|
@@ -78,7 +63,7 @@ export async function resolveTokens(cwd: string): Promise<TokenMap> {
|
|
|
78
63
|
DEFAULT_BRANCH: resolveDefaultBranch(cwd),
|
|
79
64
|
PROJECT_NAME: name.trim(),
|
|
80
65
|
REPO_SLUG: resolveRepoSlug(cwd),
|
|
81
|
-
BKIT_VERSION:
|
|
66
|
+
BKIT_VERSION: readInstallingVersion(),
|
|
82
67
|
};
|
|
83
68
|
}
|
|
84
69
|
|
|
@@ -99,7 +84,7 @@ export function applyTokens(content: string, tokens: TokenMap): string {
|
|
|
99
84
|
// so `# {{BKIT_MANAGED_MARKER}}` yields the hash form. The version is read from the
|
|
100
85
|
// package only when the token is present and the TokenMap omits BKIT_VERSION.
|
|
101
86
|
if (out.includes("{{BKIT_MANAGED_MARKER}}")) {
|
|
102
|
-
const version = tokens.BKIT_VERSION ??
|
|
87
|
+
const version = tokens.BKIT_VERSION ?? readInstallingVersion();
|
|
103
88
|
out = out
|
|
104
89
|
.replace(/^\/\/ \{\{BKIT_MANAGED_MARKER\}\}/gm, () => managedVersionMarker(version, "slash"))
|
|
105
90
|
.replace(/\{\{BKIT_MANAGED_MARKER\}\}/g, () => managedVersionMarker(version, "html"));
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
type MarkerStyle,
|
|
11
11
|
} from "./managed-block.js";
|
|
12
12
|
import { readTemplate } from "../render/parts.js";
|
|
13
|
+
import { parseJson } from "../shared/json.js";
|
|
13
14
|
import { applyTokens, type TokenMap } from "./placeholders.js";
|
|
14
15
|
import { sha256 } from "./version-file.js";
|
|
15
16
|
|
|
@@ -196,6 +197,55 @@ export function deepMergeJson(base: JsonValue, override: JsonValue): JsonValue {
|
|
|
196
197
|
return result;
|
|
197
198
|
}
|
|
198
199
|
|
|
200
|
+
// ---------------------------------------------------------------------------
|
|
201
|
+
// MCP tracker entry — bkit owns the template's parts of the entry, not the whole entry (#613)
|
|
202
|
+
//
|
|
203
|
+
// - every key the template sets is reset to the template's value
|
|
204
|
+
// - `headers["X-MCP-Toolsets"]` keeps the consumer's list and appends any template toolset
|
|
205
|
+
// it lacks, so a consumer can enable extra toolsets and a toolset bkit adds still lands
|
|
206
|
+
// - every other consumer key, header and toolset is kept
|
|
207
|
+
// ---------------------------------------------------------------------------
|
|
208
|
+
|
|
209
|
+
export const MCP_TOOLSETS_HEADER = "X-MCP-Toolsets";
|
|
210
|
+
|
|
211
|
+
/** Split an `X-MCP-Toolsets` value into toolset names (trimmed, empties dropped). */
|
|
212
|
+
export function parseToolsets(value: string): string[] {
|
|
213
|
+
return value
|
|
214
|
+
.split(",")
|
|
215
|
+
.map((s) => s.trim())
|
|
216
|
+
.filter((s) => s !== "");
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** True for a JSON object (not null, not an array). */
|
|
220
|
+
export function isJsonObject(v: JsonValue | undefined): v is { [k: string]: JsonValue } {
|
|
221
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** Merge bkit's tracker entry `owned` into the consumer's `existing` entry (rules above). */
|
|
225
|
+
export function mergeTrackerEntry(existing: JsonValue | undefined, owned: JsonValue): JsonValue {
|
|
226
|
+
if (!isJsonObject(existing) || !isJsonObject(owned)) return owned;
|
|
227
|
+
const merged = deepMergeJson(existing, owned) as { [k: string]: JsonValue };
|
|
228
|
+
const ownedHeaders = owned.headers;
|
|
229
|
+
const existingHeaders = existing.headers;
|
|
230
|
+
if (isJsonObject(ownedHeaders) && isJsonObject(existingHeaders)) {
|
|
231
|
+
const ownedSets = ownedHeaders[MCP_TOOLSETS_HEADER];
|
|
232
|
+
const existingSets = existingHeaders[MCP_TOOLSETS_HEADER];
|
|
233
|
+
if (typeof ownedSets === "string" && typeof existingSets === "string") {
|
|
234
|
+
const have = parseToolsets(existingSets);
|
|
235
|
+
const missing = parseToolsets(ownedSets).filter((t) => !have.includes(t));
|
|
236
|
+
(merged.headers as { [k: string]: JsonValue })[MCP_TOOLSETS_HEADER] =
|
|
237
|
+
missing.length === 0 ? existingSets : [...have, ...missing].join(",");
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return merged;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** True when `existing` already holds everything `mergeTrackerEntry` would write. */
|
|
244
|
+
export function trackerEntryInSync(existing: JsonValue | undefined, owned: JsonValue): boolean {
|
|
245
|
+
if (existing === undefined) return false;
|
|
246
|
+
return deepContains(mergeTrackerEntry(existing, owned), existing).ok;
|
|
247
|
+
}
|
|
248
|
+
|
|
199
249
|
// ---------------------------------------------------------------------------
|
|
200
250
|
// writeTier2JsonContained — deep-containment JSON helper (BAR-167 Phase 1)
|
|
201
251
|
//
|
|
@@ -215,12 +265,11 @@ export function writeTier2JsonContained(
|
|
|
215
265
|
ws: WriteSet,
|
|
216
266
|
): void {
|
|
217
267
|
const srcRaw = fs.readFileSync(srcPath, "utf-8");
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
template = JSON.parse(srcRaw) as Record<string, JsonValue>;
|
|
221
|
-
} catch {
|
|
268
|
+
const templateRead = parseJson(srcRaw);
|
|
269
|
+
if (!templateRead.ok) {
|
|
222
270
|
throw new Error(`writeTier2JsonContained: template at ${srcPath} is not valid JSON`);
|
|
223
271
|
}
|
|
272
|
+
const template = templateRead.value as Record<string, JsonValue>;
|
|
224
273
|
|
|
225
274
|
if (!fs.existsSync(dstPath)) {
|
|
226
275
|
// First install — write template as-is
|
|
@@ -236,15 +285,14 @@ export function writeTier2JsonContained(
|
|
|
236
285
|
|
|
237
286
|
// dest exists — read and check containment
|
|
238
287
|
const dstRaw = fs.readFileSync(dstPath, "utf-8");
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
existing = JSON.parse(dstRaw) as Record<string, JsonValue>;
|
|
242
|
-
} catch {
|
|
288
|
+
const existingRead = parseJson(dstRaw);
|
|
289
|
+
if (!existingRead.ok) {
|
|
243
290
|
// Malformed destination — refuse to overwrite; require manual fix (matches malformed-package-json blocker discipline)
|
|
244
291
|
throw new Error(
|
|
245
292
|
`[bkit] ${dstPath} is malformed JSON — fix manually before running bkit install`,
|
|
246
293
|
);
|
|
247
294
|
}
|
|
295
|
+
const existing = existingRead.value as Record<string, JsonValue>;
|
|
248
296
|
|
|
249
297
|
// Check if existing already contains the template
|
|
250
298
|
const containsResult = deepContains(template as JsonValue, existing as JsonValue);
|
|
@@ -485,12 +533,11 @@ export function ensurePackageJsonScripts(
|
|
|
485
533
|
return { added: [], preserved: [], missingPkg: true, malformed: false };
|
|
486
534
|
}
|
|
487
535
|
const raw = fs.readFileSync(pkgPath, "utf-8");
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
pkg = JSON.parse(raw) as Record<string, unknown>;
|
|
491
|
-
} catch {
|
|
536
|
+
const parsed = parseJson(raw);
|
|
537
|
+
if (!parsed.ok) {
|
|
492
538
|
return { added: [], preserved: [], missingPkg: false, malformed: true };
|
|
493
539
|
}
|
|
540
|
+
const pkg = parsed.value as Record<string, unknown>;
|
|
494
541
|
|
|
495
542
|
let pkgScripts = (pkg.scripts as Record<string, string> | undefined) ?? undefined;
|
|
496
543
|
const added: string[] = [];
|
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
import { spawnSync } from "node:child_process";
|
|
21
21
|
import * as fs from "node:fs";
|
|
22
22
|
|
|
23
|
+
import { parseJson } from "../shared/json.js";
|
|
24
|
+
|
|
23
25
|
// ---------------------------------------------------------------------------
|
|
24
26
|
// Constants
|
|
25
27
|
// ---------------------------------------------------------------------------
|
|
@@ -814,10 +816,10 @@ export function parse(raw: string): ParseResult {
|
|
|
814
816
|
for (const line of lines) {
|
|
815
817
|
const trimmed = line.trim();
|
|
816
818
|
if (trimmed === "") continue;
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
result.events.push(obj as TelemetryEvent);
|
|
820
|
-
}
|
|
819
|
+
const obj = parseJson(trimmed);
|
|
820
|
+
if (obj.ok) {
|
|
821
|
+
result.events.push(obj.value as TelemetryEvent);
|
|
822
|
+
} else {
|
|
821
823
|
result.malformedLineCount++;
|
|
822
824
|
}
|
|
823
825
|
}
|
|
@@ -105,24 +105,9 @@ export function applyOpencodeAgent(
|
|
|
105
105
|
effortMap?: EffortMap,
|
|
106
106
|
provider?: string,
|
|
107
107
|
): string {
|
|
108
|
-
const
|
|
109
|
-
if (!
|
|
110
|
-
|
|
111
|
-
const fmBlock = fmMatch[2];
|
|
112
|
-
const afterFm = content.slice(fmMatch[0].length);
|
|
113
|
-
const parsed = parseFrontmatter(fmBlock);
|
|
114
|
-
|
|
115
|
-
const name = parsed.get("name") ?? "";
|
|
116
|
-
if (!name) {
|
|
117
|
-
console.error(`${LOG_PREFIX} Subagent frontmatter missing 'name' field`);
|
|
118
|
-
process.exit(1);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const opencodeModel = opencodeModelLookup.get(name);
|
|
122
|
-
if (!opencodeModel) {
|
|
123
|
-
console.error(`${LOG_PREFIX} Missing opencode model lookup for ${name}`);
|
|
124
|
-
process.exit(1);
|
|
125
|
-
}
|
|
108
|
+
const subagent = requireSubagentModel(content, opencodeModelLookup, "opencode");
|
|
109
|
+
if (!subagent) return content;
|
|
110
|
+
const { fmBlock, afterFm, parsed, name, model: opencodeModel } = subagent;
|
|
126
111
|
|
|
127
112
|
const description = parsed.get("description") ?? "";
|
|
128
113
|
const effort = parsed.get("effort");
|
|
@@ -212,24 +197,10 @@ export function applyCodexAgent(
|
|
|
212
197
|
codexModelLookup: Map<string, string>,
|
|
213
198
|
effortMap?: EffortMap,
|
|
214
199
|
): string {
|
|
215
|
-
const
|
|
216
|
-
if (!
|
|
217
|
-
|
|
218
|
-
const
|
|
219
|
-
const body = content.slice(fmMatch[0].length).trim();
|
|
220
|
-
const parsed = parseFrontmatter(fmBlock);
|
|
221
|
-
|
|
222
|
-
const name = parsed.get("name") ?? "";
|
|
223
|
-
if (!name) {
|
|
224
|
-
console.error(`${LOG_PREFIX} Subagent frontmatter missing 'name' field`);
|
|
225
|
-
process.exit(1);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const model = codexModelLookup.get(name);
|
|
229
|
-
if (!model) {
|
|
230
|
-
console.error(`${LOG_PREFIX} Missing codex model lookup for ${name}`);
|
|
231
|
-
process.exit(1);
|
|
232
|
-
}
|
|
200
|
+
const subagent = requireSubagentModel(content, codexModelLookup, "codex");
|
|
201
|
+
if (!subagent) return content;
|
|
202
|
+
const { afterFm, parsed, name, model } = subagent;
|
|
203
|
+
const body = afterFm.trim();
|
|
233
204
|
|
|
234
205
|
const effort = parsed.get("effort");
|
|
235
206
|
let out = "";
|
|
@@ -371,20 +342,28 @@ function extractFrontmatterField(fmBlock: string, field: string): string | null
|
|
|
371
342
|
return m ? m[1] : null;
|
|
372
343
|
}
|
|
373
344
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
345
|
+
interface SubagentModel {
|
|
346
|
+
fmBlock: string;
|
|
347
|
+
/** Everything after the closing `---`. */
|
|
348
|
+
afterFm: string;
|
|
349
|
+
parsed: Map<string, string>;
|
|
350
|
+
name: string;
|
|
351
|
+
model: string;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// Shared opening of the subagent renderers: split off the frontmatter, require `name`, look
|
|
355
|
+
// the model up. Returns null when `content` has no frontmatter (the renderer passes it
|
|
356
|
+
// through); exits 1 when `name` or the model is missing. `host` qualifies the model-lookup
|
|
357
|
+
// message ("" for the unqualified Cursor message).
|
|
358
|
+
function requireSubagentModel(
|
|
379
359
|
content: string,
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
):
|
|
360
|
+
lookup: Map<string, string>,
|
|
361
|
+
host: "opencode" | "codex" | "antigravity" | "",
|
|
362
|
+
): SubagentModel | null {
|
|
383
363
|
const fmMatch = content.match(/^(---\r?\n)([\s\S]*?)(\r?\n---\r?\n?)/);
|
|
384
|
-
if (!fmMatch) return
|
|
364
|
+
if (!fmMatch) return null;
|
|
385
365
|
|
|
386
366
|
const fmBlock = fmMatch[2];
|
|
387
|
-
const afterFm = content.slice(fmMatch[0].length);
|
|
388
367
|
const parsed = parseFrontmatter(fmBlock);
|
|
389
368
|
|
|
390
369
|
const name = parsed.get("name") ?? "";
|
|
@@ -393,12 +372,28 @@ export function applyT3(
|
|
|
393
372
|
process.exit(1);
|
|
394
373
|
}
|
|
395
374
|
|
|
396
|
-
const
|
|
397
|
-
if (!
|
|
398
|
-
console.error(`${LOG_PREFIX} Missing model lookup for ${name}`);
|
|
375
|
+
const model = lookup.get(name);
|
|
376
|
+
if (!model) {
|
|
377
|
+
console.error(`${LOG_PREFIX} Missing ${host ? `${host} ` : ""}model lookup for ${name}`);
|
|
399
378
|
process.exit(1);
|
|
400
379
|
}
|
|
401
380
|
|
|
381
|
+
return { fmBlock, afterFm: content.slice(fmMatch[0].length), parsed, name, model };
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// T3: Cursor subagent frontmatter rewrite.
|
|
385
|
+
// Emits: name, description, model, tools (passthrough — Cursor 2.4+ accepts identical tool names per BAR-113),
|
|
386
|
+
// effort (from prompts.md Cursor column). Drops: permissionMode, maxTurns, readonly, is_background.
|
|
387
|
+
// Hard-fails with non-zero exit if model lookup missing for name.
|
|
388
|
+
export function applyT3(
|
|
389
|
+
content: string,
|
|
390
|
+
modelLookup: Map<string, string>,
|
|
391
|
+
effortMap?: EffortMap,
|
|
392
|
+
): string {
|
|
393
|
+
const subagent = requireSubagentModel(content, modelLookup, "");
|
|
394
|
+
if (!subagent) return content;
|
|
395
|
+
const { fmBlock, afterFm, parsed, name, model: cursorModel } = subagent;
|
|
396
|
+
|
|
402
397
|
const description = parsed.get("description") ?? "";
|
|
403
398
|
const effort = parsed.get("effort");
|
|
404
399
|
const toolsBlock = extractFrontmatterField(fmBlock, "tools");
|
|
@@ -477,24 +472,9 @@ export function applyAntigravityPrompt(
|
|
|
477
472
|
modelLookup: Map<string, string>,
|
|
478
473
|
effortMap?: EffortMap,
|
|
479
474
|
): string {
|
|
480
|
-
const
|
|
481
|
-
if (!
|
|
482
|
-
|
|
483
|
-
const fmBlock = fmMatch[2];
|
|
484
|
-
const afterFm = content.slice(fmMatch[0].length);
|
|
485
|
-
const parsed = parseFrontmatter(fmBlock);
|
|
486
|
-
|
|
487
|
-
const name = parsed.get("name") ?? "";
|
|
488
|
-
if (!name) {
|
|
489
|
-
console.error(`${LOG_PREFIX} Subagent frontmatter missing 'name' field`);
|
|
490
|
-
process.exit(1);
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
const model = modelLookup.get(name);
|
|
494
|
-
if (!model) {
|
|
495
|
-
console.error(`${LOG_PREFIX} Missing antigravity model lookup for ${name}`);
|
|
496
|
-
process.exit(1);
|
|
497
|
-
}
|
|
475
|
+
const subagent = requireSubagentModel(content, modelLookup, "antigravity");
|
|
476
|
+
if (!subagent) return content;
|
|
477
|
+
const { fmBlock, afterFm, parsed, name, model } = subagent;
|
|
498
478
|
|
|
499
479
|
const description = parsed.get("description") ?? "";
|
|
500
480
|
const effort = parsed.get("effort");
|