appydave-tools 0.0.2 → 0.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: 18296034720a33b54311ab69be92bbb66c5848ba5d6026e3de97031ae5199d67
4
- data.tar.gz: c27a782a75a63ec2b45c91c41c6694c8a74cf058a1e339826f7f64da1e470143
3
+ metadata.gz: 7f8d11a7aa2efb787554cb3146098cc7ab0885394420af910840424e8a70a544
4
+ data.tar.gz: 4153b36add667b7d250bfb7932cea34b4324f856f3d9e2a0370e00c298b8ecce
5
5
  SHA512:
6
- metadata.gz: '08773eac07fd57c0dc9c03f32e8b14975a373ec14a4430de9ff43df3f7e68e4a7bf986f5bd454db961b59cd321b6a7601a8926e57078f405ce3b40311491677f'
7
- data.tar.gz: 2ea48f9c856641b7fa69ee03c4c44017e421f946e57fd96d178507da7207be7df824e2436bf99bed7f24e176aa35811f8a7f7445a67b704aa7bb841a2029c91c
6
+ metadata.gz: d53f5bb5e624f3869da4d45901a145b9752ae490ea5fcf82cff902420bb1deb17113c5dd3d1e24671c7f57071c184023398c40be4ecc6c59f460c21a859591f3
7
+ data.tar.gz: 488a91fa38b828e10bfeb4e70aace941a4814fcbb1b8d0fab3a6e7f7748383ffb8c67b94380197a31ea14192e702bd08471db15532f8b9490f4d64bbebb7c8c2
data/.rubocop.yml CHANGED
@@ -39,6 +39,9 @@ Metrics/BlockLength:
39
39
  - shared_examples_for
40
40
  - transaction
41
41
 
42
+ RSpec/ExampleLength:
43
+ Max: 25
44
+
42
45
  Metrics/MethodLength:
43
46
  Max: 25
44
47
 
@@ -102,3 +105,7 @@ RSpec/FilePath:
102
105
  RSpec/NamedSubject:
103
106
  Exclude:
104
107
  - "**/spec/**/*"
