start-command 0.3.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.
- package/.changeset/README.md +8 -0
- package/.changeset/config.json +11 -0
- package/.changeset/isolation-support.md +30 -0
- package/.github/workflows/release.yml +292 -0
- package/.husky/pre-commit +1 -0
- package/.prettierignore +6 -0
- package/.prettierrc +10 -0
- package/CHANGELOG.md +24 -0
- package/LICENSE +24 -0
- package/README.md +249 -0
- package/REQUIREMENTS.md +229 -0
- package/bun.lock +453 -0
- package/bunfig.toml +3 -0
- package/eslint.config.mjs +122 -0
- package/experiments/debug-regex.js +49 -0
- package/experiments/isolation-design.md +142 -0
- package/experiments/test-cli.sh +42 -0
- package/experiments/test-substitution.js +143 -0
- package/package.json +63 -0
- package/scripts/changeset-version.mjs +38 -0
- package/scripts/check-file-size.mjs +103 -0
- package/scripts/create-github-release.mjs +93 -0
- package/scripts/create-manual-changeset.mjs +89 -0
- package/scripts/format-github-release.mjs +83 -0
- package/scripts/format-release-notes.mjs +219 -0
- package/scripts/instant-version-bump.mjs +121 -0
- package/scripts/publish-to-npm.mjs +129 -0
- package/scripts/setup-npm.mjs +37 -0
- package/scripts/validate-changeset.mjs +107 -0
- package/scripts/version-and-commit.mjs +237 -0
- package/src/bin/cli.js +670 -0
- package/src/lib/args-parser.js +259 -0
- package/src/lib/isolation.js +419 -0
- package/src/lib/substitution.js +323 -0
- package/src/lib/substitutions.lino +308 -0
- package/test/args-parser.test.js +389 -0
- package/test/isolation.test.js +248 -0
- package/test/substitution.test.js +236 -0
package/REQUIREMENTS.md
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# Requirements for `$` Command (start-command)
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The `$` command is a CLI tool that wraps any shell command and provides automatic logging, error reporting, issue creation capabilities, and natural language command aliases.
|
|
6
|
+
|
|
7
|
+
## Core Requirements
|
|
8
|
+
|
|
9
|
+
### 1. Command Proxy Functionality
|
|
10
|
+
|
|
11
|
+
- Act as a transparent proxy for any shell command
|
|
12
|
+
- Pass all arguments directly to the underlying shell (bash/powershell/sh)
|
|
13
|
+
- Support all standard commands: `$ ls`, `$ cat`, `$ mkdir`, etc.
|
|
14
|
+
- Preserve exit codes from wrapped commands
|
|
15
|
+
- Support natural language command aliases via pattern matching
|
|
16
|
+
|
|
17
|
+
### 2. Logging Requirements
|
|
18
|
+
|
|
19
|
+
#### 2.1 Log Storage
|
|
20
|
+
|
|
21
|
+
- Save full command output (stdout + stderr) to temporary OS directory
|
|
22
|
+
- Use platform-appropriate temp directory:
|
|
23
|
+
- Linux/macOS: `/tmp/` or `os.tmpdir()`
|
|
24
|
+
- Windows: `%TEMP%`
|
|
25
|
+
- Log file naming: `start-command-{timestamp}-{random}.log`
|
|
26
|
+
|
|
27
|
+
#### 2.2 Log Content
|
|
28
|
+
|
|
29
|
+
- Include timestamp at the start of logging
|
|
30
|
+
- Include timestamp at the end of logging
|
|
31
|
+
- Capture both stdout and stderr
|
|
32
|
+
- Store the complete command that was executed
|
|
33
|
+
- Store the exit code
|
|
34
|
+
|
|
35
|
+
#### 2.3 Log Display
|
|
36
|
+
|
|
37
|
+
- Print full log content to console after command finishes
|
|
38
|
+
- Always print the exit code (success or failure)
|
|
39
|
+
- Make exit code prominent as "it may usually be unclear"
|
|
40
|
+
|
|
41
|
+
### 3. Repository Detection
|
|
42
|
+
|
|
43
|
+
#### 3.1 NPM Package Detection
|
|
44
|
+
|
|
45
|
+
- Detect if the executed command is a globally installed NPM package
|
|
46
|
+
- Use `which` (Unix) or `where` (Windows) to find command location
|
|
47
|
+
- Check if command resolves to a path within npm global modules
|
|
48
|
+
- Extract package name from the path
|
|
49
|
+
- Use `npm view <package> repository.url` to get repository URL
|
|
50
|
+
|
|
51
|
+
#### 3.2 Supported Command Types
|
|
52
|
+
|
|
53
|
+
- Globally installed NPM packages (primary focus)
|
|
54
|
+
- Future: other package managers (pip, gem, etc.)
|
|
55
|
+
|
|
56
|
+
### 4. Automatic Issue Reporting (On Failure)
|
|
57
|
+
|
|
58
|
+
#### 4.1 Preconditions for Auto-Reporting
|
|
59
|
+
|
|
60
|
+
- Command must have failed (non-zero exit code)
|
|
61
|
+
- Repository must be detected for the command
|
|
62
|
+
- `gh` CLI tool must be authenticated
|
|
63
|
+
- User must have permission to create issues in target repository
|
|
64
|
+
|
|
65
|
+
#### 4.2 Log Upload
|
|
66
|
+
|
|
67
|
+
- Use `gh-upload-log` tool to upload the log file
|
|
68
|
+
- Upload as a gist (for logs ≤100MB)
|
|
69
|
+
- Print the uploaded log URL to console
|
|
70
|
+
|
|
71
|
+
#### 4.3 Issue Creation
|
|
72
|
+
|
|
73
|
+
- Create an issue in the detected repository
|
|
74
|
+
- Issue title: Include command name and error summary
|
|
75
|
+
- Issue body: Include:
|
|
76
|
+
- Command that was executed
|
|
77
|
+
- Exit code
|
|
78
|
+
- Link to uploaded log
|
|
79
|
+
- System information (OS, Node version)
|
|
80
|
+
- Timestamp
|
|
81
|
+
- Print the created issue URL to console
|
|
82
|
+
|
|
83
|
+
### 5. Graceful Degradation
|
|
84
|
+
|
|
85
|
+
#### 5.1 When Repository Cannot Be Detected
|
|
86
|
+
|
|
87
|
+
- Still log everything to temp directory
|
|
88
|
+
- Still print logs and exit code to console
|
|
89
|
+
- Skip log upload and issue creation
|
|
90
|
+
|
|
91
|
+
#### 5.2 When `gh` Is Not Authenticated
|
|
92
|
+
|
|
93
|
+
- Still log everything to temp directory
|
|
94
|
+
- Still print logs and exit code to console
|
|
95
|
+
- Print a message that auto-reporting is skipped
|
|
96
|
+
- Skip log upload and issue creation
|
|
97
|
+
|
|
98
|
+
#### 5.3 When `gh-upload-log` Is Not Installed
|
|
99
|
+
|
|
100
|
+
- Still log everything to temp directory
|
|
101
|
+
- Still print logs and exit code to console
|
|
102
|
+
- Print a message that log upload is skipped
|
|
103
|
+
- Skip issue creation (no log link available)
|
|
104
|
+
|
|
105
|
+
### 5. Command Aliases / Substitutions
|
|
106
|
+
|
|
107
|
+
#### 5.1 Pattern Matching
|
|
108
|
+
|
|
109
|
+
- Support natural language patterns defined in `substitutions.lino`
|
|
110
|
+
- Use Links Notation style with variables like `$packageName`, `$version`
|
|
111
|
+
- Match input against patterns and substitute with actual commands
|
|
112
|
+
- More specific patterns (more variables, longer patterns) take precedence
|
|
113
|
+
- Non-matching commands pass through unchanged
|
|
114
|
+
|
|
115
|
+
#### 5.2 Built-in Patterns
|
|
116
|
+
|
|
117
|
+
- NPM: `install $packageName npm package` -> `npm install $packageName`
|
|
118
|
+
- NPM with version: `install $version version of $packageName npm package` -> `npm install $packageName@$version`
|
|
119
|
+
- Git clone: `clone $repository repository` -> `git clone $repository`
|
|
120
|
+
- Git checkout: `checkout $branch branch` -> `git checkout $branch`
|
|
121
|
+
- Common operations: `list files` -> `ls -la`, `show current directory` -> `pwd`
|
|
122
|
+
|
|
123
|
+
#### 5.3 Custom Patterns
|
|
124
|
+
|
|
125
|
+
- Support user-defined patterns in `~/.start-command/substitutions.lino`
|
|
126
|
+
- User patterns take precedence over built-in patterns
|
|
127
|
+
- Support custom path via `START_SUBSTITUTIONS_PATH` environment variable
|
|
128
|
+
|
|
129
|
+
### 6. Process Isolation
|
|
130
|
+
|
|
131
|
+
#### 6.1 Command Syntax
|
|
132
|
+
|
|
133
|
+
Support two patterns for passing wrapper options:
|
|
134
|
+
|
|
135
|
+
- `$ [wrapper-options] -- [command] [command-options]` (explicit separator)
|
|
136
|
+
- `$ [wrapper-options] command [command-options]` (options before command)
|
|
137
|
+
|
|
138
|
+
#### 6.2 Isolation Options
|
|
139
|
+
|
|
140
|
+
- `--isolated, -i <backend>`: Run command in isolated environment
|
|
141
|
+
- `--attached, -a`: Run in attached/foreground mode (default)
|
|
142
|
+
- `--detached, -d`: Run in detached/background mode
|
|
143
|
+
- `--session, -s <name>`: Custom session name
|
|
144
|
+
- `--image <image>`: Docker image (required for docker backend)
|
|
145
|
+
|
|
146
|
+
#### 6.3 Supported Backends
|
|
147
|
+
|
|
148
|
+
- `screen`: GNU Screen terminal multiplexer
|
|
149
|
+
- `tmux`: tmux terminal multiplexer
|
|
150
|
+
- `zellij`: Modern terminal workspace
|
|
151
|
+
- `docker`: Docker containers (requires --image option)
|
|
152
|
+
|
|
153
|
+
#### 6.4 Mode Behavior
|
|
154
|
+
|
|
155
|
+
- **Attached mode**: Command runs in foreground, user can interact
|
|
156
|
+
- **Detached mode**: Command runs in background, session info displayed for reattachment
|
|
157
|
+
- **Conflict handling**: If both --attached and --detached are specified, show error asking user to choose one
|
|
158
|
+
|
|
159
|
+
#### 6.5 Graceful Degradation
|
|
160
|
+
|
|
161
|
+
- If isolation backend is not installed, show informative error with installation instructions
|
|
162
|
+
- If session creation fails, report error with details
|
|
163
|
+
|
|
164
|
+
## Configuration Options
|
|
165
|
+
|
|
166
|
+
- `START_DISABLE_AUTO_ISSUE`: Disable automatic issue creation
|
|
167
|
+
- `START_DISABLE_LOG_UPLOAD`: Disable log upload
|
|
168
|
+
- `START_LOG_DIR`: Custom log directory
|
|
169
|
+
- `START_VERBOSE`: Enable verbose output
|
|
170
|
+
- `START_DISABLE_SUBSTITUTIONS`: Disable pattern matching/aliases
|
|
171
|
+
- `START_SUBSTITUTIONS_PATH`: Custom path to substitutions file
|
|
172
|
+
|
|
173
|
+
## Output Format
|
|
174
|
+
|
|
175
|
+
### Success Case
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
[2024-01-15 10:30:45] Starting: ls -la
|
|
179
|
+
... command output ...
|
|
180
|
+
[2024-01-15 10:30:45] Finished
|
|
181
|
+
Exit code: 0
|
|
182
|
+
Log saved: /tmp/start-command-1705312245-abc123.log
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Failure Case (With Auto-Reporting)
|
|
186
|
+
|
|
187
|
+
```
|
|
188
|
+
[2024-01-15 10:30:45] Starting: failing-npm-command --arg
|
|
189
|
+
... command output/error ...
|
|
190
|
+
[2024-01-15 10:30:46] Finished
|
|
191
|
+
Exit code: 1
|
|
192
|
+
Log saved: /tmp/start-command-1705312246-def456.log
|
|
193
|
+
Detected repository: https://github.com/owner/repo
|
|
194
|
+
Log uploaded: https://gist.github.com/...
|
|
195
|
+
Issue created: https://github.com/owner/repo/issues/123
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Failure Case (Without Auto-Reporting)
|
|
199
|
+
|
|
200
|
+
```
|
|
201
|
+
[2024-01-15 10:30:45] Starting: unknown-command
|
|
202
|
+
... command output/error ...
|
|
203
|
+
[2024-01-15 10:30:45] Finished
|
|
204
|
+
Exit code: 127
|
|
205
|
+
Log saved: /tmp/start-command-1705312245-ghi789.log
|
|
206
|
+
Repository not detected - automatic issue creation skipped
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Dependencies
|
|
210
|
+
|
|
211
|
+
### Required
|
|
212
|
+
|
|
213
|
+
- Node.js >= 14.0.0
|
|
214
|
+
- `child_process` (built-in)
|
|
215
|
+
- `os` (built-in)
|
|
216
|
+
- `fs` (built-in)
|
|
217
|
+
- `path` (built-in)
|
|
218
|
+
|
|
219
|
+
### Optional (for full functionality)
|
|
220
|
+
|
|
221
|
+
- `gh` CLI - GitHub CLI for authentication and issue creation
|
|
222
|
+
- `gh-upload-log` - For uploading log files to GitHub
|
|
223
|
+
|
|
224
|
+
## Security Considerations
|
|
225
|
+
|
|
226
|
+
- Do not include sensitive environment variables in logs
|
|
227
|
+
- Do not include authentication tokens in issue reports
|
|
228
|
+
- Respect `.gitignore` patterns when detecting repositories
|
|
229
|
+
- Only create issues in public repositories unless explicitly authorized
|