robot_lab-audit 0.2.7 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd6e47211bfc31f854f89128e97ee43b5df24dd1e72a1845145c5592f3d6678c
4
- data.tar.gz: 5f23a6f3dd37b8453e98e2d1e637e4697c1d6d56eacc338f0ac1642b312ebf9c
3
+ metadata.gz: 69728f6acae0f6fc5e2ed44978b92987e4259909c9ca2331d09a6ecd0363ea88
4
+ data.tar.gz: 81c533106e0cbdda74cefe354d90e7c1374f97c5cdfe30e5a51aed1397853b84
5
5
  SHA512:
6
- metadata.gz: af6ab9e243f5537c1a06d61ad04956240aa1a7cc4e07b3d4c3262121d63f8b6191a6e6a6f9d3e535c17bcfbea7c21bbc9ee572646f5657301a84fae96a2d7bd8
7
- data.tar.gz: d565c5353d618bc546e6e37e4ebfc3473011eb15f34334d9803ce1f92cba00b5274a20f045393920fea827a3b1e8db5624a9b321d589067d48393d336f414200
6
+ metadata.gz: 03b2c5ac748d6bfcca5e6755342ede0ed38a3a19b9f6d53f6824936963559dcf7655b623eef1bb913758735e3a6387e3eb262e4b845e552944be7620e1b18447
7
+ data.tar.gz: 85126e3cd486cde65d207d599bec314fc9285255cfd19fa008558993152d89e3eeeb2aaf3d0ce5afcc095d8796f4212937a34c435c15a4f0371a3af5eb5ca212
data/.envrc CHANGED
@@ -1,3 +1,6 @@
1
+ # robot_lab_project/robot_lab-audit/.envrc
2
+
1
3
  source_up
2
- export RR=`pwd`
3
- export BUNDLE_GEMFILE=Gemfile
4
+
5
+ export RR=$(pwd)
6
+ # BUNDLE_GEMFILE is inherited from the project root .envrc (asgard dev|prod)
data/CHANGELOG.md CHANGED
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.2.8] - 2026-09-09
11
+
12
+ Released in lockstep with `robot_lab` core v0.2.8: this gem now resolves the released core gem from RubyGems instead of the local sibling checkout (local-path development remains available via `BUNDLE_GEMFILE=Gemfile.local`). Also in this release: gem lifecycle tasks (build/install/release) moved from the Rakefile to the asgard task runner.
13
+
10
14
  ### Added
11
15
  - `.loki` Asgard task file: `test`, `rubocop`, `rubocop_fix`, `flog`, `flay`, `quality`, `build`, `install`, `release`, and `console` tasks via the Asgard task runner
12
16
  - `flay_check` Rake task: structural code duplication gate (mass threshold 50); integrated into the `quality` Rake task
data/Rakefile CHANGED
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/gem_tasks'
4
3
  require 'rake/testtask'
5
4
 
6
5
  Rake::TestTask.new(:test) do |t|
@@ -24,101 +23,6 @@ task :test_file, [:file] do |_t, args|
24
23
  ruby "test/#{args[:file]}"
25
24
  end
26
25
 
