aboutsummaryrefslogtreecommitdiff
path: root/IMPROVEMENT_PLAN_V2.md
blob: abffa0e5b4c6717cd157fce346937236418654d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# Demon CLI Improvement Plan v2

## Overview
This plan outlines four major improvements to enhance the demon CLI tool's usability, error handling, and documentation.

## Task 1: Rename PidFileData to PidFile

### Rationale
- Shorter, cleaner name
- More intuitive - it represents a PID file, not just data about one
- Follows Rust naming conventions better

### Implementation Steps
1. Rename struct `PidFileData` to `PidFile`
2. Update all references throughout the codebase
3. Update comments and documentation
4. Verify compilation and tests pass

### Files to modify
- `src/main.rs` - struct definition and all usages

### Risk Assessment
- **Low risk** - Simple rename refactor
- No functional changes
- All tests should continue to pass

## Task 2: Implement PidFileReadError Enum

### Rationale
- Better error handling with specific error types
- Eliminates redundant file existence checks
- More idiomatic Rust error handling
- Cleaner code in error handling paths

### Design
```rust
#[derive(Debug)]
pub enum PidFileReadError {
    /// The PID file does not exist
    FileNotFound,
    /// The PID file exists but has invalid content
    FileInvalid(String), // Include reason for invalidity
    /// IO error occurred while reading
    IoError(std::io::Error),
}
```

### Implementation Steps
1. Define `PidFileReadError` enum with appropriate variants
2. Implement `Display` and `Error` traits for the enum
3. Update `PidFile::read_from_file()` to return `Result<PidFile, PidFileReadError>`
4. Update all call sites to handle the specific error types:
   - `is_process_running()` - handle FileNotFound and FileInvalid as "not running"
   - `stop_daemon()` - handle FileNotFound as "not running", FileInvalid as "cleanup needed"
   - `list_daemons()` - handle FileInvalid as "INVALID" entry
   - `status_daemon()` - handle FileNotFound as "NOT FOUND", FileInvalid as "ERROR"
   - `clean_orphaned_files()` - handle FileInvalid as "needs cleanup"
5. Remove redundant `Path::new().exists()` checks where the error type provides this info
6. Test all error scenarios

### Files to modify
- `src/main.rs` - enum definition, read_from_file method, all usage sites

### Risk Assessment
- **Medium risk** - Changes error handling logic
- Need thorough testing of error scenarios
- Must ensure all edge cases are handled properly

## Task 3: Make --id a Positional Argument

### Analysis

#### Current CLI Pattern
```bash
demon run --id web-server python -m http.server 8080
demon stop --id web-server
demon status --id web-server
```

#### Proposed CLI Pattern
```bash
demon run web-server python -m http.server 8080
demon stop web-server
demon status web-server
```

#### Pros
- **Better UX**: More natural and concise
- **Consistent with common tools**: Similar to git, docker, etc.
- **Faster to type**: No --id flag needed
- **More intuitive**: ID naturally comes first before the command

#### Cons
- **Breaking change**: Existing scripts/users need to update
- **Potential ambiguity**: ID could be confused with command in some cases
- **Parsing complexity**: Need careful handling of edge cases

#### Design Decisions
1. **Make ID positional for all commands that currently use --id**
2. **Keep -- separator support** for complex commands
3. **Update help text** to reflect new usage
4. **Maintain backward compatibility** by supporting both patterns initially (with deprecation warning)

#### Commands to Update
- `run <id> <command...>` - ID becomes first positional arg
- `stop <id>` - ID becomes positional arg, remove timeout flag positioning issues
- `tail <id>` - ID becomes positional arg
- `cat <id>` - ID becomes positional arg  
- `status <id>` - ID becomes positional arg

#### Implementation Strategy
1. **Phase 1**: Support both patterns with deprecation warnings
2. **Phase 2**: Remove old pattern support (future version)

### Implementation Steps
1. Define new argument structures with positional ID fields
2. Update clap derive macros to make ID positional
3. Update help text and documentation strings
4. Add deprecation warnings for --id usage (optional)
5. Update all internal function calls
6. Update tests to use new CLI pattern
7. Update LLM guide output

### Files to modify
- `src/main.rs` - argument structures, help text
- `tests/cli.rs` - all test commands
- LLM guide text

### Risk Assessment
- **High risk** - Breaking change for users
- Need to update all tests
- Must carefully verify argument parsing edge cases
- Consider gradual migration strategy

## Task 4: Write Comprehensive README.md

### Target Audience
- Developers who need background process management
- LLM agents and their operators
- DevOps engineers running long-term tasks
- Anyone working with npm run dev, build processes, etc.

### Content Structure
```markdown
# Demon - Background Process Manager

## Overview
Brief description focusing on core value proposition

## Installation
- `cargo install demon` (when published)
- Building from source
- System requirements

## Quick Start
- Basic examples
- Common workflows

## Use Cases
- Development servers (npm run dev)
- Background tasks and scripts
- LLM agent process management
- CI/CD pipeline tasks
- Long-running computations

## Command Reference
- Complete command documentation
- Examples for each command
- Common flags and options

## Integration with LLM Agents
- How agents can use demon
- Machine-readable output formats
- Best practices for automation

## Advanced Usage
- File management
- Process lifecycle
- Troubleshooting
- Performance considerations

## Contributing
- Development setup
- Testing
- Contribution guidelines
```

### Key Messages
1. **Simplicity**: Easy background process management
2. **Visibility**: Always know what's running and its status
3. **Integration**: Built for automation and LLM agents
4. **Reliability**: Robust process lifecycle management

### Implementation Steps
1. Research similar tools for README inspiration
2. Write comprehensive content covering all sections
3. Include practical examples and screenshots/command outputs
4. Add badges for build status, crates.io, etc. (when applicable)
5. Review and refine for clarity and completeness

### Files to create
- `README.md` - comprehensive documentation

### Risk Assessment
- **Low risk** - Documentation only
- No functional changes
- Easy to iterate and improve

## Execution Order

1. **Task 1**: Rename PidFileData to PidFile (Low risk, enables clean foundation)
2. **Task 2**: Implement PidFileReadError enum (Medium risk, improves error handling)
3. **Task 3**: Make --id positional (High risk, but significant UX improvement)
4. **Task 4**: Write README.md (Low risk, improves project presentation)

## Testing Strategy

After each task:
1. Run `cargo build` to ensure compilation
2. Run `cargo test` to ensure all tests pass
3. Manual testing of affected functionality
4. Format code with `cargo fmt`
5. Commit changes with descriptive message

## Success Criteria

- All tests pass after each change
- No regressions in functionality
- Improved error messages and handling
- Better CLI usability
- Comprehensive documentation
- Clean, maintainable code

## Rollback Plan

Each task will be committed separately, allowing for easy rollback if issues arise:
1. Git commit after each successful task
2. If issues found, can revert specific commits
3. Tests provide safety net for functionality

## Timeline Estimate

- Task 1: 15-20 minutes (straightforward refactor)
- Task 2: 30-45 minutes (error handling logic)
- Task 3: 45-60 minutes (CLI argument changes + tests)
- Task 4: 30-45 minutes (documentation writing)

Total: ~2-3 hours