@cbartens/bkit 6.1.0 → 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 +43 -33
- 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 +99 -36
- package/.bkit/core/.bkit/templates.md +167 -37
- 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 +161 -37
- package/.bkit/core/engine/checks/after/index.ts +18 -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 +124 -19
- package/.bkit/core/engine/commands/ci/push-gate.ts +101 -43
- package/.bkit/core/engine/commands/install/doctor.ts +5 -5
- 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 +202 -26
- 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 +46 -11
- 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/context/bkit-vercel.md +103 -59
- 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-check-accepted-divergences.mjs +1 -6
- package/.bkit/templates/scripts/ci/bkit-machine-lock.sh +511 -103
- package/.bkit/templates/scripts/ci/bkit-test-awake.mjs +314 -28
- package/.bkit/templates/scripts/ci/bkit-test-awake.test.mjs +500 -1
- package/.bkit/templates/scripts/graphify/bkit-graphify-graphml.py +1 -1
- package/.bkit/templates/scripts/graphify/bkit-graphify-rollup.py +91 -62
- package/.bkit/templates/scripts/graphify/bkit-graphify.sh +59 -11
- package/.bkit/templates/slop-scan.config.json +2 -0
- package/CHANGELOG.md +79 -0
- package/DETAILS.md +661 -0
- package/README.md +73 -604
- package/dist/checks/after/auth.js +114 -46
- package/dist/checks/after/github.js +138 -35
- package/dist/checks/after/index.js +16 -4
- 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 +113 -20
- package/dist/commands/ci/push-gate.js +79 -44
- package/dist/commands/install/doctor.js +5 -5
- 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 +190 -27
- 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 +21 -12
- 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 +23 -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
|
@@ -1,109 +1,11 @@
|
|
|
1
1
|
// --- Shell tiers: identical in the Cursor, Codex and Google Antigravity guardrails hooks
|
|
2
2
|
// (bkit renders them from one source). Each host maps a tier to its own output shape and
|
|
3
|
-
// wording. Needs `
|
|
4
|
-
// above it.
|
|
5
|
-
//
|
|
6
|
-
// git commands are classified by their parsed words — subcommand, flag set (any order,
|
|
7
|
-
// short clusters such as `-fdx` expanded), positionals, `+refspec` — never by a literal
|
|
8
|
-
// prefix, so `git reset -q --hard` and `git push origin +dev` land in the same tier as
|
|
9
|
-
// `git reset --hard` and `git push --force`.
|
|
10
|
-
|
|
11
|
-
/** git global options that take the next word as their value (`git -C dir push`). */
|
|
12
|
-
const GIT_GLOBAL_VALUE_OPTS = new Set([
|
|
13
|
-
"-C",
|
|
14
|
-
"-c",
|
|
15
|
-
"--git-dir",
|
|
16
|
-
"--work-tree",
|
|
17
|
-
"--namespace",
|
|
18
|
-
"--config-env",
|
|
19
|
-
"--super-prefix",
|
|
20
|
-
]);
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Per subcommand, the options that take a value: `short` letters consume the rest of their
|
|
24
|
-
* cluster or the next word, `long` names consume the next word when written without `=`.
|
|
25
|
-
* A value is never read as a flag or a positional (`git commit -m "drop -n"`).
|
|
26
|
-
*/
|
|
27
|
-
const GIT_VALUE_OPTS = {
|
|
28
|
-
push: { short: "o", long: ["--push-option", "--repo", "--receive-pack", "--exec"] },
|
|
29
|
-
clean: { short: "e", long: ["--exclude"] },
|
|
30
|
-
checkout: { short: "bB", long: ["--orphan"] },
|
|
31
|
-
restore: { short: "s", long: ["--source"] },
|
|
32
|
-
rebase: { short: "xsXC", long: ["--onto", "--exec", "--strategy", "--strategy-option"] },
|
|
33
|
-
commit: {
|
|
34
|
-
short: "mFCct",
|
|
35
|
-
long: [
|
|
36
|
-
"--message",
|
|
37
|
-
"--file",
|
|
38
|
-
"--author",
|
|
39
|
-
"--date",
|
|
40
|
-
"--reuse-message",
|
|
41
|
-
"--reedit-message",
|
|
42
|
-
"--fixup",
|
|
43
|
-
"--squash",
|
|
44
|
-
"--template",
|
|
45
|
-
"--cleanup",
|
|
46
|
-
"--trailer",
|
|
47
|
-
],
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* A git invocation's parsed words, or null when `words` does not run git:
|
|
53
|
-
* `{ sub, long: Set<"--name">, short: Set<letter>, args: string[] }`. Words after `--`
|
|
54
|
-
* are positionals.
|
|
55
|
-
*/
|
|
56
|
-
function parseGit(words) {
|
|
57
|
-
if ((words[0] || "").replace(/^.*\//, "") !== "git") return null;
|
|
58
|
-
let i = 1;
|
|
59
|
-
while (i < words.length && words[i].startsWith("-")) {
|
|
60
|
-
i += GIT_GLOBAL_VALUE_OPTS.has(words[i]) ? 2 : 1;
|
|
61
|
-
}
|
|
62
|
-
const sub = words[i];
|
|
63
|
-
if (!sub) return null;
|
|
64
|
-
const spec = GIT_VALUE_OPTS[sub] || { short: "", long: [] };
|
|
65
|
-
const long = new Set();
|
|
66
|
-
const short = new Set();
|
|
67
|
-
const args = [];
|
|
68
|
-
let positionalOnly = false;
|
|
69
|
-
for (let j = i + 1; j < words.length; j++) {
|
|
70
|
-
const w = words[j];
|
|
71
|
-
if (positionalOnly || w === "-" || !w.startsWith("-")) {
|
|
72
|
-
args.push(w);
|
|
73
|
-
} else if (w === "--") {
|
|
74
|
-
positionalOnly = true;
|
|
75
|
-
} else if (w.startsWith("--")) {
|
|
76
|
-
const name = w.split("=")[0];
|
|
77
|
-
long.add(name);
|
|
78
|
-
if (!w.includes("=") && spec.long.includes(name)) j++;
|
|
79
|
-
} else {
|
|
80
|
-
for (let k = 1; k < w.length; k++) {
|
|
81
|
-
short.add(w[k]);
|
|
82
|
-
if (spec.short.includes(w[k])) {
|
|
83
|
-
if (k === w.length - 1) j++;
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return { sub, long, short, args };
|
|
90
|
-
}
|
|
3
|
+
// wording. Needs `shellCommands` and `usesFetch` from `guardrails-shell.js`, and
|
|
4
|
+
// `parseGit` and `denyRule` from `guardrails-deny.js`, above it.
|
|
91
5
|
|
|
92
6
|
/** A pathspec naming the whole tree (or more): `.`, `./`, `..`, `:/`. */
|
|
93
7
|
const WHOLE_TREE_PATH = /^(?:\.\.?\/?|:\/\.?)$/;
|
|
94
8
|
|
|
95
|
-
/** `{ what, fix }` when a parsed git invocation force-pushes, else null. */
|
|
96
|
-
function gitDenyRule(g) {
|
|
97
|
-
if (g.sub !== "push") return null;
|
|
98
|
-
if (g.long.has("--force") || g.short.has("f") || g.args.some((a) => a.startsWith("+"))) {
|
|
99
|
-
return {
|
|
100
|
-
what: "git force-push",
|
|
101
|
-
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.",
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
9
|
/** What makes a parsed git invocation ask-tier, else null. */
|
|
108
10
|
function gitAskRule(g) {
|
|
109
11
|
if (g.long.has("--no-verify") || (g.sub === "commit" && g.short.has("n"))) {
|
|
@@ -134,66 +36,59 @@ function gitAskRule(g) {
|
|
|
134
36
|
}
|
|
135
37
|
}
|
|
136
38
|
|
|
137
|
-
/**
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
39
|
+
/** The basename of a word that names a program (`/usr/bin/sudo` -> `sudo`). */
|
|
40
|
+
function programName(word) {
|
|
41
|
+
return String(word || "").replace(/^.*\//, "");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Whether a parsed command runs `bkit tests jump` (also `pnpm bkit ...`, `node dist/cli.js ...`). */
|
|
45
|
+
function isTestsJump(words) {
|
|
46
|
+
return words.some(
|
|
47
|
+
(w, i) =>
|
|
48
|
+
(programName(w) === "bkit" || /^cli\.[jt]s$/.test(programName(w))) &&
|
|
49
|
+
words[i + 1] === "tests" &&
|
|
50
|
+
words[i + 2] === "jump",
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Whether any parsed command runs `bkit tests jump`. */
|
|
55
|
+
function testsJump(cmds) {
|
|
56
|
+
return cmds.some((c) => isTestsJump(c.words));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Ask tier, non-git: what makes one parsed command destructive or privileged, else null. */
|
|
60
|
+
function shellAskRule(c) {
|
|
61
|
+
for (const priv of ["sudo", "doas"]) {
|
|
62
|
+
if (c.program === priv || c.prefix.some((w) => programName(w) === priv)) return priv;
|
|
158
63
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
64
|
+
const ops = operands(c.words.slice(1));
|
|
65
|
+
if (c.program === "brew" && ops[0] === "install") return "brew install";
|
|
66
|
+
if (["pnpm", "npm", "bun"].includes(c.program) && ops[0] === "publish") return "package publish";
|
|
67
|
+
if (c.program === "gh") {
|
|
68
|
+
const sub = `${ops[0] || ""} ${ops[1] || ""}`;
|
|
69
|
+
if (sub === "repo delete" || sub === "pr close" || sub === "release delete") return `gh ${sub}`;
|
|
164
70
|
}
|
|
165
|
-
return null;
|
|
71
|
+
return isTestsJump(c.words) ? "bkit tests jump" : null;
|
|
166
72
|
}
|
|
167
73
|
|
|
168
|
-
/**
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
{ re: /\bgh\s+repo\s+delete\b/, what: "gh repo delete" },
|
|
174
|
-
{ re: /\bgh\s+pr\s+close\b/, what: "gh pr close" },
|
|
175
|
-
{ re: /\bgh\s+release\s+delete\b/, what: "gh release delete" },
|
|
176
|
-
];
|
|
177
|
-
|
|
178
|
-
/** What makes a command ask-tier, else null. */
|
|
179
|
-
function askRule(c) {
|
|
180
|
-
for (const line of commandLines(c)) {
|
|
181
|
-
const g = parseGit(commandWords(line));
|
|
182
|
-
const what = g && gitAskRule(g);
|
|
74
|
+
/** What makes one of the parsed commands ask-tier, else null. */
|
|
75
|
+
function askRule(cmds) {
|
|
76
|
+
for (const c of cmds) {
|
|
77
|
+
const g = parseGit(c.words);
|
|
78
|
+
const what = (g && gitAskRule(g)) || shellAskRule(c);
|
|
183
79
|
if (what) return what;
|
|
184
80
|
}
|
|
185
|
-
|
|
186
|
-
return hit ? hit.what : null;
|
|
81
|
+
return null;
|
|
187
82
|
}
|
|
188
83
|
|
|
189
84
|
/**
|
|
190
|
-
* `"key"` for private-key
|
|
191
|
-
*
|
|
85
|
+
* `"key"` for a private-key file (`mayNameKeyFile`), `"env"` for an env / secrets file
|
|
86
|
+
* (`.env`, `.env.*` except `.env.example`), else null. `/` or `\` separated.
|
|
192
87
|
*/
|
|
193
88
|
function secretFileKind(filePath) {
|
|
194
89
|
const p = String(filePath || "").replace(/\\/g, "/");
|
|
195
90
|
if (!p) return null;
|
|
196
|
-
if (
|
|
91
|
+
if (mayNameKeyFile(p)) return "key";
|
|
197
92
|
const base = p.split("/").pop() || p;
|
|
198
93
|
if (base === ".env" || (/^\.env[.*]/.test(base) && base !== ".env.example")) return "env";
|
|
199
94
|
return null;
|
|
@@ -224,36 +119,37 @@ const NON_READING_HEADS = new Set([
|
|
|
224
119
|
const COPY_HEADS = new Set(["cp", "install", "rsync", "scp"]);
|
|
225
120
|
/** Programs whose first positional is a search pattern unless `-e` / `-f` supplies one. */
|
|
226
121
|
const PATTERN_HEADS = new Set(["grep", "egrep", "fgrep", "rg", "ag"]);
|
|
122
|
+
/** Programs whose first positional is a filter expression, never a file (`jq .key f.json`). */
|
|
123
|
+
const FILTER_HEADS = new Set(["jq", "yq"]);
|
|
124
|
+
|
|
125
|
+
/** Whether a grep / sed / awk invocation takes its pattern or script from an option. */
|
|
126
|
+
function patternFromOption(words) {
|
|
127
|
+
return words.some((w) => /^-[a-zA-Z]*[ef]/.test(w) || /^--(?:regexp|expression|file)\b/.test(w));
|
|
128
|
+
}
|
|
227
129
|
|
|
228
130
|
/**
|
|
229
|
-
* The first secret file
|
|
230
|
-
* `
|
|
231
|
-
*
|
|
232
|
-
* and anything `NON_READING_HEADS` runs.
|
|
131
|
+
* The first secret file the parsed commands read (`cat .bkit/.env`, `grep KEY .env.local`,
|
|
132
|
+
* `source .env`, `curl -d @.env ...`, `wc -l < .env`), else null. Not reads: a redirect
|
|
133
|
+
* target (`> .env`), a copy destination, a grep pattern (`grep -rn ".env" docs`), a `jq` /
|
|
134
|
+
* `yq` filter, and anything `NON_READING_HEADS` runs.
|
|
233
135
|
*/
|
|
234
|
-
function shellSecretRead(
|
|
235
|
-
for (const
|
|
236
|
-
const words =
|
|
237
|
-
const head =
|
|
136
|
+
function shellSecretRead(cmds) {
|
|
137
|
+
for (const c of cmds) {
|
|
138
|
+
const words = c.words;
|
|
139
|
+
const head = c.program;
|
|
238
140
|
if (!head || NON_READING_HEADS.has(head)) continue;
|
|
141
|
+
if (c.stdinFile && secretFileKind(c.stdinFile)) return c.stdinFile;
|
|
239
142
|
const positionals = words.flatMap((w, i) => (i > 0 && !w.startsWith("-") ? [i] : []));
|
|
240
143
|
const skip = new Set();
|
|
241
144
|
if (COPY_HEADS.has(head) && positionals.length > 1) skip.add(positionals.at(-1));
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
) {
|
|
246
|
-
skip.add(positionals[0]);
|
|
145
|
+
// The pattern or filter is the first operand, past option values (`grep -A 2 PATTERN`).
|
|
146
|
+
if (FILTER_HEADS.has(head) || (PATTERN_HEADS.has(head) && !patternFromOption(words))) {
|
|
147
|
+
skip.add(words.indexOf(operands(words.slice(1), VALUE_OPTIONS[head])[0], 1));
|
|
247
148
|
}
|
|
248
149
|
for (let i = 1; i < words.length; i++) {
|
|
249
150
|
if (skip.has(i)) continue;
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
i++;
|
|
253
|
-
continue;
|
|
254
|
-
}
|
|
255
|
-
if (/^(?:\d*|&)>/.test(w)) continue;
|
|
256
|
-
for (const part of w.replace(/^</, "").split(/[=:@,]/)) {
|
|
151
|
+
// Then the whole word: a `{a,b}` glob holds a comma.
|
|
152
|
+
for (const part of [...words[i].split(/[=:@,]/), words[i]]) {
|
|
257
153
|
if (secretFileKind(part)) return part;
|
|
258
154
|
}
|
|
259
155
|
}
|
|
@@ -261,25 +157,200 @@ function shellSecretRead(c) {
|
|
|
261
157
|
return null;
|
|
262
158
|
}
|
|
263
159
|
|
|
160
|
+
/** A private-key file: `id_rsa`, `id_dsa`, `id_ecdsa`, `id_ed25519` (not `*.pub`), `*.pem`, `*.p12`, `*.pfx`, `*.key`. */
|
|
161
|
+
const PRIVATE_KEY_RE = /(?:^|\/)id_(?:rsa|dsa|ecdsa|ed25519)(?:_sk)?$|\.(?:pem|p12|pfx|key)$/i;
|
|
162
|
+
/** Programs that print the content of the files they are given. */
|
|
163
|
+
const CONTENT_READERS = new Set(
|
|
164
|
+
"cat tac nl head tail less more bat base64 base32 xxd od hexdump strings cut sort uniq fold rev paste column diff grep egrep fgrep rg ag sed awk".split(
|
|
165
|
+
" ",
|
|
166
|
+
),
|
|
167
|
+
);
|
|
168
|
+
/** `openssl` subcommands that print the private key they read, unless told to print none. */
|
|
169
|
+
const OPENSSL_KEY_PRINTERS = new Set(["rsa", "dsa", "ec", "pkey", "pkcs8", "pkcs12", "storeutl"]);
|
|
170
|
+
/** `openssl` subcommands that print an encoding of whatever file they read with `-in`. */
|
|
171
|
+
const OPENSSL_ENCODERS = new Set(["base64", "enc", "asn1parse"]);
|
|
172
|
+
/** Names a key-file glob is tried against, and plain names a narrow glob must not match. */
|
|
173
|
+
const KEY_NAME_SAMPLES = ["id_rsa", "id_dsa", "id_ecdsa", "id_ed25519", "id_ed25519_sk"].concat(
|
|
174
|
+
["pem", "p12", "pfx", "key"].map((ext) => "k." + ext),
|
|
175
|
+
);
|
|
176
|
+
const PLAIN_NAME_SAMPLES = ["k", "k.txt"];
|
|
177
|
+
|
|
178
|
+
/** The regex source for one shell glob: `*`, `?`, `[...]` and `{a,b}`. */
|
|
179
|
+
function globSource(glob) {
|
|
180
|
+
let re = "";
|
|
181
|
+
for (let i = 0; i < glob.length; i++) {
|
|
182
|
+
const ch = glob[i];
|
|
183
|
+
const close = ch === "[" ? glob.indexOf("]", i + 2) : ch === "{" ? glob.indexOf("}", i) : -1;
|
|
184
|
+
if (ch === "*") re += ".*";
|
|
185
|
+
else if (ch === "?") re += ".";
|
|
186
|
+
else if (ch === "[" && close > 0) re += "[" + glob.slice(i + 1, close).replace(/^!/, "^") + "]";
|
|
187
|
+
else if (ch === "{" && close > 0) {
|
|
188
|
+
re +=
|
|
189
|
+
"(?:" +
|
|
190
|
+
glob
|
|
191
|
+
.slice(i + 1, close)
|
|
192
|
+
.split(",")
|
|
193
|
+
.map(globSource)
|
|
194
|
+
.join("|") +
|
|
195
|
+
")";
|
|
196
|
+
} else re += ch.replace(/[.*+?^$()|[\]\\{}]/g, "\\$&");
|
|
197
|
+
if (close > 0 && (ch === "[" || ch === "{")) i = close;
|
|
198
|
+
}
|
|
199
|
+
return re;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Whether a file word names a private-key file, or is a glob that can match one: a glob
|
|
204
|
+
* under a `.ssh/` folder that can match a key name (`~/.ssh/*`, not `~/.ssh/*.pub`), or one
|
|
205
|
+
* that can match a key name and no plain name (`*.pem`, `id_rs?`, `id_{rsa,dsa}`, not `*`).
|
|
206
|
+
*/
|
|
207
|
+
function mayNameKeyFile(word) {
|
|
208
|
+
const p = String(word || "").replace(/\\/g, "/");
|
|
209
|
+
if (PRIVATE_KEY_RE.test(p)) return true;
|
|
210
|
+
if (!/[*?[{]/.test(p)) return false;
|
|
211
|
+
const base = new RegExp("^" + globSource(p.split("/").pop()) + "$", "i");
|
|
212
|
+
if (!KEY_NAME_SAMPLES.some((n) => base.test(n))) return false;
|
|
213
|
+
return /(?:^|\/)\.ssh\//.test(p) || !PLAIN_NAME_SAMPLES.some((n) => base.test(n));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** Options that upload the file named by their value (`curl -T`, `wget --post-file`). */
|
|
217
|
+
const UPLOAD_OPTIONS = new Set(["-T", "--upload-file", "--post-file", "--body-file"]);
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* The key file one parsed command sends off the machine, else null: an `@file` word of any
|
|
221
|
+
* program (`curl -d @key.pem`, `-F f=@key.pem`), a curl / wget upload option's value, or a
|
|
222
|
+
* local source operand of `scp` / `rsync` whose destination is `host:...`.
|
|
223
|
+
*/
|
|
224
|
+
function keySentBy(c) {
|
|
225
|
+
const words = c.words;
|
|
226
|
+
for (let i = 1; i < words.length; i++) {
|
|
227
|
+
const at = /(?:^-[A-Za-z]|^|=)@([^;]+)/.exec(words[i]);
|
|
228
|
+
if (at && mayNameKeyFile(at[1])) return at[1];
|
|
229
|
+
const eq = words[i].startsWith("--") ? words[i].indexOf("=") : -1;
|
|
230
|
+
const [name, value] =
|
|
231
|
+
eq > 0 ? [words[i].slice(0, eq), words[i].slice(eq + 1)] : [words[i], words[i + 1]];
|
|
232
|
+
const uploads = (c.program === "curl" || c.program === "wget") && UPLOAD_OPTIONS.has(name);
|
|
233
|
+
if (uploads && mayNameKeyFile(value)) return value;
|
|
234
|
+
}
|
|
235
|
+
if (c.program !== "scp" && c.program !== "rsync") return null;
|
|
236
|
+
const remote = (w) => /^[^/]*:/.test(w);
|
|
237
|
+
const ops = operands(words.slice(1), VALUE_OPTIONS[c.program]);
|
|
238
|
+
if (ops.length < 2 || !remote(ops.at(-1))) return null;
|
|
239
|
+
return ops.slice(0, -1).find((w) => !remote(w) && mayNameKeyFile(w)) || null;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* The key file one parsed `git` or `openssl` command prints, else null: `git show` /
|
|
244
|
+
* `git cat-file` of `rev:path`, `git diff --no-index`, an `openssl` encoder's `-in` file, or
|
|
245
|
+
* a key printer's input unless it prints only the public key or nothing (`-pubout`,
|
|
246
|
+
* `-noout`, `pkcs12 -nokeys`, each without `-text`).
|
|
247
|
+
*/
|
|
248
|
+
function keyPrintedByTool(c) {
|
|
249
|
+
const words = c.words;
|
|
250
|
+
const g = parseGit(words);
|
|
251
|
+
if (g && (g.sub === "show" || g.sub === "cat-file")) {
|
|
252
|
+
const file = g.args.map((a) => a.slice(a.indexOf(":") + 1 || a.length)).find(mayNameKeyFile);
|
|
253
|
+
return file || null;
|
|
254
|
+
}
|
|
255
|
+
if (g)
|
|
256
|
+
return g.sub === "diff" && g.long.has("--no-index")
|
|
257
|
+
? g.args.find(mayNameKeyFile) || null
|
|
258
|
+
: null;
|
|
259
|
+
if (c.program !== "openssl") return null;
|
|
260
|
+
const sub = words[1];
|
|
261
|
+
const inAt = words.findIndex((w) => w === "-in" || w.startsWith("-in="));
|
|
262
|
+
const named =
|
|
263
|
+
inAt < 0 ? null : words[inAt].startsWith("-in=") ? words[inAt].slice(4) : words[inAt + 1];
|
|
264
|
+
const input = sub === "storeutl" ? words.at(-1) : named;
|
|
265
|
+
if (!mayNameKeyFile(input)) return null;
|
|
266
|
+
if (OPENSSL_ENCODERS.has(sub)) return input;
|
|
267
|
+
if (!OPENSSL_KEY_PRINTERS.has(sub)) return null;
|
|
268
|
+
const has = (o) => words.includes(o);
|
|
269
|
+
const quiet = has("-pubout") || has("-noout") || (sub === "pkcs12" && has("-nokeys"));
|
|
270
|
+
return quiet && !has("-text") ? null : input;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* The key file one parsed content reader prints, else null: an operand of `cat`, `head`,
|
|
275
|
+
* `grep` and the like (after a grep / sed / awk pattern unless an option supplies it, and
|
|
276
|
+
* skipping option values such as `grep -A 2`), or `dd if=`. An in-place `sed -i` prints
|
|
277
|
+
* nothing.
|
|
278
|
+
*/
|
|
279
|
+
function keyPrintedByReader(c) {
|
|
280
|
+
const words = c.words;
|
|
281
|
+
if (c.program === "dd") {
|
|
282
|
+
const input = (words.find((w) => w.startsWith("if=")) || "").slice(3);
|
|
283
|
+
return mayNameKeyFile(input) ? input : null;
|
|
284
|
+
}
|
|
285
|
+
if (!CONTENT_READERS.has(c.program)) return null;
|
|
286
|
+
if (c.program === "sed" && words.some((w) => /^-[a-zA-Z]*i|^--in-place/.test(w))) return null;
|
|
287
|
+
const ops = operands(words.slice(1), VALUE_OPTIONS[c.program]);
|
|
288
|
+
const scripted = PATTERN_HEADS.has(c.program) || c.program === "sed" || c.program === "awk";
|
|
289
|
+
const files = scripted && !patternFromOption(words) ? ops.slice(1) : ops;
|
|
290
|
+
return files.find(mayNameKeyFile) || null;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* The private-key file whose content one of the parsed commands exposes, else null:
|
|
295
|
+
* printed (a reader, a `<` input file, `git show`, `dd`, a key-printing `openssl`
|
|
296
|
+
* subcommand) or sent off the machine (`curl -d @key`, `scp key host:`). A key passed to
|
|
297
|
+
* a program that only uses it (`ssh -i`, `curl --cacert`, `openssl x509 -in`), a write
|
|
298
|
+
* destination (`-out`, `-keyout`, `ssh-keygen -f`) and a word that only names it
|
|
299
|
+
* (`git rm`, `git commit -m`, `ls`) does not expose it.
|
|
300
|
+
*/
|
|
301
|
+
function privateKeyContentRead(cmds) {
|
|
302
|
+
for (const c of cmds) {
|
|
303
|
+
if (mayNameKeyFile(c.stdinFile)) return c.stdinFile;
|
|
304
|
+
const key = keySentBy(c) || keyPrintedByTool(c) || keyPrintedByReader(c);
|
|
305
|
+
if (key) return key;
|
|
306
|
+
}
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
|
|
264
310
|
/**
|
|
265
311
|
* The tier a trimmed command falls in, first match wins:
|
|
266
312
|
* `{ tier: "deny", what, fix }` — blocked on every host;
|
|
267
313
|
* `{ tier: "ask", what }` — a destructive / privileged command;
|
|
268
314
|
* `{ tier: "secret", path }` — a shell read of an env / secrets / private-key file;
|
|
269
|
-
* `{ tier: "fetch" }`
|
|
315
|
+
* `{ tier: "fetch", edits? }` — curl / wget to a host off the network allowlist, with the
|
|
316
|
+
* edit evidence of the same command when it has any;
|
|
270
317
|
* `{ tier: "edit", edits }` — the shell used as an edit channel (advisory only);
|
|
271
318
|
* null — nothing to say.
|
|
272
|
-
*
|
|
319
|
+
* An allowed fetch never hides an edit in the same command. `edits` is the evidence from
|
|
320
|
+
* `shellEditTargets`. `host` is the hook's host (`codex` cannot prompt); `ctx` is the call's
|
|
321
|
+
* `{ cwd, root, dirs }` (`hookContext`).
|
|
273
322
|
*/
|
|
274
|
-
function classifyShell(c,
|
|
323
|
+
function classifyShell(c, host, ctx) {
|
|
275
324
|
if (!c) return null;
|
|
276
|
-
const
|
|
325
|
+
const st = newEvidence(ctx);
|
|
326
|
+
const cmds = shellCommands(c, st);
|
|
327
|
+
const denied = denyRule(cmds);
|
|
277
328
|
if (denied) return { tier: "deny", ...denied };
|
|
278
|
-
|
|
329
|
+
if (host === "codex" && testsJump(cmds)) {
|
|
330
|
+
return {
|
|
331
|
+
tier: "deny",
|
|
332
|
+
what: "bkit tests jump",
|
|
333
|
+
fix: "Every bkit tests jump needs the human's approval and Codex cannot ask. Ask the human to run it in their own terminal.",
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
// Codex cannot prompt, so a command that exposes a private key's content (prints it or
|
|
337
|
+
// sends it off the machine) is denied there whatever tier would win; a command that uses,
|
|
338
|
+
// writes or only names a key file keeps the advisory.
|
|
339
|
+
const keyRead = host === "codex" ? privateKeyContentRead(cmds) : null;
|
|
340
|
+
if (keyRead) {
|
|
341
|
+
return {
|
|
342
|
+
tier: "deny",
|
|
343
|
+
what: `a command that exposes the content of ${keyRead}, a private-key file`,
|
|
344
|
+
fix: "NEVER read or send private keys through the shell. Ask the user to run the step that needs the key.",
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
const what = askRule(cmds);
|
|
279
348
|
if (what) return { tier: "ask", what };
|
|
280
|
-
const secret = shellSecretRead(
|
|
349
|
+
const secret = shellSecretRead(cmds);
|
|
281
350
|
if (secret) return { tier: "secret", path: secret };
|
|
282
|
-
|
|
283
|
-
const edits = shellEditTargets(
|
|
284
|
-
|
|
351
|
+
const offList = usesFetch(cmds) && !curlWgetHostAllowed(cmds, ctx.dirs);
|
|
352
|
+
const edits = shellEditTargets(cmds, st);
|
|
353
|
+
const found = hasEditEvidence(edits);
|
|
354
|
+
if (offList) return found ? { tier: "fetch", edits } : { tier: "fetch" };
|
|
355
|
+
return found ? { tier: "edit", edits } : null;
|
|
285
356
|
}
|