start-command 0.7.5 → 0.7.6
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/CHANGELOG.md +12 -0
- package/README.md +23 -0
- package/docs/PIPES.md +243 -0
- package/docs/USAGE.md +194 -0
- package/docs/case-studies/issue-28/README.md +405 -0
- package/docs/case-studies/issue-28/issue-data.json +105 -0
- package/docs/case-studies/issue-28/raw-issue-data.md +92 -0
- package/package.json +1 -1
- package/src/bin/cli.js +10 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# start-command
|
|
2
2
|
|
|
3
|
+
## 0.7.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a5fca3f: Add documentation for piping with `$` command
|
|
8
|
+
- Created `docs/PIPES.md` with detailed guide on pipe usage
|
|
9
|
+
- Preferred approach: `echo "hi" | $ agent` (pipe TO the $-wrapped command)
|
|
10
|
+
- Alternative approach: `$ 'echo "hi" | agent'` (quoting)
|
|
11
|
+
- Updated `docs/USAGE.md` with brief pipe reference
|
|
12
|
+
- Updated `README.md` with piping examples
|
|
13
|
+
- Updated case study for issue #28 with new recommended approach
|
|
14
|
+
|
|
3
15
|
## 0.7.5
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -21,6 +21,29 @@ $ npm test
|
|
|
21
21
|
$ git status
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
+
### Piping with `$`
|
|
25
|
+
|
|
26
|
+
When piping data to a command wrapped with `$`, **put `$` on the receiving command**:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# Preferred - pipe TO the $-wrapped command
|
|
30
|
+
echo "hi" | $ agent
|
|
31
|
+
|
|
32
|
+
# Alternative - quote the entire pipeline (more verbose)
|
|
33
|
+
$ 'echo "hi" | agent'
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Both approaches work, but piping TO `$` is simpler and requires fewer quotes.
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# More examples
|
|
40
|
+
cat file.txt | $ processor
|
|
41
|
+
git diff | $ reviewer
|
|
42
|
+
echo "analyze this" | $ agent --verbose
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
See [docs/PIPES.md](docs/PIPES.md) for detailed guidance on piping, and [docs/USAGE.md](docs/USAGE.md) for general usage.
|
|
46
|
+
|
|
24
47
|
### Natural Language Commands (Aliases)
|
|
25
48
|
|
|
26
49
|
You can also use natural language to execute common commands. The `$` command supports pattern-based substitutions defined in `substitutions.lino`:
|
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)
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
# Case Study: Issue #28 - Shell Quoting with Pipe Operator
|
|
2
|
+
|
|
3
|
+
## Issue Summary
|
|
4
|
+
|
|
5
|
+
**Issue URL:** https://github.com/link-foundation/start/issues/28
|
|
6
|
+
**Date Reported:** 2025-12-24
|
|
7
|
+
**Reporter:** @konard
|
|
8
|
+
**Labels:** bug, documentation, enhancement, question
|
|
9
|
+
**Status:** Under Analysis
|
|
10
|
+
|
|
11
|
+
### Problem Statement
|
|
12
|
+
|
|
13
|
+
When using the `$` command (start-command) with pipe operators (`|`) and double quotes (`"`) in the command, users need to wrap the entire command in single quotes to get the expected behavior. Without the quotes, the shell parses the pipe operator **before** passing arguments to the `$` command.
|
|
14
|
+
|
|
15
|
+
**Example - Undesired behavior:**
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
$ echo "hi" | agent
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The shell interprets this as: "Run `$ echo "hi"` and pipe its output to `agent`"
|
|
22
|
+
|
|
23
|
+
**Example - Desired behavior (requires single quotes):**
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
$ 'echo "hi" | agent'
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The shell interprets this as: "Run `$` with the argument `echo "hi" | agent`"
|
|
30
|
+
|
|
31
|
+
### Environment
|
|
32
|
+
|
|
33
|
+
- **Platform:** macOS (darwin)
|
|
34
|
+
- **Package:** start-command (version assumed latest)
|
|
35
|
+
- **Shell:** /bin/zsh
|
|
36
|
+
- **Bun Version:** 1.2.20
|
|
37
|
+
- **Working Directory:** /Users/konard
|
|
38
|
+
|
|
39
|
+
## Timeline of Events
|
|
40
|
+
|
|
41
|
+
Based on the terminal logs provided in the issue:
|
|
42
|
+
|
|
43
|
+
### Timestamp 1: 15:07:08.894 - Unquoted Command
|
|
44
|
+
|
|
45
|
+
1. **User input:** `$ echo "hi" | agent`
|
|
46
|
+
2. **Shell parsing:** The shell parsed this as TWO separate commands:
|
|
47
|
+
- Command 1: `$ echo "hi"` (run `$` with argument `echo "hi"`)
|
|
48
|
+
- Pipe: `|` (pipe stdout of command 1 to stdin of command 2)
|
|
49
|
+
- Command 2: `agent` (run `agent` with stdin from pipe)
|
|
50
|
+
3. **Result:** The `$` command executed `echo "hi"` and logged it, showing:
|
|
51
|
+
```
|
|
52
|
+
Command: echo hi
|
|
53
|
+
Exit Code: 0
|
|
54
|
+
```
|
|
55
|
+
4. **What agent received:** The `agent` received the JSON output from the `$` command (status messages, tool use messages, etc.) via the pipe - NOT the original command.
|
|
56
|
+
5. **Agent's response:** The agent saw the log file and responded about the `echo hi` execution, not the "hi" message itself.
|
|
57
|
+
|
|
58
|
+
### Timestamp 2: 15:07:33.420 - Quoted Command
|
|
59
|
+
|
|
60
|
+
1. **User input:** `$ 'echo "hi" | agent'`
|
|
61
|
+
2. **Shell parsing:** The shell parsed this as ONE command:
|
|
62
|
+
- Command: `$` with a single argument: `echo "hi" | agent`
|
|
63
|
+
3. **Result:** The `$` command received the entire string and executed it as a pipeline
|
|
64
|
+
4. **What agent received:** The output of `echo "hi"` which is `hi`
|
|
65
|
+
5. **Agent's response:** "Hello! How can I help you today?" (responding to "hi" as input)
|
|
66
|
+
|
|
67
|
+
## Sequence Diagrams
|
|
68
|
+
|
|
69
|
+
### Scenario 1: Without Quotes (Problematic)
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
User Input: $ echo "hi" | agent
|
|
73
|
+
└───┬────┘ └──┬──┘
|
|
74
|
+
│ │
|
|
75
|
+
┌────────────┴───────────┴────────────┐
|
|
76
|
+
│ Shell (zsh/bash) │
|
|
77
|
+
│ Tokenizes command line into: │
|
|
78
|
+
│ Command 1: ['$', 'echo', '"hi"'] │
|
|
79
|
+
│ Operator: | │
|
|
80
|
+
│ Command 2: ['agent'] │
|
|
81
|
+
└────────────────────────────────────┘
|
|
82
|
+
│ │
|
|
83
|
+
┌────────────┴───┐ ┌───┴────────────┐
|
|
84
|
+
│ $ (start-cmd) │ │ agent │
|
|
85
|
+
│ executes: │──→│ receives: │
|
|
86
|
+
│ "echo hi" │ │ JSON output │
|
|
87
|
+
│ │ │ from $ cmd │
|
|
88
|
+
└────────────────┘ └────────────────┘
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Scenario 2: With Quotes (Desired)
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
User Input: $ 'echo "hi" | agent'
|
|
95
|
+
└─────────┬──────────┘
|
|
96
|
+
│
|
|
97
|
+
┌──────────────────┴──────────────────┐
|
|
98
|
+
│ Shell (zsh/bash) │
|
|
99
|
+
│ Tokenizes command line into: │
|
|
100
|
+
│ Command: ['$', 'echo "hi" | agent']
|
|
101
|
+
│ Single quotes prevent parsing │
|
|
102
|
+
└──────────────────────────────────────┘
|
|
103
|
+
│
|
|
104
|
+
┌──────────────────┴──────────────────┐
|
|
105
|
+
│ $ (start-command) │
|
|
106
|
+
│ Receives: "echo \"hi\" | agent" │
|
|
107
|
+
│ Spawns shell with: │
|
|
108
|
+
│ /bin/zsh -c 'echo "hi" | agent' │
|
|
109
|
+
│ │
|
|
110
|
+
│ ┌──────────┐ ┌─────────┐ │
|
|
111
|
+
│ │ echo "hi"│─────→│ agent │ │
|
|
112
|
+
│ │ stdout: │ │ stdin: │ │
|
|
113
|
+
│ │ "hi" │ │ "hi" │ │
|
|
114
|
+
│ └──────────┘ └─────────┘ │
|
|
115
|
+
└──────────────────────────────────────┘
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Root Cause Analysis
|
|
119
|
+
|
|
120
|
+
### PRIMARY ROOT CAUSE: Shell Grammar and Operator Precedence
|
|
121
|
+
|
|
122
|
+
The root cause is **not a bug in start-command** but rather a fundamental aspect of how POSIX shells parse command lines.
|
|
123
|
+
|
|
124
|
+
According to the [Bash Reference Manual - Pipelines](https://www.gnu.org/software/bash/manual/html_node/Pipelines.html):
|
|
125
|
+
|
|
126
|
+
> "A pipeline is a sequence of one or more commands separated by one of the control operators `|` or `|&`."
|
|
127
|
+
|
|
128
|
+
The shell's parsing order is:
|
|
129
|
+
|
|
130
|
+
1. **Tokenization:** The command line is split into tokens
|
|
131
|
+
2. **Operator Recognition:** Pipe (`|`), redirections (`>`, `<`), and logical operators (`&&`, `||`) are identified
|
|
132
|
+
3. **Command Grouping:** Commands are grouped based on operators
|
|
133
|
+
4. **Quote Processing:** Quotes affect tokenization but don't change operator recognition
|
|
134
|
+
|
|
135
|
+
### Why This Happens
|
|
136
|
+
|
|
137
|
+
When you type:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
$ echo "hi" | agent
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
The shell sees:
|
|
144
|
+
|
|
145
|
+
- `$` - a command (the start-command binary)
|
|
146
|
+
- `echo` - an argument to `$`
|
|
147
|
+
- `"hi"` - another argument to `$` (quotes are stripped by shell)
|
|
148
|
+
- `|` - **pipe operator** (this is a metacharacter, not an argument)
|
|
149
|
+
- `agent` - a separate command that receives piped input
|
|
150
|
+
|
|
151
|
+
The pipe operator has special meaning to the shell and is **never** passed as an argument to commands unless quoted or escaped.
|
|
152
|
+
|
|
153
|
+
### Single Quotes Behavior
|
|
154
|
+
|
|
155
|
+
From the [GNU Bash Reference - Quoting](https://www.gnu.org/software/bash/manual/html_node/Quoting.html):
|
|
156
|
+
|
|
157
|
+
> "Enclosing characters in single quotes (`'`) preserves the literal value of each character within the quotes."
|
|
158
|
+
|
|
159
|
+
This means:
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
$ 'echo "hi" | agent'
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The shell sees:
|
|
166
|
+
|
|
167
|
+
- `$` - a command
|
|
168
|
+
- `echo "hi" | agent` - a single string argument (the `|` inside is literal, not a pipe operator)
|
|
169
|
+
|
|
170
|
+
### Operator Precedence Summary
|
|
171
|
+
|
|
172
|
+
From [Shell Grammar Rules](https://bargenqua.st/posts/bash-pipes/):
|
|
173
|
+
|
|
174
|
+
1. Redirections (`<`, `>`, `>>`) - highest precedence
|
|
175
|
+
2. Pipes (`|`) - next highest
|
|
176
|
+
3. Command separators (`;`, `&`, `&&`, `||`) - lower precedence
|
|
177
|
+
|
|
178
|
+
## Impact Assessment
|
|
179
|
+
|
|
180
|
+
### Who Is Affected
|
|
181
|
+
|
|
182
|
+
Users who want to:
|
|
183
|
+
|
|
184
|
+
1. Pipe content **through** the `$` command to another command
|
|
185
|
+
2. Use the `$` command to execute complex pipelines
|
|
186
|
+
3. Use `$` as part of a larger shell pipeline
|
|
187
|
+
|
|
188
|
+
### Severity
|
|
189
|
+
|
|
190
|
+
**Low-Medium**: The current behavior is technically correct - it follows POSIX shell semantics. However, it may be unintuitive for users who expect the entire command line to be passed to the `$` command.
|
|
191
|
+
|
|
192
|
+
## Proposed Solutions
|
|
193
|
+
|
|
194
|
+
### Solution 1: Pipe TO `$` (Recommended - Preferred Approach)
|
|
195
|
+
|
|
196
|
+
Instead of quoting, put `$` on the **receiving** command in the pipeline:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
# Preferred - pipe TO the $-wrapped command
|
|
200
|
+
echo "hi" | $ agent
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
This works because:
|
|
204
|
+
|
|
205
|
+
1. The shell creates a pipeline: `echo "hi"` piped to `$ agent`
|
|
206
|
+
2. `$ agent` receives "hi" on stdin
|
|
207
|
+
3. The `$` command wraps `agent`, which processes the input correctly
|
|
208
|
+
|
|
209
|
+
**Pros:**
|
|
210
|
+
|
|
211
|
+
- No quoting needed
|
|
212
|
+
- Simple and intuitive
|
|
213
|
+
- Works naturally with shell pipelines
|
|
214
|
+
|
|
215
|
+
**Cons:**
|
|
216
|
+
|
|
217
|
+
- Only works when piping TO a command (not for entire pipelines)
|
|
218
|
+
|
|
219
|
+
### Solution 2: Documentation Enhancement (Also Recommended)
|
|
220
|
+
|
|
221
|
+
Add clear documentation explaining:
|
|
222
|
+
|
|
223
|
+
1. How shell parsing affects the `$` command
|
|
224
|
+
2. When to use quotes around complex commands
|
|
225
|
+
3. Examples of common use cases
|
|
226
|
+
|
|
227
|
+
**Pros:**
|
|
228
|
+
|
|
229
|
+
- No code changes required
|
|
230
|
+
- Educates users about shell behavior
|
|
231
|
+
- Maintains POSIX compliance
|
|
232
|
+
|
|
233
|
+
**Cons:**
|
|
234
|
+
|
|
235
|
+
- Requires users to learn quoting rules
|
|
236
|
+
- May still feel unintuitive
|
|
237
|
+
|
|
238
|
+
### Solution 3: Use a Multi-Character Command Name
|
|
239
|
+
|
|
240
|
+
Instead of `$`, use a multi-character name like `start` or `run`:
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
start 'echo "hi" | agent' # Still needs quotes
|
|
244
|
+
start echo "hi" | agent # Same issue
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
**Pros:**
|
|
248
|
+
|
|
249
|
+
- Less visual confusion with shell's `$` variable syntax
|
|
250
|
+
- Easier to google and document
|
|
251
|
+
|
|
252
|
+
**Cons:**
|
|
253
|
+
|
|
254
|
+
- Doesn't solve the fundamental issue
|
|
255
|
+
- Breaks backward compatibility
|
|
256
|
+
|
|
257
|
+
### Solution 4: Wrapper Script with Here-Document
|
|
258
|
+
|
|
259
|
+
Create an alternative invocation method:
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
$$ <<'CMD'
|
|
263
|
+
echo "hi" | agent
|
|
264
|
+
CMD
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
**Pros:**
|
|
268
|
+
|
|
269
|
+
- No quoting issues
|
|
270
|
+
- Can handle multi-line commands
|
|
271
|
+
- Clear visual separation
|
|
272
|
+
|
|
273
|
+
**Cons:**
|
|
274
|
+
|
|
275
|
+
- Requires new syntax
|
|
276
|
+
- More verbose for simple commands
|
|
277
|
+
|
|
278
|
+
### Solution 5: Shell Function Alternative
|
|
279
|
+
|
|
280
|
+
Provide a shell function that users can source:
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
# In ~/.zshrc or ~/.bashrc
|
|
284
|
+
run() {
|
|
285
|
+
$ "$*"
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
# Usage:
|
|
289
|
+
run echo "hi" | agent # Still has the same issue!
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
**Pros:**
|
|
293
|
+
|
|
294
|
+
- More conventional naming
|
|
295
|
+
|
|
296
|
+
**Cons:**
|
|
297
|
+
|
|
298
|
+
- **Does not solve the problem** - shell parsing happens before function call
|
|
299
|
+
|
|
300
|
+
### Solution 6: Interactive Mode Detection
|
|
301
|
+
|
|
302
|
+
When `$` detects it's being piped to/from, emit a warning:
|
|
303
|
+
|
|
304
|
+
```bash
|
|
305
|
+
$ echo "hi" | agent
|
|
306
|
+
# Warning: $ stdout is being piped. Did you mean: $ 'echo "hi" | agent'?
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
**Pros:**
|
|
310
|
+
|
|
311
|
+
- Helps users understand what's happening
|
|
312
|
+
- Non-breaking change
|
|
313
|
+
|
|
314
|
+
**Cons:**
|
|
315
|
+
|
|
316
|
+
- Adds noise to output
|
|
317
|
+
- May interfere with legitimate piping use cases
|
|
318
|
+
|
|
319
|
+
### Solution 7: ZSH Global Alias (ZSH Only)
|
|
320
|
+
|
|
321
|
+
ZSH supports [global aliases](https://vonheikemen.github.io/devlog/tools/zsh-global-aliases/) that expand anywhere in the command:
|
|
322
|
+
|
|
323
|
+
```zsh
|
|
324
|
+
# In ~/.zshrc
|
|
325
|
+
alias -g '|$'='| $' # Not helpful
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
**Analysis:** This doesn't solve the problem because the issue is with the **input** to `$`, not its output.
|
|
329
|
+
|
|
330
|
+
## Recommended Approach
|
|
331
|
+
|
|
332
|
+
After careful analysis, the **recommended approach is Solution 1: Pipe TO `$`** combined with documentation enhancement:
|
|
333
|
+
|
|
334
|
+
1. **Preferred syntax**: `echo "hi" | $ agent` - pipe TO the `$`-wrapped command
|
|
335
|
+
2. **Alternative**: `$ 'echo "hi" | agent'` - quote the entire pipeline when needed
|
|
336
|
+
3. **Documentation**: Clear docs explaining both approaches
|
|
337
|
+
|
|
338
|
+
### Implementation Plan
|
|
339
|
+
|
|
340
|
+
1. **Documentation (docs/PIPES.md)** - New file:
|
|
341
|
+
- Detailed explanation of pipe usage
|
|
342
|
+
- Preferred approach: piping TO `$`
|
|
343
|
+
- Alternative approach: quoting
|
|
344
|
+
- Examples and troubleshooting
|
|
345
|
+
|
|
346
|
+
2. **Documentation (docs/USAGE.md)**:
|
|
347
|
+
- Brief section on pipes with link to PIPES.md
|
|
348
|
+
- Updated examples showing preferred syntax
|
|
349
|
+
|
|
350
|
+
3. **README.md Update**:
|
|
351
|
+
- Add piping examples showing preferred syntax
|
|
352
|
+
- Link to detailed documentation
|
|
353
|
+
|
|
354
|
+
4. **CLI Help Update** (Future Enhancement):
|
|
355
|
+
- Add a note about piping in `$ --help`
|
|
356
|
+
|
|
357
|
+
5. **Optional Warning** (Future Enhancement):
|
|
358
|
+
- Detect if stdout is a pipe
|
|
359
|
+
- Detect if command doesn't contain pipe-like patterns
|
|
360
|
+
- Emit helpful warning
|
|
361
|
+
|
|
362
|
+
## Key Learnings
|
|
363
|
+
|
|
364
|
+
1. **Shell parsing is fundamental**: Metacharacters like `|`, `&`, `;` are processed by the shell before commands receive arguments. This is not something applications can change.
|
|
365
|
+
|
|
366
|
+
2. **Single quotes are your friend**: When you want literal characters, use single quotes. When you want variable expansion inside, use double quotes with escaped special characters.
|
|
367
|
+
|
|
368
|
+
3. **The `$` symbol is contextual**: In shells, `$` typically introduces variable expansion (`$HOME`, `$PATH`). Using it as a command name, while valid, can be visually confusing.
|
|
369
|
+
|
|
370
|
+
4. **Education over code changes**: Some issues are best solved by educating users rather than adding complex workarounds that might introduce new problems.
|
|
371
|
+
|
|
372
|
+
5. **POSIX compliance matters**: Shell behavior is standardized. Fighting against it often creates more problems than it solves.
|
|
373
|
+
|
|
374
|
+
## Related Research
|
|
375
|
+
|
|
376
|
+
### Shell Quoting Resources
|
|
377
|
+
|
|
378
|
+
- [GNU Bash Reference Manual - Quoting](https://www.gnu.org/software/bash/manual/html_node/Quoting.html)
|
|
379
|
+
- [GNU Bash Reference Manual - Pipelines](https://www.gnu.org/software/bash/manual/html_node/Pipelines.html)
|
|
380
|
+
- [Advanced Quoting in Shell Scripts](https://scriptingosx.com/2020/04/advanced-quoting-in-shell-scripts/)
|
|
381
|
+
- [ZSH Global Aliases](https://vonheikemen.github.io/devlog/tools/zsh-global-aliases/)
|
|
382
|
+
|
|
383
|
+
### Shell Parsing Order
|
|
384
|
+
|
|
385
|
+
1. Tokenization (splitting into words)
|
|
386
|
+
2. Command identification
|
|
387
|
+
3. Alias expansion (if applicable)
|
|
388
|
+
4. Brace expansion
|
|
389
|
+
5. Tilde expansion
|
|
390
|
+
6. Parameter/variable expansion
|
|
391
|
+
7. Command substitution
|
|
392
|
+
8. Arithmetic expansion
|
|
393
|
+
9. Word splitting
|
|
394
|
+
10. Filename expansion (globbing)
|
|
395
|
+
11. Quote removal
|
|
396
|
+
|
|
397
|
+
The pipe operator (`|`) is recognized during **step 1 (tokenization)**, before any command receives its arguments.
|
|
398
|
+
|
|
399
|
+
## References
|
|
400
|
+
|
|
401
|
+
- [Bash Reference Manual](https://www.gnu.org/software/bash/manual/bash.html)
|
|
402
|
+
- [ZSH Expansion and Substitution](https://zsh.sourceforge.io/Doc/Release/Expansion.html)
|
|
403
|
+
- [POSIX Shell Command Language](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html)
|
|
404
|
+
- [Issue #25 Case Study](../issue-25/README.md) - Related shell quoting issues
|
|
405
|
+
- [Baeldung - Special Dollar Sign Variables](https://www.baeldung.com/linux/shell-special-dollar-sign-variables)
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
{
|
|
2
|
+
"issue": {
|
|
3
|
+
"number": 28,
|
|
4
|
+
"title": "Can we somehow overcome the need of `'` quotes with `|` and `\"` in a sequence?",
|
|
5
|
+
"url": "https://github.com/link-foundation/start/issues/28",
|
|
6
|
+
"state": "open",
|
|
7
|
+
"labels": ["bug", "documentation", "enhancement", "question"],
|
|
8
|
+
"author": "konard",
|
|
9
|
+
"created_at": "2025-12-24"
|
|
10
|
+
},
|
|
11
|
+
"environment": {
|
|
12
|
+
"platform": "darwin",
|
|
13
|
+
"shell": "/bin/zsh",
|
|
14
|
+
"bun_version": "1.2.20",
|
|
15
|
+
"working_directory": "/Users/konard"
|
|
16
|
+
},
|
|
17
|
+
"scenarios": [
|
|
18
|
+
{
|
|
19
|
+
"name": "unquoted_command",
|
|
20
|
+
"input": "$ echo \"hi\" | agent",
|
|
21
|
+
"timestamp": "2025-12-24 15:07:08.894",
|
|
22
|
+
"shell_interpretation": {
|
|
23
|
+
"command_1": "$ echo \"hi\"",
|
|
24
|
+
"operator": "|",
|
|
25
|
+
"command_2": "agent"
|
|
26
|
+
},
|
|
27
|
+
"actual_execution": {
|
|
28
|
+
"start_command_received": "echo \"hi\"",
|
|
29
|
+
"start_command_output": "hi",
|
|
30
|
+
"agent_received": "JSON output from start-command stdout"
|
|
31
|
+
},
|
|
32
|
+
"user_expectation": "agent should receive 'hi' from echo",
|
|
33
|
+
"actual_result": "agent received start-command JSON output",
|
|
34
|
+
"exit_code": 0
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"name": "quoted_command",
|
|
38
|
+
"input": "$ 'echo \"hi\" | agent'",
|
|
39
|
+
"timestamp": "2025-12-24 15:07:33.420",
|
|
40
|
+
"shell_interpretation": {
|
|
41
|
+
"command": "$",
|
|
42
|
+
"argument": "echo \"hi\" | agent"
|
|
43
|
+
},
|
|
44
|
+
"actual_execution": {
|
|
45
|
+
"start_command_received": "echo \"hi\" | agent",
|
|
46
|
+
"pipeline_executed": true,
|
|
47
|
+
"echo_output": "hi",
|
|
48
|
+
"agent_received": "hi"
|
|
49
|
+
},
|
|
50
|
+
"user_expectation": "agent should receive 'hi' from echo",
|
|
51
|
+
"actual_result": "agent received 'hi' from echo",
|
|
52
|
+
"exit_code": 0
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
"root_cause": {
|
|
56
|
+
"category": "shell_parsing_behavior",
|
|
57
|
+
"is_bug": false,
|
|
58
|
+
"description": "The pipe operator (|) is a shell metacharacter that is parsed by the shell before command arguments are passed. This is standard POSIX shell behavior, not a bug in start-command.",
|
|
59
|
+
"affected_shells": ["bash", "zsh", "sh", "dash", "ksh"],
|
|
60
|
+
"shell_parsing_order": [
|
|
61
|
+
"1. Tokenization - command line split into tokens",
|
|
62
|
+
"2. Operator recognition - | && || ; & recognized as metacharacters",
|
|
63
|
+
"3. Command grouping - commands grouped based on operators",
|
|
64
|
+
"4. Quote processing - quoted strings preserved",
|
|
65
|
+
"5. Expansion - variables, commands, etc. expanded"
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
"solutions": {
|
|
69
|
+
"recommended": "documentation_enhancement",
|
|
70
|
+
"options": [
|
|
71
|
+
{
|
|
72
|
+
"id": "documentation_enhancement",
|
|
73
|
+
"name": "Documentation Enhancement",
|
|
74
|
+
"description": "Add clear documentation about quoting requirements",
|
|
75
|
+
"pros": ["No code changes", "Educates users", "POSIX compliant"],
|
|
76
|
+
"cons": ["Requires users to learn quoting rules"],
|
|
77
|
+
"complexity": "low"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"id": "warning_detection",
|
|
81
|
+
"name": "Optional Warning Detection",
|
|
82
|
+
"description": "Detect when stdout is piped and emit helpful warning",
|
|
83
|
+
"pros": ["Helps users understand behavior", "Non-breaking"],
|
|
84
|
+
"cons": ["May add noise to output"],
|
|
85
|
+
"complexity": "medium"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"id": "here_document",
|
|
89
|
+
"name": "Here-Document Wrapper",
|
|
90
|
+
"description": "Support $$ <<'CMD' syntax for multi-line commands",
|
|
91
|
+
"pros": ["No quoting issues", "Clear syntax"],
|
|
92
|
+
"cons": ["More verbose", "New syntax to learn"],
|
|
93
|
+
"complexity": "high"
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
"references": {
|
|
98
|
+
"bash_manual": "https://www.gnu.org/software/bash/manual/bash.html",
|
|
99
|
+
"pipelines_doc": "https://www.gnu.org/software/bash/manual/html_node/Pipelines.html",
|
|
100
|
+
"quoting_doc": "https://www.gnu.org/software/bash/manual/html_node/Quoting.html",
|
|
101
|
+
"posix_shell": "https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html"
|
|
102
|
+
},
|
|
103
|
+
"analysis_date": "2025-12-24",
|
|
104
|
+
"analyst": "AI Issue Solver"
|
|
105
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# Issue #28 Raw Data
|
|
2
|
+
|
|
3
|
+
## Issue Title
|
|
4
|
+
|
|
5
|
+
Can we somehow overcome the need of `'` quotes with `|` and `"` in a sequence?
|
|
6
|
+
|
|
7
|
+
## Issue State
|
|
8
|
+
|
|
9
|
+
OPEN
|
|
10
|
+
|
|
11
|
+
## Issue Labels
|
|
12
|
+
|
|
13
|
+
bug, documentation, enhancement, question
|
|
14
|
+
|
|
15
|
+
## Issue Author
|
|
16
|
+
|
|
17
|
+
konard
|
|
18
|
+
|
|
19
|
+
## Issue Content
|
|
20
|
+
|
|
21
|
+
The issue shows two terminal sessions demonstrating different behaviors:
|
|
22
|
+
|
|
23
|
+
### Session 1: Without quoting the entire command
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
konard@MacBook-Pro-Konstantin ~ % $ echo "hi" | agent
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Result:** The `echo "hi"` command ran directly in the shell, and only its OUTPUT was piped to `agent`. The agent then processed the log file that was created by the `$` command (start-command), not the original command input.
|
|
30
|
+
|
|
31
|
+
The agent received the OUTPUT of `$ echo "hi"` which was captured in a log file, and then read that log file.
|
|
32
|
+
|
|
33
|
+
### Session 2: With quoting the entire command
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
konard@MacBook-Pro-Konstantin ~ % $ 'echo "hi" | agent'
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**Result:** The entire string `echo "hi" | agent` was passed TO the `$` command (start-command). The start-command then executed this complete pipeline, which resulted in the `echo "hi"` output being piped to `agent` correctly.
|
|
40
|
+
|
|
41
|
+
## Terminal Logs
|
|
42
|
+
|
|
43
|
+
### Session 1 Output (problematic behavior)
|
|
44
|
+
|
|
45
|
+
```json
|
|
46
|
+
{
|
|
47
|
+
"type": "status",
|
|
48
|
+
"mode": "stdin-stream",
|
|
49
|
+
"message": "Agent CLI in continuous listening mode. Accepts JSON and plain text input.",
|
|
50
|
+
"hint": "Press CTRL+C to exit. Use --help for options.",
|
|
51
|
+
"acceptedFormats": ["JSON object with \"message\" field", "Plain text"],
|
|
52
|
+
"options": {
|
|
53
|
+
"interactive": true,
|
|
54
|
+
"autoMergeQueuedMessages": true,
|
|
55
|
+
"alwaysAcceptStdin": true,
|
|
56
|
+
"compactJson": false
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The agent then read a log file:
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
=== Start Command Log ===
|
|
65
|
+
Timestamp: 2025-12-24 15:07:08.894
|
|
66
|
+
Command: echo hi
|
|
67
|
+
Shell: /bin/zsh
|
|
68
|
+
Platform: darwin
|
|
69
|
+
Bun Version: 1.2.20
|
|
70
|
+
Working Directory: /Users/konard
|
|
71
|
+
==================================================
|
|
72
|
+
|
|
73
|
+
hi
|
|
74
|
+
|
|
75
|
+
==================================================
|
|
76
|
+
Finished: 2025-12-24 15:07:08.906
|
|
77
|
+
Exit Code: 0
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
And responded:
|
|
81
|
+
|
|
82
|
+
> "It looks like you executed the command `echo hi`, which successfully output \"hi\" with exit code 0..."
|
|
83
|
+
|
|
84
|
+
### Session 2 Output (desired behavior)
|
|
85
|
+
|
|
86
|
+
The agent received "hi" directly as input and responded:
|
|
87
|
+
|
|
88
|
+
> "Hello! How can I help you today?"
|
|
89
|
+
|
|
90
|
+
## User Request
|
|
91
|
+
|
|
92
|
+
> Please download all logs and data related about the issue to this repository, make sure we compile that data to `./docs/case-studies/issue-{id}` folder, and use it to do deep case study analysis (also make sure to search online for additional facts and data), in which we will reconstruct timeline/sequence of events, find root causes of the problem, and propose possible solutions.
|
package/package.json
CHANGED
package/src/bin/cli.js
CHANGED
|
@@ -237,6 +237,16 @@ function printUsage() {
|
|
|
237
237
|
console.log(' $ -i screen -d bun start');
|
|
238
238
|
console.log(' $ --isolated docker --image oven/bun:latest -- bun install');
|
|
239
239
|
console.log('');
|
|
240
|
+
console.log('Piping with $:');
|
|
241
|
+
console.log(' echo "hi" | $ agent # Preferred - pipe TO $ command');
|
|
242
|
+
console.log(
|
|
243
|
+
' $ \'echo "hi" | agent\' # Alternative - quote entire pipeline'
|
|
244
|
+
);
|
|
245
|
+
console.log('');
|
|
246
|
+
console.log('Quoting for special characters:');
|
|
247
|
+
console.log(" $ 'npm test && npm build' # Wrap for logical operators");
|
|
248
|
+
console.log(" $ 'cat file > output.txt' # Wrap for redirections");
|
|
249
|
+
console.log('');
|
|
240
250
|
console.log('Features:');
|
|
241
251
|
console.log(' - Logs all output to temporary directory');
|
|
242
252
|
console.log(' - Displays timestamps and exit codes');
|