27
- desc 'Check code complexity with Flog (warn >=20, fail >=50)'
28
- task :flog_check do
29
- require 'flog'
30
-
31
- method_warn = 20.0
32
- method_fail = 50.0
33
-
34
- flogger = Flog.new(all: true)
35
- flogger.flog(*Dir.glob('lib/**/*.rb'))
36
-
37
- warnings = []
38
- failures = []
39
-
40
- flogger.each_by_score do |method, score|
41
- next if method.end_with?('#none')
42
-
43
- if score > method_fail
44
- failures << "#{format('%.1f', score)}: #{method}"
45
- elsif score > method_warn
46
- warnings << "#{format('%.1f', score)}: #{method}"
47
- end
48
- end
49
-
50
- unless warnings.empty?
51
- puts "\nFlog warnings (#{method_warn}–#{method_fail}) — target for future refactoring:"
52
- warnings.each { |v| puts " #{v}" }
53
- end
54
-
55
- if failures.empty?
56
- puts "\nFlog: no methods exceed the failure threshold (>=#{method_fail})"
57
- else
58
- puts "\nFlog failures (>=#{method_fail}) — must be refactored:"
59
- failures.each { |v| puts " #{v}" }
60
- abort "\nFlog quality gate failed: #{failures.size} method(s) exceed #{method_fail}"
61
- end
62
- end
63
-
64
- desc 'Check for structural code duplication with Flay (mass >= 50)'
65
- task :flay_check do
66
- require 'flay'
67
-
68
- mass_threshold = 50
69
-
70
- flay = Flay.new({ mass: mass_threshold, diff: false, verbose: false, summary: false, timeout: 60 })
71
- flay.process(*Dir.glob('lib/**/*.rb'))
72
- flay.analyze
73
-
74
- if flay.hashes.empty?
75
- puts "\nFlay: no structural duplication detected (mass >= #{mass_threshold})"
76
- else
77
- puts "\nFlay found structural duplication (mass >= #{mass_threshold}):"
78
- flay.report
79
- abort "\nFlay quality gate failed: #{flay.hashes.length} pattern(s) detected"
80
- end
81
- end
82
-
83
- desc 'Run all quality checks: tests (with coverage), RuboCop, Flog, and Flay'
84
- task :quality do
85
- gates = [
86
- ['Tests + Coverage', 'bundle exec rake test'],
87
- ['RuboCop', 'bundle exec rubocop'],
88
- ['Flog Complexity', 'bundle exec rake flog_check'],
89
- ['Flay Duplication', 'bundle exec rake flay_check']
90
- ]
91
-
92
- results = gates.map do |label, command|
93
- puts "\n#{'=' * 60}"
94
- puts "Quality Gate: #{label}"
95
- puts '=' * 60
96
- [label, system(command) ? :pass : :fail]
97
- end
98
-
99
- green = ->(s) { "\e[32m#{s}\e[0m" }
100
- red = ->(s) { "\e[31m#{s}\e[0m" }
101
- width = results.map { |label, _| label.length }.max
102
-
103
- puts "\n#{'=' * 60}"
104
- puts 'Quality Gate Summary'
105
- puts '=' * 60
106
- results.each do |label, status|
107
- badge = status == :pass ? green.call('PASS') : red.call('FAIL')
108
- puts " [#{badge}] #{label.ljust(width)}"
109
- end
110
- puts '-' * 60
111
-
112
- passed = results.count { |_, s| s == :pass }
113
- failed = results.count { |_, s| s == :fail }
114
- tally = "#{passed} passed, #{failed} failed"
115
- puts " #{failed.zero? ? green.call(tally) : red.call(tally)}"
116
- puts '=' * 60
117
-
118
- abort "\n#{red.call('Quality gate failed.')}" unless failed.zero?
119
- puts "\n#{green.call('All quality gates passed.')}"
120
- end
121
-
122
26
  namespace :docs do
123
27
  desc 'Build MkDocs documentation'
124
28
  task :build do
@@ -33,7 +33,7 @@ end
33
33
 
34
34
  class WordCountTool < RobotLab::Tool
35
35
  description 'Counts words in a text string'
36
- param :text, type: 'string', desc: 'The text to analyse'
36
+ parameter :text, type: 'string', description: 'The text to analyse'
37
37
 
38
38
  def execute(text:)
39
39
  { word_count: text.split.size, status: 'ok' }
@@ -43,7 +43,7 @@ end
43
43
 
44
44
  class SentimentTool < RobotLab::Tool
45
45
  description 'Returns a sentiment score for a text string'
46
- param :text, type: 'string', desc: 'The text to score'
46
+ parameter :text, type: 'string', description: 'The text to score'
47
47
 
48
48
  def execute(text:)
49
49
  score = text.downcase.include?('great') ? 0.9 : 0.5
@@ -54,7 +54,7 @@ end
54
54
 
55
55
  class FailingTool < RobotLab::Tool
56
56
  description 'Always raises a ToolError (for error logging demo)'
57
- param :reason, type: 'string', desc: 'Failure reason'
57
+ parameter :reason, type: 'string', description: 'Failure reason'
58
58
 
59
59
  def execute(reason:)
60
60
  raise RobotLab::ToolError, "Simulated failure: #{reason}"
@@ -198,8 +198,8 @@ word_count.instance_variable_set(:@robot, analyst)
198
198
  sentiment = SentimentTool.new
199
199
  sentiment.instance_variable_set(:@robot, analyst)
200
200
 
201
- word_count.call({ 'text' => input })
202
- sentiment.call({ 'text' => input })
201
+ word_count.call(**{ 'text' => input })
202
+ sentiment.call(**{ 'text' => input })
203
203
 
204
204
  all_tool_events = log.instance_variable_get(:@db)
205
205
  .execute("SELECT * FROM audit_events WHERE event_type = 'tool_call'")
@@ -224,7 +224,7 @@ TEXT
224
224
 
225
225
  failing = FailingTool.new
226
226
  failing.instance_variable_set(:@robot, analyst)
227
- failing.call({ 'reason' => 'network timeout' })
227
+ failing.call(**{ 'reason' => 'network timeout' })
228
228
 
229
229
  print_events(log.recent_errors, label: 'recent_errors (newest first):')
230
230
 
data/examples/common.rb CHANGED
@@ -7,6 +7,9 @@ require_relative '../lib/robot_lab/audit'
7
7
 
8
8
  RubyLLM.configure do |c|
9
9
  c.logger = Logger.new(File::NULL)