108
+
109
+ RSpec/MultipleExpectations:
110
+ Max: 5
111
+
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ # [0.1.0](https://github.com/klueless-io/appydave-tools/compare/v0.0.2...v0.1.0) (2024-05-08)
2
+
3
+
4
+ ### Features
5
+
6
+ * gpt context gatherer ([0c8089c](https://github.com/klueless-io/appydave-tools/commit/0c8089c60258a6032ea2b1fa0796a43cdd8f28c2))
7
+ * gpt context gatherer ([fe07156](https://github.com/klueless-io/appydave-tools/commit/fe0715699ad40379a1f0a1a99193d191a74e500b))
8
+
9
+ ## [0.0.2](https://github.com/klueless-io/appydave-tools/compare/v0.0.1...v0.0.2) (2024-05-07)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * update semantic dependency ([e76705e](https://github.com/klueless-io/appydave-tools/commit/e76705eb925f0be271884acc5af5119e3fa57325))
15
+ * update semantic dependency ([45623c4](https://github.com/klueless-io/appydave-tools/commit/45623c4575689ef1e813eb89bc9c55f3bf4d374f))
16
+ * update semantic dependency ([2ebb9bc](https://github.com/klueless-io/appydave-tools/commit/2ebb9bcb582b67b6bf4d8ccb6db9eff0e3b095e5))
17
+
1
18
  ## [Unreleased]
2
19
 
3
20
  ## [0.1.0] - 2024-05-07
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Usage:
5
+ # ./bin/gpt_context.rb -d -i 'lib/openai_101/tools/**/*.rb'
6
+ # ./bin/gpt_context.rb -d -i 'lib/openai_101/tools/**/*' -e 'node_modules/**/*' -e 'package-lock.json' -e 'lib/openai_101/tools/prompts/*.txt'
7
+ #
8
+ # Get GPT Context Gatherer code
9
+ # ./bin/gpt_context.rb -i 'bin/**/*gather*.rb' -i 'lib/openai_101/tools/**/*gather*.rb'
10
+ $LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
11
+
12
+ require 'appydave/tools'
13
+
14
+ options = {
15
+ include_patterns: [],
16
+ exclude_patterns: [],
17
+ format: nil,
18
+ debug: 'none'
19
+ }
20
+
21
+ OptionParser.new do |opts|
22
+ opts.banner = 'Usage: gather_content.rb [options]'
23
+
24
+ opts.on('-i', '--include PATTERN', 'Pattern or file to include (can be used multiple times)') do |pattern|
25
+ options[:include_patterns] << pattern
26
+ end
27
+
28
+ opts.on('-e', '--exclude PATTERN', 'Pattern or file to exclude (can be used multiple times)') do |pattern|
29
+ options[:exclude_patterns] << pattern
30
+ end
31
+
32
+ opts.on('-f', '--format FORMAT', 'Output format: default or tree') do |format|
33
+ options[:format] = format
34
+ end
35
+
36
+ # None - No debug output
37
+ # Output - Output the content to the console, this is the same as found in the clipboard
38
+ # Params - Output the options that were passed to the script
39
+ # Debug - Output content, options and debug information
40
+ opts.on('-d', '--debug [MODE]', 'Enable debug mode [none, output, params, debug]', 'none', 'output', 'params', 'debug') do |debug|
41
+ options[:debug] = debug || 'output'
42
+ end
43
+
44
+ opts.on_tail('-h', '--help', 'Show this message') do
45
+ puts opts
46
+ puts "\nExamples:"
47
+ puts " #{File.basename($PROGRAM_NAME)} -i 'lib/**/*.rb' -e 'lib/excluded/**/*.rb' -d"
48
+ puts " #{File.basename($PROGRAM_NAME)} --include 'src/**/*.js' --exclude 'src/vendor/**/*.js'"
49
+
50
+ puts ''
51
+ puts ' # Get GPT Context Gatherer code that is found in any folder (bin, lib & spec)'
52
+ puts " #{File.basename($PROGRAM_NAME)} -i '**/*gather*.rb'"
53
+ exit
54
+ end
55
+ end.parse!
56
+
57
+ if options[:include_patterns].empty? && options[:exclude_patterns].empty? && options[:format].nil?
58
+ script_name = File.basename($PROGRAM_NAME, File.extname($PROGRAM_NAME))
59
+
60
+ puts 'No options provided to GPT Context. Please specify patterns to include or exclude.'
61
+ puts "For help, run: #{script_name} --help"
62
+ exit
63
+ end
64
+
65
+ pp options if options[:debug] == 'params'
66
+
67
+ gatherer = Appydave::Tools::GptContext::FileCollector.new(
68
+ include_patterns: options[:include_patterns],
69
+ exclude_patterns: options[:exclude_patterns],
70
+ format: options[:format],
71
+ working_directory: Dir.pwd
72
+ )
73
+
74
+ content = gatherer.build
75
+
76
+ if %w[output debug].include?(options[:debug])
77
+ puts '-' * 80
78
+ puts content
79
+ puts '-' * 80
80
+ end
81
+
82
+ pp options if options[:debug] == 'debug'
83
+
84
+ Clipboard.copy(content)
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Appydave
4
+ module Tools
5
+ # Build GPT context from various sources
6
+ module GptContext
7
+ # Gathers file names and content based on include and exclude patterns
8
+ class FileCollector
9
+ attr_reader :include_patterns, :exclude_patterns, :format, :working_directory
10
+
11
+ def initialize(include_patterns: [], exclude_patterns: [], format: nil, working_directory: nil)
12
+ @include_patterns = include_patterns
13
+ @exclude_patterns = exclude_patterns
14
+ @format = format
15
+ @working_directory = working_directory
16
+ end
17
+
18
+ def build
19
+ FileUtils.cd(working_directory) if working_directory && Dir.exist?(working_directory)
20
+
21
+ result = case format
22
+ when 'tree'
23
+ build_tree
24
+ else
25
+ build_content
26
+ end
27
+
28
+ FileUtils.cd(Dir.home) if working_directory
29
+
30
+ result
31
+ end
32
+
33
+ private
34
+
35
+ def build_content
36
+ concatenated_content = []
37
+
38
+ include_patterns.each do |pattern|
39
+ Dir.glob(pattern).each do |file_path|
40
+ next if excluded?(file_path) || File.directory?(file_path)
41
+
42
+ content = "# file: #{file_path}\n\n#{File.read(file_path)}"
43
+ concatenated_content << content
44
+ end
45
+ end
46
+
47
+ concatenated_content.join("\n\n")
48
+ end
49
+
50
+ def build_tree
51
+ tree_view = {}
52
+
53
+ include_patterns.each do |pattern|
54
+ Dir.glob(pattern).each do |file_path|
55
+ next if excluded?(file_path)
56
+
57
+ path_parts = file_path.split('/')
58
+ insert_into_tree(tree_view, path_parts)
59
+ end
60
+ end
61
+
62
+ build_tree_pretty(tree_view).rstrip
63
+ end
64
+
65
+ def insert_into_tree(tree, path_parts)
66
+ node = tree
67
+ path_parts.each do |part|
68
+ node[part] ||= {}
69
+ node = node[part]
70
+ end
71
+ end
72
+
73
+ def build_tree_pretty(node, prefix: '', is_last: true, output: ''.dup)
74
+ node.each_with_index do |(part, child), index|
75
+ connector = is_last && index == node.size - 1 ? '└' : '├'
76
+ output << "#{prefix}#{connector}─ #{part}\n"
77
+ next_prefix = is_last && index == node.size - 1 ? ' ' : '│ '
78
+ build_tree_pretty(child, prefix: "#{prefix}#{next_prefix}", is_last: child.empty? || index == node.size - 1, output: output)
79
+ end
80
+ output
81
+ end
82
+
83
+ def excluded?(file_path)
84
+ exclude_patterns.any? { |pattern| File.fnmatch(pattern, file_path, File::FNM_PATHNAME | File::FNM_DOTMATCH) }
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Appydave
4
4
  module Tools
5
- VERSION = '0.0.2'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
@@ -1,6 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'optparse'
4
+ require 'clipboard'
5
+ require 'fileutils'
6
+
3
7
  require 'appydave/tools/version'
8
+ require 'appydave/tools/gpt_context/file_collector'
4
9
 
5
10
  module Appydave
6
11
  module Tools
@@ -12,8 +17,7 @@ module Appydave
12
17
  end
13
18
 
14
19
  if ENV.fetch('KLUE_DEBUG', 'false').downcase == 'true'
15
- namespace = 'AppydaveTools::Version'
16
- file_path = $LOADED_FEATURES.find { |f| f.include?('appydave/tools/version') }
17
- version = Appydave::Tools::VERSION.ljust(9)
18
- puts "#{namespace.ljust(35)} : #{version.ljust(9)} : #{file_path}"
20
+ $LOADED_FEATURES.find { |f| f.include?('appydave/tools/version') }
21
+ Appydave::Tools::VERSION.ljust(9)
22
+ # puts "#{namespace.ljust(35)} : #{version.ljust(9)} : #{file_path}"
19
23
  end
data/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "appydave-tools",
3
- "version": "0.0.2",
3
+ "version": "0.2.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "appydave-tools",
9
- "version": "0.0.2",
9
+ "version": "0.2.0",
10
10
  "devDependencies": {
11
11
  "@klueless-js/semantic-release-rubygem": "github:klueless-js/semantic-release-rubygem",
12
12
  "@semantic-release/changelog": "^6.0.3",
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "appydave-tools",
3
- "version": "0.0.2",
3
+ "version": "0.2.0",
4
4
  "description": "AppyDave YouTube Automation Tools",
5
5
  "scripts": {
6
6
  "release": "semantic-release"
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appydave-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-07 00:00:00.000000000 Z
11
+ date: 2024-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: k_log
14
+ name: clipboard
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '1'
27
27
  description: " AppyDave YouTube Automation Tools\n"
28
28
  email:
29
29
  - david@ideasmen.com.au
@@ -45,8 +45,10 @@ files:
45
45
  - README.md
46
46
  - Rakefile
47
47
  - bin/console
48
+ - bin/gpt_context.rb
48
49
  - bin/setup
49
50
  - lib/appydave/tools.rb
51
+ - lib/appydave/tools/gpt_context/file_collector.rb
50
52
  - lib/appydave/tools/version.rb
51
53
  - package-lock.json
52
54
  - package.json