Skip to content

feat(hooks): support multiple custom policy file paths in customPolic… - #620

Open
AVPthegreat wants to merge 2 commits into
FailproofAI:mainfrom
AVPthegreat:feat/support-multiple-custom-policy-paths
Open

feat(hooks): support multiple custom policy file paths in customPolic…#620
AVPthegreat wants to merge 2 commits into
FailproofAI:mainfrom
AVPthegreat:feat/support-multiple-custom-policy-paths

Conversation

@AVPthegreat

@AVPthegreat AVPthegreat commented Jul 29, 2026

Copy link
Copy Markdown

Summary

Fixes #60 by updating customPoliciesPath to support string | string[] across HooksConfig, loadCustomHooks, loadAllCustomHooks, and manager.ts CLI output.


❌ Motivation & Problem

Previously, customPoliciesPath in policies-config.json only accepted a single string file path (string). If a user or team wanted to specify multiple custom policy files explicitly across different directories, customPoliciesPath could not accept an array of file paths (string[]).


✅ Feature Implementation

  1. Type Signature Update (src/hooks/policy-types.ts):
    Updated HooksConfig type definition:

    export interface HooksConfig {
      // ...
      customPoliciesPath?: string | string[];
    }
  2. Custom Hook Loader (src/hooks/custom-hooks-loader.ts):
    Updated loadCustomHooks and loadAllCustomHooks to handle string | string[] | undefined:

    • Normalizes input with Array.isArray(customPoliciesPath) ? customPoliciesPath : [customPoliciesPath].
    • Iterates through all specified paths and loads custom policies from each valid file.
  3. CLI & Management Plumbing (src/hooks/manager.ts):

    • Updated installHooks / installHooksImpl parameters to accept string | string[].
    • Updated path resolution logic to map array items with resolve(p).
    • Updated listHooks output formatting to render each custom policy file section cleanly.

🧪 Unit Tests & Verification

Added unit test in __tests__/hooks/custom-hooks-loader.test.ts:

it("loads multiple custom policy files when customPoliciesPath is an array", async () => {
  const { existsSync } = await import("node:fs");
  vi.mocked(existsSync).mockReturnValue(true);

  const { rewriteFileTree } = await import("../../src/hooks/loader-utils");
  vi.mocked(rewriteFileTree).mockResolvedValue([
    { src: "/path/one.js", dst: "/path/one.__failproofai_tmp__.mjs" },
  ]);

  const { loadCustomHooks } = await import("../../src/hooks/custom-hooks-loader");
  await loadCustomHooks(["/path/one.js", "/path/two.js"]);
  expect(rewriteFileTree).toHaveBeenCalledTimes(2);
});

Test Results:

  • Ran vitest run __tests__/hooks/custom-hooks-loader.test.ts __tests__/hooks/hooks-config.test.ts
  • Result: ✓ 48 passed (48)

Summary by CodeRabbit

  • New Features

    • Custom hook policies can now be configured using multiple file paths.
    • Hook installation and loading support both individual paths and path lists.
    • Hook listings display all configured custom policy paths.
  • Bug Fixes

    • Missing custom policy files are handled and reported individually.
    • Improved messaging for custom hook paths and cases where no hooks are registered.
  • Tests

    • Added coverage for loading custom hooks from multiple policy files.

Copilot AI review requested due to automatic review settings July 29, 2026 07:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@hermes-exosphere

Copy link
Copy Markdown
Contributor

Your PR is awaiting review by a reviewer. Till then you can join the Discord for conversation: https://discord.befailproof.ai

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@AVPthegreat, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 52 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7bd56c32-4c74-4d0a-a63e-b2dd43cbe164

📥 Commits

Reviewing files that changed from the base of the PR and between 62862e6 and c86992d.

📒 Files selected for processing (1)
  • __tests__/hooks/custom-hooks-loader.test.ts
📝 Walkthrough

Walkthrough

customPoliciesPath now accepts one or multiple files. Installation, loading, validation messages, and hook listing handle each path independently, with tests covering array-based loading.

Changes

Multiple custom policy paths

Layer / File(s) Summary
Policy path contract and installation
src/hooks/policy-types.ts, src/hooks/manager.ts
Configuration and installation accept arrays, resolve each path, and format array-aware validation and console messages.
Multi-path hook loading
src/hooks/custom-hooks-loader.ts, __tests__/hooks/custom-hooks-loader.test.ts
Loaders iterate through explicit paths, warn or throw for missing files, and test loading two paths.
Custom policy listing
src/hooks/manager.ts
listHooks renders status information separately for each configured custom policy path.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

  • #60 — Adds support for registering and loading multiple custom policy files.

Suggested reviewers: copilot

Poem

I’m a bunny with paths in a row,
Watching each custom hook load and grow.
One file, two files, neatly in flight,
Missing ones warn; strict ones bite.
The policy garden now blooms bright! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main change: support for multiple custom policy file paths.
Description check ✅ Passed The description covers the problem, solution, and testing, even though it uses custom headings instead of the template.
Linked Issues check ✅ Passed The change implements #60 by allowing customPoliciesPath arrays across config, loading, and CLI display.
Out of Scope Changes check ✅ Passed The changes stay focused on multi-path custom policy support and the added unit test.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/hooks/manager.ts (1)

219-246: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Reject empty policy files individually.

A valid file masks another configured file that registers no hooks because validatedHooks is aggregated. Validate each path sequentially and reject any zero-hook file before persisting the configuration.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hooks/manager.ts` around lines 219 - 246, Update the custom policy
validation around loadCustomHooks so each configured path is loaded and checked
individually, rejecting immediately when any file returns zero hooks instead of
relying on the aggregated validatedHooks length. Preserve strict loading,
tracking, and error reporting, and only persist the configuration after every
path has registered at least one hook.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@__tests__/hooks/custom-hooks-loader.test.ts`:
- Around line 48-51: Update the rewriteFileTree mock in the custom hooks loader
test to resolve an array of temporary-path strings, not source/destination
objects; use the expected __failproofai_tmp__ path string so it matches the
loader and cleanup contract.

---

Outside diff comments:
In `@src/hooks/manager.ts`:
- Around line 219-246: Update the custom policy validation around
loadCustomHooks so each configured path is loaded and checked individually,
rejecting immediately when any file returns zero hooks instead of relying on the
aggregated validatedHooks length. Preserve strict loading, tracking, and error
reporting, and only persist the configuration after every path has registered at
least one hook.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 57d6afc0-0d65-4ee4-83c0-04077cc4f6f7

📥 Commits

Reviewing files that changed from the base of the PR and between af74838 and 62862e6.

📒 Files selected for processing (4)
  • __tests__/hooks/custom-hooks-loader.test.ts
  • src/hooks/custom-hooks-loader.ts
  • src/hooks/manager.ts
  • src/hooks/policy-types.ts

Comment thread __tests__/hooks/custom-hooks-loader.test.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feat]: support multiple custom paths policy file paths

3 participants