Class: Binpacker::ProjectState

Inherits:
Object
  • Object
show all
Defined in:
lib/binpacker/project_state.rb,
sig/binpacker/project_state.rbs

Overview

Inspects the working directory to report binpacker's setup state and recommend the next skill. Backs binpacker describe. See docs/design/agent-workflows.md.

Constant Summary collapse

CONFIG_FILE =

Returns:

  • (String)
"binpacker.yml"
DEFAULT_TIMING_FILE =

Returns:

  • (String)
"binpacker.timings"
SUPPORTED_FRAMEWORKS =

Returns:

  • (Array[String])
%w[rspec minitest].freeze
TESTUNIT_HINT =

Returns:

  • (Regexp)
%r{test-unit|test/unit}

Instance Method Summary collapse

Instance Method Details

#ci_wired?Boolean

Returns:

  • (Boolean)


36
37
38
39
40
# File 'lib/binpacker/project_state.rb', line 36

def ci_wired?
  Dir.glob(".github/workflows/*.{yml,yaml}").any? do |wf|
    File.read(wf).include?("binpacker run")
  end
end

#config_present?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/binpacker/project_state.rb', line 13

def config_present?
  File.exist?(CONFIG_FILE)
end

#frameworkString?

"rspec", "minitest", "test-unit", or nil. Minitest and test-unit share the *_test.rb convention, so they are told apart by dependency hints.

Returns:

  • (String, nil)


23
24
25
26
27
# File 'lib/binpacker/project_state.rb', line 23

def framework
  return minitest_family if minitest_globs?
  return "rspec" if Dir.glob("spec/**/*_spec.rb").any?
  nil
end

#recommendationString

The skill the agent should run next.

Returns:

  • (String)


43
44
45
46
# File 'lib/binpacker/project_state.rb', line 43

def recommendation
  return "binpacker-setup" unless config_present? && timing_present?
  "binpacker-improve"
end

#supported_framework?Boolean

binpacker ships runners for rspec and minitest only. A detected framework outside that set (e.g. test-unit) is unsupported; nil is merely unknown.

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/binpacker/project_state.rb', line 31

def supported_framework?
  fw = framework
  fw.nil? || SUPPORTED_FRAMEWORKS.include?(fw)
end

#timing_present?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/binpacker/project_state.rb', line 17

def timing_present?
  File.exist?(timing_file)
end

#to_hHash[Symbol, untyped]

Returns:

  • (Hash[Symbol, untyped])


48
49
50
51
52
53
54
55
56
# File 'lib/binpacker/project_state.rb', line 48

def to_h
  {
    config_present: config_present?,
    timing_present: timing_present?,
    framework: framework,
    ci_wired: ci_wired?,
    recommendation: recommendation
  }
end