lumitrace

Lumitrace Spec

Overview

Lumitrace instruments Ruby source code at load time (via RubyVM::InstructionSequence.translate when available), records expression results, and renders text or HTML output that overlays recorded values on your code. It is designed for local “what happened here?” inspection.

AI-Oriented Docs

Goals

Non-Goals

Public API

require "lumitrace"

Library entry points (common usage)

Lumitrace.enable!(max_samples: nil, ranges_by_file: nil, root: nil, text: nil, html: nil, json: nil, verbose: nil, at_exit: true)

Lumitrace.disable!

require "lumitrace/enable"

require "lumitrace/enable_git_diff"

Instrumentation

Activation

Root Scope

Exclusions

Rewriting Strategy

Range Filtering

Wrap Targets

Recording

Fork/Exec Merge

Output JSON

lumitrace_recorded.json contains an array of entries.

collect_mode=last (default):

{
  "file": "/path/to/file.rb",
  "start_line": 10,
  "start_col": 4,
  "end_line": 10,
  "end_col": 20,
  "kind": "expr",
  "name": null,
  "last_value": { "type": "String", "preview": "\"ok\"" },
  "types": { "Integer": 10, "NilClass": 2, "String": 111 },
  "total": 123
}

collect_mode=types:

{
  "file": "/path/to/file.rb",
  "start_line": 10,
  "start_col": 4,
  "end_line": 10,
  "end_col": 20,
  "kind": "expr",
  "name": null,
  "types": { "Integer": 10, "NilClass": 2, "String": 111 },
  "total": 123
}

collect_mode=history:

{
  "file": "/path/to/file.rb",
  "start_line": 10,
  "start_col": 4,
  "end_line": 10,
  "end_col": 20,
  "kind": "expr",
  "name": null,
  "sampled_values": [
    { "type": "Integer", "preview": "42" },
    { "type": "NilClass", "preview": "nil" },
    { "type": "String", "preview": "\"ok\"" }
  ],
  "types": { "Integer": 10, "NilClass": 2, "String": 111 },
  "total": 123
}

CLI

lumitrace

lumitrace [options] script.rb [ruby_opt]
lumitrace [options] exec CMD [args...]

Text Output (CLI)

HTML Rendering

HTML Payload Schema (v1)

{
  "version": 1,
  "meta": {
    "mode": "last|types|history",
    "mode_text": "Mode: ...",
    "max_samples": 3
  },
  "files": [
    {
      "path": "/abs/path/to/file.rb",
      "display_path": "path/to/file.rb",
      "source": "file contents...",
      "ranges": [[1, 10], [20, 30]],
      "trace": [
        {
          "location": [1, 0, 1, 5],
          "kind": "expr|arg",
          "name": "x",
          "sampled_values": [{"type": "Integer", "preview": "1"}],
          "types": {"Integer": 3},
          "total": 3
        }
      ]
    }
  ]
}

Copy/Paste Behavior

Known Limitations