@cbartens/bkit 5.5.1 → 6.0.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 +30 -20
- package/.bkit/core/.agents/docs.md +1 -0
- package/.bkit/core/.agents/rules.md +35 -26
- package/.bkit/core/.bkit/README.md +29 -19
- package/.bkit/core/.bkit/authoring.md +117 -0
- package/.bkit/core/.bkit/cloud.md +11 -11
- package/.bkit/core/.bkit/comparison.md +5 -5
- package/.bkit/core/.bkit/install.md +19 -18
- package/.bkit/core/.bkit/jsonl.md +202 -122
- package/.bkit/core/.bkit/lite.md +1 -1
- package/.bkit/core/.bkit/pipeline.md +49 -52
- package/.bkit/core/.bkit/prompts.md +91 -167
- package/.bkit/core/.bkit/providers.md +29 -32
- package/.bkit/core/.bkit/templates.md +12 -11
- package/.bkit/core/.bkit/trackers.md +51 -28
- package/.bkit/core/.bkit/workflows.md +394 -355
- package/.bkit/core/AGENTS.md +16 -22
- package/.bkit/core/docs/templates/bkit-audit-accessibility.md +14 -38
- package/.bkit/core/docs/templates/bkit-audit-adoption.md +16 -40
- package/.bkit/core/docs/templates/bkit-audit-agents.md +19 -43
- package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +16 -40
- package/.bkit/core/docs/templates/bkit-audit-analytics.md +14 -38
- package/.bkit/core/docs/templates/bkit-audit-annotations.md +11 -35
- package/.bkit/core/docs/templates/bkit-audit-app-performance.md +15 -39
- package/.bkit/core/docs/templates/bkit-audit-app-store.md +12 -36
- package/.bkit/core/docs/templates/bkit-audit-architecture.md +16 -40
- package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +16 -40
- package/.bkit/core/docs/templates/bkit-audit-config.md +18 -42
- package/.bkit/core/docs/templates/bkit-audit-cost.md +16 -40
- package/.bkit/core/docs/templates/bkit-audit-coverage.md +15 -39
- package/.bkit/core/docs/templates/bkit-audit-database.md +16 -40
- package/.bkit/core/docs/templates/bkit-audit-dead-code.md +15 -39
- package/.bkit/core/docs/templates/bkit-audit-deferrals.md +15 -38
- package/.bkit/core/docs/templates/bkit-audit-dependencies.md +16 -40
- package/.bkit/core/docs/templates/bkit-audit-documentation.md +11 -35
- package/.bkit/core/docs/templates/bkit-audit-duplication.md +18 -42
- package/.bkit/core/docs/templates/bkit-audit-failures.md +13 -37
- package/.bkit/core/docs/templates/bkit-audit-flakes.md +12 -36
- package/.bkit/core/docs/templates/bkit-audit-gates.md +14 -38
- package/.bkit/core/docs/templates/bkit-audit-issues.md +15 -39
- package/.bkit/core/docs/templates/bkit-audit-llm.md +16 -40
- package/.bkit/core/docs/templates/bkit-audit-logs.md +14 -38
- package/.bkit/core/docs/templates/bkit-audit-models.md +12 -36
- package/.bkit/core/docs/templates/bkit-audit-privacy.md +12 -36
- package/.bkit/core/docs/templates/bkit-audit-prompts.md +15 -39
- package/.bkit/core/docs/templates/bkit-audit-red-team.md +15 -39
- package/.bkit/core/docs/templates/bkit-audit-reliability.md +15 -39
- package/.bkit/core/docs/templates/bkit-audit-repo.md +12 -36
- package/.bkit/core/docs/templates/bkit-audit-security.md +13 -37
- package/.bkit/core/docs/templates/bkit-audit-slop.md +14 -38
- package/.bkit/core/docs/templates/bkit-audit-testing.md +12 -36
- package/.bkit/core/docs/templates/bkit-audit-usability.md +16 -40
- package/.bkit/core/docs/templates/bkit-plan.md +97 -226
- package/.bkit/core/engine/checks/after/ci-yml.ts +39 -29
- package/.bkit/core/engine/checks/after/github.ts +95 -17
- package/.bkit/core/engine/checks/after/index.ts +10 -7
- package/.bkit/core/engine/checks/after/suppression.ts +8 -5
- package/.bkit/core/engine/checks/after/tools.ts +46 -91
- package/.bkit/core/engine/checks/before/env.ts +2 -2
- package/.bkit/core/engine/checks/before/files.ts +5 -4
- package/.bkit/core/engine/checks/before/index.ts +18 -1
- package/.bkit/core/engine/checks/before/repo.ts +168 -2
- package/.bkit/core/engine/checks/tips/catalogue.ts +16 -5
- package/.bkit/core/engine/checks/tips/detect.ts +34 -0
- package/.bkit/core/engine/checks/tips/index.ts +6 -6
- package/.bkit/core/engine/cli.ts +20 -53
- package/.bkit/core/engine/commands/analysis.ts +171 -140
- package/.bkit/core/engine/commands/ci/ci.ts +6 -6
- package/.bkit/core/engine/commands/comply.ts +77 -103
- package/.bkit/core/engine/commands/install/doctor.ts +2 -2
- package/.bkit/core/engine/commands/install/install.ts +57 -18
- package/.bkit/core/engine/commands/install/uninstall.ts +65 -28
- package/.bkit/core/engine/commands/land.ts +18 -12
- package/.bkit/core/engine/commands/lib.ts +79 -17
- package/.bkit/core/engine/commands/registry.ts +4 -0
- package/.bkit/core/engine/commands/setup/setup.ts +7 -7
- package/.bkit/core/engine/commands/stats.ts +204 -0
- package/.bkit/core/engine/commands/tips.ts +10 -5
- package/.bkit/core/engine/commands/workflow/branches.ts +741 -62
- package/.bkit/core/engine/commands/workflow/challenge.ts +673 -0
- package/.bkit/core/engine/commands/workflow/context.ts +853 -29
- package/.bkit/core/engine/commands/workflow/counters.ts +267 -84
- package/.bkit/core/engine/commands/workflow/decisions.ts +541 -0
- package/.bkit/core/engine/commands/workflow/disk.ts +2 -2
- package/.bkit/core/engine/commands/workflow/fids.ts +793 -33
- package/.bkit/core/engine/commands/workflow/issues.ts +407 -64
- package/.bkit/core/engine/commands/workflow/ledgers.ts +884 -27
- package/.bkit/core/engine/commands/workflow/locks.ts +26 -2
- package/.bkit/core/engine/commands/workflow/plan-blocks.ts +582 -0
- package/.bkit/core/engine/commands/workflow/plan-versions.ts +21 -0
- package/.bkit/core/engine/commands/workflow/prs.ts +166 -30
- package/.bkit/core/engine/commands/workflow/repo.ts +58 -8
- package/.bkit/core/engine/commands/workflow/roadmap.ts +16 -7
- package/.bkit/core/engine/commands/workflow/run-facts.ts +501 -0
- package/.bkit/core/engine/commands/workflow/runs.ts +179 -49
- package/.bkit/core/engine/commands/workflow/runtime.ts +22 -1
- package/.bkit/core/engine/commands/workflow/status.ts +142 -29
- package/.bkit/core/engine/commands/workflow/step-table.ts +339 -0
- package/.bkit/core/engine/commands/workflow/steps.ts +213 -88
- package/.bkit/core/engine/commands/workflow/summary.ts +398 -0
- package/.bkit/core/engine/commands/workflow/tests.ts +1013 -148
- package/.bkit/core/engine/commands/workflow/tracker.ts +1195 -0
- package/.bkit/core/engine/commands/workflow/workflows.ts +984 -207
- package/.bkit/core/engine/commands/workflow/workstreams.ts +11 -5
- package/.bkit/core/engine/commands/workflow/worktrees.ts +185 -8
- package/.bkit/core/engine/install/manifest.ts +11 -9
- package/.bkit/core/engine/install/modules/cloud.ts +21 -13
- package/.bkit/core/engine/install/modules/core.ts +250 -3
- package/.bkit/core/engine/install/modules/opencode.ts +2 -2
- package/.bkit/core/engine/install/version-file.ts +6 -2
- package/.bkit/core/engine/ledgers/migrate.ts +92 -0
- package/.bkit/core/engine/ledgers/status.ts +92 -15
- package/.bkit/core/engine/ledgers/telemetry.ts +1261 -254
- package/.bkit/core/engine/render/hosts.ts +4 -0
- package/.bkit/core/engine/render/models.ts +12 -0
- package/.bkit/core/engine/shared/branches.ts +4 -1
- package/.bkit/core/engine/shared/egress.ts +7 -0
- package/.bkit/core/engine/shared/json.ts +25 -7
- package/.bkit/core/engine/shared/settings.ts +157 -20
- package/.bkit/core/engine/shared/text.ts +361 -0
- package/.bkit/core/engine/tools/grammar-density.ts +215 -0
- package/.bkit/core/engine/tools/instructions-sources.ts +834 -0
- package/.bkit/core/engine/tools/instructions.ts +1751 -0
- package/.bkit/core/hooks/gateguard-engine.js +24 -23
- package/.bkit/core/hooks/guardrails-shell.js +2 -3
- package/.bkit/core/hooks/guardrails-tiers.js +7 -1
- package/.bkit/core/hooks/readguard-engine.js +2 -2
- package/.bkit/core/prompts/bkit-audit-generate.md +62 -25
- package/.bkit/core/prompts/bkit-build-challenge-1.md +40 -17
- package/.bkit/core/prompts/bkit-build-challenge-2.md +44 -17
- package/.bkit/core/prompts/bkit-build-install-skills.md +26 -13
- package/.bkit/core/prompts/bkit-build-plan-convert.md +74 -0
- package/.bkit/core/prompts/bkit-build-plan-current.md +26 -13
- package/.bkit/core/prompts/bkit-build-plan-execute.md +74 -26
- package/.bkit/core/prompts/bkit-build-plan-gaps-remediate.md +64 -23
- package/.bkit/core/prompts/bkit-build-plan-verify.md +57 -33
- package/.bkit/core/prompts/bkit-debug-abort-handover.md +29 -15
- package/.bkit/core/prompts/bkit-debug-failure-diagnose.md +34 -14
- package/.bkit/core/prompts/bkit-debug-failure-remediate.md +34 -17
- package/.bkit/core/prompts/bkit-debug-failure-reproduce.md +26 -13
- package/.bkit/core/prompts/bkit-debug-failure-soak.md +31 -16
- package/.bkit/core/prompts/bkit-design-brainstorm-ideate-1.md +21 -11
- package/.bkit/core/prompts/bkit-design-brainstorm-ideate-2.md +20 -11
- package/.bkit/core/prompts/bkit-design-brainstorm-ideate-3.md +20 -11
- package/.bkit/core/prompts/bkit-design-generate.md +32 -14
- package/.bkit/core/prompts/bkit-design-organise.md +25 -12
- package/.bkit/core/prompts/bkit-design-review-1.md +31 -15
- package/.bkit/core/prompts/bkit-design-review-2.md +28 -13
- package/.bkit/core/prompts/bkit-design-spike.md +30 -13
- package/.bkit/core/prompts/bkit-design-update.md +33 -19
- package/.bkit/core/prompts/bkit-plan-generate.md +72 -18
- package/.bkit/core/prompts/bkit-plan-review-1.md +50 -27
- package/.bkit/core/prompts/bkit-plan-review-2.md +59 -28
- package/.bkit/core/prompts/bkit-plan-scope-check.md +109 -0
- package/.bkit/core/prompts/bkit-plan-update.md +61 -24
- package/.bkit/core/prompts/bkit-ship-conflict-resolve.md +27 -15
- package/.bkit/core/prompts/bkit-ship-deferred-sweep.md +31 -16
- package/.bkit/core/prompts/bkit-ship-update-docs.md +29 -14
- package/.bkit/core/prompts/bkit-utility-compress-markdown.md +24 -14
- package/.bkit/core/prompts/bkit-utility-update-decisions.md +32 -14
- package/.bkit/core/prompts/bkit-utility-update-deferrals.md +29 -14
- package/.bkit/core/prompts/bkit-utility-update-documentation.md +27 -12
- package/.bkit/core/prompts/bkit-utility-update-failures.md +31 -14
- package/.bkit/core/prompts/bkit-utility-update-knowledge.md +33 -14
- package/.bkit/core/prompts/bkit-utility-update-roadmap.md +38 -17
- package/.bkit/core/prompts/bkit-utility-update-tracker.md +41 -18
- package/.bkit/core/workflows/bkit-auto.md +54 -46
- package/.bkit/core/workflows/bkit-build.md +577 -458
- package/.bkit/core/workflows/bkit-debug.md +348 -333
- package/.bkit/core/workflows/bkit-design.md +201 -237
- package/.bkit/core/workflows/bkit-plan.md +210 -321
- package/.bkit/core/workflows/bkit-ship.md +328 -278
- package/.bkit/shared/.bkit/.env.example +2 -2
- package/.bkit/shared/.claude/settings.json +11 -0
- package/.bkit/shared/.cursor/mcp.json +1 -1
- package/.bkit/shared/.cursor/rules/bkit-rules.mdc +1 -1
- package/.bkit/shared/.gitattributes +1 -1
- package/.bkit/shared/.mcp.json +1 -1
- package/.bkit/shared/.opencode/opencode.json +11 -0
- package/.bkit/shared/CLAUDE.md +2 -2
- package/.bkit/shared/GEMINI.md +2 -2
- package/.bkit/shared/docs/architecture.md +1 -1
- package/.bkit/shared/docs/data-schema.md +1 -1
- package/.bkit/shared/docs/deployments.md +11 -11
- package/.bkit/shared/docs/design.md +1 -1
- package/.bkit/shared/docs/noise.md +1 -1
- package/.bkit/shared/docs/observability.md +2 -2
- package/.bkit/shared/docs/security.md +1 -1
- package/.bkit/shared/docs/setup.md +1 -1
- package/.bkit/shared/docs/technology.md +1 -1
- package/.bkit/shared/docs/testing.md +16 -7
- package/.bkit/templates/.claude/hooks/bkit-cloud-bootstrap.sh +1 -1
- package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-change.yml +26 -5
- package/.bkit/templates/.github/workflows/bkit-ci.yml +1 -1
- package/.bkit/templates/.github/workflows/bkit-cloud.yml +21 -19
- package/.bkit/templates/.husky/pre-push +4 -4
- package/.bkit/templates/.prettierignore +7 -0
- package/.bkit/templates/scripts/cleanup/bkit-disk-prune.mjs +1 -1
- package/CHANGELOG.md +112 -0
- package/README.md +50 -35
- package/dist/checks/after/ci-yml.js +39 -28
- package/dist/checks/after/github.js +91 -17
- package/dist/checks/after/index.js +11 -8
- package/dist/checks/after/suppression.js +8 -5
- package/dist/checks/after/tools.js +39 -82
- package/dist/checks/before/env.js +2 -2
- package/dist/checks/before/files.js +5 -3
- package/dist/checks/before/index.js +15 -2
- package/dist/checks/before/repo.js +163 -2
- package/dist/checks/tips/catalogue.js +14 -5
- package/dist/checks/tips/detect.js +32 -0
- package/dist/checks/tips/index.js +4 -4
- package/dist/cli.js +19 -47
- package/dist/commands/analysis.js +109 -100
- package/dist/commands/ci/ci.js +6 -6
- package/dist/commands/comply.js +54 -91
- package/dist/commands/install/doctor.js +2 -2
- package/dist/commands/install/install.js +50 -19
- package/dist/commands/install/uninstall.js +59 -28
- package/dist/commands/land.js +16 -12
- package/dist/commands/lib.js +51 -16
- package/dist/commands/registry.js +4 -0
- package/dist/commands/setup/setup.js +7 -7
- package/dist/commands/stats.js +136 -0
- package/dist/commands/tips.js +7 -3
- package/dist/commands/workflow/branches.js +656 -56
- package/dist/commands/workflow/challenge.js +556 -0
- package/dist/commands/workflow/context.js +709 -30
- package/dist/commands/workflow/counters.js +208 -75
- package/dist/commands/workflow/decisions.js +441 -0
- package/dist/commands/workflow/disk.js +2 -2
- package/dist/commands/workflow/fids.js +689 -33
- package/dist/commands/workflow/issues.js +343 -59
- package/dist/commands/workflow/ledgers.js +762 -27
- package/dist/commands/workflow/locks.js +24 -2
- package/dist/commands/workflow/plan-blocks.js +437 -0
- package/dist/commands/workflow/plan-versions.js +22 -0
- package/dist/commands/workflow/prs.js +142 -32
- package/dist/commands/workflow/repo.js +52 -8
- package/dist/commands/workflow/roadmap.js +9 -7
- package/dist/commands/workflow/run-facts.js +426 -0
- package/dist/commands/workflow/runs.js +144 -43
- package/dist/commands/workflow/runtime.js +12 -1
- package/dist/commands/workflow/status.js +130 -29
- package/dist/commands/workflow/step-table.js +276 -0
- package/dist/commands/workflow/steps.js +171 -80
- package/dist/commands/workflow/summary.js +275 -0
- package/dist/commands/workflow/tests.js +834 -136
- package/dist/commands/workflow/tracker.js +983 -0
- package/dist/commands/workflow/workflows.js +834 -195
- package/dist/commands/workflow/workstreams.js +11 -5
- package/dist/commands/workflow/worktrees.js +147 -9
- package/dist/install/manifest.js +11 -9
- package/dist/install/modules/cloud.js +22 -13
- package/dist/install/modules/core.js +247 -3
- package/dist/install/modules/opencode.js +2 -2
- package/dist/install/version-file.js +6 -2
- package/dist/ledgers/migrate.js +81 -0
- package/dist/ledgers/status.js +61 -8
- package/dist/ledgers/telemetry.js +905 -124
- package/dist/render/hosts.js +4 -0
- package/dist/render/models.js +12 -0
- package/dist/shared/branches.js +3 -1
- package/dist/shared/egress.js +7 -0
- package/dist/shared/json.js +20 -7
- package/dist/shared/settings.js +125 -17
- package/dist/shared/text.js +333 -0
- package/dist/tools/grammar-density.js +183 -0
- package/dist/tools/instructions-sources.js +721 -0
- package/dist/tools/instructions.js +1579 -0
- package/package.json +113 -24
- package/.bkit/core/engine/commands/harvest.ts +0 -459
- package/.bkit/core/engine/tools/wording.ts +0 -748
- package/.bkit/core/prompts/bkit-build-challenge-reconcile.md +0 -69
- package/.bkit/core/prompts/bkit-build-challenge-remediate.md +0 -71
- package/.bkit/core/prompts/bkit-build-challenge-tests.md +0 -74
- package/.bkit/core/prompts/bkit-build-summary.md +0 -94
- package/.bkit/core/prompts/bkit-debug-summary.md +0 -96
- package/.bkit/core/prompts/bkit-design-summary.md +0 -107
- package/.bkit/core/prompts/bkit-plan-complexity-check.md +0 -67
- package/.bkit/core/prompts/bkit-plan-complexity-split.md +0 -88
- package/.bkit/core/prompts/bkit-plan-review-3.md +0 -93
- package/.bkit/core/prompts/bkit-plan-scope-check-1.md +0 -85
- package/.bkit/core/prompts/bkit-plan-scope-check-2.md +0 -85
- package/.bkit/core/prompts/bkit-plan-summary.md +0 -107
- package/.bkit/core/prompts/bkit-ship-summary.md +0 -78
- package/dist/commands/harvest.js +0 -353
- package/dist/tools/wording.js +0 -680
|
@@ -15,18 +15,15 @@
|
|
|
15
15
|
// See DE-34 for the shared-entrypoint + crash-isolation contract.
|
|
16
16
|
|
|
17
17
|
import { execFileSync } from "node:child_process";
|
|
18
|
-
import * as fs from "node:fs";
|
|
19
18
|
import * as path from "node:path";
|
|
20
|
-
import { readJsonFile } from "../shared/json.js";
|
|
21
|
-
import { getPkgRoot } from "../shared/package-roots.js";
|
|
22
19
|
import { isMirrorPath } from "../shared/protected-paths.js";
|
|
23
20
|
import {
|
|
24
21
|
gitEnv,
|
|
25
22
|
resolveGitSha,
|
|
26
|
-
resolveRepoSlug,
|
|
27
23
|
type TelemetryEnvelope,
|
|
28
24
|
type CompliancePayload,
|
|
29
25
|
} from "../ledgers/telemetry.js";
|
|
26
|
+
import { appendLedgerRows } from "./workflow/ledgers.js";
|
|
30
27
|
import type { ComplyPhase } from "../cli.js";
|
|
31
28
|
|
|
32
29
|
// ---------------------------------------------------------------------------
|
|
@@ -200,26 +197,28 @@ export function runGrader(input: GraderInput): Violation[] {
|
|
|
200
197
|
|
|
201
198
|
export interface ComplianceRowInput {
|
|
202
199
|
violations: Violation[];
|
|
203
|
-
|
|
200
|
+
/** The graded workflow (`by.workflow`). */
|
|
201
|
+
workflow: string;
|
|
202
|
+
/** The run's join key: HEAD at its close, shared with its counter and outcome rows. */
|
|
204
203
|
parentSha: string;
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
/** Additional envelope fields (step, subagent, etc.). */
|
|
208
|
-
extra?: Partial<TelemetryEnvelope>;
|
|
204
|
+
/** The step the grade ran at (`by.step`). */
|
|
205
|
+
step: string;
|
|
209
206
|
}
|
|
210
207
|
|
|
208
|
+
/** A compliance row as handed to `bkit ledgers append`: no schema, ts, repo or bkit. */
|
|
209
|
+
export type ComplianceRowDraft = {
|
|
210
|
+
kind: "compliance";
|
|
211
|
+
by: { workflow: string; step: string };
|
|
212
|
+
} & CompliancePayload;
|
|
213
|
+
|
|
211
214
|
export type ComplianceRow = TelemetryEnvelope & CompliancePayload;
|
|
212
215
|
|
|
213
216
|
/**
|
|
214
217
|
* Build one `kind:"compliance"` row per rule.
|
|
215
218
|
* Rules that produced no violation emit a "pass" row.
|
|
216
|
-
* Every row carries `bkitVersion`.
|
|
217
|
-
*
|
|
218
|
-
* Called by the CLI dispatch after `runGrader`.
|
|
219
219
|
*/
|
|
220
|
-
export function buildComplianceRows(input: ComplianceRowInput):
|
|
221
|
-
const
|
|
222
|
-
const { violations, phase, parentSha, repo, bkitVersion, extra } = input;
|
|
220
|
+
export function buildComplianceRows(input: ComplianceRowInput): ComplianceRowDraft[] {
|
|
221
|
+
const { violations, workflow, parentSha, step } = input;
|
|
223
222
|
|
|
224
223
|
const violationByRule = new Map<RuleId, Violation>();
|
|
225
224
|
for (const v of violations) {
|
|
@@ -227,35 +226,17 @@ export function buildComplianceRows(input: ComplianceRowInput): ComplianceRow[]
|
|
|
227
226
|
}
|
|
228
227
|
|
|
229
228
|
const ALL_RULES: RuleId[] = ["no-mirror-edit", "skip-ci-not-head"];
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
for (const ruleId of ALL_RULES) {
|
|
229
|
+
return ALL_RULES.map((ruleId) => {
|
|
233
230
|
const violation = violationByRule.get(ruleId);
|
|
234
|
-
const
|
|
231
|
+
const verdict: "pass" | "fail" | "n/a" = violation != null ? violation.result : "pass";
|
|
235
232
|
const evidence = violation?.evidence;
|
|
236
|
-
|
|
237
|
-
const envelope: TelemetryEnvelope = {
|
|
238
|
-
ts: ts + rows.length, // micro-offset so each row has a unique ts within the batch
|
|
233
|
+
return {
|
|
239
234
|
kind: "compliance",
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
step: "close-gate",
|
|
244
|
-
...(extra ?? {}),
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
const payload: CompliancePayload = {
|
|
248
|
-
rule: ruleId,
|
|
249
|
-
result,
|
|
250
|
-
...(evidence != null ? { evidence } : {}),
|
|
251
|
-
phase,
|
|
252
|
-
parentSha,
|
|
235
|
+
by: { workflow, step },
|
|
236
|
+
run: { parentSha },
|
|
237
|
+
rule: { id: ruleId, verdict, ...(evidence != null ? { evidence } : {}) },
|
|
253
238
|
};
|
|
254
|
-
|
|
255
|
-
rows.push({ ...envelope, ...payload });
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
return rows;
|
|
239
|
+
});
|
|
259
240
|
}
|
|
260
241
|
|
|
261
242
|
// ---------------------------------------------------------------------------
|
|
@@ -263,16 +244,23 @@ export function buildComplianceRows(input: ComplianceRowInput): ComplianceRow[]
|
|
|
263
244
|
// ---------------------------------------------------------------------------
|
|
264
245
|
|
|
265
246
|
/**
|
|
266
|
-
* Append compliance rows to
|
|
267
|
-
* Best-effort: prints `[bkit-comply] append failed: …` on error,
|
|
247
|
+
* Append compliance rows to `<root>/.bkit/stats.jsonl` through `bkit ledgers append`.
|
|
248
|
+
* Best-effort: prints `[bkit-comply] append failed: …` and returns false on error,
|
|
249
|
+
* never throws.
|
|
268
250
|
*/
|
|
269
|
-
export function appendComplianceRows(
|
|
251
|
+
export function appendComplianceRows(
|
|
252
|
+
rows: ComplianceRowDraft[],
|
|
253
|
+
root: string,
|
|
254
|
+
log: (m: string) => void = (m) => console.error(m),
|
|
255
|
+
): boolean {
|
|
256
|
+
if (rows.length === 0) return false;
|
|
270
257
|
try {
|
|
271
|
-
|
|
272
|
-
|
|
258
|
+
appendLedgerRows(root, "stats", rows);
|
|
259
|
+
return true;
|
|
273
260
|
} catch (err: unknown) {
|
|
274
261
|
const msg = err instanceof Error ? err.message : String(err);
|
|
275
|
-
|
|
262
|
+
log(`[bkit-comply] append failed: ${path.join(root, ".bkit", "stats.jsonl")} — ${msg}`);
|
|
263
|
+
return false;
|
|
276
264
|
}
|
|
277
265
|
}
|
|
278
266
|
|
|
@@ -280,37 +268,45 @@ export function appendComplianceRows(rows: ComplianceRow[], statsPath: string):
|
|
|
280
268
|
// One grading pass, as `bkit workflows close` runs it before its report
|
|
281
269
|
// ---------------------------------------------------------------------------
|
|
282
270
|
|
|
271
|
+
/** The run a grade belongs to: the close's join key and step. */
|
|
272
|
+
export interface GradedRun {
|
|
273
|
+
parentSha: string;
|
|
274
|
+
step: string;
|
|
275
|
+
}
|
|
276
|
+
|
|
283
277
|
/**
|
|
284
278
|
* Grade `phase` over HEAD~1..HEAD (HEAD alone in a one-commit repo) and append
|
|
285
279
|
* its compliance rows to `<cwd>/.bkit/stats.jsonl`. With `squashSha` (ship's
|
|
286
280
|
* close, run in the feature worktree) the squash commit is graded instead —
|
|
287
281
|
* its subject and `squash~1..squash` — so the grade covers the whole feature
|
|
288
|
-
* as it reaches main, not the worktree's last commit.
|
|
289
|
-
*
|
|
282
|
+
* as it reaches main, not the worktree's last commit. The rows carry `run`'s
|
|
283
|
+
* `parentSha` and step (default: HEAD and `close-gate`), so they join the
|
|
284
|
+
* close's other rows. Fail-open: any error is logged and returns null, so a
|
|
285
|
+
* close never stops on the grader.
|
|
290
286
|
*/
|
|
291
287
|
export function gradeCompliance(
|
|
292
288
|
cwd: string,
|
|
293
289
|
phase: string,
|
|
294
290
|
log: (m: string) => void,
|
|
295
291
|
squashSha?: string,
|
|
292
|
+
run?: GradedRun,
|
|
296
293
|
): Violation[] | null {
|
|
297
294
|
try {
|
|
298
295
|
const squashParent = squashSha === undefined ? "" : resolveGitSha(`${squashSha}~1`, cwd);
|
|
299
|
-
const
|
|
300
|
-
if (!
|
|
296
|
+
const base = squashParent || resolveGitSha("HEAD~1", cwd) || resolveGitSha("HEAD", cwd);
|
|
297
|
+
if (!base) {
|
|
301
298
|
log("[bkit-comply] cannot resolve a parent SHA (no commits?) — skipping grade");
|
|
302
299
|
return null;
|
|
303
300
|
}
|
|
304
301
|
const headSha = squashParent ? squashSha : undefined;
|
|
305
|
-
const violations = runGrader({ parentSha, phase, cwd, ...(headSha ? { headSha } : {}) });
|
|
302
|
+
const violations = runGrader({ parentSha: base, phase, cwd, ...(headSha ? { headSha } : {}) });
|
|
306
303
|
const rows = buildComplianceRows({
|
|
307
304
|
violations,
|
|
308
|
-
phase,
|
|
309
|
-
parentSha,
|
|
310
|
-
|
|
311
|
-
bkitVersion: readBkitVersion(),
|
|
305
|
+
workflow: phase,
|
|
306
|
+
parentSha: run?.parentSha ?? resolveGitSha("HEAD", cwd),
|
|
307
|
+
step: run?.step ?? "close-gate",
|
|
312
308
|
});
|
|
313
|
-
appendComplianceRows(rows,
|
|
309
|
+
appendComplianceRows(rows, cwd, log);
|
|
314
310
|
log(
|
|
315
311
|
violations.length > 0
|
|
316
312
|
? `[bkit-comply] Compliance violations found:\n${formatComplianceSummary(violations)}`
|
|
@@ -346,33 +342,6 @@ export function formatComplianceSummary(violations: Violation[]): string {
|
|
|
346
342
|
return lines.join("\n");
|
|
347
343
|
}
|
|
348
344
|
|
|
349
|
-
// ---------------------------------------------------------------------------
|
|
350
|
-
// bkitVersion reader (used by CLI dispatch and tests)
|
|
351
|
-
// ---------------------------------------------------------------------------
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* Read the bkit version from the package.json nearest to `searchFrom` (default: the
|
|
355
|
-
* running bkit package's root). Returns "0.0.0" on any read/parse error (fail-open).
|
|
356
|
-
*/
|
|
357
|
-
export function readBkitVersion(searchFrom?: string): string {
|
|
358
|
-
// Walk up looking for a package.json with a `version` field; stop at the filesystem root.
|
|
359
|
-
let dir = path.resolve(searchFrom ?? getPkgRoot());
|
|
360
|
-
for (let i = 0; i < 8; i++) {
|
|
361
|
-
const candidate = path.join(dir, "package.json");
|
|
362
|
-
if (fs.existsSync(candidate)) {
|
|
363
|
-
const read = readJsonFile(candidate);
|
|
364
|
-
// Fail-open: a package.json that cannot be read ends the search with the default.
|
|
365
|
-
if (!read.ok || read.value === null) return "0.0.0";
|
|
366
|
-
const pkg = read.value as { version?: string };
|
|
367
|
-
if (typeof pkg.version === "string") return pkg.version;
|
|
368
|
-
}
|
|
369
|
-
const parent = path.dirname(dir);
|
|
370
|
-
if (parent === dir) break;
|
|
371
|
-
dir = parent;
|
|
372
|
-
}
|
|
373
|
-
return "0.0.0";
|
|
374
|
-
}
|
|
375
|
-
|
|
376
345
|
// comply — compliance grader (advisory, never gating, fail-open).
|
|
377
346
|
// Runs `runGrader` over `git diff parentSha..HEAD`, appends `kind:"compliance"`
|
|
378
347
|
// rows to `.bkit/stats.jsonl`, and logs violations. Always exits 0 (fail-open);
|
|
@@ -385,27 +354,28 @@ export function runComplyCommand(complyPhase: ComplyPhase | null): void {
|
|
|
385
354
|
const phase = complyPhase ?? "unknown";
|
|
386
355
|
const logPrefix = "[bkit-comply]";
|
|
387
356
|
|
|
388
|
-
//
|
|
389
|
-
// matching /^[0-9a-f]{7,40}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
const parentSha = resolveGitSha("HEAD~1", cwd) || resolveGitSha("HEAD", cwd);
|
|
393
|
-
if (!parentSha) {
|
|
357
|
+
// The grade's diff base MUST be a resolved hex SHA: diffPaths returns [] for anything
|
|
358
|
+
// not matching /^[0-9a-f]{7,40}$/. Resolves HEAD~1, else HEAD; neither → skip the grade.
|
|
359
|
+
const base = resolveGitSha("HEAD~1", cwd) || resolveGitSha("HEAD", cwd);
|
|
360
|
+
if (!base) {
|
|
394
361
|
console.log(`${logPrefix} cannot resolve a parent SHA (no commits?) — skipping grade`);
|
|
395
362
|
return;
|
|
396
363
|
}
|
|
397
364
|
|
|
398
|
-
console.log(`${logPrefix} Running compliance grader (phase=${phase},
|
|
399
|
-
|
|
400
|
-
const violations = runGrader({ parentSha, phase, cwd });
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
365
|
+
console.log(`${logPrefix} Running compliance grader (phase=${phase}, base=${base})`);
|
|
366
|
+
|
|
367
|
+
const violations = runGrader({ parentSha: base, phase, cwd });
|
|
368
|
+
// A row names the closing workflow it grades: without one, the grade is printed only.
|
|
369
|
+
const rows =
|
|
370
|
+
complyPhase === null
|
|
371
|
+
? []
|
|
372
|
+
: buildComplianceRows({
|
|
373
|
+
violations,
|
|
374
|
+
workflow: complyPhase,
|
|
375
|
+
parentSha: resolveGitSha("HEAD", cwd),
|
|
376
|
+
step: "close-gate",
|
|
377
|
+
});
|
|
378
|
+
const written = complyPhase !== null && appendComplianceRows(rows, cwd);
|
|
409
379
|
|
|
410
380
|
if (violations.length > 0) {
|
|
411
381
|
const summary = formatComplianceSummary(violations);
|
|
@@ -414,9 +384,13 @@ export function runComplyCommand(complyPhase: ComplyPhase | null): void {
|
|
|
414
384
|
console.log(`${logPrefix} All rules pass.`);
|
|
415
385
|
}
|
|
416
386
|
|
|
417
|
-
|
|
418
|
-
`${logPrefix}
|
|
419
|
-
)
|
|
387
|
+
if (complyPhase === null) {
|
|
388
|
+
console.log(`${logPrefix} no --phase: rows not written to .bkit/stats.jsonl.`);
|
|
389
|
+
} else if (written) {
|
|
390
|
+
console.log(
|
|
391
|
+
`${logPrefix} Appended ${rows.length} compliance row(s) to .bkit/stats.jsonl (advisory — not gating).`,
|
|
392
|
+
);
|
|
393
|
+
}
|
|
420
394
|
} catch (err: unknown) {
|
|
421
395
|
// Fail-open: any unexpected error in the dispatch body must not gate the workflow.
|
|
422
396
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -180,7 +180,7 @@ export async function runDoctor(
|
|
|
180
180
|
id: "opencode-provider-missing",
|
|
181
181
|
severity: "blocker",
|
|
182
182
|
detect:
|
|
183
|
-
"`.opencode/` is present but no provider is recorded — neither package.json `bkit.
|
|
183
|
+
"`.opencode/` is present but no provider is recorded — neither package.json `bkit.providers.opencode.default` nor an `opencode.json` provider block.",
|
|
184
184
|
action: `Re-run \`bkit install --opencode=<provider>\` (${OPENCODE_PROVIDERS.join(", ")}). Until then \`bkit check\` and \`bkit upgrade\` exit 1 rather than render every agent pin against a substitute provider.`,
|
|
185
185
|
});
|
|
186
186
|
}
|
|
@@ -222,7 +222,7 @@ export async function runDoctor(
|
|
|
222
222
|
let detectedProvider: string | null = detectOpencodeProvider(process.cwd());
|
|
223
223
|
if (opencodeProvider) detectedProvider = opencodeProvider;
|
|
224
224
|
|
|
225
|
-
// Multi-provider: all installed providers. bkit.
|
|
225
|
+
// Multi-provider: all installed providers. bkit.providers.opencode.installed when populated,
|
|
226
226
|
// else the single detected provider.
|
|
227
227
|
const allProviders = detectOpencodeProviders(process.cwd());
|
|
228
228
|
const activeProvider = detectedProvider ?? allProviders[0] ?? null;
|
|
@@ -32,11 +32,17 @@ import {
|
|
|
32
32
|
type EffortMap,
|
|
33
33
|
parseModelLookup,
|
|
34
34
|
applyModelOverrides,
|
|
35
|
+
unknownModelOverrides,
|
|
35
36
|
buildOpencodeModelLookup,
|
|
36
37
|
buildAntigravityModelLookup,
|
|
37
38
|
parseEffortMap,
|
|
38
39
|
} from "../../render/models.js";
|
|
39
40
|
import { getBkitDocsRoot } from "../../shared/package-roots.js";
|
|
41
|
+
import {
|
|
42
|
+
migrateBkitLayout,
|
|
43
|
+
migrateGithubProjectKey,
|
|
44
|
+
migrateLinearTeamKey,
|
|
45
|
+
} from "../../install/modules/core.js";
|
|
40
46
|
import type { WriteSet } from "../../install/write.js";
|
|
41
47
|
import { type UninstallContext, removeUnusedTrackerMcpEntries, runUninstall } from "./uninstall.js";
|
|
42
48
|
|
|
@@ -68,7 +74,7 @@ export function discardAllStaging(cwd = process.cwd()): void {
|
|
|
68
74
|
* The installed opencode provider, or exit(1) with the fix.
|
|
69
75
|
*
|
|
70
76
|
* `bkit check` / `bkit upgrade` take no `--opencode=` flag, so they read the provider the
|
|
71
|
-
* consumer actually installed (package.json `bkit.
|
|
77
|
+
* consumer actually installed (package.json `bkit.providers.opencode.default`, else the opencode.json
|
|
72
78
|
* provider block). There is no default: a repo carrying `.opencode/` with no recorded
|
|
73
79
|
* provider is a broken install.
|
|
74
80
|
*
|
|
@@ -79,7 +85,7 @@ export function requireOpencodeProvider(cwd: string, context: string): string {
|
|
|
79
85
|
if (!detected) {
|
|
80
86
|
console.error(
|
|
81
87
|
`${LOG_PREFIX} ${context}: the opencode host is installed but no provider is recorded ` +
|
|
82
|
-
`(package.json \`bkit.
|
|
88
|
+
`(package.json \`bkit.providers.opencode.default\` and .opencode/opencode.json are both silent). ` +
|
|
83
89
|
`Re-run \`bkit install --opencode=<provider>\` — one of ${OPENCODE_PROVIDERS.join(", ")}.`,
|
|
84
90
|
);
|
|
85
91
|
process.exit(1);
|
|
@@ -131,11 +137,20 @@ export function validateCloudTrackerMatch(
|
|
|
131
137
|
);
|
|
132
138
|
}
|
|
133
139
|
|
|
140
|
+
/** `parent[key]` as an object, set to a fresh `{}` first when it is absent or not an object. */
|
|
141
|
+
function section(parent: Record<string, unknown>, key: string): Record<string, unknown> {
|
|
142
|
+
const v = parent[key];
|
|
143
|
+
if (v !== null && typeof v === "object" && !Array.isArray(v)) return v as Record<string, unknown>;
|
|
144
|
+
const fresh: Record<string, unknown> = {};
|
|
145
|
+
parent[key] = fresh;
|
|
146
|
+
return fresh;
|
|
147
|
+
}
|
|
148
|
+
|
|
134
149
|
/**
|
|
135
150
|
* Detect the bkit opencode provider key a consumer installed.
|
|
136
151
|
*
|
|
137
152
|
* Resolution order:
|
|
138
|
-
* 1. `package.json` `bkit.
|
|
153
|
+
* 1. `package.json` `bkit.providers.opencode.default` — the authoritative record written on install.
|
|
139
154
|
* This is the ONLY signal for managed-auth gateways (opencode) whose opencode.json carries no
|
|
140
155
|
* custom provider block.
|
|
141
156
|
* 2. `.opencode/opencode.json` first provider key — for installs without the manifest field
|
|
@@ -165,7 +180,7 @@ export function detectOpencodeProvider(cwd: string): string | null {
|
|
|
165
180
|
|
|
166
181
|
/**
|
|
167
182
|
* Returns all bkit-installed opencode providers from the consumer package.json
|
|
168
|
-
* `bkit.
|
|
183
|
+
* `bkit.providers.opencode.installed` array, filtered to valid OPENCODE_PROVIDERS entries; [] when
|
|
169
184
|
* the field is absent.
|
|
170
185
|
*/
|
|
171
186
|
export function detectOpencodeProviders(cwd: string): string[] {
|
|
@@ -227,6 +242,18 @@ export async function runInstall(
|
|
|
227
242
|
if (upgradeReport) console.log(`${LOG_PREFIX} Checking advisories (read-only)`);
|
|
228
243
|
else if (dryRun) console.log(`${LOG_PREFIX} Running in check (dry-run) mode`);
|
|
229
244
|
|
|
245
|
+
// The package.json key moves run before anything below reads `bkit` settings: the tracker,
|
|
246
|
+
// the opencode provider and the cloud agent are read from the new paths only, so a 5.x
|
|
247
|
+
// layout read first renders every host as if no tracker were set. The core module runs
|
|
248
|
+
// the same moves again; each is a no-op once applied. Check moves nothing and reports
|
|
249
|
+
// the old keys as drift.
|
|
250
|
+
const ws: WriteSet = { writes: [] };
|
|
251
|
+
if (!dryRun) {
|
|
252
|
+
migrateLinearTeamKey(false, ws, LOG_PREFIX);
|
|
253
|
+
migrateGithubProjectKey(false, ws, LOG_PREFIX);
|
|
254
|
+
migrateBkitLayout(false, ws, LOG_PREFIX);
|
|
255
|
+
}
|
|
256
|
+
|
|
230
257
|
// `bkit check` scopes drift detection to what is INSTALLED (detected by sentinel files),
|
|
231
258
|
// not to a fixed full set. `install` keeps its explicit resolved set, plus every installed
|
|
232
259
|
// host when `--tracker=` is given: each host renders tracker-specific commands, agents and
|
|
@@ -240,14 +267,14 @@ export async function runInstall(
|
|
|
240
267
|
|
|
241
268
|
// RENDER-input provider resolution. `bkit check` takes no `--opencode=` flag, so the parsed
|
|
242
269
|
// `opencodeProvider` is null on the check path; it falls back to the INSTALLED provider
|
|
243
|
-
// (package.json `bkit.
|
|
270
|
+
// (package.json `bkit.providers.opencode.default`, else the opencode.json provider block). On install
|
|
244
271
|
// `?? detect` fires only when opencode joins as an installed host under `--tracker=`; with
|
|
245
272
|
// `--opencode=<provider>` the flag wins. The PARSED `opencodeProvider` alone drives the persist-to-package.json logic
|
|
246
273
|
// below (gated on `!dryRun` + a real flag). The tracker is resolved from package.json below,
|
|
247
274
|
// so the tracker-dependent opencode mcp block renders the same way on check.
|
|
248
275
|
const renderOpencodeProvider = opencodeProvider ?? detectOpencodeProvider(process.cwd());
|
|
249
276
|
|
|
250
|
-
// Resolve issueTracker: --tracker= flag overrides; else read bkit.
|
|
277
|
+
// Resolve issueTracker: --tracker= flag overrides; else read bkit.tracker.default from consumer
|
|
251
278
|
// package.json; else default to "none".
|
|
252
279
|
// A `--tracker=` value always applies, whether first-set or a re-set of an
|
|
253
280
|
// already-recorded tracker.
|
|
@@ -344,8 +371,20 @@ export async function runInstall(
|
|
|
344
371
|
|
|
345
372
|
// Seed preflight advisories into ctx so modules can accumulate into the same list.
|
|
346
373
|
const advisories: PreflightFinding[] = [...preflightAdvisories];
|
|
374
|
+
const deadOverrides =
|
|
375
|
+
modelLookup.size > 0
|
|
376
|
+
? unknownModelOverrides(consumerPromptsMdPath, new Set(modelLookup.keys()))
|
|
377
|
+
: [];
|
|
378
|
+
if (deadOverrides.length > 0) {
|
|
379
|
+
advisories.push({
|
|
380
|
+
id: "model-override-unknown-agent",
|
|
381
|
+
severity: "advisory",
|
|
382
|
+
detect: `.bkit/prompts.md § Model Overrides names agents bkit no longer ships: ${deadOverrides.join(", ")}. Those rows are not applied.`,
|
|
383
|
+
action:
|
|
384
|
+
"Delete the rows, or move each pin to the agent that now does that work (see .bkit/prompts.md § Models).",
|
|
385
|
+
});
|
|
386
|
+
}
|
|
347
387
|
|
|
348
|
-
const ws: WriteSet = { writes: [] };
|
|
349
388
|
const postDispatch: Array<() => void> = [];
|
|
350
389
|
|
|
351
390
|
// Symmetric cloud/tracker constraint (FINAL SCOPE decision 3/4) — see
|
|
@@ -375,8 +414,8 @@ export async function runInstall(
|
|
|
375
414
|
|
|
376
415
|
// Persist bkit manifest fields to consumer package.json AFTER all hard-error gates pass.
|
|
377
416
|
// This preserves the "no files written on mismatch" invariant. Two fields are recorded:
|
|
378
|
-
// -
|
|
379
|
-
// -
|
|
417
|
+
// - tracker.default: when a `--tracker=` value was given this run.
|
|
418
|
+
// - providers.opencode.default: when an `--opencode=<provider>` value was given this run. This is
|
|
380
419
|
// the authoritative provider record detectOpencodeProvider reads on upgrade — REQUIRED
|
|
381
420
|
// for managed-auth gateways (opencode), whose opencode.json carries no provider block to
|
|
382
421
|
// detect from. Both are merged in one read-modify-write to avoid double-writing.
|
|
@@ -391,20 +430,20 @@ export async function runInstall(
|
|
|
391
430
|
const parsed = parseJson(raw);
|
|
392
431
|
if (parsed.ok) {
|
|
393
432
|
const pkg = parsed.value as Record<string, unknown>;
|
|
394
|
-
const bkit = (pkg
|
|
395
|
-
if (persistTracker) bkit.
|
|
433
|
+
const bkit = section(pkg, "bkit");
|
|
434
|
+
if (persistTracker) section(bkit, "tracker").default = tracker;
|
|
396
435
|
if (persistProvider) {
|
|
397
|
-
|
|
436
|
+
const opencode = section(section(bkit, "providers"), "opencode");
|
|
437
|
+
opencode.default = opencodeProvider; // active (drives agent frontmatter)
|
|
398
438
|
// Update providers array (deduped).
|
|
399
|
-
const existingArr: string[] = Array.isArray(
|
|
400
|
-
? [...(
|
|
439
|
+
const existingArr: string[] = Array.isArray(opencode.installed)
|
|
440
|
+
? [...(opencode.installed as string[])]
|
|
401
441
|
: [];
|
|
402
442
|
if (!existingArr.includes(opencodeProvider!)) {
|
|
403
443
|
existingArr.push(opencodeProvider!);
|
|
404
444
|
}
|
|
405
|
-
|
|
445
|
+
opencode.installed = existingArr;
|
|
406
446
|
}
|
|
407
|
-
pkg.bkit = bkit;
|
|
408
447
|
const indentMatch = raw.match(/\n([ \t]+)"/);
|
|
409
448
|
const indent = indentMatch ? indentMatch[1] : " ";
|
|
410
449
|
const trailingNewline = raw.endsWith("\n") ? "\n" : "";
|
|
@@ -414,11 +453,11 @@ export async function runInstall(
|
|
|
414
453
|
"utf-8",
|
|
415
454
|
);
|
|
416
455
|
if (persistTracker) {
|
|
417
|
-
console.log(`${LOG_PREFIX} Set bkit.
|
|
456
|
+
console.log(`${LOG_PREFIX} Set bkit.tracker.default = "${tracker}" in package.json`);
|
|
418
457
|
}
|
|
419
458
|
if (persistProvider) {
|
|
420
459
|
console.log(
|
|
421
|
-
`${LOG_PREFIX} Set bkit.
|
|
460
|
+
`${LOG_PREFIX} Set bkit.providers.opencode.default = "${opencodeProvider}" and updated bkit.providers.opencode.installed in package.json`,
|
|
422
461
|
);
|
|
423
462
|
}
|
|
424
463
|
}
|
|
@@ -61,6 +61,7 @@ import {
|
|
|
61
61
|
} from "../../render/models.js";
|
|
62
62
|
import { readInstallingVersion } from "../../shared/package-json.js";
|
|
63
63
|
import { readBkitConfig } from "../../shared/settings.js";
|
|
64
|
+
import { SEEDED_BKIT_DEFAULTS } from "../../install/modules/core.js";
|
|
64
65
|
import {
|
|
65
66
|
CLAUDE_CLOUD_RELPATH,
|
|
66
67
|
CURSOR_CLOUD_RELPATH,
|
|
@@ -818,7 +819,7 @@ export async function runUninstall(
|
|
|
818
819
|
}
|
|
819
820
|
|
|
820
821
|
// Full/core uninstall: strip the `bkit` install-state object from package.json
|
|
821
|
-
// (
|
|
822
|
+
// (tracker / providers / cloud and every other section), whatever keys it holds. Scripts
|
|
822
823
|
// and devDeps are the consumer's and stay. No try/catch — malformed package.json is a hard failure on full
|
|
823
824
|
// teardown (same as a missing dest would be).
|
|
824
825
|
if (moduleList.includes("core") && !ctx.dryRun) {
|
|
@@ -834,8 +835,8 @@ export async function runUninstall(
|
|
|
834
835
|
}
|
|
835
836
|
}
|
|
836
837
|
|
|
837
|
-
// Targeted uninstall:
|
|
838
|
-
// stop firing. Core keeps every other key.
|
|
838
|
+
// Targeted uninstall: reset the `bkit.*` keys the removed module records to unset, so its
|
|
839
|
+
// advisories stop firing. Core keeps every other key.
|
|
839
840
|
if (!moduleList.includes("core")) {
|
|
840
841
|
stripModuleBkitKeys(moduleList, ctx, result);
|
|
841
842
|
}
|
|
@@ -1035,16 +1036,38 @@ export async function runUninstall(
|
|
|
1035
1036
|
return result;
|
|
1036
1037
|
}
|
|
1037
1038
|
|
|
1038
|
-
/** `package.json` `bkit.*` keys each module records on install. */
|
|
1039
|
+
/** `package.json` `bkit.*` keys (dotted paths) each module records on install. */
|
|
1039
1040
|
const MODULE_BKIT_KEYS: Partial<Record<ModuleName, readonly string[]>> = {
|
|
1040
|
-
cloud: ["
|
|
1041
|
-
opencode: ["
|
|
1041
|
+
cloud: ["cloud.agent"],
|
|
1042
|
+
opencode: ["providers.opencode.default", "providers.opencode.installed"],
|
|
1042
1043
|
};
|
|
1043
1044
|
|
|
1045
|
+
/** The object at dotted `keys` under `root`; null when a step is absent or not an object. */
|
|
1046
|
+
function objectAt(
|
|
1047
|
+
root: Record<string, unknown>,
|
|
1048
|
+
keys: readonly string[],
|
|
1049
|
+
): Record<string, unknown> | null {
|
|
1050
|
+
let node: Record<string, unknown> = root;
|
|
1051
|
+
for (const k of keys) {
|
|
1052
|
+
const next = node[k];
|
|
1053
|
+
if (!isJsonObject(next as JsonValue)) return null;
|
|
1054
|
+
node = next as Record<string, unknown>;
|
|
1055
|
+
}
|
|
1056
|
+
return node;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
/** The seeded value at dotted `key` in SEEDED_BKIT_DEFAULTS, copied. */
|
|
1060
|
+
function seededValue(key: string): unknown {
|
|
1061
|
+
const segs = key.split(".");
|
|
1062
|
+
const parent = objectAt(SEEDED_BKIT_DEFAULTS as Record<string, unknown>, segs.slice(0, -1));
|
|
1063
|
+
return structuredClone(parent?.[segs[segs.length - 1]!]);
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1044
1066
|
/**
|
|
1045
|
-
*
|
|
1046
|
-
*
|
|
1047
|
-
*
|
|
1067
|
+
* Reset the `bkit.*` keys recorded by the modules in `moduleList` to the value install
|
|
1068
|
+
* seeds (`""` / `[]`, read as unset), keeping the package.json indent. Deleting them
|
|
1069
|
+
* would leave `bkit check` reporting the seeded key as missing. Lists each reset key in
|
|
1070
|
+
* `result.stripped`; a dry run lists without writing.
|
|
1048
1071
|
*/
|
|
1049
1072
|
function stripModuleBkitKeys(
|
|
1050
1073
|
moduleList: ModuleName[],
|
|
@@ -1060,14 +1083,24 @@ function stripModuleBkitKeys(
|
|
|
1060
1083
|
const pkg = parsed.ok ? (parsed.value as Record<string, unknown> | null) : null;
|
|
1061
1084
|
if (pkg === null || !isJsonObject(pkg.bkit as JsonValue)) return;
|
|
1062
1085
|
const bkit = pkg.bkit as Record<string, unknown>;
|
|
1063
|
-
const
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1086
|
+
const reset = keys.filter((k) => {
|
|
1087
|
+
const segs = k.split(".");
|
|
1088
|
+
const parent = objectAt(bkit, segs.slice(0, -1));
|
|
1089
|
+
const key = segs[segs.length - 1]!;
|
|
1090
|
+
return (
|
|
1091
|
+
parent !== null &&
|
|
1092
|
+
key in parent &&
|
|
1093
|
+
JSON.stringify(parent[key]) !== JSON.stringify(seededValue(k))
|
|
1094
|
+
);
|
|
1095
|
+
});
|
|
1096
|
+
if (reset.length === 0) return;
|
|
1097
|
+
for (const k of reset) {
|
|
1098
|
+
const segs = k.split(".");
|
|
1099
|
+
objectAt(bkit, segs.slice(0, -1))![segs[segs.length - 1]!] = seededValue(k);
|
|
1067
1100
|
result.stripped.push(`package.json#bkit.${k}`);
|
|
1068
1101
|
}
|
|
1069
1102
|
console.log(
|
|
1070
|
-
`${ctx.logPrefix}${ctx.dryRun ? " [dry-run]" : ""} package.json:
|
|
1103
|
+
`${ctx.logPrefix}${ctx.dryRun ? " [dry-run]" : ""} package.json: reset bkit.${reset.join(", bkit.")} to unset`,
|
|
1071
1104
|
);
|
|
1072
1105
|
if (ctx.dryRun) return;
|
|
1073
1106
|
const indentMatch = raw.match(/\n([ \t]+)"/);
|
|
@@ -1084,8 +1117,8 @@ function stripModuleBkitKeys(
|
|
|
1084
1117
|
*
|
|
1085
1118
|
* Distinct from bare `bkit uninstall --opencode` (full host teardown):
|
|
1086
1119
|
* - Removes the provider block from `.opencode/opencode.json`
|
|
1087
|
-
* - Updates `bkit.
|
|
1088
|
-
* - If the removed provider was the active one, re-points `bkit.
|
|
1120
|
+
* - Updates `bkit.providers.opencode.installed` in `package.json`
|
|
1121
|
+
* - If the removed provider was the active one, re-points `bkit.providers.opencode.default`
|
|
1089
1122
|
* to the first remaining provider and emits a re-render advisory
|
|
1090
1123
|
* - If no providers remain, falls through to full host teardown via `runUninstall`
|
|
1091
1124
|
*/
|
|
@@ -1105,7 +1138,7 @@ export async function runSurgicalOpencodeUninstall(
|
|
|
1105
1138
|
console.log(`${LOG_PREFIX}${tag} removed provider block "${providerKey}" from opencode.json`);
|
|
1106
1139
|
}
|
|
1107
1140
|
|
|
1108
|
-
// 2. Update bkit.
|
|
1141
|
+
// 2. Update bkit.providers.opencode.installed in package.json (read inline — no detectOpencodeProviders import)
|
|
1109
1142
|
const pkgPath = path.join(cwd, "package.json");
|
|
1110
1143
|
let remainingProviders: string[] = [];
|
|
1111
1144
|
let wasActive = false;
|
|
@@ -1119,32 +1152,36 @@ export async function runSurgicalOpencodeUninstall(
|
|
|
1119
1152
|
console.warn(`${LOG_PREFIX} package.json is malformed — skipping bkit section update`);
|
|
1120
1153
|
return;
|
|
1121
1154
|
}
|
|
1122
|
-
const
|
|
1123
|
-
const arr = Array.isArray(
|
|
1124
|
-
? [...(bkit.opencodeProviders as string[])]
|
|
1125
|
-
: [];
|
|
1155
|
+
const opencode = objectAt(pkg, ["bkit", "providers", "opencode"]) ?? {};
|
|
1156
|
+
const arr = Array.isArray(opencode.installed) ? [...(opencode.installed as string[])] : [];
|
|
1126
1157
|
remainingProviders = arr.filter((p) => p !== providerKey);
|
|
1127
|
-
wasActive =
|
|
1158
|
+
wasActive = opencode.default === providerKey;
|
|
1128
1159
|
if (wasActive && remainingProviders.length > 0) {
|
|
1129
1160
|
newActive = remainingProviders[0]!;
|
|
1130
1161
|
}
|
|
1131
1162
|
|
|
1132
1163
|
if (!dryRun) {
|
|
1133
|
-
|
|
1164
|
+
opencode.installed = remainingProviders;
|
|
1134
1165
|
if (wasActive) {
|
|
1135
1166
|
if (newActive !== null) {
|
|
1136
|
-
|
|
1167
|
+
opencode.default = newActive;
|
|
1137
1168
|
} else {
|
|
1138
|
-
delete
|
|
1169
|
+
delete opencode.default;
|
|
1139
1170
|
}
|
|
1140
1171
|
}
|
|
1141
|
-
pkg
|
|
1172
|
+
if (objectAt(pkg, ["bkit", "providers", "opencode"]) === null) {
|
|
1173
|
+
const bkit = objectAt(pkg, ["bkit"]) ?? {};
|
|
1174
|
+
const providers = objectAt(bkit, ["providers"]) ?? {};
|
|
1175
|
+
providers.opencode = opencode;
|
|
1176
|
+
bkit.providers = providers;
|
|
1177
|
+
pkg.bkit = bkit;
|
|
1178
|
+
}
|
|
1142
1179
|
const indentMatch = raw.match(/\n([ \t]+)"/);
|
|
1143
1180
|
const indent = indentMatch ? indentMatch[1] : " ";
|
|
1144
1181
|
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, indent) + "\n", "utf-8");
|
|
1145
1182
|
console.log(
|
|
1146
|
-
`${LOG_PREFIX} updated package.json:
|
|
1147
|
-
(wasActive ? `
|
|
1183
|
+
`${LOG_PREFIX} updated package.json: bkit.providers.opencode.installed=[${remainingProviders.join(", ")}]` +
|
|
1184
|
+
(wasActive ? ` bkit.providers.opencode.default=${newActive ?? "(removed)"}` : ""),
|
|
1148
1185
|
);
|
|
1149
1186
|
}
|
|
1150
1187
|
}
|