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 +4 -4
- data/lib/ask/skills/shell.patterns/SKILL.md +175 -0
- data/lib/ask/tools/shell/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 57dd21c05244ce8dfcdc2b9c631ed37983b0d87071421906c7a38b090a36d237
|
|
4
|
+
data.tar.gz: 786e6bb78c5f98840d45554d77c826ddec8c94320fba1696425833e865bfef6e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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 |
|
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.
|
|
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
|