agent-context 0.0.2 → 0.1.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.
@@ -1,114 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Released under the MIT License.
4
- # Copyright, 2025, by Shopify Inc.
5
- # Copyright, 2025, by Samuel Williams.
6
-
7
- require "rubygems"
8
- require "fileutils"
9
- require "pathname"
10
-
11
- module Agent
12
- module Context
13
- class Helper
14
- def initialize(root: Dir.pwd, specifications: ::Gem::Specification)
15
- @root = root
16
- @context_path = ".context"
17
- @specifications = specifications
18
- end
19
-
20
- # Find all gems that have a context directory
21
- def find_gems_with_context(skip_local: true)
22
- gems_with_context = []
23
-
24
- @specifications.each do |spec|
25
- # Skip gems loaded from current working directory if requested:
26
- next if skip_local && spec.full_gem_path == @root
27
-
28
- context_path = File.join(spec.full_gem_path, "context")
29
- if Dir.exist?(context_path)
30
- gems_with_context << {
31
- name: spec.name,
32
- version: spec.version.to_s,
33
- path: context_path
34
- }
35
- end
36
- end
37
-
38
- gems_with_context
39
- end
40
-
41
- # Find a specific gem with context
42
- def find_gem_with_context(gem_name)
43
- spec = @specifications.find { |s| s.name == gem_name }
44
- return nil unless spec
45
-
46
- context_path = File.join(spec.full_gem_path, "context")
47
-
48
- if Dir.exist?(context_path)
49
- {
50
- name: spec.name,
51
- version: spec.version.to_s,
52
- path: context_path
53
- }
54
- else
55
- nil
56
- end
57
- end
58
-
59
- # List context files for a gem
60
- def list_context_files(gem_name)
61
- gem = find_gem_with_context(gem_name)
62
- return nil unless gem
63
-
64
- Dir.glob(File.join(gem[:path], "**/*")).select { |f| File.file?(f) }
65
- end
66
-
67
- # Show content of a specific context file
68
- def show_context_file(gem_name, file_name)
69
- gem = find_gem_with_context(gem_name)
70
- return nil unless gem
71
-
72
- # Try to find the file with or without extension
73
- possible_paths = [
74
- File.join(gem[:path], file_name),
75
- File.join(gem[:path], "#{file_name}.md"),
76
- File.join(gem[:path], "#{file_name}.md")
77
- ]
78
-
79
- file_path = possible_paths.find { |path| File.exist?(path) }
80
- return nil unless file_path
81
-
82
- File.read(file_path)
83
- end
84
-
85
- # Install context from a specific gem
86
- def install_gem_context(gem_name)
87
- gem = find_gem_with_context(gem_name)
88
- return false unless gem
89
-
90
- target_path = File.join(@context_path, gem_name)
91
- FileUtils.mkdir_p(target_path)
92
-
93
- # Copy all files from the gem's context directory
94
- FileUtils.cp_r(File.join(gem[:path], "."), target_path)
95
-
96
- true
97
- end
98
-
99
- # Install context from all gems
100
- def install_all_context(skip_local: true)
101
- gems = find_gems_with_context(skip_local: skip_local)
102
- installed = []
103
-
104
- gems.each do |gem|
105
- if install_gem_context(gem[:name])
106
- installed << gem[:name]
107
- end
108
- end
109
-
110
- installed
111
- end
112
- end
113
- end
114
- end