Skip to content

feat(miner): add PreToolUse-style deny-hook primitives#2688

Closed
dhgoal wants to merge 1 commit into
JSONbored:mainfrom
dhgoal:feat/miner-deny-hook-primitives
Closed

feat(miner): add PreToolUse-style deny-hook primitives#2688
dhgoal wants to merge 1 commit into
JSONbored:mainfrom
dhgoal:feat/miner-deny-hook-primitives

Conversation

@dhgoal

@dhgoal dhgoal commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds the PreToolUse-style deny-hook primitives to @jsonbored/gittensory-miner: a pure, deterministic evaluateDenyHooks(toolCall, rules) decision function plus a non-empty built-in DEFAULT_DENY_RULES set, so the miner package has a checked, testable place to enforce house rules before any later phase wires a real coding-agent tool-call loop through it.

This is the deterministic rule-evaluator only — there is no live tool-call interception in this phase (that needs a real coding-agent driver, out of scope here). The module never executes, intercepts, or mutates anything; a later phase's real hook wiring calls the verdict.

A DenyRule is { matcher, pathPattern?, inputIncludesAll?, reason }. A rule fires when its tool-name matcher matches and every constraint it declares matches: pathPattern (a glob) against any path-shaped string in the tool-call input, and/or inputIncludesAll (substrings that must all appear in one string field, e.g. a shell command). The built-in rules mirror the forbidden-path regex in scripts/check-mcp-package.mjs — block .github/workflows/**, .env*, **/secret*/**, **/*private*key* — plus a conservative git force-push guard (a command carrying both push and --force). An empty rule set, or a call matching no rule, always allows.

inputIncludesAll is a minimal, data-driven extension of the example DenyRule shape: the required force-push guard is a command-content check that a path glob cannot express, so it is modeled generally (order-independent substring set) rather than as a one-off special case.

Closes #2295.

Follow-up (not in scope here)

