Move os-me hook helper classes into lib/os_me so they autoload #1396

Open
opened 2026-10-26 14:45:55 +00:00 by jared · 0 comments
Owner

Problem

Four os-me helper classes live in plugins/os-me/hooks/. Hook scripts and lib/os_me.rb load them with require_relative. hooks/ is outside the Zeitwerk tree. Each consumer names the file by hand. The library entry file reaches into hooks/. Under the Sdlc/RequireInsideCode lesson, a require_relative of project code belongs only to the loader in an entry point.

Evidence (all four classes are OsMe:: constants, so Zeitwerk could autoload them from lib/os_me/):

  • plugins/os-me/lib/os_me.rb:12 require_relative '../hooks/extract_launcher' loads OsMe::ExtractLauncher
  • plugins/os-me/hooks/extract_moments.rb:4 require_relative 'extract_launcher' loads OsMe::ExtractLauncher
  • plugins/os-me/hooks/log_invocation.rb:5 require_relative 'invocation_log' loads OsMe::InvocationLog
  • plugins/os-me/hooks/prediction_recorder.rb:5 require_relative 'invocation_log' loads OsMe::InvocationLog
  • plugins/os-me/hooks/record_prediction.rb:6 require_relative 'cli_appender' loads OsMe::CliAppender
  • plugins/os-me/hooks/record_prediction.rb:7 require_relative 'prediction_recorder' loads OsMe::PredictionRecorder
  • Tests also load them by path: plugins/os-me/test/prediction_recorder_payload_provenance_test.rb:6-8 and plugins/os-me/test/prediction_recorder_provenance_test.rb:6-8.

The loader is loader.push_dir(File.join(__dir__, 'os_me'), namespace: OsMe) in plugins/os-me/lib/os_me.rb. A file at lib/os_me/cli_appender.rb would autoload as OsMe::CliAppender.

Reproduce

n/a: design ticket; the require_relative lines above show the shape.

Approach

Move each helper class file into lib/os_me/ at the path its constant maps to. Each hook script keeps one require_relative '../lib/os_me' in its top run. Delete the other require_relative calls, including the one in lib/os_me.rb and the test requires.

Required work:

  1. Move plugins/os-me/hooks/cli_appender.rb to plugins/os-me/lib/os_me/cli_appender.rb — check: absent require_relative 'cli_appender' in plugins/os-me/hooks/*.rb
  2. Move plugins/os-me/hooks/extract_launcher.rb to plugins/os-me/lib/os_me/extract_launcher.rb — check: absent require_relative 'extract_launcher' in plugins/os-me/hooks/*.rb
  3. Move plugins/os-me/hooks/invocation_log.rb to plugins/os-me/lib/os_me/invocation_log.rb — check: absent require_relative 'invocation_log' in plugins/os-me/hooks/*.rb
  4. Move plugins/os-me/hooks/prediction_recorder.rb to plugins/os-me/lib/os_me/prediction_recorder.rb — check: absent require_relative 'prediction_recorder' in plugins/os-me/hooks/*.rb
  5. Make extract_moments.rb and log_invocation.rb start with require_relative '../lib/os_me' only, and remove the sibling requires from record_prediction.rb
  6. Remove the hooks/ requires from the two provenance tests under plugins/os-me/test/
  7. Remove the hooks/ require from the library entry file — check: absent require_relative '../hooks/ in plugins/os-me/lib/**/*.rb

Acceptance criteria

  1. Given the os-me suite (ruby test/all.rb in plugins/os-me), when it runs, then it passes.
  2. Given each hook script in plugins/os-me/hooks/, when its requires are read, then it starts with only the require_relative '../lib/os_me' loader.
  3. Given the SessionStart hook ruby plugins/os-me/hooks/extract_moments.rb, when it runs, then it exits 0 and launches the extraction as before (plugins/os-me/test/extract_launcher_test.rb runs it).

Owner sketch

class OsMe::CliAppender          # lib/os_me/cli_appender.rb
class OsMe::ExtractLauncher      # lib/os_me/extract_launcher.rb
class OsMe::InvocationLog        # lib/os_me/invocation_log.rb
class OsMe::PredictionRecorder   # lib/os_me/prediction_recorder.rb

Related: #1367, #1393.

