context_spook 1.0.1 → 1.2.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: 94058fa45fd85552ea4e54d5f67d991d90d7d29a8a344490c71942a568032755
4
- data.tar.gz: a12296d4822f6cc01294ecc8c6bb3d544f894eebcaaaddc83956420b33c28c56
3
+ metadata.gz: ce46a8a82422662465714da76e66762d8ce6ca9f44b2231c1064ca774e45696e
4
+ data.tar.gz: 3e6c9fbb246330a69232b4ddc4527aea2bc83385293b8a2d16829cd1f47dc3f4
5
5
  SHA512:
6
- metadata.gz: b9f81bb6d859590f83b7febf9dbfeac3223da9624d4d6851204ad5e255b22dcff2db3d4c0eb4c741228edaac07a23565ab56abe9946b2e8b9059973c6f82de2e
7
- data.tar.gz: 3439f27cac24f0d78e3a3fa99586d6d20aa9b3a33ebe4892a2757614c27eaba9073cffeb5da81d5502c5e245d8c38c282e6964656227e24e42d90a512ea686b7
6
+ metadata.gz: 22b6f481325481fbb323cc354c404a7c87a595a5546b9c70f0cfe99b3ef2e1871dd653864dfa460f45df23a10c3573a497cefb46e83b7b7e24fb2d69892279fe
7
+ data.tar.gz: 1f8228f7e8300d887865bf262b148433ab06ef680b3bf593b404a60732f5751b66384d668366b37168195fb463b168bbe9bd8211bbf6402c8d6cc4b95016daec
data/README.md CHANGED
@@ -127,20 +127,20 @@ File.write 'context.json', context.to_json
127
127
  Generate context and save to file:
128
128
 
129
129
  ```bash
130
- ./bin/context_spook .contexts/project.rb > context.json
130
+ context_spook .contexts/project.rb > context.json
131
131
  ```
132
132
 
133
133
  Or pipe directly to another tool:
134
134
 
135
135
  ```bash
136
- ./bin/context_spook .contexts/project.rb | ollama_chat_send
136
+ context_spook .contexts/project.rb | ollama_chat_send
137
137
  ```
138
138
 
139
139
  The CLI tool also supports verbose output:
140
140
 
141
141
  ```bash
142
142
  # Generate context without verbose output
143
- ./bin/context_spook .contexts/project.rb ~v
143
+ context_spook .contexts/project.rb ~v
144
144
  ```
145
145
 
146
146
  Now you can see two orange warning messages, that demonstrates how errors like
@@ -150,7 +150,7 @@ The CLI tool also supports file redirection:
150
150
 
151
151
  ```bash
152
152
  # Generate context and save to file
153
- ./bin/context_spook .contexts/project.rb -o context.json
153
+ context_spook .contexts/project.rb -o context.json
154
154
  ```
155
155
 
156
156
  You can also use include patterns to automatically collect files without
@@ -158,22 +158,33 @@ manually specifying each one:
158
158
 
159
159
  ```bash
160
160
  # Collect all Ruby files from lib/ and spec/ directories
161
- ./bin/context_spook -i 'lib/**/*.rb' -i 'spec/**/*.rb'
161
+ context_spook -i 'lib/**/*.rb' -i 'spec/**/*.rb'
162
162
 
163
163
  # Collect Markdown and YAML files from current directory
164
- ./bin/context_spook -i '*.md' -i '*.yaml' -i '*.yml'
164
+ context_spook -i '*.md' -i '*.yaml' -i '*.yml'
165
165
 
166
166
  # Collect files with complex patterns
167
- ./bin/context_spook -i 'lib/**/{*.rb,*.rake}' # Brace expansion
168
- ./bin/context_spook -i 'lib/**/*_spec.rb' # Pattern matching
169
- ./bin/context_spook -i 'lib/**/*.rb' -i 'spec/**/*_spec.rb' # Mixed patterns
167
+ context_spook -i 'lib/**/{*.rb,*.rake}' # Brace expansion
168
+ context_spook -i 'lib/**/*_spec.rb' # Pattern matching
169
+ context_spook -i 'lib/**/*.rb' -i 'spec/**/*_spec.rb' # Mixed patterns
170
170
  ```
171
171
 
172
+ ### Size Estimation
173
+
174
+ To estimate the size of your context without generating the large output file:
175
+
176
+ ```bash
177
+ # Show context size information only
178
+ context_spook .contexts/project.rb -S
179
+ ```
180
+
181
+ This is useful for optimizing context size before committing to large output files.
182
+
172
183
  This is how you can show the usage message:
173
184
 
174
185
  ```
175
186
  # Show help
176
- ./bin/context_spook -h
187
+ context_spook -h
177
188
  ```
178
189
 
179
190
  ## What Gets Collected
@@ -232,4 +243,4 @@ assistants understand:
232
243
 
233
244
  ## License
234
245
 
235
- The gem is available as open source under the terms of the [MIT License](./LICENSE)
246
+ The gem is available as open source under the terms of the [MIT License](LICENSE)
data/Rakefile CHANGED
@@ -38,6 +38,7 @@ GemHadar do
38
38
  dependency 'mime-types', '~> 3.0'
