Skip to content

Commit b117fe3

Browse files
authored
Merge pull request #13 from ivangrynenko/docs/claude-lessons-learned
docs: add lessons learned from curl piping issues
2 parents a3d4a79 + f8468c2 commit b117fe3

File tree

2 files changed

+73
-3
lines changed

2 files changed

+73
-3
lines changed

CLAUDE.md

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ php install.php --debug --core
3838

3939
# Test installation to custom directory
4040
php install.php --all --destination=my/custom/path
41+
42+
# Test installation via curl (non-interactive)
43+
curl -s https://raw.githubusercontent.com/ivangrynenko/cursor-rules/main/install.php | php -- --ws
44+
cat install.php | php -- --core # Test piped input locally
4145
```
4246

4347
### Linting and Code Quality
@@ -47,10 +51,12 @@ php install.php --all --destination=my/custom/path
4751
## Architecture and Code Structure
4852

4953
### Project Organization
50-
- **install.php**: Main installer script (v1.0.4) - Uses builder and strategy patterns for rule set installation
54+
- **install.php**: Main installer script (current version defined by CURSOR_RULES_VERSION constant)
5155
- **.cursor/rules/**: Contains 56 MDC rule files organized by category
56+
- **.cursor/UPDATE.md**: Installation receipt file tracking installed version and configuration (created by installer)
5257
- **.tests/**: Bash test scripts for installer validation
5358
- **.github/workflows/**: CI/CD pipeline using GitHub Actions for PHP 8.3
59+
- **AGENTS.md**: Comprehensive guide for using Cursor Rules (created by installer)
5460

5561
### Rule Categories
5662
1. **Core Rules** (7 files): Git standards, testing guidelines, README maintenance
@@ -73,7 +79,69 @@ php install.php --all --destination=my/custom/path
7379
2. Script detects if running interactively or with parameters
7480
3. Creates .cursor/rules directory structure
7581
4. Downloads and installs selected rule files from GitHub
76-
5. Creates UPDATE.md file to track version
82+
5. Creates/overwrites .cursor/UPDATE.md file as an installation receipt
83+
6. Creates/updates AGENTS.md documentation (unless --yes flag overwrites)
84+
85+
## Versioning System
86+
87+
### Version Management
88+
- **Version Constant**: Defined in install.php as `CURSOR_RULES_VERSION`
89+
- **Version History**: Tracked in GitHub releases and repository documentation
90+
- **Release Process**:
91+
1. Update CURSOR_RULES_VERSION constant in install.php
92+
2. Update version history in repository documentation
93+
3. Create GitHub release matching the version number
94+
4. Tag the release in git
95+
96+
### .cursor/UPDATE.md File Purpose
97+
The UPDATE.md file serves as an installation receipt that:
98+
- Records the version of cursor-rules that was installed
99+
- Documents the installation date and time
100+
- Lists the number of rule files installed
101+
- Shows the installation type (core, web-stack, Python, etc.)
102+
- Records any tag filters that were applied
103+
- Gets created/overwritten by the installer on each run
104+
- Helps users identify which version and configuration they have installed
105+
106+
## Known Issues and Solutions
107+
108+
### Curl Piping Issues (Fixed in v1.0.6)
109+
When piping the installer through curl, several PHP-specific behaviors can cause problems:
110+
111+
**Problem**: Script hangs when using `curl ... | php` commands
112+
**Root Causes**:
113+
1. `$_SERVER['PHP_SELF']` becomes "Standard input code" instead of script name when piped
114+
2. PHP continues waiting for STDIN input even after script completion
115+
3. Arguments may not parse correctly when using `--` separator with piped input
116+
117+
**Solutions Implemented**:
118+
1. **Entry Point Detection**: Check for both normal execution and "Standard input code"
119+
```php
120+
if (basename(__FILE__) === basename($_SERVER['PHP_SELF'] ?? '') ||
121+
($_SERVER['PHP_SELF'] ?? '') === 'Standard input code')
122+
```
123+
124+
2. **STDIN Cleanup**: Always close STDIN before exit to prevent hanging
125+
```php
126+
if (defined('STDIN') && is_resource(STDIN)) {
127+
fclose(STDIN);
128+
}
129+
```
130+
131+
3. **Argument Parsing**: Handle both with and without `--` separator
132+
```php
133+
if (!stream_isatty(STDIN) && $_SERVER['PHP_SELF'] === 'Standard input code') {
134+
// Parse arguments from argv when piped
135+
}
136+
```
137+
138+
### Testing Coverage Gaps
139+
**Issue**: Test suite only covered direct PHP execution, not curl piping scenarios
140+
**Recommendation**: Add tests for:
141+
- `curl ... | php` execution paths
142+
- `cat install.php | php` scenarios
143+
- Argument parsing with and without `--` separator
144+
- STDIN handling in different contexts
77145

78146
## Important Considerations
79147

install.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,9 @@ function show_help(): void {
987987
}
988988

989989
// If this script is being run directly, execute the installation.
990-
if (basename(__FILE__) === basename($_SERVER['PHP_SELF'] ?? '')) {
990+
// Also handle execution when piped through curl (PHP_SELF becomes "Standard input code")
991+
if (basename(__FILE__) === basename($_SERVER['PHP_SELF'] ?? '') ||
992+
($_SERVER['PHP_SELF'] ?? '') === 'Standard input code') {
991993
// Default options
992994
$options = [
993995
'debug' => false,

0 commit comments

Comments
 (0)