@cbartens/bkit 5.2.3 → 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 +29 -12
- 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 +28 -11
- package/.bkit/core/.bkit/cloud.md +9 -8
- package/.bkit/core/.bkit/comparison.md +68 -345
- package/.bkit/core/.bkit/install.md +15 -9
- 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 +125 -18
- package/.bkit/core/.bkit/trackers.md +47 -1
- package/.bkit/core/.bkit/workflows.md +51 -45
- package/.bkit/core/.claude/hooks/bkit-guardrails.cjs +1 -1
- package/.bkit/core/.codex/hooks/bkit-guardrails.cjs +7 -4
- package/.bkit/core/.cursor/hooks/bkit-guardrails.cjs +8 -5
- package/.bkit/core/docs/templates/bkit-audit-accessibility.md +9 -1
- package/.bkit/core/docs/templates/bkit-audit-adoption.md +10 -2
- package/.bkit/core/docs/templates/bkit-audit-agents.md +9 -1
- package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +9 -1
- package/.bkit/core/docs/templates/bkit-audit-analytics.md +9 -1
- package/.bkit/core/docs/templates/bkit-audit-annotations.md +10 -2
- package/.bkit/core/docs/templates/bkit-audit-app-performance.md +9 -1
- package/.bkit/core/docs/templates/bkit-audit-app-store.md +9 -1
- package/.bkit/core/docs/templates/bkit-audit-architecture.md +9 -1
- package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +9 -1
- package/.bkit/core/docs/templates/bkit-audit-config.md +9 -1
- package/.bkit/core/docs/templates/bkit-audit-cost.md +10 -2
- package/.bkit/core/docs/templates/bkit-audit-coverage.md +9 -1
- package/.bkit/core/docs/templates/bkit-audit-database.md +9 -1
- package/.bkit/core/docs/templates/bkit-audit-dead-code.md +9 -1
- package/.bkit/core/docs/templates/bkit-audit-deferrals.md +9 -1
- package/.bkit/core/docs/templates/bkit-audit-dependencies.md +22 -10
- package/.bkit/core/docs/templates/bkit-audit-documentation.md +9 -1
- package/.bkit/core/docs/templates/bkit-audit-duplication.md +9 -1
- package/.bkit/core/docs/templates/bkit-audit-failures.md +9 -1
- package/.bkit/core/docs/templates/bkit-audit-flakes.md +10 -2
- package/.bkit/core/docs/templates/bkit-audit-gates.md +9 -1
- package/.bkit/core/docs/templates/bkit-audit-issues.md +9 -1
- package/.bkit/core/docs/templates/bkit-audit-llm.md +29 -15
- package/.bkit/core/docs/templates/bkit-audit-logs.md +10 -2
- package/.bkit/core/docs/templates/bkit-audit-models.md +9 -1
- package/.bkit/core/docs/templates/bkit-audit-privacy.md +9 -1
- package/.bkit/core/docs/templates/bkit-audit-prompts.md +11 -3
- package/.bkit/core/docs/templates/bkit-audit-red-team.md +19 -9
- package/.bkit/core/docs/templates/bkit-audit-reliability.md +9 -1
- package/.bkit/core/docs/templates/bkit-audit-repo.md +10 -2
- package/.bkit/core/docs/templates/bkit-audit-security.md +13 -5
- package/.bkit/core/docs/templates/bkit-audit-slop.md +9 -1
- package/.bkit/core/docs/templates/bkit-audit-testing.md +14 -5
- package/.bkit/core/docs/templates/bkit-audit-usability.md +9 -1
- package/.bkit/core/docs/templates/bkit-plan.md +8 -6
- package/.bkit/core/engine/checks/after/auth.ts +9 -9
- package/.bkit/core/engine/checks/after/ci-yml.ts +14 -12
- package/.bkit/core/engine/checks/after/github.ts +29 -120
- package/.bkit/core/engine/checks/after/index.ts +2 -2
- package/.bkit/core/engine/checks/after/managed.ts +8 -28
- package/.bkit/core/engine/checks/after/tools.ts +3 -15
- package/.bkit/core/engine/checks/before/context-fetch.ts +1 -21
- package/.bkit/core/engine/checks/before/index.ts +7 -43
- package/.bkit/core/engine/checks/before/mcp.ts +17 -8
- package/.bkit/core/engine/checks/before/repo.ts +9 -12
- package/.bkit/core/engine/checks/status-holes.ts +4 -5
- package/.bkit/core/engine/checks/tips/catalogue.ts +70 -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 +58 -53
- 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 +65 -11
- 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 +18 -4
- 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 +19 -17
- 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/bkit-latest.ts +164 -0
- 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/engine/shared/timeouts.ts +6 -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 +65 -10
- 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 +4 -4
- package/.bkit/core/workflows/bkit-debug.md +70 -34
- package/.bkit/core/workflows/bkit-design.md +3 -3
- package/.bkit/core/workflows/bkit-plan.md +12 -5
- package/.bkit/core/workflows/bkit-ship.md +6 -6
- 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 +15 -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/cleanup/bkit-tmp-prune.mjs +115 -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 +67 -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 +60 -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 +55 -49
- package/dist/commands/lib.js +32 -10
- package/dist/commands/tips.js +6 -3
- package/dist/commands/workflow/branches.js +57 -13
- 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 +16 -4
- 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 +19 -18
- 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/bkit-latest.js +150 -0
- 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/dist/shared/timeouts.js +6 -0
- package/package.json +21 -17
- package/.bkit/core/.agents/shortcuts.md +0 -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");
|
|
@@ -4,7 +4,11 @@
|
|
|
4
4
|
import * as fs from "node:fs";
|
|
5
5
|
import { findLineAnchoredMarkers, selectMarkers } from "../install/managed-block.js";
|
|
6
6
|
import { LOG_PREFIX } from "../shared/log-prefix.js";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
OPENCODE_PROVIDERS,
|
|
9
|
+
OPENCODE_PROVIDER_DEFAULTS,
|
|
10
|
+
type OpencodeProvider,
|
|
11
|
+
} from "../shared/egress.js";
|
|
8
12
|
|
|
9
13
|
/**
|
|
10
14
|
* Parse .bkit/prompts.md § Models table → Map<name, columnValue>.
|
|
@@ -97,8 +101,11 @@ export function parseModelLookup(subagentsMdPath: string): Map<string, string> {
|
|
|
97
101
|
*
|
|
98
102
|
* Cells hold the BARE, gateway-scoped model id. Any prefix a program's config format needs
|
|
99
103
|
* is added at render time by formatModelPin — never stored in the table.
|
|
104
|
+
*
|
|
105
|
+
* Every allowlisted opencode provider MUST have an entry; the `satisfies Record<OpencodeProvider | …>`
|
|
106
|
+
* check fails tsc when one is missing.
|
|
100
107
|
*/
|
|
101
|
-
const GATEWAY_COLUMN
|
|
108
|
+
const GATEWAY_COLUMN = {
|
|
102
109
|
anthropic: "Anthropic",
|
|
103
110
|
cursor: "Cursor",
|
|
104
111
|
openrouter: "OpenRouter",
|
|
@@ -107,7 +114,13 @@ const GATEWAY_COLUMN: Record<string, string> = {
|
|
|
107
114
|
"opencode-go": "OpenCode Go",
|
|
108
115
|
openai: "OpenAI",
|
|
109
116
|
google: "Google",
|
|
110
|
-
}
|
|
117
|
+
} satisfies Record<OpencodeProvider | "anthropic" | "cursor" | "openai" | "google", string>;
|
|
118
|
+
|
|
119
|
+
type GatewayKey = keyof typeof GATEWAY_COLUMN;
|
|
120
|
+
|
|
121
|
+
function isGatewayKey(value: string): value is GatewayKey {
|
|
122
|
+
return Object.hasOwn(GATEWAY_COLUMN, value);
|
|
123
|
+
}
|
|
111
124
|
|
|
112
125
|
/**
|
|
113
126
|
* Spell a model pin the way a program's config file expects it.
|
|
@@ -125,22 +138,21 @@ export function formatModelPin(program: string, gateway: string, bareModel: stri
|
|
|
125
138
|
}
|
|
126
139
|
|
|
127
140
|
/**
|
|
128
|
-
* Build the per-agent
|
|
129
|
-
* Source of truth = prompts.md § Models, which carries one curated column per
|
|
130
|
-
*
|
|
131
|
-
* ships a column;
|
|
141
|
+
* Build the per-agent model lookup for one gateway: an opencode provider, or the Codex
|
|
142
|
+
* "openai" column. Source of truth = prompts.md § Models, which carries one curated column per
|
|
143
|
+
* gateway ("OpenRouter", "Ollama", "OpenAI"). Header-addressed. Every key of GATEWAY_COLUMN
|
|
144
|
+
* ships a column; any other key throws.
|
|
132
145
|
*/
|
|
133
146
|
export function buildOpencodeModelLookup(
|
|
134
147
|
subagentsMdPath: string,
|
|
135
148
|
provider: string,
|
|
136
149
|
): Map<string, string> {
|
|
137
|
-
|
|
138
|
-
if (!header) {
|
|
150
|
+
if (!isGatewayKey(provider)) {
|
|
139
151
|
throw new Error(
|
|
140
152
|
`buildOpencodeModelLookup: no prompts.md § Models column for provider ${JSON.stringify(provider)}`,
|
|
141
153
|
);
|
|
142
154
|
}
|
|
143
|
-
return parseModelLookupForColumn(subagentsMdPath,
|
|
155
|
+
return parseModelLookupForColumn(subagentsMdPath, GATEWAY_COLUMN[provider]);
|
|
144
156
|
}
|
|
145
157
|
|
|
146
158
|
/**
|
|
@@ -329,5 +341,11 @@ export function lookupEffort(effortMap: EffortMap, program: string, sourceEffort
|
|
|
329
341
|
* keys pass through unchanged.
|
|
330
342
|
*/
|
|
331
343
|
export function opencodeProviderId(providerKey: string): string {
|
|
332
|
-
|
|
344
|
+
if (!isOpencodeProvider(providerKey)) return providerKey;
|
|
345
|
+
return OPENCODE_PROVIDER_DEFAULTS[providerKey].providerId ?? providerKey;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/** Narrow a raw string to the opencode provider allowlist. */
|
|
349
|
+
export function isOpencodeProvider(value: string): value is OpencodeProvider {
|
|
350
|
+
return OPENCODE_PROVIDERS.some((provider) => provider === value);
|
|
333
351
|
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// bkit-latest — is the bkit this repo rendered its workflows and audit templates
|
|
2
|
+
// from behind the newest published release?
|
|
3
|
+
//
|
|
4
|
+
// `bkit repo info` (every phase workflow's Step 1) and the anchor stamp on every
|
|
5
|
+
// audit report, design and plan report it, so a run on outdated workflow /
|
|
6
|
+
// template text says so. Advisory only: no registry answer means `latest`
|
|
7
|
+
// is null and nothing is printed, never an error. The registry answer is kept in
|
|
8
|
+
// the git common dir (shared by every worktree, never committed) so parallel runs
|
|
9
|
+
// ask npm at most once a day.
|
|
10
|
+
|
|
11
|
+
import { spawnSync } from "node:child_process";
|
|
12
|
+
import * as fs from "node:fs";
|
|
13
|
+
import * as path from "node:path";
|
|
14
|
+
|
|
15
|
+
import { readBkitVersion } from "../install/version-file.js";
|
|
16
|
+
import { parseJson } from "./json.js";
|
|
17
|
+
import { PACKAGE_RUNNER } from "./package-manager.js";
|
|
18
|
+
import { TIMEOUTS } from "./timeouts.js";
|
|
19
|
+
|
|
20
|
+
export const BKIT_PACKAGE = "@cbartens/bkit";
|
|
21
|
+
/** Cache file name inside the git common dir. */
|
|
22
|
+
export const BKIT_LATEST_CACHE = "bkit-latest-version.json";
|
|
23
|
+
/** Set to anything but `0` / empty to skip the registry lookup (air-gapped machines, CI). */
|
|
24
|
+
export const NO_UPDATE_CHECK_ENV = "BKIT_NO_UPDATE_CHECK";
|
|
25
|
+
|
|
26
|
+
const SEMVER_RE = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/;
|
|
27
|
+
|
|
28
|
+
/** Order of two prerelease identifier lists per semver §11: numeric < alphanumeric, shorter < longer. */
|
|
29
|
+
function comparePrerelease(a: string[], b: string[]): number {
|
|
30
|
+
for (let i = 0; i < Math.max(a.length, b.length); i++) {
|
|
31
|
+
const x = a[i];
|
|
32
|
+
const y = b[i];
|
|
33
|
+
if (x === undefined) return -1;
|
|
34
|
+
if (y === undefined) return 1;
|
|
35
|
+
const xn = /^\d+$/.test(x);
|
|
36
|
+
const yn = /^\d+$/.test(y);
|
|
37
|
+
if (xn && yn) {
|
|
38
|
+
if (Number(x) !== Number(y)) return Number(x) < Number(y) ? -1 : 1;
|
|
39
|
+
} else if (xn !== yn) {
|
|
40
|
+
return xn ? -1 : 1;
|
|
41
|
+
} else if (x !== y) {
|
|
42
|
+
return x < y ? -1 : 1;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* -1 / 0 / 1 for `a` older / equal / newer than `b`, compared as numbers (so 5.10.0
|
|
50
|
+
* is newer than 5.9.0) and with a prerelease older than its release. null when
|
|
51
|
+
* either is not a semver.
|
|
52
|
+
*/
|
|
53
|
+
export function compareSemver(a: string, b: string): -1 | 0 | 1 | null {
|
|
54
|
+
const ma = SEMVER_RE.exec(a.trim());
|
|
55
|
+
const mb = SEMVER_RE.exec(b.trim());
|
|
56
|
+
if (!ma || !mb) return null;
|
|
57
|
+
for (let i = 1; i <= 3; i++) {
|
|
58
|
+
const x = Number(ma[i]);
|
|
59
|
+
const y = Number(mb[i]);
|
|
60
|
+
if (x !== y) return x < y ? -1 : 1;
|
|
61
|
+
}
|
|
62
|
+
const pa = ma[4];
|
|
63
|
+
const pb = mb[4];
|
|
64
|
+
if (pa === undefined && pb === undefined) return 0;
|
|
65
|
+
if (pa === undefined) return 1;
|
|
66
|
+
if (pb === undefined) return -1;
|
|
67
|
+
const c = comparePrerelease(pa.split("."), pb.split("."));
|
|
68
|
+
return c === 0 ? 0 : c < 0 ? -1 : 1;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The newest published bkit per the registry, or null on any failure (offline, timeout, no pnpm). */
|
|
72
|
+
export function lookupLatestPublished(
|
|
73
|
+
cwd: string,
|
|
74
|
+
timeoutS: number | null = TIMEOUTS.BKIT_LATEST_LOOKUP_TIMEOUT_S,
|
|
75
|
+
): string | null {
|
|
76
|
+
const res = spawnSync(PACKAGE_RUNNER, ["view", BKIT_PACKAGE, "version"], {
|
|
77
|
+
cwd,
|
|
78
|
+
encoding: "utf-8",
|
|
79
|
+
...(timeoutS === null ? {} : { timeout: timeoutS * 1000 }),
|
|
80
|
+
});
|
|
81
|
+
if (res.error || res.status !== 0) return null;
|
|
82
|
+
const version = (res.stdout ?? "").trim().replace(/^v/, "");
|
|
83
|
+
return SEMVER_RE.test(version) ? version : null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface BkitVersionStatus {
|
|
87
|
+
/** `.bkit/version` `pinnedVersion`: the release this repo's bkit files were rendered from. */
|
|
88
|
+
version: string | null;
|
|
89
|
+
/** Newest published release, or null when unknown (offline, opted out, no pin to compare). */
|
|
90
|
+
latest: string | null;
|
|
91
|
+
/** true when `version` is older than `latest`; null when either is unknown. */
|
|
92
|
+
outdated: boolean | null;
|
|
93
|
+
/** One line to show the user when outdated, else null. */
|
|
94
|
+
advisory: string | null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface BkitLatestDeps {
|
|
98
|
+
now?: () => number;
|
|
99
|
+
lookup?: (cwd: string) => string | null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** The cached registry answer when still fresh: a version, or null for a remembered failure. */
|
|
103
|
+
function readCache(file: string, now: number): { latest: string | null } | undefined {
|
|
104
|
+
if (!fs.existsSync(file)) return undefined;
|
|
105
|
+
const parsed = parseJson(fs.readFileSync(file, "utf-8"));
|
|
106
|
+
if (!parsed.ok || typeof parsed.value !== "object" || parsed.value === null) return undefined;
|
|
107
|
+
const { latest, checkedAt } = parsed.value as { latest?: unknown; checkedAt?: unknown };
|
|
108
|
+
if (typeof checkedAt !== "number") return undefined;
|
|
109
|
+
const value = typeof latest === "string" && SEMVER_RE.test(latest) ? latest : null;
|
|
110
|
+
const ttl = value === null ? TIMEOUTS.BKIT_LATEST_RETRY_S : TIMEOUTS.BKIT_LATEST_CACHE_S;
|
|
111
|
+
return now - checkedAt < ttl * 1000 && now >= checkedAt ? { latest: value } : undefined;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Remember the registry answer; a cache that cannot be written only costs a lookup next run. */
|
|
115
|
+
function writeCache(file: string, latest: string | null, now: number): void {
|
|
116
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
117
|
+
try {
|
|
118
|
+
fs.writeFileSync(tmp, `${JSON.stringify({ latest, checkedAt: now })}\n`);
|
|
119
|
+
fs.renameSync(tmp, file);
|
|
120
|
+
} catch {
|
|
121
|
+
// Read-only git dir: the next run asks the registry again, nothing else changes.
|
|
122
|
+
fs.rmSync(tmp, { force: true });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Whether this repo's bkit is behind the newest release. `gitCommonDir` holds the
|
|
128
|
+
* once-a-day cache; null (not a git repo) skips the cache, not the check.
|
|
129
|
+
*/
|
|
130
|
+
export function bkitVersionStatus(
|
|
131
|
+
root: string,
|
|
132
|
+
gitCommonDir: string | null,
|
|
133
|
+
deps: BkitLatestDeps = {},
|
|
134
|
+
): BkitVersionStatus {
|
|
135
|
+
const version = readBkitVersion(path.join(root, ".bkit", "version"))?.pinnedVersion || null;
|
|
136
|
+
const unknown = { version, latest: null, outdated: null, advisory: null };
|
|
137
|
+
if (version === null) return unknown;
|
|
138
|
+
const optOut = process.env[NO_UPDATE_CHECK_ENV];
|
|
139
|
+
if (optOut !== undefined && optOut !== "" && optOut !== "0") return unknown;
|
|
140
|
+
|
|
141
|
+
const now = (deps.now ?? Date.now)();
|
|
142
|
+
const cacheFile = gitCommonDir === null ? null : path.join(gitCommonDir, BKIT_LATEST_CACHE);
|
|
143
|
+
let latest: string | null;
|
|
144
|
+
const cached = cacheFile === null ? undefined : readCache(cacheFile, now);
|
|
145
|
+
if (cached !== undefined) {
|
|
146
|
+
latest = cached.latest;
|
|
147
|
+
} else {
|
|
148
|
+
latest = (deps.lookup ?? lookupLatestPublished)(root);
|
|
149
|
+
if (cacheFile !== null) writeCache(cacheFile, latest, now);
|
|
150
|
+
}
|
|
151
|
+
if (latest === null) return unknown;
|
|
152
|
+
|
|
153
|
+
const order = compareSemver(version, latest);
|
|
154
|
+
if (order === null) return { version, latest, outdated: null, advisory: null };
|
|
155
|
+
const outdated = order < 0;
|
|
156
|
+
return {
|
|
157
|
+
version,
|
|
158
|
+
latest,
|
|
159
|
+
outdated,
|
|
160
|
+
advisory: outdated
|
|
161
|
+
? `running bkit ${version}; ${latest} is out. Upgrade: ${PACKAGE_RUNNER} bkit upgrade --latest`
|
|
162
|
+
: null,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// shared/branches.ts — which branches are shared, so nobody works on them directly.
|
|
2
|
+
//
|
|
3
|
+
// `dev` is the integration branch; `dev` and `main` are the shared branches. The workflow
|
|
4
|
+
// commands (`commands/lib.ts` re-exports these) and the managed-version check both read
|
|
5
|
+
// this one rule.
|
|
6
|
+
|
|
7
|
+
/** The integration branch feature work lands on. */
|
|
8
|
+
export const DEV = "dev";
|
|
9
|
+
|
|
10
|
+
/** True for `dev` and `main`: no feature work happens on them, no force-push touches them. */
|
|
11
|
+
export function isSharedBranch(branch: string): boolean {
|
|
12
|
+
return branch === DEV || branch === "main";
|
|
13
|
+
}
|
|
@@ -4,8 +4,6 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* Providers bkit supports for the opencode host. `--opencode=<provider>` accepts
|
|
6
6
|
* ONLY these — anything else is rejected (no generic/arbitrary-endpoint fallback).
|
|
7
|
-
* Keep in sync with OPENCODE_PROVIDER_DEFAULTS (below) and
|
|
8
|
-
* GATEWAY_COLUMN (render/models.ts § Models lookup).
|
|
9
7
|
*/
|
|
10
8
|
export const OPENCODE_PROVIDERS = [
|
|
11
9
|
// OpenAI-compatible npm driver — endpoint + key per provider.
|
|
@@ -18,6 +16,8 @@ export const OPENCODE_PROVIDERS = [
|
|
|
18
16
|
"opencode-go",
|
|
19
17
|
] as const;
|
|
20
18
|
|
|
19
|
+
export type OpencodeProvider = (typeof OPENCODE_PROVIDERS)[number];
|
|
20
|
+
|
|
21
21
|
/**
|
|
22
22
|
* One egress source: a bkit-shipped surface that an agent session reaches over the
|
|
23
23
|
* network. `hosts` are the exact hostnames contacted. `bases` are the registrable
|
|
@@ -47,7 +47,7 @@ export interface EgressSource {
|
|
|
47
47
|
// These are sane defaults; consumers tune after install.
|
|
48
48
|
// npmPackage: set for custom OpenAI-compatible providers that use npm-based AI SDK driver.
|
|
49
49
|
export const OPENCODE_PROVIDER_DEFAULTS: Record<
|
|
50
|
-
|
|
50
|
+
OpencodeProvider,
|
|
51
51
|
{
|
|
52
52
|
envVar: string;
|
|
53
53
|
baseURL: string;
|
|
@@ -4,9 +4,14 @@
|
|
|
4
4
|
// .bkit/version) must fail open into a result the caller reports in its own terms,
|
|
5
5
|
// never abort install, upgrade or `bkit check`. One shape, one catch — so the
|
|
6
6
|
// defensive-slop gate reads a single documented fallback instead of one per caller.
|
|
7
|
+
// `audits/repo/json-parse-owner.test.ts` fails on a `JSON.parse` inside a `try` anywhere else.
|
|
8
|
+
|
|
9
|
+
import * as fs from "node:fs";
|
|
10
|
+
|
|
11
|
+
export type JsonRead = { ok: true; value: unknown } | { ok: false };
|
|
7
12
|
|
|
8
13
|
/** `JSON.parse(raw)` as a result: `{ ok: true, value }`, or `{ ok: false }` when not JSON. */
|
|
9
|
-
export function parseJson(raw: string):
|
|
14
|
+
export function parseJson(raw: string): JsonRead {
|
|
10
15
|
try {
|
|
11
16
|
return { ok: true, value: JSON.parse(raw) as unknown };
|
|
12
17
|
} catch {
|
|
@@ -14,3 +19,15 @@ export function parseJson(raw: string): { ok: true; value: unknown } | { ok: fal
|
|
|
14
19
|
return { ok: false };
|
|
15
20
|
}
|
|
16
21
|
}
|
|
22
|
+
|
|
23
|
+
/** `parseJson` over the file at `file`; `{ ok: false }` also when the file cannot be read. */
|
|
24
|
+
export function readJsonFile(file: string): JsonRead {
|
|
25
|
+
let raw: string;
|
|
26
|
+
try {
|
|
27
|
+
raw = fs.readFileSync(file, "utf-8");
|
|
28
|
+
} catch {
|
|
29
|
+
// Missing, unreadable or a directory: the result says so, like malformed JSON.
|
|
30
|
+
return { ok: false };
|
|
31
|
+
}
|
|
32
|
+
return parseJson(raw);
|
|
33
|
+
}
|