@cbartens/bkit 6.1.1 → 6.2.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 +14 -12
- package/.bkit/core/.agents/docs.md +1 -11
- package/.bkit/core/.agents/plugins/bkit/hooks/bkit-gateguard.cjs +30 -9
- package/.bkit/core/.agents/plugins/bkit/hooks/bkit-guardrails.cjs +25 -27
- package/.bkit/core/.agents/rules.md +22 -9
- package/.bkit/core/.bkit/README.md +13 -11
- package/.bkit/core/.bkit/authoring.md +58 -13
- package/.bkit/core/.bkit/cli.md +42 -32
- package/.bkit/core/.bkit/cloud.md +93 -30
- package/.bkit/core/.bkit/install.md +55 -16
- package/.bkit/core/.bkit/jsonl.md +24 -7
- package/.bkit/core/.bkit/pipeline.md +8 -8
- package/.bkit/core/.bkit/prompts.md +160 -43
- package/.bkit/core/.bkit/providers.md +97 -36
- package/.bkit/core/.bkit/templates.md +162 -34
- package/.bkit/core/.bkit/trackers.md +39 -6
- package/.bkit/core/.bkit/workflows.md +344 -136
- package/.bkit/core/.claude/hooks/bkit-guardrails.cjs +50 -27
- package/.bkit/core/.claude/hooks/bkit-preflight.sh +11 -11
- package/.bkit/core/.codex/hooks/bkit-gateguard.cjs +13 -8
- package/.bkit/core/.codex/hooks/bkit-guardrails.cjs +14 -25
- package/.bkit/core/.cursor/hooks/bkit-guardrails.cjs +20 -9
- package/.bkit/core/.cursor/hooks/bkit-preflight.sh +8 -8
- package/.bkit/core/.opencode/plugin/bkit-gateguard.js +14 -4
- package/.bkit/core/.opencode/plugin/bkit-guardrails.js +114 -0
- package/.bkit/core/docs/templates/bkit-audit-accessibility.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-adoption.md +30 -6
- package/.bkit/core/docs/templates/bkit-audit-agents.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-analytics.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-annotations.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-app-performance.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-app-store.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-architecture.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +2 -2
- package/.bkit/core/docs/templates/bkit-audit-config.md +3 -2
- package/.bkit/core/docs/templates/bkit-audit-cost.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-coverage.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-database.md +3 -3
- package/.bkit/core/docs/templates/bkit-audit-dead-code.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-deferrals.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-dependencies.md +3 -3
- package/.bkit/core/docs/templates/bkit-audit-documentation.md +32 -2
- package/.bkit/core/docs/templates/bkit-audit-duplication.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-failures.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-flakes.md +2 -2
- package/.bkit/core/docs/templates/bkit-audit-gates.md +5 -3
- package/.bkit/core/docs/templates/bkit-audit-issues.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-llm.md +2 -2
- package/.bkit/core/docs/templates/bkit-audit-logs.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-models.md +2 -2
- package/.bkit/core/docs/templates/bkit-audit-privacy.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-prompts.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-red-team.md +2 -2
- package/.bkit/core/docs/templates/bkit-audit-reliability.md +3 -2
- package/.bkit/core/docs/templates/bkit-audit-repo.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-security.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-slop.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-testing.md +3 -2
- package/.bkit/core/docs/templates/bkit-audit-usability.md +1 -1
- package/.bkit/core/docs/templates/bkit-plan.md +38 -8
- package/.bkit/core/engine/checks/after/auth.ts +118 -47
- package/.bkit/core/engine/checks/after/github.ts +89 -37
- package/.bkit/core/engine/checks/after/index.ts +15 -3
- package/.bkit/core/engine/checks/after/tools.ts +245 -1
- package/.bkit/core/engine/checks/before/files.ts +59 -1
- package/.bkit/core/engine/checks/before/index.ts +8 -0
- package/.bkit/core/engine/checks/status-holes.ts +20 -26
- package/.bkit/core/engine/checks/tips/catalogue.ts +107 -10
- package/.bkit/core/engine/checks/tips/detect.ts +36 -3
- package/.bkit/core/engine/checks/tips/index.ts +1 -1
- package/.bkit/core/engine/cli.ts +13 -13
- package/.bkit/core/engine/commands/ci/ci.ts +64 -11
- package/.bkit/core/engine/commands/ci/push-gate.ts +101 -43
- package/.bkit/core/engine/commands/install/install.ts +28 -25
- package/.bkit/core/engine/commands/install/uninstall.ts +42 -30
- package/.bkit/core/engine/commands/install/upgrade.ts +14 -2
- package/.bkit/core/engine/commands/land.ts +2 -3
- package/.bkit/core/engine/commands/lib.ts +394 -39
- package/.bkit/core/engine/commands/registry.ts +1 -1
- package/.bkit/core/engine/commands/workflow/branches.ts +351 -78
- package/.bkit/core/engine/commands/workflow/challenge.ts +63 -14
- package/.bkit/core/engine/commands/workflow/context.ts +71 -10
- package/.bkit/core/engine/commands/workflow/counters.ts +298 -23
- package/.bkit/core/engine/commands/workflow/decisions.ts +260 -125
- package/.bkit/core/engine/commands/workflow/disk.ts +2 -1
- package/.bkit/core/engine/commands/workflow/feature-base.ts +66 -0
- package/.bkit/core/engine/commands/workflow/issues.ts +312 -17
- package/.bkit/core/engine/commands/workflow/junit.ts +204 -0
- package/.bkit/core/engine/commands/workflow/ledgers.ts +904 -99
- package/.bkit/core/engine/commands/workflow/locks.ts +186 -29
- package/.bkit/core/engine/commands/workflow/loops.ts +87 -0
- package/.bkit/core/engine/commands/workflow/open-decision.ts +251 -0
- package/.bkit/core/engine/commands/workflow/plan-blocks.ts +8 -0
- package/.bkit/core/engine/commands/workflow/plans.ts +1 -1
- package/.bkit/core/engine/commands/workflow/prs.ts +311 -16
- package/.bkit/core/engine/commands/workflow/repo.ts +1 -1
- package/.bkit/core/engine/commands/workflow/run-facts.ts +6 -0
- package/.bkit/core/engine/commands/workflow/runs.ts +877 -174
- package/.bkit/core/engine/commands/workflow/runtime.ts +12 -4
- package/.bkit/core/engine/commands/workflow/status.ts +324 -11
- package/.bkit/core/engine/commands/workflow/step-table.ts +41 -15
- package/.bkit/core/engine/commands/workflow/steps.ts +604 -29
- package/.bkit/core/engine/commands/workflow/summary-findings.ts +1 -1
- package/.bkit/core/engine/commands/workflow/summary.ts +314 -8
- package/.bkit/core/engine/commands/workflow/tasks.ts +400 -27
- package/.bkit/core/engine/commands/workflow/tests-base.ts +319 -0
- package/.bkit/core/engine/commands/workflow/tests-changed.ts +138 -74
- package/.bkit/core/engine/commands/workflow/tests-jump.ts +93 -0
- package/.bkit/core/engine/commands/workflow/tests.ts +815 -182
- package/.bkit/core/engine/commands/workflow/tracker.ts +1134 -137
- package/.bkit/core/engine/commands/workflow/workflows.ts +100 -72
- package/.bkit/core/engine/commands/workflow/worktrees.ts +421 -57
- package/.bkit/core/engine/install/cloud-env.ts +38 -10
- package/.bkit/core/engine/install/managed-block.ts +105 -0
- package/.bkit/core/engine/install/manifest.ts +7 -1
- package/.bkit/core/engine/install/modules/claude.ts +6 -2
- package/.bkit/core/engine/install/modules/cloud.ts +84 -95
- package/.bkit/core/engine/install/modules/codex.ts +10 -2
- package/.bkit/core/engine/install/modules/core.ts +148 -14
- package/.bkit/core/engine/install/modules/opencode.ts +18 -23
- package/.bkit/core/engine/install/network-allowlist.ts +8 -3
- package/.bkit/core/engine/install/project-docs.ts +650 -0
- package/.bkit/core/engine/install/template-copies.ts +58 -5
- package/.bkit/core/engine/install/write.ts +128 -7
- package/.bkit/core/engine/ledgers/journal.ts +18 -10
- package/.bkit/core/engine/ledgers/migrate.ts +20 -8
- package/.bkit/core/engine/ledgers/status.ts +604 -8
- package/.bkit/core/engine/ledgers/telemetry.ts +115 -13
- package/.bkit/core/engine/render/trackers.ts +3 -1
- package/.bkit/core/engine/shared/package-manager.ts +7 -3
- package/.bkit/core/engine/shared/settings.ts +12 -1
- package/.bkit/core/engine/shared/text.ts +14 -0
- package/.bkit/core/engine/tools/instructions-sources.ts +1 -0
- package/.bkit/core/engine/tools/instructions.ts +116 -20
- package/.bkit/core/hooks/antigravity-hook.js +20 -4
- package/.bkit/core/hooks/gateguard-edit-payload.js +8 -5
- package/.bkit/core/hooks/gateguard-engine.js +249 -23
- package/.bkit/core/hooks/guardrails-deny.js +167 -0
- package/.bkit/core/hooks/guardrails-read.js +3 -3
- package/.bkit/core/hooks/guardrails-shell.js +1122 -167
- package/.bkit/core/hooks/guardrails-tiers.js +247 -176
- package/.bkit/core/hooks/preflight-tracker.sh +219 -0
- package/.bkit/core/prompts/bkit-audit-generate.md +23 -6
- package/.bkit/core/prompts/bkit-build-challenge-1.md +5 -4
- package/.bkit/core/prompts/bkit-build-challenge-2.md +6 -5
- package/.bkit/core/prompts/bkit-build-install-skills.md +2 -2
- package/.bkit/core/prompts/bkit-build-plan-convert.md +21 -7
- package/.bkit/core/prompts/bkit-build-plan-current.md +5 -4
- package/.bkit/core/prompts/bkit-build-plan-gaps-remediate.md +22 -17
- package/.bkit/core/prompts/bkit-build-plan-tasks.md +16 -12
- package/.bkit/core/prompts/bkit-build-plan-tests.md +14 -10
- package/.bkit/core/prompts/bkit-build-plan-verify.md +21 -8
- package/.bkit/core/prompts/bkit-debug-abort-handover.md +10 -5
- package/.bkit/core/prompts/bkit-debug-failure-diagnose.md +22 -6
- package/.bkit/core/prompts/bkit-debug-failure-remediate.md +19 -3
- package/.bkit/core/prompts/bkit-debug-failure-reproduce.md +22 -6
- package/.bkit/core/prompts/bkit-debug-failure-soak.md +10 -7
- package/.bkit/core/prompts/bkit-design-brainstorm-ideate-1.md +3 -3
- package/.bkit/core/prompts/bkit-design-brainstorm-ideate-2.md +4 -4
- package/.bkit/core/prompts/bkit-design-brainstorm-ideate-3.md +3 -3
- package/.bkit/core/prompts/bkit-design-generate.md +6 -4
- package/.bkit/core/prompts/bkit-design-organise.md +4 -3
- package/.bkit/core/prompts/bkit-design-review-1.md +5 -4
- package/.bkit/core/prompts/bkit-design-review-2.md +6 -5
- package/.bkit/core/prompts/bkit-design-spike.md +4 -3
- package/.bkit/core/prompts/bkit-design-update.md +6 -4
- package/.bkit/core/prompts/bkit-plan-generate.md +35 -14
- package/.bkit/core/prompts/bkit-plan-review-1.md +9 -7
- package/.bkit/core/prompts/bkit-plan-review-2.md +9 -7
- package/.bkit/core/prompts/bkit-plan-scope-check.md +8 -6
- package/.bkit/core/prompts/bkit-plan-update.md +22 -8
- package/.bkit/core/prompts/bkit-ship-conflict-resolve.md +11 -8
- package/.bkit/core/prompts/bkit-ship-deferred-sweep.md +9 -5
- package/.bkit/core/prompts/bkit-ship-update-docs.md +26 -4
- package/.bkit/core/prompts/bkit-utility-compress-markdown.md +3 -3
- package/.bkit/core/prompts/bkit-utility-update-decisions.md +10 -7
- package/.bkit/core/prompts/bkit-utility-update-deferrals.md +8 -5
- package/.bkit/core/prompts/bkit-utility-update-documentation.md +31 -7
- package/.bkit/core/prompts/bkit-utility-update-failures.md +8 -5
- package/.bkit/core/prompts/bkit-utility-update-knowledge.md +10 -7
- package/.bkit/core/prompts/bkit-utility-update-roadmap.md +4 -4
- package/.bkit/core/prompts/bkit-utility-update-tracker.md +4 -4
- package/.bkit/core/workflows/bkit-auto.md +23 -11
- package/.bkit/core/workflows/bkit-build.md +331 -100
- package/.bkit/core/workflows/bkit-debug.md +135 -64
- package/.bkit/core/workflows/bkit-design.md +58 -32
- package/.bkit/core/workflows/bkit-plan.md +73 -45
- package/.bkit/core/workflows/bkit-ship.md +233 -167
- package/.bkit/shared/.agents/plugins/bkit/hooks.json +1 -1
- package/.bkit/shared/.bkit/.env.example +5 -0
- package/.bkit/shared/.claude/bkit-cloud.md +7 -7
- package/.bkit/shared/.claude/settings.json +5 -1
- package/.bkit/shared/.cursor/bkit-cloud.md +1 -1
- package/.bkit/shared/.cursor/hooks.json +1 -1
- package/.bkit/shared/.opencode/opencode.json +11 -2
- package/.bkit/templates/.claude/hooks/bkit-cloud-bootstrap.sh +27 -0
- package/.bkit/templates/.cursor/Dockerfile +7 -7
- package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-idea.yml +1 -1
- package/.bkit/templates/.github/dependabot.yml +5 -0
- package/.bkit/templates/.github/renovate.json5 +5 -3
- package/.bkit/templates/.github/workflows/bkit-ci.yml +11 -11
- package/.bkit/templates/.github/workflows/bkit-cloud.yml +525 -161
- package/.bkit/templates/.github/workflows/bkit-renovate.yml +2 -2
- package/.bkit/templates/.husky/pre-push +123 -6
- package/.bkit/templates/context/bkit-serena.md +1 -1
- package/.bkit/templates/docs/architecture.md +98 -0
- package/.bkit/templates/docs/capabilities.md +33 -37
- package/.bkit/templates/docs/components.md +142 -0
- package/.bkit/templates/docs/data-schema.md +87 -0
- package/.bkit/{shared → templates}/docs/deployments.md +128 -142
- package/.bkit/templates/docs/design.md +117 -0
- package/.bkit/templates/docs/noise.md +54 -0
- package/.bkit/templates/docs/observability.md +99 -0
- package/.bkit/templates/docs/security.md +137 -0
- package/.bkit/templates/docs/setup.md +93 -0
- package/.bkit/templates/docs/technology.md +70 -0
- package/.bkit/{shared → templates}/docs/testing.md +200 -87
- package/.bkit/templates/scripts/ci/bkit-machine-lock.sh +511 -103
- package/.bkit/templates/scripts/ci/bkit-test-awake.mjs +228 -35
- package/.bkit/templates/scripts/ci/bkit-test-awake.test.mjs +270 -2
- package/.bkit/templates/scripts/graphify/bkit-graphify-graphml.py +1 -1
- package/.bkit/templates/scripts/graphify/bkit-graphify-rollup.py +92 -63
- package/.bkit/templates/scripts/graphify/bkit-graphify.sh +59 -11
- package/.bkit/templates/slop-scan.config.json +2 -0
- package/CHANGELOG.md +64 -0
- package/DETAILS.md +24 -19
- package/README.md +1 -1
- package/dist/checks/after/auth.js +114 -46
- package/dist/checks/after/github.js +77 -35
- package/dist/checks/after/index.js +12 -3
- package/dist/checks/after/tools.js +224 -1
- package/dist/checks/before/files.js +59 -1
- package/dist/checks/before/index.js +7 -1
- package/dist/checks/status-holes.js +20 -21
- package/dist/checks/tips/catalogue.js +99 -10
- package/dist/checks/tips/detect.js +35 -3
- package/dist/checks/tips/index.js +1 -1
- package/dist/cli.js +13 -13
- package/dist/commands/ci/ci.js +56 -12
- package/dist/commands/ci/push-gate.js +79 -44
- package/dist/commands/install/install.js +23 -22
- package/dist/commands/install/uninstall.js +36 -30
- package/dist/commands/install/upgrade.js +10 -2
- package/dist/commands/land.js +2 -3
- package/dist/commands/lib.js +323 -25
- package/dist/commands/workflow/branches.js +312 -72
- package/dist/commands/workflow/challenge.js +66 -13
- package/dist/commands/workflow/context.js +46 -10
- package/dist/commands/workflow/counters.js +231 -23
- package/dist/commands/workflow/decisions.js +221 -106
- package/dist/commands/workflow/disk.js +2 -1
- package/dist/commands/workflow/feature-base.js +60 -0
- package/dist/commands/workflow/issues.js +243 -15
- package/dist/commands/workflow/junit.js +137 -0
- package/dist/commands/workflow/ledgers.js +726 -112
- package/dist/commands/workflow/locks.js +150 -29
- package/dist/commands/workflow/loops.js +67 -0
- package/dist/commands/workflow/open-decision.js +199 -0
- package/dist/commands/workflow/plan-blocks.js +6 -0
- package/dist/commands/workflow/plans.js +1 -1
- package/dist/commands/workflow/prs.js +272 -16
- package/dist/commands/workflow/repo.js +1 -1
- package/dist/commands/workflow/run-facts.js +6 -0
- package/dist/commands/workflow/runs.js +747 -155
- package/dist/commands/workflow/runtime.js +8 -4
- package/dist/commands/workflow/status.js +259 -13
- package/dist/commands/workflow/step-table.js +41 -15
- package/dist/commands/workflow/steps.js +530 -26
- package/dist/commands/workflow/summary-findings.js +1 -1
- package/dist/commands/workflow/summary.js +289 -8
- package/dist/commands/workflow/tasks.js +294 -27
- package/dist/commands/workflow/tests-base.js +266 -0
- package/dist/commands/workflow/tests-changed.js +130 -56
- package/dist/commands/workflow/tests-jump.js +77 -0
- package/dist/commands/workflow/tests.js +608 -131
- package/dist/commands/workflow/tracker.js +920 -112
- package/dist/commands/workflow/workflows.js +80 -59
- package/dist/commands/workflow/worktrees.js +387 -58
- package/dist/install/cloud-env.js +32 -10
- package/dist/install/managed-block.js +101 -0
- package/dist/install/manifest.js +7 -1
- package/dist/install/modules/claude.js +6 -2
- package/dist/install/modules/cloud.js +73 -86
- package/dist/install/modules/codex.js +9 -2
- package/dist/install/modules/core.js +133 -14
- package/dist/install/modules/opencode.js +18 -23
- package/dist/install/network-allowlist.js +8 -3
- package/dist/install/project-docs.js +551 -0
- package/dist/install/template-copies.js +55 -5
- package/dist/install/write.js +117 -5
- package/dist/ledgers/journal.js +10 -8
- package/dist/ledgers/migrate.js +20 -9
- package/dist/ledgers/status.js +461 -8
- package/dist/ledgers/telemetry.js +71 -13
- package/dist/render/trackers.js +3 -1
- package/dist/shared/package-manager.js +7 -2
- package/dist/shared/settings.js +8 -0
- package/dist/shared/text.js +13 -0
- package/dist/tools/instructions-sources.js +1 -0
- package/dist/tools/instructions.js +97 -24
- package/package.json +22 -15
- package/.bkit/core/hooks/preflight-linear.sh +0 -73
- package/.bkit/shared/docs/architecture.md +0 -16
- package/.bkit/shared/docs/data-schema.md +0 -16
- package/.bkit/shared/docs/design.md +0 -38
- package/.bkit/shared/docs/noise.md +0 -20
- package/.bkit/shared/docs/observability.md +0 -22
- package/.bkit/shared/docs/security.md +0 -62
- package/.bkit/shared/docs/setup.md +0 -52
- package/.bkit/shared/docs/technology.md +0 -15
- /package/.bkit/templates/{.lintstagedrc.json → lintstagedrc.example.json} +0 -0
- /package/.bkit/templates/{.prettierignore → prettierignore.example} +0 -0
|
@@ -16,10 +16,12 @@ const GATE_CONFIG_PATTERNS = [
|
|
|
16
16
|
/^\.prettierrc(\.(json|js|cjs|mjs|ya?ml|toml))?$/,
|
|
17
17
|
/^prettier\.config\.[mc]?js$/,
|
|
18
18
|
/^\.prettierignore$/,
|
|
19
|
+
/^prettierignore\.example$/,
|
|
19
20
|
/^biome\.jsonc?$/,
|
|
20
21
|
/^\.vale\.ini$/,
|
|
21
22
|
/^slop-scan\.config\.json$/,
|
|
22
23
|
/^\.lintstagedrc(\.(json|js|cjs|mjs|ya?ml))?$/,
|
|
24
|
+
/^lintstagedrc\.example\.json$/,
|
|
23
25
|
/^lint-staged\.config\.[mc]?js$/,
|
|
24
26
|
/^ruff\.toml$/,
|
|
25
27
|
/^\.ruff\.toml$/,
|
|
@@ -107,6 +109,27 @@ function docAuthoringAdvisory() {
|
|
|
107
109
|
);
|
|
108
110
|
}
|
|
109
111
|
|
|
112
|
+
// Agent-read files: the files below `.agents/`, `.bkit/` and `docs/` plus the root agent
|
|
113
|
+
// files, matching the scope `.bkit/authoring.md` states. Plan artifacts under `docs/plans/`
|
|
114
|
+
// keep their own template contract and get no general reminder.
|
|
115
|
+
const AGENT_READ_ROOT_FILES = new Set(["AGENTS.md", "CLAUDE.md", "GEMINI.md"]);
|
|
116
|
+
|
|
117
|
+
function isAgentReadPath(filePath) {
|
|
118
|
+
const p = filePath.replace(/\\/g, "/");
|
|
119
|
+
if (AGENT_READ_ROOT_FILES.has(p.split("/").pop() || "")) return true;
|
|
120
|
+
if (p.startsWith("docs/plans/") || p.includes("/docs/plans/")) return false;
|
|
121
|
+
return ["docs/", ".agents/", ".bkit/"].some((d) => p.startsWith(d) || p.includes("/" + d));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// The one general authoring reminder, identical for every edit channel and host.
|
|
125
|
+
function authoringReminder() {
|
|
126
|
+
return (
|
|
127
|
+
`[bkit GateGuard] Agent-read file. Before you edit it:\n` +
|
|
128
|
+
`- Find this file in \`.bkit/authoring.md\` § Which Sections Apply, and read the sections its row lists.\n` +
|
|
129
|
+
`- Follow those rules in the edit.`
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
110
133
|
function configAdvisory(filePath) {
|
|
111
134
|
const base = path.basename(filePath);
|
|
112
135
|
return (
|
|
@@ -138,6 +161,13 @@ function inProcessKey(sessionId, filePath) {
|
|
|
138
161
|
return JSON.stringify([sessionId, filePath]);
|
|
139
162
|
}
|
|
140
163
|
|
|
164
|
+
// Normalized warning identity: an absolute path resolved against the call's effective
|
|
165
|
+
// directory, so a relative, absolute or `..` spelling of one file shares one record.
|
|
166
|
+
function normalizeIdentity(filePath, cwd) {
|
|
167
|
+
const base = typeof cwd === "string" && cwd ? cwd : process.cwd();
|
|
168
|
+
return path.resolve(base, filePath);
|
|
169
|
+
}
|
|
170
|
+
|
|
141
171
|
// Dedup scope: the session, narrowed to one agent when the host names it. A Claude Code
|
|
142
172
|
// subagent shares its parent's session_id and carries its own agent_id.
|
|
143
173
|
function dedupKey(sessionId, agentId) {
|
|
@@ -151,12 +181,17 @@ function stateFile(sessionId) {
|
|
|
151
181
|
}
|
|
152
182
|
|
|
153
183
|
// Returns the per-session warned-file map. Absent state file is the NORMAL
|
|
154
|
-
// first-touch case (guarded, no throw); a corrupt file
|
|
155
|
-
// fail-open boundary and that one call no-ops.
|
|
184
|
+
// first-touch case (guarded, no throw); a corrupt file reads as empty.
|
|
156
185
|
function readState(sessionId) {
|
|
157
186
|
const file = stateFile(sessionId);
|
|
158
187
|
if (!fs.existsSync(file)) return { files: {} };
|
|
159
|
-
|
|
188
|
+
let parsed;
|
|
189
|
+
try {
|
|
190
|
+
parsed = JSON.parse(fs.readFileSync(file, "utf-8"));
|
|
191
|
+
} catch {
|
|
192
|
+
// Unparseable state is treated as empty; the in-process set still prevents a deny loop.
|
|
193
|
+
return { files: {} };
|
|
194
|
+
}
|
|
160
195
|
if (parsed && typeof parsed === "object" && parsed.files && typeof parsed.files === "object") {
|
|
161
196
|
return parsed;
|
|
162
197
|
}
|
|
@@ -168,10 +203,13 @@ function alreadyWarned(sessionId, filePath) {
|
|
|
168
203
|
return Boolean(readState(sessionId).files[filePath]);
|
|
169
204
|
}
|
|
170
205
|
|
|
171
|
-
|
|
206
|
+
// `spelling` is the path as the host wrote it; it is recorded beside the normalized key so
|
|
207
|
+
// state readers that look a file up by its original spelling still find it.
|
|
208
|
+
function markWarned(sessionId, filePath, spelling) {
|
|
172
209
|
fs.mkdirSync(stateDir(), { recursive: true });
|
|
173
210
|
const state = readState(sessionId);
|
|
174
211
|
state.files[filePath] = true;
|
|
212
|
+
if (typeof spelling === "string" && spelling) state.files[spelling] = true;
|
|
175
213
|
fs.writeFileSync(stateFile(sessionId), JSON.stringify(state), "utf-8");
|
|
176
214
|
}
|
|
177
215
|
|
|
@@ -190,39 +228,227 @@ function gcOldState() {
|
|
|
190
228
|
}
|
|
191
229
|
}
|
|
192
230
|
|
|
193
|
-
//
|
|
194
|
-
//
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
231
|
+
// Host-declared: true when the hook process outlives one call (the opencode plugin), so a
|
|
232
|
+
// deny whose state file cannot be written is still remembered in process and cannot loop.
|
|
233
|
+
function processPersists() {
|
|
234
|
+
return typeof GATEGUARD_PROCESS_PERSISTS !== "undefined" && GATEGUARD_PROCESS_PERSISTS === true;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Pure preparation: the advice for the first touch of `filePath` this session, or null when
|
|
238
|
+
// GateGuard is off, the path is unusable, or the session was already warned about it.
|
|
239
|
+
// Writes nothing; `acknowledgeAdvice` records the touch once the advice is delivered.
|
|
240
|
+
// `isNewFile` picks the reuse checklist over the read-this-file checklist.
|
|
241
|
+
function prepareAdvice(filePath, sessionId, isNewFile, cwd) {
|
|
200
242
|
const mode = process.env.BKIT_GATEGUARD;
|
|
201
243
|
if (mode === "off") return null;
|
|
202
244
|
if (!filePath || typeof filePath !== "string") return null;
|
|
203
245
|
|
|
204
246
|
const sid = typeof sessionId === "string" ? sessionId : "no-session";
|
|
247
|
+
const key = normalizeIdentity(filePath, cwd);
|
|
205
248
|
|
|
206
249
|
// Warn once per (session, file).
|
|
207
|
-
if (alreadyWarned(sid,
|
|
250
|
+
if (alreadyWarned(sid, key)) return null;
|
|
208
251
|
|
|
209
|
-
const gated = isGateConfig(
|
|
252
|
+
const gated = isGateConfig(key) && process.env.BKIT_ALLOW_CONFIG_EDIT !== "1";
|
|
210
253
|
const baseContext = gated
|
|
211
|
-
? configAdvisory(
|
|
254
|
+
? configAdvisory(key)
|
|
212
255
|
: isNewFile
|
|
213
|
-
? reuseChecklist(
|
|
214
|
-
: investigationChecklist(
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
256
|
+
? reuseChecklist(key)
|
|
257
|
+
: investigationChecklist(key);
|
|
258
|
+
const parts = [baseContext];
|
|
259
|
+
if (isDocsPath(key)) parts.push(docAuthoringAdvisory());
|
|
260
|
+
if (isAgentReadPath(key)) parts.push(authoringReminder());
|
|
261
|
+
|
|
262
|
+
return {
|
|
263
|
+
sid,
|
|
264
|
+
key,
|
|
265
|
+
mode: mode === "deny" ? "deny" : "advisory",
|
|
266
|
+
context: parts.join("\n\n"),
|
|
267
|
+
spelling: filePath,
|
|
268
|
+
agentRead: isAgentReadPath(key),
|
|
269
|
+
};
|
|
270
|
+
}
|
|
218
271
|
|
|
272
|
+
// Records a prepared touch. Fail-open: a state-file write error remembers the touch in
|
|
273
|
+
// this process and returns false (not durable). Only a durable record, or a process that
|
|
274
|
+
// outlives the call, can back a deny: a deny no later call can see was given would block
|
|
275
|
+
// every retry of the edit.
|
|
276
|
+
function acknowledgeAdvice(prepared) {
|
|
219
277
|
try {
|
|
220
|
-
markWarned(sid,
|
|
278
|
+
markWarned(prepared.sid, prepared.key, prepared.spelling);
|
|
221
279
|
gcOldState();
|
|
280
|
+
return true;
|
|
222
281
|
} catch {
|
|
223
|
-
warnedInProcess.add(inProcessKey(sid,
|
|
224
|
-
return
|
|
282
|
+
warnedInProcess.add(inProcessKey(prepared.sid, prepared.key));
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// The advisory for the first touch of `filePath` this session, or null. Prepares and
|
|
288
|
+
// acknowledges in one step, for callers that deliver the advice themselves.
|
|
289
|
+
function firstTouchAdvice(filePath, sessionId, isNewFile, cwd) {
|
|
290
|
+
const prepared = prepareAdvice(filePath, sessionId, isNewFile, cwd);
|
|
291
|
+
if (!prepared) return null;
|
|
292
|
+
const durable = acknowledgeAdvice(prepared);
|
|
293
|
+
const mode = durable || processPersists() ? prepared.mode : "advisory";
|
|
294
|
+
return { mode, context: prepared.context };
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// Conservative per-host output budgets for delivered advice (reviewed under decision
|
|
298
|
+
// `787-conservative-host-advisory-budgets`; complete-block visibility is unverified).
|
|
299
|
+
const ADVICE_BUDGETS = {
|
|
300
|
+
claude: { limit: 8000, unit: "chars" },
|
|
301
|
+
codex: { limit: 2000, unit: "bytes" },
|
|
302
|
+
cursor: { limit: 2000, unit: "bytes" },
|
|
303
|
+
antigravity: { limit: 2000, unit: "bytes" },
|
|
304
|
+
opencode: { limit: 8000, unit: "chars" },
|
|
305
|
+
};
|
|
306
|
+
const ADVICE_NOTICE_RESERVE = 512;
|
|
307
|
+
|
|
308
|
+
function adviceSize(text, unit) {
|
|
309
|
+
return unit === "bytes" ? Buffer.byteLength(text, "utf-8") : text.length;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Selects prepared advice blocks inside `budget`: only whole blocks, in order, with
|
|
313
|
+
// `ADVICE_NOTICE_RESERVE` units kept for the omitted-target notice. Pure: acknowledges
|
|
314
|
+
// nothing. `fixedCost` is the size (in the budget's unit) of text the caller adds around
|
|
315
|
+
// the blocks, so the whole composed advice fits. Returns `{ selected, context }`
|
|
316
|
+
// (`context` includes the omitted-target notice).
|
|
317
|
+
function selectAdvice(blocks, budget, fixedCost = 0) {
|
|
318
|
+
const sep = "\n\n";
|
|
319
|
+
const pick = (room) => {
|
|
320
|
+
const selected = [];
|
|
321
|
+
const omitted = [];
|
|
322
|
+
let used = 0;
|
|
323
|
+
for (const b of blocks) {
|
|
324
|
+
const cost = adviceSize(b.context, budget.unit) + (selected.length > 0 ? sep.length : 0);
|
|
325
|
+
if (used + cost <= room) {
|
|
326
|
+
selected.push(b);
|
|
327
|
+
used += cost;
|
|
328
|
+
} else {
|
|
329
|
+
omitted.push(b);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return { selected, omitted };
|
|
333
|
+
};
|
|
334
|
+
const omittedNotice = (omitted) => {
|
|
335
|
+
const reminder = omitted.some((b) => b.agentRead)
|
|
336
|
+
? " Agent-read files: see `.bkit/authoring.md` § Which Sections Apply."
|
|
337
|
+
: "";
|
|
338
|
+
return `[bkit GateGuard] ${omitted.length} target${omitted.length === 1 ? "" : "s"} omitted (output limit); they stay unacknowledged and are advised on a later edit.${reminder}`;
|
|
339
|
+
};
|
|
340
|
+
let { selected, omitted } = pick(
|
|
341
|
+
budget.limit - (fixedCost > 0 ? 0 : ADVICE_NOTICE_RESERVE) - fixedCost,
|
|
342
|
+
);
|
|
343
|
+
if (fixedCost > 0 && omitted.length > 0) {
|
|
344
|
+
// Composed advice counts its own text, so the omitted-target notice is sized exactly
|
|
345
|
+
// (worst case: every block omitted) instead of by the fixed reserve.
|
|
346
|
+
const noticeRoom = adviceSize(omittedNotice(blocks), budget.unit) + sep.length;
|
|
347
|
+
({ selected, omitted } = pick(budget.limit - fixedCost - noticeRoom));
|
|
348
|
+
}
|
|
349
|
+
const texts = selected.map((b) => b.context);
|
|
350
|
+
if (omitted.length > 0) texts.push(omittedNotice(omitted));
|
|
351
|
+
return { selected, context: texts.join(sep) };
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// Records the selected blocks once their route has delivered them. Returns the mode to
|
|
355
|
+
// report: a deny only when every record is durable (or the process outlives the call).
|
|
356
|
+
function acknowledgeSelected(selected) {
|
|
357
|
+
if (selected.length === 0) return "advisory";
|
|
358
|
+
let durable = true;
|
|
359
|
+
for (const b of selected) if (!acknowledgeAdvice(b)) durable = false;
|
|
360
|
+
return durable || processPersists() ? selected[0].mode : "advisory";
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// Delivers prepared advice blocks inside `budget` (see `selectAdvice`). Acknowledges exactly
|
|
364
|
+
// the selected blocks, and only when `verified` says the route reaches the model. Returns
|
|
365
|
+
// `{ mode, context }` or null when there is nothing to say.
|
|
366
|
+
function deliverAdvice(blocks, budget, verified, fixedCost = 0) {
|
|
367
|
+
if (blocks.length === 0) return null;
|
|
368
|
+
const { selected, context } = selectAdvice(blocks, budget, fixedCost);
|
|
369
|
+
return { mode: verified ? acknowledgeSelected(selected) : "advisory", context };
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// Prepared per-file blocks for the exact targets of a shell edit. Shell targets are
|
|
373
|
+
// relative to the evidence root (`ctx.root`, else `ctx.cwd`); they normalize to the same
|
|
374
|
+
// absolute identity the edit tools record, so both channels share one warning. A shell
|
|
375
|
+
// edit is advisory only and never a new-file reuse check: the file may not exist yet.
|
|
376
|
+
function shellTargetBlocks(targets, ctx, sessionId, agentId) {
|
|
377
|
+
const base = (ctx && (ctx.root || ctx.cwd)) || process.cwd();
|
|
378
|
+
const sid = dedupKey(sessionId, agentId);
|
|
379
|
+
const blocks = [];
|
|
380
|
+
const seen = new Set();
|
|
381
|
+
for (const t of targets || []) {
|
|
382
|
+
const prepared = prepareAdvice(t, sid, false, base);
|
|
383
|
+
if (!prepared || seen.has(prepared.key)) continue;
|
|
384
|
+
seen.add(prepared.key);
|
|
385
|
+
// The record carries only the normalized path: the relative spelling is shell-local.
|
|
386
|
+
prepared.spelling = prepared.key;
|
|
387
|
+
blocks.push(prepared);
|
|
225
388
|
}
|
|
389
|
+
return blocks;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// The name each host's guardrails advice carries in its deny line.
|
|
393
|
+
const ADVICE_HOST_LABELS = {
|
|
394
|
+
claude: "Claude Code",
|
|
395
|
+
codex: "Codex",
|
|
396
|
+
cursor: "Cursor",
|
|
397
|
+
antigravity: "Antigravity",
|
|
398
|
+
opencode: "OpenCode",
|
|
399
|
+
};
|
|
400
|
+
// The most characters of a command the advice echoes back.
|
|
401
|
+
const ADVICE_COMMAND_CHARS = 300;
|
|
226
402
|
|
|
227
|
-
|
|
403
|
+
// `command` cut to `ADVICE_COMMAND_CHARS` whole characters, marked when cut.
|
|
404
|
+
function adviceCommand(command) {
|
|
405
|
+
const chars = Array.from(String(command || ""));
|
|
406
|
+
if (chars.length <= ADVICE_COMMAND_CHARS) return chars.join("");
|
|
407
|
+
return `${chars.slice(0, ADVICE_COMMAND_CHARS).join("")} [cut]`;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// The guardrails advice for one shell verdict (`classifyShell`): one text for every host
|
|
411
|
+
// apart from the host name in the deny line and the Codex-only line that its ask and secret
|
|
412
|
+
// tiers ran without a prompt. `budget` is the host's `ADVICE_BUDGETS` entry; `call` is
|
|
413
|
+
// `{ command, ctx, session, agent, reserve }`, where `reserve` is the size of any text the
|
|
414
|
+
// host adds after the advice. Returns `{ text, selected }`: `selected` are the per-file
|
|
415
|
+
// blocks in the text, which the caller acknowledges (`acknowledgeSelected`) once its route
|
|
416
|
+
// has delivered them.
|
|
417
|
+
function composeAdvice(v, host, budget, call = {}) {
|
|
418
|
+
const label = ADVICE_HOST_LABELS[host] || host;
|
|
419
|
+
const shown = adviceCommand(call.command);
|
|
420
|
+
const noPrompt =
|
|
421
|
+
host === "codex"
|
|
422
|
+
? "\nIt runs without confirmation, because Codex cannot prompt for one. Tell the user that you ran it."
|
|
423
|
+
: "";
|
|
424
|
+
switch (v.tier) {
|
|
425
|
+
case "deny":
|
|
426
|
+
return { text: `Blocked by bkit ${label} guardrails: ${v.what}. ${v.fix}`, selected: [] };
|
|
427
|
+
case "ask":
|
|
428
|
+
return {
|
|
429
|
+
text: `bkit guardrails: this is a destructive or privileged command (${v.what}). It is on the PROHIBITED list in every bkit workflow.${noPrompt}\nIf the user did not ask for this exact command, NEVER run it.\n\`git clean\` and \`git checkout -- .\` destroy untracked files and uncommitted work, which no reflog can recover.\nCommand: ${shown}`,
|
|
430
|
+
selected: [],
|
|
431
|
+
};
|
|
432
|
+
case "secret":
|
|
433
|
+
return {
|
|
434
|
+
text: `bkit guardrails: this command reads ${v.path}, an env, secrets or private-key file, which may expose secrets.${noPrompt}\nNEVER print secret values.\nPrefer direnv or documented non-secret examples.\nCommand: ${shown}`,
|
|
435
|
+
selected: [],
|
|
436
|
+
};
|
|
437
|
+
default:
|
|
438
|
+
break;
|
|
439
|
+
}
|
|
440
|
+
const fetchNote =
|
|
441
|
+
v.tier === "fetch"
|
|
442
|
+
? `bkit guardrails: outbound fetch to a host that is not on this repo's network allowlist (.agents/context.md § allowed-domains, plus bkit's shipped tooling hosts).\nConfirm the destination is intended before you rely on the result.\nIf the host is a standing dependency, add it to allowed-domains.\nCommand: ${shown}`
|
|
443
|
+
: "";
|
|
444
|
+
const notice = v.edits ? shellEditAdvisory(v.edits) : "";
|
|
445
|
+
const fixed = [fetchNote, notice].filter(Boolean).join("\n\n");
|
|
446
|
+
const blocks = v.edits
|
|
447
|
+
? shellTargetBlocks(v.edits.targets, call.ctx, call.session, call.agent)
|
|
448
|
+
: [];
|
|
449
|
+
if (blocks.length === 0) return { text: fixed, selected: [] };
|
|
450
|
+
const sep = "\n\n";
|
|
451
|
+
const fixedCost = adviceSize(fixed, budget.unit) + sep.length + (call.reserve || 0);
|
|
452
|
+
const { selected, context } = selectAdvice(blocks, budget, fixedCost);
|
|
453
|
+
return { text: `${fixed}${sep}${context}`, selected };
|
|
228
454
|
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// --- Shell deny tier: identical in every host's guardrails hook (bkit renders it from one
|
|
2
|
+
// source). Reads the parsed commands `shellCommands` (`guardrails-shell.js`) returns, and
|
|
3
|
+
// splits their words with `operands` from the same file.
|
|
4
|
+
//
|
|
5
|
+
// git commands are classified by their parsed words — subcommand, flag set (any order,
|
|
6
|
+
// short clusters such as `-fdx` expanded), positionals, `+refspec` — never by a literal
|
|
7
|
+
// prefix, so `git reset -q --hard` and `git push origin +dev` land in the same tier as
|
|
8
|
+
// `git reset --hard` and `git push --force`.
|
|
9
|
+
|
|
10
|
+
/** git global options that take the next word as their value (`git -C dir push`). */
|
|
11
|
+
const GIT_GLOBAL_VALUE_OPTS = new Set([
|
|
12
|
+
"-C",
|
|
13
|
+
"-c",
|
|
14
|
+
"--git-dir",
|
|
15
|
+
"--work-tree",
|
|
16
|
+
"--namespace",
|
|
17
|
+
"--config-env",
|
|
18
|
+
"--super-prefix",
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Per subcommand, the options that take a value: `short` letters consume the rest of their
|
|
23
|
+
* cluster or the next word, `long` names consume the next word when written without `=`.
|
|
24
|
+
* A value is never read as a flag or a positional (`git commit -m "drop -n"`).
|
|
25
|
+
*/
|
|
26
|
+
const GIT_VALUE_OPTS = {
|
|
27
|
+
push: { short: "o", long: ["--push-option", "--repo", "--receive-pack", "--exec"] },
|
|
28
|
+
clean: { short: "e", long: ["--exclude"] },
|
|
29
|
+
checkout: { short: "bB", long: ["--orphan"] },
|
|
30
|
+
restore: { short: "s", long: ["--source"] },
|
|
31
|
+
rebase: { short: "xsXC", long: ["--onto", "--exec", "--strategy", "--strategy-option"] },
|
|
32
|
+
commit: {
|
|
33
|
+
short: "mFCct",
|
|
34
|
+
long: [
|
|
35
|
+
"--message",
|
|
36
|
+
"--file",
|
|
37
|
+
"--author",
|
|
38
|
+
"--date",
|
|
39
|
+
"--reuse-message",
|
|
40
|
+
"--reedit-message",
|
|
41
|
+
"--fixup",
|
|
42
|
+
"--squash",
|
|
43
|
+
"--template",
|
|
44
|
+
"--cleanup",
|
|
45
|
+
"--trailer",
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A git invocation's parsed words, or null when `words` does not run git:
|
|
52
|
+
* `{ sub, long: Set<"--name">, short: Set<letter>, args: string[] }`. Words after `--`
|
|
53
|
+
* are positionals.
|
|
54
|
+
*/
|
|
55
|
+
function parseGit(words) {
|
|
56
|
+
if ((words[0] || "").replace(/^.*\//, "") !== "git") return null;
|
|
57
|
+
let i = 1;
|
|
58
|
+
while (i < words.length && words[i].startsWith("-")) {
|
|
59
|
+
i += GIT_GLOBAL_VALUE_OPTS.has(words[i]) ? 2 : 1;
|
|
60
|
+
}
|
|
61
|
+
const sub = words[i];
|
|
62
|
+
if (!sub) return null;
|
|
63
|
+
const spec = GIT_VALUE_OPTS[sub] || { short: "", long: [] };
|
|
64
|
+
const long = new Set();
|
|
65
|
+
const short = new Set();
|
|
66
|
+
const args = [];
|
|
67
|
+
let positionalOnly = false;
|
|
68
|
+
for (let j = i + 1; j < words.length; j++) {
|
|
69
|
+
const w = words[j];
|
|
70
|
+
if (positionalOnly || w === "-" || !w.startsWith("-")) {
|
|
71
|
+
args.push(w);
|
|
72
|
+
} else if (w === "--") {
|
|
73
|
+
positionalOnly = true;
|
|
74
|
+
} else if (w.startsWith("--")) {
|
|
75
|
+
const name = w.split("=")[0];
|
|
76
|
+
long.add(name);
|
|
77
|
+
if (!w.includes("=") && spec.long.includes(name)) j++;
|
|
78
|
+
} else {
|
|
79
|
+
for (let k = 1; k < w.length; k++) {
|
|
80
|
+
short.add(w[k]);
|
|
81
|
+
if (spec.short.includes(w[k])) {
|
|
82
|
+
if (k === w.length - 1) j++;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return { sub, long, short, args };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** `{ what, fix }` when a parsed command's words force-push with git, else null. */
|
|
92
|
+
function gitDenyRule(words) {
|
|
93
|
+
const g = parseGit(words);
|
|
94
|
+
if (!g || g.sub !== "push") return null;
|
|
95
|
+
if (g.long.has("--force") || g.short.has("f") || g.args.some((a) => a.startsWith("+"))) {
|
|
96
|
+
return {
|
|
97
|
+
what: "git force-push",
|
|
98
|
+
fix: "NEVER force-push (--force, -f or a +refspec). Use a normal push, or --force-with-lease only when the user explicitly asks for it on a personal branch.",
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* A filesystem root an operand names: `/` (also `//`, `/.`), or `~`, `$HOME` or `${HOME}` bare
|
|
106
|
+
* or followed by such slashes and dots, with an optional trailing `*`.
|
|
107
|
+
*/
|
|
108
|
+
const ROOT_OPERAND = /^(?:\/[/.]*|(?:~|\$HOME|\$\{HOME\})(?:\/[/.]*)?)\*?$/;
|
|
109
|
+
|
|
110
|
+
/** The system root itself: `/`, `//`, `/.`, `/*`. */
|
|
111
|
+
const SYSTEM_ROOT = /^\/[/.]*\*?$/;
|
|
112
|
+
|
|
113
|
+
/** A chmod mode that makes a file world-writable: octal `777` / `0777` / `666`, or `a+w` / `o=rwx`. */
|
|
114
|
+
function worldWritable(mode) {
|
|
115
|
+
if (/^[0-7]{3,4}$/.test(mode)) return /[2367]$/.test(mode);
|
|
116
|
+
return mode.split(",").some((clause) => /^[ugoa]*[ao][ugoa]*[+=][rwxXst]*w/.test(clause));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** The short letters and long names of the options before `--`, and the operands, of `words`. */
|
|
120
|
+
function optionsAndOperands(words) {
|
|
121
|
+
const args = words.slice(1);
|
|
122
|
+
const end = args.includes("--") ? args.indexOf("--") : args.length;
|
|
123
|
+
const opts = args.slice(0, end).filter((w) => w.length > 1 && w.startsWith("-"));
|
|
124
|
+
return {
|
|
125
|
+
short: new Set(opts.filter((w) => w[1] !== "-").flatMap((w) => [...w.slice(1)])),
|
|
126
|
+
long: new Set(opts.filter((w) => w[1] === "-").map((w) => w.split("=")[0])),
|
|
127
|
+
operands: operands(args),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Deny tier — matches Claude's settings.json deny rows and OpenCode's bash deny map.
|
|
133
|
+
* `cmds` are the parsed commands (`shellCommands`). `{ what, fix }` for a blocked
|
|
134
|
+
* command, else null.
|
|
135
|
+
*/
|
|
136
|
+
function denyRule(cmds) {
|
|
137
|
+
for (const c of cmds) {
|
|
138
|
+
const denied = gitDenyRule(c.words);
|
|
139
|
+
if (denied) return denied;
|
|
140
|
+
const { short, long, operands } = optionsAndOperands(c.words);
|
|
141
|
+
// rm with both -r and -f (-rf, -fr, -Rf, -r -f, --recursive --force) on /, ~ or $HOME
|
|
142
|
+
// itself. A path below them (~/projects/x) is not matched.
|
|
143
|
+
if (
|
|
144
|
+
c.program === "rm" &&
|
|
145
|
+
(short.has("r") || short.has("R") || long.has("--recursive")) &&
|
|
146
|
+
(short.has("f") || long.has("--force")) &&
|
|
147
|
+
operands.some((o) => ROOT_OPERAND.test(o))
|
|
148
|
+
) {
|
|
149
|
+
return {
|
|
150
|
+
what: "recursive delete of a filesystem root",
|
|
151
|
+
fix: "NEVER run rm -rf against /, ~, or $HOME. Narrow the path to the target directory.",
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
if (
|
|
155
|
+
c.program === "chmod" &&
|
|
156
|
+
(short.has("R") || long.has("--recursive")) &&
|
|
157
|
+
worldWritable(operands[0] || "") &&
|
|
158
|
+
operands.slice(1).some((o) => SYSTEM_ROOT.test(o))
|
|
159
|
+
) {
|
|
160
|
+
return {
|
|
161
|
+
what: "world-writable chmod -R on the filesystem root",
|
|
162
|
+
fix: "NEVER make the filesystem root world-writable.",
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// --- Secret-file read tier: identical in the Cursor and Google Antigravity guardrails hooks
|
|
2
|
-
// (bkit renders it from one source).
|
|
3
|
-
//
|
|
2
|
+
// (bkit renders it from one source). Claude's settings.json `Read(...)` rows and opencode's
|
|
3
|
+
// `permission.read` map list fewer key names; each host maps a tier to its own output
|
|
4
4
|
// shape and wording. Needs `secretFileKind` from `guardrails-tiers.js` above it.
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* The read tier for a file path (`/` or `\` separated), first match wins:
|
|
8
|
-
* `{ tier: "deny", path }` — private-key
|
|
8
|
+
* `{ tier: "deny", path }` — a private-key file (`mayNameKeyFile`);
|
|
9
9
|
* `{ tier: "ask", path }` — an env / secrets file: `.env`, `.env.*` except `.env.example`;
|
|
10
10
|
* null — nothing to say.
|
|
11
11
|
*/
|