Module: RubynCode::Chisel::Inspection

Defined in:
lib/rubyn_code/chisel/inspection.rb

Overview

Builds the over-engineering audit instruction shared by /chisel-review (scope: :diff) and /chisel-audit (scope: :repo). Both judge by the same decision ladder and exclude the same safety floor, so the two commands can never drift apart — they differ only in what code they look at.

Detection is delegated to the agent and its tools (git_diff, bash, grep, read_file); this module only assembles the prompt.

Constant Summary collapse

SMELLS =
"Flag code that skips a rung of the ladder:\n- speculative abstractions, wrappers, or base classes with a single caller\n- reinvented stdlib or already-installed-gem functionality\n- needless indirection, configurability, or options nobody uses\n- dead parameters, unused branches, premature generalization\n- a class where a method would do; a method where one line would do\n".strip
OUTPUT_CONTRACT =
"Return a ranked deletion/simplification list, most impactful first. For\neach item give:\n- `file:line`\n- what it is (one line)\n- which rung of the ladder it skipped\n- the concrete simpler form (delete it / inline it / replace with stdlib X)\n\nIf nothing is over-engineered, say so plainly instead of inventing work.\n".strip
READ_ONLY_NOTE =
'This is a READ-ONLY review: report the list, do not edit any files.'

Class Method Summary collapse

Class Method Details

.diff_lead_in(base) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/rubyn_code/chisel/inspection.rb', line 72

def diff_lead_in(base)
  "    Chisel review \u2014 find over-engineering in my current changes.\n\n    Gather the diff with `git diff \#{base}...` plus any uncommitted changes\n    (`git diff` and `git diff --staged`). Judge ONLY the added or changed\n    lines against the Chisel decision ladder below.\n  LEAD\nend\n".strip

.guardrails ⇒ String

Read-only guard + the shared safety floor, reused verbatim from Chisel so the exclusion list can never drift from the always-on ruleset.

Returns:



51
52
53
54
# File 'lib/rubyn_code/chisel/inspection.rb', line 51

def guardrails
  "#{READ_ONLY_NOTE}\n\n#{Chisel::SAFETY_FLOOR}\n" \
    'Those are never over-engineering — leave them even if they add code.'
end

.lead_in(scope, target) ⇒ String

Returns:



57
58
59
60
61
62
63
# File 'lib/rubyn_code/chisel/inspection.rb', line 57

def lead_in(scope, target)
  case scope
  when :diff then diff_lead_in(presence(target) || 'main')
  when :repo then repo_lead_in(presence(target))
  else raise ArgumentError, "unknown Chisel inspection scope: #{scope.inspect}"
  end
end

.presence(value) ⇒ String?

Returns the trimmed value, or nil if blank.

Parameters:

Returns:

  • the trimmed value, or nil if blank



67
68
69
70
# File 'lib/rubyn_code/chisel/inspection.rb', line 67

def presence(value)
  str = value.to_s.strip
  str.empty? ? nil : str
end

.prompt(scope:, target: nil) ⇒ String

Returns the full instruction to send to the agent.

Parameters:

  • :diff (review changes) or :repo (audit codebase)

  • (defaults to: nil)

    base ref for :diff (default "main"), or an optional path to scope :repo

Returns:

  • the full instruction to send to the agent

Raises:

  • on an unknown scope



42
43
44
45
# File 'lib/rubyn_code/chisel/inspection.rb', line 42

def prompt(scope:, target: nil)
  [lead_in(scope, target), Chisel::LADDER, SMELLS, OUTPUT_CONTRACT, guardrails]
    .join("\n\n")
end

.repo_lead_in(path) ⇒ Object



82
83
84
85
86
87
88
89
90
# File 'lib/rubyn_code/chisel/inspection.rb', line 82

def repo_lead_in(path)
  scope_line = path ? "Scope the sweep to `#{path}`." : 'Sweep the whole repository.'
  "    Chisel audit \u2014 find accumulated over-engineering in this codebase.\n\n    \#{scope_line} Use grep and file reads to survey the code, then judge it\n    against the Chisel decision ladder below.\n  LEAD\nend\n".strip