Skip to content

Commit 0dc924b

Browse files
committed
chore(project): add initial project setup and guidelines
- Added `.gitignore` to exclude `.pkl` files. - Documented code style, design patterns, and project overview. - Included suggested commands and task completion checklist. - Configured project settings in `.serena/project.yml`. This commit establishes the foundation for the rtty project.
1 parent 61ec0b8 commit 0dc924b

File tree

7 files changed

+360
-0
lines changed

7 files changed

+360
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/*.pkl
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Code Style and Conventions
2+
3+
## Go Code Style
4+
- **Go Version**: 1.23.0+ (go.mod), using Go 1.24.4 toolchain
5+
- **Module Name**: github.com/skanehira/rtty
6+
- **Package Structure**:
7+
- Main package in root
8+
- Command implementations in `cmd` package
9+
- Embedded assets using `embed` package
10+
11+
## Naming Conventions
12+
- **Files**: Snake_case (e.g., `run.go`, `version.go`)
13+
- **Functions**: CamelCase with exported functions starting with uppercase
14+
- **Variables**: camelCase for private, CamelCase for exported
15+
- **Constants**: CamelCase (e.g., `EventResize`, `EventSendkey`)
16+
17+
## Code Organization
18+
- Commands are implemented using Cobra framework
19+
- Each command has its own file in the `cmd` directory
20+
- Utility functions are centralized in `util.go`
21+
- Embedded frontend assets are stored in `cmd/public`
22+
23+
## Error Handling
24+
- Errors are logged using standard `log` package
25+
- HTTP/WebSocket errors are handled gracefully
26+
- Command execution errors are reported to the client
27+
28+
## Comments and Documentation
29+
- Minimal inline comments (code should be self-documenting)
30+
- Using `//nolint` directives where necessary for linter exceptions
31+
- No extensive function documentation observed
32+
33+
## Dependencies
34+
- Minimal external dependencies
35+
- Main dependencies: cobra (CLI), creack/pty (terminal), websocket
36+
- All dependencies managed via go.mod
37+
38+
## Build Configuration
39+
- CGO_ENABLED=0 for static binaries
40+
- Supports Linux and Darwin (macOS) platforms
41+
- Uses ldflags for version injection during build
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Design Patterns and Guidelines
2+
3+
## Architecture Overview
4+
- **CLI-based Architecture**: Uses Cobra for command-line interface
5+
- **WebSocket Server**: Single-page application communicating via WebSocket
6+
- **Process Management**: Uses PTY (pseudo-terminal) for command execution
7+
8+
## Key Design Patterns
9+
10+
### 1. Command Pattern (Cobra)
11+
- Root command in `cmd/root.go`
12+
- Subcommands in separate files (run.go, version.go)
13+
- Command initialization in `init()` functions
14+
15+
### 2. Server-Client Communication
16+
- JSON message protocol over WebSocket
17+
- Event-based architecture with defined event types:
18+
- `EventResize`: Terminal resize events
19+
- `EventSendkey`: Keyboard input events (though defined as "Snedkey" - likely a typo)
20+
- `EventClose`: Connection close events
21+
22+
### 3. Embedded Assets
23+
- Frontend assets embedded using Go's `embed` package
24+
- HTML and JavaScript served from embedded filesystem
25+
26+
### 4. Concurrent I/O Handling
27+
- Goroutines for bidirectional communication
28+
- Separate goroutine for reading from WebSocket and writing to PTY
29+
- Main goroutine copies PTY output to WebSocket
30+
31+
## Code Guidelines
32+
33+
### Error Handling
34+
- Log errors but don't crash the server
35+
- Graceful degradation for client disconnections
36+
- Return meaningful error messages to clients
37+
38+
### Resource Management
39+
- Proper cleanup with `defer` statements
40+
- Close WebSocket connections and PTY on exit
41+
- Single PTY instance per connection session
42+
43+
### Security Considerations
44+
- Origin checking for WebSocket connections
45+
- Configurable allowed origins
46+
- No authentication mechanism (consider for production use)
47+
48+
## Development Guidelines
49+
50+
### Adding New Features
51+
1. Follow existing command structure for new CLI commands
52+
2. Maintain backward compatibility with message protocol
53+
3. Test with different shells and terminal types
54+
55+
### Frontend Modifications
56+
- Keep JavaScript simple and focused
57+
- Maintain compatibility with xterm.js library
58+
- Test across different browsers
59+
60+
### Performance Considerations
61+
- Minimize message overhead in WebSocket protocol
62+
- Efficient buffer handling for terminal I/O
63+
- Avoid blocking operations in message handlers
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# rtty Project Overview
2+
3+
## Purpose
4+
rtty (Remote TTY) is a terminal emulator that runs in a web browser via WebSocket. It allows users to access a terminal session through a web interface, making it possible to run command-line tools remotely through a browser.
5+
6+
## Core Features
7+
- Run any command/shell in a browser
8+
- WebSocket-based real-time communication
9+
- Terminal resize support
10+
- Configurable font and font size
11+
- Cross-platform support (Linux and macOS)
12+
13+
## Tech Stack
14+
- **Language**: Go 1.23.0+ (currently using Go 1.24.4)
15+
- **Backend Framework**:
16+
- Cobra for CLI commands
17+
- Standard Go net/http and golang.org/x/net/websocket for WebSocket server
18+
- creack/pty for pseudo-terminal handling
19+
- **Frontend**:
20+
- Vanilla JavaScript
21+
- xterm.js for terminal emulation in the browser
22+
- WebSocket API for communication
23+
24+
## Project Structure
25+
```
26+
.
27+
├── cmd/ # Command implementations
28+
│ ├── public/ # Frontend assets (HTML, JS, CSS)
29+
│ ├── root.go # Root command
30+
│ ├── run.go # Main run command (WebSocket server)
31+
│ ├── version.go # Version command
32+
│ └── util.go # Utility functions
33+
├── main.go # Entry point
34+
├── go.mod # Go module definition
35+
├── go.sum # Go module checksums
36+
├── Makefile # Build automation
37+
├── .goreleaser.yaml # Release configuration
38+
└── .github/
39+
└── workflows/ # CI/CD workflows
40+
```
41+
42+
## Key Components
43+
1. **WebSocket Server**: Handles browser connections and terminal I/O
44+
2. **PTY Management**: Creates and manages pseudo-terminals for running commands
45+
3. **Message Protocol**: JSON-based messaging between browser and server
46+
4. **Event Handling**: Supports resize, key input, and close events
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Suggested Commands for Development
2+
3+
## Build and Run
4+
```bash
5+
# Run the server locally
6+
go run . run zsh -p 8080 -v --font "Cica Regular" --font-size 20
7+
8+
# Build the binary
9+
go build
10+
11+
# Install to GOPATH/bin
12+
go install github.com/skanehira/rtty@latest
13+
```
14+
15+
## Testing
16+
```bash
17+
# Run all tests
18+
go test -v ./...
19+
20+
# Run tests with coverage
21+
go test -v -cover ./...
22+
```
23+
24+
## Linting and Code Quality
25+
```bash
26+
# Run golangci-lint (used in CI)
27+
golangci-lint run
28+
29+
# Format code
30+
go fmt ./...
31+
32+
# Check for issues
33+
go vet ./...
34+
```
35+
36+
## Dependency Management
37+
```bash
38+
# Update dependencies
39+
go mod tidy
40+
41+
# Download dependencies
42+
go mod download
43+
44+
# Verify dependencies
45+
go mod verify
46+
```
47+
48+
## Git Commands
49+
```bash
50+
# Check status
51+
git status
52+
53+
# Add changes
54+
git add .
55+
56+
# Commit with message
57+
git commit -m "message"
58+
59+
# Push to remote
60+
git push origin main
61+
```
62+
63+
## Release and Build
64+
```bash
65+
# Create a new release with goreleaser
66+
goreleaser release --clean
67+
68+
# Test release build locally
69+
goreleaser build --snapshot --clean
70+
```
71+
72+
## System Commands (Darwin/macOS)
73+
```bash
74+
# List files
75+
ls -la
76+
77+
# Find files
78+
find . -name "*.go"
79+
80+
# Search in files
81+
grep -r "pattern" .
82+
83+
# Watch file changes
84+
fswatch -o . | xargs -n1 -I{} echo "File changed"
85+
```
86+
87+
## Development Workflow
88+
```bash
89+
# 1. Make changes
90+
# 2. Format code
91+
go fmt ./...
92+
93+
# 3. Run linter
94+
golangci-lint run
95+
96+
# 4. Run tests
97+
go test -v ./...
98+
99+
# 5. Build and test manually
100+
go build && ./rtty run zsh -p 8080 -v
101+
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Task Completion Checklist
2+
3+
When completing any development task on the rtty project, ensure the following steps are performed:
4+
5+
## 1. Code Quality Checks
6+
- [ ] Run `go fmt ./...` to format all Go files
7+
- [ ] Run `golangci-lint run` to check for linting issues
8+
- [ ] Fix any linting warnings or errors
9+
10+
## 2. Testing
11+
- [ ] Run `go test -v ./...` to ensure all tests pass
12+
- [ ] Add new tests for any new functionality (if applicable)
13+
- [ ] Verify test coverage for critical paths
14+
15+
## 3. Build Verification
16+
- [ ] Run `go build` to ensure the project builds successfully
17+
- [ ] Test the built binary with basic functionality
18+
19+
## 4. Manual Testing
20+
- [ ] Run the server: `./rtty run zsh -p 8080 -v`
21+
- [ ] Open browser and verify WebSocket connection works
22+
- [ ] Test terminal functionality (typing, resize, etc.)
23+
24+
## 5. Dependencies
25+
- [ ] Run `go mod tidy` to clean up dependencies
26+
- [ ] Commit both go.mod and go.sum if changed
27+
28+
## 6. Documentation
29+
- [ ] Update README.md if functionality changes
30+
- [ ] Update inline comments if complex logic is added
31+
32+
## 7. Git Hygiene
33+
- [ ] Ensure commits follow TDD approach (test first, then implementation)
34+
- [ ] Use clear commit messages with [STRUCTURAL] or [BEHAVIORAL] prefix
35+
- [ ] Verify no secrets or sensitive data in commits
36+
37+
## Important Notes
38+
- The project currently has no test files, so writing tests for new features is especially important
39+
- Always use `ghost` for managing background processes during development
40+
- Follow the established code style (minimal comments, self-documenting code)

.serena/project.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# language of the project (csharp, python, rust, java, typescript, go, cpp, or ruby)
2+
# * For C, use cpp
3+
# * For JavaScript, use typescript
4+
# Special requirements:
5+
# * csharp: Requires the presence of a .sln file in the project folder.
6+
language: go
7+
8+
# whether to use the project's gitignore file to ignore files
9+
# Added on 2025-04-07
10+
ignore_all_files_in_gitignore: true
11+
# list of additional paths to ignore
12+
# same syntax as gitignore, so you can use * and **
13+
# Was previously called `ignored_dirs`, please update your config if you are using that.
14+
# Added (renamed)on 2025-04-07
15+
ignored_paths: []
16+
17+
# whether the project is in read-only mode
18+
# If set to true, all editing tools will be disabled and attempts to use them will result in an error
19+
# Added on 2025-04-18
20+
read_only: false
21+
22+
23+
# list of tool names to exclude. We recommend not excluding any tools, see the readme for more details.
24+
# Below is the complete list of tools for convenience.
25+
# To make sure you have the latest list of tools, and to view their descriptions,
26+
# execute `uv run scripts/print_tool_overview.py`.
27+
#
28+
# * `activate_project`: Activates a project by name.
29+
# * `check_onboarding_performed`: Checks whether project onboarding was already performed.
30+
# * `create_text_file`: Creates/overwrites a file in the project directory.
31+
# * `delete_lines`: Deletes a range of lines within a file.
32+
# * `delete_memory`: Deletes a memory from Serena's project-specific memory store.
33+
# * `execute_shell_command`: Executes a shell command.
34+
# * `find_referencing_code_snippets`: Finds code snippets in which the symbol at the given location is referenced.
35+
# * `find_referencing_symbols`: Finds symbols that reference the symbol at the given location (optionally filtered by type).
36+
# * `find_symbol`: Performs a global (or local) search for symbols with/containing a given name/substring (optionally filtered by type).
37+
# * `get_current_config`: Prints the current configuration of the agent, including the active and available projects, tools, contexts, and modes.
38+
# * `get_symbols_overview`: Gets an overview of the top-level symbols defined in a given file or directory.
39+
# * `initial_instructions`: Gets the initial instructions for the current project.
40+
# Should only be used in settings where the system prompt cannot be set,
41+
# e.g. in clients you have no control over, like Claude Desktop.
42+
# * `insert_after_symbol`: Inserts content after the end of the definition of a given symbol.
43+
# * `insert_at_line`: Inserts content at a given line in a file.
44+
# * `insert_before_symbol`: Inserts content before the beginning of the definition of a given symbol.
45+
# * `list_dir`: Lists files and directories in the given directory (optionally with recursion).
46+
# * `list_memories`: Lists memories in Serena's project-specific memory store.
47+
# * `onboarding`: Performs onboarding (identifying the project structure and essential tasks, e.g. for testing or building).
48+
# * `prepare_for_new_conversation`: Provides instructions for preparing for a new conversation (in order to continue with the necessary context).
49+
# * `read_file`: Reads a file within the project directory.
50+
# * `read_memory`: Reads the memory with the given name from Serena's project-specific memory store.
51+
# * `remove_project`: Removes a project from the Serena configuration.
52+
# * `replace_lines`: Replaces a range of lines within a file with new content.
53+
# * `replace_symbol_body`: Replaces the full definition of a symbol.
54+
# * `restart_language_server`: Restarts the language server, may be necessary when edits not through Serena happen.
55+
# * `search_for_pattern`: Performs a search for a pattern in the project.
56+
# * `summarize_changes`: Provides instructions for summarizing the changes made to the codebase.
57+
# * `switch_modes`: Activates modes by providing a list of their names
58+
# * `think_about_collected_information`: Thinking tool for pondering the completeness of collected information.
59+
# * `think_about_task_adherence`: Thinking tool for determining whether the agent is still on track with the current task.
60+
# * `think_about_whether_you_are_done`: Thinking tool for determining whether the task is truly completed.
61+
# * `write_memory`: Writes a named memory (for future reference) to Serena's project-specific memory store.
62+
excluded_tools: []
63+
64+
# initial prompt for the project. It will always be given to the LLM upon activating the project
65+
# (contrary to the memories, which are loaded on demand).
66+
initial_prompt: ""
67+
68+
project_name: "rtty"

0 commit comments

Comments
 (0)