ask-tools-shell 0.2.0 → 0.2.1

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: 40e217bcf42a1f1cdf4b3bf6d256e06aa21ee4e9c946706a1728dc8bf049e6a0
4
- data.tar.gz: cb157c2d84e1c162de9cab25394dec75ffdf65276e55a70537acc145424a7c1f
3
+ metadata.gz: 57dd21c05244ce8dfcdc2b9c631ed37983b0d87071421906c7a38b090a36d237
4
+ data.tar.gz: 786e6bb78c5f98840d45554d77c826ddec8c94320fba1696425833e865bfef6e
5
5
  SHA512:
6
- metadata.gz: 9b204fd0304eb672ad90c8359bafe27454441019079a64a38a73026f8fc3b0003098cb9df034827feb19324490c82f88d67b9642d521a3a7aad0769cb0cab9c7
7
- data.tar.gz: 9150cd2ccab75a75dfec81125b6ab6c8308ae2853a07e4d158e3244a231777acbd2f03895deacf53c910f2229f06005c70a032253ee6c14a02c2d7381e9e1149
6
+ metadata.gz: cc2b723b0e12766e682ad46cebe01b60cd35fbc8df1fbece1c165f03f05bdfd3b534745cb57af78dac6bf550130a6cc21431f67f31d640ce025cfef7ec91b300
7
+ data.tar.gz: 7f5bf812384a63539c90b153d3bb1e5bfc30014634f357ce49bbf4f8860fbb423ac0dda9e813da12f50e0a0d6c3614e7b8a95dfaee95c738674bfcd53a3e4ec3
@@ -0,0 +1,175 @@
1
+ ---
2
+ name: shell.patterns
3
+ description: Common shell tool composition patterns for code analysis, searching, and file manipulation
4
+ ---
5
+
6
+ Use this skill when you need to search, analyze, or manipulate a codebase using
7
+ shell tools. These patterns show you the most effective way to combine tools
8
+ for common tasks.
9
+
10
+ ## Pattern 1: Find and Search with Glob + Grep
11
+
12
+ The most powerful pattern for code analysis is combining Glob and Grep.
13
+
14
+ **Find files of a type, then search their contents:**
15
+
16
+ ```ruby
17
+ # Step 1: Find relevant files
18
+ result = Glob.new.call(pattern: "**/*.rb", path: "/path/to/project")
19
+
20
+ # Step 2: Search for a pattern in those files
21
+ Grep.new.call(pattern: "class.*API", path: "/path/to/project", include: "*.rb")
22
+ ```
23
+
24
+ **Search first to narrow, then read specific files:**
25
+
26
+ ```ruby
27
+ # Step 1: Find where a method is used
28
+ Grep.new.call(pattern: "def process_payment", path: "/project")
29
+
30
+ # Step 2: Read the specific files found
31
+ Read.new.call(path: "/project/app/services/payment_processor.rb")
32
+ ```
33
+
34
+ ## Pattern 2: Read Files with Offset/Limit
35
+
36
+ When reading large files, use offset and limit to navigate:
37
+
38
+ ```ruby
39
+ # Read the first 50 lines
40
+ Read.new.call(path: "large_file.rb", limit: 50)
41
+
42
+ # Then read from where you left off
43
+ Read.new.call(path: "large_file.rb", offset: 50, limit: 50)
44
+ ```
45
+
46
+ This avoids truncation and lets you browse files in chunks.
47
+
48
+ ## Pattern 3: Pipe Shell Commands via Bash
49
+
50
+ For complex queries that aren't a simple grep, use Bash with pipes:
51
+
52
+ ```ruby
53
+ # Count lines of Ruby code
54
+ Bash.new.call(command: "find . -name '*.rb' -exec cat {} \\; | wc -l", workdir: "/project")
55
+
56
+ # Find the top 10 largest files
57
+ Bash.new.call(command: "find . -name '*.rb' -exec wc -l {} \\; | sort -rn | head -10", workdir: "/project")
58
+
59
+ # Search git history
60
+ Bash.new.call(command: "git log --oneline --all --grep='fix' | head -20", workdir: "/project")
61
+ ```
62
+
63
+ ## Pattern 4: Edit with Read + Edit + Read
64
+
65
+ The safe way to make changes is Read → Edit → Read:
66
+
67
+ ```ruby
68
+ # Step 1: Read the file to find exact text
69
+ Read.new.call(path: "app/models/user.rb")
70
+
71
+ # Step 2: Edit with exact match (provide surrounding context for uniqueness)
72
+ Edit.new.call(
73
+ path: "app/models/user.rb",
74
+ old_string: "has_many :posts",
75
+ new_string: "has_many :posts, dependent: :destroy"
76
+ )
77
+
78
+ # Step 3: Verify the change
79
+ Read.new.call(path: "app/models/user.rb", limit: 30)
80
+ ```
81
+
82
+ When a string could appear multiple times:
83
+ ```ruby
84
+ # First verify occurrences
85
+ Grep.new.call(pattern: "old_string", path: "/project")
86
+
87
+ # Then replace all if appropriate
88
+ Edit.new.call(path: "file.rb", old_string: "old", new_string: "new", replace_all: true)
89
+ ```
90
+
91
+ ## Pattern 5: Code Execution for Quick Ruby Checks
92
+
93
+ Use Code for ad-hoc Ruby that doesn't need tools:
94
+
95
+ ```ruby
96
+ # Check Ruby version or gem availability
97
+ Code.new.call(code: "puts Gem::Specification.map(&:name).grep(/devise/).first")
98
+
99
+ # Parse and inspect data structures
100
+ Code.new.call(code: "require 'json'; data = JSON.parse(File.read('data.json')); puts data.keys")
101
+
102
+ # Test a regex before using it in Grep
103
+ Code.new.call(code: "puts /foo.*bar/.match?('foo_baz_bar')")
104
+ ```
105
+
106
+ ## Pattern 6: Write Files with Content
107
+
108
+ Create or overwrite files with Write:
109
+
110
+ ```ruby
111
+ # Create a new file
112
+ Write.new.call(path: "/project/app/services/new_service.rb", content: <<~RUBY)
113
+ class NewService
114
+ def call
115
+ # ...
116
+ end
117
+ end
118
+ RUBY
119
+ ```
120
+
121
+ Write creates parent directories automatically — no need for mkdir -p first.
122
+
123
+ ## Pattern 7: Project Structure Overview
124
+
125
+ Get a quick lay of the land:
126
+
127
+ ```ruby
128
+ # List top-level structure
129
+ Read.new.call(path: "/project")
130
+
131
+ # Count files by type
132
+ Bash.new.call(command: "find . -name '*.rb' | sed 's/.*\\.//' | sort | uniq -c | sort -rn", workdir: "/project")
133
+
134
+ # List all models or controllers
135
+ Glob.new.call(pattern: "app/models/**/*.rb", path: "/project")
136
+ Glob.new.call(pattern: "app/controllers/**/*.rb", path: "/project")
137
+ ```
138
+
139
+ ## Pattern 8: Search with Exclusions
140
+
141
+ To exclude test directories or vendor code:
142
+
143
+ ```ruby
144
+ # Grep already excludes .git, node_modules, vendor, .bundle, tmp, log
145
+ # For additional exclusions, use Bash:
146
+ Bash.new.call(
147
+ command: "grep -rn 'search_term' app/ lib/ --include='*.rb' | grep -v '_spec.rb' | head -50",
148
+ workdir: "/project"
149
+ )
150
+ ```
151
+
152
+ ## Pattern 9: Sequential File Processing
153
+
154
+ When you need to apply the same pattern across multiple files:
155
+
156
+ ```ruby
157
+ # Step 1: Find the files
158
+ result = Glob.new.call(pattern: "app/views/**/*.erb", path: "/project")
159
+
160
+ # Step 2: Search for the pattern you need to understand
161
+ Grep.new.call(pattern: "data-controller", path: "/project", include: "*.erb")
162
+ ```
163
+
164
+ ## Efficiency Guide
165
+
166
+ | Task | Best Tool | Why |
167
+ |------|-----------|-----|
168
+ | Find files by name pattern | Glob | Fast, sorted newest first |
169
+ | Search file contents | Grep | Pattern-aware, excludes cruft |
170
+ | Read small files | Read | Line numbers, truncation-safe |
171
+ | Read large files | Read (offset/limit) | Navigate in chunks |
172
+ | Complex shell queries | Bash | Full shell power |
173
+ | Ad-hoc Ruby checks | Code | Direct Ruby execution |
174
+ | Make changes | Edit | Exact string replacement |
175
+ | Create files | Write | Mkdir-p + write in one |
@@ -3,7 +3,7 @@
3
3
  module Ask
4
4
  module Tools
5
5
  module Shell
6
- VERSION = "0.2.0"
6
+ VERSION = "0.2.1"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ask-tools-shell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaka Ruto
@@ -89,6 +89,7 @@ files:
89
89
  - LICENSE
90
90
  - README.md
91
91
  - lib/ask-tools-shell.rb
92
+ - lib/ask/skills/shell.patterns/SKILL.md
92
93
  - lib/ask/tools/shell.rb
93
94
  - lib/ask/tools/shell/bash.rb
94
95
  - lib/ask/tools/shell/code.rb