10
+ # The demo robots stub out chat.ask, so no request ever reaches a provider —
11
+ # but ruby_llm 2.0 validates provider configuration when the chat is built.
12
+ c.anthropic_api_key = ENV.fetch("ANTHROPIC_API_KEY", "stub-key-never-used")
10
13
  end
11
14
 
12
15
  RobotLab.configure do |c|
@@ -44,6 +44,9 @@ module RobotLab
44
44
  @db.execute_batch(SCHEMA)
45
45
  end
46
46
 
47
+ # :reek:LongParameterList -- one required keyword per SCHEMA column, on
48
+ # purpose: a caller that forgets a column raises ArgumentError instead
49
+ # of silently inserting NULL.
47
50
  def record_network_run(run_id:, network_name:, input:, result:, error_class:,
48
51
  error_message:, started_at:, finished_at:, duration_ms:)
49
52
  @db.execute(
@@ -56,6 +59,9 @@ module RobotLab
56
59
  )
57
60
  end
58
61
 
62
+ # :reek:LongParameterList -- one required keyword per SCHEMA column, on
63
+ # purpose: a caller that forgets a column raises ArgumentError instead
64
+ # of silently inserting NULL.
59
65
  def record_event(run_id:, event_type:, robot_name:, tool_name:, input:, output:,
60
66
  error_class:, error_message:, started_at:, finished_at:, duration_ms:)
61
67
  @db.execute(
@@ -70,12 +76,12 @@ module RobotLab
70
76
 
71
77
  def network_runs(limit: 100)
72
78
  rows = @db.execute('SELECT * FROM network_runs ORDER BY started_at DESC LIMIT ?', [limit])
73
- rows.map { |r| row_to_hash(:network_runs, r) }
79
+ rows.map { |r| row_to_hash(NETWORK_RUN_COLUMNS, r) }
74
80
  end
75
81
 
76
82
  def events_for(run_id)
77
83
  rows = @db.execute('SELECT * FROM audit_events WHERE run_id = ? ORDER BY started_at', [run_id])
78
- rows.map { |r| row_to_hash(:audit_events, r) }
84
+ rows.map { |r| row_to_hash(AUDIT_EVENT_COLUMNS, r) }
79
85
  end
80
86
 
81
87
  def recent_errors(limit: 50)
@@ -83,7 +89,7 @@ module RobotLab
83
89
  'SELECT * FROM audit_events WHERE error_class IS NOT NULL ORDER BY started_at DESC LIMIT ?',
84
90
  [limit]
85
91
  )
86
- rows.map { |r| row_to_hash(:audit_events, r) }
92
+ rows.map { |r| row_to_hash(AUDIT_EVENT_COLUMNS, r) }
87
93
  end
88
94
 
89
95
  NETWORK_RUN_COLUMNS = %i[id run_id network_name input result error_class
@@ -93,9 +99,8 @@ module RobotLab
93
99
 
94
100
  private
95
101
 
96
- def row_to_hash(table, row)
97
- cols = table == :network_runs ? NETWORK_RUN_COLUMNS : AUDIT_EVENT_COLUMNS
98
- cols.zip(row).to_h
102
+ def row_to_hash(columns, row)
103
+ columns.zip(row).to_h
99
104
  end
100
105
  end
101
106
  end
@@ -5,6 +5,12 @@ require 'json'
5
5
 
6
6
  module RobotLab
7
7
  module Audit
8
+ # :reek:RepeatedConditional -- each callback independently no-ops when
9
+ # event_log is nil, so the hook can be registered globally (RobotLab.on)
10
+ # before Audit.enable ever runs, or scoped to one robot/network without
11
+ # ever calling enable at all. A Null Object would remove the repeated
12
+ # check but couples every caller to a different `Hook.event_log` contract
13
+ # (an object always present vs. nil-means-disabled); not worth it here.
8
14
  class Hook < RobotLab::Hook
9
15
  self.namespace = :audit
10
16
 
@@ -62,6 +68,9 @@ module RobotLab
62
68
 
63
69
  private
64
70
 
71
+ # :reek:LongParameterList -- private helper with exactly two call
72
+ # sites, each passing every argument explicitly; a wrapper object
73
+ # would add indirection without making either call site clearer.
65
74
  def record_audit_event(event_type, ctx, started, tool_name, input, output, error)
66
75
  event_log.record_event(
67
76
  run_id: current_run_id,
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RobotLab
4
4
  module Audit
5
- VERSION = '0.2.7'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: robot_lab-audit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dewayne VanHoozer
@@ -13,16 +13,16 @@ dependencies:
13
13
  name: robot_lab
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - ">="
16
+ - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '0.1'
18
+ version: 0.3.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
- - - ">="
23
+ - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: '0.1'
25
+ version: 0.3.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: sqlite3
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  requirements: []
93
- rubygems_version: 4.0.19
93
+ rubygems_version: 4.0.21
94
94
  specification_version: 4
95
95
  summary: SQLite-backed execution audit log for RobotLab via the Hook system.
96
96
  test_files: []