Module: RubynCode::Chisel

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

Overview

Chisel is rubyn-code's opt-in "write the minimum that works" enforcement layer. It is OFF by default and only changes the agent's behavior once a user turns it on (via /chisel full or the config key chisel_mode).

The single source of truth for:

- which intensity modes exist (off/lite/full/ultra),
- which mode is currently active (env override 

The decision ladder is adapted from the open-source ponytail plugin and rebuilt natively here; the safety floor (validation, error/data-loss handling, security, accessibility) is never on the chopping block.

Defined Under Namespace

Modules: Debt, Inspection

Constant Summary collapse

MODES =
%w[off lite full ultra].freeze
DEFAULT_MODE =
'off'
ENV_KEY =
'RUBYN_CHISEL_MODE'
CONFIG_KEY =
'chisel_mode'
LADDER =

The decision ladder — injected at every non-off intensity.

"# Chisel \u2014 write the minimum that works\n\nBefore writing code, stop at the first rung that holds:\n1. Does this need to exist? If not, don't write it. (YAGNI)\n2. Does Ruby's stdlib already do it? Use it.\n3. Does the framework or runtime already do it? Use it.\n4. Does an already-installed gem do it? Use it \u2014 don't add a dependency.\n5. Is it one line? Write one line.\n6. Only then: the smallest change that fully solves the task.\n".strip
FULL_ADDENDUM =

Extra guidance layered on at full and above.

"Prefer editing existing code over adding new files, classes, or layers of\nindirection. Don't introduce an abstraction until a second concrete caller\nexists \u2014 three similar lines beat a premature framework.\n".strip
ULTRA_ADDENDUM =

Extra guidance layered on at ultra only.

"Be aggressive: question every new method, parameter, option, and file. If\nyou can't name the second caller, inline it. When you finish, briefly note\nwhat you deliberately chose NOT to build.\n".strip
SAFETY_FLOOR =

The safety floor — appended at every non-off intensity, last so it is never overridden by the "delete more" guidance above it.

"Lazy, not negligent. Never chisel away: input and trust-boundary\nvalidation, error and data-loss handling, security, or accessibility.\n".strip

Class Method Summary collapse

Class Method Details

.configured_mode ⇒ String?

The persisted mode from config, or nil if unreadable. Isolated so prompt assembly never dies on a malformed config file.

Returns:

  • (String, nil)


119
120
121
122
123
124
125
# File 'lib/rubyn_code/chisel.rb', line 119

def configured_mode
  # No default needed — chisel_mode lives in Settings::DEFAULT_MAP, so an
  # unset key already resolves to DEFAULT_MODE.
  Config::Settings.new.get(CONFIG_KEY)
rescue StandardError
  nil
end

.enabled? ⇒ Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/rubyn_code/chisel.rb', line 96

def enabled?
  mode != 'off'
end

.mode ⇒ String

Resolve the active mode: env override → persisted config → default. Each layer is normalized (trimmed + downcased) the same way the /chisel command normalizes its argument, so RUBYN_CHISEL_MODE=Full and a hand-edited chisel_mode: " Full " both resolve cleanly. Any unrecognized value falls through rather than raising, so a typo can never break a turn.

Returns:

  • (String) —

    one of MODES



77
78
79
80
81
# File 'lib/rubyn_code/chisel.rb', line 77

def mode
  normalize(ENV.fetch(ENV_KEY, nil)) ||
    normalize(configured_mode) ||
    DEFAULT_MODE
end

.normalize(value) ⇒ String?

Trim + downcase a candidate mode, returning it only if recognized, otherwise nil so the caller can fall through to the next layer.

Parameters:

  • value (#to_s, nil)

Returns:

  • (String, nil)


88
89
90
91
92
93
# File 'lib/rubyn_code/chisel.rb', line 88

def normalize(value)
  return nil if value.nil?

  candidate = value.to_s.strip.downcase
  valid?(candidate) ? candidate : nil
end

.prompt_section ⇒ String

The text Chisel contributes to the system prompt for the active mode.

Returns:

  • (String) —

    "" when off; otherwise ladder + intensity addenda + safety floor.



104
105
106
107
108
109
110
111
112
113
# File 'lib/rubyn_code/chisel.rb', line 104

def prompt_section
  current = mode
  return '' if current == 'off'

  parts = [LADDER]
  parts << FULL_ADDENDUM if %w[full ultra].include?(current)
  parts << ULTRA_ADDENDUM if current == 'ultra'
  parts << SAFETY_FLOOR
  parts.join("\n\n")
end

.valid?(value) ⇒ Boolean

Returns whether the value is a recognized mode.

Parameters:

  • value (#to_s)

Returns:

  • (Boolean) —

    whether the value is a recognized mode



65
66
67
# File 'lib/rubyn_code/chisel.rb', line 65

def valid?(value)
  MODES.include?(value.to_s)
end