@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
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
// Commands that look up a script or a `bkit` setting need to tell "no file" and
|
|
4
4
|
// "file is not JSON" apart from "key absent", so a broken manifest is named in the
|
|
5
5
|
// message instead of reading as an empty one.
|
|
6
|
+
//
|
|
7
|
+
// `readInstallingVersion` reads the same file for the bkit package doing the install.
|
|
6
8
|
|
|
7
9
|
import * as fs from "node:fs";
|
|
8
10
|
import * as path from "node:path";
|
|
9
11
|
|
|
10
12
|
import { parseJson } from "./json.js";
|
|
13
|
+
import { getPkgRoot } from "./package-roots.js";
|
|
11
14
|
|
|
12
15
|
export type PackageJsonRead =
|
|
13
16
|
{ ok: true; pkg: Record<string, unknown> } | { ok: false; reason: "missing" | "unparseable" };
|
|
@@ -27,3 +30,63 @@ export function readPackageJson(dir: string): PackageJsonRead {
|
|
|
27
30
|
}
|
|
28
31
|
return { ok: true, pkg: parsed.value as Record<string, unknown> };
|
|
29
32
|
}
|
|
33
|
+
|
|
34
|
+
/** Every dependency name across the four `package.json` dependency fields; `[]` when unreadable. */
|
|
35
|
+
export function readDependencyNames(cwd: string): string[] {
|
|
36
|
+
const read = readPackageJson(cwd);
|
|
37
|
+
if (!read.ok) return [];
|
|
38
|
+
const names: string[] = [];
|
|
39
|
+
for (const field of [
|
|
40
|
+
"dependencies",
|
|
41
|
+
"devDependencies",
|
|
42
|
+
"optionalDependencies",
|
|
43
|
+
"peerDependencies",
|
|
44
|
+
]) {
|
|
45
|
+
const deps = read.pkg[field];
|
|
46
|
+
if (deps && typeof deps === "object") {
|
|
47
|
+
names.push(...Object.keys(deps as Record<string, unknown>));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return names;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The spec `package.json` declares for dependency `name` (`"^5.2.0"`, `"file:../x.tgz"`, …),
|
|
55
|
+
* from `dependencies`, `devDependencies` or `optionalDependencies`; `null` when undeclared or
|
|
56
|
+
* the file is unreadable.
|
|
57
|
+
*/
|
|
58
|
+
export function readDependencySpec(cwd: string, name: string): string | null {
|
|
59
|
+
const read = readPackageJson(cwd);
|
|
60
|
+
if (!read.ok) return null;
|
|
61
|
+
for (const field of ["dependencies", "devDependencies", "optionalDependencies"]) {
|
|
62
|
+
const deps = read.pkg[field];
|
|
63
|
+
if (deps && typeof deps === "object") {
|
|
64
|
+
const spec = (deps as Record<string, unknown>)[name];
|
|
65
|
+
if (typeof spec === "string") return spec;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The version of the bkit package doing the install, read from that package's own
|
|
73
|
+
* `package.json` (`root` defaults to the package root; never the consumer's file).
|
|
74
|
+
* Throws when the file is missing, is not a JSON object, or has no non-empty string
|
|
75
|
+
* `version`: the value is stamped into every managed file and the `.bkit/version` pin,
|
|
76
|
+
* so a damaged package stops the command instead of writing a guessed version.
|
|
77
|
+
*/
|
|
78
|
+
export function readInstallingVersion(root: string = getPkgRoot()): string {
|
|
79
|
+
const file = path.join(root, "package.json");
|
|
80
|
+
const read = readPackageJson(root);
|
|
81
|
+
if (!read.ok) {
|
|
82
|
+
const state = read.reason === "missing" ? "is missing" : "is not a JSON object";
|
|
83
|
+
throw new Error(`bkit's own package.json ${state} (${file}); reinstall @cbartens/bkit.`);
|
|
84
|
+
}
|
|
85
|
+
const version = read.pkg["version"];
|
|
86
|
+
if (typeof version !== "string" || version === "") {
|
|
87
|
+
throw new Error(
|
|
88
|
+
`bkit's own package.json has no string "version" (${file}); reinstall @cbartens/bkit.`,
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
return version;
|
|
92
|
+
}
|
|
@@ -149,13 +149,3 @@ export function getHooksRoot(): string {
|
|
|
149
149
|
export function getBkitDocsRoot(): string {
|
|
150
150
|
return path.join(getCoreRoot(), ".bkit");
|
|
151
151
|
}
|
|
152
|
-
|
|
153
|
-
// ---------------------------------------------------------------------------
|
|
154
|
-
// isDogfood — true when bkit is running inside its own repo (in-repo install).
|
|
155
|
-
// In this case the source tree IS the consumer's .agents/ directory, so any
|
|
156
|
-
// payload copy would overwrite the source with itself.
|
|
157
|
-
// ---------------------------------------------------------------------------
|
|
158
|
-
|
|
159
|
-
export function isDogfood(): boolean {
|
|
160
|
-
return getPkgRoot() === process.cwd();
|
|
161
|
-
}
|
|
@@ -1,21 +1,13 @@
|
|
|
1
|
-
// shared/protected-paths.ts —
|
|
2
|
-
// grader (`commands/comply.ts`)
|
|
3
|
-
// (`.claude/hooks/gate-paths.generated.cjs`).
|
|
1
|
+
// shared/protected-paths.ts — the table of bkit-managed IDE mirror directories, used by the
|
|
2
|
+
// compliance grader (`commands/comply.ts`).
|
|
4
3
|
//
|
|
5
4
|
// RULES:
|
|
6
|
-
// - This file is the ONE source of truth for
|
|
7
|
-
// - The
|
|
8
|
-
//
|
|
9
|
-
// - The `.cjs` lives in bkit's own repo only; install never writes it. The
|
|
10
|
-
// generation step is a manual bkit-dev tool (`generateGatePathsCjs()`).
|
|
5
|
+
// - This file is the ONE source of truth for mirror path definitions.
|
|
6
|
+
// - The gate-config list (quality-gate config basenames) lives only in
|
|
7
|
+
// `.bkit/core/hooks/gateguard-engine.js`, which every host's `bkit-gateguard` hook inlines.
|
|
11
8
|
// - Never import install-tier logic from here (keeps grader crash-isolated from
|
|
12
9
|
// the consumer-mutating install path — see DE-34).
|
|
13
10
|
|
|
14
|
-
import * as fs from "node:fs";
|
|
15
|
-
import * as path from "node:path";
|
|
16
|
-
import { fileURLToPath } from "node:url";
|
|
17
|
-
import { isDogfood, TEMPLATE_COPIES_DIR } from "./package-roots.js";
|
|
18
|
-
|
|
19
11
|
// ---------------------------------------------------------------------------
|
|
20
12
|
// Mirror-path patterns (bkit-managed IDE mirrors)
|
|
21
13
|
// ---------------------------------------------------------------------------
|
|
@@ -45,120 +37,3 @@ export const MIRROR_PATH_PREFIXES: readonly string[] = [
|
|
|
45
37
|
export function isMirrorPath(posixPath: string): boolean {
|
|
46
38
|
return MIRROR_PATH_PREFIXES.some((prefix) => posixPath.startsWith(prefix));
|
|
47
39
|
}
|
|
48
|
-
|
|
49
|
-
// ---------------------------------------------------------------------------
|
|
50
|
-
// Gate-config basename patterns (quality-gate configs)
|
|
51
|
-
// ---------------------------------------------------------------------------
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Basename patterns for quality-gate configs (lint / format / types / test / slop).
|
|
55
|
-
* Mirrors `GATE_CONFIG_PATTERNS` in `bkit-gateguard.cjs` — kept in sync via the
|
|
56
|
-
* generated `.cjs` drift test. Editing these configs to silence a gate is the
|
|
57
|
-
* "weaken-the-gate" anti-pattern; prefer targeted per-file opt-outs.
|
|
58
|
-
*/
|
|
59
|
-
export const GATE_CONFIG_PATTERNS: readonly RegExp[] = [
|
|
60
|
-
/^tsconfig(\..+)?\.json$/,
|
|
61
|
-
/^vitest\.config\.[mc]?[jt]s$/,
|
|
62
|
-
/^vite\.config\.[mc]?[jt]s$/,
|
|
63
|
-
/^eslint\.config\.[mc]?[jt]s$/,
|
|
64
|
-
/^\.eslintrc(\.(json|js|cjs|ya?ml))?$/,
|
|
65
|
-
/^\.prettierrc(\.(json|js|cjs|mjs|ya?ml|toml))?$/,
|
|
66
|
-
/^prettier\.config\.[mc]?js$/,
|
|
67
|
-
/^\.prettierignore$/,
|
|
68
|
-
/^biome\.jsonc?$/,
|
|
69
|
-
/^\.vale\.ini$/,
|
|
70
|
-
/^slop-scan\.config\.json$/,
|
|
71
|
-
/^\.lintstagedrc(\.(json|js|cjs|mjs|ya?ml))?$/,
|
|
72
|
-
/^lint-staged\.config\.[mc]?js$/,
|
|
73
|
-
];
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* POSIX prefix of the consumer's template copies (`shared/package-roots.ts` TEMPLATE_COPIES_DIR).
|
|
77
|
-
* Those are bkit's reference copies, refreshed on every upgrade, not the repo's gate config.
|
|
78
|
-
*/
|
|
79
|
-
export const TEMPLATE_COPIES_PREFIX = TEMPLATE_COPIES_DIR.split(path.sep).join("/") + "/";
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Returns true if the file basename matches any gate-config pattern. In a consumer repo a
|
|
83
|
-
* path under `.bkit/templates/` never is one; in bkit's own repo (`dogfood`) that folder is
|
|
84
|
-
* the template source, so it stays guarded.
|
|
85
|
-
*/
|
|
86
|
-
export function isGateConfig(posixPath: string, dogfood: boolean = isDogfood()): boolean {
|
|
87
|
-
const inTemplateCopies =
|
|
88
|
-
posixPath.startsWith(TEMPLATE_COPIES_PREFIX) ||
|
|
89
|
-
posixPath.includes("/" + TEMPLATE_COPIES_PREFIX);
|
|
90
|
-
if (inTemplateCopies && !dogfood) return false;
|
|
91
|
-
const base = posixPath.split("/").pop() ?? posixPath;
|
|
92
|
-
return GATE_CONFIG_PATTERNS.some((re) => re.test(base));
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// ---------------------------------------------------------------------------
|
|
96
|
-
// Code generator — emits the committed `.cjs` from this table.
|
|
97
|
-
// Run manually by a bkit developer: `ts-node .bkit/core/engine/shared/protected-paths.ts`
|
|
98
|
-
// The output must be committed to `.claude/hooks/gate-paths.generated.cjs`.
|
|
99
|
-
// ---------------------------------------------------------------------------
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Generate the content of `.claude/hooks/gate-paths.generated.cjs`.
|
|
103
|
-
* This is the single committed snapshot derived from the tables above.
|
|
104
|
-
*/
|
|
105
|
-
export function generateGatePathsCjs(): string {
|
|
106
|
-
const mirrorLines = MIRROR_PATH_PREFIXES.map((p) => ` ${JSON.stringify(p)},`).join("\n");
|
|
107
|
-
const gateLines = GATE_CONFIG_PATTERNS.map((re) => ` ${re.toString()},`).join("\n");
|
|
108
|
-
|
|
109
|
-
return `// gate-paths.generated.cjs — AUTO-GENERATED from .bkit/core/engine/shared/protected-paths.ts
|
|
110
|
-
// DO NOT EDIT BY HAND — regenerate via \`generateGatePathsCjs()\` then commit.
|
|
111
|
-
// Drift is detected by .bkit/core/engine/shared/protected-paths.test.ts (Vitest).
|
|
112
|
-
"use strict";
|
|
113
|
-
|
|
114
|
-
/** Prefixes for bkit-managed IDE mirror directories. */
|
|
115
|
-
const MIRROR_PATH_PREFIXES = [
|
|
116
|
-
${mirrorLines}
|
|
117
|
-
];
|
|
118
|
-
|
|
119
|
-
/** Returns true if the POSIX path is inside a bkit-managed mirror directory. */
|
|
120
|
-
function isMirrorPath(posixPath) {
|
|
121
|
-
return MIRROR_PATH_PREFIXES.some((prefix) => posixPath.startsWith(prefix));
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/** Basename patterns for quality-gate configs. */
|
|
125
|
-
const GATE_CONFIG_PATTERNS = [
|
|
126
|
-
${gateLines}
|
|
127
|
-
];
|
|
128
|
-
|
|
129
|
-
/** The consumer's template copies — reference copies, not the repo's gate config. */
|
|
130
|
-
const TEMPLATE_COPIES_PREFIX = ${JSON.stringify(TEMPLATE_COPIES_PREFIX)};
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Returns true if the file basename matches any gate-config pattern. Pass \`dogfood\` = true
|
|
134
|
-
* in bkit's own repo, where \`.bkit/templates/\` is the template source and stays guarded.
|
|
135
|
-
*/
|
|
136
|
-
function isGateConfig(posixPath, dogfood) {
|
|
137
|
-
const inTemplateCopies =
|
|
138
|
-
posixPath.startsWith(TEMPLATE_COPIES_PREFIX) || posixPath.includes("/" + TEMPLATE_COPIES_PREFIX);
|
|
139
|
-
if (inTemplateCopies && !dogfood) return false;
|
|
140
|
-
const base = posixPath.split("/").pop() || posixPath;
|
|
141
|
-
return GATE_CONFIG_PATTERNS.some((re) => re.test(base));
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
module.exports = {
|
|
145
|
-
MIRROR_PATH_PREFIXES,
|
|
146
|
-
isMirrorPath,
|
|
147
|
-
GATE_CONFIG_PATTERNS,
|
|
148
|
-
TEMPLATE_COPIES_PREFIX,
|
|
149
|
-
isGateConfig,
|
|
150
|
-
};
|
|
151
|
-
`;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// CLI: `node dist/shared/protected-paths.js` prints the generated content to stdout.
|
|
155
|
-
// This file compiles to ESM, so use import.meta.url for main-module detection.
|
|
156
|
-
if (process.argv[1]) {
|
|
157
|
-
try {
|
|
158
|
-
if (fs.realpathSync(fileURLToPath(import.meta.url)) === fs.realpathSync(process.argv[1])) {
|
|
159
|
-
process.stdout.write(generateGatePathsCjs());
|
|
160
|
-
}
|
|
161
|
-
} catch (_e) {
|
|
162
|
-
void _e; // realpathSync can fail on non-existent paths — skip silently
|
|
163
|
-
}
|
|
164
|
-
}
|
|
@@ -4,10 +4,15 @@
|
|
|
4
4
|
// a check name, or an app folder.
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
|
+
DEFAULT_CLOUD_AGENTS,
|
|
7
8
|
DEFAULT_ISSUE_TRACKER,
|
|
9
|
+
parseCloudAgents,
|
|
8
10
|
parseIssueTracker,
|
|
11
|
+
type CloudAgents,
|
|
9
12
|
type IssueTracker,
|
|
10
13
|
} from "../install/manifest.js";
|
|
14
|
+
import { isOpencodeProvider } from "../render/models.js";
|
|
15
|
+
import type { OpencodeProvider } from "./egress.js";
|
|
11
16
|
import { readPackageJson } from "./package-json.js";
|
|
12
17
|
|
|
13
18
|
export interface BkitConfig {
|
|
@@ -25,6 +30,18 @@ export interface BkitConfig {
|
|
|
25
30
|
githubProject: Record<string, unknown> | false | null;
|
|
26
31
|
/** CI lanes whose `skipped` conclusion refuses a ship merge; empty = the capstone's green decides. */
|
|
27
32
|
shipGateRequiredLanes: string[];
|
|
33
|
+
/** The opencode provider recorded on install; null = absent or not a supported provider. */
|
|
34
|
+
opencodeProvider: OpencodeProvider | null;
|
|
35
|
+
/** Every installed opencode provider, supported ones only; empty = none recorded. */
|
|
36
|
+
opencodeProviders: OpencodeProvider[];
|
|
37
|
+
/** The post-CI cloud-agent variant; `none` is both the default and the explicit opt-out. */
|
|
38
|
+
cloudAgents: CloudAgents;
|
|
39
|
+
/** `bkit.depUpdater` is `"none"`: silences the missing-dependency-updater advisory. */
|
|
40
|
+
depUpdaterOptOut: boolean;
|
|
41
|
+
/** `bkit.issueTracker` is present with any value, so `none` is a choice, not an undecided install. */
|
|
42
|
+
issueTrackerExplicit: boolean;
|
|
43
|
+
/** `bkit.cloudAgents` is present with any value, so `none` is a choice, not an undecided install. */
|
|
44
|
+
cloudAgentsExplicit: boolean;
|
|
28
45
|
}
|
|
29
46
|
|
|
30
47
|
export const CONFIG_DEFAULTS: Readonly<BkitConfig> = {
|
|
@@ -35,6 +52,12 @@ export const CONFIG_DEFAULTS: Readonly<BkitConfig> = {
|
|
|
35
52
|
issueTracker: DEFAULT_ISSUE_TRACKER,
|
|
36
53
|
githubProject: null,
|
|
37
54
|
shipGateRequiredLanes: [],
|
|
55
|
+
opencodeProvider: null,
|
|
56
|
+
opencodeProviders: [],
|
|
57
|
+
cloudAgents: DEFAULT_CLOUD_AGENTS,
|
|
58
|
+
depUpdaterOptOut: false,
|
|
59
|
+
issueTrackerExplicit: false,
|
|
60
|
+
cloudAgentsExplicit: false,
|
|
38
61
|
};
|
|
39
62
|
|
|
40
63
|
const nonEmptyString = (v: unknown): v is string => typeof v === "string" && v.trim() !== "";
|
|
@@ -51,6 +74,8 @@ export function readBkitConfig(root: string): BkitConfig {
|
|
|
51
74
|
const copy = worktree.copy;
|
|
52
75
|
const project = bkit.githubProject;
|
|
53
76
|
const lanes = bkit.shipGateRequiredLanes;
|
|
77
|
+
const provider = bkit.opencodeProvider;
|
|
78
|
+
const providers = bkit.opencodeProviders;
|
|
54
79
|
return {
|
|
55
80
|
ciWorkflow: nonEmptyString(bkit.ciWorkflow) ? bkit.ciWorkflow : CONFIG_DEFAULTS.ciWorkflow,
|
|
56
81
|
capstoneJob: nonEmptyString(bkit.capstoneJob) ? bkit.capstoneJob : CONFIG_DEFAULTS.capstoneJob,
|
|
@@ -68,5 +93,16 @@ export function readBkitConfig(root: string): BkitConfig {
|
|
|
68
93
|
? (project as Record<string, unknown>)
|
|
69
94
|
: null,
|
|
70
95
|
shipGateRequiredLanes: Array.isArray(lanes) ? lanes.filter(nonEmptyString) : [],
|
|
96
|
+
opencodeProvider:
|
|
97
|
+
typeof provider === "string" && isOpencodeProvider(provider) ? provider : null,
|
|
98
|
+
opencodeProviders: Array.isArray(providers)
|
|
99
|
+
? providers.filter(
|
|
100
|
+
(v): v is OpencodeProvider => typeof v === "string" && isOpencodeProvider(v),
|
|
101
|
+
)
|
|
102
|
+
: [],
|
|
103
|
+
cloudAgents: parseCloudAgents(bkit.cloudAgents) ?? CONFIG_DEFAULTS.cloudAgents,
|
|
104
|
+
depUpdaterOptOut: bkit.depUpdater === "none",
|
|
105
|
+
issueTrackerExplicit: bkit.issueTracker !== undefined,
|
|
106
|
+
cloudAgentsExplicit: bkit.cloudAgents !== undefined,
|
|
71
107
|
};
|
|
72
108
|
}
|
|
@@ -17,4 +17,10 @@ export const TIMEOUTS = {
|
|
|
17
17
|
SHIP_DEV_LOCK_STALE_S: 900,
|
|
18
18
|
/** Seconds to contend for `.dev.lock` before giving up. */
|
|
19
19
|
SHIP_DEV_LOCK_ACQUIRE_DEADLINE_S: 600,
|
|
20
|
+
/** Seconds a registry answer for the newest published bkit is reused before asking again. */
|
|
21
|
+
BKIT_LATEST_CACHE_S: 86400,
|
|
22
|
+
/** Seconds a failed registry lookup is remembered, so an offline run does not wait on every call. */
|
|
23
|
+
BKIT_LATEST_RETRY_S: 3600,
|
|
24
|
+
/** Seconds the registry lookup may take before it counts as failed. */
|
|
25
|
+
BKIT_LATEST_LOOKUP_TIMEOUT_S: 5,
|
|
20
26
|
} as const;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// --- Shell detection: identical in every host's guardrails hook (bkit renders it from
|
|
2
2
|
// one source). Needs `fs` and `path` in scope; the host's own code above declares them.
|
|
3
3
|
|
|
4
|
-
/** Wrappers that precede the real command; skipped when finding a
|
|
4
|
+
/** Wrappers that precede the real command; skipped when finding a command's program. */
|
|
5
5
|
const CMD_WRAPPERS = new Set(["sudo", "env", "time", "nohup", "nice", "command", "exec", "xargs"]);
|
|
6
6
|
|
|
7
7
|
/** Split a command line into pipeline / list segments. */
|
|
@@ -13,28 +13,95 @@ function shellSegments(cmd) {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* A token that only appears as an argument (`grep -n 'curl' file`,
|
|
20
|
-
* `sed -n '/sed -i/p' notes.md`) is not the segment's program.
|
|
16
|
+
* A segment's words: single / double quotes group and are dropped, a backslash escapes
|
|
17
|
+
* the next character, an unquoted `#` at a word start ends the segment (comment). An
|
|
18
|
+
* unterminated quote runs to the end of the segment.
|
|
21
19
|
*/
|
|
22
|
-
function
|
|
23
|
-
const words =
|
|
20
|
+
function shellWords(seg) {
|
|
21
|
+
const words = [];
|
|
22
|
+
let cur = "";
|
|
23
|
+
let started = false;
|
|
24
|
+
let quote = "";
|
|
25
|
+
for (let i = 0; i < seg.length; i++) {
|
|
26
|
+
const ch = seg[i];
|
|
27
|
+
if (quote) {
|
|
28
|
+
if (ch === quote) quote = "";
|
|
29
|
+
else if (ch === "\\" && quote === '"' && i + 1 < seg.length) cur += seg[++i];
|
|
30
|
+
else cur += ch;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (ch === "#" && !started) break;
|
|
34
|
+
if (ch === "'" || ch === '"') {
|
|
35
|
+
quote = ch;
|
|
36
|
+
started = true;
|
|
37
|
+
} else if (ch === "\\" && i + 1 < seg.length) {
|
|
38
|
+
cur += seg[++i];
|
|
39
|
+
started = true;
|
|
40
|
+
} else if (/\s/.test(ch)) {
|
|
41
|
+
if (started) words.push(cur);
|
|
42
|
+
cur = "";
|
|
43
|
+
started = false;
|
|
44
|
+
} else {
|
|
45
|
+
cur += ch;
|
|
46
|
+
started = true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (started) words.push(cur);
|
|
50
|
+
return words;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The words a segment runs: subshell punctuation, `VAR=val` and wrappers skipped. */
|
|
54
|
+
function commandWords(seg) {
|
|
55
|
+
const words = shellWords(seg.replace(/^(?:\$\(|[({`!\s])+/, "").replace(/[)}`\s]+$/, ""));
|
|
24
56
|
let i = 0;
|
|
25
57
|
while (
|
|
26
58
|
i < words.length &&
|
|
27
59
|
(/^[A-Za-z_][A-Za-z0-9_]*=/.test(words[i]) || CMD_WRAPPERS.has(words[i]))
|
|
28
60
|
)
|
|
29
61
|
i++;
|
|
30
|
-
return
|
|
62
|
+
return words.slice(i);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const SHELLS = new Set(["sh", "bash", "zsh", "dash", "ksh"]);
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Every command line the input runs: each list / pipeline segment, the script of a
|
|
69
|
+
* `sh -c '…'`, and the body of each `$(…)` / backtick substitution, recursively.
|
|
70
|
+
*/
|
|
71
|
+
function commandLines(cmd, depth = 0) {
|
|
72
|
+
const lines = [];
|
|
73
|
+
if (depth < 3) {
|
|
74
|
+
for (const m of String(cmd).matchAll(/\$\(([^()]*)\)|`([^`]*)`/g)) {
|
|
75
|
+
lines.push(...commandLines(m[1] ?? m[2] ?? "", depth + 1));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
for (const seg of shellSegments(cmd)) {
|
|
79
|
+
lines.push(seg);
|
|
80
|
+
if (depth >= 3) continue;
|
|
81
|
+
const words = commandWords(seg);
|
|
82
|
+
const head = (words[0] || "").replace(/^.*\//, "");
|
|
83
|
+
if (!SHELLS.has(head)) continue;
|
|
84
|
+
const c = words.findIndex((w, i) => i > 0 && /^-[a-z]*c$/.test(w));
|
|
85
|
+
if (c > 0 && words[c + 1]) lines.push(...commandLines(words[c + 1], depth + 1));
|
|
86
|
+
}
|
|
87
|
+
return lines;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The program a command line runs, path stripped (`/usr/bin/curl` -> `curl`). */
|
|
91
|
+
function commandProgram(words) {
|
|
92
|
+
return (words[0] || "").replace(/^.*\//, "");
|
|
31
93
|
}
|
|
32
94
|
|
|
33
|
-
/**
|
|
95
|
+
/**
|
|
96
|
+
* True when some command line actually INVOKES curl or wget, including inside
|
|
97
|
+
* `sh -c '…'`, `$(…)`, backticks and `( … )`.
|
|
98
|
+
*
|
|
99
|
+
* A token that only appears as an argument (`grep -n 'curl' file`) is not a program.
|
|
100
|
+
*/
|
|
34
101
|
function usesFetch(cmd) {
|
|
35
|
-
return
|
|
36
|
-
const
|
|
37
|
-
return
|
|
102
|
+
return commandLines(cmd).some((line) => {
|
|
103
|
+
const p = commandProgram(commandWords(line));
|
|
104
|
+
return p === "curl" || p === "wget";
|
|
38
105
|
});
|
|
39
106
|
}
|
|
40
107
|
|
|
@@ -42,6 +109,48 @@ function usesFetch(cmd) {
|
|
|
42
109
|
const SOURCE_EXT_RE =
|
|
43
110
|
/\.(ts|tsx|js|jsx|cjs|mjs|json|md|sh|bash|py|rb|go|rs|java|css|scss|html|ya?ml|toml|sql)$/i;
|
|
44
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Targets of every unquoted `>` / `>>` redirect in a command line. A `>` inside single
|
|
114
|
+
* or double quotes is text (`rg 'a > b.ts'`), a backslash-escaped `>` is a literal, and
|
|
115
|
+
* `2>`, `&>` and `>&` forms (fd redirects) are not file targets.
|
|
116
|
+
*/
|
|
117
|
+
function redirectTargets(text) {
|
|
118
|
+
const targets = [];
|
|
119
|
+
let quote = "";
|
|
120
|
+
for (let i = 0; i < text.length; i++) {
|
|
121
|
+
const ch = text[i];
|
|
122
|
+
if (quote) {
|
|
123
|
+
if (ch === quote) quote = "";
|
|
124
|
+
else if (ch === "\\" && quote === '"') i++;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (ch === "'" || ch === '"') quote = ch;
|
|
128
|
+
else if (ch === "\\") i++;
|
|
129
|
+
else if (ch === ">") {
|
|
130
|
+
const prev = text[i - 1] ?? "";
|
|
131
|
+
let j = i + 1;
|
|
132
|
+
if (text[j] === ">") j++;
|
|
133
|
+
const fdOrAmp = /[>&\d]/.test(prev);
|
|
134
|
+
i = j - 1;
|
|
135
|
+
if (fdOrAmp) continue;
|
|
136
|
+
while (/\s/.test(text[j] ?? "")) j++;
|
|
137
|
+
const open = text[j];
|
|
138
|
+
let target = "";
|
|
139
|
+
if (open === '"' || open === "'") {
|
|
140
|
+
const end = text.indexOf(open, j + 1);
|
|
141
|
+
target = end < 0 ? "" : text.slice(j + 1, end);
|
|
142
|
+
i = end < 0 ? text.length : end;
|
|
143
|
+
} else {
|
|
144
|
+
const m = /^[^\s;|&<>]+/.exec(text.slice(j));
|
|
145
|
+
target = m ? m[0] : "";
|
|
146
|
+
i = j + target.length - 1;
|
|
147
|
+
}
|
|
148
|
+
if (target.trim()) targets.push(target.trim());
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return targets;
|
|
152
|
+
}
|
|
153
|
+
|
|
45
154
|
/**
|
|
46
155
|
* Detect a shell command being used as an edit channel. Returns a list of human
|
|
47
156
|
* descriptions, empty when the command edits nothing.
|
|
@@ -52,25 +161,27 @@ const SOURCE_EXT_RE =
|
|
|
52
161
|
*/
|
|
53
162
|
function shellEditTargets(cmd) {
|
|
54
163
|
const hits = [];
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
164
|
+
const lines = commandLines(cmd);
|
|
165
|
+
for (const line of lines) {
|
|
166
|
+
const words = commandWords(line);
|
|
167
|
+
const program = commandProgram(words);
|
|
168
|
+
const args = words.slice(1);
|
|
169
|
+
if ((program === "sed" || program === "perl") && args.some((w) => /^-i(?:\..*)?$/.test(w))) {
|
|
58
170
|
hits.push("in-place sed/perl (-i)");
|
|
59
171
|
}
|
|
60
|
-
if (
|
|
172
|
+
if (program === "awk" && args.some((w, i) => w === "-i" && args[i + 1] === "inplace")) {
|
|
173
|
+
hits.push("awk -i inplace");
|
|
174
|
+
}
|
|
61
175
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (/\.(log|bak|tmp|out|err|orig)$/i.test(target)) continue;
|
|
72
|
-
if (!SOURCE_EXT_RE.test(target)) continue;
|
|
73
|
-
hits.push(`redirect into ${target}`);
|
|
176
|
+
for (const text of [String(cmd), ...lines]) {
|
|
177
|
+
for (const target of redirectTargets(text)) {
|
|
178
|
+
// Scratch and env sinks — never a source edit.
|
|
179
|
+
if (target.startsWith("$") || target.startsWith("&")) continue;
|
|
180
|
+
if (/^\/(dev|tmp|var\/folders|var\/tmp)\//.test(target)) continue;
|
|
181
|
+
if (/\.(log|bak|tmp|out|err|orig)$/i.test(target)) continue;
|
|
182
|
+
if (!SOURCE_EXT_RE.test(target)) continue;
|
|
183
|
+
hits.push(`redirect into ${target}`);
|
|
184
|
+
}
|
|
74
185
|
}
|
|
75
186
|
return [...new Set(hits)];
|
|
76
187
|
}
|
|
@@ -86,18 +197,52 @@ function shellEditAdvisory(hits) {
|
|
|
86
197
|
);
|
|
87
198
|
}
|
|
88
199
|
|
|
200
|
+
/** Repo-relative path of the install-written network allowlist every host's hook reads. */
|
|
201
|
+
const NETWORK_ALLOWLIST_FILE = path.join(".bkit", "allowlist.json");
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Directories a hook call names, most authoritative first: the workspace roots (Cursor
|
|
205
|
+
* `workspace_roots`; Antigravity `workspacePaths`, carried over by its payload adapter),
|
|
206
|
+
* the payload `cwd` (Claude, Codex, Cursor), then the hook process's own cwd — which on
|
|
207
|
+
* Antigravity is the plugin dir, not the repo.
|
|
208
|
+
*/
|
|
209
|
+
function hookDirs(payload) {
|
|
210
|
+
const p = payload && typeof payload === "object" ? payload : {};
|
|
211
|
+
const roots = Array.isArray(p.workspace_roots) ? p.workspace_roots : [];
|
|
212
|
+
return [...roots, p.cwd, process.cwd()].filter((d) => typeof d === "string" && d !== "");
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* The network allowlist file for a hook call: walking up from each of `dirs` in turn,
|
|
217
|
+
* the first `.bkit/allowlist.json` found. A directory holding `.git` (the repo root)
|
|
218
|
+
* ends that walk. null when none is found.
|
|
219
|
+
*/
|
|
220
|
+
function findNetworkAllowlist(dirs) {
|
|
221
|
+
for (const start of dirs) {
|
|
222
|
+
let dir = path.resolve(start);
|
|
223
|
+
for (;;) {
|
|
224
|
+
const file = path.join(dir, NETWORK_ALLOWLIST_FILE);
|
|
225
|
+
if (fs.existsSync(file)) return file;
|
|
226
|
+
const parent = path.dirname(dir);
|
|
227
|
+
if (parent === dir || fs.existsSync(path.join(dir, ".git"))) break;
|
|
228
|
+
dir = parent;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
|
|
89
234
|
/**
|
|
90
|
-
* Hosts come from `.
|
|
91
|
-
*
|
|
92
|
-
* `allowed-domains`); every host's hook reads it
|
|
93
|
-
*
|
|
94
|
-
* host is treated as unknown.
|
|
235
|
+
* Hosts come from `.bkit/allowlist.json`, the one install-written artifact carrying the
|
|
236
|
+
* resolved network allowlist (the shipped egress registry union the consumer's
|
|
237
|
+
* `allowed-domains`); every host's hook reads it, found from the hook call's
|
|
238
|
+
* directories (`hookDirs`). There is NO hardcoded fallback list: absent or unreadable,
|
|
239
|
+
* this returns empty and every host is treated as unknown.
|
|
95
240
|
*/
|
|
96
|
-
function loadNetworkAllowlistBases() {
|
|
241
|
+
function loadNetworkAllowlistBases(dirs) {
|
|
97
242
|
const bases = new Set();
|
|
98
243
|
try {
|
|
99
|
-
const p =
|
|
100
|
-
if (
|
|
244
|
+
const p = findNetworkAllowlist(dirs);
|
|
245
|
+
if (p) {
|
|
101
246
|
const doc = JSON.parse(fs.readFileSync(p, "utf8"));
|
|
102
247
|
const domains = Array.isArray(doc.domains) ? doc.domains : [];
|
|
103
248
|
for (const d of domains) {
|
|
@@ -144,11 +289,12 @@ function hostMatchesBase(host, base) {
|
|
|
144
289
|
* True when EVERY URL in the command targets an allowlisted host.
|
|
145
290
|
*
|
|
146
291
|
* Only each URL's host is consulted, never the rest of the command string (query
|
|
147
|
-
* params, headers). No parseable URL, or any host off the list → false.
|
|
292
|
+
* params, headers). No parseable URL, or any host off the list → false. `dirs` locate
|
|
293
|
+
* the allowlist (`hookDirs`).
|
|
148
294
|
*/
|
|
149
|
-
function curlWgetHostAllowed(cmd) {
|
|
295
|
+
function curlWgetHostAllowed(cmd, dirs) {
|
|
150
296
|
const hosts = extractUrlHosts(cmd);
|
|
151
297
|
if (hosts.length === 0) return false;
|
|
152
|
-
const bases = loadNetworkAllowlistBases();
|
|
298
|
+
const bases = loadNetworkAllowlistBases(dirs);
|
|
153
299
|
return hosts.every((h) => [...bases].some((b) => hostMatchesBase(h, b)));
|
|
154
300
|
}
|