Origin

  • Trigger: review of require_relative calls in plugins/*/hooks/*.rb after #1367
  • Improvised this session: none
  • Chain: hook helpers load by hand ← helper classes sit in hooks/, outside the Zeitwerk tree ← DESIGN (plugins/os-me/lib/os_me.rb push_dir lib/os_me only)
  • Root candidate: none found; searched os-me hooks require_relative, extract_launcher, invocation_log, cli_appender, prediction_recorder, Zeitwerk, autoload, hooks/*.rb
  • Verdict: VERDICT: CREATE
  • Where: plugins/os-me/hooks/*.rb, plugins/os-me/lib/os_me.rb
  • Session: fe2e7204-cf6e-4241-b776-f9c5f032f4a9
  • Transcript: /home/jared/.claude/projects/-home-jared-dev-cc-os/fe2e7204-cf6e-4241-b776-f9c5f032f4a9.jsonl
## Problem Four os-me helper classes live in `plugins/os-me/hooks/`. Hook scripts and `lib/os_me.rb` load them with `require_relative`. `hooks/` is outside the Zeitwerk tree. Each consumer names the file by hand. The library entry file reaches into `hooks/`. Under the Sdlc/RequireInsideCode lesson, a `require_relative` of project code belongs only to the loader in an entry point. Evidence (all four classes are `OsMe::` constants, so Zeitwerk could autoload them from `lib/os_me/`): - `plugins/os-me/lib/os_me.rb:12` `require_relative '../hooks/extract_launcher'` loads `OsMe::ExtractLauncher` - `plugins/os-me/hooks/extract_moments.rb:4` `require_relative 'extract_launcher'` loads `OsMe::ExtractLauncher` - `plugins/os-me/hooks/log_invocation.rb:5` `require_relative 'invocation_log'` loads `OsMe::InvocationLog` - `plugins/os-me/hooks/prediction_recorder.rb:5` `require_relative 'invocation_log'` loads `OsMe::InvocationLog` - `plugins/os-me/hooks/record_prediction.rb:6` `require_relative 'cli_appender'` loads `OsMe::CliAppender` - `plugins/os-me/hooks/record_prediction.rb:7` `require_relative 'prediction_recorder'` loads `OsMe::PredictionRecorder` - Tests also load them by path: `plugins/os-me/test/prediction_recorder_payload_provenance_test.rb:6-8` and `plugins/os-me/test/prediction_recorder_provenance_test.rb:6-8`. The loader is `loader.push_dir(File.join(__dir__, 'os_me'), namespace: OsMe)` in `plugins/os-me/lib/os_me.rb`. A file at `lib/os_me/cli_appender.rb` would autoload as `OsMe::CliAppender`. ## Reproduce n/a: design ticket; the `require_relative` lines above show the shape. ## Approach Move each helper class file into `lib/os_me/` at the path its constant maps to. Each hook script keeps one `require_relative '../lib/os_me'` in its top run. Delete the other `require_relative` calls, including the one in `lib/os_me.rb` and the test requires. Required work: 1. Move `plugins/os-me/hooks/cli_appender.rb` to `plugins/os-me/lib/os_me/cli_appender.rb` — check: absent `require_relative 'cli_appender'` in `plugins/os-me/hooks/*.rb` 2. Move `plugins/os-me/hooks/extract_launcher.rb` to `plugins/os-me/lib/os_me/extract_launcher.rb` — check: absent `require_relative 'extract_launcher'` in `plugins/os-me/hooks/*.rb` 3. Move `plugins/os-me/hooks/invocation_log.rb` to `plugins/os-me/lib/os_me/invocation_log.rb` — check: absent `require_relative 'invocation_log'` in `plugins/os-me/hooks/*.rb` 4. Move `plugins/os-me/hooks/prediction_recorder.rb` to `plugins/os-me/lib/os_me/prediction_recorder.rb` — check: absent `require_relative 'prediction_recorder'` in `plugins/os-me/hooks/*.rb` 5. Make `extract_moments.rb` and `log_invocation.rb` start with `require_relative '../lib/os_me'` only, and remove the sibling requires from `record_prediction.rb` 6. Remove the `hooks/` requires from the two provenance tests under `plugins/os-me/test/` 7. Remove the `hooks/` require from the library entry file — check: absent `require_relative '../hooks/` in `plugins/os-me/lib/**/*.rb` ## Acceptance criteria 1. Given the os-me suite (`ruby test/all.rb` in `plugins/os-me`), when it runs, then it passes. 2. Given each hook script in `plugins/os-me/hooks/`, when its requires are read, then it starts with only the `require_relative '../lib/os_me'` loader. 3. Given the SessionStart hook `ruby plugins/os-me/hooks/extract_moments.rb`, when it runs, then it exits 0 and launches the extraction as before (`plugins/os-me/test/extract_launcher_test.rb` runs it). ## Owner sketch ```ruby class OsMe::CliAppender # lib/os_me/cli_appender.rb class OsMe::ExtractLauncher # lib/os_me/extract_launcher.rb class OsMe::InvocationLog # lib/os_me/invocation_log.rb class OsMe::PredictionRecorder # lib/os_me/prediction_recorder.rb ``` Related: #1367, #1393. ## Origin - Trigger: review of `require_relative` calls in `plugins/*/hooks/*.rb` after #1367 - Improvised this session: none - Chain: hook helpers load by hand ← helper classes sit in `hooks/`, outside the Zeitwerk tree ← DESIGN (`plugins/os-me/lib/os_me.rb` push_dir `lib/os_me` only) - Root candidate: none found; searched os-me hooks require_relative, extract_launcher, invocation_log, cli_appender, prediction_recorder, Zeitwerk, autoload, hooks/*.rb - Verdict: VERDICT: CREATE - Where: plugins/os-me/hooks/*.rb, plugins/os-me/lib/os_me.rb - Session: fe2e7204-cf6e-4241-b776-f9c5f032f4a9 - Transcript: /home/jared/.claude/projects/-home-jared-dev-cc-os/fe2e7204-cf6e-4241-b776-f9c5f032f4a9.jsonl
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jared/cc-os#1396
No description provided.