start-command 0.7.5 → 0.9.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.
package/docs/PIPES.md ADDED
@@ -0,0 +1,243 @@
1
+ # Piping with start-command (`$`)
2
+
3
+ This document explains how to use pipes with the `$` command effectively.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Quick Summary](#quick-summary)
8
+ - [The Preferred Way: Pipe TO `$`](#the-preferred-way-pipe-to-)
9
+ - [Alternative: Quoting](#alternative-quoting)
10
+ - [Why This Matters](#why-this-matters)
11
+ - [Examples](#examples)
12
+ - [Troubleshooting](#troubleshooting)
13
+
14
+ ## Quick Summary
15
+
16
+ When piping data to a command wrapped with `$`, **put `$` on the receiving command**:
17
+
18
+ ```bash
19
+ # Preferred - pipe TO the $-wrapped command
20
+ echo "hi" | $ agent
21
+
22
+ # Alternative - quote the entire pipeline (more verbose)
23
+ $ 'echo "hi" | agent'
24
+ ```
25
+
26
+ Both approaches work, but piping TO `$` is simpler and requires fewer quotes.
27
+
28
+ ## The Preferred Way: Pipe TO `$`
29
+
30
+ The cleanest way to use pipes with `$` is to place `$` on the command that **receives** the piped input:
31
+
32
+ ```bash
33
+ # Data flows: echo "hi" -> agent (wrapped with $)
34
+ echo "hi" | $ agent
35
+ ```
36
+
37
+ This works because:
38
+
39
+ 1. The shell creates a pipeline: `echo "hi"` piped to `$ agent`
40
+ 2. `$ agent` receives "hi" on stdin
41
+ 3. The `$` command wraps `agent`, which processes the input
42
+
43
+ ### Real-World Examples
44
+
45
+ ```bash
46
+ # Pipe text to an AI agent
47
+ echo "Explain this code" | $ agent
48
+
49
+ # Pipe file contents to a processor
50
+ cat file.txt | $ processor
51
+
52
+ # Pipe command output to an analyzer
53
+ ls -la | $ analyzer
54
+
55
+ # Chain multiple commands, wrap the final one
56
+ cat data.json | jq '.items[]' | $ handler
57
+ ```
58
+
59
+ ### When to Use This Approach
60
+
61
+ Use `command | $ target` when:
62
+
63
+ - You want to pipe data INTO a command that `$` wraps
64
+ - You want the `$` logging and monitoring for the receiving command
65
+ - You prefer minimal quoting
66
+
67
+ ## Alternative: Quoting
68
+
69
+ You can also wrap the entire pipeline in quotes:
70
+
71
+ ```bash
72
+ # Single quotes preserve the pipe literally
73
+ $ 'echo "hi" | agent'
74
+
75
+ # The $ command receives the whole pipeline as one argument
76
+ $ 'cat file.txt | grep pattern | wc -l'
77
+ ```
78
+
79
+ ### When to Use Quoting
80
+
81
+ Use quotes when:
82
+
83
+ - You want `$` to wrap the ENTIRE pipeline (logging all commands)
84
+ - You need the pipeline to run as a single tracked unit
85
+ - You want a single log file for the whole operation
86
+
87
+ ### Quote Types
88
+
89
+ | Quote Type | Behavior | Example |
90
+ | ---------- | ------------------ | ---------------------- |
91
+ | `'single'` | Everything literal | `$ 'echo $HOME \| wc'` |
92
+ | `"double"` | Variables expand | `$ "echo $HOME \| wc"` |
93
+
94
+ ## Why This Matters
95
+
96
+ ### Shell Parsing Order
97
+
98
+ When you type a command, the shell parses it **before** any program runs:
99
+
100
+ ```
101
+ Without quotes or positioning:
102
+ $ echo "hi" | agent
103
+ └───┬────┘ └──┬──┘
104
+ │ │
105
+ Command 1 Command 2
106
+ ($ echo "hi") (agent)
107
+
108
+ Result: agent receives $ output, not "hi"
109
+ ```
110
+
111
+ The pipe `|` is a shell operator, so the shell splits the command at that point.
112
+
113
+ ### Solution Comparison
114
+
115
+ ```
116
+ Preferred - Pipe TO $:
117
+ echo "hi" | $ agent
118
+ └───┬────┘ └──┬──┘
119
+ │ │
120
+ Command 1 Command 2
121
+ (echo "hi") ($ agent)
122
+
123
+ Result: $ agent receives "hi" - correct!
124
+
125
+ Alternative - Quoting:
126
+ $ 'echo "hi" | agent'
127
+ └─────────┬──────────┘
128
+
129
+ Single command
130
+ (pipeline runs inside $)
131
+
132
+ Result: agent receives "hi" - correct!
133
+ ```
134
+
135
+ ## Examples
136
+
137
+ ### Basic Piping
138
+
139
+ ```bash
140
+ # Pipe text to a command
141
+ echo "hello world" | $ processor
142
+
143
+ # Pipe file contents
144
+ cat config.json | $ validator
145
+
146
+ # Pipe command output
147
+ git diff | $ reviewer
148
+ ```
149
+
150
+ ### Multiple Pipes
151
+
152
+ ```bash
153
+ # $ wraps only the final command
154
+ cat file.txt | grep "error" | $ reporter
155
+
156
+ # $ wraps the entire pipeline (quoted)
157
+ $ 'cat file.txt | grep "error" | wc -l'
158
+ ```
159
+
160
+ ### With Variables
161
+
162
+ ```bash
163
+ # Variable expands before piping (shell handles it)
164
+ echo "$HOME" | $ agent
165
+
166
+ # Variable preserved literally (single quotes)
167
+ $ 'echo $HOME | wc -c'
168
+ ```
169
+
170
+ ### Complex Commands
171
+
172
+ ```bash
173
+ # Process JSON and pipe to handler
174
+ curl -s https://api.example.com/data | jq '.items' | $ handler
175
+
176
+ # Pipe to a command with arguments
177
+ echo "analyze this" | $ agent --verbose --format json
178
+ ```
179
+
180
+ ## Troubleshooting
181
+
182
+ ### Problem: Output goes to wrong place
183
+
184
+ **Symptom:** Running `$ cmd1 | cmd2` and cmd2 receives unexpected output.
185
+
186
+ **Cause:** Shell parses `|` before `$` runs, so cmd2 gets `$` output.
187
+
188
+ **Solutions:**
189
+
190
+ 1. Pipe TO $: `cmd1 | $ cmd2`
191
+ 2. Quote: `$ 'cmd1 | cmd2'`
192
+
193
+ ### Problem: Command not receiving stdin
194
+
195
+ **Symptom:** `echo "data" | $ cmd` but cmd doesn't see the data.
196
+
197
+ **Check:** Does `cmd` read from stdin? Not all commands do.
198
+
199
+ **Test:** Try `echo "data" | cmd` without `$` first.
200
+
201
+ ### Problem: Quotes inside quotes
202
+
203
+ **Symptom:** `$ 'echo "hello 'world'"'` causes errors.
204
+
205
+ **Solutions:**
206
+
207
+ ```bash
208
+ # Use double quotes with escaping
209
+ $ "echo \"hello 'world'\""
210
+
211
+ # Or mix quote styles
212
+ echo "hello 'world'" | $ processor
213
+ ```
214
+
215
+ ### Problem: Variables not expanding
216
+
217
+ **Symptom:** `$ 'echo $HOME'` prints literal "$HOME".
218
+
219
+ **Cause:** Single quotes prevent expansion.
220
+
221
+ **Solutions:**
222
+
223
+ ```bash
224
+ # Use double quotes (escape the pipe)
225
+ $ "echo $HOME | wc -c"
226
+
227
+ # Or pipe TO $ (variable expands in source command)
228
+ echo "$HOME" | $ wc -c
229
+ ```
230
+
231
+ ## Summary
232
+
233
+ | Approach | Syntax | Best For |
234
+ | --------- | ------------------ | --------------------------- |
235
+ | Pipe TO $ | `cmd1 \| $ cmd2` | Simple piping, less quoting |
236
+ | Quoted | `$ 'cmd1 \| cmd2'` | Logging entire pipeline |
237
+
238
+ The preferred approach is **piping TO `$`** - it's simpler and avoids quote complexity.
239
+
240
+ ## See Also
241
+
242
+ - [USAGE.md](USAGE.md) - General usage guide
243
+ - [Case Study: Issue #28](case-studies/issue-28/README.md) - Detailed analysis
package/docs/USAGE.md ADDED
@@ -0,0 +1,194 @@
1
+ # start-command Usage Guide
2
+
3
+ This document provides detailed guidance on using the `$` command effectively, including important information about shell quoting and special characters.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Quick Start](#quick-start)
8
+ - [Using Pipes](#using-pipes)
9
+ - [Shell Metacharacters](#shell-metacharacters)
10
+ - [Quoting Reference](#quoting-reference)
11
+ - [Command Examples](#command-examples)
12
+ - [Troubleshooting](#troubleshooting)
13
+
14
+ ## Quick Start
15
+
16
+ The `$` command wraps any shell command with automatic logging and failure reporting:
17
+
18
+ ```bash
19
+ $ echo "Hello World"
20
+ $ npm test
21
+ $ git status
22
+ ```
23
+
24
+ ## Using Pipes
25
+
26
+ When piping data to a command wrapped with `$`, there are two approaches. **The preferred way is to pipe TO the `$`-wrapped command**:
27
+
28
+ ```bash
29
+ # Preferred - pipe TO the $-wrapped command
30
+ echo "hi" | $ agent
31
+
32
+ # Alternative - quote the entire pipeline
33
+ $ 'echo "hi" | agent'
34
+ ```
35
+
36
+ The first approach is simpler and requires fewer quotes. For detailed information about piping, see **[PIPES.md](PIPES.md)**.
37
+
38
+ ### Quick Examples
39
+
40
+ ```bash
41
+ # Pipe text to an AI agent
42
+ echo "Explain this code" | $ agent
43
+
44
+ # Pipe file contents to a processor
45
+ cat file.txt | $ processor
46
+
47
+ # Chain commands, wrap the final one
48
+ git diff | $ reviewer
49
+ ```
50
+
51
+ ## Shell Metacharacters
52
+
53
+ The following characters are interpreted by the shell before reaching `$`:
54
+
55
+ | Character | Name | Purpose |
56
+ | --------- | ---------- | ------------------------------------- |
57
+ | `\|` | Pipe | Connects stdout to stdin |
58
+ | `&` | Background | Runs command in background |
59
+ | `;` | Semicolon | Command separator |
60
+ | `&&` | AND | Run next command if previous succeeds |
61
+ | `\|\|` | OR | Run next command if previous fails |
62
+ | `>` | Redirect | Redirect stdout to file |
63
+ | `<` | Input | Read input from file |
64
+ | `$` | Variable | Variable expansion |
65
+ | `` ` `` | Backtick | Command substitution |
66
+ | `*?[]` | Globs | Filename expansion |
67
+
68
+ ## Quoting Reference
69
+
70
+ When you need to pass special characters literally to `$`, use quotes:
71
+
72
+ | Quote Type | Behavior | Use When |
73
+ | ----------- | -------------------------------------- | --------------------------------------- |
74
+ | `'single'` | Everything is literal, no expansion | Preserving pipes, special chars exactly |
75
+ | `"double"` | Variables expand, some escaping needed | Need variable expansion inside |
76
+ | `$'...'` | ANSI-C quoting, escape sequences work | Need escape sequences like `\n`, `\t` |
77
+ | `` `...` `` | Command substitution (old style) | Capturing command output (prefer `$()`) |
78
+
79
+ ### Examples with Different Quote Styles
80
+
81
+ ```bash
82
+ # Single quotes - everything literal
83
+ $ 'echo "hello" | wc -c'
84
+
85
+ # Double quotes - variables expand
86
+ $ "echo $HOME | wc -c" # $HOME expands first!
87
+
88
+ # Double quotes with escaping
89
+ $ "echo \$HOME | wc -c" # \$ keeps it literal
90
+ ```
91
+
92
+ ## Command Examples
93
+
94
+ ### Simple Commands (No Quoting Needed)
95
+
96
+ ```bash
97
+ $ ls -la
98
+ $ npm test
99
+ $ git status
100
+ $ echo "hello world"
101
+ ```
102
+
103
+ ### Commands with Pipes
104
+
105
+ ```bash
106
+ # Preferred: pipe TO the $-wrapped command
107
+ echo "hello" | $ grep "h"
108
+ cat file.txt | $ processor
109
+ git log | $ reviewer
110
+
111
+ # Alternative: quote the entire pipeline
112
+ $ 'cat file.txt | grep pattern'
113
+ $ 'ps aux | grep node'
114
+ ```
115
+
116
+ ### Commands with Redirection (Quoting Required)
117
+
118
+ ```bash
119
+ $ 'echo "data" > output.txt'
120
+ $ 'cat < input.txt'
121
+ $ 'npm test 2>&1 | tee test.log'
122
+ ```
123
+
124
+ ### Commands with Logical Operators (Quoting Required)
125
+
126
+ ```bash
127
+ $ 'npm install && npm test'
128
+ $ 'command1 || command2'
129
+ $ 'test -f file && cat file'
130
+ ```
131
+
132
+ ### Commands with Background Processes (Quoting Required)
133
+
134
+ ```bash
135
+ $ 'npm start &'
136
+ $ 'sleep 10 && echo "done" &'
137
+ ```
138
+
139
+ ### Commands with Variables
140
+
141
+ ```bash
142
+ # Variable expands BEFORE $ sees it (usually what you want)
143
+ $ echo "$HOME"
144
+
145
+ # Variable is passed literally to $ (rare use case)
146
+ $ 'echo $HOME'
147
+ ```
148
+
149
+ ## Troubleshooting
150
+
151
+ ### Problem: Pipe Output Goes to Wrong Place
152
+
153
+ **Symptom:** Running `$ cmd1 | cmd2` and cmd2 receives unexpected output.
154
+
155
+ **Solutions:**
156
+
157
+ 1. Pipe TO $: `cmd1 | $ cmd2` (preferred)
158
+ 2. Quote: `$ 'cmd1 | cmd2'`
159
+
160
+ ### Problem: Variables Not Expanding
161
+
162
+ **Symptom:** `$ 'echo $HOME'` literally prints "$HOME"
163
+
164
+ **Solution:** Use double quotes: `$ "echo $HOME"` or pipe: `echo "$HOME" | $ processor`
165
+
166
+ ### Problem: Special Characters Causing Errors
167
+
168
+ **Symptom:** Commands with `*`, `?`, `[`, `]` behave unexpectedly
169
+
170
+ **Solution:** Quote the command or escape the characters:
171
+
172
+ ```bash
173
+ $ 'ls *.txt' # Quotes prevent glob expansion by outer shell
174
+ $ ls \*.txt # Escape prevents expansion
175
+ ```
176
+
177
+ ### Problem: Command with Internal Quotes
178
+
179
+ **Symptom:** `$ 'echo "hello 'world'"'` causes syntax errors
180
+
181
+ **Solution:** Use different quote styles or escape:
182
+
183
+ ```bash
184
+ $ "echo \"hello 'world'\"" # Use double quotes with escaping
185
+ $ $'echo "hello \'world\'"' # Use ANSI-C quoting
186
+ ```
187
+
188
+ ## Further Reading
189
+
190
+ - [PIPES.md](PIPES.md) - Detailed guide on piping with `$`
191
+ - [Bash Reference Manual - Quoting](https://www.gnu.org/software/bash/manual/html_node/Quoting.html)
192
+ - [Bash Reference Manual - Pipelines](https://www.gnu.org/software/bash/manual/html_node/Pipelines.html)
193
+ - [POSIX Shell Command Language](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html)
194
+ - [Case Study: Issue #28 - Shell Quoting Analysis](case-studies/issue-28/README.md)