context_spook 0.4.0 → 0.6.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 +4 -4
- data/.contexts/project.rb +10 -0
- data/README.md +28 -2
- data/Rakefile +7 -1
- data/bin/context_spook +53 -3
- data/context_spook.gemspec +6 -5
- data/hey_world.yaml +2 -0
- data/lib/context_spook/generator.rb +99 -26
- data/lib/context_spook/version.rb +1 -1
- data/spec/context_spook/generator_spec.rb +34 -2
- metadata +19 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e70334ee77b21283268eaabfc74ea73593a375119003d74be68442188f4dbf5b
|
|
4
|
+
data.tar.gz: cc7ca13e3a403a97f16c897a797d0b2a4a92bba1b8e3da99adb199f807169b1c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: db73acce9ba9aa696619be04671adde77a115d63b2e2c48d559848cc3d02c608579982a29da2bba7bd70bda7a5fae5654828c6ad1f763e2b04094e47820c98e0
|
|
7
|
+
data.tar.gz: f95575da363d9c70d5f9303ce66bc13d8c2bb2e4c70c7c6074fe3c61f1bf35554dbfc68f286bf2eac2d4080fe39291ad4b1f2ce9ca0910560e2a4b86f5eb6154
|
data/.contexts/project.rb
CHANGED
|
@@ -5,6 +5,12 @@ context do
|
|
|
5
5
|
command "tree", tags: %w[ project_structure ]
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
+
namespace "bin" do
|
|
9
|
+
Dir['bin/**/*'].each do |filename|
|
|
10
|
+
file filename, tags: 'bin'
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
8
14
|
namespace "lib" do
|
|
9
15
|
Dir['lib/**/*.rb'].each do |filename|
|
|
10
16
|
file filename, tags: 'lib'
|
|
@@ -39,5 +45,9 @@ context do
|
|
|
39
45
|
|
|
40
46
|
meta nixda_json: json('nixda_json.json')
|
|
41
47
|
|
|
48
|
+
meta hey_world: yaml('hey_world.yaml')
|
|
49
|
+
|
|
50
|
+
meta nixda_yaml: yaml('nixda_yaml.yaml')
|
|
51
|
+
|
|
42
52
|
meta code_coverage: json('coverage/coverage_context.json')
|
|
43
53
|
end
|
data/README.md
CHANGED
|
@@ -12,6 +12,10 @@ information. The `.contexts/project.rb` example below demonstrates how to
|
|
|
12
12
|
describe a Ruby project, but the same principles apply across many different
|
|
13
13
|
domains.
|
|
14
14
|
|
|
15
|
+
## Documentation
|
|
16
|
+
|
|
17
|
+
Complete API documentation is available at: [GitHub.io](https://flori.github.io/context_spook/)
|
|
18
|
+
|
|
15
19
|
## Installation
|
|
16
20
|
|
|
17
21
|
Add this line to your application's Gemfile:
|
|
@@ -128,13 +132,35 @@ Generate context and save to file:
|
|
|
128
132
|
|
|
129
133
|
Or pipe directly to another tool:
|
|
130
134
|
|
|
131
|
-
```
|
|
135
|
+
```bash
|
|
132
136
|
./bin/context_spook .contexts/project.rb | ollama_chat_send
|
|
133
137
|
```
|
|
134
138
|
|
|
135
|
-
|
|
139
|
+
|
|
140
|
+
The CLI tool also supports verbose output:
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
# Generate context with verbose output
|
|
144
|
+
./bin/context_spook .contexts/project.rb -v
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Now you can see two orange warning messages, that demonstrates how errors like
|
|
136
148
|
missing files or commands with failing exit codes are handled.
|
|
137
149
|
|
|
150
|
+
The CLI tool also supports file redirection:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
# Generate context and save to file
|
|
154
|
+
./bin/context_spook .contexts/project.rb -o context.json
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
This is how you can show the usage message:
|
|
158
|
+
|
|
159
|
+
```
|
|
160
|
+
# Show help
|
|
161
|
+
./bin/context_spook -h
|
|
162
|
+
```
|
|
163
|
+
|
|
138
164
|
## What Gets Collected
|
|
139
165
|
|
|
140
166
|
The DSL collects various types of project information:
|
data/Rakefile
CHANGED
|
@@ -9,7 +9,6 @@ GemHadar do
|
|
|
9
9
|
email 'flori@ping.de'
|
|
10
10
|
homepage "https://github.com/flori/context_spook"
|
|
11
11
|
summary "#{name} collects project context for AI"
|
|
12
|
-
executables 'context_spook'
|
|
13
12
|
|
|
14
13
|
description <<~EOT
|
|
15
14
|
#{name} is a library that collects and organizes project
|
|
@@ -24,6 +23,12 @@ GemHadar do
|
|
|
24
23
|
'.rspec', '.github'
|
|
25
24
|
readme 'README.md'
|
|
26
25
|
|
|
26
|
+
executables 'context_spook'
|
|
27
|
+
|
|
28
|
+
github_workflows(
|
|
29
|
+
'static.yml' => {}
|
|
30
|
+
)
|
|
31
|
+
|
|
27
32
|
required_ruby_version '~> 3.1'
|
|
28
33
|
|
|
29
34
|
dependency 'tins', '~>1.39'
|
|
@@ -31,6 +36,7 @@ GemHadar do
|
|
|
31
36
|
dependency 'term-ansicolor', '~> 1.11'
|
|
32
37
|
dependency 'mize', '~> 0.6'
|
|
33
38
|
dependency 'mime-types', '~> 3.0'
|
|
39
|
+
dependency 'yaml', '~> 0.4'
|
|
34
40
|
development_dependency 'all_images', '~> 0.6'
|
|
35
41
|
development_dependency 'rspec', '~> 3.2'
|
|
36
42
|
development_dependency 'debug'
|
data/bin/context_spook
CHANGED
|
@@ -1,7 +1,57 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
3
|
require 'context_spook'
|
|
4
|
+
require 'tins/go'
|
|
5
|
+
include Tins::GO
|
|
6
|
+
require 'json'
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
# The usage method displays the command-line interface help text and example
|
|
9
|
+
# usage patterns for the ContextSpook tool.
|
|
10
|
+
#
|
|
11
|
+
# This method outputs a formatted help message that includes the tool's usage
|
|
12
|
+
# syntax, available options, and practical examples.
|
|
13
|
+
#
|
|
14
|
+
# @see ContextSpook::generate_context
|
|
15
|
+
# @see ContextSpook::Generator
|
|
16
|
+
# @see ContextSpook::Generator::Context
|
|
17
|
+
def usage
|
|
18
|
+
puts <<~EOT
|
|
19
|
+
|
|
20
|
+
Usage: #{File.basename($0)} [options] <context_definition_file>
|
|
21
|
+
|
|
22
|
+
Options:
|
|
23
|
+
-o FILE Write output to FILE instead of stdout
|
|
24
|
+
-v Verbose output
|
|
25
|
+
-h Show this help message
|
|
26
|
+
|
|
27
|
+
Examples:
|
|
28
|
+
# Generate context and output to stdout
|
|
29
|
+
#{File.basename($0)} .contexts/project.rb
|
|
30
|
+
|
|
31
|
+
# Generate context and save to file
|
|
32
|
+
#{File.basename($0)} .contexts/project.rb -o context.json
|
|
33
|
+
|
|
34
|
+
# Generate context with verbose output
|
|
35
|
+
#{File.basename($0)} .contexts/project.rb -v
|
|
36
|
+
|
|
37
|
+
# Generate context and pipe to another tool
|
|
38
|
+
#{File.basename($0)} .contexts/project.rb | ollama_chat_send
|
|
39
|
+
|
|
40
|
+
EOT
|
|
41
|
+
exit 0
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
opts = go 'o:pvh'
|
|
45
|
+
opts[?h] and usage
|
|
46
|
+
filename = ARGV.shift or fail 'require context definition file as an argument'
|
|
47
|
+
output = nil
|
|
48
|
+
context = ContextSpook.generate_context(filename, verbose: opts[?v])
|
|
49
|
+
if output_filename = opts[?o]
|
|
50
|
+
if File.exist?(output_filename)
|
|
51
|
+
fail "Filename #{output_filename.inspect} already exists!"
|
|
52
|
+
end
|
|
53
|
+
output = File.new output_filename, ?w
|
|
54
|
+
else
|
|
55
|
+
output = STDOUT
|
|
56
|
+
end
|
|
57
|
+
JSON.dump(context.as_json, output)
|
data/context_spook.gemspec
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
-
# stub: context_spook 0.
|
|
2
|
+
# stub: context_spook 0.6.0 ruby lib
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new do |s|
|
|
5
5
|
s.name = "context_spook".freeze
|
|
6
|
-
s.version = "0.
|
|
6
|
+
s.version = "0.6.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]
|
|
@@ -13,18 +13,18 @@ Gem::Specification.new do |s|
|
|
|
13
13
|
s.email = "flori@ping.de".freeze
|
|
14
14
|
s.executables = ["context_spook".freeze]
|
|
15
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, "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]
|
|
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]
|
|
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]
|
|
20
20
|
s.required_ruby_version = Gem::Requirement.new("~> 3.1".freeze)
|
|
21
|
-
s.rubygems_version = "3.
|
|
21
|
+
s.rubygems_version = "3.7.2".freeze
|
|
22
22
|
s.summary = "context_spook collects project context for AI".freeze
|
|
23
23
|
s.test_files = ["spec/context_spook/generator_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
|
24
24
|
|
|
25
25
|
s.specification_version = 4
|
|
26
26
|
|
|
27
|
-
s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 2.
|
|
27
|
+
s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 2.8".freeze])
|
|
28
28
|
s.add_development_dependency(%q<all_images>.freeze, ["~> 0.6".freeze])
|
|
29
29
|
s.add_development_dependency(%q<rspec>.freeze, ["~> 3.2".freeze])
|
|
30
30
|
s.add_development_dependency(%q<debug>.freeze, [">= 0".freeze])
|
|
@@ -34,4 +34,5 @@ Gem::Specification.new do |s|
|
|
|
34
34
|
s.add_runtime_dependency(%q<term-ansicolor>.freeze, ["~> 1.11".freeze])
|
|
35
35
|
s.add_runtime_dependency(%q<mize>.freeze, ["~> 0.6".freeze])
|
|
36
36
|
s.add_runtime_dependency(%q<mime-types>.freeze, ["~> 3.0".freeze])
|
|
37
|
+
s.add_runtime_dependency(%q<yaml>.freeze, ["~> 0.4".freeze])
|
|
37
38
|
end
|
data/hey_world.yaml
ADDED
|
@@ -3,30 +3,66 @@ require 'term/ansicolor'
|
|
|
3
3
|
require 'json'
|
|
4
4
|
require 'mize'
|
|
5
5
|
require 'mime-types'
|
|
6
|
+
require 'yaml'
|
|
6
7
|
|
|
7
8
|
# The ContextSpook module serves as a namespace container for collecting and
|
|
8
9
|
# organizing project information for AI assistance.
|
|
9
10
|
module ContextSpook
|
|
10
11
|
include DSLKit::Interpreter
|
|
11
12
|
|
|
12
|
-
# The
|
|
13
|
-
#
|
|
13
|
+
# The VerbosePuts module provides a conditional output mechanism for
|
|
14
|
+
# displaying status or debug messages.
|
|
14
15
|
#
|
|
15
|
-
# This
|
|
16
|
-
#
|
|
17
|
-
#
|
|
16
|
+
# This module includes a method that outputs messages to standard error only
|
|
17
|
+
# when a verbose flag is enabled. It is designed to be included in classes
|
|
18
|
+
# that need to conditionally emit verbose logging information during
|
|
19
|
+
# processing.
|
|
20
|
+
module VerbosePuts
|
|
21
|
+
# The verbose_puts method outputs the given arguments to standard error
|
|
22
|
+
# only if verbose mode is enabled.
|
|
23
|
+
#
|
|
24
|
+
# This method serves as a conditional output mechanism, allowing debug or
|
|
25
|
+
# status messages to be displayed based on the verbosity setting of the
|
|
26
|
+
# object.
|
|
27
|
+
#
|
|
28
|
+
# @param a [ Array ] the arguments to be printed to standard error
|
|
29
|
+
#
|
|
30
|
+
# @return [ nil ] always returns nil after attempting to output
|
|
31
|
+
def verbose_puts(*a)
|
|
32
|
+
@verbose and return
|
|
33
|
+
STDERR.puts(a)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# The generate_context method processes a context definition file or block
|
|
38
|
+
# and returns the resulting context object.
|
|
18
39
|
#
|
|
19
|
-
#
|
|
40
|
+
# This method serves as the primary entry point for generating project
|
|
41
|
+
# context data. It accepts either a filename pointing to a context definition
|
|
42
|
+
# file or a block containing the context definition, but not both.
|
|
43
|
+
# When a filename is provided, it reads and parses the file content. When a
|
|
44
|
+
# block is provided, it evaluates the block within the generator's context.
|
|
45
|
+
# The method ensures that only one context definition mechanism is used.
|
|
46
|
+
#
|
|
47
|
+
# @param filename [ String, nil ] the path to the context definition file to
|
|
48
|
+
# be processed
|
|
49
|
+
# @param verbose [ TrueClass, FalseClass ] flag to enable verbose output
|
|
50
|
+
# during processing, defaults to false.
|
|
51
|
+
# @param block [ Proc ] a block containing the context definition to be
|
|
52
|
+
# evaluated
|
|
20
53
|
#
|
|
21
54
|
# @return [ ContextSpook::Generator::Context ] the context object generated
|
|
22
|
-
#
|
|
23
|
-
|
|
55
|
+
# from the file contents or block
|
|
56
|
+
#
|
|
57
|
+
# @raise [ ArgumentError ] if neither a filename nor a block is provided
|
|
58
|
+
# @raise [ ArgumentError ] if both a filename and a block are provided
|
|
59
|
+
def self.generate_context(filename = nil, verbose: false, &block)
|
|
24
60
|
filename.present? ^ block or
|
|
25
61
|
raise ArgumentError, 'need either a filename or a &block argument'
|
|
26
62
|
generator = if filename
|
|
27
|
-
Generator.send(:new).send(:parse, File.read(filename))
|
|
63
|
+
Generator.send(:new, verbose:).send(:parse, File.read(filename))
|
|
28
64
|
else
|
|
29
|
-
Generator.send(:new, &block)
|
|
65
|
+
Generator.send(:new, verbose:, &block)
|
|
30
66
|
end
|
|
31
67
|
generator.output_context_size
|
|
32
68
|
generator.context
|
|
@@ -37,13 +73,19 @@ module ContextSpook
|
|
|
37
73
|
# project metadata, file contents, command outputs, and variables for AI
|
|
38
74
|
# assistance.
|
|
39
75
|
class Generator
|
|
76
|
+
include VerbosePuts
|
|
77
|
+
|
|
40
78
|
private_class_method :new
|
|
41
79
|
|
|
42
|
-
# The initialize method sets up the object by evaluating the provided block
|
|
80
|
+
# The initialize method sets up the object by evaluating the provided block
|
|
81
|
+
# in the object's context.
|
|
43
82
|
#
|
|
44
|
-
# @param
|
|
83
|
+
# @param verbose [ TrueClass, FalseClass ] flag to enable verbose
|
|
84
|
+
# output during processing, defaults to lfalse.
|
|
85
|
+
# @param block [ Proc ] a block of code to be evaluated within the object's context
|
|
45
86
|
# If no block is given, the method does nothing.
|
|
46
|
-
def initialize(&block)
|
|
87
|
+
def initialize(verbose: false, &block)
|
|
88
|
+
@verbose = !!verbose
|
|
47
89
|
block and instance_eval(&block)
|
|
48
90
|
end
|
|
49
91
|
|
|
@@ -55,7 +97,7 @@ module ContextSpook
|
|
|
55
97
|
def context(&block)
|
|
56
98
|
if block
|
|
57
99
|
@context and raise ArgumentError, "only one context allowed"
|
|
58
|
-
@context = Context.new(&block)
|
|
100
|
+
@context = Context.new(verbose: @verbose, &block)
|
|
59
101
|
else
|
|
60
102
|
@context
|
|
61
103
|
end
|
|
@@ -72,22 +114,27 @@ module ContextSpook
|
|
|
72
114
|
json_content_size = Tins::Unit.format(
|
|
73
115
|
context_size, format: '%.2f %U', unit: ?b, prefix: 1024
|
|
74
116
|
)
|
|
75
|
-
|
|
117
|
+
verbose_puts "Built #{json_content_size} of JSON context in total."
|
|
76
118
|
end
|
|
77
119
|
|
|
78
120
|
# The Context class represents and manages project context data, providing
|
|
79
121
|
# structured storage for file contents, command outputs, variables, and
|
|
80
122
|
# metadata that can be serialized to JSON for AI assistance.
|
|
81
123
|
class Context
|
|
124
|
+
include VerbosePuts
|
|
82
125
|
include Tins::Scope
|
|
83
126
|
include Tins::DSLAccessor
|
|
84
127
|
include Term::ANSIColor
|
|
85
128
|
|
|
86
|
-
# The initialize method sets up the object by evaluating
|
|
87
|
-
# object's context.
|
|
129
|
+
# The initialize method sets up the object by evaluating the provided block
|
|
130
|
+
# in the object's context.
|
|
88
131
|
#
|
|
89
|
-
# @param
|
|
90
|
-
|
|
132
|
+
# @param verbose [ TrueClass, FalseClass ] flag to enable verbose output
|
|
133
|
+
# during processing, defaults to false.
|
|
134
|
+
# @param block [ Proc ] a block of code to be evaluated within the object's context
|
|
135
|
+
# If no block is given, the method does nothing.
|
|
136
|
+
def initialize(verbose: false, &block)
|
|
137
|
+
@verbose = !!verbose
|
|
91
138
|
block and instance_eval(&block)
|
|
92
139
|
end
|
|
93
140
|
|
|
@@ -156,10 +203,34 @@ module ContextSpook
|
|
|
156
203
|
file_size = Tins::Unit.format(
|
|
157
204
|
File.size(filename), format: '%.2f %U', unit: ?b, prefix: 1024
|
|
158
205
|
)
|
|
159
|
-
|
|
206
|
+
verbose_puts "Read #{filename.inspect} as JSON (%s) for context." % file_size
|
|
160
207
|
JSON.load_file(filename)
|
|
161
|
-
rescue Errno::ENOENT => e
|
|
162
|
-
|
|
208
|
+
rescue Errno::ENOENT, JSON::ParserError => e
|
|
209
|
+
verbose_puts color(208) { "Reading #{filename.inspect} as JSON caused #{e.class}: #{e}" }
|
|
210
|
+
nil
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
# The yaml method reads and parses a YAML file, returning the resulting
|
|
214
|
+
# data structure.
|
|
215
|
+
#
|
|
216
|
+
# This method attempts to load a YAML file from the specified path and
|
|
217
|
+
# returns the resulting Ruby data structure. It provides verbose output
|
|
218
|
+
# about the file size when successfully reading the file. In case of file
|
|
219
|
+
# not found errors or YAML syntax errors, it outputs a colored warning
|
|
220
|
+
# message to standard error and returns nil.
|
|
221
|
+
#
|
|
222
|
+
# @param filename [ String ] the path to the YAML file to be read and parsed
|
|
223
|
+
#
|
|
224
|
+
# @return [ Object, nil ] the parsed YAML data structure or nil if the
|
|
225
|
+
# file cannot be read
|
|
226
|
+
def yaml(filename)
|
|
227
|
+
file_size = Tins::Unit.format(
|
|
228
|
+
File.size(filename), format: '%.2f %U', unit: ?b, prefix: 1024
|
|
229
|
+
)
|
|
230
|
+
verbose_puts "Read #{filename.inspect} as YAML (%s) for context." % file_size
|
|
231
|
+
YAML.load_file(filename)
|
|
232
|
+
rescue Errno::ENOENT, Psych::SyntaxError => e
|
|
233
|
+
verbose_puts color(208) { "Reading #{filename.inspect} as YAML caused #{e.class}: #{e}" }
|
|
163
234
|
nil
|
|
164
235
|
end
|
|
165
236
|
|
|
@@ -193,10 +264,10 @@ module ContextSpook
|
|
|
193
264
|
file_size = Tins::Unit.format(
|
|
194
265
|
content.size, format: '%.2f %U', unit: ?b, prefix: 1024
|
|
195
266
|
)
|
|
196
|
-
|
|
267
|
+
verbose_puts "Read #{filename.inspect} (%s) for context." % file_size
|
|
197
268
|
nil
|
|
198
269
|
rescue Errno::ENOENT => e
|
|
199
|
-
|
|
270
|
+
verbose_puts color(208) { "Reading #{filename.inspect} caused #{e.class}: #{e}" }
|
|
200
271
|
end
|
|
201
272
|
|
|
202
273
|
# The commands method sets up a DSL accessor for provided command outputs.
|
|
@@ -219,7 +290,9 @@ module ContextSpook
|
|
|
219
290
|
output = `#{shell_command}`
|
|
220
291
|
exit_code = $?&.exitstatus.to_i
|
|
221
292
|
if exit_code != 0
|
|
222
|
-
|
|
293
|
+
verbose_puts color(208) {
|
|
294
|
+
"Executing #{shell_command.inspect} resulted in exit code #{exit_code}."
|
|
295
|
+
}
|
|
223
296
|
end
|
|
224
297
|
commands[shell_command] = {
|
|
225
298
|
namespace: scope_top,
|
|
@@ -231,7 +304,7 @@ module ContextSpook
|
|
|
231
304
|
output_size = Tins::Unit.format(
|
|
232
305
|
output.size, format: '%.2f %U', unit: ?b, prefix: 1024
|
|
233
306
|
)
|
|
234
|
-
|
|
307
|
+
verbose_puts "Executed #{shell_command.inspect} with output (%s) for context." % output_size
|
|
235
308
|
nil
|
|
236
309
|
end
|
|
237
310
|
|
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe ContextSpook::Generator do
|
|
4
4
|
let :context do
|
|
5
|
-
ContextSpook.generate_context('.contexts/project.rb')
|
|
5
|
+
ContextSpook.generate_context('.contexts/project.rb', verbose: true)
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
it 'context can be generated from block' do
|
|
@@ -64,7 +64,7 @@ describe ContextSpook::Generator do
|
|
|
64
64
|
command = context.commands['tree']
|
|
65
65
|
expect(command).to be_present
|
|
66
66
|
expect(command[:working_directory]).to eq Dir.pwd
|
|
67
|
-
expect(command[:exit_code]).
|
|
67
|
+
expect(command[:exit_code]).not_to be_nil
|
|
68
68
|
if command[:exit_code] == 0
|
|
69
69
|
expect(command[:output]).to be_present
|
|
70
70
|
else
|
|
@@ -76,5 +76,37 @@ describe ContextSpook::Generator do
|
|
|
76
76
|
it 'can have metada' do
|
|
77
77
|
expect(context.metadata[:ruby]).to eq RUBY_DESCRIPTION
|
|
78
78
|
end
|
|
79
|
+
|
|
80
|
+
it 'can have json metadata' do
|
|
81
|
+
expect(context.metadata[:hello_world]).to eq("hello" => "world")
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it 'can have yaml metadata' do
|
|
85
|
+
expect(context.metadata[:hey_world]).to eq("hey" => "world")
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it 'handles missing json files gracefully' do
|
|
89
|
+
expect(context.json('nixda.json')).to be_nil
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'handles invalid json content gracefully' do
|
|
93
|
+
Tempfile.create('invalid.json') do |f|
|
|
94
|
+
f.write('{ invalid json }')
|
|
95
|
+
f.close
|
|
96
|
+
expect(context.json(f.path)).to be_nil
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it 'handles missing yaml files gracefully' do
|
|
101
|
+
expect(context.yaml('nixda.yaml')).to be_nil
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it 'handles invalid yaml content gracefully' do
|
|
105
|
+
Tempfile.create('invalid.yaml') do |f|
|
|
106
|
+
f.write('invalid: [yaml')
|
|
107
|
+
f.close
|
|
108
|
+
expect(context.yaml(f.path)).to be_nil
|
|
109
|
+
end
|
|
110
|
+
end
|
|
79
111
|
end
|
|
80
112
|
end
|
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: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Florian Frank
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - "~>"
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '2.
|
|
18
|
+
version: '2.8'
|
|
19
19
|
type: :development
|
|
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: '2.
|
|
25
|
+
version: '2.8'
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: all_images
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -149,6 +149,20 @@ dependencies:
|
|
|
149
149
|
- - "~>"
|
|
150
150
|
- !ruby/object:Gem::Version
|
|
151
151
|
version: '3.0'
|
|
152
|
+
- !ruby/object:Gem::Dependency
|
|
153
|
+
name: yaml
|
|
154
|
+
requirement: !ruby/object:Gem::Requirement
|
|
155
|
+
requirements:
|
|
156
|
+
- - "~>"
|
|
157
|
+
- !ruby/object:Gem::Version
|
|
158
|
+
version: '0.4'
|
|
159
|
+
type: :runtime
|
|
160
|
+
prerelease: false
|
|
161
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
162
|
+
requirements:
|
|
163
|
+
- - "~>"
|
|
164
|
+
- !ruby/object:Gem::Version
|
|
165
|
+
version: '0.4'
|
|
152
166
|
description: |
|
|
153
167
|
context_spook is a library that collects and organizes project
|
|
154
168
|
information to help AI assistants understand codebases better.
|
|
@@ -170,6 +184,7 @@ files:
|
|
|
170
184
|
- bin/context_spook
|
|
171
185
|
- context_spook.gemspec
|
|
172
186
|
- hello_world.json
|
|
187
|
+
- hey_world.yaml
|
|
173
188
|
- lib/context_spook.rb
|
|
174
189
|
- lib/context_spook/generator.rb
|
|
175
190
|
- lib/context_spook/version.rb
|
|
@@ -197,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
197
212
|
- !ruby/object:Gem::Version
|
|
198
213
|
version: '0'
|
|
199
214
|
requirements: []
|
|
200
|
-
rubygems_version: 3.
|
|
215
|
+
rubygems_version: 3.7.2
|
|
201
216
|
specification_version: 4
|
|
202
217
|
summary: context_spook collects project context for AI
|
|
203
218
|
test_files:
|