39
39
  dependency 'yaml', '~> 0.4'
40
40
  dependency 'pathname', '~> 0.4'
41
+ dependency 'ruby-json-toon', '~> 1.0'
41
42
  development_dependency 'all_images', '~> 0.6'
42
43
  development_dependency 'rspec', '~> 3.2'
43
44
  development_dependency 'debug'
data/bin/context_spook CHANGED
@@ -22,10 +22,12 @@ def usage
22
22
 
23
23
  Options:
24
24
  -o FILE Write output to FILE instead of stdout
25
- ~v Disable verbose output, enabled by default
26
- -h Show this help message
25
+ ~v Disable verbose informational output, enabled by default
26
+ -S suppress output (just show informational output)
27
27
  -i PATTERN Include files matching PATTERN (can be used multiple times)
28
28
  Supports glob patterns like **, *, ?, [abc], {a,b,c}
29
+ -F FORMAT Output context as format JSON (the default) or TOON
30
+ -h Show this help message
29
31
 
30
32
  Examples:
31
33
  # Generate context and output to stdout
@@ -44,13 +46,16 @@ def usage
44
46
  # Generate context without verbose output
45
47
  #{File.basename($0)} .contexts/project.rb ~v
46
48
 
49
+ # Generate informational output only to estimate context size
50
+ #{File.basename($0)} .contexts/project.rb -S
51
+
47
52
  # Generate context and save to file
48
53
  #{File.basename($0)} .contexts/project.rb -o context.json
49
54
  EOT
50
55
  exit 0
51
56
  end
52
57
 
53
- opts = go 'o:i:pvh', defaults: { ?v => true }
58
+ opts = go 'o:i:F:pvSh', defaults: { ?v => true }
54
59
  opts[?h] and usage
55
60
  context = nil
56
61
  output = nil
@@ -72,12 +77,26 @@ else
72
77
  context = ContextSpook.generate_context(filename, verbose: opts[?v])
73
78
  end
74
79
 
75
- if output_filename = opts[?o]
76
- if File.exist?(output_filename)
77
- fail "Filename #{output_filename.inspect} already exists!"
80
+ if opts[?S]
81
+ output = NULL
82
+ else
83
+ if output_filename = opts[?o]
84
+ if File.exist?(output_filename)
85
+ fail "Filename #{output_filename.inspect} already exists!"
86
+ end
87
+ output = File.new output_filename, ?w
88
+ else
89
+ output = STDOUT
90
+ end
91
+ end
92
+ case opts[?F]
93
+ when /\ATOON\z/i
94
+ if opts[?v]
95
+ STDERR.puts "Built #{ContextSpook::Utils.format_size(context.toon_size)} of TOON context in total."
78
96
  end
79
- output = File.new output_filename, ?w
97
+ output.puts context.to_toon
98
+ when /\AJSON\z/i, nil
99
+ JSON.dump(context.as_json, output)
80
100
  else
81
- output = STDOUT
101
+ STDERR.puts "Invalid output format #{opts[?F].inspect}"
82
102
  end
83
- JSON.dump(context.as_json, output)
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: context_spook 1.0.1 ruby lib
2
+ # stub: context_spook 1.2.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "context_spook".freeze
6
- s.version = "1.0.1".freeze
6
+ s.version = "1.2.0".freeze
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
12
12
  s.description = "context_spook is a library that collects and organizes project\ninformation to help AI assistants understand codebases better.\n".freeze
13
13
  s.email = "flori@ping.de".freeze
14
14
  s.executables = ["context_spook".freeze]
15
- s.extra_rdoc_files = ["README.md".freeze, "lib/context_spook.rb".freeze, "lib/context_spook/generator.rb".freeze, "lib/context_spook/version.rb".freeze]
16
- s.files = [".contexts/project.rb".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "bin/context_spook".freeze, "context_spook.gemspec".freeze, "hello_world.json".freeze, "hey_world.yaml".freeze, "lib/context_spook.rb".freeze, "lib/context_spook/generator.rb".freeze, "lib/context_spook/version.rb".freeze, "spec/context_spook/generator_spec.rb".freeze, "spec/spec_helper.rb".freeze]
15
+ s.extra_rdoc_files = ["README.md".freeze, "lib/context_spook.rb".freeze, "lib/context_spook/generator.rb".freeze, "lib/context_spook/toon.rb".freeze, "lib/context_spook/utils.rb".freeze, "lib/context_spook/version.rb".freeze]
16
+ s.files = [".contexts/project.rb".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "bin/context_spook".freeze, "context_spook.gemspec".freeze, "hello_world.json".freeze, "hey_world.yaml".freeze, "lib/context_spook.rb".freeze, "lib/context_spook/generator.rb".freeze, "lib/context_spook/toon.rb".freeze, "lib/context_spook/utils.rb".freeze, "lib/context_spook/version.rb".freeze, "spec/context_spook/generator_spec.rb".freeze, "spec/spec_helper.rb".freeze]
17
17
  s.homepage = "https://github.com/flori/context_spook".freeze
