Skip to content

Commit 48ab151

Browse files
committed
start-agent-task: refactor-gems
1 parent 651b108 commit 48ab151

File tree

20 files changed

+673
-601
lines changed

20 files changed

+673
-601
lines changed

.agents/codebase-insights.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
No insights yet. Please add content here and remove this line.
1+
When the pure Ruby recorder traces a script that holds a reference to the
2+
`PureRubyRecorder` instance in a local variable, the variable inspection code
3+
would recursively serialise the tracer's internal state. This results in an
4+
explosive amount of output and may appear as an infinite recursion when running
5+
`examples/selective_tracing_pure.rb`. To avoid this, `load_variables` now skips
6+
values that refer to the recorder or its `TraceRecord`.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
A previous developer got the following task:
2+
3+
> Make sure the functionality of both gems is usable as a library. The gem binaries
4+
> should just call into methods exported by the gem libraries. Make command-line
5+
> handling consistent between the two gems. Use class names that are derived from
6+
> the gem names.
7+
8+
He made really good progress in commit d007872908d4fb5dbe862549f825eec98e7721f0, but
9+
he hasn't tested his code.
10+
11+
Please test his changes and fix any issues that you find.
12+
13+
He tried to implement one new feature:
14+
15+
Both gem binaries now allow the standard "--" separator that specifies where
16+
the arguments of the executed program begin.
17+
18+
Please add a test case that uses this notation to make sure its works correctly.
19+
Of course, keep the existing tests that don't use this notation.

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,3 @@ pkg/
1414
# Offline dependency sources
1515
.codex/deps_src/
1616
.codex/internet_resources/
17-
18-
agents-workflow/

MAINTAINERS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ just build-extension
2323

2424
This compiles the extension in release mode using Cargo. The resulting
2525
shared library is placed under
26-
`ext/native_tracer/target/release/` and is loaded by `gems/codetracer-ruby-recorder/lib/native_trace.rb`.
26+
`ext/native_tracer/target/release/` and is loaded by `gems/codetracer-ruby-recorder/lib/codetracer_ruby_recorder.rb`.
2727

2828
## Running tests
2929

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ recorder.flush_trace(Dir.pwd)
3636
you can currently use it directly with
3737

3838
```bash
39-
ruby gems/codetracer-pure-ruby-recorder/lib/trace.rb [--out-dir DIR] <path to ruby file>
39+
ruby gems/codetracer-pure-ruby-recorder/bin/codetracer-pure-ruby-recorder [--out-dir DIR] <path to ruby file>
4040
# produces several trace json files in DIR,
4141
# or in `$CODETRACER_RUBY_RECORDER_OUT_DIR` if DIR is not provided.
4242
# Defaults to the current directory.
@@ -47,7 +47,7 @@ You can also invoke a lightweight CLI that loads the native tracer extension
4747
directly:
4848

4949
```bash
50-
ruby gems/codetracer-ruby-recorder/lib/native_trace.rb [--out-dir DIR] <path to ruby file>
50+
ruby gems/codetracer-ruby-recorder/bin/codetracer-ruby-recorder [--out-dir DIR] <path to ruby file>
5151
# Uses DIR or `$CODETRACER_RUBY_RECORDER_OUT_DIR` to choose where traces are saved.
5252
```
5353

examples/selective_tracing.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
#!/usr/bin/env ruby
22

3-
# Load the native extension only if RubyRecorder is not already available
4-
# (e.g., when running directly without the codetracer wrapper)
5-
unless defined?(RubyRecorder)
6-
ext_base = File.expand_path('../gems/codetracer-ruby-recorder/ext/native_tracer/target/release/libcodetracer_ruby_recorder', __dir__)
7-
require ext_base
8-
end
3+
ext_base = File.expand_path('../gems/codetracer-ruby-recorder/ext/native_tracer/target/release/libcodetracer_ruby_recorder', __dir__)
4+
require ext_base
95

10-
recorder = RubyRecorder.new
6+
recorder = CodeTracer::RubyRecorder.new
117

128
puts 'start trace'
139
recorder.disable_tracing

examples/selective_tracing_pure.rb

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
#!/usr/bin/env ruby
22

3-
# Load the pure Ruby tracer library if RubyRecorder is not already defined
4-
unless defined?(RubyRecorder)
5-
lib_base = File.expand_path('../gems/codetracer-pure-ruby-recorder/lib/codetracer_pure_ruby_recorder', __dir__)
6-
require lib_base
7-
end
3+
lib_base = File.expand_path('../gems/codetracer-pure-ruby-recorder/lib/codetracer_pure_ruby_recorder', __dir__)
4+
require lib_base
85

9-
recorder = RubyRecorder.new
6+
recorder = CodeTracer::PureRubyRecorder.new
107

118
puts 'start trace'
12-
recorder.disable_tracing
9+
recorder.stop
1310
puts 'this will not be traced'
14-
recorder.enable_tracing
11+
recorder.start
1512
puts 'this will be traced'
16-
recorder.disable_tracing
13+
recorder.stop
1714
puts 'tracing disabled'
1815
recorder.flush_trace(Dir.pwd)
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
#!/usr/bin/env ruby
2-
require 'rbconfig'
3-
script = File.expand_path('../lib/trace.rb', __dir__)
4-
exec RbConfig.ruby, script, *ARGV
2+
# SPDX-License-Identifier: MIT
3+
# CLI for the pure Ruby tracer
4+
5+
lib_dir = File.expand_path('../lib', __dir__)
6+
$LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
7+
require 'codetracer_pure_ruby_recorder'
8+
9+
exit CodeTracer::PureRubyRecorder.parse_argv_and_trace_ruby_file(ARGV)

gems/codetracer-pure-ruby-recorder/lib/codetracer/kernel_patches.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: MIT
22

3-
module Codetracer
3+
module CodeTracer
44
module KernelPatches
55
@@tracers = []
66

@@ -54,10 +54,6 @@ def self.uninstall(tracer)
5454
alias_method :p, :codetracer_original_p
5555
alias_method :puts, :codetracer_original_puts
5656
alias_method :print, :codetracer_original_print
57-
58-
remove_method :codetracer_original_p
59-
remove_method :codetracer_original_puts
60-
remove_method :codetracer_original_print
6157
end
6258
end
6359
end

0 commit comments

Comments
 (0)