The issue also lists wiring a status line into gittensory-miner doctor. That command does not exist yet — it comes from the CLI-entry-point issue (#2288), which is still open (and #2614 is an open PR for the laptop-mode doctor). Adding a doctor command here would duplicate/overlap that work, so the one-line "deny-hook module loads, default rule set non-empty" check is deferred to land alongside the CLI entry point. The primitive and its default set are complete and ready to wire; the non-empty invariant is already pinned by a test here.

Scope

Validation

  • git diff --check
  • npm run typecheck
  • npm run test:coverage locally — the new test/unit/miner-deny-hooks.test.ts passes; the whole suite is green. (This change lives entirely in packages/**, which Codecov does not measure, so it carries no codecov/patch obligation; the logic is nonetheless covered on both sides of every built-in rule.)
  • node --check lib/deny-hooks.js via npm run --workspace @jsonbored/gittensory-miner build
  • npm audit --audit-level=moderate — this PR adds no dependencies, so dependency-review has nothing new to evaluate.
  • New behavior has unit tests for new branches (each built-in rule fires and does not fire; empty-rule-set and no-match allow paths; matcher/pathPattern/array-field/force-push-order composition; malformed-input degrade-to-allow).

If any required check was skipped, explain why:

  • UI/OpenAPI/migration/workers checks are not applicable: this change is a single pure module in packages/gittensory-miner/lib plus its test — no src/**, UI, API schema, DB, or Cloudflare-binding surface is touched.

Safety

  • No secrets, wallet details, hotkeys, coldkeys, user PATs, private keys, raw trust scores, private rankings, or private maintainer evidence are exposed. (The built-in rules reference secret-bearing path patterns as deny targets; no secret values appear.)
  • Public GitHub text stays sanitized, low-noise, and does not imply compensation guarantees or optimization tactics.
  • Auth, cookie, CORS, GitHub App, Cloudflare, or session changes include negative-path tests. — n/a: pure decision function, no auth/session/network surface.
  • API/OpenAPI/MCP behavior is updated and tested where needed. — n/a: no API/OpenAPI/MCP surface changed.
  • UI changes use live API data or real states. — n/a: no UI change.
  • Visible UI changes include a UI Evidence section. — n/a: no visible UI, frontend, docs, or extension change.
  • Public docs/changelogs are updated where needed; changelogs are only edited for release-prep PRs.

Notes

Additive: two new files (lib/deny-hooks.js + its lib/deny-hooks.d.ts) mirroring the package's existing hand-authored JS+.d.ts pattern (lib/opportunity-fanout.*), one line added to the package build (node --check) gate, and one new test file. No existing code is modified.

@dhgoal
dhgoal requested a review from JSONbored as a code owner July 3, 2026 05:55
@dosubot dosubot Bot added the size:L label Jul 3, 2026
@superagent-security

Copy link
Copy Markdown
Contributor

🚨 Contributor flagged. Click here for more info: Superagent Dashboard

@superagent-security superagent-security Bot added the contributor:flagged Contributor flagged for review by trust analysis. label Jul 3, 2026
@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.15%. Comparing base (f207263) to head (c16514c).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2688      +/-   ##
==========================================
+ Coverage   96.13%   96.15%   +0.01%     
==========================================
  Files         239      240       +1     
  Lines       26739    26866     +127     
  Branches     9699     9750      +51     
==========================================
+ Hits        25705    25832     +127     
  Misses        424      424              
  Partials      610      610              
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Add a pure, deterministic evaluateDenyHooks(toolCall, rules) decision function
plus a non-empty DEFAULT_DENY_RULES set to @jsonbored/gittensory-miner, so the
package has a checked, testable place to enforce house rules before a later
phase wires a real coding-agent tool-call loop through it. No live interception
in this phase — the module never executes, intercepts, or mutates anything.

Built-in rules mirror the forbidden paths in scripts/check-mcp-package.mjs
(.github/workflows/**, .env*, secret-bearing paths, private key material) plus a
conservative git force-push guard (a command carrying both push and --force). An
empty rule set, or a call matching no rule, always allows.

Closes JSONbored#2295.
@loopover-orb

loopover-orb Bot commented Jul 3, 2026

Copy link
Copy Markdown

Warning

🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨

⏸️ Gittensory review result - manual review recommended

Review updated: 2026-07-03 06:10:03 UTC

4 files · 1 AI reviewer · no blockers · readiness 80/100 · CI green · clean

⏸️ Suggested Action - Manual Review

Review summary
The change adds a standalone deny-rule evaluator with default rules and focused unit coverage for the intended matcher/path/content behavior. The core evaluator is deterministic and the visible tests cover the built-in rules, empty rule sets, matcher-only rules, and top-level array fields. The most notable gap is that path globs only evaluate whole top-level string values, so command strings containing protected paths are not covered unless a later caller tokenizes them first.

Nits — 5 non-blocking
  • nit: `packages/gittensory-miner/lib/deny-hooks.js:45` only collects top-level strings and string arrays, so either document that callers must pre-extract paths from command-shaped inputs or add coverage for the intended behavior.
  • nit: `packages/gittensory-miner/lib/deny-hooks.js:68` treats `inputIncludesAll: []` as satisfied for any string input, which is surprising for a declared constraint; consider rejecting empty substring sets or documenting the vacuous-match behavior.
  • nit: `packages/gittensory-miner/lib/deny-hooks.d.ts:15` makes `name` and `input` required even though the implementation deliberately tolerates malformed calls; align the public type with the runtime contract if callers are expected to use that degraded path.
  • Add a test in `test/unit/miner-deny-hooks.test.ts` for a command string that references a protected path, and either support tokenized command-path matching in `packages/gittensory-miner/lib/deny-hooks.js` or explicitly assert that only structured path fields are in scope.
  • In `packages/gittensory-miner/lib/deny-hooks.js`, treat an empty `inputIncludesAll` as a non-match or invalid rule so accidental empty constraints do not broaden a rule.
Signal Result Evidence
Code review ✅ No blockers 1 reviewer
Linked issue ✅ Linked #2295
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (size label size:L; 1 linked issue).
Validation posture ❌ 5/25 Preflight is holding this PR: the review lane is unavailable, so it is not ready for automated review.
Contributor workload ✅ 10/10 Author activity: 0 registered-repo PR(s), 0 merged, 0 issue(s).
Contributor context ❌ No public Gittensor match dhgoal; not a blocker.
Gate result ✅ Passing No configured blocker found.
Review context
  • Author: dhgoal
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository registration is not available in the local Gittensory cache.
  • Public profile languages: not available
  • Contributor context: Public profile only; not a blocker.
  • PR-specific overlap: none found.
Contributor next steps
  • Await review-lane availability.
  • Refresh registry data or choose a registered active repo.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.

  • Re-run Gittensory review

@JSONbored JSONbored left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix this:

The most notable gap is that path globs only evaluate whole top-level string values, so command strings containing protected paths are not covered unless a later caller tokenizes them first.

@dhgoal

dhgoal commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Fixed. The evaluator now tokenizes each input string (whitespace-split, quotes stripped) and tests every path glob against the whole value and each token, so a protected path embedded as a command argument — e.g. git add .github/workflows/ci.yml — is caught without relying on a later caller to pre-split the command. Added a regression test covering an embedded workflow path, an embedded secret path, and a benign command that stays allowed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor:flagged Contributor flagged for review by trust analysis.

Development

Successfully merging this pull request may close these issues.

feat(miner-foundation): PreToolUse-style deny-hook primitives for gittensory-miner

2 participants