18
18
  s.licenses = ["MIT".freeze]
19
19
  s.rdoc_options = ["--title".freeze, "ContextSpook - context_spook collects project context for AI".freeze, "--main".freeze, "README.md".freeze]
@@ -36,4 +36,5 @@ Gem::Specification.new do |s|
36
36
  s.add_runtime_dependency(%q<mime-types>.freeze, ["~> 3.0".freeze])
37
37
  s.add_runtime_dependency(%q<yaml>.freeze, ["~> 0.4".freeze])
38
38
  s.add_runtime_dependency(%q<pathname>.freeze, ["~> 0.4".freeze])
39
+ s.add_runtime_dependency(%q<ruby-json-toon>.freeze, ["~> 1.0".freeze])
39
40
  end
@@ -4,6 +4,7 @@ require 'json'
4
4
  require 'mize'
5
5
  require 'mime-types'
6
6
  require 'yaml'
7
+ require 'context_spook/toon'
7
8
 
8
9
  # The ContextSpook module serves as a namespace container for collecting and
9
10
  # organizing project information for AI assistance.
@@ -111,11 +112,9 @@ module ContextSpook
111
112
  # JSON, formats it using binary units (KiB, MiB, etc.), and outputs the
112
113
  # result to standard error.
113
114
  def output_context_size
114
- context_size = @context&.size.to_i
115
- json_content_size = Tins::Unit.format(
116
- context_size, format: '%.2f %U', unit: ?b, prefix: 1024
117
- )
118
- verbose_puts "Built #{json_content_size} of JSON context in total."
115
+ context_size = @context&.size.to_i
116
+ json_context_size = ContextSpook::Utils.format_size(context_size)
117
+ verbose_puts "Built #{json_context_size} of JSON context in total."
119
118
  end
120
119
 
121
120
  # The Context class represents and manages project context data, providing
@@ -126,6 +125,7 @@ module ContextSpook
126
125
  include Tins::Scope
127
126
  include Tins::DSLAccessor
128
127
  include Term::ANSIColor
128
+ include ContextSpook::TOON
129
129
 
130
130
  # The initialize method sets up the object by evaluating the provided block
131
131
  # in the object's context.
@@ -0,0 +1,12 @@
1
+ require 'ruby_json_toon'
2
+
3
+ module ContextSpook::TOON
4
+ def to_toon
5
+ RubyJsonToon.encode(as_json)
6
+ end
7
+ memoize method: :to_toon
8
+
9
+ def toon_size
10
+ to_toon.size
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ module ContextSpook::Utils
2
+ module_function
3
+
4
+ # The format_size method converts a byte size value into a human-readable
5
+ # string with binary units.
6
+ #
7
+ # This method takes a raw byte count and formats it using the Tins::Unit
8
+ # library to display the size with appropriate binary prefixes (KiB, MiB,
9
+ # etc.) and two decimal places.
10
+ #
11
+ # @param context_size [ Integer ] the size in bytes to be formatted
12
+ #
13
+ # @return [ String ] the formatted size string with binary units
14
+ def format_size(context_size)
15
+ Tins::Unit.format(context_size, format: '%.2f %U', unit: ?b, prefix: 1024)
16
+ end
17
+ end
@@ -1,6 +1,6 @@
1
1
  module ContextSpook
2
2
  # ContextSpook version
3
- VERSION = '1.0.1'
3
+ VERSION = '1.2.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
data/lib/context_spook.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  module ContextSpook
2
2
  end
3
3
  require 'context_spook/version'
4
+ require 'context_spook/utils'
4
5
  require 'context_spook/generator'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: context_spook
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
@@ -177,6 +177,20 @@ dependencies:
177
177
  - - "~>"
178
178
  - !ruby/object:Gem::Version
179
179
  version: '0.4'
180
+ - !ruby/object:Gem::Dependency
181
+ name: ruby-json-toon
182
+ requirement: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - "~>"
185
+ - !ruby/object:Gem::Version
186
+ version: '1.0'
187
+ type: :runtime
188
+ prerelease: false
189
+ version_requirements: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - "~>"
192
+ - !ruby/object:Gem::Version
193
+ version: '1.0'
180
194
  description: |
181
195
  context_spook is a library that collects and organizes project
182
196
  information to help AI assistants understand codebases better.
@@ -188,6 +202,8 @@ extra_rdoc_files:
188
202
  - README.md
189
203
  - lib/context_spook.rb
190
204
  - lib/context_spook/generator.rb
205
+ - lib/context_spook/toon.rb
206
+ - lib/context_spook/utils.rb
191
207
  - lib/context_spook/version.rb
192
208
  files:
193
209
  - ".contexts/project.rb"
@@ -201,6 +217,8 @@ files:
201
217
  - hey_world.yaml
202
218
  - lib/context_spook.rb
203
219
  - lib/context_spook/generator.rb
220
+ - lib/context_spook/toon.rb
221
+ - lib/context_spook/utils.rb
204
222
  - lib/context_spook/version.rb
205
223
  - spec/context_spook/generator_spec.rb
206
224
  - spec/spec_helper.rb