Class: Crimson::TrustManager
- Inherits:
-
Object
- Object
- Crimson::TrustManager
- Defined in:
- lib/crimson/trust_manager.rb
Overview
Manages directory trust state for loading project context files. Persists trust decisions to a JSON file and prompts users for untrusted directories.
Constant Summary collapse
- CONTEXT_FILE_NAMES =
File names considered as project context files.
%w[ AGENTS.md AGENTS.MD CLAUDE.md CLAUDE.MD GEMINI.md GEMINI.MD ].freeze
Instance Method Summary collapse
-
#has_context_files?(dir) ⇒ Boolean
Check whether a directory contains any project context files.
-
#initialize(trust_file: nil) ⇒ TrustManager
constructor
A new instance of TrustManager.
-
#prompt_trust(cwd) ⇒ Boolean
Prompt the user to trust a directory that has context files.
-
#trusted?(cwd) ⇒ Boolean
Check whether a directory (or an ancestor) is trusted.
Constructor Details
#initialize(trust_file: nil) ⇒ TrustManager
Returns a new instance of TrustManager.
18 19 20 21 |
# File 'lib/crimson/trust_manager.rb', line 18 def initialize(trust_file: nil) @trust_file = trust_file || File.join(Crimson::CONFIG_DIR, "trust.json") @trust_data = load_trust_data end |
Instance Method Details
#has_context_files?(dir) ⇒ Boolean
Check whether a directory contains any project context files.
67 68 69 |
# File 'lib/crimson/trust_manager.rb', line 67 def has_context_files?(dir) CONTEXT_FILE_NAMES.any? { |name| File.exist?(File.join(dir, name)) } end |
#prompt_trust(cwd) ⇒ Boolean
Prompt the user to trust a directory that has context files.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/crimson/trust_manager.rb', line 34 def prompt_trust(cwd) = File.(cwd) return true unless has_context_files?() return true if trusted?() prompt = TTY::Prompt.new puts choice = prompt.select("Trust this project?\n#{}\n\nThis allows loading AGENTS.md and project settings.", [ { name: "Trust", value: :trust }, { name: "Trust parent folder (#{File.dirname()})", value: :trust_parent }, { name: "Trust (this session only)", value: :session_only }, { name: "Don't trust", value: :deny } ]) case choice when :trust save_trust(, true) true when :trust_parent save_trust(File.dirname(), true) save_trust(, nil) true when :session_only true when :deny save_trust(, false) false end end |
#trusted?(cwd) ⇒ Boolean
Check whether a directory (or an ancestor) is trusted.
26 27 28 29 |
# File 'lib/crimson/trust_manager.rb', line 26 def trusted?(cwd) entry = find_nearest_trust(File.(cwd)) entry == true end |